user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u021916304 | p02756 | python | s421211467 | s797697840 | 1,733 | 812 | 41,332 | 43,060 | Accepted | Accepted | 53.14 | s = eval(input())
n = int(eval(input()))
query = [0]*n
rev = 0
for i in range(n):
query[i] = list(map(str, input().split()))
if query[i][0] == '1':
rev = rev + 1
begin = ''
end = ''
pal = 0
for i in range(n):
if int(query[i][0]) == 1:
pal = (pal+1)%2
else:
if pal == 0:
if int(query[i][1]) == 1:
begin = query[i][2] + begin
else:
end = end + query[i][2]
else:
if int(query[i][1]) == 1:
end = end + query[i][2]
else:
begin = query[i][2] + begin
# print('--------'+str(i+1)+'th try-----')
# print('begin:'+begin)
# print('end:'+end)
# print('pal:'+str(pal))
if rev%2 == 1:
print((end[::-1]+s[::-1]+begin[::-1]))
else:
print((begin+s+end)) | from collections import deque
s = eval(input())
n = int(eval(input()))
query = [0]*n
rev = 0
for i in range(n):
query[i] = list(map(str, input().split()))
if query[i][0] == '1':
rev = rev + 1
begin = deque()
end = deque()
pal = 0
for i in range(n):
if int(query[i][0]) == 1:
pal = (pal+1)%2
else:
if pal == 0:
if int(query[i][1]) == 1:
begin.appendleft(query[i][2])
else:
end.append(query[i][2])
else:
if int(query[i][1]) == 1:
end.append(query[i][2])
else:
begin.appendleft(query[i][2])
# print('--------'+str(i+1)+'th try-----')
# print(begin)
# print(end)
# print('pal:'+str(pal))
#print(s)
if rev%2 == 1:
print((''.join(deque(reversed(end)))+s[::-1]+''.join(deque(reversed(begin)))))
else:
print((''.join(begin)+s+''.join(end))) | 35 | 39 | 838 | 938 | s = eval(input())
n = int(eval(input()))
query = [0] * n
rev = 0
for i in range(n):
query[i] = list(map(str, input().split()))
if query[i][0] == "1":
rev = rev + 1
begin = ""
end = ""
pal = 0
for i in range(n):
if int(query[i][0]) == 1:
pal = (pal + 1) % 2
else:
if pal == 0:
if int(query[i][1]) == 1:
begin = query[i][2] + begin
else:
end = end + query[i][2]
else:
if int(query[i][1]) == 1:
end = end + query[i][2]
else:
begin = query[i][2] + begin
# print('--------'+str(i+1)+'th try-----')
# print('begin:'+begin)
# print('end:'+end)
# print('pal:'+str(pal))
if rev % 2 == 1:
print((end[::-1] + s[::-1] + begin[::-1]))
else:
print((begin + s + end))
| from collections import deque
s = eval(input())
n = int(eval(input()))
query = [0] * n
rev = 0
for i in range(n):
query[i] = list(map(str, input().split()))
if query[i][0] == "1":
rev = rev + 1
begin = deque()
end = deque()
pal = 0
for i in range(n):
if int(query[i][0]) == 1:
pal = (pal + 1) % 2
else:
if pal == 0:
if int(query[i][1]) == 1:
begin.appendleft(query[i][2])
else:
end.append(query[i][2])
else:
if int(query[i][1]) == 1:
end.append(query[i][2])
else:
begin.appendleft(query[i][2])
# print('--------'+str(i+1)+'th try-----')
# print(begin)
# print(end)
# print('pal:'+str(pal))
# print(s)
if rev % 2 == 1:
print(("".join(deque(reversed(end))) + s[::-1] + "".join(deque(reversed(begin)))))
else:
print(("".join(begin) + s + "".join(end)))
| false | 10.25641 | [
"+from collections import deque",
"+",
"-begin = \"\"",
"-end = \"\"",
"+begin = deque()",
"+end = deque()",
"- begin = query[i][2] + begin",
"+ begin.appendleft(query[i][2])",
"- end = end + query[i][2]",
"+ end.append(query[i][2])",
"- end = end + query[i][2]",
"+ end.append(query[i][2])",
"- begin = query[i][2] + begin",
"+ begin.appendleft(query[i][2])",
"-# print('begin:'+begin)",
"-# print('end:'+end)",
"+# print(begin)",
"+# print(end)",
"+# print(s)",
"- print((end[::-1] + s[::-1] + begin[::-1]))",
"+ print((\"\".join(deque(reversed(end))) + s[::-1] + \"\".join(deque(reversed(begin)))))",
"- print((begin + s + end))",
"+ print((\"\".join(begin) + s + \"\".join(end)))"
] | false | 0.048234 | 0.048091 | 1.002987 | [
"s421211467",
"s797697840"
] |
u970267139 | p03557 | python | s691157434 | s635576428 | 1,688 | 324 | 23,556 | 22,452 | Accepted | Accepted | 80.81 | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
i = []
k = []
for j in range(n):
left = n - 1
right = 0
a_mid = n // 2
while left >= right:
if a[a_mid] >= b[j]:
left = a_mid - 1
else:
right = a_mid + 1
a_mid = (left + right) // 2
i.append(a_mid + 1)
for j in range(n):
left = n - 1
right = 0
c_mid = n // 2
while left >= right:
if c[c_mid] > b[j]:
left = c_mid - 1
else:
right = c_mid + 1
c_mid = (left + right) // 2
k.append(n - c_mid - 1)
ans = sum(x * y for x, y in zip(i, k))
print(ans) | import bisect
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in range(n):
i = bisect.bisect_left(a, b[j])
k = n - bisect.bisect_right(c, b[j])
ans += i * k
print(ans) | 38 | 17 | 783 | 316 | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
i = []
k = []
for j in range(n):
left = n - 1
right = 0
a_mid = n // 2
while left >= right:
if a[a_mid] >= b[j]:
left = a_mid - 1
else:
right = a_mid + 1
a_mid = (left + right) // 2
i.append(a_mid + 1)
for j in range(n):
left = n - 1
right = 0
c_mid = n // 2
while left >= right:
if c[c_mid] > b[j]:
left = c_mid - 1
else:
right = c_mid + 1
c_mid = (left + right) // 2
k.append(n - c_mid - 1)
ans = sum(x * y for x, y in zip(i, k))
print(ans)
| import bisect
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in range(n):
i = bisect.bisect_left(a, b[j])
k = n - bisect.bisect_right(c, b[j])
ans += i * k
print(ans)
| false | 55.263158 | [
"+import bisect",
"+",
"-i = []",
"-k = []",
"- left = n - 1",
"- right = 0",
"- a_mid = n // 2",
"- while left >= right:",
"- if a[a_mid] >= b[j]:",
"- left = a_mid - 1",
"- else:",
"- right = a_mid + 1",
"- a_mid = (left + right) // 2",
"- i.append(a_mid + 1)",
"-for j in range(n):",
"- left = n - 1",
"- right = 0",
"- c_mid = n // 2",
"- while left >= right:",
"- if c[c_mid] > b[j]:",
"- left = c_mid - 1",
"- else:",
"- right = c_mid + 1",
"- c_mid = (left + right) // 2",
"- k.append(n - c_mid - 1)",
"-ans = sum(x * y for x, y in zip(i, k))",
"+ i = bisect.bisect_left(a, b[j])",
"+ k = n - bisect.bisect_right(c, b[j])",
"+ ans += i * k"
] | false | 0.129422 | 0.173308 | 0.746774 | [
"s691157434",
"s635576428"
] |
u958506960 | p03030 | python | s926723788 | s104415418 | 30 | 26 | 9,192 | 9,144 | Accepted | Accepted | 13.33 | n = int(eval(input()))
l = []
for i in range(n):
sp = input().split()
l.append((sp[0], int(sp[1]), i+1))
a = sorted(l, key=lambda i: i[1], reverse=True)
a = sorted(a, key=lambda i: i[0])
for i in range(n):
print((a[i][2])) | n = int(eval(input()))
l = []
for i in range(n):
sp = input().split()
l.append([sp[0], int(sp[1]), i+1])
s = sorted(l, key=lambda i: (i[0], -i[1]))
for i in range(n):
print((s[i][2])) | 11 | 10 | 238 | 198 | n = int(eval(input()))
l = []
for i in range(n):
sp = input().split()
l.append((sp[0], int(sp[1]), i + 1))
a = sorted(l, key=lambda i: i[1], reverse=True)
a = sorted(a, key=lambda i: i[0])
for i in range(n):
print((a[i][2]))
| n = int(eval(input()))
l = []
for i in range(n):
sp = input().split()
l.append([sp[0], int(sp[1]), i + 1])
s = sorted(l, key=lambda i: (i[0], -i[1]))
for i in range(n):
print((s[i][2]))
| false | 9.090909 | [
"- l.append((sp[0], int(sp[1]), i + 1))",
"-a = sorted(l, key=lambda i: i[1], reverse=True)",
"-a = sorted(a, key=lambda i: i[0])",
"+ l.append([sp[0], int(sp[1]), i + 1])",
"+s = sorted(l, key=lambda i: (i[0], -i[1]))",
"- print((a[i][2]))",
"+ print((s[i][2]))"
] | false | 0.210518 | 0.088228 | 2.386066 | [
"s926723788",
"s104415418"
] |
u942893435 | p02687 | python | s024027289 | s462332215 | 21 | 19 | 9,092 | 8,948 | Accepted | Accepted | 9.52 | S = eval(input())
if(S == 'ABC'):
print('ARC')
elif(S == 'ARC'):
print('ABC')
else:
pass | S = eval(input())
if S == 'ABC':
print('ARC')
else:
print('ABC') | 7 | 5 | 94 | 66 | S = eval(input())
if S == "ABC":
print("ARC")
elif S == "ARC":
print("ABC")
else:
pass
| S = eval(input())
if S == "ABC":
print("ARC")
else:
print("ABC")
| false | 28.571429 | [
"-elif S == \"ARC\":",
"+else:",
"-else:",
"- pass"
] | false | 0.04881 | 0.046014 | 1.060768 | [
"s024027289",
"s462332215"
] |
u431981421 | p02947 | python | s290715956 | s614747660 | 741 | 376 | 25,328 | 25,328 | Accepted | Accepted | 49.26 | from collections import defaultdict
import math
N = int(eval(input()))
li = [eval(input()) for i in range(N)]
d = defaultdict(int)
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
count = 0
for i in li:
s = sorted(list(i))
t = "".join(s)
d[t] += 1
for i in d:
if d[i] > 1:
count += combinations_count(d[i], 2)
print(count) | from collections import defaultdict
import math
N = int(eval(input()))
li = [eval(input()) for i in range(N)]
d = defaultdict(int)
count = 0
for i in li:
s = sorted(list(i))
t = "".join(s)
if d[t] != 0:
count += d[t]
d[t] += 1
print(count) | 23 | 18 | 410 | 265 | from collections import defaultdict
import math
N = int(eval(input()))
li = [eval(input()) for i in range(N)]
d = defaultdict(int)
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
count = 0
for i in li:
s = sorted(list(i))
t = "".join(s)
d[t] += 1
for i in d:
if d[i] > 1:
count += combinations_count(d[i], 2)
print(count)
| from collections import defaultdict
import math
N = int(eval(input()))
li = [eval(input()) for i in range(N)]
d = defaultdict(int)
count = 0
for i in li:
s = sorted(list(i))
t = "".join(s)
if d[t] != 0:
count += d[t]
d[t] += 1
print(count)
| false | 21.73913 | [
"-",
"-",
"-def combinations_count(n, r):",
"- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))",
"-",
"-",
"+ if d[t] != 0:",
"+ count += d[t]",
"-for i in d:",
"- if d[i] > 1:",
"- count += combinations_count(d[i], 2)"
] | false | 0.138018 | 0.048026 | 2.873833 | [
"s290715956",
"s614747660"
] |
u628335443 | p02912 | python | s735634635 | s398704768 | 1,799 | 179 | 14,480 | 14,180 | Accepted | Accepted | 90.05 | def pushHeap(array, elem):
n = len(array)
array.append(elem)
while n != 0:
i = int((n - 1) / 2)
if array[n] > array[i]:
tmp = array[n]
array[n] = array[i]
array[i] = tmp
n = i
def popHeap(array):
n = len(array) - 1
array[0] = array[n]
del array[-1]
i = 0
while 2 * i + 1 < n:
j = 2 * i + 1
if j != n - 1 and array[j] < array[j + 1]:
j += 1
if array[i] < array[j]:
tmp = array[j]
array[j] = array[i]
array[i] = tmp
i = j
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heap_A = []
for a in A:
pushHeap(heap_A, a)
for _ in range(M):
discount_max = int(heap_A[0] / 2)
popHeap(heap_A)
pushHeap(heap_A, discount_max)
print((sum(heap_A)))
| import heapq
N, M = list(map(int, input().split()))
A = list([int(x) * -1 for x in input().split()])
heapq.heapify(A)
for _ in range(M):
a_min = heapq.heappop(A)
heapq.heappush(A, -1 * (-a_min//2))
print((-sum(A)))
| 41 | 11 | 887 | 233 | def pushHeap(array, elem):
n = len(array)
array.append(elem)
while n != 0:
i = int((n - 1) / 2)
if array[n] > array[i]:
tmp = array[n]
array[n] = array[i]
array[i] = tmp
n = i
def popHeap(array):
n = len(array) - 1
array[0] = array[n]
del array[-1]
i = 0
while 2 * i + 1 < n:
j = 2 * i + 1
if j != n - 1 and array[j] < array[j + 1]:
j += 1
if array[i] < array[j]:
tmp = array[j]
array[j] = array[i]
array[i] = tmp
i = j
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heap_A = []
for a in A:
pushHeap(heap_A, a)
for _ in range(M):
discount_max = int(heap_A[0] / 2)
popHeap(heap_A)
pushHeap(heap_A, discount_max)
print((sum(heap_A)))
| import heapq
N, M = list(map(int, input().split()))
A = list([int(x) * -1 for x in input().split()])
heapq.heapify(A)
for _ in range(M):
a_min = heapq.heappop(A)
heapq.heappush(A, -1 * (-a_min // 2))
print((-sum(A)))
| false | 73.170732 | [
"-def pushHeap(array, elem):",
"- n = len(array)",
"- array.append(elem)",
"- while n != 0:",
"- i = int((n - 1) / 2)",
"- if array[n] > array[i]:",
"- tmp = array[n]",
"- array[n] = array[i]",
"- array[i] = tmp",
"- n = i",
"-",
"-",
"-def popHeap(array):",
"- n = len(array) - 1",
"- array[0] = array[n]",
"- del array[-1]",
"- i = 0",
"- while 2 * i + 1 < n:",
"- j = 2 * i + 1",
"- if j != n - 1 and array[j] < array[j + 1]:",
"- j += 1",
"- if array[i] < array[j]:",
"- tmp = array[j]",
"- array[j] = array[i]",
"- array[i] = tmp",
"- i = j",
"-",
"+import heapq",
"-A = list(map(int, input().split()))",
"-heap_A = []",
"-for a in A:",
"- pushHeap(heap_A, a)",
"+A = list([int(x) * -1 for x in input().split()])",
"+heapq.heapify(A)",
"- discount_max = int(heap_A[0] / 2)",
"- popHeap(heap_A)",
"- pushHeap(heap_A, discount_max)",
"-print((sum(heap_A)))",
"+ a_min = heapq.heappop(A)",
"+ heapq.heappush(A, -1 * (-a_min // 2))",
"+print((-sum(A)))"
] | false | 0.042582 | 0.041767 | 1.019504 | [
"s735634635",
"s398704768"
] |
u707124227 | p02715 | python | s292284161 | s318451772 | 307 | 121 | 12,072 | 80,832 | Accepted | Accepted | 60.59 | # ABC162
n,k=list(map(int,input().split()))
"""
3 2
->9
3 200
->10813692
100000 100000
->742202979
"""
ans = 0
xl=[0]*(k+1)
MOD = int(1e+9 + 7)
for x in range(k,0,-1):
xl[x] = pow(k // x,n, MOD)
for x in range(k,0,-1):
xl[x] -= sum([xl[i*x] for i in range(2,1 + k//x)])
ans = 0
for i in range(k+1):
ans += i * xl[i]
print((ans % MOD))
| n,k=list(map(int,input().split()))
# 1以上k以下の整数がn個
mod=int(1e+9 + 7)
d=[0]*(k+1)
ans=0
for i in range(k,0,-1):
m=k//i
d[i]=pow(m,n, mod)
d[i]-=sum([d[j*i]for j in range(2,m+1)])
ans+=(d[i]*i)%mod
print(((ans)%mod))
#print(d)
| 25 | 13 | 368 | 254 | # ABC162
n, k = list(map(int, input().split()))
"""
3 2
->9
3 200
->10813692
100000 100000
->742202979
"""
ans = 0
xl = [0] * (k + 1)
MOD = int(1e9 + 7)
for x in range(k, 0, -1):
xl[x] = pow(k // x, n, MOD)
for x in range(k, 0, -1):
xl[x] -= sum([xl[i * x] for i in range(2, 1 + k // x)])
ans = 0
for i in range(k + 1):
ans += i * xl[i]
print((ans % MOD))
| n, k = list(map(int, input().split()))
# 1以上k以下の整数がn個
mod = int(1e9 + 7)
d = [0] * (k + 1)
ans = 0
for i in range(k, 0, -1):
m = k // i
d[i] = pow(m, n, mod)
d[i] -= sum([d[j * i] for j in range(2, m + 1)])
ans += (d[i] * i) % mod
print(((ans) % mod))
# print(d)
| false | 48 | [
"-# ABC162",
"-\"\"\"",
"-3 2",
"-->9",
"-3 200",
"-->10813692",
"-100000 100000",
"-->742202979",
"-\"\"\"",
"+# 1以上k以下の整数がn個",
"+mod = int(1e9 + 7)",
"+d = [0] * (k + 1)",
"-xl = [0] * (k + 1)",
"-MOD = int(1e9 + 7)",
"-for x in range(k, 0, -1):",
"- xl[x] = pow(k // x, n, MOD)",
"-for x in range(k, 0, -1):",
"- xl[x] -= sum([xl[i * x] for i in range(2, 1 + k // x)])",
"-ans = 0",
"-for i in range(k + 1):",
"- ans += i * xl[i]",
"-print((ans % MOD))",
"+for i in range(k, 0, -1):",
"+ m = k // i",
"+ d[i] = pow(m, n, mod)",
"+ d[i] -= sum([d[j * i] for j in range(2, m + 1)])",
"+ ans += (d[i] * i) % mod",
"+print(((ans) % mod))",
"+# print(d)"
] | false | 0.123157 | 0.466281 | 0.264126 | [
"s292284161",
"s318451772"
] |
u562935282 | p03078 | python | s353652274 | s244753396 | 716 | 575 | 150,824 | 9,548 | Accepted | Accepted | 19.69 | 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()))
d = (aa + bb for aa in a for bb in b)
d = sorted(d, reverse=True)[:K]
e = (cc + dd for cc in c for dd in d)
e = sorted(e, reverse=True)[:K]
print(('\n'.join(map(str, e)))) | 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 = list(sorted(a, reverse=True))
b = list(sorted(b, reverse=True))
c = list(sorted(c, reverse=True))
# 降順ソート
e = []
for i, aa in enumerate(a, 1):
for j, bb in enumerate(b, 1):
for k, cc in enumerate(c, 1):
if i * j * k > K: break
e.append(aa + bb + cc)
for ee in sorted(e, reverse=True)[:K]:
print(ee)
| 16 | 23 | 362 | 555 | 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()))
d = (aa + bb for aa in a for bb in b)
d = sorted(d, reverse=True)[:K]
e = (cc + dd for cc in c for dd in d)
e = sorted(e, reverse=True)[:K]
print(("\n".join(map(str, e))))
| 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 = list(sorted(a, reverse=True))
b = list(sorted(b, reverse=True))
c = list(sorted(c, reverse=True))
# 降順ソート
e = []
for i, aa in enumerate(a, 1):
for j, bb in enumerate(b, 1):
for k, cc in enumerate(c, 1):
if i * j * k > K:
break
e.append(aa + bb + cc)
for ee in sorted(e, reverse=True)[:K]:
print(ee)
| false | 30.434783 | [
"-d = (aa + bb for aa in a for bb in b)",
"-d = sorted(d, reverse=True)[:K]",
"-e = (cc + dd for cc in c for dd in d)",
"-e = sorted(e, reverse=True)[:K]",
"-print((\"\\n\".join(map(str, e))))",
"+a = list(sorted(a, reverse=True))",
"+b = list(sorted(b, reverse=True))",
"+c = list(sorted(c, reverse=True))",
"+# 降順ソート",
"+e = []",
"+for i, aa in enumerate(a, 1):",
"+ for j, bb in enumerate(b, 1):",
"+ for k, cc in enumerate(c, 1):",
"+ if i * j * k > K:",
"+ break",
"+ e.append(aa + bb + cc)",
"+for ee in sorted(e, reverse=True)[:K]:",
"+ print(ee)"
] | false | 0.089294 | 0.007385 | 12.091261 | [
"s353652274",
"s244753396"
] |
u981931040 | p02873 | python | s125422304 | s776847678 | 407 | 344 | 27,056 | 23,336 | Accepted | Accepted | 15.48 | S = list(eval(input()))
numList = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
numList[i + 1] = numList[i] + 1
for i in range(len(S) - 1 , -1 , -1):
if S[i] == '>':
numList[i] = max(numList[i + 1] + 1 ,numList[i])
print((sum(numList))) | S = eval(input())
ans_list = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
ans_list[i + 1] = ans_list[i] + 1
for i in range(len(S) - 1,-1,-1):
if S[i] == '>':
ans_list[i] = max(ans_list[i + 1] + 1, ans_list[i])
print((sum(ans_list))) | 10 | 11 | 275 | 274 | S = list(eval(input()))
numList = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
numList[i + 1] = numList[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == ">":
numList[i] = max(numList[i + 1] + 1, numList[i])
print((sum(numList)))
| S = eval(input())
ans_list = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
ans_list[i + 1] = ans_list[i] + 1
for i in range(len(S) - 1, -1, -1):
if S[i] == ">":
ans_list[i] = max(ans_list[i + 1] + 1, ans_list[i])
print((sum(ans_list)))
| false | 9.090909 | [
"-S = list(eval(input()))",
"-numList = [0] * (len(S) + 1)",
"+S = eval(input())",
"+ans_list = [0] * (len(S) + 1)",
"- numList[i + 1] = numList[i] + 1",
"+ ans_list[i + 1] = ans_list[i] + 1",
"- numList[i] = max(numList[i + 1] + 1, numList[i])",
"-print((sum(numList)))",
"+ ans_list[i] = max(ans_list[i + 1] + 1, ans_list[i])",
"+print((sum(ans_list)))"
] | false | 0.035565 | 0.120047 | 0.296258 | [
"s125422304",
"s776847678"
] |
u597374218 | p03393 | python | s740404718 | s038733100 | 29 | 25 | 8,888 | 9,060 | Accepted | Accepted | 13.79 | S=eval(input())
if len(S)<26:
for char in range(ord("a"),ord("z")):
if chr(char) not in S:
break
print((S+chr(char)))
else:
stack=list(S[-1])
for s in S[len(S)-2::-1]:
if s>stack[-1]:
stack.append(s)
else:
break
if len(stack)==26:
print((-1))
else:
print((S[:-len(stack)-1]+min(s for s in stack if s>S[-len(stack)-1]))) | S=eval(input())
if len(S)<26:
for char in range(ord("a"),ord("z")):
if chr(char) not in S:
break
print((S+chr(char)))
else:
stack=list(S[-1])
for s in S[len(S)-2::-1]:
if s>stack[-1]:
stack.append(s)
else:
break
if len(stack)==26:
print((-1))
else:
print((S[0:len(S)-len(stack)-1]+min(char for char in stack if char>S[-len(stack)-1]))) | 17 | 17 | 423 | 439 | S = eval(input())
if len(S) < 26:
for char in range(ord("a"), ord("z")):
if chr(char) not in S:
break
print((S + chr(char)))
else:
stack = list(S[-1])
for s in S[len(S) - 2 :: -1]:
if s > stack[-1]:
stack.append(s)
else:
break
if len(stack) == 26:
print((-1))
else:
print((S[: -len(stack) - 1] + min(s for s in stack if s > S[-len(stack) - 1])))
| S = eval(input())
if len(S) < 26:
for char in range(ord("a"), ord("z")):
if chr(char) not in S:
break
print((S + chr(char)))
else:
stack = list(S[-1])
for s in S[len(S) - 2 :: -1]:
if s > stack[-1]:
stack.append(s)
else:
break
if len(stack) == 26:
print((-1))
else:
print(
(
S[0 : len(S) - len(stack) - 1]
+ min(char for char in stack if char > S[-len(stack) - 1])
)
)
| false | 0 | [
"- print((S[: -len(stack) - 1] + min(s for s in stack if s > S[-len(stack) - 1])))",
"+ print(",
"+ (",
"+ S[0 : len(S) - len(stack) - 1]",
"+ + min(char for char in stack if char > S[-len(stack) - 1])",
"+ )",
"+ )"
] | false | 0.084841 | 0.040259 | 2.107349 | [
"s740404718",
"s038733100"
] |
u394731058 | p02911 | python | s432763440 | s221427108 | 140 | 125 | 4,680 | 6,620 | Accepted | Accepted | 10.71 | import sys
input = sys.stdin.readline
def main():
N, K, Q = list(map(int, input().split()))
a = [0]*N
for _ in range(Q):
a[int(eval(input()))-1] += 1
for i in range(N):
if a[i] - Q + K > 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | import sys
input = sys.stdin.readline
def main():
N, K, Q = list(map(int, input().split()))
a = [K-Q]*N
for _ in range(Q):
a[int(eval(input()))-1] += 1
for i in range(N):
if a[i] > 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 17 | 17 | 329 | 323 | import sys
input = sys.stdin.readline
def main():
N, K, Q = list(map(int, input().split()))
a = [0] * N
for _ in range(Q):
a[int(eval(input())) - 1] += 1
for i in range(N):
if a[i] - Q + K > 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
N, K, Q = list(map(int, input().split()))
a = [K - Q] * N
for _ in range(Q):
a[int(eval(input())) - 1] += 1
for i in range(N):
if a[i] > 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| false | 0 | [
"- a = [0] * N",
"+ a = [K - Q] * N",
"- if a[i] - Q + K > 0:",
"+ if a[i] > 0:"
] | false | 0.043745 | 0.040863 | 1.070533 | [
"s432763440",
"s221427108"
] |
u546338822 | p02684 | python | s660367847 | s680273646 | 140 | 128 | 32,260 | 32,232 | Accepted | Accepted | 8.57 | def main():
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
visited = [0 for i in range(n)]
visit = [0]
visited[0]=1
s = 0
while True:
s = a[s]-1
if visited[s]==1:
x = visit[0:visit.index(s)]
y = visit[visit.index(s):]
break
visit.append(s)
visited[s]=1
if k<len(x):
print((x[k]+1))
else:
k = k-len(x)
print((y[k%len(y)]+1))
if __name__ == "__main__":
main()
| def main():
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
vis = [0 for i in range(n)]
vis[0] = 1
fst = [1]
st = a[0]-1
while True:
if vis[st] == 0:
vis[st] = 1
fst.append(st+1)
st = a[st]-1
else:
st = fst.index(st+1)
loop = fst[st:]
break
if k < len(fst):
print((fst[k]))
else:
k = k - len(fst) + 1
k = k%len(loop)
print((loop[k-1]))
if __name__ == "__main__":
main()
| 25 | 26 | 532 | 575 | def main():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
visited = [0 for i in range(n)]
visit = [0]
visited[0] = 1
s = 0
while True:
s = a[s] - 1
if visited[s] == 1:
x = visit[0 : visit.index(s)]
y = visit[visit.index(s) :]
break
visit.append(s)
visited[s] = 1
if k < len(x):
print((x[k] + 1))
else:
k = k - len(x)
print((y[k % len(y)] + 1))
if __name__ == "__main__":
main()
| def main():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
vis = [0 for i in range(n)]
vis[0] = 1
fst = [1]
st = a[0] - 1
while True:
if vis[st] == 0:
vis[st] = 1
fst.append(st + 1)
st = a[st] - 1
else:
st = fst.index(st + 1)
loop = fst[st:]
break
if k < len(fst):
print((fst[k]))
else:
k = k - len(fst) + 1
k = k % len(loop)
print((loop[k - 1]))
if __name__ == "__main__":
main()
| false | 3.846154 | [
"- visited = [0 for i in range(n)]",
"- visit = [0]",
"- visited[0] = 1",
"- s = 0",
"+ vis = [0 for i in range(n)]",
"+ vis[0] = 1",
"+ fst = [1]",
"+ st = a[0] - 1",
"- s = a[s] - 1",
"- if visited[s] == 1:",
"- x = visit[0 : visit.index(s)]",
"- y = visit[visit.index(s) :]",
"+ if vis[st] == 0:",
"+ vis[st] = 1",
"+ fst.append(st + 1)",
"+ st = a[st] - 1",
"+ else:",
"+ st = fst.index(st + 1)",
"+ loop = fst[st:]",
"- visit.append(s)",
"- visited[s] = 1",
"- if k < len(x):",
"- print((x[k] + 1))",
"+ if k < len(fst):",
"+ print((fst[k]))",
"- k = k - len(x)",
"- print((y[k % len(y)] + 1))",
"+ k = k - len(fst) + 1",
"+ k = k % len(loop)",
"+ print((loop[k - 1]))"
] | false | 0.038133 | 0.046351 | 0.822698 | [
"s660367847",
"s680273646"
] |
u047796752 | p02743 | python | s141066541 | s140313525 | 96 | 72 | 61,284 | 61,296 | Accepted | Accepted | 25 | a, b, c = list(map(int, input().split()))
if c-a-b>0 and 4*a*b<(c-a-b)**2:
print('Yes')
else:
print('No') | a, b, c = list(map(int, input().split()))
if c-a-b>=0 and 4*a*b<(c-a-b)**2:
print('Yes')
else:
print('No') | 6 | 6 | 113 | 114 | a, b, c = list(map(int, input().split()))
if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if c - a - b >= 0 and 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
| false | 0 | [
"-if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:",
"+if c - a - b >= 0 and 4 * a * b < (c - a - b) ** 2:"
] | false | 0.108244 | 0.0474 | 2.283608 | [
"s141066541",
"s140313525"
] |
u564902833 | p03045 | python | s275747186 | s571148301 | 950 | 726 | 135,616 | 63,760 | Accepted | Accepted | 23.58 | import sys
sys.setrecursionlimit(2*10**5)
N, M = list(map(int, input().split()))
X, Y, Z = (
list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else
((), ())
)
G = [set() for _ in range(N + 1)]
for x, y in zip(X, Y):
G[x].add(y)
G[y].add(x)
dp = [-1 for _ in range(N + 1)]
def f(i, k):
for t in G[i]:
if dp[t] == -1:
dp[t] = k
f(t, k)
L = 0
for i in range(1, N + 1):
if dp[i] == -1:
L += 1
f(i, L)
ans = L
print(ans)
| # 入力
N, M = list(map(int, input().split()))
X, Y, Z = (
list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else
((), (), ())
)
# UnionFind木で連結成分の個数を数える
class UnionFindTree:
def __init__(self, n):
self.p = [i for i in range(n + 1)]
self.r = [0 for _ in range(n + 1)]
def find(self, x):
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
px = self.find(x)
py = self.find(y)
if px != py:
if self.r[px] < self.r[py]:
self.p[px] = py
else:
self.p[py] = px
if self.r[px] == self.r[py]:
self.r[px] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
uft = UnionFindTree(N)
for x, y in zip(X, Y):
uft.union(x, y)
ans = len({uft.find(i) for i in range(1, N + 1)})
# 出力
print(ans)
| 33 | 41 | 530 | 967 | import sys
sys.setrecursionlimit(2 * 10**5)
N, M = list(map(int, input().split()))
X, Y, Z = (
list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else ((), ())
)
G = [set() for _ in range(N + 1)]
for x, y in zip(X, Y):
G[x].add(y)
G[y].add(x)
dp = [-1 for _ in range(N + 1)]
def f(i, k):
for t in G[i]:
if dp[t] == -1:
dp[t] = k
f(t, k)
L = 0
for i in range(1, N + 1):
if dp[i] == -1:
L += 1
f(i, L)
ans = L
print(ans)
| # 入力
N, M = list(map(int, input().split()))
X, Y, Z = (
list(zip(*(list(map(int, input().split())) for _ in range(M))))
if M
else ((), (), ())
)
# UnionFind木で連結成分の個数を数える
class UnionFindTree:
def __init__(self, n):
self.p = [i for i in range(n + 1)]
self.r = [0 for _ in range(n + 1)]
def find(self, x):
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
px = self.find(x)
py = self.find(y)
if px != py:
if self.r[px] < self.r[py]:
self.p[px] = py
else:
self.p[py] = px
if self.r[px] == self.r[py]:
self.r[px] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
uft = UnionFindTree(N)
for x, y in zip(X, Y):
uft.union(x, y)
ans = len({uft.find(i) for i in range(1, N + 1)})
# 出力
print(ans)
| false | 19.512195 | [
"-import sys",
"-",
"-sys.setrecursionlimit(2 * 10**5)",
"+# 入力",
"- list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else ((), ())",
"+ list(zip(*(list(map(int, input().split())) for _ in range(M))))",
"+ if M",
"+ else ((), (), ())",
"-G = [set() for _ in range(N + 1)]",
"-for x, y in zip(X, Y):",
"- G[x].add(y)",
"- G[y].add(x)",
"-dp = [-1 for _ in range(N + 1)]",
"+# UnionFind木で連結成分の個数を数える",
"+class UnionFindTree:",
"+ def __init__(self, n):",
"+ self.p = [i for i in range(n + 1)]",
"+ self.r = [0 for _ in range(n + 1)]",
"+",
"+ def find(self, x):",
"+ if self.p[x] != x:",
"+ self.p[x] = self.find(self.p[x])",
"+ return self.p[x]",
"+",
"+ def union(self, x, y):",
"+ px = self.find(x)",
"+ py = self.find(y)",
"+ if px != py:",
"+ if self.r[px] < self.r[py]:",
"+ self.p[px] = py",
"+ else:",
"+ self.p[py] = px",
"+ if self.r[px] == self.r[py]:",
"+ self.r[px] += 1",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"-def f(i, k):",
"- for t in G[i]:",
"- if dp[t] == -1:",
"- dp[t] = k",
"- f(t, k)",
"-",
"-",
"-L = 0",
"-for i in range(1, N + 1):",
"- if dp[i] == -1:",
"- L += 1",
"- f(i, L)",
"-ans = L",
"+uft = UnionFindTree(N)",
"+for x, y in zip(X, Y):",
"+ uft.union(x, y)",
"+ans = len({uft.find(i) for i in range(1, N + 1)})",
"+# 出力"
] | false | 0.063015 | 0.167867 | 0.375388 | [
"s275747186",
"s571148301"
] |
u554781254 | p03478 | python | s171328089 | s811768942 | 207 | 188 | 42,476 | 39,024 | Accepted | Accepted | 9.18 | import sys
input = sys.stdin.readline
INF = float('inf')
def number2digits(number):
return list(map(int, str(number)))
def main():
N, A, B = list(map(int, input().split()))
ans = 0
for number in range(1, N+1):
num_digits_list = number2digits(number)
total = 0
for i in num_digits_list:
total += int(i)
if A <= total <= B:
ans += number
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
INF = float('inf')
def number2digits(number):
return list(map(int, str(number)))
def sum_of_digits(number):
sum = 0
while number > 0:
sum += number % 10
number //= 10
return sum
def main():
N, A, B = list(map(int, input().split()))
ans = 0
for number in range(1, N+1):
total = sum_of_digits(number)
if A <= total <= B:
ans += number
print(ans)
if __name__ == '__main__':
main()
| 25 | 31 | 486 | 530 | import sys
input = sys.stdin.readline
INF = float("inf")
def number2digits(number):
return list(map(int, str(number)))
def main():
N, A, B = list(map(int, input().split()))
ans = 0
for number in range(1, N + 1):
num_digits_list = number2digits(number)
total = 0
for i in num_digits_list:
total += int(i)
if A <= total <= B:
ans += number
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
INF = float("inf")
def number2digits(number):
return list(map(int, str(number)))
def sum_of_digits(number):
sum = 0
while number > 0:
sum += number % 10
number //= 10
return sum
def main():
N, A, B = list(map(int, input().split()))
ans = 0
for number in range(1, N + 1):
total = sum_of_digits(number)
if A <= total <= B:
ans += number
print(ans)
if __name__ == "__main__":
main()
| false | 19.354839 | [
"+def sum_of_digits(number):",
"+ sum = 0",
"+ while number > 0:",
"+ sum += number % 10",
"+ number //= 10",
"+ return sum",
"+",
"+",
"- num_digits_list = number2digits(number)",
"- total = 0",
"- for i in num_digits_list:",
"- total += int(i)",
"+ total = sum_of_digits(number)"
] | false | 0.036387 | 0.054257 | 0.670637 | [
"s171328089",
"s811768942"
] |
u342869120 | p02991 | python | s599043708 | s503351872 | 394 | 351 | 40,408 | 111,356 | Accepted | Accepted | 10.91 | from collections import defaultdict, deque
def kenkenpa(s, visited):
res = []
for v1 in e[s]:
if visited[v1][1]:
continue
visited[v1][1] = True
for v2 in e[v1]:
if visited[v2][2]:
continue
visited[v2][2] = True
for v3 in e[v2]:
if visited[v3][0]:
continue
visited[v3][0] = True
res.append(v3)
return res
N, M = list(map(int, input().split()))
e = defaultdict(list)
for i in range(M):
u, v = list(map(int, input().split()))
e[u].append(v)
S, T = list(map(int, input().split()))
q = deque([[S, 0]])
visited = [[False]*3 for _ in range(N+1)]
visited[S][0] = True
ans = -1
while q:
u, c = q.popleft()
if u == T:
ans = c
break
l = kenkenpa(u, visited)
for v in l:
q.append([v, c+1])
print(ans)
| from collections import defaultdict, deque
N, M = list(map(int, input().split()))
e = defaultdict(list)
for i in range(M):
u, v = list(map(int, input().split()))
e[u].append(v)
'''
頂点を%3で考える(1つの頂点にを3つに分解する)
(u,0)->(v,1)
(v,1)->(u,2)
(u,2)->(v,0)
'''
S, T = list(map(int, input().split()))
q = deque([[S, 0]])
dist = [[-3]*3 for _ in range(N+1)]
dist[S][0] = 0
while q:
u, c = q.popleft()
for v in e[u]:
step = (c+1) % 3
if dist[v][step] < 0:
dist[v][step] = c+1
q.append([v, c+1])
print((dist[T][0]//3)) | 41 | 28 | 932 | 570 | from collections import defaultdict, deque
def kenkenpa(s, visited):
res = []
for v1 in e[s]:
if visited[v1][1]:
continue
visited[v1][1] = True
for v2 in e[v1]:
if visited[v2][2]:
continue
visited[v2][2] = True
for v3 in e[v2]:
if visited[v3][0]:
continue
visited[v3][0] = True
res.append(v3)
return res
N, M = list(map(int, input().split()))
e = defaultdict(list)
for i in range(M):
u, v = list(map(int, input().split()))
e[u].append(v)
S, T = list(map(int, input().split()))
q = deque([[S, 0]])
visited = [[False] * 3 for _ in range(N + 1)]
visited[S][0] = True
ans = -1
while q:
u, c = q.popleft()
if u == T:
ans = c
break
l = kenkenpa(u, visited)
for v in l:
q.append([v, c + 1])
print(ans)
| from collections import defaultdict, deque
N, M = list(map(int, input().split()))
e = defaultdict(list)
for i in range(M):
u, v = list(map(int, input().split()))
e[u].append(v)
"""
頂点を%3で考える(1つの頂点にを3つに分解する)
(u,0)->(v,1)
(v,1)->(u,2)
(u,2)->(v,0)
"""
S, T = list(map(int, input().split()))
q = deque([[S, 0]])
dist = [[-3] * 3 for _ in range(N + 1)]
dist[S][0] = 0
while q:
u, c = q.popleft()
for v in e[u]:
step = (c + 1) % 3
if dist[v][step] < 0:
dist[v][step] = c + 1
q.append([v, c + 1])
print((dist[T][0] // 3))
| false | 31.707317 | [
"-",
"-",
"-def kenkenpa(s, visited):",
"- res = []",
"- for v1 in e[s]:",
"- if visited[v1][1]:",
"- continue",
"- visited[v1][1] = True",
"- for v2 in e[v1]:",
"- if visited[v2][2]:",
"- continue",
"- visited[v2][2] = True",
"- for v3 in e[v2]:",
"- if visited[v3][0]:",
"- continue",
"- visited[v3][0] = True",
"- res.append(v3)",
"- return res",
"-",
"+\"\"\"",
"+頂点を%3で考える(1つの頂点にを3つに分解する)",
"+(u,0)->(v,1)",
"+(v,1)->(u,2)",
"+(u,2)->(v,0)",
"+\"\"\"",
"-visited = [[False] * 3 for _ in range(N + 1)]",
"-visited[S][0] = True",
"-ans = -1",
"+dist = [[-3] * 3 for _ in range(N + 1)]",
"+dist[S][0] = 0",
"- if u == T:",
"- ans = c",
"- break",
"- l = kenkenpa(u, visited)",
"- for v in l:",
"- q.append([v, c + 1])",
"-print(ans)",
"+ for v in e[u]:",
"+ step = (c + 1) % 3",
"+ if dist[v][step] < 0:",
"+ dist[v][step] = c + 1",
"+ q.append([v, c + 1])",
"+print((dist[T][0] // 3))"
] | false | 0.059672 | 0.036126 | 1.65175 | [
"s599043708",
"s503351872"
] |
u816631826 | p02711 | python | s764739751 | s623675352 | 26 | 23 | 8,780 | 8,740 | Accepted | Accepted | 11.54 | num = eval(input())
if '7' in list(num):
print('Yes')
else:
print('No')
| in_set = set(eval(input()))
if '7' in in_set:
print('Yes')
else:
print('No') | 5 | 5 | 78 | 82 | num = eval(input())
if "7" in list(num):
print("Yes")
else:
print("No")
| in_set = set(eval(input()))
if "7" in in_set:
print("Yes")
else:
print("No")
| false | 0 | [
"-num = eval(input())",
"-if \"7\" in list(num):",
"+in_set = set(eval(input()))",
"+if \"7\" in in_set:"
] | false | 0.043466 | 0.079619 | 0.545922 | [
"s764739751",
"s623675352"
] |
u018679195 | p03813 | python | s835120070 | s139306204 | 49 | 17 | 5,868 | 3,064 | Accepted | Accepted | 65.31 | import sys
import math
import random
import threading
import time
from functools import reduce
a = int(eval(input()));
if a < 1200:
print("ABC")
else:
print("ARC"); | x=int(eval(input()))
if (x>=1200):
print('ARC')
else:
print('ABC')
| 13 | 5 | 180 | 73 | import sys
import math
import random
import threading
import time
from functools import reduce
a = int(eval(input()))
if a < 1200:
print("ABC")
else:
print("ARC")
| x = int(eval(input()))
if x >= 1200:
print("ARC")
else:
print("ABC")
| false | 61.538462 | [
"-import sys",
"-import math",
"-import random",
"-import threading",
"-import time",
"-from functools import reduce",
"-",
"-a = int(eval(input()))",
"-if a < 1200:",
"+x = int(eval(input()))",
"+if x >= 1200:",
"+ print(\"ARC\")",
"+else:",
"-else:",
"- print(\"ARC\")"
] | false | 0.043245 | 0.033443 | 1.293106 | [
"s835120070",
"s139306204"
] |
u255673886 | p02837 | python | s329875626 | s903487698 | 498 | 433 | 45,532 | 44,396 | Accepted | Accepted | 13.05 | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = []
xy = []
for i in range(n):
a.append(int(eval(input())))
xy.append([ list(map(int,input().split())) for _ in range(a[i]) ])
# print(a)
# print(xy)
ls = [-1]*n
ans = 0
for i in range(2**n):
b = str(bin(i))[2:]
c = b.zfill(n)
# print(c)
numbers = sum(list(map(int,list(str(c)))))
for j in range(n):
if c[j]=="0":
pass
else:
for k in range(a[j]):
x = xy[j][k][0]
y = xy[j][k][1]
# print(x,y)
if c[x-1]==str(y):
pass
else:
numbers = 0
# print("--")
ans = max(ans,numbers)
# print("------")
print(ans) | from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int,input().split()))
def mylistinput(n):
return [ list(myinput()) for _ in range(n) ]
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse_flag):
data.sort(key=lambda x:x[col],reverse=reverse_flag)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
n = int(eval(input()))
ls_a = []
ls_xy = []
for i in range(n):
a = int(eval(input()))
ls_a.append(a)
xy = mylistinput(a)
ls_xy.append(xy)
# print(a)
# print(ls_xy)
ans = 0
for i in range(2**n):
flag = True
for j in range(n):
if i & (2**j):
for k in range(len(ls_xy[j])):
x = ls_xy[j][k][0] - 1
y = ls_xy[j][k][1]
if y==1:
if i & (2**x) > 0:
pass
else:
flag = False
elif y==0:
if i & (2**x) == 0:
pass
else:
flag = False
if flag:
tmp = sum( list(map(int,list(bin(i)[2:]))) )
ans = max( ans, tmp )
print(ans) | 37 | 100 | 795 | 2,521 | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = []
xy = []
for i in range(n):
a.append(int(eval(input())))
xy.append([list(map(int, input().split())) for _ in range(a[i])])
# print(a)
# print(xy)
ls = [-1] * n
ans = 0
for i in range(2**n):
b = str(bin(i))[2:]
c = b.zfill(n)
# print(c)
numbers = sum(list(map(int, list(str(c)))))
for j in range(n):
if c[j] == "0":
pass
else:
for k in range(a[j]):
x = xy[j][k][0]
y = xy[j][k][1]
# print(x,y)
if c[x - 1] == str(y):
pass
else:
numbers = 0
# print("--")
ans = max(ans, numbers)
# print("------")
print(ans)
| from collections import deque
from heapq import heapify, heappop, heappush, heappushpop
from copy import copy, deepcopy
from itertools import product, permutations, combinations, combinations_with_replacement
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int, input().split()))
def mylistinput(n):
return [list(myinput()) for _ in range(n)]
def mycol(data, col):
return [row[col] for row in data]
def mysort(data, col, reverse_flag):
data.sort(key=lambda x: x[col], reverse=reverse_flag)
return data
def mymax(data):
M = -1 * float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M, m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m, M)
return m
def mycount(ls, x):
# lsはソート済みであること
l = bisect_left(ls, x)
r = bisect_right(ls, x)
return r - l
def myoutput(ls, space=True):
if space:
if len(ls) == 0:
print(" ")
elif type(ls[0]) == str:
print((" ".join(ls)))
elif type(ls[0]) == int:
print((" ".join(map(str, ls))))
else:
print("Output Error")
else:
if len(ls) == 0:
print("")
elif type(ls[0]) == str:
print(("".join(ls)))
elif type(ls[0]) == int:
print(("".join(map(str, ls))))
else:
print("Output Error")
n = int(eval(input()))
ls_a = []
ls_xy = []
for i in range(n):
a = int(eval(input()))
ls_a.append(a)
xy = mylistinput(a)
ls_xy.append(xy)
# print(a)
# print(ls_xy)
ans = 0
for i in range(2**n):
flag = True
for j in range(n):
if i & (2**j):
for k in range(len(ls_xy[j])):
x = ls_xy[j][k][0] - 1
y = ls_xy[j][k][1]
if y == 1:
if i & (2**x) > 0:
pass
else:
flag = False
elif y == 0:
if i & (2**x) == 0:
pass
else:
flag = False
if flag:
tmp = sum(list(map(int, list(bin(i)[2:]))))
ans = max(ans, tmp)
print(ans)
| false | 63 | [
"-import sys",
"+from collections import deque",
"+from heapq import heapify, heappop, heappush, heappushpop",
"+from copy import copy, deepcopy",
"+from itertools import product, permutations, combinations, combinations_with_replacement",
"+from collections import defaultdict, Counter",
"+from bisect import bisect_left, bisect_right",
"-input = sys.stdin.readline",
"+# from math import gcd,ceil,floor,factorial",
"+# from fractions import gcd",
"+from functools import reduce",
"+from pprint import pprint",
"+",
"+INF = float(\"inf\")",
"+",
"+",
"+def myinput():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def mylistinput(n):",
"+ return [list(myinput()) for _ in range(n)]",
"+",
"+",
"+def mycol(data, col):",
"+ return [row[col] for row in data]",
"+",
"+",
"+def mysort(data, col, reverse_flag):",
"+ data.sort(key=lambda x: x[col], reverse=reverse_flag)",
"+ return data",
"+",
"+",
"+def mymax(data):",
"+ M = -1 * float(\"inf\")",
"+ for i in range(len(data)):",
"+ m = max(data[i])",
"+ M = max(M, m)",
"+ return M",
"+",
"+",
"+def mymin(data):",
"+ m = float(\"inf\")",
"+ for i in range(len(data)):",
"+ M = min(data[i])",
"+ m = min(m, M)",
"+ return m",
"+",
"+",
"+def mycount(ls, x):",
"+ # lsはソート済みであること",
"+ l = bisect_left(ls, x)",
"+ r = bisect_right(ls, x)",
"+ return r - l",
"+",
"+",
"+def myoutput(ls, space=True):",
"+ if space:",
"+ if len(ls) == 0:",
"+ print(\" \")",
"+ elif type(ls[0]) == str:",
"+ print((\" \".join(ls)))",
"+ elif type(ls[0]) == int:",
"+ print((\" \".join(map(str, ls))))",
"+ else:",
"+ print(\"Output Error\")",
"+ else:",
"+ if len(ls) == 0:",
"+ print(\"\")",
"+ elif type(ls[0]) == str:",
"+ print((\"\".join(ls)))",
"+ elif type(ls[0]) == int:",
"+ print((\"\".join(map(str, ls))))",
"+ else:",
"+ print(\"Output Error\")",
"+",
"+",
"-a = []",
"-xy = []",
"+ls_a = []",
"+ls_xy = []",
"- a.append(int(eval(input())))",
"- xy.append([list(map(int, input().split())) for _ in range(a[i])])",
"+ a = int(eval(input()))",
"+ ls_a.append(a)",
"+ xy = mylistinput(a)",
"+ ls_xy.append(xy)",
"-# print(xy)",
"-ls = [-1] * n",
"+# print(ls_xy)",
"- b = str(bin(i))[2:]",
"- c = b.zfill(n)",
"- # print(c)",
"- numbers = sum(list(map(int, list(str(c)))))",
"+ flag = True",
"- if c[j] == \"0\":",
"- pass",
"- else:",
"- for k in range(a[j]):",
"- x = xy[j][k][0]",
"- y = xy[j][k][1]",
"- # print(x,y)",
"- if c[x - 1] == str(y):",
"- pass",
"- else:",
"- numbers = 0",
"- # print(\"--\")",
"- ans = max(ans, numbers)",
"+ if i & (2**j):",
"+ for k in range(len(ls_xy[j])):",
"+ x = ls_xy[j][k][0] - 1",
"+ y = ls_xy[j][k][1]",
"+ if y == 1:",
"+ if i & (2**x) > 0:",
"+ pass",
"+ else:",
"+ flag = False",
"+ elif y == 0:",
"+ if i & (2**x) == 0:",
"+ pass",
"+ else:",
"+ flag = False",
"+ if flag:",
"+ tmp = sum(list(map(int, list(bin(i)[2:]))))",
"+ ans = max(ans, tmp)"
] | false | 0.079205 | 0.140482 | 0.563811 | [
"s329875626",
"s903487698"
] |
u130203301 | p03835 | python | s335645873 | s551030574 | 254 | 223 | 41,068 | 40,304 | Accepted | Accepted | 12.2 | k, s = list(map(int, input().split()))
result = 0
for i in range(k+1):
for j in range(k+1):
if s-i-j <= k and s-i-j >= 0:
result += 1
print(result) | k, s = list(map(int, input().split()))
def fun(k, s):
count = 0
for i in range(k+1):
for j in range(k+1):
if s - i - j <= k and s - i - j >= 0:
count += 1
return count
print((fun(k, s))) | 10 | 12 | 177 | 240 | k, s = list(map(int, input().split()))
result = 0
for i in range(k + 1):
for j in range(k + 1):
if s - i - j <= k and s - i - j >= 0:
result += 1
print(result)
| k, s = list(map(int, input().split()))
def fun(k, s):
count = 0
for i in range(k + 1):
for j in range(k + 1):
if s - i - j <= k and s - i - j >= 0:
count += 1
return count
print((fun(k, s)))
| false | 16.666667 | [
"-result = 0",
"-for i in range(k + 1):",
"- for j in range(k + 1):",
"- if s - i - j <= k and s - i - j >= 0:",
"- result += 1",
"-print(result)",
"+",
"+",
"+def fun(k, s):",
"+ count = 0",
"+ for i in range(k + 1):",
"+ for j in range(k + 1):",
"+ if s - i - j <= k and s - i - j >= 0:",
"+ count += 1",
"+ return count",
"+",
"+",
"+print((fun(k, s)))"
] | false | 0.038907 | 0.037163 | 1.046946 | [
"s335645873",
"s551030574"
] |
u506858457 | p02684 | python | s757649874 | s527730436 | 137 | 108 | 32,236 | 100,164 | Accepted | Accepted | 21.17 | N,K = list(map(int,input().split()))
A = [0] + list(map(int,input().split()))
turn = [-1] * (N+1) # いつ訪問したかを記録する
c = 1
for k in range(K):
if turn[c]!=-1:
T = k - turn[c] # 周期
bias = turn[c] # バイアス
break
turn[c] = k
c = A[c]
else:
print (c)
exit()
K -= bias
K %= T
K += bias
c = 1
for k in range(K):# 小さくしたKでシミュレーションし直す
c = A[c]
print (c) | def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
N,K=MI()
A=[0]+LI()
c=1
turn=[-1]*(N+1)
for k in range(K):
if turn[c]!=-1:
T=k-turn[c]
bias=turn[c]
break
turn[c]=k
c=A[c]
else:
print(c)
exit()
K-=bias
K%=T
K+=bias
c=1
for k in range(K):
c=A[c]
print(c) | 22 | 23 | 403 | 342 | N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
turn = [-1] * (N + 1) # いつ訪問したかを記録する
c = 1
for k in range(K):
if turn[c] != -1:
T = k - turn[c] # 周期
bias = turn[c] # バイアス
break
turn[c] = k
c = A[c]
else:
print(c)
exit()
K -= bias
K %= T
K += bias
c = 1
for k in range(K): # 小さくしたKでシミュレーションし直す
c = A[c]
print(c)
| def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
N, K = MI()
A = [0] + LI()
c = 1
turn = [-1] * (N + 1)
for k in range(K):
if turn[c] != -1:
T = k - turn[c]
bias = turn[c]
break
turn[c] = k
c = A[c]
else:
print(c)
exit()
K -= bias
K %= T
K += bias
c = 1
for k in range(K):
c = A[c]
print(c)
| false | 4.347826 | [
"-N, K = list(map(int, input().split()))",
"-A = [0] + list(map(int, input().split()))",
"-turn = [-1] * (N + 1) # いつ訪問したかを記録する",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+N, K = MI()",
"+A = [0] + LI()",
"+turn = [-1] * (N + 1)",
"- T = k - turn[c] # 周期",
"- bias = turn[c] # バイアス",
"+ T = k - turn[c]",
"+ bias = turn[c]",
"-for k in range(K): # 小さくしたKでシミュレーションし直す",
"+for k in range(K):"
] | false | 0.046154 | 0.127964 | 0.360679 | [
"s757649874",
"s527730436"
] |
u729133443 | p03624 | python | s322885363 | s110109705 | 181 | 19 | 45,168 | 3,188 | Accepted | Accepted | 89.5 | print((min(set(map(chr,list(range(97,123))))-set(eval(input()))or['None']))) | print((min(set(map(chr,list(range(97,123))))-set(eval(input()))or[None]))) | 1 | 1 | 62 | 60 | print((min(set(map(chr, list(range(97, 123)))) - set(eval(input())) or ["None"])))
| print((min(set(map(chr, list(range(97, 123)))) - set(eval(input())) or [None])))
| false | 0 | [
"-print((min(set(map(chr, list(range(97, 123)))) - set(eval(input())) or [\"None\"])))",
"+print((min(set(map(chr, list(range(97, 123)))) - set(eval(input())) or [None])))"
] | false | 0.034169 | 0.039322 | 0.868945 | [
"s322885363",
"s110109705"
] |
u623819879 | p03291 | python | s645816825 | s975378749 | 580 | 254 | 27,616 | 45,168 | Accepted | Accepted | 56.21 | s=eval(input())
n=len(s)
dc=dict()
dc['A']=0
dc['B']=1
dc['C']=2
dc['?']=3
dp=[[0 for i in range(4)] for j in range(n+1)]
dp[0][0]=1
mo=10**9+7
for i in range(n):
for t in range(4):
ch=s[i]
m = 1 if dc[ch]==t-1 or dc[ch]==3 else 0
if t!=0:
dp[i+1][t]+=(dp[i][t-1]*m)%mo
dp[i+1][t]+=(dp[i][t]*(3 if dc[ch]==3 else 1))%mo
ans=dp[n][3]
print((ans%mo))
| mo=10**9+7
s=eval(input())
n=len(s)
dp=[[0]*(1+n) for i in range(3)]
cc=0
for i in range(n):
c=s[i]
if c=='A':
da=1
db=0
dc=0
dd=1
elif c=='B':
da=0
db=1
dc=0
dd=1
elif c=='C':
da=0
db=0
dc=1
dd=1
elif c=='?':
da=1
db=1
dc=1
dd=3
dp[0][i+1]=dp[0][i]*dd+da*pow(3,cc,mo)
dp[1][i+1]=dp[1][i]*dd+dp[0][i]*db
dp[2][i+1]=dp[2][i]*dd+dp[1][i]*dc
dp[0][i+1]%=mo
dp[1][i+1]%=mo
dp[2][i+1]%=mo
if c=='?':
cc+=1
print((dp[2][n]%mo)) | 21 | 38 | 411 | 644 | s = eval(input())
n = len(s)
dc = dict()
dc["A"] = 0
dc["B"] = 1
dc["C"] = 2
dc["?"] = 3
dp = [[0 for i in range(4)] for j in range(n + 1)]
dp[0][0] = 1
mo = 10**9 + 7
for i in range(n):
for t in range(4):
ch = s[i]
m = 1 if dc[ch] == t - 1 or dc[ch] == 3 else 0
if t != 0:
dp[i + 1][t] += (dp[i][t - 1] * m) % mo
dp[i + 1][t] += (dp[i][t] * (3 if dc[ch] == 3 else 1)) % mo
ans = dp[n][3]
print((ans % mo))
| mo = 10**9 + 7
s = eval(input())
n = len(s)
dp = [[0] * (1 + n) for i in range(3)]
cc = 0
for i in range(n):
c = s[i]
if c == "A":
da = 1
db = 0
dc = 0
dd = 1
elif c == "B":
da = 0
db = 1
dc = 0
dd = 1
elif c == "C":
da = 0
db = 0
dc = 1
dd = 1
elif c == "?":
da = 1
db = 1
dc = 1
dd = 3
dp[0][i + 1] = dp[0][i] * dd + da * pow(3, cc, mo)
dp[1][i + 1] = dp[1][i] * dd + dp[0][i] * db
dp[2][i + 1] = dp[2][i] * dd + dp[1][i] * dc
dp[0][i + 1] %= mo
dp[1][i + 1] %= mo
dp[2][i + 1] %= mo
if c == "?":
cc += 1
print((dp[2][n] % mo))
| false | 44.736842 | [
"+mo = 10**9 + 7",
"-dc = dict()",
"-dc[\"A\"] = 0",
"-dc[\"B\"] = 1",
"-dc[\"C\"] = 2",
"-dc[\"?\"] = 3",
"-dp = [[0 for i in range(4)] for j in range(n + 1)]",
"-dp[0][0] = 1",
"-mo = 10**9 + 7",
"+dp = [[0] * (1 + n) for i in range(3)]",
"+cc = 0",
"- for t in range(4):",
"- ch = s[i]",
"- m = 1 if dc[ch] == t - 1 or dc[ch] == 3 else 0",
"- if t != 0:",
"- dp[i + 1][t] += (dp[i][t - 1] * m) % mo",
"- dp[i + 1][t] += (dp[i][t] * (3 if dc[ch] == 3 else 1)) % mo",
"-ans = dp[n][3]",
"-print((ans % mo))",
"+ c = s[i]",
"+ if c == \"A\":",
"+ da = 1",
"+ db = 0",
"+ dc = 0",
"+ dd = 1",
"+ elif c == \"B\":",
"+ da = 0",
"+ db = 1",
"+ dc = 0",
"+ dd = 1",
"+ elif c == \"C\":",
"+ da = 0",
"+ db = 0",
"+ dc = 1",
"+ dd = 1",
"+ elif c == \"?\":",
"+ da = 1",
"+ db = 1",
"+ dc = 1",
"+ dd = 3",
"+ dp[0][i + 1] = dp[0][i] * dd + da * pow(3, cc, mo)",
"+ dp[1][i + 1] = dp[1][i] * dd + dp[0][i] * db",
"+ dp[2][i + 1] = dp[2][i] * dd + dp[1][i] * dc",
"+ dp[0][i + 1] %= mo",
"+ dp[1][i + 1] %= mo",
"+ dp[2][i + 1] %= mo",
"+ if c == \"?\":",
"+ cc += 1",
"+print((dp[2][n] % mo))"
] | false | 0.042219 | 0.040904 | 1.03215 | [
"s645816825",
"s975378749"
] |
u268402865 | p02570 | python | s177254667 | s773517705 | 68 | 25 | 61,608 | 9,136 | Accepted | Accepted | 63.24 | D, T, S = list(map(int,input().split()))
if D/S <= T:
print("Yes")
else:
print("No") | D, T, S = list(map(int,input().split()))
if D <= T*S:
print("Yes")
else:
print("No") | 5 | 5 | 96 | 96 | D, T, S = list(map(int, input().split()))
if D / S <= T:
print("Yes")
else:
print("No")
| D, T, S = list(map(int, input().split()))
if D <= T * S:
print("Yes")
else:
print("No")
| false | 0 | [
"-if D / S <= T:",
"+if D <= T * S:"
] | false | 0.036798 | 0.037483 | 0.981728 | [
"s177254667",
"s773517705"
] |
u035472582 | p02595 | python | s528816095 | s585559277 | 402 | 370 | 107,188 | 107,200 | Accepted | Accepted | 7.96 | from math import sqrt
def main():
N, D = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
if sqrt(P[i][0]**2 + P[i][1]**2) <= D:
ans += 1
print(ans)
main() | def main():
from math import sqrt
N, D = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
if sqrt(P[i][0]**2 + P[i][1]**2) <= D:
ans += 1
print(ans)
main() | 12 | 10 | 248 | 246 | from math import sqrt
def main():
N, D = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
if sqrt(P[i][0] ** 2 + P[i][1] ** 2) <= D:
ans += 1
print(ans)
main()
| def main():
from math import sqrt
N, D = list(map(int, input().split()))
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
if sqrt(P[i][0] ** 2 + P[i][1] ** 2) <= D:
ans += 1
print(ans)
main()
| false | 16.666667 | [
"-from math import sqrt",
"+def main():",
"+ from math import sqrt",
"-",
"-def main():"
] | false | 0.045717 | 0.088033 | 0.519314 | [
"s528816095",
"s585559277"
] |
u073852194 | p02551 | python | s043737804 | s858139576 | 365 | 325 | 167,188 | 94,684 | Accepted | Accepted | 10.96 | class SegmentTreeDual():
def __init__(self, arr, op=lambda x, y: y if y != -1 else x, ie=-1):
self.h = (len(arr) - 1).bit_length()
self.n = 2**self.h
self.ie = ie
self.op = op
self.val = [ie for _ in range(self.n)]
self.laz = [ie for _ in range(2 * self.n)]
for i in range(len(arr)):
self.val[i] = arr[i]
def propagate(self, k):
if self.laz[k] == self.ie: return
if self.n <= k:
self.val[k - self.n] = self.op(self.val[k - self.n], self.laz[k])
else:
self.laz[2 * k] = self.op(self.laz[2 * k], self.laz[k])
self.laz[2 * k + 1] = self.op(self.laz[2 * k + 1], self.laz[k])
self.laz[k] = self.ie
def update(self, lt, rt, x):
lt += self.n
rt += self.n
while rt - lt > 0:
if lt & 1:
self.laz[lt] = self.op(self.laz[lt], x)
lt += 1
if rt & 1:
rt -= 1
self.laz[rt] = self.op(self.laz[rt], x)
lt >>= 1
rt >>= 1
def get(self, idx):
res = self.val[idx]
idx += self.n
while idx:
res = self.op(res, self.laz[idx])
idx >>= 1
return res
import sys
input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]
stx = SegmentTreeDual(x, min, 10**18)
sty = SegmentTreeDual(y, min, 10**18)
res = (N - 2) * (N - 2)
for _ in range(Q):
q, k = list(map(int, input().split()))
if q == 1:
g = stx.get(k - 1)
res -= g - 1
sty.update(1, g, k - 1)
if q == 2:
g = sty.get(k - 1)
res -= g - 1
stx.update(1, g, k - 1)
print(res) | class SegmentTreeDual():
def __init__(self, n, op, id, commutative=False):
self.n = n
self.op = op
self.id = id
self.commutative = commutative
self.log = (n - 1).bit_length()
self.size = 1 << self.log
self.d = [id] * self.size
self.lz = [id] * (2 * self.size)
def build(self, arr):
for i, a in enumerate(arr):
self.d[i] = a
def propagate(self, k):
if self.lz[k] == self.id: return
if k < self.size:
self.lz[2 * k] = self.op(self.lz[k], self.lz[2 * k], )
self.lz[2 * k + 1] = self.op(self.lz[k], self.lz[2 * k + 1])
else:
self.d[k - self.size] = self.op(self.lz[k], self.d[k - self.size])
self.lz[k] = self.id
def get(self, p):
res = self.d[p]
p += self.size
for i in range(self.log):
res = self.op(self.lz[p >> i], res)
return res
def range_apply(self, l, r, f):
if l == r: return
l += self.size
r += self.size
if not self.commutative:
for i in range(self.log)[::-1]:
self.propagate(l >> i)
self.propagate(r >> i)
while l < r:
if l & 1:
self.lz[l] = self.op(f, self.lz[l])
l += 1
if r & 1:
r -= 1
self.lz[r] = self.op(f, self.lz[r])
l >>= 1
r >>= 1
import sys
input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
stx = SegmentTreeDual(N, min, 10**18, False)
sty = SegmentTreeDual(N, min, 10**18, False)
x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]
stx.build(x)
sty.build(y)
res = (N - 2) * (N - 2)
for _ in range(Q):
q, k = list(map(int, input().split()))
if q == 1:
g = stx.get(k - 1)
res -= g - 1
sty.range_apply(1, g, k - 1)
if q == 2:
g = sty.get(k - 1)
res -= g - 1
stx.range_apply(1, g, k - 1)
print(res) | 66 | 77 | 1,832 | 2,089 | class SegmentTreeDual:
def __init__(self, arr, op=lambda x, y: y if y != -1 else x, ie=-1):
self.h = (len(arr) - 1).bit_length()
self.n = 2**self.h
self.ie = ie
self.op = op
self.val = [ie for _ in range(self.n)]
self.laz = [ie for _ in range(2 * self.n)]
for i in range(len(arr)):
self.val[i] = arr[i]
def propagate(self, k):
if self.laz[k] == self.ie:
return
if self.n <= k:
self.val[k - self.n] = self.op(self.val[k - self.n], self.laz[k])
else:
self.laz[2 * k] = self.op(self.laz[2 * k], self.laz[k])
self.laz[2 * k + 1] = self.op(self.laz[2 * k + 1], self.laz[k])
self.laz[k] = self.ie
def update(self, lt, rt, x):
lt += self.n
rt += self.n
while rt - lt > 0:
if lt & 1:
self.laz[lt] = self.op(self.laz[lt], x)
lt += 1
if rt & 1:
rt -= 1
self.laz[rt] = self.op(self.laz[rt], x)
lt >>= 1
rt >>= 1
def get(self, idx):
res = self.val[idx]
idx += self.n
while idx:
res = self.op(res, self.laz[idx])
idx >>= 1
return res
import sys
input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]
stx = SegmentTreeDual(x, min, 10**18)
sty = SegmentTreeDual(y, min, 10**18)
res = (N - 2) * (N - 2)
for _ in range(Q):
q, k = list(map(int, input().split()))
if q == 1:
g = stx.get(k - 1)
res -= g - 1
sty.update(1, g, k - 1)
if q == 2:
g = sty.get(k - 1)
res -= g - 1
stx.update(1, g, k - 1)
print(res)
| class SegmentTreeDual:
def __init__(self, n, op, id, commutative=False):
self.n = n
self.op = op
self.id = id
self.commutative = commutative
self.log = (n - 1).bit_length()
self.size = 1 << self.log
self.d = [id] * self.size
self.lz = [id] * (2 * self.size)
def build(self, arr):
for i, a in enumerate(arr):
self.d[i] = a
def propagate(self, k):
if self.lz[k] == self.id:
return
if k < self.size:
self.lz[2 * k] = self.op(
self.lz[k],
self.lz[2 * k],
)
self.lz[2 * k + 1] = self.op(self.lz[k], self.lz[2 * k + 1])
else:
self.d[k - self.size] = self.op(self.lz[k], self.d[k - self.size])
self.lz[k] = self.id
def get(self, p):
res = self.d[p]
p += self.size
for i in range(self.log):
res = self.op(self.lz[p >> i], res)
return res
def range_apply(self, l, r, f):
if l == r:
return
l += self.size
r += self.size
if not self.commutative:
for i in range(self.log)[::-1]:
self.propagate(l >> i)
self.propagate(r >> i)
while l < r:
if l & 1:
self.lz[l] = self.op(f, self.lz[l])
l += 1
if r & 1:
r -= 1
self.lz[r] = self.op(f, self.lz[r])
l >>= 1
r >>= 1
import sys
input = sys.stdin.buffer.readline
N, Q = list(map(int, input().split()))
stx = SegmentTreeDual(N, min, 10**18, False)
sty = SegmentTreeDual(N, min, 10**18, False)
x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]
stx.build(x)
sty.build(y)
res = (N - 2) * (N - 2)
for _ in range(Q):
q, k = list(map(int, input().split()))
if q == 1:
g = stx.get(k - 1)
res -= g - 1
sty.range_apply(1, g, k - 1)
if q == 2:
g = sty.get(k - 1)
res -= g - 1
stx.range_apply(1, g, k - 1)
print(res)
| false | 14.285714 | [
"- def __init__(self, arr, op=lambda x, y: y if y != -1 else x, ie=-1):",
"- self.h = (len(arr) - 1).bit_length()",
"- self.n = 2**self.h",
"- self.ie = ie",
"+ def __init__(self, n, op, id, commutative=False):",
"+ self.n = n",
"- self.val = [ie for _ in range(self.n)]",
"- self.laz = [ie for _ in range(2 * self.n)]",
"- for i in range(len(arr)):",
"- self.val[i] = arr[i]",
"+ self.id = id",
"+ self.commutative = commutative",
"+ self.log = (n - 1).bit_length()",
"+ self.size = 1 << self.log",
"+ self.d = [id] * self.size",
"+ self.lz = [id] * (2 * self.size)",
"+",
"+ def build(self, arr):",
"+ for i, a in enumerate(arr):",
"+ self.d[i] = a",
"- if self.laz[k] == self.ie:",
"+ if self.lz[k] == self.id:",
"- if self.n <= k:",
"- self.val[k - self.n] = self.op(self.val[k - self.n], self.laz[k])",
"+ if k < self.size:",
"+ self.lz[2 * k] = self.op(",
"+ self.lz[k],",
"+ self.lz[2 * k],",
"+ )",
"+ self.lz[2 * k + 1] = self.op(self.lz[k], self.lz[2 * k + 1])",
"- self.laz[2 * k] = self.op(self.laz[2 * k], self.laz[k])",
"- self.laz[2 * k + 1] = self.op(self.laz[2 * k + 1], self.laz[k])",
"- self.laz[k] = self.ie",
"+ self.d[k - self.size] = self.op(self.lz[k], self.d[k - self.size])",
"+ self.lz[k] = self.id",
"- def update(self, lt, rt, x):",
"- lt += self.n",
"- rt += self.n",
"- while rt - lt > 0:",
"- if lt & 1:",
"- self.laz[lt] = self.op(self.laz[lt], x)",
"- lt += 1",
"- if rt & 1:",
"- rt -= 1",
"- self.laz[rt] = self.op(self.laz[rt], x)",
"- lt >>= 1",
"- rt >>= 1",
"+ def get(self, p):",
"+ res = self.d[p]",
"+ p += self.size",
"+ for i in range(self.log):",
"+ res = self.op(self.lz[p >> i], res)",
"+ return res",
"- def get(self, idx):",
"- res = self.val[idx]",
"- idx += self.n",
"- while idx:",
"- res = self.op(res, self.laz[idx])",
"- idx >>= 1",
"- return res",
"+ def range_apply(self, l, r, f):",
"+ if l == r:",
"+ return",
"+ l += self.size",
"+ r += self.size",
"+ if not self.commutative:",
"+ for i in range(self.log)[::-1]:",
"+ self.propagate(l >> i)",
"+ self.propagate(r >> i)",
"+ while l < r:",
"+ if l & 1:",
"+ self.lz[l] = self.op(f, self.lz[l])",
"+ l += 1",
"+ if r & 1:",
"+ r -= 1",
"+ self.lz[r] = self.op(f, self.lz[r])",
"+ l >>= 1",
"+ r >>= 1",
"+stx = SegmentTreeDual(N, min, 10**18, False)",
"+sty = SegmentTreeDual(N, min, 10**18, False)",
"-stx = SegmentTreeDual(x, min, 10**18)",
"-sty = SegmentTreeDual(y, min, 10**18)",
"+stx.build(x)",
"+sty.build(y)",
"- sty.update(1, g, k - 1)",
"+ sty.range_apply(1, g, k - 1)",
"- stx.update(1, g, k - 1)",
"+ stx.range_apply(1, g, k - 1)"
] | false | 0.446328 | 0.08723 | 5.116663 | [
"s043737804",
"s858139576"
] |
u367701763 | p03283 | python | s398986864 | s949086350 | 816 | 624 | 153,856 | 82,232 | Accepted | Accepted | 23.53 | # https://atcoder.jp/contests/abc106/tasks/abc106_d
'''
N が小さいので、N^2 を考えると良いことが分かる。
'''
from collections import defaultdict
N, M, Q = list(map(int, input().split())) # N, M: リストの長さ
edges = [list(map(int, input().split())) for _ in range(M)]
data = defaultdict(int) # defaultdict は 初期化の際のに value の type を指定する必要あり
for i, j in edges:
i -= 1
j -= 1
data[(i,j)] += 1
cum = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
for j in range(N):
cum[i+1][j+1] = cum[i][j+1] + cum[i+1][j] - cum[i][j] + data[(i,j)]
for _ in range(Q):
p, q = list(map(int, input().split()))
if p < q:
p, q = q, p
q -= 1
res = cum[p][p] - cum[p][q] - cum[q][p] + cum[q][q]
print(res)
| N, M, Q = list(map(int, input().split()))
C = [[0]*N for _ in range(N)]
for _ in range(M):
L, R = list(map(int, input().split()))
C[L-1][R-1] += 1
S = [[0]*(N+1) for _ in range(N+1)]
for r in range(N):
for l in reversed(list(range(N))):
S[l][r] = S[l+1][r] + C[l][r]
D = [[0]*(N+1) for _ in range(N+1)]
for l in range(N):
for r in range(N):
D[l][r] = D[l][r-1] + S[l][r]
for _ in range(Q):
p, q = list(map(int, input().split()))
print((D[p-1][q-1]))
| 37 | 16 | 770 | 479 | # https://atcoder.jp/contests/abc106/tasks/abc106_d
"""
N が小さいので、N^2 を考えると良いことが分かる。
"""
from collections import defaultdict
N, M, Q = list(map(int, input().split())) # N, M: リストの長さ
edges = [list(map(int, input().split())) for _ in range(M)]
data = defaultdict(int) # defaultdict は 初期化の際のに value の type を指定する必要あり
for i, j in edges:
i -= 1
j -= 1
data[(i, j)] += 1
cum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(N):
cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + data[(i, j)]
for _ in range(Q):
p, q = list(map(int, input().split()))
if p < q:
p, q = q, p
q -= 1
res = cum[p][p] - cum[p][q] - cum[q][p] + cum[q][q]
print(res)
| N, M, Q = list(map(int, input().split()))
C = [[0] * N for _ in range(N)]
for _ in range(M):
L, R = list(map(int, input().split()))
C[L - 1][R - 1] += 1
S = [[0] * (N + 1) for _ in range(N + 1)]
for r in range(N):
for l in reversed(list(range(N))):
S[l][r] = S[l + 1][r] + C[l][r]
D = [[0] * (N + 1) for _ in range(N + 1)]
for l in range(N):
for r in range(N):
D[l][r] = D[l][r - 1] + S[l][r]
for _ in range(Q):
p, q = list(map(int, input().split()))
print((D[p - 1][q - 1]))
| false | 56.756757 | [
"-# https://atcoder.jp/contests/abc106/tasks/abc106_d",
"-\"\"\"",
"-N が小さいので、N^2 を考えると良いことが分かる。",
"-\"\"\"",
"-from collections import defaultdict",
"-",
"-N, M, Q = list(map(int, input().split())) # N, M: リストの長さ",
"-edges = [list(map(int, input().split())) for _ in range(M)]",
"-data = defaultdict(int) # defaultdict は 初期化の際のに value の type を指定する必要あり",
"-for i, j in edges:",
"- i -= 1",
"- j -= 1",
"- data[(i, j)] += 1",
"-cum = [[0] * (N + 1) for _ in range(N + 1)]",
"-for i in range(N):",
"- for j in range(N):",
"- cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + data[(i, j)]",
"+N, M, Q = list(map(int, input().split()))",
"+C = [[0] * N for _ in range(N)]",
"+for _ in range(M):",
"+ L, R = list(map(int, input().split()))",
"+ C[L - 1][R - 1] += 1",
"+S = [[0] * (N + 1) for _ in range(N + 1)]",
"+for r in range(N):",
"+ for l in reversed(list(range(N))):",
"+ S[l][r] = S[l + 1][r] + C[l][r]",
"+D = [[0] * (N + 1) for _ in range(N + 1)]",
"+for l in range(N):",
"+ for r in range(N):",
"+ D[l][r] = D[l][r - 1] + S[l][r]",
"- if p < q:",
"- p, q = q, p",
"- q -= 1",
"- res = cum[p][p] - cum[p][q] - cum[q][p] + cum[q][q]",
"- print(res)",
"+ print((D[p - 1][q - 1]))"
] | false | 0.211652 | 0.041028 | 5.158696 | [
"s398986864",
"s949086350"
] |
u020604402 | p03730 | python | s129120795 | s690110460 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | A ,B ,C = list(map(int,input().split()))
for i in range(100):
if (A * i) % B == C:
print("YES")
quit()
print("NO")
| A ,B ,C = list(map(int,input().split()))
for i in range(1,B+1):
if (A * i) % B == C:
print("YES")
quit()
print("NO")
| 7 | 7 | 136 | 138 | A, B, C = list(map(int, input().split()))
for i in range(100):
if (A * i) % B == C:
print("YES")
quit()
print("NO")
| A, B, C = list(map(int, input().split()))
for i in range(1, B + 1):
if (A * i) % B == C:
print("YES")
quit()
print("NO")
| false | 0 | [
"-for i in range(100):",
"+for i in range(1, B + 1):"
] | false | 0.066116 | 0.050816 | 1.301074 | [
"s129120795",
"s690110460"
] |
u732412551 | p03611 | python | s083688554 | s678583460 | 224 | 86 | 14,556 | 14,044 | Accepted | Accepted | 61.61 | from collections import Counter
eval(input())
A = list(map(int, input().split()))
C = Counter(A)
def get(i): return C[i] if i in C else 0
print((max(sum(get(x) for x in range(i-1,i+2)) for i in range(10**5)))) | N,*A=list(map(int, open(0).read().split()))
C=[0]*(10**5+5)
for a in A:
C[a-1]+=1
C[a]+=1
C[a+1]+=1
print((max(C[i] for i in range(10**5+1))))
| 6 | 7 | 206 | 153 | from collections import Counter
eval(input())
A = list(map(int, input().split()))
C = Counter(A)
def get(i):
return C[i] if i in C else 0
print((max(sum(get(x) for x in range(i - 1, i + 2)) for i in range(10**5))))
| N, *A = list(map(int, open(0).read().split()))
C = [0] * (10**5 + 5)
for a in A:
C[a - 1] += 1
C[a] += 1
C[a + 1] += 1
print((max(C[i] for i in range(10**5 + 1))))
| false | 14.285714 | [
"-from collections import Counter",
"-",
"-eval(input())",
"-A = list(map(int, input().split()))",
"-C = Counter(A)",
"-",
"-",
"-def get(i):",
"- return C[i] if i in C else 0",
"-",
"-",
"-print((max(sum(get(x) for x in range(i - 1, i + 2)) for i in range(10**5))))",
"+N, *A = list(map(int, open(0).read().split()))",
"+C = [0] * (10**5 + 5)",
"+for a in A:",
"+ C[a - 1] += 1",
"+ C[a] += 1",
"+ C[a + 1] += 1",
"+print((max(C[i] for i in range(10**5 + 1))))"
] | false | 0.24495 | 0.074723 | 3.278092 | [
"s083688554",
"s678583460"
] |
u750990077 | p02687 | python | s406869537 | s164754035 | 66 | 28 | 61,792 | 8,968 | Accepted | Accepted | 57.58 | def main():
print((list(set(["ABC", "ARC"])-{eval(input())})[0]))
if __name__ == "__main__":
main() | def main():
s = eval(input())
if s == "ABC":
print("ARC")
else:
print("ABC")
if __name__ == "__main__":
main() | 6 | 9 | 114 | 145 | def main():
print((list(set(["ABC", "ARC"]) - {eval(input())})[0]))
if __name__ == "__main__":
main()
| def main():
s = eval(input())
if s == "ABC":
print("ARC")
else:
print("ABC")
if __name__ == "__main__":
main()
| false | 33.333333 | [
"- print((list(set([\"ABC\", \"ARC\"]) - {eval(input())})[0]))",
"+ s = eval(input())",
"+ if s == \"ABC\":",
"+ print(\"ARC\")",
"+ else:",
"+ print(\"ABC\")"
] | false | 0.11622 | 0.046517 | 2.498448 | [
"s406869537",
"s164754035"
] |
u077291787 | p03151 | python | s752887334 | s100483734 | 118 | 103 | 18,444 | 18,884 | Accepted | Accepted | 12.71 | # keyence2019C - Exam and Wizard
def main():
N = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
dif = sorted(i - j for i, j in zip(A, B))
ans, shortage = 0, 0
for i in dif:
if i < 0:
ans += 1
shortage += i
else:
break
for i in dif[::-1]:
if shortage >= 0:
print(ans)
return
ans += 1
shortage += i
print((-1))
if __name__ == "__main__":
main() | # keyence2019C - Exam and Wizard
def main():
N = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
pos, neg = [], []
for i, j in zip(A, B):
x = i - j
if x >= 0:
pos += [x]
else:
neg += [x]
ans, shortage = len(neg), sum(neg)
for i in sorted(pos, reverse=1):
if shortage >= 0:
print(ans)
return
ans += 1
shortage += i
print((ans if shortage >= 0 else -1))
if __name__ == "__main__":
main() | 24 | 24 | 541 | 579 | # keyence2019C - Exam and Wizard
def main():
N = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
dif = sorted(i - j for i, j in zip(A, B))
ans, shortage = 0, 0
for i in dif:
if i < 0:
ans += 1
shortage += i
else:
break
for i in dif[::-1]:
if shortage >= 0:
print(ans)
return
ans += 1
shortage += i
print((-1))
if __name__ == "__main__":
main()
| # keyence2019C - Exam and Wizard
def main():
N = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
pos, neg = [], []
for i, j in zip(A, B):
x = i - j
if x >= 0:
pos += [x]
else:
neg += [x]
ans, shortage = len(neg), sum(neg)
for i in sorted(pos, reverse=1):
if shortage >= 0:
print(ans)
return
ans += 1
shortage += i
print((ans if shortage >= 0 else -1))
if __name__ == "__main__":
main()
| false | 0 | [
"- dif = sorted(i - j for i, j in zip(A, B))",
"- ans, shortage = 0, 0",
"- for i in dif:",
"- if i < 0:",
"- ans += 1",
"- shortage += i",
"+ pos, neg = [], []",
"+ for i, j in zip(A, B):",
"+ x = i - j",
"+ if x >= 0:",
"+ pos += [x]",
"- break",
"- for i in dif[::-1]:",
"+ neg += [x]",
"+ ans, shortage = len(neg), sum(neg)",
"+ for i in sorted(pos, reverse=1):",
"- print((-1))",
"+ print((ans if shortage >= 0 else -1))"
] | false | 0.035563 | 0.037222 | 0.955427 | [
"s752887334",
"s100483734"
] |
u318029285 | p03160 | python | s053893503 | s457274495 | 139 | 128 | 13,776 | 13,980 | Accepted | Accepted | 7.91 | N = int(eval(input()))
h = list(map(int, input().split()))
dp = [10e9] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
if dp[i-1] + abs(h[i] - h[i-1]) < dp[i-2] + abs(h[i] - h[i-2]):
dp[i] = dp[i-1] + abs(h[i] - h[i-1])
else:
dp[i] = dp[i-2] + abs(h[i] - h[i-2])
print((dp[-1])) | N = int(eval(input()))
h = list(map(int, input().split()))
dp = [10e9] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print((dp[-1])) | 15 | 11 | 325 | 228 | N = int(eval(input()))
h = list(map(int, input().split()))
dp = [10e9] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
if dp[i - 1] + abs(h[i] - h[i - 1]) < dp[i - 2] + abs(h[i] - h[i - 2]):
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
else:
dp[i] = dp[i - 2] + abs(h[i] - h[i - 2])
print((dp[-1]))
| N = int(eval(input()))
h = list(map(int, input().split()))
dp = [10e9] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
print((dp[-1]))
| false | 26.666667 | [
"- if dp[i - 1] + abs(h[i] - h[i - 1]) < dp[i - 2] + abs(h[i] - h[i - 2]):",
"- dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])",
"- else:",
"- dp[i] = dp[i - 2] + abs(h[i] - h[i - 2])",
"+ dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))"
] | false | 0.04447 | 0.043543 | 1.021303 | [
"s053893503",
"s457274495"
] |
u759412327 | p02629 | python | s064671739 | s225680714 | 31 | 28 | 9,188 | 9,080 | Accepted | Accepted | 9.68 | def num2alpha(num):
if num<=26:
return chr(64+num)
elif num%26==0:
return num2alpha(num//26-1)+chr(90)
else:
return num2alpha(num//26)+chr(64+num%26)
print((num2alpha(int(eval(input()))).lower())) | N = int(eval(input()))
S = ""
while 0<N:
N-=1
S+=chr(97+N%26)
N//=26
print((S[::-1])) | 9 | 9 | 215 | 93 | def num2alpha(num):
if num <= 26:
return chr(64 + num)
elif num % 26 == 0:
return num2alpha(num // 26 - 1) + chr(90)
else:
return num2alpha(num // 26) + chr(64 + num % 26)
print((num2alpha(int(eval(input()))).lower()))
| N = int(eval(input()))
S = ""
while 0 < N:
N -= 1
S += chr(97 + N % 26)
N //= 26
print((S[::-1]))
| false | 0 | [
"-def num2alpha(num):",
"- if num <= 26:",
"- return chr(64 + num)",
"- elif num % 26 == 0:",
"- return num2alpha(num // 26 - 1) + chr(90)",
"- else:",
"- return num2alpha(num // 26) + chr(64 + num % 26)",
"-",
"-",
"-print((num2alpha(int(eval(input()))).lower()))",
"+N = int(eval(input()))",
"+S = \"\"",
"+while 0 < N:",
"+ N -= 1",
"+ S += chr(97 + N % 26)",
"+ N //= 26",
"+print((S[::-1]))"
] | false | 0.047014 | 0.125446 | 0.374776 | [
"s064671739",
"s225680714"
] |
u328510800 | p02952 | python | s711828308 | s002951584 | 55 | 47 | 2,940 | 2,940 | Accepted | Accepted | 14.55 | n = int(eval(input()))
res = 0
for i in range(1, n + 1):
l = len(str(i))
res += l & 1
print(res) | n = int(eval(input()))
print((sum([len(str(x)) & 1 for x in range(1, n+1)]))) | 8 | 2 | 103 | 76 | n = int(eval(input()))
res = 0
for i in range(1, n + 1):
l = len(str(i))
res += l & 1
print(res)
| n = int(eval(input()))
print((sum([len(str(x)) & 1 for x in range(1, n + 1)])))
| false | 75 | [
"-res = 0",
"-for i in range(1, n + 1):",
"- l = len(str(i))",
"- res += l & 1",
"-print(res)",
"+print((sum([len(str(x)) & 1 for x in range(1, n + 1)])))"
] | false | 0.090531 | 0.054129 | 1.672498 | [
"s711828308",
"s002951584"
] |
u502389123 | p03137 | python | s307880855 | s907808895 | 149 | 118 | 14,332 | 13,960 | Accepted | Accepted | 20.81 | N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
L = []
for i in reversed(list(range(len(X)))):
if i - 1 < 0:
break
if (X[i] >= 0 and X[i-1] >= 0) or (X[i] <= 0 and X[i-1] <= 0):
L.append(abs(X[i] - X[i-1]))
else:
L.append(abs(X[i]) + abs(X[i-1]))
L.sort()
L_min = 0
for i in range(M-N):
L_min += L[i]
print(L_min)
| N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
L = [0] * (M-1)
for i in range(M-1):
L[i] = abs(X[i+1] - X[i])
L.sort()
print((sum(L[:-(N-1)]) if N != 1 else sum(L)))
| 19 | 11 | 399 | 212 | N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
L = []
for i in reversed(list(range(len(X)))):
if i - 1 < 0:
break
if (X[i] >= 0 and X[i - 1] >= 0) or (X[i] <= 0 and X[i - 1] <= 0):
L.append(abs(X[i] - X[i - 1]))
else:
L.append(abs(X[i]) + abs(X[i - 1]))
L.sort()
L_min = 0
for i in range(M - N):
L_min += L[i]
print(L_min)
| N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
L = [0] * (M - 1)
for i in range(M - 1):
L[i] = abs(X[i + 1] - X[i])
L.sort()
print((sum(L[: -(N - 1)]) if N != 1 else sum(L)))
| false | 42.105263 | [
"-L = []",
"-for i in reversed(list(range(len(X)))):",
"- if i - 1 < 0:",
"- break",
"- if (X[i] >= 0 and X[i - 1] >= 0) or (X[i] <= 0 and X[i - 1] <= 0):",
"- L.append(abs(X[i] - X[i - 1]))",
"- else:",
"- L.append(abs(X[i]) + abs(X[i - 1]))",
"+L = [0] * (M - 1)",
"+for i in range(M - 1):",
"+ L[i] = abs(X[i + 1] - X[i])",
"-L_min = 0",
"-for i in range(M - N):",
"- L_min += L[i]",
"-print(L_min)",
"+print((sum(L[: -(N - 1)]) if N != 1 else sum(L)))"
] | false | 0.122144 | 0.043149 | 2.830788 | [
"s307880855",
"s907808895"
] |
u945181840 | p03295 | python | s560006611 | s913328617 | 205 | 160 | 23,732 | 29,720 | Accepted | Accepted | 21.95 | import sys
from operator import itemgetter
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = list(map(int, readline().split()))
ab = [tuple(map(int, i.split())) for i in readlines()]
ab.sort(key=itemgetter(1))
right_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= right_island:
answer += 1
right_island = j
print(answer) | import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = list(map(int, readline().split()))
ab = list(map(int, read().split()))
ab = sorted(zip(ab, ab), key=itemgetter(1))
right_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= right_island:
answer += 1
right_island = j
print(answer) | 18 | 19 | 379 | 394 | import sys
from operator import itemgetter
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = list(map(int, readline().split()))
ab = [tuple(map(int, i.split())) for i in readlines()]
ab.sort(key=itemgetter(1))
right_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= right_island:
answer += 1
right_island = j
print(answer)
| import sys
from operator import itemgetter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = list(map(int, readline().split()))
ab = list(map(int, read().split()))
ab = sorted(zip(ab, ab), key=itemgetter(1))
right_island = ab[0][1]
answer = 1
for i, j in ab:
if i >= right_island:
answer += 1
right_island = j
print(answer)
| false | 5.263158 | [
"+read = sys.stdin.read",
"-ab = [tuple(map(int, i.split())) for i in readlines()]",
"-ab.sort(key=itemgetter(1))",
"+ab = list(map(int, read().split()))",
"+ab = sorted(zip(ab, ab), key=itemgetter(1))"
] | false | 0.082742 | 0.035932 | 2.302737 | [
"s560006611",
"s913328617"
] |
u691018832 | p03612 | python | s962585757 | s652761206 | 73 | 60 | 13,876 | 11,620 | Accepted | Accepted | 17.81 | # sys.stdin.readline()
import sys
input = sys.stdin.readline
n = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
if i+1 == p[i]:
if p[i]+1 == p[i+1]:
p[i+1] = p[i]
ans += 1
if p[n-1] == n:
ans += 1
print(ans) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, *p = list(map(int, read().split()))
p += [0]
cnt = 0
for i, pp in enumerate(p):
if (i + 1) == pp:
p[i + 1] = 0
cnt += 1
print(cnt)
| 15 | 14 | 289 | 309 | # sys.stdin.readline()
import sys
input = sys.stdin.readline
n = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
if i + 1 == p[i]:
if p[i] + 1 == p[i + 1]:
p[i + 1] = p[i]
ans += 1
if p[n - 1] == n:
ans += 1
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, *p = list(map(int, read().split()))
p += [0]
cnt = 0
for i, pp in enumerate(p):
if (i + 1) == pp:
p[i + 1] = 0
cnt += 1
print(cnt)
| false | 6.666667 | [
"-# sys.stdin.readline()",
"-input = sys.stdin.readline",
"-n = int(eval(input()))",
"-p = list(map(int, input().split()))",
"-ans = 0",
"-for i in range(n - 1):",
"- if i + 1 == p[i]:",
"- if p[i] + 1 == p[i + 1]:",
"- p[i + 1] = p[i]",
"- ans += 1",
"-if p[n - 1] == n:",
"- ans += 1",
"-print(ans)",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(10**7)",
"+n, *p = list(map(int, read().split()))",
"+p += [0]",
"+cnt = 0",
"+for i, pp in enumerate(p):",
"+ if (i + 1) == pp:",
"+ p[i + 1] = 0",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.048277 | 0.176735 | 0.273163 | [
"s962585757",
"s652761206"
] |
u102461423 | p02548 | python | s323099139 | s123499663 | 874 | 31 | 24,732 | 9,360 | Accepted | Accepted | 96.45 | N=int(eval(input()))
# 約数の個数のテーブルを O(N loglog N) で作る
div = [1] * (N+1)
div[0] = 0
for p in range(2, N+1):
if div[p] != 1:
continue
# p は素数
pp = p # power of p
e = 1
while pp <= N:
for n in range(pp, N+1, pp):
div[n] += div[n] // e
e += 1
pp *= p
ans = sum(div[:N])
print(ans) | """O(N^0.5) solution"""
N = int(eval(input()))
N -= 1
ans = 0
n = int(N**.5)
for x in range(1, n+1):
# (x,x)
ans += 1
# (x,y)
ans += N//x - x
# (y,x)
ans += N//x - x
print(ans) | 20 | 16 | 326 | 200 | N = int(eval(input()))
# 約数の個数のテーブルを O(N loglog N) で作る
div = [1] * (N + 1)
div[0] = 0
for p in range(2, N + 1):
if div[p] != 1:
continue
# p は素数
pp = p # power of p
e = 1
while pp <= N:
for n in range(pp, N + 1, pp):
div[n] += div[n] // e
e += 1
pp *= p
ans = sum(div[:N])
print(ans)
| """O(N^0.5) solution"""
N = int(eval(input()))
N -= 1
ans = 0
n = int(N**0.5)
for x in range(1, n + 1):
# (x,x)
ans += 1
# (x,y)
ans += N // x - x
# (y,x)
ans += N // x - x
print(ans)
| false | 20 | [
"+\"\"\"O(N^0.5) solution\"\"\"",
"-# 約数の個数のテーブルを O(N loglog N) で作る",
"-div = [1] * (N + 1)",
"-div[0] = 0",
"-for p in range(2, N + 1):",
"- if div[p] != 1:",
"- continue",
"- # p は素数",
"- pp = p # power of p",
"- e = 1",
"- while pp <= N:",
"- for n in range(pp, N + 1, pp):",
"- div[n] += div[n] // e",
"- e += 1",
"- pp *= p",
"-ans = sum(div[:N])",
"+N -= 1",
"+ans = 0",
"+n = int(N**0.5)",
"+for x in range(1, n + 1):",
"+ # (x,x)",
"+ ans += 1",
"+ # (x,y)",
"+ ans += N // x - x",
"+ # (y,x)",
"+ ans += N // x - x"
] | false | 0.147123 | 0.035564 | 4.136814 | [
"s323099139",
"s123499663"
] |
u785578220 | p02688 | python | s788912898 | s607156900 | 22 | 20 | 9,196 | 9,140 | Accepted | Accepted | 9.09 | n,k = list(map(int,input().split()))
l = [0]*n
# print(k)
for i in range(k):
for j in range(1):
_ = eval(input())
tl = list(map(int,input().split()))
for t in tl:
l[t-1]+=1
# print(i,j)
ans = 0
for i in l:
if i ==0:
ans +=1
print(ans) | n,k = list(map(int,input().split()))
dp = [0]*n
for i in range(k):
d = int(eval(input()))
A = list(map(int,input().split()))
for i in A:
dp[i-1] +=1
print((dp.count(0))) | 17 | 9 | 300 | 184 | n, k = list(map(int, input().split()))
l = [0] * n
# print(k)
for i in range(k):
for j in range(1):
_ = eval(input())
tl = list(map(int, input().split()))
for t in tl:
l[t - 1] += 1
# print(i,j)
ans = 0
for i in l:
if i == 0:
ans += 1
print(ans)
| n, k = list(map(int, input().split()))
dp = [0] * n
for i in range(k):
d = int(eval(input()))
A = list(map(int, input().split()))
for i in A:
dp[i - 1] += 1
print((dp.count(0)))
| false | 47.058824 | [
"-l = [0] * n",
"-# print(k)",
"+dp = [0] * n",
"- for j in range(1):",
"- _ = eval(input())",
"- tl = list(map(int, input().split()))",
"- for t in tl:",
"- l[t - 1] += 1",
"- # print(i,j)",
"-ans = 0",
"-for i in l:",
"- if i == 0:",
"- ans += 1",
"-print(ans)",
"+ d = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ for i in A:",
"+ dp[i - 1] += 1",
"+print((dp.count(0)))"
] | false | 0.082394 | 0.046556 | 1.769778 | [
"s788912898",
"s607156900"
] |
u123745130 | p02791 | python | s436794343 | s525840337 | 169 | 148 | 24,744 | 24,744 | Accepted | Accepted | 12.43 | n=int(eval(input()))
l=list(map(int,input().split()))
mi=10**9
mi_lst=[]
cnt=0
for i in range(n):
if l[i]<mi:
mi_lst.append(l[i])
mi=min(mi,l[i])
cnt+=1
else:mi_lst.append(l[-1])
print(cnt) | n=int(eval(input()))
l=list(map(int,input().split()))
mi=10**9
cnt=0
for i in range(n):
if l[i]<mi:
mi=min(mi,l[i])
cnt+=1
print(cnt) | 12 | 9 | 210 | 145 | n = int(eval(input()))
l = list(map(int, input().split()))
mi = 10**9
mi_lst = []
cnt = 0
for i in range(n):
if l[i] < mi:
mi_lst.append(l[i])
mi = min(mi, l[i])
cnt += 1
else:
mi_lst.append(l[-1])
print(cnt)
| n = int(eval(input()))
l = list(map(int, input().split()))
mi = 10**9
cnt = 0
for i in range(n):
if l[i] < mi:
mi = min(mi, l[i])
cnt += 1
print(cnt)
| false | 25 | [
"-mi_lst = []",
"- mi_lst.append(l[i])",
"- else:",
"- mi_lst.append(l[-1])"
] | false | 0.036245 | 0.035454 | 1.022305 | [
"s436794343",
"s525840337"
] |
u597374218 | p03545 | python | s790045404 | s911667055 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | A,B,C,D=eval(input())
digits=3
op=[""]*digits
for i in range(1<<digits):
for j in range(digits):
if (i>>j)&1:
op[j]="+"
else:
op[j]="-"
if eval(A+op[0]+B+op[1]+C+op[2]+D)==7:
print((A+op[0]+B+op[1]+C+op[2]+D+"=7"))
break | ABCD=eval(input())
digits=3
ops=[""]*(digits+1)
for i in range(1<<digits):
for j in range(digits):
if (i>>j)&1:
ops[j]="+"
else:
ops[j]="-"
evals=""
for num,op in zip(ABCD,ops):
evals+=num+op
if eval(evals)==7:
print((evals+"=7"))
break | 12 | 15 | 287 | 322 | A, B, C, D = eval(input())
digits = 3
op = [""] * digits
for i in range(1 << digits):
for j in range(digits):
if (i >> j) & 1:
op[j] = "+"
else:
op[j] = "-"
if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
print((A + op[0] + B + op[1] + C + op[2] + D + "=7"))
break
| ABCD = eval(input())
digits = 3
ops = [""] * (digits + 1)
for i in range(1 << digits):
for j in range(digits):
if (i >> j) & 1:
ops[j] = "+"
else:
ops[j] = "-"
evals = ""
for num, op in zip(ABCD, ops):
evals += num + op
if eval(evals) == 7:
print((evals + "=7"))
break
| false | 20 | [
"-A, B, C, D = eval(input())",
"+ABCD = eval(input())",
"-op = [\"\"] * digits",
"+ops = [\"\"] * (digits + 1)",
"- op[j] = \"+\"",
"+ ops[j] = \"+\"",
"- op[j] = \"-\"",
"- if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:",
"- print((A + op[0] + B + op[1] + C + op[2] + D + \"=7\"))",
"+ ops[j] = \"-\"",
"+ evals = \"\"",
"+ for num, op in zip(ABCD, ops):",
"+ evals += num + op",
"+ if eval(evals) == 7:",
"+ print((evals + \"=7\"))"
] | false | 0.074658 | 0.05244 | 1.423681 | [
"s790045404",
"s911667055"
] |
u630211216 | p03814 | python | s153832300 | s572351455 | 45 | 28 | 9,240 | 9,124 | Accepted | Accepted | 37.78 | S=eval(input())
left=0
while S[left]!='A':
left+=1
right=len(S)-1
while S[right]!='Z':
right-=1
print((right-left+1))
| s=eval(input())
print((s.rfind('Z')-s.find('A')+1))
| 8 | 2 | 125 | 45 | S = eval(input())
left = 0
while S[left] != "A":
left += 1
right = len(S) - 1
while S[right] != "Z":
right -= 1
print((right - left + 1))
| s = eval(input())
print((s.rfind("Z") - s.find("A") + 1))
| false | 75 | [
"-S = eval(input())",
"-left = 0",
"-while S[left] != \"A\":",
"- left += 1",
"-right = len(S) - 1",
"-while S[right] != \"Z\":",
"- right -= 1",
"-print((right - left + 1))",
"+s = eval(input())",
"+print((s.rfind(\"Z\") - s.find(\"A\") + 1))"
] | false | 0.037843 | 0.037959 | 0.996942 | [
"s153832300",
"s572351455"
] |
u604839890 | p03031 | python | s248451951 | s932339478 | 48 | 40 | 9,224 | 9,164 | Accepted | Accepted | 16.67 | 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 ii in range(2**N):
check = True
for i in range(M):
cnt = 0
for j in range(1, len(ks[i])):
if (ii >> (ks[i][j]-1)) & 1:
cnt += 1
if cnt % 2 != p[i]:
check = False
break
if check:
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):
flag = True
for j in range(m):
cnt = 0
for k in range(1, len(ks[j])):
if (i >> (ks[j][k]-1)) & 1:
cnt += 1
if cnt % 2 != p[j]:
flag = False
break
if flag:
ans += 1
print(ans) | 18 | 18 | 449 | 444 | 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 ii in range(2**N):
check = True
for i in range(M):
cnt = 0
for j in range(1, len(ks[i])):
if (ii >> (ks[i][j] - 1)) & 1:
cnt += 1
if cnt % 2 != p[i]:
check = False
break
if check:
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):
flag = True
for j in range(m):
cnt = 0
for k in range(1, len(ks[j])):
if (i >> (ks[j][k] - 1)) & 1:
cnt += 1
if cnt % 2 != p[j]:
flag = False
break
if flag:
ans += 1
print(ans)
| false | 0 | [
"-N, M = list(map(int, input().split()))",
"-ks = [list(map(int, input().split())) for _ in range(M)]",
"+n, m = list(map(int, input().split()))",
"+ks = [list(map(int, input().split())) for _ in range(m)]",
"-for ii in range(2**N):",
"- check = True",
"- for i in range(M):",
"+for i in range(2**n):",
"+ flag = True",
"+ for j in range(m):",
"- for j in range(1, len(ks[i])):",
"- if (ii >> (ks[i][j] - 1)) & 1:",
"+ for k in range(1, len(ks[j])):",
"+ if (i >> (ks[j][k] - 1)) & 1:",
"- if cnt % 2 != p[i]:",
"- check = False",
"+ if cnt % 2 != p[j]:",
"+ flag = False",
"- if check:",
"+ if flag:"
] | false | 0.040232 | 0.04229 | 0.951346 | [
"s248451951",
"s932339478"
] |
u852798899 | p03945 | python | s581931108 | s261751884 | 65 | 43 | 3,956 | 3,956 | Accepted | Accepted | 33.85 | S = list(eval(input()))
i = 0
count = 0
while(i < len(S)-1):
if S[i] != S[i+1]:
count+=1
i+=1
print(count)
| S = list(eval(input()))
i = 0
count = 0
for i in range(len(S)-1):
if S[i] != S[i+1]:
count+=1
print(count)
| 12 | 11 | 130 | 127 | S = list(eval(input()))
i = 0
count = 0
while i < len(S) - 1:
if S[i] != S[i + 1]:
count += 1
i += 1
print(count)
| S = list(eval(input()))
i = 0
count = 0
for i in range(len(S) - 1):
if S[i] != S[i + 1]:
count += 1
print(count)
| false | 8.333333 | [
"-while i < len(S) - 1:",
"+for i in range(len(S) - 1):",
"- i += 1"
] | false | 0.065771 | 0.03713 | 1.771383 | [
"s581931108",
"s261751884"
] |
u886729200 | p02418 | python | s941058954 | s300133686 | 30 | 20 | 5,548 | 5,548 | Accepted | Accepted | 33.33 | s = eval(input())
s = s+s
p = eval(input())
if p in s:
print("Yes")
else:
print("No")
| s = eval(input())
p = eval(input())
s = s*2
if p in s:
print("Yes")
else:
print("No")
| 7 | 8 | 88 | 90 | s = eval(input())
s = s + s
p = eval(input())
if p in s:
print("Yes")
else:
print("No")
| s = eval(input())
p = eval(input())
s = s * 2
if p in s:
print("Yes")
else:
print("No")
| false | 12.5 | [
"-s = s + s",
"+s = s * 2"
] | false | 0.041218 | 0.044297 | 0.930502 | [
"s941058954",
"s300133686"
] |
u989345508 | p02821 | python | s214087076 | s208010193 | 523 | 483 | 85,012 | 84,980 | Accepted | Accepted | 7.65 | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
if n==1:
print((a[0]*2))
exit()
from bisect import bisect_left,bisect_right
#幸福度がx以上がm以上か?
def f(x):
global n,a
ret=0
for i in range(n):
ret+=(n-bisect_left(a,x-a[i]))
return ret
l,r=-1,10**6
while l+1<r:
k=l+(r-l)//2
if f(k)>=m:
l=k
else:
r=k
#print(l,r)
#print(f(l),f(r))
if f(r)>=m:
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,r-a[i]))
ans+=(n-bisect_right(a,r-a[i]))*a[i]
print((2*ans+(m-co)*r))
else:
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,l-a[i]))
ans+=(n-bisect_right(a,l-a[i]))*a[i]
print((2*ans+(m-co)*l)) | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
if n==1:
print((a[0]*2))
exit()
from bisect import bisect_left,bisect_right
#幸福度がx以上がm以上か?
def f(x):
global n,a
ret=0
for i in range(n):
ret+=(n-bisect_left(a,x-a[i]))
return ret
#端がやはりコーナーケース(ここまじでバグらせんな)
l,r=-1,10**6
while l+1<r:
k=l+(r-l)//2
if f(k)>=m:
l=k
else:
r=k
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,l-a[i]))
ans+=(n-bisect_right(a,l-a[i]))*a[i]
print((2*ans+(m-co)*l)) | 35 | 27 | 750 | 553 | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
if n == 1:
print((a[0] * 2))
exit()
from bisect import bisect_left, bisect_right
# 幸福度がx以上がm以上か?
def f(x):
global n, a
ret = 0
for i in range(n):
ret += n - bisect_left(a, x - a[i])
return ret
l, r = -1, 10**6
while l + 1 < r:
k = l + (r - l) // 2
if f(k) >= m:
l = k
else:
r = k
# print(l,r)
# print(f(l),f(r))
if f(r) >= m:
co, ans = 0, 0
for i in range(n):
co += n - bisect_right(a, r - a[i])
ans += (n - bisect_right(a, r - a[i])) * a[i]
print((2 * ans + (m - co) * r))
else:
co, ans = 0, 0
for i in range(n):
co += n - bisect_right(a, l - a[i])
ans += (n - bisect_right(a, l - a[i])) * a[i]
print((2 * ans + (m - co) * l))
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
if n == 1:
print((a[0] * 2))
exit()
from bisect import bisect_left, bisect_right
# 幸福度がx以上がm以上か?
def f(x):
global n, a
ret = 0
for i in range(n):
ret += n - bisect_left(a, x - a[i])
return ret
# 端がやはりコーナーケース(ここまじでバグらせんな)
l, r = -1, 10**6
while l + 1 < r:
k = l + (r - l) // 2
if f(k) >= m:
l = k
else:
r = k
co, ans = 0, 0
for i in range(n):
co += n - bisect_right(a, l - a[i])
ans += (n - bisect_right(a, l - a[i])) * a[i]
print((2 * ans + (m - co) * l))
| false | 22.857143 | [
"+# 端がやはりコーナーケース(ここまじでバグらせんな)",
"-# print(l,r)",
"-# print(f(l),f(r))",
"-if f(r) >= m:",
"- co, ans = 0, 0",
"- for i in range(n):",
"- co += n - bisect_right(a, r - a[i])",
"- ans += (n - bisect_right(a, r - a[i])) * a[i]",
"- print((2 * ans + (m - co) * r))",
"-else:",
"- co, ans = 0, 0",
"- for i in range(n):",
"- co += n - bisect_right(a, l - a[i])",
"- ans += (n - bisect_right(a, l - a[i])) * a[i]",
"- print((2 * ans + (m - co) * l))",
"+co, ans = 0, 0",
"+for i in range(n):",
"+ co += n - bisect_right(a, l - a[i])",
"+ ans += (n - bisect_right(a, l - a[i])) * a[i]",
"+print((2 * ans + (m - co) * l))"
] | false | 0.045076 | 0.043425 | 1.038025 | [
"s214087076",
"s208010193"
] |
u757117214 | p03208 | python | s998661704 | s870290746 | 151 | 116 | 14,092 | 14,092 | Accepted | Accepted | 23.18 | N,K,*h=list(map(int,open(0).read().split()))
h.sort()
if K == N:
print((h[-1] - h[0]))
else:
dif_h=[]
for i in range(N-1):
dif_h.append(h[i+1] - h[i])
_min = base = sum(dif_h[:K-1])
for i in range(K-1,N-1):
base += dif_h[i]
base -= dif_h[i-K+1]
_min = min(base,_min)
print(_min)
| N,K,*h=list(map(int,open(0).read().split()))
h.sort()
_min = 10**9
for i in range(N+1-K):
_min = min(_min, h[i+K-1] - h[i])
print(_min) | 17 | 6 | 369 | 138 | N, K, *h = list(map(int, open(0).read().split()))
h.sort()
if K == N:
print((h[-1] - h[0]))
else:
dif_h = []
for i in range(N - 1):
dif_h.append(h[i + 1] - h[i])
_min = base = sum(dif_h[: K - 1])
for i in range(K - 1, N - 1):
base += dif_h[i]
base -= dif_h[i - K + 1]
_min = min(base, _min)
print(_min)
| N, K, *h = list(map(int, open(0).read().split()))
h.sort()
_min = 10**9
for i in range(N + 1 - K):
_min = min(_min, h[i + K - 1] - h[i])
print(_min)
| false | 64.705882 | [
"-if K == N:",
"- print((h[-1] - h[0]))",
"-else:",
"- dif_h = []",
"- for i in range(N - 1):",
"- dif_h.append(h[i + 1] - h[i])",
"- _min = base = sum(dif_h[: K - 1])",
"- for i in range(K - 1, N - 1):",
"- base += dif_h[i]",
"- base -= dif_h[i - K + 1]",
"- _min = min(base, _min)",
"- print(_min)",
"+_min = 10**9",
"+for i in range(N + 1 - K):",
"+ _min = min(_min, h[i + K - 1] - h[i])",
"+print(_min)"
] | false | 0.041469 | 0.036991 | 1.121045 | [
"s998661704",
"s870290746"
] |
u796942881 | p03137 | python | s301785709 | s671503244 | 202 | 101 | 28,052 | 13,960 | Accepted | Accepted | 50 | import numpy as np
N, M = list(map(int, input().split()))
X = list(set(map(int, input().split())))
X.sort()
D = np.diff(X)
D.sort()
print((0 if M <= N else np.sum(D[:M-N])))
| N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
D = [X[i+1] - X[i] for i in range(M - 1)]
D.sort()
print((0 if M <= N else sum(D[:M-N]))) | 12 | 10 | 182 | 178 | import numpy as np
N, M = list(map(int, input().split()))
X = list(set(map(int, input().split())))
X.sort()
D = np.diff(X)
D.sort()
print((0 if M <= N else np.sum(D[: M - N])))
| N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
D = [X[i + 1] - X[i] for i in range(M - 1)]
D.sort()
print((0 if M <= N else sum(D[: M - N])))
| false | 16.666667 | [
"-import numpy as np",
"-",
"-X = list(set(map(int, input().split())))",
"+X = list(map(int, input().split()))",
"-D = np.diff(X)",
"+D = [X[i + 1] - X[i] for i in range(M - 1)]",
"-print((0 if M <= N else np.sum(D[: M - N])))",
"+print((0 if M <= N else sum(D[: M - N])))"
] | false | 0.007721 | 0.032029 | 0.241072 | [
"s301785709",
"s671503244"
] |
u489959379 | p03108 | python | s174997003 | s077220855 | 704 | 480 | 34,808 | 33,620 | Accepted | Accepted | 31.82 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
\
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 same(self, x, y):
return self.find(x) == self.find(y)
# 連結成分の大きさを返す
def size(self, x):
return -self.parents[self.find(x)]
def resolve():
n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)][::-1]
uf = UnionFind(n)
res = [(n * (n - 1)) // 2]
for a, b in AB:
if not uf.same(a - 1, b - 1):
pre1 = uf.size(a - 1)
pre2 = uf.size(b - 1)
pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2
uf.union(a - 1, b - 1)
now = uf.size(a - 1)
now_score = (now * (now - 1)) // 2
res.append(res[-1] + pre_score - now_score)
else:
res.append(res[-1])
for i in reversed(list(range(m))):
print((res[i]))
if __name__ == '__main__':
resolve()
| import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
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):
"""
yをxの根に繋ぐ
"""
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 same(self, x, y):
"""
xとyが同じ連結成分か判別する
"""
return self.find(x) == self.find(y)
def size(self, x):
"""
xの連結成分の大きさを返す
"""
return -self.parents[self.find(x)]
def kruskal(self, edge):
"""
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
cost_sum = 0
for cost, node1, node2 in edge:
if not self.same(node1, node2):
cost_sum += cost
self.union(node1, node2)
return cost_sum
def resolve():
n, m = map(int, input().split())
edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
uf = UnionFind(n)
res = [(n - 1) * n // 2]
for i in reversed(range(1, m)):
a, b = edge[i]
if not uf.same(a, b):
res.append(res[-1] - uf.size(a) * uf.size(b))
uf.union(a, b)
else:
res.append(res[-1])
print(*res[::-1], sep="\n")
if __name__ == '__main__':
resolve()
| 68 | 78 | 1,607 | 1,866 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
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 same(self, x, y):
return self.find(x) == self.find(y)
# 連結成分の大きさを返す
def size(self, x):
return -self.parents[self.find(x)]
def resolve():
n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(m)][::-1]
uf = UnionFind(n)
res = [(n * (n - 1)) // 2]
for a, b in AB:
if not uf.same(a - 1, b - 1):
pre1 = uf.size(a - 1)
pre2 = uf.size(b - 1)
pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2
uf.union(a - 1, b - 1)
now = uf.size(a - 1)
now_score = (now * (now - 1)) // 2
res.append(res[-1] + pre_score - now_score)
else:
res.append(res[-1])
for i in reversed(list(range(m))):
print((res[i]))
if __name__ == "__main__":
resolve()
| import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
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):
"""
yをxの根に繋ぐ
"""
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 same(self, x, y):
"""
xとyが同じ連結成分か判別する
"""
return self.find(x) == self.find(y)
def size(self, x):
"""
xの連結成分の大きさを返す
"""
return -self.parents[self.find(x)]
def kruskal(self, edge):
"""
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
cost_sum = 0
for cost, node1, node2 in edge:
if not self.same(node1, node2):
cost_sum += cost
self.union(node1, node2)
return cost_sum
def resolve():
n, m = map(int, input().split())
edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
uf = UnionFind(n)
res = [(n - 1) * n // 2]
for i in reversed(range(1, m)):
a, b = edge[i]
if not uf.same(a, b):
res.append(res[-1] - uf.size(a) * uf.size(b))
uf.union(a, b)
else:
res.append(res[-1])
print(*res[::-1], sep="\n")
if __name__ == "__main__":
resolve()
| false | 12.820513 | [
"-input = sys.stdin.readline",
"- # 親が同じか判別",
"+ \"\"\"",
"+ 親が同じか判別する",
"+ \"\"\"",
"- # 根を繋ぎ直す",
"+ \"\"\"",
"+ yをxの根に繋ぐ",
"+ \"\"\"",
"- # 親が同じか判別",
"+ \"\"\"",
"+ xとyが同じ連結成分か判別する",
"+ \"\"\"",
"- # 連結成分の大きさを返す",
"+ \"\"\"",
"+ xの連結成分の大きさを返す",
"+ \"\"\"",
"+",
"+ def kruskal(self, edge):",
"+ \"\"\"",
"+ :param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい",
"+ :return: 最小全域木のコストの和",
"+ \"\"\"",
"+ edge.sort()",
"+ cost_sum = 0",
"+ for cost, node1, node2 in edge:",
"+ if not self.same(node1, node2):",
"+ cost_sum += cost",
"+ self.union(node1, node2)",
"+ return cost_sum",
"- n, m = list(map(int, input().split()))",
"- AB = [list(map(int, input().split())) for _ in range(m)][::-1]",
"+ n, m = map(int, input().split())",
"+ edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]",
"- res = [(n * (n - 1)) // 2]",
"- for a, b in AB:",
"- if not uf.same(a - 1, b - 1):",
"- pre1 = uf.size(a - 1)",
"- pre2 = uf.size(b - 1)",
"- pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2",
"- uf.union(a - 1, b - 1)",
"- now = uf.size(a - 1)",
"- now_score = (now * (now - 1)) // 2",
"- res.append(res[-1] + pre_score - now_score)",
"+ res = [(n - 1) * n // 2]",
"+ for i in reversed(range(1, m)):",
"+ a, b = edge[i]",
"+ if not uf.same(a, b):",
"+ res.append(res[-1] - uf.size(a) * uf.size(b))",
"+ uf.union(a, b)",
"- for i in reversed(list(range(m))):",
"- print((res[i]))",
"+ print(*res[::-1], sep=\"\\n\")"
] | false | 0.035699 | 0.03509 | 1.017348 | [
"s174997003",
"s077220855"
] |
u281303342 | p03855 | python | s896509030 | s508385767 | 1,338 | 1,197 | 65,016 | 109,552 | Accepted | Accepted | 10.54 | from collections import defaultdict
N,K,L = list(map(int,input().split()))
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
# 道路
A = UnionFind(N)
for i in range(K):
x,y = list(map(int,input().split()))
A.unite(x,y)
# 鉄道
B = UnionFind(N)
for i in range(L):
x,y = list(map(int,input().split()))
B.unite(x,y)
dic = defaultdict(int)
for i in range(1,N+1):
dic[A.find(i),B.find(i)] += 1
Ans = list(dic[A.par[i],B.par[i]] for i in range(1,N+1))
print((" ".join(map(str,Ans))))
| # python3 (3.4.3)
import sys
input = sys.stdin.readline
# functions
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.rank = [0] * (n)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def is_same(self, x, y):
return self.find(x) == self.find(y)
# main
from collections import defaultdict
N,K,L = list(map(int,input().split()))
PQ = [list(map(int,input().split())) for _ in range(K)]
RS = [list(map(int,input().split())) for _ in range(L)]
# 道路
A = UnionFind(N)
for p,q in PQ:
A.unite(p-1,q-1)
# 鉄道
B = UnionFind(N)
for r,s in RS:
B.unite(r-1,s-1)
dic = defaultdict(int)
for i in range(N):
dic[A.find(i), B.find(i)] += 1
Ans = list(dic[A.find(i), B.find(i)] for i in range(N))
print((" ".join(map(str,Ans)))) | 44 | 52 | 1,095 | 1,217 | from collections import defaultdict
N, K, L = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
# 道路
A = UnionFind(N)
for i in range(K):
x, y = list(map(int, input().split()))
A.unite(x, y)
# 鉄道
B = UnionFind(N)
for i in range(L):
x, y = list(map(int, input().split()))
B.unite(x, y)
dic = defaultdict(int)
for i in range(1, N + 1):
dic[A.find(i), B.find(i)] += 1
Ans = list(dic[A.par[i], B.par[i]] for i in range(1, N + 1))
print((" ".join(map(str, Ans))))
| # python3 (3.4.3)
import sys
input = sys.stdin.readline
# functions
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)]
self.rank = [0] * (n)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def is_same(self, x, y):
return self.find(x) == self.find(y)
# main
from collections import defaultdict
N, K, L = list(map(int, input().split()))
PQ = [list(map(int, input().split())) for _ in range(K)]
RS = [list(map(int, input().split())) for _ in range(L)]
# 道路
A = UnionFind(N)
for p, q in PQ:
A.unite(p - 1, q - 1)
# 鉄道
B = UnionFind(N)
for r, s in RS:
B.unite(r - 1, s - 1)
dic = defaultdict(int)
for i in range(N):
dic[A.find(i), B.find(i)] += 1
Ans = list(dic[A.find(i), B.find(i)] for i in range(N))
print((" ".join(map(str, Ans))))
| false | 15.384615 | [
"-from collections import defaultdict",
"+# python3 (3.4.3)",
"+import sys",
"-N, K, L = list(map(int, input().split()))",
"-",
"-",
"+input = sys.stdin.readline",
"+# functions",
"- self.par = [i for i in range(n + 1)]",
"- self.rank = [0] * (n + 1)",
"+ self.par = [i for i in range(n)]",
"+ self.rank = [0] * (n)",
"- def check(self, x, y):",
"+ def is_same(self, x, y):",
"+# main",
"+from collections import defaultdict",
"+",
"+N, K, L = list(map(int, input().split()))",
"+PQ = [list(map(int, input().split())) for _ in range(K)]",
"+RS = [list(map(int, input().split())) for _ in range(L)]",
"-for i in range(K):",
"- x, y = list(map(int, input().split()))",
"- A.unite(x, y)",
"+for p, q in PQ:",
"+ A.unite(p - 1, q - 1)",
"-for i in range(L):",
"- x, y = list(map(int, input().split()))",
"- B.unite(x, y)",
"+for r, s in RS:",
"+ B.unite(r - 1, s - 1)",
"-for i in range(1, N + 1):",
"+for i in range(N):",
"-Ans = list(dic[A.par[i], B.par[i]] for i in range(1, N + 1))",
"+Ans = list(dic[A.find(i), B.find(i)] for i in range(N))"
] | false | 0.190871 | 0.044842 | 4.256506 | [
"s896509030",
"s508385767"
] |
u057109575 | p02804 | python | s017860036 | s267046349 | 284 | 144 | 70,636 | 91,752 | Accepted | Accepted | 49.3 | N, K, *A = list(map(int, open(0).read().split()))
MOD = 10 ** 9 + 7
fac = [0] * (N + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, N + 1):
fac[i] = fac[i - 1] * i % MOD
finv = [0] * (N + 1)
finv[N] = pow(fac[N], MOD - 2, MOD)
for i in reversed(list(range(1, N + 1))):
finv[i - 1] = finv[i] * i % MOD
def comb(n, k):
if n < k:
return 0
return fac[n] * finv[k] * finv[n - k] % MOD
ans = 0
for i, a in enumerate(sorted(A, reverse=True)):
ans += a * comb(N - i - 1, K - 1)
ans -= a * comb(i, K - 1)
ans %= MOD
print(ans)
| N, K, *A = list(map(int, open(0).read().split()))
MAX = 10 ** 5 + 1
MOD = 10 ** 9 + 7
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
fac[i] = fac[i - 1] * i % MOD
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(list(range(1, MAX + 1))):
finv[i - 1] = finv[i] * i % MOD
def comb(n, k):
if n < k or k < 0:
return 0
return (fac[n] * finv[k] * finv[n - k]) % MOD
A.sort()
ans = 0
for i in range(N):
if i >= K - 1:
ans += comb(i, K - 1) * A[i]
if i + K - 1 < N:
ans -= comb(N - i - 1, K - 1) * A[i]
ans %= MOD
print(ans)
| 27 | 34 | 574 | 690 | N, K, *A = list(map(int, open(0).read().split()))
MOD = 10**9 + 7
fac = [0] * (N + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, N + 1):
fac[i] = fac[i - 1] * i % MOD
finv = [0] * (N + 1)
finv[N] = pow(fac[N], MOD - 2, MOD)
for i in reversed(list(range(1, N + 1))):
finv[i - 1] = finv[i] * i % MOD
def comb(n, k):
if n < k:
return 0
return fac[n] * finv[k] * finv[n - k] % MOD
ans = 0
for i, a in enumerate(sorted(A, reverse=True)):
ans += a * comb(N - i - 1, K - 1)
ans -= a * comb(i, K - 1)
ans %= MOD
print(ans)
| N, K, *A = list(map(int, open(0).read().split()))
MAX = 10**5 + 1
MOD = 10**9 + 7
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
fac[i] = fac[i - 1] * i % MOD
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(list(range(1, MAX + 1))):
finv[i - 1] = finv[i] * i % MOD
def comb(n, k):
if n < k or k < 0:
return 0
return (fac[n] * finv[k] * finv[n - k]) % MOD
A.sort()
ans = 0
for i in range(N):
if i >= K - 1:
ans += comb(i, K - 1) * A[i]
if i + K - 1 < N:
ans -= comb(N - i - 1, K - 1) * A[i]
ans %= MOD
print(ans)
| false | 20.588235 | [
"+MAX = 10**5 + 1",
"-fac = [0] * (N + 1)",
"+# Factorial",
"+fac = [0] * (MAX + 1)",
"-for i in range(2, N + 1):",
"+for i in range(2, MAX + 1):",
"-finv = [0] * (N + 1)",
"-finv[N] = pow(fac[N], MOD - 2, MOD)",
"-for i in reversed(list(range(1, N + 1))):",
"+# Inverse factorial",
"+finv = [0] * (MAX + 1)",
"+finv[MAX] = pow(fac[MAX], MOD - 2, MOD)",
"+for i in reversed(list(range(1, MAX + 1))):",
"- if n < k:",
"+ if n < k or k < 0:",
"- return fac[n] * finv[k] * finv[n - k] % MOD",
"+ return (fac[n] * finv[k] * finv[n - k]) % MOD",
"+A.sort()",
"-for i, a in enumerate(sorted(A, reverse=True)):",
"- ans += a * comb(N - i - 1, K - 1)",
"- ans -= a * comb(i, K - 1)",
"+for i in range(N):",
"+ if i >= K - 1:",
"+ ans += comb(i, K - 1) * A[i]",
"+ if i + K - 1 < N:",
"+ ans -= comb(N - i - 1, K - 1) * A[i]"
] | false | 0.080824 | 0.248657 | 0.325042 | [
"s017860036",
"s267046349"
] |
u285443936 | p04015 | python | s628563561 | s792646288 | 443 | 345 | 93,004 | 92,636 | Accepted | Accepted | 22.12 | N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
ans = 0
dp = [[[0]*(50*N+1) for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1
for j in range(1,N+1):
for k in range(N+1):
for s in range(50*N+1):
dp[j][k][s] = dp[j-1][k][s]
if s>=x[j-1]:
dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
for k in range(1,N+1):
ans += dp[N][k][k*A]
print(ans) | N, A = list(map(int, input().split()))
x= [int(i) for i in input().split()]
X = max(x)
dp = [[[0]*(X*N+1) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 1
ans = 0
for j in range(1,N+1):
for k in range(j+1):
for s in range(X*N+1):
dp[j][k][s] = dp[j-1][k][s]
if s >= x[j-1]:
dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
for i in range(N+1):
ans += dp[-1][i][i*A]
if (i+1)*A > X*N:
break
print((ans-1)) | 15 | 19 | 403 | 454 | N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
ans = 0
dp = [[[0] * (50 * N + 1) for j in range(N + 1)] for k in range(N + 1)]
dp[0][0][0] = 1
for j in range(1, N + 1):
for k in range(N + 1):
for s in range(50 * N + 1):
dp[j][k][s] = dp[j - 1][k][s]
if s >= x[j - 1]:
dp[j][k][s] += dp[j - 1][k - 1][s - x[j - 1]]
for k in range(1, N + 1):
ans += dp[N][k][k * A]
print(ans)
| N, A = list(map(int, input().split()))
x = [int(i) for i in input().split()]
X = max(x)
dp = [[[0] * (X * N + 1) for i in range(N + 1)] for j in range(N + 1)]
dp[0][0][0] = 1
ans = 0
for j in range(1, N + 1):
for k in range(j + 1):
for s in range(X * N + 1):
dp[j][k][s] = dp[j - 1][k][s]
if s >= x[j - 1]:
dp[j][k][s] += dp[j - 1][k - 1][s - x[j - 1]]
for i in range(N + 1):
ans += dp[-1][i][i * A]
if (i + 1) * A > X * N:
break
print((ans - 1))
| false | 21.052632 | [
"+X = max(x)",
"+dp = [[[0] * (X * N + 1) for i in range(N + 1)] for j in range(N + 1)]",
"+dp[0][0][0] = 1",
"-dp = [[[0] * (50 * N + 1) for j in range(N + 1)] for k in range(N + 1)]",
"-dp[0][0][0] = 1",
"- for k in range(N + 1):",
"- for s in range(50 * N + 1):",
"+ for k in range(j + 1):",
"+ for s in range(X * N + 1):",
"-for k in range(1, N + 1):",
"- ans += dp[N][k][k * A]",
"-print(ans)",
"+for i in range(N + 1):",
"+ ans += dp[-1][i][i * A]",
"+ if (i + 1) * A > X * N:",
"+ break",
"+print((ans - 1))"
] | false | 0.427784 | 0.050218 | 8.51846 | [
"s628563561",
"s792646288"
] |
u810787773 | p02912 | python | s912311754 | s886927382 | 579 | 124 | 20,504 | 20,604 | Accepted | Accepted | 78.58 | import copy
def bi_search(money,M,N):
money.sort()
#list = []
#for i in range(0,money[N-1]+2,1):
#list.append(i)
left = 0
right = money[N-1]+1
mid = 0
#print(list,left,right)
while True:
mid = int( (left+right)/2 )
cnt = 0
#print(left,right,mid)
#print(money)
money_tmp = copy.copy(money)
for i in range(N):
while True:
#print(money_tmp[i],i)
if money_tmp[i] <= mid:
break
else:
money_tmp[i] //= 2
cnt += 1
#print(cnt)
if cnt == M:
return mid,cnt
elif cnt < M:
right = mid
tmp = cnt
elif cnt > M:
left = mid + 1
if left == right:
return right,tmp
def main():
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
max_money,cnt = bi_search(A,M,N)
#print (cnt)
cnt = M-cnt
ans = 0
for i in range(N):
if max_money >= A[i]:
continue
#ans += A[i]
else:
while True:
A[i] //= 2
if max_money >= A[i]:
#ans += A[i]
break
A.sort(reverse = True)
j = 0
if A[j] == 0:
return 0
for i in range(cnt):
A[j] //= 2
j += 1
for i in range(N):
ans += A[i]
return ans
print((main()))
| from heapq import heapify,heappush,heappop
def main():
N,M = list(map(int,input().split()))
A = [-x for x in map(int,input().split())]
heapify(A)
for i in range(M):
tmp = -heappop(A)
tmp2 = tmp//2
heappush(A,-tmp2)
ans = 0
for i in range(N):
ans += A[i]
ans = abs(ans)
return ans
print((main()))
| 68 | 18 | 1,560 | 372 | import copy
def bi_search(money, M, N):
money.sort()
# list = []
# for i in range(0,money[N-1]+2,1):
# list.append(i)
left = 0
right = money[N - 1] + 1
mid = 0
# print(list,left,right)
while True:
mid = int((left + right) / 2)
cnt = 0
# print(left,right,mid)
# print(money)
money_tmp = copy.copy(money)
for i in range(N):
while True:
# print(money_tmp[i],i)
if money_tmp[i] <= mid:
break
else:
money_tmp[i] //= 2
cnt += 1
# print(cnt)
if cnt == M:
return mid, cnt
elif cnt < M:
right = mid
tmp = cnt
elif cnt > M:
left = mid + 1
if left == right:
return right, tmp
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
max_money, cnt = bi_search(A, M, N)
# print (cnt)
cnt = M - cnt
ans = 0
for i in range(N):
if max_money >= A[i]:
continue
# ans += A[i]
else:
while True:
A[i] //= 2
if max_money >= A[i]:
# ans += A[i]
break
A.sort(reverse=True)
j = 0
if A[j] == 0:
return 0
for i in range(cnt):
A[j] //= 2
j += 1
for i in range(N):
ans += A[i]
return ans
print((main()))
| from heapq import heapify, heappush, heappop
def main():
N, M = list(map(int, input().split()))
A = [-x for x in map(int, input().split())]
heapify(A)
for i in range(M):
tmp = -heappop(A)
tmp2 = tmp // 2
heappush(A, -tmp2)
ans = 0
for i in range(N):
ans += A[i]
ans = abs(ans)
return ans
print((main()))
| false | 73.529412 | [
"-import copy",
"-",
"-",
"-def bi_search(money, M, N):",
"- money.sort()",
"- # list = []",
"- # for i in range(0,money[N-1]+2,1):",
"- # list.append(i)",
"- left = 0",
"- right = money[N - 1] + 1",
"- mid = 0",
"- # print(list,left,right)",
"- while True:",
"- mid = int((left + right) / 2)",
"- cnt = 0",
"- # print(left,right,mid)",
"- # print(money)",
"- money_tmp = copy.copy(money)",
"- for i in range(N):",
"- while True:",
"- # print(money_tmp[i],i)",
"- if money_tmp[i] <= mid:",
"- break",
"- else:",
"- money_tmp[i] //= 2",
"- cnt += 1",
"- # print(cnt)",
"- if cnt == M:",
"- return mid, cnt",
"- elif cnt < M:",
"- right = mid",
"- tmp = cnt",
"- elif cnt > M:",
"- left = mid + 1",
"- if left == right:",
"- return right, tmp",
"+from heapq import heapify, heappush, heappop",
"- A = list(map(int, input().split()))",
"- max_money, cnt = bi_search(A, M, N)",
"- # print (cnt)",
"- cnt = M - cnt",
"+ A = [-x for x in map(int, input().split())]",
"+ heapify(A)",
"+ for i in range(M):",
"+ tmp = -heappop(A)",
"+ tmp2 = tmp // 2",
"+ heappush(A, -tmp2)",
"- if max_money >= A[i]:",
"- continue",
"- # ans += A[i]",
"- else:",
"- while True:",
"- A[i] //= 2",
"- if max_money >= A[i]:",
"- # ans += A[i]",
"- break",
"- A.sort(reverse=True)",
"- j = 0",
"- if A[j] == 0:",
"- return 0",
"- for i in range(cnt):",
"- A[j] //= 2",
"- j += 1",
"- for i in range(N):",
"+ ans = abs(ans)"
] | false | 0.037409 | 0.042966 | 0.870672 | [
"s912311754",
"s886927382"
] |
u704001626 | p03805 | python | s910368659 | s912005528 | 133 | 26 | 3,700 | 3,064 | Accepted | Accepted | 80.45 | # -*- coding: utf-8 -*-
import copy
n,m = list(map(int,input().split()))
rinset = [[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
a,b = list(map(int,input().split()))
rinset[a][b]=b
rinset[b][a]=a
cnt = 0
def solve(start,visitted):
global cnt
visitted = copy.deepcopy(visitted)
visitted.append(start)
if len(visitted) == n:
cnt+=1
return
next_start=[i for i in rinset[start] if (i>1 and i not in visitted)]
for i in next_start:
solve(i,visitted)
solve(1,[])
print(cnt)
| # -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]
#逆順にしたもの追加
ab += [[b,a] for a,b in ab]
#辺id付きで、idがfrom,abi[from]=[to1,to2,...] のリスト
abi = [[] for _ in range(n+1)]
for i,(a,b) in enumerate(ab):
abi[a].append(b)
#再起のlimitを上げる
import sys
sys.setrecursionlimit(4100000)
def dfs(idx=1,visitted=[1],cnt=1):
ret = 0
if cnt==n:
return 1
for to in abi[idx]:
if to not in visitted:
ret += dfs(to,visitted+[to],cnt+1)
return ret
print((dfs())) | 24 | 27 | 558 | 579 | # -*- coding: utf-8 -*-
import copy
n, m = list(map(int, input().split()))
rinset = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
rinset[a][b] = b
rinset[b][a] = a
cnt = 0
def solve(start, visitted):
global cnt
visitted = copy.deepcopy(visitted)
visitted.append(start)
if len(visitted) == n:
cnt += 1
return
next_start = [i for i in rinset[start] if (i > 1 and i not in visitted)]
for i in next_start:
solve(i, visitted)
solve(1, [])
print(cnt)
| # -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
# 逆順にしたもの追加
ab += [[b, a] for a, b in ab]
# 辺id付きで、idがfrom,abi[from]=[to1,to2,...] のリスト
abi = [[] for _ in range(n + 1)]
for i, (a, b) in enumerate(ab):
abi[a].append(b)
# 再起のlimitを上げる
import sys
sys.setrecursionlimit(4100000)
def dfs(idx=1, visitted=[1], cnt=1):
ret = 0
if cnt == n:
return 1
for to in abi[idx]:
if to not in visitted:
ret += dfs(to, visitted + [to], cnt + 1)
return ret
print((dfs()))
| false | 11.111111 | [
"-import copy",
"+n, m = list(map(int, input().split()))",
"+ab = [list(map(int, input().split())) for i in range(m)]",
"+# 逆順にしたもの追加",
"+ab += [[b, a] for a, b in ab]",
"+# 辺id付きで、idがfrom,abi[from]=[to1,to2,...] のリスト",
"+abi = [[] for _ in range(n + 1)]",
"+for i, (a, b) in enumerate(ab):",
"+ abi[a].append(b)",
"+# 再起のlimitを上げる",
"+import sys",
"-n, m = list(map(int, input().split()))",
"-rinset = [[0] * (n + 1) for _ in range(n + 1)]",
"-for _ in range(m):",
"- a, b = list(map(int, input().split()))",
"- rinset[a][b] = b",
"- rinset[b][a] = a",
"-cnt = 0",
"+sys.setrecursionlimit(4100000)",
"-def solve(start, visitted):",
"- global cnt",
"- visitted = copy.deepcopy(visitted)",
"- visitted.append(start)",
"- if len(visitted) == n:",
"- cnt += 1",
"- return",
"- next_start = [i for i in rinset[start] if (i > 1 and i not in visitted)]",
"- for i in next_start:",
"- solve(i, visitted)",
"+def dfs(idx=1, visitted=[1], cnt=1):",
"+ ret = 0",
"+ if cnt == n:",
"+ return 1",
"+ for to in abi[idx]:",
"+ if to not in visitted:",
"+ ret += dfs(to, visitted + [to], cnt + 1)",
"+ return ret",
"-solve(1, [])",
"-print(cnt)",
"+print((dfs()))"
] | false | 0.04043 | 0.045131 | 0.895843 | [
"s910368659",
"s912005528"
] |
u163703551 | p03779 | python | s601016284 | s865569384 | 26 | 17 | 2,940 | 3,060 | Accepted | Accepted | 34.62 | x = eval(input())
x = int(x)
def f(x):
for n in range(0, x + 1):
s = n * (n + 1) / 2
if s >= x:
return n
print((f(x)))
| import sys
# sys.stdin = open('c1.in')
def f(x):
for n in range(0, 10 ** 9):
s = n * (n + 1) / 2
if s >= x:
return n
def f2(x):
a = 0
b = 10 ** 5
while b - a > 1:
n = (a + b) // 2
s = n * (n + 1) // 2
if s >= x:
b = n
else:
a = n
return b
x = int(eval(input()))
print((f2(x)))
# for x in range(10 ** 9, 1, -10 ** 5):
# if f(x) != f2(x):
# print(x, f(x), f2(x))
# break
| 12 | 31 | 158 | 522 | x = eval(input())
x = int(x)
def f(x):
for n in range(0, x + 1):
s = n * (n + 1) / 2
if s >= x:
return n
print((f(x)))
| import sys
# sys.stdin = open('c1.in')
def f(x):
for n in range(0, 10**9):
s = n * (n + 1) / 2
if s >= x:
return n
def f2(x):
a = 0
b = 10**5
while b - a > 1:
n = (a + b) // 2
s = n * (n + 1) // 2
if s >= x:
b = n
else:
a = n
return b
x = int(eval(input()))
print((f2(x)))
# for x in range(10 ** 9, 1, -10 ** 5):
# if f(x) != f2(x):
# print(x, f(x), f2(x))
# break
| false | 61.290323 | [
"-x = eval(input())",
"-x = int(x)",
"+import sys",
"-",
"+# sys.stdin = open('c1.in')",
"- for n in range(0, x + 1):",
"+ for n in range(0, 10**9):",
"-print((f(x)))",
"+def f2(x):",
"+ a = 0",
"+ b = 10**5",
"+ while b - a > 1:",
"+ n = (a + b) // 2",
"+ s = n * (n + 1) // 2",
"+ if s >= x:",
"+ b = n",
"+ else:",
"+ a = n",
"+ return b",
"+",
"+",
"+x = int(eval(input()))",
"+print((f2(x)))",
"+# for x in range(10 ** 9, 1, -10 ** 5):",
"+# if f(x) != f2(x):",
"+# print(x, f(x), f2(x))",
"+# break"
] | false | 0.082893 | 0.054228 | 1.528601 | [
"s601016284",
"s865569384"
] |
u727067903 | p03470 | python | s139783923 | s937363958 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | N = int(eval(input()))
inputVal = [int(eval(input())) for i in range(N)]
inputVal.sort()
default = 0
count = 0
for i in inputVal:
if i != default:
count += 1
default = i
print(count) | N = int(eval(input()))
inputVal = [int(eval(input())) for i in range(N)]
print((len(set(inputVal)))) | 12 | 3 | 203 | 88 | N = int(eval(input()))
inputVal = [int(eval(input())) for i in range(N)]
inputVal.sort()
default = 0
count = 0
for i in inputVal:
if i != default:
count += 1
default = i
print(count)
| N = int(eval(input()))
inputVal = [int(eval(input())) for i in range(N)]
print((len(set(inputVal))))
| false | 75 | [
"-inputVal.sort()",
"-default = 0",
"-count = 0",
"-for i in inputVal:",
"- if i != default:",
"- count += 1",
"- default = i",
"-print(count)",
"+print((len(set(inputVal))))"
] | false | 0.038323 | 0.039692 | 0.965499 | [
"s139783923",
"s937363958"
] |
u721553535 | p03160 | python | s765469852 | s777694228 | 206 | 143 | 109,696 | 20,444 | Accepted | Accepted | 30.58 | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
def solve(stns, idx, mem):
if idx >= len(stns) -1:
return 0
if idx in mem:
return mem[idx]
if idx == len(stns) - 2:
#cant take more than one step
final_step = abs(stns[idx] - stns[idx+1])
mem[idx] = final_step
return final_step
else:
# step: i + 11
step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx+1])
# step: i + 2
step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx+2])
min_cost = min(step1, step2)
mem[idx] = min_cost
return min_cost
def take_input():
n = eval(input())
stns = [int(x) for x in input().split()]
mem = {}
res = solve(stns, 0, mem)
print(res)
take_input() | import math
def solve(stns, n, idx, dp):
for i in range(n):
for j in range(1, 3):
j = i + j # step i + 1, i + 2
if j < n:
# min(existing min, new path using i)
dp[j] = min(dp[j], dp[i] + abs(stns[i] - stns[j]))
return dp[n-1]
def take_input():
n = int(eval(input()))
stns = [int(x) for x in input().split()]
dp = [math.inf for i in range(n)]
dp[0] = 0
res = solve(stns, n, 0, dp)
print(res)
take_input() | 40 | 21 | 888 | 517 | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
def solve(stns, idx, mem):
if idx >= len(stns) - 1:
return 0
if idx in mem:
return mem[idx]
if idx == len(stns) - 2:
# cant take more than one step
final_step = abs(stns[idx] - stns[idx + 1])
mem[idx] = final_step
return final_step
else:
# step: i + 11
step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx + 1])
# step: i + 2
step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx + 2])
min_cost = min(step1, step2)
mem[idx] = min_cost
return min_cost
def take_input():
n = eval(input())
stns = [int(x) for x in input().split()]
mem = {}
res = solve(stns, 0, mem)
print(res)
take_input()
| import math
def solve(stns, n, idx, dp):
for i in range(n):
for j in range(1, 3):
j = i + j # step i + 1, i + 2
if j < n:
# min(existing min, new path using i)
dp[j] = min(dp[j], dp[i] + abs(stns[i] - stns[j]))
return dp[n - 1]
def take_input():
n = int(eval(input()))
stns = [int(x) for x in input().split()]
dp = [math.inf for i in range(n)]
dp[0] = 0
res = solve(stns, n, 0, dp)
print(res)
take_input()
| false | 47.5 | [
"-import sys",
"-",
"-reader = (s.rstrip() for s in sys.stdin)",
"-input = reader.__next__",
"-sys.setrecursionlimit(1000000)",
"+import math",
"-def solve(stns, idx, mem):",
"- if idx >= len(stns) - 1:",
"- return 0",
"- if idx in mem:",
"- return mem[idx]",
"- if idx == len(stns) - 2:",
"- # cant take more than one step",
"- final_step = abs(stns[idx] - stns[idx + 1])",
"- mem[idx] = final_step",
"- return final_step",
"- else:",
"- # step: i + 11",
"- step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx + 1])",
"- # step: i + 2",
"- step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx + 2])",
"- min_cost = min(step1, step2)",
"- mem[idx] = min_cost",
"- return min_cost",
"+def solve(stns, n, idx, dp):",
"+ for i in range(n):",
"+ for j in range(1, 3):",
"+ j = i + j # step i + 1, i + 2",
"+ if j < n:",
"+ # min(existing min, new path using i)",
"+ dp[j] = min(dp[j], dp[i] + abs(stns[i] - stns[j]))",
"+ return dp[n - 1]",
"- n = eval(input())",
"+ n = int(eval(input()))",
"- mem = {}",
"- res = solve(stns, 0, mem)",
"+ dp = [math.inf for i in range(n)]",
"+ dp[0] = 0",
"+ res = solve(stns, n, 0, dp)"
] | false | 0.035477 | 0.034641 | 1.024133 | [
"s765469852",
"s777694228"
] |
u352394527 | p00535 | python | s572322314 | s797418658 | 5,870 | 3,210 | 16,420 | 16,524 | Accepted | Accepted | 45.32 | from heapq import heappush, heappop
h, w = list(map(int, input().split()))
mp = [[-1] + list(eval(input())) + [-1] for _ in range(h)]
mp.insert(0, [-1] * (w + 2))
mp.append([-1] * (w + 2))
que = []
for y in range(1, h + 1):
for x in range(1, w + 1):
if "1" <= mp[y][x] <= "9":
mp[y][x] = int(mp[y][x])
elif mp[y][x] == ".":
mp[y][x] = 0
heappush(que, (0, x, y))
vec = ((0, 1), (0, -1), (1, 1), (1, 0), (1, -1), (-1, 1), (-1, 0), (-1, -1))
while que:
turn, x, y = heappop(que)
for dx, dy in vec:
nx, ny = x + dx, y + dy
if mp[ny][nx] > 0:
mp[ny][nx] -= 1
if mp[ny][nx] == 0:
heappush(que, (turn + 1, nx, ny))
print(turn)
| from heapq import heappush, heappop
def main():
h, w = list(map(int, input().split()))
mp = [[-1] + list(eval(input())) + [-1] for _ in range(h)]
mp.insert(0, [-1] * (w + 2))
mp.append([-1] * (w + 2))
que = []
for y in range(1, h + 1):
for x in range(1, w + 1):
if "1" <= mp[y][x] <= "9":
mp[y][x] = int(mp[y][x])
elif mp[y][x] == ".":
mp[y][x] = 0
heappush(que, (0, x, y))
vec = ((0, 1), (0, -1), (1, 1), (1, 0), (1, -1), (-1, 1), (-1, 0), (-1, -1))
while que:
turn, x, y = heappop(que)
for dx, dy in vec:
nx, ny = x + dx, y + dy
if mp[ny][nx] > 0:
mp[ny][nx] -= 1
if mp[ny][nx] == 0:
heappush(que, (turn + 1, nx, ny))
print(turn)
main()
| 24 | 30 | 692 | 771 | from heapq import heappush, heappop
h, w = list(map(int, input().split()))
mp = [[-1] + list(eval(input())) + [-1] for _ in range(h)]
mp.insert(0, [-1] * (w + 2))
mp.append([-1] * (w + 2))
que = []
for y in range(1, h + 1):
for x in range(1, w + 1):
if "1" <= mp[y][x] <= "9":
mp[y][x] = int(mp[y][x])
elif mp[y][x] == ".":
mp[y][x] = 0
heappush(que, (0, x, y))
vec = ((0, 1), (0, -1), (1, 1), (1, 0), (1, -1), (-1, 1), (-1, 0), (-1, -1))
while que:
turn, x, y = heappop(que)
for dx, dy in vec:
nx, ny = x + dx, y + dy
if mp[ny][nx] > 0:
mp[ny][nx] -= 1
if mp[ny][nx] == 0:
heappush(que, (turn + 1, nx, ny))
print(turn)
| from heapq import heappush, heappop
def main():
h, w = list(map(int, input().split()))
mp = [[-1] + list(eval(input())) + [-1] for _ in range(h)]
mp.insert(0, [-1] * (w + 2))
mp.append([-1] * (w + 2))
que = []
for y in range(1, h + 1):
for x in range(1, w + 1):
if "1" <= mp[y][x] <= "9":
mp[y][x] = int(mp[y][x])
elif mp[y][x] == ".":
mp[y][x] = 0
heappush(que, (0, x, y))
vec = ((0, 1), (0, -1), (1, 1), (1, 0), (1, -1), (-1, 1), (-1, 0), (-1, -1))
while que:
turn, x, y = heappop(que)
for dx, dy in vec:
nx, ny = x + dx, y + dy
if mp[ny][nx] > 0:
mp[ny][nx] -= 1
if mp[ny][nx] == 0:
heappush(que, (turn + 1, nx, ny))
print(turn)
main()
| false | 20 | [
"-h, w = list(map(int, input().split()))",
"-mp = [[-1] + list(eval(input())) + [-1] for _ in range(h)]",
"-mp.insert(0, [-1] * (w + 2))",
"-mp.append([-1] * (w + 2))",
"-que = []",
"-for y in range(1, h + 1):",
"- for x in range(1, w + 1):",
"- if \"1\" <= mp[y][x] <= \"9\":",
"- mp[y][x] = int(mp[y][x])",
"- elif mp[y][x] == \".\":",
"- mp[y][x] = 0",
"- heappush(que, (0, x, y))",
"-vec = ((0, 1), (0, -1), (1, 1), (1, 0), (1, -1), (-1, 1), (-1, 0), (-1, -1))",
"-while que:",
"- turn, x, y = heappop(que)",
"- for dx, dy in vec:",
"- nx, ny = x + dx, y + dy",
"- if mp[ny][nx] > 0:",
"- mp[ny][nx] -= 1",
"- if mp[ny][nx] == 0:",
"- heappush(que, (turn + 1, nx, ny))",
"-print(turn)",
"+",
"+def main():",
"+ h, w = list(map(int, input().split()))",
"+ mp = [[-1] + list(eval(input())) + [-1] for _ in range(h)]",
"+ mp.insert(0, [-1] * (w + 2))",
"+ mp.append([-1] * (w + 2))",
"+ que = []",
"+ for y in range(1, h + 1):",
"+ for x in range(1, w + 1):",
"+ if \"1\" <= mp[y][x] <= \"9\":",
"+ mp[y][x] = int(mp[y][x])",
"+ elif mp[y][x] == \".\":",
"+ mp[y][x] = 0",
"+ heappush(que, (0, x, y))",
"+ vec = ((0, 1), (0, -1), (1, 1), (1, 0), (1, -1), (-1, 1), (-1, 0), (-1, -1))",
"+ while que:",
"+ turn, x, y = heappop(que)",
"+ for dx, dy in vec:",
"+ nx, ny = x + dx, y + dy",
"+ if mp[ny][nx] > 0:",
"+ mp[ny][nx] -= 1",
"+ if mp[ny][nx] == 0:",
"+ heappush(que, (turn + 1, nx, ny))",
"+ print(turn)",
"+",
"+",
"+main()"
] | false | 0.211177 | 0.086779 | 2.433511 | [
"s572322314",
"s797418658"
] |
u063052907 | p03681 | python | s198400357 | s284148434 | 703 | 40 | 5,176 | 3,064 | Accepted | Accepted | 94.31 | import sys
from math import factorial
sys.setrecursionlimit(500000)
N, M = list(map(int, input().split()))
MOD = 10**9 + 7
diff = abs(N - M)
if diff == 0:
ans = (factorial(N) * factorial(M)) * 2
elif diff == 1:
ans = factorial(N) * factorial(M)
else:
ans = 0
ans %= MOD
print(ans) | def fact(n):
ret = 1
MOD = 10**9 + 7
for i in range(1, n + 1):
ret = ret * i % MOD
return ret
N, M = list(map(int, input().split()))
MOD = 10**9 + 7
diff = abs(N - M)
if diff == 0:
ans = (fact(N) * fact(M)) * 2
elif diff == 1:
ans = fact(N) * fact(M)
else:
ans = 0
ans %= MOD
print(ans) | 20 | 23 | 311 | 344 | import sys
from math import factorial
sys.setrecursionlimit(500000)
N, M = list(map(int, input().split()))
MOD = 10**9 + 7
diff = abs(N - M)
if diff == 0:
ans = (factorial(N) * factorial(M)) * 2
elif diff == 1:
ans = factorial(N) * factorial(M)
else:
ans = 0
ans %= MOD
print(ans)
| def fact(n):
ret = 1
MOD = 10**9 + 7
for i in range(1, n + 1):
ret = ret * i % MOD
return ret
N, M = list(map(int, input().split()))
MOD = 10**9 + 7
diff = abs(N - M)
if diff == 0:
ans = (fact(N) * fact(M)) * 2
elif diff == 1:
ans = fact(N) * fact(M)
else:
ans = 0
ans %= MOD
print(ans)
| false | 13.043478 | [
"-import sys",
"-from math import factorial",
"+def fact(n):",
"+ ret = 1",
"+ MOD = 10**9 + 7",
"+ for i in range(1, n + 1):",
"+ ret = ret * i % MOD",
"+ return ret",
"-sys.setrecursionlimit(500000)",
"+",
"- ans = (factorial(N) * factorial(M)) * 2",
"+ ans = (fact(N) * fact(M)) * 2",
"- ans = factorial(N) * factorial(M)",
"+ ans = fact(N) * fact(M)"
] | false | 0.172161 | 0.038662 | 4.452986 | [
"s198400357",
"s284148434"
] |
u056358163 | p02574 | python | s226788464 | s118048319 | 750 | 575 | 127,728 | 127,960 | Accepted | Accepted | 23.33 | import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial ** 2, num+1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
flag = True
d_set = set()
for a in A:
while a != 1:
d = D[a]
if d in d_set:
flag = False
break
else:
d_set.add(d)
while a > 1 and a % d == 0:
a = a // d
if flag:
print('pairwise coprime')
exit()
if reduce(math.gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial ** 2, num+1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
flag = True
d_set = set()
for a in A:
while a != 1:
d = D[a]
if d in d_set:
flag = False
break
else:
d_set.add(d)
while a > 1 and a % d == 0:
a = a // d
if not(flag):
break
if flag:
print('pairwise coprime')
exit()
if reduce(math.gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| 46 | 48 | 1,014 | 1,048 | import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num + 1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num + 1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial**2, num + 1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
flag = True
d_set = set()
for a in A:
while a != 1:
d = D[a]
if d in d_set:
flag = False
break
else:
d_set.add(d)
while a > 1 and a % d == 0:
a = a // d
if flag:
print("pairwise coprime")
exit()
if reduce(math.gcd, A) == 1:
print("setwise coprime")
else:
print("not coprime")
| import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num + 1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num + 1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial**2, num + 1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
flag = True
d_set = set()
for a in A:
while a != 1:
d = D[a]
if d in d_set:
flag = False
break
else:
d_set.add(d)
while a > 1 and a % d == 0:
a = a // d
if not (flag):
break
if flag:
print("pairwise coprime")
exit()
if reduce(math.gcd, A) == 1:
print("setwise coprime")
else:
print("not coprime")
| false | 4.166667 | [
"+ if not (flag):",
"+ break"
] | false | 0.043914 | 0.038212 | 1.149208 | [
"s226788464",
"s118048319"
] |
u167681750 | p02881 | python | s749876356 | s329002061 | 270 | 219 | 2,940 | 3,064 | Accepted | Accepted | 18.89 | from math import *
n = int(eval(input()))
def ij(x):
for i in range(x):
i = x - i
if n / i == n//i:
return i, n//i
print((sum(ij(int(sqrt(n)))) - 2))
| from math import *
n = int(eval(input()))
def ij(x):
for i in range(x, 0, -1):
if n/i == n//i:
return i, n//i
print((sum(ij(int(sqrt(n)))) - 2)) | 10 | 9 | 185 | 170 | from math import *
n = int(eval(input()))
def ij(x):
for i in range(x):
i = x - i
if n / i == n // i:
return i, n // i
print((sum(ij(int(sqrt(n)))) - 2))
| from math import *
n = int(eval(input()))
def ij(x):
for i in range(x, 0, -1):
if n / i == n // i:
return i, n // i
print((sum(ij(int(sqrt(n)))) - 2))
| false | 10 | [
"- for i in range(x):",
"- i = x - i",
"+ for i in range(x, 0, -1):"
] | false | 0.050802 | 0.049816 | 1.019796 | [
"s749876356",
"s329002061"
] |
u720636500 | p03108 | python | s343722583 | s610853067 | 969 | 758 | 46,236 | 33,604 | Accepted | Accepted | 21.78 | N, M = list(map(int, input().split()))
lis = [[x, -1] for x in range(1, N + 1)]
Blis = [list(map(int, input().split())) for _ in range(M)]
inc = int(N*(N - 1)/2)
ans = [x for x in range(M)]
ans[M - 1] = inc
def root(a):
if lis[a - 1][1] < 0:
return lis[a - 1][0]
else:
k = root(lis[a - 1][1])
lis[a - 1][1] = k
return k
def size(a):
return -lis[root(a) - 1][1]
def connect(a, b):
A = root(a)
B = root(b)
if A == B:
return None
else:
if size(A) < size(B):
A, B = B, A
lis[A - 1][1] += lis[B - 1][1]
lis[B - 1][1] = A
for i in reversed(list(range(1, M))):
if root(Blis[i][0]) != root(Blis[i][1]):
ans[i - 1] = ans[i] - size(Blis[i][0])*size(Blis[i][1])
connect(Blis[i][0], Blis[i][1])
else:
ans[i - 1] = ans[i]
for i in range(M):
print((ans[i])) | N, M = list(map(int, input().split()))
Parent = [-1 for x in range(N + 5)]
lis = [list(map(int, input().split())) for _ in range(M)]
ini = int(N*(N - 1)/2)
ans = [x for x in range(M)]
ans[M - 1] = ini
def root(a):
if Parent[a] < 0:
return a
else:
k = root(Parent[a])
Parent[a] = k
return k
def size(a):
return -Parent[root(a)]
def connect(a, b):
A = root(a)
B = root(b)
if A == B:
return None
else:
if size(A) < size(B):
A, B = B, A
Parent[A] += Parent[B]
Parent[B] = A
for i in reversed(list(range(1, M))):
ans[i - 1] = ans[i]
if root(lis[i][0]) != root(lis[i][1]):
ans[i - 1] -= size(lis[i][0])*size(lis[i][1])
connect(lis[i][0], lis[i][1])
for i in range(M):
print((ans[i])) | 33 | 32 | 901 | 828 | N, M = list(map(int, input().split()))
lis = [[x, -1] for x in range(1, N + 1)]
Blis = [list(map(int, input().split())) for _ in range(M)]
inc = int(N * (N - 1) / 2)
ans = [x for x in range(M)]
ans[M - 1] = inc
def root(a):
if lis[a - 1][1] < 0:
return lis[a - 1][0]
else:
k = root(lis[a - 1][1])
lis[a - 1][1] = k
return k
def size(a):
return -lis[root(a) - 1][1]
def connect(a, b):
A = root(a)
B = root(b)
if A == B:
return None
else:
if size(A) < size(B):
A, B = B, A
lis[A - 1][1] += lis[B - 1][1]
lis[B - 1][1] = A
for i in reversed(list(range(1, M))):
if root(Blis[i][0]) != root(Blis[i][1]):
ans[i - 1] = ans[i] - size(Blis[i][0]) * size(Blis[i][1])
connect(Blis[i][0], Blis[i][1])
else:
ans[i - 1] = ans[i]
for i in range(M):
print((ans[i]))
| N, M = list(map(int, input().split()))
Parent = [-1 for x in range(N + 5)]
lis = [list(map(int, input().split())) for _ in range(M)]
ini = int(N * (N - 1) / 2)
ans = [x for x in range(M)]
ans[M - 1] = ini
def root(a):
if Parent[a] < 0:
return a
else:
k = root(Parent[a])
Parent[a] = k
return k
def size(a):
return -Parent[root(a)]
def connect(a, b):
A = root(a)
B = root(b)
if A == B:
return None
else:
if size(A) < size(B):
A, B = B, A
Parent[A] += Parent[B]
Parent[B] = A
for i in reversed(list(range(1, M))):
ans[i - 1] = ans[i]
if root(lis[i][0]) != root(lis[i][1]):
ans[i - 1] -= size(lis[i][0]) * size(lis[i][1])
connect(lis[i][0], lis[i][1])
for i in range(M):
print((ans[i]))
| false | 3.030303 | [
"-lis = [[x, -1] for x in range(1, N + 1)]",
"-Blis = [list(map(int, input().split())) for _ in range(M)]",
"-inc = int(N * (N - 1) / 2)",
"+Parent = [-1 for x in range(N + 5)]",
"+lis = [list(map(int, input().split())) for _ in range(M)]",
"+ini = int(N * (N - 1) / 2)",
"-ans[M - 1] = inc",
"+ans[M - 1] = ini",
"- if lis[a - 1][1] < 0:",
"- return lis[a - 1][0]",
"+ if Parent[a] < 0:",
"+ return a",
"- k = root(lis[a - 1][1])",
"- lis[a - 1][1] = k",
"+ k = root(Parent[a])",
"+ Parent[a] = k",
"- return -lis[root(a) - 1][1]",
"+ return -Parent[root(a)]",
"- lis[A - 1][1] += lis[B - 1][1]",
"- lis[B - 1][1] = A",
"+ Parent[A] += Parent[B]",
"+ Parent[B] = A",
"- if root(Blis[i][0]) != root(Blis[i][1]):",
"- ans[i - 1] = ans[i] - size(Blis[i][0]) * size(Blis[i][1])",
"- connect(Blis[i][0], Blis[i][1])",
"- else:",
"- ans[i - 1] = ans[i]",
"+ ans[i - 1] = ans[i]",
"+ if root(lis[i][0]) != root(lis[i][1]):",
"+ ans[i - 1] -= size(lis[i][0]) * size(lis[i][1])",
"+ connect(lis[i][0], lis[i][1])"
] | false | 0.036515 | 0.036187 | 1.009069 | [
"s343722583",
"s610853067"
] |
u467826805 | p03457 | python | s957821649 | s679583969 | 468 | 400 | 11,816 | 3,064 | Accepted | Accepted | 14.53 | n = int(eval(input()))
x = [0]
y = [0]
t = [0]
fl = True
def judge(a,b,c,d,e,f):
if abs(b-a)+abs(d-c) <= f-e and abs(b+d-a-c)%2 == abs(f-e)%2:
return False
return True
for i in range(n):
tt,xx,yy = list(map(int,input().split()))
x.append(xx)
y.append(yy)
t.append(tt)
if judge(x[i],x[i+1],y[i],y[i+1],t[i],t[i+1]):
fl = False
if(fl):
print("Yes")
else:
print("No")
| n = int(eval(input()))
x = 0
y = 0
t = 0
a = 0
def trav(a,b,c,d,e,f):
if abs(a-b) + abs(c-d) <= e - f and ((a-b) % 2 + (c-d) % 2)%2 == (e-f) % 2:
return 0
else:
return 1
for i in range(n):
tn,xn,yn = list(map(int,input().split()))
if trav(xn,x,yn,y,tn,t) == 0:
x = xn
y = yn
t = tn
else:
a = 1
if a == 0:
print("Yes")
else:
print("No")
| 20 | 22 | 424 | 421 | n = int(eval(input()))
x = [0]
y = [0]
t = [0]
fl = True
def judge(a, b, c, d, e, f):
if abs(b - a) + abs(d - c) <= f - e and abs(b + d - a - c) % 2 == abs(f - e) % 2:
return False
return True
for i in range(n):
tt, xx, yy = list(map(int, input().split()))
x.append(xx)
y.append(yy)
t.append(tt)
if judge(x[i], x[i + 1], y[i], y[i + 1], t[i], t[i + 1]):
fl = False
if fl:
print("Yes")
else:
print("No")
| n = int(eval(input()))
x = 0
y = 0
t = 0
a = 0
def trav(a, b, c, d, e, f):
if (
abs(a - b) + abs(c - d) <= e - f
and ((a - b) % 2 + (c - d) % 2) % 2 == (e - f) % 2
):
return 0
else:
return 1
for i in range(n):
tn, xn, yn = list(map(int, input().split()))
if trav(xn, x, yn, y, tn, t) == 0:
x = xn
y = yn
t = tn
else:
a = 1
if a == 0:
print("Yes")
else:
print("No")
| false | 9.090909 | [
"-x = [0]",
"-y = [0]",
"-t = [0]",
"-fl = True",
"+x = 0",
"+y = 0",
"+t = 0",
"+a = 0",
"-def judge(a, b, c, d, e, f):",
"- if abs(b - a) + abs(d - c) <= f - e and abs(b + d - a - c) % 2 == abs(f - e) % 2:",
"- return False",
"- return True",
"+def trav(a, b, c, d, e, f):",
"+ if (",
"+ abs(a - b) + abs(c - d) <= e - f",
"+ and ((a - b) % 2 + (c - d) % 2) % 2 == (e - f) % 2",
"+ ):",
"+ return 0",
"+ else:",
"+ return 1",
"- tt, xx, yy = list(map(int, input().split()))",
"- x.append(xx)",
"- y.append(yy)",
"- t.append(tt)",
"- if judge(x[i], x[i + 1], y[i], y[i + 1], t[i], t[i + 1]):",
"- fl = False",
"-if fl:",
"+ tn, xn, yn = list(map(int, input().split()))",
"+ if trav(xn, x, yn, y, tn, t) == 0:",
"+ x = xn",
"+ y = yn",
"+ t = tn",
"+ else:",
"+ a = 1",
"+if a == 0:"
] | false | 0.104683 | 0.197582 | 0.529823 | [
"s957821649",
"s679583969"
] |
u002459665 | p03862 | python | s939296081 | s067990703 | 113 | 101 | 14,052 | 14,252 | Accepted | Accepted | 10.62 | N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
sm = A[i] + A[i+1]
if sm > x:
diff = sm - x
if A[i+1] >= diff:
A[i+1] -= diff
else:
diff2 = diff - A[i+1]
A[i+1] = 0
A[i] -= diff2
cnt += diff
print(cnt)
| N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
if A[0] > x:
cnt += A[0] - x
A[0] = x
for i in range(N - 1):
sm = A[i] + A[i+1]
if sm > x:
diff = sm - x
A[i+1] -= diff
cnt += diff
print(cnt)
| 17 | 17 | 360 | 280 | N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
sm = A[i] + A[i + 1]
if sm > x:
diff = sm - x
if A[i + 1] >= diff:
A[i + 1] -= diff
else:
diff2 = diff - A[i + 1]
A[i + 1] = 0
A[i] -= diff2
cnt += diff
print(cnt)
| N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
if A[0] > x:
cnt += A[0] - x
A[0] = x
for i in range(N - 1):
sm = A[i] + A[i + 1]
if sm > x:
diff = sm - x
A[i + 1] -= diff
cnt += diff
print(cnt)
| false | 0 | [
"+if A[0] > x:",
"+ cnt += A[0] - x",
"+ A[0] = x",
"- if A[i + 1] >= diff:",
"- A[i + 1] -= diff",
"- else:",
"- diff2 = diff - A[i + 1]",
"- A[i + 1] = 0",
"- A[i] -= diff2",
"+ A[i + 1] -= diff"
] | false | 0.043997 | 0.043657 | 1.007781 | [
"s939296081",
"s067990703"
] |
u747602774 | p03293 | python | s697145525 | s641579349 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | S = list(eval(input())*2)
T = list(eval(input()))
ans = 'No'
for i in range(len(S)//2):
check = 1
for j in range(len(S)//2):
if S[i+j] != T[j]:
check = 0
if check == 1:
ans = 'Yes'
break
print(ans)
| s = eval(input())
t = eval(input())
if t in s+s:
print('Yes')
else:
print('No')
| 13 | 6 | 250 | 81 | S = list(eval(input()) * 2)
T = list(eval(input()))
ans = "No"
for i in range(len(S) // 2):
check = 1
for j in range(len(S) // 2):
if S[i + j] != T[j]:
check = 0
if check == 1:
ans = "Yes"
break
print(ans)
| s = eval(input())
t = eval(input())
if t in s + s:
print("Yes")
else:
print("No")
| false | 53.846154 | [
"-S = list(eval(input()) * 2)",
"-T = list(eval(input()))",
"-ans = \"No\"",
"-for i in range(len(S) // 2):",
"- check = 1",
"- for j in range(len(S) // 2):",
"- if S[i + j] != T[j]:",
"- check = 0",
"- if check == 1:",
"- ans = \"Yes\"",
"- break",
"-print(ans)",
"+s = eval(input())",
"+t = eval(input())",
"+if t in s + s:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.047894 | 0.048681 | 0.98382 | [
"s697145525",
"s641579349"
] |
u133936772 | p03416 | python | s905935540 | s225082624 | 83 | 62 | 2,940 | 9,156 | Accepted | Accepted | 25.3 | a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
s = list(str(i))
if s == s[::-1]:
ans += 1
print(ans) | a,b=list(map(int,input().split()))
print((sum(str(i)==str(i)[::-1] for i in range(a,b+1)))) | 7 | 2 | 129 | 84 | a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
s = list(str(i))
if s == s[::-1]:
ans += 1
print(ans)
| a, b = list(map(int, input().split()))
print((sum(str(i) == str(i)[::-1] for i in range(a, b + 1))))
| false | 71.428571 | [
"-ans = 0",
"-for i in range(a, b + 1):",
"- s = list(str(i))",
"- if s == s[::-1]:",
"- ans += 1",
"-print(ans)",
"+print((sum(str(i) == str(i)[::-1] for i in range(a, b + 1))))"
] | false | 0.120342 | 0.07343 | 1.638868 | [
"s905935540",
"s225082624"
] |
u071868443 | p02999 | python | s128611603 | s180465807 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | X, A = list(map(int, input().split()))
if X < A:
print('0')
else:
print('10') | X, A = list(map(int, input().split()))
if X < A:
print((0))
else:
print((10))
| 5 | 5 | 79 | 76 | X, A = list(map(int, input().split()))
if X < A:
print("0")
else:
print("10")
| X, A = list(map(int, input().split()))
if X < A:
print((0))
else:
print((10))
| false | 0 | [
"- print(\"0\")",
"+ print((0))",
"- print(\"10\")",
"+ print((10))"
] | false | 0.067888 | 0.066599 | 1.019359 | [
"s128611603",
"s180465807"
] |
u203843959 | p02623 | python | s768161296 | s545141260 | 237 | 152 | 130,180 | 134,128 | Accepted | Accepted | 35.86 | import bisect
N,M,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
sum_alist=[0]
for i in range(N):
sum_alist.append(sum_alist[-1]+alist[i])
#print(sum_alist)
sum_blist=[0]
for i in range(M):
sum_blist.append(sum_blist[-1]+blist[i])
#print(sum_blist)
limit_a=bisect.bisect(sum_alist,K)
#print(limit_a)
limit_b=bisect.bisect(sum_blist,K)
#print(limit_b)
answer=0
for i in reversed(list(range(1,limit_a))):
a_sum=sum_alist[i]
b_sum=K-a_sum
pos_b=bisect.bisect(sum_blist,b_sum)
#print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
answer=max(answer,i+pos_b-1)
for i in reversed(list(range(1,limit_b))):
b_sum=sum_blist[i]
a_sum=K-b_sum
pos_a=bisect.bisect(sum_alist,a_sum)
#print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
answer=max(answer,i+pos_a-1)
if limit_a==1:
pos_b=bisect.bisect(sum_blist,K)
answer=pos_b-1
elif limit_b==1:
pos_a=bisect.bisect(sum_alist,K)
answer=pos_a-1
print(answer) | N,M,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
sum_alist=[0]
for a in alist:
sum_alist.append(sum_alist[-1]+a)
sum_blist=[0]
for b in blist:
sum_blist.append(sum_blist[-1]+b)
index_b=M
answer=0
for i in range(N+1):
sum_a=sum_alist[i]
if sum_a>K:
break
while sum_a+sum_blist[index_b]>K:
index_b-=1
#print(i,index_b)
answer=max(answer,i+index_b)
print(answer) | 44 | 25 | 1,012 | 478 | import bisect
N, M, K = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
sum_alist = [0]
for i in range(N):
sum_alist.append(sum_alist[-1] + alist[i])
# print(sum_alist)
sum_blist = [0]
for i in range(M):
sum_blist.append(sum_blist[-1] + blist[i])
# print(sum_blist)
limit_a = bisect.bisect(sum_alist, K)
# print(limit_a)
limit_b = bisect.bisect(sum_blist, K)
# print(limit_b)
answer = 0
for i in reversed(list(range(1, limit_a))):
a_sum = sum_alist[i]
b_sum = K - a_sum
pos_b = bisect.bisect(sum_blist, b_sum)
# print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
answer = max(answer, i + pos_b - 1)
for i in reversed(list(range(1, limit_b))):
b_sum = sum_blist[i]
a_sum = K - b_sum
pos_a = bisect.bisect(sum_alist, a_sum)
# print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
answer = max(answer, i + pos_a - 1)
if limit_a == 1:
pos_b = bisect.bisect(sum_blist, K)
answer = pos_b - 1
elif limit_b == 1:
pos_a = bisect.bisect(sum_alist, K)
answer = pos_a - 1
print(answer)
| N, M, K = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
sum_alist = [0]
for a in alist:
sum_alist.append(sum_alist[-1] + a)
sum_blist = [0]
for b in blist:
sum_blist.append(sum_blist[-1] + b)
index_b = M
answer = 0
for i in range(N + 1):
sum_a = sum_alist[i]
if sum_a > K:
break
while sum_a + sum_blist[index_b] > K:
index_b -= 1
# print(i,index_b)
answer = max(answer, i + index_b)
print(answer)
| false | 43.181818 | [
"-import bisect",
"-",
"-for i in range(N):",
"- sum_alist.append(sum_alist[-1] + alist[i])",
"-# print(sum_alist)",
"+for a in alist:",
"+ sum_alist.append(sum_alist[-1] + a)",
"-for i in range(M):",
"- sum_blist.append(sum_blist[-1] + blist[i])",
"-# print(sum_blist)",
"-limit_a = bisect.bisect(sum_alist, K)",
"-# print(limit_a)",
"-limit_b = bisect.bisect(sum_blist, K)",
"-# print(limit_b)",
"+for b in blist:",
"+ sum_blist.append(sum_blist[-1] + b)",
"+index_b = M",
"-for i in reversed(list(range(1, limit_a))):",
"- a_sum = sum_alist[i]",
"- b_sum = K - a_sum",
"- pos_b = bisect.bisect(sum_blist, b_sum)",
"- # print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)",
"- answer = max(answer, i + pos_b - 1)",
"-for i in reversed(list(range(1, limit_b))):",
"- b_sum = sum_blist[i]",
"- a_sum = K - b_sum",
"- pos_a = bisect.bisect(sum_alist, a_sum)",
"- # print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)",
"- answer = max(answer, i + pos_a - 1)",
"-if limit_a == 1:",
"- pos_b = bisect.bisect(sum_blist, K)",
"- answer = pos_b - 1",
"-elif limit_b == 1:",
"- pos_a = bisect.bisect(sum_alist, K)",
"- answer = pos_a - 1",
"+for i in range(N + 1):",
"+ sum_a = sum_alist[i]",
"+ if sum_a > K:",
"+ break",
"+ while sum_a + sum_blist[index_b] > K:",
"+ index_b -= 1",
"+ # print(i,index_b)",
"+ answer = max(answer, i + index_b)"
] | false | 0.03536 | 0.03531 | 1.00142 | [
"s768161296",
"s545141260"
] |
u367130284 | p03487 | python | s511446182 | s848869648 | 77 | 68 | 18,344 | 18,728 | Accepted | Accepted | 11.69 | import collections as c
a=c.Counter(list(map(int,open(0).read().split()[1:])))
print((sum([[v-k,v][k>v] for k,v in list(a.items())]))) | from collections import*;n,*a=list(map(int,open(0).read().split()));print((sum(v-k*(v>=k)for k,v in list(Counter(a).items())))) | 3 | 1 | 128 | 113 | import collections as c
a = c.Counter(list(map(int, open(0).read().split()[1:])))
print((sum([[v - k, v][k > v] for k, v in list(a.items())])))
| from collections import *
n, *a = list(map(int, open(0).read().split()))
print((sum(v - k * (v >= k) for k, v in list(Counter(a).items()))))
| false | 66.666667 | [
"-import collections as c",
"+from collections import *",
"-a = c.Counter(list(map(int, open(0).read().split()[1:])))",
"-print((sum([[v - k, v][k > v] for k, v in list(a.items())])))",
"+n, *a = list(map(int, open(0).read().split()))",
"+print((sum(v - k * (v >= k) for k, v in list(Counter(a).items()))))"
] | false | 0.136737 | 0.037661 | 3.630747 | [
"s511446182",
"s848869648"
] |
u623819879 | p03048 | python | s000562784 | s397189373 | 282 | 236 | 40,812 | 40,684 | Accepted | Accepted | 16.31 | ans=0
r,g,b,n=list(map(int,input().split()))
for i in range(n//r+2):
for j in range(n//g+2):
k=n-i*r-j*g
if k>=0 and k%b==0:
ans+=1
print(ans) | # coding: utf-8
#-------------------------------------------------------------------
import sys
def p(*a):
s=" ".join(map(str,a))
#print(s)
sys.stderr.write(s+"\n")
#-------------------------------------------------------------------
R,G,B,N = list(map(int, input().split()))
if R<G: R,G=G,R
if G<B: G,B=B,G
if R<G: R,G=G,R
r=g=b=0
ans=0
#p(N//R+2)
#p(N//G+2)
#X=[]
#p(r,g,b)
for r in range(N//R+2):
if (R*r)>N: break
for g in range(N//G+2):
if (R*r)+(G*g)>N:
break
X.append("break")
b = (N-(R*r)-(G*g))//B
n = (R*r)+(G*g)+(B*b)
if n==N:
ans+=1
# X.append([r,g,b])
# p(r,g,b,n,N,ans)
print(ans)
#p(X)
| 9 | 40 | 177 | 672 | ans = 0
r, g, b, n = list(map(int, input().split()))
for i in range(n // r + 2):
for j in range(n // g + 2):
k = n - i * r - j * g
if k >= 0 and k % b == 0:
ans += 1
print(ans)
| # coding: utf-8
# -------------------------------------------------------------------
import sys
def p(*a):
s = " ".join(map(str, a))
# print(s)
sys.stderr.write(s + "\n")
# -------------------------------------------------------------------
R, G, B, N = list(map(int, input().split()))
if R < G:
R, G = G, R
if G < B:
G, B = B, G
if R < G:
R, G = G, R
r = g = b = 0
ans = 0
# p(N//R+2)
# p(N//G+2)
# X=[]
# p(r,g,b)
for r in range(N // R + 2):
if (R * r) > N:
break
for g in range(N // G + 2):
if (R * r) + (G * g) > N:
break
X.append("break")
b = (N - (R * r) - (G * g)) // B
n = (R * r) + (G * g) + (B * b)
if n == N:
ans += 1
# X.append([r,g,b])
# p(r,g,b,n,N,ans)
print(ans)
# p(X)
| false | 77.5 | [
"+# coding: utf-8",
"+import sys",
"+",
"+",
"+def p(*a):",
"+ s = \" \".join(map(str, a))",
"+ # print(s)",
"+ sys.stderr.write(s + \"\\n\")",
"+",
"+",
"+R, G, B, N = list(map(int, input().split()))",
"+if R < G:",
"+ R, G = G, R",
"+if G < B:",
"+ G, B = B, G",
"+if R < G:",
"+ R, G = G, R",
"+r = g = b = 0",
"-r, g, b, n = list(map(int, input().split()))",
"-for i in range(n // r + 2):",
"- for j in range(n // g + 2):",
"- k = n - i * r - j * g",
"- if k >= 0 and k % b == 0:",
"+# p(N//R+2)",
"+# p(N//G+2)",
"+# X=[]",
"+# p(r,g,b)",
"+for r in range(N // R + 2):",
"+ if (R * r) > N:",
"+ break",
"+ for g in range(N // G + 2):",
"+ if (R * r) + (G * g) > N:",
"+ break",
"+ X.append(\"break\")",
"+ b = (N - (R * r) - (G * g)) // B",
"+ n = (R * r) + (G * g) + (B * b)",
"+ if n == N:",
"+# \t\t\tX.append([r,g,b])",
"+# \t\tp(r,g,b,n,N,ans)",
"+# p(X)"
] | false | 0.111715 | 0.058043 | 1.924672 | [
"s000562784",
"s397189373"
] |
u379959788 | p03212 | python | s229820265 | s172365343 | 77 | 39 | 3,064 | 3,060 | Accepted | Accepted | 49.35 | # ABC114
N = int(eval(input()))
def dfs(num):
if num > N:
return 0
flag = True
for s in "357":
if str(num).count(s) >= 1:
pass
else:
flag = False
ret = 1 if flag else 0
for c in [3, 5, 7]:
ret += dfs(num * 10 + c)
return ret
ans = dfs(0)
print(ans) | # ABC114
N = int(eval(input()))
def dfs(num, use):
if num > N:
return 0
cnt = 1 if use == 0b111 else 0
cnt += dfs(num*10 + 3, use | 0b001)
cnt += dfs(num*10 + 5, use | 0b010)
cnt += dfs(num*10 + 7, use | 0b100)
return cnt
ans = dfs(0, 0)
print(ans) | 19 | 13 | 342 | 287 | # ABC114
N = int(eval(input()))
def dfs(num):
if num > N:
return 0
flag = True
for s in "357":
if str(num).count(s) >= 1:
pass
else:
flag = False
ret = 1 if flag else 0
for c in [3, 5, 7]:
ret += dfs(num * 10 + c)
return ret
ans = dfs(0)
print(ans)
| # ABC114
N = int(eval(input()))
def dfs(num, use):
if num > N:
return 0
cnt = 1 if use == 0b111 else 0
cnt += dfs(num * 10 + 3, use | 0b001)
cnt += dfs(num * 10 + 5, use | 0b010)
cnt += dfs(num * 10 + 7, use | 0b100)
return cnt
ans = dfs(0, 0)
print(ans)
| false | 31.578947 | [
"-def dfs(num):",
"+def dfs(num, use):",
"- flag = True",
"- for s in \"357\":",
"- if str(num).count(s) >= 1:",
"- pass",
"- else:",
"- flag = False",
"- ret = 1 if flag else 0",
"- for c in [3, 5, 7]:",
"- ret += dfs(num * 10 + c)",
"- return ret",
"+ cnt = 1 if use == 0b111 else 0",
"+ cnt += dfs(num * 10 + 3, use | 0b001)",
"+ cnt += dfs(num * 10 + 5, use | 0b010)",
"+ cnt += dfs(num * 10 + 7, use | 0b100)",
"+ return cnt",
"-ans = dfs(0)",
"+ans = dfs(0, 0)"
] | false | 0.107819 | 0.053137 | 2.029063 | [
"s229820265",
"s172365343"
] |
u298297089 | p03416 | python | s590868982 | s892916862 | 134 | 94 | 3,060 | 3,060 | Accepted | Accepted | 29.85 | a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
x = str(i)
flag = 1
for j in range(len(x) // 2):
if x[j] != x[-(j+1)]:
flag = 0
ans += flag
print(ans) | def is_palindrome(s):
for i in range(len(s) // 2 + 1):
if s[i] != s[-i-1]:
return False
return True
a,b = list(map(int, input().split()))
ans = 0
for i in range(a,b+1):
if is_palindrome(str(i)):
ans += 1
print(ans) | 10 | 14 | 191 | 257 | a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
x = str(i)
flag = 1
for j in range(len(x) // 2):
if x[j] != x[-(j + 1)]:
flag = 0
ans += flag
print(ans)
| def is_palindrome(s):
for i in range(len(s) // 2 + 1):
if s[i] != s[-i - 1]:
return False
return True
a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
if is_palindrome(str(i)):
ans += 1
print(ans)
| false | 28.571429 | [
"+def is_palindrome(s):",
"+ for i in range(len(s) // 2 + 1):",
"+ if s[i] != s[-i - 1]:",
"+ return False",
"+ return True",
"+",
"+",
"- x = str(i)",
"- flag = 1",
"- for j in range(len(x) // 2):",
"- if x[j] != x[-(j + 1)]:",
"- flag = 0",
"- ans += flag",
"+ if is_palindrome(str(i)):",
"+ ans += 1"
] | false | 0.059701 | 0.096516 | 0.618557 | [
"s590868982",
"s892916862"
] |
u353797797 | p02616 | python | s299579566 | s668288933 | 286 | 178 | 31,776 | 31,468 | Accepted | Accepted | 37.76 | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def cal(xx):
res=1
for x in xx:
res=res*x%md
return res
md=10**9+7
n,k=MI()
aa=LI()
if n==k:
print(cal(aa))
exit()
aa.sort(key=lambda x:-abs(x))
#print(aa)
pre=aa[:k]
pos=aa[k:]
mnp=mnn=md
mnpi=mnni=-1
neg=0
for i,a in enumerate(pre):
if a==0:
print(0)
exit()
if a<0:neg+=1
if a>0 and a<mnp:
mnp=a
mnpi=i
if a<0 and -a<mnn:
mnn=-a
mnni=i
if neg%2:
mxp=mxn=0
for a in pos:
if a > 0 and a > mxp:
mxp = a
if a < 0 and -a > mxn:
mxn = -a
if (mnni!=-1 and mxp) or (mnpi!=-1 and mxn):
if mnpi==-1 or mxp*mnp>mxn*mnn:pre[mnni]=mxp
else:pre[mnpi]=-mxn
else:
pre=aa[-k:]
print(cal(pre))
| import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
pos = []
neg = []
for a in aa:
if a < 0: neg.append(a)
else: pos.append(a)
pn = len(pos)
nn = len(neg)
if min(k,nn) // 2 * 2 + pn < k:
aa.sort(key=lambda x: abs(x))
print(cal(aa[:k]))
else:
pos.sort()
neg.sort(reverse=True)
ans = pos.pop() if k & 1 else 1
mul = []
while len(pos) > 1: mul.append(pos.pop() * pos.pop())
while len(neg) > 1: mul.append(neg.pop() * neg.pop())
mul.sort(reverse=True)
print(ans * cal(mul[:k // 2]) % md)
def cal(xx):
res=1
for x in xx:
res=res*x%md
return res
md=10**9+7
n,k=MI()
aa=LI()
main()
| 55 | 42 | 1,182 | 1,097 | import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def cal(xx):
res = 1
for x in xx:
res = res * x % md
return res
md = 10**9 + 7
n, k = MI()
aa = LI()
if n == k:
print(cal(aa))
exit()
aa.sort(key=lambda x: -abs(x))
# print(aa)
pre = aa[:k]
pos = aa[k:]
mnp = mnn = md
mnpi = mnni = -1
neg = 0
for i, a in enumerate(pre):
if a == 0:
print(0)
exit()
if a < 0:
neg += 1
if a > 0 and a < mnp:
mnp = a
mnpi = i
if a < 0 and -a < mnn:
mnn = -a
mnni = i
if neg % 2:
mxp = mxn = 0
for a in pos:
if a > 0 and a > mxp:
mxp = a
if a < 0 and -a > mxn:
mxn = -a
if (mnni != -1 and mxp) or (mnpi != -1 and mxn):
if mnpi == -1 or mxp * mnp > mxn * mnn:
pre[mnni] = mxp
else:
pre[mnpi] = -mxn
else:
pre = aa[-k:]
print(cal(pre))
| import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
pos = []
neg = []
for a in aa:
if a < 0:
neg.append(a)
else:
pos.append(a)
pn = len(pos)
nn = len(neg)
if min(k, nn) // 2 * 2 + pn < k:
aa.sort(key=lambda x: abs(x))
print(cal(aa[:k]))
else:
pos.sort()
neg.sort(reverse=True)
ans = pos.pop() if k & 1 else 1
mul = []
while len(pos) > 1:
mul.append(pos.pop() * pos.pop())
while len(neg) > 1:
mul.append(neg.pop() * neg.pop())
mul.sort(reverse=True)
print(ans * cal(mul[: k // 2]) % md)
def cal(xx):
res = 1
for x in xx:
res = res * x % md
return res
md = 10**9 + 7
n, k = MI()
aa = LI()
main()
| false | 23.636364 | [
"+def main():",
"+ pos = []",
"+ neg = []",
"+ for a in aa:",
"+ if a < 0:",
"+ neg.append(a)",
"+ else:",
"+ pos.append(a)",
"+ pn = len(pos)",
"+ nn = len(neg)",
"+ if min(k, nn) // 2 * 2 + pn < k:",
"+ aa.sort(key=lambda x: abs(x))",
"+ print(cal(aa[:k]))",
"+ else:",
"+ pos.sort()",
"+ neg.sort(reverse=True)",
"+ ans = pos.pop() if k & 1 else 1",
"+ mul = []",
"+ while len(pos) > 1:",
"+ mul.append(pos.pop() * pos.pop())",
"+ while len(neg) > 1:",
"+ mul.append(neg.pop() * neg.pop())",
"+ mul.sort(reverse=True)",
"+ print(ans * cal(mul[: k // 2]) % md)",
"+",
"+",
"-if n == k:",
"- print(cal(aa))",
"- exit()",
"-aa.sort(key=lambda x: -abs(x))",
"-# print(aa)",
"-pre = aa[:k]",
"-pos = aa[k:]",
"-mnp = mnn = md",
"-mnpi = mnni = -1",
"-neg = 0",
"-for i, a in enumerate(pre):",
"- if a == 0:",
"- print(0)",
"- exit()",
"- if a < 0:",
"- neg += 1",
"- if a > 0 and a < mnp:",
"- mnp = a",
"- mnpi = i",
"- if a < 0 and -a < mnn:",
"- mnn = -a",
"- mnni = i",
"-if neg % 2:",
"- mxp = mxn = 0",
"- for a in pos:",
"- if a > 0 and a > mxp:",
"- mxp = a",
"- if a < 0 and -a > mxn:",
"- mxn = -a",
"- if (mnni != -1 and mxp) or (mnpi != -1 and mxn):",
"- if mnpi == -1 or mxp * mnp > mxn * mnn:",
"- pre[mnni] = mxp",
"- else:",
"- pre[mnpi] = -mxn",
"- else:",
"- pre = aa[-k:]",
"-print(cal(pre))",
"+main()"
] | false | 0.045149 | 0.044162 | 1.022336 | [
"s299579566",
"s668288933"
] |
u716530146 | p02699 | python | s600673971 | s721147043 | 115 | 22 | 65,208 | 9,540 | Accepted | Accepted | 80.87 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
s,w = list(map(int,input().split()))
if s <= w:
print("unsafe")
else:
print("safe") | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
s,w = list(map(int,input().split()))
print(("unsafe" if s <= w else "safe")) | 11 | 8 | 307 | 291 | #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
s, w = list(map(int, input().split()))
if s <= w:
print("unsafe")
else:
print("safe")
| #!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
inf = float("inf")
mod = 10**9 + 7
mans = inf
ans = 0
count = 0
pro = 1
s, w = list(map(int, input().split()))
print(("unsafe" if s <= w else "safe"))
| false | 27.272727 | [
"-if s <= w:",
"- print(\"unsafe\")",
"-else:",
"- print(\"safe\")",
"+print((\"unsafe\" if s <= w else \"safe\"))"
] | false | 0.040441 | 0.037664 | 1.073718 | [
"s600673971",
"s721147043"
] |
u620238824 | p02689 | python | s485886477 | s138896017 | 315 | 246 | 31,940 | 19,960 | Accepted | Accepted | 21.9 | N, M = list(map(int, input().split())) #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)] #数字、複数行複数列
good = [True]*N
for i, j in A:
i -= 1
j -= 1
if H[i] < H[j]:
good[i] = False
if H[i] > H[j]:
good[j] = False
if H[i] == H[j]:
good[i] = False
good[j] = False
print((good.count(True))) | n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
l = [True] * n
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
#print(h[a],h[b])
if h[a] >= h[b]:
l[b] = False
if h[a] <= h[b]:
l[a] = False
#print(l)
print((l.count(True))) | 17 | 16 | 397 | 315 | N, M = list(map(int, input().split())) # 数字
H = list(map(int, input().split())) # リスト
A = [list(map(int, input().split())) for i in range(M)] # 数字、複数行複数列
good = [True] * N
for i, j in A:
i -= 1
j -= 1
if H[i] < H[j]:
good[i] = False
if H[i] > H[j]:
good[j] = False
if H[i] == H[j]:
good[i] = False
good[j] = False
print((good.count(True)))
| n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
l = [True] * n
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
# print(h[a],h[b])
if h[a] >= h[b]:
l[b] = False
if h[a] <= h[b]:
l[a] = False
# print(l)
print((l.count(True)))
| false | 5.882353 | [
"-N, M = list(map(int, input().split())) # 数字",
"-H = list(map(int, input().split())) # リスト",
"-A = [list(map(int, input().split())) for i in range(M)] # 数字、複数行複数列",
"-good = [True] * N",
"-for i, j in A:",
"- i -= 1",
"- j -= 1",
"- if H[i] < H[j]:",
"- good[i] = False",
"- if H[i] > H[j]:",
"- good[j] = False",
"- if H[i] == H[j]:",
"- good[i] = False",
"- good[j] = False",
"-print((good.count(True)))",
"+n, m = list(map(int, input().split()))",
"+h = list(map(int, input().split()))",
"+l = [True] * n",
"+for i in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ a -= 1",
"+ b -= 1",
"+ # print(h[a],h[b])",
"+ if h[a] >= h[b]:",
"+ l[b] = False",
"+ if h[a] <= h[b]:",
"+ l[a] = False",
"+# print(l)",
"+print((l.count(True)))"
] | false | 0.008094 | 0.037584 | 0.215364 | [
"s485886477",
"s138896017"
] |
u385792265 | p03167 | python | s367955262 | s956105168 | 609 | 438 | 13,812 | 11,892 | Accepted | Accepted | 28.08 | h, w = list(map(int, input().split()))
a=[ list(eval(input())) for _ in range(h)]
dp=[1]+[0]*(w-1)
for i in range(h):
dp[0]=int(dp[0]==1 and a[i][0]=='.')
for j in range(1,w): dp[j]=(int(a[i][j]=='.')*(dp[j]+dp[j-1]) % 1000000007 )
print((dp[-1])) | h, w = list(map(int, input().split()))
a=[ list(eval(input())) for _ in range(h)]
dp=[1]+[0]*(w-1)
for i in range(h):
dp[0]=int(dp[0]==1 and a[i][0]=='.')
for j in range(1,w): dp[j]=( (dp[j]+dp[j-1]) % 1000000007) if a[i][j]=='.' else 0
print((dp[-1])) | 7 | 7 | 247 | 252 | h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
dp = [1] + [0] * (w - 1)
for i in range(h):
dp[0] = int(dp[0] == 1 and a[i][0] == ".")
for j in range(1, w):
dp[j] = int(a[i][j] == ".") * (dp[j] + dp[j - 1]) % 1000000007
print((dp[-1]))
| h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
dp = [1] + [0] * (w - 1)
for i in range(h):
dp[0] = int(dp[0] == 1 and a[i][0] == ".")
for j in range(1, w):
dp[j] = ((dp[j] + dp[j - 1]) % 1000000007) if a[i][j] == "." else 0
print((dp[-1]))
| false | 0 | [
"- dp[j] = int(a[i][j] == \".\") * (dp[j] + dp[j - 1]) % 1000000007",
"+ dp[j] = ((dp[j] + dp[j - 1]) % 1000000007) if a[i][j] == \".\" else 0"
] | false | 0.037545 | 0.042956 | 0.874035 | [
"s367955262",
"s956105168"
] |
u630511239 | p03659 | python | s627507219 | s962908668 | 169 | 147 | 24,812 | 30,592 | Accepted | Accepted | 13.02 | N = int(eval(input()))
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x==y:
ans = 0
else:
ans = abs(x-y)
for i in range(1,N-1):
x += a[i]
y -= a[i]
if x==y:
ans = 0
break
elif abs(x-y)<ans:
ans = abs(x-y)
print(ans) | N = int(eval(input()))
A = list(map(int, input().split()))
x = A[0]
y = sum(A[1:])
ans = abs(x - y)
for i in range(1, N - 1):
a = A[i]
x += a
y -= a
dif = abs(x - y)
if dif < ans:
ans = dif
print(ans) | 20 | 13 | 287 | 234 | N = int(eval(input()))
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x == y:
ans = 0
else:
ans = abs(x - y)
for i in range(1, N - 1):
x += a[i]
y -= a[i]
if x == y:
ans = 0
break
elif abs(x - y) < ans:
ans = abs(x - y)
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
x = A[0]
y = sum(A[1:])
ans = abs(x - y)
for i in range(1, N - 1):
a = A[i]
x += a
y -= a
dif = abs(x - y)
if dif < ans:
ans = dif
print(ans)
| false | 35 | [
"-a = list(map(int, input().split()))",
"-s = a[:1]",
"-t = a[1:]",
"-x = sum(s)",
"-y = sum(t)",
"-if x == y:",
"- ans = 0",
"-else:",
"- ans = abs(x - y)",
"+A = list(map(int, input().split()))",
"+x = A[0]",
"+y = sum(A[1:])",
"+ans = abs(x - y)",
"- x += a[i]",
"- y -= a[i]",
"- if x == y:",
"- ans = 0",
"- break",
"- elif abs(x - y) < ans:",
"- ans = abs(x - y)",
"+ a = A[i]",
"+ x += a",
"+ y -= a",
"+ dif = abs(x - y)",
"+ if dif < ans:",
"+ ans = dif"
] | false | 0.096888 | 0.098523 | 0.983407 | [
"s627507219",
"s962908668"
] |
u316464887 | p03161 | python | s858705449 | s058590195 | 1,877 | 1,642 | 13,976 | 13,976 | Accepted | Accepted | 12.52 | def main():
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i in range(1, n):
s = max(0, i-k)
m[i] = min([ml + abs(hl - h[i]) for ml, hl in zip(m[s:i], h[s:i])])
print((m[-1]))
main()
| def main():
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i, hi in enumerate(h):
if i == 0:
continue
s = max(0, i-k)
m[i] = min([ml + abs(hl - hi) for ml, hl in zip(m[s:i], h[s:i])])
print((m[-1]))
main()
| 11 | 13 | 279 | 324 | def main():
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i in range(1, n):
s = max(0, i - k)
m[i] = min([ml + abs(hl - h[i]) for ml, hl in zip(m[s:i], h[s:i])])
print((m[-1]))
main()
| def main():
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
m = [0] * n
m[0] = 0
for i, hi in enumerate(h):
if i == 0:
continue
s = max(0, i - k)
m[i] = min([ml + abs(hl - hi) for ml, hl in zip(m[s:i], h[s:i])])
print((m[-1]))
main()
| false | 15.384615 | [
"- for i in range(1, n):",
"+ for i, hi in enumerate(h):",
"+ if i == 0:",
"+ continue",
"- m[i] = min([ml + abs(hl - h[i]) for ml, hl in zip(m[s:i], h[s:i])])",
"+ m[i] = min([ml + abs(hl - hi) for ml, hl in zip(m[s:i], h[s:i])])"
] | false | 0.038011 | 0.09946 | 0.382179 | [
"s858705449",
"s058590195"
] |
u623687794 | p02901 | python | s473549893 | s765917810 | 315 | 119 | 46,552 | 76,592 | Accepted | Accepted | 62.22 | n,m=list(map(int,input().split()))
keys=[None]*m
dp=[-1]*(2**n)
dp[0]=0
for i in range(m):
a,b=list(map(int,input().split()))
c=list(map(int,input().split()))
cond=0
for j in c:
cond+=2**(j-1)
keys[i]=[a,cond]
for key in keys:
for sta in range(2**n):
if dp[sta]==-1:continue
if dp[sta|key[1]]==-1:
dp[sta|key[1]]=key[0]+dp[sta]
else:
dp[sta|key[1]]=min(dp[sta|key[1]],dp[sta]+key[0])
print((dp[-1]))
| n,m=list(map(int,input().split()))
keys=[None]*m
INF = 10**10
dp=[INF]*(2**n)
dp[0]=0
for i in range(m):
a,b=list(map(int,input().split()))
c=list(map(int,input().split()))
cond=0
for j in c:
cond+=2**(j-1)
keys[i]=[a,cond]
for key in keys:
for sta in range(2**n):
dp[sta|key[1]]=min(dp[sta|key[1]],dp[sta]+key[0])
print((dp[-1] if dp[-1] != INF else -1))
| 19 | 16 | 444 | 381 | n, m = list(map(int, input().split()))
keys = [None] * m
dp = [-1] * (2**n)
dp[0] = 0
for i in range(m):
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
cond = 0
for j in c:
cond += 2 ** (j - 1)
keys[i] = [a, cond]
for key in keys:
for sta in range(2**n):
if dp[sta] == -1:
continue
if dp[sta | key[1]] == -1:
dp[sta | key[1]] = key[0] + dp[sta]
else:
dp[sta | key[1]] = min(dp[sta | key[1]], dp[sta] + key[0])
print((dp[-1]))
| n, m = list(map(int, input().split()))
keys = [None] * m
INF = 10**10
dp = [INF] * (2**n)
dp[0] = 0
for i in range(m):
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
cond = 0
for j in c:
cond += 2 ** (j - 1)
keys[i] = [a, cond]
for key in keys:
for sta in range(2**n):
dp[sta | key[1]] = min(dp[sta | key[1]], dp[sta] + key[0])
print((dp[-1] if dp[-1] != INF else -1))
| false | 15.789474 | [
"-dp = [-1] * (2**n)",
"+INF = 10**10",
"+dp = [INF] * (2**n)",
"- if dp[sta] == -1:",
"- continue",
"- if dp[sta | key[1]] == -1:",
"- dp[sta | key[1]] = key[0] + dp[sta]",
"- else:",
"- dp[sta | key[1]] = min(dp[sta | key[1]], dp[sta] + key[0])",
"-print((dp[-1]))",
"+ dp[sta | key[1]] = min(dp[sta | key[1]], dp[sta] + key[0])",
"+print((dp[-1] if dp[-1] != INF else -1))"
] | false | 0.035843 | 0.035928 | 0.997628 | [
"s473549893",
"s765917810"
] |
u740284863 | p02580 | python | s226876116 | s791015197 | 1,031 | 807 | 121,940 | 122,176 | Accepted | Accepted | 21.73 | import collections
h,w,m = list(map(int,input().split()))
X = []
Y = []
for _ in range(m):
x,y = list(map(int,input().split()))
X.append(x)
Y.append(y)
most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]
otherwisey = []
otherwisex = []
for i in range(m):
if X[i] != most_common_x_index:
otherwisey.append(Y[i])
if Y[i] != most_common_y_index:
otherwisex.append(X[i])
most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y)!= 0:
ansx = most_common_y[0][1] + most_common_x_count
else:
ansx = most_common_x_count
most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x)!= 0:
ansy = most_common_x[0][1] + most_common_y_count
else:
ansy = most_common_y_count
print((max(ansx,ansy))) | import collections
import sys
def input() : return sys.stdin.readline().strip()
h,w,m = list(map(int,input().split()))
X = []
Y = []
for _ in range(m):
x,y = list(map(int,input().split()))
X.append(x)
Y.append(y)
most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]
otherwisey = []
otherwisex = []
for i in range(m):
if X[i] != most_common_x_index:
otherwisey.append(Y[i])
if Y[i] != most_common_y_index:
otherwisex.append(X[i])
most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y)!= 0:
ansx = most_common_y[0][1] + most_common_x_count
else:
ansx = most_common_x_count
most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x)!= 0:
ansy = most_common_x[0][1] + most_common_y_count
else:
ansy = most_common_y_count
print((max(ansx,ansy))) | 38 | 39 | 1,035 | 1,096 | import collections
h, w, m = list(map(int, input().split()))
X = []
Y = []
for _ in range(m):
x, y = list(map(int, input().split()))
X.append(x)
Y.append(y)
most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]
otherwisey = []
otherwisex = []
for i in range(m):
if X[i] != most_common_x_index:
otherwisey.append(Y[i])
if Y[i] != most_common_y_index:
otherwisex.append(X[i])
most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y) != 0:
ansx = most_common_y[0][1] + most_common_x_count
else:
ansx = most_common_x_count
most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x) != 0:
ansy = most_common_x[0][1] + most_common_y_count
else:
ansy = most_common_y_count
print((max(ansx, ansy)))
| import collections
import sys
def input():
return sys.stdin.readline().strip()
h, w, m = list(map(int, input().split()))
X = []
Y = []
for _ in range(m):
x, y = list(map(int, input().split()))
X.append(x)
Y.append(y)
most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]
otherwisey = []
otherwisex = []
for i in range(m):
if X[i] != most_common_x_index:
otherwisey.append(Y[i])
if Y[i] != most_common_y_index:
otherwisex.append(X[i])
most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y) != 0:
ansx = most_common_y[0][1] + most_common_x_count
else:
ansx = most_common_x_count
most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x) != 0:
ansy = most_common_x[0][1] + most_common_y_count
else:
ansy = most_common_y_count
print((max(ansx, ansy)))
| false | 2.564103 | [
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+"
] | false | 0.042927 | 0.037843 | 1.134339 | [
"s226876116",
"s791015197"
] |
u238956837 | p02783 | python | s523289321 | s146995697 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | h, a = list(map(int, input().split()))
ans = 0
while h > 0:
h -= a
ans += 1
print(ans) | import math
h, a = list(map(int, input().split()))
ans = 0
print((math.ceil(h/a))) | 8 | 5 | 93 | 79 | h, a = list(map(int, input().split()))
ans = 0
while h > 0:
h -= a
ans += 1
print(ans)
| import math
h, a = list(map(int, input().split()))
ans = 0
print((math.ceil(h / a)))
| false | 37.5 | [
"+import math",
"+",
"-while h > 0:",
"- h -= a",
"- ans += 1",
"-print(ans)",
"+print((math.ceil(h / a)))"
] | false | 0.048768 | 0.047217 | 1.032865 | [
"s523289321",
"s146995697"
] |
u352394527 | p00731 | python | s460159606 | s259483541 | 1,140 | 900 | 6,208 | 6,216 | Accepted | Accepted | 21.05 | from heapq import heappush, heappop
R_next = tuple((x, y) for x in range(-3, 0) for y in range(-2, 3) if abs(x) + abs(y) <= 3)
L_next = tuple((x, y) for x in range(1, 4) for y in range(-2, 3) if abs(x) + abs(y) <= 3)
c_num = tuple(str(i) for i in range(10))
L, R = 0, 1
INF = 10 ** 20
def conv(c):
if c in c_num:
return int(c)
if c in ("T", "S"):
return 0
return -1
while True:
w, h = list(map(int, input().split()))
if w == 0:
break
mp = [[-1] * 3 + input().split() + [-1] * 3 for _ in range(h)]
for i in range(h):
mp[i] = list(map(conv, mp[i]))
mp.insert(0, [-1] * (w + 6))
mp.insert(0, [-1] * (w + 6))
mp.append([-1] * (w + 6))
mp.append([-1] * (w + 6))
start = []
goal = []
for x in range(3, w + 3):
if mp[h + 1][x] == 0:
start.append((x, h + 1))
if mp[2][x] == 0:
goal.append((x, 2))
que = []
dic = {}
for x, y, in start:
heappush(que, (0, x, y, L))
heappush(que, (0, x, y, R))
dic[(x, y, L)] = 0
dic[(x, y, R)] = 0
while que:
total, x, y, foot = heappop(que)
if foot == R:
direct = R_next
next_foot = L
else:
direct = L_next
next_foot = R
for dx, dy in direct:
nx, ny = x + dx, y + dy
cost = mp[ny][nx]
if cost == -1:
continue
if not (nx, ny, next_foot) in dic or dic[(nx, ny, next_foot)] > total + cost:
dic[(nx, ny, next_foot)] = total + cost
heappush(que, (total + cost, nx, ny, next_foot))
ans = INF
for x, y in goal:
if (x, y, L) in dic: ans = min(ans, dic[(x, y, L)])
if (x, y, R) in dic: ans = min(ans, dic[(x, y, R)])
if ans == INF:
print((-1))
else:
print(ans)
| from heapq import heappush, heappop
R_next = tuple((x, y) for x in range(-3, 0) for y in range(-2, 3) if abs(x) + abs(y) <= 3)
L_next = tuple((x, y) for x in range(1, 4) for y in range(-2, 3) if abs(x) + abs(y) <= 3)
c_num = tuple(str(i) for i in range(10))
L, R = 0, 1
INF = 10 ** 20
def conv(c):
if c in c_num:
return int(c)
if c in ("T", "S"):
return 0
return -1
while True:
w, h = list(map(int, input().split()))
if w == 0:
break
mp = [[-1] * 3 + input().split() + [-1] * 3 for _ in range(h)]
for i in range(h):
mp[i] = list(map(conv, mp[i]))
mp.insert(0, [-1] * (w + 6))
mp.insert(0, [-1] * (w + 6))
mp.append([-1] * (w + 6))
mp.append([-1] * (w + 6))
def search():
start = []
goal = []
for x in range(3, w + 3):
if mp[h + 1][x] == 0:
start.append((x, h + 1))
if mp[2][x] == 0:
goal.append((x, 2))
que = []
dic = {}
for x, y, in start:
heappush(que, (0, x, y, L))
heappush(que, (0, x, y, R))
dic[(x, y, L)] = 0
dic[(x, y, R)] = 0
while que:
total, x, y, foot = heappop(que)
if foot == R:
direct = R_next
next_foot = L
else:
direct = L_next
next_foot = R
for dx, dy in direct:
nx, ny = x + dx, y + dy
if (nx, ny) in goal:
return total
cost = mp[ny][nx]
if cost == -1:
continue
if not (nx, ny, next_foot) in dic or dic[(nx, ny, next_foot)] > total + cost:
dic[(nx, ny, next_foot)] = total + cost
heappush(que, (total + cost, nx, ny, next_foot))
else:
return -1
print((search()))
| 68 | 66 | 1,744 | 1,716 | from heapq import heappush, heappop
R_next = tuple(
(x, y) for x in range(-3, 0) for y in range(-2, 3) if abs(x) + abs(y) <= 3
)
L_next = tuple(
(x, y) for x in range(1, 4) for y in range(-2, 3) if abs(x) + abs(y) <= 3
)
c_num = tuple(str(i) for i in range(10))
L, R = 0, 1
INF = 10**20
def conv(c):
if c in c_num:
return int(c)
if c in ("T", "S"):
return 0
return -1
while True:
w, h = list(map(int, input().split()))
if w == 0:
break
mp = [[-1] * 3 + input().split() + [-1] * 3 for _ in range(h)]
for i in range(h):
mp[i] = list(map(conv, mp[i]))
mp.insert(0, [-1] * (w + 6))
mp.insert(0, [-1] * (w + 6))
mp.append([-1] * (w + 6))
mp.append([-1] * (w + 6))
start = []
goal = []
for x in range(3, w + 3):
if mp[h + 1][x] == 0:
start.append((x, h + 1))
if mp[2][x] == 0:
goal.append((x, 2))
que = []
dic = {}
for (
x,
y,
) in start:
heappush(que, (0, x, y, L))
heappush(que, (0, x, y, R))
dic[(x, y, L)] = 0
dic[(x, y, R)] = 0
while que:
total, x, y, foot = heappop(que)
if foot == R:
direct = R_next
next_foot = L
else:
direct = L_next
next_foot = R
for dx, dy in direct:
nx, ny = x + dx, y + dy
cost = mp[ny][nx]
if cost == -1:
continue
if (
not (nx, ny, next_foot) in dic
or dic[(nx, ny, next_foot)] > total + cost
):
dic[(nx, ny, next_foot)] = total + cost
heappush(que, (total + cost, nx, ny, next_foot))
ans = INF
for x, y in goal:
if (x, y, L) in dic:
ans = min(ans, dic[(x, y, L)])
if (x, y, R) in dic:
ans = min(ans, dic[(x, y, R)])
if ans == INF:
print((-1))
else:
print(ans)
| from heapq import heappush, heappop
R_next = tuple(
(x, y) for x in range(-3, 0) for y in range(-2, 3) if abs(x) + abs(y) <= 3
)
L_next = tuple(
(x, y) for x in range(1, 4) for y in range(-2, 3) if abs(x) + abs(y) <= 3
)
c_num = tuple(str(i) for i in range(10))
L, R = 0, 1
INF = 10**20
def conv(c):
if c in c_num:
return int(c)
if c in ("T", "S"):
return 0
return -1
while True:
w, h = list(map(int, input().split()))
if w == 0:
break
mp = [[-1] * 3 + input().split() + [-1] * 3 for _ in range(h)]
for i in range(h):
mp[i] = list(map(conv, mp[i]))
mp.insert(0, [-1] * (w + 6))
mp.insert(0, [-1] * (w + 6))
mp.append([-1] * (w + 6))
mp.append([-1] * (w + 6))
def search():
start = []
goal = []
for x in range(3, w + 3):
if mp[h + 1][x] == 0:
start.append((x, h + 1))
if mp[2][x] == 0:
goal.append((x, 2))
que = []
dic = {}
for (
x,
y,
) in start:
heappush(que, (0, x, y, L))
heappush(que, (0, x, y, R))
dic[(x, y, L)] = 0
dic[(x, y, R)] = 0
while que:
total, x, y, foot = heappop(que)
if foot == R:
direct = R_next
next_foot = L
else:
direct = L_next
next_foot = R
for dx, dy in direct:
nx, ny = x + dx, y + dy
if (nx, ny) in goal:
return total
cost = mp[ny][nx]
if cost == -1:
continue
if (
not (nx, ny, next_foot) in dic
or dic[(nx, ny, next_foot)] > total + cost
):
dic[(nx, ny, next_foot)] = total + cost
heappush(que, (total + cost, nx, ny, next_foot))
else:
return -1
print((search()))
| false | 2.941176 | [
"- start = []",
"- goal = []",
"- for x in range(3, w + 3):",
"- if mp[h + 1][x] == 0:",
"- start.append((x, h + 1))",
"- if mp[2][x] == 0:",
"- goal.append((x, 2))",
"- que = []",
"- dic = {}",
"- for (",
"- x,",
"- y,",
"- ) in start:",
"- heappush(que, (0, x, y, L))",
"- heappush(que, (0, x, y, R))",
"- dic[(x, y, L)] = 0",
"- dic[(x, y, R)] = 0",
"- while que:",
"- total, x, y, foot = heappop(que)",
"- if foot == R:",
"- direct = R_next",
"- next_foot = L",
"+",
"+ def search():",
"+ start = []",
"+ goal = []",
"+ for x in range(3, w + 3):",
"+ if mp[h + 1][x] == 0:",
"+ start.append((x, h + 1))",
"+ if mp[2][x] == 0:",
"+ goal.append((x, 2))",
"+ que = []",
"+ dic = {}",
"+ for (",
"+ x,",
"+ y,",
"+ ) in start:",
"+ heappush(que, (0, x, y, L))",
"+ heappush(que, (0, x, y, R))",
"+ dic[(x, y, L)] = 0",
"+ dic[(x, y, R)] = 0",
"+ while que:",
"+ total, x, y, foot = heappop(que)",
"+ if foot == R:",
"+ direct = R_next",
"+ next_foot = L",
"+ else:",
"+ direct = L_next",
"+ next_foot = R",
"+ for dx, dy in direct:",
"+ nx, ny = x + dx, y + dy",
"+ if (nx, ny) in goal:",
"+ return total",
"+ cost = mp[ny][nx]",
"+ if cost == -1:",
"+ continue",
"+ if (",
"+ not (nx, ny, next_foot) in dic",
"+ or dic[(nx, ny, next_foot)] > total + cost",
"+ ):",
"+ dic[(nx, ny, next_foot)] = total + cost",
"+ heappush(que, (total + cost, nx, ny, next_foot))",
"- direct = L_next",
"- next_foot = R",
"- for dx, dy in direct:",
"- nx, ny = x + dx, y + dy",
"- cost = mp[ny][nx]",
"- if cost == -1:",
"- continue",
"- if (",
"- not (nx, ny, next_foot) in dic",
"- or dic[(nx, ny, next_foot)] > total + cost",
"- ):",
"- dic[(nx, ny, next_foot)] = total + cost",
"- heappush(que, (total + cost, nx, ny, next_foot))",
"- ans = INF",
"- for x, y in goal:",
"- if (x, y, L) in dic:",
"- ans = min(ans, dic[(x, y, L)])",
"- if (x, y, R) in dic:",
"- ans = min(ans, dic[(x, y, R)])",
"- if ans == INF:",
"- print((-1))",
"- else:",
"- print(ans)",
"+ return -1",
"+",
"+ print((search()))"
] | false | 0.089362 | 0.111819 | 0.799166 | [
"s460159606",
"s259483541"
] |
u953486781 | p03455 | python | s807534056 | s780978205 | 26 | 17 | 3,316 | 2,940 | Accepted | Accepted | 34.62 | a, b = list(map(int, input().split()))
if a * b % 2 == 0:
print("Even")
else:
print("Odd") | a, b = list(map(int, input().split()))
if (a * b) % 2 == 0:
print('Even')
else:
print('Odd') | 5 | 5 | 96 | 98 | a, b = list(map(int, input().split()))
if a * b % 2 == 0:
print("Even")
else:
print("Odd")
| a, b = list(map(int, input().split()))
if (a * b) % 2 == 0:
print("Even")
else:
print("Odd")
| false | 0 | [
"-if a * b % 2 == 0:",
"+if (a * b) % 2 == 0:"
] | false | 0.035973 | 0.058073 | 0.619445 | [
"s807534056",
"s780978205"
] |
u076503518 | p03127 | python | s558027092 | s162800216 | 100 | 84 | 14,228 | 14,252 | Accepted | Accepted | 16 | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
denominator = 0
numerator = 1
while A[numerator] != 0:
A[denominator] = A[denominator] % A[numerator]
if A[denominator] == 0:
denominator += 1
numerator += 1
if denominator >= N or numerator >= N:
break
else:
denominator, numerator = numerator, denominator
print((min([a for a in A if a > 0]))) | N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
if a % b == 0:
return b
else:
return gcd(b, a%b)
ans = gcd(A[0], A[1])
if N > 2:
for i in range(2, N):
ans = gcd(ans, A[i])
print(ans) | 17 | 15 | 440 | 255 | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
denominator = 0
numerator = 1
while A[numerator] != 0:
A[denominator] = A[denominator] % A[numerator]
if A[denominator] == 0:
denominator += 1
numerator += 1
if denominator >= N or numerator >= N:
break
else:
denominator, numerator = numerator, denominator
print((min([a for a in A if a > 0])))
| N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
if a % b == 0:
return b
else:
return gcd(b, a % b)
ans = gcd(A[0], A[1])
if N > 2:
for i in range(2, N):
ans = gcd(ans, A[i])
print(ans)
| false | 11.764706 | [
"-A.sort(reverse=True)",
"-denominator = 0",
"-numerator = 1",
"-while A[numerator] != 0:",
"- A[denominator] = A[denominator] % A[numerator]",
"- if A[denominator] == 0:",
"- denominator += 1",
"- numerator += 1",
"- if denominator >= N or numerator >= N:",
"- break",
"+",
"+",
"+def gcd(a, b):",
"+ if a % b == 0:",
"+ return b",
"- denominator, numerator = numerator, denominator",
"-print((min([a for a in A if a > 0])))",
"+ return gcd(b, a % b)",
"+",
"+",
"+ans = gcd(A[0], A[1])",
"+if N > 2:",
"+ for i in range(2, N):",
"+ ans = gcd(ans, A[i])",
"+print(ans)"
] | false | 0.040831 | 0.044665 | 0.914166 | [
"s558027092",
"s162800216"
] |
u997641430 | p02725 | python | s354088899 | s911302705 | 291 | 118 | 92,820 | 26,060 | Accepted | Accepted | 59.45 | K, N = list(map(int, input().split()))
*A, = list(map(int, input().split()))
B = [A[i + 1] - A[i] for i in range(N - 1)]
B.append(A[0] + K - A[N - 1])
print((sum(B) - max(B)))
| k, n = list(map(int, input().split()))
*A, = list(map(int, input().split()))
B = []
for i in range(1, n):
B.append(A[i]-A[i-1])
B.append(k-sum(B))
print((k-max(B)))
| 5 | 7 | 166 | 161 | K, N = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
B = [A[i + 1] - A[i] for i in range(N - 1)]
B.append(A[0] + K - A[N - 1])
print((sum(B) - max(B)))
| k, n = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
B = []
for i in range(1, n):
B.append(A[i] - A[i - 1])
B.append(k - sum(B))
print((k - max(B)))
| false | 28.571429 | [
"-K, N = list(map(int, input().split()))",
"+k, n = list(map(int, input().split()))",
"-B = [A[i + 1] - A[i] for i in range(N - 1)]",
"-B.append(A[0] + K - A[N - 1])",
"-print((sum(B) - max(B)))",
"+B = []",
"+for i in range(1, n):",
"+ B.append(A[i] - A[i - 1])",
"+B.append(k - sum(B))",
"+print((k - max(B)))"
] | false | 0.03869 | 0.041989 | 0.921429 | [
"s354088899",
"s911302705"
] |
u234091409 | p03835 | python | s115549879 | s946979947 | 211 | 183 | 40,048 | 39,152 | Accepted | Accepted | 13.27 | def resolve():
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(K + 1):
if S - K <= x + y <= S and max(x, y) <= K:
count += 1
print(count)
if __name__ == "__main__":
resolve() | def resolve():
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(max(0, S - K - x), min(K + 1, S - x + 1)):
count += 1
print(count)
if __name__ == "__main__":
resolve() | 12 | 11 | 276 | 251 | def resolve():
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(K + 1):
if S - K <= x + y <= S and max(x, y) <= K:
count += 1
print(count)
if __name__ == "__main__":
resolve()
| def resolve():
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(max(0, S - K - x), min(K + 1, S - x + 1)):
count += 1
print(count)
if __name__ == "__main__":
resolve()
| false | 8.333333 | [
"- for y in range(K + 1):",
"- if S - K <= x + y <= S and max(x, y) <= K:",
"- count += 1",
"+ for y in range(max(0, S - K - x), min(K + 1, S - x + 1)):",
"+ count += 1"
] | false | 0.036434 | 0.058694 | 0.620749 | [
"s115549879",
"s946979947"
] |
u226108478 | p03486 | python | s733414837 | s745816821 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem B
if __name__ == '__main__':
s = sorted(list(eval(input())))
t = sorted(list(eval(input())), reverse=True)
if s < t:
print('Yes')
else:
print('No')
| # -*- coding: utf-8 -*-
def main():
s = sorted(eval(input()))
t = sorted(eval(input()), reverse=True)
if s < t:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 14 | 15 | 246 | 220 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem B
if __name__ == "__main__":
s = sorted(list(eval(input())))
t = sorted(list(eval(input())), reverse=True)
if s < t:
print("Yes")
else:
print("No")
| # -*- coding: utf-8 -*-
def main():
s = sorted(eval(input()))
t = sorted(eval(input()), reverse=True)
if s < t:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| false | 6.666667 | [
"-# AtCoder Beginner Contest",
"-# Problem B",
"-if __name__ == \"__main__\":",
"- s = sorted(list(eval(input())))",
"- t = sorted(list(eval(input())), reverse=True)",
"+def main():",
"+ s = sorted(eval(input()))",
"+ t = sorted(eval(input()), reverse=True)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.046848 | 0.040879 | 1.146 | [
"s733414837",
"s745816821"
] |
u225388820 | p04030 | python | s089616312 | s247606891 | 178 | 18 | 38,384 | 2,940 | Accepted | Accepted | 89.89 | s=eval(input())
t=""
for i in range(len(s)):
if s[i]=='B':
if t!="":
t=t[:len(t)-1]
else:
t+=s[i]
print(t)
| s=input()
t=[]
for i in s:
if i=="0":
t.append(0)
elif i=="1":
t.append(1)
else:
if len(t)>0:
t.pop(-1)
print(*t,sep="")
| 9 | 11 | 145 | 178 | s = eval(input())
t = ""
for i in range(len(s)):
if s[i] == "B":
if t != "":
t = t[: len(t) - 1]
else:
t += s[i]
print(t)
| s = input()
t = []
for i in s:
if i == "0":
t.append(0)
elif i == "1":
t.append(1)
else:
if len(t) > 0:
t.pop(-1)
print(*t, sep="")
| false | 18.181818 | [
"-s = eval(input())",
"-t = \"\"",
"-for i in range(len(s)):",
"- if s[i] == \"B\":",
"- if t != \"\":",
"- t = t[: len(t) - 1]",
"+s = input()",
"+t = []",
"+for i in s:",
"+ if i == \"0\":",
"+ t.append(0)",
"+ elif i == \"1\":",
"+ t.append(1)",
"- t += s[i]",
"-print(t)",
"+ if len(t) > 0:",
"+ t.pop(-1)",
"+print(*t, sep=\"\")"
] | false | 0.038926 | 0.037394 | 1.040966 | [
"s089616312",
"s247606891"
] |
u021019433 | p02803 | python | s870522931 | s247578605 | 585 | 535 | 3,444 | 3,316 | Accepted | Accepted | 8.55 | from collections import deque
h, w = list(map(int, input().split()))
a = ['#' * (w + 2)] * 2
a[1: 1] = ('#' + eval(input()) + '#' for _ in range(h))
r = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if a[i][j] == '.':
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while(q):
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
for j1 in range(j - d, j + 2, 2):
if b[i1][j1] == '.':
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
| from collections import deque
h, w = list(map(int, input().split()))
a = ['#' * (w + 2)] * 2
a[1: 1] = ['#' + eval(input()) + '#' for _ in range(h)]
r = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if a[i][j] == '.':
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while(q):
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
for j1 in range(j - d, j + 2, 2):
if b[i1][j1] == '.':
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
| 24 | 24 | 647 | 647 | from collections import deque
h, w = list(map(int, input().split()))
a = ["#" * (w + 2)] * 2
a[1:1] = ("#" + eval(input()) + "#" for _ in range(h))
r = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if a[i][j] == ".":
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while q:
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
for j1 in range(j - d, j + 2, 2):
if b[i1][j1] == ".":
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
| from collections import deque
h, w = list(map(int, input().split()))
a = ["#" * (w + 2)] * 2
a[1:1] = ["#" + eval(input()) + "#" for _ in range(h)]
r = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if a[i][j] == ".":
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while q:
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
for j1 in range(j - d, j + 2, 2):
if b[i1][j1] == ".":
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
| false | 0 | [
"-a[1:1] = (\"#\" + eval(input()) + \"#\" for _ in range(h))",
"+a[1:1] = [\"#\" + eval(input()) + \"#\" for _ in range(h)]"
] | false | 0.047594 | 0.04742 | 1.003672 | [
"s870522931",
"s247578605"
] |
u695857481 | p03127 | python | s111580367 | s114995767 | 809 | 71 | 14,252 | 14,252 | Accepted | Accepted | 91.22 | n = int(eval(input()))
mon = list(map(int, input().split()))
g = min(mon)
div = []
for i in range(1, g + 1):
if (g % i == 0):
div.append(i)
div.append(g // i)
if (i * i > g):
break
div.sort(reverse=True)
for d in div:
mod = []
for m in mon:
mod.append(m % d)
if (list(set(mod)) == [0]):
print(d)
break | def gcd(x, y):
while(y):
x, y = y, x % y
return x
n = int(eval(input()))
mon = list(map(int, input().split()))
g = mon[0]
for i in range(1, n):
g = gcd(g, mon[i])
print(g) | 18 | 10 | 346 | 184 | n = int(eval(input()))
mon = list(map(int, input().split()))
g = min(mon)
div = []
for i in range(1, g + 1):
if g % i == 0:
div.append(i)
div.append(g // i)
if i * i > g:
break
div.sort(reverse=True)
for d in div:
mod = []
for m in mon:
mod.append(m % d)
if list(set(mod)) == [0]:
print(d)
break
| def gcd(x, y):
while y:
x, y = y, x % y
return x
n = int(eval(input()))
mon = list(map(int, input().split()))
g = mon[0]
for i in range(1, n):
g = gcd(g, mon[i])
print(g)
| false | 44.444444 | [
"+def gcd(x, y):",
"+ while y:",
"+ x, y = y, x % y",
"+ return x",
"+",
"+",
"-g = min(mon)",
"-div = []",
"-for i in range(1, g + 1):",
"- if g % i == 0:",
"- div.append(i)",
"- div.append(g // i)",
"- if i * i > g:",
"- break",
"-div.sort(reverse=True)",
"-for d in div:",
"- mod = []",
"- for m in mon:",
"- mod.append(m % d)",
"- if list(set(mod)) == [0]:",
"- print(d)",
"- break",
"+g = mon[0]",
"+for i in range(1, n):",
"+ g = gcd(g, mon[i])",
"+print(g)"
] | false | 0.038432 | 0.051958 | 0.739667 | [
"s111580367",
"s114995767"
] |
u076917070 | p02918 | python | s899357089 | s208591284 | 99 | 42 | 14,068 | 3,316 | Accepted | Accepted | 57.58 | import sys
input=sys.stdin.readline
def runLength(s):
a = []
for c in s:
if len(a)==0 or a[-1][0]!=c:
a.append([c,1])
else:
a[-1][1] += 1
return a
def main():
N,K = list(map(int, input().split()))
S = input().strip()
ans = 0
for i,c in enumerate(S):
if c == "L":
if i > 0 and S[i-1] == "L":
ans += 1
if c == "R":
if i < N-1 and S[i+1] == "R":
ans += 1
A = runLength(S)
A.sort(key=lambda x:x[1], reverse=True)
for i in range(K):
if i < len(A):
ans += 2
if ans >= N:
break
if ans >= N:
ans = N-1
print(ans)
if __name__ == '__main__':
main() | import sys
input=sys.stdin.readline
def main():
N,K = list(map(int, input().split()))
S = input().strip()
ans = 0
for i,c in enumerate(S):
if c == "L":
if i > 0 and S[i-1] == "L":
ans += 1
if c == "R":
if i < N-1 and S[i+1] == "R":
ans += 1
ans += K*2
if ans >= N:
ans = N-1
print(ans)
if __name__ == '__main__':
main()
| 36 | 21 | 790 | 448 | import sys
input = sys.stdin.readline
def runLength(s):
a = []
for c in s:
if len(a) == 0 or a[-1][0] != c:
a.append([c, 1])
else:
a[-1][1] += 1
return a
def main():
N, K = list(map(int, input().split()))
S = input().strip()
ans = 0
for i, c in enumerate(S):
if c == "L":
if i > 0 and S[i - 1] == "L":
ans += 1
if c == "R":
if i < N - 1 and S[i + 1] == "R":
ans += 1
A = runLength(S)
A.sort(key=lambda x: x[1], reverse=True)
for i in range(K):
if i < len(A):
ans += 2
if ans >= N:
break
if ans >= N:
ans = N - 1
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
N, K = list(map(int, input().split()))
S = input().strip()
ans = 0
for i, c in enumerate(S):
if c == "L":
if i > 0 and S[i - 1] == "L":
ans += 1
if c == "R":
if i < N - 1 and S[i + 1] == "R":
ans += 1
ans += K * 2
if ans >= N:
ans = N - 1
print(ans)
if __name__ == "__main__":
main()
| false | 41.666667 | [
"-",
"-",
"-def runLength(s):",
"- a = []",
"- for c in s:",
"- if len(a) == 0 or a[-1][0] != c:",
"- a.append([c, 1])",
"- else:",
"- a[-1][1] += 1",
"- return a",
"- A = runLength(S)",
"- A.sort(key=lambda x: x[1], reverse=True)",
"- for i in range(K):",
"- if i < len(A):",
"- ans += 2",
"- if ans >= N:",
"- break",
"+ ans += K * 2"
] | false | 0.047461 | 0.038322 | 1.238497 | [
"s899357089",
"s208591284"
] |
u562935282 | p03111 | python | s999299947 | s896884770 | 813 | 77 | 3,064 | 3,064 | Accepted | Accepted | 90.53 | N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
l = list(sorted(l))
tar = []
for x in C, B, A:
if x in l:
l.remove(x)
else:
tar.append(x)
if not tar:
print((0))
exit()
ans = float('inf')
for j in range((len(tar) + 1) ** len(l)):
vvv = [[] for _ in range(len(tar) + 1)]
for i in sorted(list(range(len(l))), reverse=True):
idx, j = divmod(j, (len(tar) + 1) ** i)
vvv[idx].append(l[i])
if any(len(vvvv) == 0 for vvvv in vvv[:-1]):
continue
else:
bbb = 0
# print(tar, vvv)
for k in range(len(tar)):
bbb += 10 * (len(vvv[k]) - 1)
bbb += abs(sum(vvv[k]) - tar[k])
ans = min(ans, bbb)
print(ans)
| N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = float('inf')
def dfs(cur, a, b, c):
if cur == N:
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
# A,B,Cに使用する材料を合成し、目的の長さの差を加算(必要なMP)
# ret1-3で一つ目の材料にも合成魔法のMP10を要求しているので、A,B,Cの初回加算合わせて3回分のMP30を減算
# a,b,cのいずれかが0のとき、材料が1つも宛がわれていない竹が存在するため、不適(必要MPをINFとして解にならないようにする)
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
# l[cur]について、使用しないか、(A,B,C)のいずれかに使用の4分岐
print((dfs(0, 0, 0, 0)))
| 32 | 20 | 772 | 715 | N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
l = list(sorted(l))
tar = []
for x in C, B, A:
if x in l:
l.remove(x)
else:
tar.append(x)
if not tar:
print((0))
exit()
ans = float("inf")
for j in range((len(tar) + 1) ** len(l)):
vvv = [[] for _ in range(len(tar) + 1)]
for i in sorted(list(range(len(l))), reverse=True):
idx, j = divmod(j, (len(tar) + 1) ** i)
vvv[idx].append(l[i])
if any(len(vvvv) == 0 for vvvv in vvv[:-1]):
continue
else:
bbb = 0
# print(tar, vvv)
for k in range(len(tar)):
bbb += 10 * (len(vvv[k]) - 1)
bbb += abs(sum(vvv[k]) - tar[k])
ans = min(ans, bbb)
print(ans)
| N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = float("inf")
def dfs(cur, a, b, c):
if cur == N:
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
# A,B,Cに使用する材料を合成し、目的の長さの差を加算(必要なMP)
# ret1-3で一つ目の材料にも合成魔法のMP10を要求しているので、A,B,Cの初回加算合わせて3回分のMP30を減算
# a,b,cのいずれかが0のとき、材料が1つも宛がわれていない竹が存在するため、不適(必要MPをINFとして解にならないようにする)
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
# l[cur]について、使用しないか、(A,B,C)のいずれかに使用の4分岐
print((dfs(0, 0, 0, 0)))
| false | 37.5 | [
"-l = list(sorted(l))",
"-tar = []",
"-for x in C, B, A:",
"- if x in l:",
"- l.remove(x)",
"- else:",
"- tar.append(x)",
"-if not tar:",
"- print((0))",
"- exit()",
"-ans = float(\"inf\")",
"-for j in range((len(tar) + 1) ** len(l)):",
"- vvv = [[] for _ in range(len(tar) + 1)]",
"- for i in sorted(list(range(len(l))), reverse=True):",
"- idx, j = divmod(j, (len(tar) + 1) ** i)",
"- vvv[idx].append(l[i])",
"- if any(len(vvvv) == 0 for vvvv in vvv[:-1]):",
"- continue",
"- else:",
"- bbb = 0",
"- # print(tar, vvv)",
"- for k in range(len(tar)):",
"- bbb += 10 * (len(vvv[k]) - 1)",
"- bbb += abs(sum(vvv[k]) - tar[k])",
"- ans = min(ans, bbb)",
"-print(ans)",
"+INF = float(\"inf\")",
"+",
"+",
"+def dfs(cur, a, b, c):",
"+ if cur == N:",
"+ return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF",
"+ # A,B,Cに使用する材料を合成し、目的の長さの差を加算(必要なMP)",
"+ # ret1-3で一つ目の材料にも合成魔法のMP10を要求しているので、A,B,Cの初回加算合わせて3回分のMP30を減算",
"+ # a,b,cのいずれかが0のとき、材料が1つも宛がわれていない竹が存在するため、不適(必要MPをINFとして解にならないようにする)",
"+ ret0 = dfs(cur + 1, a, b, c)",
"+ ret1 = dfs(cur + 1, a + l[cur], b, c) + 10",
"+ ret2 = dfs(cur + 1, a, b + l[cur], c) + 10",
"+ ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10",
"+ return min(ret0, ret1, ret2, ret3)",
"+ # l[cur]について、使用しないか、(A,B,C)のいずれかに使用の4分岐",
"+",
"+",
"+print((dfs(0, 0, 0, 0)))"
] | false | 0.354002 | 0.061489 | 5.757135 | [
"s999299947",
"s896884770"
] |
u072053884 | p02238 | python | s521337924 | s936101836 | 20 | 10 | 7,772 | 7,748 | Accepted | Accepted | 50 | n = int(eval(input()))
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
sndf.append([False, i])
path = []
time = 0
def dfs(u):
global time
sndf[u][0] = True
time += 1
sndf[u].append(time)
for v in adj[u]:
if not sndf[v][0]:
dfs(v)
sndf[u][0] = True
time += 1
sndf[u].append(time)
for i in range(1, n + 1):
if not sndf[i][0]:
dfs(i)
for x in sndf[1:]:
print((*x[1:])) | n = int(eval(input()))
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
sndf.append([False, i])
path = []
time = 0
def dfs(u):
global time
sndf[u][0] = True
time += 1
sndf[u].append(time)
for v in adj[u]:
if not sndf[v][0]:
dfs(v)
time += 1
sndf[u].append(time)
for i in range(1, n + 1):
if not sndf[i][0]:
dfs(i)
for x in sndf[1:]:
print((*x[1:])) | 36 | 35 | 639 | 616 | n = int(eval(input()))
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
sndf.append([False, i])
path = []
time = 0
def dfs(u):
global time
sndf[u][0] = True
time += 1
sndf[u].append(time)
for v in adj[u]:
if not sndf[v][0]:
dfs(v)
sndf[u][0] = True
time += 1
sndf[u].append(time)
for i in range(1, n + 1):
if not sndf[i][0]:
dfs(i)
for x in sndf[1:]:
print((*x[1:]))
| n = int(eval(input()))
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
sndf.append([False, i])
path = []
time = 0
def dfs(u):
global time
sndf[u][0] = True
time += 1
sndf[u].append(time)
for v in adj[u]:
if not sndf[v][0]:
dfs(v)
time += 1
sndf[u].append(time)
for i in range(1, n + 1):
if not sndf[i][0]:
dfs(i)
for x in sndf[1:]:
print((*x[1:]))
| false | 2.777778 | [
"- sndf[u][0] = True"
] | false | 0.144965 | 0.047421 | 3.057 | [
"s521337924",
"s936101836"
] |
u047393579 | p03457 | python | s929081177 | s162876714 | 1,806 | 388 | 3,064 | 3,064 | Accepted | Accepted | 78.52 | N = int(eval(input()))
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
flag = False
t, x, y = list(map(int, input().split()))
for a in range(t - pre_t + 1):
b = pre_x - x + a
if b >= 0:
for c in range(t - pre_t + 1 - a - b):
d = t - pre_t - a - b - c
if pre_y + c - d == y:
count += 1
flag = True
break
if flag:
break
pre_t = t
pre_x = x
pre_y = y
if count == N:
print("Yes")
else:
print("No") | N = int(eval(input()))
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
t, x, y = list(map(int, input().split()))
if x > pre_x:
a = x - pre_x
b = 0
else:
b = pre_x - x
a = 0
if y > pre_y:
c = y - pre_y
d = 0
else:
d = pre_y - y
c = 0
total = a+b+c+d
if t - pre_t >= total and (t - pre_t - total) % 2 == 0:
count += 1
pre_t = t
pre_x = x
pre_y = y
if count == N:
print("Yes")
else:
print("No") | 26 | 29 | 590 | 538 | N = int(eval(input()))
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
flag = False
t, x, y = list(map(int, input().split()))
for a in range(t - pre_t + 1):
b = pre_x - x + a
if b >= 0:
for c in range(t - pre_t + 1 - a - b):
d = t - pre_t - a - b - c
if pre_y + c - d == y:
count += 1
flag = True
break
if flag:
break
pre_t = t
pre_x = x
pre_y = y
if count == N:
print("Yes")
else:
print("No")
| N = int(eval(input()))
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
t, x, y = list(map(int, input().split()))
if x > pre_x:
a = x - pre_x
b = 0
else:
b = pre_x - x
a = 0
if y > pre_y:
c = y - pre_y
d = 0
else:
d = pre_y - y
c = 0
total = a + b + c + d
if t - pre_t >= total and (t - pre_t - total) % 2 == 0:
count += 1
pre_t = t
pre_x = x
pre_y = y
if count == N:
print("Yes")
else:
print("No")
| false | 10.344828 | [
"- flag = False",
"- for a in range(t - pre_t + 1):",
"- b = pre_x - x + a",
"- if b >= 0:",
"- for c in range(t - pre_t + 1 - a - b):",
"- d = t - pre_t - a - b - c",
"- if pre_y + c - d == y:",
"- count += 1",
"- flag = True",
"- break",
"- if flag:",
"- break",
"+ if x > pre_x:",
"+ a = x - pre_x",
"+ b = 0",
"+ else:",
"+ b = pre_x - x",
"+ a = 0",
"+ if y > pre_y:",
"+ c = y - pre_y",
"+ d = 0",
"+ else:",
"+ d = pre_y - y",
"+ c = 0",
"+ total = a + b + c + d",
"+ if t - pre_t >= total and (t - pre_t - total) % 2 == 0:",
"+ count += 1"
] | false | 0.041087 | 0.042516 | 0.966392 | [
"s929081177",
"s162876714"
] |
u620084012 | p03038 | python | s078957516 | s060319039 | 814 | 533 | 81,516 | 36,828 | Accepted | Accepted | 34.52 | N, M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
L = []
for k in range(M):
B, C = list(map(int,input().split()))
L.append([B,C])
L = sorted(L,key=lambda x: -x[1])
ans = 0
i = 0
for k in range(N):
if i < M:
if A[k] < L[i][1]:
L[i][0] -= 1
ans += L[i][1]
if L[i][0] == 0:
i += 1
else:
ans += A[k]
else:
ans += A[k]
print(ans)
| N, M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
D = [list(map(int,input().split())) for k in range(M)]
D = sorted(D, key = lambda x: -x[1])
D.append([10**9+1,-1])
t = 0
ans = 0
for k in range(N):
if A[k] < D[t][1]:
ans += D[t][1]
D[t][0] -= 1
if D[t][0] == 0:
t += 1
else:
ans += A[k]
print(ans)
| 21 | 17 | 468 | 392 | N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
L = []
for k in range(M):
B, C = list(map(int, input().split()))
L.append([B, C])
L = sorted(L, key=lambda x: -x[1])
ans = 0
i = 0
for k in range(N):
if i < M:
if A[k] < L[i][1]:
L[i][0] -= 1
ans += L[i][1]
if L[i][0] == 0:
i += 1
else:
ans += A[k]
else:
ans += A[k]
print(ans)
| N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
D = [list(map(int, input().split())) for k in range(M)]
D = sorted(D, key=lambda x: -x[1])
D.append([10**9 + 1, -1])
t = 0
ans = 0
for k in range(N):
if A[k] < D[t][1]:
ans += D[t][1]
D[t][0] -= 1
if D[t][0] == 0:
t += 1
else:
ans += A[k]
print(ans)
| false | 19.047619 | [
"-L = []",
"-for k in range(M):",
"- B, C = list(map(int, input().split()))",
"- L.append([B, C])",
"-L = sorted(L, key=lambda x: -x[1])",
"+D = [list(map(int, input().split())) for k in range(M)]",
"+D = sorted(D, key=lambda x: -x[1])",
"+D.append([10**9 + 1, -1])",
"+t = 0",
"-i = 0",
"- if i < M:",
"- if A[k] < L[i][1]:",
"- L[i][0] -= 1",
"- ans += L[i][1]",
"- if L[i][0] == 0:",
"- i += 1",
"- else:",
"- ans += A[k]",
"+ if A[k] < D[t][1]:",
"+ ans += D[t][1]",
"+ D[t][0] -= 1",
"+ if D[t][0] == 0:",
"+ t += 1"
] | false | 0.0437 | 0.044641 | 0.978937 | [
"s078957516",
"s060319039"
] |
u604774382 | p02390 | python | s850711002 | s054963295 | 30 | 20 | 6,736 | 4,192 | Accepted | Accepted | 33.33 | #coding:utf-8
S=int( eval(input()) )
h=int( S/3600)
S=int( S%3600)
m=int( S/60)
s=int( S%60)
print(( "{}:{}:{}".format( h, m, s ) )) | import sys
x = int( sys.stdin.readline() )
h = x//3600
m = ( x%3600 )//60
s = ( x%3600 )%60
print(( "{}:{}:{}".format( h, m, s) )) | 7 | 7 | 130 | 135 | # coding:utf-8
S = int(eval(input()))
h = int(S / 3600)
S = int(S % 3600)
m = int(S / 60)
s = int(S % 60)
print(("{}:{}:{}".format(h, m, s)))
| import sys
x = int(sys.stdin.readline())
h = x // 3600
m = (x % 3600) // 60
s = (x % 3600) % 60
print(("{}:{}:{}".format(h, m, s)))
| false | 0 | [
"-# coding:utf-8",
"-S = int(eval(input()))",
"-h = int(S / 3600)",
"-S = int(S % 3600)",
"-m = int(S / 60)",
"-s = int(S % 60)",
"+import sys",
"+",
"+x = int(sys.stdin.readline())",
"+h = x // 3600",
"+m = (x % 3600) // 60",
"+s = (x % 3600) % 60"
] | false | 0.108866 | 0.040284 | 2.702454 | [
"s850711002",
"s054963295"
] |
u102461423 | p02821 | python | s415497404 | s968894067 | 323 | 192 | 18,236 | 30,976 | Accepted | Accepted | 40.56 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 価値 x 以上の握手を全て行うとする
# 握手回数が決まる。左手ごとに集計できる。
import numpy as np
N,M = list(map(int,readline().split()))
A = np.array(read().split(),np.int64)
A.sort()
def shake_cnt(x):
# x 以上の握手を全て行うとして、握手の回数を数える
# 行わない握手を数える
X = np.searchsorted(A,x-A)
return N * N - X.sum()
left = 0 # 握手の回数がM以上
right = 10 ** 6 # 握手の回数がM未満
while left + 1 < right:
x = (left + right) // 2
if shake_cnt(x) >= M:
left = x
else:
right = x
left,right
# right 以上の握手を全て行ったとして、回数と総和を計算
X = np.searchsorted(A,right-A) # 行わない人数
Acum = np.zeros(N+1,np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)
shake = N * N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()
happy += (M - shake) *left
print(happy) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = list(map(int,readline().split()))
A = np.array(read().split(),np.int64)
f = np.bincount(A)
fft_len = 1<<18
fft = np.fft.rfft; ifft = np.fft.irfft
Ff = fft(f,fft_len)
G = np.rint(ifft(Ff * Ff,fft_len)).astype(np.int64) # 和 -> 何通りか
Gcum = G.cumsum()
remove_cnt = N * N - M
i = np.searchsorted(Gcum,remove_cnt)
# i未満は全部除外。ちょうどiのものもいくつか除外
x = remove_cnt - Gcum[i-1]
remove_sum = (G[:i] * np.arange(i,dtype=np.int64)).sum() + i * x
answer = A.sum() * 2 * N - remove_sum
print(answer) | 43 | 27 | 879 | 646 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 価値 x 以上の握手を全て行うとする
# 握手回数が決まる。左手ごとに集計できる。
import numpy as np
N, M = list(map(int, readline().split()))
A = np.array(read().split(), np.int64)
A.sort()
def shake_cnt(x):
# x 以上の握手を全て行うとして、握手の回数を数える
# 行わない握手を数える
X = np.searchsorted(A, x - A)
return N * N - X.sum()
left = 0 # 握手の回数がM以上
right = 10**6 # 握手の回数がM未満
while left + 1 < right:
x = (left + right) // 2
if shake_cnt(x) >= M:
left = x
else:
right = x
left, right
# right 以上の握手を全て行ったとして、回数と総和を計算
X = np.searchsorted(A, right - A) # 行わない人数
Acum = np.zeros(N + 1, np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)
shake = N * N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()
happy += (M - shake) * left
print(happy)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N, M = list(map(int, readline().split()))
A = np.array(read().split(), np.int64)
f = np.bincount(A)
fft_len = 1 << 18
fft = np.fft.rfft
ifft = np.fft.irfft
Ff = fft(f, fft_len)
G = np.rint(ifft(Ff * Ff, fft_len)).astype(np.int64) # 和 -> 何通りか
Gcum = G.cumsum()
remove_cnt = N * N - M
i = np.searchsorted(Gcum, remove_cnt)
# i未満は全部除外。ちょうどiのものもいくつか除外
x = remove_cnt - Gcum[i - 1]
remove_sum = (G[:i] * np.arange(i, dtype=np.int64)).sum() + i * x
answer = A.sum() * 2 * N - remove_sum
print(answer)
| false | 37.209302 | [
"-# 価値 x 以上の握手を全て行うとする",
"-# 握手回数が決まる。左手ごとに集計できる。",
"-A.sort()",
"-",
"-",
"-def shake_cnt(x):",
"- # x 以上の握手を全て行うとして、握手の回数を数える",
"- # 行わない握手を数える",
"- X = np.searchsorted(A, x - A)",
"- return N * N - X.sum()",
"-",
"-",
"-left = 0 # 握手の回数がM以上",
"-right = 10**6 # 握手の回数がM未満",
"-while left + 1 < right:",
"- x = (left + right) // 2",
"- if shake_cnt(x) >= M:",
"- left = x",
"- else:",
"- right = x",
"-left, right",
"-# right 以上の握手を全て行ったとして、回数と総和を計算",
"-X = np.searchsorted(A, right - A) # 行わない人数",
"-Acum = np.zeros(N + 1, np.int64) # 人数 -> 累積和",
"-Acum[1:] = np.cumsum(A)",
"-shake = N * N - X.sum()",
"-happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()",
"-happy += (M - shake) * left",
"-print(happy)",
"+f = np.bincount(A)",
"+fft_len = 1 << 18",
"+fft = np.fft.rfft",
"+ifft = np.fft.irfft",
"+Ff = fft(f, fft_len)",
"+G = np.rint(ifft(Ff * Ff, fft_len)).astype(np.int64) # 和 -> 何通りか",
"+Gcum = G.cumsum()",
"+remove_cnt = N * N - M",
"+i = np.searchsorted(Gcum, remove_cnt)",
"+# i未満は全部除外。ちょうどiのものもいくつか除外",
"+x = remove_cnt - Gcum[i - 1]",
"+remove_sum = (G[:i] * np.arange(i, dtype=np.int64)).sum() + i * x",
"+answer = A.sum() * 2 * N - remove_sum",
"+print(answer)"
] | false | 0.2971 | 0.349745 | 0.849477 | [
"s415497404",
"s968894067"
] |
u160224209 | p02641 | python | s022337671 | s424638933 | 62 | 35 | 62,068 | 9,056 | Accepted | Accepted | 43.55 | x,n = list(map(int,input().split()))
p = list(map(int,input().split()))
p.sort()
li = []
ans = []
Min_sa = 9999999999
for i in range(-200,201):
if i not in p:
li.append(i)
for i in li:
Min_sa = min(Min_sa,abs(x-i))
for i in li:
if abs(x-i) == Min_sa:
ans.append(i)
print((min(ans))) | x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
print(x)
exit()
for i in range(-1000, 1000):
if not i in p:
lists.append(i)
for i in lists:
if ans > abs(x - i):
ans = abs(x-i)
m = i
print(m)
| 15 | 16 | 317 | 307 | x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
li = []
ans = []
Min_sa = 9999999999
for i in range(-200, 201):
if i not in p:
li.append(i)
for i in li:
Min_sa = min(Min_sa, abs(x - i))
for i in li:
if abs(x - i) == Min_sa:
ans.append(i)
print((min(ans)))
| x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
print(x)
exit()
for i in range(-1000, 1000):
if not i in p:
lists.append(i)
for i in lists:
if ans > abs(x - i):
ans = abs(x - i)
m = i
print(m)
| false | 6.25 | [
"-p.sort()",
"-li = []",
"-ans = []",
"-Min_sa = 9999999999",
"-for i in range(-200, 201):",
"- if i not in p:",
"- li.append(i)",
"-for i in li:",
"- Min_sa = min(Min_sa, abs(x - i))",
"-for i in li:",
"- if abs(x - i) == Min_sa:",
"- ans.append(i)",
"-print((min(ans)))",
"+ans = 9999999999",
"+lists = []",
"+if n == 0:",
"+ print(x)",
"+ exit()",
"+for i in range(-1000, 1000):",
"+ if not i in p:",
"+ lists.append(i)",
"+for i in lists:",
"+ if ans > abs(x - i):",
"+ ans = abs(x - i)",
"+ m = i",
"+print(m)"
] | false | 0.069941 | 0.044543 | 1.570195 | [
"s022337671",
"s424638933"
] |
u724732842 | p03472 | python | s127412081 | s393223474 | 772 | 532 | 35,768 | 26,192 | Accepted | Accepted | 31.09 | import math
N,H = list(map(int,input().split()))
data=[]
for i in range(N):
a,b = list(map(int,input().split()))
data.append([a,b,i])
s1 = sorted(data,key = lambda x:(-x[1],x[0]))
s2 = sorted(data,key = lambda x:(-x[0],x[1]))
cnt = 0
maxNum = s2[0][2]
for i in range(N):
if H > 0:
if s1[i][1] > s2[0][0]:
if s1[i][2] == maxNum:
continue
else:
H -= s1[i][1]
cnt += 1
else:
H -= s2[0][1]
cnt += 1
break
else:
print(cnt)
exit()
else:
H -= s2[0][1]
cnt += 1
if H > 0:
print((cnt + math.ceil(H/s2[0][0])))
else:
print(cnt) | import math
N,H = list(map(int,input().split()))
data=[]
for i in range(N):
a,b = list(map(int,input().split()))
data.append([a,b])
s1 = sorted(data,key = lambda x:-x[1])
s2 = sorted(data,key = lambda x:-x[0])
cnt = 0
for i in range(N):
if H > 0:
if s1[i][1] > s2[0][0]:
H -= s1[i][1]
cnt += 1
else:
break
else:
print(cnt)
exit()
if H > 0:
print((cnt + math.ceil(H/s2[0][0])))
else:
print(cnt)
| 38 | 31 | 742 | 541 | import math
N, H = list(map(int, input().split()))
data = []
for i in range(N):
a, b = list(map(int, input().split()))
data.append([a, b, i])
s1 = sorted(data, key=lambda x: (-x[1], x[0]))
s2 = sorted(data, key=lambda x: (-x[0], x[1]))
cnt = 0
maxNum = s2[0][2]
for i in range(N):
if H > 0:
if s1[i][1] > s2[0][0]:
if s1[i][2] == maxNum:
continue
else:
H -= s1[i][1]
cnt += 1
else:
H -= s2[0][1]
cnt += 1
break
else:
print(cnt)
exit()
else:
H -= s2[0][1]
cnt += 1
if H > 0:
print((cnt + math.ceil(H / s2[0][0])))
else:
print(cnt)
| import math
N, H = list(map(int, input().split()))
data = []
for i in range(N):
a, b = list(map(int, input().split()))
data.append([a, b])
s1 = sorted(data, key=lambda x: -x[1])
s2 = sorted(data, key=lambda x: -x[0])
cnt = 0
for i in range(N):
if H > 0:
if s1[i][1] > s2[0][0]:
H -= s1[i][1]
cnt += 1
else:
break
else:
print(cnt)
exit()
if H > 0:
print((cnt + math.ceil(H / s2[0][0])))
else:
print(cnt)
| false | 18.421053 | [
"- data.append([a, b, i])",
"-s1 = sorted(data, key=lambda x: (-x[1], x[0]))",
"-s2 = sorted(data, key=lambda x: (-x[0], x[1]))",
"+ data.append([a, b])",
"+s1 = sorted(data, key=lambda x: -x[1])",
"+s2 = sorted(data, key=lambda x: -x[0])",
"-maxNum = s2[0][2]",
"- if s1[i][2] == maxNum:",
"- continue",
"- else:",
"- H -= s1[i][1]",
"- cnt += 1",
"+ H -= s1[i][1]",
"+ cnt += 1",
"- H -= s2[0][1]",
"- cnt += 1",
"-else:",
"- H -= s2[0][1]",
"- cnt += 1"
] | false | 0.103585 | 0.111115 | 0.932226 | [
"s127412081",
"s393223474"
] |
u021019433 | p02768 | python | s863381995 | s171925314 | 126 | 109 | 3,060 | 3,060 | Accepted | Accepted | 13.49 | M = 10**9 + 7
n, a, b = list(map(int, input().split()))
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
f = f * (i + 1) % M
c = c * (n - i) % M
if i + 1 in (a, b):
r -= c * pow(f, M - 2, M)
print((r % M))
| M = 10**9 + 7
n, a, b = list(map(int, input().split()))
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
f = f * (i + 1) % M
c = c * (n - i) % M
if i + 1 == a:
a = b
r -= c * pow(f, M - 2, M)
print((r % M)) | 10 | 11 | 218 | 223 | M = 10**9 + 7
n, a, b = list(map(int, input().split()))
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
f = f * (i + 1) % M
c = c * (n - i) % M
if i + 1 in (a, b):
r -= c * pow(f, M - 2, M)
print((r % M))
| M = 10**9 + 7
n, a, b = list(map(int, input().split()))
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
f = f * (i + 1) % M
c = c * (n - i) % M
if i + 1 == a:
a = b
r -= c * pow(f, M - 2, M)
print((r % M))
| false | 9.090909 | [
"- if i + 1 in (a, b):",
"+ if i + 1 == a:",
"+ a = b"
] | false | 0.007308 | 0.110464 | 0.066159 | [
"s863381995",
"s171925314"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.