user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u347640436 | p02973 | python | s374382229 | s969861331 | 510 | 229 | 8,828 | 11,752 | Accepted | Accepted | 55.1 | from collections import deque
from bisect import bisect_left
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = deque([A[0]])
for a in A[1:]:
i = bisect_left(t, a) - 1
if i == -1:
t.appendleft(a)
else:
t[i] = a
print((len(t)))
| from bisect import bisect_right
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = [-A[0]]
for a in A[1:]:
if a <= -t[-1]:
t.append(-a)
else:
t[bisect_right(t, -a)] = -a
print((len(t)))
| 14 | 12 | 275 | 228 | from collections import deque
from bisect import bisect_left
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = deque([A[0]])
for a in A[1:]:
i = bisect_left(t, a) - 1
if i == -1:
t.appendleft(a)
else:
t[i] = a
print((len(t)))
| from bisect import bisect_right
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
t = [-A[0]]
for a in A[1:]:
if a <= -t[-1]:
t.append(-a)
else:
t[bisect_right(t, -a)] = -a
print((len(t)))
| false | 14.285714 | [
"-from collections import deque",
"-from bisect import bisect_left",
"+from bisect import bisect_right",
"-t = deque([A[0]])",
"+t = [-A[0]]",
"- i = bisect_left(t, a) - 1",
"- if i == -1:",
"- t.appendleft(a)",
"+ if a <= -t[-1]:",
"+ t.append(-a)",
"- t[i] = a",
"+ t[bisect_right(t, -a)] = -a"
] | false | 0.044646 | 0.043311 | 1.030824 | [
"s374382229",
"s969861331"
] |
u225388820 | p03166 | python | s242099194 | s651400245 | 482 | 393 | 59,056 | 194,100 | Accepted | Accepted | 18.46 | #解説AC
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n,m=list(map(int,input().split()))
es=[[] for i in range(n)]
for i in range(m):
x,y=list(map(int,input().split()))
es[x-1].append(y-1)
dp=[-1]*n
def memo(v):
if dp[v]+1: #更新済 dp[v]!=-1
return dp[v]
a=0
for i in es[v]:
a=max(a,memo(i)+1)
dp[v]=a
return a
ans=0
for i in range(n):
ans=max(ans,memo(i))
print(ans) | # 根付き木に対して根から最大でどれだけかかるかを使う方法
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(m):
a, b = list(map(int, input().split()))
co[b - 1].append(a - 1)
dp = [-1] * n
def memo(v):
if dp[v] != -1: #更新済
return dp[v]
for i in co[v]:
x = memo(i) + 1
if x > dp[v]:
parent[v] = i + 1
dp[v] = x
return max(dp[v], 0)
# 経路復元
parent = [0] * n
ans = 0
for i in range(n):
ans = max(ans, memo(i))
print(ans) | 28 | 33 | 457 | 610 | # 解説AC
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
es = [[] for i in range(n)]
for i in range(m):
x, y = list(map(int, input().split()))
es[x - 1].append(y - 1)
dp = [-1] * n
def memo(v):
if dp[v] + 1: # 更新済 dp[v]!=-1
return dp[v]
a = 0
for i in es[v]:
a = max(a, memo(i) + 1)
dp[v] = a
return a
ans = 0
for i in range(n):
ans = max(ans, memo(i))
print(ans)
| # 根付き木に対して根から最大でどれだけかかるかを使う方法
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(m):
a, b = list(map(int, input().split()))
co[b - 1].append(a - 1)
dp = [-1] * n
def memo(v):
if dp[v] != -1: # 更新済
return dp[v]
for i in co[v]:
x = memo(i) + 1
if x > dp[v]:
parent[v] = i + 1
dp[v] = x
return max(dp[v], 0)
# 経路復元
parent = [0] * n
ans = 0
for i in range(n):
ans = max(ans, memo(i))
print(ans)
| false | 15.151515 | [
"-# 解説AC",
"+# 根付き木に対して根から最大でどれだけかかるかを使う方法",
"-es = [[] for i in range(n)]",
"+co = [[] for i in range(n)] # 有効辺の向きを逆にした",
"- x, y = list(map(int, input().split()))",
"- es[x - 1].append(y - 1)",
"+ a, b = list(map(int, input().split()))",
"+ co[b - 1].append(a - 1)",
"- if dp[v] + 1: # 更新済 dp[v]!=-1",
"+ if dp[v] != -1: # 更新済",
"- a = 0",
"- for i in es[v]:",
"- a = max(a, memo(i) + 1)",
"- dp[v] = a",
"- return a",
"+ for i in co[v]:",
"+ x = memo(i) + 1",
"+ if x > dp[v]:",
"+ parent[v] = i + 1",
"+ dp[v] = x",
"+ return max(dp[v], 0)",
"+# 経路復元",
"+parent = [0] * n"
] | false | 0.04606 | 0.082443 | 0.558692 | [
"s242099194",
"s651400245"
] |
u864013199 | p03286 | python | s050796065 | s764044644 | 176 | 17 | 13,356 | 3,064 | Accepted | Accepted | 90.34 | from numpy import cumsum
N = int(eval(input()))
lis = [0]*40
tmp = [0,2]+[2**(i*2) for i in range(1,23)]
rui = cumsum(tmp)
for i in range(40):
if i==0:
if N%2 == 1:
lis[0]=1
else:
if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
lis[i]=1
print((int("".join(map(str,reversed(lis))))))
| N = int(eval(input()))
lis = [0]*40
tmp = [2]+[2**(i*2) for i in range(1,23)]
rui = [0]
for t in tmp:
rui.append(rui[-1]+t)
for i in range(40):
if i==0:
if N%2 == 1:
lis[0]=1
else:
if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
lis[i]=1
print((int("".join(map(str,reversed(lis))))))
| 15 | 16 | 332 | 338 | from numpy import cumsum
N = int(eval(input()))
lis = [0] * 40
tmp = [0, 2] + [2 ** (i * 2) for i in range(1, 23)]
rui = cumsum(tmp)
for i in range(40):
if i == 0:
if N % 2 == 1:
lis[0] = 1
else:
if (N - rui[(i + 1) // 2]) % ((2**i) * 2) < 2**i:
lis[i] = 1
print((int("".join(map(str, reversed(lis))))))
| N = int(eval(input()))
lis = [0] * 40
tmp = [2] + [2 ** (i * 2) for i in range(1, 23)]
rui = [0]
for t in tmp:
rui.append(rui[-1] + t)
for i in range(40):
if i == 0:
if N % 2 == 1:
lis[0] = 1
else:
if (N - rui[(i + 1) // 2]) % ((2**i) * 2) < 2**i:
lis[i] = 1
print((int("".join(map(str, reversed(lis))))))
| false | 6.25 | [
"-from numpy import cumsum",
"-",
"-tmp = [0, 2] + [2 ** (i * 2) for i in range(1, 23)]",
"-rui = cumsum(tmp)",
"+tmp = [2] + [2 ** (i * 2) for i in range(1, 23)]",
"+rui = [0]",
"+for t in tmp:",
"+ rui.append(rui[-1] + t)"
] | false | 0.552438 | 0.047144 | 11.718165 | [
"s050796065",
"s764044644"
] |
u699089116 | p02832 | python | s796306845 | s539041019 | 240 | 108 | 77,516 | 26,140 | Accepted | Accepted | 55 | n = int(eval(input()))
a = list(map(int, input().split()))
if 1 not in a:
print((-1))
exit()
now = 1
ans = 0
for i in a:
if i != now:
ans += 1
else:
now += 1
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
now = 1
for i, v in enumerate(a):
if v == now:
now += 1
continue
else:
cnt += 1
print((cnt if cnt != len(a) else -1)) | 16 | 13 | 210 | 222 | n = int(eval(input()))
a = list(map(int, input().split()))
if 1 not in a:
print((-1))
exit()
now = 1
ans = 0
for i in a:
if i != now:
ans += 1
else:
now += 1
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
now = 1
for i, v in enumerate(a):
if v == now:
now += 1
continue
else:
cnt += 1
print((cnt if cnt != len(a) else -1))
| false | 18.75 | [
"-if 1 not in a:",
"- print((-1))",
"- exit()",
"+cnt = 0",
"-ans = 0",
"-for i in a:",
"- if i != now:",
"- ans += 1",
"+for i, v in enumerate(a):",
"+ if v == now:",
"+ now += 1",
"+ continue",
"- now += 1",
"-print(ans)",
"+ cnt += 1",
"+print((cnt if cnt != len(a) else -1))"
] | false | 0.033955 | 0.033454 | 1.014973 | [
"s796306845",
"s539041019"
] |
u906428167 | p02686 | python | s397783588 | s498214617 | 1,110 | 1,019 | 181,276 | 227,984 | Accepted | Accepted | 8.2 | n = int(eval(input()))
left = []
mid = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = eval(input())
l = 0
r = 0
for x in s:
if x == '(':
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
mid.append((r, l)) # a,b-a
else:
midminus.append((r,l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print('No')
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
mid = sorted(mid, key=lambda x: (x[0],-x[1]))
midminus = sorted(midminus,key= lambda x:x[0]-x[1])
mid += midminus
l = A
r = 0
for a, b in mid:
if l < a:
print('No')
exit()
l -= a
l += b
print('Yes') | n = int(eval(input()))
left = []
mid = []
zero = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = eval(input())
l = 0
r = 0
for x in s:
if x == '(':
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
mid.append((r, l)) # a,b-a
elif l == r:
zero.append((r,l))
else:
midminus.append((r, l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print('No')
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
mid = sorted(mid, key=lambda x: (x[0], -x[1]))
midminus = sorted(midminus, key=lambda x: -x[1])
mid += zero + midminus
l = A
r = 0
for a, b in mid:
if l < a:
print('No')
exit()
l -= a
l += b
print('Yes')
| 57 | 60 | 967 | 1,039 | n = int(eval(input()))
left = []
mid = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = eval(input())
l = 0
r = 0
for x in s:
if x == "(":
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
mid.append((r, l)) # a,b-a
else:
midminus.append((r, l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print("No")
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
mid = sorted(mid, key=lambda x: (x[0], -x[1]))
midminus = sorted(midminus, key=lambda x: x[0] - x[1])
mid += midminus
l = A
r = 0
for a, b in mid:
if l < a:
print("No")
exit()
l -= a
l += b
print("Yes")
| n = int(eval(input()))
left = []
mid = []
zero = []
midminus = []
right = []
L = []
R = []
for i in range(n):
s = eval(input())
l = 0
r = 0
for x in s:
if x == "(":
l += 1
else:
if l > 0:
l -= 1
else:
r += 1
if l > 0 and r == 0:
left.append((l, r))
elif l > 0 and r > 0:
if l > r:
mid.append((r, l)) # a,b-a
elif l == r:
zero.append((r, l))
else:
midminus.append((r, l))
elif l == 0 and r > 0:
right.append((l, r))
L.append(l)
R.append(r)
if sum(L) != sum(R):
print("No")
exit()
A = 0
B = 0
for x in left:
A += x[0]
for x in right:
B += x[1]
mid = sorted(mid, key=lambda x: (x[0], -x[1]))
midminus = sorted(midminus, key=lambda x: -x[1])
mid += zero + midminus
l = A
r = 0
for a, b in mid:
if l < a:
print("No")
exit()
l -= a
l += b
print("Yes")
| false | 5 | [
"+zero = []",
"+ elif l == r:",
"+ zero.append((r, l))",
"-midminus = sorted(midminus, key=lambda x: x[0] - x[1])",
"-mid += midminus",
"+midminus = sorted(midminus, key=lambda x: -x[1])",
"+mid += zero + midminus"
] | false | 0.047371 | 0.046034 | 1.029043 | [
"s397783588",
"s498214617"
] |
u102275718 | p02873 | python | s235237307 | s587654128 | 695 | 433 | 32,552 | 31,132 | Accepted | Accepted | 37.7 | import sys
input = sys.stdin.readline
import numpy as np
s = input()[:-1]
cnts = []
tmp = 1
for i in range(len(s)-1):
if s[i] == s[i+1]:
tmp += 1
else:
if s[i] == '>':
tmp *= -1
cnts.append(tmp)
tmp = 1
if s[-1] == '>':
tmp *= -1
cnts.append(tmp)
idx = 0
a = [0] * (len(s)+1)
for i in range(len(cnts)):
if i != 0 and cnts[i-1] > 0 and cnts[i] < 0 and a[idx-1] >= abs(cnts[i]):
a[idx] = a[idx-1] + 1
for j in range(abs(cnts[i])):
if a[idx] != 0:
idx += 1
continue
if cnts[i] > 0:
a[idx] = j
else:
a[idx] = abs(cnts[i]) - j
idx += 1
if s[-1] == '<':
a[-1] = a[-2] + 1
# print(*cnts)
# print(*a)
print((sum(a)))
# for i in range(len(s)):
# print(a[i],s[i],end='')
# print(a[-1])
| import sys
input = sys.stdin.readline
s = input()[:-1]
a = [0]*(len(s)+1)
l = [0]*len(a)
r = [0]*len(a)
for i in range(1, len(a)):
if s[i-1] == '<':
l[i] = l[i-1] + 1
for i in range(len(a)-2, -1, -1):
if s[i] == '>':
r[i] = r[i+1] + 1
for i in range(len(a)):
a[i] = max(l[i], r[i])
print((sum(a))) | 47 | 21 | 889 | 357 | import sys
input = sys.stdin.readline
import numpy as np
s = input()[:-1]
cnts = []
tmp = 1
for i in range(len(s) - 1):
if s[i] == s[i + 1]:
tmp += 1
else:
if s[i] == ">":
tmp *= -1
cnts.append(tmp)
tmp = 1
if s[-1] == ">":
tmp *= -1
cnts.append(tmp)
idx = 0
a = [0] * (len(s) + 1)
for i in range(len(cnts)):
if i != 0 and cnts[i - 1] > 0 and cnts[i] < 0 and a[idx - 1] >= abs(cnts[i]):
a[idx] = a[idx - 1] + 1
for j in range(abs(cnts[i])):
if a[idx] != 0:
idx += 1
continue
if cnts[i] > 0:
a[idx] = j
else:
a[idx] = abs(cnts[i]) - j
idx += 1
if s[-1] == "<":
a[-1] = a[-2] + 1
# print(*cnts)
# print(*a)
print((sum(a)))
# for i in range(len(s)):
# print(a[i],s[i],end='')
# print(a[-1])
| import sys
input = sys.stdin.readline
s = input()[:-1]
a = [0] * (len(s) + 1)
l = [0] * len(a)
r = [0] * len(a)
for i in range(1, len(a)):
if s[i - 1] == "<":
l[i] = l[i - 1] + 1
for i in range(len(a) - 2, -1, -1):
if s[i] == ">":
r[i] = r[i + 1] + 1
for i in range(len(a)):
a[i] = max(l[i], r[i])
print((sum(a)))
| false | 55.319149 | [
"-import numpy as np",
"-",
"-cnts = []",
"-tmp = 1",
"-for i in range(len(s) - 1):",
"- if s[i] == s[i + 1]:",
"- tmp += 1",
"- else:",
"- if s[i] == \">\":",
"- tmp *= -1",
"- cnts.append(tmp)",
"- tmp = 1",
"-if s[-1] == \">\":",
"- tmp *= -1",
"-cnts.append(tmp)",
"-idx = 0",
"-for i in range(len(cnts)):",
"- if i != 0 and cnts[i - 1] > 0 and cnts[i] < 0 and a[idx - 1] >= abs(cnts[i]):",
"- a[idx] = a[idx - 1] + 1",
"- for j in range(abs(cnts[i])):",
"- if a[idx] != 0:",
"- idx += 1",
"- continue",
"- if cnts[i] > 0:",
"- a[idx] = j",
"- else:",
"- a[idx] = abs(cnts[i]) - j",
"- idx += 1",
"-if s[-1] == \"<\":",
"- a[-1] = a[-2] + 1",
"-# print(*cnts)",
"-# print(*a)",
"+l = [0] * len(a)",
"+r = [0] * len(a)",
"+for i in range(1, len(a)):",
"+ if s[i - 1] == \"<\":",
"+ l[i] = l[i - 1] + 1",
"+for i in range(len(a) - 2, -1, -1):",
"+ if s[i] == \">\":",
"+ r[i] = r[i + 1] + 1",
"+for i in range(len(a)):",
"+ a[i] = max(l[i], r[i])",
"-# for i in range(len(s)):",
"-# print(a[i],s[i],end='')",
"-# print(a[-1])"
] | false | 0.045534 | 0.036755 | 1.238835 | [
"s235237307",
"s587654128"
] |
u896741788 | p04000 | python | s438315829 | s622544717 | 2,316 | 676 | 19,056 | 119,736 | Accepted | Accepted | 70.81 | h,w,n=map(int,input().split())
spots=set([eval(input().replace(' ','*w+'))-w-1 for i in range(n)])
anss=[0]*10
from itertools import product as pr
moves=(tuple(x+w*y for x,y in pr(range(0,3),repeat=2)))
for i in spots:
a,b=divmod(i,w)
pre=[0]*9
for x in range(max(0,a-2),min(h-2,a+1)):
for y in range(max(0,b-2),min(w-2,b+1)):
ind=w*x+y
pre[x-a+(y-b)*3+8]+=sum(ind+m in spots for m in moves)
for v in pre:anss[v]+=1
tans=[0]*10
ans0=(h-2)*(w-2)
for i in range(1,10):
tans[i]=anss[i]//i
ans0-=anss[i]//i
tans[0]=ans0
print(*tans,sep='\n')
| h,w,n=map(int,input().split())
from itertools import product as pr
from collections import Counter as co
ans=[(h-2)*(w-2)]+[0]*9
io=[tuple(map(int,input().split())) for i in range(n)]
for k,v in co(co([(a-x)*w+b-y for x,y in pr(range(3),repeat=2) for a,b in io if h-1>a-x>0<b-y<w-1]).values()).items():
ans[k]=v
ans[0]-=v
print(*ans,sep='\n')
| 21 | 9 | 615 | 358 | h, w, n = map(int, input().split())
spots = set([eval(input().replace(" ", "*w+")) - w - 1 for i in range(n)])
anss = [0] * 10
from itertools import product as pr
moves = tuple(x + w * y for x, y in pr(range(0, 3), repeat=2))
for i in spots:
a, b = divmod(i, w)
pre = [0] * 9
for x in range(max(0, a - 2), min(h - 2, a + 1)):
for y in range(max(0, b - 2), min(w - 2, b + 1)):
ind = w * x + y
pre[x - a + (y - b) * 3 + 8] += sum(ind + m in spots for m in moves)
for v in pre:
anss[v] += 1
tans = [0] * 10
ans0 = (h - 2) * (w - 2)
for i in range(1, 10):
tans[i] = anss[i] // i
ans0 -= anss[i] // i
tans[0] = ans0
print(*tans, sep="\n")
| h, w, n = map(int, input().split())
from itertools import product as pr
from collections import Counter as co
ans = [(h - 2) * (w - 2)] + [0] * 9
io = [tuple(map(int, input().split())) for i in range(n)]
for k, v in co(
co(
[
(a - x) * w + b - y
for x, y in pr(range(3), repeat=2)
for a, b in io
if h - 1 > a - x > 0 < b - y < w - 1
]
).values()
).items():
ans[k] = v
ans[0] -= v
print(*ans, sep="\n")
| false | 57.142857 | [
"-spots = set([eval(input().replace(\" \", \"*w+\")) - w - 1 for i in range(n)])",
"-anss = [0] * 10",
"+from collections import Counter as co",
"-moves = tuple(x + w * y for x, y in pr(range(0, 3), repeat=2))",
"-for i in spots:",
"- a, b = divmod(i, w)",
"- pre = [0] * 9",
"- for x in range(max(0, a - 2), min(h - 2, a + 1)):",
"- for y in range(max(0, b - 2), min(w - 2, b + 1)):",
"- ind = w * x + y",
"- pre[x - a + (y - b) * 3 + 8] += sum(ind + m in spots for m in moves)",
"- for v in pre:",
"- anss[v] += 1",
"-tans = [0] * 10",
"-ans0 = (h - 2) * (w - 2)",
"-for i in range(1, 10):",
"- tans[i] = anss[i] // i",
"- ans0 -= anss[i] // i",
"-tans[0] = ans0",
"-print(*tans, sep=\"\\n\")",
"+ans = [(h - 2) * (w - 2)] + [0] * 9",
"+io = [tuple(map(int, input().split())) for i in range(n)]",
"+for k, v in co(",
"+ co(",
"+ [",
"+ (a - x) * w + b - y",
"+ for x, y in pr(range(3), repeat=2)",
"+ for a, b in io",
"+ if h - 1 > a - x > 0 < b - y < w - 1",
"+ ]",
"+ ).values()",
"+).items():",
"+ ans[k] = v",
"+ ans[0] -= v",
"+print(*ans, sep=\"\\n\")"
] | false | 0.042789 | 0.037853 | 1.130395 | [
"s438315829",
"s622544717"
] |
u644972721 | p02540 | python | s178005900 | s274550944 | 1,983 | 1,554 | 149,008 | 140,176 | Accepted | Accepted | 21.63 | import heapq
from collections import deque
def bfs(i, c):
color[i] = c
cnt[c] += 1
q = deque()
q.append(i)
while q:
j = q.popleft()
for k in G[j]:
if color[k] == -1:
color[k] = c
cnt[c] += 1
q.append(k)
return
n = int(eval(input()))
xy = []
for i in range(n):
x, y = list(map(int, input().split()))
xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
G.append([])
for i in range(n):
c = 0
while h[0][0] < xy[i][1]:
p = heapq.heappop(h)
if c == 0:
minv = p
c = 1
G[p[1]].append(xy[i][2])
G[xy[i][2]].append(p[1])
heapq.heappush(h, [xy[i][1], xy[i][2]])
if c:
heapq.heappush(h, minv)
color = [-1] * n
c = 0
for i in range(n):
if color[i] == -1:
bfs(i, c)
c += 1
for i in range(n):
ans = cnt[color[i]]
print(ans) | import heapq
from collections import deque
def bfs(i, c):
color[i] = c
cnt[c] += 1
q = deque()
q.append(i)
while q:
j = q.popleft()
for k in G[j]:
if color[k] == -1:
color[k] = c
cnt[c] += 1
q.append(k)
return
n = int(eval(input()))
xy = []
for i in range(n):
x, y = list(map(int, input().split()))
xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
G.append([])
for i in range(n):
c = 0
while h[0][0] < xy[i][1]:
p = heapq.heappop(h)
if c == 0:
minv = p
c = 1
G[p[1]].append(xy[i][2])
G[xy[i][2]].append(p[1])
#heapq.heappush(h, [xy[i][1], xy[i][2]])
if c:
heapq.heappush(h, minv)
else:
heapq.heappush(h, [xy[i][1], xy[i][2]])
color = [-1] * n
c = 0
for i in range(n):
if color[i] == -1:
bfs(i, c)
c += 1
for i in range(n):
ans = cnt[color[i]]
print(ans) | 49 | 51 | 1,003 | 1,064 | import heapq
from collections import deque
def bfs(i, c):
color[i] = c
cnt[c] += 1
q = deque()
q.append(i)
while q:
j = q.popleft()
for k in G[j]:
if color[k] == -1:
color[k] = c
cnt[c] += 1
q.append(k)
return
n = int(eval(input()))
xy = []
for i in range(n):
x, y = list(map(int, input().split()))
xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
G.append([])
for i in range(n):
c = 0
while h[0][0] < xy[i][1]:
p = heapq.heappop(h)
if c == 0:
minv = p
c = 1
G[p[1]].append(xy[i][2])
G[xy[i][2]].append(p[1])
heapq.heappush(h, [xy[i][1], xy[i][2]])
if c:
heapq.heappush(h, minv)
color = [-1] * n
c = 0
for i in range(n):
if color[i] == -1:
bfs(i, c)
c += 1
for i in range(n):
ans = cnt[color[i]]
print(ans)
| import heapq
from collections import deque
def bfs(i, c):
color[i] = c
cnt[c] += 1
q = deque()
q.append(i)
while q:
j = q.popleft()
for k in G[j]:
if color[k] == -1:
color[k] = c
cnt[c] += 1
q.append(k)
return
n = int(eval(input()))
xy = []
for i in range(n):
x, y = list(map(int, input().split()))
xy.append([x, y, i])
xy.sort()
cnt = [0] * n
h = [[n + 1, n + 1]]
G = []
for _ in range(n):
G.append([])
for i in range(n):
c = 0
while h[0][0] < xy[i][1]:
p = heapq.heappop(h)
if c == 0:
minv = p
c = 1
G[p[1]].append(xy[i][2])
G[xy[i][2]].append(p[1])
# heapq.heappush(h, [xy[i][1], xy[i][2]])
if c:
heapq.heappush(h, minv)
else:
heapq.heappush(h, [xy[i][1], xy[i][2]])
color = [-1] * n
c = 0
for i in range(n):
if color[i] == -1:
bfs(i, c)
c += 1
for i in range(n):
ans = cnt[color[i]]
print(ans)
| false | 3.921569 | [
"- heapq.heappush(h, [xy[i][1], xy[i][2]])",
"+ # heapq.heappush(h, [xy[i][1], xy[i][2]])",
"+ else:",
"+ heapq.heappush(h, [xy[i][1], xy[i][2]])"
] | false | 0.049683 | 0.044143 | 1.125497 | [
"s178005900",
"s274550944"
] |
u285681431 | p04000 | python | s920336501 | s421882453 | 1,059 | 705 | 164,288 | 249,012 | Accepted | Accepted | 33.43 | from collections import defaultdict
from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = {}
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
if (a + dy, b + dx) not in dict:
dict[(a + dy, b + dx)] = 1
else:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| 33 | 35 | 833 | 895 | from collections import defaultdict
from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = {}
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
if (a + dy, b + dx) not in dict:
dict[(a + dy, b + dx)] = 1
else:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| false | 5.714286 | [
"-from collections import defaultdict",
"-dict = defaultdict(int)",
"+dict = {}",
"- dict[(a + dy, b + dx)] += 1",
"+ if (a + dy, b + dx) not in dict:",
"+ dict[(a + dy, b + dx)] = 1",
"+ else:",
"+ dict[(a + dy, b + dx)] += 1"
] | false | 0.036729 | 0.043409 | 0.8461 | [
"s920336501",
"s421882453"
] |
u562016607 | p02886 | python | s927670451 | s706612603 | 172 | 17 | 38,512 | 2,940 | Accepted | Accepted | 90.12 | N=int(eval(input()))
d=[int(i) for i in input().split()]
ans=0
for i in range(N):
for j in range(i+1,N):
ans+=d[i]*d[j]
print(ans)
| N=int(eval(input()))
d=[int(i) for i in input().split()]
X=sum([i*i for i in d])
print(((sum(d)**2-X)//2))
| 7 | 4 | 137 | 102 | N = int(eval(input()))
d = [int(i) for i in input().split()]
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += d[i] * d[j]
print(ans)
| N = int(eval(input()))
d = [int(i) for i in input().split()]
X = sum([i * i for i in d])
print(((sum(d) ** 2 - X) // 2))
| false | 42.857143 | [
"-ans = 0",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- ans += d[i] * d[j]",
"-print(ans)",
"+X = sum([i * i for i in d])",
"+print(((sum(d) ** 2 - X) // 2))"
] | false | 0.047617 | 0.042679 | 1.115685 | [
"s927670451",
"s706612603"
] |
u794173881 | p03173 | python | s840662623 | s681115635 | 546 | 406 | 47,196 | 43,500 | Accepted | Accepted | 25.64 | n = int(eval(input()))
a = list(map(int, input().split()))
#dp[l][r] = [l, r)区間のスライムを合体するときのコストの最小値
dp = [[float("inf")]*(n+1) for i in range(n+1)]
for i in range(n):
dp[i][i] = 0
#cost[r]-cost[l] = [l, r)区間を合計したときのスライムの総和
cost = [0]*(n+1)
for i in range(n):
cost[i+1] = cost[i] + a[i]
#メモ化再帰でdp[0][n]求める
def dfs(l, r, infnum):
if dp[l][r] != infnum:
return dp[l][r]
elif (r - l) == 1:
dp[l][r] = 0
return dp[l][r]
else:
res = float("inf")
for k in range(l + 1, r):
#dp[l][k] + dp[k][r] + 合体に必要なコスト
res = min(res, dfs(l, k, infnum) + dfs(k, r, infnum) + (cost[r] - cost[l]))
dp[l][r] = res
return dp[l][r]
dfs(0, n, float("inf"))
print((dp[0][n])) | n = int(eval(input()))
a = list(map(int, input().split()))
ruiseki = [0] * (n+1)
for i in range(n):
ruiseki[i+1] = ruiseki[i] + a[i]
dp = [[-1]*(n+1) for i in range(n+1)]
def solve(l, r):
if dp[l][r] != -1:
return dp[l][r]
if r - l == 1:
dp[l][r] = 0
return dp[l][r]
ans = 10**18
for i in range(l+1, r):
ans = min(ans, solve(l, i) + solve(i, r) + ruiseki[r] - ruiseki[l])
dp[l][r] = ans
return dp[l][r]
solve(0, n)
print((dp[0][n])) | 30 | 22 | 768 | 508 | n = int(eval(input()))
a = list(map(int, input().split()))
# dp[l][r] = [l, r)区間のスライムを合体するときのコストの最小値
dp = [[float("inf")] * (n + 1) for i in range(n + 1)]
for i in range(n):
dp[i][i] = 0
# cost[r]-cost[l] = [l, r)区間を合計したときのスライムの総和
cost = [0] * (n + 1)
for i in range(n):
cost[i + 1] = cost[i] + a[i]
# メモ化再帰でdp[0][n]求める
def dfs(l, r, infnum):
if dp[l][r] != infnum:
return dp[l][r]
elif (r - l) == 1:
dp[l][r] = 0
return dp[l][r]
else:
res = float("inf")
for k in range(l + 1, r):
# dp[l][k] + dp[k][r] + 合体に必要なコスト
res = min(res, dfs(l, k, infnum) + dfs(k, r, infnum) + (cost[r] - cost[l]))
dp[l][r] = res
return dp[l][r]
dfs(0, n, float("inf"))
print((dp[0][n]))
| n = int(eval(input()))
a = list(map(int, input().split()))
ruiseki = [0] * (n + 1)
for i in range(n):
ruiseki[i + 1] = ruiseki[i] + a[i]
dp = [[-1] * (n + 1) for i in range(n + 1)]
def solve(l, r):
if dp[l][r] != -1:
return dp[l][r]
if r - l == 1:
dp[l][r] = 0
return dp[l][r]
ans = 10**18
for i in range(l + 1, r):
ans = min(ans, solve(l, i) + solve(i, r) + ruiseki[r] - ruiseki[l])
dp[l][r] = ans
return dp[l][r]
solve(0, n)
print((dp[0][n]))
| false | 26.666667 | [
"-# dp[l][r] = [l, r)区間のスライムを合体するときのコストの最小値",
"-dp = [[float(\"inf\")] * (n + 1) for i in range(n + 1)]",
"+ruiseki = [0] * (n + 1)",
"- dp[i][i] = 0",
"-# cost[r]-cost[l] = [l, r)区間を合計したときのスライムの総和",
"-cost = [0] * (n + 1)",
"-for i in range(n):",
"- cost[i + 1] = cost[i] + a[i]",
"-# メモ化再帰でdp[0][n]求める",
"-def dfs(l, r, infnum):",
"- if dp[l][r] != infnum:",
"+ ruiseki[i + 1] = ruiseki[i] + a[i]",
"+dp = [[-1] * (n + 1) for i in range(n + 1)]",
"+",
"+",
"+def solve(l, r):",
"+ if dp[l][r] != -1:",
"- elif (r - l) == 1:",
"+ if r - l == 1:",
"- else:",
"- res = float(\"inf\")",
"- for k in range(l + 1, r):",
"- # dp[l][k] + dp[k][r] + 合体に必要なコスト",
"- res = min(res, dfs(l, k, infnum) + dfs(k, r, infnum) + (cost[r] - cost[l]))",
"- dp[l][r] = res",
"+ ans = 10**18",
"+ for i in range(l + 1, r):",
"+ ans = min(ans, solve(l, i) + solve(i, r) + ruiseki[r] - ruiseki[l])",
"+ dp[l][r] = ans",
"-dfs(0, n, float(\"inf\"))",
"+solve(0, n)"
] | false | 0.059159 | 0.034969 | 1.691729 | [
"s840662623",
"s681115635"
] |
u150984829 | p02386 | python | s414241098 | s078814861 | 130 | 70 | 5,608 | 5,608 | Accepted | Accepted | 46.15 | n=int(eval(input()))
a=[list(map(int,input().split()))for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in('012345','152043','215304','302541','410352','514320'):
f=[d[int(k)]for k in p]
g=f[1:5]*2
for k in range(4):
if g[k:k+4]==e[1:5]:
if f[0]==e[0]:
if f[5]==e[5]:return 'No'
return 'Yes'
print((f()))
| n=int(eval(input()))
a=[list(map(int,input().split()))for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in('012345','152043','215304','302541','410352','514320'):
f=[d[int(k)]for k in p]
if f[0]==e[0]:
if f[5]==e[5]:
f=f[1:5]*2
for k in range(4):
if f[k:k+4]==e[1:5]:return 'No'
return 'Yes'
print((f()))
| 16 | 16 | 442 | 444 | n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
def f():
for i in range(n - 1):
d = a[i][:]
d[3], d[4] = d[4], d[3]
for j in range(i + 1, n):
e = a[j][:]
e[3], e[4] = e[4], e[3]
for p in ("012345", "152043", "215304", "302541", "410352", "514320"):
f = [d[int(k)] for k in p]
g = f[1:5] * 2
for k in range(4):
if g[k : k + 4] == e[1:5]:
if f[0] == e[0]:
if f[5] == e[5]:
return "No"
return "Yes"
print((f()))
| n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
def f():
for i in range(n - 1):
d = a[i][:]
d[3], d[4] = d[4], d[3]
for j in range(i + 1, n):
e = a[j][:]
e[3], e[4] = e[4], e[3]
for p in ("012345", "152043", "215304", "302541", "410352", "514320"):
f = [d[int(k)] for k in p]
if f[0] == e[0]:
if f[5] == e[5]:
f = f[1:5] * 2
for k in range(4):
if f[k : k + 4] == e[1:5]:
return "No"
return "Yes"
print((f()))
| false | 0 | [
"- g = f[1:5] * 2",
"- for k in range(4):",
"- if g[k : k + 4] == e[1:5]:",
"- if f[0] == e[0]:",
"- if f[5] == e[5]:",
"+ if f[0] == e[0]:",
"+ if f[5] == e[5]:",
"+ f = f[1:5] * 2",
"+ for k in range(4):",
"+ if f[k : k + 4] == e[1:5]:"
] | false | 0.03738 | 0.03792 | 0.985778 | [
"s414241098",
"s078814861"
] |
u795630164 | p03854 | python | s858265442 | s289180990 | 120 | 62 | 3,444 | 3,188 | Accepted | Accepted | 48.33 | import re
S = eval(input())
S = S[::-1] # 文字列反転
pattern = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(pattern)):
pattern[i] = pattern[i][::-1]
fin = False
while not fin:
if S == '':
print("YES")
exit()
fin = True
for x in pattern:
if re.match(x, S):
S = S.replace(x, "", 1)
fin = False
break
print("NO") | S = eval(input())
s = ''
ar = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S)+1):
s = S[-i] + s
if s in ar:
s = ''
if len(s) > 10:
break
if len(s) == 0:
print('YES')
else:
print('NO') | 23 | 14 | 415 | 244 | import re
S = eval(input())
S = S[::-1] # 文字列反転
pattern = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(pattern)):
pattern[i] = pattern[i][::-1]
fin = False
while not fin:
if S == "":
print("YES")
exit()
fin = True
for x in pattern:
if re.match(x, S):
S = S.replace(x, "", 1)
fin = False
break
print("NO")
| S = eval(input())
s = ""
ar = ["dream", "dreamer", "erase", "eraser"]
for i in range(1, len(S) + 1):
s = S[-i] + s
if s in ar:
s = ""
if len(s) > 10:
break
if len(s) == 0:
print("YES")
else:
print("NO")
| false | 39.130435 | [
"-import re",
"-",
"-S = S[::-1] # 文字列反転",
"-pattern = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]",
"-for i in range(len(pattern)):",
"- pattern[i] = pattern[i][::-1]",
"-fin = False",
"-while not fin:",
"- if S == \"\":",
"- print(\"YES\")",
"- exit()",
"- fin = True",
"- for x in pattern:",
"- if re.match(x, S):",
"- S = S.replace(x, \"\", 1)",
"- fin = False",
"- break",
"-print(\"NO\")",
"+s = \"\"",
"+ar = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]",
"+for i in range(1, len(S) + 1):",
"+ s = S[-i] + s",
"+ if s in ar:",
"+ s = \"\"",
"+ if len(s) > 10:",
"+ break",
"+if len(s) == 0:",
"+ print(\"YES\")",
"+else:",
"+ print(\"NO\")"
] | false | 0.062569 | 0.044325 | 1.411594 | [
"s858265442",
"s289180990"
] |
u897329068 | p03720 | python | s042190608 | s601301097 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | n,m = list(map(int,input().split()))
abm = [list(map(int,input().split())) for _ in range(m)]
countDic = {}
for nn in range(n+1):
countDic[nn] = 0
for ab in abm:
countDic[ab[0]] += 1
countDic[ab[1]] += 1
ks = list(countDic.keys())
ks = sorted(ks)[1:]
for k in ks:
print((countDic[k])) | n,m = list(map(int,input().split()))
ans = [0]*n
for _ in range(m):
a,b = list(map(int,input().split()))
ans[a-1]+=1
ans[b-1]+=1
for an in ans:
print(an) | 17 | 10 | 296 | 157 | n, m = list(map(int, input().split()))
abm = [list(map(int, input().split())) for _ in range(m)]
countDic = {}
for nn in range(n + 1):
countDic[nn] = 0
for ab in abm:
countDic[ab[0]] += 1
countDic[ab[1]] += 1
ks = list(countDic.keys())
ks = sorted(ks)[1:]
for k in ks:
print((countDic[k]))
| n, m = list(map(int, input().split()))
ans = [0] * n
for _ in range(m):
a, b = list(map(int, input().split()))
ans[a - 1] += 1
ans[b - 1] += 1
for an in ans:
print(an)
| false | 41.176471 | [
"-abm = [list(map(int, input().split())) for _ in range(m)]",
"-countDic = {}",
"-for nn in range(n + 1):",
"- countDic[nn] = 0",
"-for ab in abm:",
"- countDic[ab[0]] += 1",
"- countDic[ab[1]] += 1",
"-ks = list(countDic.keys())",
"-ks = sorted(ks)[1:]",
"-for k in ks:",
"- print((countDic[k]))",
"+ans = [0] * n",
"+for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ ans[a - 1] += 1",
"+ ans[b - 1] += 1",
"+for an in ans:",
"+ print(an)"
] | false | 0.039805 | 0.036468 | 1.091507 | [
"s042190608",
"s601301097"
] |
u761320129 | p04035 | python | s870881805 | s644027366 | 108 | 96 | 14,052 | 14,052 | Accepted | Accepted | 11.11 | N,L = map(int,input().split())
A = list(map(int,input().split()))
last = -1
for i,(a,b) in enumerate(zip(A,A[1:])):
if a+b >= L:
last = i+1
break
else:
print('Impossible')
exit()
print('Possible')
ans = [n for n in range(1,last)] + [n for n in range(N-1,last,-1)]
ans.append(last)
print(*ans, sep='\n')
| N,L = map(int,input().split())
A = list(map(int,input().split()))
last = -1
for i,(a,b) in enumerate(zip(A,A[1:])):
if a+b >= L:
last = i
break
if last < 0:
print('Impossible')
exit()
print('Possible')
ans = list(range(1,i+1)) + list(range(N-1,i,-1))
print(*ans, sep='\n')
| 16 | 15 | 347 | 316 | N, L = map(int, input().split())
A = list(map(int, input().split()))
last = -1
for i, (a, b) in enumerate(zip(A, A[1:])):
if a + b >= L:
last = i + 1
break
else:
print("Impossible")
exit()
print("Possible")
ans = [n for n in range(1, last)] + [n for n in range(N - 1, last, -1)]
ans.append(last)
print(*ans, sep="\n")
| N, L = map(int, input().split())
A = list(map(int, input().split()))
last = -1
for i, (a, b) in enumerate(zip(A, A[1:])):
if a + b >= L:
last = i
break
if last < 0:
print("Impossible")
exit()
print("Possible")
ans = list(range(1, i + 1)) + list(range(N - 1, i, -1))
print(*ans, sep="\n")
| false | 6.25 | [
"- last = i + 1",
"+ last = i",
"-else:",
"+if last < 0:",
"-ans = [n for n in range(1, last)] + [n for n in range(N - 1, last, -1)]",
"-ans.append(last)",
"+ans = list(range(1, i + 1)) + list(range(N - 1, i, -1))"
] | false | 0.035636 | 0.034104 | 1.044947 | [
"s870881805",
"s644027366"
] |
u493520238 | p02973 | python | s106458545 | s661673195 | 180 | 100 | 80,644 | 77,440 | Accepted | Accepted | 44.44 | from bisect import bisect_left, bisect_right
n = int(eval(input()))
col_maxs = []
for _ in range(n):
a = int(eval(input())) * (-1)
if not col_maxs:
col_maxs.append(a)
continue
curr_max = col_maxs[-1]
if a >= curr_max:
col_maxs.append(a)
else:
# aより大きい最小要素のindex/value
ind = bisect_right(col_maxs, a)
col_maxs[ind] = a
print((len(col_maxs))) | from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(eval(input()))
col_maxs = []
for _ in range(n):
a = int(eval(input())) * (-1)
if not col_maxs:
col_maxs.append(a)
continue
curr_max = col_maxs[-1]
if a >= curr_max:
col_maxs.append(a)
else:
# aより大きい最小要素のindex/value
ind = bisect_right(col_maxs, a)
col_maxs[ind] = a
print((len(col_maxs))) | 19 | 21 | 415 | 455 | from bisect import bisect_left, bisect_right
n = int(eval(input()))
col_maxs = []
for _ in range(n):
a = int(eval(input())) * (-1)
if not col_maxs:
col_maxs.append(a)
continue
curr_max = col_maxs[-1]
if a >= curr_max:
col_maxs.append(a)
else:
# aより大きい最小要素のindex/value
ind = bisect_right(col_maxs, a)
col_maxs[ind] = a
print((len(col_maxs)))
| from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(eval(input()))
col_maxs = []
for _ in range(n):
a = int(eval(input())) * (-1)
if not col_maxs:
col_maxs.append(a)
continue
curr_max = col_maxs[-1]
if a >= curr_max:
col_maxs.append(a)
else:
# aより大きい最小要素のindex/value
ind = bisect_right(col_maxs, a)
col_maxs[ind] = a
print((len(col_maxs)))
| false | 9.52381 | [
"+import sys",
"+input = sys.stdin.readline"
] | false | 0.048062 | 0.046545 | 1.032582 | [
"s106458545",
"s661673195"
] |
u073852194 | p03855 | python | s924623881 | s225481769 | 966 | 893 | 134,008 | 126,088 | Accepted | Accepted | 7.56 | import sys
from collections import defaultdict
input = sys.stdin.readline
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 roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def main():
n,k,l = list(map(int,input().split()))
Road = [list(map(int,input().split())) for i in range(k)]
Train = [list(map(int,input().split())) for i in range(l)]
uf_r = UnionFind(n)
uf_t = UnionFind(n)
for i in range(k):
uf_r.union(Road[i][0]-1,Road[i][1]-1)
for i in range(l):
uf_t.union(Train[i][0]-1,Train[i][1]-1)
Roots_dict = defaultdict(int)
Roots = []
for i in range(n):
Roots.append(str(uf_r.find(i))+' '+str(uf_t.find(i)))
Roots_dict[Roots[i]] += 1
ans = [0]*n
for i in range(n):
ans[i] = Roots_dict[Roots[i]]
print((*ans))
if __name__ == '__main__':
main() | import sys
from collections import defaultdict
input = sys.stdin.readline
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 main():
n,k,l = list(map(int,input().split()))
Road = [list(map(int,input().split())) for i in range(k)]
Train = [list(map(int,input().split())) for i in range(l)]
uf_r = UnionFind(n)
uf_t = UnionFind(n)
for i in range(k):
uf_r.union(Road[i][0]-1,Road[i][1]-1)
for i in range(l):
uf_t.union(Train[i][0]-1,Train[i][1]-1)
Roots_dict = defaultdict(int)
Roots = []
for i in range(n):
Roots.append((uf_r.find(i),uf_t.find(i)))
Roots_dict[Roots[i]] += 1
ans = [0]*n
for i in range(n):
ans[i] = Roots_dict[Roots[i]]
print((*ans))
if __name__ == '__main__':
main() | 67 | 61 | 1,632 | 1,467 | import sys
from collections import defaultdict
input = sys.stdin.readline
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 roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def main():
n, k, l = list(map(int, input().split()))
Road = [list(map(int, input().split())) for i in range(k)]
Train = [list(map(int, input().split())) for i in range(l)]
uf_r = UnionFind(n)
uf_t = UnionFind(n)
for i in range(k):
uf_r.union(Road[i][0] - 1, Road[i][1] - 1)
for i in range(l):
uf_t.union(Train[i][0] - 1, Train[i][1] - 1)
Roots_dict = defaultdict(int)
Roots = []
for i in range(n):
Roots.append(str(uf_r.find(i)) + " " + str(uf_t.find(i)))
Roots_dict[Roots[i]] += 1
ans = [0] * n
for i in range(n):
ans[i] = Roots_dict[Roots[i]]
print((*ans))
if __name__ == "__main__":
main()
| import sys
from collections import defaultdict
input = sys.stdin.readline
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 main():
n, k, l = list(map(int, input().split()))
Road = [list(map(int, input().split())) for i in range(k)]
Train = [list(map(int, input().split())) for i in range(l)]
uf_r = UnionFind(n)
uf_t = UnionFind(n)
for i in range(k):
uf_r.union(Road[i][0] - 1, Road[i][1] - 1)
for i in range(l):
uf_t.union(Train[i][0] - 1, Train[i][1] - 1)
Roots_dict = defaultdict(int)
Roots = []
for i in range(n):
Roots.append((uf_r.find(i), uf_t.find(i)))
Roots_dict[Roots[i]] += 1
ans = [0] * n
for i in range(n):
ans[i] = Roots_dict[Roots[i]]
print((*ans))
if __name__ == "__main__":
main()
| false | 8.955224 | [
"- def roots(self):",
"- return [i for i, x in enumerate(self.parents) if x < 0]",
"-",
"- def group_count(self):",
"- return len(self.roots())",
"-",
"- Roots.append(str(uf_r.find(i)) + \" \" + str(uf_t.find(i)))",
"+ Roots.append((uf_r.find(i), uf_t.find(i)))"
] | false | 0.128379 | 0.04946 | 2.595587 | [
"s924623881",
"s225481769"
] |
u995004106 | p02678 | python | s670910800 | s399994250 | 909 | 530 | 112,968 | 99,124 | Accepted | Accepted | 41.69 | from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import heapq
N,M=list(map(int,input().split()))
tree=[[] for _ in range(N)]
for i in range(M):
a,b=list(map(int,input().split()))
tree[a-1].append(b-1)
tree[b-1].append(a-1)
d=[float("inf") for _ in range(N)]
d[0]=0
q=[]
prev=[-1]*N
q.append([0,0])
q1=q
flag=1
#print(q)
heapq.heapify(q)
#print(q1)
while len(q)>0:
dist,u=heapq.heappop(q)
if d[u]<dist: continue
for i in tree[u]:
alt=d[u]+1
if d[i]>alt:
d[i]=alt
prev[i]=u
heapq.heappush(q,[alt,i])
#print(prev,d,q1)
for i in range(1,N):
if prev[i]==-1:
flag=0
break
if flag==0:
print("No")
else:
print("Yes")
for i in range(1,N):
print((prev[i]+1))
| from math import floor,ceil,sqrt
import fractions
import itertools
from collections import deque
import heapq
N,M=list(map(int,input().split()))
tree=[[] for _ in range(N)]
for i in range(M):
a,b=list(map(int,input().split()))
tree[a-1].append(b-1)
tree[b-1].append(a-1)
prev=[-1]*N
d=[float("inf")]
prev[0]=0
d=deque()
d.append(0)
while len(d)>0:
v=d.popleft()
for i in tree[v]:
if prev[i]==-1:
prev[i]=v
d.append(i)
print("Yes")
for i in range(1,N):
print((prev[i]+1))
| 45 | 27 | 880 | 541 | from math import floor, ceil, sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import heapq
N, M = list(map(int, input().split()))
tree = [[] for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
d = [float("inf") for _ in range(N)]
d[0] = 0
q = []
prev = [-1] * N
q.append([0, 0])
q1 = q
flag = 1
# print(q)
heapq.heapify(q)
# print(q1)
while len(q) > 0:
dist, u = heapq.heappop(q)
if d[u] < dist:
continue
for i in tree[u]:
alt = d[u] + 1
if d[i] > alt:
d[i] = alt
prev[i] = u
heapq.heappush(q, [alt, i])
# print(prev,d,q1)
for i in range(1, N):
if prev[i] == -1:
flag = 0
break
if flag == 0:
print("No")
else:
print("Yes")
for i in range(1, N):
print((prev[i] + 1))
| from math import floor, ceil, sqrt
import fractions
import itertools
from collections import deque
import heapq
N, M = list(map(int, input().split()))
tree = [[] for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
prev = [-1] * N
d = [float("inf")]
prev[0] = 0
d = deque()
d.append(0)
while len(d) > 0:
v = d.popleft()
for i in tree[v]:
if prev[i] == -1:
prev[i] = v
d.append(i)
print("Yes")
for i in range(1, N):
print((prev[i] + 1))
| false | 40 | [
"-from collections import deque",
"-d = [float(\"inf\") for _ in range(N)]",
"-d[0] = 0",
"-q = []",
"-q.append([0, 0])",
"-q1 = q",
"-flag = 1",
"-# print(q)",
"-heapq.heapify(q)",
"-# print(q1)",
"-while len(q) > 0:",
"- dist, u = heapq.heappop(q)",
"- if d[u] < dist:",
"- continue",
"- for i in tree[u]:",
"- alt = d[u] + 1",
"- if d[i] > alt:",
"- d[i] = alt",
"- prev[i] = u",
"- heapq.heappush(q, [alt, i])",
"- # print(prev,d,q1)",
"+d = [float(\"inf\")]",
"+prev[0] = 0",
"+d = deque()",
"+d.append(0)",
"+while len(d) > 0:",
"+ v = d.popleft()",
"+ for i in tree[v]:",
"+ if prev[i] == -1:",
"+ prev[i] = v",
"+ d.append(i)",
"+print(\"Yes\")",
"- if prev[i] == -1:",
"- flag = 0",
"- break",
"-if flag == 0:",
"- print(\"No\")",
"-else:",
"- print(\"Yes\")",
"- for i in range(1, N):",
"- print((prev[i] + 1))",
"+ print((prev[i] + 1))"
] | false | 0.046276 | 0.03838 | 1.205726 | [
"s670910800",
"s399994250"
] |
u548272916 | p02584 | python | s924350409 | s055650335 | 32 | 28 | 9,008 | 9,196 | Accepted | Accepted | 12.5 | x,k,d = list(map(int, input().split()))
lists = []
x = abs(x)
step = int(x/d)
if step >= k:
answer = x - k * d
elif step < k:
k_left = k - int(step)
if k_left % 2 == 0:
answer = x % d
if k_left % 2 == 1:
answer = abs(x - step * d - d)
print(answer) | x,k,d = list(map(int, input().split()))
lists = []
x = abs(x)
step = int(x/d)
if step >= k:
answer = x - k * d
elif step < k:
k_left = k - int(step)
if k_left % 2 == 0:
answer = x % d
if k_left % 2 == 1:
answer = min(abs(x % d - d), abs(x % d + d))
print(answer) | 16 | 16 | 277 | 294 | x, k, d = list(map(int, input().split()))
lists = []
x = abs(x)
step = int(x / d)
if step >= k:
answer = x - k * d
elif step < k:
k_left = k - int(step)
if k_left % 2 == 0:
answer = x % d
if k_left % 2 == 1:
answer = abs(x - step * d - d)
print(answer)
| x, k, d = list(map(int, input().split()))
lists = []
x = abs(x)
step = int(x / d)
if step >= k:
answer = x - k * d
elif step < k:
k_left = k - int(step)
if k_left % 2 == 0:
answer = x % d
if k_left % 2 == 1:
answer = min(abs(x % d - d), abs(x % d + d))
print(answer)
| false | 0 | [
"- answer = abs(x - step * d - d)",
"+ answer = min(abs(x % d - d), abs(x % d + d))"
] | false | 0.044133 | 0.045431 | 0.971417 | [
"s924350409",
"s055650335"
] |
u348805958 | p02793 | python | s307244213 | s313501583 | 1,968 | 966 | 4,596 | 6,136 | Accepted | Accepted | 50.91 | #!python3
iim = lambda: list(map(int, input().rstrip().split()))
def factor(n):
ans = []
i = 0
while n & 1 == 0:
n >>= 1
i += 1
if i > 0:
ans.append((2, i))
for i in range(3, int(n**.5) +1, 2):
x, y = divmod(n, i)
if y == 0:
j = 1
x1 = x
while True:
x1, y = divmod(x, i)
if y == 0:
x = x1
j += 1
else:
ans.append((i, j))
break
n = x
if n > 1:
ans.append((n, 1))
return ans
def resolve():
N = int(eval(input()))
A = list(iim())
mod = 10**9 + 7
c = 1
c2 = dict()
for a in A:
for n, m in factor(a):
if n in c2:
c2[n] = max(c2[n], m)
else:
c2[n] = m
c3 = 1
for n, m in list(c2.items()):
c3 *= n**m%mod % mod
s = 0
for a in A:
s += c3*pow(a, mod-2, mod)%mod
s %= mod
print(s)
if __name__ == "__main__":
resolve()
| #!python3
from fractions import gcd
iim = lambda: list(map(int, input().rstrip().split()))
def factor(n):
ans = []
i = 0
while n & 1 == 0:
n >>= 1
i += 1
if i > 0:
ans.append((2, i))
for i in range(3, int(n**.5) +1, 2):
x, y = divmod(n, i)
if y == 0:
j = 1
x1 = x
while True:
x1, y = divmod(x, i)
if y == 0:
x = x1
j += 1
else:
ans.append((i, j))
break
n = x
if n > 1:
ans.append((n, 1))
return ans
def resolve():
N = int(eval(input()))
A = list(iim())
mod = 10**9 + 7
lcm = 1
#c2 = dict()
#for a in A:
# for n, m in factor(a):
# if n in c2:
# c2[n] = max(c2[n], m)
# else:
# c2[n] = m
#lcm = 1
#for n, m in c2.items():
# lcm *= n**m%mod % mod
for a in A:
lcm = lcm // gcd(lcm, a) * a
lcm %= mod
s = 0
for a in A:
s += lcm*pow(a, mod-2, mod)%mod
s %= mod
print(s)
if __name__ == "__main__":
resolve()
| 61 | 65 | 1,150 | 1,263 | #!python3
iim = lambda: list(map(int, input().rstrip().split()))
def factor(n):
ans = []
i = 0
while n & 1 == 0:
n >>= 1
i += 1
if i > 0:
ans.append((2, i))
for i in range(3, int(n**0.5) + 1, 2):
x, y = divmod(n, i)
if y == 0:
j = 1
x1 = x
while True:
x1, y = divmod(x, i)
if y == 0:
x = x1
j += 1
else:
ans.append((i, j))
break
n = x
if n > 1:
ans.append((n, 1))
return ans
def resolve():
N = int(eval(input()))
A = list(iim())
mod = 10**9 + 7
c = 1
c2 = dict()
for a in A:
for n, m in factor(a):
if n in c2:
c2[n] = max(c2[n], m)
else:
c2[n] = m
c3 = 1
for n, m in list(c2.items()):
c3 *= n**m % mod % mod
s = 0
for a in A:
s += c3 * pow(a, mod - 2, mod) % mod
s %= mod
print(s)
if __name__ == "__main__":
resolve()
| #!python3
from fractions import gcd
iim = lambda: list(map(int, input().rstrip().split()))
def factor(n):
ans = []
i = 0
while n & 1 == 0:
n >>= 1
i += 1
if i > 0:
ans.append((2, i))
for i in range(3, int(n**0.5) + 1, 2):
x, y = divmod(n, i)
if y == 0:
j = 1
x1 = x
while True:
x1, y = divmod(x, i)
if y == 0:
x = x1
j += 1
else:
ans.append((i, j))
break
n = x
if n > 1:
ans.append((n, 1))
return ans
def resolve():
N = int(eval(input()))
A = list(iim())
mod = 10**9 + 7
lcm = 1
# c2 = dict()
# for a in A:
# for n, m in factor(a):
# if n in c2:
# c2[n] = max(c2[n], m)
# else:
# c2[n] = m
# lcm = 1
# for n, m in c2.items():
# lcm *= n**m%mod % mod
for a in A:
lcm = lcm // gcd(lcm, a) * a
lcm %= mod
s = 0
for a in A:
s += lcm * pow(a, mod - 2, mod) % mod
s %= mod
print(s)
if __name__ == "__main__":
resolve()
| false | 6.153846 | [
"+from fractions import gcd",
"+",
"- c = 1",
"- c2 = dict()",
"+ lcm = 1",
"+ # c2 = dict()",
"+ # for a in A:",
"+ # for n, m in factor(a):",
"+ # if n in c2:",
"+ # c2[n] = max(c2[n], m)",
"+ # else:",
"+ # c2[n] = m",
"+ # lcm = 1",
"+ # for n, m in c2.items():",
"+ # lcm *= n**m%mod % mod",
"- for n, m in factor(a):",
"- if n in c2:",
"- c2[n] = max(c2[n], m)",
"- else:",
"- c2[n] = m",
"- c3 = 1",
"- for n, m in list(c2.items()):",
"- c3 *= n**m % mod % mod",
"+ lcm = lcm // gcd(lcm, a) * a",
"+ lcm %= mod",
"- s += c3 * pow(a, mod - 2, mod) % mod",
"+ s += lcm * pow(a, mod - 2, mod) % mod"
] | false | 0.062819 | 0.049472 | 1.269775 | [
"s307244213",
"s313501583"
] |
u075012704 | p02691 | python | s622746864 | s251284552 | 274 | 198 | 66,788 | 50,664 | Accepted | Accepted | 27.74 | from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
B = A[:]
for n in range(N):
B[n] -= (n + 1)
D = defaultdict(int)
ans = 0
for i, a, b in zip(reversed(list(range(N))), A[::-1], B[::-1]):
ans += D[-(i + a + 1)]
D[b] += 1
print(ans)
| from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]
ans = 0
QC = Counter(Q)
for p in P:
ans += QC[p]
print(ans)
| 14 | 13 | 291 | 256 | from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
B = A[:]
for n in range(N):
B[n] -= n + 1
D = defaultdict(int)
ans = 0
for i, a, b in zip(reversed(list(range(N))), A[::-1], B[::-1]):
ans += D[-(i + a + 1)]
D[b] += 1
print(ans)
| from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]
ans = 0
QC = Counter(Q)
for p in P:
ans += QC[p]
print(ans)
| false | 7.142857 | [
"-from collections import defaultdict",
"+from collections import Counter",
"-B = A[:]",
"-for n in range(N):",
"- B[n] -= n + 1",
"-D = defaultdict(int)",
"+P = [i + a for i, a in enumerate(A, start=1)]",
"+Q = [j - a for j, a in enumerate(A, start=1)]",
"-for i, a, b in zip(reversed(list(range(N))), A[::-1], B[::-1]):",
"- ans += D[-(i + a + 1)]",
"- D[b] += 1",
"+QC = Counter(Q)",
"+for p in P:",
"+ ans += QC[p]"
] | false | 0.191551 | 0.048643 | 3.937895 | [
"s622746864",
"s251284552"
] |
u930705402 | p02708 | python | s963371503 | s916382175 | 73 | 19 | 9,180 | 9,168 | Accepted | Accepted | 73.97 | N,K=list(map(int,input().split()))
ans=0
for i in range(K,N+2):
kos=i*(N-i+1)+1
ans=(ans+kos)%(10**9+7)
print(ans) | N,k=list(map(int,input().split()))
print((((2+N-k)*(6+N+N**2+2*k+k*N-k**2*2)//6)%(10**9+7))) | 6 | 2 | 121 | 85 | N, K = list(map(int, input().split()))
ans = 0
for i in range(K, N + 2):
kos = i * (N - i + 1) + 1
ans = (ans + kos) % (10**9 + 7)
print(ans)
| N, k = list(map(int, input().split()))
print(
(((2 + N - k) * (6 + N + N**2 + 2 * k + k * N - k**2 * 2) // 6) % (10**9 + 7))
)
| false | 66.666667 | [
"-N, K = list(map(int, input().split()))",
"-ans = 0",
"-for i in range(K, N + 2):",
"- kos = i * (N - i + 1) + 1",
"- ans = (ans + kos) % (10**9 + 7)",
"-print(ans)",
"+N, k = list(map(int, input().split()))",
"+print(",
"+ (((2 + N - k) * (6 + N + N**2 + 2 * k + k * N - k**2 * 2) // 6) % (10**9 + 7))",
"+)"
] | false | 0.281174 | 0.057924 | 4.854149 | [
"s963371503",
"s916382175"
] |
u588794534 | p03161 | python | s014405204 | s341826314 | 450 | 357 | 60,768 | 56,544 | Accepted | Accepted | 20.67 | n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
dp=["INF" for _ in range(n)]
dp[0]=0
#print(r)
for i in range(n):
for j in range(min(k,n-i-1)):
if dp[i+j+1]=="INF":
dp[i+j+1]=dp[i]+abs(a[i+j+1]-a[i])
else:
dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(a[i+j+1]-a[i]))
#print(i,i+j,">>",r)
print((dp[-1]))
| n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
dp=[100000000000000000 for _ in range(n)]
dp[0]=0
#print(r)
for i in range(n):
for j in range(min(k,n-i-1)):
dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(a[i+j+1]-a[i]))
#print(i,i+j,">>",r)
print((dp[-1]))
| 16 | 13 | 353 | 285 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = ["INF" for _ in range(n)]
dp[0] = 0
# print(r)
for i in range(n):
for j in range(min(k, n - i - 1)):
if dp[i + j + 1] == "INF":
dp[i + j + 1] = dp[i] + abs(a[i + j + 1] - a[i])
else:
dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]))
# print(i,i+j,">>",r)
print((dp[-1]))
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [100000000000000000 for _ in range(n)]
dp[0] = 0
# print(r)
for i in range(n):
for j in range(min(k, n - i - 1)):
dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]))
# print(i,i+j,">>",r)
print((dp[-1]))
| false | 18.75 | [
"-dp = [\"INF\" for _ in range(n)]",
"+dp = [100000000000000000 for _ in range(n)]",
"- if dp[i + j + 1] == \"INF\":",
"- dp[i + j + 1] = dp[i] + abs(a[i + j + 1] - a[i])",
"- else:",
"- dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]))",
"- # print(i,i+j,\">>\",r)",
"+ dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(a[i + j + 1] - a[i]))",
"+ # print(i,i+j,\">>\",r)"
] | false | 0.190341 | 0.046279 | 4.112876 | [
"s014405204",
"s341826314"
] |
u432805419 | p04030 | python | s008606105 | s898483046 | 19 | 17 | 3,060 | 3,060 | Accepted | Accepted | 10.53 | a = list(eval(input()))
b = []
for i in range(len(a)):
if a[i] == "0":
b.append("0")
elif a[i] == "1":
b.append("1")
elif a[i] == "B" and len(b) != 0:
b.pop()
else:
continue
print(("".join(b))) | moji = list(eval(input()))
ans = []
for i in moji:
if i == "0":
ans.append("0")
elif i == "1":
ans.append("1")
else:
if len(ans) != 0:
ans.pop()
else:
continue
print(("".join(ans))) | 14 | 15 | 228 | 227 | a = list(eval(input()))
b = []
for i in range(len(a)):
if a[i] == "0":
b.append("0")
elif a[i] == "1":
b.append("1")
elif a[i] == "B" and len(b) != 0:
b.pop()
else:
continue
print(("".join(b)))
| moji = list(eval(input()))
ans = []
for i in moji:
if i == "0":
ans.append("0")
elif i == "1":
ans.append("1")
else:
if len(ans) != 0:
ans.pop()
else:
continue
print(("".join(ans)))
| false | 6.666667 | [
"-a = list(eval(input()))",
"-b = []",
"-for i in range(len(a)):",
"- if a[i] == \"0\":",
"- b.append(\"0\")",
"- elif a[i] == \"1\":",
"- b.append(\"1\")",
"- elif a[i] == \"B\" and len(b) != 0:",
"- b.pop()",
"+moji = list(eval(input()))",
"+ans = []",
"+for i in moji:",
"+ if i == \"0\":",
"+ ans.append(\"0\")",
"+ elif i == \"1\":",
"+ ans.append(\"1\")",
"- continue",
"-print((\"\".join(b)))",
"+ if len(ans) != 0:",
"+ ans.pop()",
"+ else:",
"+ continue",
"+print((\"\".join(ans)))"
] | false | 0.057178 | 0.04002 | 1.428748 | [
"s008606105",
"s898483046"
] |
u060938295 | p03163 | python | s121885540 | s821428544 | 1,069 | 171 | 128,480 | 14,000 | Accepted | Accepted | 84 | # -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 21:51:02 2019
@author: Yamazaki Kenichi
"""
N,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]
ans = [[-1 for i in range(N+1)]]
ans[0][N] = 0
for i in range(1,W+1):
tmp = -1
maxv = ans[-1][N]
# print('aa',maxv)
for j in range(N):
# print(i,j,A[j][0],maxv,ans[i -A[j][0]][j])
# print(i,j,A[j],i -A[j][0],ans[-1])
if i-A[j][0] >= 0 and ans[i-A[j][0]][j] == -1 and ans[i-A[j][0]][N] + A[j][1] > maxv:
maxv = ans[i-A[j][0]][N] + A[j][1]
tmp = j
# print('maxv',maxv,'tmp',tmp)
if tmp != -1:
ans.append(ans[-A[tmp][0]][:])
ans[i][tmp] = 1
else:
ans.append(ans[-1][:])
ans[i][N] = maxv
# print(ans[i][N])
# print(ans[i])
print((ans[W][N])) |
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)
N, W = list(map(int,input().split()))
wv = [list(map(int,input().split())) for _ in range(N)]
wv.sort()
ans = 0
dp = np.zeros(W + 1, dtype=int)
for w, v in wv:
np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])
ans = dp[-1]
print(ans)
| 32 | 20 | 863 | 316 | # -*- coding: utf-8 -*-
"""
Created on Sat Mar 23 21:51:02 2019
@author: Yamazaki Kenichi
"""
N, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
ans = [[-1 for i in range(N + 1)]]
ans[0][N] = 0
for i in range(1, W + 1):
tmp = -1
maxv = ans[-1][N]
# print('aa',maxv)
for j in range(N):
# print(i,j,A[j][0],maxv,ans[i -A[j][0]][j])
# print(i,j,A[j],i -A[j][0],ans[-1])
if (
i - A[j][0] >= 0
and ans[i - A[j][0]][j] == -1
and ans[i - A[j][0]][N] + A[j][1] > maxv
):
maxv = ans[i - A[j][0]][N] + A[j][1]
tmp = j
# print('maxv',maxv,'tmp',tmp)
if tmp != -1:
ans.append(ans[-A[tmp][0]][:])
ans[i][tmp] = 1
else:
ans.append(ans[-1][:])
ans[i][N] = maxv
# print(ans[i][N])
# print(ans[i])
print((ans[W][N]))
| import sys
import numpy as np
sys.setrecursionlimit(10**9)
N, W = list(map(int, input().split()))
wv = [list(map(int, input().split())) for _ in range(N)]
wv.sort()
ans = 0
dp = np.zeros(W + 1, dtype=int)
for w, v in wv:
np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
ans = dp[-1]
print(ans)
| false | 37.5 | [
"-# -*- coding: utf-8 -*-",
"-\"\"\"",
"-Created on Sat Mar 23 21:51:02 2019",
"-@author: Yamazaki Kenichi",
"-\"\"\"",
"+import sys",
"+import numpy as np",
"+",
"+sys.setrecursionlimit(10**9)",
"-A = [list(map(int, input().split())) for i in range(N)]",
"-ans = [[-1 for i in range(N + 1)]]",
"-ans[0][N] = 0",
"-for i in range(1, W + 1):",
"- tmp = -1",
"- maxv = ans[-1][N]",
"- # print('aa',maxv)",
"- for j in range(N):",
"- # print(i,j,A[j][0],maxv,ans[i -A[j][0]][j])",
"- # print(i,j,A[j],i -A[j][0],ans[-1])",
"- if (",
"- i - A[j][0] >= 0",
"- and ans[i - A[j][0]][j] == -1",
"- and ans[i - A[j][0]][N] + A[j][1] > maxv",
"- ):",
"- maxv = ans[i - A[j][0]][N] + A[j][1]",
"- tmp = j",
"- # print('maxv',maxv,'tmp',tmp)",
"- if tmp != -1:",
"- ans.append(ans[-A[tmp][0]][:])",
"- ans[i][tmp] = 1",
"- else:",
"- ans.append(ans[-1][:])",
"- ans[i][N] = maxv",
"-# print(ans[i][N])",
"-# print(ans[i])",
"-print((ans[W][N]))",
"+wv = [list(map(int, input().split())) for _ in range(N)]",
"+wv.sort()",
"+ans = 0",
"+dp = np.zeros(W + 1, dtype=int)",
"+for w, v in wv:",
"+ np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])",
"+ans = dp[-1]",
"+print(ans)"
] | false | 0.039067 | 0.206574 | 0.189121 | [
"s121885540",
"s821428544"
] |
u780354103 | p03835 | python | s898266742 | s483556874 | 1,436 | 1,247 | 2,940 | 2,940 | Accepted | Accepted | 13.16 | K,S = list(map(int,input().split()))
a = 0
for y in range(K + 1):
for z in range(K + 1):
if 0 <= S - y - z <= K:
a += 1
print(a) | K,S = list(map(int,input().split()))
a = 0
for X in range(K + 1):
for Y in range(K + 1):
if 0 <= S - X - Y <= K:
a += 1
print(a) | 8 | 8 | 155 | 154 | K, S = list(map(int, input().split()))
a = 0
for y in range(K + 1):
for z in range(K + 1):
if 0 <= S - y - z <= K:
a += 1
print(a)
| K, S = list(map(int, input().split()))
a = 0
for X in range(K + 1):
for Y in range(K + 1):
if 0 <= S - X - Y <= K:
a += 1
print(a)
| false | 0 | [
"-for y in range(K + 1):",
"- for z in range(K + 1):",
"- if 0 <= S - y - z <= K:",
"+for X in range(K + 1):",
"+ for Y in range(K + 1):",
"+ if 0 <= S - X - Y <= K:"
] | false | 0.032387 | 0.031306 | 1.034552 | [
"s898266742",
"s483556874"
] |
u164898518 | p03994 | python | s571661466 | s320439545 | 1,563 | 100 | 11,716 | 12,164 | Accepted | Accepted | 93.6 | s = input()
K = int(input())
_s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
ai = a.index("a")
zi = a.index("z")
si = [zi - a.index(c) + 1 if c != "a" else 0 for c in s]
for i, (c, ci) in enumerate(zip(s, si)):
if K == 0:
break
if c == "a":
continue
if ci <= K:
s = s[0:i] + "a" + s[i+1:]
K = K - ci
K = K % len(a)
if K > 0:
s = s[:-1] + a[a.index(s[-1]) + K]
print(s) | s = input()
s = list(s)
K = int(input())
# _s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
# ai = a.index("a")
zi = a.index("z")
si = [zi - a.index(c) + 1 if c != "a" else 0 for c in s]
for i, (c, ci) in enumerate(zip(s, si)):
if K == 0:
break
if c == "a":
continue
if ci <= K:
s[i] = 'a'
K = K - ci
K = K % len(a)
if K > 0:
s[-1] = a[a.index(s[-1]) + K]
print(("".join(s))) | 22 | 23 | 452 | 457 | s = input()
K = int(input())
_s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
ai = a.index("a")
zi = a.index("z")
si = [zi - a.index(c) + 1 if c != "a" else 0 for c in s]
for i, (c, ci) in enumerate(zip(s, si)):
if K == 0:
break
if c == "a":
continue
if ci <= K:
s = s[0:i] + "a" + s[i + 1 :]
K = K - ci
K = K % len(a)
if K > 0:
s = s[:-1] + a[a.index(s[-1]) + K]
print(s)
| s = input()
s = list(s)
K = int(input())
# _s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
# ai = a.index("a")
zi = a.index("z")
si = [zi - a.index(c) + 1 if c != "a" else 0 for c in s]
for i, (c, ci) in enumerate(zip(s, si)):
if K == 0:
break
if c == "a":
continue
if ci <= K:
s[i] = "a"
K = K - ci
K = K % len(a)
if K > 0:
s[-1] = a[a.index(s[-1]) + K]
print(("".join(s)))
| false | 4.347826 | [
"+s = list(s)",
"-_s, _K = s[:], K",
"+# _s, _K = s[:], K",
"-ai = a.index(\"a\")",
"+# ai = a.index(\"a\")",
"- s = s[0:i] + \"a\" + s[i + 1 :]",
"+ s[i] = \"a\"",
"- s = s[:-1] + a[a.index(s[-1]) + K]",
"-print(s)",
"+ s[-1] = a[a.index(s[-1]) + K]",
"+print((\"\".join(s)))"
] | false | 0.058244 | 0.049645 | 1.173196 | [
"s571661466",
"s320439545"
] |
u256678932 | p02389 | python | s807199388 | s680857890 | 30 | 20 | 7,524 | 5,584 | Accepted | Accepted | 33.33 | a, b = list(map(int, input().split(' ')))
s = a*b
c = a*2 + b*2
print((s, c)) | (a, b) = list(map(int, input().split(' ')))
s = a*b
r = 2*(a+b)
print((s, r))
| 6 | 7 | 76 | 79 | a, b = list(map(int, input().split(" ")))
s = a * b
c = a * 2 + b * 2
print((s, c))
| (a, b) = list(map(int, input().split(" ")))
s = a * b
r = 2 * (a + b)
print((s, r))
| false | 14.285714 | [
"-a, b = list(map(int, input().split(\" \")))",
"+(a, b) = list(map(int, input().split(\" \")))",
"-c = a * 2 + b * 2",
"-print((s, c))",
"+r = 2 * (a + b)",
"+print((s, r))"
] | false | 0.049946 | 0.048998 | 1.019339 | [
"s807199388",
"s680857890"
] |
u278855471 | p03073 | python | s609112561 | s236779656 | 952 | 45 | 10,452 | 9,204 | Accepted | Accepted | 95.27 | S = eval(input())
counter = 0
for i in range(1, len(S)):
previous_color = S[i - 1]
checking_color = S[i]
if previous_color == checking_color:
counter += 1
if previous_color == '0':
S = S[:i] + '1' + S[i + 1:]
else:
S = S[:i] + '0' + S[i + 1:]
print((min(counter, abs(len(S) - counter))))
| S = eval(input())
if S[0] == '0':
A = '01' * len(S)
else:
A = '10' * len(S)
cnt = 0
for i in range(len(S)):
if S[i] != A[i]:
cnt += 1
print((min(cnt, abs(len(S) - cnt))))
| 12 | 13 | 351 | 198 | S = eval(input())
counter = 0
for i in range(1, len(S)):
previous_color = S[i - 1]
checking_color = S[i]
if previous_color == checking_color:
counter += 1
if previous_color == "0":
S = S[:i] + "1" + S[i + 1 :]
else:
S = S[:i] + "0" + S[i + 1 :]
print((min(counter, abs(len(S) - counter))))
| S = eval(input())
if S[0] == "0":
A = "01" * len(S)
else:
A = "10" * len(S)
cnt = 0
for i in range(len(S)):
if S[i] != A[i]:
cnt += 1
print((min(cnt, abs(len(S) - cnt))))
| false | 7.692308 | [
"-counter = 0",
"-for i in range(1, len(S)):",
"- previous_color = S[i - 1]",
"- checking_color = S[i]",
"- if previous_color == checking_color:",
"- counter += 1",
"- if previous_color == \"0\":",
"- S = S[:i] + \"1\" + S[i + 1 :]",
"- else:",
"- S = S[:i] + \"0\" + S[i + 1 :]",
"-print((min(counter, abs(len(S) - counter))))",
"+if S[0] == \"0\":",
"+ A = \"01\" * len(S)",
"+else:",
"+ A = \"10\" * len(S)",
"+cnt = 0",
"+for i in range(len(S)):",
"+ if S[i] != A[i]:",
"+ cnt += 1",
"+print((min(cnt, abs(len(S) - cnt))))"
] | false | 0.060242 | 0.006855 | 8.787779 | [
"s609112561",
"s236779656"
] |
u894258749 | p03339 | python | s483488666 | s285255894 | 212 | 189 | 60,248 | 41,560 | Accepted | Accepted | 10.85 | inpl = lambda: list(map(int,input().split()))
def get_sequence(arr):
if len(arr) == 0:
return [], []
elements = []
nums = []
n = 1
prev = arr[0]
for c in arr[1:]:
if c == prev:
n += 1
else:
elements.append(prev)
nums.append(n)
prev = c
n = 1
elements.append(prev)
nums.append(n)
return elements, nums
N = int(eval(input()))
S = eval(input())
ele, num = get_sequence(S)
Estart = 1-int(ele[0]=='E')
NE = sum(num[Estart::2])
ans = cur = NE
for i in range(len(num)):
if (i - Estart) % 2:
cur += num[i]
else:
cur -= num[i]
if cur < ans:
ans = cur
print(ans) | inpl = lambda: list(map(int,input().split()))
N = int(eval(input()))
S = eval(input())
NE = S.count('E')
ans = cur = NE
for s in S:
if s == 'E':
cur -= 1
if cur < ans:
ans = cur
else:
cur += 1
print(ans) | 34 | 13 | 738 | 247 | inpl = lambda: list(map(int, input().split()))
def get_sequence(arr):
if len(arr) == 0:
return [], []
elements = []
nums = []
n = 1
prev = arr[0]
for c in arr[1:]:
if c == prev:
n += 1
else:
elements.append(prev)
nums.append(n)
prev = c
n = 1
elements.append(prev)
nums.append(n)
return elements, nums
N = int(eval(input()))
S = eval(input())
ele, num = get_sequence(S)
Estart = 1 - int(ele[0] == "E")
NE = sum(num[Estart::2])
ans = cur = NE
for i in range(len(num)):
if (i - Estart) % 2:
cur += num[i]
else:
cur -= num[i]
if cur < ans:
ans = cur
print(ans)
| inpl = lambda: list(map(int, input().split()))
N = int(eval(input()))
S = eval(input())
NE = S.count("E")
ans = cur = NE
for s in S:
if s == "E":
cur -= 1
if cur < ans:
ans = cur
else:
cur += 1
print(ans)
| false | 61.764706 | [
"-",
"-",
"-def get_sequence(arr):",
"- if len(arr) == 0:",
"- return [], []",
"- elements = []",
"- nums = []",
"- n = 1",
"- prev = arr[0]",
"- for c in arr[1:]:",
"- if c == prev:",
"- n += 1",
"- else:",
"- elements.append(prev)",
"- nums.append(n)",
"- prev = c",
"- n = 1",
"- elements.append(prev)",
"- nums.append(n)",
"- return elements, nums",
"-",
"-",
"-ele, num = get_sequence(S)",
"-Estart = 1 - int(ele[0] == \"E\")",
"-NE = sum(num[Estart::2])",
"+NE = S.count(\"E\")",
"-for i in range(len(num)):",
"- if (i - Estart) % 2:",
"- cur += num[i]",
"- else:",
"- cur -= num[i]",
"+for s in S:",
"+ if s == \"E\":",
"+ cur -= 1",
"+ else:",
"+ cur += 1"
] | false | 0.151756 | 0.037056 | 4.095274 | [
"s483488666",
"s285255894"
] |
u430928274 | p03738 | python | s973064358 | s071767349 | 28 | 25 | 9,216 | 9,144 | Accepted | Accepted | 10.71 | import math
a = int(eval(input()))
b = int(eval(input()))
a = math.log10(a)
b = math.log10(b)
if a > b :
print("GREATER")
elif a == b :
print("EQUAL")
else :
print("LESS")
| import math
a = int(eval(input()))
b = int(eval(input()))
if a > b :
print("GREATER")
elif a == b :
print("EQUAL")
else :
print("LESS")
| 11 | 9 | 182 | 144 | import math
a = int(eval(input()))
b = int(eval(input()))
a = math.log10(a)
b = math.log10(b)
if a > b:
print("GREATER")
elif a == b:
print("EQUAL")
else:
print("LESS")
| import math
a = int(eval(input()))
b = int(eval(input()))
if a > b:
print("GREATER")
elif a == b:
print("EQUAL")
else:
print("LESS")
| false | 18.181818 | [
"-a = math.log10(a)",
"-b = math.log10(b)"
] | false | 0.043285 | 0.04266 | 1.014647 | [
"s973064358",
"s071767349"
] |
u370086573 | p02264 | python | s612532177 | s356873484 | 510 | 330 | 16,084 | 16,168 | Accepted | Accepted | 35.29 | def initialize():
global head, tail
def isEmpty():
global head, tail
return head == tail
def isFull():
global head, tail, MAX
return head == (tail + 1) % MAX
def enqueue(x):
global head, tail, Q, MAX
if isFull():
print("?????????????????????")
else:
Q[tail] = x
if tail + 1 == MAX:
tail = 0
else:
tail += 1
def dequeue():
global head, tail, Q, MAX
if isEmpty():
print("??¢??????????????????")
else:
t = Q[head]
if head + 1 == MAX:
head = 0
else:
head += 1
return t
if __name__ == "__main__":
n, q = list(map(int, input().split()))
head = 0
tail = n
MAX = 100000
Q = [0]*MAX
runtime = 0
for i in range(n):
name, time = input().split()
Q[i] = ([name, int(time)])
while head != tail:
t_list = dequeue()
if t_list[1] > q:
t_list[1] -= q
runtime += q
enqueue(t_list)
else:
runtime += t_list[1]
t_list[1] = 0
print((t_list[0] + " " + str(runtime))) | from collections import deque
if __name__ == '__main__':
n, q = list(map(int, input().split()))
Q = deque()
for i in range(n):
name,time = input().split()
Q.append([name, int(time)])
runtime = 0
while Q:
qt = Q.popleft()
if qt[1] > q:
runtime += q
qt[1] -= q
Q.append(qt)
else:
runtime += qt[1]
print((qt[0],runtime)) | 59 | 18 | 1,210 | 447 | def initialize():
global head, tail
def isEmpty():
global head, tail
return head == tail
def isFull():
global head, tail, MAX
return head == (tail + 1) % MAX
def enqueue(x):
global head, tail, Q, MAX
if isFull():
print("?????????????????????")
else:
Q[tail] = x
if tail + 1 == MAX:
tail = 0
else:
tail += 1
def dequeue():
global head, tail, Q, MAX
if isEmpty():
print("??¢??????????????????")
else:
t = Q[head]
if head + 1 == MAX:
head = 0
else:
head += 1
return t
if __name__ == "__main__":
n, q = list(map(int, input().split()))
head = 0
tail = n
MAX = 100000
Q = [0] * MAX
runtime = 0
for i in range(n):
name, time = input().split()
Q[i] = [name, int(time)]
while head != tail:
t_list = dequeue()
if t_list[1] > q:
t_list[1] -= q
runtime += q
enqueue(t_list)
else:
runtime += t_list[1]
t_list[1] = 0
print((t_list[0] + " " + str(runtime)))
| from collections import deque
if __name__ == "__main__":
n, q = list(map(int, input().split()))
Q = deque()
for i in range(n):
name, time = input().split()
Q.append([name, int(time)])
runtime = 0
while Q:
qt = Q.popleft()
if qt[1] > q:
runtime += q
qt[1] -= q
Q.append(qt)
else:
runtime += qt[1]
print((qt[0], runtime))
| false | 69.491525 | [
"-def initialize():",
"- global head, tail",
"-",
"-",
"-def isEmpty():",
"- global head, tail",
"- return head == tail",
"-",
"-",
"-def isFull():",
"- global head, tail, MAX",
"- return head == (tail + 1) % MAX",
"-",
"-",
"-def enqueue(x):",
"- global head, tail, Q, MAX",
"- if isFull():",
"- print(\"?????????????????????\")",
"- else:",
"- Q[tail] = x",
"- if tail + 1 == MAX:",
"- tail = 0",
"- else:",
"- tail += 1",
"-",
"-",
"-def dequeue():",
"- global head, tail, Q, MAX",
"- if isEmpty():",
"- print(\"??¢??????????????????\")",
"- else:",
"- t = Q[head]",
"- if head + 1 == MAX:",
"- head = 0",
"- else:",
"- head += 1",
"- return t",
"-",
"+from collections import deque",
"- head = 0",
"- tail = n",
"- MAX = 100000",
"- Q = [0] * MAX",
"- runtime = 0",
"+ Q = deque()",
"- Q[i] = [name, int(time)]",
"- while head != tail:",
"- t_list = dequeue()",
"- if t_list[1] > q:",
"- t_list[1] -= q",
"+ Q.append([name, int(time)])",
"+ runtime = 0",
"+ while Q:",
"+ qt = Q.popleft()",
"+ if qt[1] > q:",
"- enqueue(t_list)",
"+ qt[1] -= q",
"+ Q.append(qt)",
"- runtime += t_list[1]",
"- t_list[1] = 0",
"- print((t_list[0] + \" \" + str(runtime)))",
"+ runtime += qt[1]",
"+ print((qt[0], runtime))"
] | false | 0.040304 | 0.039086 | 1.031177 | [
"s612532177",
"s356873484"
] |
u857293613 | p03160 | python | s409306130 | s769187497 | 181 | 128 | 13,928 | 13,980 | Accepted | Accepted | 29.28 | n = int(eval(input()))
hlis = list(map(int, input().split()))
hlis.append(float('inf'))
dp = [0] + [abs(hlis[0] - hlis[1])] + [float('inf')]*(n-1)
for i in range(n-1):
one = abs(hlis[i]-hlis[i+1])
two = abs(hlis[i]-hlis[i+2])
dp[i+1] = min(dp[i]+one, dp[i+1])
dp[i+2] = min(dp[i]+two, dp[i+2])
print((dp[n-1])) | N = int(eval(input()))
hlis = list(map(int, input().split()))
dp = [-1]*N
dp[0] = 0
dp[1] = abs(hlis[0] - hlis[1])
for i in range(2, N):
dp[i] = min(dp[i-1]+abs(hlis[i]-hlis[i-1]), dp[i-2]+abs(hlis[i]-hlis[i-2]))
print((dp[-1])) | 10 | 8 | 327 | 231 | n = int(eval(input()))
hlis = list(map(int, input().split()))
hlis.append(float("inf"))
dp = [0] + [abs(hlis[0] - hlis[1])] + [float("inf")] * (n - 1)
for i in range(n - 1):
one = abs(hlis[i] - hlis[i + 1])
two = abs(hlis[i] - hlis[i + 2])
dp[i + 1] = min(dp[i] + one, dp[i + 1])
dp[i + 2] = min(dp[i] + two, dp[i + 2])
print((dp[n - 1]))
| N = int(eval(input()))
hlis = list(map(int, input().split()))
dp = [-1] * N
dp[0] = 0
dp[1] = abs(hlis[0] - hlis[1])
for i in range(2, N):
dp[i] = min(
dp[i - 1] + abs(hlis[i] - hlis[i - 1]), dp[i - 2] + abs(hlis[i] - hlis[i - 2])
)
print((dp[-1]))
| false | 20 | [
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-hlis.append(float(\"inf\"))",
"-dp = [0] + [abs(hlis[0] - hlis[1])] + [float(\"inf\")] * (n - 1)",
"-for i in range(n - 1):",
"- one = abs(hlis[i] - hlis[i + 1])",
"- two = abs(hlis[i] - hlis[i + 2])",
"- dp[i + 1] = min(dp[i] + one, dp[i + 1])",
"- dp[i + 2] = min(dp[i] + two, dp[i + 2])",
"-print((dp[n - 1]))",
"+dp = [-1] * N",
"+dp[0] = 0",
"+dp[1] = abs(hlis[0] - hlis[1])",
"+for i in range(2, N):",
"+ dp[i] = min(",
"+ dp[i - 1] + abs(hlis[i] - hlis[i - 1]), dp[i - 2] + abs(hlis[i] - hlis[i - 2])",
"+ )",
"+print((dp[-1]))"
] | false | 0.101067 | 0.039462 | 2.561085 | [
"s409306130",
"s769187497"
] |
u810356688 | p03244 | python | s344356522 | s149530823 | 277 | 98 | 65,132 | 21,944 | Accepted | Accepted | 64.62 | import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
n=int(eval(input()))
V=[int(_) for _ in input().split()]
even=V[0::2]
odd=V[1::2]
even_c=Counter(even)
odd_c=Counter(odd)
even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
even_ci.sort(key=itemgetter(1),reverse=True)
odd_ci.sort(key=itemgetter(1),reverse=True)
if even_ci[0][0]==odd_ci[0][0]:
if len(even_ci)>1 and len(odd_ci)>1:
print((min(sum(even_c.values())-even_ci[1][1]+sum(odd_c.values())-odd_ci[0][1],
sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[1][1])))
elif len(even_ci)>1 and len(odd_ci)==1:
print((sum(even_c.values())-even_ci[1][1]))
elif len(even_ci)==1 and len(odd_ci)>1:
print((sum(odd_c.values())-odd_ci[0][1]))
else:
print((n//2))
else:
print((sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1]))
if __name__=='__main__':
main() | import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
n=int(eval(input()))
V=[int(_) for _ in input().split()]
even,odd=V[0::2],V[1::2]
even_c,odd_c=Counter(even),Counter(odd)
even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
even_ci.sort(key=itemgetter(1),reverse=True)
odd_ci.sort(key=itemgetter(1),reverse=True)
if even_ci[0][0]==odd_ci[0][0]:
if len(even_ci)>1 and len(odd_ci)>1:
print((min(sum(even_c.values())-even_ci[1][1]+sum(odd_c.values())-odd_ci[0][1],
sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[1][1])))
elif len(even_ci)>1 and len(odd_ci)==1:
print((sum(even_c.values())-even_ci[1][1]))
elif len(even_ci)==1 and len(odd_ci)>1:
print((sum(odd_c.values())-odd_ci[0][1]))
else:
print((n//2))
else:
print((sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1]))
if __name__=='__main__':
main() | 29 | 27 | 1,116 | 1,106 | import sys
def input():
return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
n = int(eval(input()))
V = [int(_) for _ in input().split()]
even = V[0::2]
odd = V[1::2]
even_c = Counter(even)
odd_c = Counter(odd)
even_ci, odd_ci = list(even_c.items()), list(odd_c.items())
even_ci.sort(key=itemgetter(1), reverse=True)
odd_ci.sort(key=itemgetter(1), reverse=True)
if even_ci[0][0] == odd_ci[0][0]:
if len(even_ci) > 1 and len(odd_ci) > 1:
print(
(
min(
sum(even_c.values())
- even_ci[1][1]
+ sum(odd_c.values())
- odd_ci[0][1],
sum(even_c.values())
- even_ci[0][1]
+ sum(odd_c.values())
- odd_ci[1][1],
)
)
)
elif len(even_ci) > 1 and len(odd_ci) == 1:
print((sum(even_c.values()) - even_ci[1][1]))
elif len(even_ci) == 1 and len(odd_ci) > 1:
print((sum(odd_c.values()) - odd_ci[0][1]))
else:
print((n // 2))
else:
print(
(sum(even_c.values()) - even_ci[0][1] + sum(odd_c.values()) - odd_ci[0][1])
)
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
n = int(eval(input()))
V = [int(_) for _ in input().split()]
even, odd = V[0::2], V[1::2]
even_c, odd_c = Counter(even), Counter(odd)
even_ci, odd_ci = list(even_c.items()), list(odd_c.items())
even_ci.sort(key=itemgetter(1), reverse=True)
odd_ci.sort(key=itemgetter(1), reverse=True)
if even_ci[0][0] == odd_ci[0][0]:
if len(even_ci) > 1 and len(odd_ci) > 1:
print(
(
min(
sum(even_c.values())
- even_ci[1][1]
+ sum(odd_c.values())
- odd_ci[0][1],
sum(even_c.values())
- even_ci[0][1]
+ sum(odd_c.values())
- odd_ci[1][1],
)
)
)
elif len(even_ci) > 1 and len(odd_ci) == 1:
print((sum(even_c.values()) - even_ci[1][1]))
elif len(even_ci) == 1 and len(odd_ci) > 1:
print((sum(odd_c.values()) - odd_ci[0][1]))
else:
print((n // 2))
else:
print(
(sum(even_c.values()) - even_ci[0][1] + sum(odd_c.values()) - odd_ci[0][1])
)
if __name__ == "__main__":
main()
| false | 6.896552 | [
"- even = V[0::2]",
"- odd = V[1::2]",
"- even_c = Counter(even)",
"- odd_c = Counter(odd)",
"+ even, odd = V[0::2], V[1::2]",
"+ even_c, odd_c = Counter(even), Counter(odd)"
] | false | 0.097206 | 0.097553 | 0.99644 | [
"s344356522",
"s149530823"
] |
u054825571 | p03032 | python | s128424062 | s738371534 | 44 | 40 | 9,116 | 9,228 | Accepted | Accepted | 9.09 | N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
r=min(N,K)
ans=0
for a in range(r+1):
for b in range(r-a+1):
tmp,minus=0,[]
for i in range(a):
t=V[i]
tmp+=t
if t<0:
minus.append(t)
for j in range(b):
t=V[N-1-j]
tmp+=t
if t<0:
minus.append(t)
tmp-=sum(sorted(minus)[:K-(a+b)])
ans=max(ans,tmp)
print(ans)
| N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
for b in range(r-a+1):
tmp,minus=0,[]
for i in range(a):
tmp+=V[i]
if V[i]<0:
minus.append(V[i])
for j in range(b):
tmp+=V[N-j-1]
if V[N-j-1]<0:
minus.append(V[N-j-1])
tmp-=sum(sorted(minus)[:K-(a+b)])
ans=max(ans,tmp)
print(ans) | 20 | 17 | 485 | 407 | N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
r = min(N, K)
ans = 0
for a in range(r + 1):
for b in range(r - a + 1):
tmp, minus = 0, []
for i in range(a):
t = V[i]
tmp += t
if t < 0:
minus.append(t)
for j in range(b):
t = V[N - 1 - j]
tmp += t
if t < 0:
minus.append(t)
tmp -= sum(sorted(minus)[: K - (a + b)])
ans = max(ans, tmp)
print(ans)
| N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
r, ans = min(N, K), 0
for a in range(r + 1):
for b in range(r - a + 1):
tmp, minus = 0, []
for i in range(a):
tmp += V[i]
if V[i] < 0:
minus.append(V[i])
for j in range(b):
tmp += V[N - j - 1]
if V[N - j - 1] < 0:
minus.append(V[N - j - 1])
tmp -= sum(sorted(minus)[: K - (a + b)])
ans = max(ans, tmp)
print(ans)
| false | 15 | [
"-r = min(N, K)",
"-ans = 0",
"+r, ans = min(N, K), 0",
"- t = V[i]",
"- tmp += t",
"- if t < 0:",
"- minus.append(t)",
"+ tmp += V[i]",
"+ if V[i] < 0:",
"+ minus.append(V[i])",
"- t = V[N - 1 - j]",
"- tmp += t",
"- if t < 0:",
"- minus.append(t)",
"+ tmp += V[N - j - 1]",
"+ if V[N - j - 1] < 0:",
"+ minus.append(V[N - j - 1])"
] | false | 0.11312 | 0.038753 | 2.919011 | [
"s128424062",
"s738371534"
] |
u102461423 | p02793 | python | s026975020 | s051850583 | 1,081 | 579 | 5,984 | 5,880 | Accepted | Accepted | 46.44 | import sys
read = sys.stdin.buffer.read
from fractions import gcd
N,*A = list(map(int,read().split()))
lcm = 1
answer = 0
for x in A:
n = x//gcd(lcm,x)
lcm *= n
answer *= n
answer += lcm//x
answer %= (10**9 + 7)
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from fractions import gcd
from functools import reduce
N,*A = list(map(int,read().split()))
MOD = 10 ** 9 + 7
lcm = reduce(lambda x,y: y//gcd(x,y)*x, A)
lcm %= MOD
coef = sum(pow(x, MOD-2, MOD) for x in A)
answer = lcm * coef % MOD
print(answer) | 17 | 19 | 250 | 379 | import sys
read = sys.stdin.buffer.read
from fractions import gcd
N, *A = list(map(int, read().split()))
lcm = 1
answer = 0
for x in A:
n = x // gcd(lcm, x)
lcm *= n
answer *= n
answer += lcm // x
answer %= 10**9 + 7
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from fractions import gcd
from functools import reduce
N, *A = list(map(int, read().split()))
MOD = 10**9 + 7
lcm = reduce(lambda x, y: y // gcd(x, y) * x, A)
lcm %= MOD
coef = sum(pow(x, MOD - 2, MOD) for x in A)
answer = lcm * coef % MOD
print(answer)
| false | 10.526316 | [
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+from functools import reduce",
"-lcm = 1",
"-answer = 0",
"-for x in A:",
"- n = x // gcd(lcm, x)",
"- lcm *= n",
"- answer *= n",
"- answer += lcm // x",
"-answer %= 10**9 + 7",
"+MOD = 10**9 + 7",
"+lcm = reduce(lambda x, y: y // gcd(x, y) * x, A)",
"+lcm %= MOD",
"+coef = sum(pow(x, MOD - 2, MOD) for x in A)",
"+answer = lcm * coef % MOD"
] | false | 0.098586 | 0.119151 | 0.827403 | [
"s026975020",
"s051850583"
] |
u089230684 | p03239 | python | s091964788 | s209719413 | 167 | 17 | 38,460 | 3,064 | Accepted | Accepted | 89.82 | def a():
n=list(map(int, input().split()))
c=list()
t = list()
for i in range(n[0]):
s = list(map(int, input().split()))
c.append(s[0])
t.append(s[1])
z=list()
z[len(z):]=t[:len(t)]
z.sort()
if z[0]>n[1]:
print("TLE")
return 0
l=0
for i in range(1,len(c)):
if (c[i]<=c[l]) & (t[i]<=n[1]):
l = i
print((c[l]))
return 0
a() | def MRX():
N,T = input().split()
N,T= int(N),int(T)
travel = {}
for i in range(N):
c , t = input().split()
travel[int(c)] = int(t)
for j in sorted(travel):
if travel[j] <= T:
return j
return "TLE"
print((MRX())) | 21 | 15 | 447 | 286 | def a():
n = list(map(int, input().split()))
c = list()
t = list()
for i in range(n[0]):
s = list(map(int, input().split()))
c.append(s[0])
t.append(s[1])
z = list()
z[len(z) :] = t[: len(t)]
z.sort()
if z[0] > n[1]:
print("TLE")
return 0
l = 0
for i in range(1, len(c)):
if (c[i] <= c[l]) & (t[i] <= n[1]):
l = i
print((c[l]))
return 0
a()
| def MRX():
N, T = input().split()
N, T = int(N), int(T)
travel = {}
for i in range(N):
c, t = input().split()
travel[int(c)] = int(t)
for j in sorted(travel):
if travel[j] <= T:
return j
return "TLE"
print((MRX()))
| false | 28.571429 | [
"-def a():",
"- n = list(map(int, input().split()))",
"- c = list()",
"- t = list()",
"- for i in range(n[0]):",
"- s = list(map(int, input().split()))",
"- c.append(s[0])",
"- t.append(s[1])",
"- z = list()",
"- z[len(z) :] = t[: len(t)]",
"- z.sort()",
"- if z[0] > n[1]:",
"- print(\"TLE\")",
"- return 0",
"- l = 0",
"- for i in range(1, len(c)):",
"- if (c[i] <= c[l]) & (t[i] <= n[1]):",
"- l = i",
"- print((c[l]))",
"- return 0",
"+def MRX():",
"+ N, T = input().split()",
"+ N, T = int(N), int(T)",
"+ travel = {}",
"+ for i in range(N):",
"+ c, t = input().split()",
"+ travel[int(c)] = int(t)",
"+ for j in sorted(travel):",
"+ if travel[j] <= T:",
"+ return j",
"+ return \"TLE\"",
"-a()",
"+print((MRX()))"
] | false | 0.043448 | 0.043095 | 1.0082 | [
"s091964788",
"s209719413"
] |
u241159583 | p02819 | python | s784136897 | s180673519 | 103 | 18 | 5,400 | 2,940 | Accepted | Accepted | 82.52 | import bisect
x = int(eval(input()))
def get_prime(n):
if n <= 1: return []
limit = int(n**0.5)
prime = [2]
data = [i+1 for i in range(2,n,2)]
while limit >= data[0]:
prime.append(data[0])
data = [j for j in data if j % data[0] != 0]
return prime + data
l = get_prime(10**5+3)
i = bisect.bisect_right(l, x)
if l[i-1] == x: print(x)
else: print((l[i])) | x = int(eval(input()))
def is_prime(n):
if n <= 1: return False
for i in range(2, int(n**0.5)+1):
if n % i == 0: return False
return True
if not is_prime(x):
while not is_prime(x):
x += 1
print(x) | 17 | 12 | 381 | 219 | import bisect
x = int(eval(input()))
def get_prime(n):
if n <= 1:
return []
limit = int(n**0.5)
prime = [2]
data = [i + 1 for i in range(2, n, 2)]
while limit >= data[0]:
prime.append(data[0])
data = [j for j in data if j % data[0] != 0]
return prime + data
l = get_prime(10**5 + 3)
i = bisect.bisect_right(l, x)
if l[i - 1] == x:
print(x)
else:
print((l[i]))
| x = int(eval(input()))
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if not is_prime(x):
while not is_prime(x):
x += 1
print(x)
| false | 29.411765 | [
"-import bisect",
"-",
"-def get_prime(n):",
"+def is_prime(n):",
"- return []",
"- limit = int(n**0.5)",
"- prime = [2]",
"- data = [i + 1 for i in range(2, n, 2)]",
"- while limit >= data[0]:",
"- prime.append(data[0])",
"- data = [j for j in data if j % data[0] != 0]",
"- return prime + data",
"+ return False",
"+ for i in range(2, int(n**0.5) + 1):",
"+ if n % i == 0:",
"+ return False",
"+ return True",
"-l = get_prime(10**5 + 3)",
"-i = bisect.bisect_right(l, x)",
"-if l[i - 1] == x:",
"- print(x)",
"-else:",
"- print((l[i]))",
"+if not is_prime(x):",
"+ while not is_prime(x):",
"+ x += 1",
"+print(x)"
] | false | 0.118669 | 0.071251 | 1.665514 | [
"s784136897",
"s180673519"
] |
u228223940 | p03805 | python | s619747524 | s438210799 | 28 | 24 | 3,064 | 3,064 | Accepted | Accepted | 14.29 | N, M = list(map(int, input().split()))
adj_matrix = [[0]* N for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
adj_matrix[a-1][b-1] = 1
adj_matrix[b-1][a-1] = 1
def dfs(v, used):
if not False in used:
return 1
ans = 0
for i in range(N):
if not adj_matrix[v][i]:
continue
if used[i]:
continue
used[i] = True
ans += dfs(i, used)
used[i] = False
return ans
used = [False] * N
used[0] = True
print((dfs(0, used))) | import bisect
n,m = list(map(int,input().split()))
g = [[ ] for i in range(n+1)]
for i in range(m):
a,b = list(map(int,input().split()))
g[a].append(b)
g[b].append(a)
#print(bisect.bisect_left(g[a],b))
#g[a][] = b
#g[a].append(b)
#g[b].append(a)
#g[4].sort()
ans = 0
def dfs(x,check):
#print(check,x)
ans = 0
if not False in check:
#print(ans)
return 1
#check[x] = 0
#print(x)
#print(check)
for i in g[x]:
if check[i] == True:
continue
#print(i,check)
check[i] = True
ans += dfs(i,check)
check[i] = False
return ans
check = [False] * (n+1)
check[0] = True
check[1] = True
print((dfs(1,check)))
| 29 | 44 | 572 | 781 | N, M = list(map(int, input().split()))
adj_matrix = [[0] * N for _ in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
adj_matrix[a - 1][b - 1] = 1
adj_matrix[b - 1][a - 1] = 1
def dfs(v, used):
if not False in used:
return 1
ans = 0
for i in range(N):
if not adj_matrix[v][i]:
continue
if used[i]:
continue
used[i] = True
ans += dfs(i, used)
used[i] = False
return ans
used = [False] * N
used[0] = True
print((dfs(0, used)))
| import bisect
n, m = list(map(int, input().split()))
g = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
g[a].append(b)
g[b].append(a)
# print(bisect.bisect_left(g[a],b))
# g[a][] = b
# g[a].append(b)
# g[b].append(a)
# g[4].sort()
ans = 0
def dfs(x, check):
# print(check,x)
ans = 0
if not False in check:
# print(ans)
return 1
# check[x] = 0
# print(x)
# print(check)
for i in g[x]:
if check[i] == True:
continue
# print(i,check)
check[i] = True
ans += dfs(i, check)
check[i] = False
return ans
check = [False] * (n + 1)
check[0] = True
check[1] = True
print((dfs(1, check)))
| false | 34.090909 | [
"-N, M = list(map(int, input().split()))",
"-adj_matrix = [[0] * N for _ in range(N)]",
"-for i in range(M):",
"+import bisect",
"+",
"+n, m = list(map(int, input().split()))",
"+g = [[] for i in range(n + 1)]",
"+for i in range(m):",
"- adj_matrix[a - 1][b - 1] = 1",
"- adj_matrix[b - 1][a - 1] = 1",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+ # print(bisect.bisect_left(g[a],b))",
"+ # g[a][] = b",
"+ # g[a].append(b)",
"+ # g[b].append(a)",
"+# g[4].sort()",
"+ans = 0",
"-def dfs(v, used):",
"- if not False in used:",
"+def dfs(x, check):",
"+ # print(check,x)",
"+ ans = 0",
"+ if not False in check:",
"+ # print(ans)",
"- ans = 0",
"- for i in range(N):",
"- if not adj_matrix[v][i]:",
"+ # check[x] = 0",
"+ # print(x)",
"+ # print(check)",
"+ for i in g[x]:",
"+ if check[i] == True:",
"- if used[i]:",
"- continue",
"- used[i] = True",
"- ans += dfs(i, used)",
"- used[i] = False",
"+ # print(i,check)",
"+ check[i] = True",
"+ ans += dfs(i, check)",
"+ check[i] = False",
"-used = [False] * N",
"-used[0] = True",
"-print((dfs(0, used)))",
"+check = [False] * (n + 1)",
"+check[0] = True",
"+check[1] = True",
"+print((dfs(1, check)))"
] | false | 0.033389 | 0.046463 | 0.718605 | [
"s619747524",
"s438210799"
] |
u038819082 | p02701 | python | s424898957 | s248700564 | 300 | 277 | 35,572 | 35,680 | Accepted | Accepted | 7.67 | N=int(eval(input()))
S=[]
for i in range(N):
S.append(str(eval(input())))
print((len(set(S)))) | N=int(eval(input()))
a=[]
for i in range(N):
a.append(eval(input()))
print((len(set(a)))) | 5 | 5 | 86 | 81 | N = int(eval(input()))
S = []
for i in range(N):
S.append(str(eval(input())))
print((len(set(S))))
| N = int(eval(input()))
a = []
for i in range(N):
a.append(eval(input()))
print((len(set(a))))
| false | 0 | [
"-S = []",
"+a = []",
"- S.append(str(eval(input())))",
"-print((len(set(S))))",
"+ a.append(eval(input()))",
"+print((len(set(a))))"
] | false | 0.102965 | 0.007655 | 13.450282 | [
"s424898957",
"s248700564"
] |
u075012704 | p02955 | python | s965972529 | s624591415 | 275 | 240 | 42,844 | 3,188 | Accepted | Accepted | 12.73 | from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
M = sum(A)
ans_candidates = []
for n in range(1, int(M ** 0.5) + 1):
if M % n == 0:
ans_candidates.append(n)
ans_candidates.append(M // n)
ans = 0
for X in ans_candidates:
alpha = sorted([(a % X) for a in A])
beta = [X - a for a in alpha]
alpha = list(accumulate(alpha))
beta = list(accumulate(beta))
for i in range(N):
if alpha[i] > K:
break
if alpha[i] == (beta[-1] - beta[i]):
ans = max(ans, X)
break
print(ans)
| from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
M = sum(A)
# 答えの候補を列挙
ans_candidates = []
for n in range(1, int(M ** 0.5) + 1):
if M % n == 0:
ans_candidates.append(n)
ans_candidates.append(M // n)
ans = 0
for X in ans_candidates:
A_mod = sorted([a % X for a in A])
U = [X - a for a in A_mod]
D = [-a for a in A_mod] # わかりやすいので
U = list(accumulate(U))
D = list(accumulate(D))
for i in range(N):
if -D[i] > K:
break
if -D[i] == (U[-1] - U[i]):
ans = max(ans, X)
break
print(ans)
| 30 | 31 | 646 | 666 | from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
M = sum(A)
ans_candidates = []
for n in range(1, int(M**0.5) + 1):
if M % n == 0:
ans_candidates.append(n)
ans_candidates.append(M // n)
ans = 0
for X in ans_candidates:
alpha = sorted([(a % X) for a in A])
beta = [X - a for a in alpha]
alpha = list(accumulate(alpha))
beta = list(accumulate(beta))
for i in range(N):
if alpha[i] > K:
break
if alpha[i] == (beta[-1] - beta[i]):
ans = max(ans, X)
break
print(ans)
| from itertools import accumulate
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
M = sum(A)
# 答えの候補を列挙
ans_candidates = []
for n in range(1, int(M**0.5) + 1):
if M % n == 0:
ans_candidates.append(n)
ans_candidates.append(M // n)
ans = 0
for X in ans_candidates:
A_mod = sorted([a % X for a in A])
U = [X - a for a in A_mod]
D = [-a for a in A_mod] # わかりやすいので
U = list(accumulate(U))
D = list(accumulate(D))
for i in range(N):
if -D[i] > K:
break
if -D[i] == (U[-1] - U[i]):
ans = max(ans, X)
break
print(ans)
| false | 3.225806 | [
"+# 答えの候補を列挙",
"- alpha = sorted([(a % X) for a in A])",
"- beta = [X - a for a in alpha]",
"- alpha = list(accumulate(alpha))",
"- beta = list(accumulate(beta))",
"+ A_mod = sorted([a % X for a in A])",
"+ U = [X - a for a in A_mod]",
"+ D = [-a for a in A_mod] # わかりやすいので",
"+ U = list(accumulate(U))",
"+ D = list(accumulate(D))",
"- if alpha[i] > K:",
"+ if -D[i] > K:",
"- if alpha[i] == (beta[-1] - beta[i]):",
"+ if -D[i] == (U[-1] - U[i]):"
] | false | 0.039888 | 0.063482 | 0.62833 | [
"s965972529",
"s624591415"
] |
u553987207 | p02684 | python | s321976617 | s253760994 | 205 | 166 | 32,192 | 32,460 | Accepted | Accepted | 19.02 | N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
R = []
done = set()
todo = [0]
done = set()
bp = None
while todo:
p = todo.pop()
R.append(p)
done.add(p)
np = A[p]
if np in done:
bp = np
else:
todo.append(np)
b = R.index(bp)
if K < b:
ans = R[K] + 1
else:
K -= b
R = R[b:]
ans = R[K%len(R)] + 1
print(ans) | N, K = list(map(int, input().split()))
A = tuple(int(x) - 1 for x in input().split())
done = {0}
rt = [0]
loop_point = 0
while True:
p = rt[-1]
np = A[p]
if np in done:
loop_point = np
break
done.add(np)
rt.append(np)
if K < len(rt):
ans = rt[K] + 1
else:
K -= len(rt)
rt = rt[rt.index(loop_point):]
ans = rt[K%len(rt)] + 1
print(ans) | 25 | 21 | 423 | 401 | N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
R = []
done = set()
todo = [0]
done = set()
bp = None
while todo:
p = todo.pop()
R.append(p)
done.add(p)
np = A[p]
if np in done:
bp = np
else:
todo.append(np)
b = R.index(bp)
if K < b:
ans = R[K] + 1
else:
K -= b
R = R[b:]
ans = R[K % len(R)] + 1
print(ans)
| N, K = list(map(int, input().split()))
A = tuple(int(x) - 1 for x in input().split())
done = {0}
rt = [0]
loop_point = 0
while True:
p = rt[-1]
np = A[p]
if np in done:
loop_point = np
break
done.add(np)
rt.append(np)
if K < len(rt):
ans = rt[K] + 1
else:
K -= len(rt)
rt = rt[rt.index(loop_point) :]
ans = rt[K % len(rt)] + 1
print(ans)
| false | 16 | [
"-A = list([int(x) - 1 for x in input().split()])",
"-R = []",
"-done = set()",
"-todo = [0]",
"-done = set()",
"-bp = None",
"-while todo:",
"- p = todo.pop()",
"- R.append(p)",
"- done.add(p)",
"+A = tuple(int(x) - 1 for x in input().split())",
"+done = {0}",
"+rt = [0]",
"+loop_point = 0",
"+while True:",
"+ p = rt[-1]",
"- bp = np",
"- else:",
"- todo.append(np)",
"-b = R.index(bp)",
"-if K < b:",
"- ans = R[K] + 1",
"+ loop_point = np",
"+ break",
"+ done.add(np)",
"+ rt.append(np)",
"+if K < len(rt):",
"+ ans = rt[K] + 1",
"- K -= b",
"- R = R[b:]",
"- ans = R[K % len(R)] + 1",
"+ K -= len(rt)",
"+ rt = rt[rt.index(loop_point) :]",
"+ ans = rt[K % len(rt)] + 1"
] | false | 0.044061 | 0.043855 | 1.004708 | [
"s321976617",
"s253760994"
] |
u562935282 | p03212 | python | s124712416 | s574137741 | 136 | 92 | 3,692 | 2,940 | Accepted | Accepted | 32.35 | n = int(eval(input()))
ans = 0
t = [3, 5, 7]
while len(t) > 0:
x = t.pop(0)
if x * 10 + 3 <= n:
t.append(x * 10 + 3)
if x * 10 + 5 <= n:
t.append(x * 10 + 5)
if x * 10 + 7 <= n:
t.append(x * 10 + 7)
if 357 <= x <= n:
s = str(x)
if '3' in s and '5' in s and '7' in s:
ans += 1
print(ans)
| # https://img.atcoder.jp/abc114/editorial.pdf
N = int(eval(input()))
def dfs(s): # 文字列 s で始まる七五三数の個数
if int(s) > N:
return 0
ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
for c in '753':
ret += dfs(s + c)
return ret
print((dfs('0'))) # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく
| 17 | 14 | 394 | 341 | n = int(eval(input()))
ans = 0
t = [3, 5, 7]
while len(t) > 0:
x = t.pop(0)
if x * 10 + 3 <= n:
t.append(x * 10 + 3)
if x * 10 + 5 <= n:
t.append(x * 10 + 5)
if x * 10 + 7 <= n:
t.append(x * 10 + 7)
if 357 <= x <= n:
s = str(x)
if "3" in s and "5" in s and "7" in s:
ans += 1
print(ans)
| # https://img.atcoder.jp/abc114/editorial.pdf
N = int(eval(input()))
def dfs(s): # 文字列 s で始まる七五三数の個数
if int(s) > N:
return 0
ret = 1 if all(s.count(c) > 0 for c in "753") else 0 # s 自体が七五三数なら +1
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0"))) # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく
| false | 17.647059 | [
"-n = int(eval(input()))",
"-ans = 0",
"-t = [3, 5, 7]",
"-while len(t) > 0:",
"- x = t.pop(0)",
"- if x * 10 + 3 <= n:",
"- t.append(x * 10 + 3)",
"- if x * 10 + 5 <= n:",
"- t.append(x * 10 + 5)",
"- if x * 10 + 7 <= n:",
"- t.append(x * 10 + 7)",
"- if 357 <= x <= n:",
"- s = str(x)",
"- if \"3\" in s and \"5\" in s and \"7\" in s:",
"- ans += 1",
"-print(ans)",
"+# https://img.atcoder.jp/abc114/editorial.pdf",
"+N = int(eval(input()))",
"+",
"+",
"+def dfs(s): # 文字列 s で始まる七五三数の個数",
"+ if int(s) > N:",
"+ return 0",
"+ ret = 1 if all(s.count(c) > 0 for c in \"753\") else 0 # s 自体が七五三数なら +1",
"+ for c in \"753\":",
"+ ret += dfs(s + c)",
"+ return ret",
"+",
"+",
"+print((dfs(\"0\"))) # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく"
] | false | 0.050542 | 0.047277 | 1.06905 | [
"s124712416",
"s574137741"
] |
u867069435 | p03426 | python | s678239928 | s278029447 | 1,836 | 1,664 | 51,936 | 51,896 | Accepted | Accepted | 9.37 | from functools import lru_cache
h, w, d = list(map(int, input().split()))
pos = [[] for j in range(h*w)]
for a in range(h):
s = list(map(int, input().split()))
for g in range(w):
pos[s[g] -1] = [s[g], a+1, g+1]
q = int(eval(input()))
def soo(now, start):
next = now + d
prevy, prevx = pos[now - 1][1], pos[now - 1][2]
nexty, nextx = pos[next - 1][1], pos[next - 1][2]
return ((abs(nexty - prevy) + abs(nextx - prevx)))
def solve(start, end):
now = 0
ans = 0
for i in range(int((end - start) / d)):
now = start if not now else now + d
ans += soo(now, start)
return ans
time = [0 for h in range(h*w)]
for l in range(h*w - d):
if not time[l + d]:
time[l+d] = time[l] + (abs(pos[l+d][1] - pos[l][1]) + abs(pos[l+d][2] - pos[l][2]))
@lru_cache(maxsize=None)
def ask(st, en):
return time[en-1] - time[st-1]
for rr in range(q):
dd, ff = list(map(int, input().split()))
print((ask(dd, ff))) | from functools import lru_cache
h, w, d = list(map(int, input().split()))
pos = [[] for j in range(h*w)]
for a in range(h):
s = list(map(int, input().split()))
for g in range(w):
pos[s[g] -1] = [s[g], a+1, g+1]
q = int(eval(input()))
time = [0 for h in range(h*w)]
for l in range(h*w - d):
if not time[l + d]:
time[l+d] = time[l] + (abs(pos[l+d][1] - pos[l][1]) + abs(pos[l+d][2] - pos[l][2]))
@lru_cache(maxsize=None)
def ask(st, en):
return time[en-1] - time[st-1]
for rr in range(q):
dd, ff = list(map(int, input().split()))
print((ask(dd, ff)))
| 37 | 23 | 993 | 596 | from functools import lru_cache
h, w, d = list(map(int, input().split()))
pos = [[] for j in range(h * w)]
for a in range(h):
s = list(map(int, input().split()))
for g in range(w):
pos[s[g] - 1] = [s[g], a + 1, g + 1]
q = int(eval(input()))
def soo(now, start):
next = now + d
prevy, prevx = pos[now - 1][1], pos[now - 1][2]
nexty, nextx = pos[next - 1][1], pos[next - 1][2]
return abs(nexty - prevy) + abs(nextx - prevx)
def solve(start, end):
now = 0
ans = 0
for i in range(int((end - start) / d)):
now = start if not now else now + d
ans += soo(now, start)
return ans
time = [0 for h in range(h * w)]
for l in range(h * w - d):
if not time[l + d]:
time[l + d] = time[l] + (
abs(pos[l + d][1] - pos[l][1]) + abs(pos[l + d][2] - pos[l][2])
)
@lru_cache(maxsize=None)
def ask(st, en):
return time[en - 1] - time[st - 1]
for rr in range(q):
dd, ff = list(map(int, input().split()))
print((ask(dd, ff)))
| from functools import lru_cache
h, w, d = list(map(int, input().split()))
pos = [[] for j in range(h * w)]
for a in range(h):
s = list(map(int, input().split()))
for g in range(w):
pos[s[g] - 1] = [s[g], a + 1, g + 1]
q = int(eval(input()))
time = [0 for h in range(h * w)]
for l in range(h * w - d):
if not time[l + d]:
time[l + d] = time[l] + (
abs(pos[l + d][1] - pos[l][1]) + abs(pos[l + d][2] - pos[l][2])
)
@lru_cache(maxsize=None)
def ask(st, en):
return time[en - 1] - time[st - 1]
for rr in range(q):
dd, ff = list(map(int, input().split()))
print((ask(dd, ff)))
| false | 37.837838 | [
"-",
"-",
"-def soo(now, start):",
"- next = now + d",
"- prevy, prevx = pos[now - 1][1], pos[now - 1][2]",
"- nexty, nextx = pos[next - 1][1], pos[next - 1][2]",
"- return abs(nexty - prevy) + abs(nextx - prevx)",
"-",
"-",
"-def solve(start, end):",
"- now = 0",
"- ans = 0",
"- for i in range(int((end - start) / d)):",
"- now = start if not now else now + d",
"- ans += soo(now, start)",
"- return ans",
"-",
"-"
] | false | 0.049928 | 0.036332 | 1.374209 | [
"s678239928",
"s278029447"
] |
u667024514 | p03107 | python | s787732459 | s777729522 | 25 | 18 | 3,572 | 3,188 | Accepted | Accepted | 28 | from collections import Counter
s = str(eval(input()))
print((len(s)-abs(s.count("1")-s.count("0")))) | s = str(eval(input()))
print((len(s)-abs(s.count("1")-s.count("0")))) | 3 | 2 | 95 | 62 | from collections import Counter
s = str(eval(input()))
print((len(s) - abs(s.count("1") - s.count("0"))))
| s = str(eval(input()))
print((len(s) - abs(s.count("1") - s.count("0"))))
| false | 33.333333 | [
"-from collections import Counter",
"-"
] | false | 0.034948 | 0.040786 | 0.856871 | [
"s787732459",
"s777729522"
] |
u492605584 | p03212 | python | s420172577 | s058401008 | 112 | 38 | 3,060 | 4,340 | Accepted | Accepted | 66.07 | N = int(eval(input()))
def check_753(s):
s = str(int(s))
a = ''.join(sorted(list(set(s))))
if a == '357':
return True
else:
return False
def shi(s):
if int(s) > N:
return 0
if check_753(s):
ret = 1
else:
ret = 0
for i in '753':
ret += shi(s+i)
return ret
print((shi('0')))
| import itertools as t
N = int(eval(input()))
L = [ int(''.join(j)) for i in range(10) for j in t.product(['3','5','7'], repeat=i) if '3' in j and '5' in j and '7' in j]
L = [i for i in L if i <= N]
print((len(L)))
| 22 | 7 | 331 | 214 | N = int(eval(input()))
def check_753(s):
s = str(int(s))
a = "".join(sorted(list(set(s))))
if a == "357":
return True
else:
return False
def shi(s):
if int(s) > N:
return 0
if check_753(s):
ret = 1
else:
ret = 0
for i in "753":
ret += shi(s + i)
return ret
print((shi("0")))
| import itertools as t
N = int(eval(input()))
L = [
int("".join(j))
for i in range(10)
for j in t.product(["3", "5", "7"], repeat=i)
if "3" in j and "5" in j and "7" in j
]
L = [i for i in L if i <= N]
print((len(L)))
| false | 68.181818 | [
"+import itertools as t",
"+",
"-",
"-",
"-def check_753(s):",
"- s = str(int(s))",
"- a = \"\".join(sorted(list(set(s))))",
"- if a == \"357\":",
"- return True",
"- else:",
"- return False",
"-",
"-",
"-def shi(s):",
"- if int(s) > N:",
"- return 0",
"- if check_753(s):",
"- ret = 1",
"- else:",
"- ret = 0",
"- for i in \"753\":",
"- ret += shi(s + i)",
"- return ret",
"-",
"-",
"-print((shi(\"0\")))",
"+L = [",
"+ int(\"\".join(j))",
"+ for i in range(10)",
"+ for j in t.product([\"3\", \"5\", \"7\"], repeat=i)",
"+ if \"3\" in j and \"5\" in j and \"7\" in j",
"+]",
"+L = [i for i in L if i <= N]",
"+print((len(L)))"
] | false | 0.126646 | 0.081765 | 1.548894 | [
"s420172577",
"s058401008"
] |
u863442865 | p03325 | python | s590717329 | s702476528 | 114 | 59 | 4,148 | 4,148 | Accepted | Accepted | 48.25 | n = int(eval(input()))
ni = list(map(int, input().split()))
cnt = 0
for i in ni:
while not i % 2:
i /= 2
cnt += 1
print(cnt) | N = int(eval(input()))
a = list(map(int, input().split()))
def f(n):
cnt = 0
while(n%2==0):
n = n//2
cnt +=1
return cnt
total = 0
for e in a:
total += f(e)
print(total) | 8 | 14 | 135 | 195 | n = int(eval(input()))
ni = list(map(int, input().split()))
cnt = 0
for i in ni:
while not i % 2:
i /= 2
cnt += 1
print(cnt)
| N = int(eval(input()))
a = list(map(int, input().split()))
def f(n):
cnt = 0
while n % 2 == 0:
n = n // 2
cnt += 1
return cnt
total = 0
for e in a:
total += f(e)
print(total)
| false | 42.857143 | [
"-n = int(eval(input()))",
"-ni = list(map(int, input().split()))",
"-cnt = 0",
"-for i in ni:",
"- while not i % 2:",
"- i /= 2",
"+N = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+",
"+",
"+def f(n):",
"+ cnt = 0",
"+ while n % 2 == 0:",
"+ n = n // 2",
"-print(cnt)",
"+ return cnt",
"+",
"+",
"+total = 0",
"+for e in a:",
"+ total += f(e)",
"+print(total)"
] | false | 0.042374 | 0.038503 | 1.100548 | [
"s590717329",
"s702476528"
] |
u968166680 | p03634 | python | s594122212 | s170716657 | 492 | 376 | 65,164 | 65,404 | Accepted | Accepted | 23.58 | import sys
from heapq import heappush, heappop
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = map(int, readline().split())
G[a - 1].append((b - 1, c))
G[b - 1].append((a - 1, c))
Q, K, *XY = map(int, read().split())
K -= 1
hq = [(0, K)]
dist = [INF] * N
dist[K] = 0
while hq:
d, v = heappop(hq)
if dist[v] < d:
continue
for nv, cost in G[v]:
if dist[nv] > d + cost:
dist[nv] = d + cost
heappush(hq, (dist[nv], nv))
ans = [0] * Q
for i, (x, y) in enumerate(zip(*[iter(XY)] * 2)):
ans[i] = dist[x - 1] + dist[y - 1]
print(*ans, sep='\n')
return
if __name__ == '__main__':
main()
| import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = map(int, readline().split())
G[a - 1].append((b - 1, c))
G[b - 1].append((a - 1, c))
Q, K, *XY = map(int, read().split())
K -= 1
stack = deque([K])
dist = [INF] * N
dist[K] = 0
while stack:
v = stack.pop()
for nv, cost in G[v]:
if dist[nv] == INF:
dist[nv] = dist[v] + cost
stack.append(nv)
ans = [0] * Q
for i, (x, y) in enumerate(zip(*[iter(XY)] * 2)):
ans[i] = dist[x - 1] + dist[y - 1]
print(*ans, sep='\n')
return
if __name__ == '__main__':
main()
| 44 | 42 | 988 | 930 | import sys
from heapq import heappush, heappop
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = map(int, readline().split())
G[a - 1].append((b - 1, c))
G[b - 1].append((a - 1, c))
Q, K, *XY = map(int, read().split())
K -= 1
hq = [(0, K)]
dist = [INF] * N
dist[K] = 0
while hq:
d, v = heappop(hq)
if dist[v] < d:
continue
for nv, cost in G[v]:
if dist[nv] > d + cost:
dist[nv] = d + cost
heappush(hq, (dist[nv], nv))
ans = [0] * Q
for i, (x, y) in enumerate(zip(*[iter(XY)] * 2)):
ans[i] = dist[x - 1] + dist[y - 1]
print(*ans, sep="\n")
return
if __name__ == "__main__":
main()
| import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = map(int, readline().split())
G[a - 1].append((b - 1, c))
G[b - 1].append((a - 1, c))
Q, K, *XY = map(int, read().split())
K -= 1
stack = deque([K])
dist = [INF] * N
dist[K] = 0
while stack:
v = stack.pop()
for nv, cost in G[v]:
if dist[nv] == INF:
dist[nv] = dist[v] + cost
stack.append(nv)
ans = [0] * Q
for i, (x, y) in enumerate(zip(*[iter(XY)] * 2)):
ans[i] = dist[x - 1] + dist[y - 1]
print(*ans, sep="\n")
return
if __name__ == "__main__":
main()
| false | 4.545455 | [
"-from heapq import heappush, heappop",
"+from collections import deque",
"- hq = [(0, K)]",
"+ stack = deque([K])",
"- while hq:",
"- d, v = heappop(hq)",
"- if dist[v] < d:",
"- continue",
"+ while stack:",
"+ v = stack.pop()",
"- if dist[nv] > d + cost:",
"- dist[nv] = d + cost",
"- heappush(hq, (dist[nv], nv))",
"+ if dist[nv] == INF:",
"+ dist[nv] = dist[v] + cost",
"+ stack.append(nv)"
] | false | 0.044875 | 0.036849 | 1.217806 | [
"s594122212",
"s170716657"
] |
u677523557 | p02868 | python | s755994766 | s782784558 | 1,079 | 616 | 34,176 | 71,600 | Accepted | Accepted | 42.91 | # instead of AVLTree
INF = 10**14
class BIT():
def __init__(self, max):
self.max = max
self.data = [INF]*(self.max+1)
def update(self, i, x):
while i > 0:
self.data[i] = min(self.data[i], x)
i -= i & -i
def read(self, i):
m = INF
while i <= self.max:
m = min(self.data[i], m)
i += i & -i
return m
import sys
input = sys.stdin.readline
from operator import itemgetter
N, M = list(map(int, input().split()))
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))
bit = BIT(N)
bit.update(1, 0)
for l, r, c in LRC:
m = bit.read(l)
bit.update(r, m+c)
ans = bit.data[N]
if ans == INF:
print((-1))
else:
print(ans) | import sys
input = sys.stdin.readline
import heapq as hp
N, M = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
l, r, c = list(map(int, input().split()))
graph[l-1].append((c, r-1))
for i in range(N-1):
graph[i+1].append((0, i))
INF = 10**16
D = [INF for _ in range(N)] # 頂点iへの最短距離がD[i]
D[0] = 0
q = [] # しまっていく優先度付きキュー
hp.heappush(q, (0, 0))
while q:
nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる
if D[np] < nd: # 追加した後の残骸は見ない
continue
for d, p in graph[np]:
if D[p] > D[np] + d: # 隣接するやつの中で今よりも近くなれるなら更新
D[p] = D[np] + d
hp.heappush(q, (D[p], p))
d = D[-1]
if d == INF:
print((-1))
else:
print(d) | 41 | 33 | 807 | 723 | # instead of AVLTree
INF = 10**14
class BIT:
def __init__(self, max):
self.max = max
self.data = [INF] * (self.max + 1)
def update(self, i, x):
while i > 0:
self.data[i] = min(self.data[i], x)
i -= i & -i
def read(self, i):
m = INF
while i <= self.max:
m = min(self.data[i], m)
i += i & -i
return m
import sys
input = sys.stdin.readline
from operator import itemgetter
N, M = list(map(int, input().split()))
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))
bit = BIT(N)
bit.update(1, 0)
for l, r, c in LRC:
m = bit.read(l)
bit.update(r, m + c)
ans = bit.data[N]
if ans == INF:
print((-1))
else:
print(ans)
| import sys
input = sys.stdin.readline
import heapq as hp
N, M = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(M):
l, r, c = list(map(int, input().split()))
graph[l - 1].append((c, r - 1))
for i in range(N - 1):
graph[i + 1].append((0, i))
INF = 10**16
D = [INF for _ in range(N)] # 頂点iへの最短距離がD[i]
D[0] = 0
q = [] # しまっていく優先度付きキュー
hp.heappush(q, (0, 0))
while q:
nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる
if D[np] < nd: # 追加した後の残骸は見ない
continue
for d, p in graph[np]:
if D[p] > D[np] + d: # 隣接するやつの中で今よりも近くなれるなら更新
D[p] = D[np] + d
hp.heappush(q, (D[p], p))
d = D[-1]
if d == INF:
print((-1))
else:
print(d)
| false | 19.512195 | [
"-# instead of AVLTree",
"-INF = 10**14",
"-",
"-",
"-class BIT:",
"- def __init__(self, max):",
"- self.max = max",
"- self.data = [INF] * (self.max + 1)",
"-",
"- def update(self, i, x):",
"- while i > 0:",
"- self.data[i] = min(self.data[i], x)",
"- i -= i & -i",
"-",
"- def read(self, i):",
"- m = INF",
"- while i <= self.max:",
"- m = min(self.data[i], m)",
"- i += i & -i",
"- return m",
"-",
"-",
"-from operator import itemgetter",
"+import heapq as hp",
"-LRC = [list(map(int, input().split())) for _ in range(M)]",
"-LRC.sort(key=itemgetter(0))",
"-bit = BIT(N)",
"-bit.update(1, 0)",
"-for l, r, c in LRC:",
"- m = bit.read(l)",
"- bit.update(r, m + c)",
"-ans = bit.data[N]",
"-if ans == INF:",
"+graph = [[] for _ in range(N)]",
"+for _ in range(M):",
"+ l, r, c = list(map(int, input().split()))",
"+ graph[l - 1].append((c, r - 1))",
"+for i in range(N - 1):",
"+ graph[i + 1].append((0, i))",
"+INF = 10**16",
"+D = [INF for _ in range(N)] # 頂点iへの最短距離がD[i]",
"+D[0] = 0",
"+q = [] # しまっていく優先度付きキュー",
"+hp.heappush(q, (0, 0))",
"+while q:",
"+ nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる",
"+ if D[np] < nd: # 追加した後の残骸は見ない",
"+ continue",
"+ for d, p in graph[np]:",
"+ if D[p] > D[np] + d: # 隣接するやつの中で今よりも近くなれるなら更新",
"+ D[p] = D[np] + d",
"+ hp.heappush(q, (D[p], p))",
"+d = D[-1]",
"+if d == INF:",
"- print(ans)",
"+ print(d)"
] | false | 0.053417 | 0.052573 | 1.016061 | [
"s755994766",
"s782784558"
] |
u796942881 | p03495 | python | s685350583 | s406646120 | 103 | 93 | 35,980 | 35,996 | Accepted | Accepted | 9.71 | from collections import Counter
from sys import stdin
input = stdin.readline
N, K = list(map(int, input().split()))
An = Counter(input().split())
def main():
# 要素数(v) 昇順
# 先頭 から インデックス len(An) - K - 1 まで
# 要素数(v) 合計
print((sum(sorted(An.values())[:len(An) - K])))
return
main()
| from collections import Counter
N, K = list(map(int, input().split()))
An = Counter(input().split())
def main():
# 要素数(v) 昇順
# 先頭 から インデックス len(An) - K - 1 まで
# 要素数(v) 合計
print((sum(sorted(An.values())[:len(An) - K])))
return
main()
| 21 | 17 | 319 | 268 | from collections import Counter
from sys import stdin
input = stdin.readline
N, K = list(map(int, input().split()))
An = Counter(input().split())
def main():
# 要素数(v) 昇順
# 先頭 から インデックス len(An) - K - 1 まで
# 要素数(v) 合計
print((sum(sorted(An.values())[: len(An) - K])))
return
main()
| from collections import Counter
N, K = list(map(int, input().split()))
An = Counter(input().split())
def main():
# 要素数(v) 昇順
# 先頭 から インデックス len(An) - K - 1 まで
# 要素数(v) 合計
print((sum(sorted(An.values())[: len(An) - K])))
return
main()
| false | 19.047619 | [
"-from sys import stdin",
"-input = stdin.readline"
] | false | 0.046217 | 0.046115 | 1.002229 | [
"s685350583",
"s406646120"
] |
u606989659 | p02408 | python | s677574269 | s660624744 | 30 | 20 | 7,540 | 7,740 | Accepted | Accepted | 33.33 | N = int(eval(input()))
cards = []
for i in range(N):
s,r = input().split()
cards.append((s,int(r)))
for s,r in [(s,r) for s in 'SHCD' for r in range(1,14) if (s,r) not in cards]:
print((s, r)) | marks = ["S","H","C","D"]
all_cards = []
for i in marks:
for j in range(1,14):
all_cards.append(str(i) + " " + str(j))
n = int(eval(input()))
p_cards = []
for x in range(n):
p_cards.append(str(eval(input())))
for y in p_cards:
all_cards.remove(y)
for z in all_cards:
print(z) | 7 | 17 | 202 | 307 | N = int(eval(input()))
cards = []
for i in range(N):
s, r = input().split()
cards.append((s, int(r)))
for s, r in [(s, r) for s in "SHCD" for r in range(1, 14) if (s, r) not in cards]:
print((s, r))
| marks = ["S", "H", "C", "D"]
all_cards = []
for i in marks:
for j in range(1, 14):
all_cards.append(str(i) + " " + str(j))
n = int(eval(input()))
p_cards = []
for x in range(n):
p_cards.append(str(eval(input())))
for y in p_cards:
all_cards.remove(y)
for z in all_cards:
print(z)
| false | 58.823529 | [
"-N = int(eval(input()))",
"-cards = []",
"-for i in range(N):",
"- s, r = input().split()",
"- cards.append((s, int(r)))",
"-for s, r in [(s, r) for s in \"SHCD\" for r in range(1, 14) if (s, r) not in cards]:",
"- print((s, r))",
"+marks = [\"S\", \"H\", \"C\", \"D\"]",
"+all_cards = []",
"+for i in marks:",
"+ for j in range(1, 14):",
"+ all_cards.append(str(i) + \" \" + str(j))",
"+n = int(eval(input()))",
"+p_cards = []",
"+for x in range(n):",
"+ p_cards.append(str(eval(input())))",
"+for y in p_cards:",
"+ all_cards.remove(y)",
"+for z in all_cards:",
"+ print(z)"
] | false | 0.040721 | 0.041954 | 0.970594 | [
"s677574269",
"s660624744"
] |
u840579553 | p02726 | python | s610114428 | s963555064 | 499 | 265 | 48,220 | 46,428 | Accepted | Accepted | 46.89 | from collections import defaultdict, deque
N, X, Y = list(map(int, input().split()))
G = defaultdict(list)
for i in range(1, N):
G[i].append(i+1)
G[i+1].append(i)
#print(G)
G[X].append(Y)
G[Y].append(X)
#print(G)
d = [0] * N
for i in range(1, N+1):
q = deque()
q.append(i)
visit = [-1]*N
visit[i-1] = 0
while q:
p = q.popleft()
for next_p in G[p]:
if visit[next_p-1] == -1:
visit[next_p-1] = visit[p-1] + 1
q.append(next_p)
for l in range(N):
d[visit[l]] += 1
for k in range(1, N):
print((d[k]//2))
| N, X, Y = list(map(int, input().split()))
d = [0] * N
for i in range(0, N-1):
for j in range(i+1, N):
k = min(j-i, abs(X-1-i) + 1 + abs(Y-1-j))
d[k] += 1
for i in range(1, N):
print((d[i]))
| 32 | 10 | 632 | 217 | from collections import defaultdict, deque
N, X, Y = list(map(int, input().split()))
G = defaultdict(list)
for i in range(1, N):
G[i].append(i + 1)
G[i + 1].append(i)
# print(G)
G[X].append(Y)
G[Y].append(X)
# print(G)
d = [0] * N
for i in range(1, N + 1):
q = deque()
q.append(i)
visit = [-1] * N
visit[i - 1] = 0
while q:
p = q.popleft()
for next_p in G[p]:
if visit[next_p - 1] == -1:
visit[next_p - 1] = visit[p - 1] + 1
q.append(next_p)
for l in range(N):
d[visit[l]] += 1
for k in range(1, N):
print((d[k] // 2))
| N, X, Y = list(map(int, input().split()))
d = [0] * N
for i in range(0, N - 1):
for j in range(i + 1, N):
k = min(j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j))
d[k] += 1
for i in range(1, N):
print((d[i]))
| false | 68.75 | [
"-from collections import defaultdict, deque",
"-",
"-G = defaultdict(list)",
"+d = [0] * N",
"+for i in range(0, N - 1):",
"+ for j in range(i + 1, N):",
"+ k = min(j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j))",
"+ d[k] += 1",
"- G[i].append(i + 1)",
"- G[i + 1].append(i)",
"-# print(G)",
"-G[X].append(Y)",
"-G[Y].append(X)",
"-# print(G)",
"-d = [0] * N",
"-for i in range(1, N + 1):",
"- q = deque()",
"- q.append(i)",
"- visit = [-1] * N",
"- visit[i - 1] = 0",
"- while q:",
"- p = q.popleft()",
"- for next_p in G[p]:",
"- if visit[next_p - 1] == -1:",
"- visit[next_p - 1] = visit[p - 1] + 1",
"- q.append(next_p)",
"- for l in range(N):",
"- d[visit[l]] += 1",
"-for k in range(1, N):",
"- print((d[k] // 2))",
"+ print((d[i]))"
] | false | 0.068878 | 0.040836 | 1.686696 | [
"s610114428",
"s963555064"
] |
u692746605 | p03330 | python | s963532470 | s500906019 | 685 | 539 | 5,492 | 7,284 | Accepted | Accepted | 21.31 | N,C=list(map(int,input().split()))
D=[[int(x) for x in input().split()] for y in range(C)]
c=[[int(x)-1 for x in input().split()] for y in range(N)]
d=[[0 for x in range(C)] for y in range(3)]
for i in range(N):
for j in range(N):
d[(i+j)%3][c[i][j]] += 1
a=10**9
for c0 in range(C):
for c1 in range(C):
for c2 in range(C):
if c0==c1 or c1==c2 or c0==c2:
continue
s=0
for c in range(C):
s += d[0][c]*D[c][c0]+d[1][c]*D[c][c1]+d[2][c]*D[c][c2]
a=min(a,s)
print(a)
| N,C=list(map(int,input().split()))
D=[[int(x) for x in input().split()] for y in range(C)]
c=[[int(x)-1 for x in input().split()] for y in range(N)]
d=[[0 for x in range(C)] for y in range(3)]
for i in range(N):
for j in range(N):
d[(i+j)%3][c[i][j]]+=1
a=10**9
for c0 in range(C):
for c1 in range(C):
for c2 in range(C):
if c0!=c1 and c1!=c2 and c0!=c2:
a=min(a,sum([d[0][c]*D[c][c0]+d[1][c]*D[c][c1]+d[2][c]*D[c][c2] for c in range(C)]))
print(a)
| 20 | 16 | 530 | 486 | N, C = list(map(int, input().split()))
D = [[int(x) for x in input().split()] for y in range(C)]
c = [[int(x) - 1 for x in input().split()] for y in range(N)]
d = [[0 for x in range(C)] for y in range(3)]
for i in range(N):
for j in range(N):
d[(i + j) % 3][c[i][j]] += 1
a = 10**9
for c0 in range(C):
for c1 in range(C):
for c2 in range(C):
if c0 == c1 or c1 == c2 or c0 == c2:
continue
s = 0
for c in range(C):
s += d[0][c] * D[c][c0] + d[1][c] * D[c][c1] + d[2][c] * D[c][c2]
a = min(a, s)
print(a)
| N, C = list(map(int, input().split()))
D = [[int(x) for x in input().split()] for y in range(C)]
c = [[int(x) - 1 for x in input().split()] for y in range(N)]
d = [[0 for x in range(C)] for y in range(3)]
for i in range(N):
for j in range(N):
d[(i + j) % 3][c[i][j]] += 1
a = 10**9
for c0 in range(C):
for c1 in range(C):
for c2 in range(C):
if c0 != c1 and c1 != c2 and c0 != c2:
a = min(
a,
sum(
[
d[0][c] * D[c][c0] + d[1][c] * D[c][c1] + d[2][c] * D[c][c2]
for c in range(C)
]
),
)
print(a)
| false | 20 | [
"- if c0 == c1 or c1 == c2 or c0 == c2:",
"- continue",
"- s = 0",
"- for c in range(C):",
"- s += d[0][c] * D[c][c0] + d[1][c] * D[c][c1] + d[2][c] * D[c][c2]",
"- a = min(a, s)",
"+ if c0 != c1 and c1 != c2 and c0 != c2:",
"+ a = min(",
"+ a,",
"+ sum(",
"+ [",
"+ d[0][c] * D[c][c0] + d[1][c] * D[c][c1] + d[2][c] * D[c][c2]",
"+ for c in range(C)",
"+ ]",
"+ ),",
"+ )"
] | false | 0.035653 | 0.035704 | 0.998568 | [
"s963532470",
"s500906019"
] |
u633068244 | p00488 | python | s254873679 | s688908617 | 20 | 10 | 4,192 | 4,192 | Accepted | Accepted | 50 | print(min([eval(input()) for i in [1,1,1]])+min([eval(input()) for i in [1,1]]) -50) | a=[eval(input()) for i in [1]*5]
print(min(a[:3])+min(a[3:])-50) | 1 | 2 | 71 | 58 | print(
min([eval(input()) for i in [1, 1, 1]]) + min([eval(input()) for i in [1, 1]]) - 50
)
| a = [eval(input()) for i in [1] * 5]
print(min(a[:3]) + min(a[3:]) - 50)
| false | 50 | [
"-print(",
"- min([eval(input()) for i in [1, 1, 1]]) + min([eval(input()) for i in [1, 1]]) - 50",
"-)",
"+a = [eval(input()) for i in [1] * 5]",
"+print(min(a[:3]) + min(a[3:]) - 50)"
] | false | 0.045313 | 0.046233 | 0.98009 | [
"s254873679",
"s688908617"
] |
u114641312 | p02756 | python | s996038520 | s455290239 | 1,300 | 411 | 17,064 | 21,204 | Accepted | Accepted | 68.38 | s = eval(input())
q = int(eval(input()))
query_list = []
for _ in range(q):
query_list += [eval(input())]
def query1(s):
s = s[::-1]
return s
def query2_1(letters,s):
s = letters[4] + s
return s
def query2_2(letters,s):
s = s + letters[4]
return s
true_position = True
left = ""
right = ""
for i in range(q):
if len(query_list[i])==1:
true_position = not true_position
# print(s)
else:
if query_list[i][2]=="1":
if true_position:
left = query_list[i][4] + left
else:
right = right + query_list[i][4]
elif query_list[i][2]=="2":
if true_position:
right = right + query_list[i][4]
else:
left = query_list[i][4] + left
if true_position:
ans = left + s + right
else:
ans = right[::-1]+s[::-1]+left[::-1]
print(ans) | from collections import deque
s = eval(input())
q = int(eval(input()))
query_list = []
for _ in range(q):
query_list += [eval(input())]
deq = deque(s)
true_position = True
for i in range(q):
if len(query_list[i])==1:
true_position = not true_position
# print(s)
else:
if query_list[i][2]=="1":
if true_position:
deq.appendleft(query_list[i][4])
else:
deq.append(query_list[i][4])
elif query_list[i][2]=="2":
if true_position:
deq.append(query_list[i][4])
else:
deq.appendleft(query_list[i][4])
if true_position:
ans = "".join(deq)
else:
deq.reverse()
ans = "".join(deq)
print(ans) | 46 | 35 | 935 | 770 | s = eval(input())
q = int(eval(input()))
query_list = []
for _ in range(q):
query_list += [eval(input())]
def query1(s):
s = s[::-1]
return s
def query2_1(letters, s):
s = letters[4] + s
return s
def query2_2(letters, s):
s = s + letters[4]
return s
true_position = True
left = ""
right = ""
for i in range(q):
if len(query_list[i]) == 1:
true_position = not true_position
# print(s)
else:
if query_list[i][2] == "1":
if true_position:
left = query_list[i][4] + left
else:
right = right + query_list[i][4]
elif query_list[i][2] == "2":
if true_position:
right = right + query_list[i][4]
else:
left = query_list[i][4] + left
if true_position:
ans = left + s + right
else:
ans = right[::-1] + s[::-1] + left[::-1]
print(ans)
| from collections import deque
s = eval(input())
q = int(eval(input()))
query_list = []
for _ in range(q):
query_list += [eval(input())]
deq = deque(s)
true_position = True
for i in range(q):
if len(query_list[i]) == 1:
true_position = not true_position
# print(s)
else:
if query_list[i][2] == "1":
if true_position:
deq.appendleft(query_list[i][4])
else:
deq.append(query_list[i][4])
elif query_list[i][2] == "2":
if true_position:
deq.append(query_list[i][4])
else:
deq.appendleft(query_list[i][4])
if true_position:
ans = "".join(deq)
else:
deq.reverse()
ans = "".join(deq)
print(ans)
| false | 23.913043 | [
"+from collections import deque",
"+",
"-",
"-",
"-def query1(s):",
"- s = s[::-1]",
"- return s",
"-",
"-",
"-def query2_1(letters, s):",
"- s = letters[4] + s",
"- return s",
"-",
"-",
"-def query2_2(letters, s):",
"- s = s + letters[4]",
"- return s",
"-",
"-",
"+deq = deque(s)",
"-left = \"\"",
"-right = \"\"",
"- left = query_list[i][4] + left",
"+ deq.appendleft(query_list[i][4])",
"- right = right + query_list[i][4]",
"+ deq.append(query_list[i][4])",
"- right = right + query_list[i][4]",
"+ deq.append(query_list[i][4])",
"- left = query_list[i][4] + left",
"+ deq.appendleft(query_list[i][4])",
"- ans = left + s + right",
"+ ans = \"\".join(deq)",
"- ans = right[::-1] + s[::-1] + left[::-1]",
"+ deq.reverse()",
"+ ans = \"\".join(deq)"
] | false | 0.035177 | 0.041028 | 0.85739 | [
"s996038520",
"s455290239"
] |
u936985471 | p03651 | python | s832821041 | s929667167 | 94 | 62 | 14,224 | 19,764 | Accepted | Accepted | 34.04 | N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
diffs=[]
for i in range(len(A)):
if A[i]>=K:
diffs.append(A[i]-K)
def gcd(a,b):
if a>b:
a,b=b,a
while a%b>0:
a,b=b,a%b
return b
g=A[0]
for i in range(1,len(A)):
g=gcd(g,A[i])
for dif in diffs:
if dif%g==0:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE") | import sys
readline = sys.stdin.readline
n,k = list(map(int, readline().split()))
a = list(map(int,readline().split()))
import math
from functools import reduce
g = reduce(math.gcd, a)
if k <= max(a) and k % g == 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE") | 25 | 15 | 385 | 275 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
diffs = []
for i in range(len(A)):
if A[i] >= K:
diffs.append(A[i] - K)
def gcd(a, b):
if a > b:
a, b = b, a
while a % b > 0:
a, b = b, a % b
return b
g = A[0]
for i in range(1, len(A)):
g = gcd(g, A[i])
for dif in diffs:
if dif % g == 0:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
| import sys
readline = sys.stdin.readline
n, k = list(map(int, readline().split()))
a = list(map(int, readline().split()))
import math
from functools import reduce
g = reduce(math.gcd, a)
if k <= max(a) and k % g == 0:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
| false | 40 | [
"-N, K = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-diffs = []",
"-for i in range(len(A)):",
"- if A[i] >= K:",
"- diffs.append(A[i] - K)",
"+import sys",
"+readline = sys.stdin.readline",
"+n, k = list(map(int, readline().split()))",
"+a = list(map(int, readline().split()))",
"+import math",
"+from functools import reduce",
"-def gcd(a, b):",
"- if a > b:",
"- a, b = b, a",
"- while a % b > 0:",
"- a, b = b, a % b",
"- return b",
"-",
"-",
"-g = A[0]",
"-for i in range(1, len(A)):",
"- g = gcd(g, A[i])",
"-for dif in diffs:",
"- if dif % g == 0:",
"- print(\"POSSIBLE\")",
"- break",
"+g = reduce(math.gcd, a)",
"+if k <= max(a) and k % g == 0:",
"+ print(\"POSSIBLE\")"
] | false | 0.036005 | 0.037374 | 0.963389 | [
"s832821041",
"s929667167"
] |
u279605379 | p02297 | python | s836979471 | s455782788 | 30 | 20 | 7,720 | 7,728 | Accepted | Accepted | 33.33 | x=list(range(int(eval(input()))))
P=[]
for _ in reversed(x):P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print((_*0.5)) | x=list(range(int(eval(input()))-1,-1,-1))
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print((_*0.5)) | 6 | 6 | 164 | 162 | x = list(range(int(eval(input()))))
P = []
for _ in reversed(x):
P += [[int(i) for i in input().split()]]
P += [P[0]]
for j in x:
_ += P[j + 1][1] * P[j][0] - P[j][1] * P[j + 1][0]
print((_ * 0.5))
| x = list(range(int(eval(input())) - 1, -1, -1))
P = []
for _ in x:
P += [[int(i) for i in input().split()]]
P += [P[0]]
for j in x:
_ += P[j + 1][1] * P[j][0] - P[j][1] * P[j + 1][0]
print((_ * 0.5))
| false | 0 | [
"-x = list(range(int(eval(input()))))",
"+x = list(range(int(eval(input())) - 1, -1, -1))",
"-for _ in reversed(x):",
"+for _ in x:"
] | false | 0.089836 | 0.043161 | 2.081416 | [
"s836979471",
"s455782788"
] |
u119148115 | p03391 | python | s008827256 | s533241295 | 257 | 90 | 75,924 | 74,948 | Accepted | Accepted | 64.98 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
ans = 0
A,B = [],[]
for i in range(N):
a,b = MI()
A.append(a)
B.append(b)
if A == B:
print((0))
exit()
m = sum(B)
for i in range(N):
if A[i] > B[i]:
m = min(m,B[i])
print((sum(B)-m))
| import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
ans = 0
A,B = [],[]
for i in range(N):
a,b = MI()
A.append(a)
B.append(b)
if A == B:
print((0))
exit()
s = sum(B)
m = s
for i in range(N):
if A[i] > B[i]:
m = min(m,B[i])
print((s-m))
| 29 | 23 | 729 | 372 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
ans = 0
A, B = [], []
for i in range(N):
a, b = MI()
A.append(a)
B.append(b)
if A == B:
print((0))
exit()
m = sum(B)
for i in range(N):
if A[i] > B[i]:
m = min(m, B[i])
print((sum(B) - m))
| import sys
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N = I()
ans = 0
A, B = [], []
for i in range(N):
a, b = MI()
A.append(a)
B.append(b)
if A == B:
print((0))
exit()
s = sum(B)
m = s
for i in range(N):
if A[i] > B[i]:
m = min(m, B[i])
print((s - m))
| false | 20.689655 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"-def LI():",
"- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"-",
"-",
"-def LI2():",
"- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"-",
"-",
"-def S():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"-def LS():",
"- return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"-",
"-",
"-def LS2():",
"- return list(sys.stdin.readline().rstrip()) # 空白なし",
"-m = sum(B)",
"+s = sum(B)",
"+m = s",
"-print((sum(B) - m))",
"+print((s - m))"
] | false | 0.039464 | 0.0375 | 1.052395 | [
"s008827256",
"s533241295"
] |
u785989355 | p03326 | python | s561692446 | s872851063 | 36 | 28 | 3,428 | 3,188 | Accepted | Accepted | 22.22 | N,M=list(map(int,input().split()))
X = [[] for i in range(8)]
for i in range(N):
x,y,z=list(map(int,input().split()))
for i in range(8):
X[i].append(int(2*((i%2)-1/2))*x + int(2*(((i//2)%2)-1/2))*y + int(2*(((i//4)%2)-1/2))*z)
ans=0
for i in range(8):
X[i].sort()
X[i]=X[i][::-1]
ans=max(sum(X[i][:M]),ans)
print(ans) | N,M = list(map(int,input().split()))
X = []
for i in range(N):
x,y,z = list(map(int,input().split()))
X.append([x,y,z])
max_score = 0
for i in range(8):
a = i%2
j = i//2
b = j%2
k = j//2
c = k%2
a,b,c = 2*a-1,2*b-1,2*c-1
Z = []
for j in range(N):
Z.append(a*X[j][0]+b*X[j][1]+c*X[j][2])
Z.sort(reverse=True)
max_score = max(sum(Z[:M]),max_score)
print(max_score) | 13 | 23 | 362 | 444 | N, M = list(map(int, input().split()))
X = [[] for i in range(8)]
for i in range(N):
x, y, z = list(map(int, input().split()))
for i in range(8):
X[i].append(
int(2 * ((i % 2) - 1 / 2)) * x
+ int(2 * (((i // 2) % 2) - 1 / 2)) * y
+ int(2 * (((i // 4) % 2) - 1 / 2)) * z
)
ans = 0
for i in range(8):
X[i].sort()
X[i] = X[i][::-1]
ans = max(sum(X[i][:M]), ans)
print(ans)
| N, M = list(map(int, input().split()))
X = []
for i in range(N):
x, y, z = list(map(int, input().split()))
X.append([x, y, z])
max_score = 0
for i in range(8):
a = i % 2
j = i // 2
b = j % 2
k = j // 2
c = k % 2
a, b, c = 2 * a - 1, 2 * b - 1, 2 * c - 1
Z = []
for j in range(N):
Z.append(a * X[j][0] + b * X[j][1] + c * X[j][2])
Z.sort(reverse=True)
max_score = max(sum(Z[:M]), max_score)
print(max_score)
| false | 43.478261 | [
"-X = [[] for i in range(8)]",
"+X = []",
"- for i in range(8):",
"- X[i].append(",
"- int(2 * ((i % 2) - 1 / 2)) * x",
"- + int(2 * (((i // 2) % 2) - 1 / 2)) * y",
"- + int(2 * (((i // 4) % 2) - 1 / 2)) * z",
"- )",
"-ans = 0",
"+ X.append([x, y, z])",
"+max_score = 0",
"- X[i].sort()",
"- X[i] = X[i][::-1]",
"- ans = max(sum(X[i][:M]), ans)",
"-print(ans)",
"+ a = i % 2",
"+ j = i // 2",
"+ b = j % 2",
"+ k = j // 2",
"+ c = k % 2",
"+ a, b, c = 2 * a - 1, 2 * b - 1, 2 * c - 1",
"+ Z = []",
"+ for j in range(N):",
"+ Z.append(a * X[j][0] + b * X[j][1] + c * X[j][2])",
"+ Z.sort(reverse=True)",
"+ max_score = max(sum(Z[:M]), max_score)",
"+print(max_score)"
] | false | 0.042702 | 0.0344 | 1.241334 | [
"s561692446",
"s872851063"
] |
u680851063 | p02911 | python | s485896923 | s557147165 | 272 | 246 | 8,632 | 10,472 | Accepted | Accepted | 9.56 | n, k, q = list(map(int, input().split()))
l = [0] * n
katen = []
my_append = katen.append # appendを(間接的に)直接呼び出す
for i in range(q):
my_append(int(eval(input())))
for j in katen: # pop、insertを使わない、使うとTLE!
l[j-1] += 1
for y in range(n):
if l[y] > q-k:
print('Yes')
else:
print('No') | n, k, q = list(map(int,input().split()))
l = [int(eval(input())) for _ in range(q)]
score = [k-q] * n
for i in l:
score[i-1] += 1
for j in score:
if j > 0:
print('Yes')
else:
print('No') | 16 | 12 | 318 | 215 | n, k, q = list(map(int, input().split()))
l = [0] * n
katen = []
my_append = katen.append # appendを(間接的に)直接呼び出す
for i in range(q):
my_append(int(eval(input())))
for j in katen: # pop、insertを使わない、使うとTLE!
l[j - 1] += 1
for y in range(n):
if l[y] > q - k:
print("Yes")
else:
print("No")
| n, k, q = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(q)]
score = [k - q] * n
for i in l:
score[i - 1] += 1
for j in score:
if j > 0:
print("Yes")
else:
print("No")
| false | 25 | [
"-l = [0] * n",
"-katen = []",
"-my_append = katen.append # appendを(間接的に)直接呼び出す",
"-for i in range(q):",
"- my_append(int(eval(input())))",
"-for j in katen: # pop、insertを使わない、使うとTLE!",
"- l[j - 1] += 1",
"-for y in range(n):",
"- if l[y] > q - k:",
"+l = [int(eval(input())) for _ in range(q)]",
"+score = [k - q] * n",
"+for i in l:",
"+ score[i - 1] += 1",
"+for j in score:",
"+ if j > 0:"
] | false | 0.050203 | 0.048413 | 1.036976 | [
"s485896923",
"s557147165"
] |
u077291787 | p02558 | python | s547266691 | s604443187 | 265 | 211 | 144,916 | 84,140 | Accepted | Accepted | 20.38 | class UnionFind:
__slots__ = ["_data_size", "_roots"]
def __init__(self, N):
self._data_size = N
self._roots = [-1] * N
def __getitem__(self, x: int) -> int:
while self._roots[x] >= 0:
x = self._roots[x]
return x
def unite(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
elif self._roots[y] < self._roots[x]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def is_connected(self, x, y):
return self[x] == self[y]
import sys
read = sys.stdin.buffer.read
N, Q, *TUV = list(map(int, read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
| class UnionFind:
__slots__ = ["_data_size", "_roots"]
def __init__(self, N):
self._data_size = N
self._roots = [-1] * N
def __getitem__(self, x: int) -> int:
while self._roots[x] >= 0:
x = self._roots[x]
return x
def unite(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
elif self._roots[y] < self._roots[x]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def is_connected(self, x, y):
return self[x] == self[y]
import sys
readline = sys.stdin.buffer.readline
N, Q = list(map(int, readline().split()))
tree = UnionFind(N)
res = []
for _ in range(Q):
t, u, v = list(map(int, readline().split()))
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
| 39 | 40 | 897 | 928 | class UnionFind:
__slots__ = ["_data_size", "_roots"]
def __init__(self, N):
self._data_size = N
self._roots = [-1] * N
def __getitem__(self, x: int) -> int:
while self._roots[x] >= 0:
x = self._roots[x]
return x
def unite(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
elif self._roots[y] < self._roots[x]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def is_connected(self, x, y):
return self[x] == self[y]
import sys
read = sys.stdin.buffer.read
N, Q, *TUV = list(map(int, read().split()))
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
| class UnionFind:
__slots__ = ["_data_size", "_roots"]
def __init__(self, N):
self._data_size = N
self._roots = [-1] * N
def __getitem__(self, x: int) -> int:
while self._roots[x] >= 0:
x = self._roots[x]
return x
def unite(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
elif self._roots[y] < self._roots[x]:
x, y = y, x
self._roots[x] += self._roots[y]
self._roots[y] = x
def is_connected(self, x, y):
return self[x] == self[y]
import sys
readline = sys.stdin.buffer.readline
N, Q = list(map(int, readline().split()))
tree = UnionFind(N)
res = []
for _ in range(Q):
t, u, v = list(map(int, readline().split()))
if t:
res.append(int(tree.is_connected(u, v)))
else:
tree.unite(u, v)
print(("\n".join(map(str, res))))
| false | 2.5 | [
"-read = sys.stdin.buffer.read",
"-N, Q, *TUV = list(map(int, read().split()))",
"+readline = sys.stdin.buffer.readline",
"+N, Q = list(map(int, readline().split()))",
"-for t, u, v in zip(*[iter(TUV)] * 3):",
"+for _ in range(Q):",
"+ t, u, v = list(map(int, readline().split()))"
] | false | 0.044462 | 0.039912 | 1.113999 | [
"s547266691",
"s604443187"
] |
u889914341 | p03108 | python | s728933543 | s835657851 | 453 | 408 | 26,048 | 26,056 | Accepted | Accepted | 9.93 | import sys
readline = sys.stdin.readline
N, M = map(int, input().split())
ab = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1] * size
self.number = [1] * size
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in ab[1:][::-1]:
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
print(*ans[::-1], sep="\n")
| import sys
readline = sys.stdin.readline
N, M = map(int, input().split())
ab = [tuple(map(int, readline().split())) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1] * (size + 1)
self.number = [1] * (size + 1)
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in ab[1:][::-1]:
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
print(*ans[::-1], sep="\n")
| 36 | 36 | 1,082 | 1,077 | import sys
readline = sys.stdin.readline
N, M = map(int, input().split())
ab = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1] * size
self.number = [1] * size
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in ab[1:][::-1]:
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
print(*ans[::-1], sep="\n")
| import sys
readline = sys.stdin.readline
N, M = map(int, input().split())
ab = [tuple(map(int, readline().split())) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1] * (size + 1)
self.number = [1] * (size + 1)
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in ab[1:][::-1]:
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
print(*ans[::-1], sep="\n")
| false | 0 | [
"-ab = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]",
"+ab = [tuple(map(int, readline().split())) for _ in range(M)]",
"- self.rank = [-1] * size",
"- self.number = [1] * size",
"+ self.rank = [-1] * (size + 1)",
"+ self.number = [1] * (size + 1)"
] | false | 0.046389 | 0.045366 | 1.02253 | [
"s728933543",
"s835657851"
] |
u759934006 | p00163 | python | s808298493 | s434991891 | 20 | 10 | 4,288 | 4,268 | Accepted | Accepted | 50 | # Highway Toll
PRICE_LIST = (
(0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 300, 500, 600, 700, 1350, 1650),
(0, 6, 0, 350, 450, 600, 1150, 1500),
(0, 13, 7, 0, 250, 400, 1000, 1350),
(0, 18, 12, 5, 0, 250, 850, 1300),
(0, 23, 17, 10, 5, 0, 600, 1150),
(0, 43, 37, 30, 25, 20, 0, 500),
(0, 58, 52, 45, 40, 35, 15, 0),
)
while True:
i = int(input())
if i == 0:
break
it = int(input().strip().replace(' ', ''))
o = int(input())
ot = int(input().strip().replace(' ', ''))
half = False
if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
half = True
p = PRICE_LIST[i][o]
if half:
p /= 2
if p % 50:
p = (p / 50) * 50 + 50
print(p) | # Highway Toll
PRICE_LIST = (
(0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 300, 500, 600, 700, 1350, 1650),
(0, 6, 0, 350, 450, 600, 1150, 1500),
(0, 13, 7, 0, 250, 400, 1000, 1350),
(0, 18, 12, 5, 0, 250, 850, 1300),
(0, 23, 17, 10, 5, 0, 600, 1150),
(0, 43, 37, 30, 25, 20, 0, 500),
(0, 58, 52, 45, 40, 35, 15, 0),
)
while True:
i = int(input())
if i == 0:
break
it = int(input().strip().replace(' ', ''))
o = int(input())
ot = int(input().strip().replace(' ', ''))
half = False
price = PRICE_LIST[i][o]
if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
half = True
price /= 2
if price % 50:
price = price - (price % 50) + 50
print(price) | 33 | 31 | 803 | 814 | # Highway Toll
PRICE_LIST = (
(0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 300, 500, 600, 700, 1350, 1650),
(0, 6, 0, 350, 450, 600, 1150, 1500),
(0, 13, 7, 0, 250, 400, 1000, 1350),
(0, 18, 12, 5, 0, 250, 850, 1300),
(0, 23, 17, 10, 5, 0, 600, 1150),
(0, 43, 37, 30, 25, 20, 0, 500),
(0, 58, 52, 45, 40, 35, 15, 0),
)
while True:
i = int(input())
if i == 0:
break
it = int(input().strip().replace(" ", ""))
o = int(input())
ot = int(input().strip().replace(" ", ""))
half = False
if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
half = True
p = PRICE_LIST[i][o]
if half:
p /= 2
if p % 50:
p = (p / 50) * 50 + 50
print(p)
| # Highway Toll
PRICE_LIST = (
(0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 300, 500, 600, 700, 1350, 1650),
(0, 6, 0, 350, 450, 600, 1150, 1500),
(0, 13, 7, 0, 250, 400, 1000, 1350),
(0, 18, 12, 5, 0, 250, 850, 1300),
(0, 23, 17, 10, 5, 0, 600, 1150),
(0, 43, 37, 30, 25, 20, 0, 500),
(0, 58, 52, 45, 40, 35, 15, 0),
)
while True:
i = int(input())
if i == 0:
break
it = int(input().strip().replace(" ", ""))
o = int(input())
ot = int(input().strip().replace(" ", ""))
half = False
price = PRICE_LIST[i][o]
if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
half = True
price /= 2
if price % 50:
price = price - (price % 50) + 50
print(price)
| false | 6.060606 | [
"+ price = PRICE_LIST[i][o]",
"- p = PRICE_LIST[i][o]",
"- if half:",
"- p /= 2",
"- if p % 50:",
"- p = (p / 50) * 50 + 50",
"- print(p)",
"+ price /= 2",
"+ if price % 50:",
"+ price = price - (price % 50) + 50",
"+ print(price)"
] | false | 0.041276 | 0.041525 | 0.993996 | [
"s808298493",
"s434991891"
] |
u186838327 | p03993 | python | s130256247 | s958750323 | 223 | 205 | 57,132 | 52,912 | Accepted | Accepted | 8.07 | n = int(eval(input()))
A = list(map(int, input().split()))
A = [a-1 for a in A]
ans = 0
for i in range(n):
if A[A[i]] == i:
ans += 1
print((ans//2))
| n = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for i in range(n):
if A[A[i]-1] == i+1:
ans += 1
print((ans//2))
| 8 | 7 | 160 | 142 | n = int(eval(input()))
A = list(map(int, input().split()))
A = [a - 1 for a in A]
ans = 0
for i in range(n):
if A[A[i]] == i:
ans += 1
print((ans // 2))
| n = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for i in range(n):
if A[A[i] - 1] == i + 1:
ans += 1
print((ans // 2))
| false | 12.5 | [
"-A = [a - 1 for a in A]",
"- if A[A[i]] == i:",
"+ if A[A[i] - 1] == i + 1:"
] | false | 0.079365 | 0.07102 | 1.117516 | [
"s130256247",
"s958750323"
] |
u401487574 | p02559 | python | s548563174 | s934241282 | 1,490 | 598 | 133,132 | 128,172 | Accepted | Accepted | 59.87 | ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
class FenwickTree():
def __init__(self,n):
self.n = n
self.tree = [0]*(n+1)
def add(self,idx,a):#値の更新
idx+=1
while idx<=self.n:
self.tree[idx] +=a
idx += idx &-idx
def _sum(self,r):
ret=0
r+=1
while r>0:
ret+=self.tree[r]
r-=r&-r
return ret
def sum(self,l,r):
return self._sum(r)-self._sum(l-1)
n,q = ma()
A = lma()
ft = FenwickTree(n)
for i in range(n):
ft.add(i,A[i])
for i in range(q):
t,u,v = ma()
if t==0:
ft.add(u,v)
else:
print(ft.sum(u,v-1))
| ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
input=sys.stdin.readline
class FenwickTree():
def __init__(self,n):
self.n = n
self.tree = [0]*(n+1)
def add(self,idx,a):#値の更新
idx+=1
while idx<=self.n:
self.tree[idx] +=a
idx += idx &-idx
def _sum(self,r):
ret=0
r+=1
while r>0:
ret+=self.tree[r]
r-=r&-r
return ret
def sum(self,l,r):
return self._sum(r)-self._sum(l-1)
n,q = ma()
A = lma()
ft = FenwickTree(n)
for i in range(n):
ft.add(i,A[i])
for i in range(q):
t,u,v = ma()
if t==0:
ft.add(u,v)
else:
print(ft.sum(u,v-1))
| 42 | 43 | 963 | 999 | ma = lambda: map(int, input().split())
lma = lambda: list(map(int, input().split()))
tma = lambda: tuple(map(int, input().split()))
ni = lambda: int(input())
yn = lambda fl: print("Yes") if fl else print("No")
ips = lambda: input().split()
import collections
import math
import itertools
import heapq as hq
class FenwickTree:
def __init__(self, n):
self.n = n
self.tree = [0] * (n + 1)
def add(self, idx, a): # 値の更新
idx += 1
while idx <= self.n:
self.tree[idx] += a
idx += idx & -idx
def _sum(self, r):
ret = 0
r += 1
while r > 0:
ret += self.tree[r]
r -= r & -r
return ret
def sum(self, l, r):
return self._sum(r) - self._sum(l - 1)
n, q = ma()
A = lma()
ft = FenwickTree(n)
for i in range(n):
ft.add(i, A[i])
for i in range(q):
t, u, v = ma()
if t == 0:
ft.add(u, v)
else:
print(ft.sum(u, v - 1))
| ma = lambda: map(int, input().split())
lma = lambda: list(map(int, input().split()))
tma = lambda: tuple(map(int, input().split()))
ni = lambda: int(input())
yn = lambda fl: print("Yes") if fl else print("No")
ips = lambda: input().split()
import collections
import math
import itertools
import heapq as hq
import sys
input = sys.stdin.readline
class FenwickTree:
def __init__(self, n):
self.n = n
self.tree = [0] * (n + 1)
def add(self, idx, a): # 値の更新
idx += 1
while idx <= self.n:
self.tree[idx] += a
idx += idx & -idx
def _sum(self, r):
ret = 0
r += 1
while r > 0:
ret += self.tree[r]
r -= r & -r
return ret
def sum(self, l, r):
return self._sum(r) - self._sum(l - 1)
n, q = ma()
A = lma()
ft = FenwickTree(n)
for i in range(n):
ft.add(i, A[i])
for i in range(q):
t, u, v = ma()
if t == 0:
ft.add(u, v)
else:
print(ft.sum(u, v - 1))
| false | 2.325581 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.00825 | 0.036314 | 0.227186 | [
"s548563174",
"s934241282"
] |
u347640436 | p03295 | python | s109461501 | s318801580 | 229 | 205 | 23,300 | 28,700 | Accepted | Accepted | 10.48 | from sys import stdin
readline = stdin.readline
N, M = list(map(int, readline().split()))
ab = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, readline().split()))
ab[a].append(b)
dp = [0] * (N + 1)
for i in range(1, N + 1):
dp[i] = max(dp[i], dp[i - 1])
for j in ab[i]:
dp[j] = max(dp[j], dp[i] + 1)
print((dp[N]))
| from sys import stdin
readline = stdin.readline
N, M = list(map(int, readline().split()))
ab = [list(map(int, readline().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
result = 0
t = -1
for a, b in ab:
a, b = a - 1, b - 1
if a <= t < b:
continue
result += 1
t = b - 1
print(result)
| 17 | 17 | 365 | 329 | from sys import stdin
readline = stdin.readline
N, M = list(map(int, readline().split()))
ab = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, readline().split()))
ab[a].append(b)
dp = [0] * (N + 1)
for i in range(1, N + 1):
dp[i] = max(dp[i], dp[i - 1])
for j in ab[i]:
dp[j] = max(dp[j], dp[i] + 1)
print((dp[N]))
| from sys import stdin
readline = stdin.readline
N, M = list(map(int, readline().split()))
ab = [list(map(int, readline().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
result = 0
t = -1
for a, b in ab:
a, b = a - 1, b - 1
if a <= t < b:
continue
result += 1
t = b - 1
print(result)
| false | 0 | [
"-ab = [[] for _ in range(N + 1)]",
"-for _ in range(M):",
"- a, b = list(map(int, readline().split()))",
"- ab[a].append(b)",
"-dp = [0] * (N + 1)",
"-for i in range(1, N + 1):",
"- dp[i] = max(dp[i], dp[i - 1])",
"- for j in ab[i]:",
"- dp[j] = max(dp[j], dp[i] + 1)",
"-print((dp[N]))",
"+ab = [list(map(int, readline().split())) for _ in range(M)]",
"+ab.sort(key=lambda x: x[1])",
"+result = 0",
"+t = -1",
"+for a, b in ab:",
"+ a, b = a - 1, b - 1",
"+ if a <= t < b:",
"+ continue",
"+ result += 1",
"+ t = b - 1",
"+print(result)"
] | false | 0.04323 | 0.045643 | 0.947117 | [
"s109461501",
"s318801580"
] |
u603958124 | p02796 | python | s090499111 | s963016257 | 306 | 280 | 25,460 | 27,440 | Accepted | Accepted | 8.5 | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
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())
n = INT()
x = [[0]*2 for i in range(n)]
for i in range(n):
x[i][0], x[i][1] = MAP()
x.sort()
tmp = -inf
ans = n
for i in range(n):
if tmp > x[i][0] - x[i][1]:
ans -= 1
tmp = min(tmp, x[i][0] + x[i][1])
else:
tmp = x[i][0] + x[i][1]
print(ans) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
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())
n = INT()
ls = []
for i in range(n):
x, l = MAP()
ls.append([x-l, x+l])
ls = sorted(ls, key=itemgetter(1))
ans = n
for i in range(1, n):
if ls[i][0] < ls[i-1][1]:
ls[i][1] = ls[i-1][1]
ans -= 1
print(ans) | 32 | 30 | 1,007 | 959 | from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
comb,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
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())
n = INT()
x = [[0] * 2 for i in range(n)]
for i in range(n):
x[i][0], x[i][1] = MAP()
x.sort()
tmp = -inf
ans = n
for i in range(n):
if tmp > x[i][0] - x[i][1]:
ans -= 1
tmp = min(tmp, x[i][0] + x[i][1])
else:
tmp = x[i][0] + x[i][1]
print(ans)
| from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
comb,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
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())
n = INT()
ls = []
for i in range(n):
x, l = MAP()
ls.append([x - l, x + l])
ls = sorted(ls, key=itemgetter(1))
ans = n
for i in range(1, n):
if ls[i][0] < ls[i - 1][1]:
ls[i][1] = ls[i - 1][1]
ans -= 1
print(ans)
| false | 6.25 | [
"-x = [[0] * 2 for i in range(n)]",
"+ls = []",
"- x[i][0], x[i][1] = MAP()",
"-x.sort()",
"-tmp = -inf",
"+ x, l = MAP()",
"+ ls.append([x - l, x + l])",
"+ls = sorted(ls, key=itemgetter(1))",
"-for i in range(n):",
"- if tmp > x[i][0] - x[i][1]:",
"+for i in range(1, n):",
"+ if ls[i][0] < ls[i - 1][1]:",
"+ ls[i][1] = ls[i - 1][1]",
"- tmp = min(tmp, x[i][0] + x[i][1])",
"- else:",
"- tmp = x[i][0] + x[i][1]"
] | false | 0.034015 | 0.034383 | 0.989299 | [
"s090499111",
"s963016257"
] |
u408260374 | p00489 | python | s473607080 | s889339967 | 80 | 70 | 7,500 | 7,496 | Accepted | Accepted | 12.5 | n=int(eval(input()));score=[list([int(x)-1 for x in input().split()]) for _ in range(int(n*(n-1)/2))];points= [0]*n
for a,b,c,d in score:
if c>d:points[a]+=3
elif c<d:points[b]+=3
else:points[a]+=1;points[b]+=1
rank=sorted(points,reverse=True)
for p in points:print((rank.index(p)+1)) | n=int(eval(input()));s=[list(map(int,input().split())) for _ in range(int(n*(n-1)/2))];p=[0]*n
for a,b,c,d in s:
if c>d:p[a-1]+=3
elif c<d:p[b-1]+=3
else:p[a-1]+=1;p[b-1]+=1
r=sorted(p,reverse=True)
for q in p:print((r.index(q)+1)) | 7 | 7 | 300 | 244 | n = int(eval(input()))
score = [
list([int(x) - 1 for x in input().split()]) for _ in range(int(n * (n - 1) / 2))
]
points = [0] * n
for a, b, c, d in score:
if c > d:
points[a] += 3
elif c < d:
points[b] += 3
else:
points[a] += 1
points[b] += 1
rank = sorted(points, reverse=True)
for p in points:
print((rank.index(p) + 1))
| n = int(eval(input()))
s = [list(map(int, input().split())) for _ in range(int(n * (n - 1) / 2))]
p = [0] * n
for a, b, c, d in s:
if c > d:
p[a - 1] += 3
elif c < d:
p[b - 1] += 3
else:
p[a - 1] += 1
p[b - 1] += 1
r = sorted(p, reverse=True)
for q in p:
print((r.index(q) + 1))
| false | 0 | [
"-score = [",
"- list([int(x) - 1 for x in input().split()]) for _ in range(int(n * (n - 1) / 2))",
"-]",
"-points = [0] * n",
"-for a, b, c, d in score:",
"+s = [list(map(int, input().split())) for _ in range(int(n * (n - 1) / 2))]",
"+p = [0] * n",
"+for a, b, c, d in s:",
"- points[a] += 3",
"+ p[a - 1] += 3",
"- points[b] += 3",
"+ p[b - 1] += 3",
"- points[a] += 1",
"- points[b] += 1",
"-rank = sorted(points, reverse=True)",
"-for p in points:",
"- print((rank.index(p) + 1))",
"+ p[a - 1] += 1",
"+ p[b - 1] += 1",
"+r = sorted(p, reverse=True)",
"+for q in p:",
"+ print((r.index(q) + 1))"
] | false | 0.089046 | 0.055722 | 1.598048 | [
"s473607080",
"s889339967"
] |
u463655976 | p03559 | python | s918272806 | s208319882 | 1,273 | 575 | 121,904 | 43,892 | Accepted | Accepted | 54.83 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
L = []
L.extend(((x, 3) for x in A))
L.extend(((x, 2) for x in B))
L.extend(((x, 1) for x in C))
L = sorted(L, reverse=True)
cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
if i == 1:
cnt_C += 1
elif i == 2:
cnt_B += cnt_C
elif i == 3:
cnt_A += cnt_B
print(cnt_A)
| N = int(eval(input()))
L = []
L.extend(((int(x), 3) for x in input().split()))
L.extend(((int(x), 2) for x in input().split()))
L.extend(((int(x), 1) for x in input().split()))
L = sorted(L, reverse=True)
cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
if i == 1:
cnt_C += 1
elif i == 2:
cnt_B += cnt_C
elif i == 3:
cnt_A += cnt_B
print(cnt_A)
| 25 | 21 | 436 | 398 | N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
L = []
L.extend(((x, 3) for x in A))
L.extend(((x, 2) for x in B))
L.extend(((x, 1) for x in C))
L = sorted(L, reverse=True)
cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
if i == 1:
cnt_C += 1
elif i == 2:
cnt_B += cnt_C
elif i == 3:
cnt_A += cnt_B
print(cnt_A)
| N = int(eval(input()))
L = []
L.extend(((int(x), 3) for x in input().split()))
L.extend(((int(x), 2) for x in input().split()))
L.extend(((int(x), 1) for x in input().split()))
L = sorted(L, reverse=True)
cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
if i == 1:
cnt_C += 1
elif i == 2:
cnt_B += cnt_C
elif i == 3:
cnt_A += cnt_B
print(cnt_A)
| false | 16 | [
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"-C = list(map(int, input().split()))",
"-L.extend(((x, 3) for x in A))",
"-L.extend(((x, 2) for x in B))",
"-L.extend(((x, 1) for x in C))",
"+L.extend(((int(x), 3) for x in input().split()))",
"+L.extend(((int(x), 2) for x in input().split()))",
"+L.extend(((int(x), 1) for x in input().split()))"
] | false | 0.036122 | 0.035886 | 1.006564 | [
"s918272806",
"s208319882"
] |
u761320129 | p04000 | python | s456042328 | s592728667 | 2,176 | 1,154 | 180,344 | 177,868 | Accepted | Accepted | 46.97 | from collections import Counter
H,W,N = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
blacks = Counter()
for y,x in src:
for i in range(-1,2):
if not 0 <= y+i < H: continue
for j in range(-1,2):
if not 0 <= x+j < W: continue
blacks[(x+j, y+i)] += 1
ans = [0] * 10
for (x,y),v in blacks.items():
if x<2 or y<2: continue
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])
print(*ans,sep='\n')
| import sys
input = sys.stdin.readline
H,W,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]
from collections import defaultdict
dic = defaultdict(lambda: 0)
for y,x in AB:
for dx in range(-1,2):
for dy in range(-1,2):
nx,ny = x+dx,y+dy
if not 1 <= nx <= W: continue
if not 1 <= ny <= H: continue
dic[(nx,ny)] += 1
ans = [0] * 10
for (x,y),c in dic.items():
if x==1 or x==W or y==1 or y==H: continue
ans[c] += 1
s = sum(ans)
ans[0] = (W-2)*(H-2)-s
print(*ans, sep='\n')
| 18 | 22 | 495 | 595 | from collections import Counter
H, W, N = map(int, input().split())
src = [tuple(map(int, input().split())) for i in range(N)]
blacks = Counter()
for y, x in src:
for i in range(-1, 2):
if not 0 <= y + i < H:
continue
for j in range(-1, 2):
if not 0 <= x + j < W:
continue
blacks[(x + j, y + i)] += 1
ans = [0] * 10
for (x, y), v in blacks.items():
if x < 2 or y < 2:
continue
ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
print(*ans, sep="\n")
| import sys
input = sys.stdin.readline
H, W, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N)]
from collections import defaultdict
dic = defaultdict(lambda: 0)
for y, x in AB:
for dx in range(-1, 2):
for dy in range(-1, 2):
nx, ny = x + dx, y + dy
if not 1 <= nx <= W:
continue
if not 1 <= ny <= H:
continue
dic[(nx, ny)] += 1
ans = [0] * 10
for (x, y), c in dic.items():
if x == 1 or x == W or y == 1 or y == H:
continue
ans[c] += 1
s = sum(ans)
ans[0] = (W - 2) * (H - 2) - s
print(*ans, sep="\n")
| false | 18.181818 | [
"-from collections import Counter",
"+import sys",
"+input = sys.stdin.readline",
"-src = [tuple(map(int, input().split())) for i in range(N)]",
"-blacks = Counter()",
"-for y, x in src:",
"- for i in range(-1, 2):",
"- if not 0 <= y + i < H:",
"- continue",
"- for j in range(-1, 2):",
"- if not 0 <= x + j < W:",
"+AB = [tuple(map(int, input().split())) for i in range(N)]",
"+from collections import defaultdict",
"+",
"+dic = defaultdict(lambda: 0)",
"+for y, x in AB:",
"+ for dx in range(-1, 2):",
"+ for dy in range(-1, 2):",
"+ nx, ny = x + dx, y + dy",
"+ if not 1 <= nx <= W:",
"- blacks[(x + j, y + i)] += 1",
"+ if not 1 <= ny <= H:",
"+ continue",
"+ dic[(nx, ny)] += 1",
"-for (x, y), v in blacks.items():",
"- if x < 2 or y < 2:",
"+for (x, y), c in dic.items():",
"+ if x == 1 or x == W or y == 1 or y == H:",
"- ans[v] += 1",
"-ans[0] = (H - 2) * (W - 2) - sum(ans[1:])",
"+ ans[c] += 1",
"+s = sum(ans)",
"+ans[0] = (W - 2) * (H - 2) - s"
] | false | 0.065766 | 0.036221 | 1.815692 | [
"s456042328",
"s592728667"
] |
u150984829 | p02397 | python | s801789020 | s453198653 | 40 | 30 | 5,980 | 5,884 | Accepted | Accepted | 25 | a=[]
while 1:
n=input()
if n=='0 0':break
a.append(n)
for s in a:
x,y=map(int,s.split())
print(y,x) if x>y else print(s)
| a=[]
while 1:
n=input()
if n=='0 0':break
a.append(n)
for s in a:
x,y=map(int,s.split())
print(f'{y} {x}') if x>y else print(s)
| 8 | 8 | 132 | 139 | a = []
while 1:
n = input()
if n == "0 0":
break
a.append(n)
for s in a:
x, y = map(int, s.split())
print(y, x) if x > y else print(s)
| a = []
while 1:
n = input()
if n == "0 0":
break
a.append(n)
for s in a:
x, y = map(int, s.split())
print(f"{y} {x}") if x > y else print(s)
| false | 0 | [
"- print(y, x) if x > y else print(s)",
"+ print(f\"{y} {x}\") if x > y else print(s)"
] | false | 0.048583 | 0.036847 | 1.318512 | [
"s801789020",
"s453198653"
] |
u644907318 | p03030 | python | s629221903 | s982724871 | 149 | 62 | 61,948 | 62,788 | Accepted | Accepted | 58.39 | N = int(eval(input()))
A = [list(input().split()) for _ in range(N)]
A = sorted([(A[i][0],int(A[i][1]),i+1) for i in range(N)],key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for i in range(N):
print((A[i][2])) | N = int(eval(input()))
A = [list(input().split()) for _ in range(N)]
A = [(A[i][0],int(A[i][1]),i+1) for i in range(N)]
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for i in range(N):
print((A[i][2])) | 6 | 7 | 227 | 234 | N = int(eval(input()))
A = [list(input().split()) for _ in range(N)]
A = sorted(
[(A[i][0], int(A[i][1]), i + 1) for i in range(N)], key=lambda x: x[1], reverse=True
)
A = sorted(A, key=lambda x: x[0])
for i in range(N):
print((A[i][2]))
| N = int(eval(input()))
A = [list(input().split()) for _ in range(N)]
A = [(A[i][0], int(A[i][1]), i + 1) for i in range(N)]
A = sorted(A, key=lambda x: x[1], reverse=True)
A = sorted(A, key=lambda x: x[0])
for i in range(N):
print((A[i][2]))
| false | 14.285714 | [
"-A = sorted(",
"- [(A[i][0], int(A[i][1]), i + 1) for i in range(N)], key=lambda x: x[1], reverse=True",
"-)",
"+A = [(A[i][0], int(A[i][1]), i + 1) for i in range(N)]",
"+A = sorted(A, key=lambda x: x[1], reverse=True)"
] | false | 0.181802 | 0.037277 | 4.87699 | [
"s629221903",
"s982724871"
] |
u853728588 | p02547 | python | s621415963 | s856530168 | 32 | 28 | 9,120 | 9,044 | Accepted | Accepted | 12.5 | n = int(eval(input()))
a = []
for _ in range(n):
aa, b = list(map(int,input().split()))
if aa == b:
a.append("1")
else:
a.append("0")
if "111" in "".join(a):
print("Yes")
else:
print("No") | n = int(eval(input()))
count = 0
for _ in range(n):
d1, d2 = list(map(int, input().split()))
if d1 == d2:
count += 1
if count >= 3:
print("Yes")
exit()
else:
count = 0
print("No") | 13 | 13 | 207 | 211 | n = int(eval(input()))
a = []
for _ in range(n):
aa, b = list(map(int, input().split()))
if aa == b:
a.append("1")
else:
a.append("0")
if "111" in "".join(a):
print("Yes")
else:
print("No")
| n = int(eval(input()))
count = 0
for _ in range(n):
d1, d2 = list(map(int, input().split()))
if d1 == d2:
count += 1
if count >= 3:
print("Yes")
exit()
else:
count = 0
print("No")
| false | 0 | [
"-a = []",
"+count = 0",
"- aa, b = list(map(int, input().split()))",
"- if aa == b:",
"- a.append(\"1\")",
"+ d1, d2 = list(map(int, input().split()))",
"+ if d1 == d2:",
"+ count += 1",
"+ if count >= 3:",
"+ print(\"Yes\")",
"+ exit()",
"- a.append(\"0\")",
"-if \"111\" in \"\".join(a):",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ count = 0",
"+print(\"No\")"
] | false | 0.040627 | 0.043649 | 0.930771 | [
"s621415963",
"s856530168"
] |
u644907318 | p02714 | python | s910609965 | s496073725 | 947 | 245 | 78,600 | 74,100 | Accepted | Accepted | 74.13 | from bisect import bisect_right
N = int(eval(input()))
S = input().strip()
R = []
G = []
B = []
Ron = [0 for _ in range(len(S))]
Gon = [0 for _ in range(len(S))]
Bon = [0 for _ in range(len(S))]
for i in range(N):
if S[i]=="R":
R.append(i)
Ron[i]=1
elif S[i]=="G":
G.append(i)
Gon[i]=1
else:
B.append(i)
Bon[i]=1
cnt = 0
for i in range(N):
if Ron[i]==1:
#RGB
indr = i
ind0 = bisect_right(G,indr)
for j in range(ind0,len(G)):
indg = G[j]
if len(B)>0:
ind1 = bisect_right(B,indg)
if 2*indg-indr>B[-1] or Bon[2*indg-indr]==0 or Bon[2*indg-indr]==1 and 2*indg-indr<B[ind1]:
cnt += len(B)-ind1
else:
cnt += len(B)-ind1-1
#RBG
ind0 = bisect_right(B,indr)
for j in range(ind0,len(B)):
indb = B[j]
if len(G)>0:
ind1 = bisect_right(G,indb)
if 2*indb-indr>G[-1] or Gon[2*indb-indr]==0 or Gon[2*indb-indr]==1 and 2*indb-indr<G[ind1]:
cnt += len(G)-ind1
else:
cnt += len(G)-ind1-1
elif Gon[i]==1:
#GBR
indg = i
ind0 = bisect_right(B,indg)
for j in range(ind0,len(B)):
indb = B[j]
if len(R)>0:
ind1 = bisect_right(R,indb)
if 2*indb-indg>R[-1] or Ron[2*indb-indg]==0 or Ron[2*indb-indg]==1 and 2*indb-indg<R[ind1]:
cnt += len(R)-ind1
else:
cnt += len(R)-ind1-1
#GRB
ind0 = bisect_right(R,indg)
for j in range(ind0,len(R)):
indr = R[j]
if len(B)>0:
ind1 = bisect_right(B,indr)
if 2*indr-indg>B[-1] or Bon[2*indr-indg]==0 or Bon[2*indr-indg]==1 and 2*indr-indg<B[ind1]:
cnt += len(B)-ind1
else:
cnt += len(B)-ind1-1
elif Bon[i]==1:
#BRG
indb = i
ind0 = bisect_right(R,indb)
for j in range(ind0,len(R)):
indr = R[j]
if len(G)>0:
ind1 = bisect_right(G,indr)
if 2*indr-indb>G[-1] or Gon[2*indr-indb]==0 or Gon[2*indr-indb]==1 and 2*indr-indb<G[ind1]:
cnt += len(G)-ind1
else:
cnt += len(G)-ind1-1
#BGR
ind0 = bisect_right(G,indb)
for j in range(ind0,len(G)):
indg = G[j]
if len(R)>0:
ind1 = bisect_right(R,indg)
if 2*indg-indb>R[-1] or Ron[2*indg-indb]==0 or Ron[2*indg-indb]==1 and 2*indg-indb<R[ind1]:
cnt += len(R)-ind1
else:
cnt += len(R)-ind1-1
print(cnt) | N = int(eval(input()))
S = input().strip()
C = {"R":[],"G":[],"B":[]}
for i in range(N):
C[S[i]].append(i)
C["B"] = set(C["B"])
cnt = 0
for r in C["R"]:
for g in C["G"]:
if r<g:
i = r
j = g
else:
i = g
j = r
cnt += len(C["B"])
if i-(j-i) in C["B"]:
cnt -= 1
if j+(j-i) in C["B"]:
cnt -= 1
if (j+i)%2==0 and (j+i)//2 in C["B"]:
cnt -= 1
print(cnt) | 88 | 23 | 2,934 | 502 | from bisect import bisect_right
N = int(eval(input()))
S = input().strip()
R = []
G = []
B = []
Ron = [0 for _ in range(len(S))]
Gon = [0 for _ in range(len(S))]
Bon = [0 for _ in range(len(S))]
for i in range(N):
if S[i] == "R":
R.append(i)
Ron[i] = 1
elif S[i] == "G":
G.append(i)
Gon[i] = 1
else:
B.append(i)
Bon[i] = 1
cnt = 0
for i in range(N):
if Ron[i] == 1:
# RGB
indr = i
ind0 = bisect_right(G, indr)
for j in range(ind0, len(G)):
indg = G[j]
if len(B) > 0:
ind1 = bisect_right(B, indg)
if (
2 * indg - indr > B[-1]
or Bon[2 * indg - indr] == 0
or Bon[2 * indg - indr] == 1
and 2 * indg - indr < B[ind1]
):
cnt += len(B) - ind1
else:
cnt += len(B) - ind1 - 1
# RBG
ind0 = bisect_right(B, indr)
for j in range(ind0, len(B)):
indb = B[j]
if len(G) > 0:
ind1 = bisect_right(G, indb)
if (
2 * indb - indr > G[-1]
or Gon[2 * indb - indr] == 0
or Gon[2 * indb - indr] == 1
and 2 * indb - indr < G[ind1]
):
cnt += len(G) - ind1
else:
cnt += len(G) - ind1 - 1
elif Gon[i] == 1:
# GBR
indg = i
ind0 = bisect_right(B, indg)
for j in range(ind0, len(B)):
indb = B[j]
if len(R) > 0:
ind1 = bisect_right(R, indb)
if (
2 * indb - indg > R[-1]
or Ron[2 * indb - indg] == 0
or Ron[2 * indb - indg] == 1
and 2 * indb - indg < R[ind1]
):
cnt += len(R) - ind1
else:
cnt += len(R) - ind1 - 1
# GRB
ind0 = bisect_right(R, indg)
for j in range(ind0, len(R)):
indr = R[j]
if len(B) > 0:
ind1 = bisect_right(B, indr)
if (
2 * indr - indg > B[-1]
or Bon[2 * indr - indg] == 0
or Bon[2 * indr - indg] == 1
and 2 * indr - indg < B[ind1]
):
cnt += len(B) - ind1
else:
cnt += len(B) - ind1 - 1
elif Bon[i] == 1:
# BRG
indb = i
ind0 = bisect_right(R, indb)
for j in range(ind0, len(R)):
indr = R[j]
if len(G) > 0:
ind1 = bisect_right(G, indr)
if (
2 * indr - indb > G[-1]
or Gon[2 * indr - indb] == 0
or Gon[2 * indr - indb] == 1
and 2 * indr - indb < G[ind1]
):
cnt += len(G) - ind1
else:
cnt += len(G) - ind1 - 1
# BGR
ind0 = bisect_right(G, indb)
for j in range(ind0, len(G)):
indg = G[j]
if len(R) > 0:
ind1 = bisect_right(R, indg)
if (
2 * indg - indb > R[-1]
or Ron[2 * indg - indb] == 0
or Ron[2 * indg - indb] == 1
and 2 * indg - indb < R[ind1]
):
cnt += len(R) - ind1
else:
cnt += len(R) - ind1 - 1
print(cnt)
| N = int(eval(input()))
S = input().strip()
C = {"R": [], "G": [], "B": []}
for i in range(N):
C[S[i]].append(i)
C["B"] = set(C["B"])
cnt = 0
for r in C["R"]:
for g in C["G"]:
if r < g:
i = r
j = g
else:
i = g
j = r
cnt += len(C["B"])
if i - (j - i) in C["B"]:
cnt -= 1
if j + (j - i) in C["B"]:
cnt -= 1
if (j + i) % 2 == 0 and (j + i) // 2 in C["B"]:
cnt -= 1
print(cnt)
| false | 73.863636 | [
"-from bisect import bisect_right",
"-",
"-R = []",
"-G = []",
"-B = []",
"-Ron = [0 for _ in range(len(S))]",
"-Gon = [0 for _ in range(len(S))]",
"-Bon = [0 for _ in range(len(S))]",
"+C = {\"R\": [], \"G\": [], \"B\": []}",
"- if S[i] == \"R\":",
"- R.append(i)",
"- Ron[i] = 1",
"- elif S[i] == \"G\":",
"- G.append(i)",
"- Gon[i] = 1",
"- else:",
"- B.append(i)",
"- Bon[i] = 1",
"+ C[S[i]].append(i)",
"+C[\"B\"] = set(C[\"B\"])",
"-for i in range(N):",
"- if Ron[i] == 1:",
"- # RGB",
"- indr = i",
"- ind0 = bisect_right(G, indr)",
"- for j in range(ind0, len(G)):",
"- indg = G[j]",
"- if len(B) > 0:",
"- ind1 = bisect_right(B, indg)",
"- if (",
"- 2 * indg - indr > B[-1]",
"- or Bon[2 * indg - indr] == 0",
"- or Bon[2 * indg - indr] == 1",
"- and 2 * indg - indr < B[ind1]",
"- ):",
"- cnt += len(B) - ind1",
"- else:",
"- cnt += len(B) - ind1 - 1",
"- # RBG",
"- ind0 = bisect_right(B, indr)",
"- for j in range(ind0, len(B)):",
"- indb = B[j]",
"- if len(G) > 0:",
"- ind1 = bisect_right(G, indb)",
"- if (",
"- 2 * indb - indr > G[-1]",
"- or Gon[2 * indb - indr] == 0",
"- or Gon[2 * indb - indr] == 1",
"- and 2 * indb - indr < G[ind1]",
"- ):",
"- cnt += len(G) - ind1",
"- else:",
"- cnt += len(G) - ind1 - 1",
"- elif Gon[i] == 1:",
"- # GBR",
"- indg = i",
"- ind0 = bisect_right(B, indg)",
"- for j in range(ind0, len(B)):",
"- indb = B[j]",
"- if len(R) > 0:",
"- ind1 = bisect_right(R, indb)",
"- if (",
"- 2 * indb - indg > R[-1]",
"- or Ron[2 * indb - indg] == 0",
"- or Ron[2 * indb - indg] == 1",
"- and 2 * indb - indg < R[ind1]",
"- ):",
"- cnt += len(R) - ind1",
"- else:",
"- cnt += len(R) - ind1 - 1",
"- # GRB",
"- ind0 = bisect_right(R, indg)",
"- for j in range(ind0, len(R)):",
"- indr = R[j]",
"- if len(B) > 0:",
"- ind1 = bisect_right(B, indr)",
"- if (",
"- 2 * indr - indg > B[-1]",
"- or Bon[2 * indr - indg] == 0",
"- or Bon[2 * indr - indg] == 1",
"- and 2 * indr - indg < B[ind1]",
"- ):",
"- cnt += len(B) - ind1",
"- else:",
"- cnt += len(B) - ind1 - 1",
"- elif Bon[i] == 1:",
"- # BRG",
"- indb = i",
"- ind0 = bisect_right(R, indb)",
"- for j in range(ind0, len(R)):",
"- indr = R[j]",
"- if len(G) > 0:",
"- ind1 = bisect_right(G, indr)",
"- if (",
"- 2 * indr - indb > G[-1]",
"- or Gon[2 * indr - indb] == 0",
"- or Gon[2 * indr - indb] == 1",
"- and 2 * indr - indb < G[ind1]",
"- ):",
"- cnt += len(G) - ind1",
"- else:",
"- cnt += len(G) - ind1 - 1",
"- # BGR",
"- ind0 = bisect_right(G, indb)",
"- for j in range(ind0, len(G)):",
"- indg = G[j]",
"- if len(R) > 0:",
"- ind1 = bisect_right(R, indg)",
"- if (",
"- 2 * indg - indb > R[-1]",
"- or Ron[2 * indg - indb] == 0",
"- or Ron[2 * indg - indb] == 1",
"- and 2 * indg - indb < R[ind1]",
"- ):",
"- cnt += len(R) - ind1",
"- else:",
"- cnt += len(R) - ind1 - 1",
"+for r in C[\"R\"]:",
"+ for g in C[\"G\"]:",
"+ if r < g:",
"+ i = r",
"+ j = g",
"+ else:",
"+ i = g",
"+ j = r",
"+ cnt += len(C[\"B\"])",
"+ if i - (j - i) in C[\"B\"]:",
"+ cnt -= 1",
"+ if j + (j - i) in C[\"B\"]:",
"+ cnt -= 1",
"+ if (j + i) % 2 == 0 and (j + i) // 2 in C[\"B\"]:",
"+ cnt -= 1"
] | false | 0.076029 | 0.038588 | 1.970276 | [
"s910609965",
"s496073725"
] |
u665873062 | p03722 | python | s770499970 | s522368607 | 1,767 | 1,168 | 3,572 | 3,572 | Accepted | Accepted | 33.9 | #Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
#頂点1から頂点Nに移動して、移動スコアを最大にする
#->移動スコアを正負反転させれば最短経路問題
#->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N,M = list(map(int,input().split()))
#辺を登録
Sides = []
for i in range (M):
Side = list(map(int,input().split()))
Sides.append(Side)
#コストを反転
Sides[i][2] = Sides[i][2] * (-1)
#各頂点の最短距離を初期化
Vertexes = [INF]*(N+1)
Vertexes[1] = 0
#負閉路のチェック用
negative = [False] * (N+1)
#ベルマンフォード法による最短距離探索
for count in range(N):
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
cost = Sides[i][2]
if (Vertexes[to_v] > Vertexes[from_v]+cost):
if(count==N-1):
negative[to_v] = True
else:
Vertexes[to_v] = Vertexes[from_v]+cost
#負閉路の確認
for count in range(N-1):
flag = 0
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
if negative[from_v] :
negative[to_v] = True
flag = 1
#if flag ==0:
# break
if negative[N]:
print('inf')
else:
print((-Vertexes[N])) | #Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
#頂点1から頂点Nに移動して、移動スコアを最大にする
#->移動スコアを正負反転させれば最短経路問題
#->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N,M = list(map(int,input().split()))
#辺を登録
Sides = []
for i in range (M):
Side = list(map(int,input().split()))
Sides.append(Side)
#コストを反転
Sides[i][2] = Sides[i][2] * (-1)
#各頂点の最短距離を初期化
Vertexes = [INF]*(N+1)
Vertexes[1] = 0
#負閉路のチェック用
negative = [False] * (N+1)
#ベルマンフォード法による最短距離探索
for count in range(N):
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
cost = Sides[i][2]
if (Vertexes[to_v] > Vertexes[from_v]+cost):
#N回目の更新で更新された場合は負閉路あり
if(count==N-1):
negative[to_v] = True
else:
Vertexes[to_v] = Vertexes[from_v]+cost
#負閉路が終点までにあるか確認
for count in range(N-1):
flag = 0
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
if negative[from_v] and negative[to_v] is False:
negative[to_v] = True
flag = 1
if flag ==0:
break
if negative[N]:
print('inf')
else:
print((-Vertexes[N])) | 51 | 52 | 1,119 | 1,175 | # Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
# 頂点1から頂点Nに移動して、移動スコアを最大にする
# ->移動スコアを正負反転させれば最短経路問題
# ->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N, M = list(map(int, input().split()))
# 辺を登録
Sides = []
for i in range(M):
Side = list(map(int, input().split()))
Sides.append(Side)
# コストを反転
Sides[i][2] = Sides[i][2] * (-1)
# 各頂点の最短距離を初期化
Vertexes = [INF] * (N + 1)
Vertexes[1] = 0
# 負閉路のチェック用
negative = [False] * (N + 1)
# ベルマンフォード法による最短距離探索
for count in range(N):
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
cost = Sides[i][2]
if Vertexes[to_v] > Vertexes[from_v] + cost:
if count == N - 1:
negative[to_v] = True
else:
Vertexes[to_v] = Vertexes[from_v] + cost
# 負閉路の確認
for count in range(N - 1):
flag = 0
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
if negative[from_v]:
negative[to_v] = True
flag = 1
# if flag ==0:
# break
if negative[N]:
print("inf")
else:
print((-Vertexes[N]))
| # Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
# 頂点1から頂点Nに移動して、移動スコアを最大にする
# ->移動スコアを正負反転させれば最短経路問題
# ->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N, M = list(map(int, input().split()))
# 辺を登録
Sides = []
for i in range(M):
Side = list(map(int, input().split()))
Sides.append(Side)
# コストを反転
Sides[i][2] = Sides[i][2] * (-1)
# 各頂点の最短距離を初期化
Vertexes = [INF] * (N + 1)
Vertexes[1] = 0
# 負閉路のチェック用
negative = [False] * (N + 1)
# ベルマンフォード法による最短距離探索
for count in range(N):
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
cost = Sides[i][2]
if Vertexes[to_v] > Vertexes[from_v] + cost:
# N回目の更新で更新された場合は負閉路あり
if count == N - 1:
negative[to_v] = True
else:
Vertexes[to_v] = Vertexes[from_v] + cost
# 負閉路が終点までにあるか確認
for count in range(N - 1):
flag = 0
for i in range(M):
from_v = Sides[i][0]
to_v = Sides[i][1]
if negative[from_v] and negative[to_v] is False:
negative[to_v] = True
flag = 1
if flag == 0:
break
if negative[N]:
print("inf")
else:
print((-Vertexes[N]))
| false | 1.923077 | [
"+ # N回目の更新で更新された場合は負閉路あり",
"-# 負閉路の確認",
"+# 負閉路が終点までにあるか確認",
"- if negative[from_v]:",
"+ if negative[from_v] and negative[to_v] is False:",
"- # if flag ==0:",
"- # break",
"+ if flag == 0:",
"+ break"
] | false | 0.067533 | 0.0653 | 1.034191 | [
"s770499970",
"s522368607"
] |
u341543478 | p03775 | python | s057092216 | s487721091 | 66 | 43 | 3,060 | 3,060 | Accepted | Accepted | 34.85 | def calc_digit(n):
d = 0
while n > 0:
d += 1
n //= 10
return d
n = int(eval(input()))
temp = -1
ans = 12
i = 1
while i * i <= n:
if n % i == 0:
temp = max(calc_digit(i), calc_digit(n // i))
ans = min(temp,ans)
i += 1
print(ans)
| def count_digit(n):
d = 0
while n > 0:
n //= 10
d += 1
return d
n = int(eval(input()))
i = 1
ans = 11
while i * i <= n:
if n % i == 0:
temp = max(count_digit(i), count_digit(n // i))
if ans > temp:
ans = temp
i += 1
print(ans) | 18 | 19 | 289 | 305 | def calc_digit(n):
d = 0
while n > 0:
d += 1
n //= 10
return d
n = int(eval(input()))
temp = -1
ans = 12
i = 1
while i * i <= n:
if n % i == 0:
temp = max(calc_digit(i), calc_digit(n // i))
ans = min(temp, ans)
i += 1
print(ans)
| def count_digit(n):
d = 0
while n > 0:
n //= 10
d += 1
return d
n = int(eval(input()))
i = 1
ans = 11
while i * i <= n:
if n % i == 0:
temp = max(count_digit(i), count_digit(n // i))
if ans > temp:
ans = temp
i += 1
print(ans)
| false | 5.263158 | [
"-def calc_digit(n):",
"+def count_digit(n):",
"+ n //= 10",
"- n //= 10",
"-temp = -1",
"-ans = 12",
"+ans = 11",
"- temp = max(calc_digit(i), calc_digit(n // i))",
"- ans = min(temp, ans)",
"+ temp = max(count_digit(i), count_digit(n // i))",
"+ if ans > temp:",
"+ ans = temp"
] | false | 0.255086 | 0.070709 | 3.60755 | [
"s057092216",
"s487721091"
] |
u893063840 | p03682 | python | s506628264 | s216462617 | 1,533 | 1,339 | 99,440 | 78,780 | Accepted | Accepted | 12.65 | from operator import itemgetter
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
xyi = [[x, y, i] for i, (x, y) in enumerate(xy)]
edge = set()
xyi.sort()
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
c = min(abs(x1 - x2), abs(y1 - y2))
edge.add((i1, i2, c))
xyi.sort(key=itemgetter(1))
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
c = min(abs(x1 - x2), abs(y1 - y2))
edge.add((i1, i2, c))
row, col, cost = list(zip(*edge))
graph = csr_matrix((cost, (row, col)), shape=(n, n))
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)
| from operator import itemgetter
from collections import defaultdict
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
n = int(eval(input()))
xy = [list(map(int, input().split())) + [i] for i in range(n)]
INF = 10 ** 9 + 1
d = defaultdict(lambda: INF)
for key in (itemgetter(0), itemgetter(1)):
xy.sort(key=key)
for (x1, y1, i1), (x2, y2, i2) in zip(xy, xy[1:]):
c = min(abs(x1 - x2), abs(y1 - y2))
d[(i1, i2)] = min(d[(i1, i2)], c)
row = []
col = []
cost = []
for (k1, k2), c in list(d.items()):
row.append(k1)
col.append(k2)
cost.append(c)
graph = csr_matrix((cost, (row, col)), shape=(n, n))
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)
| 26 | 29 | 738 | 782 | from operator import itemgetter
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
xyi = [[x, y, i] for i, (x, y) in enumerate(xy)]
edge = set()
xyi.sort()
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
c = min(abs(x1 - x2), abs(y1 - y2))
edge.add((i1, i2, c))
xyi.sort(key=itemgetter(1))
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
c = min(abs(x1 - x2), abs(y1 - y2))
edge.add((i1, i2, c))
row, col, cost = list(zip(*edge))
graph = csr_matrix((cost, (row, col)), shape=(n, n))
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)
| from operator import itemgetter
from collections import defaultdict
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
n = int(eval(input()))
xy = [list(map(int, input().split())) + [i] for i in range(n)]
INF = 10**9 + 1
d = defaultdict(lambda: INF)
for key in (itemgetter(0), itemgetter(1)):
xy.sort(key=key)
for (x1, y1, i1), (x2, y2, i2) in zip(xy, xy[1:]):
c = min(abs(x1 - x2), abs(y1 - y2))
d[(i1, i2)] = min(d[(i1, i2)], c)
row = []
col = []
cost = []
for (k1, k2), c in list(d.items()):
row.append(k1)
col.append(k2)
cost.append(c)
graph = csr_matrix((cost, (row, col)), shape=(n, n))
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)
| false | 10.344828 | [
"+from collections import defaultdict",
"-xy = [list(map(int, input().split())) for _ in range(n)]",
"-xyi = [[x, y, i] for i, (x, y) in enumerate(xy)]",
"-edge = set()",
"-xyi.sort()",
"-for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):",
"- c = min(abs(x1 - x2), abs(y1 - y2))",
"- edge.add((i1, i2, c))",
"-xyi.sort(key=itemgetter(1))",
"-for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):",
"- c = min(abs(x1 - x2), abs(y1 - y2))",
"- edge.add((i1, i2, c))",
"-row, col, cost = list(zip(*edge))",
"+xy = [list(map(int, input().split())) + [i] for i in range(n)]",
"+INF = 10**9 + 1",
"+d = defaultdict(lambda: INF)",
"+for key in (itemgetter(0), itemgetter(1)):",
"+ xy.sort(key=key)",
"+ for (x1, y1, i1), (x2, y2, i2) in zip(xy, xy[1:]):",
"+ c = min(abs(x1 - x2), abs(y1 - y2))",
"+ d[(i1, i2)] = min(d[(i1, i2)], c)",
"+row = []",
"+col = []",
"+cost = []",
"+for (k1, k2), c in list(d.items()):",
"+ row.append(k1)",
"+ col.append(k2)",
"+ cost.append(c)"
] | false | 0.33783 | 0.30908 | 1.09302 | [
"s506628264",
"s216462617"
] |
u796942881 | p03779 | python | s661680404 | s060471397 | 32 | 27 | 2,940 | 3,060 | Accepted | Accepted | 15.62 | def main():
X = int(eval(input()))
ans = 1
while ans * (ans + 1) * 0.5 < X:
ans += 1
print(ans)
return
main()
| from operator import rshift
def main():
X = int(eval(input()))
ans = 1
while rshift(ans * (ans + 1), 1) < X:
ans += 1
print(ans)
return
main()
| 10 | 13 | 143 | 181 | def main():
X = int(eval(input()))
ans = 1
while ans * (ans + 1) * 0.5 < X:
ans += 1
print(ans)
return
main()
| from operator import rshift
def main():
X = int(eval(input()))
ans = 1
while rshift(ans * (ans + 1), 1) < X:
ans += 1
print(ans)
return
main()
| false | 23.076923 | [
"+from operator import rshift",
"+",
"+",
"- while ans * (ans + 1) * 0.5 < X:",
"+ while rshift(ans * (ans + 1), 1) < X:"
] | false | 0.038013 | 0.035114 | 1.082554 | [
"s661680404",
"s060471397"
] |
u844646164 | p02787 | python | s875462329 | s967576287 | 1,429 | 1,053 | 412,692 | 314,376 | Accepted | Accepted | 26.31 | h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = 0
for a, b in ab:
max_a = max(max_a, a)
# i番目まで見たときに、モンスターの体力をj減らした時の、トキの消耗した魔力の最小値
dp = [[float('inf')]*(h+max_a+1) for _ in range(n+1)]
for i in range(n+1):
dp[i][0] = 0
for i in range(n):
a, b = ab[i]
for j in range(h+max_a+1):
if j-a >= 0:
dp[i+1][j] = min(dp[i][j], dp[i+1][j-a]+b)
else:
dp[i+1][j] = dp[i][j]
ans = float('inf')
for i in range(h, h+max_a+1):
ans = min(ans, dp[n][i])
print(ans)
| import sys
input = sys.stdin.readline
H, N = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(N)]
mx = max([a for a,b in ab])
dp = [[float('inf')]*(H+1+mx) for _ in range(N+1)]
# i番目までの魔法を使った時にモンスターの体力をj減らすするのに必要な魔力の最少値
dp[0][0] = 0
for i in range(N):
a, b = ab[i]
for j in range(H+1+mx):
if j - a >= 0:
dp[i+1][j] = min(dp[i+1][j-a]+b, dp[i][j])
else:
dp[i+1][j] = dp[i][j]
ans = float('inf')
for i in range(H, H+mx+1):
ans = min(ans, dp[N][i])
print(ans)
| 23 | 22 | 554 | 537 | h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = 0
for a, b in ab:
max_a = max(max_a, a)
# i番目まで見たときに、モンスターの体力をj減らした時の、トキの消耗した魔力の最小値
dp = [[float("inf")] * (h + max_a + 1) for _ in range(n + 1)]
for i in range(n + 1):
dp[i][0] = 0
for i in range(n):
a, b = ab[i]
for j in range(h + max_a + 1):
if j - a >= 0:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b)
else:
dp[i + 1][j] = dp[i][j]
ans = float("inf")
for i in range(h, h + max_a + 1):
ans = min(ans, dp[n][i])
print(ans)
| import sys
input = sys.stdin.readline
H, N = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(N)]
mx = max([a for a, b in ab])
dp = [[float("inf")] * (H + 1 + mx) for _ in range(N + 1)]
# i番目までの魔法を使った時にモンスターの体力をj減らすするのに必要な魔力の最少値
dp[0][0] = 0
for i in range(N):
a, b = ab[i]
for j in range(H + 1 + mx):
if j - a >= 0:
dp[i + 1][j] = min(dp[i + 1][j - a] + b, dp[i][j])
else:
dp[i + 1][j] = dp[i][j]
ans = float("inf")
for i in range(H, H + mx + 1):
ans = min(ans, dp[N][i])
print(ans)
| false | 4.347826 | [
"-h, n = list(map(int, input().split()))",
"-ab = [list(map(int, input().split())) for _ in range(n)]",
"-max_a = 0",
"-for a, b in ab:",
"- max_a = max(max_a, a)",
"-# i番目まで見たときに、モンスターの体力をj減らした時の、トキの消耗した魔力の最小値",
"-dp = [[float(\"inf\")] * (h + max_a + 1) for _ in range(n + 1)]",
"-for i in range(n + 1):",
"- dp[i][0] = 0",
"-for i in range(n):",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+H, N = list(map(int, input().split()))",
"+ab = [list(map(int, input().split())) for _ in range(N)]",
"+mx = max([a for a, b in ab])",
"+dp = [[float(\"inf\")] * (H + 1 + mx) for _ in range(N + 1)]",
"+# i番目までの魔法を使った時にモンスターの体力をj減らすするのに必要な魔力の最少値",
"+dp[0][0] = 0",
"+for i in range(N):",
"- for j in range(h + max_a + 1):",
"+ for j in range(H + 1 + mx):",
"- dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b)",
"+ dp[i + 1][j] = min(dp[i + 1][j - a] + b, dp[i][j])",
"-for i in range(h, h + max_a + 1):",
"- ans = min(ans, dp[n][i])",
"+for i in range(H, H + mx + 1):",
"+ ans = min(ans, dp[N][i])"
] | false | 0.385107 | 0.157469 | 2.445601 | [
"s875462329",
"s967576287"
] |
u325282913 | p03779 | python | s325550767 | s892592713 | 31 | 25 | 2,940 | 2,940 | Accepted | Accepted | 19.35 | X = int(eval(input()))
ans = 0
for i in range(1,X+1):
if ans + i <= X:
ans += i
else:
print(i)
exit()
if ans == X:
print(i)
exit() | X = int(eval(input()))
ans = 0
for i in range(1,X+1):
ans += i
if X <= ans:
print(i)
exit() | 11 | 7 | 186 | 115 | X = int(eval(input()))
ans = 0
for i in range(1, X + 1):
if ans + i <= X:
ans += i
else:
print(i)
exit()
if ans == X:
print(i)
exit()
| X = int(eval(input()))
ans = 0
for i in range(1, X + 1):
ans += i
if X <= ans:
print(i)
exit()
| false | 36.363636 | [
"- if ans + i <= X:",
"- ans += i",
"- else:",
"+ ans += i",
"+ if X <= ans:",
"- if ans == X:",
"- print(i)",
"- exit()"
] | false | 0.032586 | 0.040802 | 0.798641 | [
"s325550767",
"s892592713"
] |
u518042385 | p03557 | python | s560306667 | s101586828 | 412 | 329 | 24,000 | 23,328 | Accepted | Accepted | 20.15 | import bisect
n=int(eval(input()))
la=sorted(map(int,input().split()))
lb=sorted(map(int,input().split()))
lc=sorted(map(int,input().split()))
countb=[]
count1=0
for i in range(n):
index=bisect.bisect_left(la,lb[i])
countb.append(index)
countb2=[]
sum=0
for i in range(n):
sum+=countb[i]
countb2.append(sum)
ans=0
for i in range(n):
index=bisect.bisect_left(lb,lc[i])
if index==0:
pass
else:
ans+=countb2[index-1]
print(ans) | import bisect
n=int(eval(input()))
la=sorted(map(int,input().split()))
lb=sorted(map(int,input().split()))
lc=sorted(map(int,input().split()))
ans=0
for i in range(n):
index1=bisect.bisect_left(la,lb[i])
index2=bisect.bisect_right(lc,lb[i])
ans+=index1*(n-index2)
print(ans) | 23 | 11 | 462 | 284 | import bisect
n = int(eval(input()))
la = sorted(map(int, input().split()))
lb = sorted(map(int, input().split()))
lc = sorted(map(int, input().split()))
countb = []
count1 = 0
for i in range(n):
index = bisect.bisect_left(la, lb[i])
countb.append(index)
countb2 = []
sum = 0
for i in range(n):
sum += countb[i]
countb2.append(sum)
ans = 0
for i in range(n):
index = bisect.bisect_left(lb, lc[i])
if index == 0:
pass
else:
ans += countb2[index - 1]
print(ans)
| import bisect
n = int(eval(input()))
la = sorted(map(int, input().split()))
lb = sorted(map(int, input().split()))
lc = sorted(map(int, input().split()))
ans = 0
for i in range(n):
index1 = bisect.bisect_left(la, lb[i])
index2 = bisect.bisect_right(lc, lb[i])
ans += index1 * (n - index2)
print(ans)
| false | 52.173913 | [
"-countb = []",
"-count1 = 0",
"-for i in range(n):",
"- index = bisect.bisect_left(la, lb[i])",
"- countb.append(index)",
"-countb2 = []",
"-sum = 0",
"-for i in range(n):",
"- sum += countb[i]",
"- countb2.append(sum)",
"- index = bisect.bisect_left(lb, lc[i])",
"- if index == 0:",
"- pass",
"- else:",
"- ans += countb2[index - 1]",
"+ index1 = bisect.bisect_left(la, lb[i])",
"+ index2 = bisect.bisect_right(lc, lb[i])",
"+ ans += index1 * (n - index2)"
] | false | 0.042001 | 0.085749 | 0.489817 | [
"s560306667",
"s101586828"
] |
u078042885 | p00003 | python | s458541255 | s040962236 | 40 | 30 | 7,648 | 7,428 | Accepted | Accepted | 25 | for _ in range(int(eval(input()))):
a=sorted(map(int,input().split()))
print(('YES' if a[0]**2+a[1]**2==a[2]**2 else'NO')) | for _ in[0]*int(eval(input())):a,b,c=sorted(map(int,input().split()));print((['NO','YES'][a*a+b*b==c*c])) | 3 | 1 | 124 | 97 | for _ in range(int(eval(input()))):
a = sorted(map(int, input().split()))
print(("YES" if a[0] ** 2 + a[1] ** 2 == a[2] ** 2 else "NO"))
| for _ in [0] * int(eval(input())):
a, b, c = sorted(map(int, input().split()))
print((["NO", "YES"][a * a + b * b == c * c]))
| false | 66.666667 | [
"-for _ in range(int(eval(input()))):",
"- a = sorted(map(int, input().split()))",
"- print((\"YES\" if a[0] ** 2 + a[1] ** 2 == a[2] ** 2 else \"NO\"))",
"+for _ in [0] * int(eval(input())):",
"+ a, b, c = sorted(map(int, input().split()))",
"+ print(([\"NO\", \"YES\"][a * a + b * b == c * c]))"
] | false | 0.036325 | 0.036926 | 0.983735 | [
"s458541255",
"s040962236"
] |
u169200126 | p02658 | python | s156439007 | s098192277 | 81 | 61 | 21,600 | 21,588 | Accepted | Accepted | 24.69 |
n = int(eval(input()))
An = [int(x) for x in input().split()]
An.sort(reverse=True)
if 0 in An:
print((0))
exit()
j = 10 ** 18
ans = 1
for i in range(n):
if ans > j:
print((-1))
quit()
ans *= An[i]
if ans > j :
print((-1))
else :
print(ans)
|
n = int(eval(input()))
An = [int(x) for x in input().split()]
for i in range(n):
if An[i] == 0:
print((0))
quit()
j = 10 ** 18
ans = 1
for i in range(n):
if ans > j:
print((-1))
quit()
ans *= An[i]
if ans > j :
print((-1))
else :
print(ans)
| 23 | 23 | 301 | 313 | n = int(eval(input()))
An = [int(x) for x in input().split()]
An.sort(reverse=True)
if 0 in An:
print((0))
exit()
j = 10**18
ans = 1
for i in range(n):
if ans > j:
print((-1))
quit()
ans *= An[i]
if ans > j:
print((-1))
else:
print(ans)
| n = int(eval(input()))
An = [int(x) for x in input().split()]
for i in range(n):
if An[i] == 0:
print((0))
quit()
j = 10**18
ans = 1
for i in range(n):
if ans > j:
print((-1))
quit()
ans *= An[i]
if ans > j:
print((-1))
else:
print(ans)
| false | 0 | [
"-An.sort(reverse=True)",
"-if 0 in An:",
"- print((0))",
"- exit()",
"+for i in range(n):",
"+ if An[i] == 0:",
"+ print((0))",
"+ quit()"
] | false | 0.083874 | 0.007678 | 10.923378 | [
"s156439007",
"s098192277"
] |
u867826040 | p02987 | python | s924304693 | s646170233 | 24 | 21 | 3,444 | 3,316 | Accepted | Accepted | 12.5 | from collections import Counter as co
s=co(eval(input()))
if all([i==2 for i in list(s.values())]) and len(list(s.keys()))==2:
print("Yes")
else:
print("No") | from collections import Counter
s = eval(input())
c = Counter(s)
if len(c)==2 and all(vi==2 for vi in list(c.values())):
print("Yes")
else:
print("No") | 6 | 7 | 148 | 153 | from collections import Counter as co
s = co(eval(input()))
if all([i == 2 for i in list(s.values())]) and len(list(s.keys())) == 2:
print("Yes")
else:
print("No")
| from collections import Counter
s = eval(input())
c = Counter(s)
if len(c) == 2 and all(vi == 2 for vi in list(c.values())):
print("Yes")
else:
print("No")
| false | 14.285714 | [
"-from collections import Counter as co",
"+from collections import Counter",
"-s = co(eval(input()))",
"-if all([i == 2 for i in list(s.values())]) and len(list(s.keys())) == 2:",
"+s = eval(input())",
"+c = Counter(s)",
"+if len(c) == 2 and all(vi == 2 for vi in list(c.values())):"
] | false | 0.045483 | 0.041441 | 1.097555 | [
"s924304693",
"s646170233"
] |
u744920373 | p03546 | python | s956865179 | s320018443 | 369 | 227 | 46,044 | 43,100 | Accepted | Accepted | 38.48 | import sys
sys.setrecursionlimit(10**9)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
H, W = mi()
C = li2(10)
a = li2(H)
memo = [C[i][1] for i in range(10)]
flag = -1
'''
def dfs(column, m):
if column == 1:
global flag
flag = max(m, flag)
for i in range(10):
if i!=column and C[column][i] < m:
dfs(i, m-C[column][i])
#return
for i in range(10):
if i != 1:
dfs(i, C[i][1])
if flag != -1:
memo[i] = C[i][1]-flag
flag = -1
'''
flag = 10**9
def dfs(col, m):
if col == 1:
global flag
flag = min(m, flag)
for i in range(10):
if i != col and m + C[col][i] < lim:
dfs(i, m + C[col][i])
for i in range(10):
if i != 1:
flag = 10**9
lim = C[i][1]
dfs(i, 0)
if flag != 10**9:
memo[i] = flag
ans = 0
for i in range(H):
for j in range(W):
if abs(a[i][j]) != 1:
ans += memo[a[i][j]]
print(ans) | import sys
sys.setrecursionlimit(10**9)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
H, W = mi()
C = li2(10)
a = li2(H)
memo = [C[i][1] for i in range(10)]
'''
tmp = -1
def dfs(column, m):
if column == 1:
global tmp
tmp = max(m, tmp)
for i in range(10):
if i != column and C[column][i] < m:
dfs(i, m-C[column][i])
#return
for i in range(10):
if i != 1:
dfs(i, C[i][1])
if tmp != -1:
memo[i] = C[i][1] - tmp
tmp = -1
'''
INF = 10**9
tmp = 10**9
'''
def dfs(col, m):
if col == 1:
global tmp
tmp = min(m, tmp)
for i in range(10):
if i != col and m + C[col][i] < lim:
dfs(i, m + C[col][i])
for i in range(10):
if i != 1:
tmp = INF
lim = C[i][1]
dfs(i, 0)
memo[i] = min(tmp, memo[i])
'''
from collections import deque
for i in range(10):
que = deque()
lim = C[i][1]
for j in range(10):
if C[i][j] < lim:
que.append([j, C[i][j]])
while que != deque():
#print(que)
k = que.popleft()
for j in range(10):
if C[k[0]][j] + k[1] < lim and k[0] != j:
if j == 1:
memo[i] = min(memo[i], C[k[0]][j] + k[1])
else:
que.append([j, C[k[0]][j] + k[1]])
ans = 0
for i in range(H):
for j in range(W):
if abs(a[i][j]) != 1:
ans += memo[a[i][j]]
print(ans) | 58 | 75 | 1,496 | 1,998 | import sys
sys.setrecursionlimit(10**9)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
H, W = mi()
C = li2(10)
a = li2(H)
memo = [C[i][1] for i in range(10)]
flag = -1
"""
def dfs(column, m):
if column == 1:
global flag
flag = max(m, flag)
for i in range(10):
if i!=column and C[column][i] < m:
dfs(i, m-C[column][i])
#return
for i in range(10):
if i != 1:
dfs(i, C[i][1])
if flag != -1:
memo[i] = C[i][1]-flag
flag = -1
"""
flag = 10**9
def dfs(col, m):
if col == 1:
global flag
flag = min(m, flag)
for i in range(10):
if i != col and m + C[col][i] < lim:
dfs(i, m + C[col][i])
for i in range(10):
if i != 1:
flag = 10**9
lim = C[i][1]
dfs(i, 0)
if flag != 10**9:
memo[i] = flag
ans = 0
for i in range(H):
for j in range(W):
if abs(a[i][j]) != 1:
ans += memo[a[i][j]]
print(ans)
| import sys
sys.setrecursionlimit(10**9)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
H, W = mi()
C = li2(10)
a = li2(H)
memo = [C[i][1] for i in range(10)]
"""
tmp = -1
def dfs(column, m):
if column == 1:
global tmp
tmp = max(m, tmp)
for i in range(10):
if i != column and C[column][i] < m:
dfs(i, m-C[column][i])
#return
for i in range(10):
if i != 1:
dfs(i, C[i][1])
if tmp != -1:
memo[i] = C[i][1] - tmp
tmp = -1
"""
INF = 10**9
tmp = 10**9
"""
def dfs(col, m):
if col == 1:
global tmp
tmp = min(m, tmp)
for i in range(10):
if i != col and m + C[col][i] < lim:
dfs(i, m + C[col][i])
for i in range(10):
if i != 1:
tmp = INF
lim = C[i][1]
dfs(i, 0)
memo[i] = min(tmp, memo[i])
"""
from collections import deque
for i in range(10):
que = deque()
lim = C[i][1]
for j in range(10):
if C[i][j] < lim:
que.append([j, C[i][j]])
while que != deque():
# print(que)
k = que.popleft()
for j in range(10):
if C[k[0]][j] + k[1] < lim and k[0] != j:
if j == 1:
memo[i] = min(memo[i], C[k[0]][j] + k[1])
else:
que.append([j, C[k[0]][j] + k[1]])
ans = 0
for i in range(H):
for j in range(W):
if abs(a[i][j]) != 1:
ans += memo[a[i][j]]
print(ans)
| false | 22.666667 | [
"-flag = -1",
"+tmp = -1",
"- global flag",
"- flag = max(m, flag)",
"+ global tmp",
"+ tmp = max(m, tmp)",
"- if i!=column and C[column][i] < m:",
"+ if i != column and C[column][i] < m:",
"- if flag != -1:",
"- memo[i] = C[i][1]-flag",
"- flag = -1",
"+ if tmp != -1:",
"+ memo[i] = C[i][1] - tmp",
"+ tmp = -1",
"-flag = 10**9",
"-",
"-",
"+INF = 10**9",
"+tmp = 10**9",
"+\"\"\"",
"- global flag",
"- flag = min(m, flag)",
"+ global tmp",
"+ tmp = min(m, tmp)",
"-",
"+for i in range(10):",
"+ if i != 1:",
"+ tmp = INF",
"+ lim = C[i][1]",
"+ dfs(i, 0)",
"+ memo[i] = min(tmp, memo[i])",
"+\"\"\"",
"+from collections import deque",
"- if i != 1:",
"- flag = 10**9",
"- lim = C[i][1]",
"- dfs(i, 0)",
"- if flag != 10**9:",
"- memo[i] = flag",
"+ que = deque()",
"+ lim = C[i][1]",
"+ for j in range(10):",
"+ if C[i][j] < lim:",
"+ que.append([j, C[i][j]])",
"+ while que != deque():",
"+ # print(que)",
"+ k = que.popleft()",
"+ for j in range(10):",
"+ if C[k[0]][j] + k[1] < lim and k[0] != j:",
"+ if j == 1:",
"+ memo[i] = min(memo[i], C[k[0]][j] + k[1])",
"+ else:",
"+ que.append([j, C[k[0]][j] + k[1]])"
] | false | 0.047572 | 0.164317 | 0.289512 | [
"s956865179",
"s320018443"
] |
u839675792 | p03281 | python | s896391420 | s857152027 | 24 | 18 | 2,940 | 2,940 | Accepted | Accepted | 25 | n = int(eval(input()))
r = 0
for i in range(0, n, 2):
c = 0
for j in range(0, i + 1, 2):
if (i + 1) % (j + 1) == 0:
c += 1
if c == 8:
r += 1
print(r)
| n = int(eval(input()))
r = 0
for i in range(0, n, 2):
c = 1
for j in range(2, i + 1, 2):
if (i + 1) % (j + 1) == 0:
c += 1
if c == 8:
r += 1
print(r)
| 14 | 14 | 201 | 201 | n = int(eval(input()))
r = 0
for i in range(0, n, 2):
c = 0
for j in range(0, i + 1, 2):
if (i + 1) % (j + 1) == 0:
c += 1
if c == 8:
r += 1
print(r)
| n = int(eval(input()))
r = 0
for i in range(0, n, 2):
c = 1
for j in range(2, i + 1, 2):
if (i + 1) % (j + 1) == 0:
c += 1
if c == 8:
r += 1
print(r)
| false | 0 | [
"- c = 0",
"- for j in range(0, i + 1, 2):",
"+ c = 1",
"+ for j in range(2, i + 1, 2):"
] | false | 0.041102 | 0.041734 | 0.984865 | [
"s896391420",
"s857152027"
] |
u706414019 | p03860 | python | s202798600 | s507508541 | 31 | 26 | 9,032 | 8,804 | Accepted | Accepted | 16.13 | A,B,C = input().split()
print((A[0]+B[0]+C[0])) | print(('A'+str(eval(input()))[8]+'C')) | 2 | 1 | 46 | 30 | A, B, C = input().split()
print((A[0] + B[0] + C[0]))
| print(("A" + str(eval(input()))[8] + "C"))
| false | 50 | [
"-A, B, C = input().split()",
"-print((A[0] + B[0] + C[0]))",
"+print((\"A\" + str(eval(input()))[8] + \"C\"))"
] | false | 0.037559 | 0.039757 | 0.944715 | [
"s202798600",
"s507508541"
] |
u918601425 | p02912 | python | s499208354 | s267259314 | 368 | 170 | 21,316 | 14,180 | Accepted | Accepted | 53.8 | import heapq
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
h = []
for e in ls:
heapq.heappush(h, (-e,e))
for i in range(M):
x=heapq.heappop(h)
y=x[1]//2
heapq.heappush(h,(-y,y))
ls2=[e[1] for e in h]
print((sum(ls2)))
| import heapq
N,M=[int(s) for s in input().split()]
ls=input().split()
h = []
for e in ls:
heapq.heappush(h, -int(e))
for i in range(M):
x=heapq.heappop(h)
y=(-x)//2
heapq.heappush(h,-y)
print((-sum(h)))
| 12 | 11 | 264 | 219 | import heapq
N, M = [int(s) for s in input().split()]
ls = [int(s) for s in input().split()]
h = []
for e in ls:
heapq.heappush(h, (-e, e))
for i in range(M):
x = heapq.heappop(h)
y = x[1] // 2
heapq.heappush(h, (-y, y))
ls2 = [e[1] for e in h]
print((sum(ls2)))
| import heapq
N, M = [int(s) for s in input().split()]
ls = input().split()
h = []
for e in ls:
heapq.heappush(h, -int(e))
for i in range(M):
x = heapq.heappop(h)
y = (-x) // 2
heapq.heappush(h, -y)
print((-sum(h)))
| false | 8.333333 | [
"-ls = [int(s) for s in input().split()]",
"+ls = input().split()",
"- heapq.heappush(h, (-e, e))",
"+ heapq.heappush(h, -int(e))",
"- y = x[1] // 2",
"- heapq.heappush(h, (-y, y))",
"-ls2 = [e[1] for e in h]",
"-print((sum(ls2)))",
"+ y = (-x) // 2",
"+ heapq.heappush(h, -y)",
"+print((-sum(h)))"
] | false | 0.050879 | 0.048818 | 1.042223 | [
"s499208354",
"s267259314"
] |
u761320129 | p02615 | python | s758273067 | s018474682 | 180 | 162 | 31,440 | 31,340 | Accepted | Accepted | 10 | N = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
ans = A[-1]
i = N-1
N -= 2
while N:
i -= 1
for _ in range(2):
N -= 1
ans += A[i]
if N<=0: break
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
if N==2:
print((max(A)))
exit()
ans = A.pop()
n = N-2
while A:
a = A.pop()
for _ in range(2):
n -= 1
ans += a
if n==0:
print(ans)
exit() | 13 | 17 | 211 | 276 | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ans = A[-1]
i = N - 1
N -= 2
while N:
i -= 1
for _ in range(2):
N -= 1
ans += A[i]
if N <= 0:
break
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
if N == 2:
print((max(A)))
exit()
ans = A.pop()
n = N - 2
while A:
a = A.pop()
for _ in range(2):
n -= 1
ans += a
if n == 0:
print(ans)
exit()
| false | 23.529412 | [
"-ans = A[-1]",
"-i = N - 1",
"-N -= 2",
"-while N:",
"- i -= 1",
"+if N == 2:",
"+ print((max(A)))",
"+ exit()",
"+ans = A.pop()",
"+n = N - 2",
"+while A:",
"+ a = A.pop()",
"- N -= 1",
"- ans += A[i]",
"- if N <= 0:",
"- break",
"-print(ans)",
"+ n -= 1",
"+ ans += a",
"+ if n == 0:",
"+ print(ans)",
"+ exit()"
] | false | 0.042648 | 0.039848 | 1.070272 | [
"s758273067",
"s018474682"
] |
u836737505 | p03705 | python | s032813413 | s489822359 | 175 | 17 | 38,544 | 3,060 | Accepted | Accepted | 90.29 | n,a,b = list(map(int,input().split()))
if n == 1 and a == b:
print((1))
elif (n == 1 and a != b) or a > b:
print((0))
else:
print(((n-1)*b+a-((n-1)*a+b)+1)) | n,a,b = list(map(int, input().split()))
if n == 1 and a==b:
print((1))
elif n == 1 or a > b:
print((0))
else:
print(((n-2)*(b-a)+1)) | 7 | 7 | 162 | 138 | n, a, b = list(map(int, input().split()))
if n == 1 and a == b:
print((1))
elif (n == 1 and a != b) or a > b:
print((0))
else:
print(((n - 1) * b + a - ((n - 1) * a + b) + 1))
| n, a, b = list(map(int, input().split()))
if n == 1 and a == b:
print((1))
elif n == 1 or a > b:
print((0))
else:
print(((n - 2) * (b - a) + 1))
| false | 0 | [
"-elif (n == 1 and a != b) or a > b:",
"+elif n == 1 or a > b:",
"- print(((n - 1) * b + a - ((n - 1) * a + b) + 1))",
"+ print(((n - 2) * (b - a) + 1))"
] | false | 0.093896 | 0.071979 | 1.304494 | [
"s032813413",
"s489822359"
] |
u238940874 | p03598 | python | s033988795 | s456815716 | 20 | 18 | 3,060 | 3,060 | Accepted | Accepted | 10 | n=int(eval(input()))
k=int(eval(input()))
x=list(map(int,input().split()))
ans=0
for i in range(n):
ans+=min((x[i]-0)*2,(abs(x[i]-k))*2)
print(ans) | n=int(eval(input()))
k=int(eval(input()))
x=list(map(int,input().split()))
ans=0
for i in range(n):
ans+=min(abs(x[i]-0)*2,abs(x[i]-k)*2)
print(ans) | 8 | 7 | 147 | 146 | n = int(eval(input()))
k = int(eval(input()))
x = list(map(int, input().split()))
ans = 0
for i in range(n):
ans += min((x[i] - 0) * 2, (abs(x[i] - k)) * 2)
print(ans)
| n = int(eval(input()))
k = int(eval(input()))
x = list(map(int, input().split()))
ans = 0
for i in range(n):
ans += min(abs(x[i] - 0) * 2, abs(x[i] - k) * 2)
print(ans)
| false | 12.5 | [
"- ans += min((x[i] - 0) * 2, (abs(x[i] - k)) * 2)",
"+ ans += min(abs(x[i] - 0) * 2, abs(x[i] - k) * 2)"
] | false | 0.037576 | 0.034723 | 1.082181 | [
"s033988795",
"s456815716"
] |
u796942881 | p03862 | python | s886146439 | s096259073 | 90 | 81 | 14,092 | 14,092 | Accepted | Accepted | 10 | def main():
N, x, *an = list(map(int, open(0).read().split()))
ans = 0
for i in range(N - 1):
if x < an[i] + an[i + 1]:
cur = an[i] + an[i + 1] - x
ans += cur
if an[i + 1] <= cur:
an[i + 1] = 0
else:
an[i + 1] -= cur
print(ans)
return
main()
| def main():
N, x, *a = list(map(int, open(0).read().split()))
ans = 0
pre = a[0]
for i in range(1, N):
if x < pre + a[i]:
cur = pre + a[i] - x
ans += cur
a[i] = a[i] - cur if cur < a[i] else 0
pre = a[i]
print(ans)
return
main()
| 16 | 15 | 361 | 315 | def main():
N, x, *an = list(map(int, open(0).read().split()))
ans = 0
for i in range(N - 1):
if x < an[i] + an[i + 1]:
cur = an[i] + an[i + 1] - x
ans += cur
if an[i + 1] <= cur:
an[i + 1] = 0
else:
an[i + 1] -= cur
print(ans)
return
main()
| def main():
N, x, *a = list(map(int, open(0).read().split()))
ans = 0
pre = a[0]
for i in range(1, N):
if x < pre + a[i]:
cur = pre + a[i] - x
ans += cur
a[i] = a[i] - cur if cur < a[i] else 0
pre = a[i]
print(ans)
return
main()
| false | 6.25 | [
"- N, x, *an = list(map(int, open(0).read().split()))",
"+ N, x, *a = list(map(int, open(0).read().split()))",
"- for i in range(N - 1):",
"- if x < an[i] + an[i + 1]:",
"- cur = an[i] + an[i + 1] - x",
"+ pre = a[0]",
"+ for i in range(1, N):",
"+ if x < pre + a[i]:",
"+ cur = pre + a[i] - x",
"- if an[i + 1] <= cur:",
"- an[i + 1] = 0",
"- else:",
"- an[i + 1] -= cur",
"+ a[i] = a[i] - cur if cur < a[i] else 0",
"+ pre = a[i]"
] | false | 0.036096 | 0.049122 | 0.734823 | [
"s886146439",
"s096259073"
] |
u991567869 | p02984 | python | s688320347 | s302416199 | 120 | 106 | 20,644 | 20,536 | Accepted | Accepted | 11.67 | n = int(input())
a = list(map(int, input().split()))
ans = a[0]
l = []
for i in range(1, n, 2):
ans -= a[i]
ans += a[i + 1]
l.append(ans)
for i in range(n - 1):
ans = (a[i] - ans//2)*2
l.append(ans)
for i in l:
print(i, end = " ")
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = a[0]
l = []
for i in range(1, n, 2):
ans -= a[i]
ans += a[i + 1]
l.append(ans)
for i in range(n - 1):
ans = a[i]*2 - ans
l.append(ans)
print((*l)) | 17 | 16 | 270 | 238 | n = int(input())
a = list(map(int, input().split()))
ans = a[0]
l = []
for i in range(1, n, 2):
ans -= a[i]
ans += a[i + 1]
l.append(ans)
for i in range(n - 1):
ans = (a[i] - ans // 2) * 2
l.append(ans)
for i in l:
print(i, end=" ")
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = a[0]
l = []
for i in range(1, n, 2):
ans -= a[i]
ans += a[i + 1]
l.append(ans)
for i in range(n - 1):
ans = a[i] * 2 - ans
l.append(ans)
print((*l))
| false | 5.882353 | [
"-n = int(input())",
"+n = int(eval(input()))",
"- ans = (a[i] - ans // 2) * 2",
"+ ans = a[i] * 2 - ans",
"-for i in l:",
"- print(i, end=\" \")",
"+print((*l))"
] | false | 0.032974 | 0.036928 | 0.892921 | [
"s688320347",
"s302416199"
] |
u801049006 | p03436 | python | s699818204 | s138988869 | 30 | 27 | 3,444 | 3,316 | Accepted | Accepted | 10 | from collections import deque
def bfs():
d = [[float("inf")] * w for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
que = deque([])
que.append((sx, sy))
d[sx][sy] = 0
while que:
p = que.popleft()
if p[0] == gx and p[1] == gy:
break
for i in range(4):
nx = p[0] + dx[i]
ny = p[1] + dy[i]
if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
que.append((nx, ny))
d[nx][ny] = d[p[0]][p[1]] + 1
return d[gx][gy]
h, w = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(h)]
sx, sy = 0, 0
gx, gy = h-1, w-1
white = 0
for i in range(h):
for j in range(w):
if maze[i][j] == ".":
white += 1
res = bfs()
if 0 < res < float("inf"):
print((white-res-1))
else:
print((-1)) | from collections import deque
H, W = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(H)]
block_count = 0
for i in range(H):
for j in range(W):
if s[i][j] == '#':
block_count += 1
d = [[0] * W for _ in range(H)]
dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
que = deque([])
que.append((0, 0))
d[0][0] = 1
while que:
x, y = que.popleft()
for dx, dy in dxdy:
nx = x + dx
ny = y + dy
if 0 <= nx < W and 0 <= ny < H and d[ny][nx] == 0 and s[ny][nx] == '.':
que.append((nx, ny))
d[ny][nx] = d[y][x] + 1
if d[H-1][W-1]:
print((H * W - d[H-1][W-1] - block_count))
else:
print((-1))
| 44 | 32 | 933 | 708 | from collections import deque
def bfs():
d = [[float("inf")] * w for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
que = deque([])
que.append((sx, sy))
d[sx][sy] = 0
while que:
p = que.popleft()
if p[0] == gx and p[1] == gy:
break
for i in range(4):
nx = p[0] + dx[i]
ny = p[1] + dy[i]
if (
0 <= nx < h
and 0 <= ny < w
and maze[nx][ny] != "#"
and d[nx][ny] == float("inf")
):
que.append((nx, ny))
d[nx][ny] = d[p[0]][p[1]] + 1
return d[gx][gy]
h, w = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(h)]
sx, sy = 0, 0
gx, gy = h - 1, w - 1
white = 0
for i in range(h):
for j in range(w):
if maze[i][j] == ".":
white += 1
res = bfs()
if 0 < res < float("inf"):
print((white - res - 1))
else:
print((-1))
| from collections import deque
H, W = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(H)]
block_count = 0
for i in range(H):
for j in range(W):
if s[i][j] == "#":
block_count += 1
d = [[0] * W for _ in range(H)]
dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
que = deque([])
que.append((0, 0))
d[0][0] = 1
while que:
x, y = que.popleft()
for dx, dy in dxdy:
nx = x + dx
ny = y + dy
if 0 <= nx < W and 0 <= ny < H and d[ny][nx] == 0 and s[ny][nx] == ".":
que.append((nx, ny))
d[ny][nx] = d[y][x] + 1
if d[H - 1][W - 1]:
print((H * W - d[H - 1][W - 1] - block_count))
else:
print((-1))
| false | 27.272727 | [
"-",
"-def bfs():",
"- d = [[float(\"inf\")] * w for i in range(h)]",
"- dx = [1, 0, -1, 0]",
"- dy = [0, 1, 0, -1]",
"- que = deque([])",
"- que.append((sx, sy))",
"- d[sx][sy] = 0",
"- while que:",
"- p = que.popleft()",
"- if p[0] == gx and p[1] == gy:",
"- break",
"- for i in range(4):",
"- nx = p[0] + dx[i]",
"- ny = p[1] + dy[i]",
"- if (",
"- 0 <= nx < h",
"- and 0 <= ny < w",
"- and maze[nx][ny] != \"#\"",
"- and d[nx][ny] == float(\"inf\")",
"- ):",
"- que.append((nx, ny))",
"- d[nx][ny] = d[p[0]][p[1]] + 1",
"- return d[gx][gy]",
"-",
"-",
"-h, w = list(map(int, input().split()))",
"-maze = [list(eval(input())) for _ in range(h)]",
"-sx, sy = 0, 0",
"-gx, gy = h - 1, w - 1",
"-white = 0",
"-for i in range(h):",
"- for j in range(w):",
"- if maze[i][j] == \".\":",
"- white += 1",
"-res = bfs()",
"-if 0 < res < float(\"inf\"):",
"- print((white - res - 1))",
"+H, W = list(map(int, input().split()))",
"+s = [list(eval(input())) for _ in range(H)]",
"+block_count = 0",
"+for i in range(H):",
"+ for j in range(W):",
"+ if s[i][j] == \"#\":",
"+ block_count += 1",
"+d = [[0] * W for _ in range(H)]",
"+dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)]",
"+que = deque([])",
"+que.append((0, 0))",
"+d[0][0] = 1",
"+while que:",
"+ x, y = que.popleft()",
"+ for dx, dy in dxdy:",
"+ nx = x + dx",
"+ ny = y + dy",
"+ if 0 <= nx < W and 0 <= ny < H and d[ny][nx] == 0 and s[ny][nx] == \".\":",
"+ que.append((nx, ny))",
"+ d[ny][nx] = d[y][x] + 1",
"+if d[H - 1][W - 1]:",
"+ print((H * W - d[H - 1][W - 1] - block_count))"
] | false | 0.036302 | 0.080423 | 0.451391 | [
"s699818204",
"s138988869"
] |
u261103969 | p02627 | python | s053763013 | s285994106 | 73 | 24 | 61,684 | 8,988 | Accepted | Accepted | 67.12 | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
a = eval(input())
if a == a.upper():
print("A")
else:
print("a")
if __name__ == '__main__':
main()
| s = eval(input())
if s == s.upper():
print("A")
else:
print("a") | 19 | 6 | 270 | 72 | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
a = eval(input())
if a == a.upper():
print("A")
else:
print("a")
if __name__ == "__main__":
main()
| s = eval(input())
if s == s.upper():
print("A")
else:
print("a")
| false | 68.421053 | [
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-MOD = 10**9 + 7",
"-INF = float(\"INF\")",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def main():",
"- a = eval(input())",
"- if a == a.upper():",
"- print(\"A\")",
"- else:",
"- print(\"a\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+s = eval(input())",
"+if s == s.upper():",
"+ print(\"A\")",
"+else:",
"+ print(\"a\")"
] | false | 0.0378 | 0.057806 | 0.653916 | [
"s053763013",
"s285994106"
] |
u426534722 | p02327 | python | s920720788 | s216163565 | 3,380 | 1,600 | 54,324 | 8,188 | Accepted | Accepted | 52.66 | from sys import stdin
from collections import deque
readline = stdin.readline
h, w = list(map(int, readline().split()))
w += 1
dp = [list(map(int, readline().split())) + [1] for _ in range(h)]
for i in range(h):
for j in range(w):
dp[i][j] ^= 1
for i in range(1, h):
for j in range(w):
if dp[i][j]:
dp[i][j] += dp[i - 1][j]
max_s = 0
for i in range(h):
stack = deque()
for j in range(w):
if (stack[-1][0] if stack else 0) < dp[i][j]:
stack.append((dp[i][j], j))
elif stack and stack[-1][0] > dp[i][j]:
while stack and stack[-1][0] > dp[i][j]:
height, l = stack.pop()
s = height * (j - l)
if max_s < s:
max_s = s
if dp[i][j]:
stack.append((dp[i][j], l))
print(max_s) | from sys import stdin
from collections import deque
def judge(n,hs):
stack = deque()
ans = 0
for i, h in enumerate(hs):
j = -1
while stack and stack[-1][1] > h:
j, h2 = stack.pop()
ans = max(ans, (i - j) * h2)
if not stack or stack[-1][1] < h:
stack.append((i if j == -1 else j, h))
ans = max(ans, max((n - j) * h2 for j, h2 in stack))
return ans
H,W = list(map(int,stdin.readline().split()))
hs = [0]*W
result = 0
for i in range(H):
ht = list(map(int, stdin.readline().split()))
hs = list(map(lambda x,y:(x+1)*abs(y-1),hs,ht))
result = max(result,judge(W,hs))
print(result) | 28 | 22 | 866 | 681 | from sys import stdin
from collections import deque
readline = stdin.readline
h, w = list(map(int, readline().split()))
w += 1
dp = [list(map(int, readline().split())) + [1] for _ in range(h)]
for i in range(h):
for j in range(w):
dp[i][j] ^= 1
for i in range(1, h):
for j in range(w):
if dp[i][j]:
dp[i][j] += dp[i - 1][j]
max_s = 0
for i in range(h):
stack = deque()
for j in range(w):
if (stack[-1][0] if stack else 0) < dp[i][j]:
stack.append((dp[i][j], j))
elif stack and stack[-1][0] > dp[i][j]:
while stack and stack[-1][0] > dp[i][j]:
height, l = stack.pop()
s = height * (j - l)
if max_s < s:
max_s = s
if dp[i][j]:
stack.append((dp[i][j], l))
print(max_s)
| from sys import stdin
from collections import deque
def judge(n, hs):
stack = deque()
ans = 0
for i, h in enumerate(hs):
j = -1
while stack and stack[-1][1] > h:
j, h2 = stack.pop()
ans = max(ans, (i - j) * h2)
if not stack or stack[-1][1] < h:
stack.append((i if j == -1 else j, h))
ans = max(ans, max((n - j) * h2 for j, h2 in stack))
return ans
H, W = list(map(int, stdin.readline().split()))
hs = [0] * W
result = 0
for i in range(H):
ht = list(map(int, stdin.readline().split()))
hs = list(map(lambda x, y: (x + 1) * abs(y - 1), hs, ht))
result = max(result, judge(W, hs))
print(result)
| false | 21.428571 | [
"-readline = stdin.readline",
"-h, w = list(map(int, readline().split()))",
"-w += 1",
"-dp = [list(map(int, readline().split())) + [1] for _ in range(h)]",
"-for i in range(h):",
"- for j in range(w):",
"- dp[i][j] ^= 1",
"-for i in range(1, h):",
"- for j in range(w):",
"- if dp[i][j]:",
"- dp[i][j] += dp[i - 1][j]",
"-max_s = 0",
"-for i in range(h):",
"+",
"+def judge(n, hs):",
"- for j in range(w):",
"- if (stack[-1][0] if stack else 0) < dp[i][j]:",
"- stack.append((dp[i][j], j))",
"- elif stack and stack[-1][0] > dp[i][j]:",
"- while stack and stack[-1][0] > dp[i][j]:",
"- height, l = stack.pop()",
"- s = height * (j - l)",
"- if max_s < s:",
"- max_s = s",
"- if dp[i][j]:",
"- stack.append((dp[i][j], l))",
"-print(max_s)",
"+ ans = 0",
"+ for i, h in enumerate(hs):",
"+ j = -1",
"+ while stack and stack[-1][1] > h:",
"+ j, h2 = stack.pop()",
"+ ans = max(ans, (i - j) * h2)",
"+ if not stack or stack[-1][1] < h:",
"+ stack.append((i if j == -1 else j, h))",
"+ ans = max(ans, max((n - j) * h2 for j, h2 in stack))",
"+ return ans",
"+",
"+",
"+H, W = list(map(int, stdin.readline().split()))",
"+hs = [0] * W",
"+result = 0",
"+for i in range(H):",
"+ ht = list(map(int, stdin.readline().split()))",
"+ hs = list(map(lambda x, y: (x + 1) * abs(y - 1), hs, ht))",
"+ result = max(result, judge(W, hs))",
"+print(result)"
] | false | 0.037761 | 0.149315 | 0.252896 | [
"s920720788",
"s216163565"
] |
u255673886 | p03805 | python | s950656882 | s894290346 | 286 | 85 | 46,956 | 70,624 | Accepted | Accepted | 70.28 | import sys
readline = sys.stdin.buffer.readline
from collections import deque
from copy import copy,deepcopy
from itertools import permutations
def myinput():
return list(map(int,readline().split()))
def mycol(data,col):
return [ row[col] for row in data ]
n,m = myinput()
ab = [ list(myinput()) for _ in range(m) ]
v = list(range(1,n+1))
p = list(permutations(v))
# print(p)
count = 0
for s in p:
# print(s)
if s[0]!=1:
pass
else:
flag = True
for j in range(n-1):
v_tmp = s[j]
v_next = s[j+1]
c = [v_tmp,v_next]
d = [v_next,v_tmp]
if ( c in ab ) or ( d in ab ):
pass
else:
flag = False
if flag:
count += 1
else:
pass
# print(count)
print(count) | from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int,input().split()))
def mylistinput(n):
return [ list(myinput()) for _ in range(n) ]
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse_flag):
data.sort(key=lambda x:x[col],reverse=reverse_flag)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int,input().split()))
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(eval(input())) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(input().split())
def CS(n):
return [ eval(input()) for _ in range(n) ]
def LS(n):
return [ list(input().split()) for _ in range(n) ]
n,m = RI()
ab = LI(m)
g = [ [] for _ in range(n) ]
for i in range(m):
a = ab[i][0] - 1
b = ab[i][1] - 1
g[a].append(b)
g[b].append(a)
# print(g)
l = list(range(1,n))
ls = list( permutations(l) )
# print(ls)
ans = 0
for i in range(len(ls)):
flag = True
v = [0]*n
p = [0] + list(ls[i])
# print(p)
for j in range(len(p)-1):
if v[p[j]]!=0:
flag = False
else:
if p[j+1] in g[p[j]]:
v[p[j]] = 1
else:
flag = False
if flag:
ans += 1
else:
pass
print(ans) | 44 | 131 | 882 | 2,834 | import sys
readline = sys.stdin.buffer.readline
from collections import deque
from copy import copy, deepcopy
from itertools import permutations
def myinput():
return list(map(int, readline().split()))
def mycol(data, col):
return [row[col] for row in data]
n, m = myinput()
ab = [list(myinput()) for _ in range(m)]
v = list(range(1, n + 1))
p = list(permutations(v))
# print(p)
count = 0
for s in p:
# print(s)
if s[0] != 1:
pass
else:
flag = True
for j in range(n - 1):
v_tmp = s[j]
v_next = s[j + 1]
c = [v_tmp, v_next]
d = [v_next, v_tmp]
if (c in ab) or (d in ab):
pass
else:
flag = False
if flag:
count += 1
else:
pass
# print(count)
print(count)
| from collections import deque
from heapq import heapify, heappop, heappush, heappushpop
from copy import copy, deepcopy
from itertools import product, permutations, combinations, combinations_with_replacement
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
INF = float("inf")
def myinput():
return list(map(int, input().split()))
def mylistinput(n):
return [list(myinput()) for _ in range(n)]
def mycol(data, col):
return [row[col] for row in data]
def mysort(data, col, reverse_flag):
data.sort(key=lambda x: x[col], reverse=reverse_flag)
return data
def mymax(data):
M = -1 * float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M, m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m, M)
return m
def mycount(ls, x):
# lsはソート済みであること
l = bisect_left(ls, x)
r = bisect_right(ls, x)
return r - l
def myoutput(ls, space=True):
if space:
if len(ls) == 0:
print(" ")
elif type(ls[0]) == str:
print((" ".join(ls)))
elif type(ls[0]) == int:
print((" ".join(map(str, ls))))
else:
print("Output Error")
else:
if len(ls) == 0:
print("")
elif type(ls[0]) == str:
print(("".join(ls)))
elif type(ls[0]) == int:
print(("".join(map(str, ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def RI():
return list(map(int, input().split()))
def CI(n):
return [int(eval(input())) for _ in range(n)]
def LI(n):
return [list(map(int, input().split())) for _ in range(n)]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(input().split())
def CS(n):
return [eval(input()) for _ in range(n)]
def LS(n):
return [list(input().split()) for _ in range(n)]
n, m = RI()
ab = LI(m)
g = [[] for _ in range(n)]
for i in range(m):
a = ab[i][0] - 1
b = ab[i][1] - 1
g[a].append(b)
g[b].append(a)
# print(g)
l = list(range(1, n))
ls = list(permutations(l))
# print(ls)
ans = 0
for i in range(len(ls)):
flag = True
v = [0] * n
p = [0] + list(ls[i])
# print(p)
for j in range(len(p) - 1):
if v[p[j]] != 0:
flag = False
else:
if p[j + 1] in g[p[j]]:
v[p[j]] = 1
else:
flag = False
if flag:
ans += 1
else:
pass
print(ans)
| false | 66.412214 | [
"-import sys",
"+from collections import deque",
"+from heapq import heapify, heappop, heappush, heappushpop",
"+from copy import copy, deepcopy",
"+from itertools import product, permutations, combinations, combinations_with_replacement",
"+from collections import defaultdict, Counter",
"+from bisect import bisect_left, bisect_right",
"-readline = sys.stdin.buffer.readline",
"-from collections import deque",
"-from copy import copy, deepcopy",
"-from itertools import permutations",
"+# from math import gcd,ceil,floor,factorial",
"+# from fractions import gcd",
"+from functools import reduce",
"+from pprint import pprint",
"+",
"+INF = float(\"inf\")",
"- return list(map(int, readline().split()))",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def mylistinput(n):",
"+ return [list(myinput()) for _ in range(n)]",
"-n, m = myinput()",
"-ab = [list(myinput()) for _ in range(m)]",
"-v = list(range(1, n + 1))",
"-p = list(permutations(v))",
"-# print(p)",
"-count = 0",
"-for s in p:",
"- # print(s)",
"- if s[0] != 1:",
"- pass",
"+def mysort(data, col, reverse_flag):",
"+ data.sort(key=lambda x: x[col], reverse=reverse_flag)",
"+ return data",
"+",
"+",
"+def mymax(data):",
"+ M = -1 * float(\"inf\")",
"+ for i in range(len(data)):",
"+ m = max(data[i])",
"+ M = max(M, m)",
"+ return M",
"+",
"+",
"+def mymin(data):",
"+ m = float(\"inf\")",
"+ for i in range(len(data)):",
"+ M = min(data[i])",
"+ m = min(m, M)",
"+ return m",
"+",
"+",
"+def mycount(ls, x):",
"+ # lsはソート済みであること",
"+ l = bisect_left(ls, x)",
"+ r = bisect_right(ls, x)",
"+ return r - l",
"+",
"+",
"+def myoutput(ls, space=True):",
"+ if space:",
"+ if len(ls) == 0:",
"+ print(\" \")",
"+ elif type(ls[0]) == str:",
"+ print((\" \".join(ls)))",
"+ elif type(ls[0]) == int:",
"+ print((\" \".join(map(str, ls))))",
"+ else:",
"+ print(\"Output Error\")",
"- flag = True",
"- for j in range(n - 1):",
"- v_tmp = s[j]",
"- v_next = s[j + 1]",
"- c = [v_tmp, v_next]",
"- d = [v_next, v_tmp]",
"- if (c in ab) or (d in ab):",
"- pass",
"+ if len(ls) == 0:",
"+ print(\"\")",
"+ elif type(ls[0]) == str:",
"+ print((\"\".join(ls)))",
"+ elif type(ls[0]) == int:",
"+ print((\"\".join(map(str, ls))))",
"+ else:",
"+ print(\"Output Error\")",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def RI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def CI(n):",
"+ return [int(eval(input())) for _ in range(n)]",
"+",
"+",
"+def LI(n):",
"+ return [list(map(int, input().split())) for _ in range(n)]",
"+",
"+",
"+def S():",
"+ return eval(input())",
"+",
"+",
"+def MS():",
"+ return input().split()",
"+",
"+",
"+def RS():",
"+ return list(input().split())",
"+",
"+",
"+def CS(n):",
"+ return [eval(input()) for _ in range(n)]",
"+",
"+",
"+def LS(n):",
"+ return [list(input().split()) for _ in range(n)]",
"+",
"+",
"+n, m = RI()",
"+ab = LI(m)",
"+g = [[] for _ in range(n)]",
"+for i in range(m):",
"+ a = ab[i][0] - 1",
"+ b = ab[i][1] - 1",
"+ g[a].append(b)",
"+ g[b].append(a)",
"+# print(g)",
"+l = list(range(1, n))",
"+ls = list(permutations(l))",
"+# print(ls)",
"+ans = 0",
"+for i in range(len(ls)):",
"+ flag = True",
"+ v = [0] * n",
"+ p = [0] + list(ls[i])",
"+ # print(p)",
"+ for j in range(len(p) - 1):",
"+ if v[p[j]] != 0:",
"+ flag = False",
"+ else:",
"+ if p[j + 1] in g[p[j]]:",
"+ v[p[j]] = 1",
"- if flag:",
"- count += 1",
"- else:",
"- pass",
"- # print(count)",
"-print(count)",
"+ if flag:",
"+ ans += 1",
"+ else:",
"+ pass",
"+print(ans)"
] | false | 0.065533 | 0.058291 | 1.124249 | [
"s950656882",
"s894290346"
] |
u179169725 | p03450 | python | s416699831 | s798654431 | 1,140 | 692 | 80,552 | 118,616 | Accepted | Accepted | 39.3 | # https://atcoder.jp/contests/abc087/tasks/arc090_b
# ノードL→RへのコストはDであるとすれば、有向グラフと見なせる
# 任意のノードからbfsをして座標をメモしていけば良い。
# 探索済みのノードに到達したときに座標があっているかチェック、あっていればそれ以上探索する必要はない。
# 連結していないグラフがあるかもしれない。(だけど連結していないグラフはお互いに独立)
# 0以上10**9以下っていう制約なのでそこでWAを出されるかと思ったがそんなことなかった
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
def read_tuple(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
from collections import defaultdict, deque
N, M = read_ints()
graph = defaultdict(lambda: []) # 有向グラフ、隣接リスト形式
for _ in range(M): # データ読み込み
l, r, d = read_ints()
l -= 1
r -= 1
graph[l].append((r, d))
graph[r].append((l, -d))
# bfs
X = [None] * N # visitedも兼ねる
def bfs(u): # スタートするノードを入れる
que = deque([(u, 0)]) # (今のノード,今の座標)
X[u] = 0
while que:
u, x = que.popleft()
# print(u, x)
for nu, add in graph[u]:
nx = x + add
if X[nu] == nx:
continue
# 次の探索
if X[nu] is not None and X[nu] != nx:
print('No')
exit()
X[nu] = nx
que.append((nu, nx))
for u in range(N):
if X[u] is None:
bfs(u)
print('Yes')
| import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
def read_a_int():
return int(read())
def read_tuple(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
def read_col(H):
'''
H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合
'''
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return tuple(map(list, list(zip(*ret))))
def read_matrix(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return ret
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
# https://atcoder.jp/contests/abc087/tasks/arc090_b
# x0を0に固定したときに各点への最短距離が求められて、それが矛盾しなければ良さそう
# 任意の点から初めて距離を埋めていく
N, M = read_ints()
LRD = []
graph = defaultdict(lambda: [])
for _ in range(M):
l, r, d = read_ints()
l -= 1
r -= 1
LRD.append((l, r, d))
graph[l].append((r, d))
graph[r].append((l, -d))
D = [INF] * N # 各点の位置
def bfs(start):
now, dist = start, 0
que = deque([(now, dist)])
D[now] = dist
while que:
now, dist = que.popleft()
for to, co in graph[now]:
to_dist = dist + co
if D[to] != INF:
if D[to] != to_dist:
print("No")
exit()
continue
D[to] = to_dist
que.append((to, to_dist))
for i in range(N):
if D[i] != INF:
continue
bfs(i)
print('Yes')
| 64 | 97 | 1,384 | 2,029 | # https://atcoder.jp/contests/abc087/tasks/arc090_b
# ノードL→RへのコストはDであるとすれば、有向グラフと見なせる
# 任意のノードからbfsをして座標をメモしていけば良い。
# 探索済みのノードに到達したときに座標があっているかチェック、あっていればそれ以上探索する必要はない。
# 連結していないグラフがあるかもしれない。(だけど連結していないグラフはお互いに独立)
# 0以上10**9以下っていう制約なのでそこでWAを出されるかと思ったがそんなことなかった
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
def read_tuple(H):
"""
H is number of rows
"""
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
from collections import defaultdict, deque
N, M = read_ints()
graph = defaultdict(lambda: []) # 有向グラフ、隣接リスト形式
for _ in range(M): # データ読み込み
l, r, d = read_ints()
l -= 1
r -= 1
graph[l].append((r, d))
graph[r].append((l, -d))
# bfs
X = [None] * N # visitedも兼ねる
def bfs(u): # スタートするノードを入れる
que = deque([(u, 0)]) # (今のノード,今の座標)
X[u] = 0
while que:
u, x = que.popleft()
# print(u, x)
for nu, add in graph[u]:
nx = x + add
if X[nu] == nx:
continue
# 次の探索
if X[nu] is not None and X[nu] != nx:
print("No")
exit()
X[nu] = nx
que.append((nu, nx))
for u in range(N):
if X[u] is None:
bfs(u)
print("Yes")
| import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
def read_a_int():
return int(read())
def read_tuple(H):
"""
H is number of rows
"""
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
def read_col(H):
"""
H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合
"""
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return tuple(map(list, list(zip(*ret))))
def read_matrix(H):
"""
H is number of rows
"""
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return ret
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
# https://atcoder.jp/contests/abc087/tasks/arc090_b
# x0を0に固定したときに各点への最短距離が求められて、それが矛盾しなければ良さそう
# 任意の点から初めて距離を埋めていく
N, M = read_ints()
LRD = []
graph = defaultdict(lambda: [])
for _ in range(M):
l, r, d = read_ints()
l -= 1
r -= 1
LRD.append((l, r, d))
graph[l].append((r, d))
graph[r].append((l, -d))
D = [INF] * N # 各点の位置
def bfs(start):
now, dist = start, 0
que = deque([(now, dist)])
D[now] = dist
while que:
now, dist = que.popleft()
for to, co in graph[now]:
to_dist = dist + co
if D[to] != INF:
if D[to] != to_dist:
print("No")
exit()
continue
D[to] = to_dist
que.append((to, to_dist))
for i in range(N):
if D[i] != INF:
continue
bfs(i)
print("Yes")
| false | 34.020619 | [
"-# https://atcoder.jp/contests/abc087/tasks/arc090_b",
"-# ノードL→RへのコストはDであるとすれば、有向グラフと見なせる",
"-# 任意のノードからbfsをして座標をメモしていけば良い。",
"-# 探索済みのノードに到達したときに座標があっているかチェック、あっていればそれ以上探索する必要はない。",
"-# 連結していないグラフがあるかもしれない。(だけど連結していないグラフはお互いに独立)",
"-# 0以上10**9以下っていう制約なのでそこでWAを出されるかと思ったがそんなことなかった",
"+sys.setrecursionlimit(1 << 25)",
"+ra = range",
"+enu = enumerate",
"+",
"+",
"+def read_a_int():",
"+ return int(read())",
"-from collections import defaultdict, deque",
"+def read_col(H):",
"+ \"\"\"",
"+ H is number of rows",
"+ A列、B列が与えられるようなとき",
"+ ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合",
"+ \"\"\"",
"+ ret = []",
"+ for _ in range(H):",
"+ ret.append(list(map(int, read().split())))",
"+ return tuple(map(list, list(zip(*ret))))",
"+",
"+def read_matrix(H):",
"+ \"\"\"",
"+ H is number of rows",
"+ \"\"\"",
"+ ret = []",
"+ for _ in range(H):",
"+ ret.append(list(map(int, read().split())))",
"+ return ret",
"+",
"+",
"+MOD = 10**9 + 7",
"+INF = 2**31 # 2147483648 > 10**9",
"+# default import",
"+from collections import defaultdict, Counter, deque",
"+from operator import itemgetter",
"+from itertools import product, permutations, combinations",
"+from bisect import bisect_left, bisect_right # , insort_left, insort_right",
"+",
"+# https://atcoder.jp/contests/abc087/tasks/arc090_b",
"+# x0を0に固定したときに各点への最短距離が求められて、それが矛盾しなければ良さそう",
"+# 任意の点から初めて距離を埋めていく",
"-graph = defaultdict(lambda: []) # 有向グラフ、隣接リスト形式",
"-for _ in range(M): # データ読み込み",
"+LRD = []",
"+graph = defaultdict(lambda: [])",
"+for _ in range(M):",
"+ LRD.append((l, r, d))",
"-# bfs",
"-X = [None] * N # visitedも兼ねる",
"+D = [INF] * N # 各点の位置",
"-def bfs(u): # スタートするノードを入れる",
"- que = deque([(u, 0)]) # (今のノード,今の座標)",
"- X[u] = 0",
"+def bfs(start):",
"+ now, dist = start, 0",
"+ que = deque([(now, dist)])",
"+ D[now] = dist",
"- u, x = que.popleft()",
"- # print(u, x)",
"- for nu, add in graph[u]:",
"- nx = x + add",
"- if X[nu] == nx:",
"+ now, dist = que.popleft()",
"+ for to, co in graph[now]:",
"+ to_dist = dist + co",
"+ if D[to] != INF:",
"+ if D[to] != to_dist:",
"+ print(\"No\")",
"+ exit()",
"- # 次の探索",
"- if X[nu] is not None and X[nu] != nx:",
"- print(\"No\")",
"- exit()",
"- X[nu] = nx",
"- que.append((nu, nx))",
"+ D[to] = to_dist",
"+ que.append((to, to_dist))",
"-for u in range(N):",
"- if X[u] is None:",
"- bfs(u)",
"+for i in range(N):",
"+ if D[i] != INF:",
"+ continue",
"+ bfs(i)"
] | false | 0.059027 | 0.105218 | 0.560997 | [
"s416699831",
"s798654431"
] |
u057109575 | p03088 | python | s385161531 | s555224376 | 311 | 118 | 48,220 | 75,908 | Accepted | Accepted | 62.06 | N = int(eval(input()))
MOD = 10 ** 9 + 7
memo = [{} for i in range(N + 1)]
def ok(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if ''.join(t).count('AGC') >= 1:
return False
return True
def dfs(cur, last3):
if last3 in memo[cur]:
return memo[cur][last3]
if cur == N:
return 1
ret = 0
for c in 'ACGT':
if ok(last3 + c):
ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
memo[cur][last3] = ret
return ret
print((dfs(0, 'TTT')))
|
N = int(eval(input()))
MOD = 10 ** 9 + 7
memo = [{} for _ in range(N + 1)]
def ok(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if "".join(t).count("AGC") > 0:
return False
return True
def dfs(cur, last3):
if last3 in memo[cur]:
return memo[cur][last3]
if cur == N:
return 1
ret = 0
for c in "ACGT":
if ok(last3 + c):
ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
memo[cur][last3] = ret
return ret
print((dfs(0, "TTT")))
| 29 | 34 | 614 | 615 | N = int(eval(input()))
MOD = 10**9 + 7
memo = [{} for i in range(N + 1)]
def ok(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if "".join(t).count("AGC") >= 1:
return False
return True
def dfs(cur, last3):
if last3 in memo[cur]:
return memo[cur][last3]
if cur == N:
return 1
ret = 0
for c in "ACGT":
if ok(last3 + c):
ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
memo[cur][last3] = ret
return ret
print((dfs(0, "TTT")))
| N = int(eval(input()))
MOD = 10**9 + 7
memo = [{} for _ in range(N + 1)]
def ok(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if "".join(t).count("AGC") > 0:
return False
return True
def dfs(cur, last3):
if last3 in memo[cur]:
return memo[cur][last3]
if cur == N:
return 1
ret = 0
for c in "ACGT":
if ok(last3 + c):
ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
memo[cur][last3] = ret
return ret
print((dfs(0, "TTT")))
| false | 14.705882 | [
"-memo = [{} for i in range(N + 1)]",
"+memo = [{} for _ in range(N + 1)]",
"- if \"\".join(t).count(\"AGC\") >= 1:",
"+ if \"\".join(t).count(\"AGC\") > 0:"
] | false | 0.070798 | 0.068371 | 1.035498 | [
"s385161531",
"s555224376"
] |
u256256172 | p02407 | python | s388319370 | s066430616 | 50 | 30 | 7,440 | 7,448 | Accepted | Accepted | 40 | x = eval(input())
a = []
b = input().split()
for i in b:
a.append(i)
a.reverse()
print((" ".join(a))) | eval(input())
a = list(input().split())
a.reverse()
print((" ".join(a))) | 7 | 4 | 103 | 67 | x = eval(input())
a = []
b = input().split()
for i in b:
a.append(i)
a.reverse()
print((" ".join(a)))
| eval(input())
a = list(input().split())
a.reverse()
print((" ".join(a)))
| false | 42.857143 | [
"-x = eval(input())",
"-a = []",
"-b = input().split()",
"-for i in b:",
"- a.append(i)",
"+eval(input())",
"+a = list(input().split())"
] | false | 0.116255 | 0.195506 | 0.594637 | [
"s388319370",
"s066430616"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.