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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u186838327 | p02947 | python | s993774951 | s486839038 | 1,040 | 583 | 124,760 | 72,792 | Accepted | Accepted | 43.94 | n = int(eval(input()))
D = {}
ans = 0
for i in range(n):
s = str(eval(input()))
d = [0]*26
for j in range(len(s)):
c = ord(s[j])-ord('a')
d[c] += 1
d = tuple(d)
if d in D:
ans += D[d]
D[d] += 1
else:
D[d] = 1
print(ans)
| n = int(eval(input()))
S = [str(eval(input())) for _ in range(n)]
d = {}
ans = 0
for i in range(n):
s = S[i]
s = list(s)
s.sort()
s = ''.join(s)
if s in d:
ans += d[s]
if s in d:
d[s] += 1
else:
d[s] = 1
print(ans)
| 16 | 17 | 287 | 272 | n = int(eval(input()))
D = {}
ans = 0
for i in range(n):
s = str(eval(input()))
d = [0] * 26
for j in range(len(s)):
c = ord(s[j]) - ord("a")
d[c] += 1
d = tuple(d)
if d in D:
ans += D[d]
D[d] += 1
else:
D[d] = 1
print(ans)
| n = int(eval(input()))
S = [str(eval(input())) for _ in range(n)]
d = {}
ans = 0
for i in range(n):
s = S[i]
s = list(s)
s.sort()
s = "".join(s)
if s in d:
ans += d[s]
if s in d:
d[s] += 1
else:
d[s] = 1
print(ans)
| false | 5.882353 | [
"-D = {}",
"+S = [str(eval(input())) for _ in range(n)]",
"+d = {}",
"- s = str(eval(input()))",
"- d = [0] * 26",
"- for j in range(len(s)):",
"- c = ord(s[j]) - ord(\"a\")",
"- d[c] += 1",
"- d = tuple(d)",
"- if d in D:",
"- ans += D[d]",
"- D[d] += 1",
"+ s = S[i]",
"+ s = list(s)",
"+ s.sort()",
"+ s = \"\".join(s)",
"+ if s in d:",
"+ ans += d[s]",
"+ if s in d:",
"+ d[s] += 1",
"- D[d] = 1",
"+ d[s] = 1"
] | false | 0.043177 | 0.106736 | 0.404525 | [
"s993774951",
"s486839038"
] |
u025616818 | p03030 | python | s867692295 | s039722667 | 32 | 26 | 9,056 | 8,996 | Accepted | Accepted | 18.75 | n=int(eval(input()))
res = []
for i in range(n):
s,p=list(map(str, input().split()))
res += [(s,int(p))]
res1=res
res = sorted(res, key=lambda x:(x[0],-x[1]))
for i in range(n):
print((res1.index(res[i])+1)) | n=int(eval(input()))
res=[]
for i in range(n):
s,p=list(map(str,input().split()))
res.append([s,int(p)])
res1=res
res=sorted(res,key=lambda x:(x[0], -x[1]))
for i in range(n):
print((res1.index(res[i])+1)) | 9 | 9 | 213 | 208 | n = int(eval(input()))
res = []
for i in range(n):
s, p = list(map(str, input().split()))
res += [(s, int(p))]
res1 = res
res = sorted(res, key=lambda x: (x[0], -x[1]))
for i in range(n):
print((res1.index(res[i]) + 1))
| n = int(eval(input()))
res = []
for i in range(n):
s, p = list(map(str, input().split()))
res.append([s, int(p)])
res1 = res
res = sorted(res, key=lambda x: (x[0], -x[1]))
for i in range(n):
print((res1.index(res[i]) + 1))
| false | 0 | [
"- res += [(s, int(p))]",
"+ res.append([s, int(p)])"
] | false | 0.036537 | 0.034609 | 1.055701 | [
"s867692295",
"s039722667"
] |
u545368057 | p02889 | python | s910858362 | s619254167 | 1,764 | 1,418 | 61,656 | 107,480 | Accepted | Accepted | 19.61 | N,M,L = list(map(int, input().split()))
INF = 10**18
# 初期化
d = [[INF]*N for i in range(N)]
for i in range(N):
d[i][i] = 0
for i in range(M):
a,b,c = list(map(int, input().split()))
a -= 1
b -= 1
# 多重辺の場合はMIN
d[a][b] = c
d[b][a] = c
# 最適化(わーしゃゆふよいど)
for k in range(N):
for i in range(N):
# 左右は対称だろう
for j in range(i+1,N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
d[j][i] = d[i][j]
# 初期化2
d2 = [[INF]*N for i in range(N)]
for i in range(N):
d2[i][i] = 0
for i in range(N):
for j in range(N):
# 給油できるところに辺を張る
if d[i][j] <= L:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(i+1,N):
d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j])
d2[j][i] = d2[i][j]
#query
Q = int(eval(input()))
for i in range(Q):
l = list(map(int, input().split()))
s = min(l)-1
t = max(l)-1
ans = d2[s][t]
if ans == INF:
ans = 0
print((ans-1)) | N,M,L = list(map(int, input().split()))
Edges = [list(map(int, input().split())) for i in range(M)]
Q = int(eval(input()))
Queries = [list(map(int, input().split())) for i in range(Q)]
INF = 10**18
# 初期化
d = [[INF]*N for i in range(N)]
for i in range(N):
d[i][i] = 0
for a,b,c in Edges:
a -= 1
b -= 1
# 多重辺の場合はMIN
d[a][b] = c
d[b][a] = c
# 最適化(わーしゃゆふよいど)
for k in range(N):
for i in range(N):
# 左右は対称だろう
for j in range(i+1,N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
d[j][i] = d[i][j]
# 初期化2
d2 = [[INF]*N for i in range(N)]
for i in range(N):
d2[i][i] = 0
for i in range(N):
for j in range(N):
# 給油できるところに辺を張る
if d[i][j] <= L:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(i+1,N):
d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j])
d2[j][i] = d2[i][j]
#query
for a,b in Queries:
s = min(a,b)-1
t = max(a,b)-1
ans = d2[s][t]
if ans == INF:
ans = 0
print((ans-1)) | 48 | 49 | 1,051 | 1,090 | N, M, L = list(map(int, input().split()))
INF = 10**18
# 初期化
d = [[INF] * N for i in range(N)]
for i in range(N):
d[i][i] = 0
for i in range(M):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
# 多重辺の場合はMIN
d[a][b] = c
d[b][a] = c
# 最適化(わーしゃゆふよいど)
for k in range(N):
for i in range(N):
# 左右は対称だろう
for j in range(i + 1, N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
d[j][i] = d[i][j]
# 初期化2
d2 = [[INF] * N for i in range(N)]
for i in range(N):
d2[i][i] = 0
for i in range(N):
for j in range(N):
# 給油できるところに辺を張る
if d[i][j] <= L:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(i + 1, N):
d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j])
d2[j][i] = d2[i][j]
# query
Q = int(eval(input()))
for i in range(Q):
l = list(map(int, input().split()))
s = min(l) - 1
t = max(l) - 1
ans = d2[s][t]
if ans == INF:
ans = 0
print((ans - 1))
| N, M, L = list(map(int, input().split()))
Edges = [list(map(int, input().split())) for i in range(M)]
Q = int(eval(input()))
Queries = [list(map(int, input().split())) for i in range(Q)]
INF = 10**18
# 初期化
d = [[INF] * N for i in range(N)]
for i in range(N):
d[i][i] = 0
for a, b, c in Edges:
a -= 1
b -= 1
# 多重辺の場合はMIN
d[a][b] = c
d[b][a] = c
# 最適化(わーしゃゆふよいど)
for k in range(N):
for i in range(N):
# 左右は対称だろう
for j in range(i + 1, N):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
d[j][i] = d[i][j]
# 初期化2
d2 = [[INF] * N for i in range(N)]
for i in range(N):
d2[i][i] = 0
for i in range(N):
for j in range(N):
# 給油できるところに辺を張る
if d[i][j] <= L:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(i + 1, N):
d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j])
d2[j][i] = d2[i][j]
# query
for a, b in Queries:
s = min(a, b) - 1
t = max(a, b) - 1
ans = d2[s][t]
if ans == INF:
ans = 0
print((ans - 1))
| false | 2.040816 | [
"+Edges = [list(map(int, input().split())) for i in range(M)]",
"+Q = int(eval(input()))",
"+Queries = [list(map(int, input().split())) for i in range(Q)]",
"-for i in range(M):",
"- a, b, c = list(map(int, input().split()))",
"+for a, b, c in Edges:",
"-Q = int(eval(input()))",
"-for i in range(Q):",
"- l = list(map(int, input().split()))",
"- s = min(l) - 1",
"- t = max(l) - 1",
"+for a, b in Queries:",
"+ s = min(a, b) - 1",
"+ t = max(a, b) - 1"
] | false | 0.036885 | 0.040604 | 0.908412 | [
"s910858362",
"s619254167"
] |
u409306788 | p02700 | python | s682339229 | s276796735 | 25 | 21 | 9,200 | 9,184 | Accepted | Accepted | 16 | import sys
input = sys.stdin.readline
# B - Battle
def takahashi_win():
A, B, C, D = list(map(int, input().split()))
i = 0
while True:
if i % 2 == 0:
if C-B <= 0:
return True
else:
C -= B
else:
if A-D <= 0:
return False
else:
A -= D
i += 1
if takahashi_win():
print('Yes')
else:
print('No') | import sys
input = sys.stdin.readline
# B - Battle
def win_takahashi(A, B, C, D):
for i in range(200):
if i % 2 == 0:
if B >= C:
return True
else:
C -= B
else:
if D >= A:
return False
else:
A -= D
A, B, C, D = list(map(int, input().split()))
if win_takahashi(A, B, C, D):
print('Yes')
else:
print('No')
| 27 | 25 | 356 | 364 | import sys
input = sys.stdin.readline
# B - Battle
def takahashi_win():
A, B, C, D = list(map(int, input().split()))
i = 0
while True:
if i % 2 == 0:
if C - B <= 0:
return True
else:
C -= B
else:
if A - D <= 0:
return False
else:
A -= D
i += 1
if takahashi_win():
print("Yes")
else:
print("No")
| import sys
input = sys.stdin.readline
# B - Battle
def win_takahashi(A, B, C, D):
for i in range(200):
if i % 2 == 0:
if B >= C:
return True
else:
C -= B
else:
if D >= A:
return False
else:
A -= D
A, B, C, D = list(map(int, input().split()))
if win_takahashi(A, B, C, D):
print("Yes")
else:
print("No")
| false | 7.407407 | [
"-def takahashi_win():",
"- A, B, C, D = list(map(int, input().split()))",
"- i = 0",
"- while True:",
"+def win_takahashi(A, B, C, D):",
"+ for i in range(200):",
"- if C - B <= 0:",
"+ if B >= C:",
"- if A - D <= 0:",
"+ if D >= A:",
"- i += 1",
"-if takahashi_win():",
"+A, B, C, D = list(map(int, input().split()))",
"+if win_takahashi(A, B, C, D):"
] | false | 0.069952 | 0.035657 | 1.961787 | [
"s682339229",
"s276796735"
] |
u320511454 | p04030 | python | s324225493 | s748810701 | 20 | 18 | 3,316 | 2,940 | Accepted | Accepted | 10 | from collections import deque
S=eval(input())
d=deque()
for s in S:
if s == 'B':
if len(d) != 0:
d.pop()
else:
d.append(s)
print((''.join(d))) | S=eval(input())
d=[]
for s in S:
if s == 'B':
if d:
d.pop()
else:
d.append(s)
print((''.join(d))) | 11 | 9 | 163 | 115 | from collections import deque
S = eval(input())
d = deque()
for s in S:
if s == "B":
if len(d) != 0:
d.pop()
else:
d.append(s)
print(("".join(d)))
| S = eval(input())
d = []
for s in S:
if s == "B":
if d:
d.pop()
else:
d.append(s)
print(("".join(d)))
| false | 18.181818 | [
"-from collections import deque",
"-",
"-d = deque()",
"+d = []",
"- if len(d) != 0:",
"+ if d:"
] | false | 0.040088 | 0.039847 | 1.006046 | [
"s324225493",
"s748810701"
] |
u332906195 | p03107 | python | s407154187 | s593247886 | 32 | 18 | 3,188 | 3,188 | Accepted | Accepted | 43.75 | # -*- coding: utf-8 -*-
S = eval(input())
l0, l1 = 0, 0
for s in S:
if s == '0':
l0 += 1
elif s == '1':
l1 += 1
print((min(l0, l1) * 2))
| # -*- coding: utf-8 -*-
S = eval(input())
print((min(S.count('1'), S.count('0')) * 2))
| 12 | 4 | 167 | 83 | # -*- coding: utf-8 -*-
S = eval(input())
l0, l1 = 0, 0
for s in S:
if s == "0":
l0 += 1
elif s == "1":
l1 += 1
print((min(l0, l1) * 2))
| # -*- coding: utf-8 -*-
S = eval(input())
print((min(S.count("1"), S.count("0")) * 2))
| false | 66.666667 | [
"-l0, l1 = 0, 0",
"-for s in S:",
"- if s == \"0\":",
"- l0 += 1",
"- elif s == \"1\":",
"- l1 += 1",
"-print((min(l0, l1) * 2))",
"+print((min(S.count(\"1\"), S.count(\"0\")) * 2))"
] | false | 0.03578 | 0.034974 | 1.023038 | [
"s407154187",
"s593247886"
] |
u945181840 | p02845 | python | s468441220 | s831230911 | 285 | 148 | 20,384 | 13,956 | Accepted | Accepted | 48.07 | import sys
read = sys.stdin.read
N, *A = list(map(int, read().split()))
mod = 10 ** 9 + 7
hats = [[0] * 3 for _ in range(N + 1)]
answer = 1
for i in range(N):
answer *= hats[i].count(A[i])
answer %= mod
flag = True
for j in range(3):
if hats[i][j] == A[i] and flag:
hats[i + 1][j] = A[i] + 1
flag = False
else:
hats[i + 1][j] = hats[i][j]
print(answer) | import sys
read = sys.stdin.read
N, *A = list(map(int, read().split()))
mod = 10 ** 9 + 7
hats = [0] * 3
answer = 1
for i in range(N):
answer *= hats.count(A[i])
answer %= mod
for j in range(3):
if hats[j] == A[i]:
hats[j] += 1
break
print(answer) | 21 | 18 | 438 | 306 | import sys
read = sys.stdin.read
N, *A = list(map(int, read().split()))
mod = 10**9 + 7
hats = [[0] * 3 for _ in range(N + 1)]
answer = 1
for i in range(N):
answer *= hats[i].count(A[i])
answer %= mod
flag = True
for j in range(3):
if hats[i][j] == A[i] and flag:
hats[i + 1][j] = A[i] + 1
flag = False
else:
hats[i + 1][j] = hats[i][j]
print(answer)
| import sys
read = sys.stdin.read
N, *A = list(map(int, read().split()))
mod = 10**9 + 7
hats = [0] * 3
answer = 1
for i in range(N):
answer *= hats.count(A[i])
answer %= mod
for j in range(3):
if hats[j] == A[i]:
hats[j] += 1
break
print(answer)
| false | 14.285714 | [
"-hats = [[0] * 3 for _ in range(N + 1)]",
"+hats = [0] * 3",
"- answer *= hats[i].count(A[i])",
"+ answer *= hats.count(A[i])",
"- flag = True",
"- if hats[i][j] == A[i] and flag:",
"- hats[i + 1][j] = A[i] + 1",
"- flag = False",
"- else:",
"- hats[i + 1][j] = hats[i][j]",
"+ if hats[j] == A[i]:",
"+ hats[j] += 1",
"+ break"
] | false | 0.047078 | 0.047015 | 1.001337 | [
"s468441220",
"s831230911"
] |
u766684188 | p02949 | python | s877153443 | s505580366 | 950 | 835 | 45,880 | 43,484 | Accepted | Accepted | 12.11 | import sys
input=sys.stdin.readline
def BellmanFord(Edges,num_v,source):
inf=float('inf')
dist=[inf for _ in range(num_v)]
dist[source]=0
for i in range(num_v):
for edge in Edges:
if edge[0]!=inf and dist[edge[1]]>dist[edge[0]]+edge[2]:
dist[edge[1]]=dist[edge[0]]+edge[2]
if i==num_v-1:
before_dist=dist[num_v-1]
for _ in range(num_v):
for edge in Edges:
if edge[0]!=inf and dist[edge[1]]>dist[edge[0]]+edge[2]:
dist[edge[1]]=dist[edge[0]]+edge[2]
if before_dist!=dist[num_v-1]:
return -1
return dist
n,m,p=list(map(int,input().split()))
Edges=[]
for _ in range(m):
a,b,c=list(map(int,input().split()))
a-=1; b-=1
Edges.append((a,b,-(c-p)))
d=BellmanFord(Edges,n,0)
print((-1 if d==-1 else max(0,-d[-1]))) | import sys
input=sys.stdin.readline
def BellmanFord(Edges,num_v,start,goal):
inf=float('inf')
Dist=[inf]*num_v
Dist[start]=0
for _ in range(num_v):
for fr,to,cost in Edges:
if Dist[fr]!=inf and Dist[to]>Dist[fr]+cost:
Dist[to]=Dist[fr]+cost
d=Dist[goal]
for _ in range(num_v):
for fr,to,cost in Edges:
if Dist[fr]!=inf and Dist[to]>Dist[fr]+cost:
Dist[to]=-inf
if d!=Dist[goal]:
return -inf
return d
n,m,p=list(map(int,input().split()))
Edges=[]
for _ in range(m):
a,b,c=list(map(int,input().split()))
a-=1; b-=1
Edges.append((a,b,-(c-p)))
d=BellmanFord(Edges,n,0,n-1)
print((-1 if d==-float('inf') else max(0,-d))) | 29 | 28 | 974 | 754 | import sys
input = sys.stdin.readline
def BellmanFord(Edges, num_v, source):
inf = float("inf")
dist = [inf for _ in range(num_v)]
dist[source] = 0
for i in range(num_v):
for edge in Edges:
if edge[0] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
dist[edge[1]] = dist[edge[0]] + edge[2]
if i == num_v - 1:
before_dist = dist[num_v - 1]
for _ in range(num_v):
for edge in Edges:
if (
edge[0] != inf
and dist[edge[1]] > dist[edge[0]] + edge[2]
):
dist[edge[1]] = dist[edge[0]] + edge[2]
if before_dist != dist[num_v - 1]:
return -1
return dist
n, m, p = list(map(int, input().split()))
Edges = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
Edges.append((a, b, -(c - p)))
d = BellmanFord(Edges, n, 0)
print((-1 if d == -1 else max(0, -d[-1])))
| import sys
input = sys.stdin.readline
def BellmanFord(Edges, num_v, start, goal):
inf = float("inf")
Dist = [inf] * num_v
Dist[start] = 0
for _ in range(num_v):
for fr, to, cost in Edges:
if Dist[fr] != inf and Dist[to] > Dist[fr] + cost:
Dist[to] = Dist[fr] + cost
d = Dist[goal]
for _ in range(num_v):
for fr, to, cost in Edges:
if Dist[fr] != inf and Dist[to] > Dist[fr] + cost:
Dist[to] = -inf
if d != Dist[goal]:
return -inf
return d
n, m, p = list(map(int, input().split()))
Edges = []
for _ in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
Edges.append((a, b, -(c - p)))
d = BellmanFord(Edges, n, 0, n - 1)
print((-1 if d == -float("inf") else max(0, -d)))
| false | 3.448276 | [
"-def BellmanFord(Edges, num_v, source):",
"+def BellmanFord(Edges, num_v, start, goal):",
"- dist = [inf for _ in range(num_v)]",
"- dist[source] = 0",
"- for i in range(num_v):",
"- for edge in Edges:",
"- if edge[0] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:",
"- dist[edge[1]] = dist[edge[0]] + edge[2]",
"- if i == num_v - 1:",
"- before_dist = dist[num_v - 1]",
"- for _ in range(num_v):",
"- for edge in Edges:",
"- if (",
"- edge[0] != inf",
"- and dist[edge[1]] > dist[edge[0]] + edge[2]",
"- ):",
"- dist[edge[1]] = dist[edge[0]] + edge[2]",
"- if before_dist != dist[num_v - 1]:",
"- return -1",
"- return dist",
"+ Dist = [inf] * num_v",
"+ Dist[start] = 0",
"+ for _ in range(num_v):",
"+ for fr, to, cost in Edges:",
"+ if Dist[fr] != inf and Dist[to] > Dist[fr] + cost:",
"+ Dist[to] = Dist[fr] + cost",
"+ d = Dist[goal]",
"+ for _ in range(num_v):",
"+ for fr, to, cost in Edges:",
"+ if Dist[fr] != inf and Dist[to] > Dist[fr] + cost:",
"+ Dist[to] = -inf",
"+ if d != Dist[goal]:",
"+ return -inf",
"+ return d",
"-d = BellmanFord(Edges, n, 0)",
"-print((-1 if d == -1 else max(0, -d[-1])))",
"+d = BellmanFord(Edges, n, 0, n - 1)",
"+print((-1 if d == -float(\"inf\") else max(0, -d)))"
] | false | 0.037099 | 0.037727 | 0.983351 | [
"s877153443",
"s505580366"
] |
u875291233 | p02616 | python | s796297352 | s123181011 | 216 | 157 | 31,108 | 31,240 | Accepted | Accepted | 27.31 | # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,k,*a = list(map(int,read().split()))
pos = []
neg = []
#both = []
zero = 0
for i in a:
#if i!=0: both.append(i)
if i==0: zero += 1
elif i > 0: pos.append(i)
else: neg.append(-i)
#print(pos,neg,zero)
MOD = 10**9+7
if n - zero < k: # ゼロが多すぎる
print((0))
elif pos == []: # 全部ゼロ以下
if k%2==0:
neg.sort(reverse=True)
ans = 1
for i in range(k):
ans *= neg[i]
ans %= MOD
print(ans)
else:
if zero:
print((0))
else: # 負のみ
neg.sort()
ans = -1
for i in range(k):
ans *= neg[i]
ans %= MOD
print((ans%MOD))
else: #正もいる
pos.sort(reverse=True)
neg.sort(reverse=True)
cp = len(pos)
cn = len(neg)
i = j = 0
for _ in range(k):
if i == cp:
j += 1
elif j == cn:
i += 1
else:
if pos[i] > neg[j]:
i += 1
else:
j += 1
#print(cp,cn,i,j)
if j%2 == 0:
ans = 1
for x in pos[:i]:
ans *= x
ans %= MOD
for x in neg[:j]:
ans *= x
ans %= MOD
print(ans)
else:
can_i = i and j < cn
can_j = j and i < cp
if not can_i and not can_j:
if zero: print((0))
else:
ans = -1
for x in pos[:i]:
ans *= x
ans %= MOD
for x in neg[:j]:
ans *= x
ans %= MOD
print(ans)
exit()
if not can_i:
j -= 1
i += 1
elif not can_j:
j += 1
i -= 1
else:
if pos[i]*pos[i-1] >= neg[j]*neg[j-1]:
j -= 1
i += 1
else:
j += 1
i -= 1
ans = 1
for x in pos[:i]:
ans *= x
ans %= MOD
for x in neg[:j]:
ans *= x
ans %= MOD
print(ans)
| # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n,k,*a = list(map(int,read().split()))
pos = []
neg = []
MOD = 10**9+7
for i in a:
if i >= 0: pos.append(i)
else: neg.append(i)
if n==k:
ans = 1
for i in a:
ans *= i
ans %= MOD
print(ans)
elif pos == []: # 全部負
if k%2==0:
neg.sort()
ans = 1
for i in range(k):
ans *= neg[i]
ans %= MOD
print(ans)
else:
neg.sort(reverse=True)
ans = 1
for i in range(k):
ans *= neg[i]
ans %= MOD
print((ans%MOD))
else: #正もいる
pos.sort()
neg.sort(reverse=True)
if k&1:
ans = pos.pop()%MOD
else:
ans = 1
res = []
while len(pos)>1:
x,y=pos.pop(),pos.pop()
res.append(x*y)
while len(neg)>1:
x,y=neg.pop(),neg.pop()
res.append(x*y)
res.sort(reverse=True)
for i in range(k//2):
ans *= res[i]
ans %= MOD
print(ans)
| 119 | 62 | 2,459 | 1,126 | # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, k, *a = list(map(int, read().split()))
pos = []
neg = []
# both = []
zero = 0
for i in a:
# if i!=0: both.append(i)
if i == 0:
zero += 1
elif i > 0:
pos.append(i)
else:
neg.append(-i)
# print(pos,neg,zero)
MOD = 10**9 + 7
if n - zero < k: # ゼロが多すぎる
print((0))
elif pos == []: # 全部ゼロ以下
if k % 2 == 0:
neg.sort(reverse=True)
ans = 1
for i in range(k):
ans *= neg[i]
ans %= MOD
print(ans)
else:
if zero:
print((0))
else: # 負のみ
neg.sort()
ans = -1
for i in range(k):
ans *= neg[i]
ans %= MOD
print((ans % MOD))
else: # 正もいる
pos.sort(reverse=True)
neg.sort(reverse=True)
cp = len(pos)
cn = len(neg)
i = j = 0
for _ in range(k):
if i == cp:
j += 1
elif j == cn:
i += 1
else:
if pos[i] > neg[j]:
i += 1
else:
j += 1
# print(cp,cn,i,j)
if j % 2 == 0:
ans = 1
for x in pos[:i]:
ans *= x
ans %= MOD
for x in neg[:j]:
ans *= x
ans %= MOD
print(ans)
else:
can_i = i and j < cn
can_j = j and i < cp
if not can_i and not can_j:
if zero:
print((0))
else:
ans = -1
for x in pos[:i]:
ans *= x
ans %= MOD
for x in neg[:j]:
ans *= x
ans %= MOD
print(ans)
exit()
if not can_i:
j -= 1
i += 1
elif not can_j:
j += 1
i -= 1
else:
if pos[i] * pos[i - 1] >= neg[j] * neg[j - 1]:
j -= 1
i += 1
else:
j += 1
i -= 1
ans = 1
for x in pos[:i]:
ans *= x
ans %= MOD
for x in neg[:j]:
ans *= x
ans %= MOD
print(ans)
| # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, k, *a = list(map(int, read().split()))
pos = []
neg = []
MOD = 10**9 + 7
for i in a:
if i >= 0:
pos.append(i)
else:
neg.append(i)
if n == k:
ans = 1
for i in a:
ans *= i
ans %= MOD
print(ans)
elif pos == []: # 全部負
if k % 2 == 0:
neg.sort()
ans = 1
for i in range(k):
ans *= neg[i]
ans %= MOD
print(ans)
else:
neg.sort(reverse=True)
ans = 1
for i in range(k):
ans *= neg[i]
ans %= MOD
print((ans % MOD))
else: # 正もいる
pos.sort()
neg.sort(reverse=True)
if k & 1:
ans = pos.pop() % MOD
else:
ans = 1
res = []
while len(pos) > 1:
x, y = pos.pop(), pos.pop()
res.append(x * y)
while len(neg) > 1:
x, y = neg.pop(), neg.pop()
res.append(x * y)
res.sort(reverse=True)
for i in range(k // 2):
ans *= res[i]
ans %= MOD
print(ans)
| false | 47.89916 | [
"-# both = []",
"-zero = 0",
"+MOD = 10**9 + 7",
"- # if i!=0: both.append(i)",
"- if i == 0:",
"- zero += 1",
"- elif i > 0:",
"+ if i >= 0:",
"- neg.append(-i)",
"-# print(pos,neg,zero)",
"-MOD = 10**9 + 7",
"-if n - zero < k: # ゼロが多すぎる",
"- print((0))",
"-elif pos == []: # 全部ゼロ以下",
"+ neg.append(i)",
"+if n == k:",
"+ ans = 1",
"+ for i in a:",
"+ ans *= i",
"+ ans %= MOD",
"+ print(ans)",
"+elif pos == []: # 全部負",
"- neg.sort(reverse=True)",
"+ neg.sort()",
"- if zero:",
"- print((0))",
"- else: # 負のみ",
"- neg.sort()",
"- ans = -1",
"- for i in range(k):",
"- ans *= neg[i]",
"- ans %= MOD",
"- print((ans % MOD))",
"+ neg.sort(reverse=True)",
"+ ans = 1",
"+ for i in range(k):",
"+ ans *= neg[i]",
"+ ans %= MOD",
"+ print((ans % MOD))",
"- pos.sort(reverse=True)",
"+ pos.sort()",
"- cp = len(pos)",
"- cn = len(neg)",
"- i = j = 0",
"- for _ in range(k):",
"- if i == cp:",
"- j += 1",
"- elif j == cn:",
"- i += 1",
"- else:",
"- if pos[i] > neg[j]:",
"- i += 1",
"- else:",
"- j += 1",
"- # print(cp,cn,i,j)",
"- if j % 2 == 0:",
"+ if k & 1:",
"+ ans = pos.pop() % MOD",
"+ else:",
"- for x in pos[:i]:",
"- ans *= x",
"- ans %= MOD",
"- for x in neg[:j]:",
"- ans *= x",
"- ans %= MOD",
"- print(ans)",
"- else:",
"- can_i = i and j < cn",
"- can_j = j and i < cp",
"- if not can_i and not can_j:",
"- if zero:",
"- print((0))",
"- else:",
"- ans = -1",
"- for x in pos[:i]:",
"- ans *= x",
"- ans %= MOD",
"- for x in neg[:j]:",
"- ans *= x",
"- ans %= MOD",
"- print(ans)",
"- exit()",
"- if not can_i:",
"- j -= 1",
"- i += 1",
"- elif not can_j:",
"- j += 1",
"- i -= 1",
"- else:",
"- if pos[i] * pos[i - 1] >= neg[j] * neg[j - 1]:",
"- j -= 1",
"- i += 1",
"- else:",
"- j += 1",
"- i -= 1",
"- ans = 1",
"- for x in pos[:i]:",
"- ans *= x",
"- ans %= MOD",
"- for x in neg[:j]:",
"- ans *= x",
"- ans %= MOD",
"- print(ans)",
"+ res = []",
"+ while len(pos) > 1:",
"+ x, y = pos.pop(), pos.pop()",
"+ res.append(x * y)",
"+ while len(neg) > 1:",
"+ x, y = neg.pop(), neg.pop()",
"+ res.append(x * y)",
"+ res.sort(reverse=True)",
"+ for i in range(k // 2):",
"+ ans *= res[i]",
"+ ans %= MOD",
"+ print(ans)"
] | false | 0.03792 | 0.09706 | 0.390685 | [
"s796297352",
"s123181011"
] |
u693378622 | p02837 | python | s390887073 | s855041348 | 853 | 243 | 3,064 | 3,064 | Accepted | Accepted | 71.51 | n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int,input().split())))
# print(x)
ans = 0
for i in range(1<<n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i>>j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i>>(t[0]-1) &1 ) != t[1]:
flag = False
# break
# if flag == False:
# break
# if flag == False:
# break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int,input().split())))
# print(x)
ans = 0
for i in range(1<<n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i>>j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i>>(t[0]-1) &1 ) != t[1]:
flag = False
break
# if flag == False:
# break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| 44 | 42 | 965 | 901 | n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int, input().split())))
# print(x)
ans = 0
for i in range(1 << n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i >> j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i >> (t[0] - 1) & 1) != t[1]:
flag = False
# break
# if flag == False:
# break
# if flag == False:
# break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| n = int(eval(input()))
a = []
x = [[] for _ in range(n)]
for i in range(n):
k = int(eval(input()))
a.append(k)
for j in range(k):
x[i].append(list(map(int, input().split())))
# print(x)
ans = 0
for i in range(1 << n):
cnt = bin(i).count("1")
if ans > cnt:
continue
flag = True
for j in range(n):
# if i==3:
# print(i,j,i>>j&1,cnt)
if i >> j & 1:
# True if 1
# if i==3:
# print(i,j)
for t in x[j]:
# 証言:testimony
# if i == 3:
# print(i,t[0]-1, i>>t[0]-1, t[1])
if (i >> (t[0] - 1) & 1) != t[1]:
flag = False
break
# if flag == False:
# break
if flag == True:
# print(i) # 0 000
ans = cnt
print(ans)
| false | 4.545455 | [
"- # break",
"- # if flag == False:",
"- # break",
"+ break"
] | false | 0.040533 | 0.037748 | 1.073767 | [
"s390887073",
"s855041348"
] |
u686036872 | p03128 | python | s333468745 | s844162698 | 249 | 177 | 51,036 | 14,692 | Accepted | Accepted | 28.92 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1]*(N+1)
dp[0]=0
for i in range(N+1):
for j in A:
if i + B[j] <= N:
dp[i+B[j]]= max(dp[i]*10+j, dp[i+B[j]])
print((dp[N])) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
DP = [-1]*(N+1)
DP[0] = 0
for i in range(N):
for j in A:
if i+B[j] <= N:
DP[i+B[j]] = max(DP[i]*10+j, DP[i+B[j]])
print((DP[N])) | 10 | 14 | 266 | 273 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (N + 1)
dp[0] = 0
for i in range(N + 1):
for j in A:
if i + B[j] <= N:
dp[i + B[j]] = max(dp[i] * 10 + j, dp[i + B[j]])
print((dp[N]))
| N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
DP = [-1] * (N + 1)
DP[0] = 0
for i in range(N):
for j in A:
if i + B[j] <= N:
DP[i + B[j]] = max(DP[i] * 10 + j, DP[i + B[j]])
print((DP[N]))
| false | 28.571429 | [
"-dp = [-1] * (N + 1)",
"-dp[0] = 0",
"-for i in range(N + 1):",
"+DP = [-1] * (N + 1)",
"+DP[0] = 0",
"+for i in range(N):",
"- dp[i + B[j]] = max(dp[i] * 10 + j, dp[i + B[j]])",
"-print((dp[N]))",
"+ DP[i + B[j]] = max(DP[i] * 10 + j, DP[i + B[j]])",
"+print((DP[N]))"
] | false | 0.041006 | 0.042495 | 0.96497 | [
"s333468745",
"s844162698"
] |
u263830634 | p02837 | python | s471661705 | s586287110 | 348 | 143 | 3,064 | 3,064 | Accepted | Accepted | 58.91 | N = int(eval(input()))
lst = [[] for _ in range(N)]
for i in range(N):
A = int(eval(input()))
for _ in range(A):
x, y = list(map(int, input().split()))
lst[i].append([x - 1, y])
ans = 0
for i in range(2 ** N):
check = [-1] * N #1:正直者、0:不親切
count = 0 #カウント用
flag = True
for j in range(N):
if (i >> j) & 1: #正直者のとき
if check[j] == 0: #矛盾しているとき
flag = False
break
else:
check[j] = 1
# count += 1
for x, y in lst[j]:
if y == 1: #行き先が正直者
if check[x] != 0:
check[x] = 1
else: #矛盾しているとき
flag = False
break
else: #y == 0
if check[x] != 1:
check[x] = 0
else:
flag = False
break
else: #正直者でないとき
if check[j] == 1:
flag = False
break
else:
check[j] = 0
if flag == False:
break
if flag:
tmp = 0
for j in range(N):
if (i >> j) & 1:
tmp += 1
# print (i)
# print (check, flag)
ans = max(ans, tmp)
print (ans)
# print (lst) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N = int(eval(input()))
lst = [[] for _ in range(N)]
for i in range(N):
A = int(eval(input()))
for _ in range(A):
XY = tuple(map(int, input().split()))
lst[i].append(XY)
ans = 0
for i in range(2 ** N):
count = 0
flag = True
for j in range(N):
if (i >> j) & 1: #正直者の時、証言を確認する
for x, y in lst[j]:
if y == 1:
if (i >> (x - 1)) & 1:
continue
else:
pass
if y == 0:
if (i >> (x - 1)) & 1:
pass
else:
continue
flag = False
break
count += 1
if not flag:
break
if flag:
ans = max(ans, count)
print (ans)
| 57 | 43 | 1,421 | 958 | N = int(eval(input()))
lst = [[] for _ in range(N)]
for i in range(N):
A = int(eval(input()))
for _ in range(A):
x, y = list(map(int, input().split()))
lst[i].append([x - 1, y])
ans = 0
for i in range(2**N):
check = [-1] * N # 1:正直者、0:不親切
count = 0 # カウント用
flag = True
for j in range(N):
if (i >> j) & 1: # 正直者のとき
if check[j] == 0: # 矛盾しているとき
flag = False
break
else:
check[j] = 1
# count += 1
for x, y in lst[j]:
if y == 1: # 行き先が正直者
if check[x] != 0:
check[x] = 1
else: # 矛盾しているとき
flag = False
break
else: # y == 0
if check[x] != 1:
check[x] = 0
else:
flag = False
break
else: # 正直者でないとき
if check[j] == 1:
flag = False
break
else:
check[j] = 0
if flag == False:
break
if flag:
tmp = 0
for j in range(N):
if (i >> j) & 1:
tmp += 1
# print (i)
# print (check, flag)
ans = max(ans, tmp)
print(ans)
# print (lst)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
N = int(eval(input()))
lst = [[] for _ in range(N)]
for i in range(N):
A = int(eval(input()))
for _ in range(A):
XY = tuple(map(int, input().split()))
lst[i].append(XY)
ans = 0
for i in range(2**N):
count = 0
flag = True
for j in range(N):
if (i >> j) & 1: # 正直者の時、証言を確認する
for x, y in lst[j]:
if y == 1:
if (i >> (x - 1)) & 1:
continue
else:
pass
if y == 0:
if (i >> (x - 1)) & 1:
pass
else:
continue
flag = False
break
count += 1
if not flag:
break
if flag:
ans = max(ans, count)
print(ans)
| false | 24.561404 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**9)",
"+MOD = 10**9 + 7",
"- x, y = list(map(int, input().split()))",
"- lst[i].append([x - 1, y])",
"+ XY = tuple(map(int, input().split()))",
"+ lst[i].append(XY)",
"- check = [-1] * N # 1:正直者、0:不親切",
"- count = 0 # カウント用",
"+ count = 0",
"- if (i >> j) & 1: # 正直者のとき",
"- if check[j] == 0: # 矛盾しているとき",
"+ if (i >> j) & 1: # 正直者の時、証言を確認する",
"+ for x, y in lst[j]:",
"+ if y == 1:",
"+ if (i >> (x - 1)) & 1:",
"+ continue",
"+ else:",
"+ pass",
"+ if y == 0:",
"+ if (i >> (x - 1)) & 1:",
"+ pass",
"+ else:",
"+ continue",
"- else:",
"- check[j] = 1",
"- # count += 1",
"- for x, y in lst[j]:",
"- if y == 1: # 行き先が正直者",
"- if check[x] != 0:",
"- check[x] = 1",
"- else: # 矛盾しているとき",
"- flag = False",
"- break",
"- else: # y == 0",
"- if check[x] != 1:",
"- check[x] = 0",
"- else:",
"- flag = False",
"- break",
"- else: # 正直者でないとき",
"- if check[j] == 1:",
"- flag = False",
"- break",
"- else:",
"- check[j] = 0",
"- if flag == False:",
"+ count += 1",
"+ if not flag:",
"- tmp = 0",
"- for j in range(N):",
"- if (i >> j) & 1:",
"- tmp += 1",
"- # print (i)",
"- # print (check, flag)",
"- ans = max(ans, tmp)",
"+ ans = max(ans, count)",
"-# print (lst)"
] | false | 0.035976 | 0.054126 | 0.664669 | [
"s471661705",
"s586287110"
] |
u241159583 | p02881 | python | s467563127 | s002166186 | 265 | 143 | 3,060 | 3,060 | Accepted | Accepted | 46.04 | import math
N = int(eval(input()))
a = math.floor(N ** 0.5) + 1
ans = N + 1
for i in range(1, a):
j = N // i
if i * j == N and i + j - 2 < ans:
ans = i + j - 2
print(ans) | import math
N = int(eval(input()))
a = math.floor(N ** 0.5)
ans = N
for x in range(1, a + 1):
if N % x != 0: continue
y = N // x
if ans > x + y - 2:
ans = x + y - 2
print(ans) | 11 | 11 | 186 | 190 | import math
N = int(eval(input()))
a = math.floor(N**0.5) + 1
ans = N + 1
for i in range(1, a):
j = N // i
if i * j == N and i + j - 2 < ans:
ans = i + j - 2
print(ans)
| import math
N = int(eval(input()))
a = math.floor(N**0.5)
ans = N
for x in range(1, a + 1):
if N % x != 0:
continue
y = N // x
if ans > x + y - 2:
ans = x + y - 2
print(ans)
| false | 0 | [
"-a = math.floor(N**0.5) + 1",
"-ans = N + 1",
"-for i in range(1, a):",
"- j = N // i",
"- if i * j == N and i + j - 2 < ans:",
"- ans = i + j - 2",
"+a = math.floor(N**0.5)",
"+ans = N",
"+for x in range(1, a + 1):",
"+ if N % x != 0:",
"+ continue",
"+ y = N // x",
"+ if ans > x + y - 2:",
"+ ans = x + y - 2"
] | false | 0.040595 | 0.036832 | 1.102183 | [
"s467563127",
"s002166186"
] |
u449473917 | p03221 | python | s735571905 | s934252303 | 629 | 431 | 33,684 | 31,084 | Accepted | Accepted | 31.48 | N,M = list(map(int, input().split()))
pref = [[0] for i in range(N+1)]
q=[]
for i in range(M):
p,y = list(map(int, input().split()))
pref[p].append(y)
q.append([p,y])
for p in pref:
p.sort()
import bisect
for p,y in q:
print(("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))) | import sys
input=sys.stdin.readline
N,M = list(map(int, input().split()))
pref = [[0] for i in range(N+1)]
import collections
q = collections.deque()
for i in range(M):
p,y = list(map(int, input().split()))
pref[p].append(y)
q.append((p,y))
for p in pref:
p.sort()
import bisect
for p,y in q:
print(("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))) | 15 | 19 | 300 | 381 | N, M = list(map(int, input().split()))
pref = [[0] for i in range(N + 1)]
q = []
for i in range(M):
p, y = list(map(int, input().split()))
pref[p].append(y)
q.append([p, y])
for p in pref:
p.sort()
import bisect
for p, y in q:
print(("%06d%06d" % (p, bisect.bisect_left(pref[p], y))))
| import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
pref = [[0] for i in range(N + 1)]
import collections
q = collections.deque()
for i in range(M):
p, y = list(map(int, input().split()))
pref[p].append(y)
q.append((p, y))
for p in pref:
p.sort()
import bisect
for p, y in q:
print(("%06d%06d" % (p, bisect.bisect_left(pref[p], y))))
| false | 21.052632 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-q = []",
"+import collections",
"+",
"+q = collections.deque()",
"- q.append([p, y])",
"+ q.append((p, y))"
] | false | 0.046119 | 0.045793 | 1.007116 | [
"s735571905",
"s934252303"
] |
u163320134 | p03645 | python | s310679507 | s326988230 | 765 | 573 | 38,320 | 18,936 | Accepted | Accepted | 25.1 | n,m=list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
g[a].append(b)
g[b].append(a)
flag=False
for i in g[1]:
for j in g[i]:
if j==n:
flag=True
if flag==True:
print('POSSIBLE')
else:
print('IMPOSSIBLE') | n,m=list(map(int,input().split()))
s1=set()
s2=set()
for _ in range(m):
a,b=list(map(int,input().split()))
if a==1:
s1.add(b)
if b==n:
s2.add(a)
if len(s1&s2)!=0:
print('POSSIBLE')
else:
print('IMPOSSIBLE') | 15 | 13 | 288 | 224 | n, m = list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
g[a].append(b)
g[b].append(a)
flag = False
for i in g[1]:
for j in g[i]:
if j == n:
flag = True
if flag == True:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| n, m = list(map(int, input().split()))
s1 = set()
s2 = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
s1.add(b)
if b == n:
s2.add(a)
if len(s1 & s2) != 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| false | 13.333333 | [
"-g = [[] for _ in range(n + 1)]",
"-for i in range(m):",
"+s1 = set()",
"+s2 = set()",
"+for _ in range(m):",
"- g[a].append(b)",
"- g[b].append(a)",
"-flag = False",
"-for i in g[1]:",
"- for j in g[i]:",
"- if j == n:",
"- flag = True",
"-if flag == True:",
"+ if a == 1:",
"+ s1.add(b)",
"+ if b == n:",
"+ s2.add(a)",
"+if len(s1 & s2) != 0:"
] | false | 0.073583 | 0.041435 | 1.775856 | [
"s310679507",
"s326988230"
] |
u600402037 | p02788 | python | s278773929 | s000966281 | 1,051 | 795 | 67,692 | 52,936 | Accepted | Accepted | 24.36 | import sys
sys.setrecursionlimit(10 ** 7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def main():
N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort()
over = [N] * N # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値(最大はNで対象なし)
cur = 1
for i in range(N):
while cur < N and XH[i][0] + D + D >= XH[cur][0]:
cur += 1
over[i] = cur
damage = 0 # 今までの累計のダメージ数 (影響のないダメージは引く)
reset = [0] * (N+1) # これ以降関係のないダメージ
answer = 0
for i in range(N):
x, h = XH[i]
damage -= reset[i]
h -= damage
if h > 0:
time = (h+A-1)//A
answer += time
damage += A * time
reset[over[i]] += A * time
print(answer)
if __name__ == "__main__":
main() | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N,D,A = list(map(int,readline().split()))
m = list(map(int,read().split()))
X,H = list(zip(*sorted(zip(m,m))))
over = [-1]*N
tmp=0
for i in range(N):
while(tmp<N and X[i]+D*2>=X[tmp]):
tmp += 1
over[i] = tmp
reset = [0]*N
ans = 0
dam = 0
for i in range(N):
if i>0:
reset[i] += reset[i-1]
hp = H[i]-dam+reset[i]
if hp > 0:
bomb = (hp+A-1)//A
ans += bomb
dam += bomb * A
if(over[i]<N):
reset[over[i]] += bomb * A
print(ans)
if __name__ == "__main__":
main()
| 36 | 35 | 867 | 749 | import sys
sys.setrecursionlimit(10**7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def main():
N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort()
over = [N] * N # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値(最大はNで対象なし)
cur = 1
for i in range(N):
while cur < N and XH[i][0] + D + D >= XH[cur][0]:
cur += 1
over[i] = cur
damage = 0 # 今までの累計のダメージ数 (影響のないダメージは引く)
reset = [0] * (N + 1) # これ以降関係のないダメージ
answer = 0
for i in range(N):
x, h = XH[i]
damage -= reset[i]
h -= damage
if h > 0:
time = (h + A - 1) // A
answer += time
damage += A * time
reset[over[i]] += A * time
print(answer)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N, D, A = list(map(int, readline().split()))
m = list(map(int, read().split()))
X, H = list(zip(*sorted(zip(m, m))))
over = [-1] * N
tmp = 0
for i in range(N):
while tmp < N and X[i] + D * 2 >= X[tmp]:
tmp += 1
over[i] = tmp
reset = [0] * N
ans = 0
dam = 0
for i in range(N):
if i > 0:
reset[i] += reset[i - 1]
hp = H[i] - dam + reset[i]
if hp > 0:
bomb = (hp + A - 1) // A
ans += bomb
dam += bomb * A
if over[i] < N:
reset[over[i]] += bomb * A
print(ans)
if __name__ == "__main__":
main()
| false | 2.777778 | [
"-sys.setrecursionlimit(10**7)",
"-sr = lambda: sys.stdin.readline().rstrip()",
"-ir = lambda: int(sr())",
"-lr = lambda: list(map(int, sr().split()))",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"- N, D, A = lr()",
"- XH = [lr() for _ in range(N)]",
"- XH.sort()",
"- over = [N] * N # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値(最大はNで対象なし)",
"- cur = 1",
"+ N, D, A = list(map(int, readline().split()))",
"+ m = list(map(int, read().split()))",
"+ X, H = list(zip(*sorted(zip(m, m))))",
"+ over = [-1] * N",
"+ tmp = 0",
"- while cur < N and XH[i][0] + D + D >= XH[cur][0]:",
"- cur += 1",
"- over[i] = cur",
"- damage = 0 # 今までの累計のダメージ数 (影響のないダメージは引く)",
"- reset = [0] * (N + 1) # これ以降関係のないダメージ",
"- answer = 0",
"+ while tmp < N and X[i] + D * 2 >= X[tmp]:",
"+ tmp += 1",
"+ over[i] = tmp",
"+ reset = [0] * N",
"+ ans = 0",
"+ dam = 0",
"- x, h = XH[i]",
"- damage -= reset[i]",
"- h -= damage",
"- if h > 0:",
"- time = (h + A - 1) // A",
"- answer += time",
"- damage += A * time",
"- reset[over[i]] += A * time",
"- print(answer)",
"+ if i > 0:",
"+ reset[i] += reset[i - 1]",
"+ hp = H[i] - dam + reset[i]",
"+ if hp > 0:",
"+ bomb = (hp + A - 1) // A",
"+ ans += bomb",
"+ dam += bomb * A",
"+ if over[i] < N:",
"+ reset[over[i]] += bomb * A",
"+ print(ans)"
] | false | 0.122799 | 0.141448 | 0.868154 | [
"s278773929",
"s000966281"
] |
u801049006 | p02684 | python | s103125989 | s602133000 | 161 | 133 | 32,376 | 32,100 | Accepted | Accepted | 17.39 | N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
s = [0] * (N+1)
p = 1
h = []
for i in range(K):
h.append(p)
s[p] = 1
p = A[p]
if s[p] != 0:
break
if i == K-1:
print(p)
exit()
else:
period = len(h) - h.index(p)
rem = (K - h.index(p)) % period
print((h[h.index(p):][rem]))
| n, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
seen = [False] * (n+1)
visited = []
nxt = 1
cnt = 0
while not seen[nxt] and cnt != k:
seen[nxt] = True
visited.append(nxt)
nxt = a[nxt]
cnt += 1
if cnt == k:
print(nxt)
exit()
idx = visited.index(nxt)
print((visited[idx:][(k-idx)%(len(visited)-idx)]))
| 21 | 19 | 365 | 374 | N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
s = [0] * (N + 1)
p = 1
h = []
for i in range(K):
h.append(p)
s[p] = 1
p = A[p]
if s[p] != 0:
break
if i == K - 1:
print(p)
exit()
else:
period = len(h) - h.index(p)
rem = (K - h.index(p)) % period
print((h[h.index(p) :][rem]))
| n, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
seen = [False] * (n + 1)
visited = []
nxt = 1
cnt = 0
while not seen[nxt] and cnt != k:
seen[nxt] = True
visited.append(nxt)
nxt = a[nxt]
cnt += 1
if cnt == k:
print(nxt)
exit()
idx = visited.index(nxt)
print((visited[idx:][(k - idx) % (len(visited) - idx)]))
| false | 9.52381 | [
"-N, K = list(map(int, input().split()))",
"-A = [0] + list(map(int, input().split()))",
"-s = [0] * (N + 1)",
"-p = 1",
"-h = []",
"-for i in range(K):",
"- h.append(p)",
"- s[p] = 1",
"- p = A[p]",
"- if s[p] != 0:",
"- break",
"-if i == K - 1:",
"- print(p)",
"+n, k = list(map(int, input().split()))",
"+a = [0] + list(map(int, input().split()))",
"+seen = [False] * (n + 1)",
"+visited = []",
"+nxt = 1",
"+cnt = 0",
"+while not seen[nxt] and cnt != k:",
"+ seen[nxt] = True",
"+ visited.append(nxt)",
"+ nxt = a[nxt]",
"+ cnt += 1",
"+if cnt == k:",
"+ print(nxt)",
"-else:",
"- period = len(h) - h.index(p)",
"- rem = (K - h.index(p)) % period",
"- print((h[h.index(p) :][rem]))",
"+idx = visited.index(nxt)",
"+print((visited[idx:][(k - idx) % (len(visited) - idx)]))"
] | false | 0.044133 | 0.03755 | 1.175308 | [
"s103125989",
"s602133000"
] |
u371763408 | p03353 | python | s566650455 | s119501599 | 1,770 | 36 | 3,956 | 5,068 | Accepted | Accepted | 97.97 | s = eval(input())
k = int(eval(input()))
#正解(全列挙してソートしてる)
sub_string=[]
for i in range(len(s)):
for j in range(1,k+1):
string = s[i:i+j]
if string not in sub_string:
sub_string.append(string)
sub_string.sort()
print((sub_string[k-1])) | s = eval(input())
k = int(eval(input()))
#正解(全列挙してソートしてる)
sub_string=[]
for i in range(len(s)):
for j in range(1,k+1):
sub_string.append(s[i:i+j])
sub_string=list(set(sub_string))
sub_string.sort()
print((sub_string[k-1])) | 12 | 11 | 248 | 225 | s = eval(input())
k = int(eval(input()))
# 正解(全列挙してソートしてる)
sub_string = []
for i in range(len(s)):
for j in range(1, k + 1):
string = s[i : i + j]
if string not in sub_string:
sub_string.append(string)
sub_string.sort()
print((sub_string[k - 1]))
| s = eval(input())
k = int(eval(input()))
# 正解(全列挙してソートしてる)
sub_string = []
for i in range(len(s)):
for j in range(1, k + 1):
sub_string.append(s[i : i + j])
sub_string = list(set(sub_string))
sub_string.sort()
print((sub_string[k - 1]))
| false | 8.333333 | [
"- string = s[i : i + j]",
"- if string not in sub_string:",
"- sub_string.append(string)",
"+ sub_string.append(s[i : i + j])",
"+sub_string = list(set(sub_string))"
] | false | 0.071398 | 0.038729 | 1.843505 | [
"s566650455",
"s119501599"
] |
u798260206 | p03611 | python | s088275525 | s251468187 | 184 | 137 | 14,564 | 27,876 | Accepted | Accepted | 25.54 | from collections import Counter
N = int(eval(input()))
A = list(map(int,input().split()))
C = Counter(A)
ans = 0
for i in range(10**5):
c = C[i-1] + C[i] + C[i+1]
ans = max(c,ans)
print(ans) | import collections
n = int(eval(input()))
a = list(map(int,input().split()))
lst = collections.defaultdict(int)
for i in a:
lst[i] += 1
lst[i-1] += 1
lst[i+1] += 1
lst = sorted(list(lst.items()),reverse=True,key=lambda x:x[1])
print((lst[0][1])) | 11 | 11 | 203 | 250 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
for i in range(10**5):
c = C[i - 1] + C[i] + C[i + 1]
ans = max(c, ans)
print(ans)
| import collections
n = int(eval(input()))
a = list(map(int, input().split()))
lst = collections.defaultdict(int)
for i in a:
lst[i] += 1
lst[i - 1] += 1
lst[i + 1] += 1
lst = sorted(list(lst.items()), reverse=True, key=lambda x: x[1])
print((lst[0][1]))
| false | 0 | [
"-from collections import Counter",
"+import collections",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-C = Counter(A)",
"-ans = 0",
"-for i in range(10**5):",
"- c = C[i - 1] + C[i] + C[i + 1]",
"- ans = max(c, ans)",
"-print(ans)",
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+lst = collections.defaultdict(int)",
"+for i in a:",
"+ lst[i] += 1",
"+ lst[i - 1] += 1",
"+ lst[i + 1] += 1",
"+lst = sorted(list(lst.items()), reverse=True, key=lambda x: x[1])",
"+print((lst[0][1]))"
] | false | 0.151763 | 0.047461 | 3.197657 | [
"s088275525",
"s251468187"
] |
u670180528 | p03972 | python | s748817734 | s254047178 | 399 | 237 | 27,692 | 26,468 | Accepted | Accepted | 40.6 | w,h,*L=list(map(int,open(0).read().split()))
P=L[:w];Q=L[w:]
x,y=w,h
sss=[]
for i,pi in enumerate(P):
sss.append((pi,1))
for j,qj in enumerate(Q):
sss.append((qj,0))
sss.sort()
ans=0
for c,f in sss:
if f and x:
x-=1
ans+=c*(y+1)
elif not f and y:
y-=1
ans+=c*(x+1)
print(ans)
| w,h,*L=list(map(int,open(0).read().split()))
P=L[:w];Q=[-qj for qj in L[w:]]
x,y,ans=w,h,0
for c in sorted(P+Q,key=abs):
if c>0:
if x:ans+=c*(y+1);x-=1
else:
if y:ans-=c*(x+1);y-=1
print(ans) | 21 | 9 | 305 | 199 | w, h, *L = list(map(int, open(0).read().split()))
P = L[:w]
Q = L[w:]
x, y = w, h
sss = []
for i, pi in enumerate(P):
sss.append((pi, 1))
for j, qj in enumerate(Q):
sss.append((qj, 0))
sss.sort()
ans = 0
for c, f in sss:
if f and x:
x -= 1
ans += c * (y + 1)
elif not f and y:
y -= 1
ans += c * (x + 1)
print(ans)
| w, h, *L = list(map(int, open(0).read().split()))
P = L[:w]
Q = [-qj for qj in L[w:]]
x, y, ans = w, h, 0
for c in sorted(P + Q, key=abs):
if c > 0:
if x:
ans += c * (y + 1)
x -= 1
else:
if y:
ans -= c * (x + 1)
y -= 1
print(ans)
| false | 57.142857 | [
"-Q = L[w:]",
"-x, y = w, h",
"-sss = []",
"-for i, pi in enumerate(P):",
"- sss.append((pi, 1))",
"-for j, qj in enumerate(Q):",
"- sss.append((qj, 0))",
"-sss.sort()",
"-ans = 0",
"-for c, f in sss:",
"- if f and x:",
"- x -= 1",
"- ans += c * (y + 1)",
"- elif not f and y:",
"- y -= 1",
"- ans += c * (x + 1)",
"+Q = [-qj for qj in L[w:]]",
"+x, y, ans = w, h, 0",
"+for c in sorted(P + Q, key=abs):",
"+ if c > 0:",
"+ if x:",
"+ ans += c * (y + 1)",
"+ x -= 1",
"+ else:",
"+ if y:",
"+ ans -= c * (x + 1)",
"+ y -= 1"
] | false | 0.059531 | 0.099251 | 0.599801 | [
"s748817734",
"s254047178"
] |
u633068244 | p00725 | python | s423294611 | s956608035 | 2,320 | 850 | 4,284 | 4,276 | Accepted | Accepted | 63.36 | def rec(x,y,t):
global ans
if t >= ans: return
if field[y][x] == 3: ans = min(ans,t)
for dx,dy in zip([1,0,-1,0],[0,1,0,-1]):
nx,ny = x+dx,y+dy
while 0 <= nx < W and 0 <= ny < H:
if field[ny][nx] == 3:
rec(nx,ny,t+1)
if field[ny][nx] == 1:
if abs(nx-x)+abs(ny-y) == 1: break
field[ny][nx] = 0
rec(nx-dx,ny-dy,t+1)
field[ny][nx] = 1
break
nx += dx; ny += dy
while 1:
W,H = list(map(int,input().split()))
if W == 0: break
field = [list(map(int,input().split())) for _ in range(H)]
for y in range(H):
for x in range(W):
if field[y][x] == 2: sx,sy = x,y
ans = 11
rec(sx,sy,0)
print(ans if ans <= 10 else -1) | dxy = list(zip([1,0,-1,0],[0,1,0,-1]))
def rec(x,y,t):
global ans
if t >= ans: return
if field[y][x] == 3: ans = min(ans,t)
for dx,dy in dxy:
nx,ny = x+dx,y+dy
while 0 <= nx < W and 0 <= ny < H:
if field[ny][nx] == 3: ans = t
elif field[ny][nx] == 1:
if abs(nx-x)+abs(ny-y) == 1: break
field[ny][nx] = 0
rec(nx-dx,ny-dy,t+1)
field[ny][nx] = 1
break
nx += dx; ny += dy
while 1:
W,H = list(map(int,input().split()))
if W == 0: break
field = [list(map(int,input().split())) for _ in range(H)]
for y in range(H):
for x in range(W):
if field[y][x] == 2: sx,sy = x,y
ans = 11
rec(sx,sy,1)
print(ans if ans <= 10 else -1) | 27 | 27 | 837 | 828 | def rec(x, y, t):
global ans
if t >= ans:
return
if field[y][x] == 3:
ans = min(ans, t)
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
nx, ny = x + dx, y + dy
while 0 <= nx < W and 0 <= ny < H:
if field[ny][nx] == 3:
rec(nx, ny, t + 1)
if field[ny][nx] == 1:
if abs(nx - x) + abs(ny - y) == 1:
break
field[ny][nx] = 0
rec(nx - dx, ny - dy, t + 1)
field[ny][nx] = 1
break
nx += dx
ny += dy
while 1:
W, H = list(map(int, input().split()))
if W == 0:
break
field = [list(map(int, input().split())) for _ in range(H)]
for y in range(H):
for x in range(W):
if field[y][x] == 2:
sx, sy = x, y
ans = 11
rec(sx, sy, 0)
print(ans if ans <= 10 else -1)
| dxy = list(zip([1, 0, -1, 0], [0, 1, 0, -1]))
def rec(x, y, t):
global ans
if t >= ans:
return
if field[y][x] == 3:
ans = min(ans, t)
for dx, dy in dxy:
nx, ny = x + dx, y + dy
while 0 <= nx < W and 0 <= ny < H:
if field[ny][nx] == 3:
ans = t
elif field[ny][nx] == 1:
if abs(nx - x) + abs(ny - y) == 1:
break
field[ny][nx] = 0
rec(nx - dx, ny - dy, t + 1)
field[ny][nx] = 1
break
nx += dx
ny += dy
while 1:
W, H = list(map(int, input().split()))
if W == 0:
break
field = [list(map(int, input().split())) for _ in range(H)]
for y in range(H):
for x in range(W):
if field[y][x] == 2:
sx, sy = x, y
ans = 11
rec(sx, sy, 1)
print(ans if ans <= 10 else -1)
| false | 0 | [
"+dxy = list(zip([1, 0, -1, 0], [0, 1, 0, -1]))",
"+",
"+",
"- for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):",
"+ for dx, dy in dxy:",
"- rec(nx, ny, t + 1)",
"- if field[ny][nx] == 1:",
"+ ans = t",
"+ elif field[ny][nx] == 1:",
"- rec(sx, sy, 0)",
"+ rec(sx, sy, 1)"
] | false | 0.036779 | 0.112782 | 0.32611 | [
"s423294611",
"s956608035"
] |
u017810624 | p03055 | python | s487617134 | s492421515 | 1,344 | 728 | 123,428 | 121,092 | Accepted | Accepted | 45.83 | n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
connection[l[i][0]-1].append(l[i][1]-1)
connection[l[i][1]-1].append(l[i][0]-1)
distance1=[-1 for i in range(n)]
distance1[0]=0
next=connection[0]
next2=[]
check=[-1 for i in range(n)]
check[0]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
ct+=1
for i in range(len(next)):
distance1[next[i]]=ct
check[next[i]]=1
checkct+=1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]]==-1:
next2.append(connection[next[i]][j])
next=next2
next2=[]
x=max(distance1)
x=distance1.index(x)
distance2=[-1 for i in range(n)]
distance2[x]=0
next=connection[x]
next2=[]
check=[-1 for i in range(n)]
check[x]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
ct+=1
for i in range(len(next)):
distance2[next[i]]=ct
check[next[i]]=1
checkct+=1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]]==-1:
next2.append(connection[next[i]][j])
next=next2
next2=[]
if max(distance2)%3==1:
print('Second')
else:
print('First') | import sys
input=sys.stdin.readline
n=int(eval(input()))
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
connection[l[i][0]-1].append(l[i][1]-1)
connection[l[i][1]-1].append(l[i][0]-1)
distance1=[-1 for i in range(n)]
distance1[0]=0
next=connection[0]
next2=[]
check=[-1 for i in range(n)]
check[0]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
ct+=1
for i in range(len(next)):
distance1[next[i]]=ct
check[next[i]]=1
checkct+=1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]]==-1:
next2.append(connection[next[i]][j])
next=next2
next2=[]
x=max(distance1)
x=distance1.index(x)
distance2=[-1 for i in range(n)]
distance2[x]=0
next=connection[x]
next2=[]
check=[-1 for i in range(n)]
check[x]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
ct+=1
for i in range(len(next)):
distance2[next[i]]=ct
check[next[i]]=1
checkct+=1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]]==-1:
next2.append(connection[next[i]][j])
next=next2
next2=[]
if max(distance2)%3==1:
print('Second')
else:
print('First') | 54 | 56 | 1,217 | 1,255 | n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
connection = [[] for i in range(n)]
for i in range(n - 1):
connection[l[i][0] - 1].append(l[i][1] - 1)
connection[l[i][1] - 1].append(l[i][0] - 1)
distance1 = [-1 for i in range(n)]
distance1[0] = 0
next = connection[0]
next2 = []
check = [-1 for i in range(n)]
check[0] = 1
checkct = 1
ct = 0
while len(next) != 0 and checkct != n:
ct += 1
for i in range(len(next)):
distance1[next[i]] = ct
check[next[i]] = 1
checkct += 1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]] == -1:
next2.append(connection[next[i]][j])
next = next2
next2 = []
x = max(distance1)
x = distance1.index(x)
distance2 = [-1 for i in range(n)]
distance2[x] = 0
next = connection[x]
next2 = []
check = [-1 for i in range(n)]
check[x] = 1
checkct = 1
ct = 0
while len(next) != 0 and checkct != n:
ct += 1
for i in range(len(next)):
distance2[next[i]] = ct
check[next[i]] = 1
checkct += 1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]] == -1:
next2.append(connection[next[i]][j])
next = next2
next2 = []
if max(distance2) % 3 == 1:
print("Second")
else:
print("First")
| import sys
input = sys.stdin.readline
n = int(eval(input()))
l = [list(map(int, input().split())) for i in range(n - 1)]
connection = [[] for i in range(n)]
for i in range(n - 1):
connection[l[i][0] - 1].append(l[i][1] - 1)
connection[l[i][1] - 1].append(l[i][0] - 1)
distance1 = [-1 for i in range(n)]
distance1[0] = 0
next = connection[0]
next2 = []
check = [-1 for i in range(n)]
check[0] = 1
checkct = 1
ct = 0
while len(next) != 0 and checkct != n:
ct += 1
for i in range(len(next)):
distance1[next[i]] = ct
check[next[i]] = 1
checkct += 1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]] == -1:
next2.append(connection[next[i]][j])
next = next2
next2 = []
x = max(distance1)
x = distance1.index(x)
distance2 = [-1 for i in range(n)]
distance2[x] = 0
next = connection[x]
next2 = []
check = [-1 for i in range(n)]
check[x] = 1
checkct = 1
ct = 0
while len(next) != 0 and checkct != n:
ct += 1
for i in range(len(next)):
distance2[next[i]] = ct
check[next[i]] = 1
checkct += 1
for j in range(len(connection[next[i]])):
if check[connection[next[i]][j]] == -1:
next2.append(connection[next[i]][j])
next = next2
next2 = []
if max(distance2) % 3 == 1:
print("Second")
else:
print("First")
| false | 3.571429 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.039144 | 0.034442 | 1.136515 | [
"s487617134",
"s492421515"
] |
u029918772 | p02595 | python | s235316019 | s584830614 | 617 | 483 | 40,632 | 9,116 | Accepted | Accepted | 21.72 | n, d = list(map(int, input().split()))
xy = []
for i in range(n):
a, b = list(map(int, input().split()))
xy.append([a, b])
count = [xi**2 + yi**2 <= d**2 for xi, yi in xy]
print((sum(count))) | n, d = list(map(int, input().split()))
xy = 0
for i in range(n):
xi, yi = list(map(int, input().split()))
xy += xi**2 + yi**2 <= d**2
print(xy) | 9 | 7 | 193 | 143 | n, d = list(map(int, input().split()))
xy = []
for i in range(n):
a, b = list(map(int, input().split()))
xy.append([a, b])
count = [xi**2 + yi**2 <= d**2 for xi, yi in xy]
print((sum(count)))
| n, d = list(map(int, input().split()))
xy = 0
for i in range(n):
xi, yi = list(map(int, input().split()))
xy += xi**2 + yi**2 <= d**2
print(xy)
| false | 22.222222 | [
"-xy = []",
"+xy = 0",
"- a, b = list(map(int, input().split()))",
"- xy.append([a, b])",
"-count = [xi**2 + yi**2 <= d**2 for xi, yi in xy]",
"-print((sum(count)))",
"+ xi, yi = list(map(int, input().split()))",
"+ xy += xi**2 + yi**2 <= d**2",
"+print(xy)"
] | false | 0.03477 | 0.042169 | 0.82452 | [
"s235316019",
"s584830614"
] |
u671060652 | p03042 | python | s619723984 | s851542570 | 293 | 65 | 65,772 | 61,500 | Accepted | Accepted | 77.82 | import itertools
import math
import fractions
import functools
import copy
s = eval(input())
front = int(s[0]+s[1])
back = int(s[2]+s[3])
if (1 <= front and front <= 12) and (1 <= back and back <= 12):
print("AMBIGUOUS")
quit()
if (1 <= front and front <= 12):
print("MMYY")
quit()
if (1 <= back and back <= 12):
print("YYMM")
quit()
print("NA") | import math
def main():
# n = int(input())
# n, k = map(int, input().split())
# h = list(map(int, input().split()))
s = eval(input())
# h = [int(input()) for _ in rane(n)]
f = int(s[:2])
b = int(s[2:])
if 1 <= f and f <= 12 and 1 <= b and b <= 12:
print("AMBIGUOUS")
elif 0 <= f and f <= 99 and 1 <= b and b <= 12:
print("YYMM")
elif 0 <= b and b <= 99 and 1 <= f and f <= 12:
print("MMYY")
else:
print("NA")
if __name__ == '__main__':
main()
| 21 | 23 | 386 | 543 | import itertools
import math
import fractions
import functools
import copy
s = eval(input())
front = int(s[0] + s[1])
back = int(s[2] + s[3])
if (1 <= front and front <= 12) and (1 <= back and back <= 12):
print("AMBIGUOUS")
quit()
if 1 <= front and front <= 12:
print("MMYY")
quit()
if 1 <= back and back <= 12:
print("YYMM")
quit()
print("NA")
| import math
def main():
# n = int(input())
# n, k = map(int, input().split())
# h = list(map(int, input().split()))
s = eval(input())
# h = [int(input()) for _ in rane(n)]
f = int(s[:2])
b = int(s[2:])
if 1 <= f and f <= 12 and 1 <= b and b <= 12:
print("AMBIGUOUS")
elif 0 <= f and f <= 99 and 1 <= b and b <= 12:
print("YYMM")
elif 0 <= b and b <= 99 and 1 <= f and f <= 12:
print("MMYY")
else:
print("NA")
if __name__ == "__main__":
main()
| false | 8.695652 | [
"-import itertools",
"-import fractions",
"-import functools",
"-import copy",
"-s = eval(input())",
"-front = int(s[0] + s[1])",
"-back = int(s[2] + s[3])",
"-if (1 <= front and front <= 12) and (1 <= back and back <= 12):",
"- print(\"AMBIGUOUS\")",
"- quit()",
"-if 1 <= front and front <= 12:",
"- print(\"MMYY\")",
"- quit()",
"-if 1 <= back and back <= 12:",
"- print(\"YYMM\")",
"- quit()",
"-print(\"NA\")",
"+",
"+def main():",
"+ # n = int(input())",
"+ # n, k = map(int, input().split())",
"+ # h = list(map(int, input().split()))",
"+ s = eval(input())",
"+ # h = [int(input()) for _ in rane(n)]",
"+ f = int(s[:2])",
"+ b = int(s[2:])",
"+ if 1 <= f and f <= 12 and 1 <= b and b <= 12:",
"+ print(\"AMBIGUOUS\")",
"+ elif 0 <= f and f <= 99 and 1 <= b and b <= 12:",
"+ print(\"YYMM\")",
"+ elif 0 <= b and b <= 99 and 1 <= f and f <= 12:",
"+ print(\"MMYY\")",
"+ else:",
"+ print(\"NA\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.04101 | 0.040037 | 1.024282 | [
"s619723984",
"s851542570"
] |
u924406834 | p02916 | python | s273406899 | s986198434 | 174 | 17 | 38,384 | 3,064 | Accepted | Accepted | 90.23 | n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
check = 0
for i in range(n):
tabe = a[i]
check += b[tabe - 1]
if i < n -1 :
if (a[i+1] - a[i]) == 1:
check += c[a[i]-1]
print(check) | n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
ans += b[i]
if i == 0:continue
if a[i] - a[i-1] == 1:
ans += c[a[i-1]-1]
print(ans) | 12 | 12 | 297 | 264 | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
check = 0
for i in range(n):
tabe = a[i]
check += b[tabe - 1]
if i < n - 1:
if (a[i + 1] - a[i]) == 1:
check += c[a[i] - 1]
print(check)
| n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
ans += b[i]
if i == 0:
continue
if a[i] - a[i - 1] == 1:
ans += c[a[i - 1] - 1]
print(ans)
| false | 0 | [
"-check = 0",
"+ans = 0",
"- tabe = a[i]",
"- check += b[tabe - 1]",
"- if i < n - 1:",
"- if (a[i + 1] - a[i]) == 1:",
"- check += c[a[i] - 1]",
"-print(check)",
"+ ans += b[i]",
"+ if i == 0:",
"+ continue",
"+ if a[i] - a[i - 1] == 1:",
"+ ans += c[a[i - 1] - 1]",
"+print(ans)"
] | false | 0.043321 | 0.070484 | 0.61462 | [
"s273406899",
"s986198434"
] |
u306142032 | p02786 | python | s163442033 | s359967517 | 17 | 10 | 2,940 | 2,568 | Accepted | Accepted | 41.18 | print((~-2**int(eval(input())).bit_length())) | print(~-2**input().bit_length()) | 1 | 1 | 37 | 30 | print((~-(2 ** int(eval(input())).bit_length())))
| print(~-(2 ** input().bit_length()))
| false | 0 | [
"-print((~-(2 ** int(eval(input())).bit_length())))",
"+print(~-(2 ** input().bit_length()))"
] | false | 0.043239 | 0.08197 | 0.527494 | [
"s163442033",
"s359967517"
] |
u731896389 | p02407 | python | s328959065 | s642686834 | 30 | 20 | 7,632 | 7,656 | Accepted | Accepted | 33.33 | n = int(input())
a = list(map(int,input().split()))
a.reverse()
for i in range(n-1):
print(a[i],end = " ")
print(a[n-1])
| n =int(input())
a = list(map(int,input().split()))
a.reverse()
for i in range(n):
if i!=n-1:
print(a[i],end=" ")
else:
print(a[i])
| 6 | 8 | 129 | 161 | n = int(input())
a = list(map(int, input().split()))
a.reverse()
for i in range(n - 1):
print(a[i], end=" ")
print(a[n - 1])
| n = int(input())
a = list(map(int, input().split()))
a.reverse()
for i in range(n):
if i != n - 1:
print(a[i], end=" ")
else:
print(a[i])
| false | 25 | [
"-for i in range(n - 1):",
"- print(a[i], end=\" \")",
"-print(a[n - 1])",
"+for i in range(n):",
"+ if i != n - 1:",
"+ print(a[i], end=\" \")",
"+ else:",
"+ print(a[i])"
] | false | 0.035578 | 0.054663 | 0.650858 | [
"s328959065",
"s642686834"
] |
u562935282 | p02954 | python | s827190479 | s394719779 | 136 | 108 | 8,288 | 6,400 | Accepted | Accepted | 20.59 | def main():
from bisect import bisect_left
s = eval(input())
n = len(s)
RL = []
for i in range(n - 1):
pair = s[i:i + 2]
if pair == 'RL':
RL.append(i)
cnt = [0] * n
for i, c in enumerate(s):
if c == 'R':
j = bisect_left(RL, i)
j = RL[j]
if (j - i) % 2 == 0:
cnt[j] += 1
else:
cnt[j + 1] += 1
else:
j = bisect_left(RL, i)
j -= 1
j = RL[j]
if (j - i) % 2 == 0:
cnt[j] += 1
else:
cnt[j + 1] += 1
print((*cnt))
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| def main():
from itertools import chain, tee
s = eval(input())
n = len(s)
a = (-1 if c == 'L' else 1 for c in s)
p = -1
RL = 1
ctr = [0] * n
it = chain(a, (1,))
g1, g2 = tee(it, 2)
next(g2)
for i, (x1, x2) in enumerate(zip(g1, g2)):
if x1 + x2 == 0:
if RL:
cnt = i - p
ctr[i] += (cnt + 1) // 2
ctr[i + 1] += cnt // 2
p = i
else:
cnt = i - p
ctr[p + 1] += (cnt + 1) // 2
ctr[p] += cnt // 2
p = i
RL ^= 1
print((*ctr))
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| 43 | 40 | 866 | 844 | def main():
from bisect import bisect_left
s = eval(input())
n = len(s)
RL = []
for i in range(n - 1):
pair = s[i : i + 2]
if pair == "RL":
RL.append(i)
cnt = [0] * n
for i, c in enumerate(s):
if c == "R":
j = bisect_left(RL, i)
j = RL[j]
if (j - i) % 2 == 0:
cnt[j] += 1
else:
cnt[j + 1] += 1
else:
j = bisect_left(RL, i)
j -= 1
j = RL[j]
if (j - i) % 2 == 0:
cnt[j] += 1
else:
cnt[j + 1] += 1
print((*cnt))
if __name__ == "__main__":
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| def main():
from itertools import chain, tee
s = eval(input())
n = len(s)
a = (-1 if c == "L" else 1 for c in s)
p = -1
RL = 1
ctr = [0] * n
it = chain(a, (1,))
g1, g2 = tee(it, 2)
next(g2)
for i, (x1, x2) in enumerate(zip(g1, g2)):
if x1 + x2 == 0:
if RL:
cnt = i - p
ctr[i] += (cnt + 1) // 2
ctr[i + 1] += cnt // 2
p = i
else:
cnt = i - p
ctr[p + 1] += (cnt + 1) // 2
ctr[p] += cnt // 2
p = i
RL ^= 1
print((*ctr))
if __name__ == "__main__":
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| false | 6.976744 | [
"- from bisect import bisect_left",
"+ from itertools import chain, tee",
"- RL = []",
"- for i in range(n - 1):",
"- pair = s[i : i + 2]",
"- if pair == \"RL\":",
"- RL.append(i)",
"- cnt = [0] * n",
"- for i, c in enumerate(s):",
"- if c == \"R\":",
"- j = bisect_left(RL, i)",
"- j = RL[j]",
"- if (j - i) % 2 == 0:",
"- cnt[j] += 1",
"+ a = (-1 if c == \"L\" else 1 for c in s)",
"+ p = -1",
"+ RL = 1",
"+ ctr = [0] * n",
"+ it = chain(a, (1,))",
"+ g1, g2 = tee(it, 2)",
"+ next(g2)",
"+ for i, (x1, x2) in enumerate(zip(g1, g2)):",
"+ if x1 + x2 == 0:",
"+ if RL:",
"+ cnt = i - p",
"+ ctr[i] += (cnt + 1) // 2",
"+ ctr[i + 1] += cnt // 2",
"+ p = i",
"- cnt[j + 1] += 1",
"- else:",
"- j = bisect_left(RL, i)",
"- j -= 1",
"- j = RL[j]",
"- if (j - i) % 2 == 0:",
"- cnt[j] += 1",
"- else:",
"- cnt[j + 1] += 1",
"- print((*cnt))",
"+ cnt = i - p",
"+ ctr[p + 1] += (cnt + 1) // 2",
"+ ctr[p] += cnt // 2",
"+ p = i",
"+ RL ^= 1",
"+ print((*ctr))"
] | false | 0.043854 | 0.0839 | 0.522698 | [
"s827190479",
"s394719779"
] |
u550943777 | p03579 | python | s631313988 | s293652718 | 608 | 559 | 22,064 | 31,188 | Accepted | Accepted | 8.06 | N,M = list(map(int,input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a,b = [int(x)-1 for x in input().split()]
e_list[a].append(b)
e_list[b].append(a)
bin_or_not = True
ans = (N-1)*N//2 - M
w_or_b = [-1]*N
stack = [0]
w_or_b[0] = 0
while stack:
x = stack.pop()
for i in e_list[x]:
if w_or_b[i] >= 0:
bin_or_not = w_or_b[x]^w_or_b[i]
else:
w_or_b[i] = (w_or_b[x] + 1)%2
stack.append(i)
if not bin_or_not:
break
if not bin_or_not:
break
if bin_or_not:
w = w_or_b.count(0)
b = w_or_b.count(1)
ans = w*b - M
print(ans) | import sys
sys.setrecursionlimit(10**7)
class BinPartite:
def __init__(self, N, es):
self.colors = [0 for i in range(N)]
self.es = es
def dfs(self, v, color):
self.colors[v] = color
for to in self.es[v]:
if self.colors[to] == color:
return False
if self.colors[to] == 0 and not self.dfs(to, -color):
return False
return True
def color_cnt(self, color):
return self.colors.count(color)
def is_bipartite(self):
return self.dfs(0, 1)
N, M = list(map(int, input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a, b = [int(x)-1 for x in input().split()]
e_list[a].append(b)
e_list[b].append(a)
Bp = BinPartite(N, e_list)
if Bp.is_bipartite():
b = Bp.color_cnt(1)
w = Bp.color_cnt(-1)
print((b*w-M))
else:
print((N*(N-1)//2 - M))
| 28 | 37 | 675 | 932 | N, M = list(map(int, input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a, b = [int(x) - 1 for x in input().split()]
e_list[a].append(b)
e_list[b].append(a)
bin_or_not = True
ans = (N - 1) * N // 2 - M
w_or_b = [-1] * N
stack = [0]
w_or_b[0] = 0
while stack:
x = stack.pop()
for i in e_list[x]:
if w_or_b[i] >= 0:
bin_or_not = w_or_b[x] ^ w_or_b[i]
else:
w_or_b[i] = (w_or_b[x] + 1) % 2
stack.append(i)
if not bin_or_not:
break
if not bin_or_not:
break
if bin_or_not:
w = w_or_b.count(0)
b = w_or_b.count(1)
ans = w * b - M
print(ans)
| import sys
sys.setrecursionlimit(10**7)
class BinPartite:
def __init__(self, N, es):
self.colors = [0 for i in range(N)]
self.es = es
def dfs(self, v, color):
self.colors[v] = color
for to in self.es[v]:
if self.colors[to] == color:
return False
if self.colors[to] == 0 and not self.dfs(to, -color):
return False
return True
def color_cnt(self, color):
return self.colors.count(color)
def is_bipartite(self):
return self.dfs(0, 1)
N, M = list(map(int, input().split()))
e_list = [[] for i in range(N)]
for i in range(M):
a, b = [int(x) - 1 for x in input().split()]
e_list[a].append(b)
e_list[b].append(a)
Bp = BinPartite(N, e_list)
if Bp.is_bipartite():
b = Bp.color_cnt(1)
w = Bp.color_cnt(-1)
print((b * w - M))
else:
print((N * (N - 1) // 2 - M))
| false | 24.324324 | [
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+",
"+",
"+class BinPartite:",
"+ def __init__(self, N, es):",
"+ self.colors = [0 for i in range(N)]",
"+ self.es = es",
"+",
"+ def dfs(self, v, color):",
"+ self.colors[v] = color",
"+ for to in self.es[v]:",
"+ if self.colors[to] == color:",
"+ return False",
"+ if self.colors[to] == 0 and not self.dfs(to, -color):",
"+ return False",
"+ return True",
"+",
"+ def color_cnt(self, color):",
"+ return self.colors.count(color)",
"+",
"+ def is_bipartite(self):",
"+ return self.dfs(0, 1)",
"+",
"+",
"-bin_or_not = True",
"-ans = (N - 1) * N // 2 - M",
"-w_or_b = [-1] * N",
"-stack = [0]",
"-w_or_b[0] = 0",
"-while stack:",
"- x = stack.pop()",
"- for i in e_list[x]:",
"- if w_or_b[i] >= 0:",
"- bin_or_not = w_or_b[x] ^ w_or_b[i]",
"- else:",
"- w_or_b[i] = (w_or_b[x] + 1) % 2",
"- stack.append(i)",
"- if not bin_or_not:",
"- break",
"- if not bin_or_not:",
"- break",
"-if bin_or_not:",
"- w = w_or_b.count(0)",
"- b = w_or_b.count(1)",
"- ans = w * b - M",
"-print(ans)",
"+Bp = BinPartite(N, e_list)",
"+if Bp.is_bipartite():",
"+ b = Bp.color_cnt(1)",
"+ w = Bp.color_cnt(-1)",
"+ print((b * w - M))",
"+else:",
"+ print((N * (N - 1) // 2 - M))"
] | false | 0.07773 | 0.034773 | 2.23537 | [
"s631313988",
"s293652718"
] |
u102461423 | p03823 | python | s746666454 | s317872315 | 381 | 144 | 23,620 | 35,972 | Accepted | Accepted | 62.2 | import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
INF = 10**18 + 100
N,A,B = list(map(int,input().split()))
S = [-INF] + [int(x) for x in sys.stdin.read().split()]
MOD = 10**9 + 7
dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [1] * (N+1) + [0] # -1
dpY_cum = [1] * (N+1) + [0] # -1
dpX_left = 0
dpY_left = 0
for n,x in enumerate(S[2:],2):
iA = bisect_right(S,x-A)
iB = bisect_right(S,x-B)
# ....XY
xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1] if iB >= dpY_left else 0
# ....YX
yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1] if iA >= dpX_left else 0
# ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
if iA != n:
dpY_left = n-1
if iB != n:
dpX_left = n-1
dpX[n-1] = xy
dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD
dpX_cum[n] = dpX_cum[n-1]
dpY[n-1] = yx
dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD
dpY_cum[n] = dpY_cum[n-1]
answer = dpX_cum[N-1] - dpX_cum[dpX_left-1]
answer += dpY_cum[N-1] - dpY_cum[dpY_left-1]
answer %= MOD
print(answer) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7
def main(N, A, B, S):
if N == 1:
return 2
INF = 1 << 62
S = np.append(S, INF)
if A > B:
A, B = B, A
if np.min(S[2:] - S[:-2]) < A:
return 0
# A 未満でたどって、Xがどこまで置けるか
X = np.zeros_like(S)
for i in range(1, N + 1):
if S[i] - S[i - 1] >= A:
X[i] = X[i - 1]
else:
X[i] = i
# 直前の Y としてありうる最も右
Y = np.searchsorted(S, S - B, side='right') - 1
dp = np.zeros_like(S)
dp_cum = np.zeros_like(S)
dp[0] = 1
dp_cum[0] = 1
for n in range(1, N + 1):
if X[n - 1] == 0:
# 初出の Y
dp[n] = 1
# 直前の Y の範囲
l, r = max(0, X[n - 1] - 1), min(n - 1, Y[n])
if l <= r:
dp[n] += dp_cum[r] - dp_cum[l] + dp[l]
dp[n] %= MOD
dp_cum[n] = (dp_cum[n - 1] + dp[n]) % MOD
return dp[-1]
signature = '(i8,i8,i8,i8[:],)'
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', signature)(main)
cc.compile()
from my_module import main
N, A, B = list(map(int, readline().split()))
S = np.array(read().split(), np.int64)
print((main(N, A, B, S))) | 42 | 57 | 1,144 | 1,377 | import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
INF = 10**18 + 100
N, A, B = list(map(int, input().split()))
S = [-INF] + [int(x) for x in sys.stdin.read().split()]
MOD = 10**9 + 7
dpX = [0] * (N + 1) # 最後にYを選んだとして、直前に選んだXがどこにあるか
dpY = [0] * (N + 1) # 最後にXを選んだとして、直前に選んだYがどこにあるか
dpX[0] = 1
dpY[0] = 1
dpX_cum = [1] * (N + 1) + [0] # -1
dpY_cum = [1] * (N + 1) + [0] # -1
dpX_left = 0
dpY_left = 0
for n, x in enumerate(S[2:], 2):
iA = bisect_right(S, x - A)
iB = bisect_right(S, x - B)
# ....XY
xy = dpY_cum[iB - 1] - dpY_cum[dpY_left - 1] if iB >= dpY_left else 0
# ....YX
yx = dpX_cum[iA - 1] - dpX_cum[dpX_left - 1] if iA >= dpX_left else 0
# ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ
if iA != n:
dpY_left = n - 1
if iB != n:
dpX_left = n - 1
dpX[n - 1] = xy
dpX_cum[n - 1] = (dpX_cum[n - 2] + xy) % MOD
dpX_cum[n] = dpX_cum[n - 1]
dpY[n - 1] = yx
dpY_cum[n - 1] = (dpY_cum[n - 2] + yx) % MOD
dpY_cum[n] = dpY_cum[n - 1]
answer = dpX_cum[N - 1] - dpX_cum[dpX_left - 1]
answer += dpY_cum[N - 1] - dpY_cum[dpY_left - 1]
answer %= MOD
print(answer)
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7
def main(N, A, B, S):
if N == 1:
return 2
INF = 1 << 62
S = np.append(S, INF)
if A > B:
A, B = B, A
if np.min(S[2:] - S[:-2]) < A:
return 0
# A 未満でたどって、Xがどこまで置けるか
X = np.zeros_like(S)
for i in range(1, N + 1):
if S[i] - S[i - 1] >= A:
X[i] = X[i - 1]
else:
X[i] = i
# 直前の Y としてありうる最も右
Y = np.searchsorted(S, S - B, side="right") - 1
dp = np.zeros_like(S)
dp_cum = np.zeros_like(S)
dp[0] = 1
dp_cum[0] = 1
for n in range(1, N + 1):
if X[n - 1] == 0:
# 初出の Y
dp[n] = 1
# 直前の Y の範囲
l, r = max(0, X[n - 1] - 1), min(n - 1, Y[n])
if l <= r:
dp[n] += dp_cum[r] - dp_cum[l] + dp[l]
dp[n] %= MOD
dp_cum[n] = (dp_cum[n - 1] + dp[n]) % MOD
return dp[-1]
signature = "(i8,i8,i8,i8[:],)"
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", signature)(main)
cc.compile()
from my_module import main
N, A, B = list(map(int, readline().split()))
S = np.array(read().split(), np.int64)
print((main(N, A, B, S)))
| false | 26.315789 | [
"+import numpy as np",
"-input = sys.stdin.readline",
"-from bisect import bisect_left, bisect_right",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+MOD = 10**9 + 7",
"-INF = 10**18 + 100",
"-N, A, B = list(map(int, input().split()))",
"-S = [-INF] + [int(x) for x in sys.stdin.read().split()]",
"-MOD = 10**9 + 7",
"-dpX = [0] * (N + 1) # 最後にYを選んだとして、直前に選んだXがどこにあるか",
"-dpY = [0] * (N + 1) # 最後にXを選んだとして、直前に選んだYがどこにあるか",
"-dpX[0] = 1",
"-dpY[0] = 1",
"-dpX_cum = [1] * (N + 1) + [0] # -1",
"-dpY_cum = [1] * (N + 1) + [0] # -1",
"-dpX_left = 0",
"-dpY_left = 0",
"-for n, x in enumerate(S[2:], 2):",
"- iA = bisect_right(S, x - A)",
"- iB = bisect_right(S, x - B)",
"- # ....XY",
"- xy = dpY_cum[iB - 1] - dpY_cum[dpY_left - 1] if iB >= dpY_left else 0",
"- # ....YX",
"- yx = dpX_cum[iA - 1] - dpX_cum[dpX_left - 1] if iA >= dpX_left else 0",
"- # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ",
"- if iA != n:",
"- dpY_left = n - 1",
"- if iB != n:",
"- dpX_left = n - 1",
"- dpX[n - 1] = xy",
"- dpX_cum[n - 1] = (dpX_cum[n - 2] + xy) % MOD",
"- dpX_cum[n] = dpX_cum[n - 1]",
"- dpY[n - 1] = yx",
"- dpY_cum[n - 1] = (dpY_cum[n - 2] + yx) % MOD",
"- dpY_cum[n] = dpY_cum[n - 1]",
"-answer = dpX_cum[N - 1] - dpX_cum[dpX_left - 1]",
"-answer += dpY_cum[N - 1] - dpY_cum[dpY_left - 1]",
"-answer %= MOD",
"-print(answer)",
"+",
"+def main(N, A, B, S):",
"+ if N == 1:",
"+ return 2",
"+ INF = 1 << 62",
"+ S = np.append(S, INF)",
"+ if A > B:",
"+ A, B = B, A",
"+ if np.min(S[2:] - S[:-2]) < A:",
"+ return 0",
"+ # A 未満でたどって、Xがどこまで置けるか",
"+ X = np.zeros_like(S)",
"+ for i in range(1, N + 1):",
"+ if S[i] - S[i - 1] >= A:",
"+ X[i] = X[i - 1]",
"+ else:",
"+ X[i] = i",
"+ # 直前の Y としてありうる最も右",
"+ Y = np.searchsorted(S, S - B, side=\"right\") - 1",
"+ dp = np.zeros_like(S)",
"+ dp_cum = np.zeros_like(S)",
"+ dp[0] = 1",
"+ dp_cum[0] = 1",
"+ for n in range(1, N + 1):",
"+ if X[n - 1] == 0:",
"+ # 初出の Y",
"+ dp[n] = 1",
"+ # 直前の Y の範囲",
"+ l, r = max(0, X[n - 1] - 1), min(n - 1, Y[n])",
"+ if l <= r:",
"+ dp[n] += dp_cum[r] - dp_cum[l] + dp[l]",
"+ dp[n] %= MOD",
"+ dp_cum[n] = (dp_cum[n - 1] + dp[n]) % MOD",
"+ return dp[-1]",
"+",
"+",
"+signature = \"(i8,i8,i8,i8[:],)\"",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ from numba.pycc import CC",
"+",
"+ cc = CC(\"my_module\")",
"+ cc.export(\"main\", signature)(main)",
"+ cc.compile()",
"+from my_module import main",
"+",
"+N, A, B = list(map(int, readline().split()))",
"+S = np.array(read().split(), np.int64)",
"+print((main(N, A, B, S)))"
] | false | 0.035216 | 0.181329 | 0.194211 | [
"s746666454",
"s317872315"
] |
u298297089 | p03285 | python | s623031513 | s482405722 | 180 | 17 | 38,384 | 3,060 | Accepted | Accepted | 90.56 |
n = int(eval(input()))
for i in range(n//4+1):
for j in range(n//7+1):
if 4 * i + 7 * j == n:
print('Yes')
exit()
print('No')
| n = int(eval(input()))
for i in range((n+3)//4+1):
if (n - i * 4 ) % 7 == 0:
print('Yes')
break
else:
print('No') | 8 | 7 | 164 | 137 | n = int(eval(input()))
for i in range(n // 4 + 1):
for j in range(n // 7 + 1):
if 4 * i + 7 * j == n:
print("Yes")
exit()
print("No")
| n = int(eval(input()))
for i in range((n + 3) // 4 + 1):
if (n - i * 4) % 7 == 0:
print("Yes")
break
else:
print("No")
| false | 12.5 | [
"-for i in range(n // 4 + 1):",
"- for j in range(n // 7 + 1):",
"- if 4 * i + 7 * j == n:",
"- print(\"Yes\")",
"- exit()",
"-print(\"No\")",
"+for i in range((n + 3) // 4 + 1):",
"+ if (n - i * 4) % 7 == 0:",
"+ print(\"Yes\")",
"+ break",
"+else:",
"+ print(\"No\")"
] | false | 0.046902 | 0.046036 | 1.018793 | [
"s623031513",
"s482405722"
] |
u729133443 | p02641 | python | s925181150 | s114572687 | 62 | 23 | 62,396 | 9,152 | Accepted | Accepted | 62.9 | x,n,*p=list(map(int,open(0).read().split()))
print((min({*list(range(999))}-{*p},key=lambda y:abs(y-x)))) | x,n,*p=list(map(int,open(i:=0).read().split()))
while x in p:x+=(-1)**i*i;i+=1
print(x) | 2 | 3 | 92 | 83 | x, n, *p = list(map(int, open(0).read().split()))
print((min({*list(range(999))} - {*p}, key=lambda y: abs(y - x))))
| x, n, *p = list(map(int, open(i := 0).read().split()))
while x in p:
x += (-1) ** i * i
i += 1
print(x)
| false | 33.333333 | [
"-x, n, *p = list(map(int, open(0).read().split()))",
"-print((min({*list(range(999))} - {*p}, key=lambda y: abs(y - x))))",
"+x, n, *p = list(map(int, open(i := 0).read().split()))",
"+while x in p:",
"+ x += (-1) ** i * i",
"+ i += 1",
"+print(x)"
] | false | 0.036261 | 0.036825 | 0.98468 | [
"s925181150",
"s114572687"
] |
u550061714 | p03172 | python | s919481540 | s395373683 | 741 | 467 | 174,728 | 92,968 | Accepted | Accepted | 36.98 | import itertools
N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7
dp = [[0] * (K + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
S = [0] + list(itertools.accumulate(dp[i - 1]))
for j in range(K + 1):
dp[i][j] = (S[j + 1] - S[max(0, j - A[i - 1])]) % MOD
print((dp[N][K]))
| import numpy as np
N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7
dp = np.zeros((N + 1, K + 1), dtype=np.int64)
dp[0][0] = 1
for i in range(1, N + 1):
S = np.cumsum(dp[i - 1]) % MOD
dp[i][:A[i - 1] + 1] = S[:A[i - 1] + 1] % MOD
dp[i][A[i - 1] + 1:K + 1] = (S[A[i - 1] + 1:K + 1] - S[:K - A[i - 1]]) % MOD
print((dp[N][K]))
| 14 | 14 | 360 | 390 | import itertools
N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (K + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
S = [0] + list(itertools.accumulate(dp[i - 1]))
for j in range(K + 1):
dp[i][j] = (S[j + 1] - S[max(0, j - A[i - 1])]) % MOD
print((dp[N][K]))
| import numpy as np
N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10**9 + 7
dp = np.zeros((N + 1, K + 1), dtype=np.int64)
dp[0][0] = 1
for i in range(1, N + 1):
S = np.cumsum(dp[i - 1]) % MOD
dp[i][: A[i - 1] + 1] = S[: A[i - 1] + 1] % MOD
dp[i][A[i - 1] + 1 : K + 1] = (S[A[i - 1] + 1 : K + 1] - S[: K - A[i - 1]]) % MOD
print((dp[N][K]))
| false | 0 | [
"-import itertools",
"+import numpy as np",
"-dp = [[0] * (K + 1) for _ in range(N + 1)]",
"+dp = np.zeros((N + 1, K + 1), dtype=np.int64)",
"- S = [0] + list(itertools.accumulate(dp[i - 1]))",
"- for j in range(K + 1):",
"- dp[i][j] = (S[j + 1] - S[max(0, j - A[i - 1])]) % MOD",
"+ S = np.cumsum(dp[i - 1]) % MOD",
"+ dp[i][: A[i - 1] + 1] = S[: A[i - 1] + 1] % MOD",
"+ dp[i][A[i - 1] + 1 : K + 1] = (S[A[i - 1] + 1 : K + 1] - S[: K - A[i - 1]]) % MOD"
] | false | 0.290111 | 0.268569 | 1.080211 | [
"s919481540",
"s395373683"
] |
u561231954 | p02792 | python | s498640437 | s366516209 | 197 | 145 | 3,064 | 3,064 | Accepted | Accepted | 26.4 | n = int(eval(input()))
c=[[0]*10 for i in range(10)]
for k in range(1,n+1):
k=str(k)
i=int(k[0])
j=int(k[-1])
c[i][j]+=1
ans=0
for i in range(10):
for j in range(10):
ans+=c[i][j]*c[j][i]
print(ans) | MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)
def main():
N = int(eval(input()))
presuf = [[0] * 10 for _ in range(10)]
for i in range(1,N + 1):
pre = int(str(i)[0])
suf = i%10
presuf[pre][suf] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += presuf[i][j]*presuf[j][i]
print(ans)
if __name__ == '__main__':
main()
| 14 | 20 | 223 | 447 | n = int(eval(input()))
c = [[0] * 10 for i in range(10)]
for k in range(1, n + 1):
k = str(k)
i = int(k[0])
j = int(k[-1])
c[i][j] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += c[i][j] * c[j][i]
print(ans)
| MOD = 10**9 + 7
INF = 10**11
import sys
sys.setrecursionlimit(100000000)
def main():
N = int(eval(input()))
presuf = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
pre = int(str(i)[0])
suf = i % 10
presuf[pre][suf] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += presuf[i][j] * presuf[j][i]
print(ans)
if __name__ == "__main__":
main()
| false | 30 | [
"-n = int(eval(input()))",
"-c = [[0] * 10 for i in range(10)]",
"-for k in range(1, n + 1):",
"- k = str(k)",
"- i = int(k[0])",
"- j = int(k[-1])",
"- c[i][j] += 1",
"-ans = 0",
"-for i in range(10):",
"- for j in range(10):",
"- ans += c[i][j] * c[j][i]",
"-print(ans)",
"+MOD = 10**9 + 7",
"+INF = 10**11",
"+import sys",
"+",
"+sys.setrecursionlimit(100000000)",
"+",
"+",
"+def main():",
"+ N = int(eval(input()))",
"+ presuf = [[0] * 10 for _ in range(10)]",
"+ for i in range(1, N + 1):",
"+ pre = int(str(i)[0])",
"+ suf = i % 10",
"+ presuf[pre][suf] += 1",
"+ ans = 0",
"+ for i in range(10):",
"+ for j in range(10):",
"+ ans += presuf[i][j] * presuf[j][i]",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.049528 | 0.051462 | 0.96243 | [
"s498640437",
"s366516209"
] |
u057964173 | p02689 | python | s269613871 | s457516619 | 247 | 210 | 29,336 | 89,892 | Accepted | Accepted | 14.98 | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
N,M=list(map(int, input().split())) # 頂点の数、辺の数
H=list(map(int,input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
edge[x].append(y)
edge[y].append(x) # 有向なら#つける
cnt=0
for i in range(N):
val=H[i]
if edge[i]==[]:
cnt+=1
else:
num=0
for j in edge[i]:
if val>H[j]:
num+=1
if num==len(edge[i]):
cnt+=1
print(cnt)
resolve() | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
N,M=list(map(int, input().split()))
H=list(map(int,input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
edge[x].append(y)
edge[y].append(x)
cnt=0
for i in range(N):
val=H[i]
if edge[i]==[]:
cnt+=1
else:
if all(val>H[j] for j in edge[i]):
cnt+=1
print(cnt)
resolve() | 26 | 22 | 664 | 551 | import sys
def input():
return sys.stdin.readline().strip()
def resolve():
N, M = list(map(int, input().split())) # 頂点の数、辺の数
H = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
edge[x].append(y)
edge[y].append(x) # 有向なら#つける
cnt = 0
for i in range(N):
val = H[i]
if edge[i] == []:
cnt += 1
else:
num = 0
for j in edge[i]:
if val > H[j]:
num += 1
if num == len(edge[i]):
cnt += 1
print(cnt)
resolve()
| import sys
def input():
return sys.stdin.readline().strip()
def resolve():
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
edge[x].append(y)
edge[y].append(x)
cnt = 0
for i in range(N):
val = H[i]
if edge[i] == []:
cnt += 1
else:
if all(val > H[j] for j in edge[i]):
cnt += 1
print(cnt)
resolve()
| false | 15.384615 | [
"- N, M = list(map(int, input().split())) # 頂点の数、辺の数",
"+ N, M = list(map(int, input().split()))",
"- edge[y].append(x) # 有向なら#つける",
"+ edge[y].append(x)",
"- num = 0",
"- for j in edge[i]:",
"- if val > H[j]:",
"- num += 1",
"- if num == len(edge[i]):",
"+ if all(val > H[j] for j in edge[i]):"
] | false | 0.07269 | 0.08143 | 0.892664 | [
"s269613871",
"s457516619"
] |
u553919982 | p03478 | python | s443965693 | s881923077 | 37 | 26 | 3,060 | 3,064 | Accepted | Accepted | 29.73 | def sm(x):
xls = list(str(x))
a = 0
for i in range(len(xls)):
a += int(xls[i])
return a
N, A, B = list(map(int,input().split()))
ans = 0
for i in range(1, N+1):
if A <= sm(i) <= B:
ans += i
print(ans)
| def sm(x):
a = 0
a += (x%10)
a += (x//10)%10
a += ((x//10)//10)%10
a += (((x//10)//10)//10)%10
a += ((((x//10)//10)//10)//10)%10
return a
N, A, B = list(map(int,input().split()))
ans = 0
for i in range(1, N+1):
if A <= sm(i) <= B:
ans += i
print(ans) | 13 | 15 | 244 | 299 | def sm(x):
xls = list(str(x))
a = 0
for i in range(len(xls)):
a += int(xls[i])
return a
N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
if A <= sm(i) <= B:
ans += i
print(ans)
| def sm(x):
a = 0
a += x % 10
a += (x // 10) % 10
a += ((x // 10) // 10) % 10
a += (((x // 10) // 10) // 10) % 10
a += ((((x // 10) // 10) // 10) // 10) % 10
return a
N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
if A <= sm(i) <= B:
ans += i
print(ans)
| false | 13.333333 | [
"- xls = list(str(x))",
"- for i in range(len(xls)):",
"- a += int(xls[i])",
"+ a += x % 10",
"+ a += (x // 10) % 10",
"+ a += ((x // 10) // 10) % 10",
"+ a += (((x // 10) // 10) // 10) % 10",
"+ a += ((((x // 10) // 10) // 10) // 10) % 10"
] | false | 0.063168 | 0.061982 | 1.019129 | [
"s443965693",
"s881923077"
] |
u498487134 | p02820 | python | s002975608 | s563930694 | 196 | 86 | 49,520 | 79,876 | Accepted | Accepted | 56.12 | N,K = list(map(int,input().split()))
R,S,P = list(map(int,input().split()))
T =list(eval(input()))
ans =0
for i in range(N):
if i<K:
if T[i]=="r":
ans+=P
elif T[i]=="s":
ans+=R
else:
ans+=S
else:
if T[i]=="r":
if T[i-K]!="r":
ans+=P
else:
T[i]="-"
elif T[i]=="s":
if T[i-K]!="s":
ans+=R
else:
T[i]="-"
else:
if T[i]=="p":
if T[i-K]!="p":
ans+=S
else:
T[i]="-"
print(ans) |
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N,K=MI()
R,S,P=MI()
T=eval(input())
L=[]
ans=0
for i in range(N):
pre="z"
if i-K>=0:
pre=L[i-K]
if T[i]=="r":
if pre!="p":
ans+=P
L.append("p")
else:
L.append("z")
if T[i]=="s":
if pre!="r":
ans+=R
L.append("r")
else:
L.append("z")
if T[i]=="p":
if pre!="s":
ans+=S
L.append("s")
else:
L.append("z")
print(ans)
main()
| 32 | 44 | 685 | 878 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(eval(input()))
ans = 0
for i in range(N):
if i < K:
if T[i] == "r":
ans += P
elif T[i] == "s":
ans += R
else:
ans += S
else:
if T[i] == "r":
if T[i - K] != "r":
ans += P
else:
T[i] = "-"
elif T[i] == "s":
if T[i - K] != "s":
ans += R
else:
T[i] = "-"
else:
if T[i] == "p":
if T[i - K] != "p":
ans += S
else:
T[i] = "-"
print(ans)
| def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
N, K = MI()
R, S, P = MI()
T = eval(input())
L = []
ans = 0
for i in range(N):
pre = "z"
if i - K >= 0:
pre = L[i - K]
if T[i] == "r":
if pre != "p":
ans += P
L.append("p")
else:
L.append("z")
if T[i] == "s":
if pre != "r":
ans += R
L.append("r")
else:
L.append("z")
if T[i] == "p":
if pre != "s":
ans += S
L.append("s")
else:
L.append("z")
print(ans)
main()
| false | 27.272727 | [
"-N, K = list(map(int, input().split()))",
"-R, S, P = list(map(int, input().split()))",
"-T = list(eval(input()))",
"-ans = 0",
"-for i in range(N):",
"- if i < K:",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ N, K = MI()",
"+ R, S, P = MI()",
"+ T = eval(input())",
"+ L = []",
"+ ans = 0",
"+ for i in range(N):",
"+ pre = \"z\"",
"+ if i - K >= 0:",
"+ pre = L[i - K]",
"- ans += P",
"- elif T[i] == \"s\":",
"- ans += R",
"- else:",
"- ans += S",
"- else:",
"- if T[i] == \"r\":",
"- if T[i - K] != \"r\":",
"+ if pre != \"p\":",
"+ L.append(\"p\")",
"- T[i] = \"-\"",
"- elif T[i] == \"s\":",
"- if T[i - K] != \"s\":",
"+ L.append(\"z\")",
"+ if T[i] == \"s\":",
"+ if pre != \"r\":",
"+ L.append(\"r\")",
"- T[i] = \"-\"",
"- else:",
"- if T[i] == \"p\":",
"- if T[i - K] != \"p\":",
"- ans += S",
"- else:",
"- T[i] = \"-\"",
"-print(ans)",
"+ L.append(\"z\")",
"+ if T[i] == \"p\":",
"+ if pre != \"s\":",
"+ ans += S",
"+ L.append(\"s\")",
"+ else:",
"+ L.append(\"z\")",
"+ print(ans)",
"+",
"+",
"+main()"
] | false | 0.047099 | 0.037122 | 1.268773 | [
"s002975608",
"s563930694"
] |
u543954314 | p02936 | python | s880808156 | s764557364 | 1,695 | 961 | 92,416 | 56,144 | Accepted | Accepted | 43.3 | n,q = list(map(int, input().split()))
tree = [set() for i in range(n+1)]
for _ in range(n-1):
a,b = list(map(int, input().split()))
tree[a].add(b)
tree[b].add(a)
lazy = [0]*(n+1)
cnt = 0
for _ in range(q):
x,v = list(map(int, input().split()))
lazy[x] += v
que = [(1,0)]
while que:
v,p = que.pop()
for x in tree[v]:
if x == p:
continue
lazy[x] += lazy[v]
que.append((x,v))
print((" ".join(map(str,lazy[1:])))) | import sys
from collections import deque
readline = sys.stdin.buffer.readline
ni = lambda: int(readline().rstrip())
nm = lambda: list(map(int, readline().split()))
nl = lambda: list(map(int, readline().split()))
def solve():
n, Q = nm()
G = [list() for _ in range(n)]
for _ in range(n-1):
u, v = nm()
u -= 1; v -= 1
G[u].append(v)
G[v].append(u)
a = [0]*n
for _ in range(Q):
p, x = nm()
a[p-1] += x
q = deque()
q.append(0)
seen = [1] + [0]*(n-1)
while q:
v = q.popleft()
for x in G[v]:
if not seen[x]:
seen[x] = 1
a[x] += a[v]
q.append(x)
print((*a))
return
solve()
# T = ni()
# for _ in range(T):
# solve()
| 23 | 39 | 446 | 815 | n, q = list(map(int, input().split()))
tree = [set() for i in range(n + 1)]
for _ in range(n - 1):
a, b = list(map(int, input().split()))
tree[a].add(b)
tree[b].add(a)
lazy = [0] * (n + 1)
cnt = 0
for _ in range(q):
x, v = list(map(int, input().split()))
lazy[x] += v
que = [(1, 0)]
while que:
v, p = que.pop()
for x in tree[v]:
if x == p:
continue
lazy[x] += lazy[v]
que.append((x, v))
print((" ".join(map(str, lazy[1:]))))
| import sys
from collections import deque
readline = sys.stdin.buffer.readline
ni = lambda: int(readline().rstrip())
nm = lambda: list(map(int, readline().split()))
nl = lambda: list(map(int, readline().split()))
def solve():
n, Q = nm()
G = [list() for _ in range(n)]
for _ in range(n - 1):
u, v = nm()
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
a = [0] * n
for _ in range(Q):
p, x = nm()
a[p - 1] += x
q = deque()
q.append(0)
seen = [1] + [0] * (n - 1)
while q:
v = q.popleft()
for x in G[v]:
if not seen[x]:
seen[x] = 1
a[x] += a[v]
q.append(x)
print((*a))
return
solve()
# T = ni()
# for _ in range(T):
# solve()
| false | 41.025641 | [
"-n, q = list(map(int, input().split()))",
"-tree = [set() for i in range(n + 1)]",
"-for _ in range(n - 1):",
"- a, b = list(map(int, input().split()))",
"- tree[a].add(b)",
"- tree[b].add(a)",
"-lazy = [0] * (n + 1)",
"-cnt = 0",
"-for _ in range(q):",
"- x, v = list(map(int, input().split()))",
"- lazy[x] += v",
"-que = [(1, 0)]",
"-while que:",
"- v, p = que.pop()",
"- for x in tree[v]:",
"- if x == p:",
"- continue",
"- lazy[x] += lazy[v]",
"- que.append((x, v))",
"-print((\" \".join(map(str, lazy[1:]))))",
"+import sys",
"+from collections import deque",
"+",
"+readline = sys.stdin.buffer.readline",
"+ni = lambda: int(readline().rstrip())",
"+nm = lambda: list(map(int, readline().split()))",
"+nl = lambda: list(map(int, readline().split()))",
"+",
"+",
"+def solve():",
"+ n, Q = nm()",
"+ G = [list() for _ in range(n)]",
"+ for _ in range(n - 1):",
"+ u, v = nm()",
"+ u -= 1",
"+ v -= 1",
"+ G[u].append(v)",
"+ G[v].append(u)",
"+ a = [0] * n",
"+ for _ in range(Q):",
"+ p, x = nm()",
"+ a[p - 1] += x",
"+ q = deque()",
"+ q.append(0)",
"+ seen = [1] + [0] * (n - 1)",
"+ while q:",
"+ v = q.popleft()",
"+ for x in G[v]:",
"+ if not seen[x]:",
"+ seen[x] = 1",
"+ a[x] += a[v]",
"+ q.append(x)",
"+ print((*a))",
"+ return",
"+",
"+",
"+solve()",
"+# T = ni()",
"+# for _ in range(T):",
"+# solve()"
] | false | 0.077692 | 0.090297 | 0.860404 | [
"s880808156",
"s764557364"
] |
u212437180 | p02657 | python | s112687013 | s566354957 | 1,369 | 39 | 196,040 | 10,204 | Accepted | Accepted | 97.15 | from subprocess import run
with open("./tmp215378912379.cpp", mode='w') as f:
f.write("""
#include <bits/stdc++.h>
template <class T>
concept Integral = std::is_integral_v<T>;
int main() {
auto f = []<Integral T>(T a, T b) { return a * b; };
int a, b;
std::cin >> a >> b;
std::cout << f(a, b) << std::endl;
}
""")
run("g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp && ./tmp215378912379", shell=True) | from subprocess import run
from os import path
if not path.exists("./tmp215378912379"):
with open("./tmp215378912379.cpp", mode='w') as f:
f.write("""
#include <bits/stdc++.h>
template <class T>
concept Integral = std::is_integral_v<T>;
int main() {
auto f = []<Integral T>(T a, T b) { return a * b; };
int a, b;
std::cin >> a >> b;
std::cout << f(a, b) << std::endl;
}
""")
run("g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp", shell=True)
run("./tmp215378912379") | 17 | 21 | 453 | 549 | from subprocess import run
with open("./tmp215378912379.cpp", mode="w") as f:
f.write(
"""
#include <bits/stdc++.h>
template <class T>
concept Integral = std::is_integral_v<T>;
int main() {
auto f = []<Integral T>(T a, T b) { return a * b; };
int a, b;
std::cin >> a >> b;
std::cout << f(a, b) << std::endl;
}
"""
)
run(
"g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp && ./tmp215378912379",
shell=True,
)
| from subprocess import run
from os import path
if not path.exists("./tmp215378912379"):
with open("./tmp215378912379.cpp", mode="w") as f:
f.write(
"""
#include <bits/stdc++.h>
template <class T>
concept Integral = std::is_integral_v<T>;
int main() {
auto f = []<Integral T>(T a, T b) { return a * b; };
int a, b;
std::cin >> a >> b;
std::cout << f(a, b) << std::endl;
}
"""
)
run(
"g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp",
shell=True,
)
run("./tmp215378912379")
| false | 19.047619 | [
"+from os import path",
"-with open(\"./tmp215378912379.cpp\", mode=\"w\") as f:",
"- f.write(",
"- \"\"\"",
"-#include <bits/stdc++.h>",
"-template <class T>",
"-concept Integral = std::is_integral_v<T>;",
"-int main() {",
"- auto f = []<Integral T>(T a, T b) { return a * b; };",
"- int a, b;",
"- std::cin >> a >> b;",
"- std::cout << f(a, b) << std::endl;",
"-}",
"-\"\"\"",
"+if not path.exists(\"./tmp215378912379\"):",
"+ with open(\"./tmp215378912379.cpp\", mode=\"w\") as f:",
"+ f.write(",
"+ \"\"\"",
"+ #include <bits/stdc++.h>",
"+ template <class T>",
"+ concept Integral = std::is_integral_v<T>;",
"+ int main() {",
"+ auto f = []<Integral T>(T a, T b) { return a * b; };",
"+ int a, b;",
"+ std::cin >> a >> b;",
"+ std::cout << f(a, b) << std::endl;",
"+ }",
"+ \"\"\"",
"+ )",
"+ run(",
"+ \"g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp\",",
"+ shell=True,",
"-run(",
"- \"g++ -o ./tmp215378912379 -std=gnu++2a -fconcepts ./tmp215378912379.cpp && ./tmp215378912379\",",
"- shell=True,",
"-)",
"+run(\"./tmp215378912379\")"
] | false | 2.521744 | 0.043917 | 57.421055 | [
"s112687013",
"s566354957"
] |
u426534722 | p02371 | python | s130732534 | s399238821 | 790 | 710 | 55,500 | 55,628 | Accepted | Accepted | 10.13 | import sys
readline = sys.stdin.readline
from collections import deque
from math import isinf
INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
s, t, w = list(map(int, readline().split()))
G[s].append([t, w])
G[t].append([s, w])
def bfs(s, D):
dq = deque([s])
D = [INF] * n
D[s] = 0
while dq:
u = dq.popleft()
for i in range(len(G[u])):
e = G[u][i]
if isinf(D[e[0]]):
D[e[0]] = D[u] + e[1]
dq.append(e[0])
return D
D = bfs(0, D)
maxv = 0
tgt = 0
for i in range(n):
if isinf(D[i]): continue
if maxv < D[i]:
maxv = D[i]
tgt = i
D = bfs(tgt, D)
maxv = 0
for i in range(n):
if isinf(D[i]): continue
maxv = max(maxv, D[i])
print(maxv) | import sys
readline = sys.stdin.readline
from collections import deque
from math import isinf
INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
s, t, w = list(map(int, readline().split()))
G[s].append([t, w])
G[t].append([s, w])
def bfs(s, D):
dq = deque([s])
D = [INF] * n
D[s] = 0
while dq:
u = dq.popleft()
for i in range(len(G[u])):
e = G[u][i]
if isinf(D[e[0]]):
D[e[0]] = D[u] + e[1]
dq.append(e[0])
return D
D = bfs(0, D)
maxv = 0
tgt = 0
for i in range(n):
if isinf(D[i]): continue
if maxv < D[i]:
maxv = D[i]
tgt = i
D = bfs(tgt, D)
print((max(D[i] for i in range(n) if not isinf(D[i])))) | 39 | 35 | 881 | 835 | import sys
readline = sys.stdin.readline
from collections import deque
from math import isinf
INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
s, t, w = list(map(int, readline().split()))
G[s].append([t, w])
G[t].append([s, w])
def bfs(s, D):
dq = deque([s])
D = [INF] * n
D[s] = 0
while dq:
u = dq.popleft()
for i in range(len(G[u])):
e = G[u][i]
if isinf(D[e[0]]):
D[e[0]] = D[u] + e[1]
dq.append(e[0])
return D
D = bfs(0, D)
maxv = 0
tgt = 0
for i in range(n):
if isinf(D[i]):
continue
if maxv < D[i]:
maxv = D[i]
tgt = i
D = bfs(tgt, D)
maxv = 0
for i in range(n):
if isinf(D[i]):
continue
maxv = max(maxv, D[i])
print(maxv)
| import sys
readline = sys.stdin.readline
from collections import deque
from math import isinf
INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
s, t, w = list(map(int, readline().split()))
G[s].append([t, w])
G[t].append([s, w])
def bfs(s, D):
dq = deque([s])
D = [INF] * n
D[s] = 0
while dq:
u = dq.popleft()
for i in range(len(G[u])):
e = G[u][i]
if isinf(D[e[0]]):
D[e[0]] = D[u] + e[1]
dq.append(e[0])
return D
D = bfs(0, D)
maxv = 0
tgt = 0
for i in range(n):
if isinf(D[i]):
continue
if maxv < D[i]:
maxv = D[i]
tgt = i
D = bfs(tgt, D)
print((max(D[i] for i in range(n) if not isinf(D[i]))))
| false | 10.25641 | [
"-maxv = 0",
"-for i in range(n):",
"- if isinf(D[i]):",
"- continue",
"- maxv = max(maxv, D[i])",
"-print(maxv)",
"+print((max(D[i] for i in range(n) if not isinf(D[i]))))"
] | false | 0.047563 | 0.037585 | 1.265496 | [
"s130732534",
"s399238821"
] |
u707124227 | p02586 | python | s292150125 | s535890768 | 992 | 909 | 177,880 | 188,056 | Accepted | Accepted | 8.37 | import sys
input = sys.stdin.readline
def main(R,C,K,rcv):
inf=float('inf')
dp0=[[-inf,-inf,-inf,0] for _ in range(C)]
item=[[0]*C for _ in range(R)]
for r,c,v in rcv:
item[r-1][c-1]=v
# dp0[c][j]:c列目の時点で残りちょうどj個取れる時の最大値
for i in range(R):
# i+1行目に対する操作
# 遷移
for j in range(C):
if j>0:
dp0[j][3]=max(dp0[j])
dp0[j][0]=dp0[j-1][0]
dp0[j][1]=dp0[j-1][1]
dp0[j][2]=dp0[j-1][2]
else:
dp0[0][3]=max(dp0[0])
dp0[0][2]=-inf
dp0[0][1]=-inf
dp0[0][0]=-inf
if item[i][j]>0:
v=item[i][j]
dp0[j][0]=max(dp0[j][0],dp0[j][1]+v)
dp0[j][1]=max(dp0[j][1],dp0[j][2]+v)
dp0[j][2]=max(dp0[j][2],dp0[j][3]+v)
print((max(dp0[-1])))
if __name__=='__main__':
R,C,K=list(map(int,input().split()))
rcv=[list(map(int,input().split())) for _ in range(K)]
main(R,C,K,rcv)
| R,C,K=list(map(int,input().split()))
rcv=[list(map(int,input().split())) for _ in range(K)]
mat=[[0]*C for _ in range(R)]
for r,c,v in rcv:
mat[r-1][c-1]=v
dp=[0]*C
for i in range(R):
ndp=[0]*C
wdp=[0]*4
for j in range(C):
wdp[0]=max(wdp[0],dp[j])
if mat[i][j]>0:
v=mat[i][j]
wdp[3]=max(wdp[3],wdp[2]+v)
wdp[2]=max(wdp[2],wdp[1]+v)
wdp[1]=max(wdp[1],wdp[0]+v)
ndp[j]=max(wdp)
dp=ndp.copy()
print((max(wdp))) | 33 | 19 | 918 | 463 | import sys
input = sys.stdin.readline
def main(R, C, K, rcv):
inf = float("inf")
dp0 = [[-inf, -inf, -inf, 0] for _ in range(C)]
item = [[0] * C for _ in range(R)]
for r, c, v in rcv:
item[r - 1][c - 1] = v
# dp0[c][j]:c列目の時点で残りちょうどj個取れる時の最大値
for i in range(R):
# i+1行目に対する操作
# 遷移
for j in range(C):
if j > 0:
dp0[j][3] = max(dp0[j])
dp0[j][0] = dp0[j - 1][0]
dp0[j][1] = dp0[j - 1][1]
dp0[j][2] = dp0[j - 1][2]
else:
dp0[0][3] = max(dp0[0])
dp0[0][2] = -inf
dp0[0][1] = -inf
dp0[0][0] = -inf
if item[i][j] > 0:
v = item[i][j]
dp0[j][0] = max(dp0[j][0], dp0[j][1] + v)
dp0[j][1] = max(dp0[j][1], dp0[j][2] + v)
dp0[j][2] = max(dp0[j][2], dp0[j][3] + v)
print((max(dp0[-1])))
if __name__ == "__main__":
R, C, K = list(map(int, input().split()))
rcv = [list(map(int, input().split())) for _ in range(K)]
main(R, C, K, rcv)
| R, C, K = list(map(int, input().split()))
rcv = [list(map(int, input().split())) for _ in range(K)]
mat = [[0] * C for _ in range(R)]
for r, c, v in rcv:
mat[r - 1][c - 1] = v
dp = [0] * C
for i in range(R):
ndp = [0] * C
wdp = [0] * 4
for j in range(C):
wdp[0] = max(wdp[0], dp[j])
if mat[i][j] > 0:
v = mat[i][j]
wdp[3] = max(wdp[3], wdp[2] + v)
wdp[2] = max(wdp[2], wdp[1] + v)
wdp[1] = max(wdp[1], wdp[0] + v)
ndp[j] = max(wdp)
dp = ndp.copy()
print((max(wdp)))
| false | 42.424242 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def main(R, C, K, rcv):",
"- inf = float(\"inf\")",
"- dp0 = [[-inf, -inf, -inf, 0] for _ in range(C)]",
"- item = [[0] * C for _ in range(R)]",
"- for r, c, v in rcv:",
"- item[r - 1][c - 1] = v",
"- # dp0[c][j]:c列目の時点で残りちょうどj個取れる時の最大値",
"- for i in range(R):",
"- # i+1行目に対する操作",
"- # 遷移",
"- for j in range(C):",
"- if j > 0:",
"- dp0[j][3] = max(dp0[j])",
"- dp0[j][0] = dp0[j - 1][0]",
"- dp0[j][1] = dp0[j - 1][1]",
"- dp0[j][2] = dp0[j - 1][2]",
"- else:",
"- dp0[0][3] = max(dp0[0])",
"- dp0[0][2] = -inf",
"- dp0[0][1] = -inf",
"- dp0[0][0] = -inf",
"- if item[i][j] > 0:",
"- v = item[i][j]",
"- dp0[j][0] = max(dp0[j][0], dp0[j][1] + v)",
"- dp0[j][1] = max(dp0[j][1], dp0[j][2] + v)",
"- dp0[j][2] = max(dp0[j][2], dp0[j][3] + v)",
"- print((max(dp0[-1])))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- R, C, K = list(map(int, input().split()))",
"- rcv = [list(map(int, input().split())) for _ in range(K)]",
"- main(R, C, K, rcv)",
"+R, C, K = list(map(int, input().split()))",
"+rcv = [list(map(int, input().split())) for _ in range(K)]",
"+mat = [[0] * C for _ in range(R)]",
"+for r, c, v in rcv:",
"+ mat[r - 1][c - 1] = v",
"+dp = [0] * C",
"+for i in range(R):",
"+ ndp = [0] * C",
"+ wdp = [0] * 4",
"+ for j in range(C):",
"+ wdp[0] = max(wdp[0], dp[j])",
"+ if mat[i][j] > 0:",
"+ v = mat[i][j]",
"+ wdp[3] = max(wdp[3], wdp[2] + v)",
"+ wdp[2] = max(wdp[2], wdp[1] + v)",
"+ wdp[1] = max(wdp[1], wdp[0] + v)",
"+ ndp[j] = max(wdp)",
"+ dp = ndp.copy()",
"+print((max(wdp)))"
] | false | 0.174085 | 0.037072 | 4.695819 | [
"s292150125",
"s535890768"
] |
u852690916 | p03559 | python | s074818728 | s184914780 | 478 | 317 | 107,108 | 23,168 | Accepted | Accepted | 33.68 | import bisect
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
ans = 0
for b in B:
ai = bisect.bisect_left(A, b)
ci = bisect.bisect_right(C, b)
ans += ai * (N-ci)
#print(b,ai,ci)
print(ans) | N=int(eval(input()))
*A,=list(map(int, input().split()))
*B,=list(map(int, input().split()))
*C,=list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
from bisect import bisect_left, bisect_right
for b in B:
ac = bisect_left(A,b)
cc = N - bisect_right(C,b)
ans += ac * cc
print(ans) | 14 | 16 | 317 | 300 | import bisect
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
ai = bisect.bisect_left(A, b)
ci = bisect.bisect_right(C, b)
ans += ai * (N - ci)
# print(b,ai,ci)
print(ans)
| N = int(eval(input()))
(*A,) = list(map(int, input().split()))
(*B,) = list(map(int, input().split()))
(*C,) = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
from bisect import bisect_left, bisect_right
for b in B:
ac = bisect_left(A, b)
cc = N - bisect_right(C, b)
ans += ac * cc
print(ans)
| false | 12.5 | [
"-import bisect",
"+N = int(eval(input()))",
"+(*A,) = list(map(int, input().split()))",
"+(*B,) = list(map(int, input().split()))",
"+(*C,) = list(map(int, input().split()))",
"+A.sort()",
"+B.sort()",
"+C.sort()",
"+ans = 0",
"+from bisect import bisect_left, bisect_right",
"-N = int(eval(input()))",
"-A = sorted(list(map(int, input().split())))",
"-B = sorted(list(map(int, input().split())))",
"-C = sorted(list(map(int, input().split())))",
"-ans = 0",
"- ai = bisect.bisect_left(A, b)",
"- ci = bisect.bisect_right(C, b)",
"- ans += ai * (N - ci)",
"- # print(b,ai,ci)",
"+ ac = bisect_left(A, b)",
"+ cc = N - bisect_right(C, b)",
"+ ans += ac * cc"
] | false | 0.163652 | 0.038302 | 4.272658 | [
"s074818728",
"s184914780"
] |
u940342887 | p03160 | python | s271008341 | s466445724 | 254 | 148 | 53,440 | 20,616 | Accepted | Accepted | 41.73 | # dp[i]: i+1にくるまでにかかったコストの最小値
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N-1):
dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
if i < N-2:
dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))
print((dp[-1])) | N = int(eval(input()))
h = list(map(int, input().split(" ")))
dp = [float("inf")]*(N)
dp[0] = 0
for i in range(N-1):
dp[i + 1] = min(dp[i + 1], abs(h[i + 1] - h[i]) + dp[i])
if i + 2 < N:
dp[i + 2] = min(dp[i + 2], abs(h[i + 2] - h[i]) + dp[i])
print((dp[-1])) | 10 | 12 | 296 | 282 | # dp[i]: i+1にくるまでにかかったコストの最小値
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
if i < N - 2:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
print((dp[-1]))
| N = int(eval(input()))
h = list(map(int, input().split(" ")))
dp = [float("inf")] * (N)
dp[0] = 0
for i in range(N - 1):
dp[i + 1] = min(dp[i + 1], abs(h[i + 1] - h[i]) + dp[i])
if i + 2 < N:
dp[i + 2] = min(dp[i + 2], abs(h[i + 2] - h[i]) + dp[i])
print((dp[-1]))
| false | 16.666667 | [
"-# dp[i]: i+1にくるまでにかかったコストの最小値",
"-h = list(map(int, input().split()))",
"-dp = [float(\"inf\") for _ in range(N)]",
"+h = list(map(int, input().split(\" \")))",
"+dp = [float(\"inf\")] * (N)",
"- dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))",
"- if i < N - 2:",
"- dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))",
"+ dp[i + 1] = min(dp[i + 1], abs(h[i + 1] - h[i]) + dp[i])",
"+ if i + 2 < N:",
"+ dp[i + 2] = min(dp[i + 2], abs(h[i + 2] - h[i]) + dp[i])"
] | false | 0.044528 | 0.042331 | 1.05189 | [
"s271008341",
"s466445724"
] |
u597374218 | p03363 | python | s499767384 | s035799673 | 194 | 144 | 38,676 | 35,712 | Accepted | Accepted | 25.77 | N=int(eval(input()))
A=list(map(int,input().split()))
cumulative_sum=0
count=0
counter={0:1}
for a in A:
cumulative_sum+=a
if cumulative_sum not in counter:
counter[cumulative_sum]=0
count+=counter[cumulative_sum]
counter[cumulative_sum]+=1
print(count) | import itertools
import collections
N=int(eval(input()))
A=list(itertools.accumulate(list(map(int,input().split()))))
count=0
for s in list(collections.Counter(A+[0]).values()):
count+=s*(s-1)//2
print(count) | 12 | 8 | 282 | 201 | N = int(eval(input()))
A = list(map(int, input().split()))
cumulative_sum = 0
count = 0
counter = {0: 1}
for a in A:
cumulative_sum += a
if cumulative_sum not in counter:
counter[cumulative_sum] = 0
count += counter[cumulative_sum]
counter[cumulative_sum] += 1
print(count)
| import itertools
import collections
N = int(eval(input()))
A = list(itertools.accumulate(list(map(int, input().split()))))
count = 0
for s in list(collections.Counter(A + [0]).values()):
count += s * (s - 1) // 2
print(count)
| false | 33.333333 | [
"+import itertools",
"+import collections",
"+",
"-A = list(map(int, input().split()))",
"-cumulative_sum = 0",
"+A = list(itertools.accumulate(list(map(int, input().split()))))",
"-counter = {0: 1}",
"-for a in A:",
"- cumulative_sum += a",
"- if cumulative_sum not in counter:",
"- counter[cumulative_sum] = 0",
"- count += counter[cumulative_sum]",
"- counter[cumulative_sum] += 1",
"+for s in list(collections.Counter(A + [0]).values()):",
"+ count += s * (s - 1) // 2"
] | false | 0.039676 | 0.035114 | 1.129919 | [
"s499767384",
"s035799673"
] |
u063052907 | p03013 | python | s317033016 | s436918174 | 510 | 198 | 460,020 | 13,212 | Accepted | Accepted | 61.18 | N, M = list(map(int, input().split()))
set_a = set([int(eval(input())) for _ in range(M)])
MOD = 10**9 + 7
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in set_a else 1
for i in range(2, N+1):
dp[i] = 0 if i in set_a else dp[i-1] + dp[i-2]
ans = dp[N] % MOD
print(ans) | N, M = list(map(int, input().split()))
set_a = set([int(eval(input())) for _ in range(M)])
MOD = 10**9 + 7
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in set_a else 1
for i in range(2, N+1):
dp[i] = 0 if i in set_a else dp[i-1] + dp[i-2]
dp[i] %= MOD
ans = dp[N] % MOD
print(ans) | 12 | 13 | 271 | 289 | N, M = list(map(int, input().split()))
set_a = set([int(eval(input())) for _ in range(M)])
MOD = 10**9 + 7
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in set_a else 1
for i in range(2, N + 1):
dp[i] = 0 if i in set_a else dp[i - 1] + dp[i - 2]
ans = dp[N] % MOD
print(ans)
| N, M = list(map(int, input().split()))
set_a = set([int(eval(input())) for _ in range(M)])
MOD = 10**9 + 7
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in set_a else 1
for i in range(2, N + 1):
dp[i] = 0 if i in set_a else dp[i - 1] + dp[i - 2]
dp[i] %= MOD
ans = dp[N] % MOD
print(ans)
| false | 7.692308 | [
"+ dp[i] %= MOD"
] | false | 0.042463 | 0.036909 | 1.150478 | [
"s317033016",
"s436918174"
] |
u678167152 | p02768 | python | s598204475 | s004502386 | 968 | 489 | 47,452 | 38,768 | Accepted | Accepted | 49.48 | n,a,b = [int(i) for i in input().split()]
mod = 10**9+7
def mpow(a,n):
if n == 1:
return a
x = mpow(a,n//2)
ans = x*x%mod
if n%2==1:
ans *= a
return ans
def comb(n,a,b):
if a < b:
s, l = a, b
else:
s, l = b, a
rs = 1
for i in range(s):
rs = rs*(n-i)%mod
rl = rs
for i in range(s,l):
rl = rl*(n-i)%mod
L = 1
for i in range(1,s+1):
L = L*mpow(i,mod-2)%mod
rs = rs*L%mod
rl = rl*L%mod
for i in range(s+1,l+1):
rl = rl*mpow(i,mod-2)%mod
if a < b:
nCa, nCb = rs, rl
else:
nCa, nCb = rl, rs
return nCa, nCb
nCa,nCb = comb(n,a,b)
print(((mpow(2,n)-1-nCa-nCb)%mod))
# print(nCa,nCb)
| def comb_mod(n,r):
mod = 10**9+7
ans = 1
for i in range(r):
ans *= n-i
ans %= mod
for i in range(1,r+1):
ans *= pow(i,mod-2,mod)
ans %= mod
return ans
def solve():
n, a, b = list(map(int, input().split()))
mod = 10**9+7
ans = pow(2,n,mod)-comb_mod(n,a)-comb_mod(n,b)-1
ans %= mod
return ans
print((solve())) | 38 | 18 | 690 | 389 | n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7
def mpow(a, n):
if n == 1:
return a
x = mpow(a, n // 2)
ans = x * x % mod
if n % 2 == 1:
ans *= a
return ans
def comb(n, a, b):
if a < b:
s, l = a, b
else:
s, l = b, a
rs = 1
for i in range(s):
rs = rs * (n - i) % mod
rl = rs
for i in range(s, l):
rl = rl * (n - i) % mod
L = 1
for i in range(1, s + 1):
L = L * mpow(i, mod - 2) % mod
rs = rs * L % mod
rl = rl * L % mod
for i in range(s + 1, l + 1):
rl = rl * mpow(i, mod - 2) % mod
if a < b:
nCa, nCb = rs, rl
else:
nCa, nCb = rl, rs
return nCa, nCb
nCa, nCb = comb(n, a, b)
print(((mpow(2, n) - 1 - nCa - nCb) % mod))
# print(nCa,nCb)
| def comb_mod(n, r):
mod = 10**9 + 7
ans = 1
for i in range(r):
ans *= n - i
ans %= mod
for i in range(1, r + 1):
ans *= pow(i, mod - 2, mod)
ans %= mod
return ans
def solve():
n, a, b = list(map(int, input().split()))
mod = 10**9 + 7
ans = pow(2, n, mod) - comb_mod(n, a) - comb_mod(n, b) - 1
ans %= mod
return ans
print((solve()))
| false | 52.631579 | [
"-n, a, b = [int(i) for i in input().split()]",
"-mod = 10**9 + 7",
"-",
"-",
"-def mpow(a, n):",
"- if n == 1:",
"- return a",
"- x = mpow(a, n // 2)",
"- ans = x * x % mod",
"- if n % 2 == 1:",
"- ans *= a",
"+def comb_mod(n, r):",
"+ mod = 10**9 + 7",
"+ ans = 1",
"+ for i in range(r):",
"+ ans *= n - i",
"+ ans %= mod",
"+ for i in range(1, r + 1):",
"+ ans *= pow(i, mod - 2, mod)",
"+ ans %= mod",
"-def comb(n, a, b):",
"- if a < b:",
"- s, l = a, b",
"- else:",
"- s, l = b, a",
"- rs = 1",
"- for i in range(s):",
"- rs = rs * (n - i) % mod",
"- rl = rs",
"- for i in range(s, l):",
"- rl = rl * (n - i) % mod",
"- L = 1",
"- for i in range(1, s + 1):",
"- L = L * mpow(i, mod - 2) % mod",
"- rs = rs * L % mod",
"- rl = rl * L % mod",
"- for i in range(s + 1, l + 1):",
"- rl = rl * mpow(i, mod - 2) % mod",
"- if a < b:",
"- nCa, nCb = rs, rl",
"- else:",
"- nCa, nCb = rl, rs",
"- return nCa, nCb",
"+def solve():",
"+ n, a, b = list(map(int, input().split()))",
"+ mod = 10**9 + 7",
"+ ans = pow(2, n, mod) - comb_mod(n, a) - comb_mod(n, b) - 1",
"+ ans %= mod",
"+ return ans",
"-nCa, nCb = comb(n, a, b)",
"-print(((mpow(2, n) - 1 - nCa - nCb) % mod))",
"-# print(nCa,nCb)",
"+print((solve()))"
] | false | 1.473078 | 0.951969 | 1.547402 | [
"s598204475",
"s004502386"
] |
u279546122 | p02362 | python | s574224786 | s947320958 | 1,400 | 550 | 8,900 | 8,624 | Accepted | Accepted | 60.71 | from sys import stdin
from collections import deque
V, E, R = [int(x) for x in stdin.readline().split()]
d = {}
tick = False
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
weight = {}
st = []
for i in range(1, V+1):
for j in range(E):
if i == 1:
s, t, w = [int(x) for x in stdin.readline().split()]
weight[(s, t)] = w
st.append((s, t))
(s, t) = st[j]
if d[t] > d[s] + weight[(s, t)]:
d[t] = d[s] + weight[(s, t)]
if i == V:
print('NEGATIVE CYCLE')
quit()
for k in range(V):
if d[k] == float('inf'):
print("INF")
else:
print((d[k])) | from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G,R,V):
d = {}
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
for i in range(1, V+1):
for ((u, v), c) in list(G.items()):
if d[v] > d[u] + c:
d[v] = d[u] + c
if i == V:
return 0
return d
V, E, R = [int(x) for x in stdin.readline().split()]
G = {}
for case in range(E):
s, t, w = [int(x) for x in stdin.readline().split()]
G[(s, t)] = w
d = sp(G, R, V)
if d == 0:
print('NEGATIVE CYCLE')
else:
for k in range(V):
if d[k] == float('inf'):
print("INF")
else:
print((d[k])) | 30 | 33 | 719 | 765 | from sys import stdin
from collections import deque
V, E, R = [int(x) for x in stdin.readline().split()]
d = {}
tick = False
INF = float("inf")
for i in range(V):
d[i] = INF
d[R] = 0
weight = {}
st = []
for i in range(1, V + 1):
for j in range(E):
if i == 1:
s, t, w = [int(x) for x in stdin.readline().split()]
weight[(s, t)] = w
st.append((s, t))
(s, t) = st[j]
if d[t] > d[s] + weight[(s, t)]:
d[t] = d[s] + weight[(s, t)]
if i == V:
print("NEGATIVE CYCLE")
quit()
for k in range(V):
if d[k] == float("inf"):
print("INF")
else:
print((d[k]))
| from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G, R, V):
d = {}
INF = float("inf")
for i in range(V):
d[i] = INF
d[R] = 0
for i in range(1, V + 1):
for ((u, v), c) in list(G.items()):
if d[v] > d[u] + c:
d[v] = d[u] + c
if i == V:
return 0
return d
V, E, R = [int(x) for x in stdin.readline().split()]
G = {}
for case in range(E):
s, t, w = [int(x) for x in stdin.readline().split()]
G[(s, t)] = w
d = sp(G, R, V)
if d == 0:
print("NEGATIVE CYCLE")
else:
for k in range(V):
if d[k] == float("inf"):
print("INF")
else:
print((d[k]))
| false | 9.090909 | [
"+from collections import defaultdict",
"+from collections import deque",
"-from collections import deque",
"+",
"+",
"+def sp(G, R, V):",
"+ d = {}",
"+ INF = float(\"inf\")",
"+ for i in range(V):",
"+ d[i] = INF",
"+ d[R] = 0",
"+ for i in range(1, V + 1):",
"+ for ((u, v), c) in list(G.items()):",
"+ if d[v] > d[u] + c:",
"+ d[v] = d[u] + c",
"+ if i == V:",
"+ return 0",
"+ return d",
"+",
"-d = {}",
"-tick = False",
"-INF = float(\"inf\")",
"-for i in range(V):",
"- d[i] = INF",
"-d[R] = 0",
"-weight = {}",
"-st = []",
"-for i in range(1, V + 1):",
"- for j in range(E):",
"- if i == 1:",
"- s, t, w = [int(x) for x in stdin.readline().split()]",
"- weight[(s, t)] = w",
"- st.append((s, t))",
"- (s, t) = st[j]",
"- if d[t] > d[s] + weight[(s, t)]:",
"- d[t] = d[s] + weight[(s, t)]",
"- if i == V:",
"- print(\"NEGATIVE CYCLE\")",
"- quit()",
"-for k in range(V):",
"- if d[k] == float(\"inf\"):",
"- print(\"INF\")",
"- else:",
"- print((d[k]))",
"+G = {}",
"+for case in range(E):",
"+ s, t, w = [int(x) for x in stdin.readline().split()]",
"+ G[(s, t)] = w",
"+d = sp(G, R, V)",
"+if d == 0:",
"+ print(\"NEGATIVE CYCLE\")",
"+else:",
"+ for k in range(V):",
"+ if d[k] == float(\"inf\"):",
"+ print(\"INF\")",
"+ else:",
"+ print((d[k]))"
] | false | 0.038486 | 0.085387 | 0.450723 | [
"s574224786",
"s947320958"
] |
u810356688 | p02959 | python | s242304200 | s252153363 | 298 | 179 | 74,596 | 19,376 | Accepted | Accepted | 39.93 | def main():
import sys
input = sys.stdin.readline #文字列をsplit()しない場合s=s[:-2]が必要
n=int(eval(input()))
A=[int(_) for _ in input().split()]
sum_a=sum(A)
B=[int(_) for _ in input().split()]
for i in range(n):
s=max(B[i]-A[i],0)
A[i]-=min(A[i],B[i])
A[i+1]-=min(A[i+1],s)
print((sum_a-sum(A)))
if __name__=='__main__':
main() | from sys import stdin
def main():
input=stdin.readline
n=int(eval(input()))
A=[int(_) for _ in input().split()]
sum_a=sum(A)
B=[int(_) for _ in input().split()]
for i in range(n):
s=max(B[i]-A[i],0)
A[i]-=min(A[i],B[i])
A[i+1]-=min(A[i+1],s)
print((sum_a-sum(A)))
if __name__=='__main__':
main() | 16 | 16 | 388 | 361 | def main():
import sys
input = sys.stdin.readline # 文字列をsplit()しない場合s=s[:-2]が必要
n = int(eval(input()))
A = [int(_) for _ in input().split()]
sum_a = sum(A)
B = [int(_) for _ in input().split()]
for i in range(n):
s = max(B[i] - A[i], 0)
A[i] -= min(A[i], B[i])
A[i + 1] -= min(A[i + 1], s)
print((sum_a - sum(A)))
if __name__ == "__main__":
main()
| from sys import stdin
def main():
input = stdin.readline
n = int(eval(input()))
A = [int(_) for _ in input().split()]
sum_a = sum(A)
B = [int(_) for _ in input().split()]
for i in range(n):
s = max(B[i] - A[i], 0)
A[i] -= min(A[i], B[i])
A[i + 1] -= min(A[i + 1], s)
print((sum_a - sum(A)))
if __name__ == "__main__":
main()
| false | 0 | [
"+from sys import stdin",
"+",
"+",
"- import sys",
"-",
"- input = sys.stdin.readline # 文字列をsplit()しない場合s=s[:-2]が必要",
"+ input = stdin.readline"
] | false | 0.040256 | 0.03955 | 1.017863 | [
"s242304200",
"s252153363"
] |
u078042885 | p00071 | python | s466805530 | s904394157 | 30 | 20 | 7,608 | 7,604 | Accepted | Accepted | 33.33 | d=[[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]
def f(x,y,a):
a[y][x]='0'
for dx,dy in d:
if 0<=x+dx<8 and 0<=y+dy<8 and a[y+dy][x+dx]=='1':f(x+dx,y+dy,a)
return a
for i in range(int(eval(input()))):
print(('Data %d:'%(i+1)))
eval(input())
a=[list(eval(input())) for _ in [0]*8]
for x in f(int(eval(input()))-1,int(eval(input()))-1,a):print((''.join(x))) | def f(x,y,a):
a[y][x]='0'
for dx,dy in [[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]:
if 0<=x+dx<8 and 0<=y+dy<8 and a[y+dy][x+dx]=='1':f(x+dx,y+dy,a)
return a
for i in range(int(input())):
print('Data %d:'%(i+1))
input()
a=[list(input()) for _ in [0]*8]
[print(*x,sep='')for x in f(int(input())-1,int(input())-1,a)]
| 12 | 11 | 402 | 397 | d = [
[-3, 0],
[-2, 0],
[-1, 0],
[1, 0],
[2, 0],
[3, 0],
[0, -3],
[0, -2],
[0, -1],
[0, 1],
[0, 2],
[0, 3],
]
def f(x, y, a):
a[y][x] = "0"
for dx, dy in d:
if 0 <= x + dx < 8 and 0 <= y + dy < 8 and a[y + dy][x + dx] == "1":
f(x + dx, y + dy, a)
return a
for i in range(int(eval(input()))):
print(("Data %d:" % (i + 1)))
eval(input())
a = [list(eval(input())) for _ in [0] * 8]
for x in f(int(eval(input())) - 1, int(eval(input())) - 1, a):
print(("".join(x)))
| def f(x, y, a):
a[y][x] = "0"
for dx, dy in [
[-3, 0],
[-2, 0],
[-1, 0],
[1, 0],
[2, 0],
[3, 0],
[0, -3],
[0, -2],
[0, -1],
[0, 1],
[0, 2],
[0, 3],
]:
if 0 <= x + dx < 8 and 0 <= y + dy < 8 and a[y + dy][x + dx] == "1":
f(x + dx, y + dy, a)
return a
for i in range(int(input())):
print("Data %d:" % (i + 1))
input()
a = [list(input()) for _ in [0] * 8]
[print(*x, sep="") for x in f(int(input()) - 1, int(input()) - 1, a)]
| false | 8.333333 | [
"-d = [",
"- [-3, 0],",
"- [-2, 0],",
"- [-1, 0],",
"- [1, 0],",
"- [2, 0],",
"- [3, 0],",
"- [0, -3],",
"- [0, -2],",
"- [0, -1],",
"- [0, 1],",
"- [0, 2],",
"- [0, 3],",
"-]",
"-",
"-",
"- for dx, dy in d:",
"+ for dx, dy in [",
"+ [-3, 0],",
"+ [-2, 0],",
"+ [-1, 0],",
"+ [1, 0],",
"+ [2, 0],",
"+ [3, 0],",
"+ [0, -3],",
"+ [0, -2],",
"+ [0, -1],",
"+ [0, 1],",
"+ [0, 2],",
"+ [0, 3],",
"+ ]:",
"-for i in range(int(eval(input()))):",
"- print((\"Data %d:\" % (i + 1)))",
"- eval(input())",
"- a = [list(eval(input())) for _ in [0] * 8]",
"- for x in f(int(eval(input())) - 1, int(eval(input())) - 1, a):",
"- print((\"\".join(x)))",
"+for i in range(int(input())):",
"+ print(\"Data %d:\" % (i + 1))",
"+ input()",
"+ a = [list(input()) for _ in [0] * 8]",
"+ [print(*x, sep=\"\") for x in f(int(input()) - 1, int(input()) - 1, a)]"
] | false | 0.045487 | 0.049896 | 0.911631 | [
"s466805530",
"s904394157"
] |
u977389981 | p03317 | python | s833438109 | s971802150 | 52 | 46 | 13,880 | 13,880 | Accepted | Accepted | 11.54 | n, k = list(map(int, input().split()))
A = [int(i) for i in input().split()]
n -= k
count = 1
while n > 0:
n -= (k - 1)
count += 1
print(count) | n, k = list(map(int, input().split()))
A = [int(i) for i in input().split()]
ans = 1
ans += (n - k) // (k - 1)
if (n - k) % (k - 1) != 0:
ans += 1
print(ans) | 11 | 9 | 162 | 165 | n, k = list(map(int, input().split()))
A = [int(i) for i in input().split()]
n -= k
count = 1
while n > 0:
n -= k - 1
count += 1
print(count)
| n, k = list(map(int, input().split()))
A = [int(i) for i in input().split()]
ans = 1
ans += (n - k) // (k - 1)
if (n - k) % (k - 1) != 0:
ans += 1
print(ans)
| false | 18.181818 | [
"-n -= k",
"-count = 1",
"-while n > 0:",
"- n -= k - 1",
"- count += 1",
"-print(count)",
"+ans = 1",
"+ans += (n - k) // (k - 1)",
"+if (n - k) % (k - 1) != 0:",
"+ ans += 1",
"+print(ans)"
] | false | 0.045282 | 0.039172 | 1.155975 | [
"s833438109",
"s971802150"
] |
u150984829 | p00447 | python | s773622518 | s953822077 | 70 | 50 | 5,904 | 6,096 | Accepted | Accepted | 28.57 | def f(e):
a=list([*map(int,input().split())]for _ in range(int(e)))
s,t=a[0]
b={tuple(map(int,input().split()))for _ in range(int(input()))}
for x,y in b:
for u,v in a[1:]:
if(x+u-s,y+v-t)not in b:break
else:return print(x-s,y-t)
for e in iter(input,'0'):f(e)
| import operator
for e in iter(input,'0'):
target = [[*list(map(int,input().split()))]for _ in[0]*int(e)]
bx, by = min(target)
target = {(x - bx, y - by) for x, y in target}
max_tx = max(list(map(operator.itemgetter(0), target)))
b = {tuple(map(int,input().split()))for _ in[0]*int(eval(input()))}
max_sx = max(list(map(operator.itemgetter(0), b)))
lim_x = max_sx - max_tx
for x,y in b:
if x > lim_x:continue
for u,v in target:
if (x + u, y + v) not in b:break
else:
print((x - bx, y - by))
break
| 9 | 16 | 279 | 577 | def f(e):
a = list([*map(int, input().split())] for _ in range(int(e)))
s, t = a[0]
b = {tuple(map(int, input().split())) for _ in range(int(input()))}
for x, y in b:
for u, v in a[1:]:
if (x + u - s, y + v - t) not in b:
break
else:
return print(x - s, y - t)
for e in iter(input, "0"):
f(e)
| import operator
for e in iter(input, "0"):
target = [[*list(map(int, input().split()))] for _ in [0] * int(e)]
bx, by = min(target)
target = {(x - bx, y - by) for x, y in target}
max_tx = max(list(map(operator.itemgetter(0), target)))
b = {tuple(map(int, input().split())) for _ in [0] * int(eval(input()))}
max_sx = max(list(map(operator.itemgetter(0), b)))
lim_x = max_sx - max_tx
for x, y in b:
if x > lim_x:
continue
for u, v in target:
if (x + u, y + v) not in b:
break
else:
print((x - bx, y - by))
break
| false | 43.75 | [
"-def f(e):",
"- a = list([*map(int, input().split())] for _ in range(int(e)))",
"- s, t = a[0]",
"- b = {tuple(map(int, input().split())) for _ in range(int(input()))}",
"+import operator",
"+",
"+for e in iter(input, \"0\"):",
"+ target = [[*list(map(int, input().split()))] for _ in [0] * int(e)]",
"+ bx, by = min(target)",
"+ target = {(x - bx, y - by) for x, y in target}",
"+ max_tx = max(list(map(operator.itemgetter(0), target)))",
"+ b = {tuple(map(int, input().split())) for _ in [0] * int(eval(input()))}",
"+ max_sx = max(list(map(operator.itemgetter(0), b)))",
"+ lim_x = max_sx - max_tx",
"- for u, v in a[1:]:",
"- if (x + u - s, y + v - t) not in b:",
"+ if x > lim_x:",
"+ continue",
"+ for u, v in target:",
"+ if (x + u, y + v) not in b:",
"- return print(x - s, y - t)",
"-",
"-",
"-for e in iter(input, \"0\"):",
"- f(e)",
"+ print((x - bx, y - by))",
"+ break"
] | false | 0.037263 | 0.035569 | 1.047627 | [
"s773622518",
"s953822077"
] |
u282228874 | p03273 | python | s380604442 | s728665769 | 30 | 21 | 4,468 | 3,064 | Accepted | Accepted | 30 | h,w = map(int,input().split())
A = [input() for i in range(h)]
AnsH=[]
for i in range(h):
if "#" in A[i]:
AnsH.append(i)
AnsW=[]
for i in range(w):
c = 0
for j in range(h):
if A[j][i]=="#":
c = 1
if c == 1:
AnsW.append(i)
for i in AnsH:
for j in AnsW:
print(A[i][j],end="")
print()
| h,w = list(map(int,input().split()))
A = [list(eval(input())) for i in range(h)]
AH = []
AW = []
for i in range(h):
if '#' in A[i]:
AH.append(i)
for j in range(w):
flag = 0
for i in range(h):
if A[i][j]=='#':
flag = 1
if flag:
AW.append(j)
for i in AH:
res = []
for j in AW:
res.append(A[i][j])
print(("".join(res))) | 19 | 19 | 368 | 392 | h, w = map(int, input().split())
A = [input() for i in range(h)]
AnsH = []
for i in range(h):
if "#" in A[i]:
AnsH.append(i)
AnsW = []
for i in range(w):
c = 0
for j in range(h):
if A[j][i] == "#":
c = 1
if c == 1:
AnsW.append(i)
for i in AnsH:
for j in AnsW:
print(A[i][j], end="")
print()
| h, w = list(map(int, input().split()))
A = [list(eval(input())) for i in range(h)]
AH = []
AW = []
for i in range(h):
if "#" in A[i]:
AH.append(i)
for j in range(w):
flag = 0
for i in range(h):
if A[i][j] == "#":
flag = 1
if flag:
AW.append(j)
for i in AH:
res = []
for j in AW:
res.append(A[i][j])
print(("".join(res)))
| false | 0 | [
"-h, w = map(int, input().split())",
"-A = [input() for i in range(h)]",
"-AnsH = []",
"+h, w = list(map(int, input().split()))",
"+A = [list(eval(input())) for i in range(h)]",
"+AH = []",
"+AW = []",
"- AnsH.append(i)",
"-AnsW = []",
"-for i in range(w):",
"- c = 0",
"- for j in range(h):",
"- if A[j][i] == \"#\":",
"- c = 1",
"- if c == 1:",
"- AnsW.append(i)",
"-for i in AnsH:",
"- for j in AnsW:",
"- print(A[i][j], end=\"\")",
"- print()",
"+ AH.append(i)",
"+for j in range(w):",
"+ flag = 0",
"+ for i in range(h):",
"+ if A[i][j] == \"#\":",
"+ flag = 1",
"+ if flag:",
"+ AW.append(j)",
"+for i in AH:",
"+ res = []",
"+ for j in AW:",
"+ res.append(A[i][j])",
"+ print((\"\".join(res)))"
] | false | 0.077786 | 0.086109 | 0.90335 | [
"s380604442",
"s728665769"
] |
u614181788 | p02596 | python | s652902975 | s933965592 | 1,910 | 223 | 9,184 | 9,156 | Accepted | Accepted | 88.32 | k = int(eval(input()))
if k%2 == 0:
ans = -1
else:
x = 0
ans = -1
for i in range(10**6+1):
x += 7*pow(10, i, k)
x %= k
if x%k == 0:
ans = i+1
break
print(ans) | k = int(eval(input()))
x = 0
ans = -1
for i in range(10**6+1):
x = 10*x + 7
x %= k
if x == 0:
ans = i+1
break
print(ans)
| 13 | 10 | 228 | 152 | k = int(eval(input()))
if k % 2 == 0:
ans = -1
else:
x = 0
ans = -1
for i in range(10**6 + 1):
x += 7 * pow(10, i, k)
x %= k
if x % k == 0:
ans = i + 1
break
print(ans)
| k = int(eval(input()))
x = 0
ans = -1
for i in range(10**6 + 1):
x = 10 * x + 7
x %= k
if x == 0:
ans = i + 1
break
print(ans)
| false | 23.076923 | [
"-if k % 2 == 0:",
"- ans = -1",
"-else:",
"- x = 0",
"- ans = -1",
"- for i in range(10**6 + 1):",
"- x += 7 * pow(10, i, k)",
"- x %= k",
"- if x % k == 0:",
"- ans = i + 1",
"- break",
"+x = 0",
"+ans = -1",
"+for i in range(10**6 + 1):",
"+ x = 10 * x + 7",
"+ x %= k",
"+ if x == 0:",
"+ ans = i + 1",
"+ break"
] | false | 0.389507 | 0.144089 | 2.703234 | [
"s652902975",
"s933965592"
] |
u645250356 | p03363 | python | s346075320 | s252935630 | 1,490 | 867 | 42,172 | 111,668 | Accepted | Accepted | 41.81 | from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
a = inpl()
cntsum = list(itertools.accumulate(a))
cntcol = Counter(cntsum)
res = 0
for key in list(cntcol.keys()):
if key == 0:
res += cntcol[key]
if cntcol[key] >= 2:
res += conb(cntcol[key],2)
print(res) | from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
a = inpl()
cntsum = list(itertools.accumulate(a)) + [0]
cntcol = Counter(cntsum)
res = 0
for key in list(cntcol.keys()):
if cntcol[key] >= 2:
res += conb(cntcol[key],2)
print(res)
| 18 | 19 | 613 | 678 | from collections import Counter, defaultdict
import sys, heapq, bisect, math, itertools, string, queue
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def conb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
a = inpl()
cntsum = list(itertools.accumulate(a))
cntcol = Counter(cntsum)
res = 0
for key in list(cntcol.keys()):
if key == 0:
res += cntcol[key]
if cntcol[key] >= 2:
res += conb(cntcol[key], 2)
print(res)
| from collections import Counter, defaultdict
import sys, heapq, bisect, math, itertools, string, queue
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
def conb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
a = inpl()
cntsum = list(itertools.accumulate(a)) + [0]
cntcol = Counter(cntsum)
res = 0
for key in list(cntcol.keys()):
if cntcol[key] >= 2:
res += conb(cntcol[key], 2)
print(res)
| false | 5.263158 | [
"+sys.setrecursionlimit(10**8)",
"+def inpln(n):",
"+ return list(int(sys.stdin.readline()) for i in range(n))",
"+",
"+",
"-cntsum = list(itertools.accumulate(a))",
"+cntsum = list(itertools.accumulate(a)) + [0]",
"- if key == 0:",
"- res += cntcol[key]"
] | false | 0.038586 | 0.045189 | 0.853893 | [
"s346075320",
"s252935630"
] |
u145231176 | p02787 | python | s048179705 | s470864323 | 392 | 219 | 42,348 | 83,976 | Accepted | Accepted | 44.13 | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
H, N = getNM()
magic = []
for i in range(N):
a, b = getNM()
# AがATC,BがMP
magic.append([a, b])
dp = [float('inf')] * (H + 1)
dp[0] = 0
# HP = iを削るための最小MP
for i in range(1, H + 1):
for j in magic:
if i < j[0]:
dp[i] = min(dp[i], j[1])
else:
dp[i] = min(dp[i], dp[i - j[0]] + j[1])
print((dp[-1]))
| def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, M = getNM()
W = []
V = []
for i in range(M):
a, b = getNM()
W.append(b)
V.append(a)
# magicを重複ありで適当に組み合わせて合計Nを目指す
def knapsack_4(N, limit, weight, value):
dp = [float('inf')] * (limit + 1)
dp[0] = 0
for i in range(1, limit + 1):
for j in range(N):
if i < value[j]:
dp[i] = min(dp[i], weight[j])
else:
dp[i] = min(dp[i], dp[i - value[j]] + weight[j])
return dp[-1]
print((knapsack_4(M, N, W, V)))
| 41 | 72 | 930 | 1,850 | def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
H, N = getNM()
magic = []
for i in range(N):
a, b = getNM()
# AがATC,BがMP
magic.append([a, b])
dp = [float("inf")] * (H + 1)
dp[0] = 0
# HP = iを削るための最小MP
for i in range(1, H + 1):
for j in magic:
if i < j[0]:
dp[i] = min(dp[i], j[1])
else:
dp[i] = min(dp[i], dp[i - j[0]] + j[1])
print((dp[-1]))
| def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N, M = getNM()
W = []
V = []
for i in range(M):
a, b = getNM()
W.append(b)
V.append(a)
# magicを重複ありで適当に組み合わせて合計Nを目指す
def knapsack_4(N, limit, weight, value):
dp = [float("inf")] * (limit + 1)
dp[0] = 0
for i in range(1, limit + 1):
for j in range(N):
if i < value[j]:
dp[i] = min(dp[i], weight[j])
else:
dp[i] = min(dp[i], dp[i - value[j]] + weight[j])
return dp[-1]
print((knapsack_4(M, N, W, V)))
| false | 43.055556 | [
"+def rand_N(ran1, ran2):",
"+ return random.randint(ran1, ran2)",
"+",
"+",
"+def rand_List(ran1, ran2, rantime):",
"+ return [random.randint(ran1, ran2) for i in range(rantime)]",
"+",
"+",
"+def rand_ints_nodup(ran1, ran2, rantime):",
"+ ns = []",
"+ while len(ns) < rantime:",
"+ n = random.randint(ran1, ran2)",
"+ if not n in ns:",
"+ ns.append(n)",
"+ return sorted(ns)",
"+",
"+",
"+def rand_query(ran1, ran2, rantime):",
"+ r_query = []",
"+ while len(r_query) < rantime:",
"+ n_q = rand_ints_nodup(ran1, ran2, 2)",
"+ if not n_q in r_query:",
"+ r_query.append(n_q)",
"+ return sorted(r_query)",
"+",
"+",
"-import heapq",
"+from decimal import *",
"+from heapq import heapify, heappop, heappush",
"-import copy",
"-from operator import mul",
"+import random",
"+import string",
"+from copy import deepcopy",
"+from itertools import combinations, permutations, product",
"+from operator import mul, itemgetter",
"-H, N = getNM()",
"-magic = []",
"-for i in range(N):",
"+#############",
"+# Main Code #",
"+#############",
"+N, M = getNM()",
"+W = []",
"+V = []",
"+for i in range(M):",
"- # AがATC,BがMP",
"- magic.append([a, b])",
"-dp = [float(\"inf\")] * (H + 1)",
"-dp[0] = 0",
"-# HP = iを削るための最小MP",
"-for i in range(1, H + 1):",
"- for j in magic:",
"- if i < j[0]:",
"- dp[i] = min(dp[i], j[1])",
"- else:",
"- dp[i] = min(dp[i], dp[i - j[0]] + j[1])",
"-print((dp[-1]))",
"+ W.append(b)",
"+ V.append(a)",
"+# magicを重複ありで適当に組み合わせて合計Nを目指す",
"+def knapsack_4(N, limit, weight, value):",
"+ dp = [float(\"inf\")] * (limit + 1)",
"+ dp[0] = 0",
"+ for i in range(1, limit + 1):",
"+ for j in range(N):",
"+ if i < value[j]:",
"+ dp[i] = min(dp[i], weight[j])",
"+ else:",
"+ dp[i] = min(dp[i], dp[i - value[j]] + weight[j])",
"+ return dp[-1]",
"+",
"+",
"+print((knapsack_4(M, N, W, V)))"
] | false | 0.132749 | 0.07549 | 1.758491 | [
"s048179705",
"s470864323"
] |
u359358631 | p02712 | python | s233467694 | s568616141 | 80 | 65 | 72,668 | 61,860 | Accepted | Accepted | 18.75 | def main():
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if i % 3 != 0 and i % 5 != 0:
ans += i
print(ans)
if __name__ == "__main__":
main()
| def main():
n = int(input())
ans = n * (n + 1) // 2 - 3 * (n // 3) * (n // 3 + 1) // 2 - 5 * \
(n // 5) * (n // 5 + 1) // 2 + 15 * (n // 15) * (n // 15 + 1) // 2
print(ans)
if __name__ == "__main__":
main()
| 13 | 11 | 203 | 245 | def main():
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
if i % 3 != 0 and i % 5 != 0:
ans += i
print(ans)
if __name__ == "__main__":
main()
| def main():
n = int(input())
ans = (
n * (n + 1) // 2
- 3 * (n // 3) * (n // 3 + 1) // 2
- 5 * (n // 5) * (n // 5 + 1) // 2
+ 15 * (n // 15) * (n // 15 + 1) // 2
)
print(ans)
if __name__ == "__main__":
main()
| false | 15.384615 | [
"- n = int(eval(input()))",
"- ans = 0",
"- for i in range(1, n + 1):",
"- if i % 3 != 0 and i % 5 != 0:",
"- ans += i",
"+ n = int(input())",
"+ ans = (",
"+ n * (n + 1) // 2",
"+ - 3 * (n // 3) * (n // 3 + 1) // 2",
"+ - 5 * (n // 5) * (n // 5 + 1) // 2",
"+ + 15 * (n // 15) * (n // 15 + 1) // 2",
"+ )"
] | false | 0.090121 | 0.094504 | 0.953623 | [
"s233467694",
"s568616141"
] |
u879674287 | p03221 | python | s131809432 | s588505298 | 1,030 | 868 | 49,536 | 35,548 | Accepted | Accepted | 15.73 | debug = 0
"""
N: state num
M: city num
"""
if debug:
N = 2
m = 10
else:
(N, M) = list(map(int, input().split()))
if debug:
p_y_list = [
[1, 30]
,[1, 20]
,[1, 10]
,[1, 3]
,[2, 63]
,[2, 33]
,[2, 23]
,[3, 21]
,[3, 7]
]
city_id_list = []
for num, z in enumerate(range(M)):
# for num, (P, Y) in enumerate(p_y_list):
if not debug:
(P, Y) = list(map(int, input().split()))
city_id_list.append([Y, P, num])
city_id_list = sorted( city_id_list, key= lambda x: x[0])
state_cnt = {}
tmp_list = []
for (Y, P, num) in city_id_list:
if P not in list(state_cnt.keys()):
state_cnt[P] = 1
elif P in list(state_cnt.keys()):
state_cnt[P] += 1
tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
tmp_list.append([num, tmp_id])
for cid in sorted(tmp_list, key=lambda x: x[0]):
print((cid[1])) | N, M = list(map(int, input().split(' ')))
cities = []
for i in range(M):
p, y = list(map(int, input().split(' ')))
cities.append([p, y, i])
cities = sorted(cities, key=lambda x: x[1])
cities = sorted(cities, key=lambda x: x[0])
p = cities[0][0]
cnt = 1
for i in range(M):
if (cities[i][0] == p):
cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
cnt += 1
else:
p = cities[i][0]
cnt = 1
cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
cnt += 1
cities = sorted(cities, key=lambda x: x[2])
for i in range(M):
print((cities[i][3]))
| 52 | 27 | 994 | 624 | debug = 0
"""
N: state num
M: city num
"""
if debug:
N = 2
m = 10
else:
(N, M) = list(map(int, input().split()))
if debug:
p_y_list = [
[1, 30],
[1, 20],
[1, 10],
[1, 3],
[2, 63],
[2, 33],
[2, 23],
[3, 21],
[3, 7],
]
city_id_list = []
for num, z in enumerate(range(M)):
# for num, (P, Y) in enumerate(p_y_list):
if not debug:
(P, Y) = list(map(int, input().split()))
city_id_list.append([Y, P, num])
city_id_list = sorted(city_id_list, key=lambda x: x[0])
state_cnt = {}
tmp_list = []
for (Y, P, num) in city_id_list:
if P not in list(state_cnt.keys()):
state_cnt[P] = 1
elif P in list(state_cnt.keys()):
state_cnt[P] += 1
tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
tmp_list.append([num, tmp_id])
for cid in sorted(tmp_list, key=lambda x: x[0]):
print((cid[1]))
| N, M = list(map(int, input().split(" ")))
cities = []
for i in range(M):
p, y = list(map(int, input().split(" ")))
cities.append([p, y, i])
cities = sorted(cities, key=lambda x: x[1])
cities = sorted(cities, key=lambda x: x[0])
p = cities[0][0]
cnt = 1
for i in range(M):
if cities[i][0] == p:
cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
cnt += 1
else:
p = cities[i][0]
cnt = 1
cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
cnt += 1
cities = sorted(cities, key=lambda x: x[2])
for i in range(M):
print((cities[i][3]))
| false | 48.076923 | [
"-debug = 0",
"-\"\"\"",
"-N: state num",
"-M: city num",
"-\"\"\"",
"-if debug:",
"- N = 2",
"- m = 10",
"-else:",
"- (N, M) = list(map(int, input().split()))",
"-if debug:",
"- p_y_list = [",
"- [1, 30],",
"- [1, 20],",
"- [1, 10],",
"- [1, 3],",
"- [2, 63],",
"- [2, 33],",
"- [2, 23],",
"- [3, 21],",
"- [3, 7],",
"- ]",
"-city_id_list = []",
"-for num, z in enumerate(range(M)):",
"- # for num, (P, Y) in enumerate(p_y_list):",
"- if not debug:",
"- (P, Y) = list(map(int, input().split()))",
"- city_id_list.append([Y, P, num])",
"-city_id_list = sorted(city_id_list, key=lambda x: x[0])",
"-state_cnt = {}",
"-tmp_list = []",
"-for (Y, P, num) in city_id_list:",
"- if P not in list(state_cnt.keys()):",
"- state_cnt[P] = 1",
"- elif P in list(state_cnt.keys()):",
"- state_cnt[P] += 1",
"- tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)",
"- tmp_list.append([num, tmp_id])",
"-for cid in sorted(tmp_list, key=lambda x: x[0]):",
"- print((cid[1]))",
"+N, M = list(map(int, input().split(\" \")))",
"+cities = []",
"+for i in range(M):",
"+ p, y = list(map(int, input().split(\" \")))",
"+ cities.append([p, y, i])",
"+cities = sorted(cities, key=lambda x: x[1])",
"+cities = sorted(cities, key=lambda x: x[0])",
"+p = cities[0][0]",
"+cnt = 1",
"+for i in range(M):",
"+ if cities[i][0] == p:",
"+ cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))",
"+ cnt += 1",
"+ else:",
"+ p = cities[i][0]",
"+ cnt = 1",
"+ cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))",
"+ cnt += 1",
"+cities = sorted(cities, key=lambda x: x[2])",
"+for i in range(M):",
"+ print((cities[i][3]))"
] | false | 0.040853 | 0.041348 | 0.988016 | [
"s131809432",
"s588505298"
] |
u285891772 | p02730 | python | s982482274 | s636173662 | 156 | 38 | 13,680 | 5,196 | Accepted | Accepted | 75.64 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
S = eval(input())
T = S[:len(S)//2]
U = S[len(S)//2+1:]
c = 3
def kaibun(L, c):
for i in range(len(L)//2):
if L[i] != L[-(i+1)]:
c -= 1
print("No")
exit()
kaibun(S, c)
kaibun(T, c)
kaibun(U, c)
if c == 3:
print("Yes")
else:
print("No") | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
S = eval(input())
N = len(S)
S2 = S[:N//2]
S3 = S[(N+3)//2-1:]
if S == S[::-1] and S2 == S2[::-1] and S3 == S3[::-1]:
print("Yes")
else:
print("No") | 41 | 29 | 1,088 | 938 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
import numpy as np
S = eval(input())
T = S[: len(S) // 2]
U = S[len(S) // 2 + 1 :]
c = 3
def kaibun(L, c):
for i in range(len(L) // 2):
if L[i] != L[-(i + 1)]:
c -= 1
print("No")
exit()
kaibun(S, c)
kaibun(T, c)
kaibun(U, c)
if c == 3:
print("Yes")
else:
print("No")
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
S = eval(input())
N = len(S)
S2 = S[: N // 2]
S3 = S[(N + 3) // 2 - 1 :]
if S == S[::-1] and S2 == S2[::-1] and S3 == S3[::-1]:
print("Yes")
else:
print("No")
| false | 29.268293 | [
"-import numpy as np",
"-",
"-T = S[: len(S) // 2]",
"-U = S[len(S) // 2 + 1 :]",
"-c = 3",
"-",
"-",
"-def kaibun(L, c):",
"- for i in range(len(L) // 2):",
"- if L[i] != L[-(i + 1)]:",
"- c -= 1",
"- print(\"No\")",
"- exit()",
"-",
"-",
"-kaibun(S, c)",
"-kaibun(T, c)",
"-kaibun(U, c)",
"-if c == 3:",
"+N = len(S)",
"+S2 = S[: N // 2]",
"+S3 = S[(N + 3) // 2 - 1 :]",
"+if S == S[::-1] and S2 == S2[::-1] and S3 == S3[::-1]:"
] | false | 0.105456 | 0.037182 | 2.836218 | [
"s982482274",
"s636173662"
] |
u207241407 | p03971 | python | s335165937 | s946133645 | 62 | 42 | 5,108 | 5,108 | Accepted | Accepted | 32.26 | n, a, b = list(map(int, input().split()))
s = eval(input())
ans = ["No"] * n
success = 0
foreigner = 0
for i in range(n):
if s[i] == "a":
ans[i] = "Yes"
success += 1
elif s[i] == "b" and foreigner < b:
ans[i] = "Yes"
success += 1
foreigner += 1
if success == a + b:
break
print(("\n".join(ans))) | import sys
def main():
n, a, b = list(map(int, sys.stdin.readline().split()))
s = sys.stdin.readline().rstrip()
ans = ["No"] * n
success = 0
foreigner = 0
for i in range(n):
if s[i] == "a":
ans[i] = "Yes"
success += 1
elif s[i] == "b" and foreigner < b:
ans[i] = "Yes"
success += 1
foreigner += 1
if success == a + b:
break
print(("\n".join(ans)))
return
if __name__ == "__main__":
main() | 19 | 28 | 362 | 546 | n, a, b = list(map(int, input().split()))
s = eval(input())
ans = ["No"] * n
success = 0
foreigner = 0
for i in range(n):
if s[i] == "a":
ans[i] = "Yes"
success += 1
elif s[i] == "b" and foreigner < b:
ans[i] = "Yes"
success += 1
foreigner += 1
if success == a + b:
break
print(("\n".join(ans)))
| import sys
def main():
n, a, b = list(map(int, sys.stdin.readline().split()))
s = sys.stdin.readline().rstrip()
ans = ["No"] * n
success = 0
foreigner = 0
for i in range(n):
if s[i] == "a":
ans[i] = "Yes"
success += 1
elif s[i] == "b" and foreigner < b:
ans[i] = "Yes"
success += 1
foreigner += 1
if success == a + b:
break
print(("\n".join(ans)))
return
if __name__ == "__main__":
main()
| false | 32.142857 | [
"-n, a, b = list(map(int, input().split()))",
"-s = eval(input())",
"-ans = [\"No\"] * n",
"-success = 0",
"-foreigner = 0",
"-for i in range(n):",
"- if s[i] == \"a\":",
"- ans[i] = \"Yes\"",
"- success += 1",
"- elif s[i] == \"b\" and foreigner < b:",
"- ans[i] = \"Yes\"",
"- success += 1",
"- foreigner += 1",
"- if success == a + b:",
"- break",
"-print((\"\\n\".join(ans)))",
"+import sys",
"+",
"+",
"+def main():",
"+ n, a, b = list(map(int, sys.stdin.readline().split()))",
"+ s = sys.stdin.readline().rstrip()",
"+ ans = [\"No\"] * n",
"+ success = 0",
"+ foreigner = 0",
"+ for i in range(n):",
"+ if s[i] == \"a\":",
"+ ans[i] = \"Yes\"",
"+ success += 1",
"+ elif s[i] == \"b\" and foreigner < b:",
"+ ans[i] = \"Yes\"",
"+ success += 1",
"+ foreigner += 1",
"+ if success == a + b:",
"+ break",
"+ print((\"\\n\".join(ans)))",
"+ return",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.036589 | 0.036136 | 1.012523 | [
"s335165937",
"s946133645"
] |
u539692012 | p02689 | python | s351034349 | s816865296 | 265 | 141 | 20,140 | 44,096 | Accepted | Accepted | 46.79 | n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = [1] * n
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
if h[a] <= h[b]:
ans[a] = 0
if h[b] <= h[a]:
ans[b] = 0
print((sum(ans)))
| n,*t=list(map(int,open(0).read().split()))
r=[0]+[1]*n
for a,b in zip(t[n+1::2],t[n+2::2]):r[a]&=t[a]>t[b];r[b]&=t[b]>t[a]
print((sum(r))) | 12 | 4 | 268 | 133 | n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = [1] * n
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
if h[a] <= h[b]:
ans[a] = 0
if h[b] <= h[a]:
ans[b] = 0
print((sum(ans)))
| n, *t = list(map(int, open(0).read().split()))
r = [0] + [1] * n
for a, b in zip(t[n + 1 :: 2], t[n + 2 :: 2]):
r[a] &= t[a] > t[b]
r[b] &= t[b] > t[a]
print((sum(r)))
| false | 66.666667 | [
"-n, m = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-ans = [1] * n",
"-for _ in range(m):",
"- a, b = list(map(int, input().split()))",
"- a -= 1",
"- b -= 1",
"- if h[a] <= h[b]:",
"- ans[a] = 0",
"- if h[b] <= h[a]:",
"- ans[b] = 0",
"-print((sum(ans)))",
"+n, *t = list(map(int, open(0).read().split()))",
"+r = [0] + [1] * n",
"+for a, b in zip(t[n + 1 :: 2], t[n + 2 :: 2]):",
"+ r[a] &= t[a] > t[b]",
"+ r[b] &= t[b] > t[a]",
"+print((sum(r)))"
] | false | 0.040874 | 0.040748 | 1.003093 | [
"s351034349",
"s816865296"
] |
u994988729 | p03017 | python | s243504743 | s740425289 | 86 | 18 | 3,572 | 3,572 | Accepted | Accepted | 79.07 | def cd(a, b, c, d, s):
for i in range(b, d + 1):
if s[i] + s[i + 1] == "##":
return "No"
for i in range(a, c + 1):
if s[i] + s[i + 1] == "##":
return "No"
return "Yes"
def dc(a, b, c, d, s):
flag = False
for i in range(b, d + 1):
if s[i] + s[i + 1] == "##":
return "No"
if s[i - 1] + s[i] + s[i + 1] == "...":
flag = True
for i in range(a, c + 1):
if s[i] + s[i + 1] == "##":
return "No"
if flag:
return "Yes"
else:
return "No"
if __name__ == "__main__":
n, a, b, c, d = list(map(int, input().split()))
a -= 1
b -= 1
c -= 1
d -= 1
s = eval(input())+"##"
if c < d:
ans = cd(a, b, c, d, s)
else:
ans = dc(a, b, c, d, s)
print(ans)
| N, A, B, C, D = list(map(int, input().split()))
S = eval(input())
if "##" in S[B: D - 1]:
print("No")
exit()
elif "##" in S[A: C - 1]:
print("No")
exit()
if D < C:
if not "..." in S[B - 2: D + 1]:
print("No")
exit()
print("Yes") | 39 | 16 | 860 | 270 | def cd(a, b, c, d, s):
for i in range(b, d + 1):
if s[i] + s[i + 1] == "##":
return "No"
for i in range(a, c + 1):
if s[i] + s[i + 1] == "##":
return "No"
return "Yes"
def dc(a, b, c, d, s):
flag = False
for i in range(b, d + 1):
if s[i] + s[i + 1] == "##":
return "No"
if s[i - 1] + s[i] + s[i + 1] == "...":
flag = True
for i in range(a, c + 1):
if s[i] + s[i + 1] == "##":
return "No"
if flag:
return "Yes"
else:
return "No"
if __name__ == "__main__":
n, a, b, c, d = list(map(int, input().split()))
a -= 1
b -= 1
c -= 1
d -= 1
s = eval(input()) + "##"
if c < d:
ans = cd(a, b, c, d, s)
else:
ans = dc(a, b, c, d, s)
print(ans)
| N, A, B, C, D = list(map(int, input().split()))
S = eval(input())
if "##" in S[B : D - 1]:
print("No")
exit()
elif "##" in S[A : C - 1]:
print("No")
exit()
if D < C:
if not "..." in S[B - 2 : D + 1]:
print("No")
exit()
print("Yes")
| false | 58.974359 | [
"-def cd(a, b, c, d, s):",
"- for i in range(b, d + 1):",
"- if s[i] + s[i + 1] == \"##\":",
"- return \"No\"",
"- for i in range(a, c + 1):",
"- if s[i] + s[i + 1] == \"##\":",
"- return \"No\"",
"- return \"Yes\"",
"-",
"-",
"-def dc(a, b, c, d, s):",
"- flag = False",
"- for i in range(b, d + 1):",
"- if s[i] + s[i + 1] == \"##\":",
"- return \"No\"",
"- if s[i - 1] + s[i] + s[i + 1] == \"...\":",
"- flag = True",
"- for i in range(a, c + 1):",
"- if s[i] + s[i + 1] == \"##\":",
"- return \"No\"",
"- if flag:",
"- return \"Yes\"",
"- else:",
"- return \"No\"",
"-",
"-",
"-if __name__ == \"__main__\":",
"- n, a, b, c, d = list(map(int, input().split()))",
"- a -= 1",
"- b -= 1",
"- c -= 1",
"- d -= 1",
"- s = eval(input()) + \"##\"",
"- if c < d:",
"- ans = cd(a, b, c, d, s)",
"- else:",
"- ans = dc(a, b, c, d, s)",
"- print(ans)",
"+N, A, B, C, D = list(map(int, input().split()))",
"+S = eval(input())",
"+if \"##\" in S[B : D - 1]:",
"+ print(\"No\")",
"+ exit()",
"+elif \"##\" in S[A : C - 1]:",
"+ print(\"No\")",
"+ exit()",
"+if D < C:",
"+ if not \"...\" in S[B - 2 : D + 1]:",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.036856 | 0.035539 | 1.037043 | [
"s243504743",
"s740425289"
] |
u994988729 | p02936 | python | s797215505 | s521328105 | 1,921 | 1,300 | 69,992 | 104,472 | Accepted | Accepted | 32.33 | n,q=map(int,input().split())
link=[[] for _ in range(n)]
for _ in range(n-1):
a,b=map(int,input().split())
link[a-1].append(b-1)
under=[[] for i in range(n)]
for i in range(n-1, -1, -1):
l=link[i]
for j in l:
under[i].append(j)
#for i in link:
# print(i)
#print()
#for i in under:
# print(i)
ans=[0]*n
for _ in range(q):
p,x=map(int,input().split())
ans[p-1]+=x
for i in range(n):
for j in under[i]:
ans[j]+=ans[i]
for i in ans:
print("{} ".format(i), end="")
print()
| from collections import deque
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
query = [list(map(int, input().split())) for _ in range(Q)]
score = [0] * (N + 1)
for n, p in query:
score[n] += p
seen = [0] * (N + 1)
seen[1] = 1
node = deque([1])
while node:
s = node.popleft()
for t in edge[s]:
if not seen[t]:
seen[t] = 1
score[t] += score[s]
node.append(t)
print((*score[1:]))
| 30 | 28 | 555 | 623 | n, q = map(int, input().split())
link = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
link[a - 1].append(b - 1)
under = [[] for i in range(n)]
for i in range(n - 1, -1, -1):
l = link[i]
for j in l:
under[i].append(j)
# for i in link:
# print(i)
# print()
# for i in under:
# print(i)
ans = [0] * n
for _ in range(q):
p, x = map(int, input().split())
ans[p - 1] += x
for i in range(n):
for j in under[i]:
ans[j] += ans[i]
for i in ans:
print("{} ".format(i), end="")
print()
| from collections import deque
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a].append(b)
edge[b].append(a)
query = [list(map(int, input().split())) for _ in range(Q)]
score = [0] * (N + 1)
for n, p in query:
score[n] += p
seen = [0] * (N + 1)
seen[1] = 1
node = deque([1])
while node:
s = node.popleft()
for t in edge[s]:
if not seen[t]:
seen[t] = 1
score[t] += score[s]
node.append(t)
print((*score[1:]))
| false | 6.666667 | [
"-n, q = map(int, input().split())",
"-link = [[] for _ in range(n)]",
"-for _ in range(n - 1):",
"- a, b = map(int, input().split())",
"- link[a - 1].append(b - 1)",
"-under = [[] for i in range(n)]",
"-for i in range(n - 1, -1, -1):",
"- l = link[i]",
"- for j in l:",
"- under[i].append(j)",
"-# for i in link:",
"-# print(i)",
"-# print()",
"-# for i in under:",
"-# print(i)",
"-ans = [0] * n",
"-for _ in range(q):",
"- p, x = map(int, input().split())",
"- ans[p - 1] += x",
"-for i in range(n):",
"- for j in under[i]:",
"- ans[j] += ans[i]",
"-for i in ans:",
"- print(\"{} \".format(i), end=\"\")",
"-print()",
"+from collections import deque",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+N, Q = list(map(int, input().split()))",
"+edge = [[] for _ in range(N + 1)]",
"+for _ in range(N - 1):",
"+ a, b = list(map(int, input().split()))",
"+ edge[a].append(b)",
"+ edge[b].append(a)",
"+query = [list(map(int, input().split())) for _ in range(Q)]",
"+score = [0] * (N + 1)",
"+for n, p in query:",
"+ score[n] += p",
"+seen = [0] * (N + 1)",
"+seen[1] = 1",
"+node = deque([1])",
"+while node:",
"+ s = node.popleft()",
"+ for t in edge[s]:",
"+ if not seen[t]:",
"+ seen[t] = 1",
"+ score[t] += score[s]",
"+ node.append(t)",
"+print((*score[1:]))"
] | false | 0.052868 | 0.036045 | 1.466735 | [
"s797215505",
"s521328105"
] |
u054514819 | p03426 | python | s877514159 | s122007966 | 758 | 250 | 116,488 | 105,568 | Accepted | Accepted | 67.02 | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
H, W, d = mapint()
As = [list(mapint()) for _ in range(H)]
Q = int(eval(input()))
from collections import defaultdict
from itertools import accumulate
from bisect import bisect_left
dic = defaultdict(list)
for h in range(H):
for w in range(W):
a = As[h][w]
dic[a%d].append((a, h, w))
cost_dic = {}
for m in list(dic.keys()):
dic[m].sort()
sa, sh, sw = dic[m][0]
cost_dic[m] = [0]
for a, h, w in dic[m][1:]:
cost = abs(h-sh)+abs(w-sw)
cost_dic[m].append(cost)
sa, sh, sw = a, h, w
cost_dic[m] = list(accumulate(cost_dic[m]))
for _ in range(Q):
l, r = mapint()
sidx = bisect_left(dic[l%d], (l, 0, 0))
eidx = bisect_left(dic[l%d], (r, 0, 0))
print((cost_dic[l%d][eidx]-cost_dic[l%d][sidx])) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
H, W, d = mapint()
As = [list(mapint()) for _ in range(H)]
Q = int(eval(input()))
from collections import defaultdict
dic = {}
for h in range(H):
for w in range(W):
a = As[h][w]
dic[a] = (h, w)
cost_dic = defaultdict(int)
for i in range(d+1, H*W+1):
oh, ow = dic[i-d]
h, w = dic[i]
cost_dic[i] = cost_dic[i-d]+abs(h-oh)+abs(w-ow)
for _ in range(Q):
l, r = mapint()
print((cost_dic[r]-cost_dic[l])) | 34 | 25 | 926 | 593 | import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
H, W, d = mapint()
As = [list(mapint()) for _ in range(H)]
Q = int(eval(input()))
from collections import defaultdict
from itertools import accumulate
from bisect import bisect_left
dic = defaultdict(list)
for h in range(H):
for w in range(W):
a = As[h][w]
dic[a % d].append((a, h, w))
cost_dic = {}
for m in list(dic.keys()):
dic[m].sort()
sa, sh, sw = dic[m][0]
cost_dic[m] = [0]
for a, h, w in dic[m][1:]:
cost = abs(h - sh) + abs(w - sw)
cost_dic[m].append(cost)
sa, sh, sw = a, h, w
cost_dic[m] = list(accumulate(cost_dic[m]))
for _ in range(Q):
l, r = mapint()
sidx = bisect_left(dic[l % d], (l, 0, 0))
eidx = bisect_left(dic[l % d], (r, 0, 0))
print((cost_dic[l % d][eidx] - cost_dic[l % d][sidx]))
| import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
H, W, d = mapint()
As = [list(mapint()) for _ in range(H)]
Q = int(eval(input()))
from collections import defaultdict
dic = {}
for h in range(H):
for w in range(W):
a = As[h][w]
dic[a] = (h, w)
cost_dic = defaultdict(int)
for i in range(d + 1, H * W + 1):
oh, ow = dic[i - d]
h, w = dic[i]
cost_dic[i] = cost_dic[i - d] + abs(h - oh) + abs(w - ow)
for _ in range(Q):
l, r = mapint()
print((cost_dic[r] - cost_dic[l]))
| false | 26.470588 | [
"-from itertools import accumulate",
"-from bisect import bisect_left",
"-dic = defaultdict(list)",
"+dic = {}",
"- dic[a % d].append((a, h, w))",
"-cost_dic = {}",
"-for m in list(dic.keys()):",
"- dic[m].sort()",
"- sa, sh, sw = dic[m][0]",
"- cost_dic[m] = [0]",
"- for a, h, w in dic[m][1:]:",
"- cost = abs(h - sh) + abs(w - sw)",
"- cost_dic[m].append(cost)",
"- sa, sh, sw = a, h, w",
"- cost_dic[m] = list(accumulate(cost_dic[m]))",
"+ dic[a] = (h, w)",
"+cost_dic = defaultdict(int)",
"+for i in range(d + 1, H * W + 1):",
"+ oh, ow = dic[i - d]",
"+ h, w = dic[i]",
"+ cost_dic[i] = cost_dic[i - d] + abs(h - oh) + abs(w - ow)",
"- sidx = bisect_left(dic[l % d], (l, 0, 0))",
"- eidx = bisect_left(dic[l % d], (r, 0, 0))",
"- print((cost_dic[l % d][eidx] - cost_dic[l % d][sidx]))",
"+ print((cost_dic[r] - cost_dic[l]))"
] | false | 0.041524 | 0.055599 | 0.746838 | [
"s877514159",
"s122007966"
] |
u707808519 | p02641 | python | s640094974 | s531880167 | 22 | 20 | 9,176 | 9,168 | Accepted | Accepted | 9.09 | x, n = list(map(int, input().split()))
p = [int(y) for y in input().split()]
for i in range(200):
if x-i not in p:
print((x-i))
break
if x+i not in p:
print((x+i))
break | x, n = list(map(int, input().split()))
p = {int(i) for i in input().split()}
for i in range(55):
if x-i not in p:
print((x-i))
break
if x+i not in p:
print((x+i))
break | 10 | 10 | 209 | 209 | x, n = list(map(int, input().split()))
p = [int(y) for y in input().split()]
for i in range(200):
if x - i not in p:
print((x - i))
break
if x + i not in p:
print((x + i))
break
| x, n = list(map(int, input().split()))
p = {int(i) for i in input().split()}
for i in range(55):
if x - i not in p:
print((x - i))
break
if x + i not in p:
print((x + i))
break
| false | 0 | [
"-p = [int(y) for y in input().split()]",
"-for i in range(200):",
"+p = {int(i) for i in input().split()}",
"+for i in range(55):"
] | false | 0.032409 | 0.041991 | 0.771802 | [
"s640094974",
"s531880167"
] |
u254871849 | p03353 | python | s567186658 | s885893620 | 34 | 31 | 4,464 | 4,464 | Accepted | Accepted | 8.82 | import sys
s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)
def main():
res = set()
for l in range(n):
for r in range(l, min(l+k, n)):
res.add(s[l:r+1])
return sorted(res)[k-1]
if __name__ == '__main__':
ans = main()
print(ans) | import sys
s, k = sys.stdin.read().split()
k = int(k)
def main():
cand = set()
for j in range(1, k + 1):
for i in range(len(s) - j + 1):
cand.add(s[i:i+j])
print((sorted(cand)[k-1]))
if __name__ == '__main__':
main() | 17 | 14 | 322 | 267 | import sys
s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)
def main():
res = set()
for l in range(n):
for r in range(l, min(l + k, n)):
res.add(s[l : r + 1])
return sorted(res)[k - 1]
if __name__ == "__main__":
ans = main()
print(ans)
| import sys
s, k = sys.stdin.read().split()
k = int(k)
def main():
cand = set()
for j in range(1, k + 1):
for i in range(len(s) - j + 1):
cand.add(s[i : i + j])
print((sorted(cand)[k - 1]))
if __name__ == "__main__":
main()
| false | 17.647059 | [
"-s = sys.stdin.readline().rstrip()",
"-k = int(sys.stdin.readline().rstrip())",
"-n = len(s)",
"+s, k = sys.stdin.read().split()",
"+k = int(k)",
"- res = set()",
"- for l in range(n):",
"- for r in range(l, min(l + k, n)):",
"- res.add(s[l : r + 1])",
"- return sorted(res)[k - 1]",
"+ cand = set()",
"+ for j in range(1, k + 1):",
"+ for i in range(len(s) - j + 1):",
"+ cand.add(s[i : i + j])",
"+ print((sorted(cand)[k - 1]))",
"- ans = main()",
"- print(ans)",
"+ main()"
] | false | 0.037927 | 0.039292 | 0.965259 | [
"s567186658",
"s885893620"
] |
u402629484 | p03111 | python | s220385824 | s486168825 | 249 | 72 | 3,064 | 3,064 | Accepted | Accepted | 71.08 | N,A,B,C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = 1<<20
score = INF
import itertools
for ms in itertools.product(list(range(-1,3)), repeat=N):
lens = [0]*3
tmp_score = -30
for i, group in enumerate(ms):
if group>=0:
lens[group] += l[i]
tmp_score += 10
if all(lens):
score = min(score, tmp_score + abs(lens[0]-A)+abs(lens[1]-B)+abs(lens[2]-C))
print(score)
| def main():
N,A,B,C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = 1<<20
def perm(n, a, b, c):
if n == N:
if all([a, b, c]):
return abs(A-a)+abs(B-b)+abs(C-c)-30
else:
return INF
return min(
perm(n+1,a,b,c),
perm(n+1,a+l[n],b,c)+10,
perm(n+1,a,b+l[n],c)+10,
perm(n+1,a,b,c+l[n])+10
)
print((perm(0,0,0,0)))
main() | 18 | 22 | 455 | 524 | N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = 1 << 20
score = INF
import itertools
for ms in itertools.product(list(range(-1, 3)), repeat=N):
lens = [0] * 3
tmp_score = -30
for i, group in enumerate(ms):
if group >= 0:
lens[group] += l[i]
tmp_score += 10
if all(lens):
score = min(
score, tmp_score + abs(lens[0] - A) + abs(lens[1] - B) + abs(lens[2] - C)
)
print(score)
| def main():
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = 1 << 20
def perm(n, a, b, c):
if n == N:
if all([a, b, c]):
return abs(A - a) + abs(B - b) + abs(C - c) - 30
else:
return INF
return min(
perm(n + 1, a, b, c),
perm(n + 1, a + l[n], b, c) + 10,
perm(n + 1, a, b + l[n], c) + 10,
perm(n + 1, a, b, c + l[n]) + 10,
)
print((perm(0, 0, 0, 0)))
main()
| false | 18.181818 | [
"-N, A, B, C = list(map(int, input().split()))",
"-l = [int(eval(input())) for _ in range(N)]",
"-INF = 1 << 20",
"-score = INF",
"-import itertools",
"+def main():",
"+ N, A, B, C = list(map(int, input().split()))",
"+ l = [int(eval(input())) for _ in range(N)]",
"+ INF = 1 << 20",
"-for ms in itertools.product(list(range(-1, 3)), repeat=N):",
"- lens = [0] * 3",
"- tmp_score = -30",
"- for i, group in enumerate(ms):",
"- if group >= 0:",
"- lens[group] += l[i]",
"- tmp_score += 10",
"- if all(lens):",
"- score = min(",
"- score, tmp_score + abs(lens[0] - A) + abs(lens[1] - B) + abs(lens[2] - C)",
"+ def perm(n, a, b, c):",
"+ if n == N:",
"+ if all([a, b, c]):",
"+ return abs(A - a) + abs(B - b) + abs(C - c) - 30",
"+ else:",
"+ return INF",
"+ return min(",
"+ perm(n + 1, a, b, c),",
"+ perm(n + 1, a + l[n], b, c) + 10,",
"+ perm(n + 1, a, b + l[n], c) + 10,",
"+ perm(n + 1, a, b, c + l[n]) + 10,",
"-print(score)",
"+",
"+ print((perm(0, 0, 0, 0)))",
"+",
"+",
"+main()"
] | false | 0.274589 | 0.077786 | 3.53007 | [
"s220385824",
"s486168825"
] |
u691018832 | p02687 | python | s053441601 | s614933009 | 64 | 21 | 61,516 | 9,032 | Accepted | Accepted | 67.19 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
s = readline().rstrip().decode()
if s[1] == 'B':
print('ARC')
else:
print('ABC')
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
s = read().rstrip().decode()
if s[1] == 'B':
print('ARC')
else:
print('ABC')
| 11 | 11 | 247 | 243 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
s = readline().rstrip().decode()
if s[1] == "B":
print("ARC")
else:
print("ABC")
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
s = read().rstrip().decode()
if s[1] == "B":
print("ARC")
else:
print("ABC")
| false | 0 | [
"-s = readline().rstrip().decode()",
"+s = read().rstrip().decode()"
] | false | 0.0412 | 0.040429 | 1.019073 | [
"s053441601",
"s614933009"
] |
u163320134 | p02948 | python | s618138469 | s676853381 | 780 | 696 | 44,996 | 43,664 | Accepted | Accepted | 10.77 | import heapq
n,m=list(map(int,input().split()))
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,reverse=True,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
q=[]
ans=0
pos=0
while 1:
a,b=arr[pos]
if a>m:
break
if a==arr[pos+1][0]:
heapq.heappush(q,-b)
else:
heapq.heappush(q,-b)
ans-=heapq.heappop(q)
pos+=1
print(ans) | import heapq
n,m=list(map(int,input().split()))
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,key=lambda x:x[0])
q=[]
ans=0
pos=0
while 1:
a,b=arr[pos]
if a>m:
break
if a==arr[pos+1][0]:
heapq.heappush(q,-b)
else:
heapq.heappush(q,-b)
ans-=heapq.heappop(q)
pos+=1
print(ans) | 22 | 21 | 439 | 391 | import heapq
n, m = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(n)]
arr2 = [[i, 0] for i in range(1, m + 2)]
arr.extend(arr2)
arr = sorted(arr, reverse=True, key=lambda x: x[1])
arr = sorted(arr, key=lambda x: x[0])
q = []
ans = 0
pos = 0
while 1:
a, b = arr[pos]
if a > m:
break
if a == arr[pos + 1][0]:
heapq.heappush(q, -b)
else:
heapq.heappush(q, -b)
ans -= heapq.heappop(q)
pos += 1
print(ans)
| import heapq
n, m = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(n)]
arr2 = [[i, 0] for i in range(1, m + 2)]
arr.extend(arr2)
arr = sorted(arr, key=lambda x: x[0])
q = []
ans = 0
pos = 0
while 1:
a, b = arr[pos]
if a > m:
break
if a == arr[pos + 1][0]:
heapq.heappush(q, -b)
else:
heapq.heappush(q, -b)
ans -= heapq.heappop(q)
pos += 1
print(ans)
| false | 4.545455 | [
"-arr = sorted(arr, reverse=True, key=lambda x: x[1])"
] | false | 0.03594 | 0.097476 | 0.368712 | [
"s618138469",
"s676853381"
] |
u680851063 | p03712 | python | s242794380 | s968070590 | 19 | 17 | 3,060 | 3,060 | Accepted | Accepted | 10.53 | h,w = list(map(int, input().split()))
l = [eval(input()) for _ in range(h)]
l.insert(0,'#'*(w+2))
l.append('#'*(w+2))
for i in range(1,h+1):
x = list(l.pop(i))
x.insert(0,'#')
x.append('#')
l.insert(i,''.join(x))
for j in range(h+2):
print((l[j]))
| h,w = list(map(int, input().split()))
l = [eval(input()) for _ in range(h)]
l.insert(0,'#'*(w+2))
l.append('#'*(w+2))
for i in range(1,h+1):
l[i] = '#' +l[i] + '#'
for j in range(h+2):
print((l[j]))
| 13 | 10 | 268 | 204 | h, w = list(map(int, input().split()))
l = [eval(input()) for _ in range(h)]
l.insert(0, "#" * (w + 2))
l.append("#" * (w + 2))
for i in range(1, h + 1):
x = list(l.pop(i))
x.insert(0, "#")
x.append("#")
l.insert(i, "".join(x))
for j in range(h + 2):
print((l[j]))
| h, w = list(map(int, input().split()))
l = [eval(input()) for _ in range(h)]
l.insert(0, "#" * (w + 2))
l.append("#" * (w + 2))
for i in range(1, h + 1):
l[i] = "#" + l[i] + "#"
for j in range(h + 2):
print((l[j]))
| false | 23.076923 | [
"- x = list(l.pop(i))",
"- x.insert(0, \"#\")",
"- x.append(\"#\")",
"- l.insert(i, \"\".join(x))",
"+ l[i] = \"#\" + l[i] + \"#\""
] | false | 0.038021 | 0.039049 | 0.973661 | [
"s242794380",
"s968070590"
] |
u391875425 | p03137 | python | s502400613 | s467021709 | 234 | 113 | 22,980 | 13,960 | Accepted | Accepted | 51.71 | import numpy as np
n,m = list(map(int,input().split()))
x = np.array(list(map(int, input().split())))
if n>= m:
print((0))
exit()
x.sort()
xd = sorted(np.diff(x))
print((sum(xd[:m-n]))) | n, m = list(map(int,input().split()))
x = sorted(list(map(int, input().split())))
if n >= m:
print((0))
exit()
xd = []
for i in range(m-1):
xd.append(x[i+1]-x[i])
xd.sort()
print((sum(xd[:m-n]))) | 9 | 10 | 191 | 206 | import numpy as np
n, m = list(map(int, input().split()))
x = np.array(list(map(int, input().split())))
if n >= m:
print((0))
exit()
x.sort()
xd = sorted(np.diff(x))
print((sum(xd[: m - n])))
| n, m = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
if n >= m:
print((0))
exit()
xd = []
for i in range(m - 1):
xd.append(x[i + 1] - x[i])
xd.sort()
print((sum(xd[: m - n])))
| false | 10 | [
"-import numpy as np",
"-",
"-x = np.array(list(map(int, input().split())))",
"+x = sorted(list(map(int, input().split())))",
"-x.sort()",
"-xd = sorted(np.diff(x))",
"+xd = []",
"+for i in range(m - 1):",
"+ xd.append(x[i + 1] - x[i])",
"+xd.sort()"
] | false | 0.254856 | 0.036184 | 7.043323 | [
"s502400613",
"s467021709"
] |
u455809703 | p02708 | python | s556594961 | s942599623 | 59 | 20 | 9,164 | 9,116 | Accepted | Accepted | 66.1 | N, K = list(map(int, input().split()))
ans = 0
for i in range(K, N+2):
ans += i*(N-i+1)+1
print((ans%1000000007)) | N, K = list(map(int, input().split()))
print((int(((N*(N+1)*(N+2) - K*(K-1)*(3*N-2*K+4))/6 + N - K + 2)%1000000007))) | 6 | 3 | 115 | 112 | N, K = list(map(int, input().split()))
ans = 0
for i in range(K, N + 2):
ans += i * (N - i + 1) + 1
print((ans % 1000000007))
| N, K = list(map(int, input().split()))
print(
(
int(
(
(N * (N + 1) * (N + 2) - K * (K - 1) * (3 * N - 2 * K + 4)) / 6
+ N
- K
+ 2
)
% 1000000007
)
)
)
| false | 50 | [
"-ans = 0",
"-for i in range(K, N + 2):",
"- ans += i * (N - i + 1) + 1",
"-print((ans % 1000000007))",
"+print(",
"+ (",
"+ int(",
"+ (",
"+ (N * (N + 1) * (N + 2) - K * (K - 1) * (3 * N - 2 * K + 4)) / 6",
"+ + N",
"+ - K",
"+ + 2",
"+ )",
"+ % 1000000007",
"+ )",
"+ )",
"+)"
] | false | 0.054736 | 0.086921 | 0.629717 | [
"s556594961",
"s942599623"
] |
u138013242 | p03295 | python | s558924439 | s266683537 | 774 | 662 | 60,376 | 56,964 | Accepted | Accepted | 14.47 | """
区間スケジューリング
終端で降順にソートすれば良い
"""
n, m=list(map(int, input().split()))
hope=[]
for i in range(m):
a, b=list(map(int, input().split()))
hope.append((a, b))
hope.sort(reverse=True, key=lambda x: x[0])
hope.sort(reverse=True, key=lambda x: x[1])
ans=0
for i in range(m-1):
if i==0:
target=hope[i][0]
if target<hope[i+1][1]:
if target<hope[i+1][0]:
target=hope[i+1][0]
else:
ans=ans+1
target=hope[i+1][0]
print((ans+1))
| """
区間スケジューリング
終端で降順にソートすれば良い
最適解は,貪欲法で,1つ次の区間を通るように串刺すこと
終端で降順にソートしているので,1本で区間を刺せる条件はi<jのとき,a[i]<b[j]
さらにその後,刺せる範囲が狭まる場合(a[i]>b[i])は,狭めて次の区間に行く
"""
n, m=list(map(int, input().split()))
hope=[]
for i in range(m):
a, b=list(map(int, input().split()))
hope.append((a, b))
hope.sort(reverse=True, key=lambda x: x[1])
ans=0
for i in range(m-1):
if i==0:
target=hope[i][0]
if target<hope[i+1][1]:
if target<hope[i+1][0]:
target=hope[i+1][0]
else:
ans=ans+1
target=hope[i+1][0]
print((ans+1))
| 22 | 24 | 487 | 560 | """
区間スケジューリング
終端で降順にソートすれば良い
"""
n, m = list(map(int, input().split()))
hope = []
for i in range(m):
a, b = list(map(int, input().split()))
hope.append((a, b))
hope.sort(reverse=True, key=lambda x: x[0])
hope.sort(reverse=True, key=lambda x: x[1])
ans = 0
for i in range(m - 1):
if i == 0:
target = hope[i][0]
if target < hope[i + 1][1]:
if target < hope[i + 1][0]:
target = hope[i + 1][0]
else:
ans = ans + 1
target = hope[i + 1][0]
print((ans + 1))
| """
区間スケジューリング
終端で降順にソートすれば良い
最適解は,貪欲法で,1つ次の区間を通るように串刺すこと
終端で降順にソートしているので,1本で区間を刺せる条件はi<jのとき,a[i]<b[j]
さらにその後,刺せる範囲が狭まる場合(a[i]>b[i])は,狭めて次の区間に行く
"""
n, m = list(map(int, input().split()))
hope = []
for i in range(m):
a, b = list(map(int, input().split()))
hope.append((a, b))
hope.sort(reverse=True, key=lambda x: x[1])
ans = 0
for i in range(m - 1):
if i == 0:
target = hope[i][0]
if target < hope[i + 1][1]:
if target < hope[i + 1][0]:
target = hope[i + 1][0]
else:
ans = ans + 1
target = hope[i + 1][0]
print((ans + 1))
| false | 8.333333 | [
"+最適解は,貪欲法で,1つ次の区間を通るように串刺すこと",
"+終端で降順にソートしているので,1本で区間を刺せる条件はi<jのとき,a[i]<b[j]",
"+さらにその後,刺せる範囲が狭まる場合(a[i]>b[i])は,狭めて次の区間に行く",
"-hope.sort(reverse=True, key=lambda x: x[0])"
] | false | 0.170495 | 0.034967 | 4.875925 | [
"s558924439",
"s266683537"
] |
u761320129 | p03372 | python | s847536638 | s553129817 | 623 | 303 | 32,704 | 45,428 | Accepted | Accepted | 51.36 | N,C = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(N)]
cumsumr = [0]
cummaxr = [0]
cummaxr2 = [0]
px = 0
for x,v in src:
cumsumr.append(cumsumr[-1] + v-(x-px))
cummaxr.append(max(cummaxr[-1], cumsumr[-1]))
cummaxr2.append(max(cummaxr2[-1], cumsumr[-1]-x))
px = x
cumsuml = [0]
cummaxl = [0]
cummaxl2 = [0]
px = C
for x,v in src[::-1]:
cumsuml.append(cumsuml[-1] + v-(px-x))
cummaxl.append(max(cummaxl[-1], cumsuml[-1]))
cummaxl2.append(max(cummaxl2[-1], cumsuml[-1]-(C-x)))
px = x
ans = max(cummaxr[-1], cummaxl[-1])
for i in range(N):
ans = max(ans, cummaxr2[i] + cummaxl[N-i])
ans = max(ans, cummaxl2[i] + cummaxr[N-i])
print(ans) | import sys
input = sys.stdin.readline
N,C = list(map(int,input().split()))
XV = [tuple(map(int,input().split())) for i in range(N)]
rcum1 = [0]
rcum2 = [0]
rcummx = [0]
px = 0
for x,v in XV:
d = x - px
rcum1.append(rcum1[-1] + v - d)
rcum2.append(rcum2[-1] + v - 2*d)
rcummx.append(max(rcummx[-1], rcum1[-1]))
px = x
lcum1 = [0]
lcum2 = [0]
lcummx = [0]
px = C
for x,v in reversed(XV):
d = px - x
lcum1.append(lcum1[-1] + v - d)
lcum2.append(lcum2[-1] + v - 2*d)
lcummx.append(max(lcummx[-1], lcum1[-1]))
px = x
lcum1.reverse()
lcum2.reverse()
lcummx.reverse()
ans = max(rcummx[-1], lcummx[0])
for i in range(N+1):
a = rcum2[i] + lcummx[i]
b = lcum2[i] + rcummx[i]
ans = max(ans, a, b)
print(ans) | 28 | 36 | 736 | 780 | N, C = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
cumsumr = [0]
cummaxr = [0]
cummaxr2 = [0]
px = 0
for x, v in src:
cumsumr.append(cumsumr[-1] + v - (x - px))
cummaxr.append(max(cummaxr[-1], cumsumr[-1]))
cummaxr2.append(max(cummaxr2[-1], cumsumr[-1] - x))
px = x
cumsuml = [0]
cummaxl = [0]
cummaxl2 = [0]
px = C
for x, v in src[::-1]:
cumsuml.append(cumsuml[-1] + v - (px - x))
cummaxl.append(max(cummaxl[-1], cumsuml[-1]))
cummaxl2.append(max(cummaxl2[-1], cumsuml[-1] - (C - x)))
px = x
ans = max(cummaxr[-1], cummaxl[-1])
for i in range(N):
ans = max(ans, cummaxr2[i] + cummaxl[N - i])
ans = max(ans, cummaxl2[i] + cummaxr[N - i])
print(ans)
| import sys
input = sys.stdin.readline
N, C = list(map(int, input().split()))
XV = [tuple(map(int, input().split())) for i in range(N)]
rcum1 = [0]
rcum2 = [0]
rcummx = [0]
px = 0
for x, v in XV:
d = x - px
rcum1.append(rcum1[-1] + v - d)
rcum2.append(rcum2[-1] + v - 2 * d)
rcummx.append(max(rcummx[-1], rcum1[-1]))
px = x
lcum1 = [0]
lcum2 = [0]
lcummx = [0]
px = C
for x, v in reversed(XV):
d = px - x
lcum1.append(lcum1[-1] + v - d)
lcum2.append(lcum2[-1] + v - 2 * d)
lcummx.append(max(lcummx[-1], lcum1[-1]))
px = x
lcum1.reverse()
lcum2.reverse()
lcummx.reverse()
ans = max(rcummx[-1], lcummx[0])
for i in range(N + 1):
a = rcum2[i] + lcummx[i]
b = lcum2[i] + rcummx[i]
ans = max(ans, a, b)
print(ans)
| false | 22.222222 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-src = [tuple(map(int, input().split())) for i in range(N)]",
"-cumsumr = [0]",
"-cummaxr = [0]",
"-cummaxr2 = [0]",
"+XV = [tuple(map(int, input().split())) for i in range(N)]",
"+rcum1 = [0]",
"+rcum2 = [0]",
"+rcummx = [0]",
"-for x, v in src:",
"- cumsumr.append(cumsumr[-1] + v - (x - px))",
"- cummaxr.append(max(cummaxr[-1], cumsumr[-1]))",
"- cummaxr2.append(max(cummaxr2[-1], cumsumr[-1] - x))",
"+for x, v in XV:",
"+ d = x - px",
"+ rcum1.append(rcum1[-1] + v - d)",
"+ rcum2.append(rcum2[-1] + v - 2 * d)",
"+ rcummx.append(max(rcummx[-1], rcum1[-1]))",
"-cumsuml = [0]",
"-cummaxl = [0]",
"-cummaxl2 = [0]",
"+lcum1 = [0]",
"+lcum2 = [0]",
"+lcummx = [0]",
"-for x, v in src[::-1]:",
"- cumsuml.append(cumsuml[-1] + v - (px - x))",
"- cummaxl.append(max(cummaxl[-1], cumsuml[-1]))",
"- cummaxl2.append(max(cummaxl2[-1], cumsuml[-1] - (C - x)))",
"+for x, v in reversed(XV):",
"+ d = px - x",
"+ lcum1.append(lcum1[-1] + v - d)",
"+ lcum2.append(lcum2[-1] + v - 2 * d)",
"+ lcummx.append(max(lcummx[-1], lcum1[-1]))",
"-ans = max(cummaxr[-1], cummaxl[-1])",
"-for i in range(N):",
"- ans = max(ans, cummaxr2[i] + cummaxl[N - i])",
"- ans = max(ans, cummaxl2[i] + cummaxr[N - i])",
"+lcum1.reverse()",
"+lcum2.reverse()",
"+lcummx.reverse()",
"+ans = max(rcummx[-1], lcummx[0])",
"+for i in range(N + 1):",
"+ a = rcum2[i] + lcummx[i]",
"+ b = lcum2[i] + rcummx[i]",
"+ ans = max(ans, a, b)"
] | false | 0.054141 | 0.063253 | 0.855953 | [
"s847536638",
"s553129817"
] |
u741801763 | p01314 | python | s537196587 | s579346266 | 310 | 190 | 7,796 | 7,640 | Accepted | Accepted | 38.71 | if __name__ == "__main__":
while True:
n = int(eval(input()))
if n ==0:break
nline = [i for i in range(1,n+1)]
count = 0
for i in range(n):
for j in range(i+1,n):
if sum(nline[i:j]) > n:break
if sum(nline[i:j]) == n:count +=1
print(count) | if __name__ == "__main__":
while True:
n = int(eval(input()))
if n ==0:break
count = 0
for i in range(1,n):
for j in range(i+1,n):
sum = (i+j)*(j-i+1)/2
if sum> n:break
if sum == n:count +=1
print(count) | 12 | 12 | 341 | 313 | if __name__ == "__main__":
while True:
n = int(eval(input()))
if n == 0:
break
nline = [i for i in range(1, n + 1)]
count = 0
for i in range(n):
for j in range(i + 1, n):
if sum(nline[i:j]) > n:
break
if sum(nline[i:j]) == n:
count += 1
print(count)
| if __name__ == "__main__":
while True:
n = int(eval(input()))
if n == 0:
break
count = 0
for i in range(1, n):
for j in range(i + 1, n):
sum = (i + j) * (j - i + 1) / 2
if sum > n:
break
if sum == n:
count += 1
print(count)
| false | 0 | [
"- nline = [i for i in range(1, n + 1)]",
"- for i in range(n):",
"+ for i in range(1, n):",
"- if sum(nline[i:j]) > n:",
"+ sum = (i + j) * (j - i + 1) / 2",
"+ if sum > n:",
"- if sum(nline[i:j]) == n:",
"+ if sum == n:"
] | false | 0.09366 | 0.091974 | 1.018322 | [
"s537196587",
"s579346266"
] |
u968166680 | p02901 | python | s958052222 | s997421842 | 116 | 107 | 74,396 | 68,496 | Accepted | Accepted | 7.76 | 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()))
A = [0] * M
C = [0] * M
for i in range(M):
A[i], b = list(map(int, readline().split()))
C[i] = sum(1 << (int(s) - 1) for s in readline().split())
dp = [INF] * (1 << N)
dp[0] = 0
for bit in range(1 << N):
for a, c in zip(A, C):
if dp[bit & ~c] < INF:
dp[bit] = min(dp[bit], dp[bit & ~c] + a)
ans = dp[(1 << N) - 1]
if ans < INF:
print(ans)
else:
print((-1))
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()))
A = [0] * M
C = [0] * M
for i in range(M):
A[i], b = list(map(int, readline().split()))
C[i] = ~sum(1 << (int(s) - 1) for s in readline().split())
dp = [INF] * (1 << N)
dp[0] = 0
for bit in range(1 << N):
for a, c in zip(A, C):
if dp[bit & c] < INF:
dp[bit] = min(dp[bit], dp[bit & c] + a)
ans = dp[(1 << N) - 1]
if ans < INF:
print(ans)
else:
print((-1))
return
if __name__ == '__main__':
main()
| 35 | 35 | 752 | 751 | 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()))
A = [0] * M
C = [0] * M
for i in range(M):
A[i], b = list(map(int, readline().split()))
C[i] = sum(1 << (int(s) - 1) for s in readline().split())
dp = [INF] * (1 << N)
dp[0] = 0
for bit in range(1 << N):
for a, c in zip(A, C):
if dp[bit & ~c] < INF:
dp[bit] = min(dp[bit], dp[bit & ~c] + a)
ans = dp[(1 << N) - 1]
if ans < INF:
print(ans)
else:
print((-1))
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()))
A = [0] * M
C = [0] * M
for i in range(M):
A[i], b = list(map(int, readline().split()))
C[i] = ~sum(1 << (int(s) - 1) for s in readline().split())
dp = [INF] * (1 << N)
dp[0] = 0
for bit in range(1 << N):
for a, c in zip(A, C):
if dp[bit & c] < INF:
dp[bit] = min(dp[bit], dp[bit & c] + a)
ans = dp[(1 << N) - 1]
if ans < INF:
print(ans)
else:
print((-1))
return
if __name__ == "__main__":
main()
| false | 0 | [
"- C[i] = sum(1 << (int(s) - 1) for s in readline().split())",
"+ C[i] = ~sum(1 << (int(s) - 1) for s in readline().split())",
"- if dp[bit & ~c] < INF:",
"- dp[bit] = min(dp[bit], dp[bit & ~c] + a)",
"+ if dp[bit & c] < INF:",
"+ dp[bit] = min(dp[bit], dp[bit & c] + a)"
] | false | 0.042925 | 0.041269 | 1.040112 | [
"s958052222",
"s997421842"
] |
u509739538 | p03373 | python | s977757747 | s228199161 | 354 | 138 | 3,952 | 4,080 | Accepted | Accepted | 61.02 | import math
import queue
from collections import defaultdict
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChar():
return eval(input())
def readChars():
return input().split()
def factorization(n):
res = []
if n%2==0:
res.append(2)
for i in range(3,math.floor(n//2)+1,2):
if n%i==0:
c = 0
for j in res:
if i%j==0:
c=1
if c==0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c=0
z=n
while 1:
if z%i==0:
c+=1
z/=i
else:
break
res.append([i,c])
return res
def fact(n):#階乗
ans = 1
m=n
for _i in range(n-1):
ans*=m
m-=1
return ans
def comb(n,r):#コンビネーション
if n<r:
return 0
l = min(r,n-r)
m=n
u=1
for _i in range(l):
u*=m
m-=1
return u//fact(l)
def printQueue(q):
r=qb
ans=[0]*r.qsize()
for i in range(r.qsize()-1,-1,-1):
ans[i] = r.get()
print(ans)
def dq():
return queue.deque()
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x): # root
if self.parents[x]<0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y = y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def size(self,x):
return -1*self.parents[self.find(x)]
def same(self,x,y):
return self.find(x)==self.find(y)
def members(self,x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
x = 1
zero = "0"*n
ans = []
ans.append([0]*n)
for i in range(2**n-1):
ans.append(list([int(x) for x in list((zero+bin(x)[2:])[-1*n:])]))
x+=1
return ans;
def arrsSum(a1,a2):
for i in range(len(a1)):
a1[i]+=a2[i]
return a1
a,b,c,x,y = readInts()
ans = 1000000000000000000
for i in range(0,x+1):
B = max(y-(x-i),0)
AB = max(2*(x-i),0)
money = i*a+B*b+AB*c
ans = min(ans,money)
for i in range(0,y+1):
A = max(x-(y-i),0)
AB = max(2*(y-i),0)
money = A*a+b*i+AB*c
ans = min(ans,money)
for i in range(0,max(x,y)*2+1,2):
A = max(x - i//2,0)
B = max(y - i//2,0)
money = A*a+B*b+i*c
ans = min(ans,money)
print(ans)
| import math
import queue
from collections import defaultdict
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChar():
return eval(input())
def readChars():
return input().split()
def factorization(n):
res = []
if n%2==0:
res.append(2)
for i in range(3,math.floor(n//2)+1,2):
if n%i==0:
c = 0
for j in res:
if i%j==0:
c=1
if c==0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c=0
z=n
while 1:
if z%i==0:
c+=1
z/=i
else:
break
res.append([i,c])
return res
def fact(n):#階乗
ans = 1
m=n
for _i in range(n-1):
ans*=m
m-=1
return ans
def comb(n,r):#コンビネーション
if n<r:
return 0
l = min(r,n-r)
m=n
u=1
for _i in range(l):
u*=m
m-=1
return u//fact(l)
def printQueue(q):
r=qb
ans=[0]*r.qsize()
for i in range(r.qsize()-1,-1,-1):
ans[i] = r.get()
print(ans)
def dq():
return queue.deque()
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x): # root
if self.parents[x]<0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y = y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def size(self,x):
return -1*self.parents[self.find(x)]
def same(self,x,y):
return self.find(x)==self.find(y)
def members(self,x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
x = 1
zero = "0"*n
ans = []
ans.append([0]*n)
for i in range(2**n-1):
ans.append(list([int(x) for x in list((zero+bin(x)[2:])[-1*n:])]))
x+=1
return ans;
def arrsSum(a1,a2):
for i in range(len(a1)):
a1[i]+=a2[i]
return a1
a,b,c,x,y = readInts()
ans = 1000000000000000000
for i in range(0,max(x,y)*2+1,2):
A = max(x - i//2,0)
B = max(y - i//2,0)
money = A*a+B*b+i*c
ans = min(ans,money)
print(ans)
| 144 | 134 | 2,616 | 2,390 | import math
import queue
from collections import defaultdict
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChar():
return eval(input())
def readChars():
return input().split()
def factorization(n):
res = []
if n % 2 == 0:
res.append(2)
for i in range(3, math.floor(n // 2) + 1, 2):
if n % i == 0:
c = 0
for j in res:
if i % j == 0:
c = 1
if c == 0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c = 0
z = n
while 1:
if z % i == 0:
c += 1
z /= i
else:
break
res.append([i, c])
return res
def fact(n): # 階乗
ans = 1
m = n
for _i in range(n - 1):
ans *= m
m -= 1
return ans
def comb(n, r): # コンビネーション
if n < r:
return 0
l = min(r, n - r)
m = n
u = 1
for _i in range(l):
u *= m
m -= 1
return u // fact(l)
def printQueue(q):
r = qb
ans = [0] * r.qsize()
for i in range(r.qsize() - 1, -1, -1):
ans[i] = r.get()
print(ans)
def dq():
return queue.deque()
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x): # root
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -1 * self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n): # ビット全探索
x = 1
zero = "0" * n
ans = []
ans.append([0] * n)
for i in range(2**n - 1):
ans.append(list([int(x) for x in list((zero + bin(x)[2:])[-1 * n :])]))
x += 1
return ans
def arrsSum(a1, a2):
for i in range(len(a1)):
a1[i] += a2[i]
return a1
a, b, c, x, y = readInts()
ans = 1000000000000000000
for i in range(0, x + 1):
B = max(y - (x - i), 0)
AB = max(2 * (x - i), 0)
money = i * a + B * b + AB * c
ans = min(ans, money)
for i in range(0, y + 1):
A = max(x - (y - i), 0)
AB = max(2 * (y - i), 0)
money = A * a + b * i + AB * c
ans = min(ans, money)
for i in range(0, max(x, y) * 2 + 1, 2):
A = max(x - i // 2, 0)
B = max(y - i // 2, 0)
money = A * a + B * b + i * c
ans = min(ans, money)
print(ans)
| import math
import queue
from collections import defaultdict
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChar():
return eval(input())
def readChars():
return input().split()
def factorization(n):
res = []
if n % 2 == 0:
res.append(2)
for i in range(3, math.floor(n // 2) + 1, 2):
if n % i == 0:
c = 0
for j in res:
if i % j == 0:
c = 1
if c == 0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c = 0
z = n
while 1:
if z % i == 0:
c += 1
z /= i
else:
break
res.append([i, c])
return res
def fact(n): # 階乗
ans = 1
m = n
for _i in range(n - 1):
ans *= m
m -= 1
return ans
def comb(n, r): # コンビネーション
if n < r:
return 0
l = min(r, n - r)
m = n
u = 1
for _i in range(l):
u *= m
m -= 1
return u // fact(l)
def printQueue(q):
r = qb
ans = [0] * r.qsize()
for i in range(r.qsize() - 1, -1, -1):
ans[i] = r.get()
print(ans)
def dq():
return queue.deque()
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x): # root
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -1 * self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n): # ビット全探索
x = 1
zero = "0" * n
ans = []
ans.append([0] * n)
for i in range(2**n - 1):
ans.append(list([int(x) for x in list((zero + bin(x)[2:])[-1 * n :])]))
x += 1
return ans
def arrsSum(a1, a2):
for i in range(len(a1)):
a1[i] += a2[i]
return a1
a, b, c, x, y = readInts()
ans = 1000000000000000000
for i in range(0, max(x, y) * 2 + 1, 2):
A = max(x - i // 2, 0)
B = max(y - i // 2, 0)
money = A * a + B * b + i * c
ans = min(ans, money)
print(ans)
| false | 6.944444 | [
"-for i in range(0, x + 1):",
"- B = max(y - (x - i), 0)",
"- AB = max(2 * (x - i), 0)",
"- money = i * a + B * b + AB * c",
"- ans = min(ans, money)",
"-for i in range(0, y + 1):",
"- A = max(x - (y - i), 0)",
"- AB = max(2 * (y - i), 0)",
"- money = A * a + b * i + AB * c",
"- ans = min(ans, money)"
] | false | 0.046773 | 0.060694 | 0.770627 | [
"s977757747",
"s228199161"
] |
u968166680 | p02814 | python | s148548390 | s969096007 | 559 | 68 | 16,104 | 16,108 | Accepted | Accepted | 87.84 | import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def lcm(a, b):
return a // gcd(a, b) * b
def main():
N, M, *A = list(map(int, read().split()))
A = [a // 2 for a in A]
power = 1
while all(a % 2 == 0 for a in A):
A = [a // 2 for a in A]
power *= 2
if any(a % 2 == 0 for a in A):
print((0))
return
l = 1
for a in A:
l = lcm(l, a)
if l > M:
print((0))
return
l *= power
ans = (M + l) // (2 * l)
print(ans)
return
if __name__ == '__main__':
main()
| import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def lcm(a, b):
return a * b // gcd(a, b)
def main():
N, M, *A = list(map(int, read().split()))
A = list({a // 2 for a in A})
power = 1
while all(a % 2 == 0 for a in A):
A = [a // 2 for a in A]
power *= 2
if any(a % 2 == 0 for a in A):
print((0))
return
l = 1
for a in A:
l = lcm(l, a)
if l > M:
print((0))
return
l *= power
ans = (M + l) // (2 * l)
print(ans)
return
if __name__ == '__main__':
main()
| 42 | 42 | 727 | 733 | import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def lcm(a, b):
return a // gcd(a, b) * b
def main():
N, M, *A = list(map(int, read().split()))
A = [a // 2 for a in A]
power = 1
while all(a % 2 == 0 for a in A):
A = [a // 2 for a in A]
power *= 2
if any(a % 2 == 0 for a in A):
print((0))
return
l = 1
for a in A:
l = lcm(l, a)
if l > M:
print((0))
return
l *= power
ans = (M + l) // (2 * l)
print(ans)
return
if __name__ == "__main__":
main()
| import sys
from fractions import gcd
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def lcm(a, b):
return a * b // gcd(a, b)
def main():
N, M, *A = list(map(int, read().split()))
A = list({a // 2 for a in A})
power = 1
while all(a % 2 == 0 for a in A):
A = [a // 2 for a in A]
power *= 2
if any(a % 2 == 0 for a in A):
print((0))
return
l = 1
for a in A:
l = lcm(l, a)
if l > M:
print((0))
return
l *= power
ans = (M + l) // (2 * l)
print(ans)
return
if __name__ == "__main__":
main()
| false | 0 | [
"- return a // gcd(a, b) * b",
"+ return a * b // gcd(a, b)",
"- A = [a // 2 for a in A]",
"+ A = list({a // 2 for a in A})"
] | false | 0.085876 | 0.052243 | 1.64376 | [
"s148548390",
"s969096007"
] |
u013629972 | p03013 | python | s822625615 | s962987502 | 480 | 364 | 54,940 | 79,316 | Accepted | Accepted | 24.17 | # -*- coding: utf-8 -*-
import sys
mod = 10 ** 9 + 7
def get_nums(n):
res = [0 for _ in range(n)]
for i in range(n):
res[i] = int(eval(input()))
return res
def get_numbers():
return list(map(int, input().split()))
n, m = get_numbers()
a = set(get_nums(m))
dp = [0 for _ in range(n + 1)]
dp[0] = 1
if 1 not in a:
dp[1] = 1
for i in range(2, n + 1):
if i not in a:
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= mod
print((dp[-1]))
| import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
# f = open('C_input_29.txt')
# lines = f.readlines()
# f.close()
# N, M = map(int, lines[0].split())
# A = []
# for line in lines[1:]:
# A.append(int(line))
N, M = LI()
A = set([_I() for i in range(M)])
# if M != 0:
# # 連続した壊れた段がある場合は0
# B = [i for i in A]
# B.remove(B[0])
# B.append(10**15+100)
# diffs = [b - a for a, b in zip(A,B)]
# # print(diffs)
# if any(i == 1 for i in diffs):
# # 隣同士なので0
# print(0)
# exit()
# print('hoge')
"""
考え方
xにたどり着く通りは、x-1とx-2段目にたどり着く通りの合計
dp
3が障害のとき
1へは1通り
2へは0からと1からの2通り
3へは0通り
4へは2からの2通りと、3からの0通りで2通り
5へは3からの0通りと4からの2通りで2通り
6へは4からの2通りと5からの2通りで4通り
"""
# dp = {}
dp = [0 for i in range(N+1)]
# print('fua')
dp[0] = 1
dp[1] = 1 if 1 not in A else 0
# [dp.update({i: (dp[i-1] + dp[i-2])%mod}) if i not in A else dp.update({i: 0}) for i in range(2, N+1)]
for i in range(2, N+1):
# print(i)
# i段目までの通りを計算する
if i not in A:
# i段目が障害のときは0になっているので飛ばす
dp[i] = dp[i-1] + dp[i-2]
dp[i] %= mod
print(dp[N])
| 30 | 66 | 494 | 1,799 | # -*- coding: utf-8 -*-
import sys
mod = 10**9 + 7
def get_nums(n):
res = [0 for _ in range(n)]
for i in range(n):
res[i] = int(eval(input()))
return res
def get_numbers():
return list(map(int, input().split()))
n, m = get_numbers()
a = set(get_nums(m))
dp = [0 for _ in range(n + 1)]
dp[0] = 1
if 1 not in a:
dp[1] = 1
for i in range(2, n + 1):
if i not in a:
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= mod
print((dp[-1]))
| import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def _I():
return int(sys.stdin.readline())
def _F():
return float(sys.stdin.readline())
def _pf(s):
return print(s, flush=True)
# f = open('C_input_29.txt')
# lines = f.readlines()
# f.close()
# N, M = map(int, lines[0].split())
# A = []
# for line in lines[1:]:
# A.append(int(line))
N, M = LI()
A = set([_I() for i in range(M)])
# if M != 0:
# # 連続した壊れた段がある場合は0
# B = [i for i in A]
# B.remove(B[0])
# B.append(10**15+100)
# diffs = [b - a for a, b in zip(A,B)]
# # print(diffs)
# if any(i == 1 for i in diffs):
# # 隣同士なので0
# print(0)
# exit()
# print('hoge')
"""
考え方
xにたどり着く通りは、x-1とx-2段目にたどり着く通りの合計
dp
3が障害のとき
1へは1通り
2へは0からと1からの2通り
3へは0通り
4へは2からの2通りと、3からの0通りで2通り
5へは3からの0通りと4からの2通りで2通り
6へは4からの2通りと5からの2通りで4通り
"""
# dp = {}
dp = [0 for i in range(N + 1)]
# print('fua')
dp[0] = 1
dp[1] = 1 if 1 not in A else 0
# [dp.update({i: (dp[i-1] + dp[i-2])%mod}) if i not in A else dp.update({i: 0}) for i in range(2, N+1)]
for i in range(2, N + 1):
# print(i)
# i段目までの通りを計算する
if i not in A:
# i段目が障害のときは0になっているので飛ばす
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= mod
print(dp[N])
| false | 54.545455 | [
"-# -*- coding: utf-8 -*-",
"-import sys",
"+import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools",
"+sys.setrecursionlimit(10**7)",
"+inf = 10**20",
"+eps = 1.0 / 10**10",
"+dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]",
"+ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]",
"-def get_nums(n):",
"- res = [0 for _ in range(n)]",
"- for i in range(n):",
"- res[i] = int(eval(input()))",
"- return res",
"+def LI():",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"-def get_numbers():",
"- return list(map(int, input().split()))",
"+def LI_():",
"+ return [int(x) - 1 for x in sys.stdin.readline().split()]",
"-n, m = get_numbers()",
"-a = set(get_nums(m))",
"-dp = [0 for _ in range(n + 1)]",
"+def LF():",
"+ return [float(x) for x in sys.stdin.readline().split()]",
"+",
"+",
"+def LS():",
"+ return sys.stdin.readline().split()",
"+",
"+",
"+def _I():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def _F():",
"+ return float(sys.stdin.readline())",
"+",
"+",
"+def _pf(s):",
"+ return print(s, flush=True)",
"+",
"+",
"+# f = open('C_input_29.txt')",
"+# lines = f.readlines()",
"+# f.close()",
"+# N, M = map(int, lines[0].split())",
"+# A = []",
"+# for line in lines[1:]:",
"+# A.append(int(line))",
"+N, M = LI()",
"+A = set([_I() for i in range(M)])",
"+# if M != 0:",
"+# # 連続した壊れた段がある場合は0",
"+# B = [i for i in A]",
"+# B.remove(B[0])",
"+# B.append(10**15+100)",
"+# diffs = [b - a for a, b in zip(A,B)]",
"+# # print(diffs)",
"+# if any(i == 1 for i in diffs):",
"+# # 隣同士なので0",
"+# print(0)",
"+# exit()",
"+# print('hoge')",
"+\"\"\"",
"+考え方",
"+xにたどり着く通りは、x-1とx-2段目にたどり着く通りの合計",
"+dp",
"+3が障害のとき",
"+1へは1通り",
"+2へは0からと1からの2通り",
"+3へは0通り",
"+4へは2からの2通りと、3からの0通りで2通り",
"+5へは3からの0通りと4からの2通りで2通り",
"+6へは4からの2通りと5からの2通りで4通り",
"+\"\"\"",
"+# dp = {}",
"+dp = [0 for i in range(N + 1)]",
"+# print('fua')",
"-if 1 not in a:",
"- dp[1] = 1",
"-for i in range(2, n + 1):",
"- if i not in a:",
"+dp[1] = 1 if 1 not in A else 0",
"+# [dp.update({i: (dp[i-1] + dp[i-2])%mod}) if i not in A else dp.update({i: 0}) for i in range(2, N+1)]",
"+for i in range(2, N + 1):",
"+ # print(i)",
"+ # i段目までの通りを計算する",
"+ if i not in A:",
"+ # i段目が障害のときは0になっているので飛ばす",
"-print((dp[-1]))",
"+print(dp[N])"
] | false | 0.116023 | 0.181658 | 0.638686 | [
"s822625615",
"s962987502"
] |
u585482323 | p04046 | python | s921971259 | s727928694 | 386 | 224 | 53,232 | 44,524 | Accepted | Accepted | 41.97 | #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007
#A
"""
def check(n):
n = list(map(int,list(str(n))))
s = 0
for i in n:
s += f[i]
return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
f[i] = 1
while 1:
if check(n):
print(n)
quit()
n += 1
"""
#B
h,w,a,b = LI()
ans = 0
k = 1
inv = [pow(i,mod-2,mod) for i in range(h+w+1)]
x = b+1
y = a+1
for i in range(min(x-1,h-y)):
k *= (x-1+h-y-i)*inv[i+1]%mod
k %= mod
for i in range(min(y-1,w-x)):
k *= (y-1+w-x-i)*inv[i+1]%mod
k %= mod
for i in range(1,min(w-b,h-a)+1):
ans += k
ans %= mod
k *= (h-y)*(w-x)*inv[x]*inv[y]%mod
k %= mod
x += 1
y += 1
print(ans)
#C
#D
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
| #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007
#A
"""
def check(n):
n = list(map(int,list(str(n))))
s = 0
for i in n:
s += f[i]
return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
f[i] = 1
while 1:
if check(n):
print(n)
quit()
n += 1
"""
#B
def f(x,y):
return fact[x-1+h-y]*fact[y-1+w-x]*inv_fact[x-1]*inv_fact[y-1]*inv_fact[w-x]*inv_fact[h-y]%mod
h,w,a,b = LI()
fact = [1]*(h+w+1)
for i in range(h+w):
fact[i+1] = fact[i]*(i+1)%mod
inv_fact = [0]*(h+w+1)
inv_fact[h+w] = pow(fact[-1],mod-2,mod)
for i in range(h+w)[::-1]:
inv_fact[i] = inv_fact[i+1]*(i+1)%mod
ans = 0
for i in range(1,min(w-b,h-a)+1):
ans += f(b+i,a+i)
ans %= mod
print(ans)
#C
#D
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
| 93 | 88 | 1,374 | 1,398 | #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
mod = 1000000007
# A
"""
def check(n):
n = list(map(int,list(str(n))))
s = 0
for i in n:
s += f[i]
return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
f[i] = 1
while 1:
if check(n):
print(n)
quit()
n += 1
"""
# B
h, w, a, b = LI()
ans = 0
k = 1
inv = [pow(i, mod - 2, mod) for i in range(h + w + 1)]
x = b + 1
y = a + 1
for i in range(min(x - 1, h - y)):
k *= (x - 1 + h - y - i) * inv[i + 1] % mod
k %= mod
for i in range(min(y - 1, w - x)):
k *= (y - 1 + w - x - i) * inv[i + 1] % mod
k %= mod
for i in range(1, min(w - b, h - a) + 1):
ans += k
ans %= mod
k *= (h - y) * (w - x) * inv[x] * inv[y] % mod
k %= mod
x += 1
y += 1
print(ans)
# C
# D
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
mod = 1000000007
# A
"""
def check(n):
n = list(map(int,list(str(n))))
s = 0
for i in n:
s += f[i]
return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
f[i] = 1
while 1:
if check(n):
print(n)
quit()
n += 1
"""
# B
def f(x, y):
return (
fact[x - 1 + h - y]
* fact[y - 1 + w - x]
* inv_fact[x - 1]
* inv_fact[y - 1]
* inv_fact[w - x]
* inv_fact[h - y]
% mod
)
h, w, a, b = LI()
fact = [1] * (h + w + 1)
for i in range(h + w):
fact[i + 1] = fact[i] * (i + 1) % mod
inv_fact = [0] * (h + w + 1)
inv_fact[h + w] = pow(fact[-1], mod - 2, mod)
for i in range(h + w)[::-1]:
inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod
ans = 0
for i in range(1, min(w - b, h - a) + 1):
ans += f(b + i, a + i)
ans %= mod
print(ans)
# C
# D
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| false | 5.376344 | [
"+def f(x, y):",
"+ return (",
"+ fact[x - 1 + h - y]",
"+ * fact[y - 1 + w - x]",
"+ * inv_fact[x - 1]",
"+ * inv_fact[y - 1]",
"+ * inv_fact[w - x]",
"+ * inv_fact[h - y]",
"+ % mod",
"+ )",
"+",
"+",
"+fact = [1] * (h + w + 1)",
"+for i in range(h + w):",
"+ fact[i + 1] = fact[i] * (i + 1) % mod",
"+inv_fact = [0] * (h + w + 1)",
"+inv_fact[h + w] = pow(fact[-1], mod - 2, mod)",
"+for i in range(h + w)[::-1]:",
"+ inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod",
"-k = 1",
"-inv = [pow(i, mod - 2, mod) for i in range(h + w + 1)]",
"-x = b + 1",
"-y = a + 1",
"-for i in range(min(x - 1, h - y)):",
"- k *= (x - 1 + h - y - i) * inv[i + 1] % mod",
"- k %= mod",
"-for i in range(min(y - 1, w - x)):",
"- k *= (y - 1 + w - x - i) * inv[i + 1] % mod",
"- k %= mod",
"- ans += k",
"+ ans += f(b + i, a + i)",
"- k *= (h - y) * (w - x) * inv[x] * inv[y] % mod",
"- k %= mod",
"- x += 1",
"- y += 1"
] | false | 0.046327 | 0.091415 | 0.50678 | [
"s921971259",
"s727928694"
] |
u691501673 | p02837 | python | s945029893 | s711133489 | 492 | 244 | 3,064 | 44,140 | Accepted | Accepted | 50.41 | N = int(eval(input()))
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
array = [-1] * N
testimony_list.append(array)
for i in range(N):
A = int(eval(input()))
for j in range(A):
x, y = list(map(int, input().split()))
# iさんの、xさんへの証言
testimony_list[i][x - 1] = y
max_count = 0
for i in range(2 ** N):
failed = False
for j in range(N):
if not (i >> j & 1):
continue
array = testimony_list[j]
for k in range(N):
if array[k] != -1 and (i >> k & 1) != array[k]:
failed = True
break
if failed is False:
max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)
| N = int(eval(input()))
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
array = [-1] * N
testimony_list.append(array)
for i in range(N):
A = int(eval(input()))
for j in range(A):
x, y = list(map(int, input().split()))
# iさんの、xさんへの証言
testimony_list[i][x - 1] = y
max_count = 0
for i in range(2 ** N):
failed = False
for j in range(N):
if not (i >> j & 1):
continue
array = testimony_list[j]
for k in range(N):
if array[k] == -1:
continue
if (i >> k & 1) != array[k]: # 正直者に対して不親切 or 不親切に対して正直者と証言
failed = True
break
if not failed:
# 「0b010110」の「0b」を除外して1の数をカウント
max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)
| 28 | 31 | 718 | 823 | N = int(eval(input()))
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
array = [-1] * N
testimony_list.append(array)
for i in range(N):
A = int(eval(input()))
for j in range(A):
x, y = list(map(int, input().split()))
# iさんの、xさんへの証言
testimony_list[i][x - 1] = y
max_count = 0
for i in range(2**N):
failed = False
for j in range(N):
if not (i >> j & 1):
continue
array = testimony_list[j]
for k in range(N):
if array[k] != -1 and (i >> k & 1) != array[k]:
failed = True
break
if failed is False:
max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)
| N = int(eval(input()))
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
array = [-1] * N
testimony_list.append(array)
for i in range(N):
A = int(eval(input()))
for j in range(A):
x, y = list(map(int, input().split()))
# iさんの、xさんへの証言
testimony_list[i][x - 1] = y
max_count = 0
for i in range(2**N):
failed = False
for j in range(N):
if not (i >> j & 1):
continue
array = testimony_list[j]
for k in range(N):
if array[k] == -1:
continue
if (i >> k & 1) != array[k]: # 正直者に対して不親切 or 不親切に対して正直者と証言
failed = True
break
if not failed:
# 「0b010110」の「0b」を除外して1の数をカウント
max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)
| false | 9.677419 | [
"- if array[k] != -1 and (i >> k & 1) != array[k]:",
"+ if array[k] == -1:",
"+ continue",
"+ if (i >> k & 1) != array[k]: # 正直者に対して不親切 or 不親切に対して正直者と証言",
"- if failed is False:",
"+ if not failed:",
"+ # 「0b010110」の「0b」を除外して1の数をカウント"
] | false | 0.078857 | 0.077205 | 1.021406 | [
"s945029893",
"s711133489"
] |
u020962106 | p03524 | python | s707748537 | s302064391 | 25 | 18 | 3,444 | 3,188 | Accepted | Accepted | 28 | from collections import Counter
s = eval(input())
dic = dict(Counter(s))
if len(dic)==1:
for v in list(dic.values()):
if v==1:
print('YES')
else:
print('NO')
elif len(dic)==2:
for v in list(dic.values()):
if v>=2:
print('NO')
break
else:
print('YES')
else:
a = dic['a']
b = dic['b']
c = dic['c']
if a==b==c:
print('YES')
elif a==b and abs(b-c)<=1:
print('YES')
elif b==c and abs(c-a)<=1:
print('YES')
elif c==a and abs(a-b)<=1:
print('YES')
else:
print('NO') | s = eval(input())
na = s.count('a')
nb = s.count('b')
nc = len(s) - na - nb
if max(na,nb,nc)-min(na,nb,nc)<=1:
print('YES')
else:
print('NO') | 30 | 8 | 633 | 150 | from collections import Counter
s = eval(input())
dic = dict(Counter(s))
if len(dic) == 1:
for v in list(dic.values()):
if v == 1:
print("YES")
else:
print("NO")
elif len(dic) == 2:
for v in list(dic.values()):
if v >= 2:
print("NO")
break
else:
print("YES")
else:
a = dic["a"]
b = dic["b"]
c = dic["c"]
if a == b == c:
print("YES")
elif a == b and abs(b - c) <= 1:
print("YES")
elif b == c and abs(c - a) <= 1:
print("YES")
elif c == a and abs(a - b) <= 1:
print("YES")
else:
print("NO")
| s = eval(input())
na = s.count("a")
nb = s.count("b")
nc = len(s) - na - nb
if max(na, nb, nc) - min(na, nb, nc) <= 1:
print("YES")
else:
print("NO")
| false | 73.333333 | [
"-from collections import Counter",
"-",
"-dic = dict(Counter(s))",
"-if len(dic) == 1:",
"- for v in list(dic.values()):",
"- if v == 1:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"-elif len(dic) == 2:",
"- for v in list(dic.values()):",
"- if v >= 2:",
"- print(\"NO\")",
"- break",
"- else:",
"- print(\"YES\")",
"+na = s.count(\"a\")",
"+nb = s.count(\"b\")",
"+nc = len(s) - na - nb",
"+if max(na, nb, nc) - min(na, nb, nc) <= 1:",
"+ print(\"YES\")",
"- a = dic[\"a\"]",
"- b = dic[\"b\"]",
"- c = dic[\"c\"]",
"- if a == b == c:",
"- print(\"YES\")",
"- elif a == b and abs(b - c) <= 1:",
"- print(\"YES\")",
"- elif b == c and abs(c - a) <= 1:",
"- print(\"YES\")",
"- elif c == a and abs(a - b) <= 1:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"+ print(\"NO\")"
] | false | 0.050189 | 0.008466 | 5.928312 | [
"s707748537",
"s302064391"
] |
u777923818 | p03639 | python | s157649041 | s199443928 | 85 | 65 | 14,252 | 14,636 | Accepted | Accepted | 23.53 | # -*- coding: utf-8 -*-
N = int(eval(input()))
A = [int(n) for n in input().split()]
x2 = sum([a%2!=0 for a in A])
o2x4 = sum([(a%2==0)&(a%4!=0) for a in A])
o4 = sum([a%4==0 for a in A])
if o2x4 == 0:
if o4 + 1 >= x2:
print("Yes")
else:
print("No")
else:
if o4 >= x2:
print("Yes")
else:
print("No") | # -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
a, b, c = 0, 0, 0
for x in inpl():
if x%4 == 0:
a += 1
elif x%2 == 0:
b += 1
else:
c += 1
if a+(b==0) >= c:
print("Yes")
else:
print("No") | 19 | 18 | 362 | 325 | # -*- coding: utf-8 -*-
N = int(eval(input()))
A = [int(n) for n in input().split()]
x2 = sum([a % 2 != 0 for a in A])
o2x4 = sum([(a % 2 == 0) & (a % 4 != 0) for a in A])
o4 = sum([a % 4 == 0 for a in A])
if o2x4 == 0:
if o4 + 1 >= x2:
print("Yes")
else:
print("No")
else:
if o4 >= x2:
print("Yes")
else:
print("No")
| # -*- coding: utf-8 -*-
from collections import Counter
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
a, b, c = 0, 0, 0
for x in inpl():
if x % 4 == 0:
a += 1
elif x % 2 == 0:
b += 1
else:
c += 1
if a + (b == 0) >= c:
print("Yes")
else:
print("No")
| false | 5.263158 | [
"+from collections import Counter",
"+",
"+",
"+def inpl():",
"+ return list(map(int, input().split()))",
"+",
"+",
"-A = [int(n) for n in input().split()]",
"-x2 = sum([a % 2 != 0 for a in A])",
"-o2x4 = sum([(a % 2 == 0) & (a % 4 != 0) for a in A])",
"-o4 = sum([a % 4 == 0 for a in A])",
"-if o2x4 == 0:",
"- if o4 + 1 >= x2:",
"- print(\"Yes\")",
"+a, b, c = 0, 0, 0",
"+for x in inpl():",
"+ if x % 4 == 0:",
"+ a += 1",
"+ elif x % 2 == 0:",
"+ b += 1",
"- print(\"No\")",
"+ c += 1",
"+if a + (b == 0) >= c:",
"+ print(\"Yes\")",
"- if o4 >= x2:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+ print(\"No\")"
] | false | 0.109685 | 0.046082 | 2.380224 | [
"s157649041",
"s199443928"
] |
u039623862 | p03830 | python | s372106862 | s595677399 | 112 | 28 | 3,572 | 3,440 | Accepted | Accepted | 75 | import collections
MOD = (10 ** 9 + 7)
n = int(eval(input()))
p = [True for i in range(n+1)]
p[0] = False
p[1] = False
pf = collections.defaultdict(int)
for i in range(2, n+1):
if not p[i]:
continue
j = i * i
while j <= n:
p[j] = False
j += i
cnt = 1
v = i
while v <= n:
cnt += n//v
v *= i
pf[i] = cnt
total = 1
for v in list(pf.values()):
total = (total * v) % MOD
print(total) | import collections
MOD = 10**9+7
def list_prime(n):
if n < 2:
return []
elif n == 2:
return [2]
is_prime = [True for i in range(n+1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, n):
for j in range(i*i, n+1, i):
is_prime[j] = False
prime = []
for i in range(n+1):
if is_prime[i]:
prime.append(i)
return prime
def cnt_factor(n, p):
cnt = 0
pi = p
while pi <= n:
cnt += n //pi
pi *= p
return cnt
n = int(eval(input()))
p_list = list_prime(n)
cnt = 1
for p in p_list:
cnt = cnt * (cnt_factor(n, p)+1) % MOD
print(cnt) | 27 | 33 | 467 | 683 | import collections
MOD = 10**9 + 7
n = int(eval(input()))
p = [True for i in range(n + 1)]
p[0] = False
p[1] = False
pf = collections.defaultdict(int)
for i in range(2, n + 1):
if not p[i]:
continue
j = i * i
while j <= n:
p[j] = False
j += i
cnt = 1
v = i
while v <= n:
cnt += n // v
v *= i
pf[i] = cnt
total = 1
for v in list(pf.values()):
total = (total * v) % MOD
print(total)
| import collections
MOD = 10**9 + 7
def list_prime(n):
if n < 2:
return []
elif n == 2:
return [2]
is_prime = [True for i in range(n + 1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, n):
for j in range(i * i, n + 1, i):
is_prime[j] = False
prime = []
for i in range(n + 1):
if is_prime[i]:
prime.append(i)
return prime
def cnt_factor(n, p):
cnt = 0
pi = p
while pi <= n:
cnt += n // pi
pi *= p
return cnt
n = int(eval(input()))
p_list = list_prime(n)
cnt = 1
for p in p_list:
cnt = cnt * (cnt_factor(n, p) + 1) % MOD
print(cnt)
| false | 18.181818 | [
"+",
"+",
"+def list_prime(n):",
"+ if n < 2:",
"+ return []",
"+ elif n == 2:",
"+ return [2]",
"+ is_prime = [True for i in range(n + 1)]",
"+ is_prime[0] = False",
"+ is_prime[1] = False",
"+ for i in range(2, n):",
"+ for j in range(i * i, n + 1, i):",
"+ is_prime[j] = False",
"+ prime = []",
"+ for i in range(n + 1):",
"+ if is_prime[i]:",
"+ prime.append(i)",
"+ return prime",
"+",
"+",
"+def cnt_factor(n, p):",
"+ cnt = 0",
"+ pi = p",
"+ while pi <= n:",
"+ cnt += n // pi",
"+ pi *= p",
"+ return cnt",
"+",
"+",
"-p = [True for i in range(n + 1)]",
"-p[0] = False",
"-p[1] = False",
"-pf = collections.defaultdict(int)",
"-for i in range(2, n + 1):",
"- if not p[i]:",
"- continue",
"- j = i * i",
"- while j <= n:",
"- p[j] = False",
"- j += i",
"- cnt = 1",
"- v = i",
"- while v <= n:",
"- cnt += n // v",
"- v *= i",
"- pf[i] = cnt",
"-total = 1",
"-for v in list(pf.values()):",
"- total = (total * v) % MOD",
"-print(total)",
"+p_list = list_prime(n)",
"+cnt = 1",
"+for p in p_list:",
"+ cnt = cnt * (cnt_factor(n, p) + 1) % MOD",
"+print(cnt)"
] | false | 0.04433 | 0.045718 | 0.969643 | [
"s372106862",
"s595677399"
] |
u540877546 | p03293 | python | s290654751 | s711008273 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | s = str(eval(input()))
t = str(eval(input()))
for i in range(len(s)):
for j in s:
if(t == s[i:]+s[:i]):
print('Yes')
exit()
print('No')
| s = str(eval(input()))
t = str(eval(input()))
for i in range(len(s)):
if(t == s[i:]+s[:i]):
print('Yes')
exit()
print('No')
| 11 | 9 | 173 | 142 | s = str(eval(input()))
t = str(eval(input()))
for i in range(len(s)):
for j in s:
if t == s[i:] + s[:i]:
print("Yes")
exit()
print("No")
| s = str(eval(input()))
t = str(eval(input()))
for i in range(len(s)):
if t == s[i:] + s[:i]:
print("Yes")
exit()
print("No")
| false | 18.181818 | [
"- for j in s:",
"- if t == s[i:] + s[:i]:",
"- print(\"Yes\")",
"- exit()",
"+ if t == s[i:] + s[:i]:",
"+ print(\"Yes\")",
"+ exit()"
] | false | 0.046293 | 0.042727 | 1.083459 | [
"s290654751",
"s711008273"
] |
u088552457 | p03785 | python | s397650400 | s222586422 | 333 | 95 | 27,972 | 77,360 | Accepted | Accepted | 71.47 | n, c, k = list(map(int, input().split()))
t = []
for _ in range(n):
t.append(int(eval(input())))
st = sorted(t)
time = 0
limit = st[0]+k
d = {}
d[limit] = []
ans = 1
for i, p in enumerate(st):
if p <= limit and len(d[limit]) < c:
d[limit].append(p)
else:
limit = p + k
ans += 1
d[limit] = [p]
print(ans) | import sys
input = sys.stdin.readline
def main():
n, c, k = input_list()
arrivals = []
for _ in range(n):
arrivals.append(int(eval(input())))
arrivals.sort()
count = 0
limit = 0
ans = 0
for i, a in enumerate(arrivals):
if limit and limit < a:
limit = 0
count = 0
ans += 1
if not limit:
limit = a + k
if a <= limit:
count += 1
if count == c:
ans += 1
count = 0
limit = 0
if count > 0:
ans += 1
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 22 | 39 | 340 | 790 | n, c, k = list(map(int, input().split()))
t = []
for _ in range(n):
t.append(int(eval(input())))
st = sorted(t)
time = 0
limit = st[0] + k
d = {}
d[limit] = []
ans = 1
for i, p in enumerate(st):
if p <= limit and len(d[limit]) < c:
d[limit].append(p)
else:
limit = p + k
ans += 1
d[limit] = [p]
print(ans)
| import sys
input = sys.stdin.readline
def main():
n, c, k = input_list()
arrivals = []
for _ in range(n):
arrivals.append(int(eval(input())))
arrivals.sort()
count = 0
limit = 0
ans = 0
for i, a in enumerate(arrivals):
if limit and limit < a:
limit = 0
count = 0
ans += 1
if not limit:
limit = a + k
if a <= limit:
count += 1
if count == c:
ans += 1
count = 0
limit = 0
if count > 0:
ans += 1
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| false | 43.589744 | [
"-n, c, k = list(map(int, input().split()))",
"-t = []",
"-for _ in range(n):",
"- t.append(int(eval(input())))",
"-st = sorted(t)",
"-time = 0",
"-limit = st[0] + k",
"-d = {}",
"-d[limit] = []",
"-ans = 1",
"-for i, p in enumerate(st):",
"- if p <= limit and len(d[limit]) < c:",
"- d[limit].append(p)",
"- else:",
"- limit = p + k",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ n, c, k = input_list()",
"+ arrivals = []",
"+ for _ in range(n):",
"+ arrivals.append(int(eval(input())))",
"+ arrivals.sort()",
"+ count = 0",
"+ limit = 0",
"+ ans = 0",
"+ for i, a in enumerate(arrivals):",
"+ if limit and limit < a:",
"+ limit = 0",
"+ count = 0",
"+ ans += 1",
"+ if not limit:",
"+ limit = a + k",
"+ if a <= limit:",
"+ count += 1",
"+ if count == c:",
"+ ans += 1",
"+ count = 0",
"+ limit = 0",
"+ if count > 0:",
"- d[limit] = [p]",
"-print(ans)",
"+ print(ans)",
"+",
"+",
"+def input_list():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def input_list_str():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037729 | 0.039462 | 0.956085 | [
"s397650400",
"s222586422"
] |
u588341295 | p03762 | python | s761501614 | s035283990 | 281 | 210 | 25,212 | 19,580 | Accepted | Accepted | 25.27 | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, M = MAP()
A = LIST()
B = LIST()
# データの持ち方を座標から区間長にして累積和
A2 = []
for i in range(N-1):
A2.append(A[i+1] - A[i])
B2 = []
for i in range(M-1):
B2.append(B[i+1] - B[i])
A2 = [0] + list(accumulate(A2))
B2 = [0] + list(accumulate(B2))
# 縦横独立に、累積和の全区間総和を取る
lsm = rsm = 0
for i in range(N):
lsm += A2[i] * (N-i-1)
rsm += A2[i] * i
lsm %= MOD
rsm %= MOD
h = rsm - lsm
lsm = rsm = 0
for i in range(M):
lsm += B2[i] * (M-i-1)
rsm += B2[i] * i
lsm %= MOD
rsm %= MOD
w = rsm - lsm
ans = h * w % MOD
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, M = MAP()
A = LIST()
B = LIST()
# 縦横独立に、全区間総和を取る
lsm = rsm = 0
for i in range(N):
lsm += A[i] * (N-i-1)
rsm += A[i] * i
lsm %= MOD
rsm %= MOD
h = rsm - lsm
lsm = rsm = 0
for i in range(M):
lsm += B[i] * (M-i-1)
rsm += B[i] * i
lsm %= MOD
rsm %= MOD
w = rsm - lsm
ans = h * w % MOD
print(ans)
| 53 | 42 | 1,304 | 1,047 | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, M = MAP()
A = LIST()
B = LIST()
# データの持ち方を座標から区間長にして累積和
A2 = []
for i in range(N - 1):
A2.append(A[i + 1] - A[i])
B2 = []
for i in range(M - 1):
B2.append(B[i + 1] - B[i])
A2 = [0] + list(accumulate(A2))
B2 = [0] + list(accumulate(B2))
# 縦横独立に、累積和の全区間総和を取る
lsm = rsm = 0
for i in range(N):
lsm += A2[i] * (N - i - 1)
rsm += A2[i] * i
lsm %= MOD
rsm %= MOD
h = rsm - lsm
lsm = rsm = 0
for i in range(M):
lsm += B2[i] * (M - i - 1)
rsm += B2[i] * i
lsm %= MOD
rsm %= MOD
w = rsm - lsm
ans = h * w % MOD
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, M = MAP()
A = LIST()
B = LIST()
# 縦横独立に、全区間総和を取る
lsm = rsm = 0
for i in range(N):
lsm += A[i] * (N - i - 1)
rsm += A[i] * i
lsm %= MOD
rsm %= MOD
h = rsm - lsm
lsm = rsm = 0
for i in range(M):
lsm += B[i] * (M - i - 1)
rsm += B[i] * i
lsm %= MOD
rsm %= MOD
w = rsm - lsm
ans = h * w % MOD
print(ans)
| false | 20.754717 | [
"-from itertools import accumulate",
"-# データの持ち方を座標から区間長にして累積和",
"-A2 = []",
"-for i in range(N - 1):",
"- A2.append(A[i + 1] - A[i])",
"-B2 = []",
"-for i in range(M - 1):",
"- B2.append(B[i + 1] - B[i])",
"-A2 = [0] + list(accumulate(A2))",
"-B2 = [0] + list(accumulate(B2))",
"-# 縦横独立に、累積和の全区間総和を取る",
"+# 縦横独立に、全区間総和を取る",
"- lsm += A2[i] * (N - i - 1)",
"- rsm += A2[i] * i",
"+ lsm += A[i] * (N - i - 1)",
"+ rsm += A[i] * i",
"- lsm += B2[i] * (M - i - 1)",
"- rsm += B2[i] * i",
"+ lsm += B[i] * (M - i - 1)",
"+ rsm += B[i] * i"
] | false | 0.038296 | 0.037622 | 1.017927 | [
"s761501614",
"s035283990"
] |
u437632122 | p03470 | python | s875101072 | s845179540 | 187 | 164 | 38,256 | 38,384 | Accepted | Accepted | 12.3 | N = int(eval(input()))
d = list()
for n in range(N):
d.append(int(eval(input())))
d = sorted(d, reverse=True)
ans = 1
for i, n in enumerate(d):
if i == len(d) - 1:
break
if n > d[i + 1]:
ans += 1
print(ans)
| N = int(eval(input()))
d = list()
for n in range(N):
d.append(int(eval(input())))
print((len(set(d))))
| 12 | 6 | 234 | 99 | N = int(eval(input()))
d = list()
for n in range(N):
d.append(int(eval(input())))
d = sorted(d, reverse=True)
ans = 1
for i, n in enumerate(d):
if i == len(d) - 1:
break
if n > d[i + 1]:
ans += 1
print(ans)
| N = int(eval(input()))
d = list()
for n in range(N):
d.append(int(eval(input())))
print((len(set(d))))
| false | 50 | [
"-d = sorted(d, reverse=True)",
"-ans = 1",
"-for i, n in enumerate(d):",
"- if i == len(d) - 1:",
"- break",
"- if n > d[i + 1]:",
"- ans += 1",
"-print(ans)",
"+print((len(set(d))))"
] | false | 0.044024 | 0.045584 | 0.965763 | [
"s875101072",
"s845179540"
] |
u799443198 | p03319 | python | s104644767 | s832029377 | 40 | 17 | 13,852 | 2,940 | Accepted | Accepted | 57.5 | import math
N, K, *A = list(map(int, open(0).read().split()))
I = A.index(1)
print((math.ceil((N-1)/(K-1)))) | N, K = list(map(int, input().split()))
print(((N+K-3)//(K-1)))
| 4 | 2 | 103 | 56 | import math
N, K, *A = list(map(int, open(0).read().split()))
I = A.index(1)
print((math.ceil((N - 1) / (K - 1))))
| N, K = list(map(int, input().split()))
print(((N + K - 3) // (K - 1)))
| false | 50 | [
"-import math",
"-",
"-N, K, *A = list(map(int, open(0).read().split()))",
"-I = A.index(1)",
"-print((math.ceil((N - 1) / (K - 1))))",
"+N, K = list(map(int, input().split()))",
"+print(((N + K - 3) // (K - 1)))"
] | false | 0.080563 | 0.146856 | 0.548586 | [
"s104644767",
"s832029377"
] |
u353895424 | p03723 | python | s470028447 | s026575556 | 184 | 166 | 40,300 | 38,384 | Accepted | Accepted | 9.78 | a, b, c = list(map(int, input().split()))
cnt = 0
while cnt <= 10**6:
if a%2 != 0 or b%2 != 0 or c%2 != 0:
print(cnt)
exit()
a_ = b//2 + c//2
b_ = a//2 + c//2
c_ = a//2 + b//2
a = a_
b = b_
c = c_
cnt += 1
print((-1)) | a, b, c = list(map(int, input().split()))
cnt = 0
while cnt <= 10**6:
if (a%2 != 0 or b%2 != 0 or c%2 != 0):
print(cnt)
exit()
if a==b==c:
print((-1))
exit()
a_ = b//2 + c//2
b_ = a//2 + c//2
c_ = a//2 + b//2
a = a_
b = b_
c = c_
cnt += 1 | 18 | 21 | 282 | 331 | a, b, c = list(map(int, input().split()))
cnt = 0
while cnt <= 10**6:
if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
print(cnt)
exit()
a_ = b // 2 + c // 2
b_ = a // 2 + c // 2
c_ = a // 2 + b // 2
a = a_
b = b_
c = c_
cnt += 1
print((-1))
| a, b, c = list(map(int, input().split()))
cnt = 0
while cnt <= 10**6:
if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
print(cnt)
exit()
if a == b == c:
print((-1))
exit()
a_ = b // 2 + c // 2
b_ = a // 2 + c // 2
c_ = a // 2 + b // 2
a = a_
b = b_
c = c_
cnt += 1
| false | 14.285714 | [
"+ exit()",
"+ if a == b == c:",
"+ print((-1))",
"-print((-1))"
] | false | 0.194855 | 0.038847 | 5.015953 | [
"s470028447",
"s026575556"
] |
u906428167 | p02936 | python | s543365237 | s248449175 | 1,821 | 829 | 107,136 | 92,876 | Accepted | Accepted | 54.48 | n,qq = list(map(int,input().split()))
g = [[] for _ in range(n)]
for i in range(n-1):
a,b = list(map(int,input().split()))
g[a-1].append(b-1)
g[b-1].append(a-1)
l = [0]*n
count = [0]*n
for _ in range(qq):
p,x = list(map(int,input().split()))
l[p-1] += x
p = [True]*n
p[0] = False
q = [0]
while q:
v = q.pop()
for w in g[v]:
if p[w]:
p[w] = False
l[w] += l[v]
q.append(w)
print((*l)) | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
n, q = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(n-1):
a, b = list(map(int, input().split()))
g[a-1].append(b-1)
g[b-1].append(a-1)
l = [0]*n
for _ in range(q):
p, x = list(map(int, input().split()))
l[p-1] += x
visited = [False]*n
visited[0] = True
q = [0]
while q:
v = q.pop()
for w in g[v]:
if not visited[w]:
visited[w] = True
l[w] += l[v]
q.append(w)
print((*l))
| 32 | 33 | 475 | 562 | n, qq = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
l = [0] * n
count = [0] * n
for _ in range(qq):
p, x = list(map(int, input().split()))
l[p - 1] += x
p = [True] * n
p[0] = False
q = [0]
while q:
v = q.pop()
for w in g[v]:
if p[w]:
p[w] = False
l[w] += l[v]
q.append(w)
print((*l))
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n, q = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
l = [0] * n
for _ in range(q):
p, x = list(map(int, input().split()))
l[p - 1] += x
visited = [False] * n
visited[0] = True
q = [0]
while q:
v = q.pop()
for w in g[v]:
if not visited[w]:
visited[w] = True
l[w] += l[v]
q.append(w)
print((*l))
| false | 3.030303 | [
"-n, qq = list(map(int, input().split()))",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"+n, q = list(map(int, input().split()))",
"-count = [0] * n",
"-for _ in range(qq):",
"+for _ in range(q):",
"-p = [True] * n",
"-p[0] = False",
"+visited = [False] * n",
"+visited[0] = True",
"- if p[w]:",
"- p[w] = False",
"+ if not visited[w]:",
"+ visited[w] = True"
] | false | 0.03549 | 0.046238 | 0.767556 | [
"s543365237",
"s248449175"
] |
u241159583 | p03197 | python | s332281082 | s052863238 | 185 | 143 | 7,072 | 9,812 | Accepted | Accepted | 22.7 | N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
print(("second" if all(a[i] % 2 == 0 for i in range(N)) else "first")) | n = int(eval(input()))
a = list(int(eval(input()))%2 for _ in range(n))
a = list(set(a))
print(("second" if a == [0] else "first")) | 4 | 4 | 126 | 120 | N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
print(("second" if all(a[i] % 2 == 0 for i in range(N)) else "first"))
| n = int(eval(input()))
a = list(int(eval(input())) % 2 for _ in range(n))
a = list(set(a))
print(("second" if a == [0] else "first"))
| false | 0 | [
"-N = int(eval(input()))",
"-a = [int(eval(input())) for _ in range(N)]",
"-print((\"second\" if all(a[i] % 2 == 0 for i in range(N)) else \"first\"))",
"+n = int(eval(input()))",
"+a = list(int(eval(input())) % 2 for _ in range(n))",
"+a = list(set(a))",
"+print((\"second\" if a == [0] else \"first\"))"
] | false | 0.082272 | 0.04389 | 1.874511 | [
"s332281082",
"s052863238"
] |
u489959379 | p03420 | python | s316737842 | s965948062 | 112 | 75 | 3,316 | 9,068 | Accepted | Accepted | 33.04 | import math
n, k = list(map(int, input().split()))
res = 0
for b in range(1, n + 1):
res += math.floor(n / b) * max(0, b - k) + max(0, n % b - k + 1)
if k == 0:
res = n ** 2
print(res)
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, k = list(map(int, input().split()))
if k == 0:
print((n ** 2))
exit()
res = 0
for b in range(1, n + 1):
res += n // b * max(0, b - k)
res += max(0, n % b + 1 - k)
print(res)
if __name__ == '__main__':
resolve()
| 11 | 24 | 200 | 415 | import math
n, k = list(map(int, input().split()))
res = 0
for b in range(1, n + 1):
res += math.floor(n / b) * max(0, b - k) + max(0, n % b - k + 1)
if k == 0:
res = n**2
print(res)
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n, k = list(map(int, input().split()))
if k == 0:
print((n**2))
exit()
res = 0
for b in range(1, n + 1):
res += n // b * max(0, b - k)
res += max(0, n % b + 1 - k)
print(res)
if __name__ == "__main__":
resolve()
| false | 54.166667 | [
"-import math",
"+import sys",
"-n, k = list(map(int, input().split()))",
"-res = 0",
"-for b in range(1, n + 1):",
"- res += math.floor(n / b) * max(0, b - k) + max(0, n % b - k + 1)",
"-if k == 0:",
"- res = n**2",
"-print(res)",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ n, k = list(map(int, input().split()))",
"+ if k == 0:",
"+ print((n**2))",
"+ exit()",
"+ res = 0",
"+ for b in range(1, n + 1):",
"+ res += n // b * max(0, b - k)",
"+ res += max(0, n % b + 1 - k)",
"+ print(res)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.050357 | 0.143263 | 0.351503 | [
"s316737842",
"s965948062"
] |
u564902833 | p03107 | python | s246571311 | s150879762 | 41 | 18 | 3,188 | 3,188 | Accepted | Accepted | 56.1 | S = eval(input())
k = 0
ans = 0
for s in S:
if s == '1':
if k <= -1:
ans += 2
k += 1
else:
if k >= 1:
ans += 2
k -= 1
print(ans)
| # 入力
S = eval(input())
# 適当に取り除く操作を繰り返せばよい
ans = 2 * min(S.count('0'), S.count('1'))
# 出力
print(ans)
| 13 | 8 | 199 | 104 | S = eval(input())
k = 0
ans = 0
for s in S:
if s == "1":
if k <= -1:
ans += 2
k += 1
else:
if k >= 1:
ans += 2
k -= 1
print(ans)
| # 入力
S = eval(input())
# 適当に取り除く操作を繰り返せばよい
ans = 2 * min(S.count("0"), S.count("1"))
# 出力
print(ans)
| false | 38.461538 | [
"+# 入力",
"-k = 0",
"-ans = 0",
"-for s in S:",
"- if s == \"1\":",
"- if k <= -1:",
"- ans += 2",
"- k += 1",
"- else:",
"- if k >= 1:",
"- ans += 2",
"- k -= 1",
"+# 適当に取り除く操作を繰り返せばよい",
"+ans = 2 * min(S.count(\"0\"), S.count(\"1\"))",
"+# 出力"
] | false | 0.03764 | 0.036614 | 1.028009 | [
"s246571311",
"s150879762"
] |
u439063038 | p02573 | python | s574210838 | s119225243 | 820 | 613 | 14,756 | 13,268 | Accepted | Accepted | 25.24 | N, M = list(map(int, input().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
for _ in range(M):
a, b = [int(x)-1 for x in input().split()]
uf.union(a, b)
ans = 0
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
| import sys
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
root = [-1] * N
def r(x):
if root[x] < 0:
return x
else:
root[x] = r(root[x])
return root[x]
def unite(x, y):
x = r(x)
y = r(y)
if x == y:
return
root[x] += root[y]
root[y] = x
def size(x):
return -r(x)
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
unite(a, b)
max_size = -min(root)
print(max_size)
| 56 | 38 | 1,412 | 527 | N, M = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
for _ in range(M):
a, b = [int(x) - 1 for x in input().split()]
uf.union(a, b)
ans = 0
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
| import sys
sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
root = [-1] * N
def r(x):
if root[x] < 0:
return x
else:
root[x] = r(root[x])
return root[x]
def unite(x, y):
x = r(x)
y = r(y)
if x == y:
return
root[x] += root[y]
root[y] = x
def size(x):
return -r(x)
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
unite(a, b)
max_size = -min(root)
print(max_size)
| false | 32.142857 | [
"+import sys",
"+",
"+sys.setrecursionlimit(10**9)",
"+root = [-1] * N",
"-class UnionFind:",
"- def __init__(self, n):",
"- self.n = n",
"- self.parents = [-1] * n",
"-",
"- def find(self, x):",
"- if self.parents[x] < 0:",
"- return x",
"- else:",
"- self.parents[x] = self.find(self.parents[x])",
"- return self.parents[x]",
"-",
"- def union(self, x, y):",
"- x = self.find(x)",
"- y = self.find(y)",
"- if x == y:",
"- return",
"- if self.parents[x] > self.parents[y]:",
"- x, y = y, x",
"- self.parents[x] += self.parents[y]",
"- self.parents[y] = x",
"-",
"- def size(self, x):",
"- return -self.parents[self.find(x)]",
"-",
"- def same(self, x, y):",
"- return self.find(x) == self.find(y)",
"-",
"- def members(self, x):",
"- root = self.find(x)",
"- return [i for i in range(self.n) if self.find(i) == root]",
"-",
"- def roots(self):",
"- return [i for i, x in enumerate(self.parents) if x < 0]",
"-",
"- def group_count(self):",
"- return len(self.roots())",
"-",
"- def all_group_members(self):",
"- return {r: self.members(r) for r in self.roots()}",
"-",
"- def __str__(self):",
"- return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())",
"+def r(x):",
"+ if root[x] < 0:",
"+ return x",
"+ else:",
"+ root[x] = r(root[x])",
"+ return root[x]",
"-uf = UnionFind(N)",
"-for _ in range(M):",
"- a, b = [int(x) - 1 for x in input().split()]",
"- uf.union(a, b)",
"-ans = 0",
"-for i in range(N):",
"- ans = max(ans, uf.size(i))",
"-print(ans)",
"+def unite(x, y):",
"+ x = r(x)",
"+ y = r(y)",
"+ if x == y:",
"+ return",
"+ root[x] += root[y]",
"+ root[y] = x",
"+",
"+",
"+def size(x):",
"+ return -r(x)",
"+",
"+",
"+for i in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ a -= 1",
"+ b -= 1",
"+ unite(a, b)",
"+max_size = -min(root)",
"+print(max_size)"
] | false | 0.038807 | 0.085489 | 0.453937 | [
"s574210838",
"s119225243"
] |
u141786930 | p02679 | python | s600958229 | s631125896 | 1,654 | 835 | 92,552 | 95,936 | Accepted | Accepted | 49.52 | # E - ∙ (Bullet)
import sys
from collections import defaultdict
readline = sys.stdin.readline
MOD = 1000000007
N = int(readline())
# イワシの傾きをA/Bとする。
# A/Bは予めgcdで割って約分し、同じ傾きのものを揃えておく。
# このとき、仲の悪い組合せは(A, B)に対して(B, -A)となるもの。
# 前者をS、後者をTとして考える。
d_S = defaultdict(int)
d_T = defaultdict(int)
def gcd(x, y):
if x == 0:
return y
else:
return gcd(y%x, x)
pow2_mod = [1] + [0] * (N + 10)
for i in range(1, N + 10):
pow2_mod[i] = pow2_mod[i-1] * 2 % MOD
zeros = 0
for i in range(N):
A, B = list(map(int, readline().split()))
# (0, 0)のイワシは他の全てのイワシと仲が悪いため、
# 1匹のみでしか選ぶことができない。最後にこの数を足す。
if A == 0 and B == 0:
zeros += 1
# (?, 0),(0, ?)のイワシは、?がどのような数字であろうとも
# この組合せであれば仲が悪い。一律、(1,0)(0,-1)として考える。
elif A == 0:
d_S[(1, 0)] += 0
d_T[(0, -1)] += 1
elif B == 0:
d_S[(1, 0)] += 1
#d_T[(0, -1)] += 0
else:
g = gcd(A, B)
A //= g
B //= g
# いずれもマイナスの場合、傾きはプラスになる
if A < 0 and B < 0:
A *= -1
B *= -1
if A * B > 0:
d_S[(A, B)] += 1
#d_T[(B, -A)] += 0
# 片方がマイナスの場合、必ずAがマイナスになるよう揃える
else:
if A > B:
A, B = B, A
d_S[(-A, B)] += 0
d_T[(B, A)] += 1
ans = 1
for (si, sj), s_cnt in list(d_S.items()):
t_cnt = d_T[(sj, -1*si)]
tmp = 0
tmp += pow2_mod[s_cnt] - 1 # Sから1匹以上選ぶ組合せ
tmp += pow2_mod[t_cnt] - 1 # Tから1匹以上選ぶ組合せ
tmp += 1 # どちらも選ばない組合せ
ans = (ans * tmp)%MOD
ans -= 1 # 最終的に1匹も選ばない組合せ
ans += zeros # (0, 0)のイワシの数
print((ans%MOD)) | # E - ∙ (Bullet)
import sys
from collections import defaultdict
from math import gcd
readline = sys.stdin.readline
MOD = 1000000007
N = int(readline())
# イワシの傾きをA/Bとする。
# A/Bは予めgcdで割って約分し、同じ傾きのものを揃えておく。
# このとき、仲の悪い組合せは(A, B)に対して(B, -A)となるもの。
# 前者をS、後者をTとして考える。
d_S = defaultdict(int)
d_T = defaultdict(int)
'''
def gcd(x, y):
if x == 0:
return y
else:
return gcd(y%x, x)
'''
pow2_mod = [1] + [0] * (N + 10)
for i in range(1, N + 10):
pow2_mod[i] = pow2_mod[i-1] * 2 % MOD
zeros = 0
for i in range(N):
A, B = list(map(int, readline().split()))
# (0, 0)のイワシは他の全てのイワシと仲が悪いため、
# 1匹のみでしか選ぶことができない。最後にこの数を足す。
if A == 0 and B == 0:
zeros += 1
# (?, 0),(0, ?)のイワシは、?がどのような数字であろうとも
# この組合せであれば仲が悪い。一律、(1,0)(0,-1)として考える。
elif A == 0:
d_S[(1, 0)] += 0
d_T[(0, -1)] += 1
elif B == 0:
d_S[(1, 0)] += 1
#d_T[(0, -1)] += 0
else:
g = gcd(A, B)
A //= g
B //= g
if A < 0:
A *= -1
B *= -1
if A * B > 0:
d_S[(A, B)] += 1
#d_T[(B, -A)] += 0
else:
d_S[(-B, A)] += 0
d_T[(A, B)] += 1
ans = 1
for (si, sj), s_cnt in list(d_S.items()):
t_cnt = d_T[(sj, -1*si)]
tmp = 0
tmp += pow2_mod[s_cnt] - 1 # Sから1匹以上選ぶ組合せ
tmp += pow2_mod[t_cnt] - 1 # Tから1匹以上選ぶ組合せ
tmp += 1 # どちらも選ばない組合せ
ans = (ans * tmp)%MOD
ans -= 1 # 最終的に1匹も選ばない組合せ
ans += zeros # (0, 0)のイワシの数
print((ans%MOD)) | 71 | 70 | 1,657 | 1,555 | # E - ∙ (Bullet)
import sys
from collections import defaultdict
readline = sys.stdin.readline
MOD = 1000000007
N = int(readline())
# イワシの傾きをA/Bとする。
# A/Bは予めgcdで割って約分し、同じ傾きのものを揃えておく。
# このとき、仲の悪い組合せは(A, B)に対して(B, -A)となるもの。
# 前者をS、後者をTとして考える。
d_S = defaultdict(int)
d_T = defaultdict(int)
def gcd(x, y):
if x == 0:
return y
else:
return gcd(y % x, x)
pow2_mod = [1] + [0] * (N + 10)
for i in range(1, N + 10):
pow2_mod[i] = pow2_mod[i - 1] * 2 % MOD
zeros = 0
for i in range(N):
A, B = list(map(int, readline().split()))
# (0, 0)のイワシは他の全てのイワシと仲が悪いため、
# 1匹のみでしか選ぶことができない。最後にこの数を足す。
if A == 0 and B == 0:
zeros += 1
# (?, 0),(0, ?)のイワシは、?がどのような数字であろうとも
# この組合せであれば仲が悪い。一律、(1,0)(0,-1)として考える。
elif A == 0:
d_S[(1, 0)] += 0
d_T[(0, -1)] += 1
elif B == 0:
d_S[(1, 0)] += 1
# d_T[(0, -1)] += 0
else:
g = gcd(A, B)
A //= g
B //= g
# いずれもマイナスの場合、傾きはプラスになる
if A < 0 and B < 0:
A *= -1
B *= -1
if A * B > 0:
d_S[(A, B)] += 1
# d_T[(B, -A)] += 0
# 片方がマイナスの場合、必ずAがマイナスになるよう揃える
else:
if A > B:
A, B = B, A
d_S[(-A, B)] += 0
d_T[(B, A)] += 1
ans = 1
for (si, sj), s_cnt in list(d_S.items()):
t_cnt = d_T[(sj, -1 * si)]
tmp = 0
tmp += pow2_mod[s_cnt] - 1 # Sから1匹以上選ぶ組合せ
tmp += pow2_mod[t_cnt] - 1 # Tから1匹以上選ぶ組合せ
tmp += 1 # どちらも選ばない組合せ
ans = (ans * tmp) % MOD
ans -= 1 # 最終的に1匹も選ばない組合せ
ans += zeros # (0, 0)のイワシの数
print((ans % MOD))
| # E - ∙ (Bullet)
import sys
from collections import defaultdict
from math import gcd
readline = sys.stdin.readline
MOD = 1000000007
N = int(readline())
# イワシの傾きをA/Bとする。
# A/Bは予めgcdで割って約分し、同じ傾きのものを揃えておく。
# このとき、仲の悪い組合せは(A, B)に対して(B, -A)となるもの。
# 前者をS、後者をTとして考える。
d_S = defaultdict(int)
d_T = defaultdict(int)
"""
def gcd(x, y):
if x == 0:
return y
else:
return gcd(y%x, x)
"""
pow2_mod = [1] + [0] * (N + 10)
for i in range(1, N + 10):
pow2_mod[i] = pow2_mod[i - 1] * 2 % MOD
zeros = 0
for i in range(N):
A, B = list(map(int, readline().split()))
# (0, 0)のイワシは他の全てのイワシと仲が悪いため、
# 1匹のみでしか選ぶことができない。最後にこの数を足す。
if A == 0 and B == 0:
zeros += 1
# (?, 0),(0, ?)のイワシは、?がどのような数字であろうとも
# この組合せであれば仲が悪い。一律、(1,0)(0,-1)として考える。
elif A == 0:
d_S[(1, 0)] += 0
d_T[(0, -1)] += 1
elif B == 0:
d_S[(1, 0)] += 1
# d_T[(0, -1)] += 0
else:
g = gcd(A, B)
A //= g
B //= g
if A < 0:
A *= -1
B *= -1
if A * B > 0:
d_S[(A, B)] += 1
# d_T[(B, -A)] += 0
else:
d_S[(-B, A)] += 0
d_T[(A, B)] += 1
ans = 1
for (si, sj), s_cnt in list(d_S.items()):
t_cnt = d_T[(sj, -1 * si)]
tmp = 0
tmp += pow2_mod[s_cnt] - 1 # Sから1匹以上選ぶ組合せ
tmp += pow2_mod[t_cnt] - 1 # Tから1匹以上選ぶ組合せ
tmp += 1 # どちらも選ばない組合せ
ans = (ans * tmp) % MOD
ans -= 1 # 最終的に1匹も選ばない組合せ
ans += zeros # (0, 0)のイワシの数
print((ans % MOD))
| false | 1.408451 | [
"+from math import gcd",
"-",
"-",
"+\"\"\"",
"- return gcd(y % x, x)",
"-",
"-",
"+ return gcd(y%x, x)",
"+\"\"\"",
"- # いずれもマイナスの場合、傾きはプラスになる",
"- if A < 0 and B < 0:",
"+ if A < 0:",
"- # 片方がマイナスの場合、必ずAがマイナスになるよう揃える",
"- if A > B:",
"- A, B = B, A",
"- d_S[(-A, B)] += 0",
"- d_T[(B, A)] += 1",
"+ d_S[(-B, A)] += 0",
"+ d_T[(A, B)] += 1"
] | false | 0.041049 | 0.041972 | 0.978009 | [
"s600958229",
"s631125896"
] |
u588341295 | p02803 | python | s183797955 | s676859550 | 329 | 258 | 3,440 | 3,828 | Accepted | Accepted | 21.58 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H+offset*2, W+offset*2, intv)
for i in range(offset, H+offset):
row = _list()
for j in range(offset, W+offset):
grid[i][j] = row[j-offset]
return grid
def bfs(grid, src):
""" BFS(グリッド、重みなし) """
from collections import deque
H, W = len(grid), len(grid[0])
h, w = src
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
que = deque([(h, w, 0)])
dist = list2d(H+2, W+2, -1)
while que:
h, w, c = que.popleft()
if dist[h][w] != -1:
continue
dist[h][w] = c
for dh, dw in directions:
h2 = h + dh
w2 = w + dw
if grid[h2][w2] == '#':
continue
que.append((h2, w2, c+1))
return dist
H, W = MAP()
grid = build_grid(H, W, '#', str, space=0, padding=1)
ans = 0
for i in range(1, H+1):
for j in range(1, W+1):
if grid[i][j] != '#':
# 有効な全マスから最短距離試す
res = bfs(grid, (i, j))
for k in range(1, H+1):
for l in range(1, W+1):
# 一番遠い場所
ans = max(ans, res[k][l])
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H+offset*2, W+offset*2, intv)
for i in range(offset, H+offset):
row = _list()
for j in range(offset, W+offset):
grid[i][j] = row[j-offset]
return grid
def bfs(grid, src):
""" BFS(グリッド、重みなし) """
from collections import deque
H, W = len(grid), len(grid[0])
h, w = src
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
que = deque([(h, w, 0)])
dist = list2d(H, W, -1)
dist[h][w] = 0
while que:
h, w, c = que.popleft()
for dh, dw in directions:
h2 = h + dh
w2 = w + dw
if grid[h2][w2] == '#':
continue
if dist[h2][w2] != -1:
continue
dist[h2][w2] = c + 1
que.append((h2, w2, c+1))
return dist
H, W = MAP()
grid = build_grid(H, W, '#', str, space=0, padding=1)
ans = 0
for i in range(1, H+1):
for j in range(1, W+1):
if grid[i][j] != '#':
# 有効な全マスから最短距離試す
res = bfs(grid, (i, j))
for k in range(1, H+1):
for l in range(1, W+1):
# 一番遠い場所
ans = max(ans, res[k][l])
print(ans)
| 75 | 76 | 2,209 | 2,245 | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H + offset * 2, W + offset * 2, intv)
for i in range(offset, H + offset):
row = _list()
for j in range(offset, W + offset):
grid[i][j] = row[j - offset]
return grid
def bfs(grid, src):
"""BFS(グリッド、重みなし)"""
from collections import deque
H, W = len(grid), len(grid[0])
h, w = src
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
que = deque([(h, w, 0)])
dist = list2d(H + 2, W + 2, -1)
while que:
h, w, c = que.popleft()
if dist[h][w] != -1:
continue
dist[h][w] = c
for dh, dw in directions:
h2 = h + dh
w2 = w + dw
if grid[h2][w2] == "#":
continue
que.append((h2, w2, c + 1))
return dist
H, W = MAP()
grid = build_grid(H, W, "#", str, space=0, padding=1)
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if grid[i][j] != "#":
# 有効な全マスから最短距離試す
res = bfs(grid, (i, j))
for k in range(1, H + 1):
for l in range(1, W + 1):
# 一番遠い場所
ans = max(ans, res[k][l])
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H + offset * 2, W + offset * 2, intv)
for i in range(offset, H + offset):
row = _list()
for j in range(offset, W + offset):
grid[i][j] = row[j - offset]
return grid
def bfs(grid, src):
"""BFS(グリッド、重みなし)"""
from collections import deque
H, W = len(grid), len(grid[0])
h, w = src
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
que = deque([(h, w, 0)])
dist = list2d(H, W, -1)
dist[h][w] = 0
while que:
h, w, c = que.popleft()
for dh, dw in directions:
h2 = h + dh
w2 = w + dw
if grid[h2][w2] == "#":
continue
if dist[h2][w2] != -1:
continue
dist[h2][w2] = c + 1
que.append((h2, w2, c + 1))
return dist
H, W = MAP()
grid = build_grid(H, W, "#", str, space=0, padding=1)
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if grid[i][j] != "#":
# 有効な全マスから最短距離試す
res = bfs(grid, (i, j))
for k in range(1, H + 1):
for l in range(1, W + 1):
# 一番遠い場所
ans = max(ans, res[k][l])
print(ans)
| false | 1.315789 | [
"- dist = list2d(H + 2, W + 2, -1)",
"+ dist = list2d(H, W, -1)",
"+ dist[h][w] = 0",
"- if dist[h][w] != -1:",
"- continue",
"- dist[h][w] = c",
"+ if dist[h2][w2] != -1:",
"+ continue",
"+ dist[h2][w2] = c + 1"
] | false | 0.04624 | 0.046139 | 1.002187 | [
"s183797955",
"s676859550"
] |
u312025627 | p03371 | python | s419396854 | s584620829 | 165 | 17 | 38,256 | 3,060 | Accepted | Accepted | 89.7 | def main():
a, b, c, x, y = (int(i) for i in input().split())
ans = a*x + b*y
cur = 2*c*min(x, y) + (a*(x-y) if x > y else b*(y-x))
ans = min(ans, cur)
cur = 2*c*max(x, y)
ans = min(ans, cur)
print(ans)
if __name__ == '__main__':
main()
| def main():
a, b, c, x, y = (int(i) for i in input().split())
ans = a*x + b*y
ans = min(ans, 2*c*max(x, y))
if x < y:
d = y-x
d *= b
else:
d = x-y
d *= a
ans = min(ans, 2*c*min(x, y) + d)
print(ans)
if __name__ == '__main__':
main()
| 12 | 16 | 282 | 314 | def main():
a, b, c, x, y = (int(i) for i in input().split())
ans = a * x + b * y
cur = 2 * c * min(x, y) + (a * (x - y) if x > y else b * (y - x))
ans = min(ans, cur)
cur = 2 * c * max(x, y)
ans = min(ans, cur)
print(ans)
if __name__ == "__main__":
main()
| def main():
a, b, c, x, y = (int(i) for i in input().split())
ans = a * x + b * y
ans = min(ans, 2 * c * max(x, y))
if x < y:
d = y - x
d *= b
else:
d = x - y
d *= a
ans = min(ans, 2 * c * min(x, y) + d)
print(ans)
if __name__ == "__main__":
main()
| false | 25 | [
"- cur = 2 * c * min(x, y) + (a * (x - y) if x > y else b * (y - x))",
"- ans = min(ans, cur)",
"- cur = 2 * c * max(x, y)",
"- ans = min(ans, cur)",
"+ ans = min(ans, 2 * c * max(x, y))",
"+ if x < y:",
"+ d = y - x",
"+ d *= b",
"+ else:",
"+ d = x - y",
"+ d *= a",
"+ ans = min(ans, 2 * c * min(x, y) + d)"
] | false | 0.044462 | 0.042447 | 1.047479 | [
"s419396854",
"s584620829"
] |
u729133443 | p02538 | python | s612785031 | s736213419 | 321 | 280 | 23,484 | 23,416 | Accepted | Accepted | 12.77 | code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
# cython: cdivision=True
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/lazysegtree>" namespace "atcoder" nogil:
cdef cppclass lazy_segtree[S, OP, E, F, mapping, composition, id]:
lazy_segtree(vector[S] v)
void set(int p, S x)
S get(int p)
S prod(int l, int r)
S all_prod()
void apply(int p, F f)
void apply(int l, int r, F f)
int max_right[G](int l)
int min_left[G](int r)
cdef struct s_t:
long v, s
ctypedef long f_t
cdef extern from *:
ctypedef int op_t "myop"
ctypedef int e_t "mye"
ctypedef int m_t "mymapping"
ctypedef int c_t "mycomposition"
ctypedef int i_t "myid"
ctypedef int g_t "myg"
cdef s_t myop(s_t a, s_t b) nogil
cdef s_t mye() nogil
cdef s_t mymapping(f_t f, s_t x) nogil
cdef f_t mycomposition(f_t f, f_t g) nogil
cdef f_t myid() nogil
cdef bool myg(s_t k) nogil
cdef s_t myop(s_t a, s_t b) nogil:
cdef s_t c
c.v = (a.v * b.s + b.v) % 998244353
c.s = (a.s * b.s) % 998244353
return c
cdef s_t mye() nogil:
cdef s_t e
e.v = 0
e.s = 1
return e
cdef f_t myid() nogil:
return -1
cdef s_t mymapping(f_t f, s_t x) nogil:
if f == myid(): return x
cdef s_t y
y.v = (x.s - 1) * 443664157 * f % 998244353
y.s = x.s
return y
cdef f_t mycomposition(f_t f, f_t g) nogil:
if f == myid(): return g
return f
from libc.stdio cimport getchar, printf
cdef inline long read() nogil:
cdef long b, c = 0
while 1:
b = getchar() - 48
if b < 0: return c
c = c * 10 + b
cdef main():
cdef long n = read(), i, l, r, d
cdef s_t a
a.v = 1
a.s = 10
cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, a))
for i in range(read()):
l, r, d = read(), read(), read()
seg.apply(l - 1, r, d)
printf('%ld\n', seg.all_prod().v)
main()
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
open('solve.pyx', 'w').write(code)
os.system('cythonize -i -3 -b solve.pyx')
import solve | code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
# cython: cdivision=True
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/lazysegtree>" namespace "atcoder":
cdef cppclass lazy_segtree[S, OP, E, F, mapping, composition, id]:
lazy_segtree(vector[S] v)
void set(int p, S x)
S get(int p)
S prod(int l, int r)
S all_prod()
void apply(int p, F f)
void apply(int l, int r, F f)
int max_right[G](int l)
int min_left[G](int r)
DEF mod = 998244353
cdef struct s_t:
long v, s
ctypedef long f_t
cdef extern from *:
ctypedef int op_t "myop"
ctypedef int e_t "mye"
ctypedef int m_t "mymapping"
ctypedef int c_t "mycomposition"
ctypedef int i_t "myid"
ctypedef int g_t "myg"
cdef s_t myop(s_t a, s_t b)
cdef s_t mye()
cdef s_t mymapping(f_t f, s_t x)
cdef f_t mycomposition(f_t f, f_t g)
cdef f_t myid()
cdef bool myg(s_t k)
cdef s_t myop(s_t a, s_t b):
return s_t((a.v * b.s + b.v) % mod, (a.s * b.s) % mod)
cdef s_t mye():
return s_t(0, 1)
cdef f_t myid():
return -1
cdef s_t mymapping(f_t f, s_t x):
if f == myid(): return x
return s_t((x.s - 1) * 443664157 * f % mod, x.s)
cdef f_t mycomposition(f_t f, f_t g):
if f == myid(): return g
return f
from libc.stdio cimport getchar, printf
cdef inline long read():
cdef long b, c = 0
while 1:
b = getchar() - 48
if b < 0: return c
c = c * 10 + b
cdef main():
cdef long n = read(), i, l, r, d
cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, s_t(1, 10)))
for i in range(read()):
l, r, d = read(), read(), read()
seg.apply(l - 1, r, d)
printf('%ld\n', seg.all_prod().v)
main()
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
open('solve.pyx', 'w').write(code)
os.system('cythonize -i -3 -b solve.pyx')
import solve | 78 | 67 | 2,310 | 2,099 | code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
# cython: cdivision=True
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/lazysegtree>" namespace "atcoder" nogil:
cdef cppclass lazy_segtree[S, OP, E, F, mapping, composition, id]:
lazy_segtree(vector[S] v)
void set(int p, S x)
S get(int p)
S prod(int l, int r)
S all_prod()
void apply(int p, F f)
void apply(int l, int r, F f)
int max_right[G](int l)
int min_left[G](int r)
cdef struct s_t:
long v, s
ctypedef long f_t
cdef extern from *:
ctypedef int op_t "myop"
ctypedef int e_t "mye"
ctypedef int m_t "mymapping"
ctypedef int c_t "mycomposition"
ctypedef int i_t "myid"
ctypedef int g_t "myg"
cdef s_t myop(s_t a, s_t b) nogil
cdef s_t mye() nogil
cdef s_t mymapping(f_t f, s_t x) nogil
cdef f_t mycomposition(f_t f, f_t g) nogil
cdef f_t myid() nogil
cdef bool myg(s_t k) nogil
cdef s_t myop(s_t a, s_t b) nogil:
cdef s_t c
c.v = (a.v * b.s + b.v) % 998244353
c.s = (a.s * b.s) % 998244353
return c
cdef s_t mye() nogil:
cdef s_t e
e.v = 0
e.s = 1
return e
cdef f_t myid() nogil:
return -1
cdef s_t mymapping(f_t f, s_t x) nogil:
if f == myid(): return x
cdef s_t y
y.v = (x.s - 1) * 443664157 * f % 998244353
y.s = x.s
return y
cdef f_t mycomposition(f_t f, f_t g) nogil:
if f == myid(): return g
return f
from libc.stdio cimport getchar, printf
cdef inline long read() nogil:
cdef long b, c = 0
while 1:
b = getchar() - 48
if b < 0: return c
c = c * 10 + b
cdef main():
cdef long n = read(), i, l, r, d
cdef s_t a
a.v = 1
a.s = 10
cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, a))
for i in range(read()):
l, r, d = read(), read(), read()
seg.apply(l - 1, r, d)
printf('%ld\n', seg.all_prod().v)
main()
"""
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
open("solve.pyx", "w").write(code)
os.system("cythonize -i -3 -b solve.pyx")
import solve
| code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
# cython: cdivision=True
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/lazysegtree>" namespace "atcoder":
cdef cppclass lazy_segtree[S, OP, E, F, mapping, composition, id]:
lazy_segtree(vector[S] v)
void set(int p, S x)
S get(int p)
S prod(int l, int r)
S all_prod()
void apply(int p, F f)
void apply(int l, int r, F f)
int max_right[G](int l)
int min_left[G](int r)
DEF mod = 998244353
cdef struct s_t:
long v, s
ctypedef long f_t
cdef extern from *:
ctypedef int op_t "myop"
ctypedef int e_t "mye"
ctypedef int m_t "mymapping"
ctypedef int c_t "mycomposition"
ctypedef int i_t "myid"
ctypedef int g_t "myg"
cdef s_t myop(s_t a, s_t b)
cdef s_t mye()
cdef s_t mymapping(f_t f, s_t x)
cdef f_t mycomposition(f_t f, f_t g)
cdef f_t myid()
cdef bool myg(s_t k)
cdef s_t myop(s_t a, s_t b):
return s_t((a.v * b.s + b.v) % mod, (a.s * b.s) % mod)
cdef s_t mye():
return s_t(0, 1)
cdef f_t myid():
return -1
cdef s_t mymapping(f_t f, s_t x):
if f == myid(): return x
return s_t((x.s - 1) * 443664157 * f % mod, x.s)
cdef f_t mycomposition(f_t f, f_t g):
if f == myid(): return g
return f
from libc.stdio cimport getchar, printf
cdef inline long read():
cdef long b, c = 0
while 1:
b = getchar() - 48
if b < 0: return c
c = c * 10 + b
cdef main():
cdef long n = read(), i, l, r, d
cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, s_t(1, 10)))
for i in range(read()):
l, r, d = read(), read(), read()
seg.apply(l - 1, r, d)
printf('%ld\n', seg.all_prod().v)
main()
"""
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
open("solve.pyx", "w").write(code)
os.system("cythonize -i -3 -b solve.pyx")
import solve
| false | 14.102564 | [
"-cdef extern from \"<atcoder/lazysegtree>\" namespace \"atcoder\" nogil:",
"+cdef extern from \"<atcoder/lazysegtree>\" namespace \"atcoder\":",
"+DEF mod = 998244353",
"- cdef s_t myop(s_t a, s_t b) nogil",
"- cdef s_t mye() nogil",
"- cdef s_t mymapping(f_t f, s_t x) nogil",
"- cdef f_t mycomposition(f_t f, f_t g) nogil",
"- cdef f_t myid() nogil",
"- cdef bool myg(s_t k) nogil",
"-cdef s_t myop(s_t a, s_t b) nogil:",
"- cdef s_t c",
"- c.v = (a.v * b.s + b.v) % 998244353",
"- c.s = (a.s * b.s) % 998244353",
"- return c",
"-cdef s_t mye() nogil:",
"- cdef s_t e",
"- e.v = 0",
"- e.s = 1",
"- return e",
"-cdef f_t myid() nogil:",
"+ cdef s_t myop(s_t a, s_t b)",
"+ cdef s_t mye()",
"+ cdef s_t mymapping(f_t f, s_t x)",
"+ cdef f_t mycomposition(f_t f, f_t g)",
"+ cdef f_t myid()",
"+ cdef bool myg(s_t k)",
"+cdef s_t myop(s_t a, s_t b):",
"+ return s_t((a.v * b.s + b.v) % mod, (a.s * b.s) % mod)",
"+cdef s_t mye():",
"+ return s_t(0, 1)",
"+cdef f_t myid():",
"-cdef s_t mymapping(f_t f, s_t x) nogil:",
"+cdef s_t mymapping(f_t f, s_t x):",
"- cdef s_t y",
"- y.v = (x.s - 1) * 443664157 * f % 998244353",
"- y.s = x.s",
"- return y",
"-cdef f_t mycomposition(f_t f, f_t g) nogil:",
"+ return s_t((x.s - 1) * 443664157 * f % mod, x.s)",
"+cdef f_t mycomposition(f_t f, f_t g):",
"-cdef inline long read() nogil:",
"+cdef inline long read():",
"- cdef s_t a",
"- a.v = 1",
"- a.s = 10",
"- cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, a))",
"+ cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, s_t(1, 10)))"
] | false | 0.127388 | 0.046163 | 2.759542 | [
"s612785031",
"s736213419"
] |
u159994501 | p02755 | python | s577839762 | s474072892 | 20 | 18 | 3,188 | 2,940 | Accepted | Accepted | 10 | import math
A, B = list(map(int, input().split()))
A_min = math.ceil(A * 12.5)
A_max = math.ceil((A + 1) * 12.5) - 1
B_min = math.ceil(B * 10)
B_max = math.ceil((B + 1) * 10) - 1
# print(A_min, A_max, B_min, B_max)
candidate = max(A_min, B_min)
if candidate < min(A_max, B_max):
print(candidate)
else:
print('-1')
| import math
A, B = list(map(int, input().split()))
for i in range(1, 1001):
if math.floor(0.08 * i) == A and math.floor(0.1 * i) == B:
print(i)
exit()
print((-1))
| 15 | 8 | 333 | 183 | import math
A, B = list(map(int, input().split()))
A_min = math.ceil(A * 12.5)
A_max = math.ceil((A + 1) * 12.5) - 1
B_min = math.ceil(B * 10)
B_max = math.ceil((B + 1) * 10) - 1
# print(A_min, A_max, B_min, B_max)
candidate = max(A_min, B_min)
if candidate < min(A_max, B_max):
print(candidate)
else:
print("-1")
| import math
A, B = list(map(int, input().split()))
for i in range(1, 1001):
if math.floor(0.08 * i) == A and math.floor(0.1 * i) == B:
print(i)
exit()
print((-1))
| false | 46.666667 | [
"-A_min = math.ceil(A * 12.5)",
"-A_max = math.ceil((A + 1) * 12.5) - 1",
"-B_min = math.ceil(B * 10)",
"-B_max = math.ceil((B + 1) * 10) - 1",
"-# print(A_min, A_max, B_min, B_max)",
"-candidate = max(A_min, B_min)",
"-if candidate < min(A_max, B_max):",
"- print(candidate)",
"-else:",
"- print(\"-1\")",
"+for i in range(1, 1001):",
"+ if math.floor(0.08 * i) == A and math.floor(0.1 * i) == B:",
"+ print(i)",
"+ exit()",
"+print((-1))"
] | false | 0.228833 | 0.203424 | 1.12491 | [
"s577839762",
"s474072892"
] |
u245870380 | p02802 | python | s966365972 | s249779544 | 397 | 348 | 36,156 | 3,828 | Accepted | Accepted | 12.34 | N, M = list(map(int, input().split()))
lis = [list(input().split()) for _ in range(M)]
AC = [[0] * 2 for i in range(N)]
for i in range(M):
if lis[i][1] == "AC":
AC[int(lis[i][0])-1][1] = 1
elif AC[int(lis[i][0])-1][1] == 0:
AC[int(lis[i][0])-1][0] += 1
a = 0
w = 0
for i in range(N):
if AC[i][1] == 1:
a += 1
w += AC[i][0]
print((a, w))
| N, M = list(map(int, input().split()))
P = [0] * 10**5
score, penalty = 0, 0
for i in range(M):
p, s = list(map(str, input().split()))
p = int(p)
if s == 'AC' and P[p-1] != -1:
penalty += P[p-1]
score += 1
P[p-1] = -1
elif P[p-1] != -1:
P[p-1] += 1
print((score, penalty))
| 15 | 13 | 387 | 319 | N, M = list(map(int, input().split()))
lis = [list(input().split()) for _ in range(M)]
AC = [[0] * 2 for i in range(N)]
for i in range(M):
if lis[i][1] == "AC":
AC[int(lis[i][0]) - 1][1] = 1
elif AC[int(lis[i][0]) - 1][1] == 0:
AC[int(lis[i][0]) - 1][0] += 1
a = 0
w = 0
for i in range(N):
if AC[i][1] == 1:
a += 1
w += AC[i][0]
print((a, w))
| N, M = list(map(int, input().split()))
P = [0] * 10**5
score, penalty = 0, 0
for i in range(M):
p, s = list(map(str, input().split()))
p = int(p)
if s == "AC" and P[p - 1] != -1:
penalty += P[p - 1]
score += 1
P[p - 1] = -1
elif P[p - 1] != -1:
P[p - 1] += 1
print((score, penalty))
| false | 13.333333 | [
"-lis = [list(input().split()) for _ in range(M)]",
"-AC = [[0] * 2 for i in range(N)]",
"+P = [0] * 10**5",
"+score, penalty = 0, 0",
"- if lis[i][1] == \"AC\":",
"- AC[int(lis[i][0]) - 1][1] = 1",
"- elif AC[int(lis[i][0]) - 1][1] == 0:",
"- AC[int(lis[i][0]) - 1][0] += 1",
"-a = 0",
"-w = 0",
"-for i in range(N):",
"- if AC[i][1] == 1:",
"- a += 1",
"- w += AC[i][0]",
"-print((a, w))",
"+ p, s = list(map(str, input().split()))",
"+ p = int(p)",
"+ if s == \"AC\" and P[p - 1] != -1:",
"+ penalty += P[p - 1]",
"+ score += 1",
"+ P[p - 1] = -1",
"+ elif P[p - 1] != -1:",
"+ P[p - 1] += 1",
"+print((score, penalty))"
] | false | 0.062835 | 0.037692 | 1.667079 | [
"s966365972",
"s249779544"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.