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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u977389981 | p04045 | python | s538721266 | s515355254 | 74 | 54 | 2,940 | 2,940 | Accepted | Accepted | 27.03 | n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(10 * n):
for a in A:
if a in str(n + i):
break
else:
ans = n + i
break
print(ans) | n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(n * 10):
for j in str(n + i):
if j in A:
break
else:
print((n + i))
break | 10 | 10 | 212 | 199 | n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(10 * n):
for a in A:
if a in str(n + i):
break
else:
ans = n + i
break
print(ans)
| n, k = list(map(int, input().split()))
A = list(input().split())
for i in range(n * 10):
for j in str(n + i):
if j in A:
break
else:
print((n + i))
break
| false | 0 | [
"-for i in range(10 * n):",
"- for a in A:",
"- if a in str(n + i):",
"+for i in range(n * 10):",
"+ for j in str(n + i):",
"+ if j in A:",
"- ans = n + i",
"+ print((n + i))",
"-print(ans)"
]
| false | 0.03287 | 0.039276 | 0.836891 | [
"s538721266",
"s515355254"
]
|
u753803401 | p03470 | python | s566877171 | s367686476 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | n = int(eval(input()))
d = [int(eval(input()))for _ in range(n)]
d = sorted(d, reverse=True)
cnt = 1
for i in range(1, n):
if d[i] < d[i-1]:
cnt += 1
print(cnt)
| n = int(eval(input()))
d = [int(eval(input())) for _ in range(n)]
d = sorted(d, reverse=True)
cnt = 0
last = 10 ** 9
for i in d:
if i < last:
last = i
cnt += 1
print(cnt)
| 8 | 10 | 168 | 188 | n = int(eval(input()))
d = [int(eval(input())) for _ in range(n)]
d = sorted(d, reverse=True)
cnt = 1
for i in range(1, n):
if d[i] < d[i - 1]:
cnt += 1
print(cnt)
| n = int(eval(input()))
d = [int(eval(input())) for _ in range(n)]
d = sorted(d, reverse=True)
cnt = 0
last = 10**9
for i in d:
if i < last:
last = i
cnt += 1
print(cnt)
| false | 20 | [
"-cnt = 1",
"-for i in range(1, n):",
"- if d[i] < d[i - 1]:",
"+cnt = 0",
"+last = 10**9",
"+for i in d:",
"+ if i < last:",
"+ last = i"
]
| false | 0.042629 | 0.131228 | 0.324845 | [
"s566877171",
"s367686476"
]
|
u072717685 | p02713 | python | s926357683 | s273421285 | 1,429 | 304 | 9,160 | 89,564 | Accepted | Accepted | 78.73 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import gcd
def main():
k = int(eval(input()))
r = 0
for i1 in range(1, k + 1):
for i2 in range(1, k + 1):
for i3 in range(1, k + 1):
t1 = gcd(i1, i2)
r += gcd(t1, i3)
print(r)
if __name__ == '__main__':
main() | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
k = int(eval(input()))
k2 = np.arange(1, k+1)
k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))
print((k2gcd.sum()))
if __name__ == '__main__':
main() | 16 | 13 | 366 | 269 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import gcd
def main():
k = int(eval(input()))
r = 0
for i1 in range(1, k + 1):
for i2 in range(1, k + 1):
for i3 in range(1, k + 1):
t1 = gcd(i1, i2)
r += gcd(t1, i3)
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
k = int(eval(input()))
k2 = np.arange(1, k + 1)
k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))
print((k2gcd.sum()))
if __name__ == "__main__":
main()
| false | 18.75 | [
"-from math import gcd",
"+import numpy as np",
"- r = 0",
"- for i1 in range(1, k + 1):",
"- for i2 in range(1, k + 1):",
"- for i3 in range(1, k + 1):",
"- t1 = gcd(i1, i2)",
"- r += gcd(t1, i3)",
"- print(r)",
"+ k2 = np.arange(1, k + 1)",
"+ k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))",
"+ print((k2gcd.sum()))"
]
| false | 0.080565 | 0.215459 | 0.373923 | [
"s926357683",
"s273421285"
]
|
u958506960 | p03814 | python | s291508770 | s568754064 | 74 | 18 | 11,152 | 3,500 | Accepted | Accepted | 75.68 | S = eval(input())
a = []
z = []
for i, s in enumerate(S):
if s == 'A':
a.append(i + 1)
elif s == 'Z':
z.append(i + 1)
print((max(z) - min(a) + 1)) | s = eval(input())
a = s.index('A')
z = s.rindex('Z')
print((z - a + 1)) | 10 | 4 | 172 | 66 | S = eval(input())
a = []
z = []
for i, s in enumerate(S):
if s == "A":
a.append(i + 1)
elif s == "Z":
z.append(i + 1)
print((max(z) - min(a) + 1))
| s = eval(input())
a = s.index("A")
z = s.rindex("Z")
print((z - a + 1))
| false | 60 | [
"-S = eval(input())",
"-a = []",
"-z = []",
"-for i, s in enumerate(S):",
"- if s == \"A\":",
"- a.append(i + 1)",
"- elif s == \"Z\":",
"- z.append(i + 1)",
"-print((max(z) - min(a) + 1))",
"+s = eval(input())",
"+a = s.index(\"A\")",
"+z = s.rindex(\"Z\")",
"+print((z - a + 1))"
]
| false | 0.039032 | 0.034259 | 1.139337 | [
"s291508770",
"s568754064"
]
|
u868701750 | p03160 | python | s898304529 | s689620964 | 147 | 117 | 13,928 | 13,980 | Accepted | Accepted | 20.41 | if __name__ == '__main__':
N = int(eval(input()))
h = list(map(int, input().split()))
DP = [0]
for i in range(1, N):
if i == 1:
DP += [abs(h[i]-h[i-1])]
continue
DP += [min(DP[i-1]+abs(h[i]-h[i-1]), DP[i-2]+abs(h[i]-h[i-2]))]
print((DP[-1]))
| def dp():
N = int(eval(input()))
h = list(map(int, input().split()))
DP = [0]
for i in range(1, N):
if i == 1:
DP += [abs(h[i]-h[i-1])]
continue
DP += [min(DP[i-1]+abs(h[i]-h[i-1]), DP[i-2]+abs(h[i]-h[i-2]))]
print((DP[-1]))
dp()
| 12 | 13 | 315 | 296 | if __name__ == "__main__":
N = int(eval(input()))
h = list(map(int, input().split()))
DP = [0]
for i in range(1, N):
if i == 1:
DP += [abs(h[i] - h[i - 1])]
continue
DP += [min(DP[i - 1] + abs(h[i] - h[i - 1]), DP[i - 2] + abs(h[i] - h[i - 2]))]
print((DP[-1]))
| def dp():
N = int(eval(input()))
h = list(map(int, input().split()))
DP = [0]
for i in range(1, N):
if i == 1:
DP += [abs(h[i] - h[i - 1])]
continue
DP += [min(DP[i - 1] + abs(h[i] - h[i - 1]), DP[i - 2] + abs(h[i] - h[i - 2]))]
print((DP[-1]))
dp()
| false | 7.692308 | [
"-if __name__ == \"__main__\":",
"+def dp():",
"+",
"+",
"+dp()"
]
| false | 0.039276 | 0.044581 | 0.881009 | [
"s898304529",
"s689620964"
]
|
u476604182 | p03354 | python | s590836350 | s111624103 | 1,047 | 436 | 101,740 | 36,952 | Accepted | Accepted | 58.36 | from collections import defaultdict
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 x==y:
return
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 same(self, x, y):
return self.find(x)==self.find(y)
N, M = list(map(int, input().split()))
h = [int(i)-1 for i in input().split()]
dic1 = defaultdict(list)
dic2 = defaultdict(list)
u = UnionFind(N)
for i in range(M):
a, b = list(map(int, input().split()))
u.unite(a-1,b-1)
for c in range(N):
p = u.find(c)
dic1[p] += [c]
dic2[p] += [h[c]]
ans = 0
for p in list(dic1.keys()):
dic1[p].sort()
dic2[p].sort()
i = 0
j = 0
while i<len(dic1[p]) and j<len(dic2[p]):
if dic1[p][i]==dic2[p][j]:
i += 1
j += 1
ans += 1
elif dic1[p][i]<dic2[p][j]:
i += 1
else:
j += 1
print(ans) | 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 unit(self, x, y):
x = self.find(x)
y = self.find(y)
if x==y:
return
elif self.rank[x]<self.rank[y]:
self.par[x] = y
return
elif self.rank[y]<self.rank[x]:
self.par[y] = x
else:
self.par[y] = x
self.rank[x] += 1
def same(self, x, y):
return self.find(x)==self.find(y)
N, M, *L = list(map(int, open(0).read().split()))
p = L[:N]
ls = L[N:]
u = UnionFind(N+1)
for x,y in zip(*[iter(ls)]*2):
u.unit(x,y)
inf = {p[i]:i for i in range(N)}
ans = sum(1 if u.same(i,inf[i]+1) else 0 for i in range(1,N+1))
print(ans) | 59 | 37 | 1,217 | 860 | from collections import defaultdict
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 x == y:
return
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 same(self, x, y):
return self.find(x) == self.find(y)
N, M = list(map(int, input().split()))
h = [int(i) - 1 for i in input().split()]
dic1 = defaultdict(list)
dic2 = defaultdict(list)
u = UnionFind(N)
for i in range(M):
a, b = list(map(int, input().split()))
u.unite(a - 1, b - 1)
for c in range(N):
p = u.find(c)
dic1[p] += [c]
dic2[p] += [h[c]]
ans = 0
for p in list(dic1.keys()):
dic1[p].sort()
dic2[p].sort()
i = 0
j = 0
while i < len(dic1[p]) and j < len(dic2[p]):
if dic1[p][i] == dic2[p][j]:
i += 1
j += 1
ans += 1
elif dic1[p][i] < dic2[p][j]:
i += 1
else:
j += 1
print(ans)
| 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 unit(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.par[x] = y
return
elif self.rank[y] < self.rank[x]:
self.par[y] = x
else:
self.par[y] = x
self.rank[x] += 1
def same(self, x, y):
return self.find(x) == self.find(y)
N, M, *L = list(map(int, open(0).read().split()))
p = L[:N]
ls = L[N:]
u = UnionFind(N + 1)
for x, y in zip(*[iter(ls)] * 2):
u.unit(x, y)
inf = {p[i]: i for i in range(N)}
ans = sum(1 if u.same(i, inf[i] + 1) else 0 for i in range(1, N + 1))
print(ans)
| false | 37.288136 | [
"-from collections import defaultdict",
"-",
"-",
"- def unite(self, x, y):",
"+ def unit(self, x, y):",
"- if self.rank[x] < self.rank[y]:",
"+ elif self.rank[x] < self.rank[y]:",
"+ return",
"+ elif self.rank[y] < self.rank[x]:",
"+ self.par[y] = x",
"- if self.rank[x] == self.rank[y]:",
"- self.rank[x] += 1",
"+ self.rank[x] += 1",
"-N, M = list(map(int, input().split()))",
"-h = [int(i) - 1 for i in input().split()]",
"-dic1 = defaultdict(list)",
"-dic2 = defaultdict(list)",
"-u = UnionFind(N)",
"-for i in range(M):",
"- a, b = list(map(int, input().split()))",
"- u.unite(a - 1, b - 1)",
"-for c in range(N):",
"- p = u.find(c)",
"- dic1[p] += [c]",
"- dic2[p] += [h[c]]",
"-ans = 0",
"-for p in list(dic1.keys()):",
"- dic1[p].sort()",
"- dic2[p].sort()",
"- i = 0",
"- j = 0",
"- while i < len(dic1[p]) and j < len(dic2[p]):",
"- if dic1[p][i] == dic2[p][j]:",
"- i += 1",
"- j += 1",
"- ans += 1",
"- elif dic1[p][i] < dic2[p][j]:",
"- i += 1",
"- else:",
"- j += 1",
"+N, M, *L = list(map(int, open(0).read().split()))",
"+p = L[:N]",
"+ls = L[N:]",
"+u = UnionFind(N + 1)",
"+for x, y in zip(*[iter(ls)] * 2):",
"+ u.unit(x, y)",
"+inf = {p[i]: i for i in range(N)}",
"+ans = sum(1 if u.same(i, inf[i] + 1) else 0 for i in range(1, N + 1))"
]
| false | 0.039788 | 0.046089 | 0.863273 | [
"s590836350",
"s111624103"
]
|
u287132915 | p02720 | python | s111517664 | s986006648 | 69 | 61 | 6,096 | 79,072 | Accepted | Accepted | 11.59 | from collections import deque
k = int(eval(input()))
if 1 <= k and k <= 9:
print(k)
exit()
d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
num = d.popleft()
if num % 10 != 0:
new = 10*num + (num%10) - 1
d.append(new)
k -= 1
if k == 0: break
new = 10*num + (num%10)
d.append(new)
k -= 1
if k == 0: break
if num % 10 != 9:
new = 10*num + (num%10) + 1
d.append(new)
k -= 1
if k == 0: break
print(new) | k = int(eval(input()))
if k <= 9:
print(k)
k -= 9
lst = list(range(1, 10))
while k > 0:
new = []
for num in lst:
amari = num % 10
if amari == 0:
new.append(num*10)
new.append(num*10+1)
elif amari == 9:
new.append(num*10+8)
new.append(num*10+9)
else:
new.append(num*10+(amari-1))
new.append(num*10+amari)
new.append(num*10+(amari+1))
if len(new) >= k:
print((new[k-1]))
exit()
else:
k -= len(new)
lst = new | 28 | 27 | 531 | 593 | from collections import deque
k = int(eval(input()))
if 1 <= k and k <= 9:
print(k)
exit()
d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
num = d.popleft()
if num % 10 != 0:
new = 10 * num + (num % 10) - 1
d.append(new)
k -= 1
if k == 0:
break
new = 10 * num + (num % 10)
d.append(new)
k -= 1
if k == 0:
break
if num % 10 != 9:
new = 10 * num + (num % 10) + 1
d.append(new)
k -= 1
if k == 0:
break
print(new)
| k = int(eval(input()))
if k <= 9:
print(k)
k -= 9
lst = list(range(1, 10))
while k > 0:
new = []
for num in lst:
amari = num % 10
if amari == 0:
new.append(num * 10)
new.append(num * 10 + 1)
elif amari == 9:
new.append(num * 10 + 8)
new.append(num * 10 + 9)
else:
new.append(num * 10 + (amari - 1))
new.append(num * 10 + amari)
new.append(num * 10 + (amari + 1))
if len(new) >= k:
print((new[k - 1]))
exit()
else:
k -= len(new)
lst = new
| false | 3.571429 | [
"-from collections import deque",
"-",
"-if 1 <= k and k <= 9:",
"+if k <= 9:",
"- exit()",
"-d = deque([i for i in range(1, 10)])",
"+lst = list(range(1, 10))",
"- num = d.popleft()",
"- if num % 10 != 0:",
"- new = 10 * num + (num % 10) - 1",
"- d.append(new)",
"- k -= 1",
"- if k == 0:",
"- break",
"- new = 10 * num + (num % 10)",
"- d.append(new)",
"- k -= 1",
"- if k == 0:",
"- break",
"- if num % 10 != 9:",
"- new = 10 * num + (num % 10) + 1",
"- d.append(new)",
"- k -= 1",
"- if k == 0:",
"- break",
"-print(new)",
"+ new = []",
"+ for num in lst:",
"+ amari = num % 10",
"+ if amari == 0:",
"+ new.append(num * 10)",
"+ new.append(num * 10 + 1)",
"+ elif amari == 9:",
"+ new.append(num * 10 + 8)",
"+ new.append(num * 10 + 9)",
"+ else:",
"+ new.append(num * 10 + (amari - 1))",
"+ new.append(num * 10 + amari)",
"+ new.append(num * 10 + (amari + 1))",
"+ if len(new) >= k:",
"+ print((new[k - 1]))",
"+ exit()",
"+ else:",
"+ k -= len(new)",
"+ lst = new"
]
| false | 0.037997 | 0.040993 | 0.926901 | [
"s111517664",
"s986006648"
]
|
u332906195 | p03573 | python | s137810318 | s702234441 | 167 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.82 | A, B, C = list(map(int, input().split()))
if A == B:
print(C)
elif B == C:
print(A)
else:
print(B)
| A, B, C = list(map(int, input().split()))
print((C if A == B else A if B == C else B))
| 7 | 2 | 111 | 80 | A, B, C = list(map(int, input().split()))
if A == B:
print(C)
elif B == C:
print(A)
else:
print(B)
| A, B, C = list(map(int, input().split()))
print((C if A == B else A if B == C else B))
| false | 71.428571 | [
"-if A == B:",
"- print(C)",
"-elif B == C:",
"- print(A)",
"-else:",
"- print(B)",
"+print((C if A == B else A if B == C else B))"
]
| false | 0.038373 | 0.037542 | 1.022126 | [
"s137810318",
"s702234441"
]
|
u347640436 | p02887 | python | s578563207 | s487137815 | 42 | 34 | 3,316 | 3,316 | Accepted | Accepted | 19.05 | N = int(eval(input()))
S = eval(input())
p = ''
result = 0
for i in range(N):
if p != S[i]:
result += 1
p = S[i]
print(result)
| N = int(eval(input()))
S = eval(input())
print((sum(1 for i in range(N - 1) if S[i] != S[i + 1]) + 1))
| 10 | 4 | 135 | 93 | N = int(eval(input()))
S = eval(input())
p = ""
result = 0
for i in range(N):
if p != S[i]:
result += 1
p = S[i]
print(result)
| N = int(eval(input()))
S = eval(input())
print((sum(1 for i in range(N - 1) if S[i] != S[i + 1]) + 1))
| false | 60 | [
"-p = \"\"",
"-result = 0",
"-for i in range(N):",
"- if p != S[i]:",
"- result += 1",
"- p = S[i]",
"-print(result)",
"+print((sum(1 for i in range(N - 1) if S[i] != S[i + 1]) + 1))"
]
| false | 0.039085 | 0.081995 | 0.476676 | [
"s578563207",
"s487137815"
]
|
u436149658 | p03469 | python | s535078942 | s612487501 | 26 | 24 | 9,096 | 8,916 | Accepted | Accepted | 7.69 | s = eval(input())
print((str(int(s[:4]) + 1) + s[4:])) | print(("2018/01/" + input()[-2:])) | 2 | 1 | 48 | 32 | s = eval(input())
print((str(int(s[:4]) + 1) + s[4:]))
| print(("2018/01/" + input()[-2:]))
| false | 50 | [
"-s = eval(input())",
"-print((str(int(s[:4]) + 1) + s[4:]))",
"+print((\"2018/01/\" + input()[-2:]))"
]
| false | 0.074553 | 0.073196 | 1.018536 | [
"s535078942",
"s612487501"
]
|
u761989513 | p03848 | python | s687519811 | s064808401 | 78 | 59 | 14,820 | 14,820 | Accepted | Accepted | 24.36 | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
if ac[0] != 1:
print((0))
exit()
for i in ac:
if i == 0:
continue
if ac[i] != 2:
print((0))
exit()
else:
if ac[1] != 2:
print((0))
exit()
for i in ac:
if i == 1:
continue
if ac[i] != 2:
print((0))
exit()
mod = 10 ** 9 + 7
print(((2 ** (n // 2)) % mod)) | import collections
n = int(eval(input()))
mod = 10 ** 9 + 7
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
for i in list(ac.items()):
if i[0] == 0:
if i[1] != 1:
print((0))
exit()
else:
if i[1] != 2:
print((0))
exit()
print((2 ** (n // 2) % mod))
else:
for i in list(ac.values()):
if i != 2:
print((0))
exit()
print((2 ** (n // 2) % mod)) | 27 | 23 | 531 | 512 | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
if ac[0] != 1:
print((0))
exit()
for i in ac:
if i == 0:
continue
if ac[i] != 2:
print((0))
exit()
else:
if ac[1] != 2:
print((0))
exit()
for i in ac:
if i == 1:
continue
if ac[i] != 2:
print((0))
exit()
mod = 10**9 + 7
print(((2 ** (n // 2)) % mod))
| import collections
n = int(eval(input()))
mod = 10**9 + 7
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
for i in list(ac.items()):
if i[0] == 0:
if i[1] != 1:
print((0))
exit()
else:
if i[1] != 2:
print((0))
exit()
print((2 ** (n // 2) % mod))
else:
for i in list(ac.values()):
if i != 2:
print((0))
exit()
print((2 ** (n // 2) % mod))
| false | 14.814815 | [
"+mod = 10**9 + 7",
"- if ac[0] != 1:",
"- print((0))",
"- exit()",
"- for i in ac:",
"- if i == 0:",
"- continue",
"- if ac[i] != 2:",
"+ for i in list(ac.items()):",
"+ if i[0] == 0:",
"+ if i[1] != 1:",
"+ print((0))",
"+ exit()",
"+ else:",
"+ if i[1] != 2:",
"+ print((0))",
"+ exit()",
"+ print((2 ** (n // 2) % mod))",
"+else:",
"+ for i in list(ac.values()):",
"+ if i != 2:",
"-else:",
"- if ac[1] != 2:",
"- print((0))",
"- exit()",
"- for i in ac:",
"- if i == 1:",
"- continue",
"- if ac[i] != 2:",
"- print((0))",
"- exit()",
"-mod = 10**9 + 7",
"-print(((2 ** (n // 2)) % mod))",
"+ print((2 ** (n // 2) % mod))"
]
| false | 0.115927 | 0.113444 | 1.021887 | [
"s687519811",
"s064808401"
]
|
u423665486 | p02683 | python | s291864470 | s128665884 | 84 | 61 | 68,564 | 9,216 | Accepted | Accepted | 27.38 | def resolve():
n, m, x = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(n)]
pay = float('inf')
for i in range(1 << n):
selected = []
for j in range(n):
if i >> j & 1:
selected.append(j)
rem = [0] * m
tmp_pay = 0
for j in selected:
tmp_pay += books[j][0]
for k in range(1, m+1):
rem[k-1] += books[j][k]
done = True
for j in range(m):
if rem[j] < x:
done = False
if done:
pay = min(pay, tmp_pay)
if pay == float('inf'):
print((-1))
else:
print(pay)
resolve() | def resolve():
n, m, x = list(map(int, input().split()))
c_seq = []
a_seq = []
ans = float('inf')
for i in range(n):
c, *a = list(map(int, input().split()))
c_seq.append(c)
a_seq.append(a)
for i in range(1 << n):
pay = 0
skill = [0]*m
for j in range(n):
if i >> j & 1:
pay += c_seq[j]
for k in range(m):
skill[k] += a_seq[j][k]
ok = True
for y in skill:
if x > y:
ok = False
if ok:
ans = min(ans, pay)
print((ans if ans < float('inf') else -1))
resolve() | 27 | 25 | 569 | 515 | def resolve():
n, m, x = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(n)]
pay = float("inf")
for i in range(1 << n):
selected = []
for j in range(n):
if i >> j & 1:
selected.append(j)
rem = [0] * m
tmp_pay = 0
for j in selected:
tmp_pay += books[j][0]
for k in range(1, m + 1):
rem[k - 1] += books[j][k]
done = True
for j in range(m):
if rem[j] < x:
done = False
if done:
pay = min(pay, tmp_pay)
if pay == float("inf"):
print((-1))
else:
print(pay)
resolve()
| def resolve():
n, m, x = list(map(int, input().split()))
c_seq = []
a_seq = []
ans = float("inf")
for i in range(n):
c, *a = list(map(int, input().split()))
c_seq.append(c)
a_seq.append(a)
for i in range(1 << n):
pay = 0
skill = [0] * m
for j in range(n):
if i >> j & 1:
pay += c_seq[j]
for k in range(m):
skill[k] += a_seq[j][k]
ok = True
for y in skill:
if x > y:
ok = False
if ok:
ans = min(ans, pay)
print((ans if ans < float("inf") else -1))
resolve()
| false | 7.407407 | [
"- books = [list(map(int, input().split())) for _ in range(n)]",
"- pay = float(\"inf\")",
"+ c_seq = []",
"+ a_seq = []",
"+ ans = float(\"inf\")",
"+ for i in range(n):",
"+ c, *a = list(map(int, input().split()))",
"+ c_seq.append(c)",
"+ a_seq.append(a)",
"- selected = []",
"+ pay = 0",
"+ skill = [0] * m",
"- selected.append(j)",
"- rem = [0] * m",
"- tmp_pay = 0",
"- for j in selected:",
"- tmp_pay += books[j][0]",
"- for k in range(1, m + 1):",
"- rem[k - 1] += books[j][k]",
"- done = True",
"- for j in range(m):",
"- if rem[j] < x:",
"- done = False",
"- if done:",
"- pay = min(pay, tmp_pay)",
"- if pay == float(\"inf\"):",
"- print((-1))",
"- else:",
"- print(pay)",
"+ pay += c_seq[j]",
"+ for k in range(m):",
"+ skill[k] += a_seq[j][k]",
"+ ok = True",
"+ for y in skill:",
"+ if x > y:",
"+ ok = False",
"+ if ok:",
"+ ans = min(ans, pay)",
"+ print((ans if ans < float(\"inf\") else -1))"
]
| false | 0.03335 | 0.037645 | 0.885905 | [
"s291864470",
"s128665884"
]
|
u118642796 | p03476 | python | s788219473 | s860281631 | 1,092 | 401 | 52,640 | 54,488 | Accepted | Accepted | 63.28 | prime = [True]*((10**5)+1)
prime[0]=False
prime[1]=False
for i in range(2,10**3):
if i*i>10**5:
break
if prime[i]:
for j in range(i,10**5):
if i*j>10**5:
break
prime[i*j]=False
prime2017 = [x for x in prime]
prime2017[2] = False
for i in range(3,(10**5)+1):
if prime[i]:
prime2017[i] = prime[(i+1)//2]
count = 0
csum = [0]*((10**5)+1)
for i in range((10**5)+1):
if prime2017[i]:
count+=1
csum[i]=count
N = int(eval(input()))
for _ in range(N):
l,r = list(map(int,input().split()))
print((csum[r]-csum[l-1]))
| import sys
import heapq
import bisect
mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])
def GCD(a,b):
while b!=0:
a,b = b,a%b
return a
def LCM(a,b):
return a * b // GCD(a,b)
def Eratosthenes(N):
r = [True]*(N+1)
r[0] = False
r[1] = False
i = 2
while i*i<=N:
if r[i]:
j = i
while i*j<=N:
r[i*j]=False
j+=1
i+=1
return(r)
def main():
prime = Eratosthenes(10**5)
prime_2017 = [False]*(10**5+1)
for i in range(3,10**5+1,2):
if prime[i]:
prime_2017[i] = prime[(i+1)//2]
cnt = [0]*(10**5+1)
nxt = 0
for i in range(1,10**5+1):
if prime_2017[i]:
nxt += 1
cnt[i] = nxt
Q = I()
for _ in range(Q):
l,r = LI()
print((cnt[r] - cnt[l-1]))
if __name__ == "__main__":
main()
| 30 | 59 | 580 | 1,148 | prime = [True] * ((10**5) + 1)
prime[0] = False
prime[1] = False
for i in range(2, 10**3):
if i * i > 10**5:
break
if prime[i]:
for j in range(i, 10**5):
if i * j > 10**5:
break
prime[i * j] = False
prime2017 = [x for x in prime]
prime2017[2] = False
for i in range(3, (10**5) + 1):
if prime[i]:
prime2017[i] = prime[(i + 1) // 2]
count = 0
csum = [0] * ((10**5) + 1)
for i in range((10**5) + 1):
if prime2017[i]:
count += 1
csum[i] = count
N = int(eval(input()))
for _ in range(N):
l, r = list(map(int, input().split()))
print((csum[r] - csum[l - 1]))
| import sys
import heapq
import bisect
mod = 10**9 + 7
dd = ((-1, 0), (1, 0), (0, -1), (0, 1))
def I():
return int(sys.stdin.readline())
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def S():
return sys.stdin.readline()[:-1]
def IR(n):
return [I() for _ in range(n)]
def GCD(a, b):
while b != 0:
a, b = b, a % b
return a
def LCM(a, b):
return a * b // GCD(a, b)
def Eratosthenes(N):
r = [True] * (N + 1)
r[0] = False
r[1] = False
i = 2
while i * i <= N:
if r[i]:
j = i
while i * j <= N:
r[i * j] = False
j += 1
i += 1
return r
def main():
prime = Eratosthenes(10**5)
prime_2017 = [False] * (10**5 + 1)
for i in range(3, 10**5 + 1, 2):
if prime[i]:
prime_2017[i] = prime[(i + 1) // 2]
cnt = [0] * (10**5 + 1)
nxt = 0
for i in range(1, 10**5 + 1):
if prime_2017[i]:
nxt += 1
cnt[i] = nxt
Q = I()
for _ in range(Q):
l, r = LI()
print((cnt[r] - cnt[l - 1]))
if __name__ == "__main__":
main()
| false | 49.152542 | [
"-prime = [True] * ((10**5) + 1)",
"-prime[0] = False",
"-prime[1] = False",
"-for i in range(2, 10**3):",
"- if i * i > 10**5:",
"- break",
"- if prime[i]:",
"- for j in range(i, 10**5):",
"- if i * j > 10**5:",
"- break",
"- prime[i * j] = False",
"-prime2017 = [x for x in prime]",
"-prime2017[2] = False",
"-for i in range(3, (10**5) + 1):",
"- if prime[i]:",
"- prime2017[i] = prime[(i + 1) // 2]",
"-count = 0",
"-csum = [0] * ((10**5) + 1)",
"-for i in range((10**5) + 1):",
"- if prime2017[i]:",
"- count += 1",
"- csum[i] = count",
"-N = int(eval(input()))",
"-for _ in range(N):",
"- l, r = list(map(int, input().split()))",
"- print((csum[r] - csum[l - 1]))",
"+import sys",
"+import heapq",
"+import bisect",
"+",
"+mod = 10**9 + 7",
"+dd = ((-1, 0), (1, 0), (0, -1), (0, 1))",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def LI():",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"+",
"+",
"+def S():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"+def IR(n):",
"+ return [I() for _ in range(n)]",
"+",
"+",
"+def GCD(a, b):",
"+ while b != 0:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+def LCM(a, b):",
"+ return a * b // GCD(a, b)",
"+",
"+",
"+def Eratosthenes(N):",
"+ r = [True] * (N + 1)",
"+ r[0] = False",
"+ r[1] = False",
"+ i = 2",
"+ while i * i <= N:",
"+ if r[i]:",
"+ j = i",
"+ while i * j <= N:",
"+ r[i * j] = False",
"+ j += 1",
"+ i += 1",
"+ return r",
"+",
"+",
"+def main():",
"+ prime = Eratosthenes(10**5)",
"+ prime_2017 = [False] * (10**5 + 1)",
"+ for i in range(3, 10**5 + 1, 2):",
"+ if prime[i]:",
"+ prime_2017[i] = prime[(i + 1) // 2]",
"+ cnt = [0] * (10**5 + 1)",
"+ nxt = 0",
"+ for i in range(1, 10**5 + 1):",
"+ if prime_2017[i]:",
"+ nxt += 1",
"+ cnt[i] = nxt",
"+ Q = I()",
"+ for _ in range(Q):",
"+ l, r = LI()",
"+ print((cnt[r] - cnt[l - 1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.126981 | 0.123754 | 1.026081 | [
"s788219473",
"s860281631"
]
|
u175034939 | p03167 | python | s352568912 | s793825862 | 1,443 | 272 | 43,712 | 53,488 | Accepted | Accepted | 81.15 | h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
MOD = 10**9+7
dp = [[0]*(w+1) for _ in range(h+1)]
dp[0][0] = 1
for i in range(h):
for j in range(w):
if i+1 < h and a[i+1][j] == '.':
dp[i+1][j] += dp[i][j]
if dp[i+1][j] >= MOD:
dp[i+1][j] %= MOD
if j+1 < w and a[i][j+1] == '.':
dp[i][j+1] += dp[i][j]
if dp[i][j+1] >= MOD:
dp[i][j+1] %= MOD
print((dp[h-1][w-1])) | h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
MOD = 10**9+7
dp = [[0]*(w) for _ in range(h)]
dp[0][0] = 1
for i in range(h):
for j in range(w):
if i+1 < h and a[i+1][j] == '.':
dp[i+1][j] += dp[i][j]
if dp[i+1][j] >= MOD:
dp[i+1][j] %= MOD
if j+1 < w and a[i][j+1] == '.':
dp[i][j+1] += dp[i][j]
if dp[i][j+1] >= MOD:
dp[i][j+1] %= MOD
print((dp[h-1][w-1])) | 17 | 17 | 495 | 491 | h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
MOD = 10**9 + 7
dp = [[0] * (w + 1) for _ in range(h + 1)]
dp[0][0] = 1
for i in range(h):
for j in range(w):
if i + 1 < h and a[i + 1][j] == ".":
dp[i + 1][j] += dp[i][j]
if dp[i + 1][j] >= MOD:
dp[i + 1][j] %= MOD
if j + 1 < w and a[i][j + 1] == ".":
dp[i][j + 1] += dp[i][j]
if dp[i][j + 1] >= MOD:
dp[i][j + 1] %= MOD
print((dp[h - 1][w - 1]))
| h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
MOD = 10**9 + 7
dp = [[0] * (w) for _ in range(h)]
dp[0][0] = 1
for i in range(h):
for j in range(w):
if i + 1 < h and a[i + 1][j] == ".":
dp[i + 1][j] += dp[i][j]
if dp[i + 1][j] >= MOD:
dp[i + 1][j] %= MOD
if j + 1 < w and a[i][j + 1] == ".":
dp[i][j + 1] += dp[i][j]
if dp[i][j + 1] >= MOD:
dp[i][j + 1] %= MOD
print((dp[h - 1][w - 1]))
| false | 0 | [
"-dp = [[0] * (w + 1) for _ in range(h + 1)]",
"+dp = [[0] * (w) for _ in range(h)]"
]
| false | 0.038403 | 0.046501 | 0.825852 | [
"s352568912",
"s793825862"
]
|
u197300773 | p03310 | python | s546325889 | s034917612 | 1,067 | 914 | 24,180 | 25,972 | Accepted | Accepted | 14.34 | from itertools import accumulate as acc
from bisect import bisect_left as bl
def ans(n):
tmp=0
for i in range(N):
tmp+=abs(a[i]-a[n-1])
return tmp
N=int(eval(input()))
a=list(map(int,input().split()))
a=list(acc(a))
ans=10**18
p=0
q=2
for j in range(1,N-2):
q=max(q,j+1)
while p<j-1 and abs(a[j]-a[p]*2)>abs(a[j]-a[p+1]*2):
p+=1
while q<N-2 and abs(a[j]+a[N-1]-a[q]*2)>abs(a[j]+a[N-1]-a[q+1]*2):
q+=1
P,Q,R,S=a[p], a[j]-a[p], a[q]-a[j], a[N-1]-a[q]
ans=min(ans, max(P,Q,R,S)-min(P,Q,R,S))
print(ans) | from itertools import accumulate as acc
from bisect import bisect_left as bl
def ans(n):
tmp=0
for i in range(N):
tmp+=abs(a[i]-a[n-1])
return tmp
N=int(eval(input()))
a=list(acc(list(map(int,input().split()))))
ans=a[-1]
p=0
q=2
for j in range(1,N-2):
q=max(q,j+1)
while p<j-1 and abs(a[j]-a[p]*2)>abs(a[j]-a[p+1]*2):
p+=1
while q<N-2 and abs(a[j]+a[N-1]-a[q]*2)>abs(a[j]+a[N-1]-a[q+1]*2):
q+=1
x=[ a[p], a[j]-a[p], a[q]-a[j], a[N-1]-a[q] ]
ans=min(ans, max(x)-min(x))
print(ans) | 28 | 27 | 582 | 556 | from itertools import accumulate as acc
from bisect import bisect_left as bl
def ans(n):
tmp = 0
for i in range(N):
tmp += abs(a[i] - a[n - 1])
return tmp
N = int(eval(input()))
a = list(map(int, input().split()))
a = list(acc(a))
ans = 10**18
p = 0
q = 2
for j in range(1, N - 2):
q = max(q, j + 1)
while p < j - 1 and abs(a[j] - a[p] * 2) > abs(a[j] - a[p + 1] * 2):
p += 1
while q < N - 2 and abs(a[j] + a[N - 1] - a[q] * 2) > abs(
a[j] + a[N - 1] - a[q + 1] * 2
):
q += 1
P, Q, R, S = a[p], a[j] - a[p], a[q] - a[j], a[N - 1] - a[q]
ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))
print(ans)
| from itertools import accumulate as acc
from bisect import bisect_left as bl
def ans(n):
tmp = 0
for i in range(N):
tmp += abs(a[i] - a[n - 1])
return tmp
N = int(eval(input()))
a = list(acc(list(map(int, input().split()))))
ans = a[-1]
p = 0
q = 2
for j in range(1, N - 2):
q = max(q, j + 1)
while p < j - 1 and abs(a[j] - a[p] * 2) > abs(a[j] - a[p + 1] * 2):
p += 1
while q < N - 2 and abs(a[j] + a[N - 1] - a[q] * 2) > abs(
a[j] + a[N - 1] - a[q + 1] * 2
):
q += 1
x = [a[p], a[j] - a[p], a[q] - a[j], a[N - 1] - a[q]]
ans = min(ans, max(x) - min(x))
print(ans)
| false | 3.571429 | [
"-a = list(map(int, input().split()))",
"-a = list(acc(a))",
"-ans = 10**18",
"+a = list(acc(list(map(int, input().split()))))",
"+ans = a[-1]",
"- P, Q, R, S = a[p], a[j] - a[p], a[q] - a[j], a[N - 1] - a[q]",
"- ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))",
"+ x = [a[p], a[j] - a[p], a[q] - a[j], a[N - 1] - a[q]]",
"+ ans = min(ans, max(x) - min(x))"
]
| false | 0.049251 | 0.119084 | 0.413585 | [
"s546325889",
"s034917612"
]
|
u623231048 | p02678 | python | s063564295 | s039185096 | 495 | 322 | 94,968 | 92,244 | Accepted | Accepted | 34.95 | from collections import deque
def main():
n,m = list(map(int,input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
edges[a-1].append(b-1)
edges[b-1].append(a-1)
q = deque([0])
ans = [-1]*n
ans[0] = 0
count = 1
while q:
l = q.popleft()
for i in edges[l]:
if ans[i] == -1:
ans[i] = l
count += 1
q.append(i)
if count == n:
break
if count == n:
print('Yes')
for i in ans[1:]:
print((i+1))
else:
print('No')
if __name__ == '__main__':
main()
| from collections import deque
import sys
input = sys.stdin.readline
def main():
n,m = list(map(int,input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
edges[a-1].append(b-1)
edges[b-1].append(a-1)
q = deque([0])
ans = [-1]*n
ans[0] = 0
count = 1
while q:
l = q.popleft()
for i in edges[l]:
if ans[i] == -1:
ans[i] = l
count += 1
q.append(i)
if count == n:
break
if count == n:
print('Yes')
for i in ans[1:]:
print((i+1))
else:
print('No')
if __name__ == '__main__':
main()
| 37 | 39 | 718 | 758 | from collections import deque
def main():
n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
q = deque([0])
ans = [-1] * n
ans[0] = 0
count = 1
while q:
l = q.popleft()
for i in edges[l]:
if ans[i] == -1:
ans[i] = l
count += 1
q.append(i)
if count == n:
break
if count == n:
print("Yes")
for i in ans[1:]:
print((i + 1))
else:
print("No")
if __name__ == "__main__":
main()
| from collections import deque
import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
q = deque([0])
ans = [-1] * n
ans[0] = 0
count = 1
while q:
l = q.popleft()
for i in edges[l]:
if ans[i] == -1:
ans[i] = l
count += 1
q.append(i)
if count == n:
break
if count == n:
print("Yes")
for i in ans[1:]:
print((i + 1))
else:
print("No")
if __name__ == "__main__":
main()
| false | 5.128205 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
]
| false | 0.038088 | 0.036437 | 1.045305 | [
"s063564295",
"s039185096"
]
|
u729133443 | p03298 | python | s489141011 | s816817998 | 2,974 | 1,382 | 125,760 | 174,460 | Accepted | Accepted | 53.53 | n=int(eval(input()))
s=list(eval(input()))
l=s[:n]
r=s[n:][::-1]
d={}
e={}
for i in range(1<<n):
s=t=u=v=''
for j in range(n):
if (i>>j)&1:
s+=l[j]
t+=r[j]
else:
u+=l[j]
v+=r[j]
d[(s,u)]=d.get((s,u),0)+1
e[(t,v)]=e.get((t,v),0)+1
a=0
for i in list(d.keys()):
a+=d[i]*e.get(i,0)
print(a) | n=int(eval(input()));s=eval(input());l=s[:n];r=s[n:][::-1];d={};e={}
for i in range(1<<n):
s=t=u=v=''
for j in range(n):
if i>>j&1:s+=l[j];t+=r[j]
else:u+=l[j];v+=r[j]
d[s,u]=d.get((s,u),0)+1
e[t,v]=e.get((t,v),0)+1
print((sum(d[i]*e.get(i,0)for i in list(d.keys())))) | 21 | 9 | 330 | 264 | n = int(eval(input()))
s = list(eval(input()))
l = s[:n]
r = s[n:][::-1]
d = {}
e = {}
for i in range(1 << n):
s = t = u = v = ""
for j in range(n):
if (i >> j) & 1:
s += l[j]
t += r[j]
else:
u += l[j]
v += r[j]
d[(s, u)] = d.get((s, u), 0) + 1
e[(t, v)] = e.get((t, v), 0) + 1
a = 0
for i in list(d.keys()):
a += d[i] * e.get(i, 0)
print(a)
| n = int(eval(input()))
s = eval(input())
l = s[:n]
r = s[n:][::-1]
d = {}
e = {}
for i in range(1 << n):
s = t = u = v = ""
for j in range(n):
if i >> j & 1:
s += l[j]
t += r[j]
else:
u += l[j]
v += r[j]
d[s, u] = d.get((s, u), 0) + 1
e[t, v] = e.get((t, v), 0) + 1
print((sum(d[i] * e.get(i, 0) for i in list(d.keys()))))
| false | 57.142857 | [
"-s = list(eval(input()))",
"+s = eval(input())",
"- if (i >> j) & 1:",
"+ if i >> j & 1:",
"- d[(s, u)] = d.get((s, u), 0) + 1",
"- e[(t, v)] = e.get((t, v), 0) + 1",
"-a = 0",
"-for i in list(d.keys()):",
"- a += d[i] * e.get(i, 0)",
"-print(a)",
"+ d[s, u] = d.get((s, u), 0) + 1",
"+ e[t, v] = e.get((t, v), 0) + 1",
"+print((sum(d[i] * e.get(i, 0) for i in list(d.keys()))))"
]
| false | 0.037287 | 0.035641 | 1.046177 | [
"s489141011",
"s816817998"
]
|
u337626942 | p03037 | python | s742099959 | s895552121 | 360 | 239 | 27,328 | 22,552 | Accepted | Accepted | 33.61 | N, M=list(map(int, input().split()))
w=[list(map(int, input().split())) for i in range(M)]
R_min=10**6
L_max=0
cnt=0
for i in range(M):
if w[i][1]<=R_min:
R_min=w[i][1]
for i in range(M):
if w[i][0]>=L_max:
L_max=w[i][0]
for num in range(1, N+1):
if L_max<= num <= R_min:
cnt+=1
print(cnt) | n, m=list(map(int, input().split()))
gate=[]
for i in range(m):
L, R=list(map(int, input().split()))
gate.append((L, R))
L_max=0
R_min=10**6
for i in range(m):
if gate[i][0]>L_max:
L_max=gate[i][0]
for i in range(m):
if gate[i][1]<R_min:
R_min=gate[i][1]
ans=0
for i in range(1, n+1):
if L_max<=i<=R_min:
ans+=1
print(ans) | 18 | 25 | 339 | 385 | N, M = list(map(int, input().split()))
w = [list(map(int, input().split())) for i in range(M)]
R_min = 10**6
L_max = 0
cnt = 0
for i in range(M):
if w[i][1] <= R_min:
R_min = w[i][1]
for i in range(M):
if w[i][0] >= L_max:
L_max = w[i][0]
for num in range(1, N + 1):
if L_max <= num <= R_min:
cnt += 1
print(cnt)
| n, m = list(map(int, input().split()))
gate = []
for i in range(m):
L, R = list(map(int, input().split()))
gate.append((L, R))
L_max = 0
R_min = 10**6
for i in range(m):
if gate[i][0] > L_max:
L_max = gate[i][0]
for i in range(m):
if gate[i][1] < R_min:
R_min = gate[i][1]
ans = 0
for i in range(1, n + 1):
if L_max <= i <= R_min:
ans += 1
print(ans)
| false | 28 | [
"-N, M = list(map(int, input().split()))",
"-w = [list(map(int, input().split())) for i in range(M)]",
"+n, m = list(map(int, input().split()))",
"+gate = []",
"+for i in range(m):",
"+ L, R = list(map(int, input().split()))",
"+ gate.append((L, R))",
"+L_max = 0",
"-L_max = 0",
"-cnt = 0",
"-for i in range(M):",
"- if w[i][1] <= R_min:",
"- R_min = w[i][1]",
"-for i in range(M):",
"- if w[i][0] >= L_max:",
"- L_max = w[i][0]",
"-for num in range(1, N + 1):",
"- if L_max <= num <= R_min:",
"- cnt += 1",
"-print(cnt)",
"+for i in range(m):",
"+ if gate[i][0] > L_max:",
"+ L_max = gate[i][0]",
"+for i in range(m):",
"+ if gate[i][1] < R_min:",
"+ R_min = gate[i][1]",
"+ans = 0",
"+for i in range(1, n + 1):",
"+ if L_max <= i <= R_min:",
"+ ans += 1",
"+print(ans)"
]
| false | 0.042612 | 0.049236 | 0.865458 | [
"s742099959",
"s895552121"
]
|
u098012509 | p03645 | python | s522681703 | s473461411 | 686 | 450 | 60,508 | 45,116 | Accepted | Accepted | 34.4 | import sys
import collections
input = sys.stdin.readline
def main():
N, M = [int(x) for x in input().split()]
ab = [[] for j in range(N + 1)]
distance = [0] * (N + 1)
for _ in range(M):
a, b = [int(x) for x in input().split()]
ab[a].append(b)
ab[b].append(a)
q = collections.deque()
q.append([1, 0])
visited = set()
visited.add(1)
while q:
c, d = q.popleft()
for n in ab[c]:
if n not in visited:
visited.add(n)
q.append([n, d + 1])
distance[n] = d + 1
if distance[N] != 0 and distance[N] <=2:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
if __name__ == '__main__':
main()
| N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]
x = set()
for a, b in AB:
if a == 1:
x.add(b)
if b == 1:
x.add(a)
f = False
for a, b in AB:
if (a in x and b == N) or (b in x and a == N):
f = True
if f:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| 46 | 21 | 810 | 367 | import sys
import collections
input = sys.stdin.readline
def main():
N, M = [int(x) for x in input().split()]
ab = [[] for j in range(N + 1)]
distance = [0] * (N + 1)
for _ in range(M):
a, b = [int(x) for x in input().split()]
ab[a].append(b)
ab[b].append(a)
q = collections.deque()
q.append([1, 0])
visited = set()
visited.add(1)
while q:
c, d = q.popleft()
for n in ab[c]:
if n not in visited:
visited.add(n)
q.append([n, d + 1])
distance[n] = d + 1
if distance[N] != 0 and distance[N] <= 2:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
if __name__ == "__main__":
main()
| N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]
x = set()
for a, b in AB:
if a == 1:
x.add(b)
if b == 1:
x.add(a)
f = False
for a, b in AB:
if (a in x and b == N) or (b in x and a == N):
f = True
if f:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| false | 54.347826 | [
"-import sys",
"-import collections",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def main():",
"- N, M = [int(x) for x in input().split()]",
"- ab = [[] for j in range(N + 1)]",
"- distance = [0] * (N + 1)",
"- for _ in range(M):",
"- a, b = [int(x) for x in input().split()]",
"- ab[a].append(b)",
"- ab[b].append(a)",
"- q = collections.deque()",
"- q.append([1, 0])",
"- visited = set()",
"- visited.add(1)",
"- while q:",
"- c, d = q.popleft()",
"- for n in ab[c]:",
"- if n not in visited:",
"- visited.add(n)",
"- q.append([n, d + 1])",
"- distance[n] = d + 1",
"- if distance[N] != 0 and distance[N] <= 2:",
"- print(\"POSSIBLE\")",
"- else:",
"- print(\"IMPOSSIBLE\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N, M = [int(x) for x in input().split()]",
"+AB = [[int(x) for x in input().split()] for _ in range(M)]",
"+x = set()",
"+for a, b in AB:",
"+ if a == 1:",
"+ x.add(b)",
"+ if b == 1:",
"+ x.add(a)",
"+f = False",
"+for a, b in AB:",
"+ if (a in x and b == N) or (b in x and a == N):",
"+ f = True",
"+if f:",
"+ print(\"POSSIBLE\")",
"+else:",
"+ print(\"IMPOSSIBLE\")"
]
| false | 0.048613 | 0.047148 | 1.031079 | [
"s522681703",
"s473461411"
]
|
u312025627 | p02572 | python | s108268129 | s276293204 | 135 | 120 | 103,700 | 105,192 | Accepted | Accepted | 11.11 | MOD = 10**9 + 7
def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
from itertools import accumulate
S = list(accumulate([0] + A))
ans = 0
for i in range(N-1):
ans += A[i] * (S[N] - S[i+1])
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| MOD = 10**9 + 7
def main():
_ = int(eval(input()))
A = [int(i) for i in input().split()]
ans = (sum(A)**2) % MOD - (sum(pow(a, 2, MOD) for a in A)) % MOD
ans *= pow(2, MOD-2, MOD)
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| 17 | 15 | 329 | 277 | MOD = 10**9 + 7
def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
from itertools import accumulate
S = list(accumulate([0] + A))
ans = 0
for i in range(N - 1):
ans += A[i] * (S[N] - S[i + 1])
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| MOD = 10**9 + 7
def main():
_ = int(eval(input()))
A = [int(i) for i in input().split()]
ans = (sum(A) ** 2) % MOD - (sum(pow(a, 2, MOD) for a in A)) % MOD
ans *= pow(2, MOD - 2, MOD)
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| false | 11.764706 | [
"- N = int(eval(input()))",
"+ _ = int(eval(input()))",
"- from itertools import accumulate",
"-",
"- S = list(accumulate([0] + A))",
"- ans = 0",
"- for i in range(N - 1):",
"- ans += A[i] * (S[N] - S[i + 1])",
"- ans %= MOD",
"+ ans = (sum(A) ** 2) % MOD - (sum(pow(a, 2, MOD) for a in A)) % MOD",
"+ ans *= pow(2, MOD - 2, MOD)",
"+ ans %= MOD"
]
| false | 0.008074 | 0.037093 | 0.217683 | [
"s108268129",
"s276293204"
]
|
u179169725 | p03720 | python | s813265236 | s549636757 | 31 | 26 | 10,124 | 10,180 | Accepted | Accepted | 16.13 | mycode = r'''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython ใฏCใฎๅใซๅฏพใใ้ค็ฎใปๅฐไฝๆผ็ฎๅญใซ้ขใใไปๆงใใ(่ขซๆผ็ฎๅญ้ใฎ็ฌฆๅทใ็ฐใชใๅ ดๅใฎๆฏใ่ใใ็ฐใชใ)Pythonใฎintใฎไปๆงใซๅใใใ้ค็ฎใใๆฐใ0ใฎๅ ดๅใซZeroDivisionErrorใ้ๅบใใพใใใใฎๅฆ็ใ่กใใใใจใ้ๅบฆใซ 35% ใใใใฎใใใซใใฃใ็ใใพใใ True:ใใงใใฏใ่กใใพใใใ
ctypedef long long LL
from libc.stdio cimport scanf
from libcpp.vector cimport vector as vec
ctypedef vec[vec[LL]] Graph
cdef LL i,j,k,_
cdef LL N,M
scanf('%lld %lld',&N,&M)
cdef Graph graph=Graph(N)
cdef LL a,b
# ใใฎๅ้กใใใใฆใฐใฉใใฎๆง้ ใๆใคใใจใง่งฃใ
for _ in range(M):
scanf('%lld %lld',&a, &b)
graph[a-1].push_back(b-1)
graph[b-1].push_back(a-1)
cdef vec[LL] ans
for i in range(N):
ans.push_back(graph[i].size())
print(*ans, sep='\n')
'''
import sys
import os
if sys.argv[-1] == 'ONLINE_JUDGE': # ใณใณใใคใซๆ
with open('mycode.pyx', 'w') as f:
f.write(mycode)
os.system('cythonize -i -3 -b mycode.pyx')
import mycode
|
import sys
import os
if sys.argv[-1] == 'ONLINE_JUDGE': # ใณใณใใคใซๆ
mycode = r'''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython ใฏCใฎๅใซๅฏพใใ้ค็ฎใปๅฐไฝๆผ็ฎๅญใซ้ขใใไปๆงใใ(่ขซๆผ็ฎๅญ้ใฎ็ฌฆๅทใ็ฐใชใๅ ดๅใฎๆฏใ่ใใ็ฐใชใ)Pythonใฎintใฎไปๆงใซๅใใใ้ค็ฎใใๆฐใ0ใฎๅ ดๅใซZeroDivisionErrorใ้ๅบใใพใใใใฎๅฆ็ใ่กใใใใจใ้ๅบฆใซ 35% ใใใใฎใใใซใใฃใ็ใใพใใ True:ใใงใใฏใ่กใใพใใใ
ctypedef long long LL
from libc.stdio cimport scanf
from libcpp.vector cimport vector as vec
ctypedef vec[vec[LL]] Graph
cdef LL i,j,k,_
cdef LL N,M
scanf('%lld %lld',&N,&M)
cdef Graph graph=Graph(N)
cdef LL a,b
# ใใฎๅ้กใใใใฆใฐใฉใใฎๆง้ ใๆใคใใจใง่งฃใ
for _ in range(M):
scanf('%lld %lld',&a, &b)
graph[a-1].push_back(b-1)
graph[b-1].push_back(a-1)
cdef vec[LL] ans
for i in range(N):
ans.push_back(graph[i].size())
print(*ans, sep='\n')
'''
with open('mycode.pyx', 'w') as f:
f.write(mycode)
os.system('cythonize -i -3 -b mycode.pyx')
import mycode
| 42 | 43 | 983 | 989 | mycode = r"""
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython ใฏCใฎๅใซๅฏพใใ้ค็ฎใปๅฐไฝๆผ็ฎๅญใซ้ขใใไปๆงใใ(่ขซๆผ็ฎๅญ้ใฎ็ฌฆๅทใ็ฐใชใๅ ดๅใฎๆฏใ่ใใ็ฐใชใ)Pythonใฎintใฎไปๆงใซๅใใใ้ค็ฎใใๆฐใ0ใฎๅ ดๅใซZeroDivisionErrorใ้ๅบใใพใใใใฎๅฆ็ใ่กใใใใจใ้ๅบฆใซ 35% ใใใใฎใใใซใใฃใ็ใใพใใ True:ใใงใใฏใ่กใใพใใใ
ctypedef long long LL
from libc.stdio cimport scanf
from libcpp.vector cimport vector as vec
ctypedef vec[vec[LL]] Graph
cdef LL i,j,k,_
cdef LL N,M
scanf('%lld %lld',&N,&M)
cdef Graph graph=Graph(N)
cdef LL a,b
# ใใฎๅ้กใใใใฆใฐใฉใใฎๆง้ ใๆใคใใจใง่งฃใ
for _ in range(M):
scanf('%lld %lld',&a, &b)
graph[a-1].push_back(b-1)
graph[b-1].push_back(a-1)
cdef vec[LL] ans
for i in range(N):
ans.push_back(graph[i].size())
print(*ans, sep='\n')
"""
import sys
import os
if sys.argv[-1] == "ONLINE_JUDGE": # ใณใณใใคใซๆ
with open("mycode.pyx", "w") as f:
f.write(mycode)
os.system("cythonize -i -3 -b mycode.pyx")
import mycode
| import sys
import os
if sys.argv[-1] == "ONLINE_JUDGE": # ใณใณใใคใซๆ
mycode = r"""
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython ใฏCใฎๅใซๅฏพใใ้ค็ฎใปๅฐไฝๆผ็ฎๅญใซ้ขใใไปๆงใใ(่ขซๆผ็ฎๅญ้ใฎ็ฌฆๅทใ็ฐใชใๅ ดๅใฎๆฏใ่ใใ็ฐใชใ)Pythonใฎintใฎไปๆงใซๅใใใ้ค็ฎใใๆฐใ0ใฎๅ ดๅใซZeroDivisionErrorใ้ๅบใใพใใใใฎๅฆ็ใ่กใใใใจใ้ๅบฆใซ 35% ใใใใฎใใใซใใฃใ็ใใพใใ True:ใใงใใฏใ่กใใพใใใ
ctypedef long long LL
from libc.stdio cimport scanf
from libcpp.vector cimport vector as vec
ctypedef vec[vec[LL]] Graph
cdef LL i,j,k,_
cdef LL N,M
scanf('%lld %lld',&N,&M)
cdef Graph graph=Graph(N)
cdef LL a,b
# ใใฎๅ้กใใใใฆใฐใฉใใฎๆง้ ใๆใคใใจใง่งฃใ
for _ in range(M):
scanf('%lld %lld',&a, &b)
graph[a-1].push_back(b-1)
graph[b-1].push_back(a-1)
cdef vec[LL] ans
for i in range(N):
ans.push_back(graph[i].size())
print(*ans, sep='\n')
"""
with open("mycode.pyx", "w") as f:
f.write(mycode)
os.system("cythonize -i -3 -b mycode.pyx")
import mycode
| false | 2.325581 | [
"-mycode = r\"\"\"",
"+import sys",
"+import os",
"+",
"+if sys.argv[-1] == \"ONLINE_JUDGE\": # ใณใณใใคใซๆ",
"+ mycode = r\"\"\"",
"-import sys",
"-import os",
"-",
"-if sys.argv[-1] == \"ONLINE_JUDGE\": # ใณใณใใคใซๆ"
]
| false | 0.041285 | 0.042342 | 0.975054 | [
"s813265236",
"s549636757"
]
|
u581187895 | p02821 | python | s582262950 | s380847390 | 992 | 835 | 21,288 | 21,036 | Accepted | Accepted | 15.83 |
from bisect import bisect_left, bisect_right
from itertools import accumulate
def resolve():
def shake_cnt(x):
cnt = 0
pos = 0
for i in range(N):
pos = bisect_left(A, x - A[i])
cnt += N - pos
return cnt < M # XไปฅไธใฎๅใMๅๆชๆบใใฉใใ
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# ็ตไบๆใซngใซX-1,okใซXใๅ
ฅใฃใฆใใใ
ng = 0
ok = 10 ** 6
while abs(ok - ng) > 1:
mid = (ok + ng)//2
if shake_cnt(mid):
ok = mid
else:
ng = mid
acc = [0] + list(accumulate(A))
ans = 0
for i in range(N):
pos = bisect_right(A, ng - A[i])
cnt = N - pos
ans += cnt * A[i] + (acc[N] - acc[pos])
M -= cnt
ans += M * ng
print(ans)
if __name__ == "__main__":
resolve()
|
from bisect import bisect_left
from itertools import accumulate
def resolve():
def getCount(x):
count = 0
for Ai in A:
idx = bisect_left(A, x - Ai)
count += N - idx
return count >= M
N, M = list(map(int, input().split()))
A = sorted(map(int, input().split()))
A_r = A[::-1]
B = [0] + list(accumulate(A_r))
MIN = 0
MAX = 2 * 10 ** 5 + 1
while MAX - MIN > 1:
MID = (MIN + MAX) // 2
if getCount(MID):
MIN = MID
else:
MAX = MID
ans = 0
count = 0
for Ai in A_r:
idx = bisect_left(A, MIN - Ai)
ans += Ai * (N - idx) + B[N - idx]
count += N - idx
print((ans - (count - M) * MIN))
if __name__ == "__main__":
resolve()
| 39 | 38 | 886 | 819 | from bisect import bisect_left, bisect_right
from itertools import accumulate
def resolve():
def shake_cnt(x):
cnt = 0
pos = 0
for i in range(N):
pos = bisect_left(A, x - A[i])
cnt += N - pos
return cnt < M # XไปฅไธใฎๅใMๅๆชๆบใใฉใใ
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# ็ตไบๆใซngใซX-1,okใซXใๅ
ฅใฃใฆใใใ
ng = 0
ok = 10**6
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if shake_cnt(mid):
ok = mid
else:
ng = mid
acc = [0] + list(accumulate(A))
ans = 0
for i in range(N):
pos = bisect_right(A, ng - A[i])
cnt = N - pos
ans += cnt * A[i] + (acc[N] - acc[pos])
M -= cnt
ans += M * ng
print(ans)
if __name__ == "__main__":
resolve()
| from bisect import bisect_left
from itertools import accumulate
def resolve():
def getCount(x):
count = 0
for Ai in A:
idx = bisect_left(A, x - Ai)
count += N - idx
return count >= M
N, M = list(map(int, input().split()))
A = sorted(map(int, input().split()))
A_r = A[::-1]
B = [0] + list(accumulate(A_r))
MIN = 0
MAX = 2 * 10**5 + 1
while MAX - MIN > 1:
MID = (MIN + MAX) // 2
if getCount(MID):
MIN = MID
else:
MAX = MID
ans = 0
count = 0
for Ai in A_r:
idx = bisect_left(A, MIN - Ai)
ans += Ai * (N - idx) + B[N - idx]
count += N - idx
print((ans - (count - M) * MIN))
if __name__ == "__main__":
resolve()
| false | 2.564103 | [
"-from bisect import bisect_left, bisect_right",
"+from bisect import bisect_left",
"- def shake_cnt(x):",
"- cnt = 0",
"- pos = 0",
"- for i in range(N):",
"- pos = bisect_left(A, x - A[i])",
"- cnt += N - pos",
"- return cnt < M # XไปฅไธใฎๅใMๅๆชๆบใใฉใใ",
"+ def getCount(x):",
"+ count = 0",
"+ for Ai in A:",
"+ idx = bisect_left(A, x - Ai)",
"+ count += N - idx",
"+ return count >= M",
"- A = list(map(int, input().split()))",
"- A.sort()",
"- # ็ตไบๆใซngใซX-1,okใซXใๅ
ฅใฃใฆใใใ",
"- ng = 0",
"- ok = 10**6",
"- while abs(ok - ng) > 1:",
"- mid = (ok + ng) // 2",
"- if shake_cnt(mid):",
"- ok = mid",
"+ A = sorted(map(int, input().split()))",
"+ A_r = A[::-1]",
"+ B = [0] + list(accumulate(A_r))",
"+ MIN = 0",
"+ MAX = 2 * 10**5 + 1",
"+ while MAX - MIN > 1:",
"+ MID = (MIN + MAX) // 2",
"+ if getCount(MID):",
"+ MIN = MID",
"- ng = mid",
"- acc = [0] + list(accumulate(A))",
"+ MAX = MID",
"- for i in range(N):",
"- pos = bisect_right(A, ng - A[i])",
"- cnt = N - pos",
"- ans += cnt * A[i] + (acc[N] - acc[pos])",
"- M -= cnt",
"- ans += M * ng",
"- print(ans)",
"+ count = 0",
"+ for Ai in A_r:",
"+ idx = bisect_left(A, MIN - Ai)",
"+ ans += Ai * (N - idx) + B[N - idx]",
"+ count += N - idx",
"+ print((ans - (count - M) * MIN))"
]
| false | 0.109652 | 0.079008 | 1.387857 | [
"s582262950",
"s380847390"
]
|
u350064373 | p02269 | python | s156177010 | s479148148 | 4,200 | 3,070 | 37,372 | 323,088 | Accepted | Accepted | 26.9 | dic = {}
for s in range(int(eval(input()))):
i = input().split()
if i[0] == "insert":
dic[i[1]] = None
else:
print(("yes" if i[1] in dic else "no")) | dic = {}
line = []
for i in range(int(eval(input()))):
line.append(input().split())
for i in line:
if i[0][0] == "i":
dic[i[1]] = None
else:
print(("yes" if i[1] in dic else "no")) | 7 | 9 | 174 | 208 | dic = {}
for s in range(int(eval(input()))):
i = input().split()
if i[0] == "insert":
dic[i[1]] = None
else:
print(("yes" if i[1] in dic else "no"))
| dic = {}
line = []
for i in range(int(eval(input()))):
line.append(input().split())
for i in line:
if i[0][0] == "i":
dic[i[1]] = None
else:
print(("yes" if i[1] in dic else "no"))
| false | 22.222222 | [
"-for s in range(int(eval(input()))):",
"- i = input().split()",
"- if i[0] == \"insert\":",
"+line = []",
"+for i in range(int(eval(input()))):",
"+ line.append(input().split())",
"+for i in line:",
"+ if i[0][0] == \"i\":"
]
| false | 0.036932 | 0.036796 | 1.00369 | [
"s156177010",
"s479148148"
]
|
u962718741 | p03681 | python | s242953080 | s879048683 | 263 | 37 | 10,696 | 9,204 | Accepted | Accepted | 85.93 | import math
def main():
N, M = list(map(int, input().split()))
mod = 10 ** 9 + 7
if abs(N - M) > 1:
ans = 0
elif N - M == 1:
ans = (math.factorial(M)**2 * N) % mod
elif N - M == -1:
ans = (math.factorial(N)**2 * M) % mod
else:
ans = (math.factorial(N)**2 * 2) % mod
print(ans)
if __name__ == "__main__":
main()
| def factorial(n, mod=10**9 + 7):
a = 1
for i in range(1, n + 1):
a = a * i % mod
return a
def main():
N, M = list(map(int, input().split()))
mod = 10 ** 9 + 7
if abs(N - M) > 1:
ans = 0
elif abs(N - M) == 1:
ans = (factorial(min(N, M))**2 * max(N, M)) % mod
else:
ans = (factorial(N)**2 * 2) % mod
print(ans)
if __name__ == "__main__":
main()
| 20 | 22 | 393 | 435 | import math
def main():
N, M = list(map(int, input().split()))
mod = 10**9 + 7
if abs(N - M) > 1:
ans = 0
elif N - M == 1:
ans = (math.factorial(M) ** 2 * N) % mod
elif N - M == -1:
ans = (math.factorial(N) ** 2 * M) % mod
else:
ans = (math.factorial(N) ** 2 * 2) % mod
print(ans)
if __name__ == "__main__":
main()
| def factorial(n, mod=10**9 + 7):
a = 1
for i in range(1, n + 1):
a = a * i % mod
return a
def main():
N, M = list(map(int, input().split()))
mod = 10**9 + 7
if abs(N - M) > 1:
ans = 0
elif abs(N - M) == 1:
ans = (factorial(min(N, M)) ** 2 * max(N, M)) % mod
else:
ans = (factorial(N) ** 2 * 2) % mod
print(ans)
if __name__ == "__main__":
main()
| false | 9.090909 | [
"-import math",
"+def factorial(n, mod=10**9 + 7):",
"+ a = 1",
"+ for i in range(1, n + 1):",
"+ a = a * i % mod",
"+ return a",
"- elif N - M == 1:",
"- ans = (math.factorial(M) ** 2 * N) % mod",
"- elif N - M == -1:",
"- ans = (math.factorial(N) ** 2 * M) % mod",
"+ elif abs(N - M) == 1:",
"+ ans = (factorial(min(N, M)) ** 2 * max(N, M)) % mod",
"- ans = (math.factorial(N) ** 2 * 2) % mod",
"+ ans = (factorial(N) ** 2 * 2) % mod"
]
| false | 0.040105 | 0.075921 | 0.528246 | [
"s242953080",
"s879048683"
]
|
u389910364 | p03372 | python | s393729114 | s036403559 | 1,588 | 1,072 | 45,156 | 45,152 | Accepted | Accepted | 32.49 | from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
sys.setrecursionlimit(10000)
INF = float('inf')
def cummax(li, first=-float('inf')):
"""
็ดฏ็ฉ max
:param collections.Iterable li:
:param float first:
:return:
"""
cm = first
ret = []
for v in li:
cm = max(v, cm)
ret.append(cm)
return ret
N, C = list(map(int, input().split()))
X, V = list(zip(*[list(map(int, input().split())) for _ in range(N)]))
X = np.array(X)
V = np.array(V)
# cs1[i]: ๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs1 = V.cumsum() - X
# ็ดฏ็ฉ max
cm1 = np.array(cummax(cs1, first=0))
# cs2[i]: ๅๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs2 = V[::-1].cumsum() - (C - X)[::-1]
# ็ดฏ็ฉ max
cm2 = np.array(cummax(cs2, first=0))
cs2 = cs2[::-1]
cm2 = cm2[::-1]
ans = max(cm1.max(), cm2.max())
# ๆ่จๅใใซ X[L] ใพใง่กใฃใฆใๆใ่ฟใใฆๅๆ่จๅใใซ X[r] ใพใง่กใ
r = 0
for L in range(len(X)):
while r < len(X) and X[r] < X[L] * 2:
r += 1
if r < len(X):
ans = max(ans, cm1[L] + cm2[r] - X[L])
else:
break
# ๅๆ่จๅใใๅ
L = len(X) - 1
for r in reversed(list(range(len(X)))):
while L >= 0 and X[L] > C - (C - X[r]) * 2:
L -= 1
if L >= 0:
ans = max(ans, cm2[r] + cm1[L] - (C - X[r]))
else:
break
print(ans)
| from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
sys.setrecursionlimit(10000)
INF = float('inf')
def cummax(li, first=-float('inf')):
"""
็ดฏ็ฉ max
:param collections.Iterable li:
:param float first:
:return:
"""
cm = first
ret = []
for v in li:
cm = max(v, cm)
ret.append(cm)
return ret
N, C = list(map(int, input().split()))
X, V = list(zip(*[list(map(int, input().split())) for _ in range(N)]))
X = np.array(X)
V = np.array(V)
# cs1[i]: ๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs1 = V.cumsum() - X
# ็ดฏ็ฉ max
cm1 = np.array(cummax(cs1, first=0))
# cs2[i]: ๅๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs2 = V[::-1].cumsum() - (C - X)[::-1]
# ็ดฏ็ฉ max
cm2 = np.array(cummax(cs2, first=0))
cs2 = cs2[::-1]
cm2 = cm2[::-1]
ans = max(cm1[-1], cm2[0])
# ๆ่จๅใใซ X[L] ใพใง่กใฃใฆๆใ่ฟใใใจใใฎๆๅคง
for L in range(len(X) - 1):
ans = max(ans, cm1[L] + cm2[L + 1] - X[L])
# ๅๆ่จๅใใๅ
ใฎๅ ดๅ
for r in reversed(list(range(1, len(X)))):
ans = max(ans, cm2[r] + cm1[r - 1] - (C - X[r]))
print(ans)
| 69 | 57 | 1,460 | 1,218 | from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
def cummax(li, first=-float("inf")):
"""
็ดฏ็ฉ max
:param collections.Iterable li:
:param float first:
:return:
"""
cm = first
ret = []
for v in li:
cm = max(v, cm)
ret.append(cm)
return ret
N, C = list(map(int, input().split()))
X, V = list(zip(*[list(map(int, input().split())) for _ in range(N)]))
X = np.array(X)
V = np.array(V)
# cs1[i]: ๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs1 = V.cumsum() - X
# ็ดฏ็ฉ max
cm1 = np.array(cummax(cs1, first=0))
# cs2[i]: ๅๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs2 = V[::-1].cumsum() - (C - X)[::-1]
# ็ดฏ็ฉ max
cm2 = np.array(cummax(cs2, first=0))
cs2 = cs2[::-1]
cm2 = cm2[::-1]
ans = max(cm1.max(), cm2.max())
# ๆ่จๅใใซ X[L] ใพใง่กใฃใฆใๆใ่ฟใใฆๅๆ่จๅใใซ X[r] ใพใง่กใ
r = 0
for L in range(len(X)):
while r < len(X) and X[r] < X[L] * 2:
r += 1
if r < len(X):
ans = max(ans, cm1[L] + cm2[r] - X[L])
else:
break
# ๅๆ่จๅใใๅ
L = len(X) - 1
for r in reversed(list(range(len(X)))):
while L >= 0 and X[L] > C - (C - X[r]) * 2:
L -= 1
if L >= 0:
ans = max(ans, cm2[r] + cm1[L] - (C - X[r]))
else:
break
print(ans)
| from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
def cummax(li, first=-float("inf")):
"""
็ดฏ็ฉ max
:param collections.Iterable li:
:param float first:
:return:
"""
cm = first
ret = []
for v in li:
cm = max(v, cm)
ret.append(cm)
return ret
N, C = list(map(int, input().split()))
X, V = list(zip(*[list(map(int, input().split())) for _ in range(N)]))
X = np.array(X)
V = np.array(V)
# cs1[i]: ๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs1 = V.cumsum() - X
# ็ดฏ็ฉ max
cm1 = np.array(cummax(cs1, first=0))
# cs2[i]: ๅๆ่จๅใใซ i ็ช็ฎใพใง้ฃในใใจใใฎ็ดฏ่จใซใญใชใผ
cs2 = V[::-1].cumsum() - (C - X)[::-1]
# ็ดฏ็ฉ max
cm2 = np.array(cummax(cs2, first=0))
cs2 = cs2[::-1]
cm2 = cm2[::-1]
ans = max(cm1[-1], cm2[0])
# ๆ่จๅใใซ X[L] ใพใง่กใฃใฆๆใ่ฟใใใจใใฎๆๅคง
for L in range(len(X) - 1):
ans = max(ans, cm1[L] + cm2[L + 1] - X[L])
# ๅๆ่จๅใใๅ
ใฎๅ ดๅ
for r in reversed(list(range(1, len(X)))):
ans = max(ans, cm2[r] + cm1[r - 1] - (C - X[r]))
print(ans)
| false | 17.391304 | [
"-ans = max(cm1.max(), cm2.max())",
"-# ๆ่จๅใใซ X[L] ใพใง่กใฃใฆใๆใ่ฟใใฆๅๆ่จๅใใซ X[r] ใพใง่กใ",
"-r = 0",
"-for L in range(len(X)):",
"- while r < len(X) and X[r] < X[L] * 2:",
"- r += 1",
"- if r < len(X):",
"- ans = max(ans, cm1[L] + cm2[r] - X[L])",
"- else:",
"- break",
"-# ๅๆ่จๅใใๅ
",
"-L = len(X) - 1",
"-for r in reversed(list(range(len(X)))):",
"- while L >= 0 and X[L] > C - (C - X[r]) * 2:",
"- L -= 1",
"- if L >= 0:",
"- ans = max(ans, cm2[r] + cm1[L] - (C - X[r]))",
"- else:",
"- break",
"+ans = max(cm1[-1], cm2[0])",
"+# ๆ่จๅใใซ X[L] ใพใง่กใฃใฆๆใ่ฟใใใจใใฎๆๅคง",
"+for L in range(len(X) - 1):",
"+ ans = max(ans, cm1[L] + cm2[L + 1] - X[L])",
"+# ๅๆ่จๅใใๅ
ใฎๅ ดๅ",
"+for r in reversed(list(range(1, len(X)))):",
"+ ans = max(ans, cm2[r] + cm1[r - 1] - (C - X[r]))"
]
| false | 0.735663 | 0.185156 | 3.973201 | [
"s393729114",
"s036403559"
]
|
u225388820 | p02646 | python | s964322370 | s416770998 | 63 | 20 | 61,704 | 9,160 | Accepted | Accepted | 68.25 | a,v=list(map(int,input().split()))
b,w=list(map(int,input().split()))
t=int(eval(input()))
k=abs(a-b)
if w-v>0:
print("NO")
elif w==v:
if k==0:
print("YES")
else:
print("NO")
else:
if k<=(v-w)*t:
print("YES")
else:
print("NO") | a,v=list(map(int,input().split()))
b,w=list(map(int,input().split()))
t=int(eval(input()))
k=abs(a-b)
if 0<=k<=(v-w)*t and v!=w:
print("YES")
else:
print("NO") | 16 | 8 | 275 | 156 | a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(eval(input()))
k = abs(a - b)
if w - v > 0:
print("NO")
elif w == v:
if k == 0:
print("YES")
else:
print("NO")
else:
if k <= (v - w) * t:
print("YES")
else:
print("NO")
| a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(eval(input()))
k = abs(a - b)
if 0 <= k <= (v - w) * t and v != w:
print("YES")
else:
print("NO")
| false | 50 | [
"-if w - v > 0:",
"+if 0 <= k <= (v - w) * t and v != w:",
"+ print(\"YES\")",
"+else:",
"-elif w == v:",
"- if k == 0:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"-else:",
"- if k <= (v - w) * t:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")"
]
| false | 0.036197 | 0.05303 | 0.682571 | [
"s964322370",
"s416770998"
]
|
u480472958 | p03564 | python | s798955099 | s121983105 | 22 | 17 | 3,444 | 2,940 | Accepted | Accepted | 22.73 | n, k, ans = int(eval(input())), int(eval(input())), 1
for _ in range(n):
ans += min(ans, k)
print(ans) | n = int(eval(input()))
k = int(eval(input()))
ans = 1
for _ in range(n):
ans += min(ans, k)
print(ans) | 4 | 6 | 97 | 99 | n, k, ans = int(eval(input())), int(eval(input())), 1
for _ in range(n):
ans += min(ans, k)
print(ans)
| n = int(eval(input()))
k = int(eval(input()))
ans = 1
for _ in range(n):
ans += min(ans, k)
print(ans)
| false | 33.333333 | [
"-n, k, ans = int(eval(input())), int(eval(input())), 1",
"+n = int(eval(input()))",
"+k = int(eval(input()))",
"+ans = 1"
]
| false | 0.044351 | 0.084525 | 0.52471 | [
"s798955099",
"s121983105"
]
|
u753803401 | p03311 | python | s775398191 | s493626832 | 298 | 267 | 79,952 | 75,248 | Accepted | Accepted | 10.4 | import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
for i in range(n):
a[i] -= i + 1
a.sort()
t = a[n // 2]
mt = 0
for v in a:
mt += abs(t - v)
print(mt)
if __name__ == '__main__':
solve()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
for i in range(n):
a[i] -= i + 1
a.sort()
t = 0
for v in a:
t += abs(a[n // 2] - v)
print(t)
if __name__ == '__main__':
solve()
| 20 | 19 | 368 | 344 | import sys
def solve():
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input().rstrip("\n"))
a = list(map(int, input().rstrip("\n").split()))
for i in range(n):
a[i] -= i + 1
a.sort()
t = a[n // 2]
mt = 0
for v in a:
mt += abs(t - v)
print(mt)
if __name__ == "__main__":
solve()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
n = int(readline())
a = list(map(int, readline().split()))
for i in range(n):
a[i] -= i + 1
a.sort()
t = 0
for v in a:
t += abs(a[n // 2] - v)
print(t)
if __name__ == "__main__":
solve()
| false | 5 | [
"- input = sys.stdin.readline",
"+ readline = sys.stdin.buffer.readline",
"- n = int(input().rstrip(\"\\n\"))",
"- a = list(map(int, input().rstrip(\"\\n\").split()))",
"+ n = int(readline())",
"+ a = list(map(int, readline().split()))",
"- t = a[n // 2]",
"- mt = 0",
"+ t = 0",
"- mt += abs(t - v)",
"- print(mt)",
"+ t += abs(a[n // 2] - v)",
"+ print(t)"
]
| false | 0.044931 | 0.043878 | 1.023982 | [
"s775398191",
"s493626832"
]
|
u075012704 | p02781 | python | s083649713 | s282740790 | 1,384 | 18 | 42,092 | 3,064 | Accepted | Accepted | 98.7 | N = int(eval(input()))
N_digit = len(str(N))
K = int(eval(input()))
ans = 0
factorial = [1, 1]
for i in range(2, 101):
factorial.append(factorial[-1] * i)
def nCr(n, r):
if n - r < 0:
return 0
return factorial[n] // (factorial[r] * factorial[n - r])
if K == 1:
ans += 9 * (nCr(N_digit - 1, 1)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใฏ่ช็ฑ
ans += int(str(N)[0]) # 1ๆก็ฎใ่ใใใ2ๆก็ฎไปฅ้ใฏ0
elif K == 2:
ans += (9 ** 2) * (nCr(N_digit - 1, 2)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใใ่ช็ฑใซ2ใค
ans += (int(str(N)[0]) - 1) * 9 * (nCr(N_digit - 1, 1)) # 1ๆก็ฎใ0ใงใชใใใใคNไปฅไธใ็ขบๅฎใใใใใซๅบๅฎ
for d2_position in range(1, N_digit): # 2ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ
for d2_value in range(1, 10): # 2ใคใใฎ0ใงใชใๆฐใไฝใซใใใ
# ๆฐใใคใใ
S = ['0'] * N_digit
S[0] = str(N)[0]
S[d2_position] = d2_value
S = int(''.join(map(str, S)))
ans += (S <= N)
elif K == 3:
ans += (9 ** 3) * (nCr(N_digit - 1, 3)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใใ่ช็ฑใซ3ใค
ans += (int(str(N)[0]) - 1) * (9 ** 2) * (nCr(N_digit - 1, 2)) # 1ๆก็ฎใ0ใงใชใใใใคNไปฅไธใ็ขบๅฎใใใใใซๅบๅฎ
for d2_position in range(1, N_digit): # 2ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ
for d3_position in range(d2_position + 1, N_digit): # 3ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ
for d2_value in range(1, 10): # 2ใคใใฎ0ใงใชใๆฐใไฝใซใใใ
for d3_value in range(1, 10): # 3ใคใใฎ0ใงใชใๆฐใไฝใซใใใ
# ๆฐใไฝใ
S = ['0'] * N_digit
S[0] = str(N)[0]
S[d2_position] = str(d2_value)
S[d3_position] = str(d3_value)
S = int(''.join(S))
ans += (S <= N)
print(ans)
| N = eval(input())
N_digit = len(N)
K = int(eval(input()))
# dp[i][k] := i็ช็ฎใฟใฆใ0ใงใชใๆฐใkๅๅบ็พใใฆใใใจใใฎ้ใๆฐ
# dp0 := Nไปฅไธใงใใใใจใๆช็ขบๅฎ, dp1 := Nไปฅไธใงใใใใจใ็ขบๅฎ
dp0 = [[0] * (K + 1) for i in range(N_digit + 1)]
dp1 = [[0] * (K + 1) for i in range(N_digit + 1)]
dp0[0][0] = 1
for i, n in enumerate(N):
for k in range(K + 1):
if n == '0':
dp0[i + 1][k] += dp0[i][k]
dp1[i + 1][k] += dp1[i][k]
if k < K:
dp1[i + 1][k + 1] += 9 * dp1[i][k]
else:
if k < K:
dp0[i + 1][k + 1] += dp0[i][k]
dp1[i + 1][k + 1] += (int(n) - 1) * dp0[i][k]
dp1[i + 1][k + 1] += 9 * dp1[i][k]
dp1[i + 1][k] += dp0[i][k]
dp1[i + 1][k] += dp1[i][k]
print((dp0[-1][K] + dp1[-1][K]))
| 49 | 28 | 1,645 | 805 | N = int(eval(input()))
N_digit = len(str(N))
K = int(eval(input()))
ans = 0
factorial = [1, 1]
for i in range(2, 101):
factorial.append(factorial[-1] * i)
def nCr(n, r):
if n - r < 0:
return 0
return factorial[n] // (factorial[r] * factorial[n - r])
if K == 1:
ans += 9 * (nCr(N_digit - 1, 1)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใฏ่ช็ฑ
ans += int(str(N)[0]) # 1ๆก็ฎใ่ใใใ2ๆก็ฎไปฅ้ใฏ0
elif K == 2:
ans += (9**2) * (nCr(N_digit - 1, 2)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใใ่ช็ฑใซ2ใค
ans += (int(str(N)[0]) - 1) * 9 * (nCr(N_digit - 1, 1)) # 1ๆก็ฎใ0ใงใชใใใใคNไปฅไธใ็ขบๅฎใใใใใซๅบๅฎ
for d2_position in range(1, N_digit): # 2ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ
for d2_value in range(1, 10): # 2ใคใใฎ0ใงใชใๆฐใไฝใซใใใ
# ๆฐใใคใใ
S = ["0"] * N_digit
S[0] = str(N)[0]
S[d2_position] = d2_value
S = int("".join(map(str, S)))
ans += S <= N
elif K == 3:
ans += (9**3) * (nCr(N_digit - 1, 3)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใใ่ช็ฑใซ3ใค
ans += (
(int(str(N)[0]) - 1) * (9**2) * (nCr(N_digit - 1, 2))
) # 1ๆก็ฎใ0ใงใชใใใใคNไปฅไธใ็ขบๅฎใใใใใซๅบๅฎ
for d2_position in range(1, N_digit): # 2ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ
for d3_position in range(d2_position + 1, N_digit): # 3ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ
for d2_value in range(1, 10): # 2ใคใใฎ0ใงใชใๆฐใไฝใซใใใ
for d3_value in range(1, 10): # 3ใคใใฎ0ใงใชใๆฐใไฝใซใใใ
# ๆฐใไฝใ
S = ["0"] * N_digit
S[0] = str(N)[0]
S[d2_position] = str(d2_value)
S[d3_position] = str(d3_value)
S = int("".join(S))
ans += S <= N
print(ans)
| N = eval(input())
N_digit = len(N)
K = int(eval(input()))
# dp[i][k] := i็ช็ฎใฟใฆใ0ใงใชใๆฐใkๅๅบ็พใใฆใใใจใใฎ้ใๆฐ
# dp0 := Nไปฅไธใงใใใใจใๆช็ขบๅฎ, dp1 := Nไปฅไธใงใใใใจใ็ขบๅฎ
dp0 = [[0] * (K + 1) for i in range(N_digit + 1)]
dp1 = [[0] * (K + 1) for i in range(N_digit + 1)]
dp0[0][0] = 1
for i, n in enumerate(N):
for k in range(K + 1):
if n == "0":
dp0[i + 1][k] += dp0[i][k]
dp1[i + 1][k] += dp1[i][k]
if k < K:
dp1[i + 1][k + 1] += 9 * dp1[i][k]
else:
if k < K:
dp0[i + 1][k + 1] += dp0[i][k]
dp1[i + 1][k + 1] += (int(n) - 1) * dp0[i][k]
dp1[i + 1][k + 1] += 9 * dp1[i][k]
dp1[i + 1][k] += dp0[i][k]
dp1[i + 1][k] += dp1[i][k]
print((dp0[-1][K] + dp1[-1][K]))
| false | 42.857143 | [
"-N = int(eval(input()))",
"-N_digit = len(str(N))",
"+N = eval(input())",
"+N_digit = len(N)",
"-ans = 0",
"-factorial = [1, 1]",
"-for i in range(2, 101):",
"- factorial.append(factorial[-1] * i)",
"-",
"-",
"-def nCr(n, r):",
"- if n - r < 0:",
"- return 0",
"- return factorial[n] // (factorial[r] * factorial[n - r])",
"-",
"-",
"-if K == 1:",
"- ans += 9 * (nCr(N_digit - 1, 1)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใฏ่ช็ฑ",
"- ans += int(str(N)[0]) # 1ๆก็ฎใ่ใใใ2ๆก็ฎไปฅ้ใฏ0",
"-elif K == 2:",
"- ans += (9**2) * (nCr(N_digit - 1, 2)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใใ่ช็ฑใซ2ใค",
"- ans += (int(str(N)[0]) - 1) * 9 * (nCr(N_digit - 1, 1)) # 1ๆก็ฎใ0ใงใชใใใใคNไปฅไธใ็ขบๅฎใใใใใซๅบๅฎ",
"- for d2_position in range(1, N_digit): # 2ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ",
"- for d2_value in range(1, 10): # 2ใคใใฎ0ใงใชใๆฐใไฝใซใใใ",
"- # ๆฐใใคใใ",
"- S = [\"0\"] * N_digit",
"- S[0] = str(N)[0]",
"- S[d2_position] = d2_value",
"- S = int(\"\".join(map(str, S)))",
"- ans += S <= N",
"-elif K == 3:",
"- ans += (9**3) * (nCr(N_digit - 1, 3)) # 1ๆก็ฎใ0ใซๅบๅฎใ2ๆก็ฎไปฅ้ใใ่ช็ฑใซ3ใค",
"- ans += (",
"- (int(str(N)[0]) - 1) * (9**2) * (nCr(N_digit - 1, 2))",
"- ) # 1ๆก็ฎใ0ใงใชใใใใคNไปฅไธใ็ขบๅฎใใใใใซๅบๅฎ",
"- for d2_position in range(1, N_digit): # 2ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ",
"- for d3_position in range(d2_position + 1, N_digit): # 3ใคใใฎ0ใงใชใๆฐใใฉใใซ็ฝฎใใ",
"- for d2_value in range(1, 10): # 2ใคใใฎ0ใงใชใๆฐใไฝใซใใใ",
"- for d3_value in range(1, 10): # 3ใคใใฎ0ใงใชใๆฐใไฝใซใใใ",
"- # ๆฐใไฝใ",
"- S = [\"0\"] * N_digit",
"- S[0] = str(N)[0]",
"- S[d2_position] = str(d2_value)",
"- S[d3_position] = str(d3_value)",
"- S = int(\"\".join(S))",
"- ans += S <= N",
"-print(ans)",
"+# dp[i][k] := i็ช็ฎใฟใฆใ0ใงใชใๆฐใkๅๅบ็พใใฆใใใจใใฎ้ใๆฐ",
"+# dp0 := Nไปฅไธใงใใใใจใๆช็ขบๅฎ, dp1 := Nไปฅไธใงใใใใจใ็ขบๅฎ",
"+dp0 = [[0] * (K + 1) for i in range(N_digit + 1)]",
"+dp1 = [[0] * (K + 1) for i in range(N_digit + 1)]",
"+dp0[0][0] = 1",
"+for i, n in enumerate(N):",
"+ for k in range(K + 1):",
"+ if n == \"0\":",
"+ dp0[i + 1][k] += dp0[i][k]",
"+ dp1[i + 1][k] += dp1[i][k]",
"+ if k < K:",
"+ dp1[i + 1][k + 1] += 9 * dp1[i][k]",
"+ else:",
"+ if k < K:",
"+ dp0[i + 1][k + 1] += dp0[i][k]",
"+ dp1[i + 1][k + 1] += (int(n) - 1) * dp0[i][k]",
"+ dp1[i + 1][k + 1] += 9 * dp1[i][k]",
"+ dp1[i + 1][k] += dp0[i][k]",
"+ dp1[i + 1][k] += dp1[i][k]",
"+print((dp0[-1][K] + dp1[-1][K]))"
]
| false | 0.349851 | 0.042551 | 8.221902 | [
"s083649713",
"s282740790"
]
|
u970197315 | p03634 | python | s383681504 | s301134566 | 1,573 | 1,305 | 51,276 | 74,256 | Accepted | Accepted | 17.04 | n=int(eval(input()))
G=[[] for i in range(n)]
for i in range(n-1):
u,v,w=list(map(int,input().split()))
G[u-1].append([v-1,w])
G[v-1].append([u-1,w])
dist=[-1]*n
from collections import deque
Q,k=list(map(int,input().split()))
q=deque()
q.append(k-1)
dist[k-1]=0
while q:
cur=q.popleft()
for nx,nd in G[cur]:
if dist[nx]!=-1:continue
dist[nx]=dist[cur]+nd
q.append(nx)
for i in range(Q):
x,y=list(map(int,input().split()))
x-=1
y-=1
print((dist[x]+dist[y]))
| from heapq import heappop,heappush
def dijkstra(s,n,edge):
"""
ๅง็นsใใๅ้ ็นใธใฎๆ็ญ่ท้ขใ่ฟใ
Parameters
----------
s : int
่ฆ็นใจใใ้ ็น๏ผ0-indexed๏ผ
n : int
ใฐใฉใใฎ่ฆ็ด ๆฐ
eage:list
ใฐใฉใฐ
Returns
-------
dist ๏ผlist
ๅง็นsใใๅ้ ็นใธใฎๆ็ญ่ท้ข
"""
dist=[float("inf")]*n
dist[s]=0
used=[-1]*n
hq=[[dist[s],s]]
while hq:
d,cur=heappop(hq)
if dist[cur]<d:continue # ่ท้ขใๆๅฐใงใชใๅ ดๅใฏ้ฃใฐใ
for nx,nxd in edge[cur]:
if dist[cur]+nxd<dist[nx]:
dist[nx]=dist[cur]+nxd
used[nx]=cur
heappush(hq,[dist[cur]+nxd,nx])
return dist
n=int(eval(input()))
edge=[[] for _ in range(n)]
for _ in range(n-1):
a,b,c=list(map(int,input().split()))
a-=1
b-=1
edge[a].append((b,c))
edge[b].append((a,c))
q,k=list(map(int,input().split()))
xy=[list(map(int,input().split()))for _ in range(q)]
d=dijkstra(k-1,n,edge)
for x,y in xy:
print((d[x-1]+d[y-1]))
| 23 | 48 | 484 | 918 | n = int(eval(input()))
G = [[] for i in range(n)]
for i in range(n - 1):
u, v, w = list(map(int, input().split()))
G[u - 1].append([v - 1, w])
G[v - 1].append([u - 1, w])
dist = [-1] * n
from collections import deque
Q, k = list(map(int, input().split()))
q = deque()
q.append(k - 1)
dist[k - 1] = 0
while q:
cur = q.popleft()
for nx, nd in G[cur]:
if dist[nx] != -1:
continue
dist[nx] = dist[cur] + nd
q.append(nx)
for i in range(Q):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
print((dist[x] + dist[y]))
| from heapq import heappop, heappush
def dijkstra(s, n, edge):
"""
ๅง็นsใใๅ้ ็นใธใฎๆ็ญ่ท้ขใ่ฟใ
Parameters
----------
s : int
่ฆ็นใจใใ้ ็น๏ผ0-indexed๏ผ
n : int
ใฐใฉใใฎ่ฆ็ด ๆฐ
eage:list
ใฐใฉใฐ
Returns
-------
dist ๏ผlist
ๅง็นsใใๅ้ ็นใธใฎๆ็ญ่ท้ข
"""
dist = [float("inf")] * n
dist[s] = 0
used = [-1] * n
hq = [[dist[s], s]]
while hq:
d, cur = heappop(hq)
if dist[cur] < d:
continue # ่ท้ขใๆๅฐใงใชใๅ ดๅใฏ้ฃใฐใ
for nx, nxd in edge[cur]:
if dist[cur] + nxd < dist[nx]:
dist[nx] = dist[cur] + nxd
used[nx] = cur
heappush(hq, [dist[cur] + nxd, nx])
return dist
n = int(eval(input()))
edge = [[] for _ in range(n)]
for _ in range(n - 1):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
edge[a].append((b, c))
edge[b].append((a, c))
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
d = dijkstra(k - 1, n, edge)
for x, y in xy:
print((d[x - 1] + d[y - 1]))
| false | 52.083333 | [
"+from heapq import heappop, heappush",
"+",
"+",
"+def dijkstra(s, n, edge):",
"+ \"\"\"",
"+ ๅง็นsใใๅ้ ็นใธใฎๆ็ญ่ท้ขใ่ฟใ",
"+ Parameters",
"+ s : int",
"+ ่ฆ็นใจใใ้ ็น๏ผ0-indexed๏ผ",
"+ n : int",
"+ ใฐใฉใใฎ่ฆ็ด ๆฐ",
"+ eage:list",
"+ ใฐใฉใฐ",
"+ Returns",
"+ dist ๏ผlist",
"+ ๅง็นsใใๅ้ ็นใธใฎๆ็ญ่ท้ข",
"+ \"\"\"",
"+ dist = [float(\"inf\")] * n",
"+ dist[s] = 0",
"+ used = [-1] * n",
"+ hq = [[dist[s], s]]",
"+ while hq:",
"+ d, cur = heappop(hq)",
"+ if dist[cur] < d:",
"+ continue # ่ท้ขใๆๅฐใงใชใๅ ดๅใฏ้ฃใฐใ",
"+ for nx, nxd in edge[cur]:",
"+ if dist[cur] + nxd < dist[nx]:",
"+ dist[nx] = dist[cur] + nxd",
"+ used[nx] = cur",
"+ heappush(hq, [dist[cur] + nxd, nx])",
"+ return dist",
"+",
"+",
"-G = [[] for i in range(n)]",
"-for i in range(n - 1):",
"- u, v, w = list(map(int, input().split()))",
"- G[u - 1].append([v - 1, w])",
"- G[v - 1].append([u - 1, w])",
"-dist = [-1] * n",
"-from collections import deque",
"-",
"-Q, k = list(map(int, input().split()))",
"-q = deque()",
"-q.append(k - 1)",
"-dist[k - 1] = 0",
"-while q:",
"- cur = q.popleft()",
"- for nx, nd in G[cur]:",
"- if dist[nx] != -1:",
"- continue",
"- dist[nx] = dist[cur] + nd",
"- q.append(nx)",
"-for i in range(Q):",
"- x, y = list(map(int, input().split()))",
"- x -= 1",
"- y -= 1",
"- print((dist[x] + dist[y]))",
"+edge = [[] for _ in range(n)]",
"+for _ in range(n - 1):",
"+ a, b, c = list(map(int, input().split()))",
"+ a -= 1",
"+ b -= 1",
"+ edge[a].append((b, c))",
"+ edge[b].append((a, c))",
"+q, k = list(map(int, input().split()))",
"+xy = [list(map(int, input().split())) for _ in range(q)]",
"+d = dijkstra(k - 1, n, edge)",
"+for x, y in xy:",
"+ print((d[x - 1] + d[y - 1]))"
]
| false | 0.034421 | 0.037191 | 0.925544 | [
"s383681504",
"s301134566"
]
|
u877415670 | p02744 | python | s394113606 | s838440817 | 587 | 155 | 44,556 | 4,412 | Accepted | Accepted | 73.59 | n=int(eval(input()))
char=[chr(i) for i in range(97, 97+26)]
ans=["a"]
before=0
for i in range(2,n+1):
for c in range(len(ans)):
From=char.index(sorted(list(ans[c]))[-1])
for m in range(From+2):
ans.append(ans[c]+char[m])
#print(ans)
b=[]
for g in range(len(ans)):
if len(ans[g])==n:
b.append(ans[g])
b.sort()
for i in range(len(b)):
print((b[i])) | import sys
sys.setrecursionlimit(10**9)
N = int(eval(input()))
def bfs(s, cnt, m):
if cnt == N:
print(s)
return
for i in range(97,ord(m)+2):
if chr(i) > m:
bfs(s+chr(i), cnt+1, chr(i))
else:
bfs(s+chr(i), cnt+1, m)
bfs('a',1,'a') | 23 | 17 | 423 | 259 | n = int(eval(input()))
char = [chr(i) for i in range(97, 97 + 26)]
ans = ["a"]
before = 0
for i in range(2, n + 1):
for c in range(len(ans)):
From = char.index(sorted(list(ans[c]))[-1])
for m in range(From + 2):
ans.append(ans[c] + char[m])
# print(ans)
b = []
for g in range(len(ans)):
if len(ans[g]) == n:
b.append(ans[g])
b.sort()
for i in range(len(b)):
print((b[i]))
| import sys
sys.setrecursionlimit(10**9)
N = int(eval(input()))
def bfs(s, cnt, m):
if cnt == N:
print(s)
return
for i in range(97, ord(m) + 2):
if chr(i) > m:
bfs(s + chr(i), cnt + 1, chr(i))
else:
bfs(s + chr(i), cnt + 1, m)
bfs("a", 1, "a")
| false | 26.086957 | [
"-n = int(eval(input()))",
"-char = [chr(i) for i in range(97, 97 + 26)]",
"-ans = [\"a\"]",
"-before = 0",
"-for i in range(2, n + 1):",
"- for c in range(len(ans)):",
"- From = char.index(sorted(list(ans[c]))[-1])",
"- for m in range(From + 2):",
"- ans.append(ans[c] + char[m])",
"- # print(ans)",
"-b = []",
"-for g in range(len(ans)):",
"- if len(ans[g]) == n:",
"- b.append(ans[g])",
"-b.sort()",
"-for i in range(len(b)):",
"- print((b[i]))",
"+import sys",
"+",
"+sys.setrecursionlimit(10**9)",
"+N = int(eval(input()))",
"+",
"+",
"+def bfs(s, cnt, m):",
"+ if cnt == N:",
"+ print(s)",
"+ return",
"+ for i in range(97, ord(m) + 2):",
"+ if chr(i) > m:",
"+ bfs(s + chr(i), cnt + 1, chr(i))",
"+ else:",
"+ bfs(s + chr(i), cnt + 1, m)",
"+",
"+",
"+bfs(\"a\", 1, \"a\")"
]
| false | 0.080312 | 0.060792 | 1.321094 | [
"s394113606",
"s838440817"
]
|
u088552457 | p03147 | python | s804264796 | s147574557 | 281 | 135 | 64,876 | 77,492 | Accepted | Accepted | 51.96 | import fractions
import sys
from functools import reduce
import math
input = sys.stdin.readline
def main():
n = int(eval(input()))
h = input_list()
count = 0
while list(set(h)) != [0]:
count += 1
flag = False
for i, v in enumerate(h):
if v != 0:
flag = True
h[i] -= 1
else:
if flag:
break
print(count)
def divide_two(n):
c = 0
while True:
if c >= 2:
break
if n % 2 != 0:
break
n //= 2
c += 1
return c
def get_camulative(l):
import itertools
# ็ดฏ็ฉๅ
return [0] + list(itertools.accumulate(l))
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
if __name__ == "__main__":
main()
| # import sys
# input = sys.stdin.readline
# import re
import collections
import bisect
import math
import fractions
import collections
import itertools
from functools import reduce
def main():
n = int(eval(input()))
h = list(input_list())
count = 0
while True:
if list(set(h)) == [0]:
break
flag = False
count += 1
for i, v in enumerate(h):
if v != 0:
flag = True
h[i] -= 1
else:
if flag:
break
print(count)
def minus(numbers):
for i, n in enumerate(numbers):
if n == 0:
break
numbers[i] -= 1
return numbers
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == '__main__':
main()
| 70 | 48 | 1,310 | 914 | import fractions
import sys
from functools import reduce
import math
input = sys.stdin.readline
def main():
n = int(eval(input()))
h = input_list()
count = 0
while list(set(h)) != [0]:
count += 1
flag = False
for i, v in enumerate(h):
if v != 0:
flag = True
h[i] -= 1
else:
if flag:
break
print(count)
def divide_two(n):
c = 0
while True:
if c >= 2:
break
if n % 2 != 0:
break
n //= 2
c += 1
return c
def get_camulative(l):
import itertools
# ็ดฏ็ฉๅ
return [0] + list(itertools.accumulate(l))
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
if __name__ == "__main__":
main()
| # import sys
# input = sys.stdin.readline
# import re
import collections
import bisect
import math
import fractions
import collections
import itertools
from functools import reduce
def main():
n = int(eval(input()))
h = list(input_list())
count = 0
while True:
if list(set(h)) == [0]:
break
flag = False
count += 1
for i, v in enumerate(h):
if v != 0:
flag = True
h[i] -= 1
else:
if flag:
break
print(count)
def minus(numbers):
for i, n in enumerate(numbers):
if n == 0:
break
numbers[i] -= 1
return numbers
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| false | 31.428571 | [
"+# import sys",
"+# input = sys.stdin.readline",
"+# import re",
"+import collections",
"+import bisect",
"+import math",
"-import sys",
"+import collections",
"+import itertools",
"-import math",
"-",
"-input = sys.stdin.readline",
"- h = input_list()",
"+ h = list(input_list())",
"- while list(set(h)) != [0]:",
"+ while True:",
"+ if list(set(h)) == [0]:",
"+ break",
"+ flag = False",
"- flag = False",
"-def divide_two(n):",
"- c = 0",
"- while True:",
"- if c >= 2:",
"+def minus(numbers):",
"+ for i, n in enumerate(numbers):",
"+ if n == 0:",
"- if n % 2 != 0:",
"- break",
"- n //= 2",
"- c += 1",
"- return c",
"-",
"-",
"-def get_camulative(l):",
"- import itertools",
"-",
"- # ็ดฏ็ฉๅ",
"- return [0] + list(itertools.accumulate(l))",
"-",
"-",
"-def combinations_count(n, r):",
"- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))",
"+ numbers[i] -= 1",
"+ return numbers",
"-def lcm_base(x, y):",
"- return (x * y) // fractions.gcd(x, y)",
"-",
"-",
"-def lcm_list(numbers):",
"- return reduce(lcm_base, numbers, 1)",
"-",
"-",
"-def gcd(*numbers):",
"- return reduce(fractions.gcd, numbers)",
"-",
"-",
"-def gcd_list(numbers):",
"- return reduce(fractions.gcd, numbers)",
"-",
"-"
]
| false | 0.11715 | 0.047145 | 2.484874 | [
"s804264796",
"s147574557"
]
|
u562935282 | p03765 | python | s401766186 | s198672505 | 510 | 466 | 15,772 | 15,772 | Accepted | Accepted | 8.63 | # https://atcoder.jp/contests/arc071/submissions/6325840
from itertools import accumulate
S = tuple(map(lambda x: 1 if x == 'A' else 2, input()))
T = tuple(map(lambda x: 1 if x == 'A' else 2, input()))
# A=1,B=2
acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))
ans = []
Q = int(input())
for _ in range(Q):
sl, sr, tl, tr = map(int, input().split())
diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
# ๆทปใๅญ-1ใฏๅคๆฐๅไปฃๅ
ฅใใชใๆนใ20ms้ใ
ans.append('YES' if diff % 3 == 0 else 'NO')
print(*ans, sep='\n')
# ้ๆฌกprintใ ใจ1000ms
# ไธๆฌใ ใจ500ms
| # https://atcoder.jp/contests/arc071/submissions/6325840
from itertools import accumulate
convert = {'A': 1, 'B': 2}
S = tuple(convert[x] for x in input())
T = tuple(convert[x] for x in input())
# maspyใใใฎใใๆน
acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))
ans = []
Q = int(input())
for _ in range(Q):
sl, sr, tl, tr = map(int, input().split())
diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
# ๆทปใๅญ-1ใฏๅคๆฐๅไปฃๅ
ฅใใชใๆนใ20ms้ใ
ans.append('YES' if diff % 3 == 0 else 'NO')
print(*ans, sep='\n')
# ้ๆฌกprintใ ใจ1000ms
# ไธๆฌใ ใจ500ms
| 23 | 23 | 603 | 599 | # https://atcoder.jp/contests/arc071/submissions/6325840
from itertools import accumulate
S = tuple(map(lambda x: 1 if x == "A" else 2, input()))
T = tuple(map(lambda x: 1 if x == "A" else 2, input()))
# A=1,B=2
acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))
ans = []
Q = int(input())
for _ in range(Q):
sl, sr, tl, tr = map(int, input().split())
diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
# ๆทปใๅญ-1ใฏๅคๆฐๅไปฃๅ
ฅใใชใๆนใ20ms้ใ
ans.append("YES" if diff % 3 == 0 else "NO")
print(*ans, sep="\n")
# ้ๆฌกprintใ ใจ1000ms
# ไธๆฌใ ใจ500ms
| # https://atcoder.jp/contests/arc071/submissions/6325840
from itertools import accumulate
convert = {"A": 1, "B": 2}
S = tuple(convert[x] for x in input())
T = tuple(convert[x] for x in input())
# maspyใใใฎใใๆน
acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))
ans = []
Q = int(input())
for _ in range(Q):
sl, sr, tl, tr = map(int, input().split())
diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
# ๆทปใๅญ-1ใฏๅคๆฐๅไปฃๅ
ฅใใชใๆนใ20ms้ใ
ans.append("YES" if diff % 3 == 0 else "NO")
print(*ans, sep="\n")
# ้ๆฌกprintใ ใจ1000ms
# ไธๆฌใ ใจ500ms
| false | 0 | [
"-S = tuple(map(lambda x: 1 if x == \"A\" else 2, input()))",
"-T = tuple(map(lambda x: 1 if x == \"A\" else 2, input()))",
"-# A=1,B=2",
"+convert = {\"A\": 1, \"B\": 2}",
"+S = tuple(convert[x] for x in input())",
"+T = tuple(convert[x] for x in input())",
"+# maspyใใใฎใใๆน"
]
| false | 0.126084 | 0.099 | 1.273576 | [
"s401766186",
"s198672505"
]
|
u163320134 | p02972 | python | s327969892 | s210636911 | 679 | 493 | 14,096 | 14,000 | Accepted | Accepted | 27.39 | n=int(eval(input()))
arr=list(map(int,input().split()))
flag=[-1]*n
ans=[]
for i in range(n-1,-1,-1):
cnt=0
for j in range(i,n,i+1):
if j==i:
continue
else:
if flag[j]==1:
cnt+=1
if (arr[i]+cnt)%2==0:
flag[i]=0
else:
flag[i]=1
ans.append(i+1)
num=len(ans)
if num==0:
print((0))
else:
print(num)
print((*ans)) | n=int(eval(input()))
arr=list(map(int,input().split()))
flag=[-1]*n
ans=[]
for i in range(n-1,-1,-1):
cnt=0
for j in range(2*i+1,n,i+1):
if flag[j]==1:
cnt+=1
if (arr[i]+cnt)%2==0:
flag[i]=0
else:
flag[i]=1
ans.append(i+1)
num=len(ans)
if num==0:
print((0))
else:
print(num)
print((*ans)) | 23 | 20 | 374 | 333 | n = int(eval(input()))
arr = list(map(int, input().split()))
flag = [-1] * n
ans = []
for i in range(n - 1, -1, -1):
cnt = 0
for j in range(i, n, i + 1):
if j == i:
continue
else:
if flag[j] == 1:
cnt += 1
if (arr[i] + cnt) % 2 == 0:
flag[i] = 0
else:
flag[i] = 1
ans.append(i + 1)
num = len(ans)
if num == 0:
print((0))
else:
print(num)
print((*ans))
| n = int(eval(input()))
arr = list(map(int, input().split()))
flag = [-1] * n
ans = []
for i in range(n - 1, -1, -1):
cnt = 0
for j in range(2 * i + 1, n, i + 1):
if flag[j] == 1:
cnt += 1
if (arr[i] + cnt) % 2 == 0:
flag[i] = 0
else:
flag[i] = 1
ans.append(i + 1)
num = len(ans)
if num == 0:
print((0))
else:
print(num)
print((*ans))
| false | 13.043478 | [
"- for j in range(i, n, i + 1):",
"- if j == i:",
"- continue",
"- else:",
"- if flag[j] == 1:",
"- cnt += 1",
"+ for j in range(2 * i + 1, n, i + 1):",
"+ if flag[j] == 1:",
"+ cnt += 1"
]
| false | 0.037436 | 0.037523 | 0.997674 | [
"s327969892",
"s210636911"
]
|
u347267726 | p03250 | python | s106015088 | s477174657 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a,b,c=list(map(int,input().split()))
if(a>=b):
if(a>=c):
print(((a*10)+b+c))
else:
print(((c*10)+a+b))
elif (b>=c):
print((b * 10 + a + c)) | a,b,c=sorted(map(int,input().split()))
print((c*10+a+b)) | 8 | 2 | 162 | 55 | a, b, c = list(map(int, input().split()))
if a >= b:
if a >= c:
print(((a * 10) + b + c))
else:
print(((c * 10) + a + b))
elif b >= c:
print((b * 10 + a + c))
| a, b, c = sorted(map(int, input().split()))
print((c * 10 + a + b))
| false | 75 | [
"-a, b, c = list(map(int, input().split()))",
"-if a >= b:",
"- if a >= c:",
"- print(((a * 10) + b + c))",
"- else:",
"- print(((c * 10) + a + b))",
"-elif b >= c:",
"- print((b * 10 + a + c))",
"+a, b, c = sorted(map(int, input().split()))",
"+print((c * 10 + a + b))"
]
| false | 0.045345 | 0.043166 | 1.050468 | [
"s106015088",
"s477174657"
]
|
u844646164 | p02768 | python | s270357406 | s781971633 | 175 | 144 | 38,640 | 3,064 | Accepted | Accepted | 17.71 | def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
p=10**9+7
n,a,b = list(map(int,(input().split())))
bb = ncr(n,a,p)+ncr(n,b,p)+1
print(((pow(2,n,p)-(bb%p))%p)) | n, a, b = list(map(int, input().split()))
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
#N_C_kใฎN
for i in range(2, n+10):
fac.append(fac[-1]*i%Mod)
inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
finv.append(finv[-1] * inv[-1] % Mod)
def COM(n, k):
if n < 0 or k < 0 or n < k:
return 0
return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
p=10**9+7
ans = pow(2, n, Mod)
ans -= ncr(n, a, p)
ans %= Mod
ans -= ncr(n, b, p)
ans %= Mod
print((ans-1)) | 10 | 35 | 275 | 673 | def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
p = 10**9 + 7
n, a, b = list(map(int, (input().split())))
bb = ncr(n, a, p) + ncr(n, b, p) + 1
print(((pow(2, n, p) - (bb % p)) % p))
| n, a, b = list(map(int, input().split()))
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9 + 7
def COMinit():
# N_C_kใฎN
for i in range(2, n + 10):
fac.append(fac[-1] * i % Mod)
inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
finv.append(finv[-1] * inv[-1] % Mod)
def COM(n, k):
if n < 0 or k < 0 or n < k:
return 0
return fac[n] * (finv[k] * finv[n - k] % Mod) % Mod
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
p = 10**9 + 7
ans = pow(2, n, Mod)
ans -= ncr(n, a, p)
ans %= Mod
ans -= ncr(n, b, p)
ans %= Mod
print((ans - 1))
| false | 71.428571 | [
"+n, a, b = list(map(int, input().split()))",
"+fac = [1, 1]",
"+finv = [1, 1]",
"+inv = [0, 1]",
"+Mod = 10**9 + 7",
"+",
"+",
"+def COMinit():",
"+ # N_C_kใฎN",
"+ for i in range(2, n + 10):",
"+ fac.append(fac[-1] * i % Mod)",
"+ inv.append((-inv[Mod % i] * (Mod // i)) % Mod)",
"+ finv.append(finv[-1] * inv[-1] % Mod)",
"+",
"+",
"+def COM(n, k):",
"+ if n < 0 or k < 0 or n < k:",
"+ return 0",
"+ return fac[n] * (finv[k] * finv[n - k] % Mod) % Mod",
"+",
"+",
"-n, a, b = list(map(int, (input().split())))",
"-bb = ncr(n, a, p) + ncr(n, b, p) + 1",
"-print(((pow(2, n, p) - (bb % p)) % p))",
"+ans = pow(2, n, Mod)",
"+ans -= ncr(n, a, p)",
"+ans %= Mod",
"+ans -= ncr(n, b, p)",
"+ans %= Mod",
"+print((ans - 1))"
]
| false | 0.117248 | 0.181521 | 0.645918 | [
"s270357406",
"s781971633"
]
|
u941407962 | p03968 | python | s278280086 | s728372760 | 2,981 | 2,755 | 49,240 | 62,680 | Accepted | Accepted | 7.58 | from collections import defaultdict
N, = list(map(int, input().split()))
dd = defaultdict(int)
cc = dict()
norm = dict()
ss = []
for _ in range(N):
xs = list(map(int, input().split()))
cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)]
x = min(cnd)
for item in cnd:
norm[item] = x
dd[x] += 1
cc[x] = (4 if x[0] == x[1] else 2)if x[0] == x[2] and x[1] == x[3] else 1
ss.append(x)
def f(ff, gg):
a,b,c,d=ff
e,h,g,f=gg
tl = [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)]
for i in range(4):
if tl[i] not in norm:
return 0
tl[i] = norm[tl[i]]
r = 1
for cp in tl:
r *= dd[cp]*cc[cp]
dd[cp] -= 1
for cp in tl:
dd[cp] += 1
return r
r = 0
for i in range(N):
ff = ss[i]
dd[ff]-=1
for j in range(i+1, N):
sl = ss[j]
x, y, z, w = sl
dd[sl]-=1
sls = [(x,y,z,w), (y,z,w,x), (z,w,x,y), (w,x,y,z)]
for s in sls:
r += f(ff, s)
dd[sl]+=1
print(r) | from collections import defaultdict
N, = list(map(int, input().split()))
dd = defaultdict(int)
cc = dict()
nrm = dict()
ss = []
for _ in range(N):
xs = list(map(int, input().split()))
cnd = [tuple(xs[j:]+xs[:j])for j in range(4)]
x = min(cnd)
for item in cnd:
nrm[item] = x
dd[x] += 1
cc[x] = (4 if x[0]==x[1]else 2)if x[0]==x[2]and x[1]==x[3]else 1
ss.append(x)
def f(ff, gg):
a,b,c,d=ff
e,h,g,f=gg
tl = [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)]
q = defaultdict(int)
for p in tl:
if p not in nrm:
return 0
q[nrm[p]] += 1
r= 1
for p, c in list(q.items()):
for i in range(c):
r *= dd[p]-i
r *= cc[p]**c
return r
r = 0
for i in range(N):
ff = ss[i]
dd[ff]-=1
for j in range(i+1, N):
sl = ss[j]
x, y, z, w = sl
dd[sl]-=1
r += sum(f(ff,tuple(sl[j:]+sl[:j]))for j in range(4))
dd[sl]+=1
print(r) | 46 | 41 | 1,061 | 909 | from collections import defaultdict
(N,) = list(map(int, input().split()))
dd = defaultdict(int)
cc = dict()
norm = dict()
ss = []
for _ in range(N):
xs = list(map(int, input().split()))
cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)]
x = min(cnd)
for item in cnd:
norm[item] = x
dd[x] += 1
cc[x] = (4 if x[0] == x[1] else 2) if x[0] == x[2] and x[1] == x[3] else 1
ss.append(x)
def f(ff, gg):
a, b, c, d = ff
e, h, g, f = gg
tl = [(a, e, f, b), (b, f, g, c), (c, g, h, d), (d, h, e, a)]
for i in range(4):
if tl[i] not in norm:
return 0
tl[i] = norm[tl[i]]
r = 1
for cp in tl:
r *= dd[cp] * cc[cp]
dd[cp] -= 1
for cp in tl:
dd[cp] += 1
return r
r = 0
for i in range(N):
ff = ss[i]
dd[ff] -= 1
for j in range(i + 1, N):
sl = ss[j]
x, y, z, w = sl
dd[sl] -= 1
sls = [(x, y, z, w), (y, z, w, x), (z, w, x, y), (w, x, y, z)]
for s in sls:
r += f(ff, s)
dd[sl] += 1
print(r)
| from collections import defaultdict
(N,) = list(map(int, input().split()))
dd = defaultdict(int)
cc = dict()
nrm = dict()
ss = []
for _ in range(N):
xs = list(map(int, input().split()))
cnd = [tuple(xs[j:] + xs[:j]) for j in range(4)]
x = min(cnd)
for item in cnd:
nrm[item] = x
dd[x] += 1
cc[x] = (4 if x[0] == x[1] else 2) if x[0] == x[2] and x[1] == x[3] else 1
ss.append(x)
def f(ff, gg):
a, b, c, d = ff
e, h, g, f = gg
tl = [(a, e, f, b), (b, f, g, c), (c, g, h, d), (d, h, e, a)]
q = defaultdict(int)
for p in tl:
if p not in nrm:
return 0
q[nrm[p]] += 1
r = 1
for p, c in list(q.items()):
for i in range(c):
r *= dd[p] - i
r *= cc[p] ** c
return r
r = 0
for i in range(N):
ff = ss[i]
dd[ff] -= 1
for j in range(i + 1, N):
sl = ss[j]
x, y, z, w = sl
dd[sl] -= 1
r += sum(f(ff, tuple(sl[j:] + sl[:j])) for j in range(4))
dd[sl] += 1
print(r)
| false | 10.869565 | [
"-norm = dict()",
"+nrm = dict()",
"- cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)]",
"+ cnd = [tuple(xs[j:] + xs[:j]) for j in range(4)]",
"- norm[item] = x",
"+ nrm[item] = x",
"- for i in range(4):",
"- if tl[i] not in norm:",
"+ q = defaultdict(int)",
"+ for p in tl:",
"+ if p not in nrm:",
"- tl[i] = norm[tl[i]]",
"+ q[nrm[p]] += 1",
"- for cp in tl:",
"- r *= dd[cp] * cc[cp]",
"- dd[cp] -= 1",
"- for cp in tl:",
"- dd[cp] += 1",
"+ for p, c in list(q.items()):",
"+ for i in range(c):",
"+ r *= dd[p] - i",
"+ r *= cc[p] ** c",
"- sls = [(x, y, z, w), (y, z, w, x), (z, w, x, y), (w, x, y, z)]",
"- for s in sls:",
"- r += f(ff, s)",
"+ r += sum(f(ff, tuple(sl[j:] + sl[:j])) for j in range(4))"
]
| false | 0.067829 | 0.085532 | 0.793029 | [
"s278280086",
"s728372760"
]
|
u088552457 | p03147 | python | s147574557 | s079316265 | 135 | 73 | 77,492 | 67,980 | Accepted | Accepted | 45.93 | # import sys
# input = sys.stdin.readline
# import re
import collections
import bisect
import math
import fractions
import collections
import itertools
from functools import reduce
def main():
n = int(eval(input()))
h = list(input_list())
count = 0
while True:
if list(set(h)) == [0]:
break
flag = False
count += 1
for i, v in enumerate(h):
if v != 0:
flag = True
h[i] -= 1
else:
if flag:
break
print(count)
def minus(numbers):
for i, n in enumerate(numbers):
if n == 0:
break
numbers[i] -= 1
return numbers
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == '__main__':
main()
| # import sys
# input = sys.stdin.readline
import collections
def main():
n = int(eval(input()))
h = input_list()
count = 0
while True:
if list(set(h)) == [0]:
break
count += 1
f = False
for i, v in enumerate(h):
if v == 0:
if f:
break
if v > 0:
h[i] -= 1
f = True
print(count)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 48 | 33 | 914 | 630 | # import sys
# input = sys.stdin.readline
# import re
import collections
import bisect
import math
import fractions
import collections
import itertools
from functools import reduce
def main():
n = int(eval(input()))
h = list(input_list())
count = 0
while True:
if list(set(h)) == [0]:
break
flag = False
count += 1
for i, v in enumerate(h):
if v != 0:
flag = True
h[i] -= 1
else:
if flag:
break
print(count)
def minus(numbers):
for i, n in enumerate(numbers):
if n == 0:
break
numbers[i] -= 1
return numbers
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| # import sys
# input = sys.stdin.readline
import collections
def main():
n = int(eval(input()))
h = input_list()
count = 0
while True:
if list(set(h)) == [0]:
break
count += 1
f = False
for i, v in enumerate(h):
if v == 0:
if f:
break
if v > 0:
h[i] -= 1
f = True
print(count)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| false | 31.25 | [
"-# import re",
"-import bisect",
"-import math",
"-import fractions",
"-import collections",
"-import itertools",
"-from functools import reduce",
"- h = list(input_list())",
"+ h = input_list()",
"- flag = False",
"+ f = False",
"- if v != 0:",
"- flag = True",
"+ if v == 0:",
"+ if f:",
"+ break",
"+ if v > 0:",
"- else:",
"- if flag:",
"- break",
"+ f = True",
"-",
"-",
"-def minus(numbers):",
"- for i, n in enumerate(numbers):",
"- if n == 0:",
"- break",
"- numbers[i] -= 1",
"- return numbers"
]
| false | 0.047145 | 0.035083 | 1.343829 | [
"s147574557",
"s079316265"
]
|
u423665486 | p03944 | python | s600738205 | s159838566 | 202 | 46 | 41,712 | 3,064 | Accepted | Accepted | 77.23 | def resolve():
w, h, n = list(map(int, input().split()))
r = [[True]*w for _ in range(h)]
for _ in range(n):
ix, iy, a = list(map(int, input().split()))
if a == 1:
for i in range(h):
for j in range(ix):
r[i][j] = False
elif a == 2:
for i in range(h):
for j in range(ix, w):
r[i][j] = False
elif a == 3:
for i in range(iy):
for j in range(w):
r[i][j] = False
else:
for i in range(iy, h):
for j in range(w):
r[i][j] = False
ans = 0
for row in r:
for i in row:
if i:
ans += 1
print(ans)
resolve() | def resolve():
w, h, n = list(map(int, input().split()))
r = [[True]*w for _ in range(h)]
for i in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
for j in range(h):
for k in range(x):
r[j][k] = False
if a == 2:
for j in range(h):
for k in range(x, w):
r[j][k] = False
if a == 3:
for j in range(y):
for k in range(w):
r[j][k] = False
if a == 4:
for j in range(y, h):
for k in range(w):
r[j][k] = False
ans = 0
for i in range(h):
for j in r[i]:
if j:
ans += 1
print(ans)
resolve() | 29 | 28 | 583 | 582 | def resolve():
w, h, n = list(map(int, input().split()))
r = [[True] * w for _ in range(h)]
for _ in range(n):
ix, iy, a = list(map(int, input().split()))
if a == 1:
for i in range(h):
for j in range(ix):
r[i][j] = False
elif a == 2:
for i in range(h):
for j in range(ix, w):
r[i][j] = False
elif a == 3:
for i in range(iy):
for j in range(w):
r[i][j] = False
else:
for i in range(iy, h):
for j in range(w):
r[i][j] = False
ans = 0
for row in r:
for i in row:
if i:
ans += 1
print(ans)
resolve()
| def resolve():
w, h, n = list(map(int, input().split()))
r = [[True] * w for _ in range(h)]
for i in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
for j in range(h):
for k in range(x):
r[j][k] = False
if a == 2:
for j in range(h):
for k in range(x, w):
r[j][k] = False
if a == 3:
for j in range(y):
for k in range(w):
r[j][k] = False
if a == 4:
for j in range(y, h):
for k in range(w):
r[j][k] = False
ans = 0
for i in range(h):
for j in r[i]:
if j:
ans += 1
print(ans)
resolve()
| false | 3.448276 | [
"- for _ in range(n):",
"- ix, iy, a = list(map(int, input().split()))",
"+ for i in range(n):",
"+ x, y, a = list(map(int, input().split()))",
"- for i in range(h):",
"- for j in range(ix):",
"- r[i][j] = False",
"- elif a == 2:",
"- for i in range(h):",
"- for j in range(ix, w):",
"- r[i][j] = False",
"- elif a == 3:",
"- for i in range(iy):",
"- for j in range(w):",
"- r[i][j] = False",
"- else:",
"- for i in range(iy, h):",
"- for j in range(w):",
"- r[i][j] = False",
"+ for j in range(h):",
"+ for k in range(x):",
"+ r[j][k] = False",
"+ if a == 2:",
"+ for j in range(h):",
"+ for k in range(x, w):",
"+ r[j][k] = False",
"+ if a == 3:",
"+ for j in range(y):",
"+ for k in range(w):",
"+ r[j][k] = False",
"+ if a == 4:",
"+ for j in range(y, h):",
"+ for k in range(w):",
"+ r[j][k] = False",
"- for row in r:",
"- for i in row:",
"- if i:",
"+ for i in range(h):",
"+ for j in r[i]:",
"+ if j:"
]
| false | 0.058008 | 0.057982 | 1.000447 | [
"s600738205",
"s159838566"
]
|
u539367121 | p02773 | python | s378751125 | s381799670 | 735 | 391 | 67,208 | 35,320 | Accepted | Accepted | 46.8 | N=int(eval(input()))
S={}
for n in range(N):
s=eval(input())
S[s]=S.get(s,0)+1
maxS=max(S.values())
S={k:v for k, v in list(S.items()) if v==maxS}
S=sorted(list(S.items()), key=lambda x:(-x[1],x[0]))
for k,cnt in S:
print(k)
| N=int(eval(input()))
S={}
for n in range(N):
s=eval(input())
S[s]=S.get(s,0)+1
maxS=max(S.values())
S=[k for k,v in list(S.items()) if v==maxS]
print(('\n'.join(sorted(S))))
| 11 | 9 | 218 | 167 | N = int(eval(input()))
S = {}
for n in range(N):
s = eval(input())
S[s] = S.get(s, 0) + 1
maxS = max(S.values())
S = {k: v for k, v in list(S.items()) if v == maxS}
S = sorted(list(S.items()), key=lambda x: (-x[1], x[0]))
for k, cnt in S:
print(k)
| N = int(eval(input()))
S = {}
for n in range(N):
s = eval(input())
S[s] = S.get(s, 0) + 1
maxS = max(S.values())
S = [k for k, v in list(S.items()) if v == maxS]
print(("\n".join(sorted(S))))
| false | 18.181818 | [
"-S = {k: v for k, v in list(S.items()) if v == maxS}",
"-S = sorted(list(S.items()), key=lambda x: (-x[1], x[0]))",
"-for k, cnt in S:",
"- print(k)",
"+S = [k for k, v in list(S.items()) if v == maxS]",
"+print((\"\\n\".join(sorted(S))))"
]
| false | 0.06767 | 0.036807 | 1.838506 | [
"s378751125",
"s381799670"
]
|
u648901783 | p03805 | python | s384971430 | s265211768 | 37 | 28 | 3,064 | 3,316 | Accepted | Accepted | 24.32 | n,m= list(map(int,input().split()))
a = [input().rstrip().split() for j in range(m)]
cnt = 0#็พๅจใฎ็ต่ทฏ
# a
visited=[False]*n#ใใ่จชๅใใใ
graph = [[False for i in range(n)] for j in range(n)]#ใฉใใ้ฃ็ตใใใฆใใใ
# graph
for i in range(0,m):
x = int(a[i][0])-1
y = int(a[i][1])-1
graph[x][y]=graph[y][x]=True
# graph
def DFS(v,n,visited):
# print(visited)
all_visited = True #bool
for i in range(0,n):
if(visited[i]==0):
all_visited = False
if(all_visited):
return 1
ret = 0
for i in range(0,n):
if(graph[v][i]==False):
continue
if(visited[i]):
continue
visited[i] = True
ret += DFS(i,n,visited)
visited[i] = False
return ret
visited[0]=True
print((DFS(0,n,visited))) | N,M = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(M)]
from collections import defaultdict
memo = defaultdict(list)
for ele in ab:
memo[ele[0]-1].append(ele[1]-1)
memo[ele[1]-1].append(ele[0]-1)
que = []
visited = defaultdict(int)
ans = [0]
def dfs(visited,node,pre_node,tmp_sum):
if tmp_sum == N:
ans[0] += 1
return
for nn in memo[node]:
if nn == pre_node: continue
if visited[nn]==1: continue
visited[nn] = 1
dfs(visited,nn,node,tmp_sum+1)
visited[nn] = 0
return
flag = [False]
visited[0]=1
dfs(visited,0,-1,1)
print((ans[0])) | 37 | 34 | 818 | 684 | n, m = list(map(int, input().split()))
a = [input().rstrip().split() for j in range(m)]
cnt = 0 # ็พๅจใฎ็ต่ทฏ
# a
visited = [False] * n # ใใ่จชๅใใใ
graph = [[False for i in range(n)] for j in range(n)] # ใฉใใ้ฃ็ตใใใฆใใใ
# graph
for i in range(0, m):
x = int(a[i][0]) - 1
y = int(a[i][1]) - 1
graph[x][y] = graph[y][x] = True
# graph
def DFS(v, n, visited):
# print(visited)
all_visited = True # bool
for i in range(0, n):
if visited[i] == 0:
all_visited = False
if all_visited:
return 1
ret = 0
for i in range(0, n):
if graph[v][i] == False:
continue
if visited[i]:
continue
visited[i] = True
ret += DFS(i, n, visited)
visited[i] = False
return ret
visited[0] = True
print((DFS(0, n, visited)))
| N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(M)]
from collections import defaultdict
memo = defaultdict(list)
for ele in ab:
memo[ele[0] - 1].append(ele[1] - 1)
memo[ele[1] - 1].append(ele[0] - 1)
que = []
visited = defaultdict(int)
ans = [0]
def dfs(visited, node, pre_node, tmp_sum):
if tmp_sum == N:
ans[0] += 1
return
for nn in memo[node]:
if nn == pre_node:
continue
if visited[nn] == 1:
continue
visited[nn] = 1
dfs(visited, nn, node, tmp_sum + 1)
visited[nn] = 0
return
flag = [False]
visited[0] = 1
dfs(visited, 0, -1, 1)
print((ans[0]))
| false | 8.108108 | [
"-n, m = list(map(int, input().split()))",
"-a = [input().rstrip().split() for j in range(m)]",
"-cnt = 0 # ็พๅจใฎ็ต่ทฏ",
"-# a",
"-visited = [False] * n # ใใ่จชๅใใใ",
"-graph = [[False for i in range(n)] for j in range(n)] # ใฉใใ้ฃ็ตใใใฆใใใ",
"-# graph",
"-for i in range(0, m):",
"- x = int(a[i][0]) - 1",
"- y = int(a[i][1]) - 1",
"- graph[x][y] = graph[y][x] = True",
"-# graph",
"-def DFS(v, n, visited):",
"- # print(visited)",
"- all_visited = True # bool",
"- for i in range(0, n):",
"- if visited[i] == 0:",
"- all_visited = False",
"- if all_visited:",
"- return 1",
"- ret = 0",
"- for i in range(0, n):",
"- if graph[v][i] == False:",
"- continue",
"- if visited[i]:",
"- continue",
"- visited[i] = True",
"- ret += DFS(i, n, visited)",
"- visited[i] = False",
"- return ret",
"+N, M = list(map(int, input().split()))",
"+ab = [list(map(int, input().split())) for i in range(M)]",
"+from collections import defaultdict",
"+",
"+memo = defaultdict(list)",
"+for ele in ab:",
"+ memo[ele[0] - 1].append(ele[1] - 1)",
"+ memo[ele[1] - 1].append(ele[0] - 1)",
"+que = []",
"+visited = defaultdict(int)",
"+ans = [0]",
"-visited[0] = True",
"-print((DFS(0, n, visited)))",
"+def dfs(visited, node, pre_node, tmp_sum):",
"+ if tmp_sum == N:",
"+ ans[0] += 1",
"+ return",
"+ for nn in memo[node]:",
"+ if nn == pre_node:",
"+ continue",
"+ if visited[nn] == 1:",
"+ continue",
"+ visited[nn] = 1",
"+ dfs(visited, nn, node, tmp_sum + 1)",
"+ visited[nn] = 0",
"+ return",
"+",
"+",
"+flag = [False]",
"+visited[0] = 1",
"+dfs(visited, 0, -1, 1)",
"+print((ans[0]))"
]
| false | 0.047172 | 0.045936 | 1.026919 | [
"s384971430",
"s265211768"
]
|
u647766105 | p00114 | python | s046397552 | s963812514 | 360 | 230 | 5,900 | 5,900 | Accepted | Accepted | 36.11 | from fractions import gcd
from functools import reduce
def lcm(a,b):
return a*b/gcd(a,b)
while True:
tmp = list(map(int, input().split(" ")))
if all(t==0 for t in tmp):
break
b = []
for a,m in zip(tmp[::2], tmp[1::2]):
i, c = 1, a%m
while c!=1:
c = (a*c)%m
i += 1
b.append(i)
print(reduce(lcm,b)) | from fractions import gcd
from functools import reduce
def lcm(a,b):
return a*b/gcd(a,b)
def ge(a,m):
for aa,mm in zip(a, m):
i, b = 1, aa%mm
while b!=1:
b = (aa*b)%mm
i += 1
yield i
while True:
tmp = list(map(int, input().split(" ")))
if all(t==0 for t in tmp):
break
print(reduce(lcm,ge(tmp[::2],tmp[1::2]))) | 15 | 15 | 358 | 369 | from fractions import gcd
from functools import reduce
def lcm(a, b):
return a * b / gcd(a, b)
while True:
tmp = list(map(int, input().split(" ")))
if all(t == 0 for t in tmp):
break
b = []
for a, m in zip(tmp[::2], tmp[1::2]):
i, c = 1, a % m
while c != 1:
c = (a * c) % m
i += 1
b.append(i)
print(reduce(lcm, b))
| from fractions import gcd
from functools import reduce
def lcm(a, b):
return a * b / gcd(a, b)
def ge(a, m):
for aa, mm in zip(a, m):
i, b = 1, aa % mm
while b != 1:
b = (aa * b) % mm
i += 1
yield i
while True:
tmp = list(map(int, input().split(" ")))
if all(t == 0 for t in tmp):
break
print(reduce(lcm, ge(tmp[::2], tmp[1::2])))
| false | 0 | [
"+def ge(a, m):",
"+ for aa, mm in zip(a, m):",
"+ i, b = 1, aa % mm",
"+ while b != 1:",
"+ b = (aa * b) % mm",
"+ i += 1",
"+ yield i",
"+",
"+",
"- b = []",
"- for a, m in zip(tmp[::2], tmp[1::2]):",
"- i, c = 1, a % m",
"- while c != 1:",
"- c = (a * c) % m",
"- i += 1",
"- b.append(i)",
"- print(reduce(lcm, b))",
"+ print(reduce(lcm, ge(tmp[::2], tmp[1::2])))"
]
| false | 0.051283 | 0.052724 | 0.972667 | [
"s046397552",
"s963812514"
]
|
u962909487 | p02397 | python | s084955841 | s923753607 | 60 | 50 | 5,612 | 5,612 | Accepted | Accepted | 16.67 | while True:
x,y = list(map(int,input().split()))
if (x,y) ==(0,0): break
if x < y:
print((x,y))
else:
print((y,x))
| while True:
a,b = list(map(int,input().split()))
if a == 0 and b==0:
break
if a > b:
print((b,a))
else:
print((a,b))
| 7 | 8 | 143 | 155 | while True:
x, y = list(map(int, input().split()))
if (x, y) == (0, 0):
break
if x < y:
print((x, y))
else:
print((y, x))
| while True:
a, b = list(map(int, input().split()))
if a == 0 and b == 0:
break
if a > b:
print((b, a))
else:
print((a, b))
| false | 12.5 | [
"- x, y = list(map(int, input().split()))",
"- if (x, y) == (0, 0):",
"+ a, b = list(map(int, input().split()))",
"+ if a == 0 and b == 0:",
"- if x < y:",
"- print((x, y))",
"+ if a > b:",
"+ print((b, a))",
"- print((y, x))",
"+ print((a, b))"
]
| false | 0.079286 | 0.080821 | 0.981016 | [
"s084955841",
"s923753607"
]
|
u426764965 | p02947 | python | s729550285 | s673409840 | 845 | 456 | 12,224 | 19,732 | Accepted | Accepted | 46.04 | N = int(eval(input()))
words = []
for i in range(N):
s = str(eval(input()))
s_sort = ''.join(sorted([ch for ch in s]))
words.append(s_sort)
words_sort = sorted(words)
counter = 0
target_word = ''
counts = []
for word in words_sort:
if word == target_word:
counter += 1
else:
counts.append(counter)
counter = 1
target_word = word
counts.append(counter)
from math import factorial
ans = 0
for cnt in counts:
if cnt > 1:
ans += factorial(cnt) // factorial(cnt-2) // 2
print(ans) | N = int(eval(input()))
words = []
for i in range(N):
s_in = str(eval(input()))
s_sort = ''.join(sorted([ch for ch in s_in]))
words.append(s_sort)
#print(words)
# Counterใฏใฉใน: key=่ฆ็ด , val=ๅบ็พๅๆฐ
from collections import Counter
cntr = Counter(words)
#print(cntr)
# ๅบ็พๅๆฐ2ๅไปฅไธใฏ็ตใฟๅใใๆฐใ่ถณใ
ans = 0
for cnt in list(cntr.values()):
if cnt > 1:
ans += cnt * (cnt - 1) // 2
print(ans) | 30 | 20 | 530 | 385 | N = int(eval(input()))
words = []
for i in range(N):
s = str(eval(input()))
s_sort = "".join(sorted([ch for ch in s]))
words.append(s_sort)
words_sort = sorted(words)
counter = 0
target_word = ""
counts = []
for word in words_sort:
if word == target_word:
counter += 1
else:
counts.append(counter)
counter = 1
target_word = word
counts.append(counter)
from math import factorial
ans = 0
for cnt in counts:
if cnt > 1:
ans += factorial(cnt) // factorial(cnt - 2) // 2
print(ans)
| N = int(eval(input()))
words = []
for i in range(N):
s_in = str(eval(input()))
s_sort = "".join(sorted([ch for ch in s_in]))
words.append(s_sort)
# print(words)
# Counterใฏใฉใน: key=่ฆ็ด , val=ๅบ็พๅๆฐ
from collections import Counter
cntr = Counter(words)
# print(cntr)
# ๅบ็พๅๆฐ2ๅไปฅไธใฏ็ตใฟๅใใๆฐใ่ถณใ
ans = 0
for cnt in list(cntr.values()):
if cnt > 1:
ans += cnt * (cnt - 1) // 2
print(ans)
| false | 33.333333 | [
"- s = str(eval(input()))",
"- s_sort = \"\".join(sorted([ch for ch in s]))",
"+ s_in = str(eval(input()))",
"+ s_sort = \"\".join(sorted([ch for ch in s_in]))",
"-words_sort = sorted(words)",
"-counter = 0",
"-target_word = \"\"",
"-counts = []",
"-for word in words_sort:",
"- if word == target_word:",
"- counter += 1",
"- else:",
"- counts.append(counter)",
"- counter = 1",
"- target_word = word",
"-counts.append(counter)",
"-from math import factorial",
"+# print(words)",
"+# Counterใฏใฉใน: key=่ฆ็ด , val=ๅบ็พๅๆฐ",
"+from collections import Counter",
"+cntr = Counter(words)",
"+# print(cntr)",
"+# ๅบ็พๅๆฐ2ๅไปฅไธใฏ็ตใฟๅใใๆฐใ่ถณใ",
"-for cnt in counts:",
"+for cnt in list(cntr.values()):",
"- ans += factorial(cnt) // factorial(cnt - 2) // 2",
"+ ans += cnt * (cnt - 1) // 2"
]
| false | 0.034974 | 0.037601 | 0.930135 | [
"s729550285",
"s673409840"
]
|
u054556734 | p03575 | python | s087268869 | s917311295 | 242 | 166 | 17,568 | 13,240 | Accepted | Accepted | 31.4 | import numpy as np
class unionfind: #ใใผใๆฐnใ่ชญใฟ่พผใ
def __init__(self,n): #ใณใณในใใฉใฏใฟ
self.parent = list(range(n))
def find(self,a): #ๆ นใๆขใใใใฎใคใฉๆ นใๆดๆฐ
if self.parent[a] == a: return a #่ชๅใๆ นใ ใฃใใ็ตไบ
else:
self.parent[a] = self.find(self.parent[a]) #็ต่ทฏๅง็ธฎ
return self.parent[a]
def unite(self,a,b): #ใฉใณใฏๅบฆๅค่ฆใงๆ นใๅไฝใใ
pa,pb = self.find(a),self.find(b)
if pa == pb: return 0 #ๆ นใไธ็ทใชใไฝใใใ็ตไบ
else: self.parent[pa] = pb
def same(self,a,b):
pa,pb = self.find(a),self.find(b)
return pa == pb
# ใฏใฉในใไฝฟใใชใๅฎ่ฃ
def find(x):
if node[x] == x: return x
else: node[x] = find(node[x]) ; return node[x]
def unite(x,y):
x,y = find(x),find(y)
if x == y : return
else: node[x] = y
def same(x,y): return find(x) == find(y)
n,m = list(map(int,input().split()))
ab = np.array([list(map(int,input().split())) for i in range(m)])
a,b = ab.T[0] -1, ab.T[1] -1
ans = 0
for i in range(m): #้คๅคใใ่พบใๆฑบใใ
connect = 0
node = list(range(n))
for j in range(m): #iไปฅๅคใฎ่พบใซใคใใฆuniteใใฆใใ
if i != j and not same(a[j],b[j]): unite(a[j],b[j]) ; connect += 1
ans += 0 if connect == n-1 else 1
print(ans)
| import numpy as np
def find(x):
if x == root[x]: return x
else: root[x] = find(root[x]); return root[x]
def unite(x,y):
px,py = find(x),find(y)
if px == py : return
else: root[px] = py
def same(x,y): return find(x)==find(y)
n,m = list(map(int,input().split()))
ab = np.array([list(map(int,input().split())) for i in range(m)])
a,b = ab.T[0] -1, ab.T[1] -1
ans = 0
for i in range(m): #้คๅคใใ่พบใๆฑบใใ
connect = 0
root = list(range(n))
for j in range(m): #iไปฅๅคใฎ่พบใซใคใใฆuniteใใฆใใ
if i != j and not same(a[j],b[j]):
unite(a[j],b[j]) ; connect += 1
ans += 0 if connect == n-1 else 1
print(ans)
| 42 | 27 | 1,226 | 662 | import numpy as np
class unionfind: # ใใผใๆฐnใ่ชญใฟ่พผใ
def __init__(self, n): # ใณใณในใใฉใฏใฟ
self.parent = list(range(n))
def find(self, a): # ๆ นใๆขใใใใฎใคใฉๆ นใๆดๆฐ
if self.parent[a] == a:
return a # ่ชๅใๆ นใ ใฃใใ็ตไบ
else:
self.parent[a] = self.find(self.parent[a]) # ็ต่ทฏๅง็ธฎ
return self.parent[a]
def unite(self, a, b): # ใฉใณใฏๅบฆๅค่ฆใงๆ นใๅไฝใใ
pa, pb = self.find(a), self.find(b)
if pa == pb:
return 0 # ๆ นใไธ็ทใชใไฝใใใ็ตไบ
else:
self.parent[pa] = pb
def same(self, a, b):
pa, pb = self.find(a), self.find(b)
return pa == pb
# ใฏใฉในใไฝฟใใชใๅฎ่ฃ
def find(x):
if node[x] == x:
return x
else:
node[x] = find(node[x])
return node[x]
def unite(x, y):
x, y = find(x), find(y)
if x == y:
return
else:
node[x] = y
def same(x, y):
return find(x) == find(y)
n, m = list(map(int, input().split()))
ab = np.array([list(map(int, input().split())) for i in range(m)])
a, b = ab.T[0] - 1, ab.T[1] - 1
ans = 0
for i in range(m): # ้คๅคใใ่พบใๆฑบใใ
connect = 0
node = list(range(n))
for j in range(m): # iไปฅๅคใฎ่พบใซใคใใฆuniteใใฆใใ
if i != j and not same(a[j], b[j]):
unite(a[j], b[j])
connect += 1
ans += 0 if connect == n - 1 else 1
print(ans)
| import numpy as np
def find(x):
if x == root[x]:
return x
else:
root[x] = find(root[x])
return root[x]
def unite(x, y):
px, py = find(x), find(y)
if px == py:
return
else:
root[px] = py
def same(x, y):
return find(x) == find(y)
n, m = list(map(int, input().split()))
ab = np.array([list(map(int, input().split())) for i in range(m)])
a, b = ab.T[0] - 1, ab.T[1] - 1
ans = 0
for i in range(m): # ้คๅคใใ่พบใๆฑบใใ
connect = 0
root = list(range(n))
for j in range(m): # iไปฅๅคใฎ่พบใซใคใใฆuniteใใฆใใ
if i != j and not same(a[j], b[j]):
unite(a[j], b[j])
connect += 1
ans += 0 if connect == n - 1 else 1
print(ans)
| false | 35.714286 | [
"-class unionfind: # ใใผใๆฐnใ่ชญใฟ่พผใ",
"- def __init__(self, n): # ใณใณในใใฉใฏใฟ",
"- self.parent = list(range(n))",
"-",
"- def find(self, a): # ๆ นใๆขใใใใฎใคใฉๆ นใๆดๆฐ",
"- if self.parent[a] == a:",
"- return a # ่ชๅใๆ นใ ใฃใใ็ตไบ",
"- else:",
"- self.parent[a] = self.find(self.parent[a]) # ็ต่ทฏๅง็ธฎ",
"- return self.parent[a]",
"-",
"- def unite(self, a, b): # ใฉใณใฏๅบฆๅค่ฆใงๆ นใๅไฝใใ",
"- pa, pb = self.find(a), self.find(b)",
"- if pa == pb:",
"- return 0 # ๆ นใไธ็ทใชใไฝใใใ็ตไบ",
"- else:",
"- self.parent[pa] = pb",
"-",
"- def same(self, a, b):",
"- pa, pb = self.find(a), self.find(b)",
"- return pa == pb",
"-",
"-",
"-# ใฏใฉในใไฝฟใใชใๅฎ่ฃ
",
"- if node[x] == x:",
"+ if x == root[x]:",
"- node[x] = find(node[x])",
"- return node[x]",
"+ root[x] = find(root[x])",
"+ return root[x]",
"- x, y = find(x), find(y)",
"- if x == y:",
"+ px, py = find(x), find(y)",
"+ if px == py:",
"- node[x] = y",
"+ root[px] = py",
"- node = list(range(n))",
"+ root = list(range(n))"
]
| false | 0.36359 | 0.211057 | 1.722708 | [
"s087268869",
"s917311295"
]
|
u981122970 | p03013 | python | s760395888 | s129860592 | 514 | 441 | 463,984 | 464,008 | Accepted | Accepted | 14.2 | n, m = [int(i) for i in input().split()]
a = [-1] + [int(eval(input())) for _ in range(m)] + [n+1]
fib_l = [-1] * (n+3)
def make_fib(n):
fib_l[0] = fib_l[1] = 1
for i in range(2, n):
fib_l[i] = fib_l[i-1] + fib_l[i-2]
make_fib(n+3)
ret = 1
for i in range(m+1):
t = a[i+1] - a[i] - 2
if t < 0:
ret = 0
break
ret *= fib_l[t]
print((ret % 1000000007)) | from sys import stdin
n, m = [int(i) for i in stdin.readline().rstrip().split()]
a = [-1] + [int(stdin.readline()) for _ in range(m)] + [n+1]
fib_l = [-1] * (n+3)
def make_fib(n):
fib_l[0] = fib_l[1] = 1
for i in range(2, n):
fib_l[i] = fib_l[i-1] + fib_l[i-2]
make_fib(n+3)
ret = 1
for i in range(m+1):
t = a[i+1] - a[i] - 2
if t < 0:
ret = 0
break
ret *= fib_l[t]
print((ret % 1000000007)) | 19 | 21 | 405 | 457 | n, m = [int(i) for i in input().split()]
a = [-1] + [int(eval(input())) for _ in range(m)] + [n + 1]
fib_l = [-1] * (n + 3)
def make_fib(n):
fib_l[0] = fib_l[1] = 1
for i in range(2, n):
fib_l[i] = fib_l[i - 1] + fib_l[i - 2]
make_fib(n + 3)
ret = 1
for i in range(m + 1):
t = a[i + 1] - a[i] - 2
if t < 0:
ret = 0
break
ret *= fib_l[t]
print((ret % 1000000007))
| from sys import stdin
n, m = [int(i) for i in stdin.readline().rstrip().split()]
a = [-1] + [int(stdin.readline()) for _ in range(m)] + [n + 1]
fib_l = [-1] * (n + 3)
def make_fib(n):
fib_l[0] = fib_l[1] = 1
for i in range(2, n):
fib_l[i] = fib_l[i - 1] + fib_l[i - 2]
make_fib(n + 3)
ret = 1
for i in range(m + 1):
t = a[i + 1] - a[i] - 2
if t < 0:
ret = 0
break
ret *= fib_l[t]
print((ret % 1000000007))
| false | 9.52381 | [
"-n, m = [int(i) for i in input().split()]",
"-a = [-1] + [int(eval(input())) for _ in range(m)] + [n + 1]",
"+from sys import stdin",
"+",
"+n, m = [int(i) for i in stdin.readline().rstrip().split()]",
"+a = [-1] + [int(stdin.readline()) for _ in range(m)] + [n + 1]"
]
| false | 0.086412 | 0.042954 | 2.011747 | [
"s760395888",
"s129860592"
]
|
u863442865 | p02936 | python | s106886610 | s880017161 | 1,877 | 1,182 | 80,516 | 80,544 | Accepted | Accepted | 37.03 | import sys
sys.setrecursionlimit(500000)
N, Q = list(map(int, input().split()))
G = [set() for _ in range(N)]
cnt = [0]*N
visited = [0]*N
def dfs(start_node):
for i in G[start_node]:
if visited[i]==0:
visited[i]=1
cnt[i] += cnt[start_node]
dfs(i)
for _ in range(N-1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
for i in range(Q):
node, x = list(map(int, input().split()))
node -= 1
cnt[node] += x
visited[0]=1
#dfs(0)
st = [0]
while st:
v = st.pop()
for u in G[v]:
if visited[u]: continue
visited[u] = 1
cnt[u] += cnt[v]
st.append(u)
print((*cnt))
| import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
G = [set() for _ in range(N)]
cnt = [0]*N
visited = [0]*N
for _ in range(N-1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
for i in range(Q):
node, x = list(map(int, input().split()))
node -= 1
cnt[node] += x
visited[0]=1
st = [0]
while st:
v = st.pop()
for u in G[v]:
if visited[u]:
continue
visited[u] = 1
cnt[u] += cnt[v]
st.append(u)
print((*cnt)) | 39 | 33 | 730 | 596 | import sys
sys.setrecursionlimit(500000)
N, Q = list(map(int, input().split()))
G = [set() for _ in range(N)]
cnt = [0] * N
visited = [0] * N
def dfs(start_node):
for i in G[start_node]:
if visited[i] == 0:
visited[i] = 1
cnt[i] += cnt[start_node]
dfs(i)
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
for i in range(Q):
node, x = list(map(int, input().split()))
node -= 1
cnt[node] += x
visited[0] = 1
# dfs(0)
st = [0]
while st:
v = st.pop()
for u in G[v]:
if visited[u]:
continue
visited[u] = 1
cnt[u] += cnt[v]
st.append(u)
print((*cnt))
| import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
G = [set() for _ in range(N)]
cnt = [0] * N
visited = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
for i in range(Q):
node, x = list(map(int, input().split()))
node -= 1
cnt[node] += x
visited[0] = 1
st = [0]
while st:
v = st.pop()
for u in G[v]:
if visited[u]:
continue
visited[u] = 1
cnt[u] += cnt[v]
st.append(u)
print((*cnt))
| false | 15.384615 | [
"+input = sys.stdin.readline",
"-",
"-",
"-def dfs(start_node):",
"- for i in G[start_node]:",
"- if visited[i] == 0:",
"- visited[i] = 1",
"- cnt[i] += cnt[start_node]",
"- dfs(i)",
"-",
"-",
"-# dfs(0)"
]
| false | 0.008288 | 0.066206 | 0.125188 | [
"s106886610",
"s880017161"
]
|
u855775311 | p02376 | python | s196109310 | s813184390 | 50 | 40 | 7,888 | 7,856 | Accepted | Accepted | 20 | def main():
nvertices, nedges = list(map(int, input().split()))
adj = [[0] * nvertices for i in range(nvertices)]
for i in range(nedges):
u, v, c = list(map(int, input().split()))
adj[u][v] = c
ans = 0
while True:
parents = bfs(0, nvertices - 1, adj)
if parents is None:
break
v = nvertices - 1
flow = float('inf')
while parents[v] != -1:
u = parents[v]
flow = min(flow, adj[u][v])
v = u
ans += flow
v = nvertices - 1
while parents[v] != -1:
u = parents[v]
adj[u][v] -= flow
adj[v][u] += flow
v = u
print(ans)
def bfs(s, t, adj):
nvertices = len(adj)
visited = [False] * nvertices
parents = [-1] * nvertices
visited[s] = True
que = [s]
while que:
u = que.pop(0)
if u == t:
return parents
for v in range(nvertices):
if not visited[v] and adj[u][v] > 0:
visited[v] = True
parents[v] = u
que.append(v)
return None
main() | def main():
nvertices, nedges = list(map(int, input().split()))
adj = [[0] * nvertices for j in range(nvertices)]
for i in range(nedges):
u, v, c = list(map(int, input().split()))
adj[u][v] = c
INF = float('inf')
ans = 0
while True:
parents = bfs(0, nvertices - 1, adj)
if parents is None:
break
v = nvertices - 1
f = INF
while parents[v] != -1:
u = parents[v]
f = min(f, adj[u][v])
v = u
ans += f
v = nvertices - 1
while parents[v] != -1:
u = parents[v]
adj[u][v] -= f
adj[v][u] += f
v = u
print(ans)
def bfs(s, t, adj):
nvertices = len(adj)
visited = [False] * nvertices
visited[s] = True
que = [s]
parents = [-1] * nvertices
while que:
u = que.pop(0)
if u == t:
return parents
for v in range(nvertices):
if not visited[v] and adj[u][v] > 0:
parents[v] = u
visited[v] = True
que.append(v)
return None
main() | 49 | 52 | 1,184 | 1,185 | def main():
nvertices, nedges = list(map(int, input().split()))
adj = [[0] * nvertices for i in range(nvertices)]
for i in range(nedges):
u, v, c = list(map(int, input().split()))
adj[u][v] = c
ans = 0
while True:
parents = bfs(0, nvertices - 1, adj)
if parents is None:
break
v = nvertices - 1
flow = float("inf")
while parents[v] != -1:
u = parents[v]
flow = min(flow, adj[u][v])
v = u
ans += flow
v = nvertices - 1
while parents[v] != -1:
u = parents[v]
adj[u][v] -= flow
adj[v][u] += flow
v = u
print(ans)
def bfs(s, t, adj):
nvertices = len(adj)
visited = [False] * nvertices
parents = [-1] * nvertices
visited[s] = True
que = [s]
while que:
u = que.pop(0)
if u == t:
return parents
for v in range(nvertices):
if not visited[v] and adj[u][v] > 0:
visited[v] = True
parents[v] = u
que.append(v)
return None
main()
| def main():
nvertices, nedges = list(map(int, input().split()))
adj = [[0] * nvertices for j in range(nvertices)]
for i in range(nedges):
u, v, c = list(map(int, input().split()))
adj[u][v] = c
INF = float("inf")
ans = 0
while True:
parents = bfs(0, nvertices - 1, adj)
if parents is None:
break
v = nvertices - 1
f = INF
while parents[v] != -1:
u = parents[v]
f = min(f, adj[u][v])
v = u
ans += f
v = nvertices - 1
while parents[v] != -1:
u = parents[v]
adj[u][v] -= f
adj[v][u] += f
v = u
print(ans)
def bfs(s, t, adj):
nvertices = len(adj)
visited = [False] * nvertices
visited[s] = True
que = [s]
parents = [-1] * nvertices
while que:
u = que.pop(0)
if u == t:
return parents
for v in range(nvertices):
if not visited[v] and adj[u][v] > 0:
parents[v] = u
visited[v] = True
que.append(v)
return None
main()
| false | 5.769231 | [
"- adj = [[0] * nvertices for i in range(nvertices)]",
"+ adj = [[0] * nvertices for j in range(nvertices)]",
"+ INF = float(\"inf\")",
"- flow = float(\"inf\")",
"+ f = INF",
"- flow = min(flow, adj[u][v])",
"+ f = min(f, adj[u][v])",
"- ans += flow",
"+ ans += f",
"- adj[u][v] -= flow",
"- adj[v][u] += flow",
"+ adj[u][v] -= f",
"+ adj[v][u] += f",
"- parents = [-1] * nvertices",
"+ parents = [-1] * nvertices",
"+ parents[v] = u",
"- parents[v] = u"
]
| false | 0.037972 | 0.007936 | 4.784715 | [
"s196109310",
"s813184390"
]
|
u504836877 | p03682 | python | s335391229 | s639211207 | 1,734 | 1,279 | 55,384 | 43,972 | Accepted | Accepted | 26.24 | from operator import itemgetter
import heapq
N = int(eval(input()))
X = [[int(p) for p in input().split()] for _ in range(N)]
X.sort()
for i in range(N):
X[i].append(i)
Y = sorted(X, key=itemgetter(1))
h = []
for i in range(N-1):
heapq.heappush(h, (X[i+1][0]-X[i][0], i+1, i))
heapq.heappush(h, (Y[i+1][1]-Y[i][1], Y[i+1][2], Y[i][2]))
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
def find_root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.find_root(x) == self.find_root(y)
def count(self, x):
return -self.root[self.find_root(x)]
UF = UnionFind(N)
ans = 0
while h:
t = heapq.heappop(h)
if UF.isSameGroup(t[1], t[2]):
continue
ans += t[0]
UF.unite(t[1], t[2])
print(ans) | from operator import itemgetter
import heapq
N = int(eval(input()))
pos = [[int(p) for p in input().split()] for _ in range(N)]
pos.sort()
for i in range(N):
pos[i].append(i)
Y = sorted(pos, key=itemgetter(1))
Y_idx = [0]*N
for i in range(N):
Y_idx[Y[i][2]] = i
ans = 0
used = [0]*N
used[0] = 1
h = []
c = 1
idx = Y_idx[0]
heapq.heappush(h, (pos[c][0]-pos[c-1][0], 1))
if idx > 0:
heapq.heappush(h, (Y[idx][1]-Y[idx-1][1], Y[idx-1][2]))
if idx < N-1:
heapq.heappush(h, (Y[idx+1][1]-Y[idx][1], Y[idx+1][2]))
cnt = 0
while cnt < N-1:
t = heapq.heappop(h)
if used[t[1]] == 1:
continue
c = t[1]
used[c] = 1
cnt += 1
ans += t[0]
if c > 0 and used[c-1] == 0:
heapq.heappush(h, (pos[c][0]-pos[c-1][0], c-1))
if c < N-1 and used[c+1] == 0:
heapq.heappush(h, (pos[c+1][0]-pos[c][0], c+1))
idx = Y_idx[c]
if idx > 0 and used[Y[idx-1][2]] == 0:
heapq.heappush(h, (Y[idx][1]-Y[idx-1][1], Y[idx-1][2]))
if idx < N-1 and used[Y[idx+1][2]] == 0:
heapq.heappush(h, (Y[idx+1][1]-Y[idx][1], Y[idx+1][2]))
print(ans) | 62 | 47 | 1,495 | 1,169 | from operator import itemgetter
import heapq
N = int(eval(input()))
X = [[int(p) for p in input().split()] for _ in range(N)]
X.sort()
for i in range(N):
X[i].append(i)
Y = sorted(X, key=itemgetter(1))
h = []
for i in range(N - 1):
heapq.heappush(h, (X[i + 1][0] - X[i][0], i + 1, i))
heapq.heappush(h, (Y[i + 1][1] - Y[i][1], Y[i + 1][2], Y[i][2]))
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find_root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.find_root(x) == self.find_root(y)
def count(self, x):
return -self.root[self.find_root(x)]
UF = UnionFind(N)
ans = 0
while h:
t = heapq.heappop(h)
if UF.isSameGroup(t[1], t[2]):
continue
ans += t[0]
UF.unite(t[1], t[2])
print(ans)
| from operator import itemgetter
import heapq
N = int(eval(input()))
pos = [[int(p) for p in input().split()] for _ in range(N)]
pos.sort()
for i in range(N):
pos[i].append(i)
Y = sorted(pos, key=itemgetter(1))
Y_idx = [0] * N
for i in range(N):
Y_idx[Y[i][2]] = i
ans = 0
used = [0] * N
used[0] = 1
h = []
c = 1
idx = Y_idx[0]
heapq.heappush(h, (pos[c][0] - pos[c - 1][0], 1))
if idx > 0:
heapq.heappush(h, (Y[idx][1] - Y[idx - 1][1], Y[idx - 1][2]))
if idx < N - 1:
heapq.heappush(h, (Y[idx + 1][1] - Y[idx][1], Y[idx + 1][2]))
cnt = 0
while cnt < N - 1:
t = heapq.heappop(h)
if used[t[1]] == 1:
continue
c = t[1]
used[c] = 1
cnt += 1
ans += t[0]
if c > 0 and used[c - 1] == 0:
heapq.heappush(h, (pos[c][0] - pos[c - 1][0], c - 1))
if c < N - 1 and used[c + 1] == 0:
heapq.heappush(h, (pos[c + 1][0] - pos[c][0], c + 1))
idx = Y_idx[c]
if idx > 0 and used[Y[idx - 1][2]] == 0:
heapq.heappush(h, (Y[idx][1] - Y[idx - 1][1], Y[idx - 1][2]))
if idx < N - 1 and used[Y[idx + 1][2]] == 0:
heapq.heappush(h, (Y[idx + 1][1] - Y[idx][1], Y[idx + 1][2]))
print(ans)
| false | 24.193548 | [
"-X = [[int(p) for p in input().split()] for _ in range(N)]",
"-X.sort()",
"+pos = [[int(p) for p in input().split()] for _ in range(N)]",
"+pos.sort()",
"- X[i].append(i)",
"-Y = sorted(X, key=itemgetter(1))",
"+ pos[i].append(i)",
"+Y = sorted(pos, key=itemgetter(1))",
"+Y_idx = [0] * N",
"+for i in range(N):",
"+ Y_idx[Y[i][2]] = i",
"+ans = 0",
"+used = [0] * N",
"+used[0] = 1",
"-for i in range(N - 1):",
"- heapq.heappush(h, (X[i + 1][0] - X[i][0], i + 1, i))",
"- heapq.heappush(h, (Y[i + 1][1] - Y[i][1], Y[i + 1][2], Y[i][2]))",
"-",
"-",
"-class UnionFind:",
"- def __init__(self, n):",
"- self.n = n",
"- self.root = [-1] * (n + 1)",
"- self.rnk = [0] * (n + 1)",
"-",
"- def find_root(self, x):",
"- if self.root[x] < 0:",
"- return x",
"- else:",
"- self.root[x] = self.find_root(self.root[x])",
"- return self.root[x]",
"-",
"- def unite(self, x, y):",
"- x = self.find_root(x)",
"- y = self.find_root(y)",
"- if x == y:",
"- return",
"- elif self.rnk[x] > self.rnk[y]:",
"- self.root[x] += self.root[y]",
"- self.root[y] = x",
"- else:",
"- self.root[y] += self.root[x]",
"- self.root[x] = y",
"- if self.rnk[x] == self.rnk[y]:",
"- self.rnk[y] += 1",
"-",
"- def isSameGroup(self, x, y):",
"- return self.find_root(x) == self.find_root(y)",
"-",
"- def count(self, x):",
"- return -self.root[self.find_root(x)]",
"-",
"-",
"-UF = UnionFind(N)",
"-ans = 0",
"-while h:",
"+c = 1",
"+idx = Y_idx[0]",
"+heapq.heappush(h, (pos[c][0] - pos[c - 1][0], 1))",
"+if idx > 0:",
"+ heapq.heappush(h, (Y[idx][1] - Y[idx - 1][1], Y[idx - 1][2]))",
"+if idx < N - 1:",
"+ heapq.heappush(h, (Y[idx + 1][1] - Y[idx][1], Y[idx + 1][2]))",
"+cnt = 0",
"+while cnt < N - 1:",
"- if UF.isSameGroup(t[1], t[2]):",
"+ if used[t[1]] == 1:",
"+ c = t[1]",
"+ used[c] = 1",
"+ cnt += 1",
"- UF.unite(t[1], t[2])",
"+ if c > 0 and used[c - 1] == 0:",
"+ heapq.heappush(h, (pos[c][0] - pos[c - 1][0], c - 1))",
"+ if c < N - 1 and used[c + 1] == 0:",
"+ heapq.heappush(h, (pos[c + 1][0] - pos[c][0], c + 1))",
"+ idx = Y_idx[c]",
"+ if idx > 0 and used[Y[idx - 1][2]] == 0:",
"+ heapq.heappush(h, (Y[idx][1] - Y[idx - 1][1], Y[idx - 1][2]))",
"+ if idx < N - 1 and used[Y[idx + 1][2]] == 0:",
"+ heapq.heappush(h, (Y[idx + 1][1] - Y[idx][1], Y[idx + 1][2]))"
]
| false | 0.040824 | 0.039179 | 1.041977 | [
"s335391229",
"s639211207"
]
|
u038404105 | p02678 | python | s966236436 | s782640272 | 1,364 | 698 | 34,652 | 34,228 | Accepted | Accepted | 48.83 | N, M = list(map(int, input().split()))
to = [[] for i in range(N+1)]
dist = [100001 for i in range(N+1)]
flug = [1 for i in range(N+1)]
to[0].append(1)
dist[0] = 0
flug[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
to[a].append(b)
to[b].append(a)
q = []
q.append(0)
while (len(q) != 0):
i = q.pop(0)
for j in to[i]:
if dist[j] == 100001:
dist[j] = dist[i] +1
flug[j] = i
q.append(j)
print("Yes")
for i in range(2,N+1):
print((flug[i])) | from collections import deque
N, M = list(map(int, input().split()))
to = [[] for i in range(N+1)]
#dist = [100001 for i in range(N+1)]
flug = [0 for i in range(N+1)]
to[0].append(1)
#dist[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
to[a].append(b)
to[b].append(a)
q = deque([0])
while (len(q) != 0):
i = q.popleft()
for j in to[i]:
if flug[j] == 0:
# dist[j] = dist[i] +1
flug[j] = i
q.append(j)
print("Yes")
for i in range(2,N+1):
print((flug[i]))
| 29 | 27 | 542 | 555 | N, M = list(map(int, input().split()))
to = [[] for i in range(N + 1)]
dist = [100001 for i in range(N + 1)]
flug = [1 for i in range(N + 1)]
to[0].append(1)
dist[0] = 0
flug[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
to[a].append(b)
to[b].append(a)
q = []
q.append(0)
while len(q) != 0:
i = q.pop(0)
for j in to[i]:
if dist[j] == 100001:
dist[j] = dist[i] + 1
flug[j] = i
q.append(j)
print("Yes")
for i in range(2, N + 1):
print((flug[i]))
| from collections import deque
N, M = list(map(int, input().split()))
to = [[] for i in range(N + 1)]
# dist = [100001 for i in range(N+1)]
flug = [0 for i in range(N + 1)]
to[0].append(1)
# dist[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
to[a].append(b)
to[b].append(a)
q = deque([0])
while len(q) != 0:
i = q.popleft()
for j in to[i]:
if flug[j] == 0:
# dist[j] = dist[i] +1
flug[j] = i
q.append(j)
print("Yes")
for i in range(2, N + 1):
print((flug[i]))
| false | 6.896552 | [
"+from collections import deque",
"+",
"-dist = [100001 for i in range(N + 1)]",
"-flug = [1 for i in range(N + 1)]",
"+# dist = [100001 for i in range(N+1)]",
"+flug = [0 for i in range(N + 1)]",
"-dist[0] = 0",
"-flug[0] = 0",
"+# dist[0] = 0",
"-q = []",
"-q.append(0)",
"+q = deque([0])",
"- i = q.pop(0)",
"+ i = q.popleft()",
"- if dist[j] == 100001:",
"- dist[j] = dist[i] + 1",
"+ if flug[j] == 0:",
"+ # dist[j] = dist[i] +1"
]
| false | 0.088036 | 0.088957 | 0.989652 | [
"s966236436",
"s782640272"
]
|
u207241407 | p03680 | python | s186094374 | s747948738 | 81 | 55 | 7,852 | 7,068 | Accepted | Accepted | 32.1 | import sys
n = int(eval(input()))
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]
button = 1
for i in range(n):
if button == 2:
print(i)
break
button = a[button]
else:
print((-1)) | import sys
n = list(map(int, sys.stdin))
button = 1
for i in range(n[0]):
if button == 2:
print(i)
break
button = n[button]
else:
print((-1)) | 14 | 13 | 223 | 182 | import sys
n = int(eval(input()))
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]
button = 1
for i in range(n):
if button == 2:
print(i)
break
button = a[button]
else:
print((-1))
| import sys
n = list(map(int, sys.stdin))
button = 1
for i in range(n[0]):
if button == 2:
print(i)
break
button = n[button]
else:
print((-1))
| false | 7.142857 | [
"-n = int(eval(input()))",
"-a = [0] + [int(sys.stdin.readline()) for _ in range(n)]",
"+n = list(map(int, sys.stdin))",
"-for i in range(n):",
"+for i in range(n[0]):",
"- button = a[button]",
"+ button = n[button]"
]
| false | 0.076782 | 0.035869 | 2.140645 | [
"s186094374",
"s747948738"
]
|
u995004106 | p02679 | python | s175353956 | s088653356 | 971 | 840 | 228,404 | 236,244 | Accepted | Accepted | 13.49 | def modpow(a,n,p):
if n==0:
return 1
x=modpow(a,n//2,p)
x=(x*x)%p
if (n%2)==1:
x=(x*a)%p
return x%p
def modinv(a,p):
return modpow(a,p-2,p)
def ggcd(a,b):
if(b==0):
return a
return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(eval(input()))
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
#ใคใกใผใธ็ใซใฏa/bใๆ ผ็ดใใฆใใๆใ
#ai/bi==-bj/ajใชใใใก
a=fish[i][0]
b=fish[i][1]
g=ggcd(abs(a),abs(b))
if g!=0: #ggcdใฎๅฎ็พฉใใa=b=0ใชใ0ใซใชใใใ(a=0,b!=0ใชใb,้ใใใใ)
a=a//g
b=b//g
#ใใใใธใใงใa,bใใใฎgcdใงๅฒใใใจใซใใๆญฃ่ฆๅใๅฎไบใใฆใใใฏใ
if b<0:
a=-a
b=-b
#b<0ใฎๆใซๅผทๅถ็ใซbใๆญฃใฎๅคใซๅคๆใใฆใๅฝฑ้ฟใฏใชใ(ใใใๅใพใใใจๅพใ
ๅฌใใ)
if (a!=0)or(b!=0):
if d.get(a)==None:
d[a]={}
d[a][b]=1
else:
if d[a].get(b)==None:
d[a][b]=1
else:
val=d[a].get(b)
d[a][b]=val+1
fishcomp.append([a, b])
else:
both0=both0+1
#print(d)
#print(fishcomp)
fishcomp=list(map(list,set(map(tuple,fishcomp)))) #ไบๆฌกๅ
้
ๅใฎset(ๅฐๅณใซreferenceใใชใใใค)
#print(fishcomp)
length=N-both0
sets=[]
#ไปฅไธใงใฏai/bi==-bj/ajใฎ็ตใฟใๆขใใฆใใใd[a][b]ใฎๅๆฐใจd[-b][a]ใฎๅๆฐใฎใฟๆขใใฐ่ฏใ
#ๅฎใฏbใๆญฃใซๅบๅฎใใใฎใใใใง็ใใใ[a b]โ[-b a][b,-a]ใจ2ใคๅ่ฃใๅบใใใ
#a>0ใชใ[-b a]ใซใa<0ใชใ[b,-a]ใฎไธใคใซใชใใa=0ใชใ[ยฑb 0]ใ ใใใใใฏไธใงไธๆฌใใฆ1ใซใพใจใใฆใใใใ็กๅ้ก
#ๅๆใซd[a][b]ใจๅใใใฆใใกใชใฎใฏd[b][-a],d[-b][a]ใงใใใใไธๆนใฎใฟๅใใฐๅคงไธๅคซ
for i in fishcomp:
a=i[0]
b=i[1]
val1=d[a][b]
#print(a,b,val1)
if d.get(-b)!=None:
if d[-b].get(a)!=None:
val2=d[-b][a]
sets.append([val1,val2])
length=length-(val2+val1)
#print(sets,length)
pro=1
for i in sets:
pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p
#print(pro)
print(((pow(2,length,p)*pro-1+both0)%p)) | def modpow(a,n,p):
if n==0:
return 1
x=modpow(a,n//2,p)
x=(x*x)%p
if (n%2)==1:
x=(x*a)%p
return x%p
def modinv(a,p):
return modpow(a,p-2,p)
def ggcd(a,b):
if(b==0):
return a
return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(eval(input()))
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
a=fish[i][0]
b=fish[i][1]
g=ggcd(a,b)
if g!=0:
a=a//g
b=b//g
if b<0:
a=-a
b=-b
if (a!=0)or(b!=0):
if d.get(a)==None:
d[a]={}
d[a][b]=1
else:
if d[a].get(b)==None:
d[a][b]=1
else:
val=d[a].get(b)
d[a][b]=val+1
fishcomp.append([a, b])
else:
both0=both0+1
#print(d)
#print(fishcomp)
fishcomp=list(map(list,set(map(tuple,fishcomp))))
#print(fishcomp)
length=N-both0
sets=[]
for i in fishcomp:
a=i[0]
b=i[1]
val1=d[a][b]
#print(a,b,val1)
if d.get(-b)!=None:
if d[-b].get(a)!=None:
val2=d[-b][a]
sets.append([val1,val2])
length=length-(val2+val1)
#print(sets,length)
pro=1
for i in sets:
pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p
#print(pro)
print(((pow(2,length,p)*pro-1+both0)%p))
| 83 | 75 | 1,964 | 1,498 | def modpow(a, n, p):
if n == 0:
return 1
x = modpow(a, n // 2, p)
x = (x * x) % p
if (n % 2) == 1:
x = (x * a) % p
return x % p
def modinv(a, p):
return modpow(a, p - 2, p)
def ggcd(a, b):
if b == 0:
return a
return ggcd(b, a % b)
import math
import fractions
import collections
import itertools
import pprint
N = int(eval(input()))
l1 = []
adivb = []
bis0 = 0
bdiva = []
ais0 = 0
both0 = 0
p = 10**9 + 7
fish = [list(map(int, input().split())) for _ in range(N)]
fishcomp = []
d = {}
for i in range(N):
# ใคใกใผใธ็ใซใฏa/bใๆ ผ็ดใใฆใใๆใ
# ai/bi==-bj/ajใชใใใก
a = fish[i][0]
b = fish[i][1]
g = ggcd(abs(a), abs(b))
if g != 0: # ggcdใฎๅฎ็พฉใใa=b=0ใชใ0ใซใชใใใ(a=0,b!=0ใชใb,้ใใใใ)
a = a // g
b = b // g
# ใใใใธใใงใa,bใใใฎgcdใงๅฒใใใจใซใใๆญฃ่ฆๅใๅฎไบใใฆใใใฏใ
if b < 0:
a = -a
b = -b
# b<0ใฎๆใซๅผทๅถ็ใซbใๆญฃใฎๅคใซๅคๆใใฆใๅฝฑ้ฟใฏใชใ(ใใใๅใพใใใจๅพใ
ๅฌใใ)
if (a != 0) or (b != 0):
if d.get(a) == None:
d[a] = {}
d[a][b] = 1
else:
if d[a].get(b) == None:
d[a][b] = 1
else:
val = d[a].get(b)
d[a][b] = val + 1
fishcomp.append([a, b])
else:
both0 = both0 + 1
# print(d)
# print(fishcomp)
fishcomp = list(map(list, set(map(tuple, fishcomp)))) # ไบๆฌกๅ
้
ๅใฎset(ๅฐๅณใซreferenceใใชใใใค)
# print(fishcomp)
length = N - both0
sets = []
# ไปฅไธใงใฏai/bi==-bj/ajใฎ็ตใฟใๆขใใฆใใใd[a][b]ใฎๅๆฐใจd[-b][a]ใฎๅๆฐใฎใฟๆขใใฐ่ฏใ
# ๅฎใฏbใๆญฃใซๅบๅฎใใใฎใใใใง็ใใใ[a b]โ[-b a][b,-a]ใจ2ใคๅ่ฃใๅบใใใ
# a>0ใชใ[-b a]ใซใa<0ใชใ[b,-a]ใฎไธใคใซใชใใa=0ใชใ[ยฑb 0]ใ ใใใใใฏไธใงไธๆฌใใฆ1ใซใพใจใใฆใใใใ็กๅ้ก
# ๅๆใซd[a][b]ใจๅใใใฆใใกใชใฎใฏd[b][-a],d[-b][a]ใงใใใใไธๆนใฎใฟๅใใฐๅคงไธๅคซ
for i in fishcomp:
a = i[0]
b = i[1]
val1 = d[a][b]
# print(a,b,val1)
if d.get(-b) != None:
if d[-b].get(a) != None:
val2 = d[-b][a]
sets.append([val1, val2])
length = length - (val2 + val1)
# print(sets,length)
pro = 1
for i in sets:
pro = (pro * (pow(2, i[0], p) + pow(2, i[1], p) - 1)) % p
# print(pro)
print(((pow(2, length, p) * pro - 1 + both0) % p))
| def modpow(a, n, p):
if n == 0:
return 1
x = modpow(a, n // 2, p)
x = (x * x) % p
if (n % 2) == 1:
x = (x * a) % p
return x % p
def modinv(a, p):
return modpow(a, p - 2, p)
def ggcd(a, b):
if b == 0:
return a
return ggcd(b, a % b)
import math
import fractions
import collections
import itertools
import pprint
N = int(eval(input()))
l1 = []
adivb = []
bis0 = 0
bdiva = []
ais0 = 0
both0 = 0
p = 10**9 + 7
fish = [list(map(int, input().split())) for _ in range(N)]
fishcomp = []
d = {}
for i in range(N):
a = fish[i][0]
b = fish[i][1]
g = ggcd(a, b)
if g != 0:
a = a // g
b = b // g
if b < 0:
a = -a
b = -b
if (a != 0) or (b != 0):
if d.get(a) == None:
d[a] = {}
d[a][b] = 1
else:
if d[a].get(b) == None:
d[a][b] = 1
else:
val = d[a].get(b)
d[a][b] = val + 1
fishcomp.append([a, b])
else:
both0 = both0 + 1
# print(d)
# print(fishcomp)
fishcomp = list(map(list, set(map(tuple, fishcomp))))
# print(fishcomp)
length = N - both0
sets = []
for i in fishcomp:
a = i[0]
b = i[1]
val1 = d[a][b]
# print(a,b,val1)
if d.get(-b) != None:
if d[-b].get(a) != None:
val2 = d[-b][a]
sets.append([val1, val2])
length = length - (val2 + val1)
# print(sets,length)
pro = 1
for i in sets:
pro = (pro * (pow(2, i[0], p) + pow(2, i[1], p) - 1)) % p
# print(pro)
print(((pow(2, length, p) * pro - 1 + both0) % p))
| false | 9.638554 | [
"- # ใคใกใผใธ็ใซใฏa/bใๆ ผ็ดใใฆใใๆใ",
"- # ai/bi==-bj/ajใชใใใก",
"- g = ggcd(abs(a), abs(b))",
"- if g != 0: # ggcdใฎๅฎ็พฉใใa=b=0ใชใ0ใซใชใใใ(a=0,b!=0ใชใb,้ใใใใ)",
"+ g = ggcd(a, b)",
"+ if g != 0:",
"- # ใใใใธใใงใa,bใใใฎgcdใงๅฒใใใจใซใใๆญฃ่ฆๅใๅฎไบใใฆใใใฏใ",
"- # b<0ใฎๆใซๅผทๅถ็ใซbใๆญฃใฎๅคใซๅคๆใใฆใๅฝฑ้ฟใฏใชใ(ใใใๅใพใใใจๅพใ
ๅฌใใ)",
"-fishcomp = list(map(list, set(map(tuple, fishcomp)))) # ไบๆฌกๅ
้
ๅใฎset(ๅฐๅณใซreferenceใใชใใใค)",
"+fishcomp = list(map(list, set(map(tuple, fishcomp))))",
"-# ไปฅไธใงใฏai/bi==-bj/ajใฎ็ตใฟใๆขใใฆใใใd[a][b]ใฎๅๆฐใจd[-b][a]ใฎๅๆฐใฎใฟๆขใใฐ่ฏใ",
"-# ๅฎใฏbใๆญฃใซๅบๅฎใใใฎใใใใง็ใใใ[a b]โ[-b a][b,-a]ใจ2ใคๅ่ฃใๅบใใใ",
"-# a>0ใชใ[-b a]ใซใa<0ใชใ[b,-a]ใฎไธใคใซใชใใa=0ใชใ[ยฑb 0]ใ ใใใใใฏไธใงไธๆฌใใฆ1ใซใพใจใใฆใใใใ็กๅ้ก",
"-# ๅๆใซd[a][b]ใจๅใใใฆใใกใชใฎใฏd[b][-a],d[-b][a]ใงใใใใไธๆนใฎใฟๅใใฐๅคงไธๅคซ"
]
| false | 0.146095 | 0.038217 | 3.822778 | [
"s175353956",
"s088653356"
]
|
u578441226 | p03999 | python | s633732299 | s272872555 | 29 | 26 | 9,096 | 9,096 | Accepted | Accepted | 10.34 | def dfs(i,sum1):
global ss
#print(i,sum1)
if i == len(s):
return sum(list(map(int,sum1.split("+"))))
return dfs(i + 1, sum1 + s[i]) + dfs(i + 1, sum1 + "+" +s[i])
s = eval(input())
ss = 0
print((dfs(1,s[0]))) | def dfs(i,sum1):
if i == len(s):
return sum(list(map(int,sum1.split("+"))))
return dfs(i+1,sum1 + "+" + s[i])+dfs(i+1,sum1 + s[i])
s = eval(input())#ไธไปฅไธ9ไปฅไธ
print((dfs(1,s[0]))) | 11 | 6 | 236 | 189 | def dfs(i, sum1):
global ss
# print(i,sum1)
if i == len(s):
return sum(list(map(int, sum1.split("+"))))
return dfs(i + 1, sum1 + s[i]) + dfs(i + 1, sum1 + "+" + s[i])
s = eval(input())
ss = 0
print((dfs(1, s[0])))
| def dfs(i, sum1):
if i == len(s):
return sum(list(map(int, sum1.split("+"))))
return dfs(i + 1, sum1 + "+" + s[i]) + dfs(i + 1, sum1 + s[i])
s = eval(input()) # ไธไปฅไธ9ไปฅไธ
print((dfs(1, s[0])))
| false | 45.454545 | [
"- global ss",
"- # print(i,sum1)",
"- return dfs(i + 1, sum1 + s[i]) + dfs(i + 1, sum1 + \"+\" + s[i])",
"+ return dfs(i + 1, sum1 + \"+\" + s[i]) + dfs(i + 1, sum1 + s[i])",
"-s = eval(input())",
"-ss = 0",
"+s = eval(input()) # ไธไปฅไธ9ไปฅไธ"
]
| false | 0.046672 | 0.045086 | 1.035178 | [
"s633732299",
"s272872555"
]
|
u171366497 | p03305 | python | s400036633 | s577431987 | 1,625 | 1,435 | 115,616 | 104,212 | Accepted | Accepted | 11.69 | import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush,heappop
from itertools import accumulate
N,m,s,t=list(map(int,input().split()))
en=defaultdict(set)
sneek=defaultdict(set)
for i in range(m):
u,v,a,b=list(map(int,input().split()))
en[u]|={(a,v)}
en[v]|={(a,u)}
sneek[u]|={(b,v)}
sneek[v]|={(b,u)}
inf=float('inf')
def makedist(first,branch):
dist=[inf]*(N+1)
dist[first]=0
check=[(0,first)]
while len(check)>0:
d,now=heappop(check)
if dist[now]<d:
continue
for lenth,nex in branch[now]:
if d+lenth<dist[nex]:
dist[nex]=d+lenth
heappush(check,(d+lenth,nex))
return dist
disten=makedist(s,en)
distsneek=makedist(t,sneek)
ans=list(accumulate([y+s for y,s in zip(disten,distsneek)][::-1],min))
big=10**15
for i in range(N-1,-1,-1):
print((big-ans[i]))
#https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/4993088 | import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush,heappop
from itertools import accumulate
N,m,s,t=map(int,input().split())
en=[set() for i in range(N+1)]
sneek=[set() for i in range(N+1)]
for i in range(m):
u,v,a,b=map(int,input().split())
en[u]|={(a,v)}
en[v]|={(a,u)}
sneek[u]|={(b,v)}
sneek[v]|={(b,u)}
inf=float('inf')
def makedist(first,branch):
dist=[inf]*(N+1)
dist[first]=0
check=[(0,first)]
while len(check)>0:
d,now=heappop(check)
if dist[now]<d:
continue
for lenth,nex in branch[now]:
if d+lenth<dist[nex]:
dist[nex]=d+lenth
heappush(check,(d+lenth,nex))
return dist
disten=makedist(s,en)
distsneek=makedist(t,sneek)
ans=list(accumulate([y+s for y,s in zip(disten,distsneek)][::-1],min))
big=10**15
[print(big-ans[i]) for i in range(N-1,-1,-1)]
#https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/4993088
| 35 | 34 | 1,016 | 1,034 | import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop
from itertools import accumulate
N, m, s, t = list(map(int, input().split()))
en = defaultdict(set)
sneek = defaultdict(set)
for i in range(m):
u, v, a, b = list(map(int, input().split()))
en[u] |= {(a, v)}
en[v] |= {(a, u)}
sneek[u] |= {(b, v)}
sneek[v] |= {(b, u)}
inf = float("inf")
def makedist(first, branch):
dist = [inf] * (N + 1)
dist[first] = 0
check = [(0, first)]
while len(check) > 0:
d, now = heappop(check)
if dist[now] < d:
continue
for lenth, nex in branch[now]:
if d + lenth < dist[nex]:
dist[nex] = d + lenth
heappush(check, (d + lenth, nex))
return dist
disten = makedist(s, en)
distsneek = makedist(t, sneek)
ans = list(accumulate([y + s for y, s in zip(disten, distsneek)][::-1], min))
big = 10**15
for i in range(N - 1, -1, -1):
print((big - ans[i]))
# https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/4993088
| import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop
from itertools import accumulate
N, m, s, t = map(int, input().split())
en = [set() for i in range(N + 1)]
sneek = [set() for i in range(N + 1)]
for i in range(m):
u, v, a, b = map(int, input().split())
en[u] |= {(a, v)}
en[v] |= {(a, u)}
sneek[u] |= {(b, v)}
sneek[v] |= {(b, u)}
inf = float("inf")
def makedist(first, branch):
dist = [inf] * (N + 1)
dist[first] = 0
check = [(0, first)]
while len(check) > 0:
d, now = heappop(check)
if dist[now] < d:
continue
for lenth, nex in branch[now]:
if d + lenth < dist[nex]:
dist[nex] = d + lenth
heappush(check, (d + lenth, nex))
return dist
disten = makedist(s, en)
distsneek = makedist(t, sneek)
ans = list(accumulate([y + s for y, s in zip(disten, distsneek)][::-1], min))
big = 10**15
[print(big - ans[i]) for i in range(N - 1, -1, -1)]
# https://atcoder.jp/contests/soundhound2018-summer-qual/submissions/4993088
| false | 2.857143 | [
"-N, m, s, t = list(map(int, input().split()))",
"-en = defaultdict(set)",
"-sneek = defaultdict(set)",
"+N, m, s, t = map(int, input().split())",
"+en = [set() for i in range(N + 1)]",
"+sneek = [set() for i in range(N + 1)]",
"- u, v, a, b = list(map(int, input().split()))",
"+ u, v, a, b = map(int, input().split())",
"-for i in range(N - 1, -1, -1):",
"- print((big - ans[i]))",
"+[print(big - ans[i]) for i in range(N - 1, -1, -1)]"
]
| false | 0.033442 | 0.032943 | 1.015132 | [
"s400036633",
"s577431987"
]
|
u891635666 | p02918 | python | s457580115 | s322798416 | 78 | 37 | 10,408 | 3,316 | Accepted | Accepted | 52.56 | import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
def rle(s):
import itertools
return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)])
n, k = ril()
s = rs()
s = rle(s)
m = len(s)
if m <= 2 * k:
print((n - 1))
else:
print((n - m + 2 * k)) | import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
s = rs()
m = 1
for c0, c1 in zip(s, s[1:]):
if c0 != c1:
m += 1
if m <= 2 * k:
print((n - 1))
else:
print((n - m + 2 * k)) | 27 | 23 | 596 | 523 | import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
def rle(s):
import itertools
return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)])
n, k = ril()
s = rs()
s = rle(s)
m = len(s)
if m <= 2 * k:
print((n - 1))
else:
print((n - m + 2 * k))
| import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
s = rs()
m = 1
for c0, c1 in zip(s, s[1:]):
if c0 != c1:
m += 1
if m <= 2 * k:
print((n - 1))
else:
print((n - m + 2 * k))
| false | 14.814815 | [
"-",
"-",
"-def rle(s):",
"- import itertools",
"-",
"- return list([(x[0], len(list(x[1]))) for x in itertools.groupby(s)])",
"-",
"-",
"-s = rle(s)",
"-m = len(s)",
"+m = 1",
"+for c0, c1 in zip(s, s[1:]):",
"+ if c0 != c1:",
"+ m += 1"
]
| false | 0.064356 | 0.084386 | 0.762644 | [
"s457580115",
"s322798416"
]
|
u102461423 | p02715 | python | s749908955 | s126983750 | 295 | 28 | 29,640 | 9,408 | Accepted | Accepted | 90.51 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10**9 + 7
N, K = list(map(int, read().split()))
is_prime = np.zeros(K + 10, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 10, 2):
if p * p > K:
break
if is_prime[p]:
is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]
A = [0] * (K + 1)
for d in range(1, K + 1):
A[d] = pow(K // d, N, MOD)
for p in primes.tolist():
for i in range(K // p + 1):
A[i] -= A[i * p]
answer = sum(i * x for i, x in enumerate(A))
print((answer % MOD))
| N, K = list(map(int, input().split()))
MOD = 10**9 + 7
M = int(K ** .5)
f_l = [0] * (M+1) # f(k)
f_h = [0] * (M+1) # f(K//d)
def f(k):
return f_l[k] if k <= M else f_h[K//k]
def compute_f(k):
x = pow(k, N, MOD)
sq = int(k ** .5)
for d in range(2, k+1):
n = k // d
if n <= sq:
break
x -= f(n)
for n in range(1, sq+1):
cnt = k//n - k//(n+1)
x -= f_l[n] * cnt
return x
for k in range(1, M+1):
f_l[k] = compute_f(k)
for d in range(M, 0, -1):
f_h[d] = compute_f(K//d)
answer = 0
for k in range(1, M+1):
low_d = K // (k+1) + 1
high_d = K // k
items = high_d - low_d + 1
coef = (low_d + high_d) * items // 2
answer += coef * f_l[k]
for d in range(1, M+1):
if K // d <= M:
break
answer += d * f_h[d]
answer %= MOD
print(answer) | 30 | 45 | 662 | 830 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10**9 + 7
N, K = list(map(int, read().split()))
is_prime = np.zeros(K + 10, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 10, 2):
if p * p > K:
break
if is_prime[p]:
is_prime[p * p :: p + p] = 0
primes = np.where(is_prime)[0]
A = [0] * (K + 1)
for d in range(1, K + 1):
A[d] = pow(K // d, N, MOD)
for p in primes.tolist():
for i in range(K // p + 1):
A[i] -= A[i * p]
answer = sum(i * x for i, x in enumerate(A))
print((answer % MOD))
| N, K = list(map(int, input().split()))
MOD = 10**9 + 7
M = int(K**0.5)
f_l = [0] * (M + 1) # f(k)
f_h = [0] * (M + 1) # f(K//d)
def f(k):
return f_l[k] if k <= M else f_h[K // k]
def compute_f(k):
x = pow(k, N, MOD)
sq = int(k**0.5)
for d in range(2, k + 1):
n = k // d
if n <= sq:
break
x -= f(n)
for n in range(1, sq + 1):
cnt = k // n - k // (n + 1)
x -= f_l[n] * cnt
return x
for k in range(1, M + 1):
f_l[k] = compute_f(k)
for d in range(M, 0, -1):
f_h[d] = compute_f(K // d)
answer = 0
for k in range(1, M + 1):
low_d = K // (k + 1) + 1
high_d = K // k
items = high_d - low_d + 1
coef = (low_d + high_d) * items // 2
answer += coef * f_l[k]
for d in range(1, M + 1):
if K // d <= M:
break
answer += d * f_h[d]
answer %= MOD
print(answer)
| false | 33.333333 | [
"-import sys",
"+N, K = list(map(int, input().split()))",
"+MOD = 10**9 + 7",
"+M = int(K**0.5)",
"+f_l = [0] * (M + 1) # f(k)",
"+f_h = [0] * (M + 1) # f(K//d)",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-import numpy as np",
"-MOD = 10**9 + 7",
"-N, K = list(map(int, read().split()))",
"-is_prime = np.zeros(K + 10, np.bool)",
"-is_prime[2] = 1",
"-is_prime[3::2] = 1",
"-for p in range(3, K + 10, 2):",
"- if p * p > K:",
"+def f(k):",
"+ return f_l[k] if k <= M else f_h[K // k]",
"+",
"+",
"+def compute_f(k):",
"+ x = pow(k, N, MOD)",
"+ sq = int(k**0.5)",
"+ for d in range(2, k + 1):",
"+ n = k // d",
"+ if n <= sq:",
"+ break",
"+ x -= f(n)",
"+ for n in range(1, sq + 1):",
"+ cnt = k // n - k // (n + 1)",
"+ x -= f_l[n] * cnt",
"+ return x",
"+",
"+",
"+for k in range(1, M + 1):",
"+ f_l[k] = compute_f(k)",
"+for d in range(M, 0, -1):",
"+ f_h[d] = compute_f(K // d)",
"+answer = 0",
"+for k in range(1, M + 1):",
"+ low_d = K // (k + 1) + 1",
"+ high_d = K // k",
"+ items = high_d - low_d + 1",
"+ coef = (low_d + high_d) * items // 2",
"+ answer += coef * f_l[k]",
"+for d in range(1, M + 1):",
"+ if K // d <= M:",
"- if is_prime[p]:",
"- is_prime[p * p :: p + p] = 0",
"-primes = np.where(is_prime)[0]",
"-A = [0] * (K + 1)",
"-for d in range(1, K + 1):",
"- A[d] = pow(K // d, N, MOD)",
"-for p in primes.tolist():",
"- for i in range(K // p + 1):",
"- A[i] -= A[i * p]",
"-answer = sum(i * x for i, x in enumerate(A))",
"-print((answer % MOD))",
"+ answer += d * f_h[d]",
"+answer %= MOD",
"+print(answer)"
]
| false | 0.538511 | 0.048238 | 11.163626 | [
"s749908955",
"s126983750"
]
|
u072717685 | p02570 | python | s708893182 | s249630596 | 111 | 70 | 64,676 | 61,808 | Accepted | Accepted | 36.94 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
d, t, s = list(map(int, input().split()))
dis = s * t
if d > dis:
print('No')
else:
print('Yes')
if __name__ == '__main__':
main() | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
d, t, s = list(map(int, input().split()))
if t * s >= d:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 14 | 13 | 283 | 239 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
d, t, s = list(map(int, input().split()))
dis = s * t
if d > dis:
print("No")
else:
print("Yes")
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
d, t, s = list(map(int, input().split()))
if t * s >= d:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| false | 7.142857 | [
"-from collections import Counter",
"- dis = s * t",
"- if d > dis:",
"+ if t * s >= d:",
"+ print(\"Yes\")",
"+ else:",
"- else:",
"- print(\"Yes\")"
]
| false | 0.038621 | 0.035746 | 1.080433 | [
"s708893182",
"s249630596"
]
|
u550061714 | p03163 | python | s691791224 | s040997019 | 584 | 187 | 120,172 | 14,800 | Accepted | Accepted | 67.98 | N, W = list(map(int, input().split()))
goods = []
for _ in range(N):
goods.append(tuple(map(int, input().split())))
table = [[0] * (W + 1) for _ in range(N + 1)]
for n in range(N):
for w in range(W + 1):
addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0
table[n + 1][w] = max(table[n][w], addn)
print((table[N][W]))
| import numpy as np
N, W = list(map(int, input().split()))
goods = [tuple(map(int, input().split())) for _ in range(N)]
dp = np.zeros(W + 1, dtype=np.int64)
for n in range(N):
tmp = np.zeros_like(dp, dtype=np.int64)
tmp[goods[n][0]:] = dp[:W + 1 - goods[n][0]] + goods[n][1]
dp = np.maximum(dp, tmp)
print((dp[W]))
| 11 | 11 | 371 | 330 | N, W = list(map(int, input().split()))
goods = []
for _ in range(N):
goods.append(tuple(map(int, input().split())))
table = [[0] * (W + 1) for _ in range(N + 1)]
for n in range(N):
for w in range(W + 1):
addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0
table[n + 1][w] = max(table[n][w], addn)
print((table[N][W]))
| import numpy as np
N, W = list(map(int, input().split()))
goods = [tuple(map(int, input().split())) for _ in range(N)]
dp = np.zeros(W + 1, dtype=np.int64)
for n in range(N):
tmp = np.zeros_like(dp, dtype=np.int64)
tmp[goods[n][0] :] = dp[: W + 1 - goods[n][0]] + goods[n][1]
dp = np.maximum(dp, tmp)
print((dp[W]))
| false | 0 | [
"+import numpy as np",
"+",
"-goods = []",
"-for _ in range(N):",
"- goods.append(tuple(map(int, input().split())))",
"-table = [[0] * (W + 1) for _ in range(N + 1)]",
"+goods = [tuple(map(int, input().split())) for _ in range(N)]",
"+dp = np.zeros(W + 1, dtype=np.int64)",
"- for w in range(W + 1):",
"- addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0",
"- table[n + 1][w] = max(table[n][w], addn)",
"-print((table[N][W]))",
"+ tmp = np.zeros_like(dp, dtype=np.int64)",
"+ tmp[goods[n][0] :] = dp[: W + 1 - goods[n][0]] + goods[n][1]",
"+ dp = np.maximum(dp, tmp)",
"+print((dp[W]))"
]
| false | 0.075263 | 0.410375 | 0.183402 | [
"s691791224",
"s040997019"
]
|
u757030836 | p03805 | python | s011598278 | s532403582 | 43 | 33 | 3,060 | 3,064 | Accepted | Accepted | 23.26 | import itertools
N,M=list(map(int,input().split()))
edges={tuple(sorted(map(int,input().split()))) for i in range(M)}
ans=0
for i in itertools.permutations(list(range(2,N+1)),N-1):
l=[1]+list(i)
ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1
print(ans) | import itertools
N,M=list(map(int,input().split()))
edges=set()
for _ in range(M):
a,b =list(map(int,input().split()))
edges.add((a,b))
edges.add((b,a))
answer=0
for p in itertools.permutations(list(range(1,N+1))):
if p[0] !=1:
continue
bl=True
for i in range(N-1):
if(p[i],p[i+1]) not in edges:
bl =False
break
if bl:
answer +=1
print(answer) | 8 | 25 | 282 | 405 | import itertools
N, M = list(map(int, input().split()))
edges = {tuple(sorted(map(int, input().split()))) for i in range(M)}
ans = 0
for i in itertools.permutations(list(range(2, N + 1)), N - 1):
l = [1] + list(i)
ans += sum(1 for edge in zip(l, l[1:]) if tuple(sorted(edge)) in edges) == N - 1
print(ans)
| import itertools
N, M = list(map(int, input().split()))
edges = set()
for _ in range(M):
a, b = list(map(int, input().split()))
edges.add((a, b))
edges.add((b, a))
answer = 0
for p in itertools.permutations(list(range(1, N + 1))):
if p[0] != 1:
continue
bl = True
for i in range(N - 1):
if (p[i], p[i + 1]) not in edges:
bl = False
break
if bl:
answer += 1
print(answer)
| false | 68 | [
"-edges = {tuple(sorted(map(int, input().split()))) for i in range(M)}",
"-ans = 0",
"-for i in itertools.permutations(list(range(2, N + 1)), N - 1):",
"- l = [1] + list(i)",
"- ans += sum(1 for edge in zip(l, l[1:]) if tuple(sorted(edge)) in edges) == N - 1",
"-print(ans)",
"+edges = set()",
"+for _ in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ edges.add((a, b))",
"+ edges.add((b, a))",
"+answer = 0",
"+for p in itertools.permutations(list(range(1, N + 1))):",
"+ if p[0] != 1:",
"+ continue",
"+ bl = True",
"+ for i in range(N - 1):",
"+ if (p[i], p[i + 1]) not in edges:",
"+ bl = False",
"+ break",
"+ if bl:",
"+ answer += 1",
"+print(answer)"
]
| false | 0.081532 | 0.057677 | 1.413603 | [
"s011598278",
"s532403582"
]
|
u869790980 | p03425 | python | s230795202 | s064069802 | 376 | 104 | 98,876 | 82,792 | Accepted | Accepted | 72.34 | import collections
cc = collections.Counter()
for _ in range(int(input())):
cc[input()[0]] +=1
def dfs(i, total ,cumul, cc, k, s):
if i == len(s) or k == 0:
if k == 0: total[0] += cumul
return
if k:
dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
dfs(i+1, total, cumul, cc, k, s)
total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print(total[0]) | import collections
cc = collections.Counter([input()[0] for _ in range(int(input()))])
def dfs(i, total ,cumul, cc, k, s):
if i == len(s) or k == 0:
if k == 0: total[0] += cumul
return
dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
dfs(i+1, total, cumul, cc, k, s)
total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print(total[0]) | 17 | 15 | 379 | 360 | import collections
cc = collections.Counter()
for _ in range(int(input())):
cc[input()[0]] += 1
def dfs(i, total, cumul, cc, k, s):
if i == len(s) or k == 0:
if k == 0:
total[0] += cumul
return
if k:
dfs(i + 1, total, cumul * cc[s[i]], cc, k - 1, s)
dfs(i + 1, total, cumul, cc, k, s)
total = [0]
dfs(0, total, 1, cc, 3, "MARCH")
print(total[0])
| import collections
cc = collections.Counter([input()[0] for _ in range(int(input()))])
def dfs(i, total, cumul, cc, k, s):
if i == len(s) or k == 0:
if k == 0:
total[0] += cumul
return
dfs(i + 1, total, cumul * cc[s[i]], cc, k - 1, s)
dfs(i + 1, total, cumul, cc, k, s)
total = [0]
dfs(0, total, 1, cc, 3, "MARCH")
print(total[0])
| false | 11.764706 | [
"-cc = collections.Counter()",
"-for _ in range(int(input())):",
"- cc[input()[0]] += 1",
"+cc = collections.Counter([input()[0] for _ in range(int(input()))])",
"- if k:",
"- dfs(i + 1, total, cumul * cc[s[i]], cc, k - 1, s)",
"+ dfs(i + 1, total, cumul * cc[s[i]], cc, k - 1, s)"
]
| false | 0.007648 | 0.039494 | 0.193655 | [
"s230795202",
"s064069802"
]
|
u089142196 | p02984 | python | s406573871 | s598776718 | 161 | 132 | 14,624 | 14,028 | Accepted | Accepted | 18.01 | N=int(eval(input()))
A=list(map(int, input().split()))
M=[0]*N
maxi=sum(A)
M[0]=maxi//4
tmp=10**9
while M[0]/2 != tmp:
for i in range(1,N):
M[i]= 2*(A[i-1]-M[i-1]//2)
tmp = A[-1] - M[N-1]//2
#print(M,tmp)
if M[0] != tmp*2:
M[0] = (M[0]+tmp*2)//2
if M[0]%2!=0:
M[0] +=1
else:
print((*M)) | N=int(eval(input()))
A=list(map(int, input().split()))
M=[0]*N
maxi=sum(A)
M[0]= maxi-2*sum(A[1::2])
for i in range(1,N):
M[i]= 2*(A[i-1]-M[i-1]//2)
print((*M)) | 19 | 9 | 326 | 163 | N = int(eval(input()))
A = list(map(int, input().split()))
M = [0] * N
maxi = sum(A)
M[0] = maxi // 4
tmp = 10**9
while M[0] / 2 != tmp:
for i in range(1, N):
M[i] = 2 * (A[i - 1] - M[i - 1] // 2)
tmp = A[-1] - M[N - 1] // 2
# print(M,tmp)
if M[0] != tmp * 2:
M[0] = (M[0] + tmp * 2) // 2
if M[0] % 2 != 0:
M[0] += 1
else:
print((*M))
| N = int(eval(input()))
A = list(map(int, input().split()))
M = [0] * N
maxi = sum(A)
M[0] = maxi - 2 * sum(A[1::2])
for i in range(1, N):
M[i] = 2 * (A[i - 1] - M[i - 1] // 2)
print((*M))
| false | 52.631579 | [
"-M[0] = maxi // 4",
"-tmp = 10**9",
"-while M[0] / 2 != tmp:",
"- for i in range(1, N):",
"- M[i] = 2 * (A[i - 1] - M[i - 1] // 2)",
"- tmp = A[-1] - M[N - 1] // 2",
"- # print(M,tmp)",
"- if M[0] != tmp * 2:",
"- M[0] = (M[0] + tmp * 2) // 2",
"- if M[0] % 2 != 0:",
"- M[0] += 1",
"-else:",
"- print((*M))",
"+M[0] = maxi - 2 * sum(A[1::2])",
"+for i in range(1, N):",
"+ M[i] = 2 * (A[i - 1] - M[i - 1] // 2)",
"+print((*M))"
]
| false | 0.047182 | 0.110774 | 0.425926 | [
"s406573871",
"s598776718"
]
|
u389910364 | p03344 | python | s921645248 | s204865829 | 1,274 | 1,177 | 69,908 | 127,928 | Accepted | Accepted | 7.61 | import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
class UnionFind:
def __init__(self, size=None, nodes=None):
"""
size ใ nodes ใฉใฃใกใๆๅฎใ
nodes ใฏ setใsize ใฏ list ใไฝฟใใ
:param int size:
:param collections.Iterable nodes:
"""
assert size is not None or nodes is not None
if size is not None:
self._parents = [i for i in range(size)]
self._ranks = [0 for _ in range(size)]
self._sizes = [1 for _ in range(size)]
else:
self._parents = {k: k for k in nodes}
self._ranks = {k: 0 for k in nodes}
self._sizes = {k: 1 for k in nodes}
def unite(self, x, y):
"""
x ใๅฑใใๆจใจ y ใๅฑใใๆจใไฝตๅ
:param x:
:param y:
"""
x = self.root(x)
y = self.root(y)
if x == y:
return
# rank ใๅฐใใๆนใไธ
if self._ranks[x] > self._ranks[y]:
# x ใ root
self._parents[y] = x
self._sizes[x] += self._sizes[y]
else:
# y ใ root
self._parents[x] = y
self._sizes[y] += self._sizes[x]
if self._ranks[x] == self._ranks[y]:
self._ranks[y] += 1
def root(self, x):
"""
x ใๅฑใใๆจใฎ root
:param x:
"""
if self._parents[x] == x:
return x
self._parents[x] = self.root(self._parents[x])
return self._parents[x]
def size(self, x):
"""
x ใๅฑใใๆจใฎใใผใๆฐ
:param x:
"""
return self._sizes[self.root(x)]
def argsort(li, key=None, reverse=False):
return [i for _, i in sorted(
[(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse
)]
N, M = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]))
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
# from libs.debug import plot_graph
#
# plot_graph(VU)
graph = [[] for _ in range(N)]
for v, u in VU:
v -= 1
u -= 1
graph[v].append(u)
graph[u].append(v)
# ่งฃ่ชฌ
# C[v] = A[v] - B[v]
# C ใฎๅฐใใ้ ใซใฐใฉใใๆง็ฏใใฆใ้จๅใฐใฉใใใจใซ็ญใใๆใค
reqs = [max(0, a - b) for a, b in zip(A, B)]
uses = list(B)
idx = argsort(reqs)
uf = UnionFind(size=N)
seen = [False] * N
ans = [INF] * N
for v in idx:
# v: ไปใพใงใซ่ฆใไธญใง C ใๆๅคงใฎ้ ็น
seen[v] = True
roots = set()
for u in graph[v]:
if not seen[u]:
continue
roots.add(uf.root(u))
use_all = uses[v]
for r in roots:
use_all += uses[r]
# v ใๆๅใซใใๅ ดๅ
req_v = reqs[v] + use_all
for r in roots:
# r ใฎใฉใใใ root ใจใใ้จๅใฐใฉใใๆๅใซใใๅ ดๅ
# C[v] ใไปใพใง่ฆใใใกๆๅคงใชใฎใง v ใซๆฅใใใจใฏๅฅฝใใช้ ็นใพใง่กใใ
req_v = min(req_v, max(reqs[r], reqs[v]) + use_all - uses[r])
for r in roots:
uf.unite(v, r)
reqs[uf.root(v)] = req_v
uses[uf.root(v)] = use_all
ans = reqs[uf.root(0)]
print(ans)
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
class UnionFind:
def __init__(self, size=None, nodes=None):
"""
size ใ nodes ใฉใฃใกใๆๅฎใ
nodes ใฏ setใsize ใฏ list ใไฝฟใใ
:param int size:
:param collections.Iterable nodes:
"""
assert size is not None or nodes is not None
if size is not None:
self._parents = [i for i in range(size)]
self._ranks = [0 for _ in range(size)]
self._sizes = [1 for _ in range(size)]
else:
self._parents = {k: k for k in nodes}
self._ranks = {k: 0 for k in nodes}
self._sizes = {k: 1 for k in nodes}
def unite(self, x, y):
"""
x ใๅฑใใๆจใจ y ใๅฑใใๆจใไฝตๅ
:param x:
:param y:
"""
x = self.root(x)
y = self.root(y)
if x == y:
return
# rank ใๅฐใใๆนใไธ
if self._ranks[x] > self._ranks[y]:
# x ใ root
self._parents[y] = x
self._sizes[x] += self._sizes[y]
else:
# y ใ root
self._parents[x] = y
self._sizes[y] += self._sizes[x]
if self._ranks[x] == self._ranks[y]:
self._ranks[y] += 1
def root(self, x):
"""
x ใๅฑใใๆจใฎ root
:param x:
"""
if self._parents[x] == x:
return x
self._parents[x] = self.root(self._parents[x])
return self._parents[x]
def size(self, x):
"""
x ใๅฑใใๆจใฎใใผใๆฐ
:param x:
"""
return self._sizes[self.root(x)]
def argsort(li, key=None, reverse=False):
return [i for _, i in sorted(
[(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse
)]
N, M = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]))
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
# from libs.debug import plot_graph
#
# plot_graph(VU)
graph = [[] for _ in range(N)]
for v, u in VU:
v -= 1
u -= 1
graph[v].append(u)
graph[u].append(v)
reqs = [max(a, b) for a, b in zip(A, B)]
uses = list(B)
idx = argsort([a - b for a, b in zip(A, B)])
uf = UnionFind(size=N)
seen = [False] * N
ans = [INF] * N
for v in idx:
seen[v] = True
roots = set()
for u in graph[v]:
if not seen[u]:
continue
roots.add(uf.root(u))
use_all = uses[v]
for r in roots:
use_all += uses[r]
# v ใๆๅพ
req_v = reqs[v] + use_all - uses[v]
for r in roots:
req_v = min(req_v, max(reqs[r], reqs[v] - uses[v]) + use_all - uses[r])
for r in roots:
uf.unite(v, r)
reqs[uf.root(v)] = req_v
uses[uf.root(v)] = use_all
ans = reqs[uf.root(0)]
print(ans)
| 130 | 125 | 3,260 | 3,118 | import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
class UnionFind:
def __init__(self, size=None, nodes=None):
"""
size ใ nodes ใฉใฃใกใๆๅฎใ
nodes ใฏ setใsize ใฏ list ใไฝฟใใ
:param int size:
:param collections.Iterable nodes:
"""
assert size is not None or nodes is not None
if size is not None:
self._parents = [i for i in range(size)]
self._ranks = [0 for _ in range(size)]
self._sizes = [1 for _ in range(size)]
else:
self._parents = {k: k for k in nodes}
self._ranks = {k: 0 for k in nodes}
self._sizes = {k: 1 for k in nodes}
def unite(self, x, y):
"""
x ใๅฑใใๆจใจ y ใๅฑใใๆจใไฝตๅ
:param x:
:param y:
"""
x = self.root(x)
y = self.root(y)
if x == y:
return
# rank ใๅฐใใๆนใไธ
if self._ranks[x] > self._ranks[y]:
# x ใ root
self._parents[y] = x
self._sizes[x] += self._sizes[y]
else:
# y ใ root
self._parents[x] = y
self._sizes[y] += self._sizes[x]
if self._ranks[x] == self._ranks[y]:
self._ranks[y] += 1
def root(self, x):
"""
x ใๅฑใใๆจใฎ root
:param x:
"""
if self._parents[x] == x:
return x
self._parents[x] = self.root(self._parents[x])
return self._parents[x]
def size(self, x):
"""
x ใๅฑใใๆจใฎใใผใๆฐ
:param x:
"""
return self._sizes[self.root(x)]
def argsort(li, key=None, reverse=False):
return [
i
for _, i in sorted(
[(a, i) for i, a in enumerate(li)],
key=(lambda t: key(t[0])) if key else None,
reverse=reverse,
)
]
N, M = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(
zip(*[list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)])
)
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
# from libs.debug import plot_graph
#
# plot_graph(VU)
graph = [[] for _ in range(N)]
for v, u in VU:
v -= 1
u -= 1
graph[v].append(u)
graph[u].append(v)
# ่งฃ่ชฌ
# C[v] = A[v] - B[v]
# C ใฎๅฐใใ้ ใซใฐใฉใใๆง็ฏใใฆใ้จๅใฐใฉใใใจใซ็ญใใๆใค
reqs = [max(0, a - b) for a, b in zip(A, B)]
uses = list(B)
idx = argsort(reqs)
uf = UnionFind(size=N)
seen = [False] * N
ans = [INF] * N
for v in idx:
# v: ไปใพใงใซ่ฆใไธญใง C ใๆๅคงใฎ้ ็น
seen[v] = True
roots = set()
for u in graph[v]:
if not seen[u]:
continue
roots.add(uf.root(u))
use_all = uses[v]
for r in roots:
use_all += uses[r]
# v ใๆๅใซใใๅ ดๅ
req_v = reqs[v] + use_all
for r in roots:
# r ใฎใฉใใใ root ใจใใ้จๅใฐใฉใใๆๅใซใใๅ ดๅ
# C[v] ใไปใพใง่ฆใใใกๆๅคงใชใฎใง v ใซๆฅใใใจใฏๅฅฝใใช้ ็นใพใง่กใใ
req_v = min(req_v, max(reqs[r], reqs[v]) + use_all - uses[r])
for r in roots:
uf.unite(v, r)
reqs[uf.root(v)] = req_v
uses[uf.root(v)] = use_all
ans = reqs[uf.root(0)]
print(ans)
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
class UnionFind:
def __init__(self, size=None, nodes=None):
"""
size ใ nodes ใฉใฃใกใๆๅฎใ
nodes ใฏ setใsize ใฏ list ใไฝฟใใ
:param int size:
:param collections.Iterable nodes:
"""
assert size is not None or nodes is not None
if size is not None:
self._parents = [i for i in range(size)]
self._ranks = [0 for _ in range(size)]
self._sizes = [1 for _ in range(size)]
else:
self._parents = {k: k for k in nodes}
self._ranks = {k: 0 for k in nodes}
self._sizes = {k: 1 for k in nodes}
def unite(self, x, y):
"""
x ใๅฑใใๆจใจ y ใๅฑใใๆจใไฝตๅ
:param x:
:param y:
"""
x = self.root(x)
y = self.root(y)
if x == y:
return
# rank ใๅฐใใๆนใไธ
if self._ranks[x] > self._ranks[y]:
# x ใ root
self._parents[y] = x
self._sizes[x] += self._sizes[y]
else:
# y ใ root
self._parents[x] = y
self._sizes[y] += self._sizes[x]
if self._ranks[x] == self._ranks[y]:
self._ranks[y] += 1
def root(self, x):
"""
x ใๅฑใใๆจใฎ root
:param x:
"""
if self._parents[x] == x:
return x
self._parents[x] = self.root(self._parents[x])
return self._parents[x]
def size(self, x):
"""
x ใๅฑใใๆจใฎใใผใๆฐ
:param x:
"""
return self._sizes[self.root(x)]
def argsort(li, key=None, reverse=False):
return [
i
for _, i in sorted(
[(a, i) for i, a in enumerate(li)],
key=(lambda t: key(t[0])) if key else None,
reverse=reverse,
)
]
N, M = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(
zip(*[list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)])
)
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
# from libs.debug import plot_graph
#
# plot_graph(VU)
graph = [[] for _ in range(N)]
for v, u in VU:
v -= 1
u -= 1
graph[v].append(u)
graph[u].append(v)
reqs = [max(a, b) for a, b in zip(A, B)]
uses = list(B)
idx = argsort([a - b for a, b in zip(A, B)])
uf = UnionFind(size=N)
seen = [False] * N
ans = [INF] * N
for v in idx:
seen[v] = True
roots = set()
for u in graph[v]:
if not seen[u]:
continue
roots.add(uf.root(u))
use_all = uses[v]
for r in roots:
use_all += uses[r]
# v ใๆๅพ
req_v = reqs[v] + use_all - uses[v]
for r in roots:
req_v = min(req_v, max(reqs[r], reqs[v] - uses[v]) + use_all - uses[r])
for r in roots:
uf.unite(v, r)
reqs[uf.root(v)] = req_v
uses[uf.root(v)] = use_all
ans = reqs[uf.root(0)]
print(ans)
| false | 3.846154 | [
"-# ่งฃ่ชฌ",
"-# C[v] = A[v] - B[v]",
"-# C ใฎๅฐใใ้ ใซใฐใฉใใๆง็ฏใใฆใ้จๅใฐใฉใใใจใซ็ญใใๆใค",
"-reqs = [max(0, a - b) for a, b in zip(A, B)]",
"+reqs = [max(a, b) for a, b in zip(A, B)]",
"-idx = argsort(reqs)",
"+idx = argsort([a - b for a, b in zip(A, B)])",
"- # v: ไปใพใงใซ่ฆใไธญใง C ใๆๅคงใฎ้ ็น",
"- # v ใๆๅใซใใๅ ดๅ",
"- req_v = reqs[v] + use_all",
"+ # v ใๆๅพ",
"+ req_v = reqs[v] + use_all - uses[v]",
"- # r ใฎใฉใใใ root ใจใใ้จๅใฐใฉใใๆๅใซใใๅ ดๅ",
"- # C[v] ใไปใพใง่ฆใใใกๆๅคงใชใฎใง v ใซๆฅใใใจใฏๅฅฝใใช้ ็นใพใง่กใใ",
"- req_v = min(req_v, max(reqs[r], reqs[v]) + use_all - uses[r])",
"+ req_v = min(req_v, max(reqs[r], reqs[v] - uses[v]) + use_all - uses[r])"
]
| false | 0.045204 | 0.035937 | 1.257889 | [
"s921645248",
"s204865829"
]
|
u346812984 | p03229 | python | s863736929 | s960418183 | 243 | 136 | 7,512 | 7,524 | Accepted | Accepted | 44.03 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.sort()
if N % 2 == 0:
ans = 0
for i in range(N // 2):
ans -= 2 * A[i]
for i in range(N // 2, N):
ans += 2 * A[i]
ans += A[N // 2 - 1]
ans -= A[N // 2]
print(ans)
else:
ans1 = 0
for i in range(N // 2):
ans1 -= 2 * A[i]
for i in range(N // 2, N):
ans1 += 2 * A[i]
ans1 -= A[N // 2]
ans1 -= A[N // 2 + 1]
ans2 = 0
for i in range(N // 2 + 1):
ans2 -= 2 * A[i]
for i in range(N // 2 + 1, N):
ans2 += 2 * A[i]
ans2 += A[N // 2]
ans2 += A[N // 2 - 1]
print((max(ans1, ans2)))
| import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.sort()
if N % 2 == 0:
ans = A[N // 2] - A[N // 2 - 1]
for i in range(N // 2 - 1):
ans -= 2 * A[i]
for i in range(N // 2 + 1, N):
ans += 2 * A[i]
else:
ans1 = -A[N // 2] - A[N // 2 - 1]
for i in range(N // 2 - 1):
ans1 -= 2 * A[i]
for i in range(N // 2 + 1, N):
ans1 += 2 * A[i]
ans2 = A[N // 2] + A[N // 2 + 1]
for i in range(N // 2):
ans2 -= 2 * A[i]
for i in range(N // 2 + 2, N):
ans2 += 2 * A[i]
ans = max(ans1, ans2)
print(ans)
if __name__ == "__main__":
main()
| 30 | 42 | 670 | 899 | N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.sort()
if N % 2 == 0:
ans = 0
for i in range(N // 2):
ans -= 2 * A[i]
for i in range(N // 2, N):
ans += 2 * A[i]
ans += A[N // 2 - 1]
ans -= A[N // 2]
print(ans)
else:
ans1 = 0
for i in range(N // 2):
ans1 -= 2 * A[i]
for i in range(N // 2, N):
ans1 += 2 * A[i]
ans1 -= A[N // 2]
ans1 -= A[N // 2 + 1]
ans2 = 0
for i in range(N // 2 + 1):
ans2 -= 2 * A[i]
for i in range(N // 2 + 1, N):
ans2 += 2 * A[i]
ans2 += A[N // 2]
ans2 += A[N // 2 - 1]
print((max(ans1, ans2)))
| import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.sort()
if N % 2 == 0:
ans = A[N // 2] - A[N // 2 - 1]
for i in range(N // 2 - 1):
ans -= 2 * A[i]
for i in range(N // 2 + 1, N):
ans += 2 * A[i]
else:
ans1 = -A[N // 2] - A[N // 2 - 1]
for i in range(N // 2 - 1):
ans1 -= 2 * A[i]
for i in range(N // 2 + 1, N):
ans1 += 2 * A[i]
ans2 = A[N // 2] + A[N // 2 + 1]
for i in range(N // 2):
ans2 -= 2 * A[i]
for i in range(N // 2 + 2, N):
ans2 += 2 * A[i]
ans = max(ans1, ans2)
print(ans)
if __name__ == "__main__":
main()
| false | 28.571429 | [
"-N = int(eval(input()))",
"-A = [int(eval(input())) for _ in range(N)]",
"-A.sort()",
"-if N % 2 == 0:",
"- ans = 0",
"- for i in range(N // 2):",
"- ans -= 2 * A[i]",
"- for i in range(N // 2, N):",
"- ans += 2 * A[i]",
"- ans += A[N // 2 - 1]",
"- ans -= A[N // 2]",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def main():",
"+ N = int(eval(input()))",
"+ A = [int(eval(input())) for _ in range(N)]",
"+ A.sort()",
"+ if N % 2 == 0:",
"+ ans = A[N // 2] - A[N // 2 - 1]",
"+ for i in range(N // 2 - 1):",
"+ ans -= 2 * A[i]",
"+ for i in range(N // 2 + 1, N):",
"+ ans += 2 * A[i]",
"+ else:",
"+ ans1 = -A[N // 2] - A[N // 2 - 1]",
"+ for i in range(N // 2 - 1):",
"+ ans1 -= 2 * A[i]",
"+ for i in range(N // 2 + 1, N):",
"+ ans1 += 2 * A[i]",
"+ ans2 = A[N // 2] + A[N // 2 + 1]",
"+ for i in range(N // 2):",
"+ ans2 -= 2 * A[i]",
"+ for i in range(N // 2 + 2, N):",
"+ ans2 += 2 * A[i]",
"+ ans = max(ans1, ans2)",
"-else:",
"- ans1 = 0",
"- for i in range(N // 2):",
"- ans1 -= 2 * A[i]",
"- for i in range(N // 2, N):",
"- ans1 += 2 * A[i]",
"- ans1 -= A[N // 2]",
"- ans1 -= A[N // 2 + 1]",
"- ans2 = 0",
"- for i in range(N // 2 + 1):",
"- ans2 -= 2 * A[i]",
"- for i in range(N // 2 + 1, N):",
"- ans2 += 2 * A[i]",
"- ans2 += A[N // 2]",
"- ans2 += A[N // 2 - 1]",
"- print((max(ans1, ans2)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.037448 | 0.081704 | 0.458338 | [
"s863736929",
"s960418183"
]
|
u611853667 | p00109 | python | s069393053 | s712607780 | 20 | 10 | 4,384 | 4,368 | Accepted | Accepted | 50 | def divide(x, y):
s = 1
if(x < 0):s *= -1
if(y < 0):s *= -1
return abs(x) / abs(y) * s
operator = {"+":(lambda x,y: x+y),
"-":(lambda x,y: x-y),
"*":(lambda x,y: x*y),
"/":divide
}
def ind(src, x):
if x not in src:return 1<<30
return src.index(x)
def _split(_src):
c = 0
l = len(_src)
if l == 0:
return []
while c < l and ord('0') <= ord(_src[c]) <= ord('9'):
c += 1
if c == 0:
return [_src[0]] + _split(_src[1:])
else:
return [int(_src[:c])] + _split(_src[c:])
def evaluate(src):
if len(src) == 1:
return src[0]
if "(" in src:
l = src.index("(")
r = l
st = 1
while st:
r += 1
if src[r] == "(": st += 1
if src[r] == ")": st -= 1
mid = evaluate(src[l + 1:r])
return evaluate( src[:l] + [mid] + src[r + 1:])
if "*" in src or "/" in src:
pos = min(ind(src, "*"), ind(src,"/"))
op = src[pos]
l, r = src[pos - 1], src[pos + 1]
mid = operator[op](l, r)
return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])
else:
pos = min(ind(src, "+"), ind(src, "-"))
op = src[pos]
l, r = src[pos - 1], src[pos + 1]
mid = operator[op](l, r)
return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])
for t in range(eval(input())):
_src = input().strip("=")
src = _split(_src)
print(evaluate(src)) | def divide(x, y):
s = 1
if(x < 0):s *= -1
if(y < 0):s *= -1
return abs(x) / abs(y) * s
operator = {"+":(lambda x,y: x+y),
"-":(lambda x,y: x-y),
"*":(lambda x,y: x*y),
"/":divide
}
def ind(src, x):
if x not in src:return 1<<30
return src.index(x)
def _split(_src):
c = 0
l = len(_src)
if l == 0:
return []
while c < l and ord('0') <= ord(_src[c]) <= ord('9'):
c += 1
if c == 0:
return [_src[0]] + _split(_src[1:])
else:
return [int(_src[:c])] + _split(_src[c:])
def evaluate(src):
if len(src) == 1:
return src[0]
if "(" in src:
l = src.index("(")
r = l
st = 1
while st:
r += 1
if src[r] == "(": st += 1
if src[r] == ")": st -= 1
mid = evaluate(src[l + 1:r])
return evaluate( src[:l] + [mid] + src[r + 1:])
pos = min(ind(src, "*"), ind(src,"/"))
if(pos == 1<<30):
pos = min(ind(src, "+"), ind(src, "-"))
op = src[pos]
l, r = src[pos - 1], src[pos + 1]
mid = operator[op](l, r)
return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])
for t in range(eval(input())):
_src = input().strip("=")
src = _split(_src)
print(evaluate(src)) | 64 | 59 | 1,618 | 1,408 | def divide(x, y):
s = 1
if x < 0:
s *= -1
if y < 0:
s *= -1
return abs(x) / abs(y) * s
operator = {
"+": (lambda x, y: x + y),
"-": (lambda x, y: x - y),
"*": (lambda x, y: x * y),
"/": divide,
}
def ind(src, x):
if x not in src:
return 1 << 30
return src.index(x)
def _split(_src):
c = 0
l = len(_src)
if l == 0:
return []
while c < l and ord("0") <= ord(_src[c]) <= ord("9"):
c += 1
if c == 0:
return [_src[0]] + _split(_src[1:])
else:
return [int(_src[:c])] + _split(_src[c:])
def evaluate(src):
if len(src) == 1:
return src[0]
if "(" in src:
l = src.index("(")
r = l
st = 1
while st:
r += 1
if src[r] == "(":
st += 1
if src[r] == ")":
st -= 1
mid = evaluate(src[l + 1 : r])
return evaluate(src[:l] + [mid] + src[r + 1 :])
if "*" in src or "/" in src:
pos = min(ind(src, "*"), ind(src, "/"))
op = src[pos]
l, r = src[pos - 1], src[pos + 1]
mid = operator[op](l, r)
return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])
else:
pos = min(ind(src, "+"), ind(src, "-"))
op = src[pos]
l, r = src[pos - 1], src[pos + 1]
mid = operator[op](l, r)
return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])
for t in range(eval(input())):
_src = input().strip("=")
src = _split(_src)
print(evaluate(src))
| def divide(x, y):
s = 1
if x < 0:
s *= -1
if y < 0:
s *= -1
return abs(x) / abs(y) * s
operator = {
"+": (lambda x, y: x + y),
"-": (lambda x, y: x - y),
"*": (lambda x, y: x * y),
"/": divide,
}
def ind(src, x):
if x not in src:
return 1 << 30
return src.index(x)
def _split(_src):
c = 0
l = len(_src)
if l == 0:
return []
while c < l and ord("0") <= ord(_src[c]) <= ord("9"):
c += 1
if c == 0:
return [_src[0]] + _split(_src[1:])
else:
return [int(_src[:c])] + _split(_src[c:])
def evaluate(src):
if len(src) == 1:
return src[0]
if "(" in src:
l = src.index("(")
r = l
st = 1
while st:
r += 1
if src[r] == "(":
st += 1
if src[r] == ")":
st -= 1
mid = evaluate(src[l + 1 : r])
return evaluate(src[:l] + [mid] + src[r + 1 :])
pos = min(ind(src, "*"), ind(src, "/"))
if pos == 1 << 30:
pos = min(ind(src, "+"), ind(src, "-"))
op = src[pos]
l, r = src[pos - 1], src[pos + 1]
mid = operator[op](l, r)
return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])
for t in range(eval(input())):
_src = input().strip("=")
src = _split(_src)
print(evaluate(src))
| false | 7.8125 | [
"- if \"*\" in src or \"/\" in src:",
"- pos = min(ind(src, \"*\"), ind(src, \"/\"))",
"- op = src[pos]",
"- l, r = src[pos - 1], src[pos + 1]",
"- mid = operator[op](l, r)",
"- return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])",
"- else:",
"+ pos = min(ind(src, \"*\"), ind(src, \"/\"))",
"+ if pos == 1 << 30:",
"- op = src[pos]",
"- l, r = src[pos - 1], src[pos + 1]",
"- mid = operator[op](l, r)",
"- return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])",
"+ op = src[pos]",
"+ l, r = src[pos - 1], src[pos + 1]",
"+ mid = operator[op](l, r)",
"+ return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])"
]
| false | 0.074621 | 0.047253 | 1.579162 | [
"s069393053",
"s712607780"
]
|
u268554510 | p02793 | python | s136622512 | s779543342 | 967 | 313 | 5,616 | 53,228 | Accepted | Accepted | 67.63 | N = int(eval(input()))
A = list(map(int,input().split()))
from fractions import gcd
mod = 10**9+7
g = A[0]
for a in A[1::]:
g = g*a//gcd(g,a)
ans = 0
b = g%mod
for a in A:
ans += b*pow(a,mod-2,mod)
ans %= mod
print((ans%mod)) | N = int(eval(input()))
A = list(map(int,input().split()))
mod = 10**9+7
l = [0]*(max(A)+1)
l[1]=1
for a in A:
if a==1:
continue
x=0
while a%2==0:
a//=2
x+=1
l[2]=max(l[2],x)
f = 3
while f**2<=a:
x = 0
while a%f==0:
a//=f
x+=1
l[f]=max(l[f],x)
f+=2
if a!=1:
l[a]=max(l[a],1)
b = 1
for i,x in enumerate(l):
b*=pow(i,x,mod)
b%=mod
ans = 0
for a in A:
ans+=(b*pow(a,mod-2,mod))%mod
ans%=mod
print((ans%mod)) | 15 | 38 | 241 | 518 | N = int(eval(input()))
A = list(map(int, input().split()))
from fractions import gcd
mod = 10**9 + 7
g = A[0]
for a in A[1::]:
g = g * a // gcd(g, a)
ans = 0
b = g % mod
for a in A:
ans += b * pow(a, mod - 2, mod)
ans %= mod
print((ans % mod))
| N = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
l = [0] * (max(A) + 1)
l[1] = 1
for a in A:
if a == 1:
continue
x = 0
while a % 2 == 0:
a //= 2
x += 1
l[2] = max(l[2], x)
f = 3
while f**2 <= a:
x = 0
while a % f == 0:
a //= f
x += 1
l[f] = max(l[f], x)
f += 2
if a != 1:
l[a] = max(l[a], 1)
b = 1
for i, x in enumerate(l):
b *= pow(i, x, mod)
b %= mod
ans = 0
for a in A:
ans += (b * pow(a, mod - 2, mod)) % mod
ans %= mod
print((ans % mod))
| false | 60.526316 | [
"-from fractions import gcd",
"-",
"-g = A[0]",
"-for a in A[1::]:",
"- g = g * a // gcd(g, a)",
"+l = [0] * (max(A) + 1)",
"+l[1] = 1",
"+for a in A:",
"+ if a == 1:",
"+ continue",
"+ x = 0",
"+ while a % 2 == 0:",
"+ a //= 2",
"+ x += 1",
"+ l[2] = max(l[2], x)",
"+ f = 3",
"+ while f**2 <= a:",
"+ x = 0",
"+ while a % f == 0:",
"+ a //= f",
"+ x += 1",
"+ l[f] = max(l[f], x)",
"+ f += 2",
"+ if a != 1:",
"+ l[a] = max(l[a], 1)",
"+b = 1",
"+for i, x in enumerate(l):",
"+ b *= pow(i, x, mod)",
"+ b %= mod",
"-b = g % mod",
"- ans += b * pow(a, mod - 2, mod)",
"+ ans += (b * pow(a, mod - 2, mod)) % mod"
]
| false | 0.046649 | 0.357424 | 0.130514 | [
"s136622512",
"s779543342"
]
|
u936985471 | p02948 | python | s110358843 | s816149375 | 317 | 230 | 27,832 | 31,960 | Accepted | Accepted | 27.44 | import sys
readline = sys.stdin.readline
# ้้ ใซ่ฆใฆใใ
# A_iใฎๅคใๅฐใใ้ ใซheapqใซ่ฟฝๅ ใใฆใใ
N,M = list(map(int,readline().split()))
from collections import defaultdict
tasks = defaultdict(list)
for i in range(N):
a,b = list(map(int,readline().split()))
tasks[a].append(b)
import heapq
q = []
heapq.heapify(q)
ans = 0
for i in range(1,M + 1):
for task in tasks[i]:
heapq.heappush(q,-task)
if q:
t = heapq.heappop(q)
ans += (-t)
print(ans) | import sys
readline = sys.stdin.readline
N,M = list(map(int,readline().split()))
from collections import defaultdict
tasks = defaultdict(list)
for i in range(N):
a,b = list(map(int,readline().split()))
tasks[a].append(b)
import heapq as hq
q = []
ans = 0
for i in range(1, M + 1):
newtask = tasks[i]
for t in newtask:
hq.heappush(q,-t)
if q:
ans += -hq.heappop(q)
print(ans) | 25 | 21 | 460 | 405 | import sys
readline = sys.stdin.readline
# ้้ ใซ่ฆใฆใใ
# A_iใฎๅคใๅฐใใ้ ใซheapqใซ่ฟฝๅ ใใฆใใ
N, M = list(map(int, readline().split()))
from collections import defaultdict
tasks = defaultdict(list)
for i in range(N):
a, b = list(map(int, readline().split()))
tasks[a].append(b)
import heapq
q = []
heapq.heapify(q)
ans = 0
for i in range(1, M + 1):
for task in tasks[i]:
heapq.heappush(q, -task)
if q:
t = heapq.heappop(q)
ans += -t
print(ans)
| import sys
readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
from collections import defaultdict
tasks = defaultdict(list)
for i in range(N):
a, b = list(map(int, readline().split()))
tasks[a].append(b)
import heapq as hq
q = []
ans = 0
for i in range(1, M + 1):
newtask = tasks[i]
for t in newtask:
hq.heappush(q, -t)
if q:
ans += -hq.heappop(q)
print(ans)
| false | 16 | [
"-# ้้ ใซ่ฆใฆใใ",
"-# A_iใฎๅคใๅฐใใ้ ใซheapqใซ่ฟฝๅ ใใฆใใ",
"-import heapq",
"+import heapq as hq",
"-heapq.heapify(q)",
"- for task in tasks[i]:",
"- heapq.heappush(q, -task)",
"+ newtask = tasks[i]",
"+ for t in newtask:",
"+ hq.heappush(q, -t)",
"- t = heapq.heappop(q)",
"- ans += -t",
"+ ans += -hq.heappop(q)"
]
| false | 0.037978 | 0.036635 | 1.036665 | [
"s110358843",
"s816149375"
]
|
u814986259 | p03103 | python | s428218658 | s728001799 | 454 | 412 | 29,020 | 16,984 | Accepted | Accepted | 9.25 | N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
if M >= AB[i][1]:
ans += AB[i][0] * AB[i][1]
M -= AB[i][1]
else:
ans += AB[i][0] * M
M = 0
if M == 0:
break
print(ans)
| N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for i in range(N)]
AB.sort()
ans = 0
for a, b in AB:
if M > b:
M -= b
ans += a*b
else:
ans += a*M
break
print(ans)
| 15 | 14 | 331 | 242 | N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
if M >= AB[i][1]:
ans += AB[i][0] * AB[i][1]
M -= AB[i][1]
else:
ans += AB[i][0] * M
M = 0
if M == 0:
break
print(ans)
| N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for i in range(N)]
AB.sort()
ans = 0
for a, b in AB:
if M > b:
M -= b
ans += a * b
else:
ans += a * M
break
print(ans)
| false | 6.666667 | [
"-AB = [list(map(int, input().split())) for i in range(N)]",
"-AB.sort(key=lambda x: x[0])",
"+AB = [tuple(map(int, input().split())) for i in range(N)]",
"+AB.sort()",
"-for i in range(N):",
"- if M >= AB[i][1]:",
"- ans += AB[i][0] * AB[i][1]",
"- M -= AB[i][1]",
"+for a, b in AB:",
"+ if M > b:",
"+ M -= b",
"+ ans += a * b",
"- ans += AB[i][0] * M",
"- M = 0",
"- if M == 0:",
"+ ans += a * M"
]
| false | 0.105173 | 0.042486 | 2.475457 | [
"s428218658",
"s728001799"
]
|
u735891571 | p02762 | python | s878352038 | s454864914 | 1,503 | 1,390 | 64,532 | 64,560 | Accepted | Accepted | 7.52 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
N, M, K = list(map(int,input().split()))
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
A, B = list(map(int,input().split()))
A -= 1
B -= 1
uf.union(A, B)
uf.find(A)
f_b[A].add(B)
f_b[B].add(A)
for i in range(K):
C, D = list(map(int,input().split()))
C -= 1
D -= 1
if uf.same(C, D):
f_b[C].add(D)
f_b[D].add(C)
for i in range(N):
ans.append(uf.size(i) - len(f_b[i]) - 1)
print((*ans)) |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
N, M, K = list(map(int,input().split()))
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
A, B = list(map(int,input().split()))
A -= 1
B -= 1
uf.union(A, B)
f_b[A].add(B)
f_b[B].add(A)
for i in range(K):
C, D = list(map(int,input().split()))
C -= 1
D -= 1
if uf.same(C, D):
f_b[C].add(D)
f_b[D].add(C)
for i in range(N):
ans.append(uf.size(i) - len(f_b[i]) - 1)
print((*ans)) | 60 | 59 | 1,345 | 1,329 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
N, M, K = list(map(int, input().split()))
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
uf.union(A, B)
uf.find(A)
f_b[A].add(B)
f_b[B].add(A)
for i in range(K):
C, D = list(map(int, input().split()))
C -= 1
D -= 1
if uf.same(C, D):
f_b[C].add(D)
f_b[D].add(C)
for i in range(N):
ans.append(uf.size(i) - len(f_b[i]) - 1)
print((*ans))
| class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
N, M, K = list(map(int, input().split()))
uf = UnionFind(N)
f_b = [set() for _ in range(N)]
ans = []
for i in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
uf.union(A, B)
f_b[A].add(B)
f_b[B].add(A)
for i in range(K):
C, D = list(map(int, input().split()))
C -= 1
D -= 1
if uf.same(C, D):
f_b[C].add(D)
f_b[D].add(C)
for i in range(N):
ans.append(uf.size(i) - len(f_b[i]) - 1)
print((*ans))
| false | 1.666667 | [
"- uf.find(A)"
]
| false | 0.035969 | 0.103656 | 0.347 | [
"s878352038",
"s454864914"
]
|
u416011173 | p02578 | python | s343479984 | s333489646 | 176 | 131 | 32,224 | 31,008 | Accepted | Accepted | 25.57 | # -*- coding: utf-8 -*-
# ๆจๆบๅ
ฅๅใๅๅพ
N = int(eval(input()))
A = list(map(int, input().split()))
# ๆฑ่งฃๅฆ็
ans = 0
highest = 0
for n in range(N):
highest = max(highest, A[n])
ans += max(highest - A[n], 0)
# ็ตๆๅบๅ
print(ans)
| # -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
ๆจๆบๅ
ฅๅใๅๅพใใ.
Returns:\n
tuple: ๆจๆบๅ
ฅๅ
"""
N = int(eval(input()))
A = list(map(int, input().split()))
return N, A
def main(A: list) -> None:
"""
ใกใคใณๅฆ็.
Args:\n
A (list): ่บซ้ท(1 <= A_i <= 10**9)
"""
# ๆฑ่งฃๅฆ็
ans = 0
highest = 0
for A_n in A:
highest = max(highest, A_n)
ans += max(highest - A_n, 0)
# ็ตๆๅบๅ
print(ans)
if __name__ == "__main__":
# ๆจๆบๅ
ฅๅใๅๅพ
N, A = get_input()
# ใกใคใณๅฆ็
main(A)
| 14 | 39 | 233 | 591 | # -*- coding: utf-8 -*-
# ๆจๆบๅ
ฅๅใๅๅพ
N = int(eval(input()))
A = list(map(int, input().split()))
# ๆฑ่งฃๅฆ็
ans = 0
highest = 0
for n in range(N):
highest = max(highest, A[n])
ans += max(highest - A[n], 0)
# ็ตๆๅบๅ
print(ans)
| # -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
ๆจๆบๅ
ฅๅใๅๅพใใ.
Returns:\n
tuple: ๆจๆบๅ
ฅๅ
"""
N = int(eval(input()))
A = list(map(int, input().split()))
return N, A
def main(A: list) -> None:
"""
ใกใคใณๅฆ็.
Args:\n
A (list): ่บซ้ท(1 <= A_i <= 10**9)
"""
# ๆฑ่งฃๅฆ็
ans = 0
highest = 0
for A_n in A:
highest = max(highest, A_n)
ans += max(highest - A_n, 0)
# ็ตๆๅบๅ
print(ans)
if __name__ == "__main__":
# ๆจๆบๅ
ฅๅใๅๅพ
N, A = get_input()
# ใกใคใณๅฆ็
main(A)
| false | 64.102564 | [
"-# ๆจๆบๅ
ฅๅใๅๅพ",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-# ๆฑ่งฃๅฆ็",
"-ans = 0",
"-highest = 0",
"-for n in range(N):",
"- highest = max(highest, A[n])",
"- ans += max(highest - A[n], 0)",
"-# ็ตๆๅบๅ",
"-print(ans)",
"+def get_input() -> tuple:",
"+ \"\"\"",
"+ ๆจๆบๅ
ฅๅใๅๅพใใ.",
"+ Returns:\\n",
"+ tuple: ๆจๆบๅ
ฅๅ",
"+ \"\"\"",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ return N, A",
"+",
"+",
"+def main(A: list) -> None:",
"+ \"\"\"",
"+ ใกใคใณๅฆ็.",
"+ Args:\\n",
"+ A (list): ่บซ้ท(1 <= A_i <= 10**9)",
"+ \"\"\"",
"+ # ๆฑ่งฃๅฆ็",
"+ ans = 0",
"+ highest = 0",
"+ for A_n in A:",
"+ highest = max(highest, A_n)",
"+ ans += max(highest - A_n, 0)",
"+ # ็ตๆๅบๅ",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ # ๆจๆบๅ
ฅๅใๅๅพ",
"+ N, A = get_input()",
"+ # ใกใคใณๅฆ็",
"+ main(A)"
]
| false | 0.076719 | 0.048593 | 1.578808 | [
"s343479984",
"s333489646"
]
|
u638282348 | p03607 | python | s034001540 | s116267816 | 232 | 75 | 15,032 | 18,400 | Accepted | Accepted | 67.67 | N = int(eval(input()))
d = dict()
for _ in range(N):
a = int(eval(input()))
d[a] = d.get(a, 0) ^ 1
print((sum(d.values()))) | N, *A = list(map(int, open(0).read().split()))
d = dict()
for a in A:
d[a] = d.get(a, 0) ^ 1
print((sum(d.values()))) | 6 | 5 | 122 | 117 | N = int(eval(input()))
d = dict()
for _ in range(N):
a = int(eval(input()))
d[a] = d.get(a, 0) ^ 1
print((sum(d.values())))
| N, *A = list(map(int, open(0).read().split()))
d = dict()
for a in A:
d[a] = d.get(a, 0) ^ 1
print((sum(d.values())))
| false | 16.666667 | [
"-N = int(eval(input()))",
"+N, *A = list(map(int, open(0).read().split()))",
"-for _ in range(N):",
"- a = int(eval(input()))",
"+for a in A:"
]
| false | 0.063092 | 0.035631 | 1.770682 | [
"s034001540",
"s116267816"
]
|
u227020436 | p02702 | python | s792171514 | s021788802 | 643 | 200 | 71,952 | 16,500 | Accepted | Accepted | 68.9 | # D - Multiple of 2019
s = eval(input())
# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1 # 10 ** n == 1 mod 2019
# memo[i % n][m] = (int(s[:i+1]) % 2019 == mใงใใiใฎๅๆฐ)
memo = [[0] * 2019 for i in range(n)]
memo[n - 1][0] = 1 # memo[-1][0] = 1
count = 0 # int(s[i:j+1]) == 0 mod 2019 ใงใใ(i,j)ใฎๅๆฐ
mod = 0
for j, c in enumerate(s):
mod = (mod * 10 + int(c)) % 2019 # mod = int(s[:j+1]) % 2019
for i in range(1, n + 1):
m = mod * pow[n - i] % 2019 # m == mod * 10 ** (-i) mod 2019
count += memo[(j - i + n) % n][m]
memo[j % n][mod] += 1
print(count)
| # D - Multiple of 2019
from collections import Counter
s = eval(input())
count = 0
counter = Counter([0])
suffix = [0] * (len(s) + 1)
pow = 1
for i in range(len(s) - 1, -1, -1):
suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019
pow = pow * 10 % 2019
count += counter[suffix[i]]
counter[suffix[i]] += 1
print(count)
| 24 | 18 | 676 | 350 | # D - Multiple of 2019
s = eval(input())
# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1 # 10 ** n == 1 mod 2019
# memo[i % n][m] = (int(s[:i+1]) % 2019 == mใงใใiใฎๅๆฐ)
memo = [[0] * 2019 for i in range(n)]
memo[n - 1][0] = 1 # memo[-1][0] = 1
count = 0 # int(s[i:j+1]) == 0 mod 2019 ใงใใ(i,j)ใฎๅๆฐ
mod = 0
for j, c in enumerate(s):
mod = (mod * 10 + int(c)) % 2019 # mod = int(s[:j+1]) % 2019
for i in range(1, n + 1):
m = mod * pow[n - i] % 2019 # m == mod * 10 ** (-i) mod 2019
count += memo[(j - i + n) % n][m]
memo[j % n][mod] += 1
print(count)
| # D - Multiple of 2019
from collections import Counter
s = eval(input())
count = 0
counter = Counter([0])
suffix = [0] * (len(s) + 1)
pow = 1
for i in range(len(s) - 1, -1, -1):
suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019
pow = pow * 10 % 2019
count += counter[suffix[i]]
counter[suffix[i]] += 1
print(count)
| false | 25 | [
"+from collections import Counter",
"+",
"-# pow[k] = 10 ** k % 2019",
"-pow = [1]",
"-while len(pow) <= 1 or pow[-1] > 1:",
"- pow.append(pow[-1] * 10 % 2019)",
"-n = len(pow) - 1 # 10 ** n == 1 mod 2019",
"-# memo[i % n][m] = (int(s[:i+1]) % 2019 == mใงใใiใฎๅๆฐ)",
"-memo = [[0] * 2019 for i in range(n)]",
"-memo[n - 1][0] = 1 # memo[-1][0] = 1",
"-count = 0 # int(s[i:j+1]) == 0 mod 2019 ใงใใ(i,j)ใฎๅๆฐ",
"-mod = 0",
"-for j, c in enumerate(s):",
"- mod = (mod * 10 + int(c)) % 2019 # mod = int(s[:j+1]) % 2019",
"- for i in range(1, n + 1):",
"- m = mod * pow[n - i] % 2019 # m == mod * 10 ** (-i) mod 2019",
"- count += memo[(j - i + n) % n][m]",
"- memo[j % n][mod] += 1",
"+count = 0",
"+counter = Counter([0])",
"+suffix = [0] * (len(s) + 1)",
"+pow = 1",
"+for i in range(len(s) - 1, -1, -1):",
"+ suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019",
"+ pow = pow * 10 % 2019",
"+ count += counter[suffix[i]]",
"+ counter[suffix[i]] += 1"
]
| false | 0.156318 | 0.038495 | 4.060773 | [
"s792171514",
"s021788802"
]
|
u677121387 | p02947 | python | s915211427 | s126379856 | 380 | 317 | 17,852 | 24,976 | Accepted | Accepted | 16.58 | n = int(eval(input()))
d = {}
ans = 0
for i in range(n):
s = "".join(sorted(eval(input())))
if s not in d:
d[s] = 1
else:
ans += d[s]
d[s] += 1
print(ans) | n = int(eval(input()))
S = [eval(input()) for _ in range(n)]
d = {}
ans = 0
for s in S:
x = "".join(sorted(s))
if x in d: ans += d[x]
d[x] = d.get(x,0) + 1
print(ans) | 13 | 9 | 196 | 174 | n = int(eval(input()))
d = {}
ans = 0
for i in range(n):
s = "".join(sorted(eval(input())))
if s not in d:
d[s] = 1
else:
ans += d[s]
d[s] += 1
print(ans)
| n = int(eval(input()))
S = [eval(input()) for _ in range(n)]
d = {}
ans = 0
for s in S:
x = "".join(sorted(s))
if x in d:
ans += d[x]
d[x] = d.get(x, 0) + 1
print(ans)
| false | 30.769231 | [
"+S = [eval(input()) for _ in range(n)]",
"-for i in range(n):",
"- s = \"\".join(sorted(eval(input())))",
"- if s not in d:",
"- d[s] = 1",
"- else:",
"- ans += d[s]",
"- d[s] += 1",
"+for s in S:",
"+ x = \"\".join(sorted(s))",
"+ if x in d:",
"+ ans += d[x]",
"+ d[x] = d.get(x, 0) + 1"
]
| false | 0.048032 | 0.04874 | 0.98546 | [
"s915211427",
"s126379856"
]
|
u832039789 | p03449 | python | s399106178 | s504540640 | 22 | 18 | 3,060 | 3,060 | Accepted | Accepted | 18.18 | res = 0
n = int(eval(input()))
a = [list(map(int,input().split())) for _ in range(2)]
# ใใใซใใใพใ
for i in range(n):
t = 0
tmp = 0
for j in range(n):
tmp += a[t][j]
if i==j:
t += 1
tmp += a[t][j]
res = max(res,tmp)
print(res)
| n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
res = 0
for i in range(n):
tmp = 0
for j in range(i + 1):
tmp += a[j]
for j in range(i, n):
tmp += b[j]
res = max(res, tmp)
print(res)
| 14 | 13 | 287 | 267 | res = 0
n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(2)]
# ใใใซใใใพใ
for i in range(n):
t = 0
tmp = 0
for j in range(n):
tmp += a[t][j]
if i == j:
t += 1
tmp += a[t][j]
res = max(res, tmp)
print(res)
| n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
tmp = 0
for j in range(i + 1):
tmp += a[j]
for j in range(i, n):
tmp += b[j]
res = max(res, tmp)
print(res)
| false | 7.142857 | [
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+b = list(map(int, input().split()))",
"-n = int(eval(input()))",
"-a = [list(map(int, input().split())) for _ in range(2)]",
"-# ใใใซใใใพใ",
"- t = 0",
"- for j in range(n):",
"- tmp += a[t][j]",
"- if i == j:",
"- t += 1",
"- tmp += a[t][j]",
"+ for j in range(i + 1):",
"+ tmp += a[j]",
"+ for j in range(i, n):",
"+ tmp += b[j]"
]
| false | 0.036587 | 0.035615 | 1.027296 | [
"s399106178",
"s504540640"
]
|
u761320129 | p03600 | python | s254276972 | s850101837 | 736 | 454 | 44,124 | 74,908 | Accepted | Accepted | 38.32 | N = int(eval(input()))
src = [list(map(int,input().split())) for i in range(N)]
ans = 0
for k in range(N):
for i in range(N):
for j in range(N):
if src[i][j] > src[i][k] + src[k][j]:
print((-1))
exit()
for i in range(N-1):
for j in range(i+1,N):
for k in range(N):
if k==i or k==j: continue
if src[i][j] == src[i][k] + src[k][j]:
break
else:
ans += src[i][j]
print(ans) | N = int(eval(input()))
A = [list(map(int,input().split())) for i in range(N)]
for k in range(N):
for i in range(N):
for j in range(N):
if A[i][j] > A[i][k] + A[k][j]:
print((-1))
exit()
ans = 0
for i in range(N-1):
for j in range(i+1,N):
for k in range(N):
if k==i or k==j: continue
if A[i][j] == A[i][k] + A[k][j]:
break
else:
ans += A[i][j]
print(ans) | 20 | 20 | 510 | 494 | N = int(eval(input()))
src = [list(map(int, input().split())) for i in range(N)]
ans = 0
for k in range(N):
for i in range(N):
for j in range(N):
if src[i][j] > src[i][k] + src[k][j]:
print((-1))
exit()
for i in range(N - 1):
for j in range(i + 1, N):
for k in range(N):
if k == i or k == j:
continue
if src[i][j] == src[i][k] + src[k][j]:
break
else:
ans += src[i][j]
print(ans)
| N = int(eval(input()))
A = [list(map(int, input().split())) for i in range(N)]
for k in range(N):
for i in range(N):
for j in range(N):
if A[i][j] > A[i][k] + A[k][j]:
print((-1))
exit()
ans = 0
for i in range(N - 1):
for j in range(i + 1, N):
for k in range(N):
if k == i or k == j:
continue
if A[i][j] == A[i][k] + A[k][j]:
break
else:
ans += A[i][j]
print(ans)
| false | 0 | [
"-src = [list(map(int, input().split())) for i in range(N)]",
"-ans = 0",
"+A = [list(map(int, input().split())) for i in range(N)]",
"- if src[i][j] > src[i][k] + src[k][j]:",
"+ if A[i][j] > A[i][k] + A[k][j]:",
"+ans = 0",
"- if src[i][j] == src[i][k] + src[k][j]:",
"+ if A[i][j] == A[i][k] + A[k][j]:",
"- ans += src[i][j]",
"+ ans += A[i][j]"
]
| false | 0.037616 | 0.037758 | 0.996242 | [
"s254276972",
"s850101837"
]
|
u631277801 | p03290 | python | s702976132 | s636409177 | 27 | 22 | 3,064 | 3,064 | Accepted | Accepted | 18.52 |
D,G = list(map(int, input().split()))
#prob_num = [3,5]
#comp = [500,800]
prob_num = []
comp = []
for i in range(D):
p,c = list(map(int, input().split()))
prob_num.append(p)
comp.append(c)
comp_point = []
for i in range(D):
comp_point.append((100*(i+1)*prob_num[i]+comp[i]))
ans = 1000000
for b in range(1<<D):
hasComp = []
for j in range(D):
if b & (1<<j):
hasComp.append(True)
else:
hasComp.append(False)
# compใใฆใใใฎใๆฑบใๆใก
point = 0
prb = 0
for i in range(D):
if hasComp[i]:
point += comp_point[i]
prb += prob_num[i]
res = G-point
while res>0:
flag = 0
for i in range(D-1,-1,-1):
if not hasComp[i]:
if res <= (100*(i+1)*(prob_num[i]-1)):
req_prob = (res//(100*(i+1))) + bool(res%(100*(i+1)))
prb += req_prob
res = 0
break
else:
prb += (prob_num[i]-1)
res -= (100*(i+1))*(prob_num[i]-1)
if i==0:
flag = 1
break
if flag:
break
if res<=0:
ans = min(ans,prb)
print(ans)
| D,G = list(map(int, input().split()))
prob_num = []
bonus = []
comp_pt = []
for i in range(D):
p,b = list(map(int, input().split()))
prob_num.append(p)
bonus.append(b)
comp_pt.append(100*(i+1)*p+b)
def dfs(hascomp:str, target:int, prob:int, depth:int) -> int:
if target <= 0:
#print(hascomp, depth, prob)
return prob
elif depth == D:
for i in range(D-1,-1,-1):
if hascomp[i] == "n":
if target <= 100*(i+1)*(prob_num[i]-1):
prob += (target//(100*(i+1)))+bool(target%(100*(i+1)))
#print(hascomp, depth, prob)
return prob
else:
prob += (prob_num[i]-1)
target -= 100*(i+1)*(prob_num[i]-1)
if target > 0:
#print(hascomp, depth, prob)
return 10**5
else:
new_tar = target-comp_pt[depth]
new_prob = prob + prob_num[depth]
return min(dfs(hascomp+"y",new_tar, new_prob, depth+1),
dfs(hascomp+"n",target, prob, depth+1))
ans = dfs("",G,0,0)
print(ans) | 64 | 40 | 1,374 | 1,201 | D, G = list(map(int, input().split()))
# prob_num = [3,5]
# comp = [500,800]
prob_num = []
comp = []
for i in range(D):
p, c = list(map(int, input().split()))
prob_num.append(p)
comp.append(c)
comp_point = []
for i in range(D):
comp_point.append((100 * (i + 1) * prob_num[i] + comp[i]))
ans = 1000000
for b in range(1 << D):
hasComp = []
for j in range(D):
if b & (1 << j):
hasComp.append(True)
else:
hasComp.append(False)
# compใใฆใใใฎใๆฑบใๆใก
point = 0
prb = 0
for i in range(D):
if hasComp[i]:
point += comp_point[i]
prb += prob_num[i]
res = G - point
while res > 0:
flag = 0
for i in range(D - 1, -1, -1):
if not hasComp[i]:
if res <= (100 * (i + 1) * (prob_num[i] - 1)):
req_prob = (res // (100 * (i + 1))) + bool(res % (100 * (i + 1)))
prb += req_prob
res = 0
break
else:
prb += prob_num[i] - 1
res -= (100 * (i + 1)) * (prob_num[i] - 1)
if i == 0:
flag = 1
break
if flag:
break
if res <= 0:
ans = min(ans, prb)
print(ans)
| D, G = list(map(int, input().split()))
prob_num = []
bonus = []
comp_pt = []
for i in range(D):
p, b = list(map(int, input().split()))
prob_num.append(p)
bonus.append(b)
comp_pt.append(100 * (i + 1) * p + b)
def dfs(hascomp: str, target: int, prob: int, depth: int) -> int:
if target <= 0:
# print(hascomp, depth, prob)
return prob
elif depth == D:
for i in range(D - 1, -1, -1):
if hascomp[i] == "n":
if target <= 100 * (i + 1) * (prob_num[i] - 1):
prob += (target // (100 * (i + 1))) + bool(target % (100 * (i + 1)))
# print(hascomp, depth, prob)
return prob
else:
prob += prob_num[i] - 1
target -= 100 * (i + 1) * (prob_num[i] - 1)
if target > 0:
# print(hascomp, depth, prob)
return 10**5
else:
new_tar = target - comp_pt[depth]
new_prob = prob + prob_num[depth]
return min(
dfs(hascomp + "y", new_tar, new_prob, depth + 1),
dfs(hascomp + "n", target, prob, depth + 1),
)
ans = dfs("", G, 0, 0)
print(ans)
| false | 37.5 | [
"-# prob_num = [3,5]",
"-# comp = [500,800]",
"-comp = []",
"+bonus = []",
"+comp_pt = []",
"- p, c = list(map(int, input().split()))",
"+ p, b = list(map(int, input().split()))",
"- comp.append(c)",
"-comp_point = []",
"-for i in range(D):",
"- comp_point.append((100 * (i + 1) * prob_num[i] + comp[i]))",
"-ans = 1000000",
"-for b in range(1 << D):",
"- hasComp = []",
"- for j in range(D):",
"- if b & (1 << j):",
"- hasComp.append(True)",
"- else:",
"- hasComp.append(False)",
"- # compใใฆใใใฎใๆฑบใๆใก",
"- point = 0",
"- prb = 0",
"- for i in range(D):",
"- if hasComp[i]:",
"- point += comp_point[i]",
"- prb += prob_num[i]",
"- res = G - point",
"- while res > 0:",
"- flag = 0",
"+ bonus.append(b)",
"+ comp_pt.append(100 * (i + 1) * p + b)",
"+",
"+",
"+def dfs(hascomp: str, target: int, prob: int, depth: int) -> int:",
"+ if target <= 0:",
"+ # print(hascomp, depth, prob)",
"+ return prob",
"+ elif depth == D:",
"- if not hasComp[i]:",
"- if res <= (100 * (i + 1) * (prob_num[i] - 1)):",
"- req_prob = (res // (100 * (i + 1))) + bool(res % (100 * (i + 1)))",
"- prb += req_prob",
"- res = 0",
"- break",
"+ if hascomp[i] == \"n\":",
"+ if target <= 100 * (i + 1) * (prob_num[i] - 1):",
"+ prob += (target // (100 * (i + 1))) + bool(target % (100 * (i + 1)))",
"+ # print(hascomp, depth, prob)",
"+ return prob",
"- prb += prob_num[i] - 1",
"- res -= (100 * (i + 1)) * (prob_num[i] - 1)",
"- if i == 0:",
"- flag = 1",
"- break",
"- if flag:",
"- break",
"- if res <= 0:",
"- ans = min(ans, prb)",
"+ prob += prob_num[i] - 1",
"+ target -= 100 * (i + 1) * (prob_num[i] - 1)",
"+ if target > 0:",
"+ # print(hascomp, depth, prob)",
"+ return 10**5",
"+ else:",
"+ new_tar = target - comp_pt[depth]",
"+ new_prob = prob + prob_num[depth]",
"+ return min(",
"+ dfs(hascomp + \"y\", new_tar, new_prob, depth + 1),",
"+ dfs(hascomp + \"n\", target, prob, depth + 1),",
"+ )",
"+",
"+",
"+ans = dfs(\"\", G, 0, 0)"
]
| false | 0.03495 | 0.042326 | 0.825734 | [
"s702976132",
"s636409177"
]
|
u112364985 | p02608 | python | s298096203 | s368866572 | 1,219 | 520 | 9,428 | 9,780 | Accepted | Accepted | 57.34 | import itertools
n=int(eval(input()))
mylist=[0]*n
a=1
while(6*(a**2)<n):
a+=1
l=list(range(1,3*a-1))
for c in itertools.product(l,repeat=3):
sum_num=sum(c)**2-(c[0]*c[1]+c[1]*c[2]+c[2]*c[0])
if sum_num<=n:
mylist[sum_num-1]+=1
for i in mylist:
print(i) | n=int(eval(input()))
l=[0]*(10**5)
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
l[(x*x+y*y+z*z+x*y+y*z+z*x)-1]+=1
for i in range(n):
print((l[i])) | 13 | 8 | 283 | 197 | import itertools
n = int(eval(input()))
mylist = [0] * n
a = 1
while 6 * (a**2) < n:
a += 1
l = list(range(1, 3 * a - 1))
for c in itertools.product(l, repeat=3):
sum_num = sum(c) ** 2 - (c[0] * c[1] + c[1] * c[2] + c[2] * c[0])
if sum_num <= n:
mylist[sum_num - 1] += 1
for i in mylist:
print(i)
| n = int(eval(input()))
l = [0] * (10**5)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
l[(x * x + y * y + z * z + x * y + y * z + z * x) - 1] += 1
for i in range(n):
print((l[i]))
| false | 38.461538 | [
"-import itertools",
"-",
"-mylist = [0] * n",
"-a = 1",
"-while 6 * (a**2) < n:",
"- a += 1",
"-l = list(range(1, 3 * a - 1))",
"-for c in itertools.product(l, repeat=3):",
"- sum_num = sum(c) ** 2 - (c[0] * c[1] + c[1] * c[2] + c[2] * c[0])",
"- if sum_num <= n:",
"- mylist[sum_num - 1] += 1",
"-for i in mylist:",
"- print(i)",
"+l = [0] * (10**5)",
"+for x in range(1, 101):",
"+ for y in range(1, 101):",
"+ for z in range(1, 101):",
"+ l[(x * x + y * y + z * z + x * y + y * z + z * x) - 1] += 1",
"+for i in range(n):",
"+ print((l[i]))"
]
| false | 0.066689 | 0.687157 | 0.097051 | [
"s298096203",
"s368866572"
]
|
u777299405 | p00022 | python | s340896758 | s830464009 | 2,360 | 40 | 7,932 | 7,728 | Accepted | Accepted | 98.31 | import itertools
while True:
n = int(eval(input()))
if n == 0:
break
else:
a = [int(eval(input())) for i in range(n)]
a = list(itertools.accumulate(a))
a.insert(0, 0)
ans = -100000
for j in range(n):
for k in range(j + 1, n + 1):
ans = max(ans, a[k] - a[j])
print(ans) | while True:
n = int(eval(input()))
if n == 0:
break
else:
a = [int(eval(input())) for i in range(n)]
for i in range(1, n):
a[i] = max(a[i - 1] + a[i], a[i])
print((max(a))) | 15 | 9 | 367 | 222 | import itertools
while True:
n = int(eval(input()))
if n == 0:
break
else:
a = [int(eval(input())) for i in range(n)]
a = list(itertools.accumulate(a))
a.insert(0, 0)
ans = -100000
for j in range(n):
for k in range(j + 1, n + 1):
ans = max(ans, a[k] - a[j])
print(ans)
| while True:
n = int(eval(input()))
if n == 0:
break
else:
a = [int(eval(input())) for i in range(n)]
for i in range(1, n):
a[i] = max(a[i - 1] + a[i], a[i])
print((max(a)))
| false | 40 | [
"-import itertools",
"-",
"- a = list(itertools.accumulate(a))",
"- a.insert(0, 0)",
"- ans = -100000",
"- for j in range(n):",
"- for k in range(j + 1, n + 1):",
"- ans = max(ans, a[k] - a[j])",
"- print(ans)",
"+ for i in range(1, n):",
"+ a[i] = max(a[i - 1] + a[i], a[i])",
"+ print((max(a)))"
]
| false | 0.036895 | 0.037776 | 0.976677 | [
"s340896758",
"s830464009"
]
|
u086503932 | p03472 | python | s558218201 | s244416863 | 338 | 296 | 17,508 | 20,988 | Accepted | Accepted | 12.43 | #!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right,bisect_left
from itertools import accumulate
def main():
N, H = list(map(int, input().split()))
a = [None] * N
b = [None] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
i = bisect_left(b,a[N-1])
c = list(accumulate(b[i:][::-1]))
# print(c)
M = len(c)
count = bisect_left(c,H)
if count < M:
print((count+1))
else:
print((count + (H-c[M-1] + a[N-1]-1)//a[N-1]))
if __name__ == "__main__":
main()
| from heapq import heappop, heappush
N, H = list(map(int, input().split()))
a = [None] * N
b = [None] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
q = []
for i in range(N):
if b[i] > a[-1]:
heappush(q, -b[i])
ans = 0
while q:
H += heappop(q)
ans += 1
if H <= 0:
print(ans)
exit()
print((ans + (H+a[-1]-1)//a[-1])) | 26 | 24 | 654 | 410 | #!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right, bisect_left
from itertools import accumulate
def main():
N, H = list(map(int, input().split()))
a = [None] * N
b = [None] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
i = bisect_left(b, a[N - 1])
c = list(accumulate(b[i:][::-1]))
# print(c)
M = len(c)
count = bisect_left(c, H)
if count < M:
print((count + 1))
else:
print((count + (H - c[M - 1] + a[N - 1] - 1) // a[N - 1]))
if __name__ == "__main__":
main()
| from heapq import heappop, heappush
N, H = list(map(int, input().split()))
a = [None] * N
b = [None] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
q = []
for i in range(N):
if b[i] > a[-1]:
heappush(q, -b[i])
ans = 0
while q:
H += heappop(q)
ans += 1
if H <= 0:
print(ans)
exit()
print((ans + (H + a[-1] - 1) // a[-1]))
| false | 7.692308 | [
"-#!/usr/bin/env python3",
"-from collections import deque, Counter",
"-from bisect import bisect_right, bisect_left",
"-from itertools import accumulate",
"-",
"-def main():",
"- N, H = list(map(int, input().split()))",
"- a = [None] * N",
"- b = [None] * N",
"- for i in range(N):",
"- a[i], b[i] = list(map(int, input().split()))",
"- a.sort()",
"- b.sort()",
"- i = bisect_left(b, a[N - 1])",
"- c = list(accumulate(b[i:][::-1]))",
"- # print(c)",
"- M = len(c)",
"- count = bisect_left(c, H)",
"- if count < M:",
"- print((count + 1))",
"- else:",
"- print((count + (H - c[M - 1] + a[N - 1] - 1) // a[N - 1]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N, H = list(map(int, input().split()))",
"+a = [None] * N",
"+b = [None] * N",
"+for i in range(N):",
"+ a[i], b[i] = list(map(int, input().split()))",
"+a.sort()",
"+b.sort()",
"+q = []",
"+for i in range(N):",
"+ if b[i] > a[-1]:",
"+ heappush(q, -b[i])",
"+ans = 0",
"+while q:",
"+ H += heappop(q)",
"+ ans += 1",
"+ if H <= 0:",
"+ print(ans)",
"+ exit()",
"+print((ans + (H + a[-1] - 1) // a[-1]))"
]
| false | 0.050509 | 0.049049 | 1.029771 | [
"s558218201",
"s244416863"
]
|
u788337030 | p02726 | python | s204643506 | s534695462 | 1,418 | 1,311 | 3,444 | 3,444 | Accepted | Accepted | 7.55 | n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
if b_1 < 0:
b_1 = - b_1
for j in range(i+1, n):
l = j + 1
a = l - k
b_2 = l - y
if b_2 < 0:
b_2 = - b_2
b = b_1 + b_2 + 1
if b < a:
a = b
ans[a-1] += 1
for i in range(n-1):
print((ans[i])) | n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n-1)]
for i in range(n-1):
k = i + 1
b_1 = k - x
for j in range(i+1, n):
l = j + 1
a = l - k
b = abs(k - x) + abs(l - y) + 1
if b < a:
a = b
ans[a-1] += 1
for i in range(n-1):
print((ans[i])) | 19 | 14 | 369 | 296 | n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n - 1)]
for i in range(n - 1):
k = i + 1
b_1 = k - x
if b_1 < 0:
b_1 = -b_1
for j in range(i + 1, n):
l = j + 1
a = l - k
b_2 = l - y
if b_2 < 0:
b_2 = -b_2
b = b_1 + b_2 + 1
if b < a:
a = b
ans[a - 1] += 1
for i in range(n - 1):
print((ans[i]))
| n, x, y = list(map(int, input().split()))
ans = [0 for i in range(n - 1)]
for i in range(n - 1):
k = i + 1
b_1 = k - x
for j in range(i + 1, n):
l = j + 1
a = l - k
b = abs(k - x) + abs(l - y) + 1
if b < a:
a = b
ans[a - 1] += 1
for i in range(n - 1):
print((ans[i]))
| false | 26.315789 | [
"- if b_1 < 0:",
"- b_1 = -b_1",
"- b_2 = l - y",
"- if b_2 < 0:",
"- b_2 = -b_2",
"- b = b_1 + b_2 + 1",
"+ b = abs(k - x) + abs(l - y) + 1"
]
| false | 0.03638 | 0.040409 | 0.9003 | [
"s204643506",
"s534695462"
]
|
u312025627 | p03049 | python | s578141859 | s900354154 | 308 | 270 | 45,160 | 44,760 | Accepted | Accepted | 12.34 | def main():
N = int(eval(input()))
ab_cnt = 0
b_cnt = 0
a_cnt = 0
ans = 0
for _ in range(N):
S = eval(input())
ans += S.count("AB")
if S[0] == "B" and S[-1] == "A":
ab_cnt += 1
elif S[0] == "B":
b_cnt += 1
elif S[-1] == "A":
a_cnt += 1
if ab_cnt > 1:
ans += max(ab_cnt - 1, 0)
ab_cnt = 1
if a_cnt <= b_cnt:
ans += a_cnt
a_cnt = 0
b_cnt -= a_cnt
elif b_cnt < a_cnt:
ans += b_cnt
b_cnt = 0
a_cnt -= b_cnt
if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):
ans += 1
print(ans)
if __name__ == '__main__':
main()
| def main():
N = int(eval(input()))
A = [eval(input()) for i in range(N)]
ans = 0
ba = 0
b = 0
a = 0
for s in A:
ans += s.count("AB")
if s[0] == "B" and s[-1] == "A":
ba += 1
elif s[0] == "B":
b += 1
elif s[-1] == "A":
a += 1
ans += (ba - 1 if ba > 1 else 0)
if ba > 0 and a > 0 and b > 0:
b += 1
a += 1
ans += min(a, b)
elif ba > 0 and a == 0 and b == 0:
pass
elif ba > 0 and a > 0:
ans += 1
elif ba > 0 and b > 0:
ans += 1
elif ba == 0:
ans += min(a, b)
print(ans)
if __name__ == '__main__':
main()
| 33 | 33 | 719 | 706 | def main():
N = int(eval(input()))
ab_cnt = 0
b_cnt = 0
a_cnt = 0
ans = 0
for _ in range(N):
S = eval(input())
ans += S.count("AB")
if S[0] == "B" and S[-1] == "A":
ab_cnt += 1
elif S[0] == "B":
b_cnt += 1
elif S[-1] == "A":
a_cnt += 1
if ab_cnt > 1:
ans += max(ab_cnt - 1, 0)
ab_cnt = 1
if a_cnt <= b_cnt:
ans += a_cnt
a_cnt = 0
b_cnt -= a_cnt
elif b_cnt < a_cnt:
ans += b_cnt
b_cnt = 0
a_cnt -= b_cnt
if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):
ans += 1
print(ans)
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
A = [eval(input()) for i in range(N)]
ans = 0
ba = 0
b = 0
a = 0
for s in A:
ans += s.count("AB")
if s[0] == "B" and s[-1] == "A":
ba += 1
elif s[0] == "B":
b += 1
elif s[-1] == "A":
a += 1
ans += ba - 1 if ba > 1 else 0
if ba > 0 and a > 0 and b > 0:
b += 1
a += 1
ans += min(a, b)
elif ba > 0 and a == 0 and b == 0:
pass
elif ba > 0 and a > 0:
ans += 1
elif ba > 0 and b > 0:
ans += 1
elif ba == 0:
ans += min(a, b)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- ab_cnt = 0",
"- b_cnt = 0",
"- a_cnt = 0",
"+ A = [eval(input()) for i in range(N)]",
"- for _ in range(N):",
"- S = eval(input())",
"- ans += S.count(\"AB\")",
"- if S[0] == \"B\" and S[-1] == \"A\":",
"- ab_cnt += 1",
"- elif S[0] == \"B\":",
"- b_cnt += 1",
"- elif S[-1] == \"A\":",
"- a_cnt += 1",
"- if ab_cnt > 1:",
"- ans += max(ab_cnt - 1, 0)",
"- ab_cnt = 1",
"- if a_cnt <= b_cnt:",
"- ans += a_cnt",
"- a_cnt = 0",
"- b_cnt -= a_cnt",
"- elif b_cnt < a_cnt:",
"- ans += b_cnt",
"- b_cnt = 0",
"- a_cnt -= b_cnt",
"- if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):",
"+ ba = 0",
"+ b = 0",
"+ a = 0",
"+ for s in A:",
"+ ans += s.count(\"AB\")",
"+ if s[0] == \"B\" and s[-1] == \"A\":",
"+ ba += 1",
"+ elif s[0] == \"B\":",
"+ b += 1",
"+ elif s[-1] == \"A\":",
"+ a += 1",
"+ ans += ba - 1 if ba > 1 else 0",
"+ if ba > 0 and a > 0 and b > 0:",
"+ b += 1",
"+ a += 1",
"+ ans += min(a, b)",
"+ elif ba > 0 and a == 0 and b == 0:",
"+ pass",
"+ elif ba > 0 and a > 0:",
"+ elif ba > 0 and b > 0:",
"+ ans += 1",
"+ elif ba == 0:",
"+ ans += min(a, b)"
]
| false | 0.038703 | 0.038738 | 0.999081 | [
"s578141859",
"s900354154"
]
|
u729133443 | p03240 | python | s861376616 | s085201417 | 49 | 43 | 3,700 | 3,700 | Accepted | Accepted | 12.24 | A=abs
_,*p=[list(map(int,t.split()))for t in open(0)]
x,y,h=[t for t in p if t[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print((*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))) | A=abs
_,*p=[list(map(int,t.split()))for t in open(0)]
for t in p:
if t[2]:x,y,h=t
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print((*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))) | 4 | 5 | 206 | 204 | A = abs
_, *p = [list(map(int, t.split())) for t in open(0)]
x, y, h = [t for t in p if t[2]][0]
for I in range(10201):
j, i = I // 101, I % 101
H = h + A(x - j) + A(y - i)
print((*(j, i, H) * all(u == max(H - A(s - j) - A(t - i), 0) for s, t, u in p)))
| A = abs
_, *p = [list(map(int, t.split())) for t in open(0)]
for t in p:
if t[2]:
x, y, h = t
for I in range(10201):
j, i = I // 101, I % 101
H = h + A(x - j) + A(y - i)
print((*(j, i, H) * all(u == max(H - A(s - j) - A(t - i), 0) for s, t, u in p)))
| false | 20 | [
"-x, y, h = [t for t in p if t[2]][0]",
"+for t in p:",
"+ if t[2]:",
"+ x, y, h = t"
]
| false | 0.135172 | 0.127962 | 1.056349 | [
"s861376616",
"s085201417"
]
|
u179169725 | p02698 | python | s060259270 | s966259526 | 1,464 | 947 | 554,452 | 232,364 | Accepted | Accepted | 35.31 | # ๆจใซใใฃใฆLISใไฝใใdfsใงๆใใใจใใซLISใใใฎๅใฎ็ถๆ
ใพใงๅพฉๅ
ใใ
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def mina1(x):
return int(x) - 1
def read_ints(mina=False):
if mina:
return list(map(mina1, read().split()))
else:
return list(map(int, read().split()))
def read_a_int():
return int(read())
from bisect import bisect_left, bisect_right
####################
# dp = []
# for a in A:
# print(dp)
# idx = bisect_left(dp, a) # ๅใใฆ็ใซๅคงใใ่ฆ็ด ใซใชใidx
# if idx == len(dp):
# dp.append(a)
# else:
# dp[idx] = a # aใซๆดๆฐ
# print(dp)
# print(len(dp))
####################
from collections import defaultdict
N = read_a_int()
A = read_ints()
tree = defaultdict(lambda: [])
for _ in ra(N - 1):
u, v = read_ints(mina=True)
tree[u].append(v)
tree[v].append(u)
LIS = []
ans = [0] * N # ๅใใผใใฎlen(LIS)ใ่จ้ฒ
def dfs(now, p): # ็พๅจใฎใใผใใ่ฆช
# ็ตไบๆกไปถ# ๅญใ็กใใจใ
# LISใฎๆดๆฐ
idx = bisect_left(LIS, A[now])
is_append = False
if idx == len(LIS):
LIS.append(A[now])
is_append = True
else:
old = LIS[idx] # ใชใใฎๅคใ ใฃใใๆใฃใฆใใ
LIS[idx] = A[now] # aใซๆดๆฐ
ans[now] = len(LIS) # ็ญใใ่จ้ฒ
# ๆฌกใฎใใผใใๆข็ดข
for to in tree[now]:
if to == p:
continue
dfs(to, now)
# ๆใใใจใใซLISใๅพฉๅ
if is_append:
del LIS[idx]
else:
LIS[idx] = old
dfs(0, -1)
print(*ans, sep='\n')
| # ๆจใซใใฃใฆLISใไฝใใdfsใงๆใใใจใใซLISใใใฎๅใฎ็ถๆ
ใพใงๅพฉๅ
ใใ
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def mina1(x):
return int(x) - 1
def read_ints(mina=False):
if mina:
return list(map(mina1, read().split()))
else:
return list(map(int, read().split()))
def read_a_int():
return int(read())
from bisect import bisect_left, bisect_right
from collections import defaultdict
N = read_a_int()
A = read_ints()
tree = defaultdict(lambda: [])
for _ in ra(N - 1):
u, v = read_ints(mina=True)
tree[u].append(v)
tree[v].append(u)
LIS = []
ans = [0] * N # ๅใใผใใฎlen(LIS)ใ่จ้ฒ
def dfs(now, p): # ็พๅจใฎใใผใใ่ฆช
a = A[now]
# LISใฎๆดๆฐ
idx = bisect_left(LIS, a)
is_append = False
if idx == len(LIS):
LIS.append(a)
is_append = True
else:
old = LIS[idx] # ใชใใฎๅคใ ใฃใใๆใฃใฆใใ
LIS[idx] = a # aใซๆดๆฐ
ans[now] = len(LIS) # ็ญใใ่จ้ฒ
# ๆฌกใฎใใผใใๆข็ดข
for to in tree[now]:
if to == p:
continue
dfs(to, now)
# ๆใใใจใใซLISใๅพฉๅ
if is_append:
del LIS[idx]
else:
LIS[idx] = old
dfs(0, -1)
print(*ans, sep='\n')
| 80 | 66 | 1,528 | 1,241 | # ๆจใซใใฃใฆLISใไฝใใdfsใงๆใใใจใใซLISใใใฎๅใฎ็ถๆ
ใพใงๅพฉๅ
ใใ
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def mina1(x):
return int(x) - 1
def read_ints(mina=False):
if mina:
return list(map(mina1, read().split()))
else:
return list(map(int, read().split()))
def read_a_int():
return int(read())
from bisect import bisect_left, bisect_right
####################
# dp = []
# for a in A:
# print(dp)
# idx = bisect_left(dp, a) # ๅใใฆ็ใซๅคงใใ่ฆ็ด ใซใชใidx
# if idx == len(dp):
# dp.append(a)
# else:
# dp[idx] = a # aใซๆดๆฐ
# print(dp)
# print(len(dp))
####################
from collections import defaultdict
N = read_a_int()
A = read_ints()
tree = defaultdict(lambda: [])
for _ in ra(N - 1):
u, v = read_ints(mina=True)
tree[u].append(v)
tree[v].append(u)
LIS = []
ans = [0] * N # ๅใใผใใฎlen(LIS)ใ่จ้ฒ
def dfs(now, p): # ็พๅจใฎใใผใใ่ฆช
# ็ตไบๆกไปถ# ๅญใ็กใใจใ
# LISใฎๆดๆฐ
idx = bisect_left(LIS, A[now])
is_append = False
if idx == len(LIS):
LIS.append(A[now])
is_append = True
else:
old = LIS[idx] # ใชใใฎๅคใ ใฃใใๆใฃใฆใใ
LIS[idx] = A[now] # aใซๆดๆฐ
ans[now] = len(LIS) # ็ญใใ่จ้ฒ
# ๆฌกใฎใใผใใๆข็ดข
for to in tree[now]:
if to == p:
continue
dfs(to, now)
# ๆใใใจใใซLISใๅพฉๅ
if is_append:
del LIS[idx]
else:
LIS[idx] = old
dfs(0, -1)
print(*ans, sep="\n")
| # ๆจใซใใฃใฆLISใไฝใใdfsใงๆใใใจใใซLISใใใฎๅใฎ็ถๆ
ใพใงๅพฉๅ
ใใ
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def mina1(x):
return int(x) - 1
def read_ints(mina=False):
if mina:
return list(map(mina1, read().split()))
else:
return list(map(int, read().split()))
def read_a_int():
return int(read())
from bisect import bisect_left, bisect_right
from collections import defaultdict
N = read_a_int()
A = read_ints()
tree = defaultdict(lambda: [])
for _ in ra(N - 1):
u, v = read_ints(mina=True)
tree[u].append(v)
tree[v].append(u)
LIS = []
ans = [0] * N # ๅใใผใใฎlen(LIS)ใ่จ้ฒ
def dfs(now, p): # ็พๅจใฎใใผใใ่ฆช
a = A[now]
# LISใฎๆดๆฐ
idx = bisect_left(LIS, a)
is_append = False
if idx == len(LIS):
LIS.append(a)
is_append = True
else:
old = LIS[idx] # ใชใใฎๅคใ ใฃใใๆใฃใฆใใ
LIS[idx] = a # aใซๆดๆฐ
ans[now] = len(LIS) # ็ญใใ่จ้ฒ
# ๆฌกใฎใใผใใๆข็ดข
for to in tree[now]:
if to == p:
continue
dfs(to, now)
# ๆใใใจใใซLISใๅพฉๅ
if is_append:
del LIS[idx]
else:
LIS[idx] = old
dfs(0, -1)
print(*ans, sep="\n")
| false | 17.5 | [
"-",
"-####################",
"-# dp = []",
"-# for a in A:",
"-# print(dp)",
"-# idx = bisect_left(dp, a) # ๅใใฆ็ใซๅคงใใ่ฆ็ด ใซใชใidx",
"-# if idx == len(dp):",
"-# dp.append(a)",
"-# else:",
"-# dp[idx] = a # aใซๆดๆฐ",
"-# print(dp)",
"-# print(len(dp))",
"-####################",
"- # ็ตไบๆกไปถ# ๅญใ็กใใจใ",
"+ a = A[now]",
"- idx = bisect_left(LIS, A[now])",
"+ idx = bisect_left(LIS, a)",
"- LIS.append(A[now])",
"+ LIS.append(a)",
"- LIS[idx] = A[now] # aใซๆดๆฐ",
"+ LIS[idx] = a # aใซๆดๆฐ"
]
| false | 0.037705 | 0.03649 | 1.033294 | [
"s060259270",
"s966259526"
]
|
u585482323 | p04044 | python | s061441411 | s902456394 | 232 | 199 | 43,496 | 38,512 | Accepted | Accepted | 14.22 | #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007
#A
"""
a = LI()
i = a.count(5)
j = a.count(7)
if i == 2 and j == 1:
print("YES")
else:
print("NO")
"""
#B
n,l = LI()
s = SR(n)
s.sort()
for i in s:
for j in i:
print(j,end = "")
print()
#C
"""
def check(n):
n = list(map(int,list(str(n))))
s = 0
for i in n:
s += f[i]
return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
f[i] = 1
while 1:
if check(n):
print(n)
quit()
n += 1
"""
#D
"""
def f(x,y):
return fact[x-1+h-y]*fact[y-1+w-x]*inv_fact[x-1]*inv_fact[y-1]*inv_fact[w-x]*inv_fact[h-y]%mod
h,w,a,b = LI()
fact = [1]*(h+w+1)
for i in range(h+w):
fact[i+1] = fact[i]*(i+1)%mod
inv_fact = [0]*(h+w+1)
inv_fact[h+w] = pow(fact[-1],mod-2,mod)
for i in range(h+w)[::-1]:
inv_fact[i] = inv_fact[i+1]*(i+1)%mod
ans = 0
for i in range(1,min(w-b,h-a)+1):
ans += f(b+i,a+i)
ans %= mod
print(ans)
"""
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n,l = LI()
s = [input() for i in range(n)]
s.sort()
for i in s:
print(i,end = "")
print()
return
#Solve
if __name__ == "__main__":
solve()
| 107 | 39 | 1,626 | 943 | #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
mod = 1000000007
# A
"""
a = LI()
i = a.count(5)
j = a.count(7)
if i == 2 and j == 1:
print("YES")
else:
print("NO")
"""
# B
n, l = LI()
s = SR(n)
s.sort()
for i in s:
for j in i:
print(j, end="")
print()
# C
"""
def check(n):
n = list(map(int,list(str(n))))
s = 0
for i in n:
s += f[i]
return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
f[i] = 1
while 1:
if check(n):
print(n)
quit()
n += 1
"""
# D
"""
def f(x,y):
return fact[x-1+h-y]*fact[y-1+w-x]*inv_fact[x-1]*inv_fact[y-1]*inv_fact[w-x]*inv_fact[h-y]%mod
h,w,a,b = LI()
fact = [1]*(h+w+1)
for i in range(h+w):
fact[i+1] = fact[i]*(i+1)%mod
inv_fact = [0]*(h+w+1)
inv_fact[h+w] = pow(fact[-1],mod-2,mod)
for i in range(h+w)[::-1]:
inv_fact[i] = inv_fact[i+1]*(i+1)%mod
ans = 0
for i in range(1,min(w-b,h-a)+1):
ans += f(b+i,a+i)
ans %= mod
print(ans)
"""
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.buffer.readline().split()]
def I():
return int(sys.stdin.buffer.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n, l = LI()
s = [input() for i in range(n)]
s.sort()
for i in s:
print(i, end="")
print()
return
# Solve
if __name__ == "__main__":
solve()
| false | 63.551402 | [
"-from collections import defaultdict",
"+from collections import defaultdict, deque",
"+from itertools import permutations, accumulate",
"-import random",
"- return list(map(int, sys.stdin.readline().split()))",
"+ return [int(x) for x in sys.stdin.buffer.readline().split()]",
"- return int(sys.stdin.readline())",
"+ return int(sys.stdin.buffer.readline())",
"- return list(map(list, sys.stdin.readline().split()))",
"+ return [list(x) for x in sys.stdin.readline().split()]",
"- return list(sys.stdin.readline())[:-1]",
"+ res = list(sys.stdin.readline())",
"+ if res[-1] == \"\\n\":",
"+ return res[:-1]",
"+ return res",
"+sys.setrecursionlimit(1000000)",
"-# A",
"-\"\"\"",
"-a = LI()",
"-i = a.count(5)",
"-j = a.count(7)",
"-if i == 2 and j == 1:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"-\"\"\"",
"-# B",
"-n, l = LI()",
"-s = SR(n)",
"-s.sort()",
"-for i in s:",
"- for j in i:",
"- print(j, end=\"\")",
"-print()",
"-# C",
"-\"\"\"",
"-def check(n):",
"- n = list(map(int,list(str(n))))",
"- s = 0",
"- for i in n:",
"- s += f[i]",
"- return s == 0",
"-n,k = LI()",
"-d = LI()",
"-f = [0 for i in range(10)]",
"-for i in d:",
"- f[i] = 1",
"-while 1:",
"- if check(n):",
"- print(n)",
"- quit()",
"- n += 1",
"-\"\"\"",
"-# D",
"-\"\"\"",
"-def f(x,y):",
"- return fact[x-1+h-y]*fact[y-1+w-x]*inv_fact[x-1]*inv_fact[y-1]*inv_fact[w-x]*inv_fact[h-y]%mod",
"-h,w,a,b = LI()",
"-fact = [1]*(h+w+1)",
"-for i in range(h+w):",
"- fact[i+1] = fact[i]*(i+1)%mod",
"-inv_fact = [0]*(h+w+1)",
"-inv_fact[h+w] = pow(fact[-1],mod-2,mod)",
"-for i in range(h+w)[::-1]:",
"- inv_fact[i] = inv_fact[i+1]*(i+1)%mod",
"-ans = 0",
"-for i in range(1,min(w-b,h-a)+1):",
"- ans += f(b+i,a+i)",
"- ans %= mod",
"-print(ans)",
"-\"\"\"",
"-# E",
"-# F",
"-# G",
"-# H",
"-# I",
"-# J",
"-# K",
"-# L",
"-# M",
"-# N",
"-# O",
"-# P",
"-# Q",
"-# R",
"-# S",
"-# T",
"+",
"+",
"+def solve():",
"+ n, l = LI()",
"+ s = [input() for i in range(n)]",
"+ s.sort()",
"+ for i in s:",
"+ print(i, end=\"\")",
"+ print()",
"+ return",
"+",
"+",
"+# Solve",
"+if __name__ == \"__main__\":",
"+ solve()"
]
| false | 0.081674 | 0.078164 | 1.044904 | [
"s061441411",
"s902456394"
]
|
u797673668 | p02278 | python | s171047226 | s395642410 | 160 | 40 | 7,832 | 7,764 | Accepted | Accepted | 75 | def perfect_swap():
global n, a, b, cost
for i in range(1, n - 1):
for j in range(i + 1, n):
ai, aj = a[i], a[j]
if ai == b[j] and aj == b[i]:
a[i], a[j] = aj, ai
cost += ai + aj
def lowest_swap():
global n, a, b, cost
for i in range(n - 1):
bi, tmp_cost, count = b[i], 0, 0
while a[i] != bi:
si = a.index(bi)
bsi = b[si]
sj = a.index(bsi)
a[si], a[sj] = bsi, bi
tmp_cost += bi + bsi
count += 1
if count:
if i:
b0 = b[0]
cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)
else:
cost += tmp_cost
n, a, cost = int(eval(input())), list(map(int, input().split())), 0
b = sorted(a)
perfect_swap()
lowest_swap()
print(cost) | n, a, cost = int(eval(input())), list(map(int, input().split())), 0
b = sorted(a)
b0 = b[0]
for i in range(n - 1):
bi, tmp_cost, count = b[i], 0, 0
si = a.index(bi)
while si != i:
bsi = b[si]
sj = a.index(bsi)
a[si], a[sj] = bsi, bi
tmp_cost += bi + bsi
count += 1
si = sj
if count:
cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)
print(cost) | 34 | 16 | 913 | 443 | def perfect_swap():
global n, a, b, cost
for i in range(1, n - 1):
for j in range(i + 1, n):
ai, aj = a[i], a[j]
if ai == b[j] and aj == b[i]:
a[i], a[j] = aj, ai
cost += ai + aj
def lowest_swap():
global n, a, b, cost
for i in range(n - 1):
bi, tmp_cost, count = b[i], 0, 0
while a[i] != bi:
si = a.index(bi)
bsi = b[si]
sj = a.index(bsi)
a[si], a[sj] = bsi, bi
tmp_cost += bi + bsi
count += 1
if count:
if i:
b0 = b[0]
cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)
else:
cost += tmp_cost
n, a, cost = int(eval(input())), list(map(int, input().split())), 0
b = sorted(a)
perfect_swap()
lowest_swap()
print(cost)
| n, a, cost = int(eval(input())), list(map(int, input().split())), 0
b = sorted(a)
b0 = b[0]
for i in range(n - 1):
bi, tmp_cost, count = b[i], 0, 0
si = a.index(bi)
while si != i:
bsi = b[si]
sj = a.index(bsi)
a[si], a[sj] = bsi, bi
tmp_cost += bi + bsi
count += 1
si = sj
if count:
cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)
print(cost)
| false | 52.941176 | [
"-def perfect_swap():",
"- global n, a, b, cost",
"- for i in range(1, n - 1):",
"- for j in range(i + 1, n):",
"- ai, aj = a[i], a[j]",
"- if ai == b[j] and aj == b[i]:",
"- a[i], a[j] = aj, ai",
"- cost += ai + aj",
"-",
"-",
"-def lowest_swap():",
"- global n, a, b, cost",
"- for i in range(n - 1):",
"- bi, tmp_cost, count = b[i], 0, 0",
"- while a[i] != bi:",
"- si = a.index(bi)",
"- bsi = b[si]",
"- sj = a.index(bsi)",
"- a[si], a[sj] = bsi, bi",
"- tmp_cost += bi + bsi",
"- count += 1",
"- if count:",
"- if i:",
"- b0 = b[0]",
"- cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)",
"- else:",
"- cost += tmp_cost",
"-",
"-",
"-perfect_swap()",
"-lowest_swap()",
"+b0 = b[0]",
"+for i in range(n - 1):",
"+ bi, tmp_cost, count = b[i], 0, 0",
"+ si = a.index(bi)",
"+ while si != i:",
"+ bsi = b[si]",
"+ sj = a.index(bsi)",
"+ a[si], a[sj] = bsi, bi",
"+ tmp_cost += bi + bsi",
"+ count += 1",
"+ si = sj",
"+ if count:",
"+ cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)"
]
| false | 0.041139 | 0.036762 | 1.11908 | [
"s171047226",
"s395642410"
]
|
u753803401 | p02947 | python | s131733043 | s963239827 | 395 | 356 | 72,540 | 64,092 | Accepted | Accepted | 9.87 | def slove():
import sys, collections
input = sys.stdin.readline
n = int(input().rstrip('\n'))
s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]
s = collections.Counter(s).most_common()
t = 0
for i, v in s:
for j in range(1, v):
t += j
print(t)
if __name__ == '__main__':
slove()
| def slove():
import sys
import collections
input = sys.stdin.readline
n = int(input().rstrip('\n'))
s = collections.Counter(["".join(sorted(str(input().rstrip('\n')))) for _ in range(n)])
t = 0
for k, v in list(s.items()):
for i in range(1, v):
t += i
print(t)
if __name__ == '__main__':
slove()
| 15 | 15 | 374 | 362 | def slove():
import sys, collections
input = sys.stdin.readline
n = int(input().rstrip("\n"))
s = ["".join(sorted(list(str(input().rstrip("\n"))))) for _ in range(n)]
s = collections.Counter(s).most_common()
t = 0
for i, v in s:
for j in range(1, v):
t += j
print(t)
if __name__ == "__main__":
slove()
| def slove():
import sys
import collections
input = sys.stdin.readline
n = int(input().rstrip("\n"))
s = collections.Counter(
["".join(sorted(str(input().rstrip("\n")))) for _ in range(n)]
)
t = 0
for k, v in list(s.items()):
for i in range(1, v):
t += i
print(t)
if __name__ == "__main__":
slove()
| false | 0 | [
"- import sys, collections",
"+ import sys",
"+ import collections",
"- s = [\"\".join(sorted(list(str(input().rstrip(\"\\n\"))))) for _ in range(n)]",
"- s = collections.Counter(s).most_common()",
"+ s = collections.Counter(",
"+ [\"\".join(sorted(str(input().rstrip(\"\\n\")))) for _ in range(n)]",
"+ )",
"- for i, v in s:",
"- for j in range(1, v):",
"- t += j",
"+ for k, v in list(s.items()):",
"+ for i in range(1, v):",
"+ t += i"
]
| false | 0.042298 | 0.121761 | 0.347388 | [
"s131733043",
"s963239827"
]
|
u440566786 | p02868 | python | s573230673 | s036687968 | 1,546 | 624 | 124,524 | 78,624 | Accepted | Accepted | 59.64 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
class SegmentTree(object):
def __init__(self,A,dot,e):
n=2**((len(A)-1).bit_length())
self.__n=n
self.__dot=dot
self.__e=e
self.__node=[e]*(2*n)
for i in range(len(A)):
self.__node[i+n]=A[i]
for i in range(n-1,-0,-1):
self.__node[i]=dot(self.__node[2*i],self.__node[2*i+1])
def add(self,i,c):
i+=self.__n
node=self.__node
node[i]=self.__dot(c,node[i])
while(i!=1):
i//=2
node[i]=self.__dot(node[2*i],node[2*i+1])
def sum(self,l,r):
vl,vr=self.__e,self.__e
l+=self.__n; r+=self.__n
while(l<r):
if(l%2==1):
vl=self.__dot(vl,self.__node[l])
l+=1
l//=2
if(r%2==1):
r-=1
vr=self.__dot(self.__node[r],vr)
r//=2
return self.__dot(vl,vr)
def resolve():
n,m=list(map(int,input().split()))
LRC=[0]*m
for i in range(m):
l,r,c=list(map(int,input().split()))
l-=1
LRC[i]=(l,r,c)
LRC.sort()
A=[INF]*n
A[0]=0
tree=SegmentTree(A,min,INF)
for l,r,c in LRC:
s=tree.sum(l,r)
tree.add(r-1,s+c)
ans=tree.sum(n-1,n)
if(ans==INF): ans=-1
print(ans)
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
n,m=list(map(int,input().split()))
E=[[] for _ in range(n)]
for i in range(1,n):
E[i].append((i-1,0))
for _ in range(m):
l,r,c=list(map(int,input().split()))
l-=1; r-=1
E[l].append((r,c))
# Dijkstra with heap
from heapq import heappop,heappush
Q=[(0,0)]
dist=[INF]*n
dist[0]=0
while(Q):
d,v=heappop(Q)
if(dist[v]<d): continue
for nv,w in E[v]:
if(dist[nv]>dist[v]+w):
dist[nv]=dist[v]+w
heappush(Q,(dist[nv],nv))
ans=dist[-1]
if(ans==INF): ans=-1
print(ans)
resolve() | 59 | 31 | 1,480 | 771 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
class SegmentTree(object):
def __init__(self, A, dot, e):
n = 2 ** ((len(A) - 1).bit_length())
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, -0, -1):
self.__node[i] = dot(self.__node[2 * i], self.__node[2 * i + 1])
def add(self, i, c):
i += self.__n
node = self.__node
node[i] = self.__dot(c, node[i])
while i != 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def sum(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while l < r:
if l % 2 == 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r % 2 == 1:
r -= 1
vr = self.__dot(self.__node[r], vr)
r //= 2
return self.__dot(vl, vr)
def resolve():
n, m = list(map(int, input().split()))
LRC = [0] * m
for i in range(m):
l, r, c = list(map(int, input().split()))
l -= 1
LRC[i] = (l, r, c)
LRC.sort()
A = [INF] * n
A[0] = 0
tree = SegmentTree(A, min, INF)
for l, r, c in LRC:
s = tree.sum(l, r)
tree.add(r - 1, s + c)
ans = tree.sum(n - 1, n)
if ans == INF:
ans = -1
print(ans)
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n, m = list(map(int, input().split()))
E = [[] for _ in range(n)]
for i in range(1, n):
E[i].append((i - 1, 0))
for _ in range(m):
l, r, c = list(map(int, input().split()))
l -= 1
r -= 1
E[l].append((r, c))
# Dijkstra with heap
from heapq import heappop, heappush
Q = [(0, 0)]
dist = [INF] * n
dist[0] = 0
while Q:
d, v = heappop(Q)
if dist[v] < d:
continue
for nv, w in E[v]:
if dist[nv] > dist[v] + w:
dist[nv] = dist[v] + w
heappush(Q, (dist[nv], nv))
ans = dist[-1]
if ans == INF:
ans = -1
print(ans)
resolve()
| false | 47.457627 | [
"-class SegmentTree(object):",
"- def __init__(self, A, dot, e):",
"- n = 2 ** ((len(A) - 1).bit_length())",
"- self.__n = n",
"- self.__dot = dot",
"- self.__e = e",
"- self.__node = [e] * (2 * n)",
"- for i in range(len(A)):",
"- self.__node[i + n] = A[i]",
"- for i in range(n - 1, -0, -1):",
"- self.__node[i] = dot(self.__node[2 * i], self.__node[2 * i + 1])",
"-",
"- def add(self, i, c):",
"- i += self.__n",
"- node = self.__node",
"- node[i] = self.__dot(c, node[i])",
"- while i != 1:",
"- i //= 2",
"- node[i] = self.__dot(node[2 * i], node[2 * i + 1])",
"-",
"- def sum(self, l, r):",
"- vl, vr = self.__e, self.__e",
"- l += self.__n",
"- r += self.__n",
"- while l < r:",
"- if l % 2 == 1:",
"- vl = self.__dot(vl, self.__node[l])",
"- l += 1",
"- l //= 2",
"- if r % 2 == 1:",
"- r -= 1",
"- vr = self.__dot(self.__node[r], vr)",
"- r //= 2",
"- return self.__dot(vl, vr)",
"-",
"-",
"- LRC = [0] * m",
"- for i in range(m):",
"+ E = [[] for _ in range(n)]",
"+ for i in range(1, n):",
"+ E[i].append((i - 1, 0))",
"+ for _ in range(m):",
"- LRC[i] = (l, r, c)",
"- LRC.sort()",
"- A = [INF] * n",
"- A[0] = 0",
"- tree = SegmentTree(A, min, INF)",
"- for l, r, c in LRC:",
"- s = tree.sum(l, r)",
"- tree.add(r - 1, s + c)",
"- ans = tree.sum(n - 1, n)",
"+ r -= 1",
"+ E[l].append((r, c))",
"+ # Dijkstra with heap",
"+ from heapq import heappop, heappush",
"+",
"+ Q = [(0, 0)]",
"+ dist = [INF] * n",
"+ dist[0] = 0",
"+ while Q:",
"+ d, v = heappop(Q)",
"+ if dist[v] < d:",
"+ continue",
"+ for nv, w in E[v]:",
"+ if dist[nv] > dist[v] + w:",
"+ dist[nv] = dist[v] + w",
"+ heappush(Q, (dist[nv], nv))",
"+ ans = dist[-1]"
]
| false | 0.04497 | 0.04376 | 1.027655 | [
"s573230673",
"s036687968"
]
|
u919633157 | p03640 | python | s401583909 | s591660222 | 32 | 28 | 4,212 | 4,084 | Accepted | Accepted | 12.5 | # 2019/09/09
from collections import deque
h,w=list(map(int,input().split()))
n=int(eval(input()))
a=list(map(int,input().split()))
res=[]
for i in range(n):
res+=[i+1]*a[i]
res=deque(res)
for i in range(h):
tmp=[]
for j in range(w):
tmp.append(res.popleft())
if i%2:print((*tmp[::-1]))
else:print((*tmp)) | # https://atcoder.jp/contests/arc080/tasks/arc080_b
h,w = list(map(int,input().split()))
n = int(eval(input()))
a = list(map(int,input().split()))
hw=[]
for i in range(n):
hw+=([str(i+1)]*a[i])
flag = False
for i in range(h):
bgn=i*w
end=bgn+w
res = hw[bgn:end]
if flag:
res=res[::-1]
flag = False
else:
flag = True
print((*res)) | 20 | 21 | 341 | 390 | # 2019/09/09
from collections import deque
h, w = list(map(int, input().split()))
n = int(eval(input()))
a = list(map(int, input().split()))
res = []
for i in range(n):
res += [i + 1] * a[i]
res = deque(res)
for i in range(h):
tmp = []
for j in range(w):
tmp.append(res.popleft())
if i % 2:
print((*tmp[::-1]))
else:
print((*tmp))
| # https://atcoder.jp/contests/arc080/tasks/arc080_b
h, w = list(map(int, input().split()))
n = int(eval(input()))
a = list(map(int, input().split()))
hw = []
for i in range(n):
hw += [str(i + 1)] * a[i]
flag = False
for i in range(h):
bgn = i * w
end = bgn + w
res = hw[bgn:end]
if flag:
res = res[::-1]
flag = False
else:
flag = True
print((*res))
| false | 4.761905 | [
"-# 2019/09/09",
"-from collections import deque",
"-",
"+# https://atcoder.jp/contests/arc080/tasks/arc080_b",
"-res = []",
"+hw = []",
"- res += [i + 1] * a[i]",
"-res = deque(res)",
"+ hw += [str(i + 1)] * a[i]",
"+flag = False",
"- tmp = []",
"- for j in range(w):",
"- tmp.append(res.popleft())",
"- if i % 2:",
"- print((*tmp[::-1]))",
"+ bgn = i * w",
"+ end = bgn + w",
"+ res = hw[bgn:end]",
"+ if flag:",
"+ res = res[::-1]",
"+ flag = False",
"- print((*tmp))",
"+ flag = True",
"+ print((*res))"
]
| false | 0.101276 | 0.042933 | 2.358957 | [
"s401583909",
"s591660222"
]
|
u361826811 | p02831 | python | s275353552 | s121231106 | 147 | 17 | 12,416 | 3,060 | Accepted | Accepted | 88.44 | """
author : halo2halo
date : 4, Feb, 2020
"""
import sys
import itertools
# import math
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
A, B = list(map(int, readline().split()))
print((A*B//gcd(A,B))) | """
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import itertools
# import math
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
A, B = list(map(int, readline().split()))
print((A*B//gcd(A,B))) | 25 | 23 | 373 | 373 | """
author : halo2halo
date : 4, Feb, 2020
"""
import sys
import itertools
# import math
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
A, B = list(map(int, readline().split()))
print((A * B // gcd(A, B)))
| """
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import itertools
# import math
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
A, B = list(map(int, readline().split()))
print((A * B // gcd(A, B)))
| false | 8 | [
"-import itertools",
"+# import itertools",
"-import numpy as np",
"-",
"+# import numpy as np"
]
| false | 0.037513 | 0.042758 | 0.877321 | [
"s275353552",
"s121231106"
]
|
u634079249 | p02946 | python | s357620688 | s544725563 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, X = list(map(int, sys.stdin.readline().split()))
MAX = 1000000
MIN = -1000000
ret = [X]
for i in range(1, K):
if X + i <= MAX:
ret.append(X+i)
else:
ret.append(X - K)
if X - i >= MIN:
ret.append(X-i)
else:
ret.append(X + K)
print((*sorted(set(ret))))
if __name__ == '__main__':
main()
| import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, X = list(map(int, sys.stdin.readline().split()))
ret = []
for i in range(X-K+1, X+K):
ret.append(i)
print((*ret))
if __name__ == '__main__':
main()
| 28 | 18 | 531 | 303 | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, X = list(map(int, sys.stdin.readline().split()))
MAX = 1000000
MIN = -1000000
ret = [X]
for i in range(1, K):
if X + i <= MAX:
ret.append(X + i)
else:
ret.append(X - K)
if X - i >= MIN:
ret.append(X - i)
else:
ret.append(X + K)
print((*sorted(set(ret))))
if __name__ == "__main__":
main()
| import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, X = list(map(int, sys.stdin.readline().split()))
ret = []
for i in range(X - K + 1, X + K):
ret.append(i)
print((*ret))
if __name__ == "__main__":
main()
| false | 35.714286 | [
"- MAX = 1000000",
"- MIN = -1000000",
"- ret = [X]",
"- for i in range(1, K):",
"- if X + i <= MAX:",
"- ret.append(X + i)",
"- else:",
"- ret.append(X - K)",
"- if X - i >= MIN:",
"- ret.append(X - i)",
"- else:",
"- ret.append(X + K)",
"- print((*sorted(set(ret))))",
"+ ret = []",
"+ for i in range(X - K + 1, X + K):",
"+ ret.append(i)",
"+ print((*ret))"
]
| false | 0.123149 | 0.047124 | 2.613275 | [
"s357620688",
"s544725563"
]
|
u822353071 | p03862 | python | s728831851 | s323977437 | 190 | 114 | 14,152 | 14,548 | Accepted | Accepted | 40 | #003
N,x=input().split(" ")
s = input().split(" ")
list = []
for i in range(int(N)):
list.append(int(s[i]))
count = 0
if(list[0]>int(x)):
count+=list[0]-int(x)
list[0]-=list[0]-int(x)
for i in range(1,int(N)):
temp = list[i]+list[i-1]
if(temp>int(x)):
count+=temp-int(x)
list[i]-=temp-int(x)
print(count) | #003
N,x= [int(i) for i in input().split(" ")]
list = [int(i) for i in input().split(" ")]
count = 0
for i in range(N):
if(i==0):
if list[i]>x:
temp = list[i]-x
count+=temp
list[i]-=temp
else:
temp = list[i]+list[i-1]-x
if(temp>0):
count+=temp
list[i]-=temp
print(count) | 18 | 16 | 368 | 382 | # 003
N, x = input().split(" ")
s = input().split(" ")
list = []
for i in range(int(N)):
list.append(int(s[i]))
count = 0
if list[0] > int(x):
count += list[0] - int(x)
list[0] -= list[0] - int(x)
for i in range(1, int(N)):
temp = list[i] + list[i - 1]
if temp > int(x):
count += temp - int(x)
list[i] -= temp - int(x)
print(count)
| # 003
N, x = [int(i) for i in input().split(" ")]
list = [int(i) for i in input().split(" ")]
count = 0
for i in range(N):
if i == 0:
if list[i] > x:
temp = list[i] - x
count += temp
list[i] -= temp
else:
temp = list[i] + list[i - 1] - x
if temp > 0:
count += temp
list[i] -= temp
print(count)
| false | 11.111111 | [
"-N, x = input().split(\" \")",
"-s = input().split(\" \")",
"-list = []",
"-for i in range(int(N)):",
"- list.append(int(s[i]))",
"+N, x = [int(i) for i in input().split(\" \")]",
"+list = [int(i) for i in input().split(\" \")]",
"-if list[0] > int(x):",
"- count += list[0] - int(x)",
"- list[0] -= list[0] - int(x)",
"-for i in range(1, int(N)):",
"- temp = list[i] + list[i - 1]",
"- if temp > int(x):",
"- count += temp - int(x)",
"- list[i] -= temp - int(x)",
"+for i in range(N):",
"+ if i == 0:",
"+ if list[i] > x:",
"+ temp = list[i] - x",
"+ count += temp",
"+ list[i] -= temp",
"+ else:",
"+ temp = list[i] + list[i - 1] - x",
"+ if temp > 0:",
"+ count += temp",
"+ list[i] -= temp"
]
| false | 0.039701 | 0.042854 | 0.926426 | [
"s728831851",
"s323977437"
]
|
u241159583 | p02768 | python | s757249286 | s890269187 | 150 | 132 | 3,064 | 9,156 | Accepted | Accepted | 12 | n,a,b = list(map(int, input().split()))
MOD = 10**9+7
def cmb(n,r):
a,b = 1,1
for i in range(r):
a = a * (n-i) % MOD
b = b * (i+1) % MOD
return a * pow(b, MOD-2, MOD)%MOD
print(((pow(2,n,MOD) - cmb(n,a) - cmb(n,b) - 1)%MOD)) | n,a,b = list(map(int, input().split()))
mod = 10**9+7
def cmb(n,r):
a,b = 1,1
for i in range(r):
a = a * (n-i) % mod
b = b * (i+1) % mod
return a * pow(b, mod-2, mod) %mod
print(((pow(2, n, mod) - cmb(n,a) - cmb(n,b) - 1)%mod)) | 11 | 11 | 256 | 259 | n, a, b = list(map(int, input().split()))
MOD = 10**9 + 7
def cmb(n, r):
a, b = 1, 1
for i in range(r):
a = a * (n - i) % MOD
b = b * (i + 1) % MOD
return a * pow(b, MOD - 2, MOD) % MOD
print(((pow(2, n, MOD) - cmb(n, a) - cmb(n, b) - 1) % MOD))
| n, a, b = list(map(int, input().split()))
mod = 10**9 + 7
def cmb(n, r):
a, b = 1, 1
for i in range(r):
a = a * (n - i) % mod
b = b * (i + 1) % mod
return a * pow(b, mod - 2, mod) % mod
print(((pow(2, n, mod) - cmb(n, a) - cmb(n, b) - 1) % mod))
| false | 0 | [
"-MOD = 10**9 + 7",
"+mod = 10**9 + 7",
"- a = a * (n - i) % MOD",
"- b = b * (i + 1) % MOD",
"- return a * pow(b, MOD - 2, MOD) % MOD",
"+ a = a * (n - i) % mod",
"+ b = b * (i + 1) % mod",
"+ return a * pow(b, mod - 2, mod) % mod",
"-print(((pow(2, n, MOD) - cmb(n, a) - cmb(n, b) - 1) % MOD))",
"+print(((pow(2, n, mod) - cmb(n, a) - cmb(n, b) - 1) % mod))"
]
| false | 0.239285 | 0.102972 | 2.323797 | [
"s757249286",
"s890269187"
]
|
u797673668 | p02272 | python | s130410545 | s900825011 | 4,360 | 3,910 | 63,848 | 64,024 | Accepted | Accepted | 10.32 | def merge(a, l, m, r):
global cnt
ll = a[l:m] + [1e9 + 1]
rl = a[m:r] + [1e9 + 1]
i, j = 0, 0
for k in range(l, r):
if ll[i] < rl[j]:
a[k] = ll[i]
i += 1
else:
a[k] = rl[j]
j += 1
cnt += 1
def merge_sort(a, l, r):
if l + 1 < r:
m = (l + r) // 2
merge_sort(a, l, m)
merge_sort(a, m, r)
merge(a, l, m, r)
n, a, cnt = int(eval(input())), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print((*a))
print(cnt) | from collections import deque
INFTY = 1e9 + 1
def merge(a, l, m, r):
global cnt
ll = deque(a[l:m])
rl = deque(a[m:r])
ll.append(INFTY)
rl.append(INFTY)
for k in range(l, r):
a[k] = (ll if ll[0] < rl[0] else rl).popleft()
cnt += r - l
def merge_sort(a, l, r):
if l + 1 < r:
m = (l + r) // 2
merge_sort(a, l, m)
merge_sort(a, m, r)
merge(a, l, m, r)
n, a, cnt = int(eval(input())), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print((*a))
print(cnt) | 27 | 28 | 562 | 555 | def merge(a, l, m, r):
global cnt
ll = a[l:m] + [1e9 + 1]
rl = a[m:r] + [1e9 + 1]
i, j = 0, 0
for k in range(l, r):
if ll[i] < rl[j]:
a[k] = ll[i]
i += 1
else:
a[k] = rl[j]
j += 1
cnt += 1
def merge_sort(a, l, r):
if l + 1 < r:
m = (l + r) // 2
merge_sort(a, l, m)
merge_sort(a, m, r)
merge(a, l, m, r)
n, a, cnt = int(eval(input())), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print((*a))
print(cnt)
| from collections import deque
INFTY = 1e9 + 1
def merge(a, l, m, r):
global cnt
ll = deque(a[l:m])
rl = deque(a[m:r])
ll.append(INFTY)
rl.append(INFTY)
for k in range(l, r):
a[k] = (ll if ll[0] < rl[0] else rl).popleft()
cnt += r - l
def merge_sort(a, l, r):
if l + 1 < r:
m = (l + r) // 2
merge_sort(a, l, m)
merge_sort(a, m, r)
merge(a, l, m, r)
n, a, cnt = int(eval(input())), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print((*a))
print(cnt)
| false | 3.571429 | [
"+from collections import deque",
"+",
"+INFTY = 1e9 + 1",
"+",
"+",
"- ll = a[l:m] + [1e9 + 1]",
"- rl = a[m:r] + [1e9 + 1]",
"- i, j = 0, 0",
"+ ll = deque(a[l:m])",
"+ rl = deque(a[m:r])",
"+ ll.append(INFTY)",
"+ rl.append(INFTY)",
"- if ll[i] < rl[j]:",
"- a[k] = ll[i]",
"- i += 1",
"- else:",
"- a[k] = rl[j]",
"- j += 1",
"- cnt += 1",
"+ a[k] = (ll if ll[0] < rl[0] else rl).popleft()",
"+ cnt += r - l"
]
| false | 0.04929 | 0.048459 | 1.017157 | [
"s130410545",
"s900825011"
]
|
u923668099 | p02396 | python | s957311474 | s067861760 | 140 | 70 | 7,488 | 7,764 | Accepted | Accepted | 50 | # coding: utf-8
# Here your code !
import sys
i = 1
while True:
n = int(eval(input()))
if n == 0:
break
print(("Case " + str(i) + ": " + str(n)))
i += 1 | from sys import stdin
for test_case in range(10**4 + 2):
x = int(stdin.readline())
if not x:
break
print(('Case {}: {}'.format(test_case + 1, x))) | 14 | 9 | 193 | 175 | # coding: utf-8
# Here your code !
import sys
i = 1
while True:
n = int(eval(input()))
if n == 0:
break
print(("Case " + str(i) + ": " + str(n)))
i += 1
| from sys import stdin
for test_case in range(10**4 + 2):
x = int(stdin.readline())
if not x:
break
print(("Case {}: {}".format(test_case + 1, x)))
| false | 35.714286 | [
"-# coding: utf-8",
"-# Here your code !",
"-import sys",
"+from sys import stdin",
"-i = 1",
"-while True:",
"- n = int(eval(input()))",
"- if n == 0:",
"+for test_case in range(10**4 + 2):",
"+ x = int(stdin.readline())",
"+ if not x:",
"- print((\"Case \" + str(i) + \": \" + str(n)))",
"- i += 1",
"+ print((\"Case {}: {}\".format(test_case + 1, x)))"
]
| false | 0.034662 | 0.034937 | 0.992126 | [
"s957311474",
"s067861760"
]
|
u933341648 | p03838 | python | s056008428 | s779898308 | 31 | 26 | 9,172 | 9,068 | Accepted | Accepted | 16.13 | x, y = list(map(int, input().split()))
d = abs(abs(y) - abs(x))
if (x > 0 and y <= 0) or (x >= 0 and y < 0) or (x < 0 and y > 0):
d += 1
elif x > y:
d += 2
print(d)
| x, y = list(map(int, input().split()))
d = abs(abs(y) - abs(x))
if (x > 0 and y < 0) or (x < 0 and y > 0):
d += 1
elif x > y:
if x == 0 or y == 0:
d += 1
else:
d += 2
print(d)
| 10 | 13 | 179 | 213 | x, y = list(map(int, input().split()))
d = abs(abs(y) - abs(x))
if (x > 0 and y <= 0) or (x >= 0 and y < 0) or (x < 0 and y > 0):
d += 1
elif x > y:
d += 2
print(d)
| x, y = list(map(int, input().split()))
d = abs(abs(y) - abs(x))
if (x > 0 and y < 0) or (x < 0 and y > 0):
d += 1
elif x > y:
if x == 0 or y == 0:
d += 1
else:
d += 2
print(d)
| false | 23.076923 | [
"-if (x > 0 and y <= 0) or (x >= 0 and y < 0) or (x < 0 and y > 0):",
"+if (x > 0 and y < 0) or (x < 0 and y > 0):",
"- d += 2",
"+ if x == 0 or y == 0:",
"+ d += 1",
"+ else:",
"+ d += 2"
]
| false | 0.034746 | 0.03651 | 0.951691 | [
"s056008428",
"s779898308"
]
|
u785220618 | p03557 | python | s153476907 | s305245047 | 984 | 311 | 23,328 | 23,244 | Accepted | Accepted | 68.39 | # -*- coding: utf-8 -*-
def higher_search(list, key):
l = -1
r = len(list)
while r - l > 1:
mid = l + (r - l) // 2
if list[mid] > key:
r = mid
else:
l = mid
if r == len(list):
return -1
else:
return r
def lower_search(list, key):
l = -1
r = len(list)
while r - l > 1:
mid = r - (r - l) // 2
if list[mid] < key:
l = mid
else:
r = mid
if l == -1:
return -1
else:
return l
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 b in B:
a_index = lower_search(A, b)
c_index = higher_search(C, b)
if c_index == -1:
c_index = n
ans += (a_index + 1) * (n - c_index)
print(ans)
| # -*- coding: utf-8 -*-
import bisect
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans)
| 54 | 13 | 936 | 303 | # -*- coding: utf-8 -*-
def higher_search(list, key):
l = -1
r = len(list)
while r - l > 1:
mid = l + (r - l) // 2
if list[mid] > key:
r = mid
else:
l = mid
if r == len(list):
return -1
else:
return r
def lower_search(list, key):
l = -1
r = len(list)
while r - l > 1:
mid = r - (r - l) // 2
if list[mid] < key:
l = mid
else:
r = mid
if l == -1:
return -1
else:
return l
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 b in B:
a_index = lower_search(A, b)
c_index = higher_search(C, b)
if c_index == -1:
c_index = n
ans += (a_index + 1) * (n - c_index)
print(ans)
| # -*- coding: utf-8 -*-
import bisect
n = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans)
| false | 75.925926 | [
"-def higher_search(list, key):",
"- l = -1",
"- r = len(list)",
"- while r - l > 1:",
"- mid = l + (r - l) // 2",
"- if list[mid] > key:",
"- r = mid",
"- else:",
"- l = mid",
"- if r == len(list):",
"- return -1",
"- else:",
"- return r",
"-",
"-",
"-def lower_search(list, key):",
"- l = -1",
"- r = len(list)",
"- while r - l > 1:",
"- mid = r - (r - l) // 2",
"- if list[mid] < key:",
"- l = mid",
"- else:",
"- r = mid",
"- if l == -1:",
"- return -1",
"- else:",
"- return l",
"-",
"+import bisect",
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"-A.sort()",
"-B.sort()",
"-C.sort()",
"+A = sorted(list(map(int, input().split())))",
"+B = sorted(list(map(int, input().split())))",
"+C = sorted(list(map(int, input().split())))",
"- a_index = lower_search(A, b)",
"- c_index = higher_search(C, b)",
"- if c_index == -1:",
"- c_index = n",
"- ans += (a_index + 1) * (n - c_index)",
"+ ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))"
]
| false | 0.041468 | 0.079514 | 0.521511 | [
"s153476907",
"s305245047"
]
|
u503228842 | p04013 | python | s814247739 | s124135769 | 426 | 296 | 92,636 | 92,124 | Accepted | Accepted | 30.52 | n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
X = max(max(x), a)
#dp = [[[0]*(n*X+1) for _ in range(X+1)] for i in range(n+1)]
dp = [[[0]*(n*X+1) for _ in range(n+1)] for i in range(n+1)]
for j in range(n+1):
for k in range(n+1):
for s in range(n*X+1):
if j == 0 and k == 0 and s == 0:
dp[j][k][s] = 1
elif j >= 1 and s < x[j-1]:
dp[j][k][s] = dp[j-1][k][s]
elif j >= 1 and k >= 1 and s >= x[j-1]:
dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
else:
dp[j][k][s] = 0
ans = 0
for k in range(1,n+1):
ans += dp[n][k][k*a]
print(ans) | # ้
ๅใๅคงใใใซใจใฃใฆ้
ใฃใๆนใใใฃใใใใใใฎใใ
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
X = max(max(x), a)
dp = [[[0]*(n*X+1) for _ in range(n+1)] for i in range(n+1)]
#if j == 0 and k == 0 and s == 0:
dp[0][0][0] = 1
for j in range(n):
for k in range(n):
for s in range(n*X):
if dp[j][k][s]:
dp[j+1][k][s] += dp[j][k][s]
dp[j+1][k+1][s+x[j]] += dp[j][k][s]
ans = 0
for k in range(1,n+1):
ans += dp[n][k][k*a]
print(ans) | 21 | 21 | 707 | 513 | n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
X = max(max(x), a)
# dp = [[[0]*(n*X+1) for _ in range(X+1)] for i in range(n+1)]
dp = [[[0] * (n * X + 1) for _ in range(n + 1)] for i in range(n + 1)]
for j in range(n + 1):
for k in range(n + 1):
for s in range(n * X + 1):
if j == 0 and k == 0 and s == 0:
dp[j][k][s] = 1
elif j >= 1 and s < x[j - 1]:
dp[j][k][s] = dp[j - 1][k][s]
elif j >= 1 and k >= 1 and s >= x[j - 1]:
dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]
else:
dp[j][k][s] = 0
ans = 0
for k in range(1, n + 1):
ans += dp[n][k][k * a]
print(ans)
| # ้
ๅใๅคงใใใซใจใฃใฆ้
ใฃใๆนใใใฃใใใใใใฎใใ
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
X = max(max(x), a)
dp = [[[0] * (n * X + 1) for _ in range(n + 1)] for i in range(n + 1)]
# if j == 0 and k == 0 and s == 0:
dp[0][0][0] = 1
for j in range(n):
for k in range(n):
for s in range(n * X):
if dp[j][k][s]:
dp[j + 1][k][s] += dp[j][k][s]
dp[j + 1][k + 1][s + x[j]] += dp[j][k][s]
ans = 0
for k in range(1, n + 1):
ans += dp[n][k][k * a]
print(ans)
| false | 0 | [
"+# ้
ๅใๅคงใใใซใจใฃใฆ้
ใฃใๆนใใใฃใใใใใใฎใใ",
"-# dp = [[[0]*(n*X+1) for _ in range(X+1)] for i in range(n+1)]",
"-for j in range(n + 1):",
"- for k in range(n + 1):",
"- for s in range(n * X + 1):",
"- if j == 0 and k == 0 and s == 0:",
"- dp[j][k][s] = 1",
"- elif j >= 1 and s < x[j - 1]:",
"- dp[j][k][s] = dp[j - 1][k][s]",
"- elif j >= 1 and k >= 1 and s >= x[j - 1]:",
"- dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]",
"- else:",
"- dp[j][k][s] = 0",
"+# if j == 0 and k == 0 and s == 0:",
"+dp[0][0][0] = 1",
"+for j in range(n):",
"+ for k in range(n):",
"+ for s in range(n * X):",
"+ if dp[j][k][s]:",
"+ dp[j + 1][k][s] += dp[j][k][s]",
"+ dp[j + 1][k + 1][s + x[j]] += dp[j][k][s]"
]
| false | 0.04078 | 0.045356 | 0.899112 | [
"s814247739",
"s124135769"
]
|
u445032255 | p02267 | python | s854365423 | s661252309 | 30 | 20 | 6,336 | 6,340 | Accepted | Accepted | 33.33 | def main():
N = int(eval(input()))
S = [int(_) for _ in input().split()]
Q = int(eval(input()))
T = [int(_) for _ in input().split()]
ans = 0
for t in T:
for s in S:
if s == t:
ans += 1
break
print(ans)
main()
| import sys
# Set max recursion limit
sys.setrecursionlimit(1000000)
def li_input():
return [int(_) for _ in input().split()]
def main():
n = int(eval(input()))
S = li_input()
q = int(eval(input()))
T = li_input()
ans = 0
for t in T:
if t in S:
ans += 1
print(ans)
main()
| 18 | 27 | 300 | 348 | def main():
N = int(eval(input()))
S = [int(_) for _ in input().split()]
Q = int(eval(input()))
T = [int(_) for _ in input().split()]
ans = 0
for t in T:
for s in S:
if s == t:
ans += 1
break
print(ans)
main()
| import sys
# Set max recursion limit
sys.setrecursionlimit(1000000)
def li_input():
return [int(_) for _ in input().split()]
def main():
n = int(eval(input()))
S = li_input()
q = int(eval(input()))
T = li_input()
ans = 0
for t in T:
if t in S:
ans += 1
print(ans)
main()
| false | 33.333333 | [
"+import sys",
"+",
"+# Set max recursion limit",
"+sys.setrecursionlimit(1000000)",
"+",
"+",
"+def li_input():",
"+ return [int(_) for _ in input().split()]",
"+",
"+",
"- N = int(eval(input()))",
"- S = [int(_) for _ in input().split()]",
"- Q = int(eval(input()))",
"- T = [int(_) for _ in input().split()]",
"+ n = int(eval(input()))",
"+ S = li_input()",
"+ q = int(eval(input()))",
"+ T = li_input()",
"- for s in S:",
"- if s == t:",
"- ans += 1",
"- break",
"+ if t in S:",
"+ ans += 1"
]
| false | 0.040276 | 0.083093 | 0.484702 | [
"s854365423",
"s661252309"
]
|
u540761833 | p03408 | python | s837219109 | s700439954 | 21 | 18 | 3,316 | 3,060 | Accepted | Accepted | 14.29 | import collections
N = int(eval(input()))
blue = []
red = []
for i in range(N):
s = eval(input())
blue.append(s)
bc = sorted(list(collections.Counter(blue).items()), key = lambda x:x[1],reverse = True)
M = int(eval(input()))
for i in range(M):
t = eval(input())
red.append(t)
rc = collections.Counter(red)
count = []
for i in range(len(bc)):
count.append(bc[i][1])
if bc[i][0] in rc:
count[i] -= rc[bc[i][0]]
print((max(0,max(count))))
| N= int(eval(input()))
s = [eval(input()) for i in range(N)]
M = int(eval(input()))
t = [eval(input()) for i in range(M)]
ans = 0
for i in s:
ans = max(ans,s.count(i)-t.count(i))
print(ans) | 23 | 8 | 469 | 176 | import collections
N = int(eval(input()))
blue = []
red = []
for i in range(N):
s = eval(input())
blue.append(s)
bc = sorted(list(collections.Counter(blue).items()), key=lambda x: x[1], reverse=True)
M = int(eval(input()))
for i in range(M):
t = eval(input())
red.append(t)
rc = collections.Counter(red)
count = []
for i in range(len(bc)):
count.append(bc[i][1])
if bc[i][0] in rc:
count[i] -= rc[bc[i][0]]
print((max(0, max(count))))
| N = int(eval(input()))
s = [eval(input()) for i in range(N)]
M = int(eval(input()))
t = [eval(input()) for i in range(M)]
ans = 0
for i in s:
ans = max(ans, s.count(i) - t.count(i))
print(ans)
| false | 65.217391 | [
"-import collections",
"-",
"-blue = []",
"-red = []",
"-for i in range(N):",
"- s = eval(input())",
"- blue.append(s)",
"-bc = sorted(list(collections.Counter(blue).items()), key=lambda x: x[1], reverse=True)",
"+s = [eval(input()) for i in range(N)]",
"-for i in range(M):",
"- t = eval(input())",
"- red.append(t)",
"-rc = collections.Counter(red)",
"-count = []",
"-for i in range(len(bc)):",
"- count.append(bc[i][1])",
"- if bc[i][0] in rc:",
"- count[i] -= rc[bc[i][0]]",
"-print((max(0, max(count))))",
"+t = [eval(input()) for i in range(M)]",
"+ans = 0",
"+for i in s:",
"+ ans = max(ans, s.count(i) - t.count(i))",
"+print(ans)"
]
| false | 0.058822 | 0.041626 | 1.41312 | [
"s837219109",
"s700439954"
]
|
u222668979 | p02844 | python | s219440036 | s879039476 | 959 | 304 | 3,188 | 41,324 | Accepted | Accepted | 68.3 | n, s = int(eval(input())), str(eval(input()))
num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
if s[i] in num1:
continue
num1.add(s[i])
for j in range(i + 1, n):
tmp2 = s[i] + s[j]
if tmp2 in num2:
continue
num2.add(tmp2)
for k in range(j + 1, n):
tmp3 = tmp2 + s[k]
if tmp3 in num3:
continue
num3.add(tmp3)
print((len(num3))) | n, s = int(eval(input())), str(eval(input()))
num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
if s[i] in num1:
continue
num1.add(s[i])
for j in range(i + 1, n):
tmp2 = s[i] + s[j]
if tmp2 in num2:
continue
num2.add(tmp2)
for k in range(j + 1, n):
num3.add(tmp2 + s[k])
print((len(num3)))
| 18 | 15 | 461 | 381 | n, s = int(eval(input())), str(eval(input()))
num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
if s[i] in num1:
continue
num1.add(s[i])
for j in range(i + 1, n):
tmp2 = s[i] + s[j]
if tmp2 in num2:
continue
num2.add(tmp2)
for k in range(j + 1, n):
tmp3 = tmp2 + s[k]
if tmp3 in num3:
continue
num3.add(tmp3)
print((len(num3)))
| n, s = int(eval(input())), str(eval(input()))
num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
if s[i] in num1:
continue
num1.add(s[i])
for j in range(i + 1, n):
tmp2 = s[i] + s[j]
if tmp2 in num2:
continue
num2.add(tmp2)
for k in range(j + 1, n):
num3.add(tmp2 + s[k])
print((len(num3)))
| false | 16.666667 | [
"- tmp3 = tmp2 + s[k]",
"- if tmp3 in num3:",
"- continue",
"- num3.add(tmp3)",
"+ num3.add(tmp2 + s[k])"
]
| false | 0.035736 | 0.045931 | 0.778036 | [
"s219440036",
"s879039476"
]
|
u670180528 | p03240 | python | s751803086 | s568233245 | 35 | 32 | 3,064 | 3,064 | Accepted | Accepted | 8.57 | n = int(eval(input()));_h=0
li = []
for _ in range(n):
x,y,h = list(map(int,input().split()))
li.append((x,y,h))
if not _h:
_x,_y,_h = x,y,h
for i in range(101):
for j in range(101):
H = _h + abs(i-_x) + abs(j-_y)
if all(h==max(0,H-abs(i-x)-abs(j-y)) for (x,y,h) in li):
print((i,j,H))
exit()
else:
pass | l=[];A=abs;r=list(range(101))
for _ in range(int(eval(input()))):
*t,=list(map(int,input().split()))
l+=[t]
if t[2]:a,b,c=t
for i in r:
for j in r:
H=c+A(i-a)+A(j-b)
if all(h==max(0,H-A(i-x)-A(j-y))for x,y,h in l):
print((i,j,H)) | 15 | 10 | 324 | 229 | n = int(eval(input()))
_h = 0
li = []
for _ in range(n):
x, y, h = list(map(int, input().split()))
li.append((x, y, h))
if not _h:
_x, _y, _h = x, y, h
for i in range(101):
for j in range(101):
H = _h + abs(i - _x) + abs(j - _y)
if all(h == max(0, H - abs(i - x) - abs(j - y)) for (x, y, h) in li):
print((i, j, H))
exit()
else:
pass
| l = []
A = abs
r = list(range(101))
for _ in range(int(eval(input()))):
(*t,) = list(map(int, input().split()))
l += [t]
if t[2]:
a, b, c = t
for i in r:
for j in r:
H = c + A(i - a) + A(j - b)
if all(h == max(0, H - A(i - x) - A(j - y)) for x, y, h in l):
print((i, j, H))
| false | 33.333333 | [
"-n = int(eval(input()))",
"-_h = 0",
"-li = []",
"-for _ in range(n):",
"- x, y, h = list(map(int, input().split()))",
"- li.append((x, y, h))",
"- if not _h:",
"- _x, _y, _h = x, y, h",
"-for i in range(101):",
"- for j in range(101):",
"- H = _h + abs(i - _x) + abs(j - _y)",
"- if all(h == max(0, H - abs(i - x) - abs(j - y)) for (x, y, h) in li):",
"+l = []",
"+A = abs",
"+r = list(range(101))",
"+for _ in range(int(eval(input()))):",
"+ (*t,) = list(map(int, input().split()))",
"+ l += [t]",
"+ if t[2]:",
"+ a, b, c = t",
"+for i in r:",
"+ for j in r:",
"+ H = c + A(i - a) + A(j - b)",
"+ if all(h == max(0, H - A(i - x) - A(j - y)) for x, y, h in l):",
"- exit()",
"- else:",
"- pass"
]
| false | 0.051803 | 0.071305 | 0.726493 | [
"s751803086",
"s568233245"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.