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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u363610900
|
p03610
|
python
|
s674771984
|
s418936264
| 29 | 21 | 4,268 | 4,268 |
Accepted
|
Accepted
| 27.59 |
s = list(eval(input()))
ans = ''
for j in s[0:len(s):2]:
ans += j
print(ans)
|
s = list(eval(input()))
print((''.join(s[::2])))
| 5 | 2 | 78 | 41 |
s = list(eval(input()))
ans = ""
for j in s[0 : len(s) : 2]:
ans += j
print(ans)
|
s = list(eval(input()))
print(("".join(s[::2])))
| false | 60 |
[
"-ans = \"\"",
"-for j in s[0 : len(s) : 2]:",
"- ans += j",
"-print(ans)",
"+print((\"\".join(s[::2])))"
] | false | 0.039113 | 0.039199 | 0.997818 |
[
"s674771984",
"s418936264"
] |
u608088992
|
p03213
|
python
|
s800907596
|
s272203257
| 29 | 21 | 3,188 | 3,316 |
Accepted
|
Accepted
| 27.59 |
N = int(eval(input()))
lim = 1
for i in range(N): lim *= (i+1)
Prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,\
53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
Ans = 0
for i in range(23):
for j in range(i+1, 24):
for k in range(j+1, 25):
a, b, c = Prime[i], Prime[j], Prime[k]
d, e, f = (a**4)*(b**4)*(c**2), (a**4)*(b**2)*(c**4), (a**2)*(b**4)*(c**4)
if d <= lim and lim%d == 0: Ans += 1
if e <= lim and lim%e == 0: Ans += 1
if f <= lim and lim%f == 0: Ans += 1
for i in range(24):
for j in range(i+1, 25):
a, b = Prime[i], Prime[j]
d, e, f, g = (a**24)*(b**2), (a**2)*(b**24), (a**4)*(b**14), (a**14)*(b**4)
if d <= lim and lim%d == 0: Ans += 1
if e <= lim and lim%e == 0: Ans += 1
if f <= lim and lim%f == 0: Ans += 1
if g <= lim and lim%g == 0: Ans += 1
for i in range(5):
if Prime[i] ** 74 <= lim and lim % (Prime[i]**74) == 0: Ans += 1
print(Ans)
|
import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N = int(eval(input()))
primes = defaultdict(int)
ans = 0
for i in range(1, N + 1):
k = i
for j in range(2, i+1):
if j ** 2 > i: break
if k % j == 0:
while k % j == 0:
primes[j] += 1
k //= j
if k > 1: primes[k] += 1
P = []
for key in primes: P.append(primes[key])
pn = len(P)
for i in range(pn):
if P[i] >= 74: ans += 1
if P[i] >= 24:
for j in range(pn):
if P[j] >= 2 and j != i: ans += 1
if P[i] >= 14:
for j in range(pn):
if P[j] >= 4 and j != i: ans += 1
if P[i] >= 4:
for j in range(i+1, pn):
if P[j] >= 4:
for k in range(pn):
if P[k] >= 2 and k != i and k != j: ans += 1
print(ans)
#print(primes)
#print(P)
return 0
if __name__ == "__main__":
solve()
| 26 | 42 | 1,013 | 1,100 |
N = int(eval(input()))
lim = 1
for i in range(N):
lim *= i + 1
Prime = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
]
Ans = 0
for i in range(23):
for j in range(i + 1, 24):
for k in range(j + 1, 25):
a, b, c = Prime[i], Prime[j], Prime[k]
d, e, f = (
(a**4) * (b**4) * (c**2),
(a**4) * (b**2) * (c**4),
(a**2) * (b**4) * (c**4),
)
if d <= lim and lim % d == 0:
Ans += 1
if e <= lim and lim % e == 0:
Ans += 1
if f <= lim and lim % f == 0:
Ans += 1
for i in range(24):
for j in range(i + 1, 25):
a, b = Prime[i], Prime[j]
d, e, f, g = (
(a**24) * (b**2),
(a**2) * (b**24),
(a**4) * (b**14),
(a**14) * (b**4),
)
if d <= lim and lim % d == 0:
Ans += 1
if e <= lim and lim % e == 0:
Ans += 1
if f <= lim and lim % f == 0:
Ans += 1
if g <= lim and lim % g == 0:
Ans += 1
for i in range(5):
if Prime[i] ** 74 <= lim and lim % (Prime[i] ** 74) == 0:
Ans += 1
print(Ans)
|
import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N = int(eval(input()))
primes = defaultdict(int)
ans = 0
for i in range(1, N + 1):
k = i
for j in range(2, i + 1):
if j**2 > i:
break
if k % j == 0:
while k % j == 0:
primes[j] += 1
k //= j
if k > 1:
primes[k] += 1
P = []
for key in primes:
P.append(primes[key])
pn = len(P)
for i in range(pn):
if P[i] >= 74:
ans += 1
if P[i] >= 24:
for j in range(pn):
if P[j] >= 2 and j != i:
ans += 1
if P[i] >= 14:
for j in range(pn):
if P[j] >= 4 and j != i:
ans += 1
if P[i] >= 4:
for j in range(i + 1, pn):
if P[j] >= 4:
for k in range(pn):
if P[k] >= 2 and k != i and k != j:
ans += 1
print(ans)
# print(primes)
# print(P)
return 0
if __name__ == "__main__":
solve()
| false | 38.095238 |
[
"-N = int(eval(input()))",
"-lim = 1",
"-for i in range(N):",
"- lim *= i + 1",
"-Prime = [",
"- 2,",
"- 3,",
"- 5,",
"- 7,",
"- 11,",
"- 13,",
"- 17,",
"- 19,",
"- 23,",
"- 29,",
"- 31,",
"- 37,",
"- 41,",
"- 43,",
"- 47,",
"- 53,",
"- 59,",
"- 61,",
"- 67,",
"- 71,",
"- 73,",
"- 79,",
"- 83,",
"- 89,",
"- 97,",
"-]",
"-Ans = 0",
"-for i in range(23):",
"- for j in range(i + 1, 24):",
"- for k in range(j + 1, 25):",
"- a, b, c = Prime[i], Prime[j], Prime[k]",
"- d, e, f = (",
"- (a**4) * (b**4) * (c**2),",
"- (a**4) * (b**2) * (c**4),",
"- (a**2) * (b**4) * (c**4),",
"- )",
"- if d <= lim and lim % d == 0:",
"- Ans += 1",
"- if e <= lim and lim % e == 0:",
"- Ans += 1",
"- if f <= lim and lim % f == 0:",
"- Ans += 1",
"-for i in range(24):",
"- for j in range(i + 1, 25):",
"- a, b = Prime[i], Prime[j]",
"- d, e, f, g = (",
"- (a**24) * (b**2),",
"- (a**2) * (b**24),",
"- (a**4) * (b**14),",
"- (a**14) * (b**4),",
"- )",
"- if d <= lim and lim % d == 0:",
"- Ans += 1",
"- if e <= lim and lim % e == 0:",
"- Ans += 1",
"- if f <= lim and lim % f == 0:",
"- Ans += 1",
"- if g <= lim and lim % g == 0:",
"- Ans += 1",
"-for i in range(5):",
"- if Prime[i] ** 74 <= lim and lim % (Prime[i] ** 74) == 0:",
"- Ans += 1",
"-print(Ans)",
"+import sys",
"+from collections import defaultdict",
"+",
"+",
"+def solve():",
"+ input = sys.stdin.readline",
"+ N = int(eval(input()))",
"+ primes = defaultdict(int)",
"+ ans = 0",
"+ for i in range(1, N + 1):",
"+ k = i",
"+ for j in range(2, i + 1):",
"+ if j**2 > i:",
"+ break",
"+ if k % j == 0:",
"+ while k % j == 0:",
"+ primes[j] += 1",
"+ k //= j",
"+ if k > 1:",
"+ primes[k] += 1",
"+ P = []",
"+ for key in primes:",
"+ P.append(primes[key])",
"+ pn = len(P)",
"+ for i in range(pn):",
"+ if P[i] >= 74:",
"+ ans += 1",
"+ if P[i] >= 24:",
"+ for j in range(pn):",
"+ if P[j] >= 2 and j != i:",
"+ ans += 1",
"+ if P[i] >= 14:",
"+ for j in range(pn):",
"+ if P[j] >= 4 and j != i:",
"+ ans += 1",
"+ if P[i] >= 4:",
"+ for j in range(i + 1, pn):",
"+ if P[j] >= 4:",
"+ for k in range(pn):",
"+ if P[k] >= 2 and k != i and k != j:",
"+ ans += 1",
"+ print(ans)",
"+ # print(primes)",
"+ # print(P)",
"+ return 0",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.047695 | 0.040138 | 1.18827 |
[
"s800907596",
"s272203257"
] |
u437351386
|
p03044
|
python
|
s925544461
|
s699928289
| 708 | 564 | 84,432 | 181,980 |
Accepted
|
Accepted
| 20.34 |
# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)
#二部グラフになっている時の色の塗り分けを聞いている
n=int(eval(input()))
es=[[] for i in range(n)]
for i in range(n-1):
u,v,w=list(map(int,input().split()))
es[u-1].append([v,w])
es[v-1].append([u,w])
colors=[0 for i in range(n)]
#深さ優先探索 頂点vをcolorで塗ることを考える
def dfs(v,color):
colors[v-1]=color
for i in es[v-1]:
if i[1]%2==0 and colors[i[0]-1]==0:
dfs(i[0],color)
elif i[1]%2==1 and colors[i[0]-1]==0:
dfs(i[0],(-1)*color)
return colors
a=dfs(1,-1)
for i in a:
if i==-1:
print((0))
else:
print((1))
|
n=int(eval(input()))
#隣接リスト表現
es=[[] for i in range(n)]
for i in range(n-1):
u,v,w=list(map(int,input().split()))
es[u-1].append([v-1,w])
es[v-1].append([u-1,w])
# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)
#頂点vから初めて白なら1、黒なら−1、未探索なら0
colors=[0 for i in range(n)]
def search(v,color):
colors[v]=color
#vから行ける辺について考える
for to in es[v]:
if colors[to[0]]==0 and to[1]%2==0:
search(to[0],color)
elif colors[to[0]]==0 and to[1]%2==1:
search(to[0],-color)
return colors
search(0,1)
for i in colors:
if i==-1:
print((0))
else:
print((1))
| 30 | 36 | 616 | 642 |
# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)
# 二部グラフになっている時の色の塗り分けを聞いている
n = int(eval(input()))
es = [[] for i in range(n)]
for i in range(n - 1):
u, v, w = list(map(int, input().split()))
es[u - 1].append([v, w])
es[v - 1].append([u, w])
colors = [0 for i in range(n)]
# 深さ優先探索 頂点vをcolorで塗ることを考える
def dfs(v, color):
colors[v - 1] = color
for i in es[v - 1]:
if i[1] % 2 == 0 and colors[i[0] - 1] == 0:
dfs(i[0], color)
elif i[1] % 2 == 1 and colors[i[0] - 1] == 0:
dfs(i[0], (-1) * color)
return colors
a = dfs(1, -1)
for i in a:
if i == -1:
print((0))
else:
print((1))
|
n = int(eval(input()))
# 隣接リスト表現
es = [[] for i in range(n)]
for i in range(n - 1):
u, v, w = list(map(int, input().split()))
es[u - 1].append([v - 1, w])
es[v - 1].append([u - 1, w])
# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)
# 頂点vから初めて白なら1、黒なら−1、未探索なら0
colors = [0 for i in range(n)]
def search(v, color):
colors[v] = color
# vから行ける辺について考える
for to in es[v]:
if colors[to[0]] == 0 and to[1] % 2 == 0:
search(to[0], color)
elif colors[to[0]] == 0 and to[1] % 2 == 1:
search(to[0], -color)
return colors
search(0, 1)
for i in colors:
if i == -1:
print((0))
else:
print((1))
| false | 16.666667 |
[
"+n = int(eval(input()))",
"+# 隣接リスト表現",
"+es = [[] for i in range(n)]",
"+for i in range(n - 1):",
"+ u, v, w = list(map(int, input().split()))",
"+ es[u - 1].append([v - 1, w])",
"+ es[v - 1].append([u - 1, w])",
"-# 二部グラフになっている時の色の塗り分けを聞いている",
"-n = int(eval(input()))",
"-es = [[] for i in range(n)]",
"-for i in range(n - 1):",
"- u, v, w = list(map(int, input().split()))",
"- es[u - 1].append([v, w])",
"- es[v - 1].append([u, w])",
"+# 頂点vから初めて白なら1、黒なら−1、未探索なら0",
"-# 深さ優先探索 頂点vをcolorで塗ることを考える",
"-def dfs(v, color):",
"- colors[v - 1] = color",
"- for i in es[v - 1]:",
"- if i[1] % 2 == 0 and colors[i[0] - 1] == 0:",
"- dfs(i[0], color)",
"- elif i[1] % 2 == 1 and colors[i[0] - 1] == 0:",
"- dfs(i[0], (-1) * color)",
"+",
"+",
"+def search(v, color):",
"+ colors[v] = color",
"+ # vから行ける辺について考える",
"+ for to in es[v]:",
"+ if colors[to[0]] == 0 and to[1] % 2 == 0:",
"+ search(to[0], color)",
"+ elif colors[to[0]] == 0 and to[1] % 2 == 1:",
"+ search(to[0], -color)",
"-a = dfs(1, -1)",
"-for i in a:",
"+search(0, 1)",
"+for i in colors:"
] | false | 0.087655 | 0.046687 | 1.877514 |
[
"s925544461",
"s699928289"
] |
u854294899
|
p02594
|
python
|
s409363457
|
s802421591
| 28 | 25 | 9,144 | 9,092 |
Accepted
|
Accepted
| 10.71 |
n = int(eval(input()))
if n >= 30:
print('Yes')
else:
print('No')
|
n = int(eval(input()))
s = ''
if n >= 30:
s = 'Yes'
else:
s = 'No'
print(s)
| 5 | 7 | 67 | 79 |
n = int(eval(input()))
if n >= 30:
print("Yes")
else:
print("No")
|
n = int(eval(input()))
s = ""
if n >= 30:
s = "Yes"
else:
s = "No"
print(s)
| false | 28.571429 |
[
"+s = \"\"",
"- print(\"Yes\")",
"+ s = \"Yes\"",
"- print(\"No\")",
"+ s = \"No\"",
"+print(s)"
] | false | 0.112134 | 0.085532 | 1.311012 |
[
"s409363457",
"s802421591"
] |
u498531348
|
p02772
|
python
|
s401498611
|
s827111329
| 71 | 62 | 62,008 | 62,016 |
Accepted
|
Accepted
| 12.68 |
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if (A[i] % 2 == 0):
if A[i] % 3 != 0 and A[i] % 5 != 0:
print('DENIED')
exit()
else:
continue
else:
continue
print('APPROVED')
|
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if (A[i] % 2 != 0 or (A[i] % 3 == 0 or A[i] % 5 == 0)):
continue
else:
print('DENIED')
exit()
print('APPROVED')
| 17 | 15 | 297 | 246 |
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if A[i] % 2 == 0:
if A[i] % 3 != 0 and A[i] % 5 != 0:
print("DENIED")
exit()
else:
continue
else:
continue
print("APPROVED")
|
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if A[i] % 2 != 0 or (A[i] % 3 == 0 or A[i] % 5 == 0):
continue
else:
print("DENIED")
exit()
print("APPROVED")
| false | 11.764706 |
[
"- if A[i] % 2 == 0:",
"- if A[i] % 3 != 0 and A[i] % 5 != 0:",
"- print(\"DENIED\")",
"- exit()",
"- else:",
"- continue",
"+ if A[i] % 2 != 0 or (A[i] % 3 == 0 or A[i] % 5 == 0):",
"+ continue",
"- continue",
"+ print(\"DENIED\")",
"+ exit()"
] | false | 0.045471 | 0.045289 | 1.004036 |
[
"s401498611",
"s827111329"
] |
u896741788
|
p03634
|
python
|
s994744232
|
s019648985
| 1,464 | 623 | 47,184 | 47,156 |
Accepted
|
Accepted
| 57.45 |
n=int(eval(input()))
edges=[[] for i in range(n)]
for i in range(n-1):
a,s,d=list(map(int,input().split()))
edges[a-1].append((s-1,d));edges[s-1].append((a-1,d))
q,k=list(map(int,input().split()))
cost=[0]*n
from collections import deque
dq=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
for to,cos in edges[k-1]:
dq.append((k-1,to))
cost[to]=cos
while dq:
par,now=dq.popleft()
for to,c in edges[now]:
if to!=par:
cost[to]=cost[now]+c
dq.append((now,to))
for i in range(q):
x,y=list(map(int,input().split()))
print((cost[x-1]+cost[y-1]))
|
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n=int(eval(input()))
edges=[[] for i in range(n)]
for i in range(n-1):
a,s,d=list(map(int,input().split()))
edges[a-1].append((s-1,d));edges[s-1].append((a-1,d))
q,k=list(map(int,input().split()))
cost=[0]*n
from collections import deque
dq=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
for to,cos in edges[k-1]:
dq.append((k-1,to))
cost[to]=cos
while dq:
par,now=dq.popleft()
for to,c in edges[now]:
if to!=par:
cost[to]=cost[now]+c
dq.append((now,to))
for i in range(q):
x,y=list(map(int,input().split()))
print((cost[x-1]+cost[y-1]))
| 24 | 27 | 636 | 711 |
n = int(eval(input()))
edges = [[] for i in range(n)]
for i in range(n - 1):
a, s, d = list(map(int, input().split()))
edges[a - 1].append((s - 1, d))
edges[s - 1].append((a - 1, d))
q, k = list(map(int, input().split()))
cost = [0] * n
from collections import deque
dq = deque([])
# pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
for to, cos in edges[k - 1]:
dq.append((k - 1, to))
cost[to] = cos
while dq:
par, now = dq.popleft()
for to, c in edges[now]:
if to != par:
cost[to] = cost[now] + c
dq.append((now, to))
for i in range(q):
x, y = list(map(int, input().split()))
print((cost[x - 1] + cost[y - 1]))
|
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n = int(eval(input()))
edges = [[] for i in range(n)]
for i in range(n - 1):
a, s, d = list(map(int, input().split()))
edges[a - 1].append((s - 1, d))
edges[s - 1].append((a - 1, d))
q, k = list(map(int, input().split()))
cost = [0] * n
from collections import deque
dq = deque([])
# pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
for to, cos in edges[k - 1]:
dq.append((k - 1, to))
cost[to] = cos
while dq:
par, now = dq.popleft()
for to, c in edges[now]:
if to != par:
cost[to] = cost[now] + c
dq.append((now, to))
for i in range(q):
x, y = list(map(int, input().split()))
print((cost[x - 1] + cost[y - 1]))
| false | 11.111111 |
[
"+import sys",
"+",
"+input = sys.stdin.buffer.readline",
"+sys.setrecursionlimit(10**9)"
] | false | 0.040778 | 0.069983 | 0.582682 |
[
"s994744232",
"s019648985"
] |
u203843959
|
p02990
|
python
|
s840959648
|
s521013909
| 1,219 | 89 | 3,316 | 3,316 |
Accepted
|
Accepted
| 92.7 |
MOD=10**9+7
def powmod(a,p):
if p==0:
return 1
elif p==1:
return a
else:
pow2=powmod(a,p//2)
if p%2==0:
return (pow2**2)%MOD
else:
return (a*pow2**2)%MOD
def invmod(a):
return powmod(a,MOD-2)
def comb_mod(n,r):
nPr=1
fact_r=1
for i in range(r):
nPr*=n-i
nPr%=MOD
fact_r*=r-i
fact_r%=MOD
return (nPr*invmod(fact_r))%MOD
N,K=list(map(int,input().split()))
for i in range(1,K+1):
term1=comb_mod(N-K+1,i)
term2=comb_mod(K-1,K-i)
print((term1*term2%MOD))
|
MOD=10**9+7
N,K=list(map(int,input().split()))
def powmod(a,p):
if p==0:
return 1
elif p==1:
return a
else:
pow2=powmod(a,p//2)
if p%2==0:
return (pow2**2)%MOD
else:
return (a*pow2**2)%MOD
def invmod(a):
return powmod(a,MOD-2)
term1=N-K+1
term2=1
for i in range(1,K+1):
#print(term1,term2)
print(((term1*term2)%MOD))
term1=term1*(N-K+1-i)*invmod(i+1)%MOD
term2=term2*(K-i)*invmod(i)%MOD
| 30 | 25 | 544 | 457 |
MOD = 10**9 + 7
def powmod(a, p):
if p == 0:
return 1
elif p == 1:
return a
else:
pow2 = powmod(a, p // 2)
if p % 2 == 0:
return (pow2**2) % MOD
else:
return (a * pow2**2) % MOD
def invmod(a):
return powmod(a, MOD - 2)
def comb_mod(n, r):
nPr = 1
fact_r = 1
for i in range(r):
nPr *= n - i
nPr %= MOD
fact_r *= r - i
fact_r %= MOD
return (nPr * invmod(fact_r)) % MOD
N, K = list(map(int, input().split()))
for i in range(1, K + 1):
term1 = comb_mod(N - K + 1, i)
term2 = comb_mod(K - 1, K - i)
print((term1 * term2 % MOD))
|
MOD = 10**9 + 7
N, K = list(map(int, input().split()))
def powmod(a, p):
if p == 0:
return 1
elif p == 1:
return a
else:
pow2 = powmod(a, p // 2)
if p % 2 == 0:
return (pow2**2) % MOD
else:
return (a * pow2**2) % MOD
def invmod(a):
return powmod(a, MOD - 2)
term1 = N - K + 1
term2 = 1
for i in range(1, K + 1):
# print(term1,term2)
print(((term1 * term2) % MOD))
term1 = term1 * (N - K + 1 - i) * invmod(i + 1) % MOD
term2 = term2 * (K - i) * invmod(i) % MOD
| false | 16.666667 |
[
"+N, K = list(map(int, input().split()))",
"-def comb_mod(n, r):",
"- nPr = 1",
"- fact_r = 1",
"- for i in range(r):",
"- nPr *= n - i",
"- nPr %= MOD",
"- fact_r *= r - i",
"- fact_r %= MOD",
"- return (nPr * invmod(fact_r)) % MOD",
"-",
"-",
"-N, K = list(map(int, input().split()))",
"+term1 = N - K + 1",
"+term2 = 1",
"- term1 = comb_mod(N - K + 1, i)",
"- term2 = comb_mod(K - 1, K - i)",
"- print((term1 * term2 % MOD))",
"+ # print(term1,term2)",
"+ print(((term1 * term2) % MOD))",
"+ term1 = term1 * (N - K + 1 - i) * invmod(i + 1) % MOD",
"+ term2 = term2 * (K - i) * invmod(i) % MOD"
] | false | 0.035771 | 0.04097 | 0.873107 |
[
"s840959648",
"s521013909"
] |
u426649993
|
p03575
|
python
|
s731773042
|
s975628005
| 29 | 25 | 3,064 | 3,316 |
Accepted
|
Accepted
| 13.79 |
if __name__ == "__main__":
n, m = list(map(int, input().split()))
edge = list()
for i in range(m):
edge.append(list(map(int, input().split())))
ans = 0
def dfs(v):
visted[v] = True
for i in range(n):
if graph[v][i] is False:
continue
if visted[i] is True:
continue
dfs(i)
for i in range(m):
visted = [False] * n
graph = [[False] * n for _ in range(n)]
for j in range(m):
if i != j:
graph[edge[j][0]-1][edge[j][1]-1] = True
graph[edge[j][1]-1][edge[j][0]-1] = True
dfs(0)
if visted != [True] * n:
ans += 1
print((str(ans)))
|
from collections import deque
if __name__ == "__main__":
n, m = list(map(int, input().split()))
edge = list()
for i in range(m):
edge.append(list(map(int, input().split())))
ans = 0
for i in range(m):
distance = [-1] * n
que = deque([0])
graph = dict()
for j in range(n):
graph[j] = []
distance[0] = 0 # 初期条件(スタート地点)
for j in range(m):
if i != j:
graph[edge[j][0]-1].append(edge[j][1]-1)
graph[edge[j][1]-1].append(edge[j][0]-1)
# 幅優先探索
while len(que) != 0:
v = que.popleft()
for g in graph[v]:
if distance[g] != -1:
continue
distance[g] = distance[v] + 1
que.append(g)
for d in distance:
if d == -1:
ans += 1
break
print((str(ans)))
| 30 | 39 | 765 | 969 |
if __name__ == "__main__":
n, m = list(map(int, input().split()))
edge = list()
for i in range(m):
edge.append(list(map(int, input().split())))
ans = 0
def dfs(v):
visted[v] = True
for i in range(n):
if graph[v][i] is False:
continue
if visted[i] is True:
continue
dfs(i)
for i in range(m):
visted = [False] * n
graph = [[False] * n for _ in range(n)]
for j in range(m):
if i != j:
graph[edge[j][0] - 1][edge[j][1] - 1] = True
graph[edge[j][1] - 1][edge[j][0] - 1] = True
dfs(0)
if visted != [True] * n:
ans += 1
print((str(ans)))
|
from collections import deque
if __name__ == "__main__":
n, m = list(map(int, input().split()))
edge = list()
for i in range(m):
edge.append(list(map(int, input().split())))
ans = 0
for i in range(m):
distance = [-1] * n
que = deque([0])
graph = dict()
for j in range(n):
graph[j] = []
distance[0] = 0 # 初期条件(スタート地点)
for j in range(m):
if i != j:
graph[edge[j][0] - 1].append(edge[j][1] - 1)
graph[edge[j][1] - 1].append(edge[j][0] - 1)
# 幅優先探索
while len(que) != 0:
v = que.popleft()
for g in graph[v]:
if distance[g] != -1:
continue
distance[g] = distance[v] + 1
que.append(g)
for d in distance:
if d == -1:
ans += 1
break
print((str(ans)))
| false | 23.076923 |
[
"+from collections import deque",
"+",
"-",
"- def dfs(v):",
"- visted[v] = True",
"- for i in range(n):",
"- if graph[v][i] is False:",
"- continue",
"- if visted[i] is True:",
"- continue",
"- dfs(i)",
"-",
"- visted = [False] * n",
"- graph = [[False] * n for _ in range(n)]",
"+ distance = [-1] * n",
"+ que = deque([0])",
"+ graph = dict()",
"+ for j in range(n):",
"+ graph[j] = []",
"+ distance[0] = 0 # 初期条件(スタート地点)",
"- graph[edge[j][0] - 1][edge[j][1] - 1] = True",
"- graph[edge[j][1] - 1][edge[j][0] - 1] = True",
"- dfs(0)",
"- if visted != [True] * n:",
"- ans += 1",
"+ graph[edge[j][0] - 1].append(edge[j][1] - 1)",
"+ graph[edge[j][1] - 1].append(edge[j][0] - 1)",
"+ # 幅優先探索",
"+ while len(que) != 0:",
"+ v = que.popleft()",
"+ for g in graph[v]:",
"+ if distance[g] != -1:",
"+ continue",
"+ distance[g] = distance[v] + 1",
"+ que.append(g)",
"+ for d in distance:",
"+ if d == -1:",
"+ ans += 1",
"+ break"
] | false | 0.046003 | 0.064909 | 0.708726 |
[
"s731773042",
"s975628005"
] |
u353919145
|
p03712
|
python
|
s641645488
|
s810684737
| 32 | 19 | 4,468 | 3,064 |
Accepted
|
Accepted
| 40.62 |
arr=list(map(int,input().rstrip().split()))
r=arr[0]
c=arr[1]
line=[]
for i in range(0,r):
line.append(input())
s=[[0 for x in range(r)]for y in range(c)]
for i in range(0,r+2):
for j in range(0,c+2):
if i == 0 or i == r + 1 or j == 0 or j == c + 1:
print("#",end="")
else:
z=line[i-1]
print(z[j-1],end="")
print()
|
h,w = [int(i) for i in input().split()]
pic = []
for i in range(h):
pic.append(input())
for i in range(w+2):
print('#', sep='',end='')
print()
for i in range(h):
print('#', sep='',end='')
print(pic[i],end='')
print('#')
for i in range(w+2):
print('#', sep='',end='')
print()
| 16 | 21 | 395 | 308 |
arr = list(map(int, input().rstrip().split()))
r = arr[0]
c = arr[1]
line = []
for i in range(0, r):
line.append(input())
s = [[0 for x in range(r)] for y in range(c)]
for i in range(0, r + 2):
for j in range(0, c + 2):
if i == 0 or i == r + 1 or j == 0 or j == c + 1:
print("#", end="")
else:
z = line[i - 1]
print(z[j - 1], end="")
print()
|
h, w = [int(i) for i in input().split()]
pic = []
for i in range(h):
pic.append(input())
for i in range(w + 2):
print("#", sep="", end="")
print()
for i in range(h):
print("#", sep="", end="")
print(pic[i], end="")
print("#")
for i in range(w + 2):
print("#", sep="", end="")
print()
| false | 23.809524 |
[
"-arr = list(map(int, input().rstrip().split()))",
"-r = arr[0]",
"-c = arr[1]",
"-line = []",
"-for i in range(0, r):",
"- line.append(input())",
"-s = [[0 for x in range(r)] for y in range(c)]",
"-for i in range(0, r + 2):",
"- for j in range(0, c + 2):",
"- if i == 0 or i == r + 1 or j == 0 or j == c + 1:",
"- print(\"#\", end=\"\")",
"- else:",
"- z = line[i - 1]",
"- print(z[j - 1], end=\"\")",
"- print()",
"+h, w = [int(i) for i in input().split()]",
"+pic = []",
"+for i in range(h):",
"+ pic.append(input())",
"+for i in range(w + 2):",
"+ print(\"#\", sep=\"\", end=\"\")",
"+print()",
"+for i in range(h):",
"+ print(\"#\", sep=\"\", end=\"\")",
"+ print(pic[i], end=\"\")",
"+ print(\"#\")",
"+for i in range(w + 2):",
"+ print(\"#\", sep=\"\", end=\"\")",
"+print()"
] | false | 0.058519 | 0.079206 | 0.738826 |
[
"s641645488",
"s810684737"
] |
u347640436
|
p02873
|
python
|
s197619008
|
s008457451
| 427 | 341 | 23,336 | 24,752 |
Accepted
|
Accepted
| 20.14 |
S = eval(input())
N = len(S) + 1
t = [0] * N
p = ''
for i in range(N - 2, -2, -1):
if p == '>':
t[i + 1] = t[i + 2] + 1
p = S[i]
for i in range(N - 1):
if S[i] == '<':
t[i + 1] = max(t[i + 1], t[i] + 1)
print((sum(t)))
|
S = eval(input())
N = len(S) + 1
t = [0] * N
for i in range(N - 1):
if S[i] == '<':
t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
if S[i] == '>':
t[i] = max(t[i], t[i + 1] + 1)
print((sum(t)))
| 13 | 11 | 238 | 225 |
S = eval(input())
N = len(S) + 1
t = [0] * N
p = ""
for i in range(N - 2, -2, -1):
if p == ">":
t[i + 1] = t[i + 2] + 1
p = S[i]
for i in range(N - 1):
if S[i] == "<":
t[i + 1] = max(t[i + 1], t[i] + 1)
print((sum(t)))
|
S = eval(input())
N = len(S) + 1
t = [0] * N
for i in range(N - 1):
if S[i] == "<":
t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
if S[i] == ">":
t[i] = max(t[i], t[i + 1] + 1)
print((sum(t)))
| false | 15.384615 |
[
"-p = \"\"",
"-for i in range(N - 2, -2, -1):",
"- if p == \">\":",
"- t[i + 1] = t[i + 2] + 1",
"- p = S[i]",
"- t[i + 1] = max(t[i + 1], t[i] + 1)",
"+ t[i + 1] = t[i] + 1",
"+for i in range(N - 2, -1, -1):",
"+ if S[i] == \">\":",
"+ t[i] = max(t[i], t[i + 1] + 1)"
] | false | 0.04268 | 0.075816 | 0.562944 |
[
"s197619008",
"s008457451"
] |
u923668099
|
p02397
|
python
|
s205934351
|
s965357992
| 50 | 30 | 7,560 | 7,816 |
Accepted
|
Accepted
| 40 |
# coding: utf-8
# Here your code !
while True:
x,y = list(map(int, input().split()))
if x == 0 and y == 0:
break
if x < y:
print((str(x) + " " + str(y)))
else:
print((str(y) + " " + str(x)))
|
from sys import stdin
for test_case in range(3000 + 2):
x, y = list(map(int, stdin.readline().split()))
if not(x + y):
break
if x > y:
x, y = y, x
print((x, y))
| 13 | 12 | 249 | 199 |
# coding: utf-8
# Here your code !
while True:
x, y = list(map(int, input().split()))
if x == 0 and y == 0:
break
if x < y:
print((str(x) + " " + str(y)))
else:
print((str(y) + " " + str(x)))
|
from sys import stdin
for test_case in range(3000 + 2):
x, y = list(map(int, stdin.readline().split()))
if not (x + y):
break
if x > y:
x, y = y, x
print((x, y))
| false | 7.692308 |
[
"-# coding: utf-8",
"-# Here your code !",
"-while True:",
"- x, y = list(map(int, input().split()))",
"- if x == 0 and y == 0:",
"+from sys import stdin",
"+",
"+for test_case in range(3000 + 2):",
"+ x, y = list(map(int, stdin.readline().split()))",
"+ if not (x + y):",
"- if x < y:",
"- print((str(x) + \" \" + str(y)))",
"- else:",
"- print((str(y) + \" \" + str(x)))",
"+ if x > y:",
"+ x, y = y, x",
"+ print((x, y))"
] | false | 0.037143 | 0.07864 | 0.472317 |
[
"s205934351",
"s965357992"
] |
u667024514
|
p03818
|
python
|
s316554474
|
s303488340
| 93 | 53 | 14,396 | 14,564 |
Accepted
|
Accepted
| 43.01 |
n = int(eval(input()))
lis = list(map(int,input().split()))
s = set()
for i in range(n):s.add(lis[i])
lis.sort()
if (len(lis)-len(s)) % 2 == 1:
print((len(s)-1))
else:
print((len(s)))
|
n = int(eval(input()))
lis = list(map(int,input().split()))
ans = set()
for num in lis:ans.add(num)
print((len(ans)-((len(ans) % 2)+1)%2))
| 9 | 5 | 183 | 134 |
n = int(eval(input()))
lis = list(map(int, input().split()))
s = set()
for i in range(n):
s.add(lis[i])
lis.sort()
if (len(lis) - len(s)) % 2 == 1:
print((len(s) - 1))
else:
print((len(s)))
|
n = int(eval(input()))
lis = list(map(int, input().split()))
ans = set()
for num in lis:
ans.add(num)
print((len(ans) - ((len(ans) % 2) + 1) % 2))
| false | 44.444444 |
[
"-s = set()",
"-for i in range(n):",
"- s.add(lis[i])",
"-lis.sort()",
"-if (len(lis) - len(s)) % 2 == 1:",
"- print((len(s) - 1))",
"-else:",
"- print((len(s)))",
"+ans = set()",
"+for num in lis:",
"+ ans.add(num)",
"+print((len(ans) - ((len(ans) % 2) + 1) % 2))"
] | false | 0.088086 | 0.045172 | 1.950008 |
[
"s316554474",
"s303488340"
] |
u630511239
|
p03380
|
python
|
s527014957
|
s244930206
| 95 | 79 | 14,052 | 20,068 |
Accepted
|
Accepted
| 16.84 |
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
M = A[-1]
a = M // 2
for i in range(N-1):
if A[i] <= a and A[i+1] >= a:
if (M-A[i])*A[i] >= (M-A[i+1])*A[i+1]:
ans = [M, A[i]]
else:
ans = [M, A[i+1]]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = a[-1]
m = a[0]
C = -1
for i in range(n):
c = a[i]*(M-a[i])
if C < c:
C = c
m = a[i]
else:
break
print(M, m, sep=' ')
| 15 | 14 | 314 | 213 |
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
M = A[-1]
a = M // 2
for i in range(N - 1):
if A[i] <= a and A[i + 1] >= a:
if (M - A[i]) * A[i] >= (M - A[i + 1]) * A[i + 1]:
ans = [M, A[i]]
else:
ans = [M, A[i + 1]]
ans = [str(b) for b in ans]
ans = " ".join(ans)
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = a[-1]
m = a[0]
C = -1
for i in range(n):
c = a[i] * (M - a[i])
if C < c:
C = c
m = a[i]
else:
break
print(M, m, sep=" ")
| false | 6.666667 |
[
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-A.sort()",
"-M = A[-1]",
"-a = M // 2",
"-for i in range(N - 1):",
"- if A[i] <= a and A[i + 1] >= a:",
"- if (M - A[i]) * A[i] >= (M - A[i + 1]) * A[i + 1]:",
"- ans = [M, A[i]]",
"- else:",
"- ans = [M, A[i + 1]]",
"-ans = [str(b) for b in ans]",
"-ans = \" \".join(ans)",
"-print(ans)",
"+n = int(input())",
"+a = list(map(int, input().split()))",
"+a.sort()",
"+M = a[-1]",
"+m = a[0]",
"+C = -1",
"+for i in range(n):",
"+ c = a[i] * (M - a[i])",
"+ if C < c:",
"+ C = c",
"+ m = a[i]",
"+ else:",
"+ break",
"+print(M, m, sep=\" \")"
] | false | 0.180158 | 0.075836 | 2.375624 |
[
"s527014957",
"s244930206"
] |
u102461423
|
p03682
|
python
|
s059605954
|
s304108636
| 1,405 | 1,103 | 74,612 | 81,240 |
Accepted
|
Accepted
| 21.49 |
import sys
input = sys.stdin.readline
from operator import itemgetter
from scipy.sparse import csr_matrix
import numpy as np
N = int(eval(input()))
XY = [[i] + [int(x) for x in input().split()] for i in range(N)]
edge = set()
for key in [itemgetter(1),itemgetter(2)]:
XY.sort(key = key)
for i in range(N-1):
i1,x1,y1 = XY[i]
i2,x2,y2 = XY[i+1]
d = min(abs(x1-x2),abs(y1-y2))
edge.add((i1,i2,d))
# csr形式に直す
edge = sorted(list(edge))
row,col,value = list(zip(*edge))
value = np.array(value,dtype=int)
graph = csr_matrix((value,(row,col)),shape=(N,N))
# 最小全域木
from scipy.sparse.csgraph import minimum_spanning_tree
tree = minimum_spanning_tree(graph, overwrite = True).astype(int)
answer = tree.sum()
print(answer)
|
import sys
input = sys.stdin.readline
from operator import itemgetter
from scipy.sparse import csr_matrix
import numpy as np
N = int(eval(input()))
XY = [[i] + [int(x) for x in input().split()] for i in range(N)]
edge = set()
for key in [itemgetter(1),itemgetter(2)]:
XY.sort(key = key)
for i in range(N-1):
i1,x1,y1 = XY[i]
i2,x2,y2 = XY[i+1]
d = min(abs(x1-x2),abs(y1-y2))
edge.add((i1,i2,d))
# csr形式に直す
row,col,value = list(zip(*edge))
value = np.array(value,dtype=int)
graph = csr_matrix((value,(row,col)),shape=(N,N))
# 最小全域木
from scipy.sparse.csgraph import minimum_spanning_tree
tree = minimum_spanning_tree(graph, overwrite = True).astype(int)
answer = tree.sum()
print(answer)
| 30 | 29 | 758 | 731 |
import sys
input = sys.stdin.readline
from operator import itemgetter
from scipy.sparse import csr_matrix
import numpy as np
N = int(eval(input()))
XY = [[i] + [int(x) for x in input().split()] for i in range(N)]
edge = set()
for key in [itemgetter(1), itemgetter(2)]:
XY.sort(key=key)
for i in range(N - 1):
i1, x1, y1 = XY[i]
i2, x2, y2 = XY[i + 1]
d = min(abs(x1 - x2), abs(y1 - y2))
edge.add((i1, i2, d))
# csr形式に直す
edge = sorted(list(edge))
row, col, value = list(zip(*edge))
value = np.array(value, dtype=int)
graph = csr_matrix((value, (row, col)), shape=(N, N))
# 最小全域木
from scipy.sparse.csgraph import minimum_spanning_tree
tree = minimum_spanning_tree(graph, overwrite=True).astype(int)
answer = tree.sum()
print(answer)
|
import sys
input = sys.stdin.readline
from operator import itemgetter
from scipy.sparse import csr_matrix
import numpy as np
N = int(eval(input()))
XY = [[i] + [int(x) for x in input().split()] for i in range(N)]
edge = set()
for key in [itemgetter(1), itemgetter(2)]:
XY.sort(key=key)
for i in range(N - 1):
i1, x1, y1 = XY[i]
i2, x2, y2 = XY[i + 1]
d = min(abs(x1 - x2), abs(y1 - y2))
edge.add((i1, i2, d))
# csr形式に直す
row, col, value = list(zip(*edge))
value = np.array(value, dtype=int)
graph = csr_matrix((value, (row, col)), shape=(N, N))
# 最小全域木
from scipy.sparse.csgraph import minimum_spanning_tree
tree = minimum_spanning_tree(graph, overwrite=True).astype(int)
answer = tree.sum()
print(answer)
| false | 3.333333 |
[
"-edge = sorted(list(edge))"
] | false | 0.341326 | 0.341457 | 0.999616 |
[
"s059605954",
"s304108636"
] |
u849324100
|
p03012
|
python
|
s133943399
|
s780003061
| 151 | 18 | 12,436 | 3,060 |
Accepted
|
Accepted
| 88.08 |
#import sys
#import math
import numpy as np
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)]
a=int(eval(input()))
li0=[int(x) for x in input().split()]
count=0
ju=ans=mis=0
half=0
count=sum(li0)//2
for i in range(len(li0)):
ju+=li0[i]
if ju>=count:
half=i
break
if sum(li0[0:half])>=sum(li0[half+1:]):
print((np.absolute(sum(li0[0:half])-sum(li0[half:]))))
else:
print((np.absolute(sum(li0[0:half+1])-sum(li0[half+1:]))))
|
#import sys
#import math
#import numpy as np
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)]
a=int(eval(input()))
li=[int(x) for x in input().split()]
count=10**9
for i in range(len(li)):
count=min(count,abs(sum(li[:i])-sum(li[i:])))
print(count)
| 24 | 15 | 632 | 438 |
# import sys
# import math
import numpy as np
"""a,b= map(int,input().split())"""
# a, b, c = [list(map(int, input().split())) for _ in range(3)]
# li0= [int(x) for x in input().split()]
# n,l= map(int, input().split())
# x = [list(map(int, input().split())) for _ in range(n)]
a = int(eval(input()))
li0 = [int(x) for x in input().split()]
count = 0
ju = ans = mis = 0
half = 0
count = sum(li0) // 2
for i in range(len(li0)):
ju += li0[i]
if ju >= count:
half = i
break
if sum(li0[0:half]) >= sum(li0[half + 1 :]):
print((np.absolute(sum(li0[0:half]) - sum(li0[half:]))))
else:
print((np.absolute(sum(li0[0 : half + 1]) - sum(li0[half + 1 :]))))
|
# import sys
# import math
# import numpy as np
"""a,b= map(int,input().split())"""
# a, b, c = [list(map(int, input().split())) for _ in range(3)]
# li0= [int(x) for x in input().split()]
# n,l= map(int, input().split())
# x = [list(map(int, input().split())) for _ in range(n)]
a = int(eval(input()))
li = [int(x) for x in input().split()]
count = 10**9
for i in range(len(li)):
count = min(count, abs(sum(li[:i]) - sum(li[i:])))
print(count)
| false | 37.5 |
[
"-import numpy as np",
"-",
"+# import numpy as np",
"-li0 = [int(x) for x in input().split()]",
"-count = 0",
"-ju = ans = mis = 0",
"-half = 0",
"-count = sum(li0) // 2",
"-for i in range(len(li0)):",
"- ju += li0[i]",
"- if ju >= count:",
"- half = i",
"- break",
"-if sum(li0[0:half]) >= sum(li0[half + 1 :]):",
"- print((np.absolute(sum(li0[0:half]) - sum(li0[half:]))))",
"-else:",
"- print((np.absolute(sum(li0[0 : half + 1]) - sum(li0[half + 1 :]))))",
"+li = [int(x) for x in input().split()]",
"+count = 10**9",
"+for i in range(len(li)):",
"+ count = min(count, abs(sum(li[:i]) - sum(li[i:])))",
"+print(count)"
] | false | 0.41604 | 0.036616 | 11.362387 |
[
"s133943399",
"s780003061"
] |
u486448566
|
p03162
|
python
|
s422032471
|
s110621538
| 696 | 361 | 74,200 | 70,236 |
Accepted
|
Accepted
| 48.13 |
n = int(eval(input()))
abc = []
for _ in range(n):
abc.append(list(map(int, input().split())))
dp = [[0]*3 for _ in range(n)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
for i in range(1,n):
for j in range(3):
if j == 0:
dp[i][j] = max(dp[i-1][1], dp[i-1][2]) + abc[i][j]
if j == 1:
dp[i][j] = max(dp[i-1][0], dp[i-1][2]) + abc[i][j]
if j == 2:
dp[i][j] = max(dp[i-1][0], dp[i-1][1]) + abc[i][j]
print((max(dp[n-1])))
|
INF = float("inf")
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda:int(eval(input()))
input_ints = lambda:list(map(int,input().split()))
input_ints_list = lambda:list(input_ints())
input_str = lambda:eval(input())
input_strs = lambda:input().split()
input_lines = lambda n,input_func:[input_func() for _ in range(n)]
import importlib
import_module = lambda module_name:importlib.import_module(module_name)
init_array_1dim = lambda value,n:[value]*n # 1次元配列を生成
init_array_2dim = lambda value,n,m:[init_array_1dim(value,n) for _ in range(m)] # 2次元配列を生成
gcd_base = lambda value1,value2:import_module('fractions').gcd(value1,value2) # 最大公約数(2値)
gcd = lambda lst:import_module('functools').reduce(gcd_base,lst) # 最大公約数(リスト)
lcm_base = lambda value1,value2:(value1*value2)//gcd_base(value1,value2) # 最小公倍数(2値)
lcm = lambda lst:import_module('functools').reduce(lcm_base,lst,1) # 最小公倍数(リスト)
permutations = lambda lst,n:import_module('itertools').permutations(lst,n) # 順列
combinations = lambda lst,n:import_module('itertools').combinations(lst,n) # 組み合わせ
product = lambda lst1,lst2:import_module('itertools').product(lst1,lst2) # 二つのリストの直積
round = lambda value:round(value) # 四捨五入
ceil = lambda value:import_module('math').ceil(value) # 切り上げ
floor = lambda value:import_module('math').floor(value) # 切り捨て
# キュー
init_q = lambda lst: import_module('collections').deque(lst)
q_pop = lambda q: q.popleft() # 先頭から取り出し
q_push = lambda q,value:q.appendleft(value) # 先頭に追加(値)
q_pushlist = lambda q,lst:q.extendleft(lst) # 先頭に追加(リスト)
q_append = lambda q,value:q.append(value) # 末尾に追加(値)
q_appendlist = lambda q,lst:q.extend(lst) # 末尾に追加(リスト)
# プライオリティキュー
init_heap = lambda a:import_module('heapq').heapify(a)
heap_push = lambda a,v:import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す
def solution():
# ここに実装
N = input_int()
abc = input_lines(N,input_ints_list)
dp = init_array_2dim(-1,3,N)
for i in range(N):
if i == 0:
dp[i][0] = abc[0][0]
dp[i][1] = abc[0][1]
dp[i][2] = abc[0][2]
else:
dp[i][0] = abc[i][0] + max(dp[i-1][1],dp[i-1][2])
dp[i][1] = abc[i][1] + max(dp[i-1][0],dp[i-1][2])
dp[i][2] = abc[i][2] + max(dp[i-1][0],dp[i-1][1])
print((max(dp[N-1])))
if __name__ == '__main__':
solution()
| 19 | 63 | 517 | 2,443 |
n = int(eval(input()))
abc = []
for _ in range(n):
abc.append(list(map(int, input().split())))
dp = [[0] * 3 for _ in range(n)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
for i in range(1, n):
for j in range(3):
if j == 0:
dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + abc[i][j]
if j == 1:
dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]) + abc[i][j]
if j == 2:
dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]) + abc[i][j]
print((max(dp[n - 1])))
|
INF = float("inf")
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda: int(eval(input()))
input_ints = lambda: list(map(int, input().split()))
input_ints_list = lambda: list(input_ints())
input_str = lambda: eval(input())
input_strs = lambda: input().split()
input_lines = lambda n, input_func: [input_func() for _ in range(n)]
import importlib
import_module = lambda module_name: importlib.import_module(module_name)
init_array_1dim = lambda value, n: [value] * n # 1次元配列を生成
init_array_2dim = lambda value, n, m: [
init_array_1dim(value, n) for _ in range(m)
] # 2次元配列を生成
gcd_base = lambda value1, value2: import_module("fractions").gcd(
value1, value2
) # 最大公約数(2値)
gcd = lambda lst: import_module("functools").reduce(gcd_base, lst) # 最大公約数(リスト)
lcm_base = lambda value1, value2: (value1 * value2) // gcd_base(
value1, value2
) # 最小公倍数(2値)
lcm = lambda lst: import_module("functools").reduce(lcm_base, lst, 1) # 最小公倍数(リスト)
permutations = lambda lst, n: import_module("itertools").permutations(lst, n) # 順列
combinations = lambda lst, n: import_module("itertools").combinations(lst, n) # 組み合わせ
product = lambda lst1, lst2: import_module("itertools").product(lst1, lst2) # 二つのリストの直積
round = lambda value: round(value) # 四捨五入
ceil = lambda value: import_module("math").ceil(value) # 切り上げ
floor = lambda value: import_module("math").floor(value) # 切り捨て
# キュー
init_q = lambda lst: import_module("collections").deque(lst)
q_pop = lambda q: q.popleft() # 先頭から取り出し
q_push = lambda q, value: q.appendleft(value) # 先頭に追加(値)
q_pushlist = lambda q, lst: q.extendleft(lst) # 先頭に追加(リスト)
q_append = lambda q, value: q.append(value) # 末尾に追加(値)
q_appendlist = lambda q, lst: q.extend(lst) # 末尾に追加(リスト)
# プライオリティキュー
init_heap = lambda a: import_module("heapq").heapify(a)
heap_push = lambda a, v: import_module("heapq").heappush(a, v)
heap_pop = lambda a: import_module("heapq").heappop(a) # 最小値を取り出す
def solution():
# ここに実装
N = input_int()
abc = input_lines(N, input_ints_list)
dp = init_array_2dim(-1, 3, N)
for i in range(N):
if i == 0:
dp[i][0] = abc[0][0]
dp[i][1] = abc[0][1]
dp[i][2] = abc[0][2]
else:
dp[i][0] = abc[i][0] + max(dp[i - 1][1], dp[i - 1][2])
dp[i][1] = abc[i][1] + max(dp[i - 1][0], dp[i - 1][2])
dp[i][2] = abc[i][2] + max(dp[i - 1][0], dp[i - 1][1])
print((max(dp[N - 1])))
if __name__ == "__main__":
solution()
| false | 69.84127 |
[
"-n = int(eval(input()))",
"-abc = []",
"-for _ in range(n):",
"- abc.append(list(map(int, input().split())))",
"-dp = [[0] * 3 for _ in range(n)]",
"-dp[0][0] = abc[0][0]",
"-dp[0][1] = abc[0][1]",
"-dp[0][2] = abc[0][2]",
"-for i in range(1, n):",
"- for j in range(3):",
"- if j == 0:",
"- dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + abc[i][j]",
"- if j == 1:",
"- dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]) + abc[i][j]",
"- if j == 2:",
"- dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]) + abc[i][j]",
"-print((max(dp[n - 1])))",
"+INF = float(\"inf\")",
"+import sys",
"+",
"+sys.setrecursionlimit(10**9)",
"+input = sys.stdin.readline",
"+input_int = lambda: int(eval(input()))",
"+input_ints = lambda: list(map(int, input().split()))",
"+input_ints_list = lambda: list(input_ints())",
"+input_str = lambda: eval(input())",
"+input_strs = lambda: input().split()",
"+input_lines = lambda n, input_func: [input_func() for _ in range(n)]",
"+import importlib",
"+",
"+import_module = lambda module_name: importlib.import_module(module_name)",
"+init_array_1dim = lambda value, n: [value] * n # 1次元配列を生成",
"+init_array_2dim = lambda value, n, m: [",
"+ init_array_1dim(value, n) for _ in range(m)",
"+] # 2次元配列を生成",
"+gcd_base = lambda value1, value2: import_module(\"fractions\").gcd(",
"+ value1, value2",
"+) # 最大公約数(2値)",
"+gcd = lambda lst: import_module(\"functools\").reduce(gcd_base, lst) # 最大公約数(リスト)",
"+lcm_base = lambda value1, value2: (value1 * value2) // gcd_base(",
"+ value1, value2",
"+) # 最小公倍数(2値)",
"+lcm = lambda lst: import_module(\"functools\").reduce(lcm_base, lst, 1) # 最小公倍数(リスト)",
"+permutations = lambda lst, n: import_module(\"itertools\").permutations(lst, n) # 順列",
"+combinations = lambda lst, n: import_module(\"itertools\").combinations(lst, n) # 組み合わせ",
"+product = lambda lst1, lst2: import_module(\"itertools\").product(lst1, lst2) # 二つのリストの直積",
"+round = lambda value: round(value) # 四捨五入",
"+ceil = lambda value: import_module(\"math\").ceil(value) # 切り上げ",
"+floor = lambda value: import_module(\"math\").floor(value) # 切り捨て",
"+# キュー",
"+init_q = lambda lst: import_module(\"collections\").deque(lst)",
"+q_pop = lambda q: q.popleft() # 先頭から取り出し",
"+q_push = lambda q, value: q.appendleft(value) # 先頭に追加(値)",
"+q_pushlist = lambda q, lst: q.extendleft(lst) # 先頭に追加(リスト)",
"+q_append = lambda q, value: q.append(value) # 末尾に追加(値)",
"+q_appendlist = lambda q, lst: q.extend(lst) # 末尾に追加(リスト)",
"+# プライオリティキュー",
"+init_heap = lambda a: import_module(\"heapq\").heapify(a)",
"+heap_push = lambda a, v: import_module(\"heapq\").heappush(a, v)",
"+heap_pop = lambda a: import_module(\"heapq\").heappop(a) # 最小値を取り出す",
"+",
"+",
"+def solution():",
"+ # ここに実装",
"+ N = input_int()",
"+ abc = input_lines(N, input_ints_list)",
"+ dp = init_array_2dim(-1, 3, N)",
"+ for i in range(N):",
"+ if i == 0:",
"+ dp[i][0] = abc[0][0]",
"+ dp[i][1] = abc[0][1]",
"+ dp[i][2] = abc[0][2]",
"+ else:",
"+ dp[i][0] = abc[i][0] + max(dp[i - 1][1], dp[i - 1][2])",
"+ dp[i][1] = abc[i][1] + max(dp[i - 1][0], dp[i - 1][2])",
"+ dp[i][2] = abc[i][2] + max(dp[i - 1][0], dp[i - 1][1])",
"+ print((max(dp[N - 1])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solution()"
] | false | 0.087076 | 0.048644 | 1.790082 |
[
"s422032471",
"s110621538"
] |
u935558307
|
p03546
|
python
|
s455565594
|
s520667565
| 206 | 90 | 41,564 | 74,016 |
Accepted
|
Accepted
| 56.31 |
H,W = list(map(int,input().split()))
dp = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]
"""
各数字から各数字への変更コストの最小値をわーシャルフロイドで計算する
"""
for i in range(10):
for j in range(10):
for k in range(9,-1,-1):
dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])
cost = 0
for i in range(H):
for j in range(W):
default = A[i][j]
if default != -1:
cost += dp[default][1]
print(cost)
|
H,W = list(map(int,input().split()))
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]
dp = [float("INF")]*(10)
dp[1] = 0
cnt = 0
while cnt <= 10:
cnt += 1
for i in range(10):
for j in range(10):
dp[j] = min(dp[j],dp[i]+C[j][i])
cost = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1:
cost += dp[A[i][j]]
print(cost)
| 22 | 19 | 494 | 452 |
H, W = list(map(int, input().split()))
dp = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]
"""
各数字から各数字への変更コストの最小値をわーシャルフロイドで計算する
"""
for i in range(10):
for j in range(10):
for k in range(9, -1, -1):
dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])
cost = 0
for i in range(H):
for j in range(W):
default = A[i][j]
if default != -1:
cost += dp[default][1]
print(cost)
|
H, W = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]
dp = [float("INF")] * (10)
dp[1] = 0
cnt = 0
while cnt <= 10:
cnt += 1
for i in range(10):
for j in range(10):
dp[j] = min(dp[j], dp[i] + C[j][i])
cost = 0
for i in range(H):
for j in range(W):
if A[i][j] != -1:
cost += dp[A[i][j]]
print(cost)
| false | 13.636364 |
[
"-dp = [list(map(int, input().split())) for _ in range(10)]",
"+C = [list(map(int, input().split())) for _ in range(10)]",
"-\"\"\"",
"-各数字から各数字への変更コストの最小値をわーシャルフロイドで計算する",
"-\"\"\"",
"-for i in range(10):",
"- for j in range(10):",
"- for k in range(9, -1, -1):",
"- dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])",
"+dp = [float(\"INF\")] * (10)",
"+dp[1] = 0",
"+cnt = 0",
"+while cnt <= 10:",
"+ cnt += 1",
"+ for i in range(10):",
"+ for j in range(10):",
"+ dp[j] = min(dp[j], dp[i] + C[j][i])",
"- default = A[i][j]",
"- if default != -1:",
"- cost += dp[default][1]",
"+ if A[i][j] != -1:",
"+ cost += dp[A[i][j]]"
] | false | 0.061588 | 0.089049 | 0.691622 |
[
"s455565594",
"s520667565"
] |
u638078488
|
p03478
|
python
|
s314472782
|
s286759658
| 46 | 26 | 3,060 | 3,060 |
Accepted
|
Accepted
| 43.48 |
N, A, B = list(map(int, input().split()))
total = 0
for i in range(1, N + 1, 1):
i_sum = 0
for j in range(len(str(i))):
i_sum += int(str(i)[j])
# print("i_sum", i_sum)
if A <= i_sum and i_sum <= B:
total += i
print(total)
|
N, A, B = list(map(int, input().split()))
total = 0
# 各桁の和を計算する関数
def sumOfDigits(n):
sum = 0
while n > 0:
sum += n % 10
n = n // 10
return sum
for i in range(1, N + 1, 1):
j = sumOfDigits(i)
if A <= j and j <= B:
total += i
print(total)
| 11 | 17 | 258 | 294 |
N, A, B = list(map(int, input().split()))
total = 0
for i in range(1, N + 1, 1):
i_sum = 0
for j in range(len(str(i))):
i_sum += int(str(i)[j])
# print("i_sum", i_sum)
if A <= i_sum and i_sum <= B:
total += i
print(total)
|
N, A, B = list(map(int, input().split()))
total = 0
# 各桁の和を計算する関数
def sumOfDigits(n):
sum = 0
while n > 0:
sum += n % 10
n = n // 10
return sum
for i in range(1, N + 1, 1):
j = sumOfDigits(i)
if A <= j and j <= B:
total += i
print(total)
| false | 35.294118 |
[
"+# 各桁の和を計算する関数",
"+def sumOfDigits(n):",
"+ sum = 0",
"+ while n > 0:",
"+ sum += n % 10",
"+ n = n // 10",
"+ return sum",
"+",
"+",
"- i_sum = 0",
"- for j in range(len(str(i))):",
"- i_sum += int(str(i)[j])",
"- # print(\"i_sum\", i_sum)",
"- if A <= i_sum and i_sum <= B:",
"+ j = sumOfDigits(i)",
"+ if A <= j and j <= B:"
] | false | 0.046583 | 0.045907 | 1.014717 |
[
"s314472782",
"s286759658"
] |
u879870653
|
p03356
|
python
|
s716004793
|
s731668414
| 694 | 467 | 66,164 | 14,388 |
Accepted
|
Accepted
| 32.71 |
from collections import deque
N,M = list(map(int,input().split()))
P = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(M)]
G = [[] for i in range(N)]
for i in range(len(L)) :
u,v = L[i]
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
explored = [0 for i in range(N)]
ans = 0
for i in range(N) :
if explored[i] :
continue
explored[i] = 1
q = deque([i])
A = []
B = []
while q :
now = q.popleft()
A.append(now)
B.append(P[now]-1)
for to in G[now] :
if explored[to] :
continue
q.append(to)
explored[to] = 1
C = set(A) & set(B)
ans += len(C)
print(ans)
|
class UnionFind:
def __init__(self, num):
self.rank = [0] * num
self.par = [i for i in range(num)]
self.n = num
def find_root(self, node):
if self.par[node] == node:
return node
else:
self.par[node] = self.find_root(self.par[node])
return self.par[node]
def same_root(self, x, y):
return self.find_root(x) == self.find_root(y)
def union(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
if self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def main():
N, M = list(map(int,input().split()))
L = list(map(int,input().split()))
UF = UnionFind(N)
for i in range(M) :
A, B = list(map(int,input().split()))
A -= 1
B -= 1
UF.union(A, B)
ans = 0
for i, v in enumerate(L) :
ans += (UF.same_root(i, v-1))
print(ans)
import sys
input = sys.stdin.readline
if __name__ == "__main__":
main()
| 49 | 54 | 834 | 1,229 |
from collections import deque
N, M = list(map(int, input().split()))
P = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(M)]
G = [[] for i in range(N)]
for i in range(len(L)):
u, v = L[i]
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
explored = [0 for i in range(N)]
ans = 0
for i in range(N):
if explored[i]:
continue
explored[i] = 1
q = deque([i])
A = []
B = []
while q:
now = q.popleft()
A.append(now)
B.append(P[now] - 1)
for to in G[now]:
if explored[to]:
continue
q.append(to)
explored[to] = 1
C = set(A) & set(B)
ans += len(C)
print(ans)
|
class UnionFind:
def __init__(self, num):
self.rank = [0] * num
self.par = [i for i in range(num)]
self.n = num
def find_root(self, node):
if self.par[node] == node:
return node
else:
self.par[node] = self.find_root(self.par[node])
return self.par[node]
def same_root(self, x, y):
return self.find_root(x) == self.find_root(y)
def union(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
if self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def main():
N, M = list(map(int, input().split()))
L = list(map(int, input().split()))
UF = UnionFind(N)
for i in range(M):
A, B = list(map(int, input().split()))
A -= 1
B -= 1
UF.union(A, B)
ans = 0
for i, v in enumerate(L):
ans += UF.same_root(i, v - 1)
print(ans)
import sys
input = sys.stdin.readline
if __name__ == "__main__":
main()
| false | 9.259259 |
[
"-from collections import deque",
"+class UnionFind:",
"+ def __init__(self, num):",
"+ self.rank = [0] * num",
"+ self.par = [i for i in range(num)]",
"+ self.n = num",
"-N, M = list(map(int, input().split()))",
"-P = list(map(int, input().split()))",
"-L = [list(map(int, input().split())) for i in range(M)]",
"-G = [[] for i in range(N)]",
"-for i in range(len(L)):",
"- u, v = L[i]",
"- u -= 1",
"- v -= 1",
"- G[u].append(v)",
"- G[v].append(u)",
"-explored = [0 for i in range(N)]",
"-ans = 0",
"-for i in range(N):",
"- if explored[i]:",
"- continue",
"- explored[i] = 1",
"- q = deque([i])",
"- A = []",
"- B = []",
"- while q:",
"- now = q.popleft()",
"- A.append(now)",
"- B.append(P[now] - 1)",
"- for to in G[now]:",
"- if explored[to]:",
"- continue",
"- q.append(to)",
"- explored[to] = 1",
"- C = set(A) & set(B)",
"- ans += len(C)",
"-print(ans)",
"+ def find_root(self, node):",
"+ if self.par[node] == node:",
"+ return node",
"+ else:",
"+ self.par[node] = self.find_root(self.par[node])",
"+ return self.par[node]",
"+",
"+ def same_root(self, x, y):",
"+ return self.find_root(x) == self.find_root(y)",
"+",
"+ def union(self, x, y):",
"+ x = self.find_root(x)",
"+ y = self.find_root(y)",
"+ if x == y:",
"+ return",
"+ if self.rank[x] > self.rank[y]:",
"+ self.par[y] = x",
"+ else:",
"+ self.par[x] = y",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[y] += 1",
"+",
"+",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ L = list(map(int, input().split()))",
"+ UF = UnionFind(N)",
"+ for i in range(M):",
"+ A, B = list(map(int, input().split()))",
"+ A -= 1",
"+ B -= 1",
"+ UF.union(A, B)",
"+ ans = 0",
"+ for i, v in enumerate(L):",
"+ ans += UF.same_root(i, v - 1)",
"+ print(ans)",
"+",
"+",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.040337 | 0.046772 | 0.862408 |
[
"s716004793",
"s731668414"
] |
u169350228
|
p02693
|
python
|
s294527859
|
s570784258
| 103 | 23 | 27,112 | 9,000 |
Accepted
|
Accepted
| 77.67 |
import numpy as np
import math
k = int(eval(input()))
a, b = list(map(int,input().split()))
ans = False
for i in range(a,b+1):
if i%k == 0:
ans = True
break
if ans:
print("OK")
else:
print("NG")
|
k = int(eval(input()))
a, b = list(map(int,input().split()))
for i in range(a,b+1):
if i%k == 0:
print("OK")
exit()
print("NG")
| 14 | 9 | 224 | 146 |
import numpy as np
import math
k = int(eval(input()))
a, b = list(map(int, input().split()))
ans = False
for i in range(a, b + 1):
if i % k == 0:
ans = True
break
if ans:
print("OK")
else:
print("NG")
|
k = int(eval(input()))
a, b = list(map(int, input().split()))
for i in range(a, b + 1):
if i % k == 0:
print("OK")
exit()
print("NG")
| false | 35.714286 |
[
"-import numpy as np",
"-import math",
"-",
"-ans = False",
"- ans = True",
"- break",
"-if ans:",
"- print(\"OK\")",
"-else:",
"- print(\"NG\")",
"+ print(\"OK\")",
"+ exit()",
"+print(\"NG\")"
] | false | 0.159821 | 0.068397 | 2.336658 |
[
"s294527859",
"s570784258"
] |
u332906195
|
p03502
|
python
|
s870332651
|
s734160415
| 175 | 21 | 38,256 | 3,316 |
Accepted
|
Accepted
| 88 |
N = eval(input())
sumN = sum([int(n) for n in N])
print(("Yes" if int(N) % sumN == 0 else "No"))
|
N = eval(input())
print(("Yes" if int(N) % sum([int(n) for n in N]) == 0 else "No"))
| 4 | 2 | 93 | 78 |
N = eval(input())
sumN = sum([int(n) for n in N])
print(("Yes" if int(N) % sumN == 0 else "No"))
|
N = eval(input())
print(("Yes" if int(N) % sum([int(n) for n in N]) == 0 else "No"))
| false | 50 |
[
"-sumN = sum([int(n) for n in N])",
"-print((\"Yes\" if int(N) % sumN == 0 else \"No\"))",
"+print((\"Yes\" if int(N) % sum([int(n) for n in N]) == 0 else \"No\"))"
] | false | 0.007516 | 0.035336 | 0.212713 |
[
"s870332651",
"s734160415"
] |
u888092736
|
p02678
|
python
|
s477089329
|
s305333199
| 739 | 678 | 72,768 | 74,908 |
Accepted
|
Accepted
| 8.25 |
from collections import deque, defaultdict
import sys
def input():
return sys.stdin.readline().strip()
N, M = map(int, input().split())
graph = defaultdict(set)
for _ in range(M):
A, B = map(lambda x: int(x) - 1, input().split())
graph[A].add(B)
graph[B].add(A)
if len(set(graph.keys())) != N:
print('No')
exit()
tokens = [-1] * N
tokens[0] = N
q = deque([0])
while q:
v = q.popleft()
for nv in graph[v]:
if tokens[nv] < 0:
tokens[nv] = v
q.append(nv)
print('Yes')
[print(t + 1) for t in tokens[1:]]
|
from collections import deque, defaultdict
import sys
def input():
return sys.stdin.readline().strip()
N, M = list(map(int, input().split()))
graph = defaultdict(set)
for _ in range(M):
A, B = [int(x) - 1 for x in input().split()]
graph[A].add(B)
graph[B].add(A)
tokens = [-1] * N
tokens[0] = N
q = deque([0])
while q:
v = q.popleft()
for nv in graph[v]:
if tokens[nv] < 0:
tokens[nv] = v
q.append(nv)
if -1 in tokens[1:]:
print('No')
else:
print('Yes')
print(('\n'.join([str(x + 1) for x in tokens[1:]])))
| 30 | 30 | 599 | 612 |
from collections import deque, defaultdict
import sys
def input():
return sys.stdin.readline().strip()
N, M = map(int, input().split())
graph = defaultdict(set)
for _ in range(M):
A, B = map(lambda x: int(x) - 1, input().split())
graph[A].add(B)
graph[B].add(A)
if len(set(graph.keys())) != N:
print("No")
exit()
tokens = [-1] * N
tokens[0] = N
q = deque([0])
while q:
v = q.popleft()
for nv in graph[v]:
if tokens[nv] < 0:
tokens[nv] = v
q.append(nv)
print("Yes")
[print(t + 1) for t in tokens[1:]]
|
from collections import deque, defaultdict
import sys
def input():
return sys.stdin.readline().strip()
N, M = list(map(int, input().split()))
graph = defaultdict(set)
for _ in range(M):
A, B = [int(x) - 1 for x in input().split()]
graph[A].add(B)
graph[B].add(A)
tokens = [-1] * N
tokens[0] = N
q = deque([0])
while q:
v = q.popleft()
for nv in graph[v]:
if tokens[nv] < 0:
tokens[nv] = v
q.append(nv)
if -1 in tokens[1:]:
print("No")
else:
print("Yes")
print(("\n".join([str(x + 1) for x in tokens[1:]])))
| false | 0 |
[
"-N, M = map(int, input().split())",
"+N, M = list(map(int, input().split()))",
"- A, B = map(lambda x: int(x) - 1, input().split())",
"+ A, B = [int(x) - 1 for x in input().split()]",
"-if len(set(graph.keys())) != N:",
"- print(\"No\")",
"- exit()",
"-print(\"Yes\")",
"-[print(t + 1) for t in tokens[1:]]",
"+if -1 in tokens[1:]:",
"+ print(\"No\")",
"+else:",
"+ print(\"Yes\")",
"+ print((\"\\n\".join([str(x + 1) for x in tokens[1:]])))"
] | false | 0.047162 | 0.049836 | 0.946335 |
[
"s477089329",
"s305333199"
] |
u984276646
|
p02600
|
python
|
s815765028
|
s816210332
| 34 | 30 | 9,148 | 9,124 |
Accepted
|
Accepted
| 11.76 |
X = int(eval(input()))
print((8-(X-400)//200))
|
print((8-(int(eval(input()))-400)//200))
| 2 | 1 | 39 | 32 |
X = int(eval(input()))
print((8 - (X - 400) // 200))
|
print((8 - (int(eval(input())) - 400) // 200))
| false | 50 |
[
"-X = int(eval(input()))",
"-print((8 - (X - 400) // 200))",
"+print((8 - (int(eval(input())) - 400) // 200))"
] | false | 0.042985 | 0.071517 | 0.601041 |
[
"s815765028",
"s816210332"
] |
u309120194
|
p03059
|
python
|
s052988646
|
s496380430
| 36 | 26 | 9,080 | 8,752 |
Accepted
|
Accepted
| 27.78 |
A, B, T = list(map(int, input().split()))
print((int((T+0.5)//A) * B))
|
A, B, T = list(map(int, input().split()))
print((T // A * B))
| 3 | 3 | 66 | 57 |
A, B, T = list(map(int, input().split()))
print((int((T + 0.5) // A) * B))
|
A, B, T = list(map(int, input().split()))
print((T // A * B))
| false | 0 |
[
"-print((int((T + 0.5) // A) * B))",
"+print((T // A * B))"
] | false | 0.034965 | 0.034433 | 1.015442 |
[
"s052988646",
"s496380430"
] |
u730769327
|
p03112
|
python
|
s600842907
|
s606427553
| 972 | 894 | 100,476 | 97,488 |
Accepted
|
Accepted
| 8.02 |
import bisect
INF=10**11
A,B,q=list(map(int,input().split()))
a=[-INF]+[int(eval(input())) for _ in range(A)]+[INF]
b=[-INF]+[int(eval(input())) for _ in range(B)]+[INF]
for _ in range(q):
x=int(eval(input()))
i=bisect.bisect_left(a,x)
j=bisect.bisect_left(b,x)
ans=min(max(a[i],b[j])-x,x-min(a[i-1],b[j-1]),a[i]-b[j-1]+min(a[i]-x,x-b[j-1]),b[j]-a[i-1]+min(b[j]-x,x-a[i-1]))
print(ans)
|
from bisect import*
a,b,q=list(map(int,input().split()))
s=[-10**18]+[int(eval(input())) for _ in range(a)]+[10**18]
t=[-10**18]+[int(eval(input())) for _ in range(b)]+[10**18]
for _ in range(q):
i=int(eval(input()))
si=bisect_left(s,i)
ti=bisect_left(t,i)
print((min(max(s[si],t[ti])-i,i-min(t[ti-1],s[si-1]),
2*t[ti]-s[si-1]-i,2*s[si]-t[ti-1]-i,
i+t[ti]-2*s[si-1],i+s[si]-2*t[ti-1])))
| 11 | 11 | 381 | 402 |
import bisect
INF = 10**11
A, B, q = list(map(int, input().split()))
a = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
b = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for _ in range(q):
x = int(eval(input()))
i = bisect.bisect_left(a, x)
j = bisect.bisect_left(b, x)
ans = min(
max(a[i], b[j]) - x,
x - min(a[i - 1], b[j - 1]),
a[i] - b[j - 1] + min(a[i] - x, x - b[j - 1]),
b[j] - a[i - 1] + min(b[j] - x, x - a[i - 1]),
)
print(ans)
|
from bisect import *
a, b, q = list(map(int, input().split()))
s = [-(10**18)] + [int(eval(input())) for _ in range(a)] + [10**18]
t = [-(10**18)] + [int(eval(input())) for _ in range(b)] + [10**18]
for _ in range(q):
i = int(eval(input()))
si = bisect_left(s, i)
ti = bisect_left(t, i)
print(
(
min(
max(s[si], t[ti]) - i,
i - min(t[ti - 1], s[si - 1]),
2 * t[ti] - s[si - 1] - i,
2 * s[si] - t[ti - 1] - i,
i + t[ti] - 2 * s[si - 1],
i + s[si] - 2 * t[ti - 1],
)
)
)
| false | 0 |
[
"-import bisect",
"+from bisect import *",
"-INF = 10**11",
"-A, B, q = list(map(int, input().split()))",
"-a = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]",
"-b = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]",
"+a, b, q = list(map(int, input().split()))",
"+s = [-(10**18)] + [int(eval(input())) for _ in range(a)] + [10**18]",
"+t = [-(10**18)] + [int(eval(input())) for _ in range(b)] + [10**18]",
"- x = int(eval(input()))",
"- i = bisect.bisect_left(a, x)",
"- j = bisect.bisect_left(b, x)",
"- ans = min(",
"- max(a[i], b[j]) - x,",
"- x - min(a[i - 1], b[j - 1]),",
"- a[i] - b[j - 1] + min(a[i] - x, x - b[j - 1]),",
"- b[j] - a[i - 1] + min(b[j] - x, x - a[i - 1]),",
"+ i = int(eval(input()))",
"+ si = bisect_left(s, i)",
"+ ti = bisect_left(t, i)",
"+ print(",
"+ (",
"+ min(",
"+ max(s[si], t[ti]) - i,",
"+ i - min(t[ti - 1], s[si - 1]),",
"+ 2 * t[ti] - s[si - 1] - i,",
"+ 2 * s[si] - t[ti - 1] - i,",
"+ i + t[ti] - 2 * s[si - 1],",
"+ i + s[si] - 2 * t[ti - 1],",
"+ )",
"+ )",
"- print(ans)"
] | false | 0.053531 | 0.144281 | 0.371018 |
[
"s600842907",
"s606427553"
] |
u734519000
|
p03112
|
python
|
s916165488
|
s352135029
| 1,821 | 1,216 | 12,080 | 16,244 |
Accepted
|
Accepted
| 33.22 |
import bisect as bi
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
for i in range(q):
c = []
d = []
x = int(eval(input()))
tmp = bi.bisect_left(s, x)
if tmp != a : c.append(s[tmp])
if tmp != 0 : c.append(s[tmp-1])
tmp = bi.bisect_left(t, x)
if tmp != b : d.append(t[tmp])
if tmp != 0 : d.append(t[tmp-1])
ans = 2**64
for e in c:
for f in d:
g = abs(x-e)
h = abs(x-f)
if (x-e)*(x-f) > 0:
ans = min(ans, max(g, h))
else:
if g > h : g,h = h,g
ans = min(ans, 2*g+h)
print(ans)
|
import bisect as bi
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
u = [int(eval(input())) for i in range(q)]
for x in u:
c = []
d = []
tmp = bi.bisect_left(s, x)
if tmp != a : c.append(s[tmp])
if tmp != 0 : c.append(s[tmp-1])
tmp = bi.bisect_left(t, x)
if tmp != b : d.append(t[tmp])
if tmp != 0 : d.append(t[tmp-1])
ans = 2**64
for e in c:
for f in d:
g = abs(x-e)
h = abs(x-f)
if (x-e)*(x-f) > 0:
ans = min(ans, max(g, h))
else:
if g > h : g,h = h,g
ans = min(ans, 2*g+h)
print(ans)
| 25 | 26 | 705 | 717 |
import bisect as bi
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
for i in range(q):
c = []
d = []
x = int(eval(input()))
tmp = bi.bisect_left(s, x)
if tmp != a:
c.append(s[tmp])
if tmp != 0:
c.append(s[tmp - 1])
tmp = bi.bisect_left(t, x)
if tmp != b:
d.append(t[tmp])
if tmp != 0:
d.append(t[tmp - 1])
ans = 2**64
for e in c:
for f in d:
g = abs(x - e)
h = abs(x - f)
if (x - e) * (x - f) > 0:
ans = min(ans, max(g, h))
else:
if g > h:
g, h = h, g
ans = min(ans, 2 * g + h)
print(ans)
|
import bisect as bi
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
u = [int(eval(input())) for i in range(q)]
for x in u:
c = []
d = []
tmp = bi.bisect_left(s, x)
if tmp != a:
c.append(s[tmp])
if tmp != 0:
c.append(s[tmp - 1])
tmp = bi.bisect_left(t, x)
if tmp != b:
d.append(t[tmp])
if tmp != 0:
d.append(t[tmp - 1])
ans = 2**64
for e in c:
for f in d:
g = abs(x - e)
h = abs(x - f)
if (x - e) * (x - f) > 0:
ans = min(ans, max(g, h))
else:
if g > h:
g, h = h, g
ans = min(ans, 2 * g + h)
print(ans)
| false | 3.846154 |
[
"-for i in range(q):",
"+u = [int(eval(input())) for i in range(q)]",
"+for x in u:",
"- x = int(eval(input()))"
] | false | 0.122453 | 0.104731 | 1.169208 |
[
"s916165488",
"s352135029"
] |
u024890678
|
p02712
|
python
|
s771500594
|
s499978573
| 205 | 159 | 9,036 | 9,164 |
Accepted
|
Accepted
| 22.44 |
n = int(eval(input()))
ans = 0
for i in range(1, n+1):
if i%15 == 0 or i%5 == 0 or i%3 ==0:
continue
else:
ans += i
print(ans)
|
n = int(eval(input()))
ans = 0
for i in range(1, n+1):
if i%5 == 0 or i%3 ==0:
continue
else:
ans += i
print(ans)
| 10 | 10 | 143 | 130 |
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if i % 15 == 0 or i % 5 == 0 or i % 3 == 0:
continue
else:
ans += i
print(ans)
|
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if i % 5 == 0 or i % 3 == 0:
continue
else:
ans += i
print(ans)
| false | 0 |
[
"- if i % 15 == 0 or i % 5 == 0 or i % 3 == 0:",
"+ if i % 5 == 0 or i % 3 == 0:"
] | false | 0.255278 | 0.384629 | 0.663699 |
[
"s771500594",
"s499978573"
] |
u968166680
|
p03003
|
python
|
s241258778
|
s532047704
| 179 | 119 | 134,172 | 74,160 |
Accepted
|
Accepted
| 33.52 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M = list(map(int, readline().split()))
S = list(map(int, readline().split()))
T = list(map(int, readline().split()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
for i in range(N + 1):
sdp[i][0] = 1
for j in range(M + 1):
sdp[0][j] = 1
for i in range(N):
for j in range(M):
if S[i] == T[j]:
dp[i + 1][j + 1] = sdp[i][j]
sdp[i + 1][j + 1] = (sdp[i][j + 1] + sdp[i + 1][j] - sdp[i][j] + dp[i + 1][j + 1]) % MOD
print((sdp[N][M]))
return
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M = list(map(int, readline().split()))
S = list(map(int, readline().split()))
T = list(map(int, readline().split()))
dp = [1] * (M + 1)
for i in range(N):
dp_prev = dp[:]
for j in range(M):
if S[i] == T[j]:
dp[j + 1] = (dp_prev[j + 1] + dp[j]) % MOD
else:
dp[j + 1] = (dp_prev[j + 1] + dp[j] - dp_prev[j]) % MOD
print((dp[M]))
return
if __name__ == '__main__':
main()
| 36 | 31 | 844 | 674 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M = list(map(int, readline().split()))
S = list(map(int, readline().split()))
T = list(map(int, readline().split()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
for i in range(N + 1):
sdp[i][0] = 1
for j in range(M + 1):
sdp[0][j] = 1
for i in range(N):
for j in range(M):
if S[i] == T[j]:
dp[i + 1][j + 1] = sdp[i][j]
sdp[i + 1][j + 1] = (
sdp[i][j + 1] + sdp[i + 1][j] - sdp[i][j] + dp[i + 1][j + 1]
) % MOD
print((sdp[N][M]))
return
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M = list(map(int, readline().split()))
S = list(map(int, readline().split()))
T = list(map(int, readline().split()))
dp = [1] * (M + 1)
for i in range(N):
dp_prev = dp[:]
for j in range(M):
if S[i] == T[j]:
dp[j + 1] = (dp_prev[j + 1] + dp[j]) % MOD
else:
dp[j + 1] = (dp_prev[j + 1] + dp[j] - dp_prev[j]) % MOD
print((dp[M]))
return
if __name__ == "__main__":
main()
| false | 13.888889 |
[
"- dp = [[0] * (M + 1) for _ in range(N + 1)]",
"- sdp = [[0] * (M + 2) for _ in range(N + 2)]",
"- dp[0][0] = 1",
"- for i in range(N + 1):",
"- sdp[i][0] = 1",
"- for j in range(M + 1):",
"- sdp[0][j] = 1",
"+ dp = [1] * (M + 1)",
"+ dp_prev = dp[:]",
"- dp[i + 1][j + 1] = sdp[i][j]",
"- sdp[i + 1][j + 1] = (",
"- sdp[i][j + 1] + sdp[i + 1][j] - sdp[i][j] + dp[i + 1][j + 1]",
"- ) % MOD",
"- print((sdp[N][M]))",
"+ dp[j + 1] = (dp_prev[j + 1] + dp[j]) % MOD",
"+ else:",
"+ dp[j + 1] = (dp_prev[j + 1] + dp[j] - dp_prev[j]) % MOD",
"+ print((dp[M]))"
] | false | 0.046869 | 0.042029 | 1.115135 |
[
"s241258778",
"s532047704"
] |
u103902792
|
p02813
|
python
|
s466698892
|
s803943093
| 190 | 142 | 44,912 | 13,884 |
Accepted
|
Accepted
| 25.26 |
n = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
from itertools import permutations
lst = list(permutations(list(range(1,n+1))))
lst.sort()
print((abs(lst.index(P) - lst.index(Q))))
|
n = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
queue = [[]]
lst = []
while queue:
e = queue.pop(-1)
if len(e) == n:
lst.append(tuple(e))
continue
for i in range(1,n+1):
if i not in e:
queue.append(e+[i])
lst.sort()
print((abs(lst.index(P) - lst.index(Q))))
| 10 | 20 | 226 | 345 |
n = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
from itertools import permutations
lst = list(permutations(list(range(1, n + 1))))
lst.sort()
print((abs(lst.index(P) - lst.index(Q))))
|
n = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
queue = [[]]
lst = []
while queue:
e = queue.pop(-1)
if len(e) == n:
lst.append(tuple(e))
continue
for i in range(1, n + 1):
if i not in e:
queue.append(e + [i])
lst.sort()
print((abs(lst.index(P) - lst.index(Q))))
| false | 50 |
[
"-from itertools import permutations",
"-",
"-lst = list(permutations(list(range(1, n + 1))))",
"+queue = [[]]",
"+lst = []",
"+while queue:",
"+ e = queue.pop(-1)",
"+ if len(e) == n:",
"+ lst.append(tuple(e))",
"+ continue",
"+ for i in range(1, n + 1):",
"+ if i not in e:",
"+ queue.append(e + [i])"
] | false | 0.039319 | 0.039832 | 0.987119 |
[
"s466698892",
"s803943093"
] |
u707124227
|
p02995
|
python
|
s444384655
|
s881723263
| 39 | 35 | 5,048 | 5,048 |
Accepted
|
Accepted
| 10.26 |
import fractions
a,b,c,d=list(map(int,input().split()))
base=b-a+1
n_c=b//c-(a+c-1)//c+1
n_d=b//d-(a+d-1)//d+1
cd=c*d // fractions.gcd(c,d)
n_cd=b//cd-(a+cd-1)//cd+1
print((base-n_c-n_d+n_cd))
|
import fractions
a,b,c,d=list(map(int,input().split()))
nc=b//c-(a+c-1)//c+1
nd=b//d-(a+d-1)//d+1
cd=c*d//fractions.gcd(c,d)
ncd=b//cd-(a+cd-1)//cd+1
print((b-a+1-(nc+nd-ncd)))
# math.ceil(a/b)->(a+b-1)//b
| 8 | 9 | 192 | 206 |
import fractions
a, b, c, d = list(map(int, input().split()))
base = b - a + 1
n_c = b // c - (a + c - 1) // c + 1
n_d = b // d - (a + d - 1) // d + 1
cd = c * d // fractions.gcd(c, d)
n_cd = b // cd - (a + cd - 1) // cd + 1
print((base - n_c - n_d + n_cd))
|
import fractions
a, b, c, d = list(map(int, input().split()))
nc = b // c - (a + c - 1) // c + 1
nd = b // d - (a + d - 1) // d + 1
cd = c * d // fractions.gcd(c, d)
ncd = b // cd - (a + cd - 1) // cd + 1
print((b - a + 1 - (nc + nd - ncd)))
# math.ceil(a/b)->(a+b-1)//b
| false | 11.111111 |
[
"-base = b - a + 1",
"-n_c = b // c - (a + c - 1) // c + 1",
"-n_d = b // d - (a + d - 1) // d + 1",
"+nc = b // c - (a + c - 1) // c + 1",
"+nd = b // d - (a + d - 1) // d + 1",
"-n_cd = b // cd - (a + cd - 1) // cd + 1",
"-print((base - n_c - n_d + n_cd))",
"+ncd = b // cd - (a + cd - 1) // cd + 1",
"+print((b - a + 1 - (nc + nd - ncd)))",
"+# math.ceil(a/b)->(a+b-1)//b"
] | false | 0.054931 | 0.053775 | 1.021495 |
[
"s444384655",
"s881723263"
] |
u227020436
|
p02696
|
python
|
s792406869
|
s173520193
| 24 | 21 | 9,156 | 9,152 |
Accepted
|
Accepted
| 12.5 |
# D - Floor Function
a, b, n = list(map(int, input().split()))
# max(floor(a * x / b) - a * floor(x / b) for 0 <= x <= n)
# x = k * b のとき, 第1項 == 第2項
# k * b <= x < (k+1) * b のとき, 第1項は単調増加, 第2項は一定
x = min(n, b - 1)
print((a * x // b - a * (x // b)))
|
# D - Floor Function
a, b, n = list(map(int, input().split()))
# max(floor(a * x / b) - a * floor(x / b) for 0 <= x <= n)
# x = k * b のとき, 第1項 == 第2項
# k * b <= x < (k+1) * b のとき, 第1項は単調増加, 第2項は一定
x = min(n, b - 1)
print((a * x // b))
| 10 | 10 | 254 | 239 |
# D - Floor Function
a, b, n = list(map(int, input().split()))
# max(floor(a * x / b) - a * floor(x / b) for 0 <= x <= n)
# x = k * b のとき, 第1項 == 第2項
# k * b <= x < (k+1) * b のとき, 第1項は単調増加, 第2項は一定
x = min(n, b - 1)
print((a * x // b - a * (x // b)))
|
# D - Floor Function
a, b, n = list(map(int, input().split()))
# max(floor(a * x / b) - a * floor(x / b) for 0 <= x <= n)
# x = k * b のとき, 第1項 == 第2項
# k * b <= x < (k+1) * b のとき, 第1項は単調増加, 第2項は一定
x = min(n, b - 1)
print((a * x // b))
| false | 0 |
[
"-print((a * x // b - a * (x // b)))",
"+print((a * x // b))"
] | false | 0.038982 | 0.037833 | 1.030377 |
[
"s792406869",
"s173520193"
] |
u312025627
|
p02971
|
python
|
s263718149
|
s799083154
| 483 | 311 | 14,076 | 92,872 |
Accepted
|
Accepted
| 35.61 |
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a_max = max(a)
b = a.copy()
b.remove(a_max)
a_max_second = max(b)
for a_i in a:
if a_i != a_max:
print(a_max)
else:
print(a_max_second)
|
def main():
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
L = [0]*(N+1)
for i, a in enumerate(A, start=1):
L[i] = max(L[i-1], a)
R = [0]*(N+2)
for i in range(N)[::-1]:
R[i] = max(R[i+1], A[i])
for i in range(N):
print((max(L[i], R[i+1])))
if __name__ == '__main__':
main()
| 14 | 17 | 229 | 355 |
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a_max = max(a)
b = a.copy()
b.remove(a_max)
a_max_second = max(b)
for a_i in a:
if a_i != a_max:
print(a_max)
else:
print(a_max_second)
|
def main():
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
L = [0] * (N + 1)
for i, a in enumerate(A, start=1):
L[i] = max(L[i - 1], a)
R = [0] * (N + 2)
for i in range(N)[::-1]:
R[i] = max(R[i + 1], A[i])
for i in range(N):
print((max(L[i], R[i + 1])))
if __name__ == "__main__":
main()
| false | 17.647059 |
[
"-n = int(eval(input()))",
"-a = [int(eval(input())) for i in range(n)]",
"-a_max = max(a)",
"-b = a.copy()",
"-b.remove(a_max)",
"-a_max_second = max(b)",
"-for a_i in a:",
"- if a_i != a_max:",
"- print(a_max)",
"- else:",
"- print(a_max_second)",
"+def main():",
"+ N = int(eval(input()))",
"+ A = [int(eval(input())) for i in range(N)]",
"+ L = [0] * (N + 1)",
"+ for i, a in enumerate(A, start=1):",
"+ L[i] = max(L[i - 1], a)",
"+ R = [0] * (N + 2)",
"+ for i in range(N)[::-1]:",
"+ R[i] = max(R[i + 1], A[i])",
"+ for i in range(N):",
"+ print((max(L[i], R[i + 1])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.040505 | 0.092844 | 0.436266 |
[
"s263718149",
"s799083154"
] |
u278955646
|
p02881
|
python
|
s309089849
|
s787929248
| 153 | 128 | 3,060 | 3,060 |
Accepted
|
Accepted
| 16.34 |
import math
N = int(eval(input()))
answer = N + 1
for a in range(1, math.floor(math.sqrt(N)) + 1):
if N % a == 0:
answer = min(answer, int(a + N / a) - 2)
print(answer)
|
import math
N = int(eval(input()))
print((min([a + N // a - 2 for a in range(math.floor(math.sqrt(N)) + 1, 0, -1) if N % a == 0])))
| 9 | 3 | 185 | 126 |
import math
N = int(eval(input()))
answer = N + 1
for a in range(1, math.floor(math.sqrt(N)) + 1):
if N % a == 0:
answer = min(answer, int(a + N / a) - 2)
print(answer)
|
import math
N = int(eval(input()))
print(
(
min(
[
a + N // a - 2
for a in range(math.floor(math.sqrt(N)) + 1, 0, -1)
if N % a == 0
]
)
)
)
| false | 66.666667 |
[
"-answer = N + 1",
"-for a in range(1, math.floor(math.sqrt(N)) + 1):",
"- if N % a == 0:",
"- answer = min(answer, int(a + N / a) - 2)",
"-print(answer)",
"+print(",
"+ (",
"+ min(",
"+ [",
"+ a + N // a - 2",
"+ for a in range(math.floor(math.sqrt(N)) + 1, 0, -1)",
"+ if N % a == 0",
"+ ]",
"+ )",
"+ )",
"+)"
] | false | 0.03876 | 0.037083 | 1.045216 |
[
"s309089849",
"s787929248"
] |
u025501820
|
p02660
|
python
|
s889477124
|
s128580961
| 251 | 178 | 9,500 | 9,496 |
Accepted
|
Accepted
| 29.08 |
import sys
N = int(sys.stdin.readline().rstrip())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
def prime_judge(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a = set(a)
if len(a) == 1:
return True
else:
return False
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a = set(a)
if len(a) == 1 and prime_judge(list(a)[0]):
return True
else:
return False
divisors = make_divisors(N)
ans = 0
for d in divisors:
if prime_factorize(d) and N % d == 0 and N // d > 0:
N //= d
ans += 1
print(ans)
|
import sys
N = int(sys.stdin.readline().rstrip())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a = set(a)
if len(a) == 1:
return True
else:
return False
divisors = make_divisors(N)
ans = 0
for d in divisors:
if prime_factorize(d) and N % d == 0:
N //= d
ans += 1
print(ans)
| 60 | 40 | 1,235 | 820 |
import sys
N = int(sys.stdin.readline().rstrip())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
def prime_judge(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a = set(a)
if len(a) == 1:
return True
else:
return False
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a = set(a)
if len(a) == 1 and prime_judge(list(a)[0]):
return True
else:
return False
divisors = make_divisors(N)
ans = 0
for d in divisors:
if prime_factorize(d) and N % d == 0 and N // d > 0:
N //= d
ans += 1
print(ans)
|
import sys
N = int(sys.stdin.readline().rstrip())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a = set(a)
if len(a) == 1:
return True
else:
return False
divisors = make_divisors(N)
ans = 0
for d in divisors:
if prime_factorize(d) and N % d == 0:
N //= d
ans += 1
print(ans)
| false | 33.333333 |
[
"-def prime_judge(n):",
"+def prime_factorize(n):",
"-def prime_factorize(n):",
"- a = []",
"- while n % 2 == 0:",
"- a.append(2)",
"- n //= 2",
"- f = 3",
"- while f * f <= n:",
"- if n % f == 0:",
"- a.append(f)",
"- n //= f",
"- else:",
"- f += 2",
"- if n != 1:",
"- a.append(n)",
"- a = set(a)",
"- if len(a) == 1 and prime_judge(list(a)[0]):",
"- return True",
"- else:",
"- return False",
"-",
"-",
"- if prime_factorize(d) and N % d == 0 and N // d > 0:",
"+ if prime_factorize(d) and N % d == 0:"
] | false | 0.0745 | 0.063597 | 1.171431 |
[
"s889477124",
"s128580961"
] |
u241159583
|
p03696
|
python
|
s226475887
|
s452965270
| 30 | 25 | 9,040 | 9,080 |
Accepted
|
Accepted
| 16.67 |
n = int(eval(input()))
s = eval(input())
ans = s
while s.count("()")>0:
s = s.replace("()", "")
cnt_l = s.count(")")
cnt_r = s.count("(")
ans = cnt_l * "(" + ans
ans += cnt_r * ")"
print(ans)
|
n = int(eval(input()))
s = eval(input())
ans = s
while s.count("()")>0:
s = s.replace("()", "")
cnt_l = s.count(")")
cnt_r = s.count("(")
print((cnt_l * "(" + ans + cnt_r * ")"))
| 10 | 8 | 192 | 175 |
n = int(eval(input()))
s = eval(input())
ans = s
while s.count("()") > 0:
s = s.replace("()", "")
cnt_l = s.count(")")
cnt_r = s.count("(")
ans = cnt_l * "(" + ans
ans += cnt_r * ")"
print(ans)
|
n = int(eval(input()))
s = eval(input())
ans = s
while s.count("()") > 0:
s = s.replace("()", "")
cnt_l = s.count(")")
cnt_r = s.count("(")
print((cnt_l * "(" + ans + cnt_r * ")"))
| false | 20 |
[
"-ans = cnt_l * \"(\" + ans",
"-ans += cnt_r * \")\"",
"-print(ans)",
"+print((cnt_l * \"(\" + ans + cnt_r * \")\"))"
] | false | 0.049548 | 0.126871 | 0.390536 |
[
"s226475887",
"s452965270"
] |
u703528810
|
p02732
|
python
|
s804677194
|
s139760845
| 473 | 418 | 24,748 | 26,268 |
Accepted
|
Accepted
| 11.63 |
N=int(eval(input()))
A=list(map(int,input().split()))
A1=sorted(A)
cnt=[0 for _ in range(N+1)] #cnt_table[i]: 数字iの要素の個数
for i in range(N):
cnt[A[i]]+=1
cmb=[cnt[k]*(cnt[k]-1)//2 for k in range(N+1)]
SUM=sum(cmb)
for j in range(N):
n=A[j]
v=cnt[A[j]]
print((SUM-cmb[n]+(v-1)*(v-2)//2))
|
N=int(eval(input()))
A=list(map(int,input().split()))
cnt=[0 for _ in range(N+1)]
for i in range(N):
cnt[A[i]]+=1
cmb=[cnt[k]*(cnt[k]-1)//2 for k in range(N+1)]
SUM=sum(cmb)
for j in range(N):
n=A[j]
v=cnt[A[j]]
print((SUM-cmb[n]+(v-1)*(v-2)//2))
| 15 | 11 | 310 | 264 |
N = int(eval(input()))
A = list(map(int, input().split()))
A1 = sorted(A)
cnt = [0 for _ in range(N + 1)] # cnt_table[i]: 数字iの要素の個数
for i in range(N):
cnt[A[i]] += 1
cmb = [cnt[k] * (cnt[k] - 1) // 2 for k in range(N + 1)]
SUM = sum(cmb)
for j in range(N):
n = A[j]
v = cnt[A[j]]
print((SUM - cmb[n] + (v - 1) * (v - 2) // 2))
|
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = [0 for _ in range(N + 1)]
for i in range(N):
cnt[A[i]] += 1
cmb = [cnt[k] * (cnt[k] - 1) // 2 for k in range(N + 1)]
SUM = sum(cmb)
for j in range(N):
n = A[j]
v = cnt[A[j]]
print((SUM - cmb[n] + (v - 1) * (v - 2) // 2))
| false | 26.666667 |
[
"-A1 = sorted(A)",
"-cnt = [0 for _ in range(N + 1)] # cnt_table[i]: 数字iの要素の個数",
"+cnt = [0 for _ in range(N + 1)]"
] | false | 0.03452 | 0.036343 | 0.949823 |
[
"s804677194",
"s139760845"
] |
u979444096
|
p02773
|
python
|
s610831481
|
s244766788
| 717 | 662 | 49,204 | 45,076 |
Accepted
|
Accepted
| 7.67 |
from collections import Counter
def main():
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
C = Counter(A)
most_c = C.most_common()
max_num = most_c[0][1]
ANS = []
for c in most_c:
if c[1] < max_num:
break
ANS.append(c[0])
for ans in sorted(ANS):
print(ans)
if __name__ == '__main__':
main()
|
from collections import Counter
def main():
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
c = Counter(A)
max_num = c.most_common()[0][1]
ANS = [i[0] for i in list(c.items()) if i[1] == max_num]
ANS.sort()
for ans in ANS:
print(ans)
if __name__ == '__main__':
main()
| 21 | 17 | 390 | 324 |
from collections import Counter
def main():
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
C = Counter(A)
most_c = C.most_common()
max_num = most_c[0][1]
ANS = []
for c in most_c:
if c[1] < max_num:
break
ANS.append(c[0])
for ans in sorted(ANS):
print(ans)
if __name__ == "__main__":
main()
|
from collections import Counter
def main():
N = int(eval(input()))
A = [eval(input()) for _ in range(N)]
c = Counter(A)
max_num = c.most_common()[0][1]
ANS = [i[0] for i in list(c.items()) if i[1] == max_num]
ANS.sort()
for ans in ANS:
print(ans)
if __name__ == "__main__":
main()
| false | 19.047619 |
[
"- C = Counter(A)",
"- most_c = C.most_common()",
"- max_num = most_c[0][1]",
"- ANS = []",
"- for c in most_c:",
"- if c[1] < max_num:",
"- break",
"- ANS.append(c[0])",
"- for ans in sorted(ANS):",
"+ c = Counter(A)",
"+ max_num = c.most_common()[0][1]",
"+ ANS = [i[0] for i in list(c.items()) if i[1] == max_num]",
"+ ANS.sort()",
"+ for ans in ANS:"
] | false | 0.075411 | 0.047092 | 1.601361 |
[
"s610831481",
"s244766788"
] |
u476124554
|
p03160
|
python
|
s533375060
|
s396739799
| 166 | 132 | 13,928 | 14,036 |
Accepted
|
Accepted
| 20.48 |
n = int(eval(input()))
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(1,n):
dp[i] = min(dp[i],dp[i-1] + abs(h[i] - h[i-1]))
if i >= 2:
dp[i] = min(dp[i],dp[i-2] + abs(h[i] - h[i-2]))
print((dp[-1]))
|
n = int(eval(input()))
h = list(map(int,input().split()))
dp = [10 ** 5 for i in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(n-2):
dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+1] + abs(h[i+2] - h[i+1]))
print((dp[-1]))
| 13 | 9 | 284 | 241 |
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(1, n):
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i >= 2:
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[-1]))
|
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [10**5 for i in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(n - 2):
dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]))
print((dp[-1]))
| false | 30.769231 |
[
"-dp = [float(\"inf\")] * n",
"+dp = [10**5 for i in range(n)]",
"-for i in range(1, n):",
"- dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))",
"- if i >= 2:",
"- dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))",
"+for i in range(n - 2):",
"+ dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]))"
] | false | 0.042317 | 0.099941 | 0.423419 |
[
"s533375060",
"s396739799"
] |
u278886389
|
p03608
|
python
|
s544418243
|
s720372785
| 448 | 409 | 8,304 | 8,336 |
Accepted
|
Accepted
| 8.71 |
INF = float('inf')
N,M,RR = list(map(int,input().split(" ")))
R = list([int(x)-1 for x in input().split(" ")])
G = [[] for i in range(N)]
sq = [[(x==y)-1 for x in range(RR)] for y in range(RR)]
for i in range(M):
a,b,c = list(map(int,input().split(" ")))
a -= 1
b -= 1
G[a].append((b,c))
G[b].append((a,c))
for i in range(RR):
E = [INF for x in range(N)]
F = [0 for x in range(N)]
E[R[i]] = 0
F[R[i]] = 1
q = R[i]
c = 1
while c != N:
for a,b in G[q]:
if F[a]:
continue
if E[a] == -1:
E[a] = E[q] + b
else:
E[a] = min(E[a],E[q] + b)
a = [x for x in range(N) if not(F[x]) and E[x] != -1]
q = min(a,key=lambda x:E[x])
F[q] = 1
c += 1
for j in range(RR):
sq[i][j] = E[R[j]]
q = [[[],0,0]]
s = []
while len(q):
a,b,c = q.pop()
if b == RR:
s.append(c)
continue
for i in range(RR):
if i in a:
continue
if b == 0:
q.append([a+[i],b+1,0])
else:
q.append([a+[i],b+1,c+sq[a[-1]][i]])
print((min(s)))
|
INF = float('inf')
N,M,RR = list(map(int,input().split(" ")))
R = list([int(x)-1 for x in input().split(" ")])
G = [[] for i in range(N)]
sq = [[(x==y)-1 for x in range(RR)] for y in range(RR)]
for i in range(M):
a,b,c = list(map(int,input().split(" ")))
a -= 1
b -= 1
G[a].append((b,c))
G[b].append((a,c))
for i in range(RR):
E = [INF]*N
F = [1]*N
E[R[i]] = 0
F[R[i]] = 0
q = R[i]
c = 1
while c != N:
for a,b in G[q]:
if F[a]:
E[a] = min(E[a],E[q] + b)
a = [x for x in range(N) if F[x]]
q = min(a,key=lambda x:E[x])
F[q] = 0
c += 1
for j in range(RR):
sq[i][j] = E[R[j]]
q = [[[],0,0]]
s = []
while len(q):
a,b,c = q.pop()
if b == RR:
s.append(c)
continue
for i in range(RR):
if i in a:
continue
d = c
d += b and sq[a[-1]][i]
q.append([a+[i],b+1,d])
print((min(s)))
| 51 | 46 | 1,204 | 1,005 |
INF = float("inf")
N, M, RR = list(map(int, input().split(" ")))
R = list([int(x) - 1 for x in input().split(" ")])
G = [[] for i in range(N)]
sq = [[(x == y) - 1 for x in range(RR)] for y in range(RR)]
for i in range(M):
a, b, c = list(map(int, input().split(" ")))
a -= 1
b -= 1
G[a].append((b, c))
G[b].append((a, c))
for i in range(RR):
E = [INF for x in range(N)]
F = [0 for x in range(N)]
E[R[i]] = 0
F[R[i]] = 1
q = R[i]
c = 1
while c != N:
for a, b in G[q]:
if F[a]:
continue
if E[a] == -1:
E[a] = E[q] + b
else:
E[a] = min(E[a], E[q] + b)
a = [x for x in range(N) if not (F[x]) and E[x] != -1]
q = min(a, key=lambda x: E[x])
F[q] = 1
c += 1
for j in range(RR):
sq[i][j] = E[R[j]]
q = [[[], 0, 0]]
s = []
while len(q):
a, b, c = q.pop()
if b == RR:
s.append(c)
continue
for i in range(RR):
if i in a:
continue
if b == 0:
q.append([a + [i], b + 1, 0])
else:
q.append([a + [i], b + 1, c + sq[a[-1]][i]])
print((min(s)))
|
INF = float("inf")
N, M, RR = list(map(int, input().split(" ")))
R = list([int(x) - 1 for x in input().split(" ")])
G = [[] for i in range(N)]
sq = [[(x == y) - 1 for x in range(RR)] for y in range(RR)]
for i in range(M):
a, b, c = list(map(int, input().split(" ")))
a -= 1
b -= 1
G[a].append((b, c))
G[b].append((a, c))
for i in range(RR):
E = [INF] * N
F = [1] * N
E[R[i]] = 0
F[R[i]] = 0
q = R[i]
c = 1
while c != N:
for a, b in G[q]:
if F[a]:
E[a] = min(E[a], E[q] + b)
a = [x for x in range(N) if F[x]]
q = min(a, key=lambda x: E[x])
F[q] = 0
c += 1
for j in range(RR):
sq[i][j] = E[R[j]]
q = [[[], 0, 0]]
s = []
while len(q):
a, b, c = q.pop()
if b == RR:
s.append(c)
continue
for i in range(RR):
if i in a:
continue
d = c
d += b and sq[a[-1]][i]
q.append([a + [i], b + 1, d])
print((min(s)))
| false | 9.803922 |
[
"- E = [INF for x in range(N)]",
"- F = [0 for x in range(N)]",
"+ E = [INF] * N",
"+ F = [1] * N",
"- F[R[i]] = 1",
"+ F[R[i]] = 0",
"- continue",
"- if E[a] == -1:",
"- E[a] = E[q] + b",
"- else:",
"- a = [x for x in range(N) if not (F[x]) and E[x] != -1]",
"+ a = [x for x in range(N) if F[x]]",
"- F[q] = 1",
"+ F[q] = 0",
"- if b == 0:",
"- q.append([a + [i], b + 1, 0])",
"- else:",
"- q.append([a + [i], b + 1, c + sq[a[-1]][i]])",
"+ d = c",
"+ d += b and sq[a[-1]][i]",
"+ q.append([a + [i], b + 1, d])"
] | false | 0.07032 | 0.057933 | 1.213803 |
[
"s544418243",
"s720372785"
] |
u155757809
|
p03633
|
python
|
s277469141
|
s573514758
| 33 | 25 | 9,508 | 9,152 |
Accepted
|
Accepted
| 24.24 |
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
n = int(eval(input()))
l = []
for i in range(n):
t = int(eval(input()))
l.append(t)
print((lcm_list(l)))
|
def gcd(m, n):
if m < n:
m, n = n, m
while True:
r = m % n
if r == 0:
return n
else:
m, n = n, r
def lcm(m, n):
return m*n // gcd(m, n)
n = int(eval(input()))
l = []
ans = 1
for i in range(n):
t = int(eval(input()))
ans = lcm(ans, t)
print(ans)
| 18 | 24 | 283 | 338 |
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
n = int(eval(input()))
l = []
for i in range(n):
t = int(eval(input()))
l.append(t)
print((lcm_list(l)))
|
def gcd(m, n):
if m < n:
m, n = n, m
while True:
r = m % n
if r == 0:
return n
else:
m, n = n, r
def lcm(m, n):
return m * n // gcd(m, n)
n = int(eval(input()))
l = []
ans = 1
for i in range(n):
t = int(eval(input()))
ans = lcm(ans, t)
print(ans)
| false | 25 |
[
"-import math",
"-from functools import reduce",
"+def gcd(m, n):",
"+ if m < n:",
"+ m, n = n, m",
"+ while True:",
"+ r = m % n",
"+ if r == 0:",
"+ return n",
"+ else:",
"+ m, n = n, r",
"-def lcm_base(x, y):",
"- return (x * y) // math.gcd(x, y)",
"-",
"-",
"-def lcm_list(numbers):",
"- return reduce(lcm_base, numbers, 1)",
"+def lcm(m, n):",
"+ return m * n // gcd(m, n)",
"+ans = 1",
"- l.append(t)",
"-print((lcm_list(l)))",
"+ ans = lcm(ans, t)",
"+print(ans)"
] | false | 0.036515 | 0.038538 | 0.947526 |
[
"s277469141",
"s573514758"
] |
u347600233
|
p02765
|
python
|
s473960042
|
s759790233
| 29 | 26 | 9,096 | 9,156 |
Accepted
|
Accepted
| 10.34 |
n, r = list(map(int, input().split()))
print((r + max(0, 100*(10 - n))))
|
n, r = list(map(int, input().split()))
print((r + 100*(10 - min(10, n))))
| 2 | 2 | 65 | 66 |
n, r = list(map(int, input().split()))
print((r + max(0, 100 * (10 - n))))
|
n, r = list(map(int, input().split()))
print((r + 100 * (10 - min(10, n))))
| false | 0 |
[
"-print((r + max(0, 100 * (10 - n))))",
"+print((r + 100 * (10 - min(10, n))))"
] | false | 0.046844 | 0.047705 | 0.981954 |
[
"s473960042",
"s759790233"
] |
u761320129
|
p03761
|
python
|
s876531107
|
s749399735
| 25 | 22 | 3,316 | 3,316 |
Accepted
|
Accepted
| 12 |
from collections import Counter
N = int(eval(input()))
src = [eval(input()) for i in range(N)]
ctr = Counter(src[0])
for s in src[1:]:
ctr &= Counter(s)
ans = ''
for k,v in sorted(ctr.items()):
ans += k*v
print(ans)
|
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
from collections import Counter
ctr = Counter(S[0])
for s in S[1:]:
ctr &= Counter(s)
ans = ''
for k,v in sorted(ctr.items()):
ans += k * v
print(ans)
| 12 | 10 | 224 | 216 |
from collections import Counter
N = int(eval(input()))
src = [eval(input()) for i in range(N)]
ctr = Counter(src[0])
for s in src[1:]:
ctr &= Counter(s)
ans = ""
for k, v in sorted(ctr.items()):
ans += k * v
print(ans)
|
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
from collections import Counter
ctr = Counter(S[0])
for s in S[1:]:
ctr &= Counter(s)
ans = ""
for k, v in sorted(ctr.items()):
ans += k * v
print(ans)
| false | 16.666667 |
[
"+N = int(eval(input()))",
"+S = [eval(input()) for i in range(N)]",
"-N = int(eval(input()))",
"-src = [eval(input()) for i in range(N)]",
"-ctr = Counter(src[0])",
"-for s in src[1:]:",
"+ctr = Counter(S[0])",
"+for s in S[1:]:"
] | false | 0.112239 | 0.050685 | 2.214439 |
[
"s876531107",
"s749399735"
] |
u633068244
|
p00915
|
python
|
s554092459
|
s736260773
| 170 | 90 | 4,276 | 4,252 |
Accepted
|
Accepted
| 47.06 |
while 1:
n,l = list(map(int,input().split()))
if n == 0: break
tube = [[] for i in range(l-1)]
for i in range(1,n+1):
d,p = input().split()
tube[int(p)-1].append(i if d == "R" else -i)
t = num = 0
while sum(len(ele) for ele in tube) != 0:
for s in [-1,1]:
for i in range(l-1)[::s]:
for a in tube[i]:
if -s*a > 0:
tube[i].remove(a)
if i == (l-2 if s == -1 else 0):
num = abs(a)
else:
tube[i-s].append(a)
for i in range(l-1):
if len(tube[i]) > 1:
tube[i] = [-a for a in tube[i]]
t += 1
print(t,num)
|
while 1:
n,l = list(map(int,input().split()))
if n == 0: break
R = [0]*(l-1)
L = [0]*(l-1)
for i in range(1,n+1):
d,p = input().split()
p = int(p)-1
if d == "R": R[p] = i
else: L[p] = i
t = num = 0
while sum(R)+sum(L) != 0:
if R[-1] > 0: num = R[-1]
R = [0]+R[:-1]
if L[0] > 0: num = L[0]
L = L[1:]+[0]
for i in range(l-1):
if min(L[i],R[i]) > 0: R[i],L[i] = L[i],R[i]
t += 1
print(t,num)
| 24 | 20 | 800 | 535 |
while 1:
n, l = list(map(int, input().split()))
if n == 0:
break
tube = [[] for i in range(l - 1)]
for i in range(1, n + 1):
d, p = input().split()
tube[int(p) - 1].append(i if d == "R" else -i)
t = num = 0
while sum(len(ele) for ele in tube) != 0:
for s in [-1, 1]:
for i in range(l - 1)[::s]:
for a in tube[i]:
if -s * a > 0:
tube[i].remove(a)
if i == (l - 2 if s == -1 else 0):
num = abs(a)
else:
tube[i - s].append(a)
for i in range(l - 1):
if len(tube[i]) > 1:
tube[i] = [-a for a in tube[i]]
t += 1
print(t, num)
|
while 1:
n, l = list(map(int, input().split()))
if n == 0:
break
R = [0] * (l - 1)
L = [0] * (l - 1)
for i in range(1, n + 1):
d, p = input().split()
p = int(p) - 1
if d == "R":
R[p] = i
else:
L[p] = i
t = num = 0
while sum(R) + sum(L) != 0:
if R[-1] > 0:
num = R[-1]
R = [0] + R[:-1]
if L[0] > 0:
num = L[0]
L = L[1:] + [0]
for i in range(l - 1):
if min(L[i], R[i]) > 0:
R[i], L[i] = L[i], R[i]
t += 1
print(t, num)
| false | 16.666667 |
[
"- tube = [[] for i in range(l - 1)]",
"+ R = [0] * (l - 1)",
"+ L = [0] * (l - 1)",
"- tube[int(p) - 1].append(i if d == \"R\" else -i)",
"+ p = int(p) - 1",
"+ if d == \"R\":",
"+ R[p] = i",
"+ else:",
"+ L[p] = i",
"- while sum(len(ele) for ele in tube) != 0:",
"- for s in [-1, 1]:",
"- for i in range(l - 1)[::s]:",
"- for a in tube[i]:",
"- if -s * a > 0:",
"- tube[i].remove(a)",
"- if i == (l - 2 if s == -1 else 0):",
"- num = abs(a)",
"- else:",
"- tube[i - s].append(a)",
"+ while sum(R) + sum(L) != 0:",
"+ if R[-1] > 0:",
"+ num = R[-1]",
"+ R = [0] + R[:-1]",
"+ if L[0] > 0:",
"+ num = L[0]",
"+ L = L[1:] + [0]",
"- if len(tube[i]) > 1:",
"- tube[i] = [-a for a in tube[i]]",
"+ if min(L[i], R[i]) > 0:",
"+ R[i], L[i] = L[i], R[i]"
] | false | 0.077438 | 0.042587 | 1.818368 |
[
"s554092459",
"s736260773"
] |
u762420987
|
p03986
|
python
|
s386821239
|
s248987707
| 207 | 187 | 48,864 | 48,352 |
Accepted
|
Accepted
| 9.66 |
from collections import deque
d = deque()
X = eval(input())
for c in X:
d.append(c)
while len(d) >= 2:
new = d.pop()
last = d.pop()
if last == "S" and new == "T":
continue
else:
d.append(last)
d.append(new)
break
print((len(d)))
|
from collections import deque
d = deque()
X = eval(input())
for c in X:
if d:
last = d.pop()
if last == "S" and c == "T":
pass
else:
d.append(last)
d.append(c)
else:
d.append(c)
print((len(d)))
| 15 | 14 | 322 | 275 |
from collections import deque
d = deque()
X = eval(input())
for c in X:
d.append(c)
while len(d) >= 2:
new = d.pop()
last = d.pop()
if last == "S" and new == "T":
continue
else:
d.append(last)
d.append(new)
break
print((len(d)))
|
from collections import deque
d = deque()
X = eval(input())
for c in X:
if d:
last = d.pop()
if last == "S" and c == "T":
pass
else:
d.append(last)
d.append(c)
else:
d.append(c)
print((len(d)))
| false | 6.666667 |
[
"- d.append(c)",
"- while len(d) >= 2:",
"- new = d.pop()",
"+ if d:",
"- if last == \"S\" and new == \"T\":",
"- continue",
"+ if last == \"S\" and c == \"T\":",
"+ pass",
"- d.append(new)",
"- break",
"+ d.append(c)",
"+ else:",
"+ d.append(c)"
] | false | 0.049388 | 0.049476 | 0.998219 |
[
"s386821239",
"s248987707"
] |
u725107050
|
p03161
|
python
|
s549525192
|
s421338066
| 487 | 409 | 57,312 | 57,184 |
Accepted
|
Accepted
| 16.02 |
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0
def change_min(a, b):
if a > b: return b
else: return a
for i in range(N):
for j in range(1, K + 1):
if i + j > N - 1: continue
dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])
print((dp[N - 1]))
|
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0
def update_dp(now, next):
global h_list
global dp
global N
if next > N - 1: return
if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
dp[next] = dp[now] + abs(h_list[next] - h_list[now])
return
for i in range(N):
for j in range(1, K + 1):
update_dp(i, i + j)
print((dp[N - 1]))
| 15 | 19 | 371 | 449 |
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp = [float("INF") for i in range(N)]
dp[0] = 0
def change_min(a, b):
if a > b:
return b
else:
return a
for i in range(N):
for j in range(1, K + 1):
if i + j > N - 1:
continue
dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])
print((dp[N - 1]))
|
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp = [float("INF") for i in range(N)]
dp[0] = 0
def update_dp(now, next):
global h_list
global dp
global N
if next > N - 1:
return
if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
dp[next] = dp[now] + abs(h_list[next] - h_list[now])
return
for i in range(N):
for j in range(1, K + 1):
update_dp(i, i + j)
print((dp[N - 1]))
| false | 21.052632 |
[
"-def change_min(a, b):",
"- if a > b:",
"- return b",
"- else:",
"- return a",
"+def update_dp(now, next):",
"+ global h_list",
"+ global dp",
"+ global N",
"+ if next > N - 1:",
"+ return",
"+ if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):",
"+ dp[next] = dp[now] + abs(h_list[next] - h_list[now])",
"+ return",
"- if i + j > N - 1:",
"- continue",
"- dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])",
"+ update_dp(i, i + j)"
] | false | 0.043877 | 0.095685 | 0.458563 |
[
"s549525192",
"s421338066"
] |
u989306199
|
p03610
|
python
|
s195725170
|
s878826505
| 79 | 17 | 4,596 | 3,188 |
Accepted
|
Accepted
| 78.48 |
s = input()
for i,c in enumerate(s):
if i % 2==0:
print(c, end='')
|
s = eval(input())
print((s[::2]))
| 4 | 2 | 82 | 26 |
s = input()
for i, c in enumerate(s):
if i % 2 == 0:
print(c, end="")
|
s = eval(input())
print((s[::2]))
| false | 50 |
[
"-s = input()",
"-for i, c in enumerate(s):",
"- if i % 2 == 0:",
"- print(c, end=\"\")",
"+s = eval(input())",
"+print((s[::2]))"
] | false | 0.044362 | 0.038595 | 1.14941 |
[
"s195725170",
"s878826505"
] |
u225388820
|
p02695
|
python
|
s714409367
|
s122427378
| 1,456 | 1,003 | 22,960 | 9,120 |
Accepted
|
Accepted
| 31.11 |
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n,m,q=list(map(int,input().split()))
x=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
for j in range(2):
x[i][j]-=1
a=[]
def dfs(v):
if len(v)>n:
return
if len(v)==n:
a.append(v)
for i in range(int(v[-1]),m+1):
dfs(v+[i])
for i in range(1,m+1):
dfs([i])
ans=0
for i in a:
now=0
for k in range(q):
if i[x[k][1]]-i[x[k][0]]==x[k][2]:
now+=x[k][3]
ans=max(now,ans)
print(ans)
|
from itertools import combinations_with_replacement
n,m,q=list(map(int,input().split()))
a,b,c,d=[0]*q,[0]*q,[0]*q,[0]*q
for i in range(q):
x,y,z,w=list(map(int,input().split()))
x-=1
y-=1
a[i],b[i],c[i],d[i]=x,y,z,w
ans=0
for v in combinations_with_replacement(list(range(1,m+1)),n):
res=0
for i in range(q):
if v[b[i]]-v[a[i]]==c[i]:
res+=d[i]
ans=max(ans,res)
print(ans)
| 26 | 16 | 570 | 418 |
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m, q = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
for j in range(2):
x[i][j] -= 1
a = []
def dfs(v):
if len(v) > n:
return
if len(v) == n:
a.append(v)
for i in range(int(v[-1]), m + 1):
dfs(v + [i])
for i in range(1, m + 1):
dfs([i])
ans = 0
for i in a:
now = 0
for k in range(q):
if i[x[k][1]] - i[x[k][0]] == x[k][2]:
now += x[k][3]
ans = max(now, ans)
print(ans)
|
from itertools import combinations_with_replacement
n, m, q = list(map(int, input().split()))
a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q
for i in range(q):
x, y, z, w = list(map(int, input().split()))
x -= 1
y -= 1
a[i], b[i], c[i], d[i] = x, y, z, w
ans = 0
for v in combinations_with_replacement(list(range(1, m + 1)), n):
res = 0
for i in range(q):
if v[b[i]] - v[a[i]] == c[i]:
res += d[i]
ans = max(ans, res)
print(ans)
| false | 38.461538 |
[
"-import sys",
"+from itertools import combinations_with_replacement",
"-sys.setrecursionlimit(1000000000)",
"-input = sys.stdin.readline",
"-x = [list(map(int, input().split())) for i in range(q)]",
"+a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q",
"- for j in range(2):",
"- x[i][j] -= 1",
"-a = []",
"-",
"-",
"-def dfs(v):",
"- if len(v) > n:",
"- return",
"- if len(v) == n:",
"- a.append(v)",
"- for i in range(int(v[-1]), m + 1):",
"- dfs(v + [i])",
"-",
"-",
"-for i in range(1, m + 1):",
"- dfs([i])",
"+ x, y, z, w = list(map(int, input().split()))",
"+ x -= 1",
"+ y -= 1",
"+ a[i], b[i], c[i], d[i] = x, y, z, w",
"-for i in a:",
"- now = 0",
"- for k in range(q):",
"- if i[x[k][1]] - i[x[k][0]] == x[k][2]:",
"- now += x[k][3]",
"- ans = max(now, ans)",
"+for v in combinations_with_replacement(list(range(1, m + 1)), n):",
"+ res = 0",
"+ for i in range(q):",
"+ if v[b[i]] - v[a[i]] == c[i]:",
"+ res += d[i]",
"+ ans = max(ans, res)"
] | false | 0.07455 | 0.047322 | 1.575368 |
[
"s714409367",
"s122427378"
] |
u537782349
|
p03848
|
python
|
s035970140
|
s224509029
| 118 | 99 | 14,008 | 14,008 |
Accepted
|
Accepted
| 16.1 |
a = int(eval(input()))
b = list(map(int, input().split()))
b.sort()
c = 1 if a % 2 == 0 else 0
for i in range(a):
if (a % 2) ^ (i % 2) == 0 and i != 0:
c += 2
if b[i] != c:
print((0))
exit()
print(((2 ** (a // 2)) % (10 ** 9 + 7)))
|
a = int(eval(input()))
b = list(map(int, input().split()))
b.sort()
if a % 2 == 0:
c = 1
for i in range(len(b)):
if i > 0 and i % 2 == 0:
c += 2
if b[i] != c:
print((0))
exit()
print(((2 ** (a // 2)) % (10 ** 9 + 7)))
else:
c = 0
for i in range(len(b)):
if i > 0 and i % 2 == 1:
c += 2
if b[i] != c:
print((0))
exit()
print(((2 ** ((a-1) // 2)) % (10 ** 9 + 7)))
| 11 | 21 | 264 | 497 |
a = int(eval(input()))
b = list(map(int, input().split()))
b.sort()
c = 1 if a % 2 == 0 else 0
for i in range(a):
if (a % 2) ^ (i % 2) == 0 and i != 0:
c += 2
if b[i] != c:
print((0))
exit()
print(((2 ** (a // 2)) % (10**9 + 7)))
|
a = int(eval(input()))
b = list(map(int, input().split()))
b.sort()
if a % 2 == 0:
c = 1
for i in range(len(b)):
if i > 0 and i % 2 == 0:
c += 2
if b[i] != c:
print((0))
exit()
print(((2 ** (a // 2)) % (10**9 + 7)))
else:
c = 0
for i in range(len(b)):
if i > 0 and i % 2 == 1:
c += 2
if b[i] != c:
print((0))
exit()
print(((2 ** ((a - 1) // 2)) % (10**9 + 7)))
| false | 47.619048 |
[
"-c = 1 if a % 2 == 0 else 0",
"-for i in range(a):",
"- if (a % 2) ^ (i % 2) == 0 and i != 0:",
"- c += 2",
"- if b[i] != c:",
"- print((0))",
"- exit()",
"-print(((2 ** (a // 2)) % (10**9 + 7)))",
"+if a % 2 == 0:",
"+ c = 1",
"+ for i in range(len(b)):",
"+ if i > 0 and i % 2 == 0:",
"+ c += 2",
"+ if b[i] != c:",
"+ print((0))",
"+ exit()",
"+ print(((2 ** (a // 2)) % (10**9 + 7)))",
"+else:",
"+ c = 0",
"+ for i in range(len(b)):",
"+ if i > 0 and i % 2 == 1:",
"+ c += 2",
"+ if b[i] != c:",
"+ print((0))",
"+ exit()",
"+ print(((2 ** ((a - 1) // 2)) % (10**9 + 7)))"
] | false | 0.046125 | 0.048154 | 0.957872 |
[
"s035970140",
"s224509029"
] |
u729133443
|
p03852
|
python
|
s171184603
|
s320580212
| 182 | 28 | 38,256 | 9,036 |
Accepted
|
Accepted
| 84.62 |
print(('vowel'*(eval(input())in'aiueo')or'consonant'))
|
print((('consonant','vowel')[eval(input())in'aiueo']))
| 1 | 1 | 46 | 46 |
print(("vowel" * (eval(input()) in "aiueo") or "consonant"))
|
print((("consonant", "vowel")[eval(input()) in "aiueo"]))
| false | 0 |
[
"-print((\"vowel\" * (eval(input()) in \"aiueo\") or \"consonant\"))",
"+print(((\"consonant\", \"vowel\")[eval(input()) in \"aiueo\"]))"
] | false | 0.035931 | 0.081116 | 0.442957 |
[
"s171184603",
"s320580212"
] |
u858748695
|
p02755
|
python
|
s846333250
|
s201091207
| 33 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 48.48 |
#!/usr/bin/env python3
a, b = list(map(int, input().split()))
for i in range(10 ** 5):
if i * 8 // 100 == a and i // 10 == b:
print(i)
exit()
print((-1))
|
#!/usr/bin/env python3
a, b = list(map(int, input().split()))
mn = max(100 * a, 80 * b)
mx = min(100 * a + 99, 80 * b + 72)
print(((mn + 7) // 8 if mn <= mx else -1))
| 7 | 5 | 172 | 163 |
#!/usr/bin/env python3
a, b = list(map(int, input().split()))
for i in range(10**5):
if i * 8 // 100 == a and i // 10 == b:
print(i)
exit()
print((-1))
|
#!/usr/bin/env python3
a, b = list(map(int, input().split()))
mn = max(100 * a, 80 * b)
mx = min(100 * a + 99, 80 * b + 72)
print(((mn + 7) // 8 if mn <= mx else -1))
| false | 28.571429 |
[
"-for i in range(10**5):",
"- if i * 8 // 100 == a and i // 10 == b:",
"- print(i)",
"- exit()",
"-print((-1))",
"+mn = max(100 * a, 80 * b)",
"+mx = min(100 * a + 99, 80 * b + 72)",
"+print(((mn + 7) // 8 if mn <= mx else -1))"
] | false | 0.06361 | 0.085264 | 0.746036 |
[
"s846333250",
"s201091207"
] |
u624689667
|
p03266
|
python
|
s802379965
|
s201617002
| 194 | 171 | 50,800 | 38,384 |
Accepted
|
Accepted
| 11.86 |
import collections
N, K = [int(i) for i in input().split()]
# Kで割ってvalue余る数が1以上key以下にいくつあるか
d = collections.defaultdict(int)
for i in range(1, N + 1):
d[i % K] += 1
ans = 0
for a in range(K):
b = (K - a) % K
c = (K - a) % K
if (b + c) % K:
continue
ans += d[a] * d[b] * d[c]
print(ans)
|
import collections
N, K = [int(i) for i in input().split()]
ans = (N // K) ** 3
if K % 2 == 0:
ans += ((N + K//2) // K) ** 3
print(ans)
| 16 | 7 | 330 | 147 |
import collections
N, K = [int(i) for i in input().split()]
# Kで割ってvalue余る数が1以上key以下にいくつあるか
d = collections.defaultdict(int)
for i in range(1, N + 1):
d[i % K] += 1
ans = 0
for a in range(K):
b = (K - a) % K
c = (K - a) % K
if (b + c) % K:
continue
ans += d[a] * d[b] * d[c]
print(ans)
|
import collections
N, K = [int(i) for i in input().split()]
ans = (N // K) ** 3
if K % 2 == 0:
ans += ((N + K // 2) // K) ** 3
print(ans)
| false | 56.25 |
[
"-# Kで割ってvalue余る数が1以上key以下にいくつあるか",
"-d = collections.defaultdict(int)",
"-for i in range(1, N + 1):",
"- d[i % K] += 1",
"-ans = 0",
"-for a in range(K):",
"- b = (K - a) % K",
"- c = (K - a) % K",
"- if (b + c) % K:",
"- continue",
"- ans += d[a] * d[b] * d[c]",
"+ans = (N // K) ** 3",
"+if K % 2 == 0:",
"+ ans += ((N + K // 2) // K) ** 3"
] | false | 0.038897 | 0.040295 | 0.965299 |
[
"s802379965",
"s201617002"
] |
u775421443
|
p03160
|
python
|
s575134084
|
s117111802
| 86 | 76 | 14,184 | 14,184 |
Accepted
|
Accepted
| 11.63 |
def main():
n = int(eval(input()))
hs = tuple(map(int, input().split()))
a, b = 0, abs(hs[1] - hs[0])
for i in range(2, n):
d1 = a + abs(hs[i] - hs[i-2])
d2 = b + abs(hs[i] - hs[i-1])
a, b = b, min(d1, d2)
print(b)
if __name__ == "__main__":
main()
|
def main():
n = int(eval(input()))
hs = tuple(map(int, input().split()))
a, b = 0, abs(hs[1] - hs[0])
for i in range(2, n):
d1 = a + abs(hs[i] - hs[i-2])
d2 = b + abs(hs[i] - hs[i-1])
a, b = b, d1 if d1 <= d2 else d2
print(b)
if __name__ == "__main__":
main()
| 15 | 15 | 285 | 296 |
def main():
n = int(eval(input()))
hs = tuple(map(int, input().split()))
a, b = 0, abs(hs[1] - hs[0])
for i in range(2, n):
d1 = a + abs(hs[i] - hs[i - 2])
d2 = b + abs(hs[i] - hs[i - 1])
a, b = b, min(d1, d2)
print(b)
if __name__ == "__main__":
main()
|
def main():
n = int(eval(input()))
hs = tuple(map(int, input().split()))
a, b = 0, abs(hs[1] - hs[0])
for i in range(2, n):
d1 = a + abs(hs[i] - hs[i - 2])
d2 = b + abs(hs[i] - hs[i - 1])
a, b = b, d1 if d1 <= d2 else d2
print(b)
if __name__ == "__main__":
main()
| false | 0 |
[
"- a, b = b, min(d1, d2)",
"+ a, b = b, d1 if d1 <= d2 else d2"
] | false | 0.045783 | 0.044921 | 1.01918 |
[
"s575134084",
"s117111802"
] |
u053749071
|
p02899
|
python
|
s920349721
|
s031482930
| 270 | 203 | 52,164 | 105,408 |
Accepted
|
Accepted
| 24.81 |
import math
import numpy as np
n = int(eval(input()))
a = list(map(int, input().split()))
# a = np.array(a)
# ans = []
# while a.min() != 9999999:
# min_index = a.argmin()
# ans.append(min_index+1)
# a[min_index] = 9999999
# print(' '.join([str(_) for _ in ans]))
l = []
for i in range(n):
l.append([i+1, a[i]])
sl = sorted(l, key=lambda x: x[1])
sl0 = [r[0] for r in sl]
print((' '.join([str(_) for _ in sl0])))
|
n = int(eval(input()))
a = list(map(int, input().split()))
# a = np.array(a)
# ans = []
# while a.min() != 9999999:
# min_index = a.argmin()
# ans.append(min_index+1)
# a[min_index] = 9999999
# print(' '.join([str(_) for _ in ans]))
l = []
for i in range(n):
l.append([i+1, a[i]])
sl = sorted(l, key=lambda x: x[1])
sl0 = [r[0] for r in sl]
print((' '.join([str(_) for _ in sl0])))
| 22 | 19 | 447 | 412 |
import math
import numpy as np
n = int(eval(input()))
a = list(map(int, input().split()))
# a = np.array(a)
# ans = []
# while a.min() != 9999999:
# min_index = a.argmin()
# ans.append(min_index+1)
# a[min_index] = 9999999
# print(' '.join([str(_) for _ in ans]))
l = []
for i in range(n):
l.append([i + 1, a[i]])
sl = sorted(l, key=lambda x: x[1])
sl0 = [r[0] for r in sl]
print((" ".join([str(_) for _ in sl0])))
|
n = int(eval(input()))
a = list(map(int, input().split()))
# a = np.array(a)
# ans = []
# while a.min() != 9999999:
# min_index = a.argmin()
# ans.append(min_index+1)
# a[min_index] = 9999999
# print(' '.join([str(_) for _ in ans]))
l = []
for i in range(n):
l.append([i + 1, a[i]])
sl = sorted(l, key=lambda x: x[1])
sl0 = [r[0] for r in sl]
print((" ".join([str(_) for _ in sl0])))
| false | 13.636364 |
[
"-import math",
"-import numpy as np",
"-"
] | false | 0.128412 | 0.038386 | 3.345254 |
[
"s920349721",
"s031482930"
] |
u416011173
|
p02601
|
python
|
s333239923
|
s869696617
| 31 | 28 | 9,080 | 9,216 |
Accepted
|
Accepted
| 9.68 |
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
# 標準入力を取得
A, B, C = list(map(int, input().split()))
K = int(eval(input()))
# 求解処理
ans = str()
k_b = 0
if A >= B:
k_b = int(math.log(A / B) / math.log(2)) + 1
if k_b > K:
ans = "No"
else:
if 2**(K - k_b) * C > 2**k_b * B:
ans = "Yes"
else:
ans = "No"
# 結果出力
print(ans)
|
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
A, B, C = list(map(int, input().split()))
K = int(eval(input()))
return A, B, C, K
def main(A: int, B: int, C: int, K: int) -> None:
"""
メイン処理.
Args:\n
A (int): 整数(1 <= A <= 7)
B (int): 整数(1 <= B <= 7)
C (int): 整数(1 <= C <= 7)
K (int): 操作回数(1 <= K <= 7)
"""
# 求解処理
cnt = 0
while A >= B:
cnt += 1
B *= 2
while B >= C:
cnt += 1
C *= 2
# 結果出力
if cnt <= K:
print("Yes")
else:
print("No")
if __name__ == "__main__":
# 標準入力を取得
A, B, C, K = get_input()
# メイン処理
main(A, B, C, K)
| 23 | 45 | 369 | 785 |
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
# 標準入力を取得
A, B, C = list(map(int, input().split()))
K = int(eval(input()))
# 求解処理
ans = str()
k_b = 0
if A >= B:
k_b = int(math.log(A / B) / math.log(2)) + 1
if k_b > K:
ans = "No"
else:
if 2 ** (K - k_b) * C > 2**k_b * B:
ans = "Yes"
else:
ans = "No"
# 結果出力
print(ans)
|
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
A, B, C = list(map(int, input().split()))
K = int(eval(input()))
return A, B, C, K
def main(A: int, B: int, C: int, K: int) -> None:
"""
メイン処理.
Args:\n
A (int): 整数(1 <= A <= 7)
B (int): 整数(1 <= B <= 7)
C (int): 整数(1 <= C <= 7)
K (int): 操作回数(1 <= K <= 7)
"""
# 求解処理
cnt = 0
while A >= B:
cnt += 1
B *= 2
while B >= C:
cnt += 1
C *= 2
# 結果出力
if cnt <= K:
print("Yes")
else:
print("No")
if __name__ == "__main__":
# 標準入力を取得
A, B, C, K = get_input()
# メイン処理
main(A, B, C, K)
| false | 48.888889 |
[
"-# モジュールのインポート",
"-import math",
"+def get_input() -> tuple:",
"+ \"\"\"",
"+ 標準入力を取得する.",
"+ Returns:\\n",
"+ tuple: 標準入力",
"+ \"\"\"",
"+ A, B, C = list(map(int, input().split()))",
"+ K = int(eval(input()))",
"+ return A, B, C, K",
"-# 標準入力を取得",
"-A, B, C = list(map(int, input().split()))",
"-K = int(eval(input()))",
"-# 求解処理",
"-ans = str()",
"-k_b = 0",
"-if A >= B:",
"- k_b = int(math.log(A / B) / math.log(2)) + 1",
"-if k_b > K:",
"- ans = \"No\"",
"-else:",
"- if 2 ** (K - k_b) * C > 2**k_b * B:",
"- ans = \"Yes\"",
"+",
"+def main(A: int, B: int, C: int, K: int) -> None:",
"+ \"\"\"",
"+ メイン処理.",
"+ Args:\\n",
"+ A (int): 整数(1 <= A <= 7)",
"+ B (int): 整数(1 <= B <= 7)",
"+ C (int): 整数(1 <= C <= 7)",
"+ K (int): 操作回数(1 <= K <= 7)",
"+ \"\"\"",
"+ # 求解処理",
"+ cnt = 0",
"+ while A >= B:",
"+ cnt += 1",
"+ B *= 2",
"+ while B >= C:",
"+ cnt += 1",
"+ C *= 2",
"+ # 結果出力",
"+ if cnt <= K:",
"+ print(\"Yes\")",
"- ans = \"No\"",
"-# 結果出力",
"-print(ans)",
"+ print(\"No\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ # 標準入力を取得",
"+ A, B, C, K = get_input()",
"+ # メイン処理",
"+ main(A, B, C, K)"
] | false | 0.036551 | 0.036438 | 1.003102 |
[
"s333239923",
"s869696617"
] |
u562935282
|
p02990
|
python
|
s016439668
|
s481052884
| 224 | 33 | 43,376 | 3,984 |
Accepted
|
Accepted
| 85.27 |
def cmb(n, r):
if n < r:
return 0 # <-直した
if r > n - r:
return cmb(n, n - r)
if r == 0:
return 1
if r == 1:
return n
res = f[n]
res *= invs[r]
res %= MOD
res *= invs[n - r]
res %= MOD
return res
MOD = 10 ** 9 + 7
N, K = list(map(int, input().split()))
f = [-1] * (N * 2 + 1)
f[0] = 1
t = 1
for i in range(1, N * 2 + 1):
t *= i
t %= MOD
f[i] = t
inv = pow(t, MOD - 2, MOD)
invs = [-1] * (N * 2 + 1)
invs[N * 2] = inv
for i in range(N * 2 - 1, 0, -1):
inv *= (i + 1) # <-直した
inv %= MOD
invs[i] = inv
print((N - K + 1))
for i in range(2, K + 1):
print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % MOD))
|
from collections import defaultdict
mod = 10 ** 9 + 7
memo = defaultdict(int)
def cmb(n, r):
if (n, r) in memo:
return memo[(n, r)]
if n < r or r < 0:
return 0
if r > n - r:
return cmb(n, n - r)
res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod
memo[(n, r)] = res
return res
n, k = list(map(int, input().split()))
f = [1]
for i in range(1, 4000 + 10):
f.append(f[-1] * i % mod)
for i in range(1, k + 1):
print((cmb(n - k + 1, i) * cmb(k - 1, i - 1) % mod))
| 40 | 30 | 731 | 568 |
def cmb(n, r):
if n < r:
return 0 # <-直した
if r > n - r:
return cmb(n, n - r)
if r == 0:
return 1
if r == 1:
return n
res = f[n]
res *= invs[r]
res %= MOD
res *= invs[n - r]
res %= MOD
return res
MOD = 10**9 + 7
N, K = list(map(int, input().split()))
f = [-1] * (N * 2 + 1)
f[0] = 1
t = 1
for i in range(1, N * 2 + 1):
t *= i
t %= MOD
f[i] = t
inv = pow(t, MOD - 2, MOD)
invs = [-1] * (N * 2 + 1)
invs[N * 2] = inv
for i in range(N * 2 - 1, 0, -1):
inv *= i + 1 # <-直した
inv %= MOD
invs[i] = inv
print((N - K + 1))
for i in range(2, K + 1):
print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % MOD))
|
from collections import defaultdict
mod = 10**9 + 7
memo = defaultdict(int)
def cmb(n, r):
if (n, r) in memo:
return memo[(n, r)]
if n < r or r < 0:
return 0
if r > n - r:
return cmb(n, n - r)
res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod
memo[(n, r)] = res
return res
n, k = list(map(int, input().split()))
f = [1]
for i in range(1, 4000 + 10):
f.append(f[-1] * i % mod)
for i in range(1, k + 1):
print((cmb(n - k + 1, i) * cmb(k - 1, i - 1) % mod))
| false | 25 |
[
"+from collections import defaultdict",
"+",
"+mod = 10**9 + 7",
"+memo = defaultdict(int)",
"+",
"+",
"- if n < r:",
"- return 0 # <-直した",
"+ if (n, r) in memo:",
"+ return memo[(n, r)]",
"+ if n < r or r < 0:",
"+ return 0",
"- if r == 0:",
"- return 1",
"- if r == 1:",
"- return n",
"- res = f[n]",
"- res *= invs[r]",
"- res %= MOD",
"- res *= invs[n - r]",
"- res %= MOD",
"+ res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod",
"+ memo[(n, r)] = res",
"-MOD = 10**9 + 7",
"-N, K = list(map(int, input().split()))",
"-f = [-1] * (N * 2 + 1)",
"-f[0] = 1",
"-t = 1",
"-for i in range(1, N * 2 + 1):",
"- t *= i",
"- t %= MOD",
"- f[i] = t",
"-inv = pow(t, MOD - 2, MOD)",
"-invs = [-1] * (N * 2 + 1)",
"-invs[N * 2] = inv",
"-for i in range(N * 2 - 1, 0, -1):",
"- inv *= i + 1 # <-直した",
"- inv %= MOD",
"- invs[i] = inv",
"-print((N - K + 1))",
"-for i in range(2, K + 1):",
"- print((cmb(K - 1, i - 1) * cmb(N - K + 1, i) % MOD))",
"+n, k = list(map(int, input().split()))",
"+f = [1]",
"+for i in range(1, 4000 + 10):",
"+ f.append(f[-1] * i % mod)",
"+for i in range(1, k + 1):",
"+ print((cmb(n - k + 1, i) * cmb(k - 1, i - 1) % mod))"
] | false | 0.036025 | 0.037822 | 0.952484 |
[
"s016439668",
"s481052884"
] |
u691018832
|
p03578
|
python
|
s310048277
|
s087052595
| 901 | 264 | 71,252 | 56,952 |
Accepted
|
Accepted
| 70.7 |
import sys
from collections import Counter
input = sys.stdin.readline
n = int(eval(input()))
d = list(map(int, input().split()))
m = int(eval(input()))
t = list(map(int, input().split()))
dif = sorted(list(Counter(d).items()))
check = sorted(list(Counter(t).items()))
cnt = 0
len_check = len(check)
for i, j in dif:
if i == check[cnt][0]:
if j >= check[cnt][1]:
cnt += 1
else:
print('NO')
exit()
if cnt == len_check:
print('YES')
exit()
print('NO')
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import Counter
n = int(readline())
d = list(map(int, readline().split()))
m, *t = list(map(int, read().split()))
d = Counter(d)
for k, v in list(Counter(t).items()):
if d[k] < v:
print('NO')
break
else:
print('YES')
| 23 | 18 | 536 | 411 |
import sys
from collections import Counter
input = sys.stdin.readline
n = int(eval(input()))
d = list(map(int, input().split()))
m = int(eval(input()))
t = list(map(int, input().split()))
dif = sorted(list(Counter(d).items()))
check = sorted(list(Counter(t).items()))
cnt = 0
len_check = len(check)
for i, j in dif:
if i == check[cnt][0]:
if j >= check[cnt][1]:
cnt += 1
else:
print("NO")
exit()
if cnt == len_check:
print("YES")
exit()
print("NO")
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from collections import Counter
n = int(readline())
d = list(map(int, readline().split()))
m, *t = list(map(int, read().split()))
d = Counter(d)
for k, v in list(Counter(t).items()):
if d[k] < v:
print("NO")
break
else:
print("YES")
| false | 21.73913 |
[
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(10**7)",
"-input = sys.stdin.readline",
"-n = int(eval(input()))",
"-d = list(map(int, input().split()))",
"-m = int(eval(input()))",
"-t = list(map(int, input().split()))",
"-dif = sorted(list(Counter(d).items()))",
"-check = sorted(list(Counter(t).items()))",
"-cnt = 0",
"-len_check = len(check)",
"-for i, j in dif:",
"- if i == check[cnt][0]:",
"- if j >= check[cnt][1]:",
"- cnt += 1",
"- else:",
"- print(\"NO\")",
"- exit()",
"- if cnt == len_check:",
"- print(\"YES\")",
"- exit()",
"-print(\"NO\")",
"+n = int(readline())",
"+d = list(map(int, readline().split()))",
"+m, *t = list(map(int, read().split()))",
"+d = Counter(d)",
"+for k, v in list(Counter(t).items()):",
"+ if d[k] < v:",
"+ print(\"NO\")",
"+ break",
"+else:",
"+ print(\"YES\")"
] | false | 0.046558 | 0.150282 | 0.309805 |
[
"s310048277",
"s087052595"
] |
u427344224
|
p02984
|
python
|
s948415607
|
s443653097
| 224 | 186 | 16,944 | 14,028 |
Accepted
|
Accepted
| 16.96 |
N = int(eval(input()))
a_list = list(map(int, input().split()))
odd_sum = [0]
even_sum = [0]
for i in range(N):
if i % 2 == 0:
odd_sum.append(odd_sum[-1] + a_list[i])
even_sum.append(even_sum[-1] - a_list[i])
else:
odd_sum.append(odd_sum[-1] - a_list[i])
even_sum.append(even_sum[-1] + a_list[i])
ans = []
for i in range(N):
a = a_list[i]
if i % 2 == 0:
a += (odd_sum[-1] - odd_sum[i + 1])
a += even_sum[i]
else:
a += (even_sum[-1] - even_sum[i + 1])
a += odd_sum[i]
print(a)
|
N = int(eval(input()))
a_list = list(map(int, input().split()))
ans = []
for i in range(N):
a = a_list[i]
if i == 0:
for j in range(1, N):
if j % 2 == 0:
a += a_list[j]
else:
a -= a_list[j]
ans.append(a)
else:
a = a_list[i - 1]
ans.append(2 * (a - ans[-1] // 2))
for a in ans:
print(a)
| 25 | 19 | 586 | 404 |
N = int(eval(input()))
a_list = list(map(int, input().split()))
odd_sum = [0]
even_sum = [0]
for i in range(N):
if i % 2 == 0:
odd_sum.append(odd_sum[-1] + a_list[i])
even_sum.append(even_sum[-1] - a_list[i])
else:
odd_sum.append(odd_sum[-1] - a_list[i])
even_sum.append(even_sum[-1] + a_list[i])
ans = []
for i in range(N):
a = a_list[i]
if i % 2 == 0:
a += odd_sum[-1] - odd_sum[i + 1]
a += even_sum[i]
else:
a += even_sum[-1] - even_sum[i + 1]
a += odd_sum[i]
print(a)
|
N = int(eval(input()))
a_list = list(map(int, input().split()))
ans = []
for i in range(N):
a = a_list[i]
if i == 0:
for j in range(1, N):
if j % 2 == 0:
a += a_list[j]
else:
a -= a_list[j]
ans.append(a)
else:
a = a_list[i - 1]
ans.append(2 * (a - ans[-1] // 2))
for a in ans:
print(a)
| false | 24 |
[
"-odd_sum = [0]",
"-even_sum = [0]",
"-for i in range(N):",
"- if i % 2 == 0:",
"- odd_sum.append(odd_sum[-1] + a_list[i])",
"- even_sum.append(even_sum[-1] - a_list[i])",
"- else:",
"- odd_sum.append(odd_sum[-1] - a_list[i])",
"- even_sum.append(even_sum[-1] + a_list[i])",
"- if i % 2 == 0:",
"- a += odd_sum[-1] - odd_sum[i + 1]",
"- a += even_sum[i]",
"+ if i == 0:",
"+ for j in range(1, N):",
"+ if j % 2 == 0:",
"+ a += a_list[j]",
"+ else:",
"+ a -= a_list[j]",
"+ ans.append(a)",
"- a += even_sum[-1] - even_sum[i + 1]",
"- a += odd_sum[i]",
"+ a = a_list[i - 1]",
"+ ans.append(2 * (a - ans[-1] // 2))",
"+for a in ans:"
] | false | 0.043761 | 0.034734 | 1.259898 |
[
"s948415607",
"s443653097"
] |
u089376182
|
p03160
|
python
|
s316553341
|
s065592668
| 134 | 122 | 13,928 | 20,704 |
Accepted
|
Accepted
| 8.96 |
n = int(eval(input()))
H = list(map(int, input().split()))
C = [0]*(n)
for i in range(1, n):
if i == 1:
C[i] = abs(H[i]-H[i-1])
else:
C[i] = min(C[i-1]+abs(H[i]-H[i-1]), C[i-2]+abs(H[i]-H[i-2]))
print((C.pop()))
|
n = int(eval(input()))
H = [0]+list(map(int, input().split()))
dp = [0]*(n+1)
dp[2] = abs(H[2]-H[1])
for i in range(3, n+1):
dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
print((dp[-1]))
| 12 | 9 | 231 | 208 |
n = int(eval(input()))
H = list(map(int, input().split()))
C = [0] * (n)
for i in range(1, n):
if i == 1:
C[i] = abs(H[i] - H[i - 1])
else:
C[i] = min(C[i - 1] + abs(H[i] - H[i - 1]), C[i - 2] + abs(H[i] - H[i - 2]))
print((C.pop()))
|
n = int(eval(input()))
H = [0] + list(map(int, input().split()))
dp = [0] * (n + 1)
dp[2] = abs(H[2] - H[1])
for i in range(3, n + 1):
dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
print((dp[-1]))
| false | 25 |
[
"-H = list(map(int, input().split()))",
"-C = [0] * (n)",
"-for i in range(1, n):",
"- if i == 1:",
"- C[i] = abs(H[i] - H[i - 1])",
"- else:",
"- C[i] = min(C[i - 1] + abs(H[i] - H[i - 1]), C[i - 2] + abs(H[i] - H[i - 2]))",
"-print((C.pop()))",
"+H = [0] + list(map(int, input().split()))",
"+dp = [0] * (n + 1)",
"+dp[2] = abs(H[2] - H[1])",
"+for i in range(3, n + 1):",
"+ dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))",
"+print((dp[-1]))"
] | false | 0.042322 | 0.046511 | 0.90993 |
[
"s316553341",
"s065592668"
] |
u871201743
|
p03176
|
python
|
s638431194
|
s964829700
| 832 | 746 | 121,936 | 121,852 |
Accepted
|
Accepted
| 10.34 |
import operator
class SegmentTree:
def __init__(self, seq, op=operator.add):
self.n = len(seq)
self.op = op
self.tree = [-1] * self.n + seq
for i in reversed(list(range(1, self.n))):
self.tree[i] = op(self.tree[2*i], self.tree[2*i+1])
def modify(self, pos, val):
assert pos < self.n
pos += self.n
self.tree[pos] = val
while pos > 1:
self.tree[pos//2] = self.op(self.tree[pos], self.tree[pos ^ 1])
pos //= 2
def query(self, L, R):
assert L <= R and L >= 0 and R <= self.n
res = 0
L += self.n
R += self.n
while L < R:
if L % 2 == 1:
res = self.op(res, self.tree[L])
L += 1
if R % 2 == 1:
R -= 1
res = self.op(res, self.tree[R])
L //= 2
R //= 2
return res
def solve(n, heights, beauty):
st = SegmentTree([0] * (n+1), op = lambda x, y: max(x, y))
for flower in range(n):
st.modify(heights[flower], st.query(0, heights[flower] + 1) + beauty[flower])
return st.tree[1]
def main():
n = int(eval(input()))
heights = [int(c) for c in input().split()]
beauty = [int(c) for c in input().split()]
ans = solve(n, heights, beauty)
print(ans)
if __name__ == "__main__":
main()
|
import operator
class SegmentTree:
def __init__(self, seq, op=operator.add):
self.n = len(seq)
self.op = op
self.tree = [-1] * self.n + seq
for i in reversed(list(range(1, self.n))):
self.tree[i] = op(self.tree[2*i], self.tree[2*i+1])
def modify(self, pos, val):
assert pos < self.n
pos += self.n
self.tree[pos] = val
while pos > 1:
self.tree[pos//2] = self.op(self.tree[pos], self.tree[pos ^ 1])
pos //= 2
def query(self, L, R):
assert L <= R and L >= 0 and R <= self.n
res = 0
L += self.n
R += self.n
while L < R:
if L % 2 == 1:
res = self.op(res, self.tree[L])
L += 1
if R % 2 == 1:
R -= 1
res = self.op(res, self.tree[R])
L //= 2
R //= 2
return res
def solve(n, heights, beauty):
dp = [0] * (n+1)
st = SegmentTree(dp, op=max)
for flower in range(n):
pos = heights[flower]
val = st.query(0, heights[flower]) + beauty[flower]
st.modify(pos, val)
return st.tree[1]
def main():
n = int(eval(input()))
heights = [int(c) for c in input().split()]
beauty = [int(c) for c in input().split()]
ans = solve(n, heights, beauty)
print(ans)
if __name__ == "__main__":
main()
| 57 | 60 | 1,436 | 1,462 |
import operator
class SegmentTree:
def __init__(self, seq, op=operator.add):
self.n = len(seq)
self.op = op
self.tree = [-1] * self.n + seq
for i in reversed(list(range(1, self.n))):
self.tree[i] = op(self.tree[2 * i], self.tree[2 * i + 1])
def modify(self, pos, val):
assert pos < self.n
pos += self.n
self.tree[pos] = val
while pos > 1:
self.tree[pos // 2] = self.op(self.tree[pos], self.tree[pos ^ 1])
pos //= 2
def query(self, L, R):
assert L <= R and L >= 0 and R <= self.n
res = 0
L += self.n
R += self.n
while L < R:
if L % 2 == 1:
res = self.op(res, self.tree[L])
L += 1
if R % 2 == 1:
R -= 1
res = self.op(res, self.tree[R])
L //= 2
R //= 2
return res
def solve(n, heights, beauty):
st = SegmentTree([0] * (n + 1), op=lambda x, y: max(x, y))
for flower in range(n):
st.modify(heights[flower], st.query(0, heights[flower] + 1) + beauty[flower])
return st.tree[1]
def main():
n = int(eval(input()))
heights = [int(c) for c in input().split()]
beauty = [int(c) for c in input().split()]
ans = solve(n, heights, beauty)
print(ans)
if __name__ == "__main__":
main()
|
import operator
class SegmentTree:
def __init__(self, seq, op=operator.add):
self.n = len(seq)
self.op = op
self.tree = [-1] * self.n + seq
for i in reversed(list(range(1, self.n))):
self.tree[i] = op(self.tree[2 * i], self.tree[2 * i + 1])
def modify(self, pos, val):
assert pos < self.n
pos += self.n
self.tree[pos] = val
while pos > 1:
self.tree[pos // 2] = self.op(self.tree[pos], self.tree[pos ^ 1])
pos //= 2
def query(self, L, R):
assert L <= R and L >= 0 and R <= self.n
res = 0
L += self.n
R += self.n
while L < R:
if L % 2 == 1:
res = self.op(res, self.tree[L])
L += 1
if R % 2 == 1:
R -= 1
res = self.op(res, self.tree[R])
L //= 2
R //= 2
return res
def solve(n, heights, beauty):
dp = [0] * (n + 1)
st = SegmentTree(dp, op=max)
for flower in range(n):
pos = heights[flower]
val = st.query(0, heights[flower]) + beauty[flower]
st.modify(pos, val)
return st.tree[1]
def main():
n = int(eval(input()))
heights = [int(c) for c in input().split()]
beauty = [int(c) for c in input().split()]
ans = solve(n, heights, beauty)
print(ans)
if __name__ == "__main__":
main()
| false | 5 |
[
"- st = SegmentTree([0] * (n + 1), op=lambda x, y: max(x, y))",
"+ dp = [0] * (n + 1)",
"+ st = SegmentTree(dp, op=max)",
"- st.modify(heights[flower], st.query(0, heights[flower] + 1) + beauty[flower])",
"+ pos = heights[flower]",
"+ val = st.query(0, heights[flower]) + beauty[flower]",
"+ st.modify(pos, val)"
] | false | 0.03816 | 0.038169 | 0.999767 |
[
"s638431194",
"s964829700"
] |
u562935282
|
p03503
|
python
|
s155379856
|
s508543781
| 167 | 63 | 3,064 | 3,064 |
Accepted
|
Accepted
| 62.28 |
n = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(n)]#F[i]は(i+1)番目の店の営業の有無のリスト
P = [list(map(int, input().split())) for _ in range(n)]#P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト
ans = (-1) * 10 ** 9
for i in range(2 ** 10):
if sum(map(int, list(str(i)))) == 0:
continue
cnt_lst = [0 for _ in range(n)]
for d in range(5):
for t in range(2):
dt = 2 * d + t
if i & (2 ** dt) != 0:
for j in range(n):
cnt_lst[j] += F[j][dt]
buf = 0
for j in range(n):
buf += P[j][cnt_lst[j]]
ans = max(buf, ans)
print(ans)
|
def main():
from itertools import combinations
N = int(eval(input()))
F = []
for _ in range(N):
t = 0
for j, b in enumerate(map(int, input().split())):
if b:
t |= (1 << j)
F.append(t)
# F[i]:=店舗iの営業時間情報
P = [list(map(int, input().split())) for _ in range(N)]
# P[i]:=店舗iと営業時間が重なる個数に対する利益
ans = -10 ** 9 - 1
for open_ in range(1, 10 + 1):
for comb in combinations(list(range(10)), r=open_):
t = 0
for j in comb:
t |= (1 << j)
p = 0
for i, f in enumerate(F):
x = bin(t & f).count('1')
p += P[i][x]
ans = max(ans, p)
print(ans)
if __name__ == '__main__':
main()
| 20 | 34 | 637 | 799 |
n = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(n)] # F[i]は(i+1)番目の店の営業の有無のリスト
P = [
list(map(int, input().split())) for _ in range(n)
] # P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト
ans = (-1) * 10**9
for i in range(2**10):
if sum(map(int, list(str(i)))) == 0:
continue
cnt_lst = [0 for _ in range(n)]
for d in range(5):
for t in range(2):
dt = 2 * d + t
if i & (2**dt) != 0:
for j in range(n):
cnt_lst[j] += F[j][dt]
buf = 0
for j in range(n):
buf += P[j][cnt_lst[j]]
ans = max(buf, ans)
print(ans)
|
def main():
from itertools import combinations
N = int(eval(input()))
F = []
for _ in range(N):
t = 0
for j, b in enumerate(map(int, input().split())):
if b:
t |= 1 << j
F.append(t)
# F[i]:=店舗iの営業時間情報
P = [list(map(int, input().split())) for _ in range(N)]
# P[i]:=店舗iと営業時間が重なる個数に対する利益
ans = -(10**9) - 1
for open_ in range(1, 10 + 1):
for comb in combinations(list(range(10)), r=open_):
t = 0
for j in comb:
t |= 1 << j
p = 0
for i, f in enumerate(F):
x = bin(t & f).count("1")
p += P[i][x]
ans = max(ans, p)
print(ans)
if __name__ == "__main__":
main()
| false | 41.176471 |
[
"-n = int(eval(input()))",
"-F = [list(map(int, input().split())) for _ in range(n)] # F[i]は(i+1)番目の店の営業の有無のリスト",
"-P = [",
"- list(map(int, input().split())) for _ in range(n)",
"-] # P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト",
"-ans = (-1) * 10**9",
"-for i in range(2**10):",
"- if sum(map(int, list(str(i)))) == 0:",
"- continue",
"- cnt_lst = [0 for _ in range(n)]",
"- for d in range(5):",
"- for t in range(2):",
"- dt = 2 * d + t",
"- if i & (2**dt) != 0:",
"- for j in range(n):",
"- cnt_lst[j] += F[j][dt]",
"- buf = 0",
"- for j in range(n):",
"- buf += P[j][cnt_lst[j]]",
"- ans = max(buf, ans)",
"-print(ans)",
"+def main():",
"+ from itertools import combinations",
"+",
"+ N = int(eval(input()))",
"+ F = []",
"+ for _ in range(N):",
"+ t = 0",
"+ for j, b in enumerate(map(int, input().split())):",
"+ if b:",
"+ t |= 1 << j",
"+ F.append(t)",
"+ # F[i]:=店舗iの営業時間情報",
"+ P = [list(map(int, input().split())) for _ in range(N)]",
"+ # P[i]:=店舗iと営業時間が重なる個数に対する利益",
"+ ans = -(10**9) - 1",
"+ for open_ in range(1, 10 + 1):",
"+ for comb in combinations(list(range(10)), r=open_):",
"+ t = 0",
"+ for j in comb:",
"+ t |= 1 << j",
"+ p = 0",
"+ for i, f in enumerate(F):",
"+ x = bin(t & f).count(\"1\")",
"+ p += P[i][x]",
"+ ans = max(ans, p)",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.045979 | 0.045243 | 1.016253 |
[
"s155379856",
"s508543781"
] |
u761320129
|
p02813
|
python
|
s666519659
|
s268176522
| 45 | 28 | 3,064 | 8,052 |
Accepted
|
Accepted
| 37.78 |
n = int(eval(input()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools
i = 1
for ptn in itertools.permutations(list(range(1,n+1))):
if list(ptn)==p:
a = i
if list(ptn)==q:
b = i
i += 1
print((abs(a-b)))
|
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
from itertools import permutations
l = list(permutations(list(range(1,N+1))))
print((abs(l.index(P) - l.index(Q))))
| 12 | 6 | 262 | 201 |
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
import itertools
i = 1
for ptn in itertools.permutations(list(range(1, n + 1))):
if list(ptn) == p:
a = i
if list(ptn) == q:
b = i
i += 1
print((abs(a - b)))
|
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
from itertools import permutations
l = list(permutations(list(range(1, N + 1))))
print((abs(l.index(P) - l.index(Q))))
| false | 50 |
[
"-n = int(eval(input()))",
"-p = list(map(int, input().split()))",
"-q = list(map(int, input().split()))",
"-import itertools",
"+N = int(eval(input()))",
"+P = tuple(map(int, input().split()))",
"+Q = tuple(map(int, input().split()))",
"+from itertools import permutations",
"-i = 1",
"-for ptn in itertools.permutations(list(range(1, n + 1))):",
"- if list(ptn) == p:",
"- a = i",
"- if list(ptn) == q:",
"- b = i",
"- i += 1",
"-print((abs(a - b)))",
"+l = list(permutations(list(range(1, N + 1))))",
"+print((abs(l.index(P) - l.index(Q))))"
] | false | 0.11435 | 0.109576 | 1.043566 |
[
"s666519659",
"s268176522"
] |
u093861603
|
p03557
|
python
|
s545914681
|
s663475265
| 450 | 344 | 107,108 | 22,720 |
Accepted
|
Accepted
| 23.56 |
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())))
"""
minnum以上で最小の数のindexを返す。無いときはlen(List)を返す
計算量log(len(List))
def bts(List,minnum,under=0):
if List[0]>=minnum:
return under
if List[-1]<minnum:
return len(List)+under
i = int(len(List)/2)
if List[i]>=minnum and List[i-1]<minnum:
return i + under
if List[i]<minnum:
return bts(List[i+1:],minnum,under+i+1)
return bts(List[:i],minnum,under)
"""
def binary_search(list, item):
if list[0]>=item:
return 0
if list[-1]<item:
return len(list)
low = 0
high = len(list) - 1
while low <= high:
mid = (low + high) //2
guess = list[mid]
if guess >= item and list[mid-1] < item:
return mid
if guess >= item:
high = mid -1
else:
low = mid + 1
return None
res = 0
for i in range(N):
b = B[i]
a = binary_search(A,b)
c = N - binary_search(C,b+1)
res += a*c
print(res)
|
import bisect
n=int(eval(input()))
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))
al.sort()
bl.sort()
cl.sort()
ans=0
for b in bl:
ac=bisect.bisect_right(al,b-1)
cc=n-bisect.bisect_left(cl,b+1)
ans+=ac*cc
print(ans)
| 54 | 17 | 1,151 | 296 |
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())))
"""
minnum以上で最小の数のindexを返す。無いときはlen(List)を返す
計算量log(len(List))
def bts(List,minnum,under=0):
if List[0]>=minnum:
return under
if List[-1]<minnum:
return len(List)+under
i = int(len(List)/2)
if List[i]>=minnum and List[i-1]<minnum:
return i + under
if List[i]<minnum:
return bts(List[i+1:],minnum,under+i+1)
return bts(List[:i],minnum,under)
"""
def binary_search(list, item):
if list[0] >= item:
return 0
if list[-1] < item:
return len(list)
low = 0
high = len(list) - 1
while low <= high:
mid = (low + high) // 2
guess = list[mid]
if guess >= item and list[mid - 1] < item:
return mid
if guess >= item:
high = mid - 1
else:
low = mid + 1
return None
res = 0
for i in range(N):
b = B[i]
a = binary_search(A, b)
c = N - binary_search(C, b + 1)
res += a * c
print(res)
|
import bisect
n = int(eval(input()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
ans = 0
for b in bl:
ac = bisect.bisect_right(al, b - 1)
cc = n - bisect.bisect_left(cl, b + 1)
ans += ac * cc
print(ans)
| false | 68.518519 |
[
"-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())))",
"-\"\"\"",
"-minnum以上で最小の数のindexを返す。無いときはlen(List)を返す",
"-計算量log(len(List))",
"-def bts(List,minnum,under=0):",
"- if List[0]>=minnum:",
"- return under",
"- if List[-1]<minnum:",
"- return len(List)+under",
"- i = int(len(List)/2)",
"- if List[i]>=minnum and List[i-1]<minnum:",
"- return i + under",
"- if List[i]<minnum:",
"- return bts(List[i+1:],minnum,under+i+1)",
"- return bts(List[:i],minnum,under)",
"-\"\"\"",
"+import bisect",
"-",
"-def binary_search(list, item):",
"- if list[0] >= item:",
"- return 0",
"- if list[-1] < item:",
"- return len(list)",
"- low = 0",
"- high = len(list) - 1",
"- while low <= high:",
"- mid = (low + high) // 2",
"- guess = list[mid]",
"- if guess >= item and list[mid - 1] < item:",
"- return mid",
"- if guess >= item:",
"- high = mid - 1",
"- else:",
"- low = mid + 1",
"- return None",
"-",
"-",
"-res = 0",
"-for i in range(N):",
"- b = B[i]",
"- a = binary_search(A, b)",
"- c = N - binary_search(C, b + 1)",
"- res += a * c",
"-print(res)",
"+n = int(eval(input()))",
"+al = list(map(int, input().split()))",
"+bl = list(map(int, input().split()))",
"+cl = list(map(int, input().split()))",
"+al.sort()",
"+bl.sort()",
"+cl.sort()",
"+ans = 0",
"+for b in bl:",
"+ ac = bisect.bisect_right(al, b - 1)",
"+ cc = n - bisect.bisect_left(cl, b + 1)",
"+ ans += ac * cc",
"+print(ans)"
] | false | 0.043528 | 0.084563 | 0.51474 |
[
"s545914681",
"s663475265"
] |
u426534722
|
p02237
|
python
|
s358295286
|
s880570537
| 30 | 20 | 8,448 | 6,380 |
Accepted
|
Accepted
| 33.33 |
from sys import stdin
n = int(stdin.readline())
v = [[0] * n for _ in range(n)]
for u in range(n):
l = [int(j) for j in stdin.readline().split()]
for k in l[2:]:
v[u][k - 1] = 1
print((*v[u]))
|
n = int(eval(input()))
MAP = [[0] * n for _ in range(n)]
for i in range(n):
u, k, *v = list(map(int, input().split()))
for j in v:
MAP[u - 1][j - 1] = 1
for m in MAP:
print((*m))
| 8 | 9 | 217 | 194 |
from sys import stdin
n = int(stdin.readline())
v = [[0] * n for _ in range(n)]
for u in range(n):
l = [int(j) for j in stdin.readline().split()]
for k in l[2:]:
v[u][k - 1] = 1
print((*v[u]))
|
n = int(eval(input()))
MAP = [[0] * n for _ in range(n)]
for i in range(n):
u, k, *v = list(map(int, input().split()))
for j in v:
MAP[u - 1][j - 1] = 1
for m in MAP:
print((*m))
| false | 11.111111 |
[
"-from sys import stdin",
"-",
"-n = int(stdin.readline())",
"-v = [[0] * n for _ in range(n)]",
"-for u in range(n):",
"- l = [int(j) for j in stdin.readline().split()]",
"- for k in l[2:]:",
"- v[u][k - 1] = 1",
"- print((*v[u]))",
"+n = int(eval(input()))",
"+MAP = [[0] * n for _ in range(n)]",
"+for i in range(n):",
"+ u, k, *v = list(map(int, input().split()))",
"+ for j in v:",
"+ MAP[u - 1][j - 1] = 1",
"+for m in MAP:",
"+ print((*m))"
] | false | 0.041284 | 0.089622 | 0.460651 |
[
"s358295286",
"s880570537"
] |
u345621867
|
p03031
|
python
|
s324909985
|
s779877529
| 45 | 39 | 9,200 | 9,144 |
Accepted
|
Accepted
| 13.33 |
N, M = list(map(int,input().split()))
K = []
S = []
for i in range(M):
k = 0
s = []
k, *s = list(map(int,input().split()))
K.append(k)
S.append(s)
P = list(map(int,input().split()))
res = 0
for bit in range(1 << N):
judge = True
for i in range(M):
cnt = 0
for s in S[i]:
cnt += (bit >> s-1) & 1
if cnt % 2 != P[i]:
judge = False
if judge:
res += 1
print(res)
|
N, M = list(map(int,input().split()))
K = []
S = []
for i in range(M):
k = 0
s = []
k, *s = list(map(int,input().split()))
K.append(k)
S.append(s)
P = list(map(int,input().split()))
res = 0
for bit in range(1 << N):
judge = True
for i in range(M):
cnt = 0
for s in S[i]:
cnt += (bit >> s-1) & 1
if cnt % 2 != P[i]:
judge = False
break
if judge:
res += 1
print(res)
| 22 | 23 | 455 | 474 |
N, M = list(map(int, input().split()))
K = []
S = []
for i in range(M):
k = 0
s = []
k, *s = list(map(int, input().split()))
K.append(k)
S.append(s)
P = list(map(int, input().split()))
res = 0
for bit in range(1 << N):
judge = True
for i in range(M):
cnt = 0
for s in S[i]:
cnt += (bit >> s - 1) & 1
if cnt % 2 != P[i]:
judge = False
if judge:
res += 1
print(res)
|
N, M = list(map(int, input().split()))
K = []
S = []
for i in range(M):
k = 0
s = []
k, *s = list(map(int, input().split()))
K.append(k)
S.append(s)
P = list(map(int, input().split()))
res = 0
for bit in range(1 << N):
judge = True
for i in range(M):
cnt = 0
for s in S[i]:
cnt += (bit >> s - 1) & 1
if cnt % 2 != P[i]:
judge = False
break
if judge:
res += 1
print(res)
| false | 4.347826 |
[
"+ break"
] | false | 0.103908 | 0.067362 | 1.542526 |
[
"s324909985",
"s779877529"
] |
u358254559
|
p04000
|
python
|
s526296343
|
s468061454
| 1,633 | 1,336 | 230,392 | 228,860 |
Accepted
|
Accepted
| 18.19 |
h,w,n = list(map(int, input().split()))
l=[list(map(int,input().split())) for i in range(n)]
from collections import defaultdict
d = defaultdict(int)
for tmp in l:
y=tmp[0]-1
x=tmp[1]-1
for i in [-1,0,1]:
for j in [-1,0,1]:
if 1<=x+i<w-1 and 1<=y+j <h-1:
s = str(x+i) + "_" + str(y+j)
d[s]+=1
import collections
lis = list(d.values())
c = collections.Counter(lis)
ans=[0]*10
for itm in list(c.items()):
ans[itm[0]]=itm[1]
ans[0]=(h-2)*(w-2)-sum(ans)
for a in ans:
print(a)
|
import sys
input=sys.stdin.readline
h,w,n = list(map(int, input().split()))
l=[list(map(int,input().split())) for i in range(n)]
from collections import defaultdict
d = defaultdict(int)
for tmp in l:
y=tmp[0]-1
x=tmp[1]-1
for i in [-1,0,1]:
for j in [-1,0,1]:
if 1<=x+i<w-1 and 1<=y+j <h-1:
s = str(x+i) + "_" + str(y+j)
d[s]+=1
import collections
lis = list(d.values())
c = collections.Counter(lis)
ans=[0]*10
for itm in list(c.items()):
ans[itm[0]]=itm[1]
ans[0]=(h-2)*(w-2)-sum(ans)
for a in ans:
print(a)
| 26 | 28 | 562 | 600 |
h, w, n = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
from collections import defaultdict
d = defaultdict(int)
for tmp in l:
y = tmp[0] - 1
x = tmp[1] - 1
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if 1 <= x + i < w - 1 and 1 <= y + j < h - 1:
s = str(x + i) + "_" + str(y + j)
d[s] += 1
import collections
lis = list(d.values())
c = collections.Counter(lis)
ans = [0] * 10
for itm in list(c.items()):
ans[itm[0]] = itm[1]
ans[0] = (h - 2) * (w - 2) - sum(ans)
for a in ans:
print(a)
|
import sys
input = sys.stdin.readline
h, w, n = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
from collections import defaultdict
d = defaultdict(int)
for tmp in l:
y = tmp[0] - 1
x = tmp[1] - 1
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
if 1 <= x + i < w - 1 and 1 <= y + j < h - 1:
s = str(x + i) + "_" + str(y + j)
d[s] += 1
import collections
lis = list(d.values())
c = collections.Counter(lis)
ans = [0] * 10
for itm in list(c.items()):
ans[itm[0]] = itm[1]
ans[0] = (h - 2) * (w - 2) - sum(ans)
for a in ans:
print(a)
| false | 7.142857 |
[
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.044294 | 0.044316 | 0.999512 |
[
"s526296343",
"s468061454"
] |
u588341295
|
p04048
|
python
|
s506231618
|
s311931212
| 52 | 18 | 5,556 | 3,064 |
Accepted
|
Accepted
| 65.38 |
# -*- coding: utf-8 -*-
import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, X = MAP()
print(((N-gcd(N, X))*3))
|
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, X = MAP()
# 最初のN以外は、平行四辺形を小さくしていくと考える
def rec(a, b):
a, b = min(a, b), max(a, b)
if a == 0:
# 最後に割り切れた時は半分でいいので減らす
return -b
# 同じだけ小さくする所はまとめてやる
return a*2*(b//a) + rec(a, b%a)
print((N+rec(X, N-X)))
| 25 | 32 | 827 | 947 |
# -*- coding: utf-8 -*-
import sys
if sys.version_info.minor >= 5:
from math import gcd
else:
from fractions import gcd
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N, X = MAP()
print(((N - gcd(N, X)) * 3))
|
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N, X = MAP()
# 最初のN以外は、平行四辺形を小さくしていくと考える
def rec(a, b):
a, b = min(a, b), max(a, b)
if a == 0:
# 最後に割り切れた時は半分でいいので減らす
return -b
# 同じだけ小さくする所はまとめてやる
return a * 2 * (b // a) + rec(a, b % a)
print((N + rec(X, N - X)))
| false | 21.875 |
[
"-",
"-if sys.version_info.minor >= 5:",
"- from math import gcd",
"-else:",
"- from fractions import gcd",
"-print(((N - gcd(N, X)) * 3))",
"+# 最初のN以外は、平行四辺形を小さくしていくと考える",
"+def rec(a, b):",
"+ a, b = min(a, b), max(a, b)",
"+ if a == 0:",
"+ # 最後に割り切れた時は半分でいいので減らす",
"+ return -b",
"+ # 同じだけ小さくする所はまとめてやる",
"+ return a * 2 * (b // a) + rec(a, b % a)",
"+",
"+",
"+print((N + rec(X, N - X)))"
] | false | 0.039715 | 0.043188 | 0.91958 |
[
"s506231618",
"s311931212"
] |
u094191970
|
p03295
|
python
|
s258156343
|
s951964795
| 526 | 457 | 28,764 | 29,920 |
Accepted
|
Accepted
| 13.12 |
n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
for i in l:
i[0],i[1]=i[1],i[0]
ll=sorted(l)
x,cnt=ll[0][0],1
for i in ll:
a=i[1]
b=i[0]
if a>=x:
cnt+=1
x=b
print(cnt)
|
from operator import itemgetter
n,m=list(map(int,input().split()))
l=sorted([list(map(int,input().split())) for i in range(m)],key=itemgetter(1))
x,cnt=l[0][1],1
for i in l:
a=i[0]
b=i[1]
if a>=x:
cnt+=1
x=b
print(cnt)
| 13 | 12 | 245 | 252 |
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
for i in l:
i[0], i[1] = i[1], i[0]
ll = sorted(l)
x, cnt = ll[0][0], 1
for i in ll:
a = i[1]
b = i[0]
if a >= x:
cnt += 1
x = b
print(cnt)
|
from operator import itemgetter
n, m = list(map(int, input().split()))
l = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1))
x, cnt = l[0][1], 1
for i in l:
a = i[0]
b = i[1]
if a >= x:
cnt += 1
x = b
print(cnt)
| false | 7.692308 |
[
"+from operator import itemgetter",
"+",
"-l = [list(map(int, input().split())) for i in range(m)]",
"+l = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1))",
"+x, cnt = l[0][1], 1",
"- i[0], i[1] = i[1], i[0]",
"-ll = sorted(l)",
"-x, cnt = ll[0][0], 1",
"-for i in ll:",
"- a = i[1]",
"- b = i[0]",
"+ a = i[0]",
"+ b = i[1]"
] | false | 0.099116 | 0.158611 | 0.624897 |
[
"s258156343",
"s951964795"
] |
u222668979
|
p02616
|
python
|
s188013663
|
s662309398
| 266 | 238 | 33,304 | 31,684 |
Accepted
|
Accepted
| 10.53 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt *= mia.pop()
elif len(pla) > 0:
cnt *= pla.pop()
k -= 1
elif len(pla) <= 1:
cnt *= mia.pop() * mia.pop()
k -= 2
elif len(pla) >= 2 and len(mia) >= 2:
if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt *= pla.pop()
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt *= mia.pop() * mia.pop()
k -= 2
cnt %= mod
print(cnt)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt *= mia.pop()
elif len(pla) > 0:
cnt *= pla.pop()
k -= 1
elif len(pla) <= 1:
cnt *= mia.pop() * mia.pop()
k -= 2
elif pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt *= pla.pop()
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt *= mia.pop() * mia.pop()
k -= 2
cnt %= mod
print(cnt)
| 31 | 30 | 905 | 836 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9 + 7
mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt *= mia.pop()
elif len(pla) > 0:
cnt *= pla.pop()
k -= 1
elif len(pla) <= 1:
cnt *= mia.pop() * mia.pop()
k -= 2
elif len(pla) >= 2 and len(mia) >= 2:
if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt *= pla.pop()
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt *= mia.pop() * mia.pop()
k -= 2
cnt %= mod
print(cnt)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9 + 7
mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt *= mia.pop()
elif len(pla) > 0:
cnt *= pla.pop()
k -= 1
elif len(pla) <= 1:
cnt *= mia.pop() * mia.pop()
k -= 2
elif pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt *= pla.pop()
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt *= mia.pop() * mia.pop()
k -= 2
cnt %= mod
print(cnt)
| false | 3.225806 |
[
"- elif len(pla) >= 2 and len(mia) >= 2:",
"- if pla[-1] * pla[-2] > mia[-1] * mia[-2]:",
"- cnt *= pla.pop()",
"- k -= 1",
"- elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:",
"- cnt *= mia.pop() * mia.pop()",
"- k -= 2",
"+ elif pla[-1] * pla[-2] > mia[-1] * mia[-2]:",
"+ cnt *= pla.pop()",
"+ k -= 1",
"+ elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:",
"+ cnt *= mia.pop() * mia.pop()",
"+ k -= 2"
] | false | 0.039387 | 0.044694 | 0.881252 |
[
"s188013663",
"s662309398"
] |
u260036763
|
p03478
|
python
|
s041839430
|
s240940551
| 33 | 28 | 2,940 | 2,940 |
Accepted
|
Accepted
| 15.15 |
n, a, b = list(map(int, input().split()))
sum = 0
for i in range(1, n+1):
isum = 0
m = i
for j in range(5):
isum += m%10
m //= 10
if a <= isum <= b:
sum += i
print(sum)
|
n, a, b = list(map(int, input().split()))
sum = 0
for i in range(1, n+1):
isum = 0
m = i
while m != 0:
isum += m%10
m //= 10
if a <= isum <= b:
sum += i
print(sum)
| 11 | 11 | 193 | 188 |
n, a, b = list(map(int, input().split()))
sum = 0
for i in range(1, n + 1):
isum = 0
m = i
for j in range(5):
isum += m % 10
m //= 10
if a <= isum <= b:
sum += i
print(sum)
|
n, a, b = list(map(int, input().split()))
sum = 0
for i in range(1, n + 1):
isum = 0
m = i
while m != 0:
isum += m % 10
m //= 10
if a <= isum <= b:
sum += i
print(sum)
| false | 0 |
[
"- for j in range(5):",
"+ while m != 0:"
] | false | 0.091988 | 0.007588 | 12.123128 |
[
"s041839430",
"s240940551"
] |
u977193988
|
p03018
|
python
|
s082024532
|
s554513828
| 62 | 46 | 5,864 | 3,500 |
Accepted
|
Accepted
| 25.81 |
import re
s=eval(input())
ss=s.replace('BC','D')
sss=re.split('[BC]',ss)
ans=0
for i in sss:
acnt=0
for g in i:
if g=='A':
acnt+=1
else:
ans+=acnt
print(ans)
|
s=eval(input())
s=s.replace('BC','D')
ans=0
cnt=0
for i in s:
if i=='A':
cnt+=1
elif i=='D':
ans+=cnt
else:
cnt=0
print(ans)
| 13 | 13 | 212 | 168 |
import re
s = eval(input())
ss = s.replace("BC", "D")
sss = re.split("[BC]", ss)
ans = 0
for i in sss:
acnt = 0
for g in i:
if g == "A":
acnt += 1
else:
ans += acnt
print(ans)
|
s = eval(input())
s = s.replace("BC", "D")
ans = 0
cnt = 0
for i in s:
if i == "A":
cnt += 1
elif i == "D":
ans += cnt
else:
cnt = 0
print(ans)
| false | 0 |
[
"-import re",
"-",
"-ss = s.replace(\"BC\", \"D\")",
"-sss = re.split(\"[BC]\", ss)",
"+s = s.replace(\"BC\", \"D\")",
"-for i in sss:",
"- acnt = 0",
"- for g in i:",
"- if g == \"A\":",
"- acnt += 1",
"- else:",
"- ans += acnt",
"+cnt = 0",
"+for i in s:",
"+ if i == \"A\":",
"+ cnt += 1",
"+ elif i == \"D\":",
"+ ans += cnt",
"+ else:",
"+ cnt = 0"
] | false | 0.039181 | 0.033017 | 1.186697 |
[
"s082024532",
"s554513828"
] |
u894114233
|
p00146
|
python
|
s126234342
|
s143080918
| 4,450 | 3,540 | 27,408 | 27,320 |
Accepted
|
Accepted
| 20.45 |
def calctime(w,dist):
time=dist/(2000/(70.0+w))
return time
n=int(input())
s={}
d={}
v={}
for i in range(n):
S,D,V=list(map(int,input().split()))
s[i]=S
d[i]=D
v[i]=V
dist=[[None]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if i==j:
dist[i][j]=float('inf')
else:
dist[i][j]=abs(d[i]-d[j])
w=[float('inf')]*(1<<n)
time=[[float('inf')]*n for _ in range(1<<n)]
last=[[0]*n for _ in range(1<<n)]
for i in range(n):
time[1<<i][i]=0
w[1<<i]=v[i]*20
for i in range(1,1<<n):
for j in range(n):
if w[i]==float('inf'):continue
for k in range(n):
if not i>>k&1:
nexti=i|(1<<k)
w[nexti]=w[i]+v[k]*20
if time[nexti][k]>calctime(w[i],dist[j][k])+time[i][j]:
time[nexti][k]=calctime(w[i],dist[j][k])+time[i][j]
last[nexti][k]=j
ans=[]
now=(1<<n)-1
last_index=time[now].index(min(time[now]))
while now!=0:
ans.append(s[last_index])
nx=last[now][last_index]
now=now^(1<<last_index)
last_index=nx
ans.reverse()
print((' '.join(map(str,ans))))
|
def calctime(w,dist):
time=dist/(2000/(70.0+w))
return time
def solve():
dist=[[None]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if i==j:
dist[i][j]=float('inf')
else:
dist[i][j]=abs(d[i]-d[j])
w=[float('inf')]*(1<<n)
time=[[float('inf')]*n for _ in range(1<<n)]
last=[[0]*n for _ in range(1<<n)]
for i in range(n):
time[1<<i][i]=0
w[1<<i]=v[i]*20
for i in range(1,1<<n):
for j in range(n):
if w[i]==float('inf'):continue
for k in range(n):
if not i>>k&1:
nexti=i|(1<<k)
w[nexti]=w[i]+v[k]*20
if time[nexti][k]>calctime(w[i],dist[j][k])+time[i][j]:
time[nexti][k]=calctime(w[i],dist[j][k])+time[i][j]
last[nexti][k]=j
ans=[]
now=(1<<n)-1
last_index=time[now].index(min(time[now]))
while now!=0:
ans.append(s[last_index])
nx=last[now][last_index]
now=now^(1<<last_index)
last_index=nx
ans.reverse()
return ans
n=int(input())
s={}
d={}
v={}
for i in range(n):
S,D,V=list(map(int,input().split()))
s[i]=S
d[i]=D
v[i]=V
ans=solve()
print((' '.join(map(str,ans))))
| 50 | 54 | 1,215 | 1,388 |
def calctime(w, dist):
time = dist / (2000 / (70.0 + w))
return time
n = int(input())
s = {}
d = {}
v = {}
for i in range(n):
S, D, V = list(map(int, input().split()))
s[i] = S
d[i] = D
v[i] = V
dist = [[None] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if i == j:
dist[i][j] = float("inf")
else:
dist[i][j] = abs(d[i] - d[j])
w = [float("inf")] * (1 << n)
time = [[float("inf")] * n for _ in range(1 << n)]
last = [[0] * n for _ in range(1 << n)]
for i in range(n):
time[1 << i][i] = 0
w[1 << i] = v[i] * 20
for i in range(1, 1 << n):
for j in range(n):
if w[i] == float("inf"):
continue
for k in range(n):
if not i >> k & 1:
nexti = i | (1 << k)
w[nexti] = w[i] + v[k] * 20
if time[nexti][k] > calctime(w[i], dist[j][k]) + time[i][j]:
time[nexti][k] = calctime(w[i], dist[j][k]) + time[i][j]
last[nexti][k] = j
ans = []
now = (1 << n) - 1
last_index = time[now].index(min(time[now]))
while now != 0:
ans.append(s[last_index])
nx = last[now][last_index]
now = now ^ (1 << last_index)
last_index = nx
ans.reverse()
print((" ".join(map(str, ans))))
|
def calctime(w, dist):
time = dist / (2000 / (70.0 + w))
return time
def solve():
dist = [[None] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if i == j:
dist[i][j] = float("inf")
else:
dist[i][j] = abs(d[i] - d[j])
w = [float("inf")] * (1 << n)
time = [[float("inf")] * n for _ in range(1 << n)]
last = [[0] * n for _ in range(1 << n)]
for i in range(n):
time[1 << i][i] = 0
w[1 << i] = v[i] * 20
for i in range(1, 1 << n):
for j in range(n):
if w[i] == float("inf"):
continue
for k in range(n):
if not i >> k & 1:
nexti = i | (1 << k)
w[nexti] = w[i] + v[k] * 20
if time[nexti][k] > calctime(w[i], dist[j][k]) + time[i][j]:
time[nexti][k] = calctime(w[i], dist[j][k]) + time[i][j]
last[nexti][k] = j
ans = []
now = (1 << n) - 1
last_index = time[now].index(min(time[now]))
while now != 0:
ans.append(s[last_index])
nx = last[now][last_index]
now = now ^ (1 << last_index)
last_index = nx
ans.reverse()
return ans
n = int(input())
s = {}
d = {}
v = {}
for i in range(n):
S, D, V = list(map(int, input().split()))
s[i] = S
d[i] = D
v[i] = V
ans = solve()
print((" ".join(map(str, ans))))
| false | 7.407407 |
[
"+",
"+",
"+def solve():",
"+ dist = [[None] * n for _ in range(n)]",
"+ for i in range(n):",
"+ for j in range(n):",
"+ if i == j:",
"+ dist[i][j] = float(\"inf\")",
"+ else:",
"+ dist[i][j] = abs(d[i] - d[j])",
"+ w = [float(\"inf\")] * (1 << n)",
"+ time = [[float(\"inf\")] * n for _ in range(1 << n)]",
"+ last = [[0] * n for _ in range(1 << n)]",
"+ for i in range(n):",
"+ time[1 << i][i] = 0",
"+ w[1 << i] = v[i] * 20",
"+ for i in range(1, 1 << n):",
"+ for j in range(n):",
"+ if w[i] == float(\"inf\"):",
"+ continue",
"+ for k in range(n):",
"+ if not i >> k & 1:",
"+ nexti = i | (1 << k)",
"+ w[nexti] = w[i] + v[k] * 20",
"+ if time[nexti][k] > calctime(w[i], dist[j][k]) + time[i][j]:",
"+ time[nexti][k] = calctime(w[i], dist[j][k]) + time[i][j]",
"+ last[nexti][k] = j",
"+ ans = []",
"+ now = (1 << n) - 1",
"+ last_index = time[now].index(min(time[now]))",
"+ while now != 0:",
"+ ans.append(s[last_index])",
"+ nx = last[now][last_index]",
"+ now = now ^ (1 << last_index)",
"+ last_index = nx",
"+ ans.reverse()",
"+ return ans",
"-dist = [[None] * n for _ in range(n)]",
"-for i in range(n):",
"- for j in range(n):",
"- if i == j:",
"- dist[i][j] = float(\"inf\")",
"- else:",
"- dist[i][j] = abs(d[i] - d[j])",
"-w = [float(\"inf\")] * (1 << n)",
"-time = [[float(\"inf\")] * n for _ in range(1 << n)]",
"-last = [[0] * n for _ in range(1 << n)]",
"-for i in range(n):",
"- time[1 << i][i] = 0",
"- w[1 << i] = v[i] * 20",
"-for i in range(1, 1 << n):",
"- for j in range(n):",
"- if w[i] == float(\"inf\"):",
"- continue",
"- for k in range(n):",
"- if not i >> k & 1:",
"- nexti = i | (1 << k)",
"- w[nexti] = w[i] + v[k] * 20",
"- if time[nexti][k] > calctime(w[i], dist[j][k]) + time[i][j]:",
"- time[nexti][k] = calctime(w[i], dist[j][k]) + time[i][j]",
"- last[nexti][k] = j",
"-ans = []",
"-now = (1 << n) - 1",
"-last_index = time[now].index(min(time[now]))",
"-while now != 0:",
"- ans.append(s[last_index])",
"- nx = last[now][last_index]",
"- now = now ^ (1 << last_index)",
"- last_index = nx",
"-ans.reverse()",
"+ans = solve()"
] | false | 0.03777 | 0.037259 | 1.01373 |
[
"s126234342",
"s143080918"
] |
u042105122
|
p03078
|
python
|
s240281412
|
s865253006
| 508 | 40 | 5,648 | 5,448 |
Accepted
|
Accepted
| 92.13 |
def main():
buf = eval(input())
buflist = buf.split()
X = int(buflist[0])
Y = int(buflist[1])
Z = int(buflist[2])
K = int(buflist[3])
buf = eval(input())
buflist = buf.split()
A = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
B = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
C = list(map(int, buflist))
A = list(sorted(A, reverse=True))
B = list(sorted(B, reverse=True))
C = list(sorted(C, reverse=True))
cakelist = [(A[0]+B[0]+C[0], 0, 0, 0)]
hashtable = {(A[0]+B[0]+C[0], 0, 0, 0)}
tastiness = []
while len(tastiness) < K:
current = cakelist.pop()
tastiness.append(current[0])
if current[1] < len(A)-1:
if (A[current[1]+1]+B[current[2]]+C[current[3]], current[1]+1, current[2], current[3]) not in hashtable:
cakelist.append((A[current[1]+1]+B[current[2]]+C[current[3]], current[1]+1, current[2], current[3]))
hashtable.add((A[current[1]+1]+B[current[2]]+C[current[3]], current[1]+1, current[2], current[3]))
if current[2] < len(B)-1:
if (A[current[1]]+B[current[2]+1]+C[current[3]], current[1], current[2]+1, current[3]) not in hashtable:
cakelist.append((A[current[1]]+B[current[2]+1]+C[current[3]], current[1], current[2]+1, current[3]))
hashtable.add((A[current[1]]+B[current[2]+1]+C[current[3]], current[1], current[2]+1, current[3]))
if current[3] < len(C)-1:
if (A[current[1]]+B[current[2]]+C[current[3]+1], current[1], current[2], current[3]+1) not in hashtable:
cakelist.append((A[current[1]]+B[current[2]]+C[current[3]+1], current[1], current[2], current[3]+1))
hashtable.add((A[current[1]]+B[current[2]]+C[current[3]+1], current[1], current[2], current[3]+1))
cakelist = list(sorted(cakelist))
for i in tastiness:
print(i)
if __name__ == '__main__':
main()
|
import heapq
def main():
buf = eval(input())
buflist = buf.split()
X = int(buflist[0])
Y = int(buflist[1])
Z = int(buflist[2])
K = int(buflist[3])
buf = eval(input())
buflist = buf.split()
A = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
B = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
C = list(map(int, buflist))
A = list(sorted(A, reverse=True))
B = list(sorted(B, reverse=True))
C = list(sorted(C, reverse=True))
cakeheap = [(-(A[0]+B[0]+C[0]), 0, 0, 0)]
hashtable = {(-(A[0]+B[0]+C[0]), 0, 0, 0)}
tastiness = []
while len(tastiness) < K:
current = heapq.heappop(cakeheap)
tastiness.append(-current[0])
if current[1] < len(A)-1:
if (-(A[current[1]+1]+B[current[2]]+C[current[3]]), current[1]+1, current[2], current[3]) not in hashtable:
heapq.heappush(cakeheap, (-(A[current[1]+1]+B[current[2]]+C[current[3]]), current[1]+1, current[2], current[3]))
hashtable.add((-(A[current[1]+1]+B[current[2]]+C[current[3]]), current[1]+1, current[2], current[3]))
if current[2] < len(B)-1:
if (-(A[current[1]]+B[current[2]+1]+C[current[3]]), current[1], current[2]+1, current[3]) not in hashtable:
heapq.heappush(cakeheap, (-(A[current[1]]+B[current[2]+1]+C[current[3]]), current[1], current[2]+1, current[3]))
hashtable.add((-(A[current[1]]+B[current[2]+1]+C[current[3]]), current[1], current[2]+1, current[3]))
if current[3] < len(C)-1:
if (-(A[current[1]]+B[current[2]]+C[current[3]+1]), current[1], current[2], current[3]+1) not in hashtable:
heapq.heappush(cakeheap, (-(A[current[1]]+B[current[2]]+C[current[3]+1]), current[1], current[2], current[3]+1))
hashtable.add((-(A[current[1]]+B[current[2]]+C[current[3]+1]), current[1], current[2], current[3]+1))
for i in tastiness:
print(i)
if __name__ == '__main__':
main()
| 45 | 45 | 2,017 | 2,058 |
def main():
buf = eval(input())
buflist = buf.split()
X = int(buflist[0])
Y = int(buflist[1])
Z = int(buflist[2])
K = int(buflist[3])
buf = eval(input())
buflist = buf.split()
A = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
B = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
C = list(map(int, buflist))
A = list(sorted(A, reverse=True))
B = list(sorted(B, reverse=True))
C = list(sorted(C, reverse=True))
cakelist = [(A[0] + B[0] + C[0], 0, 0, 0)]
hashtable = {(A[0] + B[0] + C[0], 0, 0, 0)}
tastiness = []
while len(tastiness) < K:
current = cakelist.pop()
tastiness.append(current[0])
if current[1] < len(A) - 1:
if (
A[current[1] + 1] + B[current[2]] + C[current[3]],
current[1] + 1,
current[2],
current[3],
) not in hashtable:
cakelist.append(
(
A[current[1] + 1] + B[current[2]] + C[current[3]],
current[1] + 1,
current[2],
current[3],
)
)
hashtable.add(
(
A[current[1] + 1] + B[current[2]] + C[current[3]],
current[1] + 1,
current[2],
current[3],
)
)
if current[2] < len(B) - 1:
if (
A[current[1]] + B[current[2] + 1] + C[current[3]],
current[1],
current[2] + 1,
current[3],
) not in hashtable:
cakelist.append(
(
A[current[1]] + B[current[2] + 1] + C[current[3]],
current[1],
current[2] + 1,
current[3],
)
)
hashtable.add(
(
A[current[1]] + B[current[2] + 1] + C[current[3]],
current[1],
current[2] + 1,
current[3],
)
)
if current[3] < len(C) - 1:
if (
A[current[1]] + B[current[2]] + C[current[3] + 1],
current[1],
current[2],
current[3] + 1,
) not in hashtable:
cakelist.append(
(
A[current[1]] + B[current[2]] + C[current[3] + 1],
current[1],
current[2],
current[3] + 1,
)
)
hashtable.add(
(
A[current[1]] + B[current[2]] + C[current[3] + 1],
current[1],
current[2],
current[3] + 1,
)
)
cakelist = list(sorted(cakelist))
for i in tastiness:
print(i)
if __name__ == "__main__":
main()
|
import heapq
def main():
buf = eval(input())
buflist = buf.split()
X = int(buflist[0])
Y = int(buflist[1])
Z = int(buflist[2])
K = int(buflist[3])
buf = eval(input())
buflist = buf.split()
A = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
B = list(map(int, buflist))
buf = eval(input())
buflist = buf.split()
C = list(map(int, buflist))
A = list(sorted(A, reverse=True))
B = list(sorted(B, reverse=True))
C = list(sorted(C, reverse=True))
cakeheap = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
hashtable = {(-(A[0] + B[0] + C[0]), 0, 0, 0)}
tastiness = []
while len(tastiness) < K:
current = heapq.heappop(cakeheap)
tastiness.append(-current[0])
if current[1] < len(A) - 1:
if (
-(A[current[1] + 1] + B[current[2]] + C[current[3]]),
current[1] + 1,
current[2],
current[3],
) not in hashtable:
heapq.heappush(
cakeheap,
(
-(A[current[1] + 1] + B[current[2]] + C[current[3]]),
current[1] + 1,
current[2],
current[3],
),
)
hashtable.add(
(
-(A[current[1] + 1] + B[current[2]] + C[current[3]]),
current[1] + 1,
current[2],
current[3],
)
)
if current[2] < len(B) - 1:
if (
-(A[current[1]] + B[current[2] + 1] + C[current[3]]),
current[1],
current[2] + 1,
current[3],
) not in hashtable:
heapq.heappush(
cakeheap,
(
-(A[current[1]] + B[current[2] + 1] + C[current[3]]),
current[1],
current[2] + 1,
current[3],
),
)
hashtable.add(
(
-(A[current[1]] + B[current[2] + 1] + C[current[3]]),
current[1],
current[2] + 1,
current[3],
)
)
if current[3] < len(C) - 1:
if (
-(A[current[1]] + B[current[2]] + C[current[3] + 1]),
current[1],
current[2],
current[3] + 1,
) not in hashtable:
heapq.heappush(
cakeheap,
(
-(A[current[1]] + B[current[2]] + C[current[3] + 1]),
current[1],
current[2],
current[3] + 1,
),
)
hashtable.add(
(
-(A[current[1]] + B[current[2]] + C[current[3] + 1]),
current[1],
current[2],
current[3] + 1,
)
)
for i in tastiness:
print(i)
if __name__ == "__main__":
main()
| false | 0 |
[
"+import heapq",
"+",
"+",
"- cakelist = [(A[0] + B[0] + C[0], 0, 0, 0)]",
"- hashtable = {(A[0] + B[0] + C[0], 0, 0, 0)}",
"+ cakeheap = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]",
"+ hashtable = {(-(A[0] + B[0] + C[0]), 0, 0, 0)}",
"- current = cakelist.pop()",
"- tastiness.append(current[0])",
"+ current = heapq.heappop(cakeheap)",
"+ tastiness.append(-current[0])",
"- A[current[1] + 1] + B[current[2]] + C[current[3]],",
"+ -(A[current[1] + 1] + B[current[2]] + C[current[3]]),",
"- cakelist.append(",
"+ heapq.heappush(",
"+ cakeheap,",
"- A[current[1] + 1] + B[current[2]] + C[current[3]],",
"+ -(A[current[1] + 1] + B[current[2]] + C[current[3]]),",
"- )",
"+ ),",
"- A[current[1] + 1] + B[current[2]] + C[current[3]],",
"+ -(A[current[1] + 1] + B[current[2]] + C[current[3]]),",
"- A[current[1]] + B[current[2] + 1] + C[current[3]],",
"+ -(A[current[1]] + B[current[2] + 1] + C[current[3]]),",
"- cakelist.append(",
"+ heapq.heappush(",
"+ cakeheap,",
"- A[current[1]] + B[current[2] + 1] + C[current[3]],",
"+ -(A[current[1]] + B[current[2] + 1] + C[current[3]]),",
"- )",
"+ ),",
"- A[current[1]] + B[current[2] + 1] + C[current[3]],",
"+ -(A[current[1]] + B[current[2] + 1] + C[current[3]]),",
"- A[current[1]] + B[current[2]] + C[current[3] + 1],",
"+ -(A[current[1]] + B[current[2]] + C[current[3] + 1]),",
"- cakelist.append(",
"+ heapq.heappush(",
"+ cakeheap,",
"- A[current[1]] + B[current[2]] + C[current[3] + 1],",
"+ -(A[current[1]] + B[current[2]] + C[current[3] + 1]),",
"+ current[1],",
"+ current[2],",
"+ current[3] + 1,",
"+ ),",
"+ )",
"+ hashtable.add(",
"+ (",
"+ -(A[current[1]] + B[current[2]] + C[current[3] + 1]),",
"- hashtable.add(",
"- (",
"- A[current[1]] + B[current[2]] + C[current[3] + 1],",
"- current[1],",
"- current[2],",
"- current[3] + 1,",
"- )",
"- )",
"- cakelist = list(sorted(cakelist))"
] | false | 0.045441 | 0.038739 | 1.17301 |
[
"s240281412",
"s865253006"
] |
u279460955
|
p03372
|
python
|
s817729920
|
s899998678
| 285 | 252 | 109,080 | 118,996 |
Accepted
|
Accepted
| 11.58 |
from itertools import accumulate
class SegTree: # 0-index !!!
"""
fx: モノイドXでの二項演算
ex: モノイドXでの単位元
init(seq, fx, ex): 配列seqで初期化 O(N)
update(i, x): i番目の値をxに更新 O(logN)
query(l, r): 区間[l,r)をfxしたものを返す O(logN)
get(i): i番目の値を返す
show(): 配列を返す
"""
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1<<(self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(list(range(1, self.size))):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def set(self, i, x): # O(log(n))
i += self.size
self.tree[i] = x
while i:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r): # l = r の場合はたぶんバグるので注意
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
def get(self, i):
return self.tree[self.size + i]
def show(self):
return self.tree[self.size: self.size + self.n]
# ---------------------- #
n, c = (int(x) for x in input().split())
X = []
V = []
D = []
prev_x = 0
for _ in range(n):
x, v = (int(x) for x in input().split())
X.append(x)
D.append(x - prev_x)
V.append(v)
prev_x = x
D.append(c - X[-1])
rev_D = list(reversed(D))
rev_V = list(reversed(V))
ans = 0
# 時計回り
A = [0] * n
for i in range(n):
A[i] = V[i] - D[i]
acc_A = list(accumulate(A))
ans = max(ans, max(acc_A))
# 反時計回り
B = [0] * n
for i in range(n):
B[i] = rev_V[i] - rev_D[i]
acc_B = list(accumulate(B))
ans = max(ans, max(acc_B))
# 時計回りからの反時計回り i個まで食べて向きを変える
seg_B = SegTree(acc_B, fx=max, ex=-10**18)
tmp = 0
for i in range(n - 1):
tmp_cal = acc_A[i] - X[i] # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + seg_B.query(0, n-i-1))
ans = max(ans, tmp)
# 反時計回りからの時計回り
seg_A = SegTree(acc_A, fx=max, ex=-10**18)
tmp = 0
for i in range(n - 1):
tmp_cal = acc_B[i] - (c - X[-i - 1]) # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + seg_A.query(0, n-i-1))
ans = max(ans, tmp)
print(ans)
|
from itertools import accumulate
n, c = (int(x) for x in input().split())
X = []
V = []
D = []
prev_x = 0
for _ in range(n):
x, v = (int(x) for x in input().split())
X.append(x)
D.append(x - prev_x)
V.append(v)
prev_x = x
D.append(c - X[-1])
rev_D = list(reversed(D))
rev_V = list(reversed(V))
ans = 0
# 時計回り
A = [0] * n
for i in range(n):
A[i] = V[i] - D[i]
acc_A = list(accumulate(A))
ans = max(ans, max(acc_A))
# 反時計回り
B = [0] * n
for i in range(n):
B[i] = rev_V[i] - rev_D[i]
acc_B = list(accumulate(B))
ans = max(ans, max(acc_B))
max_acc_A = [acc_A[0]]
max_acc_B = [acc_B[0]]
for i in range(1, n):
max_acc_A.append(max(max_acc_A[-1], acc_A[i]))
max_acc_B.append(max(max_acc_B[-1], acc_B[i]))
# 時計回りからの反時計回り i個まで食べて向きを変える
tmp = 0
for i in range(n - 1):
tmp_cal = acc_A[i] - X[i] # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + max_acc_B[n - i - 2])
ans = max(ans, tmp)
# 反時計回りからの時計回り
tmp = 0
for i in range(n - 1):
tmp_cal = acc_B[i] - (c - X[-i - 1]) # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + max_acc_A[n - i - 2])
ans = max(ans, tmp)
print(ans)
| 109 | 53 | 2,801 | 1,164 |
from itertools import accumulate
class SegTree: # 0-index !!!
"""
fx: モノイドXでの二項演算
ex: モノイドXでの単位元
init(seq, fx, ex): 配列seqで初期化 O(N)
update(i, x): i番目の値をxに更新 O(logN)
query(l, r): 区間[l,r)をfxしたものを返す O(logN)
get(i): i番目の値を返す
show(): 配列を返す
"""
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1 << (self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(list(range(1, self.size))):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def set(self, i, x): # O(log(n))
i += self.size
self.tree[i] = x
while i:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r): # l = r の場合はたぶんバグるので注意
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
def get(self, i):
return self.tree[self.size + i]
def show(self):
return self.tree[self.size : self.size + self.n]
# ---------------------- #
n, c = (int(x) for x in input().split())
X = []
V = []
D = []
prev_x = 0
for _ in range(n):
x, v = (int(x) for x in input().split())
X.append(x)
D.append(x - prev_x)
V.append(v)
prev_x = x
D.append(c - X[-1])
rev_D = list(reversed(D))
rev_V = list(reversed(V))
ans = 0
# 時計回り
A = [0] * n
for i in range(n):
A[i] = V[i] - D[i]
acc_A = list(accumulate(A))
ans = max(ans, max(acc_A))
# 反時計回り
B = [0] * n
for i in range(n):
B[i] = rev_V[i] - rev_D[i]
acc_B = list(accumulate(B))
ans = max(ans, max(acc_B))
# 時計回りからの反時計回り i個まで食べて向きを変える
seg_B = SegTree(acc_B, fx=max, ex=-(10**18))
tmp = 0
for i in range(n - 1):
tmp_cal = acc_A[i] - X[i] # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + seg_B.query(0, n - i - 1))
ans = max(ans, tmp)
# 反時計回りからの時計回り
seg_A = SegTree(acc_A, fx=max, ex=-(10**18))
tmp = 0
for i in range(n - 1):
tmp_cal = acc_B[i] - (c - X[-i - 1]) # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + seg_A.query(0, n - i - 1))
ans = max(ans, tmp)
print(ans)
|
from itertools import accumulate
n, c = (int(x) for x in input().split())
X = []
V = []
D = []
prev_x = 0
for _ in range(n):
x, v = (int(x) for x in input().split())
X.append(x)
D.append(x - prev_x)
V.append(v)
prev_x = x
D.append(c - X[-1])
rev_D = list(reversed(D))
rev_V = list(reversed(V))
ans = 0
# 時計回り
A = [0] * n
for i in range(n):
A[i] = V[i] - D[i]
acc_A = list(accumulate(A))
ans = max(ans, max(acc_A))
# 反時計回り
B = [0] * n
for i in range(n):
B[i] = rev_V[i] - rev_D[i]
acc_B = list(accumulate(B))
ans = max(ans, max(acc_B))
max_acc_A = [acc_A[0]]
max_acc_B = [acc_B[0]]
for i in range(1, n):
max_acc_A.append(max(max_acc_A[-1], acc_A[i]))
max_acc_B.append(max(max_acc_B[-1], acc_B[i]))
# 時計回りからの反時計回り i個まで食べて向きを変える
tmp = 0
for i in range(n - 1):
tmp_cal = acc_A[i] - X[i] # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + max_acc_B[n - i - 2])
ans = max(ans, tmp)
# 反時計回りからの時計回り
tmp = 0
for i in range(n - 1):
tmp_cal = acc_B[i] - (c - X[-i - 1]) # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + max_acc_A[n - i - 2])
ans = max(ans, tmp)
print(ans)
| false | 51.376147 |
[
"-",
"-class SegTree: # 0-index !!!",
"- \"\"\"",
"- fx: モノイドXでの二項演算",
"- ex: モノイドXでの単位元",
"- init(seq, fx, ex): 配列seqで初期化 O(N)",
"- update(i, x): i番目の値をxに更新 O(logN)",
"- query(l, r): 区間[l,r)をfxしたものを返す O(logN)",
"- get(i): i番目の値を返す",
"- show(): 配列を返す",
"- \"\"\"",
"-",
"- def __init__(self, seq, fx, ex):",
"- self.n = len(seq)",
"- self.fx = fx",
"- self.ex = ex",
"- self.size = 1 << (self.n - 1).bit_length()",
"- self.tree = [ex] * (self.size * 2)",
"- # build",
"- for i, x in enumerate(seq, start=self.size):",
"- self.tree[i] = x",
"- for i in reversed(list(range(1, self.size))):",
"- self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])",
"-",
"- def set(self, i, x): # O(log(n))",
"- i += self.size",
"- self.tree[i] = x",
"- while i:",
"- i >>= 1",
"- self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])",
"-",
"- def update(self, i, x):",
"- i += self.size",
"- self.tree[i] = x",
"- while i > 1:",
"- i >>= 1",
"- self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])",
"-",
"- def query(self, l, r): # l = r の場合はたぶんバグるので注意",
"- tmp_l = self.ex",
"- tmp_r = self.ex",
"- l += self.size",
"- r += self.size",
"- while l < r:",
"- if l & 1:",
"- tmp_l = self.fx(tmp_l, self.tree[l])",
"- l += 1",
"- if r & 1:",
"- tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)",
"- l >>= 1",
"- r >>= 1",
"- return self.fx(tmp_l, tmp_r)",
"-",
"- def get(self, i):",
"- return self.tree[self.size + i]",
"-",
"- def show(self):",
"- return self.tree[self.size : self.size + self.n]",
"-",
"-",
"+max_acc_A = [acc_A[0]]",
"+max_acc_B = [acc_B[0]]",
"+for i in range(1, n):",
"+ max_acc_A.append(max(max_acc_A[-1], acc_A[i]))",
"+ max_acc_B.append(max(max_acc_B[-1], acc_B[i]))",
"-seg_B = SegTree(acc_B, fx=max, ex=-(10**18))",
"- tmp = max(tmp, tmp_cal + seg_B.query(0, n - i - 1))",
"+ tmp = max(tmp, tmp_cal + max_acc_B[n - i - 2])",
"-seg_A = SegTree(acc_A, fx=max, ex=-(10**18))",
"- tmp = max(tmp, tmp_cal + seg_A.query(0, n - i - 1))",
"+ tmp = max(tmp, tmp_cal + max_acc_A[n - i - 2])"
] | false | 0.04614 | 0.044056 | 1.047307 |
[
"s817729920",
"s899998678"
] |
u561231954
|
p03987
|
python
|
s236313411
|
s227061891
| 850 | 371 | 104,572 | 48,596 |
Accepted
|
Accepted
| 56.35 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
class SegmentTree():
def __init__(self,N,f,unit):
self.f = f
self.unit = unit
self.N = N
self.tree = [self.unit] * (2*self.N)
#self._build(array)
def _build(self,array):
for i,x in enumerate(array,self.N):
self.tree[i] = x
for i in range(self.N - 1,0,-1):
self.tree[i] = self.f(self.tree[i << 1],self.tree[i << 1|1])
def update(self,k,x):
k += self.N
self.tree[k] = x
while k > 1:
k >>= 1
self.tree[k] = self.f(self.tree[k << 1],self.tree[k << 1|1])
def query(self,l,r):
l += self.N
r += self.N
vl = self.unit
vr = self.unit
while l < r:
if l&1:
vl = self.f(vl,self.tree[l])
l += 1
if r&1:
r -= 1
vr = self.f(self.tree[r],vr)
l >>= 1
r >>= 1
return self.f(vl,vr)
def debug(self):
print((self.tree))
def main():
N = int(eval(input()))
A = list(map(int,input().split()))
st = SegmentTree(N,max,-1)
L = [-1] * N
for i,a in enumerate(A):
L[i] = st.query(0,a - 1)
st.update(a - 1,i)
st = SegmentTree(N,min,N)
R = [N] * N
for i in range(N - 1,-1,-1):
R[i] = st.query(0,A[i] - 1)
st.update(A[i] - 1,i)
ans = sum((R[i] - i)*(i - L[i])*A[i] for i in range(N))
print(ans)
if __name__ == '__main__':
main()
|
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
N = int(eval(input()))
A = list(enumerate(map(int,input().split())))
A.sort(key = lambda x:-x[1])
left = list(range(-1,N + 2))
right = list(range(1,N + 4))
ans = 0
for i,a in A:
L = left[i]
R = right[i]
ans += a*(i - L)*(R - i)
left[R] = L
right[L] = R
print(ans)
if __name__ == '__main__':
main()
| 66 | 22 | 1,659 | 478 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15
class SegmentTree:
def __init__(self, N, f, unit):
self.f = f
self.unit = unit
self.N = N
self.tree = [self.unit] * (2 * self.N)
# self._build(array)
def _build(self, array):
for i, x in enumerate(array, self.N):
self.tree[i] = x
for i in range(self.N - 1, 0, -1):
self.tree[i] = self.f(self.tree[i << 1], self.tree[i << 1 | 1])
def update(self, k, x):
k += self.N
self.tree[k] = x
while k > 1:
k >>= 1
self.tree[k] = self.f(self.tree[k << 1], self.tree[k << 1 | 1])
def query(self, l, r):
l += self.N
r += self.N
vl = self.unit
vr = self.unit
while l < r:
if l & 1:
vl = self.f(vl, self.tree[l])
l += 1
if r & 1:
r -= 1
vr = self.f(self.tree[r], vr)
l >>= 1
r >>= 1
return self.f(vl, vr)
def debug(self):
print((self.tree))
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
st = SegmentTree(N, max, -1)
L = [-1] * N
for i, a in enumerate(A):
L[i] = st.query(0, a - 1)
st.update(a - 1, i)
st = SegmentTree(N, min, N)
R = [N] * N
for i in range(N - 1, -1, -1):
R[i] = st.query(0, A[i] - 1)
st.update(A[i] - 1, i)
ans = sum((R[i] - i) * (i - L[i]) * A[i] for i in range(N))
print(ans)
if __name__ == "__main__":
main()
|
import sys
sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15
def main():
N = int(eval(input()))
A = list(enumerate(map(int, input().split())))
A.sort(key=lambda x: -x[1])
left = list(range(-1, N + 2))
right = list(range(1, N + 4))
ans = 0
for i, a in A:
L = left[i]
R = right[i]
ans += a * (i - L) * (R - i)
left[R] = L
right[L] = R
print(ans)
if __name__ == "__main__":
main()
| false | 66.666667 |
[
"-class SegmentTree:",
"- def __init__(self, N, f, unit):",
"- self.f = f",
"- self.unit = unit",
"- self.N = N",
"- self.tree = [self.unit] * (2 * self.N)",
"- # self._build(array)",
"-",
"- def _build(self, array):",
"- for i, x in enumerate(array, self.N):",
"- self.tree[i] = x",
"- for i in range(self.N - 1, 0, -1):",
"- self.tree[i] = self.f(self.tree[i << 1], self.tree[i << 1 | 1])",
"-",
"- def update(self, k, x):",
"- k += self.N",
"- self.tree[k] = x",
"- while k > 1:",
"- k >>= 1",
"- self.tree[k] = self.f(self.tree[k << 1], self.tree[k << 1 | 1])",
"-",
"- def query(self, l, r):",
"- l += self.N",
"- r += self.N",
"- vl = self.unit",
"- vr = self.unit",
"- while l < r:",
"- if l & 1:",
"- vl = self.f(vl, self.tree[l])",
"- l += 1",
"- if r & 1:",
"- r -= 1",
"- vr = self.f(self.tree[r], vr)",
"- l >>= 1",
"- r >>= 1",
"- return self.f(vl, vr)",
"-",
"- def debug(self):",
"- print((self.tree))",
"-",
"-",
"- A = list(map(int, input().split()))",
"- st = SegmentTree(N, max, -1)",
"- L = [-1] * N",
"- for i, a in enumerate(A):",
"- L[i] = st.query(0, a - 1)",
"- st.update(a - 1, i)",
"- st = SegmentTree(N, min, N)",
"- R = [N] * N",
"- for i in range(N - 1, -1, -1):",
"- R[i] = st.query(0, A[i] - 1)",
"- st.update(A[i] - 1, i)",
"- ans = sum((R[i] - i) * (i - L[i]) * A[i] for i in range(N))",
"+ A = list(enumerate(map(int, input().split())))",
"+ A.sort(key=lambda x: -x[1])",
"+ left = list(range(-1, N + 2))",
"+ right = list(range(1, N + 4))",
"+ ans = 0",
"+ for i, a in A:",
"+ L = left[i]",
"+ R = right[i]",
"+ ans += a * (i - L) * (R - i)",
"+ left[R] = L",
"+ right[L] = R"
] | false | 0.109798 | 0.035326 | 3.108114 |
[
"s236313411",
"s227061891"
] |
u508732591
|
p00009
|
python
|
s918546600
|
s978480803
| 270 | 170 | 26,348 | 16,888 |
Accepted
|
Accepted
| 37.04 |
import sys
import math
N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])
for i in range(3,int(math.sqrt(N)),2):
if primes[i]:
primes[i*i::i*2] = [0] * len(primes[i*i::i*2])
for i in sys.stdin:
n = int(i)
print((sum(primes[0:n+1])))
|
import sys
import math
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
for i in range(3,int(math.sqrt(N)),2):
if primes[i//2]:
primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
for i in sys.stdin:
n = int(i)
if n == 1:
print((0))
elif n == 2:
print((1))
else:
print((sum(primes[0:(n+1)//2])+1))
| 16 | 19 | 321 | 364 |
import sys
import math
N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])
for i in range(3, int(math.sqrt(N)), 2):
if primes[i]:
primes[i * i :: i * 2] = [0] * len(primes[i * i :: i * 2])
for i in sys.stdin:
n = int(i)
print((sum(primes[0 : n + 1])))
|
import sys
import math
N = 1000000
primes = [1] * (N // 2)
primes[0] = 0
for i in range(3, int(math.sqrt(N)), 2):
if primes[i // 2]:
primes[(i * i) // 2 :: i] = [0] * len(primes[(i * i) // 2 :: i])
for i in sys.stdin:
n = int(i)
if n == 1:
print((0))
elif n == 2:
print((1))
else:
print((sum(primes[0 : (n + 1) // 2]) + 1))
| false | 15.789474 |
[
"-primes = [1] * N",
"+primes = [1] * (N // 2)",
"-primes[1] = 0",
"-primes[4::2] = [0] * len(primes[4::2])",
"- if primes[i]:",
"- primes[i * i :: i * 2] = [0] * len(primes[i * i :: i * 2])",
"+ if primes[i // 2]:",
"+ primes[(i * i) // 2 :: i] = [0] * len(primes[(i * i) // 2 :: i])",
"- print((sum(primes[0 : n + 1])))",
"+ if n == 1:",
"+ print((0))",
"+ elif n == 2:",
"+ print((1))",
"+ else:",
"+ print((sum(primes[0 : (n + 1) // 2]) + 1))"
] | false | 0.245928 | 0.157458 | 1.561863 |
[
"s918546600",
"s978480803"
] |
u886747123
|
p02883
|
python
|
s087369415
|
s163073557
| 509 | 423 | 38,748 | 38,840 |
Accepted
|
Accepted
| 16.9 |
# E - Gluttony
import numpy as np
# np.arrayに変換する場合はsortedを使うよりnp.sortを使う方が少し速い
N, K = list(map(int, input().split()))
A = np.sort(np.array((list(map(int, input().split())))))
F = np.sort(np.array(sorted((list(map(int, input().split()))))))[::-1]
lower = 0
upper = A[-1] * F[0]
# 達成可能な最高成績を二分探索する
while lower <= upper:
result = (lower + upper) // 2
# resultを達成可能なAと実際のAの差異の総和が必要な修行コスト
# np.arrayの和を求める場合、sum(array)よりarray.sum()の方が速い(使わないとTLE)
if np.clip(A - result//F, 0, None).sum() <= K:
ans = result
upper = result - 1
else:
lower = result + 1
print(ans)
|
# E - Gluttony
import numpy as np
# np.arrayに変換する場合はsortedを使うよりnp.sortを使う方が少し速い
N, K = list(map(int, input().split()))
A = np.sort(np.array((list(map(int, input().split())))))
F = np.sort(np.array(((list(map(int, input().split()))))))[::-1]
lower = 0
upper = A[-1] * F[0]
# 達成可能な最高成績を二分探索する
while lower <= upper:
result = (lower + upper) // 2
# resultを達成可能なAと実際のAの差異の総和が必要な修行コスト
# np.arrayの和を求める場合、sum(array)よりarray.sum()の方が速い(使わないとTLE)
if np.clip(A - result//F, 0, None).sum() <= K:
ans = result
upper = result - 1
else:
lower = result + 1
print(ans)
| 24 | 24 | 623 | 617 |
# E - Gluttony
import numpy as np
# np.arrayに変換する場合はsortedを使うよりnp.sortを使う方が少し速い
N, K = list(map(int, input().split()))
A = np.sort(np.array((list(map(int, input().split())))))
F = np.sort(np.array(sorted((list(map(int, input().split()))))))[::-1]
lower = 0
upper = A[-1] * F[0]
# 達成可能な最高成績を二分探索する
while lower <= upper:
result = (lower + upper) // 2
# resultを達成可能なAと実際のAの差異の総和が必要な修行コスト
# np.arrayの和を求める場合、sum(array)よりarray.sum()の方が速い(使わないとTLE)
if np.clip(A - result // F, 0, None).sum() <= K:
ans = result
upper = result - 1
else:
lower = result + 1
print(ans)
|
# E - Gluttony
import numpy as np
# np.arrayに変換する場合はsortedを使うよりnp.sortを使う方が少し速い
N, K = list(map(int, input().split()))
A = np.sort(np.array((list(map(int, input().split())))))
F = np.sort(np.array(((list(map(int, input().split()))))))[::-1]
lower = 0
upper = A[-1] * F[0]
# 達成可能な最高成績を二分探索する
while lower <= upper:
result = (lower + upper) // 2
# resultを達成可能なAと実際のAの差異の総和が必要な修行コスト
# np.arrayの和を求める場合、sum(array)よりarray.sum()の方が速い(使わないとTLE)
if np.clip(A - result // F, 0, None).sum() <= K:
ans = result
upper = result - 1
else:
lower = result + 1
print(ans)
| false | 0 |
[
"-F = np.sort(np.array(sorted((list(map(int, input().split()))))))[::-1]",
"+F = np.sort(np.array(((list(map(int, input().split()))))))[::-1]"
] | false | 1.010155 | 0.479854 | 2.10513 |
[
"s087369415",
"s163073557"
] |
u802537549
|
p00009
|
python
|
s552730007
|
s992921675
| 720 | 540 | 21,236 | 21,248 |
Accepted
|
Accepted
| 25 |
# coding: utf-8
LIMIT = 999999
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
for i in range(3, LIMIT + 1):
if prime[i - 1]:
for j in range(i ** 2, LIMIT + 1, i):
prime[j - 1] = 0
while True:
try:
n = int(eval(input()))
except EOFError:
break
print((sum(prime[:n])))
|
# coding: utf-8
LIMIT = 999999
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
for i in range(3, int(LIMIT ** 0.5) + 1):
if prime[i - 1]:
for j in range(i ** 2, LIMIT + 1, i):
prime[j - 1] = 0
while True:
try:
n = int(eval(input()))
except EOFError:
break
print((sum(prime[:n])))
| 19 | 18 | 359 | 369 |
# coding: utf-8
LIMIT = 999999
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
for i in range(3, LIMIT + 1):
if prime[i - 1]:
for j in range(i**2, LIMIT + 1, i):
prime[j - 1] = 0
while True:
try:
n = int(eval(input()))
except EOFError:
break
print((sum(prime[:n])))
|
# coding: utf-8
LIMIT = 999999
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
for i in range(3, int(LIMIT**0.5) + 1):
if prime[i - 1]:
for j in range(i**2, LIMIT + 1, i):
prime[j - 1] = 0
while True:
try:
n = int(eval(input()))
except EOFError:
break
print((sum(prime[:n])))
| false | 5.263158 |
[
"-for i in range(3, LIMIT + 1):",
"+for i in range(3, int(LIMIT**0.5) + 1):"
] | false | 1.318732 | 0.600931 | 2.19448 |
[
"s552730007",
"s992921675"
] |
u426534722
|
p02366
|
python
|
s828112177
|
s770285887
| 300 | 210 | 20,304 | 20,492 |
Accepted
|
Accepted
| 30 |
import sys
sys.setrecursionlimit(100000)
def dfs(v, tm):
dts[v] = est[v] = tm + 1
child = 0
for i in adj[v]:
if est[i] == float('inf'):
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] is None and child > 1: aps[v] = True
if parents[v] is not None and est[i] >= dts[v]: aps[v] = True
elif parents[v] != i:
est[v] = min(est[v], dts[i])
nv, ne = list(map(int, input().split(' ')))
adj = [[] for _ in range(nv)]
est = [float('inf')] * nv
parents = [None] * nv
aps = [False] * nv
dts = [0] * nv
for _ in range(ne):
s, t = list(map(int, input().split(' ')))
adj[s].append(t)
adj[t].append(s)
dfs(0, 0)
for i in range(nv):
if aps[i]:
print(i)
|
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
dts[v] = est[v] = tm + 1
child = 0
for i in adj[v]:
if isinf(est[i]):
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] is None and child > 1: aps[v] = True
if parents[v] is not None and est[i] >= dts[v]: aps[v] = True
elif parents[v] != i:
est[v] = min(est[v], dts[i])
n, m = list(map(int, stdin.readline().split()))
adj = [[] for _ in range(n)]
est = [float('inf')] * n
parents = [None] * n
aps = [False] * n
dts = [0] * n
for _ in range(m):
s, t = list(map(int, stdin.readline().split()))
adj[s].append(t)
adj[t].append(s)
dfs(0, 0)
for i in range(n):
if aps[i]:
print(i)
| 39 | 32 | 843 | 884 |
import sys
sys.setrecursionlimit(100000)
def dfs(v, tm):
dts[v] = est[v] = tm + 1
child = 0
for i in adj[v]:
if est[i] == float("inf"):
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] is None and child > 1:
aps[v] = True
if parents[v] is not None and est[i] >= dts[v]:
aps[v] = True
elif parents[v] != i:
est[v] = min(est[v], dts[i])
nv, ne = list(map(int, input().split(" ")))
adj = [[] for _ in range(nv)]
est = [float("inf")] * nv
parents = [None] * nv
aps = [False] * nv
dts = [0] * nv
for _ in range(ne):
s, t = list(map(int, input().split(" ")))
adj[s].append(t)
adj[t].append(s)
dfs(0, 0)
for i in range(nv):
if aps[i]:
print(i)
|
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
dts[v] = est[v] = tm + 1
child = 0
for i in adj[v]:
if isinf(est[i]):
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] is None and child > 1:
aps[v] = True
if parents[v] is not None and est[i] >= dts[v]:
aps[v] = True
elif parents[v] != i:
est[v] = min(est[v], dts[i])
n, m = list(map(int, stdin.readline().split()))
adj = [[] for _ in range(n)]
est = [float("inf")] * n
parents = [None] * n
aps = [False] * n
dts = [0] * n
for _ in range(m):
s, t = list(map(int, stdin.readline().split()))
adj[s].append(t)
adj[t].append(s)
dfs(0, 0)
for i in range(n):
if aps[i]:
print(i)
| false | 17.948718 |
[
"+from sys import stdin",
"+from math import isinf",
"+INF = float(\"inf\")",
"- if est[i] == float(\"inf\"):",
"+ if isinf(est[i]):",
"-nv, ne = list(map(int, input().split(\" \")))",
"-adj = [[] for _ in range(nv)]",
"-est = [float(\"inf\")] * nv",
"-parents = [None] * nv",
"-aps = [False] * nv",
"-dts = [0] * nv",
"-for _ in range(ne):",
"- s, t = list(map(int, input().split(\" \")))",
"+n, m = list(map(int, stdin.readline().split()))",
"+adj = [[] for _ in range(n)]",
"+est = [float(\"inf\")] * n",
"+parents = [None] * n",
"+aps = [False] * n",
"+dts = [0] * n",
"+for _ in range(m):",
"+ s, t = list(map(int, stdin.readline().split()))",
"-for i in range(nv):",
"+for i in range(n):"
] | false | 0.088989 | 0.036107 | 2.464631 |
[
"s828112177",
"s770285887"
] |
u442030035
|
p02990
|
python
|
s567925274
|
s462570680
| 1,281 | 831 | 3,316 | 3,316 |
Accepted
|
Accepted
| 35.13 |
N, K = list(map(int, input().split()))
mod = 1000000007
def factorial_2(N: int, M: int) -> int:
res = 1
for i in range(2, N+1):
res *= i
res %= M
return res
def nCr(n: int, r: int, mod: int):
if n == r:
return 1
if r > n:
return 0
return (factorial_2(n, mod) * pow((factorial_2(n-r, mod) * factorial_2(r, mod)), mod-2, mod)) % mod
for i in range(1, K+1):
print((nCr(N-K+1, i, mod) * nCr(K-1, i-1, mod) % mod))
|
import math
N, K = list(map(int, input().split()))
mod = 1000000007
def nCr(n: int, r: int):
if n == r:
return 1
if r > n:
return 0
return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
for i in range(1, K+1):
print((nCr(N-K+1, i) * nCr(K-1, i-1) % mod))
| 22 | 16 | 489 | 315 |
N, K = list(map(int, input().split()))
mod = 1000000007
def factorial_2(N: int, M: int) -> int:
res = 1
for i in range(2, N + 1):
res *= i
res %= M
return res
def nCr(n: int, r: int, mod: int):
if n == r:
return 1
if r > n:
return 0
return (
factorial_2(n, mod)
* pow((factorial_2(n - r, mod) * factorial_2(r, mod)), mod - 2, mod)
) % mod
for i in range(1, K + 1):
print((nCr(N - K + 1, i, mod) * nCr(K - 1, i - 1, mod) % mod))
|
import math
N, K = list(map(int, input().split()))
mod = 1000000007
def nCr(n: int, r: int):
if n == r:
return 1
if r > n:
return 0
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1, K + 1):
print((nCr(N - K + 1, i) * nCr(K - 1, i - 1) % mod))
| false | 27.272727 |
[
"+import math",
"+",
"-def factorial_2(N: int, M: int) -> int:",
"- res = 1",
"- for i in range(2, N + 1):",
"- res *= i",
"- res %= M",
"- return res",
"-",
"-",
"-def nCr(n: int, r: int, mod: int):",
"+def nCr(n: int, r: int):",
"- return (",
"- factorial_2(n, mod)",
"- * pow((factorial_2(n - r, mod) * factorial_2(r, mod)), mod - 2, mod)",
"- ) % mod",
"+ return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))",
"- print((nCr(N - K + 1, i, mod) * nCr(K - 1, i - 1, mod) % mod))",
"+ print((nCr(N - K + 1, i) * nCr(K - 1, i - 1) % mod))"
] | false | 0.038245 | 0.040867 | 0.935856 |
[
"s567925274",
"s462570680"
] |
u280552586
|
p03556
|
python
|
s802070271
|
s703101826
| 44 | 17 | 2,940 | 3,060 |
Accepted
|
Accepted
| 61.36 |
n = int(eval(input()))
for i in range(1, n+1):
if i**2 <= n:
ans = min(n, i**2)
else:
break
print(ans)
|
n = int(eval(input()))
print((int(n**.5)**2))
| 9 | 2 | 131 | 39 |
n = int(eval(input()))
for i in range(1, n + 1):
if i**2 <= n:
ans = min(n, i**2)
else:
break
print(ans)
|
n = int(eval(input()))
print((int(n**0.5) ** 2))
| false | 77.777778 |
[
"-for i in range(1, n + 1):",
"- if i**2 <= n:",
"- ans = min(n, i**2)",
"- else:",
"- break",
"-print(ans)",
"+print((int(n**0.5) ** 2))"
] | false | 0.048656 | 0.039445 | 1.233517 |
[
"s802070271",
"s703101826"
] |
u285443936
|
p03425
|
python
|
s993673911
|
s414951487
| 261 | 179 | 9,772 | 3,064 |
Accepted
|
Accepted
| 31.42 |
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
S_march = []
MARCH = ["M", "A", "R", "C", "H"]
cmb = []
ans = 0
N_march = [0]*5
for Si in S:
for j in range(5):
if Si[:1] == MARCH[j]:
N_march[j] += 1
for i in range(2**5):
check = [False]*5
for j in range(5):
if (i>>j) & 1:
check[j] = True
if check.count(True) == 3:
cmb.append(check)
for i in cmb:
tmp_list = []
for j in range(5):
if i[j]:
tmp_list.append(N_march[j])
ans += tmp_list[0]*tmp_list[1]*tmp_list[2]
print(ans)
#for i in range(2*N):
# for j in range(N):
# if (i>>j) & 1:
# if S[j][:1] in MARCH:
# check[j] = True
# MARCH.pop(S[j][:1])
# if check.count(True) == 3:
# ans += 1
#print(ans)
|
N = int(eval(input()))
m,a,r,c,h = 0,0,0,0,0
for i in range(N):
s = eval(input())
if s[0] == "M":
m += 1
if s[0] == "A":
a += 1
if s[0] == "R":
r += 1
if s[0] == "C":
c += 1
if s[0] == "H":
h += 1
A = [m,a,r,c,h]
ans = 0
for i in range(5):
for j in range(min(i+1,5),5):
for k in range(min(j+1,5),5):
ans += A[i]*A[j]*A[k]
print(ans)
| 42 | 21 | 786 | 384 |
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
S_march = []
MARCH = ["M", "A", "R", "C", "H"]
cmb = []
ans = 0
N_march = [0] * 5
for Si in S:
for j in range(5):
if Si[:1] == MARCH[j]:
N_march[j] += 1
for i in range(2**5):
check = [False] * 5
for j in range(5):
if (i >> j) & 1:
check[j] = True
if check.count(True) == 3:
cmb.append(check)
for i in cmb:
tmp_list = []
for j in range(5):
if i[j]:
tmp_list.append(N_march[j])
ans += tmp_list[0] * tmp_list[1] * tmp_list[2]
print(ans)
# for i in range(2*N):
# for j in range(N):
# if (i>>j) & 1:
# if S[j][:1] in MARCH:
# check[j] = True
# MARCH.pop(S[j][:1])
# if check.count(True) == 3:
# ans += 1
# print(ans)
|
N = int(eval(input()))
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(N):
s = eval(input())
if s[0] == "M":
m += 1
if s[0] == "A":
a += 1
if s[0] == "R":
r += 1
if s[0] == "C":
c += 1
if s[0] == "H":
h += 1
A = [m, a, r, c, h]
ans = 0
for i in range(5):
for j in range(min(i + 1, 5), 5):
for k in range(min(j + 1, 5), 5):
ans += A[i] * A[j] * A[k]
print(ans)
| false | 50 |
[
"-S = [eval(input()) for i in range(N)]",
"-S_march = []",
"-MARCH = [\"M\", \"A\", \"R\", \"C\", \"H\"]",
"-cmb = []",
"+m, a, r, c, h = 0, 0, 0, 0, 0",
"+for i in range(N):",
"+ s = eval(input())",
"+ if s[0] == \"M\":",
"+ m += 1",
"+ if s[0] == \"A\":",
"+ a += 1",
"+ if s[0] == \"R\":",
"+ r += 1",
"+ if s[0] == \"C\":",
"+ c += 1",
"+ if s[0] == \"H\":",
"+ h += 1",
"+A = [m, a, r, c, h]",
"-N_march = [0] * 5",
"-for Si in S:",
"- for j in range(5):",
"- if Si[:1] == MARCH[j]:",
"- N_march[j] += 1",
"-for i in range(2**5):",
"- check = [False] * 5",
"- for j in range(5):",
"- if (i >> j) & 1:",
"- check[j] = True",
"- if check.count(True) == 3:",
"- cmb.append(check)",
"-for i in cmb:",
"- tmp_list = []",
"- for j in range(5):",
"- if i[j]:",
"- tmp_list.append(N_march[j])",
"- ans += tmp_list[0] * tmp_list[1] * tmp_list[2]",
"+for i in range(5):",
"+ for j in range(min(i + 1, 5), 5):",
"+ for k in range(min(j + 1, 5), 5):",
"+ ans += A[i] * A[j] * A[k]",
"-# for i in range(2*N):",
"-# for j in range(N):",
"-# if (i>>j) & 1:",
"-# if S[j][:1] in MARCH:",
"-# check[j] = True",
"-# MARCH.pop(S[j][:1])",
"-# if check.count(True) == 3:",
"-# ans += 1",
"-# print(ans)"
] | false | 0.037547 | 0.036636 | 1.024873 |
[
"s993673911",
"s414951487"
] |
u131984977
|
p02412
|
python
|
s210774544
|
s229334190
| 2,060 | 1,150 | 25,476 | 6,724 |
Accepted
|
Accepted
| 44.17 |
while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
dataset = []
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
dataset.append([a,b,c])
count = 0
for data in dataset:
if sum(data) == x:
count += 1
print(count)
|
while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
if sum([a,b,c]) == x:
count += 1
print(count)
| 17 | 13 | 384 | 316 |
while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
dataset = []
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
dataset.append([a, b, c])
count = 0
for data in dataset:
if sum(data) == x:
count += 1
print(count)
|
while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
if sum([a, b, c]) == x:
count += 1
print(count)
| false | 23.529412 |
[
"- dataset = []",
"+ count = 0",
"- dataset.append([a, b, c])",
"- count = 0",
"- for data in dataset:",
"- if sum(data) == x:",
"- count += 1",
"+ if sum([a, b, c]) == x:",
"+ count += 1"
] | false | 0.047809 | 0.174898 | 0.273356 |
[
"s210774544",
"s229334190"
] |
u102461423
|
p02998
|
python
|
s119611354
|
s898996081
| 590 | 422 | 25,060 | 48,424 |
Accepted
|
Accepted
| 28.47 |
from collections import defaultdict
U = 10 ** 5
root = [None] * (2*U+1)
N = int(eval(input()))
XY = [[int(x) for x in input().split()] for _ in range(N)]
def find_root(x):
y = root[x]
if y is None:
root[x] = x
return x
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x,y):
rx = find_root(x)
ry = find_root(y)
if rx == ry:
return
root[ry] = rx
return
for x,y in XY:
merge(x,U+y)
pts_cnt = defaultdict(int)
x_cnt = defaultdict(int)
y_cnt = defaultdict(int)
for x in range(U+1):
if root[x] is None:
continue
x_cnt[find_root(x)] += 1
for y in range(U+1,U+U+1):
if root[y] is None:
continue
y_cnt[find_root(y)] += 1
for x,y in XY:
pts_cnt[find_root(x)] += 1
answer = 0
for k,v in list(pts_cnt.items()):
answer += x_cnt[k] * y_cnt[k] - v
print(answer)
|
import numpy as np
from scipy.sparse import *
U = 10**5
N = int(eval(input()))
XY = np.array([input().split() for _ in range(N)], dtype=np.int32)
graph = csr_matrix((np.ones(N,dtype=np.bool), (XY[:,0], U + XY[:,1])), (2*U+1, 2*U+1))
_, component = csgraph.connected_components(graph)
X_cnt = np.bincount(component[:U+1], minlength = 2*U+2)
Y_cnt = np.bincount(component[U+1:], minlength = 2*U+2)
pts_cnt = np.bincount(component[XY[:,0]], minlength = 2*U+2)
answer = (X_cnt * Y_cnt - pts_cnt).sum()
print(answer)
| 50 | 15 | 871 | 523 |
from collections import defaultdict
U = 10**5
root = [None] * (2 * U + 1)
N = int(eval(input()))
XY = [[int(x) for x in input().split()] for _ in range(N)]
def find_root(x):
y = root[x]
if y is None:
root[x] = x
return x
if x == y:
return y
z = find_root(y)
root[x] = z
return z
def merge(x, y):
rx = find_root(x)
ry = find_root(y)
if rx == ry:
return
root[ry] = rx
return
for x, y in XY:
merge(x, U + y)
pts_cnt = defaultdict(int)
x_cnt = defaultdict(int)
y_cnt = defaultdict(int)
for x in range(U + 1):
if root[x] is None:
continue
x_cnt[find_root(x)] += 1
for y in range(U + 1, U + U + 1):
if root[y] is None:
continue
y_cnt[find_root(y)] += 1
for x, y in XY:
pts_cnt[find_root(x)] += 1
answer = 0
for k, v in list(pts_cnt.items()):
answer += x_cnt[k] * y_cnt[k] - v
print(answer)
|
import numpy as np
from scipy.sparse import *
U = 10**5
N = int(eval(input()))
XY = np.array([input().split() for _ in range(N)], dtype=np.int32)
graph = csr_matrix(
(np.ones(N, dtype=np.bool), (XY[:, 0], U + XY[:, 1])), (2 * U + 1, 2 * U + 1)
)
_, component = csgraph.connected_components(graph)
X_cnt = np.bincount(component[: U + 1], minlength=2 * U + 2)
Y_cnt = np.bincount(component[U + 1 :], minlength=2 * U + 2)
pts_cnt = np.bincount(component[XY[:, 0]], minlength=2 * U + 2)
answer = (X_cnt * Y_cnt - pts_cnt).sum()
print(answer)
| false | 70 |
[
"-from collections import defaultdict",
"+import numpy as np",
"+from scipy.sparse import *",
"-root = [None] * (2 * U + 1)",
"-XY = [[int(x) for x in input().split()] for _ in range(N)]",
"-",
"-",
"-def find_root(x):",
"- y = root[x]",
"- if y is None:",
"- root[x] = x",
"- return x",
"- if x == y:",
"- return y",
"- z = find_root(y)",
"- root[x] = z",
"- return z",
"-",
"-",
"-def merge(x, y):",
"- rx = find_root(x)",
"- ry = find_root(y)",
"- if rx == ry:",
"- return",
"- root[ry] = rx",
"- return",
"-",
"-",
"-for x, y in XY:",
"- merge(x, U + y)",
"-pts_cnt = defaultdict(int)",
"-x_cnt = defaultdict(int)",
"-y_cnt = defaultdict(int)",
"-for x in range(U + 1):",
"- if root[x] is None:",
"- continue",
"- x_cnt[find_root(x)] += 1",
"-for y in range(U + 1, U + U + 1):",
"- if root[y] is None:",
"- continue",
"- y_cnt[find_root(y)] += 1",
"-for x, y in XY:",
"- pts_cnt[find_root(x)] += 1",
"-answer = 0",
"-for k, v in list(pts_cnt.items()):",
"- answer += x_cnt[k] * y_cnt[k] - v",
"+XY = np.array([input().split() for _ in range(N)], dtype=np.int32)",
"+graph = csr_matrix(",
"+ (np.ones(N, dtype=np.bool), (XY[:, 0], U + XY[:, 1])), (2 * U + 1, 2 * U + 1)",
"+)",
"+_, component = csgraph.connected_components(graph)",
"+X_cnt = np.bincount(component[: U + 1], minlength=2 * U + 2)",
"+Y_cnt = np.bincount(component[U + 1 :], minlength=2 * U + 2)",
"+pts_cnt = np.bincount(component[XY[:, 0]], minlength=2 * U + 2)",
"+answer = (X_cnt * Y_cnt - pts_cnt).sum()"
] | false | 0.08093 | 0.444861 | 0.181922 |
[
"s119611354",
"s898996081"
] |
u193264896
|
p03029
|
python
|
s586124496
|
s147018652
| 36 | 17 | 5,076 | 3,060 |
Accepted
|
Accepted
| 52.78 |
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
def main():
a, p = list(map(int, readline().split()))
print(((3*a+p)//2))
if __name__ == '__main__':
main()
|
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
A, P = list(map(int, readline().split()))
print(((3*A+P)//2))
if __name__ == '__main__':
main()
| 28 | 12 | 860 | 240 |
from collections import deque
from collections import Counter
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
# pypyではscipy, numpyは使えない
# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
# import numpy as np
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
def main():
a, p = list(map(int, readline().split()))
print(((3 * a + p) // 2))
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def main():
A, P = list(map(int, readline().split()))
print(((3 * A + P) // 2))
if __name__ == "__main__":
main()
| false | 57.142857 |
[
"-from collections import deque",
"-from collections import Counter",
"-from itertools import product, permutations, combinations",
"-from operator import itemgetter",
"-from heapq import heappop, heappush",
"-from bisect import bisect_left, bisect_right, bisect",
"-",
"-# pypyではscipy, numpyは使えない",
"-# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree",
"-# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix",
"-# import numpy as np",
"-from fractions import gcd",
"-from math import ceil, floor, sqrt, cos, sin, pi, factorial",
"-read = sys.stdin.buffer.read",
"-readlines = sys.stdin.buffer.readlines",
"+MOD = 10**9 + 7",
"- a, p = list(map(int, readline().split()))",
"- print(((3 * a + p) // 2))",
"+ A, P = list(map(int, readline().split()))",
"+ print(((3 * A + P) // 2))"
] | false | 0.046612 | 0.067957 | 0.685906 |
[
"s586124496",
"s147018652"
] |
u047102107
|
p03588
|
python
|
s825356576
|
s317307140
| 872 | 307 | 67,800 | 83,620 |
Accepted
|
Accepted
| 64.79 |
N = int(eval(input()))
A, B = [], []
for _ in range(N):
ai, bi = list(map(int, input().split()))
A.append(ai)
B.append(bi)
AB = sorted(list(zip(A, B)))
count = len(AB)
# 先頭
count += AB[0][0] - 1
for i in range(N - 1):
# i と j の間に何人入れられるか
if AB[i + 1][0] > AB[i][0] + 1:
count += AB[i + 1][0] - AB[i][0] - 1
# 末尾 (0点以上なので)
count += AB[-1][1] - 0
print(count)
|
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)
INF = int(1e10)
MOD = int(1e9 + 7)
def main():
from builtins import int, map
N = int(eval(input()))
AB = []
for _ in range(N):
ai, bi = list(map(int, input().split()))
AB.append((ai, bi))
AB = sorted(AB, key=lambda x: x[0])
ans = AB[0][0] - 1
for i in range(N - 1):
diff = AB[i + 1][0] - AB[i][0]
ans += diff
ans += AB[-1][1] + 1
print(ans)
if __name__ == '__main__':
main()
| 22 | 27 | 399 | 682 |
N = int(eval(input()))
A, B = [], []
for _ in range(N):
ai, bi = list(map(int, input().split()))
A.append(ai)
B.append(bi)
AB = sorted(list(zip(A, B)))
count = len(AB)
# 先頭
count += AB[0][0] - 1
for i in range(N - 1):
# i と j の間に何人入れられるか
if AB[i + 1][0] > AB[i][0] + 1:
count += AB[i + 1][0] - AB[i][0] - 1
# 末尾 (0点以上なので)
count += AB[-1][1] - 0
print(count)
|
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)
INF = int(1e10)
MOD = int(1e9 + 7)
def main():
from builtins import int, map
N = int(eval(input()))
AB = []
for _ in range(N):
ai, bi = list(map(int, input().split()))
AB.append((ai, bi))
AB = sorted(AB, key=lambda x: x[0])
ans = AB[0][0] - 1
for i in range(N - 1):
diff = AB[i + 1][0] - AB[i][0]
ans += diff
ans += AB[-1][1] + 1
print(ans)
if __name__ == "__main__":
main()
| false | 18.518519 |
[
"-N = int(eval(input()))",
"-A, B = [], []",
"-for _ in range(N):",
"- ai, bi = list(map(int, input().split()))",
"- A.append(ai)",
"- B.append(bi)",
"-AB = sorted(list(zip(A, B)))",
"-count = len(AB)",
"-# 先頭",
"-count += AB[0][0] - 1",
"-for i in range(N - 1):",
"- # i と j の間に何人入れられるか",
"- if AB[i + 1][0] > AB[i][0] + 1:",
"- count += AB[i + 1][0] - AB[i][0] - 1",
"-# 末尾 (0点以上なので)",
"-count += AB[-1][1] - 0",
"-print(count)",
"+from sys import stdin, setrecursionlimit",
"+from collections import Counter, deque, defaultdict",
"+from math import floor, ceil",
"+from bisect import bisect_left",
"+from itertools import combinations",
"+",
"+setrecursionlimit(100000)",
"+INF = int(1e10)",
"+MOD = int(1e9 + 7)",
"+",
"+",
"+def main():",
"+ from builtins import int, map",
"+",
"+ N = int(eval(input()))",
"+ AB = []",
"+ for _ in range(N):",
"+ ai, bi = list(map(int, input().split()))",
"+ AB.append((ai, bi))",
"+ AB = sorted(AB, key=lambda x: x[0])",
"+ ans = AB[0][0] - 1",
"+ for i in range(N - 1):",
"+ diff = AB[i + 1][0] - AB[i][0]",
"+ ans += diff",
"+ ans += AB[-1][1] + 1",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.03773 | 0.044208 | 0.853478 |
[
"s825356576",
"s317307140"
] |
u380524497
|
p02662
|
python
|
s859916378
|
s452709947
| 238 | 210 | 27,760 | 27,168 |
Accepted
|
Accepted
| 11.76 |
import numpy as np
mod = 998244353
n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
DP[0] = 1
for a in A:
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP %= mod
print((DP[s]))
|
import numpy as np
mod = 998244353
n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
DP[0] = 1
for a in A:
double = DP * 2
double[a:] += DP[:-a] # shift
DP = double % mod
print((DP[s]))
| 16 | 15 | 315 | 270 |
import numpy as np
mod = 998244353
n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
DP[0] = 1
for a in A:
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP %= mod
print((DP[s]))
|
import numpy as np
mod = 998244353
n, s = list(map(int, input().split()))
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
DP[0] = 1
for a in A:
double = DP * 2
double[a:] += DP[:-a] # shift
DP = double % mod
print((DP[s]))
| false | 6.25 |
[
"- shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)",
"- DP = double + shift",
"- DP %= mod",
"+ double[a:] += DP[:-a] # shift",
"+ DP = double % mod"
] | false | 0.262788 | 0.23846 | 1.102022 |
[
"s859916378",
"s452709947"
] |
u923279197
|
p03108
|
python
|
s104706491
|
s013897532
| 1,291 | 979 | 120,920 | 93,016 |
Accepted
|
Accepted
| 24.17 |
n,m = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(m)]
#入力
AB.reverse()
ans = [0]*(m+1)
ans[m] = n*(n-1)//2
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
self.count = [1]* (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.count[y] += self.count[x]
self.count[x] = 0
else:
self.par[y] = x
self.count[x] += self.count[y]
self.count[y] = 0
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
# 属している集合の要素数
def search(self,x):
q = UnionFind.find(self,x)
return self.count[q]
uf = UnionFind(n)
for i in range(m):
a = AB[i][0]
b = AB[i][1]
#print(a,b)
if uf.same_check(a,b):
ans[m-i-1] = ans[m-i]
continue
else:
s = uf.search(a)
t = uf.search(b)
#print(s,t)
uf.union(a,b)
ans[m-i-1] = ans[m-i] + s*(s-1)//2 + t*(t-1)//2 - (s+t)*(s+t-1)//2
for i in range(1,m+1):
print((ans[i]))
|
class UnionFind:
def __init__(self, n):
# 親要素のノード番号を格納 par[x] == x の時そのノードは根
self.par = [i for i in range(n+1)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * (n+1)
# 各々の集合の要素数(根が代表して値を持っておく)
self.count = [1] * (n+1)
# 検索
def find(self, x):
# 根ならその番号を返す
root = x
queue = [x]
data = []
while queue:
now = queue.pop()
if self.par[now] == now:
root = now
else:
# 根でないなら親の要素で再検索
data.append(now)
queue.append(self.par[now])
# 検索する過程で親を更新
for y in data:
self.par[y] = root
return root
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return True
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.count[y] += self.count[x]
self.count[x] = 0
else:
self.par[y] = x
self.count[x] += self.count[y]
self.count[y] = 0
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
return False
# 同じ集合に属しているか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
# 属している集合の要素数
def size(self, x):
q = UnionFind.find(self, x)
return self.count[q]
n, m = list(map(int, input().split()))
data = [tuple([int(z) - 1 for z in input().split()]) for _ in range(m)][::-1]
u = UnionFind(n)
ans = [n*(n-1)//2]
for i in range(m):
if u.same_check(data[i][0], data[i][1]):
ans.append(ans[-1])
else:
ans.append(ans[-1] - u.size(data[i][0])*u.size(data[i][1]))
u.union(data[i][0], data[i][1])
for x in ans[::-1][1:]:
print(x)
| 62 | 69 | 1,534 | 1,869 |
n, m = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(m)]
# 入力
AB.reverse()
ans = [0] * (m + 1)
ans[m] = n * (n - 1) // 2
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
self.count = [1] * (n + 1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.count[y] += self.count[x]
self.count[x] = 0
else:
self.par[y] = x
self.count[x] += self.count[y]
self.count[y] = 0
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
# 属している集合の要素数
def search(self, x):
q = UnionFind.find(self, x)
return self.count[q]
uf = UnionFind(n)
for i in range(m):
a = AB[i][0]
b = AB[i][1]
# print(a,b)
if uf.same_check(a, b):
ans[m - i - 1] = ans[m - i]
continue
else:
s = uf.search(a)
t = uf.search(b)
# print(s,t)
uf.union(a, b)
ans[m - i - 1] = (
ans[m - i]
+ s * (s - 1) // 2
+ t * (t - 1) // 2
- (s + t) * (s + t - 1) // 2
)
for i in range(1, m + 1):
print((ans[i]))
|
class UnionFind:
def __init__(self, n):
# 親要素のノード番号を格納 par[x] == x の時そのノードは根
self.par = [i for i in range(n + 1)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * (n + 1)
# 各々の集合の要素数(根が代表して値を持っておく)
self.count = [1] * (n + 1)
# 検索
def find(self, x):
# 根ならその番号を返す
root = x
queue = [x]
data = []
while queue:
now = queue.pop()
if self.par[now] == now:
root = now
else:
# 根でないなら親の要素で再検索
data.append(now)
queue.append(self.par[now])
# 検索する過程で親を更新
for y in data:
self.par[y] = root
return root
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return True
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.count[y] += self.count[x]
self.count[x] = 0
else:
self.par[y] = x
self.count[x] += self.count[y]
self.count[y] = 0
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
return False
# 同じ集合に属しているか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
# 属している集合の要素数
def size(self, x):
q = UnionFind.find(self, x)
return self.count[q]
n, m = list(map(int, input().split()))
data = [tuple([int(z) - 1 for z in input().split()]) for _ in range(m)][::-1]
u = UnionFind(n)
ans = [n * (n - 1) // 2]
for i in range(m):
if u.same_check(data[i][0], data[i][1]):
ans.append(ans[-1])
else:
ans.append(ans[-1] - u.size(data[i][0]) * u.size(data[i][1]))
u.union(data[i][0], data[i][1])
for x in ans[::-1][1:]:
print(x)
| false | 10.144928 |
[
"-n, m = list(map(int, input().split()))",
"-AB = [list(map(int, input().split())) for i in range(m)]",
"-# 入力",
"-AB.reverse()",
"-ans = [0] * (m + 1)",
"-ans[m] = n * (n - 1) // 2",
"-",
"-",
"+ # 親要素のノード番号を格納 par[x] == x の時そのノードは根",
"+ # 木の高さを格納する(初期状態では0)",
"+ # 各々の集合の要素数(根が代表して値を持っておく)",
"- if self.par[x] == x:",
"- return x",
"- else:",
"- self.par[x] = self.find(self.par[x])",
"- return self.par[x]",
"+ # 根ならその番号を返す",
"+ root = x",
"+ queue = [x]",
"+ data = []",
"+ while queue:",
"+ now = queue.pop()",
"+ if self.par[now] == now:",
"+ root = now",
"+ else:",
"+ # 根でないなら親の要素で再検索",
"+ data.append(now)",
"+ queue.append(self.par[now])",
"+ # 検索する過程で親を更新",
"+ for y in data:",
"+ self.par[y] = root",
"+ return root",
"+ if x == y:",
"+ return True",
"+ return False",
"- # 同じ集合に属するか判定",
"+ # 同じ集合に属しているか判定",
"- def search(self, x):",
"+ def size(self, x):",
"-uf = UnionFind(n)",
"+n, m = list(map(int, input().split()))",
"+data = [tuple([int(z) - 1 for z in input().split()]) for _ in range(m)][::-1]",
"+u = UnionFind(n)",
"+ans = [n * (n - 1) // 2]",
"- a = AB[i][0]",
"- b = AB[i][1]",
"- # print(a,b)",
"- if uf.same_check(a, b):",
"- ans[m - i - 1] = ans[m - i]",
"- continue",
"+ if u.same_check(data[i][0], data[i][1]):",
"+ ans.append(ans[-1])",
"- s = uf.search(a)",
"- t = uf.search(b)",
"- # print(s,t)",
"- uf.union(a, b)",
"- ans[m - i - 1] = (",
"- ans[m - i]",
"- + s * (s - 1) // 2",
"- + t * (t - 1) // 2",
"- - (s + t) * (s + t - 1) // 2",
"- )",
"-for i in range(1, m + 1):",
"- print((ans[i]))",
"+ ans.append(ans[-1] - u.size(data[i][0]) * u.size(data[i][1]))",
"+ u.union(data[i][0], data[i][1])",
"+for x in ans[::-1][1:]:",
"+ print(x)"
] | false | 0.087428 | 0.073635 | 1.187316 |
[
"s104706491",
"s013897532"
] |
u489762173
|
p03103
|
python
|
s943900369
|
s124696218
| 290 | 168 | 28,972 | 27,496 |
Accepted
|
Accepted
| 42.07 |
import sys
input = sys.stdin.buffer.readline
from collections import deque
def main():
N, M = list(map(int, input().split()))
AB = [0] * N
for i in range(N):
AB[i] = list(map(int, input().split()))
AB = sorted(AB)
have = 0
price = 0
for x, y in AB:
if M - have < y:
price += x * (M - have)
break
else:
price += x * y
have += y
print(price)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N, M = list(map(int, readline().split()))
d = list(map(int, read().split()))
AB = list(zip(d, d))
AB = sorted(AB)
have = 0
price = 0
for x, y in AB:
if M - have < y:
price += x * (M - have)
break
else:
price += x * y
have += y
print(price)
main()
| 28 | 28 | 479 | 493 |
import sys
input = sys.stdin.buffer.readline
from collections import deque
def main():
N, M = list(map(int, input().split()))
AB = [0] * N
for i in range(N):
AB[i] = list(map(int, input().split()))
AB = sorted(AB)
have = 0
price = 0
for x, y in AB:
if M - have < y:
price += x * (M - have)
break
else:
price += x * y
have += y
print(price)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N, M = list(map(int, readline().split()))
d = list(map(int, read().split()))
AB = list(zip(d, d))
AB = sorted(AB)
have = 0
price = 0
for x, y in AB:
if M - have < y:
price += x * (M - have)
break
else:
price += x * y
have += y
print(price)
main()
| false | 0 |
[
"-input = sys.stdin.buffer.readline",
"-from collections import deque",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"- N, M = list(map(int, input().split()))",
"- AB = [0] * N",
"- for i in range(N):",
"- AB[i] = list(map(int, input().split()))",
"+ N, M = list(map(int, readline().split()))",
"+ d = list(map(int, read().split()))",
"+ AB = list(zip(d, d))"
] | false | 0.060239 | 0.037766 | 1.595075 |
[
"s943900369",
"s124696218"
] |
u701318346
|
p02923
|
python
|
s074159329
|
s128017490
| 108 | 88 | 14,224 | 15,020 |
Accepted
|
Accepted
| 18.52 |
N = int(eval(input()))
H = list(map(int, input().split()))
if N == 1:
print((0))
else:
ans = 0
H1 = H[0]
H2 = H[1]
count = 1
move = 0
while count != N:
count += 1
if H2 <= H1:
move += 1
ans = max(ans, move)
else:
move = 0
if count != N:
H1 = H2
H2 = H[count]
print(ans)
|
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
count = 0
for i in range(N - 1):
if H[i] >= H[i + 1]:
count += 1
ans = max(ans, count)
else:
count = 0
print(ans)
| 23 | 13 | 410 | 221 |
N = int(eval(input()))
H = list(map(int, input().split()))
if N == 1:
print((0))
else:
ans = 0
H1 = H[0]
H2 = H[1]
count = 1
move = 0
while count != N:
count += 1
if H2 <= H1:
move += 1
ans = max(ans, move)
else:
move = 0
if count != N:
H1 = H2
H2 = H[count]
print(ans)
|
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
count = 0
for i in range(N - 1):
if H[i] >= H[i + 1]:
count += 1
ans = max(ans, count)
else:
count = 0
print(ans)
| false | 43.478261 |
[
"-if N == 1:",
"- print((0))",
"-else:",
"- ans = 0",
"- H1 = H[0]",
"- H2 = H[1]",
"- count = 1",
"- move = 0",
"- while count != N:",
"+ans = 0",
"+count = 0",
"+for i in range(N - 1):",
"+ if H[i] >= H[i + 1]:",
"- if H2 <= H1:",
"- move += 1",
"- ans = max(ans, move)",
"- else:",
"- move = 0",
"- if count != N:",
"- H1 = H2",
"- H2 = H[count]",
"- print(ans)",
"+ ans = max(ans, count)",
"+ else:",
"+ count = 0",
"+print(ans)"
] | false | 0.104967 | 0.078434 | 1.338282 |
[
"s074159329",
"s128017490"
] |
u258492760
|
p03075
|
python
|
s972197078
|
s048739221
| 38 | 18 | 3,064 | 2,940 |
Accepted
|
Accepted
| 52.63 |
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
ab = b - a
ac = c - a
ad = d - a
ae = e - a
bc = c - b
bd = d - b
be = e - b
cd = d - c
ce = e - c
de = e - d
if ab <= k and ac <= k and ad <= k and ae <= k and bc <= k and bd <= k and be <= k and cd <= k and ce <= k and de <= k:
print('Yay!')
else:
print(':(')
|
N = 5
a2e = [int(eval(input())) for _ in range(N)]
k = int(eval(input()))
for i in range(N):
for j in range(N):
if k < abs(a2e[i] - a2e[j]):
print(':(')
exit()
print('Yay!')
| 22 | 11 | 394 | 210 |
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))
ab = b - a
ac = c - a
ad = d - a
ae = e - a
bc = c - b
bd = d - b
be = e - b
cd = d - c
ce = e - c
de = e - d
if (
ab <= k
and ac <= k
and ad <= k
and ae <= k
and bc <= k
and bd <= k
and be <= k
and cd <= k
and ce <= k
and de <= k
):
print("Yay!")
else:
print(":(")
|
N = 5
a2e = [int(eval(input())) for _ in range(N)]
k = int(eval(input()))
for i in range(N):
for j in range(N):
if k < abs(a2e[i] - a2e[j]):
print(":(")
exit()
print("Yay!")
| false | 50 |
[
"-a = int(eval(input()))",
"-b = int(eval(input()))",
"-c = int(eval(input()))",
"-d = int(eval(input()))",
"-e = int(eval(input()))",
"+N = 5",
"+a2e = [int(eval(input())) for _ in range(N)]",
"-ab = b - a",
"-ac = c - a",
"-ad = d - a",
"-ae = e - a",
"-bc = c - b",
"-bd = d - b",
"-be = e - b",
"-cd = d - c",
"-ce = e - c",
"-de = e - d",
"-if (",
"- ab <= k",
"- and ac <= k",
"- and ad <= k",
"- and ae <= k",
"- and bc <= k",
"- and bd <= k",
"- and be <= k",
"- and cd <= k",
"- and ce <= k",
"- and de <= k",
"-):",
"- print(\"Yay!\")",
"-else:",
"- print(\":(\")",
"+for i in range(N):",
"+ for j in range(N):",
"+ if k < abs(a2e[i] - a2e[j]):",
"+ print(\":(\")",
"+ exit()",
"+print(\"Yay!\")"
] | false | 0.077589 | 0.096044 | 0.807848 |
[
"s972197078",
"s048739221"
] |
u389910364
|
p03286
|
python
|
s833224366
|
s889920962
| 288 | 160 | 21,196 | 13,360 |
Accepted
|
Accepted
| 44.44 |
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N = int(sys.stdin.readline())
if N == 0:
print((0))
exit()
ans = ''
odd = False
while abs(N) > 0:
if N & 1:
ans += '1'
else:
ans += '0'
if odd:
N += 1
N >>= 1
odd = not odd
print((ans[::-1]))
|
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
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
N = int(sys.stdin.buffer.readline())
if N == 0:
print((0))
exit()
N = -N
ans = ''
while N != 0:
if N % -2 == 0:
ans += '0'
else:
ans += '1'
N //= -2
print((ans[::-1]))
| 43 | 43 | 789 | 778 |
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
N = int(sys.stdin.readline())
if N == 0:
print((0))
exit()
ans = ""
odd = False
while abs(N) > 0:
if N & 1:
ans += "1"
else:
ans += "0"
if odd:
N += 1
N >>= 1
odd = not odd
print((ans[::-1]))
|
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
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
N = int(sys.stdin.buffer.readline())
if N == 0:
print((0))
exit()
N = -N
ans = ""
while N != 0:
if N % -2 == 0:
ans += "0"
else:
ans += "1"
N //= -2
print((ans[::-1]))
| false | 0 |
[
"+import cmath",
"-sys.setrecursionlimit(2147483647)",
"+sys.setrecursionlimit(10**9)",
"-N = int(sys.stdin.readline())",
"+# MOD = 998244353",
"+N = int(sys.stdin.buffer.readline())",
"+N = -N",
"-odd = False",
"-while abs(N) > 0:",
"- if N & 1:",
"+while N != 0:",
"+ if N % -2 == 0:",
"+ ans += \"0\"",
"+ else:",
"- else:",
"- ans += \"0\"",
"- if odd:",
"- N += 1",
"- N >>= 1",
"- odd = not odd",
"+ N //= -2"
] | false | 0.040892 | 0.042653 | 0.958724 |
[
"s833224366",
"s889920962"
] |
u729133443
|
p03379
|
python
|
s102414903
|
s675012580
| 313 | 283 | 25,052 | 25,052 |
Accepted
|
Accepted
| 9.58 |
n,*x=list(map(int,open(0).read().split()))
y=sorted(x)
a,b=y[n//2],y[n//2-1]
for i in x:print((a*(i<=b)or b))
|
n,*x=list(map(int,open(0).read().split()))
y=sorted(x)[n//2-1:n//2+1]
for i in x:print((y[i<=y[0]]))
| 4 | 3 | 104 | 94 |
n, *x = list(map(int, open(0).read().split()))
y = sorted(x)
a, b = y[n // 2], y[n // 2 - 1]
for i in x:
print((a * (i <= b) or b))
|
n, *x = list(map(int, open(0).read().split()))
y = sorted(x)[n // 2 - 1 : n // 2 + 1]
for i in x:
print((y[i <= y[0]]))
| false | 25 |
[
"-y = sorted(x)",
"-a, b = y[n // 2], y[n // 2 - 1]",
"+y = sorted(x)[n // 2 - 1 : n // 2 + 1]",
"- print((a * (i <= b) or b))",
"+ print((y[i <= y[0]]))"
] | false | 0.074605 | 0.109039 | 0.684209 |
[
"s102414903",
"s675012580"
] |
u832871520
|
p03478
|
python
|
s918203784
|
s119943505
| 38 | 25 | 3,060 | 2,940 |
Accepted
|
Accepted
| 34.21 |
N, A, B = list(map(int, input().split()))
sum = 0
for n in range(N + 1):
wa = 0
sn = str(n)
size = len(sn)
for s in range(size):
wa += int(sn[s])
if A <= wa and B >= wa:
sum += n
print(sum)
|
def sumOfDigits(n):
sum = 0
while(n > 0):
sum += n % 10
n //= 10
return sum
N, A, B = list(map(int, input().split()))
sum = 0
for n in range(N + 1):
wa = sumOfDigits(n)
if A <= wa and B >= wa:
sum += n
print(sum)
| 12 | 15 | 231 | 266 |
N, A, B = list(map(int, input().split()))
sum = 0
for n in range(N + 1):
wa = 0
sn = str(n)
size = len(sn)
for s in range(size):
wa += int(sn[s])
if A <= wa and B >= wa:
sum += n
print(sum)
|
def sumOfDigits(n):
sum = 0
while n > 0:
sum += n % 10
n //= 10
return sum
N, A, B = list(map(int, input().split()))
sum = 0
for n in range(N + 1):
wa = sumOfDigits(n)
if A <= wa and B >= wa:
sum += n
print(sum)
| false | 20 |
[
"+def sumOfDigits(n):",
"+ sum = 0",
"+ while n > 0:",
"+ sum += n % 10",
"+ n //= 10",
"+ return sum",
"+",
"+",
"- wa = 0",
"- sn = str(n)",
"- size = len(sn)",
"- for s in range(size):",
"- wa += int(sn[s])",
"+ wa = sumOfDigits(n)"
] | false | 0.042885 | 0.083438 | 0.513975 |
[
"s918203784",
"s119943505"
] |
u021019433
|
p02803
|
python
|
s720634259
|
s634438226
| 625 | 560 | 3,316 | 3,316 |
Accepted
|
Accepted
| 10.4 |
from collections import deque
h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
r = 0
for i in range(h):
for j in range(w):
if a[i][j] == '.':
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while(q):
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
if 0 <= i1 < h:
for j1 in range(j - d, j + 2, 2):
if 0 <= j1 < w and b[i1][j1] == '.':
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
|
from collections import deque
h, w = list(map(int, input().split()))
a = ['#' * (w + 2)] * 2
a[1: 1] = ['#' + eval(input()) + '#' for _ in range(h)]
r = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if a[i][j] == '.':
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while(q):
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
for j1 in range(j - d, j + 2, 2):
if b[i1][j1] == '.':
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
| 24 | 24 | 640 | 647 |
from collections import deque
h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
r = 0
for i in range(h):
for j in range(w):
if a[i][j] == ".":
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while q:
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
if 0 <= i1 < h:
for j1 in range(j - d, j + 2, 2):
if 0 <= j1 < w and b[i1][j1] == ".":
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
|
from collections import deque
h, w = list(map(int, input().split()))
a = ["#" * (w + 2)] * 2
a[1:1] = ["#" + eval(input()) + "#" for _ in range(h)]
r = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if a[i][j] == ".":
b = list(map(list, a))
q = deque()
b[i][j] = 0
q.append((i, j))
while q:
i, j = q.popleft()
r = max(r, b[i][j])
d = 0
for i1 in range(i - 1, i + 2):
for j1 in range(j - d, j + 2, 2):
if b[i1][j1] == ".":
b[i1][j1] = b[i][j] + 1
q.append((i1, j1))
d ^= 1
print(r)
| false | 0 |
[
"-a = [eval(input()) for _ in range(h)]",
"+a = [\"#\" * (w + 2)] * 2",
"+a[1:1] = [\"#\" + eval(input()) + \"#\" for _ in range(h)]",
"-for i in range(h):",
"- for j in range(w):",
"+for i in range(1, h + 1):",
"+ for j in range(1, w + 1):",
"- if 0 <= i1 < h:",
"- for j1 in range(j - d, j + 2, 2):",
"- if 0 <= j1 < w and b[i1][j1] == \".\":",
"- b[i1][j1] = b[i][j] + 1",
"- q.append((i1, j1))",
"+ for j1 in range(j - d, j + 2, 2):",
"+ if b[i1][j1] == \".\":",
"+ b[i1][j1] = b[i][j] + 1",
"+ q.append((i1, j1))"
] | false | 0.043507 | 0.080813 | 0.538363 |
[
"s720634259",
"s634438226"
] |
u794173881
|
p03464
|
python
|
s106404435
|
s755277582
| 252 | 230 | 63,856 | 63,856 |
Accepted
|
Accepted
| 8.73 |
n = int(eval(input()))
a = list(map(int, input().split()))[::-1]
min_ans = 2
max_ans = 2
for i in range(n):
min_ans = -((-min_ans) // a[i]) * a[i]
for i in range(n):
max_ans = (max_ans// a[i]) * a[i] +a[i] - 1
a = a[::-1]
tmp_ans = min_ans
tmp_ans2 = max_ans
for i in range(n):
tmp_ans = (tmp_ans // a[i]) * a[i]
tmp_ans2 = (tmp_ans // a[i]) * a[i]
if tmp_ans == 2 and tmp_ans2 == 2:
print((min_ans, max_ans))
else:
print((-1))
|
k = int(eval(input()))
a = list(map(int, input().split()))
max_ans = 2
for i in range(k)[::-1]:
max_ans = (max_ans // a[i]) * a[i] + (a[i] - 1)
min_ans = 2
for i in range(k)[::-1]:
min_ans = -((-min_ans) // a[i]) * a[i]
tmp = max_ans
for i in range(k):
tmp = (tmp // a[i]) * a[i]
if tmp != 2:
print((-1))
exit()
tmp = min_ans
for i in range(k):
tmp = (tmp // a[i]) * a[i]
if tmp != 2:
print((-1))
exit()
print((min_ans, max_ans))
| 23 | 26 | 476 | 487 |
n = int(eval(input()))
a = list(map(int, input().split()))[::-1]
min_ans = 2
max_ans = 2
for i in range(n):
min_ans = -((-min_ans) // a[i]) * a[i]
for i in range(n):
max_ans = (max_ans // a[i]) * a[i] + a[i] - 1
a = a[::-1]
tmp_ans = min_ans
tmp_ans2 = max_ans
for i in range(n):
tmp_ans = (tmp_ans // a[i]) * a[i]
tmp_ans2 = (tmp_ans // a[i]) * a[i]
if tmp_ans == 2 and tmp_ans2 == 2:
print((min_ans, max_ans))
else:
print((-1))
|
k = int(eval(input()))
a = list(map(int, input().split()))
max_ans = 2
for i in range(k)[::-1]:
max_ans = (max_ans // a[i]) * a[i] + (a[i] - 1)
min_ans = 2
for i in range(k)[::-1]:
min_ans = -((-min_ans) // a[i]) * a[i]
tmp = max_ans
for i in range(k):
tmp = (tmp // a[i]) * a[i]
if tmp != 2:
print((-1))
exit()
tmp = min_ans
for i in range(k):
tmp = (tmp // a[i]) * a[i]
if tmp != 2:
print((-1))
exit()
print((min_ans, max_ans))
| false | 11.538462 |
[
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))[::-1]",
"+k = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+max_ans = 2",
"+for i in range(k)[::-1]:",
"+ max_ans = (max_ans // a[i]) * a[i] + (a[i] - 1)",
"-max_ans = 2",
"-for i in range(n):",
"+for i in range(k)[::-1]:",
"-for i in range(n):",
"- max_ans = (max_ans // a[i]) * a[i] + a[i] - 1",
"-a = a[::-1]",
"-tmp_ans = min_ans",
"-tmp_ans2 = max_ans",
"-for i in range(n):",
"- tmp_ans = (tmp_ans // a[i]) * a[i]",
"- tmp_ans2 = (tmp_ans // a[i]) * a[i]",
"-if tmp_ans == 2 and tmp_ans2 == 2:",
"- print((min_ans, max_ans))",
"-else:",
"+tmp = max_ans",
"+for i in range(k):",
"+ tmp = (tmp // a[i]) * a[i]",
"+if tmp != 2:",
"+ exit()",
"+tmp = min_ans",
"+for i in range(k):",
"+ tmp = (tmp // a[i]) * a[i]",
"+if tmp != 2:",
"+ print((-1))",
"+ exit()",
"+print((min_ans, max_ans))"
] | false | 0.082206 | 0.101193 | 0.812373 |
[
"s106404435",
"s755277582"
] |
u219197917
|
p03031
|
python
|
s374175491
|
s966649446
| 42 | 37 | 9,200 | 8,988 |
Accepted
|
Accepted
| 11.9 |
n, m = [int(i) for i in input().split()]
ks = [[int(i) for i in input().split()] for _ in range(m)]
p = [int(i) for i in input().split()]
cnt = 0
for i in range(2**n):
on = set(j + 1 for j in range(n) if i >> j & 1 == 1)
flag = True
for j in range(m):
_, *s = ks[j]
flag &= len(on & set(s)) % 2 == p[j]
cnt += flag
print(cnt)
|
from itertools import product
n, m = list(map(int, input().split()))
l = [[int(i) for i in input().split()] for _ in range(m)]
p = [int(i) for i in input().split()]
c = 0
for sw in product((0, 1), repeat=n):
for i in range(m):
if sum(sw[si - 1] for si in l[i][1:]) % 2 != p[i]:
break
else:
c += 1
print(c)
| 12 | 13 | 353 | 349 |
n, m = [int(i) for i in input().split()]
ks = [[int(i) for i in input().split()] for _ in range(m)]
p = [int(i) for i in input().split()]
cnt = 0
for i in range(2**n):
on = set(j + 1 for j in range(n) if i >> j & 1 == 1)
flag = True
for j in range(m):
_, *s = ks[j]
flag &= len(on & set(s)) % 2 == p[j]
cnt += flag
print(cnt)
|
from itertools import product
n, m = list(map(int, input().split()))
l = [[int(i) for i in input().split()] for _ in range(m)]
p = [int(i) for i in input().split()]
c = 0
for sw in product((0, 1), repeat=n):
for i in range(m):
if sum(sw[si - 1] for si in l[i][1:]) % 2 != p[i]:
break
else:
c += 1
print(c)
| false | 7.692308 |
[
"-n, m = [int(i) for i in input().split()]",
"-ks = [[int(i) for i in input().split()] for _ in range(m)]",
"+from itertools import product",
"+",
"+n, m = list(map(int, input().split()))",
"+l = [[int(i) for i in input().split()] for _ in range(m)]",
"-cnt = 0",
"-for i in range(2**n):",
"- on = set(j + 1 for j in range(n) if i >> j & 1 == 1)",
"- flag = True",
"- for j in range(m):",
"- _, *s = ks[j]",
"- flag &= len(on & set(s)) % 2 == p[j]",
"- cnt += flag",
"-print(cnt)",
"+c = 0",
"+for sw in product((0, 1), repeat=n):",
"+ for i in range(m):",
"+ if sum(sw[si - 1] for si in l[i][1:]) % 2 != p[i]:",
"+ break",
"+ else:",
"+ c += 1",
"+print(c)"
] | false | 0.039036 | 0.045069 | 0.866147 |
[
"s374175491",
"s966649446"
] |
u497596438
|
p03699
|
python
|
s501977345
|
s587917783
| 187 | 137 | 48,876 | 4,628 |
Accepted
|
Accepted
| 26.74 |
N=int(eval(input()))
S=set([0])
for i in range(N):
T=set(S)
s=int(eval(input()))
for t in T:
S.add(t+s)
S=list(S)
S.sort()
for i in S[::-1]:
if i%10!=0:
print(i)
quit()
print((0))
|
N=int(eval(input()))
S=[]
for i in range(N):
s=int(eval(input()))
S.append(s)
t=set([0])
for i in range(N):
t_=set()
for s in t:
t_.add(s)
t_.add(s+S[i])
t=t_
ans=0
for s in t:
if s%10==0:
continue
ans=max(s,ans)
print(ans)
| 14 | 18 | 219 | 281 |
N = int(eval(input()))
S = set([0])
for i in range(N):
T = set(S)
s = int(eval(input()))
for t in T:
S.add(t + s)
S = list(S)
S.sort()
for i in S[::-1]:
if i % 10 != 0:
print(i)
quit()
print((0))
|
N = int(eval(input()))
S = []
for i in range(N):
s = int(eval(input()))
S.append(s)
t = set([0])
for i in range(N):
t_ = set()
for s in t:
t_.add(s)
t_.add(s + S[i])
t = t_
ans = 0
for s in t:
if s % 10 == 0:
continue
ans = max(s, ans)
print(ans)
| false | 22.222222 |
[
"-S = set([0])",
"+S = []",
"- T = set(S)",
"- for t in T:",
"- S.add(t + s)",
"-S = list(S)",
"-S.sort()",
"-for i in S[::-1]:",
"- if i % 10 != 0:",
"- print(i)",
"- quit()",
"-print((0))",
"+ S.append(s)",
"+t = set([0])",
"+for i in range(N):",
"+ t_ = set()",
"+ for s in t:",
"+ t_.add(s)",
"+ t_.add(s + S[i])",
"+ t = t_",
"+ans = 0",
"+for s in t:",
"+ if s % 10 == 0:",
"+ continue",
"+ ans = max(s, ans)",
"+print(ans)"
] | false | 0.034135 | 0.052494 | 0.650261 |
[
"s501977345",
"s587917783"
] |
u173230196
|
p03045
|
python
|
s024403489
|
s482210683
| 1,735 | 1,370 | 7,088 | 7,088 |
Accepted
|
Accepted
| 21.04 |
n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
while i != xy[i]:
i = xy[i]
xy[x] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
rx = root(x)
ry = root(y)
if rx < ry:
xy[rx] = ry
else:
xy[ry] = rx
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)
|
n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
a = []
while i != xy[i]:
i = xy[i]
a += [i]
for b in a:
xy[b] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
xy[root(x)] = root(y)
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)
| 25 | 23 | 404 | 376 |
n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
while i != xy[i]:
i = xy[i]
xy[x] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
rx = root(x)
ry = root(y)
if rx < ry:
xy[rx] = ry
else:
xy[ry] = rx
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)
|
n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
a = []
while i != xy[i]:
i = xy[i]
a += [i]
for b in a:
xy[b] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
xy[root(x)] = root(y)
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)
| false | 8 |
[
"+ a = []",
"- xy[x] = i",
"+ a += [i]",
"+ for b in a:",
"+ xy[b] = i",
"- rx = root(x)",
"- ry = root(y)",
"- if rx < ry:",
"- xy[rx] = ry",
"- else:",
"- xy[ry] = rx",
"+ xy[root(x)] = root(y)"
] | false | 0.08868 | 0.046901 | 1.890786 |
[
"s024403489",
"s482210683"
] |
u729133443
|
p03503
|
python
|
s814114215
|
s238181883
| 252 | 78 | 41,308 | 3,444 |
Accepted
|
Accepted
| 69.05 |
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print((max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024))))
|
I=input;n=int(I());f=eval('int(I()[::2],2),'*n);p=eval('I().split(),'*n);print((max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024))))
| 1 | 1 | 166 | 158 |
I = input
n = int(I())
f = [int(I()[::2], 2) for _ in [0] * n]
p = [I().split() for _ in [0] * n]
print(
(
max(
sum(int(q[bin(i & g).count("1")]) for g, q in zip(f, p))
for i in range(1, 1024)
)
)
)
|
I = input
n = int(I())
f = eval("int(I()[::2],2)," * n)
p = eval("I().split()," * n)
print(
(
max(
sum(int(q[bin(i & g).count("1")]) for g, q in zip(f, p))
for i in range(1, 1024)
)
)
)
| false | 0 |
[
"-f = [int(I()[::2], 2) for _ in [0] * n]",
"-p = [I().split() for _ in [0] * n]",
"+f = eval(\"int(I()[::2],2),\" * n)",
"+p = eval(\"I().split(),\" * n)"
] | false | 0.048556 | 0.064003 | 0.758649 |
[
"s814114215",
"s238181883"
] |
u094191970
|
p02923
|
python
|
s396600914
|
s164563133
| 82 | 70 | 15,020 | 15,020 |
Accepted
|
Accepted
| 14.63 |
n=int(eval(input()))
h=list(map(int,input().split()))+[10**9+1]
ans=0
cnt=0
for i in range(1,n+1):
if h[i-1]>=h[i]:
cnt+=1
else:
ans=max(ans,cnt)
cnt=0
print(ans)
|
n=int(eval(input()))
h=list(map(int,input().split()))
ans=0
t_ans=0
b_h=h[0]
for i in h[1:]:
if b_h>=i:
t_ans+=1
else:
ans=max(ans,t_ans)
t_ans=0
b_h=i
ans=max(ans,t_ans)
print(ans)
| 11 | 14 | 198 | 206 |
n = int(eval(input()))
h = list(map(int, input().split())) + [10**9 + 1]
ans = 0
cnt = 0
for i in range(1, n + 1):
if h[i - 1] >= h[i]:
cnt += 1
else:
ans = max(ans, cnt)
cnt = 0
print(ans)
|
n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
t_ans = 0
b_h = h[0]
for i in h[1:]:
if b_h >= i:
t_ans += 1
else:
ans = max(ans, t_ans)
t_ans = 0
b_h = i
ans = max(ans, t_ans)
print(ans)
| false | 21.428571 |
[
"-h = list(map(int, input().split())) + [10**9 + 1]",
"+h = list(map(int, input().split()))",
"-cnt = 0",
"-for i in range(1, n + 1):",
"- if h[i - 1] >= h[i]:",
"- cnt += 1",
"+t_ans = 0",
"+b_h = h[0]",
"+for i in h[1:]:",
"+ if b_h >= i:",
"+ t_ans += 1",
"- ans = max(ans, cnt)",
"- cnt = 0",
"+ ans = max(ans, t_ans)",
"+ t_ans = 0",
"+ b_h = i",
"+ans = max(ans, t_ans)"
] | false | 0.039995 | 0.038961 | 1.026535 |
[
"s396600914",
"s164563133"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.