user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u190405389 | p02580 | python | s793122184 | s661514268 | 836 | 448 | 213,984 | 206,828 | Accepted | Accepted | 46.41 | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print(('\n'.join(map(str,x))))
def printline(x):print((' '.join(map(str,x))))
import bisect
from operator import itemgetter
h,w,m = readints()
r = [0]*h
c = [0]*w
p = [readints() for i in range(m)]
p.sort(key=itemgetter(1))
d = [[] for i in range(h)]
for i in range(m):
a,b = (x-1 for x in p[i])
r[a] += 1
c[b] += 1
d[a].append(b)
mr = max(r)
mc = max(c)
R = [i for i,x in enumerate(r) if x==mr]
C = [i for i,x in enumerate(c) if x==mc]
flag = 1
if len(R)*len(C)>m:
flag = 0
else:
for x in R:
for y in C:
z = bisect.bisect_left(d[x],y)
if z>=len(d[x]):
flag = 0
break
else:
if y != d[x][z]:
flag = 0
break
print((max(r)+max(c)-flag))
| import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print(('\n'.join(map(str,x))))
def printline(x):print((' '.join(map(str,x))))
h,w,m = readints()
r = [0]*h
c = [0]*w
d = [set() for i in range(h)]
for i in range(m):
a,b = (x-1 for x in readints())
r[a] += 1
c[b] += 1
d[a].add(b)
mr = max(r)
mc = max(c)
R = [i for i,x in enumerate(r) if x==mr]
C = [i for i,x in enumerate(c) if x==mc]
flag = 1
if len(R)*len(C)>m:
flag = 0
else:
for x in R:
for y in C:
if y not in d[x]:
flag = 0
break
print((max(r)+max(c)-flag))
| 54 | 43 | 1,143 | 881 | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():
return readline().rstrip().decode()
def readstrs():
return list(readline().decode().split())
def readint():
return int(readline())
def readints():
return list(map(int, readline().split()))
def printrows(x):
print(("\n".join(map(str, x))))
def printline(x):
print((" ".join(map(str, x))))
import bisect
from operator import itemgetter
h, w, m = readints()
r = [0] * h
c = [0] * w
p = [readints() for i in range(m)]
p.sort(key=itemgetter(1))
d = [[] for i in range(h)]
for i in range(m):
a, b = (x - 1 for x in p[i])
r[a] += 1
c[b] += 1
d[a].append(b)
mr = max(r)
mc = max(c)
R = [i for i, x in enumerate(r) if x == mr]
C = [i for i, x in enumerate(c) if x == mc]
flag = 1
if len(R) * len(C) > m:
flag = 0
else:
for x in R:
for y in C:
z = bisect.bisect_left(d[x], y)
if z >= len(d[x]):
flag = 0
break
else:
if y != d[x][z]:
flag = 0
break
print((max(r) + max(c) - flag))
| import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():
return readline().rstrip().decode()
def readstrs():
return list(readline().decode().split())
def readint():
return int(readline())
def readints():
return list(map(int, readline().split()))
def printrows(x):
print(("\n".join(map(str, x))))
def printline(x):
print((" ".join(map(str, x))))
h, w, m = readints()
r = [0] * h
c = [0] * w
d = [set() for i in range(h)]
for i in range(m):
a, b = (x - 1 for x in readints())
r[a] += 1
c[b] += 1
d[a].add(b)
mr = max(r)
mc = max(c)
R = [i for i, x in enumerate(r) if x == mr]
C = [i for i, x in enumerate(c) if x == mc]
flag = 1
if len(R) * len(C) > m:
flag = 0
else:
for x in R:
for y in C:
if y not in d[x]:
flag = 0
break
print((max(r) + max(c) - flag))
| false | 20.37037 | [
"-import bisect",
"-from operator import itemgetter",
"-",
"-p = [readints() for i in range(m)]",
"-p.sort(key=itemgetter(1))",
"-d = [[] for i in range(h)]",
"+d = [set() for i in range(h)]",
"- a, b = (x - 1 for x in p[i])",
"+ a, b = (x - 1 for x in readints())",
"- d[a].append(b)",
"+ d[a].add(b)",
"- z = bisect.bisect_left(d[x], y)",
"- if z >= len(d[x]):",
"+ if y not in d[x]:",
"- else:",
"- if y != d[x][z]:",
"- flag = 0",
"- break"
] | false | 0.039084 | 0.039391 | 0.992193 | [
"s793122184",
"s661514268"
] |
u188827677 | p02819 | python | s171318154 | s282652622 | 206 | 93 | 16,968 | 71,912 | Accepted | Accepted | 54.85 | x = int(eval(input()))
flag = [True]*(10**6+1)
flag[0] = flag[1] = False
for i in range(4, 10**6+1,2): flag[i] = False
for i in range(3, int((10**6)**0.5)+1, 2):
if flag[i]:
for j in range(i+i, 10**6+1, i): flag[j] = False
while True:
if flag[x]:
print(x)
exit()
x += 1 | x = int(eval(input()))
nums = [True]*(10**6)
n = int(10**6**0.5)
for i in range(4, 10**6, 2): nums[i] = False
for i in range(3, n, 2):
if nums[i]:
for j in range(i+i, 10**6, i): nums[j] = False
while True:
if nums[x]:
print(x)
break
x += 1 | 15 | 14 | 304 | 272 | x = int(eval(input()))
flag = [True] * (10**6 + 1)
flag[0] = flag[1] = False
for i in range(4, 10**6 + 1, 2):
flag[i] = False
for i in range(3, int((10**6) ** 0.5) + 1, 2):
if flag[i]:
for j in range(i + i, 10**6 + 1, i):
flag[j] = False
while True:
if flag[x]:
print(x)
exit()
x += 1
| x = int(eval(input()))
nums = [True] * (10**6)
n = int(10**6**0.5)
for i in range(4, 10**6, 2):
nums[i] = False
for i in range(3, n, 2):
if nums[i]:
for j in range(i + i, 10**6, i):
nums[j] = False
while True:
if nums[x]:
print(x)
break
x += 1
| false | 6.666667 | [
"-flag = [True] * (10**6 + 1)",
"-flag[0] = flag[1] = False",
"-for i in range(4, 10**6 + 1, 2):",
"- flag[i] = False",
"-for i in range(3, int((10**6) ** 0.5) + 1, 2):",
"- if flag[i]:",
"- for j in range(i + i, 10**6 + 1, i):",
"- flag[j] = False",
"+nums = [True] * (10**6)",
"+n = int(10**6**0.5)",
"+for i in range(4, 10**6, 2):",
"+ nums[i] = False",
"+for i in range(3, n, 2):",
"+ if nums[i]:",
"+ for j in range(i + i, 10**6, i):",
"+ nums[j] = False",
"- if flag[x]:",
"+ if nums[x]:",
"- exit()",
"+ break"
] | false | 0.555537 | 0.695078 | 0.799244 | [
"s171318154",
"s282652622"
] |
u512212329 | p02780 | python | s998028173 | s202855436 | 174 | 140 | 24,836 | 25,148 | Accepted | Accepted | 19.54 | def main():
n, k = [int(x) for x in input().split()]
dice = [int(x) for x in input().split()]
expected_accum = []
for i, p in enumerate(dice):
ex = (1 + p) / 2
if i == 0:
expected_accum.append(ex)
else:
expected_accum.append(expected_accum[-1] + ex)
def gen():
for start in range(n - k + 1):
if start == 0:
yield expected_accum[k - 1]
else:
yield expected_accum[start + k - 1] - expected_accum[start - 1]
print((max(gen())))
if __name__ == '__main__':
main()
| from itertools import accumulate
def main():
n, k = [int(x) for x in input().split()]
dice = [int(x) for x in input().split()]
expected_accum = list(accumulate((1 + p) / 2 for p in dice))
def gen():
for start in range(n - k + 1):
if start == 0:
yield expected_accum[k - 1]
else:
yield expected_accum[start + k - 1] - expected_accum[start - 1]
print((max(gen())))
if __name__ == '__main__':
main()
| 24 | 21 | 625 | 510 | def main():
n, k = [int(x) for x in input().split()]
dice = [int(x) for x in input().split()]
expected_accum = []
for i, p in enumerate(dice):
ex = (1 + p) / 2
if i == 0:
expected_accum.append(ex)
else:
expected_accum.append(expected_accum[-1] + ex)
def gen():
for start in range(n - k + 1):
if start == 0:
yield expected_accum[k - 1]
else:
yield expected_accum[start + k - 1] - expected_accum[start - 1]
print((max(gen())))
if __name__ == "__main__":
main()
| from itertools import accumulate
def main():
n, k = [int(x) for x in input().split()]
dice = [int(x) for x in input().split()]
expected_accum = list(accumulate((1 + p) / 2 for p in dice))
def gen():
for start in range(n - k + 1):
if start == 0:
yield expected_accum[k - 1]
else:
yield expected_accum[start + k - 1] - expected_accum[start - 1]
print((max(gen())))
if __name__ == "__main__":
main()
| false | 12.5 | [
"+from itertools import accumulate",
"+",
"+",
"- expected_accum = []",
"- for i, p in enumerate(dice):",
"- ex = (1 + p) / 2",
"- if i == 0:",
"- expected_accum.append(ex)",
"- else:",
"- expected_accum.append(expected_accum[-1] + ex)",
"+ expected_accum = list(accumulate((1 + p) / 2 for p in dice))"
] | false | 0.042183 | 0.043211 | 0.976211 | [
"s998028173",
"s202855436"
] |
u752907966 | p02773 | python | s985916812 | s253726499 | 540 | 392 | 35,952 | 35,944 | Accepted | Accepted | 27.41 | from collections import Counter
n=int(eval(input()))
s=[]
for _ in range(n):
s.append(eval(input()))
c = Counter(s)
ans=[]
max_vote = max(c.values())
for i,j in list(c.items()):
if j == max_vote:
ans.append(i)
print(("\n".join(sorted(ans)))) | from collections import Counter
import sys
input = sys.stdin.readline
n=int(eval(input()))
s=[]
for _ in range(n):
s.append(input().rstrip())
c = Counter(s)
ans=[]
max_vote = max(c.values())
for i,j in list(c.items()):
if j == max_vote:
ans.append(i)
print(("\n".join(sorted(ans)))) | 12 | 14 | 248 | 297 | from collections import Counter
n = int(eval(input()))
s = []
for _ in range(n):
s.append(eval(input()))
c = Counter(s)
ans = []
max_vote = max(c.values())
for i, j in list(c.items()):
if j == max_vote:
ans.append(i)
print(("\n".join(sorted(ans))))
| from collections import Counter
import sys
input = sys.stdin.readline
n = int(eval(input()))
s = []
for _ in range(n):
s.append(input().rstrip())
c = Counter(s)
ans = []
max_vote = max(c.values())
for i, j in list(c.items()):
if j == max_vote:
ans.append(i)
print(("\n".join(sorted(ans))))
| false | 14.285714 | [
"+import sys",
"+input = sys.stdin.readline",
"- s.append(eval(input()))",
"+ s.append(input().rstrip())"
] | false | 0.04228 | 0.058659 | 0.720779 | [
"s985916812",
"s253726499"
] |
u488178971 | p03733 | python | s276357687 | s217403701 | 165 | 143 | 25,200 | 25,196 | Accepted | Accepted | 13.33 | N,T=list(map(int,input().split()))
t=[int(i) for i in input().split()]
ans = T
for i in range(N-1):
ans += min(t[i+1] - t[i],T)
print(ans) | N,T= list(map(int,input().split()))
t = [int(j) for j in input().split()]
ans =T
b = 0
for i in t:
ans+=min(i-b,T)
b = i
print(ans) | 6 | 8 | 141 | 140 | N, T = list(map(int, input().split()))
t = [int(i) for i in input().split()]
ans = T
for i in range(N - 1):
ans += min(t[i + 1] - t[i], T)
print(ans)
| N, T = list(map(int, input().split()))
t = [int(j) for j in input().split()]
ans = T
b = 0
for i in t:
ans += min(i - b, T)
b = i
print(ans)
| false | 25 | [
"-t = [int(i) for i in input().split()]",
"+t = [int(j) for j in input().split()]",
"-for i in range(N - 1):",
"- ans += min(t[i + 1] - t[i], T)",
"+b = 0",
"+for i in t:",
"+ ans += min(i - b, T)",
"+ b = i"
] | false | 0.036022 | 0.035783 | 1.006681 | [
"s276357687",
"s217403701"
] |
u626337957 | p02959 | python | s134426173 | s764479549 | 162 | 136 | 18,476 | 18,476 | Accepted | Accepted | 16.05 | N = int(eval(input()))
M = list(map(int, input().split()))
H = list(map(int, input().split()))
sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
killed = min(H[i]+rest, M[i])
rest = min(H[i]+rest-killed, H[i])
sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)
| N = int(eval(input()))
M = list(map(int, input().split()))
H = list(map(int, input().split()))
sum_m = 0
rest = 0
for i in range(N):
if M[i] >= H[i]+rest:
sum_m += H[i]+rest
rest = 0
else:
sum_m += M[i]
rest = min(H[i], H[i]+rest-M[i])
sum_m += min(rest, M[-1])
print(sum_m)
| 13 | 16 | 280 | 306 | N = int(eval(input()))
M = list(map(int, input().split()))
H = list(map(int, input().split()))
sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
killed = min(H[i] + rest, M[i])
rest = min(H[i] + rest - killed, H[i])
sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)
| N = int(eval(input()))
M = list(map(int, input().split()))
H = list(map(int, input().split()))
sum_m = 0
rest = 0
for i in range(N):
if M[i] >= H[i] + rest:
sum_m += H[i] + rest
rest = 0
else:
sum_m += M[i]
rest = min(H[i], H[i] + rest - M[i])
sum_m += min(rest, M[-1])
print(sum_m)
| false | 18.75 | [
"-killed = 0",
"-for i in range(0, N):",
"- killed = min(H[i] + rest, M[i])",
"- rest = min(H[i] + rest - killed, H[i])",
"- sum_m += killed",
"+for i in range(N):",
"+ if M[i] >= H[i] + rest:",
"+ sum_m += H[i] + rest",
"+ rest = 0",
"+ else:",
"+ sum_m += M[i]",
"+ rest = min(H[i], H[i] + rest - M[i])"
] | false | 0.031826 | 0.032478 | 0.979934 | [
"s134426173",
"s764479549"
] |
u314906167 | p03674 | python | s797440459 | s734284721 | 1,135 | 741 | 80,104 | 72,168 | Accepted | Accepted | 34.71 | from collections import Counter
class Mint:
MOD = 1000000007 # Must be a prime
CACHE_FACTORIALS = [1, 1]
def __init__(self, v):
if self.__isally(v):
self.v = v.v % self.MOD
else:
self.v = v % self.MOD
@property
def inv(self):
return Mint(self.__minv(self.v))
@classmethod
def factorial(cls, v):
for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
return Mint(cls.CACHE_FACTORIALS[int(v)])
@classmethod
def perm(cls, n, r):
if n < r or r < 0:
return 0
return cls.factorial(n) // cls.factorial(n - r)
@classmethod
def comb(cls, n, r):
if n < r or r < 0:
return 0
return cls.perm(n, r) // cls.factorial(r)
@classmethod
def __isally(cls, v) -> bool:
return isinstance(v, cls)
@classmethod
def __minv(cls, v) -> int:
return pow(v, cls.MOD - 2, cls.MOD)
@classmethod
def __mpow(cls, v, w) -> int:
return pow(v, w, cls.MOD)
def __str__(self):
return str(self.v)
__repr__ = __str__
def __int__(self):
return self.v
def __eq__(self, w):
return self.v == w.v if self.__isally(w) else self.v == w
def __add__(self, w):
return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
__radd__ = __add__
def __sub__(self, w):
return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)
def __rsub__(self, u):
return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)
def __mul__(self, w):
return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
__rmul__ = __mul__
def __floordiv__(self, w):
return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else \
Mint(self.v * self.__minv(w))
def __rfloordiv__(self, u):
return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else \
Mint(u * self.__minv(self.v))
def __pow__(self, w):
return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else \
Mint(self.__mpow(self.v, w))
def __rpow__(self, u):
return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else \
Mint(self.__mpow(u, self.v))
N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i+1)
l = i
m = j - i - 1
n = N - j
for k in range(1, N + 2):
ans = Mint.comb(l + m + n, k) + Mint.comb(l + m + n, k - 1) * \
2 - Mint.comb(l + n, k - 1) + Mint.comb(l + m + n, k - 2)
print(ans)
| from collections import Counter
class Mint:
MOD = 1000000007 # Must be a prime
CACHE_FACTORIALS = [1, 1]
def __init__(self, v):
if self.__isally(v):
self.v = v.v % self.MOD
else:
self.v = v % self.MOD
@property
def inv(self):
return Mint(self.__minv(self.v))
@classmethod
def factorial(cls, v):
for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
return Mint(cls.CACHE_FACTORIALS[int(v)])
@classmethod
def perm(cls, n, r):
if n < r or r < 0:
return 0
return cls.factorial(n) // cls.factorial(n - r)
@classmethod
def comb(cls, n, r):
if n < r or r < 0:
return 0
return cls.perm(n, r) // cls.factorial(r)
@classmethod
def __isally(cls, v) -> bool:
return isinstance(v, cls)
@classmethod
def __minv(cls, v) -> int:
return pow(v, cls.MOD - 2, cls.MOD)
@classmethod
def __mpow(cls, v, w) -> int:
return pow(v, w, cls.MOD)
def __str__(self):
return str(self.v)
__repr__ = __str__
def __int__(self):
return self.v
def __eq__(self, w):
return self.v == w.v if self.__isally(w) else self.v == w
def __add__(self, w):
return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
__radd__ = __add__
def __sub__(self, w):
return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)
def __rsub__(self, u):
return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)
def __mul__(self, w):
return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
__rmul__ = __mul__
def __floordiv__(self, w):
return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else \
Mint(self.v * self.__minv(w))
def __rfloordiv__(self, u):
return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else \
Mint(u * self.__minv(self.v))
def __pow__(self, w):
return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else \
Mint(self.__mpow(self.v, w))
def __rpow__(self, u):
return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else \
Mint(self.__mpow(u, self.v))
N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i+1)
m = j - i - 1
for k in range(1, N + 2):
ans = Mint.comb(N + 1, k) - Mint.comb(N - m - 1, k - 1)
print(ans)
| 100 | 97 | 2,806 | 2,713 | from collections import Counter
class Mint:
MOD = 1000000007 # Must be a prime
CACHE_FACTORIALS = [1, 1]
def __init__(self, v):
if self.__isally(v):
self.v = v.v % self.MOD
else:
self.v = v % self.MOD
@property
def inv(self):
return Mint(self.__minv(self.v))
@classmethod
def factorial(cls, v):
for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
return Mint(cls.CACHE_FACTORIALS[int(v)])
@classmethod
def perm(cls, n, r):
if n < r or r < 0:
return 0
return cls.factorial(n) // cls.factorial(n - r)
@classmethod
def comb(cls, n, r):
if n < r or r < 0:
return 0
return cls.perm(n, r) // cls.factorial(r)
@classmethod
def __isally(cls, v) -> bool:
return isinstance(v, cls)
@classmethod
def __minv(cls, v) -> int:
return pow(v, cls.MOD - 2, cls.MOD)
@classmethod
def __mpow(cls, v, w) -> int:
return pow(v, w, cls.MOD)
def __str__(self):
return str(self.v)
__repr__ = __str__
def __int__(self):
return self.v
def __eq__(self, w):
return self.v == w.v if self.__isally(w) else self.v == w
def __add__(self, w):
return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
__radd__ = __add__
def __sub__(self, w):
return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)
def __rsub__(self, u):
return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)
def __mul__(self, w):
return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
__rmul__ = __mul__
def __floordiv__(self, w):
return (
Mint(self.v * self.__minv(w.v))
if self.__isally(w)
else Mint(self.v * self.__minv(w))
)
def __rfloordiv__(self, u):
return (
Mint(u.v * self.__minv(self.v))
if self.__isally(u)
else Mint(u * self.__minv(self.v))
)
def __pow__(self, w):
return (
Mint(self.__mpow(self.v, w.v))
if self.__isally(w)
else Mint(self.__mpow(self.v, w))
)
def __rpow__(self, u):
return (
Mint(self.__mpow(u.v, self.v))
if self.__isally(u)
else Mint(self.__mpow(u, self.v))
)
N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i + 1)
l = i
m = j - i - 1
n = N - j
for k in range(1, N + 2):
ans = (
Mint.comb(l + m + n, k)
+ Mint.comb(l + m + n, k - 1) * 2
- Mint.comb(l + n, k - 1)
+ Mint.comb(l + m + n, k - 2)
)
print(ans)
| from collections import Counter
class Mint:
MOD = 1000000007 # Must be a prime
CACHE_FACTORIALS = [1, 1]
def __init__(self, v):
if self.__isally(v):
self.v = v.v % self.MOD
else:
self.v = v % self.MOD
@property
def inv(self):
return Mint(self.__minv(self.v))
@classmethod
def factorial(cls, v):
for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
return Mint(cls.CACHE_FACTORIALS[int(v)])
@classmethod
def perm(cls, n, r):
if n < r or r < 0:
return 0
return cls.factorial(n) // cls.factorial(n - r)
@classmethod
def comb(cls, n, r):
if n < r or r < 0:
return 0
return cls.perm(n, r) // cls.factorial(r)
@classmethod
def __isally(cls, v) -> bool:
return isinstance(v, cls)
@classmethod
def __minv(cls, v) -> int:
return pow(v, cls.MOD - 2, cls.MOD)
@classmethod
def __mpow(cls, v, w) -> int:
return pow(v, w, cls.MOD)
def __str__(self):
return str(self.v)
__repr__ = __str__
def __int__(self):
return self.v
def __eq__(self, w):
return self.v == w.v if self.__isally(w) else self.v == w
def __add__(self, w):
return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
__radd__ = __add__
def __sub__(self, w):
return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)
def __rsub__(self, u):
return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)
def __mul__(self, w):
return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
__rmul__ = __mul__
def __floordiv__(self, w):
return (
Mint(self.v * self.__minv(w.v))
if self.__isally(w)
else Mint(self.v * self.__minv(w))
)
def __rfloordiv__(self, u):
return (
Mint(u.v * self.__minv(self.v))
if self.__isally(u)
else Mint(u * self.__minv(self.v))
)
def __pow__(self, w):
return (
Mint(self.__mpow(self.v, w.v))
if self.__isally(w)
else Mint(self.__mpow(self.v, w))
)
def __rpow__(self, u):
return (
Mint(self.__mpow(u.v, self.v))
if self.__isally(u)
else Mint(self.__mpow(u, self.v))
)
N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i + 1)
m = j - i - 1
for k in range(1, N + 2):
ans = Mint.comb(N + 1, k) - Mint.comb(N - m - 1, k - 1)
print(ans)
| false | 3 | [
"-l = i",
"-n = N - j",
"- ans = (",
"- Mint.comb(l + m + n, k)",
"- + Mint.comb(l + m + n, k - 1) * 2",
"- - Mint.comb(l + n, k - 1)",
"- + Mint.comb(l + m + n, k - 2)",
"- )",
"+ ans = Mint.comb(N + 1, k) - Mint.comb(N - m - 1, k - 1)"
] | false | 0.037786 | 0.044998 | 0.839724 | [
"s797440459",
"s734284721"
] |
u815218584 | p02725 | python | s445685374 | s779561626 | 164 | 119 | 26,444 | 26,420 | Accepted | Accepted | 27.44 | k,n=list(map(int,input().split()))
a=list(map(int,input().split()))
ma=0
for i in range(n-1):
ma=max(ma,a[i+1]-a[i])
print((k-max(ma,a[0]+k-a[n-1]))) | k,n=list(map(int,input().split()))
a=list(map(int,input().split()))
check_l =[]
for i in range(len(a)-1):
check_l.append(a[i+1]-a[i])
check_l.append(k+a[0]-a[n-1])
print((k-max(check_l))) | 6 | 9 | 150 | 190 | k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
ma = 0
for i in range(n - 1):
ma = max(ma, a[i + 1] - a[i])
print((k - max(ma, a[0] + k - a[n - 1])))
| k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
check_l = []
for i in range(len(a) - 1):
check_l.append(a[i + 1] - a[i])
check_l.append(k + a[0] - a[n - 1])
print((k - max(check_l)))
| false | 33.333333 | [
"-ma = 0",
"-for i in range(n - 1):",
"- ma = max(ma, a[i + 1] - a[i])",
"-print((k - max(ma, a[0] + k - a[n - 1])))",
"+check_l = []",
"+for i in range(len(a) - 1):",
"+ check_l.append(a[i + 1] - a[i])",
"+check_l.append(k + a[0] - a[n - 1])",
"+print((k - max(check_l)))"
] | false | 0.054195 | 0.082123 | 0.659917 | [
"s445685374",
"s779561626"
] |
u573754721 | p02936 | python | s182341669 | s101335347 | 1,991 | 1,833 | 123,020 | 105,236 | Accepted | Accepted | 7.94 | from collections import deque
n,q=list(map(int,input().split()))
K=[set() for _ in range(n)]
V=[False]*n
P=[0]*n
for i in range(n-1):
a,b=list(map(int,input().split()))
K[a-1].add(b-1)
K[b-1].add(a-1)
for i in range(q):
c,d=list(map(int,input().split()))
P[c-1]+=d
que=deque([0])
while que:
s=que.popleft()
V[s]=True
for ni in K[s]:
if V[ni]==False:
P[ni]+=P[s]
que.append(ni)
print((*P)) | from collections import deque
n,q=list(map(int,input().split()))
E=[[] for _ in range(n)]
P=[0]*n
V=[False]*n
for i in range(n-1):
a,b=list(map(int,input().split()))
E[a-1].append(b-1)
E[b-1].append(a-1)
for i in range(q):
p,x=list(map(int,input().split()))
P[p-1]+=x
que=deque([0])
while que:
s=que.popleft()
V[s]=True
for ni in E[s]:
if V[ni]==False:
P[ni]+=P[s]
que.append(ni)
print((*P)) | 21 | 23 | 484 | 459 | from collections import deque
n, q = list(map(int, input().split()))
K = [set() for _ in range(n)]
V = [False] * n
P = [0] * n
for i in range(n - 1):
a, b = list(map(int, input().split()))
K[a - 1].add(b - 1)
K[b - 1].add(a - 1)
for i in range(q):
c, d = list(map(int, input().split()))
P[c - 1] += d
que = deque([0])
while que:
s = que.popleft()
V[s] = True
for ni in K[s]:
if V[ni] == False:
P[ni] += P[s]
que.append(ni)
print((*P))
| from collections import deque
n, q = list(map(int, input().split()))
E = [[] for _ in range(n)]
P = [0] * n
V = [False] * n
for i in range(n - 1):
a, b = list(map(int, input().split()))
E[a - 1].append(b - 1)
E[b - 1].append(a - 1)
for i in range(q):
p, x = list(map(int, input().split()))
P[p - 1] += x
que = deque([0])
while que:
s = que.popleft()
V[s] = True
for ni in E[s]:
if V[ni] == False:
P[ni] += P[s]
que.append(ni)
print((*P))
| false | 8.695652 | [
"-K = [set() for _ in range(n)]",
"+E = [[] for _ in range(n)]",
"+P = [0] * n",
"-P = [0] * n",
"- K[a - 1].add(b - 1)",
"- K[b - 1].add(a - 1)",
"+ E[a - 1].append(b - 1)",
"+ E[b - 1].append(a - 1)",
"- c, d = list(map(int, input().split()))",
"- P[c - 1] += d",
"+ p, x = list(map(int, input().split()))",
"+ P[p - 1] += x",
"- for ni in K[s]:",
"+ for ni in E[s]:"
] | false | 0.038318 | 0.040493 | 0.94627 | [
"s182341669",
"s101335347"
] |
u227082700 | p03045 | python | s250861943 | s948558639 | 608 | 352 | 7,700 | 13,288 | Accepted | Accepted | 42.11 | import sys;sys.setrecursionlimit(10**9)
class u():#UnionFind f-根探し u-連結 s-連結? c-要素数
def __init__(self,n):self.n,self.r=[-1]*n,[0]*n
def f(self,x):
if self.n[x]<0:return x
else:self.n[x]=self.f(self.n[x]);return self.n[x]
def u(self,x,y):
x,y=self.f(x),self.f(y)
if x==y:return
elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x
else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y]
def s(self,x,y):return self.f(x)==self.f(y)
def c(self,x):return -self.n[self.f(x)]
n,m=list(map(int,input().split()));u=u(n)
for i in range(m):
a,b,c=list(map(int,input().split()));a-=1;b-=1
if not(u.s(a,b)):n-=1;u.u(a,b)
print(n) | import sys;sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self,n):
self.n=[-1]*n
self.r=[0]*n
self.siz=n
def find_root(self,x):
if self.n[x]<0:
return x
else:
self.n[x]=self.find_root(self.n[x])
return self.n[x]
def unite(self,x,y):
x=self.find_root(x)
y=self.find_root(y)
if x==y:return
elif self.r[x]>self.r[y]:
self.n[x]+=self.n[y]
self.n[y]=x
else:
self.n[y]+=self.n[x]
self.n[x]=y
if self.r[x]==self.r[y]:
self.r[y]+=1
self.siz-=1
def root_same(self,x,y):
return self.find_root(x)==self.find_root(y)
def count(self,x):
return -self.n[self.find_root(x)]
def size(self):
return self.siz
n,m=list(map(int,input().split()))
uf=UnionFind(n)
for i in range(m):
x,y,z=list(map(int,input().split()))
uf.unite(x-1,y-1)
print((uf.size())) | 18 | 38 | 679 | 897 | import sys
sys.setrecursionlimit(10**9)
class u: # UnionFind f-根探し u-連結 s-連結? c-要素数
def __init__(self, n):
self.n, self.r = [-1] * n, [0] * n
def f(self, x):
if self.n[x] < 0:
return x
else:
self.n[x] = self.f(self.n[x])
return self.n[x]
def u(self, x, y):
x, y = self.f(x), self.f(y)
if x == y:
return
elif self.r[x] > self.r[y]:
self.n[x] += self.n[y]
self.n[y] = x
else:
self.n[y] += self.n[x]
self.n[x] = y
self.r[y] += self.r[x] == self.r[y]
def s(self, x, y):
return self.f(x) == self.f(y)
def c(self, x):
return -self.n[self.f(x)]
n, m = list(map(int, input().split()))
u = u(n)
for i in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
if not (u.s(a, b)):
n -= 1
u.u(a, b)
print(n)
| import sys
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self, n):
self.n = [-1] * n
self.r = [0] * n
self.siz = n
def find_root(self, x):
if self.n[x] < 0:
return x
else:
self.n[x] = self.find_root(self.n[x])
return self.n[x]
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.r[x] > self.r[y]:
self.n[x] += self.n[y]
self.n[y] = x
else:
self.n[y] += self.n[x]
self.n[x] = y
if self.r[x] == self.r[y]:
self.r[y] += 1
self.siz -= 1
def root_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def count(self, x):
return -self.n[self.find_root(x)]
def size(self):
return self.siz
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
x, y, z = list(map(int, input().split()))
uf.unite(x - 1, y - 1)
print((uf.size()))
| false | 52.631579 | [
"-class u: # UnionFind f-根探し u-連結 s-連結? c-要素数",
"+class UnionFind:",
"- self.n, self.r = [-1] * n, [0] * n",
"+ self.n = [-1] * n",
"+ self.r = [0] * n",
"+ self.siz = n",
"- def f(self, x):",
"+ def find_root(self, x):",
"- self.n[x] = self.f(self.n[x])",
"+ self.n[x] = self.find_root(self.n[x])",
"- def u(self, x, y):",
"- x, y = self.f(x), self.f(y)",
"+ def unite(self, x, y):",
"+ x = self.find_root(x)",
"+ y = self.find_root(y)",
"- self.r[y] += self.r[x] == self.r[y]",
"+ if self.r[x] == self.r[y]:",
"+ self.r[y] += 1",
"+ self.siz -= 1",
"- def s(self, x, y):",
"- return self.f(x) == self.f(y)",
"+ def root_same(self, x, y):",
"+ return self.find_root(x) == self.find_root(y)",
"- def c(self, x):",
"- return -self.n[self.f(x)]",
"+ def count(self, x):",
"+ return -self.n[self.find_root(x)]",
"+",
"+ def size(self):",
"+ return self.siz",
"-u = u(n)",
"+uf = UnionFind(n)",
"- a, b, c = list(map(int, input().split()))",
"- a -= 1",
"- b -= 1",
"- if not (u.s(a, b)):",
"- n -= 1",
"- u.u(a, b)",
"-print(n)",
"+ x, y, z = list(map(int, input().split()))",
"+ uf.unite(x - 1, y - 1)",
"+print((uf.size()))"
] | false | 0.037451 | 0.063529 | 0.589512 | [
"s250861943",
"s948558639"
] |
u740284863 | p02861 | python | s189887036 | s065419658 | 457 | 292 | 8,180 | 13,864 | Accepted | Accepted | 36.11 | import itertools
n = int(eval(input()))
points = [ list(map(int,input().split())) for _ in range(n)]
routes = list(itertools.permutations(points))
ans = 0
for route in routes:
for i in range(len(route)-1):
x,y = route[i][0],route[i][1]
a,b = route[i+1][0],route[i+1][1]
ans += ((x-a)**2+(y-b)**2 )**(0.5)
ans /= len(routes)
print(ans) | import itertools,math
n = int(eval(input()))
points = [list(map(int,input().split())) for _ in range(n)]
roots = list(itertools.permutations(points))
ans = 0
for root in roots:
for i in range(n-1):
ans += math.sqrt(pow(root[i+1][0] - root[i][0],2) + pow(root[i+1][1] - root[i][1],2))
ans /= len(roots)
print(ans) | 12 | 10 | 375 | 327 | import itertools
n = int(eval(input()))
points = [list(map(int, input().split())) for _ in range(n)]
routes = list(itertools.permutations(points))
ans = 0
for route in routes:
for i in range(len(route) - 1):
x, y = route[i][0], route[i][1]
a, b = route[i + 1][0], route[i + 1][1]
ans += ((x - a) ** 2 + (y - b) ** 2) ** (0.5)
ans /= len(routes)
print(ans)
| import itertools, math
n = int(eval(input()))
points = [list(map(int, input().split())) for _ in range(n)]
roots = list(itertools.permutations(points))
ans = 0
for root in roots:
for i in range(n - 1):
ans += math.sqrt(
pow(root[i + 1][0] - root[i][0], 2) + pow(root[i + 1][1] - root[i][1], 2)
)
ans /= len(roots)
print(ans)
| false | 16.666667 | [
"-import itertools",
"+import itertools, math",
"-routes = list(itertools.permutations(points))",
"+roots = list(itertools.permutations(points))",
"-for route in routes:",
"- for i in range(len(route) - 1):",
"- x, y = route[i][0], route[i][1]",
"- a, b = route[i + 1][0], route[i + 1][1]",
"- ans += ((x - a) ** 2 + (y - b) ** 2) ** (0.5)",
"-ans /= len(routes)",
"+for root in roots:",
"+ for i in range(n - 1):",
"+ ans += math.sqrt(",
"+ pow(root[i + 1][0] - root[i][0], 2) + pow(root[i + 1][1] - root[i][1], 2)",
"+ )",
"+ans /= len(roots)"
] | false | 0.046629 | 0.081944 | 0.569039 | [
"s189887036",
"s065419658"
] |
u089032001 | p03470 | python | s277035136 | s017819676 | 26 | 18 | 3,316 | 2,940 | Accepted | Accepted | 30.77 | from collections import Counter
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
print((len(Counter([int(eval(input())) for _ in range(N)])))) | def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
print((len({int(eval(input())) for _ in range(N)}))) | 7 | 5 | 162 | 118 | from collections import Counter
def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
print((len(Counter([int(eval(input())) for _ in range(N)]))))
| def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
print((len({int(eval(input())) for _ in range(N)})))
| false | 28.571429 | [
"-from collections import Counter",
"-",
"-",
"-print((len(Counter([int(eval(input())) for _ in range(N)]))))",
"+print((len({int(eval(input())) for _ in range(N)})))"
] | false | 0.035518 | 0.043703 | 0.812726 | [
"s277035136",
"s017819676"
] |
u766566560 | p02812 | python | s144284377 | s665720280 | 20 | 17 | 2,940 | 3,060 | Accepted | Accepted | 15 | EXP_STR="ABC"
n = int(eval(input()))
input_str = eval(input())
print((input_str.count(EXP_STR)))
| N = int(eval(input()))
S = eval(input())
print((S.count('ABC'))) | 6 | 4 | 90 | 54 | EXP_STR = "ABC"
n = int(eval(input()))
input_str = eval(input())
print((input_str.count(EXP_STR)))
| N = int(eval(input()))
S = eval(input())
print((S.count("ABC")))
| false | 33.333333 | [
"-EXP_STR = \"ABC\"",
"-n = int(eval(input()))",
"-input_str = eval(input())",
"-print((input_str.count(EXP_STR)))",
"+N = int(eval(input()))",
"+S = eval(input())",
"+print((S.count(\"ABC\")))"
] | false | 0.035508 | 0.033857 | 1.048771 | [
"s144284377",
"s665720280"
] |
u349449706 | p02614 | python | s612337371 | s413954432 | 165 | 91 | 72,652 | 68,356 | Accepted | Accepted | 44.85 | import copy
h,w,k2=list(map(int, input().split()))
c = [list(eval(input())) for i in range(h)]
ans = 0
for i in range(2**h):
for j in range(2**w):
d = copy.deepcopy(c)
for k in range(h):
if i%(2**(k+1))//(2**k)==1:
for j2 in range(w):
d[k][j2]='r'
for l in range(w):
if j%(2**(l+1))//(2**l)==1:
for i2 in range(h):
d[i2][l]='r'
black = 0
for i3 in range(h):
for j3 in range(w):
if d[i3][j3]=='#':
black +=1
if black == k2:
ans+=1
print(ans)
| h,w,k=list(map(int, input().split()))
c = [list(eval(input())) for i in range(h)]
ans = 0
for i in range(2**h):
for j in range(2**w):
black = 0
for i2 in range(h):
for j2 in range(w):
if c[i2][j2]=='#' and i>>i2&1==0 and j>>j2&1==0:
black +=1
if black == k:
ans+=1
print(ans)
| 24 | 13 | 661 | 364 | import copy
h, w, k2 = list(map(int, input().split()))
c = [list(eval(input())) for i in range(h)]
ans = 0
for i in range(2**h):
for j in range(2**w):
d = copy.deepcopy(c)
for k in range(h):
if i % (2 ** (k + 1)) // (2**k) == 1:
for j2 in range(w):
d[k][j2] = "r"
for l in range(w):
if j % (2 ** (l + 1)) // (2**l) == 1:
for i2 in range(h):
d[i2][l] = "r"
black = 0
for i3 in range(h):
for j3 in range(w):
if d[i3][j3] == "#":
black += 1
if black == k2:
ans += 1
print(ans)
| h, w, k = list(map(int, input().split()))
c = [list(eval(input())) for i in range(h)]
ans = 0
for i in range(2**h):
for j in range(2**w):
black = 0
for i2 in range(h):
for j2 in range(w):
if c[i2][j2] == "#" and i >> i2 & 1 == 0 and j >> j2 & 1 == 0:
black += 1
if black == k:
ans += 1
print(ans)
| false | 45.833333 | [
"-import copy",
"-",
"-h, w, k2 = list(map(int, input().split()))",
"+h, w, k = list(map(int, input().split()))",
"- d = copy.deepcopy(c)",
"- for k in range(h):",
"- if i % (2 ** (k + 1)) // (2**k) == 1:",
"- for j2 in range(w):",
"- d[k][j2] = \"r\"",
"- for l in range(w):",
"- if j % (2 ** (l + 1)) // (2**l) == 1:",
"- for i2 in range(h):",
"- d[i2][l] = \"r\"",
"- for i3 in range(h):",
"- for j3 in range(w):",
"- if d[i3][j3] == \"#\":",
"+ for i2 in range(h):",
"+ for j2 in range(w):",
"+ if c[i2][j2] == \"#\" and i >> i2 & 1 == 0 and j >> j2 & 1 == 0:",
"- if black == k2:",
"+ if black == k:"
] | false | 0.121705 | 0.08157 | 1.492032 | [
"s612337371",
"s413954432"
] |
u223663729 | p03806 | python | s482784340 | s233030341 | 707 | 76 | 74,876 | 73,460 | Accepted | Accepted | 89.25 | import sys
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
X = [tuple(map(int, line.split())) for line in readlines()]
INF = 1 << 30
x = [[INF]*201 for _ in [0]*201]
y = [[INF]*201 for _ in [0]*201]
n = N//2
X, Y = X[:n], X[n:]
for bit in range(1 << n):
totA = totB = cost = 0
for i in range(n):
if bit >> i & 1:
a, b, c = X[i]
totA += a
totB += b
cost += c
x[totA][totB] = min(x[totA][totB], cost)
for bit in range(1 << (N-n)):
totA = totB = cost = 0
for i in range(N-n):
if bit >> i & 1:
a, b, c = Y[i]
totA += a
totB += b
cost += c
y[totA][totB] = min(y[totA][totB], cost)
ans = INF
M = 405//max(Ma, Mb)
for i, t in enumerate(x):
for j, s in enumerate(t):
if s == INF:
continue
for k in range(1, M+1):
I = k*Ma-i
J = k*Mb-j
if 0 <= I <= 200 and 0 <= J <= 200:
ans = min(ans, s + y[I][J])
print((ans if ans < INF else -1))
| import sys
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
X = [list(map(int, line.split())) for line in readlines()]
X = [(a*Mb-b*Ma, c) for a, b, c in X]
INF = 1 << 30
MAX = 10000
MID = MAX//2
dp = [INF]*(MAX+1)
ans = INF
for i, (x, c) in enumerate(X):
if x == 0:
ans = min(ans, c)
continue
if x > 0:
for j in range(MAX, x-1, -1):
dp[j] = min(dp[j], dp[j-x]+c)
else:
for j in range(MAX+x):
dp[j] = min(dp[j], dp[j-x]+c)
dp[MID+x] = min(dp[MID+x], c)
ans = min(ans, dp[MID])
print((ans if ans < INF else -1))
| 47 | 28 | 1,159 | 668 | import sys
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
X = [tuple(map(int, line.split())) for line in readlines()]
INF = 1 << 30
x = [[INF] * 201 for _ in [0] * 201]
y = [[INF] * 201 for _ in [0] * 201]
n = N // 2
X, Y = X[:n], X[n:]
for bit in range(1 << n):
totA = totB = cost = 0
for i in range(n):
if bit >> i & 1:
a, b, c = X[i]
totA += a
totB += b
cost += c
x[totA][totB] = min(x[totA][totB], cost)
for bit in range(1 << (N - n)):
totA = totB = cost = 0
for i in range(N - n):
if bit >> i & 1:
a, b, c = Y[i]
totA += a
totB += b
cost += c
y[totA][totB] = min(y[totA][totB], cost)
ans = INF
M = 405 // max(Ma, Mb)
for i, t in enumerate(x):
for j, s in enumerate(t):
if s == INF:
continue
for k in range(1, M + 1):
I = k * Ma - i
J = k * Mb - j
if 0 <= I <= 200 and 0 <= J <= 200:
ans = min(ans, s + y[I][J])
print((ans if ans < INF else -1))
| import sys
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
X = [list(map(int, line.split())) for line in readlines()]
X = [(a * Mb - b * Ma, c) for a, b, c in X]
INF = 1 << 30
MAX = 10000
MID = MAX // 2
dp = [INF] * (MAX + 1)
ans = INF
for i, (x, c) in enumerate(X):
if x == 0:
ans = min(ans, c)
continue
if x > 0:
for j in range(MAX, x - 1, -1):
dp[j] = min(dp[j], dp[j - x] + c)
else:
for j in range(MAX + x):
dp[j] = min(dp[j], dp[j - x] + c)
dp[MID + x] = min(dp[MID + x], c)
ans = min(ans, dp[MID])
print((ans if ans < INF else -1))
| false | 40.425532 | [
"-X = [tuple(map(int, line.split())) for line in readlines()]",
"+X = [list(map(int, line.split())) for line in readlines()]",
"+X = [(a * Mb - b * Ma, c) for a, b, c in X]",
"-x = [[INF] * 201 for _ in [0] * 201]",
"-y = [[INF] * 201 for _ in [0] * 201]",
"-n = N // 2",
"-X, Y = X[:n], X[n:]",
"-for bit in range(1 << n):",
"- totA = totB = cost = 0",
"- for i in range(n):",
"- if bit >> i & 1:",
"- a, b, c = X[i]",
"- totA += a",
"- totB += b",
"- cost += c",
"- x[totA][totB] = min(x[totA][totB], cost)",
"-for bit in range(1 << (N - n)):",
"- totA = totB = cost = 0",
"- for i in range(N - n):",
"- if bit >> i & 1:",
"- a, b, c = Y[i]",
"- totA += a",
"- totB += b",
"- cost += c",
"- y[totA][totB] = min(y[totA][totB], cost)",
"+MAX = 10000",
"+MID = MAX // 2",
"+dp = [INF] * (MAX + 1)",
"-M = 405 // max(Ma, Mb)",
"-for i, t in enumerate(x):",
"- for j, s in enumerate(t):",
"- if s == INF:",
"- continue",
"- for k in range(1, M + 1):",
"- I = k * Ma - i",
"- J = k * Mb - j",
"- if 0 <= I <= 200 and 0 <= J <= 200:",
"- ans = min(ans, s + y[I][J])",
"+for i, (x, c) in enumerate(X):",
"+ if x == 0:",
"+ ans = min(ans, c)",
"+ continue",
"+ if x > 0:",
"+ for j in range(MAX, x - 1, -1):",
"+ dp[j] = min(dp[j], dp[j - x] + c)",
"+ else:",
"+ for j in range(MAX + x):",
"+ dp[j] = min(dp[j], dp[j - x] + c)",
"+ dp[MID + x] = min(dp[MID + x], c)",
"+ans = min(ans, dp[MID])"
] | false | 0.045126 | 0.039964 | 1.129151 | [
"s482784340",
"s233030341"
] |
u600402037 | p03213 | python | s894433595 | s076424225 | 20 | 18 | 3,188 | 3,064 | Accepted | Accepted | 10 | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
power = [0] * (N+1)
for x in range(2, N+1):
for p in range(2, x+1):
while x % p == 0:
power[p] += 1
x //= p
def num(x):
'''約数がx-1以上の数を返す'''
return len(list(filter(lambda y: y >= x-1, power)))
answer = num(75) + num(25) * (num(3)-1) + num(15) * (num(5)-1)\
+ num(5) * (num(5)-1) * (num(3)-2) // 2
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
exp = [0] * (N+1)
for i in range(2, N+1):
cur = i
for p in range(2, i+1):
while cur % p == 0:
exp[p] += 1
cur //= p
def num(x):
'''冪乗がx-1以上の数を返す'''
return len(list(filter(lambda y: y >= x-1, exp)))
answer = num(75) + num(25) * (num(3)-1) + num(15) * (num(5)-1)\
+ num(5) * (num(5)-1) * (num(3)-2) // 2
print(answer)
| 22 | 23 | 531 | 542 | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
power = [0] * (N + 1)
for x in range(2, N + 1):
for p in range(2, x + 1):
while x % p == 0:
power[p] += 1
x //= p
def num(x):
"""約数がx-1以上の数を返す"""
return len(list(filter(lambda y: y >= x - 1, power)))
answer = (
num(75)
+ num(25) * (num(3) - 1)
+ num(15) * (num(5) - 1)
+ num(5) * (num(5) - 1) * (num(3) - 2) // 2
)
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
exp = [0] * (N + 1)
for i in range(2, N + 1):
cur = i
for p in range(2, i + 1):
while cur % p == 0:
exp[p] += 1
cur //= p
def num(x):
"""冪乗がx-1以上の数を返す"""
return len(list(filter(lambda y: y >= x - 1, exp)))
answer = (
num(75)
+ num(25) * (num(3) - 1)
+ num(15) * (num(5) - 1)
+ num(5) * (num(5) - 1) * (num(3) - 2) // 2
)
print(answer)
| false | 4.347826 | [
"-power = [0] * (N + 1)",
"-for x in range(2, N + 1):",
"- for p in range(2, x + 1):",
"- while x % p == 0:",
"- power[p] += 1",
"- x //= p",
"+exp = [0] * (N + 1)",
"+for i in range(2, N + 1):",
"+ cur = i",
"+ for p in range(2, i + 1):",
"+ while cur % p == 0:",
"+ exp[p] += 1",
"+ cur //= p",
"- \"\"\"約数がx-1以上の数を返す\"\"\"",
"- return len(list(filter(lambda y: y >= x - 1, power)))",
"+ \"\"\"冪乗がx-1以上の数を返す\"\"\"",
"+ return len(list(filter(lambda y: y >= x - 1, exp)))"
] | false | 0.035877 | 0.044336 | 0.809203 | [
"s894433595",
"s076424225"
] |
u922449550 | p03713 | python | s076933623 | s947968681 | 417 | 230 | 3,188 | 3,064 | Accepted | Accepted | 44.84 | H, W = list(map(int, input().split()))
if (H%3) * (W%3) == 0:
print((0))
quit()
ans = H * W
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1; T1 = W * ((H-1)//2)
S2 = (H - 1) * w2; T2 = W * (H-1) - T1
S3 = W
h = H - 1
for i in range(H-1):
diff1 = max(S1, S2, S3) - min(S1, S2, S3)
diff2 = max(T1, T2, S3) - min(T1, T2, S3)
ans = min(ans, diff1, diff2)
S1 -= w1; S2 -= w2; S3 += W
h -= 1
T1 = W * (h//2)
T2 = W*h - T1
h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1; T1 = H * ((W-1)//2)
S2 = (W - 1) * h2; T2 = H * (W-1) - T1
S3 = H
w = W - 1
for i in range(W-1):
diff1 = max(S1, S2, S3) - min(S1, S2, S3)
diff2 = max(T1, T2, S3) - min(T1, T2, S3)
ans = min(ans, diff1, diff2)
S1 -= h1; S2 -= h2; S3 += H
w -= 1
T1 = H * (w//2)
T2 = H*w - T1
print(ans) | H, W = list(map(int, input().split()))
if (H%3) * (W%3) == 0:
print((0))
quit()
ans = min(H, W)
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1
S2 = (H - 1) * w2
S3 = W
for i in range(H-1):
diff = max(S1, S2, S3) - min(S1, S2, S3)
ans = min(ans, diff)
S1 -= w1; S2 -= w2; S3 += W
h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1
S2 = (W - 1) * h2
S3 = H
for i in range(W-1):
diff = max(S1, S2, S3) - min(S1, S2, S3)
ans = min(ans, diff)
S1 -= h1; S2 -= h2; S3 += H
print(ans) | 37 | 27 | 801 | 499 | H, W = list(map(int, input().split()))
if (H % 3) * (W % 3) == 0:
print((0))
quit()
ans = H * W
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1
T1 = W * ((H - 1) // 2)
S2 = (H - 1) * w2
T2 = W * (H - 1) - T1
S3 = W
h = H - 1
for i in range(H - 1):
diff1 = max(S1, S2, S3) - min(S1, S2, S3)
diff2 = max(T1, T2, S3) - min(T1, T2, S3)
ans = min(ans, diff1, diff2)
S1 -= w1
S2 -= w2
S3 += W
h -= 1
T1 = W * (h // 2)
T2 = W * h - T1
h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1
T1 = H * ((W - 1) // 2)
S2 = (W - 1) * h2
T2 = H * (W - 1) - T1
S3 = H
w = W - 1
for i in range(W - 1):
diff1 = max(S1, S2, S3) - min(S1, S2, S3)
diff2 = max(T1, T2, S3) - min(T1, T2, S3)
ans = min(ans, diff1, diff2)
S1 -= h1
S2 -= h2
S3 += H
w -= 1
T1 = H * (w // 2)
T2 = H * w - T1
print(ans)
| H, W = list(map(int, input().split()))
if (H % 3) * (W % 3) == 0:
print((0))
quit()
ans = min(H, W)
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1
S2 = (H - 1) * w2
S3 = W
for i in range(H - 1):
diff = max(S1, S2, S3) - min(S1, S2, S3)
ans = min(ans, diff)
S1 -= w1
S2 -= w2
S3 += W
h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1
S2 = (W - 1) * h2
S3 = H
for i in range(W - 1):
diff = max(S1, S2, S3) - min(S1, S2, S3)
ans = min(ans, diff)
S1 -= h1
S2 -= h2
S3 += H
print(ans)
| false | 27.027027 | [
"-ans = H * W",
"+ans = min(H, W)",
"-T1 = W * ((H - 1) // 2)",
"-T2 = W * (H - 1) - T1",
"-h = H - 1",
"- diff1 = max(S1, S2, S3) - min(S1, S2, S3)",
"- diff2 = max(T1, T2, S3) - min(T1, T2, S3)",
"- ans = min(ans, diff1, diff2)",
"+ diff = max(S1, S2, S3) - min(S1, S2, S3)",
"+ ans = min(ans, diff)",
"- h -= 1",
"- T1 = W * (h // 2)",
"- T2 = W * h - T1",
"-T1 = H * ((W - 1) // 2)",
"-T2 = H * (W - 1) - T1",
"-w = W - 1",
"- diff1 = max(S1, S2, S3) - min(S1, S2, S3)",
"- diff2 = max(T1, T2, S3) - min(T1, T2, S3)",
"- ans = min(ans, diff1, diff2)",
"+ diff = max(S1, S2, S3) - min(S1, S2, S3)",
"+ ans = min(ans, diff)",
"- w -= 1",
"- T1 = H * (w // 2)",
"- T2 = H * w - T1"
] | false | 0.687813 | 0.315732 | 2.178472 | [
"s076933623",
"s947968681"
] |
u724687935 | p02971 | python | s319149361 | s915044250 | 854 | 409 | 55,816 | 71,644 | Accepted | Accepted | 52.11 | N = int(eval(input()))
one = (0, 0)
two = (0, 0)
for i in range(N):
A = int(eval(input()))
if A > one[0]:
two = one
one = (A, i)
elif A > two[0]:
two = (A, i)
for i in range(N):
if i == one[1]:
print((two[0]))
else:
print((one[0]))
| import sys
N = int(eval(input()))
one = (0, 0)
two = (0, 0)
for i, A in enumerate(map(int, sys.stdin.readlines())):
if A > one[0]:
two = one
one = (A, i)
elif A > two[0]:
two = (A, i)
for i in range(N):
if i == one[1]:
print((two[0]))
else:
print((one[0]))
| 17 | 18 | 294 | 323 | N = int(eval(input()))
one = (0, 0)
two = (0, 0)
for i in range(N):
A = int(eval(input()))
if A > one[0]:
two = one
one = (A, i)
elif A > two[0]:
two = (A, i)
for i in range(N):
if i == one[1]:
print((two[0]))
else:
print((one[0]))
| import sys
N = int(eval(input()))
one = (0, 0)
two = (0, 0)
for i, A in enumerate(map(int, sys.stdin.readlines())):
if A > one[0]:
two = one
one = (A, i)
elif A > two[0]:
two = (A, i)
for i in range(N):
if i == one[1]:
print((two[0]))
else:
print((one[0]))
| false | 5.555556 | [
"+import sys",
"+",
"-for i in range(N):",
"- A = int(eval(input()))",
"+for i, A in enumerate(map(int, sys.stdin.readlines())):"
] | false | 0.058211 | 0.083234 | 0.699367 | [
"s319149361",
"s915044250"
] |
u762420987 | p03147 | python | s880375365 | s028359153 | 159 | 18 | 12,496 | 3,060 | Accepted | Accepted | 88.68 | import numpy as np
N = int(eval(input()))
hlist = np.array([_ for _ in map(int,input().split())])
max = np.max(hlist)
min = np.min(hlist)
newlist = np.zeros_like(hlist)
num = 0
list = []
#+++++
for i in range(1,N):
sa = hlist[i-1]-hlist[i]
if sa > 0:
list.append(sa)
list.append(hlist[N-1])
print((sum(list)))
| N = int(eval(input()))
hlist = list(map(int, input().split()))
def count_island(height):
res = 0
sink = True
for h in hlist:
if sink and h > height:
res += 1
sink = False
if h <= height:
sink = True
return res
ans = 0
for height in range(max(hlist)):
ans += count_island(height)
print(ans) | 19 | 17 | 340 | 372 | import numpy as np
N = int(eval(input()))
hlist = np.array([_ for _ in map(int, input().split())])
max = np.max(hlist)
min = np.min(hlist)
newlist = np.zeros_like(hlist)
num = 0
list = []
# +++++
for i in range(1, N):
sa = hlist[i - 1] - hlist[i]
if sa > 0:
list.append(sa)
list.append(hlist[N - 1])
print((sum(list)))
| N = int(eval(input()))
hlist = list(map(int, input().split()))
def count_island(height):
res = 0
sink = True
for h in hlist:
if sink and h > height:
res += 1
sink = False
if h <= height:
sink = True
return res
ans = 0
for height in range(max(hlist)):
ans += count_island(height)
print(ans)
| false | 10.526316 | [
"-import numpy as np",
"+N = int(eval(input()))",
"+hlist = list(map(int, input().split()))",
"-N = int(eval(input()))",
"-hlist = np.array([_ for _ in map(int, input().split())])",
"-max = np.max(hlist)",
"-min = np.min(hlist)",
"-newlist = np.zeros_like(hlist)",
"-num = 0",
"-list = []",
"-for i in range(1, N):",
"- sa = hlist[i - 1] - hlist[i]",
"- if sa > 0:",
"- list.append(sa)",
"-list.append(hlist[N - 1])",
"-print((sum(list)))",
"+",
"+def count_island(height):",
"+ res = 0",
"+ sink = True",
"+ for h in hlist:",
"+ if sink and h > height:",
"+ res += 1",
"+ sink = False",
"+ if h <= height:",
"+ sink = True",
"+ return res",
"+",
"+",
"+ans = 0",
"+for height in range(max(hlist)):",
"+ ans += count_island(height)",
"+print(ans)"
] | false | 0.404523 | 0.039613 | 10.211816 | [
"s880375365",
"s028359153"
] |
u434967413 | p02820 | python | s525356784 | s418774488 | 95 | 57 | 4,800 | 4,212 | Accepted | Accepted | 40 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in eval(input())]
my_T = []
result = 0
for i in T:
if i == "r":
my_T.append("p")
elif i == "s":
my_T.append("r")
elif i == "p":
my_T.append("s")
for i in range(K, N):
if my_T[i] == my_T[i-K]:
if i+K < N:
if my_T[i+K] == "r":
my_T[i] = "s"
elif my_T[i+K] == "s":
my_T[i] = "p"
elif my_T[i+K] == "p":
my_T[i] = "r"
else:
if my_T[i-K] == "r":
my_T[i] = "s"
elif my_T[i-K] == "s":
my_T[i] = "p"
elif my_T[i-K] == "p":
my_T[i] = "r"
else:
if my_T[i] == "r":
result += R
elif my_T[i] == "s":
result += S
elif my_T[i] == "p":
result += P
for i in range(K):
if my_T[i] == "r":
result += R
elif my_T[i] == "s":
result += S
elif my_T[i] == "p":
result += P
print(result) | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in eval(input())]
result = 0
score = {"r": P, "s": R, "p": S}
for i in range(K):
result += score[T[i]]
for i in range(K, N):
if T[i] == T[i-K]:
T[i] = ""
continue
else:
result += score[T[i]]
print(result) | 48 | 16 | 1,226 | 363 | N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in eval(input())]
my_T = []
result = 0
for i in T:
if i == "r":
my_T.append("p")
elif i == "s":
my_T.append("r")
elif i == "p":
my_T.append("s")
for i in range(K, N):
if my_T[i] == my_T[i - K]:
if i + K < N:
if my_T[i + K] == "r":
my_T[i] = "s"
elif my_T[i + K] == "s":
my_T[i] = "p"
elif my_T[i + K] == "p":
my_T[i] = "r"
else:
if my_T[i - K] == "r":
my_T[i] = "s"
elif my_T[i - K] == "s":
my_T[i] = "p"
elif my_T[i - K] == "p":
my_T[i] = "r"
else:
if my_T[i] == "r":
result += R
elif my_T[i] == "s":
result += S
elif my_T[i] == "p":
result += P
for i in range(K):
if my_T[i] == "r":
result += R
elif my_T[i] == "s":
result += S
elif my_T[i] == "p":
result += P
print(result)
| N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = [i for i in eval(input())]
result = 0
score = {"r": P, "s": R, "p": S}
for i in range(K):
result += score[T[i]]
for i in range(K, N):
if T[i] == T[i - K]:
T[i] = ""
continue
else:
result += score[T[i]]
print(result)
| false | 66.666667 | [
"-my_T = []",
"-for i in T:",
"- if i == \"r\":",
"- my_T.append(\"p\")",
"- elif i == \"s\":",
"- my_T.append(\"r\")",
"- elif i == \"p\":",
"- my_T.append(\"s\")",
"+score = {\"r\": P, \"s\": R, \"p\": S}",
"+for i in range(K):",
"+ result += score[T[i]]",
"- if my_T[i] == my_T[i - K]:",
"- if i + K < N:",
"- if my_T[i + K] == \"r\":",
"- my_T[i] = \"s\"",
"- elif my_T[i + K] == \"s\":",
"- my_T[i] = \"p\"",
"- elif my_T[i + K] == \"p\":",
"- my_T[i] = \"r\"",
"- else:",
"- if my_T[i - K] == \"r\":",
"- my_T[i] = \"s\"",
"- elif my_T[i - K] == \"s\":",
"- my_T[i] = \"p\"",
"- elif my_T[i - K] == \"p\":",
"- my_T[i] = \"r\"",
"+ if T[i] == T[i - K]:",
"+ T[i] = \"\"",
"+ continue",
"- if my_T[i] == \"r\":",
"- result += R",
"- elif my_T[i] == \"s\":",
"- result += S",
"- elif my_T[i] == \"p\":",
"- result += P",
"-for i in range(K):",
"- if my_T[i] == \"r\":",
"- result += R",
"- elif my_T[i] == \"s\":",
"- result += S",
"- elif my_T[i] == \"p\":",
"- result += P",
"+ result += score[T[i]]"
] | false | 0.044853 | 0.037438 | 1.198062 | [
"s525356784",
"s418774488"
] |
u423585790 | p03295 | python | s586656487 | s314055595 | 449 | 398 | 60,508 | 55,900 | Accepted | Accepted | 11.36 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b, c = LI()
ans = 10 ** 5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
#B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No","Yes"][f]))
return
#C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
ab = LIR(m)
ab.sort(key=lambda x: x[1])
before = 0
ans = 0
for a, b in ab:
if a < before <= b:
continue
else:
before = b
ans += 1
print(ans)
return
#Solve
if __name__ == '__main__':
D()
| #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b, c = LI()
ans = 10 ** 5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
#B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No","Yes"][f]))
return
#C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
d = defaultdict(int)
for _ in range(m):
a, b = LI_()
d[a] = max(d[a], n-b)
mi = 0
ans = 0
for i in range(n-1):
mi = max(mi, d[i])
if i == n - mi - 1:
mi = 0
ans += 1
print(ans)
return
#Solve
if __name__ == '__main__':
D()
| 78 | 79 | 1,883 | 1,924 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list([int(x) - 1 for x in stdin.readline().split()])
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
a, b, c = LI()
ans = 10**5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
# B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No", "Yes"][f]))
return
# C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
ab = LIR(m)
ab.sort(key=lambda x: x[1])
before = 0
ans = 0
for a, b in ab:
if a < before <= b:
continue
else:
before = b
ans += 1
print(ans)
return
# Solve
if __name__ == "__main__":
D()
| #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list([int(x) - 1 for x in stdin.readline().split()])
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
a, b, c = LI()
ans = 10**5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
# B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No", "Yes"][f]))
return
# C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
d = defaultdict(int)
for _ in range(m):
a, b = LI_()
d[a] = max(d[a], n - b)
mi = 0
ans = 0
for i in range(n - 1):
mi = max(mi, d[i])
if i == n - mi - 1:
mi = 0
ans += 1
print(ans)
return
# Solve
if __name__ == "__main__":
D()
| false | 1.265823 | [
"- ab = LIR(m)",
"- ab.sort(key=lambda x: x[1])",
"- before = 0",
"+ d = defaultdict(int)",
"+ for _ in range(m):",
"+ a, b = LI_()",
"+ d[a] = max(d[a], n - b)",
"+ mi = 0",
"- for a, b in ab:",
"- if a < before <= b:",
"- continue",
"- else:",
"- before = b",
"+ for i in range(n - 1):",
"+ mi = max(mi, d[i])",
"+ if i == n - mi - 1:",
"+ mi = 0"
] | false | 0.046154 | 0.046855 | 0.985035 | [
"s586656487",
"s314055595"
] |
u864013199 | p02814 | python | s065463626 | s208915956 | 883 | 754 | 16,320 | 16,320 | Accepted | Accepted | 14.61 | from fractions import gcd
#from math import gcd
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
lcm = A[0]
lis = [[0] for _ in range(30)]
tmp = 0
while A[0]%2 == 0:
A[0]//= 2
tmp += 1
lis[tmp] = 1
for i in range(1,N):
tmp = 0
while A[i]%2 == 0:
A[i]//= 2
tmp += 1
lis[tmp] = 1
lcm = (lcm*A[i]) // gcd(lcm,A[i])
if lcm > 2*M:
print((0))
exit()
jud = False
for l in lis:
if l == 1:
if jud == True:
print((0))
exit()
else:
jud = True
M -= lcm//2
ans = (M//lcm)+1
print(ans)
| from fractions import gcd
#from math import gcd
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
lcm = A[0]
lis = [[0] for _ in range(30)]
tmp = 0
while A[0]%2 == 0:
A[0]//= 2
tmp += 1
lis[tmp] = 1
for i in range(1,N):
tmp = 0
Ai = A[i]
while Ai%2 == 0:
Ai//= 2
tmp += 1
lis[tmp] = 1
lcm = (lcm*A[i]) // gcd(lcm,A[i])
if lcm > 2*M:
print((0))
exit()
jud = False
if lis.count(1) > 1:
print((0))
exit()
M -= lcm//2
ans = (M//lcm)+1
print(ans)
| 35 | 32 | 638 | 560 | from fractions import gcd
# from math import gcd
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
lcm = A[0]
lis = [[0] for _ in range(30)]
tmp = 0
while A[0] % 2 == 0:
A[0] //= 2
tmp += 1
lis[tmp] = 1
for i in range(1, N):
tmp = 0
while A[i] % 2 == 0:
A[i] //= 2
tmp += 1
lis[tmp] = 1
lcm = (lcm * A[i]) // gcd(lcm, A[i])
if lcm > 2 * M:
print((0))
exit()
jud = False
for l in lis:
if l == 1:
if jud == True:
print((0))
exit()
else:
jud = True
M -= lcm // 2
ans = (M // lcm) + 1
print(ans)
| from fractions import gcd
# from math import gcd
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
lcm = A[0]
lis = [[0] for _ in range(30)]
tmp = 0
while A[0] % 2 == 0:
A[0] //= 2
tmp += 1
lis[tmp] = 1
for i in range(1, N):
tmp = 0
Ai = A[i]
while Ai % 2 == 0:
Ai //= 2
tmp += 1
lis[tmp] = 1
lcm = (lcm * A[i]) // gcd(lcm, A[i])
if lcm > 2 * M:
print((0))
exit()
jud = False
if lis.count(1) > 1:
print((0))
exit()
M -= lcm // 2
ans = (M // lcm) + 1
print(ans)
| false | 8.571429 | [
"- while A[i] % 2 == 0:",
"- A[i] //= 2",
"+ Ai = A[i]",
"+ while Ai % 2 == 0:",
"+ Ai //= 2",
"-for l in lis:",
"- if l == 1:",
"- if jud == True:",
"- print((0))",
"- exit()",
"- else:",
"- jud = True",
"+if lis.count(1) > 1:",
"+ print((0))",
"+ exit()"
] | false | 0.059947 | 0.060748 | 0.986823 | [
"s065463626",
"s208915956"
] |
u045953894 | p02767 | python | s581348721 | s427803280 | 59 | 17 | 3,060 | 2,940 | Accepted | Accepted | 71.19 | n = int(eval(input()))
x = list(map(int,input().split()))
S = sum(x)
Ave = sum(x) // n
m = 10**6
score = 0
for p in range(Ave,Ave+1001):
for i in range(n):
score += (x[i]-p)**2
if score < m:
m = score
score = 0
print(m) | #恐らく平均値に最も近い整数が答えになるかと思われる
n = int(eval(input()))
x = list(map(int,input().split()))
Ave = sum(x) / n
point = 0
for i in range(n):
point += (x[i]-round(Ave))**2
print(point) | 14 | 10 | 260 | 183 | n = int(eval(input()))
x = list(map(int, input().split()))
S = sum(x)
Ave = sum(x) // n
m = 10**6
score = 0
for p in range(Ave, Ave + 1001):
for i in range(n):
score += (x[i] - p) ** 2
if score < m:
m = score
score = 0
print(m)
| # 恐らく平均値に最も近い整数が答えになるかと思われる
n = int(eval(input()))
x = list(map(int, input().split()))
Ave = sum(x) / n
point = 0
for i in range(n):
point += (x[i] - round(Ave)) ** 2
print(point)
| false | 28.571429 | [
"+# 恐らく平均値に最も近い整数が答えになるかと思われる",
"-S = sum(x)",
"-Ave = sum(x) // n",
"-m = 10**6",
"-score = 0",
"-for p in range(Ave, Ave + 1001):",
"- for i in range(n):",
"- score += (x[i] - p) ** 2",
"- if score < m:",
"- m = score",
"- score = 0",
"-print(m)",
"+Ave = sum(x) / n",
"+point = 0",
"+for i in range(n):",
"+ point += (x[i] - round(Ave)) ** 2",
"+print(point)"
] | false | 0.045649 | 0.041452 | 1.101257 | [
"s581348721",
"s427803280"
] |
u494314211 | p02315 | python | s973952917 | s698195788 | 2,070 | 1,180 | 26,012 | 44,372 | Accepted | Accepted | 43 | l=[]
n,W=input().split()
n=int(n)
W=int(W)
for i in range(n):
item=list(map(int,input().split()))
l.append([item[1],item[0]])
dp=[[False for j in range(W+1)] for i in range(n+1)]
def solve(i,w):
if dp[i][w]==False:
if i==n:
res=(0)
elif w-l[i][0]<0:
res=(solve(i+1,w))
else:
a=solve(i+1,w)
b=l[i][1]+solve(i+1,w-l[i][0])
if b>a:
res=(b)
else:
res=(a)
dp[i][w]=res
return(res)
else:
return(dp[i][w])
print((solve(0,W))) | value=[0]
weight=[0]
n,W=input().split()
n=int(n)
W=int(W)
for i in range(n):
item=list(map(int,input().split()))
value.append(item[0])
weight.append(item[1])
dp=[[0 for j in range(W+1)] for i in range(n+1)]
for i in range(n+1):
for j in range(W+1):
if i==0:
res=0
elif j-weight[i]<0:
res=dp[i-1][j]
else:
res=max(dp[i-1][j-weight[i]]+value[i],dp[i-1][j])
dp[i][j]=res
print((dp[n][W])) | 29 | 21 | 489 | 426 | l = []
n, W = input().split()
n = int(n)
W = int(W)
for i in range(n):
item = list(map(int, input().split()))
l.append([item[1], item[0]])
dp = [[False for j in range(W + 1)] for i in range(n + 1)]
def solve(i, w):
if dp[i][w] == False:
if i == n:
res = 0
elif w - l[i][0] < 0:
res = solve(i + 1, w)
else:
a = solve(i + 1, w)
b = l[i][1] + solve(i + 1, w - l[i][0])
if b > a:
res = b
else:
res = a
dp[i][w] = res
return res
else:
return dp[i][w]
print((solve(0, W)))
| value = [0]
weight = [0]
n, W = input().split()
n = int(n)
W = int(W)
for i in range(n):
item = list(map(int, input().split()))
value.append(item[0])
weight.append(item[1])
dp = [[0 for j in range(W + 1)] for i in range(n + 1)]
for i in range(n + 1):
for j in range(W + 1):
if i == 0:
res = 0
elif j - weight[i] < 0:
res = dp[i - 1][j]
else:
res = max(dp[i - 1][j - weight[i]] + value[i], dp[i - 1][j])
dp[i][j] = res
print((dp[n][W]))
| false | 27.586207 | [
"-l = []",
"+value = [0]",
"+weight = [0]",
"- l.append([item[1], item[0]])",
"-dp = [[False for j in range(W + 1)] for i in range(n + 1)]",
"-",
"-",
"-def solve(i, w):",
"- if dp[i][w] == False:",
"- if i == n:",
"+ value.append(item[0])",
"+ weight.append(item[1])",
"+dp = [[0 for j in range(W + 1)] for i in range(n + 1)]",
"+for i in range(n + 1):",
"+ for j in range(W + 1):",
"+ if i == 0:",
"- elif w - l[i][0] < 0:",
"- res = solve(i + 1, w)",
"+ elif j - weight[i] < 0:",
"+ res = dp[i - 1][j]",
"- a = solve(i + 1, w)",
"- b = l[i][1] + solve(i + 1, w - l[i][0])",
"- if b > a:",
"- res = b",
"- else:",
"- res = a",
"- dp[i][w] = res",
"- return res",
"- else:",
"- return dp[i][w]",
"-",
"-",
"-print((solve(0, W)))",
"+ res = max(dp[i - 1][j - weight[i]] + value[i], dp[i - 1][j])",
"+ dp[i][j] = res",
"+print((dp[n][W]))"
] | false | 0.043098 | 0.046071 | 0.935469 | [
"s973952917",
"s698195788"
] |
u134302690 | p03624 | python | s568631642 | s431168002 | 194 | 73 | 40,940 | 3,188 | Accepted | Accepted | 62.37 | s = eval(input())
alfa = [chr(i) for i in range(97, 97+26)]
for i in range(len(alfa)):
for j in range(len(s)):
if alfa[i] == s[j]:
alfa[i] = "-"
for i in range(len(alfa)):
if alfa[i] != "-":
ans = alfa[i]
break
else:
ans = "None"
print(ans) | import sys
S = eval(input())
alfa = [chr(i) for i in range(97, 97+26)]
l = [0] * 26
for i in range(len(S)):
index = alfa.index(S[i])
l[index] += 1
for i in range(len(l)):
if l[i] == 0:
print((alfa[i]))
sys.exit()
print("None")
| 13 | 15 | 302 | 264 | s = eval(input())
alfa = [chr(i) for i in range(97, 97 + 26)]
for i in range(len(alfa)):
for j in range(len(s)):
if alfa[i] == s[j]:
alfa[i] = "-"
for i in range(len(alfa)):
if alfa[i] != "-":
ans = alfa[i]
break
else:
ans = "None"
print(ans)
| import sys
S = eval(input())
alfa = [chr(i) for i in range(97, 97 + 26)]
l = [0] * 26
for i in range(len(S)):
index = alfa.index(S[i])
l[index] += 1
for i in range(len(l)):
if l[i] == 0:
print((alfa[i]))
sys.exit()
print("None")
| false | 13.333333 | [
"-s = eval(input())",
"+import sys",
"+",
"+S = eval(input())",
"-for i in range(len(alfa)):",
"- for j in range(len(s)):",
"- if alfa[i] == s[j]:",
"- alfa[i] = \"-\"",
"-for i in range(len(alfa)):",
"- if alfa[i] != \"-\":",
"- ans = alfa[i]",
"- break",
"- else:",
"- ans = \"None\"",
"-print(ans)",
"+l = [0] * 26",
"+for i in range(len(S)):",
"+ index = alfa.index(S[i])",
"+ l[index] += 1",
"+for i in range(len(l)):",
"+ if l[i] == 0:",
"+ print((alfa[i]))",
"+ sys.exit()",
"+print(\"None\")"
] | false | 0.037691 | 0.045165 | 0.834515 | [
"s568631642",
"s431168002"
] |
u585482323 | p03739 | python | s060432238 | s464794320 | 284 | 255 | 60,116 | 59,376 | Accepted | Accepted | 10.21 | #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = SR()
return l
mod = 1000000007
#A
#B
#C
n = I()
a = LI()
b = [a[i] for i in range(n)]
ans = 0
k = a[0]
if a[0] == 0:
a[0] = 1
ans = 1
k = 1
for i in range(1,n):
if k*(k+a[i]) >= 0:
if k < 0:
ans += abs(1-k-a[i])
a[i] = 1-k
k = 1
else:
ans += abs(-1-k-a[i])
a[i] = -1-k
k = -1
else:
k += a[i]
if b[0] >= 0:
ans2 = b[0]+1
k = -1
b[0] = -1
else:
ans2 = 1-b[0]
k = 1
b[0] = 1
for i in range(1,n):
if k*(k+b[i]) >= 0:
if k < 0:
ans2 += abs(1-k-b[i])
b[i] = 1-k
k = 1
else:
ans2 += abs(-1-k-b[i])
b[i] = -1-k
k = -1
else:
k += b[i]
print((min(ans,ans2)))
#D
"""
x,y = LI()
if abs(x-y) <= 1:
print("Brown")
else:
print("Alice")
"""
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
| #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
a = LI()
ans = 0
s = a[0]
if s <= 0:
ans += 1-a[0]
s = 1
f = 1
for i in a[1:]:
s += i
if f and (s >= 0):
ans += s+1
s = -1
if not f and (s <= 0):
ans += 1-s
s = 1
f ^= 1
m = ans
ans = 0
s = a[0]
if s >= 0:
ans += a[0]+1
s = -1
f = 0
for i in a[1:]:
s += i
if f and (s >= 0):
ans += s+1
s = -1
if not f and (s <= 0):
ans += 1-s
s = 1
f ^= 1
print((min(m,ans)))
return
#Solve
if __name__ == "__main__":
solve()
| 116 | 67 | 1,766 | 1,419 | #!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = SR()
return l
mod = 1000000007
# A
# B
# C
n = I()
a = LI()
b = [a[i] for i in range(n)]
ans = 0
k = a[0]
if a[0] == 0:
a[0] = 1
ans = 1
k = 1
for i in range(1, n):
if k * (k + a[i]) >= 0:
if k < 0:
ans += abs(1 - k - a[i])
a[i] = 1 - k
k = 1
else:
ans += abs(-1 - k - a[i])
a[i] = -1 - k
k = -1
else:
k += a[i]
if b[0] >= 0:
ans2 = b[0] + 1
k = -1
b[0] = -1
else:
ans2 = 1 - b[0]
k = 1
b[0] = 1
for i in range(1, n):
if k * (k + b[i]) >= 0:
if k < 0:
ans2 += abs(1 - k - b[i])
b[i] = 1 - k
k = 1
else:
ans2 += abs(-1 - k - b[i])
b[i] = -1 - k
k = -1
else:
k += b[i]
print((min(ans, ans2)))
# D
"""
x,y = LI()
if abs(x-y) <= 1:
print("Brown")
else:
print("Alice")
"""
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
a = LI()
ans = 0
s = a[0]
if s <= 0:
ans += 1 - a[0]
s = 1
f = 1
for i in a[1:]:
s += i
if f and (s >= 0):
ans += s + 1
s = -1
if not f and (s <= 0):
ans += 1 - s
s = 1
f ^= 1
m = ans
ans = 0
s = a[0]
if s >= 0:
ans += a[0] + 1
s = -1
f = 0
for i in a[1:]:
s += i
if f and (s >= 0):
ans += s + 1
s = -1
if not f and (s <= 0):
ans += 1 - s
s = 1
f ^= 1
print((min(m, ans)))
return
# Solve
if __name__ == "__main__":
solve()
| false | 42.241379 | [
"-from collections import defaultdict",
"+from collections import defaultdict, deque",
"- return list(map(int, sys.stdin.readline().split()))",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"- return list(map(list, sys.stdin.readline().split()))",
"+ return [list(x) for x in sys.stdin.readline().split()]",
"- return list(sys.stdin.readline())[:-1]",
"+ res = list(sys.stdin.readline())",
"+ if res[-1] == \"\\n\":",
"+ return res[:-1]",
"+ return res",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = I()",
"- return l",
"+ return [I() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = LI()",
"- return l",
"+ return [LI() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = S()",
"- return l",
"+ return [S() for i in range(n)]",
"- l = [None for i in range(n)]",
"- for i in range(n):",
"- l[i] = SR()",
"- return l",
"+ return [LS() for i in range(n)]",
"+sys.setrecursionlimit(1000000)",
"-# A",
"-# B",
"-# C",
"-n = I()",
"-a = LI()",
"-b = [a[i] for i in range(n)]",
"-ans = 0",
"-k = a[0]",
"-if a[0] == 0:",
"- a[0] = 1",
"- ans = 1",
"- k = 1",
"-for i in range(1, n):",
"- if k * (k + a[i]) >= 0:",
"- if k < 0:",
"- ans += abs(1 - k - a[i])",
"- a[i] = 1 - k",
"- k = 1",
"- else:",
"- ans += abs(-1 - k - a[i])",
"- a[i] = -1 - k",
"- k = -1",
"- else:",
"- k += a[i]",
"-if b[0] >= 0:",
"- ans2 = b[0] + 1",
"- k = -1",
"- b[0] = -1",
"-else:",
"- ans2 = 1 - b[0]",
"- k = 1",
"- b[0] = 1",
"-for i in range(1, n):",
"- if k * (k + b[i]) >= 0:",
"- if k < 0:",
"- ans2 += abs(1 - k - b[i])",
"- b[i] = 1 - k",
"- k = 1",
"- else:",
"- ans2 += abs(-1 - k - b[i])",
"- b[i] = -1 - k",
"- k = -1",
"- else:",
"- k += b[i]",
"-print((min(ans, ans2)))",
"-# D",
"-\"\"\"",
"-x,y = LI()",
"-if abs(x-y) <= 1:",
"- print(\"Brown\")",
"-else:",
"- print(\"Alice\")",
"-\"\"\"",
"-# E",
"-# F",
"-# G",
"-# H",
"-# I",
"-# J",
"-# K",
"-# L",
"-# M",
"-# N",
"-# O",
"-# P",
"-# Q",
"-# R",
"-# S",
"-# T",
"+",
"+",
"+def solve():",
"+ n = I()",
"+ a = LI()",
"+ ans = 0",
"+ s = a[0]",
"+ if s <= 0:",
"+ ans += 1 - a[0]",
"+ s = 1",
"+ f = 1",
"+ for i in a[1:]:",
"+ s += i",
"+ if f and (s >= 0):",
"+ ans += s + 1",
"+ s = -1",
"+ if not f and (s <= 0):",
"+ ans += 1 - s",
"+ s = 1",
"+ f ^= 1",
"+ m = ans",
"+ ans = 0",
"+ s = a[0]",
"+ if s >= 0:",
"+ ans += a[0] + 1",
"+ s = -1",
"+ f = 0",
"+ for i in a[1:]:",
"+ s += i",
"+ if f and (s >= 0):",
"+ ans += s + 1",
"+ s = -1",
"+ if not f and (s <= 0):",
"+ ans += 1 - s",
"+ s = 1",
"+ f ^= 1",
"+ print((min(m, ans)))",
"+ return",
"+",
"+",
"+# Solve",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.093449 | 0.1269 | 0.736398 | [
"s060432238",
"s464794320"
] |
u039189422 | p03212 | python | s187284457 | s013562245 | 1,464 | 52 | 3,064 | 7,148 | Accepted | Accepted | 96.45 | def Base_10_to_n(x,n):
if (int(x/n)):
return Base_10_to_n(int(x/n),n)+str(x%n)
return str(x%n)
n=int(eval(input()))
l=len(str(n))
res=0
for i in range(4**l):
x=Base_10_to_n(i,4)
cnt=0
if not "0" in x:
if ("3" in x) and ("2" in x) and ("1" in x):
for j in range(len(x)):
if x[j]=="1":
cnt+=3*(10**j)
elif x[j]=="2":
cnt+=5*(10**j)
elif x[j]=="3":
cnt+=7*(10**j)
if cnt<=n:
res+=1
print(res)
| n=int(eval(input()))
A=["3","5","7"]
A=set(A)
cnt=0
for _ in range(len(str(n))-1):
for a in list(A):
x=a+"3"
y=a+"5"
z=a+"7"
if int(x)<=n:
A.add(x)
if int(y)<=n:
A.add(y)
if int(z)<=n:
A.add(z)
res=0
for a in list(A):
if "3" in a and "5" in a and "7" in a:
res+=1
print(res) | 27 | 24 | 467 | 322 | def Base_10_to_n(x, n):
if int(x / n):
return Base_10_to_n(int(x / n), n) + str(x % n)
return str(x % n)
n = int(eval(input()))
l = len(str(n))
res = 0
for i in range(4**l):
x = Base_10_to_n(i, 4)
cnt = 0
if not "0" in x:
if ("3" in x) and ("2" in x) and ("1" in x):
for j in range(len(x)):
if x[j] == "1":
cnt += 3 * (10**j)
elif x[j] == "2":
cnt += 5 * (10**j)
elif x[j] == "3":
cnt += 7 * (10**j)
if cnt <= n:
res += 1
print(res)
| n = int(eval(input()))
A = ["3", "5", "7"]
A = set(A)
cnt = 0
for _ in range(len(str(n)) - 1):
for a in list(A):
x = a + "3"
y = a + "5"
z = a + "7"
if int(x) <= n:
A.add(x)
if int(y) <= n:
A.add(y)
if int(z) <= n:
A.add(z)
res = 0
for a in list(A):
if "3" in a and "5" in a and "7" in a:
res += 1
print(res)
| false | 11.111111 | [
"-def Base_10_to_n(x, n):",
"- if int(x / n):",
"- return Base_10_to_n(int(x / n), n) + str(x % n)",
"- return str(x % n)",
"-",
"-",
"-l = len(str(n))",
"+A = [\"3\", \"5\", \"7\"]",
"+A = set(A)",
"+cnt = 0",
"+for _ in range(len(str(n)) - 1):",
"+ for a in list(A):",
"+ x = a + \"3\"",
"+ y = a + \"5\"",
"+ z = a + \"7\"",
"+ if int(x) <= n:",
"+ A.add(x)",
"+ if int(y) <= n:",
"+ A.add(y)",
"+ if int(z) <= n:",
"+ A.add(z)",
"-for i in range(4**l):",
"- x = Base_10_to_n(i, 4)",
"- cnt = 0",
"- if not \"0\" in x:",
"- if (\"3\" in x) and (\"2\" in x) and (\"1\" in x):",
"- for j in range(len(x)):",
"- if x[j] == \"1\":",
"- cnt += 3 * (10**j)",
"- elif x[j] == \"2\":",
"- cnt += 5 * (10**j)",
"- elif x[j] == \"3\":",
"- cnt += 7 * (10**j)",
"- if cnt <= n:",
"- res += 1",
"+for a in list(A):",
"+ if \"3\" in a and \"5\" in a and \"7\" in a:",
"+ res += 1"
] | false | 0.006704 | 0.042592 | 0.157392 | [
"s187284457",
"s013562245"
] |
u838006829 | p02412 | python | s568550878 | s262728510 | 130 | 120 | 5,608 | 5,608 | Accepted | Accepted | 7.69 | def countCombinations(n, x, size=3):
dp = [[0 for j in range(x + 1)] for i in range(size + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for row in range(size - 1, -1, -1):
for col in range(x + 1 - i):
dp[1+row][i+col] += dp[row][col]
return dp[-1][-1]
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
ans = countCombinations(m, n)
print(ans)
| def countCombinations(n, x, size=3):
dp = [[0 for j in range(x + 1)] for i in range(size + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for row in range(size - 1, -1, -1):
for col in range(x + 1 - i):
dp[1+row][i+col] += dp[row][col]
return dp[-1][-1]
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
print((countCombinations(m, n)))
| 17 | 14 | 464 | 445 | def countCombinations(n, x, size=3):
dp = [[0 for j in range(x + 1)] for i in range(size + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for row in range(size - 1, -1, -1):
for col in range(x + 1 - i):
dp[1 + row][i + col] += dp[row][col]
return dp[-1][-1]
while True:
m, n = (int(x) for x in input().split())
if m == 0 and n == 0:
quit()
ans = countCombinations(m, n)
print(ans)
| def countCombinations(n, x, size=3):
dp = [[0 for j in range(x + 1)] for i in range(size + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for row in range(size - 1, -1, -1):
for col in range(x + 1 - i):
dp[1 + row][i + col] += dp[row][col]
return dp[-1][-1]
while True:
m, n = (int(x) for x in input().split())
if m == 0 and n == 0:
quit()
print((countCombinations(m, n)))
| false | 17.647059 | [
"- ans = countCombinations(m, n)",
"- print(ans)",
"+ print((countCombinations(m, n)))"
] | false | 0.040584 | 0.038156 | 1.063624 | [
"s568550878",
"s262728510"
] |
u197968862 | p02684 | python | s422020059 | s051874786 | 176 | 104 | 32,876 | 95,496 | Accepted | Accepted | 40.91 | n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = [-1] * n
c = [1]
t = 0
now = 0
while s[now] == -1:
s[now] = t
now = a[now] - 1
c.append(now+1)
t += 1
start_cycle = c.index(c[-1])
loop = c[start_cycle:-1]
cycle = len(loop)
if k < start_cycle:
print((c[k]))
else:
k -= start_cycle
k %= cycle
print((loop[k])) | n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = [False] * n
c = [1]
now = 0
while not s[now]:
s[now] = True
now = a[now] - 1
c.append(now+1)
start_cycle = c.index(c[-1])
loop = c[start_cycle:-1]
cycle = len(loop)
if k < start_cycle:
print((c[k]))
else:
k -= start_cycle
k %= cycle
print((loop[k])) | 23 | 21 | 382 | 367 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = [-1] * n
c = [1]
t = 0
now = 0
while s[now] == -1:
s[now] = t
now = a[now] - 1
c.append(now + 1)
t += 1
start_cycle = c.index(c[-1])
loop = c[start_cycle:-1]
cycle = len(loop)
if k < start_cycle:
print((c[k]))
else:
k -= start_cycle
k %= cycle
print((loop[k]))
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = [False] * n
c = [1]
now = 0
while not s[now]:
s[now] = True
now = a[now] - 1
c.append(now + 1)
start_cycle = c.index(c[-1])
loop = c[start_cycle:-1]
cycle = len(loop)
if k < start_cycle:
print((c[k]))
else:
k -= start_cycle
k %= cycle
print((loop[k]))
| false | 8.695652 | [
"-s = [-1] * n",
"+s = [False] * n",
"-t = 0",
"-while s[now] == -1:",
"- s[now] = t",
"+while not s[now]:",
"+ s[now] = True",
"- t += 1"
] | false | 0.043402 | 0.102946 | 0.421599 | [
"s422020059",
"s051874786"
] |
u814986259 | p03364 | python | s580115577 | s934225514 | 1,051 | 638 | 39,928 | 37,808 | Accepted | Accepted | 39.3 | import collections
import sys
import numpy as np
input = sys.stdin.readline
table = collections.defaultdict(set)
N = int(eval(input()))
S = [list(input().rstrip()) for i in range(N)]
T = [[""] * (N*2) for i in range(2*N)]
table2 = [[set() for j in range(N)] for i in range(N)]
for i in range(2*N):
if i < N:
T[i] = S[i] + S[i]
else:
T[i] = S[i - N] + S[i-N]
ans = 0
T = np.array(T)
for i in range(N):
tmp = T[i:i+N, N-1-i:2*N-1-i]
if (tmp == tmp.T).all():
ans += N - (N // 2)
tmp = T[i+1:i+N+1, N-1-i:2*N-1-i]
if (tmp == tmp.T).all():
ans += N // 2
print(ans)
| import collections
import sys
import numpy as np
input = sys.stdin.readline
table = collections.defaultdict(set)
N = int(eval(input()))
S = [list(input().rstrip()) for i in range(N)]
T = [[""] * (N*2) for i in range(2*N)]
table2 = [[set() for j in range(N)] for i in range(N)]
for i in range(2*N):
if i < N:
T[i] = S[i] + S[i]
else:
T[i] = S[i - N] + S[i-N]
ans = 0
T = np.array(T)
for i in range(N):
tmp = T[0:N, i:i+N]
if (tmp == tmp.T).all():
ans += N
tmp = T[i+1:i+N+1, N-1-i:2*N-1-i]
print(ans)
| 28 | 24 | 641 | 563 | import collections
import sys
import numpy as np
input = sys.stdin.readline
table = collections.defaultdict(set)
N = int(eval(input()))
S = [list(input().rstrip()) for i in range(N)]
T = [[""] * (N * 2) for i in range(2 * N)]
table2 = [[set() for j in range(N)] for i in range(N)]
for i in range(2 * N):
if i < N:
T[i] = S[i] + S[i]
else:
T[i] = S[i - N] + S[i - N]
ans = 0
T = np.array(T)
for i in range(N):
tmp = T[i : i + N, N - 1 - i : 2 * N - 1 - i]
if (tmp == tmp.T).all():
ans += N - (N // 2)
tmp = T[i + 1 : i + N + 1, N - 1 - i : 2 * N - 1 - i]
if (tmp == tmp.T).all():
ans += N // 2
print(ans)
| import collections
import sys
import numpy as np
input = sys.stdin.readline
table = collections.defaultdict(set)
N = int(eval(input()))
S = [list(input().rstrip()) for i in range(N)]
T = [[""] * (N * 2) for i in range(2 * N)]
table2 = [[set() for j in range(N)] for i in range(N)]
for i in range(2 * N):
if i < N:
T[i] = S[i] + S[i]
else:
T[i] = S[i - N] + S[i - N]
ans = 0
T = np.array(T)
for i in range(N):
tmp = T[0:N, i : i + N]
if (tmp == tmp.T).all():
ans += N
tmp = T[i + 1 : i + N + 1, N - 1 - i : 2 * N - 1 - i]
print(ans)
| false | 14.285714 | [
"- tmp = T[i : i + N, N - 1 - i : 2 * N - 1 - i]",
"+ tmp = T[0:N, i : i + N]",
"- ans += N - (N // 2)",
"+ ans += N",
"- if (tmp == tmp.T).all():",
"- ans += N // 2"
] | false | 0.191992 | 0.192576 | 0.996968 | [
"s580115577",
"s934225514"
] |
u417365712 | p02948 | python | s186395509 | s742910198 | 253 | 204 | 28,652 | 24,932 | Accepted | Accepted | 19.37 | from heapq import heappop, heappush
n, m, *AB = list(map(int, open(0).read().split()))
AB = [(a, b) for a, b in zip(AB[::2], AB[1::2]) if a <= m]
AB_ = [[] for _ in range(m)]
for a, b in AB:
AB_[a-1].append(b)
ans = 0
heap = []
for ab in AB_:
for x in ab:
heappush(heap, -x)
if heap:
ans -= heappop(heap)
print(ans)
| from heapq import heappop, heappush
n, m, *AB = list(map(int, open(0).read().split()))
B = [[] for _ in range(m)]
for a, b in zip(AB[::2], AB[1::2]):
if a <= m:
B[a-1].append(b)
ans = 0
heap = []
for b in B:
for x in b:
heappush(heap, -x)
if heap:
ans -= heappop(heap)
print(ans)
| 15 | 15 | 353 | 325 | from heapq import heappop, heappush
n, m, *AB = list(map(int, open(0).read().split()))
AB = [(a, b) for a, b in zip(AB[::2], AB[1::2]) if a <= m]
AB_ = [[] for _ in range(m)]
for a, b in AB:
AB_[a - 1].append(b)
ans = 0
heap = []
for ab in AB_:
for x in ab:
heappush(heap, -x)
if heap:
ans -= heappop(heap)
print(ans)
| from heapq import heappop, heappush
n, m, *AB = list(map(int, open(0).read().split()))
B = [[] for _ in range(m)]
for a, b in zip(AB[::2], AB[1::2]):
if a <= m:
B[a - 1].append(b)
ans = 0
heap = []
for b in B:
for x in b:
heappush(heap, -x)
if heap:
ans -= heappop(heap)
print(ans)
| false | 0 | [
"-AB = [(a, b) for a, b in zip(AB[::2], AB[1::2]) if a <= m]",
"-AB_ = [[] for _ in range(m)]",
"-for a, b in AB:",
"- AB_[a - 1].append(b)",
"+B = [[] for _ in range(m)]",
"+for a, b in zip(AB[::2], AB[1::2]):",
"+ if a <= m:",
"+ B[a - 1].append(b)",
"-for ab in AB_:",
"- for x in ab:",
"+for b in B:",
"+ for x in b:"
] | false | 0.100172 | 0.079062 | 1.267004 | [
"s186395509",
"s742910198"
] |
u326609687 | p02889 | python | s274106859 | s224704069 | 303 | 270 | 39,344 | 32,884 | Accepted | Accepted | 10.89 | import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
i8 = np.int64
i4 = np.int32
def main():
stdin = open('/dev/stdin')
pin = np.fromstring(stdin.read(), i8, sep=' ')
N = pin[0]
M = pin[1]
L = pin[2]
ABC = pin[3: M * 3 + 3].reshape((-1, 3))
A = ABC[:, 0] - 1
B = ABC[:, 1] - 1
C = ABC[:, 2]
Q = pin[M * 3 + 3]
st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2))
s = st[:, 0]
t = st[:, 1]
graph = csr_matrix((C, (A, B)), shape=(N, N))
dist = np.array(floyd_warshall(graph, directed=False))
dist[dist > L + 0.5] = 0
dist[dist > 0] = 1
min_dist = np.array(floyd_warshall(dist))
min_dist[min_dist == np.inf] = 0
min_dist = (min_dist + .5).astype(int)
x = min_dist[s, t] - 1
print(('\n'.join(x.astype(str))))
if __name__ == '__main__':
main() | import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
i8 = np.int64
i4 = np.int32
def main():
stdin = open('/dev/stdin')
pin = np.fromstring(stdin.read(), i8, sep=' ')
N = pin[0]
M = pin[1]
L = pin[2]
ABC = pin[3: M * 3 + 3].reshape((-1, 3))
A = ABC[:, 0] - 1
B = ABC[:, 1] - 1
C = ABC[:, 2]
Q = pin[M * 3 + 3]
st = (pin[M * 3 + 4: 2 * Q + M * 3 + 4] - 1).reshape((-1, 2))
s = st[:, 0]
t = st[:, 1]
graph = csr_matrix((C, (A, B)), shape=(N, N))
dist = np.array(floyd_warshall(graph, directed=False))
dist[dist > L + 0.5] = 0
dist[dist > 0] = 1
min_dist = np.array(floyd_warshall(dist))
min_dist[min_dist == np.inf] = 0
min_dist = (min_dist + .5).astype(int)
x = min_dist[s, t] - 1
print(('\n'.join(x.astype(str).tolist())))
if __name__ == '__main__':
main()
| 36 | 36 | 928 | 938 | import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
i8 = np.int64
i4 = np.int32
def main():
stdin = open("/dev/stdin")
pin = np.fromstring(stdin.read(), i8, sep=" ")
N = pin[0]
M = pin[1]
L = pin[2]
ABC = pin[3 : M * 3 + 3].reshape((-1, 3))
A = ABC[:, 0] - 1
B = ABC[:, 1] - 1
C = ABC[:, 2]
Q = pin[M * 3 + 3]
st = (pin[M * 3 + 4 : 2 * Q + M * 3 + 4] - 1).reshape((-1, 2))
s = st[:, 0]
t = st[:, 1]
graph = csr_matrix((C, (A, B)), shape=(N, N))
dist = np.array(floyd_warshall(graph, directed=False))
dist[dist > L + 0.5] = 0
dist[dist > 0] = 1
min_dist = np.array(floyd_warshall(dist))
min_dist[min_dist == np.inf] = 0
min_dist = (min_dist + 0.5).astype(int)
x = min_dist[s, t] - 1
print(("\n".join(x.astype(str))))
if __name__ == "__main__":
main()
| import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
i8 = np.int64
i4 = np.int32
def main():
stdin = open("/dev/stdin")
pin = np.fromstring(stdin.read(), i8, sep=" ")
N = pin[0]
M = pin[1]
L = pin[2]
ABC = pin[3 : M * 3 + 3].reshape((-1, 3))
A = ABC[:, 0] - 1
B = ABC[:, 1] - 1
C = ABC[:, 2]
Q = pin[M * 3 + 3]
st = (pin[M * 3 + 4 : 2 * Q + M * 3 + 4] - 1).reshape((-1, 2))
s = st[:, 0]
t = st[:, 1]
graph = csr_matrix((C, (A, B)), shape=(N, N))
dist = np.array(floyd_warshall(graph, directed=False))
dist[dist > L + 0.5] = 0
dist[dist > 0] = 1
min_dist = np.array(floyd_warshall(dist))
min_dist[min_dist == np.inf] = 0
min_dist = (min_dist + 0.5).astype(int)
x = min_dist[s, t] - 1
print(("\n".join(x.astype(str).tolist())))
if __name__ == "__main__":
main()
| false | 0 | [
"- print((\"\\n\".join(x.astype(str))))",
"+ print((\"\\n\".join(x.astype(str).tolist())))"
] | false | 0.273739 | 0.336015 | 0.814662 | [
"s274106859",
"s224704069"
] |
u790710233 | p02640 | python | s187354815 | s579405929 | 24 | 20 | 9,184 | 9,168 | Accepted | Accepted | 16.67 | X, Y = list(map(int, input().split()))
for x in range(10000):
y = X-x
if y < 0:
continue
z = x*2+4*y
if z == Y:
print('Yes')
break
else:
print('No')
| A, B = list(map(int, input().split()))
for x in range(101):
y = A-x
if y < 0:
continue
if 2*x+4*y == B:
print('Yes')
break
else:
print('No')
| 12 | 11 | 199 | 186 | X, Y = list(map(int, input().split()))
for x in range(10000):
y = X - x
if y < 0:
continue
z = x * 2 + 4 * y
if z == Y:
print("Yes")
break
else:
print("No")
| A, B = list(map(int, input().split()))
for x in range(101):
y = A - x
if y < 0:
continue
if 2 * x + 4 * y == B:
print("Yes")
break
else:
print("No")
| false | 8.333333 | [
"-X, Y = list(map(int, input().split()))",
"-for x in range(10000):",
"- y = X - x",
"+A, B = list(map(int, input().split()))",
"+for x in range(101):",
"+ y = A - x",
"- z = x * 2 + 4 * y",
"- if z == Y:",
"+ if 2 * x + 4 * y == B:"
] | false | 0.049226 | 0.090248 | 0.545452 | [
"s187354815",
"s579405929"
] |
u525065967 | p02596 | python | s541711725 | s310184575 | 1,531 | 187 | 9,132 | 9,116 | Accepted | Accepted | 87.79 | # k = int(input())
K = eval(input())
k = int(K)
# if k%2 == 0:
# print(-1)
# exit()
# r7 = 7%k
r = 0
for i in range(1,k*10):
r = (r*10 + 7)%k
# print('r {} i {}'.format(r,i))
if r == 0:
print(i)
exit()
# print(n)
print((-1))
| k = int(eval(input()))
r = 0
for i in range(1, k+1):
r = (r*10 + 7)%k
if r == 0:
print(i)
exit()
print((-1))
| 18 | 8 | 276 | 132 | # k = int(input())
K = eval(input())
k = int(K)
# if k%2 == 0:
# print(-1)
# exit()
# r7 = 7%k
r = 0
for i in range(1, k * 10):
r = (r * 10 + 7) % k
# print('r {} i {}'.format(r,i))
if r == 0:
print(i)
exit()
# print(n)
print((-1))
| k = int(eval(input()))
r = 0
for i in range(1, k + 1):
r = (r * 10 + 7) % k
if r == 0:
print(i)
exit()
print((-1))
| false | 55.555556 | [
"-# k = int(input())",
"-K = eval(input())",
"-k = int(K)",
"-# if k%2 == 0:",
"-# print(-1)",
"-# exit()",
"-# r7 = 7%k",
"+k = int(eval(input()))",
"-for i in range(1, k * 10):",
"+for i in range(1, k + 1):",
"- # print('r {} i {}'.format(r,i))",
"- # print(n)"
] | false | 0.131666 | 0.065189 | 2.019767 | [
"s541711725",
"s310184575"
] |
u638456847 | p02631 | python | s137596626 | s541890789 | 787 | 142 | 42,788 | 30,892 | Accepted | Accepted | 81.96 | from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,*A = list(map(int, read().split()))
L = [A[0]]
R = deque([A[-1]])
for i in range(1,N):
L.append(L[-1] ^ A[i])
R.appendleft(R[0] ^ A[-(i+1)])
ans = [R[1]]
for i in range(1,N-1):
ans.append(L[i-1] ^ R[i+1])
ans.append(L[-2])
print((*ans))
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,*A = list(map(int, read().split()))
X = 0
for a in A:
X ^= a
ans = []
for a in A:
ans.append(a ^ X)
print((*ans))
if __name__ == "__main__":
main()
| 27 | 21 | 500 | 323 | from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, *A = list(map(int, read().split()))
L = [A[0]]
R = deque([A[-1]])
for i in range(1, N):
L.append(L[-1] ^ A[i])
R.appendleft(R[0] ^ A[-(i + 1)])
ans = [R[1]]
for i in range(1, N - 1):
ans.append(L[i - 1] ^ R[i + 1])
ans.append(L[-2])
print((*ans))
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, *A = list(map(int, read().split()))
X = 0
for a in A:
X ^= a
ans = []
for a in A:
ans.append(a ^ X)
print((*ans))
if __name__ == "__main__":
main()
| false | 22.222222 | [
"-from collections import deque",
"- L = [A[0]]",
"- R = deque([A[-1]])",
"- for i in range(1, N):",
"- L.append(L[-1] ^ A[i])",
"- R.appendleft(R[0] ^ A[-(i + 1)])",
"- ans = [R[1]]",
"- for i in range(1, N - 1):",
"- ans.append(L[i - 1] ^ R[i + 1])",
"- ans.append(L[-2])",
"+ X = 0",
"+ for a in A:",
"+ X ^= a",
"+ ans = []",
"+ for a in A:",
"+ ans.append(a ^ X)"
] | false | 0.065725 | 0.06634 | 0.990725 | [
"s137596626",
"s541890789"
] |
u333945892 | p03863 | python | s880958834 | s762119886 | 32 | 17 | 5,228 | 3,316 | Accepted | Accepted | 46.88 | from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
S = list(eval(input()))
L = len(S)
if L%2 == 1:
if S[0] == S[-1]:
print('Second')
else:
print('First')
else:
if S[0] != S[-1]:
print('Second')
else:
print('First')
| S = eval(input())
L = len(S)
if S[0]==S[-1]:
if L%2==0:
print("First")
else:
print("Second")
else:
if L%2==1:
print("First")
else:
print("Second") | 21 | 13 | 463 | 201 | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
def inpl():
return list(map(int, input().split()))
def inpl_s():
return list(input().split())
S = list(eval(input()))
L = len(S)
if L % 2 == 1:
if S[0] == S[-1]:
print("Second")
else:
print("First")
else:
if S[0] != S[-1]:
print("Second")
else:
print("First")
| S = eval(input())
L = len(S)
if S[0] == S[-1]:
if L % 2 == 0:
print("First")
else:
print("Second")
else:
if L % 2 == 1:
print("First")
else:
print("Second")
| false | 38.095238 | [
"-from collections import defaultdict, deque",
"-import sys, heapq, bisect, math, itertools, string, queue, datetime",
"-",
"-sys.setrecursionlimit(10**8)",
"-INF = float(\"inf\")",
"-mod = 10**9 + 7",
"-eps = 10**-7",
"-",
"-",
"-def inpl():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def inpl_s():",
"- return list(input().split())",
"-",
"-",
"-S = list(eval(input()))",
"+S = eval(input())",
"-if L % 2 == 1:",
"- if S[0] == S[-1]:",
"+if S[0] == S[-1]:",
"+ if L % 2 == 0:",
"+ print(\"First\")",
"+ else:",
"+else:",
"+ if L % 2 == 1:",
"+ print(\"First\")",
"- print(\"First\")",
"-else:",
"- if S[0] != S[-1]:",
"- else:",
"- print(\"First\")"
] | false | 0.038418 | 0.038334 | 1.002194 | [
"s880958834",
"s762119886"
] |
u358919705 | p00010 | python | s794785392 | s333881423 | 30 | 20 | 7,596 | 7,664 | Accepted | Accepted | 33.33 | for _ in range(int(eval(input()))):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
d = 2 * (x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3 + x1 * y2 - x2 * y1)
px = ((y2 - y3) * (x1 ** 2 + y1 ** 2) + (y3 - y1) * (x2 ** 2 + y2 ** 2) + (y1 - y2) * (x3 ** 2 + y3 ** 2)) / d
py = -1 * ((x2 - x3) * (x1 ** 2 + y1 ** 2) + (x3 - x1) * (x2 ** 2 + y2 ** 2) + (x1 - x2) * (x3 ** 2 + y3 ** 2)) / d
print(('{0:.3f} {1:.3f} {2:.3f}'.format(px, py, ((x1 - px) ** 2 + (y1 - py) ** 2) ** 0.5))) | for _ in[0]*int(eval(input())):
a,d,b,e,c,f=list(map(float,input().split()))
z=2*(b*f-c*e+c*d-a*f+a*e-b*d)
x=((e-f)*(a**2+d**2)+(f-d)*(b**2+e**2)+(d-e)*(c**2+f**2))/z
y=((c-b)*(a**2+d**2)+(a-c)*(b**2+e**2)+(b-a)*(c**2+f**2))/z
print(('{0:.3f} {1:.3f} {2:.3f}'.format(x,y,((a-x)**2+(d-y)**2)**0.5))) | 6 | 6 | 492 | 294 | for _ in range(int(eval(input()))):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
d = 2 * (x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3 + x1 * y2 - x2 * y1)
px = (
(y2 - y3) * (x1**2 + y1**2)
+ (y3 - y1) * (x2**2 + y2**2)
+ (y1 - y2) * (x3**2 + y3**2)
) / d
py = (
-1
* (
(x2 - x3) * (x1**2 + y1**2)
+ (x3 - x1) * (x2**2 + y2**2)
+ (x1 - x2) * (x3**2 + y3**2)
)
/ d
)
print(
(
"{0:.3f} {1:.3f} {2:.3f}".format(
px, py, ((x1 - px) ** 2 + (y1 - py) ** 2) ** 0.5
)
)
)
| for _ in [0] * int(eval(input())):
a, d, b, e, c, f = list(map(float, input().split()))
z = 2 * (b * f - c * e + c * d - a * f + a * e - b * d)
x = (
(e - f) * (a**2 + d**2)
+ (f - d) * (b**2 + e**2)
+ (d - e) * (c**2 + f**2)
) / z
y = (
(c - b) * (a**2 + d**2)
+ (a - c) * (b**2 + e**2)
+ (b - a) * (c**2 + f**2)
) / z
print(
("{0:.3f} {1:.3f} {2:.3f}".format(x, y, ((a - x) ** 2 + (d - y) ** 2) ** 0.5))
)
| false | 0 | [
"-for _ in range(int(eval(input()))):",
"- x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))",
"- d = 2 * (x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3 + x1 * y2 - x2 * y1)",
"- px = (",
"- (y2 - y3) * (x1**2 + y1**2)",
"- + (y3 - y1) * (x2**2 + y2**2)",
"- + (y1 - y2) * (x3**2 + y3**2)",
"- ) / d",
"- py = (",
"- -1",
"- * (",
"- (x2 - x3) * (x1**2 + y1**2)",
"- + (x3 - x1) * (x2**2 + y2**2)",
"- + (x1 - x2) * (x3**2 + y3**2)",
"- )",
"- / d",
"+for _ in [0] * int(eval(input())):",
"+ a, d, b, e, c, f = list(map(float, input().split()))",
"+ z = 2 * (b * f - c * e + c * d - a * f + a * e - b * d)",
"+ x = (",
"+ (e - f) * (a**2 + d**2)",
"+ + (f - d) * (b**2 + e**2)",
"+ + (d - e) * (c**2 + f**2)",
"+ ) / z",
"+ y = (",
"+ (c - b) * (a**2 + d**2)",
"+ + (a - c) * (b**2 + e**2)",
"+ + (b - a) * (c**2 + f**2)",
"+ ) / z",
"+ print(",
"+ (\"{0:.3f} {1:.3f} {2:.3f}\".format(x, y, ((a - x) ** 2 + (d - y) ** 2) ** 0.5))",
"- print(",
"- (",
"- \"{0:.3f} {1:.3f} {2:.3f}\".format(",
"- px, py, ((x1 - px) ** 2 + (y1 - py) ** 2) ** 0.5",
"- )",
"- )",
"- )"
] | false | 0.073594 | 0.052131 | 1.411718 | [
"s794785392",
"s333881423"
] |
u318127926 | p03583 | python | s708678207 | s820544438 | 1,995 | 206 | 43,216 | 40,556 | Accepted | Accepted | 89.67 | N = int(eval(input()))
for h in range(1, 3501):
for n in range(h, 3501):
ok = 0
ng = 3501
while abs(ok-ng)>1:
w = (ok+ng)//2
if 4*h*n*w<=N*(n*w+w*h+h*n):
ok = w
else:
ng = w
if 4*h*n*ok==N*(n*ok+ok*h+h*n):
print((h, n, ok))
exit() | N = int(eval(input()))
for h in range(1, 3501):
for n in range(h, 3501):
if (4*h*n-N*n-N*h)>0 and (N*h*n)%(4*h*n-N*n-N*h)==0:
print((h, n, (N*h*n)//(4*h*n-N*n-N*h)))
exit() | 14 | 6 | 363 | 205 | N = int(eval(input()))
for h in range(1, 3501):
for n in range(h, 3501):
ok = 0
ng = 3501
while abs(ok - ng) > 1:
w = (ok + ng) // 2
if 4 * h * n * w <= N * (n * w + w * h + h * n):
ok = w
else:
ng = w
if 4 * h * n * ok == N * (n * ok + ok * h + h * n):
print((h, n, ok))
exit()
| N = int(eval(input()))
for h in range(1, 3501):
for n in range(h, 3501):
if (4 * h * n - N * n - N * h) > 0 and (N * h * n) % (
4 * h * n - N * n - N * h
) == 0:
print((h, n, (N * h * n) // (4 * h * n - N * n - N * h)))
exit()
| false | 57.142857 | [
"- ok = 0",
"- ng = 3501",
"- while abs(ok - ng) > 1:",
"- w = (ok + ng) // 2",
"- if 4 * h * n * w <= N * (n * w + w * h + h * n):",
"- ok = w",
"- else:",
"- ng = w",
"- if 4 * h * n * ok == N * (n * ok + ok * h + h * n):",
"- print((h, n, ok))",
"+ if (4 * h * n - N * n - N * h) > 0 and (N * h * n) % (",
"+ 4 * h * n - N * n - N * h",
"+ ) == 0:",
"+ print((h, n, (N * h * n) // (4 * h * n - N * n - N * h)))"
] | false | 0.006085 | 0.660311 | 0.009215 | [
"s708678207",
"s820544438"
] |
u535803878 | p02950 | python | s355707252 | s138174087 | 1,867 | 228 | 75,480 | 75,340 | Accepted | Accepted | 87.79 | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
p = int(eval(input()))
a = list(map(int, input().split()))
### 素数の逆元とCombination
M = p
N = 10**4 # 必要なテーブルサイズ
g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range( 2, N + 1 ):
g1[i] = ( g1[i-1] * i ) % M
inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
g2[i] = (g2[i-1] * inverse[i]) % M
def cmb(n, r, M):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return (g1[n] * g2[r] * g2[n-r]) % M
ans = [0]*p
for i,num in enumerate(a):
if num==0:
continue
for j in range(p):
ans[j] += -cmb(p-1,j,M) * pow(-i,p-1-j,M)
ans[j] %= M
ans[0] += 1
for i in range(p):
ans[i] %= M
write(" ".join(map(str, ans))) | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
p = int(eval(input()))
a = list(map(int, input().split()))
### 素数の逆元とCombination
M = p
N = 10**4 # 必要なテーブルサイズ
g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range( 2, N + 1 ):
g1[i] = ( g1[i-1] * i ) % M
inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
g2[i] = (g2[i-1] * inverse[i]) % M
def cmb(n, r, M):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return (g1[n] * g2[r] * g2[n-r]) % M
ans = [0]*p
for i,num in enumerate(a):
if num==0:
continue
val = 1
for j in reversed(list(range(p))):
ans[j] += -cmb(p-1,j,M) * val #pow(-i,p-1-j,M)
# ans[j] += -cmb(p-1,j,M) * pow(-i,p-1-j,M)
ans[j] %= M
val *= -i
val %= M
ans[0] += 1
for i in range(p):
ans[i] %= M
write(" ".join(map(str, ans))) | 41 | 45 | 1,027 | 1,145 | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
p = int(eval(input()))
a = list(map(int, input().split()))
### 素数の逆元とCombination
M = p
N = 10**4 # 必要なテーブルサイズ
g1 = [None] * (N + 1) # 元テーブル
g2 = [None] * (N + 1) # 逆元テーブル
inverse = [None] * (N + 1) # 逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range(2, N + 1):
g1[i] = (g1[i - 1] * i) % M
inverse[i] = (
-inverse[M % i] * (M // i)
) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
g2[i] = (g2[i - 1] * inverse[i]) % M
def cmb(n, r, M):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return (g1[n] * g2[r] * g2[n - r]) % M
ans = [0] * p
for i, num in enumerate(a):
if num == 0:
continue
for j in range(p):
ans[j] += -cmb(p - 1, j, M) * pow(-i, p - 1 - j, M)
ans[j] %= M
ans[0] += 1
for i in range(p):
ans[i] %= M
write(" ".join(map(str, ans)))
| import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
p = int(eval(input()))
a = list(map(int, input().split()))
### 素数の逆元とCombination
M = p
N = 10**4 # 必要なテーブルサイズ
g1 = [None] * (N + 1) # 元テーブル
g2 = [None] * (N + 1) # 逆元テーブル
inverse = [None] * (N + 1) # 逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range(2, N + 1):
g1[i] = (g1[i - 1] * i) % M
inverse[i] = (
-inverse[M % i] * (M // i)
) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
g2[i] = (g2[i - 1] * inverse[i]) % M
def cmb(n, r, M):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return (g1[n] * g2[r] * g2[n - r]) % M
ans = [0] * p
for i, num in enumerate(a):
if num == 0:
continue
val = 1
for j in reversed(list(range(p))):
ans[j] += -cmb(p - 1, j, M) * val # pow(-i,p-1-j,M)
# ans[j] += -cmb(p-1,j,M) * pow(-i,p-1-j,M)
ans[j] %= M
val *= -i
val %= M
ans[0] += 1
for i in range(p):
ans[i] %= M
write(" ".join(map(str, ans)))
| false | 8.888889 | [
"- for j in range(p):",
"- ans[j] += -cmb(p - 1, j, M) * pow(-i, p - 1 - j, M)",
"+ val = 1",
"+ for j in reversed(list(range(p))):",
"+ ans[j] += -cmb(p - 1, j, M) * val # pow(-i,p-1-j,M)",
"+ # ans[j] += -cmb(p-1,j,M) * pow(-i,p-1-j,M)",
"+ val *= -i",
"+ val %= M"
] | false | 0.056923 | 0.082171 | 0.692741 | [
"s355707252",
"s138174087"
] |
u063550903 | p02881 | python | s213733912 | s245811924 | 258 | 160 | 3,060 | 3,060 | Accepted | Accepted | 37.98 | N = int(eval(input()))
ans = []
for i in range(1,int(pow(N,0.5))+1):
j = N//i
if i*j == N:
ans.append(i+j)
print((min(ans)-2)) | N = int(eval(input()))
ans = []
for i in range(1,int(pow(N,0.5))+1):
if N%i==0:
ans.append(i+N//i)
print((min(ans)-2)) | 8 | 7 | 142 | 129 | N = int(eval(input()))
ans = []
for i in range(1, int(pow(N, 0.5)) + 1):
j = N // i
if i * j == N:
ans.append(i + j)
print((min(ans) - 2))
| N = int(eval(input()))
ans = []
for i in range(1, int(pow(N, 0.5)) + 1):
if N % i == 0:
ans.append(i + N // i)
print((min(ans) - 2))
| false | 12.5 | [
"- j = N // i",
"- if i * j == N:",
"- ans.append(i + j)",
"+ if N % i == 0:",
"+ ans.append(i + N // i)"
] | false | 0.040809 | 0.039634 | 1.029637 | [
"s213733912",
"s245811924"
] |
u044220565 | p02617 | python | s346333784 | s274109239 | 518 | 308 | 9,264 | 9,196 | Accepted | Accepted | 40.54 | # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba
def sum_between(a, b):
if a > b:a, b = b, a
return (b-a+1) * (b+a) // 2
def run():
N = int(eval(input()))
n_dots = 0
for i in range(1, N+1):
n_dots += (1+i) * i // 2
#print(n_dots)
ans = (N-1) * (N+1) * N // 2
#print(ans)
for i in range(N-1):
l, r = list(map(int, input().split()))
if l > r: l,r = r,l
tmp = 0
if l > 1: tmp += sum_between(r-1, r-l+1)
tmp += r-l
tmp += sum_between(N-l, 1)
#print(tmp)
ans -= tmp
print((n_dots - ans))
ans = (N-1) * N * N
if __name__ == "__main__":
run() | # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba
def sum_between(a, b):
if a > b:a, b = b, a
return (b-a+1) * (b+a) // 2
def run():
N = int(eval(input()))
n_dots = 0
for i in range(1, N+1):
n_dots += (1+i) * i // 2
#print(n_dots)
ans = (N-1) * (N+1) * N // 2
#print(ans)
for i in range(N-1):
l, r = list(map(int, sysread().split()))
if l > r: l,r = r,l
tmp = 0
if l > 1: tmp += sum_between(r-1, r-l+1)
tmp += r-l
tmp += sum_between(N-l, 1)
#print(tmp)
ans -= tmp
print((n_dots - ans))
ans = (N-1) * N * N
if __name__ == "__main__":
run() | 46 | 46 | 1,076 | 1,078 | # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**7)
from heapq import heappop, heappush
# from collections import OrderedDict, defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
# import numpy as np
# from copy import deepcopy
# from collections import deque
# import numba
def sum_between(a, b):
if a > b:
a, b = b, a
return (b - a + 1) * (b + a) // 2
def run():
N = int(eval(input()))
n_dots = 0
for i in range(1, N + 1):
n_dots += (1 + i) * i // 2
# print(n_dots)
ans = (N - 1) * (N + 1) * N // 2
# print(ans)
for i in range(N - 1):
l, r = list(map(int, input().split()))
if l > r:
l, r = r, l
tmp = 0
if l > 1:
tmp += sum_between(r - 1, r - l + 1)
tmp += r - l
tmp += sum_between(N - l, 1)
# print(tmp)
ans -= tmp
print((n_dots - ans))
ans = (N - 1) * N * N
if __name__ == "__main__":
run()
| # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**7)
from heapq import heappop, heappush
# from collections import OrderedDict, defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
# import numpy as np
# from copy import deepcopy
# from collections import deque
# import numba
def sum_between(a, b):
if a > b:
a, b = b, a
return (b - a + 1) * (b + a) // 2
def run():
N = int(eval(input()))
n_dots = 0
for i in range(1, N + 1):
n_dots += (1 + i) * i // 2
# print(n_dots)
ans = (N - 1) * (N + 1) * N // 2
# print(ans)
for i in range(N - 1):
l, r = list(map(int, sysread().split()))
if l > r:
l, r = r, l
tmp = 0
if l > 1:
tmp += sum_between(r - 1, r - l + 1)
tmp += r - l
tmp += sum_between(N - l, 1)
# print(tmp)
ans -= tmp
print((n_dots - ans))
ans = (N - 1) * N * N
if __name__ == "__main__":
run()
| false | 0 | [
"- l, r = list(map(int, input().split()))",
"+ l, r = list(map(int, sysread().split()))"
] | false | 0.03705 | 0.039619 | 0.935172 | [
"s346333784",
"s274109239"
] |
u784022244 | p03329 | python | s598213647 | s211391562 | 506 | 84 | 3,828 | 74,664 | Accepted | Accepted | 83.4 | N=int(eval(input()))
L=[1]
for i in range(1,100):
a=6**i
if a<=100000:
L.append(a)
else:
break
for i in range(1,100):
a=9**i
if a<=100000:
L.append(a)
else:
break
dp=[1000000]*(N+1)
dp[0]=0
for i in range(1,N+1):
sub=10**5
for l in L:
if i-l>=0:
sub=min(sub, dp[i-l]+1)
dp[i]=sub
print((dp[N])) | N=int(eval(input()))
L=[1]
now=6
while now<=10**6:
L.append(now)
now*=6
now=9
while now<=10**6:
L.append(now)
now*=9
#print(L)
dp=[float("INF")]*(N+1)
dp[0]=0
for i in range(1,N+1):
for x in L:
if i-x>=0:
dp[i]=min(dp[i], dp[i-x]+1)
print((dp[N]))
#print(dp) | 24 | 19 | 398 | 308 | N = int(eval(input()))
L = [1]
for i in range(1, 100):
a = 6**i
if a <= 100000:
L.append(a)
else:
break
for i in range(1, 100):
a = 9**i
if a <= 100000:
L.append(a)
else:
break
dp = [1000000] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
sub = 10**5
for l in L:
if i - l >= 0:
sub = min(sub, dp[i - l] + 1)
dp[i] = sub
print((dp[N]))
| N = int(eval(input()))
L = [1]
now = 6
while now <= 10**6:
L.append(now)
now *= 6
now = 9
while now <= 10**6:
L.append(now)
now *= 9
# print(L)
dp = [float("INF")] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
for x in L:
if i - x >= 0:
dp[i] = min(dp[i], dp[i - x] + 1)
print((dp[N]))
# print(dp)
| false | 20.833333 | [
"-for i in range(1, 100):",
"- a = 6**i",
"- if a <= 100000:",
"- L.append(a)",
"- else:",
"- break",
"-for i in range(1, 100):",
"- a = 9**i",
"- if a <= 100000:",
"- L.append(a)",
"- else:",
"- break",
"-dp = [1000000] * (N + 1)",
"+now = 6",
"+while now <= 10**6:",
"+ L.append(now)",
"+ now *= 6",
"+now = 9",
"+while now <= 10**6:",
"+ L.append(now)",
"+ now *= 9",
"+# print(L)",
"+dp = [float(\"INF\")] * (N + 1)",
"- sub = 10**5",
"- for l in L:",
"- if i - l >= 0:",
"- sub = min(sub, dp[i - l] + 1)",
"- dp[i] = sub",
"+ for x in L:",
"+ if i - x >= 0:",
"+ dp[i] = min(dp[i], dp[i - x] + 1)",
"+# print(dp)"
] | false | 0.133092 | 0.094151 | 1.413594 | [
"s598213647",
"s211391562"
] |
u017810624 | p02960 | python | s785766475 | s927749588 | 964 | 798 | 69,512 | 66,876 | Accepted | Accepted | 17.22 | s=list(eval(input()))
s.reverse()
l=[1,10,9,12,3,4]
p=10**9+7
dp=[[0 for i in range(13)] for j in range(len(s))]
if s[0]=='?':
for i in range(10):
dp[0][i]+=1
else:
dp[0][int(s[0])]+=1
for i in range(1,len(s)):
if s[i]!='?':
for j in range(13):
dp[i][j]+=dp[i-1][(j-(int(s[i])*l[i%6]))%13]
dp[i][j]%=p
else:
for j in range(13):
for k in range(10):
dp[i][j]+=dp[i-1][(j-k*l[i%6])%13]
dp[i][j]%=p
print((dp[len(s)-1][5])) | s=list(eval(input()))
n=len(s)
s.reverse()
mod=10**9+7
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
x=1
for i in range(n):
for j in range(13):
if s[i]=='?':
for k in range(10):
dp[i+1][j]+=dp[i][(j-(k*x)%13+13)%13]
else:
dp[i+1][j]+=dp[i][(j-(int(s[i])*x)%13+13)%13]
dp[i+1][j]%=mod
x*=10
x%=13
print((dp[n][5])) | 21 | 18 | 485 | 357 | s = list(eval(input()))
s.reverse()
l = [1, 10, 9, 12, 3, 4]
p = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(len(s))]
if s[0] == "?":
for i in range(10):
dp[0][i] += 1
else:
dp[0][int(s[0])] += 1
for i in range(1, len(s)):
if s[i] != "?":
for j in range(13):
dp[i][j] += dp[i - 1][(j - (int(s[i]) * l[i % 6])) % 13]
dp[i][j] %= p
else:
for j in range(13):
for k in range(10):
dp[i][j] += dp[i - 1][(j - k * l[i % 6]) % 13]
dp[i][j] %= p
print((dp[len(s) - 1][5]))
| s = list(eval(input()))
n = len(s)
s.reverse()
mod = 10**9 + 7
dp = [[0] * 13 for i in range(n + 1)]
dp[0][0] = 1
x = 1
for i in range(n):
for j in range(13):
if s[i] == "?":
for k in range(10):
dp[i + 1][j] += dp[i][(j - (k * x) % 13 + 13) % 13]
else:
dp[i + 1][j] += dp[i][(j - (int(s[i]) * x) % 13 + 13) % 13]
dp[i + 1][j] %= mod
x *= 10
x %= 13
print((dp[n][5]))
| false | 14.285714 | [
"+n = len(s)",
"-l = [1, 10, 9, 12, 3, 4]",
"-p = 10**9 + 7",
"-dp = [[0 for i in range(13)] for j in range(len(s))]",
"-if s[0] == \"?\":",
"- for i in range(10):",
"- dp[0][i] += 1",
"-else:",
"- dp[0][int(s[0])] += 1",
"-for i in range(1, len(s)):",
"- if s[i] != \"?\":",
"- for j in range(13):",
"- dp[i][j] += dp[i - 1][(j - (int(s[i]) * l[i % 6])) % 13]",
"- dp[i][j] %= p",
"- else:",
"- for j in range(13):",
"+mod = 10**9 + 7",
"+dp = [[0] * 13 for i in range(n + 1)]",
"+dp[0][0] = 1",
"+x = 1",
"+for i in range(n):",
"+ for j in range(13):",
"+ if s[i] == \"?\":",
"- dp[i][j] += dp[i - 1][(j - k * l[i % 6]) % 13]",
"- dp[i][j] %= p",
"-print((dp[len(s) - 1][5]))",
"+ dp[i + 1][j] += dp[i][(j - (k * x) % 13 + 13) % 13]",
"+ else:",
"+ dp[i + 1][j] += dp[i][(j - (int(s[i]) * x) % 13 + 13) % 13]",
"+ dp[i + 1][j] %= mod",
"+ x *= 10",
"+ x %= 13",
"+print((dp[n][5]))"
] | false | 0.038366 | 0.043685 | 0.878223 | [
"s785766475",
"s927749588"
] |
u711539583 | p02960 | python | s130422023 | s863993925 | 728 | 568 | 69,376 | 66,140 | Accepted | Accepted | 21.98 | s = eval(input())
mod = 10 ** 9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
memo[i+1] = memo[i] * 10 % 13
if si == '?':
for n in range(10):
a = n * memo[i]
for j in range(13):
dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
else:
a = int(si) * memo[i]
for j in range(13):
dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
print((dp[len(s)][5]))
| s = eval(input())
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s):
if si == '?':
for n in range(10):
for j in range(13):
dp[i+1][(n + j * 10) % 13] += dp[i][j]
else:
for j in range(13):
dp[i+1][(int(si) + j * 10) % 13] += dp[i][j]
for k in range(13):
dp[i+1][k] = dp[i+1][k] % mod
print((dp[len(s)][5]))
| 18 | 15 | 576 | 455 | s = eval(input())
mod = 10**9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
memo[i + 1] = memo[i] * 10 % 13
if si == "?":
for n in range(10):
a = n * memo[i]
for j in range(13):
dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod
else:
a = int(si) * memo[i]
for j in range(13):
dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod
print((dp[len(s)][5]))
| s = eval(input())
mod = 10**9 + 7
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s):
if si == "?":
for n in range(10):
for j in range(13):
dp[i + 1][(n + j * 10) % 13] += dp[i][j]
else:
for j in range(13):
dp[i + 1][(int(si) + j * 10) % 13] += dp[i][j]
for k in range(13):
dp[i + 1][k] = dp[i + 1][k] % mod
print((dp[len(s)][5]))
| false | 16.666667 | [
"-memo = [0] * (len(s) + 1)",
"-memo[0] = 1",
"-for i, si in enumerate(s[::-1]):",
"- memo[i + 1] = memo[i] * 10 % 13",
"+for i, si in enumerate(s):",
"- a = n * memo[i]",
"- dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod",
"+ dp[i + 1][(n + j * 10) % 13] += dp[i][j]",
"- a = int(si) * memo[i]",
"- dp[i + 1][(j + a) % 13] = (dp[i + 1][(j + a) % 13] + dp[i][j]) % mod",
"+ dp[i + 1][(int(si) + j * 10) % 13] += dp[i][j]",
"+ for k in range(13):",
"+ dp[i + 1][k] = dp[i + 1][k] % mod"
] | false | 0.007432 | 0.036452 | 0.203879 | [
"s130422023",
"s863993925"
] |
u762540523 | p02713 | python | s729923623 | s087509573 | 1,101 | 826 | 15,880 | 9,204 | Accepted | Accepted | 24.98 | from functools import lru_cache
@lru_cache(maxsize=100000)
def gcd(a, b):
while b:
a, b = b, a % b
return a
def resolve():
k = int(eval(input()))
l = [None] * k ** 2
for i in range(k):
for j in range(k):
l[i * k + j] = gcd(i + 1, j + 1)
ans = 0
for i in l:
for j in range(k):
ans += gcd(i, j + 1)
print(ans)
if __name__ == '__main__':
resolve()
| from math import gcd
def resolve():
k = int(eval(input()))
l = [None] * k ** 2
for i in range(k):
for j in range(k):
l[i * k + j] = gcd(i + 1, j + 1)
ans = 0
for i in l:
for j in range(k):
ans += gcd(i, j + 1)
print(ans)
if __name__ == '__main__':
resolve()
| 24 | 17 | 451 | 339 | from functools import lru_cache
@lru_cache(maxsize=100000)
def gcd(a, b):
while b:
a, b = b, a % b
return a
def resolve():
k = int(eval(input()))
l = [None] * k**2
for i in range(k):
for j in range(k):
l[i * k + j] = gcd(i + 1, j + 1)
ans = 0
for i in l:
for j in range(k):
ans += gcd(i, j + 1)
print(ans)
if __name__ == "__main__":
resolve()
| from math import gcd
def resolve():
k = int(eval(input()))
l = [None] * k**2
for i in range(k):
for j in range(k):
l[i * k + j] = gcd(i + 1, j + 1)
ans = 0
for i in l:
for j in range(k):
ans += gcd(i, j + 1)
print(ans)
if __name__ == "__main__":
resolve()
| false | 29.166667 | [
"-from functools import lru_cache",
"-",
"-",
"-@lru_cache(maxsize=100000)",
"-def gcd(a, b):",
"- while b:",
"- a, b = b, a % b",
"- return a",
"+from math import gcd"
] | false | 0.108412 | 0.221094 | 0.490344 | [
"s729923623",
"s087509573"
] |
u208713671 | p04001 | python | s718742383 | s603233292 | 87 | 79 | 68,260 | 71,928 | Accepted | Accepted | 9.2 | S = list(eval(input()))
N = len(S)
def calc(T):
N = len(T)
t = 0
ans = 0
tmp = 0
while T[t]!="=":
if T[t]=="+":
ans += tmp
tmp = 0
t+=1
continue
else:
tmp = 10*tmp+int(T[t])
t+=1
ans += tmp
return ans
from itertools import product
LS = list(product([0,1], repeat=N-1))
out = 0
for L in LS:
T = S[0]
for i in range(N-1):
if L[i]==1:
T += "+"+S[i+1]
else:
T += S[i+1]
T += "="
out += calc(T)
print(out) | S = list(eval(input()))
N = len(S)
from itertools import product
LS = list(product([0,1], repeat=N-1))
out = 0
for L in LS:
T = S[0]
for i in range(N-1):
if L[i]==1:
T += "+"+S[i+1]
else:
T += S[i+1]
A = list(map(int,T.split("+")))
out += sum(A)
print(out) | 33 | 16 | 600 | 322 | S = list(eval(input()))
N = len(S)
def calc(T):
N = len(T)
t = 0
ans = 0
tmp = 0
while T[t] != "=":
if T[t] == "+":
ans += tmp
tmp = 0
t += 1
continue
else:
tmp = 10 * tmp + int(T[t])
t += 1
ans += tmp
return ans
from itertools import product
LS = list(product([0, 1], repeat=N - 1))
out = 0
for L in LS:
T = S[0]
for i in range(N - 1):
if L[i] == 1:
T += "+" + S[i + 1]
else:
T += S[i + 1]
T += "="
out += calc(T)
print(out)
| S = list(eval(input()))
N = len(S)
from itertools import product
LS = list(product([0, 1], repeat=N - 1))
out = 0
for L in LS:
T = S[0]
for i in range(N - 1):
if L[i] == 1:
T += "+" + S[i + 1]
else:
T += S[i + 1]
A = list(map(int, T.split("+")))
out += sum(A)
print(out)
| false | 51.515152 | [
"-",
"-",
"-def calc(T):",
"- N = len(T)",
"- t = 0",
"- ans = 0",
"- tmp = 0",
"- while T[t] != \"=\":",
"- if T[t] == \"+\":",
"- ans += tmp",
"- tmp = 0",
"- t += 1",
"- continue",
"- else:",
"- tmp = 10 * tmp + int(T[t])",
"- t += 1",
"- ans += tmp",
"- return ans",
"-",
"-",
"- T += \"=\"",
"- out += calc(T)",
"+ A = list(map(int, T.split(\"+\")))",
"+ out += sum(A)"
] | false | 0.03976 | 0.041975 | 0.947239 | [
"s718742383",
"s603233292"
] |
u810356688 | p03037 | python | s487301459 | s181686791 | 544 | 163 | 47,416 | 6,980 | Accepted | Accepted | 70.04 | def main():
n,m=list(map(int,input().split()))
CARD=[0]*(n+1)
for i in range(m):
L,R=list(map(int,input().split()))
CARD[L-1]+=1
CARD[R]-=1
ans=0
for i in range(n):
if CARD[i]==m:ans+=1
CARD[i+1]=CARD[i+1]+CARD[i]
print(ans)
if __name__=='__main__':
main() | def main():
import sys
input = sys.stdin.readline
n,m=list(map(int,input().split()))
CARD=[0]*(n+1)
for i in range(m):
L,R=list(map(int,input().split()))
CARD[L-1]+=1
CARD[R]-=1
ans=0
for i in range(n):
if CARD[i]==m:ans+=1
CARD[i+1]=CARD[i+1]+CARD[i]
print(ans)
if __name__=='__main__':
main()
| 16 | 19 | 329 | 380 | def main():
n, m = list(map(int, input().split()))
CARD = [0] * (n + 1)
for i in range(m):
L, R = list(map(int, input().split()))
CARD[L - 1] += 1
CARD[R] -= 1
ans = 0
for i in range(n):
if CARD[i] == m:
ans += 1
CARD[i + 1] = CARD[i + 1] + CARD[i]
print(ans)
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
CARD = [0] * (n + 1)
for i in range(m):
L, R = list(map(int, input().split()))
CARD[L - 1] += 1
CARD[R] -= 1
ans = 0
for i in range(n):
if CARD[i] == m:
ans += 1
CARD[i + 1] = CARD[i + 1] + CARD[i]
print(ans)
if __name__ == "__main__":
main()
| false | 15.789474 | [
"+ import sys",
"+",
"+ input = sys.stdin.readline"
] | false | 0.163586 | 0.110491 | 1.480532 | [
"s487301459",
"s181686791"
] |
u075595666 | p03045 | python | s456611350 | s417908046 | 528 | 354 | 13,992 | 14,316 | Accepted | Accepted | 32.95 | #Union Find
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
#xとyの属する集合の併合
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
n,m = [int(i) for i in input().split()]
par = [-1]*n
for i in range(m):
x,y,z = [int(i)-1 for i in input().split()]
unite(x,y)
chk = []
for i in range(n):
chk_append = chk.append
chk_append(find(i))
chk = set(chk)
print((len(chk))) | #Union Find
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
#xとyの属する集合の併合
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
import sys
input = sys.stdin.readline
n,m = [int(i) for i in input().split()]
par = [-1]*n
for i in range(m):
x,y,z = [int(i)-1 for i in input().split()]
unite(x,y)
import collections
chk = []
chk = collections.deque(chk)
for i in range(n):
chk_append = chk.append
chk_append(find(i))
chk = set(chk)
print((len(chk))) | 42 | 46 | 738 | 830 | # Union Find
# xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
# xとyの属する集合の併合
def unite(x, y):
x = find(x)
y = find(y)
if x == y:
return False
else:
# sizeの大きいほうがx
if par[x] > par[y]:
x, y = y, x
par[x] += par[y]
par[y] = x
return True
# xとyが同じ集合に属するかの判定
def same(x, y):
return find(x) == find(y)
n, m = [int(i) for i in input().split()]
par = [-1] * n
for i in range(m):
x, y, z = [int(i) - 1 for i in input().split()]
unite(x, y)
chk = []
for i in range(n):
chk_append = chk.append
chk_append(find(i))
chk = set(chk)
print((len(chk)))
| # Union Find
# xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
# xとyの属する集合の併合
def unite(x, y):
x = find(x)
y = find(y)
if x == y:
return False
else:
# sizeの大きいほうがx
if par[x] > par[y]:
x, y = y, x
par[x] += par[y]
par[y] = x
return True
# xとyが同じ集合に属するかの判定
def same(x, y):
return find(x) == find(y)
import sys
input = sys.stdin.readline
n, m = [int(i) for i in input().split()]
par = [-1] * n
for i in range(m):
x, y, z = [int(i) - 1 for i in input().split()]
unite(x, y)
import collections
chk = []
chk = collections.deque(chk)
for i in range(n):
chk_append = chk.append
chk_append(find(i))
chk = set(chk)
print((len(chk)))
| false | 8.695652 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+import collections",
"+",
"+chk = collections.deque(chk)"
] | false | 0.048126 | 0.055226 | 0.871427 | [
"s456611350",
"s417908046"
] |
u063073794 | p02701 | python | s648227091 | s715254534 | 359 | 299 | 35,136 | 31,104 | Accepted | Accepted | 16.71 | n=int(eval(input()))
d=dict()
for i in range(n):
s="".join(eval(input()))
#print(s)
if s in d:
d[s]+=1
else:
d[s]=1
ans=0
for x in list(d.values()):
ans+=1
print(ans) | n= int(eval(input()))
kk=set()
for i in range(n):
s=eval(input())
kk.add(s)
print((len(kk))) | 14 | 6 | 180 | 87 | n = int(eval(input()))
d = dict()
for i in range(n):
s = "".join(eval(input()))
# print(s)
if s in d:
d[s] += 1
else:
d[s] = 1
ans = 0
for x in list(d.values()):
ans += 1
print(ans)
| n = int(eval(input()))
kk = set()
for i in range(n):
s = eval(input())
kk.add(s)
print((len(kk)))
| false | 57.142857 | [
"-d = dict()",
"+kk = set()",
"- s = \"\".join(eval(input()))",
"- # print(s)",
"- if s in d:",
"- d[s] += 1",
"- else:",
"- d[s] = 1",
"-ans = 0",
"-for x in list(d.values()):",
"- ans += 1",
"-print(ans)",
"+ s = eval(input())",
"+ kk.add(s)",
"+print((len(kk)))"
] | false | 0.054301 | 0.082759 | 0.656137 | [
"s648227091",
"s715254534"
] |
u813371068 | p03220 | python | s626885810 | s594976687 | 20 | 18 | 3,060 | 3,060 | Accepted | Accepted | 10 | n=int(eval(input()))
t,a=list(map(int,input().split()))
h=list(map(int,input().split()))
z=[abs(t-x*0.006-a) for x in h]
print((z.index(min(z))+1)) | n = int(eval(input()))
T,A = list(map(int, input().split()))
H = list(map(int, input().split()))
z = [abs(A - (T - h*0.006)) for h in H]
print(( z.index(min(z)) +1 )) | 5 | 5 | 137 | 156 | n = int(eval(input()))
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))
z = [abs(t - x * 0.006 - a) for x in h]
print((z.index(min(z)) + 1))
| n = int(eval(input()))
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))
z = [abs(A - (T - h * 0.006)) for h in H]
print((z.index(min(z)) + 1))
| false | 0 | [
"-t, a = list(map(int, input().split()))",
"-h = list(map(int, input().split()))",
"-z = [abs(t - x * 0.006 - a) for x in h]",
"+T, A = list(map(int, input().split()))",
"+H = list(map(int, input().split()))",
"+z = [abs(A - (T - h * 0.006)) for h in H]"
] | false | 0.039777 | 0.039258 | 1.013198 | [
"s626885810",
"s594976687"
] |
u191874006 | p03103 | python | s484779363 | s056849462 | 498 | 411 | 27,760 | 58,332 | Accepted | Accepted | 17.47 | #!/usr/bin/env python3
#ABC121 C
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
cost = 0
count = 0
AB.sort()
for i in range(N):
if count == M:
break
elif count < M:
if AB[i][1] + count < M:
cost += AB[i][0]*AB[i][1]
count += AB[i][1]
elif AB[i][1] + count == M:
cost += AB[i][0]*AB[i][1]
break
else:
cost += AB[i][0]*(M - count)
break
print(cost)
| #!/usr/bin/env python3
#ABC121 C
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,m = LI()
h = []
for _ in range(n):
a,b = LI()
heappush(h,(a,b))
cnt = 0
ans = 0
while cnt < m:
a,b = heappop(h)
if b + cnt <= m:
cnt += b
ans += a*b
else:
ans += (m-cnt)*a
cnt = m
print(ans)
| 24 | 36 | 525 | 771 | #!/usr/bin/env python3
# ABC121 C
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
cost = 0
count = 0
AB.sort()
for i in range(N):
if count == M:
break
elif count < M:
if AB[i][1] + count < M:
cost += AB[i][0] * AB[i][1]
count += AB[i][1]
elif AB[i][1] + count == M:
cost += AB[i][0] * AB[i][1]
break
else:
cost += AB[i][0] * (M - count)
break
print(cost)
| #!/usr/bin/env python3
# ABC121 C
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n, m = LI()
h = []
for _ in range(n):
a, b = LI()
heappush(h, (a, b))
cnt = 0
ans = 0
while cnt < m:
a, b = heappop(h)
if b + cnt <= m:
cnt += b
ans += a * b
else:
ans += (m - cnt) * a
cnt = m
print(ans)
| false | 33.333333 | [
"-N, M = list(map(int, input().split()))",
"-AB = [list(map(int, input().split())) for _ in range(N)]",
"-cost = 0",
"-count = 0",
"-AB.sort()",
"-for i in range(N):",
"- if count == M:",
"- break",
"- elif count < M:",
"- if AB[i][1] + count < M:",
"- cost += AB[i][0] * AB[i][1]",
"- count += AB[i][1]",
"- elif AB[i][1] + count == M:",
"- cost += AB[i][0] * AB[i][1]",
"- break",
"- else:",
"- cost += AB[i][0] * (M - count)",
"- break",
"-print(cost)",
"+import sys",
"+import math",
"+import bisect",
"+",
"+sys.setrecursionlimit(1000000000)",
"+from heapq import heappush, heappop, heappushpop",
"+from collections import defaultdict",
"+from itertools import accumulate",
"+from collections import Counter",
"+from collections import deque",
"+from operator import itemgetter",
"+from itertools import permutations",
"+",
"+mod = 10**9 + 7",
"+inf = float(\"inf\")",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+n, m = LI()",
"+h = []",
"+for _ in range(n):",
"+ a, b = LI()",
"+ heappush(h, (a, b))",
"+cnt = 0",
"+ans = 0",
"+while cnt < m:",
"+ a, b = heappop(h)",
"+ if b + cnt <= m:",
"+ cnt += b",
"+ ans += a * b",
"+ else:",
"+ ans += (m - cnt) * a",
"+ cnt = m",
"+print(ans)"
] | false | 0.046631 | 0.047752 | 0.976523 | [
"s484779363",
"s056849462"
] |
u567281053 | p02276 | python | s386659875 | s850464182 | 160 | 60 | 15,212 | 18,436 | Accepted | Accepted | 62.5 | import sys
def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
swap(A, i, j)
swap(A, i + 1, r)
return i + 1
def swap(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
if __name__ == "__main__":
lines = sys.stdin.readlines()
A = list(map(int, lines[1].split()))
q = partition(A, 0, len(A) - 1)
pre = ""
suf = ""
for i in range(len(A) - 1):
if i == q:
pre = "["
suf = "]"
print(pre + str(A[i]) + suf, end=' ')
pre = ""
suf = ""
print(A[i + 1]) | import sys
def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
if __name__ == "__main__":
lines = sys.stdin.readlines()
A = list(map(int, lines[1].split()))
q = partition(A, 0, len(A) - 1)
A = list(map(str, A))
A[q] = "[" + A[q] + "]"
print(" ".join(A)) | 33 | 20 | 658 | 441 | import sys
def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
swap(A, i, j)
swap(A, i + 1, r)
return i + 1
def swap(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
if __name__ == "__main__":
lines = sys.stdin.readlines()
A = list(map(int, lines[1].split()))
q = partition(A, 0, len(A) - 1)
pre = ""
suf = ""
for i in range(len(A) - 1):
if i == q:
pre = "["
suf = "]"
print(pre + str(A[i]) + suf, end=" ")
pre = ""
suf = ""
print(A[i + 1])
| import sys
def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
if __name__ == "__main__":
lines = sys.stdin.readlines()
A = list(map(int, lines[1].split()))
q = partition(A, 0, len(A) - 1)
A = list(map(str, A))
A[q] = "[" + A[q] + "]"
print(" ".join(A))
| false | 39.393939 | [
"- swap(A, i, j)",
"- swap(A, i + 1, r)",
"+ A[i], A[j] = A[j], A[i]",
"+ A[i + 1], A[r] = A[r], A[i + 1]",
"-",
"-",
"-def swap(array, i, j):",
"- tmp = array[i]",
"- array[i] = array[j]",
"- array[j] = tmp",
"- pre = \"\"",
"- suf = \"\"",
"- for i in range(len(A) - 1):",
"- if i == q:",
"- pre = \"[\"",
"- suf = \"]\"",
"- print(pre + str(A[i]) + suf, end=\" \")",
"- pre = \"\"",
"- suf = \"\"",
"- print(A[i + 1])",
"+ A = list(map(str, A))",
"+ A[q] = \"[\" + A[q] + \"]\"",
"+ print(\" \".join(A))"
] | false | 0.03734 | 0.036885 | 1.012328 | [
"s386659875",
"s850464182"
] |
u977389981 | p02994 | python | s429720571 | s089364372 | 172 | 17 | 38,384 | 3,060 | Accepted | Accepted | 90.12 | N, L = list(map(int, input().split()))
A = []
for i in range(1, N + 1):
A.append(L + i - 1)
cur_diff = float('inf')
ans = float('inf')
Sum = sum(A)
for a in A:
tmp = Sum - a
diff = abs(Sum - tmp)
if diff < cur_diff:
cur_diff = diff
ans = tmp
print(ans) | N, L = list(map(int, input().split()))
sumA = 0
for i in range(N):
sumA += (L + i)
cur_diff = float('inf')
ans = 0
for i in range(N):
tmp = sumA - (L + i)
diff = abs(sumA - tmp)
if diff < cur_diff:
cur_diff = diff
ans = tmp
print(ans) | 17 | 16 | 302 | 290 | N, L = list(map(int, input().split()))
A = []
for i in range(1, N + 1):
A.append(L + i - 1)
cur_diff = float("inf")
ans = float("inf")
Sum = sum(A)
for a in A:
tmp = Sum - a
diff = abs(Sum - tmp)
if diff < cur_diff:
cur_diff = diff
ans = tmp
print(ans)
| N, L = list(map(int, input().split()))
sumA = 0
for i in range(N):
sumA += L + i
cur_diff = float("inf")
ans = 0
for i in range(N):
tmp = sumA - (L + i)
diff = abs(sumA - tmp)
if diff < cur_diff:
cur_diff = diff
ans = tmp
print(ans)
| false | 5.882353 | [
"-A = []",
"-for i in range(1, N + 1):",
"- A.append(L + i - 1)",
"+sumA = 0",
"+for i in range(N):",
"+ sumA += L + i",
"-ans = float(\"inf\")",
"-Sum = sum(A)",
"-for a in A:",
"- tmp = Sum - a",
"- diff = abs(Sum - tmp)",
"+ans = 0",
"+for i in range(N):",
"+ tmp = sumA - (L + i)",
"+ diff = abs(sumA - tmp)"
] | false | 0.041789 | 0.106819 | 0.391212 | [
"s429720571",
"s089364372"
] |
u514894322 | p03037 | python | s932159288 | s980565913 | 293 | 137 | 3,060 | 3,060 | Accepted | Accepted | 53.24 | n,m = list(map(int,input().split()))
#ll = [list(map(int,input().split())) for _ in [0]*m]
#l=[]
#r=[]
#for i in range(m):
# l.append(ll[i][0])
# r.append(ll[i][1])
#l = max(l)
#r = min(r)
l=0
r=n
for _ in range(m):
a,b = list(map(int,input().split()))
l = l if l>a else a
r = r if r<b else b
print((max([0,r-l+1]))) | from sys import stdin
n,m = list(map(int,stdin.readline().split()))
#ll = [list(map(int,input().split())) for _ in [0]*m]
#l=[]
#r=[]
#for i in range(m):
# l.append(ll[i][0])
# r.append(ll[i][1])
#l = max(l)
#r = min(r)
l=0
r=n
for _ in range(m):
a,b = list(map(int,stdin.readline().split()))
l = l if l>a else a
r = r if r<b else b
print((max([0,r-l+1]))) | 17 | 18 | 327 | 368 | n, m = list(map(int, input().split()))
# ll = [list(map(int,input().split())) for _ in [0]*m]
# l=[]
# r=[]
# for i in range(m):
# l.append(ll[i][0])
# r.append(ll[i][1])
# l = max(l)
# r = min(r)
l = 0
r = n
for _ in range(m):
a, b = list(map(int, input().split()))
l = l if l > a else a
r = r if r < b else b
print((max([0, r - l + 1])))
| from sys import stdin
n, m = list(map(int, stdin.readline().split()))
# ll = [list(map(int,input().split())) for _ in [0]*m]
# l=[]
# r=[]
# for i in range(m):
# l.append(ll[i][0])
# r.append(ll[i][1])
# l = max(l)
# r = min(r)
l = 0
r = n
for _ in range(m):
a, b = list(map(int, stdin.readline().split()))
l = l if l > a else a
r = r if r < b else b
print((max([0, r - l + 1])))
| false | 5.555556 | [
"-n, m = list(map(int, input().split()))",
"+from sys import stdin",
"+",
"+n, m = list(map(int, stdin.readline().split()))",
"- a, b = list(map(int, input().split()))",
"+ a, b = list(map(int, stdin.readline().split()))"
] | false | 0.070003 | 0.067741 | 1.03338 | [
"s932159288",
"s980565913"
] |
u227082700 | p02975 | python | s010070086 | s825807704 | 69 | 53 | 14,212 | 14,100 | Accepted | Accepted | 23.19 | n,a=int(eval(input())),sorted(list(map(int,input().split())));b=set(a);l=len(b);print(("Yes"if(l==3and b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2])or(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")) | n,a=int(eval(input())),0
for i in list(map(int,input().split())):a^=i
print(("Yes"if a==0else"No")) | 1 | 3 | 258 | 93 | n, a = int(eval(input())), sorted(list(map(int, input().split())))
b = set(a)
l = len(b)
print(
(
"Yes"
if (
l == 3
and b.pop() ^ b.pop() == b.pop()
and n % 3 == 0
and a[n // 3 - 1] != a[n // 3]
and a[n // 3 * 2 - 1] != a[n // 3 * 2]
)
or (l == 1 and a[0] == 0)
or (l == 2 and a[0] == 0 and n % 3 == 0 and a[n // 3 - 1] != a[n // 3])
else "No"
)
)
| n, a = int(eval(input())), 0
for i in list(map(int, input().split())):
a ^= i
print(("Yes" if a == 0 else "No"))
| false | 66.666667 | [
"-n, a = int(eval(input())), sorted(list(map(int, input().split())))",
"-b = set(a)",
"-l = len(b)",
"-print(",
"- (",
"- \"Yes\"",
"- if (",
"- l == 3",
"- and b.pop() ^ b.pop() == b.pop()",
"- and n % 3 == 0",
"- and a[n // 3 - 1] != a[n // 3]",
"- and a[n // 3 * 2 - 1] != a[n // 3 * 2]",
"- )",
"- or (l == 1 and a[0] == 0)",
"- or (l == 2 and a[0] == 0 and n % 3 == 0 and a[n // 3 - 1] != a[n // 3])",
"- else \"No\"",
"- )",
"-)",
"+n, a = int(eval(input())), 0",
"+for i in list(map(int, input().split())):",
"+ a ^= i",
"+print((\"Yes\" if a == 0 else \"No\"))"
] | false | 0.041695 | 0.042291 | 0.985904 | [
"s010070086",
"s825807704"
] |
u189023301 | p03352 | python | s783395979 | s034407329 | 29 | 23 | 9,192 | 9,048 | Accepted | Accepted | 20.69 | n = int(eval(input()))
s = set()
for i in range(1, 32):
s.add(i ** 2)
for i in range(1, 11):
s.add(i ** 3)
for i in range(1, 7):
s.add(i ** 4)
for i in range(1, 5):
s.add(i ** 5)
s.add(i ** 6)
s.add(i ** 7)
s.add(i ** 8)
s.add(i ** 9)
s.add(i ** 10)
t = list(s)
t.sort()
t = [x for x in t if x <= 1000]
res = 0
for tt in t:
res = tt if tt <= n else res
print(res) | n = int(eval(input()))
t = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100,
125, 121, 128, 144, 169, 196, 216, 225, 243, 256,
289, 324, 343, 361, 400, 441, 484, 512, 529, 576,
625, 676, 729, 784, 841, 900, 961, 1000, 1024, 1296]
res = 0
for tt in t:
res = tt if tt <= n else res
print(res)
| 27 | 10 | 428 | 314 | n = int(eval(input()))
s = set()
for i in range(1, 32):
s.add(i**2)
for i in range(1, 11):
s.add(i**3)
for i in range(1, 7):
s.add(i**4)
for i in range(1, 5):
s.add(i**5)
s.add(i**6)
s.add(i**7)
s.add(i**8)
s.add(i**9)
s.add(i**10)
t = list(s)
t.sort()
t = [x for x in t if x <= 1000]
res = 0
for tt in t:
res = tt if tt <= n else res
print(res)
| n = int(eval(input()))
t = [
1,
4,
8,
9,
16,
25,
27,
32,
36,
49,
64,
81,
100,
125,
121,
128,
144,
169,
196,
216,
225,
243,
256,
289,
324,
343,
361,
400,
441,
484,
512,
529,
576,
625,
676,
729,
784,
841,
900,
961,
1000,
1024,
1296,
]
res = 0
for tt in t:
res = tt if tt <= n else res
print(res)
| false | 62.962963 | [
"-s = set()",
"-for i in range(1, 32):",
"- s.add(i**2)",
"-for i in range(1, 11):",
"- s.add(i**3)",
"-for i in range(1, 7):",
"- s.add(i**4)",
"-for i in range(1, 5):",
"- s.add(i**5)",
"- s.add(i**6)",
"- s.add(i**7)",
"- s.add(i**8)",
"- s.add(i**9)",
"- s.add(i**10)",
"-t = list(s)",
"-t.sort()",
"-t = [x for x in t if x <= 1000]",
"+t = [",
"+ 1,",
"+ 4,",
"+ 8,",
"+ 9,",
"+ 16,",
"+ 25,",
"+ 27,",
"+ 32,",
"+ 36,",
"+ 49,",
"+ 64,",
"+ 81,",
"+ 100,",
"+ 125,",
"+ 121,",
"+ 128,",
"+ 144,",
"+ 169,",
"+ 196,",
"+ 216,",
"+ 225,",
"+ 243,",
"+ 256,",
"+ 289,",
"+ 324,",
"+ 343,",
"+ 361,",
"+ 400,",
"+ 441,",
"+ 484,",
"+ 512,",
"+ 529,",
"+ 576,",
"+ 625,",
"+ 676,",
"+ 729,",
"+ 784,",
"+ 841,",
"+ 900,",
"+ 961,",
"+ 1000,",
"+ 1024,",
"+ 1296,",
"+]"
] | false | 0.037583 | 0.044 | 0.854173 | [
"s783395979",
"s034407329"
] |
u047023156 | p02912 | python | s382947039 | s698893280 | 450 | 171 | 70,424 | 14,204 | Accepted | Accepted | 62 | import sys
import heapq
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list([x * (-1) for x in A])
heapq.heapify(A)
for _ in range(M):
mx = heapq.heappop(A)
heapq.heappush(A, mx // 2 if mx % 2 == 0 else mx // 2 + 1)
print((sum(A) * (-1))) | import sys
import heapq
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
#A = list(map(lambda x: x * (-1), A))
A = [-i for i in A]
heapq.heapify(A)
for _ in range(M):
mx = heapq.heappop(A)
heapq.heappush(A, mx // 2 if mx % 2 == 0 else mx // 2 + 1)
print((sum(A) * (-1))) | 16 | 17 | 324 | 346 | import sys
import heapq
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = list([x * (-1) for x in A])
heapq.heapify(A)
for _ in range(M):
mx = heapq.heappop(A)
heapq.heappush(A, mx // 2 if mx % 2 == 0 else mx // 2 + 1)
print((sum(A) * (-1)))
| import sys
import heapq
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# A = list(map(lambda x: x * (-1), A))
A = [-i for i in A]
heapq.heapify(A)
for _ in range(M):
mx = heapq.heappop(A)
heapq.heappush(A, mx // 2 if mx % 2 == 0 else mx // 2 + 1)
print((sum(A) * (-1)))
| false | 5.882353 | [
"-A = list([x * (-1) for x in A])",
"+# A = list(map(lambda x: x * (-1), A))",
"+A = [-i for i in A]"
] | false | 0.04713 | 0.046805 | 1.006931 | [
"s382947039",
"s698893280"
] |
u033606236 | p03624 | python | s523763429 | s404985791 | 59 | 22 | 3,956 | 4,016 | Accepted | Accepted | 62.71 | strings = list(eval(input()))
alfabet = 'abcdefghijklmnopqrstuvwxyz'
for i in alfabet:
if strings.count(i) == 0:
result = i
break
else:
result = "None"
print(result) | S = sorted(set([i for i in eval(input())]))
for i in "abcdefghijklmnopqrstuvwxyz":
if i not in S:
print(i)
break
else:print("None") | 11 | 6 | 196 | 150 | strings = list(eval(input()))
alfabet = "abcdefghijklmnopqrstuvwxyz"
for i in alfabet:
if strings.count(i) == 0:
result = i
break
else:
result = "None"
print(result)
| S = sorted(set([i for i in eval(input())]))
for i in "abcdefghijklmnopqrstuvwxyz":
if i not in S:
print(i)
break
else:
print("None")
| false | 45.454545 | [
"-strings = list(eval(input()))",
"-alfabet = \"abcdefghijklmnopqrstuvwxyz\"",
"-for i in alfabet:",
"- if strings.count(i) == 0:",
"- result = i",
"+S = sorted(set([i for i in eval(input())]))",
"+for i in \"abcdefghijklmnopqrstuvwxyz\":",
"+ if i not in S:",
"+ print(i)",
"- result = \"None\"",
"-print(result)",
"+ print(\"None\")"
] | false | 0.039675 | 0.052486 | 0.755922 | [
"s523763429",
"s404985791"
] |
u627803856 | p02559 | python | s212630606 | s381352706 | 1,510 | 623 | 132,544 | 127,208 | Accepted | Accepted | 58.74 | class FenwickTree:
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def build(self, lst):
self.value = lst
for i, x in enumerate(lst):
self.add(i + 1, x)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.n:
self.bit[i] += x
i += i & -i
def get_sum(self, i, j):
return self.sum(j) - self.sum(i)
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
bit = FenwickTree(N)
bit.build(A)
for i in range(Q):
a, b, c = list(map(int, input().split()))
if a == 0:
bit.add(b + 1, c)
else:
print((bit.get_sum(b, c)))
| class FenwickTree:
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def build(self, lst):
self.value = lst
for i, x in enumerate(lst):
self.add(i + 1, x)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.n:
self.bit[i] += x
i += i & -i
def get_sum(self, i, j):
return self.sum(j) - self.sum(i)
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
bit = FenwickTree(N)
bit.build(A)
for i in range(Q):
a, b, c = list(map(int, input().split()))
if a == 0:
bit.add(b + 1, c)
else:
print((bit.get_sum(b, c)))
| 38 | 40 | 840 | 869 | class FenwickTree:
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def build(self, lst):
self.value = lst
for i, x in enumerate(lst):
self.add(i + 1, x)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.n:
self.bit[i] += x
i += i & -i
def get_sum(self, i, j):
return self.sum(j) - self.sum(i)
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
bit = FenwickTree(N)
bit.build(A)
for i in range(Q):
a, b, c = list(map(int, input().split()))
if a == 0:
bit.add(b + 1, c)
else:
print((bit.get_sum(b, c)))
| class FenwickTree:
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def build(self, lst):
self.value = lst
for i, x in enumerate(lst):
self.add(i + 1, x)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.n:
self.bit[i] += x
i += i & -i
def get_sum(self, i, j):
return self.sum(j) - self.sum(i)
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
bit = FenwickTree(N)
bit.build(A)
for i in range(Q):
a, b, c = list(map(int, input().split()))
if a == 0:
bit.add(b + 1, c)
else:
print((bit.get_sum(b, c)))
| false | 5 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.04235 | 0.124031 | 0.341451 | [
"s212630606",
"s381352706"
] |
u102461423 | p02954 | python | s411051330 | s376222819 | 1,300 | 245 | 23,316 | 41,792 | Accepted | Accepted | 81.15 | import numpy as np
from scipy.sparse import csr_matrix
s = np.array(list(eval(input())), dtype='U1')
n = len(s)
child = np.ones(n,dtype=np.int32)
rows = np.arange(n)
cols = np.where(s == 'R', rows+1, rows-1)
x = csr_matrix((np.ones(n,dtype=np.int32),(rows,cols)),(n,n))
def power(x,n):
if n == 1:
return x
y = power(x,n//2)
y = y*y
return x*y if n&1 else y
x = power(x,10**100)
print((*(child*x)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# doublingしてみる
import numpy as np
S = np.array(list(read().rstrip().decode('utf-8')))
L = len(S)
x = np.arange(L,dtype=np.int32)
x[S=='R'] += 1
x[S=='L'] -= 1
dp = [x]
for _ in range(20):
x = dp[-1]
dp.append(x[x])
answer = np.bincount(dp[-1],minlength=L)
print((' '.join(answer.astype(str)))) | 18 | 24 | 433 | 445 | import numpy as np
from scipy.sparse import csr_matrix
s = np.array(list(eval(input())), dtype="U1")
n = len(s)
child = np.ones(n, dtype=np.int32)
rows = np.arange(n)
cols = np.where(s == "R", rows + 1, rows - 1)
x = csr_matrix((np.ones(n, dtype=np.int32), (rows, cols)), (n, n))
def power(x, n):
if n == 1:
return x
y = power(x, n // 2)
y = y * y
return x * y if n & 1 else y
x = power(x, 10**100)
print((*(child * x)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# doublingしてみる
import numpy as np
S = np.array(list(read().rstrip().decode("utf-8")))
L = len(S)
x = np.arange(L, dtype=np.int32)
x[S == "R"] += 1
x[S == "L"] -= 1
dp = [x]
for _ in range(20):
x = dp[-1]
dp.append(x[x])
answer = np.bincount(dp[-1], minlength=L)
print((" ".join(answer.astype(str))))
| false | 25 | [
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+# doublingしてみる",
"-from scipy.sparse import csr_matrix",
"-s = np.array(list(eval(input())), dtype=\"U1\")",
"-n = len(s)",
"-child = np.ones(n, dtype=np.int32)",
"-rows = np.arange(n)",
"-cols = np.where(s == \"R\", rows + 1, rows - 1)",
"-x = csr_matrix((np.ones(n, dtype=np.int32), (rows, cols)), (n, n))",
"-",
"-",
"-def power(x, n):",
"- if n == 1:",
"- return x",
"- y = power(x, n // 2)",
"- y = y * y",
"- return x * y if n & 1 else y",
"-",
"-",
"-x = power(x, 10**100)",
"-print((*(child * x)))",
"+S = np.array(list(read().rstrip().decode(\"utf-8\")))",
"+L = len(S)",
"+x = np.arange(L, dtype=np.int32)",
"+x[S == \"R\"] += 1",
"+x[S == \"L\"] -= 1",
"+dp = [x]",
"+for _ in range(20):",
"+ x = dp[-1]",
"+ dp.append(x[x])",
"+answer = np.bincount(dp[-1], minlength=L)",
"+print((\" \".join(answer.astype(str))))"
] | false | 1.095271 | 0.268459 | 4.079838 | [
"s411051330",
"s376222819"
] |
u203900263 | p03854 | python | s979542498 | s074133543 | 32 | 26 | 6,516 | 3,316 | Accepted | Accepted | 18.75 | import re
S = eval(input())
x = r"^(dream|dreamer|erase|eraser)*$"
if re.match(x, S):
print("YES")
else:
print("NO")
| S = eval(input())
S = S[::-1]
def solve(S):
point = 0
while S:
if len(S) == point:
print('YES')
return False
if S[point:point + 7] in {'remaerd'}:
point += 7
elif S[point:point + 6] in {'resare'}:
point += 6
elif S[point:point + 5] in {'esare', 'maerd'}:
point += 5
else:
return True
if solve(S):
print('NO') | 10 | 23 | 131 | 453 | import re
S = eval(input())
x = r"^(dream|dreamer|erase|eraser)*$"
if re.match(x, S):
print("YES")
else:
print("NO")
| S = eval(input())
S = S[::-1]
def solve(S):
point = 0
while S:
if len(S) == point:
print("YES")
return False
if S[point : point + 7] in {"remaerd"}:
point += 7
elif S[point : point + 6] in {"resare"}:
point += 6
elif S[point : point + 5] in {"esare", "maerd"}:
point += 5
else:
return True
if solve(S):
print("NO")
| false | 56.521739 | [
"-import re",
"+S = eval(input())",
"+S = S[::-1]",
"-S = eval(input())",
"-x = r\"^(dream|dreamer|erase|eraser)*$\"",
"-if re.match(x, S):",
"- print(\"YES\")",
"-else:",
"+",
"+def solve(S):",
"+ point = 0",
"+ while S:",
"+ if len(S) == point:",
"+ print(\"YES\")",
"+ return False",
"+ if S[point : point + 7] in {\"remaerd\"}:",
"+ point += 7",
"+ elif S[point : point + 6] in {\"resare\"}:",
"+ point += 6",
"+ elif S[point : point + 5] in {\"esare\", \"maerd\"}:",
"+ point += 5",
"+ else:",
"+ return True",
"+",
"+",
"+if solve(S):"
] | false | 0.053841 | 0.041719 | 1.290553 | [
"s979542498",
"s074133543"
] |
u562935282 | p03291 | python | s977444929 | s367233345 | 417 | 86 | 27,568 | 3,188 | Accepted | Accepted | 79.38 | def main():
MOD = 10 ** 9 + 7
s = eval(input())
n = len(s)
dp = [[0] * 4 for _ in range(n + 1)]
dp[0][0] = 1
for i, c in enumerate(s, start=1):
for j in range(4):
dp[i][j] = dp[i - 1][j]
if c == 'A':
dp[i][1] += dp[i - 1][0]
elif c == 'B':
dp[i][2] += dp[i - 1][1]
elif c == 'C':
dp[i][3] += dp[i - 1][2]
else:
for j in range(1, 4):
dp[i][j] += dp[i - 1][j - 1]
for j in range(4):
dp[i][j] += dp[i - 1][j] * 2
for j in range(4):
dp[i][j] %= MOD
print((dp[n][3]))
if __name__ == '__main__':
main()
| def main():
MOD = 10 ** 9 + 7
s = eval(input())
x, a, b, c = 1, 0, 0, 0
for char in s:
if char == 'A':
a = (a + x) % MOD
elif char == 'B':
b = (b + a) % MOD
elif char == 'C':
c = (c + b) % MOD
else:
x, a, b, c = 3 * x % MOD, (3 * a + x) % MOD, (3 * b + a) % MOD, (3 * c + b) % MOD
print(c)
if __name__ == '__main__':
main()
| 31 | 22 | 721 | 449 | def main():
MOD = 10**9 + 7
s = eval(input())
n = len(s)
dp = [[0] * 4 for _ in range(n + 1)]
dp[0][0] = 1
for i, c in enumerate(s, start=1):
for j in range(4):
dp[i][j] = dp[i - 1][j]
if c == "A":
dp[i][1] += dp[i - 1][0]
elif c == "B":
dp[i][2] += dp[i - 1][1]
elif c == "C":
dp[i][3] += dp[i - 1][2]
else:
for j in range(1, 4):
dp[i][j] += dp[i - 1][j - 1]
for j in range(4):
dp[i][j] += dp[i - 1][j] * 2
for j in range(4):
dp[i][j] %= MOD
print((dp[n][3]))
if __name__ == "__main__":
main()
| def main():
MOD = 10**9 + 7
s = eval(input())
x, a, b, c = 1, 0, 0, 0
for char in s:
if char == "A":
a = (a + x) % MOD
elif char == "B":
b = (b + a) % MOD
elif char == "C":
c = (c + b) % MOD
else:
x, a, b, c = (
3 * x % MOD,
(3 * a + x) % MOD,
(3 * b + a) % MOD,
(3 * c + b) % MOD,
)
print(c)
if __name__ == "__main__":
main()
| false | 29.032258 | [
"- n = len(s)",
"- dp = [[0] * 4 for _ in range(n + 1)]",
"- dp[0][0] = 1",
"- for i, c in enumerate(s, start=1):",
"- for j in range(4):",
"- dp[i][j] = dp[i - 1][j]",
"- if c == \"A\":",
"- dp[i][1] += dp[i - 1][0]",
"- elif c == \"B\":",
"- dp[i][2] += dp[i - 1][1]",
"- elif c == \"C\":",
"- dp[i][3] += dp[i - 1][2]",
"+ x, a, b, c = 1, 0, 0, 0",
"+ for char in s:",
"+ if char == \"A\":",
"+ a = (a + x) % MOD",
"+ elif char == \"B\":",
"+ b = (b + a) % MOD",
"+ elif char == \"C\":",
"+ c = (c + b) % MOD",
"- for j in range(1, 4):",
"- dp[i][j] += dp[i - 1][j - 1]",
"- for j in range(4):",
"- dp[i][j] += dp[i - 1][j] * 2",
"- for j in range(4):",
"- dp[i][j] %= MOD",
"- print((dp[n][3]))",
"+ x, a, b, c = (",
"+ 3 * x % MOD,",
"+ (3 * a + x) % MOD,",
"+ (3 * b + a) % MOD,",
"+ (3 * c + b) % MOD,",
"+ )",
"+ print(c)"
] | false | 0.251561 | 0.045439 | 5.53626 | [
"s977444929",
"s367233345"
] |
u427344224 | p03142 | python | s447378897 | s762229176 | 1,082 | 982 | 74,340 | 74,340 | Accepted | Accepted | 9.24 | from collections import deque, defaultdict
N, M = list(map(int, input().split()))
ab = []
for _ in range(N + M - 1):
a, b = list(map(int, input().split()))
ab.append((a, b))
out = defaultdict(list)
in_cnt = defaultdict(int)
rev = defaultdict(list)
for a, b in ab:
out[a].append(b)
in_cnt[b] += 1
rev[b].append(a)
queue = deque(i for i in range(1, N + 1) if in_cnt[i] == 0)
sorted_ans = []
while len(queue) != 0:
v = queue.popleft()
sorted_ans.append(v)
for v2 in out[v]:
in_cnt[v2] -= 1
if in_cnt[v2] == 0:
queue.append(v2)
order = [i + 1 for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]
order = [0] + order
ans = [0] * (N + 1)
ans[sorted_ans[0] + 1] = 0
for v in sorted_ans[:0:-1]:
ans[v] = max((order[v2], v2) for v2 in rev[v])[1]
ans.pop(0)
for a in ans:
print(a)
| from collections import deque, defaultdict
N, M = list(map(int, input().split()))
ab = []
for _ in range(N + M - 1):
a, b = list(map(int, input().split()))
ab.append((a, b))
out = defaultdict(list)
in_cnt = defaultdict(int)
rev = defaultdict(list)
for a, b in ab:
out[a].append(b)
in_cnt[b] += 1
rev[b].append(a)
queue = deque(i for i in range(1, N + 1) if in_cnt[i] == 0)
sorted_ans = []
while len(queue) != 0:
v = queue.popleft()
sorted_ans.append(v)
for v2 in out[v]:
in_cnt[v2] -= 1
if in_cnt[v2] == 0:
queue.append(v2)
order = [0] + [i + 1 for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]
ans = [0] * (N + 1)
ans[sorted_ans[0] + 1] = 0
for v in sorted_ans[:0:-1]:
ans[v] = max((order[v2], v2) for v2 in rev[v])[1]
for a in ans[1:]:
print(a)
| 37 | 36 | 879 | 862 | from collections import deque, defaultdict
N, M = list(map(int, input().split()))
ab = []
for _ in range(N + M - 1):
a, b = list(map(int, input().split()))
ab.append((a, b))
out = defaultdict(list)
in_cnt = defaultdict(int)
rev = defaultdict(list)
for a, b in ab:
out[a].append(b)
in_cnt[b] += 1
rev[b].append(a)
queue = deque(i for i in range(1, N + 1) if in_cnt[i] == 0)
sorted_ans = []
while len(queue) != 0:
v = queue.popleft()
sorted_ans.append(v)
for v2 in out[v]:
in_cnt[v2] -= 1
if in_cnt[v2] == 0:
queue.append(v2)
order = [i + 1 for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]
order = [0] + order
ans = [0] * (N + 1)
ans[sorted_ans[0] + 1] = 0
for v in sorted_ans[:0:-1]:
ans[v] = max((order[v2], v2) for v2 in rev[v])[1]
ans.pop(0)
for a in ans:
print(a)
| from collections import deque, defaultdict
N, M = list(map(int, input().split()))
ab = []
for _ in range(N + M - 1):
a, b = list(map(int, input().split()))
ab.append((a, b))
out = defaultdict(list)
in_cnt = defaultdict(int)
rev = defaultdict(list)
for a, b in ab:
out[a].append(b)
in_cnt[b] += 1
rev[b].append(a)
queue = deque(i for i in range(1, N + 1) if in_cnt[i] == 0)
sorted_ans = []
while len(queue) != 0:
v = queue.popleft()
sorted_ans.append(v)
for v2 in out[v]:
in_cnt[v2] -= 1
if in_cnt[v2] == 0:
queue.append(v2)
order = [0] + [i + 1 for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]
ans = [0] * (N + 1)
ans[sorted_ans[0] + 1] = 0
for v in sorted_ans[:0:-1]:
ans[v] = max((order[v2], v2) for v2 in rev[v])[1]
for a in ans[1:]:
print(a)
| false | 2.702703 | [
"-order = [i + 1 for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]",
"-order = [0] + order",
"+order = [0] + [i + 1 for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]",
"-ans.pop(0)",
"-for a in ans:",
"+for a in ans[1:]:"
] | false | 0.03546 | 0.035619 | 0.995538 | [
"s447378897",
"s762229176"
] |
u652656291 | p02829 | python | s058695030 | s342709129 | 23 | 17 | 3,316 | 2,940 | Accepted | Accepted | 26.09 | a = int(eval(input()))
b = int(eval(input()))
c = 6
print((c // (a*b))) | a = int(eval(input()))
b = int(eval(input()))
print((6-a-b)) | 4 | 3 | 60 | 48 | a = int(eval(input()))
b = int(eval(input()))
c = 6
print((c // (a * b)))
| a = int(eval(input()))
b = int(eval(input()))
print((6 - a - b))
| false | 25 | [
"-c = 6",
"-print((c // (a * b)))",
"+print((6 - a - b))"
] | false | 0.038175 | 0.043095 | 0.885842 | [
"s058695030",
"s342709129"
] |
u579699847 | p02873 | python | s085036469 | s971293096 | 437 | 335 | 65,548 | 23,336 | Accepted | Accepted | 23.34 | import itertools,sys
def S(): return sys.stdin.readline().rstrip()
S = S()
groupby_S = itertools.groupby(S)
ans = 0
rangeN = [i for i in range(len(S)+1)]
rangeN_accumulate = list(itertools.accumulate(rangeN))
group = []
temp = []
for k,g in groupby_S:
if k=='<':
temp.append(len(list(g)))
else:
temp.append(len(list(g)))
group.append(temp)
temp = []
group.append(temp)
for x in group:
if len(x)==0:
continue
elif len(x)==1:
ans += rangeN_accumulate[x[0]]
else:
a,b = max(x),min(x)-1
ans += rangeN_accumulate[a]
ans += rangeN_accumulate[b]
print(ans)
| import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
seq = [0]*(len(S)+1)
for i in range(len(S)):
if S[i]=='<':
seq[i+1] = seq[i]+1
for j in range(len(S))[::-1]:
if S[j]=='>':
seq[j] = max(seq[j],seq[j+1]+1)
print((sum(seq)))
| 27 | 11 | 668 | 270 | import itertools, sys
def S():
return sys.stdin.readline().rstrip()
S = S()
groupby_S = itertools.groupby(S)
ans = 0
rangeN = [i for i in range(len(S) + 1)]
rangeN_accumulate = list(itertools.accumulate(rangeN))
group = []
temp = []
for k, g in groupby_S:
if k == "<":
temp.append(len(list(g)))
else:
temp.append(len(list(g)))
group.append(temp)
temp = []
group.append(temp)
for x in group:
if len(x) == 0:
continue
elif len(x) == 1:
ans += rangeN_accumulate[x[0]]
else:
a, b = max(x), min(x) - 1
ans += rangeN_accumulate[a]
ans += rangeN_accumulate[b]
print(ans)
| import sys
def S():
return sys.stdin.readline().rstrip()
S = S()
seq = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == "<":
seq[i + 1] = seq[i] + 1
for j in range(len(S))[::-1]:
if S[j] == ">":
seq[j] = max(seq[j], seq[j + 1] + 1)
print((sum(seq)))
| false | 59.259259 | [
"-import itertools, sys",
"+import sys",
"-groupby_S = itertools.groupby(S)",
"-ans = 0",
"-rangeN = [i for i in range(len(S) + 1)]",
"-rangeN_accumulate = list(itertools.accumulate(rangeN))",
"-group = []",
"-temp = []",
"-for k, g in groupby_S:",
"- if k == \"<\":",
"- temp.append(len(list(g)))",
"- else:",
"- temp.append(len(list(g)))",
"- group.append(temp)",
"- temp = []",
"-group.append(temp)",
"-for x in group:",
"- if len(x) == 0:",
"- continue",
"- elif len(x) == 1:",
"- ans += rangeN_accumulate[x[0]]",
"- else:",
"- a, b = max(x), min(x) - 1",
"- ans += rangeN_accumulate[a]",
"- ans += rangeN_accumulate[b]",
"-print(ans)",
"+seq = [0] * (len(S) + 1)",
"+for i in range(len(S)):",
"+ if S[i] == \"<\":",
"+ seq[i + 1] = seq[i] + 1",
"+for j in range(len(S))[::-1]:",
"+ if S[j] == \">\":",
"+ seq[j] = max(seq[j], seq[j + 1] + 1)",
"+print((sum(seq)))"
] | false | 0.042302 | 0.043911 | 0.963349 | [
"s085036469",
"s971293096"
] |
u948524308 | p02787 | python | s464559077 | s961138279 | 721 | 375 | 127,856 | 41,580 | Accepted | Accepted | 47.99 | 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=[[1000000000]*(H+max(A)+1) for i in range(N+1)]
for i in range(N):
DP[i+1][A[i]]=B[i]
for i in range(N):
for h in range(H+max(A)+1):
DP[i+1][h]=min(DP[i+1][h],DP[i][h])
if h-A[i]>=0:
DP[i+1][h]=min(DP[i+1][h-A[i]]+B[i],DP[i+1][h])
print((min(DP[N][H:]))) | 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=[1000000000]*(H+max(A)+1)
DP[0]=0
for i in range(N):
DP[A[i]]=B[i]
for i in range(N):
for h in range(A[i],H+max(A)+1):
DP[h]=min(DP[h-A[i]]+B[i],DP[h])
print((min(DP[H:]))) | 24 | 22 | 445 | 340 | 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 = [[1000000000] * (H + max(A) + 1) for i in range(N + 1)]
for i in range(N):
DP[i + 1][A[i]] = B[i]
for i in range(N):
for h in range(H + max(A) + 1):
DP[i + 1][h] = min(DP[i + 1][h], DP[i][h])
if h - A[i] >= 0:
DP[i + 1][h] = min(DP[i + 1][h - A[i]] + B[i], DP[i + 1][h])
print((min(DP[N][H:])))
| 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 = [1000000000] * (H + max(A) + 1)
DP[0] = 0
for i in range(N):
DP[A[i]] = B[i]
for i in range(N):
for h in range(A[i], H + max(A) + 1):
DP[h] = min(DP[h - A[i]] + B[i], DP[h])
print((min(DP[H:])))
| false | 8.333333 | [
"-DP = [[1000000000] * (H + max(A) + 1) for i in range(N + 1)]",
"+DP = [1000000000] * (H + max(A) + 1)",
"+DP[0] = 0",
"- DP[i + 1][A[i]] = B[i]",
"+ DP[A[i]] = B[i]",
"- for h in range(H + max(A) + 1):",
"- DP[i + 1][h] = min(DP[i + 1][h], DP[i][h])",
"- if h - A[i] >= 0:",
"- DP[i + 1][h] = min(DP[i + 1][h - A[i]] + B[i], DP[i + 1][h])",
"-print((min(DP[N][H:])))",
"+ for h in range(A[i], H + max(A) + 1):",
"+ DP[h] = min(DP[h - A[i]] + B[i], DP[h])",
"+print((min(DP[H:])))"
] | false | 0.298871 | 0.079704 | 3.749749 | [
"s464559077",
"s961138279"
] |
u163501259 | p02713 | python | s782930576 | s055737252 | 1,582 | 931 | 9,660 | 74,936 | Accepted | Accepted | 41.15 | import math
from functools import reduce
K = int(eval(input()))
CNT= 0
def gcd(*numbers):
return reduce(math.gcd, numbers)
for i in range(1,K+1):
for j in range(1,K+1):
GCD = gcd(i,j)
if GCD == 1:
CNT += K
else:
for k in range(1, K+1):
if gcd(GCD,k) != 1:
CNT += gcd(GCD,k)
else:
CNT += 1
print(CNT) | import math
from functools import reduce
K = int(eval(input()))
CNT= 0
def gcd(*numbers):
return reduce(math.gcd, numbers)
for i in range(1,K+1):
for j in range(1,K+1):
for k in range(1,K+1):
CNT += gcd(i,j,k)
print(CNT) | 18 | 11 | 438 | 252 | import math
from functools import reduce
K = int(eval(input()))
CNT = 0
def gcd(*numbers):
return reduce(math.gcd, numbers)
for i in range(1, K + 1):
for j in range(1, K + 1):
GCD = gcd(i, j)
if GCD == 1:
CNT += K
else:
for k in range(1, K + 1):
if gcd(GCD, k) != 1:
CNT += gcd(GCD, k)
else:
CNT += 1
print(CNT)
| import math
from functools import reduce
K = int(eval(input()))
CNT = 0
def gcd(*numbers):
return reduce(math.gcd, numbers)
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
CNT += gcd(i, j, k)
print(CNT)
| false | 38.888889 | [
"- GCD = gcd(i, j)",
"- if GCD == 1:",
"- CNT += K",
"- else:",
"- for k in range(1, K + 1):",
"- if gcd(GCD, k) != 1:",
"- CNT += gcd(GCD, k)",
"- else:",
"- CNT += 1",
"+ for k in range(1, K + 1):",
"+ CNT += gcd(i, j, k)"
] | false | 0.171335 | 0.04148 | 4.13053 | [
"s782930576",
"s055737252"
] |
u624475441 | p03624 | python | s891340027 | s916167797 | 29 | 21 | 3,892 | 3,188 | Accepted | Accepted | 27.59 | import string
s = set(string.ascii_lowercase) - set(eval(input()))
print((min(s) if s else 'None')) | S = eval(input())
for c in 'abcdefghijklmnopqrstuvwxyz':
if c not in S:
print(c)
exit()
print('None') | 3 | 6 | 93 | 120 | import string
s = set(string.ascii_lowercase) - set(eval(input()))
print((min(s) if s else "None"))
| S = eval(input())
for c in "abcdefghijklmnopqrstuvwxyz":
if c not in S:
print(c)
exit()
print("None")
| false | 50 | [
"-import string",
"-",
"-s = set(string.ascii_lowercase) - set(eval(input()))",
"-print((min(s) if s else \"None\"))",
"+S = eval(input())",
"+for c in \"abcdefghijklmnopqrstuvwxyz\":",
"+ if c not in S:",
"+ print(c)",
"+ exit()",
"+print(\"None\")"
] | false | 0.040457 | 0.043857 | 0.922491 | [
"s891340027",
"s916167797"
] |
u623819879 | p02971 | python | s021690962 | s600523652 | 932 | 592 | 70,204 | 14,112 | Accepted | Accepted | 36.48 | import sys
sys.setrecursionlimit(10**6)
def MI():
return list(map(int,input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
n=I()
a,b=[],[]
for i in range(n):
a.append(I())
b=sorted(a)[::-1]
M=b[0]
m=b[1]
ans=0
for i in range(n):
if a[i]==M:
ans=m
else:
ans=M
print(ans)
| n=int(eval(input()))
a=[]
for i in range(n):
a.append(int(eval(input())))
b=sorted(a)
m,M=b[-2:]
for i in range(n): print((m if a[i]==M else M)) | 23 | 7 | 376 | 138 | import sys
sys.setrecursionlimit(10**6)
def MI():
return list(map(int, input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
n = I()
a, b = [], []
for i in range(n):
a.append(I())
b = sorted(a)[::-1]
M = b[0]
m = b[1]
ans = 0
for i in range(n):
if a[i] == M:
ans = m
else:
ans = M
print(ans)
| n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
b = sorted(a)
m, M = b[-2:]
for i in range(n):
print((m if a[i] == M else M))
| false | 69.565217 | [
"-import sys",
"-",
"-sys.setrecursionlimit(10**6)",
"-",
"-",
"-def MI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def I():",
"- return int(eval(input()))",
"-",
"-",
"-def LI():",
"- return [int(i) for i in input().split()]",
"-",
"-",
"-n = I()",
"-a, b = [], []",
"+n = int(eval(input()))",
"+a = []",
"- a.append(I())",
"-b = sorted(a)[::-1]",
"-M = b[0]",
"-m = b[1]",
"-ans = 0",
"+ a.append(int(eval(input())))",
"+b = sorted(a)",
"+m, M = b[-2:]",
"- if a[i] == M:",
"- ans = m",
"- else:",
"- ans = M",
"- print(ans)",
"+ print((m if a[i] == M else M))"
] | false | 0.046546 | 0.042518 | 1.094718 | [
"s021690962",
"s600523652"
] |
u059436995 | p03457 | python | s146877936 | s537843112 | 372 | 192 | 3,060 | 10,284 | Accepted | Accepted | 48.39 | n = int(eval(input()))
t,x,y =(0, 0, 0)
for _ in range(n):
nt, nx, ny =list(map(int,input().split()))
dis=abs(nx-x)+abs(ny-y)
tim = nt - t
if tim >= dis and (tim - dis) % 2 ==0:
t,x,y=nt, nx, ny
else:
print('No')
break
else:
print('Yes')
| from sys import stdin
input = stdin.readline
lines = stdin.readlines
N = int(eval(input()))
txy = ((list(map(int, line.split()))) for line in lines())
t,x,y =(0, 0, 0)
for nt, nx, ny in txy:
dis=abs(nx-x)+abs(ny-y)
tim = nt - t
if tim >= dis and (tim - dis) % 2 ==0:
t,x,y=nt, nx, ny
else:
print('No')
break
else:
print('Yes') | 13 | 19 | 286 | 382 | n = int(eval(input()))
t, x, y = (0, 0, 0)
for _ in range(n):
nt, nx, ny = list(map(int, input().split()))
dis = abs(nx - x) + abs(ny - y)
tim = nt - t
if tim >= dis and (tim - dis) % 2 == 0:
t, x, y = nt, nx, ny
else:
print("No")
break
else:
print("Yes")
| from sys import stdin
input = stdin.readline
lines = stdin.readlines
N = int(eval(input()))
txy = ((list(map(int, line.split()))) for line in lines())
t, x, y = (0, 0, 0)
for nt, nx, ny in txy:
dis = abs(nx - x) + abs(ny - y)
tim = nt - t
if tim >= dis and (tim - dis) % 2 == 0:
t, x, y = nt, nx, ny
else:
print("No")
break
else:
print("Yes")
| false | 31.578947 | [
"-n = int(eval(input()))",
"+from sys import stdin",
"+",
"+input = stdin.readline",
"+lines = stdin.readlines",
"+N = int(eval(input()))",
"+txy = ((list(map(int, line.split()))) for line in lines())",
"-for _ in range(n):",
"- nt, nx, ny = list(map(int, input().split()))",
"+for nt, nx, ny in txy:"
] | false | 0.067668 | 0.035061 | 1.930038 | [
"s146877936",
"s537843112"
] |
u523087093 | p02608 | python | s361779959 | s642573737 | 1,732 | 81 | 9,924 | 9,884 | Accepted | Accepted | 95.32 | N = int(eval(input()))
keys = [i for i in range(1, N+1)]
values = [0] * N
count_dict = dict(list(zip(keys, values)))
for x in range(1, N//6+7):
for y in range(x, N//6+7):
for z in range(y, N//6+7):
n = x**2 + y**2 + z**2 + x*y + y*z + z*x
if n > N:
break
if x == y and y == z:
count_dict[n] += 1
elif x != y and x != z and y != z:
count_dict[n] += 6
else:
count_dict[n] += 3
for v in list(count_dict.values()):
print(v) | N = int(eval(input()))
keys = [i for i in range(1, N+1)]
values = [0] * N
count_dict = dict(list(zip(keys, values)))
for x in range(1, 110):
for y in range(x, 110):
for z in range(y, 110):
n = x**2 + y**2 + z**2 + x*y + y*z + z*x
if n > N:
break
if x == y and y == z:
count_dict[n] += 1
elif x != y and x != z and y != z:
count_dict[n] += 6
else:
count_dict[n] += 3
for v in list(count_dict.values()):
print(v) | 21 | 21 | 564 | 555 | N = int(eval(input()))
keys = [i for i in range(1, N + 1)]
values = [0] * N
count_dict = dict(list(zip(keys, values)))
for x in range(1, N // 6 + 7):
for y in range(x, N // 6 + 7):
for z in range(y, N // 6 + 7):
n = x**2 + y**2 + z**2 + x * y + y * z + z * x
if n > N:
break
if x == y and y == z:
count_dict[n] += 1
elif x != y and x != z and y != z:
count_dict[n] += 6
else:
count_dict[n] += 3
for v in list(count_dict.values()):
print(v)
| N = int(eval(input()))
keys = [i for i in range(1, N + 1)]
values = [0] * N
count_dict = dict(list(zip(keys, values)))
for x in range(1, 110):
for y in range(x, 110):
for z in range(y, 110):
n = x**2 + y**2 + z**2 + x * y + y * z + z * x
if n > N:
break
if x == y and y == z:
count_dict[n] += 1
elif x != y and x != z and y != z:
count_dict[n] += 6
else:
count_dict[n] += 3
for v in list(count_dict.values()):
print(v)
| false | 0 | [
"-for x in range(1, N // 6 + 7):",
"- for y in range(x, N // 6 + 7):",
"- for z in range(y, N // 6 + 7):",
"+for x in range(1, 110):",
"+ for y in range(x, 110):",
"+ for z in range(y, 110):"
] | false | 0.077692 | 0.043841 | 1.772141 | [
"s361779959",
"s642573737"
] |
u772311880 | p02947 | python | s127561756 | s586818145 | 346 | 287 | 24,976 | 24,976 | Accepted | Accepted | 17.05 | # C - Green Bin
def main():
count = 0
dictCount = {}
for i in [eval(input()) for i in range(int(eval(input())))]:
strInput = ''.join(sorted([c for c in i]))
if strInput in dictCount:
count += dictCount[strInput]
dictCount[strInput] += 1
else:
dictCount[strInput] = 1
print(count)
if __name__ == "__main__":
main()
| # C - Green Bin
def main():
count = 0
dictCount = {}
for i in [eval(input()) for i in range(int(eval(input())))]:
strInput = ''.join(sorted(i))
if strInput in dictCount:
count += dictCount[strInput]
dictCount[strInput] += 1
else:
dictCount[strInput] = 1
print(count)
if __name__ == "__main__":
main()
| 16 | 16 | 402 | 389 | # C - Green Bin
def main():
count = 0
dictCount = {}
for i in [eval(input()) for i in range(int(eval(input())))]:
strInput = "".join(sorted([c for c in i]))
if strInput in dictCount:
count += dictCount[strInput]
dictCount[strInput] += 1
else:
dictCount[strInput] = 1
print(count)
if __name__ == "__main__":
main()
| # C - Green Bin
def main():
count = 0
dictCount = {}
for i in [eval(input()) for i in range(int(eval(input())))]:
strInput = "".join(sorted(i))
if strInput in dictCount:
count += dictCount[strInput]
dictCount[strInput] += 1
else:
dictCount[strInput] = 1
print(count)
if __name__ == "__main__":
main()
| false | 0 | [
"- strInput = \"\".join(sorted([c for c in i]))",
"+ strInput = \"\".join(sorted(i))"
] | false | 0.037191 | 0.033869 | 1.098077 | [
"s127561756",
"s586818145"
] |
u599925824 | p03109 | python | s923591344 | s113934649 | 19 | 17 | 3,312 | 2,940 | Accepted | Accepted | 10.53 | import datetime
H = '2019/04/30'
S = str(eval(input()))
print(('TBD' if H<S else 'Heisei')) | print(('TBD' if '20190430'<str(eval(input())).replace('/','') else 'Heisei')) | 4 | 1 | 86 | 69 | import datetime
H = "2019/04/30"
S = str(eval(input()))
print(("TBD" if H < S else "Heisei"))
| print(("TBD" if "20190430" < str(eval(input())).replace("/", "") else "Heisei"))
| false | 75 | [
"-import datetime",
"-",
"-H = \"2019/04/30\"",
"-S = str(eval(input()))",
"-print((\"TBD\" if H < S else \"Heisei\"))",
"+print((\"TBD\" if \"20190430\" < str(eval(input())).replace(\"/\", \"\") else \"Heisei\"))"
] | false | 0.141269 | 0.049718 | 2.841385 | [
"s923591344",
"s113934649"
] |
u600402037 | p03086 | python | s218518616 | s532008804 | 21 | 18 | 3,316 | 3,064 | Accepted | Accepted | 14.29 | S = eval(input())
from collections import deque
answer = 0
queue = deque()
target = {'A','C','G','T'}
for s in S:
if s in target:
queue.append(s)
else:
answer = max(answer, len(queue))
queue.clear()
answer = max(answer, len(queue))
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
se = {'A', 'C', 'G', 'T'}
S = sr()
cand = []
answer = []
for s in S:
if s in se:
cand.append(s)
else:
if len(cand) > len(answer):
answer = cand
cand = []
if len(cand) > len(answer):
answer = cand
print((len(answer)))
| 15 | 22 | 288 | 422 | S = eval(input())
from collections import deque
answer = 0
queue = deque()
target = {"A", "C", "G", "T"}
for s in S:
if s in target:
queue.append(s)
else:
answer = max(answer, len(queue))
queue.clear()
answer = max(answer, len(queue))
print(answer)
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
se = {"A", "C", "G", "T"}
S = sr()
cand = []
answer = []
for s in S:
if s in se:
cand.append(s)
else:
if len(cand) > len(answer):
answer = cand
cand = []
if len(cand) > len(answer):
answer = cand
print((len(answer)))
| false | 31.818182 | [
"-S = eval(input())",
"-from collections import deque",
"+# coding: utf-8",
"+import sys",
"-answer = 0",
"-queue = deque()",
"-target = {\"A\", \"C\", \"G\", \"T\"}",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+se = {\"A\", \"C\", \"G\", \"T\"}",
"+S = sr()",
"+cand = []",
"+answer = []",
"- if s in target:",
"- queue.append(s)",
"+ if s in se:",
"+ cand.append(s)",
"- answer = max(answer, len(queue))",
"- queue.clear()",
"-answer = max(answer, len(queue))",
"-print(answer)",
"+ if len(cand) > len(answer):",
"+ answer = cand",
"+ cand = []",
"+if len(cand) > len(answer):",
"+ answer = cand",
"+print((len(answer)))"
] | false | 0.036381 | 0.035845 | 1.014948 | [
"s218518616",
"s532008804"
] |
u282228874 | p03240 | python | s800414020 | s800312545 | 526 | 38 | 3,064 | 3,064 | Accepted | Accepted | 92.78 | N = int(eval(input()))
XYH = [list(map(int,input().split())) for i in range(N)]
XYH.sort(key = lambda x:x[2], reverse = 1)
for Cx in range(101):
for Cy in range(101):
H = XYH[0][2]+abs(XYH[0][0]-Cx)+abs(XYH[0][1]-Cy)
cnt = 0
for X,Y,h in XYH:
if h == max(H-abs(X-Cx)-abs(Y-Cy),0):
cnt += 1
if cnt == N:
print((Cx,Cy,H))
break | N = int(eval(input()))
XYH = [list(map(int,input().split())) for i in range(N)]
XYH.sort(key = lambda x:x[2], reverse = 1)
mx,my,mh = XYH[0]
for Cx in range(101):
for Cy in range(101):
H = mh+abs(mx-Cx)+abs(my-Cy)
if all(h == max(H-abs(X-Cx)-abs(Y-Cy),0) for X,Y,h in XYH):
print((Cx,Cy,H))
break | 13 | 10 | 421 | 341 | N = int(eval(input()))
XYH = [list(map(int, input().split())) for i in range(N)]
XYH.sort(key=lambda x: x[2], reverse=1)
for Cx in range(101):
for Cy in range(101):
H = XYH[0][2] + abs(XYH[0][0] - Cx) + abs(XYH[0][1] - Cy)
cnt = 0
for X, Y, h in XYH:
if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
cnt += 1
if cnt == N:
print((Cx, Cy, H))
break
| N = int(eval(input()))
XYH = [list(map(int, input().split())) for i in range(N)]
XYH.sort(key=lambda x: x[2], reverse=1)
mx, my, mh = XYH[0]
for Cx in range(101):
for Cy in range(101):
H = mh + abs(mx - Cx) + abs(my - Cy)
if all(h == max(H - abs(X - Cx) - abs(Y - Cy), 0) for X, Y, h in XYH):
print((Cx, Cy, H))
break
| false | 23.076923 | [
"+mx, my, mh = XYH[0]",
"- H = XYH[0][2] + abs(XYH[0][0] - Cx) + abs(XYH[0][1] - Cy)",
"- cnt = 0",
"- for X, Y, h in XYH:",
"- if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):",
"- cnt += 1",
"- if cnt == N:",
"+ H = mh + abs(mx - Cx) + abs(my - Cy)",
"+ if all(h == max(H - abs(X - Cx) - abs(Y - Cy), 0) for X, Y, h in XYH):"
] | false | 0.242588 | 0.049757 | 4.875477 | [
"s800414020",
"s800312545"
] |
u136395536 | p03617 | python | s753124187 | s797480497 | 19 | 17 | 3,064 | 3,064 | Accepted | Accepted | 10.53 | Q,H,S,D = (int(i) for i in input().split())
N = int(eval(input()))
q = Q*4
h = H*2
s = S
d = D/2
if min(q,h,s,d)==d:
if N%2 == 0:
money = D*(N//2)
else:
money = (N//2)*D + min(q,h,s)
else:
money = min(q,h,s)*N
print((int(money))) | Q,H,S,D = (int(i) for i in input().split())
N = int(eval(input()))
Qper025L = Q
Hper025L = H / 2
Sper025L = S / 4
Dper025L = D / 8
teainfo = [["Q",Qper025L,Q,0.25],["H",Hper025L,H,0.50],["S",Sper025L,S,1],["D",Dper025L,D,2]]
sortedtea = sorted(teainfo, key = lambda x:(x[1],x[2]), reverse = False)
price = 0
for i in range(4):
if sortedtea[i][3] <= N:
numbottles = int(N / sortedtea[i][3])
N -= sortedtea[i][3] * numbottles
price += sortedtea[i][2] * numbottles
print((int(price))) | 17 | 21 | 268 | 527 | Q, H, S, D = (int(i) for i in input().split())
N = int(eval(input()))
q = Q * 4
h = H * 2
s = S
d = D / 2
if min(q, h, s, d) == d:
if N % 2 == 0:
money = D * (N // 2)
else:
money = (N // 2) * D + min(q, h, s)
else:
money = min(q, h, s) * N
print((int(money)))
| Q, H, S, D = (int(i) for i in input().split())
N = int(eval(input()))
Qper025L = Q
Hper025L = H / 2
Sper025L = S / 4
Dper025L = D / 8
teainfo = [
["Q", Qper025L, Q, 0.25],
["H", Hper025L, H, 0.50],
["S", Sper025L, S, 1],
["D", Dper025L, D, 2],
]
sortedtea = sorted(teainfo, key=lambda x: (x[1], x[2]), reverse=False)
price = 0
for i in range(4):
if sortedtea[i][3] <= N:
numbottles = int(N / sortedtea[i][3])
N -= sortedtea[i][3] * numbottles
price += sortedtea[i][2] * numbottles
print((int(price)))
| false | 19.047619 | [
"-q = Q * 4",
"-h = H * 2",
"-s = S",
"-d = D / 2",
"-if min(q, h, s, d) == d:",
"- if N % 2 == 0:",
"- money = D * (N // 2)",
"- else:",
"- money = (N // 2) * D + min(q, h, s)",
"-else:",
"- money = min(q, h, s) * N",
"-print((int(money)))",
"+Qper025L = Q",
"+Hper025L = H / 2",
"+Sper025L = S / 4",
"+Dper025L = D / 8",
"+teainfo = [",
"+ [\"Q\", Qper025L, Q, 0.25],",
"+ [\"H\", Hper025L, H, 0.50],",
"+ [\"S\", Sper025L, S, 1],",
"+ [\"D\", Dper025L, D, 2],",
"+]",
"+sortedtea = sorted(teainfo, key=lambda x: (x[1], x[2]), reverse=False)",
"+price = 0",
"+for i in range(4):",
"+ if sortedtea[i][3] <= N:",
"+ numbottles = int(N / sortedtea[i][3])",
"+ N -= sortedtea[i][3] * numbottles",
"+ price += sortedtea[i][2] * numbottles",
"+print((int(price)))"
] | false | 0.05523 | 0.087102 | 0.634082 | [
"s753124187",
"s797480497"
] |
u790710233 | p02804 | python | s801936836 | s318526973 | 399 | 337 | 39,648 | 39,900 | Accepted | Accepted | 15.54 | from collections import defaultdict
MOD = 10**9+7
n, K = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = defaultdict(int)
for a in A:
cnt[a] += 1
keys = sorted(cnt.keys())
key_to_idx = defaultdict(int)
for i, k in enumerate(keys):
key_to_idx[k] = i
Acum = [0]
for k in keys:
Acum.append(Acum[-1]+cnt[k])
U = n
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
fact[i] = fact[i-1]*i % MOD
invfact = [0]*(U+1)
invfact[U] = pow(fact[U], MOD-2, MOD)
for i in reversed(list(range(U))):
invfact[i] = invfact[i+1]*(i+1) % MOD
def nCr(n, r):
if r < 0 or n < r:
return 0
return fact[n]*invfact[r]*invfact[n-r]
MAX = 0
for k in reversed(keys):
x = Acum[key_to_idx[k]+1]
y = Acum[key_to_idx[k]]
c = nCr(x, K) - nCr(y, K)
MAX += c*k
MAX %= MOD
MIN = 0
for k in keys:
x = n-Acum[key_to_idx[k]]
y = n-Acum[key_to_idx[k]+1]
c = nCr(x, K) - nCr(y, K)
MIN += c*k
MIN %= MOD
print(((MAX-MIN) % MOD))
| from collections import defaultdict, Counter
MOD = 10**9+7
n, K = list(map(int, input().split()))
cnt = Counter(list(map(int, input().split())))
keys = sorted(cnt.keys())
key_to_idx = defaultdict(int)
for i, k in enumerate(keys):
key_to_idx[k] = i
Acum = [0]
for k in keys:
Acum.append(Acum[-1]+cnt[k])
U = n
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
fact[i] = fact[i-1]*i % MOD
invfact = [0]*(U+1)
invfact[U] = pow(fact[U], MOD-2, MOD)
for i in reversed(list(range(U))):
invfact[i] = invfact[i+1]*(i+1) % MOD
def nCr(n, r):
if r < 0 or n < r:
return 0
return fact[n]*invfact[r]*invfact[n-r]
ans = 0
for k in keys:
x = Acum[key_to_idx[k]+1]
y = Acum[key_to_idx[k]]
cmax = nCr(x, K) - nCr(y, K)
cmin = nCr(n-y, K) - nCr(n-x, K)
ans += k*(cmax-cmin)
ans %= MOD
print(ans)
| 54 | 42 | 1,032 | 869 | from collections import defaultdict
MOD = 10**9 + 7
n, K = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = defaultdict(int)
for a in A:
cnt[a] += 1
keys = sorted(cnt.keys())
key_to_idx = defaultdict(int)
for i, k in enumerate(keys):
key_to_idx[k] = i
Acum = [0]
for k in keys:
Acum.append(Acum[-1] + cnt[k])
U = n
fact = [0] * (U + 1)
fact[0] = 1
for i in range(1, U + 1):
fact[i] = fact[i - 1] * i % MOD
invfact = [0] * (U + 1)
invfact[U] = pow(fact[U], MOD - 2, MOD)
for i in reversed(list(range(U))):
invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCr(n, r):
if r < 0 or n < r:
return 0
return fact[n] * invfact[r] * invfact[n - r]
MAX = 0
for k in reversed(keys):
x = Acum[key_to_idx[k] + 1]
y = Acum[key_to_idx[k]]
c = nCr(x, K) - nCr(y, K)
MAX += c * k
MAX %= MOD
MIN = 0
for k in keys:
x = n - Acum[key_to_idx[k]]
y = n - Acum[key_to_idx[k] + 1]
c = nCr(x, K) - nCr(y, K)
MIN += c * k
MIN %= MOD
print(((MAX - MIN) % MOD))
| from collections import defaultdict, Counter
MOD = 10**9 + 7
n, K = list(map(int, input().split()))
cnt = Counter(list(map(int, input().split())))
keys = sorted(cnt.keys())
key_to_idx = defaultdict(int)
for i, k in enumerate(keys):
key_to_idx[k] = i
Acum = [0]
for k in keys:
Acum.append(Acum[-1] + cnt[k])
U = n
fact = [0] * (U + 1)
fact[0] = 1
for i in range(1, U + 1):
fact[i] = fact[i - 1] * i % MOD
invfact = [0] * (U + 1)
invfact[U] = pow(fact[U], MOD - 2, MOD)
for i in reversed(list(range(U))):
invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCr(n, r):
if r < 0 or n < r:
return 0
return fact[n] * invfact[r] * invfact[n - r]
ans = 0
for k in keys:
x = Acum[key_to_idx[k] + 1]
y = Acum[key_to_idx[k]]
cmax = nCr(x, K) - nCr(y, K)
cmin = nCr(n - y, K) - nCr(n - x, K)
ans += k * (cmax - cmin)
ans %= MOD
print(ans)
| false | 22.222222 | [
"-from collections import defaultdict",
"+from collections import defaultdict, Counter",
"-A = list(map(int, input().split()))",
"-cnt = defaultdict(int)",
"-for a in A:",
"- cnt[a] += 1",
"+cnt = Counter(list(map(int, input().split())))",
"-MAX = 0",
"-for k in reversed(keys):",
"+ans = 0",
"+for k in keys:",
"- c = nCr(x, K) - nCr(y, K)",
"- MAX += c * k",
"- MAX %= MOD",
"-MIN = 0",
"-for k in keys:",
"- x = n - Acum[key_to_idx[k]]",
"- y = n - Acum[key_to_idx[k] + 1]",
"- c = nCr(x, K) - nCr(y, K)",
"- MIN += c * k",
"- MIN %= MOD",
"-print(((MAX - MIN) % MOD))",
"+ cmax = nCr(x, K) - nCr(y, K)",
"+ cmin = nCr(n - y, K) - nCr(n - x, K)",
"+ ans += k * (cmax - cmin)",
"+ ans %= MOD",
"+print(ans)"
] | false | 0.036331 | 0.034025 | 1.067768 | [
"s801936836",
"s318526973"
] |
u540761833 | p02937 | python | s346749833 | s293634994 | 936 | 409 | 3,316 | 7,924 | Accepted | Accepted | 56.3 | s = eval(input())
t = eval(input())
lent = len(t)
tcount = 0
snow = 0
count = 0
flag = True
if t[0] not in s:
print((-1))
else:
snow = s.index(t[0])
while True:
tcount += 1
if tcount == lent:
break
if t[tcount] in s[snow+1:]:
snow = s[snow+1:].index(t[tcount])+snow+1
elif t[tcount] in s:
snow = s.index(t[tcount])
count += 1
else:
flag = False
break
if flag:
print((count*len(s) + snow+1))
else:
print((-1)) | from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for i in range(len(s)):
dicta[s[i]] += [i]
snow = -1
count = 0
flag = True
for i in t:
if i not in s:
flag = False
break
nowt = dicta[i]
snowind = bisect.bisect_right(nowt,snow)
if snowind == len(nowt):
count += 1
snow = nowt[0]
else:
snow = nowt[snowind]
if flag:
print((len(s)*count+snow +1))
else:
print((-1))
| 27 | 26 | 564 | 514 | s = eval(input())
t = eval(input())
lent = len(t)
tcount = 0
snow = 0
count = 0
flag = True
if t[0] not in s:
print((-1))
else:
snow = s.index(t[0])
while True:
tcount += 1
if tcount == lent:
break
if t[tcount] in s[snow + 1 :]:
snow = s[snow + 1 :].index(t[tcount]) + snow + 1
elif t[tcount] in s:
snow = s.index(t[tcount])
count += 1
else:
flag = False
break
if flag:
print((count * len(s) + snow + 1))
else:
print((-1))
| from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for i in range(len(s)):
dicta[s[i]] += [i]
snow = -1
count = 0
flag = True
for i in t:
if i not in s:
flag = False
break
nowt = dicta[i]
snowind = bisect.bisect_right(nowt, snow)
if snowind == len(nowt):
count += 1
snow = nowt[0]
else:
snow = nowt[snowind]
if flag:
print((len(s) * count + snow + 1))
else:
print((-1))
| false | 3.703704 | [
"+from collections import defaultdict",
"+import bisect",
"+",
"-lent = len(t)",
"-tcount = 0",
"-snow = 0",
"+dicta = defaultdict(list)",
"+for i in range(len(s)):",
"+ dicta[s[i]] += [i]",
"+snow = -1",
"-if t[0] not in s:",
"+for i in t:",
"+ if i not in s:",
"+ flag = False",
"+ break",
"+ nowt = dicta[i]",
"+ snowind = bisect.bisect_right(nowt, snow)",
"+ if snowind == len(nowt):",
"+ count += 1",
"+ snow = nowt[0]",
"+ else:",
"+ snow = nowt[snowind]",
"+if flag:",
"+ print((len(s) * count + snow + 1))",
"+else:",
"-else:",
"- snow = s.index(t[0])",
"- while True:",
"- tcount += 1",
"- if tcount == lent:",
"- break",
"- if t[tcount] in s[snow + 1 :]:",
"- snow = s[snow + 1 :].index(t[tcount]) + snow + 1",
"- elif t[tcount] in s:",
"- snow = s.index(t[tcount])",
"- count += 1",
"- else:",
"- flag = False",
"- break",
"- if flag:",
"- print((count * len(s) + snow + 1))",
"- else:",
"- print((-1))"
] | false | 0.03639 | 0.046556 | 0.781648 | [
"s346749833",
"s293634994"
] |
u844646164 | p03633 | python | s882340165 | s152390371 | 261 | 53 | 64,364 | 5,684 | Accepted | Accepted | 79.69 | n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]
from fractions import gcd
def lcm(l):
x = l[0]
for i in range(1, len(l)):
x = (x * l[i]) // gcd(x, l[i])
return x
print((lcm(l))) | n = int(eval(input()))
t = [int(eval(input())) for _ in range(n)]
from fractions import gcd
def lcm(t):
x = t[0]
for i in range(1, len(t)):
x = (x * t[i]) // gcd(x, t[i])
return x
print((lcm(t))) | 11 | 13 | 203 | 209 | n = int(eval(input()))
l = [int(eval(input())) for _ in range(n)]
from fractions import gcd
def lcm(l):
x = l[0]
for i in range(1, len(l)):
x = (x * l[i]) // gcd(x, l[i])
return x
print((lcm(l)))
| n = int(eval(input()))
t = [int(eval(input())) for _ in range(n)]
from fractions import gcd
def lcm(t):
x = t[0]
for i in range(1, len(t)):
x = (x * t[i]) // gcd(x, t[i])
return x
print((lcm(t)))
| false | 15.384615 | [
"-l = [int(eval(input())) for _ in range(n)]",
"+t = [int(eval(input())) for _ in range(n)]",
"-def lcm(l):",
"- x = l[0]",
"- for i in range(1, len(l)):",
"- x = (x * l[i]) // gcd(x, l[i])",
"+def lcm(t):",
"+ x = t[0]",
"+ for i in range(1, len(t)):",
"+ x = (x * t[i]) // gcd(x, t[i])",
"-print((lcm(l)))",
"+print((lcm(t)))"
] | false | 0.045952 | 0.046212 | 0.994374 | [
"s882340165",
"s152390371"
] |
u219197917 | p03038 | python | s021161221 | s082540559 | 374 | 307 | 27,852 | 28,108 | Accepted | Accepted | 17.91 | import sys
from operator import itemgetter
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = sorted(int(i) for i in read().split())
bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)
d = []
for b, c in bc:
if len(d) < n:
d += [c] * b
for i in range(min(n, len(d))):
if a[i] < d[i]:
a[i] = d[i]
else:
break
print((sum(a)))
if __name__ == '__main__':
main() | def main():
n, m = list(map(int, input().split()))
a = sorted(int(i) for i in input().split())
bc = [(0, 0) for _ in range(m)]
for i in range(m):
b, c = list(map(int, input().split()))
bc[i] = (c, b)
bc.sort(reverse=True)
k = 0
d = []
for c, b in bc:
if k + b > n:
d += [c] * (n - k)
break
d += [c] * b
k += b
for i in range(len(d)):
if a[i] < d[i]:
a[i] = d[i]
else:
break
print((sum(a)))
if __name__ == '__main__':
main()
| 23 | 26 | 569 | 585 | import sys
from operator import itemgetter
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = sorted(int(i) for i in read().split())
bc = sorted(
[[int(i) for i in read().split()] for _ in range(m)],
key=itemgetter(1),
reverse=True,
)
d = []
for b, c in bc:
if len(d) < n:
d += [c] * b
for i in range(min(n, len(d))):
if a[i] < d[i]:
a[i] = d[i]
else:
break
print((sum(a)))
if __name__ == "__main__":
main()
| def main():
n, m = list(map(int, input().split()))
a = sorted(int(i) for i in input().split())
bc = [(0, 0) for _ in range(m)]
for i in range(m):
b, c = list(map(int, input().split()))
bc[i] = (c, b)
bc.sort(reverse=True)
k = 0
d = []
for c, b in bc:
if k + b > n:
d += [c] * (n - k)
break
d += [c] * b
k += b
for i in range(len(d)):
if a[i] < d[i]:
a[i] = d[i]
else:
break
print((sum(a)))
if __name__ == "__main__":
main()
| false | 11.538462 | [
"-import sys",
"-from operator import itemgetter",
"-",
"-",
"-def read():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"- n, m = list(map(int, read().split()))",
"- a = sorted(int(i) for i in read().split())",
"- bc = sorted(",
"- [[int(i) for i in read().split()] for _ in range(m)],",
"- key=itemgetter(1),",
"- reverse=True,",
"- )",
"+ n, m = list(map(int, input().split()))",
"+ a = sorted(int(i) for i in input().split())",
"+ bc = [(0, 0) for _ in range(m)]",
"+ for i in range(m):",
"+ b, c = list(map(int, input().split()))",
"+ bc[i] = (c, b)",
"+ bc.sort(reverse=True)",
"+ k = 0",
"- for b, c in bc:",
"- if len(d) < n:",
"- d += [c] * b",
"- for i in range(min(n, len(d))):",
"+ for c, b in bc:",
"+ if k + b > n:",
"+ d += [c] * (n - k)",
"+ break",
"+ d += [c] * b",
"+ k += b",
"+ for i in range(len(d)):"
] | false | 0.047704 | 0.036996 | 1.289447 | [
"s021161221",
"s082540559"
] |
u150984829 | p02277 | python | s862731441 | s135224298 | 1,250 | 750 | 20,176 | 20,332 | Accepted | Accepted | 40 | import sys
def t(A,p,r):
x=A[r][1];i=p-1
for j in range(p,r):
if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
A[i+1],A[r]=A[r],A[i+1]
return i+1
def k(A,p,r):
if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def m(L,R):
T=[]
for l in L[::-1]:
while R and R[-1][1]>=l[1]:T+=[R.pop()]
T+=[l]
return R+T[::-1]
def d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
n=int(eval(input()))
f=lambda x,y:(x,int(y))
A=[f(*e.split())for e in sys.stdin]
B=A[:]
k(A,0,n-1)
print((['Not s','S'][A==d(B)]+'table'))
for e in A:print((*e))
| import sys
def t(A,p,r):
x=A[r][1];i=p-1
for j in range(p,r):
if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
A[i+1],A[r]=A[r],A[i+1]
return i+1
def k(A,p,r):
if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
for i in range(n-1):
if A[i][1]==A[i+1][1]:
if A[i][2]>A[i+1][2]:return 0
return 1
n=int(eval(input()))
f=lambda x,y:(x,int(y))
A=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]
k(A,0,n-1)
print((['Not s','S'][s(A)]+'table'))
for e in A:print((*e[:2]))
| 23 | 20 | 543 | 480 | import sys
def t(A, p, r):
x = A[r][1]
i = p - 1
for j in range(p, r):
if A[j][1] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def k(A, p, r):
if p < r:
q = t(A, p, r)
k(A, p, q - 1)
k(A, q + 1, r)
def m(L, R):
T = []
for l in L[::-1]:
while R and R[-1][1] >= l[1]:
T += [R.pop()]
T += [l]
return R + T[::-1]
def d(A):
l = len(A)
s = l // 2
return m(d(A[:s]), d(A[s:])) if l > 1 else A
n = int(eval(input()))
f = lambda x, y: (x, int(y))
A = [f(*e.split()) for e in sys.stdin]
B = A[:]
k(A, 0, n - 1)
print((["Not s", "S"][A == d(B)] + "table"))
for e in A:
print((*e))
| import sys
def t(A, p, r):
x = A[r][1]
i = p - 1
for j in range(p, r):
if A[j][1] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def k(A, p, r):
if p < r:
q = t(A, p, r)
k(A, p, q - 1)
k(A, q + 1, r)
def s(A):
for i in range(n - 1):
if A[i][1] == A[i + 1][1]:
if A[i][2] > A[i + 1][2]:
return 0
return 1
n = int(eval(input()))
f = lambda x, y: (x, int(y))
A = [(*f(*e.split()), i) for i, e in enumerate(sys.stdin)]
k(A, 0, n - 1)
print((["Not s", "S"][s(A)] + "table"))
for e in A:
print((*e[:2]))
| false | 13.043478 | [
"-def m(L, R):",
"- T = []",
"- for l in L[::-1]:",
"- while R and R[-1][1] >= l[1]:",
"- T += [R.pop()]",
"- T += [l]",
"- return R + T[::-1]",
"-",
"-",
"-def d(A):",
"- l = len(A)",
"- s = l // 2",
"- return m(d(A[:s]), d(A[s:])) if l > 1 else A",
"+def s(A):",
"+ for i in range(n - 1):",
"+ if A[i][1] == A[i + 1][1]:",
"+ if A[i][2] > A[i + 1][2]:",
"+ return 0",
"+ return 1",
"-A = [f(*e.split()) for e in sys.stdin]",
"-B = A[:]",
"+A = [(*f(*e.split()), i) for i, e in enumerate(sys.stdin)]",
"-print(([\"Not s\", \"S\"][A == d(B)] + \"table\"))",
"+print(([\"Not s\", \"S\"][s(A)] + \"table\"))",
"- print((*e))",
"+ print((*e[:2]))"
] | false | 0.048639 | 0.048284 | 1.007367 | [
"s862731441",
"s135224298"
] |
u527993431 | p02779 | python | s586539729 | s627223219 | 92 | 84 | 26,804 | 26,808 | Accepted | Accepted | 8.7 | N=int(eval(input()))
S=list(map(int,input().split()))
P=set(S)
Q=len(P)
if N==Q:
print("YES")
else:
print("NO") | N=int(eval(input()))
L=list(map(int,input().split()))
if N==len(set(L)):
print("YES")
else:
print("NO") | 8 | 6 | 114 | 106 | N = int(eval(input()))
S = list(map(int, input().split()))
P = set(S)
Q = len(P)
if N == Q:
print("YES")
else:
print("NO")
| N = int(eval(input()))
L = list(map(int, input().split()))
if N == len(set(L)):
print("YES")
else:
print("NO")
| false | 25 | [
"-S = list(map(int, input().split()))",
"-P = set(S)",
"-Q = len(P)",
"-if N == Q:",
"+L = list(map(int, input().split()))",
"+if N == len(set(L)):"
] | false | 0.069016 | 0.05468 | 1.262174 | [
"s586539729",
"s627223219"
] |
u426764965 | p02732 | python | s798184066 | s616867808 | 476 | 410 | 32,688 | 26,780 | Accepted | Accepted | 13.87 | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
# 書かれた番号の頻度
Freq = dict(sorted(list(Counter(A).items()), key=lambda x: x[1], reverse=True))
# 答えの最大値
ans_max = 0
for kv in list(Freq.items()):
ans_max += kv[1] * (kv[1] - 1) // 2
for a in A:
# 1個しか存在しない番号は、取り除いても答えに影響しない
if Freq.get(a) == 1:
print(ans_max)
continue
# x個の場合と、x-1個の場合と、の差分
x = Freq.get(a)
diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)
# そのぶんだけ、答えの最大値から減らす
ans = ans_max - diff
print(ans) | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
# 書かれた番号の頻度
Freq = Counter(A)
# 答えの最大値
ans_max = 0
for kv in list(Freq.items()):
ans_max += kv[1] * (kv[1] - 1) // 2
for a in A:
# 1個しか存在しない番号は、取り除いても答えに影響しない
if Freq.get(a) == 1:
print(ans_max)
continue
# x個の場合と、x-1個の場合と、の差分
x = Freq.get(a)
diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)
# そのぶんだけ、答えの最大値から減らす
ans = ans_max - diff
print(ans) | 26 | 26 | 533 | 477 | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
# 書かれた番号の頻度
Freq = dict(sorted(list(Counter(A).items()), key=lambda x: x[1], reverse=True))
# 答えの最大値
ans_max = 0
for kv in list(Freq.items()):
ans_max += kv[1] * (kv[1] - 1) // 2
for a in A:
# 1個しか存在しない番号は、取り除いても答えに影響しない
if Freq.get(a) == 1:
print(ans_max)
continue
# x個の場合と、x-1個の場合と、の差分
x = Freq.get(a)
diff = (x * (x - 1) // 2) - ((x - 1) * (x - 2) // 2)
# そのぶんだけ、答えの最大値から減らす
ans = ans_max - diff
print(ans)
| from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
# 書かれた番号の頻度
Freq = Counter(A)
# 答えの最大値
ans_max = 0
for kv in list(Freq.items()):
ans_max += kv[1] * (kv[1] - 1) // 2
for a in A:
# 1個しか存在しない番号は、取り除いても答えに影響しない
if Freq.get(a) == 1:
print(ans_max)
continue
# x個の場合と、x-1個の場合と、の差分
x = Freq.get(a)
diff = (x * (x - 1) // 2) - ((x - 1) * (x - 2) // 2)
# そのぶんだけ、答えの最大値から減らす
ans = ans_max - diff
print(ans)
| false | 0 | [
"-Freq = dict(sorted(list(Counter(A).items()), key=lambda x: x[1], reverse=True))",
"+Freq = Counter(A)"
] | false | 0.07793 | 0.036881 | 2.113041 | [
"s798184066",
"s616867808"
] |
u581187895 | p02579 | python | s070526470 | s807978766 | 561 | 461 | 98,272 | 93,868 | Accepted | Accepted | 17.83 |
from collections import deque
def resolve():
drc4 = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + drc4]
H, W = list(map(int, input().split()))
sy, sx = [int(x) - 1 for x in input().split()]
gy, gx = [int(x) - 1 for x in input().split()]
G = [eval(input()) for _ in range(H)]
INF = 10 ** 12
ans = [[INF] * W for _ in range(H)]
q = deque()
q.append((sy, sx, 0))
ans[sy][sx] = 0
while q:
sy, sx, cost = q.popleft()
for dy, dx in drc4:
ny = dy + sy
nx = dx + sx
if 0 <= ny < H and 0 <= nx < W and G[ny][nx] == "." and ans[ny][nx] > cost:
ans[ny][nx] = cost
# q.appendleft 使用
q.appendleft((ny, nx, cost))
for dy8, dx8 in warp:
ny8 = dy8 + sy
nx8 = dx8 + sx
if 0 <= ny8 < H and 0 <= nx8 < W and G[ny8][nx8] == "." and ans[ny8][nx8] > cost + 1:
ans[ny8][nx8] = cost + 1
# q.appendleft 使用しない
q.append((ny8, nx8, cost + 1))
res = ans[gy][gx] if ans[gy][gx] < INF else -1
print(res)
if __name__ == "__main__":
resolve() |
from collections import deque
def resolve():
drc4 = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + drc4]
H, W = list(map(int, input().split()))
sy, sx = [int(x) - 1 for x in input().split()]
gy, gx = [int(x) - 1 for x in input().split()]
G = [eval(input()) for _ in range(H)]
INF = 10 ** 12
dist = [[INF] * W for _ in range(H)]
q = deque()
q.append((sy, sx))
dist[sy][sx] = 0
cnt = 0
while True:
next_warp = []
while q:
sy, sx = q.popleft()
next_warp.append((sy, sx))
for dy, dx in drc4:
ny = dy + sy
nx = dx + sx
if 0 <= ny < H and 0 <= nx < W and G[ny][nx] == "." and dist[ny][nx] == INF:
dist[ny][nx] = cnt
q.append((ny, nx))
for sy, sx in next_warp:
for dy8, dx8 in warp:
ny8 = dy8 + sy
nx8 = dx8 + sx
if 0 <= ny8 < H and 0 <= nx8 < W and G[ny8][nx8] == "." and dist[ny8][nx8] == INF:
dist[ny8][nx8] = cnt + 1
q.append((ny8, nx8))
if not q or dist[gy][gx] != INF:
break
cnt += 1
ans = dist[gy][gx] if dist[gy][gx] != INF else -1
print(ans)
if __name__ == "__main__":
resolve() | 42 | 48 | 1,285 | 1,449 | from collections import deque
def resolve():
drc4 = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [
(i, j)
for i in range(-2, 3)
for j in range(-2, 3)
if (i, j) not in [(0, 0)] + drc4
]
H, W = list(map(int, input().split()))
sy, sx = [int(x) - 1 for x in input().split()]
gy, gx = [int(x) - 1 for x in input().split()]
G = [eval(input()) for _ in range(H)]
INF = 10**12
ans = [[INF] * W for _ in range(H)]
q = deque()
q.append((sy, sx, 0))
ans[sy][sx] = 0
while q:
sy, sx, cost = q.popleft()
for dy, dx in drc4:
ny = dy + sy
nx = dx + sx
if 0 <= ny < H and 0 <= nx < W and G[ny][nx] == "." and ans[ny][nx] > cost:
ans[ny][nx] = cost
# q.appendleft 使用
q.appendleft((ny, nx, cost))
for dy8, dx8 in warp:
ny8 = dy8 + sy
nx8 = dx8 + sx
if (
0 <= ny8 < H
and 0 <= nx8 < W
and G[ny8][nx8] == "."
and ans[ny8][nx8] > cost + 1
):
ans[ny8][nx8] = cost + 1
# q.appendleft 使用しない
q.append((ny8, nx8, cost + 1))
res = ans[gy][gx] if ans[gy][gx] < INF else -1
print(res)
if __name__ == "__main__":
resolve()
| from collections import deque
def resolve():
drc4 = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [
(i, j)
for i in range(-2, 3)
for j in range(-2, 3)
if (i, j) not in [(0, 0)] + drc4
]
H, W = list(map(int, input().split()))
sy, sx = [int(x) - 1 for x in input().split()]
gy, gx = [int(x) - 1 for x in input().split()]
G = [eval(input()) for _ in range(H)]
INF = 10**12
dist = [[INF] * W for _ in range(H)]
q = deque()
q.append((sy, sx))
dist[sy][sx] = 0
cnt = 0
while True:
next_warp = []
while q:
sy, sx = q.popleft()
next_warp.append((sy, sx))
for dy, dx in drc4:
ny = dy + sy
nx = dx + sx
if (
0 <= ny < H
and 0 <= nx < W
and G[ny][nx] == "."
and dist[ny][nx] == INF
):
dist[ny][nx] = cnt
q.append((ny, nx))
for sy, sx in next_warp:
for dy8, dx8 in warp:
ny8 = dy8 + sy
nx8 = dx8 + sx
if (
0 <= ny8 < H
and 0 <= nx8 < W
and G[ny8][nx8] == "."
and dist[ny8][nx8] == INF
):
dist[ny8][nx8] = cnt + 1
q.append((ny8, nx8))
if not q or dist[gy][gx] != INF:
break
cnt += 1
ans = dist[gy][gx] if dist[gy][gx] != INF else -1
print(ans)
if __name__ == "__main__":
resolve()
| false | 12.5 | [
"- ans = [[INF] * W for _ in range(H)]",
"+ dist = [[INF] * W for _ in range(H)]",
"- q.append((sy, sx, 0))",
"- ans[sy][sx] = 0",
"- while q:",
"- sy, sx, cost = q.popleft()",
"- for dy, dx in drc4:",
"- ny = dy + sy",
"- nx = dx + sx",
"- if 0 <= ny < H and 0 <= nx < W and G[ny][nx] == \".\" and ans[ny][nx] > cost:",
"- ans[ny][nx] = cost",
"- # q.appendleft 使用",
"- q.appendleft((ny, nx, cost))",
"- for dy8, dx8 in warp:",
"- ny8 = dy8 + sy",
"- nx8 = dx8 + sx",
"- if (",
"- 0 <= ny8 < H",
"- and 0 <= nx8 < W",
"- and G[ny8][nx8] == \".\"",
"- and ans[ny8][nx8] > cost + 1",
"- ):",
"- ans[ny8][nx8] = cost + 1",
"- # q.appendleft 使用しない",
"- q.append((ny8, nx8, cost + 1))",
"- res = ans[gy][gx] if ans[gy][gx] < INF else -1",
"- print(res)",
"+ q.append((sy, sx))",
"+ dist[sy][sx] = 0",
"+ cnt = 0",
"+ while True:",
"+ next_warp = []",
"+ while q:",
"+ sy, sx = q.popleft()",
"+ next_warp.append((sy, sx))",
"+ for dy, dx in drc4:",
"+ ny = dy + sy",
"+ nx = dx + sx",
"+ if (",
"+ 0 <= ny < H",
"+ and 0 <= nx < W",
"+ and G[ny][nx] == \".\"",
"+ and dist[ny][nx] == INF",
"+ ):",
"+ dist[ny][nx] = cnt",
"+ q.append((ny, nx))",
"+ for sy, sx in next_warp:",
"+ for dy8, dx8 in warp:",
"+ ny8 = dy8 + sy",
"+ nx8 = dx8 + sx",
"+ if (",
"+ 0 <= ny8 < H",
"+ and 0 <= nx8 < W",
"+ and G[ny8][nx8] == \".\"",
"+ and dist[ny8][nx8] == INF",
"+ ):",
"+ dist[ny8][nx8] = cnt + 1",
"+ q.append((ny8, nx8))",
"+ if not q or dist[gy][gx] != INF:",
"+ break",
"+ cnt += 1",
"+ ans = dist[gy][gx] if dist[gy][gx] != INF else -1",
"+ print(ans)"
] | false | 0.076154 | 0.042806 | 1.779058 | [
"s070526470",
"s807978766"
] |
u969190727 | p02803 | python | s772830796 | s025632405 | 374 | 310 | 3,188 | 3,316 | Accepted | Accepted | 17.11 | h,w=list(map(int,input().split()))
inf=10**3
d=((-1,0),(1,0),(0,-1),(0,1))
S=[["#"]*(w+2)]
S.extend([["#"]+[s for s in eval(input())]+["#"] for _ in range(h)])
S.append(["#"]*(w+2))
import heapq
def dist(a,b):
D=[[inf]*(w+2) for _ in range(h+2)]
D[a][b]=0
Visit=[100*a+b]
heapq.heapify(Visit)
while Visit:
v=heapq.heappop(Visit)
vd,va,vb=v//(10**4),(v%(10**4))//100,v%100
for dx,dy in d:
if S[va+dx][vb+dy]=="." and D[va+dx][vb+dy]==inf:
heapq.heappush(Visit,(vd+1)*(10**4)+(va+dx)*(10**2)+vb+dy)
D[va+dx][vb+dy]=vd+1
ret=0
for i in range(h):
for j in range(w):
if D[i+1][j+1]<inf:
ret=max(ret,D[i+1][j+1])
return ret
ans=0
for i in range(h):
for j in range(w):
if S[i+1][j+1]==".":
ans=max(dist(i+1,j+1),ans)
print(ans)
| h,w=list(map(int,input().split()))
inf=10**3
d=((-1,0),(1,0),(0,-1),(0,1))
S=[["#"]*(w+2)]
S.extend([["#"]+[s for s in eval(input())]+["#"] for _ in range(h)])
S.append(["#"]*(w+2))
import collections
def dist(a,b):
D=[[inf]*(w+2) for _ in range(h+2)]
D[a][b]=0
Visit=collections.deque()
Visit.append(100*a+b)
while Visit:
v=Visit.popleft()
va,vb=v//100,v%100
for dx,dy in d:
if S[va+dx][vb+dy]=="." and D[va+dx][vb+dy]==inf:
Visit.append((va+dx)*100+(vb+dy))
D[va+dx][vb+dy]=D[va][vb]+1
ret=0
for i in range(h):
for j in range(w):
if D[i+1][j+1]<inf:
ret=max(ret,D[i+1][j+1])
return ret
ans=0
for i in range(h):
for j in range(w):
if S[i+1][j+1]==".":
ans=max(dist(i+1,j+1),ans)
print(ans)
| 35 | 34 | 827 | 795 | h, w = list(map(int, input().split()))
inf = 10**3
d = ((-1, 0), (1, 0), (0, -1), (0, 1))
S = [["#"] * (w + 2)]
S.extend([["#"] + [s for s in eval(input())] + ["#"] for _ in range(h)])
S.append(["#"] * (w + 2))
import heapq
def dist(a, b):
D = [[inf] * (w + 2) for _ in range(h + 2)]
D[a][b] = 0
Visit = [100 * a + b]
heapq.heapify(Visit)
while Visit:
v = heapq.heappop(Visit)
vd, va, vb = v // (10**4), (v % (10**4)) // 100, v % 100
for dx, dy in d:
if S[va + dx][vb + dy] == "." and D[va + dx][vb + dy] == inf:
heapq.heappush(
Visit, (vd + 1) * (10**4) + (va + dx) * (10**2) + vb + dy
)
D[va + dx][vb + dy] = vd + 1
ret = 0
for i in range(h):
for j in range(w):
if D[i + 1][j + 1] < inf:
ret = max(ret, D[i + 1][j + 1])
return ret
ans = 0
for i in range(h):
for j in range(w):
if S[i + 1][j + 1] == ".":
ans = max(dist(i + 1, j + 1), ans)
print(ans)
| h, w = list(map(int, input().split()))
inf = 10**3
d = ((-1, 0), (1, 0), (0, -1), (0, 1))
S = [["#"] * (w + 2)]
S.extend([["#"] + [s for s in eval(input())] + ["#"] for _ in range(h)])
S.append(["#"] * (w + 2))
import collections
def dist(a, b):
D = [[inf] * (w + 2) for _ in range(h + 2)]
D[a][b] = 0
Visit = collections.deque()
Visit.append(100 * a + b)
while Visit:
v = Visit.popleft()
va, vb = v // 100, v % 100
for dx, dy in d:
if S[va + dx][vb + dy] == "." and D[va + dx][vb + dy] == inf:
Visit.append((va + dx) * 100 + (vb + dy))
D[va + dx][vb + dy] = D[va][vb] + 1
ret = 0
for i in range(h):
for j in range(w):
if D[i + 1][j + 1] < inf:
ret = max(ret, D[i + 1][j + 1])
return ret
ans = 0
for i in range(h):
for j in range(w):
if S[i + 1][j + 1] == ".":
ans = max(dist(i + 1, j + 1), ans)
print(ans)
| false | 2.857143 | [
"-import heapq",
"+import collections",
"- Visit = [100 * a + b]",
"- heapq.heapify(Visit)",
"+ Visit = collections.deque()",
"+ Visit.append(100 * a + b)",
"- v = heapq.heappop(Visit)",
"- vd, va, vb = v // (10**4), (v % (10**4)) // 100, v % 100",
"+ v = Visit.popleft()",
"+ va, vb = v // 100, v % 100",
"- heapq.heappush(",
"- Visit, (vd + 1) * (10**4) + (va + dx) * (10**2) + vb + dy",
"- )",
"- D[va + dx][vb + dy] = vd + 1",
"+ Visit.append((va + dx) * 100 + (vb + dy))",
"+ D[va + dx][vb + dy] = D[va][vb] + 1"
] | false | 0.038232 | 0.037476 | 1.020183 | [
"s772830796",
"s025632405"
] |
u970197315 | p02949 | python | s902114507 | s027970646 | 1,612 | 1,397 | 53,464 | 53,208 | Accepted | Accepted | 13.34 | n,m,p=list(map(int,input().split()))
E=[list(map(int,input().split())) for i in range(m)]
INF=float("inf")
dist=[INF]*n
dist[0]=0
prev=0
# 閉路の長さの最大はnなので2*n回ループさせれば閉路検出ができる
for i in range(2*n):
for fr,to,cost in E:
fr,to=fr-1,to-1
cost*=-1
cost+=p
if dist[fr]!=INF and dist[to]>dist[fr]+cost:
dist[to]=dist[fr]+cost
if i>=n:
dist[to]=-float("inf")
if i==n-1:
prev=dist[n-1]
if prev==dist[n-1]:
print((max(-dist[n-1],0)))
else:
print((-1))
| def shortest_path(s):
dist[s]=0
for _ in range(n):
for fr,to,cost in edge:
if dist[fr]!=inf and dist[to]>dist[fr]+cost:
dist[to]=dist[fr]+cost
def find_negative_loops():
for _ in range(n):
for fr,to,cost in edge:
if dist[fr]!=inf and dist[to]>dist[fr]+cost:
dist[to]=dist[fr]+cost
negative[to]=True
if negative[fr]:negative[to]=True
n,m,p=map(int,input().split())
edge=[]
for i in range(m):
a,b,c=map(int,input().split())
edge.append([a-1,b-1,-c+p])
inf=float("inf")
dist=[inf]*n
negative=[False]*n
shortest_path(0)
find_negative_loops()
print(-1) if negative[-1] else print(max(-dist[-1],0))
| 22 | 26 | 501 | 680 | n, m, p = list(map(int, input().split()))
E = [list(map(int, input().split())) for i in range(m)]
INF = float("inf")
dist = [INF] * n
dist[0] = 0
prev = 0
# 閉路の長さの最大はnなので2*n回ループさせれば閉路検出ができる
for i in range(2 * n):
for fr, to, cost in E:
fr, to = fr - 1, to - 1
cost *= -1
cost += p
if dist[fr] != INF and dist[to] > dist[fr] + cost:
dist[to] = dist[fr] + cost
if i >= n:
dist[to] = -float("inf")
if i == n - 1:
prev = dist[n - 1]
if prev == dist[n - 1]:
print((max(-dist[n - 1], 0)))
else:
print((-1))
| def shortest_path(s):
dist[s] = 0
for _ in range(n):
for fr, to, cost in edge:
if dist[fr] != inf and dist[to] > dist[fr] + cost:
dist[to] = dist[fr] + cost
def find_negative_loops():
for _ in range(n):
for fr, to, cost in edge:
if dist[fr] != inf and dist[to] > dist[fr] + cost:
dist[to] = dist[fr] + cost
negative[to] = True
if negative[fr]:
negative[to] = True
n, m, p = map(int, input().split())
edge = []
for i in range(m):
a, b, c = map(int, input().split())
edge.append([a - 1, b - 1, -c + p])
inf = float("inf")
dist = [inf] * n
negative = [False] * n
shortest_path(0)
find_negative_loops()
print(-1) if negative[-1] else print(max(-dist[-1], 0))
| false | 15.384615 | [
"-n, m, p = list(map(int, input().split()))",
"-E = [list(map(int, input().split())) for i in range(m)]",
"-INF = float(\"inf\")",
"-dist = [INF] * n",
"-dist[0] = 0",
"-prev = 0",
"-# 閉路の長さの最大はnなので2*n回ループさせれば閉路検出ができる",
"-for i in range(2 * n):",
"- for fr, to, cost in E:",
"- fr, to = fr - 1, to - 1",
"- cost *= -1",
"- cost += p",
"- if dist[fr] != INF and dist[to] > dist[fr] + cost:",
"- dist[to] = dist[fr] + cost",
"- if i >= n:",
"- dist[to] = -float(\"inf\")",
"- if i == n - 1:",
"- prev = dist[n - 1]",
"-if prev == dist[n - 1]:",
"- print((max(-dist[n - 1], 0)))",
"-else:",
"- print((-1))",
"+def shortest_path(s):",
"+ dist[s] = 0",
"+ for _ in range(n):",
"+ for fr, to, cost in edge:",
"+ if dist[fr] != inf and dist[to] > dist[fr] + cost:",
"+ dist[to] = dist[fr] + cost",
"+",
"+",
"+def find_negative_loops():",
"+ for _ in range(n):",
"+ for fr, to, cost in edge:",
"+ if dist[fr] != inf and dist[to] > dist[fr] + cost:",
"+ dist[to] = dist[fr] + cost",
"+ negative[to] = True",
"+ if negative[fr]:",
"+ negative[to] = True",
"+",
"+",
"+n, m, p = map(int, input().split())",
"+edge = []",
"+for i in range(m):",
"+ a, b, c = map(int, input().split())",
"+ edge.append([a - 1, b - 1, -c + p])",
"+inf = float(\"inf\")",
"+dist = [inf] * n",
"+negative = [False] * n",
"+shortest_path(0)",
"+find_negative_loops()",
"+print(-1) if negative[-1] else print(max(-dist[-1], 0))"
] | false | 0.080882 | 0.090904 | 0.889758 | [
"s902114507",
"s027970646"
] |
u935558307 | p03476 | python | s784382269 | s878732948 | 1,031 | 425 | 52,260 | 80,228 | Accepted | Accepted | 58.78 | """
10**5以下の各数に対して、その数字以下の2017に似た数の個数をカウントしておく。
"""
prime = [1]*(10**5+1)
prime[0] = 0
prime[1] = 1
count = [0,0]
for i in range(2,10**5+1):
count.append(count[-1])
if prime[i]:
for j in range(i*i,10**5+1,i):
prime[j] = 0
if i>2 and prime[(i+1)//2]==1:
count[-1] += 1
Q = int(eval(input()))
for _ in range(Q):
l,r = list(map(int,input().split()))
print((count[r]-count[l-1])) | prime = [1]*(100001)
prime[0] = 0
prime[1] = 0
for i in range(2,100001):
if prime[i]:
for j in range(i*i,100001,i):
prime[j] = 0
for i in range(100000,-1,-1):
if prime[i]:
if prime[(i+1)//2] != 1:
prime[i] = 0
from itertools import accumulate
accum = list(accumulate(prime))
Q = int(eval(input()))
for _ in range(Q):
l,r = list(map(int,input().split()))
print((accum[r]-accum[l-1]))
| 19 | 20 | 436 | 447 | """
10**5以下の各数に対して、その数字以下の2017に似た数の個数をカウントしておく。
"""
prime = [1] * (10**5 + 1)
prime[0] = 0
prime[1] = 1
count = [0, 0]
for i in range(2, 10**5 + 1):
count.append(count[-1])
if prime[i]:
for j in range(i * i, 10**5 + 1, i):
prime[j] = 0
if i > 2 and prime[(i + 1) // 2] == 1:
count[-1] += 1
Q = int(eval(input()))
for _ in range(Q):
l, r = list(map(int, input().split()))
print((count[r] - count[l - 1]))
| prime = [1] * (100001)
prime[0] = 0
prime[1] = 0
for i in range(2, 100001):
if prime[i]:
for j in range(i * i, 100001, i):
prime[j] = 0
for i in range(100000, -1, -1):
if prime[i]:
if prime[(i + 1) // 2] != 1:
prime[i] = 0
from itertools import accumulate
accum = list(accumulate(prime))
Q = int(eval(input()))
for _ in range(Q):
l, r = list(map(int, input().split()))
print((accum[r] - accum[l - 1]))
| false | 5 | [
"-\"\"\"",
"-10**5以下の各数に対して、その数字以下の2017に似た数の個数をカウントしておく。",
"-\"\"\"",
"-prime = [1] * (10**5 + 1)",
"+prime = [1] * (100001)",
"-prime[1] = 1",
"-count = [0, 0]",
"-for i in range(2, 10**5 + 1):",
"- count.append(count[-1])",
"+prime[1] = 0",
"+for i in range(2, 100001):",
"- for j in range(i * i, 10**5 + 1, i):",
"+ for j in range(i * i, 100001, i):",
"- if i > 2 and prime[(i + 1) // 2] == 1:",
"- count[-1] += 1",
"+for i in range(100000, -1, -1):",
"+ if prime[i]:",
"+ if prime[(i + 1) // 2] != 1:",
"+ prime[i] = 0",
"+from itertools import accumulate",
"+",
"+accum = list(accumulate(prime))",
"- print((count[r] - count[l - 1]))",
"+ print((accum[r] - accum[l - 1]))"
] | false | 0.139486 | 0.081047 | 1.721046 | [
"s784382269",
"s878732948"
] |
u266272131 | p03599 | python | s008829184 | s119688233 | 86 | 78 | 3,188 | 3,188 | Accepted | Accepted | 9.3 | A, B, C, D, E, F = list(map(int, input().split()))
x = set()
y = set()
for i in range(F // (100 * A) + 1):
for j in range((F - 100 * A * i) // (100 * B) + 1):
if i + j == 0:
continue
x.add(A * i * 100 + B * j * 100)
for i in range(F // C + 1):
for j in range((F - C * i) // D + 1):
y.add(C * i + D * j)
ret_w = 1
ret_s = -1
for w in x:
for s in y:
if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
ret_s = s
ret_w = w + s
print((ret_w, ret_s)) |
A,B,C,D,E,F = list(map(int, input().split()))
#x is a list which represents for the volumn of water
x = set()
#y is a list which represents for the volumn of sugar
y = set()
for i in range(F//C+1):
for j in range((F-C*i)//D+1):
#if i + j == 0:
#continue
y.add( i * C + j * D)
for i in range(F//(100 * A)+1):
for j in range((F-100*A*i)//(100*B)+1):
if i + j == 0:
continue
x.add(i * A * 100 + j * B * 100)
#print(x)
#print(y)
ans_sweetwater = 1
ans_sugar = -1
#ans_density = -1
#density = E/(100+E)
#print("density: ",density)
for m in x:
for n in y:
#tmp_density = n/(m+n)
if m + n <= F and m*E/100 >= n and ans_sugar/ans_sweetwater <= n/(m+n):
ans_sweetwater = m + n
ans_sugar = n
#ans_density = tmp_density
print((ans_sweetwater,ans_sugar))
| 25 | 35 | 570 | 901 | A, B, C, D, E, F = list(map(int, input().split()))
x = set()
y = set()
for i in range(F // (100 * A) + 1):
for j in range((F - 100 * A * i) // (100 * B) + 1):
if i + j == 0:
continue
x.add(A * i * 100 + B * j * 100)
for i in range(F // C + 1):
for j in range((F - C * i) // D + 1):
y.add(C * i + D * j)
ret_w = 1
ret_s = -1
for w in x:
for s in y:
if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
ret_s = s
ret_w = w + s
print((ret_w, ret_s))
| A, B, C, D, E, F = list(map(int, input().split()))
# x is a list which represents for the volumn of water
x = set()
# y is a list which represents for the volumn of sugar
y = set()
for i in range(F // C + 1):
for j in range((F - C * i) // D + 1):
# if i + j == 0:
# continue
y.add(i * C + j * D)
for i in range(F // (100 * A) + 1):
for j in range((F - 100 * A * i) // (100 * B) + 1):
if i + j == 0:
continue
x.add(i * A * 100 + j * B * 100)
# print(x)
# print(y)
ans_sweetwater = 1
ans_sugar = -1
# ans_density = -1
# density = E/(100+E)
# print("density: ",density)
for m in x:
for n in y:
# tmp_density = n/(m+n)
if (
m + n <= F
and m * E / 100 >= n
and ans_sugar / ans_sweetwater <= n / (m + n)
):
ans_sweetwater = m + n
ans_sugar = n
# ans_density = tmp_density
print((ans_sweetwater, ans_sugar))
| false | 28.571429 | [
"+# x is a list which represents for the volumn of water",
"+# y is a list which represents for the volumn of sugar",
"+for i in range(F // C + 1):",
"+ for j in range((F - C * i) // D + 1):",
"+ # if i + j == 0:",
"+ # continue",
"+ y.add(i * C + j * D)",
"- x.add(A * i * 100 + B * j * 100)",
"-for i in range(F // C + 1):",
"- for j in range((F - C * i) // D + 1):",
"- y.add(C * i + D * j)",
"-ret_w = 1",
"-ret_s = -1",
"-for w in x:",
"- for s in y:",
"- if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:",
"- ret_s = s",
"- ret_w = w + s",
"-print((ret_w, ret_s))",
"+ x.add(i * A * 100 + j * B * 100)",
"+# print(x)",
"+# print(y)",
"+ans_sweetwater = 1",
"+ans_sugar = -1",
"+# ans_density = -1",
"+# density = E/(100+E)",
"+# print(\"density: \",density)",
"+for m in x:",
"+ for n in y:",
"+ # tmp_density = n/(m+n)",
"+ if (",
"+ m + n <= F",
"+ and m * E / 100 >= n",
"+ and ans_sugar / ans_sweetwater <= n / (m + n)",
"+ ):",
"+ ans_sweetwater = m + n",
"+ ans_sugar = n",
"+ # ans_density = tmp_density",
"+print((ans_sweetwater, ans_sugar))"
] | false | 0.066438 | 0.008414 | 7.89588 | [
"s008829184",
"s119688233"
] |
u729133443 | p02783 | python | s819650185 | s271289451 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | h,a=list(map(int,input().split()))
print((0--h//a)) | print((-eval(input().replace(' ','//-')))) | 2 | 1 | 44 | 40 | h, a = list(map(int, input().split()))
print((0 - -h // a))
| print((-eval(input().replace(" ", "//-"))))
| false | 50 | [
"-h, a = list(map(int, input().split()))",
"-print((0 - -h // a))",
"+print((-eval(input().replace(\" \", \"//-\"))))"
] | false | 0.053733 | 0.054112 | 0.992996 | [
"s819650185",
"s271289451"
] |
u576917603 | p03487 | python | s996915119 | s949768329 | 160 | 80 | 18,552 | 18,132 | Accepted | Accepted | 50 | n=int(eval(input()))
a=sorted(list(map(int,input().split())))
b=set()
ans=0
d={}
cnt=0
for i in range(n):
if i!=0 and a[i]!=a[i-1]:
d[a[i-1]]=cnt
cnt=0
cnt+=1
if i==n-1:
x=a.count(a[i])
d[a[i]]=x
for i in list(d.keys()):
if d[i]>=i:
ans+=d[i]-i
else:
ans+=d[i]
print(ans) | n=int(eval(input()))
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
ans=0
for x,y in list(c.items()):
if x<=y:
ans+=y-x
else:
ans+=y
print(ans) | 20 | 11 | 346 | 196 | n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = set()
ans = 0
d = {}
cnt = 0
for i in range(n):
if i != 0 and a[i] != a[i - 1]:
d[a[i - 1]] = cnt
cnt = 0
cnt += 1
if i == n - 1:
x = a.count(a[i])
d[a[i]] = x
for i in list(d.keys()):
if d[i] >= i:
ans += d[i] - i
else:
ans += d[i]
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
ans = 0
for x, y in list(c.items()):
if x <= y:
ans += y - x
else:
ans += y
print(ans)
| false | 45 | [
"-a = sorted(list(map(int, input().split())))",
"-b = set()",
"+a = list(map(int, input().split()))",
"+from collections import Counter",
"+",
"+c = Counter(a)",
"-d = {}",
"-cnt = 0",
"-for i in range(n):",
"- if i != 0 and a[i] != a[i - 1]:",
"- d[a[i - 1]] = cnt",
"- cnt = 0",
"- cnt += 1",
"- if i == n - 1:",
"- x = a.count(a[i])",
"- d[a[i]] = x",
"-for i in list(d.keys()):",
"- if d[i] >= i:",
"- ans += d[i] - i",
"+for x, y in list(c.items()):",
"+ if x <= y:",
"+ ans += y - x",
"- ans += d[i]",
"+ ans += y"
] | false | 0.038503 | 0.073452 | 0.524194 | [
"s996915119",
"s949768329"
] |
u602702913 | p02399 | python | s993487761 | s674222763 | 40 | 20 | 7,684 | 5,608 | Accepted | Accepted | 50 | a,b=list(map(int,input().split()))
d=a//b
r=a%b
f=round(a/b,6)
print((d,r,f)) | a,b=list(map(int,input().split()))
d=a//b
r=a%b
f=a/b
print((d,r,"{0:.9f}".format(f)))
| 7 | 8 | 77 | 89 | a, b = list(map(int, input().split()))
d = a // b
r = a % b
f = round(a / b, 6)
print((d, r, f))
| a, b = list(map(int, input().split()))
d = a // b
r = a % b
f = a / b
print((d, r, "{0:.9f}".format(f)))
| false | 12.5 | [
"-f = round(a / b, 6)",
"-print((d, r, f))",
"+f = a / b",
"+print((d, r, \"{0:.9f}\".format(f)))"
] | false | 0.088593 | 0.128355 | 0.690219 | [
"s993487761",
"s674222763"
] |
u942435175 | p02843 | python | s512764107 | s006798857 | 218 | 17 | 10,904 | 2,940 | Accepted | Accepted | 92.2 | X = int(eval(input()))
C = 1000000
output = []
for c in range(C):
if (c*100) <= X <= (c*105):
output.append(1)
else:
output.append(0)
if max(output):
print("1")
else:
print("0") | def one_int():
return int(eval(input()))
N=one_int()
num=int(N/100)
amari = N % 100
if num*5 < amari:
print((0))
else:
print((1)) | 13 | 10 | 212 | 142 | X = int(eval(input()))
C = 1000000
output = []
for c in range(C):
if (c * 100) <= X <= (c * 105):
output.append(1)
else:
output.append(0)
if max(output):
print("1")
else:
print("0")
| def one_int():
return int(eval(input()))
N = one_int()
num = int(N / 100)
amari = N % 100
if num * 5 < amari:
print((0))
else:
print((1))
| false | 23.076923 | [
"-X = int(eval(input()))",
"-C = 1000000",
"-output = []",
"-for c in range(C):",
"- if (c * 100) <= X <= (c * 105):",
"- output.append(1)",
"- else:",
"- output.append(0)",
"-if max(output):",
"- print(\"1\")",
"+def one_int():",
"+ return int(eval(input()))",
"+",
"+",
"+N = one_int()",
"+num = int(N / 100)",
"+amari = N % 100",
"+if num * 5 < amari:",
"+ print((0))",
"- print(\"0\")",
"+ print((1))"
] | false | 0.289927 | 0.076465 | 3.791622 | [
"s512764107",
"s006798857"
] |
u382907940 | p02862 | python | s769533072 | s204385964 | 1,331 | 879 | 121,880 | 82,200 | Accepted | Accepted | 33.96 | #lにa回、rにb回進む
x,y = list(map(int,input().split()))
#x = a +2b
#y = 2a+b
#x+y = 3a+3b
#a+b = (x+y)/3
#b=x-a+b
b = x-(x+y)/3
a = (x-2*b)
ans = 0
#print("a:{} b:{}".format(a,b))
if a<0 or b<0 or b-int(b)>0.00001 or a-int(a)>0.00001:
print(ans)
exit()
MAX = 1000000;
MOD = 1000000007;
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
#テーブルを作る前処理
def COMinit():
fac[0],fac[1] = 1,1
finv[0],finv[1] = 1,1
inv[1] = 1
for i in range(2,MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
#二項係数計算
def COM(n,k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMinit()
print((COM(int(a+b),int(a)))) | #lにa回、rにb回進む
x,y = list(map(int,input().split()))
#x = a +2b
#y = 2a+b
#x+y = 3a+3b
#a+b = (x+y)/3
#b=x-a+b
b = x-(x+y)/3
a = (x-2*b)
ans = 0
#print("a:{} b:{}".format(a,b))
if a<0 or b<0 or b-int(b)>0.00001 or a-int(a)>0.00001:
print(ans)
exit()
MAX = int(a+b)+1
MOD = 1000000007
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
#テーブルを作る前処理
def COMinit():
fac[0],fac[1] = 1,1
finv[0],finv[1] = 1,1
inv[1] = 1
for i in range(2,MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
#二項係数計算
def COM(n,k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMinit()
print((COM(int(a+b),int(a)))) | 42 | 42 | 841 | 837 | # lにa回、rにb回進む
x, y = list(map(int, input().split()))
# x = a +2b
# y = 2a+b
# x+y = 3a+3b
# a+b = (x+y)/3
# b=x-a+b
b = x - (x + y) / 3
a = x - 2 * b
ans = 0
# print("a:{} b:{}".format(a,b))
if a < 0 or b < 0 or b - int(b) > 0.00001 or a - int(a) > 0.00001:
print(ans)
exit()
MAX = 1000000
MOD = 1000000007
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
# テーブルを作る前処理
def COMinit():
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
# 二項係数計算
def COM(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMinit()
print((COM(int(a + b), int(a))))
| # lにa回、rにb回進む
x, y = list(map(int, input().split()))
# x = a +2b
# y = 2a+b
# x+y = 3a+3b
# a+b = (x+y)/3
# b=x-a+b
b = x - (x + y) / 3
a = x - 2 * b
ans = 0
# print("a:{} b:{}".format(a,b))
if a < 0 or b < 0 or b - int(b) > 0.00001 or a - int(a) > 0.00001:
print(ans)
exit()
MAX = int(a + b) + 1
MOD = 1000000007
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
# テーブルを作る前処理
def COMinit():
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
# 二項係数計算
def COM(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMinit()
print((COM(int(a + b), int(a))))
| false | 0 | [
"-MAX = 1000000",
"+MAX = int(a + b) + 1"
] | false | 1.903124 | 0.476725 | 3.992076 | [
"s769533072",
"s204385964"
] |
u670180528 | p02839 | python | s271720323 | s173334375 | 68 | 55 | 15,220 | 3,956 | Accepted | Accepted | 19.12 | import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [[0] * w for _ in range(h)]
poss[0][0] |= 1 << 6400 + g[0][0]
poss[0][0] |= 1 << 6400 - g[0][0]
for i in range(h):
for j in range(w - 1):
poss[i][j + 1] |= poss[i][j] << g[i][j + 1]
poss[i][j + 1] |= poss[i][j] >> g[i][j + 1]
if i != h - 1:
for j in range(w):
poss[i + 1][j] |= poss[i][j] << g[i + 1][j]
poss[i + 1][j] |= poss[i][j] >> g[i + 1][j]
res = poss[-1][-1]
for i in range(6400):
if res & (1 << 6400 + i) or res & (1 << 6400 - i):
print(i)
exit()
| import sys
input = sys.stdin.readline
def main():
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [0] * w
poss[0] |= 1 << 6400 + g[0][0]
poss[0] |= 1 << 6400 - g[0][0]
for i in range(h):
for j in range(w):
if j < w - 1:
d = g[i][j + 1]
poss[j + 1] |= poss[j] << d
poss[j + 1] |= poss[j] >> d
if i < h - 1:
d = g[i + 1][j]
poss[j] = poss[j] << d | poss[j] >> d
res = poss[-1]
for i in range(6400):
if res & (1 << 6400 + i) or res & (1 << 6400 - i):
print(i)
exit()
if __name__ == "__main__":
main() | 23 | 28 | 754 | 736 | import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [[0] * w for _ in range(h)]
poss[0][0] |= 1 << 6400 + g[0][0]
poss[0][0] |= 1 << 6400 - g[0][0]
for i in range(h):
for j in range(w - 1):
poss[i][j + 1] |= poss[i][j] << g[i][j + 1]
poss[i][j + 1] |= poss[i][j] >> g[i][j + 1]
if i != h - 1:
for j in range(w):
poss[i + 1][j] |= poss[i][j] << g[i + 1][j]
poss[i + 1][j] |= poss[i][j] >> g[i + 1][j]
res = poss[-1][-1]
for i in range(6400):
if res & (1 << 6400 + i) or res & (1 << 6400 - i):
print(i)
exit()
| import sys
input = sys.stdin.readline
def main():
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [0] * w
poss[0] |= 1 << 6400 + g[0][0]
poss[0] |= 1 << 6400 - g[0][0]
for i in range(h):
for j in range(w):
if j < w - 1:
d = g[i][j + 1]
poss[j + 1] |= poss[j] << d
poss[j + 1] |= poss[j] >> d
if i < h - 1:
d = g[i + 1][j]
poss[j] = poss[j] << d | poss[j] >> d
res = poss[-1]
for i in range(6400):
if res & (1 << 6400 + i) or res & (1 << 6400 - i):
print(i)
exit()
if __name__ == "__main__":
main()
| false | 17.857143 | [
"-input = sys.stdin.buffer.readline",
"-h, w = list(map(int, input().split()))",
"-a = [list(map(int, input().split())) for _ in range(h)]",
"-b = [list(map(int, input().split())) for _ in range(h)]",
"-g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]",
"-poss = [[0] * w for _ in range(h)]",
"-poss[0][0] |= 1 << 6400 + g[0][0]",
"-poss[0][0] |= 1 << 6400 - g[0][0]",
"-for i in range(h):",
"- for j in range(w - 1):",
"- poss[i][j + 1] |= poss[i][j] << g[i][j + 1]",
"- poss[i][j + 1] |= poss[i][j] >> g[i][j + 1]",
"- if i != h - 1:",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ h, w = list(map(int, input().split()))",
"+ a = [list(map(int, input().split())) for _ in range(h)]",
"+ b = [list(map(int, input().split())) for _ in range(h)]",
"+ g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]",
"+ poss = [0] * w",
"+ poss[0] |= 1 << 6400 + g[0][0]",
"+ poss[0] |= 1 << 6400 - g[0][0]",
"+ for i in range(h):",
"- poss[i + 1][j] |= poss[i][j] << g[i + 1][j]",
"- poss[i + 1][j] |= poss[i][j] >> g[i + 1][j]",
"-res = poss[-1][-1]",
"-for i in range(6400):",
"- if res & (1 << 6400 + i) or res & (1 << 6400 - i):",
"- print(i)",
"- exit()",
"+ if j < w - 1:",
"+ d = g[i][j + 1]",
"+ poss[j + 1] |= poss[j] << d",
"+ poss[j + 1] |= poss[j] >> d",
"+ if i < h - 1:",
"+ d = g[i + 1][j]",
"+ poss[j] = poss[j] << d | poss[j] >> d",
"+ res = poss[-1]",
"+ for i in range(6400):",
"+ if res & (1 << 6400 + i) or res & (1 << 6400 - i):",
"+ print(i)",
"+ exit()",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.048248 | 0.048458 | 0.995668 | [
"s271720323",
"s173334375"
] |
u781758937 | p02779 | python | s324867594 | s174064830 | 233 | 195 | 34,112 | 25,172 | Accepted | Accepted | 16.31 | import numpy as np
N = int(eval(input()))
S = np.array([int(i) for i in input().split()])
if len(np.unique(S))==len(S):
print("YES")
else:
print("NO")
| N = int(eval(input()))
S = [int(i) for i in input().split()]
S.sort()
flg = 0
for i in range(1,N):
if S[i] == S[i-1]:
flg = 1
if flg == 1:
print("NO")
else:
print("YES") | 9 | 13 | 159 | 193 | import numpy as np
N = int(eval(input()))
S = np.array([int(i) for i in input().split()])
if len(np.unique(S)) == len(S):
print("YES")
else:
print("NO")
| N = int(eval(input()))
S = [int(i) for i in input().split()]
S.sort()
flg = 0
for i in range(1, N):
if S[i] == S[i - 1]:
flg = 1
if flg == 1:
print("NO")
else:
print("YES")
| false | 30.769231 | [
"-import numpy as np",
"-",
"-S = np.array([int(i) for i in input().split()])",
"-if len(np.unique(S)) == len(S):",
"+S = [int(i) for i in input().split()]",
"+S.sort()",
"+flg = 0",
"+for i in range(1, N):",
"+ if S[i] == S[i - 1]:",
"+ flg = 1",
"+if flg == 1:",
"+ print(\"NO\")",
"+else:",
"-else:",
"- print(\"NO\")"
] | false | 0.200168 | 0.035136 | 5.697015 | [
"s324867594",
"s174064830"
] |
u006425112 | p02706 | python | s487128654 | s855111305 | 109 | 22 | 27,452 | 10,032 | Accepted | Accepted | 79.82 | import numpy as np
import math
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
a = sum(A)
if n < a:
print((-1))
else:
print((n - a)) | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
homework = sum(A)
print((n - homework if n - homework >= 0 else -1))
| 12 | 5 | 171 | 142 | import numpy as np
import math
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
a = sum(A)
if n < a:
print((-1))
else:
print((n - a))
| n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
homework = sum(A)
print((n - homework if n - homework >= 0 else -1))
| false | 58.333333 | [
"-import numpy as np",
"-import math",
"-",
"-a = sum(A)",
"-if n < a:",
"- print((-1))",
"-else:",
"- print((n - a))",
"+homework = sum(A)",
"+print((n - homework if n - homework >= 0 else -1))"
] | false | 0.006685 | 0.040906 | 0.163421 | [
"s487128654",
"s855111305"
] |
u983918956 | p03007 | python | s296450044 | s564529015 | 295 | 265 | 20,892 | 21,144 | Accepted | Accepted | 10.17 | from collections import deque
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
ans_list = []
p = deque()
n = deque()
# 最大にプラス、最小にマイナスを割り当てる
p.append(A[-1])
n.append(A[0])
# 正ならプラスを負ならマイナスを割り当てる
for a in A[1:-1]:
if a >= 0:
p.append(a)
elif a < 0:
n.append(a)
# プラスが1つになるまで消す
while len(p) != 1:
x = n.pop()
y = p.pop()
n.append(x-y)
ans_list.append((x, y))
# マイナスがなくなるまで消す
while len(n) != 0:
x = p.pop()
y = n.pop()
p.append(x-y)
ans_list.append((x,y))
# 残ったものが最大値
M = p[0]
print(M)
for x, y in ans_list:
print((x, y)) | N = int(eval(input()))
A = sorted(list(map(int,input().split())))
ans_list = []
p = []
n = []
# 最大にプラス、最小にマイナスを割り当てる
p.append(A[-1])
n.append(A[0])
# 正ならプラスを負ならマイナスを割り当てる
for a in A[1:-1]:
if a >= 0:
p.append(a)
elif a < 0:
n.append(a)
# プラスが1つになるまで消す
res = n[0]
for ep in p[1:]:
ans_list.append((res, ep))
res -= ep
n[0] = res
p = [p[0]]
# マイナスがなくなるまで消す
res = p[0]
for en in n:
ans_list.append((res, en))
res -= en
# 残ったものが最大値
M = res
print(M)
for x, y in ans_list:
print((x, y)) | 39 | 37 | 631 | 558 | from collections import deque
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
ans_list = []
p = deque()
n = deque()
# 最大にプラス、最小にマイナスを割り当てる
p.append(A[-1])
n.append(A[0])
# 正ならプラスを負ならマイナスを割り当てる
for a in A[1:-1]:
if a >= 0:
p.append(a)
elif a < 0:
n.append(a)
# プラスが1つになるまで消す
while len(p) != 1:
x = n.pop()
y = p.pop()
n.append(x - y)
ans_list.append((x, y))
# マイナスがなくなるまで消す
while len(n) != 0:
x = p.pop()
y = n.pop()
p.append(x - y)
ans_list.append((x, y))
# 残ったものが最大値
M = p[0]
print(M)
for x, y in ans_list:
print((x, y))
| N = int(eval(input()))
A = sorted(list(map(int, input().split())))
ans_list = []
p = []
n = []
# 最大にプラス、最小にマイナスを割り当てる
p.append(A[-1])
n.append(A[0])
# 正ならプラスを負ならマイナスを割り当てる
for a in A[1:-1]:
if a >= 0:
p.append(a)
elif a < 0:
n.append(a)
# プラスが1つになるまで消す
res = n[0]
for ep in p[1:]:
ans_list.append((res, ep))
res -= ep
n[0] = res
p = [p[0]]
# マイナスがなくなるまで消す
res = p[0]
for en in n:
ans_list.append((res, en))
res -= en
# 残ったものが最大値
M = res
print(M)
for x, y in ans_list:
print((x, y))
| false | 5.128205 | [
"-from collections import deque",
"-",
"-p = deque()",
"-n = deque()",
"+p = []",
"+n = []",
"-while len(p) != 1:",
"- x = n.pop()",
"- y = p.pop()",
"- n.append(x - y)",
"- ans_list.append((x, y))",
"+res = n[0]",
"+for ep in p[1:]:",
"+ ans_list.append((res, ep))",
"+ res -= ep",
"+n[0] = res",
"+p = [p[0]]",
"-while len(n) != 0:",
"- x = p.pop()",
"- y = n.pop()",
"- p.append(x - y)",
"- ans_list.append((x, y))",
"+res = p[0]",
"+for en in n:",
"+ ans_list.append((res, en))",
"+ res -= en",
"-M = p[0]",
"+M = res"
] | false | 0.036849 | 0.082557 | 0.446346 | [
"s296450044",
"s564529015"
] |
u392319141 | p04006 | python | s033941471 | s838605297 | 1,611 | 776 | 73,948 | 3,188 | Accepted | Accepted | 51.83 | from collections import deque
class SlideMin:
"""
スライド最小値\n
各区間[ai, ai+leng]の最小値を取得する:O(n)\n
self.que = [(i1, v1), (i2, v2), ..., (ik, vk)]\n
i1 < ... < ik and v1 < ... < vk
"""
def __init__(self, leng):
self.que = deque([])
self.leng = leng
def top(self):
return self.que[0]
def getQue(self):
return self.que
def update(self, index, value):
while self.que:
if self.que[-1][1] >= value:
self.que.pop()
else:
break
self.que.append((index, value))
if self.que[0][0] == index - self.leng:
self.que.popleft()
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
def sol(n):
# n個前までの最小値
B = A + A
que = SlideMin(n + 1)
ret = [10**18] * N
for i, a in enumerate(B):
que.update(i, a)
ret[i % N] = min(ret[i % N], que.top()[1])
return sum(ret) + n * X
ans = sum(A)
for i in range(N):
ans = min(ans, sol(i))
print(ans)
| N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
B = A[:]
ans = sum(A)
for x in range(1, N + 1):
for i in range(N)[::-1]:
if B[i] > A[i - x]:
B[i] = A[i - x]
ans = min(ans, sum(B) + x * X)
print(ans)
| 48 | 11 | 1,089 | 259 | from collections import deque
class SlideMin:
"""
スライド最小値\n
各区間[ai, ai+leng]の最小値を取得する:O(n)\n
self.que = [(i1, v1), (i2, v2), ..., (ik, vk)]\n
i1 < ... < ik and v1 < ... < vk
"""
def __init__(self, leng):
self.que = deque([])
self.leng = leng
def top(self):
return self.que[0]
def getQue(self):
return self.que
def update(self, index, value):
while self.que:
if self.que[-1][1] >= value:
self.que.pop()
else:
break
self.que.append((index, value))
if self.que[0][0] == index - self.leng:
self.que.popleft()
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
def sol(n):
# n個前までの最小値
B = A + A
que = SlideMin(n + 1)
ret = [10**18] * N
for i, a in enumerate(B):
que.update(i, a)
ret[i % N] = min(ret[i % N], que.top()[1])
return sum(ret) + n * X
ans = sum(A)
for i in range(N):
ans = min(ans, sol(i))
print(ans)
| N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
B = A[:]
ans = sum(A)
for x in range(1, N + 1):
for i in range(N)[::-1]:
if B[i] > A[i - x]:
B[i] = A[i - x]
ans = min(ans, sum(B) + x * X)
print(ans)
| false | 77.083333 | [
"-from collections import deque",
"-",
"-",
"-class SlideMin:",
"- \"\"\"",
"- スライド最小値\\n",
"- 各区間[ai, ai+leng]の最小値を取得する:O(n)\\n",
"- self.que = [(i1, v1), (i2, v2), ..., (ik, vk)]\\n",
"- i1 < ... < ik and v1 < ... < vk",
"- \"\"\"",
"-",
"- def __init__(self, leng):",
"- self.que = deque([])",
"- self.leng = leng",
"-",
"- def top(self):",
"- return self.que[0]",
"-",
"- def getQue(self):",
"- return self.que",
"-",
"- def update(self, index, value):",
"- while self.que:",
"- if self.que[-1][1] >= value:",
"- self.que.pop()",
"- else:",
"- break",
"- self.que.append((index, value))",
"- if self.que[0][0] == index - self.leng:",
"- self.que.popleft()",
"-",
"-",
"-",
"-",
"-def sol(n):",
"- # n個前までの最小値",
"- B = A + A",
"- que = SlideMin(n + 1)",
"- ret = [10**18] * N",
"- for i, a in enumerate(B):",
"- que.update(i, a)",
"- ret[i % N] = min(ret[i % N], que.top()[1])",
"- return sum(ret) + n * X",
"-",
"-",
"+B = A[:]",
"-for i in range(N):",
"- ans = min(ans, sol(i))",
"+for x in range(1, N + 1):",
"+ for i in range(N)[::-1]:",
"+ if B[i] > A[i - x]:",
"+ B[i] = A[i - x]",
"+ ans = min(ans, sum(B) + x * X)"
] | false | 0.035052 | 0.041913 | 0.836297 | [
"s033941471",
"s838605297"
] |
u281610856 | p02971 | python | s323672482 | s517353869 | 569 | 477 | 13,316 | 15,604 | Accepted | Accepted | 16.17 | n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
max_id = A.index(max(A))
A = sorted(A, reverse=True)
for i in range(n):
if i == max_id:
# 最大値が取り除かれるので2番目に大きい数値を出力
print((A[1]))
else:
# 最大値が残っているので,最大値を出力
print((A[0])) | n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
maxA = max(A)
maxIdx = A.index(maxA)
for i in range(n):
if i != maxIdx:
print(maxA)
else:
print((max(A[:i] + A[i + 1:]))) | 11 | 9 | 269 | 193 | n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
max_id = A.index(max(A))
A = sorted(A, reverse=True)
for i in range(n):
if i == max_id:
# 最大値が取り除かれるので2番目に大きい数値を出力
print((A[1]))
else:
# 最大値が残っているので,最大値を出力
print((A[0]))
| n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
maxA = max(A)
maxIdx = A.index(maxA)
for i in range(n):
if i != maxIdx:
print(maxA)
else:
print((max(A[:i] + A[i + 1 :])))
| false | 18.181818 | [
"-max_id = A.index(max(A))",
"-A = sorted(A, reverse=True)",
"+maxA = max(A)",
"+maxIdx = A.index(maxA)",
"- if i == max_id:",
"- # 最大値が取り除かれるので2番目に大きい数値を出力",
"- print((A[1]))",
"+ if i != maxIdx:",
"+ print(maxA)",
"- # 最大値が残っているので,最大値を出力",
"- print((A[0]))",
"+ print((max(A[:i] + A[i + 1 :])))"
] | false | 0.04887 | 0.044377 | 1.101242 | [
"s323672482",
"s517353869"
] |
u291278680 | p02689 | python | s413754062 | s472305856 | 243 | 224 | 88,116 | 87,524 | Accepted | Accepted | 7.82 | import sys
sys.setrecursionlimit(700000)
def s_in():
return eval(input())
def n_in():
return int(eval(input()))
def l_in():
return list(map(int, input().split()))
n,m = l_in()
h = l_in()
edges=[[] for _ in range(n)]
good=[True]*n
for _ in range(m):
a,b=l_in()
if h[a-1] > h[b-1]:
good[a-1] = good[a-1] and True
good[b-1] = False
if h[b-1] > h[a-1]:
good[b-1] = good[b-1] and True
good[a-1] = False
if h[b-1] == h[a-1]:
good[b-1] = False
good[a-1] = False
print((len(list([a for a in good if a]))))
| import sys
sys.setrecursionlimit(700000)
def s_in():
return eval(input())
def n_in():
return int(eval(input()))
def l_in():
return list(map(int, input().split()))
n,m = l_in()
h = l_in()
edges=[[] for _ in range(n)]
good=[True]*n
for _ in range(m):
a,b=l_in()
if h[a-1] > h[b-1]:
good[a-1] = good[a-1] and True
good[b-1] = False
if h[b-1] > h[a-1]:
good[b-1] = good[b-1] and True
good[a-1] = False
if h[b-1] == h[a-1]:
good[b-1] = False
good[a-1] = False
print((sum(good)))
| 32 | 32 | 610 | 583 | import sys
sys.setrecursionlimit(700000)
def s_in():
return eval(input())
def n_in():
return int(eval(input()))
def l_in():
return list(map(int, input().split()))
n, m = l_in()
h = l_in()
edges = [[] for _ in range(n)]
good = [True] * n
for _ in range(m):
a, b = l_in()
if h[a - 1] > h[b - 1]:
good[a - 1] = good[a - 1] and True
good[b - 1] = False
if h[b - 1] > h[a - 1]:
good[b - 1] = good[b - 1] and True
good[a - 1] = False
if h[b - 1] == h[a - 1]:
good[b - 1] = False
good[a - 1] = False
print((len(list([a for a in good if a]))))
| import sys
sys.setrecursionlimit(700000)
def s_in():
return eval(input())
def n_in():
return int(eval(input()))
def l_in():
return list(map(int, input().split()))
n, m = l_in()
h = l_in()
edges = [[] for _ in range(n)]
good = [True] * n
for _ in range(m):
a, b = l_in()
if h[a - 1] > h[b - 1]:
good[a - 1] = good[a - 1] and True
good[b - 1] = False
if h[b - 1] > h[a - 1]:
good[b - 1] = good[b - 1] and True
good[a - 1] = False
if h[b - 1] == h[a - 1]:
good[b - 1] = False
good[a - 1] = False
print((sum(good)))
| false | 0 | [
"-print((len(list([a for a in good if a]))))",
"+print((sum(good)))"
] | false | 0.036931 | 0.035946 | 1.027418 | [
"s413754062",
"s472305856"
] |