user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
list | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
list |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u879870653
|
p03212
|
python
|
s783088217
|
s360955782
| 81 | 54 | 3,060 | 3,316 |
Accepted
|
Accepted
| 33.33 |
from itertools import product
N = int(eval(input()))
E = [3,5,7]
ans = 0
for i in range(3, len(str(N))+1) :
L = product(E, repeat=i)
for l in L :
if (3 not in l) or (5 not in l) or (7 not in l) :
continue
number = int("".join(list(map(str,l))))
if number <= N :
ans += 1
print(ans)
|
from itertools import *
N = int(eval(input()))
A = ["3", "5", "7"]
ans = 0
length = len(str(N))
for i in range(3, length+1) :
for prod in product(A, repeat=i) :
if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0 :
continue
num = int("".join(prod))
if num > N :
break
ans += 1
print(ans)
| 14 | 22 | 346 | 415 |
from itertools import product
N = int(eval(input()))
E = [3, 5, 7]
ans = 0
for i in range(3, len(str(N)) + 1):
L = product(E, repeat=i)
for l in L:
if (3 not in l) or (5 not in l) or (7 not in l):
continue
number = int("".join(list(map(str, l))))
if number <= N:
ans += 1
print(ans)
|
from itertools import *
N = int(eval(input()))
A = ["3", "5", "7"]
ans = 0
length = len(str(N))
for i in range(3, length + 1):
for prod in product(A, repeat=i):
if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0:
continue
num = int("".join(prod))
if num > N:
break
ans += 1
print(ans)
| false | 36.363636 |
[
"-from itertools import product",
"+from itertools import *",
"-E = [3, 5, 7]",
"+A = [\"3\", \"5\", \"7\"]",
"-for i in range(3, len(str(N)) + 1):",
"- L = product(E, repeat=i)",
"- for l in L:",
"- if (3 not in l) or (5 not in l) or (7 not in l):",
"+length = len(str(N))",
"+for i in range(3, length + 1):",
"+ for prod in product(A, repeat=i):",
"+ if prod.count(\"3\") == 0 or prod.count(\"5\") == 0 or prod.count(\"7\") == 0:",
"- number = int(\"\".join(list(map(str, l))))",
"- if number <= N:",
"- ans += 1",
"+ num = int(\"\".join(prod))",
"+ if num > N:",
"+ break",
"+ ans += 1"
] | false | 0.218488 | 0.050429 | 4.332631 |
[
"s783088217",
"s360955782"
] |
u869790980
|
p02762
|
python
|
s350355731
|
s637179262
| 836 | 498 | 104,348 | 58,268 |
Accepted
|
Accepted
| 40.43 |
import collections
n,m,k = list(map(int,input().split(' ')))
friendships = [list(map(int, input().split(' '))) for _ in range(m)]
disses = [list(map(int, input().split(' '))) for _ in range(k)]
parent = [i for i in range(0, n+1)]
sizes = [1 for i in range(0, n+1)]
hd = collections.Counter()
adj = collections.defaultdict(set)
def f(parent, u):
if parent[u] != u:
parent[u] = f(parent, parent[u])
return parent[u]
for a,b in friendships:
pa,pb = f(parent, a), f(parent, b)
adj[a].add(b)
adj[b].add(a)
if pa != pb:
if sizes[pa] >= sizes[pb]:
parent[pb] = pa
sizes[pa] += sizes[pb]
else:
parent[pa] = pb
sizes[pb] += sizes[pa]
for c,d in disses:
pc,pd = f(parent, c), f(parent, d)
if d not in adj[c] and (pc == pd):
hd[c] += 1
hd[d] += 1
print(' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1) for u in range(1, n+1)]))
|
import collections
n,m,k = list(map(int,input().split(' ')))
friendships = [list(map(int, input().split(' '))) for _ in range(m)]
disses = [list(map(int, input().split(' '))) for _ in range(k)]
parent = [i for i in range(0, n+1)]
sizes = [1 for i in range(0, n+1)]
hd = [1 for i in range(0, n + 1)]
def f(parent, u):
if parent[u] != u: parent[u] = f(parent, parent[u])
return parent[u]
for a,b in friendships:
pa,pb = f(parent, a), f(parent, b)
hd[a] +=1
hd[b] +=1
if pa != pb:
if sizes[pa] >= sizes[pb]:
parent[pb] = pa
sizes[pa] += sizes[pb]
else:
parent[pa] = pb
sizes[pb] += sizes[pa]
for c,d in disses:
pc,pd = f(parent, c), f(parent, d)
if (pc == pd):
hd[c] += 1
hd[d] += 1
print(' '.join([str(sizes[f(parent,u)] - hd[u]) for u in range(1, n+1)]))
| 40 | 37 | 903 | 822 |
import collections
n, m, k = list(map(int, input().split(" ")))
friendships = [list(map(int, input().split(" "))) for _ in range(m)]
disses = [list(map(int, input().split(" "))) for _ in range(k)]
parent = [i for i in range(0, n + 1)]
sizes = [1 for i in range(0, n + 1)]
hd = collections.Counter()
adj = collections.defaultdict(set)
def f(parent, u):
if parent[u] != u:
parent[u] = f(parent, parent[u])
return parent[u]
for a, b in friendships:
pa, pb = f(parent, a), f(parent, b)
adj[a].add(b)
adj[b].add(a)
if pa != pb:
if sizes[pa] >= sizes[pb]:
parent[pb] = pa
sizes[pa] += sizes[pb]
else:
parent[pa] = pb
sizes[pb] += sizes[pa]
for c, d in disses:
pc, pd = f(parent, c), f(parent, d)
if d not in adj[c] and (pc == pd):
hd[c] += 1
hd[d] += 1
print(
" ".join(
[str(sizes[f(parent, u)] - len(adj[u]) - hd[u] - 1) for u in range(1, n + 1)]
)
)
|
import collections
n, m, k = list(map(int, input().split(" ")))
friendships = [list(map(int, input().split(" "))) for _ in range(m)]
disses = [list(map(int, input().split(" "))) for _ in range(k)]
parent = [i for i in range(0, n + 1)]
sizes = [1 for i in range(0, n + 1)]
hd = [1 for i in range(0, n + 1)]
def f(parent, u):
if parent[u] != u:
parent[u] = f(parent, parent[u])
return parent[u]
for a, b in friendships:
pa, pb = f(parent, a), f(parent, b)
hd[a] += 1
hd[b] += 1
if pa != pb:
if sizes[pa] >= sizes[pb]:
parent[pb] = pa
sizes[pa] += sizes[pb]
else:
parent[pa] = pb
sizes[pb] += sizes[pa]
for c, d in disses:
pc, pd = f(parent, c), f(parent, d)
if pc == pd:
hd[c] += 1
hd[d] += 1
print(" ".join([str(sizes[f(parent, u)] - hd[u]) for u in range(1, n + 1)]))
| false | 7.5 |
[
"-hd = collections.Counter()",
"-adj = collections.defaultdict(set)",
"+hd = [1 for i in range(0, n + 1)]",
"- adj[a].add(b)",
"- adj[b].add(a)",
"+ hd[a] += 1",
"+ hd[b] += 1",
"- if d not in adj[c] and (pc == pd):",
"+ if pc == pd:",
"-print(",
"- \" \".join(",
"- [str(sizes[f(parent, u)] - len(adj[u]) - hd[u] - 1) for u in range(1, n + 1)]",
"- )",
"-)",
"+print(\" \".join([str(sizes[f(parent, u)] - hd[u]) for u in range(1, n + 1)]))"
] | false | 0.037337 | 0.041213 | 0.905952 |
[
"s350355731",
"s637179262"
] |
u761320129
|
p02763
|
python
|
s412500669
|
s422982810
| 827 | 483 | 170,976 | 206,952 |
Accepted
|
Accepted
| 41.6 |
N = int(input())
S = input()
Q = int(input())
qs = [input().split() for i in range(Q)]
def ctoi(c):
return ord(c) - ord('a')
class BinaryIndexedTree:
def __init__(self,size):
self.N = size
self.bit = [0]*(size+1)
def add(self,x,w): # 0-indexed
x += 1
while x <= self.N:
self.bit[x] += w
x += (x & -x)
def _sum(self,x): # 1-indexed
ret = 0
while x > 0:
ret += self.bit[x]
x -= (x & -x)
return ret
def sum(self,l,r): # [l,r)
return self._sum(r) - self._sum(l)
def __str__(self): # for debug
arr = [self.sum(i,i+1) for i in range(self.N)]
return str(arr)
bits = [BinaryIndexedTree(N) for i in range(26)]
s = []
for i,c in enumerate(S):
bits[ctoi(c)].add(i,1)
s.append(c)
ans = []
for a,b,c in qs:
if a=='1':
i = int(b)-1
bits[ctoi(s[i])].add(i,-1)
bits[ctoi(c)].add(i,1)
s[i] = c
else:
l,r = int(b)-1,int(c)
a = 0
for i in range(26):
if bits[i].sum(l,r):
a += 1
ans.append(a)
print(*ans,sep='\n')
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
S = input().rstrip()
Q = int(eval(input()))
qs = [input().split() for i in range(Q)]
class BinaryIndexedTree:
def __init__(self,size):
self.N = size
self.bit = [0]*(size+1)
def add(self,x,w): # 0-indexed
x += 1
while x <= self.N:
self.bit[x] += w
x += (x & -x)
def _sum(self,x): # 1-indexed
ret = 0
while x > 0:
ret += self.bit[x]
x -= (x & -x)
return ret
def sum(self,l,r): # [l,r)
return self._sum(r) - self._sum(l)
def __str__(self): # for debug
arr = [self.sum(i,i+1) for i in range(self.N)]
return str(arr)
bits = [BinaryIndexedTree(N+1) for i in range(26)]
for i,c in enumerate(S):
ci = ord(c) - ord('a')
bits[ci].add(i,1)
now = list(S)
for a,b,c in qs:
if a=='1':
b = int(b)
pi = ord(now[b-1]) - ord('a')
bits[pi].add(b-1, -1)
ci = ord(c) - ord('a')
bits[ci].add(b-1, 1)
now[b-1] = c
else:
b,c = int(b),int(c)
cnt = 0
for i in range(26):
cnt += int(bits[i].sum(b-1,c) > 0)
print(cnt)
| 50 | 48 | 1,206 | 1,245 |
N = int(input())
S = input()
Q = int(input())
qs = [input().split() for i in range(Q)]
def ctoi(c):
return ord(c) - ord("a")
class BinaryIndexedTree:
def __init__(self, size):
self.N = size
self.bit = [0] * (size + 1)
def add(self, x, w): # 0-indexed
x += 1
while x <= self.N:
self.bit[x] += w
x += x & -x
def _sum(self, x): # 1-indexed
ret = 0
while x > 0:
ret += self.bit[x]
x -= x & -x
return ret
def sum(self, l, r): # [l,r)
return self._sum(r) - self._sum(l)
def __str__(self): # for debug
arr = [self.sum(i, i + 1) for i in range(self.N)]
return str(arr)
bits = [BinaryIndexedTree(N) for i in range(26)]
s = []
for i, c in enumerate(S):
bits[ctoi(c)].add(i, 1)
s.append(c)
ans = []
for a, b, c in qs:
if a == "1":
i = int(b) - 1
bits[ctoi(s[i])].add(i, -1)
bits[ctoi(c)].add(i, 1)
s[i] = c
else:
l, r = int(b) - 1, int(c)
a = 0
for i in range(26):
if bits[i].sum(l, r):
a += 1
ans.append(a)
print(*ans, sep="\n")
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
S = input().rstrip()
Q = int(eval(input()))
qs = [input().split() for i in range(Q)]
class BinaryIndexedTree:
def __init__(self, size):
self.N = size
self.bit = [0] * (size + 1)
def add(self, x, w): # 0-indexed
x += 1
while x <= self.N:
self.bit[x] += w
x += x & -x
def _sum(self, x): # 1-indexed
ret = 0
while x > 0:
ret += self.bit[x]
x -= x & -x
return ret
def sum(self, l, r): # [l,r)
return self._sum(r) - self._sum(l)
def __str__(self): # for debug
arr = [self.sum(i, i + 1) for i in range(self.N)]
return str(arr)
bits = [BinaryIndexedTree(N + 1) for i in range(26)]
for i, c in enumerate(S):
ci = ord(c) - ord("a")
bits[ci].add(i, 1)
now = list(S)
for a, b, c in qs:
if a == "1":
b = int(b)
pi = ord(now[b - 1]) - ord("a")
bits[pi].add(b - 1, -1)
ci = ord(c) - ord("a")
bits[ci].add(b - 1, 1)
now[b - 1] = c
else:
b, c = int(b), int(c)
cnt = 0
for i in range(26):
cnt += int(bits[i].sum(b - 1, c) > 0)
print(cnt)
| false | 4 |
[
"-N = int(input())",
"-S = input()",
"-Q = int(input())",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+N = int(eval(input()))",
"+S = input().rstrip()",
"+Q = int(eval(input()))",
"-",
"-",
"-def ctoi(c):",
"- return ord(c) - ord(\"a\")",
"-bits = [BinaryIndexedTree(N) for i in range(26)]",
"-s = []",
"+bits = [BinaryIndexedTree(N + 1) for i in range(26)]",
"- bits[ctoi(c)].add(i, 1)",
"- s.append(c)",
"-ans = []",
"+ ci = ord(c) - ord(\"a\")",
"+ bits[ci].add(i, 1)",
"+now = list(S)",
"- i = int(b) - 1",
"- bits[ctoi(s[i])].add(i, -1)",
"- bits[ctoi(c)].add(i, 1)",
"- s[i] = c",
"+ b = int(b)",
"+ pi = ord(now[b - 1]) - ord(\"a\")",
"+ bits[pi].add(b - 1, -1)",
"+ ci = ord(c) - ord(\"a\")",
"+ bits[ci].add(b - 1, 1)",
"+ now[b - 1] = c",
"- l, r = int(b) - 1, int(c)",
"- a = 0",
"+ b, c = int(b), int(c)",
"+ cnt = 0",
"- if bits[i].sum(l, r):",
"- a += 1",
"- ans.append(a)",
"-print(*ans, sep=\"\\n\")",
"+ cnt += int(bits[i].sum(b - 1, c) > 0)",
"+ print(cnt)"
] | false | 0.0371 | 0.036725 | 1.010213 |
[
"s412500669",
"s422982810"
] |
u252729807
|
p03774
|
python
|
s329050420
|
s318397926
| 202 | 29 | 44,420 | 9,080 |
Accepted
|
Accepted
| 85.64 |
from scipy.spatial.distance import cdist
import numpy as np
#%%
n, m = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(n)]
cp = [list(map(int, input().split())) for _ in range(m)]
#%%
# for s in st:
# print(cityblock(s, np.array(cp)))
cd = cdist(st, cp, 'cityblock')
idx = np.argmin(cd, axis=1)
for i in idx:
print((i+1))
|
# scipyなし
n, m = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(n)]
cp = [list(map(int, input().split())) for _ in range(m)]
for s in st:
mandist = float('inf')
for i, c in enumerate(cp):
d = abs(s[0] - c[0]) + abs(s[1] - c[1])
if d < mandist:
ans_check = i + 1
mandist = d
print(ans_check)
| 15 | 14 | 374 | 389 |
from scipy.spatial.distance import cdist
import numpy as np
#%%
n, m = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(n)]
cp = [list(map(int, input().split())) for _ in range(m)]
#%%
# for s in st:
# print(cityblock(s, np.array(cp)))
cd = cdist(st, cp, "cityblock")
idx = np.argmin(cd, axis=1)
for i in idx:
print((i + 1))
|
# scipyなし
n, m = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(n)]
cp = [list(map(int, input().split())) for _ in range(m)]
for s in st:
mandist = float("inf")
for i, c in enumerate(cp):
d = abs(s[0] - c[0]) + abs(s[1] - c[1])
if d < mandist:
ans_check = i + 1
mandist = d
print(ans_check)
| false | 6.666667 |
[
"-from scipy.spatial.distance import cdist",
"-import numpy as np",
"-",
"-#%%",
"+# scipyなし",
"-#%%",
"-# for s in st:",
"-# print(cityblock(s, np.array(cp)))",
"-cd = cdist(st, cp, \"cityblock\")",
"-idx = np.argmin(cd, axis=1)",
"-for i in idx:",
"- print((i + 1))",
"+for s in st:",
"+ mandist = float(\"inf\")",
"+ for i, c in enumerate(cp):",
"+ d = abs(s[0] - c[0]) + abs(s[1] - c[1])",
"+ if d < mandist:",
"+ ans_check = i + 1",
"+ mandist = d",
"+ print(ans_check)"
] | false | 0.390217 | 0.035143 | 11.103647 |
[
"s329050420",
"s318397926"
] |
u477977638
|
p02821
|
python
|
s660703820
|
s278926070
| 1,971 | 1,011 | 53,232 | 53,232 |
Accepted
|
Accepted
| 48.71 |
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
import bisect
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
def hand(x):
cnt=0
for i in range(n):
p=x-A[i]
cnt+=n-bisect.bisect_left(A,p)
return cnt
def main():
l=0
h=10**15+3
mid=(l+h)//2
while l+1<h:
mid=(l+h)//2
if hand(mid)<m:
h=mid
else:
l=mid
B=A[::-1]
for i in range(n-1):
B[i+1]+=B[i]
B=B[::-1]
ans=0
cnt=0
for i in range(n):
y=l-A[i]+1
index=bisect.bisect_left(A,y)
if n==index:
continue
else:
ans+=(n-index)*A[i]+B[index]
cnt+=(n-index)
ans+=(m-cnt)*l
print(ans)
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
import bisect
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
def hand(x):
cnt=0
for i in range(n):
p=x-A[i]
cnt+=n-bisect.bisect_left(A,p)
return cnt
def main():
l=0
h=2*10**5+1
mid=(l+h)//2
while l+1<h:
mid=(l+h)//2
if hand(mid)<m:
h=mid
else:
l=mid
B=A[::-1]
for i in range(n-1):
B[i+1]+=B[i]
B=B[::-1]
ans=0
cnt=0
for i in range(n):
y=l-A[i]+1
index=bisect.bisect_left(A,y)
if n==index:
continue
else:
ans+=(n-index)*A[i]+B[index]
cnt+=(n-index)
ans+=(m-cnt)*l
print(ans)
if __name__ == "__main__":
main()
| 60 | 60 | 842 | 843 |
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
import bisect
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
def hand(x):
cnt = 0
for i in range(n):
p = x - A[i]
cnt += n - bisect.bisect_left(A, p)
return cnt
def main():
l = 0
h = 10**15 + 3
mid = (l + h) // 2
while l + 1 < h:
mid = (l + h) // 2
if hand(mid) < m:
h = mid
else:
l = mid
B = A[::-1]
for i in range(n - 1):
B[i + 1] += B[i]
B = B[::-1]
ans = 0
cnt = 0
for i in range(n):
y = l - A[i] + 1
index = bisect.bisect_left(A, y)
if n == index:
continue
else:
ans += (n - index) * A[i] + B[index]
cnt += n - index
ans += (m - cnt) * l
print(ans)
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
import bisect
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
def hand(x):
cnt = 0
for i in range(n):
p = x - A[i]
cnt += n - bisect.bisect_left(A, p)
return cnt
def main():
l = 0
h = 2 * 10**5 + 1
mid = (l + h) // 2
while l + 1 < h:
mid = (l + h) // 2
if hand(mid) < m:
h = mid
else:
l = mid
B = A[::-1]
for i in range(n - 1):
B[i + 1] += B[i]
B = B[::-1]
ans = 0
cnt = 0
for i in range(n):
y = l - A[i] + 1
index = bisect.bisect_left(A, y)
if n == index:
continue
else:
ans += (n - index) * A[i] + B[index]
cnt += n - index
ans += (m - cnt) * l
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- h = 10**15 + 3",
"+ h = 2 * 10**5 + 1"
] | false | 0.037215 | 0.036068 | 1.031798 |
[
"s660703820",
"s278926070"
] |
u168578024
|
p03061
|
python
|
s595120584
|
s313733372
| 670 | 615 | 81,340 | 81,468 |
Accepted
|
Accepted
| 8.21 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd
class SegmentTree:
def __init__(self, N, func, I):
self.sz = N
self.func = func
self.I = I
self.seg = [I]*(N*2)
def assign(self, k, x):
self.seg[k + self.sz] = x
def build(self):
for i in range(self.sz - 1, 0, -1):
self.seg[i] = gcd(self.seg[2 * i], self.seg[2 * i + 1])
def update(self, k, x):
k += self.sz
self.seg[k] = x
while k > 1:
k //= 2
self.seg[k] = gcd(self.seg[2 * k], self.seg[2 * k + 1])
def query(self, a, b):
R = self.I
a += self.sz
b += self.sz
while a < b:
if a & 1:
R = gcd(R, self.seg[a])
a += 1
if b & 1:
b -= 1
R = gcd(self.seg[b], R)
a //= 2
b //= 2
return R
def main():
N = int(readline())
m = list(map(int,read().split()))
seg = SegmentTree(N , gcd , 0)
for i in range(N):
seg.assign(i , next(m))
seg.build()
ans = 1
for i in range(N):
ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
print(ans)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd
class SegmentTree:
def __init__(self, N, func, I):
self.sz = N
self.func = func
self.I = I
self.seg = [I]*(N*2)
def assign(self, k, x):
self.seg[k + self.sz] = x
def build(self):
for i in range(self.sz - 1, 0, -1):
self.seg[i] = gcd(self.seg[2 * i], self.seg[2 * i + 1])
def update(self, k, x):
k += self.sz
self.seg[k] = x
while k > 1:
k //= 2
self.seg[k] = gcd(self.seg[2 * k], self.seg[2 * k + 1])
def query(self, a, b):
R = self.I
a += self.sz
b += self.sz
while a < b:
if a & 1:
R = gcd(R, self.seg[a])
a += 1
if b & 1:
b -= 1
R = gcd(self.seg[b], R)
a >>= 1
b >>= 1
return R
def main():
N = int(readline())
m = list(map(int,read().split()))
seg = SegmentTree(N , gcd , 0)
for i in range(N):
seg.assign(i , next(m))
seg.build()
ans = 1
for i in range(N):
ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
print(ans)
main()
| 54 | 54 | 1,321 | 1,321 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd
class SegmentTree:
def __init__(self, N, func, I):
self.sz = N
self.func = func
self.I = I
self.seg = [I] * (N * 2)
def assign(self, k, x):
self.seg[k + self.sz] = x
def build(self):
for i in range(self.sz - 1, 0, -1):
self.seg[i] = gcd(self.seg[2 * i], self.seg[2 * i + 1])
def update(self, k, x):
k += self.sz
self.seg[k] = x
while k > 1:
k //= 2
self.seg[k] = gcd(self.seg[2 * k], self.seg[2 * k + 1])
def query(self, a, b):
R = self.I
a += self.sz
b += self.sz
while a < b:
if a & 1:
R = gcd(R, self.seg[a])
a += 1
if b & 1:
b -= 1
R = gcd(self.seg[b], R)
a //= 2
b //= 2
return R
def main():
N = int(readline())
m = list(map(int, read().split()))
seg = SegmentTree(N, gcd, 0)
for i in range(N):
seg.assign(i, next(m))
seg.build()
ans = 1
for i in range(N):
ans = max(ans, gcd(seg.query(0, i), seg.query(i + 1, N)))
print(ans)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd
class SegmentTree:
def __init__(self, N, func, I):
self.sz = N
self.func = func
self.I = I
self.seg = [I] * (N * 2)
def assign(self, k, x):
self.seg[k + self.sz] = x
def build(self):
for i in range(self.sz - 1, 0, -1):
self.seg[i] = gcd(self.seg[2 * i], self.seg[2 * i + 1])
def update(self, k, x):
k += self.sz
self.seg[k] = x
while k > 1:
k //= 2
self.seg[k] = gcd(self.seg[2 * k], self.seg[2 * k + 1])
def query(self, a, b):
R = self.I
a += self.sz
b += self.sz
while a < b:
if a & 1:
R = gcd(R, self.seg[a])
a += 1
if b & 1:
b -= 1
R = gcd(self.seg[b], R)
a >>= 1
b >>= 1
return R
def main():
N = int(readline())
m = list(map(int, read().split()))
seg = SegmentTree(N, gcd, 0)
for i in range(N):
seg.assign(i, next(m))
seg.build()
ans = 1
for i in range(N):
ans = max(ans, gcd(seg.query(0, i), seg.query(i + 1, N)))
print(ans)
main()
| false | 0 |
[
"- a //= 2",
"- b //= 2",
"+ a >>= 1",
"+ b >>= 1"
] | false | 0.108457 | 0.061114 | 1.774666 |
[
"s595120584",
"s313733372"
] |
u471797506
|
p03666
|
python
|
s848261499
|
s486868733
| 113 | 92 | 4,392 | 4,392 |
Accepted
|
Accepted
| 18.58 |
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll
def solve():
N, A, B, C, D = list(map(int, input().split()))
A, B = 0, B - A
if B < 0: B *= -1
M = N - 1
for i in range(0, N, 2):
if C*(M - i) <= B <= (D - C)*((i + 1)/2) + D*(M - i):
return True
for i in range(N):
if C*(M - i) - D*i <= B <= D*(M - i) - C*i:
return True
return False
print("YES" if solve() else "NO")
|
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll
def solve():
N, A, B, C, D = list(map(int, input().split()))
A, B = 0, B - A
if B < 0: B *= -1
M = N - 1
for i in range(N):
if C*(M - i) - D*i <= B <= D*(M - i) - C*i:
return True
return False
print("YES" if solve() else "NO")
| 21 | 17 | 519 | 398 |
# -*- coding: utf-8 -*-
import sys, copy, math, heapq, itertools as it, fractions, re, bisect, collections as coll
def solve():
N, A, B, C, D = list(map(int, input().split()))
A, B = 0, B - A
if B < 0:
B *= -1
M = N - 1
for i in range(0, N, 2):
if C * (M - i) <= B <= (D - C) * ((i + 1) / 2) + D * (M - i):
return True
for i in range(N):
if C * (M - i) - D * i <= B <= D * (M - i) - C * i:
return True
return False
print("YES" if solve() else "NO")
|
# -*- coding: utf-8 -*-
import sys, copy, math, heapq, itertools as it, fractions, re, bisect, collections as coll
def solve():
N, A, B, C, D = list(map(int, input().split()))
A, B = 0, B - A
if B < 0:
B *= -1
M = N - 1
for i in range(N):
if C * (M - i) - D * i <= B <= D * (M - i) - C * i:
return True
return False
print("YES" if solve() else "NO")
| false | 19.047619 |
[
"- for i in range(0, N, 2):",
"- if C * (M - i) <= B <= (D - C) * ((i + 1) / 2) + D * (M - i):",
"- return True"
] | false | 0.093618 | 0.090692 | 1.032261 |
[
"s848261499",
"s486868733"
] |
u371385198
|
p02713
|
python
|
s235407686
|
s341743266
| 1,313 | 1,098 | 9,188 | 9,212 |
Accepted
|
Accepted
| 16.37 |
import sys
import math
input = sys.stdin.readline
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
n = math.gcd(i, j)
for l in range(1, K + 1):
ans += math.gcd(n, l)
print(ans)
|
import sys
import math
input = sys.stdin.readline
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(i, K + 1):
n = math.gcd(i, j)
for l in range(j, K + 1):
if len(set([i, j, l])) == 1:
ans += math.gcd(n, l)
elif len(set([i, j, l])) == 2:
ans += (math.gcd(n, l) * 3)
else:
ans += (math.gcd(n, l) * 6)
print(ans)
| 14 | 19 | 252 | 452 |
import sys
import math
input = sys.stdin.readline
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
n = math.gcd(i, j)
for l in range(1, K + 1):
ans += math.gcd(n, l)
print(ans)
|
import sys
import math
input = sys.stdin.readline
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(i, K + 1):
n = math.gcd(i, j)
for l in range(j, K + 1):
if len(set([i, j, l])) == 1:
ans += math.gcd(n, l)
elif len(set([i, j, l])) == 2:
ans += math.gcd(n, l) * 3
else:
ans += math.gcd(n, l) * 6
print(ans)
| false | 26.315789 |
[
"- for j in range(1, K + 1):",
"+ for j in range(i, K + 1):",
"- for l in range(1, K + 1):",
"- ans += math.gcd(n, l)",
"+ for l in range(j, K + 1):",
"+ if len(set([i, j, l])) == 1:",
"+ ans += math.gcd(n, l)",
"+ elif len(set([i, j, l])) == 2:",
"+ ans += math.gcd(n, l) * 3",
"+ else:",
"+ ans += math.gcd(n, l) * 6"
] | false | 0.123399 | 0.101314 | 1.217987 |
[
"s235407686",
"s341743266"
] |
u285891772
|
p02585
|
python
|
s908687186
|
s928057407
| 2,918 | 2,530 | 79,980 | 98,160 |
Accepted
|
Accepted
| 13.3 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N, K = MAP()
P = LIST()
C = LIST()
check = [0]*N
score = []
i = 0
while 1:
while i < N and check[i]:
i += 1
if i == N:
break
tmp = []
while check[i] == 0:
check[i] = 1
i = P[i]-1
tmp.append(C[i])
score.append(tmp)
ans = -INF
for x in score:
x_acc = list(accumulate([0] + x*3))
n = len(x)
if x_acc[n] <= 0:
tmp_ans = 0
l = min(K, n)
else:
tmp_ans = x_acc[n]*(max(0, K//n-1))
l = min(K%n+n, K)
tmp_max = -INF
for i, j in combinations(list(range(3*n+1)), 2):
if j-i <= l:
if tmp_max < x_acc[j]-x_acc[i]:
tmp_max = x_acc[j]-x_acc[i]
tmp_ans += tmp_max
ans = max(ans, tmp_ans)
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N, K = MAP()
P = LIST()
C = LIST()
check = [0]*N
score = []
i = 0
while 1:
while i < N and check[i]:
i += 1
if i == N:
break
tmp = []
while check[i] == 0:
check[i] = 1
i = P[i]-1
tmp.append(C[i])
score.append(tmp)
ans = -INF
for x in score:
x_acc = list(accumulate([0] + x + x))
n = len(x)
tmp_max = -INF
for i, j in combinations(list(range(2*n+1)), 2):
if j-i <= min(K, n):
if tmp_max < x_acc[j]-x_acc[i]:
tmp_max = x_acc[j]-x_acc[i]
cnt = j-i
tmp_ans = -INF
if 0 >= x_acc[n]:
tmp_ans = tmp_max
else:
if cnt <= K%n:
tmp_ans = x_acc[n]*(K//n) + tmp_max
else:
tmp_max2 = 0
for i, j in combinations(list(range(2*n+1)), 2):
if j-i <= K%n:
if tmp_max2 < x_acc[j]-x_acc[i]:
tmp_max2 = x_acc[j]-x_acc[i]
tmp_ans = max(x_acc[n]*(K//n-1)+tmp_max, x_acc[n]*(K//n) + tmp_max2)
ans = max(ans, tmp_ans)
print(ans)
| 66 | 75 | 1,678 | 1,931 |
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def TUPLE():
return tuple(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
N, K = MAP()
P = LIST()
C = LIST()
check = [0] * N
score = []
i = 0
while 1:
while i < N and check[i]:
i += 1
if i == N:
break
tmp = []
while check[i] == 0:
check[i] = 1
i = P[i] - 1
tmp.append(C[i])
score.append(tmp)
ans = -INF
for x in score:
x_acc = list(accumulate([0] + x * 3))
n = len(x)
if x_acc[n] <= 0:
tmp_ans = 0
l = min(K, n)
else:
tmp_ans = x_acc[n] * (max(0, K // n - 1))
l = min(K % n + n, K)
tmp_max = -INF
for i, j in combinations(list(range(3 * n + 1)), 2):
if j - i <= l:
if tmp_max < x_acc[j] - x_acc[i]:
tmp_max = x_acc[j] - x_acc[i]
tmp_ans += tmp_max
ans = max(ans, tmp_ans)
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def TUPLE():
return tuple(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
N, K = MAP()
P = LIST()
C = LIST()
check = [0] * N
score = []
i = 0
while 1:
while i < N and check[i]:
i += 1
if i == N:
break
tmp = []
while check[i] == 0:
check[i] = 1
i = P[i] - 1
tmp.append(C[i])
score.append(tmp)
ans = -INF
for x in score:
x_acc = list(accumulate([0] + x + x))
n = len(x)
tmp_max = -INF
for i, j in combinations(list(range(2 * n + 1)), 2):
if j - i <= min(K, n):
if tmp_max < x_acc[j] - x_acc[i]:
tmp_max = x_acc[j] - x_acc[i]
cnt = j - i
tmp_ans = -INF
if 0 >= x_acc[n]:
tmp_ans = tmp_max
else:
if cnt <= K % n:
tmp_ans = x_acc[n] * (K // n) + tmp_max
else:
tmp_max2 = 0
for i, j in combinations(list(range(2 * n + 1)), 2):
if j - i <= K % n:
if tmp_max2 < x_acc[j] - x_acc[i]:
tmp_max2 = x_acc[j] - x_acc[i]
tmp_ans = max(
x_acc[n] * (K // n - 1) + tmp_max, x_acc[n] * (K // n) + tmp_max2
)
ans = max(ans, tmp_ans)
print(ans)
| false | 12 |
[
"- x_acc = list(accumulate([0] + x * 3))",
"+ x_acc = list(accumulate([0] + x + x))",
"- if x_acc[n] <= 0:",
"- tmp_ans = 0",
"- l = min(K, n)",
"- else:",
"- tmp_ans = x_acc[n] * (max(0, K // n - 1))",
"- l = min(K % n + n, K)",
"- for i, j in combinations(list(range(3 * n + 1)), 2):",
"- if j - i <= l:",
"+ for i, j in combinations(list(range(2 * n + 1)), 2):",
"+ if j - i <= min(K, n):",
"- tmp_ans += tmp_max",
"+ cnt = j - i",
"+ tmp_ans = -INF",
"+ if 0 >= x_acc[n]:",
"+ tmp_ans = tmp_max",
"+ else:",
"+ if cnt <= K % n:",
"+ tmp_ans = x_acc[n] * (K // n) + tmp_max",
"+ else:",
"+ tmp_max2 = 0",
"+ for i, j in combinations(list(range(2 * n + 1)), 2):",
"+ if j - i <= K % n:",
"+ if tmp_max2 < x_acc[j] - x_acc[i]:",
"+ tmp_max2 = x_acc[j] - x_acc[i]",
"+ tmp_ans = max(",
"+ x_acc[n] * (K // n - 1) + tmp_max, x_acc[n] * (K // n) + tmp_max2",
"+ )"
] | false | 0.196609 | 0.089313 | 2.201347 |
[
"s908687186",
"s928057407"
] |
u846150137
|
p03221
|
python
|
s614058890
|
s780995699
| 1,254 | 1,058 | 39,272 | 40,688 |
Accepted
|
Accepted
| 15.63 |
I=lambda:list(map(int,input().split()))
n,m=I()
a=[[i]+I() for i in range(m)]
a=sorted(a,key=lambda x:(x[1],x[2]))
b=[]
j0=0
p=1
for i,j,k in a:
if j!=j0:
p=1
else:
p+=1
b.append([i,j,p])
j0=j
b=sorted(b,key=lambda x:x[0])
for i,j,k in b:
print(("{:06d}{:06d}".format(j,k)))
|
I=lambda:list(map(int,input().split()))
n,m=I()
a=[[i]+I() for i in range(m)]
a=sorted(a,key=lambda x:(x[1],x[2]))
b=[]
j0=0
p=1
for i,j,k in a:
p=1 if j!=j0 else p+1
b.append([i,j,p])
j0=j
for i,j,k in sorted(b):
print(("{:06d}{:06d}".format(j,k)))
| 17 | 14 | 306 | 271 |
I = lambda: list(map(int, input().split()))
n, m = I()
a = [[i] + I() for i in range(m)]
a = sorted(a, key=lambda x: (x[1], x[2]))
b = []
j0 = 0
p = 1
for i, j, k in a:
if j != j0:
p = 1
else:
p += 1
b.append([i, j, p])
j0 = j
b = sorted(b, key=lambda x: x[0])
for i, j, k in b:
print(("{:06d}{:06d}".format(j, k)))
|
I = lambda: list(map(int, input().split()))
n, m = I()
a = [[i] + I() for i in range(m)]
a = sorted(a, key=lambda x: (x[1], x[2]))
b = []
j0 = 0
p = 1
for i, j, k in a:
p = 1 if j != j0 else p + 1
b.append([i, j, p])
j0 = j
for i, j, k in sorted(b):
print(("{:06d}{:06d}".format(j, k)))
| false | 17.647059 |
[
"- if j != j0:",
"- p = 1",
"- else:",
"- p += 1",
"+ p = 1 if j != j0 else p + 1",
"-b = sorted(b, key=lambda x: x[0])",
"-for i, j, k in b:",
"+for i, j, k in sorted(b):"
] | false | 0.074101 | 0.03995 | 1.854837 |
[
"s614058890",
"s780995699"
] |
u285891772
|
p02838
|
python
|
s756865873
|
s351028927
| 944 | 774 | 132,112 | 131,716 |
Accepted
|
Accepted
| 18.01 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
n = max(A).bit_length()
cnt = [[0, 0] for _ in range(n)]
for x in A:
x = "{:b}".format(x).zfill(n)
for i in range(n):
cnt[i][int(x[-(i+1)])] += 1
ans = 0
for i in range(n):
bit_sum = ((cnt[i][0]*cnt[i][1])%mod) * pow(2, i, mod) % mod
ans = (ans+bit_sum)%mod
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
n = max(A).bit_length()
cnt = [0]*n
for x in A:
for i, y in enumerate("{:b}".format(x).zfill(n)[::-1]):
if y == "1":
cnt[i] += 1
ans = 0
for i, c in enumerate(cnt):
bit_sum = (c*(N-c)%mod) * pow(2, i, mod) % mod
ans = (ans+bit_sum)%mod
print(ans)
| 39 | 39 | 1,100 | 1,080 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
n = max(A).bit_length()
cnt = [[0, 0] for _ in range(n)]
for x in A:
x = "{:b}".format(x).zfill(n)
for i in range(n):
cnt[i][int(x[-(i + 1)])] += 1
ans = 0
for i in range(n):
bit_sum = ((cnt[i][0] * cnt[i][1]) % mod) * pow(2, i, mod) % mod
ans = (ans + bit_sum) % mod
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
A = LIST()
n = max(A).bit_length()
cnt = [0] * n
for x in A:
for i, y in enumerate("{:b}".format(x).zfill(n)[::-1]):
if y == "1":
cnt[i] += 1
ans = 0
for i, c in enumerate(cnt):
bit_sum = (c * (N - c) % mod) * pow(2, i, mod) % mod
ans = (ans + bit_sum) % mod
print(ans)
| false | 0 |
[
"-cnt = [[0, 0] for _ in range(n)]",
"+cnt = [0] * n",
"- x = \"{:b}\".format(x).zfill(n)",
"- for i in range(n):",
"- cnt[i][int(x[-(i + 1)])] += 1",
"+ for i, y in enumerate(\"{:b}\".format(x).zfill(n)[::-1]):",
"+ if y == \"1\":",
"+ cnt[i] += 1",
"-for i in range(n):",
"- bit_sum = ((cnt[i][0] * cnt[i][1]) % mod) * pow(2, i, mod) % mod",
"+for i, c in enumerate(cnt):",
"+ bit_sum = (c * (N - c) % mod) * pow(2, i, mod) % mod"
] | false | 0.097074 | 0.036953 | 2.626958 |
[
"s756865873",
"s351028927"
] |
u729133443
|
p02688
|
python
|
s363178327
|
s662877419
| 65 | 20 | 67,076 | 9,356 |
Accepted
|
Accepted
| 69.23 |
(n,_),*t=[t.split()for t in open(0)][::2]
print((int(n)-len(set(sum(t,[])))))
|
n,_,*t=''.join([*open(0)][::2]).split()
print((int(n)-len({*t})))
| 2 | 2 | 76 | 64 |
(n, _), *t = [t.split() for t in open(0)][::2]
print((int(n) - len(set(sum(t, [])))))
|
n, _, *t = "".join([*open(0)][::2]).split()
print((int(n) - len({*t})))
| false | 0 |
[
"-(n, _), *t = [t.split() for t in open(0)][::2]",
"-print((int(n) - len(set(sum(t, [])))))",
"+n, _, *t = \"\".join([*open(0)][::2]).split()",
"+print((int(n) - len({*t})))"
] | false | 0.059837 | 0.084236 | 0.710345 |
[
"s363178327",
"s662877419"
] |
u072053884
|
p02241
|
python
|
s922503345
|
s256022027
| 580 | 20 | 7,908 | 7,924 |
Accepted
|
Accepted
| 96.55 |
n = int(eval(input()))
adj = [list(map(int, input().split())) for i in range(n)]
def mst():
T = [0]
gross_weight = 0
cnt = n - 1
while cnt:
ew = 2001
for i in range(len(T)):
for tv, tew in enumerate(adj[T[i]]):
if (tv not in T) and (tew != -1):
if tew < ew:
v, ew = tv, tew
T.append(v)
gross_weight += ew
cnt -= 1
print(gross_weight)
mst()
|
n = int(eval(input()))
adj = [list(map(int, input().split())) for i in range(n)]
def prim_mst(vn):
isVisited = [False] * vn
d = [0] + [2001] * (vn - 1)
p = [-1] * vn
while True:
mincost = 2001
for i in range(vn):
if (not isVisited[i]) and (d[i] < mincost):
mincost = d[i]
u = i
if mincost == 2001:
break
isVisited[u] = True
for v in range(vn):
if (not isVisited[v]) and (adj[u][v] != -1):
if adj[u][v] < d[v]:
d[v] = adj[u][v]
p[v] = u
print((sum(d)))
prim_mst(n)
| 22 | 32 | 490 | 680 |
n = int(eval(input()))
adj = [list(map(int, input().split())) for i in range(n)]
def mst():
T = [0]
gross_weight = 0
cnt = n - 1
while cnt:
ew = 2001
for i in range(len(T)):
for tv, tew in enumerate(adj[T[i]]):
if (tv not in T) and (tew != -1):
if tew < ew:
v, ew = tv, tew
T.append(v)
gross_weight += ew
cnt -= 1
print(gross_weight)
mst()
|
n = int(eval(input()))
adj = [list(map(int, input().split())) for i in range(n)]
def prim_mst(vn):
isVisited = [False] * vn
d = [0] + [2001] * (vn - 1)
p = [-1] * vn
while True:
mincost = 2001
for i in range(vn):
if (not isVisited[i]) and (d[i] < mincost):
mincost = d[i]
u = i
if mincost == 2001:
break
isVisited[u] = True
for v in range(vn):
if (not isVisited[v]) and (adj[u][v] != -1):
if adj[u][v] < d[v]:
d[v] = adj[u][v]
p[v] = u
print((sum(d)))
prim_mst(n)
| false | 31.25 |
[
"-def mst():",
"- T = [0]",
"- gross_weight = 0",
"- cnt = n - 1",
"- while cnt:",
"- ew = 2001",
"- for i in range(len(T)):",
"- for tv, tew in enumerate(adj[T[i]]):",
"- if (tv not in T) and (tew != -1):",
"- if tew < ew:",
"- v, ew = tv, tew",
"- T.append(v)",
"- gross_weight += ew",
"- cnt -= 1",
"- print(gross_weight)",
"+def prim_mst(vn):",
"+ isVisited = [False] * vn",
"+ d = [0] + [2001] * (vn - 1)",
"+ p = [-1] * vn",
"+ while True:",
"+ mincost = 2001",
"+ for i in range(vn):",
"+ if (not isVisited[i]) and (d[i] < mincost):",
"+ mincost = d[i]",
"+ u = i",
"+ if mincost == 2001:",
"+ break",
"+ isVisited[u] = True",
"+ for v in range(vn):",
"+ if (not isVisited[v]) and (adj[u][v] != -1):",
"+ if adj[u][v] < d[v]:",
"+ d[v] = adj[u][v]",
"+ p[v] = u",
"+ print((sum(d)))",
"-mst()",
"+prim_mst(n)"
] | false | 0.065482 | 0.038405 | 1.705035 |
[
"s922503345",
"s256022027"
] |
u074220993
|
p03643
|
python
|
s535891906
|
s257031124
| 30 | 26 | 9,016 | 9,016 |
Accepted
|
Accepted
| 13.33 |
N = eval(input())
ans = "ABC" + N
print(ans)
|
n = int(eval(input()))
print(f'ABC{n:0>3}')
| 3 | 2 | 40 | 38 |
N = eval(input())
ans = "ABC" + N
print(ans)
|
n = int(eval(input()))
print(f"ABC{n:0>3}")
| false | 33.333333 |
[
"-N = eval(input())",
"-ans = \"ABC\" + N",
"-print(ans)",
"+n = int(eval(input()))",
"+print(f\"ABC{n:0>3}\")"
] | false | 0.035547 | 0.034443 | 1.032049 |
[
"s535891906",
"s257031124"
] |
u141610915
|
p03162
|
python
|
s265933075
|
s924540917
| 717 | 372 | 79,064 | 70,620 |
Accepted
|
Accepted
| 48.12 |
N = int(eval(input()))
act = list(list(map(int, input().split())) for _ in range(N))
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(N):
dp[i + 1][0] = max(dp[i + 1][0], act[i][0] + max(dp[i][1], dp[i][2]))
dp[i + 1][1] = max(dp[i + 1][1], act[i][1] + max(dp[i][0], dp[i][2]))
dp[i + 1][2] = max(dp[i + 1][2], act[i][2] + max(dp[i][0], dp[i][1]))
print((max(dp[N])))
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
act = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = act[0][0]
dp[0][1] = act[0][1]
dp[0][2] = act[0][2]
for i in range(N - 1):
for j in range(3):
dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j]
print((max(dp[-1])))
| 8 | 12 | 389 | 362 |
N = int(eval(input()))
act = list(list(map(int, input().split())) for _ in range(N))
dp = [[0 for _ in range(3)] for _ in range(N + 1)]
for i in range(N):
dp[i + 1][0] = max(dp[i + 1][0], act[i][0] + max(dp[i][1], dp[i][2]))
dp[i + 1][1] = max(dp[i + 1][1], act[i][1] + max(dp[i][0], dp[i][2]))
dp[i + 1][2] = max(dp[i + 1][2], act[i][2] + max(dp[i][0], dp[i][1]))
print((max(dp[N])))
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
act = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]
dp[0][0] = act[0][0]
dp[0][1] = act[0][1]
dp[0][2] = act[0][2]
for i in range(N - 1):
for j in range(3):
dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j]
print((max(dp[-1])))
| false | 33.333333 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"-act = list(list(map(int, input().split())) for _ in range(N))",
"-dp = [[0 for _ in range(3)] for _ in range(N + 1)]",
"-for i in range(N):",
"- dp[i + 1][0] = max(dp[i + 1][0], act[i][0] + max(dp[i][1], dp[i][2]))",
"- dp[i + 1][1] = max(dp[i + 1][1], act[i][1] + max(dp[i][0], dp[i][2]))",
"- dp[i + 1][2] = max(dp[i + 1][2], act[i][2] + max(dp[i][0], dp[i][1]))",
"-print((max(dp[N])))",
"+act = [tuple(map(int, input().split())) for _ in range(N)]",
"+dp = [[0] * 3 for _ in range(N)]",
"+dp[0][0] = act[0][0]",
"+dp[0][1] = act[0][1]",
"+dp[0][2] = act[0][2]",
"+for i in range(N - 1):",
"+ for j in range(3):",
"+ dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + act[i + 1][j]",
"+print((max(dp[-1])))"
] | false | 0.036472 | 0.056682 | 0.643462 |
[
"s265933075",
"s924540917"
] |
u397496203
|
p03162
|
python
|
s633457408
|
s727173166
| 706 | 337 | 76,376 | 44,148 |
Accepted
|
Accepted
| 52.27 |
class Solver(object):
def __init__(self, N, happy):
self.dp = [[99999999 for _ in range(3)] for _ in range(N)]
self.N = N
self.happy = happy
def solve(self):
happy_list = self.happy
self.dp[0] = happy_list[0]
for i in range(1, self.N):
self.dp[i][0] = max(happy_list[i][0] + self.dp[i-1][1],
happy_list[i][0] + self.dp[i-1][2])
self.dp[i][1] = max(happy_list[i][1] + self.dp[i-1][0],
happy_list[i][1] + self.dp[i-1][2])
self.dp[i][2] = max(happy_list[i][2] + self.dp[i-1][0],
happy_list[i][2] + self.dp[i - 1][1])
return max(self.dp[-1])
def main():
N = int(eval(input()))
happy = [[int(i) for i in input().split()] for _ in range(N)]
solver = Solver(N, happy)
print((solver.solve()))
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
def main():
N = int(input().strip())
happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)]
dp = [[None, None, None] for _ in range(N)]
dp[0] = happy_list[0]
for i in range(1, N):
dp[i][0] = happy_list[i][0] + max(dp[i - 1][1], dp[i - 1][2])
dp[i][1] = happy_list[i][1] + max(dp[i - 1][0], dp[i - 1][2])
dp[i][2] = happy_list[i][2] + max(dp[i - 1][0], dp[i - 1][1])
return max(dp[-1])
if __name__ == "__main__":
print((main()))
| 28 | 22 | 958 | 596 |
class Solver(object):
def __init__(self, N, happy):
self.dp = [[99999999 for _ in range(3)] for _ in range(N)]
self.N = N
self.happy = happy
def solve(self):
happy_list = self.happy
self.dp[0] = happy_list[0]
for i in range(1, self.N):
self.dp[i][0] = max(
happy_list[i][0] + self.dp[i - 1][1],
happy_list[i][0] + self.dp[i - 1][2],
)
self.dp[i][1] = max(
happy_list[i][1] + self.dp[i - 1][0],
happy_list[i][1] + self.dp[i - 1][2],
)
self.dp[i][2] = max(
happy_list[i][2] + self.dp[i - 1][0],
happy_list[i][2] + self.dp[i - 1][1],
)
return max(self.dp[-1])
def main():
N = int(eval(input()))
happy = [[int(i) for i in input().split()] for _ in range(N)]
solver = Solver(N, happy)
print((solver.solve()))
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
def main():
N = int(input().strip())
happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)]
dp = [[None, None, None] for _ in range(N)]
dp[0] = happy_list[0]
for i in range(1, N):
dp[i][0] = happy_list[i][0] + max(dp[i - 1][1], dp[i - 1][2])
dp[i][1] = happy_list[i][1] + max(dp[i - 1][0], dp[i - 1][2])
dp[i][2] = happy_list[i][2] + max(dp[i - 1][0], dp[i - 1][1])
return max(dp[-1])
if __name__ == "__main__":
print((main()))
| false | 21.428571 |
[
"-class Solver(object):",
"- def __init__(self, N, happy):",
"- self.dp = [[99999999 for _ in range(3)] for _ in range(N)]",
"- self.N = N",
"- self.happy = happy",
"+import sys",
"- def solve(self):",
"- happy_list = self.happy",
"- self.dp[0] = happy_list[0]",
"- for i in range(1, self.N):",
"- self.dp[i][0] = max(",
"- happy_list[i][0] + self.dp[i - 1][1],",
"- happy_list[i][0] + self.dp[i - 1][2],",
"- )",
"- self.dp[i][1] = max(",
"- happy_list[i][1] + self.dp[i - 1][0],",
"- happy_list[i][1] + self.dp[i - 1][2],",
"- )",
"- self.dp[i][2] = max(",
"- happy_list[i][2] + self.dp[i - 1][0],",
"- happy_list[i][2] + self.dp[i - 1][1],",
"- )",
"- return max(self.dp[-1])",
"-",
"-",
"+input = sys.stdin.readline",
"+# sys.setrecursionlimit(100000)",
"- N = int(eval(input()))",
"- happy = [[int(i) for i in input().split()] for _ in range(N)]",
"- solver = Solver(N, happy)",
"- print((solver.solve()))",
"+ N = int(input().strip())",
"+ happy_list = [[int(i) for i in input().strip().split()] for _ in range(N)]",
"+ dp = [[None, None, None] for _ in range(N)]",
"+ dp[0] = happy_list[0]",
"+ for i in range(1, N):",
"+ dp[i][0] = happy_list[i][0] + max(dp[i - 1][1], dp[i - 1][2])",
"+ dp[i][1] = happy_list[i][1] + max(dp[i - 1][0], dp[i - 1][2])",
"+ dp[i][2] = happy_list[i][2] + max(dp[i - 1][0], dp[i - 1][1])",
"+ return max(dp[-1])",
"- main()",
"+ print((main()))"
] | false | 0.046837 | 0.041031 | 1.141498 |
[
"s633457408",
"s727173166"
] |
u583507988
|
p02578
|
python
|
s268522210
|
s105057068
| 132 | 115 | 32,364 | 32,136 |
Accepted
|
Accepted
| 12.88 |
n = int(eval(input()))
a = list(map(int, input().split()))
res = a[0]
ans = 0
for i in range(1, n):
if res>=a[i]:
ans += res-a[i]
else:
res = a[i]
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
res = a[0]
ans = 0
for i in range(1, n):
if res-a[i]>=0:
ans += res-a[i]
else:
res = a[i]
print(ans)
| 12 | 13 | 180 | 184 |
n = int(eval(input()))
a = list(map(int, input().split()))
res = a[0]
ans = 0
for i in range(1, n):
if res >= a[i]:
ans += res - a[i]
else:
res = a[i]
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
res = a[0]
ans = 0
for i in range(1, n):
if res - a[i] >= 0:
ans += res - a[i]
else:
res = a[i]
print(ans)
| false | 7.692308 |
[
"- if res >= a[i]:",
"+ if res - a[i] >= 0:"
] | false | 0.039404 | 0.035203 | 1.119339 |
[
"s268522210",
"s105057068"
] |
u497952650
|
p03964
|
python
|
s511078385
|
s027463966
| 1,182 | 88 | 5,076 | 5,076 |
Accepted
|
Accepted
| 92.55 |
from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(eval(input()))
takahashi,aoki = 1,1
for _ in range(N):
a,b = list(map(int,input().split()))
c = max(ceil(Decimal(takahashi)/Decimal(a)),ceil(Decimal(aoki)/Decimal(b)))
takahashi = c*a
aoki = c*b
print((takahashi+aoki))
|
from decimal import Decimal,getcontext
from math import ceil
N = int(eval(input()))
takahashi,aoki = 1,1
for _ in range(N):
a,b = list(map(int,input().split()))
c = max(ceil(takahashi/Decimal(a)),ceil(aoki/Decimal(b)))
takahashi = c*a
aoki = c*b
print((takahashi+aoki))
| 14 | 14 | 330 | 288 |
from decimal import Decimal, getcontext
from math import ceil
getcontext().prec = 1000
N = int(eval(input()))
takahashi, aoki = 1, 1
for _ in range(N):
a, b = list(map(int, input().split()))
c = max(ceil(Decimal(takahashi) / Decimal(a)), ceil(Decimal(aoki) / Decimal(b)))
takahashi = c * a
aoki = c * b
print((takahashi + aoki))
|
from decimal import Decimal, getcontext
from math import ceil
N = int(eval(input()))
takahashi, aoki = 1, 1
for _ in range(N):
a, b = list(map(int, input().split()))
c = max(ceil(takahashi / Decimal(a)), ceil(aoki / Decimal(b)))
takahashi = c * a
aoki = c * b
print((takahashi + aoki))
| false | 0 |
[
"-getcontext().prec = 1000",
"- c = max(ceil(Decimal(takahashi) / Decimal(a)), ceil(Decimal(aoki) / Decimal(b)))",
"+ c = max(ceil(takahashi / Decimal(a)), ceil(aoki / Decimal(b)))"
] | false | 0.109382 | 0.037669 | 2.903781 |
[
"s511078385",
"s027463966"
] |
u941753895
|
p03031
|
python
|
s526728328
|
s870341640
| 71 | 65 | 6,820 | 6,828 |
Accepted
|
Accepted
| 8.45 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
def main():
n,m=LI()
l2=[]
for _ in range(m):
l2.append(LI())
l3=LI()
l=[]
a=len(bin(1<<n))-3
for i in range(1<<n):
l.append(str(bin(i))[2:].zfill(a))
cnt=0
for x in l:
x=list(x)
f=True
for i in range(len(l2)):
y=l2[i]
c=0
for a in y[1:]:
c+=int(x[a-1])
# print(c,l3[i])
if c%2==l3[i]:
pass
else:
f=False
break
if f:
cnt+=1
return cnt
print((main()))
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def main():
n,m=LI()
l=[]
for _ in range(m):
a=LI()
l.append(a[1:])
l2=LI()
pattern=[]
for i in range(1<<n):
_l=[]
for j in range(n):
_l.append(1 if i&(1<<j) else 0)
pattern.append(_l)
ans=0
for x in pattern:
f=True
for i,y in enumerate(l):
on_num=0
for z in y:
on_num+=x[z-1]
if not f:
break
if f and l2[i]!=on_num%2:
f=False
break
if f:
ans+=1
return ans
# main()
print((main()))
| 50 | 52 | 804 | 1,046 |
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI():
return list(map(int, input().split()))
def I():
return int(eval(input()))
def LS():
return input().split()
def S():
return eval(input())
def main():
n, m = LI()
l2 = []
for _ in range(m):
l2.append(LI())
l3 = LI()
l = []
a = len(bin(1 << n)) - 3
for i in range(1 << n):
l.append(str(bin(i))[2:].zfill(a))
cnt = 0
for x in l:
x = list(x)
f = True
for i in range(len(l2)):
y = l2[i]
c = 0
for a in y[1:]:
c += int(x[a - 1])
# print(c,l3[i])
if c % 2 == l3[i]:
pass
else:
f = False
break
if f:
cnt += 1
return cnt
print((main()))
|
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
def main():
n, m = LI()
l = []
for _ in range(m):
a = LI()
l.append(a[1:])
l2 = LI()
pattern = []
for i in range(1 << n):
_l = []
for j in range(n):
_l.append(1 if i & (1 << j) else 0)
pattern.append(_l)
ans = 0
for x in pattern:
f = True
for i, y in enumerate(l):
on_num = 0
for z in y:
on_num += x[z - 1]
if not f:
break
if f and l2[i] != on_num % 2:
f = False
break
if f:
ans += 1
return ans
# main()
print((main()))
| false | 3.846154 |
[
"-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time",
"+import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy",
"+dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]",
"+ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]",
"- return list(map(int, input().split()))",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"+",
"+",
"+def LI_():",
"+ return [int(x) - 1 for x in sys.stdin.readline().split()]",
"- return int(eval(input()))",
"+ return int(sys.stdin.readline())",
"- return input().split()",
"+ return sys.stdin.readline().split()",
"- l2 = []",
"+ l = []",
"- l2.append(LI())",
"- l3 = LI()",
"- l = []",
"- a = len(bin(1 << n)) - 3",
"+ a = LI()",
"+ l.append(a[1:])",
"+ l2 = LI()",
"+ pattern = []",
"- l.append(str(bin(i))[2:].zfill(a))",
"- cnt = 0",
"- for x in l:",
"- x = list(x)",
"+ _l = []",
"+ for j in range(n):",
"+ _l.append(1 if i & (1 << j) else 0)",
"+ pattern.append(_l)",
"+ ans = 0",
"+ for x in pattern:",
"- for i in range(len(l2)):",
"- y = l2[i]",
"- c = 0",
"- for a in y[1:]:",
"- c += int(x[a - 1])",
"- # print(c,l3[i])",
"- if c % 2 == l3[i]:",
"- pass",
"- else:",
"+ for i, y in enumerate(l):",
"+ on_num = 0",
"+ for z in y:",
"+ on_num += x[z - 1]",
"+ if not f:",
"+ break",
"+ if f and l2[i] != on_num % 2:",
"- cnt += 1",
"- return cnt",
"+ ans += 1",
"+ return ans",
"+# main()"
] | false | 0.036242 | 0.037372 | 0.969767 |
[
"s526728328",
"s870341640"
] |
u148551245
|
p03327
|
python
|
s022945488
|
s409180104
| 178 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 90.45 |
n = int(eval(input()))
if n < 1000:
print("ABC")
else:
print("ABD")
|
n = int(eval(input()))
if n > 999:
print("ABD")
else:
print("ABC")
| 5 | 5 | 73 | 72 |
n = int(eval(input()))
if n < 1000:
print("ABC")
else:
print("ABD")
|
n = int(eval(input()))
if n > 999:
print("ABD")
else:
print("ABC")
| false | 0 |
[
"-if n < 1000:",
"+if n > 999:",
"+ print(\"ABD\")",
"+else:",
"-else:",
"- print(\"ABD\")"
] | false | 0.137623 | 0.043006 | 3.20009 |
[
"s022945488",
"s409180104"
] |
u074220993
|
p03610
|
python
|
s749599960
|
s430865604
| 46 | 26 | 9,028 | 9,152 |
Accepted
|
Accepted
| 43.48 |
s = eval(input())
i = 1
ans = ''
for x in s:
if i & 1:
ans += x
i += 1
print(ans)
|
s = eval(input())
print((s[::2]))
| 9 | 2 | 100 | 26 |
s = eval(input())
i = 1
ans = ""
for x in s:
if i & 1:
ans += x
i += 1
print(ans)
|
s = eval(input())
print((s[::2]))
| false | 77.777778 |
[
"-i = 1",
"-ans = \"\"",
"-for x in s:",
"- if i & 1:",
"- ans += x",
"- i += 1",
"-print(ans)",
"+print((s[::2]))"
] | false | 0.083383 | 0.045764 | 1.82202 |
[
"s749599960",
"s430865604"
] |
u502389123
|
p03338
|
python
|
s511739355
|
s468438988
| 20 | 18 | 3,064 | 2,940 |
Accepted
|
Accepted
| 10 |
N = int(eval(input()))
S = eval(input())
L = []
for i in range(1, N):
a = set()
b = set()
for j in S[:i]:
a.add(j)
for k in S[i:]:
b.add(k)
count = len(a & b)
L.append(count)
print((max(L)))
|
N = int(eval(input()))
S = eval(input())
cnt = 0
for i in range(N-1):
a = S[:i+1]
b = S[i+1:]
a = set(a)
b = set(b)
cnt = max(cnt, len(a & b))
print(cnt)
| 14 | 14 | 231 | 182 |
N = int(eval(input()))
S = eval(input())
L = []
for i in range(1, N):
a = set()
b = set()
for j in S[:i]:
a.add(j)
for k in S[i:]:
b.add(k)
count = len(a & b)
L.append(count)
print((max(L)))
|
N = int(eval(input()))
S = eval(input())
cnt = 0
for i in range(N - 1):
a = S[: i + 1]
b = S[i + 1 :]
a = set(a)
b = set(b)
cnt = max(cnt, len(a & b))
print(cnt)
| false | 0 |
[
"-L = []",
"-for i in range(1, N):",
"- a = set()",
"- b = set()",
"- for j in S[:i]:",
"- a.add(j)",
"- for k in S[i:]:",
"- b.add(k)",
"- count = len(a & b)",
"- L.append(count)",
"-print((max(L)))",
"+cnt = 0",
"+for i in range(N - 1):",
"+ a = S[: i + 1]",
"+ b = S[i + 1 :]",
"+ a = set(a)",
"+ b = set(b)",
"+ cnt = max(cnt, len(a & b))",
"+print(cnt)"
] | false | 0.040288 | 0.045908 | 0.877575 |
[
"s511739355",
"s468438988"
] |
u170201762
|
p03700
|
python
|
s275116761
|
s176246953
| 1,335 | 934 | 7,068 | 50,648 |
Accepted
|
Accepted
| 30.04 |
from math import ceil
N,A,B = list(map(int,input().split()))
H = [int(eval(input())) for _ in range(N)]
def attack(n):
s = 0
for h in H:
h -= B*n
if h > 0:
s += ceil(h/(A-B))
return s <= n
l = 0
r = 0
for h in H:
r = max(ceil(h/B),r)
for _ in range(30):
mid = (l+r)//2
if attack(mid):
r = mid
else:
l = mid
print(r)
|
from math import ceil
N,A,B = list(map(int,input().split()))
H = [int(eval(input())) for _ in range(N)]
def attack(n):
s = 0
for h in H:
h -= B*n
if h > 0:
s += ceil(h/(A-B))
return s <= n
l = 0
r = 0
for h in H:
r = max(ceil(h/B),r)
while l != r-1:
mid = (l+r)//2
if attack(mid):
r = mid
else:
l = mid
print(r)
| 25 | 25 | 403 | 399 |
from math import ceil
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
def attack(n):
s = 0
for h in H:
h -= B * n
if h > 0:
s += ceil(h / (A - B))
return s <= n
l = 0
r = 0
for h in H:
r = max(ceil(h / B), r)
for _ in range(30):
mid = (l + r) // 2
if attack(mid):
r = mid
else:
l = mid
print(r)
|
from math import ceil
N, A, B = list(map(int, input().split()))
H = [int(eval(input())) for _ in range(N)]
def attack(n):
s = 0
for h in H:
h -= B * n
if h > 0:
s += ceil(h / (A - B))
return s <= n
l = 0
r = 0
for h in H:
r = max(ceil(h / B), r)
while l != r - 1:
mid = (l + r) // 2
if attack(mid):
r = mid
else:
l = mid
print(r)
| false | 0 |
[
"-for _ in range(30):",
"+while l != r - 1:"
] | false | 0.04618 | 0.086971 | 0.530982 |
[
"s275116761",
"s176246953"
] |
u926412290
|
p03043
|
python
|
s021724702
|
s702883434
| 31 | 27 | 3,188 | 2,940 |
Accepted
|
Accepted
| 12.9 |
import math as m
N, K = list(map(int, input().split()))
P = 0
for i in range(1, N+1):
if i >= K:
P += (N-i+1) / N
break
else:
if m.log2(K/i).is_integer():
P += 1 / (N*2**(m.log10(K/i)/m.log10(2)))
else:
P += 1 / (N*2**int(m.log10(K/i)/m.log10(2) + 1))
print(P)
|
N, K = list(map(int, input().split()))
P = 0
for i in range(1, N+1):
if i >= K:
P += (N-i+1) / N
break
else:
n = 1
while i*n < K:
n *= 2
P += 1 / (N*n)
print(P)
| 17 | 16 | 338 | 233 |
import math as m
N, K = list(map(int, input().split()))
P = 0
for i in range(1, N + 1):
if i >= K:
P += (N - i + 1) / N
break
else:
if m.log2(K / i).is_integer():
P += 1 / (N * 2 ** (m.log10(K / i) / m.log10(2)))
else:
P += 1 / (N * 2 ** int(m.log10(K / i) / m.log10(2) + 1))
print(P)
|
N, K = list(map(int, input().split()))
P = 0
for i in range(1, N + 1):
if i >= K:
P += (N - i + 1) / N
break
else:
n = 1
while i * n < K:
n *= 2
P += 1 / (N * n)
print(P)
| false | 5.882353 |
[
"-import math as m",
"-",
"- if m.log2(K / i).is_integer():",
"- P += 1 / (N * 2 ** (m.log10(K / i) / m.log10(2)))",
"- else:",
"- P += 1 / (N * 2 ** int(m.log10(K / i) / m.log10(2) + 1))",
"+ n = 1",
"+ while i * n < K:",
"+ n *= 2",
"+ P += 1 / (N * n)"
] | false | 0.088929 | 0.046496 | 1.912602 |
[
"s021724702",
"s702883434"
] |
u133936772
|
p03208
|
python
|
s300762462
|
s937605636
| 228 | 78 | 7,852 | 20,128 |
Accepted
|
Accepted
| 65.79 |
n,k=list(map(int,input().split()))
l=sorted(int(eval(input())) for _ in [0]*n)
print((min(l[i+k-1]-l[i] for i in range(n-k+1))))
|
n,k,*l=list(map(int,open(0).read().split()))
l.sort()
print((min(l[k+i-1]-l[i] for i in range(n-k+1))))
| 3 | 3 | 116 | 97 |
n, k = list(map(int, input().split()))
l = sorted(int(eval(input())) for _ in [0] * n)
print((min(l[i + k - 1] - l[i] for i in range(n - k + 1))))
|
n, k, *l = list(map(int, open(0).read().split()))
l.sort()
print((min(l[k + i - 1] - l[i] for i in range(n - k + 1))))
| false | 0 |
[
"-n, k = list(map(int, input().split()))",
"-l = sorted(int(eval(input())) for _ in [0] * n)",
"-print((min(l[i + k - 1] - l[i] for i in range(n - k + 1))))",
"+n, k, *l = list(map(int, open(0).read().split()))",
"+l.sort()",
"+print((min(l[k + i - 1] - l[i] for i in range(n - k + 1))))"
] | false | 0.038 | 0.041487 | 0.915953 |
[
"s300762462",
"s937605636"
] |
u279493135
|
p02713
|
python
|
s600385980
|
s222641817
| 1,232 | 194 | 85,092 | 74,864 |
Accepted
|
Accepted
| 84.25 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
K = INT()
@lru_cache(maxsize=None)
def memo_gcd(a, b):
return gcd(a, b)
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
a = gcd(i, j)
for k in range(1, K+1):
ans += memo_gcd(a, k)
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
K = INT()
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
a = gcd(i, j)
for k in range(1, K+1):
ans += gcd(a, k)
print(ans)
| 32 | 28 | 994 | 921 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
K = INT()
@lru_cache(maxsize=None)
def memo_gcd(a, b):
return gcd(a, b)
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
a = gcd(i, j)
for k in range(1, K + 1):
ans += memo_gcd(a, k)
print(ans)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
K = INT()
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
a = gcd(i, j)
for k in range(1, K + 1):
ans += gcd(a, k)
print(ans)
| false | 12.5 |
[
"-",
"-",
"-@lru_cache(maxsize=None)",
"-def memo_gcd(a, b):",
"- return gcd(a, b)",
"-",
"-",
"- ans += memo_gcd(a, k)",
"+ ans += gcd(a, k)"
] | false | 0.177913 | 0.223243 | 0.796945 |
[
"s600385980",
"s222641817"
] |
u607563136
|
p02548
|
python
|
s156218736
|
s965501814
| 323 | 128 | 9,108 | 9,156 |
Accepted
|
Accepted
| 60.37 |
def main():
n = int(eval(input()))
ans = 0
cnt = 0
for i in range(1,n):
if n%i==0:
ans+=n//i-1
else:
ans+=n//i
if i**2<n:
cnt+=1
print(ans)
main()
|
def main():
n = int(eval(input()))
ans = 0
for i in range(1,n):
if n%i==0:
ans+=n//i-1
else:
ans+=n//i
print(ans)
main()
| 13 | 10 | 232 | 179 |
def main():
n = int(eval(input()))
ans = 0
cnt = 0
for i in range(1, n):
if n % i == 0:
ans += n // i - 1
else:
ans += n // i
if i**2 < n:
cnt += 1
print(ans)
main()
|
def main():
n = int(eval(input()))
ans = 0
for i in range(1, n):
if n % i == 0:
ans += n // i - 1
else:
ans += n // i
print(ans)
main()
| false | 23.076923 |
[
"- cnt = 0",
"- if i**2 < n:",
"- cnt += 1"
] | false | 0.127758 | 0.273611 | 0.466934 |
[
"s156218736",
"s965501814"
] |
u860002137
|
p03282
|
python
|
s008989296
|
s629389371
| 333 | 28 | 20,748 | 9,168 |
Accepted
|
Accepted
| 91.59 |
import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(eval(input()))
cnt = 0
ans = 1
for i, s in enumerate(S):
if s != "1":
cnt = i+1
ans = s
break
if cnt > K:
print((1))
else:
print((int(ans)))
|
s = list(map(str, input().rstrip()))
k = int(eval(input()))
ans = 1
for x in s[:k]:
if int(x) != 1:
ans = int(x)
break
print(ans)
| 17 | 9 | 259 | 152 |
import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(eval(input()))
cnt = 0
ans = 1
for i, s in enumerate(S):
if s != "1":
cnt = i + 1
ans = s
break
if cnt > K:
print((1))
else:
print((int(ans)))
|
s = list(map(str, input().rstrip()))
k = int(eval(input()))
ans = 1
for x in s[:k]:
if int(x) != 1:
ans = int(x)
break
print(ans)
| false | 47.058824 |
[
"-import numpy as np",
"-",
"-S = np.array(list(map(str, input().rstrip())))",
"-K = int(eval(input()))",
"-cnt = 0",
"+s = list(map(str, input().rstrip()))",
"+k = int(eval(input()))",
"-for i, s in enumerate(S):",
"- if s != \"1\":",
"- cnt = i + 1",
"- ans = s",
"+for x in s[:k]:",
"+ if int(x) != 1:",
"+ ans = int(x)",
"-if cnt > K:",
"- print((1))",
"-else:",
"- print((int(ans)))",
"+print(ans)"
] | false | 0.41125 | 0.05635 | 7.298142 |
[
"s008989296",
"s629389371"
] |
u497952650
|
p03448
|
python
|
s905287321
|
s421363183
| 44 | 18 | 3,064 | 3,060 |
Accepted
|
Accepted
| 59.09 |
def main():
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for i in range(A+1):
for j in range(B+1):
for h in range(C+1):
if 500*i + 100*j + 50*h == X:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
def main():
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for i in range(A+1):
for j in range(B+1):
tmp = X - 500*i - 100*j
if tmp >= 0 and tmp//50 <= C:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 17 | 17 | 349 | 341 |
def main():
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for i in range(A + 1):
for j in range(B + 1):
for h in range(C + 1):
if 500 * i + 100 * j + 50 * h == X:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
def main():
A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for i in range(A + 1):
for j in range(B + 1):
tmp = X - 500 * i - 100 * j
if tmp >= 0 and tmp // 50 <= C:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"- for h in range(C + 1):",
"- if 500 * i + 100 * j + 50 * h == X:",
"- ans += 1",
"+ tmp = X - 500 * i - 100 * j",
"+ if tmp >= 0 and tmp // 50 <= C:",
"+ ans += 1"
] | false | 0.054271 | 0.034749 | 1.561783 |
[
"s905287321",
"s421363183"
] |
u047796752
|
p03062
|
python
|
s546191888
|
s829803897
| 229 | 191 | 60,272 | 88,172 |
Accepted
|
Accepted
| 16.59 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
m = 10**18
for Ai in A:
if Ai<0:
cnt += 1
m = min(m, abs(Ai))
if cnt%2==0:
print((sum(abs(Ai) for Ai in A)))
else:
print((sum(abs(Ai) for Ai in A)-2*m))
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for Ai in A:
if Ai<0:
cnt += 1
if cnt%2==0:
print((sum(abs(Ai) for Ai in A)))
else:
A.sort(key=lambda x: abs(x))
print((-abs(A[0])+sum(abs(Ai) for Ai in A[1:])))
| 18 | 16 | 296 | 298 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
m = 10**18
for Ai in A:
if Ai < 0:
cnt += 1
m = min(m, abs(Ai))
if cnt % 2 == 0:
print((sum(abs(Ai) for Ai in A)))
else:
print((sum(abs(Ai) for Ai in A) - 2 * m))
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for Ai in A:
if Ai < 0:
cnt += 1
if cnt % 2 == 0:
print((sum(abs(Ai) for Ai in A)))
else:
A.sort(key=lambda x: abs(x))
print((-abs(A[0]) + sum(abs(Ai) for Ai in A[1:])))
| false | 11.111111 |
[
"-m = 10**18",
"- m = min(m, abs(Ai))",
"- print((sum(abs(Ai) for Ai in A) - 2 * m))",
"+ A.sort(key=lambda x: abs(x))",
"+ print((-abs(A[0]) + sum(abs(Ai) for Ai in A[1:])))"
] | false | 0.043083 | 0.037656 | 1.144132 |
[
"s546191888",
"s829803897"
] |
u977389981
|
p03773
|
python
|
s942151789
|
s731071173
| 20 | 17 | 2,940 | 3,064 |
Accepted
|
Accepted
| 15 |
a, b = list(map(int, input().split()))
print((a + b if a + b < 24 else (a + b - 24 if a + b > 24 else 0)))
|
A, B = list(map(int, input().split()))
x = A + B
print((x if x < 24 else (0 if x == 24 else x - 24)))
| 2 | 3 | 99 | 95 |
a, b = list(map(int, input().split()))
print((a + b if a + b < 24 else (a + b - 24 if a + b > 24 else 0)))
|
A, B = list(map(int, input().split()))
x = A + B
print((x if x < 24 else (0 if x == 24 else x - 24)))
| false | 33.333333 |
[
"-a, b = list(map(int, input().split()))",
"-print((a + b if a + b < 24 else (a + b - 24 if a + b > 24 else 0)))",
"+A, B = list(map(int, input().split()))",
"+x = A + B",
"+print((x if x < 24 else (0 if x == 24 else x - 24)))"
] | false | 0.038861 | 0.040236 | 0.965833 |
[
"s942151789",
"s731071173"
] |
u677121387
|
p03095
|
python
|
s879722118
|
s863353181
| 642 | 35 | 9,300 | 9,456 |
Accepted
|
Accepted
| 94.55 |
n = int(eval(input()))
s = eval(input())
mod = 1000000007
alphacnt = [0]*26
ans = 0
for c in s:
idx = ord(c)-ord("a")
alphacnt[idx] += 1
cnt = 1
for i in range(26):
if i == idx: continue
cnt = (cnt*(alphacnt[i]+1))%mod
ans = (ans+cnt)%mod
print(ans)
|
from collections import Counter
n = int(eval(input()))
s = eval(input())
mod = 1000000007
ans = 1
cnt = Counter(s)
for v in list(cnt.values()): ans = ans*(v+1)%mod
ans = (ans-1)%mod
print(ans)
| 14 | 9 | 286 | 182 |
n = int(eval(input()))
s = eval(input())
mod = 1000000007
alphacnt = [0] * 26
ans = 0
for c in s:
idx = ord(c) - ord("a")
alphacnt[idx] += 1
cnt = 1
for i in range(26):
if i == idx:
continue
cnt = (cnt * (alphacnt[i] + 1)) % mod
ans = (ans + cnt) % mod
print(ans)
|
from collections import Counter
n = int(eval(input()))
s = eval(input())
mod = 1000000007
ans = 1
cnt = Counter(s)
for v in list(cnt.values()):
ans = ans * (v + 1) % mod
ans = (ans - 1) % mod
print(ans)
| false | 35.714286 |
[
"+from collections import Counter",
"+",
"-alphacnt = [0] * 26",
"-ans = 0",
"-for c in s:",
"- idx = ord(c) - ord(\"a\")",
"- alphacnt[idx] += 1",
"- cnt = 1",
"- for i in range(26):",
"- if i == idx:",
"- continue",
"- cnt = (cnt * (alphacnt[i] + 1)) % mod",
"- ans = (ans + cnt) % mod",
"+ans = 1",
"+cnt = Counter(s)",
"+for v in list(cnt.values()):",
"+ ans = ans * (v + 1) % mod",
"+ans = (ans - 1) % mod"
] | false | 0.061918 | 0.034863 | 1.776065 |
[
"s879722118",
"s863353181"
] |
u808427016
|
p03209
|
python
|
s472438314
|
s206935261
| 20 | 18 | 3,188 | 3,064 |
Accepted
|
Accepted
| 10 |
N, X = [int(_) for _ in input().split()]
def calc(n, x, cache = {}):
#print("calc", n, x)
key = (n, x)
if key in cache:
return cache[key]
if n == 1:
if x < 2:
result = 0
elif x < 5:
result = x - 1
else:
result = 3
else:
plen = 2 * 2 ** n - 3
if x == 1:
result = 0
elif x < 2 + plen:
result = calc(n - 1, x - 1)
elif x == 2 + plen:
result = calc(n - 1, x - 1) + 1
else:
result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)
#print("calc", n, x, "=", result)
cache[key] = result
return result
result = calc(N, X)
print(result)
|
N, X = [int(_) for _ in input().split()]
def calc(n, x, cache = {}):
if n == 1:
return min(max(x - 1, 0), 3)
else:
plen = 2 * 2 ** n - 3
if x == 1:
return 0
elif x >= 4 * 2 ** n - 3:
return 2 * 2 ** n - 1
elif x < 2 + plen:
return calc(n - 1, x - 1)
elif x == 2 + plen:
return calc(n - 1, x - 1) + 1
else:
return 2 ** n + calc(n - 1, x - 2 - plen)
result = calc(N, X)
print(result)
| 32 | 21 | 753 | 529 |
N, X = [int(_) for _ in input().split()]
def calc(n, x, cache={}):
# print("calc", n, x)
key = (n, x)
if key in cache:
return cache[key]
if n == 1:
if x < 2:
result = 0
elif x < 5:
result = x - 1
else:
result = 3
else:
plen = 2 * 2**n - 3
if x == 1:
result = 0
elif x < 2 + plen:
result = calc(n - 1, x - 1)
elif x == 2 + plen:
result = calc(n - 1, x - 1) + 1
else:
result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)
# print("calc", n, x, "=", result)
cache[key] = result
return result
result = calc(N, X)
print(result)
|
N, X = [int(_) for _ in input().split()]
def calc(n, x, cache={}):
if n == 1:
return min(max(x - 1, 0), 3)
else:
plen = 2 * 2**n - 3
if x == 1:
return 0
elif x >= 4 * 2**n - 3:
return 2 * 2**n - 1
elif x < 2 + plen:
return calc(n - 1, x - 1)
elif x == 2 + plen:
return calc(n - 1, x - 1) + 1
else:
return 2**n + calc(n - 1, x - 2 - plen)
result = calc(N, X)
print(result)
| false | 34.375 |
[
"- # print(\"calc\", n, x)",
"- key = (n, x)",
"- if key in cache:",
"- return cache[key]",
"- if x < 2:",
"- result = 0",
"- elif x < 5:",
"- result = x - 1",
"- else:",
"- result = 3",
"+ return min(max(x - 1, 0), 3)",
"- result = 0",
"+ return 0",
"+ elif x >= 4 * 2**n - 3:",
"+ return 2 * 2**n - 1",
"- result = calc(n - 1, x - 1)",
"+ return calc(n - 1, x - 1)",
"- result = calc(n - 1, x - 1) + 1",
"+ return calc(n - 1, x - 1) + 1",
"- result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)",
"- # print(\"calc\", n, x, \"=\", result)",
"- cache[key] = result",
"- return result",
"+ return 2**n + calc(n - 1, x - 2 - plen)"
] | false | 0.033581 | 0.039157 | 0.857609 |
[
"s472438314",
"s206935261"
] |
u962718741
|
p03341
|
python
|
s187046059
|
s807967324
| 140 | 125 | 10,040 | 9,896 |
Accepted
|
Accepted
| 10.71 |
import collections
def main():
N = int(eval(input()))
S = eval(input())
cnt = collections.Counter(S)
E_cnt = cnt['E']
W_cnt = cnt['W']
tmp = 0
if S[0] == 'E':
E_cnt -= 1
ans = E_cnt
for i in range(1, N):
if S[i] == 'E':
E_cnt -= 1
else:
W_cnt -= 1
if S[i - 1] == 'W':
tmp += 1
ans = min(ans, tmp + E_cnt)
print(ans)
if __name__ == "__main__":
main()
|
import collections
def main():
N = int(eval(input()))
S = eval(input())
cnt = collections.Counter(S)
E_cnt = cnt['E']
tmp = 0
if S[0] == 'E':
E_cnt -= 1
ans = E_cnt
for i in range(1, N):
if S[i] == 'E':
E_cnt -= 1
if S[i - 1] == 'W':
tmp += 1
ans = min(ans, tmp + E_cnt)
print(ans)
if __name__ == "__main__":
main()
| 27 | 24 | 489 | 428 |
import collections
def main():
N = int(eval(input()))
S = eval(input())
cnt = collections.Counter(S)
E_cnt = cnt["E"]
W_cnt = cnt["W"]
tmp = 0
if S[0] == "E":
E_cnt -= 1
ans = E_cnt
for i in range(1, N):
if S[i] == "E":
E_cnt -= 1
else:
W_cnt -= 1
if S[i - 1] == "W":
tmp += 1
ans = min(ans, tmp + E_cnt)
print(ans)
if __name__ == "__main__":
main()
|
import collections
def main():
N = int(eval(input()))
S = eval(input())
cnt = collections.Counter(S)
E_cnt = cnt["E"]
tmp = 0
if S[0] == "E":
E_cnt -= 1
ans = E_cnt
for i in range(1, N):
if S[i] == "E":
E_cnt -= 1
if S[i - 1] == "W":
tmp += 1
ans = min(ans, tmp + E_cnt)
print(ans)
if __name__ == "__main__":
main()
| false | 11.111111 |
[
"- W_cnt = cnt[\"W\"]",
"- else:",
"- W_cnt -= 1"
] | false | 0.035431 | 0.07247 | 0.488914 |
[
"s187046059",
"s807967324"
] |
u905582793
|
p03133
|
python
|
s617571747
|
s311812827
| 231 | 58 | 42,588 | 3,064 |
Accepted
|
Accepted
| 74.89 |
n,m = list(map(int,input().split()))
a = [int(input().replace(" ",""),2) for i in range(n)]
mod = 998244353
cnt = 0
for j in range(m)[::-1]:
for i in range(cnt,n):
if a[i] & 1<<j:
for k in range(n):
if (i != k) and (a[k] & 1<<j):
a[k] ^= a[i]
a[i],a[cnt] = a[cnt],a[i]
cnt += 1
if cnt == 0:
print((0))
else:
ans = pow(2,n+m-2*cnt,mod)*pow(2,cnt-1,mod)*(pow(2,cnt,mod)-1)%mod
print(ans)
|
n,m=list(map(int,input().split()))
a=[int(input().replace(" ",""),2) for i in range(n)]
o=998244353
c=0
for j in range(m)[::-1]:
for i in range(c,n):
if a[i]&1<<j:
for k in range(n):
if i!=k and a[k]&1<<j:
a[k]^=a[i]
a[i],a[c]=a[c],a[i]
c+=1
p=lambda x:pow(2,x,o)
print((p(n+m-c-1)*(p(c)-1)%o))
| 17 | 14 | 441 | 320 |
n, m = list(map(int, input().split()))
a = [int(input().replace(" ", ""), 2) for i in range(n)]
mod = 998244353
cnt = 0
for j in range(m)[::-1]:
for i in range(cnt, n):
if a[i] & 1 << j:
for k in range(n):
if (i != k) and (a[k] & 1 << j):
a[k] ^= a[i]
a[i], a[cnt] = a[cnt], a[i]
cnt += 1
if cnt == 0:
print((0))
else:
ans = (
pow(2, n + m - 2 * cnt, mod)
* pow(2, cnt - 1, mod)
* (pow(2, cnt, mod) - 1)
% mod
)
print(ans)
|
n, m = list(map(int, input().split()))
a = [int(input().replace(" ", ""), 2) for i in range(n)]
o = 998244353
c = 0
for j in range(m)[::-1]:
for i in range(c, n):
if a[i] & 1 << j:
for k in range(n):
if i != k and a[k] & 1 << j:
a[k] ^= a[i]
a[i], a[c] = a[c], a[i]
c += 1
p = lambda x: pow(2, x, o)
print((p(n + m - c - 1) * (p(c) - 1) % o))
| false | 17.647059 |
[
"-mod = 998244353",
"-cnt = 0",
"+o = 998244353",
"+c = 0",
"- for i in range(cnt, n):",
"+ for i in range(c, n):",
"- if (i != k) and (a[k] & 1 << j):",
"+ if i != k and a[k] & 1 << j:",
"- a[i], a[cnt] = a[cnt], a[i]",
"- cnt += 1",
"-if cnt == 0:",
"- print((0))",
"-else:",
"- ans = (",
"- pow(2, n + m - 2 * cnt, mod)",
"- * pow(2, cnt - 1, mod)",
"- * (pow(2, cnt, mod) - 1)",
"- % mod",
"- )",
"- print(ans)",
"+ a[i], a[c] = a[c], a[i]",
"+ c += 1",
"+p = lambda x: pow(2, x, o)",
"+print((p(n + m - c - 1) * (p(c) - 1) % o))"
] | false | 0.047007 | 0.035255 | 1.333349 |
[
"s617571747",
"s311812827"
] |
u784022244
|
p03352
|
python
|
s904986684
|
s006844949
| 183 | 19 | 38,256 | 3,188 |
Accepted
|
Accepted
| 89.62 |
from math import sqrt
X=int(eval(input()))
ans=0
for i in range(1,int(sqrt(X))+1):
now=i
b=2
while i!=1 and X>=i**b:
now=i**b
b+=1
ans=max(ans, now)
print(ans)
|
X=int(eval(input()))
ans=0
for i in range(1,33):
for j in range(2,11):
now=i**j
if ans<now and now<=X:
ans=now
print(ans)
| 11 | 9 | 195 | 157 |
from math import sqrt
X = int(eval(input()))
ans = 0
for i in range(1, int(sqrt(X)) + 1):
now = i
b = 2
while i != 1 and X >= i**b:
now = i**b
b += 1
ans = max(ans, now)
print(ans)
|
X = int(eval(input()))
ans = 0
for i in range(1, 33):
for j in range(2, 11):
now = i**j
if ans < now and now <= X:
ans = now
print(ans)
| false | 18.181818 |
[
"-from math import sqrt",
"-",
"-for i in range(1, int(sqrt(X)) + 1):",
"- now = i",
"- b = 2",
"- while i != 1 and X >= i**b:",
"- now = i**b",
"- b += 1",
"- ans = max(ans, now)",
"+for i in range(1, 33):",
"+ for j in range(2, 11):",
"+ now = i**j",
"+ if ans < now and now <= X:",
"+ ans = now"
] | false | 0.041194 | 0.047081 | 0.874959 |
[
"s904986684",
"s006844949"
] |
u639104973
|
p03239
|
python
|
s242740048
|
s468347904
| 19 | 17 | 3,060 | 3,060 |
Accepted
|
Accepted
| 10.53 |
N,T=list(map(int,input().split()))
C=[list(map(int, input().split())) for _ in range(N)]
e=[]
for i in C:
if T>=i[1]:
e.extend([i[0]])
print(('TLE' if len(e)==0 else min(e)))
|
N,T=list(map(int,input().split()))
C=[list(map(int, input().split())) for _ in range(N)]
e=10000
for i in C:
if T>=i[1] and e>i[0]:
e=i[0]
print(('TLE' if e==10000 else e))
| 7 | 7 | 178 | 176 |
N, T = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(N)]
e = []
for i in C:
if T >= i[1]:
e.extend([i[0]])
print(("TLE" if len(e) == 0 else min(e)))
|
N, T = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(N)]
e = 10000
for i in C:
if T >= i[1] and e > i[0]:
e = i[0]
print(("TLE" if e == 10000 else e))
| false | 0 |
[
"-e = []",
"+e = 10000",
"- if T >= i[1]:",
"- e.extend([i[0]])",
"-print((\"TLE\" if len(e) == 0 else min(e)))",
"+ if T >= i[1] and e > i[0]:",
"+ e = i[0]",
"+print((\"TLE\" if e == 10000 else e))"
] | false | 0.079856 | 0.075957 | 1.05133 |
[
"s242740048",
"s468347904"
] |
u617515020
|
p03281
|
python
|
s805368253
|
s578129718
| 31 | 26 | 9,188 | 9,344 |
Accepted
|
Accepted
| 16.13 |
from math import sqrt
N=int(eval(input()))
ans=0
for i in range(1,N+1,2):
d=[]
for j in range(1,int(sqrt(i))+1):
if i%j==0:
d.append(j)
d.append(N//j)
d=list(set(d))
if len(d)==8:
ans+=1
print(ans)
|
N=int(eval(input()))
ans=0
for i in range(1,N+1,2):
cnt=2
for j in range(3,int(i**0.5)+1,2):
if i%j==0:
cnt+=2
if cnt==8:
ans+=1
print(ans)
| 13 | 10 | 231 | 162 |
from math import sqrt
N = int(eval(input()))
ans = 0
for i in range(1, N + 1, 2):
d = []
for j in range(1, int(sqrt(i)) + 1):
if i % j == 0:
d.append(j)
d.append(N // j)
d = list(set(d))
if len(d) == 8:
ans += 1
print(ans)
|
N = int(eval(input()))
ans = 0
for i in range(1, N + 1, 2):
cnt = 2
for j in range(3, int(i**0.5) + 1, 2):
if i % j == 0:
cnt += 2
if cnt == 8:
ans += 1
print(ans)
| false | 23.076923 |
[
"-from math import sqrt",
"-",
"- d = []",
"- for j in range(1, int(sqrt(i)) + 1):",
"+ cnt = 2",
"+ for j in range(3, int(i**0.5) + 1, 2):",
"- d.append(j)",
"- d.append(N // j)",
"- d = list(set(d))",
"- if len(d) == 8:",
"+ cnt += 2",
"+ if cnt == 8:"
] | false | 0.045494 | 0.042152 | 1.079283 |
[
"s805368253",
"s578129718"
] |
u079022693
|
p02624
|
python
|
s029424021
|
s572458467
| 672 | 621 | 339,660 | 339,924 |
Accepted
|
Accepted
| 7.59 |
from sys import stdin
import numpy as np
def main():
#入力
readline=stdin.readline
n=int(readline())
ans=0
n_min=np.arange(1,n+1,dtype=np.int64)
n_max=n//n_min*n_min
kousu=n//n_min
ans=(kousu*(n_min+n_max)//2).sum()
print(ans)
if __name__=="__main__":
main()
|
import numpy as np
n=int(eval(input()))
n_min=np.arange(1,n+1,dtype=np.int64)
n_max=n//n_min*n_min
kousu=n//n_min
print(((kousu*(n_min+n_max)//2).sum()))
| 17 | 8 | 315 | 154 |
from sys import stdin
import numpy as np
def main():
# 入力
readline = stdin.readline
n = int(readline())
ans = 0
n_min = np.arange(1, n + 1, dtype=np.int64)
n_max = n // n_min * n_min
kousu = n // n_min
ans = (kousu * (n_min + n_max) // 2).sum()
print(ans)
if __name__ == "__main__":
main()
|
import numpy as np
n = int(eval(input()))
n_min = np.arange(1, n + 1, dtype=np.int64)
n_max = n // n_min * n_min
kousu = n // n_min
print(((kousu * (n_min + n_max) // 2).sum()))
| false | 52.941176 |
[
"-from sys import stdin",
"-",
"-def main():",
"- # 入力",
"- readline = stdin.readline",
"- n = int(readline())",
"- ans = 0",
"- n_min = np.arange(1, n + 1, dtype=np.int64)",
"- n_max = n // n_min * n_min",
"- kousu = n // n_min",
"- ans = (kousu * (n_min + n_max) // 2).sum()",
"- print(ans)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n = int(eval(input()))",
"+n_min = np.arange(1, n + 1, dtype=np.int64)",
"+n_max = n // n_min * n_min",
"+kousu = n // n_min",
"+print(((kousu * (n_min + n_max) // 2).sum()))"
] | false | 0.40589 | 0.589422 | 0.688623 |
[
"s029424021",
"s572458467"
] |
u284854859
|
p02575
|
python
|
s572213825
|
s059851277
| 1,765 | 1,149 | 130,432 | 126,820 |
Accepted
|
Accepted
| 34.9 |
import sys,heapq
input = sys.stdin.buffer.readline
def main():
h,w = list(map(int,input().split()))
#dp[i] : iの時の最小右移動回数
dp = [0]*(w+1)
#解候補
res = [0]*w
#解候補から消されるもの
anti = []
#Ai = {1:dp[i]はvalid 0:invalid}
#A1 ... AnのBIT(1-indexed)
BIT = [0]*(w+1)
#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
res_sum = 0
while idx > 0:
res_sum += BIT[idx]
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def BIT_update(idx,x):
while idx <= w:
BIT[idx] += x
idx += idx&(-idx)
for i in range(1,w+1):
BIT_update(i,1)
for i in range(1,h+1):
a,b = list(map(int,input().split()))
#a-1,b+1の値を計算
x = a-1
if x != 0 and x != w+1 and dp[x] == -1:
#x以下のvalidな個数
k = BIT_query(x-1)
#k番目のvalidな位置okからXに行く
if k != 0:
ok = x
ng = 0
while ok-ng > 1:
mid = (ok+ng)//2
if BIT_query(mid) == k:
ok = mid
else:
ng = mid
#xをvalidにする
dp[x] = dp[ok] + (x-ok)
BIT_update(x,1)
heapq.heappush(res,dp[x])
x = b+1
if x != 0 and x != w+1 and dp[x] == -1:
#x以下のvalidな個数
k = BIT_query(x-1)
#k番目のvalidな位置okからXに行く
if k != 0:
ok = x
ng = 0
while ok-ng > 1:
mid = (ok+ng)//2
if BIT_query(mid) == k:
ok = mid
else:
ng = mid
#xをvalidにする
dp[x] = dp[ok] + (x-ok)
BIT_update(x,1)
heapq.heappush(res,dp[x])
k = BIT_query(a-1)+1
while True:
ng = a-1
ok = b+1
while ok-ng > 1:
mid = (ok+ng)//2
if BIT_query(mid) >= k:
ok = mid
else:
ng = mid
if ok > b or dp[ok] == -1:
break
heapq.heappush(anti,dp[ok])
dp[ok] = -1
BIT_update(ok,-1)
while anti and res and anti[0] == res[0]:
heapq.heappop(anti)
heapq.heappop(res)
if res:
print((res[0]+i))
else:
print((-1))
if __name__ == '__main__':
main()
|
import sys,heapq
input = sys.stdin.buffer.readline
def main():
h,w = list(map(int,input().split()))
class BIT:
def __init__(self,len_A):
self.N = len_A + 10
self.bit = [0]*(len_A+10)
# sum(A0 ~ Ai)
# O(log N)
def query(self,i):
res = 0
idx = i+1
while idx:
res += self.bit[idx]
idx -= idx&(-idx)
return res
# Ai += x
# O(log N)
def update(self,i,x):
idx = i+1
while idx < self.N:
self.bit[idx] += x
idx += idx&(-idx)
# min_i satisfying {sum(A0 ~ Ai) >= w} (Ai >= 0)
# O(log N)
def lower_left(self,w):
if (w < 0):
return -1
x = 0
k = 1<<(self.N.bit_length()-1)
while k > 0:
if x+k < self.N and self.bit[x+k] < w:
w -= self.bit[x+k]
x += k
k //= 2
return x
#dp[i] : iの時の最小右移動回数
dp = [0]*(w+1)
#解候補
res = [0]*w
#解候補から消されるもの
anti = []
C = BIT(w)
for i in range(1,w+1):
C.update(i,1)
for i in range(1,h+1):
a,b = list(map(int,input().split()))
#a-1,b+1の値を計算
x = a-1
if x != 0 and x != w+1 and dp[x] == -1:
#x以下のvalidな個数
k = C.query(x-1)
#k番目のvalidな位置okからXに行く
if k != 0:
ok = C.lower_left(k)
#xをvalidにする
dp[x] = dp[ok] + (x-ok)
C.update(x,1)
heapq.heappush(res,dp[x])
x = b+1
if x != 0 and x != w+1 and dp[x] == -1:
#x以下のvalidな個数
k = C.query(x-1)
#k番目のvalidな位置okからXに行く
if k != 0:
ok = C.lower_left(k)
#xをvalidにする
dp[x] = dp[ok] + (x-ok)
C.update(x,1)
heapq.heappush(res,dp[x])
k = C.query(a-1)+1
while True:
ok = C.lower_left(k)
if ok > b or dp[ok] == -1:
break
heapq.heappush(anti,dp[ok])
dp[ok] = -1
C.update(ok,-1)
while anti and res and anti[0] == res[0]:
heapq.heappop(anti)
heapq.heappop(res)
if res:
print((res[0]+i))
else:
print((-1))
if __name__ == '__main__':
main()
| 113 | 114 | 2,710 | 2,670 |
import sys, heapq
input = sys.stdin.buffer.readline
def main():
h, w = list(map(int, input().split()))
# dp[i] : iの時の最小右移動回数
dp = [0] * (w + 1)
# 解候補
res = [0] * w
# 解候補から消されるもの
anti = []
# Ai = {1:dp[i]はvalid 0:invalid}
# A1 ... AnのBIT(1-indexed)
BIT = [0] * (w + 1)
# A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
res_sum = 0
while idx > 0:
res_sum += BIT[idx]
idx -= idx & (-idx)
return res_sum
# Ai += x O(logN)
def BIT_update(idx, x):
while idx <= w:
BIT[idx] += x
idx += idx & (-idx)
for i in range(1, w + 1):
BIT_update(i, 1)
for i in range(1, h + 1):
a, b = list(map(int, input().split()))
# a-1,b+1の値を計算
x = a - 1
if x != 0 and x != w + 1 and dp[x] == -1:
# x以下のvalidな個数
k = BIT_query(x - 1)
# k番目のvalidな位置okからXに行く
if k != 0:
ok = x
ng = 0
while ok - ng > 1:
mid = (ok + ng) // 2
if BIT_query(mid) == k:
ok = mid
else:
ng = mid
# xをvalidにする
dp[x] = dp[ok] + (x - ok)
BIT_update(x, 1)
heapq.heappush(res, dp[x])
x = b + 1
if x != 0 and x != w + 1 and dp[x] == -1:
# x以下のvalidな個数
k = BIT_query(x - 1)
# k番目のvalidな位置okからXに行く
if k != 0:
ok = x
ng = 0
while ok - ng > 1:
mid = (ok + ng) // 2
if BIT_query(mid) == k:
ok = mid
else:
ng = mid
# xをvalidにする
dp[x] = dp[ok] + (x - ok)
BIT_update(x, 1)
heapq.heappush(res, dp[x])
k = BIT_query(a - 1) + 1
while True:
ng = a - 1
ok = b + 1
while ok - ng > 1:
mid = (ok + ng) // 2
if BIT_query(mid) >= k:
ok = mid
else:
ng = mid
if ok > b or dp[ok] == -1:
break
heapq.heappush(anti, dp[ok])
dp[ok] = -1
BIT_update(ok, -1)
while anti and res and anti[0] == res[0]:
heapq.heappop(anti)
heapq.heappop(res)
if res:
print((res[0] + i))
else:
print((-1))
if __name__ == "__main__":
main()
|
import sys, heapq
input = sys.stdin.buffer.readline
def main():
h, w = list(map(int, input().split()))
class BIT:
def __init__(self, len_A):
self.N = len_A + 10
self.bit = [0] * (len_A + 10)
# sum(A0 ~ Ai)
# O(log N)
def query(self, i):
res = 0
idx = i + 1
while idx:
res += self.bit[idx]
idx -= idx & (-idx)
return res
# Ai += x
# O(log N)
def update(self, i, x):
idx = i + 1
while idx < self.N:
self.bit[idx] += x
idx += idx & (-idx)
# min_i satisfying {sum(A0 ~ Ai) >= w} (Ai >= 0)
# O(log N)
def lower_left(self, w):
if w < 0:
return -1
x = 0
k = 1 << (self.N.bit_length() - 1)
while k > 0:
if x + k < self.N and self.bit[x + k] < w:
w -= self.bit[x + k]
x += k
k //= 2
return x
# dp[i] : iの時の最小右移動回数
dp = [0] * (w + 1)
# 解候補
res = [0] * w
# 解候補から消されるもの
anti = []
C = BIT(w)
for i in range(1, w + 1):
C.update(i, 1)
for i in range(1, h + 1):
a, b = list(map(int, input().split()))
# a-1,b+1の値を計算
x = a - 1
if x != 0 and x != w + 1 and dp[x] == -1:
# x以下のvalidな個数
k = C.query(x - 1)
# k番目のvalidな位置okからXに行く
if k != 0:
ok = C.lower_left(k)
# xをvalidにする
dp[x] = dp[ok] + (x - ok)
C.update(x, 1)
heapq.heappush(res, dp[x])
x = b + 1
if x != 0 and x != w + 1 and dp[x] == -1:
# x以下のvalidな個数
k = C.query(x - 1)
# k番目のvalidな位置okからXに行く
if k != 0:
ok = C.lower_left(k)
# xをvalidにする
dp[x] = dp[ok] + (x - ok)
C.update(x, 1)
heapq.heappush(res, dp[x])
k = C.query(a - 1) + 1
while True:
ok = C.lower_left(k)
if ok > b or dp[ok] == -1:
break
heapq.heappush(anti, dp[ok])
dp[ok] = -1
C.update(ok, -1)
while anti and res and anti[0] == res[0]:
heapq.heappop(anti)
heapq.heappop(res)
if res:
print((res[0] + i))
else:
print((-1))
if __name__ == "__main__":
main()
| false | 0.877193 |
[
"+",
"+ class BIT:",
"+ def __init__(self, len_A):",
"+ self.N = len_A + 10",
"+ self.bit = [0] * (len_A + 10)",
"+",
"+ # sum(A0 ~ Ai)",
"+ # O(log N)",
"+ def query(self, i):",
"+ res = 0",
"+ idx = i + 1",
"+ while idx:",
"+ res += self.bit[idx]",
"+ idx -= idx & (-idx)",
"+ return res",
"+",
"+ # Ai += x",
"+ # O(log N)",
"+ def update(self, i, x):",
"+ idx = i + 1",
"+ while idx < self.N:",
"+ self.bit[idx] += x",
"+ idx += idx & (-idx)",
"+",
"+ # min_i satisfying {sum(A0 ~ Ai) >= w} (Ai >= 0)",
"+ # O(log N)",
"+ def lower_left(self, w):",
"+ if w < 0:",
"+ return -1",
"+ x = 0",
"+ k = 1 << (self.N.bit_length() - 1)",
"+ while k > 0:",
"+ if x + k < self.N and self.bit[x + k] < w:",
"+ w -= self.bit[x + k]",
"+ x += k",
"+ k //= 2",
"+ return x",
"+",
"- # Ai = {1:dp[i]はvalid 0:invalid}",
"- # A1 ... AnのBIT(1-indexed)",
"- BIT = [0] * (w + 1)",
"- # A1 ~ Aiまでの和 O(logN)",
"- def BIT_query(idx):",
"- res_sum = 0",
"- while idx > 0:",
"- res_sum += BIT[idx]",
"- idx -= idx & (-idx)",
"- return res_sum",
"-",
"- # Ai += x O(logN)",
"- def BIT_update(idx, x):",
"- while idx <= w:",
"- BIT[idx] += x",
"- idx += idx & (-idx)",
"-",
"+ C = BIT(w)",
"- BIT_update(i, 1)",
"+ C.update(i, 1)",
"- k = BIT_query(x - 1)",
"+ k = C.query(x - 1)",
"- ok = x",
"- ng = 0",
"- while ok - ng > 1:",
"- mid = (ok + ng) // 2",
"- if BIT_query(mid) == k:",
"- ok = mid",
"- else:",
"- ng = mid",
"+ ok = C.lower_left(k)",
"- BIT_update(x, 1)",
"+ C.update(x, 1)",
"- k = BIT_query(x - 1)",
"+ k = C.query(x - 1)",
"- ok = x",
"- ng = 0",
"- while ok - ng > 1:",
"- mid = (ok + ng) // 2",
"- if BIT_query(mid) == k:",
"- ok = mid",
"- else:",
"- ng = mid",
"+ ok = C.lower_left(k)",
"- BIT_update(x, 1)",
"+ C.update(x, 1)",
"- k = BIT_query(a - 1) + 1",
"+ k = C.query(a - 1) + 1",
"- ng = a - 1",
"- ok = b + 1",
"- while ok - ng > 1:",
"- mid = (ok + ng) // 2",
"- if BIT_query(mid) >= k:",
"- ok = mid",
"- else:",
"- ng = mid",
"+ ok = C.lower_left(k)",
"- BIT_update(ok, -1)",
"+ C.update(ok, -1)"
] | false | 0.040185 | 0.050857 | 0.79017 |
[
"s572213825",
"s059851277"
] |
u094191970
|
p03549
|
python
|
s046333310
|
s814953650
| 659 | 30 | 9,444 | 9,100 |
Accepted
|
Accepted
| 95.45 |
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
ms=1900*m+100*(n-m)
ans=0
for i in range(1,10**6):
p1=0.5**m
p2=(1-0.5**m)**(i-1)
p=p1*p2
t_ms=ms*i
ans+=p*t_ms
ans=int(ans)
q=ans%10
if q!=0:
ans+=10-q
print(ans)
|
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
ms=1900*m+100*(n-m)
ans=ms*(2**m)
print(ans)
| 22 | 10 | 330 | 185 |
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n, m = nii()
ms = 1900 * m + 100 * (n - m)
ans = 0
for i in range(1, 10**6):
p1 = 0.5**m
p2 = (1 - 0.5**m) ** (i - 1)
p = p1 * p2
t_ms = ms * i
ans += p * t_ms
ans = int(ans)
q = ans % 10
if q != 0:
ans += 10 - q
print(ans)
|
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n, m = nii()
ms = 1900 * m + 100 * (n - m)
ans = ms * (2**m)
print(ans)
| false | 54.545455 |
[
"-ans = 0",
"-for i in range(1, 10**6):",
"- p1 = 0.5**m",
"- p2 = (1 - 0.5**m) ** (i - 1)",
"- p = p1 * p2",
"- t_ms = ms * i",
"- ans += p * t_ms",
"-ans = int(ans)",
"-q = ans % 10",
"-if q != 0:",
"- ans += 10 - q",
"+ans = ms * (2**m)"
] | false | 1.24939 | 0.006605 | 189.163649 |
[
"s046333310",
"s814953650"
] |
u858523893
|
p03797
|
python
|
s580101595
|
s010838829
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
N, M = list(map(int, input().split()))
if N >= M // 2:
print((M // 2))
else :
print((N + (M - N * 2) // 4))
|
N, M = list(map(int, input().split()))
if M < 2 * N :
print((M // 2))
else :
print((N + (M - 2*N) // 4))
| 7 | 6 | 117 | 108 |
N, M = list(map(int, input().split()))
if N >= M // 2:
print((M // 2))
else:
print((N + (M - N * 2) // 4))
|
N, M = list(map(int, input().split()))
if M < 2 * N:
print((M // 2))
else:
print((N + (M - 2 * N) // 4))
| false | 14.285714 |
[
"-if N >= M // 2:",
"+if M < 2 * N:",
"- print((N + (M - N * 2) // 4))",
"+ print((N + (M - 2 * N) // 4))"
] | false | 0.084727 | 0.084636 | 1.001072 |
[
"s580101595",
"s010838829"
] |
u609061751
|
p02574
|
python
|
s899355926
|
s808466202
| 793 | 723 | 257,136 | 236,324 |
Accepted
|
Accepted
| 8.83 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
def max_gcd_pair(S):
# Assumption 1: S is the list of numbers
# Assumption 2: There are no duplicates in S
s = set(S)
m = max(S)
res = 0
i = m
while(i > 0):
a = i
cnt = 0
while (a<=m): # a maxed at max of the list
if a in s:
cnt += 1
a += i
if cnt >= 2: # we have found the result
res = i
break
i = i -1
return res
n = int(eval(input()))
a = [int(x) for x in input().split()]
from collections import Counter
c = Counter(a)
flag = 1
for i in a:
if c[i] > 1 and i != 1:
flag = 0
if flag:
if max_gcd_pair(a) <= 1:
print('pairwise coprime')
sys.exit()
import math
from functools import reduce
def gcd(*numbers):
return abs(reduce(math.gcd, numbers))
if gcd(*a) == 1:
print('setwise coprime')
sys.exit()
else:
print('not coprime')
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
n = int(eval(input()))
a = [int(x) for x in input().split()]
# 1~aの最大値までの数の最小の素因数を前処理で求める(O(max_aloglog(max_a)))
def smallest_prime_factors(a):
max_a = max(a)
smallest_prime_factors = [int(x) for x in range(max_a + 1)]
for i in range(2, max_a + 1):
if smallest_prime_factors[i] == i:
for j in range(i, max_a + 1, i):
if smallest_prime_factors[j] == j:
smallest_prime_factors[j] = i
else:
continue
return smallest_prime_factors
smallest_prime_factors = smallest_prime_factors(a)
# nを素因数分解(O(log(n)))
def prime_factorize(n):
prime_factors = []
if n == 1:
return prime_factors
while n != smallest_prime_factors[n]:
prime_factors.append(smallest_prime_factors[n])
n //= smallest_prime_factors[n]
prime_factors.append(n)
return prime_factors
prime_factors = set()
flag = 1
for i in a:
prime_factorize_i = set(prime_factorize(i))
for j in prime_factorize_i:
if j in prime_factors:
flag = 0
break
else:
prime_factors.add(j)
if flag:
print('pairwise coprime')
sys.exit()
import math
from functools import reduce
def gcd(*numbers):
return abs(reduce(math.gcd, numbers))
if gcd(*a) == 1:
print('setwise coprime')
else:
print('not coprime')
| 56 | 59 | 1,040 | 1,471 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
def max_gcd_pair(S):
# Assumption 1: S is the list of numbers
# Assumption 2: There are no duplicates in S
s = set(S)
m = max(S)
res = 0
i = m
while i > 0:
a = i
cnt = 0
while a <= m: # a maxed at max of the list
if a in s:
cnt += 1
a += i
if cnt >= 2: # we have found the result
res = i
break
i = i - 1
return res
n = int(eval(input()))
a = [int(x) for x in input().split()]
from collections import Counter
c = Counter(a)
flag = 1
for i in a:
if c[i] > 1 and i != 1:
flag = 0
if flag:
if max_gcd_pair(a) <= 1:
print("pairwise coprime")
sys.exit()
import math
from functools import reduce
def gcd(*numbers):
return abs(reduce(math.gcd, numbers))
if gcd(*a) == 1:
print("setwise coprime")
sys.exit()
else:
print("not coprime")
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
n = int(eval(input()))
a = [int(x) for x in input().split()]
# 1~aの最大値までの数の最小の素因数を前処理で求める(O(max_aloglog(max_a)))
def smallest_prime_factors(a):
max_a = max(a)
smallest_prime_factors = [int(x) for x in range(max_a + 1)]
for i in range(2, max_a + 1):
if smallest_prime_factors[i] == i:
for j in range(i, max_a + 1, i):
if smallest_prime_factors[j] == j:
smallest_prime_factors[j] = i
else:
continue
return smallest_prime_factors
smallest_prime_factors = smallest_prime_factors(a)
# nを素因数分解(O(log(n)))
def prime_factorize(n):
prime_factors = []
if n == 1:
return prime_factors
while n != smallest_prime_factors[n]:
prime_factors.append(smallest_prime_factors[n])
n //= smallest_prime_factors[n]
prime_factors.append(n)
return prime_factors
prime_factors = set()
flag = 1
for i in a:
prime_factorize_i = set(prime_factorize(i))
for j in prime_factorize_i:
if j in prime_factors:
flag = 0
break
else:
prime_factors.add(j)
if flag:
print("pairwise coprime")
sys.exit()
import math
from functools import reduce
def gcd(*numbers):
return abs(reduce(math.gcd, numbers))
if gcd(*a) == 1:
print("setwise coprime")
else:
print("not coprime")
| false | 5.084746 |
[
"+n = int(eval(input()))",
"+a = [int(x) for x in input().split()]",
"+# 1~aの最大値までの数の最小の素因数を前処理で求める(O(max_aloglog(max_a)))",
"+def smallest_prime_factors(a):",
"+ max_a = max(a)",
"+ smallest_prime_factors = [int(x) for x in range(max_a + 1)]",
"+ for i in range(2, max_a + 1):",
"+ if smallest_prime_factors[i] == i:",
"+ for j in range(i, max_a + 1, i):",
"+ if smallest_prime_factors[j] == j:",
"+ smallest_prime_factors[j] = i",
"+ else:",
"+ continue",
"+ return smallest_prime_factors",
"-def max_gcd_pair(S):",
"- # Assumption 1: S is the list of numbers",
"- # Assumption 2: There are no duplicates in S",
"- s = set(S)",
"- m = max(S)",
"- res = 0",
"- i = m",
"- while i > 0:",
"- a = i",
"- cnt = 0",
"- while a <= m: # a maxed at max of the list",
"- if a in s:",
"- cnt += 1",
"- a += i",
"- if cnt >= 2: # we have found the result",
"- res = i",
"- break",
"- i = i - 1",
"- return res",
"+smallest_prime_factors = smallest_prime_factors(a)",
"+# nを素因数分解(O(log(n)))",
"+def prime_factorize(n):",
"+ prime_factors = []",
"+ if n == 1:",
"+ return prime_factors",
"+ while n != smallest_prime_factors[n]:",
"+ prime_factors.append(smallest_prime_factors[n])",
"+ n //= smallest_prime_factors[n]",
"+ prime_factors.append(n)",
"+ return prime_factors",
"-n = int(eval(input()))",
"-a = [int(x) for x in input().split()]",
"-from collections import Counter",
"-",
"-c = Counter(a)",
"+prime_factors = set()",
"- if c[i] > 1 and i != 1:",
"- flag = 0",
"+ prime_factorize_i = set(prime_factorize(i))",
"+ for j in prime_factorize_i:",
"+ if j in prime_factors:",
"+ flag = 0",
"+ break",
"+ else:",
"+ prime_factors.add(j)",
"- if max_gcd_pair(a) <= 1:",
"- print(\"pairwise coprime\")",
"- sys.exit()",
"+ print(\"pairwise coprime\")",
"+ sys.exit()",
"- sys.exit()"
] | false | 0.038806 | 0.045822 | 0.846888 |
[
"s899355926",
"s808466202"
] |
u107077660
|
p03327
|
python
|
s570808495
|
s683121161
| 168 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.88 |
print(('AB'+'DC'[not input()[3:]]))
|
print(("AB"+"DC"[len(eval(input()))<4]))
| 1 | 1 | 34 | 32 |
print(("AB" + "DC"[not input()[3:]]))
|
print(("AB" + "DC"[len(eval(input())) < 4]))
| false | 0 |
[
"-print((\"AB\" + \"DC\"[not input()[3:]]))",
"+print((\"AB\" + \"DC\"[len(eval(input())) < 4]))"
] | false | 0.039328 | 0.03907 | 1.006594 |
[
"s570808495",
"s683121161"
] |
u941407962
|
p02788
|
python
|
s782446344
|
s084467219
| 1,780 | 1,174 | 130,624 | 89,944 |
Accepted
|
Accepted
| 34.04 |
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
N, D, A = list(map(int, input().split()))
ys = []
for _ in range(N):
X, H = list(map(int, input().split()))
ys.append((2*X, -(-H//A)))
ys.append((2*X+4*D+1, -(-H//A)))
ys = sorted(ys, key=lambda x : x[0])
d1 = dict()
d2 = dict()
ls = []
c = 0
hs = [0]
for i, (y, h) in enumerate(ys):
if y%2:
d1[y-1-4*D] = c
else:
c += 1
d2[y] = c
ls.append(y)
hs.append(h)
lls = []
for i in range(N):
lls.append(d1[ls[i]]-d2[ls[i]]+1)
X = Bit(N+1)
r = 0
for i in range(N):
n = lls[i]
x = hs[i+1] + X.sum(i+1)
if x <=0:
continue
r += x
X.add(i+1, -x)
X.add(i+1+n, x)
print(r)
|
from collections import deque
N, D, A = list(map(int, input().split()))
ys = []
hs = []
for i in range(N):
X, H = list(map(int, input().split()))
ys.append((X,i))
hs.append(-(-H//A))
ys = sorted(ys, key=lambda x : x[0])
l = ys[0][0] + 2*D
li = 0
dmg = 0
r = 0
for y, i in ys:
while (not l >= y):
li += 1
l = ys[li][0] + 2*D
dmg -= hs[ys[li-1][1]]
tr = max(0, hs[i]-dmg)
hs[i] = tr
dmg += tr
r += tr
print(r)
| 55 | 25 | 1,037 | 478 |
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
N, D, A = list(map(int, input().split()))
ys = []
for _ in range(N):
X, H = list(map(int, input().split()))
ys.append((2 * X, -(-H // A)))
ys.append((2 * X + 4 * D + 1, -(-H // A)))
ys = sorted(ys, key=lambda x: x[0])
d1 = dict()
d2 = dict()
ls = []
c = 0
hs = [0]
for i, (y, h) in enumerate(ys):
if y % 2:
d1[y - 1 - 4 * D] = c
else:
c += 1
d2[y] = c
ls.append(y)
hs.append(h)
lls = []
for i in range(N):
lls.append(d1[ls[i]] - d2[ls[i]] + 1)
X = Bit(N + 1)
r = 0
for i in range(N):
n = lls[i]
x = hs[i + 1] + X.sum(i + 1)
if x <= 0:
continue
r += x
X.add(i + 1, -x)
X.add(i + 1 + n, x)
print(r)
|
from collections import deque
N, D, A = list(map(int, input().split()))
ys = []
hs = []
for i in range(N):
X, H = list(map(int, input().split()))
ys.append((X, i))
hs.append(-(-H // A))
ys = sorted(ys, key=lambda x: x[0])
l = ys[0][0] + 2 * D
li = 0
dmg = 0
r = 0
for y, i in ys:
while not l >= y:
li += 1
l = ys[li][0] + 2 * D
dmg -= hs[ys[li - 1][1]]
tr = max(0, hs[i] - dmg)
hs[i] = tr
dmg += tr
r += tr
print(r)
| false | 54.545455 |
[
"-class Bit:",
"- def __init__(self, n):",
"- self.size = n",
"- self.tree = [0] * (n + 1)",
"-",
"- def sum(self, i):",
"- s = 0",
"- while i > 0:",
"- s += self.tree[i]",
"- i -= i & -i",
"- return s",
"-",
"- def add(self, i, x):",
"- while i <= self.size:",
"- self.tree[i] += x",
"- i += i & -i",
"-",
"+from collections import deque",
"-for _ in range(N):",
"+hs = []",
"+for i in range(N):",
"- ys.append((2 * X, -(-H // A)))",
"- ys.append((2 * X + 4 * D + 1, -(-H // A)))",
"+ ys.append((X, i))",
"+ hs.append(-(-H // A))",
"-d1 = dict()",
"-d2 = dict()",
"-ls = []",
"-c = 0",
"-hs = [0]",
"-for i, (y, h) in enumerate(ys):",
"- if y % 2:",
"- d1[y - 1 - 4 * D] = c",
"- else:",
"- c += 1",
"- d2[y] = c",
"- ls.append(y)",
"- hs.append(h)",
"-lls = []",
"-for i in range(N):",
"- lls.append(d1[ls[i]] - d2[ls[i]] + 1)",
"-X = Bit(N + 1)",
"+l = ys[0][0] + 2 * D",
"+li = 0",
"+dmg = 0",
"-for i in range(N):",
"- n = lls[i]",
"- x = hs[i + 1] + X.sum(i + 1)",
"- if x <= 0:",
"- continue",
"- r += x",
"- X.add(i + 1, -x)",
"- X.add(i + 1 + n, x)",
"+for y, i in ys:",
"+ while not l >= y:",
"+ li += 1",
"+ l = ys[li][0] + 2 * D",
"+ dmg -= hs[ys[li - 1][1]]",
"+ tr = max(0, hs[i] - dmg)",
"+ hs[i] = tr",
"+ dmg += tr",
"+ r += tr"
] | false | 0.03985 | 0.036623 | 1.08812 |
[
"s782446344",
"s084467219"
] |
u745087332
|
p03108
|
python
|
s311592813
|
s086618242
| 956 | 648 | 110,940 | 29,076 |
Accepted
|
Accepted
| 32.22 |
# coding:utf-8
import sys
from collections import deque, defaultdict
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
# UnionFind
class UnionFind:
# 負: ルートで値は木の深さを表す
# 正: 子で値は次のノードを表す
def __init__(self, size: int) -> None:
self.nodes = [-1] * size # 初期状態では全てのノードがルート
def find(self, x: int) -> int:
if self.nodes[x] < 0:
return x
else:
self.nodes[x] = self.find(self.nodes[x])
return self.nodes[x]
def unite(self, x: int, y: int) -> None:
root_x, root_y = self.find(x), self.find(y)
if root_x != root_y:
if self.nodes[root_x] != self.nodes[root_y]: # グラフの高さが異なる場合
# 木のランクが高い方のルートに併合させる
# 併合後にランクの変動はない
if self.nodes[root_x] < self.nodes[root_y]:
self.nodes[root_y] = root_x
else:
self.nodes[root_x] = root_y
else:
# ランクが等しい木同士を併合させるので
# 併合後は木のランクが1つ上がる
self.nodes[root_x] += -1
self.nodes[root_y] = root_x
def same(self, x, y):
return self.find(x) == self.find(y)
def main():
n, m = LI()
uf = UnionFind(n)
res = deque()
res.append(n * (n - 1) // 2)
cnt = [1] * n
AB = [LI_() for _ in range(m)]
AB.reverse()
for a, b in AB:
if uf.same(a, b):
res.append(res[-1])
continue
ca = cnt[uf.find(a)]
cb = cnt[uf.find(b)]
tmp = res[-1] - ca * cb
# print(a+1, b+1, res[-1], ca, cb)
if tmp < 0:
tmp = 0
res.append(tmp)
uf.unite(a, b)
cnt[uf.find(a)] = ca + cb
# print(cnt[uf.find(a)], cnt[uf.find(b)])
res.reverse()
res.popleft()
print(*res, sep='\n')
main()
|
# coding:utf-8
import sys
from collections import deque, defaultdict
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
# UnionFind
class UnionFind:
# 負: ルートで値は木のサイズを表す
# 正: 子で値は次のノードを表す
def __init__(self, size: int) -> None:
self.nodes = [-1] * size # 初期状態では全てのノードがルート
def find(self, x: int) -> int:
if self.nodes[x] < 0:
return x
else:
self.nodes[x] = self.find(self.nodes[x])
return self.nodes[x]
def unite(self, x: int, y: int) -> bool:
rx, ry = self.find(x), self.find(y)
if rx == ry:
return False
if self.size(x) < self.size(y):
rx, ry = ry, rx
self.nodes[rx] += self.nodes[ry]
self.nodes[ry] = rx
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return - self.nodes[self.find(x)]
def main():
n, m = LI()
uf = UnionFind(n)
res = deque()
res.append(n * (n - 1) // 2)
AB = [LI_() for _ in range(m)]
AB.reverse()
for a, b in AB:
if uf.same(a, b):
res.append(res[-1])
continue
tmp = res[-1] - uf.size(a) * uf.size(b)
if tmp < 0:
tmp = 0
res.append(tmp)
uf.unite(a, b)
res.reverse()
res.popleft()
print(*res, sep='\n')
main()
| 80 | 74 | 2,137 | 1,685 |
# coding:utf-8
import sys
from collections import deque, defaultdict
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return input()
# UnionFind
class UnionFind:
# 負: ルートで値は木の深さを表す
# 正: 子で値は次のノードを表す
def __init__(self, size: int) -> None:
self.nodes = [-1] * size # 初期状態では全てのノードがルート
def find(self, x: int) -> int:
if self.nodes[x] < 0:
return x
else:
self.nodes[x] = self.find(self.nodes[x])
return self.nodes[x]
def unite(self, x: int, y: int) -> None:
root_x, root_y = self.find(x), self.find(y)
if root_x != root_y:
if self.nodes[root_x] != self.nodes[root_y]: # グラフの高さが異なる場合
# 木のランクが高い方のルートに併合させる
# 併合後にランクの変動はない
if self.nodes[root_x] < self.nodes[root_y]:
self.nodes[root_y] = root_x
else:
self.nodes[root_x] = root_y
else:
# ランクが等しい木同士を併合させるので
# 併合後は木のランクが1つ上がる
self.nodes[root_x] += -1
self.nodes[root_y] = root_x
def same(self, x, y):
return self.find(x) == self.find(y)
def main():
n, m = LI()
uf = UnionFind(n)
res = deque()
res.append(n * (n - 1) // 2)
cnt = [1] * n
AB = [LI_() for _ in range(m)]
AB.reverse()
for a, b in AB:
if uf.same(a, b):
res.append(res[-1])
continue
ca = cnt[uf.find(a)]
cb = cnt[uf.find(b)]
tmp = res[-1] - ca * cb
# print(a+1, b+1, res[-1], ca, cb)
if tmp < 0:
tmp = 0
res.append(tmp)
uf.unite(a, b)
cnt[uf.find(a)] = ca + cb
# print(cnt[uf.find(a)], cnt[uf.find(b)])
res.reverse()
res.popleft()
print(*res, sep="\n")
main()
|
# coding:utf-8
import sys
from collections import deque, defaultdict
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return input()
# UnionFind
class UnionFind:
# 負: ルートで値は木のサイズを表す
# 正: 子で値は次のノードを表す
def __init__(self, size: int) -> None:
self.nodes = [-1] * size # 初期状態では全てのノードがルート
def find(self, x: int) -> int:
if self.nodes[x] < 0:
return x
else:
self.nodes[x] = self.find(self.nodes[x])
return self.nodes[x]
def unite(self, x: int, y: int) -> bool:
rx, ry = self.find(x), self.find(y)
if rx == ry:
return False
if self.size(x) < self.size(y):
rx, ry = ry, rx
self.nodes[rx] += self.nodes[ry]
self.nodes[ry] = rx
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.nodes[self.find(x)]
def main():
n, m = LI()
uf = UnionFind(n)
res = deque()
res.append(n * (n - 1) // 2)
AB = [LI_() for _ in range(m)]
AB.reverse()
for a, b in AB:
if uf.same(a, b):
res.append(res[-1])
continue
tmp = res[-1] - uf.size(a) * uf.size(b)
if tmp < 0:
tmp = 0
res.append(tmp)
uf.unite(a, b)
res.reverse()
res.popleft()
print(*res, sep="\n")
main()
| false | 7.5 |
[
"- # 負: ルートで値は木の深さを表す",
"+ # 負: ルートで値は木のサイズを表す",
"- def unite(self, x: int, y: int) -> None:",
"- root_x, root_y = self.find(x), self.find(y)",
"- if root_x != root_y:",
"- if self.nodes[root_x] != self.nodes[root_y]: # グラフの高さが異なる場合",
"- # 木のランクが高い方のルートに併合させる",
"- # 併合後にランクの変動はない",
"- if self.nodes[root_x] < self.nodes[root_y]:",
"- self.nodes[root_y] = root_x",
"- else:",
"- self.nodes[root_x] = root_y",
"- else:",
"- # ランクが等しい木同士を併合させるので",
"- # 併合後は木のランクが1つ上がる",
"- self.nodes[root_x] += -1",
"- self.nodes[root_y] = root_x",
"+ def unite(self, x: int, y: int) -> bool:",
"+ rx, ry = self.find(x), self.find(y)",
"+ if rx == ry:",
"+ return False",
"+ if self.size(x) < self.size(y):",
"+ rx, ry = ry, rx",
"+ self.nodes[rx] += self.nodes[ry]",
"+ self.nodes[ry] = rx",
"+ return True",
"+",
"+ def size(self, x):",
"+ return -self.nodes[self.find(x)]",
"- cnt = [1] * n",
"- ca = cnt[uf.find(a)]",
"- cb = cnt[uf.find(b)]",
"- tmp = res[-1] - ca * cb",
"- # print(a+1, b+1, res[-1], ca, cb)",
"+ tmp = res[-1] - uf.size(a) * uf.size(b)",
"- cnt[uf.find(a)] = ca + cb",
"- # print(cnt[uf.find(a)], cnt[uf.find(b)])"
] | false | 0.079785 | 0.090693 | 0.879726 |
[
"s311592813",
"s086618242"
] |
u638456847
|
p02679
|
python
|
s856363272
|
s524650998
| 678 | 618 | 72,960 | 72,812 |
Accepted
|
Accepted
| 8.85 |
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
def main():
N,*ab = list(map(int, read().split()))
ab_zero = 0
ratio = []
for a, b in zip(*[iter(ab)]*2):
if a == 0 and b == 0:
ab_zero += 1
else:
g = gcd(a, b)
a //= g
b //= g
ratio.append((a, b))
ab_zero %= MOD
s = Counter(ratio)
bad = 1
for k, v in list(s.items()):
if v == 0:
continue
a, b = k
if (-a, -b) in s:
v += s[(-a, -b)]
s[(-a, -b)] = 0
inv = 0
if (-b, a) in s:
inv += s[(-b, a)]
s[(-b, a)] = 0
if (b, -a) in s:
inv += s[(b, -a)]
s[(b, -a)] = 0
bad *= (pow(2, v, MOD) + pow(2, inv, MOD) -1) % MOD
bad %= MOD
s[k] = 0
ans = (bad + ab_zero -1) % MOD
print(ans)
if __name__ == "__main__":
main()
|
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
def main():
N,*ab = list(map(int, read().split()))
ab_zero = 0
ratio = []
for a, b in zip(*[iter(ab)]*2):
if a == 0 and b == 0:
ab_zero += 1
else:
if b < 0:
a, b = -a, -b
if b == 0:
a = 1
g = gcd(a, b)
a //= g
b //= g
ratio.append((a, b))
ab_zero %= MOD
s = Counter(ratio)
bad = 1
for k, v in list(s.items()):
if v == 0:
continue
a, b = k
if (-b, a) in s:
bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) -1) % MOD
bad %= MOD
s[(-b, a)] = 0
elif (b, -a) in s:
bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) -1) % MOD
bad %= MOD
s[(b, -a)] = 0
else:
bad *= pow(2, v, MOD)
bad %= MOD
s[k] = 0
ans = (bad + ab_zero -1) % MOD
print(ans)
if __name__ == "__main__":
main()
| 54 | 54 | 1,111 | 1,256 |
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9 + 7
def main():
N, *ab = list(map(int, read().split()))
ab_zero = 0
ratio = []
for a, b in zip(*[iter(ab)] * 2):
if a == 0 and b == 0:
ab_zero += 1
else:
g = gcd(a, b)
a //= g
b //= g
ratio.append((a, b))
ab_zero %= MOD
s = Counter(ratio)
bad = 1
for k, v in list(s.items()):
if v == 0:
continue
a, b = k
if (-a, -b) in s:
v += s[(-a, -b)]
s[(-a, -b)] = 0
inv = 0
if (-b, a) in s:
inv += s[(-b, a)]
s[(-b, a)] = 0
if (b, -a) in s:
inv += s[(b, -a)]
s[(b, -a)] = 0
bad *= (pow(2, v, MOD) + pow(2, inv, MOD) - 1) % MOD
bad %= MOD
s[k] = 0
ans = (bad + ab_zero - 1) % MOD
print(ans)
if __name__ == "__main__":
main()
|
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9 + 7
def main():
N, *ab = list(map(int, read().split()))
ab_zero = 0
ratio = []
for a, b in zip(*[iter(ab)] * 2):
if a == 0 and b == 0:
ab_zero += 1
else:
if b < 0:
a, b = -a, -b
if b == 0:
a = 1
g = gcd(a, b)
a //= g
b //= g
ratio.append((a, b))
ab_zero %= MOD
s = Counter(ratio)
bad = 1
for k, v in list(s.items()):
if v == 0:
continue
a, b = k
if (-b, a) in s:
bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) - 1) % MOD
bad %= MOD
s[(-b, a)] = 0
elif (b, -a) in s:
bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) - 1) % MOD
bad %= MOD
s[(b, -a)] = 0
else:
bad *= pow(2, v, MOD)
bad %= MOD
s[k] = 0
ans = (bad + ab_zero - 1) % MOD
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"+ if b < 0:",
"+ a, b = -a, -b",
"+ if b == 0:",
"+ a = 1",
"- if (-a, -b) in s:",
"- v += s[(-a, -b)]",
"- s[(-a, -b)] = 0",
"- inv = 0",
"- inv += s[(-b, a)]",
"+ bad *= (pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) - 1) % MOD",
"+ bad %= MOD",
"- if (b, -a) in s:",
"- inv += s[(b, -a)]",
"+ elif (b, -a) in s:",
"+ bad *= (pow(2, v, MOD) + pow(2, s[(b, -a)], MOD) - 1) % MOD",
"+ bad %= MOD",
"- bad *= (pow(2, v, MOD) + pow(2, inv, MOD) - 1) % MOD",
"- bad %= MOD",
"+ else:",
"+ bad *= pow(2, v, MOD)",
"+ bad %= MOD"
] | false | 0.048306 | 0.046135 | 1.047052 |
[
"s856363272",
"s524650998"
] |
u119148115
|
p03682
|
python
|
s557650076
|
s623162804
| 1,999 | 908 | 139,608 | 121,084 |
Accepted
|
Accepted
| 54.58 |
class Kruskal():
def __init__(self,n):
self.e = []
self.par = [i for i in range(n+1)] #親のノード番号
self.rank = [0]*(n+1)
def add(self,u,v,d): #クラスカル法で考えるのは無向グラフ
self.e.append([u,v,d])
def find(self,x): #xの根のノード番号
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self,x,y): #x,yが同じグループか否か
return self.find(x) == self.find(y)
def unite(self,x,y): #x,yの属するグループの併合
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
elif self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[y] = x
self.rank[x] += 1
def Kruskal(self):
edges = sorted(self.e,key=lambda x: x[2]) #距離でソート
a = 0
for e in edges:
if not self.same_check(e[0],e[1]):
self.unite(e[0],e[1])
a += e[2]
return a
N = int(eval(input()))
A = [list(map(int,input().split())) for i in range(N)]
G = Kruskal(N)
X = []
Y = []
for i in range(N):
X.append((A[i][0], i))
Y.append((A[i][1], i))
X = sorted(X)
Y = sorted(Y)
# 辞書順で隣り合うものだけ考えれば良い
for i in range(N - 1):
G.add(X[i][1], X[i + 1][1], X[i + 1][0] - X[i][0])
G.add(Y[i][1], Y[i + 1][1], Y[i + 1][0] - Y[i][0])
print((G.Kruskal()))
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
X,Y = [],[]
for i in range(N):
x,y = MI()
X.append((x,i+1))
Y.append((y,i+1))
X.sort()
Y.sort()
# Kruskal
class Kruskal():
def __init__(self,n):
self.e = []
self.par = [i for i in range(n+1)] # 親のノード番号
self.rank = [0]*(n+1)
def add(self,u,v,d): # クラスカル法で考えるのは無向グラフ
self.e.append([u,v,d])
def find(self,x): # xの根のノード番号
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self,x,y): # x,yが同じグループか否か
return self.find(x) == self.find(y)
def unite(self,x,y): # x,yの属するグループの併合
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
elif self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[y] = x
self.rank[x] += 1
def Kruskal(self):
edges = sorted(self.e,key=lambda x: x[2]) # 距離でソート
a = 0
for e in edges:
if not self.same_check(e[0],e[1]):
self.unite(e[0],e[1])
a += e[2]
return a
K = Kruskal(N)
for j in range(N-1):
x0,i0 = X[j]
x1,i1 = X[j+1]
K.add(i0,i1,x1-x0)
for j in range(N-1):
y0,i0 = Y[j]
y1,i1 = Y[j+1]
K.add(i0,i1,y1-y0)
print((K.Kruskal()))
| 55 | 72 | 1,475 | 1,925 |
class Kruskal:
def __init__(self, n):
self.e = []
self.par = [i for i in range(n + 1)] # 親のノード番号
self.rank = [0] * (n + 1)
def add(self, u, v, d): # クラスカル法で考えるのは無向グラフ
self.e.append([u, v, d])
def find(self, x): # xの根のノード番号
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self, x, y): # x,yが同じグループか否か
return self.find(x) == self.find(y)
def unite(self, x, y): # x,yの属するグループの併合
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
elif self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[y] = x
self.rank[x] += 1
def Kruskal(self):
edges = sorted(self.e, key=lambda x: x[2]) # 距離でソート
a = 0
for e in edges:
if not self.same_check(e[0], e[1]):
self.unite(e[0], e[1])
a += e[2]
return a
N = int(eval(input()))
A = [list(map(int, input().split())) for i in range(N)]
G = Kruskal(N)
X = []
Y = []
for i in range(N):
X.append((A[i][0], i))
Y.append((A[i][1], i))
X = sorted(X)
Y = sorted(Y)
# 辞書順で隣り合うものだけ考えれば良い
for i in range(N - 1):
G.add(X[i][1], X[i + 1][1], X[i + 1][0] - X[i][0])
G.add(Y[i][1], Y[i + 1][1], Y[i + 1][0] - Y[i][0])
print((G.Kruskal()))
|
import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
X, Y = [], []
for i in range(N):
x, y = MI()
X.append((x, i + 1))
Y.append((y, i + 1))
X.sort()
Y.sort()
# Kruskal
class Kruskal:
def __init__(self, n):
self.e = []
self.par = [i for i in range(n + 1)] # 親のノード番号
self.rank = [0] * (n + 1)
def add(self, u, v, d): # クラスカル法で考えるのは無向グラフ
self.e.append([u, v, d])
def find(self, x): # xの根のノード番号
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self, x, y): # x,yが同じグループか否か
return self.find(x) == self.find(y)
def unite(self, x, y): # x,yの属するグループの併合
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
elif self.rank[x] > self.rank[y]:
self.par[y] = x
else:
self.par[y] = x
self.rank[x] += 1
def Kruskal(self):
edges = sorted(self.e, key=lambda x: x[2]) # 距離でソート
a = 0
for e in edges:
if not self.same_check(e[0], e[1]):
self.unite(e[0], e[1])
a += e[2]
return a
K = Kruskal(N)
for j in range(N - 1):
x0, i0 = X[j]
x1, i1 = X[j + 1]
K.add(i0, i1, x1 - x0)
for j in range(N - 1):
y0, i0 = Y[j]
y1, i1 = Y[j + 1]
K.add(i0, i1, y1 - y0)
print((K.Kruskal()))
| false | 23.611111 |
[
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline().rstrip())",
"+",
"+",
"+def MI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"+",
"+",
"+def LI2():",
"+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"+",
"+",
"+def S():",
"+ return sys.stdin.readline().rstrip()",
"+",
"+",
"+def LS():",
"+ return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"+",
"+",
"+def LS2():",
"+ return list(sys.stdin.readline().rstrip()) # 空白なし",
"+",
"+",
"+N = I()",
"+X, Y = [], []",
"+for i in range(N):",
"+ x, y = MI()",
"+ X.append((x, i + 1))",
"+ Y.append((y, i + 1))",
"+X.sort()",
"+Y.sort()",
"+# Kruskal",
"-N = int(eval(input()))",
"-A = [list(map(int, input().split())) for i in range(N)]",
"-G = Kruskal(N)",
"-X = []",
"-Y = []",
"-for i in range(N):",
"- X.append((A[i][0], i))",
"- Y.append((A[i][1], i))",
"-X = sorted(X)",
"-Y = sorted(Y)",
"-# 辞書順で隣り合うものだけ考えれば良い",
"-for i in range(N - 1):",
"- G.add(X[i][1], X[i + 1][1], X[i + 1][0] - X[i][0])",
"- G.add(Y[i][1], Y[i + 1][1], Y[i + 1][0] - Y[i][0])",
"-print((G.Kruskal()))",
"+K = Kruskal(N)",
"+for j in range(N - 1):",
"+ x0, i0 = X[j]",
"+ x1, i1 = X[j + 1]",
"+ K.add(i0, i1, x1 - x0)",
"+for j in range(N - 1):",
"+ y0, i0 = Y[j]",
"+ y1, i1 = Y[j + 1]",
"+ K.add(i0, i1, y1 - y0)",
"+print((K.Kruskal()))"
] | false | 0.040682 | 0.060395 | 0.673605 |
[
"s557650076",
"s623162804"
] |
u747602774
|
p02793
|
python
|
s468475648
|
s714930446
| 1,315 | 965 | 17,448 | 4,084 |
Accepted
|
Accepted
| 26.62 |
#べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)
def modinv(a,m):
return pow(a,m-2,m)
#n以下の素数列挙(O(nlog(n))
def primes(n):
ass = {}
is_prime = [True for _ in range(n+1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2,int(n**0.5)+1):
if not is_prime[i]:
continue
#i**2から始めてOK
for j in range(i*2,n+1,i):
is_prime[j] = False
for i in range(len(is_prime)):
if is_prime[i]:
ass[i] = 0
return ass
#[[素因数,数]]を出力
def fctr1(n):
f = []
c = 0
for i in range(2,int(n**0.5)+2):
while n%i == 0:
c += 1
n = n//i
if c !=0:
f.append([i,c])
c = 0
if n != 1:
f.append([n,1])
return f
N = int(eval(input()))
A = list(map(int,input().split()))
e = primes(10**6+7)
inv = 0
P = 10**9+7
for i in range(N):
inv = (inv+modinv(A[i],P))%P
l = fctr1(A[i])
for j in range(len(l)):
e[l[j][0]] = max(e[l[j][0]],l[j][1])
ans = 1
for k in list(e.keys()):
if e[k] != 0:
for i in range(e[k]):
ans = ans*k%P
ans = ans*inv%P
print(ans)
|
#a,bの最大公約数
def gcd(a,b):
while b:
a,b = b,a%b
return a
#a,bの最小公倍数
def lcm(a,b):
return a*b//gcd(a,b)
#べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)
def modinv2(a,m):
return pow(a,m-2,m)
N = int(eval(input()))
A = list(map(int,input().split()))
P = 10**9+7
if N == 1:
ans = 1
else:
inv = modinv2(A[0],P)
g = A[0]
invlist = []
seki = A[0]%P
for i in range(1,N):
inv = (inv+modinv2(A[i],P))%P
seki = seki*A[i]%P
g = gcd(A[0],A[1])
l = A[0]//g*A[1]
cc = modinv2(g,P)
for i in range(2,N):
g = gcd(l,A[i])
l = l//g*A[i]
cc = cc*modinv2(g,P)%P
ans = (inv*seki%P)*cc%P
print(ans)
| 57 | 44 | 1,195 | 729 |
# べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)
def modinv(a, m):
return pow(a, m - 2, m)
# n以下の素数列挙(O(nlog(n))
def primes(n):
ass = {}
is_prime = [True for _ in range(n + 1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
if not is_prime[i]:
continue
# i**2から始めてOK
for j in range(i * 2, n + 1, i):
is_prime[j] = False
for i in range(len(is_prime)):
if is_prime[i]:
ass[i] = 0
return ass
# [[素因数,数]]を出力
def fctr1(n):
f = []
c = 0
for i in range(2, int(n**0.5) + 2):
while n % i == 0:
c += 1
n = n // i
if c != 0:
f.append([i, c])
c = 0
if n != 1:
f.append([n, 1])
return f
N = int(eval(input()))
A = list(map(int, input().split()))
e = primes(10**6 + 7)
inv = 0
P = 10**9 + 7
for i in range(N):
inv = (inv + modinv(A[i], P)) % P
l = fctr1(A[i])
for j in range(len(l)):
e[l[j][0]] = max(e[l[j][0]], l[j][1])
ans = 1
for k in list(e.keys()):
if e[k] != 0:
for i in range(e[k]):
ans = ans * k % P
ans = ans * inv % P
print(ans)
|
# a,bの最大公約数
def gcd(a, b):
while b:
a, b = b, a % b
return a
# a,bの最小公倍数
def lcm(a, b):
return a * b // gcd(a, b)
# べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)
def modinv2(a, m):
return pow(a, m - 2, m)
N = int(eval(input()))
A = list(map(int, input().split()))
P = 10**9 + 7
if N == 1:
ans = 1
else:
inv = modinv2(A[0], P)
g = A[0]
invlist = []
seki = A[0] % P
for i in range(1, N):
inv = (inv + modinv2(A[i], P)) % P
seki = seki * A[i] % P
g = gcd(A[0], A[1])
l = A[0] // g * A[1]
cc = modinv2(g, P)
for i in range(2, N):
g = gcd(l, A[i])
l = l // g * A[i]
cc = cc * modinv2(g, P) % P
ans = (inv * seki % P) * cc % P
print(ans)
| false | 22.807018 |
[
"-# べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)",
"-def modinv(a, m):",
"- return pow(a, m - 2, m)",
"+# a,bの最大公約数",
"+def gcd(a, b):",
"+ while b:",
"+ a, b = b, a % b",
"+ return a",
"-# n以下の素数列挙(O(nlog(n))",
"-def primes(n):",
"- ass = {}",
"- is_prime = [True for _ in range(n + 1)]",
"- is_prime[0] = False",
"- is_prime[1] = False",
"- for i in range(2, int(n**0.5) + 1):",
"- if not is_prime[i]:",
"- continue",
"- # i**2から始めてOK",
"- for j in range(i * 2, n + 1, i):",
"- is_prime[j] = False",
"- for i in range(len(is_prime)):",
"- if is_prime[i]:",
"- ass[i] = 0",
"- return ass",
"+# a,bの最小公倍数",
"+def lcm(a, b):",
"+ return a * b // gcd(a, b)",
"-# [[素因数,数]]を出力",
"-def fctr1(n):",
"- f = []",
"- c = 0",
"- for i in range(2, int(n**0.5) + 2):",
"- while n % i == 0:",
"- c += 1",
"- n = n // i",
"- if c != 0:",
"- f.append([i, c])",
"- c = 0",
"- if n != 1:",
"- f.append([n, 1])",
"- return f",
"+# べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)",
"+def modinv2(a, m):",
"+ return pow(a, m - 2, m)",
"-e = primes(10**6 + 7)",
"-inv = 0",
"-for i in range(N):",
"- inv = (inv + modinv(A[i], P)) % P",
"- l = fctr1(A[i])",
"- for j in range(len(l)):",
"- e[l[j][0]] = max(e[l[j][0]], l[j][1])",
"-ans = 1",
"-for k in list(e.keys()):",
"- if e[k] != 0:",
"- for i in range(e[k]):",
"- ans = ans * k % P",
"-ans = ans * inv % P",
"+if N == 1:",
"+ ans = 1",
"+else:",
"+ inv = modinv2(A[0], P)",
"+ g = A[0]",
"+ invlist = []",
"+ seki = A[0] % P",
"+ for i in range(1, N):",
"+ inv = (inv + modinv2(A[i], P)) % P",
"+ seki = seki * A[i] % P",
"+ g = gcd(A[0], A[1])",
"+ l = A[0] // g * A[1]",
"+ cc = modinv2(g, P)",
"+ for i in range(2, N):",
"+ g = gcd(l, A[i])",
"+ l = l // g * A[i]",
"+ cc = cc * modinv2(g, P) % P",
"+ ans = (inv * seki % P) * cc % P"
] | false | 0.470857 | 0.105202 | 4.475739 |
[
"s468475648",
"s714930446"
] |
u864197622
|
p02794
|
python
|
s460839209
|
s856113782
| 1,352 | 290 | 58,844 | 56,668 |
Accepted
|
Accepted
| 78.55 |
N = int(eval(input()))
X = [[] for i in range(N)]
for i in range(N-1):
x, y = list(map(int, input().split()))
X[x-1].append(y-1)
X[y-1].append(x-1)
P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
i = Q.pop()
for a in X[i][::-1]:
if a != P[i]:
P[a] = i
DE[a] = DE[i] + 1
X[a].remove(i)
Q.append(a)
def lp(u, v):
t = 0
while u != v:
if DE[u] > DE[v]:
t += 1 << u-1
u = P[u]
elif DE[u] < DE[v]:
t += 1 << v-1
v = P[v]
else:
t += 1 << u-1
t += 1 << v-1
u = P[u]
v = P[v]
return t
Y = []
M = int(eval(input()))
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
Y.append(lp(a, b))
D = {1<<i: i for i in range(50)}
Z = [0] * (1<<M)
ans = 0
CC = [0] * N
BC = [0] * (1<<M)
for m in range(1, 1<<M):
a = m & (-m)
BC[m] = BC[m^a] + 1
for m in range(1<<M):
a = m & (-m)
if a == m:
if a == 0:
Z[m] = 0
else:
Z[m] = Y[D[a]]
else:
Z[m] = Z[m^a] | Y[D[a]]
CC[N - 1 - bin(Z[m]).count("1")] += (1 if BC[m] % 2 == 0 else -1)
print((sum([2 ** i * CC[i] for i in range(N)])))
|
N = int(eval(input()))
X = [[] for i in range(N)]
for i in range(N-1):
x, y = list(map(int, input().split()))
X[x-1].append(y-1)
X[y-1].append(x-1)
P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
i = Q.pop()
for a in X[i][::-1]:
if a != P[i]:
P[a] = i
DE[a] = DE[i] + 1
X[a].remove(i)
Q.append(a)
def lp(u, v):
t = 0
while u != v:
if DE[u] > DE[v]:
t += 1 << u-1
u = P[u]
elif DE[u] < DE[v]:
t += 1 << v-1
v = P[v]
else:
t += 1 << u-1
t += 1 << v-1
u = P[u]
v = P[v]
return t
Y = []
M = int(eval(input()))
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
Y.append(lp(a, b))
D = {1<<i: i for i in range(50)}
Z = [0] * (1<<M)
ans = 0
CC = [0] * N
BC = [0] * (1<<20)
for m in range(1, 1<<20):
a = m & (-m)
BC[m] = BC[m^a] + 1
for m in range(1<<M):
a = m & (-m)
if a == m:
if a == 0:
Z[m] = 0
else:
Z[m] = Y[D[a]]
else:
Z[m] = Z[m^a] | Y[D[a]]
aa = Z[m]
bc = BC[aa % (1<<10)]
aa >>= 10
bc += BC[aa % (1<<20)]
aa >>= 20
bc += BC[aa]
CC[N - 1 - bc] += (1 if BC[m] % 2 == 0 else -1)
print((sum([2 ** i * CC[i] for i in range(N)])))
| 64 | 70 | 1,316 | 1,418 |
N = int(eval(input()))
X = [[] for i in range(N)]
for i in range(N - 1):
x, y = list(map(int, input().split()))
X[x - 1].append(y - 1)
X[y - 1].append(x - 1)
P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
i = Q.pop()
for a in X[i][::-1]:
if a != P[i]:
P[a] = i
DE[a] = DE[i] + 1
X[a].remove(i)
Q.append(a)
def lp(u, v):
t = 0
while u != v:
if DE[u] > DE[v]:
t += 1 << u - 1
u = P[u]
elif DE[u] < DE[v]:
t += 1 << v - 1
v = P[v]
else:
t += 1 << u - 1
t += 1 << v - 1
u = P[u]
v = P[v]
return t
Y = []
M = int(eval(input()))
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
Y.append(lp(a, b))
D = {1 << i: i for i in range(50)}
Z = [0] * (1 << M)
ans = 0
CC = [0] * N
BC = [0] * (1 << M)
for m in range(1, 1 << M):
a = m & (-m)
BC[m] = BC[m ^ a] + 1
for m in range(1 << M):
a = m & (-m)
if a == m:
if a == 0:
Z[m] = 0
else:
Z[m] = Y[D[a]]
else:
Z[m] = Z[m ^ a] | Y[D[a]]
CC[N - 1 - bin(Z[m]).count("1")] += 1 if BC[m] % 2 == 0 else -1
print((sum([2**i * CC[i] for i in range(N)])))
|
N = int(eval(input()))
X = [[] for i in range(N)]
for i in range(N - 1):
x, y = list(map(int, input().split()))
X[x - 1].append(y - 1)
X[y - 1].append(x - 1)
P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
i = Q.pop()
for a in X[i][::-1]:
if a != P[i]:
P[a] = i
DE[a] = DE[i] + 1
X[a].remove(i)
Q.append(a)
def lp(u, v):
t = 0
while u != v:
if DE[u] > DE[v]:
t += 1 << u - 1
u = P[u]
elif DE[u] < DE[v]:
t += 1 << v - 1
v = P[v]
else:
t += 1 << u - 1
t += 1 << v - 1
u = P[u]
v = P[v]
return t
Y = []
M = int(eval(input()))
for _ in range(M):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
Y.append(lp(a, b))
D = {1 << i: i for i in range(50)}
Z = [0] * (1 << M)
ans = 0
CC = [0] * N
BC = [0] * (1 << 20)
for m in range(1, 1 << 20):
a = m & (-m)
BC[m] = BC[m ^ a] + 1
for m in range(1 << M):
a = m & (-m)
if a == m:
if a == 0:
Z[m] = 0
else:
Z[m] = Y[D[a]]
else:
Z[m] = Z[m ^ a] | Y[D[a]]
aa = Z[m]
bc = BC[aa % (1 << 10)]
aa >>= 10
bc += BC[aa % (1 << 20)]
aa >>= 20
bc += BC[aa]
CC[N - 1 - bc] += 1 if BC[m] % 2 == 0 else -1
print((sum([2**i * CC[i] for i in range(N)])))
| false | 8.571429 |
[
"-BC = [0] * (1 << M)",
"-for m in range(1, 1 << M):",
"+BC = [0] * (1 << 20)",
"+for m in range(1, 1 << 20):",
"- CC[N - 1 - bin(Z[m]).count(\"1\")] += 1 if BC[m] % 2 == 0 else -1",
"+ aa = Z[m]",
"+ bc = BC[aa % (1 << 10)]",
"+ aa >>= 10",
"+ bc += BC[aa % (1 << 20)]",
"+ aa >>= 20",
"+ bc += BC[aa]",
"+ CC[N - 1 - bc] += 1 if BC[m] % 2 == 0 else -1"
] | false | 0.100784 | 0.400473 | 0.251664 |
[
"s460839209",
"s856113782"
] |
u163320134
|
p03721
|
python
|
s014599101
|
s296000188
| 460 | 321 | 29,912 | 5,736 |
Accepted
|
Accepted
| 30.22 |
n,k=list(map(int,input().split()))
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr, key=lambda x:x[0])
sum=0
for i in range(n):
if sum<k<=sum+arr[i][1]:
print((arr[i][0]))
sum=sum+arr[i][1]
|
n,k=list(map(int,input().split()))
cnt=[0]*(10**5+1)
for _ in range(n):
a,b=list(map(int,input().split()))
cnt[a]+=b
tmp=0
for i in range(10**5+1):
tmp+=cnt[i]
if tmp>=k:
print(i)
break
| 8 | 11 | 218 | 199 |
n, k = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(n)]
arr = sorted(arr, key=lambda x: x[0])
sum = 0
for i in range(n):
if sum < k <= sum + arr[i][1]:
print((arr[i][0]))
sum = sum + arr[i][1]
|
n, k = list(map(int, input().split()))
cnt = [0] * (10**5 + 1)
for _ in range(n):
a, b = list(map(int, input().split()))
cnt[a] += b
tmp = 0
for i in range(10**5 + 1):
tmp += cnt[i]
if tmp >= k:
print(i)
break
| false | 27.272727 |
[
"-arr = [list(map(int, input().split())) for _ in range(n)]",
"-arr = sorted(arr, key=lambda x: x[0])",
"-sum = 0",
"-for i in range(n):",
"- if sum < k <= sum + arr[i][1]:",
"- print((arr[i][0]))",
"- sum = sum + arr[i][1]",
"+cnt = [0] * (10**5 + 1)",
"+for _ in range(n):",
"+ a, b = list(map(int, input().split()))",
"+ cnt[a] += b",
"+tmp = 0",
"+for i in range(10**5 + 1):",
"+ tmp += cnt[i]",
"+ if tmp >= k:",
"+ print(i)",
"+ break"
] | false | 0.155772 | 0.183603 | 0.848415 |
[
"s014599101",
"s296000188"
] |
u268822556
|
p02683
|
python
|
s364601666
|
s573247194
| 96 | 31 | 9,112 | 9,284 |
Accepted
|
Accepted
| 67.71 |
N, M, X = list(map(int, input().split()))
book_lists = [list(map(int, input().split())) for i in range(N)]
max_cost = 10**5*12+1
min_cost = max_cost
for i in range(1, 2**N):
score_list = [0 for _ in range(M)]
cost = 0
for j in range(N):
if i >> j & 1:
cost += book_lists[j][0]
for k in range(M):
score_list[k] += book_lists[j][k+1]
if min(score_list) >= X:
min_cost = min(cost, min_cost)
print((min_cost if not min_cost == max_cost else -1))
|
def saiki(i,cost,score_list):
if i == N:
if min(score_list) >= X:
ans.append(cost)
else:
temp = [score_list[j]+book_lists[i][j+1] for j in range(M)]
saiki(i+1,cost,score_list)
saiki(i+1,cost+book_lists[i][0],temp)
N,M,X = list(map(int,input().split()))
book_lists = [list(map(int, input().split())) for _ in range(N)]
ans=[]
saiki(0,0,[0]*M)
print((min(ans) if len(ans)!=0 else -1))
| 17 | 14 | 523 | 441 |
N, M, X = list(map(int, input().split()))
book_lists = [list(map(int, input().split())) for i in range(N)]
max_cost = 10**5 * 12 + 1
min_cost = max_cost
for i in range(1, 2**N):
score_list = [0 for _ in range(M)]
cost = 0
for j in range(N):
if i >> j & 1:
cost += book_lists[j][0]
for k in range(M):
score_list[k] += book_lists[j][k + 1]
if min(score_list) >= X:
min_cost = min(cost, min_cost)
print((min_cost if not min_cost == max_cost else -1))
|
def saiki(i, cost, score_list):
if i == N:
if min(score_list) >= X:
ans.append(cost)
else:
temp = [score_list[j] + book_lists[i][j + 1] for j in range(M)]
saiki(i + 1, cost, score_list)
saiki(i + 1, cost + book_lists[i][0], temp)
N, M, X = list(map(int, input().split()))
book_lists = [list(map(int, input().split())) for _ in range(N)]
ans = []
saiki(0, 0, [0] * M)
print((min(ans) if len(ans) != 0 else -1))
| false | 17.647059 |
[
"+def saiki(i, cost, score_list):",
"+ if i == N:",
"+ if min(score_list) >= X:",
"+ ans.append(cost)",
"+ else:",
"+ temp = [score_list[j] + book_lists[i][j + 1] for j in range(M)]",
"+ saiki(i + 1, cost, score_list)",
"+ saiki(i + 1, cost + book_lists[i][0], temp)",
"+",
"+",
"-book_lists = [list(map(int, input().split())) for i in range(N)]",
"-max_cost = 10**5 * 12 + 1",
"-min_cost = max_cost",
"-for i in range(1, 2**N):",
"- score_list = [0 for _ in range(M)]",
"- cost = 0",
"- for j in range(N):",
"- if i >> j & 1:",
"- cost += book_lists[j][0]",
"- for k in range(M):",
"- score_list[k] += book_lists[j][k + 1]",
"- if min(score_list) >= X:",
"- min_cost = min(cost, min_cost)",
"-print((min_cost if not min_cost == max_cost else -1))",
"+book_lists = [list(map(int, input().split())) for _ in range(N)]",
"+ans = []",
"+saiki(0, 0, [0] * M)",
"+print((min(ans) if len(ans) != 0 else -1))"
] | false | 0.037129 | 0.037039 | 1.002439 |
[
"s364601666",
"s573247194"
] |
u063052907
|
p03854
|
python
|
s946930153
|
s422736643
| 41 | 19 | 3,188 | 3,188 |
Accepted
|
Accepted
| 53.66 |
S = eval(input())
lst_str = ["maerd", "remaerd", "esare", "resare"]
char = ""
for c in S[::-1]:
char += c
if char in lst_str:
char = ""
if char:
print("NO")
else:
print("YES")
|
S = eval(input())
char = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if char:
print("NO")
else:
print("YES")
| 12 | 7 | 206 | 162 |
S = eval(input())
lst_str = ["maerd", "remaerd", "esare", "resare"]
char = ""
for c in S[::-1]:
char += c
if char in lst_str:
char = ""
if char:
print("NO")
else:
print("YES")
|
S = eval(input())
char = (
S.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
)
if char:
print("NO")
else:
print("YES")
| false | 41.666667 |
[
"-lst_str = [\"maerd\", \"remaerd\", \"esare\", \"resare\"]",
"-char = \"\"",
"-for c in S[::-1]:",
"- char += c",
"- if char in lst_str:",
"- char = \"\"",
"+char = (",
"+ S.replace(\"eraser\", \"\")",
"+ .replace(\"erase\", \"\")",
"+ .replace(\"dreamer\", \"\")",
"+ .replace(\"dream\", \"\")",
"+)"
] | false | 0.034616 | 0.041045 | 0.843371 |
[
"s946930153",
"s422736643"
] |
u044952145
|
p03854
|
python
|
s705937789
|
s519512242
| 30 | 19 | 3,188 | 3,188 |
Accepted
|
Accepted
| 36.67 |
S = input()[::-1]
i = 0
ls = len(S)
accept = True
while ls > i:
if S[i: i+5] == "maerd" or S[i: i+5] == "esare":
i += 5
elif S[i: i+6] == "resare":
i += 6
elif S[i: i+7] == "remaerd":
i += 7
else:
accept = False
break
if accept:
print("YES")
else:
print("NO")
|
S = eval(input())
result = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if len(result) == 0:
print("YES")
else:
print("NO")
| 20 | 7 | 344 | 176 |
S = input()[::-1]
i = 0
ls = len(S)
accept = True
while ls > i:
if S[i : i + 5] == "maerd" or S[i : i + 5] == "esare":
i += 5
elif S[i : i + 6] == "resare":
i += 6
elif S[i : i + 7] == "remaerd":
i += 7
else:
accept = False
break
if accept:
print("YES")
else:
print("NO")
|
S = eval(input())
result = (
S.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
)
if len(result) == 0:
print("YES")
else:
print("NO")
| false | 65 |
[
"-S = input()[::-1]",
"-i = 0",
"-ls = len(S)",
"-accept = True",
"-while ls > i:",
"- if S[i : i + 5] == \"maerd\" or S[i : i + 5] == \"esare\":",
"- i += 5",
"- elif S[i : i + 6] == \"resare\":",
"- i += 6",
"- elif S[i : i + 7] == \"remaerd\":",
"- i += 7",
"- else:",
"- accept = False",
"- break",
"-if accept:",
"+S = eval(input())",
"+result = (",
"+ S.replace(\"eraser\", \"\")",
"+ .replace(\"erase\", \"\")",
"+ .replace(\"dreamer\", \"\")",
"+ .replace(\"dream\", \"\")",
"+)",
"+if len(result) == 0:"
] | false | 0.035984 | 0.075692 | 0.475408 |
[
"s705937789",
"s519512242"
] |
u811733736
|
p00092
|
python
|
s576872602
|
s943457904
| 3,510 | 2,800 | 35,048 | 34,264 |
Accepted
|
Accepted
| 20.23 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square0(data):
max_size = 0
dp = [] # dp??¨???2?¬??????????
# '.'????????????1??????'*'????????????0????????????
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
dp.append(temp)
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(dp)):
for x in range(1, len(dp[0])):
if dp[y][x] == 1:
dp[y][x] = min(dp[y-1][x-1], dp[y-1][x], dp[y][x-1]) + 1
if dp[y][x] > max_size:
max_size = dp[y][x]
return max_size
def find_square2(data):
max_size = 0
dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬???????????????¨??????0??§?????????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y][x] = 1
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square3(data):
from array import array
max_size = 0
dp = [array('I', [0]*len(data[0])) for _ in range(len(data))] # ????¬?????????????array??????????????§?¢????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y][x] = 1
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square4(data):
# 4.91[s]
max_size = 0
dp = [0 for _ in range(1024*1024)]
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y*1024+x] = 1
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(data)):
for x in range(1, len(data)):
if dp[y*1024+x] == 1:
dp[y*1024+x] = min(dp[(y-1)*1024+x-1], dp[(y-1)*1024+x], dp[y*1024+x-1]) + 1
if dp[y*1024+x] > max_size:
max_size = dp[y*1024+x]
return max_size
def main(args):
while True:
n = int(eval(input()))
if n == 0:
break
data = [eval(input()) for _ in range(n)]
result = find_square0(data)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square0(data):
max_size = 0
dp = [] # dp??¨???2?¬??????????
# '.'????????????1??????'*'????????????0????????????
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
dp.append(temp)
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(dp)):
for x in range(1, len(dp[0])):
if dp[y][x] == 1:
dp[y][x] = min(dp[y-1][x-1], dp[y-1][x], dp[y][x-1]) + 1
if dp[y][x] > max_size:
max_size = dp[y][x]
return max_size
def find_square2(data):
max_size = 0
dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬???????????????¨??????0??§?????????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y][x] = 1
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square3(data):
from array import array
max_size = 0
dp = [array('I', [0]*len(data[0])) for _ in range(len(data))] # ????¬?????????????array??????????????§?¢????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y][x] = 1
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square4(data):
# 4.91[s]
max_size = 0
dp = [0 for _ in range(1024*1024)]
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y*1024+x] = 1
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(data)):
for x in range(1, len(data)):
if dp[y*1024+x] == 1:
dp[y*1024+x] = min(dp[(y-1)*1024+x-1], dp[(y-1)*1024+x], dp[y*1024+x-1]) + 1
if dp[y*1024+x] > max_size:
max_size = dp[y*1024+x]
return max_size
def main(args):
while True:
n = int(eval(input()))
if n == 0:
break
data = [eval(input()) for _ in range(n)]
result = find_square2(data)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
| 105 | 105 | 3,266 | 3,266 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square0(data):
max_size = 0
dp = [] # dp??¨???2?¬??????????
# '.'????????????1??????'*'????????????0????????????
for row in data:
temp = []
for c in row:
if c == ".":
temp.append(1)
else:
temp.append(0)
dp.append(temp)
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(dp)):
for x in range(1, len(dp[0])):
if dp[y][x] == 1:
dp[y][x] = min(dp[y - 1][x - 1], dp[y - 1][x], dp[y][x - 1]) + 1
if dp[y][x] > max_size:
max_size = dp[y][x]
return max_size
def find_square2(data):
max_size = 0
dp = [
[0] * len(data[0]) for _ in range(len(data))
] # dp??¨???2?¬???????????????¨??????0??§?????????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == ".":
dp[y][x] = 1
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x - 1], prev_row[x], curr_row[x - 1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square3(data):
from array import array
max_size = 0
dp = [
array("I", [0] * len(data[0])) for _ in range(len(data))
] # ????¬?????????????array??????????????§?¢????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == ".":
dp[y][x] = 1
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x - 1], prev_row[x], curr_row[x - 1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square4(data):
# 4.91[s]
max_size = 0
dp = [0 for _ in range(1024 * 1024)]
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == ".":
dp[y * 1024 + x] = 1
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(data)):
for x in range(1, len(data)):
if dp[y * 1024 + x] == 1:
dp[y * 1024 + x] = (
min(
dp[(y - 1) * 1024 + x - 1],
dp[(y - 1) * 1024 + x],
dp[y * 1024 + x - 1],
)
+ 1
)
if dp[y * 1024 + x] > max_size:
max_size = dp[y * 1024 + x]
return max_size
def main(args):
while True:
n = int(eval(input()))
if n == 0:
break
data = [eval(input()) for _ in range(n)]
result = find_square0(data)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square0(data):
max_size = 0
dp = [] # dp??¨???2?¬??????????
# '.'????????????1??????'*'????????????0????????????
for row in data:
temp = []
for c in row:
if c == ".":
temp.append(1)
else:
temp.append(0)
dp.append(temp)
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(dp)):
for x in range(1, len(dp[0])):
if dp[y][x] == 1:
dp[y][x] = min(dp[y - 1][x - 1], dp[y - 1][x], dp[y][x - 1]) + 1
if dp[y][x] > max_size:
max_size = dp[y][x]
return max_size
def find_square2(data):
max_size = 0
dp = [
[0] * len(data[0]) for _ in range(len(data))
] # dp??¨???2?¬???????????????¨??????0??§?????????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == ".":
dp[y][x] = 1
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x - 1], prev_row[x], curr_row[x - 1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square3(data):
from array import array
max_size = 0
dp = [
array("I", [0] * len(data[0])) for _ in range(len(data))
] # ????¬?????????????array??????????????§?¢????
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == ".":
dp[y][x] = 1
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x - 1], prev_row[x], curr_row[x - 1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square4(data):
# 4.91[s]
max_size = 0
dp = [0 for _ in range(1024 * 1024)]
# '.'????????????1???
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == ".":
dp[y * 1024 + x] = 1
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(data)):
for x in range(1, len(data)):
if dp[y * 1024 + x] == 1:
dp[y * 1024 + x] = (
min(
dp[(y - 1) * 1024 + x - 1],
dp[(y - 1) * 1024 + x],
dp[y * 1024 + x - 1],
)
+ 1
)
if dp[y * 1024 + x] > max_size:
max_size = dp[y * 1024 + x]
return max_size
def main(args):
while True:
n = int(eval(input()))
if n == 0:
break
data = [eval(input()) for _ in range(n)]
result = find_square2(data)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 0 |
[
"- result = find_square0(data)",
"+ result = find_square2(data)"
] | false | 0.098733 | 0.114531 | 0.862062 |
[
"s576872602",
"s943457904"
] |
u353919145
|
p03325
|
python
|
s378710938
|
s470721101
| 76 | 67 | 3,460 | 3,460 |
Accepted
|
Accepted
| 11.84 |
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
curr = a[i]
while True:
if curr % 2 == 0:
curr /= 2
count += 1
else:
break
print(count)
|
c = eval(input())
m = list(map(int, input().split()))
conte = 0
for i in m:
while(i%2 == 0):
conte += 1
i /= 2
print(conte)
| 14 | 14 | 246 | 139 |
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
curr = a[i]
while True:
if curr % 2 == 0:
curr /= 2
count += 1
else:
break
print(count)
|
c = eval(input())
m = list(map(int, input().split()))
conte = 0
for i in m:
while i % 2 == 0:
conte += 1
i /= 2
print(conte)
| false | 0 |
[
"-n = int(input())",
"-a = list(map(int, input().split()))",
"-count = 0",
"-for i in range(n):",
"- curr = a[i]",
"- while True:",
"- if curr % 2 == 0:",
"- curr /= 2",
"- count += 1",
"- else:",
"- break",
"-print(count)",
"+c = eval(input())",
"+m = list(map(int, input().split()))",
"+conte = 0",
"+for i in m:",
"+ while i % 2 == 0:",
"+ conte += 1",
"+ i /= 2",
"+print(conte)"
] | false | 0.037379 | 0.068704 | 0.544059 |
[
"s378710938",
"s470721101"
] |
u585819925
|
p02837
|
python
|
s516073669
|
s570429818
| 1,640 | 1,457 | 3,064 | 3,064 |
Accepted
|
Accepted
| 11.16 |
n = int(eval(input()))
g = [[-1 for j in range(n)] for i in range(n)]
for i in range(n):
a = int(eval(input()))
for _ in range(a):
x, y = list(map(int, input().split()))
g[i][x-1] = y
ans = 0
for s in range(2**n):
ok = True
for i in range(n):
if (s>>i&1) == 1:
for j in range(n):
if g[i][j] != -1 and (s>>j&1) != g[i][j]:
ok = False
if ok:
ans = max(ans, bin(s).count("1"))
print(ans)
|
n = int(eval(input()))
g = [[-1]*n for i in range(n)]
for i in range(n):
a = int(eval(input()))
for _ in range(a):
x, y = list(map(int, input().split()))
g[i][x-1] = y
ans = 0
for s in range(2**n):
ok = True
for i in range(n):
if (s>>i&1) == 1:
for j in range(n):
if g[i][j] == -1: continue
if (s>>j&1) != g[i][j]: ok = False
if ok:
ans = max(ans, bin(s).count("1"))
print(ans)
| 22 | 22 | 417 | 409 |
n = int(eval(input()))
g = [[-1 for j in range(n)] for i in range(n)]
for i in range(n):
a = int(eval(input()))
for _ in range(a):
x, y = list(map(int, input().split()))
g[i][x - 1] = y
ans = 0
for s in range(2**n):
ok = True
for i in range(n):
if (s >> i & 1) == 1:
for j in range(n):
if g[i][j] != -1 and (s >> j & 1) != g[i][j]:
ok = False
if ok:
ans = max(ans, bin(s).count("1"))
print(ans)
|
n = int(eval(input()))
g = [[-1] * n for i in range(n)]
for i in range(n):
a = int(eval(input()))
for _ in range(a):
x, y = list(map(int, input().split()))
g[i][x - 1] = y
ans = 0
for s in range(2**n):
ok = True
for i in range(n):
if (s >> i & 1) == 1:
for j in range(n):
if g[i][j] == -1:
continue
if (s >> j & 1) != g[i][j]:
ok = False
if ok:
ans = max(ans, bin(s).count("1"))
print(ans)
| false | 0 |
[
"-g = [[-1 for j in range(n)] for i in range(n)]",
"+g = [[-1] * n for i in range(n)]",
"- if g[i][j] != -1 and (s >> j & 1) != g[i][j]:",
"+ if g[i][j] == -1:",
"+ continue",
"+ if (s >> j & 1) != g[i][j]:"
] | false | 0.075713 | 0.03872 | 1.955397 |
[
"s516073669",
"s570429818"
] |
u821989875
|
p03557
|
python
|
s724805391
|
s215665327
| 854 | 347 | 24,264 | 22,720 |
Accepted
|
Accepted
| 59.37 |
# coding: utf-8
n = int(eval(input()))
al = sorted(list(int(i) for i in input().split()))
bl = sorted(list(int(i) for i in input().split()))
cl = sorted(list(int(i) for i in input().split()))
ans = 0
def low_left(a, key):
left = -1
right = len(a)
while right - left > 1:
center = (left + right) // 2
if a[center] >= key:
right = center
else:
left = center
return left+1
def high_right(a, key):
left = -1
right = len(a)
while right - left > 1:
center = (left + right) // 2
if a[center] <= key:
left = center
else:
right = center
return n-right
for i in bl:
ans += low_left(al, i) * high_right(cl, i)
print(ans)
|
import bisect
n = int(eval(input()))
al, bl, cl = list(sorted(map(int, input().split())) for i in range(3))
ans = 0
for key in bl:
top = bisect.bisect_left(al, key)
btm = len(cl) - bisect.bisect_right(cl, key)
ans += top * btm
print(ans)
| 33 | 12 | 780 | 257 |
# coding: utf-8
n = int(eval(input()))
al = sorted(list(int(i) for i in input().split()))
bl = sorted(list(int(i) for i in input().split()))
cl = sorted(list(int(i) for i in input().split()))
ans = 0
def low_left(a, key):
left = -1
right = len(a)
while right - left > 1:
center = (left + right) // 2
if a[center] >= key:
right = center
else:
left = center
return left + 1
def high_right(a, key):
left = -1
right = len(a)
while right - left > 1:
center = (left + right) // 2
if a[center] <= key:
left = center
else:
right = center
return n - right
for i in bl:
ans += low_left(al, i) * high_right(cl, i)
print(ans)
|
import bisect
n = int(eval(input()))
al, bl, cl = list(sorted(map(int, input().split())) for i in range(3))
ans = 0
for key in bl:
top = bisect.bisect_left(al, key)
btm = len(cl) - bisect.bisect_right(cl, key)
ans += top * btm
print(ans)
| false | 63.636364 |
[
"-# coding: utf-8",
"+import bisect",
"+",
"-al = sorted(list(int(i) for i in input().split()))",
"-bl = sorted(list(int(i) for i in input().split()))",
"-cl = sorted(list(int(i) for i in input().split()))",
"+al, bl, cl = list(sorted(map(int, input().split())) for i in range(3))",
"-",
"-",
"-def low_left(a, key):",
"- left = -1",
"- right = len(a)",
"- while right - left > 1:",
"- center = (left + right) // 2",
"- if a[center] >= key:",
"- right = center",
"- else:",
"- left = center",
"- return left + 1",
"-",
"-",
"-def high_right(a, key):",
"- left = -1",
"- right = len(a)",
"- while right - left > 1:",
"- center = (left + right) // 2",
"- if a[center] <= key:",
"- left = center",
"- else:",
"- right = center",
"- return n - right",
"-",
"-",
"-for i in bl:",
"- ans += low_left(al, i) * high_right(cl, i)",
"+for key in bl:",
"+ top = bisect.bisect_left(al, key)",
"+ btm = len(cl) - bisect.bisect_right(cl, key)",
"+ ans += top * btm"
] | false | 0.040959 | 0.041302 | 0.991698 |
[
"s724805391",
"s215665327"
] |
u242580186
|
p03167
|
python
|
s898179682
|
s488640015
| 199 | 122 | 92,820 | 83,092 |
Accepted
|
Accepted
| 38.69 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# ---------------------------------------
mod = 10**9 + 7
H, W = inpl()
a = []
flag = [[False] * W for i in range(H)]
for i in range(H):
a.append(input().strip())
_debug(a)
dp = [[0] * (W+1) for i in range(H+1)]
dp[0][0] = 1
for i in range(max(H, W)):
if i < H:
for j in range(W):
if a[i][j] == "#" or flag[i][j]:
continue
flag[i][j] = True
for x, y in ((0, 1), (1, 0)):
dp[i+x][j+y] += dp[i][j]
dp[i+x][j+y] %= mod
if i < W:
for j in range(H):
if a[j][i] == "#" or flag[j][i]:
continue
flag[j][i] = True
for x, y in ((0, 1), (1, 0)):
dp[j+x][i+y] += dp[j][i]
dp[j+x][i+y] %= mod
print(dp[H-1][W-1])
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# ---------------------------------------
mod = 10**9 + 7
H, W = inpl()
a = []
for i in range(H):
a.append(input().strip())
dp = [[0] * (W+1) for i in range(H+1)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
for x, y in ((1, 0), (0, 1)):
dp[i+x][j+y] += dp[i][j]
dp[i+x][j+y] %= mod
print(dp[H-1][W-1])
| 49 | 38 | 1,210 | 797 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# ---------------------------------------
mod = 10**9 + 7
H, W = inpl()
a = []
flag = [[False] * W for i in range(H)]
for i in range(H):
a.append(input().strip())
_debug(a)
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][0] = 1
for i in range(max(H, W)):
if i < H:
for j in range(W):
if a[i][j] == "#" or flag[i][j]:
continue
flag[i][j] = True
for x, y in ((0, 1), (1, 0)):
dp[i + x][j + y] += dp[i][j]
dp[i + x][j + y] %= mod
if i < W:
for j in range(H):
if a[j][i] == "#" or flag[j][i]:
continue
flag[j][i] = True
for x, y in ((0, 1), (1, 0)):
dp[j + x][i + y] += dp[j][i]
dp[j + x][i + y] %= mod
print(dp[H - 1][W - 1])
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# ---------------------------------------
mod = 10**9 + 7
H, W = inpl()
a = []
for i in range(H):
a.append(input().strip())
dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
for x, y in ((1, 0), (0, 1)):
dp[i + x][j + y] += dp[i][j]
dp[i + x][j + y] %= mod
print(dp[H - 1][W - 1])
| false | 22.44898 |
[
"-flag = [[False] * W for i in range(H)]",
"-_debug(a)",
"-for i in range(max(H, W)):",
"- if i < H:",
"- for j in range(W):",
"- if a[i][j] == \"#\" or flag[i][j]:",
"- continue",
"- flag[i][j] = True",
"- for x, y in ((0, 1), (1, 0)):",
"- dp[i + x][j + y] += dp[i][j]",
"- dp[i + x][j + y] %= mod",
"- if i < W:",
"- for j in range(H):",
"- if a[j][i] == \"#\" or flag[j][i]:",
"- continue",
"- flag[j][i] = True",
"- for x, y in ((0, 1), (1, 0)):",
"- dp[j + x][i + y] += dp[j][i]",
"- dp[j + x][i + y] %= mod",
"+for i in range(H):",
"+ for j in range(W):",
"+ if a[i][j] == \"#\":",
"+ continue",
"+ for x, y in ((1, 0), (0, 1)):",
"+ dp[i + x][j + y] += dp[i][j]",
"+ dp[i + x][j + y] %= mod"
] | false | 0.072993 | 0.126513 | 0.576965 |
[
"s898179682",
"s488640015"
] |
u312025627
|
p03700
|
python
|
s066345746
|
s519284327
| 1,451 | 632 | 53,172 | 122,840 |
Accepted
|
Accepted
| 56.44 |
def main():
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(x):
y = 0 # 中心爆破必要回数
for i, h in enumerate(H):
if h - x*B <= 0:
continue
le = 0
ri = 10**9 + 1
while ri - le > 1:
mid = le + ((ri - le) // 2)
if h - B*(max(x - mid, 0)) - A*mid <= 0:
ri = mid
else:
le = mid
y += ri
if y <= x: # 魔物を消し去るのが可能
return True
else:
return False
def binary_search_meguru():
left = -1
right = 10**9 + 1
while right - left > 1:
mid = left + ((right - left) // 2)
if is_ok(mid):
right = mid
else:
left = mid
return right
print((binary_search_meguru()))
if __name__ == '__main__':
main()
|
def main():
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(H, mid):
H = [h - mid*B for h in H]
need = 0
for h in H:
if h > 0:
need += (h + (A - B) - 1)//(A - B)
if need <= mid:
return True
else:
return False
def binary_search_meguru(H):
ng = -1
ok = 10**9 + 1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2 # 爆破回数
if is_ok(H, mid):
ok = mid
else:
ng = mid
return ok
print((binary_search_meguru(H)))
if __name__ == '__main__':
main()
| 39 | 31 | 999 | 730 |
def main():
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(x):
y = 0 # 中心爆破必要回数
for i, h in enumerate(H):
if h - x * B <= 0:
continue
le = 0
ri = 10**9 + 1
while ri - le > 1:
mid = le + ((ri - le) // 2)
if h - B * (max(x - mid, 0)) - A * mid <= 0:
ri = mid
else:
le = mid
y += ri
if y <= x: # 魔物を消し去るのが可能
return True
else:
return False
def binary_search_meguru():
left = -1
right = 10**9 + 1
while right - left > 1:
mid = left + ((right - left) // 2)
if is_ok(mid):
right = mid
else:
left = mid
return right
print((binary_search_meguru()))
if __name__ == "__main__":
main()
|
def main():
N, A, B = (int(i) for i in input().split())
H = [int(eval(input())) for i in range(N)]
def is_ok(H, mid):
H = [h - mid * B for h in H]
need = 0
for h in H:
if h > 0:
need += (h + (A - B) - 1) // (A - B)
if need <= mid:
return True
else:
return False
def binary_search_meguru(H):
ng = -1
ok = 10**9 + 1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2 # 爆破回数
if is_ok(H, mid):
ok = mid
else:
ng = mid
return ok
print((binary_search_meguru(H)))
if __name__ == "__main__":
main()
| false | 20.512821 |
[
"- def is_ok(x):",
"- y = 0 # 中心爆破必要回数",
"- for i, h in enumerate(H):",
"- if h - x * B <= 0:",
"- continue",
"- le = 0",
"- ri = 10**9 + 1",
"- while ri - le > 1:",
"- mid = le + ((ri - le) // 2)",
"- if h - B * (max(x - mid, 0)) - A * mid <= 0:",
"- ri = mid",
"- else:",
"- le = mid",
"- y += ri",
"- if y <= x: # 魔物を消し去るのが可能",
"+ def is_ok(H, mid):",
"+ H = [h - mid * B for h in H]",
"+ need = 0",
"+ for h in H:",
"+ if h > 0:",
"+ need += (h + (A - B) - 1) // (A - B)",
"+ if need <= mid:",
"- def binary_search_meguru():",
"- left = -1",
"- right = 10**9 + 1",
"- while right - left > 1:",
"- mid = left + ((right - left) // 2)",
"- if is_ok(mid):",
"- right = mid",
"+ def binary_search_meguru(H):",
"+ ng = -1",
"+ ok = 10**9 + 1",
"+ while abs(ok - ng) > 1:",
"+ mid = ng + (ok - ng) // 2 # 爆破回数",
"+ if is_ok(H, mid):",
"+ ok = mid",
"- left = mid",
"- return right",
"+ ng = mid",
"+ return ok",
"- print((binary_search_meguru()))",
"+ print((binary_search_meguru(H)))"
] | false | 0.038738 | 0.03732 | 1.037999 |
[
"s066345746",
"s519284327"
] |
u102126195
|
p03013
|
python
|
s410713796
|
s606480098
| 522 | 197 | 50,848 | 7,816 |
Accepted
|
Accepted
| 62.26 |
n, m = list(map(int, input().split()))
a = [0 for _ in range(n + 1)]
for i in range(m):
A = int(eval(input()))
a[A] = 1
tmp = [0 for _ in range(n + 1)]
tmp[0] = 1
for i in range(1, n + 1):
if a[i] == 1:
tmp[i] = 0
else:
if i - 2 >= 0:
tmp[i] += tmp[i - 2]
if i - 1 >= 0:
tmp[i] += tmp[i - 1]
tmp[i] %= 1000000007
print((tmp[-1] % 1000000007))
|
n, m = list(map(int, input().split()))
a = [0 for _ in range(n + 1)]
for i in range(m):
A = int(eval(input()))
a[A] = 1
tmp = [0 for _ in range(n + 1)]
tmp[0] = 1
for i in range(1, n + 1):
if a[i] == 1:
tmp[i] = 0
else:
if i - 2 >= 0:
tmp[i] += tmp[i - 2]
if i - 1 >= 0:
tmp[i] += tmp[i - 1]
tmp[i] %= 1000000007
print((tmp[n] % 1000000007))
| 21 | 20 | 424 | 421 |
n, m = list(map(int, input().split()))
a = [0 for _ in range(n + 1)]
for i in range(m):
A = int(eval(input()))
a[A] = 1
tmp = [0 for _ in range(n + 1)]
tmp[0] = 1
for i in range(1, n + 1):
if a[i] == 1:
tmp[i] = 0
else:
if i - 2 >= 0:
tmp[i] += tmp[i - 2]
if i - 1 >= 0:
tmp[i] += tmp[i - 1]
tmp[i] %= 1000000007
print((tmp[-1] % 1000000007))
|
n, m = list(map(int, input().split()))
a = [0 for _ in range(n + 1)]
for i in range(m):
A = int(eval(input()))
a[A] = 1
tmp = [0 for _ in range(n + 1)]
tmp[0] = 1
for i in range(1, n + 1):
if a[i] == 1:
tmp[i] = 0
else:
if i - 2 >= 0:
tmp[i] += tmp[i - 2]
if i - 1 >= 0:
tmp[i] += tmp[i - 1]
tmp[i] %= 1000000007
print((tmp[n] % 1000000007))
| false | 4.761905 |
[
"-print((tmp[-1] % 1000000007))",
"+print((tmp[n] % 1000000007))"
] | false | 0.037225 | 0.043347 | 0.858759 |
[
"s410713796",
"s606480098"
] |
u170201762
|
p03082
|
python
|
s832732147
|
s849939154
| 1,891 | 1,673 | 225,548 | 225,672 |
Accepted
|
Accepted
| 11.53 |
N,X = list(map(int,input().split()))
S = list(map(int,input().split()))
S.sort()
mod = 10**9+7
dp = [[x]+[0]*N for x in range(X+1)]
for x in range(X+1):
for n in range(1,N+1):
dp[x][n] = (dp[x%S[n-1]][n-1] + (n-1)*dp[x][n-1])%mod
print((dp[X][N]))
|
N,X = list(map(int,input().split()))
S = list(map(int,input().split()))
S.sort()
mod = 10**9+7
dp = [[x]+[0]*N for x in range(X+1)]
for n in range(1,N+1):
for x in range(X+1):
dp[x][n] = (dp[x%S[n-1]][n-1] + (n-1)*dp[x][n-1])%mod
print((dp[X][N]))
| 11 | 11 | 263 | 263 |
N, X = list(map(int, input().split()))
S = list(map(int, input().split()))
S.sort()
mod = 10**9 + 7
dp = [[x] + [0] * N for x in range(X + 1)]
for x in range(X + 1):
for n in range(1, N + 1):
dp[x][n] = (dp[x % S[n - 1]][n - 1] + (n - 1) * dp[x][n - 1]) % mod
print((dp[X][N]))
|
N, X = list(map(int, input().split()))
S = list(map(int, input().split()))
S.sort()
mod = 10**9 + 7
dp = [[x] + [0] * N for x in range(X + 1)]
for n in range(1, N + 1):
for x in range(X + 1):
dp[x][n] = (dp[x % S[n - 1]][n - 1] + (n - 1) * dp[x][n - 1]) % mod
print((dp[X][N]))
| false | 0 |
[
"-for x in range(X + 1):",
"- for n in range(1, N + 1):",
"+for n in range(1, N + 1):",
"+ for x in range(X + 1):"
] | false | 0.344266 | 0.676701 | 0.508742 |
[
"s832732147",
"s849939154"
] |
u997641430
|
p03076
|
python
|
s631767997
|
s248425029
| 19 | 17 | 3,060 | 3,064 |
Accepted
|
Accepted
| 10.53 |
A = [int(eval(input())) for i in range(5)]
B = [(10 - a % 10) % 10 for a in A]
print((sum(A) + sum(B) - max(B)))
|
A = [int(eval(input())) for i in range(5)]
# A = [101, 86, 119, 108, 57]
# A = [29, 20, 7, 35, 120]
# A = [123, 123, 123, 123, 123]
B = [(10-a % 10) % 10 for a in A]
C = [-(-a//10)*10 for a in A]
print((sum(C)-max(B)))
| 3 | 7 | 107 | 217 |
A = [int(eval(input())) for i in range(5)]
B = [(10 - a % 10) % 10 for a in A]
print((sum(A) + sum(B) - max(B)))
|
A = [int(eval(input())) for i in range(5)]
# A = [101, 86, 119, 108, 57]
# A = [29, 20, 7, 35, 120]
# A = [123, 123, 123, 123, 123]
B = [(10 - a % 10) % 10 for a in A]
C = [-(-a // 10) * 10 for a in A]
print((sum(C) - max(B)))
| false | 57.142857 |
[
"+# A = [101, 86, 119, 108, 57]",
"+# A = [29, 20, 7, 35, 120]",
"+# A = [123, 123, 123, 123, 123]",
"-print((sum(A) + sum(B) - max(B)))",
"+C = [-(-a // 10) * 10 for a in A]",
"+print((sum(C) - max(B)))"
] | false | 0.077638 | 0.177732 | 0.436825 |
[
"s631767997",
"s248425029"
] |
u063896676
|
p03240
|
python
|
s411810053
|
s025371384
| 112 | 65 | 3,064 | 3,064 |
Accepted
|
Accepted
| 41.96 |
# -*- coding: utf-8 -*-
N = int(eval(input()))
x = [None] * N
y = [None] * N
h = [None] * N
for i in range(N):
x[i], y[i], h[i] = list(map(int, input().split()))
def distance(a,b):
a_x = a[0]
a_y = a[1]
b_x = b[0]
b_y = b[1]
return abs(a_x - b_x) + abs(a_y - b_y)
for cx in range(101):
for cy in range(101):
ans = True
c = [cx, cy]
for i in range(N):
if h[i] != 0:
ch = distance(c, [x[i], y[i]]) + h[i]
break
# ch = distance(c, [x[0], y[0]]) + h[0] # cx, cyを仮定するとchが定まる
for i in range(N):
if max([ch - distance(c, [x[i], y[i]]), 0]) != h[i]:
ans = False
break
if ans:
break
if ans:
break
print((" ".join(list(map(str, [cx, cy, ch])))))
|
# coding: utf-8
# https://atcoder.jp/contests/abc112
def main():
N = int(eval(input()))
x, y, h = [None] * N, [None] * N, [None] * N
for i in range(N):
x[i], y[i], h[i] = list(map(int, input().split()))
for cx in range(0, 101):
for cy in range(0, 101):
first = True
notans = False
for i in range(N):
# print(cx, cy, i)
if h[i] > 0:
H = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
if first:
first = False
pre_H = H
else:
if H != pre_H:
break
if H == pre_H:
for i in range(N):
if h[i] == 0:
if H - abs(x[i]-cx) - abs(y[i]-cy) > 0:
notans = True
break
if notans:
continue
print((cx, cy, H))
return None
main()
# print(main())
| 38 | 43 | 854 | 1,108 |
# -*- coding: utf-8 -*-
N = int(eval(input()))
x = [None] * N
y = [None] * N
h = [None] * N
for i in range(N):
x[i], y[i], h[i] = list(map(int, input().split()))
def distance(a, b):
a_x = a[0]
a_y = a[1]
b_x = b[0]
b_y = b[1]
return abs(a_x - b_x) + abs(a_y - b_y)
for cx in range(101):
for cy in range(101):
ans = True
c = [cx, cy]
for i in range(N):
if h[i] != 0:
ch = distance(c, [x[i], y[i]]) + h[i]
break
# ch = distance(c, [x[0], y[0]]) + h[0] # cx, cyを仮定するとchが定まる
for i in range(N):
if max([ch - distance(c, [x[i], y[i]]), 0]) != h[i]:
ans = False
break
if ans:
break
if ans:
break
print((" ".join(list(map(str, [cx, cy, ch])))))
|
# coding: utf-8
# https://atcoder.jp/contests/abc112
def main():
N = int(eval(input()))
x, y, h = [None] * N, [None] * N, [None] * N
for i in range(N):
x[i], y[i], h[i] = list(map(int, input().split()))
for cx in range(0, 101):
for cy in range(0, 101):
first = True
notans = False
for i in range(N):
# print(cx, cy, i)
if h[i] > 0:
H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
if first:
first = False
pre_H = H
else:
if H != pre_H:
break
if H == pre_H:
for i in range(N):
if h[i] == 0:
if H - abs(x[i] - cx) - abs(y[i] - cy) > 0:
notans = True
break
if notans:
continue
print((cx, cy, H))
return None
main()
# print(main())
| false | 11.627907 |
[
"-# -*- coding: utf-8 -*-",
"-N = int(eval(input()))",
"-x = [None] * N",
"-y = [None] * N",
"-h = [None] * N",
"-for i in range(N):",
"- x[i], y[i], h[i] = list(map(int, input().split()))",
"+# coding: utf-8",
"+# https://atcoder.jp/contests/abc112",
"+def main():",
"+ N = int(eval(input()))",
"+ x, y, h = [None] * N, [None] * N, [None] * N",
"+ for i in range(N):",
"+ x[i], y[i], h[i] = list(map(int, input().split()))",
"+ for cx in range(0, 101):",
"+ for cy in range(0, 101):",
"+ first = True",
"+ notans = False",
"+ for i in range(N):",
"+ # print(cx, cy, i)",
"+ if h[i] > 0:",
"+ H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)",
"+ if first:",
"+ first = False",
"+ pre_H = H",
"+ else:",
"+ if H != pre_H:",
"+ break",
"+ if H == pre_H:",
"+ for i in range(N):",
"+ if h[i] == 0:",
"+ if H - abs(x[i] - cx) - abs(y[i] - cy) > 0:",
"+ notans = True",
"+ break",
"+ if notans:",
"+ continue",
"+ print((cx, cy, H))",
"+ return None",
"-def distance(a, b):",
"- a_x = a[0]",
"- a_y = a[1]",
"- b_x = b[0]",
"- b_y = b[1]",
"- return abs(a_x - b_x) + abs(a_y - b_y)",
"-",
"-",
"-for cx in range(101):",
"- for cy in range(101):",
"- ans = True",
"- c = [cx, cy]",
"- for i in range(N):",
"- if h[i] != 0:",
"- ch = distance(c, [x[i], y[i]]) + h[i]",
"- break",
"- # ch = distance(c, [x[0], y[0]]) + h[0] # cx, cyを仮定するとchが定まる",
"- for i in range(N):",
"- if max([ch - distance(c, [x[i], y[i]]), 0]) != h[i]:",
"- ans = False",
"- break",
"- if ans:",
"- break",
"- if ans:",
"- break",
"-print((\" \".join(list(map(str, [cx, cy, ch])))))",
"+main()",
"+# print(main())"
] | false | 0.061734 | 0.046839 | 1.318018 |
[
"s411810053",
"s025371384"
] |
u773265208
|
p02897
|
python
|
s400413403
|
s654309131
| 182 | 17 | 38,384 | 2,940 |
Accepted
|
Accepted
| 90.66 |
n = int(eval(input()))
if n % 2 == 0:
print((0.5))
else:
print(((n//2 + 1 )/ n))
|
n=int(eval(input()))
if n % 2 == 0:
print((0.5))
else:
print((1-(n//2)/n))
| 6 | 6 | 79 | 73 |
n = int(eval(input()))
if n % 2 == 0:
print((0.5))
else:
print(((n // 2 + 1) / n))
|
n = int(eval(input()))
if n % 2 == 0:
print((0.5))
else:
print((1 - (n // 2) / n))
| false | 0 |
[
"- print(((n // 2 + 1) / n))",
"+ print((1 - (n // 2) / n))"
] | false | 0.03479 | 0.061949 | 0.561592 |
[
"s400413403",
"s654309131"
] |
u729133443
|
p03161
|
python
|
s574004608
|
s556543468
| 1,857 | 604 | 13,876 | 59,948 |
Accepted
|
Accepted
| 67.47 |
if __name__=='__main__':
n,k,*h=list(map(int,open(0).read().split()))
dp=[0]
for i,t in enumerate(h):
if i:
j=max(0,i-k)
dp.append(min(v+abs(t-w)for v,w in zip(dp[j:i],h[j:i])))
print((dp[-1]))
|
n,k,*h=list(map(int,open(0).read().split()));d=[0]*n
for i in range(1,n):j=max(0,i-k);d[i]=(min(v+abs(h[i]-w)for v,w in zip(d[j:i],h[j:i])))
print((d[-1]))
| 8 | 3 | 240 | 149 |
if __name__ == "__main__":
n, k, *h = list(map(int, open(0).read().split()))
dp = [0]
for i, t in enumerate(h):
if i:
j = max(0, i - k)
dp.append(min(v + abs(t - w) for v, w in zip(dp[j:i], h[j:i])))
print((dp[-1]))
|
n, k, *h = list(map(int, open(0).read().split()))
d = [0] * n
for i in range(1, n):
j = max(0, i - k)
d[i] = min(v + abs(h[i] - w) for v, w in zip(d[j:i], h[j:i]))
print((d[-1]))
| false | 62.5 |
[
"-if __name__ == \"__main__\":",
"- n, k, *h = list(map(int, open(0).read().split()))",
"- dp = [0]",
"- for i, t in enumerate(h):",
"- if i:",
"- j = max(0, i - k)",
"- dp.append(min(v + abs(t - w) for v, w in zip(dp[j:i], h[j:i])))",
"- print((dp[-1]))",
"+n, k, *h = list(map(int, open(0).read().split()))",
"+d = [0] * n",
"+for i in range(1, n):",
"+ j = max(0, i - k)",
"+ d[i] = min(v + abs(h[i] - w) for v, w in zip(d[j:i], h[j:i]))",
"+print((d[-1]))"
] | false | 0.187495 | 0.042368 | 4.425438 |
[
"s574004608",
"s556543468"
] |
u958958520
|
p03479
|
python
|
s790336202
|
s130437535
| 29 | 26 | 8,964 | 9,160 |
Accepted
|
Accepted
| 10.34 |
X, Y = list(map(int, input().split()))
ans = 0
math = X
while(math <= Y):
ans += 1
math = math * 2
print(ans)
|
X, Y = list(map(int, input().split()))
ans = []
num = X
while(num <= Y):
ans.append(num)
num *= 2
print((len(ans)))
| 9 | 9 | 123 | 128 |
X, Y = list(map(int, input().split()))
ans = 0
math = X
while math <= Y:
ans += 1
math = math * 2
print(ans)
|
X, Y = list(map(int, input().split()))
ans = []
num = X
while num <= Y:
ans.append(num)
num *= 2
print((len(ans)))
| false | 0 |
[
"-ans = 0",
"-math = X",
"-while math <= Y:",
"- ans += 1",
"- math = math * 2",
"-print(ans)",
"+ans = []",
"+num = X",
"+while num <= Y:",
"+ ans.append(num)",
"+ num *= 2",
"+print((len(ans)))"
] | false | 0.113474 | 0.064133 | 1.769358 |
[
"s790336202",
"s130437535"
] |
u324197506
|
p02691
|
python
|
s279256842
|
s804344221
| 570 | 527 | 87,412 | 87,488 |
Accepted
|
Accepted
| 7.54 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
heights = list(map(int, input().split()))
cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}
for ind in range(N):
height = heights[ind]
if ind - height not in cnt_ind_minus_height:
cnt_ind_minus_height[ind - height] = 0
cnt_ind_minus_height[ind - height] += 1
if ind + height not in cnt_height_plus_ind:
cnt_height_plus_ind[ind + height] = 0
cnt_height_plus_ind[ind + height] += 1
if height - ind not in cnt_height_minus_ind:
cnt_height_minus_ind[height - ind] = 0
cnt_height_minus_ind[height - ind] += 1
if - ind - height not in cnt_minus_height_minus_ind:
cnt_minus_height_minus_ind[-ind-height] = 0
cnt_minus_height_minus_ind[-ind-height] += 1
ans = 0
for val in cnt_height_minus_ind:
if val in cnt_minus_height_minus_ind:
ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]
for val in cnt_height_plus_ind:
if val in cnt_ind_minus_height:
ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]
print((ans//2))
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
heights = list(map(int, input().split()))
cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}
for ind in range(N):
height = heights[ind]
if ind - height not in cnt_ind_minus_height:
cnt_ind_minus_height[ind - height] = 0
cnt_ind_minus_height[ind - height] += 1
if ind + height not in cnt_height_plus_ind:
cnt_height_plus_ind[ind + height] = 0
cnt_height_plus_ind[ind + height] += 1
if height - ind not in cnt_height_minus_ind:
cnt_height_minus_ind[height - ind] = 0
cnt_height_minus_ind[height - ind] += 1
if - ind - height not in cnt_minus_height_minus_ind:
cnt_minus_height_minus_ind[-ind-height] = 0
cnt_minus_height_minus_ind[-ind-height] += 1
ans = 0
#for val in cnt_height_minus_ind:
# if val in cnt_minus_height_minus_ind:
# ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]
for val in cnt_height_plus_ind:
if val in cnt_ind_minus_height:
ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]
print(ans)
| 43 | 43 | 1,194 | 1,194 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
heights = list(map(int, input().split()))
cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}
for ind in range(N):
height = heights[ind]
if ind - height not in cnt_ind_minus_height:
cnt_ind_minus_height[ind - height] = 0
cnt_ind_minus_height[ind - height] += 1
if ind + height not in cnt_height_plus_ind:
cnt_height_plus_ind[ind + height] = 0
cnt_height_plus_ind[ind + height] += 1
if height - ind not in cnt_height_minus_ind:
cnt_height_minus_ind[height - ind] = 0
cnt_height_minus_ind[height - ind] += 1
if -ind - height not in cnt_minus_height_minus_ind:
cnt_minus_height_minus_ind[-ind - height] = 0
cnt_minus_height_minus_ind[-ind - height] += 1
ans = 0
for val in cnt_height_minus_ind:
if val in cnt_minus_height_minus_ind:
ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]
for val in cnt_height_plus_ind:
if val in cnt_ind_minus_height:
ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]
print((ans // 2))
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
heights = list(map(int, input().split()))
cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}
for ind in range(N):
height = heights[ind]
if ind - height not in cnt_ind_minus_height:
cnt_ind_minus_height[ind - height] = 0
cnt_ind_minus_height[ind - height] += 1
if ind + height not in cnt_height_plus_ind:
cnt_height_plus_ind[ind + height] = 0
cnt_height_plus_ind[ind + height] += 1
if height - ind not in cnt_height_minus_ind:
cnt_height_minus_ind[height - ind] = 0
cnt_height_minus_ind[height - ind] += 1
if -ind - height not in cnt_minus_height_minus_ind:
cnt_minus_height_minus_ind[-ind - height] = 0
cnt_minus_height_minus_ind[-ind - height] += 1
ans = 0
# for val in cnt_height_minus_ind:
# if val in cnt_minus_height_minus_ind:
# ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]
for val in cnt_height_plus_ind:
if val in cnt_ind_minus_height:
ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]
print(ans)
| false | 0 |
[
"-for val in cnt_height_minus_ind:",
"- if val in cnt_minus_height_minus_ind:",
"- ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]",
"+# for val in cnt_height_minus_ind:",
"+# if val in cnt_minus_height_minus_ind:",
"+# ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]",
"-print((ans // 2))",
"+print(ans)"
] | false | 0.04828 | 0.078406 | 0.615771 |
[
"s279256842",
"s804344221"
] |
u493813116
|
p03805
|
python
|
s321675358
|
s422744145
| 37 | 19 | 3,064 | 3,064 |
Accepted
|
Accepted
| 48.65 |
N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
dp = {}
for _ in range(M):
a, b = list(map(int, input().split()))
E[a-1].append(b-1)
E[b-1].append(a-1)
S = 1
G = (1 << N) - 1
def is_visited(v: int, path: int):
return path & (1 << v)
def visit(v: int, path: int):
return path ^ (1 << v)
def count(u: int, path: int):
if path == G:
return 1
if (u, path) in dp:
return dp[(u, path)]
return sum(
count(v, visit(v, path))
for v in E[u]
if not is_visited(v, path)
)
print((count(0, S)))
|
N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
dp = {}
for _ in range(M):
a, b = list(map(int, input().split()))
E[a-1].append(b-1)
E[b-1].append(a-1)
S = 1
G = (1 << N) - 1
def is_visited(v: int, path: int):
return path & (1 << v)
def visit(v: int, path: int):
return path ^ (1 << v)
def count(u: int, path: int):
if path == G:
return 1
k = (u, path)
if k in dp:
return dp[k]
s = sum(
count(v, visit(v, path))
for v in E[u]
if not is_visited(v, path)
)
dp[k] = s
return s
print((count(0, S)))
| 36 | 39 | 608 | 637 |
N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
dp = {}
for _ in range(M):
a, b = list(map(int, input().split()))
E[a - 1].append(b - 1)
E[b - 1].append(a - 1)
S = 1
G = (1 << N) - 1
def is_visited(v: int, path: int):
return path & (1 << v)
def visit(v: int, path: int):
return path ^ (1 << v)
def count(u: int, path: int):
if path == G:
return 1
if (u, path) in dp:
return dp[(u, path)]
return sum(count(v, visit(v, path)) for v in E[u] if not is_visited(v, path))
print((count(0, S)))
|
N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
dp = {}
for _ in range(M):
a, b = list(map(int, input().split()))
E[a - 1].append(b - 1)
E[b - 1].append(a - 1)
S = 1
G = (1 << N) - 1
def is_visited(v: int, path: int):
return path & (1 << v)
def visit(v: int, path: int):
return path ^ (1 << v)
def count(u: int, path: int):
if path == G:
return 1
k = (u, path)
if k in dp:
return dp[k]
s = sum(count(v, visit(v, path)) for v in E[u] if not is_visited(v, path))
dp[k] = s
return s
print((count(0, S)))
| false | 7.692308 |
[
"- if (u, path) in dp:",
"- return dp[(u, path)]",
"- return sum(count(v, visit(v, path)) for v in E[u] if not is_visited(v, path))",
"+ k = (u, path)",
"+ if k in dp:",
"+ return dp[k]",
"+ s = sum(count(v, visit(v, path)) for v in E[u] if not is_visited(v, path))",
"+ dp[k] = s",
"+ return s"
] | false | 0.088672 | 0.062157 | 1.426571 |
[
"s321675358",
"s422744145"
] |
u445624660
|
p02866
|
python
|
s803534661
|
s428312164
| 247 | 191 | 68,140 | 23,752 |
Accepted
|
Accepted
| 22.67 |
# 最初dは与えられる距離だと思ってて「サンプルケース1は3じゃね?」とか思ってて2時間経過した
# 落ち着いて読んだら最小の辺の数だった
from collections import Counter
n = int(eval(input()))
arr = list(map(int, input().split()))
if arr[0] != 0:
print((0))
exit()
arr = sorted(list(Counter(arr).items()), key=lambda x: x[0])
if arr[0][1] > 1:
print((0))
exit()
mod = 998244353
ans = 1
tmp = 1
for i in range(1, len(arr)):
if arr[i][0] != i:
print((0))
exit()
ans *= pow(tmp, arr[i][1])
ans %= mod
tmp = arr[i][1]
print(ans)
|
n = int(eval(input()))
d = {}
mod = 998244353
max_v = 0
lis = list(map(int, input().split()))
# 先頭はかならず0
if lis[0] != 0:
print((0))
exit()
for v in lis:
if v not in d:
d[v] = 1
else:
d[v] += 1
max_v = max(max_v, v)
# 0はひとつだけ
if 0 not in d or d[0] > 1:
print((0))
exit()
ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
if i not in d or i - 1 not in d:
ans *= 0
else:
ans *= pow(d[i - 1], d[i], mod)
ans %= mod
print(ans)
| 27 | 32 | 523 | 551 |
# 最初dは与えられる距離だと思ってて「サンプルケース1は3じゃね?」とか思ってて2時間経過した
# 落ち着いて読んだら最小の辺の数だった
from collections import Counter
n = int(eval(input()))
arr = list(map(int, input().split()))
if arr[0] != 0:
print((0))
exit()
arr = sorted(list(Counter(arr).items()), key=lambda x: x[0])
if arr[0][1] > 1:
print((0))
exit()
mod = 998244353
ans = 1
tmp = 1
for i in range(1, len(arr)):
if arr[i][0] != i:
print((0))
exit()
ans *= pow(tmp, arr[i][1])
ans %= mod
tmp = arr[i][1]
print(ans)
|
n = int(eval(input()))
d = {}
mod = 998244353
max_v = 0
lis = list(map(int, input().split()))
# 先頭はかならず0
if lis[0] != 0:
print((0))
exit()
for v in lis:
if v not in d:
d[v] = 1
else:
d[v] += 1
max_v = max(max_v, v)
# 0はひとつだけ
if 0 not in d or d[0] > 1:
print((0))
exit()
ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
if i not in d or i - 1 not in d:
ans *= 0
else:
ans *= pow(d[i - 1], d[i], mod)
ans %= mod
print(ans)
| false | 15.625 |
[
"-# 最初dは与えられる距離だと思ってて「サンプルケース1は3じゃね?」とか思ってて2時間経過した",
"-# 落ち着いて読んだら最小の辺の数だった",
"-from collections import Counter",
"-",
"-arr = list(map(int, input().split()))",
"-if arr[0] != 0:",
"+d = {}",
"+mod = 998244353",
"+max_v = 0",
"+lis = list(map(int, input().split()))",
"+# 先頭はかならず0",
"+if lis[0] != 0:",
"-arr = sorted(list(Counter(arr).items()), key=lambda x: x[0])",
"-if arr[0][1] > 1:",
"+for v in lis:",
"+ if v not in d:",
"+ d[v] = 1",
"+ else:",
"+ d[v] += 1",
"+ max_v = max(max_v, v)",
"+# 0はひとつだけ",
"+if 0 not in d or d[0] > 1:",
"-mod = 998244353",
"-tmp = 1",
"-for i in range(1, len(arr)):",
"- if arr[i][0] != i:",
"- print((0))",
"- exit()",
"- ans *= pow(tmp, arr[i][1])",
"- ans %= mod",
"- tmp = arr[i][1]",
"+# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する",
"+for i in range(1, max_v + 1):",
"+ if i not in d or i - 1 not in d:",
"+ ans *= 0",
"+ else:",
"+ ans *= pow(d[i - 1], d[i], mod)",
"+ ans %= mod"
] | false | 0.042954 | 0.042788 | 1.003899 |
[
"s803534661",
"s428312164"
] |
u102461423
|
p02624
|
python
|
s049861616
|
s276421978
| 548 | 206 | 106,232 | 27,408 |
Accepted
|
Accepted
| 62.41 |
import sys
import numba
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@numba.njit('(i8,)', cache=True)
def main(N):
x = 0
for a in range(1, N+1):
for b in range(1, N//a+1):
x += a*b
return x
N = int(read())
print((main(N)))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(N):
x = 0
for a in range(1, N+1):
for b in range(a, N+1, a):
x += b
return x
if sys.argv[-1] == 'ONLINE_JUDGE':
import numba
from numba.pycc import CC
i8 = numba.int64
cc = CC('my_module')
def cc_export(f, signature):
cc.export(f.__name__, signature)(f)
return numba.njit(f)
main = cc_export(main, (i8, ))
cc.compile()
from my_module import main
N = int(read())
print((main(N)))
| 17 | 30 | 332 | 614 |
import sys
import numba
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@numba.njit("(i8,)", cache=True)
def main(N):
x = 0
for a in range(1, N + 1):
for b in range(1, N // a + 1):
x += a * b
return x
N = int(read())
print((main(N)))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(N):
x = 0
for a in range(1, N + 1):
for b in range(a, N + 1, a):
x += b
return x
if sys.argv[-1] == "ONLINE_JUDGE":
import numba
from numba.pycc import CC
i8 = numba.int64
cc = CC("my_module")
def cc_export(f, signature):
cc.export(f.__name__, signature)(f)
return numba.njit(f)
main = cc_export(main, (i8,))
cc.compile()
from my_module import main
N = int(read())
print((main(N)))
| false | 43.333333 |
[
"-import numba",
"[email protected](\"(i8,)\", cache=True)",
"- for b in range(1, N // a + 1):",
"- x += a * b",
"+ for b in range(a, N + 1, a):",
"+ x += b",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ import numba",
"+ from numba.pycc import CC",
"+",
"+ i8 = numba.int64",
"+ cc = CC(\"my_module\")",
"+",
"+ def cc_export(f, signature):",
"+ cc.export(f.__name__, signature)(f)",
"+ return numba.njit(f)",
"+",
"+ main = cc_export(main, (i8,))",
"+ cc.compile()",
"+from my_module import main",
"+"
] | false | 0.035117 | 0.035271 | 0.995643 |
[
"s049861616",
"s276421978"
] |
u952708174
|
p03031
|
python
|
s661237064
|
s880612924
| 266 | 153 | 17,712 | 12,260 |
Accepted
|
Accepted
| 42.48 |
def c_switches(N, M, Switches, P):
import numpy as np
def rank_matrix(matrix):
"""mod2 上で行列の階数を求める"""
num_row, num_col = matrix.shape[0], matrix.shape[1]
rank = 0
for col in range(num_col):
# ピボット探し
pivot = -1
max_element = 0 # 最大の要素(1しかないが)がある場所を探す
for row in range(rank, num_row):
if matrix[row][col] > max_element:
max_element = matrix[row][col]
pivot = row
if pivot == -1:
continue # ピボットが見つからない。次の列へ
tmp = matrix[pivot, :].copy()
matrix[pivot, :] = matrix[rank, :]
matrix[rank, :] = tmp
# (行列の要素は0または1しかないので、ピボットの値を1にする操作は不要)
# ピボットのある列の値がすべて0となるように、掃き出しを行う
for row in range(num_row):
if row != rank and matrix[row][col] == 1:
for col2 in range(num_col):
matrix[row][col2] = (matrix[row][col2] + matrix[rank][col2]) % 2
rank += 1
return rank
# 電球iがスイッチjとつながっているとき a_{ij}=1, そうでないなら0とする
a = np.zeros((M, N), dtype='int8')
for t, (_, *switches) in enumerate(Switches):
for s in switches:
a[t][s - 1] = 1
p = np.reshape(P, (-1, 1))
ap = np.concatenate((a, p), axis=1) # 拡大係数行列
rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
return 2**(N - rank_a) if rank_a == rank_ap else 0
# 参考: http://drken1215.hatenablog.com/entry/2019/03/20/202800
N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print((c_switches(N, M, Switches, P)))
|
def c_switches(N, M, Switches, P):
import numpy as np
def rank_matrix(matrix):
"""mod2 上で行列の階数を求める"""
num_row, num_col = matrix.shape[0], matrix.shape[1]
rank = 0
for col in range(num_col):
# ピボット探し
pivot = -1
max_element = 0 # 最大の要素(1しかないが)がある場所を探す
for row in range(rank, num_row):
if matrix[row][col] > max_element:
max_element = matrix[row][col]
pivot = row
if pivot == -1:
continue # ピボットが見つからない。次の列へ
tmp = matrix[pivot, :].copy()
matrix[pivot, :] = matrix[rank, :]
matrix[rank, :] = tmp
# (行列の要素は0または1しかないので、ピボットの値を1にする操作は不要)
# ピボットのある列の値がすべて0となるように、掃き出しを行う
for row in range(num_row):
if row != rank and matrix[row][col] == 1:
for col2 in range(num_col):
matrix[row][col2] = (matrix[row][col2] - matrix[rank][col2]) % 2
rank += 1
return rank
# 電球iがスイッチjとつながっているとき a_{ij}=1, そうでないなら0とする
a = np.zeros((M, N), dtype='int8')
for t, (_, *switches) in enumerate(Switches):
for s in switches:
a[t][s - 1] = 1
p = np.reshape(P, (-1, 1))
ap = np.concatenate((a, p), axis=1) # 拡大係数行列
rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
return 2**(N - rank_a) if rank_a == rank_ap else 0
# 参考: http://drken1215.hatenablog.com/entry/2019/03/20/202800
N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print((c_switches(N, M, Switches, P)))
| 47 | 47 | 1,753 | 1,753 |
def c_switches(N, M, Switches, P):
import numpy as np
def rank_matrix(matrix):
"""mod2 上で行列の階数を求める"""
num_row, num_col = matrix.shape[0], matrix.shape[1]
rank = 0
for col in range(num_col):
# ピボット探し
pivot = -1
max_element = 0 # 最大の要素(1しかないが)がある場所を探す
for row in range(rank, num_row):
if matrix[row][col] > max_element:
max_element = matrix[row][col]
pivot = row
if pivot == -1:
continue # ピボットが見つからない。次の列へ
tmp = matrix[pivot, :].copy()
matrix[pivot, :] = matrix[rank, :]
matrix[rank, :] = tmp
# (行列の要素は0または1しかないので、ピボットの値を1にする操作は不要)
# ピボットのある列の値がすべて0となるように、掃き出しを行う
for row in range(num_row):
if row != rank and matrix[row][col] == 1:
for col2 in range(num_col):
matrix[row][col2] = (matrix[row][col2] + matrix[rank][col2]) % 2
rank += 1
return rank
# 電球iがスイッチjとつながっているとき a_{ij}=1, そうでないなら0とする
a = np.zeros((M, N), dtype="int8")
for t, (_, *switches) in enumerate(Switches):
for s in switches:
a[t][s - 1] = 1
p = np.reshape(P, (-1, 1))
ap = np.concatenate((a, p), axis=1) # 拡大係数行列
rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
return 2 ** (N - rank_a) if rank_a == rank_ap else 0
# 参考: http://drken1215.hatenablog.com/entry/2019/03/20/202800
N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print((c_switches(N, M, Switches, P)))
|
def c_switches(N, M, Switches, P):
import numpy as np
def rank_matrix(matrix):
"""mod2 上で行列の階数を求める"""
num_row, num_col = matrix.shape[0], matrix.shape[1]
rank = 0
for col in range(num_col):
# ピボット探し
pivot = -1
max_element = 0 # 最大の要素(1しかないが)がある場所を探す
for row in range(rank, num_row):
if matrix[row][col] > max_element:
max_element = matrix[row][col]
pivot = row
if pivot == -1:
continue # ピボットが見つからない。次の列へ
tmp = matrix[pivot, :].copy()
matrix[pivot, :] = matrix[rank, :]
matrix[rank, :] = tmp
# (行列の要素は0または1しかないので、ピボットの値を1にする操作は不要)
# ピボットのある列の値がすべて0となるように、掃き出しを行う
for row in range(num_row):
if row != rank and matrix[row][col] == 1:
for col2 in range(num_col):
matrix[row][col2] = (matrix[row][col2] - matrix[rank][col2]) % 2
rank += 1
return rank
# 電球iがスイッチjとつながっているとき a_{ij}=1, そうでないなら0とする
a = np.zeros((M, N), dtype="int8")
for t, (_, *switches) in enumerate(Switches):
for s in switches:
a[t][s - 1] = 1
p = np.reshape(P, (-1, 1))
ap = np.concatenate((a, p), axis=1) # 拡大係数行列
rank_a, rank_ap = rank_matrix(a), rank_matrix(ap)
return 2 ** (N - rank_a) if rank_a == rank_ap else 0
# 参考: http://drken1215.hatenablog.com/entry/2019/03/20/202800
N, M = [int(i) for i in input().split()]
Switches = [[int(i) for i in input().split()] for j in range(M)]
P = [int(i) for i in input().split()]
print((c_switches(N, M, Switches, P)))
| false | 0 |
[
"- matrix[row][col2] = (matrix[row][col2] + matrix[rank][col2]) % 2",
"+ matrix[row][col2] = (matrix[row][col2] - matrix[rank][col2]) % 2"
] | false | 0.280753 | 0.238388 | 1.177714 |
[
"s661237064",
"s880612924"
] |
u550279454
|
p02639
|
python
|
s648791878
|
s060328952
| 20 | 18 | 9,168 | 9,056 |
Accepted
|
Accepted
| 10 |
X_s = list(map(int, input().split()))
for i in range(len(X_s)):
num = X_s[i]
if (num == 0):
print((i + 1))
|
X_s = list(map(int, input().split()))
for i in range(len(X_s)):
num = X_s[i]
if (num == 0):
print((i + 1))
break
| 7 | 8 | 128 | 145 |
X_s = list(map(int, input().split()))
for i in range(len(X_s)):
num = X_s[i]
if num == 0:
print((i + 1))
|
X_s = list(map(int, input().split()))
for i in range(len(X_s)):
num = X_s[i]
if num == 0:
print((i + 1))
break
| false | 12.5 |
[
"+ break"
] | false | 0.037222 | 0.041422 | 0.898619 |
[
"s648791878",
"s060328952"
] |
u408260374
|
p00775
|
python
|
s583633292
|
s654109422
| 140 | 110 | 7,652 | 7,684 |
Accepted
|
Accepted
| 21.43 |
while True:
R, N = list(map(int, input().split()))
if not (R | N):
break
geta = 20
buildings = [0] * (geta * 2)
for _ in range(N):
xl, xr, h = list(map(int, input().split()))
for i in range(xl + geta, xr + geta):
buildings[i] = max(buildings[i], h)
left, right = 0, 20
while right - left > 1e-4:
mid = (left + right) / 2
flag = True
for i in range(-R + geta, R + geta):
if i < geta:
y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5)
flag &= buildings[i] >= y - R + mid
else:
y = pow(R * R - (i - geta) * (i - geta), 0.5)
flag &= buildings[i] >= y - R + mid
if flag:
left = mid
else:
right = mid
print(("{:.20f}".format(left)))
|
while True:
R, N = list(map(int, input().split()))
if not (R | N):
break
geta = 20
buildings = [0] * (geta * 2)
for _ in range(N):
xl, xr, h = list(map(int, input().split()))
for i in range(xl + geta, xr + geta):
buildings[i] = max(buildings[i], h)
sun = [0] * (geta * 2)
for i in range(-R + geta, R + geta):
if i < geta:
buildings[i] -= pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) - R
else:
buildings[i] -= pow(R * R - (i - geta) * (i - geta), 0.5) - R
left, right = 0, 20
while right - left > 1e-4:
mid = (left + right) / 2
flag = True
for i in range(-R + geta, R + geta):
if i < geta:
flag &= buildings[i] >= mid
else:
y = pow(R * R - (i - geta) * (i - geta), 0.5)
flag &= buildings[i] >= mid
if flag:
left = mid
else:
right = mid
print(("{:.20f}".format(left)))
| 27 | 34 | 863 | 1,045 |
while True:
R, N = list(map(int, input().split()))
if not (R | N):
break
geta = 20
buildings = [0] * (geta * 2)
for _ in range(N):
xl, xr, h = list(map(int, input().split()))
for i in range(xl + geta, xr + geta):
buildings[i] = max(buildings[i], h)
left, right = 0, 20
while right - left > 1e-4:
mid = (left + right) / 2
flag = True
for i in range(-R + geta, R + geta):
if i < geta:
y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5)
flag &= buildings[i] >= y - R + mid
else:
y = pow(R * R - (i - geta) * (i - geta), 0.5)
flag &= buildings[i] >= y - R + mid
if flag:
left = mid
else:
right = mid
print(("{:.20f}".format(left)))
|
while True:
R, N = list(map(int, input().split()))
if not (R | N):
break
geta = 20
buildings = [0] * (geta * 2)
for _ in range(N):
xl, xr, h = list(map(int, input().split()))
for i in range(xl + geta, xr + geta):
buildings[i] = max(buildings[i], h)
sun = [0] * (geta * 2)
for i in range(-R + geta, R + geta):
if i < geta:
buildings[i] -= pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) - R
else:
buildings[i] -= pow(R * R - (i - geta) * (i - geta), 0.5) - R
left, right = 0, 20
while right - left > 1e-4:
mid = (left + right) / 2
flag = True
for i in range(-R + geta, R + geta):
if i < geta:
flag &= buildings[i] >= mid
else:
y = pow(R * R - (i - geta) * (i - geta), 0.5)
flag &= buildings[i] >= mid
if flag:
left = mid
else:
right = mid
print(("{:.20f}".format(left)))
| false | 20.588235 |
[
"+ sun = [0] * (geta * 2)",
"+ for i in range(-R + geta, R + geta):",
"+ if i < geta:",
"+ buildings[i] -= pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5) - R",
"+ else:",
"+ buildings[i] -= pow(R * R - (i - geta) * (i - geta), 0.5) - R",
"- y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5)",
"- flag &= buildings[i] >= y - R + mid",
"+ flag &= buildings[i] >= mid",
"- flag &= buildings[i] >= y - R + mid",
"+ flag &= buildings[i] >= mid"
] | false | 0.037329 | 0.048113 | 0.775875 |
[
"s583633292",
"s654109422"
] |
u150984829
|
p00056
|
python
|
s097378185
|
s849602268
| 1,760 | 1,440 | 7,800 | 8,448 |
Accepted
|
Accepted
| 18.18 |
from bisect import *
from itertools import *
n=list(range(50001));a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print((sum(1 for d in p[:bisect(p,x//2)]if a[x-d])))
|
import bisect,sys
from itertools import *
n=list(range(50001));a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in sys.stdin:
x=int(x)
if x:print((sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d])))
| 6 | 8 | 240 | 248 |
from bisect import *
from itertools import *
n = list(range(50001))
a = list(n)
a[1] = 0
for i in range(2, 224):
a[i * 2 :: i] = [0] * len(a[i * 2 :: i])
p = list(compress(n, a))
for x in iter(input, "0"):
x = int(x)
print((sum(1 for d in p[: bisect(p, x // 2)] if a[x - d])))
|
import bisect, sys
from itertools import *
n = list(range(50001))
a = list(n)
a[1] = 0
for i in range(2, 224):
a[i * 2 :: i] = [0] * len(a[i * 2 :: i])
p = list(compress(n, a))
for x in sys.stdin:
x = int(x)
if x:
print((sum(1 for d in p[: bisect.bisect(p, x // 2)] if a[x - d])))
| false | 25 |
[
"-from bisect import *",
"+import bisect, sys",
"-for x in iter(input, \"0\"):",
"+for x in sys.stdin:",
"- print((sum(1 for d in p[: bisect(p, x // 2)] if a[x - d])))",
"+ if x:",
"+ print((sum(1 for d in p[: bisect.bisect(p, x // 2)] if a[x - d])))"
] | false | 0.041986 | 0.046947 | 0.894327 |
[
"s097378185",
"s849602268"
] |
u057109575
|
p02713
|
python
|
s599950173
|
s447242683
| 541 | 499 | 67,604 | 68,348 |
Accepted
|
Accepted
| 7.76 |
from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(i, gcd(k, j))
print(ans)
|
from math import gcd
K = int(eval(input()))
ans = 0
for a in range(1, K + 1):
for b in range(1, K + 1):
for c in range(1, K + 1):
ans += gcd(gcd(a, b), c)
print(ans)
| 9 | 12 | 192 | 199 |
from math import gcd
K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(i, gcd(k, j))
print(ans)
|
from math import gcd
K = int(eval(input()))
ans = 0
for a in range(1, K + 1):
for b in range(1, K + 1):
for c in range(1, K + 1):
ans += gcd(gcd(a, b), c)
print(ans)
| false | 25 |
[
"-for i in range(1, K + 1):",
"- for j in range(1, K + 1):",
"- for k in range(1, K + 1):",
"- ans += gcd(i, gcd(k, j))",
"+for a in range(1, K + 1):",
"+ for b in range(1, K + 1):",
"+ for c in range(1, K + 1):",
"+ ans += gcd(gcd(a, b), c)"
] | false | 0.049676 | 0.051433 | 0.965832 |
[
"s599950173",
"s447242683"
] |
u009961299
|
p02388
|
python
|
s524871965
|
s719235032
| 30 | 20 | 6,720 | 5,576 |
Accepted
|
Accepted
| 33.33 |
print((eval(eval(input())) ** 3))
|
x = int(eval(input()))
print(("%d" % (x ** 3)))
| 1 | 3 | 25 | 43 |
print((eval(eval(input())) ** 3))
|
x = int(eval(input()))
print(("%d" % (x**3)))
| false | 66.666667 |
[
"-print((eval(eval(input())) ** 3))",
"+x = int(eval(input()))",
"+print((\"%d\" % (x**3)))"
] | false | 0.043186 | 0.0423 | 1.020947 |
[
"s524871965",
"s719235032"
] |
u818349438
|
p02947
|
python
|
s640453500
|
s465343935
| 528 | 347 | 47,988 | 25,020 |
Accepted
|
Accepted
| 34.28 |
import numpy as np
n =int(eval(input()))
strl = [list(eval(input())) for i in range(n)]
count =0
pt = {}
for i in range(n):
sal = strl[i]
sal.sort()
temp = "".join(sal)
if temp in list(pt.keys()):
tempc = pt[temp]
count +=tempc
pt[temp]= tempc+1
else:
pt[temp]= 1
print(count)
|
n = int(eval(input()))
s = [eval(input())for _ in range(n)]
cnt = {}
for x in s:
p = list(x)
p.sort()
b = "".join(p)
if "".join(p) not in cnt:cnt[b] = 1
else:cnt[b] +=1
ans = 0
for key in cnt:
v = cnt[key]
ans +=v*(v-1)//2
print(ans)
| 17 | 19 | 327 | 283 |
import numpy as np
n = int(eval(input()))
strl = [list(eval(input())) for i in range(n)]
count = 0
pt = {}
for i in range(n):
sal = strl[i]
sal.sort()
temp = "".join(sal)
if temp in list(pt.keys()):
tempc = pt[temp]
count += tempc
pt[temp] = tempc + 1
else:
pt[temp] = 1
print(count)
|
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
cnt = {}
for x in s:
p = list(x)
p.sort()
b = "".join(p)
if "".join(p) not in cnt:
cnt[b] = 1
else:
cnt[b] += 1
ans = 0
for key in cnt:
v = cnt[key]
ans += v * (v - 1) // 2
print(ans)
| false | 10.526316 |
[
"-import numpy as np",
"-",
"-strl = [list(eval(input())) for i in range(n)]",
"-count = 0",
"-pt = {}",
"-for i in range(n):",
"- sal = strl[i]",
"- sal.sort()",
"- temp = \"\".join(sal)",
"- if temp in list(pt.keys()):",
"- tempc = pt[temp]",
"- count += tempc",
"- pt[temp] = tempc + 1",
"+s = [eval(input()) for _ in range(n)]",
"+cnt = {}",
"+for x in s:",
"+ p = list(x)",
"+ p.sort()",
"+ b = \"\".join(p)",
"+ if \"\".join(p) not in cnt:",
"+ cnt[b] = 1",
"- pt[temp] = 1",
"-print(count)",
"+ cnt[b] += 1",
"+ans = 0",
"+for key in cnt:",
"+ v = cnt[key]",
"+ ans += v * (v - 1) // 2",
"+print(ans)"
] | false | 0.112852 | 0.080714 | 1.398172 |
[
"s640453500",
"s465343935"
] |
u691018832
|
p03062
|
python
|
s591495998
|
s826817084
| 77 | 68 | 15,020 | 12,508 |
Accepted
|
Accepted
| 11.69 |
n = int(eval(input()))
a = list(map(int, input().split()))
b = 0
ans = 0
for i in range(n):
if a[i] < 0:
b += 1
a[i] = abs(a[i])
if (0 in a) or ((b % 2) == 0):
pass
else:
ans -= min(a) * 2
ans += sum(a)
print(ans)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, *a = list(map(int, read().split()))
cnt = 0
for i, aa in enumerate(a):
if aa < 0:
a[i] = -aa
cnt += 1
if cnt % 2 == 0:
print((sum(a)))
else:
print((sum(a) - min(a) * 2))
| 17 | 16 | 262 | 354 |
n = int(eval(input()))
a = list(map(int, input().split()))
b = 0
ans = 0
for i in range(n):
if a[i] < 0:
b += 1
a[i] = abs(a[i])
if (0 in a) or ((b % 2) == 0):
pass
else:
ans -= min(a) * 2
ans += sum(a)
print(ans)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, *a = list(map(int, read().split()))
cnt = 0
for i, aa in enumerate(a):
if aa < 0:
a[i] = -aa
cnt += 1
if cnt % 2 == 0:
print((sum(a)))
else:
print((sum(a) - min(a) * 2))
| false | 5.882353 |
[
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-b = 0",
"-ans = 0",
"-for i in range(n):",
"- if a[i] < 0:",
"- b += 1",
"- a[i] = abs(a[i])",
"-if (0 in a) or ((b % 2) == 0):",
"- pass",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(10**7)",
"+n, *a = list(map(int, read().split()))",
"+cnt = 0",
"+for i, aa in enumerate(a):",
"+ if aa < 0:",
"+ a[i] = -aa",
"+ cnt += 1",
"+if cnt % 2 == 0:",
"+ print((sum(a)))",
"- ans -= min(a) * 2",
"-ans += sum(a)",
"-print(ans)",
"+ print((sum(a) - min(a) * 2))"
] | false | 0.007726 | 0.070959 | 0.108884 |
[
"s591495998",
"s826817084"
] |
u840310460
|
p02879
|
python
|
s430722503
|
s058536906
| 168 | 17 | 38,384 | 2,940 |
Accepted
|
Accepted
| 89.88 |
A, B = [int(i) for i in input().split()]
if A < 10 and B < 10:
print((A * B))
else:
print((-1))
|
A, B = [int(i) for i in input().split()]
if A <= 9 and B <= 9:
print((A*B))
else:
print((-1))
| 6 | 6 | 101 | 103 |
A, B = [int(i) for i in input().split()]
if A < 10 and B < 10:
print((A * B))
else:
print((-1))
|
A, B = [int(i) for i in input().split()]
if A <= 9 and B <= 9:
print((A * B))
else:
print((-1))
| false | 0 |
[
"-if A < 10 and B < 10:",
"+if A <= 9 and B <= 9:"
] | false | 0.119247 | 0.038844 | 3.069903 |
[
"s430722503",
"s058536906"
] |
u439396449
|
p03495
|
python
|
s081757085
|
s624214339
| 161 | 107 | 25,748 | 32,516 |
Accepted
|
Accepted
| 33.54 |
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [0] * (N + 1)
for i in range(N):
B[A[i]] += 1
B = [x for x in sorted(B, reverse=True) if x > 0]
ans = 0
while len(B) - K > 0:
ans += B.pop()
print(ans)
|
from collections import Counter
from operator import itemgetter
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
c = sorted(list(Counter(A).values()), reverse=True)
print((sum([x for x in c[K:]])))
| 12 | 8 | 248 | 220 |
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [0] * (N + 1)
for i in range(N):
B[A[i]] += 1
B = [x for x in sorted(B, reverse=True) if x > 0]
ans = 0
while len(B) - K > 0:
ans += B.pop()
print(ans)
|
from collections import Counter
from operator import itemgetter
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
c = sorted(list(Counter(A).values()), reverse=True)
print((sum([x for x in c[K:]])))
| false | 33.333333 |
[
"+from collections import Counter",
"+from operator import itemgetter",
"+",
"-B = [0] * (N + 1)",
"-for i in range(N):",
"- B[A[i]] += 1",
"-B = [x for x in sorted(B, reverse=True) if x > 0]",
"-ans = 0",
"-while len(B) - K > 0:",
"- ans += B.pop()",
"-print(ans)",
"+c = sorted(list(Counter(A).values()), reverse=True)",
"+print((sum([x for x in c[K:]])))"
] | false | 0.126795 | 0.048043 | 2.639198 |
[
"s081757085",
"s624214339"
] |
u463655976
|
p03048
|
python
|
s489706478
|
s247301781
| 1,856 | 746 | 3,060 | 2,940 |
Accepted
|
Accepted
| 59.81 |
R, G, B, N = list(map(int, input().split()))
C = sorted([R, G, B], reverse=True)
cnt = 0
for p0 in range(N//C[0]+1):
p0v = p0*C[0]
for p1 in range((N-p0v)//C[1]+1):
p1v = p1*C[1]
if (N - p0v - p1v)%C[2] == 0:
cnt += 1
print(cnt)
|
R, G, B, N = list(map(int, input().split()))
C = sorted([R, G, B], reverse=True)
print((sum((1 for c1 in range(0, N+1, C[0]) for c12 in range(c1, N+1, C[1]) if (N - c12) % C[2] == 0 ))))
| 12 | 5 | 272 | 185 |
R, G, B, N = list(map(int, input().split()))
C = sorted([R, G, B], reverse=True)
cnt = 0
for p0 in range(N // C[0] + 1):
p0v = p0 * C[0]
for p1 in range((N - p0v) // C[1] + 1):
p1v = p1 * C[1]
if (N - p0v - p1v) % C[2] == 0:
cnt += 1
print(cnt)
|
R, G, B, N = list(map(int, input().split()))
C = sorted([R, G, B], reverse=True)
print(
(
sum(
(
1
for c1 in range(0, N + 1, C[0])
for c12 in range(c1, N + 1, C[1])
if (N - c12) % C[2] == 0
)
)
)
)
| false | 58.333333 |
[
"-cnt = 0",
"-for p0 in range(N // C[0] + 1):",
"- p0v = p0 * C[0]",
"- for p1 in range((N - p0v) // C[1] + 1):",
"- p1v = p1 * C[1]",
"- if (N - p0v - p1v) % C[2] == 0:",
"- cnt += 1",
"-print(cnt)",
"+print(",
"+ (",
"+ sum(",
"+ (",
"+ 1",
"+ for c1 in range(0, N + 1, C[0])",
"+ for c12 in range(c1, N + 1, C[1])",
"+ if (N - c12) % C[2] == 0",
"+ )",
"+ )",
"+ )",
"+)"
] | false | 0.045378 | 0.039068 | 1.161526 |
[
"s489706478",
"s247301781"
] |
u716660050
|
p02954
|
python
|
s995329617
|
s909366290
| 110 | 98 | 17,132 | 17,152 |
Accepted
|
Accepted
| 10.91 |
S=eval(input())
l=len(S)
A=[0]*l
c=0
for i in range(l-1):
if S[i]=='R':
c+=1
if S[i+1]=='L'or (i==l-1 and S[-1]=='R'):
if i==l-1 and S[-1]=='R':
c+=1
A[i]+=(c+1)//2
A[i+1]+=c//2
c=0
c=0
for i in range(l-1,0,-1):
if S[i]=='L':
c+=1
if S[i-1]=='R' or (i==0 and S[0]=='L'):
if i==0 and S[0]=='L':
c+=1
A[i]+=(c+1)//2
A[i-1]+=c//2
c=0
print((' '.join(map(str,A))))
|
S=eval(input())+'R'
L=len(S)
RL=0
l,r,f=0,0,0
a=[0]*(L-1)
for i in range(1,L):
if f:r+=1
else:l+=1
if S[i-1:i+1]=='LR':
a[RL-1]=r//2+(l+1)//2
a[RL]=(r+1)//2+l//2
l,r,f=0,0,0
if S[i-1:i+1]=='RL':RL,f=i,1
print((' '.join(map(str,a))))
| 24 | 14 | 495 | 279 |
S = eval(input())
l = len(S)
A = [0] * l
c = 0
for i in range(l - 1):
if S[i] == "R":
c += 1
if S[i + 1] == "L" or (i == l - 1 and S[-1] == "R"):
if i == l - 1 and S[-1] == "R":
c += 1
A[i] += (c + 1) // 2
A[i + 1] += c // 2
c = 0
c = 0
for i in range(l - 1, 0, -1):
if S[i] == "L":
c += 1
if S[i - 1] == "R" or (i == 0 and S[0] == "L"):
if i == 0 and S[0] == "L":
c += 1
A[i] += (c + 1) // 2
A[i - 1] += c // 2
c = 0
print((" ".join(map(str, A))))
|
S = eval(input()) + "R"
L = len(S)
RL = 0
l, r, f = 0, 0, 0
a = [0] * (L - 1)
for i in range(1, L):
if f:
r += 1
else:
l += 1
if S[i - 1 : i + 1] == "LR":
a[RL - 1] = r // 2 + (l + 1) // 2
a[RL] = (r + 1) // 2 + l // 2
l, r, f = 0, 0, 0
if S[i - 1 : i + 1] == "RL":
RL, f = i, 1
print((" ".join(map(str, a))))
| false | 41.666667 |
[
"-S = eval(input())",
"-l = len(S)",
"-A = [0] * l",
"-c = 0",
"-for i in range(l - 1):",
"- if S[i] == \"R\":",
"- c += 1",
"- if S[i + 1] == \"L\" or (i == l - 1 and S[-1] == \"R\"):",
"- if i == l - 1 and S[-1] == \"R\":",
"- c += 1",
"- A[i] += (c + 1) // 2",
"- A[i + 1] += c // 2",
"- c = 0",
"-c = 0",
"-for i in range(l - 1, 0, -1):",
"- if S[i] == \"L\":",
"- c += 1",
"- if S[i - 1] == \"R\" or (i == 0 and S[0] == \"L\"):",
"- if i == 0 and S[0] == \"L\":",
"- c += 1",
"- A[i] += (c + 1) // 2",
"- A[i - 1] += c // 2",
"- c = 0",
"-print((\" \".join(map(str, A))))",
"+S = eval(input()) + \"R\"",
"+L = len(S)",
"+RL = 0",
"+l, r, f = 0, 0, 0",
"+a = [0] * (L - 1)",
"+for i in range(1, L):",
"+ if f:",
"+ r += 1",
"+ else:",
"+ l += 1",
"+ if S[i - 1 : i + 1] == \"LR\":",
"+ a[RL - 1] = r // 2 + (l + 1) // 2",
"+ a[RL] = (r + 1) // 2 + l // 2",
"+ l, r, f = 0, 0, 0",
"+ if S[i - 1 : i + 1] == \"RL\":",
"+ RL, f = i, 1",
"+print((\" \".join(map(str, a))))"
] | false | 0.077989 | 0.037532 | 2.077941 |
[
"s995329617",
"s909366290"
] |
u994988729
|
p02761
|
python
|
s718834910
|
s886123582
| 25 | 18 | 3,444 | 3,064 |
Accepted
|
Accepted
| 28 |
from collections import defaultdict
d = defaultdict(list)
N, M = map(int, input().split())
for _ in range(M):
s, c = map(int, input().split())
d[s].append(c)
val = [-1] * N
# とりあえず桁を確定させる
for k, v in d.items():
if len(set(v)) > 1:
print(-1)
exit()
val[k - 1] = v[0]
if N == 1:
ans = max(0, val.pop())
print(ans)
exit()
if N >= 2:
if val[0] == 0:
print(-1)
exit()
if val[0] == -1:
val[0] = 1
for i in range(N):
val[i] = max(0, val[i])
print(*val, sep="")
|
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 10000
L = 10 ** (N - 1)
if N == 1:
L = 0
U = 10**N
for i in range(L, U):
x = str(i).zfill(N)
for s, c in sc:
if x[s - 1] == str(c):
continue
break
else:
ans = min(ans, i)
if ans >= 10000:
ans = -1
print(ans)
| 32 | 22 | 583 | 384 |
from collections import defaultdict
d = defaultdict(list)
N, M = map(int, input().split())
for _ in range(M):
s, c = map(int, input().split())
d[s].append(c)
val = [-1] * N
# とりあえず桁を確定させる
for k, v in d.items():
if len(set(v)) > 1:
print(-1)
exit()
val[k - 1] = v[0]
if N == 1:
ans = max(0, val.pop())
print(ans)
exit()
if N >= 2:
if val[0] == 0:
print(-1)
exit()
if val[0] == -1:
val[0] = 1
for i in range(N):
val[i] = max(0, val[i])
print(*val, sep="")
|
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 10000
L = 10 ** (N - 1)
if N == 1:
L = 0
U = 10**N
for i in range(L, U):
x = str(i).zfill(N)
for s, c in sc:
if x[s - 1] == str(c):
continue
break
else:
ans = min(ans, i)
if ans >= 10000:
ans = -1
print(ans)
| false | 31.25 |
[
"-from collections import defaultdict",
"-",
"-d = defaultdict(list)",
"-N, M = map(int, input().split())",
"-for _ in range(M):",
"- s, c = map(int, input().split())",
"- d[s].append(c)",
"-val = [-1] * N",
"-# とりあえず桁を確定させる",
"-for k, v in d.items():",
"- if len(set(v)) > 1:",
"- print(-1)",
"- exit()",
"- val[k - 1] = v[0]",
"+N, M = list(map(int, input().split()))",
"+sc = [list(map(int, input().split())) for _ in range(M)]",
"+ans = 10000",
"+L = 10 ** (N - 1)",
"- ans = max(0, val.pop())",
"- print(ans)",
"- exit()",
"-if N >= 2:",
"- if val[0] == 0:",
"- print(-1)",
"- exit()",
"- if val[0] == -1:",
"- val[0] = 1",
"- for i in range(N):",
"- val[i] = max(0, val[i])",
"- print(*val, sep=\"\")",
"+ L = 0",
"+U = 10**N",
"+for i in range(L, U):",
"+ x = str(i).zfill(N)",
"+ for s, c in sc:",
"+ if x[s - 1] == str(c):",
"+ continue",
"+ break",
"+ else:",
"+ ans = min(ans, i)",
"+if ans >= 10000:",
"+ ans = -1",
"+print(ans)"
] | false | 0.041782 | 0.083446 | 0.50071 |
[
"s718834910",
"s886123582"
] |
u208713671
|
p03273
|
python
|
s457078917
|
s443295976
| 88 | 68 | 67,756 | 68,744 |
Accepted
|
Accepted
| 22.73 |
H,W= list(map(int,input().split()))
M = []
for i in range(H):
M.append(list(eval(input())))
Hs = []
for i in range(H):
flag = 0
for j in range(W):
if M[i][j]!=".":
flag = 1
if flag==1:
Hs.append(i)
Ws = []
for j in range(W):
flag = 0
for i in range(H):
if M[i][j]!=".":
flag = 1
if flag==1:
Ws.append(j)
for i in Hs:
out = []
for j in Ws:
out.append(M[i][j])
print(("".join(out)))
|
[H,W] = list(map(int,input().split()))
a = []
for i in range(H):
a.append(list(eval(input())))
line = [0]*H
colu = [0]*W
for i in range(H):
for j in range(W):
if a[i][j] == '#':
line[i]=1
colu[j]=1
ans=[]
for i in range(H):
dammy=[]
for j in range(W):
if line[i]==1 and colu[j]==1 :
dammy.append(a[i][j])
if dammy!=[]:
ans.append(dammy)
for i in range(len(ans)):
print((''.join(ans[i])))
| 29 | 25 | 509 | 491 |
H, W = list(map(int, input().split()))
M = []
for i in range(H):
M.append(list(eval(input())))
Hs = []
for i in range(H):
flag = 0
for j in range(W):
if M[i][j] != ".":
flag = 1
if flag == 1:
Hs.append(i)
Ws = []
for j in range(W):
flag = 0
for i in range(H):
if M[i][j] != ".":
flag = 1
if flag == 1:
Ws.append(j)
for i in Hs:
out = []
for j in Ws:
out.append(M[i][j])
print(("".join(out)))
|
[H, W] = list(map(int, input().split()))
a = []
for i in range(H):
a.append(list(eval(input())))
line = [0] * H
colu = [0] * W
for i in range(H):
for j in range(W):
if a[i][j] == "#":
line[i] = 1
colu[j] = 1
ans = []
for i in range(H):
dammy = []
for j in range(W):
if line[i] == 1 and colu[j] == 1:
dammy.append(a[i][j])
if dammy != []:
ans.append(dammy)
for i in range(len(ans)):
print(("".join(ans[i])))
| false | 13.793103 |
[
"-H, W = list(map(int, input().split()))",
"-M = []",
"+[H, W] = list(map(int, input().split()))",
"+a = []",
"- M.append(list(eval(input())))",
"-Hs = []",
"+ a.append(list(eval(input())))",
"+line = [0] * H",
"+colu = [0] * W",
"- flag = 0",
"- if M[i][j] != \".\":",
"- flag = 1",
"- if flag == 1:",
"- Hs.append(i)",
"-Ws = []",
"-for j in range(W):",
"- flag = 0",
"- for i in range(H):",
"- if M[i][j] != \".\":",
"- flag = 1",
"- if flag == 1:",
"- Ws.append(j)",
"-for i in Hs:",
"- out = []",
"- for j in Ws:",
"- out.append(M[i][j])",
"- print((\"\".join(out)))",
"+ if a[i][j] == \"#\":",
"+ line[i] = 1",
"+ colu[j] = 1",
"+ans = []",
"+for i in range(H):",
"+ dammy = []",
"+ for j in range(W):",
"+ if line[i] == 1 and colu[j] == 1:",
"+ dammy.append(a[i][j])",
"+ if dammy != []:",
"+ ans.append(dammy)",
"+for i in range(len(ans)):",
"+ print((\"\".join(ans[i])))"
] | false | 0.034705 | 0.037529 | 0.924744 |
[
"s457078917",
"s443295976"
] |
u592547545
|
p03493
|
python
|
s647693479
|
s187062364
| 20 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 15 |
s=eval(input())
count=0
if(s[0]=='1'):
count+=1
if(s[1]=='1'):
count+=1
if(s[2]=='1'):
count+=1
print(count)
|
s = eval(input())
count=0
for _ in s:
if ( _ == '1'):
count+=1
print(count)
| 9 | 6 | 117 | 81 |
s = eval(input())
count = 0
if s[0] == "1":
count += 1
if s[1] == "1":
count += 1
if s[2] == "1":
count += 1
print(count)
|
s = eval(input())
count = 0
for _ in s:
if _ == "1":
count += 1
print(count)
| false | 33.333333 |
[
"-if s[0] == \"1\":",
"- count += 1",
"-if s[1] == \"1\":",
"- count += 1",
"-if s[2] == \"1\":",
"- count += 1",
"+for _ in s:",
"+ if _ == \"1\":",
"+ count += 1"
] | false | 0.046707 | 0.100491 | 0.464788 |
[
"s647693479",
"s187062364"
] |
u644907318
|
p02843
|
python
|
s984001694
|
s197604105
| 258 | 184 | 11,672 | 38,384 |
Accepted
|
Accepted
| 28.68 |
X = int(eval(input()))
A = [100,101,102,103,104,105]
dp = [[-1 for _ in range(X+1)] for _ in range(7)]
for i in range(1,7):
dp[i][0] = 10**6
for i in range(1,7):
for j in range(1,X+1):
if dp[i-1][j]>=0:
dp[i][j] = 10**6
elif j<A[i-1] or dp[i][j-A[i-1]]<=0:
dp[i][j] = -1
else:
dp[i][j] = dp[i][j-A[i-1]]-1
if dp[6][X]>=0:
print((1))
else:
print((0))
|
X = int(eval(input()))
x = X%100
cnt = 0
cnt += x//5
x = x%5
cnt += x//4
x = x%4
cnt += x//3
x = x%3
cnt += x//2
x = x%2
cnt += x
X = X-X%100
if X>=100*cnt:
print((1))
else:
print((0))
| 17 | 17 | 431 | 198 |
X = int(eval(input()))
A = [100, 101, 102, 103, 104, 105]
dp = [[-1 for _ in range(X + 1)] for _ in range(7)]
for i in range(1, 7):
dp[i][0] = 10**6
for i in range(1, 7):
for j in range(1, X + 1):
if dp[i - 1][j] >= 0:
dp[i][j] = 10**6
elif j < A[i - 1] or dp[i][j - A[i - 1]] <= 0:
dp[i][j] = -1
else:
dp[i][j] = dp[i][j - A[i - 1]] - 1
if dp[6][X] >= 0:
print((1))
else:
print((0))
|
X = int(eval(input()))
x = X % 100
cnt = 0
cnt += x // 5
x = x % 5
cnt += x // 4
x = x % 4
cnt += x // 3
x = x % 3
cnt += x // 2
x = x % 2
cnt += x
X = X - X % 100
if X >= 100 * cnt:
print((1))
else:
print((0))
| false | 0 |
[
"-A = [100, 101, 102, 103, 104, 105]",
"-dp = [[-1 for _ in range(X + 1)] for _ in range(7)]",
"-for i in range(1, 7):",
"- dp[i][0] = 10**6",
"-for i in range(1, 7):",
"- for j in range(1, X + 1):",
"- if dp[i - 1][j] >= 0:",
"- dp[i][j] = 10**6",
"- elif j < A[i - 1] or dp[i][j - A[i - 1]] <= 0:",
"- dp[i][j] = -1",
"- else:",
"- dp[i][j] = dp[i][j - A[i - 1]] - 1",
"-if dp[6][X] >= 0:",
"+x = X % 100",
"+cnt = 0",
"+cnt += x // 5",
"+x = x % 5",
"+cnt += x // 4",
"+x = x % 4",
"+cnt += x // 3",
"+x = x % 3",
"+cnt += x // 2",
"+x = x % 2",
"+cnt += x",
"+X = X - X % 100",
"+if X >= 100 * cnt:"
] | false | 0.045661 | 0.04718 | 0.967796 |
[
"s984001694",
"s197604105"
] |
u130860911
|
p02834
|
python
|
s687187077
|
s881525533
| 1,039 | 920 | 29,512 | 29,520 |
Accepted
|
Accepted
| 11.45 |
import heapq
N,u,v = list(map(int,input().split()))
u -= 1
v -= 1
du = [float('inf')]*N
dv = [float('inf')]*N
G = [[]]*N
def calcDist(s, dist):
q = []
heapq.heappush(q,[0, s])
dist[s] = int(0)
while q!=[]:
p = heapq.heappop(q)
pv = p[1]
if dist[pv] < p[0] :
continue
for i in range(len(G[pv])):
eto = G[pv][i]
if dist[eto] > dist[pv] + 1:
dist[eto] = int(dist[pv] + 1)
heapq.heappush(q, [dist[eto], eto])
for i in range(N-1):
e1,e2 = list(map(int, input().split()))
e1 -= 1
e2 -= 1
if G[e1] == []:
G[e1] = [e2]
else:
G[e1].append(e2)
if G[e2] == []:
G[e2] = [e1]
else:
G[e2].append(e1)
if v in G[u]:
ans = 0
else:
calcDist(v,dv)
calcDist(u,du)
maxD = 0
for idu,idv in zip(du,dv):
if idu < idv:
maxD = max(maxD, idv)
ans = maxD-1
print(ans)
|
import heapq
N,u,v = list(map(int,input().split()))
u -= 1
v -= 1
du = [float('inf')]*N
dv = [float('inf')]*N
G = [[]]*N
def calcDist(s, dist):
q = []
heapq.heappush(q,[0, s])
dist[s] = int(0)
while q!=[]:
p = heapq.heappop(q)
pv = p[1]
if dist[pv] < p[0] :
continue
for eto in G[pv]:
if dist[eto] > dist[pv] + 1:
dist[eto] = int(dist[pv] + 1)
heapq.heappush(q, [dist[eto], eto])
for i in range(N-1):
e1,e2 = list(map(int, input().split()))
e1 -= 1
e2 -= 1
if G[e1] == []:
G[e1] = [e2]
else:
G[e1].append(e2)
if G[e2] == []:
G[e2] = [e1]
else:
G[e2].append(e1)
if v in G[u]:
ans = 0
else:
calcDist(v,dv)
calcDist(u,du)
maxD = 0
for idu,idv in zip(du,dv):
if idu < idv:
maxD = max(maxD, idv)
ans = maxD-1
print(ans)
| 53 | 52 | 1,029 | 991 |
import heapq
N, u, v = list(map(int, input().split()))
u -= 1
v -= 1
du = [float("inf")] * N
dv = [float("inf")] * N
G = [[]] * N
def calcDist(s, dist):
q = []
heapq.heappush(q, [0, s])
dist[s] = int(0)
while q != []:
p = heapq.heappop(q)
pv = p[1]
if dist[pv] < p[0]:
continue
for i in range(len(G[pv])):
eto = G[pv][i]
if dist[eto] > dist[pv] + 1:
dist[eto] = int(dist[pv] + 1)
heapq.heappush(q, [dist[eto], eto])
for i in range(N - 1):
e1, e2 = list(map(int, input().split()))
e1 -= 1
e2 -= 1
if G[e1] == []:
G[e1] = [e2]
else:
G[e1].append(e2)
if G[e2] == []:
G[e2] = [e1]
else:
G[e2].append(e1)
if v in G[u]:
ans = 0
else:
calcDist(v, dv)
calcDist(u, du)
maxD = 0
for idu, idv in zip(du, dv):
if idu < idv:
maxD = max(maxD, idv)
ans = maxD - 1
print(ans)
|
import heapq
N, u, v = list(map(int, input().split()))
u -= 1
v -= 1
du = [float("inf")] * N
dv = [float("inf")] * N
G = [[]] * N
def calcDist(s, dist):
q = []
heapq.heappush(q, [0, s])
dist[s] = int(0)
while q != []:
p = heapq.heappop(q)
pv = p[1]
if dist[pv] < p[0]:
continue
for eto in G[pv]:
if dist[eto] > dist[pv] + 1:
dist[eto] = int(dist[pv] + 1)
heapq.heappush(q, [dist[eto], eto])
for i in range(N - 1):
e1, e2 = list(map(int, input().split()))
e1 -= 1
e2 -= 1
if G[e1] == []:
G[e1] = [e2]
else:
G[e1].append(e2)
if G[e2] == []:
G[e2] = [e1]
else:
G[e2].append(e1)
if v in G[u]:
ans = 0
else:
calcDist(v, dv)
calcDist(u, du)
maxD = 0
for idu, idv in zip(du, dv):
if idu < idv:
maxD = max(maxD, idv)
ans = maxD - 1
print(ans)
| false | 1.886792 |
[
"- for i in range(len(G[pv])):",
"- eto = G[pv][i]",
"+ for eto in G[pv]:"
] | false | 0.030875 | 0.035852 | 0.861184 |
[
"s687187077",
"s881525533"
] |
u794173881
|
p02763
|
python
|
s773207862
|
s801873761
| 498 | 441 | 73,436 | 77,404 |
Accepted
|
Accepted
| 11.45 |
class SegmentTree():
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
update: i番目をvalに変更する
get_min: 区間[begin, end)の最小値を求める
"""
def __init__(self, n):
self.n = n
self.INF = 0
self.size = 1
while self.size < n:
self.size *= 2
self.node = [self.INF] * (2*self.size - 1)
def update(self, i, val):
i += (self.size - 1)
self.node[i] = val
while i > 0:
i = (i - 1) // 2
self.node[i] = self.node[2*i + 1] | self.node[2*i + 2]
def get_min(self, begin, end):
begin += (self.size - 1)
end += (self.size - 1)
s = 0
while begin < end:
if (end - 1) & 1:
end -= 1
s = s | self.node[end]
if (begin - 1) & 1:
s = s | self.node[begin]
begin += 1
begin = (begin - 1) // 2
end = (end - 1) // 2
return s
import sys
input = sys.stdin.readline
n = int(eval(input()))
s = eval(input())
q = int(eval(input()))
query = [list(input().split()) for i in range(q)]
alph = "abcdefghijklmnopqrstuvwxyz"
to_int = {char: i for i, char in enumerate(alph)}
st = SegmentTree(n)
for i, char in enumerate(s[0:n]):
st.update(i, 1 << to_int[char])
for num, l, r in query:
if num == "1":
st.update(int(l) - 1, 1 << to_int[r])
else:
tmp = st.get_min(int(l) - 1, int(r))
print((bin(tmp).count("1")))
|
class SegmentTree():
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
built(array) := arrayを初期値とするセグメント木を構築する O(N)。
update(i, val) := i番目の要素をvalに変更する。
get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
"""
def __init__(self, n, op, e):
"""要素数、二項演算、単位元を引数として渡す
例) 区間最小値 SegmentTree(n, min, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def built(self, array):
"""arrayを初期値とするセグメント木を構築する"""
for i in range(self.n):
self.node[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def update(self, i, val):
"""i番目の要素をvalに変更する"""
i += self.size
self.node[i] = val
while i > 1:
i >>= 1
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res = self.e
while l < r:
if l & 1:
res = self.op(self.node[l], res)
l += 1
if r & 1:
r -= 1
res = self.op(self.node[r], res)
l, r = l >> 1, r >> 1
return res
import sys
input = sys.stdin.readline
n = int(eval(input()))
s = eval(input())
q = int(eval(input()))
query = [list(input().split()) for i in range(q)]
alph = "abcdefghijklmnopqrstuvwxyz"
to_int = {char: i for i, char in enumerate(alph)}
st = SegmentTree(n, lambda a, b : a | b, 0)
init = [0] * n
for i, char in enumerate(s[0:n]):
init[i] = 1 << to_int[char]
st.built(init)
for num, l, r in query:
if num == "1":
st.update(int(l) - 1, 1 << to_int[r])
else:
tmp = st.get_val(int(l) - 1, int(r))
print((bin(tmp).count("1")))
| 57 | 71 | 1,511 | 2,067 |
class SegmentTree:
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
update: i番目をvalに変更する
get_min: 区間[begin, end)の最小値を求める
"""
def __init__(self, n):
self.n = n
self.INF = 0
self.size = 1
while self.size < n:
self.size *= 2
self.node = [self.INF] * (2 * self.size - 1)
def update(self, i, val):
i += self.size - 1
self.node[i] = val
while i > 0:
i = (i - 1) // 2
self.node[i] = self.node[2 * i + 1] | self.node[2 * i + 2]
def get_min(self, begin, end):
begin += self.size - 1
end += self.size - 1
s = 0
while begin < end:
if (end - 1) & 1:
end -= 1
s = s | self.node[end]
if (begin - 1) & 1:
s = s | self.node[begin]
begin += 1
begin = (begin - 1) // 2
end = (end - 1) // 2
return s
import sys
input = sys.stdin.readline
n = int(eval(input()))
s = eval(input())
q = int(eval(input()))
query = [list(input().split()) for i in range(q)]
alph = "abcdefghijklmnopqrstuvwxyz"
to_int = {char: i for i, char in enumerate(alph)}
st = SegmentTree(n)
for i, char in enumerate(s[0:n]):
st.update(i, 1 << to_int[char])
for num, l, r in query:
if num == "1":
st.update(int(l) - 1, 1 << to_int[r])
else:
tmp = st.get_min(int(l) - 1, int(r))
print((bin(tmp).count("1")))
|
class SegmentTree:
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
built(array) := arrayを初期値とするセグメント木を構築する O(N)。
update(i, val) := i番目の要素をvalに変更する。
get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
"""
def __init__(self, n, op, e):
"""要素数、二項演算、単位元を引数として渡す
例) 区間最小値 SegmentTree(n, min, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def built(self, array):
"""arrayを初期値とするセグメント木を構築する"""
for i in range(self.n):
self.node[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def update(self, i, val):
"""i番目の要素をvalに変更する"""
i += self.size
self.node[i] = val
while i > 1:
i >>= 1
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res = self.e
while l < r:
if l & 1:
res = self.op(self.node[l], res)
l += 1
if r & 1:
r -= 1
res = self.op(self.node[r], res)
l, r = l >> 1, r >> 1
return res
import sys
input = sys.stdin.readline
n = int(eval(input()))
s = eval(input())
q = int(eval(input()))
query = [list(input().split()) for i in range(q)]
alph = "abcdefghijklmnopqrstuvwxyz"
to_int = {char: i for i, char in enumerate(alph)}
st = SegmentTree(n, lambda a, b: a | b, 0)
init = [0] * n
for i, char in enumerate(s[0:n]):
init[i] = 1 << to_int[char]
st.built(init)
for num, l, r in query:
if num == "1":
st.update(int(l) - 1, 1 << to_int[r])
else:
tmp = st.get_val(int(l) - 1, int(r))
print((bin(tmp).count("1")))
| false | 19.71831 |
[
"- \"\"\"一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する",
"- update: i番目をvalに変更する",
"- get_min: 区間[begin, end)の最小値を求める",
"+ \"\"\"一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。",
"+ built(array) := arrayを初期値とするセグメント木を構築する O(N)。",
"+ update(i, val) := i番目の要素をvalに変更する。",
"+ get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。",
"- def __init__(self, n):",
"+ def __init__(self, n, op, e):",
"+ \"\"\"要素数、二項演算、単位元を引数として渡す",
"+ 例) 区間最小値 SegmentTree(n, min, 10 ** 18)",
"+ 区間和 SegmentTree(n, lambda a, b : a + b, 0)",
"+ \"\"\"",
"- self.INF = 0",
"- self.size = 1",
"- while self.size < n:",
"- self.size *= 2",
"- self.node = [self.INF] * (2 * self.size - 1)",
"+ self.op = op",
"+ self.e = e",
"+ self.size = 2 ** ((n - 1).bit_length())",
"+ self.node = [self.e] * (2 * self.size)",
"+",
"+ def built(self, array):",
"+ \"\"\"arrayを初期値とするセグメント木を構築する\"\"\"",
"+ for i in range(self.n):",
"+ self.node[self.size + i] = array[i]",
"+ for i in range(self.size - 1, 0, -1):",
"+ self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])",
"- i += self.size - 1",
"+ \"\"\"i番目の要素をvalに変更する\"\"\"",
"+ i += self.size",
"- while i > 0:",
"- i = (i - 1) // 2",
"- self.node[i] = self.node[2 * i + 1] | self.node[2 * i + 2]",
"+ while i > 1:",
"+ i >>= 1",
"+ self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])",
"- def get_min(self, begin, end):",
"- begin += self.size - 1",
"- end += self.size - 1",
"- s = 0",
"- while begin < end:",
"- if (end - 1) & 1:",
"- end -= 1",
"- s = s | self.node[end]",
"- if (begin - 1) & 1:",
"- s = s | self.node[begin]",
"- begin += 1",
"- begin = (begin - 1) // 2",
"- end = (end - 1) // 2",
"- return s",
"+ def get_val(self, l, r):",
"+ \"\"\"[l, r)の畳み込みの結果を返す\"\"\"",
"+ l, r = l + self.size, r + self.size",
"+ res = self.e",
"+ while l < r:",
"+ if l & 1:",
"+ res = self.op(self.node[l], res)",
"+ l += 1",
"+ if r & 1:",
"+ r -= 1",
"+ res = self.op(self.node[r], res)",
"+ l, r = l >> 1, r >> 1",
"+ return res",
"-st = SegmentTree(n)",
"+st = SegmentTree(n, lambda a, b: a | b, 0)",
"+init = [0] * n",
"- st.update(i, 1 << to_int[char])",
"+ init[i] = 1 << to_int[char]",
"+st.built(init)",
"- tmp = st.get_min(int(l) - 1, int(r))",
"+ tmp = st.get_val(int(l) - 1, int(r))"
] | false | 0.039163 | 0.05562 | 0.704114 |
[
"s773207862",
"s801873761"
] |
u211236379
|
p03013
|
python
|
s852816615
|
s926877840
| 1,561 | 570 | 536,716 | 471,288 |
Accepted
|
Accepted
| 63.48 |
#N = int(input())
N, M = list(map(int,input().split()))
#W =list(map(int,input().split()))
a = [(int(eval(input()))) for i in range(M)]
import sys
sys.setrecursionlimit(100000)
memo =[-1]*(N+2)
def stair_count(n):
if memo[n]!= -1:
return memo[n]
if n==0 or n==1:
memo[n] =1
return memo[n]
memo[n] = stair_count(n-1) + stair_count(n-2)
return memo[n]
start = 0
answer = 1
for i in a:
if i == start:
print((0))
exit()
else:
n = i-1-start
answer = (answer * stair_count(n))
start = i+1
n = N -start
answer = (answer * stair_count(n))
print((answer%1000000007))
|
#N = int(input())
N, M = list(map(int,input().split()))
#W =list(map(int,input().split()))
a = [(int(eval(input()))) for i in range(M)]
import sys
sys.setrecursionlimit(100000)
memo =[-1]*(N+2)
memo[0] = 1
memo[1] = 1
def stair_count(n):
for j in range(2,n+1):
memo[j] = memo[j-1] + memo[j-2]
start = 0
answer = 1
dif = []
for i in a:
if i == start:
print((0))
exit()
else:
n = i-1-start
dif.append(n)
start = i+1
dif.append(N-start)
stair_count(max(dif))
for i in dif:
answer = (answer * memo[i])
print((answer%1000000007))
| 31 | 32 | 693 | 614 |
# N = int(input())
N, M = list(map(int, input().split()))
# W =list(map(int,input().split()))
a = [(int(eval(input()))) for i in range(M)]
import sys
sys.setrecursionlimit(100000)
memo = [-1] * (N + 2)
def stair_count(n):
if memo[n] != -1:
return memo[n]
if n == 0 or n == 1:
memo[n] = 1
return memo[n]
memo[n] = stair_count(n - 1) + stair_count(n - 2)
return memo[n]
start = 0
answer = 1
for i in a:
if i == start:
print((0))
exit()
else:
n = i - 1 - start
answer = answer * stair_count(n)
start = i + 1
n = N - start
answer = answer * stair_count(n)
print((answer % 1000000007))
|
# N = int(input())
N, M = list(map(int, input().split()))
# W =list(map(int,input().split()))
a = [(int(eval(input()))) for i in range(M)]
import sys
sys.setrecursionlimit(100000)
memo = [-1] * (N + 2)
memo[0] = 1
memo[1] = 1
def stair_count(n):
for j in range(2, n + 1):
memo[j] = memo[j - 1] + memo[j - 2]
start = 0
answer = 1
dif = []
for i in a:
if i == start:
print((0))
exit()
else:
n = i - 1 - start
dif.append(n)
start = i + 1
dif.append(N - start)
stair_count(max(dif))
for i in dif:
answer = answer * memo[i]
print((answer % 1000000007))
| false | 3.125 |
[
"+memo[0] = 1",
"+memo[1] = 1",
"- if memo[n] != -1:",
"- return memo[n]",
"- if n == 0 or n == 1:",
"- memo[n] = 1",
"- return memo[n]",
"- memo[n] = stair_count(n - 1) + stair_count(n - 2)",
"- return memo[n]",
"+ for j in range(2, n + 1):",
"+ memo[j] = memo[j - 1] + memo[j - 2]",
"+dif = []",
"- answer = answer * stair_count(n)",
"+ dif.append(n)",
"-n = N - start",
"-answer = answer * stair_count(n)",
"+dif.append(N - start)",
"+stair_count(max(dif))",
"+for i in dif:",
"+ answer = answer * memo[i]"
] | false | 0.03797 | 0.107489 | 0.353242 |
[
"s852816615",
"s926877840"
] |
u513081876
|
p03240
|
python
|
s480456713
|
s452445797
| 471 | 29 | 3,188 | 3,188 |
Accepted
|
Accepted
| 93.84 |
N = int(eval(input()))
x, y, h = [0]*N, [0]*N, [0]*N
for i in range(N):
x[i], y[i], h[i] = list(map(int, input().split()))
for cx in range(0, 101):
for cy in range(0, 101):
for i in range(N):
if h[i] > 0:
H = h[i] + abs(x[i]-cx)+abs(y[i]-cy)
for i in range(N):
if h[i] != max(0, H-abs(x[i]-cx)-abs(y[i]-cy)):
break
else:
print((cx, cy, H))
exit()
|
import sys
N = int(eval(input()))
xyh = [list(map(int, input().split())) for i in range(N)]
xyh.sort(key=lambda x:x[2])
if N==1:
print((xyh[0][0], xyh[0][1] , xyh[0][2]))
else:
for xc in range(101):
for yc in range(101):
H = xyh[-1][2] + abs(xyh[-1][0] - xc) + abs(xyh[-1][1] - yc)
for xi, yi, hi in xyh:
if hi != max(H - abs(xi - xc) - abs(yi - yc), 0):
break
else:
print((xc, yc, H))
sys.exit()
| 17 | 20 | 470 | 539 |
N = int(eval(input()))
x, y, h = [0] * N, [0] * N, [0] * N
for i in range(N):
x[i], y[i], h[i] = list(map(int, input().split()))
for cx in range(0, 101):
for cy in range(0, 101):
for i in range(N):
if h[i] > 0:
H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
for i in range(N):
if h[i] != max(0, H - abs(x[i] - cx) - abs(y[i] - cy)):
break
else:
print((cx, cy, H))
exit()
|
import sys
N = int(eval(input()))
xyh = [list(map(int, input().split())) for i in range(N)]
xyh.sort(key=lambda x: x[2])
if N == 1:
print((xyh[0][0], xyh[0][1], xyh[0][2]))
else:
for xc in range(101):
for yc in range(101):
H = xyh[-1][2] + abs(xyh[-1][0] - xc) + abs(xyh[-1][1] - yc)
for xi, yi, hi in xyh:
if hi != max(H - abs(xi - xc) - abs(yi - yc), 0):
break
else:
print((xc, yc, H))
sys.exit()
| false | 15 |
[
"+import sys",
"+",
"-x, y, h = [0] * N, [0] * N, [0] * N",
"-for i in range(N):",
"- x[i], y[i], h[i] = list(map(int, input().split()))",
"-for cx in range(0, 101):",
"- for cy in range(0, 101):",
"- for i in range(N):",
"- if h[i] > 0:",
"- H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)",
"- for i in range(N):",
"- if h[i] != max(0, H - abs(x[i] - cx) - abs(y[i] - cy)):",
"- break",
"- else:",
"- print((cx, cy, H))",
"- exit()",
"+xyh = [list(map(int, input().split())) for i in range(N)]",
"+xyh.sort(key=lambda x: x[2])",
"+if N == 1:",
"+ print((xyh[0][0], xyh[0][1], xyh[0][2]))",
"+else:",
"+ for xc in range(101):",
"+ for yc in range(101):",
"+ H = xyh[-1][2] + abs(xyh[-1][0] - xc) + abs(xyh[-1][1] - yc)",
"+ for xi, yi, hi in xyh:",
"+ if hi != max(H - abs(xi - xc) - abs(yi - yc), 0):",
"+ break",
"+ else:",
"+ print((xc, yc, H))",
"+ sys.exit()"
] | false | 0.066423 | 0.038692 | 1.716724 |
[
"s480456713",
"s452445797"
] |
u485319545
|
p02584
|
python
|
s198312827
|
s755109658
| 35 | 30 | 9,196 | 8,956 |
Accepted
|
Accepted
| 14.29 |
x,k,d=list(map(int,input().split()))
if d>=abs(x):
if k%2==0:
p=abs(x)
else:
if x>=0:
p=abs(x-d)
else:
p=abs(x+d)
print(p)
exit(0)
else:
cnt=abs(x)//d
if cnt>=k:
cnt=k
if x>=0:
p=x-d*cnt
else:
p=x+d*cnt
k-=cnt
if k==0:
print((abs(p)))
exit(0)
if k%2==0:
print((abs(p)))
else:
if p>=0:
p=abs(p-d)
else:
p=abs(p+d)
print(p)
|
x,k,d=list(map(int,input().split()))
x=abs(x)
cnt=abs(x)//d
if cnt>=k:
print((x-d*k))
else:
k-=cnt
if k%2==0:
print((abs(x-d*cnt)))
else:
print((abs(x-d*(cnt+1))))
| 39 | 17 | 549 | 206 |
x, k, d = list(map(int, input().split()))
if d >= abs(x):
if k % 2 == 0:
p = abs(x)
else:
if x >= 0:
p = abs(x - d)
else:
p = abs(x + d)
print(p)
exit(0)
else:
cnt = abs(x) // d
if cnt >= k:
cnt = k
if x >= 0:
p = x - d * cnt
else:
p = x + d * cnt
k -= cnt
if k == 0:
print((abs(p)))
exit(0)
if k % 2 == 0:
print((abs(p)))
else:
if p >= 0:
p = abs(p - d)
else:
p = abs(p + d)
print(p)
|
x, k, d = list(map(int, input().split()))
x = abs(x)
cnt = abs(x) // d
if cnt >= k:
print((x - d * k))
else:
k -= cnt
if k % 2 == 0:
print((abs(x - d * cnt)))
else:
print((abs(x - d * (cnt + 1))))
| false | 56.410256 |
[
"-if d >= abs(x):",
"+x = abs(x)",
"+cnt = abs(x) // d",
"+if cnt >= k:",
"+ print((x - d * k))",
"+else:",
"+ k -= cnt",
"- p = abs(x)",
"+ print((abs(x - d * cnt)))",
"- if x >= 0:",
"- p = abs(x - d)",
"- else:",
"- p = abs(x + d)",
"- print(p)",
"- exit(0)",
"-else:",
"- cnt = abs(x) // d",
"- if cnt >= k:",
"- cnt = k",
"- if x >= 0:",
"- p = x - d * cnt",
"- else:",
"- p = x + d * cnt",
"- k -= cnt",
"- if k == 0:",
"- print((abs(p)))",
"- exit(0)",
"- if k % 2 == 0:",
"- print((abs(p)))",
"- else:",
"- if p >= 0:",
"- p = abs(p - d)",
"- else:",
"- p = abs(p + d)",
"- print(p)",
"+ print((abs(x - d * (cnt + 1))))"
] | false | 0.03788 | 0.043459 | 0.871617 |
[
"s198312827",
"s755109658"
] |
u017810624
|
p02838
|
python
|
s103665632
|
s810854343
| 1,420 | 1,046 | 125,624 | 125,624 |
Accepted
|
Accepted
| 26.34 |
def sumXOR( arr, n):
sum = 0
for i in range(0, 100):
zc = 0
oc = 0
idsum = 0
for j in range(0, n):
if (arr[j] % 2 == 0):
zc = zc + 1
else:
oc = oc + 1
arr[j] = arr[j]//2
idsum = oc * zc * (1 << i)
sum = sum + idsum;
sum%=10**9+7
return sum
n=int(eval(input()))
arr=list(map(int,input().split()))
sum = sumXOR(arr, n);
sum%=10**9+7
print(sum)
|
n=int(eval(input()))
a=list(map(int,input().split()))
mod=10**9+7
ct0=[0]*64
ct1=[0]*64
for i in range(n):
x=format(a[i],'0'+str(64)+'b')
for j in range(64):
if x[j]=='0':
ct0[j]+=1
else:
ct1[j]+=1
ct0.reverse()
ct1.reverse()
ans=0
for i in range(64):
x=(ct0[i]*ct1[i])%mod
ans+=x*(2**i)
ans%=mod
print(ans)
| 23 | 20 | 526 | 350 |
def sumXOR(arr, n):
sum = 0
for i in range(0, 100):
zc = 0
oc = 0
idsum = 0
for j in range(0, n):
if arr[j] % 2 == 0:
zc = zc + 1
else:
oc = oc + 1
arr[j] = arr[j] // 2
idsum = oc * zc * (1 << i)
sum = sum + idsum
sum %= 10**9 + 7
return sum
n = int(eval(input()))
arr = list(map(int, input().split()))
sum = sumXOR(arr, n)
sum %= 10**9 + 7
print(sum)
|
n = int(eval(input()))
a = list(map(int, input().split()))
mod = 10**9 + 7
ct0 = [0] * 64
ct1 = [0] * 64
for i in range(n):
x = format(a[i], "0" + str(64) + "b")
for j in range(64):
if x[j] == "0":
ct0[j] += 1
else:
ct1[j] += 1
ct0.reverse()
ct1.reverse()
ans = 0
for i in range(64):
x = (ct0[i] * ct1[i]) % mod
ans += x * (2**i)
ans %= mod
print(ans)
| false | 13.043478 |
[
"-def sumXOR(arr, n):",
"- sum = 0",
"- for i in range(0, 100):",
"- zc = 0",
"- oc = 0",
"- idsum = 0",
"- for j in range(0, n):",
"- if arr[j] % 2 == 0:",
"- zc = zc + 1",
"- else:",
"- oc = oc + 1",
"- arr[j] = arr[j] // 2",
"- idsum = oc * zc * (1 << i)",
"- sum = sum + idsum",
"- sum %= 10**9 + 7",
"- return sum",
"-",
"-",
"-arr = list(map(int, input().split()))",
"-sum = sumXOR(arr, n)",
"-sum %= 10**9 + 7",
"-print(sum)",
"+a = list(map(int, input().split()))",
"+mod = 10**9 + 7",
"+ct0 = [0] * 64",
"+ct1 = [0] * 64",
"+for i in range(n):",
"+ x = format(a[i], \"0\" + str(64) + \"b\")",
"+ for j in range(64):",
"+ if x[j] == \"0\":",
"+ ct0[j] += 1",
"+ else:",
"+ ct1[j] += 1",
"+ct0.reverse()",
"+ct1.reverse()",
"+ans = 0",
"+for i in range(64):",
"+ x = (ct0[i] * ct1[i]) % mod",
"+ ans += x * (2**i)",
"+ ans %= mod",
"+print(ans)"
] | false | 0.037465 | 0.039111 | 0.957911 |
[
"s103665632",
"s810854343"
] |
u968166680
|
p02787
|
python
|
s069996134
|
s724196265
| 244 | 132 | 152,636 | 70,556 |
Accepted
|
Accepted
| 45.9 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, N, *AB = list(map(int, read().split()))
magic = [0] * N
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
magic[i] = (a, b)
dp = [[INF] * (H + 1) for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0] = 0
for i in range(N):
a, b = magic[i]
for j in range(H + 1):
dp[i + 1][j] = min(dp[i][j], dp[i + 1][max(j - a, 0)] + b)
print((dp[N][H]))
return
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, N, *AB = list(map(int, read().split()))
dp = [INF] * (H + 1)
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H + 1):
dp[i] = min(dp[i], dp[max(i - a, 0)] + b)
print((dp[H]))
return
if __name__ == '__main__':
main()
| 32 | 26 | 665 | 471 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
H, N, *AB = list(map(int, read().split()))
magic = [0] * N
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
magic[i] = (a, b)
dp = [[INF] * (H + 1) for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0] = 0
for i in range(N):
a, b = magic[i]
for j in range(H + 1):
dp[i + 1][j] = min(dp[i][j], dp[i + 1][max(j - a, 0)] + b)
print((dp[N][H]))
return
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
H, N, *AB = list(map(int, read().split()))
dp = [INF] * (H + 1)
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H + 1):
dp[i] = min(dp[i], dp[max(i - a, 0)] + b)
print((dp[H]))
return
if __name__ == "__main__":
main()
| false | 18.75 |
[
"- magic = [0] * N",
"- for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):",
"- magic[i] = (a, b)",
"- dp = [[INF] * (H + 1) for _ in range(N + 1)]",
"- for i in range(N + 1):",
"- dp[i][0] = 0",
"- for i in range(N):",
"- a, b = magic[i]",
"- for j in range(H + 1):",
"- dp[i + 1][j] = min(dp[i][j], dp[i + 1][max(j - a, 0)] + b)",
"- print((dp[N][H]))",
"+ dp = [INF] * (H + 1)",
"+ dp[0] = 0",
"+ for a, b in zip(*[iter(AB)] * 2):",
"+ for i in range(H + 1):",
"+ dp[i] = min(dp[i], dp[max(i - a, 0)] + b)",
"+ print((dp[H]))"
] | false | 0.064787 | 0.368846 | 0.175647 |
[
"s069996134",
"s724196265"
] |
u428132025
|
p02683
|
python
|
s178712607
|
s062953181
| 88 | 79 | 74,024 | 9,636 |
Accepted
|
Accepted
| 10.23 |
n, m, x = list(map(int, input().split()))
c = [0] * n
for i in range(n):
c[i] = [int(_) for _ in input().split()]
ans = 10**10
for i in range(2 ** n):
state = [0] * n
for j in range(n):
state[j] = (i >> j) & 1
#print(state)
num = [0] * m
val = 0
for j in range(n):
if state[j] == 1:
for k in range(m):
num[k] += c[j][k+1]
val += c[j][0]
flag = True
for j in range(m):
if num[j] < x:
flag = False
break
if flag:
ans = min(ans, val)
if ans == 10**10:
print((-1))
else:
print(ans)
|
from itertools import product
n, m, x = list(map(int, input().split()))
c = [0] * n
a = [0] * n
for i in range(n):
inp = [int(_) for _ in input().split()]
c[i] = inp[0]
a[i] = inp[1:]
INIT = 10**10
ans = INIT
pat = list(product([0, 1], repeat=n))
for p in pat:
a_val = [0] * m
c_yen = 0
for i in range(n):
if p[i] == 1:
c_yen += c[i]
for j in range(m):
a_val[j] += a[i][j]
flag = True
for i in range(m):
if a_val[i] < x:
flag = False
break
if flag:
ans = min(ans, c_yen)
if ans == INIT:
print((-1))
else:
print(ans)
| 32 | 36 | 648 | 681 |
n, m, x = list(map(int, input().split()))
c = [0] * n
for i in range(n):
c[i] = [int(_) for _ in input().split()]
ans = 10**10
for i in range(2**n):
state = [0] * n
for j in range(n):
state[j] = (i >> j) & 1
# print(state)
num = [0] * m
val = 0
for j in range(n):
if state[j] == 1:
for k in range(m):
num[k] += c[j][k + 1]
val += c[j][0]
flag = True
for j in range(m):
if num[j] < x:
flag = False
break
if flag:
ans = min(ans, val)
if ans == 10**10:
print((-1))
else:
print(ans)
|
from itertools import product
n, m, x = list(map(int, input().split()))
c = [0] * n
a = [0] * n
for i in range(n):
inp = [int(_) for _ in input().split()]
c[i] = inp[0]
a[i] = inp[1:]
INIT = 10**10
ans = INIT
pat = list(product([0, 1], repeat=n))
for p in pat:
a_val = [0] * m
c_yen = 0
for i in range(n):
if p[i] == 1:
c_yen += c[i]
for j in range(m):
a_val[j] += a[i][j]
flag = True
for i in range(m):
if a_val[i] < x:
flag = False
break
if flag:
ans = min(ans, c_yen)
if ans == INIT:
print((-1))
else:
print(ans)
| false | 11.111111 |
[
"+from itertools import product",
"+",
"+a = [0] * n",
"- c[i] = [int(_) for _ in input().split()]",
"-ans = 10**10",
"-for i in range(2**n):",
"- state = [0] * n",
"- for j in range(n):",
"- state[j] = (i >> j) & 1",
"- # print(state)",
"- num = [0] * m",
"- val = 0",
"- for j in range(n):",
"- if state[j] == 1:",
"- for k in range(m):",
"- num[k] += c[j][k + 1]",
"- val += c[j][0]",
"+ inp = [int(_) for _ in input().split()]",
"+ c[i] = inp[0]",
"+ a[i] = inp[1:]",
"+INIT = 10**10",
"+ans = INIT",
"+pat = list(product([0, 1], repeat=n))",
"+for p in pat:",
"+ a_val = [0] * m",
"+ c_yen = 0",
"+ for i in range(n):",
"+ if p[i] == 1:",
"+ c_yen += c[i]",
"+ for j in range(m):",
"+ a_val[j] += a[i][j]",
"- for j in range(m):",
"- if num[j] < x:",
"+ for i in range(m):",
"+ if a_val[i] < x:",
"- ans = min(ans, val)",
"-if ans == 10**10:",
"+ ans = min(ans, c_yen)",
"+if ans == INIT:"
] | false | 0.051697 | 0.047635 | 1.085267 |
[
"s178712607",
"s062953181"
] |
u729133443
|
p02975
|
python
|
s632625266
|
s504912269
| 182 | 55 | 24,780 | 11,632 |
Accepted
|
Accepted
| 69.78 |
from numpy import*;_,a=open(0);print(('YNeos'[bitwise_xor.reduce(int32(a.split()))>0::2]))
|
from functools import*;_,a=open(0);print(('YNeos'[reduce(lambda x,y:x^y,list(map(int,a.split())))>0::2]))
| 1 | 1 | 88 | 97 |
from numpy import *
_, a = open(0)
print(("YNeos"[bitwise_xor.reduce(int32(a.split())) > 0 :: 2]))
|
from functools import *
_, a = open(0)
print(("YNeos"[reduce(lambda x, y: x ^ y, list(map(int, a.split()))) > 0 :: 2]))
| false | 0 |
[
"-from numpy import *",
"+from functools import *",
"-print((\"YNeos\"[bitwise_xor.reduce(int32(a.split())) > 0 :: 2]))",
"+print((\"YNeos\"[reduce(lambda x, y: x ^ y, list(map(int, a.split()))) > 0 :: 2]))"
] | false | 0.253822 | 0.043463 | 5.839944 |
[
"s632625266",
"s504912269"
] |
u227082700
|
p02988
|
python
|
s972022669
|
s222610696
| 21 | 18 | 3,316 | 3,060 |
Accepted
|
Accepted
| 14.29 |
n=int(eval(input()))
#n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
b=[a[i-1],a[i],a[i+1]]
b.sort()
if b[1]==a[i]:ans+=1
print(ans)
|
n=int(eval(input()))
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
if sorted([p[i-1],p[i],p[i+1]])[1]==p[i]:ans+=1
print(ans)
| 9 | 6 | 184 | 142 |
n = int(eval(input()))
# n,k=map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
b = [a[i - 1], a[i], a[i + 1]]
b.sort()
if b[1] == a[i]:
ans += 1
print(ans)
|
n = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
if sorted([p[i - 1], p[i], p[i + 1]])[1] == p[i]:
ans += 1
print(ans)
| false | 33.333333 |
[
"-# n,k=map(int,input().split())",
"-a = list(map(int, input().split()))",
"+p = list(map(int, input().split()))",
"- b = [a[i - 1], a[i], a[i + 1]]",
"- b.sort()",
"- if b[1] == a[i]:",
"+ if sorted([p[i - 1], p[i], p[i + 1]])[1] == p[i]:"
] | false | 0.046148 | 0.045675 | 1.010362 |
[
"s972022669",
"s222610696"
] |
u135454978
|
p02844
|
python
|
s257038787
|
s003383811
| 178 | 18 | 38,256 | 3,060 |
Accepted
|
Accepted
| 89.89 |
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
import sys
N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(10):
code1 = S.find(str(i))
if code1 == -1:
continue
for j in range(10):
code2 = S.find(str(j), code1 + 1)
if code2 == -1:
continue
for k in range(10):
code3 = S.find(str(k), code2 + 1)
if code3 != -1:
ans += 1
print(ans)
|
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
import sys
N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(10):
code1 = S.find(str(i))
if code1 == -1:
continue
for j in range(10):
code2 = S.find(str(j), code1 + 1)
if code2 == -1:
continue
for k in range(10):
if S.find(str(k), code2 + 1) != -1:
ans += 1
print(ans)
| 22 | 21 | 448 | 421 |
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
import sys
N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(10):
code1 = S.find(str(i))
if code1 == -1:
continue
for j in range(10):
code2 = S.find(str(j), code1 + 1)
if code2 == -1:
continue
for k in range(10):
code3 = S.find(str(k), code2 + 1)
if code3 != -1:
ans += 1
print(ans)
|
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
import sys
N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(10):
code1 = S.find(str(i))
if code1 == -1:
continue
for j in range(10):
code2 = S.find(str(j), code1 + 1)
if code2 == -1:
continue
for k in range(10):
if S.find(str(k), code2 + 1) != -1:
ans += 1
print(ans)
| false | 4.545455 |
[
"- code3 = S.find(str(k), code2 + 1)",
"- if code3 != -1:",
"+ if S.find(str(k), code2 + 1) != -1:"
] | false | 0.044169 | 0.041566 | 1.062634 |
[
"s257038787",
"s003383811"
] |
u119456964
|
p02386
|
python
|
s889013990
|
s410941091
| 50 | 40 | 6,464 | 6,468 |
Accepted
|
Accepted
| 20 |
n = int(input())
dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
dice[i] = list(map(int, input().split()))
def rolling(inst, dice):
if inst == 'E':
dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
elif inst == 'W':
dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
elif inst == 'N':
dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
elif inst == 'S':
dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
def dice_matching(dice1, dice2):
if dice1[1] == dice2[1]:
for i in range(4):
if dice1 == dice2:
return 1
break
rolling('E', dice2)
return 0
else:
return 0
flag = 0
for i in range(n):
for j in range(i+1, n):
count = 0
while(1):
if dice_matching(dice[i], dice[j]) == 1:
flag = 1
print('No')
break
else:
if count < 3:
rolling('N', dice[j])
count += 1
elif 7 > count and count >= 3:
if count == 3:
rolling('E', dice[j])
rolling('N', dice[j])
count += 1
else:
break
if flag ==1:
break
if flag == 1:
break
if flag == 0:
print('Yes')
|
n = int(input())
dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
dice[i] = list(map(int, input().split()))
def rolling(inst, dice):
if inst == 'E':
dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
elif inst == 'W':
dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
elif inst == 'N':
dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
elif inst == 'S':
dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
def dice_matching(dice1, dice2):
if dice1[1] == dice2[1]:
for i in range(4):
if dice1 == dice2:
return 1
break
rolling('E', dice2)
return 0
else:
return 0
def alldice_matching(dice1, dice2):
count = 0
while(1):
if dice_matching(dice1, dice2) == 1:
return 1
else:
if count < 3:
rolling('N', dice2)
count += 1
elif 7 > count and count >= 3:
if count == 3:
rolling('E', dice2)
rolling('N', dice2)
count += 1
else:
return 0
flag = 0
for i in range(n):
for j in range(i+1, n):
if alldice_matching(dice[i], dice[j]) == 1:
flag = 1
print("No")
break
if flag == 1:
break
if flag == 0:
print('Yes')
| 53 | 55 | 1,562 | 1,552 |
n = int(input())
dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
dice[i] = list(map(int, input().split()))
def rolling(inst, dice):
if inst == "E":
dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
elif inst == "W":
dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
elif inst == "N":
dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
elif inst == "S":
dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
def dice_matching(dice1, dice2):
if dice1[1] == dice2[1]:
for i in range(4):
if dice1 == dice2:
return 1
break
rolling("E", dice2)
return 0
else:
return 0
flag = 0
for i in range(n):
for j in range(i + 1, n):
count = 0
while 1:
if dice_matching(dice[i], dice[j]) == 1:
flag = 1
print("No")
break
else:
if count < 3:
rolling("N", dice[j])
count += 1
elif 7 > count and count >= 3:
if count == 3:
rolling("E", dice[j])
rolling("N", dice[j])
count += 1
else:
break
if flag == 1:
break
if flag == 1:
break
if flag == 0:
print("Yes")
|
n = int(input())
dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
dice[i] = list(map(int, input().split()))
def rolling(inst, dice):
if inst == "E":
dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
elif inst == "W":
dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
elif inst == "N":
dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
elif inst == "S":
dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
def dice_matching(dice1, dice2):
if dice1[1] == dice2[1]:
for i in range(4):
if dice1 == dice2:
return 1
break
rolling("E", dice2)
return 0
else:
return 0
def alldice_matching(dice1, dice2):
count = 0
while 1:
if dice_matching(dice1, dice2) == 1:
return 1
else:
if count < 3:
rolling("N", dice2)
count += 1
elif 7 > count and count >= 3:
if count == 3:
rolling("E", dice2)
rolling("N", dice2)
count += 1
else:
return 0
flag = 0
for i in range(n):
for j in range(i + 1, n):
if alldice_matching(dice[i], dice[j]) == 1:
flag = 1
print("No")
break
if flag == 1:
break
if flag == 0:
print("Yes")
| false | 3.636364 |
[
"+def alldice_matching(dice1, dice2):",
"+ count = 0",
"+ while 1:",
"+ if dice_matching(dice1, dice2) == 1:",
"+ return 1",
"+ else:",
"+ if count < 3:",
"+ rolling(\"N\", dice2)",
"+ count += 1",
"+ elif 7 > count and count >= 3:",
"+ if count == 3:",
"+ rolling(\"E\", dice2)",
"+ rolling(\"N\", dice2)",
"+ count += 1",
"+ else:",
"+ return 0",
"+",
"+",
"- count = 0",
"- while 1:",
"- if dice_matching(dice[i], dice[j]) == 1:",
"- flag = 1",
"- print(\"No\")",
"- break",
"- else:",
"- if count < 3:",
"- rolling(\"N\", dice[j])",
"- count += 1",
"- elif 7 > count and count >= 3:",
"- if count == 3:",
"- rolling(\"E\", dice[j])",
"- rolling(\"N\", dice[j])",
"- count += 1",
"- else:",
"- break",
"- if flag == 1:",
"+ if alldice_matching(dice[i], dice[j]) == 1:",
"+ flag = 1",
"+ print(\"No\")"
] | false | 0.042259 | 0.042919 | 0.984629 |
[
"s889013990",
"s410941091"
] |
u638456847
|
p02888
|
python
|
s090397895
|
s008758872
| 980 | 871 | 3,184 | 3,188 |
Accepted
|
Accepted
| 11.12 |
import bisect
import time
def main():
N = int(eval(input()))
L = [int(i) for i in input().split()]
#N = 2000
#L = [int(i) for i in range(N)]
L.sort()
ans = 0
for i in range(N-2):
for j in range(i+1,N-1):
#ans += bisect.bisect_left(L[j+1:], L[i]+L[j])
index = bisect.bisect_left(L, L[i]+L[j])
ans += (index - (j+1))
print(ans)
if __name__ == "__main__":
#start = time.time()
main()
#elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
|
from bisect import bisect_left
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N = int(readline())
L = [int(i) for i in readline().split()]
L.sort()
ans = 0
for i in range(N-1):
L_i = L[i]
for j in range(i+1, N):
idx = bisect_left(L, L_i + L[j])
ans += idx - (j + 1)
print(ans)
if __name__ == "__main__":
main()
| 25 | 23 | 591 | 466 |
import bisect
import time
def main():
N = int(eval(input()))
L = [int(i) for i in input().split()]
# N = 2000
# L = [int(i) for i in range(N)]
L.sort()
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
# ans += bisect.bisect_left(L[j+1:], L[i]+L[j])
index = bisect.bisect_left(L, L[i] + L[j])
ans += index - (j + 1)
print(ans)
if __name__ == "__main__":
# start = time.time()
main()
# elapsed_time = time.time() - start
# print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
|
from bisect import bisect_left
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N = int(readline())
L = [int(i) for i in readline().split()]
L.sort()
ans = 0
for i in range(N - 1):
L_i = L[i]
for j in range(i + 1, N):
idx = bisect_left(L, L_i + L[j])
ans += idx - (j + 1)
print(ans)
if __name__ == "__main__":
main()
| false | 8 |
[
"-import bisect",
"-import time",
"+from bisect import bisect_left",
"+import sys",
"+",
"+read = sys.stdin.read",
"+readline = sys.stdin.readline",
"+readlines = sys.stdin.readlines",
"- N = int(eval(input()))",
"- L = [int(i) for i in input().split()]",
"- # N = 2000",
"- # L = [int(i) for i in range(N)]",
"+ N = int(readline())",
"+ L = [int(i) for i in readline().split()]",
"- for i in range(N - 2):",
"- for j in range(i + 1, N - 1):",
"- # ans += bisect.bisect_left(L[j+1:], L[i]+L[j])",
"- index = bisect.bisect_left(L, L[i] + L[j])",
"- ans += index - (j + 1)",
"+ for i in range(N - 1):",
"+ L_i = L[i]",
"+ for j in range(i + 1, N):",
"+ idx = bisect_left(L, L_i + L[j])",
"+ ans += idx - (j + 1)",
"- # start = time.time()",
"- # elapsed_time = time.time() - start",
"- # print (\"elapsed_time:{0}\".format(elapsed_time) + \"[sec]\")"
] | false | 0.045783 | 0.045592 | 1.00418 |
[
"s090397895",
"s008758872"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.