user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u020604402
|
p03574
|
python
|
s601747035
|
s012054488
| 32 | 29 | 3,444 | 3,444 |
Accepted
|
Accepted
| 9.38 |
H,W = map(int,input().split())
L = []
blank = ['.' for _ in range(W+2)]
L.append(blank)
def cnt(x):
if x == '#':
return 1
else:
return 0
for _ in range(H):
L.append(['.']+list(input())+['.'])
L.append(blank)
for i in range(1,H+1):
for j in range(1,W+1):
if L[i][j] == '#':
print('#',end='')
else:
c = 0
for x in [-1,0,1]:
for y in [-1,0,1]:
if not (x==y==0):
c += cnt(L[i+x][j+y])
print(c,end='')
print()
|
H, W = map(int,input().split())
L = []
def cange(x):
if x == '.':
return 0
else:
return 1
zerofill = [ '.' for _ in range(W+2)]
L.append(zerofill)
for _ in range(H):
L.append(['.']+list(input())+['.'])
L.append(zerofill)
for i in range(1,H+1):
for j in range(1,1+W):
if L[i][j] == '.':
cnt = 0
for x in [-1,0,1]:
for y in [-1,0,1]:
if not (x == 0 and y == 0):
cnt += cange(L[i+x][j+y])
print(cnt,end='')
else:
print('#',end='')
print()
| 27 | 28 | 594 | 547 |
H, W = map(int, input().split())
L = []
blank = ["." for _ in range(W + 2)]
L.append(blank)
def cnt(x):
if x == "#":
return 1
else:
return 0
for _ in range(H):
L.append(["."] + list(input()) + ["."])
L.append(blank)
for i in range(1, H + 1):
for j in range(1, W + 1):
if L[i][j] == "#":
print("#", end="")
else:
c = 0
for x in [-1, 0, 1]:
for y in [-1, 0, 1]:
if not (x == y == 0):
c += cnt(L[i + x][j + y])
print(c, end="")
print()
|
H, W = map(int, input().split())
L = []
def cange(x):
if x == ".":
return 0
else:
return 1
zerofill = ["." for _ in range(W + 2)]
L.append(zerofill)
for _ in range(H):
L.append(["."] + list(input()) + ["."])
L.append(zerofill)
for i in range(1, H + 1):
for j in range(1, 1 + W):
if L[i][j] == ".":
cnt = 0
for x in [-1, 0, 1]:
for y in [-1, 0, 1]:
if not (x == 0 and y == 0):
cnt += cange(L[i + x][j + y])
print(cnt, end="")
else:
print("#", end="")
print()
| false | 3.571429 |
[
"-blank = [\".\" for _ in range(W + 2)]",
"-L.append(blank)",
"-def cnt(x):",
"- if x == \"#\":",
"+def cange(x):",
"+ if x == \".\":",
"+ return 0",
"+ else:",
"- else:",
"- return 0",
"+zerofill = [\".\" for _ in range(W + 2)]",
"+L.append(zerofill)",
"-L.append(blank)",
"+L.append(zerofill)",
"- for j in range(1, W + 1):",
"- if L[i][j] == \"#\":",
"- print(\"#\", end=\"\")",
"- else:",
"- c = 0",
"+ for j in range(1, 1 + W):",
"+ if L[i][j] == \".\":",
"+ cnt = 0",
"- if not (x == y == 0):",
"- c += cnt(L[i + x][j + y])",
"- print(c, end=\"\")",
"+ if not (x == 0 and y == 0):",
"+ cnt += cange(L[i + x][j + y])",
"+ print(cnt, end=\"\")",
"+ else:",
"+ print(\"#\", end=\"\")"
] | false | 0.039735 | 0.089591 | 0.443517 |
[
"s601747035",
"s012054488"
] |
u463775490
|
p03030
|
python
|
s534744491
|
s407856694
| 21 | 17 | 3,064 | 3,064 |
Accepted
|
Accepted
| 19.05 |
n = int(eval(input()))
s = []
p = []
ans = [0]*n
for i in range(n):
s1,p1 = [str(i) for i in input().split()]
s.append(s1)
p.append(p1)
ans[i] = i + 1
for i in range(n):
p[i] = int(p[i])
flag = 1
while flag:
flag = 0
for i in range(n-1,0,-1):
if s[i] < s[i-1]:
s[i],s[i-1] = s[i-1],s[i]
p[i],p[i-1] = p[i-1],p[i]
ans[i],ans[i-1] = ans[i-1],ans[i]
flag = 1
flag = 1
while flag:
flag = 0
for i in range(n-1):
if s[i] == s[i+1] and p[i] < p[i+1]:
p[i],p[i+1] = p[i+1],p[i]
ans[i],ans[i+1] = ans[i+1],ans[i]
flag = 1
for i in range(n):
print((ans[i]))
|
n = int(eval(input()))
ans = [[] for i in range(n)]
for i in range(n):
ss,pp = list(map(str,input().split()))
ans[i].append(ss)
ans[i].append(int(pp))
ans[i].append(i+1)
ans.sort(key=lambda x: (x[0],-x[1]))
for i in range(n):
print((ans[i][2]))
| 30 | 10 | 708 | 259 |
n = int(eval(input()))
s = []
p = []
ans = [0] * n
for i in range(n):
s1, p1 = [str(i) for i in input().split()]
s.append(s1)
p.append(p1)
ans[i] = i + 1
for i in range(n):
p[i] = int(p[i])
flag = 1
while flag:
flag = 0
for i in range(n - 1, 0, -1):
if s[i] < s[i - 1]:
s[i], s[i - 1] = s[i - 1], s[i]
p[i], p[i - 1] = p[i - 1], p[i]
ans[i], ans[i - 1] = ans[i - 1], ans[i]
flag = 1
flag = 1
while flag:
flag = 0
for i in range(n - 1):
if s[i] == s[i + 1] and p[i] < p[i + 1]:
p[i], p[i + 1] = p[i + 1], p[i]
ans[i], ans[i + 1] = ans[i + 1], ans[i]
flag = 1
for i in range(n):
print((ans[i]))
|
n = int(eval(input()))
ans = [[] for i in range(n)]
for i in range(n):
ss, pp = list(map(str, input().split()))
ans[i].append(ss)
ans[i].append(int(pp))
ans[i].append(i + 1)
ans.sort(key=lambda x: (x[0], -x[1]))
for i in range(n):
print((ans[i][2]))
| false | 66.666667 |
[
"-s = []",
"-p = []",
"-ans = [0] * n",
"+ans = [[] for i in range(n)]",
"- s1, p1 = [str(i) for i in input().split()]",
"- s.append(s1)",
"- p.append(p1)",
"- ans[i] = i + 1",
"+ ss, pp = list(map(str, input().split()))",
"+ ans[i].append(ss)",
"+ ans[i].append(int(pp))",
"+ ans[i].append(i + 1)",
"+ans.sort(key=lambda x: (x[0], -x[1]))",
"- p[i] = int(p[i])",
"-flag = 1",
"-while flag:",
"- flag = 0",
"- for i in range(n - 1, 0, -1):",
"- if s[i] < s[i - 1]:",
"- s[i], s[i - 1] = s[i - 1], s[i]",
"- p[i], p[i - 1] = p[i - 1], p[i]",
"- ans[i], ans[i - 1] = ans[i - 1], ans[i]",
"- flag = 1",
"-flag = 1",
"-while flag:",
"- flag = 0",
"- for i in range(n - 1):",
"- if s[i] == s[i + 1] and p[i] < p[i + 1]:",
"- p[i], p[i + 1] = p[i + 1], p[i]",
"- ans[i], ans[i + 1] = ans[i + 1], ans[i]",
"- flag = 1",
"-for i in range(n):",
"- print((ans[i]))",
"+ print((ans[i][2]))"
] | false | 0.042172 | 0.043146 | 0.977431 |
[
"s534744491",
"s407856694"
] |
u546285759
|
p00148
|
python
|
s440390408
|
s597026022
| 30 | 20 | 7,536 | 7,688 |
Accepted
|
Accepted
| 33.33 |
while True:
try:
c= int(eval(input()))
except:
break
c%= 39
print(("3C0"+str(c) if len(str(c))==1 and c> 0 else ("3C39" if not c else "3C"+str(c))))
|
while True:
try:
a = int(eval(input()))
except:
break
tmp = a - (a // 39) * 39
print(("3C{:02d}".format(tmp if tmp % 39 else 39)))
| 7 | 7 | 178 | 160 |
while True:
try:
c = int(eval(input()))
except:
break
c %= 39
print(
(
"3C0" + str(c)
if len(str(c)) == 1 and c > 0
else ("3C39" if not c else "3C" + str(c))
)
)
|
while True:
try:
a = int(eval(input()))
except:
break
tmp = a - (a // 39) * 39
print(("3C{:02d}".format(tmp if tmp % 39 else 39)))
| false | 0 |
[
"- c = int(eval(input()))",
"+ a = int(eval(input()))",
"- c %= 39",
"- print(",
"- (",
"- \"3C0\" + str(c)",
"- if len(str(c)) == 1 and c > 0",
"- else (\"3C39\" if not c else \"3C\" + str(c))",
"- )",
"- )",
"+ tmp = a - (a // 39) * 39",
"+ print((\"3C{:02d}\".format(tmp if tmp % 39 else 39)))"
] | false | 0.041012 | 0.035373 | 1.159422 |
[
"s440390408",
"s597026022"
] |
u789132058
|
p02900
|
python
|
s781721664
|
s651060248
| 634 | 326 | 3,064 | 3,064 |
Accepted
|
Accepted
| 48.58 |
import sys
import itertools
input = sys.stdin.readline
#複数入力
a,b=(int(x) for x in input().split())
def factorize(n):
b = 2
#本当は[]
fct = [1]
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
return fct
#len(list(itertools.combinations(set(factorize(a))&set(factorize(b)),2)))
if len(set(factorize(a))&set(factorize(b)))==1:
print((1))
else:
print((len((set(factorize(a))&set(factorize(b))))))
|
import sys
import itertools
input = sys.stdin.readline
#複数入力
a,b=(int(x) for x in input().split())
def factorize(n):
b = 2
#本当は[]
fct = [1]
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
return fct
print((len((set(factorize(a))&set(factorize(b))))))
| 25 | 21 | 536 | 387 |
import sys
import itertools
input = sys.stdin.readline
# 複数入力
a, b = (int(x) for x in input().split())
def factorize(n):
b = 2
# 本当は[]
fct = [1]
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
return fct
# len(list(itertools.combinations(set(factorize(a))&set(factorize(b)),2)))
if len(set(factorize(a)) & set(factorize(b))) == 1:
print((1))
else:
print((len((set(factorize(a)) & set(factorize(b))))))
|
import sys
import itertools
input = sys.stdin.readline
# 複数入力
a, b = (int(x) for x in input().split())
def factorize(n):
b = 2
# 本当は[]
fct = [1]
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
return fct
print((len((set(factorize(a)) & set(factorize(b))))))
| false | 16 |
[
"-# len(list(itertools.combinations(set(factorize(a))&set(factorize(b)),2)))",
"-if len(set(factorize(a)) & set(factorize(b))) == 1:",
"- print((1))",
"-else:",
"- print((len((set(factorize(a)) & set(factorize(b))))))",
"+print((len((set(factorize(a)) & set(factorize(b))))))"
] | false | 0.075094 | 0.035105 | 2.139152 |
[
"s781721664",
"s651060248"
] |
u695811449
|
p03287
|
python
|
s054774481
|
s924293235
| 125 | 113 | 16,956 | 14,696 |
Accepted
|
Accepted
| 9.6 |
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(N):
S[i+1]=(A[i]+S[i])%M
def tr(k):
return k*(k-1)//2
countlist=dict()
check=set()
for i in range(1,N+1):
countlist[S[i]]=countlist.get(S[i],0)+1
ANS=countlist.get(0,0)
for i in list(countlist.keys()):
ANS+=tr(countlist[i])
print(ANS)
|
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(N):
S[i+1]=(A[i]+S[i])%M
def tr(k):
return k*(k-1)//2
S.sort()
S=[-1]+S+[-1]
count=0
ANS=0
for i in range(1,N+3):
if S[i]==S[i-1]:
count+=1
else:
ANS+=tr(count)
count=1
print(ANS)
| 35 | 28 | 396 | 346 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (A[i] + S[i]) % M
def tr(k):
return k * (k - 1) // 2
countlist = dict()
check = set()
for i in range(1, N + 1):
countlist[S[i]] = countlist.get(S[i], 0) + 1
ANS = countlist.get(0, 0)
for i in list(countlist.keys()):
ANS += tr(countlist[i])
print(ANS)
|
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (A[i] + S[i]) % M
def tr(k):
return k * (k - 1) // 2
S.sort()
S = [-1] + S + [-1]
count = 0
ANS = 0
for i in range(1, N + 3):
if S[i] == S[i - 1]:
count += 1
else:
ANS += tr(count)
count = 1
print(ANS)
| false | 20 |
[
"-countlist = dict()",
"-check = set()",
"-for i in range(1, N + 1):",
"- countlist[S[i]] = countlist.get(S[i], 0) + 1",
"-ANS = countlist.get(0, 0)",
"-for i in list(countlist.keys()):",
"- ANS += tr(countlist[i])",
"+S.sort()",
"+S = [-1] + S + [-1]",
"+count = 0",
"+ANS = 0",
"+for i in range(1, N + 3):",
"+ if S[i] == S[i - 1]:",
"+ count += 1",
"+ else:",
"+ ANS += tr(count)",
"+ count = 1"
] | false | 0.032733 | 0.09292 | 0.352274 |
[
"s054774481",
"s924293235"
] |
u941022948
|
p03315
|
python
|
s878756836
|
s271700349
| 18 | 16 | 2,940 | 2,940 |
Accepted
|
Accepted
| 11.11 |
a=eval(input())
ans=0
for i in a:
if i=='+':
ans+=1
else:
ans=ans-1
print(ans)
|
a=(eval(input()))
print((a.count('+')-a.count('-')))
| 8 | 2 | 104 | 45 |
a = eval(input())
ans = 0
for i in a:
if i == "+":
ans += 1
else:
ans = ans - 1
print(ans)
|
a = eval(input())
print((a.count("+") - a.count("-")))
| false | 75 |
[
"-ans = 0",
"-for i in a:",
"- if i == \"+\":",
"- ans += 1",
"- else:",
"- ans = ans - 1",
"-print(ans)",
"+print((a.count(\"+\") - a.count(\"-\")))"
] | false | 0.064793 | 0.109996 | 0.589053 |
[
"s878756836",
"s271700349"
] |
u074220993
|
p03945
|
python
|
s807974236
|
s882352234
| 211 | 36 | 9,144 | 9,116 |
Accepted
|
Accepted
| 82.94 |
S = eval(input())
X = S[0]
ans = 0
while 1:
for i in range(len(S)):
if S[i] != X:
ans += 1
X =S[i]
S = S[i:]
break
else:
break
print(ans)
|
S = eval(input())
l = len(S)
ans = sum(a != b for a,b in zip(S[:l-1],S[1:]))
print(ans)
| 14 | 4 | 226 | 84 |
S = eval(input())
X = S[0]
ans = 0
while 1:
for i in range(len(S)):
if S[i] != X:
ans += 1
X = S[i]
S = S[i:]
break
else:
break
print(ans)
|
S = eval(input())
l = len(S)
ans = sum(a != b for a, b in zip(S[: l - 1], S[1:]))
print(ans)
| false | 71.428571 |
[
"-X = S[0]",
"-ans = 0",
"-while 1:",
"- for i in range(len(S)):",
"- if S[i] != X:",
"- ans += 1",
"- X = S[i]",
"- S = S[i:]",
"- break",
"- else:",
"- break",
"+l = len(S)",
"+ans = sum(a != b for a, b in zip(S[: l - 1], S[1:]))"
] | false | 0.037496 | 0.036187 | 1.036152 |
[
"s807974236",
"s882352234"
] |
u657361950
|
p02271
|
python
|
s682320952
|
s519358532
| 1,520 | 1,230 | 6,412 | 5,948 |
Accepted
|
Accepted
| 19.08 |
def subset_sum(s, a):
dict = {}
return subset_rec(0, s, a, dict)
def subset_rec(i, s, a, dict):
key = str(i) + '-' + str(s)
if key in dict:
ret = dict[key]
elif s == 0:
ret = True
elif i >= len(a):
ret = False
else:
ret = subset_rec(i+1, s-a[i], a, dict) or subset_rec(i+1, s, a, dict)
dict[key] = ret
return ret
n = int(eval(input()))
a = list(map(int, input().split()))
p = int(eval(input()))
q = list(map(int, input().split()))
for i in range(p):
if subset_sum(q[i], a):
print('yes')
else:
print('no')
|
def subset_sum(s, a):
n = len(a)
dp = [[False for x in range(s+1)] for x in range(n+1)]
for i in range(n):
v = a[i]
for j in range(s+1):
if v == j:
dp[i+1][j] = True
elif v > j:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = dp[i][j] or dp[i][j-v]
return dp[n][s]
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
m = list(map(int, input().split()))
for i in range(q):
if subset_sum(m[i], a) == True:
print('yes')
else:
print('no')
| 27 | 23 | 547 | 504 |
def subset_sum(s, a):
dict = {}
return subset_rec(0, s, a, dict)
def subset_rec(i, s, a, dict):
key = str(i) + "-" + str(s)
if key in dict:
ret = dict[key]
elif s == 0:
ret = True
elif i >= len(a):
ret = False
else:
ret = subset_rec(i + 1, s - a[i], a, dict) or subset_rec(i + 1, s, a, dict)
dict[key] = ret
return ret
n = int(eval(input()))
a = list(map(int, input().split()))
p = int(eval(input()))
q = list(map(int, input().split()))
for i in range(p):
if subset_sum(q[i], a):
print("yes")
else:
print("no")
|
def subset_sum(s, a):
n = len(a)
dp = [[False for x in range(s + 1)] for x in range(n + 1)]
for i in range(n):
v = a[i]
for j in range(s + 1):
if v == j:
dp[i + 1][j] = True
elif v > j:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = dp[i][j] or dp[i][j - v]
return dp[n][s]
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
m = list(map(int, input().split()))
for i in range(q):
if subset_sum(m[i], a) == True:
print("yes")
else:
print("no")
| false | 14.814815 |
[
"- dict = {}",
"- return subset_rec(0, s, a, dict)",
"-",
"-",
"-def subset_rec(i, s, a, dict):",
"- key = str(i) + \"-\" + str(s)",
"- if key in dict:",
"- ret = dict[key]",
"- elif s == 0:",
"- ret = True",
"- elif i >= len(a):",
"- ret = False",
"- else:",
"- ret = subset_rec(i + 1, s - a[i], a, dict) or subset_rec(i + 1, s, a, dict)",
"- dict[key] = ret",
"- return ret",
"+ n = len(a)",
"+ dp = [[False for x in range(s + 1)] for x in range(n + 1)]",
"+ for i in range(n):",
"+ v = a[i]",
"+ for j in range(s + 1):",
"+ if v == j:",
"+ dp[i + 1][j] = True",
"+ elif v > j:",
"+ dp[i + 1][j] = dp[i][j]",
"+ else:",
"+ dp[i + 1][j] = dp[i][j] or dp[i][j - v]",
"+ return dp[n][s]",
"-p = int(eval(input()))",
"-q = list(map(int, input().split()))",
"-for i in range(p):",
"- if subset_sum(q[i], a):",
"+q = int(eval(input()))",
"+m = list(map(int, input().split()))",
"+for i in range(q):",
"+ if subset_sum(m[i], a) == True:"
] | false | 0.037458 | 0.036035 | 1.039493 |
[
"s682320952",
"s519358532"
] |
u285891772
|
p03053
|
python
|
s202123457
|
s774130440
| 339 | 274 | 120,432 | 114,676 |
Accepted
|
Accepted
| 19.17 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
H, W = MAP()
A = [eval(input()) for _ in range(H)]
cnt = [[0]*W for _ in range(H)]
q = deque()
for y in range(H):
for x in range(W):
if A[y][x] == "#":
q.append((y, x))
dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]
while q:
y, x = q.popleft()
for Dy, Dx in zip(dy, dx):
ny = y + Dy
nx = x + Dx
if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == 0 and A[ny][nx] == ".":
cnt[ny][nx] = cnt[y][x] + 1
q.append((ny, nx))
ans = 0
for i in range(H):
ans = max(ans, max(cnt[i]))
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
H, W = MAP()
A = [eval(input()) for _ in range(H)]
cnt = [[-1]*W for _ in range(H)]
q = deque()
for y in range(H):
for x in range(W):
if A[y][x] == "#":
cnt[y][x] = 0
q.append((y, x))
dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]
while q:
y, x = q.popleft()
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == -1:
cnt[ny][nx] = cnt[y][x] + 1
q.append((ny, nx))
ans = 0
for i in range(H):
ans = max(ans, max(cnt[i]))
print(ans)
| 47 | 48 | 1,474 | 1,481 |
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
from decimal import *
H, W = MAP()
A = [eval(input()) for _ in range(H)]
cnt = [[0] * W for _ in range(H)]
q = deque()
for y in range(H):
for x in range(W):
if A[y][x] == "#":
q.append((y, x))
dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]
while q:
y, x = q.popleft()
for Dy, Dx in zip(dy, dx):
ny = y + Dy
nx = x + Dx
if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == 0 and A[ny][nx] == ".":
cnt[ny][nx] = cnt[y][x] + 1
q.append((ny, nx))
ans = 0
for i in range(H):
ans = max(ans, max(cnt[i]))
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
from decimal import *
H, W = MAP()
A = [eval(input()) for _ in range(H)]
cnt = [[-1] * W for _ in range(H)]
q = deque()
for y in range(H):
for x in range(W):
if A[y][x] == "#":
cnt[y][x] = 0
q.append((y, x))
dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]
while q:
y, x = q.popleft()
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == -1:
cnt[ny][nx] = cnt[y][x] + 1
q.append((ny, nx))
ans = 0
for i in range(H):
ans = max(ans, max(cnt[i]))
print(ans)
| false | 2.083333 |
[
"-cnt = [[0] * W for _ in range(H)]",
"+cnt = [[-1] * W for _ in range(H)]",
"+ cnt[y][x] = 0",
"- for Dy, Dx in zip(dy, dx):",
"- ny = y + Dy",
"- nx = x + Dx",
"- if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == 0 and A[ny][nx] == \".\":",
"+ for i in range(4):",
"+ ny = y + dy[i]",
"+ nx = x + dx[i]",
"+ if 0 <= ny < H and 0 <= nx < W and cnt[ny][nx] == -1:"
] | false | 0.047908 | 0.048064 | 0.996754 |
[
"s202123457",
"s774130440"
] |
u562935282
|
p02850
|
python
|
s832513981
|
s791740501
| 516 | 469 | 86,304 | 54,180 |
Accepted
|
Accepted
| 9.11 |
def solve():
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
g = tuple(set() for _ in range(n))
for idx in range(n - 1):
a, b = (int(x) - 1 for x in input().split())
g[a].add((b, idx))
g[b].add((a, idx))
q = deque()
q.append((0, -1, -1))
e = [-1] * n # e[-1]は使わない
used = [False] * n
used[0] = True
while q:
v, v_idx, prev_color = q.popleft()
curr = 1 if prev_color != 1 else 2
for u, u_idx in g[v]:
if used[u]:
continue
used[u] = True
e[u_idx] = curr
q.append((u, u_idx, curr))
curr += 1
if curr == prev_color:
curr += 1
ret = e[:-1]
return len(set(ret)), ret
l, ret = solve()
print(l)
print(*ret, sep='\n')
|
def main():
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
g = tuple(set() for _ in range(N))
for i in range(N - 1):
a, b = (int(x) - 1 for x in input().split())
g[a].add((b, i))
g[b].add((a, i))
dq = deque()
dq.append([0, -1])
color = [-1] * (N - 1)
while dq:
v, skip = dq.popleft()
color_to_use = 1
for u, i in g[v]:
if ~color[i]: continue
if color_to_use == skip:
color_to_use += 1
color[i] = color_to_use
dq.append((u, color_to_use))
color_to_use += 1
print(max(color))
print(*color, sep='\n')
if __name__ == '__main__':
main()
| 40 | 33 | 901 | 784 |
def solve():
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
g = tuple(set() for _ in range(n))
for idx in range(n - 1):
a, b = (int(x) - 1 for x in input().split())
g[a].add((b, idx))
g[b].add((a, idx))
q = deque()
q.append((0, -1, -1))
e = [-1] * n # e[-1]は使わない
used = [False] * n
used[0] = True
while q:
v, v_idx, prev_color = q.popleft()
curr = 1 if prev_color != 1 else 2
for u, u_idx in g[v]:
if used[u]:
continue
used[u] = True
e[u_idx] = curr
q.append((u, u_idx, curr))
curr += 1
if curr == prev_color:
curr += 1
ret = e[:-1]
return len(set(ret)), ret
l, ret = solve()
print(l)
print(*ret, sep="\n")
|
def main():
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
g = tuple(set() for _ in range(N))
for i in range(N - 1):
a, b = (int(x) - 1 for x in input().split())
g[a].add((b, i))
g[b].add((a, i))
dq = deque()
dq.append([0, -1])
color = [-1] * (N - 1)
while dq:
v, skip = dq.popleft()
color_to_use = 1
for u, i in g[v]:
if ~color[i]:
continue
if color_to_use == skip:
color_to_use += 1
color[i] = color_to_use
dq.append((u, color_to_use))
color_to_use += 1
print(max(color))
print(*color, sep="\n")
if __name__ == "__main__":
main()
| false | 17.5 |
[
"-def solve():",
"+def main():",
"- n = int(input())",
"- g = tuple(set() for _ in range(n))",
"- for idx in range(n - 1):",
"+ N = int(input())",
"+ g = tuple(set() for _ in range(N))",
"+ for i in range(N - 1):",
"- g[a].add((b, idx))",
"- g[b].add((a, idx))",
"- q = deque()",
"- q.append((0, -1, -1))",
"- e = [-1] * n # e[-1]は使わない",
"- used = [False] * n",
"- used[0] = True",
"- while q:",
"- v, v_idx, prev_color = q.popleft()",
"- curr = 1 if prev_color != 1 else 2",
"- for u, u_idx in g[v]:",
"- if used[u]:",
"+ g[a].add((b, i))",
"+ g[b].add((a, i))",
"+ dq = deque()",
"+ dq.append([0, -1])",
"+ color = [-1] * (N - 1)",
"+ while dq:",
"+ v, skip = dq.popleft()",
"+ color_to_use = 1",
"+ for u, i in g[v]:",
"+ if ~color[i]:",
"- used[u] = True",
"- e[u_idx] = curr",
"- q.append((u, u_idx, curr))",
"- curr += 1",
"- if curr == prev_color:",
"- curr += 1",
"- ret = e[:-1]",
"- return len(set(ret)), ret",
"+ if color_to_use == skip:",
"+ color_to_use += 1",
"+ color[i] = color_to_use",
"+ dq.append((u, color_to_use))",
"+ color_to_use += 1",
"+ print(max(color))",
"+ print(*color, sep=\"\\n\")",
"-l, ret = solve()",
"-print(l)",
"-print(*ret, sep=\"\\n\")",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.040232 | 0.112212 | 0.35854 |
[
"s832513981",
"s791740501"
] |
u361826811
|
p02911
|
python
|
s868757376
|
s396001059
| 401 | 92 | 21,464 | 12,392 |
Accepted
|
Accepted
| 77.06 |
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = map(int, read().split())
point = np.zeros(N+1)
for i in A:
point[i] += 1
point += K - Q
print(*['Yes' if i > 0 else 'No' for i in point[1:]], sep='\n')
|
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = map(int, read().split())
point =[K-Q]*(N+1)
for i in A:
point[i] += 1
print(*['Yes' if i > 0 else 'No' for i in point[1:]], sep='\n')
| 19 | 18 | 374 | 357 |
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = map(int, read().split())
point = np.zeros(N + 1)
for i in A:
point[i] += 1
point += K - Q
print(*["Yes" if i > 0 else "No" for i in point[1:]], sep="\n")
|
"""
author : halo2halo
date : 4, Feb, 2020
"""
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, Q, *A = map(int, read().split())
point = [K - Q] * (N + 1)
for i in A:
point[i] += 1
print(*["Yes" if i > 0 else "No" for i in point[1:]], sep="\n")
| false | 5.263158 |
[
"-import numpy as np",
"+# import numpy as np",
"-point = np.zeros(N + 1)",
"+point = [K - Q] * (N + 1)",
"-point += K - Q"
] | false | 0.449894 | 0.038786 | 11.599466 |
[
"s868757376",
"s396001059"
] |
u130900604
|
p02720
|
python
|
s140749731
|
s124797873
| 321 | 140 | 29,176 | 16,120 |
Accepted
|
Accepted
| 56.39 |
# coding: utf-8
# Your code here!
from collections import deque
k=int(eval(input()))
ans=[]
d=deque([1,2,3,4,5,6,7,8,9])
c=0
while c<11:
q=d.popleft()
ans.append(q)
c=len(str(q))
b=q%10
if b!=0:
d.append(q*10+b-1)
d.append(q*10+b)
if b!=9:
d.append(q*10+b+1)
print((ans[k-1]))
|
# coding: utf-8
# Your code here!
from collections import deque
k=int(eval(input()))
ans=[]
d=deque([1,2,3,4,5,6,7,8,9])
c=0
while c<100100:
q=d.popleft()
ans.append(q)
c+=1
b=q%10
if b!=0:
d.append(q*10+b-1)
d.append(q*10+b)
if b!=9:
d.append(q*10+b+1)
print((ans[k-1]))
| 19 | 19 | 335 | 330 |
# coding: utf-8
# Your code here!
from collections import deque
k = int(eval(input()))
ans = []
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
c = 0
while c < 11:
q = d.popleft()
ans.append(q)
c = len(str(q))
b = q % 10
if b != 0:
d.append(q * 10 + b - 1)
d.append(q * 10 + b)
if b != 9:
d.append(q * 10 + b + 1)
print((ans[k - 1]))
|
# coding: utf-8
# Your code here!
from collections import deque
k = int(eval(input()))
ans = []
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
c = 0
while c < 100100:
q = d.popleft()
ans.append(q)
c += 1
b = q % 10
if b != 0:
d.append(q * 10 + b - 1)
d.append(q * 10 + b)
if b != 9:
d.append(q * 10 + b + 1)
print((ans[k - 1]))
| false | 0 |
[
"-while c < 11:",
"+while c < 100100:",
"- c = len(str(q))",
"+ c += 1"
] | false | 1.330709 | 0.283419 | 4.6952 |
[
"s140749731",
"s124797873"
] |
u094191970
|
p02661
|
python
|
s758988058
|
s462792744
| 467 | 278 | 26,976 | 25,364 |
Accepted
|
Accepted
| 40.47 |
n=int(eval(input()))
s=[]
e=[]
for i in range(n):
a,b=list(map(int,input().split()))
s.append(a)
e.append(b)
s=sorted(s)
e=sorted(e,reverse=True)
x=n//2
if n%2==1:
ans=(e[x]-s[x]+1)
else:
ts=(s[x]+s[x-1])/2
te=(e[x]+e[x-1])/2
ans=(te-ts)//0.5+1
print((int(ans)))
|
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(eval(input()))
l1=[]
l2=[]
for i in range(n):
a,b=nii()
l1.append(a)
l2.append(b)
l1.sort()
l2.sort()
if n%2==1:
ans=l2[n//2]-l1[n//2]
else:
m1=(l2[n//2]+l2[n//2-1])
m2=(l1[n//2]+l1[n//2-1])
ans=m1-m2
print((ans+1))
| 22 | 23 | 288 | 372 |
n = int(eval(input()))
s = []
e = []
for i in range(n):
a, b = list(map(int, input().split()))
s.append(a)
e.append(b)
s = sorted(s)
e = sorted(e, reverse=True)
x = n // 2
if n % 2 == 1:
ans = e[x] - s[x] + 1
else:
ts = (s[x] + s[x - 1]) / 2
te = (e[x] + e[x - 1]) / 2
ans = (te - ts) // 0.5 + 1
print((int(ans)))
|
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n = int(eval(input()))
l1 = []
l2 = []
for i in range(n):
a, b = nii()
l1.append(a)
l2.append(b)
l1.sort()
l2.sort()
if n % 2 == 1:
ans = l2[n // 2] - l1[n // 2]
else:
m1 = l2[n // 2] + l2[n // 2 - 1]
m2 = l1[n // 2] + l1[n // 2 - 1]
ans = m1 - m2
print((ans + 1))
| false | 4.347826 |
[
"+from sys import stdin",
"+",
"+nii = lambda: list(map(int, stdin.readline().split()))",
"+lnii = lambda: list(map(int, stdin.readline().split()))",
"-s = []",
"-e = []",
"+l1 = []",
"+l2 = []",
"- a, b = list(map(int, input().split()))",
"- s.append(a)",
"- e.append(b)",
"-s = sorted(s)",
"-e = sorted(e, reverse=True)",
"-x = n // 2",
"+ a, b = nii()",
"+ l1.append(a)",
"+ l2.append(b)",
"+l1.sort()",
"+l2.sort()",
"- ans = e[x] - s[x] + 1",
"+ ans = l2[n // 2] - l1[n // 2]",
"- ts = (s[x] + s[x - 1]) / 2",
"- te = (e[x] + e[x - 1]) / 2",
"- ans = (te - ts) // 0.5 + 1",
"-print((int(ans)))",
"+ m1 = l2[n // 2] + l2[n // 2 - 1]",
"+ m2 = l1[n // 2] + l1[n // 2 - 1]",
"+ ans = m1 - m2",
"+print((ans + 1))"
] | false | 0.038307 | 0.035606 | 1.075869 |
[
"s758988058",
"s462792744"
] |
u452269253
|
p02802
|
python
|
s718222743
|
s729644548
| 581 | 281 | 51,288 | 5,528 |
Accepted
|
Accepted
| 51.64 |
n, m = [int(i) for i in input().split()]
wa = [0]*n
ac = [0]*n
for _ in range(m):
p, s = input().split()
if s == "WA":
if ac[int(p)-1] == 0:
wa[int(p)-1] += 1
else:
ac[int(p)-1] += 1
print((n-ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1])))
|
def main():
n, m = [int(i) for i in input().split()]
wa = [0]*n
ac = [0]*n
for _ in range(m):
p, s = input().split()
if s == "WA":
if ac[int(p)-1] == 0:
wa[int(p)-1] += 1
else:
ac[int(p)-1] += 1
print((n-ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1])))
if __name__ == "__main__":
main()
| 13 | 18 | 304 | 412 |
n, m = [int(i) for i in input().split()]
wa = [0] * n
ac = [0] * n
for _ in range(m):
p, s = input().split()
if s == "WA":
if ac[int(p) - 1] == 0:
wa[int(p) - 1] += 1
else:
ac[int(p) - 1] += 1
print((n - ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1])))
|
def main():
n, m = [int(i) for i in input().split()]
wa = [0] * n
ac = [0] * n
for _ in range(m):
p, s = input().split()
if s == "WA":
if ac[int(p) - 1] == 0:
wa[int(p) - 1] += 1
else:
ac[int(p) - 1] += 1
print((n - ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1])))
if __name__ == "__main__":
main()
| false | 27.777778 |
[
"-n, m = [int(i) for i in input().split()]",
"-wa = [0] * n",
"-ac = [0] * n",
"-for _ in range(m):",
"- p, s = input().split()",
"- if s == \"WA\":",
"- if ac[int(p) - 1] == 0:",
"- wa[int(p) - 1] += 1",
"- else:",
"- ac[int(p) - 1] += 1",
"-print((n - ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1])))",
"+def main():",
"+ n, m = [int(i) for i in input().split()]",
"+ wa = [0] * n",
"+ ac = [0] * n",
"+ for _ in range(m):",
"+ p, s = input().split()",
"+ if s == \"WA\":",
"+ if ac[int(p) - 1] == 0:",
"+ wa[int(p) - 1] += 1",
"+ else:",
"+ ac[int(p) - 1] += 1",
"+ print((n - ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037795 | 0.078062 | 0.484174 |
[
"s718222743",
"s729644548"
] |
u891635666
|
p03475
|
python
|
s128591433
|
s140962599
| 133 | 103 | 3,188 | 3,188 |
Accepted
|
Accepted
| 22.56 |
n = int(eval(input()))
cs, ss, fs = [], [], []
for _ in range(n - 1):
c, s, f = list(map(int, input().split()))
cs.append(c)
ss.append(s)
fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)
res = []
for i in range(n - 1):
arrives = [0]
lefts = [ss[i]]
for j in range(i, n - 1):
a = lefts[-1] + cs[j]
arrives.append(a)
ns = ss[j + 1]
if a > ss[j + 1]:
nf = fs[j + 1]
w = (nf - (a - ns) % nf) % nf
lefts.append(a + w)
else:
lefts.append(ns)
res.append(arrives[-1])
res.append(0)
for x in res:
print(x)
|
n = int(eval(input()))
cs, ss, fs = [], [], []
for _ in range(n - 1):
c, s, f = list(map(int, input().split()))
cs.append(c)
ss.append(s)
fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)
res = []
for i in range(n - 1):
t = 0
for j in range(i, n - 1):
s = ss[j]
f = fs[j]
if t < s:
t = s
elif t % f > 0:
t += f - t % f
t += cs[j]
res.append(t)
res.append(0)
for x in res:
print(x)
| 29 | 26 | 640 | 492 |
n = int(eval(input()))
cs, ss, fs = [], [], []
for _ in range(n - 1):
c, s, f = list(map(int, input().split()))
cs.append(c)
ss.append(s)
fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)
res = []
for i in range(n - 1):
arrives = [0]
lefts = [ss[i]]
for j in range(i, n - 1):
a = lefts[-1] + cs[j]
arrives.append(a)
ns = ss[j + 1]
if a > ss[j + 1]:
nf = fs[j + 1]
w = (nf - (a - ns) % nf) % nf
lefts.append(a + w)
else:
lefts.append(ns)
res.append(arrives[-1])
res.append(0)
for x in res:
print(x)
|
n = int(eval(input()))
cs, ss, fs = [], [], []
for _ in range(n - 1):
c, s, f = list(map(int, input().split()))
cs.append(c)
ss.append(s)
fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)
res = []
for i in range(n - 1):
t = 0
for j in range(i, n - 1):
s = ss[j]
f = fs[j]
if t < s:
t = s
elif t % f > 0:
t += f - t % f
t += cs[j]
res.append(t)
res.append(0)
for x in res:
print(x)
| false | 10.344828 |
[
"- arrives = [0]",
"- lefts = [ss[i]]",
"+ t = 0",
"- a = lefts[-1] + cs[j]",
"- arrives.append(a)",
"- ns = ss[j + 1]",
"- if a > ss[j + 1]:",
"- nf = fs[j + 1]",
"- w = (nf - (a - ns) % nf) % nf",
"- lefts.append(a + w)",
"- else:",
"- lefts.append(ns)",
"- res.append(arrives[-1])",
"+ s = ss[j]",
"+ f = fs[j]",
"+ if t < s:",
"+ t = s",
"+ elif t % f > 0:",
"+ t += f - t % f",
"+ t += cs[j]",
"+ res.append(t)"
] | false | 0.050052 | 0.048991 | 1.021655 |
[
"s128591433",
"s140962599"
] |
u707808519
|
p02842
|
python
|
s776834050
|
s381487011
| 32 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 46.88 |
import sys
N = int(eval(input()))
for i in range(N+1):
a = int(i * 1.08)
if N == a:
print(i)
sys.exit()
print(':(')
|
import math
n = int(eval(input()))
a = math.ceil(n/1.08)
if int(a*1.08) == n:
print(a)
else:
print(':(')
| 8 | 7 | 140 | 112 |
import sys
N = int(eval(input()))
for i in range(N + 1):
a = int(i * 1.08)
if N == a:
print(i)
sys.exit()
print(":(")
|
import math
n = int(eval(input()))
a = math.ceil(n / 1.08)
if int(a * 1.08) == n:
print(a)
else:
print(":(")
| false | 12.5 |
[
"-import sys",
"+import math",
"-N = int(eval(input()))",
"-for i in range(N + 1):",
"- a = int(i * 1.08)",
"- if N == a:",
"- print(i)",
"- sys.exit()",
"-print(\":(\")",
"+n = int(eval(input()))",
"+a = math.ceil(n / 1.08)",
"+if int(a * 1.08) == n:",
"+ print(a)",
"+else:",
"+ print(\":(\")"
] | false | 0.061422 | 0.042397 | 1.448735 |
[
"s776834050",
"s381487011"
] |
u770018088
|
p02547
|
python
|
s883195576
|
s635481518
| 30 | 27 | 9,188 | 9,192 |
Accepted
|
Accepted
| 10 |
it = lambda: list(map(int, input().strip().split()))
def solve():
n = int(eval(input()))
ok = False
cnt = 0
for _ in range(n):
a, b = it()
if a == b:
cnt += 1
if cnt == 3:
ok = True
else:
cnt = 0
return 'Yes' if ok else 'No'
if __name__ == '__main__':
print((solve()))
|
it = lambda: list(map(int, input().strip().split()))
def solve():
n = int(eval(input()))
F = [0] * n
S = [0] * n
for i in range(n):
a, b = it()
F[i] = a
S[i] = b
cnt = 0
for i in range(n):
if F[i] == S[i]:
cnt += 1
if cnt == 3:
return 'Yes'
else:
cnt = 0
return 'No'
if __name__ == '__main__':
print((solve()))
| 19 | 25 | 381 | 459 |
it = lambda: list(map(int, input().strip().split()))
def solve():
n = int(eval(input()))
ok = False
cnt = 0
for _ in range(n):
a, b = it()
if a == b:
cnt += 1
if cnt == 3:
ok = True
else:
cnt = 0
return "Yes" if ok else "No"
if __name__ == "__main__":
print((solve()))
|
it = lambda: list(map(int, input().strip().split()))
def solve():
n = int(eval(input()))
F = [0] * n
S = [0] * n
for i in range(n):
a, b = it()
F[i] = a
S[i] = b
cnt = 0
for i in range(n):
if F[i] == S[i]:
cnt += 1
if cnt == 3:
return "Yes"
else:
cnt = 0
return "No"
if __name__ == "__main__":
print((solve()))
| false | 24 |
[
"- ok = False",
"+ F = [0] * n",
"+ S = [0] * n",
"+ for i in range(n):",
"+ a, b = it()",
"+ F[i] = a",
"+ S[i] = b",
"- for _ in range(n):",
"- a, b = it()",
"- if a == b:",
"+ for i in range(n):",
"+ if F[i] == S[i]:",
"- ok = True",
"+ return \"Yes\"",
"- return \"Yes\" if ok else \"No\"",
"+ return \"No\""
] | false | 0.048824 | 0.045413 | 1.075114 |
[
"s883195576",
"s635481518"
] |
u729133443
|
p03075
|
python
|
s734370034
|
s025626296
| 168 | 17 | 38,560 | 3,060 |
Accepted
|
Accepted
| 89.88 |
a,*_,e,k=eval('int(input()),'*6);print((':('*(e-a>k)or'Yay!'))
|
a,*_,e,k=eval('int(input()),'*6);print(('Y:a(y !'[e-a>k::2]))
| 1 | 1 | 60 | 59 |
a, *_, e, k = eval("int(input())," * 6)
print((":(" * (e - a > k) or "Yay!"))
|
a, *_, e, k = eval("int(input())," * 6)
print(("Y:a(y !"[e - a > k :: 2]))
| false | 0 |
[
"-print((\":(\" * (e - a > k) or \"Yay!\"))",
"+print((\"Y:a(y !\"[e - a > k :: 2]))"
] | false | 0.07796 | 0.03963 | 1.967183 |
[
"s734370034",
"s025626296"
] |
u843175622
|
p03291
|
python
|
s825743811
|
s366549637
| 416 | 244 | 27,596 | 9,280 |
Accepted
|
Accepted
| 41.35 |
MOD = pow(10, 9) + 7
s = eval(input())
n = len(s)
dp = [[0 for _ in range(4)] for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
dp[i+1][0] = dp[i][0]
dp[i+1][1] = dp[i][1]
dp[i+1][2] = dp[i][2]
dp[i+1][3] = dp[i][3]
if s[i] == 'A':
dp[i+1][1] += dp[i][0]
elif s[i] == 'B':
dp[i+1][2] += dp[i][1]
elif s[i] == 'C':
dp[i+1][3] += dp[i][2]
else:
dp[i+1][0] = dp[i][0] * 3
dp[i+1][1] = dp[i][1] * 3
dp[i+1][2] = dp[i][2] * 3
dp[i+1][3] = dp[i][3] * 3
dp[i+1][1] += dp[i][0]
dp[i+1][2] += dp[i][1]
dp[i+1][3] += dp[i][2]
dp[i+1][0] %= MOD
dp[i+1][1] %= MOD
dp[i+1][2] %= MOD
dp[i+1][3] %= MOD
print((dp[n][3]))
|
s = input().rstrip()
n = len(s)
mod = 10**9 + 7
dp = [0] * 4
dp[0] = 1
for i in range(n):
next = [0] * 4
if s[i] == 'A':
next[1] += dp[0]
elif s[i] == 'B':
next[2] += dp[1]
elif s[i] == 'C':
next[3] += dp[2]
else:
next[1] += dp[0]
next[2] += dp[1]
next[3] += dp[2]
next[0] += dp[0] * 2
next[1] += dp[1] * 2
next[2] += dp[2] * 2
next[3] += dp[3] * 2
next[0] += dp[0]
next[1] += dp[1]
next[2] += dp[2]
next[3] += dp[3]
for j in range(4):
next[j] %= mod
dp = next
print((dp[3]))
| 31 | 31 | 763 | 638 |
MOD = pow(10, 9) + 7
s = eval(input())
n = len(s)
dp = [[0 for _ in range(4)] for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
dp[i + 1][0] = dp[i][0]
dp[i + 1][1] = dp[i][1]
dp[i + 1][2] = dp[i][2]
dp[i + 1][3] = dp[i][3]
if s[i] == "A":
dp[i + 1][1] += dp[i][0]
elif s[i] == "B":
dp[i + 1][2] += dp[i][1]
elif s[i] == "C":
dp[i + 1][3] += dp[i][2]
else:
dp[i + 1][0] = dp[i][0] * 3
dp[i + 1][1] = dp[i][1] * 3
dp[i + 1][2] = dp[i][2] * 3
dp[i + 1][3] = dp[i][3] * 3
dp[i + 1][1] += dp[i][0]
dp[i + 1][2] += dp[i][1]
dp[i + 1][3] += dp[i][2]
dp[i + 1][0] %= MOD
dp[i + 1][1] %= MOD
dp[i + 1][2] %= MOD
dp[i + 1][3] %= MOD
print((dp[n][3]))
|
s = input().rstrip()
n = len(s)
mod = 10**9 + 7
dp = [0] * 4
dp[0] = 1
for i in range(n):
next = [0] * 4
if s[i] == "A":
next[1] += dp[0]
elif s[i] == "B":
next[2] += dp[1]
elif s[i] == "C":
next[3] += dp[2]
else:
next[1] += dp[0]
next[2] += dp[1]
next[3] += dp[2]
next[0] += dp[0] * 2
next[1] += dp[1] * 2
next[2] += dp[2] * 2
next[3] += dp[3] * 2
next[0] += dp[0]
next[1] += dp[1]
next[2] += dp[2]
next[3] += dp[3]
for j in range(4):
next[j] %= mod
dp = next
print((dp[3]))
| false | 0 |
[
"-MOD = pow(10, 9) + 7",
"-s = eval(input())",
"+s = input().rstrip()",
"-dp = [[0 for _ in range(4)] for _ in range(n + 1)]",
"-dp[0][0] = 1",
"+mod = 10**9 + 7",
"+dp = [0] * 4",
"+dp[0] = 1",
"- dp[i + 1][0] = dp[i][0]",
"- dp[i + 1][1] = dp[i][1]",
"- dp[i + 1][2] = dp[i][2]",
"- dp[i + 1][3] = dp[i][3]",
"+ next = [0] * 4",
"- dp[i + 1][1] += dp[i][0]",
"+ next[1] += dp[0]",
"- dp[i + 1][2] += dp[i][1]",
"+ next[2] += dp[1]",
"- dp[i + 1][3] += dp[i][2]",
"+ next[3] += dp[2]",
"- dp[i + 1][0] = dp[i][0] * 3",
"- dp[i + 1][1] = dp[i][1] * 3",
"- dp[i + 1][2] = dp[i][2] * 3",
"- dp[i + 1][3] = dp[i][3] * 3",
"- dp[i + 1][1] += dp[i][0]",
"- dp[i + 1][2] += dp[i][1]",
"- dp[i + 1][3] += dp[i][2]",
"- dp[i + 1][0] %= MOD",
"- dp[i + 1][1] %= MOD",
"- dp[i + 1][2] %= MOD",
"- dp[i + 1][3] %= MOD",
"-print((dp[n][3]))",
"+ next[1] += dp[0]",
"+ next[2] += dp[1]",
"+ next[3] += dp[2]",
"+ next[0] += dp[0] * 2",
"+ next[1] += dp[1] * 2",
"+ next[2] += dp[2] * 2",
"+ next[3] += dp[3] * 2",
"+ next[0] += dp[0]",
"+ next[1] += dp[1]",
"+ next[2] += dp[2]",
"+ next[3] += dp[3]",
"+ for j in range(4):",
"+ next[j] %= mod",
"+ dp = next",
"+print((dp[3]))"
] | false | 0.073282 | 0.037269 | 1.966302 |
[
"s825743811",
"s366549637"
] |
u334712262
|
p02669
|
python
|
s426408549
|
s465108028
| 941 | 798 | 116,556 | 111,148 |
Accepted
|
Accepted
| 15.2 |
# -*- coding: utf-8 -*-
from functools import lru_cache
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
# @mt
def slv(N, A, B, C, D):
@lru_cache(maxsize=None)
def f(n):
ans = n*D
for i in range(-min(2, n), min(3, n)):
m = n + i
i = abs(i)
if m == 0:
continue
if m % 5 == 0:
ans = min(ans, f(m//5) + C + D*i)
if m % 3 == 0:
ans = min(ans, f(m//3) + B + D*i)
if m % 2 == 0:
ans = min(ans, f(m//2) + A + D*i)
return ans
return f(N)
def main():
T = read_int()
for _ in range(T):
N, A, B, C ,D = read_int_n()
print(slv(N, A, B, C, D))
if __name__ == '__main__':
main()
|
# -*- coding: utf-8 -*-
from functools import lru_cache
import sys
# sys.setrecursionlimit(10)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
# @mt
def slv(N, A, B, C, D):
@lru_cache(maxsize=None)
def f(n):
if n == 1:
return D
if n == 0:
return 0
ans = n*D
i = (n // 2) * 2
ans = min(ans, f(i//2) + A + D*abs(n-i))
i = -(-n // 2) * 2
ans = min(ans, f(i//2) + A + D*abs(n-i))
i = (n // 3) * 3
ans = min(ans, f(i//3) + B + D*abs(n-i))
i = -(-n // 3) * 3
ans = min(ans, f(i//3) + B + D*abs(n-i))
i = (n // 5) * 5
ans = min(ans, f(i//5) + C + D*abs(n-i))
i = -(-n // 5) * 5
ans = min(ans, f(i//5) + C + D*abs(n-i))
return ans
return f(N)
def main():
T = read_int()
for _ in range(T):
N, A, B, C ,D = read_int_n()
print(slv(N, A, B, C, D))
if __name__ == '__main__':
main()
| 84 | 91 | 1,602 | 1,767 |
# -*- coding: utf-8 -*-
from functools import lru_cache
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
# @mt
def slv(N, A, B, C, D):
@lru_cache(maxsize=None)
def f(n):
ans = n * D
for i in range(-min(2, n), min(3, n)):
m = n + i
i = abs(i)
if m == 0:
continue
if m % 5 == 0:
ans = min(ans, f(m // 5) + C + D * i)
if m % 3 == 0:
ans = min(ans, f(m // 3) + B + D * i)
if m % 2 == 0:
ans = min(ans, f(m // 2) + A + D * i)
return ans
return f(N)
def main():
T = read_int()
for _ in range(T):
N, A, B, C, D = read_int_n()
print(slv(N, A, B, C, D))
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
from functools import lru_cache
import sys
# sys.setrecursionlimit(10)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
# @mt
def slv(N, A, B, C, D):
@lru_cache(maxsize=None)
def f(n):
if n == 1:
return D
if n == 0:
return 0
ans = n * D
i = (n // 2) * 2
ans = min(ans, f(i // 2) + A + D * abs(n - i))
i = -(-n // 2) * 2
ans = min(ans, f(i // 2) + A + D * abs(n - i))
i = (n // 3) * 3
ans = min(ans, f(i // 3) + B + D * abs(n - i))
i = -(-n // 3) * 3
ans = min(ans, f(i // 3) + B + D * abs(n - i))
i = (n // 5) * 5
ans = min(ans, f(i // 5) + C + D * abs(n - i))
i = -(-n // 5) * 5
ans = min(ans, f(i // 5) + C + D * abs(n - i))
return ans
return f(N)
def main():
T = read_int()
for _ in range(T):
N, A, B, C, D = read_int_n()
print(slv(N, A, B, C, D))
if __name__ == "__main__":
main()
| false | 7.692308 |
[
"-# sys.setrecursionlimit(10**6)",
"+# sys.setrecursionlimit(10)",
"+ if n == 1:",
"+ return D",
"+ if n == 0:",
"+ return 0",
"- for i in range(-min(2, n), min(3, n)):",
"- m = n + i",
"- i = abs(i)",
"- if m == 0:",
"- continue",
"- if m % 5 == 0:",
"- ans = min(ans, f(m // 5) + C + D * i)",
"- if m % 3 == 0:",
"- ans = min(ans, f(m // 3) + B + D * i)",
"- if m % 2 == 0:",
"- ans = min(ans, f(m // 2) + A + D * i)",
"+ i = (n // 2) * 2",
"+ ans = min(ans, f(i // 2) + A + D * abs(n - i))",
"+ i = -(-n // 2) * 2",
"+ ans = min(ans, f(i // 2) + A + D * abs(n - i))",
"+ i = (n // 3) * 3",
"+ ans = min(ans, f(i // 3) + B + D * abs(n - i))",
"+ i = -(-n // 3) * 3",
"+ ans = min(ans, f(i // 3) + B + D * abs(n - i))",
"+ i = (n // 5) * 5",
"+ ans = min(ans, f(i // 5) + C + D * abs(n - i))",
"+ i = -(-n // 5) * 5",
"+ ans = min(ans, f(i // 5) + C + D * abs(n - i))"
] | false | 0.600875 | 0.259313 | 2.317176 |
[
"s426408549",
"s465108028"
] |
u832039789
|
p03325
|
python
|
s473899075
|
s686498919
| 142 | 83 | 4,148 | 4,152 |
Accepted
|
Accepted
| 41.55 |
N = int(eval(input()))
a = list(map(int,input().split()))
result = 0
for i in a:
while True:
if i%2!=0:
break
else:
i/=2
result += 1
print(result)
|
n = int(eval(input()))
a = list(map(int,input().split()))
p = 0
for i in a:
cnt = 0
while i % 2 == 0:
cnt += 1
i //= 2
p += cnt
print(p)
| 11 | 10 | 164 | 168 |
N = int(eval(input()))
a = list(map(int, input().split()))
result = 0
for i in a:
while True:
if i % 2 != 0:
break
else:
i /= 2
result += 1
print(result)
|
n = int(eval(input()))
a = list(map(int, input().split()))
p = 0
for i in a:
cnt = 0
while i % 2 == 0:
cnt += 1
i //= 2
p += cnt
print(p)
| false | 9.090909 |
[
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-result = 0",
"+p = 0",
"- while True:",
"- if i % 2 != 0:",
"- break",
"- else:",
"- i /= 2",
"- result += 1",
"-print(result)",
"+ cnt = 0",
"+ while i % 2 == 0:",
"+ cnt += 1",
"+ i //= 2",
"+ p += cnt",
"+print(p)"
] | false | 0.069624 | 0.038486 | 1.809094 |
[
"s473899075",
"s686498919"
] |
u855710796
|
p02629
|
python
|
s673218686
|
s704794213
| 36 | 29 | 9,216 | 9,220 |
Accepted
|
Accepted
| 19.44 |
N = int(input())
s = []
a = 26
tmp = 1
for i in range(20):
s.append(tmp)
tmp += a
a *= 26
if tmp > 100000000000000000:
break
for i in range(len(s)):
if N >= s[i]:
continue
else:
size = i
break
b = N - s[size-1]
n2a = lambda c: chr(c+64)
a = 26 ** (size-1)
ans = []
while(a >= 1):
ans.append(n2a(b // a + 1).lower())
b %= a
a //= 26
print(*ans, sep="")
|
N = int(eval(input()))
N -= 1
d = 26
for i in range(1,15):
if N >= d:
N -= d
d *= 26
else:
d //= 26
ans = ""
for j in range(i):
ans += chr(N // d + ord("a"))
N %= d
d //= 26
break
print(ans)
| 31 | 18 | 456 | 295 |
N = int(input())
s = []
a = 26
tmp = 1
for i in range(20):
s.append(tmp)
tmp += a
a *= 26
if tmp > 100000000000000000:
break
for i in range(len(s)):
if N >= s[i]:
continue
else:
size = i
break
b = N - s[size - 1]
n2a = lambda c: chr(c + 64)
a = 26 ** (size - 1)
ans = []
while a >= 1:
ans.append(n2a(b // a + 1).lower())
b %= a
a //= 26
print(*ans, sep="")
|
N = int(eval(input()))
N -= 1
d = 26
for i in range(1, 15):
if N >= d:
N -= d
d *= 26
else:
d //= 26
ans = ""
for j in range(i):
ans += chr(N // d + ord("a"))
N %= d
d //= 26
break
print(ans)
| false | 41.935484 |
[
"-N = int(input())",
"-s = []",
"-a = 26",
"-tmp = 1",
"-for i in range(20):",
"- s.append(tmp)",
"- tmp += a",
"- a *= 26",
"- if tmp > 100000000000000000:",
"+N = int(eval(input()))",
"+N -= 1",
"+d = 26",
"+for i in range(1, 15):",
"+ if N >= d:",
"+ N -= d",
"+ d *= 26",
"+ else:",
"+ d //= 26",
"+ ans = \"\"",
"+ for j in range(i):",
"+ ans += chr(N // d + ord(\"a\"))",
"+ N %= d",
"+ d //= 26",
"-for i in range(len(s)):",
"- if N >= s[i]:",
"- continue",
"- else:",
"- size = i",
"- break",
"-b = N - s[size - 1]",
"-n2a = lambda c: chr(c + 64)",
"-a = 26 ** (size - 1)",
"-ans = []",
"-while a >= 1:",
"- ans.append(n2a(b // a + 1).lower())",
"- b %= a",
"- a //= 26",
"-print(*ans, sep=\"\")",
"+print(ans)"
] | false | 0.036705 | 0.03693 | 0.993902 |
[
"s673218686",
"s704794213"
] |
u392319141
|
p03018
|
python
|
s249570422
|
s924689977
| 103 | 56 | 5,224 | 3,500 |
Accepted
|
Accepted
| 45.63 |
S = eval(input())
S = S.replace('BC', 'D').replace('B', ' ').replace('C', ' ').split()
ans = 0
for s in S:
leftA = 0
for i, t in enumerate(s[:: -1]):
if t == 'A':
ans += max(0, i - leftA)
leftA += 1
print(ans)
|
S = eval(input())
S = S.replace('BC', 'D')
cnt = 0
ans = 0
for i, s in enumerate(S):
if s == 'D':
ans += cnt
elif s == 'A':
cnt += 1
else:
cnt = 0
print(ans)
| 12 | 13 | 256 | 201 |
S = eval(input())
S = S.replace("BC", "D").replace("B", " ").replace("C", " ").split()
ans = 0
for s in S:
leftA = 0
for i, t in enumerate(s[::-1]):
if t == "A":
ans += max(0, i - leftA)
leftA += 1
print(ans)
|
S = eval(input())
S = S.replace("BC", "D")
cnt = 0
ans = 0
for i, s in enumerate(S):
if s == "D":
ans += cnt
elif s == "A":
cnt += 1
else:
cnt = 0
print(ans)
| false | 7.692308 |
[
"-S = S.replace(\"BC\", \"D\").replace(\"B\", \" \").replace(\"C\", \" \").split()",
"+S = S.replace(\"BC\", \"D\")",
"+cnt = 0",
"-for s in S:",
"- leftA = 0",
"- for i, t in enumerate(s[::-1]):",
"- if t == \"A\":",
"- ans += max(0, i - leftA)",
"- leftA += 1",
"+for i, s in enumerate(S):",
"+ if s == \"D\":",
"+ ans += cnt",
"+ elif s == \"A\":",
"+ cnt += 1",
"+ else:",
"+ cnt = 0"
] | false | 0.046113 | 0.037747 | 1.221628 |
[
"s249570422",
"s924689977"
] |
u982594421
|
p02780
|
python
|
s816440206
|
s719592638
| 542 | 205 | 73,992 | 25,060 |
Accepted
|
Accepted
| 62.18 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
e = [sum(range(1, pi + 1)) / pi for pi in p]
tmp = 0
for i in range(n):
tmp += e[i]
if i >= k:
tmp -= e[i - k]
ans = max(ans, tmp)
print(ans)
|
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
e = [(pi + 1) / 2 for pi in p]
tmp = 0
for i in range(n):
tmp += e[i]
if i >= k:
tmp -= e[i - k]
ans = max(ans, tmp)
print(ans)
| 13 | 13 | 252 | 238 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
e = [sum(range(1, pi + 1)) / pi for pi in p]
tmp = 0
for i in range(n):
tmp += e[i]
if i >= k:
tmp -= e[i - k]
ans = max(ans, tmp)
print(ans)
|
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
e = [(pi + 1) / 2 for pi in p]
tmp = 0
for i in range(n):
tmp += e[i]
if i >= k:
tmp -= e[i - k]
ans = max(ans, tmp)
print(ans)
| false | 0 |
[
"-e = [sum(range(1, pi + 1)) / pi for pi in p]",
"+e = [(pi + 1) / 2 for pi in p]"
] | false | 0.036611 | 0.036592 | 1.000519 |
[
"s816440206",
"s719592638"
] |
u281610856
|
p03244
|
python
|
s377489657
|
s306482695
| 93 | 86 | 21,952 | 20,572 |
Accepted
|
Accepted
| 7.53 |
import collections
n = int(eval(input())) # even
v = list(map(int, input().split()))
e = v[0::2]
o = v[1::2]
e_cnt = collections.Counter(e)
o_cnt = collections.Counter(o)
e_most = e_cnt.most_common() + ([(0, 0)])
e_most1 = e_most[0][1]
e_most2 = e_most[1][1]
o_most = o_cnt.most_common() + ([(0, 0)])
o_most1 = o_most[0][1]
o_most2 = o_most[1][1]
if e_most[0][0] != o_most[0][0]:
print((n - e_most1 - o_most1))
else:
print((min(n - e_most1 - o_most2, n - e_most2 - o_most1)))
|
from collections import Counter
n = int(eval(input()))
v = list(map(int, input().split()))
odd_cnt = Counter(v[0::2]).most_common() + ([(0, 0)])
even_cnt = Counter(v[1::2]).most_common() + ([(0, 0)])
if odd_cnt[0][0] != even_cnt[0][0]:
ans = n - odd_cnt[0][1] - even_cnt[0][1]
else:
ans = min(n - odd_cnt[1][1] - even_cnt[0][1], n - odd_cnt[0][1] - even_cnt[1][1])
print(ans)
| 18 | 12 | 492 | 391 |
import collections
n = int(eval(input())) # even
v = list(map(int, input().split()))
e = v[0::2]
o = v[1::2]
e_cnt = collections.Counter(e)
o_cnt = collections.Counter(o)
e_most = e_cnt.most_common() + ([(0, 0)])
e_most1 = e_most[0][1]
e_most2 = e_most[1][1]
o_most = o_cnt.most_common() + ([(0, 0)])
o_most1 = o_most[0][1]
o_most2 = o_most[1][1]
if e_most[0][0] != o_most[0][0]:
print((n - e_most1 - o_most1))
else:
print((min(n - e_most1 - o_most2, n - e_most2 - o_most1)))
|
from collections import Counter
n = int(eval(input()))
v = list(map(int, input().split()))
odd_cnt = Counter(v[0::2]).most_common() + ([(0, 0)])
even_cnt = Counter(v[1::2]).most_common() + ([(0, 0)])
if odd_cnt[0][0] != even_cnt[0][0]:
ans = n - odd_cnt[0][1] - even_cnt[0][1]
else:
ans = min(n - odd_cnt[1][1] - even_cnt[0][1], n - odd_cnt[0][1] - even_cnt[1][1])
print(ans)
| false | 33.333333 |
[
"-import collections",
"+from collections import Counter",
"-n = int(eval(input())) # even",
"+n = int(eval(input()))",
"-e = v[0::2]",
"-o = v[1::2]",
"-e_cnt = collections.Counter(e)",
"-o_cnt = collections.Counter(o)",
"-e_most = e_cnt.most_common() + ([(0, 0)])",
"-e_most1 = e_most[0][1]",
"-e_most2 = e_most[1][1]",
"-o_most = o_cnt.most_common() + ([(0, 0)])",
"-o_most1 = o_most[0][1]",
"-o_most2 = o_most[1][1]",
"-if e_most[0][0] != o_most[0][0]:",
"- print((n - e_most1 - o_most1))",
"+odd_cnt = Counter(v[0::2]).most_common() + ([(0, 0)])",
"+even_cnt = Counter(v[1::2]).most_common() + ([(0, 0)])",
"+if odd_cnt[0][0] != even_cnt[0][0]:",
"+ ans = n - odd_cnt[0][1] - even_cnt[0][1]",
"- print((min(n - e_most1 - o_most2, n - e_most2 - o_most1)))",
"+ ans = min(n - odd_cnt[1][1] - even_cnt[0][1], n - odd_cnt[0][1] - even_cnt[1][1])",
"+print(ans)"
] | false | 0.070691 | 0.070991 | 0.995771 |
[
"s377489657",
"s306482695"
] |
u729133443
|
p04035
|
python
|
s079744716
|
s162109713
| 270 | 84 | 71,228 | 19,864 |
Accepted
|
Accepted
| 68.89 |
n,l,*a=list(map(int,open(0).read().split()))
i=m=0
for j,(x,y)in enumerate(zip(a,a[1:]),1):
if x+y>m:
m=x+y
i=j
if m<l:
print('Impossible')
else:
print('Possible')
print((*list(range(1,i))))
print((*list(range(n-1,i,-1))))
print(i)
|
n,l,*a=map(int,open(i:=0).read().split())
for a,b in zip(a,a[1:]):i+=1;a+b>=l>exit(print('Possible',*range(1,i),*range(n-1,i-1,-1)))
print('Impossible')
| 13 | 3 | 241 | 154 |
n, l, *a = list(map(int, open(0).read().split()))
i = m = 0
for j, (x, y) in enumerate(zip(a, a[1:]), 1):
if x + y > m:
m = x + y
i = j
if m < l:
print("Impossible")
else:
print("Possible")
print((*list(range(1, i))))
print((*list(range(n - 1, i, -1))))
print(i)
|
n, l, *a = map(int, open(i := 0).read().split())
for a, b in zip(a, a[1:]):
i += 1
a + b >= l > exit(print("Possible", *range(1, i), *range(n - 1, i - 1, -1)))
print("Impossible")
| false | 76.923077 |
[
"-n, l, *a = list(map(int, open(0).read().split()))",
"-i = m = 0",
"-for j, (x, y) in enumerate(zip(a, a[1:]), 1):",
"- if x + y > m:",
"- m = x + y",
"- i = j",
"-if m < l:",
"- print(\"Impossible\")",
"-else:",
"- print(\"Possible\")",
"- print((*list(range(1, i))))",
"- print((*list(range(n - 1, i, -1))))",
"- print(i)",
"+n, l, *a = map(int, open(i := 0).read().split())",
"+for a, b in zip(a, a[1:]):",
"+ i += 1",
"+ a + b >= l > exit(print(\"Possible\", *range(1, i), *range(n - 1, i - 1, -1)))",
"+print(\"Impossible\")"
] | false | 0.042992 | 0.03489 | 1.232231 |
[
"s079744716",
"s162109713"
] |
u863442865
|
p03487
|
python
|
s456054288
|
s650349880
| 115 | 77 | 21,228 | 18,676 |
Accepted
|
Accepted
| 33.04 |
from collections import Counter
from collections import deque
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
for num, cnt in c:
if cnt>=num:
ans += cnt - num
else:
ans += cnt
print(ans)
|
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for num, cnt in list(c.items()):
if cnt>=num:
ans += cnt - num
else:
ans += cnt
print(ans)
| 14 | 11 | 272 | 227 |
from collections import Counter
from collections import deque
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
for num, cnt in c:
if cnt >= num:
ans += cnt - num
else:
ans += cnt
print(ans)
|
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for num, cnt in list(c.items()):
if cnt >= num:
ans += cnt - num
else:
ans += cnt
print(ans)
| false | 21.428571 |
[
"-from collections import deque",
"-c = c.most_common()",
"-for num, cnt in c:",
"+for num, cnt in list(c.items()):"
] | false | 0.046788 | 0.04443 | 1.053083 |
[
"s456054288",
"s650349880"
] |
u687041133
|
p02837
|
python
|
s220192907
|
s046920555
| 1,295 | 110 | 8,820 | 8,820 |
Accepted
|
Accepted
| 91.51 |
import itertools
N = int(eval(input()))
all_list = list(itertools.product([0,1], repeat=N))
xy_list =[]
for i in range(N):
for j in range(int(eval(input()))):
x, y = list(map(int, input().split()))
xy_list.append((i+1,x,y))
#print(xy_list)
num_ok = 0
for i in all_list:
#どの人の証言なのか
flag = True
for j in xy_list:
if i[j[0]-1] == 1:
if i[j[1]-1] != j[2]:
flag = False
if flag == True:
if num_ok < i.count(1):
num_ok = i.count(1)
print(num_ok)
|
import itertools
N = int(eval(input()))
all_list = list(itertools.product([0,1], repeat=N))
xy_list =[]
for i in range(N):
for j in range(int(eval(input()))):
x, y = list(map(int, input().split()))
xy_list.append((i+1,x,y))
#print(xy_list)
num_ok = 0
for i in all_list:
#どの人の証言なのか
flag = True
for j in xy_list:
if i[j[0]-1] == 1:
if i[j[1]-1] != j[2]:
flag = False
break
if flag == True:
if num_ok < i.count(1):
num_ok = i.count(1)
print(num_ok)
| 30 | 36 | 560 | 605 |
import itertools
N = int(eval(input()))
all_list = list(itertools.product([0, 1], repeat=N))
xy_list = []
for i in range(N):
for j in range(int(eval(input()))):
x, y = list(map(int, input().split()))
xy_list.append((i + 1, x, y))
# print(xy_list)
num_ok = 0
for i in all_list:
# どの人の証言なのか
flag = True
for j in xy_list:
if i[j[0] - 1] == 1:
if i[j[1] - 1] != j[2]:
flag = False
if flag == True:
if num_ok < i.count(1):
num_ok = i.count(1)
print(num_ok)
|
import itertools
N = int(eval(input()))
all_list = list(itertools.product([0, 1], repeat=N))
xy_list = []
for i in range(N):
for j in range(int(eval(input()))):
x, y = list(map(int, input().split()))
xy_list.append((i + 1, x, y))
# print(xy_list)
num_ok = 0
for i in all_list:
# どの人の証言なのか
flag = True
for j in xy_list:
if i[j[0] - 1] == 1:
if i[j[1] - 1] != j[2]:
flag = False
break
if flag == True:
if num_ok < i.count(1):
num_ok = i.count(1)
print(num_ok)
| false | 16.666667 |
[
"+ break"
] | false | 0.111464 | 0.032459 | 3.43398 |
[
"s220192907",
"s046920555"
] |
u463655976
|
p03061
|
python
|
s996891262
|
s014625315
| 428 | 271 | 20,840 | 14,076 |
Accepted
|
Accepted
| 36.68 |
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
if x == 0 or y == 0:
return max(x, y)
if y == 0:
return x
return gcd(y, x % y)
param = [[0, 0, 0]]
addr = 0
while True:
if len(param) <= 0:
break
addr, Li, Lv = param.pop()
if addr == 0:
if Li == N-1:
Rv = 0
M, isCall = Lv, False
continue
param += [[1, Li, Lv], [0, Li+1, gcd(Lv, A[Li])]]
isCall = True
continue
elif addr == 1:
Rv = gcd(A[Li+1], Rv)
M, isCall = max(M, gcd(Lv, Rv)), False
continue
print(M)
|
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
if x == 0 or y == 0:
return max(x, y)
return gcd(y, x % y) if y!=0 else x
def F(init, add):
w = [0]
for i in range(init, init + add * N, add):
w += [gcd(w[-1], A[i])]
return w[:-1]
print((max(list(map(lambda x,y:gcd(x,y), F(0, 1), F(N-1, -1)[::-1])))))
| 30 | 15 | 664 | 366 |
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
if x == 0 or y == 0:
return max(x, y)
if y == 0:
return x
return gcd(y, x % y)
param = [[0, 0, 0]]
addr = 0
while True:
if len(param) <= 0:
break
addr, Li, Lv = param.pop()
if addr == 0:
if Li == N - 1:
Rv = 0
M, isCall = Lv, False
continue
param += [[1, Li, Lv], [0, Li + 1, gcd(Lv, A[Li])]]
isCall = True
continue
elif addr == 1:
Rv = gcd(A[Li + 1], Rv)
M, isCall = max(M, gcd(Lv, Rv)), False
continue
print(M)
|
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(x, y):
if x == 0 or y == 0:
return max(x, y)
return gcd(y, x % y) if y != 0 else x
def F(init, add):
w = [0]
for i in range(init, init + add * N, add):
w += [gcd(w[-1], A[i])]
return w[:-1]
print((max(list(map(lambda x, y: gcd(x, y), F(0, 1), F(N - 1, -1)[::-1])))))
| false | 50 |
[
"- if y == 0:",
"- return x",
"- return gcd(y, x % y)",
"+ return gcd(y, x % y) if y != 0 else x",
"-param = [[0, 0, 0]]",
"-addr = 0",
"-while True:",
"- if len(param) <= 0:",
"- break",
"- addr, Li, Lv = param.pop()",
"- if addr == 0:",
"- if Li == N - 1:",
"- Rv = 0",
"- M, isCall = Lv, False",
"- continue",
"- param += [[1, Li, Lv], [0, Li + 1, gcd(Lv, A[Li])]]",
"- isCall = True",
"- continue",
"- elif addr == 1:",
"- Rv = gcd(A[Li + 1], Rv)",
"- M, isCall = max(M, gcd(Lv, Rv)), False",
"- continue",
"-print(M)",
"+def F(init, add):",
"+ w = [0]",
"+ for i in range(init, init + add * N, add):",
"+ w += [gcd(w[-1], A[i])]",
"+ return w[:-1]",
"+",
"+",
"+print((max(list(map(lambda x, y: gcd(x, y), F(0, 1), F(N - 1, -1)[::-1])))))"
] | false | 0.037148 | 0.046792 | 0.7939 |
[
"s996891262",
"s014625315"
] |
u729133443
|
p03060
|
python
|
s075147711
|
s695097572
| 172 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 90.12 |
n,*t=list(map(int,open(0).read().split()));print((sum((x-y)*(x>y)for x,y in zip(t[:n],t[n:]))))
|
_,v,c=[list(map(int,t.split()))for t in open(0)];print((sum((x-y)*(x>y)for x,y in zip(v,c))))
| 1 | 1 | 87 | 85 |
n, *t = list(map(int, open(0).read().split()))
print((sum((x - y) * (x > y) for x, y in zip(t[:n], t[n:]))))
|
_, v, c = [list(map(int, t.split())) for t in open(0)]
print((sum((x - y) * (x > y) for x, y in zip(v, c))))
| false | 0 |
[
"-n, *t = list(map(int, open(0).read().split()))",
"-print((sum((x - y) * (x > y) for x, y in zip(t[:n], t[n:]))))",
"+_, v, c = [list(map(int, t.split())) for t in open(0)]",
"+print((sum((x - y) * (x > y) for x, y in zip(v, c))))"
] | false | 0.047375 | 0.040469 | 1.170653 |
[
"s075147711",
"s695097572"
] |
u119655368
|
p03805
|
python
|
s491740038
|
s609909644
| 132 | 46 | 8,052 | 3,572 |
Accepted
|
Accepted
| 65.15 |
import itertools
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
r = [[] for i in range(n + 1)]
ans = 0
for i in range(m):
r[l[i][0]].append(l[i][1])
r[l[i][1]].append(l[i][0])
p = []
for i in range(n):
p.append(i + 1)
p = list(itertools.permutations(p))
for i in range(len(p)):
check = True
t = list(p[i])
if t[0] != 1:
check = False
for j in range(len(t)-1):
if not t[j + 1] in r[t[j]]:
check = False
if check:
ans += 1
print(ans)
|
import itertools
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
r = [[] for i in range(n + 1)]
ans = 0
for i in range(m):
r[l[i][0]].append(l[i][1])
r[l[i][1]].append(l[i][0])
p = "2345678"[:n-1]
p = list(itertools.permutations(p))
for i in range(len(p)):
check = True
t = "1" + "".join(p[i])
for j in range(len(t)-1):
if not int(t[j + 1]) in r[int(t[j])]:
check = False
if check:
ans += 1
print(ans)
| 23 | 20 | 563 | 514 |
import itertools
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
r = [[] for i in range(n + 1)]
ans = 0
for i in range(m):
r[l[i][0]].append(l[i][1])
r[l[i][1]].append(l[i][0])
p = []
for i in range(n):
p.append(i + 1)
p = list(itertools.permutations(p))
for i in range(len(p)):
check = True
t = list(p[i])
if t[0] != 1:
check = False
for j in range(len(t) - 1):
if not t[j + 1] in r[t[j]]:
check = False
if check:
ans += 1
print(ans)
|
import itertools
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
r = [[] for i in range(n + 1)]
ans = 0
for i in range(m):
r[l[i][0]].append(l[i][1])
r[l[i][1]].append(l[i][0])
p = "2345678"[: n - 1]
p = list(itertools.permutations(p))
for i in range(len(p)):
check = True
t = "1" + "".join(p[i])
for j in range(len(t) - 1):
if not int(t[j + 1]) in r[int(t[j])]:
check = False
if check:
ans += 1
print(ans)
| false | 13.043478 |
[
"-p = []",
"-for i in range(n):",
"- p.append(i + 1)",
"+p = \"2345678\"[: n - 1]",
"- t = list(p[i])",
"- if t[0] != 1:",
"- check = False",
"+ t = \"1\" + \"\".join(p[i])",
"- if not t[j + 1] in r[t[j]]:",
"+ if not int(t[j + 1]) in r[int(t[j])]:"
] | false | 0.180909 | 0.07228 | 2.502892 |
[
"s491740038",
"s609909644"
] |
u086566114
|
p02411
|
python
|
s607256576
|
s192836039
| 20 | 10 | 6,332 | 6,364 |
Accepted
|
Accepted
| 50 |
def get_score(medium, final, retry):
medium_final = medium + final
if medium == -1 or final == -1:
return 'F'
elif 80 <= medium_final:
return 'A'
elif 65 <= medium_final:
return 'B'
elif 50 <= medium_final:
return 'C'
elif 30 <= medium_final:
if 50 <= retry:
return 'C'
else:
return 'D'
else:
return 'F'
while True:
[medium, final, retry] = [int(x) for x in input().split()]
if [medium, final, retry] == [-1, -1, -1]:
break
print((get_score(medium, final, retry)))
|
def get_score(medium, final, retry):
medium_final = medium + final
if medium == -1 or final == -1:
return 'F'
elif 80 <= medium_final:
return 'A'
elif 65 <= medium_final:
return 'B'
elif 50 <= medium_final:
return 'C'
elif 30 <= medium_final:
if 50 <= retry:
return 'C'
else:
return 'D'
else:
return 'F'
data = []
while True:
[medium, final, retry] = [int(x) for x in input().split()]
if [medium, final, retry] == [-1, -1, -1]:
break
data.append(get_score(medium, final, retry))
for n in data:
print(n)
| 25 | 28 | 621 | 668 |
def get_score(medium, final, retry):
medium_final = medium + final
if medium == -1 or final == -1:
return "F"
elif 80 <= medium_final:
return "A"
elif 65 <= medium_final:
return "B"
elif 50 <= medium_final:
return "C"
elif 30 <= medium_final:
if 50 <= retry:
return "C"
else:
return "D"
else:
return "F"
while True:
[medium, final, retry] = [int(x) for x in input().split()]
if [medium, final, retry] == [-1, -1, -1]:
break
print((get_score(medium, final, retry)))
|
def get_score(medium, final, retry):
medium_final = medium + final
if medium == -1 or final == -1:
return "F"
elif 80 <= medium_final:
return "A"
elif 65 <= medium_final:
return "B"
elif 50 <= medium_final:
return "C"
elif 30 <= medium_final:
if 50 <= retry:
return "C"
else:
return "D"
else:
return "F"
data = []
while True:
[medium, final, retry] = [int(x) for x in input().split()]
if [medium, final, retry] == [-1, -1, -1]:
break
data.append(get_score(medium, final, retry))
for n in data:
print(n)
| false | 10.714286 |
[
"+data = []",
"- print((get_score(medium, final, retry)))",
"+ data.append(get_score(medium, final, retry))",
"+for n in data:",
"+ print(n)"
] | false | 0.048855 | 0.192903 | 0.25326 |
[
"s607256576",
"s192836039"
] |
u326609687
|
p02551
|
python
|
s655802641
|
s045276700
| 534 | 399 | 114,096 | 33,432 |
Accepted
|
Accepted
| 25.28 |
import numpy as np
from numba import njit
from numba.types import int64
i8 = np.int64
@njit((int64, int64[:,::-1]), cache=True)
def solve(n, qr):
col = np.zeros(n - 1, i8)
col[0] = 0
col_min = n - 1
row = np.zeros(n - 1, i8)
row[0] = 0
row_min = n - 1
white = 0
for i in range(qr.shape[0]):
j = qr[i, 1] - 1
if qr[i, 0] == 1:
if j < col_min:
white += row_min - 1
for m in range(j + 1, col_min):
col[m] = row_min - 1
col_min = j
else:
white += col[j]
else:
if j < row_min:
white += col_min - 1
for m in range(j + 1, row_min):
row[m] = col_min - 1
row_min = j
else:
white += row[j]
return white
def main():
f = open(0)
n, q = [int(x) for x in f.readline().split()]
qr = np.fromstring(f.read(), i8, sep=' ').reshape((-1, 2))
white = solve(n, qr)
print(((n - 2) ** 2 - white))
main()
|
import numpy as np
# from numba import njit
# from numba.types import int64
i8 = np.int64
# @njit((int64, int64[:,::-1]), cache=True)
def solve(n, qr):
col = np.zeros(n - 1, i8)
col[0] = 0
col_min = n - 1
row = np.zeros(n - 1, i8)
row[0] = 0
row_min = n - 1
white = 0
for i in range(qr.shape[0]):
j = qr[i, 1] - 1
if qr[i, 0] == 1:
if j < col_min:
white += row_min - 1
for m in range(j + 1, col_min):
col[m] = row_min - 1
col_min = j
else:
white += col[j]
else:
if j < row_min:
white += col_min - 1
for m in range(j + 1, row_min):
row[m] = col_min - 1
row_min = j
else:
white += row[j]
return white
def main():
f = open(0)
n, q = [int(x) for x in f.readline().split()]
qr = np.fromstring(f.read(), i8, sep=' ').reshape((-1, 2))
white = solve(n, qr)
print(((n - 2) ** 2 - white))
main()
| 44 | 44 | 1,121 | 1,127 |
import numpy as np
from numba import njit
from numba.types import int64
i8 = np.int64
@njit((int64, int64[:, ::-1]), cache=True)
def solve(n, qr):
col = np.zeros(n - 1, i8)
col[0] = 0
col_min = n - 1
row = np.zeros(n - 1, i8)
row[0] = 0
row_min = n - 1
white = 0
for i in range(qr.shape[0]):
j = qr[i, 1] - 1
if qr[i, 0] == 1:
if j < col_min:
white += row_min - 1
for m in range(j + 1, col_min):
col[m] = row_min - 1
col_min = j
else:
white += col[j]
else:
if j < row_min:
white += col_min - 1
for m in range(j + 1, row_min):
row[m] = col_min - 1
row_min = j
else:
white += row[j]
return white
def main():
f = open(0)
n, q = [int(x) for x in f.readline().split()]
qr = np.fromstring(f.read(), i8, sep=" ").reshape((-1, 2))
white = solve(n, qr)
print(((n - 2) ** 2 - white))
main()
|
import numpy as np
# from numba import njit
# from numba.types import int64
i8 = np.int64
# @njit((int64, int64[:,::-1]), cache=True)
def solve(n, qr):
col = np.zeros(n - 1, i8)
col[0] = 0
col_min = n - 1
row = np.zeros(n - 1, i8)
row[0] = 0
row_min = n - 1
white = 0
for i in range(qr.shape[0]):
j = qr[i, 1] - 1
if qr[i, 0] == 1:
if j < col_min:
white += row_min - 1
for m in range(j + 1, col_min):
col[m] = row_min - 1
col_min = j
else:
white += col[j]
else:
if j < row_min:
white += col_min - 1
for m in range(j + 1, row_min):
row[m] = col_min - 1
row_min = j
else:
white += row[j]
return white
def main():
f = open(0)
n, q = [int(x) for x in f.readline().split()]
qr = np.fromstring(f.read(), i8, sep=" ").reshape((-1, 2))
white = solve(n, qr)
print(((n - 2) ** 2 - white))
main()
| false | 0 |
[
"-from numba import njit",
"-from numba.types import int64",
"+# from numba import njit",
"+# from numba.types import int64",
"-",
"-",
"-@njit((int64, int64[:, ::-1]), cache=True)",
"+# @njit((int64, int64[:,::-1]), cache=True)"
] | false | 0.264269 | 0.312647 | 0.845264 |
[
"s655802641",
"s045276700"
] |
u562935282
|
p02983
|
python
|
s515537840
|
s704207658
| 173 | 64 | 39,024 | 3,316 |
Accepted
|
Accepted
| 63.01 |
inf = float('inf')
L, R = list(map(int, input().split()))
if R > L + 3000:
R = L + 3000
t = [i % 2019 for i in range(L, R + 1)]
t.sort()
if (3 in t and 673 in t) or (0 in t):
print((0))
else:
n = len(t)
ans = inf
for i in range(n - 1):
for j in range(i + 1, n):
ans = min(ans, t[i] * t[j] % 2019)
print(ans)
# print(t)
|
mod = 2019
l, r = list(map(int, input().split()))
e = []
for i in range(l, min(r, l + mod * 2) + 1):
e.append(i % mod)
e.sort()
ans = mod
for i in range(len(e)):
for j in range(i + 1, len(e)):
ans = min(ans, e[i] * e[j] % mod)
if ans == 0:
break
else:
continue
break
print(ans)
| 18 | 17 | 378 | 341 |
inf = float("inf")
L, R = list(map(int, input().split()))
if R > L + 3000:
R = L + 3000
t = [i % 2019 for i in range(L, R + 1)]
t.sort()
if (3 in t and 673 in t) or (0 in t):
print((0))
else:
n = len(t)
ans = inf
for i in range(n - 1):
for j in range(i + 1, n):
ans = min(ans, t[i] * t[j] % 2019)
print(ans)
# print(t)
|
mod = 2019
l, r = list(map(int, input().split()))
e = []
for i in range(l, min(r, l + mod * 2) + 1):
e.append(i % mod)
e.sort()
ans = mod
for i in range(len(e)):
for j in range(i + 1, len(e)):
ans = min(ans, e[i] * e[j] % mod)
if ans == 0:
break
else:
continue
break
print(ans)
| false | 5.555556 |
[
"-inf = float(\"inf\")",
"-L, R = list(map(int, input().split()))",
"-if R > L + 3000:",
"- R = L + 3000",
"-t = [i % 2019 for i in range(L, R + 1)]",
"-t.sort()",
"-if (3 in t and 673 in t) or (0 in t):",
"- print((0))",
"-else:",
"- n = len(t)",
"- ans = inf",
"- for i in range(n - 1):",
"- for j in range(i + 1, n):",
"- ans = min(ans, t[i] * t[j] % 2019)",
"- print(ans)",
"- # print(t)",
"+mod = 2019",
"+l, r = list(map(int, input().split()))",
"+e = []",
"+for i in range(l, min(r, l + mod * 2) + 1):",
"+ e.append(i % mod)",
"+e.sort()",
"+ans = mod",
"+for i in range(len(e)):",
"+ for j in range(i + 1, len(e)):",
"+ ans = min(ans, e[i] * e[j] % mod)",
"+ if ans == 0:",
"+ break",
"+ else:",
"+ continue",
"+ break",
"+print(ans)"
] | false | 0.043716 | 0.044301 | 0.98679 |
[
"s515537840",
"s704207658"
] |
u963468276
|
p03834
|
python
|
s681331791
|
s575489856
| 180 | 164 | 38,256 | 38,256 |
Accepted
|
Accepted
| 8.89 |
s1, s2, s3 = input().split(',')
print((s1 + ' ' + s2 + ' ' + s3))
|
s = list(input().split(','))
print((' '.join(s)))
| 2 | 2 | 64 | 48 |
s1, s2, s3 = input().split(",")
print((s1 + " " + s2 + " " + s3))
|
s = list(input().split(","))
print((" ".join(s)))
| false | 0 |
[
"-s1, s2, s3 = input().split(\",\")",
"-print((s1 + \" \" + s2 + \" \" + s3))",
"+s = list(input().split(\",\"))",
"+print((\" \".join(s)))"
] | false | 0.044259 | 0.04504 | 0.982663 |
[
"s681331791",
"s575489856"
] |
u678167152
|
p02586
|
python
|
s441806634
|
s414768523
| 1,970 | 1,222 | 215,568 | 207,492 |
Accepted
|
Accepted
| 37.97 |
def solve():
R, C, K = list(map(int, input().split()))
item = [[0]*C for _ in range(R)]
for i in range(K):
r,c,v = list(map(int, input().split()))
item[r-1][c-1] = v
last_dp = [[0]*5 for _ in range(C+1)]
for i in range(1,R+1):
dp = [[0]*5 for _ in range(C+1)]
for j in range(1,C+1):
for k in range(4): #横から取らない
dp[j][k] = dp[j-1][k]
#上から取らない
dp[j][0] = max(dp[j][0],last_dp[j][-1])
if item[i-1][j-1]>0:
#上からとる
dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
for k in range(1,4): #横から取る
dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
dp[j][4] = max(dp[j][:4])
last_dp = dp
ans = max(last_dp[-1])
return ans
print((solve()))
|
def solve():
R, C, K = list(map(int, input().split()))
item = [[0]*C for _ in range(R)]
for i in range(K):
r,c,v = list(map(int, input().split()))
item[r-1][c-1] = v
last_dp = [[0]*(C+1) for _ in range(5)]
for i in range(1,R+1):
dp = [[0]*(C+1) for _ in range(5)]
for j in range(1,C+1):
for k in range(4): #横から取らない
dp[k][j] = dp[k][j-1]
#上から取らない
dp[0][j] = max(dp[0][j],last_dp[-1][j])
if item[i-1][j-1]>0:
#上からとる
dp[1][j] = max(dp[1][j],last_dp[-1][j]+item[i-1][j-1])
for k in range(1,4): #横から取る
dp[k][j] = max(dp[k][j],dp[k-1][j-1]+item[i-1][j-1])
for k in range(4):
dp[-1][j] = max(dp[-1][j],dp[k][j])
last_dp = dp
ans = last_dp[-1][-1]
return ans
print((solve()))
| 24 | 25 | 750 | 791 |
def solve():
R, C, K = list(map(int, input().split()))
item = [[0] * C for _ in range(R)]
for i in range(K):
r, c, v = list(map(int, input().split()))
item[r - 1][c - 1] = v
last_dp = [[0] * 5 for _ in range(C + 1)]
for i in range(1, R + 1):
dp = [[0] * 5 for _ in range(C + 1)]
for j in range(1, C + 1):
for k in range(4): # 横から取らない
dp[j][k] = dp[j - 1][k]
# 上から取らない
dp[j][0] = max(dp[j][0], last_dp[j][-1])
if item[i - 1][j - 1] > 0:
# 上からとる
dp[j][1] = max(dp[j][1], last_dp[j][-1] + item[i - 1][j - 1])
for k in range(1, 4): # 横から取る
dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + item[i - 1][j - 1])
dp[j][4] = max(dp[j][:4])
last_dp = dp
ans = max(last_dp[-1])
return ans
print((solve()))
|
def solve():
R, C, K = list(map(int, input().split()))
item = [[0] * C for _ in range(R)]
for i in range(K):
r, c, v = list(map(int, input().split()))
item[r - 1][c - 1] = v
last_dp = [[0] * (C + 1) for _ in range(5)]
for i in range(1, R + 1):
dp = [[0] * (C + 1) for _ in range(5)]
for j in range(1, C + 1):
for k in range(4): # 横から取らない
dp[k][j] = dp[k][j - 1]
# 上から取らない
dp[0][j] = max(dp[0][j], last_dp[-1][j])
if item[i - 1][j - 1] > 0:
# 上からとる
dp[1][j] = max(dp[1][j], last_dp[-1][j] + item[i - 1][j - 1])
for k in range(1, 4): # 横から取る
dp[k][j] = max(dp[k][j], dp[k - 1][j - 1] + item[i - 1][j - 1])
for k in range(4):
dp[-1][j] = max(dp[-1][j], dp[k][j])
last_dp = dp
ans = last_dp[-1][-1]
return ans
print((solve()))
| false | 4 |
[
"- last_dp = [[0] * 5 for _ in range(C + 1)]",
"+ last_dp = [[0] * (C + 1) for _ in range(5)]",
"- dp = [[0] * 5 for _ in range(C + 1)]",
"+ dp = [[0] * (C + 1) for _ in range(5)]",
"- dp[j][k] = dp[j - 1][k]",
"+ dp[k][j] = dp[k][j - 1]",
"- dp[j][0] = max(dp[j][0], last_dp[j][-1])",
"+ dp[0][j] = max(dp[0][j], last_dp[-1][j])",
"- dp[j][1] = max(dp[j][1], last_dp[j][-1] + item[i - 1][j - 1])",
"+ dp[1][j] = max(dp[1][j], last_dp[-1][j] + item[i - 1][j - 1])",
"- dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + item[i - 1][j - 1])",
"- dp[j][4] = max(dp[j][:4])",
"+ dp[k][j] = max(dp[k][j], dp[k - 1][j - 1] + item[i - 1][j - 1])",
"+ for k in range(4):",
"+ dp[-1][j] = max(dp[-1][j], dp[k][j])",
"- ans = max(last_dp[-1])",
"+ ans = last_dp[-1][-1]"
] | false | 0.044577 | 0.042345 | 1.052725 |
[
"s441806634",
"s414768523"
] |
u252828980
|
p03617
|
python
|
s805224668
|
s945804193
| 20 | 17 | 3,064 | 3,064 |
Accepted
|
Accepted
| 15 |
q,h,s,d = list(map(int,input().split()))
n = int(eval(input()))
L2 = [8*q,4*h,2*s,d]
L2.sort()
L1 = [4*q,2*h,s]
L1.sort()
L5 = [2*q,h]
L5.sort()
L25 = [q]
ans = 0
if n >= 2:
ans += n//2*L2[0]
n = n%2
if n == 1:
ans += L1[0]
elif n == 1:
ans = L1[0]
elif n == 0:
ans = 0
print(ans)
|
q,h,s,d = list(map(int,input().split()))
n = int(eval(input()))
d1 = min([8*q,4*h,2*s,d])
s1 = min([4*q,2*h,s])
ans = 0
if n >= 2:
ans += n//2*d1
n = n%2
if n == 1:
ans += s1
elif n == 1:
ans = s1
print(ans)
| 23 | 16 | 325 | 241 |
q, h, s, d = list(map(int, input().split()))
n = int(eval(input()))
L2 = [8 * q, 4 * h, 2 * s, d]
L2.sort()
L1 = [4 * q, 2 * h, s]
L1.sort()
L5 = [2 * q, h]
L5.sort()
L25 = [q]
ans = 0
if n >= 2:
ans += n // 2 * L2[0]
n = n % 2
if n == 1:
ans += L1[0]
elif n == 1:
ans = L1[0]
elif n == 0:
ans = 0
print(ans)
|
q, h, s, d = list(map(int, input().split()))
n = int(eval(input()))
d1 = min([8 * q, 4 * h, 2 * s, d])
s1 = min([4 * q, 2 * h, s])
ans = 0
if n >= 2:
ans += n // 2 * d1
n = n % 2
if n == 1:
ans += s1
elif n == 1:
ans = s1
print(ans)
| false | 30.434783 |
[
"-L2 = [8 * q, 4 * h, 2 * s, d]",
"-L2.sort()",
"-L1 = [4 * q, 2 * h, s]",
"-L1.sort()",
"-L5 = [2 * q, h]",
"-L5.sort()",
"-L25 = [q]",
"+d1 = min([8 * q, 4 * h, 2 * s, d])",
"+s1 = min([4 * q, 2 * h, s])",
"- ans += n // 2 * L2[0]",
"+ ans += n // 2 * d1",
"- ans += L1[0]",
"+ ans += s1",
"- ans = L1[0]",
"-elif n == 0:",
"- ans = 0",
"+ ans = s1"
] | false | 0.051085 | 0.050701 | 1.007585 |
[
"s805224668",
"s945804193"
] |
u843175622
|
p03032
|
python
|
s304874632
|
s856343863
| 53 | 34 | 9,212 | 9,220 |
Accepted
|
Accepted
| 35.85 |
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
# 左から何個、右から何個を全探索
ans = 0
for l in range(0, k + 1):
for r in range(0, k + 1 - l):
if l + r > n:
continue
suteru = k - l - r
get = []
for i in range(l):
get.append(v[i])
for i in range(n - 1, n - 1 - r, -1):
get.append(v[i])
get.sort()
minus = 0
while minus < min(suteru, len(get)) and get[minus] < 0:
minus += 1
ans = max(ans, sum(get[minus:]))
print(ans)
|
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
for l in range(0, k + 1):
for r in range(0, k + 1 - l):
if l == r == 0 or l + r > n:
continue
a = sorted(v[:l] + v[n - r:])
m = min(k - l - r, len(a) - 1)
ans = max(ans, sum(a[m:] if a[m] <
0 else [x for x in a if x > 0]))
print(ans)
| 21 | 13 | 570 | 401 |
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
# 左から何個、右から何個を全探索
ans = 0
for l in range(0, k + 1):
for r in range(0, k + 1 - l):
if l + r > n:
continue
suteru = k - l - r
get = []
for i in range(l):
get.append(v[i])
for i in range(n - 1, n - 1 - r, -1):
get.append(v[i])
get.sort()
minus = 0
while minus < min(suteru, len(get)) and get[minus] < 0:
minus += 1
ans = max(ans, sum(get[minus:]))
print(ans)
|
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
for l in range(0, k + 1):
for r in range(0, k + 1 - l):
if l == r == 0 or l + r > n:
continue
a = sorted(v[:l] + v[n - r :])
m = min(k - l - r, len(a) - 1)
ans = max(ans, sum(a[m:] if a[m] < 0 else [x for x in a if x > 0]))
print(ans)
| false | 38.095238 |
[
"-# 左から何個、右から何個を全探索",
"- if l + r > n:",
"+ if l == r == 0 or l + r > n:",
"- suteru = k - l - r",
"- get = []",
"- for i in range(l):",
"- get.append(v[i])",
"- for i in range(n - 1, n - 1 - r, -1):",
"- get.append(v[i])",
"- get.sort()",
"- minus = 0",
"- while minus < min(suteru, len(get)) and get[minus] < 0:",
"- minus += 1",
"- ans = max(ans, sum(get[minus:]))",
"+ a = sorted(v[:l] + v[n - r :])",
"+ m = min(k - l - r, len(a) - 1)",
"+ ans = max(ans, sum(a[m:] if a[m] < 0 else [x for x in a if x > 0]))"
] | false | 0.037313 | 0.074004 | 0.504196 |
[
"s304874632",
"s856343863"
] |
u161712560
|
p02720
|
python
|
s364294593
|
s302309862
| 297 | 125 | 3,064 | 8,568 |
Accepted
|
Accepted
| 57.91 |
def dfs(inParam, digits, lunlunCount, lunlun):
if len(inParam) != digits:
if int(inParam[len(inParam)-1]) == 0:
nextNumList = [0, 1]
elif int(inParam[len(inParam)-1]) == 9:
nextNumList = [8, 9]
else:
nextNum = int(inParam[len(inParam)-1])
nextNumList = [nextNum-1, nextNum, nextNum+1]
for item in nextNumList:
myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
lunlunCount = myTupp[0]
if myTupp[2] == 'e':
return myTupp
return myTupp
else:
lunlunCount += 1
state = 'c'
if lunlunCount == lunlun:
state = 'e'
print(inParam)
return (lunlunCount, inParam, state)
K = int(eval(input()))
mylunlun = 0
mydigits = 1
while mylunlun != K:
for indx in range(1, 10):
mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
# if mylunlun == K:
# break
if mylunlun >= K:
break
mydigits += 1
|
K = int(eval(input()))
if K <= 9:
print(K)
else:
mylun = 9
lunList = []
for indx in range(1, 10):
lunList.append(str(indx))
while mylun < K:
newLunList = []
for lunItem in lunList:
if lunItem[len(lunItem)-1] != "0":
mylun += 1
newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))
if mylun == K:
print((lunItem + str( int(lunItem[len(lunItem)-1])-1 )))
break
mylun += 1
newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1]) ))
if mylun == K:
print((lunItem + str( int(lunItem[len(lunItem)-1]) )))
break
if lunItem[len(lunItem)-1] != "9":
mylun += 1
newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))
if mylun == K:
print((lunItem + str( int(lunItem[len(lunItem)-1])+1 )))
break
lunList = newLunList
| 42 | 35 | 1,117 | 1,104 |
def dfs(inParam, digits, lunlunCount, lunlun):
if len(inParam) != digits:
if int(inParam[len(inParam) - 1]) == 0:
nextNumList = [0, 1]
elif int(inParam[len(inParam) - 1]) == 9:
nextNumList = [8, 9]
else:
nextNum = int(inParam[len(inParam) - 1])
nextNumList = [nextNum - 1, nextNum, nextNum + 1]
for item in nextNumList:
myTupp = dfs(inParam + str(item), digits, lunlunCount, lunlun)
lunlunCount = myTupp[0]
if myTupp[2] == "e":
return myTupp
return myTupp
else:
lunlunCount += 1
state = "c"
if lunlunCount == lunlun:
state = "e"
print(inParam)
return (lunlunCount, inParam, state)
K = int(eval(input()))
mylunlun = 0
mydigits = 1
while mylunlun != K:
for indx in range(1, 10):
mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
# if mylunlun == K:
# break
if mylunlun >= K:
break
mydigits += 1
|
K = int(eval(input()))
if K <= 9:
print(K)
else:
mylun = 9
lunList = []
for indx in range(1, 10):
lunList.append(str(indx))
while mylun < K:
newLunList = []
for lunItem in lunList:
if lunItem[len(lunItem) - 1] != "0":
mylun += 1
newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) - 1))
if mylun == K:
print((lunItem + str(int(lunItem[len(lunItem) - 1]) - 1)))
break
mylun += 1
newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1])))
if mylun == K:
print((lunItem + str(int(lunItem[len(lunItem) - 1]))))
break
if lunItem[len(lunItem) - 1] != "9":
mylun += 1
newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) + 1))
if mylun == K:
print((lunItem + str(int(lunItem[len(lunItem) - 1]) + 1)))
break
lunList = newLunList
| false | 16.666667 |
[
"-def dfs(inParam, digits, lunlunCount, lunlun):",
"- if len(inParam) != digits:",
"- if int(inParam[len(inParam) - 1]) == 0:",
"- nextNumList = [0, 1]",
"- elif int(inParam[len(inParam) - 1]) == 9:",
"- nextNumList = [8, 9]",
"- else:",
"- nextNum = int(inParam[len(inParam) - 1])",
"- nextNumList = [nextNum - 1, nextNum, nextNum + 1]",
"- for item in nextNumList:",
"- myTupp = dfs(inParam + str(item), digits, lunlunCount, lunlun)",
"- lunlunCount = myTupp[0]",
"- if myTupp[2] == \"e\":",
"- return myTupp",
"- return myTupp",
"- else:",
"- lunlunCount += 1",
"- state = \"c\"",
"- if lunlunCount == lunlun:",
"- state = \"e\"",
"- print(inParam)",
"- return (lunlunCount, inParam, state)",
"-",
"-",
"-mylunlun = 0",
"-mydigits = 1",
"-while mylunlun != K:",
"+if K <= 9:",
"+ print(K)",
"+else:",
"+ mylun = 9",
"+ lunList = []",
"- mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)",
"- # if mylunlun == K:",
"- # break",
"- if mylunlun >= K:",
"- break",
"- mydigits += 1",
"+ lunList.append(str(indx))",
"+ while mylun < K:",
"+ newLunList = []",
"+ for lunItem in lunList:",
"+ if lunItem[len(lunItem) - 1] != \"0\":",
"+ mylun += 1",
"+ newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) - 1))",
"+ if mylun == K:",
"+ print((lunItem + str(int(lunItem[len(lunItem) - 1]) - 1)))",
"+ break",
"+ mylun += 1",
"+ newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1])))",
"+ if mylun == K:",
"+ print((lunItem + str(int(lunItem[len(lunItem) - 1]))))",
"+ break",
"+ if lunItem[len(lunItem) - 1] != \"9\":",
"+ mylun += 1",
"+ newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) + 1))",
"+ if mylun == K:",
"+ print((lunItem + str(int(lunItem[len(lunItem) - 1]) + 1)))",
"+ break",
"+ lunList = newLunList"
] | false | 0.092524 | 0.065846 | 1.405156 |
[
"s364294593",
"s302309862"
] |
u588341295
|
p03634
|
python
|
s271088916
|
s118623871
| 692 | 623 | 53,700 | 80,084 |
Accepted
|
Accepted
| 9.97 |
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def dfs(N, nodes, src):
""" DFS(木、スタック、重みあり) """
stack = [(src, -1, 0)]
dist = [INF] * N
while stack:
u, prev, c1 = stack.pop()
dist[u] = c1
for v, c2 in nodes[u]:
if v != prev:
stack.append((v, u, c1+c2))
return dist
N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
a, b, c = MAP()
a -= 1; b -= 1
nodes[a].append((b, c))
nodes[b].append((a, c))
Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
ans = []
for i in range(Q):
x, y = MAP()
x -= 1; y -= 1
ans.append(str(res[x] + res[y]))
print(('\n'.join(ans)))
|
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def dfs(N, nodes, src):
""" DFS(木、スタック、重みあり) """
stack = [(src, -1, 0)]
dist = [INF] * N
while stack:
u, prev, c1 = stack.pop()
dist[u] = c1
for v, c2 in nodes[u]:
if v != prev:
stack.append((v, u, c1+c2))
return dist
N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
a, b, c = MAP()
a -= 1; b -= 1
nodes[a].append((b, c))
nodes[b].append((a, c))
Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
x, y = MAP()
x -= 1; y -= 1
ans = res[x] + res[y]
print(ans)
| 50 | 49 | 1,342 | 1,314 |
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def dfs(N, nodes, src):
"""DFS(木、スタック、重みあり)"""
stack = [(src, -1, 0)]
dist = [INF] * N
while stack:
u, prev, c1 = stack.pop()
dist[u] = c1
for v, c2 in nodes[u]:
if v != prev:
stack.append((v, u, c1 + c2))
return dist
N = INT()
nodes = [[] for i in range(N)]
for i in range(N - 1):
a, b, c = MAP()
a -= 1
b -= 1
nodes[a].append((b, c))
nodes[b].append((a, c))
Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
ans = []
for i in range(Q):
x, y = MAP()
x -= 1
y -= 1
ans.append(str(res[x] + res[y]))
print(("\n".join(ans)))
|
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def dfs(N, nodes, src):
"""DFS(木、スタック、重みあり)"""
stack = [(src, -1, 0)]
dist = [INF] * N
while stack:
u, prev, c1 = stack.pop()
dist[u] = c1
for v, c2 in nodes[u]:
if v != prev:
stack.append((v, u, c1 + c2))
return dist
N = INT()
nodes = [[] for i in range(N)]
for i in range(N - 1):
a, b, c = MAP()
a -= 1
b -= 1
nodes[a].append((b, c))
nodes[b].append((a, c))
Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
x, y = MAP()
x -= 1
y -= 1
ans = res[x] + res[y]
print(ans)
| false | 2 |
[
"-ans = []",
"- ans.append(str(res[x] + res[y]))",
"-print((\"\\n\".join(ans)))",
"+ ans = res[x] + res[y]",
"+ print(ans)"
] | false | 0.049605 | 0.047775 | 1.0383 |
[
"s271088916",
"s118623871"
] |
u083960235
|
p03062
|
python
|
s149076554
|
s730330280
| 111 | 92 | 14,224 | 15,092 |
Accepted
|
Accepted
| 17.12 |
N=int(eval(input()))
A=list(map(int,input().split()))
l=[]
cnt=0
for i in range(N):
if A[i]<0:
cnt+=1
l.append(A[i])
wa=0
l_ab=[]
for i in range(N):
wa+=abs(A[i])
l_ab.append(abs(A[i]))
if cnt%2!=0:
wa-=2*min(l_ab)
print(wa)
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
is_zero = False
if 0 in A:
is_zero = True
minus = 0
plus = 0
for a in A:
if a < 0:
minus += 1
elif a > 0:
plus += 1
ans = 0
for a in A:
ans += abs(a)
tmp = INF
if is_zero == True or minus % 2 == 0:
print(ans)
else:
for a in A:
if abs(a) < tmp:
tmp = abs(a)
print((ans - 2 * tmp))
| 20 | 48 | 286 | 1,147 |
N = int(eval(input()))
A = list(map(int, input().split()))
l = []
cnt = 0
for i in range(N):
if A[i] < 0:
cnt += 1
l.append(A[i])
wa = 0
l_ab = []
for i in range(N):
wa += abs(A[i])
l_ab.append(abs(A[i]))
if cnt % 2 != 0:
wa -= 2 * min(l_ab)
print(wa)
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
is_zero = False
if 0 in A:
is_zero = True
minus = 0
plus = 0
for a in A:
if a < 0:
minus += 1
elif a > 0:
plus += 1
ans = 0
for a in A:
ans += abs(a)
tmp = INF
if is_zero == True or minus % 2 == 0:
print(ans)
else:
for a in A:
if abs(a) < tmp:
tmp = abs(a)
print((ans - 2 * tmp))
| false | 58.333333 |
[
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-l = []",
"-cnt = 0",
"-for i in range(N):",
"- if A[i] < 0:",
"- cnt += 1",
"- l.append(A[i])",
"-wa = 0",
"-l_ab = []",
"-for i in range(N):",
"- wa += abs(A[i])",
"- l_ab.append(abs(A[i]))",
"-if cnt % 2 != 0:",
"- wa -= 2 * min(l_ab)",
"-print(wa)",
"+import sys, re, os",
"+from collections import deque, defaultdict, Counter",
"+from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians",
"+from itertools import permutations, combinations, product, accumulate",
"+from operator import itemgetter, mul",
"+from copy import deepcopy",
"+from string import ascii_lowercase, ascii_uppercase, digits",
"+from heapq import heapify, heappop, heappush",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def S_MAP():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+def LIST():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def S_LIST():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+INF = float(\"inf\")",
"+mod = 10**9 + 7",
"+N = INT()",
"+A = LIST()",
"+is_zero = False",
"+if 0 in A:",
"+ is_zero = True",
"+minus = 0",
"+plus = 0",
"+for a in A:",
"+ if a < 0:",
"+ minus += 1",
"+ elif a > 0:",
"+ plus += 1",
"+ans = 0",
"+for a in A:",
"+ ans += abs(a)",
"+tmp = INF",
"+if is_zero == True or minus % 2 == 0:",
"+ print(ans)",
"+else:",
"+ for a in A:",
"+ if abs(a) < tmp:",
"+ tmp = abs(a)",
"+ print((ans - 2 * tmp))"
] | false | 0.082708 | 0.041134 | 2.01067 |
[
"s149076554",
"s730330280"
] |
u631277801
|
p03295
|
python
|
s282664712
|
s183060474
| 451 | 311 | 29,076 | 18,200 |
Accepted
|
Accepted
| 31.04 |
N,M = list(map(int, input().split()))
AB = []
for _ in range(M):
AB.append(list(map(int,input().split())))
AB.sort(key=lambda x:x[1])
cur = 0
ans = 0
for a,b in AB:
if cur > a:
continue
ans += 1
cur = b
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n,m = li()
ab = []
for _ in range(m):
a,b = li_()
ab.append(tuple([a,b]))
ab.sort(key=lambda x:x[1])
ans = 0
cur = -1
for a,b in ab:
if a >= cur:
ans += 1
cur = b
print(ans)
| 17 | 30 | 255 | 673 |
N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[1])
cur = 0
ans = 0
for a, b in AB:
if cur > a:
continue
ans += 1
cur = b
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n, m = li()
ab = []
for _ in range(m):
a, b = li_()
ab.append(tuple([a, b]))
ab.sort(key=lambda x: x[1])
ans = 0
cur = -1
for a, b in ab:
if a >= cur:
ans += 1
cur = b
print(ans)
| false | 43.333333 |
[
"-N, M = list(map(int, input().split()))",
"-AB = []",
"-for _ in range(M):",
"- AB.append(list(map(int, input().split())))",
"-AB.sort(key=lambda x: x[1])",
"-cur = 0",
"+import sys",
"+",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**5)",
"+",
"+",
"+def li():",
"+ return list(map(int, stdin.readline().split()))",
"+",
"+",
"+def li_():",
"+ return [int(x) - 1 for x in stdin.readline().split()]",
"+",
"+",
"+def lf():",
"+ return list(map(float, stdin.readline().split()))",
"+",
"+",
"+def ls():",
"+ return stdin.readline().split()",
"+",
"+",
"+def ns():",
"+ return stdin.readline().rstrip()",
"+",
"+",
"+def lc():",
"+ return list(ns())",
"+",
"+",
"+def ni():",
"+ return int(stdin.readline())",
"+",
"+",
"+def nf():",
"+ return float(stdin.readline())",
"+",
"+",
"+n, m = li()",
"+ab = []",
"+for _ in range(m):",
"+ a, b = li_()",
"+ ab.append(tuple([a, b]))",
"+ab.sort(key=lambda x: x[1])",
"-for a, b in AB:",
"- if cur > a:",
"- continue",
"- ans += 1",
"- cur = b",
"+cur = -1",
"+for a, b in ab:",
"+ if a >= cur:",
"+ ans += 1",
"+ cur = b"
] | false | 0.037818 | 0.038277 | 0.988014 |
[
"s282664712",
"s183060474"
] |
u193264896
|
p03014
|
python
|
s040066609
|
s762716011
| 1,777 | 1,588 | 309,888 | 310,664 |
Accepted
|
Accepted
| 10.64 |
def main():
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
s = list(eval(input()))
S.append(s)
R = [[0]*W for _ in range(H)]
L = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
for i in range(H):
cnt = 0
for j in range(W):
if S[i][j]=='#':
cnt = 0
else:
cnt += 1
L[i][j] = cnt
for i in range(H):
cnt = 0
for j in range(W-1, -1, -1):
if S[i][j]=='#':
cnt = 0
else:
cnt += 1
R[i][j] = cnt
for j in range(W):
cnt = 0
for i in range(H):
if S[i][j]=='#':
cnt = 0
else:
cnt += 1
U[i][j] = cnt
for j in range(W):
cnt = 0
for i in range(H-1,-1,-1):
if S[i][j]=='#':
cnt = 0
else:
cnt += 1
D[i][j] = cnt
ans = 0
for i in range(H):
for j in range(W):
ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)
if __name__ == '__main__':
main()
|
def main():
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
s = list(eval(input()))
S.append(s)
R = [[0]*W for _ in range(H)]
L = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
for i in range(H):
cnt1 = 0
cnt2 = 0
for j in range(W):
if S[i][j]=='#':
cnt1 = 0
else:
cnt1 += 1
L[i][j] = cnt1
for j in range(W-1, -1, -1):
if S[i][j]=='#':
cnt2 = 0
else:
cnt2 += 1
R[i][j] = cnt2
for j in range(W):
cnt1 = 0
cnt2 = 0
for i in range(H):
if S[i][j]=='#':
cnt1 = 0
else:
cnt1 += 1
U[i][j] = cnt1
for i in range(H-1,-1,-1):
if S[i][j]=='#':
cnt2 = 0
else:
cnt2 += 1
D[i][j] = cnt2
ans = 0
for i in range(H):
for j in range(W):
ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)
if __name__ == '__main__':
main()
| 51 | 51 | 1,279 | 1,251 |
def main():
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
s = list(eval(input()))
S.append(s)
R = [[0] * W for _ in range(H)]
L = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
for i in range(H):
cnt = 0
for j in range(W):
if S[i][j] == "#":
cnt = 0
else:
cnt += 1
L[i][j] = cnt
for i in range(H):
cnt = 0
for j in range(W - 1, -1, -1):
if S[i][j] == "#":
cnt = 0
else:
cnt += 1
R[i][j] = cnt
for j in range(W):
cnt = 0
for i in range(H):
if S[i][j] == "#":
cnt = 0
else:
cnt += 1
U[i][j] = cnt
for j in range(W):
cnt = 0
for i in range(H - 1, -1, -1):
if S[i][j] == "#":
cnt = 0
else:
cnt += 1
D[i][j] = cnt
ans = 0
for i in range(H):
for j in range(W):
ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)
if __name__ == "__main__":
main()
|
def main():
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
s = list(eval(input()))
S.append(s)
R = [[0] * W for _ in range(H)]
L = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
for i in range(H):
cnt1 = 0
cnt2 = 0
for j in range(W):
if S[i][j] == "#":
cnt1 = 0
else:
cnt1 += 1
L[i][j] = cnt1
for j in range(W - 1, -1, -1):
if S[i][j] == "#":
cnt2 = 0
else:
cnt2 += 1
R[i][j] = cnt2
for j in range(W):
cnt1 = 0
cnt2 = 0
for i in range(H):
if S[i][j] == "#":
cnt1 = 0
else:
cnt1 += 1
U[i][j] = cnt1
for i in range(H - 1, -1, -1):
if S[i][j] == "#":
cnt2 = 0
else:
cnt2 += 1
D[i][j] = cnt2
ans = 0
for i in range(H):
for j in range(W):
ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- cnt = 0",
"+ cnt1 = 0",
"+ cnt2 = 0",
"- cnt = 0",
"+ cnt1 = 0",
"- cnt += 1",
"- L[i][j] = cnt",
"- for i in range(H):",
"- cnt = 0",
"+ cnt1 += 1",
"+ L[i][j] = cnt1",
"- cnt = 0",
"+ cnt2 = 0",
"- cnt += 1",
"- R[i][j] = cnt",
"+ cnt2 += 1",
"+ R[i][j] = cnt2",
"- cnt = 0",
"+ cnt1 = 0",
"+ cnt2 = 0",
"- cnt = 0",
"+ cnt1 = 0",
"- cnt += 1",
"- U[i][j] = cnt",
"- for j in range(W):",
"- cnt = 0",
"+ cnt1 += 1",
"+ U[i][j] = cnt1",
"- cnt = 0",
"+ cnt2 = 0",
"- cnt += 1",
"- D[i][j] = cnt",
"+ cnt2 += 1",
"+ D[i][j] = cnt2"
] | false | 0.046802 | 0.041687 | 1.122698 |
[
"s040066609",
"s762716011"
] |
u564589929
|
p02819
|
python
|
s561779235
|
s825798556
| 21 | 17 | 3,316 | 2,940 |
Accepted
|
Accepted
| 19.05 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return input().split()
def printlist(lst, k='\n'): print((k.join(list(map(str, lst)))))
INF = float('inf')
from math import ceil, floor, log2, sqrt
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush
def is_prime(n):
for i in range(2, int(sqrt(n))+1):
if n % i == 0:
return False
return True
def solve():
X = II()
while 1:
if is_prime(X):
print(X)
return
X += 1
if __name__ == '__main__':
solve()
|
# import sys
# sys.setrecursionlimit(10 ** 6)
# # input = sys.stdin.readline ####
# def int1(x): return int(x) - 1
def II(): return int(eval(input()))
# def MI(): return map(int, input().split())
# def MI1(): return map(int1, input().split())
#
# def LI(): return list(map(int, input().split()))
# def LI1(): return list(map(int1, input().split()))
# def LLI(rows_number): return [LI() for _ in range(rows_number)]
#
# def SI(): return input().split()
#
# def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
# INF = float('inf')
#
# from math import ceil, floor, log2, sqrt
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
# from heapq import heapify, heappop, heappush
def is_prime(n):
for i in range(2, int(pow(n, 0.5))+1):
if n % i == 0:
return False
return True
def solve():
X = II()
while 1:
if is_prime(X):
print(X)
return
X += 1
if __name__ == '__main__':
solve()
| 45 | 45 | 1,063 | 1,103 |
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline ####
def int1(x):
return int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return input().split()
def printlist(lst, k="\n"):
print((k.join(list(map(str, lst)))))
INF = float("inf")
from math import ceil, floor, log2, sqrt
from collections import deque
from itertools import (
combinations as comb,
combinations_with_replacement as comb_w,
accumulate,
product,
)
from heapq import heapify, heappop, heappush
def is_prime(n):
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
return False
return True
def solve():
X = II()
while 1:
if is_prime(X):
print(X)
return
X += 1
if __name__ == "__main__":
solve()
|
# import sys
# sys.setrecursionlimit(10 ** 6)
# # input = sys.stdin.readline ####
# def int1(x): return int(x) - 1
def II():
return int(eval(input()))
# def MI(): return map(int, input().split())
# def MI1(): return map(int1, input().split())
#
# def LI(): return list(map(int, input().split()))
# def LI1(): return list(map(int1, input().split()))
# def LLI(rows_number): return [LI() for _ in range(rows_number)]
#
# def SI(): return input().split()
#
# def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
# INF = float('inf')
#
# from math import ceil, floor, log2, sqrt
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
# from heapq import heapify, heappop, heappush
def is_prime(n):
for i in range(2, int(pow(n, 0.5)) + 1):
if n % i == 0:
return False
return True
def solve():
X = II()
while 1:
if is_prime(X):
print(X)
return
X += 1
if __name__ == "__main__":
solve()
| false | 0 |
[
"-import sys",
"-",
"-sys.setrecursionlimit(10**6)",
"-# input = sys.stdin.readline ####",
"-def int1(x):",
"- return int(x) - 1",
"-",
"-",
"+# import sys",
"+# sys.setrecursionlimit(10 ** 6)",
"+# # input = sys.stdin.readline ####",
"+# def int1(x): return int(x) - 1",
"-def MI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def MI1():",
"- return list(map(int1, input().split()))",
"-",
"-",
"-def LI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def LI1():",
"- return list(map(int1, input().split()))",
"-",
"-",
"-def LLI(rows_number):",
"- return [LI() for _ in range(rows_number)]",
"-",
"-",
"-def SI():",
"- return input().split()",
"-",
"-",
"-def printlist(lst, k=\"\\n\"):",
"- print((k.join(list(map(str, lst)))))",
"-",
"-",
"-INF = float(\"inf\")",
"-from math import ceil, floor, log2, sqrt",
"-from collections import deque",
"-from itertools import (",
"- combinations as comb,",
"- combinations_with_replacement as comb_w,",
"- accumulate,",
"- product,",
"-)",
"-from heapq import heapify, heappop, heappush",
"-",
"-",
"+# def MI(): return map(int, input().split())",
"+# def MI1(): return map(int1, input().split())",
"+#",
"+# def LI(): return list(map(int, input().split()))",
"+# def LI1(): return list(map(int1, input().split()))",
"+# def LLI(rows_number): return [LI() for _ in range(rows_number)]",
"+#",
"+# def SI(): return input().split()",
"+#",
"+# def printlist(lst, k='\\n'): print(k.join(list(map(str, lst))))",
"+# INF = float('inf')",
"+#",
"+# from math import ceil, floor, log2, sqrt",
"+# from collections import deque",
"+# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product",
"+# from heapq import heapify, heappop, heappush",
"- for i in range(2, int(sqrt(n)) + 1):",
"+ for i in range(2, int(pow(n, 0.5)) + 1):"
] | false | 0.038698 | 0.044294 | 0.873659 |
[
"s561779235",
"s825798556"
] |
u849029577
|
p02844
|
python
|
s680167537
|
s823683816
| 876 | 513 | 43,100 | 40,940 |
Accepted
|
Accepted
| 41.44 |
n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(1000):
count = 0
index = 0
i = str(i)
if len(i) < 2:
i = "00"+i
elif len(i) < 3:
i = "0"+i
for j in i:
for k in range(index, n):
if j == s[k]:
index = k+1
count += 1
break
if count == 3:
ans += 1
print(ans)
|
n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(1000):
index = 0
i = str(i)
if len(i) < 2:
i = "00"+i
elif len(i) < 3:
i = "0"+i
for j in s:
if i[index] == j:
index += 1
if index == 3:
ans += 1
break
print(ans)
| 20 | 17 | 397 | 318 |
n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(1000):
count = 0
index = 0
i = str(i)
if len(i) < 2:
i = "00" + i
elif len(i) < 3:
i = "0" + i
for j in i:
for k in range(index, n):
if j == s[k]:
index = k + 1
count += 1
break
if count == 3:
ans += 1
print(ans)
|
n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(1000):
index = 0
i = str(i)
if len(i) < 2:
i = "00" + i
elif len(i) < 3:
i = "0" + i
for j in s:
if i[index] == j:
index += 1
if index == 3:
ans += 1
break
print(ans)
| false | 15 |
[
"- count = 0",
"- for j in i:",
"- for k in range(index, n):",
"- if j == s[k]:",
"- index = k + 1",
"- count += 1",
"- break",
"- if count == 3:",
"- ans += 1",
"+ for j in s:",
"+ if i[index] == j:",
"+ index += 1",
"+ if index == 3:",
"+ ans += 1",
"+ break"
] | false | 0.053481 | 0.0795 | 0.672714 |
[
"s680167537",
"s823683816"
] |
u600402037
|
p03644
|
python
|
s163401738
|
s713246924
| 19 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10.53 |
print((2**(len(bin(int(eval(input()))))-3)))
|
N = int(eval(input()))
print((2 ** (len(bin(N)[2:]) - 1)))
| 1 | 2 | 37 | 51 |
print((2 ** (len(bin(int(eval(input())))) - 3)))
|
N = int(eval(input()))
print((2 ** (len(bin(N)[2:]) - 1)))
| false | 50 |
[
"-print((2 ** (len(bin(int(eval(input())))) - 3)))",
"+N = int(eval(input()))",
"+print((2 ** (len(bin(N)[2:]) - 1)))"
] | false | 0.044523 | 0.146114 | 0.304715 |
[
"s163401738",
"s713246924"
] |
u163320134
|
p02679
|
python
|
s397598484
|
s084966338
| 841 | 759 | 150,788 | 141,724 |
Accepted
|
Accepted
| 9.75 |
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
mod=10**9+7
n=int(eval(input()))
dic={}
cnt=0
for _ in range(n):
a,b=list(map(int,input().split()))
if a!=0 and b!=0:
g=gcd(abs(a),abs(b))
if (a>0 and b>0) or (a<0 and b<0):
if (abs(a)//g,abs(b)//g) not in dic:
dic[(abs(a)//g,abs(b)//g)]=1
else:
dic[(abs(a)//g,abs(b)//g)]+=1
elif (a<0 and b>0) or (a>0 and b<0):
if (-abs(a)//g,abs(b)//g) not in dic:
dic[(-abs(a)//g,abs(b)//g)]=1
else:
dic[(-abs(a)//g,abs(b)//g)]+=1
else:
if a==0 and b==0:
cnt+=1
elif a==0:
if (1,0) not in dic:
dic[(1,0)]=1
else:
dic[(1,0)]+=1
elif b==0:
if (0,1) not in dic:
dic[(0,1)]=1
else:
dic[(0,1)]+=1
ans=1
s=set()
for a,b in list(dic.keys()):
if (a,b) in s:
continue
s.add((a,b))
if a!=0 and b!=0:
if a>0:
if (-b,a) in dic:
s.add((-b,a))
cnt1=dic[(a,b)]
cnt2=dic[(-b,a)]
ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
ans%=mod
else:
ans*=pow(2,dic[(a,b)])
ans%=mod
elif a<0:
if (b,-a) in dic:
s.add((b,-a))
cnt1=dic[(a,b)]
cnt2=dic[(b,-a)]
ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
ans%=mod
else:
ans*=pow(2,dic[(a,b)],mod)
ans%=mod
else:
if (b,a) in dic:
s.add((b,a))
cnt1=dic[(a,b)]
cnt2=dic[(b,a)]
ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
ans%=mod
else:
ans*=pow(2,dic[(a,b)],mod)
ans%=mod
print(((ans+cnt-1)%mod))
|
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
mod=10**9+7
n=int(eval(input()))
dic={}
cnt=0
for _ in range(n):
a,b=list(map(int,input().split()))
if a!=0 and b!=0:
g=gcd(abs(a),abs(b))
if a*b>0:
if (abs(a)//g,abs(b)//g) not in dic:
dic[(abs(a)//g,abs(b)//g)]=1
else:
dic[(abs(a)//g,abs(b)//g)]+=1
else:
if (-abs(a)//g,abs(b)//g) not in dic:
dic[(-abs(a)//g,abs(b)//g)]=1
else:
dic[(-abs(a)//g,abs(b)//g)]+=1
else:
if a==0 and b==0:
cnt+=1
elif a==0:
if (1,0) not in dic:
dic[(1,0)]=1
else:
dic[(1,0)]+=1
elif b==0:
if (0,1) not in dic:
dic[(0,1)]=1
else:
dic[(0,1)]+=1
ans=1
s=set()
for a,b in list(dic.keys()):
if (a,b) in s:
continue
s.add((a,b))
if a*b!=0:
if a>0:
if (-b,a) in dic:
s.add((-b,a))
cnt1=dic[(a,b)]
cnt2=dic[(-b,a)]
ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
ans%=mod
else:
ans*=pow(2,dic[(a,b)])
ans%=mod
elif a<0:
if (b,-a) in dic:
s.add((b,-a))
cnt1=dic[(a,b)]
cnt2=dic[(b,-a)]
ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
ans%=mod
else:
ans*=pow(2,dic[(a,b)])
ans%=mod
else:
if (b,a) in dic:
s.add((b,a))
cnt1=dic[(a,b)]
cnt2=dic[(b,a)]
ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
ans%=mod
else:
ans*=pow(2,dic[(a,b)])
ans%=mod
print(((ans+cnt-1)%mod))
| 75 | 75 | 1,678 | 1,607 |
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
mod = 10**9 + 7
n = int(eval(input()))
dic = {}
cnt = 0
for _ in range(n):
a, b = list(map(int, input().split()))
if a != 0 and b != 0:
g = gcd(abs(a), abs(b))
if (a > 0 and b > 0) or (a < 0 and b < 0):
if (abs(a) // g, abs(b) // g) not in dic:
dic[(abs(a) // g, abs(b) // g)] = 1
else:
dic[(abs(a) // g, abs(b) // g)] += 1
elif (a < 0 and b > 0) or (a > 0 and b < 0):
if (-abs(a) // g, abs(b) // g) not in dic:
dic[(-abs(a) // g, abs(b) // g)] = 1
else:
dic[(-abs(a) // g, abs(b) // g)] += 1
else:
if a == 0 and b == 0:
cnt += 1
elif a == 0:
if (1, 0) not in dic:
dic[(1, 0)] = 1
else:
dic[(1, 0)] += 1
elif b == 0:
if (0, 1) not in dic:
dic[(0, 1)] = 1
else:
dic[(0, 1)] += 1
ans = 1
s = set()
for a, b in list(dic.keys()):
if (a, b) in s:
continue
s.add((a, b))
if a != 0 and b != 0:
if a > 0:
if (-b, a) in dic:
s.add((-b, a))
cnt1 = dic[(a, b)]
cnt2 = dic[(-b, a)]
ans *= (pow(2, cnt1, mod) + pow(2, cnt2, mod) - 1) % mod
ans %= mod
else:
ans *= pow(2, dic[(a, b)])
ans %= mod
elif a < 0:
if (b, -a) in dic:
s.add((b, -a))
cnt1 = dic[(a, b)]
cnt2 = dic[(b, -a)]
ans *= (pow(2, cnt1, mod) + pow(2, cnt2, mod) - 1) % mod
ans %= mod
else:
ans *= pow(2, dic[(a, b)], mod)
ans %= mod
else:
if (b, a) in dic:
s.add((b, a))
cnt1 = dic[(a, b)]
cnt2 = dic[(b, a)]
ans *= (pow(2, cnt1, mod) + pow(2, cnt2, mod) - 1) % mod
ans %= mod
else:
ans *= pow(2, dic[(a, b)], mod)
ans %= mod
print(((ans + cnt - 1) % mod))
|
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
mod = 10**9 + 7
n = int(eval(input()))
dic = {}
cnt = 0
for _ in range(n):
a, b = list(map(int, input().split()))
if a != 0 and b != 0:
g = gcd(abs(a), abs(b))
if a * b > 0:
if (abs(a) // g, abs(b) // g) not in dic:
dic[(abs(a) // g, abs(b) // g)] = 1
else:
dic[(abs(a) // g, abs(b) // g)] += 1
else:
if (-abs(a) // g, abs(b) // g) not in dic:
dic[(-abs(a) // g, abs(b) // g)] = 1
else:
dic[(-abs(a) // g, abs(b) // g)] += 1
else:
if a == 0 and b == 0:
cnt += 1
elif a == 0:
if (1, 0) not in dic:
dic[(1, 0)] = 1
else:
dic[(1, 0)] += 1
elif b == 0:
if (0, 1) not in dic:
dic[(0, 1)] = 1
else:
dic[(0, 1)] += 1
ans = 1
s = set()
for a, b in list(dic.keys()):
if (a, b) in s:
continue
s.add((a, b))
if a * b != 0:
if a > 0:
if (-b, a) in dic:
s.add((-b, a))
cnt1 = dic[(a, b)]
cnt2 = dic[(-b, a)]
ans *= (pow(2, cnt1, mod) + pow(2, cnt2, mod) - 1) % mod
ans %= mod
else:
ans *= pow(2, dic[(a, b)])
ans %= mod
elif a < 0:
if (b, -a) in dic:
s.add((b, -a))
cnt1 = dic[(a, b)]
cnt2 = dic[(b, -a)]
ans *= (pow(2, cnt1, mod) + pow(2, cnt2, mod) - 1) % mod
ans %= mod
else:
ans *= pow(2, dic[(a, b)])
ans %= mod
else:
if (b, a) in dic:
s.add((b, a))
cnt1 = dic[(a, b)]
cnt2 = dic[(b, a)]
ans *= (pow(2, cnt1, mod) + pow(2, cnt2, mod) - 1) % mod
ans %= mod
else:
ans *= pow(2, dic[(a, b)])
ans %= mod
print(((ans + cnt - 1) % mod))
| false | 0 |
[
"- if (a > 0 and b > 0) or (a < 0 and b < 0):",
"+ if a * b > 0:",
"- elif (a < 0 and b > 0) or (a > 0 and b < 0):",
"+ else:",
"- if a != 0 and b != 0:",
"+ if a * b != 0:",
"- ans *= pow(2, dic[(a, b)], mod)",
"+ ans *= pow(2, dic[(a, b)])",
"- ans *= pow(2, dic[(a, b)], mod)",
"+ ans *= pow(2, dic[(a, b)])"
] | false | 0.043991 | 0.04042 | 1.088331 |
[
"s397598484",
"s084966338"
] |
u385574568
|
p02953
|
python
|
s797863887
|
s835165289
| 75 | 64 | 15,340 | 15,344 |
Accepted
|
Accepted
| 14.67 |
import math
import os
import random
import re
import sys
def check_non_decreasing_squares(n: int, a: list):
for i in range(1, n):
if a[i] != a[i - 1]:
if a[i] - 1 < a[i - 1]:
print("No")
sys.exit(0)
a[i] -= 1
print("Yes")
if __name__ == '__main__':
n = int(eval(input()))
a = list(map(int, input().rstrip().split()))
check_non_decreasing_squares(n, a)
|
import math
import os
import random
import re
import sys
def check_non_decreasing_squares(n: int, a: list):
p = a[0]
for i in range(1, n):
if a[i] > p:
p = a[i]
if p - a[i] == 1 or p - a[i] == 0:
continue
print("No")
exit(0)
print("Yes")
if __name__ == '__main__':
n = int(eval(input()))
a = list(map(int, input().rstrip().split()))
check_non_decreasing_squares(n, a)
| 19 | 21 | 449 | 463 |
import math
import os
import random
import re
import sys
def check_non_decreasing_squares(n: int, a: list):
for i in range(1, n):
if a[i] != a[i - 1]:
if a[i] - 1 < a[i - 1]:
print("No")
sys.exit(0)
a[i] -= 1
print("Yes")
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().rstrip().split()))
check_non_decreasing_squares(n, a)
|
import math
import os
import random
import re
import sys
def check_non_decreasing_squares(n: int, a: list):
p = a[0]
for i in range(1, n):
if a[i] > p:
p = a[i]
if p - a[i] == 1 or p - a[i] == 0:
continue
print("No")
exit(0)
print("Yes")
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().rstrip().split()))
check_non_decreasing_squares(n, a)
| false | 9.52381 |
[
"+ p = a[0]",
"- if a[i] != a[i - 1]:",
"- if a[i] - 1 < a[i - 1]:",
"- print(\"No\")",
"- sys.exit(0)",
"- a[i] -= 1",
"+ if a[i] > p:",
"+ p = a[i]",
"+ if p - a[i] == 1 or p - a[i] == 0:",
"+ continue",
"+ print(\"No\")",
"+ exit(0)"
] | false | 0.048964 | 0.112108 | 0.436754 |
[
"s797863887",
"s835165289"
] |
u366482170
|
p03043
|
python
|
s795361350
|
s796415264
| 81 | 44 | 2,940 | 3,316 |
Accepted
|
Accepted
| 45.68 |
import math
def main():
pos=0
n,k=list(map(int,input().split()))
nmen=1/n
for i in range(1,n+1):
ajs=(-(-math.log2(k/i)//1))
if ajs<=0: ajs=0
pos+=nmen*0.5**ajs
# print(ajs)
print(pos)
if __name__ == "__main__":
main()
|
import math
n,k=list(map(int,input().split()))
p=0
for i in range(n):
g=k/(i+1)
if i>=k:
p+=1/n
continue
x=-(-math.log2(g)//1)
p+=1/n*((0.5)**x)
print(p)
| 17 | 11 | 266 | 189 |
import math
def main():
pos = 0
n, k = list(map(int, input().split()))
nmen = 1 / n
for i in range(1, n + 1):
ajs = -(-math.log2(k / i) // 1)
if ajs <= 0:
ajs = 0
pos += nmen * 0.5**ajs
# print(ajs)
print(pos)
if __name__ == "__main__":
main()
|
import math
n, k = list(map(int, input().split()))
p = 0
for i in range(n):
g = k / (i + 1)
if i >= k:
p += 1 / n
continue
x = -(-math.log2(g) // 1)
p += 1 / n * ((0.5) ** x)
print(p)
| false | 35.294118 |
[
"-",
"-def main():",
"- pos = 0",
"- n, k = list(map(int, input().split()))",
"- nmen = 1 / n",
"- for i in range(1, n + 1):",
"- ajs = -(-math.log2(k / i) // 1)",
"- if ajs <= 0:",
"- ajs = 0",
"- pos += nmen * 0.5**ajs",
"- # print(ajs)",
"- print(pos)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n, k = list(map(int, input().split()))",
"+p = 0",
"+for i in range(n):",
"+ g = k / (i + 1)",
"+ if i >= k:",
"+ p += 1 / n",
"+ continue",
"+ x = -(-math.log2(g) // 1)",
"+ p += 1 / n * ((0.5) ** x)",
"+print(p)"
] | false | 0.088487 | 0.055067 | 1.60689 |
[
"s795361350",
"s796415264"
] |
u814781830
|
p02612
|
python
|
s078177342
|
s977809834
| 76 | 64 | 61,528 | 61,776 |
Accepted
|
Accepted
| 15.79 |
n = int(eval(input()))
print((1000-n%1000 if n%1000 > 0 else 0))
|
print(((1000-int(eval(input()))%1000)%1000))
| 2 | 1 | 57 | 36 |
n = int(eval(input()))
print((1000 - n % 1000 if n % 1000 > 0 else 0))
|
print(((1000 - int(eval(input())) % 1000) % 1000))
| false | 50 |
[
"-n = int(eval(input()))",
"-print((1000 - n % 1000 if n % 1000 > 0 else 0))",
"+print(((1000 - int(eval(input())) % 1000) % 1000))"
] | false | 0.086225 | 0.063382 | 1.360412 |
[
"s078177342",
"s977809834"
] |
u223646582
|
p03504
|
python
|
s402028584
|
s816595497
| 942 | 311 | 68,672 | 88,464 |
Accepted
|
Accepted
| 66.99 |
N, C = list(map(int, input().split()))
imos = [0]*(10**5+1)
pgs = []
for _ in range(N):
s, t, c = list(map(int, input().split()))
pgs.append((s, t, c))
pgs = sorted(pgs, key=lambda x: (x[2], x[0]))
for i in range(N):
s, t, c = pgs[i]
if i >= 1 and pgs[i-1][2] == pgs[i][2] and pgs[i-1][1] == pgs[i][0]:
imos[s] += 1
imos[t] -= 1
else:
imos[s-1] += 1
imos[t] -= 1
ans = 0
a = 0
for i in imos:
a += i
ans = max(ans, a)
print(ans)
|
from collections import defaultdict
N, C = list(map(int, input().split()))
D = defaultdict(list)
for _ in range(N):
s, t, c = list(map(int, input().split()))
D[c-1].append((s, t))
IMOS = [0]*(10**5+2)
for c in range(C):
D[c].sort(key=lambda x: x[0])
pt = -1
for i, (s, t) in enumerate(D[c]):
if s == pt:
IMOS[s+1] += 1
IMOS[t] -= 1
else:
IMOS[s-1] += 1
IMOS[t] -= 1
pt = t
ans = 0
a = 0
for i in IMOS:
a += i
ans = max(ans, a)
print(ans)
| 27 | 30 | 508 | 561 |
N, C = list(map(int, input().split()))
imos = [0] * (10**5 + 1)
pgs = []
for _ in range(N):
s, t, c = list(map(int, input().split()))
pgs.append((s, t, c))
pgs = sorted(pgs, key=lambda x: (x[2], x[0]))
for i in range(N):
s, t, c = pgs[i]
if i >= 1 and pgs[i - 1][2] == pgs[i][2] and pgs[i - 1][1] == pgs[i][0]:
imos[s] += 1
imos[t] -= 1
else:
imos[s - 1] += 1
imos[t] -= 1
ans = 0
a = 0
for i in imos:
a += i
ans = max(ans, a)
print(ans)
|
from collections import defaultdict
N, C = list(map(int, input().split()))
D = defaultdict(list)
for _ in range(N):
s, t, c = list(map(int, input().split()))
D[c - 1].append((s, t))
IMOS = [0] * (10**5 + 2)
for c in range(C):
D[c].sort(key=lambda x: x[0])
pt = -1
for i, (s, t) in enumerate(D[c]):
if s == pt:
IMOS[s + 1] += 1
IMOS[t] -= 1
else:
IMOS[s - 1] += 1
IMOS[t] -= 1
pt = t
ans = 0
a = 0
for i in IMOS:
a += i
ans = max(ans, a)
print(ans)
| false | 10 |
[
"+from collections import defaultdict",
"+",
"-imos = [0] * (10**5 + 1)",
"-pgs = []",
"+D = defaultdict(list)",
"- pgs.append((s, t, c))",
"-pgs = sorted(pgs, key=lambda x: (x[2], x[0]))",
"-for i in range(N):",
"- s, t, c = pgs[i]",
"- if i >= 1 and pgs[i - 1][2] == pgs[i][2] and pgs[i - 1][1] == pgs[i][0]:",
"- imos[s] += 1",
"- imos[t] -= 1",
"- else:",
"- imos[s - 1] += 1",
"- imos[t] -= 1",
"+ D[c - 1].append((s, t))",
"+IMOS = [0] * (10**5 + 2)",
"+for c in range(C):",
"+ D[c].sort(key=lambda x: x[0])",
"+ pt = -1",
"+ for i, (s, t) in enumerate(D[c]):",
"+ if s == pt:",
"+ IMOS[s + 1] += 1",
"+ IMOS[t] -= 1",
"+ else:",
"+ IMOS[s - 1] += 1",
"+ IMOS[t] -= 1",
"+ pt = t",
"-for i in imos:",
"+for i in IMOS:"
] | false | 0.117402 | 0.11372 | 1.032378 |
[
"s402028584",
"s816595497"
] |
u631277801
|
p03370
|
python
|
s903715945
|
s276623028
| 56 | 17 | 3,064 | 3,064 |
Accepted
|
Accepted
| 69.64 |
N,X = list(map(int, input().split()))
M = []
for i in range(N):
M.append(int(eval(input())))
ichi = sum(M)
ans = N
X -= ichi
M.sort()
i = 0
while X-M[i]>=0:
if X - M[i] >= 0:
X -= M[i]
ans += 1
continue
i += 1
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
n,x = li()
m = []
for _ in range(n):
m.append(ni())
msum = sum(m)
mmin = min(m)
print((n + (x-msum)//mmin))
| 21 | 23 | 281 | 565 |
N, X = list(map(int, input().split()))
M = []
for i in range(N):
M.append(int(eval(input())))
ichi = sum(M)
ans = N
X -= ichi
M.sort()
i = 0
while X - M[i] >= 0:
if X - M[i] >= 0:
X -= M[i]
ans += 1
continue
i += 1
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
n, x = li()
m = []
for _ in range(n):
m.append(ni())
msum = sum(m)
mmin = min(m)
print((n + (x - msum) // mmin))
| false | 8.695652 |
[
"-N, X = list(map(int, input().split()))",
"-M = []",
"-for i in range(N):",
"- M.append(int(eval(input())))",
"-ichi = sum(M)",
"-ans = N",
"-X -= ichi",
"-M.sort()",
"-i = 0",
"-while X - M[i] >= 0:",
"- if X - M[i] >= 0:",
"- X -= M[i]",
"- ans += 1",
"- continue",
"- i += 1",
"-print(ans)",
"+import sys",
"+",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**5)",
"+",
"+",
"+def li():",
"+ return list(map(int, stdin.readline().split()))",
"+",
"+",
"+def li_():",
"+ return [int(x) - 1 for x in stdin.readline().split()]",
"+",
"+",
"+def lf():",
"+ return list(map(float, stdin.readline().split()))",
"+",
"+",
"+def ls():",
"+ return stdin.readline().split()",
"+",
"+",
"+def ns():",
"+ return stdin.readline().rstrip()",
"+",
"+",
"+def lc():",
"+ return list(ns())",
"+",
"+",
"+def ni():",
"+ return int(stdin.readline())",
"+",
"+",
"+def nf():",
"+ return float(stdin.readline())",
"+",
"+",
"+n, x = li()",
"+m = []",
"+for _ in range(n):",
"+ m.append(ni())",
"+msum = sum(m)",
"+mmin = min(m)",
"+print((n + (x - msum) // mmin))"
] | false | 0.037646 | 0.037546 | 1.002656 |
[
"s903715945",
"s276623028"
] |
u073852194
|
p03031
|
python
|
s124829397
|
s919516447
| 66 | 52 | 3,064 | 3,064 |
Accepted
|
Accepted
| 21.21 |
n,m = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(m)]
P = list(map(int, input().split()))
c = 0
a = 0
for a in range(2**n):
a2 = format(a, 'b').zfill(n)
d = 0
for i in range(m):
o = 0
for j in range(S[i][0]):
o += int(a2[S[i][j+1]-1])
if o % 2 == P[i]:
d += 1
if d == m:
c += 1
print(c)
|
N,M = list(map(int,input().split()))
B = [tuple(map(int,input().split())) for _ in range(M)]
P = tuple(map(int,input().split()))
ans = 0
for i in range(2**N):
flag = True
for k in range(M):
on = 0
for j in range(B[k][0]):
if i>>(B[k][j+1]-1) & 1:
on += 1
if on%2 != P[k]:
flag = False
if flag:
ans += 1
print(ans)
| 17 | 22 | 372 | 454 |
n, m = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(m)]
P = list(map(int, input().split()))
c = 0
a = 0
for a in range(2**n):
a2 = format(a, "b").zfill(n)
d = 0
for i in range(m):
o = 0
for j in range(S[i][0]):
o += int(a2[S[i][j + 1] - 1])
if o % 2 == P[i]:
d += 1
if d == m:
c += 1
print(c)
|
N, M = list(map(int, input().split()))
B = [tuple(map(int, input().split())) for _ in range(M)]
P = tuple(map(int, input().split()))
ans = 0
for i in range(2**N):
flag = True
for k in range(M):
on = 0
for j in range(B[k][0]):
if i >> (B[k][j + 1] - 1) & 1:
on += 1
if on % 2 != P[k]:
flag = False
if flag:
ans += 1
print(ans)
| false | 22.727273 |
[
"-n, m = list(map(int, input().split()))",
"-S = [list(map(int, input().split())) for i in range(m)]",
"-P = list(map(int, input().split()))",
"-c = 0",
"-a = 0",
"-for a in range(2**n):",
"- a2 = format(a, \"b\").zfill(n)",
"- d = 0",
"- for i in range(m):",
"- o = 0",
"- for j in range(S[i][0]):",
"- o += int(a2[S[i][j + 1] - 1])",
"- if o % 2 == P[i]:",
"- d += 1",
"- if d == m:",
"- c += 1",
"-print(c)",
"+N, M = list(map(int, input().split()))",
"+B = [tuple(map(int, input().split())) for _ in range(M)]",
"+P = tuple(map(int, input().split()))",
"+ans = 0",
"+for i in range(2**N):",
"+ flag = True",
"+ for k in range(M):",
"+ on = 0",
"+ for j in range(B[k][0]):",
"+ if i >> (B[k][j + 1] - 1) & 1:",
"+ on += 1",
"+ if on % 2 != P[k]:",
"+ flag = False",
"+ if flag:",
"+ ans += 1",
"+print(ans)"
] | false | 0.040921 | 0.088512 | 0.462327 |
[
"s124829397",
"s919516447"
] |
u843175622
|
p03222
|
python
|
s693143762
|
s632795002
| 58 | 40 | 9,128 | 9,136 |
Accepted
|
Accepted
| 31.03 |
h, w, k = list(map(int, input().split()))
dp = [0] * w
mod = 10 ** 9 + 7
dp[0] = 1
for i in range(h):
next = [0] * w
for bit in range(1 << w - 1):
ok = True
for j in range(w - 2):
if bit >> j & 1 and bit >> j + 1 & 1:
ok = False
if ok:
moved = [False] * w
for j in range(w):
if bit >> j & 1:
next[j + 1] += dp[j]
next[j] += dp[j + 1]
moved[j] = moved[j + 1] = True
elif not moved[j]:
next[j] += dp[j]
dp = next
print((dp[k - 1] % mod))
|
h, w, k = list(map(int, input().split()))
dp = [0] * w
mod = 10 ** 9 + 7
comb = []
for bit in range(1 << w - 1):
ok = True
for j in range(w - 2):
if bit >> j & 1 and bit >> j + 1 & 1:
ok = False
if ok:
comb.append(bit)
dp[0] = 1
for i in range(h):
next = [0] * w
for bit in comb:
moved = [False] * w
for j in range(w):
if bit >> j & 1:
next[j + 1] += dp[j]
next[j] += dp[j + 1]
moved[j] = moved[j + 1] = True
elif not moved[j]:
next[j] += dp[j]
dp = next
print((dp[k - 1] % mod))
| 23 | 27 | 651 | 656 |
h, w, k = list(map(int, input().split()))
dp = [0] * w
mod = 10**9 + 7
dp[0] = 1
for i in range(h):
next = [0] * w
for bit in range(1 << w - 1):
ok = True
for j in range(w - 2):
if bit >> j & 1 and bit >> j + 1 & 1:
ok = False
if ok:
moved = [False] * w
for j in range(w):
if bit >> j & 1:
next[j + 1] += dp[j]
next[j] += dp[j + 1]
moved[j] = moved[j + 1] = True
elif not moved[j]:
next[j] += dp[j]
dp = next
print((dp[k - 1] % mod))
|
h, w, k = list(map(int, input().split()))
dp = [0] * w
mod = 10**9 + 7
comb = []
for bit in range(1 << w - 1):
ok = True
for j in range(w - 2):
if bit >> j & 1 and bit >> j + 1 & 1:
ok = False
if ok:
comb.append(bit)
dp[0] = 1
for i in range(h):
next = [0] * w
for bit in comb:
moved = [False] * w
for j in range(w):
if bit >> j & 1:
next[j + 1] += dp[j]
next[j] += dp[j + 1]
moved[j] = moved[j + 1] = True
elif not moved[j]:
next[j] += dp[j]
dp = next
print((dp[k - 1] % mod))
| false | 14.814815 |
[
"+comb = []",
"+for bit in range(1 << w - 1):",
"+ ok = True",
"+ for j in range(w - 2):",
"+ if bit >> j & 1 and bit >> j + 1 & 1:",
"+ ok = False",
"+ if ok:",
"+ comb.append(bit)",
"- for bit in range(1 << w - 1):",
"- ok = True",
"- for j in range(w - 2):",
"- if bit >> j & 1 and bit >> j + 1 & 1:",
"- ok = False",
"- if ok:",
"- moved = [False] * w",
"- for j in range(w):",
"- if bit >> j & 1:",
"- next[j + 1] += dp[j]",
"- next[j] += dp[j + 1]",
"- moved[j] = moved[j + 1] = True",
"- elif not moved[j]:",
"- next[j] += dp[j]",
"+ for bit in comb:",
"+ moved = [False] * w",
"+ for j in range(w):",
"+ if bit >> j & 1:",
"+ next[j + 1] += dp[j]",
"+ next[j] += dp[j + 1]",
"+ moved[j] = moved[j + 1] = True",
"+ elif not moved[j]:",
"+ next[j] += dp[j]"
] | false | 0.049544 | 0.046758 | 1.059582 |
[
"s693143762",
"s632795002"
] |
u294385082
|
p02714
|
python
|
s155978423
|
s266268223
| 1,154 | 1,064 | 9,200 | 9,208 |
Accepted
|
Accepted
| 7.8 |
n = int(eval(input()))
s = list(eval(input()))
r = s.count('R')
g = s.count('G')
b = len(s) - r - g
ans = r*g*b
for i in range(n-2):
for j in range(i+1,i+((n-i-1)//2)+1):
if s[i] != s[j] and s[i] != s[2*j - i] and s[j] != s[2*j - i]:
ans -= 1
print(ans)
|
n = int(eval(input()))
s = list(eval(input()))
r = s.count('R')
g = s.count('G')
b = n - r - g
ans = r*g*b
for i in range(n-2):
for j in range(i+1,i+((n-i-1)//2)+1):
if s[i] != s[j] and s[i] != s[2*j - i] and s[j] != s[2*j - i]:
ans -= 1
print(ans)
| 14 | 14 | 275 | 270 |
n = int(eval(input()))
s = list(eval(input()))
r = s.count("R")
g = s.count("G")
b = len(s) - r - g
ans = r * g * b
for i in range(n - 2):
for j in range(i + 1, i + ((n - i - 1) // 2) + 1):
if s[i] != s[j] and s[i] != s[2 * j - i] and s[j] != s[2 * j - i]:
ans -= 1
print(ans)
|
n = int(eval(input()))
s = list(eval(input()))
r = s.count("R")
g = s.count("G")
b = n - r - g
ans = r * g * b
for i in range(n - 2):
for j in range(i + 1, i + ((n - i - 1) // 2) + 1):
if s[i] != s[j] and s[i] != s[2 * j - i] and s[j] != s[2 * j - i]:
ans -= 1
print(ans)
| false | 0 |
[
"-b = len(s) - r - g",
"+b = n - r - g"
] | false | 0.09121 | 0.089573 | 1.018277 |
[
"s155978423",
"s266268223"
] |
u780962115
|
p03032
|
python
|
s290440295
|
s639991955
| 54 | 48 | 3,064 | 9,468 |
Accepted
|
Accepted
| 11.11 |
n,k=list(map(int,input().split()))
lists=list(map(int,input().split()))
ans=0
nums=min(n,k)
for j in range(1,nums+1):
#スライドするときの数 j=0,1,2,3,4......numsまでとることができる
#n<kの時max n かつかくjに対して取り除けるのはk-j回めまでである
#n>=kの時max k かつ かくjに対して取り除けるのはk-j回までである
for m in range(j+1):
sublist=lists[:m]+lists[n+m-j:]
sublist=sorted(sublist)
sublist.append(0)
del_some=0
while del_some<k-j and min(sublist)<0:
del sublist[0]
del_some+=1
p=sum(sublist)
ans=max(ans,p)
print(ans)
|
# equeue
from collections import deque
import heapq
def main():
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
res = 0
for pull in range(K+1):
push = K - pull
if push < 0 or push > N:
continue
for left_push in range(push+1):
tmp_que = deque(V)
tmp_heap = []
heapq.heapify(tmp_heap)
right_push = push - left_push
for _ in range(left_push):
heapq.heappush(tmp_heap, tmp_que.popleft())
for _ in range(right_push):
heapq.heappush(tmp_heap, tmp_que.pop())
tmp_res = sum(tmp_que)
for i in range(min(push, pull)):
x = heapq.heappop(tmp_heap)
if x >= 0:
heapq.heappush(tmp_heap,x)
break
res = max(res, sum(tmp_heap))
print(res)
return
if __name__ == "__main__":
main()
| 19 | 39 | 561 | 1,004 |
n, k = list(map(int, input().split()))
lists = list(map(int, input().split()))
ans = 0
nums = min(n, k)
for j in range(1, nums + 1):
# スライドするときの数 j=0,1,2,3,4......numsまでとることができる
# n<kの時max n かつかくjに対して取り除けるのはk-j回めまでである
# n>=kの時max k かつ かくjに対して取り除けるのはk-j回までである
for m in range(j + 1):
sublist = lists[:m] + lists[n + m - j :]
sublist = sorted(sublist)
sublist.append(0)
del_some = 0
while del_some < k - j and min(sublist) < 0:
del sublist[0]
del_some += 1
p = sum(sublist)
ans = max(ans, p)
print(ans)
|
# equeue
from collections import deque
import heapq
def main():
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
res = 0
for pull in range(K + 1):
push = K - pull
if push < 0 or push > N:
continue
for left_push in range(push + 1):
tmp_que = deque(V)
tmp_heap = []
heapq.heapify(tmp_heap)
right_push = push - left_push
for _ in range(left_push):
heapq.heappush(tmp_heap, tmp_que.popleft())
for _ in range(right_push):
heapq.heappush(tmp_heap, tmp_que.pop())
tmp_res = sum(tmp_que)
for i in range(min(push, pull)):
x = heapq.heappop(tmp_heap)
if x >= 0:
heapq.heappush(tmp_heap, x)
break
res = max(res, sum(tmp_heap))
print(res)
return
if __name__ == "__main__":
main()
| false | 51.282051 |
[
"-n, k = list(map(int, input().split()))",
"-lists = list(map(int, input().split()))",
"-ans = 0",
"-nums = min(n, k)",
"-for j in range(1, nums + 1):",
"- # スライドするときの数 j=0,1,2,3,4......numsまでとることができる",
"- # n<kの時max n かつかくjに対して取り除けるのはk-j回めまでである",
"- # n>=kの時max k かつ かくjに対して取り除けるのはk-j回までである",
"- for m in range(j + 1):",
"- sublist = lists[:m] + lists[n + m - j :]",
"- sublist = sorted(sublist)",
"- sublist.append(0)",
"- del_some = 0",
"- while del_some < k - j and min(sublist) < 0:",
"- del sublist[0]",
"- del_some += 1",
"- p = sum(sublist)",
"- ans = max(ans, p)",
"-print(ans)",
"+# equeue",
"+from collections import deque",
"+import heapq",
"+",
"+",
"+def main():",
"+ N, K = list(map(int, input().split()))",
"+ V = list(map(int, input().split()))",
"+ res = 0",
"+ for pull in range(K + 1):",
"+ push = K - pull",
"+ if push < 0 or push > N:",
"+ continue",
"+ for left_push in range(push + 1):",
"+ tmp_que = deque(V)",
"+ tmp_heap = []",
"+ heapq.heapify(tmp_heap)",
"+ right_push = push - left_push",
"+ for _ in range(left_push):",
"+ heapq.heappush(tmp_heap, tmp_que.popleft())",
"+ for _ in range(right_push):",
"+ heapq.heappush(tmp_heap, tmp_que.pop())",
"+ tmp_res = sum(tmp_que)",
"+ for i in range(min(push, pull)):",
"+ x = heapq.heappop(tmp_heap)",
"+ if x >= 0:",
"+ heapq.heappush(tmp_heap, x)",
"+ break",
"+ res = max(res, sum(tmp_heap))",
"+ print(res)",
"+ return",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.048699 | 0.142637 | 0.341421 |
[
"s290440295",
"s639991955"
] |
u046187684
|
p03088
|
python
|
s709396416
|
s830984479
| 263 | 18 | 6,288 | 3,064 |
Accepted
|
Accepted
| 93.16 |
from functools import lru_cache
def check(s):
bads = ["AGC", "ACG", "GAC"] + [b.format(_s) for b in ["AG{}C", "A{}GC"] for _s in "ACGT"]
return not any([x in s for x in bads])
def solve(string):
n = int(string)
@lru_cache(n * 4**3)
def dfs(pos, last3):
if pos == n:
return 1
ans = 0
for _s in "ACGT":
ans += dfs(pos + 1, last3[1:] + _s) if check(last3 + _s) else 0
return ans % (10**9 + 7)
return str(dfs(0, "TTT"))
if __name__ == '__main__':
print((solve(eval(input()))))
|
def solve(string):
n = int(string)
dp = [[0] * 4 for _ in range(n)]
dp[0] = [1] * 4
for i in range(1, n):
base = sum(dp[i - 1])
for j in range(4):
dp[i][j] = base
# "AGC", "ACG", "GAC"
if i >= 2:
dp[i][1] -= dp[i - 2][0] + dp[i - 2][2]
dp[i][2] -= dp[i - 2][0]
# "AG{}C", "A{}GC"
if i >= 3:
dp[i][1] -= dp[i - 3][0] * 3
dp[i][2] += dp[i - 3][2]
return str(sum(dp[n - 1]) % (10**9 + 7))
if __name__ == '__main__':
print((solve(eval(input()))))
| 25 | 22 | 586 | 591 |
from functools import lru_cache
def check(s):
bads = ["AGC", "ACG", "GAC"] + [
b.format(_s) for b in ["AG{}C", "A{}GC"] for _s in "ACGT"
]
return not any([x in s for x in bads])
def solve(string):
n = int(string)
@lru_cache(n * 4**3)
def dfs(pos, last3):
if pos == n:
return 1
ans = 0
for _s in "ACGT":
ans += dfs(pos + 1, last3[1:] + _s) if check(last3 + _s) else 0
return ans % (10**9 + 7)
return str(dfs(0, "TTT"))
if __name__ == "__main__":
print((solve(eval(input()))))
|
def solve(string):
n = int(string)
dp = [[0] * 4 for _ in range(n)]
dp[0] = [1] * 4
for i in range(1, n):
base = sum(dp[i - 1])
for j in range(4):
dp[i][j] = base
# "AGC", "ACG", "GAC"
if i >= 2:
dp[i][1] -= dp[i - 2][0] + dp[i - 2][2]
dp[i][2] -= dp[i - 2][0]
# "AG{}C", "A{}GC"
if i >= 3:
dp[i][1] -= dp[i - 3][0] * 3
dp[i][2] += dp[i - 3][2]
return str(sum(dp[n - 1]) % (10**9 + 7))
if __name__ == "__main__":
print((solve(eval(input()))))
| false | 12 |
[
"-from functools import lru_cache",
"-",
"-",
"-def check(s):",
"- bads = [\"AGC\", \"ACG\", \"GAC\"] + [",
"- b.format(_s) for b in [\"AG{}C\", \"A{}GC\"] for _s in \"ACGT\"",
"- ]",
"- return not any([x in s for x in bads])",
"-",
"-",
"-",
"- @lru_cache(n * 4**3)",
"- def dfs(pos, last3):",
"- if pos == n:",
"- return 1",
"- ans = 0",
"- for _s in \"ACGT\":",
"- ans += dfs(pos + 1, last3[1:] + _s) if check(last3 + _s) else 0",
"- return ans % (10**9 + 7)",
"-",
"- return str(dfs(0, \"TTT\"))",
"+ dp = [[0] * 4 for _ in range(n)]",
"+ dp[0] = [1] * 4",
"+ for i in range(1, n):",
"+ base = sum(dp[i - 1])",
"+ for j in range(4):",
"+ dp[i][j] = base",
"+ # \"AGC\", \"ACG\", \"GAC\"",
"+ if i >= 2:",
"+ dp[i][1] -= dp[i - 2][0] + dp[i - 2][2]",
"+ dp[i][2] -= dp[i - 2][0]",
"+ # \"AG{}C\", \"A{}GC\"",
"+ if i >= 3:",
"+ dp[i][1] -= dp[i - 3][0] * 3",
"+ dp[i][2] += dp[i - 3][2]",
"+ return str(sum(dp[n - 1]) % (10**9 + 7))"
] | false | 0.125088 | 0.036671 | 3.411042 |
[
"s709396416",
"s830984479"
] |
u046187684
|
p03282
|
python
|
s234529297
|
s981443181
| 179 | 163 | 38,256 | 38,256 |
Accepted
|
Accepted
| 8.94 |
def solve(string):
s, k = string.split()
if len(s) == 1:
return s
k = int(k)
for _s in s[:k]:
if _s != "1":
return _s
else:
return "1"
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
|
def solve(string):
s, k = string.split()
for _s in s[:int(k)]:
if _s != "1":
return _s
else:
return "1"
if __name__ == '__main__':
print((solve('\n'.join([eval(input()), eval(input())]))))
| 14 | 11 | 281 | 231 |
def solve(string):
s, k = string.split()
if len(s) == 1:
return s
k = int(k)
for _s in s[:k]:
if _s != "1":
return _s
else:
return "1"
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
|
def solve(string):
s, k = string.split()
for _s in s[: int(k)]:
if _s != "1":
return _s
else:
return "1"
if __name__ == "__main__":
print((solve("\n".join([eval(input()), eval(input())]))))
| false | 21.428571 |
[
"- if len(s) == 1:",
"- return s",
"- k = int(k)",
"- for _s in s[:k]:",
"+ for _s in s[: int(k)]:"
] | false | 0.044425 | 0.060884 | 0.729673 |
[
"s234529297",
"s981443181"
] |
u970308980
|
p02793
|
python
|
s052271581
|
s425056508
| 1,959 | 968 | 6,136 | 6,136 |
Accepted
|
Accepted
| 50.59 |
import sys
input = sys.stdin.readline
from fractions import gcd
def lcm(a, b):
return a * b // gcd(a, b)
def mod_inv(a, m):
return pow(a, m-2, m)
MOD = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
LCM = 1
for a in A:
LCM = lcm(LCM, a)
# ans = LCM * sum([mod_inv(a, MOD) for a in A]) % MOD
ans = 0
for a in A:
ans += LCM * mod_inv(a, MOD) % MOD
ans %= MOD
print(ans)
|
from fractions import gcd
def lcm(a, b):
return a * b // gcd(a, b)
def mod_inv(a, m):
return pow(a, m-2, m)
MOD = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
LCM = 1
for a in A:
LCM = lcm(LCM, a)
LCM %= MOD
# ans = LCM * sum([mod_inv(a, MOD) for a in A]) % MOD
ans = 0
for a in A:
ans += LCM * mod_inv(a, MOD) % MOD
ans %= MOD
print(ans)
| 29 | 28 | 444 | 416 |
import sys
input = sys.stdin.readline
from fractions import gcd
def lcm(a, b):
return a * b // gcd(a, b)
def mod_inv(a, m):
return pow(a, m - 2, m)
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
LCM = 1
for a in A:
LCM = lcm(LCM, a)
# ans = LCM * sum([mod_inv(a, MOD) for a in A]) % MOD
ans = 0
for a in A:
ans += LCM * mod_inv(a, MOD) % MOD
ans %= MOD
print(ans)
|
from fractions import gcd
def lcm(a, b):
return a * b // gcd(a, b)
def mod_inv(a, m):
return pow(a, m - 2, m)
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
LCM = 1
for a in A:
LCM = lcm(LCM, a)
LCM %= MOD
# ans = LCM * sum([mod_inv(a, MOD) for a in A]) % MOD
ans = 0
for a in A:
ans += LCM * mod_inv(a, MOD) % MOD
ans %= MOD
print(ans)
| false | 3.448276 |
[
"-import sys",
"-",
"-input = sys.stdin.readline",
"+LCM %= MOD"
] | false | 0.045291 | 0.065627 | 0.69012 |
[
"s052271581",
"s425056508"
] |
u508732591
|
p02315
|
python
|
s559384301
|
s646592951
| 760 | 440 | 26,900 | 6,664 |
Accepted
|
Accepted
| 42.11 |
from fractions import gcd
from functools import reduce
N,W = list(map(int, input().split()))
v = [0]*(N+1)
wtemp = [0]*(N+1)
for i in range(1,N+1):
v[i],wtemp[i] = list(map(int, input().split()))
gcdw = reduce(gcd,wtemp+[W])
w = list([x//gcdw for x in wtemp])
W2 = W//gcdw
dp = [[0]*(W2+1) for y in range(N+1)]
for i in range(1,N+1):
dp[i][0:w[i]] = dp[i-1][0:w[i]]
for j in range(w[i], W2+1):
dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i])
print((dp[N][W2]))
|
N,W = list(map(int, input().split()))
dp = [0]*(W+1)
temp = [0]*(W+1)
for i in range(1,N+1):
v,w = list(map(int,input().split()))
for j in range(1, W+1):
if w <= j and v + temp[j-w] > temp[j]:
dp[j] = temp[j-w]+v
temp[0:W+1] = dp[0:W+1]
print((dp[W]))
| 22 | 12 | 496 | 282 |
from fractions import gcd
from functools import reduce
N, W = list(map(int, input().split()))
v = [0] * (N + 1)
wtemp = [0] * (N + 1)
for i in range(1, N + 1):
v[i], wtemp[i] = list(map(int, input().split()))
gcdw = reduce(gcd, wtemp + [W])
w = list([x // gcdw for x in wtemp])
W2 = W // gcdw
dp = [[0] * (W2 + 1) for y in range(N + 1)]
for i in range(1, N + 1):
dp[i][0 : w[i]] = dp[i - 1][0 : w[i]]
for j in range(w[i], W2 + 1):
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i])
print((dp[N][W2]))
|
N, W = list(map(int, input().split()))
dp = [0] * (W + 1)
temp = [0] * (W + 1)
for i in range(1, N + 1):
v, w = list(map(int, input().split()))
for j in range(1, W + 1):
if w <= j and v + temp[j - w] > temp[j]:
dp[j] = temp[j - w] + v
temp[0 : W + 1] = dp[0 : W + 1]
print((dp[W]))
| false | 45.454545 |
[
"-from fractions import gcd",
"-from functools import reduce",
"-",
"-v = [0] * (N + 1)",
"-wtemp = [0] * (N + 1)",
"+dp = [0] * (W + 1)",
"+temp = [0] * (W + 1)",
"- v[i], wtemp[i] = list(map(int, input().split()))",
"-gcdw = reduce(gcd, wtemp + [W])",
"-w = list([x // gcdw for x in wtemp])",
"-W2 = W // gcdw",
"-dp = [[0] * (W2 + 1) for y in range(N + 1)]",
"-for i in range(1, N + 1):",
"- dp[i][0 : w[i]] = dp[i - 1][0 : w[i]]",
"- for j in range(w[i], W2 + 1):",
"- dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i])",
"-print((dp[N][W2]))",
"+ v, w = list(map(int, input().split()))",
"+ for j in range(1, W + 1):",
"+ if w <= j and v + temp[j - w] > temp[j]:",
"+ dp[j] = temp[j - w] + v",
"+ temp[0 : W + 1] = dp[0 : W + 1]",
"+print((dp[W]))"
] | false | 0.109992 | 0.03845 | 2.860618 |
[
"s559384301",
"s646592951"
] |
u086566114
|
p02412
|
python
|
s130967232
|
s902365252
| 450 | 190 | 6,324 | 6,412 |
Accepted
|
Accepted
| 57.78 |
while True:
[n, m] = [int(x) for x in input().split()]
if [n, m] == [0, 0]:
break
data = []
for x in range(n, 2, -1):
if 3 * x - 2 < m:
break
for y in range(x - 1, 1, -1):
for z in range(y - 1, 0, -1):
s = x + y + z
if s < m:
break
if s == m:
data.append(s)
print((len(data)))
|
def get_num(n, m):
ans = 0
for x in range(n, 2, -1):
if 3 * x - 2 < m:
return ans
for y in range(x - 1, 1, -1):
if x + 2 * y - 1 < m:
break
for z in range(y - 1, 0, -1):
s = x + y + z
if s == m:
ans += 1
return ans
while True:
[n, m] = [int(x) for x in input().split()]
if [n, m] == [0, 0]:
break
print((get_num(n, m)))
| 18 | 20 | 453 | 494 |
while True:
[n, m] = [int(x) for x in input().split()]
if [n, m] == [0, 0]:
break
data = []
for x in range(n, 2, -1):
if 3 * x - 2 < m:
break
for y in range(x - 1, 1, -1):
for z in range(y - 1, 0, -1):
s = x + y + z
if s < m:
break
if s == m:
data.append(s)
print((len(data)))
|
def get_num(n, m):
ans = 0
for x in range(n, 2, -1):
if 3 * x - 2 < m:
return ans
for y in range(x - 1, 1, -1):
if x + 2 * y - 1 < m:
break
for z in range(y - 1, 0, -1):
s = x + y + z
if s == m:
ans += 1
return ans
while True:
[n, m] = [int(x) for x in input().split()]
if [n, m] == [0, 0]:
break
print((get_num(n, m)))
| false | 10 |
[
"+def get_num(n, m):",
"+ ans = 0",
"+ for x in range(n, 2, -1):",
"+ if 3 * x - 2 < m:",
"+ return ans",
"+ for y in range(x - 1, 1, -1):",
"+ if x + 2 * y - 1 < m:",
"+ break",
"+ for z in range(y - 1, 0, -1):",
"+ s = x + y + z",
"+ if s == m:",
"+ ans += 1",
"+ return ans",
"+",
"+",
"- data = []",
"- for x in range(n, 2, -1):",
"- if 3 * x - 2 < m:",
"- break",
"- for y in range(x - 1, 1, -1):",
"- for z in range(y - 1, 0, -1):",
"- s = x + y + z",
"- if s < m:",
"- break",
"- if s == m:",
"- data.append(s)",
"- print((len(data)))",
"+ print((get_num(n, m)))"
] | false | 0.047894 | 0.048277 | 0.992071 |
[
"s130967232",
"s902365252"
] |
u254871849
|
p03645
|
python
|
s955108084
|
s532033683
| 485 | 188 | 76,048 | 46,660 |
Accepted
|
Accepted
| 61.24 |
import sys
n, m, *ab = list(map(int, sys.stdin.read().split()))
g = [set() for _ in range(n+1)]
for a, b in zip(*[iter(ab)] * 2):
g[a].add(b)
g[b].add(a)
def main():
return 'POSSIBLE' if g[1] & g[n] else 'IMPOSSIBLE'
if __name__ == '__main__':
ans = main()
print(ans)
|
import sys
n, m, *ab = list(map(int, sys.stdin.read().split()))
g_1 = set()
g_n = set()
for a, b in zip(*[iter(ab)] * 2):
if a == 1 or b == 1:
g_1.add(b)
elif a == n or b == n:
g_n.add(a)
def main():
return 'POSSIBLE' if g_1 & g_n else 'IMPOSSIBLE'
if __name__ == '__main__':
ans = main()
print(ans)
| 14 | 17 | 297 | 348 |
import sys
n, m, *ab = list(map(int, sys.stdin.read().split()))
g = [set() for _ in range(n + 1)]
for a, b in zip(*[iter(ab)] * 2):
g[a].add(b)
g[b].add(a)
def main():
return "POSSIBLE" if g[1] & g[n] else "IMPOSSIBLE"
if __name__ == "__main__":
ans = main()
print(ans)
|
import sys
n, m, *ab = list(map(int, sys.stdin.read().split()))
g_1 = set()
g_n = set()
for a, b in zip(*[iter(ab)] * 2):
if a == 1 or b == 1:
g_1.add(b)
elif a == n or b == n:
g_n.add(a)
def main():
return "POSSIBLE" if g_1 & g_n else "IMPOSSIBLE"
if __name__ == "__main__":
ans = main()
print(ans)
| false | 17.647059 |
[
"-g = [set() for _ in range(n + 1)]",
"+g_1 = set()",
"+g_n = set()",
"- g[a].add(b)",
"- g[b].add(a)",
"+ if a == 1 or b == 1:",
"+ g_1.add(b)",
"+ elif a == n or b == n:",
"+ g_n.add(a)",
"- return \"POSSIBLE\" if g[1] & g[n] else \"IMPOSSIBLE\"",
"+ return \"POSSIBLE\" if g_1 & g_n else \"IMPOSSIBLE\""
] | false | 0.106029 | 0.044048 | 2.407132 |
[
"s955108084",
"s532033683"
] |
u463068683
|
p02572
|
python
|
s776759005
|
s498994665
| 215 | 126 | 31,384 | 31,440 |
Accepted
|
Accepted
| 41.4 |
n = int(eval(input()))
la = list(map(int, input().split()))
MOD = (10**9+7)
ans = 0
nn = 0
for i in range(n):
ans %= MOD
ans += la[i]%MOD
nn %= MOD
nn += (la[i]**2)%MOD
ans = (ans**2-nn+10**9+7)*pow(2, -1, MOD)%MOD
print(ans)
|
n = int(eval(input()))
la = list(map(int, input().split()))
MOD = 10**9+7
s1 = sum(la)
s2 = sum([x**2 for x in la])
ans = (s1*s1-s2)//2%MOD
print(ans)
| 12 | 7 | 238 | 150 |
n = int(eval(input()))
la = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0
nn = 0
for i in range(n):
ans %= MOD
ans += la[i] % MOD
nn %= MOD
nn += (la[i] ** 2) % MOD
ans = (ans**2 - nn + 10**9 + 7) * pow(2, -1, MOD) % MOD
print(ans)
|
n = int(eval(input()))
la = list(map(int, input().split()))
MOD = 10**9 + 7
s1 = sum(la)
s2 = sum([x**2 for x in la])
ans = (s1 * s1 - s2) // 2 % MOD
print(ans)
| false | 41.666667 |
[
"-ans = 0",
"-nn = 0",
"-for i in range(n):",
"- ans %= MOD",
"- ans += la[i] % MOD",
"- nn %= MOD",
"- nn += (la[i] ** 2) % MOD",
"-ans = (ans**2 - nn + 10**9 + 7) * pow(2, -1, MOD) % MOD",
"+s1 = sum(la)",
"+s2 = sum([x**2 for x in la])",
"+ans = (s1 * s1 - s2) // 2 % MOD"
] | false | 0.008287 | 0.069241 | 0.119679 |
[
"s776759005",
"s498994665"
] |
u608088992
|
p03937
|
python
|
s980675235
|
s544480994
| 24 | 19 | 3,316 | 3,064 |
Accepted
|
Accepted
| 20.83 |
import sys
from collections import deque
def solve():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [input().strip("\n") for _ in range(H)]
q = deque()
q.append((0, 0))
visited = [[False] * W for _ in range(H)]
possible = True
while q:
nh, nw = q.popleft()
if not visited[nh][nw]:
visited[nh][nw] = True
count = 0
if 0 <= nh + 1 < H and A[nh + 1][nw] == "#":
if 0 <= nw - 1 and A[nh+1][nw-1] == "#":
possible = False
break
q.append((nh+1, nw))
count += 1
if 0 <= nw + 1 < W and A[nh][nw+1] == "#":
if 0 <= nh - 1 and A[nh-1][nw+1] == "#":
possible = False
break
q.append((nh, nw+1))
count += 1
if count == 2:
possible = False
break
else:
if not visited[H-1][W-1]: possible = False
print(("Possible" if possible else "Impossible"))
return 0
if __name__ =="__main__":
solve()
|
import sys
def solve():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [input().strip("\n") for _ in range(H)]
count = 0
for h in range(H):
for w in range(W):
if A[h][w] == "#": count += 1
if count + 1 == H + W: print("Possible")
else: print("Impossible")
return 0
if __name__ == "__main__":
solve()
| 39 | 18 | 1,170 | 393 |
import sys
from collections import deque
def solve():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [input().strip("\n") for _ in range(H)]
q = deque()
q.append((0, 0))
visited = [[False] * W for _ in range(H)]
possible = True
while q:
nh, nw = q.popleft()
if not visited[nh][nw]:
visited[nh][nw] = True
count = 0
if 0 <= nh + 1 < H and A[nh + 1][nw] == "#":
if 0 <= nw - 1 and A[nh + 1][nw - 1] == "#":
possible = False
break
q.append((nh + 1, nw))
count += 1
if 0 <= nw + 1 < W and A[nh][nw + 1] == "#":
if 0 <= nh - 1 and A[nh - 1][nw + 1] == "#":
possible = False
break
q.append((nh, nw + 1))
count += 1
if count == 2:
possible = False
break
else:
if not visited[H - 1][W - 1]:
possible = False
print(("Possible" if possible else "Impossible"))
return 0
if __name__ == "__main__":
solve()
|
import sys
def solve():
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [input().strip("\n") for _ in range(H)]
count = 0
for h in range(H):
for w in range(W):
if A[h][w] == "#":
count += 1
if count + 1 == H + W:
print("Possible")
else:
print("Impossible")
return 0
if __name__ == "__main__":
solve()
| false | 53.846154 |
[
"-from collections import deque",
"- q = deque()",
"- q.append((0, 0))",
"- visited = [[False] * W for _ in range(H)]",
"- possible = True",
"- while q:",
"- nh, nw = q.popleft()",
"- if not visited[nh][nw]:",
"- visited[nh][nw] = True",
"- count = 0",
"- if 0 <= nh + 1 < H and A[nh + 1][nw] == \"#\":",
"- if 0 <= nw - 1 and A[nh + 1][nw - 1] == \"#\":",
"- possible = False",
"- break",
"- q.append((nh + 1, nw))",
"+ count = 0",
"+ for h in range(H):",
"+ for w in range(W):",
"+ if A[h][w] == \"#\":",
"- if 0 <= nw + 1 < W and A[nh][nw + 1] == \"#\":",
"- if 0 <= nh - 1 and A[nh - 1][nw + 1] == \"#\":",
"- possible = False",
"- break",
"- q.append((nh, nw + 1))",
"- count += 1",
"- if count == 2:",
"- possible = False",
"- break",
"+ if count + 1 == H + W:",
"+ print(\"Possible\")",
"- if not visited[H - 1][W - 1]:",
"- possible = False",
"- print((\"Possible\" if possible else \"Impossible\"))",
"+ print(\"Impossible\")"
] | false | 0.037547 | 0.036101 | 1.04004 |
[
"s980675235",
"s544480994"
] |
u787562674
|
p03363
|
python
|
s241017574
|
s462195054
| 224 | 156 | 41,472 | 41,472 |
Accepted
|
Accepted
| 30.36 |
from collections import Counter
from itertools import accumulate
N = int(eval(input()))
inputs = [int(i) for i in input().split()]
ans = 0
ruisekiwa = list(accumulate(inputs))
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)
for key, value in list(counter_ruiseki.items()):
if key == 0 and value == 1:
ans += value
continue
elif key == 0 and value > 1:
ans += value
if value > 1:
ans += sum(list(range(value)))
print(ans)
|
from collections import Counter
from itertools import accumulate
N = int(eval(input()))
inputs = [int(i) for i in input().split()]
ans = 0
ruisekiwa = list(accumulate(inputs))
for key, value in list(Counter(ruisekiwa).items()):
if key == 0 and value == 1:
ans += value
continue
elif key == 0 and value > 1:
ans += value
if value > 1:
ans += value * (value - 1) // 2
print(ans)
| 22 | 20 | 485 | 433 |
from collections import Counter
from itertools import accumulate
N = int(eval(input()))
inputs = [int(i) for i in input().split()]
ans = 0
ruisekiwa = list(accumulate(inputs))
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)
for key, value in list(counter_ruiseki.items()):
if key == 0 and value == 1:
ans += value
continue
elif key == 0 and value > 1:
ans += value
if value > 1:
ans += sum(list(range(value)))
print(ans)
|
from collections import Counter
from itertools import accumulate
N = int(eval(input()))
inputs = [int(i) for i in input().split()]
ans = 0
ruisekiwa = list(accumulate(inputs))
for key, value in list(Counter(ruisekiwa).items()):
if key == 0 and value == 1:
ans += value
continue
elif key == 0 and value > 1:
ans += value
if value > 1:
ans += value * (value - 1) // 2
print(ans)
| false | 9.090909 |
[
"-ruisekiwa.sort()",
"-counter_ruiseki = Counter(ruisekiwa)",
"-for key, value in list(counter_ruiseki.items()):",
"+for key, value in list(Counter(ruisekiwa).items()):",
"- ans += sum(list(range(value)))",
"+ ans += value * (value - 1) // 2"
] | false | 0.035179 | 0.042243 | 0.832768 |
[
"s241017574",
"s462195054"
] |
u951601135
|
p03835
|
python
|
s768057919
|
s349018509
| 1,460 | 484 | 2,940 | 2,940 |
Accepted
|
Accepted
| 66.85 |
K , S = list(map(int,input().split()))
count = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if(0 <= z <= K):
count += 1
print(count)
|
K , S = list(map(int,input().split()))
count = 0
for x in range(K+1):
for y in range(max(0,S-K-x), min(K+1,S-x+1)):
count += 1
print(count)
| 8 | 6 | 166 | 144 |
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if 0 <= z <= K:
count += 1
print(count)
|
K, S = list(map(int, input().split()))
count = 0
for x in range(K + 1):
for y in range(max(0, S - K - x), min(K + 1, S - x + 1)):
count += 1
print(count)
| false | 25 |
[
"- for y in range(K + 1):",
"- z = S - x - y",
"- if 0 <= z <= K:",
"- count += 1",
"+ for y in range(max(0, S - K - x), min(K + 1, S - x + 1)):",
"+ count += 1"
] | false | 0.038085 | 0.075086 | 0.507211 |
[
"s768057919",
"s349018509"
] |
u934246119
|
p03361
|
python
|
s785492140
|
s525149975
| 21 | 19 | 3,064 | 3,064 |
Accepted
|
Accepted
| 9.52 |
h, w = list(map(int, input().split()))
s = [[] for i in range(h)]
for i in range(h):
s[i] = eval(input())
s2 = [[False for j in range(w)] for i in range(h)]
ssum = 0
ssum2 = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
# print(i, j, s[i][j])
if 0 < i:
# print(s[i-1][j])
if s[i-1][j] == "#":
s2[i][j] = True
if i < h-1:
# print(s[i+1][j])
if s[i+1][j] == "#":
s2[i][j] = True
if 0 < j:
# print(s[i][j-1])
if s[i][j-1] == "#":
s2[i][j] = True
if j < w-1:
# print(s[i][j+1])
if s[i][j+1] == "#":
s2[i][j] = True
if s2[i][j]:
ssum2 += 1
ssum += 1
if ssum == ssum2:
print('Yes')
else:
print('No')
|
h, w = map(int, input().split())
s = [[] for i in range(h+2)]
s[0] = '.'*(w+2)
for i in range(1, h+1):
s[i] = '.' + input() + '.'
s[h+1] = '.'*(w+2)
s2 = [[False for j in range(w)] for i in range(h)]
judge = True
for i in range(1, h+1):
for j in range(1, w+1):
if s[i][j] == "#":
if [s[i+1][j], s[i-1][j], s[i][j-1], s[i][j+1]] \
== ['.', '.', '.', '.']:
judge = False
else:
continue
if not judge:
break
if not judge:
break
if judge:
print('Yes')
else:
print('No')
| 35 | 25 | 962 | 605 |
h, w = list(map(int, input().split()))
s = [[] for i in range(h)]
for i in range(h):
s[i] = eval(input())
s2 = [[False for j in range(w)] for i in range(h)]
ssum = 0
ssum2 = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
# print(i, j, s[i][j])
if 0 < i:
# print(s[i-1][j])
if s[i - 1][j] == "#":
s2[i][j] = True
if i < h - 1:
# print(s[i+1][j])
if s[i + 1][j] == "#":
s2[i][j] = True
if 0 < j:
# print(s[i][j-1])
if s[i][j - 1] == "#":
s2[i][j] = True
if j < w - 1:
# print(s[i][j+1])
if s[i][j + 1] == "#":
s2[i][j] = True
if s2[i][j]:
ssum2 += 1
ssum += 1
if ssum == ssum2:
print("Yes")
else:
print("No")
|
h, w = map(int, input().split())
s = [[] for i in range(h + 2)]
s[0] = "." * (w + 2)
for i in range(1, h + 1):
s[i] = "." + input() + "."
s[h + 1] = "." * (w + 2)
s2 = [[False for j in range(w)] for i in range(h)]
judge = True
for i in range(1, h + 1):
for j in range(1, w + 1):
if s[i][j] == "#":
if [s[i + 1][j], s[i - 1][j], s[i][j - 1], s[i][j + 1]] == [
".",
".",
".",
".",
]:
judge = False
else:
continue
if not judge:
break
if not judge:
break
if judge:
print("Yes")
else:
print("No")
| false | 28.571429 |
[
"-h, w = list(map(int, input().split()))",
"-s = [[] for i in range(h)]",
"-for i in range(h):",
"- s[i] = eval(input())",
"+h, w = map(int, input().split())",
"+s = [[] for i in range(h + 2)]",
"+s[0] = \".\" * (w + 2)",
"+for i in range(1, h + 1):",
"+ s[i] = \".\" + input() + \".\"",
"+s[h + 1] = \".\" * (w + 2)",
"-ssum = 0",
"-ssum2 = 0",
"-for i in range(h):",
"- for j in range(w):",
"+judge = True",
"+for i in range(1, h + 1):",
"+ for j in range(1, w + 1):",
"- # print(i, j, s[i][j])",
"- if 0 < i:",
"- # print(s[i-1][j])",
"- if s[i - 1][j] == \"#\":",
"- s2[i][j] = True",
"- if i < h - 1:",
"- # print(s[i+1][j])",
"- if s[i + 1][j] == \"#\":",
"- s2[i][j] = True",
"- if 0 < j:",
"- # print(s[i][j-1])",
"- if s[i][j - 1] == \"#\":",
"- s2[i][j] = True",
"- if j < w - 1:",
"- # print(s[i][j+1])",
"- if s[i][j + 1] == \"#\":",
"- s2[i][j] = True",
"- if s2[i][j]:",
"- ssum2 += 1",
"- ssum += 1",
"-if ssum == ssum2:",
"+ if [s[i + 1][j], s[i - 1][j], s[i][j - 1], s[i][j + 1]] == [",
"+ \".\",",
"+ \".\",",
"+ \".\",",
"+ \".\",",
"+ ]:",
"+ judge = False",
"+ else:",
"+ continue",
"+ if not judge:",
"+ break",
"+ if not judge:",
"+ break",
"+if judge:"
] | false | 0.044751 | 0.046713 | 0.957989 |
[
"s785492140",
"s525149975"
] |
u729133443
|
p03987
|
python
|
s903771347
|
s847636225
| 1,212 | 1,100 | 25,884 | 25,884 |
Accepted
|
Accepted
| 9.24 |
from bisect import*
class BTreeNode:
def __init__(self):self.key,self.child=[],[]
class BTree:
def __init__(self):self.root=BTreeNode()
def search_higher(self,key):
ptr=self.root
ret=None
while ptr.child:
i=bisect(ptr.key,key)
if i!=len(ptr.key):ret=ptr.key[i]
ptr=ptr.child[i]
i=bisect(ptr.key,key)
if i!=len(ptr.key):ret=ptr.key[i]
return ret
def search_lower(self,key):
ptr=self.root
ret=None
while ptr.child:
i=bisect_left(ptr.key,key)
if i:ret=ptr.key[i-1]
ptr=ptr.child[i]
i=bisect_left(ptr.key,key)
if i:ret=ptr.key[i-1]
return ret
def insert(self,key):
def insert_rec(ptr):
b_size=512
if not ptr.child:
insort(ptr.key,key)
if len(ptr.key)==b_size*2-1:
ret=BTreeNode()
ret.key=ptr.key[:b_size]
ptr.key=ptr.key[b_size:]
return ret
else:
i=bisect(ptr.key,key)
tmp=insert_rec(ptr.child[i])
if tmp:
ptr.key.insert(i,tmp.key.pop())
ptr.child.insert(i,tmp)
if len(ptr.child)==b_size*2:
ret=BTreeNode()
ret.child=ptr.child[:b_size]
ptr.child=ptr.child[b_size:]
ret.key=ptr.key[:b_size]
ptr.key=ptr.key[b_size:]
return ret
tmp=insert_rec(self.root)
if tmp:
root=BTreeNode()
root.key=[tmp.key.pop()]
root.child=[tmp,self.root]
self.root=root
def main():
n,*a=list(map(int,open(0).read().split()))
l=[0]*n
for i,v in enumerate(a,1):l[v-1]=i
t=BTree()
t.insert(0)
t.insert(n+1)
c=0
for i,v in enumerate(l,1):
c+=(t.search_higher(v)-v)*(v-t.search_lower(v))*i
t.insert(v)
print(c)
main()
|
from bisect import*
class BTreeNode:
def __init__(self):self.key,self.child=[],[]
root=BTreeNode()
def main():
def search_higher(key):
ptr=root
ret=None
while ptr.child:
i=bisect(ptr.key,key)
if i!=len(ptr.key):ret=ptr.key[i]
ptr=ptr.child[i]
i=bisect(ptr.key,key)
if i!=len(ptr.key):ret=ptr.key[i]
return ret
def search_lower(key):
ptr=root
ret=None
while ptr.child:
i=bisect_left(ptr.key,key)
if i:ret=ptr.key[i-1]
ptr=ptr.child[i]
i=bisect_left(ptr.key,key)
if i:ret=ptr.key[i-1]
return ret
def insert_rec(ptr,key):
b_size=512
if not ptr.child:
insort(ptr.key,key)
if len(ptr.key)==b_size*2-1:
ret=BTreeNode()
ret.key=ptr.key[:b_size]
ptr.key=ptr.key[b_size:]
return ret
else:
i=bisect(ptr.key,key)
tmp=insert_rec(ptr.child[i],key)
if tmp:
ptr.key.insert(i,tmp.key.pop())
ptr.child.insert(i,tmp)
if len(ptr.child)==b_size*2:
ret=BTreeNode()
ret.child=ptr.child[:b_size]
ptr.child=ptr.child[b_size:]
ret.key=ptr.key[:b_size]
ptr.key=ptr.key[b_size:]
return ret
def insert(key):
global root
tmp=insert_rec(root,key)
if tmp:
p=BTreeNode()
p.key=[tmp.key.pop()]
p.child=[tmp,root]
root=p
n,*a=list(map(int,open(0).read().split()))
l=[0]*n
for i,v in enumerate(a,1):l[v-1]=i
insert(0)
insert(n+1)
c=0
for i,v in enumerate(l,1):
c+=(search_higher(v)-v)*(v-search_lower(v))*i
insert(v)
print(c)
main()
| 67 | 66 | 2,154 | 1,980 |
from bisect import *
class BTreeNode:
def __init__(self):
self.key, self.child = [], []
class BTree:
def __init__(self):
self.root = BTreeNode()
def search_higher(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
ptr = ptr.child[i]
i = bisect(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
return ret
def search_lower(self, key):
ptr = self.root
ret = None
while ptr.child:
i = bisect_left(ptr.key, key)
if i:
ret = ptr.key[i - 1]
ptr = ptr.child[i]
i = bisect_left(ptr.key, key)
if i:
ret = ptr.key[i - 1]
return ret
def insert(self, key):
def insert_rec(ptr):
b_size = 512
if not ptr.child:
insort(ptr.key, key)
if len(ptr.key) == b_size * 2 - 1:
ret = BTreeNode()
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
else:
i = bisect(ptr.key, key)
tmp = insert_rec(ptr.child[i])
if tmp:
ptr.key.insert(i, tmp.key.pop())
ptr.child.insert(i, tmp)
if len(ptr.child) == b_size * 2:
ret = BTreeNode()
ret.child = ptr.child[:b_size]
ptr.child = ptr.child[b_size:]
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
tmp = insert_rec(self.root)
if tmp:
root = BTreeNode()
root.key = [tmp.key.pop()]
root.child = [tmp, self.root]
self.root = root
def main():
n, *a = list(map(int, open(0).read().split()))
l = [0] * n
for i, v in enumerate(a, 1):
l[v - 1] = i
t = BTree()
t.insert(0)
t.insert(n + 1)
c = 0
for i, v in enumerate(l, 1):
c += (t.search_higher(v) - v) * (v - t.search_lower(v)) * i
t.insert(v)
print(c)
main()
|
from bisect import *
class BTreeNode:
def __init__(self):
self.key, self.child = [], []
root = BTreeNode()
def main():
def search_higher(key):
ptr = root
ret = None
while ptr.child:
i = bisect(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
ptr = ptr.child[i]
i = bisect(ptr.key, key)
if i != len(ptr.key):
ret = ptr.key[i]
return ret
def search_lower(key):
ptr = root
ret = None
while ptr.child:
i = bisect_left(ptr.key, key)
if i:
ret = ptr.key[i - 1]
ptr = ptr.child[i]
i = bisect_left(ptr.key, key)
if i:
ret = ptr.key[i - 1]
return ret
def insert_rec(ptr, key):
b_size = 512
if not ptr.child:
insort(ptr.key, key)
if len(ptr.key) == b_size * 2 - 1:
ret = BTreeNode()
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
else:
i = bisect(ptr.key, key)
tmp = insert_rec(ptr.child[i], key)
if tmp:
ptr.key.insert(i, tmp.key.pop())
ptr.child.insert(i, tmp)
if len(ptr.child) == b_size * 2:
ret = BTreeNode()
ret.child = ptr.child[:b_size]
ptr.child = ptr.child[b_size:]
ret.key = ptr.key[:b_size]
ptr.key = ptr.key[b_size:]
return ret
def insert(key):
global root
tmp = insert_rec(root, key)
if tmp:
p = BTreeNode()
p.key = [tmp.key.pop()]
p.child = [tmp, root]
root = p
n, *a = list(map(int, open(0).read().split()))
l = [0] * n
for i, v in enumerate(a, 1):
l[v - 1] = i
insert(0)
insert(n + 1)
c = 0
for i, v in enumerate(l, 1):
c += (search_higher(v) - v) * (v - search_lower(v)) * i
insert(v)
print(c)
main()
| false | 1.492537 |
[
"-class BTree:",
"- def __init__(self):",
"- self.root = BTreeNode()",
"+root = BTreeNode()",
"- def search_higher(self, key):",
"- ptr = self.root",
"+",
"+def main():",
"+ def search_higher(key):",
"+ ptr = root",
"- def search_lower(self, key):",
"- ptr = self.root",
"+ def search_lower(key):",
"+ ptr = root",
"- def insert(self, key):",
"- def insert_rec(ptr):",
"- b_size = 512",
"- if not ptr.child:",
"- insort(ptr.key, key)",
"- if len(ptr.key) == b_size * 2 - 1:",
"+ def insert_rec(ptr, key):",
"+ b_size = 512",
"+ if not ptr.child:",
"+ insort(ptr.key, key)",
"+ if len(ptr.key) == b_size * 2 - 1:",
"+ ret = BTreeNode()",
"+ ret.key = ptr.key[:b_size]",
"+ ptr.key = ptr.key[b_size:]",
"+ return ret",
"+ else:",
"+ i = bisect(ptr.key, key)",
"+ tmp = insert_rec(ptr.child[i], key)",
"+ if tmp:",
"+ ptr.key.insert(i, tmp.key.pop())",
"+ ptr.child.insert(i, tmp)",
"+ if len(ptr.child) == b_size * 2:",
"+ ret.child = ptr.child[:b_size]",
"+ ptr.child = ptr.child[b_size:]",
"- else:",
"- i = bisect(ptr.key, key)",
"- tmp = insert_rec(ptr.child[i])",
"- if tmp:",
"- ptr.key.insert(i, tmp.key.pop())",
"- ptr.child.insert(i, tmp)",
"- if len(ptr.child) == b_size * 2:",
"- ret = BTreeNode()",
"- ret.child = ptr.child[:b_size]",
"- ptr.child = ptr.child[b_size:]",
"- ret.key = ptr.key[:b_size]",
"- ptr.key = ptr.key[b_size:]",
"- return ret",
"- tmp = insert_rec(self.root)",
"+ def insert(key):",
"+ global root",
"+ tmp = insert_rec(root, key)",
"- root = BTreeNode()",
"- root.key = [tmp.key.pop()]",
"- root.child = [tmp, self.root]",
"- self.root = root",
"+ p = BTreeNode()",
"+ p.key = [tmp.key.pop()]",
"+ p.child = [tmp, root]",
"+ root = p",
"-",
"-def main():",
"- t = BTree()",
"- t.insert(0)",
"- t.insert(n + 1)",
"+ insert(0)",
"+ insert(n + 1)",
"- c += (t.search_higher(v) - v) * (v - t.search_lower(v)) * i",
"- t.insert(v)",
"+ c += (search_higher(v) - v) * (v - search_lower(v)) * i",
"+ insert(v)"
] | false | 0.044687 | 0.037146 | 1.203011 |
[
"s903771347",
"s847636225"
] |
u634046173
|
p04012
|
python
|
s337354923
|
s319259836
| 32 | 26 | 9,028 | 8,928 |
Accepted
|
Accepted
| 18.75 |
s = eval(input())
ss = set(s)
r = 'Yes'
for w in ss:
if s.count(w) % 2 == 1:
r = 'No'
break
print(r)
|
s = eval(input())
r = 'Yes'
for w in s:
if s.count(w) % 2 == 1:
r = 'No'
break
print(r)
| 9 | 8 | 113 | 100 |
s = eval(input())
ss = set(s)
r = "Yes"
for w in ss:
if s.count(w) % 2 == 1:
r = "No"
break
print(r)
|
s = eval(input())
r = "Yes"
for w in s:
if s.count(w) % 2 == 1:
r = "No"
break
print(r)
| false | 11.111111 |
[
"-ss = set(s)",
"-for w in ss:",
"+for w in s:"
] | false | 0.045494 | 0.077438 | 0.587489 |
[
"s337354923",
"s319259836"
] |
u191874006
|
p02937
|
python
|
s058545325
|
s662281583
| 1,520 | 496 | 3,980 | 133,472 |
Accepted
|
Accepted
| 67.37 |
#!/usr/bin/env python3
#ABC138 E
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = eval(input())
t = eval(input())
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
f[alpha.index(s[i])] = True
for i in range(m):
f2[alpha.index(t[i])] = True
for i in range(26):
if not f[i] and f2[i]:
print((-1))
quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
s = s[inde+1:] + s[:inde+1]
inde = s.index(t[i])
ans += inde+1
print(ans)
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = eval(input())
t = eval(input())
flag = [False] * 26
for si in s:
flag[ord(si) - ord('a')] = True
for ti in t:
if not flag[ord(ti) - ord('a')]:
print((-1))
quit()
n = len(s)
S = s + s
idx = [[] for _ in range(26)]
for i in range(2*n):
idx[ord(S[i]) - ord('a')].append(i)
dp = [[inf] * 26 for _ in range(n)]
for i in range(n):
for j in range(26):
if idx[j]:
r = br(idx[j], i)
dp[i][j] = idx[j][r]
c = ord(t[0]) - ord('a')
i = idx[c][0]
ans = i + 1
for ti in t[1:]:
c = ord(ti) - ord('a')
ni = dp[i][c] % n
ans += dp[i][c] - i
i = ni
print(ans)
| 42 | 49 | 978 | 1,201 |
#!/usr/bin/env python3
# ABC138 E
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
s = eval(input())
t = eval(input())
n = len(s)
m = len(t)
f = [False] * 26
f2 = [False] * 26
alpha = "abcdefghijklmnopqrstuvwxyz"
for i in range(n):
f[alpha.index(s[i])] = True
for i in range(m):
f2[alpha.index(t[i])] = True
for i in range(26):
if not f[i] and f2[i]:
print((-1))
quit()
ans = 0
inde = s.index(t[0])
ans += inde + 1
for i in range(1, m):
s = s[inde + 1 :] + s[: inde + 1]
inde = s.index(t[i])
ans += inde + 1
print(ans)
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
s = eval(input())
t = eval(input())
flag = [False] * 26
for si in s:
flag[ord(si) - ord("a")] = True
for ti in t:
if not flag[ord(ti) - ord("a")]:
print((-1))
quit()
n = len(s)
S = s + s
idx = [[] for _ in range(26)]
for i in range(2 * n):
idx[ord(S[i]) - ord("a")].append(i)
dp = [[inf] * 26 for _ in range(n)]
for i in range(n):
for j in range(26):
if idx[j]:
r = br(idx[j], i)
dp[i][j] = idx[j][r]
c = ord(t[0]) - ord("a")
i = idx[c][0]
ans = i + 1
for ti in t[1:]:
c = ord(ti) - ord("a")
ni = dp[i][c] % n
ans += dp[i][c] - i
i = ni
print(ans)
| false | 14.285714 |
[
"-# ABC138 E",
"-import bisect",
"+from bisect import bisect_right as br",
"+from bisect import bisect_left as bl",
"-sys.setrecursionlimit(1000000000)",
"+sys.setrecursionlimit(2147483647)",
"-n = len(s)",
"-m = len(t)",
"-f = [False] * 26",
"-f2 = [False] * 26",
"-alpha = \"abcdefghijklmnopqrstuvwxyz\"",
"-for i in range(n):",
"- f[alpha.index(s[i])] = True",
"-for i in range(m):",
"- f2[alpha.index(t[i])] = True",
"-for i in range(26):",
"- if not f[i] and f2[i]:",
"+flag = [False] * 26",
"+for si in s:",
"+ flag[ord(si) - ord(\"a\")] = True",
"+for ti in t:",
"+ if not flag[ord(ti) - ord(\"a\")]:",
"-ans = 0",
"-inde = s.index(t[0])",
"-ans += inde + 1",
"-for i in range(1, m):",
"- s = s[inde + 1 :] + s[: inde + 1]",
"- inde = s.index(t[i])",
"- ans += inde + 1",
"+n = len(s)",
"+S = s + s",
"+idx = [[] for _ in range(26)]",
"+for i in range(2 * n):",
"+ idx[ord(S[i]) - ord(\"a\")].append(i)",
"+dp = [[inf] * 26 for _ in range(n)]",
"+for i in range(n):",
"+ for j in range(26):",
"+ if idx[j]:",
"+ r = br(idx[j], i)",
"+ dp[i][j] = idx[j][r]",
"+c = ord(t[0]) - ord(\"a\")",
"+i = idx[c][0]",
"+ans = i + 1",
"+for ti in t[1:]:",
"+ c = ord(ti) - ord(\"a\")",
"+ ni = dp[i][c] % n",
"+ ans += dp[i][c] - i",
"+ i = ni"
] | false | 0.080843 | 0.060047 | 1.346326 |
[
"s058545325",
"s662281583"
] |
u389910364
|
p03148
|
python
|
s764920430
|
s919084918
| 823 | 399 | 43,652 | 33,088 |
Accepted
|
Accepted
| 51.52 |
import heapq
INF = float('inf')
n, k = list(map(int, input().split()))
sushi = {}
for _ in range(n):
t, d = list(map(int, input().split()))
if t not in sushi:
sushi[t] = []
sushi[t].append(d)
for s in list(sushi.values()):
s.sort(reverse=True)
eat_counts = {s: 0 for s in list(sushi.keys())}
# まだ食べてないやつ
news = []
# リピート
repeats = []
# 食べた履歴
eats = []
# 各寿司の一番おいしいやつを heap へ
for name, deli_li in list(sushi.items()):
# (-おいしさ, name)
heapq.heappush(news, (-deli_li[0], name))
sum_deli = 0
variety = 0
for _ in range(k):
# おいしいやつから食べる
if news and (not repeats or news[0] <= repeats[0]):
deli, name = heapq.heappop(news)
variety += 1
else:
deli, name = heapq.heappop(repeats)
sum_deli += -deli
eat_counts[name] += 1
heapq.heappush(eats, (-deli, name))
if eat_counts[name] < len(sushi[name]):
heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name))
# 美味しいやつから順に食べた
# 種類増やしたらもっと得点上がるか確かめる
ans = sum_deli + variety ** 2
while True:
if not news or not eats:
break
# 食べたやつポイント小さいやつから置き換えたい
ate_min_deli, ate_min_name = heapq.heappop(eats)
eat_counts[ate_min_name] -= 1
if eat_counts[ate_min_name] <= 0:
# これは種類減っちゃうからだめ
continue
sum_deli -= ate_min_deli
deli, name = heapq.heappop(news)
variety += 1
sum_deli += -deli
eat_counts[name] += 1
ans = max(ans, sum_deli + variety ** 2)
print(ans)
|
import os
import sys
from collections import deque
from operator import itemgetter
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N, K = list(map(int, sys.stdin.buffer.readline().split()))
TD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
t_seen = [False] * (N + 1)
sushi_seen = [False] * N
TD.sort(key=itemgetter(1), reverse=True)
delicious = 0
que = deque()
for i, (t, d) in enumerate(TD):
if len(que) >= K:
break
if not t_seen[t]:
que.append(i)
delicious += d
t_seen[t] = True
sushi_seen[i] = True
for i, (t, d) in enumerate(TD):
if len(que) >= K:
break
if not sushi_seen[i]:
que.appendleft(i)
delicious += d
sushi_seen[i] = True
idx = i
type_cnt = sum(t_seen)
ans = delicious + type_cnt ** 2
while idx < que[-1]:
while idx < N and sushi_seen[idx]:
idx += 1
if idx >= N:
break
que.appendleft(idx)
delicious -= TD[que.pop()][1]
delicious += TD[idx][1]
type_cnt -= 1
score = delicious + type_cnt ** 2
ans = max(ans, score)
sushi_seen[idx] = True
print(ans)
| 70 | 55 | 1,505 | 1,300 |
import heapq
INF = float("inf")
n, k = list(map(int, input().split()))
sushi = {}
for _ in range(n):
t, d = list(map(int, input().split()))
if t not in sushi:
sushi[t] = []
sushi[t].append(d)
for s in list(sushi.values()):
s.sort(reverse=True)
eat_counts = {s: 0 for s in list(sushi.keys())}
# まだ食べてないやつ
news = []
# リピート
repeats = []
# 食べた履歴
eats = []
# 各寿司の一番おいしいやつを heap へ
for name, deli_li in list(sushi.items()):
# (-おいしさ, name)
heapq.heappush(news, (-deli_li[0], name))
sum_deli = 0
variety = 0
for _ in range(k):
# おいしいやつから食べる
if news and (not repeats or news[0] <= repeats[0]):
deli, name = heapq.heappop(news)
variety += 1
else:
deli, name = heapq.heappop(repeats)
sum_deli += -deli
eat_counts[name] += 1
heapq.heappush(eats, (-deli, name))
if eat_counts[name] < len(sushi[name]):
heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name))
# 美味しいやつから順に食べた
# 種類増やしたらもっと得点上がるか確かめる
ans = sum_deli + variety**2
while True:
if not news or not eats:
break
# 食べたやつポイント小さいやつから置き換えたい
ate_min_deli, ate_min_name = heapq.heappop(eats)
eat_counts[ate_min_name] -= 1
if eat_counts[ate_min_name] <= 0:
# これは種類減っちゃうからだめ
continue
sum_deli -= ate_min_deli
deli, name = heapq.heappop(news)
variety += 1
sum_deli += -deli
eat_counts[name] += 1
ans = max(ans, sum_deli + variety**2)
print(ans)
|
import os
import sys
from collections import deque
from operator import itemgetter
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N, K = list(map(int, sys.stdin.buffer.readline().split()))
TD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
t_seen = [False] * (N + 1)
sushi_seen = [False] * N
TD.sort(key=itemgetter(1), reverse=True)
delicious = 0
que = deque()
for i, (t, d) in enumerate(TD):
if len(que) >= K:
break
if not t_seen[t]:
que.append(i)
delicious += d
t_seen[t] = True
sushi_seen[i] = True
for i, (t, d) in enumerate(TD):
if len(que) >= K:
break
if not sushi_seen[i]:
que.appendleft(i)
delicious += d
sushi_seen[i] = True
idx = i
type_cnt = sum(t_seen)
ans = delicious + type_cnt**2
while idx < que[-1]:
while idx < N and sushi_seen[idx]:
idx += 1
if idx >= N:
break
que.appendleft(idx)
delicious -= TD[que.pop()][1]
delicious += TD[idx][1]
type_cnt -= 1
score = delicious + type_cnt**2
ans = max(ans, score)
sushi_seen[idx] = True
print(ans)
| false | 21.428571 |
[
"-import heapq",
"+import os",
"+import sys",
"+from collections import deque",
"+from operator import itemgetter",
"+if os.getenv(\"LOCAL\"):",
"+ sys.stdin = open(\"_in.txt\", \"r\")",
"+sys.setrecursionlimit(10**9)",
"-n, k = list(map(int, input().split()))",
"-sushi = {}",
"-for _ in range(n):",
"- t, d = list(map(int, input().split()))",
"- if t not in sushi:",
"- sushi[t] = []",
"- sushi[t].append(d)",
"-for s in list(sushi.values()):",
"- s.sort(reverse=True)",
"-eat_counts = {s: 0 for s in list(sushi.keys())}",
"-# まだ食べてないやつ",
"-news = []",
"-# リピート",
"-repeats = []",
"-# 食べた履歴",
"-eats = []",
"-# 各寿司の一番おいしいやつを heap へ",
"-for name, deli_li in list(sushi.items()):",
"- # (-おいしさ, name)",
"- heapq.heappush(news, (-deli_li[0], name))",
"-sum_deli = 0",
"-variety = 0",
"-for _ in range(k):",
"- # おいしいやつから食べる",
"- if news and (not repeats or news[0] <= repeats[0]):",
"- deli, name = heapq.heappop(news)",
"- variety += 1",
"- else:",
"- deli, name = heapq.heappop(repeats)",
"- sum_deli += -deli",
"- eat_counts[name] += 1",
"- heapq.heappush(eats, (-deli, name))",
"- if eat_counts[name] < len(sushi[name]):",
"- heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name))",
"-# 美味しいやつから順に食べた",
"-# 種類増やしたらもっと得点上がるか確かめる",
"-ans = sum_deli + variety**2",
"-while True:",
"- if not news or not eats:",
"+IINF = 10**18",
"+MOD = 10**9 + 7",
"+# MOD = 998244353",
"+N, K = list(map(int, sys.stdin.buffer.readline().split()))",
"+TD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]",
"+t_seen = [False] * (N + 1)",
"+sushi_seen = [False] * N",
"+TD.sort(key=itemgetter(1), reverse=True)",
"+delicious = 0",
"+que = deque()",
"+for i, (t, d) in enumerate(TD):",
"+ if len(que) >= K:",
"- # 食べたやつポイント小さいやつから置き換えたい",
"- ate_min_deli, ate_min_name = heapq.heappop(eats)",
"- eat_counts[ate_min_name] -= 1",
"- if eat_counts[ate_min_name] <= 0:",
"- # これは種類減っちゃうからだめ",
"- continue",
"- sum_deli -= ate_min_deli",
"- deli, name = heapq.heappop(news)",
"- variety += 1",
"- sum_deli += -deli",
"- eat_counts[name] += 1",
"- ans = max(ans, sum_deli + variety**2)",
"+ if not t_seen[t]:",
"+ que.append(i)",
"+ delicious += d",
"+ t_seen[t] = True",
"+ sushi_seen[i] = True",
"+for i, (t, d) in enumerate(TD):",
"+ if len(que) >= K:",
"+ break",
"+ if not sushi_seen[i]:",
"+ que.appendleft(i)",
"+ delicious += d",
"+ sushi_seen[i] = True",
"+idx = i",
"+type_cnt = sum(t_seen)",
"+ans = delicious + type_cnt**2",
"+while idx < que[-1]:",
"+ while idx < N and sushi_seen[idx]:",
"+ idx += 1",
"+ if idx >= N:",
"+ break",
"+ que.appendleft(idx)",
"+ delicious -= TD[que.pop()][1]",
"+ delicious += TD[idx][1]",
"+ type_cnt -= 1",
"+ score = delicious + type_cnt**2",
"+ ans = max(ans, score)",
"+ sushi_seen[idx] = True"
] | false | 0.062367 | 0.099695 | 0.625579 |
[
"s764920430",
"s919084918"
] |
u826188728
|
p02888
|
python
|
s108332163
|
s183667956
| 1,937 | 1,625 | 3,188 | 3,188 |
Accepted
|
Accepted
| 16.11 |
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
count = 0
l.sort(reverse = False)
for i in range(len(l)-1, 1, -1):
for j in range(i-1, 0, -1):
pt = bisect.bisect_right(l, l[i] - l[j])
count += max(j - pt, 0)
print(count)
|
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(len(l)-1, 1, -1):
for j in range(i-1, 0, -1):
count += max(j - (bisect.bisect_right(l, l[i] - l[j])), 0)
print(count)
| 11 | 10 | 261 | 235 |
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
count = 0
l.sort(reverse=False)
for i in range(len(l) - 1, 1, -1):
for j in range(i - 1, 0, -1):
pt = bisect.bisect_right(l, l[i] - l[j])
count += max(j - pt, 0)
print(count)
|
import bisect
n = int(eval(input()))
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(len(l) - 1, 1, -1):
for j in range(i - 1, 0, -1):
count += max(j - (bisect.bisect_right(l, l[i] - l[j])), 0)
print(count)
| false | 9.090909 |
[
"-l.sort(reverse=False)",
"+l.sort()",
"- pt = bisect.bisect_right(l, l[i] - l[j])",
"- count += max(j - pt, 0)",
"+ count += max(j - (bisect.bisect_right(l, l[i] - l[j])), 0)"
] | false | 0.046576 | 0.047186 | 0.987072 |
[
"s108332163",
"s183667956"
] |
u368796742
|
p02564
|
python
|
s563281199
|
s957239289
| 3,477 | 2,936 | 200,044 | 200,156 |
Accepted
|
Accepted
| 15.56 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
class SCC:
def __init__(self, n):
self.n = n
self.graph = [[] for i in range(n)]
self.graph_rev = [[] for i in range(n)]
self.used = [False]*n
def add_edge(self, fr, to):
if fr == to:
return
self.graph[fr].append(to)
self.graph_rev[to].append(fr)
def dfs(self, node, graph):
self.used[node] = True
for nex in graph[node]:
if self.used[nex]:
continue
self.dfs(nex,graph)
self.order.append(node)
def first_dfs(self):
self.used = [False]*self.n
self.order = []
for i in range(self.n):
if self.used[i]:
continue
self.dfs(i,self.graph)
def second_dfs(self):
self.used = [False]*self.n
self.ans = []
for node in reversed(self.order):
if self.used[node]:
continue
self.used[node] = True
self.order = []
self.dfs(node, self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
n,m = list(map(int,input().split()))
scc = SCC(n)
for _ in range(m):
a,b = list(map(int,input().split()))
scc.add_edge(a,b)
ans = scc.scc()
print((len(ans)))
for i in ans:
print((len(i),*i))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
class SCC:
def __init__(self, n):
self.n = n
self.graph = [[] for i in range(n)]
self.graph_rev = [[] for i in range(n)]
self.used = [False]*n
def add_edge(self, fr, to):
if fr == to:
return
self.graph[fr].append(to)
self.graph_rev[to].append(fr)
def dfs(self, node, graph):
self.used[node] = True
for nex in graph[node]:
if self.used[nex]:
continue
self.dfs(nex,graph)
self.order.append(node)
def first_dfs(self):
self.used = [False]*self.n
self.order = []
for i in range(self.n):
if self.used[i]:
continue
self.dfs(i,self.graph)
def second_dfs(self):
self.used = [False]*self.n
self.ans = []
for node in reversed(self.order):
if self.used[node]:
continue
self.used[node] = True
self.order = []
self.dfs(node, self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
def main():
n,m = list(map(int,input().split()))
scc = SCC(n)
for _ in range(m):
a,b = list(map(int,input().split()))
scc.add_edge(a,b)
ans = scc.scc()
print((len(ans)))
for i in ans:
print((len(i),*i))
if __name__ == "__main__":
main()
| 63 | 66 | 1,538 | 1,627 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
class SCC:
def __init__(self, n):
self.n = n
self.graph = [[] for i in range(n)]
self.graph_rev = [[] for i in range(n)]
self.used = [False] * n
def add_edge(self, fr, to):
if fr == to:
return
self.graph[fr].append(to)
self.graph_rev[to].append(fr)
def dfs(self, node, graph):
self.used[node] = True
for nex in graph[node]:
if self.used[nex]:
continue
self.dfs(nex, graph)
self.order.append(node)
def first_dfs(self):
self.used = [False] * self.n
self.order = []
for i in range(self.n):
if self.used[i]:
continue
self.dfs(i, self.graph)
def second_dfs(self):
self.used = [False] * self.n
self.ans = []
for node in reversed(self.order):
if self.used[node]:
continue
self.used[node] = True
self.order = []
self.dfs(node, self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
n, m = list(map(int, input().split()))
scc = SCC(n)
for _ in range(m):
a, b = list(map(int, input().split()))
scc.add_edge(a, b)
ans = scc.scc()
print((len(ans)))
for i in ans:
print((len(i), *i))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
class SCC:
def __init__(self, n):
self.n = n
self.graph = [[] for i in range(n)]
self.graph_rev = [[] for i in range(n)]
self.used = [False] * n
def add_edge(self, fr, to):
if fr == to:
return
self.graph[fr].append(to)
self.graph_rev[to].append(fr)
def dfs(self, node, graph):
self.used[node] = True
for nex in graph[node]:
if self.used[nex]:
continue
self.dfs(nex, graph)
self.order.append(node)
def first_dfs(self):
self.used = [False] * self.n
self.order = []
for i in range(self.n):
if self.used[i]:
continue
self.dfs(i, self.graph)
def second_dfs(self):
self.used = [False] * self.n
self.ans = []
for node in reversed(self.order):
if self.used[node]:
continue
self.used[node] = True
self.order = []
self.dfs(node, self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
def main():
n, m = list(map(int, input().split()))
scc = SCC(n)
for _ in range(m):
a, b = list(map(int, input().split()))
scc.add_edge(a, b)
ans = scc.scc()
print((len(ans)))
for i in ans:
print((len(i), *i))
if __name__ == "__main__":
main()
| false | 4.545455 |
[
"-n, m = list(map(int, input().split()))",
"-scc = SCC(n)",
"-for _ in range(m):",
"- a, b = list(map(int, input().split()))",
"- scc.add_edge(a, b)",
"-ans = scc.scc()",
"-print((len(ans)))",
"-for i in ans:",
"- print((len(i), *i))",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ scc = SCC(n)",
"+ for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ scc.add_edge(a, b)",
"+ ans = scc.scc()",
"+ print((len(ans)))",
"+ for i in ans:",
"+ print((len(i), *i))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.048021 | 0.039627 | 1.211835 |
[
"s563281199",
"s957239289"
] |
u123756661
|
p02837
|
python
|
s352523035
|
s980527690
| 322 | 140 | 43,500 | 73,872 |
Accepted
|
Accepted
| 56.52 |
n=int(eval(input()))
w=[[] for i in range(n)]
for i in range(n):
a=int(eval(input()))
for j in range(a):
x,y=list(map(int,input().split()))
w[i].append((x,y))
ans=0
for i in range(1<<n):
x="0"*15+bin(i)[2:]
z=[int(i) for i in x[-n:]]
f=1
for p,q in enumerate(w):
if z[p]==1:
for r in q:
if (z[r[0]-1]!=r[1]):
f=0
if f:
ans=max(ans,z.count(1))
print(ans)
|
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
n=int(eval(input()))
w=[]
ans=chk=0
for i in range(n):
a=int(eval(input()))
t=[]
for j in range(a):
x,y=list(map(int,input().split()))
t.append((x,y))
w.append(t)
for i in range(1,2**n):
l=[0]*n
for j in range(n):
if i&1: l[j]=1
i=i>>1
chk=1
for j in range(n):
if l[j]:
for k in w[j]:
if l[k[0]-1]!=k[1]:
chk=0
break
if chk: ans=max(ans,sum(l))
print(ans)
| 20 | 27 | 462 | 556 |
n = int(eval(input()))
w = [[] for i in range(n)]
for i in range(n):
a = int(eval(input()))
for j in range(a):
x, y = list(map(int, input().split()))
w[i].append((x, y))
ans = 0
for i in range(1 << n):
x = "0" * 15 + bin(i)[2:]
z = [int(i) for i in x[-n:]]
f = 1
for p, q in enumerate(w):
if z[p] == 1:
for r in q:
if z[r[0] - 1] != r[1]:
f = 0
if f:
ans = max(ans, z.count(1))
print(ans)
|
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
n = int(eval(input()))
w = []
ans = chk = 0
for i in range(n):
a = int(eval(input()))
t = []
for j in range(a):
x, y = list(map(int, input().split()))
t.append((x, y))
w.append(t)
for i in range(1, 2**n):
l = [0] * n
for j in range(n):
if i & 1:
l[j] = 1
i = i >> 1
chk = 1
for j in range(n):
if l[j]:
for k in w[j]:
if l[k[0] - 1] != k[1]:
chk = 0
break
if chk:
ans = max(ans, sum(l))
print(ans)
| false | 25.925926 |
[
"+#!/usr/bin/env python3",
"+# -*- coding: UTF-8 -*-",
"-w = [[] for i in range(n)]",
"+w = []",
"+ans = chk = 0",
"+ t = []",
"- w[i].append((x, y))",
"-ans = 0",
"-for i in range(1 << n):",
"- x = \"0\" * 15 + bin(i)[2:]",
"- z = [int(i) for i in x[-n:]]",
"- f = 1",
"- for p, q in enumerate(w):",
"- if z[p] == 1:",
"- for r in q:",
"- if z[r[0] - 1] != r[1]:",
"- f = 0",
"- if f:",
"- ans = max(ans, z.count(1))",
"+ t.append((x, y))",
"+ w.append(t)",
"+for i in range(1, 2**n):",
"+ l = [0] * n",
"+ for j in range(n):",
"+ if i & 1:",
"+ l[j] = 1",
"+ i = i >> 1",
"+ chk = 1",
"+ for j in range(n):",
"+ if l[j]:",
"+ for k in w[j]:",
"+ if l[k[0] - 1] != k[1]:",
"+ chk = 0",
"+ break",
"+ if chk:",
"+ ans = max(ans, sum(l))"
] | false | 0.03803 | 0.037612 | 1.011133 |
[
"s352523035",
"s980527690"
] |
u581603131
|
p02712
|
python
|
s379861250
|
s857984363
| 199 | 154 | 48,544 | 9,164 |
Accepted
|
Accepted
| 22.61 |
N = int(eval(input()))
list = []
for i in range(1,N+1):
list.append(i)
for i in range(1,(N+3)//3):
list[3*i-1] = 0
for i in range(1,(N+5)//5):
list[5*i-1] = 0
print((sum(list)))
|
n = int(eval(input()))
ans = 0
for i in range(n+1):
if i % 3 != 0 and i % 5 != 0:
ans += i
print(ans)
| 9 | 7 | 189 | 114 |
N = int(eval(input()))
list = []
for i in range(1, N + 1):
list.append(i)
for i in range(1, (N + 3) // 3):
list[3 * i - 1] = 0
for i in range(1, (N + 5) // 5):
list[5 * i - 1] = 0
print((sum(list)))
|
n = int(eval(input()))
ans = 0
for i in range(n + 1):
if i % 3 != 0 and i % 5 != 0:
ans += i
print(ans)
| false | 22.222222 |
[
"-N = int(eval(input()))",
"-list = []",
"-for i in range(1, N + 1):",
"- list.append(i)",
"-for i in range(1, (N + 3) // 3):",
"- list[3 * i - 1] = 0",
"-for i in range(1, (N + 5) // 5):",
"- list[5 * i - 1] = 0",
"-print((sum(list)))",
"+n = int(eval(input()))",
"+ans = 0",
"+for i in range(n + 1):",
"+ if i % 3 != 0 and i % 5 != 0:",
"+ ans += i",
"+print(ans)"
] | false | 0.343468 | 0.176888 | 1.941723 |
[
"s379861250",
"s857984363"
] |
u200887663
|
p02791
|
python
|
s058211917
|
s933572632
| 176 | 145 | 26,012 | 32,384 |
Accepted
|
Accepted
| 17.61 |
n=int(eval(input()))
#n,p=map(int,input().split())
pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
mn=pl[0]
mnl=[]
count=1
for i in range(n):
mn=min(mn,pl[i])
mnl.append(mn)
for i in range(1,n):
if pl[i]<=mnl[i-1]:
count+=1
print(count)
|
n=int(eval(input()))
#n,m=map(int,input().split())
#t=int(input())
pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
mn=pl[0]
mnl=[]
for i in range(n):
mn=min(mn,pl[i])
mnl.append(mn)
res=0
for i in range(n):
if pl[i]<=mnl[i]: res+=1
print(res)
| 17 | 15 | 309 | 304 |
n = int(eval(input()))
# n,p=map(int,input().split())
pl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
mn = pl[0]
mnl = []
count = 1
for i in range(n):
mn = min(mn, pl[i])
mnl.append(mn)
for i in range(1, n):
if pl[i] <= mnl[i - 1]:
count += 1
print(count)
|
n = int(eval(input()))
# n,m=map(int,input().split())
# t=int(input())
pl = list(map(int, input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
mn = pl[0]
mnl = []
for i in range(n):
mn = min(mn, pl[i])
mnl.append(mn)
res = 0
for i in range(n):
if pl[i] <= mnl[i]:
res += 1
print(res)
| false | 11.764706 |
[
"-# n,p=map(int,input().split())",
"+# n,m=map(int,input().split())",
"+# t=int(input())",
"-count = 1",
"-for i in range(1, n):",
"- if pl[i] <= mnl[i - 1]:",
"- count += 1",
"-print(count)",
"+res = 0",
"+for i in range(n):",
"+ if pl[i] <= mnl[i]:",
"+ res += 1",
"+print(res)"
] | false | 0.120101 | 0.046713 | 2.571018 |
[
"s058211917",
"s933572632"
] |
u539692012
|
p02601
|
python
|
s653874747
|
s122174080
| 93 | 29 | 61,604 | 9,024 |
Accepted
|
Accepted
| 68.82 |
a, b, c = list(map(int, input().split()))
k = int(eval(input()))
t = 0
# c > b > a
while not b > a:
b *= 2
t += 1
while not c > b:
c *= 2
t += 1
print(('Yes' if t <= k else 'No'))
|
a,b,c,k=list(map(int,open(0).read().split()))
while k:k-=1;t=a<b;b*=2-t;c*=1+t
print(('NYoe s'[a<b<c::2]))
| 11 | 3 | 191 | 100 |
a, b, c = list(map(int, input().split()))
k = int(eval(input()))
t = 0
# c > b > a
while not b > a:
b *= 2
t += 1
while not c > b:
c *= 2
t += 1
print(("Yes" if t <= k else "No"))
|
a, b, c, k = list(map(int, open(0).read().split()))
while k:
k -= 1
t = a < b
b *= 2 - t
c *= 1 + t
print(("NYoe s"[a < b < c :: 2]))
| false | 72.727273 |
[
"-a, b, c = list(map(int, input().split()))",
"-k = int(eval(input()))",
"-t = 0",
"-# c > b > a",
"-while not b > a:",
"- b *= 2",
"- t += 1",
"-while not c > b:",
"- c *= 2",
"- t += 1",
"-print((\"Yes\" if t <= k else \"No\"))",
"+a, b, c, k = list(map(int, open(0).read().split()))",
"+while k:",
"+ k -= 1",
"+ t = a < b",
"+ b *= 2 - t",
"+ c *= 1 + t",
"+print((\"NYoe s\"[a < b < c :: 2]))"
] | false | 0.085866 | 0.039491 | 2.174354 |
[
"s653874747",
"s122174080"
] |
u677991935
|
p03031
|
python
|
s519163367
|
s890675536
| 52 | 46 | 3,064 | 3,064 |
Accepted
|
Accepted
| 11.54 |
N,M = list(map(int,input().split()))
#ks[i][0]がk_i
ks = [[int(i) for i in input().split()]for i in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(2**N):
flag=0
#Onoff[i]=0はスイッチiのOFFを、=1はONを表す
OnOff = [0]*N
for j in range(N):
if (i>>j) & 1:
OnOff[j]=1
for j in range(M):
count=0
for l in range(1,len(ks[j])):
if(OnOff[ks[j][l]-1]==1):
count+=1
if(p[j]==0 and count%2==0):
flag+=1
elif(p[j]==1 and count%2==1):
flag+=1
else:
pass
if(flag==len(p)):
ans+=1
print(ans)
|
N,M = list(map(int,input().split()))
#ks[i][0]がk_i
ks = [[int(i) for i in input().split()]for i in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(2**N):
flag=0
#Onoff[i]=0はスイッチiのOFFを、=1はONを表す
OnOff = [0]*N
for j in range(N):
if (i>>j) & 1:
OnOff[j]=1
for j in range(M):
count=0
for l in range(1,len(ks[j])):
if(OnOff[ks[j][l]-1]==1):#-1に注意(スイッチxはOnOff[x-1]に対応)
count+=1
if(p[j]==0 and count%2==0):
flag+=1
elif(p[j]==1 and count%2==1):
flag+=1
else:
pass
#全ての電球が点くならばansに+1
if(flag==len(p)):
ans+=1
print(ans)
| 28 | 28 | 667 | 712 |
N, M = list(map(int, input().split()))
# ks[i][0]がk_i
ks = [[int(i) for i in input().split()] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
flag = 0
# Onoff[i]=0はスイッチiのOFFを、=1はONを表す
OnOff = [0] * N
for j in range(N):
if (i >> j) & 1:
OnOff[j] = 1
for j in range(M):
count = 0
for l in range(1, len(ks[j])):
if OnOff[ks[j][l] - 1] == 1:
count += 1
if p[j] == 0 and count % 2 == 0:
flag += 1
elif p[j] == 1 and count % 2 == 1:
flag += 1
else:
pass
if flag == len(p):
ans += 1
print(ans)
|
N, M = list(map(int, input().split()))
# ks[i][0]がk_i
ks = [[int(i) for i in input().split()] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
flag = 0
# Onoff[i]=0はスイッチiのOFFを、=1はONを表す
OnOff = [0] * N
for j in range(N):
if (i >> j) & 1:
OnOff[j] = 1
for j in range(M):
count = 0
for l in range(1, len(ks[j])):
if OnOff[ks[j][l] - 1] == 1: # -1に注意(スイッチxはOnOff[x-1]に対応)
count += 1
if p[j] == 0 and count % 2 == 0:
flag += 1
elif p[j] == 1 and count % 2 == 1:
flag += 1
else:
pass
# 全ての電球が点くならばansに+1
if flag == len(p):
ans += 1
print(ans)
| false | 0 |
[
"- if OnOff[ks[j][l] - 1] == 1:",
"+ if OnOff[ks[j][l] - 1] == 1: # -1に注意(スイッチxはOnOff[x-1]に対応)",
"+ # 全ての電球が点くならばansに+1"
] | false | 0.007179 | 0.03982 | 0.180294 |
[
"s519163367",
"s890675536"
] |
u533039576
|
p02678
|
python
|
s567065130
|
s653635461
| 1,018 | 691 | 64,140 | 34,992 |
Accepted
|
Accepted
| 32.12 |
from heapq import heappush, heappop
def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
# graph[v_from] = [(cost, v_to), ...]
dist = [INF] * n
prev_node = [-1] * n
dist[v_s] = 0
heap = [(0, v_s)] # heap = [(dist[v], v), ...]
while heap:
dist2v, v_from = heappop(heap)
if dist[v_from] < dist2v:
continue
for cost, v_to in graph[v_from]:
dist_cand = dist2v + cost
if dist_cand < dist[v_to]:
dist[v_to] = dist_cand
prev_node[v_to] = v_from
heappush(heap, (dist[v_to], v_to))
return dist, prev_node
n, m = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
graph[a].append((1, b))
graph[b].append((1, a))
dist, prev_node = dijkstra(graph, n, 0)
# print(dist)
# print(prev_node)
print('Yes')
for i in range(1, n):
print((prev_node[i] + 1))
|
from collections import deque
n, m = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
dist = [-1] * n
prev_node = [-1] * n
dist[0] = 0
q = deque([0])
while q:
v = q.popleft()
for v_next in graph[v]:
if dist[v_next] == -1:
dist[v_next] = dist[v] + 1
prev_node[v_next] = v
q.append(v_next)
# print(dist)
# print(prev_node)
print('Yes')
for i in range(1, n):
print((prev_node[i] + 1))
| 40 | 29 | 1,039 | 600 |
from heapq import heappush, heappop
def dijkstra(graph: list, n: int, v_s: int, INF: int = float("inf")) -> list:
# graph[v_from] = [(cost, v_to), ...]
dist = [INF] * n
prev_node = [-1] * n
dist[v_s] = 0
heap = [(0, v_s)] # heap = [(dist[v], v), ...]
while heap:
dist2v, v_from = heappop(heap)
if dist[v_from] < dist2v:
continue
for cost, v_to in graph[v_from]:
dist_cand = dist2v + cost
if dist_cand < dist[v_to]:
dist[v_to] = dist_cand
prev_node[v_to] = v_from
heappush(heap, (dist[v_to], v_to))
return dist, prev_node
n, m = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
graph[a].append((1, b))
graph[b].append((1, a))
dist, prev_node = dijkstra(graph, n, 0)
# print(dist)
# print(prev_node)
print("Yes")
for i in range(1, n):
print((prev_node[i] + 1))
|
from collections import deque
n, m = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
dist = [-1] * n
prev_node = [-1] * n
dist[0] = 0
q = deque([0])
while q:
v = q.popleft()
for v_next in graph[v]:
if dist[v_next] == -1:
dist[v_next] = dist[v] + 1
prev_node[v_next] = v
q.append(v_next)
# print(dist)
# print(prev_node)
print("Yes")
for i in range(1, n):
print((prev_node[i] + 1))
| false | 27.5 |
[
"-from heapq import heappush, heappop",
"-",
"-",
"-def dijkstra(graph: list, n: int, v_s: int, INF: int = float(\"inf\")) -> list:",
"- # graph[v_from] = [(cost, v_to), ...]",
"- dist = [INF] * n",
"- prev_node = [-1] * n",
"- dist[v_s] = 0",
"- heap = [(0, v_s)] # heap = [(dist[v], v), ...]",
"- while heap:",
"- dist2v, v_from = heappop(heap)",
"- if dist[v_from] < dist2v:",
"- continue",
"- for cost, v_to in graph[v_from]:",
"- dist_cand = dist2v + cost",
"- if dist_cand < dist[v_to]:",
"- dist[v_to] = dist_cand",
"- prev_node[v_to] = v_from",
"- heappush(heap, (dist[v_to], v_to))",
"- return dist, prev_node",
"-",
"+from collections import deque",
"- graph[a].append((1, b))",
"- graph[b].append((1, a))",
"-dist, prev_node = dijkstra(graph, n, 0)",
"+ graph[a].append(b)",
"+ graph[b].append(a)",
"+dist = [-1] * n",
"+prev_node = [-1] * n",
"+dist[0] = 0",
"+q = deque([0])",
"+while q:",
"+ v = q.popleft()",
"+ for v_next in graph[v]:",
"+ if dist[v_next] == -1:",
"+ dist[v_next] = dist[v] + 1",
"+ prev_node[v_next] = v",
"+ q.append(v_next)"
] | false | 0.038829 | 0.039183 | 0.990973 |
[
"s567065130",
"s653635461"
] |
u671252250
|
p03672
|
python
|
s984895171
|
s313275037
| 21 | 17 | 3,316 | 3,060 |
Accepted
|
Accepted
| 19.05 |
# coding: utf-8
# Your code here!
from collections import Counter
S = list(eval(input()))
A_li = []
B_li = []
for i in range(1, len(S) + 1):
S_del = S[:-i]
A_li = S_del[0:len(S_del) // 2]
B_li = S_del[len(S_del) // 2::]
if A_li == B_li:
print((len(A_li) * 2))
exit()
|
# coding: utf-8
# Your code here!
S = list(eval(input()))
A_li = []
B_li = []
for i in range(1, len(S) + 1):
S_del = S[:-i]
A_li = S_del[0:len(S_del) // 2]
B_li = S_del[len(S_del) // 2::]
if A_li == B_li:
print((len(A_li) * 2))
exit()
| 15 | 14 | 306 | 273 |
# coding: utf-8
# Your code here!
from collections import Counter
S = list(eval(input()))
A_li = []
B_li = []
for i in range(1, len(S) + 1):
S_del = S[:-i]
A_li = S_del[0 : len(S_del) // 2]
B_li = S_del[len(S_del) // 2 : :]
if A_li == B_li:
print((len(A_li) * 2))
exit()
|
# coding: utf-8
# Your code here!
S = list(eval(input()))
A_li = []
B_li = []
for i in range(1, len(S) + 1):
S_del = S[:-i]
A_li = S_del[0 : len(S_del) // 2]
B_li = S_del[len(S_del) // 2 : :]
if A_li == B_li:
print((len(A_li) * 2))
exit()
| false | 6.666667 |
[
"-from collections import Counter",
"-"
] | false | 0.036772 | 0.076213 | 0.482482 |
[
"s984895171",
"s313275037"
] |
u407160848
|
p02745
|
python
|
s415742872
|
s291712992
| 1,954 | 1,779 | 52,788 | 53,192 |
Accepted
|
Accepted
| 8.96 |
a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a=="?" or b=="?" or a==b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i-j+50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
left = min(0, i, j)
right = max(len_a, len_b+i, len_c+j)
ans = min(ans, right - left)
print(ans)
|
a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a=="?" or b=="?" or a==b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i-j+50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
ans = min(ans, max(len_a, len_b+i, len_c+j) - min(0, i, j))
print(ans)
| 39 | 37 | 966 | 914 |
a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a == "?" or b == "?" or a == b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i - j + 50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i + 50000] and ac[j + 50000] and bc[j - i + 50000]:
left = min(0, i, j)
right = max(len_a, len_b + i, len_c + j)
ans = min(ans, right - left)
print(ans)
|
a = eval(input())
b = eval(input())
c = eval(input())
# 文字のマッチング(?はワイルドカード)
def match(a, b):
return a == "?" or b == "?" or a == b
ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか?
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか?
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか?
def check(a, b, ab):
for i in range(len(a)):
for j in range(len(b)):
if not match(a[i], b[j]):
ab[i - j + 50000] = False
check(a, b, ab)
check(a, c, ac)
check(b, c, bc)
len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)
ans = len_a + len_b + len_c
# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
# j = CをAに対していくつスライドして置くか
for j in range(-2 * len_max, 2 * len_max + 1):
if ab[i + 50000] and ac[j + 50000] and bc[j - i + 50000]:
ans = min(ans, max(len_a, len_b + i, len_c + j) - min(0, i, j))
print(ans)
| false | 5.128205 |
[
"- left = min(0, i, j)",
"- right = max(len_a, len_b + i, len_c + j)",
"- ans = min(ans, right - left)",
"+ ans = min(ans, max(len_a, len_b + i, len_c + j) - min(0, i, j))"
] | false | 0.042213 | 0.045521 | 0.92734 |
[
"s415742872",
"s291712992"
] |
u246253778
|
p02622
|
python
|
s095178291
|
s065843951
| 81 | 62 | 73,224 | 9,328 |
Accepted
|
Accepted
| 23.46 |
S = eval(input())
T = eval(input())
cnt = 0
for i, s in enumerate(S):
if s != T[i]:
cnt += 1
print(cnt)
|
S = eval(input())
T = eval(input())
cnt = 0
for i in range(len(S)):
if S[i] != T[i]:
cnt += 1
print(cnt)
| 9 | 9 | 113 | 114 |
S = eval(input())
T = eval(input())
cnt = 0
for i, s in enumerate(S):
if s != T[i]:
cnt += 1
print(cnt)
|
S = eval(input())
T = eval(input())
cnt = 0
for i in range(len(S)):
if S[i] != T[i]:
cnt += 1
print(cnt)
| false | 0 |
[
"-for i, s in enumerate(S):",
"- if s != T[i]:",
"+for i in range(len(S)):",
"+ if S[i] != T[i]:"
] | false | 0.10258 | 0.043962 | 2.333405 |
[
"s095178291",
"s065843951"
] |
u852690916
|
p03371
|
python
|
s155831675
|
s239568696
| 182 | 126 | 39,408 | 3,064 |
Accepted
|
Accepted
| 30.77 |
A,B,C,X,Y = list(map(int, input().split()))
ans = 5000 * 10**5 * 4 + 1
for c in range(0,max(X,Y)*2+1,2):
a = c * C
x,y = max(0,X-c//2), max(0,Y-c//2)
a += A*x + B*y
ans = min(ans, a)
print(ans)
|
a,b,c,x,y=list(map(int, input().split()))
c*=2
ans=10**9
for cc in range(max(x,y)+1):
tmp = cc * c
tmp += max(0, x-cc)*a
tmp += max(0, y-cc)*b
ans = min(ans, tmp)
print(ans)
| 9 | 9 | 212 | 191 |
A, B, C, X, Y = list(map(int, input().split()))
ans = 5000 * 10**5 * 4 + 1
for c in range(0, max(X, Y) * 2 + 1, 2):
a = c * C
x, y = max(0, X - c // 2), max(0, Y - c // 2)
a += A * x + B * y
ans = min(ans, a)
print(ans)
|
a, b, c, x, y = list(map(int, input().split()))
c *= 2
ans = 10**9
for cc in range(max(x, y) + 1):
tmp = cc * c
tmp += max(0, x - cc) * a
tmp += max(0, y - cc) * b
ans = min(ans, tmp)
print(ans)
| false | 0 |
[
"-A, B, C, X, Y = list(map(int, input().split()))",
"-ans = 5000 * 10**5 * 4 + 1",
"-for c in range(0, max(X, Y) * 2 + 1, 2):",
"- a = c * C",
"- x, y = max(0, X - c // 2), max(0, Y - c // 2)",
"- a += A * x + B * y",
"- ans = min(ans, a)",
"+a, b, c, x, y = list(map(int, input().split()))",
"+c *= 2",
"+ans = 10**9",
"+for cc in range(max(x, y) + 1):",
"+ tmp = cc * c",
"+ tmp += max(0, x - cc) * a",
"+ tmp += max(0, y - cc) * b",
"+ ans = min(ans, tmp)"
] | false | 0.054441 | 0.07096 | 0.767212 |
[
"s155831675",
"s239568696"
] |
u977389981
|
p03700
|
python
|
s149011394
|
s563260925
| 1,444 | 1,180 | 11,032 | 11,060 |
Accepted
|
Accepted
| 18.28 |
import math
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
def f(x):
s = sum([math.ceil(max(0, h - x * B) / (A - B)) for h in H])
if s <= x:
return True
else:
return False
l = 0
r = 10 ** 9 + 7
while r - l > 1:
m = (l + r) // 2
if f(m):
r = m
else:
l = m
# print(r, l, m)
print(r)
|
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
def f(x):
s = sum([- (- max(0, h - x * B) // (A - B)) for h in H])
if s <= x:
return True
else:
return False
l = 0
r = 10 ** 9 + 7
while r - l > 1:
m = (l + r) // 2
if f(m):
r = m
else:
l = m
# print(r, l, m)
print(r)
| 22 | 21 | 406 | 389 |
import math
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
def f(x):
s = sum([math.ceil(max(0, h - x * B) / (A - B)) for h in H])
if s <= x:
return True
else:
return False
l = 0
r = 10**9 + 7
while r - l > 1:
m = (l + r) // 2
if f(m):
r = m
else:
l = m
# print(r, l, m)
print(r)
|
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for i in range(N)]
def f(x):
s = sum([-(-max(0, h - x * B) // (A - B)) for h in H])
if s <= x:
return True
else:
return False
l = 0
r = 10**9 + 7
while r - l > 1:
m = (l + r) // 2
if f(m):
r = m
else:
l = m
# print(r, l, m)
print(r)
| false | 4.545455 |
[
"-import math",
"-",
"- s = sum([math.ceil(max(0, h - x * B) / (A - B)) for h in H])",
"+ s = sum([-(-max(0, h - x * B) // (A - B)) for h in H])"
] | false | 0.068145 | 0.05522 | 1.23407 |
[
"s149011394",
"s563260925"
] |
u216015528
|
p03329
|
python
|
s663833255
|
s854252042
| 229 | 104 | 9,160 | 73,456 |
Accepted
|
Accepted
| 54.59 |
import sys
def resolve():
readline = sys.stdin.readline
def func(n: int, a: int):
res = 0
while n > 0:
res += n % a
n = int(n / a)
return res
N = int(readline())
res = N
for i in range(N + 1):
tmp = func(i, 6) + func(N - i, 9)
res = min(res, tmp)
print(res)
resolve()
|
#!/usr/bin/env python3
def main():
N = int(eval(input()))
can_six = []
can_nine = []
limit = 100
for i in range(1, limit):
six = 6 ** i
if six <= N:
can_six.append(six)
nine = 9 ** i
if nine <= N:
can_nine.append(nine)
if six > N and nine > N:
break
can = sorted([1] + can_six + can_nine)
INF = 10 ** 9
dp = [INF] * (N + 1)
dp[0] = 0
for n in range(N + 1):
for draw in can:
if n - draw < 0:
break
dp[n] = min(dp[n], dp[n - draw] + 1)
print((dp[-1]))
if __name__ == '__main__':
main()
| 22 | 31 | 383 | 686 |
import sys
def resolve():
readline = sys.stdin.readline
def func(n: int, a: int):
res = 0
while n > 0:
res += n % a
n = int(n / a)
return res
N = int(readline())
res = N
for i in range(N + 1):
tmp = func(i, 6) + func(N - i, 9)
res = min(res, tmp)
print(res)
resolve()
|
#!/usr/bin/env python3
def main():
N = int(eval(input()))
can_six = []
can_nine = []
limit = 100
for i in range(1, limit):
six = 6**i
if six <= N:
can_six.append(six)
nine = 9**i
if nine <= N:
can_nine.append(nine)
if six > N and nine > N:
break
can = sorted([1] + can_six + can_nine)
INF = 10**9
dp = [INF] * (N + 1)
dp[0] = 0
for n in range(N + 1):
for draw in can:
if n - draw < 0:
break
dp[n] = min(dp[n], dp[n - draw] + 1)
print((dp[-1]))
if __name__ == "__main__":
main()
| false | 29.032258 |
[
"-import sys",
"+#!/usr/bin/env python3",
"+def main():",
"+ N = int(eval(input()))",
"+ can_six = []",
"+ can_nine = []",
"+ limit = 100",
"+ for i in range(1, limit):",
"+ six = 6**i",
"+ if six <= N:",
"+ can_six.append(six)",
"+ nine = 9**i",
"+ if nine <= N:",
"+ can_nine.append(nine)",
"+ if six > N and nine > N:",
"+ break",
"+ can = sorted([1] + can_six + can_nine)",
"+ INF = 10**9",
"+ dp = [INF] * (N + 1)",
"+ dp[0] = 0",
"+ for n in range(N + 1):",
"+ for draw in can:",
"+ if n - draw < 0:",
"+ break",
"+ dp[n] = min(dp[n], dp[n - draw] + 1)",
"+ print((dp[-1]))",
"-def resolve():",
"- readline = sys.stdin.readline",
"-",
"- def func(n: int, a: int):",
"- res = 0",
"- while n > 0:",
"- res += n % a",
"- n = int(n / a)",
"- return res",
"-",
"- N = int(readline())",
"- res = N",
"- for i in range(N + 1):",
"- tmp = func(i, 6) + func(N - i, 9)",
"- res = min(res, tmp)",
"- print(res)",
"-",
"-",
"-resolve()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.066733 | 0.21767 | 0.30658 |
[
"s663833255",
"s854252042"
] |
u391731808
|
p03569
|
python
|
s461183493
|
s580494672
| 76 | 66 | 3,956 | 5,236 |
Accepted
|
Accepted
| 13.16 |
s = eval(input())
t= "".join(c for c in s if c!="x")
if t!=t[::-1]:
print((-1))
else:
ans=0
i=0
j=0
l=len(s)
while i+j<l-1:
if s[i] != s[l-1-j]:
ans+=1
if s[i] == "x" : i+=1
else : j+=1
else:
i+=1
j+=1
print(ans)
|
s = eval(input())
t = "".join(s.split("x"))
if t!=t[::-1]:print((-1));exit()
ans = 0
i,j=0,len(s)-1
while i<j:
if s[i]==s[j]:i+=1;j-=1
elif s[i]=="x":ans+=1;i+=1
elif s[j]=="x":ans+=1;j-=1
print(ans)
| 18 | 10 | 325 | 212 |
s = eval(input())
t = "".join(c for c in s if c != "x")
if t != t[::-1]:
print((-1))
else:
ans = 0
i = 0
j = 0
l = len(s)
while i + j < l - 1:
if s[i] != s[l - 1 - j]:
ans += 1
if s[i] == "x":
i += 1
else:
j += 1
else:
i += 1
j += 1
print(ans)
|
s = eval(input())
t = "".join(s.split("x"))
if t != t[::-1]:
print((-1))
exit()
ans = 0
i, j = 0, len(s) - 1
while i < j:
if s[i] == s[j]:
i += 1
j -= 1
elif s[i] == "x":
ans += 1
i += 1
elif s[j] == "x":
ans += 1
j -= 1
print(ans)
| false | 44.444444 |
[
"-t = \"\".join(c for c in s if c != \"x\")",
"+t = \"\".join(s.split(\"x\"))",
"-else:",
"- ans = 0",
"- i = 0",
"- j = 0",
"- l = len(s)",
"- while i + j < l - 1:",
"- if s[i] != s[l - 1 - j]:",
"- ans += 1",
"- if s[i] == \"x\":",
"- i += 1",
"- else:",
"- j += 1",
"- else:",
"- i += 1",
"- j += 1",
"- print(ans)",
"+ exit()",
"+ans = 0",
"+i, j = 0, len(s) - 1",
"+while i < j:",
"+ if s[i] == s[j]:",
"+ i += 1",
"+ j -= 1",
"+ elif s[i] == \"x\":",
"+ ans += 1",
"+ i += 1",
"+ elif s[j] == \"x\":",
"+ ans += 1",
"+ j -= 1",
"+print(ans)"
] | false | 0.0861 | 0.153837 | 0.559688 |
[
"s461183493",
"s580494672"
] |
u527993431
|
p02847
|
python
|
s254210618
|
s282800484
| 19 | 17 | 2,940 | 3,060 |
Accepted
|
Accepted
| 10.53 |
S = eval(input())
youbi = {
'SUN':7,
'MON':6,
'TUE':5,
'WED':4,
'THU':3,
'FRI':2,
'SAT':1
}
print((youbi[S]))
|
S=["SUN","MON","TUE","WED","THU","FRI","SAT"]
T=eval(input())
if T=="SUN":
print((7))
if T=="MON":
print((6))
if T=="TUE":
print((5))
if T=="WED":
print((4))
if T=="THU":
print((3))
if T=="FRI":
print((2))
if T=="SAT":
print((1))
| 13 | 16 | 143 | 232 |
S = eval(input())
youbi = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1}
print((youbi[S]))
|
S = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
T = eval(input())
if T == "SUN":
print((7))
if T == "MON":
print((6))
if T == "TUE":
print((5))
if T == "WED":
print((4))
if T == "THU":
print((3))
if T == "FRI":
print((2))
if T == "SAT":
print((1))
| false | 18.75 |
[
"-S = eval(input())",
"-youbi = {\"SUN\": 7, \"MON\": 6, \"TUE\": 5, \"WED\": 4, \"THU\": 3, \"FRI\": 2, \"SAT\": 1}",
"-print((youbi[S]))",
"+S = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\"]",
"+T = eval(input())",
"+if T == \"SUN\":",
"+ print((7))",
"+if T == \"MON\":",
"+ print((6))",
"+if T == \"TUE\":",
"+ print((5))",
"+if T == \"WED\":",
"+ print((4))",
"+if T == \"THU\":",
"+ print((3))",
"+if T == \"FRI\":",
"+ print((2))",
"+if T == \"SAT\":",
"+ print((1))"
] | false | 0.046422 | 0.049621 | 0.935535 |
[
"s254210618",
"s282800484"
] |
u069533671
|
p03073
|
python
|
s696353254
|
s890653704
| 51 | 37 | 4,652 | 4,252 |
Accepted
|
Accepted
| 27.45 |
l = [int(i) for i in list(eval(input()))]
even = l[0::2]
odd = l[1::2]
l = sum([abs(1-x) for x in even]) + sum(odd)
r = sum([abs(1-x) for x in odd]) + sum(even)
print((min(l, r)))
|
s = [int(i) for i in eval(input())]
n = len(s)
l = sum(s[0::2])
r = sum(s[1::2])
print((min(abs(l-r+len(s[1::2])), abs(r-l+len(s[0::2])))))
| 9 | 7 | 190 | 139 |
l = [int(i) for i in list(eval(input()))]
even = l[0::2]
odd = l[1::2]
l = sum([abs(1 - x) for x in even]) + sum(odd)
r = sum([abs(1 - x) for x in odd]) + sum(even)
print((min(l, r)))
|
s = [int(i) for i in eval(input())]
n = len(s)
l = sum(s[0::2])
r = sum(s[1::2])
print((min(abs(l - r + len(s[1::2])), abs(r - l + len(s[0::2])))))
| false | 22.222222 |
[
"-l = [int(i) for i in list(eval(input()))]",
"-even = l[0::2]",
"-odd = l[1::2]",
"-l = sum([abs(1 - x) for x in even]) + sum(odd)",
"-r = sum([abs(1 - x) for x in odd]) + sum(even)",
"-print((min(l, r)))",
"+s = [int(i) for i in eval(input())]",
"+n = len(s)",
"+l = sum(s[0::2])",
"+r = sum(s[1::2])",
"+print((min(abs(l - r + len(s[1::2])), abs(r - l + len(s[0::2])))))"
] | false | 0.037007 | 0.066409 | 0.557257 |
[
"s696353254",
"s890653704"
] |
u367701763
|
p02793
|
python
|
s929382006
|
s063973797
| 335 | 140 | 33,656 | 90,212 |
Accepted
|
Accepted
| 58.21 |
import sys
input = sys.stdin.readline
from collections import defaultdict
class PrimeFactor():
def __init__(self, n): # エラトステネス O(N loglog N)
self.n = n
self.table = [i if i % 2 else 2 for i in range(n + 1)]
self.table[0] = 0
for p in range(3, n + 1):
if self.table[p] == p:
for q in range(p * p, n + 1, 2 * p):
self.table[q] = p
def is_prime(self, x): # 素数判定 O(1)
if x < 2:
return False
return self.table[x] == x
def prime_factors(self, x): # 素因数分解 O(logN)
res = []
if x < 2:
return res
while self.table[x] != 1:
res.append(self.table[x])
x //= self.table[x]
return res
def prime_counter(self, x): # 素因数分解(個数のリスト)
res = defaultdict(int)
if x < 2:
return res
while self.table[x] != 1:
res[self.table[x]] += 1
x //= self.table[x]
return res
def prime_gcd(self, X): # n個の最大公約数 X:n個のリスト
exponents = self.prime_counter(X[0])
for x in X[1:]:
Y = self.prime_counter(x)
for prime, exp in list(exponents.items()):
if Y[prime] < exp:
exponents[prime] = Y[prime]
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp)
return res
def prime_lcm(self, X, mod=None): # n個の最小公倍数 X:n個のリスト
exponents = defaultdict(int)
for x in X:
for prime, exp in list(self.prime_counter(x).items()):
if exp > exponents[prime]:
exponents[prime] = exp
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp, mod)
if mod == None:
return res
else:
return res % mod
mod = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
table = PrimeFactor(10**6)
num = table.prime_lcm(A,mod)
res = 0
for a in A:
res += num * pow(a, mod - 2, mod)
print((res % mod))
|
import sys
input = sys.stdin.readline
from collections import defaultdict
class PrimeFactor():
def __init__(self, n): # エラトステネス O(N loglog N)
self.n = n
self.table = list(range(n+1))
self.table[2::2] = [2]*(n//2)
for p in range(3, int(n**0.5) + 2, 2):
if self.table[p] == p:
self.table[p * p::2 * p] = [p] * ((n - p * p - 1) // (2 * p) + 1)
def is_prime(self, x): # 素数判定 O(1)
if x < 2:
return False
return self.table[x] == x
def prime_factors(self, x): # 素因数分解 O(logN)
res = []
if x < 2:
return res
while self.table[x] != 1:
res.append(self.table[x])
x //= self.table[x]
return res
def prime_counter(self, x): # 素因数分解(個数のリスト)
res = defaultdict(int)
if x < 2:
return res
while self.table[x] != 1:
res[self.table[x]] += 1
x //= self.table[x]
return res
def prime_gcd(self, X): # n個の最大公約数 X:n個のリスト
exponents = self.prime_counter(X[0])
for x in X[1:]:
Y = self.prime_counter(x)
for prime, exp in list(exponents.items()):
if Y[prime] < exp:
exponents[prime] = Y[prime]
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp)
return res
def prime_lcm(self, X, mod=None): # n個の最小公倍数 X:n個のリスト
exponents = defaultdict(int)
for x in X:
for prime, exp in list(self.prime_counter(x).items()):
if exp > exponents[prime]:
exponents[prime] = exp
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp, mod)
if mod == None:
return res
else:
return res % mod
mod = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
table = PrimeFactor(10**6)
num = table.prime_lcm(A,mod)
res = 0
for a in A:
res += num * pow(a, mod - 2, mod)
print((res % mod))
| 77 | 76 | 2,208 | 2,198 |
import sys
input = sys.stdin.readline
from collections import defaultdict
class PrimeFactor:
def __init__(self, n): # エラトステネス O(N loglog N)
self.n = n
self.table = [i if i % 2 else 2 for i in range(n + 1)]
self.table[0] = 0
for p in range(3, n + 1):
if self.table[p] == p:
for q in range(p * p, n + 1, 2 * p):
self.table[q] = p
def is_prime(self, x): # 素数判定 O(1)
if x < 2:
return False
return self.table[x] == x
def prime_factors(self, x): # 素因数分解 O(logN)
res = []
if x < 2:
return res
while self.table[x] != 1:
res.append(self.table[x])
x //= self.table[x]
return res
def prime_counter(self, x): # 素因数分解(個数のリスト)
res = defaultdict(int)
if x < 2:
return res
while self.table[x] != 1:
res[self.table[x]] += 1
x //= self.table[x]
return res
def prime_gcd(self, X): # n個の最大公約数 X:n個のリスト
exponents = self.prime_counter(X[0])
for x in X[1:]:
Y = self.prime_counter(x)
for prime, exp in list(exponents.items()):
if Y[prime] < exp:
exponents[prime] = Y[prime]
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp)
return res
def prime_lcm(self, X, mod=None): # n個の最小公倍数 X:n個のリスト
exponents = defaultdict(int)
for x in X:
for prime, exp in list(self.prime_counter(x).items()):
if exp > exponents[prime]:
exponents[prime] = exp
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp, mod)
if mod == None:
return res
else:
return res % mod
mod = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
table = PrimeFactor(10**6)
num = table.prime_lcm(A, mod)
res = 0
for a in A:
res += num * pow(a, mod - 2, mod)
print((res % mod))
|
import sys
input = sys.stdin.readline
from collections import defaultdict
class PrimeFactor:
def __init__(self, n): # エラトステネス O(N loglog N)
self.n = n
self.table = list(range(n + 1))
self.table[2::2] = [2] * (n // 2)
for p in range(3, int(n**0.5) + 2, 2):
if self.table[p] == p:
self.table[p * p :: 2 * p] = [p] * ((n - p * p - 1) // (2 * p) + 1)
def is_prime(self, x): # 素数判定 O(1)
if x < 2:
return False
return self.table[x] == x
def prime_factors(self, x): # 素因数分解 O(logN)
res = []
if x < 2:
return res
while self.table[x] != 1:
res.append(self.table[x])
x //= self.table[x]
return res
def prime_counter(self, x): # 素因数分解(個数のリスト)
res = defaultdict(int)
if x < 2:
return res
while self.table[x] != 1:
res[self.table[x]] += 1
x //= self.table[x]
return res
def prime_gcd(self, X): # n個の最大公約数 X:n個のリスト
exponents = self.prime_counter(X[0])
for x in X[1:]:
Y = self.prime_counter(x)
for prime, exp in list(exponents.items()):
if Y[prime] < exp:
exponents[prime] = Y[prime]
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp)
return res
def prime_lcm(self, X, mod=None): # n個の最小公倍数 X:n個のリスト
exponents = defaultdict(int)
for x in X:
for prime, exp in list(self.prime_counter(x).items()):
if exp > exponents[prime]:
exponents[prime] = exp
res = 1
for prime, exp in list(exponents.items()):
res *= pow(prime, exp, mod)
if mod == None:
return res
else:
return res % mod
mod = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
table = PrimeFactor(10**6)
num = table.prime_lcm(A, mod)
res = 0
for a in A:
res += num * pow(a, mod - 2, mod)
print((res % mod))
| false | 1.298701 |
[
"- self.table = [i if i % 2 else 2 for i in range(n + 1)]",
"- self.table[0] = 0",
"- for p in range(3, n + 1):",
"+ self.table = list(range(n + 1))",
"+ self.table[2::2] = [2] * (n // 2)",
"+ for p in range(3, int(n**0.5) + 2, 2):",
"- for q in range(p * p, n + 1, 2 * p):",
"- self.table[q] = p",
"+ self.table[p * p :: 2 * p] = [p] * ((n - p * p - 1) // (2 * p) + 1)"
] | false | 0.481566 | 0.145493 | 3.309895 |
[
"s929382006",
"s063973797"
] |
u368249389
|
p02684
|
python
|
s207117355
|
s652477107
| 170 | 157 | 32,380 | 32,376 |
Accepted
|
Accepted
| 7.65 |
# Problem D - Teleporter
# input
N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
visit_list = [0] * N
pos = a_list[0]
visit_list[pos-1] = 1
visit_count = 1
remain = K - 1
is_ok = True
ans = 0
# count
while remain>0 and is_ok:
pos = a_list[pos-1]
remain -= 1
visit_count += 1
if pos==1 or not visit_list[pos-1]==0:
tmp_1 = visit_count - visit_list[pos-1]
tmp_2 = remain % tmp_1
for t in range(tmp_2):
pos = a_list[pos-1]
is_ok = False
break
else:
if not pos==1 and visit_list[pos-1]==0:
visit_list[pos-1] = visit_count
# output
print(pos)
|
# Problem D - Teleporter
# input
N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
visit_list = [0] * N
pos = a_list[0]
visit_list[pos-1] = 1
visit_count = 1
remain = K - 1
is_ok = True
ans = 0
# count
while remain>0 and is_ok:
pos = a_list[pos-1]
remain -= 1
visit_count += 1
if pos==1 or not visit_list[pos-1]==0:
tmp_1 = visit_count - visit_list[pos-1]
tmp_2 = remain % tmp_1
for t in range(tmp_2):
pos = a_list[pos-1]
is_ok = False
break
else:
visit_list[pos-1] = visit_count
# output
print(pos)
| 33 | 32 | 709 | 656 |
# Problem D - Teleporter
# input
N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
visit_list = [0] * N
pos = a_list[0]
visit_list[pos - 1] = 1
visit_count = 1
remain = K - 1
is_ok = True
ans = 0
# count
while remain > 0 and is_ok:
pos = a_list[pos - 1]
remain -= 1
visit_count += 1
if pos == 1 or not visit_list[pos - 1] == 0:
tmp_1 = visit_count - visit_list[pos - 1]
tmp_2 = remain % tmp_1
for t in range(tmp_2):
pos = a_list[pos - 1]
is_ok = False
break
else:
if not pos == 1 and visit_list[pos - 1] == 0:
visit_list[pos - 1] = visit_count
# output
print(pos)
|
# Problem D - Teleporter
# input
N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
visit_list = [0] * N
pos = a_list[0]
visit_list[pos - 1] = 1
visit_count = 1
remain = K - 1
is_ok = True
ans = 0
# count
while remain > 0 and is_ok:
pos = a_list[pos - 1]
remain -= 1
visit_count += 1
if pos == 1 or not visit_list[pos - 1] == 0:
tmp_1 = visit_count - visit_list[pos - 1]
tmp_2 = remain % tmp_1
for t in range(tmp_2):
pos = a_list[pos - 1]
is_ok = False
break
else:
visit_list[pos - 1] = visit_count
# output
print(pos)
| false | 3.030303 |
[
"- if not pos == 1 and visit_list[pos - 1] == 0:",
"- visit_list[pos - 1] = visit_count",
"+ visit_list[pos - 1] = visit_count"
] | false | 0.048222 | 0.046248 | 1.042667 |
[
"s207117355",
"s652477107"
] |
u171366497
|
p03684
|
python
|
s623965322
|
s013608730
| 1,045 | 831 | 47,596 | 63,736 |
Accepted
|
Accepted
| 20.48 |
N=int(eval(input()))
city=[0]*N
for i in range(N):
x,y=list(map(int,input().split()))
city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
global root
if root[i]>=0:
root[i]=search(root[i])
return root[i]
return i
cost=0
for i,j,k in data:
ri=search(i)
rj=search(j)
if ri==rj:
continue
elif root[ri]<=root[rj]:
cost+=k
root[ri]+=root[rj]
root[rj]=ri
elif root[ri]>root[rj]:
cost+=k
root[rj]+=root[ri]
root[ri]=rj
print(cost)
|
import sys
input=sys.stdin.readline
N=int(eval(input()))
P=[tuple(map(int,input().split())) for i in range(N)]
X=[(i,P[i][0]) for i in range(N)]
Y=[(i,P[i][1]) for i in range(N)]
X.sort(key=lambda x:x[1])
Y.sort(key=lambda x:x[1])
Z=[(X[i][0],X[i+1][0],X[i+1][1]-X[i][1]) for i in range(N-1)]+[(Y[i][0],Y[i+1][0],Y[i+1][1]-Y[i][1]) for i in range(N-1)]
Z.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
global root
if root[i]>=0:
root[i]=search(root[i])
return root[i]
return i
ans=0
for i,j,k in Z:
ri=search(i)
rj=search(j)
if ri==rj:
continue
elif root[ri]<=root[rj]:
root[ri]+=root[rj]
root[rj]=ri
ans+=k
else:
root[rj]+=root[ri]
root[ri]=rj
ans+=k
print(ans)
| 32 | 32 | 787 | 795 |
N = int(eval(input()))
city = [0] * N
for i in range(N):
x, y = list(map(int, input().split()))
city[i] = (i, x, y)
city.sort(key=lambda x: x[1])
data = [(city[i][0], city[i + 1][0], city[i + 1][1] - city[i][1]) for i in range(N - 1)]
city.sort(key=lambda x: x[2])
data += [
(city[i][0], city[i + 1][0], city[i + 1][2] - city[i][2]) for i in range(N - 1)
]
data.sort(key=lambda x: x[2])
root = [-1] * N
def search(i):
global root
if root[i] >= 0:
root[i] = search(root[i])
return root[i]
return i
cost = 0
for i, j, k in data:
ri = search(i)
rj = search(j)
if ri == rj:
continue
elif root[ri] <= root[rj]:
cost += k
root[ri] += root[rj]
root[rj] = ri
elif root[ri] > root[rj]:
cost += k
root[rj] += root[ri]
root[ri] = rj
print(cost)
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
P = [tuple(map(int, input().split())) for i in range(N)]
X = [(i, P[i][0]) for i in range(N)]
Y = [(i, P[i][1]) for i in range(N)]
X.sort(key=lambda x: x[1])
Y.sort(key=lambda x: x[1])
Z = [(X[i][0], X[i + 1][0], X[i + 1][1] - X[i][1]) for i in range(N - 1)] + [
(Y[i][0], Y[i + 1][0], Y[i + 1][1] - Y[i][1]) for i in range(N - 1)
]
Z.sort(key=lambda x: x[2])
root = [-1] * N
def search(i):
global root
if root[i] >= 0:
root[i] = search(root[i])
return root[i]
return i
ans = 0
for i, j, k in Z:
ri = search(i)
rj = search(j)
if ri == rj:
continue
elif root[ri] <= root[rj]:
root[ri] += root[rj]
root[rj] = ri
ans += k
else:
root[rj] += root[ri]
root[ri] = rj
ans += k
print(ans)
| false | 0 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"-city = [0] * N",
"-for i in range(N):",
"- x, y = list(map(int, input().split()))",
"- city[i] = (i, x, y)",
"-city.sort(key=lambda x: x[1])",
"-data = [(city[i][0], city[i + 1][0], city[i + 1][1] - city[i][1]) for i in range(N - 1)]",
"-city.sort(key=lambda x: x[2])",
"-data += [",
"- (city[i][0], city[i + 1][0], city[i + 1][2] - city[i][2]) for i in range(N - 1)",
"+P = [tuple(map(int, input().split())) for i in range(N)]",
"+X = [(i, P[i][0]) for i in range(N)]",
"+Y = [(i, P[i][1]) for i in range(N)]",
"+X.sort(key=lambda x: x[1])",
"+Y.sort(key=lambda x: x[1])",
"+Z = [(X[i][0], X[i + 1][0], X[i + 1][1] - X[i][1]) for i in range(N - 1)] + [",
"+ (Y[i][0], Y[i + 1][0], Y[i + 1][1] - Y[i][1]) for i in range(N - 1)",
"-data.sort(key=lambda x: x[2])",
"+Z.sort(key=lambda x: x[2])",
"-cost = 0",
"-for i, j, k in data:",
"+ans = 0",
"+for i, j, k in Z:",
"- cost += k",
"- elif root[ri] > root[rj]:",
"- cost += k",
"+ ans += k",
"+ else:",
"-print(cost)",
"+ ans += k",
"+print(ans)"
] | false | 0.032871 | 0.077577 | 0.423719 |
[
"s623965322",
"s013608730"
] |
u271934630
|
p03999
|
python
|
s391650251
|
s366101494
| 191 | 26 | 39,536 | 3,188 |
Accepted
|
Accepted
| 86.39 |
S = eval(input())
ans = 0
for i in range(2**(len(S)-1)):
tmp = S[0]
for j in range(len(S)-1):
if i & (1 << j):
tmp += "+"
tmp += S[j+1]
ans += eval(tmp)
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
s = i_s()
ans = 0
for i in range(2**(len(s)-1)):
tmp = s[0]
for j in range(len(s)-1):
if i & (1<<j):
tmp += "+"
tmp += s[j+1]
ans += eval(tmp)
print(ans)
| 10 | 20 | 207 | 396 |
S = eval(input())
ans = 0
for i in range(2 ** (len(S) - 1)):
tmp = S[0]
for j in range(len(S) - 1):
if i & (1 << j):
tmp += "+"
tmp += S[j + 1]
ans += eval(tmp)
print(ans)
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
s = i_s()
ans = 0
for i in range(2 ** (len(s) - 1)):
tmp = s[0]
for j in range(len(s) - 1):
if i & (1 << j):
tmp += "+"
tmp += s[j + 1]
ans += eval(tmp)
print(ans)
| false | 50 |
[
"-S = eval(input())",
"+import sys",
"+",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**7)",
"+i_i = lambda: int(i_s())",
"+i_l = lambda: list(map(int, stdin.readline().split()))",
"+i_s = lambda: stdin.readline().rstrip()",
"+s = i_s()",
"-for i in range(2 ** (len(S) - 1)):",
"- tmp = S[0]",
"- for j in range(len(S) - 1):",
"+for i in range(2 ** (len(s) - 1)):",
"+ tmp = s[0]",
"+ for j in range(len(s) - 1):",
"- tmp += S[j + 1]",
"+ tmp += s[j + 1]"
] | false | 0.040596 | 0.036634 | 1.108155 |
[
"s391650251",
"s366101494"
] |
u994988729
|
p02973
|
python
|
s334795759
|
s984278317
| 529 | 160 | 8,060 | 8,196 |
Accepted
|
Accepted
| 69.75 |
import bisect
from collections import deque
N=int(eval(input()))
a=[int(eval(input())) for _ in range(N)]
d=deque()
for i in range(N):
p=bisect.bisect_left(d, a[i])
#print(a[i], p, d)
if p==0:
d.appendleft(a[i])
else:
d[p-1]=a[i]
print((len(d)))
|
from collections import deque
import bisect
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A = A[::-1]
col = [A.pop()]
col = deque(col)
while A:
a = A.pop()
if a <= col[0]:
col.appendleft(a)
else:
x = bisect.bisect_left(col, a)
col[x - 1] = a
ans = len(col)
print(ans)
| 14 | 22 | 277 | 375 |
import bisect
from collections import deque
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
d = deque()
for i in range(N):
p = bisect.bisect_left(d, a[i])
# print(a[i], p, d)
if p == 0:
d.appendleft(a[i])
else:
d[p - 1] = a[i]
print((len(d)))
|
from collections import deque
import bisect
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A = A[::-1]
col = [A.pop()]
col = deque(col)
while A:
a = A.pop()
if a <= col[0]:
col.appendleft(a)
else:
x = bisect.bisect_left(col, a)
col[x - 1] = a
ans = len(col)
print(ans)
| false | 36.363636 |
[
"+from collections import deque",
"-from collections import deque",
"+import sys",
"+input = sys.stdin.readline",
"-a = [int(eval(input())) for _ in range(N)]",
"-d = deque()",
"-for i in range(N):",
"- p = bisect.bisect_left(d, a[i])",
"- # print(a[i], p, d)",
"- if p == 0:",
"- d.appendleft(a[i])",
"+A = [int(eval(input())) for _ in range(N)]",
"+A = A[::-1]",
"+col = [A.pop()]",
"+col = deque(col)",
"+while A:",
"+ a = A.pop()",
"+ if a <= col[0]:",
"+ col.appendleft(a)",
"- d[p - 1] = a[i]",
"-print((len(d)))",
"+ x = bisect.bisect_left(col, a)",
"+ col[x - 1] = a",
"+ans = len(col)",
"+print(ans)"
] | false | 0.047247 | 0.067275 | 0.7023 |
[
"s334795759",
"s984278317"
] |
u798803522
|
p02363
|
python
|
s012718547
|
s869056090
| 3,820 | 1,380 | 9,968 | 10,880 |
Accepted
|
Accepted
| 63.87 |
from collections import defaultdict
vertice,edge = list(map(int,input().split(" ")))
cost = [[0 if m == n else float("inf") for n in range(vertice)] for m in range(vertice)]
link = defaultdict(dict)
weight = defaultdict(dict)
for e in range(edge):
i,j,w = list(map(int,input().split(" ")))
link[i] = link.get(i,set()) | {j}
weight[i].update({j:w})
vertice_cnt = 0
while 1:
if vertice_cnt >= vertice:
print("NEGATIVE CYCLE")
break
update = False
for source in range(vertice):
for k,value in list(link.items()):
for v in value:
if cost[source][v] > cost[source][k] + weight[k][v]:
cost[source][v] = cost[source][k] + weight[k][v]
update = True
if not update:
for o in range(vertice):
print((*([n if n != float("INF") else "INF" for n in cost[o]])))
break
vertice_cnt += 1
|
from collections import defaultdict
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
cost_dp = [[float("inf") if n != m else 0 for n in range(vertices)] for m in range(vertices)]
for e in range(edges):
v1, v2, weight = (int(n) for n in input().split(" "))
connect[v1].append([v2,weight])
connect[v2].append([v1,weight])
cost_dp[v1][v2] = weight
for neg in range(2):
updated = 0
for t in range(vertices):
for i in range(vertices):
for k in range(vertices):
if cost_dp[i][k] > cost_dp[i][t] + cost_dp[t][k]:
updated = 1
cost_dp[i][k] = cost_dp[i][t] + cost_dp[t][k]
if neg == 1 and updated:
print("NEGATIVE CYCLE")
else:
for ve in range(vertices):
ans = ["INF" if n == float("inf") else n for n in cost_dp[ve]]
print((*ans))
| 30 | 23 | 934 | 900 |
from collections import defaultdict
vertice, edge = list(map(int, input().split(" ")))
cost = [[0 if m == n else float("inf") for n in range(vertice)] for m in range(vertice)]
link = defaultdict(dict)
weight = defaultdict(dict)
for e in range(edge):
i, j, w = list(map(int, input().split(" ")))
link[i] = link.get(i, set()) | {j}
weight[i].update({j: w})
vertice_cnt = 0
while 1:
if vertice_cnt >= vertice:
print("NEGATIVE CYCLE")
break
update = False
for source in range(vertice):
for k, value in list(link.items()):
for v in value:
if cost[source][v] > cost[source][k] + weight[k][v]:
cost[source][v] = cost[source][k] + weight[k][v]
update = True
if not update:
for o in range(vertice):
print((*([n if n != float("INF") else "INF" for n in cost[o]])))
break
vertice_cnt += 1
|
from collections import defaultdict
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
cost_dp = [
[float("inf") if n != m else 0 for n in range(vertices)] for m in range(vertices)
]
for e in range(edges):
v1, v2, weight = (int(n) for n in input().split(" "))
connect[v1].append([v2, weight])
connect[v2].append([v1, weight])
cost_dp[v1][v2] = weight
for neg in range(2):
updated = 0
for t in range(vertices):
for i in range(vertices):
for k in range(vertices):
if cost_dp[i][k] > cost_dp[i][t] + cost_dp[t][k]:
updated = 1
cost_dp[i][k] = cost_dp[i][t] + cost_dp[t][k]
if neg == 1 and updated:
print("NEGATIVE CYCLE")
else:
for ve in range(vertices):
ans = ["INF" if n == float("inf") else n for n in cost_dp[ve]]
print((*ans))
| false | 23.333333 |
[
"-vertice, edge = list(map(int, input().split(\" \")))",
"-cost = [[0 if m == n else float(\"inf\") for n in range(vertice)] for m in range(vertice)]",
"-link = defaultdict(dict)",
"-weight = defaultdict(dict)",
"-for e in range(edge):",
"- i, j, w = list(map(int, input().split(\" \")))",
"- link[i] = link.get(i, set()) | {j}",
"- weight[i].update({j: w})",
"-vertice_cnt = 0",
"-while 1:",
"- if vertice_cnt >= vertice:",
"- print(\"NEGATIVE CYCLE\")",
"- break",
"- update = False",
"- for source in range(vertice):",
"- for k, value in list(link.items()):",
"- for v in value:",
"- if cost[source][v] > cost[source][k] + weight[k][v]:",
"- cost[source][v] = cost[source][k] + weight[k][v]",
"- update = True",
"- if not update:",
"- for o in range(vertice):",
"- print((*([n if n != float(\"INF\") else \"INF\" for n in cost[o]])))",
"- break",
"- vertice_cnt += 1",
"+vertices, edges = (int(n) for n in input().split(\" \"))",
"+connect = defaultdict(list)",
"+cost_dp = [",
"+ [float(\"inf\") if n != m else 0 for n in range(vertices)] for m in range(vertices)",
"+]",
"+for e in range(edges):",
"+ v1, v2, weight = (int(n) for n in input().split(\" \"))",
"+ connect[v1].append([v2, weight])",
"+ connect[v2].append([v1, weight])",
"+ cost_dp[v1][v2] = weight",
"+for neg in range(2):",
"+ updated = 0",
"+ for t in range(vertices):",
"+ for i in range(vertices):",
"+ for k in range(vertices):",
"+ if cost_dp[i][k] > cost_dp[i][t] + cost_dp[t][k]:",
"+ updated = 1",
"+ cost_dp[i][k] = cost_dp[i][t] + cost_dp[t][k]",
"+if neg == 1 and updated:",
"+ print(\"NEGATIVE CYCLE\")",
"+else:",
"+ for ve in range(vertices):",
"+ ans = [\"INF\" if n == float(\"inf\") else n for n in cost_dp[ve]]",
"+ print((*ans))"
] | false | 0.095057 | 0.037579 | 2.52954 |
[
"s012718547",
"s869056090"
] |
u562016607
|
p03157
|
python
|
s212503879
|
s447609520
| 1,258 | 393 | 35,756 | 73,352 |
Accepted
|
Accepted
| 68.76 |
H,W=list(map(int,input().split()))
S=[list(eval(input())) for i in range(H)]
N=H*W
par=[0 for i in range(N)]
rnk=[0 for i in range(N)]
def init(n):
for i in range(N):
par[i]=i
rnk[i]=0
def find(x):
if par[x]==x:
return x
else:
par[x]=find(par[x])
return par[x]
def unite(x,y):
x=find(x)
y=find(y)
if x==y:
return
if (rnk[x]<rnk[y]):
par[x]=y
else:
par[y]=x
if(rnk[x]==rnk[y]):
rnk[x]+=1
def same(x,y):
return find(x)==find(y)
init(N)
dx=[0,0,1,-1]
dy=[1,-1,0,0]
for i in range(H):
for j in range(W):
for k in range(4):
nx=dx[k]+i
ny=dy[k]+j
if 0<=nx<H and 0<=ny<W:
if S[nx][ny]!=S[i][j]:
p=i*W+j
q=nx*W+ny
unite(p,q)
A=[find(i) for i in range(N)]
D=dict()
for j in range(N):
i=A[j]
if not(i in D):
D[i]=[0,0]
if S[j//W][j%W]=="#":
D[i][1]+=1
else:
D[i][0]+=1
ans=0
for i in D:
seq=D[i]
ans+=seq[0]*seq[1]
print(ans)
|
class UnionFind():
n=1
par=[0]
rnk=[0]
def __init__(self,size):
self.n=size
self.par=[i for i in range(self.n)]
self.rnk=[0 for i in range(self.n)]
def find(self,vertex1):
if self.par[vertex1]==vertex1:
return vertex1
else:
self.par[vertex1]=self.find(self.par[vertex1])
return self.par[vertex1]
def unite(self,vertex1,vertex2):
vertex1=self.find(vertex1)
vertex2=self.find(vertex2)
if vertex1==vertex2:
return
if (self.rnk[vertex1]<self.rnk[vertex2]):
self.par[vertex1]=vertex2
else:
self.par[vertex2]=vertex1
if(self.rnk[vertex1]==self.rnk[vertex2]):
self.rnk[vertex1]+=1
def same(self,vetrex1,vertex2):
return self.find(vetrex1)==self.find(vertex2)
H,W=list(map(int,input().split()))
S=[list(eval(input())) for i in range(H)]
G=UnionFind(H*W)
#i*W+j
for i in range(H):
for j in range(W-1):
if S[i][j]!=S[i][j+1]:
G.unite(i*W+j,i*W+(j+1))
for i in range(H-1):
for j in range(W):
if S[i][j]!=S[i+1][j]:
G.unite(i*W+j,(i+1)*W+j)
D=dict()
for i in range(H):
for j in range(W):
k=G.find(i*W+j)
if not k in D:
D[k]=[0,0]
if S[i][j]=="#":
D[k][0]+=1
else:
D[k][1]+=1
ans=0
for k in D:
x=D[k][0]
y=D[k][1]
ans+=x*y
print(ans)
| 56 | 55 | 1,151 | 1,511 |
H, W = list(map(int, input().split()))
S = [list(eval(input())) for i in range(H)]
N = H * W
par = [0 for i in range(N)]
rnk = [0 for i in range(N)]
def init(n):
for i in range(N):
par[i] = i
rnk[i] = 0
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x, y):
x = find(x)
y = find(y)
if x == y:
return
if rnk[x] < rnk[y]:
par[x] = y
else:
par[y] = x
if rnk[x] == rnk[y]:
rnk[x] += 1
def same(x, y):
return find(x) == find(y)
init(N)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
for i in range(H):
for j in range(W):
for k in range(4):
nx = dx[k] + i
ny = dy[k] + j
if 0 <= nx < H and 0 <= ny < W:
if S[nx][ny] != S[i][j]:
p = i * W + j
q = nx * W + ny
unite(p, q)
A = [find(i) for i in range(N)]
D = dict()
for j in range(N):
i = A[j]
if not (i in D):
D[i] = [0, 0]
if S[j // W][j % W] == "#":
D[i][1] += 1
else:
D[i][0] += 1
ans = 0
for i in D:
seq = D[i]
ans += seq[0] * seq[1]
print(ans)
|
class UnionFind:
n = 1
par = [0]
rnk = [0]
def __init__(self, size):
self.n = size
self.par = [i for i in range(self.n)]
self.rnk = [0 for i in range(self.n)]
def find(self, vertex1):
if self.par[vertex1] == vertex1:
return vertex1
else:
self.par[vertex1] = self.find(self.par[vertex1])
return self.par[vertex1]
def unite(self, vertex1, vertex2):
vertex1 = self.find(vertex1)
vertex2 = self.find(vertex2)
if vertex1 == vertex2:
return
if self.rnk[vertex1] < self.rnk[vertex2]:
self.par[vertex1] = vertex2
else:
self.par[vertex2] = vertex1
if self.rnk[vertex1] == self.rnk[vertex2]:
self.rnk[vertex1] += 1
def same(self, vetrex1, vertex2):
return self.find(vetrex1) == self.find(vertex2)
H, W = list(map(int, input().split()))
S = [list(eval(input())) for i in range(H)]
G = UnionFind(H * W)
# i*W+j
for i in range(H):
for j in range(W - 1):
if S[i][j] != S[i][j + 1]:
G.unite(i * W + j, i * W + (j + 1))
for i in range(H - 1):
for j in range(W):
if S[i][j] != S[i + 1][j]:
G.unite(i * W + j, (i + 1) * W + j)
D = dict()
for i in range(H):
for j in range(W):
k = G.find(i * W + j)
if not k in D:
D[k] = [0, 0]
if S[i][j] == "#":
D[k][0] += 1
else:
D[k][1] += 1
ans = 0
for k in D:
x = D[k][0]
y = D[k][1]
ans += x * y
print(ans)
| false | 1.785714 |
[
"+class UnionFind:",
"+ n = 1",
"+ par = [0]",
"+ rnk = [0]",
"+",
"+ def __init__(self, size):",
"+ self.n = size",
"+ self.par = [i for i in range(self.n)]",
"+ self.rnk = [0 for i in range(self.n)]",
"+",
"+ def find(self, vertex1):",
"+ if self.par[vertex1] == vertex1:",
"+ return vertex1",
"+ else:",
"+ self.par[vertex1] = self.find(self.par[vertex1])",
"+ return self.par[vertex1]",
"+",
"+ def unite(self, vertex1, vertex2):",
"+ vertex1 = self.find(vertex1)",
"+ vertex2 = self.find(vertex2)",
"+ if vertex1 == vertex2:",
"+ return",
"+ if self.rnk[vertex1] < self.rnk[vertex2]:",
"+ self.par[vertex1] = vertex2",
"+ else:",
"+ self.par[vertex2] = vertex1",
"+ if self.rnk[vertex1] == self.rnk[vertex2]:",
"+ self.rnk[vertex1] += 1",
"+",
"+ def same(self, vetrex1, vertex2):",
"+ return self.find(vetrex1) == self.find(vertex2)",
"+",
"+",
"-N = H * W",
"-par = [0 for i in range(N)]",
"-rnk = [0 for i in range(N)]",
"-",
"-",
"-def init(n):",
"- for i in range(N):",
"- par[i] = i",
"- rnk[i] = 0",
"-",
"-",
"-def find(x):",
"- if par[x] == x:",
"- return x",
"- else:",
"- par[x] = find(par[x])",
"- return par[x]",
"-",
"-",
"-def unite(x, y):",
"- x = find(x)",
"- y = find(y)",
"- if x == y:",
"- return",
"- if rnk[x] < rnk[y]:",
"- par[x] = y",
"- else:",
"- par[y] = x",
"- if rnk[x] == rnk[y]:",
"- rnk[x] += 1",
"-",
"-",
"-def same(x, y):",
"- return find(x) == find(y)",
"-",
"-",
"-init(N)",
"-dx = [0, 0, 1, -1]",
"-dy = [1, -1, 0, 0]",
"+G = UnionFind(H * W)",
"+# i*W+j",
"+for i in range(H):",
"+ for j in range(W - 1):",
"+ if S[i][j] != S[i][j + 1]:",
"+ G.unite(i * W + j, i * W + (j + 1))",
"+for i in range(H - 1):",
"+ for j in range(W):",
"+ if S[i][j] != S[i + 1][j]:",
"+ G.unite(i * W + j, (i + 1) * W + j)",
"+D = dict()",
"- for k in range(4):",
"- nx = dx[k] + i",
"- ny = dy[k] + j",
"- if 0 <= nx < H and 0 <= ny < W:",
"- if S[nx][ny] != S[i][j]:",
"- p = i * W + j",
"- q = nx * W + ny",
"- unite(p, q)",
"-A = [find(i) for i in range(N)]",
"-D = dict()",
"-for j in range(N):",
"- i = A[j]",
"- if not (i in D):",
"- D[i] = [0, 0]",
"- if S[j // W][j % W] == \"#\":",
"- D[i][1] += 1",
"- else:",
"- D[i][0] += 1",
"+ k = G.find(i * W + j)",
"+ if not k in D:",
"+ D[k] = [0, 0]",
"+ if S[i][j] == \"#\":",
"+ D[k][0] += 1",
"+ else:",
"+ D[k][1] += 1",
"-for i in D:",
"- seq = D[i]",
"- ans += seq[0] * seq[1]",
"+for k in D:",
"+ x = D[k][0]",
"+ y = D[k][1]",
"+ ans += x * y"
] | false | 0.074978 | 0.040018 | 1.873622 |
[
"s212503879",
"s447609520"
] |
u606045429
|
p03946
|
python
|
s434793330
|
s896897484
| 177 | 141 | 21,600 | 20,448 |
Accepted
|
Accepted
| 20.34 |
from collections import Counter
N, T, *A = list(map(int, open(0).read().split()))
mi = A[0]
ma = 0
B = Counter()
for a in A[1:]:
b = a - mi
B[b] += 1
ma = max(ma, b)
mi = min(mi, a)
print((B[ma]))
|
N, T, A0, *A = list(map(int, open(0).read().split()))
ma, mi = 0, A0
B = {}
for a in A:
b = a - mi
B[b] = B.get(b, 0) + 1
ma, mi = max(ma, b), min(mi, a)
print((B[ma]))
| 15 | 10 | 223 | 183 |
from collections import Counter
N, T, *A = list(map(int, open(0).read().split()))
mi = A[0]
ma = 0
B = Counter()
for a in A[1:]:
b = a - mi
B[b] += 1
ma = max(ma, b)
mi = min(mi, a)
print((B[ma]))
|
N, T, A0, *A = list(map(int, open(0).read().split()))
ma, mi = 0, A0
B = {}
for a in A:
b = a - mi
B[b] = B.get(b, 0) + 1
ma, mi = max(ma, b), min(mi, a)
print((B[ma]))
| false | 33.333333 |
[
"-from collections import Counter",
"-",
"-N, T, *A = list(map(int, open(0).read().split()))",
"-mi = A[0]",
"-ma = 0",
"-B = Counter()",
"-for a in A[1:]:",
"+N, T, A0, *A = list(map(int, open(0).read().split()))",
"+ma, mi = 0, A0",
"+B = {}",
"+for a in A:",
"- B[b] += 1",
"- ma = max(ma, b)",
"- mi = min(mi, a)",
"+ B[b] = B.get(b, 0) + 1",
"+ ma, mi = max(ma, b), min(mi, a)"
] | false | 0.040098 | 0.031191 | 1.285574 |
[
"s434793330",
"s896897484"
] |
u798803522
|
p02316
|
python
|
s219369597
|
s810570771
| 1,600 | 880 | 44,520 | 6,956 |
Accepted
|
Accepted
| 45 |
num,weight = (int(n) for n in input().split(" "))
query = []
for n in range(num):
query.append([int(n) for n in input().split(" ")])
nap = [[0 for n in range(weight + 1)] for m in range(num + 1)]
query = sorted(query,key = lambda x:x[1],reverse = True)
for n in range(num):
for w in range(weight + 1):
if w == 0:
continue
elif w >= query[n][1]:
nap[n + 1][w] = max(nap[n+1][w-query[n][1]] + query[n][0] ,nap[n][w-query[n][1]] + query[n][0] ,nap[n][w])
print((nap[num][weight]))
|
import copy
length, cap = list(map(int, input().split(" ")))
dp = [0] * (cap + 1)
items = []
for _ in range(length):
a, b = list(map(int, input().split(" ")))
items.append([a, b])
for item in items:
v, w = item
temp_dp = copy.copy(dp)
temp_dp[w] = max(temp_dp[w], v)
for j in range(cap):
if temp_dp[j] and w + j <= cap:
temp_dp[w + j] = max(temp_dp[w + j], v + temp_dp[j])
dp = temp_dp
answer = max(dp)
print(answer)
| 14 | 18 | 537 | 471 |
num, weight = (int(n) for n in input().split(" "))
query = []
for n in range(num):
query.append([int(n) for n in input().split(" ")])
nap = [[0 for n in range(weight + 1)] for m in range(num + 1)]
query = sorted(query, key=lambda x: x[1], reverse=True)
for n in range(num):
for w in range(weight + 1):
if w == 0:
continue
elif w >= query[n][1]:
nap[n + 1][w] = max(
nap[n + 1][w - query[n][1]] + query[n][0],
nap[n][w - query[n][1]] + query[n][0],
nap[n][w],
)
print((nap[num][weight]))
|
import copy
length, cap = list(map(int, input().split(" ")))
dp = [0] * (cap + 1)
items = []
for _ in range(length):
a, b = list(map(int, input().split(" ")))
items.append([a, b])
for item in items:
v, w = item
temp_dp = copy.copy(dp)
temp_dp[w] = max(temp_dp[w], v)
for j in range(cap):
if temp_dp[j] and w + j <= cap:
temp_dp[w + j] = max(temp_dp[w + j], v + temp_dp[j])
dp = temp_dp
answer = max(dp)
print(answer)
| false | 22.222222 |
[
"-num, weight = (int(n) for n in input().split(\" \"))",
"-query = []",
"-for n in range(num):",
"- query.append([int(n) for n in input().split(\" \")])",
"-nap = [[0 for n in range(weight + 1)] for m in range(num + 1)]",
"-query = sorted(query, key=lambda x: x[1], reverse=True)",
"-for n in range(num):",
"- for w in range(weight + 1):",
"- if w == 0:",
"- continue",
"- elif w >= query[n][1]:",
"- nap[n + 1][w] = max(",
"- nap[n + 1][w - query[n][1]] + query[n][0],",
"- nap[n][w - query[n][1]] + query[n][0],",
"- nap[n][w],",
"- )",
"-print((nap[num][weight]))",
"+import copy",
"+",
"+length, cap = list(map(int, input().split(\" \")))",
"+dp = [0] * (cap + 1)",
"+items = []",
"+for _ in range(length):",
"+ a, b = list(map(int, input().split(\" \")))",
"+ items.append([a, b])",
"+for item in items:",
"+ v, w = item",
"+ temp_dp = copy.copy(dp)",
"+ temp_dp[w] = max(temp_dp[w], v)",
"+ for j in range(cap):",
"+ if temp_dp[j] and w + j <= cap:",
"+ temp_dp[w + j] = max(temp_dp[w + j], v + temp_dp[j])",
"+ dp = temp_dp",
"+answer = max(dp)",
"+print(answer)"
] | false | 0.040554 | 0.053395 | 0.759512 |
[
"s219369597",
"s810570771"
] |
u077291787
|
p03160
|
python
|
s360786692
|
s311286117
| 224 | 204 | 53,752 | 24,264 |
Accepted
|
Accepted
| 8.93 |
# dpA
def main():
n = int(eval(input()))
A = tuple(map(int, input().rstrip().split()))
dp = [0] + [float("inf")] * (n - 1)
for i in range(1, n):
for j in range(1, 3):
if i - j >= 0:
dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
print((dp[-1]))
if __name__ == "__main__":
main()
|
# A - Frog 1
from collections import defaultdict
def main():
N, *H = list(map(int, open(0).read().split()))
H = [0] + H + [0, 0]
dp = defaultdict(lambda: 1 << 30)
dp[1] = 0
for i, a in enumerate(H[1:N + 1], 1):
for j, b in enumerate(H[i + 1:i + 3], i + 1):
dp[j] = min(dp[j], dp[i] + abs(a - b))
print((dp[N]))
if __name__ == "__main__":
main()
| 14 | 17 | 351 | 405 |
# dpA
def main():
n = int(eval(input()))
A = tuple(map(int, input().rstrip().split()))
dp = [0] + [float("inf")] * (n - 1)
for i in range(1, n):
for j in range(1, 3):
if i - j >= 0:
dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
print((dp[-1]))
if __name__ == "__main__":
main()
|
# A - Frog 1
from collections import defaultdict
def main():
N, *H = list(map(int, open(0).read().split()))
H = [0] + H + [0, 0]
dp = defaultdict(lambda: 1 << 30)
dp[1] = 0
for i, a in enumerate(H[1 : N + 1], 1):
for j, b in enumerate(H[i + 1 : i + 3], i + 1):
dp[j] = min(dp[j], dp[i] + abs(a - b))
print((dp[N]))
if __name__ == "__main__":
main()
| false | 17.647059 |
[
"-# dpA",
"+# A - Frog 1",
"+from collections import defaultdict",
"+",
"+",
"- n = int(eval(input()))",
"- A = tuple(map(int, input().rstrip().split()))",
"- dp = [0] + [float(\"inf\")] * (n - 1)",
"- for i in range(1, n):",
"- for j in range(1, 3):",
"- if i - j >= 0:",
"- dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))",
"- print((dp[-1]))",
"+ N, *H = list(map(int, open(0).read().split()))",
"+ H = [0] + H + [0, 0]",
"+ dp = defaultdict(lambda: 1 << 30)",
"+ dp[1] = 0",
"+ for i, a in enumerate(H[1 : N + 1], 1):",
"+ for j, b in enumerate(H[i + 1 : i + 3], i + 1):",
"+ dp[j] = min(dp[j], dp[i] + abs(a - b))",
"+ print((dp[N]))"
] | false | 0.041809 | 0.04638 | 0.901445 |
[
"s360786692",
"s311286117"
] |
u227082700
|
p02807
|
python
|
s676627135
|
s169072488
| 480 | 180 | 14,252 | 14,052 |
Accepted
|
Accepted
| 62.5 |
n=int(eval(input()));a=list(map(int,input().split()));mod=10**9+7;x=m=1;z=0
for i in range(2,n):x=m=m*i%mod
for i in range(n):z=z+x*(a[i]-a[i-1])%mod;x=x+m*pow(i+1,mod-2,mod)%mod
print((z%mod))
|
N,*X=list(map(int,open(0).read().split()));M,g,q,r=10**9+7,1,[1,1],0
for i in range(1,N):r,g=(r+q[-1]*(X[-1]-X[i-1]))%M,g*i%M;q+=[M//(-~i)*-q[M%(-~i)]%M]
print((r*g%M))
| 4 | 3 | 188 | 162 |
n = int(eval(input()))
a = list(map(int, input().split()))
mod = 10**9 + 7
x = m = 1
z = 0
for i in range(2, n):
x = m = m * i % mod
for i in range(n):
z = z + x * (a[i] - a[i - 1]) % mod
x = x + m * pow(i + 1, mod - 2, mod) % mod
print((z % mod))
|
N, *X = list(map(int, open(0).read().split()))
M, g, q, r = 10**9 + 7, 1, [1, 1], 0
for i in range(1, N):
r, g = (r + q[-1] * (X[-1] - X[i - 1])) % M, g * i % M
q += [M // (-~i) * -q[M % (-~i)] % M]
print((r * g % M))
| false | 25 |
[
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-mod = 10**9 + 7",
"-x = m = 1",
"-z = 0",
"-for i in range(2, n):",
"- x = m = m * i % mod",
"-for i in range(n):",
"- z = z + x * (a[i] - a[i - 1]) % mod",
"- x = x + m * pow(i + 1, mod - 2, mod) % mod",
"-print((z % mod))",
"+N, *X = list(map(int, open(0).read().split()))",
"+M, g, q, r = 10**9 + 7, 1, [1, 1], 0",
"+for i in range(1, N):",
"+ r, g = (r + q[-1] * (X[-1] - X[i - 1])) % M, g * i % M",
"+ q += [M // (-~i) * -q[M % (-~i)] % M]",
"+print((r * g % M))"
] | false | 0.039345 | 0.036204 | 1.086756 |
[
"s676627135",
"s169072488"
] |
u391819434
|
p03331
|
python
|
s150563295
|
s816413723
| 36 | 26 | 9,864 | 9,088 |
Accepted
|
Accepted
| 27.78 |
N=eval(input())
import re
if re.match('10+',N):
print((10))
else:
ans=0
for n in N:
ans+=int(n)
print(ans)
|
N=eval(input())
ans=0
for n in N:
ans+=int(n)
if ans==1:
ans=10
print(ans)
| 9 | 7 | 130 | 82 |
N = eval(input())
import re
if re.match("10+", N):
print((10))
else:
ans = 0
for n in N:
ans += int(n)
print(ans)
|
N = eval(input())
ans = 0
for n in N:
ans += int(n)
if ans == 1:
ans = 10
print(ans)
| false | 22.222222 |
[
"-import re",
"-",
"-if re.match(\"10+\", N):",
"- print((10))",
"-else:",
"- ans = 0",
"- for n in N:",
"- ans += int(n)",
"- print(ans)",
"+ans = 0",
"+for n in N:",
"+ ans += int(n)",
"+if ans == 1:",
"+ ans = 10",
"+print(ans)"
] | false | 0.044071 | 0.039223 | 1.123607 |
[
"s150563295",
"s816413723"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.