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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u775681539
|
p02756
|
python
|
s934130595
|
s554137969
| 1,334 | 153 | 6,260 | 8,628 |
Accepted
|
Accepted
| 88.53 |
#python3
def main():
s = eval(input())
addfront = ''
addback = ''
q = int(eval(input()))
direction = 0
for i in range(q):
t = eval(input())
if t[0] == '1':
direction += 1
continue
if t[0] == '2':
if direction % 2 == 0:
if t[2] == '1':
addfront = t[4] + addfront
if t[2] == '2':
addback = addback + t[4]
else:
if t[2] == '1':
addback = addback + t[4]
if t[2] == '2':
addfront = t[4] + addfront
ans = addfront + s + addback
if direction%2 == 0:
print(ans)
else:
ans = ''.join(reversed(ans))
print(ans)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
s = deque(readline().rstrip().decode())
q = int(readline())
dir = 1
for _ in range(q):
txt = readline().rstrip().decode()
if txt[0] == '1':
dir ^= 1
elif txt[0] == '2':
f = txt[2]
c = txt[4]
if ((dir==1) and (f=='1')) or ((dir==0) and (f=='2')):
s.appendleft(c)
else:
s.append(c)
if dir!=1:
print((''.join(reversed(s))))
else:
print((''.join(s)))
if __name__ == '__main__':
main()
| 30 | 27 | 795 | 723 |
# python3
def main():
s = eval(input())
addfront = ""
addback = ""
q = int(eval(input()))
direction = 0
for i in range(q):
t = eval(input())
if t[0] == "1":
direction += 1
continue
if t[0] == "2":
if direction % 2 == 0:
if t[2] == "1":
addfront = t[4] + addfront
if t[2] == "2":
addback = addback + t[4]
else:
if t[2] == "1":
addback = addback + t[4]
if t[2] == "2":
addfront = t[4] + addfront
ans = addfront + s + addback
if direction % 2 == 0:
print(ans)
else:
ans = "".join(reversed(ans))
print(ans)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
s = deque(readline().rstrip().decode())
q = int(readline())
dir = 1
for _ in range(q):
txt = readline().rstrip().decode()
if txt[0] == "1":
dir ^= 1
elif txt[0] == "2":
f = txt[2]
c = txt[4]
if ((dir == 1) and (f == "1")) or ((dir == 0) and (f == "2")):
s.appendleft(c)
else:
s.append(c)
if dir != 1:
print(("".join(reversed(s))))
else:
print(("".join(s)))
if __name__ == "__main__":
main()
| false | 10 |
[
"-# python3",
"-def main():",
"- s = eval(input())",
"- addfront = \"\"",
"- addback = \"\"",
"- q = int(eval(input()))",
"- direction = 0",
"- for i in range(q):",
"- t = eval(input())",
"- if t[0] == \"1\":",
"- direction += 1",
"- continue",
"- if t[0] == \"2\":",
"- if direction % 2 == 0:",
"- if t[2] == \"1\":",
"- addfront = t[4] + addfront",
"- if t[2] == \"2\":",
"- addback = addback + t[4]",
"- else:",
"- if t[2] == \"1\":",
"- addback = addback + t[4]",
"- if t[2] == \"2\":",
"- addfront = t[4] + addfront",
"- ans = addfront + s + addback",
"- if direction % 2 == 0:",
"- print(ans)",
"- else:",
"- ans = \"\".join(reversed(ans))",
"- print(ans)",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+from collections import deque",
"-main()",
"+def main():",
"+ s = deque(readline().rstrip().decode())",
"+ q = int(readline())",
"+ dir = 1",
"+ for _ in range(q):",
"+ txt = readline().rstrip().decode()",
"+ if txt[0] == \"1\":",
"+ dir ^= 1",
"+ elif txt[0] == \"2\":",
"+ f = txt[2]",
"+ c = txt[4]",
"+ if ((dir == 1) and (f == \"1\")) or ((dir == 0) and (f == \"2\")):",
"+ s.appendleft(c)",
"+ else:",
"+ s.append(c)",
"+ if dir != 1:",
"+ print((\"\".join(reversed(s))))",
"+ else:",
"+ print((\"\".join(s)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.036087 | 0.035995 | 1.002548 |
[
"s934130595",
"s554137969"
] |
u256031597
|
p03212
|
python
|
s526570738
|
s213378355
| 93 | 71 | 2,940 | 3,060 |
Accepted
|
Accepted
| 23.66 |
N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
if all(s.count(c) > 0 for c in "753"):
ret = 1
else:
ret = 0
for c in '753':
ret += dfs(s + c)
return ret
print((dfs('0')))
|
N = int(eval(input()))
def func(s, cnt):
if int(s)>N:
return cnt
else:
b=list(s)
if '7' in b and '5' in b and '3' in b:
cnt += 1
for t in "753":
cnt = func(s+t, cnt)
return cnt
print((func("0", 0)))
| 15 | 15 | 248 | 284 |
N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
if all(s.count(c) > 0 for c in "753"):
ret = 1
else:
ret = 0
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0")))
|
N = int(eval(input()))
def func(s, cnt):
if int(s) > N:
return cnt
else:
b = list(s)
if "7" in b and "5" in b and "3" in b:
cnt += 1
for t in "753":
cnt = func(s + t, cnt)
return cnt
print((func("0", 0)))
| false | 0 |
[
"-def dfs(s):",
"+def func(s, cnt):",
"- return 0",
"- if all(s.count(c) > 0 for c in \"753\"):",
"- ret = 1",
"+ return cnt",
"- ret = 0",
"- for c in \"753\":",
"- ret += dfs(s + c)",
"- return ret",
"+ b = list(s)",
"+ if \"7\" in b and \"5\" in b and \"3\" in b:",
"+ cnt += 1",
"+ for t in \"753\":",
"+ cnt = func(s + t, cnt)",
"+ return cnt",
"-print((dfs(\"0\")))",
"+print((func(\"0\", 0)))"
] | false | 0.053853 | 0.045488 | 1.183889 |
[
"s526570738",
"s213378355"
] |
u580920947
|
p02711
|
python
|
s242691791
|
s908250738
| 28 | 20 | 10,304 | 9,064 |
Accepted
|
Accepted
| 28.57 |
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)
def input():
return sys.stdin.readline()[:-1]
def main():
N = eval(input())
flag = False
for l in N:
if l == '7':
flag = True
else:
pass
if flag:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
|
x = eval(input())
for l in x:
if l == "7":
print("Yes")
exit()
print("No")
| 27 | 6 | 519 | 93 |
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
def input():
return sys.stdin.readline()[:-1]
def main():
N = eval(input())
flag = False
for l in N:
if l == "7":
flag = True
else:
pass
if flag:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
x = eval(input())
for l in x:
if l == "7":
print("Yes")
exit()
print("No")
| false | 77.777778 |
[
"-#!/usr/bin/env python",
"-import sys",
"-from collections import Counter",
"-from itertools import permutations, combinations",
"-from fractions import gcd",
"-from math import ceil, floor",
"-",
"-sys.setrecursionlimit(10**6)",
"-",
"-",
"-def input():",
"- return sys.stdin.readline()[:-1]",
"-",
"-",
"-def main():",
"- N = eval(input())",
"- flag = False",
"- for l in N:",
"- if l == \"7\":",
"- flag = True",
"- else:",
"- pass",
"- if flag:",
"+x = eval(input())",
"+for l in x:",
"+ if l == \"7\":",
"- else:",
"- print(\"No\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ exit()",
"+print(\"No\")"
] | false | 0.035957 | 0.065821 | 0.546281 |
[
"s242691791",
"s908250738"
] |
u077291787
|
p03994
|
python
|
s798589632
|
s788943821
| 83 | 49 | 8,476 | 5,532 |
Accepted
|
Accepted
| 40.96 |
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc
def main():
S = input().rstrip()
K = int(input())
N, MOD = len(S), 26
# dist[c] := distance to "a" through "z"
dist = {c: 26 - i for i, c in enumerate(abc)}
dist["a"] = 0
A = [dist[i] for i in S]
for i in range(N):
if A[i] and A[i] <= K: # A[i] -> "a" if possible
A[i], K = 0, K - A[i]
A[-1] = (A[-1] - K) % MOD # use the remaining K on A[-1]
rest = {v: k for k, v in dist.items()}
ans = [rest[i] for i in A] # restore dist to chr
print(*ans, sep="")
if __name__ == "__main__":
main()
|
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc
def main():
S = input().rstrip()
K = int(eval(input()))
# dist[c] := distance to "a" through "z"
dist = {c: 26 - i for i, c in enumerate(abc)}
dist["a"] = 0
A = [dist[i] for i in S]
ans = ""
for i, s in zip(A[:-1], S[:-1]):
if 0 < i <= K: # change s to "a" if possible
ans += "a"
K -= i
else:
ans += s
# use the remaining K on A[-1] and combine with ans
ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
print(ans)
if __name__ == "__main__":
main()
| 23 | 25 | 681 | 673 |
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc
def main():
S = input().rstrip()
K = int(input())
N, MOD = len(S), 26
# dist[c] := distance to "a" through "z"
dist = {c: 26 - i for i, c in enumerate(abc)}
dist["a"] = 0
A = [dist[i] for i in S]
for i in range(N):
if A[i] and A[i] <= K: # A[i] -> "a" if possible
A[i], K = 0, K - A[i]
A[-1] = (A[-1] - K) % MOD # use the remaining K on A[-1]
rest = {v: k for k, v in dist.items()}
ans = [rest[i] for i in A] # restore dist to chr
print(*ans, sep="")
if __name__ == "__main__":
main()
|
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc
def main():
S = input().rstrip()
K = int(eval(input()))
# dist[c] := distance to "a" through "z"
dist = {c: 26 - i for i, c in enumerate(abc)}
dist["a"] = 0
A = [dist[i] for i in S]
ans = ""
for i, s in zip(A[:-1], S[:-1]):
if 0 < i <= K: # change s to "a" if possible
ans += "a"
K -= i
else:
ans += s
# use the remaining K on A[-1] and combine with ans
ans += chr((ord(S[-1]) + K - ord("a")) % 26 + ord("a"))
print(ans)
if __name__ == "__main__":
main()
| false | 8 |
[
"- K = int(input())",
"- N, MOD = len(S), 26",
"+ K = int(eval(input()))",
"- for i in range(N):",
"- if A[i] and A[i] <= K: # A[i] -> \"a\" if possible",
"- A[i], K = 0, K - A[i]",
"- A[-1] = (A[-1] - K) % MOD # use the remaining K on A[-1]",
"- rest = {v: k for k, v in dist.items()}",
"- ans = [rest[i] for i in A] # restore dist to chr",
"- print(*ans, sep=\"\")",
"+ ans = \"\"",
"+ for i, s in zip(A[:-1], S[:-1]):",
"+ if 0 < i <= K: # change s to \"a\" if possible",
"+ ans += \"a\"",
"+ K -= i",
"+ else:",
"+ ans += s",
"+ # use the remaining K on A[-1] and combine with ans",
"+ ans += chr((ord(S[-1]) + K - ord(\"a\")) % 26 + ord(\"a\"))",
"+ print(ans)"
] | false | 0.043905 | 0.007625 | 5.75765 |
[
"s798589632",
"s788943821"
] |
u078349616
|
p02691
|
python
|
s447812091
|
s222869256
| 351 | 268 | 73,596 | 61,316 |
Accepted
|
Accepted
| 23.65 |
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))
di = defaultdict(int)
dj = defaultdict(int)
for i in range(1, N+1):
di[i + A[i-1]] += 1
dj[i - A[i-1]] += 1
ans = 0
for key in list(di.keys()):
ans += dj[key] * di[key]
print(ans)
|
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
di = defaultdict(int)
for i, a in enumerate(A):
ans += di[i+1 - a]
di[i+1 + a] += 1
print(ans)
| 16 | 12 | 286 | 212 |
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
di = defaultdict(int)
dj = defaultdict(int)
for i in range(1, N + 1):
di[i + A[i - 1]] += 1
dj[i - A[i - 1]] += 1
ans = 0
for key in list(di.keys()):
ans += dj[key] * di[key]
print(ans)
|
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
di = defaultdict(int)
for i, a in enumerate(A):
ans += di[i + 1 - a]
di[i + 1 + a] += 1
print(ans)
| false | 25 |
[
"+ans = 0",
"-dj = defaultdict(int)",
"-for i in range(1, N + 1):",
"- di[i + A[i - 1]] += 1",
"- dj[i - A[i - 1]] += 1",
"-ans = 0",
"-for key in list(di.keys()):",
"- ans += dj[key] * di[key]",
"+for i, a in enumerate(A):",
"+ ans += di[i + 1 - a]",
"+ di[i + 1 + a] += 1"
] | false | 0.035588 | 0.038103 | 0.934 |
[
"s447812091",
"s222869256"
] |
u754022296
|
p02913
|
python
|
s272790413
|
s912202944
| 959 | 659 | 231,944 | 229,912 |
Accepted
|
Accepted
| 31.28 |
def main():
n = int(eval(input()))
S = eval(input())
ans = 0
dp = [[0]*n for _ in range(n)]
for j in range(n-1, 0, -1):
for i in range(j-1, -1, -1):
if j == n-1:
dp[i][j] = int(S[i] == S[j])
else:
if S[i] == S[j]:
dp[i][j] = dp[i+1][j+1] + 1
ans = max(ans, min(dp[i][j], j-i))
print(ans)
if __name__ == "__main__":
main()
|
def main():
n = int(eval(input()))
S = eval(input())
ans = 0
dp = [0]*(n*n)
for j in range(n-1, 0, -1):
for i in range(j-1, -1, -1):
if j == n-1:
dp[i*n+j] = int(S[i] == S[j])
else:
if S[i] == S[j]:
dp[i*n+j] = dp[i*n+j+1+n] + 1
ans = max(ans, min(dp[i*n+j], j-i))
print(ans)
if __name__ == "__main__":
main()
| 16 | 16 | 386 | 374 |
def main():
n = int(eval(input()))
S = eval(input())
ans = 0
dp = [[0] * n for _ in range(n)]
for j in range(n - 1, 0, -1):
for i in range(j - 1, -1, -1):
if j == n - 1:
dp[i][j] = int(S[i] == S[j])
else:
if S[i] == S[j]:
dp[i][j] = dp[i + 1][j + 1] + 1
ans = max(ans, min(dp[i][j], j - i))
print(ans)
if __name__ == "__main__":
main()
|
def main():
n = int(eval(input()))
S = eval(input())
ans = 0
dp = [0] * (n * n)
for j in range(n - 1, 0, -1):
for i in range(j - 1, -1, -1):
if j == n - 1:
dp[i * n + j] = int(S[i] == S[j])
else:
if S[i] == S[j]:
dp[i * n + j] = dp[i * n + j + 1 + n] + 1
ans = max(ans, min(dp[i * n + j], j - i))
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- dp = [[0] * n for _ in range(n)]",
"+ dp = [0] * (n * n)",
"- dp[i][j] = int(S[i] == S[j])",
"+ dp[i * n + j] = int(S[i] == S[j])",
"- dp[i][j] = dp[i + 1][j + 1] + 1",
"- ans = max(ans, min(dp[i][j], j - i))",
"+ dp[i * n + j] = dp[i * n + j + 1 + n] + 1",
"+ ans = max(ans, min(dp[i * n + j], j - i))"
] | false | 0.041929 | 0.041173 | 1.018376 |
[
"s272790413",
"s912202944"
] |
u766684188
|
p03108
|
python
|
s046822506
|
s468403856
| 814 | 736 | 36,400 | 36,404 |
Accepted
|
Accepted
| 9.58 |
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self,n):
self.par=[i for i in range(n+1)] #親要素のノード番号を格納
self.rank=[0]*(n+1) #木の高さを格納
def find(self,x): #根を検索
if self.par[x]==x: #par[x]==xの時そのノードは根
return x
else:
self.par[x]=self.find(self.par[x]) #親を書き換える
return self.par[x]
def union(self,x,y): #木の併合
x=self.find(x)
y=self.find(y)
if x==y:
return
if self.rank[x]<self.rank[y]: #木の高さを比較し、低い方を親とする
self.par[x]=y #xの親がy
else:
self.par[y]=x
if self.rank[x]==self.rank[y]: #木の高さが同じなら親とする方を1増やす
self.rank[x]+=1
def same_check(self,x,y): #同じ木に属するか判定
return self.find(x)==self.find(y)
n,m=list(map(int,input().split()))
edges=[list(map(int,input().split())) for _ in range(m)]
ans=[n*(n-1)//2]
size=[1]*n #size[i]:iを根とするグループのサイズ
uf=UnionFind(n)
for i in range(m-1,0,-1):
tmp=ans[-1]
a,b=edges[i][0]-1,edges[i][1]-1
if not uf.same_check(a,b):
tmp-=size[uf.find(a)]*size[uf.find(b)]
tmp_a,tmp_b=size[uf.find(a)],size[uf.find(b)]
uf.union(a,b)
size[uf.find(a)]=tmp_a+tmp_b
else:
uf.union(a,b)
ans.append(tmp)
for i in range(1,m+1):
print((ans[-i]))
|
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self,n):
self.par=[i for i in range(n+1)]
self.rank=[0]*(n+1)
self.size=[1]*(n+1)
def find(self,x):
if self.par[x]==x:
return x
else:
self.par[x]=self.find(self.par[x])
return self.par[x]
def union(self,x,y):
px=self.find(x)
py=self.find(y)
if px!=py:
if self.rank[px]==self.rank[py]:
self.rank[px]+=1
elif self.rank[px]<self.rank[py]:
px,py=py,px
self.par[py]=px
self.size[px]+=self.size[py]
def same_check(self,x,y):
return self.find(x)==self.find(y)
n,m=list(map(int,input().split()))
edges=[list(map(int,input().split())) for _ in range(m)]
ans=[n*(n-1)//2]
uf=UnionFind(n)
for i in range(m-1,0,-1):
tmp=ans[-1]
a,b=edges[i][0]-1,edges[i][1]-1
if not uf.same_check(a,b):
tmp-=uf.size[uf.find(a)]*uf.size[uf.find(b)]
uf.union(a,b)
ans.append(tmp)
for i in range(1,m+1):
print((ans[-i]))
| 46 | 41 | 1,383 | 1,154 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)] # 親要素のノード番号を格納
self.rank = [0] * (n + 1) # 木の高さを格納
def find(self, x): # 根を検索
if self.par[x] == x: # par[x]==xの時そのノードは根
return x
else:
self.par[x] = self.find(self.par[x]) # 親を書き換える
return self.par[x]
def union(self, x, y): # 木の併合
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]: # 木の高さを比較し、低い方を親とする
self.par[x] = y # xの親がy
else:
self.par[y] = x
if self.rank[x] == self.rank[y]: # 木の高さが同じなら親とする方を1増やす
self.rank[x] += 1
def same_check(self, x, y): # 同じ木に属するか判定
return self.find(x) == self.find(y)
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
ans = [n * (n - 1) // 2]
size = [1] * n # size[i]:iを根とするグループのサイズ
uf = UnionFind(n)
for i in range(m - 1, 0, -1):
tmp = ans[-1]
a, b = edges[i][0] - 1, edges[i][1] - 1
if not uf.same_check(a, b):
tmp -= size[uf.find(a)] * size[uf.find(b)]
tmp_a, tmp_b = size[uf.find(a)], size[uf.find(b)]
uf.union(a, b)
size[uf.find(a)] = tmp_a + tmp_b
else:
uf.union(a, b)
ans.append(tmp)
for i in range(1, m + 1):
print((ans[-i]))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
self.size = [1] * (n + 1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
px = self.find(x)
py = self.find(y)
if px != py:
if self.rank[px] == self.rank[py]:
self.rank[px] += 1
elif self.rank[px] < self.rank[py]:
px, py = py, px
self.par[py] = px
self.size[px] += self.size[py]
def same_check(self, x, y):
return self.find(x) == self.find(y)
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
ans = [n * (n - 1) // 2]
uf = UnionFind(n)
for i in range(m - 1, 0, -1):
tmp = ans[-1]
a, b = edges[i][0] - 1, edges[i][1] - 1
if not uf.same_check(a, b):
tmp -= uf.size[uf.find(a)] * uf.size[uf.find(b)]
uf.union(a, b)
ans.append(tmp)
for i in range(1, m + 1):
print((ans[-i]))
| false | 10.869565 |
[
"- self.par = [i for i in range(n + 1)] # 親要素のノード番号を格納",
"- self.rank = [0] * (n + 1) # 木の高さを格納",
"+ self.par = [i for i in range(n + 1)]",
"+ self.rank = [0] * (n + 1)",
"+ self.size = [1] * (n + 1)",
"- def find(self, x): # 根を検索",
"- if self.par[x] == x: # par[x]==xの時そのノードは根",
"+ def find(self, x):",
"+ if self.par[x] == x:",
"- self.par[x] = self.find(self.par[x]) # 親を書き換える",
"+ self.par[x] = self.find(self.par[x])",
"- def union(self, x, y): # 木の併合",
"- x = self.find(x)",
"- y = self.find(y)",
"- if x == y:",
"- return",
"- if self.rank[x] < self.rank[y]: # 木の高さを比較し、低い方を親とする",
"- self.par[x] = y # xの親がy",
"- else:",
"- self.par[y] = x",
"- if self.rank[x] == self.rank[y]: # 木の高さが同じなら親とする方を1増やす",
"- self.rank[x] += 1",
"+ def union(self, x, y):",
"+ px = self.find(x)",
"+ py = self.find(y)",
"+ if px != py:",
"+ if self.rank[px] == self.rank[py]:",
"+ self.rank[px] += 1",
"+ elif self.rank[px] < self.rank[py]:",
"+ px, py = py, px",
"+ self.par[py] = px",
"+ self.size[px] += self.size[py]",
"- def same_check(self, x, y): # 同じ木に属するか判定",
"+ def same_check(self, x, y):",
"-size = [1] * n # size[i]:iを根とするグループのサイズ",
"- tmp -= size[uf.find(a)] * size[uf.find(b)]",
"- tmp_a, tmp_b = size[uf.find(a)], size[uf.find(b)]",
"- uf.union(a, b)",
"- size[uf.find(a)] = tmp_a + tmp_b",
"- else:",
"- uf.union(a, b)",
"+ tmp -= uf.size[uf.find(a)] * uf.size[uf.find(b)]",
"+ uf.union(a, b)"
] | false | 0.036283 | 0.115111 | 0.315197 |
[
"s046822506",
"s468403856"
] |
u038021590
|
p02555
|
python
|
s266397587
|
s794022036
| 264 | 64 | 212,956 | 63,824 |
Accepted
|
Accepted
| 75.76 |
S = int(eval(input()))
mod = 10**9 + 7
N = 10**6
ans = 0
n = S // 3
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
def cmb(n, r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % mod
for i in range(2, N + 1):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
for i in range(1, n + 1):
si = S - i * 3
ans += cmb(si + i - 1, i - 1)
ans %= mod
print(ans)
|
S = int(eval(input()))
mod = 10 ** 9 + 7
DP = [0] * (S+1)
if S >= 3:
DP[3] = 1
for i in range(4, S+1):
DP[i] = DP[i-1] + DP[i-3]
DP[i] %= mod
print((DP[-1]))
| 32 | 13 | 553 | 177 |
S = int(eval(input()))
mod = 10**9 + 7
N = 10**6
ans = 0
n = S // 3
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
def cmb(n, r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % mod
for i in range(2, N + 1):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
for i in range(1, n + 1):
si = S - i * 3
ans += cmb(si + i - 1, i - 1)
ans %= mod
print(ans)
|
S = int(eval(input()))
mod = 10**9 + 7
DP = [0] * (S + 1)
if S >= 3:
DP[3] = 1
for i in range(4, S + 1):
DP[i] = DP[i - 1] + DP[i - 3]
DP[i] %= mod
print((DP[-1]))
| false | 59.375 |
[
"-N = 10**6",
"-ans = 0",
"-n = S // 3",
"-fact = [1, 1]",
"-factinv = [1, 1]",
"-inv = [0, 1]",
"-",
"-",
"-def cmb(n, r):",
"- if (r < 0) or (n < r):",
"- return 0",
"- r = min(r, n - r)",
"- return fact[n] * factinv[r] * factinv[n - r] % mod",
"-",
"-",
"-for i in range(2, N + 1):",
"- fact.append((fact[-1] * i) % mod)",
"- inv.append((-inv[mod % i] * (mod // i)) % mod)",
"- factinv.append((factinv[-1] * inv[-1]) % mod)",
"-for i in range(1, n + 1):",
"- si = S - i * 3",
"- ans += cmb(si + i - 1, i - 1)",
"- ans %= mod",
"-print(ans)",
"+DP = [0] * (S + 1)",
"+if S >= 3:",
"+ DP[3] = 1",
"+for i in range(4, S + 1):",
"+ DP[i] = DP[i - 1] + DP[i - 3]",
"+ DP[i] %= mod",
"+print((DP[-1]))"
] | false | 1.577885 | 0.036908 | 42.751624 |
[
"s266397587",
"s794022036"
] |
u581187895
|
p03472
|
python
|
s633576707
|
s540155328
| 385 | 206 | 29,820 | 17,624 |
Accepted
|
Accepted
| 46.49 |
# 振るのは最強のやつだけ
# 投げるのは強い順
N,H = list(map(int,input().split()))
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = list(zip(*AB))
a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse = True)
attack_cnt = 0
for b in B:
if H <= 0:
break
attack_cnt += 1
H -= b
if H > 0:
attack_cnt += (H-1)//a + 1
print(attack_cnt)
|
def resolve():
N, H = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for i in range(N):
a, b = list(map(int, input().split()))
A[i] = a
B[i] = b
a_max = max(A)
# a_maxより高い攻撃力を選択(a_maxは何回でも行えるのでそれより低いものは選択しない)
B = [b for b in B if a_max < b]
B.sort(reverse=True)
cnt = 0
for b in B:
if H <= 0:
print(cnt)
return
H -= b
cnt += 1
cnt += -(-H // a_max)
print(cnt)
if __name__ == "__main__":
resolve()
| 23 | 29 | 375 | 551 |
# 振るのは最強のやつだけ
# 投げるのは強い順
N, H = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(N)]
A, B = list(zip(*AB))
a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse=True)
attack_cnt = 0
for b in B:
if H <= 0:
break
attack_cnt += 1
H -= b
if H > 0:
attack_cnt += (H - 1) // a + 1
print(attack_cnt)
|
def resolve():
N, H = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for i in range(N):
a, b = list(map(int, input().split()))
A[i] = a
B[i] = b
a_max = max(A)
# a_maxより高い攻撃力を選択(a_maxは何回でも行えるのでそれより低いものは選択しない)
B = [b for b in B if a_max < b]
B.sort(reverse=True)
cnt = 0
for b in B:
if H <= 0:
print(cnt)
return
H -= b
cnt += 1
cnt += -(-H // a_max)
print(cnt)
if __name__ == "__main__":
resolve()
| false | 20.689655 |
[
"-# 振るのは最強のやつだけ",
"-# 投げるのは強い順",
"-N, H = list(map(int, input().split()))",
"-AB = [[int(x) for x in input().split()] for _ in range(N)]",
"-A, B = list(zip(*AB))",
"-a = max(A) # 振る",
"-B = [b for b in B if b > a] # 投げる価値あり",
"-B.sort(reverse=True)",
"-attack_cnt = 0",
"-for b in B:",
"- if H <= 0:",
"- break",
"- attack_cnt += 1",
"- H -= b",
"-if H > 0:",
"- attack_cnt += (H - 1) // a + 1",
"-print(attack_cnt)",
"+def resolve():",
"+ N, H = list(map(int, input().split()))",
"+ A = [0] * N",
"+ B = [0] * N",
"+ for i in range(N):",
"+ a, b = list(map(int, input().split()))",
"+ A[i] = a",
"+ B[i] = b",
"+ a_max = max(A)",
"+ # a_maxより高い攻撃力を選択(a_maxは何回でも行えるのでそれより低いものは選択しない)",
"+ B = [b for b in B if a_max < b]",
"+ B.sort(reverse=True)",
"+ cnt = 0",
"+ for b in B:",
"+ if H <= 0:",
"+ print(cnt)",
"+ return",
"+ H -= b",
"+ cnt += 1",
"+ cnt += -(-H // a_max)",
"+ print(cnt)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.038189 | 0.037488 | 1.018708 |
[
"s633576707",
"s540155328"
] |
u111471511
|
p02570
|
python
|
s172590619
|
s003383511
| 33 | 29 | 9,156 | 9,164 |
Accepted
|
Accepted
| 12.12 |
DTS = [int(i) for i in input().split()]
D = DTS[0]
T = DTS[1]
S = DTS[2]
if D/T <= S:
print("Yes")
else:
print("No")
|
input_list = [int(num) for num in input().split()]
D = input_list[0]
T = input_list[1]
S = input_list[2]
if D/S <= T:
print("Yes")
else:
print("No")
| 8 | 11 | 131 | 169 |
DTS = [int(i) for i in input().split()]
D = DTS[0]
T = DTS[1]
S = DTS[2]
if D / T <= S:
print("Yes")
else:
print("No")
|
input_list = [int(num) for num in input().split()]
D = input_list[0]
T = input_list[1]
S = input_list[2]
if D / S <= T:
print("Yes")
else:
print("No")
| false | 27.272727 |
[
"-DTS = [int(i) for i in input().split()]",
"-D = DTS[0]",
"-T = DTS[1]",
"-S = DTS[2]",
"-if D / T <= S:",
"+input_list = [int(num) for num in input().split()]",
"+D = input_list[0]",
"+T = input_list[1]",
"+S = input_list[2]",
"+if D / S <= T:"
] | false | 0.037096 | 0.036808 | 1.007842 |
[
"s172590619",
"s003383511"
] |
u347600233
|
p02773
|
python
|
s588698258
|
s166051471
| 877 | 718 | 32,096 | 34,372 |
Accepted
|
Accepted
| 18.13 |
n = int(eval(input()))
dics = {}
for i in range(n):
try:
s = eval(input())
dics[s] += 1
except KeyError:
dics[s] = 1
max_v = max(dics.values())
max_k_list = [kv[0] for kv in list(dics.items()) if kv[1] == max_v]
max_k_list.sort()
for i in max_k_list:
print(i)
|
from collections import defaultdict
n = int(input())
dics = defaultdict(int)
for i in range(n):
s = input()
dics[s] += 1
max_v = max(dics.values())
max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]
max_k_list.sort()
print(*max_k_list, sep='\n')
| 14 | 10 | 291 | 273 |
n = int(eval(input()))
dics = {}
for i in range(n):
try:
s = eval(input())
dics[s] += 1
except KeyError:
dics[s] = 1
max_v = max(dics.values())
max_k_list = [kv[0] for kv in list(dics.items()) if kv[1] == max_v]
max_k_list.sort()
for i in max_k_list:
print(i)
|
from collections import defaultdict
n = int(input())
dics = defaultdict(int)
for i in range(n):
s = input()
dics[s] += 1
max_v = max(dics.values())
max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]
max_k_list.sort()
print(*max_k_list, sep="\n")
| false | 28.571429 |
[
"-n = int(eval(input()))",
"-dics = {}",
"+from collections import defaultdict",
"+",
"+n = int(input())",
"+dics = defaultdict(int)",
"- try:",
"- s = eval(input())",
"- dics[s] += 1",
"- except KeyError:",
"- dics[s] = 1",
"+ s = input()",
"+ dics[s] += 1",
"-max_k_list = [kv[0] for kv in list(dics.items()) if kv[1] == max_v]",
"+max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]",
"-for i in max_k_list:",
"- print(i)",
"+print(*max_k_list, sep=\"\\n\")"
] | false | 0.03151 | 0.032659 | 0.964816 |
[
"s588698258",
"s166051471"
] |
u644907318
|
p02953
|
python
|
s146802015
|
s544797596
| 221 | 84 | 63,984 | 85,088 |
Accepted
|
Accepted
| 61.99 |
N = int(eval(input()))
H = list(map(int,input().split()))
hmax = H[0]
flag = 0
for i in range(1,N):
hmax = max(hmax,H[i])
if hmax-H[i]>=2:
flag = 1
break
if flag==0:
print("Yes")
else:
print("No")
|
N = int(eval(input()))
H = list(map(int,input().split()))
hmax = H[0]
flag = 0
for i in range(1,N):
if H[i]>=hmax:
hmax = H[i]
else:
if hmax-H[i]>=2:
flag = 1
break
if flag==1:
print("No")
else:
print("Yes")
| 13 | 15 | 234 | 271 |
N = int(eval(input()))
H = list(map(int, input().split()))
hmax = H[0]
flag = 0
for i in range(1, N):
hmax = max(hmax, H[i])
if hmax - H[i] >= 2:
flag = 1
break
if flag == 0:
print("Yes")
else:
print("No")
|
N = int(eval(input()))
H = list(map(int, input().split()))
hmax = H[0]
flag = 0
for i in range(1, N):
if H[i] >= hmax:
hmax = H[i]
else:
if hmax - H[i] >= 2:
flag = 1
break
if flag == 1:
print("No")
else:
print("Yes")
| false | 13.333333 |
[
"- hmax = max(hmax, H[i])",
"- if hmax - H[i] >= 2:",
"- flag = 1",
"- break",
"-if flag == 0:",
"+ if H[i] >= hmax:",
"+ hmax = H[i]",
"+ else:",
"+ if hmax - H[i] >= 2:",
"+ flag = 1",
"+ break",
"+if flag == 1:",
"+ print(\"No\")",
"+else:",
"-else:",
"- print(\"No\")"
] | false | 0.143241 | 0.037063 | 3.864814 |
[
"s146802015",
"s544797596"
] |
u227020436
|
p03262
|
python
|
s997610965
|
s672312813
| 152 | 132 | 16,276 | 16,280 |
Accepted
|
Accepted
| 13.16 |
import fractions
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
x.sort()
# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]
# distance between the first city and the start point
dist.append(abs(x[0] - X))
def listgcd(xs):
g = xs[0]
for i in range(1, len(xs)):
g = fractions.gcd(g, xs[i])
return g
print((listgcd(dist)))
|
from fractions import gcd
from functools import reduce
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
x.sort()
# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]
# distance between the first city and the start point
dist.append(abs(x[0] - X))
print((reduce(gcd, dist)))
| 21 | 16 | 440 | 364 |
import fractions
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
x.sort()
# distance between each two cities
dist = [x[i] - x[i - 1] for i in range(1, len(x))]
# distance between the first city and the start point
dist.append(abs(x[0] - X))
def listgcd(xs):
g = xs[0]
for i in range(1, len(xs)):
g = fractions.gcd(g, xs[i])
return g
print((listgcd(dist)))
|
from fractions import gcd
from functools import reduce
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
x.sort()
# distance between each two cities
dist = [x[i] - x[i - 1] for i in range(1, len(x))]
# distance between the first city and the start point
dist.append(abs(x[0] - X))
print((reduce(gcd, dist)))
| false | 23.809524 |
[
"-import fractions",
"+from fractions import gcd",
"+from functools import reduce",
"-",
"-",
"-def listgcd(xs):",
"- g = xs[0]",
"- for i in range(1, len(xs)):",
"- g = fractions.gcd(g, xs[i])",
"- return g",
"-",
"-",
"-print((listgcd(dist)))",
"+print((reduce(gcd, dist)))"
] | false | 0.052656 | 0.105539 | 0.498924 |
[
"s997610965",
"s672312813"
] |
u877283726
|
p03680
|
python
|
s275269001
|
s571706363
| 228 | 203 | 7,852 | 7,084 |
Accepted
|
Accepted
| 10.96 |
N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
pushed = [0] * N
pushed[0] = 1
current_bottom = a[0]
ans = 1
if current_bottom == 2:
print(ans)
exit()
for _ in range(N):
current_bottom = a[current_bottom-1]
if pushed[current_bottom-1] == 1:
print((-1))
exit()
else:
pushed[current_bottom-1] = 1
ans += 1
if current_bottom == 2:
print(ans)
exit()
|
N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
current_bottom = a[0]
ans = 1
if current_bottom == 2:
print(ans)
exit()
for _ in range(N):
current_bottom = a[current_bottom-1]
ans += 1
if current_bottom == 2:
print(ans)
exit()
print((-1))
| 25 | 18 | 460 | 313 |
N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
pushed = [0] * N
pushed[0] = 1
current_bottom = a[0]
ans = 1
if current_bottom == 2:
print(ans)
exit()
for _ in range(N):
current_bottom = a[current_bottom - 1]
if pushed[current_bottom - 1] == 1:
print((-1))
exit()
else:
pushed[current_bottom - 1] = 1
ans += 1
if current_bottom == 2:
print(ans)
exit()
|
N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
current_bottom = a[0]
ans = 1
if current_bottom == 2:
print(ans)
exit()
for _ in range(N):
current_bottom = a[current_bottom - 1]
ans += 1
if current_bottom == 2:
print(ans)
exit()
print((-1))
| false | 28 |
[
"-pushed = [0] * N",
"-pushed[0] = 1",
"- if pushed[current_bottom - 1] == 1:",
"- print((-1))",
"- exit()",
"- else:",
"- pushed[current_bottom - 1] = 1",
"+print((-1))"
] | false | 0.043206 | 0.039378 | 1.097223 |
[
"s275269001",
"s571706363"
] |
u562935282
|
p03262
|
python
|
s184597239
|
s129037293
| 145 | 100 | 14,252 | 15,020 |
Accepted
|
Accepted
| 31.03 |
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = sorted(x)
x = list([abs(arg - X) for arg in x])
g = x[0]
for xx in x:
g = gcd(g, xx)
print(g)
|
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = list([abs(arg - X) for arg in x])
g = x[0]
for xx in x[1:]:
g = gcd(g, xx)
print(g)
| 14 | 13 | 256 | 245 |
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = sorted(x)
x = list([abs(arg - X) for arg in x])
g = x[0]
for xx in x:
g = gcd(g, xx)
print(g)
|
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x = list([abs(arg - X) for arg in x])
g = x[0]
for xx in x[1:]:
g = gcd(g, xx)
print(g)
| false | 7.142857 |
[
"-x = sorted(x)",
"-for xx in x:",
"+for xx in x[1:]:"
] | false | 0.038833 | 0.037676 | 1.030706 |
[
"s184597239",
"s129037293"
] |
u216392490
|
p02596
|
python
|
s570247376
|
s043772087
| 363 | 246 | 9,140 | 9,180 |
Accepted
|
Accepted
| 32.23 |
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
dprint = print
else:
def dprint(*args):
pass
k = list(map(int, input().split()))[0]
if (k % 7 == 0):
l = 9*k/7
else:
l = 9*k
dprint('k, l = ', k, l)
i = 1
n = 10
while(i < 10**6):
m = n % l
if (m == 1): # (10^i mod L = 1)
print(i)
exit()
dprint('i, n, m = ', i, n, m)
i = i + 1
n = m * 10
else:
print(-1)
|
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
dprint = print
else:
def dprint(*args):
pass
k = list(map(int, input().split()))[0]
am = 7 % k
i = 1
for i in range(k):
if am==0:
print(i+1)
exit()
else:
i+=1
am=(am*10+7)%k
print('-1')
| 31 | 24 | 480 | 347 |
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
dprint = print
else:
def dprint(*args):
pass
k = list(map(int, input().split()))[0]
if k % 7 == 0:
l = 9 * k / 7
else:
l = 9 * k
dprint("k, l = ", k, l)
i = 1
n = 10
while i < 10**6:
m = n % l
if m == 1: # (10^i mod L = 1)
print(i)
exit()
dprint("i, n, m = ", i, n, m)
i = i + 1
n = m * 10
else:
print(-1)
|
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
dprint = print
else:
def dprint(*args):
pass
k = list(map(int, input().split()))[0]
am = 7 % k
i = 1
for i in range(k):
if am == 0:
print(i + 1)
exit()
else:
i += 1
am = (am * 10 + 7) % k
print("-1")
| false | 22.580645 |
[
"-if k % 7 == 0:",
"- l = 9 * k / 7",
"-else:",
"- l = 9 * k",
"-dprint(\"k, l = \", k, l)",
"+am = 7 % k",
"-n = 10",
"-while i < 10**6:",
"- m = n % l",
"- if m == 1: # (10^i mod L = 1)",
"- print(i)",
"+for i in range(k):",
"+ if am == 0:",
"+ print(i + 1)",
"- dprint(\"i, n, m = \", i, n, m)",
"- i = i + 1",
"- n = m * 10",
"-else:",
"- print(-1)",
"+ else:",
"+ i += 1",
"+ am = (am * 10 + 7) % k",
"+print(\"-1\")"
] | false | 0.292896 | 0.226557 | 1.292812 |
[
"s570247376",
"s043772087"
] |
u199194110
|
p03836
|
python
|
s666269943
|
s539757612
| 26 | 11 | 3,708 | 2,816 |
Accepted
|
Accepted
| 57.69 |
# coding: utf-8
import sys
import itertools
def move(x,y):
xs = "R"*x if x > 0 else "L"*(-x)
ys = "U"*y if y > 0 else "D"*(-y)
return (xs, ys)
def main():
sx, sy, tx, ty = list(map(int,sys.stdin.read().split()))
x = tx - sx
y = ty - sy
xs, ys = move(x,y)
ans = ys + xs
xs, ys = move(-x,-y)
ans += ys + xs
xs, ys = move(x+1,y+1)
ans += "L" + ys + xs + "D"
xs, ys = move(-(x+1),-(y+1))
ans += "R" + ys + xs + "U"
sys.stdout.write(ans)
if __name__ == '__main__':
main()
|
# coding: utf-8
import sys
LEFT = "L"
RIGHT = "R"
UP = "U"
DOWN = "D"
def move(x,y):
xs = RIGHT*x if x > 0 else LEFT*(-x)
ys = UP*y if y > 0 else DOWN*(-y)
return ys + xs
def main():
sx, sy, tx, ty = list(map(int,sys.stdin.read().split()))
x = tx - sx
y = ty - sy
ans = ""
ans += move(x,y)
ans += move(-x,-y)
ans += LEFT + move(x+1,y+1) + DOWN
ans += RIGHT + move(-(x+1),-(y+1)) + UP
sys.stdout.write(ans)
if __name__ == '__main__':
main()
| 32 | 31 | 646 | 603 |
# coding: utf-8
import sys
import itertools
def move(x, y):
xs = "R" * x if x > 0 else "L" * (-x)
ys = "U" * y if y > 0 else "D" * (-y)
return (xs, ys)
def main():
sx, sy, tx, ty = list(map(int, sys.stdin.read().split()))
x = tx - sx
y = ty - sy
xs, ys = move(x, y)
ans = ys + xs
xs, ys = move(-x, -y)
ans += ys + xs
xs, ys = move(x + 1, y + 1)
ans += "L" + ys + xs + "D"
xs, ys = move(-(x + 1), -(y + 1))
ans += "R" + ys + xs + "U"
sys.stdout.write(ans)
if __name__ == "__main__":
main()
|
# coding: utf-8
import sys
LEFT = "L"
RIGHT = "R"
UP = "U"
DOWN = "D"
def move(x, y):
xs = RIGHT * x if x > 0 else LEFT * (-x)
ys = UP * y if y > 0 else DOWN * (-y)
return ys + xs
def main():
sx, sy, tx, ty = list(map(int, sys.stdin.read().split()))
x = tx - sx
y = ty - sy
ans = ""
ans += move(x, y)
ans += move(-x, -y)
ans += LEFT + move(x + 1, y + 1) + DOWN
ans += RIGHT + move(-(x + 1), -(y + 1)) + UP
sys.stdout.write(ans)
if __name__ == "__main__":
main()
| false | 3.125 |
[
"-import itertools",
"+",
"+LEFT = \"L\"",
"+RIGHT = \"R\"",
"+UP = \"U\"",
"+DOWN = \"D\"",
"- xs = \"R\" * x if x > 0 else \"L\" * (-x)",
"- ys = \"U\" * y if y > 0 else \"D\" * (-y)",
"- return (xs, ys)",
"+ xs = RIGHT * x if x > 0 else LEFT * (-x)",
"+ ys = UP * y if y > 0 else DOWN * (-y)",
"+ return ys + xs",
"- xs, ys = move(x, y)",
"- ans = ys + xs",
"- xs, ys = move(-x, -y)",
"- ans += ys + xs",
"- xs, ys = move(x + 1, y + 1)",
"- ans += \"L\" + ys + xs + \"D\"",
"- xs, ys = move(-(x + 1), -(y + 1))",
"- ans += \"R\" + ys + xs + \"U\"",
"+ ans = \"\"",
"+ ans += move(x, y)",
"+ ans += move(-x, -y)",
"+ ans += LEFT + move(x + 1, y + 1) + DOWN",
"+ ans += RIGHT + move(-(x + 1), -(y + 1)) + UP"
] | false | 0.040829 | 0.035954 | 1.135594 |
[
"s666269943",
"s539757612"
] |
u970267139
|
p03127
|
python
|
s195906054
|
s527912930
| 319 | 63 | 20,004 | 20,396 |
Accepted
|
Accepted
| 80.25 |
n = int(eval(input()))
a = list(map(int, input().split()))
m = 0
tmp = min(a)
while m != tmp:
m = tmp
for i in range(n):
if a[i] != m:
a[i] = a[i] % m
if a[i] < m and a[i] != 0:
tmp = a[i]
print(m)
|
import math
from functools import reduce
def gcd_list(numbers):
return reduce(math.gcd, numbers)
n = int(eval(input()))
a = list(map(int, input().split()))
print((gcd_list(a)))
| 13 | 10 | 253 | 185 |
n = int(eval(input()))
a = list(map(int, input().split()))
m = 0
tmp = min(a)
while m != tmp:
m = tmp
for i in range(n):
if a[i] != m:
a[i] = a[i] % m
if a[i] < m and a[i] != 0:
tmp = a[i]
print(m)
|
import math
from functools import reduce
def gcd_list(numbers):
return reduce(math.gcd, numbers)
n = int(eval(input()))
a = list(map(int, input().split()))
print((gcd_list(a)))
| false | 23.076923 |
[
"+import math",
"+from functools import reduce",
"+",
"+",
"+def gcd_list(numbers):",
"+ return reduce(math.gcd, numbers)",
"+",
"+",
"-m = 0",
"-tmp = min(a)",
"-while m != tmp:",
"- m = tmp",
"- for i in range(n):",
"- if a[i] != m:",
"- a[i] = a[i] % m",
"- if a[i] < m and a[i] != 0:",
"- tmp = a[i]",
"-print(m)",
"+print((gcd_list(a)))"
] | false | 0.105299 | 0.036884 | 2.854893 |
[
"s195906054",
"s527912930"
] |
u886274153
|
p03244
|
python
|
s878551679
|
s405533194
| 123 | 79 | 21,144 | 15,588 |
Accepted
|
Accepted
| 35.77 |
n = int(eval(input()))
v = [int(i) for i in input().split()]
a, b = dict(), dict()
for i in range(n):
if i%2 == 0:
a[v[i]] = a.get(v[i], 0) + 1
else:
b[v[i]] = b.get(v[i], 0) + 1
alst = sorted(list(a.items()), key=lambda x: x[1], reverse=True)
blst = sorted(list(b.items()), key=lambda x: x[1], reverse=True)
if alst[0][0] != blst[0][0]:
print((n-alst[0][1]-blst[0][1]))
elif len(alst) == 1 and len(blst) == 1:
print((blst[0][1]))
elif len(alst) == 1:
print((n-alst[0][1]-blst[1][1]))
elif len(blst) == 1:
print((n-alst[1][1]-blst[0][1]))
elif blst[0][1]+alst[1][1] > alst[0][1]+blst[1][1]:
print((n-alst[1][1]-blst[0][1]))
else:
print((n-alst[0][1]-blst[1][1]))
|
import collections
n = int(eval(input()))
v = [int(i) for i in input().split()]
dummy = [(-1, 0)]
(av1, ak1), (av2, ak2) = (collections.Counter(v[::2]).most_common(2) + dummy)[:2]
(bv1, bk1), (bv2, bk2) = (collections.Counter(v[1::2]).most_common(2) + dummy)[:2]
if av1 != bv1:
print((n-ak1-bk1))
elif ak1 < bk1:
print((n-ak2-bk1))
elif ak1 > bk1:
print((n-ak1-bk2))
elif ak1+bk2 > bk1+ak2:
print((n-ak1-bk2))
else:
print((n-ak2-bk1))
| 24 | 18 | 721 | 457 |
n = int(eval(input()))
v = [int(i) for i in input().split()]
a, b = dict(), dict()
for i in range(n):
if i % 2 == 0:
a[v[i]] = a.get(v[i], 0) + 1
else:
b[v[i]] = b.get(v[i], 0) + 1
alst = sorted(list(a.items()), key=lambda x: x[1], reverse=True)
blst = sorted(list(b.items()), key=lambda x: x[1], reverse=True)
if alst[0][0] != blst[0][0]:
print((n - alst[0][1] - blst[0][1]))
elif len(alst) == 1 and len(blst) == 1:
print((blst[0][1]))
elif len(alst) == 1:
print((n - alst[0][1] - blst[1][1]))
elif len(blst) == 1:
print((n - alst[1][1] - blst[0][1]))
elif blst[0][1] + alst[1][1] > alst[0][1] + blst[1][1]:
print((n - alst[1][1] - blst[0][1]))
else:
print((n - alst[0][1] - blst[1][1]))
|
import collections
n = int(eval(input()))
v = [int(i) for i in input().split()]
dummy = [(-1, 0)]
(av1, ak1), (av2, ak2) = (collections.Counter(v[::2]).most_common(2) + dummy)[:2]
(bv1, bk1), (bv2, bk2) = (collections.Counter(v[1::2]).most_common(2) + dummy)[:2]
if av1 != bv1:
print((n - ak1 - bk1))
elif ak1 < bk1:
print((n - ak2 - bk1))
elif ak1 > bk1:
print((n - ak1 - bk2))
elif ak1 + bk2 > bk1 + ak2:
print((n - ak1 - bk2))
else:
print((n - ak2 - bk1))
| false | 25 |
[
"+import collections",
"+",
"-a, b = dict(), dict()",
"-for i in range(n):",
"- if i % 2 == 0:",
"- a[v[i]] = a.get(v[i], 0) + 1",
"- else:",
"- b[v[i]] = b.get(v[i], 0) + 1",
"-alst = sorted(list(a.items()), key=lambda x: x[1], reverse=True)",
"-blst = sorted(list(b.items()), key=lambda x: x[1], reverse=True)",
"-if alst[0][0] != blst[0][0]:",
"- print((n - alst[0][1] - blst[0][1]))",
"-elif len(alst) == 1 and len(blst) == 1:",
"- print((blst[0][1]))",
"-elif len(alst) == 1:",
"- print((n - alst[0][1] - blst[1][1]))",
"-elif len(blst) == 1:",
"- print((n - alst[1][1] - blst[0][1]))",
"-elif blst[0][1] + alst[1][1] > alst[0][1] + blst[1][1]:",
"- print((n - alst[1][1] - blst[0][1]))",
"+dummy = [(-1, 0)]",
"+(av1, ak1), (av2, ak2) = (collections.Counter(v[::2]).most_common(2) + dummy)[:2]",
"+(bv1, bk1), (bv2, bk2) = (collections.Counter(v[1::2]).most_common(2) + dummy)[:2]",
"+if av1 != bv1:",
"+ print((n - ak1 - bk1))",
"+elif ak1 < bk1:",
"+ print((n - ak2 - bk1))",
"+elif ak1 > bk1:",
"+ print((n - ak1 - bk2))",
"+elif ak1 + bk2 > bk1 + ak2:",
"+ print((n - ak1 - bk2))",
"- print((n - alst[0][1] - blst[1][1]))",
"+ print((n - ak2 - bk1))"
] | false | 0.04499 | 0.062864 | 0.715664 |
[
"s878551679",
"s405533194"
] |
u729133443
|
p02760
|
python
|
s675099296
|
s017199937
| 162 | 17 | 38,384 | 3,064 |
Accepted
|
Accepted
| 89.51 |
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
|
a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[9:]))for t in({0,3,6},{0,4,8},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2]))
| 1 | 1 | 132 | 131 |
a = open(0).read().split()
print(
(
"YNeos"[
all(
t - set(map(a.index, a[10:]))
for t in (
{0, 3, 6},
{0, 4, 8},
{2, 4, 6},
{2, 5, 8},
{3, 4, 5},
{6, 7, 8},
)
) :: 2
]
)
)
|
a = open(0).read().split()
print(
(
"YNeos"[
all(
t - set(map(a.index, a[9:]))
for t in (
{0, 3, 6},
{0, 4, 8},
{2, 4, 6},
{2, 5, 8},
{3, 4, 5},
{6, 7, 8},
)
) :: 2
]
)
)
| false | 0 |
[
"- t - set(map(a.index, a[10:]))",
"+ t - set(map(a.index, a[9:]))"
] | false | 0.103291 | 0.035783 | 2.886553 |
[
"s675099296",
"s017199937"
] |
u768896740
|
p03721
|
python
|
s425811673
|
s301315838
| 416 | 356 | 30,164 | 14,944 |
Accepted
|
Accepted
| 14.42 |
n, k = list(map(int, input().split()))
lis = []
max_num = 0
for i in range(n):
array = list(map(int, input().split()))
if array[0] > max_num:
max_num = array[0]
lis.append(array)
num_list = [0] * max_num
for i, j in lis:
num_list[i-1] += j
count = 0
for i in range(len(num_list)):
count += num_list[i]
if count >= k:
print((i+1))
exit()
|
from collections import defaultdict
n, k = list(map(int, input().split()))
cnt = 0
d = defaultdict(int)
for i in range(n):
a, b = list(map(int, input().split()))
d[a] += b
d = sorted(d.items())
for i, j in d:
cnt += j
if cnt >= k:
print(i)
break
| 21 | 19 | 400 | 290 |
n, k = list(map(int, input().split()))
lis = []
max_num = 0
for i in range(n):
array = list(map(int, input().split()))
if array[0] > max_num:
max_num = array[0]
lis.append(array)
num_list = [0] * max_num
for i, j in lis:
num_list[i - 1] += j
count = 0
for i in range(len(num_list)):
count += num_list[i]
if count >= k:
print((i + 1))
exit()
|
from collections import defaultdict
n, k = list(map(int, input().split()))
cnt = 0
d = defaultdict(int)
for i in range(n):
a, b = list(map(int, input().split()))
d[a] += b
d = sorted(d.items())
for i, j in d:
cnt += j
if cnt >= k:
print(i)
break
| false | 9.52381 |
[
"+from collections import defaultdict",
"+",
"-lis = []",
"-max_num = 0",
"+cnt = 0",
"+d = defaultdict(int)",
"- array = list(map(int, input().split()))",
"- if array[0] > max_num:",
"- max_num = array[0]",
"- lis.append(array)",
"-num_list = [0] * max_num",
"-for i, j in lis:",
"- num_list[i - 1] += j",
"-count = 0",
"-for i in range(len(num_list)):",
"- count += num_list[i]",
"- if count >= k:",
"- print((i + 1))",
"- exit()",
"+ a, b = list(map(int, input().split()))",
"+ d[a] += b",
"+d = sorted(d.items())",
"+for i, j in d:",
"+ cnt += j",
"+ if cnt >= k:",
"+ print(i)",
"+ break"
] | false | 0.047443 | 0.113465 | 0.418129 |
[
"s425811673",
"s301315838"
] |
u493130708
|
p02949
|
python
|
s553774190
|
s337969674
| 1,659 | 1,030 | 75,888 | 75,496 |
Accepted
|
Accepted
| 37.91 |
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7
N,M,P = list(map(int,(input().split())))
line = []
for i in range(M):
a,b,c = list(map(int,(input().split())))
line.append([a-1,b-1,-c+P])
min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
def Bellman_Ford(S,V,E,distance):
update = False
flag = 0
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance,flag
def Bellman_Ford2(S,V,E,distance):
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
if g == N-1:
print((-1))
exit()
break
else:
continue
break
return min_distance
min_distance,flag = Bellman_Ford(1,N,M,line)
if flag == 1:
ans = min_distance[N-1]
print((max(-ans,0)))
else:
min_distance = Bellman_Ford2(1,N,M,line)
ans = min_distance[N-1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans,0)))
#print(min_distance)
|
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7
N,M,P = list(map(int,(input().split())))
line = []
for i in range(M):
a,b,c = list(map(int,(input().split())))
line.append([a-1,b-1,-c+P])
min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
def Bellman_Ford(S,V,E,distance):
flag = 0
for _ in range(V):
update = False
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance,flag
def Bellman_Ford2(S,V,E,distance):
for _ in range(V):
for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
if g == N-1:
break
else:
continue
break
return min_distance
min_distance,flag = Bellman_Ford(1,N,M,line)
if flag == 1:
ans = min_distance[N-1]
print((max(-ans,0)))
else:
min_distance = Bellman_Ford2(1,N,M,line)
ans = min_distance[N-1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans,0)))
#print(min_distance)
| 62 | 61 | 1,795 | 1,746 |
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9 + 7
N, M, P = list(map(int, (input().split())))
line = []
for i in range(M):
a, b, c = list(map(int, (input().split())))
line.append([a - 1, b - 1, -c + P])
min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
def Bellman_Ford(S, V, E, distance):
update = False
flag = 0
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance, flag
def Bellman_Ford2(S, V, E, distance):
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
if g == N - 1:
print((-1))
exit()
break
else:
continue
break
return min_distance
min_distance, flag = Bellman_Ford(1, N, M, line)
if flag == 1:
ans = min_distance[N - 1]
print((max(-ans, 0)))
else:
min_distance = Bellman_Ford2(1, N, M, line)
ans = min_distance[N - 1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans, 0)))
# print(min_distance)
|
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9 + 7
N, M, P = list(map(int, (input().split())))
line = []
for i in range(M):
a, b, c = list(map(int, (input().split())))
line.append([a - 1, b - 1, -c + P])
min_distance = [float("inf")] * N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
def Bellman_Ford(S, V, E, distance):
flag = 0
for _ in range(V):
update = False
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = min_distance[s] + d # 最短距離を上書きする
update = True
if not update:
flag = 1
break
return min_distance, flag
def Bellman_Ford2(S, V, E, distance):
for _ in range(V):
for s, g, d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
if (
min_distance[s] != float("inf")
and min_distance[s] + d < min_distance[g]
): # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
min_distance[g] = -float("inf")
if g == N - 1:
break
else:
continue
break
return min_distance
min_distance, flag = Bellman_Ford(1, N, M, line)
if flag == 1:
ans = min_distance[N - 1]
print((max(-ans, 0)))
else:
min_distance = Bellman_Ford2(1, N, M, line)
ans = min_distance[N - 1]
if ans == -float("inf"):
print((-1))
else:
print((max(-ans, 0)))
# print(min_distance)
| false | 1.612903 |
[
"- update = False",
"+ update = False",
"- print((-1))",
"- exit()"
] | false | 0.007066 | 0.03272 | 0.215954 |
[
"s553774190",
"s337969674"
] |
u655110382
|
p03687
|
python
|
s633756371
|
s623393943
| 22 | 18 | 3,316 | 3,060 |
Accepted
|
Accepted
| 18.18 |
from collections import Counter, deque
s = eval(input())
n = len(s)
d = deque([{char} for char in s])
c = Counter(s)
if s[0] * n == s:
print((0))
exit()
for i in range(1, n):
for j in range(n - i):
char_j = s[j]
char_right = s[j + i]
set_j = d[j]
if char_right not in set_j:
set_j.add(char_right)
c[char_right] += 1
rightest = d.pop()
for char in rightest:
c[char] -= 1
if max(c.values()) == n - i:
print(i)
exit()
print('oops, something wrong')
|
s = eval(input())
a_z = [chr(i) for i in range(97, 97 + 26)]
ans = len(s)
for alp in a_z:
cnt = 0
step = 0
for char in s:
if char == alp:
cnt = max(cnt, step)
step = 0
else:
step += 1
ans = min(max(cnt, step), ans)
print(ans)
| 26 | 14 | 570 | 301 |
from collections import Counter, deque
s = eval(input())
n = len(s)
d = deque([{char} for char in s])
c = Counter(s)
if s[0] * n == s:
print((0))
exit()
for i in range(1, n):
for j in range(n - i):
char_j = s[j]
char_right = s[j + i]
set_j = d[j]
if char_right not in set_j:
set_j.add(char_right)
c[char_right] += 1
rightest = d.pop()
for char in rightest:
c[char] -= 1
if max(c.values()) == n - i:
print(i)
exit()
print("oops, something wrong")
|
s = eval(input())
a_z = [chr(i) for i in range(97, 97 + 26)]
ans = len(s)
for alp in a_z:
cnt = 0
step = 0
for char in s:
if char == alp:
cnt = max(cnt, step)
step = 0
else:
step += 1
ans = min(max(cnt, step), ans)
print(ans)
| false | 46.153846 |
[
"-from collections import Counter, deque",
"-",
"-n = len(s)",
"-d = deque([{char} for char in s])",
"-c = Counter(s)",
"-if s[0] * n == s:",
"- print((0))",
"- exit()",
"-for i in range(1, n):",
"- for j in range(n - i):",
"- char_j = s[j]",
"- char_right = s[j + i]",
"- set_j = d[j]",
"- if char_right not in set_j:",
"- set_j.add(char_right)",
"- c[char_right] += 1",
"- rightest = d.pop()",
"- for char in rightest:",
"- c[char] -= 1",
"- if max(c.values()) == n - i:",
"- print(i)",
"- exit()",
"-print(\"oops, something wrong\")",
"+a_z = [chr(i) for i in range(97, 97 + 26)]",
"+ans = len(s)",
"+for alp in a_z:",
"+ cnt = 0",
"+ step = 0",
"+ for char in s:",
"+ if char == alp:",
"+ cnt = max(cnt, step)",
"+ step = 0",
"+ else:",
"+ step += 1",
"+ ans = min(max(cnt, step), ans)",
"+print(ans)"
] | false | 0.049078 | 0.045541 | 1.077656 |
[
"s633756371",
"s623393943"
] |
u102461423
|
p03482
|
python
|
s264809443
|
s446314598
| 473 | 40 | 20,048 | 7,892 |
Accepted
|
Accepted
| 91.54 |
# [a,b] - [a,b) = {b} なので、端の方は自由。
# 中央が単色であるかを確認すればよい。
import numpy as np
arr = np.array([int(x) for x in eval(input())])
arr_c = arr.cumsum()
N = arr.size
answer = 0
for K in range(N,0,-1):
left = N-K
right = K-1
# [left,right]が単色であればよい
if left >= right:
answer = K
break
one_cnt = arr_c[right] - arr_c[left] + arr[left]
zero_cnt = (right - left + 1) - one_cnt
if one_cnt == 0 or zero_cnt == 0:
answer = K
break
print(answer)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
S = [int(x) - ord('0') for x in read().rstrip()]
N = len(S)
Scum = list(itertools.accumulate(S))
def test(x):
if x + x <= N:
return True
L = N - x
R = x
cnt = Scum[R-1] - Scum[L] + S[L]
return cnt in [0,R-L]
left = 0 # True
right = N + 1 # False
while left + 1 < right:
x = (left + right) // 2
if test(x):
left = x
else:
right = x
answer = left
print(answer)
| 25 | 31 | 483 | 583 |
# [a,b] - [a,b) = {b} なので、端の方は自由。
# 中央が単色であるかを確認すればよい。
import numpy as np
arr = np.array([int(x) for x in eval(input())])
arr_c = arr.cumsum()
N = arr.size
answer = 0
for K in range(N, 0, -1):
left = N - K
right = K - 1
# [left,right]が単色であればよい
if left >= right:
answer = K
break
one_cnt = arr_c[right] - arr_c[left] + arr[left]
zero_cnt = (right - left + 1) - one_cnt
if one_cnt == 0 or zero_cnt == 0:
answer = K
break
print(answer)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
S = [int(x) - ord("0") for x in read().rstrip()]
N = len(S)
Scum = list(itertools.accumulate(S))
def test(x):
if x + x <= N:
return True
L = N - x
R = x
cnt = Scum[R - 1] - Scum[L] + S[L]
return cnt in [0, R - L]
left = 0 # True
right = N + 1 # False
while left + 1 < right:
x = (left + right) // 2
if test(x):
left = x
else:
right = x
answer = left
print(answer)
| false | 19.354839 |
[
"-# [a,b] - [a,b) = {b} なので、端の方は自由。",
"-# 中央が単色であるかを確認すればよい。",
"-import numpy as np",
"+import sys",
"-arr = np.array([int(x) for x in eval(input())])",
"-arr_c = arr.cumsum()",
"-N = arr.size",
"-answer = 0",
"-for K in range(N, 0, -1):",
"- left = N - K",
"- right = K - 1",
"- # [left,right]が単色であればよい",
"- if left >= right:",
"- answer = K",
"- break",
"- one_cnt = arr_c[right] - arr_c[left] + arr[left]",
"- zero_cnt = (right - left + 1) - one_cnt",
"- if one_cnt == 0 or zero_cnt == 0:",
"- answer = K",
"- break",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+import itertools",
"+",
"+S = [int(x) - ord(\"0\") for x in read().rstrip()]",
"+N = len(S)",
"+Scum = list(itertools.accumulate(S))",
"+",
"+",
"+def test(x):",
"+ if x + x <= N:",
"+ return True",
"+ L = N - x",
"+ R = x",
"+ cnt = Scum[R - 1] - Scum[L] + S[L]",
"+ return cnt in [0, R - L]",
"+",
"+",
"+left = 0 # True",
"+right = N + 1 # False",
"+while left + 1 < right:",
"+ x = (left + right) // 2",
"+ if test(x):",
"+ left = x",
"+ else:",
"+ right = x",
"+answer = left"
] | false | 0.222737 | 0.037338 | 5.965489 |
[
"s264809443",
"s446314598"
] |
u816587940
|
p02936
|
python
|
s880707791
|
s145193733
| 1,953 | 916 | 121,420 | 113,260 |
Accepted
|
Accepted
| 53.1 |
#入力
n, q = map(int, input().split())
G = [[] for _ in range(n+1)]
for i in range(n-1):
x, y = map(int, input().split())
G[x].append(y)
G[y].append(x)
counter = [0 for _ in range(n+1)]
for _ in range(q):
x, y = map(int, input().split())
counter[x] += y
"""
#再帰
ans_dfs = [0 for _ in range(n)]
def dfs(now, parent, S):
ans_dfs[now] = S + counter[now]
for to in G[now]:
if to == parent: continue
dfs(to, now, ans_dfs[now])
"""
#非再帰
class p:
num = -1
parent = -1
def __init__(self, x, y):
self.num = x
self.parent = y
#dfsでの探索順
node_list = []
ans = [0 for _ in range(n+1)]
def main():
#dfs(1, -1, 0)
#dfsでの探索順の作成
stack = []
stack.append(p(1, -1))
while len(stack) != 0:
now = stack.pop()
node_list.append(now)
for to in G[now.num]:
if to == now.parent: continue
stack.append(p(to, now.num))
for now in node_list:
ans[now.num] = counter[now.num] + ans[now.parent]
for i in range(1, n+1): print(ans[i], end=' ')
print()
if __name__ == '__main__':
main()
|
import sys
input = lambda: sys.stdin.readline().rstrip()
#入力
n, q = map(int, input().split())
G = [[] for _ in range(n+1)]
for i in range(n-1):
x, y = map(int, input().split())
G[x].append(y)
G[y].append(x)
counter = [0 for _ in range(n+1)]
for _ in range(q):
x, y = map(int, input().split())
counter[x] += y
"""
#再帰
ans_dfs = [0 for _ in range(n)]
def dfs(now, parent, S):
ans_dfs[now] = S + counter[now]
for to in G[now]:
if to == parent: continue
dfs(to, now, ans_dfs[now])
"""
#非再帰
class p:
num = -1
parent = -1
def __init__(self, x, y):
self.num = x
self.parent = y
#dfsでの探索順
node_list = []
ans = [0 for _ in range(n+1)]
def main():
#dfs(1, -1, 0)
#dfsでの探索順の作成
stack = []
stack.append(p(1, -1))
while len(stack) != 0:
now = stack.pop()
node_list.append(now)
for to in G[now.num]:
if to == now.parent: continue
stack.append(p(to, now.num))
for now in node_list:
ans[now.num] = counter[now.num] + ans[now.parent]
for i in range(1, n+1): print(ans[i], end=' ')
print()
if __name__ == '__main__':
main()
| 58 | 60 | 1,180 | 1,239 |
# 入力
n, q = map(int, input().split())
G = [[] for _ in range(n + 1)]
for i in range(n - 1):
x, y = map(int, input().split())
G[x].append(y)
G[y].append(x)
counter = [0 for _ in range(n + 1)]
for _ in range(q):
x, y = map(int, input().split())
counter[x] += y
"""
#再帰
ans_dfs = [0 for _ in range(n)]
def dfs(now, parent, S):
ans_dfs[now] = S + counter[now]
for to in G[now]:
if to == parent: continue
dfs(to, now, ans_dfs[now])
"""
# 非再帰
class p:
num = -1
parent = -1
def __init__(self, x, y):
self.num = x
self.parent = y
# dfsでの探索順
node_list = []
ans = [0 for _ in range(n + 1)]
def main():
# dfs(1, -1, 0)
# dfsでの探索順の作成
stack = []
stack.append(p(1, -1))
while len(stack) != 0:
now = stack.pop()
node_list.append(now)
for to in G[now.num]:
if to == now.parent:
continue
stack.append(p(to, now.num))
for now in node_list:
ans[now.num] = counter[now.num] + ans[now.parent]
for i in range(1, n + 1):
print(ans[i], end=" ")
print()
if __name__ == "__main__":
main()
|
import sys
input = lambda: sys.stdin.readline().rstrip()
# 入力
n, q = map(int, input().split())
G = [[] for _ in range(n + 1)]
for i in range(n - 1):
x, y = map(int, input().split())
G[x].append(y)
G[y].append(x)
counter = [0 for _ in range(n + 1)]
for _ in range(q):
x, y = map(int, input().split())
counter[x] += y
"""
#再帰
ans_dfs = [0 for _ in range(n)]
def dfs(now, parent, S):
ans_dfs[now] = S + counter[now]
for to in G[now]:
if to == parent: continue
dfs(to, now, ans_dfs[now])
"""
# 非再帰
class p:
num = -1
parent = -1
def __init__(self, x, y):
self.num = x
self.parent = y
# dfsでの探索順
node_list = []
ans = [0 for _ in range(n + 1)]
def main():
# dfs(1, -1, 0)
# dfsでの探索順の作成
stack = []
stack.append(p(1, -1))
while len(stack) != 0:
now = stack.pop()
node_list.append(now)
for to in G[now.num]:
if to == now.parent:
continue
stack.append(p(to, now.num))
for now in node_list:
ans[now.num] = counter[now.num] + ans[now.parent]
for i in range(1, n + 1):
print(ans[i], end=" ")
print()
if __name__ == "__main__":
main()
| false | 3.333333 |
[
"+import sys",
"+",
"+input = lambda: sys.stdin.readline().rstrip()"
] | false | 0.040319 | 0.044065 | 0.914991 |
[
"s880707791",
"s145193733"
] |
u910288980
|
p03435
|
python
|
s649295801
|
s870355429
| 199 | 17 | 38,384 | 3,064 |
Accepted
|
Accepted
| 91.46 |
# -*- coding: utf-8 -*-
def solve():
c = [list(map(int, input().split())) for _ in range(3)]
for a0 in range(-100, 101) :
b = [c[0][i] - a0 for i in range(3)]
if any(c[1][0] - b[0] != c[1][i] - b[i] for i in range(3)):
continue
if any(c[2][0] - b[0] != c[2][i] - b[i] for i in range(3)):
continue
return True
if __name__ == '__main__':
if solve() :
print("Yes")
else :
print("No")
|
# -*- coding: utf-8 -*-
def solve():
c = [list(map(int, input().split())) for _ in range(3)]
for a0 in range(-100, 101) :
b = [c[0][i] - a0 for i in range(3)]
if any(c[1][0] - b[0] != c[1][i] - b[i] for i in range(3)):
continue
if any(c[2][0] - b[0] != c[2][i] - b[i] for i in range(3)):
continue
return True
return False
if solve() :
print("Yes")
else :
print("No")
| 18 | 18 | 489 | 463 |
# -*- coding: utf-8 -*-
def solve():
c = [list(map(int, input().split())) for _ in range(3)]
for a0 in range(-100, 101):
b = [c[0][i] - a0 for i in range(3)]
if any(c[1][0] - b[0] != c[1][i] - b[i] for i in range(3)):
continue
if any(c[2][0] - b[0] != c[2][i] - b[i] for i in range(3)):
continue
return True
if __name__ == "__main__":
if solve():
print("Yes")
else:
print("No")
|
# -*- coding: utf-8 -*-
def solve():
c = [list(map(int, input().split())) for _ in range(3)]
for a0 in range(-100, 101):
b = [c[0][i] - a0 for i in range(3)]
if any(c[1][0] - b[0] != c[1][i] - b[i] for i in range(3)):
continue
if any(c[2][0] - b[0] != c[2][i] - b[i] for i in range(3)):
continue
return True
return False
if solve():
print("Yes")
else:
print("No")
| false | 0 |
[
"+ return False",
"-if __name__ == \"__main__\":",
"- if solve():",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+if solve():",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.119352 | 0.03716 | 3.2118 |
[
"s649295801",
"s870355429"
] |
u284854859
|
p03061
|
python
|
s902685098
|
s194551992
| 777 | 263 | 14,136 | 14,428 |
Accepted
|
Accepted
| 66.15 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
#a,bの最大公約数
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
#リスト l の最大公約数
def gcdlist(l):
a = l[0]
for i in range(len(l)):
a = gcd(a,l[i])
return a
#nの約数列挙
def divisor(n):
ass = []
for i in range(1,int(n**0.5)+1):
if n%i == 0:
ass.append(i)
if i**2 == n:
continue
ass.append(n//i)
return ass #sortされていない
#0番目を使わない場合
res = gcdlist(a[1::])
#else
p = sorted(divisor(a[0]))
for i in range(len(p)-1,-1,-1):
if p[i]<=res:
break
cnt = 1
for j in range(1,n):
if a[j]%p[i]==0:
cnt += 1
if cnt >= n-1:
res = p[i]
break
print(res)
|
#a,bの最大公約数
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
n = int(eval(input()))
a = list(map(int,input().split()))
#b[i]:a[0]~a[i]までのgcd,c[i]:a[i]~a[-1]までのgcd
b = [0]*n
c = [0]*n
for i in range(n):
if i == 0:
b[0] = a[0]
c[-1] = a[-1]
continue
b[i]=gcd(b[i-1],a[i])
c[n-1-i]=gcd(c[n-i],a[n-1-i])
res = max(b[n-2],c[1])
for i in range(1,n-1):
res = max(res,gcd(b[i-1],c[i+1]))
print(res)
| 45 | 25 | 853 | 484 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
# a,bの最大公約数
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
# リスト l の最大公約数
def gcdlist(l):
a = l[0]
for i in range(len(l)):
a = gcd(a, l[i])
return a
# nの約数列挙
def divisor(n):
ass = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
ass.append(i)
if i**2 == n:
continue
ass.append(n // i)
return ass # sortされていない
# 0番目を使わない場合
res = gcdlist(a[1::])
# else
p = sorted(divisor(a[0]))
for i in range(len(p) - 1, -1, -1):
if p[i] <= res:
break
cnt = 1
for j in range(1, n):
if a[j] % p[i] == 0:
cnt += 1
if cnt >= n - 1:
res = p[i]
break
print(res)
|
# a,bの最大公約数
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
n = int(eval(input()))
a = list(map(int, input().split()))
# b[i]:a[0]~a[i]までのgcd,c[i]:a[i]~a[-1]までのgcd
b = [0] * n
c = [0] * n
for i in range(n):
if i == 0:
b[0] = a[0]
c[-1] = a[-1]
continue
b[i] = gcd(b[i - 1], a[i])
c[n - 1 - i] = gcd(c[n - i], a[n - 1 - i])
res = max(b[n - 2], c[1])
for i in range(1, n - 1):
res = max(res, gcd(b[i - 1], c[i + 1]))
print(res)
| false | 44.444444 |
[
"-import sys",
"-",
"-input = sys.stdin.readline",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-a.sort()",
"-# リスト l の最大公約数",
"-def gcdlist(l):",
"- a = l[0]",
"- for i in range(len(l)):",
"- a = gcd(a, l[i])",
"- return a",
"-",
"-",
"-# nの約数列挙",
"-def divisor(n):",
"- ass = []",
"- for i in range(1, int(n**0.5) + 1):",
"- if n % i == 0:",
"- ass.append(i)",
"- if i**2 == n:",
"- continue",
"- ass.append(n // i)",
"- return ass # sortされていない",
"-",
"-",
"-# 0番目を使わない場合",
"-res = gcdlist(a[1::])",
"-# else",
"-p = sorted(divisor(a[0]))",
"-for i in range(len(p) - 1, -1, -1):",
"- if p[i] <= res:",
"- break",
"- cnt = 1",
"- for j in range(1, n):",
"- if a[j] % p[i] == 0:",
"- cnt += 1",
"- if cnt >= n - 1:",
"- res = p[i]",
"- break",
"+n = int(eval(input()))",
"+a = list(map(int, input().split()))",
"+# b[i]:a[0]~a[i]までのgcd,c[i]:a[i]~a[-1]までのgcd",
"+b = [0] * n",
"+c = [0] * n",
"+for i in range(n):",
"+ if i == 0:",
"+ b[0] = a[0]",
"+ c[-1] = a[-1]",
"+ continue",
"+ b[i] = gcd(b[i - 1], a[i])",
"+ c[n - 1 - i] = gcd(c[n - i], a[n - 1 - i])",
"+res = max(b[n - 2], c[1])",
"+for i in range(1, n - 1):",
"+ res = max(res, gcd(b[i - 1], c[i + 1]))"
] | false | 0.036241 | 0.036533 | 0.992009 |
[
"s902685098",
"s194551992"
] |
u133936772
|
p02834
|
python
|
s260277829
|
s581884358
| 662 | 467 | 28,464 | 28,464 |
Accepted
|
Accepted
| 29.46 |
f=lambda:list(map(int,input().split()))
n,st,sa=f()
st-=1
sa-=1
g=[[] for _ in range(n)]
for _ in range(n-1):
a,b=f()
g[a-1].append(b-1)
g[b-1].append(a-1)
def bfs(s):
l=[-1]*n; l[s]=0; q=[s]
while q:
v=q.pop(); d=l[v]+1
for c in g[v]:
if l[c]<0: l[c]=d; q+=[c]
return l
lt=bfs(st)
la=bfs(sa)
m=0
for i in range(n):
if lt[i]<la[i]: m=max(m,la[i])
print((m-1))
|
import sys
f=lambda:list(map(int,sys.stdin.readline().split()))
n,st,sa=f()
st-=1
sa-=1
g=[[] for _ in range(n)]
for _ in range(n-1):
a,b=f()
g[a-1].append(b-1)
g[b-1].append(a-1)
def bfs(s):
l=[-1]*n; l[s]=0; q=[s]
while q:
v=q.pop(); d=l[v]+1
for c in g[v]:
if l[c]<0: l[c]=d; q+=[c]
return l
lt=bfs(st)
la=bfs(sa)
m=0
for i in range(n):
if lt[i]<la[i]: m=max(m,la[i])
print((m-1))
| 22 | 23 | 400 | 425 |
f = lambda: list(map(int, input().split()))
n, st, sa = f()
st -= 1
sa -= 1
g = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = f()
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
def bfs(s):
l = [-1] * n
l[s] = 0
q = [s]
while q:
v = q.pop()
d = l[v] + 1
for c in g[v]:
if l[c] < 0:
l[c] = d
q += [c]
return l
lt = bfs(st)
la = bfs(sa)
m = 0
for i in range(n):
if lt[i] < la[i]:
m = max(m, la[i])
print((m - 1))
|
import sys
f = lambda: list(map(int, sys.stdin.readline().split()))
n, st, sa = f()
st -= 1
sa -= 1
g = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = f()
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
def bfs(s):
l = [-1] * n
l[s] = 0
q = [s]
while q:
v = q.pop()
d = l[v] + 1
for c in g[v]:
if l[c] < 0:
l[c] = d
q += [c]
return l
lt = bfs(st)
la = bfs(sa)
m = 0
for i in range(n):
if lt[i] < la[i]:
m = max(m, la[i])
print((m - 1))
| false | 4.347826 |
[
"-f = lambda: list(map(int, input().split()))",
"+import sys",
"+",
"+f = lambda: list(map(int, sys.stdin.readline().split()))"
] | false | 0.037078 | 0.036176 | 1.024943 |
[
"s260277829",
"s581884358"
] |
u729133443
|
p03644
|
python
|
s522591681
|
s237104114
| 169 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.94 |
print((2**(len(bin(int(eval(input()))))-3)))
|
print((2**len(bin(int(eval(input()))))>>3))
| 1 | 1 | 36 | 35 |
print((2 ** (len(bin(int(eval(input())))) - 3)))
|
print((2 ** len(bin(int(eval(input())))) >> 3))
| false | 0 |
[
"-print((2 ** (len(bin(int(eval(input())))) - 3)))",
"+print((2 ** len(bin(int(eval(input())))) >> 3))"
] | false | 0.034702 | 0.03592 | 0.966095 |
[
"s522591681",
"s237104114"
] |
u969850098
|
p03013
|
python
|
s370777768
|
s018712367
| 66 | 60 | 11,884 | 11,884 |
Accepted
|
Accepted
| 9.09 |
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
broken_floors = set(int(eval(input())) for _ in range(M))
dp = [0]*(N+2)
dp[1] = 1
for i in range(1, N+1):
if i not in broken_floors:
dp[i+1] = (dp[i] + dp[i-1]) % MOD
print((dp[-1]))
|
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
def main():
N, M = list(map(int, input().split()))
broken_floors = set(int(eval(input())) for _ in range(M))
dp = [0]*(N+2)
dp[1] = 1
for i in range(1, N+1):
if i not in broken_floors:
dp[i+1] = (dp[i] + dp[i-1]) % MOD
print((dp[-1]))
if __name__ == '__main__':
main()
| 14 | 18 | 290 | 377 |
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
broken_floors = set(int(eval(input())) for _ in range(M))
dp = [0] * (N + 2)
dp[1] = 1
for i in range(1, N + 1):
if i not in broken_floors:
dp[i + 1] = (dp[i] + dp[i - 1]) % MOD
print((dp[-1]))
|
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
def main():
N, M = list(map(int, input().split()))
broken_floors = set(int(eval(input())) for _ in range(M))
dp = [0] * (N + 2)
dp[1] = 1
for i in range(1, N + 1):
if i not in broken_floors:
dp[i + 1] = (dp[i] + dp[i - 1]) % MOD
print((dp[-1]))
if __name__ == "__main__":
main()
| false | 22.222222 |
[
"-N, M = list(map(int, input().split()))",
"-broken_floors = set(int(eval(input())) for _ in range(M))",
"-dp = [0] * (N + 2)",
"-dp[1] = 1",
"-for i in range(1, N + 1):",
"- if i not in broken_floors:",
"- dp[i + 1] = (dp[i] + dp[i - 1]) % MOD",
"-print((dp[-1]))",
"+",
"+",
"+def main():",
"+ N, M = list(map(int, input().split()))",
"+ broken_floors = set(int(eval(input())) for _ in range(M))",
"+ dp = [0] * (N + 2)",
"+ dp[1] = 1",
"+ for i in range(1, N + 1):",
"+ if i not in broken_floors:",
"+ dp[i + 1] = (dp[i] + dp[i - 1]) % MOD",
"+ print((dp[-1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.033496 | 0.033158 | 1.010219 |
[
"s370777768",
"s018712367"
] |
u948524308
|
p03241
|
python
|
s145139759
|
s984580168
| 414 | 20 | 3,060 | 3,060 |
Accepted
|
Accepted
| 95.17 |
N,M=list(map(int,input().split()))
if N==1:
print(M)
exit()
if N>=M**0.5:
for i in range(M//N,0,-1):
if M%i==0:
print(i)
exit()
else:
for i in range(N,M+1):
if M%i==0:
print((M//i))
exit()
print((1))
|
def div(N):
ans = []
for i in range(1, int(N ** 0.5) + 1):
if N % i == 0:
ans.append(i)
if N // i != i:
ans.append(N // i)
ans.sort()
return ans
N,M=list(map(int,input().split()))
if N==1:
print(M)
exit()
divM=div(M)
for i in range(1,len(divM)):
if divM[i]>M//N:
print((divM[i-1]))
exit()
| 16 | 23 | 285 | 400 |
N, M = list(map(int, input().split()))
if N == 1:
print(M)
exit()
if N >= M**0.5:
for i in range(M // N, 0, -1):
if M % i == 0:
print(i)
exit()
else:
for i in range(N, M + 1):
if M % i == 0:
print((M // i))
exit()
print((1))
|
def div(N):
ans = []
for i in range(1, int(N**0.5) + 1):
if N % i == 0:
ans.append(i)
if N // i != i:
ans.append(N // i)
ans.sort()
return ans
N, M = list(map(int, input().split()))
if N == 1:
print(M)
exit()
divM = div(M)
for i in range(1, len(divM)):
if divM[i] > M // N:
print((divM[i - 1]))
exit()
| false | 30.434783 |
[
"+def div(N):",
"+ ans = []",
"+ for i in range(1, int(N**0.5) + 1):",
"+ if N % i == 0:",
"+ ans.append(i)",
"+ if N // i != i:",
"+ ans.append(N // i)",
"+ ans.sort()",
"+ return ans",
"+",
"+",
"-if N >= M**0.5:",
"- for i in range(M // N, 0, -1):",
"- if M % i == 0:",
"- print(i)",
"- exit()",
"-else:",
"- for i in range(N, M + 1):",
"- if M % i == 0:",
"- print((M // i))",
"- exit()",
"-print((1))",
"+divM = div(M)",
"+for i in range(1, len(divM)):",
"+ if divM[i] > M // N:",
"+ print((divM[i - 1]))",
"+ exit()"
] | false | 0.085166 | 0.037867 | 2.249063 |
[
"s145139759",
"s984580168"
] |
u185249212
|
p03273
|
python
|
s892412058
|
s905409764
| 329 | 291 | 70,356 | 67,308 |
Accepted
|
Accepted
| 11.55 |
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
return
import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
def lcm(n,m):
return int(n*m/gcd(n,m))
import re
import array
import copy
import functools
import operator
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
def reduce(p, q):
common = fractions.gcd(p, q)
return (p//common , q//common )
# from itertools import accumulate
# from collections import deque
import random
def main():
H,W = list(map(int, input().strip().split())) # H行 W列
G=[]
for i_row in range(H):
G.append(input().strip())
eprint("graph G:")
eprint(G)
l_flag_row_all_dot_flag=[ 1 for _ in range(H) ]
for i_row in range(H):
for j_col in range(W):
if G[i_row][j_col]!=".":
l_flag_row_all_dot_flag[i_row]=0
l_flag_col_all_dot_flag=[ 1 for _ in range(W) ]
for j_col in range(W):
for i_row in range(H):
if G[i_row][j_col]!=".":
l_flag_col_all_dot_flag[j_col]=0
for i_row in range(H):
if l_flag_row_all_dot_flag[i_row]==1:
continue
for j_col in range(W):
if l_flag_col_all_dot_flag[j_col]==1:
continue
print(G[i_row][j_col],end="")
print()
# for i_row in range(H): # H is length of row
# if G[i_row] == str(["."* W ]):
# G.pop(i_row)
# all_dot_flag=1
# for j_col in range(W): # W は列の長さ
# for i_row in range(H): # H は行の長さ
# G[i_row][j_col] != "."
# failure_flag=0
# if all_dot_flag==1:
# for ii in range(H):
# G.pop()
return
if __name__ == '__main__':
main()
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
return
import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
def lcm(n,m):
return int(n*m/gcd(n,m))
import re
import array
import copy
import functools
import operator
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
def reduce(p, q):
common = fractions.gcd(p, q)
return (p//common , q//common )
# from itertools import accumulate
# from collections import deque
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, list(range(n, n - r, -1)), 1)
denom = reduce(mul, list(range(1, r + 1)), 1)
return numer // denom
import random
def main():
h,w = list(map(int, input().strip().split()))
g = [input().strip() for _ in range(h)]
gg = [col for col in zip(*g) if("#" in col)]
eprint("gg ",end=": \n")
eprint(gg)
for elem in gg:
eprint(elem)
gg = [row for row in zip(*gg) if("#" in row)]
eprint("gg ",end=": \n")
eprint(gg)
# for elem in gg:
# eprint(elem)
for S in gg:
print("".join(S))
return
if __name__ == '__main__':
main()
# trA = [list(col) for col in zip(*A)]
| 99 | 82 | 2,203 | 1,670 |
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
return
import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
def lcm(n, m):
return int(n * m / gcd(n, m))
import re
import array
import copy
import functools
import operator
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
def reduce(p, q):
common = fractions.gcd(p, q)
return (p // common, q // common)
# from itertools import accumulate
# from collections import deque
import random
def main():
H, W = list(map(int, input().strip().split())) # H行 W列
G = []
for i_row in range(H):
G.append(input().strip())
eprint("graph G:")
eprint(G)
l_flag_row_all_dot_flag = [1 for _ in range(H)]
for i_row in range(H):
for j_col in range(W):
if G[i_row][j_col] != ".":
l_flag_row_all_dot_flag[i_row] = 0
l_flag_col_all_dot_flag = [1 for _ in range(W)]
for j_col in range(W):
for i_row in range(H):
if G[i_row][j_col] != ".":
l_flag_col_all_dot_flag[j_col] = 0
for i_row in range(H):
if l_flag_row_all_dot_flag[i_row] == 1:
continue
for j_col in range(W):
if l_flag_col_all_dot_flag[j_col] == 1:
continue
print(G[i_row][j_col], end="")
print()
# for i_row in range(H): # H is length of row
# if G[i_row] == str(["."* W ]):
# G.pop(i_row)
# all_dot_flag=1
# for j_col in range(W): # W は列の長さ
# for i_row in range(H): # H は行の長さ
# G[i_row][j_col] != "."
# failure_flag=0
# if all_dot_flag==1:
# for ii in range(H):
# G.pop()
return
if __name__ == "__main__":
main()
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
return
import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
def lcm(n, m):
return int(n * m / gcd(n, m))
import re
import array
import copy
import functools
import operator
import collections
import itertools
import bisect
import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
def reduce(p, q):
common = fractions.gcd(p, q)
return (p // common, q // common)
# from itertools import accumulate
# from collections import deque
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, list(range(n, n - r, -1)), 1)
denom = reduce(mul, list(range(1, r + 1)), 1)
return numer // denom
import random
def main():
h, w = list(map(int, input().strip().split()))
g = [input().strip() for _ in range(h)]
gg = [col for col in zip(*g) if ("#" in col)]
eprint("gg ", end=": \n")
eprint(gg)
for elem in gg:
eprint(elem)
gg = [row for row in zip(*gg) if ("#" in row)]
eprint("gg ", end=": \n")
eprint(gg)
# for elem in gg:
# eprint(elem)
for S in gg:
print("".join(S))
return
if __name__ == "__main__":
main()
# trA = [list(col) for col in zip(*A)]
| false | 17.171717 |
[
"+from operator import mul",
"+from functools import reduce",
"+",
"+",
"+def combinations_count(n, r):",
"+ r = min(r, n - r)",
"+ numer = reduce(mul, list(range(n, n - r, -1)), 1)",
"+ denom = reduce(mul, list(range(1, r + 1)), 1)",
"+ return numer // denom",
"+",
"+",
"- H, W = list(map(int, input().strip().split())) # H行 W列",
"- G = []",
"- for i_row in range(H):",
"- G.append(input().strip())",
"- eprint(\"graph G:\")",
"- eprint(G)",
"- l_flag_row_all_dot_flag = [1 for _ in range(H)]",
"- for i_row in range(H):",
"- for j_col in range(W):",
"- if G[i_row][j_col] != \".\":",
"- l_flag_row_all_dot_flag[i_row] = 0",
"- l_flag_col_all_dot_flag = [1 for _ in range(W)]",
"- for j_col in range(W):",
"- for i_row in range(H):",
"- if G[i_row][j_col] != \".\":",
"- l_flag_col_all_dot_flag[j_col] = 0",
"- for i_row in range(H):",
"- if l_flag_row_all_dot_flag[i_row] == 1:",
"- continue",
"- for j_col in range(W):",
"- if l_flag_col_all_dot_flag[j_col] == 1:",
"- continue",
"- print(G[i_row][j_col], end=\"\")",
"- print()",
"- # for i_row in range(H): # H is length of row",
"- # if G[i_row] == str([\".\"* W ]):",
"- # G.pop(i_row)",
"- # all_dot_flag=1",
"- # for j_col in range(W): # W は列の長さ",
"- # for i_row in range(H): # H は行の長さ",
"- # G[i_row][j_col] != \".\"",
"- # failure_flag=0",
"- # if all_dot_flag==1:",
"- # for ii in range(H):",
"- # G.pop()",
"+ h, w = list(map(int, input().strip().split()))",
"+ g = [input().strip() for _ in range(h)]",
"+ gg = [col for col in zip(*g) if (\"#\" in col)]",
"+ eprint(\"gg \", end=\": \\n\")",
"+ eprint(gg)",
"+ for elem in gg:",
"+ eprint(elem)",
"+ gg = [row for row in zip(*gg) if (\"#\" in row)]",
"+ eprint(\"gg \", end=\": \\n\")",
"+ eprint(gg)",
"+ # for elem in gg:",
"+ # eprint(elem)",
"+ for S in gg:",
"+ print(\"\".join(S))",
"+# trA = [list(col) for col in zip(*A)]"
] | false | 0.044311 | 0.078961 | 0.561177 |
[
"s892412058",
"s905409764"
] |
u377989038
|
p03013
|
python
|
s037041247
|
s455057721
| 189 | 68 | 7,824 | 7,836 |
Accepted
|
Accepted
| 64.02 |
n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)] + [0]
mod = 10 ** 9 + 7
dp = [0] * (n + 1)
dp[0] = 1
b = a[0]
j = 1
for i in range(1, n + 1):
if i == b:
b = a[j]
j += 1
else:
tmp = dp[i - 2] + dp[i - 1]
if tmp >= mod:
tmp -= mod
dp[i] = tmp
print((int(dp[-1])))
|
import sys
input = sys.stdin.buffer.readline
n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)] + [0]
mod = 10 ** 9 + 7
dp = [0] * (n + 1)
dp[0] = 1
b = a[0]
j = 1
for i in range(1, n + 1):
if i == b:
b = a[j]
j += 1
else:
tmp = dp[i - 2] + dp[i - 1]
if tmp >= mod:
tmp -= mod
dp[i] = tmp
print((int(dp[-1])))
| 18 | 21 | 359 | 408 |
n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)] + [0]
mod = 10**9 + 7
dp = [0] * (n + 1)
dp[0] = 1
b = a[0]
j = 1
for i in range(1, n + 1):
if i == b:
b = a[j]
j += 1
else:
tmp = dp[i - 2] + dp[i - 1]
if tmp >= mod:
tmp -= mod
dp[i] = tmp
print((int(dp[-1])))
|
import sys
input = sys.stdin.buffer.readline
n, m = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(m)] + [0]
mod = 10**9 + 7
dp = [0] * (n + 1)
dp[0] = 1
b = a[0]
j = 1
for i in range(1, n + 1):
if i == b:
b = a[j]
j += 1
else:
tmp = dp[i - 2] + dp[i - 1]
if tmp >= mod:
tmp -= mod
dp[i] = tmp
print((int(dp[-1])))
| false | 14.285714 |
[
"+import sys",
"+",
"+input = sys.stdin.buffer.readline"
] | false | 0.140911 | 0.13889 | 1.014549 |
[
"s037041247",
"s455057721"
] |
u729133443
|
p03086
|
python
|
s599116034
|
s780520490
| 163 | 19 | 38,768 | 3,188 |
Accepted
|
Accepted
| 88.34 |
import re;print((max(list(map(len,re.findall('[ATGC]*',eval(input())))))))
|
import re;print((max(list(map(len,re.split('[^ACGT]',eval(input())))))))
| 1 | 1 | 60 | 58 |
import re
print((max(list(map(len, re.findall("[ATGC]*", eval(input())))))))
|
import re
print((max(list(map(len, re.split("[^ACGT]", eval(input())))))))
| false | 0 |
[
"-print((max(list(map(len, re.findall(\"[ATGC]*\", eval(input())))))))",
"+print((max(list(map(len, re.split(\"[^ACGT]\", eval(input())))))))"
] | false | 0.158477 | 0.084884 | 1.866992 |
[
"s599116034",
"s780520490"
] |
u144913062
|
p02892
|
python
|
s516036523
|
s119446368
| 351 | 239 | 54,236 | 16,956 |
Accepted
|
Accepted
| 31.91 |
def b(u,x):
c[u]=x
return all((c[u]!=c[v])&(c[v]or b(v,-x))for v in X if d[u][v]==1)
N=int(eval(input()))
X=list(range(N))
S=[eval(input())for _ in X]
d=[[1 if S[i][j]=='1'else(N if i^j else 0)for j in X]for i in X]
for k in X:
for i in X:
for j in X:d[i][j]=min(d[i][j],d[i][k]+d[k][j])
c=[0]*N
print((max(max(e)for e in d)+1 if b(0,1)else-1))
|
import scipy.sparse.csgraph as s
def b(u,x):c[u]=x;return all(d[u][v]^1or(c[u]!=c[v])&(c[v]or b(v,-x))for v in X)
N,*S=open(0)
N=int(N)
X=list(range(N))
d=[[i^j and(S[i][j]=='1'or N)for j in X]for i in X]
c=[0]*N
print((int(b(0,1)and s.floyd_warshall(d).max()+2)-1))
| 12 | 8 | 340 | 266 |
def b(u, x):
c[u] = x
return all((c[u] != c[v]) & (c[v] or b(v, -x)) for v in X if d[u][v] == 1)
N = int(eval(input()))
X = list(range(N))
S = [eval(input()) for _ in X]
d = [[1 if S[i][j] == "1" else (N if i ^ j else 0) for j in X] for i in X]
for k in X:
for i in X:
for j in X:
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
c = [0] * N
print((max(max(e) for e in d) + 1 if b(0, 1) else -1))
|
import scipy.sparse.csgraph as s
def b(u, x):
c[u] = x
return all(d[u][v] ^ 1 or (c[u] != c[v]) & (c[v] or b(v, -x)) for v in X)
N, *S = open(0)
N = int(N)
X = list(range(N))
d = [[i ^ j and (S[i][j] == "1" or N) for j in X] for i in X]
c = [0] * N
print((int(b(0, 1) and s.floyd_warshall(d).max() + 2) - 1))
| false | 33.333333 |
[
"+import scipy.sparse.csgraph as s",
"+",
"+",
"- return all((c[u] != c[v]) & (c[v] or b(v, -x)) for v in X if d[u][v] == 1)",
"+ return all(d[u][v] ^ 1 or (c[u] != c[v]) & (c[v] or b(v, -x)) for v in X)",
"-N = int(eval(input()))",
"+N, *S = open(0)",
"+N = int(N)",
"-S = [eval(input()) for _ in X]",
"-d = [[1 if S[i][j] == \"1\" else (N if i ^ j else 0) for j in X] for i in X]",
"-for k in X:",
"- for i in X:",
"- for j in X:",
"- d[i][j] = min(d[i][j], d[i][k] + d[k][j])",
"+d = [[i ^ j and (S[i][j] == \"1\" or N) for j in X] for i in X]",
"-print((max(max(e) for e in d) + 1 if b(0, 1) else -1))",
"+print((int(b(0, 1) and s.floyd_warshall(d).max() + 2) - 1))"
] | false | 0.105823 | 0.599472 | 0.176527 |
[
"s516036523",
"s119446368"
] |
u952708174
|
p03325
|
python
|
s602466660
|
s121346714
| 61 | 24 | 4,404 | 4,148 |
Accepted
|
Accepted
| 60.66 |
def c_time3_or_div2(N, A):
ans = 0 # Aの各要素の因数2の個数の和
for a in A:
while a % 2 == 0:
ans += 1
a //= 2
return ans
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_time3_or_div2(N, A)))
|
def c_time3_or_div2(N, A):
# Aの各要素aにおける因数2の個数の和
# aを2進数として下位ビットから見て、最初に1が現れた桁数が因数2の個数
return sum((bin(a)[::-1].index('1') for a in A))
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_time3_or_div2(N, A)))
| 11 | 8 | 249 | 238 |
def c_time3_or_div2(N, A):
ans = 0 # Aの各要素の因数2の個数の和
for a in A:
while a % 2 == 0:
ans += 1
a //= 2
return ans
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_time3_or_div2(N, A)))
|
def c_time3_or_div2(N, A):
# Aの各要素aにおける因数2の個数の和
# aを2進数として下位ビットから見て、最初に1が現れた桁数が因数2の個数
return sum((bin(a)[::-1].index("1") for a in A))
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_time3_or_div2(N, A)))
| false | 27.272727 |
[
"- ans = 0 # Aの各要素の因数2の個数の和",
"- for a in A:",
"- while a % 2 == 0:",
"- ans += 1",
"- a //= 2",
"- return ans",
"+ # Aの各要素aにおける因数2の個数の和",
"+ # aを2進数として下位ビットから見て、最初に1が現れた桁数が因数2の個数",
"+ return sum((bin(a)[::-1].index(\"1\") for a in A))"
] | false | 0.07026 | 0.036615 | 1.91887 |
[
"s602466660",
"s121346714"
] |
u864197622
|
p02563
|
python
|
s692457859
|
s539610906
| 1,311 | 943 | 203,256 | 196,740 |
Accepted
|
Accepted
| 28.07 |
p, g = 998244353, 3
invg = pow(g, p-2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k)[::-1]:
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2*d):
f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
u = u * W[l+1] % p
def ifft(k, f):
for l in range(k):
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2*d):
f[j+d] *= u
f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
u = u * iW[l+1] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length()
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
return a[:n0]
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
|
p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k, 0, -1):
d = 1 << l - 1
for i in range(1 << k - l):
u = 1
for j in range(i * 2 * d, (i * 2 + 1) * d):
f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
u = u * W[l] % p
def ifft(k, f):
for l in range(1, k + 1):
d = 1 << l - 1
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j+d] *= u
f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
u = u * iW[l] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length()
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
del a[n0:]
return a
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
| 43 | 43 | 1,199 | 1,243 |
p, g = 998244353, 3
invg = pow(g, p - 2, p)
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k)[::-1]:
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j], f[j + d] = (f[j] + f[j + d]) % p, u * (f[j] - f[j + d]) % p
u = u * W[l + 1] % p
def ifft(k, f):
for l in range(k):
d = 1 << l
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j + d] *= u
f[j], f[j + d] = (f[j] + f[j + d]) % p, (f[j] - f[j + d]) % p
u = u * iW[l + 1] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length()
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
return a[:n0]
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
|
p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]
def fft(k, f):
for l in range(k, 0, -1):
d = 1 << l - 1
for i in range(1 << k - l):
u = 1
for j in range(i * 2 * d, (i * 2 + 1) * d):
f[j], f[j + d] = (f[j] + f[j + d]) % p, u * (f[j] - f[j + d]) % p
u = u * W[l] % p
def ifft(k, f):
for l in range(1, k + 1):
d = 1 << l - 1
u = 1
for i in range(d):
for j in range(i, 1 << k, 2 * d):
f[j + d] *= u
f[j], f[j + d] = (f[j] + f[j + d]) % p, (f[j] - f[j + d]) % p
u = u * iW[l] % p
def convolve(a, b):
n0 = len(a) + len(b) - 1
k = (n0).bit_length()
n = 1 << k
a = a + [0] * (n - len(a))
b = b + [0] * (n - len(b))
fft(k, a), fft(k, b)
for i in range(n):
a[i] = a[i] * b[i] % p
ifft(k, a)
invn = pow(n, p - 2, p)
for i in range(n0):
a[i] = a[i] * invn % p
del a[n0:]
return a
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print((*convolve(A, B)))
| false | 0 |
[
"-p, g = 998244353, 3",
"-invg = pow(g, p - 2, p)",
"+p, g, ig = 998244353, 3, 332748118",
"-iW = [pow(invg, (p - 1) >> i, p) for i in range(24)]",
"+iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]",
"- for l in range(k)[::-1]:",
"- d = 1 << l",
"- u = 1",
"- for i in range(d):",
"- for j in range(i, 1 << k, 2 * d):",
"+ for l in range(k, 0, -1):",
"+ d = 1 << l - 1",
"+ for i in range(1 << k - l):",
"+ u = 1",
"+ for j in range(i * 2 * d, (i * 2 + 1) * d):",
"- u = u * W[l + 1] % p",
"+ u = u * W[l] % p",
"- for l in range(k):",
"- d = 1 << l",
"+ for l in range(1, k + 1):",
"+ d = 1 << l - 1",
"- u = u * iW[l + 1] % p",
"+ u = u * iW[l] % p",
"- return a[:n0]",
"+ del a[n0:]",
"+ return a"
] | false | 0.03946 | 0.044888 | 0.879065 |
[
"s692457859",
"s539610906"
] |
u987164499
|
p02720
|
python
|
s621452038
|
s256046797
| 191 | 105 | 11,628 | 18,884 |
Accepted
|
Accepted
| 45.03 |
from sys import stdin,setrecursionlimit
k = int(stdin.readline().rstrip())
li = [i for i in range(1,10)]
#ルンルン最初の数
def runrun(before,kazu):
if before == 0:
li.append(int(kazu+str(before+1)))
li.append(int(kazu+str(before)))
elif before == 9:
li.append(int(kazu+str(before-1)))
li.append(int(kazu+str(before)))
else:
li.append(int(kazu+str(before+1)))
li.append(int(kazu+str(before-1)))
li.append(int(kazu+str(before)))
if len(kazu)+1 >= 10:
return
else:
if before == 0:
return runrun(before+1,kazu+str(before+1)),runrun(before,kazu+str(before))
elif before == 9:
return runrun(before-1,kazu+str(before-1)),runrun(before,kazu+str(before))
else:
return runrun(before+1,kazu+str(before+1)),runrun(before-1,kazu+str(before-1)),runrun(before,kazu+str(before))
for i in range(1,10):
runrun(i,str(i))
li.sort()
print((li[k-1]))
|
from queue import deque
k = int(eval(input()))
que = deque()
for i in range(1,10):
que.append(i)
for i in range(k):
if i == (k-1):
print((que.popleft()))
exit()
now = que.popleft()
if now%10 != 0:
que.append(now*10+now%10-1)
que.append(now*10+now%10)
if now%10 != 9:
que.append(now*10+now%10+1)
| 28 | 17 | 993 | 360 |
from sys import stdin, setrecursionlimit
k = int(stdin.readline().rstrip())
li = [i for i in range(1, 10)]
# ルンルン最初の数
def runrun(before, kazu):
if before == 0:
li.append(int(kazu + str(before + 1)))
li.append(int(kazu + str(before)))
elif before == 9:
li.append(int(kazu + str(before - 1)))
li.append(int(kazu + str(before)))
else:
li.append(int(kazu + str(before + 1)))
li.append(int(kazu + str(before - 1)))
li.append(int(kazu + str(before)))
if len(kazu) + 1 >= 10:
return
else:
if before == 0:
return runrun(before + 1, kazu + str(before + 1)), runrun(
before, kazu + str(before)
)
elif before == 9:
return runrun(before - 1, kazu + str(before - 1)), runrun(
before, kazu + str(before)
)
else:
return (
runrun(before + 1, kazu + str(before + 1)),
runrun(before - 1, kazu + str(before - 1)),
runrun(before, kazu + str(before)),
)
for i in range(1, 10):
runrun(i, str(i))
li.sort()
print((li[k - 1]))
|
from queue import deque
k = int(eval(input()))
que = deque()
for i in range(1, 10):
que.append(i)
for i in range(k):
if i == (k - 1):
print((que.popleft()))
exit()
now = que.popleft()
if now % 10 != 0:
que.append(now * 10 + now % 10 - 1)
que.append(now * 10 + now % 10)
if now % 10 != 9:
que.append(now * 10 + now % 10 + 1)
| false | 39.285714 |
[
"-from sys import stdin, setrecursionlimit",
"+from queue import deque",
"-k = int(stdin.readline().rstrip())",
"-li = [i for i in range(1, 10)]",
"-# ルンルン最初の数",
"-def runrun(before, kazu):",
"- if before == 0:",
"- li.append(int(kazu + str(before + 1)))",
"- li.append(int(kazu + str(before)))",
"- elif before == 9:",
"- li.append(int(kazu + str(before - 1)))",
"- li.append(int(kazu + str(before)))",
"- else:",
"- li.append(int(kazu + str(before + 1)))",
"- li.append(int(kazu + str(before - 1)))",
"- li.append(int(kazu + str(before)))",
"- if len(kazu) + 1 >= 10:",
"- return",
"- else:",
"- if before == 0:",
"- return runrun(before + 1, kazu + str(before + 1)), runrun(",
"- before, kazu + str(before)",
"- )",
"- elif before == 9:",
"- return runrun(before - 1, kazu + str(before - 1)), runrun(",
"- before, kazu + str(before)",
"- )",
"- else:",
"- return (",
"- runrun(before + 1, kazu + str(before + 1)),",
"- runrun(before - 1, kazu + str(before - 1)),",
"- runrun(before, kazu + str(before)),",
"- )",
"-",
"-",
"+k = int(eval(input()))",
"+que = deque()",
"- runrun(i, str(i))",
"-li.sort()",
"-print((li[k - 1]))",
"+ que.append(i)",
"+for i in range(k):",
"+ if i == (k - 1):",
"+ print((que.popleft()))",
"+ exit()",
"+ now = que.popleft()",
"+ if now % 10 != 0:",
"+ que.append(now * 10 + now % 10 - 1)",
"+ que.append(now * 10 + now % 10)",
"+ if now % 10 != 9:",
"+ que.append(now * 10 + now % 10 + 1)"
] | false | 0.488377 | 0.118076 | 4.136133 |
[
"s621452038",
"s256046797"
] |
u858748695
|
p03007
|
python
|
s464667212
|
s743558658
| 224 | 203 | 14,092 | 25,040 |
Accepted
|
Accepted
| 9.38 |
#!/usr/bin/env python3
import bisect
n = int(eval(input()))
a = sorted(map(int, input().split()))
if n == 2:
print((a[1] - a[0]))
print((a[1], a[0]))
exit()
p = bisect.bisect_left(a, 0)
p = min(max(1, p), n - 1)
print((sum(a[p:]) - sum(a[:p])))
b = a[p - 1]
for i in range(p, n - 1):
print((b, a[i]))
b -= a[i]
c = a[n - 1]
for i in range(p - 1):
print((c, a[i]))
c -= a[i]
print((c, b))
|
n = int(eval(input()))
a = sorted(map(int, input().split()))
ans = []
for i in range(1, n - 1):
# +
if a[i] < 0:
ans.append([a[-1], a[i]])
a[-1] -= a[i]
# -
else:
ans.append([a[0], a[i]])
a[0] -= a[i]
ans.append([a[-1], a[0]])
print((a[-1] - a[0]))
for x, y in ans:
print((x, y))
| 21 | 16 | 419 | 337 |
#!/usr/bin/env python3
import bisect
n = int(eval(input()))
a = sorted(map(int, input().split()))
if n == 2:
print((a[1] - a[0]))
print((a[1], a[0]))
exit()
p = bisect.bisect_left(a, 0)
p = min(max(1, p), n - 1)
print((sum(a[p:]) - sum(a[:p])))
b = a[p - 1]
for i in range(p, n - 1):
print((b, a[i]))
b -= a[i]
c = a[n - 1]
for i in range(p - 1):
print((c, a[i]))
c -= a[i]
print((c, b))
|
n = int(eval(input()))
a = sorted(map(int, input().split()))
ans = []
for i in range(1, n - 1):
# +
if a[i] < 0:
ans.append([a[-1], a[i]])
a[-1] -= a[i]
# -
else:
ans.append([a[0], a[i]])
a[0] -= a[i]
ans.append([a[-1], a[0]])
print((a[-1] - a[0]))
for x, y in ans:
print((x, y))
| false | 23.809524 |
[
"-#!/usr/bin/env python3",
"-import bisect",
"-",
"-if n == 2:",
"- print((a[1] - a[0]))",
"- print((a[1], a[0]))",
"- exit()",
"-p = bisect.bisect_left(a, 0)",
"-p = min(max(1, p), n - 1)",
"-print((sum(a[p:]) - sum(a[:p])))",
"-b = a[p - 1]",
"-for i in range(p, n - 1):",
"- print((b, a[i]))",
"- b -= a[i]",
"-c = a[n - 1]",
"-for i in range(p - 1):",
"- print((c, a[i]))",
"- c -= a[i]",
"-print((c, b))",
"+ans = []",
"+for i in range(1, n - 1):",
"+ # +",
"+ if a[i] < 0:",
"+ ans.append([a[-1], a[i]])",
"+ a[-1] -= a[i]",
"+ # -",
"+ else:",
"+ ans.append([a[0], a[i]])",
"+ a[0] -= a[i]",
"+ans.append([a[-1], a[0]])",
"+print((a[-1] - a[0]))",
"+for x, y in ans:",
"+ print((x, y))"
] | false | 0.036901 | 0.033073 | 1.115735 |
[
"s464667212",
"s743558658"
] |
u968166680
|
p02861
|
python
|
s099518222
|
s387031146
| 108 | 70 | 3,064 | 3,188 |
Accepted
|
Accepted
| 35.19 |
from itertools import permutations
from math import factorial
N = int(eval(input()))
cities = [tuple(map(int, input().split())) for _ in range(N)]
dists = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
dists[i][j] = dists[j][i] = (
(cities[j][0] - cities[i][0]) ** 2 + (cities[j][1] - cities[i][1]) ** 2
) ** 0.5
total_dist = 0
for p in permutations(list(range(N))):
for i in range(N - 1):
total_dist += dists[p[i]][p[i + 1]]
print((total_dist / factorial(N)))
|
import sys
from itertools import permutations
from math import factorial
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def distance(p, q):
return sum((px - qx) ** 2.0 for px, qx in zip(p, q)) ** 0.5
def main():
N = int(readline())
C = [tuple(map(int, readline().split())) for _ in range(N)]
dist = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
dist[i][j] = dist[j][i] = distance(C[i], C[j])
ans = 0
for perm in permutations(list(range(N))):
for i in range(N - 1):
ans += dist[perm[i]][perm[i + 1]]
print((ans / factorial(N)))
return
if __name__ == '__main__':
main()
| 19 | 35 | 539 | 793 |
from itertools import permutations
from math import factorial
N = int(eval(input()))
cities = [tuple(map(int, input().split())) for _ in range(N)]
dists = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
dists[i][j] = dists[j][i] = (
(cities[j][0] - cities[i][0]) ** 2 + (cities[j][1] - cities[i][1]) ** 2
) ** 0.5
total_dist = 0
for p in permutations(list(range(N))):
for i in range(N - 1):
total_dist += dists[p[i]][p[i + 1]]
print((total_dist / factorial(N)))
|
import sys
from itertools import permutations
from math import factorial
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def distance(p, q):
return sum((px - qx) ** 2.0 for px, qx in zip(p, q)) ** 0.5
def main():
N = int(readline())
C = [tuple(map(int, readline().split())) for _ in range(N)]
dist = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
dist[i][j] = dist[j][i] = distance(C[i], C[j])
ans = 0
for perm in permutations(list(range(N))):
for i in range(N - 1):
ans += dist[perm[i]][perm[i + 1]]
print((ans / factorial(N)))
return
if __name__ == "__main__":
main()
| false | 45.714286 |
[
"+import sys",
"-N = int(eval(input()))",
"-cities = [tuple(map(int, input().split())) for _ in range(N)]",
"-dists = [[0] * N for _ in range(N)]",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- dists[i][j] = dists[j][i] = (",
"- (cities[j][0] - cities[i][0]) ** 2 + (cities[j][1] - cities[i][1]) ** 2",
"- ) ** 0.5",
"-total_dist = 0",
"-for p in permutations(list(range(N))):",
"- for i in range(N - 1):",
"- total_dist += dists[p[i]][p[i + 1]]",
"-print((total_dist / factorial(N)))",
"+read = sys.stdin.read",
"+readline = sys.stdin.readline",
"+readlines = sys.stdin.readlines",
"+sys.setrecursionlimit(10**9)",
"+INF = 1 << 60",
"+",
"+",
"+def distance(p, q):",
"+ return sum((px - qx) ** 2.0 for px, qx in zip(p, q)) ** 0.5",
"+",
"+",
"+def main():",
"+ N = int(readline())",
"+ C = [tuple(map(int, readline().split())) for _ in range(N)]",
"+ dist = [[0] * N for _ in range(N)]",
"+ for i in range(N):",
"+ for j in range(i + 1, N):",
"+ dist[i][j] = dist[j][i] = distance(C[i], C[j])",
"+ ans = 0",
"+ for perm in permutations(list(range(N))):",
"+ for i in range(N - 1):",
"+ ans += dist[perm[i]][perm[i + 1]]",
"+ print((ans / factorial(N)))",
"+ return",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.039365 | 0.040503 | 0.971891 |
[
"s099518222",
"s387031146"
] |
u562935282
|
p02863
|
python
|
s009814554
|
s138518626
| 722 | 565 | 179,208 | 46,960 |
Accepted
|
Accepted
| 21.75 |
def solve():
from collections import namedtuple
import sys
input = sys.stdin.readline
Dish = namedtuple('Dish', 'idx cost pt')
n, t = list(map(int, input().split()))
dishes = []
for idx in range(1, n + 1):
cost, pt = list(map(int, input().split()))
dishes.append(Dish(idx=idx, cost=cost, pt=pt))
dp_ht = [[0] * t for _ in range(n + 2)] # head->tail
dp_th = [[0] * t for _ in range(n + 2)] # tail->head
# dp[注文可能な範囲の端][完食にかかる総時間]:= 美味しさの最大値
for dish in dishes:
for cost_ in range(t):
if cost_ >= dish.cost:
dp_ht[dish.idx][cost_] = max(dp_ht[dish.idx - 1][cost_],
dp_ht[dish.idx - 1][cost_ - dish.cost] + dish.pt)
else:
dp_ht[dish.idx][cost_] = dp_ht[dish.idx - 1][cost_]
for dish in reversed(dishes):
for cost_ in range(t):
if cost_ >= dish.cost:
dp_th[dish.idx][cost_] = max(dp_th[dish.idx + 1][cost_],
dp_th[dish.idx + 1][cost_ - dish.cost] + dish.pt)
else:
dp_th[dish.idx][cost_] = dp_th[dish.idx + 1][cost_]
ret = 0
for last_dish in dishes:
for cost_ in range(t):
ret = max(ret, dp_ht[last_dish.idx - 1][cost_] + dp_th[last_dish.idx + 1][t - 1 - cost_] + last_dish.pt)
return ret
print((solve()))
|
def solve():
from collections import namedtuple
import sys
input = sys.stdin.readline
Dish = namedtuple('Dish', 'idx cost pt')
n, t = list(map(int, input().split()))
dishes = []
for idx in range(1, n + 1):
cost, pt = list(map(int, input().split()))
dishes.append(Dish(idx=idx, cost=cost, pt=pt))
dp = [[0] * 2 for _ in range(t)]
# dp[完食にかかる総時間][最後の皿を選んだか]:= 美味しさの最大値
for dish in dishes:
for cost_ in range(t - 1, -1, -1):
dp[cost_][True] = max(dp[cost_][True], dp[cost_][False] + dish.pt)
if cost_ >= dish.cost:
dp[cost_][False] = max(dp[cost_][False], dp[cost_ - dish.cost][False] + dish.pt)
dp[cost_][True] = max(dp[cost_][True], dp[cost_ - dish.cost][True] + dish.pt)
return max(dp[cost_][True] for cost_ in range(t))
print((solve()))
# 最後の皿を選んだかフラグを設ける
# https://sen-comp.hatenablog.com/entry/2019/11/17/003150
| 41 | 30 | 1,451 | 962 |
def solve():
from collections import namedtuple
import sys
input = sys.stdin.readline
Dish = namedtuple("Dish", "idx cost pt")
n, t = list(map(int, input().split()))
dishes = []
for idx in range(1, n + 1):
cost, pt = list(map(int, input().split()))
dishes.append(Dish(idx=idx, cost=cost, pt=pt))
dp_ht = [[0] * t for _ in range(n + 2)] # head->tail
dp_th = [[0] * t for _ in range(n + 2)] # tail->head
# dp[注文可能な範囲の端][完食にかかる総時間]:= 美味しさの最大値
for dish in dishes:
for cost_ in range(t):
if cost_ >= dish.cost:
dp_ht[dish.idx][cost_] = max(
dp_ht[dish.idx - 1][cost_],
dp_ht[dish.idx - 1][cost_ - dish.cost] + dish.pt,
)
else:
dp_ht[dish.idx][cost_] = dp_ht[dish.idx - 1][cost_]
for dish in reversed(dishes):
for cost_ in range(t):
if cost_ >= dish.cost:
dp_th[dish.idx][cost_] = max(
dp_th[dish.idx + 1][cost_],
dp_th[dish.idx + 1][cost_ - dish.cost] + dish.pt,
)
else:
dp_th[dish.idx][cost_] = dp_th[dish.idx + 1][cost_]
ret = 0
for last_dish in dishes:
for cost_ in range(t):
ret = max(
ret,
dp_ht[last_dish.idx - 1][cost_]
+ dp_th[last_dish.idx + 1][t - 1 - cost_]
+ last_dish.pt,
)
return ret
print((solve()))
|
def solve():
from collections import namedtuple
import sys
input = sys.stdin.readline
Dish = namedtuple("Dish", "idx cost pt")
n, t = list(map(int, input().split()))
dishes = []
for idx in range(1, n + 1):
cost, pt = list(map(int, input().split()))
dishes.append(Dish(idx=idx, cost=cost, pt=pt))
dp = [[0] * 2 for _ in range(t)]
# dp[完食にかかる総時間][最後の皿を選んだか]:= 美味しさの最大値
for dish in dishes:
for cost_ in range(t - 1, -1, -1):
dp[cost_][True] = max(dp[cost_][True], dp[cost_][False] + dish.pt)
if cost_ >= dish.cost:
dp[cost_][False] = max(
dp[cost_][False], dp[cost_ - dish.cost][False] + dish.pt
)
dp[cost_][True] = max(
dp[cost_][True], dp[cost_ - dish.cost][True] + dish.pt
)
return max(dp[cost_][True] for cost_ in range(t))
print((solve()))
# 最後の皿を選んだかフラグを設ける
# https://sen-comp.hatenablog.com/entry/2019/11/17/003150
| false | 26.829268 |
[
"- dp_ht = [[0] * t for _ in range(n + 2)] # head->tail",
"- dp_th = [[0] * t for _ in range(n + 2)] # tail->head",
"- # dp[注文可能な範囲の端][完食にかかる総時間]:= 美味しさの最大値",
"+ dp = [[0] * 2 for _ in range(t)]",
"+ # dp[完食にかかる総時間][最後の皿を選んだか]:= 美味しさの最大値",
"- for cost_ in range(t):",
"+ for cost_ in range(t - 1, -1, -1):",
"+ dp[cost_][True] = max(dp[cost_][True], dp[cost_][False] + dish.pt)",
"- dp_ht[dish.idx][cost_] = max(",
"- dp_ht[dish.idx - 1][cost_],",
"- dp_ht[dish.idx - 1][cost_ - dish.cost] + dish.pt,",
"+ dp[cost_][False] = max(",
"+ dp[cost_][False], dp[cost_ - dish.cost][False] + dish.pt",
"- else:",
"- dp_ht[dish.idx][cost_] = dp_ht[dish.idx - 1][cost_]",
"- for dish in reversed(dishes):",
"- for cost_ in range(t):",
"- if cost_ >= dish.cost:",
"- dp_th[dish.idx][cost_] = max(",
"- dp_th[dish.idx + 1][cost_],",
"- dp_th[dish.idx + 1][cost_ - dish.cost] + dish.pt,",
"+ dp[cost_][True] = max(",
"+ dp[cost_][True], dp[cost_ - dish.cost][True] + dish.pt",
"- else:",
"- dp_th[dish.idx][cost_] = dp_th[dish.idx + 1][cost_]",
"- ret = 0",
"- for last_dish in dishes:",
"- for cost_ in range(t):",
"- ret = max(",
"- ret,",
"- dp_ht[last_dish.idx - 1][cost_]",
"- + dp_th[last_dish.idx + 1][t - 1 - cost_]",
"- + last_dish.pt,",
"- )",
"- return ret",
"+ return max(dp[cost_][True] for cost_ in range(t))",
"+# 最後の皿を選んだかフラグを設ける",
"+# https://sen-comp.hatenablog.com/entry/2019/11/17/003150"
] | false | 0.18281 | 0.038842 | 4.706459 |
[
"s009814554",
"s138518626"
] |
u915355756
|
p03073
|
python
|
s224247208
|
s640440607
| 314 | 47 | 21,380 | 3,188 |
Accepted
|
Accepted
| 85.03 |
import numpy as np
#input
S = str(eval(input()))
ans = 0
for i in range(len(S)):
if i % 2 == 0:
if S[i] == "1":
ans += 1
else:
if S[i] == "0":
ans += 1
print((min(ans,len(S)-ans)))
|
#input
#N = list(map(int,input().split()))
#H = list(map(int,input().split()))
S = str(eval(input()))
ans = 0
for i in range(len(S)):
if i % 2 == 0:
if S[i] == "1":
ans += 1
else:
if S[i] == "0":
ans+= 1
print((min(ans,len(S)-ans)))
| 12 | 14 | 231 | 286 |
import numpy as np
# input
S = str(eval(input()))
ans = 0
for i in range(len(S)):
if i % 2 == 0:
if S[i] == "1":
ans += 1
else:
if S[i] == "0":
ans += 1
print((min(ans, len(S) - ans)))
|
# input
# N = list(map(int,input().split()))
# H = list(map(int,input().split()))
S = str(eval(input()))
ans = 0
for i in range(len(S)):
if i % 2 == 0:
if S[i] == "1":
ans += 1
else:
if S[i] == "0":
ans += 1
print((min(ans, len(S) - ans)))
| false | 14.285714 |
[
"-import numpy as np",
"-",
"+# N = list(map(int,input().split()))",
"+# H = list(map(int,input().split()))"
] | false | 0.085296 | 0.062925 | 1.355502 |
[
"s224247208",
"s640440607"
] |
u088552457
|
p03393
|
python
|
s036292444
|
s226792729
| 291 | 67 | 63,980 | 61,972 |
Accepted
|
Accepted
| 76.98 |
import fractions
import sys
from functools import reduce
import math
input = sys.stdin.readline
def main():
s = str(eval(input()))
abc = 'abcdefghijklmmopqrstuvwxyz'
usable = []
for a in list(abc):
if a not in s:
usable.append(a)
if len(usable) > 0:
print((s.strip() + usable[0]))
exit()
if s == list(abc)[::-1]:
print((-1))
exit()
for i in (list(range(len(s)-1)))[::-1]:
if s[i] < s[i+1]:
for j in range(i+1, len(s))[::-1]:
if s[i] < s[j]:
print((s[:i]+s[j]))
exit()
print((-1))
def divide_list(l, args):
result = []
pre = 0
for i, a in enumerate(args):
if i != 0:
pre = args[i-1]
result.append(l[pre:a])
if i == len(args) - 1:
result.append(l[a:])
return result
def divide_two(n):
c = 0
while True:
if c >= 2:
break
if n % 2 != 0:
break
n //= 2
c += 1
return c
def get_camulative(l):
import itertools
# 累積和
return [0] + list(itertools.accumulate(l))
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
if __name__ == "__main__":
main()
|
import itertools
def main():
a = 'abcdefghijklmnopqrstuvwxyz'
s = eval(input())
if len(s) < 26:
for v in s:
a = a.replace(v, '')
print((s + a[0]))
elif s == a[::-1]:
print((-1))
else:
for i in (list(range(25)))[::-1]:
if s[i] < s[i+1]:
for j in range(i+1, len(s))[::-1]:
if s[i] < s[j]:
print((s[:i]+s[j]))
exit()
def input_list():
return list(map(int, input().split()))
if __name__ == "__main__":
main()
| 86 | 27 | 1,763 | 586 |
import fractions
import sys
from functools import reduce
import math
input = sys.stdin.readline
def main():
s = str(eval(input()))
abc = "abcdefghijklmmopqrstuvwxyz"
usable = []
for a in list(abc):
if a not in s:
usable.append(a)
if len(usable) > 0:
print((s.strip() + usable[0]))
exit()
if s == list(abc)[::-1]:
print((-1))
exit()
for i in (list(range(len(s) - 1)))[::-1]:
if s[i] < s[i + 1]:
for j in range(i + 1, len(s))[::-1]:
if s[i] < s[j]:
print((s[:i] + s[j]))
exit()
print((-1))
def divide_list(l, args):
result = []
pre = 0
for i, a in enumerate(args):
if i != 0:
pre = args[i - 1]
result.append(l[pre:a])
if i == len(args) - 1:
result.append(l[a:])
return result
def divide_two(n):
c = 0
while True:
if c >= 2:
break
if n % 2 != 0:
break
n //= 2
c += 1
return c
def get_camulative(l):
import itertools
# 累積和
return [0] + list(itertools.accumulate(l))
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
if __name__ == "__main__":
main()
|
import itertools
def main():
a = "abcdefghijklmnopqrstuvwxyz"
s = eval(input())
if len(s) < 26:
for v in s:
a = a.replace(v, "")
print((s + a[0]))
elif s == a[::-1]:
print((-1))
else:
for i in (list(range(25)))[::-1]:
if s[i] < s[i + 1]:
for j in range(i + 1, len(s))[::-1]:
if s[i] < s[j]:
print((s[:i] + s[j]))
exit()
def input_list():
return list(map(int, input().split()))
if __name__ == "__main__":
main()
| false | 68.604651 |
[
"-import fractions",
"-import sys",
"-from functools import reduce",
"-import math",
"-",
"-input = sys.stdin.readline",
"+import itertools",
"- s = str(eval(input()))",
"- abc = \"abcdefghijklmmopqrstuvwxyz\"",
"- usable = []",
"- for a in list(abc):",
"- if a not in s:",
"- usable.append(a)",
"- if len(usable) > 0:",
"- print((s.strip() + usable[0]))",
"- exit()",
"- if s == list(abc)[::-1]:",
"+ a = \"abcdefghijklmnopqrstuvwxyz\"",
"+ s = eval(input())",
"+ if len(s) < 26:",
"+ for v in s:",
"+ a = a.replace(v, \"\")",
"+ print((s + a[0]))",
"+ elif s == a[::-1]:",
"- exit()",
"- for i in (list(range(len(s) - 1)))[::-1]:",
"- if s[i] < s[i + 1]:",
"- for j in range(i + 1, len(s))[::-1]:",
"- if s[i] < s[j]:",
"- print((s[:i] + s[j]))",
"- exit()",
"- print((-1))",
"-",
"-",
"-def divide_list(l, args):",
"- result = []",
"- pre = 0",
"- for i, a in enumerate(args):",
"- if i != 0:",
"- pre = args[i - 1]",
"- result.append(l[pre:a])",
"- if i == len(args) - 1:",
"- result.append(l[a:])",
"- return result",
"-",
"-",
"-def divide_two(n):",
"- c = 0",
"- while True:",
"- if c >= 2:",
"- break",
"- if n % 2 != 0:",
"- break",
"- n //= 2",
"- c += 1",
"- return c",
"-",
"-",
"-def get_camulative(l):",
"- import itertools",
"-",
"- # 累積和",
"- return [0] + list(itertools.accumulate(l))",
"-",
"-",
"-def combinations_count(n, r):",
"- return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))",
"+ else:",
"+ for i in (list(range(25)))[::-1]:",
"+ if s[i] < s[i + 1]:",
"+ for j in range(i + 1, len(s))[::-1]:",
"+ if s[i] < s[j]:",
"+ print((s[:i] + s[j]))",
"+ exit()",
"-def input_list_str():",
"- return list(map(str, input().split()))",
"-",
"-",
"-def lcm_base(x, y):",
"- return (x * y) // fractions.gcd(x, y)",
"-",
"-",
"-def lcm_list(numbers):",
"- return reduce(lcm_base, numbers, 1)",
"-",
"-",
"-def gcd(*numbers):",
"- return reduce(fractions.gcd, numbers)",
"-",
"-",
"-def gcd_list(numbers):",
"- return reduce(fractions.gcd, numbers)",
"-",
"-"
] | false | 0.054555 | 0.06248 | 0.873168 |
[
"s036292444",
"s226792729"
] |
u204842730
|
p02695
|
python
|
s535866120
|
s536202972
| 1,078 | 698 | 9,168 | 9,204 |
Accepted
|
Accepted
| 35.25 |
import itertools
n,m,q=list(map(int,input().split()))
a=[0 for i in range(q)]
b=[0 for i in range(q)]
c=[0 for i in range(q)]
d=[0 for i in range(q)]
for i in range(q):
a[i],b[i],c[i],d[i]=list(map(int,input().split()))
a[i]-=1
b[i]-=1
ans=0
for i in itertools.combinations_with_replacement(list(range(1,m+1)),n):
tmp=0
for j in range(q):
if i[b[j]] - i[a[j]] == c[j]:
tmp+=d[j]
ans=max(ans,tmp)
print(ans)
|
import itertools
n,m,q=list(map(int,input().split()))
a=[0 for i in range(q)]
b=[0 for i in range(q)]
c=[0 for i in range(q)]
d=[0 for i in range(q)]
for i in range(q):
a[i],b[i],c[i],d[i]=list(map(int,input().split()))
a[i]-=1
b[i]-=1
ans=0
buf=[None]*n
def dfs(nowdigit,cannum):
global ans
if nowdigit==n:
tmp=0
for j in range(q):
if buf[b[j]] - buf[a[j]] == c[j]:
tmp+=d[j]
ans=max(ans,tmp)
else:
for i in range(cannum,m+1):
buf[nowdigit]=i
dfs(nowdigit+1,i)
dfs(0,1)
print(ans)
| 19 | 27 | 451 | 604 |
import itertools
n, m, q = list(map(int, input().split()))
a = [0 for i in range(q)]
b = [0 for i in range(q)]
c = [0 for i in range(q)]
d = [0 for i in range(q)]
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
a[i] -= 1
b[i] -= 1
ans = 0
for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n):
tmp = 0
for j in range(q):
if i[b[j]] - i[a[j]] == c[j]:
tmp += d[j]
ans = max(ans, tmp)
print(ans)
|
import itertools
n, m, q = list(map(int, input().split()))
a = [0 for i in range(q)]
b = [0 for i in range(q)]
c = [0 for i in range(q)]
d = [0 for i in range(q)]
for i in range(q):
a[i], b[i], c[i], d[i] = list(map(int, input().split()))
a[i] -= 1
b[i] -= 1
ans = 0
buf = [None] * n
def dfs(nowdigit, cannum):
global ans
if nowdigit == n:
tmp = 0
for j in range(q):
if buf[b[j]] - buf[a[j]] == c[j]:
tmp += d[j]
ans = max(ans, tmp)
else:
for i in range(cannum, m + 1):
buf[nowdigit] = i
dfs(nowdigit + 1, i)
dfs(0, 1)
print(ans)
| false | 29.62963 |
[
"-for i in itertools.combinations_with_replacement(list(range(1, m + 1)), n):",
"- tmp = 0",
"- for j in range(q):",
"- if i[b[j]] - i[a[j]] == c[j]:",
"- tmp += d[j]",
"- ans = max(ans, tmp)",
"+buf = [None] * n",
"+",
"+",
"+def dfs(nowdigit, cannum):",
"+ global ans",
"+ if nowdigit == n:",
"+ tmp = 0",
"+ for j in range(q):",
"+ if buf[b[j]] - buf[a[j]] == c[j]:",
"+ tmp += d[j]",
"+ ans = max(ans, tmp)",
"+ else:",
"+ for i in range(cannum, m + 1):",
"+ buf[nowdigit] = i",
"+ dfs(nowdigit + 1, i)",
"+",
"+",
"+dfs(0, 1)"
] | false | 0.059296 | 0.063834 | 0.92891 |
[
"s535866120",
"s536202972"
] |
u764215612
|
p02690
|
python
|
s946361713
|
s399610567
| 28 | 25 | 9,160 | 9,088 |
Accepted
|
Accepted
| 10.71 |
x=int(eval(input()))
for i in range(120):
for j in range(-95,i):
if i**5-j**5==x:print((i,j));exit()
|
x=int(eval(input()))
for i in range(120):
for j in range(-90,i):
if i**5-j**5==x:print((i,j));exit()
| 4 | 4 | 98 | 98 |
x = int(eval(input()))
for i in range(120):
for j in range(-95, i):
if i**5 - j**5 == x:
print((i, j))
exit()
|
x = int(eval(input()))
for i in range(120):
for j in range(-90, i):
if i**5 - j**5 == x:
print((i, j))
exit()
| false | 0 |
[
"- for j in range(-95, i):",
"+ for j in range(-90, i):"
] | false | 0.098833 | 0.154995 | 0.637651 |
[
"s946361713",
"s399610567"
] |
u634677999
|
p03013
|
python
|
s414845805
|
s376501692
| 240 | 219 | 15,456 | 84,468 |
Accepted
|
Accepted
| 8.75 |
from collections import defaultdict as dd
n,m=[int(i) for i in input().split()]
brkn = dd(int)
mod = 10**9+7
for i in range(m):
num = int(eval(input()))
brkn[num]+=1
dp = [0]*(n+1)
dp[0]=1
if(1 in brkn):
dp[1]=0
else:
dp[1]=1
for i in range(2,n+1):
if(i in brkn):
dp[i]=0
else:
dp[i] = (dp[i-1]+ dp[i-2])%mod
print((dp[n]))
|
import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict as dd
n,m=[int(i) for i in input().split()]
brkn = dd(int)
mod = 10**9+7
for i in range(m):
num = int(eval(input()))
brkn[num]+=1
dp = [-1]*(n+1)
def func(curr):
if(curr==0):
dp[0]=1
return dp[0]
if(curr>0 and (curr in brkn)):
dp[curr]=0
return dp[curr]%mod
if(curr==1):
dp[1]=1
return dp[1]
if(dp[curr]!=-1):
return dp[curr]%mod
else:
dp[curr] = (func(curr-1) + func(curr-2))%mod
return dp[curr]%mod
print((func(n)))
| 20 | 30 | 384 | 628 |
from collections import defaultdict as dd
n, m = [int(i) for i in input().split()]
brkn = dd(int)
mod = 10**9 + 7
for i in range(m):
num = int(eval(input()))
brkn[num] += 1
dp = [0] * (n + 1)
dp[0] = 1
if 1 in brkn:
dp[1] = 0
else:
dp[1] = 1
for i in range(2, n + 1):
if i in brkn:
dp[i] = 0
else:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
|
import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict as dd
n, m = [int(i) for i in input().split()]
brkn = dd(int)
mod = 10**9 + 7
for i in range(m):
num = int(eval(input()))
brkn[num] += 1
dp = [-1] * (n + 1)
def func(curr):
if curr == 0:
dp[0] = 1
return dp[0]
if curr > 0 and (curr in brkn):
dp[curr] = 0
return dp[curr] % mod
if curr == 1:
dp[1] = 1
return dp[1]
if dp[curr] != -1:
return dp[curr] % mod
else:
dp[curr] = (func(curr - 1) + func(curr - 2)) % mod
return dp[curr] % mod
print((func(n)))
| false | 33.333333 |
[
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"-dp = [0] * (n + 1)",
"-dp[0] = 1",
"-if 1 in brkn:",
"- dp[1] = 0",
"-else:",
"- dp[1] = 1",
"-for i in range(2, n + 1):",
"- if i in brkn:",
"- dp[i] = 0",
"+dp = [-1] * (n + 1)",
"+",
"+",
"+def func(curr):",
"+ if curr == 0:",
"+ dp[0] = 1",
"+ return dp[0]",
"+ if curr > 0 and (curr in brkn):",
"+ dp[curr] = 0",
"+ return dp[curr] % mod",
"+ if curr == 1:",
"+ dp[1] = 1",
"+ return dp[1]",
"+ if dp[curr] != -1:",
"+ return dp[curr] % mod",
"- dp[i] = (dp[i - 1] + dp[i - 2]) % mod",
"-print((dp[n]))",
"+ dp[curr] = (func(curr - 1) + func(curr - 2)) % mod",
"+ return dp[curr] % mod",
"+",
"+",
"+print((func(n)))"
] | false | 0.007374 | 0.063502 | 0.116129 |
[
"s414845805",
"s376501692"
] |
u595289165
|
p03087
|
python
|
s444930500
|
s637462875
| 1,765 | 856 | 16,664 | 7,748 |
Accepted
|
Accepted
| 51.5 |
import numpy as np
n, q = list(map(int, input().split()))
s = eval(input())
w = np.zeros(n, dtype=int)
a = 0
for i in range(n):
if s[i] == "A":
if a == 0:
a += 1
elif s[i] == "C":
if a:
w[i-1] = 1
a -= 1
else:
if a:
a -= 1
ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))
for _ in range(q):
l, r = list(map(int, input().split()))
print((ans[r-1] - ans[l-1]))
|
N, Q = list(map(int, input().split()))
S = eval(input())
t=[0]*(N+1)
for i in range(N):
t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
l, r = list(map(int, input().split()))
print((t[r-1] - t[l-1]))
| 22 | 9 | 459 | 224 |
import numpy as np
n, q = list(map(int, input().split()))
s = eval(input())
w = np.zeros(n, dtype=int)
a = 0
for i in range(n):
if s[i] == "A":
if a == 0:
a += 1
elif s[i] == "C":
if a:
w[i - 1] = 1
a -= 1
else:
if a:
a -= 1
ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))
for _ in range(q):
l, r = list(map(int, input().split()))
print((ans[r - 1] - ans[l - 1]))
|
N, Q = list(map(int, input().split()))
S = eval(input())
t = [0] * (N + 1)
for i in range(N):
t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0)
for i in range(Q):
l, r = list(map(int, input().split()))
print((t[r - 1] - t[l - 1]))
| false | 59.090909 |
[
"-import numpy as np",
"-",
"-n, q = list(map(int, input().split()))",
"-s = eval(input())",
"-w = np.zeros(n, dtype=int)",
"-a = 0",
"-for i in range(n):",
"- if s[i] == \"A\":",
"- if a == 0:",
"- a += 1",
"- elif s[i] == \"C\":",
"- if a:",
"- w[i - 1] = 1",
"- a -= 1",
"- else:",
"- if a:",
"- a -= 1",
"-ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))",
"-for _ in range(q):",
"+N, Q = list(map(int, input().split()))",
"+S = eval(input())",
"+t = [0] * (N + 1)",
"+for i in range(N):",
"+ t[i + 1] = t[i] + (1 if S[i : i + 2] == \"AC\" else 0)",
"+for i in range(Q):",
"- print((ans[r - 1] - ans[l - 1]))",
"+ print((t[r - 1] - t[l - 1]))"
] | false | 0.379147 | 0.037282 | 10.16959 |
[
"s444930500",
"s637462875"
] |
u433532588
|
p02971
|
python
|
s157197846
|
s990156765
| 706 | 348 | 15,636 | 14,136 |
Accepted
|
Accepted
| 50.71 |
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
L = [0] * (200000+1)
R = [0] * (200000+1)
L[0] = 0
for i in range(1, N+1):
L[i] = max(A[i-1], L[i-1])
R[N] = 0
for i in range(N-1, 0, -1):
R[i] = max(R[i+1], A[i])
#print(L)
#print(R)
for i in range(N):
ans = max(L[i], R[i+1])
print(ans)
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################
N = int(eval(input()))
A = []
for i in range(N):
a = int(eval(input()))
A.append(a)
B = list(reversed(sorted(A)))
for i in range(N):
# 最大か二番目を出せばいい
if A[i] == B[0]:
print((B[1]))
else:
print((B[0]))
| 20 | 20 | 331 | 339 |
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
L = [0] * (200000 + 1)
R = [0] * (200000 + 1)
L[0] = 0
for i in range(1, N + 1):
L[i] = max(A[i - 1], L[i - 1])
R[N] = 0
for i in range(N - 1, 0, -1):
R[i] = max(R[i + 1], A[i])
# print(L)
# print(R)
for i in range(N):
ans = max(L[i], R[i + 1])
print(ans)
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################
N = int(eval(input()))
A = []
for i in range(N):
a = int(eval(input()))
A.append(a)
B = list(reversed(sorted(A)))
for i in range(N):
# 最大か二番目を出せばいい
if A[i] == B[0]:
print((B[1]))
else:
print((B[0]))
| false | 0 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**6)",
"+##############################",
"-A = [int(eval(input())) for _ in range(N)]",
"-L = [0] * (200000 + 1)",
"-R = [0] * (200000 + 1)",
"-L[0] = 0",
"-for i in range(1, N + 1):",
"- L[i] = max(A[i - 1], L[i - 1])",
"-R[N] = 0",
"-for i in range(N - 1, 0, -1):",
"- R[i] = max(R[i + 1], A[i])",
"-# print(L)",
"-# print(R)",
"+A = []",
"- ans = max(L[i], R[i + 1])",
"- print(ans)",
"+ a = int(eval(input()))",
"+ A.append(a)",
"+B = list(reversed(sorted(A)))",
"+for i in range(N):",
"+ # 最大か二番目を出せばいい",
"+ if A[i] == B[0]:",
"+ print((B[1]))",
"+ else:",
"+ print((B[0]))"
] | false | 0.038426 | 0.036557 | 1.051137 |
[
"s157197846",
"s990156765"
] |
u404676457
|
p03317
|
python
|
s013932171
|
s090106587
| 49 | 29 | 13,880 | 4,724 |
Accepted
|
Accepted
| 40.82 |
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
while n > k:
n -= k - 1
count += 1
count += 1
print(count)
|
(n, k) = list(map(int, input().split()))
_ = eval(input())
count = 0
while n > k:
n -= k - 1
count += 1
count += 1
print(count)
| 10 | 10 | 158 | 134 |
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
while n > k:
n -= k - 1
count += 1
count += 1
print(count)
|
(n, k) = list(map(int, input().split()))
_ = eval(input())
count = 0
while n > k:
n -= k - 1
count += 1
count += 1
print(count)
| false | 0 |
[
"-a = list(map(int, input().split()))",
"+_ = eval(input())"
] | false | 0.039272 | 0.007772 | 5.053034 |
[
"s013932171",
"s090106587"
] |
u312025627
|
p03264
|
python
|
s225202663
|
s786171576
| 191 | 161 | 38,256 | 38,384 |
Accepted
|
Accepted
| 15.71 |
k = int(eval(input()))
cnt_odd = 0
cnt_even = 0
if k&1:
while k >= 1:
cnt_odd += 1
k -= 2
cnt_even = cnt_odd - 1
else:
while k > 0:
cnt_even += 1
k -= 2
cnt_odd = cnt_even
print((cnt_even * cnt_odd))
|
def main():
N = int(eval(input()))
odd = (N+1)//2
even = N//2
print((odd*even))
if __name__ == '__main__':
main()
| 15 | 9 | 254 | 136 |
k = int(eval(input()))
cnt_odd = 0
cnt_even = 0
if k & 1:
while k >= 1:
cnt_odd += 1
k -= 2
cnt_even = cnt_odd - 1
else:
while k > 0:
cnt_even += 1
k -= 2
cnt_odd = cnt_even
print((cnt_even * cnt_odd))
|
def main():
N = int(eval(input()))
odd = (N + 1) // 2
even = N // 2
print((odd * even))
if __name__ == "__main__":
main()
| false | 40 |
[
"-k = int(eval(input()))",
"-cnt_odd = 0",
"-cnt_even = 0",
"-if k & 1:",
"- while k >= 1:",
"- cnt_odd += 1",
"- k -= 2",
"- cnt_even = cnt_odd - 1",
"-else:",
"- while k > 0:",
"- cnt_even += 1",
"- k -= 2",
"- cnt_odd = cnt_even",
"-print((cnt_even * cnt_odd))",
"+def main():",
"+ N = int(eval(input()))",
"+ odd = (N + 1) // 2",
"+ even = N // 2",
"+ print((odd * even))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.068422 | 0.038456 | 1.779221 |
[
"s225202663",
"s786171576"
] |
u133936772
|
p03805
|
python
|
s455694221
|
s296093761
| 29 | 25 | 3,064 | 3,064 |
Accepted
|
Accepted
| 13.79 |
f=lambda:list(map(int,input().split()))
n,m=f()
g=[[0]*n for _ in range(n)]
for i in range(m):
a,b=f(); g[a-1][b-1]=g[b-1][a-1]=1
import itertools as it
c=0
for t in it.permutations(list(range(1,n))):
p,d=0,1
for q in t: d*=g[p][q]; p=q
c+=d
print(c)
|
f=lambda:list(map(int,input().split()))
n,m=f()
g=[[0]*n for _ in range(n)]
for i in range(m):
a,b=f(); g[a-1][b-1]=g[b-1][a-1]=1
import itertools as it
c=0
for t in it.permutations(list(range(1,n))):
p=0
for q in t:
if g[p][q]<1: break
p=q
else: c+=1
print(c)
| 12 | 14 | 257 | 277 |
f = lambda: list(map(int, input().split()))
n, m = f()
g = [[0] * n for _ in range(n)]
for i in range(m):
a, b = f()
g[a - 1][b - 1] = g[b - 1][a - 1] = 1
import itertools as it
c = 0
for t in it.permutations(list(range(1, n))):
p, d = 0, 1
for q in t:
d *= g[p][q]
p = q
c += d
print(c)
|
f = lambda: list(map(int, input().split()))
n, m = f()
g = [[0] * n for _ in range(n)]
for i in range(m):
a, b = f()
g[a - 1][b - 1] = g[b - 1][a - 1] = 1
import itertools as it
c = 0
for t in it.permutations(list(range(1, n))):
p = 0
for q in t:
if g[p][q] < 1:
break
p = q
else:
c += 1
print(c)
| false | 14.285714 |
[
"- p, d = 0, 1",
"+ p = 0",
"- d *= g[p][q]",
"+ if g[p][q] < 1:",
"+ break",
"- c += d",
"+ else:",
"+ c += 1"
] | false | 0.091268 | 0.044307 | 2.059902 |
[
"s455694221",
"s296093761"
] |
u820351940
|
p04001
|
python
|
s631547186
|
s507587997
| 54 | 27 | 3,064 | 3,064 |
Accepted
|
Accepted
| 50 |
import itertools
nums = eval(input())
index = list(range(1, len(nums)))
def resolve(i):
t = list(nums)
for j in reversed(i): t.insert(j, "+")
return eval("".join(t))
print((sum([resolve(i) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])])))
|
import itertools
number = eval(input())
answer = int(number)
length = len(number)
empty = [""] * length
plus = ["+"] * length
results = []
for i in range(2**(length - 1)):
calc = ""
for j in range(length - 1):
calc += number[j]
if i & 1:
calc += "+"
i >>= 1
f = calc + number[-1]
results.append(eval(f))
print((sum(results)))
| 9 | 20 | 293 | 392 |
import itertools
nums = eval(input())
index = list(range(1, len(nums)))
def resolve(i):
t = list(nums)
for j in reversed(i):
t.insert(j, "+")
return eval("".join(t))
print(
(
sum(
[
resolve(i)
for i in itertools.chain(
*[itertools.combinations(index, x) for x in range(len(index) + 1)]
)
]
)
)
)
|
import itertools
number = eval(input())
answer = int(number)
length = len(number)
empty = [""] * length
plus = ["+"] * length
results = []
for i in range(2 ** (length - 1)):
calc = ""
for j in range(length - 1):
calc += number[j]
if i & 1:
calc += "+"
i >>= 1
f = calc + number[-1]
results.append(eval(f))
print((sum(results)))
| false | 55 |
[
"-nums = eval(input())",
"-index = list(range(1, len(nums)))",
"-",
"-",
"-def resolve(i):",
"- t = list(nums)",
"- for j in reversed(i):",
"- t.insert(j, \"+\")",
"- return eval(\"\".join(t))",
"-",
"-",
"-print(",
"- (",
"- sum(",
"- [",
"- resolve(i)",
"- for i in itertools.chain(",
"- *[itertools.combinations(index, x) for x in range(len(index) + 1)]",
"- )",
"- ]",
"- )",
"- )",
"-)",
"+number = eval(input())",
"+answer = int(number)",
"+length = len(number)",
"+empty = [\"\"] * length",
"+plus = [\"+\"] * length",
"+results = []",
"+for i in range(2 ** (length - 1)):",
"+ calc = \"\"",
"+ for j in range(length - 1):",
"+ calc += number[j]",
"+ if i & 1:",
"+ calc += \"+\"",
"+ i >>= 1",
"+ f = calc + number[-1]",
"+ results.append(eval(f))",
"+print((sum(results)))"
] | false | 0.040682 | 0.040256 | 1.010585 |
[
"s631547186",
"s507587997"
] |
u197955752
|
p03785
|
python
|
s209166668
|
s232061740
| 176 | 94 | 13,340 | 13,264 |
Accepted
|
Accepted
| 46.59 |
N, C, K = [int(x) for x in input().split()]
T = [int(eval(input())) for _ in range(N)]
T.sort()
depart = T[0] + K # 出発時刻
passenger = 0 # 乗客数
bus = 1
for i in range(N):
if passenger >= C or depart < T[i]: # すでに満員または待ち時間オーバー
bus += 1
passenger = 1
depart = T[i] + K
else:
passenger += 1
print(bus)
|
import sys
input = sys.stdin.readline
N, C, K = [int(x) for x in input().split()]
T = [int(eval(input())) for _ in range(N)]
T.sort()
depart = T[0] + K # 出発時刻
passenger = 0 # 乗客数
bus = 1
for i in range(N):
if passenger >= C or depart < T[i]: # すでに満員または待ち時間オーバー
bus += 1
passenger = 1
depart = T[i] + K
else:
passenger += 1
print(bus)
| 15 | 17 | 347 | 387 |
N, C, K = [int(x) for x in input().split()]
T = [int(eval(input())) for _ in range(N)]
T.sort()
depart = T[0] + K # 出発時刻
passenger = 0 # 乗客数
bus = 1
for i in range(N):
if passenger >= C or depart < T[i]: # すでに満員または待ち時間オーバー
bus += 1
passenger = 1
depart = T[i] + K
else:
passenger += 1
print(bus)
|
import sys
input = sys.stdin.readline
N, C, K = [int(x) for x in input().split()]
T = [int(eval(input())) for _ in range(N)]
T.sort()
depart = T[0] + K # 出発時刻
passenger = 0 # 乗客数
bus = 1
for i in range(N):
if passenger >= C or depart < T[i]: # すでに満員または待ち時間オーバー
bus += 1
passenger = 1
depart = T[i] + K
else:
passenger += 1
print(bus)
| false | 11.764706 |
[
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.074334 | 0.037322 | 1.991684 |
[
"s209166668",
"s232061740"
] |
u020604402
|
p03147
|
python
|
s860854043
|
s812407266
| 21 | 18 | 3,188 | 3,188 |
Accepted
|
Accepted
| 14.29 |
N = int(eval(input()))
L = list(map(int,input().split()))
ans = 0
def zero_spliter(L):
cnt = 1
for x in L:
if x == 0:
cnt += 1
M = [[] for _ in range(cnt)]
i = 0
for x in L:
if x != 0:
M[i].append(x)
else:
i += 1
for x in M:
if x != []:
yield x
ans = 0
def counter(L):
global ans
if L == []:
pass
if 0 in L:
l = list(zero_spliter(L))
for x in l:
counter(x)
else:
M = [x-1 for x in L]
ans += 1
counter(M)
counter(L)
print(ans)
|
N = int(eval(input()))
L = list(map(int,input().split()))
def count(L):
if len(L) == 1:
return L[0]
if L == []:
return 0
if 0 in L:
i = L.index(0)
return count(L[:i]) + count(L[i+1:])
else:
m = min(L)
L = list([x-m for x in L])
return m + count(L)
print((count(L)))
| 33 | 16 | 632 | 350 |
N = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
def zero_spliter(L):
cnt = 1
for x in L:
if x == 0:
cnt += 1
M = [[] for _ in range(cnt)]
i = 0
for x in L:
if x != 0:
M[i].append(x)
else:
i += 1
for x in M:
if x != []:
yield x
ans = 0
def counter(L):
global ans
if L == []:
pass
if 0 in L:
l = list(zero_spliter(L))
for x in l:
counter(x)
else:
M = [x - 1 for x in L]
ans += 1
counter(M)
counter(L)
print(ans)
|
N = int(eval(input()))
L = list(map(int, input().split()))
def count(L):
if len(L) == 1:
return L[0]
if L == []:
return 0
if 0 in L:
i = L.index(0)
return count(L[:i]) + count(L[i + 1 :])
else:
m = min(L)
L = list([x - m for x in L])
return m + count(L)
print((count(L)))
| false | 51.515152 |
[
"-ans = 0",
"-def zero_spliter(L):",
"- cnt = 1",
"- for x in L:",
"- if x == 0:",
"- cnt += 1",
"- M = [[] for _ in range(cnt)]",
"- i = 0",
"- for x in L:",
"- if x != 0:",
"- M[i].append(x)",
"- else:",
"- i += 1",
"- for x in M:",
"- if x != []:",
"- yield x",
"+def count(L):",
"+ if len(L) == 1:",
"+ return L[0]",
"+ if L == []:",
"+ return 0",
"+ if 0 in L:",
"+ i = L.index(0)",
"+ return count(L[:i]) + count(L[i + 1 :])",
"+ else:",
"+ m = min(L)",
"+ L = list([x - m for x in L])",
"+ return m + count(L)",
"-ans = 0",
"-",
"-",
"-def counter(L):",
"- global ans",
"- if L == []:",
"- pass",
"- if 0 in L:",
"- l = list(zero_spliter(L))",
"- for x in l:",
"- counter(x)",
"- else:",
"- M = [x - 1 for x in L]",
"- ans += 1",
"- counter(M)",
"-",
"-",
"-counter(L)",
"-print(ans)",
"+print((count(L)))"
] | false | 0.043833 | 0.044902 | 0.976204 |
[
"s860854043",
"s812407266"
] |
u471898432
|
p02813
|
python
|
s610880398
|
s600930843
| 28 | 25 | 8,052 | 3,060 |
Accepted
|
Accepted
| 10.71 |
from itertools import permutations
N = int(eval(input()))
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
ps = list(permutations(list(range(1, N + 1))))
ps.index(P)
print((abs(ps.index(Q) - ps.index(P))))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
ps = permutations(list(range(1, N + 1)))
try:
x, y = [i for i, t in enumerate(ps) if t == P or t == Q]
except ValueError:
print((0))
else:
print((abs(x - y)))
| 10 | 14 | 241 | 315 |
from itertools import permutations
N = int(eval(input()))
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
ps = list(permutations(list(range(1, N + 1))))
ps.index(P)
print((abs(ps.index(Q) - ps.index(P))))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
ps = permutations(list(range(1, N + 1)))
try:
x, y = [i for i, t in enumerate(ps) if t == P or t == Q]
except ValueError:
print((0))
else:
print((abs(x - y)))
| false | 28.571429 |
[
"-ps = list(permutations(list(range(1, N + 1))))",
"-ps.index(P)",
"-print((abs(ps.index(Q) - ps.index(P))))",
"+ps = permutations(list(range(1, N + 1)))",
"+try:",
"+ x, y = [i for i, t in enumerate(ps) if t == P or t == Q]",
"+except ValueError:",
"+ print((0))",
"+else:",
"+ print((abs(x - y)))"
] | false | 0.039667 | 0.039666 | 1.000005 |
[
"s610880398",
"s600930843"
] |
u114641312
|
p02642
|
python
|
s710028530
|
s200437765
| 1,776 | 777 | 114,896 | 122,340 |
Accepted
|
Accepted
| 56.25 |
import numpy as np
from numba import njit
# @njit('(i4[::1],)', cache=True)
def solve(A):
count = np.zeros(10**6 + 10, np.int32)
for x in A:
if count[x] > 1:
continue
count[::x] += 1
ret = 0
for x in A:
ret += count[x] == 1
return ret
N = int(eval(input()))
A = np.array(list(map(int,input().split())), np.int32)
print((solve(A)))
|
import numpy as np
from numba import njit
# @njit('(i4[::1],)', cache=True)
@njit
def solve(A):
count = np.zeros(10**6 + 10, np.int32)
for x in A:
if count[x] > 1:
continue
count[::x] += 1
ret = 0
for x in A:
ret += count[x] == 1
return ret
N = int(eval(input()))
A = np.array(list(map(int,input().split())), np.int32)
print((solve(A)))
| 19 | 20 | 403 | 410 |
import numpy as np
from numba import njit
# @njit('(i4[::1],)', cache=True)
def solve(A):
count = np.zeros(10**6 + 10, np.int32)
for x in A:
if count[x] > 1:
continue
count[::x] += 1
ret = 0
for x in A:
ret += count[x] == 1
return ret
N = int(eval(input()))
A = np.array(list(map(int, input().split())), np.int32)
print((solve(A)))
|
import numpy as np
from numba import njit
# @njit('(i4[::1],)', cache=True)
@njit
def solve(A):
count = np.zeros(10**6 + 10, np.int32)
for x in A:
if count[x] > 1:
continue
count[::x] += 1
ret = 0
for x in A:
ret += count[x] == 1
return ret
N = int(eval(input()))
A = np.array(list(map(int, input().split())), np.int32)
print((solve(A)))
| false | 5 |
[
"+@njit"
] | false | 0.467638 | 0.270957 | 1.725877 |
[
"s710028530",
"s200437765"
] |
u753803401
|
p03387
|
python
|
s464113333
|
s675708137
| 279 | 166 | 63,980 | 38,336 |
Accepted
|
Accepted
| 40.5 |
def slove():
import sys
import bisect
import collections
import fractions
import heapq
input = sys.stdin.readline
a, b, c = list(map(int, input().rstrip('\n').split()))
cnt = 0
while True:
a, b, c = sorted([a, b, c])
if abs(a - c) >= 2:
a += 2
cnt += 1
else:
if a == b == c:
print(cnt)
exit()
if a == b:
a += 1
b += 1
cnt += 1
elif b == c:
b += 1
c += 1
cnt += 1
elif a == c:
a += 1
c += 1
cnt += 1
if __name__ == '__main__':
slove()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
a, b, c = list(map(int, readline().split()))
sn = sum([a, b, c])
mn = max(a, b, c)
for i in range(mn * 3, 10 ** 10, 3):
if (i - sn) % 2 == 0:
print(((i - sn) // 2))
exit()
if __name__ == '__main__':
solve()
| 34 | 17 | 781 | 364 |
def slove():
import sys
import bisect
import collections
import fractions
import heapq
input = sys.stdin.readline
a, b, c = list(map(int, input().rstrip("\n").split()))
cnt = 0
while True:
a, b, c = sorted([a, b, c])
if abs(a - c) >= 2:
a += 2
cnt += 1
else:
if a == b == c:
print(cnt)
exit()
if a == b:
a += 1
b += 1
cnt += 1
elif b == c:
b += 1
c += 1
cnt += 1
elif a == c:
a += 1
c += 1
cnt += 1
if __name__ == "__main__":
slove()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
a, b, c = list(map(int, readline().split()))
sn = sum([a, b, c])
mn = max(a, b, c)
for i in range(mn * 3, 10**10, 3):
if (i - sn) % 2 == 0:
print(((i - sn) // 2))
exit()
if __name__ == "__main__":
solve()
| false | 50 |
[
"-def slove():",
"- import sys",
"- import bisect",
"- import collections",
"- import fractions",
"- import heapq",
"+import sys",
"- input = sys.stdin.readline",
"- a, b, c = list(map(int, input().rstrip(\"\\n\").split()))",
"- cnt = 0",
"- while True:",
"- a, b, c = sorted([a, b, c])",
"- if abs(a - c) >= 2:",
"- a += 2",
"- cnt += 1",
"- else:",
"- if a == b == c:",
"- print(cnt)",
"- exit()",
"- if a == b:",
"- a += 1",
"- b += 1",
"- cnt += 1",
"- elif b == c:",
"- b += 1",
"- c += 1",
"- cnt += 1",
"- elif a == c:",
"- a += 1",
"- c += 1",
"- cnt += 1",
"+",
"+def solve():",
"+ readline = sys.stdin.buffer.readline",
"+ mod = 10**9 + 7",
"+ a, b, c = list(map(int, readline().split()))",
"+ sn = sum([a, b, c])",
"+ mn = max(a, b, c)",
"+ for i in range(mn * 3, 10**10, 3):",
"+ if (i - sn) % 2 == 0:",
"+ print(((i - sn) // 2))",
"+ exit()",
"- slove()",
"+ solve()"
] | false | 0.037205 | 0.055563 | 0.669591 |
[
"s464113333",
"s675708137"
] |
u141610915
|
p03592
|
python
|
s473727039
|
s736841667
| 193 | 176 | 46,704 | 38,768 |
Accepted
|
Accepted
| 8.81 |
import sys
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N + 1):
for j in range(M + 1):
dp[i][j] = i * M + j * N - 2 * i * j
if dp[i][j] == K:
print("Yes")
exit(0)
print("No")
|
import sys
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
for i in range(N + 1):
for j in range(M + 1):
if i * M + j * N - i * j * 2 == K:
print("Yes")
exit(0)
print("No")
| 11 | 9 | 282 | 213 |
import sys
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N + 1):
for j in range(M + 1):
dp[i][j] = i * M + j * N - 2 * i * j
if dp[i][j] == K:
print("Yes")
exit(0)
print("No")
|
import sys
input = sys.stdin.readline
N, M, K = list(map(int, input().split()))
for i in range(N + 1):
for j in range(M + 1):
if i * M + j * N - i * j * 2 == K:
print("Yes")
exit(0)
print("No")
| false | 18.181818 |
[
"-dp = [[0] * (M + 1) for _ in range(N + 1)]",
"- dp[i][j] = i * M + j * N - 2 * i * j",
"- if dp[i][j] == K:",
"+ if i * M + j * N - i * j * 2 == K:"
] | false | 0.035494 | 0.04214 | 0.842291 |
[
"s473727039",
"s736841667"
] |
u123756661
|
p03805
|
python
|
s861018210
|
s184220268
| 190 | 80 | 41,200 | 79,752 |
Accepted
|
Accepted
| 57.89 |
import itertools
n,m=list(map(int,input().split()))
path={i+1:[] for i in range(n)}
for i in range(m):
u,v=list(map(int,input().split()))
path[u].append(v)
path[v].append(u)
chk=[i for i in range(2,n+1)]
ans=0
for way in list(itertools.permutations(chk)):
now=1
if way[0] in path[now]:
f=1
for j in way:
if j in path[now]:
now=j
f+=1
else:
break
if f==n: ans+=1
print(ans)
|
import itertools
n,m=list(map(int,input().split()))
l=[[0]*n for i in range(n)]
for i in range(m):
a,b=list(map(int,input().split()))
l[a-1][b-1]=1
l[b-1][a-1]=1
d=[int(i)+1 for i in range(n)]
ans=chk=0
for i in list(itertools.permutations(d,n)):
chk=1
if i[0]!=1: continue
for j in range(n-1):
chk*=l[i[j+1]-1][i[j]-1]
ans+=chk
print(ans)
| 22 | 16 | 498 | 378 |
import itertools
n, m = list(map(int, input().split()))
path = {i + 1: [] for i in range(n)}
for i in range(m):
u, v = list(map(int, input().split()))
path[u].append(v)
path[v].append(u)
chk = [i for i in range(2, n + 1)]
ans = 0
for way in list(itertools.permutations(chk)):
now = 1
if way[0] in path[now]:
f = 1
for j in way:
if j in path[now]:
now = j
f += 1
else:
break
if f == n:
ans += 1
print(ans)
|
import itertools
n, m = list(map(int, input().split()))
l = [[0] * n for i in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
l[a - 1][b - 1] = 1
l[b - 1][a - 1] = 1
d = [int(i) + 1 for i in range(n)]
ans = chk = 0
for i in list(itertools.permutations(d, n)):
chk = 1
if i[0] != 1:
continue
for j in range(n - 1):
chk *= l[i[j + 1] - 1][i[j] - 1]
ans += chk
print(ans)
| false | 27.272727 |
[
"-path = {i + 1: [] for i in range(n)}",
"+l = [[0] * n for i in range(n)]",
"- u, v = list(map(int, input().split()))",
"- path[u].append(v)",
"- path[v].append(u)",
"-chk = [i for i in range(2, n + 1)]",
"-ans = 0",
"-for way in list(itertools.permutations(chk)):",
"- now = 1",
"- if way[0] in path[now]:",
"- f = 1",
"- for j in way:",
"- if j in path[now]:",
"- now = j",
"- f += 1",
"- else:",
"- break",
"- if f == n:",
"- ans += 1",
"+ a, b = list(map(int, input().split()))",
"+ l[a - 1][b - 1] = 1",
"+ l[b - 1][a - 1] = 1",
"+d = [int(i) + 1 for i in range(n)]",
"+ans = chk = 0",
"+for i in list(itertools.permutations(d, n)):",
"+ chk = 1",
"+ if i[0] != 1:",
"+ continue",
"+ for j in range(n - 1):",
"+ chk *= l[i[j + 1] - 1][i[j] - 1]",
"+ ans += chk"
] | false | 0.123093 | 0.065624 | 1.875726 |
[
"s861018210",
"s184220268"
] |
u645250356
|
p03006
|
python
|
s762116765
|
s646065076
| 190 | 40 | 39,280 | 10,708 |
Accepted
|
Accepted
| 78.95 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = [inpl() for i in range(n)]
a.sort(key=lambda x:x[1])
a.sort()
z = []
# pprint.pprint(a)
for i in range(n):
for j in range(i,n):
if i == j:
continue
z.append((a[i][0]-a[j][0], a[i][1]-a[j][1]))
c = Counter(z)
# pprint.pprint(c)
if n == 1:
print((1))
else:
print((n-c.most_common()[0][1]))
# print(n-c.most_common()[0][1])
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = [inpl() for _ in range(n)]
if n == 1:
print((1))
quit()
c = []
for i,(x,y) in enumerate(a):
for j,(z,w) in enumerate(a):
if i == j: continue
c.append(((x-z), (y-w)))
h = Counter(c)
print((n-max(h.values())))
| 28 | 21 | 755 | 580 |
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = [inpl() for i in range(n)]
a.sort(key=lambda x: x[1])
a.sort()
z = []
# pprint.pprint(a)
for i in range(n):
for j in range(i, n):
if i == j:
continue
z.append((a[i][0] - a[j][0], a[i][1] - a[j][1]))
c = Counter(z)
# pprint.pprint(c)
if n == 1:
print((1))
else:
print((n - c.most_common()[0][1]))
# print(n-c.most_common()[0][1])
|
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
a = [inpl() for _ in range(n)]
if n == 1:
print((1))
quit()
c = []
for i, (x, y) in enumerate(a):
for j, (z, w) in enumerate(a):
if i == j:
continue
c.append(((x - z), (y - w)))
h = Counter(c)
print((n - max(h.values())))
| false | 25 |
[
"-import sys, bisect, math, itertools, pprint",
"+import sys, bisect, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-a = [inpl() for i in range(n)]",
"-a.sort(key=lambda x: x[1])",
"-a.sort()",
"-z = []",
"-# pprint.pprint(a)",
"-for i in range(n):",
"- for j in range(i, n):",
"+a = [inpl() for _ in range(n)]",
"+if n == 1:",
"+ print((1))",
"+ quit()",
"+c = []",
"+for i, (x, y) in enumerate(a):",
"+ for j, (z, w) in enumerate(a):",
"- z.append((a[i][0] - a[j][0], a[i][1] - a[j][1]))",
"-c = Counter(z)",
"-# pprint.pprint(c)",
"-if n == 1:",
"- print((1))",
"-else:",
"- print((n - c.most_common()[0][1]))",
"-# print(n-c.most_common()[0][1])",
"+ c.append(((x - z), (y - w)))",
"+h = Counter(c)",
"+print((n - max(h.values())))"
] | false | 0.04137 | 0.040479 | 1.022005 |
[
"s762116765",
"s646065076"
] |
u064505481
|
p03175
|
python
|
s882781448
|
s126305967
| 1,536 | 282 | 942,488 | 114,524 |
Accepted
|
Accepted
| 81.64 |
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float('inf'), float('-inf')
def main():
MOD = 10**9 + 7
n = int(rl())
G = [[] for _ in range(n)]
for _ in range(n-1):
u, v = rli()
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
def dfs(node, prnt):
w, b = 1, 1
for nbhr in G[node]:
if nbhr == prnt: continue
nw, nb = dfs(nbhr, node)
w *= (nw + nb)
w %= MOD
b *= nw
b %= MOD
return w, b
answ, ansb = dfs(0, -1)
print(((answ + ansb) % MOD))
stdout.close()
if __name__ == "__main__":
main()
|
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float('inf'), float('-inf')
def main():
MOD = 10**9 + 7
n = int(rl())
G = [[] for _ in range(n)]
for _ in range(n-1):
u, v = rli()
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
wb = [[1,1] for _ in range(n+1)]
wb[n] = [0, 0]
seen = [0 for _ in range(n)]
stack = []
stack.append((0, n))
while stack:
node, prnt = stack.pop()
w, b = wb[node]
if not seen[node]:
seen[node] = 1
stack.append((node, prnt))
for nbhr in G[node]:
if nbhr == prnt: continue
stack.append((nbhr, node))
else:
pw, pb = wb[prnt]
pw *= (w + b)
pb *= w
wb[prnt] = [pw % MOD, pb % MOD]
ans = (wb[0][0] + wb[0][1]) % MOD
print(ans)
stdout.close()
if __name__ == "__main__":
main()
| 43 | 52 | 912 | 1,151 |
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
def main():
MOD = 10**9 + 7
n = int(rl())
G = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = rli()
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
def dfs(node, prnt):
w, b = 1, 1
for nbhr in G[node]:
if nbhr == prnt:
continue
nw, nb = dfs(nbhr, node)
w *= nw + nb
w %= MOD
b *= nw
b %= MOD
return w, b
answ, ansb = dfs(0, -1)
print(((answ + ansb) % MOD))
stdout.close()
if __name__ == "__main__":
main()
|
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: list(map(int, stdin.readline().split()))
rlf = lambda: list(map(float, stdin.readline().split()))
INF, NINF = float("inf"), float("-inf")
def main():
MOD = 10**9 + 7
n = int(rl())
G = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = rli()
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
wb = [[1, 1] for _ in range(n + 1)]
wb[n] = [0, 0]
seen = [0 for _ in range(n)]
stack = []
stack.append((0, n))
while stack:
node, prnt = stack.pop()
w, b = wb[node]
if not seen[node]:
seen[node] = 1
stack.append((node, prnt))
for nbhr in G[node]:
if nbhr == prnt:
continue
stack.append((nbhr, node))
else:
pw, pb = wb[prnt]
pw *= w + b
pb *= w
wb[prnt] = [pw % MOD, pb % MOD]
ans = (wb[0][0] + wb[0][1]) % MOD
print(ans)
stdout.close()
if __name__ == "__main__":
main()
| false | 17.307692 |
[
"-",
"- def dfs(node, prnt):",
"- w, b = 1, 1",
"- for nbhr in G[node]:",
"- if nbhr == prnt:",
"- continue",
"- nw, nb = dfs(nbhr, node)",
"- w *= nw + nb",
"- w %= MOD",
"- b *= nw",
"- b %= MOD",
"- return w, b",
"-",
"- answ, ansb = dfs(0, -1)",
"- print(((answ + ansb) % MOD))",
"+ wb = [[1, 1] for _ in range(n + 1)]",
"+ wb[n] = [0, 0]",
"+ seen = [0 for _ in range(n)]",
"+ stack = []",
"+ stack.append((0, n))",
"+ while stack:",
"+ node, prnt = stack.pop()",
"+ w, b = wb[node]",
"+ if not seen[node]:",
"+ seen[node] = 1",
"+ stack.append((node, prnt))",
"+ for nbhr in G[node]:",
"+ if nbhr == prnt:",
"+ continue",
"+ stack.append((nbhr, node))",
"+ else:",
"+ pw, pb = wb[prnt]",
"+ pw *= w + b",
"+ pb *= w",
"+ wb[prnt] = [pw % MOD, pb % MOD]",
"+ ans = (wb[0][0] + wb[0][1]) % MOD",
"+ print(ans)"
] | false | 0.048036 | 0.048413 | 0.99221 |
[
"s882781448",
"s126305967"
] |
u393253137
|
p03292
|
python
|
s526611136
|
s096304503
| 20 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 15 |
a,b,c=sorted(map(int,input().split()))
print((c-a))
|
A=list(map(int,input().split()))
print((max(A)-min(A)))
| 2 | 2 | 50 | 54 |
a, b, c = sorted(map(int, input().split()))
print((c - a))
|
A = list(map(int, input().split()))
print((max(A) - min(A)))
| false | 0 |
[
"-a, b, c = sorted(map(int, input().split()))",
"-print((c - a))",
"+A = list(map(int, input().split()))",
"+print((max(A) - min(A)))"
] | false | 0.039614 | 0.039733 | 0.996995 |
[
"s526611136",
"s096304503"
] |
u646264672
|
p03597
|
python
|
s264475148
|
s304716834
| 20 | 17 | 3,316 | 2,940 |
Accepted
|
Accepted
| 15 |
N=int(eval(input()))
A=int(eval(input()))
print((N**2-A))
|
n=int(eval(input()))
a=int(eval(input()))
print((n*n-a))
| 3 | 3 | 45 | 45 |
N = int(eval(input()))
A = int(eval(input()))
print((N**2 - A))
|
n = int(eval(input()))
a = int(eval(input()))
print((n * n - a))
| false | 0 |
[
"-N = int(eval(input()))",
"-A = int(eval(input()))",
"-print((N**2 - A))",
"+n = int(eval(input()))",
"+a = int(eval(input()))",
"+print((n * n - a))"
] | false | 0.049222 | 0.051156 | 0.962192 |
[
"s264475148",
"s304716834"
] |
u562016607
|
p02815
|
python
|
s732101698
|
s989242117
| 708 | 549 | 25,508 | 31,624 |
Accepted
|
Accepted
| 22.46 |
N=int(eval(input()))
c=sorted([int(i) for i in input().split()])
mod=10**9+7
ans=0
for i in range(N):
ans+=(c[i]*(((N-i+1)*pow(2,(N-2)%(mod-1),mod))%mod))%mod
ans%=mod
print(((ans*pow(2,N,mod))%mod))
|
N=int(eval(input()))
c=list(map(int,input().split()))
c.sort()
m=10**9+7
ans=0
for i in range(N):
ans+=(c[i]*(N-i+1)*pow(2,(N-2)%(m-1),m))%m
print(((ans*pow(2,N,m))%m))
| 8 | 8 | 206 | 171 |
N = int(eval(input()))
c = sorted([int(i) for i in input().split()])
mod = 10**9 + 7
ans = 0
for i in range(N):
ans += (c[i] * (((N - i + 1) * pow(2, (N - 2) % (mod - 1), mod)) % mod)) % mod
ans %= mod
print(((ans * pow(2, N, mod)) % mod))
|
N = int(eval(input()))
c = list(map(int, input().split()))
c.sort()
m = 10**9 + 7
ans = 0
for i in range(N):
ans += (c[i] * (N - i + 1) * pow(2, (N - 2) % (m - 1), m)) % m
print(((ans * pow(2, N, m)) % m))
| false | 0 |
[
"-c = sorted([int(i) for i in input().split()])",
"-mod = 10**9 + 7",
"+c = list(map(int, input().split()))",
"+c.sort()",
"+m = 10**9 + 7",
"- ans += (c[i] * (((N - i + 1) * pow(2, (N - 2) % (mod - 1), mod)) % mod)) % mod",
"- ans %= mod",
"-print(((ans * pow(2, N, mod)) % mod))",
"+ ans += (c[i] * (N - i + 1) * pow(2, (N - 2) % (m - 1), m)) % m",
"+print(((ans * pow(2, N, m)) % m))"
] | false | 0.038661 | 0.040853 | 0.946347 |
[
"s732101698",
"s989242117"
] |
u768256617
|
p03160
|
python
|
s681310592
|
s596050196
| 141 | 128 | 13,980 | 13,928 |
Accepted
|
Accepted
| 9.22 |
n=int(eval(input()))
h=list(map(int,input().split()))
dp=[float('inf')]*(n+1)
dp[1]=0
dp[0]=0
dp[2]=dp[1]+abs(h[1]-h[0])
for i in range(1,n-1):
dp[i+2]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i]+abs(h[i+1]-h[i-1]))
print((dp[n]))
|
n=int(eval(input()))
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
#print(dp)
print((dp[n-1]))
| 11 | 11 | 229 | 222 |
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf")] * (n + 1)
dp[1] = 0
dp[0] = 0
dp[2] = dp[1] + abs(h[1] - h[0])
for i in range(1, n - 1):
dp[i + 2] = min(dp[i + 1] + abs(h[i + 1] - h[i]), dp[i] + abs(h[i + 1] - h[i - 1]))
print((dp[n]))
|
n = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
# print(dp)
print((dp[n - 1]))
| false | 0 |
[
"-dp = [float(\"inf\")] * (n + 1)",
"-dp[1] = 0",
"+dp = [float(\"inf\")] * n",
"-dp[2] = dp[1] + abs(h[1] - h[0])",
"-for i in range(1, n - 1):",
"- dp[i + 2] = min(dp[i + 1] + abs(h[i + 1] - h[i]), dp[i] + abs(h[i + 1] - h[i - 1]))",
"-print((dp[n]))",
"+dp[1] = abs(h[1] - h[0])",
"+for i in range(2, n):",
"+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"+# print(dp)",
"+print((dp[n - 1]))"
] | false | 0.035924 | 0.054227 | 0.662476 |
[
"s681310592",
"s596050196"
] |
u532022710
|
p02911
|
python
|
s189626264
|
s283023949
| 249 | 152 | 10,448 | 10,444 |
Accepted
|
Accepted
| 38.96 |
n, k, q = list(map(int, input().split()))
q_list = [int(eval(input())) for i in range(q)]
arr = [k - q] * n
for q_i in q_list:
arr[q_i - 1] += 1
for go_or_not in arr:
if go_or_not > 0:
print("Yes")
else:
print("No")
|
#!/usr/bin/env python3
import sys
def solve(N: int, K: int, Q: int, A: "List[int]"):
arr = [K - Q] * N
for a in A:
arr[a - 1] += 1
for go_or_not in arr:
if go_or_not > 0:
print("Yes")
else:
print("No")
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
Q = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(Q)] # type: "List[int]"
solve(N, K, Q, A)
if __name__ == "__main__":
main()
| 13 | 36 | 247 | 727 |
n, k, q = list(map(int, input().split()))
q_list = [int(eval(input())) for i in range(q)]
arr = [k - q] * n
for q_i in q_list:
arr[q_i - 1] += 1
for go_or_not in arr:
if go_or_not > 0:
print("Yes")
else:
print("No")
|
#!/usr/bin/env python3
import sys
def solve(N: int, K: int, Q: int, A: "List[int]"):
arr = [K - Q] * N
for a in A:
arr[a - 1] += 1
for go_or_not in arr:
if go_or_not > 0:
print("Yes")
else:
print("No")
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
Q = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(Q)] # type: "List[int]"
solve(N, K, Q, A)
if __name__ == "__main__":
main()
| false | 63.888889 |
[
"-n, k, q = list(map(int, input().split()))",
"-q_list = [int(eval(input())) for i in range(q)]",
"-arr = [k - q] * n",
"-for q_i in q_list:",
"- arr[q_i - 1] += 1",
"-for go_or_not in arr:",
"- if go_or_not > 0:",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"+#!/usr/bin/env python3",
"+import sys",
"+",
"+",
"+def solve(N: int, K: int, Q: int, A: \"List[int]\"):",
"+ arr = [K - Q] * N",
"+ for a in A:",
"+ arr[a - 1] += 1",
"+ for go_or_not in arr:",
"+ if go_or_not > 0:",
"+ print(\"Yes\")",
"+ else:",
"+ print(\"No\")",
"+ return",
"+",
"+",
"+def main():",
"+ def iterate_tokens():",
"+ for line in sys.stdin:",
"+ for word in line.split():",
"+ yield word",
"+",
"+ tokens = iterate_tokens()",
"+ N = int(next(tokens)) # type: int",
"+ K = int(next(tokens)) # type: int",
"+ Q = int(next(tokens)) # type: int",
"+ A = [int(next(tokens)) for _ in range(Q)] # type: \"List[int]\"",
"+ solve(N, K, Q, A)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.079913 | 0.104585 | 0.764094 |
[
"s189626264",
"s283023949"
] |
u638282348
|
p02696
|
python
|
s395056518
|
s395442430
| 22 | 20 | 9,104 | 9,104 |
Accepted
|
Accepted
| 9.09 |
A, B, N = list(map(int, input().split()))
print(((lambda x: int(A * x / B) - A * int(x / B))(min(B - 1, N))))
|
print(((lambda a, b, n: a * min(b - 1, n) // b - min(b - 1, n) // b * a)(*list(map(int, input().split())))))
| 2 | 1 | 103 | 101 |
A, B, N = list(map(int, input().split()))
print(((lambda x: int(A * x / B) - A * int(x / B))(min(B - 1, N))))
|
print(
(
(lambda a, b, n: a * min(b - 1, n) // b - min(b - 1, n) // b * a)(
*list(map(int, input().split()))
)
)
)
| false | 50 |
[
"-A, B, N = list(map(int, input().split()))",
"-print(((lambda x: int(A * x / B) - A * int(x / B))(min(B - 1, N))))",
"+print(",
"+ (",
"+ (lambda a, b, n: a * min(b - 1, n) // b - min(b - 1, n) // b * a)(",
"+ *list(map(int, input().split()))",
"+ )",
"+ )",
"+)"
] | false | 0.043643 | 0.048038 | 0.908505 |
[
"s395056518",
"s395442430"
] |
u179169725
|
p02883
|
python
|
s402453744
|
s122475622
| 1,156 | 496 | 106,956 | 106,956 |
Accepted
|
Accepted
| 57.09 |
# https://atcoder.jp/contests/abc144/tasks/abc144_e
# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる
# 求めたいのは最大値!
# 最小はxにできると仮定してみる?
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort() # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)]) # ここから崩すことができるポイントを探せる
from math import ceil
def is_ok(x, K):
for i in range(N):
if A[i] * F[i] <= x:
continue
a = ceil(A[i] - x / F[i]) # Kから使うべき個数
K -= a
if K < 0:
return False
return K > -1
def meguru_bisect(ng, ok):
'''
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid, K):
ok = mid
else:
ng = mid
return ok
print((meguru_bisect(-1, 10**12 + 1)))
|
# https://atcoder.jp/contests/abc144/tasks/abc144_e
# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる
# 求めたいのは最大値!
# 最小はxにできると仮定してみる?
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort() # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)]) # ここから崩すことができるポイントを探せる
def is_ok(x, K):
for i in range(N):
if A[i] * F[i] <= x:
continue
a = A[i] - (x // F[i]) # Kから使うべき個数
K -= a
if K < 0:
return False
return K > -1
def meguru_bisect(ng, ok):
'''
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid, K):
ok = mid
else:
ng = mid
return ok
print((meguru_bisect(-1, 10**12 + 1)))
| 61 | 59 | 1,224 | 1,196 |
# https://atcoder.jp/contests/abc144/tasks/abc144_e
# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる
# 求めたいのは最大値!
# 最小はxにできると仮定してみる?
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort() # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)]) # ここから崩すことができるポイントを探せる
from math import ceil
def is_ok(x, K):
for i in range(N):
if A[i] * F[i] <= x:
continue
a = ceil(A[i] - x / F[i]) # Kから使うべき個数
K -= a
if K < 0:
return False
return K > -1
def meguru_bisect(ng, ok):
"""
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
"""
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid, K):
ok = mid
else:
ng = mid
return ok
print((meguru_bisect(-1, 10**12 + 1)))
|
# https://atcoder.jp/contests/abc144/tasks/abc144_e
# 修行を行わないときに最適なのは両方を逆順でソートしておくこと
# そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので
# greedyにKをみたすまで引いてあげる
# 求めたいのは最大値!
# 最小はxにできると仮定してみる?
# 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
N, K = read_ints()
A = read_ints()
F = read_ints()
A.sort() # 前からFの大きい順に対処していく人になっている
F.sort(reverse=True)
# print(A)
# print([x * y for x, y in zip(A, F)]) # ここから崩すことができるポイントを探せる
def is_ok(x, K):
for i in range(N):
if A[i] * F[i] <= x:
continue
a = A[i] - (x // F[i]) # Kから使うべき個数
K -= a
if K < 0:
return False
return K > -1
def meguru_bisect(ng, ok):
"""
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
"""
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid, K):
ok = mid
else:
ng = mid
return ok
print((meguru_bisect(-1, 10**12 + 1)))
| false | 3.278689 |
[
"-from math import ceil",
"-",
"-",
"- a = ceil(A[i] - x / F[i]) # Kから使うべき個数",
"+ a = A[i] - (x // F[i]) # Kから使うべき個数"
] | false | 0.063942 | 0.113861 | 0.561582 |
[
"s402453744",
"s122475622"
] |
u684241248
|
p02241
|
python
|
s380781427
|
s228960811
| 300 | 20 | 6,868 | 6,464 |
Accepted
|
Accepted
| 93.33 |
# -*- coding: utf-8 -*-
def prim(edges, *, start=0, adj_matrix=False, default_value=float('inf')):
'''
Returns the Minimum Spanning Tree(MST) of a given graph
# sample input when given not as adjacency list (generally works faster)
edges = [[(1, 2), (2, 5), (3, 4)], # node 0
[(0, 2), (3, 3), (4, 6)], # node 1
[(0, 5), (3, 2), (5, 6)], # node 2
[(0, 4), (1, 3), (2, 2), (4, 2)], # node 3
[(1, 6), (3, 2), (5, 4)], # node 4
[(2, 6), (4, 4)]] # node 5
# sample input when given as adjacency matrix
edges = [[0, 2, 5, 4, inf, inf], # node 0
[2, 0, inf, 3, 6, inf], # node 1
[5, inf, 0, 2, inf, 6], # node 2
[4, 3, 2, 0, 2, inf], # node 3
[inf, 6, inf, 2, 0, 4], # node 4
[inf, inf, 6, inf, 4, 0]] # node 5
'''
n = len(edges)
mst = []
cost = 0
T = [start]
while True:
tmp_edges = [(cost, (u, v)) for u in T for v, cost in enumerate(edges[u]) if cost != default_value and v not in T] if adj_matrix else\
[(cost, (u, v)) for u in T for v, cost in edges[u] if v not in T]
if tmp_edges:
min_cost, min_edge = min(tmp_edges)
mst.append(min_edge)
cost += min_cost
T.append(min_edge[1])
else:
if len(mst) != n - 1:
raise NoSpanningError(
'There is no spanning tree in this graph (search started from node{})'.
format(start))
else:
return mst, cost
class NoSpanningError(Exception):
pass
if __name__ == '__main__':
'''
an example of using this function
AIZU ONLINE JUDGE - ALDS_1_12_A
'''
n = int(input())
edges = [[(j, int(cost)) for j, cost in enumerate(input().split()) if int(cost) != -1] for i in range(n)]
print(prim(edges)[1])
|
# -*- coding: utf-8 -*-
from heapq import heappop, heappush
def prim(edges, *, start=0, adj_matrix=False, default_value=float('inf')):
'''
Returns the Minimum Spanning Tree(MST) of a given graph
# sample input when given not as adjacency list (adj_matrix=False) (generally works faster)
edges = [[(1, 2), (2, 5), (3, 4)], # node 0
[(0, 2), (3, 3), (4, 6)], # node 1
[(0, 5), (3, 2), (5, 6)], # node 2
[(0, 4), (1, 3), (2, 2), (4, 2)], # node 3
[(1, 6), (3, 2), (5, 4)], # node 4
[(2, 6), (4, 4)]] # node 5
# sample input when given as adjacency matrix (adj_matrix=True)
edges = [[0, 2, 5, 4, inf, inf], # node 0
[2, 0, inf, 3, 6, inf], # node 1
[5, inf, 0, 2, inf, 6], # node 2
[4, 3, 2, 0, 2, inf], # node 3
[inf, 6, inf, 2, 0, 4], # node 4
[inf, inf, 6, inf, 4, 0]] # node 5
'''
n = len(edges)
costs = [float('inf')] * n
costs[start] = 0
prevs = [-1] * n
pq = [(0, start)]
T = [True] * n
while pq:
tmp_cost, tmp_node = heappop(pq)
T[tmp_node] = False
nxt_edges = ((node, cost) for node, cost in enumerate(edges[tmp_node]) if cost != default_value and T[node]) if adj_matrix else\
((node, cost) for node, cost in edges[tmp_node] if T[node])
for nxt_node, nxt_cost in nxt_edges:
if costs[nxt_node] > nxt_cost:
costs[nxt_node] = nxt_cost
prevs[nxt_node] = tmp_node
heappush(pq, (nxt_cost, nxt_node))
T[nxt_node] = True
else:
if len([prev for prev in prevs if prev != -1]) != n - 1:
raise NoSpanningError(
'There is no spanning tree in this graph (search started from node{})'.
format(start))
else:
return prevs, costs
class NoSpanningError(Exception):
pass
if __name__ == '__main__':
'''
an example of using this function
AIZU ONLINE JUDGE - ALDS_1_12_A
'''
n = int(input())
edges = [[(j, int(cost)) for j, cost in enumerate(input().split())
if int(cost) != -1] for i in range(n)]
prevs, costs = prim(edges)
print(sum(costs))
| 62 | 75 | 2,103 | 2,466 |
# -*- coding: utf-8 -*-
def prim(edges, *, start=0, adj_matrix=False, default_value=float("inf")):
"""
Returns the Minimum Spanning Tree(MST) of a given graph
# sample input when given not as adjacency list (generally works faster)
edges = [[(1, 2), (2, 5), (3, 4)], # node 0
[(0, 2), (3, 3), (4, 6)], # node 1
[(0, 5), (3, 2), (5, 6)], # node 2
[(0, 4), (1, 3), (2, 2), (4, 2)], # node 3
[(1, 6), (3, 2), (5, 4)], # node 4
[(2, 6), (4, 4)]] # node 5
# sample input when given as adjacency matrix
edges = [[0, 2, 5, 4, inf, inf], # node 0
[2, 0, inf, 3, 6, inf], # node 1
[5, inf, 0, 2, inf, 6], # node 2
[4, 3, 2, 0, 2, inf], # node 3
[inf, 6, inf, 2, 0, 4], # node 4
[inf, inf, 6, inf, 4, 0]] # node 5
"""
n = len(edges)
mst = []
cost = 0
T = [start]
while True:
tmp_edges = (
[
(cost, (u, v))
for u in T
for v, cost in enumerate(edges[u])
if cost != default_value and v not in T
]
if adj_matrix
else [(cost, (u, v)) for u in T for v, cost in edges[u] if v not in T]
)
if tmp_edges:
min_cost, min_edge = min(tmp_edges)
mst.append(min_edge)
cost += min_cost
T.append(min_edge[1])
else:
if len(mst) != n - 1:
raise NoSpanningError(
"There is no spanning tree in this graph (search started from node{})".format(
start
)
)
else:
return mst, cost
class NoSpanningError(Exception):
pass
if __name__ == "__main__":
"""
an example of using this function
AIZU ONLINE JUDGE - ALDS_1_12_A
"""
n = int(input())
edges = [
[(j, int(cost)) for j, cost in enumerate(input().split()) if int(cost) != -1]
for i in range(n)
]
print(prim(edges)[1])
|
# -*- coding: utf-8 -*-
from heapq import heappop, heappush
def prim(edges, *, start=0, adj_matrix=False, default_value=float("inf")):
"""
Returns the Minimum Spanning Tree(MST) of a given graph
# sample input when given not as adjacency list (adj_matrix=False) (generally works faster)
edges = [[(1, 2), (2, 5), (3, 4)], # node 0
[(0, 2), (3, 3), (4, 6)], # node 1
[(0, 5), (3, 2), (5, 6)], # node 2
[(0, 4), (1, 3), (2, 2), (4, 2)], # node 3
[(1, 6), (3, 2), (5, 4)], # node 4
[(2, 6), (4, 4)]] # node 5
# sample input when given as adjacency matrix (adj_matrix=True)
edges = [[0, 2, 5, 4, inf, inf], # node 0
[2, 0, inf, 3, 6, inf], # node 1
[5, inf, 0, 2, inf, 6], # node 2
[4, 3, 2, 0, 2, inf], # node 3
[inf, 6, inf, 2, 0, 4], # node 4
[inf, inf, 6, inf, 4, 0]] # node 5
"""
n = len(edges)
costs = [float("inf")] * n
costs[start] = 0
prevs = [-1] * n
pq = [(0, start)]
T = [True] * n
while pq:
tmp_cost, tmp_node = heappop(pq)
T[tmp_node] = False
nxt_edges = (
(
(node, cost)
for node, cost in enumerate(edges[tmp_node])
if cost != default_value and T[node]
)
if adj_matrix
else ((node, cost) for node, cost in edges[tmp_node] if T[node])
)
for nxt_node, nxt_cost in nxt_edges:
if costs[nxt_node] > nxt_cost:
costs[nxt_node] = nxt_cost
prevs[nxt_node] = tmp_node
heappush(pq, (nxt_cost, nxt_node))
T[nxt_node] = True
else:
if len([prev for prev in prevs if prev != -1]) != n - 1:
raise NoSpanningError(
"There is no spanning tree in this graph (search started from node{})".format(
start
)
)
else:
return prevs, costs
class NoSpanningError(Exception):
pass
if __name__ == "__main__":
"""
an example of using this function
AIZU ONLINE JUDGE - ALDS_1_12_A
"""
n = int(input())
edges = [
[(j, int(cost)) for j, cost in enumerate(input().split()) if int(cost) != -1]
for i in range(n)
]
prevs, costs = prim(edges)
print(sum(costs))
| false | 17.333333 |
[
"+from heapq import heappop, heappush",
"+",
"+",
"- # sample input when given not as adjacency list (generally works faster)",
"+ # sample input when given not as adjacency list (adj_matrix=False) (generally works faster)",
"- # sample input when given as adjacency matrix",
"+ # sample input when given as adjacency matrix (adj_matrix=True)",
"- mst = []",
"- cost = 0",
"- T = [start]",
"- while True:",
"- tmp_edges = (",
"- [",
"- (cost, (u, v))",
"- for u in T",
"- for v, cost in enumerate(edges[u])",
"- if cost != default_value and v not in T",
"- ]",
"+ costs = [float(\"inf\")] * n",
"+ costs[start] = 0",
"+ prevs = [-1] * n",
"+ pq = [(0, start)]",
"+ T = [True] * n",
"+ while pq:",
"+ tmp_cost, tmp_node = heappop(pq)",
"+ T[tmp_node] = False",
"+ nxt_edges = (",
"+ (",
"+ (node, cost)",
"+ for node, cost in enumerate(edges[tmp_node])",
"+ if cost != default_value and T[node]",
"+ )",
"- else [(cost, (u, v)) for u in T for v, cost in edges[u] if v not in T]",
"+ else ((node, cost) for node, cost in edges[tmp_node] if T[node])",
"- if tmp_edges:",
"- min_cost, min_edge = min(tmp_edges)",
"- mst.append(min_edge)",
"- cost += min_cost",
"- T.append(min_edge[1])",
"+ for nxt_node, nxt_cost in nxt_edges:",
"+ if costs[nxt_node] > nxt_cost:",
"+ costs[nxt_node] = nxt_cost",
"+ prevs[nxt_node] = tmp_node",
"+ heappush(pq, (nxt_cost, nxt_node))",
"+ T[nxt_node] = True",
"+ else:",
"+ if len([prev for prev in prevs if prev != -1]) != n - 1:",
"+ raise NoSpanningError(",
"+ \"There is no spanning tree in this graph (search started from node{})\".format(",
"+ start",
"+ )",
"+ )",
"- if len(mst) != n - 1:",
"- raise NoSpanningError(",
"- \"There is no spanning tree in this graph (search started from node{})\".format(",
"- start",
"- )",
"- )",
"- else:",
"- return mst, cost",
"+ return prevs, costs",
"- print(prim(edges)[1])",
"+ prevs, costs = prim(edges)",
"+ print(sum(costs))"
] | false | 0.039699 | 0.037822 | 1.049624 |
[
"s380781427",
"s228960811"
] |
u407160848
|
p02698
|
python
|
s998363605
|
s676889671
| 1,473 | 1,287 | 356,120 | 355,872 |
Accepted
|
Accepted
| 12.63 |
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
# def input(): return sys.stdin.readline().strip()
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
INF = 999999999999999999999999
n = int(input())
A = [-INF] + get_nums_l()
# log(n)
# log(A)
edges = [ [] for _ in range(n+1) ]
for _ in range(n-1):
#for line in map(lambda s: s.strip(), sys.stdin.readlines()):
line = input().strip()
# log(line)
u,v = map(int, line.split())
edges[u].append(v)
edges[v].append(u)
def dfs(dp, u, p=None):
# log(u)
# log(dp)
# dpの中でA[u]以上の値が入っている最小のindex
i = bisect_left(dp, A[u])
old = dp[i]
dp[i] = A[u]
# 有効値(INF以外)が入っている最大のindex
ans[u] = bisect_left(dp, INF) - 1
for v in edges[u]:
if v == p:
continue
dfs(dp, v, u)
# 巻き戻し
dp[i] = old
# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)
# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF
dfs(dp, 1, None)
for i in range(1, n+1):
print(ans[i])
|
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().strip()
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
INF = 999999999999999999999999
n = int(input())
A = [-INF] + get_nums_l()
# log(n)
# log(A)
edges = [ [] for _ in range(n+1) ]
for _ in range(n-1):
# for line in map(lambda s: s.strip(), sys.stdin.readlines()):
line = input()
# log(line)
u,v = map(int, line.split())
edges[u].append(v)
edges[v].append(u)
def dfs(dp, u, p=None):
# log(u)
# log(dp)
# dpの中でA[u]以上の値が入っている最小のindex
i = bisect_left(dp, A[u])
old = dp[i]
dp[i] = A[u]
# 有効値(INF以外)が入っている最大のindex
ans[u] = bisect_left(dp, INF) - 1
for v in edges[u]:
if v == p:
continue
dfs(dp, v, u)
# 巻き戻し
dp[i] = old
# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)
# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF
dfs(dp, 1, None)
for i in range(1, n+1):
print(ans[i])
| 64 | 64 | 1,229 | 1,220 |
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
# def input(): return sys.stdin.readline().strip()
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [int(s) for s in input().split(" ")]
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
INF = 999999999999999999999999
n = int(input())
A = [-INF] + get_nums_l()
# log(n)
# log(A)
edges = [[] for _ in range(n + 1)]
for _ in range(n - 1):
# for line in map(lambda s: s.strip(), sys.stdin.readlines()):
line = input().strip()
# log(line)
u, v = map(int, line.split())
edges[u].append(v)
edges[v].append(u)
def dfs(dp, u, p=None):
# log(u)
# log(dp)
# dpの中でA[u]以上の値が入っている最小のindex
i = bisect_left(dp, A[u])
old = dp[i]
dp[i] = A[u]
# 有効値(INF以外)が入っている最大のindex
ans[u] = bisect_left(dp, INF) - 1
for v in edges[u]:
if v == p:
continue
dfs(dp, v, u)
# 巻き戻し
dp[i] = old
# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n + 1)
# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n + 1)
dp[0] = -INF
dfs(dp, 1, None)
for i in range(1, n + 1):
print(ans[i])
|
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [int(s) for s in input().split(" ")]
def log(*args):
print("DEBUG:", *args, file=sys.stderr)
INF = 999999999999999999999999
n = int(input())
A = [-INF] + get_nums_l()
# log(n)
# log(A)
edges = [[] for _ in range(n + 1)]
for _ in range(n - 1):
# for line in map(lambda s: s.strip(), sys.stdin.readlines()):
line = input()
# log(line)
u, v = map(int, line.split())
edges[u].append(v)
edges[v].append(u)
def dfs(dp, u, p=None):
# log(u)
# log(dp)
# dpの中でA[u]以上の値が入っている最小のindex
i = bisect_left(dp, A[u])
old = dp[i]
dp[i] = A[u]
# 有効値(INF以外)が入っている最大のindex
ans[u] = bisect_left(dp, INF) - 1
for v in edges[u]:
if v == p:
continue
dfs(dp, v, u)
# 巻き戻し
dp[i] = old
# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n + 1)
# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n + 1)
dp[0] = -INF
dfs(dp, 1, None)
for i in range(1, n + 1):
print(ans[i])
| false | 0 |
[
"-# def input(): return sys.stdin.readline().strip()",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"- line = input().strip()",
"+ line = input()"
] | false | 0.07119 | 0.098159 | 0.725247 |
[
"s998363605",
"s676889671"
] |
u798557584
|
p03109
|
python
|
s472942446
|
s003551881
| 44 | 17 | 4,692 | 2,940 |
Accepted
|
Accepted
| 61.36 |
# abc119_a
from datetime import datetime
S=eval(input())
to_dt=datetime.strptime(S,'%Y/%m/%d')
# 2019/04/30
from_dt=datetime(2019,4,30)
# 2019/04/30以前であれば、"Heisei"
# 以降は"TBD"
if to_dt <= from_dt:
print("Heisei")
else:
print("TBD")
|
# abc119_a
year, month, day = list(map(int, input().split("/")))
if month <= 4:
print("Heisei")
else:
print("TBD")
"""
from datetime import datetime
S=input()
to_dt=datetime.strptime(S,'%Y/%m/%d')
# 2019/04/30
from_dt=datetime(2019,4,30)
# 2019/04/30以前であれば、"Heisei"
# 以降は"TBD"
if to_dt <= from_dt:
print("Heisei")
else:
print("TBD")
"""
| 12 | 20 | 238 | 355 |
# abc119_a
from datetime import datetime
S = eval(input())
to_dt = datetime.strptime(S, "%Y/%m/%d")
# 2019/04/30
from_dt = datetime(2019, 4, 30)
# 2019/04/30以前であれば、"Heisei"
# 以降は"TBD"
if to_dt <= from_dt:
print("Heisei")
else:
print("TBD")
|
# abc119_a
year, month, day = list(map(int, input().split("/")))
if month <= 4:
print("Heisei")
else:
print("TBD")
"""
from datetime import datetime
S=input()
to_dt=datetime.strptime(S,'%Y/%m/%d')
# 2019/04/30
from_dt=datetime(2019,4,30)
# 2019/04/30以前であれば、"Heisei"
# 以降は"TBD"
if to_dt <= from_dt:
print("Heisei")
else:
print("TBD")
"""
| false | 40 |
[
"+year, month, day = list(map(int, input().split(\"/\")))",
"+if month <= 4:",
"+ print(\"Heisei\")",
"+else:",
"+ print(\"TBD\")",
"+\"\"\"",
"-",
"-S = eval(input())",
"-to_dt = datetime.strptime(S, \"%Y/%m/%d\")",
"+S=input()",
"+to_dt=datetime.strptime(S,'%Y/%m/%d')",
"-from_dt = datetime(2019, 4, 30)",
"+from_dt=datetime(2019,4,30)",
"- print(\"Heisei\")",
"+ print(\"Heisei\")",
"- print(\"TBD\")",
"+ print(\"TBD\")",
"+\"\"\""
] | false | 0.128375 | 0.146576 | 0.875826 |
[
"s472942446",
"s003551881"
] |
u018679195
|
p04039
|
python
|
s315533372
|
s581742598
| 188 | 133 | 40,300 | 3,060 |
Accepted
|
Accepted
| 29.26 |
n, k = list(map(int, input().split()))
d = list(map(str, input().split()))
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(n, 100000):
Nums = set(str(i))
if Nums <= left:
print(i)
break
|
n,k = input().split(" ")
l = input().split(" ")
l1 = ['0','1','2','3','4','5','6','7','8','9']
d = sorted(list(set(l1)-set(l)))
i = int(n)
while(True):
if set(list(str(i))).difference(set(d))==set():
break
else:
i+=1
print(i)
| 10 | 11 | 245 | 259 |
n, k = list(map(int, input().split()))
d = list(map(str, input().split()))
digits = set(d)
num = {str(i) for i in range(0, 10)}
left = num - digits
for i in range(n, 100000):
Nums = set(str(i))
if Nums <= left:
print(i)
break
|
n, k = input().split(" ")
l = input().split(" ")
l1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
d = sorted(list(set(l1) - set(l)))
i = int(n)
while True:
if set(list(str(i))).difference(set(d)) == set():
break
else:
i += 1
print(i)
| false | 9.090909 |
[
"-n, k = list(map(int, input().split()))",
"-d = list(map(str, input().split()))",
"-digits = set(d)",
"-num = {str(i) for i in range(0, 10)}",
"-left = num - digits",
"-for i in range(n, 100000):",
"- Nums = set(str(i))",
"- if Nums <= left:",
"- print(i)",
"+n, k = input().split(\" \")",
"+l = input().split(\" \")",
"+l1 = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"]",
"+d = sorted(list(set(l1) - set(l)))",
"+i = int(n)",
"+while True:",
"+ if set(list(str(i))).difference(set(d)) == set():",
"+ else:",
"+ i += 1",
"+print(i)"
] | false | 0.037192 | 0.043367 | 0.857609 |
[
"s315533372",
"s581742598"
] |
u912237403
|
p00030
|
python
|
s018665355
|
s812818206
| 20 | 10 | 4,260 | 4,252 |
Accepted
|
Accepted
| 50 |
def dec2bin(n, base=10):
s = format(n,'b')
s = "0"*(10-len(s))+s
return s
x=[[0]*50 for i in range(11)]
for i in range(0, 2**10):
B = dec2bin(i)
s = 0
c = B.count("1")
j = 0
for e in B:
if e=="1": s+=j
j+=1
x[c][s]+=1
while 1:
n, s=list(map(int, input().split()))
if n==0 and s==0: break
if s>=50: print(0)
else: print(x[n][s])
|
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
B = format(i,'b')[::-1]
s,c,j = 0,0,0
for e in B:
if e=="1": s,c = s+j, c+1
j += 1
x[c][s]+=1
while 1:
n, s=list(map(int, input().split()))
if n==0 and s==0: break
print(0 if s>=50 else x[n][s])
| 21 | 13 | 414 | 306 |
def dec2bin(n, base=10):
s = format(n, "b")
s = "0" * (10 - len(s)) + s
return s
x = [[0] * 50 for i in range(11)]
for i in range(0, 2**10):
B = dec2bin(i)
s = 0
c = B.count("1")
j = 0
for e in B:
if e == "1":
s += j
j += 1
x[c][s] += 1
while 1:
n, s = list(map(int, input().split()))
if n == 0 and s == 0:
break
if s >= 50:
print(0)
else:
print(x[n][s])
|
x = [[0] * 50 for i in range(11)]
for i in range(0, 2**10):
B = format(i, "b")[::-1]
s, c, j = 0, 0, 0
for e in B:
if e == "1":
s, c = s + j, c + 1
j += 1
x[c][s] += 1
while 1:
n, s = list(map(int, input().split()))
if n == 0 and s == 0:
break
print(0 if s >= 50 else x[n][s])
| false | 38.095238 |
[
"-def dec2bin(n, base=10):",
"- s = format(n, \"b\")",
"- s = \"0\" * (10 - len(s)) + s",
"- return s",
"-",
"-",
"- B = dec2bin(i)",
"- s = 0",
"- c = B.count(\"1\")",
"- j = 0",
"+ B = format(i, \"b\")[::-1]",
"+ s, c, j = 0, 0, 0",
"- s += j",
"+ s, c = s + j, c + 1",
"- if s >= 50:",
"- print(0)",
"- else:",
"- print(x[n][s])",
"+ print(0 if s >= 50 else x[n][s])"
] | false | 0.042779 | 0.0435 | 0.983439 |
[
"s018665355",
"s812818206"
] |
u525065967
|
p02627
|
python
|
s285300521
|
s526037027
| 31 | 24 | 9,004 | 9,068 |
Accepted
|
Accepted
| 22.58 |
# print('a' if 'a' <= input() <= 'z' else 'A')
print((['A','a']['a' <= eval(input()) <= 'z']))
|
# print('a' if 'a' <= input() <= 'z' else 'A')
# print(['A','a']['a' <= input() <= 'z'])
print((['A','a'][input().islower()]))
| 2 | 3 | 88 | 127 |
# print('a' if 'a' <= input() <= 'z' else 'A')
print((["A", "a"]["a" <= eval(input()) <= "z"]))
|
# print('a' if 'a' <= input() <= 'z' else 'A')
# print(['A','a']['a' <= input() <= 'z'])
print((["A", "a"][input().islower()]))
| false | 33.333333 |
[
"-print(([\"A\", \"a\"][\"a\" <= eval(input()) <= \"z\"]))",
"+# print(['A','a']['a' <= input() <= 'z'])",
"+print(([\"A\", \"a\"][input().islower()]))"
] | false | 0.040888 | 0.04913 | 0.832242 |
[
"s285300521",
"s526037027"
] |
u343977188
|
p02624
|
python
|
s664438407
|
s530112890
| 1,423 | 661 | 9,052 | 108,880 |
Accepted
|
Accepted
| 53.55 |
def main(N):
x = 0
for a in range(1, N+1):
b=N//a
x += a*b*(b+1)//2
return x
N = int(eval(input()))
print((main(N)))
|
import numba
@numba.njit
def main(N):
x = 0
for a in range(1, N+1):
b=N//a
x += a*b*(b+1)//2
return x
N = int(eval(input()))
print((main(N)))
| 9 | 10 | 146 | 170 |
def main(N):
x = 0
for a in range(1, N + 1):
b = N // a
x += a * b * (b + 1) // 2
return x
N = int(eval(input()))
print((main(N)))
|
import numba
@numba.njit
def main(N):
x = 0
for a in range(1, N + 1):
b = N // a
x += a * b * (b + 1) // 2
return x
N = int(eval(input()))
print((main(N)))
| false | 10 |
[
"+import numba",
"+",
"+",
"[email protected]"
] | false | 0.007842 | 0.037595 | 0.208588 |
[
"s664438407",
"s530112890"
] |
u057109575
|
p03001
|
python
|
s013242582
|
s290415270
| 174 | 57 | 38,256 | 61,764 |
Accepted
|
Accepted
| 67.24 |
W, H, x, y = list(map(float, input().split()))
ans1 = W * H / 2
ans2 = int(W / 2 == x and H / 2 == y)
print((ans1, ans2))
|
W, H, x, y = list(map(int, input().split()))
ans0 = float(W * H) / 2
ans1 = 0
if W%2 == 0 and H%2 == 0 and W//2 == x and H//2 == y:
ans1 = 1
print((ans0, ans1))
| 4 | 9 | 117 | 172 |
W, H, x, y = list(map(float, input().split()))
ans1 = W * H / 2
ans2 = int(W / 2 == x and H / 2 == y)
print((ans1, ans2))
|
W, H, x, y = list(map(int, input().split()))
ans0 = float(W * H) / 2
ans1 = 0
if W % 2 == 0 and H % 2 == 0 and W // 2 == x and H // 2 == y:
ans1 = 1
print((ans0, ans1))
| false | 55.555556 |
[
"-W, H, x, y = list(map(float, input().split()))",
"-ans1 = W * H / 2",
"-ans2 = int(W / 2 == x and H / 2 == y)",
"-print((ans1, ans2))",
"+W, H, x, y = list(map(int, input().split()))",
"+ans0 = float(W * H) / 2",
"+ans1 = 0",
"+if W % 2 == 0 and H % 2 == 0 and W // 2 == x and H // 2 == y:",
"+ ans1 = 1",
"+print((ans0, ans1))"
] | false | 0.035701 | 0.037529 | 0.951278 |
[
"s013242582",
"s290415270"
] |
u922449550
|
p03311
|
python
|
s946011303
|
s424152660
| 212 | 185 | 27,240 | 26,708 |
Accepted
|
Accepted
| 12.74 |
import statistics
N = int(eval(input()))
A = list(map(int, input().split()))
A = [a - i for i, a in enumerate(A, 1)]
b = statistics.median(A)
ans = int(sum([abs(a-b) for a in A]))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted([a - i for i, a in enumerate(A, 1)])
b = A[(N - 1)//2]
ans = sum([abs(a-b) for a in A])
print(ans)
| 9 | 7 | 194 | 169 |
import statistics
N = int(eval(input()))
A = list(map(int, input().split()))
A = [a - i for i, a in enumerate(A, 1)]
b = statistics.median(A)
ans = int(sum([abs(a - b) for a in A]))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted([a - i for i, a in enumerate(A, 1)])
b = A[(N - 1) // 2]
ans = sum([abs(a - b) for a in A])
print(ans)
| false | 22.222222 |
[
"-import statistics",
"-",
"-A = [a - i for i, a in enumerate(A, 1)]",
"-b = statistics.median(A)",
"-ans = int(sum([abs(a - b) for a in A]))",
"+A = sorted([a - i for i, a in enumerate(A, 1)])",
"+b = A[(N - 1) // 2]",
"+ans = sum([abs(a - b) for a in A])"
] | false | 0.062221 | 0.112643 | 0.552372 |
[
"s946011303",
"s424152660"
] |
u130900604
|
p02753
|
python
|
s353847174
|
s155671695
| 37 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 54.05 |
s=list(eval(input()))
if len(set(s))==2:
print("Yes")
else:
print("No")
|
if eval(input()) in ["AAA","BBB"]:
print("No")
else:
print("Yes")
| 5 | 4 | 78 | 66 |
s = list(eval(input()))
if len(set(s)) == 2:
print("Yes")
else:
print("No")
|
if eval(input()) in ["AAA", "BBB"]:
print("No")
else:
print("Yes")
| false | 20 |
[
"-s = list(eval(input()))",
"-if len(set(s)) == 2:",
"+if eval(input()) in [\"AAA\", \"BBB\"]:",
"+ print(\"No\")",
"+else:",
"-else:",
"- print(\"No\")"
] | false | 0.037245 | 0.037671 | 0.988686 |
[
"s353847174",
"s155671695"
] |
u352394527
|
p00112
|
python
|
s481430013
|
s015881770
| 110 | 100 | 5,720 | 6,152 |
Accepted
|
Accepted
| 9.09 |
while True:
n = int(eval(input()))
if not n:
break
else:
lst = [int(eval(input())) for _ in range(n)]
lst.sort()
acc = ans = 0
for i in lst:
ans += acc
acc += i
print(ans)
|
while True:
n = int(eval(input()))
if not n:
break
lst = sorted([int(eval(input())) for _ in range(n)])
print((sum([(n - i - 1) * lst[i] for i in range(n)])))
| 12 | 6 | 214 | 162 |
while True:
n = int(eval(input()))
if not n:
break
else:
lst = [int(eval(input())) for _ in range(n)]
lst.sort()
acc = ans = 0
for i in lst:
ans += acc
acc += i
print(ans)
|
while True:
n = int(eval(input()))
if not n:
break
lst = sorted([int(eval(input())) for _ in range(n)])
print((sum([(n - i - 1) * lst[i] for i in range(n)])))
| false | 50 |
[
"- else:",
"- lst = [int(eval(input())) for _ in range(n)]",
"- lst.sort()",
"- acc = ans = 0",
"- for i in lst:",
"- ans += acc",
"- acc += i",
"- print(ans)",
"+ lst = sorted([int(eval(input())) for _ in range(n)])",
"+ print((sum([(n - i - 1) * lst[i] for i in range(n)])))"
] | false | 0.039129 | 0.135688 | 0.288377 |
[
"s481430013",
"s015881770"
] |
u428132025
|
p02796
|
python
|
s845116050
|
s478962289
| 502 | 363 | 23,276 | 23,272 |
Accepted
|
Accepted
| 27.69 |
import sys
n = int(eval(input()))
info = [0] * n
for i in range(n):
x, l = list(map(int, input().split()))
info[i] = [x+l, x, l]
info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
if right <= info[i][1] - info[i][2]:
ans += 1
right = info[i][1] + info[i][2]
print(ans)
|
import sys
input = sys.stdin.readline
n = int(eval(input()))
info = [0] * n
for i in range(n):
x, l = list(map(int, input().split()))
info[i] = [x+l, x, l]
info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
if right <= info[i][1] - info[i][2]:
ans += 1
right = info[i][1] + info[i][2]
print(ans)
| 15 | 16 | 322 | 350 |
import sys
n = int(eval(input()))
info = [0] * n
for i in range(n):
x, l = list(map(int, input().split()))
info[i] = [x + l, x, l]
info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
if right <= info[i][1] - info[i][2]:
ans += 1
right = info[i][1] + info[i][2]
print(ans)
|
import sys
input = sys.stdin.readline
n = int(eval(input()))
info = [0] * n
for i in range(n):
x, l = list(map(int, input().split()))
info[i] = [x + l, x, l]
info.sort()
ans = 1
right = info[0][1] + info[0][2]
for i in range(1, n):
if right <= info[i][1] - info[i][2]:
ans += 1
right = info[i][1] + info[i][2]
print(ans)
| false | 6.25 |
[
"+input = sys.stdin.readline"
] | false | 0.122301 | 0.167359 | 0.730773 |
[
"s845116050",
"s478962289"
] |
u396211450
|
p03862
|
python
|
s741437125
|
s078074661
| 146 | 99 | 20,100 | 19,980 |
Accepted
|
Accepted
| 32.19 |
N,X=(int(T) for T in input().split())
A=list(map(int,input().split()))
ans=0
for i in range(0,N-1):
if A[i]+A[i+1]>X:
s=A[i]+A[i+1]-X
ans=s+ans
A[i]=A[i]-max(0,A[i]-A[i+1])
A[i+1]=max(0,A[i+1]-s)
print(ans)
|
N,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
for i in range(1,N):
tmp=a[i-1]+a[i]
if tmp>x:
ans+=tmp-x
if a[i]>=tmp-x:
a[i]-=tmp-x
else:
a[i]=0
print(ans)
| 10 | 12 | 252 | 245 |
N, X = (int(T) for T in input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(0, N - 1):
if A[i] + A[i + 1] > X:
s = A[i] + A[i + 1] - X
ans = s + ans
A[i] = A[i] - max(0, A[i] - A[i + 1])
A[i + 1] = max(0, A[i + 1] - s)
print(ans)
|
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, N):
tmp = a[i - 1] + a[i]
if tmp > x:
ans += tmp - x
if a[i] >= tmp - x:
a[i] -= tmp - x
else:
a[i] = 0
print(ans)
| false | 16.666667 |
[
"-N, X = (int(T) for T in input().split())",
"-A = list(map(int, input().split()))",
"+N, x = list(map(int, input().split()))",
"+a = list(map(int, input().split()))",
"-for i in range(0, N - 1):",
"- if A[i] + A[i + 1] > X:",
"- s = A[i] + A[i + 1] - X",
"- ans = s + ans",
"- A[i] = A[i] - max(0, A[i] - A[i + 1])",
"- A[i + 1] = max(0, A[i + 1] - s)",
"+for i in range(1, N):",
"+ tmp = a[i - 1] + a[i]",
"+ if tmp > x:",
"+ ans += tmp - x",
"+ if a[i] >= tmp - x:",
"+ a[i] -= tmp - x",
"+ else:",
"+ a[i] = 0"
] | false | 0.07602 | 0.03437 | 2.211811 |
[
"s741437125",
"s078074661"
] |
u626228246
|
p02717
|
python
|
s570911762
|
s210534344
| 25 | 22 | 9,064 | 9,096 |
Accepted
|
Accepted
| 12 |
import sys
#readline = sys.stdin.readline()
A,B,C = list(map(int,input().split()))
print((C,A,B))
|
X,Y,Z = list(map(int,input().split()))
print((Z,X,Y))
| 4 | 2 | 92 | 46 |
import sys
# readline = sys.stdin.readline()
A, B, C = list(map(int, input().split()))
print((C, A, B))
|
X, Y, Z = list(map(int, input().split()))
print((Z, X, Y))
| false | 50 |
[
"-import sys",
"-",
"-# readline = sys.stdin.readline()",
"-A, B, C = list(map(int, input().split()))",
"-print((C, A, B))",
"+X, Y, Z = list(map(int, input().split()))",
"+print((Z, X, Y))"
] | false | 0.008354 | 0.03268 | 0.255623 |
[
"s570911762",
"s210534344"
] |
u141610915
|
p03862
|
python
|
s926521997
|
s144976992
| 227 | 90 | 59,632 | 84,728 |
Accepted
|
Accepted
| 60.35 |
import sys
input = sys.stdin.readline
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(1, N):
if a[i - 1] + a[i] > x:
t = a[i - 1] + a[i] - x
res += t
if t > a[i]:
t -= a[i]
a[i] = 0
a[i - 1] -= t
else:
a[i] -= t
print(res)
|
import sys
input = sys.stdin.readline
N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(N - 1):
if a[i] + a[i + 1] > X:
if a[i] <= X:
res += a[i] + a[i + 1] - X
a[i + 1] -= a[i] + a[i + 1] - X
else:
res += a[i] + a[i + 1] - X
a[i + 1] = 0
print(res)
| 16 | 14 | 323 | 338 |
import sys
input = sys.stdin.readline
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(1, N):
if a[i - 1] + a[i] > x:
t = a[i - 1] + a[i] - x
res += t
if t > a[i]:
t -= a[i]
a[i] = 0
a[i - 1] -= t
else:
a[i] -= t
print(res)
|
import sys
input = sys.stdin.readline
N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
res = 0
for i in range(N - 1):
if a[i] + a[i + 1] > X:
if a[i] <= X:
res += a[i] + a[i + 1] - X
a[i + 1] -= a[i] + a[i + 1] - X
else:
res += a[i] + a[i + 1] - X
a[i + 1] = 0
print(res)
| false | 12.5 |
[
"-N, x = list(map(int, input().split()))",
"+N, X = list(map(int, input().split()))",
"-for i in range(1, N):",
"- if a[i - 1] + a[i] > x:",
"- t = a[i - 1] + a[i] - x",
"- res += t",
"- if t > a[i]:",
"- t -= a[i]",
"- a[i] = 0",
"- a[i - 1] -= t",
"+for i in range(N - 1):",
"+ if a[i] + a[i + 1] > X:",
"+ if a[i] <= X:",
"+ res += a[i] + a[i + 1] - X",
"+ a[i + 1] -= a[i] + a[i + 1] - X",
"- a[i] -= t",
"+ res += a[i] + a[i + 1] - X",
"+ a[i + 1] = 0"
] | false | 0.04647 | 0.038014 | 1.222431 |
[
"s926521997",
"s144976992"
] |
u941407962
|
p02834
|
python
|
s310898892
|
s411437146
| 801 | 486 | 118,688 | 94,128 |
Accepted
|
Accepted
| 39.33 |
import copy
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
N,U,V = list(map(int, input().split()))
d = [set() for _ in range(N+1)]
dps = [0 for _ in range(N+1)]
dpss = [0 for _ in range(N+1)]
vs = set()
r = {}
def it(v, p, depth, ps):
for u in d[v]:
if u == p:
continue
dps[u] = depth
if u == V:
r["p"] = copy.deepcopy(ps)
continue
ps.add(u)
it(u, v, depth+1,ps)
ps.remove(u)
vs.add(u)
def it2(v, p, depth):
for u in d[v]:
if u == p:
continue
if u not in vs:
continue
if dps[v] >= depth-1 and u not in r["p"]:
continue
dpss[u] = depth
it2(u, v, depth+1)
for _ in range(N-1):
a, b = [int(x) for x in input().split()]
d[a].add(b)
d[b].add(a)
vs.add(U)
it(U, -1, 1, set([U]))
it2(V, -1, 1)
print((max(dpss)-1))
|
import sys
input = sys.stdin.readline
N,U,V = list(map(int, input().split()))
d = [set() for _ in range(N+1)]
dps = [0 for _ in range(N+1)]
dpss = [0 for _ in range(N+1)]
oks = set()
def it(v):
stack = [v]
vs = set()
path = []
while True:
if not len(stack):
break
v = stack.pop()
if v > 0:
path.append(v)
vs.add(v)
for u in d[v]:
if u in vs:
continue
if u == V:
r = path[:]
continue
dps[u] = dps[v] + 1
oks.add(u)
stack.append(-v)
stack.append(u)
else:
path.pop()
return r
def it2(v, path):
stack = [v]
vs = set()
while True:
if not len(stack):
break
v = stack.pop()
vs.add(v)
for u in d[v]:
if u in vs:
continue
if u not in oks:
continue
if dps[v] >= dpss[v] and u not in path:
continue
dpss[u] = dpss[v] + 1
stack.append(u)
for _ in range(N-1):
a, b = [int(x) for x in input().split()]
d[a].add(b)
d[b].add(a)
oks.add(U)
path = set(it(U))
it2(V, path)
print((max(dpss)-1))
| 47 | 60 | 962 | 1,374 |
import copy
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
N, U, V = list(map(int, input().split()))
d = [set() for _ in range(N + 1)]
dps = [0 for _ in range(N + 1)]
dpss = [0 for _ in range(N + 1)]
vs = set()
r = {}
def it(v, p, depth, ps):
for u in d[v]:
if u == p:
continue
dps[u] = depth
if u == V:
r["p"] = copy.deepcopy(ps)
continue
ps.add(u)
it(u, v, depth + 1, ps)
ps.remove(u)
vs.add(u)
def it2(v, p, depth):
for u in d[v]:
if u == p:
continue
if u not in vs:
continue
if dps[v] >= depth - 1 and u not in r["p"]:
continue
dpss[u] = depth
it2(u, v, depth + 1)
for _ in range(N - 1):
a, b = [int(x) for x in input().split()]
d[a].add(b)
d[b].add(a)
vs.add(U)
it(U, -1, 1, set([U]))
it2(V, -1, 1)
print((max(dpss) - 1))
|
import sys
input = sys.stdin.readline
N, U, V = list(map(int, input().split()))
d = [set() for _ in range(N + 1)]
dps = [0 for _ in range(N + 1)]
dpss = [0 for _ in range(N + 1)]
oks = set()
def it(v):
stack = [v]
vs = set()
path = []
while True:
if not len(stack):
break
v = stack.pop()
if v > 0:
path.append(v)
vs.add(v)
for u in d[v]:
if u in vs:
continue
if u == V:
r = path[:]
continue
dps[u] = dps[v] + 1
oks.add(u)
stack.append(-v)
stack.append(u)
else:
path.pop()
return r
def it2(v, path):
stack = [v]
vs = set()
while True:
if not len(stack):
break
v = stack.pop()
vs.add(v)
for u in d[v]:
if u in vs:
continue
if u not in oks:
continue
if dps[v] >= dpss[v] and u not in path:
continue
dpss[u] = dpss[v] + 1
stack.append(u)
for _ in range(N - 1):
a, b = [int(x) for x in input().split()]
d[a].add(b)
d[b].add(a)
oks.add(U)
path = set(it(U))
it2(V, path)
print((max(dpss) - 1))
| false | 21.666667 |
[
"-import copy",
"-sys.setrecursionlimit(100000)",
"-vs = set()",
"-r = {}",
"+oks = set()",
"-def it(v, p, depth, ps):",
"- for u in d[v]:",
"- if u == p:",
"- continue",
"- dps[u] = depth",
"- if u == V:",
"- r[\"p\"] = copy.deepcopy(ps)",
"- continue",
"- ps.add(u)",
"- it(u, v, depth + 1, ps)",
"- ps.remove(u)",
"- vs.add(u)",
"+def it(v):",
"+ stack = [v]",
"+ vs = set()",
"+ path = []",
"+ while True:",
"+ if not len(stack):",
"+ break",
"+ v = stack.pop()",
"+ if v > 0:",
"+ path.append(v)",
"+ vs.add(v)",
"+ for u in d[v]:",
"+ if u in vs:",
"+ continue",
"+ if u == V:",
"+ r = path[:]",
"+ continue",
"+ dps[u] = dps[v] + 1",
"+ oks.add(u)",
"+ stack.append(-v)",
"+ stack.append(u)",
"+ else:",
"+ path.pop()",
"+ return r",
"-def it2(v, p, depth):",
"- for u in d[v]:",
"- if u == p:",
"- continue",
"- if u not in vs:",
"- continue",
"- if dps[v] >= depth - 1 and u not in r[\"p\"]:",
"- continue",
"- dpss[u] = depth",
"- it2(u, v, depth + 1)",
"+def it2(v, path):",
"+ stack = [v]",
"+ vs = set()",
"+ while True:",
"+ if not len(stack):",
"+ break",
"+ v = stack.pop()",
"+ vs.add(v)",
"+ for u in d[v]:",
"+ if u in vs:",
"+ continue",
"+ if u not in oks:",
"+ continue",
"+ if dps[v] >= dpss[v] and u not in path:",
"+ continue",
"+ dpss[u] = dpss[v] + 1",
"+ stack.append(u)",
"-vs.add(U)",
"-it(U, -1, 1, set([U]))",
"-it2(V, -1, 1)",
"+oks.add(U)",
"+path = set(it(U))",
"+it2(V, path)"
] | false | 0.061666 | 0.041519 | 1.485246 |
[
"s310898892",
"s411437146"
] |
u474561976
|
p02726
|
python
|
s876948018
|
s797558452
| 1,698 | 990 | 116,008 | 3,444 |
Accepted
|
Accepted
| 41.7 |
def main():
import collections
n,x,y = list(map(int,input().split(" ")))
dp = [[0]*n for i in range(n)]
for i in range(0,n):
for j in range(i+1,n):
if i < x-1:
if j < x:
dp[i][j] =dp[i][j-1] +1
if j >= x and j < y:
dp[i][j] = dp[i][x-1]+min(j-x+1,y-j)
if j >=y:
dp[i][j] = dp[i][y-1]+j-y+1
if i >= x-1 and i < y-1:
if j < y:
dp[i][j] = dp[i][x-1]+min(j-i,y-x+1-(j-i))
if j >=y:
dp[i][j] = dp[i][y-1]+j-y+1
if i >= y-1:
dp[i][j] = dp[i][j-1] + 1
dp_fl = dp[0]
for i in range(1,n):
dp_fl += dp[i]
cnts = collections.Counter(dp_fl)
for i in range(1,n):
print((cnts.get(i,0)))
main()
|
def main2():
n,x,y = list(map(int,input().split(" ")))
cnts = [0]*n
for i in range(n):
for j in range(i+1,n):
dis = min(j-i,abs(x-1-i)+1+abs(y-1-j))
cnts[dis]+=1
for i in range(1,n):
print((cnts[i]))
main2()
| 33 | 11 | 925 | 270 |
def main():
import collections
n, x, y = list(map(int, input().split(" ")))
dp = [[0] * n for i in range(n)]
for i in range(0, n):
for j in range(i + 1, n):
if i < x - 1:
if j < x:
dp[i][j] = dp[i][j - 1] + 1
if j >= x and j < y:
dp[i][j] = dp[i][x - 1] + min(j - x + 1, y - j)
if j >= y:
dp[i][j] = dp[i][y - 1] + j - y + 1
if i >= x - 1 and i < y - 1:
if j < y:
dp[i][j] = dp[i][x - 1] + min(j - i, y - x + 1 - (j - i))
if j >= y:
dp[i][j] = dp[i][y - 1] + j - y + 1
if i >= y - 1:
dp[i][j] = dp[i][j - 1] + 1
dp_fl = dp[0]
for i in range(1, n):
dp_fl += dp[i]
cnts = collections.Counter(dp_fl)
for i in range(1, n):
print((cnts.get(i, 0)))
main()
|
def main2():
n, x, y = list(map(int, input().split(" ")))
cnts = [0] * n
for i in range(n):
for j in range(i + 1, n):
dis = min(j - i, abs(x - 1 - i) + 1 + abs(y - 1 - j))
cnts[dis] += 1
for i in range(1, n):
print((cnts[i]))
main2()
| false | 66.666667 |
[
"-def main():",
"- import collections",
"-",
"+def main2():",
"- dp = [[0] * n for i in range(n)]",
"- for i in range(0, n):",
"+ cnts = [0] * n",
"+ for i in range(n):",
"- if i < x - 1:",
"- if j < x:",
"- dp[i][j] = dp[i][j - 1] + 1",
"- if j >= x and j < y:",
"- dp[i][j] = dp[i][x - 1] + min(j - x + 1, y - j)",
"- if j >= y:",
"- dp[i][j] = dp[i][y - 1] + j - y + 1",
"- if i >= x - 1 and i < y - 1:",
"- if j < y:",
"- dp[i][j] = dp[i][x - 1] + min(j - i, y - x + 1 - (j - i))",
"- if j >= y:",
"- dp[i][j] = dp[i][y - 1] + j - y + 1",
"- if i >= y - 1:",
"- dp[i][j] = dp[i][j - 1] + 1",
"- dp_fl = dp[0]",
"+ dis = min(j - i, abs(x - 1 - i) + 1 + abs(y - 1 - j))",
"+ cnts[dis] += 1",
"- dp_fl += dp[i]",
"- cnts = collections.Counter(dp_fl)",
"- for i in range(1, n):",
"- print((cnts.get(i, 0)))",
"+ print((cnts[i]))",
"-main()",
"+main2()"
] | false | 0.04562 | 0.045106 | 1.011384 |
[
"s876948018",
"s797558452"
] |
u216015528
|
p03290
|
python
|
s237385844
|
s719856109
| 35 | 29 | 9,096 | 9,148 |
Accepted
|
Accepted
| 17.14 |
# ABC 104 C - All Green(my answer for bit)
D, G = list(map(int, input().split()))
p, c = [], []
ans = float('inf')
for _ in range(D):
a, b = list(map(int, input().split()))
p.append(a)
c.append(b)
for bit in range(1 << D): # bitで完答した問題を列挙
score = 0
cnt = 0
comp = set(range(D))
for i in range(D): # 完答した問題のscoreを全て加算
if bit & (1 << i):
score += p[i] * 100 * (i + 1) + c[i]
cnt += p[i]
comp.discard(i)
if score < G: # scoreがGに満たなければ中途半端に解答する
incomp = max(comp)
# -が2つあるのは//で切り上げで計算するため.-がないと切り下げ
# https://python.ms/division/#3つのやり方
incomp_num = min(p[incomp],
-(-(G - score) // (100 * (incomp + 1))))
score += (incomp + 1) * incomp_num * 100
cnt += incomp_num
if score >= G: # scoreが目標点G以上なら計算回数cntを記録
ans = min(ans, cnt)
print(ans)
|
def resolve():
""" recursive function"""
def func(i, sum, cnt, rem):
nonlocal ans
if i == D:
if sum < G:
use = max(rem)
n = min(lst[use - 1][0], -(-(G - sum) // ((use) * 100)))
sum += n * use * 100
cnt += n
if sum >= G:
ans = min(ans, cnt)
else:
func(i + 1, sum, cnt, rem)
func(
i + 1,
sum + lst[i][0] * (i + 1) * 100 + lst[i][1],
cnt + lst[i][0],
rem - {i + 1})
D, G = list(map(int, input().split()))
lst = [list(map(int, input().split())) for x in range(D)]
ans = float('inf')
func(0, 0, 0, set(range(1, D + 1)))
print(ans)
if __name__ == "__main__":
resolve()
| 30 | 30 | 918 | 837 |
# ABC 104 C - All Green(my answer for bit)
D, G = list(map(int, input().split()))
p, c = [], []
ans = float("inf")
for _ in range(D):
a, b = list(map(int, input().split()))
p.append(a)
c.append(b)
for bit in range(1 << D): # bitで完答した問題を列挙
score = 0
cnt = 0
comp = set(range(D))
for i in range(D): # 完答した問題のscoreを全て加算
if bit & (1 << i):
score += p[i] * 100 * (i + 1) + c[i]
cnt += p[i]
comp.discard(i)
if score < G: # scoreがGに満たなければ中途半端に解答する
incomp = max(comp)
# -が2つあるのは//で切り上げで計算するため.-がないと切り下げ
# https://python.ms/division/#3つのやり方
incomp_num = min(p[incomp], -(-(G - score) // (100 * (incomp + 1))))
score += (incomp + 1) * incomp_num * 100
cnt += incomp_num
if score >= G: # scoreが目標点G以上なら計算回数cntを記録
ans = min(ans, cnt)
print(ans)
|
def resolve():
"""recursive function"""
def func(i, sum, cnt, rem):
nonlocal ans
if i == D:
if sum < G:
use = max(rem)
n = min(lst[use - 1][0], -(-(G - sum) // ((use) * 100)))
sum += n * use * 100
cnt += n
if sum >= G:
ans = min(ans, cnt)
else:
func(i + 1, sum, cnt, rem)
func(
i + 1,
sum + lst[i][0] * (i + 1) * 100 + lst[i][1],
cnt + lst[i][0],
rem - {i + 1},
)
D, G = list(map(int, input().split()))
lst = [list(map(int, input().split())) for x in range(D)]
ans = float("inf")
func(0, 0, 0, set(range(1, D + 1)))
print(ans)
if __name__ == "__main__":
resolve()
| false | 0 |
[
"-# ABC 104 C - All Green(my answer for bit)",
"-D, G = list(map(int, input().split()))",
"-p, c = [], []",
"-ans = float(\"inf\")",
"-for _ in range(D):",
"- a, b = list(map(int, input().split()))",
"- p.append(a)",
"- c.append(b)",
"-for bit in range(1 << D): # bitで完答した問題を列挙",
"- score = 0",
"- cnt = 0",
"- comp = set(range(D))",
"- for i in range(D): # 完答した問題のscoreを全て加算",
"- if bit & (1 << i):",
"- score += p[i] * 100 * (i + 1) + c[i]",
"- cnt += p[i]",
"- comp.discard(i)",
"- if score < G: # scoreがGに満たなければ中途半端に解答する",
"- incomp = max(comp)",
"- # -が2つあるのは//で切り上げで計算するため.-がないと切り下げ",
"- # https://python.ms/division/#3つのやり方",
"- incomp_num = min(p[incomp], -(-(G - score) // (100 * (incomp + 1))))",
"- score += (incomp + 1) * incomp_num * 100",
"- cnt += incomp_num",
"- if score >= G: # scoreが目標点G以上なら計算回数cntを記録",
"- ans = min(ans, cnt)",
"-print(ans)",
"+def resolve():",
"+ \"\"\"recursive function\"\"\"",
"+",
"+ def func(i, sum, cnt, rem):",
"+ nonlocal ans",
"+ if i == D:",
"+ if sum < G:",
"+ use = max(rem)",
"+ n = min(lst[use - 1][0], -(-(G - sum) // ((use) * 100)))",
"+ sum += n * use * 100",
"+ cnt += n",
"+ if sum >= G:",
"+ ans = min(ans, cnt)",
"+ else:",
"+ func(i + 1, sum, cnt, rem)",
"+ func(",
"+ i + 1,",
"+ sum + lst[i][0] * (i + 1) * 100 + lst[i][1],",
"+ cnt + lst[i][0],",
"+ rem - {i + 1},",
"+ )",
"+",
"+ D, G = list(map(int, input().split()))",
"+ lst = [list(map(int, input().split())) for x in range(D)]",
"+ ans = float(\"inf\")",
"+ func(0, 0, 0, set(range(1, D + 1)))",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.037288 | 0.04699 | 0.793531 |
[
"s237385844",
"s719856109"
] |
u753803401
|
p03162
|
python
|
s082838408
|
s572554341
| 399 | 301 | 56,428 | 53,996 |
Accepted
|
Accepted
| 24.56 |
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
dp = [[0] * 3 for _ in range(n)]
for i in range(n):
a, b, c = list(map(int, input().rstrip('\n').split()))
if i == 0:
dp[i][0] = a
dp[i][1] = b
dp[i][2] = c
else:
dp[i][0] = max(dp[i-1][1] + a, dp[i-1][2] + a)
dp[i][0] = max(dp[i-1][1] + a, dp[i-1][2] + a)
dp[i][1] = max(dp[i-1][0] + b, dp[i-1][2] + b)
dp[i][1] = max(dp[i-1][0] + b, dp[i-1][2] + b)
dp[i][2] = max(dp[i-1][0] + c, dp[i-1][1] + c)
dp[i][2] = max(dp[i-1][0] + c, dp[i-1][1] + c)
print((max(dp[-1])))
if __name__ == '__main__':
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
dp = [[0] * 3 for _ in range(n)]
for i in range(n):
a, b, c = list(map(int, readline().split()))
if i == 0:
dp[i][0] = a
dp[i][1] = b
dp[i][2] = c
else:
dp[i][0] = max(dp[i-1][1] + a, dp[i-1][2] + a)
dp[i][1] = max(dp[i-1][0] + b, dp[i-1][2] + b)
dp[i][2] = max(dp[i-1][0] + c, dp[i-1][1] + c)
print((max(dp[-1])))
if __name__ == '__main__':
solve()
| 28 | 23 | 791 | 597 |
import sys
def solve():
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input().rstrip("\n"))
dp = [[0] * 3 for _ in range(n)]
for i in range(n):
a, b, c = list(map(int, input().rstrip("\n").split()))
if i == 0:
dp[i][0] = a
dp[i][1] = b
dp[i][2] = c
else:
dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
print((max(dp[-1])))
if __name__ == "__main__":
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
n = int(readline())
dp = [[0] * 3 for _ in range(n)]
for i in range(n):
a, b, c = list(map(int, readline().split()))
if i == 0:
dp[i][0] = a
dp[i][1] = b
dp[i][2] = c
else:
dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
print((max(dp[-1])))
if __name__ == "__main__":
solve()
| false | 17.857143 |
[
"- input = sys.stdin.readline",
"+ readline = sys.stdin.buffer.readline",
"- n = int(input().rstrip(\"\\n\"))",
"+ n = int(readline())",
"- a, b, c = list(map(int, input().rstrip(\"\\n\").split()))",
"+ a, b, c = list(map(int, readline().split()))",
"- dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)",
"- dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)",
"- dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)"
] | false | 0.036959 | 0.044524 | 0.830104 |
[
"s082838408",
"s572554341"
] |
u014333473
|
p03474
|
python
|
s720361483
|
s272739049
| 19 | 17 | 3,188 | 2,940 |
Accepted
|
Accepted
| 10.53 |
import re
A,B=list(map(int,input().split()));S=eval(input())
print(('Yes' if 1<=A<=5 and 1<=B<=5 and S[:A].isdigit() and S[A]=='-' and S[B+1:].isdigit() else 'No'))
|
A,B=list(map(int,input().split()));S=eval(input())
print(('Yes' if S[:A].isdigit() and S[A]=='-' and S[B+1:].isdigit() else 'No'))
| 3 | 2 | 152 | 117 |
import re
A, B = list(map(int, input().split()))
S = eval(input())
print(
(
"Yes"
if 1 <= A <= 5
and 1 <= B <= 5
and S[:A].isdigit()
and S[A] == "-"
and S[B + 1 :].isdigit()
else "No"
)
)
|
A, B = list(map(int, input().split()))
S = eval(input())
print(("Yes" if S[:A].isdigit() and S[A] == "-" and S[B + 1 :].isdigit() else "No"))
| false | 33.333333 |
[
"-import re",
"-",
"-print(",
"- (",
"- \"Yes\"",
"- if 1 <= A <= 5",
"- and 1 <= B <= 5",
"- and S[:A].isdigit()",
"- and S[A] == \"-\"",
"- and S[B + 1 :].isdigit()",
"- else \"No\"",
"- )",
"-)",
"+print((\"Yes\" if S[:A].isdigit() and S[A] == \"-\" and S[B + 1 :].isdigit() else \"No\"))"
] | false | 0.068226 | 0.06761 | 1.009111 |
[
"s720361483",
"s272739049"
] |
u284854859
|
p02787
|
python
|
s620351647
|
s066350410
| 631 | 572 | 41,708 | 41,452 |
Accepted
|
Accepted
| 9.35 |
h,n = list(map(int,input().split()))
dg = 10**5
ba = []
for _ in [0]*n:
a,b = list(map(int,input().split()))
if a >= h:
a = h
ba.append(b*dg+a)
ba.sort()
d = [10**9]*(h+1)
d[0] = 0
for i in range(1,h+1):
for e in ba:
a,b = e%dg,e//dg
if i<=a:
if d[i] > b:
d[i] = b
else:
if d[i] > d[i-a]+b:
d[i] = d[i-a]+b
print((d[-1]))
|
import sys
input = sys.stdin.readline
h,n = list(map(int,input().split()))
dg = 10**5
ba = []
for _ in [0]*n:
a,b = list(map(int,input().split()))
if a >= h:
a = h
ba.append(b*dg+a)
ba.sort()
d = [10**9]*(h+1)
d[0] = 0
for i in range(1,h+1):
for e in ba:
a,b = e%dg,e//dg
if i<=a:
if d[i] > b:
d[i] = b
else:
if d[i] > d[i-a]+b:
d[i] = d[i-a]+b
print((d[-1]))
| 27 | 30 | 443 | 486 |
h, n = list(map(int, input().split()))
dg = 10**5
ba = []
for _ in [0] * n:
a, b = list(map(int, input().split()))
if a >= h:
a = h
ba.append(b * dg + a)
ba.sort()
d = [10**9] * (h + 1)
d[0] = 0
for i in range(1, h + 1):
for e in ba:
a, b = e % dg, e // dg
if i <= a:
if d[i] > b:
d[i] = b
else:
if d[i] > d[i - a] + b:
d[i] = d[i - a] + b
print((d[-1]))
|
import sys
input = sys.stdin.readline
h, n = list(map(int, input().split()))
dg = 10**5
ba = []
for _ in [0] * n:
a, b = list(map(int, input().split()))
if a >= h:
a = h
ba.append(b * dg + a)
ba.sort()
d = [10**9] * (h + 1)
d[0] = 0
for i in range(1, h + 1):
for e in ba:
a, b = e % dg, e // dg
if i <= a:
if d[i] > b:
d[i] = b
else:
if d[i] > d[i - a] + b:
d[i] = d[i - a] + b
print((d[-1]))
| false | 10 |
[
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.125055 | 0.262456 | 0.476482 |
[
"s620351647",
"s066350410"
] |
u312025627
|
p04029
|
python
|
s886314786
|
s200685190
| 177 | 160 | 38,256 | 38,256 |
Accepted
|
Accepted
| 9.6 |
n = int(eval(input()))
ans = 0
for i in range(1,n+1):
ans += i
print(ans)
|
def main():
N = int(eval(input()))
print((N*(N+1)//2))
if __name__ == '__main__':
main()
| 5 | 7 | 75 | 101 |
n = int(eval(input()))
ans = 0
for i in range(1, n + 1):
ans += i
print(ans)
|
def main():
N = int(eval(input()))
print((N * (N + 1) // 2))
if __name__ == "__main__":
main()
| false | 28.571429 |
[
"-n = int(eval(input()))",
"-ans = 0",
"-for i in range(1, n + 1):",
"- ans += i",
"-print(ans)",
"+def main():",
"+ N = int(eval(input()))",
"+ print((N * (N + 1) // 2))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.075106 | 0.049794 | 1.508317 |
[
"s886314786",
"s200685190"
] |
u781262926
|
p03361
|
python
|
s252019264
|
s844261461
| 178 | 127 | 12,352 | 27,340 |
Accepted
|
Accepted
| 28.65 |
from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid():
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return '\n'.join([' '.join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:], function=lambda x: int(x == '#'))
def dfs(root):
count = 1
x, y = root
grid[y, x] = 0
stack = [root]
while stack:
x, y = stack.pop()
grid[y, x] = 0
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if grid.is_valid_xy(x+dx, y+dy) and grid[y+dy, x+dx]:
stack.append((x+dx, y+dy))
count += 1
return count
ans = 'Yes'
for i, j in product(list(range(h)), list(range(w))):
if grid[i, j]:
if dfs((j, i)) == 1:
ans = 'No'
break
print(ans)
|
from itertools import product
from collections import deque
import numpy as np
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return '\n'.join([' '.join(map(str, row)) for row in self.grid]) + '\n'
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
def dfs(grid, root):
stack = [root]
x, y = root
grid[y, x] = '!'
while stack:
x, y = stack.pop()
yield (x, y)
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
nx, ny = x+dx, y+dy
if grid.is_valid_xy(nx, ny) and grid[ny, nx] == '#':
stack.append((nx, ny))
grid[ny, nx] = '!'
h, w = list(map(int, input().split()))
grid = Grid([eval(input()) for s in range(h)])
for y, x in product(list(range(h)), list(range(w))):
if grid[y, x] == '#':
if len(list(dfs(grid, (x, y)))) == 1:
print('No')
break
else:
print('Yes')
| 54 | 53 | 1,661 | 1,649 |
from itertools import product
from collections import deque
import numpy as np
inputs = open(0).readlines()
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return "\n".join([" ".join(map(str, row)) for row in self.grid])
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
h, w = list(map(int, inputs[0].split()))
grid = Grid(inputs[1:], function=lambda x: int(x == "#"))
def dfs(root):
count = 1
x, y = root
grid[y, x] = 0
stack = [root]
while stack:
x, y = stack.pop()
grid[y, x] = 0
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
if grid.is_valid_xy(x + dx, y + dy) and grid[y + dy, x + dx]:
stack.append((x + dx, y + dy))
count += 1
return count
ans = "Yes"
for i, j in product(list(range(h)), list(range(w))):
if grid[i, j]:
if dfs((j, i)) == 1:
ans = "No"
break
print(ans)
|
from itertools import product
from collections import deque
import numpy as np
class Grid:
def __init__(self, grid, w=0, h=0, function=lambda x: x):
self.w = w = w if w else len(grid[0])
self.h = h = h if h else len(grid)
dtype = type(function(grid[0][0]))
self.grid = np.empty((h, w), dtype=dtype)
for i, row in zip(list(range(h)), grid):
for j, val in zip(list(range(w)), row):
self.grid[i][j] = function(val)
def is_valid_x(self, x):
return 0 <= x < self.w
def is_valid_y(self, y):
return 0 <= y < self.h
def is_valid_xy(self, x, y):
return self.is_valid_x(x) and self.is_valid_y(y)
def __iter__(self):
return iter(self.grid)
def __repr__(self):
return "\n".join([" ".join(map(str, row)) for row in self.grid]) + "\n"
def __getitem__(self, x):
return self.grid[x]
def __setitem__(self, x, val):
self.grid[x] = val
def dfs(grid, root):
stack = [root]
x, y = root
grid[y, x] = "!"
while stack:
x, y = stack.pop()
yield (x, y)
for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
nx, ny = x + dx, y + dy
if grid.is_valid_xy(nx, ny) and grid[ny, nx] == "#":
stack.append((nx, ny))
grid[ny, nx] = "!"
h, w = list(map(int, input().split()))
grid = Grid([eval(input()) for s in range(h)])
for y, x in product(list(range(h)), list(range(w))):
if grid[y, x] == "#":
if len(list(dfs(grid, (x, y)))) == 1:
print("No")
break
else:
print("Yes")
| false | 1.851852 |
[
"-",
"-inputs = open(0).readlines()",
"- return \"\\n\".join([\" \".join(map(str, row)) for row in self.grid])",
"+ return \"\\n\".join([\" \".join(map(str, row)) for row in self.grid]) + \"\\n\"",
"-h, w = list(map(int, inputs[0].split()))",
"-grid = Grid(inputs[1:], function=lambda x: int(x == \"#\"))",
"+def dfs(grid, root):",
"+ stack = [root]",
"+ x, y = root",
"+ grid[y, x] = \"!\"",
"+ while stack:",
"+ x, y = stack.pop()",
"+ yield (x, y)",
"+ for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):",
"+ nx, ny = x + dx, y + dy",
"+ if grid.is_valid_xy(nx, ny) and grid[ny, nx] == \"#\":",
"+ stack.append((nx, ny))",
"+ grid[ny, nx] = \"!\"",
"-def dfs(root):",
"- count = 1",
"- x, y = root",
"- grid[y, x] = 0",
"- stack = [root]",
"- while stack:",
"- x, y = stack.pop()",
"- grid[y, x] = 0",
"- for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):",
"- if grid.is_valid_xy(x + dx, y + dy) and grid[y + dy, x + dx]:",
"- stack.append((x + dx, y + dy))",
"- count += 1",
"- return count",
"-",
"-",
"-ans = \"Yes\"",
"-for i, j in product(list(range(h)), list(range(w))):",
"- if grid[i, j]:",
"- if dfs((j, i)) == 1:",
"- ans = \"No\"",
"+h, w = list(map(int, input().split()))",
"+grid = Grid([eval(input()) for s in range(h)])",
"+for y, x in product(list(range(h)), list(range(w))):",
"+ if grid[y, x] == \"#\":",
"+ if len(list(dfs(grid, (x, y)))) == 1:",
"+ print(\"No\")",
"-print(ans)",
"+else:",
"+ print(\"Yes\")"
] | false | 0.153809 | 0.154719 | 0.994119 |
[
"s252019264",
"s844261461"
] |
u363610900
|
p03448
|
python
|
s650757749
|
s194557904
| 57 | 49 | 3,060 | 3,060 |
Accepted
|
Accepted
| 14.04 |
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
res = 0
for a in range(A+1):
for b in range(B+1):
for c in range(C+1):
calc = a * 500 + b * 100 + c * 50
if calc == X:
res += 1
print(res)
|
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
cnt = 0
for i in range(A+1):
for j in range(B+1):
for k in range(C+1):
if i * 500 + j * 100 + k * 50 == X:
cnt += 1
print(cnt)
| 15 | 12 | 275 | 246 |
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
res = 0
for a in range(A + 1):
for b in range(B + 1):
for c in range(C + 1):
calc = a * 500 + b * 100 + c * 50
if calc == X:
res += 1
print(res)
|
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
cnt = 0
for i in range(A + 1):
for j in range(B + 1):
for k in range(C + 1):
if i * 500 + j * 100 + k * 50 == X:
cnt += 1
print(cnt)
| false | 20 |
[
"-res = 0",
"-for a in range(A + 1):",
"- for b in range(B + 1):",
"- for c in range(C + 1):",
"- calc = a * 500 + b * 100 + c * 50",
"- if calc == X:",
"- res += 1",
"-print(res)",
"+cnt = 0",
"+for i in range(A + 1):",
"+ for j in range(B + 1):",
"+ for k in range(C + 1):",
"+ if i * 500 + j * 100 + k * 50 == X:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.119848 | 0.221333 | 0.541483 |
[
"s650757749",
"s194557904"
] |
u188827677
|
p02813
|
python
|
s243828786
|
s426892588
| 34 | 27 | 8,052 | 8,052 |
Accepted
|
Accepted
| 20.59 |
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = list(permutations(list(range(1,n+1)), n))
a = 0
b = 0
c = 0
for i in nums:
c += 1
if i == p:
a = c
if i == q:
b = c
print((abs(a-b)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = list(permutations(list(range(1,n+1)),n))
print((abs(nums.index(p) - nums.index(q))))
| 16 | 7 | 288 | 216 |
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = list(permutations(list(range(1, n + 1)), n))
a = 0
b = 0
c = 0
for i in nums:
c += 1
if i == p:
a = c
if i == q:
b = c
print((abs(a - b)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = list(permutations(list(range(1, n + 1)), n))
print((abs(nums.index(p) - nums.index(q))))
| false | 56.25 |
[
"-a = 0",
"-b = 0",
"-c = 0",
"-for i in nums:",
"- c += 1",
"- if i == p:",
"- a = c",
"- if i == q:",
"- b = c",
"-print((abs(a - b)))",
"+print((abs(nums.index(p) - nums.index(q))))"
] | false | 0.038844 | 0.040618 | 0.956317 |
[
"s243828786",
"s426892588"
] |
u367130284
|
p03682
|
python
|
s665774010
|
s829983046
| 1,246 | 1,058 | 53,020 | 51,188 |
Accepted
|
Accepted
| 15.09 |
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse import csr_matrix
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline #危険!基本オフにしろ!
class UNION_FIND(object):
def __init__(self,n):
self.parent=[-1 for i in range(n)]
def root(self,x):
if self.parent[x]<0:
return x
else:
self.parent[x]=self.root(self.parent[x])
return self.parent[x]
def size(self,x):
return -self.parent[self.root(x)]
def union(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return False
if self.size(x)<self.size(y):
x,y=y,x
self.parent[x]+=self.parent[y]
self.parent[y]=x
return True
def compute_mst_kruskal(max_v, edges, flip):
edges.sort(key=lambda x: x[2],reverse=flip)
uf = UNION_FIND(max_v)
mst = []
for (a,b,c) in edges:
if uf.root(a)!= uf.root(b):
uf.union(a,b)
mst.append(c)
return mst
def main():
n=int(eval(input()))
inp=[[i]+list(map(int,input().split()))for i in range(n)]
inpX=sorted(inp,key=lambda x:x[1])
inpY=sorted(inp,key=lambda x:x[2])
edges=[]
for i in range(1,n):
a,b,c=inpX[i]
d,e,f=inpX[i-1]
edges.append((a,d,min(abs(b-e),abs(c-f))))
a,b,c=inpY[i]
d,e,f=inpY[i-1]
edges.append((a,d,min(abs(b-e),abs(c-f))))
print((sum(compute_mst_kruskal(n, edges, 0))))
if __name__ == '__main__':
main()
|
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse import csr_matrix
#from collections import* #defaultdict Counter deque appendleft
#from fractions import gcd
#from functools import* #reduce
#from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
#from operator import mul,itemgetter
#from bisect import* #bisect_left bisect_right
#from heapq import* #heapify heappop heappushpop
#from math import factorial,pi
#from copy import deepcopy
import sys
#sys.setrecursionlimit(10**8)
input=sys.stdin.readline #危険!基本オフにしろ!
class UNION_FIND(object):
def __init__(self,n):
self.parent=[-1 for i in range(n)]
def root(self,x):
if self.parent[x]<0:
return x
else:
self.parent[x]=self.root(self.parent[x])
return self.parent[x]
def size(self,x):
return -self.parent[self.root(x)]
def union(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return False
if self.size(x)<self.size(y):
x,y=y,x
self.parent[x]+=self.parent[y]
self.parent[y]=x
return True
def compute_mst_kruskal(max_v, edges, flip):
edges.sort(key=lambda x: x[2],reverse=flip)
uf = UNION_FIND(max_v)
mst = []
for (a,b,c) in edges:
if uf.root(a)!= uf.root(b):
uf.union(a,b)
mst.append(c)
return mst
def main():
n=int(eval(input()))
inp=[[i]+list(map(int,input().split()))for i in range(n)]
inpX=sorted(inp,key=lambda x:x[1])
inpY=sorted(inp,key=lambda x:x[2])
edges=[]
for i in range(1,n):
a,b,c=inpX[i]
d,e,f=inpX[i-1]
edges.append((a,d,min(abs(b-e),abs(c-f))))
a,b,c=inpY[i]
d,e,f=inpY[i-1]
edges.append((a,d,min(abs(b-e),abs(c-f))))
print((sum(compute_mst_kruskal(n, edges, 0))))
if __name__ == '__main__':
main()
| 76 | 74 | 2,199 | 2,196 |
# import numpy as np
# from numpy import*
# from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse import csr_matrix
from collections import * # defaultdict Counter deque appendleft
from fractions import gcd
from functools import * # reduce
from itertools import * # permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul, itemgetter
from bisect import * # bisect_left bisect_right
from heapq import * # heapify heappop heappushpop
from math import factorial, pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
# input=sys.stdin.readline #危険!基本オフにしろ!
class UNION_FIND(object):
def __init__(self, n):
self.parent = [-1 for i in range(n)]
def root(self, x):
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(self.parent[x])
return self.parent[x]
def size(self, x):
return -self.parent[self.root(x)]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.size(x) < self.size(y):
x, y = y, x
self.parent[x] += self.parent[y]
self.parent[y] = x
return True
def compute_mst_kruskal(max_v, edges, flip):
edges.sort(key=lambda x: x[2], reverse=flip)
uf = UNION_FIND(max_v)
mst = []
for (a, b, c) in edges:
if uf.root(a) != uf.root(b):
uf.union(a, b)
mst.append(c)
return mst
def main():
n = int(eval(input()))
inp = [[i] + list(map(int, input().split())) for i in range(n)]
inpX = sorted(inp, key=lambda x: x[1])
inpY = sorted(inp, key=lambda x: x[2])
edges = []
for i in range(1, n):
a, b, c = inpX[i]
d, e, f = inpX[i - 1]
edges.append((a, d, min(abs(b - e), abs(c - f))))
a, b, c = inpY[i]
d, e, f = inpY[i - 1]
edges.append((a, d, min(abs(b - e), abs(c - f))))
print((sum(compute_mst_kruskal(n, edges, 0))))
if __name__ == "__main__":
main()
|
# import numpy as np
# from numpy import*
# from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse import csr_matrix
# from collections import* #defaultdict Counter deque appendleft
# from fractions import gcd
# from functools import* #reduce
# from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
# from operator import mul,itemgetter
# from bisect import* #bisect_left bisect_right
# from heapq import* #heapify heappop heappushpop
# from math import factorial,pi
# from copy import deepcopy
import sys
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline # 危険!基本オフにしろ!
class UNION_FIND(object):
def __init__(self, n):
self.parent = [-1 for i in range(n)]
def root(self, x):
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(self.parent[x])
return self.parent[x]
def size(self, x):
return -self.parent[self.root(x)]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.size(x) < self.size(y):
x, y = y, x
self.parent[x] += self.parent[y]
self.parent[y] = x
return True
def compute_mst_kruskal(max_v, edges, flip):
edges.sort(key=lambda x: x[2], reverse=flip)
uf = UNION_FIND(max_v)
mst = []
for (a, b, c) in edges:
if uf.root(a) != uf.root(b):
uf.union(a, b)
mst.append(c)
return mst
def main():
n = int(eval(input()))
inp = [[i] + list(map(int, input().split())) for i in range(n)]
inpX = sorted(inp, key=lambda x: x[1])
inpY = sorted(inp, key=lambda x: x[2])
edges = []
for i in range(1, n):
a, b, c = inpX[i]
d, e, f = inpX[i - 1]
edges.append((a, d, min(abs(b - e), abs(c - f))))
a, b, c = inpY[i]
d, e, f = inpY[i - 1]
edges.append((a, d, min(abs(b - e), abs(c - f))))
print((sum(compute_mst_kruskal(n, edges, 0))))
if __name__ == "__main__":
main()
| false | 2.631579 |
[
"-from collections import * # defaultdict Counter deque appendleft",
"-from fractions import gcd",
"-from functools import * # reduce",
"-from itertools import * # permutations(\"AB\",repeat=2) combinations(\"AB\",2) product(\"AB\",2) groupby accumulate",
"-from operator import mul, itemgetter",
"-from bisect import * # bisect_left bisect_right",
"-from heapq import * # heapify heappop heappushpop",
"-from math import factorial, pi",
"-from copy import deepcopy",
"+# from collections import* #defaultdict Counter deque appendleft",
"+# from fractions import gcd",
"+# from functools import* #reduce",
"+# from itertools import* #permutations(\"AB\",repeat=2) combinations(\"AB\",2) product(\"AB\",2) groupby accumulate",
"+# from operator import mul,itemgetter",
"+# from bisect import* #bisect_left bisect_right",
"+# from heapq import* #heapify heappop heappushpop",
"+# from math import factorial,pi",
"+# from copy import deepcopy",
"-sys.setrecursionlimit(10**8)",
"-# input=sys.stdin.readline #危険!基本オフにしろ!",
"+# sys.setrecursionlimit(10**8)",
"+input = sys.stdin.readline # 危険!基本オフにしろ!",
"+",
"+"
] | false | 0.048807 | 0.048264 | 1.011256 |
[
"s665774010",
"s829983046"
] |
u492447501
|
p03220
|
python
|
s084959438
|
s801386117
| 149 | 18 | 12,496 | 3,060 |
Accepted
|
Accepted
| 87.92 |
import numpy as np
N = int(eval(input()))
T, A = list(map(int, input().split()))
*H, = list(map(int,input().split()))
m = [abs(A-(T-h*0.006)) for h in H]
print((m.index(min(m))+1))
|
N = int(eval(input()))
T,A = list(map(int, input().split()))
*H, = list(map(int, input().split()))
ans = 100000000
index = 0
for i in range(len(H)):
temp = T-H[i]*0.006
if abs(A-temp)<ans:
ans = abs(A-temp)
index = i
print((index+1))
| 9 | 16 | 173 | 257 |
import numpy as np
N = int(eval(input()))
T, A = list(map(int, input().split()))
(*H,) = list(map(int, input().split()))
m = [abs(A - (T - h * 0.006)) for h in H]
print((m.index(min(m)) + 1))
|
N = int(eval(input()))
T, A = list(map(int, input().split()))
(*H,) = list(map(int, input().split()))
ans = 100000000
index = 0
for i in range(len(H)):
temp = T - H[i] * 0.006
if abs(A - temp) < ans:
ans = abs(A - temp)
index = i
print((index + 1))
| false | 43.75 |
[
"-import numpy as np",
"-",
"-m = [abs(A - (T - h * 0.006)) for h in H]",
"-print((m.index(min(m)) + 1))",
"+ans = 100000000",
"+index = 0",
"+for i in range(len(H)):",
"+ temp = T - H[i] * 0.006",
"+ if abs(A - temp) < ans:",
"+ ans = abs(A - temp)",
"+ index = i",
"+print((index + 1))"
] | false | 0.040697 | 0.058524 | 0.695394 |
[
"s084959438",
"s801386117"
] |
u063550903
|
p02802
|
python
|
s618090402
|
s446368358
| 286 | 237 | 4,760 | 17,112 |
Accepted
|
Accepted
| 17.13 |
N,M = list(map(int,input().split()))
seito = 0
penarty = 0
pena = [False for i in range(N+1)]
pena2 = [0 for i in range(N+1)]
for i in range(M):
p,s = input().split()
p = int(p)
if not pena[p]:
if s == "AC":
pena[p]=True
seito += 1
else:
pena2[p] += 1
for i in range(N+1):
if pena[i]:
penarty += pena2[i]
print((seito,penarty))
|
N,M = list(map(int,input().split()))
dic = {}
ans = 0
for i in range(M):
p,s = input().split()
if s == "AC":
if p in dic:
ans += dic[p]
dic[p] = 0
else:
if p in dic:
if dic[p] != 0:
dic[p] += 1
else:
dic[p] = 1
print((len([1 for i in list(dic.values()) if i==0]),ans))
| 19 | 17 | 414 | 367 |
N, M = list(map(int, input().split()))
seito = 0
penarty = 0
pena = [False for i in range(N + 1)]
pena2 = [0 for i in range(N + 1)]
for i in range(M):
p, s = input().split()
p = int(p)
if not pena[p]:
if s == "AC":
pena[p] = True
seito += 1
else:
pena2[p] += 1
for i in range(N + 1):
if pena[i]:
penarty += pena2[i]
print((seito, penarty))
|
N, M = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(M):
p, s = input().split()
if s == "AC":
if p in dic:
ans += dic[p]
dic[p] = 0
else:
if p in dic:
if dic[p] != 0:
dic[p] += 1
else:
dic[p] = 1
print((len([1 for i in list(dic.values()) if i == 0]), ans))
| false | 10.526316 |
[
"-seito = 0",
"-penarty = 0",
"-pena = [False for i in range(N + 1)]",
"-pena2 = [0 for i in range(N + 1)]",
"+dic = {}",
"+ans = 0",
"- p = int(p)",
"- if not pena[p]:",
"- if s == \"AC\":",
"- pena[p] = True",
"- seito += 1",
"+ if s == \"AC\":",
"+ if p in dic:",
"+ ans += dic[p]",
"+ dic[p] = 0",
"+ else:",
"+ if p in dic:",
"+ if dic[p] != 0:",
"+ dic[p] += 1",
"- pena2[p] += 1",
"-for i in range(N + 1):",
"- if pena[i]:",
"- penarty += pena2[i]",
"-print((seito, penarty))",
"+ dic[p] = 1",
"+print((len([1 for i in list(dic.values()) if i == 0]), ans))"
] | false | 0.110477 | 0.096068 | 1.149994 |
[
"s618090402",
"s446368358"
] |
u948524308
|
p03781
|
python
|
s039877312
|
s014744304
| 31 | 24 | 2,940 | 2,940 |
Accepted
|
Accepted
| 22.58 |
X=int(eval(input()))
i=0
d=0
while d<X:
i+=1
d=i*(i+1)//2
print(i)
|
X=int(eval(input()))
d=0
for i in range(1,X+1):
d+=i
if d>=X:
print(i)
exit()
| 8 | 7 | 76 | 101 |
X = int(eval(input()))
i = 0
d = 0
while d < X:
i += 1
d = i * (i + 1) // 2
print(i)
|
X = int(eval(input()))
d = 0
for i in range(1, X + 1):
d += i
if d >= X:
print(i)
exit()
| false | 12.5 |
[
"-i = 0",
"-while d < X:",
"- i += 1",
"- d = i * (i + 1) // 2",
"-print(i)",
"+for i in range(1, X + 1):",
"+ d += i",
"+ if d >= X:",
"+ print(i)",
"+ exit()"
] | false | 0.077325 | 0.047307 | 1.63452 |
[
"s039877312",
"s014744304"
] |
u661576386
|
p03327
|
python
|
s411734503
|
s766815497
| 20 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 15 |
n = int(eval(input()))
if n < 1000:
print("ABC")
else:
print("ABD")
|
n = int(eval(input()))
print(("ABC" if n<1000 else "ABD"))
| 5 | 2 | 74 | 52 |
n = int(eval(input()))
if n < 1000:
print("ABC")
else:
print("ABD")
|
n = int(eval(input()))
print(("ABC" if n < 1000 else "ABD"))
| false | 60 |
[
"-if n < 1000:",
"- print(\"ABC\")",
"-else:",
"- print(\"ABD\")",
"+print((\"ABC\" if n < 1000 else \"ABD\"))"
] | false | 0.045946 | 0.045668 | 1.006082 |
[
"s411734503",
"s766815497"
] |
u278479217
|
p03576
|
python
|
s121726907
|
s194558773
| 1,556 | 60 | 61,344 | 3,064 |
Accepted
|
Accepted
| 96.14 |
from itertools import combinations
N, K = list(map(int, input().split()))
points = []
for i in range(N):
points.append(list(map(int, input().split())))
xl = list([p[0] for p in points])
yl = list([p[1] for p in points])
def contained(point, xmin, xmax, ymin, ymax):
return (xmin <= point[0] <= xmax) and (ymin <= point[1] <= ymax)
def count_contained(xmin, xmax, ymin, ymax):
count = 0
for point in points:
if contained(point, xmin, xmax, ymin, ymax):
count += 1
return count
min_area = 10**20
for xs in combinations(xl, 2):
xmin = min(xs)
xmax = max(xs)
for ys in combinations(yl, 2):
ymin = min(ys)
ymax = max(ys)
if count_contained(xmin, xmax, ymin, ymax) >= K:
area = (xmax-xmin) * (ymax-ymin)
min_area = min(area, min_area)
print(min_area)
|
from itertools import combinations
N, K = list(map(int, input().split()))
points = []
for i in range(N):
points.append(list(map(int, input().split())))
points.sort(key=lambda p:p[0])
min_area = 10**20
for k in range(K, N+1):
for l in range(0, N-k+1):
points_tmp = points[l:l+k]
points_tmp.sort(key=lambda p:p[1])
for m in range(0, k-K+1):
points_selected = points_tmp[m: m+K]
ymin = points_selected[0][1]
ymax = points_selected[-1][1]
points_selected.sort(key=lambda p:p[0])
xmin = points_selected[0][0]
xmax = points_selected[-1][0]
area = (xmax-xmin) * (ymax-ymin)
min_area = min(area, min_area)
print(min_area)
| 33 | 26 | 914 | 766 |
from itertools import combinations
N, K = list(map(int, input().split()))
points = []
for i in range(N):
points.append(list(map(int, input().split())))
xl = list([p[0] for p in points])
yl = list([p[1] for p in points])
def contained(point, xmin, xmax, ymin, ymax):
return (xmin <= point[0] <= xmax) and (ymin <= point[1] <= ymax)
def count_contained(xmin, xmax, ymin, ymax):
count = 0
for point in points:
if contained(point, xmin, xmax, ymin, ymax):
count += 1
return count
min_area = 10**20
for xs in combinations(xl, 2):
xmin = min(xs)
xmax = max(xs)
for ys in combinations(yl, 2):
ymin = min(ys)
ymax = max(ys)
if count_contained(xmin, xmax, ymin, ymax) >= K:
area = (xmax - xmin) * (ymax - ymin)
min_area = min(area, min_area)
print(min_area)
|
from itertools import combinations
N, K = list(map(int, input().split()))
points = []
for i in range(N):
points.append(list(map(int, input().split())))
points.sort(key=lambda p: p[0])
min_area = 10**20
for k in range(K, N + 1):
for l in range(0, N - k + 1):
points_tmp = points[l : l + k]
points_tmp.sort(key=lambda p: p[1])
for m in range(0, k - K + 1):
points_selected = points_tmp[m : m + K]
ymin = points_selected[0][1]
ymax = points_selected[-1][1]
points_selected.sort(key=lambda p: p[0])
xmin = points_selected[0][0]
xmax = points_selected[-1][0]
area = (xmax - xmin) * (ymax - ymin)
min_area = min(area, min_area)
print(min_area)
| false | 21.212121 |
[
"-xl = list([p[0] for p in points])",
"-yl = list([p[1] for p in points])",
"-",
"-",
"-def contained(point, xmin, xmax, ymin, ymax):",
"- return (xmin <= point[0] <= xmax) and (ymin <= point[1] <= ymax)",
"-",
"-",
"-def count_contained(xmin, xmax, ymin, ymax):",
"- count = 0",
"- for point in points:",
"- if contained(point, xmin, xmax, ymin, ymax):",
"- count += 1",
"- return count",
"-",
"-",
"+points.sort(key=lambda p: p[0])",
"-for xs in combinations(xl, 2):",
"- xmin = min(xs)",
"- xmax = max(xs)",
"- for ys in combinations(yl, 2):",
"- ymin = min(ys)",
"- ymax = max(ys)",
"- if count_contained(xmin, xmax, ymin, ymax) >= K:",
"+for k in range(K, N + 1):",
"+ for l in range(0, N - k + 1):",
"+ points_tmp = points[l : l + k]",
"+ points_tmp.sort(key=lambda p: p[1])",
"+ for m in range(0, k - K + 1):",
"+ points_selected = points_tmp[m : m + K]",
"+ ymin = points_selected[0][1]",
"+ ymax = points_selected[-1][1]",
"+ points_selected.sort(key=lambda p: p[0])",
"+ xmin = points_selected[0][0]",
"+ xmax = points_selected[-1][0]"
] | false | 0.115067 | 0.035317 | 3.258136 |
[
"s121726907",
"s194558773"
] |
u193927973
|
p02773
|
python
|
s204222220
|
s790897528
| 769 | 704 | 50,436 | 50,224 |
Accepted
|
Accepted
| 8.45 |
N=int(input())
S=[]
for _ in range(N):
S.append(input())
import collections
c=collections.Counter(S)
vl=list(c.values())
mv=max(vl)
ans=[]
cc=list(c.items())
cc.sort(key=lambda x:x[1], reverse=True)
for k, v in cc:
if v==mv:
ans.append(k)
else:
break
ans.sort()
[print(a) for a in ans]
|
N=int(input())
S=[]
for _ in range(N):
S.append(input())
import collections
c=collections.Counter(S)
vl=list(c.values())
# 最大要素数
mv=max(vl)
ans=[]
cc=list(c.items()) # 辞書を[key, value]のリストにする
cc.sort(key=lambda x:x[1], reverse=True) # valueで降順ソート
# 辞書リスト内のkey, valueを調べる
for k, v in cc:
if v==mv: # valueが要素数最大のやつ
ans.append(k)
else:
break
ans.sort()
[print(a) for a in ans]
| 23 | 23 | 330 | 415 |
N = int(input())
S = []
for _ in range(N):
S.append(input())
import collections
c = collections.Counter(S)
vl = list(c.values())
mv = max(vl)
ans = []
cc = list(c.items())
cc.sort(key=lambda x: x[1], reverse=True)
for k, v in cc:
if v == mv:
ans.append(k)
else:
break
ans.sort()
[print(a) for a in ans]
|
N = int(input())
S = []
for _ in range(N):
S.append(input())
import collections
c = collections.Counter(S)
vl = list(c.values())
# 最大要素数
mv = max(vl)
ans = []
cc = list(c.items()) # 辞書を[key, value]のリストにする
cc.sort(key=lambda x: x[1], reverse=True) # valueで降順ソート
# 辞書リスト内のkey, valueを調べる
for k, v in cc:
if v == mv: # valueが要素数最大のやつ
ans.append(k)
else:
break
ans.sort()
[print(a) for a in ans]
| false | 0 |
[
"+# 最大要素数",
"-cc = list(c.items())",
"-cc.sort(key=lambda x: x[1], reverse=True)",
"+cc = list(c.items()) # 辞書を[key, value]のリストにする",
"+cc.sort(key=lambda x: x[1], reverse=True) # valueで降順ソート",
"+# 辞書リスト内のkey, valueを調べる",
"- if v == mv:",
"+ if v == mv: # valueが要素数最大のやつ"
] | false | 0.040718 | 0.058929 | 0.69096 |
[
"s204222220",
"s790897528"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.