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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u978313283
|
p03160
|
python
|
s460568070
|
s844290286
| 144 | 130 | 13,980 | 14,028 |
Accepted
|
Accepted
| 9.72 |
INF=10**15
N=int(eval(input()))
h=list(map(int,input().split()))
dp=[INF for i in range(N)]
dp[0]=0
for i in range(1,N):
if i>1:
dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
else:
dp[i]=dp[i-1]+abs(h[i]-h[i-1])
print((dp[N-1]))
|
N=int(eval(input()))
H=list(map(int,input().split()))
Cost=[0 for i in range(N)]
Cost[1]=abs(H[1]-H[0])
for i in range(2,N):
Cost[i]=min(Cost[i-2] + abs(H[i]-H[i-2]), Cost[i-1] + abs(H[i]-H[i-1]))
print((Cost[N-1]))
| 11 | 7 | 269 | 217 |
INF = 10**15
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [INF for i in range(N)]
dp[0] = 0
for i in range(1, N):
if i > 1:
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
else:
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
print((dp[N - 1]))
|
N = int(eval(input()))
H = list(map(int, input().split()))
Cost = [0 for i in range(N)]
Cost[1] = abs(H[1] - H[0])
for i in range(2, N):
Cost[i] = min(
Cost[i - 2] + abs(H[i] - H[i - 2]), Cost[i - 1] + abs(H[i] - H[i - 1])
)
print((Cost[N - 1]))
| false | 36.363636 |
[
"-INF = 10**15",
"-h = list(map(int, input().split()))",
"-dp = [INF for i in range(N)]",
"-dp[0] = 0",
"-for i in range(1, N):",
"- if i > 1:",
"- dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"- else:",
"- dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])",
"-print((dp[N - 1]))",
"+H = list(map(int, input().split()))",
"+Cost = [0 for i in range(N)]",
"+Cost[1] = abs(H[1] - H[0])",
"+for i in range(2, N):",
"+ Cost[i] = min(",
"+ Cost[i - 2] + abs(H[i] - H[i - 2]), Cost[i - 1] + abs(H[i] - H[i - 1])",
"+ )",
"+print((Cost[N - 1]))"
] | false | 0.041336 | 0.036959 | 1.118411 |
[
"s460568070",
"s844290286"
] |
u298297089
|
p02804
|
python
|
s350898184
|
s752195164
| 614 | 447 | 15,988 | 22,932 |
Accepted
|
Accepted
| 27.2 |
class Factorial:
def __init__(self, n, mod=10**9+7):
self.fac = [0] * (n+1)
self.ifac = [0] * (n+1)
self.fac[0] = 1
self.ifac[0] = 1
self.mod = mod
modmod = self.mod - 2
for i in range(n):
self.fac[i+1] = self.fac[i] * (i+1) % self.mod
self.ifac[i+1] = self.ifac[i] * pow(i+1, modmod, self.mod) % self.mod
def comb(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
tmp = self.ifac[n-r] * self.ifac[r] % self.mod
return tmp * self.fac[n] % self.mod
def perm(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
return (self.fac[n] * self.ifac[n-r]) % self.mod
def resolve():
n, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
mod = 10 ** 9 + 7
fact = Factorial(n + 1)
mn, mx = 0, 0
for i in range(k, n+1):
mx = (mx + a[i-1] * fact.comb(i-1, k-1)) % mod
mn = (mn + a[n-i] * fact.comb(i-1, k-1)) % mod
ans = mx - mn
if ans < 0:
ans += mod
print(ans)
if __name__ == "__main__":
resolve()
|
from itertools import accumulate
class Factorial:
def __init__(self, n, mod=10**9+7):
self.fac = [0] * (n+1)
self.ifac = [0] * (n+1)
self.fac[0] = 1
self.ifac[0] = 1
self.mod = mod
modmod = self.mod - 2
for i in range(n):
self.fac[i+1] = self.fac[i] * (i+1) % self.mod
self.ifac[i+1] = self.ifac[i] * pow(i+1, modmod, self.mod) % self.mod
def comb(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
tmp = self.ifac[n-r] * self.ifac[r] % self.mod
return tmp * self.fac[n] % self.mod
def perm(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
return (self.fac[n] * self.ifac[n-r]) % self.mod
def resolve():
n, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
mod = 10**9 + 7
fact = Factorial(n + 1)
lll = [fact.comb(i, k-1) for i in range(k-1, n)]
# acc = list(accumulate(lll))
ans = 0
for i in range(n-k+1):
# print(i, -1-i, f" --- {a[i]}, {a[-i-1]}, {lll[-i-1]}")
ans = (ans + (a[-i-1] - a[i]) * lll[-i-1]) % mod
print(ans)
if __name__ == "__main__":
resolve()
| 45 | 46 | 1,256 | 1,328 |
class Factorial:
def __init__(self, n, mod=10**9 + 7):
self.fac = [0] * (n + 1)
self.ifac = [0] * (n + 1)
self.fac[0] = 1
self.ifac[0] = 1
self.mod = mod
modmod = self.mod - 2
for i in range(n):
self.fac[i + 1] = self.fac[i] * (i + 1) % self.mod
self.ifac[i + 1] = self.ifac[i] * pow(i + 1, modmod, self.mod) % self.mod
def comb(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
tmp = self.ifac[n - r] * self.ifac[r] % self.mod
return tmp * self.fac[n] % self.mod
def perm(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
return (self.fac[n] * self.ifac[n - r]) % self.mod
def resolve():
n, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
mod = 10**9 + 7
fact = Factorial(n + 1)
mn, mx = 0, 0
for i in range(k, n + 1):
mx = (mx + a[i - 1] * fact.comb(i - 1, k - 1)) % mod
mn = (mn + a[n - i] * fact.comb(i - 1, k - 1)) % mod
ans = mx - mn
if ans < 0:
ans += mod
print(ans)
if __name__ == "__main__":
resolve()
|
from itertools import accumulate
class Factorial:
def __init__(self, n, mod=10**9 + 7):
self.fac = [0] * (n + 1)
self.ifac = [0] * (n + 1)
self.fac[0] = 1
self.ifac[0] = 1
self.mod = mod
modmod = self.mod - 2
for i in range(n):
self.fac[i + 1] = self.fac[i] * (i + 1) % self.mod
self.ifac[i + 1] = self.ifac[i] * pow(i + 1, modmod, self.mod) % self.mod
def comb(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
tmp = self.ifac[n - r] * self.ifac[r] % self.mod
return tmp * self.fac[n] % self.mod
def perm(self, n, r):
if n == 0 and r == 0:
return 1
if n < r or n < 0:
return 0
return (self.fac[n] * self.ifac[n - r]) % self.mod
def resolve():
n, k = list(map(int, input().split()))
a = sorted(map(int, input().split()))
mod = 10**9 + 7
fact = Factorial(n + 1)
lll = [fact.comb(i, k - 1) for i in range(k - 1, n)]
# acc = list(accumulate(lll))
ans = 0
for i in range(n - k + 1):
# print(i, -1-i, f" --- {a[i]}, {a[-i-1]}, {lll[-i-1]}")
ans = (ans + (a[-i - 1] - a[i]) * lll[-i - 1]) % mod
print(ans)
if __name__ == "__main__":
resolve()
| false | 2.173913 |
[
"+from itertools import accumulate",
"+",
"+",
"- mn, mx = 0, 0",
"- for i in range(k, n + 1):",
"- mx = (mx + a[i - 1] * fact.comb(i - 1, k - 1)) % mod",
"- mn = (mn + a[n - i] * fact.comb(i - 1, k - 1)) % mod",
"- ans = mx - mn",
"- if ans < 0:",
"- ans += mod",
"+ lll = [fact.comb(i, k - 1) for i in range(k - 1, n)]",
"+ # acc = list(accumulate(lll))",
"+ ans = 0",
"+ for i in range(n - k + 1):",
"+ ans = (ans + (a[-i - 1] - a[i]) * lll[-i - 1]) % mod"
] | false | 0.036616 | 0.03665 | 0.999067 |
[
"s350898184",
"s752195164"
] |
u936985471
|
p03618
|
python
|
s866031905
|
s823307126
| 78 | 30 | 3,500 | 3,560 |
Accepted
|
Accepted
| 61.54 |
a=eval(input())
dic={}
for i in range(len(a)):
s=a[i]
if s in dic:
dic[s]=dic[s]+1
else:
dic[s]=1
sum=0
for val in list(dic.values()):
if val>1:
sum=sum+(val-1)*val//2
print(((len(a)*(len(a)-1))//2-sum+1))
|
import sys
readline = sys.stdin.readline
A = readline().rstrip()
from collections import Counter
counter = Counter(A)
ans = 1 + (len(A) * (len(A) - 1)) // 2
for val in list(counter.values()):
ans -= (val * (val - 1)) // 2
print(ans)
| 15 | 14 | 229 | 248 |
a = eval(input())
dic = {}
for i in range(len(a)):
s = a[i]
if s in dic:
dic[s] = dic[s] + 1
else:
dic[s] = 1
sum = 0
for val in list(dic.values()):
if val > 1:
sum = sum + (val - 1) * val // 2
print(((len(a) * (len(a) - 1)) // 2 - sum + 1))
|
import sys
readline = sys.stdin.readline
A = readline().rstrip()
from collections import Counter
counter = Counter(A)
ans = 1 + (len(A) * (len(A) - 1)) // 2
for val in list(counter.values()):
ans -= (val * (val - 1)) // 2
print(ans)
| false | 6.666667 |
[
"-a = eval(input())",
"-dic = {}",
"-for i in range(len(a)):",
"- s = a[i]",
"- if s in dic:",
"- dic[s] = dic[s] + 1",
"- else:",
"- dic[s] = 1",
"-sum = 0",
"-for val in list(dic.values()):",
"- if val > 1:",
"- sum = sum + (val - 1) * val // 2",
"-print(((len(a) * (len(a) - 1)) // 2 - sum + 1))",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+A = readline().rstrip()",
"+from collections import Counter",
"+",
"+counter = Counter(A)",
"+ans = 1 + (len(A) * (len(A) - 1)) // 2",
"+for val in list(counter.values()):",
"+ ans -= (val * (val - 1)) // 2",
"+print(ans)"
] | false | 0.061434 | 0.057096 | 1.075969 |
[
"s866031905",
"s823307126"
] |
u581603131
|
p03338
|
python
|
s405712986
|
s411296864
| 20 | 18 | 3,064 | 3,060 |
Accepted
|
Accepted
| 10 |
N = int(eval(input()))
S = eval(input())
s = set(S)
count = 0
maxx = 0
for i in range(N): #切断場所
for k in range(i):
if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
count += 1
maxx = max(maxx, count)
count = 0
print(maxx)
|
N = int(eval(input()))
S = eval(input())
print((max(len(set(S[:i])&set(S[i:])) for i in range(N))))
| 12 | 3 | 260 | 87 |
N = int(eval(input()))
S = eval(input())
s = set(S)
count = 0
maxx = 0
for i in range(N): # 切断場所
for k in range(i):
if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
count += 1
maxx = max(maxx, count)
count = 0
print(maxx)
|
N = int(eval(input()))
S = eval(input())
print((max(len(set(S[:i]) & set(S[i:])) for i in range(N))))
| false | 75 |
[
"-s = set(S)",
"-count = 0",
"-maxx = 0",
"-for i in range(N): # 切断場所",
"- for k in range(i):",
"- if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:",
"- count += 1",
"- maxx = max(maxx, count)",
"- count = 0",
"-print(maxx)",
"+print((max(len(set(S[:i]) & set(S[i:])) for i in range(N))))"
] | false | 0.061865 | 0.047444 | 1.303948 |
[
"s405712986",
"s411296864"
] |
u645250356
|
p03379
|
python
|
s980558238
|
s304987442
| 457 | 194 | 86,656 | 33,712 |
Accepted
|
Accepted
| 57.55 |
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
b = sorted(a)
l,r = b[n//2-1],b[n//2]
for i in a:
if i <= l:
print(r)
else:
print(l)
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,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()
b = sorted(a)
mi = b[n//2-1]
ma = b[n//2]
for x in a:
print((ma if x <= mi else mi))
| 18 | 17 | 529 | 467 |
from collections import Counter, defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
b = sorted(a)
l, r = b[n // 2 - 1], b[n // 2]
for i in a:
if i <= l:
print(r)
else:
print(l)
|
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, 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()
b = sorted(a)
mi = b[n // 2 - 1]
ma = b[n // 2]
for x in a:
print((ma if x <= mi else mi))
| false | 5.555556 |
[
"-import sys, heapq, bisect, math, itertools, string, queue",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"-",
"-",
"-def inpln(n):",
"- return list(int(sys.stdin.readline()) for i in range(n))",
"-",
"-",
"-l, r = b[n // 2 - 1], b[n // 2]",
"-for i in a:",
"- if i <= l:",
"- print(r)",
"- else:",
"- print(l)",
"+mi = b[n // 2 - 1]",
"+ma = b[n // 2]",
"+for x in a:",
"+ print((ma if x <= mi else mi))"
] | false | 0.047786 | 0.053245 | 0.897487 |
[
"s980558238",
"s304987442"
] |
u489061952
|
p02983
|
python
|
s776279965
|
s121919995
| 1,038 | 72 | 3,060 | 3,060 |
Accepted
|
Accepted
| 93.06 |
l, r = (int(x) for x in input().split())
tmpmin = 2019
if r-l >= 2019:
print((0))
else:
for i in range(l, r):
for j in range(l+1, r+1):
tmp = (i*j)%2019
if tmp < tmpmin:
tmpmin = tmp
if tmpmin == 0:
break
print(tmpmin)
|
import sys
l, r = (int(x) for x in input().split())
tmpmin = 2019
if r-l >= 2019:
print((0))
else:
for i in range(l, r):
for j in range(l+1, r+1):
tmp = (i*j)%2019
if tmp < tmpmin:
tmpmin = tmp
if tmpmin == 0:
print(tmpmin)
sys.exit()
print(tmpmin)
| 13 | 15 | 324 | 376 |
l, r = (int(x) for x in input().split())
tmpmin = 2019
if r - l >= 2019:
print((0))
else:
for i in range(l, r):
for j in range(l + 1, r + 1):
tmp = (i * j) % 2019
if tmp < tmpmin:
tmpmin = tmp
if tmpmin == 0:
break
print(tmpmin)
|
import sys
l, r = (int(x) for x in input().split())
tmpmin = 2019
if r - l >= 2019:
print((0))
else:
for i in range(l, r):
for j in range(l + 1, r + 1):
tmp = (i * j) % 2019
if tmp < tmpmin:
tmpmin = tmp
if tmpmin == 0:
print(tmpmin)
sys.exit()
print(tmpmin)
| false | 13.333333 |
[
"+import sys",
"+",
"- break",
"+ print(tmpmin)",
"+ sys.exit()"
] | false | 0.047847 | 0.007281 | 6.571448 |
[
"s776279965",
"s121919995"
] |
u353797797
|
p02734
|
python
|
s464078252
|
s873638586
| 1,845 | 966 | 3,316 | 3,444 |
Accepted
|
Accepted
| 47.64 |
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
md = 998244353
n, s = MI()
aa = LI()
dp = [0] * (s + 1)
ans = 0
for a in aa:
dp[0] += 1
for i in range(s, a - 1, -1):
dp[i] += dp[i - a]
dp[i] %= md
ans += dp[s]
ans %= md
print(ans)
main()
|
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
md = 998244353
n, s = MI()
aa = LI()
dp = [0] * (s + 1)
ans = 0
for a in aa:
dp[0] += 1
for i in range(s, a - 1, -1):dp[i] += dp[i - a]
ans += dp[s]
print(ans%md)
main()
| 27 | 24 | 689 | 634 |
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
md = 998244353
n, s = MI()
aa = LI()
dp = [0] * (s + 1)
ans = 0
for a in aa:
dp[0] += 1
for i in range(s, a - 1, -1):
dp[i] += dp[i - a]
dp[i] %= md
ans += dp[s]
ans %= md
print(ans)
main()
|
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
md = 998244353
n, s = MI()
aa = LI()
dp = [0] * (s + 1)
ans = 0
for a in aa:
dp[0] += 1
for i in range(s, a - 1, -1):
dp[i] += dp[i - a]
ans += dp[s]
print(ans % md)
main()
| false | 11.111111 |
[
"- dp[i] %= md",
"- ans %= md",
"- print(ans)",
"+ print(ans % md)"
] | false | 0.036961 | 0.073853 | 0.500473 |
[
"s464078252",
"s873638586"
] |
u477320129
|
p03244
|
python
|
s196727849
|
s434725782
| 126 | 101 | 30,624 | 27,536 |
Accepted
|
Accepted
| 19.84 |
#!/usr/bin/env python3
import sys
def solve(n: int, v: "List[int]"):
from collections import Counter
a = sorted(list(Counter(v[::2]).items()), key=lambda x: (x[1], x[0]))
b = sorted(list(Counter(v[1::2]).items()), key=lambda x: (x[1], x[0]))
if a[-1][0] != b[-1][0]:
return n - a[-1][1] - b[-1][1]
a = [(0, 0)] + a
b = [(0, 0)] + b
return n - max(a[-1][1] + b[-2][1],
a[-2][1] + b[-1][1])
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
v = [int(next(tokens)) for _ in range(n)] # type: "List[int]"
print((solve(n, v)))
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
|
#!/usr/bin/env python3
import sys
def solve(n: int, v: "List[int]"):
from collections import Counter
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
if a[0][0] != b[0][0]:
return n - a[0][1] - b[0][1]
a = a + [(0, 0)]
b = b + [(0, 0)]
return n - max(a[0][1] + b[1][1],
a[1][1] + b[0][1])
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
v = [int(next(tokens)) for _ in range(n)] # type: "List[int]"
print((solve(n, v)))
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
| 34 | 34 | 937 | 869 |
#!/usr/bin/env python3
import sys
def solve(n: int, v: "List[int]"):
from collections import Counter
a = sorted(list(Counter(v[::2]).items()), key=lambda x: (x[1], x[0]))
b = sorted(list(Counter(v[1::2]).items()), key=lambda x: (x[1], x[0]))
if a[-1][0] != b[-1][0]:
return n - a[-1][1] - b[-1][1]
a = [(0, 0)] + a
b = [(0, 0)] + b
return n - max(a[-1][1] + b[-2][1], a[-2][1] + b[-1][1])
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
v = [int(next(tokens)) for _ in range(n)] # type: "List[int]"
print((solve(n, v)))
def test():
import doctest
doctest.testmod()
if __name__ == "__main__":
# test()
main()
|
#!/usr/bin/env python3
import sys
def solve(n: int, v: "List[int]"):
from collections import Counter
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
if a[0][0] != b[0][0]:
return n - a[0][1] - b[0][1]
a = a + [(0, 0)]
b = b + [(0, 0)]
return n - max(a[0][1] + b[1][1], a[1][1] + b[0][1])
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
v = [int(next(tokens)) for _ in range(n)] # type: "List[int]"
print((solve(n, v)))
def test():
import doctest
doctest.testmod()
if __name__ == "__main__":
# test()
main()
| false | 0 |
[
"- a = sorted(list(Counter(v[::2]).items()), key=lambda x: (x[1], x[0]))",
"- b = sorted(list(Counter(v[1::2]).items()), key=lambda x: (x[1], x[0]))",
"- if a[-1][0] != b[-1][0]:",
"- return n - a[-1][1] - b[-1][1]",
"- a = [(0, 0)] + a",
"- b = [(0, 0)] + b",
"- return n - max(a[-1][1] + b[-2][1], a[-2][1] + b[-1][1])",
"+ a = Counter(v[::2]).most_common()",
"+ b = Counter(v[1::2]).most_common()",
"+ if a[0][0] != b[0][0]:",
"+ return n - a[0][1] - b[0][1]",
"+ a = a + [(0, 0)]",
"+ b = b + [(0, 0)]",
"+ return n - max(a[0][1] + b[1][1], a[1][1] + b[0][1])"
] | false | 0.050936 | 0.051967 | 0.98015 |
[
"s196727849",
"s434725782"
] |
u046187684
|
p02948
|
python
|
s246775767
|
s438915401
| 434 | 397 | 25,876 | 25,840 |
Accepted
|
Accepted
| 8.53 |
import heapq
def solve(string):
n, m, *ab = list(map(int, string.split()))
ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
hq = []
index, cap, count = 0, 1, m
ans = 0
while index < n:
_a, _b = ab[index]
if _a > m:
break
if _a <= cap:
heapq.heappush(hq, -_b)
index += 1
else:
if len(hq) > 0:
ans += -heapq.heappop(hq)
count -= 1
cap += 1
for _ in range(count):
if len(hq) > 0:
ans += -heapq.heappop(hq)
return str(ans)
if __name__ == '__main__':
n, m = list(map(int, input().split()))
print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
|
import heapq
def solve(string):
n, m, *ab = list(map(int, string.split()))
ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
hq, index, cap, count, ans = [], 0, 1, m, 0
while index < n:
_a, _b = ab[index]
if _a > m:
break
if _a <= cap:
heapq.heappush(hq, -_b)
index += 1
else:
ans += -heapq.heappop(hq) if len(hq) > 0 else 0
count -= 1
cap += 1
ans += sum([-heapq.heappop(hq) if len(hq) > 0 else 0 for _ in range(count)])
return str(ans)
if __name__ == '__main__':
n, m = list(map(int, input().split()))
print((solve('{} {}\n'.format(n, m) + '\n'.join([eval(input()) for _ in range(n)]))))
| 30 | 25 | 770 | 739 |
import heapq
def solve(string):
n, m, *ab = list(map(int, string.split()))
ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
hq = []
index, cap, count = 0, 1, m
ans = 0
while index < n:
_a, _b = ab[index]
if _a > m:
break
if _a <= cap:
heapq.heappush(hq, -_b)
index += 1
else:
if len(hq) > 0:
ans += -heapq.heappop(hq)
count -= 1
cap += 1
for _ in range(count):
if len(hq) > 0:
ans += -heapq.heappop(hq)
return str(ans)
if __name__ == "__main__":
n, m = list(map(int, input().split()))
print(
(solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)])))
)
|
import heapq
def solve(string):
n, m, *ab = list(map(int, string.split()))
ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
hq, index, cap, count, ans = [], 0, 1, m, 0
while index < n:
_a, _b = ab[index]
if _a > m:
break
if _a <= cap:
heapq.heappush(hq, -_b)
index += 1
else:
ans += -heapq.heappop(hq) if len(hq) > 0 else 0
count -= 1
cap += 1
ans += sum([-heapq.heappop(hq) if len(hq) > 0 else 0 for _ in range(count)])
return str(ans)
if __name__ == "__main__":
n, m = list(map(int, input().split()))
print(
(solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)])))
)
| false | 16.666667 |
[
"- hq = []",
"- index, cap, count = 0, 1, m",
"- ans = 0",
"+ hq, index, cap, count, ans = [], 0, 1, m, 0",
"- if len(hq) > 0:",
"- ans += -heapq.heappop(hq)",
"+ ans += -heapq.heappop(hq) if len(hq) > 0 else 0",
"- for _ in range(count):",
"- if len(hq) > 0:",
"- ans += -heapq.heappop(hq)",
"+ ans += sum([-heapq.heappop(hq) if len(hq) > 0 else 0 for _ in range(count)])"
] | false | 0.049962 | 0.048878 | 1.022182 |
[
"s246775767",
"s438915401"
] |
u352394527
|
p00486
|
python
|
s558273012
|
s579607281
| 610 | 510 | 25,180 | 25,128 |
Accepted
|
Accepted
| 16.39 |
from bisect import bisect_left as bl
INF = 10 ** 20
def main():
w, h = list(map(int, input().split()))
n = int(eval(input()))
xlst = []
ylst = []
appx = xlst.append
appy = ylst.append
for i in range(n):
x, y = list(map(int,input().split()))
appx(x)
appy(y)
sorted_xlst = sorted(xlst)
sorted_ylst = sorted(ylst)
accx = accy = 0
cum_sum_xlst = []
cum_sum_ylst = []
appx = cum_sum_xlst.append
appy = cum_sum_ylst.append
for i in range(n):
accx += sorted_xlst[i]
accy += sorted_ylst[i]
appx(accx)
appy(accy)
if n % 2:
clx = crx = sorted_xlst[n // 2]
cly = cry = sorted_ylst[n // 2]
else:
clx = sorted_xlst[n // 2 - 1]
crx = sorted_xlst[n // 2]
cly = sorted_ylst[n // 2 - 1]
cry = sorted_ylst[n // 2]
plx = bl(sorted_xlst, clx)
prx = bl(sorted_xlst, crx)
ply = bl(sorted_ylst, cly)
pry = bl(sorted_ylst, cry)
ans = ansx = ansy = INF
for i in range(n):
xi = xlst[i]
yi = ylst[i]
if xi <= clx:
cx = crx
px = prx
else:
cx = clx
px = plx
if yi <= cly:
cy = cry
py = pry
else:
cy = cly
py = ply
dx = xi - cx
if dx < 0:
dx = -dx
if px:
csx = cum_sum_xlst[px - 1]
xlen = (accx - csx * 2 - cx * (n - px * 2)) * 2 - dx
else:
xlen = (accx - cx * n) * 2 - dx
dy = yi - cy
if dy < 0:
dy = -dy
if py:
csy = cum_sum_ylst[py - 1]
ylen = (accy - csy * 2 - cy * (n - py * 2)) * 2 - dy
else:
ylen = (accy - cy * n) * 2 - dy
tlen = xlen + ylen
if ans > tlen:
ans = tlen
ansx = cx
ansy = cy
elif ans == tlen:
if ansx > cx:
ansx = cx
ansy = cy
elif ansx == cx:
if ansy > cy:
ansy = cy
print(ans)
print((ansx, ansy))
main()
|
from bisect import bisect_left as bl
INF = 10 ** 20
def main():
w, h = list(map(int, input().split()))
n = int(eval(input()))
xlst = []
ylst = []
appx = xlst.append
appy = ylst.append
for i in range(n):
x, y = list(map(int,input().split()))
appx(x)
appy(y)
sorted_xlst = sorted(xlst)
sorted_ylst = sorted(ylst)
accx = accy = 0
cum_sum_xlst = []
cum_sum_ylst = []
appx = cum_sum_xlst.append
appy = cum_sum_ylst.append
for i in range(n):
accx += sorted_xlst[i]
accy += sorted_ylst[i]
appx(accx)
appy(accy)
if n % 2:
clx = crx = sorted_xlst[n // 2]
cly = cry = sorted_ylst[n // 2]
else:
clx = sorted_xlst[n // 2 - 1]
crx = sorted_xlst[n // 2]
cly = sorted_ylst[n // 2 - 1]
cry = sorted_ylst[n // 2]
plx = bl(sorted_xlst, clx)
prx = bl(sorted_xlst, crx)
ply = bl(sorted_ylst, cly)
pry = bl(sorted_ylst, cry)
xllen = (accx - cum_sum_xlst[plx - 1] * 2 - clx * (n - plx * 2)) * 2 if plx != 0 else (accx - clx * n) * 2
xrlen = (accx - cum_sum_xlst[prx - 1] * 2 - crx * (n - prx * 2)) * 2 if prx != 0 else (accx - crx * n) * 2
yllen = (accy - cum_sum_ylst[ply - 1] * 2 - cly * (n - ply * 2)) * 2 if ply != 0 else (accy - cly * n) * 2
yrlen = (accy - cum_sum_ylst[pry - 1] * 2 - cry * (n - pry * 2)) * 2 if pry != 0 else (accy - cry * n) * 2
ans = ansx = ansy = INF
max_sumd = 0
for i in range(n):
xi = xlst[i]
yi = ylst[i]
if xi <= clx:
cx = crx
xlen = xrlen
else:
cx = clx
xlen = xllen
if yi <= cly:
cy = cry
ylen = yrlen
else:
cy = cly
ylen = yllen
dx = xi - cx
if dx < 0:
dx = -dx
dy = yi - cy
if dy < 0:
dy = -dy
if max_sumd > dx + dy:
continue
else:
max_sumd = dx + dy
tlen = xlen + ylen - max_sumd
if ans > tlen:
ans = tlen
ansx = cx
ansy = cy
elif ans == tlen:
if ansx > cx:
ansx = cx
ansy = cy
elif ansx == cx:
if ansy > cy:
ansy = cy
print(ans)
print((ansx, ansy))
main()
| 103 | 101 | 1,953 | 2,197 |
from bisect import bisect_left as bl
INF = 10**20
def main():
w, h = list(map(int, input().split()))
n = int(eval(input()))
xlst = []
ylst = []
appx = xlst.append
appy = ylst.append
for i in range(n):
x, y = list(map(int, input().split()))
appx(x)
appy(y)
sorted_xlst = sorted(xlst)
sorted_ylst = sorted(ylst)
accx = accy = 0
cum_sum_xlst = []
cum_sum_ylst = []
appx = cum_sum_xlst.append
appy = cum_sum_ylst.append
for i in range(n):
accx += sorted_xlst[i]
accy += sorted_ylst[i]
appx(accx)
appy(accy)
if n % 2:
clx = crx = sorted_xlst[n // 2]
cly = cry = sorted_ylst[n // 2]
else:
clx = sorted_xlst[n // 2 - 1]
crx = sorted_xlst[n // 2]
cly = sorted_ylst[n // 2 - 1]
cry = sorted_ylst[n // 2]
plx = bl(sorted_xlst, clx)
prx = bl(sorted_xlst, crx)
ply = bl(sorted_ylst, cly)
pry = bl(sorted_ylst, cry)
ans = ansx = ansy = INF
for i in range(n):
xi = xlst[i]
yi = ylst[i]
if xi <= clx:
cx = crx
px = prx
else:
cx = clx
px = plx
if yi <= cly:
cy = cry
py = pry
else:
cy = cly
py = ply
dx = xi - cx
if dx < 0:
dx = -dx
if px:
csx = cum_sum_xlst[px - 1]
xlen = (accx - csx * 2 - cx * (n - px * 2)) * 2 - dx
else:
xlen = (accx - cx * n) * 2 - dx
dy = yi - cy
if dy < 0:
dy = -dy
if py:
csy = cum_sum_ylst[py - 1]
ylen = (accy - csy * 2 - cy * (n - py * 2)) * 2 - dy
else:
ylen = (accy - cy * n) * 2 - dy
tlen = xlen + ylen
if ans > tlen:
ans = tlen
ansx = cx
ansy = cy
elif ans == tlen:
if ansx > cx:
ansx = cx
ansy = cy
elif ansx == cx:
if ansy > cy:
ansy = cy
print(ans)
print((ansx, ansy))
main()
|
from bisect import bisect_left as bl
INF = 10**20
def main():
w, h = list(map(int, input().split()))
n = int(eval(input()))
xlst = []
ylst = []
appx = xlst.append
appy = ylst.append
for i in range(n):
x, y = list(map(int, input().split()))
appx(x)
appy(y)
sorted_xlst = sorted(xlst)
sorted_ylst = sorted(ylst)
accx = accy = 0
cum_sum_xlst = []
cum_sum_ylst = []
appx = cum_sum_xlst.append
appy = cum_sum_ylst.append
for i in range(n):
accx += sorted_xlst[i]
accy += sorted_ylst[i]
appx(accx)
appy(accy)
if n % 2:
clx = crx = sorted_xlst[n // 2]
cly = cry = sorted_ylst[n // 2]
else:
clx = sorted_xlst[n // 2 - 1]
crx = sorted_xlst[n // 2]
cly = sorted_ylst[n // 2 - 1]
cry = sorted_ylst[n // 2]
plx = bl(sorted_xlst, clx)
prx = bl(sorted_xlst, crx)
ply = bl(sorted_ylst, cly)
pry = bl(sorted_ylst, cry)
xllen = (
(accx - cum_sum_xlst[plx - 1] * 2 - clx * (n - plx * 2)) * 2
if plx != 0
else (accx - clx * n) * 2
)
xrlen = (
(accx - cum_sum_xlst[prx - 1] * 2 - crx * (n - prx * 2)) * 2
if prx != 0
else (accx - crx * n) * 2
)
yllen = (
(accy - cum_sum_ylst[ply - 1] * 2 - cly * (n - ply * 2)) * 2
if ply != 0
else (accy - cly * n) * 2
)
yrlen = (
(accy - cum_sum_ylst[pry - 1] * 2 - cry * (n - pry * 2)) * 2
if pry != 0
else (accy - cry * n) * 2
)
ans = ansx = ansy = INF
max_sumd = 0
for i in range(n):
xi = xlst[i]
yi = ylst[i]
if xi <= clx:
cx = crx
xlen = xrlen
else:
cx = clx
xlen = xllen
if yi <= cly:
cy = cry
ylen = yrlen
else:
cy = cly
ylen = yllen
dx = xi - cx
if dx < 0:
dx = -dx
dy = yi - cy
if dy < 0:
dy = -dy
if max_sumd > dx + dy:
continue
else:
max_sumd = dx + dy
tlen = xlen + ylen - max_sumd
if ans > tlen:
ans = tlen
ansx = cx
ansy = cy
elif ans == tlen:
if ansx > cx:
ansx = cx
ansy = cy
elif ansx == cx:
if ansy > cy:
ansy = cy
print(ans)
print((ansx, ansy))
main()
| false | 1.941748 |
[
"+ xllen = (",
"+ (accx - cum_sum_xlst[plx - 1] * 2 - clx * (n - plx * 2)) * 2",
"+ if plx != 0",
"+ else (accx - clx * n) * 2",
"+ )",
"+ xrlen = (",
"+ (accx - cum_sum_xlst[prx - 1] * 2 - crx * (n - prx * 2)) * 2",
"+ if prx != 0",
"+ else (accx - crx * n) * 2",
"+ )",
"+ yllen = (",
"+ (accy - cum_sum_ylst[ply - 1] * 2 - cly * (n - ply * 2)) * 2",
"+ if ply != 0",
"+ else (accy - cly * n) * 2",
"+ )",
"+ yrlen = (",
"+ (accy - cum_sum_ylst[pry - 1] * 2 - cry * (n - pry * 2)) * 2",
"+ if pry != 0",
"+ else (accy - cry * n) * 2",
"+ )",
"+ max_sumd = 0",
"- px = prx",
"+ xlen = xrlen",
"- px = plx",
"+ xlen = xllen",
"- py = pry",
"+ ylen = yrlen",
"- py = ply",
"+ ylen = yllen",
"- if px:",
"- csx = cum_sum_xlst[px - 1]",
"- xlen = (accx - csx * 2 - cx * (n - px * 2)) * 2 - dx",
"- else:",
"- xlen = (accx - cx * n) * 2 - dx",
"- if py:",
"- csy = cum_sum_ylst[py - 1]",
"- ylen = (accy - csy * 2 - cy * (n - py * 2)) * 2 - dy",
"+ if max_sumd > dx + dy:",
"+ continue",
"- ylen = (accy - cy * n) * 2 - dy",
"- tlen = xlen + ylen",
"+ max_sumd = dx + dy",
"+ tlen = xlen + ylen - max_sumd"
] | false | 0.049416 | 0.126658 | 0.390151 |
[
"s558273012",
"s579607281"
] |
u022407960
|
p02317
|
python
|
s102506287
|
s202113611
| 220 | 180 | 19,524 | 19,504 |
Accepted
|
Accepted
| 18.18 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5
5
1
3
2
4
or
3
1
1
1
output:
3
or
1
"""
import sys
from bisect import bisect_left
def solve():
dis_rec = [float('inf')] * array_length
dis_rec[0] = array[0]
length = 1
for j in range(1, array_length):
if dis_rec[length - 1] < array[j]:
dis_rec[length] = array[j]
length += 1
else:
position = bisect_left(dis_rec, array[j])
dis_rec[position] = array[j]
return length
if __name__ == '__main__':
_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1:]))
print((solve()))
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5
5
1
3
2
4
or
3
1
1
1
output:
3
or
1
"""
import sys
from bisect import bisect_left
def solve():
dis_rec = [float('inf')] * array_length
dis_rec[0] = array[0]
length = 1
for i, ele in enumerate(array, 1):
if dis_rec[length - 1] < ele:
dis_rec[length] = ele
length += 1
else:
position = bisect_left(dis_rec, ele)
dis_rec[position] = ele
return length
if __name__ == '__main__':
_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1:]))
print((solve()))
| 50 | 52 | 722 | 709 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5
5
1
3
2
4
or
3
1
1
1
output:
3
or
1
"""
import sys
from bisect import bisect_left
def solve():
dis_rec = [float("inf")] * array_length
dis_rec[0] = array[0]
length = 1
for j in range(1, array_length):
if dis_rec[length - 1] < array[j]:
dis_rec[length] = array[j]
length += 1
else:
position = bisect_left(dis_rec, array[j])
dis_rec[position] = array[j]
return length
if __name__ == "__main__":
_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1:]))
print((solve()))
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5
5
1
3
2
4
or
3
1
1
1
output:
3
or
1
"""
import sys
from bisect import bisect_left
def solve():
dis_rec = [float("inf")] * array_length
dis_rec[0] = array[0]
length = 1
for i, ele in enumerate(array, 1):
if dis_rec[length - 1] < ele:
dis_rec[length] = ele
length += 1
else:
position = bisect_left(dis_rec, ele)
dis_rec[position] = ele
return length
if __name__ == "__main__":
_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1:]))
print((solve()))
| false | 3.846154 |
[
"- for j in range(1, array_length):",
"- if dis_rec[length - 1] < array[j]:",
"- dis_rec[length] = array[j]",
"+ for i, ele in enumerate(array, 1):",
"+ if dis_rec[length - 1] < ele:",
"+ dis_rec[length] = ele",
"- position = bisect_left(dis_rec, array[j])",
"- dis_rec[position] = array[j]",
"+ position = bisect_left(dis_rec, ele)",
"+ dis_rec[position] = ele"
] | false | 0.033608 | 0.036648 | 0.917053 |
[
"s102506287",
"s202113611"
] |
u426534722
|
p02265
|
python
|
s519753224
|
s632321766
| 2,170 | 1,660 | 45,944 | 69,732 |
Accepted
|
Accepted
| 23.5 |
import sys
from collections import deque
readline = sys.stdin.readline
dq = deque()
for _ in range(int(eval(input()))):
ss = readline().strip()
if ss == "deleteFirst":
del dq[0]
elif ss == "deleteLast":
del dq[-1]
else:
c, s = ss.split()
s = int(s)
if c == "insert":
dq.appendleft(s)
elif c == "delete":
if s in dq:
dq.remove(s)
print((*dq))
|
import sys
from collections import deque
readline = sys.stdin.readline
dq = deque()
for _ in range(int(eval(input()))):
c = readline().split()
if c[0] == "deleteFirst":
del dq[0]
elif c[0] == "deleteLast":
del dq[-1]
else:
if c[0] == "insert":
dq.appendleft(c[1])
elif c[0] == "delete":
if c[1] in dq:
dq.remove(c[1])
print((*dq))
| 20 | 18 | 458 | 429 |
import sys
from collections import deque
readline = sys.stdin.readline
dq = deque()
for _ in range(int(eval(input()))):
ss = readline().strip()
if ss == "deleteFirst":
del dq[0]
elif ss == "deleteLast":
del dq[-1]
else:
c, s = ss.split()
s = int(s)
if c == "insert":
dq.appendleft(s)
elif c == "delete":
if s in dq:
dq.remove(s)
print((*dq))
|
import sys
from collections import deque
readline = sys.stdin.readline
dq = deque()
for _ in range(int(eval(input()))):
c = readline().split()
if c[0] == "deleteFirst":
del dq[0]
elif c[0] == "deleteLast":
del dq[-1]
else:
if c[0] == "insert":
dq.appendleft(c[1])
elif c[0] == "delete":
if c[1] in dq:
dq.remove(c[1])
print((*dq))
| false | 10 |
[
"- ss = readline().strip()",
"- if ss == \"deleteFirst\":",
"+ c = readline().split()",
"+ if c[0] == \"deleteFirst\":",
"- elif ss == \"deleteLast\":",
"+ elif c[0] == \"deleteLast\":",
"- c, s = ss.split()",
"- s = int(s)",
"- if c == \"insert\":",
"- dq.appendleft(s)",
"- elif c == \"delete\":",
"- if s in dq:",
"- dq.remove(s)",
"+ if c[0] == \"insert\":",
"+ dq.appendleft(c[1])",
"+ elif c[0] == \"delete\":",
"+ if c[1] in dq:",
"+ dq.remove(c[1])"
] | false | 0.041613 | 0.036963 | 1.125799 |
[
"s519753224",
"s632321766"
] |
u994988729
|
p03682
|
python
|
s902557857
|
s926251682
| 1,527 | 1,118 | 47,048 | 45,240 |
Accepted
|
Accepted
| 26.78 |
import heapq
N = int(eval(input()))
town = []
for i in range(N):
x, y = list(map(int, input().split()))
town.append((x, y, i))
uf = [i for i in range(N)] #uf[i]==iであれば根
def root(x):
if x == uf[x]:
return x
else:
r = root(uf[x])
uf[x] = r
return r
def isSame(x,y):
return root(x) == root(y)
def unite(x, y):
x = root(x)
y = root(y)
if x==y:
return
uf[x] = y
return
road = []
town.sort() #x座標でソート O(NlogN + N)
for i in range(N-1):
x1, _, ind1 = town[i]
x2, _, ind2 = town[i+1]
cost = abs(x2 - x1)
heapq.heappush(road, (cost, ind1, ind2))
town.sort(key = lambda x:x[1]) #y座標でソート O(NlogN + N)
for i in range(N-1):
_, x1, ind1 = town[i]
_, x2, ind2 = town[i+1]
cost = abs(x2 - x1)
heapq.heappush(road, (cost, ind1, ind2))
ans = 0
while road: #O(2N)
cost, i, j = heapq.heappop(road)
if isSame(i,j):
continue
unite(i, j)
ans += cost
print(ans)
|
from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数
self.rank = [0] * (n + 1)
def find(self, x): # xの根となる要素番号を返す
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def getNodeLen(self, x):
return -self.root[self.find(x)]
if __name__ == "__main__":
N = int(eval(input()))
XY = []
for i in range(N):
x, y = list(map(int, input().split()))
XY.append((x, y, i))
edge = []
XY.sort()
for (x1, _, i), (x2, _, j) in zip(XY[:-1], XY[1:]):
edge.append((x2 - x1, i, j))
XY.sort(key=itemgetter(1))
for (_, x1, i), (_, x2, j) in zip(XY[:-1], XY[1:]):
edge.append((x2 - x1, i, j))
uf = UF_tree(N + 10)
edge.sort()
ans = 0
for cost, x, y in edge:
if uf.isSame(x, y):
continue
uf.unite(x, y)
ans += cost
print(ans)
| 51 | 64 | 1,023 | 1,622 |
import heapq
N = int(eval(input()))
town = []
for i in range(N):
x, y = list(map(int, input().split()))
town.append((x, y, i))
uf = [i for i in range(N)] # uf[i]==iであれば根
def root(x):
if x == uf[x]:
return x
else:
r = root(uf[x])
uf[x] = r
return r
def isSame(x, y):
return root(x) == root(y)
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
uf[x] = y
return
road = []
town.sort() # x座標でソート O(NlogN + N)
for i in range(N - 1):
x1, _, ind1 = town[i]
x2, _, ind2 = town[i + 1]
cost = abs(x2 - x1)
heapq.heappush(road, (cost, ind1, ind2))
town.sort(key=lambda x: x[1]) # y座標でソート O(NlogN + N)
for i in range(N - 1):
_, x1, ind1 = town[i]
_, x2, ind2 = town[i + 1]
cost = abs(x2 - x1)
heapq.heappush(road, (cost, ind1, ind2))
ans = 0
while road: # O(2N)
cost, i, j = heapq.heappop(road)
if isSame(i, j):
continue
unite(i, j)
ans += cost
print(ans)
|
from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数
self.rank = [0] * (n + 1)
def find(self, x): # xの根となる要素番号を返す
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def getNodeLen(self, x):
return -self.root[self.find(x)]
if __name__ == "__main__":
N = int(eval(input()))
XY = []
for i in range(N):
x, y = list(map(int, input().split()))
XY.append((x, y, i))
edge = []
XY.sort()
for (x1, _, i), (x2, _, j) in zip(XY[:-1], XY[1:]):
edge.append((x2 - x1, i, j))
XY.sort(key=itemgetter(1))
for (_, x1, i), (_, x2, j) in zip(XY[:-1], XY[1:]):
edge.append((x2 - x1, i, j))
uf = UF_tree(N + 10)
edge.sort()
ans = 0
for cost, x, y in edge:
if uf.isSame(x, y):
continue
uf.unite(x, y)
ans += cost
print(ans)
| false | 20.3125 |
[
"-import heapq",
"+from operator import itemgetter",
"+import sys",
"-N = int(eval(input()))",
"-town = []",
"-for i in range(N):",
"- x, y = list(map(int, input().split()))",
"- town.append((x, y, i))",
"-uf = [i for i in range(N)] # uf[i]==iであれば根",
"+input = sys.stdin.buffer.readline",
"+sys.setrecursionlimit(10**7)",
"-def root(x):",
"- if x == uf[x]:",
"- return x",
"- else:",
"- r = root(uf[x])",
"- uf[x] = r",
"- return r",
"+class UF_tree:",
"+ def __init__(self, n):",
"+ self.root = [-1] * (n + 1) # -1ならそのノードが根,で絶対値が木の要素数",
"+ self.rank = [0] * (n + 1)",
"+",
"+ def find(self, x): # xの根となる要素番号を返す",
"+ if self.root[x] < 0:",
"+ return x",
"+ else:",
"+ self.root[x] = self.find(self.root[x])",
"+ return self.root[x]",
"+",
"+ def isSame(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def unite(self, x, y):",
"+ x = self.find(x)",
"+ y = self.find(y)",
"+ if x == y:",
"+ return",
"+ elif self.rank[x] < self.rank[y]:",
"+ self.root[y] += self.root[x]",
"+ self.root[x] = y",
"+ else:",
"+ self.root[x] += self.root[y]",
"+ self.root[y] = x",
"+ if self.rank[x] == self.rank[y]:",
"+ self.rank[x] += 1",
"+",
"+ def getNodeLen(self, x):",
"+ return -self.root[self.find(x)]",
"-def isSame(x, y):",
"- return root(x) == root(y)",
"-",
"-",
"-def unite(x, y):",
"- x = root(x)",
"- y = root(y)",
"- if x == y:",
"- return",
"- uf[x] = y",
"- return",
"-",
"-",
"-road = []",
"-town.sort() # x座標でソート O(NlogN + N)",
"-for i in range(N - 1):",
"- x1, _, ind1 = town[i]",
"- x2, _, ind2 = town[i + 1]",
"- cost = abs(x2 - x1)",
"- heapq.heappush(road, (cost, ind1, ind2))",
"-town.sort(key=lambda x: x[1]) # y座標でソート O(NlogN + N)",
"-for i in range(N - 1):",
"- _, x1, ind1 = town[i]",
"- _, x2, ind2 = town[i + 1]",
"- cost = abs(x2 - x1)",
"- heapq.heappush(road, (cost, ind1, ind2))",
"-ans = 0",
"-while road: # O(2N)",
"- cost, i, j = heapq.heappop(road)",
"- if isSame(i, j):",
"- continue",
"- unite(i, j)",
"- ans += cost",
"-print(ans)",
"+if __name__ == \"__main__\":",
"+ N = int(eval(input()))",
"+ XY = []",
"+ for i in range(N):",
"+ x, y = list(map(int, input().split()))",
"+ XY.append((x, y, i))",
"+ edge = []",
"+ XY.sort()",
"+ for (x1, _, i), (x2, _, j) in zip(XY[:-1], XY[1:]):",
"+ edge.append((x2 - x1, i, j))",
"+ XY.sort(key=itemgetter(1))",
"+ for (_, x1, i), (_, x2, j) in zip(XY[:-1], XY[1:]):",
"+ edge.append((x2 - x1, i, j))",
"+ uf = UF_tree(N + 10)",
"+ edge.sort()",
"+ ans = 0",
"+ for cost, x, y in edge:",
"+ if uf.isSame(x, y):",
"+ continue",
"+ uf.unite(x, y)",
"+ ans += cost",
"+ print(ans)"
] | false | 0.037829 | 0.037702 | 1.003381 |
[
"s902557857",
"s926251682"
] |
u338225045
|
p03495
|
python
|
s216074603
|
s502775487
| 119 | 99 | 24,748 | 24,996 |
Accepted
|
Accepted
| 16.81 |
N, K = list(map( int, input().split() ))
A = list( map( int, input().split() ) )
numAppeared = [0] * (N+1)
for i in A:
numAppeared[i] += 1
numAppeared.sort( reverse=True )
print(( sum( numAppeared[i] for i in range(K,N) ) ))
|
N, K = list(map( int, input().split() ))
A = list( map( int, input().split() ) )
numAppeared = [0] * (N+1)
for i in A:
numAppeared[i] += 1
numAppeared.sort( reverse=True )
# print( sum( numAppeared[i] for i in range(K,N) ) )
print(( sum( numAppeared[K:N] ) ))
| 11 | 12 | 234 | 270 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
numAppeared = [0] * (N + 1)
for i in A:
numAppeared[i] += 1
numAppeared.sort(reverse=True)
print((sum(numAppeared[i] for i in range(K, N))))
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
numAppeared = [0] * (N + 1)
for i in A:
numAppeared[i] += 1
numAppeared.sort(reverse=True)
# print( sum( numAppeared[i] for i in range(K,N) ) )
print((sum(numAppeared[K:N])))
| false | 8.333333 |
[
"-print((sum(numAppeared[i] for i in range(K, N))))",
"+# print( sum( numAppeared[i] for i in range(K,N) ) )",
"+print((sum(numAppeared[K:N])))"
] | false | 0.194023 | 0.041688 | 4.65414 |
[
"s216074603",
"s502775487"
] |
u294520705
|
p02995
|
python
|
s051485701
|
s014027158
| 35 | 18 | 5,088 | 3,064 |
Accepted
|
Accepted
| 48.57 |
import fractions
import sys
input = sys.stdin.readline# 最小公倍数
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
|
import sys
import math
input = sys.stdin.readline# 最小公倍数
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(x, y):
return (x * y) // gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
| 20 | 26 | 655 | 714 |
import fractions
import sys
input = sys.stdin.readline # 最小公倍数
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
# print("e: {}".format(e))
# print("c: {} - {}".format(b // c, (a - 1) // c))
# print("d: {} - {}".format(b // d, (a - 1) // d))
# print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
# print("count_c: {}".format(count_c))
# print("count_d: {}".format(count_d))
# print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
|
import sys
import math
input = sys.stdin.readline # 最小公倍数
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(x, y):
return (x * y) // gcd(x, y)
a, b, c, d = list(map(int, input().split()))
e = lcm(c, d)
# print("e: {}".format(e))
# print("c: {} - {}".format(b // c, (a - 1) // c))
# print("d: {} - {}".format(b // d, (a - 1) // d))
# print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
# print("count_c: {}".format(count_c))
# print("count_d: {}".format(count_d))
# print("count_e: {}".format(count_e))
print((b - a + 1 - (count_c + count_d - count_e)))
| false | 23.076923 |
[
"-import fractions",
"+import math",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"- return (x * y) // fractions.gcd(x, y)",
"+ return (x * y) // gcd(x, y)"
] | false | 0.098318 | 0.072998 | 1.346853 |
[
"s051485701",
"s014027158"
] |
u021548497
|
p03137
|
python
|
s671956416
|
s368038359
| 164 | 112 | 13,960 | 13,832 |
Accepted
|
Accepted
| 31.71 |
import sys
import heapq
inf = 10**6
n, m = list(map(int, input().split()))
if n >= m:
print((0))
sys.exit()
a = [int(x) for x in input().split()]
a.sort()
count = []
heapq.heapify(count)
for i in range(m-1):
heapq.heappush(count, -a[i+1]+a[i])
ans = 0
for j in range(n-1):
ans -= heapq.heappop(count)
ans = max(a)-min(a)-ans
print(ans)
|
m, n = list(map(int, input().split()))
a = [int(x) for x in input().split()]
a.sort()
b = [a[i+1]-a[i] for i in range(n-1)]
b.sort(reverse=True)
print((a[-1]-a[0]-sum(b[:min([m-1, n-1])])))
| 22 | 7 | 360 | 188 |
import sys
import heapq
inf = 10**6
n, m = list(map(int, input().split()))
if n >= m:
print((0))
sys.exit()
a = [int(x) for x in input().split()]
a.sort()
count = []
heapq.heapify(count)
for i in range(m - 1):
heapq.heappush(count, -a[i + 1] + a[i])
ans = 0
for j in range(n - 1):
ans -= heapq.heappop(count)
ans = max(a) - min(a) - ans
print(ans)
|
m, n = list(map(int, input().split()))
a = [int(x) for x in input().split()]
a.sort()
b = [a[i + 1] - a[i] for i in range(n - 1)]
b.sort(reverse=True)
print((a[-1] - a[0] - sum(b[: min([m - 1, n - 1])])))
| false | 68.181818 |
[
"-import sys",
"-import heapq",
"-",
"-inf = 10**6",
"-n, m = list(map(int, input().split()))",
"-if n >= m:",
"- print((0))",
"- sys.exit()",
"+m, n = list(map(int, input().split()))",
"-count = []",
"-heapq.heapify(count)",
"-for i in range(m - 1):",
"- heapq.heappush(count, -a[i + 1] + a[i])",
"-ans = 0",
"-for j in range(n - 1):",
"- ans -= heapq.heappop(count)",
"-ans = max(a) - min(a) - ans",
"-print(ans)",
"+b = [a[i + 1] - a[i] for i in range(n - 1)]",
"+b.sort(reverse=True)",
"+print((a[-1] - a[0] - sum(b[: min([m - 1, n - 1])])))"
] | false | 0.041218 | 0.037157 | 1.10929 |
[
"s671956416",
"s368038359"
] |
u951289777
|
p04044
|
python
|
s953528864
|
s681705309
| 19 | 17 | 3,064 | 3,060 |
Accepted
|
Accepted
| 10.53 |
n_and_l = eval(input())
n, l = list(map(int, n_and_l.split()))
text = []
for num in range(0, n):
text.append(eval(input()))
for object in range(1, n):
for compare in range(0, object):
if text[object] < text[compare]:
tmp = text[object]
text[object] = text[compare]
text[compare] = tmp
answer = ""
for num in range(0, n):
answer = answer + text[num]
print(answer)
|
num, len = list(map(int, input().split()))
strings = []
for n in range(num):
strings.append(eval(input()))
strings.sort()
print((''.join(strings)))
| 25 | 9 | 434 | 148 |
n_and_l = eval(input())
n, l = list(map(int, n_and_l.split()))
text = []
for num in range(0, n):
text.append(eval(input()))
for object in range(1, n):
for compare in range(0, object):
if text[object] < text[compare]:
tmp = text[object]
text[object] = text[compare]
text[compare] = tmp
answer = ""
for num in range(0, n):
answer = answer + text[num]
print(answer)
|
num, len = list(map(int, input().split()))
strings = []
for n in range(num):
strings.append(eval(input()))
strings.sort()
print(("".join(strings)))
| false | 64 |
[
"-n_and_l = eval(input())",
"-n, l = list(map(int, n_and_l.split()))",
"-text = []",
"-for num in range(0, n):",
"- text.append(eval(input()))",
"-for object in range(1, n):",
"- for compare in range(0, object):",
"- if text[object] < text[compare]:",
"- tmp = text[object]",
"- text[object] = text[compare]",
"- text[compare] = tmp",
"-answer = \"\"",
"-for num in range(0, n):",
"- answer = answer + text[num]",
"-print(answer)",
"+num, len = list(map(int, input().split()))",
"+strings = []",
"+for n in range(num):",
"+ strings.append(eval(input()))",
"+strings.sort()",
"+print((\"\".join(strings)))"
] | false | 0.059799 | 0.04174 | 1.432634 |
[
"s953528864",
"s681705309"
] |
u583276018
|
p02701
|
python
|
s711530004
|
s842592362
| 331 | 269 | 35,192 | 35,456 |
Accepted
|
Accepted
| 18.73 |
stock = {}
for _ in range(int(eval(input()))):
s = eval(input())
try:
stock[s] += 1
except KeyError:
stock[s] = 1
print((len(stock)))
|
n = int(eval(input()))
stock = []
for _ in range(n):
stock.append(eval(input()))
print((len(set(stock))))
| 8 | 5 | 140 | 98 |
stock = {}
for _ in range(int(eval(input()))):
s = eval(input())
try:
stock[s] += 1
except KeyError:
stock[s] = 1
print((len(stock)))
|
n = int(eval(input()))
stock = []
for _ in range(n):
stock.append(eval(input()))
print((len(set(stock))))
| false | 37.5 |
[
"-stock = {}",
"-for _ in range(int(eval(input()))):",
"- s = eval(input())",
"- try:",
"- stock[s] += 1",
"- except KeyError:",
"- stock[s] = 1",
"-print((len(stock)))",
"+n = int(eval(input()))",
"+stock = []",
"+for _ in range(n):",
"+ stock.append(eval(input()))",
"+print((len(set(stock))))"
] | false | 0.086307 | 0.079461 | 1.086156 |
[
"s711530004",
"s842592362"
] |
u492994678
|
p03029
|
python
|
s044938053
|
s215217305
| 19 | 17 | 2,940 | 3,064 |
Accepted
|
Accepted
| 10.53 |
A,P = list(map(int,input().split()))
a=((P + A * 3) // 2)
print(a)
|
A,P = list(map(int,input().split()))
print(((P + A * 3) // 2))
| 6 | 2 | 68 | 56 |
A, P = list(map(int, input().split()))
a = (P + A * 3) // 2
print(a)
|
A, P = list(map(int, input().split()))
print(((P + A * 3) // 2))
| false | 66.666667 |
[
"-a = (P + A * 3) // 2",
"-print(a)",
"+print(((P + A * 3) // 2))"
] | false | 0.039559 | 0.038579 | 1.025419 |
[
"s044938053",
"s215217305"
] |
u693953100
|
p02915
|
python
|
s915946910
|
s126442915
| 20 | 17 | 3,316 | 2,940 |
Accepted
|
Accepted
| 15 |
n = int(eval(input()))
print((n**3))
|
def solve():
n = int(eval(input()))
print((n**3))
if __name__ == "__main__":
solve()
| 2 | 5 | 29 | 92 |
n = int(eval(input()))
print((n**3))
|
def solve():
n = int(eval(input()))
print((n**3))
if __name__ == "__main__":
solve()
| false | 60 |
[
"-n = int(eval(input()))",
"-print((n**3))",
"+def solve():",
"+ n = int(eval(input()))",
"+ print((n**3))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.047612 | 0.048021 | 0.99147 |
[
"s915946910",
"s126442915"
] |
u066413086
|
p02913
|
python
|
s179101971
|
s509434669
| 1,642 | 42 | 4,852 | 3,800 |
Accepted
|
Accepted
| 97.44 |
from collections import defaultdict
class RollingHash(object):
def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
self.S = S
self.N = N = len(S)
self.MOD = MOD
self.BASE = BASE
self.S_arr = [ord(x) for x in S]
self.POWER = [1] * (N + 1)
self.HASH = [0] * (N + 1)
p, h = 1, 0
for i in range(N):
self.POWER[i + 1] = p = (p * BASE) % MOD
self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD
def hash(self, l: int, r: int):
# get hash for S[l:r]
_hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
return _hash
def main():
N = int(eval(input()))
S = eval(input())
MOD = 998244353
rs = RollingHash(S, MOD=MOD, BASE=37)
h, p = rs.HASH, rs.POWER
left, right = 0, N // 2 + 1
while abs(right - left) > 1:
mid = (left + right) // 2
ok = False
hash_to_left = defaultdict(list)
L = mid
for i in range(N - L + 1):
_hash = (h[i+L] - h[i] * p[L]) % MOD
# hashが衝突しても文字列が完全に一致するか分からないので、
# 衝突した場合は文字列が完全に一致するか調べ、かつ
# 文字列同士がSの中で重なるような範囲にない場合はOKとする
for j in hash_to_left[_hash]:
if j+L <= i and S[i:i+L] == S[j:j+L]:
ok = True
break
if ok:
break
hash_to_left[_hash].append(i)
if ok:
left = mid
else:
right = mid
print(left)
# # 長さLの部分文字列同士が、範囲を重ねず同じ文字列となる場合はTrue,
# # そうでない場合はFalseを返す関数
# def isOK(L):
# if L == 0:
# return True
# hash_to_left = defaultdict(list)
# for i in range(N - L + 1):
# _hash = rs.hash(i, i + L)
# # hashが衝突しても文字列が完全に一致するか分からないので、
# # 衝突した場合は文字列が完全に一致するか調べ、かつ
# # 文字列同士がSの中で重なるような範囲にない場合はOKとする
# for j in hash_to_left[_hash]:
# if j+L <= i and S[i:i+L] == S[j:j+L]:
# return True
# hash_to_left[_hash].append(i)
# return False
# # 範囲が重ならないことが条件にあるので、答えは最大でもN // 2(文字列の長さの半分)となる。
# # ただし、二分探索する上で絶対に答えとならない範囲を含めたいので、
# # 探索範囲としてはN // 2 + 1 と、+1しておく。
# ans = binary_search(0, N // 2 + 1, isOK, search_max=True)
# print(ans)
if __name__ == '__main__':
main()
|
def solve():
N = int(eval(input()))
S = eval(input())
def rolling_hash(s, mod, base = 37):
l = len(s)
h = [0]*(l + 1)
v = 0
for i in range(l):
h[i+1] = v = (v * base + ord(s[i])) % mod
pw = [1]*(l + 1)
v = 1
for i in range(l):
pw[i+1] = v = v * base % mod
return h, pw
def chk(S, mod, D = [0]*N):
h, pw = rolling_hash(S, mod)
left = 0; right = N//2+1
while left+1 < right:
l = mid = (left + right) >> 1
p = pw[l]
for i in range(min(l, N-2*l+1)):
D[i] = (h[l+i] - h[i]*p) % mod
s = set()
ok = 0
for i in range(l, N-l+1):
s.add(D[i-l])
D[i] = v = (h[l+i] - h[i]*p) % mod
if v in s:
ok = 1
break
if ok:
left = mid
else:
right = mid
return left
print((chk(S, 10**9 + 9)))
solve()
| 81 | 40 | 2,475 | 1,076 |
from collections import defaultdict
class RollingHash(object):
def __init__(self, S: str, MOD: int = 10**9 + 7, BASE: int = 10**5 + 7):
self.S = S
self.N = N = len(S)
self.MOD = MOD
self.BASE = BASE
self.S_arr = [ord(x) for x in S]
self.POWER = [1] * (N + 1)
self.HASH = [0] * (N + 1)
p, h = 1, 0
for i in range(N):
self.POWER[i + 1] = p = (p * BASE) % MOD
self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD
def hash(self, l: int, r: int):
# get hash for S[l:r]
_hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
return _hash
def main():
N = int(eval(input()))
S = eval(input())
MOD = 998244353
rs = RollingHash(S, MOD=MOD, BASE=37)
h, p = rs.HASH, rs.POWER
left, right = 0, N // 2 + 1
while abs(right - left) > 1:
mid = (left + right) // 2
ok = False
hash_to_left = defaultdict(list)
L = mid
for i in range(N - L + 1):
_hash = (h[i + L] - h[i] * p[L]) % MOD
# hashが衝突しても文字列が完全に一致するか分からないので、
# 衝突した場合は文字列が完全に一致するか調べ、かつ
# 文字列同士がSの中で重なるような範囲にない場合はOKとする
for j in hash_to_left[_hash]:
if j + L <= i and S[i : i + L] == S[j : j + L]:
ok = True
break
if ok:
break
hash_to_left[_hash].append(i)
if ok:
left = mid
else:
right = mid
print(left)
# # 長さLの部分文字列同士が、範囲を重ねず同じ文字列となる場合はTrue,
# # そうでない場合はFalseを返す関数
# def isOK(L):
# if L == 0:
# return True
# hash_to_left = defaultdict(list)
# for i in range(N - L + 1):
# _hash = rs.hash(i, i + L)
# # hashが衝突しても文字列が完全に一致するか分からないので、
# # 衝突した場合は文字列が完全に一致するか調べ、かつ
# # 文字列同士がSの中で重なるような範囲にない場合はOKとする
# for j in hash_to_left[_hash]:
# if j+L <= i and S[i:i+L] == S[j:j+L]:
# return True
# hash_to_left[_hash].append(i)
# return False
# # 範囲が重ならないことが条件にあるので、答えは最大でもN // 2(文字列の長さの半分)となる。
# # ただし、二分探索する上で絶対に答えとならない範囲を含めたいので、
# # 探索範囲としてはN // 2 + 1 と、+1しておく。
# ans = binary_search(0, N // 2 + 1, isOK, search_max=True)
# print(ans)
if __name__ == "__main__":
main()
|
def solve():
N = int(eval(input()))
S = eval(input())
def rolling_hash(s, mod, base=37):
l = len(s)
h = [0] * (l + 1)
v = 0
for i in range(l):
h[i + 1] = v = (v * base + ord(s[i])) % mod
pw = [1] * (l + 1)
v = 1
for i in range(l):
pw[i + 1] = v = v * base % mod
return h, pw
def chk(S, mod, D=[0] * N):
h, pw = rolling_hash(S, mod)
left = 0
right = N // 2 + 1
while left + 1 < right:
l = mid = (left + right) >> 1
p = pw[l]
for i in range(min(l, N - 2 * l + 1)):
D[i] = (h[l + i] - h[i] * p) % mod
s = set()
ok = 0
for i in range(l, N - l + 1):
s.add(D[i - l])
D[i] = v = (h[l + i] - h[i] * p) % mod
if v in s:
ok = 1
break
if ok:
left = mid
else:
right = mid
return left
print((chk(S, 10**9 + 9)))
solve()
| false | 50.617284 |
[
"-from collections import defaultdict",
"+def solve():",
"+ N = int(eval(input()))",
"+ S = eval(input())",
"+",
"+ def rolling_hash(s, mod, base=37):",
"+ l = len(s)",
"+ h = [0] * (l + 1)",
"+ v = 0",
"+ for i in range(l):",
"+ h[i + 1] = v = (v * base + ord(s[i])) % mod",
"+ pw = [1] * (l + 1)",
"+ v = 1",
"+ for i in range(l):",
"+ pw[i + 1] = v = v * base % mod",
"+ return h, pw",
"+",
"+ def chk(S, mod, D=[0] * N):",
"+ h, pw = rolling_hash(S, mod)",
"+ left = 0",
"+ right = N // 2 + 1",
"+ while left + 1 < right:",
"+ l = mid = (left + right) >> 1",
"+ p = pw[l]",
"+ for i in range(min(l, N - 2 * l + 1)):",
"+ D[i] = (h[l + i] - h[i] * p) % mod",
"+ s = set()",
"+ ok = 0",
"+ for i in range(l, N - l + 1):",
"+ s.add(D[i - l])",
"+ D[i] = v = (h[l + i] - h[i] * p) % mod",
"+ if v in s:",
"+ ok = 1",
"+ break",
"+ if ok:",
"+ left = mid",
"+ else:",
"+ right = mid",
"+ return left",
"+",
"+ print((chk(S, 10**9 + 9)))",
"-class RollingHash(object):",
"- def __init__(self, S: str, MOD: int = 10**9 + 7, BASE: int = 10**5 + 7):",
"- self.S = S",
"- self.N = N = len(S)",
"- self.MOD = MOD",
"- self.BASE = BASE",
"- self.S_arr = [ord(x) for x in S]",
"- self.POWER = [1] * (N + 1)",
"- self.HASH = [0] * (N + 1)",
"- p, h = 1, 0",
"- for i in range(N):",
"- self.POWER[i + 1] = p = (p * BASE) % MOD",
"- self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD",
"-",
"- def hash(self, l: int, r: int):",
"- # get hash for S[l:r]",
"- _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD",
"- return _hash",
"-",
"-",
"-def main():",
"- N = int(eval(input()))",
"- S = eval(input())",
"- MOD = 998244353",
"- rs = RollingHash(S, MOD=MOD, BASE=37)",
"- h, p = rs.HASH, rs.POWER",
"- left, right = 0, N // 2 + 1",
"- while abs(right - left) > 1:",
"- mid = (left + right) // 2",
"- ok = False",
"- hash_to_left = defaultdict(list)",
"- L = mid",
"- for i in range(N - L + 1):",
"- _hash = (h[i + L] - h[i] * p[L]) % MOD",
"- # hashが衝突しても文字列が完全に一致するか分からないので、",
"- # 衝突した場合は文字列が完全に一致するか調べ、かつ",
"- # 文字列同士がSの中で重なるような範囲にない場合はOKとする",
"- for j in hash_to_left[_hash]:",
"- if j + L <= i and S[i : i + L] == S[j : j + L]:",
"- ok = True",
"- break",
"- if ok:",
"- break",
"- hash_to_left[_hash].append(i)",
"- if ok:",
"- left = mid",
"- else:",
"- right = mid",
"- print(left)",
"- # # 長さLの部分文字列同士が、範囲を重ねず同じ文字列となる場合はTrue,",
"- # # そうでない場合はFalseを返す関数",
"- # def isOK(L):",
"- # if L == 0:",
"- # return True",
"- # hash_to_left = defaultdict(list)",
"- # for i in range(N - L + 1):",
"- # _hash = rs.hash(i, i + L)",
"- # # hashが衝突しても文字列が完全に一致するか分からないので、",
"- # # 衝突した場合は文字列が完全に一致するか調べ、かつ",
"- # # 文字列同士がSの中で重なるような範囲にない場合はOKとする",
"- # for j in hash_to_left[_hash]:",
"- # if j+L <= i and S[i:i+L] == S[j:j+L]:",
"- # return True",
"- # hash_to_left[_hash].append(i)",
"- # return False",
"- # # 範囲が重ならないことが条件にあるので、答えは最大でもN // 2(文字列の長さの半分)となる。",
"- # # ただし、二分探索する上で絶対に答えとならない範囲を含めたいので、",
"- # # 探索範囲としてはN // 2 + 1 と、+1しておく。",
"- # ans = binary_search(0, N // 2 + 1, isOK, search_max=True)",
"- # print(ans)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+solve()"
] | false | 0.087703 | 0.035731 | 2.454522 |
[
"s179101971",
"s509434669"
] |
u653883313
|
p03478
|
python
|
s004091038
|
s906227284
| 38 | 30 | 3,060 | 2,940 |
Accepted
|
Accepted
| 21.05 |
n, a, b= list(map(int, input().split()))
ALlsum = 0
for i in range(1, n+1):
sum = 0
i = str(i)
i_len = len(i)
for j in range(i_len):
sum += int(i[j])
if a<=sum and sum<=b :
ALlsum += int(i)
print(ALlsum)
|
n, a, b= list(map(int, input().split()))
Ssum = 0
for i in range(1, n+1):
tmp = i
sum = 0
while i>0 :
sum += i%10
i //= 10
if a<=sum and sum<=b:
Ssum += tmp
print(Ssum)
| 14 | 13 | 249 | 216 |
n, a, b = list(map(int, input().split()))
ALlsum = 0
for i in range(1, n + 1):
sum = 0
i = str(i)
i_len = len(i)
for j in range(i_len):
sum += int(i[j])
if a <= sum and sum <= b:
ALlsum += int(i)
print(ALlsum)
|
n, a, b = list(map(int, input().split()))
Ssum = 0
for i in range(1, n + 1):
tmp = i
sum = 0
while i > 0:
sum += i % 10
i //= 10
if a <= sum and sum <= b:
Ssum += tmp
print(Ssum)
| false | 7.142857 |
[
"-ALlsum = 0",
"+Ssum = 0",
"+ tmp = i",
"- i = str(i)",
"- i_len = len(i)",
"- for j in range(i_len):",
"- sum += int(i[j])",
"+ while i > 0:",
"+ sum += i % 10",
"+ i //= 10",
"- ALlsum += int(i)",
"-print(ALlsum)",
"+ Ssum += tmp",
"+print(Ssum)"
] | false | 0.048313 | 0.039388 | 1.226601 |
[
"s004091038",
"s906227284"
] |
u462329577
|
p03029
|
python
|
s205547266
|
s899149410
| 164 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.63 |
A,P = list(map(int,input().split()))
print(((A*3+P)//2))
|
a, p = list(map(int, input().split()))
print(((a * 3 + p) // 2))
| 2 | 3 | 49 | 60 |
A, P = list(map(int, input().split()))
print(((A * 3 + P) // 2))
|
a, p = list(map(int, input().split()))
print(((a * 3 + p) // 2))
| false | 33.333333 |
[
"-A, P = list(map(int, input().split()))",
"-print(((A * 3 + P) // 2))",
"+a, p = list(map(int, input().split()))",
"+print(((a * 3 + p) // 2))"
] | false | 0.042414 | 0.042433 | 0.999549 |
[
"s205547266",
"s899149410"
] |
u837673618
|
p02737
|
python
|
s078794633
|
s779278341
| 1,958 | 1,695 | 73,492 | 73,496 |
Accepted
|
Accepted
| 13.43 |
from collections import defaultdict
M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))
def ext_euc(a, b):
x1, y1, z1 = 1, 0, a
x2, y2, z2 = 0, 1, b
while z1 != 1:
d, m = divmod(z2,z1)
x1, x2 = x2-d*x1, x1
y1, y2 = y2-d*y1, y1
z1, z2 = m, z1
return x1, y1
def inv_mod(a, b, m):
x, y = ext_euc(a, m)
return (x * b % m)
def mex(s):
for i in range(N+1):
if i not in s:
return i
def calc_grundy(e):
g = {}
sum_g = defaultdict(int)
sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
for i in range(N, 0, -1):
if i not in e:
continue
m = mex({g.get(j, 0) for j in e[i]})
if m:
g[i] = m
x = pow(B, i, M)
sum_g[m] += x
sum_g[0] -= x
return sum_g
def read_edge():
M = int(eval(input()))
e = defaultdict(set)
for i in range(M):
a, b = sorted(map(int, input().split()))
e[a].add(b)
return e
def solve(N, edge):
sum_g = list(map(calc_grundy, edge))
ret = 0
for gx, sx in list(sum_g[0].items()):
for gy, sy in list(sum_g[1].items()):
gz = gx^gy
sz = sum_g[2][gz]
if sz:
ret += (sx*sy*sz) % M
return ret%M
edge = [read_edge() for i in range(3)]
print((solve(N, edge)))
|
from collections import defaultdict
M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))
def ext_euc(a, b):
x1, y1, z1 = 1, 0, a
x2, y2, z2 = 0, 1, b
while z1 != 1:
d, m = divmod(z2,z1)
x1, x2 = x2-d*x1, x1
y1, y2 = y2-d*y1, y1
z1, z2 = m, z1
return x1, y1
def inv_mod(a, b, m):
x, y = ext_euc(a, m)
return (x * b % m)
def mex(s):
for i in range(N+1):
if i not in s:
return i
def calc_grundy(e):
g = {}
for i in range(N, 0, -1):
if i not in e:
continue
m = mex({g.get(j, 0) for j in e[i]})
if m:
g[i] = m
sum_g = defaultdict(int)
sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
x = 1
for i in range(1, N+1):
x = (x * B) % M
if i in g:
sum_g[g[i]] += x
sum_g[0] -= x
return sum_g
def read_edge():
M = int(eval(input()))
e = defaultdict(set)
for i in range(M):
a, b = sorted(map(int, input().split()))
e[a].add(b)
return e
def solve(N, edge):
sum_g = list(map(calc_grundy, edge))
ret = 0
for gx, sx in list(sum_g[0].items()):
for gy, sy in list(sum_g[1].items()):
gz = gx^gy
sz = sum_g[2][gz]
if sz:
ret += (sx*sy*sz) % M
return ret%M
edge = [read_edge() for i in range(3)]
print((solve(N, edge)))
| 63 | 66 | 1,244 | 1,296 |
from collections import defaultdict
M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))
def ext_euc(a, b):
x1, y1, z1 = 1, 0, a
x2, y2, z2 = 0, 1, b
while z1 != 1:
d, m = divmod(z2, z1)
x1, x2 = x2 - d * x1, x1
y1, y2 = y2 - d * y1, y1
z1, z2 = m, z1
return x1, y1
def inv_mod(a, b, m):
x, y = ext_euc(a, m)
return x * b % m
def mex(s):
for i in range(N + 1):
if i not in s:
return i
def calc_grundy(e):
g = {}
sum_g = defaultdict(int)
sum_g[0] = inv_mod(B - 1, pow(B, N + 1, M) - B, M)
for i in range(N, 0, -1):
if i not in e:
continue
m = mex({g.get(j, 0) for j in e[i]})
if m:
g[i] = m
x = pow(B, i, M)
sum_g[m] += x
sum_g[0] -= x
return sum_g
def read_edge():
M = int(eval(input()))
e = defaultdict(set)
for i in range(M):
a, b = sorted(map(int, input().split()))
e[a].add(b)
return e
def solve(N, edge):
sum_g = list(map(calc_grundy, edge))
ret = 0
for gx, sx in list(sum_g[0].items()):
for gy, sy in list(sum_g[1].items()):
gz = gx ^ gy
sz = sum_g[2][gz]
if sz:
ret += (sx * sy * sz) % M
return ret % M
edge = [read_edge() for i in range(3)]
print((solve(N, edge)))
|
from collections import defaultdict
M = 998244353
B = pow(10, 18, M)
N = int(eval(input()))
def ext_euc(a, b):
x1, y1, z1 = 1, 0, a
x2, y2, z2 = 0, 1, b
while z1 != 1:
d, m = divmod(z2, z1)
x1, x2 = x2 - d * x1, x1
y1, y2 = y2 - d * y1, y1
z1, z2 = m, z1
return x1, y1
def inv_mod(a, b, m):
x, y = ext_euc(a, m)
return x * b % m
def mex(s):
for i in range(N + 1):
if i not in s:
return i
def calc_grundy(e):
g = {}
for i in range(N, 0, -1):
if i not in e:
continue
m = mex({g.get(j, 0) for j in e[i]})
if m:
g[i] = m
sum_g = defaultdict(int)
sum_g[0] = inv_mod(B - 1, pow(B, N + 1, M) - B, M)
x = 1
for i in range(1, N + 1):
x = (x * B) % M
if i in g:
sum_g[g[i]] += x
sum_g[0] -= x
return sum_g
def read_edge():
M = int(eval(input()))
e = defaultdict(set)
for i in range(M):
a, b = sorted(map(int, input().split()))
e[a].add(b)
return e
def solve(N, edge):
sum_g = list(map(calc_grundy, edge))
ret = 0
for gx, sx in list(sum_g[0].items()):
for gy, sy in list(sum_g[1].items()):
gz = gx ^ gy
sz = sum_g[2][gz]
if sz:
ret += (sx * sy * sz) % M
return ret % M
edge = [read_edge() for i in range(3)]
print((solve(N, edge)))
| false | 4.545455 |
[
"- sum_g = defaultdict(int)",
"- sum_g[0] = inv_mod(B - 1, pow(B, N + 1, M) - B, M)",
"- x = pow(B, i, M)",
"- sum_g[m] += x",
"+ sum_g = defaultdict(int)",
"+ sum_g[0] = inv_mod(B - 1, pow(B, N + 1, M) - B, M)",
"+ x = 1",
"+ for i in range(1, N + 1):",
"+ x = (x * B) % M",
"+ if i in g:",
"+ sum_g[g[i]] += x"
] | false | 0.056532 | 0.130122 | 0.43445 |
[
"s078794633",
"s779278341"
] |
u411203878
|
p03062
|
python
|
s746921078
|
s409379732
| 241 | 91 | 65,440 | 90,756 |
Accepted
|
Accepted
| 62.24 |
n=int(eval(input()))
t = list(map(int,input().split()))
count = 0
for i in t:
if i < 0:
count += 1
memo = []
for i in t:
memo.append(abs(i))
memo.sort()
if count%2==0:
print((sum(memo)))
else:
print((sum(memo)-memo[0]*2))
|
n=int(eval(input()))
a= list(map(int,input().split()))
plus = []
minas = []
for value in a:
if value < 0:
minas.append(abs(value))
else:
plus.append(value)
if len(minas)%2 == 0:
ans = sum(plus)+sum(minas)
else:
if len(plus) > 0:
mini = min(min(plus),min(minas))
ans = sum(plus)+sum(minas)-mini*2
else:
mini = min(minas)
ans = sum(minas)-mini*2
print(ans)
| 20 | 25 | 260 | 446 |
n = int(eval(input()))
t = list(map(int, input().split()))
count = 0
for i in t:
if i < 0:
count += 1
memo = []
for i in t:
memo.append(abs(i))
memo.sort()
if count % 2 == 0:
print((sum(memo)))
else:
print((sum(memo) - memo[0] * 2))
|
n = int(eval(input()))
a = list(map(int, input().split()))
plus = []
minas = []
for value in a:
if value < 0:
minas.append(abs(value))
else:
plus.append(value)
if len(minas) % 2 == 0:
ans = sum(plus) + sum(minas)
else:
if len(plus) > 0:
mini = min(min(plus), min(minas))
ans = sum(plus) + sum(minas) - mini * 2
else:
mini = min(minas)
ans = sum(minas) - mini * 2
print(ans)
| false | 20 |
[
"-t = list(map(int, input().split()))",
"-count = 0",
"-for i in t:",
"- if i < 0:",
"- count += 1",
"-memo = []",
"-for i in t:",
"- memo.append(abs(i))",
"-memo.sort()",
"-if count % 2 == 0:",
"- print((sum(memo)))",
"+a = list(map(int, input().split()))",
"+plus = []",
"+minas = []",
"+for value in a:",
"+ if value < 0:",
"+ minas.append(abs(value))",
"+ else:",
"+ plus.append(value)",
"+if len(minas) % 2 == 0:",
"+ ans = sum(plus) + sum(minas)",
"- print((sum(memo) - memo[0] * 2))",
"+ if len(plus) > 0:",
"+ mini = min(min(plus), min(minas))",
"+ ans = sum(plus) + sum(minas) - mini * 2",
"+ else:",
"+ mini = min(minas)",
"+ ans = sum(minas) - mini * 2",
"+print(ans)"
] | false | 0.044699 | 0.045001 | 0.993286 |
[
"s746921078",
"s409379732"
] |
u945181840
|
p03014
|
python
|
s132205317
|
s987362710
| 1,128 | 1,031 | 247,328 | 267,056 |
Accepted
|
Accepted
| 8.6 |
import numpy as np
import sys
buf = sys.stdin.buffer
H, W = list(map(int, buf.readline().split()))
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.', 1, 0)
grid_v = grid.T
right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T
print((np.max((left - right) + (up - down)) - 3))
|
import numpy as np
import sys
line = sys.stdin.readline
H, W = list(map(int, line().split()))
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
grid_v = grid.T
right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T
print((np.max((left - right) + (up - down)) - 3))
| 15 | 15 | 724 | 699 |
import numpy as np
import sys
buf = sys.stdin.buffer
H, W = list(map(int, buf.readline().split()))
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(
np.array(list(map(list, buf.read().decode("utf-8").split()))).reshape(H, W) == ".",
1,
0,
)
grid_v = grid.T
right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(
np.minimum.accumulate(
np.fliplr(np.where(grid < 1, np.arange(W + 2), 10**10)).copy(), axis=1
)
)
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(
np.minimum.accumulate(
np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10**10)).copy(), axis=1
)
).T
print((np.max((left - right) + (up - down)) - 3))
|
import numpy as np
import sys
line = sys.stdin.readline
H, W = list(map(int, line().split()))
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (
np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == "."
) * 1
grid_v = grid.T
right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(
np.minimum.accumulate(
np.fliplr(np.where(grid < 1, np.arange(W + 2), 10**10)).copy(), axis=1
)
)
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(
np.minimum.accumulate(
np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10**10)).copy(), axis=1
)
).T
print((np.max((left - right) + (up - down)) - 3))
| false | 0 |
[
"-buf = sys.stdin.buffer",
"-H, W = list(map(int, buf.readline().split()))",
"+line = sys.stdin.readline",
"+H, W = list(map(int, line().split()))",
"-grid[1:-1, 1:-1] = np.where(",
"- np.array(list(map(list, buf.read().decode(\"utf-8\").split()))).reshape(H, W) == \".\",",
"- 1,",
"- 0,",
"-)",
"+grid[1:-1, 1:-1] = (",
"+ np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == \".\"",
"+) * 1"
] | false | 0.270777 | 0.792292 | 0.341765 |
[
"s132205317",
"s987362710"
] |
u419877586
|
p02778
|
python
|
s795029846
|
s834805344
| 169 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.94 |
S=eval(input())
ans=["x" for _ in range(len(S))]
print(("".join(ans)))
|
S = eval(input())
print(("".join(["x" for _ in range(len(S))])))
| 3 | 2 | 64 | 57 |
S = eval(input())
ans = ["x" for _ in range(len(S))]
print(("".join(ans)))
|
S = eval(input())
print(("".join(["x" for _ in range(len(S))])))
| false | 33.333333 |
[
"-ans = [\"x\" for _ in range(len(S))]",
"-print((\"\".join(ans)))",
"+print((\"\".join([\"x\" for _ in range(len(S))])))"
] | false | 0.041809 | 0.035644 | 1.172961 |
[
"s795029846",
"s834805344"
] |
u150984829
|
p00043
|
python
|
s769014618
|
s402814461
| 60 | 50 | 5,580 | 5,612 |
Accepted
|
Accepted
| 16.67 |
import sys
def p(c,l,b):
for i in l:c[i]+=[-1,1][b]
def f(c):
if sum(c)in c:return 1
if 5 in c:return 0
if 4 in c:
k=c.index(4);c[k]-=3
if f(c):return 1
c[k]+=3
if 3 in c:
k=c.index(3);c[k]-=3
if f(c):return 1
c[k]+=3
for i in range(7):
if c[i]and c[i+1]and c[i+2]:
p(c,[i,i+1,i+2],0)
if f(c):return 1
p(c,[i,i+1,i+2],1)
n='123456789'
for e in sys.stdin:
e=list(e)
a=[i for i in n if f([(e+[i]).count(j)for j in n])]
if a:print((*a))
else:print((0))
|
import sys
def g(c,i):
a=[0]*9
for j in e+[i]:a[j-1]+=1
return a
def f(c):
if sum(c)in c:return 1
if 5 in c:return 0
if 4 in c:
k=c.index(4);c[k]-=3
if f(c):return 1
c[k]+=3
if 3 in c:
k=c.index(3);c[k]-=3
if f(c):return 1
c[k]+=3
for i in range(7):
if c[i]and c[i+1]and c[i+2]:
c[i]-=1;c[i+1]-=1;c[i+2]-=1
if f(c):return 1
c[i]+=1;c[i+1]+=1;c[i+2]+=1
for e in sys.stdin:
e=list(map(int,e.strip()))
a=[i for i in range(1,10)if f(g(e,i))]
if a:print((*a))
else:print((0))
| 25 | 26 | 503 | 527 |
import sys
def p(c, l, b):
for i in l:
c[i] += [-1, 1][b]
def f(c):
if sum(c) in c:
return 1
if 5 in c:
return 0
if 4 in c:
k = c.index(4)
c[k] -= 3
if f(c):
return 1
c[k] += 3
if 3 in c:
k = c.index(3)
c[k] -= 3
if f(c):
return 1
c[k] += 3
for i in range(7):
if c[i] and c[i + 1] and c[i + 2]:
p(c, [i, i + 1, i + 2], 0)
if f(c):
return 1
p(c, [i, i + 1, i + 2], 1)
n = "123456789"
for e in sys.stdin:
e = list(e)
a = [i for i in n if f([(e + [i]).count(j) for j in n])]
if a:
print((*a))
else:
print((0))
|
import sys
def g(c, i):
a = [0] * 9
for j in e + [i]:
a[j - 1] += 1
return a
def f(c):
if sum(c) in c:
return 1
if 5 in c:
return 0
if 4 in c:
k = c.index(4)
c[k] -= 3
if f(c):
return 1
c[k] += 3
if 3 in c:
k = c.index(3)
c[k] -= 3
if f(c):
return 1
c[k] += 3
for i in range(7):
if c[i] and c[i + 1] and c[i + 2]:
c[i] -= 1
c[i + 1] -= 1
c[i + 2] -= 1
if f(c):
return 1
c[i] += 1
c[i + 1] += 1
c[i + 2] += 1
for e in sys.stdin:
e = list(map(int, e.strip()))
a = [i for i in range(1, 10) if f(g(e, i))]
if a:
print((*a))
else:
print((0))
| false | 3.846154 |
[
"-def p(c, l, b):",
"- for i in l:",
"- c[i] += [-1, 1][b]",
"+def g(c, i):",
"+ a = [0] * 9",
"+ for j in e + [i]:",
"+ a[j - 1] += 1",
"+ return a",
"- p(c, [i, i + 1, i + 2], 0)",
"+ c[i] -= 1",
"+ c[i + 1] -= 1",
"+ c[i + 2] -= 1",
"- p(c, [i, i + 1, i + 2], 1)",
"+ c[i] += 1",
"+ c[i + 1] += 1",
"+ c[i + 2] += 1",
"-n = \"123456789\"",
"- e = list(e)",
"- a = [i for i in n if f([(e + [i]).count(j) for j in n])]",
"+ e = list(map(int, e.strip()))",
"+ a = [i for i in range(1, 10) if f(g(e, i))]"
] | false | 0.049835 | 0.05298 | 0.940639 |
[
"s769014618",
"s402814461"
] |
u941407962
|
p02901
|
python
|
s323322163
|
s901546203
| 288 | 247 | 47,576 | 42,732 |
Accepted
|
Accepted
| 14.24 |
n, m = list(map(int, input().split()))
dp = [pow(10, 10) for _ in range(pow(2, n))]
dp[0] = 0
for _ in range(m):
a, b = list(map(int, input().split()))
cs = list(map(int, input().split()))
d = 0
for c in cs:
d += pow(2, (c-1))
for i in range(pow(2, n)):
dp[i|d] = min(dp[i|d], dp[i] + a)
if dp[pow(2,n)-1] == pow(10, 10):
print((-1))
else:
print((dp[pow(2,n)-1]))
|
import sys;input=sys.stdin.readline
N, M = list(map(int, input().split()))
inf = 10**18
dp = [inf]*(1<<N)
dp[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
Cs = list(map(int, input().split()))
bb = 0
for c in Cs:
bb += 2**(c-1)
for x in range((1<<N)-1, -1, -1):
dp[bb|x] = min(dp[x]+a, dp[bb|x])
#print(dp)
r = dp[(1<<N)-1]
if r != inf:
print((dp[(1<<N)-1]))
else:
print((-1))
| 17 | 20 | 422 | 443 |
n, m = list(map(int, input().split()))
dp = [pow(10, 10) for _ in range(pow(2, n))]
dp[0] = 0
for _ in range(m):
a, b = list(map(int, input().split()))
cs = list(map(int, input().split()))
d = 0
for c in cs:
d += pow(2, (c - 1))
for i in range(pow(2, n)):
dp[i | d] = min(dp[i | d], dp[i] + a)
if dp[pow(2, n) - 1] == pow(10, 10):
print((-1))
else:
print((dp[pow(2, n) - 1]))
|
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
inf = 10**18
dp = [inf] * (1 << N)
dp[0] = 0
for i in range(M):
a, b = list(map(int, input().split()))
Cs = list(map(int, input().split()))
bb = 0
for c in Cs:
bb += 2 ** (c - 1)
for x in range((1 << N) - 1, -1, -1):
dp[bb | x] = min(dp[x] + a, dp[bb | x])
# print(dp)
r = dp[(1 << N) - 1]
if r != inf:
print((dp[(1 << N) - 1]))
else:
print((-1))
| false | 15 |
[
"-n, m = list(map(int, input().split()))",
"-dp = [pow(10, 10) for _ in range(pow(2, n))]",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+N, M = list(map(int, input().split()))",
"+inf = 10**18",
"+dp = [inf] * (1 << N)",
"-for _ in range(m):",
"+for i in range(M):",
"- cs = list(map(int, input().split()))",
"- d = 0",
"- for c in cs:",
"- d += pow(2, (c - 1))",
"- for i in range(pow(2, n)):",
"- dp[i | d] = min(dp[i | d], dp[i] + a)",
"-if dp[pow(2, n) - 1] == pow(10, 10):",
"+ Cs = list(map(int, input().split()))",
"+ bb = 0",
"+ for c in Cs:",
"+ bb += 2 ** (c - 1)",
"+ for x in range((1 << N) - 1, -1, -1):",
"+ dp[bb | x] = min(dp[x] + a, dp[bb | x])",
"+# print(dp)",
"+r = dp[(1 << N) - 1]",
"+if r != inf:",
"+ print((dp[(1 << N) - 1]))",
"+else:",
"-else:",
"- print((dp[pow(2, n) - 1]))"
] | false | 0.045219 | 0.039674 | 1.139743 |
[
"s323322163",
"s901546203"
] |
u343128979
|
p03030
|
python
|
s805783993
|
s598724153
| 169 | 148 | 38,256 | 12,496 |
Accepted
|
Accepted
| 12.43 |
import math
def main():
N = int(eval(input()))
SP = [list(input().split()) + [i + 1] for i in range(N)]
SP.sort(key=lambda x: (x[0], -int(x[1])))
for i in [x[2] for x in SP]:
print(i)
if __name__ == '__main__':
main()
|
import math
import numpy as np
def main():
N = int(eval(input()))
SP = [list(input().split()) + [i + 1] for i in range(N)]
SP.sort(key=lambda x: (x[0], -int(x[1])))
_SP = np.array(SP)
for i in _SP[:, 2]:
print(i)
if __name__ == '__main__':
main()
| 13 | 15 | 261 | 291 |
import math
def main():
N = int(eval(input()))
SP = [list(input().split()) + [i + 1] for i in range(N)]
SP.sort(key=lambda x: (x[0], -int(x[1])))
for i in [x[2] for x in SP]:
print(i)
if __name__ == "__main__":
main()
|
import math
import numpy as np
def main():
N = int(eval(input()))
SP = [list(input().split()) + [i + 1] for i in range(N)]
SP.sort(key=lambda x: (x[0], -int(x[1])))
_SP = np.array(SP)
for i in _SP[:, 2]:
print(i)
if __name__ == "__main__":
main()
| false | 13.333333 |
[
"+import numpy as np",
"- for i in [x[2] for x in SP]:",
"+ _SP = np.array(SP)",
"+ for i in _SP[:, 2]:"
] | false | 0.037263 | 0.245566 | 0.151742 |
[
"s805783993",
"s598724153"
] |
u844789719
|
p03608
|
python
|
s033528195
|
s732245998
| 754 | 321 | 10,684 | 42,816 |
Accepted
|
Accepted
| 57.43 |
import itertools
import heapq
V, E, R = [int(_) for _ in input().split()]
r = [int(_) - 1 for _ in input().split()] # 0-indexed
G = {}
for i in range(V):
G[i] = {}
G[i][i] = 0
for _ in range(E):
s, t, c = [int(_) for _ in input().split()]
s -= 1 # 0-indexed
t -= 1 # 0-indexed
G[s][t] = c
G[t][s] = c
INF = float('inf')
Ds = []
for r_index in range(R):
que = []
d = 0
i = r[r_index]
D = [INF] * V
D[i] = 0
used = [False] * V
used[i] = True
while True:
for j in list(G[i].keys()):
heapq.heappush(que, (d + G[i][j], j))
v = -1
while que:
d, j = heapq.heappop(que)
if not used[j]:
v = j
break
if v == -1:
break
else:
used[v] = True
D[v] = d
i = v
Ds += [D]
ans = INF
for array in itertools.permutations(list(range(R)), R):
d = 0
for i in range(R - 1):
d += Ds[array[i]][r[array[i + 1]]]
ans = min(ans, d)
print(ans)
|
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import itertools
I = [int(_) for _ in open(0).read().split()]
N, M, R = I[:3]
r = np.array(I[3:3 + R])
ABC = I[3 + R:]
F = floyd_warshall(csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0).astype(np.int64)
ans = float('inf')
for root in itertools.permutations(r, R):
ans = min(ans, sum(F[i,j] for i, j in zip(root, root[1:])))
print(ans)
| 52 | 13 | 1,099 | 473 |
import itertools
import heapq
V, E, R = [int(_) for _ in input().split()]
r = [int(_) - 1 for _ in input().split()] # 0-indexed
G = {}
for i in range(V):
G[i] = {}
G[i][i] = 0
for _ in range(E):
s, t, c = [int(_) for _ in input().split()]
s -= 1 # 0-indexed
t -= 1 # 0-indexed
G[s][t] = c
G[t][s] = c
INF = float("inf")
Ds = []
for r_index in range(R):
que = []
d = 0
i = r[r_index]
D = [INF] * V
D[i] = 0
used = [False] * V
used[i] = True
while True:
for j in list(G[i].keys()):
heapq.heappush(que, (d + G[i][j], j))
v = -1
while que:
d, j = heapq.heappop(que)
if not used[j]:
v = j
break
if v == -1:
break
else:
used[v] = True
D[v] = d
i = v
Ds += [D]
ans = INF
for array in itertools.permutations(list(range(R)), R):
d = 0
for i in range(R - 1):
d += Ds[array[i]][r[array[i + 1]]]
ans = min(ans, d)
print(ans)
|
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import itertools
I = [int(_) for _ in open(0).read().split()]
N, M, R = I[:3]
r = np.array(I[3 : 3 + R])
ABC = I[3 + R :]
F = floyd_warshall(
csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0
).astype(np.int64)
ans = float("inf")
for root in itertools.permutations(r, R):
ans = min(ans, sum(F[i, j] for i, j in zip(root, root[1:])))
print(ans)
| false | 75 |
[
"+import numpy as np",
"+from scipy.sparse import csr_matrix",
"+from scipy.sparse.csgraph import floyd_warshall",
"-import heapq",
"-V, E, R = [int(_) for _ in input().split()]",
"-r = [int(_) - 1 for _ in input().split()] # 0-indexed",
"-G = {}",
"-for i in range(V):",
"- G[i] = {}",
"- G[i][i] = 0",
"-for _ in range(E):",
"- s, t, c = [int(_) for _ in input().split()]",
"- s -= 1 # 0-indexed",
"- t -= 1 # 0-indexed",
"- G[s][t] = c",
"- G[t][s] = c",
"-INF = float(\"inf\")",
"-Ds = []",
"-for r_index in range(R):",
"- que = []",
"- d = 0",
"- i = r[r_index]",
"- D = [INF] * V",
"- D[i] = 0",
"- used = [False] * V",
"- used[i] = True",
"- while True:",
"- for j in list(G[i].keys()):",
"- heapq.heappush(que, (d + G[i][j], j))",
"- v = -1",
"- while que:",
"- d, j = heapq.heappop(que)",
"- if not used[j]:",
"- v = j",
"- break",
"- if v == -1:",
"- break",
"- else:",
"- used[v] = True",
"- D[v] = d",
"- i = v",
"- Ds += [D]",
"-ans = INF",
"-for array in itertools.permutations(list(range(R)), R):",
"- d = 0",
"- for i in range(R - 1):",
"- d += Ds[array[i]][r[array[i + 1]]]",
"- ans = min(ans, d)",
"+I = [int(_) for _ in open(0).read().split()]",
"+N, M, R = I[:3]",
"+r = np.array(I[3 : 3 + R])",
"+ABC = I[3 + R :]",
"+F = floyd_warshall(",
"+ csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0",
"+).astype(np.int64)",
"+ans = float(\"inf\")",
"+for root in itertools.permutations(r, R):",
"+ ans = min(ans, sum(F[i, j] for i, j in zip(root, root[1:])))"
] | false | 0.036054 | 0.744948 | 0.048399 |
[
"s033528195",
"s732245998"
] |
u279605379
|
p02265
|
python
|
s140431809
|
s883937870
| 4,570 | 1,990 | 71,992 | 214,356 |
Accepted
|
Accepted
| 56.46 |
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
q = collections.deque()
cmds={"insert":lambda cmd: q.appendleft(cmd[1]),
"delete":lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
"deleteFirst":lambda cmd: q.popleft(),
"deleteLast": lambda cmd: q.pop()
}
n=int(eval(input()))
for i in range(n):
cmd=input().split()
cmds[cmd[0]](cmd)
print((*q))
|
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
import sys
q = collections.deque()
n=int(eval(input()))
_input = sys.stdin.readlines()
cmds={"insert":lambda cmd: q.appendleft(cmd[1]),
"delete":lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
"deleteFirst":lambda cmd: q.popleft(),
"deleteLast": lambda cmd: q.pop()
}
for i in range(n):
cmd=_input[i].split()
cmds[cmd[0]](cmd)
print((*q))
| 14 | 16 | 428 | 474 |
# ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
q = collections.deque()
cmds = {
"insert": lambda cmd: q.appendleft(cmd[1]),
"delete": lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
"deleteFirst": lambda cmd: q.popleft(),
"deleteLast": lambda cmd: q.pop(),
}
n = int(eval(input()))
for i in range(n):
cmd = input().split()
cmds[cmd[0]](cmd)
print((*q))
|
# ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
import sys
q = collections.deque()
n = int(eval(input()))
_input = sys.stdin.readlines()
cmds = {
"insert": lambda cmd: q.appendleft(cmd[1]),
"delete": lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
"deleteFirst": lambda cmd: q.popleft(),
"deleteLast": lambda cmd: q.pop(),
}
for i in range(n):
cmd = _input[i].split()
cmds[cmd[0]](cmd)
print((*q))
| false | 12.5 |
[
"+import sys",
"+n = int(eval(input()))",
"+_input = sys.stdin.readlines()",
"-n = int(eval(input()))",
"- cmd = input().split()",
"+ cmd = _input[i].split()"
] | false | 0.036284 | 0.035096 | 1.033847 |
[
"s140431809",
"s883937870"
] |
u227082700
|
p02883
|
python
|
s836903746
|
s877331663
| 1,285 | 790 | 132,236 | 127,200 |
Accepted
|
Accepted
| 38.52 |
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort()
ok=a[-1]*f[-1]
ng=0
if sum(a)<=k:print((0));exit()
ma=ok
while ng+1!=ok:
mid=(ok+ng)//2
b=[mid//i for i in f]
b.sort()
h=0
for i in range(n):h+=max(0,a[i]-b[i])
if h<=k:ok=mid
else:ng=mid
print(ok)
|
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
ok=max(ok,a[i]*f[i])
su+=a[i]
if su<=k:print((0));exit()
while ng+1!=ok:
mid=(ok+ng)//2
b=[mid//i for i in f]
b.sort()
h=0
for i in range(n):h+=max(0,a[i]-b[i])
if h<=k:ok=mid
else:ng=mid
print(ok)
| 18 | 19 | 339 | 383 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
ok = a[-1] * f[-1]
ng = 0
if sum(a) <= k:
print((0))
exit()
ma = ok
while ng + 1 != ok:
mid = (ok + ng) // 2
b = [mid // i for i in f]
b.sort()
h = 0
for i in range(n):
h += max(0, a[i] - b[i])
if h <= k:
ok = mid
else:
ng = mid
print(ok)
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=1)
su = ok = ng = 0
for i in range(n):
ok = max(ok, a[i] * f[i])
su += a[i]
if su <= k:
print((0))
exit()
while ng + 1 != ok:
mid = (ok + ng) // 2
b = [mid // i for i in f]
b.sort()
h = 0
for i in range(n):
h += max(0, a[i] - b[i])
if h <= k:
ok = mid
else:
ng = mid
print(ok)
| false | 5.263158 |
[
"-f.sort()",
"-ok = a[-1] * f[-1]",
"-ng = 0",
"-if sum(a) <= k:",
"+f.sort(reverse=1)",
"+su = ok = ng = 0",
"+for i in range(n):",
"+ ok = max(ok, a[i] * f[i])",
"+ su += a[i]",
"+if su <= k:",
"-ma = ok"
] | false | 0.114095 | 0.046556 | 2.450717 |
[
"s836903746",
"s877331663"
] |
u644516473
|
p03379
|
python
|
s199056896
|
s643062004
| 303 | 235 | 25,228 | 25,620 |
Accepted
|
Accepted
| 22.44 |
N = int(eval(input()))
X = list(map(int, input().split()))
mid = sorted(X)[N//2-1:N//2+1]
for xi in X:
if xi > mid[0]:
print((mid[0]))
else:
print((mid[1]))
|
N = int(input())
X = list(map(int, input().split()))
mid1, mid2 = sorted(X)[N//2-1:N//2+1]
print(*[mid1 if xi>mid1 else mid2 for xi in X], sep="\n")
| 9 | 5 | 180 | 154 |
N = int(eval(input()))
X = list(map(int, input().split()))
mid = sorted(X)[N // 2 - 1 : N // 2 + 1]
for xi in X:
if xi > mid[0]:
print((mid[0]))
else:
print((mid[1]))
|
N = int(input())
X = list(map(int, input().split()))
mid1, mid2 = sorted(X)[N // 2 - 1 : N // 2 + 1]
print(*[mid1 if xi > mid1 else mid2 for xi in X], sep="\n")
| false | 44.444444 |
[
"-N = int(eval(input()))",
"+N = int(input())",
"-mid = sorted(X)[N // 2 - 1 : N // 2 + 1]",
"-for xi in X:",
"- if xi > mid[0]:",
"- print((mid[0]))",
"- else:",
"- print((mid[1]))",
"+mid1, mid2 = sorted(X)[N // 2 - 1 : N // 2 + 1]",
"+print(*[mid1 if xi > mid1 else mid2 for xi in X], sep=\"\\n\")"
] | false | 0.047743 | 0.045457 | 1.050304 |
[
"s199056896",
"s643062004"
] |
u127499732
|
p02732
|
python
|
s903065350
|
s415285960
| 273 | 218 | 44,448 | 44,276 |
Accepted
|
Accepted
| 20.15 |
def main():
from collections import defaultdict
from collections import Counter
import sys
n = int(eval(input()))
a = list(map(int, sys.stdin.readline().split()))
d = Counter(a)
e = defaultdict(int)
base = sum(v * (v - 1) // 2 for v in list(d.values()))
for k, v in list(d.items()):
if v <= 1:
e[k] = base - 0
else:
e[k] = base - (v - 1)
p = [str(e[x]) + '\n' for x in a]
q = ''.join(p)
print(q)
if __name__ == '__main__':
main()
|
def main():
from collections import defaultdict
from collections import Counter
import sys
n = int(eval(input()))
a = list(map(int, sys.stdin.readline().split()))
d = Counter(a)
e = defaultdict(int)
base = sum(v * (v - 1) // 2 for v in list(d.values()))
e = {k: base - (v >= 2) * (v - 1) for k, v in list(d.items())}
p = [str(e[x]) + '\n' for x in a]
q = ''.join(p)
print(q)
if __name__ == '__main__':
main()
| 26 | 21 | 536 | 469 |
def main():
from collections import defaultdict
from collections import Counter
import sys
n = int(eval(input()))
a = list(map(int, sys.stdin.readline().split()))
d = Counter(a)
e = defaultdict(int)
base = sum(v * (v - 1) // 2 for v in list(d.values()))
for k, v in list(d.items()):
if v <= 1:
e[k] = base - 0
else:
e[k] = base - (v - 1)
p = [str(e[x]) + "\n" for x in a]
q = "".join(p)
print(q)
if __name__ == "__main__":
main()
|
def main():
from collections import defaultdict
from collections import Counter
import sys
n = int(eval(input()))
a = list(map(int, sys.stdin.readline().split()))
d = Counter(a)
e = defaultdict(int)
base = sum(v * (v - 1) // 2 for v in list(d.values()))
e = {k: base - (v >= 2) * (v - 1) for k, v in list(d.items())}
p = [str(e[x]) + "\n" for x in a]
q = "".join(p)
print(q)
if __name__ == "__main__":
main()
| false | 19.230769 |
[
"- for k, v in list(d.items()):",
"- if v <= 1:",
"- e[k] = base - 0",
"- else:",
"- e[k] = base - (v - 1)",
"+ e = {k: base - (v >= 2) * (v - 1) for k, v in list(d.items())}"
] | false | 0.041832 | 0.10552 | 0.396438 |
[
"s903065350",
"s415285960"
] |
u813098295
|
p03828
|
python
|
s180732489
|
s873696074
| 23 | 20 | 3,064 | 3,064 |
Accepted
|
Accepted
| 13.04 |
n = int(eval(input()))
exps = [0] * 1003
for i in range(2, n+1):
t = i
div = 2
while div*div <= i:
if t % div == 0:
exps[div] += 1
t //= div
else:
div += 1
if t != 1:
exps[t] += 1
ans = 1
mod = int(1e9) + 7
for i in range(2, n+1):
ans *= (exps[i] + 1)
ans %= mod
print(ans)
|
def prime_factorize(n):
res = []
p = 2
while p*p <= n:
if n % p != 0:
p += 1
continue
num = 0
while n % p == 0:
num += 1
n //= p
res.append( [p, num] )
p += 1
if n != 1: res.append( [n, 1] )
return res
# n! の約数の数を mod で割った余りを返す
def mod_div_fact(n, mod):
d = {}
for i in range(2, n+1):
L = prime_factorize(i)
for (p, e) in L:
d[p] = d.get(p, 0) + e
res = 1
for v in list(d.values()):
res *= (v+1)
res %= mod
return res;
n = int(eval(input()))
mod = int(1e9)+7
print((mod_div_fact(n, mod)))
| 23 | 36 | 377 | 687 |
n = int(eval(input()))
exps = [0] * 1003
for i in range(2, n + 1):
t = i
div = 2
while div * div <= i:
if t % div == 0:
exps[div] += 1
t //= div
else:
div += 1
if t != 1:
exps[t] += 1
ans = 1
mod = int(1e9) + 7
for i in range(2, n + 1):
ans *= exps[i] + 1
ans %= mod
print(ans)
|
def prime_factorize(n):
res = []
p = 2
while p * p <= n:
if n % p != 0:
p += 1
continue
num = 0
while n % p == 0:
num += 1
n //= p
res.append([p, num])
p += 1
if n != 1:
res.append([n, 1])
return res
# n! の約数の数を mod で割った余りを返す
def mod_div_fact(n, mod):
d = {}
for i in range(2, n + 1):
L = prime_factorize(i)
for (p, e) in L:
d[p] = d.get(p, 0) + e
res = 1
for v in list(d.values()):
res *= v + 1
res %= mod
return res
n = int(eval(input()))
mod = int(1e9) + 7
print((mod_div_fact(n, mod)))
| false | 36.111111 |
[
"+def prime_factorize(n):",
"+ res = []",
"+ p = 2",
"+ while p * p <= n:",
"+ if n % p != 0:",
"+ p += 1",
"+ continue",
"+ num = 0",
"+ while n % p == 0:",
"+ num += 1",
"+ n //= p",
"+ res.append([p, num])",
"+ p += 1",
"+ if n != 1:",
"+ res.append([n, 1])",
"+ return res",
"+",
"+",
"+# n! の約数の数を mod で割った余りを返す",
"+def mod_div_fact(n, mod):",
"+ d = {}",
"+ for i in range(2, n + 1):",
"+ L = prime_factorize(i)",
"+ for (p, e) in L:",
"+ d[p] = d.get(p, 0) + e",
"+ res = 1",
"+ for v in list(d.values()):",
"+ res *= v + 1",
"+ res %= mod",
"+ return res",
"+",
"+",
"-exps = [0] * 1003",
"-for i in range(2, n + 1):",
"- t = i",
"- div = 2",
"- while div * div <= i:",
"- if t % div == 0:",
"- exps[div] += 1",
"- t //= div",
"- else:",
"- div += 1",
"- if t != 1:",
"- exps[t] += 1",
"-ans = 1",
"-for i in range(2, n + 1):",
"- ans *= exps[i] + 1",
"- ans %= mod",
"-print(ans)",
"+print((mod_div_fact(n, mod)))"
] | false | 0.036733 | 0.04324 | 0.849519 |
[
"s180732489",
"s873696074"
] |
u616217092
|
p02912
|
python
|
s066000343
|
s962986113
| 199 | 160 | 14,180 | 14,180 |
Accepted
|
Accepted
| 19.6 |
from sys import stdin
import heapq
def main():
N, M = [int(x) for x in stdin.readline().rstrip().split()]
As = []
for i in [int(x) for x in stdin.readline().rstrip().split()]:
heapq.heappush(As, -i)
for _ in range(M):
x = heapq.heappop(As)
heapq.heappush(As, x / 2)
print((sum([-1 * int(x) for x in As])))
if __name__ == "__main__":
main()
|
from sys import stdin
import heapq
def main():
N, M = [int(x) for x in stdin.readline().rstrip().split()]
As = []
for i in [int(x) for x in stdin.readline().rstrip().split()]:
heapq.heappush(As, -i)
for _ in range(M):
x = heapq.heappop(As)
heapq.heappush(As, -(-x // 2))
print((sum([-1 * x for x in As])))
if __name__ == "__main__":
main()
| 17 | 17 | 406 | 406 |
from sys import stdin
import heapq
def main():
N, M = [int(x) for x in stdin.readline().rstrip().split()]
As = []
for i in [int(x) for x in stdin.readline().rstrip().split()]:
heapq.heappush(As, -i)
for _ in range(M):
x = heapq.heappop(As)
heapq.heappush(As, x / 2)
print((sum([-1 * int(x) for x in As])))
if __name__ == "__main__":
main()
|
from sys import stdin
import heapq
def main():
N, M = [int(x) for x in stdin.readline().rstrip().split()]
As = []
for i in [int(x) for x in stdin.readline().rstrip().split()]:
heapq.heappush(As, -i)
for _ in range(M):
x = heapq.heappop(As)
heapq.heappush(As, -(-x // 2))
print((sum([-1 * x for x in As])))
if __name__ == "__main__":
main()
| false | 0 |
[
"- heapq.heappush(As, x / 2)",
"- print((sum([-1 * int(x) for x in As])))",
"+ heapq.heappush(As, -(-x // 2))",
"+ print((sum([-1 * x for x in As])))"
] | false | 0.137455 | 0.037986 | 3.618577 |
[
"s066000343",
"s962986113"
] |
u600402037
|
p02832
|
python
|
s964962011
|
s033671318
| 139 | 100 | 27,180 | 26,140 |
Accepted
|
Accepted
| 28.06 |
import sys
from fractions import gcd
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
N = ri()
A = rl()
answer = 0
cur = 1
for i in range(N):
if A[i] == cur:
answer += 1
cur += 1
print((N - answer if answer > 0 else -1))
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = lr()
cur = 0
for a in A:
if a == cur + 1:
cur += 1
print((N-cur if cur > 0 else -1))
# 54
| 18 | 15 | 397 | 248 |
import sys
from fractions import gcd
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
N = ri()
A = rl()
answer = 0
cur = 1
for i in range(N):
if A[i] == cur:
answer += 1
cur += 1
print((N - answer if answer > 0 else -1))
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = lr()
cur = 0
for a in A:
if a == cur + 1:
cur += 1
print((N - cur if cur > 0 else -1))
# 54
| false | 16.666667 |
[
"-from fractions import gcd",
"-stdin = sys.stdin",
"-ri = lambda: int(rs())",
"-rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers",
"-rs = lambda: stdin.readline().rstrip() # ignores trailing space",
"-N = ri()",
"-A = rl()",
"-answer = 0",
"-cur = 1",
"-for i in range(N):",
"- if A[i] == cur:",
"- answer += 1",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+N = ir()",
"+A = lr()",
"+cur = 0",
"+for a in A:",
"+ if a == cur + 1:",
"-print((N - answer if answer > 0 else -1))",
"+print((N - cur if cur > 0 else -1))",
"+# 54"
] | false | 0.038886 | 0.03738 | 1.040304 |
[
"s964962011",
"s033671318"
] |
u352394527
|
p02368
|
python
|
s210691353
|
s604660009
| 930 | 830 | 19,196 | 19,236 |
Accepted
|
Accepted
| 10.75 |
"""
強連結成分分解
"""
import sys
sys.setrecursionlimit(1000000)
def dfs(v, visited, edges, order):
visited[v] = True
for to in edges[v]:
if not visited[to]:
dfs(to, visited, edges, order)
order.append(v)
def search_strongly_connection(v, visited, reverse_edges, parent, num):
visited[v] = True
for to in reverse_edges[v]:
if not visited[to]:
parent[to] = num
search_strongly_connection(to, visited, reverse_edges, parent, num)
v_num , e_num = list(map(int, input().split()))
edges = [[] for _ in range(v_num)]
reverse_edges = [[] for _ in range(v_num)]
for _ in range(e_num):
s, t = list(map(int, input().split()))
edges[s].append(t)
reverse_edges[t].append(s)
order = []
visited = [False] * v_num
for v in range(v_num):
if not visited[v]:
dfs(v, visited, edges, order)
order.reverse()
visited = [False] * v_num
parent = [i for i in range(v_num)]
for v in order:
num = v
if not visited[v]:
search_strongly_connection(v, visited, reverse_edges, parent, num)
q_num = int(eval(input()))
for _ in range(q_num):
u, v = list(map(int, input().split()))
if parent[u] == parent[v]:
print((1))
else:
print((0))
|
"""
強連結成分分解
"""
import sys
sys.setrecursionlimit(1000000)
def dfs(v, visited, edges, order):
visited[v] = True
for to in edges[v]:
if not visited[to]:
dfs(to, visited, edges, order)
order.append(v)
def search_strongly_connection(v, visited, reverse_edges, parent, num):
visited[v] = True
for to in reverse_edges[v]:
if not visited[to]:
parent[to] = num
search_strongly_connection(to, visited, reverse_edges, parent, num)
def main():
v_num , e_num = list(map(int, input().split()))
edges = [[] for _ in range(v_num)]
reverse_edges = [[] for _ in range(v_num)]
for _ in range(e_num):
s, t = list(map(int, input().split()))
edges[s].append(t)
reverse_edges[t].append(s)
order = []
visited = [False] * v_num
for v in range(v_num):
if not visited[v]:
dfs(v, visited, edges, order)
order.reverse()
visited = [False] * v_num
parent = [i for i in range(v_num)]
for v in order:
if not visited[v]:
search_strongly_connection(v, visited, reverse_edges, parent, v)
q_num = int(eval(input()))
for _ in range(q_num):
u, v = list(map(int, input().split()))
print((1 if parent[u] == parent[v] else 0))
main()
| 53 | 52 | 1,199 | 1,241 |
"""
強連結成分分解
"""
import sys
sys.setrecursionlimit(1000000)
def dfs(v, visited, edges, order):
visited[v] = True
for to in edges[v]:
if not visited[to]:
dfs(to, visited, edges, order)
order.append(v)
def search_strongly_connection(v, visited, reverse_edges, parent, num):
visited[v] = True
for to in reverse_edges[v]:
if not visited[to]:
parent[to] = num
search_strongly_connection(to, visited, reverse_edges, parent, num)
v_num, e_num = list(map(int, input().split()))
edges = [[] for _ in range(v_num)]
reverse_edges = [[] for _ in range(v_num)]
for _ in range(e_num):
s, t = list(map(int, input().split()))
edges[s].append(t)
reverse_edges[t].append(s)
order = []
visited = [False] * v_num
for v in range(v_num):
if not visited[v]:
dfs(v, visited, edges, order)
order.reverse()
visited = [False] * v_num
parent = [i for i in range(v_num)]
for v in order:
num = v
if not visited[v]:
search_strongly_connection(v, visited, reverse_edges, parent, num)
q_num = int(eval(input()))
for _ in range(q_num):
u, v = list(map(int, input().split()))
if parent[u] == parent[v]:
print((1))
else:
print((0))
|
"""
強連結成分分解
"""
import sys
sys.setrecursionlimit(1000000)
def dfs(v, visited, edges, order):
visited[v] = True
for to in edges[v]:
if not visited[to]:
dfs(to, visited, edges, order)
order.append(v)
def search_strongly_connection(v, visited, reverse_edges, parent, num):
visited[v] = True
for to in reverse_edges[v]:
if not visited[to]:
parent[to] = num
search_strongly_connection(to, visited, reverse_edges, parent, num)
def main():
v_num, e_num = list(map(int, input().split()))
edges = [[] for _ in range(v_num)]
reverse_edges = [[] for _ in range(v_num)]
for _ in range(e_num):
s, t = list(map(int, input().split()))
edges[s].append(t)
reverse_edges[t].append(s)
order = []
visited = [False] * v_num
for v in range(v_num):
if not visited[v]:
dfs(v, visited, edges, order)
order.reverse()
visited = [False] * v_num
parent = [i for i in range(v_num)]
for v in order:
if not visited[v]:
search_strongly_connection(v, visited, reverse_edges, parent, v)
q_num = int(eval(input()))
for _ in range(q_num):
u, v = list(map(int, input().split()))
print((1 if parent[u] == parent[v] else 0))
main()
| false | 1.886792 |
[
"-v_num, e_num = list(map(int, input().split()))",
"-edges = [[] for _ in range(v_num)]",
"-reverse_edges = [[] for _ in range(v_num)]",
"-for _ in range(e_num):",
"- s, t = list(map(int, input().split()))",
"- edges[s].append(t)",
"- reverse_edges[t].append(s)",
"-order = []",
"-visited = [False] * v_num",
"-for v in range(v_num):",
"- if not visited[v]:",
"- dfs(v, visited, edges, order)",
"-order.reverse()",
"-visited = [False] * v_num",
"-parent = [i for i in range(v_num)]",
"-for v in order:",
"- num = v",
"- if not visited[v]:",
"- search_strongly_connection(v, visited, reverse_edges, parent, num)",
"-q_num = int(eval(input()))",
"-for _ in range(q_num):",
"- u, v = list(map(int, input().split()))",
"- if parent[u] == parent[v]:",
"- print((1))",
"- else:",
"- print((0))",
"+def main():",
"+ v_num, e_num = list(map(int, input().split()))",
"+ edges = [[] for _ in range(v_num)]",
"+ reverse_edges = [[] for _ in range(v_num)]",
"+ for _ in range(e_num):",
"+ s, t = list(map(int, input().split()))",
"+ edges[s].append(t)",
"+ reverse_edges[t].append(s)",
"+ order = []",
"+ visited = [False] * v_num",
"+ for v in range(v_num):",
"+ if not visited[v]:",
"+ dfs(v, visited, edges, order)",
"+ order.reverse()",
"+ visited = [False] * v_num",
"+ parent = [i for i in range(v_num)]",
"+ for v in order:",
"+ if not visited[v]:",
"+ search_strongly_connection(v, visited, reverse_edges, parent, v)",
"+ q_num = int(eval(input()))",
"+ for _ in range(q_num):",
"+ u, v = list(map(int, input().split()))",
"+ print((1 if parent[u] == parent[v] else 0))",
"+",
"+",
"+main()"
] | false | 0.037679 | 0.035782 | 1.053001 |
[
"s210691353",
"s604660009"
] |
u549161102
|
p03610
|
python
|
s107154690
|
s778752079
| 43 | 21 | 3,956 | 3,572 |
Accepted
|
Accepted
| 51.16 |
s = list(eval(input()))
l = len(s)
a = ''
if l%2 != 0:
for i in range(l//2+1):
a = a + "".join(s[2*i])
else:
for i in range(l//2):
a = a + "".join(s[2*i])
print(a)
|
S = eval(input())
l = [S[i] for i in range(0,len(S),2)]
a = "".join(l)
print(a)
| 10 | 4 | 190 | 76 |
s = list(eval(input()))
l = len(s)
a = ""
if l % 2 != 0:
for i in range(l // 2 + 1):
a = a + "".join(s[2 * i])
else:
for i in range(l // 2):
a = a + "".join(s[2 * i])
print(a)
|
S = eval(input())
l = [S[i] for i in range(0, len(S), 2)]
a = "".join(l)
print(a)
| false | 60 |
[
"-s = list(eval(input()))",
"-l = len(s)",
"-a = \"\"",
"-if l % 2 != 0:",
"- for i in range(l // 2 + 1):",
"- a = a + \"\".join(s[2 * i])",
"-else:",
"- for i in range(l // 2):",
"- a = a + \"\".join(s[2 * i])",
"+S = eval(input())",
"+l = [S[i] for i in range(0, len(S), 2)]",
"+a = \"\".join(l)"
] | false | 0.053162 | 0.040896 | 1.299925 |
[
"s107154690",
"s778752079"
] |
u445624660
|
p02971
|
python
|
s790032924
|
s422467546
| 681 | 355 | 40,964 | 9,188 |
Accepted
|
Accepted
| 47.87 |
# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用
n = int(eval(input()))
arr = []
for i in range(n):
t = int(eval(input()))
arr.append([i, t])
sorted_arr = list(sorted(arr, key = lambda x : x[1]))
biggest = sorted_arr[-1]
second_biggest = sorted_arr[-2]
for i in range(n):
if i != biggest[0]:
print((biggest[1]))
else:
print((second_biggest[1]))
|
n = int(eval(input()))
max_n = -1
semi_max_n = -1
max_idx = -1
for i in range(n):
x = int(eval(input()))
if x > max_n:
max_n = x
max_idx = i
elif x >= semi_max_n:
semi_max_n = x
for i in range(n):
if i == max_idx:
print(semi_max_n)
else:
print(max_n)
| 16 | 16 | 356 | 313 |
# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用
n = int(eval(input()))
arr = []
for i in range(n):
t = int(eval(input()))
arr.append([i, t])
sorted_arr = list(sorted(arr, key=lambda x: x[1]))
biggest = sorted_arr[-1]
second_biggest = sorted_arr[-2]
for i in range(n):
if i != biggest[0]:
print((biggest[1]))
else:
print((second_biggest[1]))
|
n = int(eval(input()))
max_n = -1
semi_max_n = -1
max_idx = -1
for i in range(n):
x = int(eval(input()))
if x > max_n:
max_n = x
max_idx = i
elif x >= semi_max_n:
semi_max_n = x
for i in range(n):
if i == max_idx:
print(semi_max_n)
else:
print(max_n)
| false | 0 |
[
"-# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用",
"-arr = []",
"+max_n = -1",
"+semi_max_n = -1",
"+max_idx = -1",
"- t = int(eval(input()))",
"- arr.append([i, t])",
"-sorted_arr = list(sorted(arr, key=lambda x: x[1]))",
"-biggest = sorted_arr[-1]",
"-second_biggest = sorted_arr[-2]",
"+ x = int(eval(input()))",
"+ if x > max_n:",
"+ max_n = x",
"+ max_idx = i",
"+ elif x >= semi_max_n:",
"+ semi_max_n = x",
"- if i != biggest[0]:",
"- print((biggest[1]))",
"+ if i == max_idx:",
"+ print(semi_max_n)",
"- print((second_biggest[1]))",
"+ print(max_n)"
] | false | 0.040888 | 0.04101 | 0.997016 |
[
"s790032924",
"s422467546"
] |
u347600233
|
p02984
|
python
|
s961885918
|
s738164297
| 203 | 127 | 14,024 | 14,092 |
Accepted
|
Accepted
| 37.44 |
n = int(input())
a = [int(i) for i in input().split()]
x = [0] * n
not_x0 = 0
for i in range(1, n, 2):
not_x0 += 2*a[i]
x[0] = sum(a) - not_x0
for i in range(1, n):
x[i] = 2*a[i - 1] - x[i - 1]
for i in range(n):
print(x[i], end=' ')
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
x = [0] * n
x[0] = sum(a) - 2*sum(a[1::2])
for i in range(1, n):
x[i] = 2*a[i - 1] - x[i - 1]
print((*x))
| 14 | 8 | 261 | 170 |
n = int(input())
a = [int(i) for i in input().split()]
x = [0] * n
not_x0 = 0
for i in range(1, n, 2):
not_x0 += 2 * a[i]
x[0] = sum(a) - not_x0
for i in range(1, n):
x[i] = 2 * a[i - 1] - x[i - 1]
for i in range(n):
print(x[i], end=" ")
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
x = [0] * n
x[0] = sum(a) - 2 * sum(a[1::2])
for i in range(1, n):
x[i] = 2 * a[i - 1] - x[i - 1]
print((*x))
| false | 42.857143 |
[
"-n = int(input())",
"+n = int(eval(input()))",
"-not_x0 = 0",
"-for i in range(1, n, 2):",
"- not_x0 += 2 * a[i]",
"-x[0] = sum(a) - not_x0",
"+x[0] = sum(a) - 2 * sum(a[1::2])",
"-for i in range(n):",
"- print(x[i], end=\" \")",
"+print((*x))"
] | false | 0.035842 | 0.03632 | 0.98684 |
[
"s961885918",
"s738164297"
] |
u701644092
|
p03212
|
python
|
s485613261
|
s132611635
| 75 | 63 | 9,420 | 9,092 |
Accepted
|
Accepted
| 16 |
N = int(eval(input()))
T = ("3","5","7")
from collections import deque
que = deque(list(T))
ans = 0
while que:
num = que.pop()
if int(num) > N:
continue
if len(set(num)) == 3:
ans += 1
for t in T:
que.append(num + t)
print(ans)
|
N = int(eval(input()))
T = ("3","5","7")
def dfs(x):
if x != "" and int(x) > N:
return 0
res = 0
if len(set(x)) == 3:
res = 1
for t in T:
res += dfs(x + t)
return res
print((dfs("")))
| 17 | 14 | 260 | 214 |
N = int(eval(input()))
T = ("3", "5", "7")
from collections import deque
que = deque(list(T))
ans = 0
while que:
num = que.pop()
if int(num) > N:
continue
if len(set(num)) == 3:
ans += 1
for t in T:
que.append(num + t)
print(ans)
|
N = int(eval(input()))
T = ("3", "5", "7")
def dfs(x):
if x != "" and int(x) > N:
return 0
res = 0
if len(set(x)) == 3:
res = 1
for t in T:
res += dfs(x + t)
return res
print((dfs("")))
| false | 17.647059 |
[
"-from collections import deque",
"-que = deque(list(T))",
"-ans = 0",
"-while que:",
"- num = que.pop()",
"- if int(num) > N:",
"- continue",
"- if len(set(num)) == 3:",
"- ans += 1",
"+",
"+def dfs(x):",
"+ if x != \"\" and int(x) > N:",
"+ return 0",
"+ res = 0",
"+ if len(set(x)) == 3:",
"+ res = 1",
"- que.append(num + t)",
"-print(ans)",
"+ res += dfs(x + t)",
"+ return res",
"+",
"+",
"+print((dfs(\"\")))"
] | false | 0.044482 | 0.046466 | 0.957293 |
[
"s485613261",
"s132611635"
] |
u670180528
|
p04035
|
python
|
s409301628
|
s935557547
| 77 | 71 | 19,660 | 19,660 |
Accepted
|
Accepted
| 7.79 |
n,l,*a=list(map(int,open(0).read().split()))
for i,(x,y) in enumerate(zip(a,a[1:])):
if x+y>=l:
print("Possible")
r=list(range(n))
print(("\n".join(map(str,r[1:i+1]+r[n:i:-1]))))
exit()
print("Impossible")
|
def s():
n, l, *a = list(map(int, open(0).read().split()))
for i, (x, y) in enumerate(zip(a, a[1:])):
if x + y >= l:
print("Possible")
r = list(range(n))
print(("\n".join(map(str, r[1:i + 1] + r[n:i:-1]))))
break
else:
print("Impossible")
if __name__=="__main__":
s()
| 8 | 12 | 213 | 290 |
n, l, *a = list(map(int, open(0).read().split()))
for i, (x, y) in enumerate(zip(a, a[1:])):
if x + y >= l:
print("Possible")
r = list(range(n))
print(("\n".join(map(str, r[1 : i + 1] + r[n:i:-1]))))
exit()
print("Impossible")
|
def s():
n, l, *a = list(map(int, open(0).read().split()))
for i, (x, y) in enumerate(zip(a, a[1:])):
if x + y >= l:
print("Possible")
r = list(range(n))
print(("\n".join(map(str, r[1 : i + 1] + r[n:i:-1]))))
break
else:
print("Impossible")
if __name__ == "__main__":
s()
| false | 33.333333 |
[
"-n, l, *a = list(map(int, open(0).read().split()))",
"-for i, (x, y) in enumerate(zip(a, a[1:])):",
"- if x + y >= l:",
"- print(\"Possible\")",
"- r = list(range(n))",
"- print((\"\\n\".join(map(str, r[1 : i + 1] + r[n:i:-1]))))",
"- exit()",
"-print(\"Impossible\")",
"+def s():",
"+ n, l, *a = list(map(int, open(0).read().split()))",
"+ for i, (x, y) in enumerate(zip(a, a[1:])):",
"+ if x + y >= l:",
"+ print(\"Possible\")",
"+ r = list(range(n))",
"+ print((\"\\n\".join(map(str, r[1 : i + 1] + r[n:i:-1]))))",
"+ break",
"+ else:",
"+ print(\"Impossible\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ s()"
] | false | 0.044032 | 0.077228 | 0.570157 |
[
"s409301628",
"s935557547"
] |
u904995051
|
p03631
|
python
|
s521285357
|
s279524684
| 31 | 23 | 9,088 | 9,028 |
Accepted
|
Accepted
| 25.81 |
#ABC070A
a = eval(input())
print(("Yes" if (a[-1] == a[0]) else "No"))
|
#ABC070
#文字列の逆順
n = eval(input())
print(("Yes" if n==n[::-1] else "No"))
| 3 | 4 | 64 | 67 |
# ABC070A
a = eval(input())
print(("Yes" if (a[-1] == a[0]) else "No"))
|
# ABC070
# 文字列の逆順
n = eval(input())
print(("Yes" if n == n[::-1] else "No"))
| false | 25 |
[
"-# ABC070A",
"-a = eval(input())",
"-print((\"Yes\" if (a[-1] == a[0]) else \"No\"))",
"+# ABC070",
"+# 文字列の逆順",
"+n = eval(input())",
"+print((\"Yes\" if n == n[::-1] else \"No\"))"
] | false | 0.032053 | 0.036439 | 0.879653 |
[
"s521285357",
"s279524684"
] |
u718949306
|
p02630
|
python
|
s659482811
|
s334996590
| 390 | 349 | 26,968 | 21,828 |
Accepted
|
Accepted
| 10.51 |
N = int(eval(input()))
A = list(map(int, input().split()))
B = [0]*(N+1)
for n in range(N):
B[n+1] = B[n] + A[n]
C = B.pop()
Z = {}
for n in range(N):
Z[A[n]] = 0
for n in range(N):
Z[A[n]] += 1
D = []
Q = int(eval(input()))
for q in range(Q):
x, y = list(map(int, input().split()))
if x in Z:
C = C - x*Z[x]
C = C + y*Z[x]
D.append(C)
if x == y:
continue
if y in Z:
Z[y] += 1*Z[x]
else:
Z[y] = Z[x]
Z.pop(x)
else:
D.append(C)
for d in D:
print(d)
|
N = int(eval(input()))
A = list(map(int, input().split()))
C = sum(A)
Z = {}
for n in range(N):
Z[A[n]] = 0
for n in range(N):
Z[A[n]] += 1
D = []
Q = int(eval(input()))
for q in range(Q):
x, y = list(map(int, input().split()))
if x in Z:
C = C - x*Z[x]
C = C + y*Z[x]
D.append(C)
if x == y:
continue
if y in Z:
Z[y] += 1*Z[x]
else:
Z[y] = Z[x]
Z.pop(x)
else:
D.append(C)
for d in D:
print(d)
| 32 | 27 | 590 | 525 |
N = int(eval(input()))
A = list(map(int, input().split()))
B = [0] * (N + 1)
for n in range(N):
B[n + 1] = B[n] + A[n]
C = B.pop()
Z = {}
for n in range(N):
Z[A[n]] = 0
for n in range(N):
Z[A[n]] += 1
D = []
Q = int(eval(input()))
for q in range(Q):
x, y = list(map(int, input().split()))
if x in Z:
C = C - x * Z[x]
C = C + y * Z[x]
D.append(C)
if x == y:
continue
if y in Z:
Z[y] += 1 * Z[x]
else:
Z[y] = Z[x]
Z.pop(x)
else:
D.append(C)
for d in D:
print(d)
|
N = int(eval(input()))
A = list(map(int, input().split()))
C = sum(A)
Z = {}
for n in range(N):
Z[A[n]] = 0
for n in range(N):
Z[A[n]] += 1
D = []
Q = int(eval(input()))
for q in range(Q):
x, y = list(map(int, input().split()))
if x in Z:
C = C - x * Z[x]
C = C + y * Z[x]
D.append(C)
if x == y:
continue
if y in Z:
Z[y] += 1 * Z[x]
else:
Z[y] = Z[x]
Z.pop(x)
else:
D.append(C)
for d in D:
print(d)
| false | 15.625 |
[
"-B = [0] * (N + 1)",
"-for n in range(N):",
"- B[n + 1] = B[n] + A[n]",
"-C = B.pop()",
"+C = sum(A)"
] | false | 0.071838 | 0.051405 | 1.397479 |
[
"s659482811",
"s334996590"
] |
u254871849
|
p03476
|
python
|
s658738492
|
s286174118
| 212 | 159 | 22,552 | 26,388 |
Accepted
|
Accepted
| 25 |
import sys
# import collections
# import math
# import bisect
# import re
# import itertools
def primeNums(n):
from math import floor, sqrt
sieve = set(range(2, n + 1))
if 2 in sieve:
not_prime = set(range(2 * 2, n + 1, 2))
sieve -= not_prime
for i in range(3, floor(sqrt(n)) + 1, 2):
if i in sieve:
not_prime = set(range(i * 2, n + 1, i))
sieve -= not_prime
return sieve
limit = 10 ** 5
prime_table = [0 for _ in range(limit + 1)]
for p in primeNums(limit):
prime_table[p] = 1
like_2017_table = [0 for _ in range(limit + 1)]
for i in range(3, limit + 1, 2):
if prime_table[i] and prime_table[(i + 1) // 2]:
like_2017_table[i] = 1
s = [0 for _ in range(limit + 1)]
for i in range(limit):
s[i+1] = s[i] + like_2017_table[i+1]
def main():
q = int(sys.stdin.readline().rstrip())
m = list(map(int, sys.stdin.read().split()))
for l, r in zip(m, m):
res = s[r] - s[l-1]
print(res)
if __name__ == "__main__":
main()
|
import sys
from math import floor, sqrt
def prime_nums(n):
sieve = set(range(2, n + 1))
non_prime = set(range(2 * 2, n + 1, 2))
sieve -= non_prime
for i in range(3, floor(sqrt(n)) + 1, 2):
if i in sieve:
non_prime = set(range(i * 2, n + 1, i))
sieve -= non_prime
return sieve
p = prime_nums(10**5)
cnt = [None] * (10**5+1)
cnt[0] = 0
for i in range(1, 10**5+1, 2):
if i in p and (i + 1) // 2 in p:
cnt[i] = cnt[i-1] + 1
else:
cnt[i] = cnt[i-1]
cnt[i+1] = cnt[i]
q = int(sys.stdin.readline().rstrip())
lr = zip(*[map(int, sys.stdin.read().split())] * 2)
def main():
for l, r in lr:
yield cnt[r] - cnt[l-1]
if __name__ == '__main__':
ans = main()
print(*ans, sep='\n')
| 46 | 34 | 1,082 | 809 |
import sys
# import collections
# import math
# import bisect
# import re
# import itertools
def primeNums(n):
from math import floor, sqrt
sieve = set(range(2, n + 1))
if 2 in sieve:
not_prime = set(range(2 * 2, n + 1, 2))
sieve -= not_prime
for i in range(3, floor(sqrt(n)) + 1, 2):
if i in sieve:
not_prime = set(range(i * 2, n + 1, i))
sieve -= not_prime
return sieve
limit = 10**5
prime_table = [0 for _ in range(limit + 1)]
for p in primeNums(limit):
prime_table[p] = 1
like_2017_table = [0 for _ in range(limit + 1)]
for i in range(3, limit + 1, 2):
if prime_table[i] and prime_table[(i + 1) // 2]:
like_2017_table[i] = 1
s = [0 for _ in range(limit + 1)]
for i in range(limit):
s[i + 1] = s[i] + like_2017_table[i + 1]
def main():
q = int(sys.stdin.readline().rstrip())
m = list(map(int, sys.stdin.read().split()))
for l, r in zip(m, m):
res = s[r] - s[l - 1]
print(res)
if __name__ == "__main__":
main()
|
import sys
from math import floor, sqrt
def prime_nums(n):
sieve = set(range(2, n + 1))
non_prime = set(range(2 * 2, n + 1, 2))
sieve -= non_prime
for i in range(3, floor(sqrt(n)) + 1, 2):
if i in sieve:
non_prime = set(range(i * 2, n + 1, i))
sieve -= non_prime
return sieve
p = prime_nums(10**5)
cnt = [None] * (10**5 + 1)
cnt[0] = 0
for i in range(1, 10**5 + 1, 2):
if i in p and (i + 1) // 2 in p:
cnt[i] = cnt[i - 1] + 1
else:
cnt[i] = cnt[i - 1]
cnt[i + 1] = cnt[i]
q = int(sys.stdin.readline().rstrip())
lr = zip(*[map(int, sys.stdin.read().split())] * 2)
def main():
for l, r in lr:
yield cnt[r] - cnt[l - 1]
if __name__ == "__main__":
ans = main()
print(*ans, sep="\n")
| false | 26.086957 |
[
"+from math import floor, sqrt",
"-# import collections",
"-# import math",
"-# import bisect",
"-# import re",
"-# import itertools",
"-def primeNums(n):",
"- from math import floor, sqrt",
"+def prime_nums(n):",
"- if 2 in sieve:",
"- not_prime = set(range(2 * 2, n + 1, 2))",
"- sieve -= not_prime",
"+ non_prime = set(range(2 * 2, n + 1, 2))",
"+ sieve -= non_prime",
"- not_prime = set(range(i * 2, n + 1, i))",
"- sieve -= not_prime",
"+ non_prime = set(range(i * 2, n + 1, i))",
"+ sieve -= non_prime",
"-limit = 10**5",
"-prime_table = [0 for _ in range(limit + 1)]",
"-for p in primeNums(limit):",
"- prime_table[p] = 1",
"-like_2017_table = [0 for _ in range(limit + 1)]",
"-for i in range(3, limit + 1, 2):",
"- if prime_table[i] and prime_table[(i + 1) // 2]:",
"- like_2017_table[i] = 1",
"-s = [0 for _ in range(limit + 1)]",
"-for i in range(limit):",
"- s[i + 1] = s[i] + like_2017_table[i + 1]",
"+p = prime_nums(10**5)",
"+cnt = [None] * (10**5 + 1)",
"+cnt[0] = 0",
"+for i in range(1, 10**5 + 1, 2):",
"+ if i in p and (i + 1) // 2 in p:",
"+ cnt[i] = cnt[i - 1] + 1",
"+ else:",
"+ cnt[i] = cnt[i - 1]",
"+ cnt[i + 1] = cnt[i]",
"+q = int(sys.stdin.readline().rstrip())",
"+lr = zip(*[map(int, sys.stdin.read().split())] * 2)",
"- q = int(sys.stdin.readline().rstrip())",
"- m = list(map(int, sys.stdin.read().split()))",
"- for l, r in zip(m, m):",
"- res = s[r] - s[l - 1]",
"- print(res)",
"+ for l, r in lr:",
"+ yield cnt[r] - cnt[l - 1]",
"- main()",
"+ ans = main()",
"+ print(*ans, sep=\"\\n\")"
] | false | 0.359262 | 0.344154 | 1.043898 |
[
"s658738492",
"s286174118"
] |
u608007704
|
p02621
|
python
|
s417089982
|
s269971013
| 29 | 25 | 9,148 | 9,084 |
Accepted
|
Accepted
| 13.79 |
x=int(eval(input()))
print((x+x*x+x*x*x))
|
a=int(eval(input()))
print((a+a**2+a**3))
| 2 | 2 | 34 | 34 |
x = int(eval(input()))
print((x + x * x + x * x * x))
|
a = int(eval(input()))
print((a + a**2 + a**3))
| false | 0 |
[
"-x = int(eval(input()))",
"-print((x + x * x + x * x * x))",
"+a = int(eval(input()))",
"+print((a + a**2 + a**3))"
] | false | 0.042494 | 0.036421 | 1.166765 |
[
"s417089982",
"s269971013"
] |
u556589653
|
p02789
|
python
|
s356423825
|
s177884917
| 178 | 28 | 38,384 | 9,152 |
Accepted
|
Accepted
| 84.27 |
N,M = list(map(int,input().split()))
if N==M:
print("Yes")
else:
print("No")
|
a,b = list(map(int,input().split()))
if a == b:
print("Yes")
else:
print("No")
| 5 | 5 | 78 | 80 |
N, M = list(map(int, input().split()))
if N == M:
print("Yes")
else:
print("No")
|
a, b = list(map(int, input().split()))
if a == b:
print("Yes")
else:
print("No")
| false | 0 |
[
"-N, M = list(map(int, input().split()))",
"-if N == M:",
"+a, b = list(map(int, input().split()))",
"+if a == b:"
] | false | 0.040437 | 0.037934 | 1.06597 |
[
"s356423825",
"s177884917"
] |
u227082700
|
p02880
|
python
|
s804693956
|
s988176778
| 20 | 18 | 2,940 | 2,940 |
Accepted
|
Accepted
| 10 |
n=int(eval(input()))
for i in range(1,10):
if n%i==0 and n//i<10:print("Yes");exit()
print("No")
|
n=int(eval(input()))
for i in range(1,10):
for j in range(1,10):
if n==i*j:print("Yes");exit()
print("No")
| 4 | 5 | 95 | 110 |
n = int(eval(input()))
for i in range(1, 10):
if n % i == 0 and n // i < 10:
print("Yes")
exit()
print("No")
|
n = int(eval(input()))
for i in range(1, 10):
for j in range(1, 10):
if n == i * j:
print("Yes")
exit()
print("No")
| false | 20 |
[
"- if n % i == 0 and n // i < 10:",
"- print(\"Yes\")",
"- exit()",
"+ for j in range(1, 10):",
"+ if n == i * j:",
"+ print(\"Yes\")",
"+ exit()"
] | false | 0.038155 | 0.038889 | 0.981131 |
[
"s804693956",
"s988176778"
] |
u635391238
|
p01132
|
python
|
s227653885
|
s228552547
| 120 | 110 | 7,708 | 7,776 |
Accepted
|
Accepted
| 8.33 |
def back_oturigation(fee, coin_values, coin_nums):
"""
1. ????????????????????????????????£??????????????????
2. 1????????????????????????????????????????????????????????????
???????????§?????????????????????-> ?°????????????????????¶???????????????????
3. 2????????????????????°?????????????????????????????????????????????
"""
# 1.
oturi = coin_values[0] * coin_nums[0] \
+ coin_values[1] * coin_nums[1] \
+ coin_values[2] * coin_nums[2] \
+ coin_values[3] * coin_nums[3] \
- fee
use_coins = [0] * len(coin_values)
no_use_coins = [0] * len(coin_values)
# 2.
for i in range(len(coin_values) - 1, -1, -1):
no_use_coins[i] = int(oturi / coin_values[i])
oturi = oturi - (coin_values[i] * no_use_coins[i])
# 3.
for i in range(0, len(use_coins), 1):
use_coins[i] = coin_nums[i] - no_use_coins[i]
if use_coins[i] > 0:
print(str(coin_values[i]) + ' ' + str(use_coins[i]))
if __name__ == "__main__":
first = True
while (True):
total_fee = int(input(''))
if total_fee == 0:
break
if first:
first = False
else:
print('')
coins = input('')
coins = coins.split(' ') # 10, 50, 100, 500????????§????????????
coins = [int(coin) for coin in coins]
coin_values = [10, 50, 100, 500]
back_oturigation(total_fee, coin_values, coins)
|
def back_oturigation(fee, coin_values, coin_nums):
"""
1. ?????????????????????????????????£??????????????????
2. 1????????????????????????????????????????????????????????????
????????????§?????????????????????-> ??°?????????????????????¶???????????????????
3. 2?????????????????????°?????????????????????????????????????????????
"""
# 1.
oturi = coin_values[0] * coin_nums[0] \
+ coin_values[1] * coin_nums[1] \
+ coin_values[2] * coin_nums[2] \
+ coin_values[3] * coin_nums[3] \
- fee
use_coins = [0] * len(coin_values)
no_use_coins = [0] * len(coin_values)
# 2.
for i in range(len(coin_values) - 1, -1, -1):
no_use_coins[i] = int(oturi / coin_values[i])
oturi = oturi - (coin_values[i] * no_use_coins[i])
# 3.
for i in range(0, len(use_coins), 1):
use_coins[i] = coin_nums[i] - no_use_coins[i]
if use_coins[i] > 0:
print(str(coin_values[i]) + ' ' + str(use_coins[i]))
if __name__ == "__main__":
first = True
while (True):
total_fee = int(input(''))
if total_fee == 0:
break
if first:
first = False
else:
print('')
coins = input('')
coins = coins.split(' ') # 10, 50, 100, 500?????????§????????????
coins = [int(coin) for coin in coins]
coin_values = [10, 50, 100, 500]
back_oturigation(total_fee, coin_values, coins)
| 43 | 42 | 1,527 | 1,534 |
def back_oturigation(fee, coin_values, coin_nums):
"""
1. ????????????????????????????????£??????????????????
2. 1????????????????????????????????????????????????????????????
???????????§?????????????????????-> ?°????????????????????¶???????????????????
3. 2????????????????????°?????????????????????????????????????????????
"""
# 1.
oturi = (
coin_values[0] * coin_nums[0]
+ coin_values[1] * coin_nums[1]
+ coin_values[2] * coin_nums[2]
+ coin_values[3] * coin_nums[3]
- fee
)
use_coins = [0] * len(coin_values)
no_use_coins = [0] * len(coin_values)
# 2.
for i in range(len(coin_values) - 1, -1, -1):
no_use_coins[i] = int(oturi / coin_values[i])
oturi = oturi - (coin_values[i] * no_use_coins[i])
# 3.
for i in range(0, len(use_coins), 1):
use_coins[i] = coin_nums[i] - no_use_coins[i]
if use_coins[i] > 0:
print(str(coin_values[i]) + " " + str(use_coins[i]))
if __name__ == "__main__":
first = True
while True:
total_fee = int(input(""))
if total_fee == 0:
break
if first:
first = False
else:
print("")
coins = input("")
coins = coins.split(" ") # 10, 50, 100, 500????????§????????????
coins = [int(coin) for coin in coins]
coin_values = [10, 50, 100, 500]
back_oturigation(total_fee, coin_values, coins)
|
def back_oturigation(fee, coin_values, coin_nums):
"""
1. ?????????????????????????????????£??????????????????
2. 1????????????????????????????????????????????????????????????
????????????§?????????????????????-> ??°?????????????????????¶???????????????????
3. 2?????????????????????°?????????????????????????????????????????????
"""
# 1.
oturi = (
coin_values[0] * coin_nums[0]
+ coin_values[1] * coin_nums[1]
+ coin_values[2] * coin_nums[2]
+ coin_values[3] * coin_nums[3]
- fee
)
use_coins = [0] * len(coin_values)
no_use_coins = [0] * len(coin_values)
# 2.
for i in range(len(coin_values) - 1, -1, -1):
no_use_coins[i] = int(oturi / coin_values[i])
oturi = oturi - (coin_values[i] * no_use_coins[i])
# 3.
for i in range(0, len(use_coins), 1):
use_coins[i] = coin_nums[i] - no_use_coins[i]
if use_coins[i] > 0:
print(str(coin_values[i]) + " " + str(use_coins[i]))
if __name__ == "__main__":
first = True
while True:
total_fee = int(input(""))
if total_fee == 0:
break
if first:
first = False
else:
print("")
coins = input("")
coins = coins.split(" ") # 10, 50, 100, 500?????????§????????????
coins = [int(coin) for coin in coins]
coin_values = [10, 50, 100, 500]
back_oturigation(total_fee, coin_values, coins)
| false | 2.325581 |
[
"- 1. ????????????????????????????????£??????????????????",
"+ 1. ?????????????????????????????????£??????????????????",
"- ???????????§?????????????????????-> ?°????????????????????¶???????????????????",
"- 3. 2????????????????????°?????????????????????????????????????????????",
"+ ????????????§?????????????????????-> ??°?????????????????????¶???????????????????",
"+ 3. 2?????????????????????°?????????????????????????????????????????????",
"- coins = coins.split(\" \") # 10, 50, 100, 500????????§????????????",
"+ coins = coins.split(\" \") # 10, 50, 100, 500?????????§????????????"
] | false | 0.042841 | 0.049036 | 0.873677 |
[
"s227653885",
"s228552547"
] |
u970308980
|
p02882
|
python
|
s611271999
|
s685930994
| 170 | 19 | 38,356 | 3,188 |
Accepted
|
Accepted
| 88.82 |
import math
a, b, x = list(map(int, input().split()))
p = ((x*2)/(a**2)) - b
if p == 0:
print((45))
exit()
if p > 0:
radian = math.atan2(a, b-p)
print((90-math.degrees(radian)))
else:
p = 2*x/(a*b)
radian = math.atan2(b, p)
print((math.degrees(radian)))
|
import math
a, b, x = list(map(int, input().split()))
s = x / a
if s >= a * b / 2:
h = (a * b - s) * 2 / a
radian = math.atan2(h, a)
else:
w = s * 2 / b
radian = math.atan2(b, w)
ans = math.degrees(radian)
print(ans)
| 17 | 14 | 290 | 243 |
import math
a, b, x = list(map(int, input().split()))
p = ((x * 2) / (a**2)) - b
if p == 0:
print((45))
exit()
if p > 0:
radian = math.atan2(a, b - p)
print((90 - math.degrees(radian)))
else:
p = 2 * x / (a * b)
radian = math.atan2(b, p)
print((math.degrees(radian)))
|
import math
a, b, x = list(map(int, input().split()))
s = x / a
if s >= a * b / 2:
h = (a * b - s) * 2 / a
radian = math.atan2(h, a)
else:
w = s * 2 / b
radian = math.atan2(b, w)
ans = math.degrees(radian)
print(ans)
| false | 17.647059 |
[
"-p = ((x * 2) / (a**2)) - b",
"-if p == 0:",
"- print((45))",
"- exit()",
"-if p > 0:",
"- radian = math.atan2(a, b - p)",
"- print((90 - math.degrees(radian)))",
"+s = x / a",
"+if s >= a * b / 2:",
"+ h = (a * b - s) * 2 / a",
"+ radian = math.atan2(h, a)",
"- p = 2 * x / (a * b)",
"- radian = math.atan2(b, p)",
"- print((math.degrees(radian)))",
"+ w = s * 2 / b",
"+ radian = math.atan2(b, w)",
"+ans = math.degrees(radian)",
"+print(ans)"
] | false | 0.053024 | 0.035654 | 1.487194 |
[
"s611271999",
"s685930994"
] |
u762420987
|
p03108
|
python
|
s216471971
|
s785761568
| 796 | 601 | 33,364 | 24,508 |
Accepted
|
Accepted
| 24.5 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
N, M = list(map(int, input().split()))
uf = UnionFind(N)
ABlist = [list(map(int, input().split())) for _ in range(M)]
ans = [0] * M
for i in reversed(list(range(M))):
A, B = ABlist[i]
if not uf.same(A-1, B-1):
ans[i] = uf.size(A-1)*uf.size(B-1)
uf.union(A-1, B-1)
num = 0
for a in ans:
num += a
print(num)
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
uf = UnionFind(N)
ans = [N*(N-1)//2]
ABlist = [tuple(map(int, input().split())) for _ in range(M)]
for a, b in reversed(ABlist[1::]):
if uf.same(a-1, b-1):
ans.append(ans[-1])
else:
ans.append(ans[-1] - uf.size(a-1)*uf.size(b-1))
uf.union(a-1, b-1)
for a in ans[::-1]:
print(a)
| 58 | 60 | 1,423 | 1,481 |
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
N, M = list(map(int, input().split()))
uf = UnionFind(N)
ABlist = [list(map(int, input().split())) for _ in range(M)]
ans = [0] * M
for i in reversed(list(range(M))):
A, B = ABlist[i]
if not uf.same(A - 1, B - 1):
ans[i] = uf.size(A - 1) * uf.size(B - 1)
uf.union(A - 1, B - 1)
num = 0
for a in ans:
num += a
print(num)
|
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
ABlist = [tuple(map(int, input().split())) for _ in range(M)]
for a, b in reversed(ABlist[1::]):
if uf.same(a - 1, b - 1):
ans.append(ans[-1])
else:
ans.append(ans[-1] - uf.size(a - 1) * uf.size(b - 1))
uf.union(a - 1, b - 1)
for a in ans[::-1]:
print(a)
| false | 3.333333 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"-ABlist = [list(map(int, input().split())) for _ in range(M)]",
"-ans = [0] * M",
"-for i in reversed(list(range(M))):",
"- A, B = ABlist[i]",
"- if not uf.same(A - 1, B - 1):",
"- ans[i] = uf.size(A - 1) * uf.size(B - 1)",
"- uf.union(A - 1, B - 1)",
"-num = 0",
"-for a in ans:",
"- num += a",
"- print(num)",
"+ans = [N * (N - 1) // 2]",
"+ABlist = [tuple(map(int, input().split())) for _ in range(M)]",
"+for a, b in reversed(ABlist[1::]):",
"+ if uf.same(a - 1, b - 1):",
"+ ans.append(ans[-1])",
"+ else:",
"+ ans.append(ans[-1] - uf.size(a - 1) * uf.size(b - 1))",
"+ uf.union(a - 1, b - 1)",
"+for a in ans[::-1]:",
"+ print(a)"
] | false | 0.046965 | 0.116524 | 0.40305 |
[
"s216471971",
"s785761568"
] |
u172569352
|
p03945
|
python
|
s669898818
|
s372932856
| 48 | 44 | 3,188 | 3,188 |
Accepted
|
Accepted
| 8.33 |
S = eval(input())
count = 0
for s in range(1, len(S)):
if S[s-1] != S[s]:
count += 1
print(count)
|
S = eval(input())
count = 0
for i in range(1, len(S)):
if S[i-1] != S[i]:
count += 1
print(count)
| 7 | 7 | 110 | 110 |
S = eval(input())
count = 0
for s in range(1, len(S)):
if S[s - 1] != S[s]:
count += 1
print(count)
|
S = eval(input())
count = 0
for i in range(1, len(S)):
if S[i - 1] != S[i]:
count += 1
print(count)
| false | 0 |
[
"-for s in range(1, len(S)):",
"- if S[s - 1] != S[s]:",
"+for i in range(1, len(S)):",
"+ if S[i - 1] != S[i]:"
] | false | 0.11974 | 0.043436 | 2.756689 |
[
"s669898818",
"s372932856"
] |
u197300773
|
p03504
|
python
|
s216546441
|
s133469315
| 584 | 403 | 28,360 | 28,360 |
Accepted
|
Accepted
| 30.99 |
import sys
import math
from itertools import accumulate as acc
N,C=list(map(int,input().split()))
a=[[0 for i in range(10**5+1)] for i in range(C+1)]
rec=[0 for i in range(10**5+1)]
for i in range(N):
s,t,c=list(map(int,input().split()))
recs,rect=a[c][s],a[c][t]
if recs==0 and rect==0:
rec[s-1]+=1
rec[t]-=1
elif recs==0 and rect==1:
rec[s-1]+=1
rec[t-1]-=1
elif recs==1 and rect==0:
rec[s]+=1
rec[t]-=1
elif recs==1 and rect==1:
rec[s]+=1
rec[t-1]-=1
a[c][s],a[c][t]=1,1
tmp=0
ans=0
for i in range(10**5):
tmp+=rec[i]
ans=max(tmp,ans)
print(ans)
|
import sys
import math
from itertools import accumulate as acc
input=sys.stdin.readline
N,C=list(map(int,input().split()))
a=[[0 for i in range(10**5+1)] for i in range(C+1)]
rec=[0 for i in range(10**5+1)]
for i in range(N):
s,t,c=list(map(int,input().split()))
recs,rect=a[c][s],a[c][t]
if recs==0 and rect==0:
rec[s-1]+=1
rec[t]-=1
elif recs==0 and rect==1:
rec[s-1]+=1
rec[t-1]-=1
elif recs==1 and rect==0:
rec[s]+=1
rec[t]-=1
elif recs==1 and rect==1:
rec[s]+=1
rec[t-1]-=1
a[c][s],a[c][t]=1,1
tmp=0
ans=0
for i in range(10**5):
tmp+=rec[i]
ans=max(tmp,ans)
print(ans)
| 35 | 37 | 677 | 705 |
import sys
import math
from itertools import accumulate as acc
N, C = list(map(int, input().split()))
a = [[0 for i in range(10**5 + 1)] for i in range(C + 1)]
rec = [0 for i in range(10**5 + 1)]
for i in range(N):
s, t, c = list(map(int, input().split()))
recs, rect = a[c][s], a[c][t]
if recs == 0 and rect == 0:
rec[s - 1] += 1
rec[t] -= 1
elif recs == 0 and rect == 1:
rec[s - 1] += 1
rec[t - 1] -= 1
elif recs == 1 and rect == 0:
rec[s] += 1
rec[t] -= 1
elif recs == 1 and rect == 1:
rec[s] += 1
rec[t - 1] -= 1
a[c][s], a[c][t] = 1, 1
tmp = 0
ans = 0
for i in range(10**5):
tmp += rec[i]
ans = max(tmp, ans)
print(ans)
|
import sys
import math
from itertools import accumulate as acc
input = sys.stdin.readline
N, C = list(map(int, input().split()))
a = [[0 for i in range(10**5 + 1)] for i in range(C + 1)]
rec = [0 for i in range(10**5 + 1)]
for i in range(N):
s, t, c = list(map(int, input().split()))
recs, rect = a[c][s], a[c][t]
if recs == 0 and rect == 0:
rec[s - 1] += 1
rec[t] -= 1
elif recs == 0 and rect == 1:
rec[s - 1] += 1
rec[t - 1] -= 1
elif recs == 1 and rect == 0:
rec[s] += 1
rec[t] -= 1
elif recs == 1 and rect == 1:
rec[s] += 1
rec[t - 1] -= 1
a[c][s], a[c][t] = 1, 1
tmp = 0
ans = 0
for i in range(10**5):
tmp += rec[i]
ans = max(tmp, ans)
print(ans)
| false | 5.405405 |
[
"+input = sys.stdin.readline"
] | false | 0.12581 | 0.007655 | 16.435538 |
[
"s216546441",
"s133469315"
] |
u562935282
|
p03164
|
python
|
s786038037
|
s064826133
| 991 | 878 | 311,048 | 307,264 |
Accepted
|
Accepted
| 11.4 |
inf = float('inf')
n, w = list(map(int, input().split()))
wv = tuple(tuple(map(int, input().split())) for _ in range(n))
dp = tuple([inf] * (pow(10, 3) * n + 1) for _ in range(n + 1))
dp[0][0] = 0
for ind, (wi, vi) in enumerate(wv, 1):
for v in range(pow(10, 3) * n + 1):
if vi <= v:
dp[ind][v] = min(dp[ind - 1][v], dp[ind - 1][v - vi] + wi)
else:
dp[ind][v] = dp[ind - 1][v]
for v in range(pow(10, 3) * n, 0, -1):
if dp[n][v] <= w:
print(v)
exit()
|
inf = float('inf')
n, w = list(map(int, input().split()))
e = tuple(list(map(int, input().split())) for _ in range(n))
wt, vt = list(zip(*e))
sv = sum(vt)
dp = tuple([inf] * (sv + 1) for _ in range(n + 1))
dp[0][0] = 0
for i in range(n):
dp[i + 1][:vt[i]] = dp[i][:vt[i]]
for j in range(vt[i], sv + 1):
dp[i + 1][j] = min(dp[i][j], dp[i][j - vt[i]] + wt[i])
res = -1
for j in range(sv, -1, -1):
if dp[n][j] <= w:
res = j
break
print(res)
| 19 | 21 | 530 | 480 |
inf = float("inf")
n, w = list(map(int, input().split()))
wv = tuple(tuple(map(int, input().split())) for _ in range(n))
dp = tuple([inf] * (pow(10, 3) * n + 1) for _ in range(n + 1))
dp[0][0] = 0
for ind, (wi, vi) in enumerate(wv, 1):
for v in range(pow(10, 3) * n + 1):
if vi <= v:
dp[ind][v] = min(dp[ind - 1][v], dp[ind - 1][v - vi] + wi)
else:
dp[ind][v] = dp[ind - 1][v]
for v in range(pow(10, 3) * n, 0, -1):
if dp[n][v] <= w:
print(v)
exit()
|
inf = float("inf")
n, w = list(map(int, input().split()))
e = tuple(list(map(int, input().split())) for _ in range(n))
wt, vt = list(zip(*e))
sv = sum(vt)
dp = tuple([inf] * (sv + 1) for _ in range(n + 1))
dp[0][0] = 0
for i in range(n):
dp[i + 1][: vt[i]] = dp[i][: vt[i]]
for j in range(vt[i], sv + 1):
dp[i + 1][j] = min(dp[i][j], dp[i][j - vt[i]] + wt[i])
res = -1
for j in range(sv, -1, -1):
if dp[n][j] <= w:
res = j
break
print(res)
| false | 9.52381 |
[
"-wv = tuple(tuple(map(int, input().split())) for _ in range(n))",
"-dp = tuple([inf] * (pow(10, 3) * n + 1) for _ in range(n + 1))",
"+e = tuple(list(map(int, input().split())) for _ in range(n))",
"+wt, vt = list(zip(*e))",
"+sv = sum(vt)",
"+dp = tuple([inf] * (sv + 1) for _ in range(n + 1))",
"-for ind, (wi, vi) in enumerate(wv, 1):",
"- for v in range(pow(10, 3) * n + 1):",
"- if vi <= v:",
"- dp[ind][v] = min(dp[ind - 1][v], dp[ind - 1][v - vi] + wi)",
"- else:",
"- dp[ind][v] = dp[ind - 1][v]",
"-for v in range(pow(10, 3) * n, 0, -1):",
"- if dp[n][v] <= w:",
"- print(v)",
"- exit()",
"+for i in range(n):",
"+ dp[i + 1][: vt[i]] = dp[i][: vt[i]]",
"+ for j in range(vt[i], sv + 1):",
"+ dp[i + 1][j] = min(dp[i][j], dp[i][j - vt[i]] + wt[i])",
"+res = -1",
"+for j in range(sv, -1, -1):",
"+ if dp[n][j] <= w:",
"+ res = j",
"+ break",
"+print(res)"
] | false | 0.053636 | 0.040437 | 1.326428 |
[
"s786038037",
"s064826133"
] |
u260980560
|
p02295
|
python
|
s851237997
|
s980207192
| 30 | 20 | 6,464 | 7,780 |
Accepted
|
Accepted
| 33.33 |
for t in range(eval(input())):
x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split()))
dx0 = x1 - x0
dy0 = y1 - y0
dx1 = x3 - x2
dy1 = y3 - y2
s = (y0-y2)*dx1 - (x0-x2)*dy1
sm = dx0*dy1 - dy0*dx1
if s < 0:
s = -s
sm = -sm
t = (y2-y0)*dx0 - (x2-x0)*dy0
tm = dx1*dy0 - dy1*dx0
if t < 0:
t = -t
tm = -tm
if s == 0:
x = x0
y = y0
else:
x = x0 + s*dx0/float(sm)
y = y0 + s*dy0/float(sm)
print("%.09f %.09f" % (x, y))
|
def intersection_ll(S0, S1, T0, T1):
x0, y0 = S0; x1, y1 = S1
X0, X1 = T0; X1, Y1 = T1
p = (x1-x0)*(y0-Y0) - (y1-y0)*(x0-X0) # -cross(S0, S1, T0)
q = (x1-x0)*(Y1-Y0) - (y1-y0)*(X1-X0) # cross(0, S1-S0, T1-T0)
return (X0 + p*(X1-X0)/float(q), Y0 + p*(Y1-Y0)/float(q))# T0 + p/q*(T1-T0)
n = int(eval(input()))
for i in range(n):
x0, y0, x1, y1, X0, Y0, X1, Y1 = list(map(int, input().split()))
print(("%.08f %.08f" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1))))
| 24 | 11 | 556 | 497 |
for t in range(eval(input())):
x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split()))
dx0 = x1 - x0
dy0 = y1 - y0
dx1 = x3 - x2
dy1 = y3 - y2
s = (y0 - y2) * dx1 - (x0 - x2) * dy1
sm = dx0 * dy1 - dy0 * dx1
if s < 0:
s = -s
sm = -sm
t = (y2 - y0) * dx0 - (x2 - x0) * dy0
tm = dx1 * dy0 - dy1 * dx0
if t < 0:
t = -t
tm = -tm
if s == 0:
x = x0
y = y0
else:
x = x0 + s * dx0 / float(sm)
y = y0 + s * dy0 / float(sm)
print("%.09f %.09f" % (x, y))
|
def intersection_ll(S0, S1, T0, T1):
x0, y0 = S0
x1, y1 = S1
X0, X1 = T0
X1, Y1 = T1
p = (x1 - x0) * (y0 - Y0) - (y1 - y0) * (x0 - X0) # -cross(S0, S1, T0)
q = (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0) # cross(0, S1-S0, T1-T0)
return (
X0 + p * (X1 - X0) / float(q),
Y0 + p * (Y1 - Y0) / float(q),
) # T0 + p/q*(T1-T0)
n = int(eval(input()))
for i in range(n):
x0, y0, x1, y1, X0, Y0, X1, Y1 = list(map(int, input().split()))
print(("%.08f %.08f" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1))))
| false | 54.166667 |
[
"-for t in range(eval(input())):",
"- x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split()))",
"- dx0 = x1 - x0",
"- dy0 = y1 - y0",
"- dx1 = x3 - x2",
"- dy1 = y3 - y2",
"- s = (y0 - y2) * dx1 - (x0 - x2) * dy1",
"- sm = dx0 * dy1 - dy0 * dx1",
"- if s < 0:",
"- s = -s",
"- sm = -sm",
"- t = (y2 - y0) * dx0 - (x2 - x0) * dy0",
"- tm = dx1 * dy0 - dy1 * dx0",
"- if t < 0:",
"- t = -t",
"- tm = -tm",
"- if s == 0:",
"- x = x0",
"- y = y0",
"- else:",
"- x = x0 + s * dx0 / float(sm)",
"- y = y0 + s * dy0 / float(sm)",
"- print(\"%.09f %.09f\" % (x, y))",
"+def intersection_ll(S0, S1, T0, T1):",
"+ x0, y0 = S0",
"+ x1, y1 = S1",
"+ X0, X1 = T0",
"+ X1, Y1 = T1",
"+ p = (x1 - x0) * (y0 - Y0) - (y1 - y0) * (x0 - X0) # -cross(S0, S1, T0)",
"+ q = (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0) # cross(0, S1-S0, T1-T0)",
"+ return (",
"+ X0 + p * (X1 - X0) / float(q),",
"+ Y0 + p * (Y1 - Y0) / float(q),",
"+ ) # T0 + p/q*(T1-T0)",
"+",
"+",
"+n = int(eval(input()))",
"+for i in range(n):",
"+ x0, y0, x1, y1, X0, Y0, X1, Y1 = list(map(int, input().split()))",
"+ print((\"%.08f %.08f\" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1))))"
] | false | 0.042935 | 0.053092 | 0.808687 |
[
"s851237997",
"s980207192"
] |
u704001626
|
p02803
|
python
|
s798540138
|
s454015639
| 1,705 | 393 | 3,724 | 3,540 |
Accepted
|
Accepted
| 76.95 |
# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))
maze = [list(eval(input())) for i in range(h)]
for i in maze:
i.insert(0,"#")
i.append("#")
maze.insert(0,["#"]*(w+2))
maze.append(["#"]*(w+2))
import copy
def clear_maze(maze,target=0):
con = False
for r,v1 in enumerate(maze):
for c,v2 in enumerate(v1):
if v2==target:
con = True
if maze[r-1][c]==".":
maze[r-1][c]=target+1
if maze[r+1][c]==".":
maze[r+1][c]=target+1
if maze[r][c-1]==".":
maze[r][c-1]=target+1
if maze[r][c+1]==".":
maze[r][c+1]=target+1
if con:
return clear_maze(maze,target+1)
else:
return target - 1
ret = 0
for i in range(h+1):
for j in range(w+1):
if maze[i][j]==".":
m = copy.deepcopy(maze)
m[i][j]=0
ret = max(ret,clear_maze(m))
print(ret)
|
# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))
inf=float("inf")
s = [[-1]*(w+2)] + [[-1] + [inf if i=="." else -1 for i in eval(input())] + [-1] for _ in range(h)] + [[-1]*(w+2)]
from copy import deepcopy
from collections import deque
ret = 0
for i in range(1,h+1):
for j in range(1,w+1):
temp_s = deepcopy(s)
if temp_s[i][j]!=-1:
temp_s[i][j]=-1
stack_deque = deque([(i,j,0)])
else:
stack_deque = []
max_v=0
while len(stack_deque)>0:
hi,wj,v = stack_deque.popleft()
v+=1
if temp_s[hi][wj-1]!=-1:
temp_s[hi][wj-1]=-1
stack_deque.append([hi,wj-1,v])
max_v=max(max_v,v)
if temp_s[hi][wj+1]!=-1:
temp_s[hi][wj+1]=-1
stack_deque.append([hi,wj+1,v])
max_v=max(max_v,v)
if temp_s[hi-1][wj]!=-1:
temp_s[hi-1][wj]=-1
stack_deque.append([hi-1,wj,v])
max_v=max(max_v,v)
if temp_s[hi+1][wj]!=-1:
temp_s[hi+1][wj]=-1
stack_deque.append([hi+1,wj,v])
max_v=max(max_v,v)
ret=max(ret,max_v)
print(ret)
| 39 | 39 | 1,030 | 1,285 |
# -*- coding: utf-8 -*-
h, w = list(map(int, input().split()))
maze = [list(eval(input())) for i in range(h)]
for i in maze:
i.insert(0, "#")
i.append("#")
maze.insert(0, ["#"] * (w + 2))
maze.append(["#"] * (w + 2))
import copy
def clear_maze(maze, target=0):
con = False
for r, v1 in enumerate(maze):
for c, v2 in enumerate(v1):
if v2 == target:
con = True
if maze[r - 1][c] == ".":
maze[r - 1][c] = target + 1
if maze[r + 1][c] == ".":
maze[r + 1][c] = target + 1
if maze[r][c - 1] == ".":
maze[r][c - 1] = target + 1
if maze[r][c + 1] == ".":
maze[r][c + 1] = target + 1
if con:
return clear_maze(maze, target + 1)
else:
return target - 1
ret = 0
for i in range(h + 1):
for j in range(w + 1):
if maze[i][j] == ".":
m = copy.deepcopy(maze)
m[i][j] = 0
ret = max(ret, clear_maze(m))
print(ret)
|
# -*- coding: utf-8 -*-
h, w = list(map(int, input().split()))
inf = float("inf")
s = (
[[-1] * (w + 2)]
+ [[-1] + [inf if i == "." else -1 for i in eval(input())] + [-1] for _ in range(h)]
+ [[-1] * (w + 2)]
)
from copy import deepcopy
from collections import deque
ret = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
temp_s = deepcopy(s)
if temp_s[i][j] != -1:
temp_s[i][j] = -1
stack_deque = deque([(i, j, 0)])
else:
stack_deque = []
max_v = 0
while len(stack_deque) > 0:
hi, wj, v = stack_deque.popleft()
v += 1
if temp_s[hi][wj - 1] != -1:
temp_s[hi][wj - 1] = -1
stack_deque.append([hi, wj - 1, v])
max_v = max(max_v, v)
if temp_s[hi][wj + 1] != -1:
temp_s[hi][wj + 1] = -1
stack_deque.append([hi, wj + 1, v])
max_v = max(max_v, v)
if temp_s[hi - 1][wj] != -1:
temp_s[hi - 1][wj] = -1
stack_deque.append([hi - 1, wj, v])
max_v = max(max_v, v)
if temp_s[hi + 1][wj] != -1:
temp_s[hi + 1][wj] = -1
stack_deque.append([hi + 1, wj, v])
max_v = max(max_v, v)
ret = max(ret, max_v)
print(ret)
| false | 0 |
[
"-maze = [list(eval(input())) for i in range(h)]",
"-for i in maze:",
"- i.insert(0, \"#\")",
"- i.append(\"#\")",
"-maze.insert(0, [\"#\"] * (w + 2))",
"-maze.append([\"#\"] * (w + 2))",
"-import copy",
"-",
"-",
"-def clear_maze(maze, target=0):",
"- con = False",
"- for r, v1 in enumerate(maze):",
"- for c, v2 in enumerate(v1):",
"- if v2 == target:",
"- con = True",
"- if maze[r - 1][c] == \".\":",
"- maze[r - 1][c] = target + 1",
"- if maze[r + 1][c] == \".\":",
"- maze[r + 1][c] = target + 1",
"- if maze[r][c - 1] == \".\":",
"- maze[r][c - 1] = target + 1",
"- if maze[r][c + 1] == \".\":",
"- maze[r][c + 1] = target + 1",
"- if con:",
"- return clear_maze(maze, target + 1)",
"- else:",
"- return target - 1",
"-",
"+inf = float(\"inf\")",
"+s = (",
"+ [[-1] * (w + 2)]",
"+ + [[-1] + [inf if i == \".\" else -1 for i in eval(input())] + [-1] for _ in range(h)]",
"+ + [[-1] * (w + 2)]",
"+)",
"+from copy import deepcopy",
"+from collections import deque",
"-for i in range(h + 1):",
"- for j in range(w + 1):",
"- if maze[i][j] == \".\":",
"- m = copy.deepcopy(maze)",
"- m[i][j] = 0",
"- ret = max(ret, clear_maze(m))",
"+for i in range(1, h + 1):",
"+ for j in range(1, w + 1):",
"+ temp_s = deepcopy(s)",
"+ if temp_s[i][j] != -1:",
"+ temp_s[i][j] = -1",
"+ stack_deque = deque([(i, j, 0)])",
"+ else:",
"+ stack_deque = []",
"+ max_v = 0",
"+ while len(stack_deque) > 0:",
"+ hi, wj, v = stack_deque.popleft()",
"+ v += 1",
"+ if temp_s[hi][wj - 1] != -1:",
"+ temp_s[hi][wj - 1] = -1",
"+ stack_deque.append([hi, wj - 1, v])",
"+ max_v = max(max_v, v)",
"+ if temp_s[hi][wj + 1] != -1:",
"+ temp_s[hi][wj + 1] = -1",
"+ stack_deque.append([hi, wj + 1, v])",
"+ max_v = max(max_v, v)",
"+ if temp_s[hi - 1][wj] != -1:",
"+ temp_s[hi - 1][wj] = -1",
"+ stack_deque.append([hi - 1, wj, v])",
"+ max_v = max(max_v, v)",
"+ if temp_s[hi + 1][wj] != -1:",
"+ temp_s[hi + 1][wj] = -1",
"+ stack_deque.append([hi + 1, wj, v])",
"+ max_v = max(max_v, v)",
"+ ret = max(ret, max_v)"
] | false | 0.071623 | 0.044351 | 1.614907 |
[
"s798540138",
"s454015639"
] |
u285443936
|
p03805
|
python
|
s549794516
|
s656768106
| 66 | 25 | 3,064 | 3,188 |
Accepted
|
Accepted
| 62.12 |
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(M)]
visited = {i:False for i in range(N)}
visited[0] = True
ans = 0
def DFS(x):
# print(visited)
global ans
nextx = []
if False not in list(visited.values()):
ans += 1
return
for i in range(M):
if x in ab[i]:
xcol = ab[i].index(x)
if visited[ab[i][1-xcol]-1]:
continue
else:
nextx.append(ab[i][1-xcol])
# print(nextx)
for i in nextx:
visited[i-1] = True
DFS(i)
visited[i-1] = False
return
DFS(1)
print(ans)
|
N, M = list(map(int,input().split()))
C = [[] for i in range(N)]
for i in range(M):
a,b = list(map(int, input().split()))
a -= 1
b -= 1
C[a].append(b)
C[b].append(a)
visited = [0]*N
ans = 0
def dfs(x):
global ans
visited[x] = 1
if all(visited):
ans += 1
return
for i in C[x]:
if visited[i] == 0:
dfs(i)
visited[i] = 0
return
dfs(0)
print(ans)
| 29 | 23 | 588 | 398 |
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(M)]
visited = {i: False for i in range(N)}
visited[0] = True
ans = 0
def DFS(x):
# print(visited)
global ans
nextx = []
if False not in list(visited.values()):
ans += 1
return
for i in range(M):
if x in ab[i]:
xcol = ab[i].index(x)
if visited[ab[i][1 - xcol] - 1]:
continue
else:
nextx.append(ab[i][1 - xcol])
# print(nextx)
for i in nextx:
visited[i - 1] = True
DFS(i)
visited[i - 1] = False
return
DFS(1)
print(ans)
|
N, M = list(map(int, input().split()))
C = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
C[a].append(b)
C[b].append(a)
visited = [0] * N
ans = 0
def dfs(x):
global ans
visited[x] = 1
if all(visited):
ans += 1
return
for i in C[x]:
if visited[i] == 0:
dfs(i)
visited[i] = 0
return
dfs(0)
print(ans)
| false | 20.689655 |
[
"-ab = [list(map(int, input().split())) for i in range(M)]",
"-visited = {i: False for i in range(N)}",
"-visited[0] = True",
"+C = [[] for i in range(N)]",
"+for i in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ a -= 1",
"+ b -= 1",
"+ C[a].append(b)",
"+ C[b].append(a)",
"+visited = [0] * N",
"-def DFS(x):",
"- # print(visited)",
"+def dfs(x):",
"- nextx = []",
"- if False not in list(visited.values()):",
"+ visited[x] = 1",
"+ if all(visited):",
"- for i in range(M):",
"- if x in ab[i]:",
"- xcol = ab[i].index(x)",
"- if visited[ab[i][1 - xcol] - 1]:",
"- continue",
"- else:",
"- nextx.append(ab[i][1 - xcol])",
"- # print(nextx)",
"- for i in nextx:",
"- visited[i - 1] = True",
"- DFS(i)",
"- visited[i - 1] = False",
"+ for i in C[x]:",
"+ if visited[i] == 0:",
"+ dfs(i)",
"+ visited[i] = 0",
"-DFS(1)",
"+dfs(0)"
] | false | 0.047165 | 0.037753 | 1.249306 |
[
"s549794516",
"s656768106"
] |
u357751375
|
p02786
|
python
|
s300360921
|
s868162857
| 28 | 25 | 9,104 | 9,136 |
Accepted
|
Accepted
| 10.71 |
h = int(eval(input()))
ans = 1
i = 1
while h > 1:
h = h // 2
ans += 2 ** i
i += 1
print(ans)
|
h = int(eval(input()))
ans = 0
i = 0
while h > 0:
h = h // 2
ans += 2 ** i
i += 1
print(ans)
| 8 | 8 | 105 | 105 |
h = int(eval(input()))
ans = 1
i = 1
while h > 1:
h = h // 2
ans += 2**i
i += 1
print(ans)
|
h = int(eval(input()))
ans = 0
i = 0
while h > 0:
h = h // 2
ans += 2**i
i += 1
print(ans)
| false | 0 |
[
"-ans = 1",
"-i = 1",
"-while h > 1:",
"+ans = 0",
"+i = 0",
"+while h > 0:"
] | false | 0.104513 | 0.115578 | 0.904264 |
[
"s300360921",
"s868162857"
] |
u021019433
|
p02837
|
python
|
s682399720
|
s453305802
| 60 | 55 | 3,064 | 3,188 |
Accepted
|
Accepted
| 8.33 |
from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
ans = next(i for i in count(n, - 1) for x in combinations(r, i)
if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))
print(ans)
|
from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
ans = next(i for i in count(n, - 1) for x in map(set, combinations(r, i))
if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x))
print(ans)
| 12 | 12 | 372 | 374 |
from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
ans = next(
i
for i in count(n, -1)
for x in combinations(r, i)
if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x)
)
print(ans)
|
from itertools import combinations, count
n = int(eval(input()))
r = list(range(n))
a = [(set(), set()) for _ in r]
for i in r:
for _ in range(int(eval(input()))):
x, y = list(map(int, input().split()))
a[i][y].add(x - 1)
ans = next(
i
for i in count(n, -1)
for x in map(set, combinations(r, i))
if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)
)
print(ans)
| false | 0 |
[
"- for x in combinations(r, i)",
"- if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x)",
"+ for x in map(set, combinations(r, i))",
"+ if all(a[j][0].isdisjoint(x) and a[j][1] < x for j in x)"
] | false | 0.03482 | 0.058231 | 0.597969 |
[
"s682399720",
"s453305802"
] |
u168578024
|
p03449
|
python
|
s997469384
|
s399024682
| 189 | 164 | 39,828 | 38,384 |
Accepted
|
Accepted
| 13.23 |
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
cur = 0
for j in range(N):
if j < i:
cur += A[j]
elif j == i:
cur += A[j] + B[j]
else:
cur += B[j]
ans = max(ans , cur)
print(ans)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
def rui(a):
ret = [0] * (len(a) + 1)
for i in range(len(a)):
ret[i + 1] = ret[i] + a[i]
return ret
ra = rui(A)
rb = rui(B)
ans = 0
for i in range(N):
ans = max(ans, ra[i + 1] + rb[N] - rb[i])
print(ans)
| 16 | 21 | 332 | 424 |
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
cur = 0
for j in range(N):
if j < i:
cur += A[j]
elif j == i:
cur += A[j] + B[j]
else:
cur += B[j]
ans = max(ans, cur)
print(ans)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
def rui(a):
ret = [0] * (len(a) + 1)
for i in range(len(a)):
ret[i + 1] = ret[i] + a[i]
return ret
ra = rui(A)
rb = rui(B)
ans = 0
for i in range(N):
ans = max(ans, ra[i + 1] + rb[N] - rb[i])
print(ans)
| false | 23.809524 |
[
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-B = list(map(int, input().split()))",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+N = int(readline())",
"+A = list(map(int, readline().split()))",
"+B = list(map(int, readline().split()))",
"+",
"+",
"+def rui(a):",
"+ ret = [0] * (len(a) + 1)",
"+ for i in range(len(a)):",
"+ ret[i + 1] = ret[i] + a[i]",
"+ return ret",
"+",
"+",
"+ra = rui(A)",
"+rb = rui(B)",
"- cur = 0",
"- for j in range(N):",
"- if j < i:",
"- cur += A[j]",
"- elif j == i:",
"- cur += A[j] + B[j]",
"- else:",
"- cur += B[j]",
"- ans = max(ans, cur)",
"+ ans = max(ans, ra[i + 1] + rb[N] - rb[i])"
] | false | 0.046877 | 0.047039 | 0.996541 |
[
"s997469384",
"s399024682"
] |
u062484507
|
p02683
|
python
|
s105947641
|
s567980734
| 78 | 61 | 9,276 | 9,540 |
Accepted
|
Accepted
| 21.79 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, m, x = list(map(int, readline().split()))
c = [list(map(int, readline().split())) for _ in range(n)]
ans = float('inf')
# bit全探索
for i in range(2 ** n):
bag = [0]*(m+1)
for j in range(n):
if ((i >> j) & 1):
bag = [x + y for (x, y) in zip(bag, c[j])]
if min(bag[1::]) >= x:
ans = min(ans, bag[0])
print(('-1'if ans == float('inf') else int(ans)))
|
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, m, x = list(map(int, readline().split()))
c = [list(map(int, readline().split())) for _ in range(n)]
ans = 10 ** 9 + 7
for l in list(itertools.product([0, 1], repeat=n)):
cart = [0] * (m + 1)
for i in [i for i, a in enumerate(l) if a == 1]:
array = c[i]
cart = list(map(lambda x,y: x+y, cart, array))
if min(cart[1::]) >= x:
ans = min(ans, cart[0])
print((ans if ans != 10 ** 9 + 7 else '-1'))
| 19 | 19 | 538 | 586 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, m, x = list(map(int, readline().split()))
c = [list(map(int, readline().split())) for _ in range(n)]
ans = float("inf")
# bit全探索
for i in range(2**n):
bag = [0] * (m + 1)
for j in range(n):
if (i >> j) & 1:
bag = [x + y for (x, y) in zip(bag, c[j])]
if min(bag[1::]) >= x:
ans = min(ans, bag[0])
print(("-1" if ans == float("inf") else int(ans)))
|
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, m, x = list(map(int, readline().split()))
c = [list(map(int, readline().split())) for _ in range(n)]
ans = 10**9 + 7
for l in list(itertools.product([0, 1], repeat=n)):
cart = [0] * (m + 1)
for i in [i for i, a in enumerate(l) if a == 1]:
array = c[i]
cart = list(map(lambda x, y: x + y, cart, array))
if min(cart[1::]) >= x:
ans = min(ans, cart[0])
print((ans if ans != 10**9 + 7 else "-1"))
| false | 0 |
[
"+import itertools",
"-ans = float(\"inf\")",
"-# bit全探索",
"-for i in range(2**n):",
"- bag = [0] * (m + 1)",
"- for j in range(n):",
"- if (i >> j) & 1:",
"- bag = [x + y for (x, y) in zip(bag, c[j])]",
"- if min(bag[1::]) >= x:",
"- ans = min(ans, bag[0])",
"-print((\"-1\" if ans == float(\"inf\") else int(ans)))",
"+ans = 10**9 + 7",
"+for l in list(itertools.product([0, 1], repeat=n)):",
"+ cart = [0] * (m + 1)",
"+ for i in [i for i, a in enumerate(l) if a == 1]:",
"+ array = c[i]",
"+ cart = list(map(lambda x, y: x + y, cart, array))",
"+ if min(cart[1::]) >= x:",
"+ ans = min(ans, cart[0])",
"+print((ans if ans != 10**9 + 7 else \"-1\"))"
] | false | 0.068565 | 0.049828 | 1.376034 |
[
"s105947641",
"s567980734"
] |
u945181840
|
p02960
|
python
|
s358451705
|
s620296378
| 1,111 | 825 | 63,160 | 3,188 |
Accepted
|
Accepted
| 25.74 |
def main():
S = [int(i) if i != '?' else -1 for i in eval(input())]
s = len(S)
mod = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(s)]
table = [[0] * 10 for _ in range(13)]
for i in range(13):
for j in range(10):
table[i][j] = (i * 10 + j) % 13
table2 = [[] for _ in range(13)]
for i in range(13):
for j in range(10):
table2[table[i][j]].append(i)
t = set(range(13))
table2 = [t - set(i) for i in table2]
if S[0] == -1:
for i in range(10):
dp[0][i] += 1
else:
dp[0][S[0] % 13] += 1
for i in range(1, s):
if S[i] == -1:
temp = sum(dp[i - 1])
for j in range(13):
dp[i][j] = temp
for k in table2[j]:
dp[i][j] -= dp[i - 1][k]
dp[i][j] %= mod
else:
for j in range(13):
dp[i][table[j][S[i]]] = dp[i - 1][j]
print((dp[-1][5] % mod))
if __name__ == '__main__':
main()
|
def main():
S = str(eval(input()))
ans = [0] * 13
ans[0] = 1
MOD = 10**9 + 7
for i in S:
dp = [0] * 13
for j in range(13):
dp[(j * 10) % 13] = ans[j] % MOD
dp += dp
if i == '?':
for j in range(13):
ans[j] = sum(dp[j+4:j+14])
else:
for j in range(13):
ans[j] = dp[j + 13 - int(i)]
print((ans[5] % MOD))
if __name__ == '__main__':
main()
| 41 | 23 | 1,058 | 458 |
def main():
S = [int(i) if i != "?" else -1 for i in eval(input())]
s = len(S)
mod = 10**9 + 7
dp = [[0] * 13 for _ in range(s)]
table = [[0] * 10 for _ in range(13)]
for i in range(13):
for j in range(10):
table[i][j] = (i * 10 + j) % 13
table2 = [[] for _ in range(13)]
for i in range(13):
for j in range(10):
table2[table[i][j]].append(i)
t = set(range(13))
table2 = [t - set(i) for i in table2]
if S[0] == -1:
for i in range(10):
dp[0][i] += 1
else:
dp[0][S[0] % 13] += 1
for i in range(1, s):
if S[i] == -1:
temp = sum(dp[i - 1])
for j in range(13):
dp[i][j] = temp
for k in table2[j]:
dp[i][j] -= dp[i - 1][k]
dp[i][j] %= mod
else:
for j in range(13):
dp[i][table[j][S[i]]] = dp[i - 1][j]
print((dp[-1][5] % mod))
if __name__ == "__main__":
main()
|
def main():
S = str(eval(input()))
ans = [0] * 13
ans[0] = 1
MOD = 10**9 + 7
for i in S:
dp = [0] * 13
for j in range(13):
dp[(j * 10) % 13] = ans[j] % MOD
dp += dp
if i == "?":
for j in range(13):
ans[j] = sum(dp[j + 4 : j + 14])
else:
for j in range(13):
ans[j] = dp[j + 13 - int(i)]
print((ans[5] % MOD))
if __name__ == "__main__":
main()
| false | 43.902439 |
[
"- S = [int(i) if i != \"?\" else -1 for i in eval(input())]",
"- s = len(S)",
"- mod = 10**9 + 7",
"- dp = [[0] * 13 for _ in range(s)]",
"- table = [[0] * 10 for _ in range(13)]",
"- for i in range(13):",
"- for j in range(10):",
"- table[i][j] = (i * 10 + j) % 13",
"- table2 = [[] for _ in range(13)]",
"- for i in range(13):",
"- for j in range(10):",
"- table2[table[i][j]].append(i)",
"- t = set(range(13))",
"- table2 = [t - set(i) for i in table2]",
"- if S[0] == -1:",
"- for i in range(10):",
"- dp[0][i] += 1",
"- else:",
"- dp[0][S[0] % 13] += 1",
"- for i in range(1, s):",
"- if S[i] == -1:",
"- temp = sum(dp[i - 1])",
"+ S = str(eval(input()))",
"+ ans = [0] * 13",
"+ ans[0] = 1",
"+ MOD = 10**9 + 7",
"+ for i in S:",
"+ dp = [0] * 13",
"+ for j in range(13):",
"+ dp[(j * 10) % 13] = ans[j] % MOD",
"+ dp += dp",
"+ if i == \"?\":",
"- dp[i][j] = temp",
"- for k in table2[j]:",
"- dp[i][j] -= dp[i - 1][k]",
"- dp[i][j] %= mod",
"+ ans[j] = sum(dp[j + 4 : j + 14])",
"- dp[i][table[j][S[i]]] = dp[i - 1][j]",
"- print((dp[-1][5] % mod))",
"+ ans[j] = dp[j + 13 - int(i)]",
"+ print((ans[5] % MOD))"
] | false | 0.040732 | 0.039159 | 1.040161 |
[
"s358451705",
"s620296378"
] |
u806976856
|
p02687
|
python
|
s873673229
|
s542018897
| 23 | 21 | 9,092 | 9,032 |
Accepted
|
Accepted
| 8.7 |
S=eval(input())
if S=="ABC":
print("ARC")
if S=="ARC":
print("ABC")
|
A=eval(input())
if A=="ABC":
print("ARC")
if A=="ARC":
print("ABC")
| 5 | 5 | 73 | 73 |
S = eval(input())
if S == "ABC":
print("ARC")
if S == "ARC":
print("ABC")
|
A = eval(input())
if A == "ABC":
print("ARC")
if A == "ARC":
print("ABC")
| false | 0 |
[
"-S = eval(input())",
"-if S == \"ABC\":",
"+A = eval(input())",
"+if A == \"ABC\":",
"-if S == \"ARC\":",
"+if A == \"ARC\":"
] | false | 0.043818 | 0.044426 | 0.986318 |
[
"s873673229",
"s542018897"
] |
u606045429
|
p03945
|
python
|
s859536667
|
s404078054
| 42 | 18 | 3,188 | 3,188 |
Accepted
|
Accepted
| 57.14 |
S = eval(input())
count = 0
for i in range(len(S) - 1):
if S[i] != S[i + 1]:
count += 1
print(count)
|
S = eval(input())
print((S.count("WB") + S.count("BW")))
| 8 | 2 | 115 | 49 |
S = eval(input())
count = 0
for i in range(len(S) - 1):
if S[i] != S[i + 1]:
count += 1
print(count)
|
S = eval(input())
print((S.count("WB") + S.count("BW")))
| false | 75 |
[
"-count = 0",
"-for i in range(len(S) - 1):",
"- if S[i] != S[i + 1]:",
"- count += 1",
"-print(count)",
"+print((S.count(\"WB\") + S.count(\"BW\")))"
] | false | 0.09887 | 0.079519 | 1.243351 |
[
"s859536667",
"s404078054"
] |
u378691508
|
p02787
|
python
|
s021302130
|
s599903389
| 471 | 342 | 217,288 | 217,768 |
Accepted
|
Accepted
| 27.39 |
H, N = list(map(int, input().split()))
A=[]
B=[]
for i in range(N):
a,b = list(map(int, input().split()))
A.append(a)
B.append(b)
#dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp=[[float("inf")]*(H+1) for _ in range(N+1)]
for i in range(N):
for h in range(H+1):
if A[i]>=h:
dp[i+1][h] = min(dp[i][h], B[i])
else:
dp[i+1][h] = min(dp[i][h], dp[i+1][h-A[i]]+B[i], dp[i][h-A[i]]+B[i])
print((dp[-1][-1]))
|
H, N = list(map(int, input().split()))
A=[]
B=[]
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
dp=[[float("inf")]*(H+1) for _ in range(N+1)]
dp[0][0]=0
for i in range(N):
a, b = A[i], B[i]
for j in range(H+1):
if a>=j:
dp[i+1][j] = min(dp[i][j], b)
else:
dp[i+1][j] = min(dp[i][j], dp[i+1][j-a]+b)
print((dp[-1][-1]))
| 17 | 19 | 418 | 375 |
H, N = list(map(int, input().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト
dp = [[float("inf")] * (H + 1) for _ in range(N + 1)]
for i in range(N):
for h in range(H + 1):
if A[i] >= h:
dp[i + 1][h] = min(dp[i][h], B[i])
else:
dp[i + 1][h] = min(
dp[i][h], dp[i + 1][h - A[i]] + B[i], dp[i][h - A[i]] + B[i]
)
print((dp[-1][-1]))
|
H, N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
dp = [[float("inf")] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
a, b = A[i], B[i]
for j in range(H + 1):
if a >= j:
dp[i + 1][j] = min(dp[i][j], b)
else:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b)
print((dp[-1][-1]))
| false | 10.526316 |
[
"-for i in range(N):",
"+for _ in range(N):",
"-# dp[i+1][h] := i番目の魔法まで見て、ライフをh以上削った時の最小魔力コスト",
"+dp[0][0] = 0",
"- for h in range(H + 1):",
"- if A[i] >= h:",
"- dp[i + 1][h] = min(dp[i][h], B[i])",
"+ a, b = A[i], B[i]",
"+ for j in range(H + 1):",
"+ if a >= j:",
"+ dp[i + 1][j] = min(dp[i][j], b)",
"- dp[i + 1][h] = min(",
"- dp[i][h], dp[i + 1][h - A[i]] + B[i], dp[i][h - A[i]] + B[i]",
"- )",
"+ dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a] + b)"
] | false | 0.113874 | 0.187852 | 0.606191 |
[
"s021302130",
"s599903389"
] |
u798260206
|
p02844
|
python
|
s689120015
|
s802897405
| 1,683 | 29 | 4,456 | 9,276 |
Accepted
|
Accepted
| 98.28 |
n=int(eval(input()))
s=list(eval(input()))
cnt=0
for i in range (10):
i=str(i)
for j in range (10):
j=str(j)
for k in range (10):
k=str(k)
if s.count(i)!=0:
a=s.index(i)
x=s[(a+1):]
if x.count(j)!=0:
b=x.index(j)
y=x[(b+1):]
if y.count(k)!=0:
cnt+=1
print(cnt)
|
n = int(eval(input()))
s = eval(input())
cnt = 0
for N in range(1000):
tgt = str(N).zfill(3)
if tgt[0] in s:
i = s.index(tgt[0])
if tgt[1] in s[i+1:]:
j = s[i+1:].index(tgt[1]) + i
if tgt[2] in s[j+2:]:
cnt += 1
print(cnt)
| 19 | 13 | 363 | 288 |
n = int(eval(input()))
s = list(eval(input()))
cnt = 0
for i in range(10):
i = str(i)
for j in range(10):
j = str(j)
for k in range(10):
k = str(k)
if s.count(i) != 0:
a = s.index(i)
x = s[(a + 1) :]
if x.count(j) != 0:
b = x.index(j)
y = x[(b + 1) :]
if y.count(k) != 0:
cnt += 1
print(cnt)
|
n = int(eval(input()))
s = eval(input())
cnt = 0
for N in range(1000):
tgt = str(N).zfill(3)
if tgt[0] in s:
i = s.index(tgt[0])
if tgt[1] in s[i + 1 :]:
j = s[i + 1 :].index(tgt[1]) + i
if tgt[2] in s[j + 2 :]:
cnt += 1
print(cnt)
| false | 31.578947 |
[
"-s = list(eval(input()))",
"+s = eval(input())",
"-for i in range(10):",
"- i = str(i)",
"- for j in range(10):",
"- j = str(j)",
"- for k in range(10):",
"- k = str(k)",
"- if s.count(i) != 0:",
"- a = s.index(i)",
"- x = s[(a + 1) :]",
"- if x.count(j) != 0:",
"- b = x.index(j)",
"- y = x[(b + 1) :]",
"- if y.count(k) != 0:",
"- cnt += 1",
"+for N in range(1000):",
"+ tgt = str(N).zfill(3)",
"+ if tgt[0] in s:",
"+ i = s.index(tgt[0])",
"+ if tgt[1] in s[i + 1 :]:",
"+ j = s[i + 1 :].index(tgt[1]) + i",
"+ if tgt[2] in s[j + 2 :]:",
"+ cnt += 1"
] | false | 0.041951 | 0.040212 | 1.043245 |
[
"s689120015",
"s802897405"
] |
u855775311
|
p02363
|
python
|
s354976244
|
s301955362
| 570 | 520 | 8,676 | 8,760 |
Accepted
|
Accepted
| 8.77 |
def main():
nvertices, nedges = list(map(int, input().split()))
INF = float('inf')
D1 = [[INF for i in range(nvertices)] for i in range(nvertices)]
for i in range(nedges):
s, t, d = list(map(int, input().split()))
D1[s][t] = d
for i in range(nvertices):
D1[i][i] = 0
for k in range(nvertices):
D2 = [[INF for i in range(nvertices)] for i in range(nvertices)]
for i in range(nvertices):
for j in range(nvertices):
D2[i][j] = min(D1[i][j], D1[i][k] + D1[k][j])
D1 = D2
for i in range(nvertices):
if D1[i][i] < 0:
print("NEGATIVE CYCLE")
return
for lst in D1:
print((" ".join([str(e) if e < INF else "INF" for e in lst])))
main()
|
import math
def main():
nvertices, nedges = list(map(int, input().split()))
INF = float('inf')
D1 = [[0 if i == j else INF for i in range(nvertices)]
for j in range(nvertices)]
for i in range(nedges):
u, v, w = list(map(int, input().split()))
D1[u][v] = w
for k in range(nvertices):
D2 = [[0] * nvertices for i in range(nvertices)]
for i in range(nvertices):
for j in range(nvertices):
D2[i][j] = min(D1[i][j], D1[i][k] + D1[k][j])
D1 = D2
for v in range(nvertices):
if D1[v][v] < 0:
print("NEGATIVE CYCLE")
return
for D in D1:
print((" ".join(["INF" if math.isinf(e) else str(e) for e in D])))
main()
| 28 | 29 | 798 | 773 |
def main():
nvertices, nedges = list(map(int, input().split()))
INF = float("inf")
D1 = [[INF for i in range(nvertices)] for i in range(nvertices)]
for i in range(nedges):
s, t, d = list(map(int, input().split()))
D1[s][t] = d
for i in range(nvertices):
D1[i][i] = 0
for k in range(nvertices):
D2 = [[INF for i in range(nvertices)] for i in range(nvertices)]
for i in range(nvertices):
for j in range(nvertices):
D2[i][j] = min(D1[i][j], D1[i][k] + D1[k][j])
D1 = D2
for i in range(nvertices):
if D1[i][i] < 0:
print("NEGATIVE CYCLE")
return
for lst in D1:
print((" ".join([str(e) if e < INF else "INF" for e in lst])))
main()
|
import math
def main():
nvertices, nedges = list(map(int, input().split()))
INF = float("inf")
D1 = [[0 if i == j else INF for i in range(nvertices)] for j in range(nvertices)]
for i in range(nedges):
u, v, w = list(map(int, input().split()))
D1[u][v] = w
for k in range(nvertices):
D2 = [[0] * nvertices for i in range(nvertices)]
for i in range(nvertices):
for j in range(nvertices):
D2[i][j] = min(D1[i][j], D1[i][k] + D1[k][j])
D1 = D2
for v in range(nvertices):
if D1[v][v] < 0:
print("NEGATIVE CYCLE")
return
for D in D1:
print((" ".join(["INF" if math.isinf(e) else str(e) for e in D])))
main()
| false | 3.448276 |
[
"+import math",
"+",
"+",
"- D1 = [[INF for i in range(nvertices)] for i in range(nvertices)]",
"+ D1 = [[0 if i == j else INF for i in range(nvertices)] for j in range(nvertices)]",
"- s, t, d = list(map(int, input().split()))",
"- D1[s][t] = d",
"- for i in range(nvertices):",
"- D1[i][i] = 0",
"+ u, v, w = list(map(int, input().split()))",
"+ D1[u][v] = w",
"- D2 = [[INF for i in range(nvertices)] for i in range(nvertices)]",
"+ D2 = [[0] * nvertices for i in range(nvertices)]",
"- for i in range(nvertices):",
"- if D1[i][i] < 0:",
"+ for v in range(nvertices):",
"+ if D1[v][v] < 0:",
"- for lst in D1:",
"- print((\" \".join([str(e) if e < INF else \"INF\" for e in lst])))",
"+ for D in D1:",
"+ print((\" \".join([\"INF\" if math.isinf(e) else str(e) for e in D])))"
] | false | 0.045219 | 0.044598 | 1.013918 |
[
"s354976244",
"s301955362"
] |
u463655976
|
p03828
|
python
|
s030278542
|
s269549370
| 247 | 220 | 50,908 | 49,756 |
Accepted
|
Accepted
| 10.93 |
from functools import reduce
N = int(eval(input()))
g = 10 ** 9 + 7
def add(a, b):
return (a + b) % g
def mul(a, b):
return (a * b) % g
def adda(a, p1, p2):
for x in range(len(a)):
a[x] = add(p1[x], p2[x])
d = []
DP = [[0 for _ in range(N+1)] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]
for i in range(2, N+1):
for j in (x for x in d if x * x <= N):
if i % j == 0:
adda(DP[i], DP[j], DP[i//j])
break
else:
d.append(i)
DP[i][i] = 1
adda(ans, ans, DP[i])
print((reduce(mul, [x + 1 for x in ans[1:N+1]])))
|
from functools import reduce
N = int(eval(input()))
g = 10 ** 9 + 7
def mul(a, b):
return (a * b) % g
def adda(a, p1, p2):
for x in range(len(a)):
a[x] = p1[x] + p2[x]
d = []
DP = [[0 for _ in range(N+1)] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]
for i in range(2, N+1):
for j in (x for x in d if x * x <= N):
if i % j == 0:
adda(DP[i], DP[j], DP[i//j])
break
else:
d.append(i)
DP[i][i] = 1
adda(ans, ans, DP[i])
print((reduce(mul, [x + 1 for x in ans[1:N+1]])))
| 27 | 26 | 578 | 538 |
from functools import reduce
N = int(eval(input()))
g = 10**9 + 7
def add(a, b):
return (a + b) % g
def mul(a, b):
return (a * b) % g
def adda(a, p1, p2):
for x in range(len(a)):
a[x] = add(p1[x], p2[x])
d = []
DP = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
ans = [0 for _ in range(N + 1)]
for i in range(2, N + 1):
for j in (x for x in d if x * x <= N):
if i % j == 0:
adda(DP[i], DP[j], DP[i // j])
break
else:
d.append(i)
DP[i][i] = 1
adda(ans, ans, DP[i])
print((reduce(mul, [x + 1 for x in ans[1 : N + 1]])))
|
from functools import reduce
N = int(eval(input()))
g = 10**9 + 7
def mul(a, b):
return (a * b) % g
def adda(a, p1, p2):
for x in range(len(a)):
a[x] = p1[x] + p2[x]
d = []
DP = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
ans = [0 for _ in range(N + 1)]
for i in range(2, N + 1):
for j in (x for x in d if x * x <= N):
if i % j == 0:
adda(DP[i], DP[j], DP[i // j])
break
else:
d.append(i)
DP[i][i] = 1
adda(ans, ans, DP[i])
print((reduce(mul, [x + 1 for x in ans[1 : N + 1]])))
| false | 3.703704 |
[
"-",
"-",
"-def add(a, b):",
"- return (a + b) % g",
"- a[x] = add(p1[x], p2[x])",
"+ a[x] = p1[x] + p2[x]"
] | false | 0.294382 | 0.074633 | 3.944403 |
[
"s030278542",
"s269549370"
] |
u969850098
|
p02947
|
python
|
s617611267
|
s260310897
| 633 | 225 | 19,844 | 19,728 |
Accepted
|
Accepted
| 64.45 |
import sys
from collections import Counter
from math import factorial
def combinations_count(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
def main():
input = sys.stdin.readline
N = int(eval(input()))
texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
c = Counter(texts)
cnt = 0
for t in list(c.values()):
if t > 1:
cnt += combinations_count(t, 2)
print(cnt)
if __name__ == '__main__':
main()
|
import sys
from collections import Counter
def main():
input = sys.stdin.readline
N = int(eval(input()))
texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
c = Counter(texts)
cnt = 0
for t in list(c.values()):
if t > 1:
cnt += (t * (t-1)) // 2
print(cnt)
if __name__ == '__main__':
main()
| 20 | 16 | 469 | 339 |
import sys
from collections import Counter
from math import factorial
def combinations_count(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
def main():
input = sys.stdin.readline
N = int(eval(input()))
texts = ["".join(sorted(list(input().rstrip()))) for _ in range(N)]
c = Counter(texts)
cnt = 0
for t in list(c.values()):
if t > 1:
cnt += combinations_count(t, 2)
print(cnt)
if __name__ == "__main__":
main()
|
import sys
from collections import Counter
def main():
input = sys.stdin.readline
N = int(eval(input()))
texts = ["".join(sorted(list(input().rstrip()))) for _ in range(N)]
c = Counter(texts)
cnt = 0
for t in list(c.values()):
if t > 1:
cnt += (t * (t - 1)) // 2
print(cnt)
if __name__ == "__main__":
main()
| false | 20 |
[
"-from math import factorial",
"-",
"-",
"-def combinations_count(n, r):",
"- return factorial(n) // (factorial(n - r) * factorial(r))",
"- cnt += combinations_count(t, 2)",
"+ cnt += (t * (t - 1)) // 2"
] | false | 0.044868 | 0.038191 | 1.174848 |
[
"s617611267",
"s260310897"
] |
u667978773
|
p02994
|
python
|
s430341236
|
s669858462
| 198 | 17 | 38,384 | 2,940 |
Accepted
|
Accepted
| 91.41 |
n,l = list(map(int,input().split()))
taste = [l+i-1 for i in range(1,n+1)]
ideal = sum(taste)
bited = [ideal-taste[i] for i in range(n)]
dif = [abs(ideal-bited[i]) for i in range(n)]
print((bited[dif.index(min(dif))]))
|
n,l=(list(map(int,input().split())))
if l>0:
print((sum(range(l+1,l+n))))
elif l+n-1<0:
print((sum(range(l,l+n-1))))
else:
print((sum(range(l,l+n))))
| 6 | 7 | 217 | 150 |
n, l = list(map(int, input().split()))
taste = [l + i - 1 for i in range(1, n + 1)]
ideal = sum(taste)
bited = [ideal - taste[i] for i in range(n)]
dif = [abs(ideal - bited[i]) for i in range(n)]
print((bited[dif.index(min(dif))]))
|
n, l = list(map(int, input().split()))
if l > 0:
print((sum(range(l + 1, l + n))))
elif l + n - 1 < 0:
print((sum(range(l, l + n - 1))))
else:
print((sum(range(l, l + n))))
| false | 14.285714 |
[
"-taste = [l + i - 1 for i in range(1, n + 1)]",
"-ideal = sum(taste)",
"-bited = [ideal - taste[i] for i in range(n)]",
"-dif = [abs(ideal - bited[i]) for i in range(n)]",
"-print((bited[dif.index(min(dif))]))",
"+if l > 0:",
"+ print((sum(range(l + 1, l + n))))",
"+elif l + n - 1 < 0:",
"+ print((sum(range(l, l + n - 1))))",
"+else:",
"+ print((sum(range(l, l + n))))"
] | false | 0.073432 | 0.035477 | 2.069852 |
[
"s430341236",
"s669858462"
] |
u232852711
|
p03695
|
python
|
s441465309
|
s281938884
| 22 | 19 | 3,444 | 3,188 |
Accepted
|
Accepted
| 13.64 |
import copy
n = int(eval(input()))
a = list(map(int, input().split()))
color = [0]*9
for i in range(n):
rate = min(a[i]//400, 8)
color[rate] += 1
ans_min = 0
color_min = copy.deepcopy(color)
for c in color_min[:-1]:
if c > 0:
ans_min += 1
ans_min = max(1, ans_min)
ans_max = 0
color_max = copy.deepcopy(color)
for c in color_max[:-1]:
if c > 0:
ans_max += 1
ans_max += color_max[-1]
print((ans_min, ans_max))
|
n = int(eval(input()))
a = list(map(int, input().split()))
rates = [0]*9
for i in range(n):
r = min(a[i]//400, 8)
rates[r] += 1
n_min, n_max = 0, 0
if max(rates[:-1]) > 0:
for i in range(8):
n_min += 1 if rates[i] > 0 else 0
n_max = n_min+rates[-1]
else:
n_min = 1
n_max = rates[-1]
print((n_min, n_max))
| 24 | 18 | 459 | 332 |
import copy
n = int(eval(input()))
a = list(map(int, input().split()))
color = [0] * 9
for i in range(n):
rate = min(a[i] // 400, 8)
color[rate] += 1
ans_min = 0
color_min = copy.deepcopy(color)
for c in color_min[:-1]:
if c > 0:
ans_min += 1
ans_min = max(1, ans_min)
ans_max = 0
color_max = copy.deepcopy(color)
for c in color_max[:-1]:
if c > 0:
ans_max += 1
ans_max += color_max[-1]
print((ans_min, ans_max))
|
n = int(eval(input()))
a = list(map(int, input().split()))
rates = [0] * 9
for i in range(n):
r = min(a[i] // 400, 8)
rates[r] += 1
n_min, n_max = 0, 0
if max(rates[:-1]) > 0:
for i in range(8):
n_min += 1 if rates[i] > 0 else 0
n_max = n_min + rates[-1]
else:
n_min = 1
n_max = rates[-1]
print((n_min, n_max))
| false | 25 |
[
"-import copy",
"-",
"-color = [0] * 9",
"+rates = [0] * 9",
"- rate = min(a[i] // 400, 8)",
"- color[rate] += 1",
"-ans_min = 0",
"-color_min = copy.deepcopy(color)",
"-for c in color_min[:-1]:",
"- if c > 0:",
"- ans_min += 1",
"-ans_min = max(1, ans_min)",
"-ans_max = 0",
"-color_max = copy.deepcopy(color)",
"-for c in color_max[:-1]:",
"- if c > 0:",
"- ans_max += 1",
"-ans_max += color_max[-1]",
"-print((ans_min, ans_max))",
"+ r = min(a[i] // 400, 8)",
"+ rates[r] += 1",
"+n_min, n_max = 0, 0",
"+if max(rates[:-1]) > 0:",
"+ for i in range(8):",
"+ n_min += 1 if rates[i] > 0 else 0",
"+ n_max = n_min + rates[-1]",
"+else:",
"+ n_min = 1",
"+ n_max = rates[-1]",
"+print((n_min, n_max))"
] | false | 0.038763 | 0.075329 | 0.514585 |
[
"s441465309",
"s281938884"
] |
u726285999
|
p02644
|
python
|
s461537568
|
s197986507
| 1,923 | 1,727 | 43,340 | 53,000 |
Accepted
|
Accepted
| 10.19 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
H, W, K = list(map(int,input().split()))
sth, stw, glh, glw = list(map(int,input().split()))
sth, stw = sth-1, stw-1
glh, glw = glh-1, glw-1
INF = -1
Gmap = [list(eval(input())) for _ in range(H)]
Seen = [[INF]*W for _ in range(H)]
direc = {(1,0), (-1,0), (0,1), (0,-1)}
from collections import deque
def bfs(sth, stw, glh, glw):
next_q = deque([])
next_q.append((sth,stw,0))
Seen[sth][stw] = 0
while len(next_q)!=0:
#キュー取り出し(先頭)
h, w, c = next_q.popleft()
for dh, dw in direc:
for sk in range(1,K+1):
hs, ws = h + dh*sk, w + dw*sk
if not (0<=hs<H and 0<=ws<W):
break
if Gmap[hs][ws]=='@':
break
if Seen[hs][ws]==INF:
next_q.append((hs,ws,c+1))
Seen[hs][ws] = c + 1
elif Seen[hs][ws]<=c:
break
if hs==glh and ws==glw:
return c + 1
return -1
def main():
ret = bfs(sth, stw, glh, glw)
print(ret)
if __name__ == '__main__':
main()
|
from collections import deque
import sys
N_MAX = 200000 + 5
H, W, K = list(map(int, input().split()))
sth, stw, glh, glw = list(map(int, input().split()))
INF = 10**6 * K
dp = [[INF for _ in range(W+2)] for _ in range(H+2)]
dp[0] = [-1]*(W+2)
dp[H+1] = [-1]*(W+2)
for h in range(1, H+1):
s = sys.stdin.readline()
dp[h][0] = -1
dp[h][W+1] = -1
for w in range(1, W+1):
if s[w-1] == "@":
dp[h][w] = -1
# Seen = [[INF]*W for _ in range(H)]
XY = {(1, 0), (-1, 0), (0, 1), (0, -1)}
def bfs(sth, stw, glh, glw):
next_q = deque()
next_q.append((sth, stw, 0))
dp[sth][stw] = 0
while len(next_q) != 0:
# キュー取り出し(先頭)
h, w, c = next_q.popleft()
for dh, dw in XY:
for sk in range(1, K+1):
hs, ws = h + dh*sk, w + dw*sk
if dp[hs][ws] == -1:
break
if dp[hs][ws] == INF:
next_q.append((hs, ws, c+1))
dp[hs][ws] = c + 1
elif dp[hs][ws] <= c:
break
if hs == glh and ws == glw:
return c + 1
return -1
def main():
ret = bfs(sth, stw, glh, glw)
print(ret)
if __name__ == '__main__':
main()
| 45 | 57 | 1,192 | 1,311 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
H, W, K = list(map(int, input().split()))
sth, stw, glh, glw = list(map(int, input().split()))
sth, stw = sth - 1, stw - 1
glh, glw = glh - 1, glw - 1
INF = -1
Gmap = [list(eval(input())) for _ in range(H)]
Seen = [[INF] * W for _ in range(H)]
direc = {(1, 0), (-1, 0), (0, 1), (0, -1)}
from collections import deque
def bfs(sth, stw, glh, glw):
next_q = deque([])
next_q.append((sth, stw, 0))
Seen[sth][stw] = 0
while len(next_q) != 0:
# キュー取り出し(先頭)
h, w, c = next_q.popleft()
for dh, dw in direc:
for sk in range(1, K + 1):
hs, ws = h + dh * sk, w + dw * sk
if not (0 <= hs < H and 0 <= ws < W):
break
if Gmap[hs][ws] == "@":
break
if Seen[hs][ws] == INF:
next_q.append((hs, ws, c + 1))
Seen[hs][ws] = c + 1
elif Seen[hs][ws] <= c:
break
if hs == glh and ws == glw:
return c + 1
return -1
def main():
ret = bfs(sth, stw, glh, glw)
print(ret)
if __name__ == "__main__":
main()
|
from collections import deque
import sys
N_MAX = 200000 + 5
H, W, K = list(map(int, input().split()))
sth, stw, glh, glw = list(map(int, input().split()))
INF = 10**6 * K
dp = [[INF for _ in range(W + 2)] for _ in range(H + 2)]
dp[0] = [-1] * (W + 2)
dp[H + 1] = [-1] * (W + 2)
for h in range(1, H + 1):
s = sys.stdin.readline()
dp[h][0] = -1
dp[h][W + 1] = -1
for w in range(1, W + 1):
if s[w - 1] == "@":
dp[h][w] = -1
# Seen = [[INF]*W for _ in range(H)]
XY = {(1, 0), (-1, 0), (0, 1), (0, -1)}
def bfs(sth, stw, glh, glw):
next_q = deque()
next_q.append((sth, stw, 0))
dp[sth][stw] = 0
while len(next_q) != 0:
# キュー取り出し(先頭)
h, w, c = next_q.popleft()
for dh, dw in XY:
for sk in range(1, K + 1):
hs, ws = h + dh * sk, w + dw * sk
if dp[hs][ws] == -1:
break
if dp[hs][ws] == INF:
next_q.append((hs, ws, c + 1))
dp[hs][ws] = c + 1
elif dp[hs][ws] <= c:
break
if hs == glh and ws == glw:
return c + 1
return -1
def main():
ret = bfs(sth, stw, glh, glw)
print(ret)
if __name__ == "__main__":
main()
| false | 21.052632 |
[
"-#!/usr/bin python3",
"-# -*- coding: utf-8 -*-",
"+from collections import deque",
"+import sys",
"+",
"+N_MAX = 200000 + 5",
"-sth, stw = sth - 1, stw - 1",
"-glh, glw = glh - 1, glw - 1",
"-INF = -1",
"-Gmap = [list(eval(input())) for _ in range(H)]",
"-Seen = [[INF] * W for _ in range(H)]",
"-direc = {(1, 0), (-1, 0), (0, 1), (0, -1)}",
"-from collections import deque",
"+INF = 10**6 * K",
"+dp = [[INF for _ in range(W + 2)] for _ in range(H + 2)]",
"+dp[0] = [-1] * (W + 2)",
"+dp[H + 1] = [-1] * (W + 2)",
"+for h in range(1, H + 1):",
"+ s = sys.stdin.readline()",
"+ dp[h][0] = -1",
"+ dp[h][W + 1] = -1",
"+ for w in range(1, W + 1):",
"+ if s[w - 1] == \"@\":",
"+ dp[h][w] = -1",
"+# Seen = [[INF]*W for _ in range(H)]",
"+XY = {(1, 0), (-1, 0), (0, 1), (0, -1)}",
"- next_q = deque([])",
"+ next_q = deque()",
"- Seen[sth][stw] = 0",
"+ dp[sth][stw] = 0",
"- for dh, dw in direc:",
"+ for dh, dw in XY:",
"- if not (0 <= hs < H and 0 <= ws < W):",
"+ if dp[hs][ws] == -1:",
"- if Gmap[hs][ws] == \"@\":",
"- break",
"- if Seen[hs][ws] == INF:",
"+ if dp[hs][ws] == INF:",
"- Seen[hs][ws] = c + 1",
"- elif Seen[hs][ws] <= c:",
"+ dp[hs][ws] = c + 1",
"+ elif dp[hs][ws] <= c:"
] | false | 0.035446 | 0.043674 | 0.811598 |
[
"s461537568",
"s197986507"
] |
u813098295
|
p02687
|
python
|
s897760309
|
s741119391
| 23 | 21 | 9,020 | 8,956 |
Accepted
|
Accepted
| 8.7 |
S = eval(input())
print(("ABC" if S == "ARC" else "ARC"))
|
print(("ABC" if eval(input()) == "ARC" else "ARC"))
| 2 | 1 | 51 | 43 |
S = eval(input())
print(("ABC" if S == "ARC" else "ARC"))
|
print(("ABC" if eval(input()) == "ARC" else "ARC"))
| false | 50 |
[
"-S = eval(input())",
"-print((\"ABC\" if S == \"ARC\" else \"ARC\"))",
"+print((\"ABC\" if eval(input()) == \"ARC\" else \"ARC\"))"
] | false | 0.077913 | 0.145226 | 0.536497 |
[
"s897760309",
"s741119391"
] |
u089032001
|
p02813
|
python
|
s516220080
|
s746772711
| 38 | 28 | 8,052 | 3,188 |
Accepted
|
Accepted
| 26.32 |
from itertools import permutations as perm
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
P = tuple(inpl())
Q = tuple(inpl())
A = list(perm([i for i in range(1, N + 1)]))
A.sort()
for i, a in enumerate(A):
# print(a)
if a == P:
p = i
if a == Q:
q = i
print((abs(p - q)))
|
from itertools import permutations as perm
def inpl():
return tuple(map(int, input().split()))
N = int(eval(input()))
P = inpl()
Q = inpl()
for i, p in enumerate(perm([j+1 for j in range(N)])):
if p == P:
pi = i
if p == Q:
qi = i
print((abs(pi-qi)))
| 22 | 17 | 350 | 291 |
from itertools import permutations as perm
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
P = tuple(inpl())
Q = tuple(inpl())
A = list(perm([i for i in range(1, N + 1)]))
A.sort()
for i, a in enumerate(A):
# print(a)
if a == P:
p = i
if a == Q:
q = i
print((abs(p - q)))
|
from itertools import permutations as perm
def inpl():
return tuple(map(int, input().split()))
N = int(eval(input()))
P = inpl()
Q = inpl()
for i, p in enumerate(perm([j + 1 for j in range(N)])):
if p == P:
pi = i
if p == Q:
qi = i
print((abs(pi - qi)))
| false | 22.727273 |
[
"- return list(map(int, input().split()))",
"+ return tuple(map(int, input().split()))",
"-P = tuple(inpl())",
"-Q = tuple(inpl())",
"-A = list(perm([i for i in range(1, N + 1)]))",
"-A.sort()",
"-for i, a in enumerate(A):",
"- # print(a)",
"- if a == P:",
"- p = i",
"- if a == Q:",
"- q = i",
"-print((abs(p - q)))",
"+P = inpl()",
"+Q = inpl()",
"+for i, p in enumerate(perm([j + 1 for j in range(N)])):",
"+ if p == P:",
"+ pi = i",
"+ if p == Q:",
"+ qi = i",
"+print((abs(pi - qi)))"
] | false | 0.041854 | 0.040691 | 1.028566 |
[
"s516220080",
"s746772711"
] |
u864197622
|
p04022
|
python
|
s486536776
|
s118192190
| 3,615 | 2,847 | 123,228 | 123,352 |
Accepted
|
Accepted
| 21.24 |
import sys
input = sys.stdin.readline
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i%2
if i == 101 and n >= 2**20:
def findFactorRho(N):
def gcd(a, b):
while b: a, b = b, a % b
return a
def f(x, c):
return (x * x + c) % N
for c in range(1, 99):
X, d, j = [2], 1, 0
while d == 1:
j += 1
X.append(f(X[-1], c))
X.append(f(X[-1], c))
d = gcd(abs(X[2*j]-X[j]), N)
if d != N:
if isPrimeMR(d):
return d
elif isPrimeMR(N//d): return N//d
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
return ret
def isPrimeMR(n):
if n == 2:
return True
if n == 1 or n & 1 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
L = [2, 7, 61] if n < 1<<32 else [2, 13, 23, 1662803] if n < 1<<40 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
for a in L:
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = (y * y) % n
t <<= 1
if y != n - 1 and t & 1 == 0:
return False
return True
N = int(eval(input()))
ans = 0
D = {}
for _ in range(N):
pf = primeFactor(int(eval(input())))
a, b = 1, 1
for p in pf:
a *= p ** (pf[p] % 3)
b *= p ** (-pf[p] % 3)
if a not in D: D[a] = 0
if a == b:
if D[a] == 0: ans += 1
else:
if b not in D: D[b] = 0
if D[b] <= D[a]: ans += 1
D[a] += 1
print(ans)
|
import sys
input = sys.stdin.readline
def gcd(a, b):
while b: a, b = b, a % b
return a
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8 + 1
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r-k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
while g == 1:
ys = f(ys)
g = gcd(abs(x-ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n//g): return n//g
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i%2
if i == 101 and n >= 2**20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
return ret
N = int(eval(input()))
ans = 0
D = {}
for _ in range(N):
pf = primeFactor(int(eval(input())))
a, b = 1, 1
for p in pf:
a *= p ** (pf[p] % 3)
b *= p ** (-pf[p] % 3)
if a not in D: D[a] = 0
if a == b:
if D[a] == 0: ans += 1
else:
if b not in D: D[b] = 0
if D[b] <= D[a]: ans += 1
D[a] += 1
print(ans)
| 87 | 91 | 2,398 | 2,352 |
import sys
input = sys.stdin.readline
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
while i * i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k:
ret[i] = k
i += 1 + i % 2
if i == 101 and n >= 2**20:
def findFactorRho(N):
def gcd(a, b):
while b:
a, b = b, a % b
return a
def f(x, c):
return (x * x + c) % N
for c in range(1, 99):
X, d, j = [2], 1, 0
while d == 1:
j += 1
X.append(f(X[-1], c))
X.append(f(X[-1], c))
d = gcd(abs(X[2 * j] - X[j]), N)
if d != N:
if isPrimeMR(d):
return d
elif isPrimeMR(N // d):
return N // d
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1:
ret[n] = 1
if mrFlg > 0:
ret = {x: ret[x] for x in sorted(ret)}
return ret
def isPrimeMR(n):
if n == 2:
return True
if n == 1 or n & 1 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
L = (
[2, 7, 61]
if n < 1 << 32
else [2, 13, 23, 1662803]
if n < 1 << 40
else [2, 3, 5, 7, 11, 13, 17]
if n < 1 << 48
else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
)
for a in L:
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = (y * y) % n
t <<= 1
if y != n - 1 and t & 1 == 0:
return False
return True
N = int(eval(input()))
ans = 0
D = {}
for _ in range(N):
pf = primeFactor(int(eval(input())))
a, b = 1, 1
for p in pf:
a *= p ** (pf[p] % 3)
b *= p ** (-pf[p] % 3)
if a not in D:
D[a] = 0
if a == b:
if D[a] == 0:
ans += 1
else:
if b not in D:
D[b] = 0
if D[b] <= D[a]:
ans += 1
D[a] += 1
print(ans)
|
import sys
input = sys.stdin.readline
def gcd(a, b):
while b:
a, b = b, a % b
return a
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = (
[2, 7, 61]
if n < 1 << 32
else [2, 3, 5, 7, 11, 13, 17]
if n < 1 << 48
else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
)
for a in L:
t = d
y = pow(a, t, n)
if y == 1:
continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1:
return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8 + 1
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g):
return g
elif isPrimeMR(n // g):
return n // g
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
while i * i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k:
ret[i] = k
i += 1 + i % 2
if i == 101 and n >= 2**20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1:
ret[n] = 1
if mrFlg > 0:
ret = {x: ret[x] for x in sorted(ret)}
return ret
N = int(eval(input()))
ans = 0
D = {}
for _ in range(N):
pf = primeFactor(int(eval(input())))
a, b = 1, 1
for p in pf:
a *= p ** (pf[p] % 3)
b *= p ** (-pf[p] % 3)
if a not in D:
D[a] = 0
if a == b:
if D[a] == 0:
ans += 1
else:
if b not in D:
D[b] = 0
if D[b] <= D[a]:
ans += 1
D[a] += 1
print(ans)
| false | 4.395604 |
[
"+",
"+",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+def isPrimeMR(n):",
"+ d = n - 1",
"+ d = d // (d & -d)",
"+ L = (",
"+ [2, 7, 61]",
"+ if n < 1 << 32",
"+ else [2, 3, 5, 7, 11, 13, 17]",
"+ if n < 1 << 48",
"+ else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]",
"+ )",
"+ for a in L:",
"+ t = d",
"+ y = pow(a, t, n)",
"+ if y == 1:",
"+ continue",
"+ while y != n - 1:",
"+ y = (y * y) % n",
"+ if y == 1 or t == n - 1:",
"+ return 0",
"+ t <<= 1",
"+ return 1",
"+",
"+",
"+def findFactorRho(n):",
"+ m = 1 << n.bit_length() // 8 + 1",
"+ for c in range(1, 99):",
"+ f = lambda x: (x * x + c) % n",
"+ y, r, q, g = 2, 1, 1, 1",
"+ while g == 1:",
"+ x = y",
"+ for i in range(r):",
"+ y = f(y)",
"+ k = 0",
"+ while k < r and g == 1:",
"+ ys = y",
"+ for i in range(min(m, r - k)):",
"+ y = f(y)",
"+ q = q * abs(x - y) % n",
"+ g = gcd(q, n)",
"+ k += m",
"+ r <<= 1",
"+ if g == n:",
"+ while g == 1:",
"+ ys = f(ys)",
"+ g = gcd(abs(x - ys), n)",
"+ if g < n:",
"+ if isPrimeMR(g):",
"+ return g",
"+ elif isPrimeMR(n // g):",
"+ return n // g",
"-",
"- def findFactorRho(N):",
"- def gcd(a, b):",
"- while b:",
"- a, b = b, a % b",
"- return a",
"-",
"- def f(x, c):",
"- return (x * x + c) % N",
"-",
"- for c in range(1, 99):",
"- X, d, j = [2], 1, 0",
"- while d == 1:",
"- j += 1",
"- X.append(f(X[-1], c))",
"- X.append(f(X[-1], c))",
"- d = gcd(abs(X[2 * j] - X[j]), N)",
"- if d != N:",
"- if isPrimeMR(d):",
"- return d",
"- elif isPrimeMR(N // d):",
"- return N // d",
"-",
"-",
"-",
"-def isPrimeMR(n):",
"- if n == 2:",
"- return True",
"- if n == 1 or n & 1 == 0:",
"- return False",
"- d = (n - 1) >> 1",
"- while d & 1 == 0:",
"- d >>= 1",
"- L = (",
"- [2, 7, 61]",
"- if n < 1 << 32",
"- else [2, 13, 23, 1662803]",
"- if n < 1 << 40",
"- else [2, 3, 5, 7, 11, 13, 17]",
"- if n < 1 << 48",
"- else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]",
"- )",
"- for a in L:",
"- t = d",
"- y = pow(a, t, n)",
"- while t != n - 1 and y != 1 and y != n - 1:",
"- y = (y * y) % n",
"- t <<= 1",
"- if y != n - 1 and t & 1 == 0:",
"- return False",
"- return True"
] | false | 0.05962 | 0.059811 | 0.996805 |
[
"s486536776",
"s118192190"
] |
u197457087
|
p02720
|
python
|
s450352309
|
s100636749
| 99 | 88 | 11,028 | 76,096 |
Accepted
|
Accepted
| 11.11 |
k = int(eval(input()))
a = [1,2,3,4,5,6,7,8,9] #一桁目を入れる。
kosu = [0,1,1,1,1,1,1,1,1,1]
total = sum(kosu)
i = 0 #これが1桁に相当.
tempk = k*1
while k > total:
b = a.copy() #aのコピーを作ってbを参照して新しいaを作る。
tempk = k - total
i += 1
a = [] #ここでaをリセット
kosub = kosu.copy() #各々の数で終わる個数を記録
kosu = []
for i in range(10):
if i == 0:
kosu.append(kosub[i]+kosub[i+1])
elif i == 9:
kosu.append(kosub[i-1]+kosub[i])
else:
kosu.append(kosub[i-1]+kosub[i]+kosub[i+1])
total += sum(kosu)
for i in range(len(b)):
if b[i]%10 == 0:
a.append(b[i]*10)
a.append(b[i]*10+1)
elif b[i]%10 == 9:
a.append(b[i]*10+8)
a.append(b[i]*10+9)
else:
a.append(b[i]*10+b[i]%10-1)
a.append(b[i]*10+b[i]%10)
a.append(b[i]*10+b[i]%10+1)
#print(a)
#print(kosu)
#print(total)
#print(tempk,total,len(a))
print((a[tempk-1]))
|
N = int(eval(input()))
if N <= 9:
print(N)
exit()
A = [[] for _ in range(11)]
A[0] = [1,2,3,4,5,6,7,8,9]
now = 9
keta = 1
while True:
for x in A[keta-1]:
x = str(x)
last = int(x[-1])
if last - 1 >= 0:
temp = x+str(last-1)
A[keta].append(int(temp))
now += 1
if now == N:
print(temp)
exit()
temp = x+str(last)
A[keta].append(int(temp))
now += 1
if now == N:
print(temp)
exit()
if last+1 <= 9:
temp = x+str(last+1)
A[keta].append(int(temp))
now += 1
if now == N:
print(temp)
exit()
keta += 1
| 37 | 34 | 906 | 649 |
k = int(eval(input()))
a = [1, 2, 3, 4, 5, 6, 7, 8, 9] # 一桁目を入れる。
kosu = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
total = sum(kosu)
i = 0 # これが1桁に相当.
tempk = k * 1
while k > total:
b = a.copy() # aのコピーを作ってbを参照して新しいaを作る。
tempk = k - total
i += 1
a = [] # ここでaをリセット
kosub = kosu.copy() # 各々の数で終わる個数を記録
kosu = []
for i in range(10):
if i == 0:
kosu.append(kosub[i] + kosub[i + 1])
elif i == 9:
kosu.append(kosub[i - 1] + kosub[i])
else:
kosu.append(kosub[i - 1] + kosub[i] + kosub[i + 1])
total += sum(kosu)
for i in range(len(b)):
if b[i] % 10 == 0:
a.append(b[i] * 10)
a.append(b[i] * 10 + 1)
elif b[i] % 10 == 9:
a.append(b[i] * 10 + 8)
a.append(b[i] * 10 + 9)
else:
a.append(b[i] * 10 + b[i] % 10 - 1)
a.append(b[i] * 10 + b[i] % 10)
a.append(b[i] * 10 + b[i] % 10 + 1)
# print(a)
# print(kosu)
# print(total)
# print(tempk,total,len(a))
print((a[tempk - 1]))
|
N = int(eval(input()))
if N <= 9:
print(N)
exit()
A = [[] for _ in range(11)]
A[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
now = 9
keta = 1
while True:
for x in A[keta - 1]:
x = str(x)
last = int(x[-1])
if last - 1 >= 0:
temp = x + str(last - 1)
A[keta].append(int(temp))
now += 1
if now == N:
print(temp)
exit()
temp = x + str(last)
A[keta].append(int(temp))
now += 1
if now == N:
print(temp)
exit()
if last + 1 <= 9:
temp = x + str(last + 1)
A[keta].append(int(temp))
now += 1
if now == N:
print(temp)
exit()
keta += 1
| false | 8.108108 |
[
"-k = int(eval(input()))",
"-a = [1, 2, 3, 4, 5, 6, 7, 8, 9] # 一桁目を入れる。",
"-kosu = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1]",
"-total = sum(kosu)",
"-i = 0 # これが1桁に相当.",
"-tempk = k * 1",
"-while k > total:",
"- b = a.copy() # aのコピーを作ってbを参照して新しいaを作る。",
"- tempk = k - total",
"- i += 1",
"- a = [] # ここでaをリセット",
"- kosub = kosu.copy() # 各々の数で終わる個数を記録",
"- kosu = []",
"- for i in range(10):",
"- if i == 0:",
"- kosu.append(kosub[i] + kosub[i + 1])",
"- elif i == 9:",
"- kosu.append(kosub[i - 1] + kosub[i])",
"- else:",
"- kosu.append(kosub[i - 1] + kosub[i] + kosub[i + 1])",
"- total += sum(kosu)",
"- for i in range(len(b)):",
"- if b[i] % 10 == 0:",
"- a.append(b[i] * 10)",
"- a.append(b[i] * 10 + 1)",
"- elif b[i] % 10 == 9:",
"- a.append(b[i] * 10 + 8)",
"- a.append(b[i] * 10 + 9)",
"- else:",
"- a.append(b[i] * 10 + b[i] % 10 - 1)",
"- a.append(b[i] * 10 + b[i] % 10)",
"- a.append(b[i] * 10 + b[i] % 10 + 1)",
"- # print(a)",
"- # print(kosu)",
"- # print(total)",
"-# print(tempk,total,len(a))",
"-print((a[tempk - 1]))",
"+N = int(eval(input()))",
"+if N <= 9:",
"+ print(N)",
"+ exit()",
"+A = [[] for _ in range(11)]",
"+A[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9]",
"+now = 9",
"+keta = 1",
"+while True:",
"+ for x in A[keta - 1]:",
"+ x = str(x)",
"+ last = int(x[-1])",
"+ if last - 1 >= 0:",
"+ temp = x + str(last - 1)",
"+ A[keta].append(int(temp))",
"+ now += 1",
"+ if now == N:",
"+ print(temp)",
"+ exit()",
"+ temp = x + str(last)",
"+ A[keta].append(int(temp))",
"+ now += 1",
"+ if now == N:",
"+ print(temp)",
"+ exit()",
"+ if last + 1 <= 9:",
"+ temp = x + str(last + 1)",
"+ A[keta].append(int(temp))",
"+ now += 1",
"+ if now == N:",
"+ print(temp)",
"+ exit()",
"+ keta += 1"
] | false | 0.007856 | 0.047857 | 0.164145 |
[
"s450352309",
"s100636749"
] |
u761529120
|
p02792
|
python
|
s684898603
|
s201735528
| 240 | 86 | 42,076 | 67,828 |
Accepted
|
Accepted
| 64.17 |
def main():
N = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1,N+1):
tmp = str(i)
top = int(tmp[0])
end = int(tmp[-1])
cnt[top][end] += 1
ans = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if a == d and b == c:
ans += cnt[a][b] * cnt[c][d]
print(ans)
if __name__ == "__main__":
main()
|
def main():
N = int(eval(input()))
dp = [[0] * 10 for _ in range(10)]
for i in range(1,N+1):
tmp = str(i)
left = int(tmp[0])
right = int(tmp[-1])
if left == 0 or right == 0:
continue
dp[left][right] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += dp[i][j] * dp[j][i]
print(ans)
if __name__ == "__main__":
main()
| 22 | 21 | 505 | 441 |
def main():
N = int(eval(input()))
cnt = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
tmp = str(i)
top = int(tmp[0])
end = int(tmp[-1])
cnt[top][end] += 1
ans = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if a == d and b == c:
ans += cnt[a][b] * cnt[c][d]
print(ans)
if __name__ == "__main__":
main()
|
def main():
N = int(eval(input()))
dp = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
tmp = str(i)
left = int(tmp[0])
right = int(tmp[-1])
if left == 0 or right == 0:
continue
dp[left][right] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += dp[i][j] * dp[j][i]
print(ans)
if __name__ == "__main__":
main()
| false | 4.545455 |
[
"- cnt = [[0] * 10 for _ in range(10)]",
"+ dp = [[0] * 10 for _ in range(10)]",
"- top = int(tmp[0])",
"- end = int(tmp[-1])",
"- cnt[top][end] += 1",
"+ left = int(tmp[0])",
"+ right = int(tmp[-1])",
"+ if left == 0 or right == 0:",
"+ continue",
"+ dp[left][right] += 1",
"- for a in range(10):",
"- for b in range(10):",
"- for c in range(10):",
"- for d in range(10):",
"- if a == d and b == c:",
"- ans += cnt[a][b] * cnt[c][d]",
"+ for i in range(10):",
"+ for j in range(10):",
"+ ans += dp[i][j] * dp[j][i]"
] | false | 0.067458 | 0.066709 | 1.011229 |
[
"s684898603",
"s201735528"
] |
u062147869
|
p03210
|
python
|
s494724927
|
s289454765
| 175 | 18 | 38,256 | 3,064 |
Accepted
|
Accepted
| 89.71 |
X=int(eval(input()))
if X==7 or X==5 or X==3:
print('YES')
else:
print('NO')
|
N=int(eval(input()))
if N==3 or N==5 or N==7:
print('YES')
else:
print('NO')
| 5 | 5 | 82 | 78 |
X = int(eval(input()))
if X == 7 or X == 5 or X == 3:
print("YES")
else:
print("NO")
|
N = int(eval(input()))
if N == 3 or N == 5 or N == 7:
print("YES")
else:
print("NO")
| false | 0 |
[
"-X = int(eval(input()))",
"-if X == 7 or X == 5 or X == 3:",
"+N = int(eval(input()))",
"+if N == 3 or N == 5 or N == 7:"
] | false | 0.042802 | 0.033119 | 1.292346 |
[
"s494724927",
"s289454765"
] |
u796942881
|
p03659
|
python
|
s071632097
|
s247744039
| 126 | 112 | 24,320 | 24,320 |
Accepted
|
Accepted
| 11.11 |
from itertools import accumulate
def main():
N, *a = list(map(int, open(0).read().split()))
a = list(accumulate(a))
total = a[-1]
print((min(abs(total - 2 * a[i]) for i in range(N - 1))))
return
main()
|
from itertools import accumulate
def main():
N, *a = list(map(int, open(0).read().split()))
a = list(accumulate(a))
total = a[-1]
print((min(abs(total - 2 * i) for i in a[:-1])))
return
main()
| 12 | 12 | 229 | 220 |
from itertools import accumulate
def main():
N, *a = list(map(int, open(0).read().split()))
a = list(accumulate(a))
total = a[-1]
print((min(abs(total - 2 * a[i]) for i in range(N - 1))))
return
main()
|
from itertools import accumulate
def main():
N, *a = list(map(int, open(0).read().split()))
a = list(accumulate(a))
total = a[-1]
print((min(abs(total - 2 * i) for i in a[:-1])))
return
main()
| false | 0 |
[
"- print((min(abs(total - 2 * a[i]) for i in range(N - 1))))",
"+ print((min(abs(total - 2 * i) for i in a[:-1])))"
] | false | 0.039784 | 0.040286 | 0.987554 |
[
"s071632097",
"s247744039"
] |
u668503853
|
p03031
|
python
|
s019599356
|
s729210192
| 42 | 38 | 3,064 | 3,064 |
Accepted
|
Accepted
| 9.52 |
N,M=list(map(int,input().split()))
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
lit=[0]*M
for j,switch in enumerate(L):
cnt=0
for s in switch:
if i>>(s-1)&1:
cnt+=1
if cnt%2==P[j]:
lit[j]=1
else:
lit[j]=0
if all(lit): ans+=1
print(ans)
|
N,M=list(map(int,input().split()))
L=[list(map(int,input().split()))[1:] for _ in range(M)]
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
lit=[0]*M
for j,switches in enumerate(L):
cnt=0
for s in switches:
if i>>(s-1)&1:cnt+=1
if cnt%2==P[j]:lit[j]=1
if all(lit):ans+=1
print(ans)
| 17 | 13 | 367 | 325 |
N, M = list(map(int, input().split()))
L = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
lit = [0] * M
for j, switch in enumerate(L):
cnt = 0
for s in switch:
if i >> (s - 1) & 1:
cnt += 1
if cnt % 2 == P[j]:
lit[j] = 1
else:
lit[j] = 0
if all(lit):
ans += 1
print(ans)
|
N, M = list(map(int, input().split()))
L = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
lit = [0] * M
for j, switches in enumerate(L):
cnt = 0
for s in switches:
if i >> (s - 1) & 1:
cnt += 1
if cnt % 2 == P[j]:
lit[j] = 1
if all(lit):
ans += 1
print(ans)
| false | 23.529412 |
[
"- for j, switch in enumerate(L):",
"+ for j, switches in enumerate(L):",
"- for s in switch:",
"+ for s in switches:",
"- else:",
"- lit[j] = 0"
] | false | 0.049622 | 0.049701 | 0.998411 |
[
"s019599356",
"s729210192"
] |
u290563917
|
p03163
|
python
|
s194585932
|
s857388142
| 738 | 500 | 144,744 | 120,812 |
Accepted
|
Accepted
| 32.25 |
n, w = list(map(int, input().split(' ')))
items = [[]] * n
for i in range(n):
weight, val = list(map(int, input().split(' ')))
items[i] = [weight, val]
# print(n, w)
# print(items)
dp = []
for i in range(n+1):
dp.append([])
for j in range(w+1):
dp[i].append(0)
# print(len(dp), len(dp[0]), dp[0][0])
for i in range(n):
weight , val = items[i]
for sum_w in range(w+1):
# i番目のアイテムを選択する
if sum_w - weight >= 0:
dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight] + val)
# i番目のアイテムを選択しない
dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print((dp[n][w]))
|
n, w = list(map(int, input().split()))
wl = [0] * n
vl = [0] * n
for i in range(n):
wl[i], vl[i] = list(map(int, input().split()))
dp = [[]] * (n+1)
for i in range(n+1):
dp[i] = [0] * (w+1)
for i in range(n):
for j in range(w+1):
if j >= wl[i]:
dp[i+1][j] = max(dp[i][j], dp[i][j-wl[i]]+vl[i])
dp[i+1][j] = max(dp[i][j], dp[i+1][j])
print((dp[n][w]))
#for i in range(n+1):
# print(dp[i])
| 26 | 19 | 611 | 415 |
n, w = list(map(int, input().split(" ")))
items = [[]] * n
for i in range(n):
weight, val = list(map(int, input().split(" ")))
items[i] = [weight, val]
# print(n, w)
# print(items)
dp = []
for i in range(n + 1):
dp.append([])
for j in range(w + 1):
dp[i].append(0)
# print(len(dp), len(dp[0]), dp[0][0])
for i in range(n):
weight, val = items[i]
for sum_w in range(w + 1):
# i番目のアイテムを選択する
if sum_w - weight >= 0:
dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + val)
# i番目のアイテムを選択しない
dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print((dp[n][w]))
|
n, w = list(map(int, input().split()))
wl = [0] * n
vl = [0] * n
for i in range(n):
wl[i], vl[i] = list(map(int, input().split()))
dp = [[]] * (n + 1)
for i in range(n + 1):
dp[i] = [0] * (w + 1)
for i in range(n):
for j in range(w + 1):
if j >= wl[i]:
dp[i + 1][j] = max(dp[i][j], dp[i][j - wl[i]] + vl[i])
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
print((dp[n][w]))
# for i in range(n+1):
# print(dp[i])
| false | 26.923077 |
[
"-n, w = list(map(int, input().split(\" \")))",
"-items = [[]] * n",
"+n, w = list(map(int, input().split()))",
"+wl = [0] * n",
"+vl = [0] * n",
"- weight, val = list(map(int, input().split(\" \")))",
"- items[i] = [weight, val]",
"-# print(n, w)",
"-# print(items)",
"-dp = []",
"+ wl[i], vl[i] = list(map(int, input().split()))",
"+dp = [[]] * (n + 1)",
"- dp.append([])",
"+ dp[i] = [0] * (w + 1)",
"+for i in range(n):",
"- dp[i].append(0)",
"-# print(len(dp), len(dp[0]), dp[0][0])",
"-for i in range(n):",
"- weight, val = items[i]",
"- for sum_w in range(w + 1):",
"- # i番目のアイテムを選択する",
"- if sum_w - weight >= 0:",
"- dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + val)",
"- # i番目のアイテムを選択しない",
"- dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])",
"+ if j >= wl[i]:",
"+ dp[i + 1][j] = max(dp[i][j], dp[i][j - wl[i]] + vl[i])",
"+ dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])",
"+# for i in range(n+1):",
"+# print(dp[i])"
] | false | 0.105547 | 0.078981 | 1.336364 |
[
"s194585932",
"s857388142"
] |
u769640830
|
p03171
|
python
|
s709533285
|
s089739370
| 1,932 | 462 | 164,488 | 115,292 |
Accepted
|
Accepted
| 76.09 |
import sys
def f(l,beg,end):
if beg==end:
dp[beg][end]=l[beg]
return l[beg]
if beg+1==end:
dp[beg][end] = max(l[beg],l[end])
return max(l[beg],l[end])
if dp[beg][end]!=-1:
return dp[beg][end]
ans1=l[beg]+min(f(l,beg+2,end),f(l,beg+1,end-1))
ans2=l[end]+min(f(l,beg,end-2),f(l,beg+1,end-1))
dp[beg][end]=max(ans1,ans2)
return max(ans1,ans2)
n = int(eval(input()))
l = list(map(int, input().split()))
tl = sum(l)
dp=[]
for _ in range(n):
dp.append([-1]*n)
a = f(l,0,n-1)
b = tl-a
print((a-b))
|
n = int(eval(input()))
l = list(map(int, input().split()))
tl = sum(l)
dp=[]
for _ in range(n):
dp.append([0]*n)
for i in range(n):
dp[i][i]=l[i]
for i in range(n-1):
dp[i][i+1]=max(l[i],l[i+1])
for i in range(n-1,-1,-1):
for j in range(i+2,n):
ans1=l[i]+min(dp[i+2][j],dp[i+1][j-1])
ans2=l[j]+min(dp[i+1][j-1],dp[i][j-2])
dp[i][j]=max(ans1,ans2)
a = dp[0][n-1]
b = tl-a
print((a-b))
| 25 | 18 | 581 | 432 |
import sys
def f(l, beg, end):
if beg == end:
dp[beg][end] = l[beg]
return l[beg]
if beg + 1 == end:
dp[beg][end] = max(l[beg], l[end])
return max(l[beg], l[end])
if dp[beg][end] != -1:
return dp[beg][end]
ans1 = l[beg] + min(f(l, beg + 2, end), f(l, beg + 1, end - 1))
ans2 = l[end] + min(f(l, beg, end - 2), f(l, beg + 1, end - 1))
dp[beg][end] = max(ans1, ans2)
return max(ans1, ans2)
n = int(eval(input()))
l = list(map(int, input().split()))
tl = sum(l)
dp = []
for _ in range(n):
dp.append([-1] * n)
a = f(l, 0, n - 1)
b = tl - a
print((a - b))
|
n = int(eval(input()))
l = list(map(int, input().split()))
tl = sum(l)
dp = []
for _ in range(n):
dp.append([0] * n)
for i in range(n):
dp[i][i] = l[i]
for i in range(n - 1):
dp[i][i + 1] = max(l[i], l[i + 1])
for i in range(n - 1, -1, -1):
for j in range(i + 2, n):
ans1 = l[i] + min(dp[i + 2][j], dp[i + 1][j - 1])
ans2 = l[j] + min(dp[i + 1][j - 1], dp[i][j - 2])
dp[i][j] = max(ans1, ans2)
a = dp[0][n - 1]
b = tl - a
print((a - b))
| false | 28 |
[
"-import sys",
"-",
"-",
"-def f(l, beg, end):",
"- if beg == end:",
"- dp[beg][end] = l[beg]",
"- return l[beg]",
"- if beg + 1 == end:",
"- dp[beg][end] = max(l[beg], l[end])",
"- return max(l[beg], l[end])",
"- if dp[beg][end] != -1:",
"- return dp[beg][end]",
"- ans1 = l[beg] + min(f(l, beg + 2, end), f(l, beg + 1, end - 1))",
"- ans2 = l[end] + min(f(l, beg, end - 2), f(l, beg + 1, end - 1))",
"- dp[beg][end] = max(ans1, ans2)",
"- return max(ans1, ans2)",
"-",
"-",
"- dp.append([-1] * n)",
"-a = f(l, 0, n - 1)",
"+ dp.append([0] * n)",
"+for i in range(n):",
"+ dp[i][i] = l[i]",
"+for i in range(n - 1):",
"+ dp[i][i + 1] = max(l[i], l[i + 1])",
"+for i in range(n - 1, -1, -1):",
"+ for j in range(i + 2, n):",
"+ ans1 = l[i] + min(dp[i + 2][j], dp[i + 1][j - 1])",
"+ ans2 = l[j] + min(dp[i + 1][j - 1], dp[i][j - 2])",
"+ dp[i][j] = max(ans1, ans2)",
"+a = dp[0][n - 1]"
] | false | 0.037351 | 0.042041 | 0.88844 |
[
"s709533285",
"s089739370"
] |
u489959379
|
p03240
|
python
|
s363668762
|
s974436067
| 566 | 231 | 3,064 | 9,164 |
Accepted
|
Accepted
| 59.19 |
n = int(eval(input()))
query = []
query0 = []
for i in range(n):
x, y, h = list(map(int, input().split()))
if h > 0:
query.append([x, y, h])
else:
query0.append([x, y, h])
for cx in range(101):
for cy in range(101):
res = []
for i in range(len(query)):
x, y, h = query[i]
p = abs(x - cx) + abs(y - cy)
H = h + p
if h != 0:
res.append(H)
if len(set(res)) == 1:
H = res[0]
for j in range(len(query0)):
x0, y0, _ = query0[j]
if 0 < H - abs(x0 - cx) - abs(y0 - cy):
break
else:
print((cx, cy, H))
exit()
|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
XYH = [list(map(int, input().split())) for _ in range(n)]
info = []
for x, y, h in XYH:
if h == 0:
continue
info.append([x, y, h])
if len(info) == 1:
print((*info[0]))
exit()
for Cx in range(100 + 1):
for Cy in range(100 + 1):
tmp = set()
for x, y, h in info:
if h == 0:
continue
H = h + abs(x - Cx) + abs(y - Cy)
tmp.add(H)
if len(tmp) == 1:
print((Cx, Cy, *list(tmp)))
exit()
if __name__ == '__main__':
resolve()
| 29 | 37 | 756 | 811 |
n = int(eval(input()))
query = []
query0 = []
for i in range(n):
x, y, h = list(map(int, input().split()))
if h > 0:
query.append([x, y, h])
else:
query0.append([x, y, h])
for cx in range(101):
for cy in range(101):
res = []
for i in range(len(query)):
x, y, h = query[i]
p = abs(x - cx) + abs(y - cy)
H = h + p
if h != 0:
res.append(H)
if len(set(res)) == 1:
H = res[0]
for j in range(len(query0)):
x0, y0, _ = query0[j]
if 0 < H - abs(x0 - cx) - abs(y0 - cy):
break
else:
print((cx, cy, H))
exit()
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
XYH = [list(map(int, input().split())) for _ in range(n)]
info = []
for x, y, h in XYH:
if h == 0:
continue
info.append([x, y, h])
if len(info) == 1:
print((*info[0]))
exit()
for Cx in range(100 + 1):
for Cy in range(100 + 1):
tmp = set()
for x, y, h in info:
if h == 0:
continue
H = h + abs(x - Cx) + abs(y - Cy)
tmp.add(H)
if len(tmp) == 1:
print((Cx, Cy, *list(tmp)))
exit()
if __name__ == "__main__":
resolve()
| false | 21.621622 |
[
"-n = int(eval(input()))",
"-query = []",
"-query0 = []",
"-for i in range(n):",
"- x, y, h = list(map(int, input().split()))",
"- if h > 0:",
"- query.append([x, y, h])",
"- else:",
"- query0.append([x, y, h])",
"-for cx in range(101):",
"- for cy in range(101):",
"- res = []",
"- for i in range(len(query)):",
"- x, y, h = query[i]",
"- p = abs(x - cx) + abs(y - cy)",
"- H = h + p",
"- if h != 0:",
"- res.append(H)",
"- if len(set(res)) == 1:",
"- H = res[0]",
"- for j in range(len(query0)):",
"- x0, y0, _ = query0[j]",
"- if 0 < H - abs(x0 - cx) - abs(y0 - cy):",
"- break",
"- else:",
"- print((cx, cy, H))",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ n = int(eval(input()))",
"+ XYH = [list(map(int, input().split())) for _ in range(n)]",
"+ info = []",
"+ for x, y, h in XYH:",
"+ if h == 0:",
"+ continue",
"+ info.append([x, y, h])",
"+ if len(info) == 1:",
"+ print((*info[0]))",
"+ exit()",
"+ for Cx in range(100 + 1):",
"+ for Cy in range(100 + 1):",
"+ tmp = set()",
"+ for x, y, h in info:",
"+ if h == 0:",
"+ continue",
"+ H = h + abs(x - Cx) + abs(y - Cy)",
"+ tmp.add(H)",
"+ if len(tmp) == 1:",
"+ print((Cx, Cy, *list(tmp)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.11014 | 0.057266 | 1.923315 |
[
"s363668762",
"s974436067"
] |
u691018832
|
p02676
|
python
|
s866439460
|
s692601109
| 64 | 23 | 61,616 | 9,240 |
Accepted
|
Accepted
| 64.06 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
k = int(readline())
s = readline().rstrip().decode()
if len(s) <= k:
print(s)
else:
print((s[:k] + '...'))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
k = int(readline())
s = read().rstrip().decode()
if len(s) <= k:
print(s)
else:
print((s[:k] + '...'))
| 12 | 12 | 272 | 268 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
k = int(readline())
s = readline().rstrip().decode()
if len(s) <= k:
print(s)
else:
print((s[:k] + "..."))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
k = int(readline())
s = read().rstrip().decode()
if len(s) <= k:
print(s)
else:
print((s[:k] + "..."))
| false | 0 |
[
"-s = readline().rstrip().decode()",
"+s = read().rstrip().decode()"
] | false | 0.038602 | 0.034922 | 1.105372 |
[
"s866439460",
"s692601109"
] |
u753803401
|
p02912
|
python
|
s444141015
|
s156858195
| 614 | 413 | 88,576 | 69,160 |
Accepted
|
Accepted
| 32.74 |
def slove():
import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
a = list(map(int, input().rstrip('\n').split()))
for i in range(len(a)):
a[i] = a[i] * - 1
heapq.heapify(a)
for i in range(m):
p = heapq.heappop(a)
p /= 2
heapq.heappush(a, p)
t = 0
for i in range(len(a)):
t += int(a[i])
print((-t))
if __name__ == '__main__':
slove()
|
def slove():
import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
a = [- i for i in list(map(int, input().rstrip('\n').split()))]
heapq.heapify(a)
for i in range(m):
heapq.heappush(a, -(-heapq.heappop(a) // 2))
print((-sum(a)))
if __name__ == '__main__':
slove()
| 21 | 14 | 492 | 370 |
def slove():
import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip("\n").split()))
a = list(map(int, input().rstrip("\n").split()))
for i in range(len(a)):
a[i] = a[i] * -1
heapq.heapify(a)
for i in range(m):
p = heapq.heappop(a)
p /= 2
heapq.heappush(a, p)
t = 0
for i in range(len(a)):
t += int(a[i])
print((-t))
if __name__ == "__main__":
slove()
|
def slove():
import sys
import heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip("\n").split()))
a = [-i for i in list(map(int, input().rstrip("\n").split()))]
heapq.heapify(a)
for i in range(m):
heapq.heappush(a, -(-heapq.heappop(a) // 2))
print((-sum(a)))
if __name__ == "__main__":
slove()
| false | 33.333333 |
[
"- a = list(map(int, input().rstrip(\"\\n\").split()))",
"- for i in range(len(a)):",
"- a[i] = a[i] * -1",
"+ a = [-i for i in list(map(int, input().rstrip(\"\\n\").split()))]",
"- p = heapq.heappop(a)",
"- p /= 2",
"- heapq.heappush(a, p)",
"- t = 0",
"- for i in range(len(a)):",
"- t += int(a[i])",
"- print((-t))",
"+ heapq.heappush(a, -(-heapq.heappop(a) // 2))",
"+ print((-sum(a)))"
] | false | 0.046349 | 0.106512 | 0.435151 |
[
"s444141015",
"s156858195"
] |
u634046173
|
p03612
|
python
|
s760818582
|
s369783582
| 284 | 85 | 83,836 | 83,968 |
Accepted
|
Accepted
| 70.07 |
N = int(eval(input()))
P = list(map(int, input().split()))
c = 0
for i in range(N):
if P[i] == i+1:
if i != N - 1:
t = P[i]
P[i] = P[i+1]
P[i+1] = t
c += 1
else:
t = P[i]
P[i] = P[i-1]
P[i-1] = t
c += 1
print(c)
|
N = int(eval(input()))
P = list(map(int, input().split()))
c = 0
for i in range(N):
f = 1
if P[i] == i+1:
if i != N - 1:
if P[i+1] != i+1:
t = P[i]
P[i] = P[i+1]
P[i+1] = t
c += 1
else:
if P[i-1] != i+1:
t = P[i]
P[i] = P[i-1]
P[i-1] = t
c += 1
print(c)
| 16 | 19 | 336 | 442 |
N = int(eval(input()))
P = list(map(int, input().split()))
c = 0
for i in range(N):
if P[i] == i + 1:
if i != N - 1:
t = P[i]
P[i] = P[i + 1]
P[i + 1] = t
c += 1
else:
t = P[i]
P[i] = P[i - 1]
P[i - 1] = t
c += 1
print(c)
|
N = int(eval(input()))
P = list(map(int, input().split()))
c = 0
for i in range(N):
f = 1
if P[i] == i + 1:
if i != N - 1:
if P[i + 1] != i + 1:
t = P[i]
P[i] = P[i + 1]
P[i + 1] = t
c += 1
else:
if P[i - 1] != i + 1:
t = P[i]
P[i] = P[i - 1]
P[i - 1] = t
c += 1
print(c)
| false | 15.789474 |
[
"+ f = 1",
"- t = P[i]",
"- P[i] = P[i + 1]",
"- P[i + 1] = t",
"- c += 1",
"+ if P[i + 1] != i + 1:",
"+ t = P[i]",
"+ P[i] = P[i + 1]",
"+ P[i + 1] = t",
"+ c += 1",
"- t = P[i]",
"- P[i] = P[i - 1]",
"- P[i - 1] = t",
"- c += 1",
"+ if P[i - 1] != i + 1:",
"+ t = P[i]",
"+ P[i] = P[i - 1]",
"+ P[i - 1] = t",
"+ c += 1"
] | false | 0.089217 | 0.046281 | 1.927723 |
[
"s760818582",
"s369783582"
] |
u200887663
|
p02861
|
python
|
s353150737
|
s560219867
| 412 | 265 | 7,972 | 9,160 |
Accepted
|
Accepted
| 35.68 |
n=int(eval(input()))
distance=[list(map(int,input().split())) for i in range(n)]
import itertools
import math
temp=[i for i in range(n)]
perm=list(itertools.permutations(temp))
sm=0
count=0
for route in perm:
count+=1
temp_dis=0
route_list=list(route)
for i in range(1,n):
j=route_list[i]
k=route_list[i-1]
temp_dis+=math.sqrt((distance[j][0]-distance[k][0])**2+(distance[j][1]-distance[k][1])**2)
sm+=temp_dis
ans=sm/count
print(('{:.9f}'.format(ans)))
|
import math
import itertools
n = int(eval(input()))
#n, m = map(int, input().split())
#hl = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
total = 0
townnum = [i for i in range(n)]
for v in itertools.permutations(townnum):
for j in range(1, n):
cur = l[v[j]]
bef = l[v[j-1]]
total += math.sqrt((cur[0]-bef[0])**2+(cur[1]-bef[1])**2)
ans = total/math.factorial(n)
print(('{:.9f}'.format(ans)))
| 21 | 15 | 512 | 467 |
n = int(eval(input()))
distance = [list(map(int, input().split())) for i in range(n)]
import itertools
import math
temp = [i for i in range(n)]
perm = list(itertools.permutations(temp))
sm = 0
count = 0
for route in perm:
count += 1
temp_dis = 0
route_list = list(route)
for i in range(1, n):
j = route_list[i]
k = route_list[i - 1]
temp_dis += math.sqrt(
(distance[j][0] - distance[k][0]) ** 2
+ (distance[j][1] - distance[k][1]) ** 2
)
sm += temp_dis
ans = sm / count
print(("{:.9f}".format(ans)))
|
import math
import itertools
n = int(eval(input()))
# n, m = map(int, input().split())
# hl = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
total = 0
townnum = [i for i in range(n)]
for v in itertools.permutations(townnum):
for j in range(1, n):
cur = l[v[j]]
bef = l[v[j - 1]]
total += math.sqrt((cur[0] - bef[0]) ** 2 + (cur[1] - bef[1]) ** 2)
ans = total / math.factorial(n)
print(("{:.9f}".format(ans)))
| false | 28.571429 |
[
"+import math",
"+import itertools",
"+",
"-distance = [list(map(int, input().split())) for i in range(n)]",
"-import itertools",
"-import math",
"-",
"-temp = [i for i in range(n)]",
"-perm = list(itertools.permutations(temp))",
"-sm = 0",
"-count = 0",
"-for route in perm:",
"- count += 1",
"- temp_dis = 0",
"- route_list = list(route)",
"- for i in range(1, n):",
"- j = route_list[i]",
"- k = route_list[i - 1]",
"- temp_dis += math.sqrt(",
"- (distance[j][0] - distance[k][0]) ** 2",
"- + (distance[j][1] - distance[k][1]) ** 2",
"- )",
"- sm += temp_dis",
"-ans = sm / count",
"+# n, m = map(int, input().split())",
"+# hl = list(map(int, input().split()))",
"+l = [list(map(int, input().split())) for i in range(n)]",
"+total = 0",
"+townnum = [i for i in range(n)]",
"+for v in itertools.permutations(townnum):",
"+ for j in range(1, n):",
"+ cur = l[v[j]]",
"+ bef = l[v[j - 1]]",
"+ total += math.sqrt((cur[0] - bef[0]) ** 2 + (cur[1] - bef[1]) ** 2)",
"+ans = total / math.factorial(n)"
] | false | 0.044662 | 0.042984 | 1.03902 |
[
"s353150737",
"s560219867"
] |
u254871849
|
p02972
|
python
|
s517431164
|
s582107751
| 304 | 224 | 8,336 | 13,220 |
Accepted
|
Accepted
| 26.32 |
# 2019-11-15 14:12:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# from scipy.misc import comb # float
# import numpy as np
def main():
n, *a = [int(x) for x in sys.stdin.read().split()]
a = [None] + a
in_or_not = [0 for _ in range(n+1)]
for i in range(n, 0, -1):
count = sum(in_or_not[2*i:n+1:i])
in_or_not[i] = a[i] ^ count % 2
print(in_or_not.count(1))
for i in range(1, n+1):
if in_or_not[i] == 1:
print(i, end=' ')
if __name__ == "__main__":
main()
|
import sys
n, *a = map(int, sys.stdin.read().split())
a = [None] + a
def main():
res = [0] * (n + 1)
chosen = []
for i in range(n, 0, -1):
tmp = sum(res[i*2:n+1:i]) & 1
if tmp ^ a[i]:
res[i] = 1
chosen.append(i)
if chosen:
m = len(chosen)
return [m], chosen[::-1]
else:
return [[0]]
if __name__ == '__main__':
ans = main()
for a in ans:
print(*a, sep=' ')
| 30 | 24 | 778 | 482 |
# 2019-11-15 14:12:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# from scipy.misc import comb # float
# import numpy as np
def main():
n, *a = [int(x) for x in sys.stdin.read().split()]
a = [None] + a
in_or_not = [0 for _ in range(n + 1)]
for i in range(n, 0, -1):
count = sum(in_or_not[2 * i : n + 1 : i])
in_or_not[i] = a[i] ^ count % 2
print(in_or_not.count(1))
for i in range(1, n + 1):
if in_or_not[i] == 1:
print(i, end=" ")
if __name__ == "__main__":
main()
|
import sys
n, *a = map(int, sys.stdin.read().split())
a = [None] + a
def main():
res = [0] * (n + 1)
chosen = []
for i in range(n, 0, -1):
tmp = sum(res[i * 2 : n + 1 : i]) & 1
if tmp ^ a[i]:
res[i] = 1
chosen.append(i)
if chosen:
m = len(chosen)
return [m], chosen[::-1]
else:
return [[0]]
if __name__ == "__main__":
ans = main()
for a in ans:
print(*a, sep=" ")
| false | 20 |
[
"-# 2019-11-15 14:12:24(JST)",
"-# import collections",
"-# import math",
"-# from string import ascii_lowercase, ascii_uppercase, digits",
"-# from bisect import bisect_left as bi_l, bisect_right as bi_r",
"-# import itertools",
"-# from functools import reduce",
"-# import operator as op",
"-# import re",
"-# from scipy.misc import comb # float",
"-# import numpy as np",
"+n, *a = map(int, sys.stdin.read().split())",
"+a = [None] + a",
"+",
"+",
"- n, *a = [int(x) for x in sys.stdin.read().split()]",
"- a = [None] + a",
"- in_or_not = [0 for _ in range(n + 1)]",
"+ res = [0] * (n + 1)",
"+ chosen = []",
"- count = sum(in_or_not[2 * i : n + 1 : i])",
"- in_or_not[i] = a[i] ^ count % 2",
"- print(in_or_not.count(1))",
"- for i in range(1, n + 1):",
"- if in_or_not[i] == 1:",
"- print(i, end=\" \")",
"+ tmp = sum(res[i * 2 : n + 1 : i]) & 1",
"+ if tmp ^ a[i]:",
"+ res[i] = 1",
"+ chosen.append(i)",
"+ if chosen:",
"+ m = len(chosen)",
"+ return [m], chosen[::-1]",
"+ else:",
"+ return [[0]]",
"- main()",
"+ ans = main()",
"+ for a in ans:",
"+ print(*a, sep=\" \")"
] | false | 0.036631 | 0.218906 | 0.167337 |
[
"s517431164",
"s582107751"
] |
u276204978
|
p03821
|
python
|
s951428501
|
s085578192
| 926 | 773 | 14,072 | 14,168 |
Accepted
|
Accepted
| 16.52 |
import numpy as np
N = int(eval(input()))
A = np.zeros(N).astype(int)
B = np.zeros(N).astype(int)
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
ans = 0
for i in reversed(list(range(N))):
A[i] = A[i] + ans
if A[i] % B[i] == 0:
continue
elif B[i] - A[i] > 0:
ans += B[i] - A[i]
else:
ans += B[i] - (A[i] % B[i])
print(ans)
|
import numpy as np
N = int(eval(input()))
A = np.zeros(N).astype(int)
B = np.zeros(N).astype(int)
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
ans = 0
for i in reversed(list(range(N))):
A[i] = A[i] + ans
if A[i] % B[i] == 0:
continue
else:
ans += B[i] - (A[i] % B[i])
print(ans)
| 20 | 18 | 391 | 336 |
import numpy as np
N = int(eval(input()))
A = np.zeros(N).astype(int)
B = np.zeros(N).astype(int)
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
ans = 0
for i in reversed(list(range(N))):
A[i] = A[i] + ans
if A[i] % B[i] == 0:
continue
elif B[i] - A[i] > 0:
ans += B[i] - A[i]
else:
ans += B[i] - (A[i] % B[i])
print(ans)
|
import numpy as np
N = int(eval(input()))
A = np.zeros(N).astype(int)
B = np.zeros(N).astype(int)
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
ans = 0
for i in reversed(list(range(N))):
A[i] = A[i] + ans
if A[i] % B[i] == 0:
continue
else:
ans += B[i] - (A[i] % B[i])
print(ans)
| false | 10 |
[
"- elif B[i] - A[i] > 0:",
"- ans += B[i] - A[i]"
] | false | 0.57466 | 0.272453 | 2.10921 |
[
"s951428501",
"s085578192"
] |
u163783894
|
p02621
|
python
|
s202437641
|
s827114826
| 1,104 | 698 | 12,692 | 9,044 |
Accepted
|
Accepted
| 36.78 |
N = 10**7
M = 10**5
arr = list(range(M))
for i in range(N):
t = arr[i % M]
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
N = 10**7
arr = [0]
for i in range(N):
t = arr[0]
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
| 10 | 9 | 135 | 109 |
N = 10**7
M = 10**5
arr = list(range(M))
for i in range(N):
t = arr[i % M]
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
|
N = 10**7
arr = [0]
for i in range(N):
t = arr[0]
# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
| false | 10 |
[
"-M = 10**5",
"-arr = list(range(M))",
"+arr = [0]",
"- t = arr[i % M]",
"+ t = arr[0]"
] | false | 1.651937 | 1.480967 | 1.115445 |
[
"s202437641",
"s827114826"
] |
u622045059
|
p03545
|
python
|
s869188142
|
s729608277
| 171 | 38 | 38,384 | 5,300 |
Accepted
|
Accepted
| 77.78 |
ABCD = eval(input())
ops = ['+', '-']
for i in range(2**3):
ans = int(ABCD[0])
op = []
for j in range(3):
if ops[i % 2] == '+':
ans += int(ABCD[j+1])
else:
ans -= int(ABCD[j+1])
op.append(ops[i%2])
i //= 2
if ans == 7:
print((ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3] + '=7'))
break
|
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(eval(input())) #整数読み込み
def ifn(): return float(eval(input())) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return list(map(int, input().split())) #整数map取得
def fmn(): return list(map(float, input().split())) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
ABCD = eval(input())
for i in range(2**3):
total = int(ABCD[0])
op = []
tmp = i
for j in range(3):
if tmp & 1 == 1:
op.append('+')
total += int(ABCD[j+1])
else:
op.append('-')
total -= int(ABCD[j+1])
tmp = tmp >> 1
if total == 7:
print((ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] +ABCD[3] + '=7'))
break
| 22 | 48 | 422 | 1,690 |
ABCD = eval(input())
ops = ["+", "-"]
for i in range(2**3):
ans = int(ABCD[0])
op = []
for j in range(3):
if ops[i % 2] == "+":
ans += int(ABCD[j + 1])
else:
ans -= int(ABCD[j + 1])
op.append(ops[i % 2])
i //= 2
if ans == 7:
print((ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3] + "=7"))
break
|
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7
def gcd(a, b):
return fractions.gcd(a, b) # 最大公約数
def lcm(a, b):
return (a * b) // fractions.gcd(a, b) # 最小公倍数
def iin():
return int(eval(input())) # 整数読み込み
def ifn():
return float(eval(input())) # 浮動小数点読み込み
def isn():
return input().split() # 文字列読み込み
def imn():
return list(map(int, input().split())) # 整数map取得
def fmn():
return list(map(float, input().split())) # 浮動小数点map取得
def iln():
return list(map(int, input().split())) # 整数リスト取得
def iln_s():
return sorted(iln()) # 昇順の整数リスト取得
def iln_r():
return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln():
return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=""):
return s.join(l) # リストを文字列に変換
def perm(l, n):
return itertools.permutations(l, n) # 順列取得
def perm_count(n, r):
return math.factorial(n) // math.factorial(n - r) # 順列の総数
def comb(l, n):
return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数
def two_distance(a, b, c, d):
return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離
def m_add(a, b):
return (a + b) % MOD
ABCD = eval(input())
for i in range(2**3):
total = int(ABCD[0])
op = []
tmp = i
for j in range(3):
if tmp & 1 == 1:
op.append("+")
total += int(ABCD[j + 1])
else:
op.append("-")
total -= int(ABCD[j + 1])
tmp = tmp >> 1
if total == 7:
print((ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3] + "=7"))
break
| false | 54.166667 |
[
"+import math",
"+import fractions",
"+import bisect",
"+import collections",
"+import itertools",
"+import heapq",
"+import string",
"+import sys",
"+import copy",
"+from collections import deque",
"+",
"+sys.setrecursionlimit(10**7)",
"+MOD = 10**9 + 7",
"+",
"+",
"+def gcd(a, b):",
"+ return fractions.gcd(a, b) # 最大公約数",
"+",
"+",
"+def lcm(a, b):",
"+ return (a * b) // fractions.gcd(a, b) # 最小公倍数",
"+",
"+",
"+def iin():",
"+ return int(eval(input())) # 整数読み込み",
"+",
"+",
"+def ifn():",
"+ return float(eval(input())) # 浮動小数点読み込み",
"+",
"+",
"+def isn():",
"+ return input().split() # 文字列読み込み",
"+",
"+",
"+def imn():",
"+ return list(map(int, input().split())) # 整数map取得",
"+",
"+",
"+def fmn():",
"+ return list(map(float, input().split())) # 浮動小数点map取得",
"+",
"+",
"+def iln():",
"+ return list(map(int, input().split())) # 整数リスト取得",
"+",
"+",
"+def iln_s():",
"+ return sorted(iln()) # 昇順の整数リスト取得",
"+",
"+",
"+def iln_r():",
"+ return sorted(iln(), reverse=True) # 降順の整数リスト取得",
"+",
"+",
"+def fln():",
"+ return list(map(float, input().split())) # 浮動小数点リスト取得",
"+",
"+",
"+def join(l, s=\"\"):",
"+ return s.join(l) # リストを文字列に変換",
"+",
"+",
"+def perm(l, n):",
"+ return itertools.permutations(l, n) # 順列取得",
"+",
"+",
"+def perm_count(n, r):",
"+ return math.factorial(n) // math.factorial(n - r) # 順列の総数",
"+",
"+",
"+def comb(l, n):",
"+ return itertools.combinations(l, n) # 組み合わせ取得",
"+",
"+",
"+def comb_count(n, r):",
"+ return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) # 組み合わせの総数",
"+",
"+",
"+def two_distance(a, b, c, d):",
"+ return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離",
"+",
"+",
"+def m_add(a, b):",
"+ return (a + b) % MOD",
"+",
"+",
"-ops = [\"+\", \"-\"]",
"- ans = int(ABCD[0])",
"+ total = int(ABCD[0])",
"+ tmp = i",
"- if ops[i % 2] == \"+\":",
"- ans += int(ABCD[j + 1])",
"+ if tmp & 1 == 1:",
"+ op.append(\"+\")",
"+ total += int(ABCD[j + 1])",
"- ans -= int(ABCD[j + 1])",
"- op.append(ops[i % 2])",
"- i //= 2",
"- if ans == 7:",
"+ op.append(\"-\")",
"+ total -= int(ABCD[j + 1])",
"+ tmp = tmp >> 1",
"+ if total == 7:"
] | false | 0.059017 | 0.053359 | 1.106032 |
[
"s869188142",
"s729608277"
] |
u530383736
|
p03814
|
python
|
s380980947
|
s268013678
| 60 | 38 | 3,516 | 3,516 |
Accepted
|
Accepted
| 36.67 |
# -*- coding: utf-8 -*-
s = input().strip()
#----------
loc_A=len(s)+1
loc_Z=-1
for i in range(len(s)):
if s[i] == "Z" and loc_Z < i:
loc_Z = i
elif s[i] == "A" and i < loc_A:
loc_A = i
print(( loc_Z - (loc_A - 1) ))
|
# -*- coding: utf-8 -*-
s=input().strip()
for i,word in enumerate(s):
if word == "A":
start = i
break
for i,word in enumerate( reversed(s) ):
if word == "Z":
end = len(s)-1-i
break
print(( end-start+1 ))
| 14 | 15 | 255 | 260 |
# -*- coding: utf-8 -*-
s = input().strip()
# ----------
loc_A = len(s) + 1
loc_Z = -1
for i in range(len(s)):
if s[i] == "Z" and loc_Z < i:
loc_Z = i
elif s[i] == "A" and i < loc_A:
loc_A = i
print((loc_Z - (loc_A - 1)))
|
# -*- coding: utf-8 -*-
s = input().strip()
for i, word in enumerate(s):
if word == "A":
start = i
break
for i, word in enumerate(reversed(s)):
if word == "Z":
end = len(s) - 1 - i
break
print((end - start + 1))
| false | 6.666667 |
[
"-loc_A = len(s) + 1",
"-loc_Z = -1",
"-for i in range(len(s)):",
"- if s[i] == \"Z\" and loc_Z < i:",
"- loc_Z = i",
"- elif s[i] == \"A\" and i < loc_A:",
"- loc_A = i",
"-print((loc_Z - (loc_A - 1)))",
"+for i, word in enumerate(s):",
"+ if word == \"A\":",
"+ start = i",
"+ break",
"+for i, word in enumerate(reversed(s)):",
"+ if word == \"Z\":",
"+ end = len(s) - 1 - i",
"+ break",
"+print((end - start + 1))"
] | false | 0.111706 | 0.04547 | 2.456689 |
[
"s380980947",
"s268013678"
] |
u723345499
|
p02641
|
python
|
s669488487
|
s470970201
| 22 | 20 | 9,060 | 9,200 |
Accepted
|
Accepted
| 9.09 |
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(200):
if x - i not in p:
print((x - i))
break
if x + i not in p:
print((x + i))
break
|
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(101):
if x - i not in p:
print((x - i))
break
if x + i not in p:
print((x + i))
break
| 11 | 11 | 217 | 217 |
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(200):
if x - i not in p:
print((x - i))
break
if x + i not in p:
print((x + i))
break
|
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(101):
if x - i not in p:
print((x - i))
break
if x + i not in p:
print((x + i))
break
| false | 0 |
[
"-for i in range(200):",
"+for i in range(101):"
] | false | 0.032701 | 0.041583 | 0.786399 |
[
"s669488487",
"s470970201"
] |
u673361376
|
p03401
|
python
|
s845595727
|
s746641011
| 226 | 188 | 14,048 | 13,920 |
Accepted
|
Accepted
| 16.81 |
n = int(eval(input()))
alist = [0] + list(map(int, input().split()))
total = 0
for i in range(n):total += abs(alist[i]-alist[i+1])
total += abs(alist[-1])
for i in range(1,n):
print((total-abs(alist[i]-alist[i-1])-abs(alist[i+1]-alist[i])+ abs(alist[i+1]-alist[i-1])))
print((total-abs(alist[-1]-alist[-2])-abs(alist[-1]-alist[0])+abs(alist[-2]-alist[0])))
|
N = int(eval(input()))
A = [0] + list(map(int, input().split())) + [0]
costs = [0] + [abs(A[i] - A[i+1]) for i in range(N+1)]
sum_costs = sum(costs)
for i in range(1, N+1):
print((sum_costs - costs[i] - costs[i+1] + abs(A[i-1] - A[i+1])))
| 9 | 7 | 357 | 242 |
n = int(eval(input()))
alist = [0] + list(map(int, input().split()))
total = 0
for i in range(n):
total += abs(alist[i] - alist[i + 1])
total += abs(alist[-1])
for i in range(1, n):
print(
(
total
- abs(alist[i] - alist[i - 1])
- abs(alist[i + 1] - alist[i])
+ abs(alist[i + 1] - alist[i - 1])
)
)
print(
(
total
- abs(alist[-1] - alist[-2])
- abs(alist[-1] - alist[0])
+ abs(alist[-2] - alist[0])
)
)
|
N = int(eval(input()))
A = [0] + list(map(int, input().split())) + [0]
costs = [0] + [abs(A[i] - A[i + 1]) for i in range(N + 1)]
sum_costs = sum(costs)
for i in range(1, N + 1):
print((sum_costs - costs[i] - costs[i + 1] + abs(A[i - 1] - A[i + 1])))
| false | 22.222222 |
[
"-n = int(eval(input()))",
"-alist = [0] + list(map(int, input().split()))",
"-total = 0",
"-for i in range(n):",
"- total += abs(alist[i] - alist[i + 1])",
"-total += abs(alist[-1])",
"-for i in range(1, n):",
"- print(",
"- (",
"- total",
"- - abs(alist[i] - alist[i - 1])",
"- - abs(alist[i + 1] - alist[i])",
"- + abs(alist[i + 1] - alist[i - 1])",
"- )",
"- )",
"-print(",
"- (",
"- total",
"- - abs(alist[-1] - alist[-2])",
"- - abs(alist[-1] - alist[0])",
"- + abs(alist[-2] - alist[0])",
"- )",
"-)",
"+N = int(eval(input()))",
"+A = [0] + list(map(int, input().split())) + [0]",
"+costs = [0] + [abs(A[i] - A[i + 1]) for i in range(N + 1)]",
"+sum_costs = sum(costs)",
"+for i in range(1, N + 1):",
"+ print((sum_costs - costs[i] - costs[i + 1] + abs(A[i - 1] - A[i + 1])))"
] | false | 0.04012 | 0.060159 | 0.666887 |
[
"s845595727",
"s746641011"
] |
u965346773
|
p03262
|
python
|
s233643613
|
s205516169
| 344 | 120 | 14,444 | 16,280 |
Accepted
|
Accepted
| 65.12 |
N, X = list(map(int,input().split()))
x = list([abs(int(y)-X) for y in input().split()])
m = min(x)
def prim(y):
p=[]
while y>1:
for i in range(2,y+1):
if y%i==0:
y//=i
p.append(i)
break
return p
ans=1
for i in prim(m):
if m%i !=0:
continue
if set([j%i for j in x]) == {0}:
ans *= i
x = [j//i for j in x]
if set([j%(m//i) for j in x]) == {0}:
ans *= (m//i)
x = [j//(m//i) for j in x]
print(ans)
|
import fractions
N, X = list(map(int,input().split()))
x = list([abs(int(y)-X) for y in input().split()])
m = min(x)
ans = x[0]
for i in range(1,N):
ans = fractions.gcd(ans,x[i])
print(ans)
| 27 | 10 | 557 | 206 |
N, X = list(map(int, input().split()))
x = list([abs(int(y) - X) for y in input().split()])
m = min(x)
def prim(y):
p = []
while y > 1:
for i in range(2, y + 1):
if y % i == 0:
y //= i
p.append(i)
break
return p
ans = 1
for i in prim(m):
if m % i != 0:
continue
if set([j % i for j in x]) == {0}:
ans *= i
x = [j // i for j in x]
if set([j % (m // i) for j in x]) == {0}:
ans *= m // i
x = [j // (m // i) for j in x]
print(ans)
|
import fractions
N, X = list(map(int, input().split()))
x = list([abs(int(y) - X) for y in input().split()])
m = min(x)
ans = x[0]
for i in range(1, N):
ans = fractions.gcd(ans, x[i])
print(ans)
| false | 62.962963 |
[
"+import fractions",
"+",
"-",
"-",
"-def prim(y):",
"- p = []",
"- while y > 1:",
"- for i in range(2, y + 1):",
"- if y % i == 0:",
"- y //= i",
"- p.append(i)",
"- break",
"- return p",
"-",
"-",
"-ans = 1",
"-for i in prim(m):",
"- if m % i != 0:",
"- continue",
"- if set([j % i for j in x]) == {0}:",
"- ans *= i",
"- x = [j // i for j in x]",
"- if set([j % (m // i) for j in x]) == {0}:",
"- ans *= m // i",
"- x = [j // (m // i) for j in x]",
"+ans = x[0]",
"+for i in range(1, N):",
"+ ans = fractions.gcd(ans, x[i])"
] | false | 0.057479 | 0.046246 | 1.242909 |
[
"s233643613",
"s205516169"
] |
u145035045
|
p03312
|
python
|
s839146608
|
s037020713
| 1,724 | 1,437 | 26,996 | 26,996 |
Accepted
|
Accepted
| 16.65 |
from bisect import bisect_left as bl
from itertools import accumulate
INF = 10 ** 20
def get_score(acc, head, end):
sec_head = acc[head - 1]
sec_end = acc[end]
sec_sum = sec_end - sec_head
cut = bl(acc, sec_head + sec_sum // 2) - 1
score = INF
reta, retb = None, None
for i in range(cut - 2, cut + 3):
if head <= i < end:
a = acc[i] - sec_head
b = sec_end - acc[i]
if score > abs(a - b):
score = abs(a - b)
reta, retb = a, b
return (reta, retb)
n = int(eval(input()))
acc = [0]
acc += accumulate(list(map(int, input().split())))
ans = INF
for i in range(2, n - 1):
p, q = get_score(acc, 1, i)
r, s = get_score(acc, i + 1, n)
if not None in (p, q, r, s):
ans = min(ans, max(p, q, r, s) - min(p, q, r, s))
print(ans)
|
from bisect import bisect_left as bl
from itertools import accumulate
INF = 10 ** 20
def get_score(acc, head, end):
sec_head = acc[head - 1]
sec_end = acc[end]
sec_sum = sec_end - sec_head
cut = bl(acc, sec_head + sec_sum // 2) - 1
score = INF
reta, retb = None, None
for i in range(cut - 1, cut + 2):
if head <= i < end:
a = acc[i] - sec_head
b = sec_end - acc[i]
if score > abs(a - b):
score = abs(a - b)
reta, retb = a, b
return (reta, retb)
n = int(eval(input()))
acc = [0]
acc += accumulate(list(map(int, input().split())))
ans = INF
for i in range(2, n - 1):
p, q = get_score(acc, 1, i)
r, s = get_score(acc, i + 1, n)
if not None in (p, q, r, s):
ans = min(ans, max(p, q, r, s) - min(p, q, r, s))
print(ans)
| 31 | 31 | 800 | 800 |
from bisect import bisect_left as bl
from itertools import accumulate
INF = 10**20
def get_score(acc, head, end):
sec_head = acc[head - 1]
sec_end = acc[end]
sec_sum = sec_end - sec_head
cut = bl(acc, sec_head + sec_sum // 2) - 1
score = INF
reta, retb = None, None
for i in range(cut - 2, cut + 3):
if head <= i < end:
a = acc[i] - sec_head
b = sec_end - acc[i]
if score > abs(a - b):
score = abs(a - b)
reta, retb = a, b
return (reta, retb)
n = int(eval(input()))
acc = [0]
acc += accumulate(list(map(int, input().split())))
ans = INF
for i in range(2, n - 1):
p, q = get_score(acc, 1, i)
r, s = get_score(acc, i + 1, n)
if not None in (p, q, r, s):
ans = min(ans, max(p, q, r, s) - min(p, q, r, s))
print(ans)
|
from bisect import bisect_left as bl
from itertools import accumulate
INF = 10**20
def get_score(acc, head, end):
sec_head = acc[head - 1]
sec_end = acc[end]
sec_sum = sec_end - sec_head
cut = bl(acc, sec_head + sec_sum // 2) - 1
score = INF
reta, retb = None, None
for i in range(cut - 1, cut + 2):
if head <= i < end:
a = acc[i] - sec_head
b = sec_end - acc[i]
if score > abs(a - b):
score = abs(a - b)
reta, retb = a, b
return (reta, retb)
n = int(eval(input()))
acc = [0]
acc += accumulate(list(map(int, input().split())))
ans = INF
for i in range(2, n - 1):
p, q = get_score(acc, 1, i)
r, s = get_score(acc, i + 1, n)
if not None in (p, q, r, s):
ans = min(ans, max(p, q, r, s) - min(p, q, r, s))
print(ans)
| false | 0 |
[
"- for i in range(cut - 2, cut + 3):",
"+ for i in range(cut - 1, cut + 2):"
] | false | 0.037546 | 0.037309 | 1.006344 |
[
"s839146608",
"s037020713"
] |
u562935282
|
p03053
|
python
|
s893379096
|
s462829813
| 687 | 590 | 135,900 | 89,180 |
Accepted
|
Accepted
| 14.12 |
from collections import deque
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
bl = [[False] * W for _ in range(H)]
dq = deque()
for r in range(H):
for c in range(W):
if a[r][c] == '#':
bl[r][c] = True
dq.append((r, c, 0))
def in_range(r, c):
return 0 <= r < H and 0 <= c < W
dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)
while dq:
r, c, d = dq.popleft()
for dr, dc in zip(dr_s, dc_s):
nr = r + dr
nc = c + dc
if not in_range(nr, nc): continue
if bl[nr][nc]: continue
bl[nr][nc] = True
dq.append((nr, nc, d + 1))
print(d)
|
import sys
input = sys.stdin.readline
from collections import deque
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
dq = deque()
for r in range(H):
for c in range(W):
if a[r][c] == '#':
dist[r][c] = 0
dq.append((r, c))
def in_range(r, c):
return 0 <= r < H and 0 <= c < W
dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)
d = 0
while dq:
r, c = dq.popleft()
d = dist[r][c]
for dr, dc in zip(dr_s, dc_s):
nr = r + dr
nc = c + dc
if not in_range(nr, nc): continue
if dist[nr][nc] != -1: continue
dist[nr][nc] = d + 1
dq.append((nr, nc))
print(d)
| 33 | 39 | 671 | 738 |
from collections import deque
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
bl = [[False] * W for _ in range(H)]
dq = deque()
for r in range(H):
for c in range(W):
if a[r][c] == "#":
bl[r][c] = True
dq.append((r, c, 0))
def in_range(r, c):
return 0 <= r < H and 0 <= c < W
dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)
while dq:
r, c, d = dq.popleft()
for dr, dc in zip(dr_s, dc_s):
nr = r + dr
nc = c + dc
if not in_range(nr, nc):
continue
if bl[nr][nc]:
continue
bl[nr][nc] = True
dq.append((nr, nc, d + 1))
print(d)
|
import sys
input = sys.stdin.readline
from collections import deque
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
dq = deque()
for r in range(H):
for c in range(W):
if a[r][c] == "#":
dist[r][c] = 0
dq.append((r, c))
def in_range(r, c):
return 0 <= r < H and 0 <= c < W
dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)
d = 0
while dq:
r, c = dq.popleft()
d = dist[r][c]
for dr, dc in zip(dr_s, dc_s):
nr = r + dr
nc = c + dc
if not in_range(nr, nc):
continue
if dist[nr][nc] != -1:
continue
dist[nr][nc] = d + 1
dq.append((nr, nc))
print(d)
| false | 15.384615 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"-bl = [[False] * W for _ in range(H)]",
"+dist = [[-1] * W for _ in range(H)]",
"- bl[r][c] = True",
"- dq.append((r, c, 0))",
"+ dist[r][c] = 0",
"+ dq.append((r, c))",
"+d = 0",
"- r, c, d = dq.popleft()",
"+ r, c = dq.popleft()",
"+ d = dist[r][c]",
"- if bl[nr][nc]:",
"+ if dist[nr][nc] != -1:",
"- bl[nr][nc] = True",
"- dq.append((nr, nc, d + 1))",
"+ dist[nr][nc] = d + 1",
"+ dq.append((nr, nc))"
] | false | 0.040956 | 0.041853 | 0.978574 |
[
"s893379096",
"s462829813"
] |
u155687575
|
p03565
|
python
|
s984184428
|
s309633922
| 168 | 17 | 38,768 | 3,064 |
Accepted
|
Accepted
| 89.88 |
s_ = eval(input())
t = eval(input())
exit_flag = True
for i in range(len(s_) - len(t) + 1):
flag = True
for j in range(len(t)):
if (s_[i+j] != '?') and (s_[i+j] != t[j]):
flag = False
if flag:
h = ''
for index in range(len(s_)):
if (i <= index <= i + len(t) -1):
h += t[index - i]
else:
h += s_[index]
exit_flag = False
if exit_flag:
print('UNRESTORABLE')
exit()
h = h.replace('?', 'a')
print(h)
|
# C
sd = eval(input())
scnt = len(sd)
t = eval(input())
tcnt = len(t)
point = 0
unrestorable = True
while point <= scnt - tcnt:
oneroopcorres = True
for i in range(tcnt):
anyone = sd[point+i] == '?'
correspond = sd[point+i] == t[i]
if not (anyone or correspond):
oneroopcorres = False
if oneroopcorres:
unrestorable = False
good_point = point
point += 1
if unrestorable:
print('UNRESTORABLE')
exit()
else:
sd = list(sd)
for i in range(tcnt):
sd[good_point + i] = t[i]
sd = ''.join(sd)
sd = sd.replace('?', 'a')
print(sd)
| 25 | 33 | 536 | 641 |
s_ = eval(input())
t = eval(input())
exit_flag = True
for i in range(len(s_) - len(t) + 1):
flag = True
for j in range(len(t)):
if (s_[i + j] != "?") and (s_[i + j] != t[j]):
flag = False
if flag:
h = ""
for index in range(len(s_)):
if i <= index <= i + len(t) - 1:
h += t[index - i]
else:
h += s_[index]
exit_flag = False
if exit_flag:
print("UNRESTORABLE")
exit()
h = h.replace("?", "a")
print(h)
|
# C
sd = eval(input())
scnt = len(sd)
t = eval(input())
tcnt = len(t)
point = 0
unrestorable = True
while point <= scnt - tcnt:
oneroopcorres = True
for i in range(tcnt):
anyone = sd[point + i] == "?"
correspond = sd[point + i] == t[i]
if not (anyone or correspond):
oneroopcorres = False
if oneroopcorres:
unrestorable = False
good_point = point
point += 1
if unrestorable:
print("UNRESTORABLE")
exit()
else:
sd = list(sd)
for i in range(tcnt):
sd[good_point + i] = t[i]
sd = "".join(sd)
sd = sd.replace("?", "a")
print(sd)
| false | 24.242424 |
[
"-s_ = eval(input())",
"+# C",
"+sd = eval(input())",
"+scnt = len(sd)",
"-exit_flag = True",
"-for i in range(len(s_) - len(t) + 1):",
"- flag = True",
"- for j in range(len(t)):",
"- if (s_[i + j] != \"?\") and (s_[i + j] != t[j]):",
"- flag = False",
"- if flag:",
"- h = \"\"",
"- for index in range(len(s_)):",
"- if i <= index <= i + len(t) - 1:",
"- h += t[index - i]",
"- else:",
"- h += s_[index]",
"- exit_flag = False",
"-if exit_flag:",
"+tcnt = len(t)",
"+point = 0",
"+unrestorable = True",
"+while point <= scnt - tcnt:",
"+ oneroopcorres = True",
"+ for i in range(tcnt):",
"+ anyone = sd[point + i] == \"?\"",
"+ correspond = sd[point + i] == t[i]",
"+ if not (anyone or correspond):",
"+ oneroopcorres = False",
"+ if oneroopcorres:",
"+ unrestorable = False",
"+ good_point = point",
"+ point += 1",
"+if unrestorable:",
"-h = h.replace(\"?\", \"a\")",
"-print(h)",
"+else:",
"+ sd = list(sd)",
"+ for i in range(tcnt):",
"+ sd[good_point + i] = t[i]",
"+ sd = \"\".join(sd)",
"+sd = sd.replace(\"?\", \"a\")",
"+print(sd)"
] | false | 0.043612 | 0.039105 | 1.115253 |
[
"s984184428",
"s309633922"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.