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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u970197315
|
p03682
|
python
|
s570650226
|
s818444363
| 1,724 | 1,179 | 49,660 | 51,024 |
Accepted
|
Accepted
| 31.61 |
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self,n):
self.n=[-1]*n
self.r=[0]*n
self.siz=n
def find_root(self,x):
if self.n[x]<0:
return x
else:
self.n[x]=self.find_root(self.n[x])
return self.n[x]
def unite(self,x,y):
x=self.find_root(x)
y=self.find_root(y)
if x==y:return
elif self.r[x]>self.r[y]:
self.n[x]+=self.n[y]
self.n[y]=x
else:
self.n[y]+=self.n[x]
self.n[x]=y
if self.r[x]==self.r[y]:
self.r[y]+=1
self.siz-=1
def root_same(self,x,y):
return self.find_root(x)==self.find_root(y)
def count(self,x):
return -self.n[self.find_root(x)]
def size(self):
return self.siz
n=int(eval(input()))
xy=[list(map(int,input().split()))+[i] for i in range(n)]
G=[]
# MSTを求める
xy.sort()
for j in range(1,n):
sx,sy,si=xy[j-1]
tx,ty,ti=xy[j]
G.append((min(abs(sx-tx),abs(sy-ty)),si,ti))
xy.sort(key=lambda x:x[1])
for j in range(1,n):
sx,sy,si=xy[j-1]
tx,ty,ti=xy[j]
G.append((min(abs(sx-tx),abs(sy-ty)),si,ti))
# Kruskal 法
u=UnionFind(n)
ans=0
G.sort()
for c,x,y in G:
if u.root_same(x,y):continue
u.unite(x,y)
ans+=c
print(ans)
|
import sys
sys.setrecursionlimit(10**7)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n = int(eval(input()))
xy = [list(map(int, input().split()))+[i] for i in range(n)]
G = []
xy.sort()
for j in range(1, n):
sx, sy, si = xy[j-1]
tx, ty, ti = xy[j]
G.append((min(abs(sx-tx), abs(sy-ty)), si, ti))
xy.sort(key=lambda x: x[1])
for j in range(1, n):
sx, sy, si = xy[j-1]
tx, ty, ti = xy[j]
G.append((min(abs(sx-tx), abs(sy-ty)), si, ti))
uf = UnionFind(n)
ans = 0
G.sort()
for c, x, y in G:
if uf.same(x, y):
continue
uf.union(x, y)
ans += c
print(ans)
| 59 | 75 | 1,245 | 1,767 |
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self, n):
self.n = [-1] * n
self.r = [0] * n
self.siz = n
def find_root(self, x):
if self.n[x] < 0:
return x
else:
self.n[x] = self.find_root(self.n[x])
return self.n[x]
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.r[x] > self.r[y]:
self.n[x] += self.n[y]
self.n[y] = x
else:
self.n[y] += self.n[x]
self.n[x] = y
if self.r[x] == self.r[y]:
self.r[y] += 1
self.siz -= 1
def root_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def count(self, x):
return -self.n[self.find_root(x)]
def size(self):
return self.siz
n = int(eval(input()))
xy = [list(map(int, input().split())) + [i] for i in range(n)]
G = []
# MSTを求める
xy.sort()
for j in range(1, n):
sx, sy, si = xy[j - 1]
tx, ty, ti = xy[j]
G.append((min(abs(sx - tx), abs(sy - ty)), si, ti))
xy.sort(key=lambda x: x[1])
for j in range(1, n):
sx, sy, si = xy[j - 1]
tx, ty, ti = xy[j]
G.append((min(abs(sx - tx), abs(sy - ty)), si, ti))
# Kruskal 法
u = UnionFind(n)
ans = 0
G.sort()
for c, x, y in G:
if u.root_same(x, y):
continue
u.unite(x, y)
ans += c
print(ans)
|
import sys
sys.setrecursionlimit(10**7)
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
n = int(eval(input()))
xy = [list(map(int, input().split())) + [i] for i in range(n)]
G = []
xy.sort()
for j in range(1, n):
sx, sy, si = xy[j - 1]
tx, ty, ti = xy[j]
G.append((min(abs(sx - tx), abs(sy - ty)), si, ti))
xy.sort(key=lambda x: x[1])
for j in range(1, n):
sx, sy, si = xy[j - 1]
tx, ty, ti = xy[j]
G.append((min(abs(sx - tx), abs(sy - ty)), si, ti))
uf = UnionFind(n)
ans = 0
G.sort()
for c, x, y in G:
if uf.same(x, y):
continue
uf.union(x, y)
ans += c
print(ans)
| false | 21.333333 |
[
"-sys.setrecursionlimit(10**9)",
"+sys.setrecursionlimit(10**7)",
"- self.n = [-1] * n",
"- self.r = [0] * n",
"- self.siz = n",
"+ self.n = n",
"+ self.parents = [-1] * n",
"- def find_root(self, x):",
"- if self.n[x] < 0:",
"+ def find(self, x):",
"+ if self.parents[x] < 0:",
"- self.n[x] = self.find_root(self.n[x])",
"- return self.n[x]",
"+ self.parents[x] = self.find(self.parents[x])",
"+ return self.parents[x]",
"- def unite(self, x, y):",
"- x = self.find_root(x)",
"- y = self.find_root(y)",
"+ def union(self, x, y):",
"+ x = self.find(x)",
"+ y = self.find(y)",
"- elif self.r[x] > self.r[y]:",
"- self.n[x] += self.n[y]",
"- self.n[y] = x",
"- else:",
"- self.n[y] += self.n[x]",
"- self.n[x] = y",
"- if self.r[x] == self.r[y]:",
"- self.r[y] += 1",
"- self.siz -= 1",
"+ if self.parents[x] > self.parents[y]:",
"+ x, y = y, x",
"+ self.parents[x] += self.parents[y]",
"+ self.parents[y] = x",
"- def root_same(self, x, y):",
"- return self.find_root(x) == self.find_root(y)",
"+ def size(self, x):",
"+ return -self.parents[self.find(x)]",
"- def count(self, x):",
"- return -self.n[self.find_root(x)]",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"- def size(self):",
"- return self.siz",
"+ def members(self, x):",
"+ root = self.find(x)",
"+ return [i for i in range(self.n) if self.find(i) == root]",
"+",
"+ def roots(self):",
"+ return [i for i, x in enumerate(self.parents) if x < 0]",
"+",
"+ def group_count(self):",
"+ return len(self.roots())",
"+",
"+ def all_group_members(self):",
"+ return {r: self.members(r) for r in self.roots()}",
"+",
"+ def __str__(self):",
"+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())",
"-# MSTを求める",
"-# Kruskal 法",
"-u = UnionFind(n)",
"+uf = UnionFind(n)",
"- if u.root_same(x, y):",
"+ if uf.same(x, y):",
"- u.unite(x, y)",
"+ uf.union(x, y)"
] | false | 0.074182 | 0.039614 | 1.872615 |
[
"s570650226",
"s818444363"
] |
u590241855
|
p02554
|
python
|
s515571672
|
s668246699
| 386 | 37 | 10,884 | 9,156 |
Accepted
|
Accepted
| 90.41 |
n = int(eval(input()))
mod = 10**9 + 7
ans = 10**n - 9**n * 2 + 8**n
ans %= mod
print(ans)
|
n = int(eval(input()))
mod = 10**9 + 7
ans = pow(10, n, mod) - pow(9, n, mod) * 2 + pow(8, n, mod)
ans %= mod
print(ans)
| 8 | 8 | 95 | 125 |
n = int(eval(input()))
mod = 10**9 + 7
ans = 10**n - 9**n * 2 + 8**n
ans %= mod
print(ans)
|
n = int(eval(input()))
mod = 10**9 + 7
ans = pow(10, n, mod) - pow(9, n, mod) * 2 + pow(8, n, mod)
ans %= mod
print(ans)
| false | 0 |
[
"-ans = 10**n - 9**n * 2 + 8**n",
"+ans = pow(10, n, mod) - pow(9, n, mod) * 2 + pow(8, n, mod)"
] | false | 0.144936 | 0.084248 | 1.720346 |
[
"s515571672",
"s668246699"
] |
u602252807
|
p02953
|
python
|
s087149755
|
s538381103
| 106 | 89 | 14,252 | 14,396 |
Accepted
|
Accepted
| 16.04 |
n = int(eval(input()))
h = list(map(int,input().split()))
M = h[0]
for i in range(n-1):
if h[i] >= h[i+1] + 2:
print("No")
exit()
if M > h[i+1] + 1:
print("No")
exit()
M = max(M,h[i+1])
print("Yes")
|
n = int(eval(input()))
h = list(map(int,input().split()))
M = h[0]
for i in range(n-1):
if M > h[i+1] + 1:
print("No")
exit()
M = max(M,h[i+1])
print("Yes")
| 14 | 10 | 251 | 184 |
n = int(eval(input()))
h = list(map(int, input().split()))
M = h[0]
for i in range(n - 1):
if h[i] >= h[i + 1] + 2:
print("No")
exit()
if M > h[i + 1] + 1:
print("No")
exit()
M = max(M, h[i + 1])
print("Yes")
|
n = int(eval(input()))
h = list(map(int, input().split()))
M = h[0]
for i in range(n - 1):
if M > h[i + 1] + 1:
print("No")
exit()
M = max(M, h[i + 1])
print("Yes")
| false | 28.571429 |
[
"- if h[i] >= h[i + 1] + 2:",
"- print(\"No\")",
"- exit()"
] | false | 0.035979 | 0.034626 | 1.039083 |
[
"s087149755",
"s538381103"
] |
u740284863
|
p03807
|
python
|
s214386839
|
s120273400
| 44 | 40 | 14,052 | 11,172 |
Accepted
|
Accepted
| 9.09 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int,input().split()))
if sum(A) % 2 == 0:
print("YES")
else:
print("NO")
|
import sys
input = sys.stdin.readline
eval(input())
print(('YES' if sum(map(int, input().split())) % 2 == 0 else 'NO'))
| 8 | 4 | 156 | 115 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int, input().split()))
if sum(A) % 2 == 0:
print("YES")
else:
print("NO")
|
import sys
input = sys.stdin.readline
eval(input())
print(("YES" if sum(map(int, input().split())) % 2 == 0 else "NO"))
| false | 50 |
[
"-n = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-if sum(A) % 2 == 0:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+eval(input())",
"+print((\"YES\" if sum(map(int, input().split())) % 2 == 0 else \"NO\"))"
] | false | 0.081254 | 0.048431 | 1.677715 |
[
"s214386839",
"s120273400"
] |
u744920373
|
p03575
|
python
|
s057945608
|
s074302312
| 108 | 20 | 3,188 | 3,064 |
Accepted
|
Accepted
| 81.48 |
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
## UnionFind
N, M = mi()
memo = []
rel = [[] for i in range(N)]
#d = dp2(float('inf'), N, N)
for i in range(M):
s, t = mi()
s, t = s-1, t-1
memo.append((s, t))
rel[s].append(t)
rel[t].append(s)
#d[s][t] = d[t][s] = 1
#print(d)
def dfs(v):
#print(v, used)
for nv in rel[v]:
#for nv in range(N):
if not used[nv]:
#if d[v][nv] != float('inf') and not used[nv]:
used[nv] = 1
dfs(nv)
if sum(used) == N:
global flag
flag = True
return
#used[nv] = 0
cnt = M
for x in range(M):
s, t = memo[x][0], memo[x][1]
rel[s].remove(t)
rel[t].remove(s)
#print(rel)
#print(s, t)
#d[s][t] = d[t][s] = float('inf')
#print(d)
for i in range(N):
#print(x, i)
flag = 0
used = [0]*N
used[i] = 1
dfs(i)
#print(flag)
if flag:
cnt -= 1
break
rel[s].append(t)
rel[t].append(s)
#d[s][t] = d[t][s] = 1
print(cnt)
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
## DFS
N, M = mi()
memo = []
rel = [[] for i in range(N)]
for i in range(M):
s, t = mi()
s, t = s-1, t-1
memo.append((s, t))
rel[s].append(t)
rel[t].append(s)
def dfs(v):
for nv in rel[v]:
if not used[nv]:
used[nv] = 1
dfs(nv)
if sum(used) == N:
global flag
flag = 1
return
cnt = M
for x in range(M):
s, t = memo[x][0], memo[x][1]
rel[s].remove(t)
rel[t].remove(s)
flag = 0
used = [0]*N
dfs(0)
if flag:
cnt -= 1
rel[s].append(t)
rel[t].append(s)
print(cnt)
| 66 | 49 | 1,712 | 1,259 |
import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j):
return [[ini] * i for _ in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for _ in range(j)] for _ in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from itertools import accumulate #list(accumulate(A))
## UnionFind
N, M = mi()
memo = []
rel = [[] for i in range(N)]
# d = dp2(float('inf'), N, N)
for i in range(M):
s, t = mi()
s, t = s - 1, t - 1
memo.append((s, t))
rel[s].append(t)
rel[t].append(s)
# d[s][t] = d[t][s] = 1
# print(d)
def dfs(v):
# print(v, used)
for nv in rel[v]:
# for nv in range(N):
if not used[nv]:
# if d[v][nv] != float('inf') and not used[nv]:
used[nv] = 1
dfs(nv)
if sum(used) == N:
global flag
flag = True
return
# used[nv] = 0
cnt = M
for x in range(M):
s, t = memo[x][0], memo[x][1]
rel[s].remove(t)
rel[t].remove(s)
# print(rel)
# print(s, t)
# d[s][t] = d[t][s] = float('inf')
# print(d)
for i in range(N):
# print(x, i)
flag = 0
used = [0] * N
used[i] = 1
dfs(i)
# print(flag)
if flag:
cnt -= 1
break
rel[s].append(t)
rel[t].append(s)
# d[s][t] = d[t][s] = 1
print(cnt)
|
import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j):
return [[ini] * i for _ in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for _ in range(j)] for _ in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from itertools import accumulate #list(accumulate(A))
## DFS
N, M = mi()
memo = []
rel = [[] for i in range(N)]
for i in range(M):
s, t = mi()
s, t = s - 1, t - 1
memo.append((s, t))
rel[s].append(t)
rel[t].append(s)
def dfs(v):
for nv in rel[v]:
if not used[nv]:
used[nv] = 1
dfs(nv)
if sum(used) == N:
global flag
flag = 1
return
cnt = M
for x in range(M):
s, t = memo[x][0], memo[x][1]
rel[s].remove(t)
rel[t].remove(s)
flag = 0
used = [0] * N
dfs(0)
if flag:
cnt -= 1
rel[s].append(t)
rel[t].append(s)
print(cnt)
| false | 25.757576 |
[
"-## UnionFind",
"+## DFS",
"-# d = dp2(float('inf'), N, N)",
"- # d[s][t] = d[t][s] = 1",
"-# print(d)",
"+",
"+",
"- # print(v, used)",
"- # for nv in range(N):",
"- # if d[v][nv] != float('inf') and not used[nv]:",
"- flag = True",
"+ flag = 1",
"- # used[nv] = 0",
"- # print(rel)",
"- # print(s, t)",
"- # d[s][t] = d[t][s] = float('inf')",
"- # print(d)",
"- for i in range(N):",
"- # print(x, i)",
"- flag = 0",
"- used = [0] * N",
"- used[i] = 1",
"- dfs(i)",
"- # print(flag)",
"- if flag:",
"- cnt -= 1",
"- break",
"+ flag = 0",
"+ used = [0] * N",
"+ dfs(0)",
"+ if flag:",
"+ cnt -= 1",
"- # d[s][t] = d[t][s] = 1"
] | false | 0.032015 | 0.037135 | 0.862138 |
[
"s057945608",
"s074302312"
] |
u977661421
|
p02732
|
python
|
s799558452
|
s061829840
| 714 | 288 | 109,364 | 33,336 |
Accepted
|
Accepted
| 59.66 |
# -*- coding: utf-8 -*-
import collections
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
if n == 0: return 0
if n == 1: return 0
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
"""
def cmb(n, r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
N = 3 * pow(10, 5) # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % mod)
#fact.append(fact[-1] * i)
inv.append((-inv[mod % i] * (mod // i)) % mod)
#inv.append(-inv[mod%i] * (mod // i))
factinv.append((factinv[-1] * inv[-1]) % mod)
#factinv.append(factinv[-1] * inv[-1])
"""
n = int(eval(input()))
a = [int(i) for i in input().split()]
count = [0 for _ in range(n+1)]
ans = [0 for _ in range(n+1)]
c = collections.Counter(a)
#print(c)
for i in range(n+1):
#tmp = a.count(i)
tmp = c[i]
#print(tmp)
count[i] = tmp
ans[i] = cmb(tmp, 2)
#print(tmp, ans[i])
#print(count, ans)
sum_ans = sum(ans)
#print(sum_ans)
for k in range(n):
#count[k] -= 1
#print(a[k], count[a[k]])
#print(count[a[k]] - 1 ,cmb(count[a[k]]-1, 2))
#print(count[a[k]] ,cmb(count[a[k]], 2))
ans = sum_ans + cmb(count[a[k]]-1, 2) - cmb(count[a[k]], 2)
print(ans)
|
""" スニペット """
def get_int():
return int(eval(input()))
def get_ints():
return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
return n*(n-1)//2
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
for i in range(N + 1):
sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
print((sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)))
| 75 | 27 | 1,917 | 580 |
# -*- coding: utf-8 -*-
import collections
def cmb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
if n == 0:
return 0
if n == 1:
return 0
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
"""
def cmb(n, r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
N = 3 * pow(10, 5) # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % mod)
#fact.append(fact[-1] * i)
inv.append((-inv[mod % i] * (mod // i)) % mod)
#inv.append(-inv[mod%i] * (mod // i))
factinv.append((factinv[-1] * inv[-1]) % mod)
#factinv.append(factinv[-1] * inv[-1])
"""
n = int(eval(input()))
a = [int(i) for i in input().split()]
count = [0 for _ in range(n + 1)]
ans = [0 for _ in range(n + 1)]
c = collections.Counter(a)
# print(c)
for i in range(n + 1):
# tmp = a.count(i)
tmp = c[i]
# print(tmp)
count[i] = tmp
ans[i] = cmb(tmp, 2)
# print(tmp, ans[i])
# print(count, ans)
sum_ans = sum(ans)
# print(sum_ans)
for k in range(n):
# count[k] -= 1
# print(a[k], count[a[k]])
# print(count[a[k]] - 1 ,cmb(count[a[k]]-1, 2))
# print(count[a[k]] ,cmb(count[a[k]], 2))
ans = sum_ans + cmb(count[a[k]] - 1, 2) - cmb(count[a[k]], 2)
print(ans)
|
""" スニペット """
def get_int():
return int(eval(input()))
def get_ints():
return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
return n * (n - 1) // 2
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N + 1)
# ユニーク数の配列を求める
for i in range(N):
uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
for i in range(N + 1):
sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
print((sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]] - 1)))
| false | 64 |
[
"-# -*- coding: utf-8 -*-",
"-import collections",
"+\"\"\" スニペット \"\"\"",
"-def cmb(n, r):",
"- if n - r < r:",
"- r = n - r",
"- if r == 0:",
"- return 1",
"- if r == 1:",
"- return n",
"- if n == 0:",
"- return 0",
"- if n == 1:",
"- return 0",
"- numerator = [n - r + k + 1 for k in range(r)]",
"- denominator = [k + 1 for k in range(r)]",
"- for p in range(2, r + 1):",
"- pivot = denominator[p - 1]",
"- if pivot > 1:",
"- offset = (n - r) % p",
"- for k in range(p - 1, r, p):",
"- numerator[k - offset] /= pivot",
"- denominator[k] /= pivot",
"- result = 1",
"- for k in range(r):",
"- if numerator[k] > 1:",
"- result *= int(numerator[k])",
"- return result",
"+def get_int():",
"+ return int(eval(input()))",
"-\"\"\"",
"-def cmb(n, r):",
"- if (r < 0) or (n < r):",
"- return 0",
"- r = min(r, n - r)",
"- return fact[n] * factinv[r] * factinv[n-r] % mod",
"-N = 3 * pow(10, 5) # N は必要分だけ用意する",
"-mod = pow(10, 9) + 7",
"-fact = [1, 1] # fact[n] = (n! mod p)",
"-factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)",
"-inv = [0, 1] # factinv 計算用",
"-for i in range(2, N + 1):",
"- fact.append((fact[-1] * i) % mod)",
"- #fact.append(fact[-1] * i)",
"- inv.append((-inv[mod % i] * (mod // i)) % mod)",
"- #inv.append(-inv[mod%i] * (mod // i))",
"- factinv.append((factinv[-1] * inv[-1]) % mod)",
"- #factinv.append(factinv[-1] * inv[-1])",
"-\"\"\"",
"-n = int(eval(input()))",
"-a = [int(i) for i in input().split()]",
"-count = [0 for _ in range(n + 1)]",
"-ans = [0 for _ in range(n + 1)]",
"-c = collections.Counter(a)",
"-# print(c)",
"-for i in range(n + 1):",
"- # tmp = a.count(i)",
"- tmp = c[i]",
"- # print(tmp)",
"- count[i] = tmp",
"- ans[i] = cmb(tmp, 2)",
"- # print(tmp, ans[i])",
"-# print(count, ans)",
"-sum_ans = sum(ans)",
"-# print(sum_ans)",
"-for k in range(n):",
"- # count[k] -= 1",
"- # print(a[k], count[a[k]])",
"- # print(count[a[k]] - 1 ,cmb(count[a[k]]-1, 2))",
"- # print(count[a[k]] ,cmb(count[a[k]], 2))",
"- ans = sum_ans + cmb(count[a[k]] - 1, 2) - cmb(count[a[k]], 2)",
"- print(ans)",
"+def get_ints():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+\"\"\" スニペット \"\"\"",
"+import math",
"+",
"+# 2つ選ぶ通り数を算出 nC2",
"+def choose2(n):",
"+ return n * (n - 1) // 2",
"+",
"+",
"+# インプット",
"+N = get_int()",
"+An = get_ints()",
"+\"\"\" 全ての要素から2つのボールを選ぶ通り数を求める \"\"\"",
"+uni = [0] * (N + 1)",
"+# ユニーク数の配列を求める",
"+for i in range(N):",
"+ uni[An[i]] += 1",
"+sumWay = 0",
"+# 各数値の2通りの選択通り数を足していく",
"+for i in range(N + 1):",
"+ sumWay += choose2(uni[i])",
"+\"\"\" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める \"\"\"",
"+for i in range(N):",
"+ print((sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]] - 1)))"
] | false | 0.03483 | 0.037513 | 0.928468 |
[
"s799558452",
"s061829840"
] |
u991567869
|
p02732
|
python
|
s990241035
|
s925505706
| 309 | 202 | 26,780 | 39,352 |
Accepted
|
Accepted
| 34.63 |
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i*(i - 1)//2 for i in list(b.values()))
for i in a:
print((total - (b[i] - 1)))
|
def ban():
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i*(i - 1)//2 for i in list(b.values()))
ans = [(total - (b[i] - 1)) for i in a]
return "\n".join(map(str, ans))
print((ban()))
| 9 | 11 | 197 | 281 |
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i * (i - 1) // 2 for i in list(b.values()))
for i in a:
print((total - (b[i] - 1)))
|
def ban():
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i * (i - 1) // 2 for i in list(b.values()))
ans = [(total - (b[i] - 1)) for i in a]
return "\n".join(map(str, ans))
print((ban()))
| false | 18.181818 |
[
"-from collections import Counter",
"+def ban():",
"+ from collections import Counter",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-b = Counter(a)",
"-total = sum(i * (i - 1) // 2 for i in list(b.values()))",
"-for i in a:",
"- print((total - (b[i] - 1)))",
"+ n = int(eval(input()))",
"+ a = list(map(int, input().split()))",
"+ b = Counter(a)",
"+ total = sum(i * (i - 1) // 2 for i in list(b.values()))",
"+ ans = [(total - (b[i] - 1)) for i in a]",
"+ return \"\\n\".join(map(str, ans))",
"+",
"+",
"+print((ban()))"
] | false | 0.043729 | 0.085102 | 0.513841 |
[
"s990241035",
"s925505706"
] |
u273084112
|
p03628
|
python
|
s061679921
|
s219541591
| 19 | 17 | 3,188 | 3,064 |
Accepted
|
Accepted
| 10.53 |
n = int(eval(input()))
s1 = eval(input())
s2 = eval(input())
mod = 1000000007
num = 1
i = 0
b = 0
tmp_t = -1
while(b + i < n):
if s1[i + b] == s2[i + b]: # t 0
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 1) % mod
else:
num = 3
tmp_t = 0
else: # t 1
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 3) % mod
else:
num = 6
tmp_t = 1
b += 1
i += 1
print(num)
|
n = int(eval(input()))
s1 = eval(input()) + " "
s2 = eval(input()) + " "
mod = 1000000007
num = 1
i = 0
b = 0
tmp_t = -1
while(b + i < n):
if s1[i + b] == s2[i + b]: # t 0
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 1) % mod
else:
num = 3
tmp_t = 0
else: # t 1
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 3) % mod
else:
num = 6
tmp_t = 1
b += 1
i += 1
print(num)
| 31 | 31 | 568 | 582 |
n = int(eval(input()))
s1 = eval(input())
s2 = eval(input())
mod = 1000000007
num = 1
i = 0
b = 0
tmp_t = -1
while b + i < n:
if s1[i + b] == s2[i + b]: # t 0
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 1) % mod
else:
num = 3
tmp_t = 0
else: # t 1
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 3) % mod
else:
num = 6
tmp_t = 1
b += 1
i += 1
print(num)
|
n = int(eval(input()))
s1 = eval(input()) + " "
s2 = eval(input()) + " "
mod = 1000000007
num = 1
i = 0
b = 0
tmp_t = -1
while b + i < n:
if s1[i + b] == s2[i + b]: # t 0
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 1) % mod
else:
num = 3
tmp_t = 0
else: # t 1
if tmp_t == 0:
num = (num * 2) % mod
elif tmp_t == 1:
num = (num * 3) % mod
else:
num = 6
tmp_t = 1
b += 1
i += 1
print(num)
| false | 0 |
[
"-s1 = eval(input())",
"-s2 = eval(input())",
"+s1 = eval(input()) + \" \"",
"+s2 = eval(input()) + \" \""
] | false | 0.082215 | 0.008196 | 10.031295 |
[
"s061679921",
"s219541591"
] |
u493520238
|
p03108
|
python
|
s042519488
|
s319628391
| 694 | 623 | 24,504 | 24,520 |
Accepted
|
Accepted
| 10.23 |
import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n, m = list(map(int, input().split()))
abl = []
for _ in range(m):
a,b = list(map(int, input().split()))
abl.append((a,b))
uf = UnionFind(n)
ans_r = []
curr_ans_minus = 0
for ab in reversed(abl):
a,b = ab
if not uf.same(a-1,b-1):
a_size = uf.size(a-1)
b_size = uf.size(b-1)
curr_ans_minus += (a_size+b_size)*(a_size+b_size-1)//2
curr_ans_minus -= (a_size*(a_size-1)//2 + b_size*(b_size-1)//2)
uf.union(a-1,b-1)
ans_r.append(curr_ans_minus)
all_sum = n*(n-1)//2
for v in reversed(ans_r[:-1]):
print((all_sum-v))
print(all_sum)
|
import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
n, m = list(map(int, input().split()))
abl = []
for _ in range(m):
a,b = list(map(int, input().split()))
abl.append((a,b))
uf = UnionFind(n)
ans_r = []
curr_ans_minus = 0
for ab in reversed(abl):
a,b = ab
if not uf.same(a-1,b-1):
a_size = uf.size(a-1)
b_size = uf.size(b-1)
curr_ans_minus += (a_size+b_size)*(a_size+b_size-1)//2
curr_ans_minus -= (a_size*(a_size-1)//2 + b_size*(b_size-1)//2)
uf.union(a-1,b-1)
ans_r.append(curr_ans_minus)
all_sum = n*(n-1)//2
for v in reversed(ans_r[:-1]):
print((all_sum-v))
print(all_sum)
if __name__ == "__main__":
main()
| 76 | 80 | 1,843 | 1,981 |
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
n, m = list(map(int, input().split()))
abl = []
for _ in range(m):
a, b = list(map(int, input().split()))
abl.append((a, b))
uf = UnionFind(n)
ans_r = []
curr_ans_minus = 0
for ab in reversed(abl):
a, b = ab
if not uf.same(a - 1, b - 1):
a_size = uf.size(a - 1)
b_size = uf.size(b - 1)
curr_ans_minus += (a_size + b_size) * (a_size + b_size - 1) // 2
curr_ans_minus -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2
uf.union(a - 1, b - 1)
ans_r.append(curr_ans_minus)
all_sum = n * (n - 1) // 2
for v in reversed(ans_r[:-1]):
print((all_sum - v))
print(all_sum)
|
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
n, m = list(map(int, input().split()))
abl = []
for _ in range(m):
a, b = list(map(int, input().split()))
abl.append((a, b))
uf = UnionFind(n)
ans_r = []
curr_ans_minus = 0
for ab in reversed(abl):
a, b = ab
if not uf.same(a - 1, b - 1):
a_size = uf.size(a - 1)
b_size = uf.size(b - 1)
curr_ans_minus += (a_size + b_size) * (a_size + b_size - 1) // 2
curr_ans_minus -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2
uf.union(a - 1, b - 1)
ans_r.append(curr_ans_minus)
all_sum = n * (n - 1) // 2
for v in reversed(ans_r[:-1]):
print((all_sum - v))
print(all_sum)
if __name__ == "__main__":
main()
| false | 5 |
[
"-n, m = list(map(int, input().split()))",
"-abl = []",
"-for _ in range(m):",
"- a, b = list(map(int, input().split()))",
"- abl.append((a, b))",
"-uf = UnionFind(n)",
"-ans_r = []",
"-curr_ans_minus = 0",
"-for ab in reversed(abl):",
"- a, b = ab",
"- if not uf.same(a - 1, b - 1):",
"- a_size = uf.size(a - 1)",
"- b_size = uf.size(b - 1)",
"- curr_ans_minus += (a_size + b_size) * (a_size + b_size - 1) // 2",
"- curr_ans_minus -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2",
"- uf.union(a - 1, b - 1)",
"- ans_r.append(curr_ans_minus)",
"-all_sum = n * (n - 1) // 2",
"-for v in reversed(ans_r[:-1]):",
"- print((all_sum - v))",
"-print(all_sum)",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ abl = []",
"+ for _ in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ abl.append((a, b))",
"+ uf = UnionFind(n)",
"+ ans_r = []",
"+ curr_ans_minus = 0",
"+ for ab in reversed(abl):",
"+ a, b = ab",
"+ if not uf.same(a - 1, b - 1):",
"+ a_size = uf.size(a - 1)",
"+ b_size = uf.size(b - 1)",
"+ curr_ans_minus += (a_size + b_size) * (a_size + b_size - 1) // 2",
"+ curr_ans_minus -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2",
"+ uf.union(a - 1, b - 1)",
"+ ans_r.append(curr_ans_minus)",
"+ all_sum = n * (n - 1) // 2",
"+ for v in reversed(ans_r[:-1]):",
"+ print((all_sum - v))",
"+ print(all_sum)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.038437 | 0.066352 | 0.579284 |
[
"s042519488",
"s319628391"
] |
u627600101
|
p02787
|
python
|
s703927250
|
s549475792
| 275 | 105 | 82,852 | 74,408 |
Accepted
|
Accepted
| 61.82 |
import sys
sys.setrecursionlimit(10**9)
H, N = list(map(int, input().split()))
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0]/magic[k][1])
magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]
def solve(start, power, point, maryoku):
if start == H:
print((min(point, min(anskouho))))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start+power, power, point+maryoku, maryoku)
for k in range(N):
for item in visited:
solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
print((min(anskouho)))
|
#import sys
#sys.setrecursionlimit(10**9)
H, N = list(map(int, input().split()))
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0]/magic[k][1])
magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]
ans2 = float('inf')
"""
def solve(start, power, point, maryoku):
if start == H:
print(min(point, min(anskouho)))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
for item in visited:
#solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
start = item+magic[k][0]
power = magic[k][0]
point = ans[item]+ magic[k][1]
maryoku = magic[k][1]
for _ in range(10**5):
if start == H:
print((min(point, ans2)))
exit()
elif start > H:
ans2 = min(ans2, point)
break
elif ans[start]!=0:
break
else:
visited.append(start)
ans[start] = point
start += power
point += maryoku
print(ans2)
| 34 | 53 | 819 | 1,298 |
import sys
sys.setrecursionlimit(10**9)
H, N = list(map(int, input().split()))
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0] / magic[k][1])
magic.sort(key=lambda x: x[2], reverse=True)
ans = [0 for _ in range(H + 1)]
visited = [0]
anskouho = [float("inf")]
def solve(start, power, point, maryoku):
if start == H:
print((min(point, min(anskouho))))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start + power, power, point + maryoku, maryoku)
for k in range(N):
for item in visited:
solve(item + magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
print((min(anskouho)))
|
# import sys
# sys.setrecursionlimit(10**9)
H, N = list(map(int, input().split()))
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0] / magic[k][1])
magic.sort(key=lambda x: x[2], reverse=True)
ans = [0 for _ in range(H + 1)]
visited = [0]
anskouho = [float("inf")]
ans2 = float("inf")
"""
def solve(start, power, point, maryoku):
if start == H:
print(min(point, min(anskouho)))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
for item in visited:
# solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
start = item + magic[k][0]
power = magic[k][0]
point = ans[item] + magic[k][1]
maryoku = magic[k][1]
for _ in range(10**5):
if start == H:
print((min(point, ans2)))
exit()
elif start > H:
ans2 = min(ans2, point)
break
elif ans[start] != 0:
break
else:
visited.append(start)
ans[start] = point
start += power
point += maryoku
print(ans2)
| false | 35.849057 |
[
"-import sys",
"-",
"-sys.setrecursionlimit(10**9)",
"+# import sys",
"+# sys.setrecursionlimit(10**9)",
"-",
"-",
"+ans2 = float(\"inf\")",
"+\"\"\"",
"- if start == H:",
"- print((min(point, min(anskouho))))",
"- exit()",
"- elif start > H:",
"- anskouho.append(point)",
"- return 0",
"- elif ans[start] != 0:",
"- return 0",
"- else:",
"- visited.append(start)",
"- ans[start] = point",
"- solve(start + power, power, point + maryoku, maryoku)",
"-",
"-",
"+ if start == H:",
"+ print(min(point, min(anskouho)))",
"+ exit()",
"+ elif start > H:",
"+ anskouho.append(point)",
"+ return 0",
"+ elif ans[start] != 0:",
"+ return 0",
"+ else:",
"+ visited.append(start)",
"+ ans[start] = point",
"+ solve(start+power, power, point+maryoku, maryoku)",
"+\"\"\"",
"- solve(item + magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])",
"-print((min(anskouho)))",
"+ # solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])",
"+ start = item + magic[k][0]",
"+ power = magic[k][0]",
"+ point = ans[item] + magic[k][1]",
"+ maryoku = magic[k][1]",
"+ for _ in range(10**5):",
"+ if start == H:",
"+ print((min(point, ans2)))",
"+ exit()",
"+ elif start > H:",
"+ ans2 = min(ans2, point)",
"+ break",
"+ elif ans[start] != 0:",
"+ break",
"+ else:",
"+ visited.append(start)",
"+ ans[start] = point",
"+ start += power",
"+ point += maryoku",
"+print(ans2)"
] | false | 0.081155 | 0.039853 | 2.036351 |
[
"s703927250",
"s549475792"
] |
u272075541
|
p02947
|
python
|
s497968426
|
s253387994
| 988 | 677 | 17,332 | 17,332 |
Accepted
|
Accepted
| 31.48 |
import collections
chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z"]
def eratosthenes_sieve(n):
primes = [2]
for odd in range(3, n + 1, 2):
for p in primes:
if odd % p == 0:
break
if p ** 2 > odd:
primes.append(odd)
break
return primes
era = eratosthenes_sieve(150)
n = int(eval(input()))
array = [0] * n
for i in range(n):
new = eval(input())
var = 1
for j in range(10):
h = chars.index(new[j])
var *= era[h]
array[i] = var
c = collections.Counter(array)
cv = list(c.values())
ans = 0
for i in range(len(c)):
ans += cv[i] * (cv[i] - 1) // 2
print(ans)
|
# ABC137C_GreenBin.py
# ちなみに D は DP, E は ヘルマンフォード法 の良問。
import collections
"""
英子文字 26 個を素数で置き換えて掛け合わせると、アナグラムの組は同じ値となる。
1 <= i < j <= n であって、 si が sj のアナグラムであるようなものの個数を求める。
"""
def eratosthenes_sieve(n):
primes = [2]
for odd in range(3, n + 1, 2):
for p in primes:
if odd % p == 0:
break
if p ** 2 > odd:
primes.append(odd)
break
return primes
# 入力と同時にアナグラムを素数の積に変換
Era = eratosthenes_sieve(150) # 小さいほうから素数 26 個あまり用意する
chars = "abcdefghijklmnopqrstuvwxyz" # Python では文字列もイテラブル
N = int(eval(input()))
array = [0] * N
for i in range(N):
new = eval(input())
var = 1
for j in range(10):
h = chars.index(new[j])
var *= Era[h]
array[i] = var
# 加工と出力
kinds = collections.Counter(array)
kind = list(kinds.values())
print((sum(kind[i] * (kind[i] - 1) // 2 for i in range(len(kinds)))))
"""
# collection モジュールのまとめ
Counter は辞書型 dict のサブクラスで、キーに要素、値に出現回数という形のデータを持つ。
キーのリスト(keys()メソッド)、値のリスト(values())、
キーと値のペアのタプルのリスト(items()メソッド)を取得したりできる。
リストに変換したい場合はlist()を使えばよい。
"""
| 38 | 48 | 813 | 1,129 |
import collections
chars = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
def eratosthenes_sieve(n):
primes = [2]
for odd in range(3, n + 1, 2):
for p in primes:
if odd % p == 0:
break
if p**2 > odd:
primes.append(odd)
break
return primes
era = eratosthenes_sieve(150)
n = int(eval(input()))
array = [0] * n
for i in range(n):
new = eval(input())
var = 1
for j in range(10):
h = chars.index(new[j])
var *= era[h]
array[i] = var
c = collections.Counter(array)
cv = list(c.values())
ans = 0
for i in range(len(c)):
ans += cv[i] * (cv[i] - 1) // 2
print(ans)
|
# ABC137C_GreenBin.py
# ちなみに D は DP, E は ヘルマンフォード法 の良問。
import collections
"""
英子文字 26 個を素数で置き換えて掛け合わせると、アナグラムの組は同じ値となる。
1 <= i < j <= n であって、 si が sj のアナグラムであるようなものの個数を求める。
"""
def eratosthenes_sieve(n):
primes = [2]
for odd in range(3, n + 1, 2):
for p in primes:
if odd % p == 0:
break
if p**2 > odd:
primes.append(odd)
break
return primes
# 入力と同時にアナグラムを素数の積に変換
Era = eratosthenes_sieve(150) # 小さいほうから素数 26 個あまり用意する
chars = "abcdefghijklmnopqrstuvwxyz" # Python では文字列もイテラブル
N = int(eval(input()))
array = [0] * N
for i in range(N):
new = eval(input())
var = 1
for j in range(10):
h = chars.index(new[j])
var *= Era[h]
array[i] = var
# 加工と出力
kinds = collections.Counter(array)
kind = list(kinds.values())
print((sum(kind[i] * (kind[i] - 1) // 2 for i in range(len(kinds)))))
"""
# collection モジュールのまとめ
Counter は辞書型 dict のサブクラスで、キーに要素、値に出現回数という形のデータを持つ。
キーのリスト(keys()メソッド)、値のリスト(values())、
キーと値のペアのタプルのリスト(items()メソッド)を取得したりできる。
リストに変換したい場合はlist()を使えばよい。
"""
| false | 20.833333 |
[
"+# ABC137C_GreenBin.py",
"+# ちなみに D は DP, E は ヘルマンフォード法 の良問。",
"-chars = [",
"- \"a\",",
"- \"b\",",
"- \"c\",",
"- \"d\",",
"- \"e\",",
"- \"f\",",
"- \"g\",",
"- \"h\",",
"- \"i\",",
"- \"j\",",
"- \"k\",",
"- \"l\",",
"- \"m\",",
"- \"n\",",
"- \"o\",",
"- \"p\",",
"- \"q\",",
"- \"r\",",
"- \"s\",",
"- \"t\",",
"- \"u\",",
"- \"v\",",
"- \"w\",",
"- \"x\",",
"- \"y\",",
"- \"z\",",
"-]",
"+\"\"\"",
"+英子文字 26 個を素数で置き換えて掛け合わせると、アナグラムの組は同じ値となる。",
"+1 <= i < j <= n であって、 si が sj のアナグラムであるようなものの個数を求める。",
"+\"\"\"",
"-era = eratosthenes_sieve(150)",
"-n = int(eval(input()))",
"-array = [0] * n",
"-for i in range(n):",
"+# 入力と同時にアナグラムを素数の積に変換",
"+Era = eratosthenes_sieve(150) # 小さいほうから素数 26 個あまり用意する",
"+chars = \"abcdefghijklmnopqrstuvwxyz\" # Python では文字列もイテラブル",
"+N = int(eval(input()))",
"+array = [0] * N",
"+for i in range(N):",
"- var *= era[h]",
"+ var *= Era[h]",
"-c = collections.Counter(array)",
"-cv = list(c.values())",
"-ans = 0",
"-for i in range(len(c)):",
"- ans += cv[i] * (cv[i] - 1) // 2",
"-print(ans)",
"+# 加工と出力",
"+kinds = collections.Counter(array)",
"+kind = list(kinds.values())",
"+print((sum(kind[i] * (kind[i] - 1) // 2 for i in range(len(kinds)))))",
"+\"\"\"",
"+# collection モジュールのまとめ",
"+Counter は辞書型 dict のサブクラスで、キーに要素、値に出現回数という形のデータを持つ。",
"+キーのリスト(keys()メソッド)、値のリスト(values())、",
"+キーと値のペアのタプルのリスト(items()メソッド)を取得したりできる。",
"+リストに変換したい場合はlist()を使えばよい。",
"+\"\"\""
] | false | 0.075001 | 0.07499 | 1.00015 |
[
"s497968426",
"s253387994"
] |
u377989038
|
p02989
|
python
|
s470386319
|
s977540041
| 248 | 92 | 23,404 | 14,428 |
Accepted
|
Accepted
| 62.9 |
import numpy as np
n = int(eval(input()))
d = np.array(sorted((list(map(int, input().split())))))
if len(d[d <= d[n // 2 - 1]]) == n // 2:
print((d[n // 2] - d[n // 2 - 1]))
else:
print((0))
|
n = int(eval(input()))
d = sorted((list(map(int, input().split()))))
if len([i for i in d if d[n // 2 - 1] >= i]) == n // 2:
print((d[n // 2] - d[n // 2 - 1]))
else:
print((0))
| 9 | 7 | 198 | 181 |
import numpy as np
n = int(eval(input()))
d = np.array(sorted((list(map(int, input().split())))))
if len(d[d <= d[n // 2 - 1]]) == n // 2:
print((d[n // 2] - d[n // 2 - 1]))
else:
print((0))
|
n = int(eval(input()))
d = sorted((list(map(int, input().split()))))
if len([i for i in d if d[n // 2 - 1] >= i]) == n // 2:
print((d[n // 2] - d[n // 2 - 1]))
else:
print((0))
| false | 22.222222 |
[
"-import numpy as np",
"-",
"-d = np.array(sorted((list(map(int, input().split())))))",
"-if len(d[d <= d[n // 2 - 1]]) == n // 2:",
"+d = sorted((list(map(int, input().split()))))",
"+if len([i for i in d if d[n // 2 - 1] >= i]) == n // 2:"
] | false | 0.301211 | 0.037867 | 7.954469 |
[
"s470386319",
"s977540041"
] |
u073852194
|
p03798
|
python
|
s654863767
|
s694129964
| 251 | 171 | 3,444 | 10,716 |
Accepted
|
Accepted
| 31.87 |
N = int(eval(input()))
s = eval(input())
def solve(ans):
for i in range(2,N):
if ans[i-2]=='S' and ans[i-1]=='S':
if s[i-1]=='o':
ans += 'S'
else:
ans += 'W'
elif ans[i-2]=='S' and ans[i-1]=='W':
if s[i-1]=='o':
ans += 'W'
else:
ans += 'S'
elif ans[i-2]=='W' and ans[i-1]=='S':
if s[i-1]=='o':
ans += 'W'
else:
ans += 'S'
else:
if s[i-1]=='o':
ans += 'S'
else:
ans += 'W'
if (ans[0]=='S' and s[0]=='o') or (ans[0]=='W' and s[0]=='x'):
if ans[-1]!=ans[1]:
return
elif (ans[0]=='S' and s[0]=='x') or (ans[0]=='W' and s[0]=='o'):
if ans[-1]==ans[1]:
return
if (ans[-1]=='S' and s[-1]=='o') or (ans[-1]=='W' and s[-1]=='x'):
if ans[-2]!=ans[0]:
return
elif (ans[-1]=='S' and s[-1]=='x') or (ans[-1]=='W' and s[-1]=='o'):
if ans[-2]==ans[0]:
return
return ans
C = ['SS','SW','WS','WW']
for c in C:
if solve(c):
print((solve(c)))
break
else:
print((-1))
|
N = int(input())
S = input()
assignable = False
for k in range(4):
res = [None for _ in range(N)]
res[0] = k % 2
res[-1] = k // 2
for i in range(N - 2):
if S[i] == 'o':
if res[i] == 0:
res[i + 1] = res[i - 1]
else:
res[i + 1] = 1 - res[i - 1]
else:
if res[i] == 0:
res[i + 1] = 1 - res[i - 1]
else:
res[i + 1] = res[i - 1]
if S[-2] == 'o':
if res[-2] == 0:
if res[-1] != res[-3]:
continue
else:
if res[-1] != 1 - res[-3]:
continue
else:
if res[-2] == 0:
if res[-1] != 1 - res[-3]:
continue
else:
if res[-1] != res[-3]:
continue
if S[-1] == 'o':
if res[-1] == 0:
if res[0] == res[-2]:
assignable = True
else:
if res[0] == 1 - res[-2]:
assignable = True
else:
if res[-1] == 0:
if res[0] == 1 - res[-2]:
assignable = True
else:
if res[0] == res[-2]:
assignable = True
if assignable:
for i in range(N):
if res[i]:
print('W', end='')
else:
print('S', end='')
break
else:
print(-1)
| 46 | 57 | 1,262 | 1,461 |
N = int(eval(input()))
s = eval(input())
def solve(ans):
for i in range(2, N):
if ans[i - 2] == "S" and ans[i - 1] == "S":
if s[i - 1] == "o":
ans += "S"
else:
ans += "W"
elif ans[i - 2] == "S" and ans[i - 1] == "W":
if s[i - 1] == "o":
ans += "W"
else:
ans += "S"
elif ans[i - 2] == "W" and ans[i - 1] == "S":
if s[i - 1] == "o":
ans += "W"
else:
ans += "S"
else:
if s[i - 1] == "o":
ans += "S"
else:
ans += "W"
if (ans[0] == "S" and s[0] == "o") or (ans[0] == "W" and s[0] == "x"):
if ans[-1] != ans[1]:
return
elif (ans[0] == "S" and s[0] == "x") or (ans[0] == "W" and s[0] == "o"):
if ans[-1] == ans[1]:
return
if (ans[-1] == "S" and s[-1] == "o") or (ans[-1] == "W" and s[-1] == "x"):
if ans[-2] != ans[0]:
return
elif (ans[-1] == "S" and s[-1] == "x") or (ans[-1] == "W" and s[-1] == "o"):
if ans[-2] == ans[0]:
return
return ans
C = ["SS", "SW", "WS", "WW"]
for c in C:
if solve(c):
print((solve(c)))
break
else:
print((-1))
|
N = int(input())
S = input()
assignable = False
for k in range(4):
res = [None for _ in range(N)]
res[0] = k % 2
res[-1] = k // 2
for i in range(N - 2):
if S[i] == "o":
if res[i] == 0:
res[i + 1] = res[i - 1]
else:
res[i + 1] = 1 - res[i - 1]
else:
if res[i] == 0:
res[i + 1] = 1 - res[i - 1]
else:
res[i + 1] = res[i - 1]
if S[-2] == "o":
if res[-2] == 0:
if res[-1] != res[-3]:
continue
else:
if res[-1] != 1 - res[-3]:
continue
else:
if res[-2] == 0:
if res[-1] != 1 - res[-3]:
continue
else:
if res[-1] != res[-3]:
continue
if S[-1] == "o":
if res[-1] == 0:
if res[0] == res[-2]:
assignable = True
else:
if res[0] == 1 - res[-2]:
assignable = True
else:
if res[-1] == 0:
if res[0] == 1 - res[-2]:
assignable = True
else:
if res[0] == res[-2]:
assignable = True
if assignable:
for i in range(N):
if res[i]:
print("W", end="")
else:
print("S", end="")
break
else:
print(-1)
| false | 19.298246 |
[
"-N = int(eval(input()))",
"-s = eval(input())",
"-",
"-",
"-def solve(ans):",
"- for i in range(2, N):",
"- if ans[i - 2] == \"S\" and ans[i - 1] == \"S\":",
"- if s[i - 1] == \"o\":",
"- ans += \"S\"",
"+N = int(input())",
"+S = input()",
"+assignable = False",
"+for k in range(4):",
"+ res = [None for _ in range(N)]",
"+ res[0] = k % 2",
"+ res[-1] = k // 2",
"+ for i in range(N - 2):",
"+ if S[i] == \"o\":",
"+ if res[i] == 0:",
"+ res[i + 1] = res[i - 1]",
"- ans += \"W\"",
"- elif ans[i - 2] == \"S\" and ans[i - 1] == \"W\":",
"- if s[i - 1] == \"o\":",
"- ans += \"W\"",
"+ res[i + 1] = 1 - res[i - 1]",
"+ else:",
"+ if res[i] == 0:",
"+ res[i + 1] = 1 - res[i - 1]",
"- ans += \"S\"",
"- elif ans[i - 2] == \"W\" and ans[i - 1] == \"S\":",
"- if s[i - 1] == \"o\":",
"- ans += \"W\"",
"+ res[i + 1] = res[i - 1]",
"+ if S[-2] == \"o\":",
"+ if res[-2] == 0:",
"+ if res[-1] != res[-3]:",
"+ continue",
"+ else:",
"+ if res[-1] != 1 - res[-3]:",
"+ continue",
"+ else:",
"+ if res[-2] == 0:",
"+ if res[-1] != 1 - res[-3]:",
"+ continue",
"+ else:",
"+ if res[-1] != res[-3]:",
"+ continue",
"+ if S[-1] == \"o\":",
"+ if res[-1] == 0:",
"+ if res[0] == res[-2]:",
"+ assignable = True",
"+ else:",
"+ if res[0] == 1 - res[-2]:",
"+ assignable = True",
"+ else:",
"+ if res[-1] == 0:",
"+ if res[0] == 1 - res[-2]:",
"+ assignable = True",
"+ else:",
"+ if res[0] == res[-2]:",
"+ assignable = True",
"+ if assignable:",
"+ for i in range(N):",
"+ if res[i]:",
"+ print(\"W\", end=\"\")",
"- ans += \"S\"",
"- else:",
"- if s[i - 1] == \"o\":",
"- ans += \"S\"",
"- else:",
"- ans += \"W\"",
"- if (ans[0] == \"S\" and s[0] == \"o\") or (ans[0] == \"W\" and s[0] == \"x\"):",
"- if ans[-1] != ans[1]:",
"- return",
"- elif (ans[0] == \"S\" and s[0] == \"x\") or (ans[0] == \"W\" and s[0] == \"o\"):",
"- if ans[-1] == ans[1]:",
"- return",
"- if (ans[-1] == \"S\" and s[-1] == \"o\") or (ans[-1] == \"W\" and s[-1] == \"x\"):",
"- if ans[-2] != ans[0]:",
"- return",
"- elif (ans[-1] == \"S\" and s[-1] == \"x\") or (ans[-1] == \"W\" and s[-1] == \"o\"):",
"- if ans[-2] == ans[0]:",
"- return",
"- return ans",
"-",
"-",
"-C = [\"SS\", \"SW\", \"WS\", \"WW\"]",
"-for c in C:",
"- if solve(c):",
"- print((solve(c)))",
"+ print(\"S\", end=\"\")",
"- print((-1))",
"+ print(-1)"
] | false | 0.038401 | 0.07835 | 0.490125 |
[
"s654863767",
"s694129964"
] |
u305366205
|
p03807
|
python
|
s960409660
|
s467788567
| 61 | 50 | 14,112 | 14,108 |
Accepted
|
Accepted
| 18.03 |
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
if a[i] % 2 == 1:
cnt += 1
if cnt % 2 == 0:
print('YES')
else:
print('NO')
|
n = eval(input())
a = list(map(int, input().split()))
# Python: TrueとFalseは0,1と等価
odd_cnt = len([1 for ai in a if ai % 2])
print(('YES' if odd_cnt % 2 == 0 else 'NO'))
| 10 | 5 | 183 | 163 |
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
if a[i] % 2 == 1:
cnt += 1
if cnt % 2 == 0:
print("YES")
else:
print("NO")
|
n = eval(input())
a = list(map(int, input().split()))
# Python: TrueとFalseは0,1と等価
odd_cnt = len([1 for ai in a if ai % 2])
print(("YES" if odd_cnt % 2 == 0 else "NO"))
| false | 50 |
[
"-n = int(eval(input()))",
"+n = eval(input())",
"-cnt = 0",
"-for i in range(n):",
"- if a[i] % 2 == 1:",
"- cnt += 1",
"-if cnt % 2 == 0:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+# Python: TrueとFalseは0,1と等価",
"+odd_cnt = len([1 for ai in a if ai % 2])",
"+print((\"YES\" if odd_cnt % 2 == 0 else \"NO\"))"
] | false | 0.048985 | 0.048565 | 1.008651 |
[
"s960409660",
"s467788567"
] |
u179169725
|
p03078
|
python
|
s341504192
|
s075022983
| 594 | 41 | 4,084 | 5,232 |
Accepted
|
Accepted
| 93.1 |
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方
# これもなかなか早い
# ヒープは追加も要素の取り出しもO(log n)で住むので、
# 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが
# not in があるのでO(n K log n)では?
# pythonのヒープは使い方に癖があるのでこの機会に習得しよう
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
from heapq import heapify, heappop, heappush, heappushpop
class PriorityQueue:
def __init__(self, heap):
'''
heap ... list
'''
self.heap = heap
heapify(self.heap)
def push(self, item):
heappush(self.heap, item)
def pop(self):
return heappop(self.heap)
def pushpop(self, item):
return heappushpop(self.heap, item)
def __call__(self):
return self.heap
heap = [] # ヒープといっても順序を工夫したただのリスト
q = PriorityQueue(heap)
q.push((-(A[0] + B[0] + C[0]), 0, 0, 0))
ans = []
for k_th in range(1, K+1):
heap_max, i, j, k = q.pop()
# print(heap_max)
ans.append(-heap_max)
for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
i_new, j_new, k_new = i + di, j + dj, k + dk
if i_new >= X or j_new >= Y or k_new >= Z:
continue
tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)
if tmp in q(): # ここが計算量がおおい
continue
q.push(tmp)
print(*ans, sep='\n')
|
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方
# これもなかなか早い
# ヒープは追加も要素の取り出しもO(log n)で住むので、
# 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが
# not in があるのでO(n K log n)では?
# pythonのヒープは使い方に癖があるのでこの機会に習得しよう
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
from heapq import heapify, heappop, heappush, heappushpop
class PriorityQueue:
def __init__(self, heap):
'''
heap ... list
'''
self.heap = heap
heapify(self.heap)
def push(self, item):
heappush(self.heap, item)
def pop(self):
return heappop(self.heap)
def pushpop(self, item):
return heappushpop(self.heap, item)
def __call__(self):
return self.heap
heap = [] # ヒープといっても順序を工夫したただのリスト
q = PriorityQueue(heap)
q.push((-(A[0] + B[0] + C[0]), 0, 0, 0))
considered = set()
ans = []
for k_th in range(1, K+1):
heap_max, i, j, k = q.pop()
ans.append(-heap_max)
for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
i_new, j_new, k_new = i + di, j + dj, k + dk
if i_new >= X or j_new >= Y or k_new >= Z:
continue
if (i_new, j_new, k_new) in considered:
continue
considered.add((i_new, j_new, k_new))
q.push((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new))
print(*ans, sep='\n')
| 69 | 69 | 1,521 | 1,557 |
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方
# これもなかなか早い
# ヒープは追加も要素の取り出しもO(log n)で住むので、
# 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが
# not in があるのでO(n K log n)では?
# pythonのヒープは使い方に癖があるのでこの機会に習得しよう
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
from heapq import heapify, heappop, heappush, heappushpop
class PriorityQueue:
def __init__(self, heap):
"""
heap ... list
"""
self.heap = heap
heapify(self.heap)
def push(self, item):
heappush(self.heap, item)
def pop(self):
return heappop(self.heap)
def pushpop(self, item):
return heappushpop(self.heap, item)
def __call__(self):
return self.heap
heap = [] # ヒープといっても順序を工夫したただのリスト
q = PriorityQueue(heap)
q.push((-(A[0] + B[0] + C[0]), 0, 0, 0))
ans = []
for k_th in range(1, K + 1):
heap_max, i, j, k = q.pop()
# print(heap_max)
ans.append(-heap_max)
for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
i_new, j_new, k_new = i + di, j + dj, k + dk
if i_new >= X or j_new >= Y or k_new >= Z:
continue
tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)
if tmp in q(): # ここが計算量がおおい
continue
q.push(tmp)
print(*ans, sep="\n")
|
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方
# これもなかなか早い
# ヒープは追加も要素の取り出しもO(log n)で住むので、
# 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが
# not in があるのでO(n K log n)では?
# pythonのヒープは使い方に癖があるのでこの機会に習得しよう
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
X, Y, Z, K = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
from heapq import heapify, heappop, heappush, heappushpop
class PriorityQueue:
def __init__(self, heap):
"""
heap ... list
"""
self.heap = heap
heapify(self.heap)
def push(self, item):
heappush(self.heap, item)
def pop(self):
return heappop(self.heap)
def pushpop(self, item):
return heappushpop(self.heap, item)
def __call__(self):
return self.heap
heap = [] # ヒープといっても順序を工夫したただのリスト
q = PriorityQueue(heap)
q.push((-(A[0] + B[0] + C[0]), 0, 0, 0))
considered = set()
ans = []
for k_th in range(1, K + 1):
heap_max, i, j, k = q.pop()
ans.append(-heap_max)
for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
i_new, j_new, k_new = i + di, j + dj, k + dk
if i_new >= X or j_new >= Y or k_new >= Z:
continue
if (i_new, j_new, k_new) in considered:
continue
considered.add((i_new, j_new, k_new))
q.push((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new))
print(*ans, sep="\n")
| false | 0 |
[
"+considered = set()",
"- # print(heap_max)",
"- tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)",
"- if tmp in q(): # ここが計算量がおおい",
"+ if (i_new, j_new, k_new) in considered:",
"- q.push(tmp)",
"+ considered.add((i_new, j_new, k_new))",
"+ q.push((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new))"
] | false | 0.060739 | 0.03692 | 1.645144 |
[
"s341504192",
"s075022983"
] |
u218843509
|
p02651
|
python
|
s869315012
|
s435580511
| 93 | 76 | 68,644 | 73,764 |
Accepted
|
Accepted
| 18.28 |
t = int(eval(input()))
for _ in range(t):
n = int(eval(input()))
a = list(map(int, input().split()))
s = eval(input())
basis = []
ans = 0
for i in range(n-1, -1, -1):
if s[i] == "0":
for b in basis:
a[i] = min(a[i], a[i]^b)
if a[i]:
basis.append(a[i])
else:
for b in basis:
a[i] = min(a[i], a[i]^b)
if a[i]:
ans = 1
break
print(ans)
|
for _ in range(int(eval(input()))):
n = int(eval(input()))
a = list(map(int, input().split()))
s = eval(input())
basis = []
ans = 0
for i in range(n-1, -1, -1):
for b in basis:
a[i] = min(a[i], a[i]^b)
if a[i]:
if s[i] == "0":
basis.append(a[i])
else:
ans = 1
break
print(ans)
| 20 | 16 | 376 | 305 |
t = int(eval(input()))
for _ in range(t):
n = int(eval(input()))
a = list(map(int, input().split()))
s = eval(input())
basis = []
ans = 0
for i in range(n - 1, -1, -1):
if s[i] == "0":
for b in basis:
a[i] = min(a[i], a[i] ^ b)
if a[i]:
basis.append(a[i])
else:
for b in basis:
a[i] = min(a[i], a[i] ^ b)
if a[i]:
ans = 1
break
print(ans)
|
for _ in range(int(eval(input()))):
n = int(eval(input()))
a = list(map(int, input().split()))
s = eval(input())
basis = []
ans = 0
for i in range(n - 1, -1, -1):
for b in basis:
a[i] = min(a[i], a[i] ^ b)
if a[i]:
if s[i] == "0":
basis.append(a[i])
else:
ans = 1
break
print(ans)
| false | 20 |
[
"-t = int(eval(input()))",
"-for _ in range(t):",
"+for _ in range(int(eval(input()))):",
"- if s[i] == \"0\":",
"- for b in basis:",
"- a[i] = min(a[i], a[i] ^ b)",
"- if a[i]:",
"+ for b in basis:",
"+ a[i] = min(a[i], a[i] ^ b)",
"+ if a[i]:",
"+ if s[i] == \"0\":",
"- else:",
"- for b in basis:",
"- a[i] = min(a[i], a[i] ^ b)",
"- if a[i]:",
"+ else:"
] | false | 0.037275 | 0.046707 | 0.798064 |
[
"s869315012",
"s435580511"
] |
u121921603
|
p02913
|
python
|
s872214372
|
s356729873
| 888 | 806 | 231,432 | 52,588 |
Accepted
|
Accepted
| 9.23 |
import sys
input = sys.stdin.readline
N=int(eval(input()))
S=input().strip()
dp=[[0]*(N+1) for _ in range(N+1)]
for i in range(N-1,-1,-1):
for j in range(N-1,i,-1):
if S[i]==S[j]:
dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1)
#print(dp)
ans=0
for i in range(N):
for j in range(N):
ans=max(ans,min(dp[i][j],j-i))
print(ans)
|
import sys
input = sys.stdin.readline
N=int(eval(input()))
S=input().strip()
"""dp=[[0]*(N+1) for _ in range(N+1)]
for i in range(N-1,-1,-1):
for j in range(N-1,i,-1):
if S[i]==S[j]:
dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1)
#print(dp)
ans=0
for i in range(N):
for j in range(N):
ans=max(ans,min(dp[i][j],j-i))
print(ans)
"""
def Z_algo(S):
n = len(S)
LCP = [0]*n
i = 1
j = 0
c = 0#最も末尾側までLCPを求めたインデックス
for i in range(1, n):
#i番目からのLCPが以前計算したcからのLCPに含まれている場合
if i+LCP[i-c] < c+LCP[c]:
LCP[i] = LCP[i-c]
else:
j = max(0, c+LCP[c]-i)
while i+j < n and S[j] == S[i+j]: j+=1
LCP[i] = j
c = i
LCP[0] = n
return LCP
ans=0
for i in range(N):
LCP=Z_algo(S[i:])
#print(LCP)
for j , l in enumerate(LCP):
tmp=min(l,j)
ans=max(ans,tmp)
print(ans)
| 15 | 43 | 359 | 949 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
S = input().strip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for j in range(N - 1, i, -1):
if S[i] == S[j]:
dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)
# print(dp)
ans = 0
for i in range(N):
for j in range(N):
ans = max(ans, min(dp[i][j], j - i))
print(ans)
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
S = input().strip()
"""dp=[[0]*(N+1) for _ in range(N+1)]
for i in range(N-1,-1,-1):
for j in range(N-1,i,-1):
if S[i]==S[j]:
dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1)
#print(dp)
ans=0
for i in range(N):
for j in range(N):
ans=max(ans,min(dp[i][j],j-i))
print(ans)
"""
def Z_algo(S):
n = len(S)
LCP = [0] * n
i = 1
j = 0
c = 0 # 最も末尾側までLCPを求めたインデックス
for i in range(1, n):
# i番目からのLCPが以前計算したcからのLCPに含まれている場合
if i + LCP[i - c] < c + LCP[c]:
LCP[i] = LCP[i - c]
else:
j = max(0, c + LCP[c] - i)
while i + j < n and S[j] == S[i + j]:
j += 1
LCP[i] = j
c = i
LCP[0] = n
return LCP
ans = 0
for i in range(N):
LCP = Z_algo(S[i:])
# print(LCP)
for j, l in enumerate(LCP):
tmp = min(l, j)
ans = max(ans, tmp)
print(ans)
| false | 65.116279 |
[
"-dp = [[0] * (N + 1) for _ in range(N + 1)]",
"-for i in range(N - 1, -1, -1):",
"- for j in range(N - 1, i, -1):",
"- if S[i] == S[j]:",
"- dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)",
"-# print(dp)",
"+\"\"\"dp=[[0]*(N+1) for _ in range(N+1)]",
"+for i in range(N-1,-1,-1):",
"+ for j in range(N-1,i,-1):",
"+ if S[i]==S[j]:",
"+ dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1)",
"+#print(dp)",
"+ans=0",
"+for i in range(N):",
"+ for j in range(N):",
"+ ans=max(ans,min(dp[i][j],j-i))",
"+print(ans)",
"+\"\"\"",
"+",
"+",
"+def Z_algo(S):",
"+ n = len(S)",
"+ LCP = [0] * n",
"+ i = 1",
"+ j = 0",
"+ c = 0 # 最も末尾側までLCPを求めたインデックス",
"+ for i in range(1, n):",
"+ # i番目からのLCPが以前計算したcからのLCPに含まれている場合",
"+ if i + LCP[i - c] < c + LCP[c]:",
"+ LCP[i] = LCP[i - c]",
"+ else:",
"+ j = max(0, c + LCP[c] - i)",
"+ while i + j < n and S[j] == S[i + j]:",
"+ j += 1",
"+ LCP[i] = j",
"+ c = i",
"+ LCP[0] = n",
"+ return LCP",
"+",
"+",
"- for j in range(N):",
"- ans = max(ans, min(dp[i][j], j - i))",
"+ LCP = Z_algo(S[i:])",
"+ # print(LCP)",
"+ for j, l in enumerate(LCP):",
"+ tmp = min(l, j)",
"+ ans = max(ans, tmp)"
] | false | 0.048166 | 0.049086 | 0.981245 |
[
"s872214372",
"s356729873"
] |
u774160580
|
p03361
|
python
|
s638487904
|
s049274510
| 45 | 20 | 4,080 | 3,064 |
Accepted
|
Accepted
| 55.56 |
import queue as q
direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]
H, W = list(map(int, input().split()))
s = []
for i in range(H):
s_i = eval(input())
s.append([s_i[i] for i in range(len(s_i))])
def do_bfs(s, que):
while True:
if que.empty():
break
pos = que.get()
for arrow in direction:
next = [pos[0] + arrow[0], pos[1] + arrow[1]]
if next[0] == -1 or next[0] == H or next[1] == -1 or next[1] == W:
continue
if s[next[0]][next[1]] == "#":
que.put(next)
s[next[0]][next[1]] = "."
for i in range(H):
for j in range(W):
if s[i][j] == "#":
# check not isolated
is_conneted = False
for arrow in direction:
neighbor = [i + arrow[0], j + arrow[1]]
if (
neighbor[0] == -1
or neighbor[0] == H
or neighbor[1] == -1
or neighbor[1] == W
):
continue
if s[neighbor[0]][neighbor[1]] == "#":
is_conneted = True
break
if is_conneted:
s[i][j] = "."
que = q.Queue()
que.put([i, j])
do_bfs(s, que)
# check
for i in range(H):
for j in range(W):
if s[i][j] == "#":
print("No")
exit()
print("Yes")
|
H, W = list(map(int, input().split()))
s = []
for i in range(H):
s_i = eval(input())
s.append([s_i[i] for i in range(len(s_i))])
direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]
for i in range(H):
for j in range(W):
if s[i][j] == "#":
# check isolated
is_isolated = True
for arrow in direction:
neigh = [i + arrow[0], j + arrow[1]]
if neigh[0] == -1 or neigh[0] == H or neigh[1] == -1 or neigh[1] == W:
continue
if s[neigh[0]][neigh[1]] == "#":
is_isolated = False
break
if is_isolated:
print("No")
exit()
print("Yes")
| 54 | 22 | 1,520 | 734 |
import queue as q
direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]
H, W = list(map(int, input().split()))
s = []
for i in range(H):
s_i = eval(input())
s.append([s_i[i] for i in range(len(s_i))])
def do_bfs(s, que):
while True:
if que.empty():
break
pos = que.get()
for arrow in direction:
next = [pos[0] + arrow[0], pos[1] + arrow[1]]
if next[0] == -1 or next[0] == H or next[1] == -1 or next[1] == W:
continue
if s[next[0]][next[1]] == "#":
que.put(next)
s[next[0]][next[1]] = "."
for i in range(H):
for j in range(W):
if s[i][j] == "#":
# check not isolated
is_conneted = False
for arrow in direction:
neighbor = [i + arrow[0], j + arrow[1]]
if (
neighbor[0] == -1
or neighbor[0] == H
or neighbor[1] == -1
or neighbor[1] == W
):
continue
if s[neighbor[0]][neighbor[1]] == "#":
is_conneted = True
break
if is_conneted:
s[i][j] = "."
que = q.Queue()
que.put([i, j])
do_bfs(s, que)
# check
for i in range(H):
for j in range(W):
if s[i][j] == "#":
print("No")
exit()
print("Yes")
|
H, W = list(map(int, input().split()))
s = []
for i in range(H):
s_i = eval(input())
s.append([s_i[i] for i in range(len(s_i))])
direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]
for i in range(H):
for j in range(W):
if s[i][j] == "#":
# check isolated
is_isolated = True
for arrow in direction:
neigh = [i + arrow[0], j + arrow[1]]
if neigh[0] == -1 or neigh[0] == H or neigh[1] == -1 or neigh[1] == W:
continue
if s[neigh[0]][neigh[1]] == "#":
is_isolated = False
break
if is_isolated:
print("No")
exit()
print("Yes")
| false | 59.259259 |
[
"-import queue as q",
"-",
"-direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]",
"-",
"-",
"-def do_bfs(s, que):",
"- while True:",
"- if que.empty():",
"- break",
"- pos = que.get()",
"- for arrow in direction:",
"- next = [pos[0] + arrow[0], pos[1] + arrow[1]]",
"- if next[0] == -1 or next[0] == H or next[1] == -1 or next[1] == W:",
"- continue",
"- if s[next[0]][next[1]] == \"#\":",
"- que.put(next)",
"- s[next[0]][next[1]] = \".\"",
"-",
"-",
"+direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]",
"- # check not isolated",
"- is_conneted = False",
"+ # check isolated",
"+ is_isolated = True",
"- neighbor = [i + arrow[0], j + arrow[1]]",
"- if (",
"- neighbor[0] == -1",
"- or neighbor[0] == H",
"- or neighbor[1] == -1",
"- or neighbor[1] == W",
"- ):",
"+ neigh = [i + arrow[0], j + arrow[1]]",
"+ if neigh[0] == -1 or neigh[0] == H or neigh[1] == -1 or neigh[1] == W:",
"- if s[neighbor[0]][neighbor[1]] == \"#\":",
"- is_conneted = True",
"+ if s[neigh[0]][neigh[1]] == \"#\":",
"+ is_isolated = False",
"- if is_conneted:",
"- s[i][j] = \".\"",
"- que = q.Queue()",
"- que.put([i, j])",
"- do_bfs(s, que)",
"-# check",
"-for i in range(H):",
"- for j in range(W):",
"- if s[i][j] == \"#\":",
"- print(\"No\")",
"- exit()",
"+ if is_isolated:",
"+ print(\"No\")",
"+ exit()"
] | false | 0.070351 | 0.038243 | 1.839588 |
[
"s638487904",
"s049274510"
] |
u600402037
|
p02802
|
python
|
s715298605
|
s430810928
| 285 | 180 | 4,596 | 5,364 |
Accepted
|
Accepted
| 36.84 |
import sys
#import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N, M = rl()
solve = [False] * (N+1)
count = [0] * (N+1)
penalty = 0
for i in range(M):
p, s = input().split()
p = int(p)
if solve[p]:
continue
if s == 'WA':
count[p] += 1
else:
solve[p] = True
penalty += count[p]
print((sum(solve), penalty))
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
problems = [False] * N
AC = [0] * N
WA = [0] * N
for _ in range(M):
p, S = sr().split(); p = int(p) - 1
if not problems[p] and S == 'WA':
WA[p] += 1
if not problems[p] and S == 'AC':
problems[p] = True
AC[p] += 1
AC_total = sum(AC)
WA_total = sum(y for x, y in zip(AC, WA) if x)
print((AC_total, WA_total))
| 25 | 21 | 537 | 495 |
import sys
# import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N, M = rl()
solve = [False] * (N + 1)
count = [0] * (N + 1)
penalty = 0
for i in range(M):
p, s = input().split()
p = int(p)
if solve[p]:
continue
if s == "WA":
count[p] += 1
else:
solve[p] = True
penalty += count[p]
print((sum(solve), penalty))
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
problems = [False] * N
AC = [0] * N
WA = [0] * N
for _ in range(M):
p, S = sr().split()
p = int(p) - 1
if not problems[p] and S == "WA":
WA[p] += 1
if not problems[p] and S == "AC":
problems[p] = True
AC[p] += 1
AC_total = sum(AC)
WA_total = sum(y for x, y in zip(AC, WA) if x)
print((AC_total, WA_total))
| false | 16 |
[
"-# import numpy as np",
"-stdin = sys.stdin",
"-ri = lambda: int(rs())",
"-rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only",
"-rs = lambda: stdin.readline().rstrip() # ignore trailing spaces",
"-N, M = rl()",
"-solve = [False] * (N + 1)",
"-count = [0] * (N + 1)",
"-penalty = 0",
"-for i in range(M):",
"- p, s = input().split()",
"- p = int(p)",
"- if solve[p]:",
"- continue",
"- if s == \"WA\":",
"- count[p] += 1",
"- else:",
"- solve[p] = True",
"- penalty += count[p]",
"-print((sum(solve), penalty))",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lambda: int(sr())",
"+lr = lambda: list(map(int, sr().split()))",
"+N, M = lr()",
"+problems = [False] * N",
"+AC = [0] * N",
"+WA = [0] * N",
"+for _ in range(M):",
"+ p, S = sr().split()",
"+ p = int(p) - 1",
"+ if not problems[p] and S == \"WA\":",
"+ WA[p] += 1",
"+ if not problems[p] and S == \"AC\":",
"+ problems[p] = True",
"+ AC[p] += 1",
"+AC_total = sum(AC)",
"+WA_total = sum(y for x, y in zip(AC, WA) if x)",
"+print((AC_total, WA_total))"
] | false | 0.044069 | 0.12428 | 0.354593 |
[
"s715298605",
"s430810928"
] |
u977982384
|
p02577
|
python
|
s892226069
|
s608774446
| 217 | 55 | 9,204 | 10,552 |
Accepted
|
Accepted
| 74.65 |
N = int( eval(input()) )
if N % 9 == 0 :
print('Yes')
if N % 9 != 0 :
print('No')
|
n = eval(input( ))
result = sum(list(map(int, str(n))))
if result % 9 == 0 :
print('Yes')
else :
print('No')
| 5 | 8 | 89 | 123 |
N = int(eval(input()))
if N % 9 == 0:
print("Yes")
if N % 9 != 0:
print("No")
|
n = eval(input())
result = sum(list(map(int, str(n))))
if result % 9 == 0:
print("Yes")
else:
print("No")
| false | 37.5 |
[
"-N = int(eval(input()))",
"-if N % 9 == 0:",
"+n = eval(input())",
"+result = sum(list(map(int, str(n))))",
"+if result % 9 == 0:",
"-if N % 9 != 0:",
"+else:"
] | false | 0.035983 | 0.077926 | 0.461754 |
[
"s892226069",
"s608774446"
] |
u133936772
|
p03379
|
python
|
s496919081
|
s999411977
| 325 | 186 | 25,220 | 30,848 |
Accepted
|
Accepted
| 42.77 |
m=int(eval(input()))//2-1
x=list(map(int,input().split()))
l,r=sorted(x)[m:m+2]
for i in x: print(([l,r][i<r]))
|
n=int(eval(input()))
x=[*list(map(int,input().split()))]
s=sorted(x)
l,r=s[n//2-1],s[n//2]
for i in x:
print(([l,r][i<r]))
| 4 | 6 | 106 | 115 |
m = int(eval(input())) // 2 - 1
x = list(map(int, input().split()))
l, r = sorted(x)[m : m + 2]
for i in x:
print(([l, r][i < r]))
|
n = int(eval(input()))
x = [*list(map(int, input().split()))]
s = sorted(x)
l, r = s[n // 2 - 1], s[n // 2]
for i in x:
print(([l, r][i < r]))
| false | 33.333333 |
[
"-m = int(eval(input())) // 2 - 1",
"-x = list(map(int, input().split()))",
"-l, r = sorted(x)[m : m + 2]",
"+n = int(eval(input()))",
"+x = [*list(map(int, input().split()))]",
"+s = sorted(x)",
"+l, r = s[n // 2 - 1], s[n // 2]"
] | false | 0.039475 | 0.038895 | 1.014914 |
[
"s496919081",
"s999411977"
] |
u580697892
|
p03102
|
python
|
s307998496
|
s802795858
| 967 | 18 | 21,656 | 3,060 |
Accepted
|
Accepted
| 98.14 |
#coding: utf-8
import numpy as np
N, M, C = list(map(int, input().split()))
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(N)])
sum_ = np.array([np.sum(A[i] * B) + C for i in range(N)])
print((np.sum(sum_ > 0)))
|
#coding: utf-8
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
l = []
for i in range(N):
A = list(map(int, input().split()))
l.append(sum(A[j] * B[j] for j in range(M)) + C > 0)
print((sum(l)))
| 7 | 8 | 269 | 230 |
# coding: utf-8
import numpy as np
N, M, C = list(map(int, input().split()))
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(N)])
sum_ = np.array([np.sum(A[i] * B) + C for i in range(N)])
print((np.sum(sum_ > 0)))
|
# coding: utf-8
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
l = []
for i in range(N):
A = list(map(int, input().split()))
l.append(sum(A[j] * B[j] for j in range(M)) + C > 0)
print((sum(l)))
| false | 12.5 |
[
"-import numpy as np",
"-",
"-B = np.array(list(map(int, input().split())))",
"-A = np.array([list(map(int, input().split())) for _ in range(N)])",
"-sum_ = np.array([np.sum(A[i] * B) + C for i in range(N)])",
"-print((np.sum(sum_ > 0)))",
"+B = list(map(int, input().split()))",
"+l = []",
"+for i in range(N):",
"+ A = list(map(int, input().split()))",
"+ l.append(sum(A[j] * B[j] for j in range(M)) + C > 0)",
"+print((sum(l)))"
] | false | 0.345302 | 0.037897 | 9.111505 |
[
"s307998496",
"s802795858"
] |
u997641430
|
p02721
|
python
|
s846670753
|
s988713153
| 315 | 253 | 69,832 | 22,316 |
Accepted
|
Accepted
| 19.68 |
n, k, c = list(map(int, input().split()))
S = list(eval(input()))
def f(S):
L = []
on = True
cnt = 0
for i in range(n):
if not on:
if cnt == c:
on = True
cnt += 1
if on and S[i] == 'o':
on = False
cnt = 0
L.append(i)
if len(L) == k:
break
return L
L = f(S)
R = [n-1-i for i in f(S[::-1])][::-1]
for i in range(k):
if L[i] == R[i]:
print((L[i]+1))
|
def work(S, k, c):
tir = 0
cnt = 0
for i, s in enumerate(S):
if s == 'o' and tir == 0 and cnt < k:
yield i
tir = c
cnt += 1
else:
tir = max(tir-1, 0)
n, k, c = list(map(int, input().split()))
S = list(eval(input()))
L = [i+1 for i in work(S, k, c)]
R = [n-i for i in work(S[::-1], k, c)][::-1]
for l, r in zip(L, R):
if l == r:
print(l)
| 27 | 19 | 515 | 433 |
n, k, c = list(map(int, input().split()))
S = list(eval(input()))
def f(S):
L = []
on = True
cnt = 0
for i in range(n):
if not on:
if cnt == c:
on = True
cnt += 1
if on and S[i] == "o":
on = False
cnt = 0
L.append(i)
if len(L) == k:
break
return L
L = f(S)
R = [n - 1 - i for i in f(S[::-1])][::-1]
for i in range(k):
if L[i] == R[i]:
print((L[i] + 1))
|
def work(S, k, c):
tir = 0
cnt = 0
for i, s in enumerate(S):
if s == "o" and tir == 0 and cnt < k:
yield i
tir = c
cnt += 1
else:
tir = max(tir - 1, 0)
n, k, c = list(map(int, input().split()))
S = list(eval(input()))
L = [i + 1 for i in work(S, k, c)]
R = [n - i for i in work(S[::-1], k, c)][::-1]
for l, r in zip(L, R):
if l == r:
print(l)
| false | 29.62963 |
[
"+def work(S, k, c):",
"+ tir = 0",
"+ cnt = 0",
"+ for i, s in enumerate(S):",
"+ if s == \"o\" and tir == 0 and cnt < k:",
"+ yield i",
"+ tir = c",
"+ cnt += 1",
"+ else:",
"+ tir = max(tir - 1, 0)",
"+",
"+",
"-",
"-",
"-def f(S):",
"- L = []",
"- on = True",
"- cnt = 0",
"- for i in range(n):",
"- if not on:",
"- if cnt == c:",
"- on = True",
"- cnt += 1",
"- if on and S[i] == \"o\":",
"- on = False",
"- cnt = 0",
"- L.append(i)",
"- if len(L) == k:",
"- break",
"- return L",
"-",
"-",
"-L = f(S)",
"-R = [n - 1 - i for i in f(S[::-1])][::-1]",
"-for i in range(k):",
"- if L[i] == R[i]:",
"- print((L[i] + 1))",
"+L = [i + 1 for i in work(S, k, c)]",
"+R = [n - i for i in work(S[::-1], k, c)][::-1]",
"+for l, r in zip(L, R):",
"+ if l == r:",
"+ print(l)"
] | false | 0.043888 | 0.045492 | 0.964743 |
[
"s846670753",
"s988713153"
] |
u020390084
|
p02845
|
python
|
s501199953
|
s444091999
| 336 | 122 | 14,324 | 14,376 |
Accepted
|
Accepted
| 63.69 |
#!/usr/bin/env python3
import sys
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]"):
if A[0] != 0:
print((0))
return
## 一番多い色の帽子の数
color = [1,0,0]
answer = 3
for i in range(1,N):
if A[i] not in color:
print((0))
return
count = color.count(A[i])
answer *= count
for j in range(len(color)):
if color[j] == A[i]:
color[j]+=1
break
print((answer%MOD))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return list(map(int,input().split()))
def LI(): return list(map(int,input().split()))
def main():
N = INT()
A = LI()
RGB = [0,0,0]
answer = 1
MOD = 10**9+7
for i in range(N):
if RGB.count(A[i]) == 0:
print((0))
return
answer *= RGB.count(A[i])
answer %= MOD
for j in range(3):
if RGB[j] == A[i]:
RGB[j] += 1
break
print(answer)
return
if __name__ == '__main__':
main()
| 44 | 31 | 895 | 635 |
#!/usr/bin/env python3
import sys
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]"):
if A[0] != 0:
print((0))
return
## 一番多い色の帽子の数
color = [1, 0, 0]
answer = 3
for i in range(1, N):
if A[i] not in color:
print((0))
return
count = color.count(A[i])
answer *= count
for j in range(len(color)):
if color[j] == A[i]:
color[j] += 1
break
print((answer % MOD))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
N = INT()
A = LI()
RGB = [0, 0, 0]
answer = 1
MOD = 10**9 + 7
for i in range(N):
if RGB.count(A[i]) == 0:
print((0))
return
answer *= RGB.count(A[i])
answer %= MOD
for j in range(3):
if RGB[j] == A[i]:
RGB[j] += 1
break
print(answer)
return
if __name__ == "__main__":
main()
| false | 29.545455 |
[
"-MOD = 1000000007 # type: int",
"+input = sys.stdin.readline",
"-def solve(N: int, A: \"List[int]\"):",
"- if A[0] != 0:",
"- print((0))",
"- return",
"- ## 一番多い色の帽子の数",
"- color = [1, 0, 0]",
"- answer = 3",
"- for i in range(1, N):",
"- if A[i] not in color:",
"- print((0))",
"- return",
"- count = color.count(A[i])",
"- answer *= count",
"- for j in range(len(color)):",
"- if color[j] == A[i]:",
"- color[j] += 1",
"- break",
"- print((answer % MOD))",
"- return",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"- def iterate_tokens():",
"- for line in sys.stdin:",
"- for word in line.split():",
"- yield word",
"-",
"- tokens = iterate_tokens()",
"- N = int(next(tokens)) # type: int",
"- A = [int(next(tokens)) for _ in range(N)] # type: \"List[int]\"",
"- solve(N, A)",
"+ N = INT()",
"+ A = LI()",
"+ RGB = [0, 0, 0]",
"+ answer = 1",
"+ MOD = 10**9 + 7",
"+ for i in range(N):",
"+ if RGB.count(A[i]) == 0:",
"+ print((0))",
"+ return",
"+ answer *= RGB.count(A[i])",
"+ answer %= MOD",
"+ for j in range(3):",
"+ if RGB[j] == A[i]:",
"+ RGB[j] += 1",
"+ break",
"+ print(answer)",
"+ return"
] | false | 0.11687 | 0.038288 | 3.052403 |
[
"s501199953",
"s444091999"
] |
u973840923
|
p03212
|
python
|
s049252309
|
s790075418
| 64 | 40 | 3,060 | 3,060 |
Accepted
|
Accepted
| 37.5 |
N = int(eval(input()))
cnt = 0
def dfs(s):
global cnt
if '3' in s and '5' in s and '7' in s and int(s) <= N:
cnt += 1
if len(s) >= 10:
return cnt
dfs(s + '3')
dfs(s + '5')
dfs(s + '7')
return cnt
print((dfs('')))
|
from itertools import product
N = int(eval(input()))
cnt = 0
for i in range(3,10):
for v in product('357',repeat=i):
val = ''.join(v)
if int(val) <= N and '3' in val and '5' in val and '7' in val:
cnt += 1
print(cnt)
| 15 | 11 | 264 | 253 |
N = int(eval(input()))
cnt = 0
def dfs(s):
global cnt
if "3" in s and "5" in s and "7" in s and int(s) <= N:
cnt += 1
if len(s) >= 10:
return cnt
dfs(s + "3")
dfs(s + "5")
dfs(s + "7")
return cnt
print((dfs("")))
|
from itertools import product
N = int(eval(input()))
cnt = 0
for i in range(3, 10):
for v in product("357", repeat=i):
val = "".join(v)
if int(val) <= N and "3" in val and "5" in val and "7" in val:
cnt += 1
print(cnt)
| false | 26.666667 |
[
"+from itertools import product",
"+",
"-",
"-",
"-def dfs(s):",
"- global cnt",
"- if \"3\" in s and \"5\" in s and \"7\" in s and int(s) <= N:",
"- cnt += 1",
"- if len(s) >= 10:",
"- return cnt",
"- dfs(s + \"3\")",
"- dfs(s + \"5\")",
"- dfs(s + \"7\")",
"- return cnt",
"-",
"-",
"-print((dfs(\"\")))",
"+for i in range(3, 10):",
"+ for v in product(\"357\", repeat=i):",
"+ val = \"\".join(v)",
"+ if int(val) <= N and \"3\" in val and \"5\" in val and \"7\" in val:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.138498 | 0.075817 | 1.826754 |
[
"s049252309",
"s790075418"
] |
u551909378
|
p02972
|
python
|
s662726442
|
s318544846
| 842 | 434 | 21,768 | 21,864 |
Accepted
|
Accepted
| 48.46 |
N = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N//2 + 1, N + 1) if a[i] == 1])
for i in range(N//2, 0, -1):
k, temp = 2, 0
while k * i < N + 1:
if k * i in b:
temp += 1
k += 1
if temp % 2 != a[i]:
b.add(i)
if len(b) > 0:
print((len(b)))
print((' '.join(list(map(str, sorted(list(b)))))))
else:
print((0))
|
N = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N//2 + 1, N + 1) if a[i] == 1])
for i in range(N//2, 0, -1):
if sum([1 for k in range(2, N//i + 1) if k*i in b]) % 2 != a[i]:
b.add(i)
if len(b) > 0:
print((len(b)))
print((' '.join(list(map(str, sorted(list(b)))))))
else:
print((0))
| 18 | 13 | 415 | 350 |
N = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N // 2 + 1, N + 1) if a[i] == 1])
for i in range(N // 2, 0, -1):
k, temp = 2, 0
while k * i < N + 1:
if k * i in b:
temp += 1
k += 1
if temp % 2 != a[i]:
b.add(i)
if len(b) > 0:
print((len(b)))
print((" ".join(list(map(str, sorted(list(b)))))))
else:
print((0))
|
N = int(eval(input()))
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N // 2 + 1, N + 1) if a[i] == 1])
for i in range(N // 2, 0, -1):
if sum([1 for k in range(2, N // i + 1) if k * i in b]) % 2 != a[i]:
b.add(i)
if len(b) > 0:
print((len(b)))
print((" ".join(list(map(str, sorted(list(b)))))))
else:
print((0))
| false | 27.777778 |
[
"- k, temp = 2, 0",
"- while k * i < N + 1:",
"- if k * i in b:",
"- temp += 1",
"- k += 1",
"- if temp % 2 != a[i]:",
"+ if sum([1 for k in range(2, N // i + 1) if k * i in b]) % 2 != a[i]:"
] | false | 0.039004 | 0.008023 | 4.861806 |
[
"s662726442",
"s318544846"
] |
u893063840
|
p02690
|
python
|
s933074053
|
s633452273
| 1,341 | 42 | 9,164 | 9,224 |
Accepted
|
Accepted
| 96.87 |
x = int(eval(input()))
for i in range(-1000, 1000):
for j in range(-1000, 1000):
if i ** 5 - j ** 5 == x:
print((i, j))
exit()
|
def f(x):
return pow(x, 5) - pow(x - 1, 5)
x = int(eval(input()))
a_mx = 1
while f(a_mx) < x:
a_mx += 1
a_mn = 0
while f(a_mn) < x:
a_mn -= 1
b_mx = a_mx - 1
b_mn = a_mn - 1
for a in range(a_mn, a_mx + 1):
for b in range(b_mn, b_mx + 1):
if pow(a, 5) - pow(b, 5) == x:
print((a, b))
exit()
| 7 | 22 | 162 | 357 |
x = int(eval(input()))
for i in range(-1000, 1000):
for j in range(-1000, 1000):
if i**5 - j**5 == x:
print((i, j))
exit()
|
def f(x):
return pow(x, 5) - pow(x - 1, 5)
x = int(eval(input()))
a_mx = 1
while f(a_mx) < x:
a_mx += 1
a_mn = 0
while f(a_mn) < x:
a_mn -= 1
b_mx = a_mx - 1
b_mn = a_mn - 1
for a in range(a_mn, a_mx + 1):
for b in range(b_mn, b_mx + 1):
if pow(a, 5) - pow(b, 5) == x:
print((a, b))
exit()
| false | 68.181818 |
[
"+def f(x):",
"+ return pow(x, 5) - pow(x - 1, 5)",
"+",
"+",
"-for i in range(-1000, 1000):",
"- for j in range(-1000, 1000):",
"- if i**5 - j**5 == x:",
"- print((i, j))",
"+a_mx = 1",
"+while f(a_mx) < x:",
"+ a_mx += 1",
"+a_mn = 0",
"+while f(a_mn) < x:",
"+ a_mn -= 1",
"+b_mx = a_mx - 1",
"+b_mn = a_mn - 1",
"+for a in range(a_mn, a_mx + 1):",
"+ for b in range(b_mn, b_mx + 1):",
"+ if pow(a, 5) - pow(b, 5) == x:",
"+ print((a, b))"
] | false | 0.006884 | 0.039188 | 0.175679 |
[
"s933074053",
"s633452273"
] |
u608088992
|
p02708
|
python
|
s840185918
|
s089057100
| 114 | 102 | 9,196 | 9,196 |
Accepted
|
Accepted
| 10.53 |
import sys
mod = 7 + 10 ** 9
def solve():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
ans = 0
for k in range(K, N + 2):
minSum = (0 + k - 1) * k // 2
maxSum = (N - k + 1 + N) * k // 2
ans += (maxSum - minSum + 1) % mod
ans %= mod
print(ans)
return 0
if __name__ == "__main__":
solve()
|
import sys
mod = 7 + 10 ** 9
def solve():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
ans = 0
for k in range(K, N + 2):
minS = (k - 1) * k // 2
maxS = (N - k + 1 + N) * k // 2
ans += (maxS - minS + 1)
ans %= mod
print(ans)
return 0
if __name__ == "__main__":
solve()
| 20 | 19 | 388 | 365 |
import sys
mod = 7 + 10**9
def solve():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
ans = 0
for k in range(K, N + 2):
minSum = (0 + k - 1) * k // 2
maxSum = (N - k + 1 + N) * k // 2
ans += (maxSum - minSum + 1) % mod
ans %= mod
print(ans)
return 0
if __name__ == "__main__":
solve()
|
import sys
mod = 7 + 10**9
def solve():
input = sys.stdin.readline
N, K = list(map(int, input().split()))
ans = 0
for k in range(K, N + 2):
minS = (k - 1) * k // 2
maxS = (N - k + 1 + N) * k // 2
ans += maxS - minS + 1
ans %= mod
print(ans)
return 0
if __name__ == "__main__":
solve()
| false | 5 |
[
"- minSum = (0 + k - 1) * k // 2",
"- maxSum = (N - k + 1 + N) * k // 2",
"- ans += (maxSum - minSum + 1) % mod",
"+ minS = (k - 1) * k // 2",
"+ maxS = (N - k + 1 + N) * k // 2",
"+ ans += maxS - minS + 1"
] | false | 0.064482 | 0.051713 | 1.246914 |
[
"s840185918",
"s089057100"
] |
u347184682
|
p02899
|
python
|
s123461179
|
s181273698
| 121 | 98 | 13,880 | 19,920 |
Accepted
|
Accepted
| 19.01 |
n=int(eval(input()))
A=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
for i in range(n):
ans[A[i]-1]=i+1
print((*ans))
|
n=int(eval(input()))
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
for i in range(n):
ans[a[i]-1]=i+1
print((*ans))
| 6 | 6 | 139 | 143 |
n = int(eval(input()))
A = [int(x) for x in input().rstrip().split()]
ans = [0 for i in range(n)]
for i in range(n):
ans[A[i] - 1] = i + 1
print((*ans))
|
n = int(eval(input()))
a = [int(x) for x in input().rstrip().split()]
ans = [0 for i in range(n)]
for i in range(n):
ans[a[i] - 1] = i + 1
print((*ans))
| false | 0 |
[
"-A = [int(x) for x in input().rstrip().split()]",
"+a = [int(x) for x in input().rstrip().split()]",
"- ans[A[i] - 1] = i + 1",
"+ ans[a[i] - 1] = i + 1"
] | false | 0.048275 | 0.04873 | 0.990665 |
[
"s123461179",
"s181273698"
] |
u102461423
|
p02561
|
python
|
s482638341
|
s049713751
| 621 | 541 | 82,828 | 69,828 |
Accepted
|
Accepted
| 12.88 |
import sys
import itertools
import numpy as np
import networkx as nx
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')
A = []
B = []
E = []
for i, j in itertools.product(list(range(N)), list(range(M))):
if S[i, j] == '#':
continue
elif (i + j) & 1:
A.append((i, j))
else:
B.append((i, j))
for i, j in A:
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
i1, j1 = i + dx, j + dy
if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
E.append(((i, j), (i1, j1)))
G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)
M = nx.bipartite.eppstein_matching(G, A)
for key, item in list(M.items()):
i, j = key
i1, j1 = item
if i1 == i + 1:
a, b = 'v', '^'
elif i1 == i - 1:
a, b = '^', 'v'
elif j1 == j + 1:
a, b = '>', '<'
else:
a, b = '<', '>'
S[i, j], S[i1, j1] = a, b
print((len(M) // 2))
for row in S:
print((''.join(row)))
|
import sys
import itertools
import numpy as np
import networkx as nx
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')
A = []
B = []
E = []
for i, j in itertools.product(list(range(N)), list(range(M))):
if S[i, j] == '#':
continue
elif (i + j) & 1:
A.append((i, j))
else:
B.append((i, j))
for i, j in A:
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
i1, j1 = i + dx, j + dy
if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
E.append(((i, j), (i1, j1)))
G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)
M = nx.bipartite.maximum_matching(G, A)
for key, item in list(M.items()):
i, j = key
i1, j1 = item
if i1 == i + 1:
a, b = 'v', '^'
elif i1 == i - 1:
a, b = '^', 'v'
elif j1 == j + 1:
a, b = '>', '<'
else:
a, b = '<', '>'
S[i, j], S[i1, j1] = a, b
print((len(M) // 2))
for row in S:
print((''.join(row)))
| 52 | 52 | 1,193 | 1,192 |
import sys
import itertools
import numpy as np
import networkx as nx
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
S = np.frombuffer(read(), "S1").reshape(N, -1)[:, :M].astype("U1")
A = []
B = []
E = []
for i, j in itertools.product(list(range(N)), list(range(M))):
if S[i, j] == "#":
continue
elif (i + j) & 1:
A.append((i, j))
else:
B.append((i, j))
for i, j in A:
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
i1, j1 = i + dx, j + dy
if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != "#":
E.append(((i, j), (i1, j1)))
G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)
M = nx.bipartite.eppstein_matching(G, A)
for key, item in list(M.items()):
i, j = key
i1, j1 = item
if i1 == i + 1:
a, b = "v", "^"
elif i1 == i - 1:
a, b = "^", "v"
elif j1 == j + 1:
a, b = ">", "<"
else:
a, b = "<", ">"
S[i, j], S[i1, j1] = a, b
print((len(M) // 2))
for row in S:
print(("".join(row)))
|
import sys
import itertools
import numpy as np
import networkx as nx
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
S = np.frombuffer(read(), "S1").reshape(N, -1)[:, :M].astype("U1")
A = []
B = []
E = []
for i, j in itertools.product(list(range(N)), list(range(M))):
if S[i, j] == "#":
continue
elif (i + j) & 1:
A.append((i, j))
else:
B.append((i, j))
for i, j in A:
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
i1, j1 = i + dx, j + dy
if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != "#":
E.append(((i, j), (i1, j1)))
G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)
M = nx.bipartite.maximum_matching(G, A)
for key, item in list(M.items()):
i, j = key
i1, j1 = item
if i1 == i + 1:
a, b = "v", "^"
elif i1 == i - 1:
a, b = "^", "v"
elif j1 == j + 1:
a, b = ">", "<"
else:
a, b = "<", ">"
S[i, j], S[i1, j1] = a, b
print((len(M) // 2))
for row in S:
print(("".join(row)))
| false | 0 |
[
"-M = nx.bipartite.eppstein_matching(G, A)",
"+M = nx.bipartite.maximum_matching(G, A)"
] | false | 0.261532 | 0.228729 | 1.143414 |
[
"s482638341",
"s049713751"
] |
u794173881
|
p03283
|
python
|
s450897674
|
s933811414
| 1,410 | 584 | 111,576 | 100,060 |
Accepted
|
Accepted
| 58.58 |
class Ruiseki2D:
"""二次元累積和を構築する"""
def __init__(self, matrix):
self.h = len(matrix)
self.w = len(matrix[0])
self.ru = [[0] * (self.w + 1) for _ in range(self.h + 1)]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] = self.ru[i + 1][j] + matrix[i][j]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] += self.ru[i][j + 1]
def get_sum(self, hl, hr, wl, wr):
"""[hl, hr), [wl, wr) で囲まれた部分の和を求める"""
return (self.ru[hr][wr] + self.ru[hl][wl]
- self.ru[hr][wl] - self.ru[hl][wr])
n, m, q = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
query = [list(map(int, input().split())) for i in range(q)]
matrix = [[0] * (n + 1) for i in range(n + 1)]
for l, r in info:
matrix[l][r] += 1
ru = Ruiseki2D(matrix)
for l, r in query:
ans = ru.get_sum(l, r + 1, l, r + 1)
print(ans)
|
import sys
input = sys.stdin.readline
class Ruiseki2D:
"""二次元累積和を構築する"""
def __init__(self, matrix):
self.h = len(matrix)
self.w = len(matrix[0])
self.ru = [[0] * (self.w + 1) for _ in range(self.h + 1)]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] = self.ru[i + 1][j] + matrix[i][j]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] += self.ru[i][j + 1]
def get_sum(self, hl, hr, wl, wr):
"""[hl, hr), [wl, wr) で囲まれた部分の和を求める"""
return (self.ru[hr][wr] + self.ru[hl][wl]
- self.ru[hr][wl] - self.ru[hl][wr])
n, m, q = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
query = [list(map(int, input().split())) for i in range(q)]
matrix = [[0] * (n + 1) for i in range(n + 1)]
for l, r in info:
matrix[l][r] += 1
ru = Ruiseki2D(matrix)
for l, r in query:
ans = ru.get_sum(l, r + 1, l, r + 1)
print(ans)
| 32 | 36 | 1,031 | 1,075 |
class Ruiseki2D:
"""二次元累積和を構築する"""
def __init__(self, matrix):
self.h = len(matrix)
self.w = len(matrix[0])
self.ru = [[0] * (self.w + 1) for _ in range(self.h + 1)]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] = self.ru[i + 1][j] + matrix[i][j]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] += self.ru[i][j + 1]
def get_sum(self, hl, hr, wl, wr):
"""[hl, hr), [wl, wr) で囲まれた部分の和を求める"""
return self.ru[hr][wr] + self.ru[hl][wl] - self.ru[hr][wl] - self.ru[hl][wr]
n, m, q = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
query = [list(map(int, input().split())) for i in range(q)]
matrix = [[0] * (n + 1) for i in range(n + 1)]
for l, r in info:
matrix[l][r] += 1
ru = Ruiseki2D(matrix)
for l, r in query:
ans = ru.get_sum(l, r + 1, l, r + 1)
print(ans)
|
import sys
input = sys.stdin.readline
class Ruiseki2D:
"""二次元累積和を構築する"""
def __init__(self, matrix):
self.h = len(matrix)
self.w = len(matrix[0])
self.ru = [[0] * (self.w + 1) for _ in range(self.h + 1)]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] = self.ru[i + 1][j] + matrix[i][j]
for i in range(self.h):
for j in range(self.w):
self.ru[i + 1][j + 1] += self.ru[i][j + 1]
def get_sum(self, hl, hr, wl, wr):
"""[hl, hr), [wl, wr) で囲まれた部分の和を求める"""
return self.ru[hr][wr] + self.ru[hl][wl] - self.ru[hr][wl] - self.ru[hl][wr]
n, m, q = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
query = [list(map(int, input().split())) for i in range(q)]
matrix = [[0] * (n + 1) for i in range(n + 1)]
for l, r in info:
matrix[l][r] += 1
ru = Ruiseki2D(matrix)
for l, r in query:
ans = ru.get_sum(l, r + 1, l, r + 1)
print(ans)
| false | 11.111111 |
[
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+"
] | false | 0.036652 | 0.036729 | 0.997902 |
[
"s450897674",
"s933811414"
] |
u555767343
|
p02778
|
python
|
s965749324
|
s716756241
| 186 | 164 | 38,384 | 38,512 |
Accepted
|
Accepted
| 11.83 |
lenS = len(eval(input()))
print(('x'*lenS))
|
print(('x'*len(eval(input()))))
| 2 | 1 | 36 | 23 |
lenS = len(eval(input()))
print(("x" * lenS))
|
print(("x" * len(eval(input()))))
| false | 50 |
[
"-lenS = len(eval(input()))",
"-print((\"x\" * lenS))",
"+print((\"x\" * len(eval(input()))))"
] | false | 0.040467 | 0.036731 | 1.10173 |
[
"s965749324",
"s716756241"
] |
u198440493
|
p03103
|
python
|
s943477377
|
s029140414
| 230 | 202 | 25,828 | 25,828 |
Accepted
|
Accepted
| 12.17 |
n,m,*l=list(map(int,open(0).read().split()))
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
ans+=s*min(m,t)
m=max(m-t,0)
if not m:
break
print(ans)
|
n,m,*l=list(map(int,open(0).read().split()))
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
ans+=s*min(m,t)
m-=t
if m<=0:
print(ans)
break
| 8 | 8 | 157 | 152 |
n, m, *l = list(map(int, open(0).read().split()))
ans = 0
for s, t in sorted(zip(l[::2], l[1::2])):
ans += s * min(m, t)
m = max(m - t, 0)
if not m:
break
print(ans)
|
n, m, *l = list(map(int, open(0).read().split()))
ans = 0
for s, t in sorted(zip(l[::2], l[1::2])):
ans += s * min(m, t)
m -= t
if m <= 0:
print(ans)
break
| false | 0 |
[
"- m = max(m - t, 0)",
"- if not m:",
"+ m -= t",
"+ if m <= 0:",
"+ print(ans)",
"-print(ans)"
] | false | 0.034148 | 0.045958 | 0.743032 |
[
"s943477377",
"s029140414"
] |
u426534722
|
p02266
|
python
|
s272673233
|
s111451490
| 990 | 20 | 7,896 | 6,500 |
Accepted
|
Accepted
| 97.98 |
import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().strip()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
break
ans = []
for a in li:
if a[1] != 0:
ans.append(a[1])
print((sum(ans)))
print((len(ans), *ans))
|
li1 = []
li2 = []
ans = 0
for i, s in enumerate(eval(input())):
if s == "\\":
li1.append(i)
elif s == "/" and li1:
j = li1.pop()
c = i - j
ans += c
while li2 and li2[-1][0] > j:
c += li2[-1][1]
li2.pop()
li2.append((j, c))
print(ans)
if li2:
print((len(li2), *list(zip(*li2))[1]))
else:
print((0))
| 22 | 20 | 606 | 396 |
import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().strip()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
li = li[:j] + [
[li[j][0], sum(tuple(zip(*li[j + 1 :]))[1]) + i - li[j][0]]
]
break
ans = []
for a in li:
if a[1] != 0:
ans.append(a[1])
print((sum(ans)))
print((len(ans), *ans))
|
li1 = []
li2 = []
ans = 0
for i, s in enumerate(eval(input())):
if s == "\\":
li1.append(i)
elif s == "/" and li1:
j = li1.pop()
c = i - j
ans += c
while li2 and li2[-1][0] > j:
c += li2[-1][1]
li2.pop()
li2.append((j, c))
print(ans)
if li2:
print((len(li2), *list(zip(*li2))[1]))
else:
print((0))
| false | 9.090909 |
[
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-li = []",
"-for i, s in enumerate(readline().strip()):",
"+li1 = []",
"+li2 = []",
"+ans = 0",
"+for i, s in enumerate(eval(input())):",
"- li.append([i, 0])",
"- elif s == \"/\":",
"- if li:",
"- if li[-1][1] == 0:",
"- li[-1][1] = i - li[-1][0]",
"- else:",
"- for j in range(len(li) - 1, -1, -1):",
"- if li[j][1] == 0:",
"- li = li[:j] + [",
"- [li[j][0], sum(tuple(zip(*li[j + 1 :]))[1]) + i - li[j][0]]",
"- ]",
"- break",
"-ans = []",
"-for a in li:",
"- if a[1] != 0:",
"- ans.append(a[1])",
"-print((sum(ans)))",
"-print((len(ans), *ans))",
"+ li1.append(i)",
"+ elif s == \"/\" and li1:",
"+ j = li1.pop()",
"+ c = i - j",
"+ ans += c",
"+ while li2 and li2[-1][0] > j:",
"+ c += li2[-1][1]",
"+ li2.pop()",
"+ li2.append((j, c))",
"+print(ans)",
"+if li2:",
"+ print((len(li2), *list(zip(*li2))[1]))",
"+else:",
"+ print((0))"
] | false | 0.08234 | 0.037106 | 2.219026 |
[
"s272673233",
"s111451490"
] |
u150984829
|
p02396
|
python
|
s417408835
|
s357707770
| 70 | 50 | 6,260 | 5,672 |
Accepted
|
Accepted
| 28.57 |
newArray = []
x = eval(input())
while x != "0":
newArray.append(x)
x = eval(input())
for i in range(len(newArray)):
print(("Case " + str(i + 1) + ": " + newArray[i]))
|
import sys
i=1
for a in sys.stdin:
a=a.strip()
if'0'==a:break
print(f'Case {i}: {a}')
i+=1
| 10 | 7 | 183 | 100 |
newArray = []
x = eval(input())
while x != "0":
newArray.append(x)
x = eval(input())
for i in range(len(newArray)):
print(("Case " + str(i + 1) + ": " + newArray[i]))
|
import sys
i = 1
for a in sys.stdin:
a = a.strip()
if "0" == a:
break
print(f"Case {i}: {a}")
i += 1
| false | 30 |
[
"-newArray = []",
"-x = eval(input())",
"-while x != \"0\":",
"- newArray.append(x)",
"- x = eval(input())",
"-for i in range(len(newArray)):",
"- print((\"Case \" + str(i + 1) + \": \" + newArray[i]))",
"+import sys",
"+",
"+i = 1",
"+for a in sys.stdin:",
"+ a = a.strip()",
"+ if \"0\" == a:",
"+ break",
"+ print(f\"Case {i}: {a}\")",
"+ i += 1"
] | false | 0.040005 | 0.039528 | 1.012043 |
[
"s417408835",
"s357707770"
] |
u794544096
|
p02724
|
python
|
s396174566
|
s086712370
| 164 | 19 | 38,384 | 2,940 |
Accepted
|
Accepted
| 88.41 |
x = int(eval(input()))
y500 = x // 500
y5 = (x % 500) // 5
print((y500 * 1000 + y5*5))
|
x = int(eval(input()))
coin_500 = x // 500
coin_5 = (x-coin_500*500) // 5
print((coin_500 * 1000 + coin_5 * 5))
| 6 | 6 | 85 | 110 |
x = int(eval(input()))
y500 = x // 500
y5 = (x % 500) // 5
print((y500 * 1000 + y5 * 5))
|
x = int(eval(input()))
coin_500 = x // 500
coin_5 = (x - coin_500 * 500) // 5
print((coin_500 * 1000 + coin_5 * 5))
| false | 0 |
[
"-y500 = x // 500",
"-y5 = (x % 500) // 5",
"-print((y500 * 1000 + y5 * 5))",
"+coin_500 = x // 500",
"+coin_5 = (x - coin_500 * 500) // 5",
"+print((coin_500 * 1000 + coin_5 * 5))"
] | false | 0.047981 | 0.046981 | 1.021291 |
[
"s396174566",
"s086712370"
] |
u667189155
|
p02923
|
python
|
s180698008
|
s056078697
| 89 | 80 | 14,224 | 14,252 |
Accepted
|
Accepted
| 10.11 |
n = int(eval(input()))
h = list(map(int, input().split()))
out, cnt = 0, 0
for i in range(n-1):
if h[i] >= h[i+1]:
cnt += 1
out = max(out, cnt)
else:
cnt = 0
print(out)
|
n = int(eval(input()))
h = list(map(int, input().split()))
cnt = 0
result = 0
for i in range(n-1):
if h[i] - h[i+1] >= 0:
cnt += 1
else:
result = max(cnt, result)
cnt = 0
result = max(cnt, result)
print(result)
| 12 | 15 | 208 | 253 |
n = int(eval(input()))
h = list(map(int, input().split()))
out, cnt = 0, 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
cnt += 1
out = max(out, cnt)
else:
cnt = 0
print(out)
|
n = int(eval(input()))
h = list(map(int, input().split()))
cnt = 0
result = 0
for i in range(n - 1):
if h[i] - h[i + 1] >= 0:
cnt += 1
else:
result = max(cnt, result)
cnt = 0
result = max(cnt, result)
print(result)
| false | 20 |
[
"-out, cnt = 0, 0",
"+cnt = 0",
"+result = 0",
"- if h[i] >= h[i + 1]:",
"+ if h[i] - h[i + 1] >= 0:",
"- out = max(out, cnt)",
"+ result = max(cnt, result)",
"-print(out)",
"+result = max(cnt, result)",
"+print(result)"
] | false | 0.039188 | 0.037745 | 1.038216 |
[
"s180698008",
"s056078697"
] |
u079022693
|
p02837
|
python
|
s817817911
|
s714735493
| 400 | 163 | 45,404 | 3,064 |
Accepted
|
Accepted
| 59.25 |
N=int(eval(input()))
A=[]
X=list()
for i in range(N):
X.append([])
Y=list()
for i in range(N):
Y.append([])
for i in range(N):
A_i=int(eval(input()))
A.append(A_i)
for j in range(A_i):
x,y=list(map(int,input().split()))
X[i].append(x)
Y[i].append(y)
max_nin=0
#bit全探索
for i in range(1<<N):
honest_kamo=[]
for j in range(N):
if(i>>j)&1:
honest_kamo.append(j)
liar_kamo=[c for c in range(N)]
liar_kamo=list(set(liar_kamo)-set(honest_kamo))
#print("honest_kamo:",honest_kamo)
#print("liar_kamo:",liar_kamo)
flag=True
for i in honest_kamo:
for j in range(A[i]):
if Y[i][j]==1:
if X[i][j]-1 in liar_kamo:
flag=False
elif Y[i][j]==0:
if X[i][j]-1 in honest_kamo:
flag=False
#print(flag)
if flag:
max_nin=max(max_nin,len(honest_kamo))
print(max_nin)
|
from sys import stdin
def main():
#入力
readline=stdin.readline
n=int(readline())
shogen=[]
nums=[]
for i in range(n):
a=int(readline())
nums.append(a)
xy=[0]*a
for j in range(a):
xy[j]=list(map(int,readline().split()))
shogen.append(xy)
res=0
for i in range(1<<n):
output=[]
for j in range(n):
if(i>>j)&1:
output.append(j)
flag=True
for p in output:
num_p=nums[p]
shogen_p=shogen[p]
for j in range(num_p):
if shogen_p[j][1]==1:
if shogen_p[j][0]-1 in output:
pass
else:
flag=False
break
else:
if shogen_p[j][0]-1 in output:
flag=False
break
else:
pass
if flag==False:
break
else:
res=max(res,len(output))
print(res)
if __name__=="__main__":
main()
| 47 | 48 | 949 | 1,201 |
N = int(eval(input()))
A = []
X = list()
for i in range(N):
X.append([])
Y = list()
for i in range(N):
Y.append([])
for i in range(N):
A_i = int(eval(input()))
A.append(A_i)
for j in range(A_i):
x, y = list(map(int, input().split()))
X[i].append(x)
Y[i].append(y)
max_nin = 0
# bit全探索
for i in range(1 << N):
honest_kamo = []
for j in range(N):
if (i >> j) & 1:
honest_kamo.append(j)
liar_kamo = [c for c in range(N)]
liar_kamo = list(set(liar_kamo) - set(honest_kamo))
# print("honest_kamo:",honest_kamo)
# print("liar_kamo:",liar_kamo)
flag = True
for i in honest_kamo:
for j in range(A[i]):
if Y[i][j] == 1:
if X[i][j] - 1 in liar_kamo:
flag = False
elif Y[i][j] == 0:
if X[i][j] - 1 in honest_kamo:
flag = False
# print(flag)
if flag:
max_nin = max(max_nin, len(honest_kamo))
print(max_nin)
|
from sys import stdin
def main():
# 入力
readline = stdin.readline
n = int(readline())
shogen = []
nums = []
for i in range(n):
a = int(readline())
nums.append(a)
xy = [0] * a
for j in range(a):
xy[j] = list(map(int, readline().split()))
shogen.append(xy)
res = 0
for i in range(1 << n):
output = []
for j in range(n):
if (i >> j) & 1:
output.append(j)
flag = True
for p in output:
num_p = nums[p]
shogen_p = shogen[p]
for j in range(num_p):
if shogen_p[j][1] == 1:
if shogen_p[j][0] - 1 in output:
pass
else:
flag = False
break
else:
if shogen_p[j][0] - 1 in output:
flag = False
break
else:
pass
if flag == False:
break
else:
res = max(res, len(output))
print(res)
if __name__ == "__main__":
main()
| false | 2.083333 |
[
"-N = int(eval(input()))",
"-A = []",
"-X = list()",
"-for i in range(N):",
"- X.append([])",
"-Y = list()",
"-for i in range(N):",
"- Y.append([])",
"-for i in range(N):",
"- A_i = int(eval(input()))",
"- A.append(A_i)",
"- for j in range(A_i):",
"- x, y = list(map(int, input().split()))",
"- X[i].append(x)",
"- Y[i].append(y)",
"-max_nin = 0",
"-# bit全探索",
"-for i in range(1 << N):",
"- honest_kamo = []",
"- for j in range(N):",
"- if (i >> j) & 1:",
"- honest_kamo.append(j)",
"- liar_kamo = [c for c in range(N)]",
"- liar_kamo = list(set(liar_kamo) - set(honest_kamo))",
"- # print(\"honest_kamo:\",honest_kamo)",
"- # print(\"liar_kamo:\",liar_kamo)",
"- flag = True",
"- for i in honest_kamo:",
"- for j in range(A[i]):",
"- if Y[i][j] == 1:",
"- if X[i][j] - 1 in liar_kamo:",
"- flag = False",
"- elif Y[i][j] == 0:",
"- if X[i][j] - 1 in honest_kamo:",
"- flag = False",
"- # print(flag)",
"- if flag:",
"- max_nin = max(max_nin, len(honest_kamo))",
"-print(max_nin)",
"+from sys import stdin",
"+",
"+",
"+def main():",
"+ # 入力",
"+ readline = stdin.readline",
"+ n = int(readline())",
"+ shogen = []",
"+ nums = []",
"+ for i in range(n):",
"+ a = int(readline())",
"+ nums.append(a)",
"+ xy = [0] * a",
"+ for j in range(a):",
"+ xy[j] = list(map(int, readline().split()))",
"+ shogen.append(xy)",
"+ res = 0",
"+ for i in range(1 << n):",
"+ output = []",
"+ for j in range(n):",
"+ if (i >> j) & 1:",
"+ output.append(j)",
"+ flag = True",
"+ for p in output:",
"+ num_p = nums[p]",
"+ shogen_p = shogen[p]",
"+ for j in range(num_p):",
"+ if shogen_p[j][1] == 1:",
"+ if shogen_p[j][0] - 1 in output:",
"+ pass",
"+ else:",
"+ flag = False",
"+ break",
"+ else:",
"+ if shogen_p[j][0] - 1 in output:",
"+ flag = False",
"+ break",
"+ else:",
"+ pass",
"+ if flag == False:",
"+ break",
"+ else:",
"+ res = max(res, len(output))",
"+ print(res)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.03134 | 0.031338 | 1.000055 |
[
"s817817911",
"s714735493"
] |
u332906195
|
p02861
|
python
|
s669343860
|
s410433411
| 473 | 17 | 3,064 | 3,060 |
Accepted
|
Accepted
| 96.41 |
import itertools
import math
N = int(eval(input()))
P = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for perm in itertools.permutations([i for i in range(N)]):
for i in range(N - 1):
ans += ((P[perm[i]][0] - P[perm[i+1]][0]) ** 2
+ (P[perm[i]][1] - P[perm[i+1]][1]) ** 2) ** 0.5
print((ans / math.factorial(N)))
|
N = int(eval(input()))
P = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += ((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2) ** 0.5
print((2 * ans / N))
| 13 | 8 | 363 | 234 |
import itertools
import math
N = int(eval(input()))
P = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for perm in itertools.permutations([i for i in range(N)]):
for i in range(N - 1):
ans += (
(P[perm[i]][0] - P[perm[i + 1]][0]) ** 2
+ (P[perm[i]][1] - P[perm[i + 1]][1]) ** 2
) ** 0.5
print((ans / math.factorial(N)))
|
N = int(eval(input()))
P = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += ((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2) ** 0.5
print((2 * ans / N))
| false | 38.461538 |
[
"-import itertools",
"-import math",
"-",
"-for perm in itertools.permutations([i for i in range(N)]):",
"- for i in range(N - 1):",
"- ans += (",
"- (P[perm[i]][0] - P[perm[i + 1]][0]) ** 2",
"- + (P[perm[i]][1] - P[perm[i + 1]][1]) ** 2",
"- ) ** 0.5",
"-print((ans / math.factorial(N)))",
"+for i in range(N):",
"+ for j in range(i + 1, N):",
"+ ans += ((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2) ** 0.5",
"+print((2 * ans / N))"
] | false | 0.112582 | 0.038353 | 2.935393 |
[
"s669343860",
"s410433411"
] |
u768896740
|
p03127
|
python
|
s443384561
|
s422847046
| 1,577 | 80 | 14,224 | 16,304 |
Accepted
|
Accepted
| 94.93 |
n = int(eval(input()))
l = list(map(int, input().split()))
hp = max(l)
l.sort()
while hp > 1 and len(l) != 1:
a = l[0]
for i in range(1, len(l)):
l[i] %= a
l.sort()
while l[0] == 0:
l.remove(0)
if l[0] < hp:
hp = l[0]
print(hp)
|
import fractions
from functools import reduce
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
n = int(eval(input()))
x = list(map(int, input().split()))
print((gcd_list(x)))
| 18 | 13 | 286 | 259 |
n = int(eval(input()))
l = list(map(int, input().split()))
hp = max(l)
l.sort()
while hp > 1 and len(l) != 1:
a = l[0]
for i in range(1, len(l)):
l[i] %= a
l.sort()
while l[0] == 0:
l.remove(0)
if l[0] < hp:
hp = l[0]
print(hp)
|
import fractions
from functools import reduce
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
n = int(eval(input()))
x = list(map(int, input().split()))
print((gcd_list(x)))
| false | 27.777778 |
[
"+import fractions",
"+from functools import reduce",
"+",
"+",
"+def gcd(*numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"+def gcd_list(numbers):",
"+ return reduce(fractions.gcd, numbers)",
"+",
"+",
"-l = list(map(int, input().split()))",
"-hp = max(l)",
"-l.sort()",
"-while hp > 1 and len(l) != 1:",
"- a = l[0]",
"- for i in range(1, len(l)):",
"- l[i] %= a",
"- l.sort()",
"- while l[0] == 0:",
"- l.remove(0)",
"- if l[0] < hp:",
"- hp = l[0]",
"-print(hp)",
"+x = list(map(int, input().split()))",
"+print((gcd_list(x)))"
] | false | 0.042015 | 0.046634 | 0.900945 |
[
"s443384561",
"s422847046"
] |
u057109575
|
p02960
|
python
|
s732315823
|
s095322735
| 745 | 315 | 62,044 | 88,420 |
Accepted
|
Accepted
| 57.72 |
S = eval(input())
MOD = 10 ** 9 + 7
MAX_LEN = len(S)
dp = [[0] * 13 for _ in range(MAX_LEN + 1)]
dp[0][0] = 1
for i in range(MAX_LEN):
c = int(S[i]) if S[i] != '?' else -1
for j in range(10):
if c != -1 and c != j:
continue
for k in range(13):
idx = (k * 10 + j) % 13
dp[i + 1][idx] += dp[i][k]
dp[i + 1][idx] %= MOD
print((dp[-1][5]))
|
S = eval(input())
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(len(S)):
for j in range(13):
if S[i] == "?":
for k in range(10):
x = (j * 10 + k) % 13
dp[i + 1][x] += dp[i][j]
dp[i + 1][x] %= mod
else:
x = (j * 10 + int(S[i])) % 13
dp[i + 1][x] += dp[i][j]
dp[i + 1][x] %= mod
print((dp[-1][5]))
| 20 | 18 | 440 | 478 |
S = eval(input())
MOD = 10**9 + 7
MAX_LEN = len(S)
dp = [[0] * 13 for _ in range(MAX_LEN + 1)]
dp[0][0] = 1
for i in range(MAX_LEN):
c = int(S[i]) if S[i] != "?" else -1
for j in range(10):
if c != -1 and c != j:
continue
for k in range(13):
idx = (k * 10 + j) % 13
dp[i + 1][idx] += dp[i][k]
dp[i + 1][idx] %= MOD
print((dp[-1][5]))
|
S = eval(input())
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mod = 10**9 + 7
for i in range(len(S)):
for j in range(13):
if S[i] == "?":
for k in range(10):
x = (j * 10 + k) % 13
dp[i + 1][x] += dp[i][j]
dp[i + 1][x] %= mod
else:
x = (j * 10 + int(S[i])) % 13
dp[i + 1][x] += dp[i][j]
dp[i + 1][x] %= mod
print((dp[-1][5]))
| false | 10 |
[
"-MOD = 10**9 + 7",
"-MAX_LEN = len(S)",
"-dp = [[0] * 13 for _ in range(MAX_LEN + 1)]",
"+dp = [[0] * 13 for _ in range(len(S) + 1)]",
"-for i in range(MAX_LEN):",
"- c = int(S[i]) if S[i] != \"?\" else -1",
"- for j in range(10):",
"- if c != -1 and c != j:",
"- continue",
"- for k in range(13):",
"- idx = (k * 10 + j) % 13",
"- dp[i + 1][idx] += dp[i][k]",
"- dp[i + 1][idx] %= MOD",
"+mod = 10**9 + 7",
"+for i in range(len(S)):",
"+ for j in range(13):",
"+ if S[i] == \"?\":",
"+ for k in range(10):",
"+ x = (j * 10 + k) % 13",
"+ dp[i + 1][x] += dp[i][j]",
"+ dp[i + 1][x] %= mod",
"+ else:",
"+ x = (j * 10 + int(S[i])) % 13",
"+ dp[i + 1][x] += dp[i][j]",
"+ dp[i + 1][x] %= mod"
] | false | 0.078661 | 0.076227 | 1.031925 |
[
"s732315823",
"s095322735"
] |
u321035578
|
p02678
|
python
|
s662976175
|
s112599497
| 898 | 617 | 37,080 | 36,916 |
Accepted
|
Accepted
| 31.29 |
import queue
def main():
n,m = list(map(int,input().split()))
ab = [[] for i in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
ab[a-1].append(b-1)
ab[b-1].append(a-1)
q =queue.Queue()
q.put(0)
ans = [-1] * n
ans[0] = 0
while not q.empty():
now = q.get()
for i, next in enumerate(ab[now]):
if ans[next] == -1:
ans[next] = now+1
q.put(next)
print('Yes')
for i in range(1,n):
print((ans[i]))
if __name__=='__main__':
main()
|
from collections import deque
def main():
n,m = list(map(int,input().split()))
ab = [[] for i in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
ab[a-1].append(b-1)
ab[b-1].append(a-1)
q = deque()
q.append(0)
ans = [-1] * n
ans[0] = 0
while len(q) != 0:
now = q.popleft()
for i, next in enumerate(ab[now]):
if ans[next] == -1:
ans[next] = now+1
q.append(next)
print('Yes')
for i in range(1,n):
print((ans[i]))
if __name__=='__main__':
main()
| 27 | 27 | 600 | 612 |
import queue
def main():
n, m = list(map(int, input().split()))
ab = [[] for i in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
ab[a - 1].append(b - 1)
ab[b - 1].append(a - 1)
q = queue.Queue()
q.put(0)
ans = [-1] * n
ans[0] = 0
while not q.empty():
now = q.get()
for i, next in enumerate(ab[now]):
if ans[next] == -1:
ans[next] = now + 1
q.put(next)
print("Yes")
for i in range(1, n):
print((ans[i]))
if __name__ == "__main__":
main()
|
from collections import deque
def main():
n, m = list(map(int, input().split()))
ab = [[] for i in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
ab[a - 1].append(b - 1)
ab[b - 1].append(a - 1)
q = deque()
q.append(0)
ans = [-1] * n
ans[0] = 0
while len(q) != 0:
now = q.popleft()
for i, next in enumerate(ab[now]):
if ans[next] == -1:
ans[next] = now + 1
q.append(next)
print("Yes")
for i in range(1, n):
print((ans[i]))
if __name__ == "__main__":
main()
| false | 0 |
[
"-import queue",
"+from collections import deque",
"- q = queue.Queue()",
"- q.put(0)",
"+ q = deque()",
"+ q.append(0)",
"- while not q.empty():",
"- now = q.get()",
"+ while len(q) != 0:",
"+ now = q.popleft()",
"- q.put(next)",
"+ q.append(next)"
] | false | 0.058624 | 0.059076 | 0.992341 |
[
"s662976175",
"s112599497"
] |
u426534722
|
p02275
|
python
|
s439531941
|
s101552322
| 2,190 | 1,870 | 224,376 | 241,460 |
Accepted
|
Accepted
| 14.61 |
n = int(eval(input()))
def CountingSort(A, B, k):
C = [0] * (k + 1)
for j in range(n):
C[A[j]] += 1
C[0] -= 1
for i in range(1, k + 1):
C[i] += C[i - 1]
for j in A[::-1]:
B[C[j]] = j
C[j] -= 1
A = list(map(int, input().split()))
B = [0] * n
CountingSort(A, B, max(A))
print((*B))
|
n = int(eval(input()))
def CountingSort(A, B, k):
C = [0] * (k + 1)
for j in range(n):
C[A[j]] += 1
C[0] -= 1
for i in range(1, k + 1):
C[i] += C[i - 1]
for j in A[::-1]:
B[C[j]] = j
C[j] -= 1
A = list(map(int, input().split()))
B = [0] * n
CountingSort(A, B, max(A))
print((" ".join(map(str,B))))
| 16 | 16 | 340 | 358 |
n = int(eval(input()))
def CountingSort(A, B, k):
C = [0] * (k + 1)
for j in range(n):
C[A[j]] += 1
C[0] -= 1
for i in range(1, k + 1):
C[i] += C[i - 1]
for j in A[::-1]:
B[C[j]] = j
C[j] -= 1
A = list(map(int, input().split()))
B = [0] * n
CountingSort(A, B, max(A))
print((*B))
|
n = int(eval(input()))
def CountingSort(A, B, k):
C = [0] * (k + 1)
for j in range(n):
C[A[j]] += 1
C[0] -= 1
for i in range(1, k + 1):
C[i] += C[i - 1]
for j in A[::-1]:
B[C[j]] = j
C[j] -= 1
A = list(map(int, input().split()))
B = [0] * n
CountingSort(A, B, max(A))
print((" ".join(map(str, B))))
| false | 0 |
[
"-print((*B))",
"+print((\" \".join(map(str, B))))"
] | false | 0.113985 | 0.050769 | 2.245164 |
[
"s439531941",
"s101552322"
] |
u477638578
|
p02554
|
python
|
s189802050
|
s177812974
| 390 | 30 | 10,904 | 9,164 |
Accepted
|
Accepted
| 92.31 |
# #
# author : samars_diary #
# 16-09-2020 │ 18:28:11 #
# #
import sys, os.path, math
#if(os.path.exists('input.txt')):
#sys.stdin = open('input.txt',"r")
#sys.stdout = open('output.txt',"w")
sys.setrecursionlimit(10 ** 5)
def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return list(map(int, sys.stdin.readline().split()))
def lii(): return list(map(int, sys.stdin.readline().strip().split()))
#print=sys.stdout.write
def solve():
a=ii()
print((((10**a)-2*(9**a)+(8**a))%mod()))
for _ in range(1):
solve()
|
# #
# author : samars_diary #
# 16-09-2020 │ 18:28:11 #
# #
import sys, os.path, math
#if(os.path.exists('input.txt')):
#sys.stdin = open('input.txt',"r")
#sys.stdout = open('output.txt',"w")
sys.setrecursionlimit(10 ** 5)
def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return list(map(int, sys.stdin.readline().split()))
def lii(): return list(map(int, sys.stdin.readline().strip().split()))
#print=sys.stdout.write
def solve():
a=ii();print(((pow(10,a,mod())+pow(8,a,mod())-2*pow(9,a,mod()))%mod()))
for _ in range(1):
solve()
| 27 | 26 | 746 | 765 |
# #
# author : samars_diary #
# 16-09-2020 │ 18:28:11 #
# #
import sys, os.path, math
# if(os.path.exists('input.txt')):
# sys.stdin = open('input.txt',"r")
# sys.stdout = open('output.txt',"w")
sys.setrecursionlimit(10**5)
def mod():
return 10**9 + 7
def i():
return sys.stdin.readline().strip()
def ii():
return int(sys.stdin.readline())
def li():
return list(sys.stdin.readline().strip())
def mii():
return list(map(int, sys.stdin.readline().split()))
def lii():
return list(map(int, sys.stdin.readline().strip().split()))
# print=sys.stdout.write
def solve():
a = ii()
print((((10**a) - 2 * (9**a) + (8**a)) % mod()))
for _ in range(1):
solve()
|
# #
# author : samars_diary #
# 16-09-2020 │ 18:28:11 #
# #
import sys, os.path, math
# if(os.path.exists('input.txt')):
# sys.stdin = open('input.txt',"r")
# sys.stdout = open('output.txt',"w")
sys.setrecursionlimit(10**5)
def mod():
return 10**9 + 7
def i():
return sys.stdin.readline().strip()
def ii():
return int(sys.stdin.readline())
def li():
return list(sys.stdin.readline().strip())
def mii():
return list(map(int, sys.stdin.readline().split()))
def lii():
return list(map(int, sys.stdin.readline().strip().split()))
# print=sys.stdout.write
def solve():
a = ii()
print(((pow(10, a, mod()) + pow(8, a, mod()) - 2 * pow(9, a, mod())) % mod()))
for _ in range(1):
solve()
| false | 3.703704 |
[
"- print((((10**a) - 2 * (9**a) + (8**a)) % mod()))",
"+ print(((pow(10, a, mod()) + pow(8, a, mod()) - 2 * pow(9, a, mod())) % mod()))"
] | false | 0.128893 | 0.036159 | 3.56462 |
[
"s189802050",
"s177812974"
] |
u486251525
|
p03557
|
python
|
s672279477
|
s670595427
| 895 | 325 | 23,924 | 22,720 |
Accepted
|
Accepted
| 63.69 |
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
sumSunuke = 0
def bs_left(list, target):
low, high = 0, len(list)
while low < high:
mid = (low + high) // 2
if list[mid] < target:
low = mid + 1
else:
high = mid
return low
def bs_right(list, target):
low, high = 0, len(list)
while low < high:
mid = (low + high) // 2
if list[mid] > target:
high = mid
else:
low = mid + 1
return low
for x in range(N):
ab = bs_left(A, B[x])
bc = N - bs_right(C, B[x])
sumSunuke += ab * bc
print(sumSunuke)
|
from bisect import bisect_left, bisect_right
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
sumSunuke = 0
for x in range(N):
ab = bisect_left(A, B[x])
bc = N - bisect_right(C, B[x])
sumSunuke += ab * bc
print(sumSunuke)
| 34 | 13 | 741 | 330 |
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
sumSunuke = 0
def bs_left(list, target):
low, high = 0, len(list)
while low < high:
mid = (low + high) // 2
if list[mid] < target:
low = mid + 1
else:
high = mid
return low
def bs_right(list, target):
low, high = 0, len(list)
while low < high:
mid = (low + high) // 2
if list[mid] > target:
high = mid
else:
low = mid + 1
return low
for x in range(N):
ab = bs_left(A, B[x])
bc = N - bs_right(C, B[x])
sumSunuke += ab * bc
print(sumSunuke)
|
from bisect import bisect_left, bisect_right
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
sumSunuke = 0
for x in range(N):
ab = bisect_left(A, B[x])
bc = N - bisect_right(C, B[x])
sumSunuke += ab * bc
print(sumSunuke)
| false | 61.764706 |
[
"+from bisect import bisect_left, bisect_right",
"+",
"-",
"-",
"-def bs_left(list, target):",
"- low, high = 0, len(list)",
"- while low < high:",
"- mid = (low + high) // 2",
"- if list[mid] < target:",
"- low = mid + 1",
"- else:",
"- high = mid",
"- return low",
"-",
"-",
"-def bs_right(list, target):",
"- low, high = 0, len(list)",
"- while low < high:",
"- mid = (low + high) // 2",
"- if list[mid] > target:",
"- high = mid",
"- else:",
"- low = mid + 1",
"- return low",
"-",
"-",
"- ab = bs_left(A, B[x])",
"- bc = N - bs_right(C, B[x])",
"+ ab = bisect_left(A, B[x])",
"+ bc = N - bisect_right(C, B[x])"
] | false | 0.061549 | 0.076257 | 0.807119 |
[
"s672279477",
"s670595427"
] |
u348805958
|
p02781
|
python
|
s255649454
|
s854995734
| 23 | 18 | 3,440 | 3,188 |
Accepted
|
Accepted
| 21.74 |
#!python3
iim = lambda: list(map(int, input().rstrip().split()))
def resolve():
N = list(map(int, eval(input())))
K = int(eval(input()))
size = len(N)
if size < K:
print((0))
return
dp = [[[0]*(size+1) for j in range(2)] for i in range(size+1)]
dp[0][0][0] = 1
for i in range(size):
for k in range(i+1):
dp0, dp1 = dp[i], dp[i+1]
dp1[1][k+1] += 9 * dp0[1][k]
dp1[1][k] += dp0[1][k]
x, y = N[i], dp0[0][k]
if x == 0:
dp1[0][k] += y
else:
dp1[1][k] += y
dp1[0][k+1] += y
dp1[1][k+1] += (x-1) * y
#print(dp1)
print((dp[-1][0][K] + dp[-1][1][K]))
if __name__ == "__main__":
resolve()
|
#!python3
iim = lambda: list(map(int, input().rstrip().split()))
def resolve():
N = list(map(int, eval(input())))
K = int(eval(input()))
size = len(N)
if size < K:
print((0))
return
dp = [[[0]*(size+1) for j in range(2)] for i in range(size+1)]
dp[0][0][0] = 1
for i in range(size):
for k in range(min(i+1, K+1)):
dp0, dp1 = dp[i], dp[i+1]
dp1[1][k+1] += 9 * dp0[1][k]
dp1[1][k] += dp0[1][k]
x, y = N[i], dp0[0][k]
if x == 0:
dp1[0][k] += y
else:
dp1[1][k] += y
dp1[0][k+1] += y
dp1[1][k+1] += (x-1) * y
#print(dp1)
print((dp[-1][0][K] + dp[-1][1][K]))
if __name__ == "__main__":
resolve()
| 37 | 37 | 814 | 824 |
#!python3
iim = lambda: list(map(int, input().rstrip().split()))
def resolve():
N = list(map(int, eval(input())))
K = int(eval(input()))
size = len(N)
if size < K:
print((0))
return
dp = [[[0] * (size + 1) for j in range(2)] for i in range(size + 1)]
dp[0][0][0] = 1
for i in range(size):
for k in range(i + 1):
dp0, dp1 = dp[i], dp[i + 1]
dp1[1][k + 1] += 9 * dp0[1][k]
dp1[1][k] += dp0[1][k]
x, y = N[i], dp0[0][k]
if x == 0:
dp1[0][k] += y
else:
dp1[1][k] += y
dp1[0][k + 1] += y
dp1[1][k + 1] += (x - 1) * y
# print(dp1)
print((dp[-1][0][K] + dp[-1][1][K]))
if __name__ == "__main__":
resolve()
|
#!python3
iim = lambda: list(map(int, input().rstrip().split()))
def resolve():
N = list(map(int, eval(input())))
K = int(eval(input()))
size = len(N)
if size < K:
print((0))
return
dp = [[[0] * (size + 1) for j in range(2)] for i in range(size + 1)]
dp[0][0][0] = 1
for i in range(size):
for k in range(min(i + 1, K + 1)):
dp0, dp1 = dp[i], dp[i + 1]
dp1[1][k + 1] += 9 * dp0[1][k]
dp1[1][k] += dp0[1][k]
x, y = N[i], dp0[0][k]
if x == 0:
dp1[0][k] += y
else:
dp1[1][k] += y
dp1[0][k + 1] += y
dp1[1][k + 1] += (x - 1) * y
# print(dp1)
print((dp[-1][0][K] + dp[-1][1][K]))
if __name__ == "__main__":
resolve()
| false | 0 |
[
"- for k in range(i + 1):",
"+ for k in range(min(i + 1, K + 1)):"
] | false | 0.077037 | 0.132345 | 0.582094 |
[
"s255649454",
"s854995734"
] |
u606045429
|
p02972
|
python
|
s952887102
|
s688073391
| 339 | 259 | 74,204 | 14,140 |
Accepted
|
Accepted
| 23.6 |
from sys import stderr
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [0] * N
for i in range(N // 2, N):
B[i] = A[i]
for i in reversed(list(range(N // 2))):
s = sum(B[i::i + 1])
B[i] = (A[i] - s) % 2
ans = [i + 1 for i, b in enumerate(B) if b == 1]
print((len(ans)))
if ans:
print((*ans))
|
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [0] * N
for i in reversed(list(range(N))):
B[i] = (A[i] - sum(B[i::i + 1])) % 2
ans = [i + 1 for i, b in enumerate(B) if b == 1]
print((len(ans)))
print((*ans))
| 17 | 10 | 326 | 224 |
from sys import stderr
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [0] * N
for i in range(N // 2, N):
B[i] = A[i]
for i in reversed(list(range(N // 2))):
s = sum(B[i :: i + 1])
B[i] = (A[i] - s) % 2
ans = [i + 1 for i, b in enumerate(B) if b == 1]
print((len(ans)))
if ans:
print((*ans))
|
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [0] * N
for i in reversed(list(range(N))):
B[i] = (A[i] - sum(B[i :: i + 1])) % 2
ans = [i + 1 for i, b in enumerate(B) if b == 1]
print((len(ans)))
print((*ans))
| false | 41.176471 |
[
"-from sys import stderr",
"-",
"-for i in range(N // 2, N):",
"- B[i] = A[i]",
"-for i in reversed(list(range(N // 2))):",
"- s = sum(B[i :: i + 1])",
"- B[i] = (A[i] - s) % 2",
"+for i in reversed(list(range(N))):",
"+ B[i] = (A[i] - sum(B[i :: i + 1])) % 2",
"-if ans:",
"- print((*ans))",
"+print((*ans))"
] | false | 0.038694 | 0.036144 | 1.070545 |
[
"s952887102",
"s688073391"
] |
u624475441
|
p03713
|
python
|
s792677967
|
s384941304
| 328 | 17 | 3,064 | 3,064 |
Accepted
|
Accepted
| 94.82 |
def calc(H, W, ans):
w0 = W // 2
w1 = W - w0
for h0 in range(1, H):
Sa = h0 * W
h1 = H - h0
h2 = h1 // 2
h3 = h1 - h2
Sb1, Sc1 = h1 * w0, h1 * w1
Sb2, Sc2 = h2 * W, h3 * W
m1, _, M1 = sorted([Sa, Sb1, Sc1])
m2, _, M2 = sorted([Sa, Sb2, Sc2])
ans = min(ans, M1 - m1, M2 - m2)
return ans
H, W = list(map(int, input().split()))
print((calc(W, H, calc(H, W, H * W))))
|
h, w = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
print((0))
else:
a = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
b = (h - h // 3) * (w - w // 2) - h // 3 * w
c = min(h, w)
h, w = w, h
d = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
e = (h - h // 3) * (w - w // 2) - h // 3 * w
print((min(a, b, c, d, e)))
| 17 | 11 | 460 | 362 |
def calc(H, W, ans):
w0 = W // 2
w1 = W - w0
for h0 in range(1, H):
Sa = h0 * W
h1 = H - h0
h2 = h1 // 2
h3 = h1 - h2
Sb1, Sc1 = h1 * w0, h1 * w1
Sb2, Sc2 = h2 * W, h3 * W
m1, _, M1 = sorted([Sa, Sb1, Sc1])
m2, _, M2 = sorted([Sa, Sb2, Sc2])
ans = min(ans, M1 - m1, M2 - m2)
return ans
H, W = list(map(int, input().split()))
print((calc(W, H, calc(H, W, H * W))))
|
h, w = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
print((0))
else:
a = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
b = (h - h // 3) * (w - w // 2) - h // 3 * w
c = min(h, w)
h, w = w, h
d = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
e = (h - h // 3) * (w - w // 2) - h // 3 * w
print((min(a, b, c, d, e)))
| false | 35.294118 |
[
"-def calc(H, W, ans):",
"- w0 = W // 2",
"- w1 = W - w0",
"- for h0 in range(1, H):",
"- Sa = h0 * W",
"- h1 = H - h0",
"- h2 = h1 // 2",
"- h3 = h1 - h2",
"- Sb1, Sc1 = h1 * w0, h1 * w1",
"- Sb2, Sc2 = h2 * W, h3 * W",
"- m1, _, M1 = sorted([Sa, Sb1, Sc1])",
"- m2, _, M2 = sorted([Sa, Sb2, Sc2])",
"- ans = min(ans, M1 - m1, M2 - m2)",
"- return ans",
"-",
"-",
"-H, W = list(map(int, input().split()))",
"-print((calc(W, H, calc(H, W, H * W))))",
"+h, w = list(map(int, input().split()))",
"+if h % 3 == 0 or w % 3 == 0:",
"+ print((0))",
"+else:",
"+ a = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)",
"+ b = (h - h // 3) * (w - w // 2) - h // 3 * w",
"+ c = min(h, w)",
"+ h, w = w, h",
"+ d = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)",
"+ e = (h - h // 3) * (w - w // 2) - h // 3 * w",
"+ print((min(a, b, c, d, e)))"
] | false | 0.142676 | 0.036272 | 3.933475 |
[
"s792677967",
"s384941304"
] |
u167931717
|
p03087
|
python
|
s855566035
|
s512300311
| 601 | 525 | 55,316 | 19,444 |
Accepted
|
Accepted
| 12.65 |
###############################################################################
from bisect import bisect_left as binl
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return list(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
###############################################################################
def main():
n, q = intin()
s = eval(input())
lrlist = intinl(q)
lrlist = [(l, r) for l, r in lrlist]
prev = None
pos_i_list = []
for i, c in enumerate(s):
if prev == 'A' and c == 'C':
pos_i_list.append(i)
prev = c
for l, r in lrlist:
start = binl(pos_i_list, l)
end = binl(pos_i_list, r)
print((end - start))
if __name__ == '__main__':
main()
|
###############################################################################
from bisect import bisect_left as binl
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * sy) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
###############################################################################
def main():
n, q = intin()
s = eval(input())
lrlist = intinl(q)
prev = None
pos_i_list = []
for i, c in enumerate(s):
if prev == 'A' and c == 'C':
pos_i_list.append(i)
prev = c
for l, r in lrlist:
start = binl(pos_i_list, l)
end = binl(pos_i_list, r)
print((end - start))
if __name__ == '__main__':
main()
| 51 | 60 | 1,046 | 1,142 |
###############################################################################
from bisect import bisect_left as binl
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return list(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
###############################################################################
def main():
n, q = intin()
s = eval(input())
lrlist = intinl(q)
lrlist = [(l, r) for l, r in lrlist]
prev = None
pos_i_list = []
for i, c in enumerate(s):
if prev == "A" and c == "C":
pos_i_list.append(i)
prev = c
for l, r in lrlist:
start = binl(pos_i_list, l)
end = binl(pos_i_list, r)
print((end - start))
if __name__ == "__main__":
main()
|
###############################################################################
from bisect import bisect_left as binl
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * sy) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
###############################################################################
def main():
n, q = intin()
s = eval(input())
lrlist = intinl(q)
prev = None
pos_i_list = []
for i, c in enumerate(s):
if prev == "A" and c == "C":
pos_i_list.append(i)
prev = c
for l, r in lrlist:
start = binl(pos_i_list, l)
end = binl(pos_i_list, r)
print((end - start))
if __name__ == "__main__":
main()
| false | 15 |
[
"- return list(map(int, input_tuple))",
"+ return tuple(map(int, input_tuple))",
"+",
"+",
"+def modadd(x, y):",
"+ global mod",
"+ return (x + y) % mod",
"+",
"+",
"+def modmlt(x, y):",
"+ global mod",
"+ return (x * sy) % mod",
"- lrlist = [(l, r) for l, r in lrlist]"
] | false | 0.069175 | 0.045119 | 1.533178 |
[
"s855566035",
"s512300311"
] |
u459150945
|
p02786
|
python
|
s608880163
|
s598948586
| 19 | 17 | 3,060 | 2,940 |
Accepted
|
Accepted
| 10.53 |
H = int(eval(input()))
if H == 1:
print((1))
else:
cnt = 0
while H > 3:
H = H//2
cnt += 1
ans = 0
for i in range(cnt):
ans += 2**i
print((int(((2**cnt)*3)+ans)))
|
H = int(eval(input()))
def f(H):
if H == 1:
return 1
else:
return f(H//2) * 2 + 1
print((f(H)))
| 12 | 10 | 210 | 124 |
H = int(eval(input()))
if H == 1:
print((1))
else:
cnt = 0
while H > 3:
H = H // 2
cnt += 1
ans = 0
for i in range(cnt):
ans += 2**i
print((int(((2**cnt) * 3) + ans)))
|
H = int(eval(input()))
def f(H):
if H == 1:
return 1
else:
return f(H // 2) * 2 + 1
print((f(H)))
| false | 16.666667 |
[
"-if H == 1:",
"- print((1))",
"-else:",
"- cnt = 0",
"- while H > 3:",
"- H = H // 2",
"- cnt += 1",
"- ans = 0",
"- for i in range(cnt):",
"- ans += 2**i",
"- print((int(((2**cnt) * 3) + ans)))",
"+",
"+",
"+def f(H):",
"+ if H == 1:",
"+ return 1",
"+ else:",
"+ return f(H // 2) * 2 + 1",
"+",
"+",
"+print((f(H)))"
] | false | 0.062263 | 0.050613 | 1.23017 |
[
"s608880163",
"s598948586"
] |
u981931040
|
p03145
|
python
|
s495652616
|
s389227617
| 19 | 17 | 3,064 | 2,940 |
Accepted
|
Accepted
| 10.53 |
A , B , _ = list(map(int,input().split()))
print((A * B // 2))
|
ab, bc ,_ = list(map(int,input().split()))
print((ab * bc // 2))
| 2 | 2 | 55 | 57 |
A, B, _ = list(map(int, input().split()))
print((A * B // 2))
|
ab, bc, _ = list(map(int, input().split()))
print((ab * bc // 2))
| false | 0 |
[
"-A, B, _ = list(map(int, input().split()))",
"-print((A * B // 2))",
"+ab, bc, _ = list(map(int, input().split()))",
"+print((ab * bc // 2))"
] | false | 0.139037 | 0.044984 | 3.090828 |
[
"s495652616",
"s389227617"
] |
u691018832
|
p03221
|
python
|
s916078530
|
s105219383
| 1,185 | 749 | 66,524 | 33,428 |
Accepted
|
Accepted
| 36.79 |
import sys
input = sys.stdin.readline
def binary_search(list, item):
low = 0
high = len(list) - 1
while low <= high:
mid = (low + high) // 2
guess = list[mid]
if guess == item:
return mid
if guess > item:
high = mid - 1
else:
low = mid + 1
n, m = list(map(int, input().split()))
py = [list(map(int, input().split())) for i in range(m)]
check = sorted(py)
memo = py[0][0]
cnt = [0] * m
cnt_memo = 0
for i in range(m):
if memo != check[i][0]:
memo = check[i][0]
cnt_memo = 0
cnt_memo += 1
cnt[i] = cnt_memo
for i in range(m):
number = str(cnt[binary_search(check, py[i])])
p = str(py[i][0])
print(((6 - len(p)) * '0' + p + (6 - len(number)) * '0' + number))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from bisect import bisect_left
n, m = list(map(int, readline().split()))
py = [list(map(int, readline().split())) for _ in range(m)]
check = sorted(py)
idx = [0] * (n + 1)
memo = 0
for i, (p, _) in enumerate(check):
if memo != p:
idx[p] = i
memo = p
for p, y in py:
yy = str(bisect_left(check, [p, y]) - idx[p] + 1)
p = str(p)
print(('0' * (6 - len(p)) + p + '0' * (6 - len(yy)) + yy))
| 37 | 21 | 819 | 579 |
import sys
input = sys.stdin.readline
def binary_search(list, item):
low = 0
high = len(list) - 1
while low <= high:
mid = (low + high) // 2
guess = list[mid]
if guess == item:
return mid
if guess > item:
high = mid - 1
else:
low = mid + 1
n, m = list(map(int, input().split()))
py = [list(map(int, input().split())) for i in range(m)]
check = sorted(py)
memo = py[0][0]
cnt = [0] * m
cnt_memo = 0
for i in range(m):
if memo != check[i][0]:
memo = check[i][0]
cnt_memo = 0
cnt_memo += 1
cnt[i] = cnt_memo
for i in range(m):
number = str(cnt[binary_search(check, py[i])])
p = str(py[i][0])
print(((6 - len(p)) * "0" + p + (6 - len(number)) * "0" + number))
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from bisect import bisect_left
n, m = list(map(int, readline().split()))
py = [list(map(int, readline().split())) for _ in range(m)]
check = sorted(py)
idx = [0] * (n + 1)
memo = 0
for i, (p, _) in enumerate(check):
if memo != p:
idx[p] = i
memo = p
for p, y in py:
yy = str(bisect_left(check, [p, y]) - idx[p] + 1)
p = str(p)
print(("0" * (6 - len(p)) + p + "0" * (6 - len(yy)) + yy))
| false | 43.243243 |
[
"-input = sys.stdin.readline",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(10**7)",
"+from bisect import bisect_left",
"-",
"-def binary_search(list, item):",
"- low = 0",
"- high = len(list) - 1",
"- while low <= high:",
"- mid = (low + high) // 2",
"- guess = list[mid]",
"- if guess == item:",
"- return mid",
"- if guess > item:",
"- high = mid - 1",
"- else:",
"- low = mid + 1",
"-",
"-",
"-n, m = list(map(int, input().split()))",
"-py = [list(map(int, input().split())) for i in range(m)]",
"+n, m = list(map(int, readline().split()))",
"+py = [list(map(int, readline().split())) for _ in range(m)]",
"-memo = py[0][0]",
"-cnt = [0] * m",
"-cnt_memo = 0",
"-for i in range(m):",
"- if memo != check[i][0]:",
"- memo = check[i][0]",
"- cnt_memo = 0",
"- cnt_memo += 1",
"- cnt[i] = cnt_memo",
"-for i in range(m):",
"- number = str(cnt[binary_search(check, py[i])])",
"- p = str(py[i][0])",
"- print(((6 - len(p)) * \"0\" + p + (6 - len(number)) * \"0\" + number))",
"+idx = [0] * (n + 1)",
"+memo = 0",
"+for i, (p, _) in enumerate(check):",
"+ if memo != p:",
"+ idx[p] = i",
"+ memo = p",
"+for p, y in py:",
"+ yy = str(bisect_left(check, [p, y]) - idx[p] + 1)",
"+ p = str(p)",
"+ print((\"0\" * (6 - len(p)) + p + \"0\" * (6 - len(yy)) + yy))"
] | false | 0.095668 | 0.040629 | 2.354692 |
[
"s916078530",
"s105219383"
] |
u353797797
|
p03003
|
python
|
s182862905
|
s778562238
| 1,622 | 1,449 | 159,520 | 3,316 |
Accepted
|
Accepted
| 10.67 |
def f(n, m):
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [[1] * (m + 1) for _ in range(n + 1)]
for i, sk in enumerate(s):
dpi1 = dp[i + 1] = dp[i][:]
cs = 0
for j, tk in enumerate(t):
if sk == tk:
cs = (cs + dp[i][j]) % md
dpi1[j + 1] = (dpi1[j + 1] + cs) % md
# for x in dp:
# print(*x)
print((dp[-1][-1]))
md = 10 ** 9 + 7
n, m = list(map(int, input().split()))
f(n, m)
|
def f(n, m):
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dpi = [1] * (m + 1)
for i, sk in enumerate(s):
dpi1 = dpi[:]
cs = 0
for j, tk in enumerate(t):
if sk == tk:
cs = (cs + dpi[j]) % md
dpi1[j + 1] = (dpi1[j + 1] + cs) % md
dpi=dpi1
# for x in dp:
# print(*x)
print((dpi1[-1]))
md = 10 ** 9 + 7
n, m = list(map(int, input().split()))
f(n, m)
| 18 | 19 | 507 | 484 |
def f(n, m):
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [[1] * (m + 1) for _ in range(n + 1)]
for i, sk in enumerate(s):
dpi1 = dp[i + 1] = dp[i][:]
cs = 0
for j, tk in enumerate(t):
if sk == tk:
cs = (cs + dp[i][j]) % md
dpi1[j + 1] = (dpi1[j + 1] + cs) % md
# for x in dp:
# print(*x)
print((dp[-1][-1]))
md = 10**9 + 7
n, m = list(map(int, input().split()))
f(n, m)
|
def f(n, m):
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dpi = [1] * (m + 1)
for i, sk in enumerate(s):
dpi1 = dpi[:]
cs = 0
for j, tk in enumerate(t):
if sk == tk:
cs = (cs + dpi[j]) % md
dpi1[j + 1] = (dpi1[j + 1] + cs) % md
dpi = dpi1
# for x in dp:
# print(*x)
print((dpi1[-1]))
md = 10**9 + 7
n, m = list(map(int, input().split()))
f(n, m)
| false | 5.263158 |
[
"- dp = [[1] * (m + 1) for _ in range(n + 1)]",
"+ dpi = [1] * (m + 1)",
"- dpi1 = dp[i + 1] = dp[i][:]",
"+ dpi1 = dpi[:]",
"- cs = (cs + dp[i][j]) % md",
"+ cs = (cs + dpi[j]) % md",
"+ dpi = dpi1",
"- print((dp[-1][-1]))",
"+ print((dpi1[-1]))"
] | false | 0.038324 | 0.086451 | 0.443306 |
[
"s182862905",
"s778562238"
] |
u188827677
|
p02947
|
python
|
s058713210
|
s334025423
| 368 | 337 | 23,464 | 19,476 |
Accepted
|
Accepted
| 8.42 |
import collections
n = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for i in set(s):
x = c[i]
ans += x * (x -1)//2
print(ans)
|
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
for i in range(n):
s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
if s[i] in t:
t[s[i]] += 1
else:
t[s[i]] = 1
print((sum(t[k] * (t[k] -1) // 2 for k in t)))
| 12 | 11 | 195 | 236 |
import collections
n = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for i in set(s):
x = c[i]
ans += x * (x - 1) // 2
print(ans)
|
n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
for i in range(n):
s[i] = "".join(sorted(s[i]))
t = {}
for i in range(n):
if s[i] in t:
t[s[i]] += 1
else:
t[s[i]] = 1
print((sum(t[k] * (t[k] - 1) // 2 for k in t)))
| false | 8.333333 |
[
"-import collections",
"-",
"-s = [\"\".join(sorted(eval(input()))) for _ in range(n)]",
"-c = collections.Counter(s)",
"-ans = 0",
"-for i in set(s):",
"- x = c[i]",
"- ans += x * (x - 1) // 2",
"-print(ans)",
"+s = [eval(input()) for _ in range(n)]",
"+for i in range(n):",
"+ s[i] = \"\".join(sorted(s[i]))",
"+t = {}",
"+for i in range(n):",
"+ if s[i] in t:",
"+ t[s[i]] += 1",
"+ else:",
"+ t[s[i]] = 1",
"+print((sum(t[k] * (t[k] - 1) // 2 for k in t)))"
] | false | 0.045505 | 0.118988 | 0.382434 |
[
"s058713210",
"s334025423"
] |
u708255304
|
p03037
|
python
|
s454356851
|
s148369466
| 410 | 321 | 8,876 | 3,060 |
Accepted
|
Accepted
| 21.71 |
N, M = list(map(int, input().split()))
imos = [0]*(N+1)
for _ in range(M):
# ゲートの情報が入ってくる
l, r = [int(x)-1 for x in input().split()]
imos[l] += 1
imos[r+1] -= 1 # rまでは有効であり、r+1以降が無向になる仕様であるのでr+1をデクリメントする
cumulative = [imos[0]]
for value in imos[1:]:
cumulative.append(cumulative[-1]+value)
ans = 0
for c in cumulative:
if c == M:
ans += 1
print(ans)
|
N, M = list(map(int, input().split()))
left = -1
right = 10**10
for _ in range(M):
l, r = list(map(int, input().split()))
left = max(left, l)
right = min(right, r)
print((max(right-left+1, 0)))
| 16 | 10 | 398 | 203 |
N, M = list(map(int, input().split()))
imos = [0] * (N + 1)
for _ in range(M):
# ゲートの情報が入ってくる
l, r = [int(x) - 1 for x in input().split()]
imos[l] += 1
imos[r + 1] -= 1 # rまでは有効であり、r+1以降が無向になる仕様であるのでr+1をデクリメントする
cumulative = [imos[0]]
for value in imos[1:]:
cumulative.append(cumulative[-1] + value)
ans = 0
for c in cumulative:
if c == M:
ans += 1
print(ans)
|
N, M = list(map(int, input().split()))
left = -1
right = 10**10
for _ in range(M):
l, r = list(map(int, input().split()))
left = max(left, l)
right = min(right, r)
print((max(right - left + 1, 0)))
| false | 37.5 |
[
"-imos = [0] * (N + 1)",
"+left = -1",
"+right = 10**10",
"- # ゲートの情報が入ってくる",
"- l, r = [int(x) - 1 for x in input().split()]",
"- imos[l] += 1",
"- imos[r + 1] -= 1 # rまでは有効であり、r+1以降が無向になる仕様であるのでr+1をデクリメントする",
"-cumulative = [imos[0]]",
"-for value in imos[1:]:",
"- cumulative.append(cumulative[-1] + value)",
"-ans = 0",
"-for c in cumulative:",
"- if c == M:",
"- ans += 1",
"-print(ans)",
"+ l, r = list(map(int, input().split()))",
"+ left = max(left, l)",
"+ right = min(right, r)",
"+print((max(right - left + 1, 0)))"
] | false | 0.087291 | 0.070004 | 1.246931 |
[
"s454356851",
"s148369466"
] |
u277802731
|
p03610
|
python
|
s822454953
|
s743771556
| 35 | 17 | 3,572 | 3,188 |
Accepted
|
Accepted
| 51.43 |
#72b
s = eval(input())
ans=[]
for i in range(len(s)):
if i%2==0:
ans.append(s[i])
print((''.join(ans)))
|
s = eval(input())
print((s[::2]))
| 7 | 2 | 113 | 26 |
# 72b
s = eval(input())
ans = []
for i in range(len(s)):
if i % 2 == 0:
ans.append(s[i])
print(("".join(ans)))
|
s = eval(input())
print((s[::2]))
| false | 71.428571 |
[
"-# 72b",
"-ans = []",
"-for i in range(len(s)):",
"- if i % 2 == 0:",
"- ans.append(s[i])",
"-print((\"\".join(ans)))",
"+print((s[::2]))"
] | false | 0.045273 | 0.04009 | 1.129308 |
[
"s822454953",
"s743771556"
] |
u227082700
|
p02848
|
python
|
s770536693
|
s388010447
| 25 | 19 | 3,316 | 3,060 |
Accepted
|
Accepted
| 24 |
n=int(eval(input()))
s=eval(input())
t=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2)
a=""
for i in s:a+=t[t.index(i)+n]
print(a)
|
t="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
n=int(eval(input()))
print(("".join([t[t.index(i)+n]for i in eval(input())])))
| 6 | 3 | 112 | 123 |
n = int(eval(input()))
s = eval(input())
t = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ" * 2)
a = ""
for i in s:
a += t[t.index(i) + n]
print(a)
|
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
n = int(eval(input()))
print(("".join([t[t.index(i) + n] for i in eval(input())])))
| false | 50 |
[
"+t = \"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\"",
"-s = eval(input())",
"-t = list(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\" * 2)",
"-a = \"\"",
"-for i in s:",
"- a += t[t.index(i) + n]",
"-print(a)",
"+print((\"\".join([t[t.index(i) + n] for i in eval(input())])))"
] | false | 0.038738 | 0.038463 | 1.007149 |
[
"s770536693",
"s388010447"
] |
u982594421
|
p02820
|
python
|
s209725451
|
s541793234
| 1,116 | 803 | 4,084 | 4,084 |
Accepted
|
Accepted
| 28.05 |
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
h = [''] * n
c = {'r': 'p', 's': 'r', 'p': 's'}
points = 0
for i, ti in enumerate(t):
ci = c[ti]
if i < k or h[i - k] != c[ti]:
h[i] = ci
points += eval(ci)
else:
p1, p2 = eval(ci), eval(h[i - k])
if p1 > p2:
h[i] = ci
points -= p2
points += p1
else:
h[i] = '*'
print(points)
|
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
h = [''] * n
c = {'r': 'p', 's': 'r', 'p': 's'}
points = 0
for i, ti in enumerate(t):
ci = c[ti]
if i < k or h[i - k] != c[ti]:
h[i] = ci
points += eval(ci)
else:
# p1, p2 = eval(ci), eval(h[i - k])
# if p1 > p2:
# h[i] = ci
# points -= p2
# points += p1
# else:
h[i] = '*'
print(points)
| 24 | 24 | 484 | 492 |
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
h = [""] * n
c = {"r": "p", "s": "r", "p": "s"}
points = 0
for i, ti in enumerate(t):
ci = c[ti]
if i < k or h[i - k] != c[ti]:
h[i] = ci
points += eval(ci)
else:
p1, p2 = eval(ci), eval(h[i - k])
if p1 > p2:
h[i] = ci
points -= p2
points += p1
else:
h[i] = "*"
print(points)
|
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
h = [""] * n
c = {"r": "p", "s": "r", "p": "s"}
points = 0
for i, ti in enumerate(t):
ci = c[ti]
if i < k or h[i - k] != c[ti]:
h[i] = ci
points += eval(ci)
else:
# p1, p2 = eval(ci), eval(h[i - k])
# if p1 > p2:
# h[i] = ci
# points -= p2
# points += p1
# else:
h[i] = "*"
print(points)
| false | 0 |
[
"- p1, p2 = eval(ci), eval(h[i - k])",
"- if p1 > p2:",
"- h[i] = ci",
"- points -= p2",
"- points += p1",
"- else:",
"- h[i] = \"*\"",
"+ # p1, p2 = eval(ci), eval(h[i - k])",
"+ # if p1 > p2:",
"+ # h[i] = ci",
"+ # points -= p2",
"+ # points += p1",
"+ # else:",
"+ h[i] = \"*\""
] | false | 0.042814 | 0.072133 | 0.593552 |
[
"s209725451",
"s541793234"
] |
u763881112
|
p03486
|
python
|
s994873457
|
s253144343
| 291 | 151 | 20,872 | 14,408 |
Accepted
|
Accepted
| 48.11 |
import numpy as np
s=sorted(eval(input()))
t=sorted(eval(input()))
t.reverse()
print(("Yes" if(s<t) else "No"))
|
import numpy as np
s="".join(sorted(eval(input())))
t="".join(sorted(eval(input()),reverse=True))
if(s<t):
print("Yes")
else:
print("No")
| 10 | 11 | 112 | 147 |
import numpy as np
s = sorted(eval(input()))
t = sorted(eval(input()))
t.reverse()
print(("Yes" if (s < t) else "No"))
|
import numpy as np
s = "".join(sorted(eval(input())))
t = "".join(sorted(eval(input()), reverse=True))
if s < t:
print("Yes")
else:
print("No")
| false | 9.090909 |
[
"-s = sorted(eval(input()))",
"-t = sorted(eval(input()))",
"-t.reverse()",
"-print((\"Yes\" if (s < t) else \"No\"))",
"+s = \"\".join(sorted(eval(input())))",
"+t = \"\".join(sorted(eval(input()), reverse=True))",
"+if s < t:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.041401 | 0.042363 | 0.977291 |
[
"s994873457",
"s253144343"
] |
u814171899
|
p03305
|
python
|
s669542717
|
s446895697
| 1,981 | 1,593 | 99,688 | 94,660 |
Accepted
|
Accepted
| 19.59 |
from collections import defaultdict
from itertools import accumulate
import heapq
n,m,s,t=list(map(int, input().split()))
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
u,v,a,b=list(map(int, input().split()))
u-=1
v-=1
adj[u].append(v)
adj[v].append(u)
yen[u,v]=a
yen[v,u]=a
snk[u,v]=b
snk[v,u]=b
def dijkstra(s, t, cost):
q=[]
d=[float('inf')]*n
d[s]=0
heapq.heappush(q, (d[s], s))
while q!=[]:
du, u=heapq.heappop(q)
if du>d[u]:
continue
for v in adj[u]:
if d[v]>du+cost[u,v]:
d[v]=du+cost[u,v]
heapq.heappush(q, (d[v], v))
return d
d1=dijkstra(s, t, yen)
d2=dijkstra(t, s, snk)
ans=list(accumulate(reversed([y+s for y,s in zip(d1, d2)]), min))
for ai in reversed(ans):
print((10**15-ai))
|
from itertools import accumulate
import heapq
n,m,s,t=list(map(int, input().split()))
s-=1
t-=1
yen=[{} for _ in range(n)]
snk=[{} for _ in range(n)]
for _ in range(m):
u,v,a,b=list(map(int, input().split()))
u-=1
v-=1
yen[u][v]=a
yen[v][u]=a
snk[u][v]=b
snk[v][u]=b
def dijkstra(s, t, g):
q=[]
d=[float('inf')]*n
d[s]=0
heapq.heappush(q, (d[s], s))
while q!=[]:
du, u=heapq.heappop(q)
if du>d[u]:
continue
for v in g[u]:
if d[v]>du+g[u][v]:
d[v]=du+g[u][v]
heapq.heappush(q, (d[v], v))
return d
d1=dijkstra(s, t, yen)
d2=dijkstra(t, s, snk)
ans=list(accumulate(reversed([y+s for y,s in zip(d1, d2)]), min))
for ai in reversed(ans):
print((10**15-ai))
| 40 | 36 | 890 | 821 |
from collections import defaultdict
from itertools import accumulate
import heapq
n, m, s, t = list(map(int, input().split()))
s -= 1
t -= 1
yen = {}
snk = {}
adj = defaultdict(list)
for _ in range(m):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
adj[u].append(v)
adj[v].append(u)
yen[u, v] = a
yen[v, u] = a
snk[u, v] = b
snk[v, u] = b
def dijkstra(s, t, cost):
q = []
d = [float("inf")] * n
d[s] = 0
heapq.heappush(q, (d[s], s))
while q != []:
du, u = heapq.heappop(q)
if du > d[u]:
continue
for v in adj[u]:
if d[v] > du + cost[u, v]:
d[v] = du + cost[u, v]
heapq.heappush(q, (d[v], v))
return d
d1 = dijkstra(s, t, yen)
d2 = dijkstra(t, s, snk)
ans = list(accumulate(reversed([y + s for y, s in zip(d1, d2)]), min))
for ai in reversed(ans):
print((10**15 - ai))
|
from itertools import accumulate
import heapq
n, m, s, t = list(map(int, input().split()))
s -= 1
t -= 1
yen = [{} for _ in range(n)]
snk = [{} for _ in range(n)]
for _ in range(m):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
yen[u][v] = a
yen[v][u] = a
snk[u][v] = b
snk[v][u] = b
def dijkstra(s, t, g):
q = []
d = [float("inf")] * n
d[s] = 0
heapq.heappush(q, (d[s], s))
while q != []:
du, u = heapq.heappop(q)
if du > d[u]:
continue
for v in g[u]:
if d[v] > du + g[u][v]:
d[v] = du + g[u][v]
heapq.heappush(q, (d[v], v))
return d
d1 = dijkstra(s, t, yen)
d2 = dijkstra(t, s, snk)
ans = list(accumulate(reversed([y + s for y, s in zip(d1, d2)]), min))
for ai in reversed(ans):
print((10**15 - ai))
| false | 10 |
[
"-from collections import defaultdict",
"-yen = {}",
"-snk = {}",
"-adj = defaultdict(list)",
"+yen = [{} for _ in range(n)]",
"+snk = [{} for _ in range(n)]",
"- adj[u].append(v)",
"- adj[v].append(u)",
"- yen[u, v] = a",
"- yen[v, u] = a",
"- snk[u, v] = b",
"- snk[v, u] = b",
"+ yen[u][v] = a",
"+ yen[v][u] = a",
"+ snk[u][v] = b",
"+ snk[v][u] = b",
"-def dijkstra(s, t, cost):",
"+def dijkstra(s, t, g):",
"- for v in adj[u]:",
"- if d[v] > du + cost[u, v]:",
"- d[v] = du + cost[u, v]",
"+ for v in g[u]:",
"+ if d[v] > du + g[u][v]:",
"+ d[v] = du + g[u][v]"
] | false | 0.10881 | 0.094664 | 1.149433 |
[
"s669542717",
"s446895697"
] |
u133936772
|
p04013
|
python
|
s427893576
|
s455010164
| 164 | 27 | 5,620 | 3,188 |
Accepted
|
Accepted
| 83.54 |
f=lambda:list(map(int,input().split()))
n,a=f()
l=[i-a for i in f()]
dp=[[0]*5000 for _ in range(51)]
Z=2500
dp[0][Z]=1
for i in range(n):
for s in range(5000-max(l[i],0)):
dp[i+1][s]+=dp[i][s]
dp[i+1][s+l[i]]+=dp[i][s]
print((dp[n][Z]-1))
|
_,a,*l=list(map(int,open(0).read().split()))
d={0:1}
for i in l:
for k,v in list(d.copy().items()): d[i-a+k]=d.get(i-a+k,0)+v
print((d[0]-1))
| 11 | 5 | 251 | 133 |
f = lambda: list(map(int, input().split()))
n, a = f()
l = [i - a for i in f()]
dp = [[0] * 5000 for _ in range(51)]
Z = 2500
dp[0][Z] = 1
for i in range(n):
for s in range(5000 - max(l[i], 0)):
dp[i + 1][s] += dp[i][s]
dp[i + 1][s + l[i]] += dp[i][s]
print((dp[n][Z] - 1))
|
_, a, *l = list(map(int, open(0).read().split()))
d = {0: 1}
for i in l:
for k, v in list(d.copy().items()):
d[i - a + k] = d.get(i - a + k, 0) + v
print((d[0] - 1))
| false | 54.545455 |
[
"-f = lambda: list(map(int, input().split()))",
"-n, a = f()",
"-l = [i - a for i in f()]",
"-dp = [[0] * 5000 for _ in range(51)]",
"-Z = 2500",
"-dp[0][Z] = 1",
"-for i in range(n):",
"- for s in range(5000 - max(l[i], 0)):",
"- dp[i + 1][s] += dp[i][s]",
"- dp[i + 1][s + l[i]] += dp[i][s]",
"-print((dp[n][Z] - 1))",
"+_, a, *l = list(map(int, open(0).read().split()))",
"+d = {0: 1}",
"+for i in l:",
"+ for k, v in list(d.copy().items()):",
"+ d[i - a + k] = d.get(i - a + k, 0) + v",
"+print((d[0] - 1))"
] | false | 0.057935 | 0.038404 | 1.508557 |
[
"s427893576",
"s455010164"
] |
u735335967
|
p03289
|
python
|
s308309198
|
s906043535
| 20 | 17 | 2,940 | 2,940 |
Accepted
|
Accepted
| 15 |
s = eval(input())
cnt = 0
if s[0] == "A" and s[2:-1].count("C") == 1:
for i in range(len(s)):
if ord(s[i])<=90:
cnt += 1
if cnt != 2:
print("WA")
quit()
else:
print("AC")
else:
print("WA")
|
s = eval(input())
cnt = 0
if s[0] == "A" and s[2:-1].count("C") == 1:
for i in range(len(s)):
if ord(s[i])<=90:
cnt += 1
if cnt != 2:
print("WA")
else:
print("AC")
else:
print("WA")
| 13 | 12 | 255 | 239 |
s = eval(input())
cnt = 0
if s[0] == "A" and s[2:-1].count("C") == 1:
for i in range(len(s)):
if ord(s[i]) <= 90:
cnt += 1
if cnt != 2:
print("WA")
quit()
else:
print("AC")
else:
print("WA")
|
s = eval(input())
cnt = 0
if s[0] == "A" and s[2:-1].count("C") == 1:
for i in range(len(s)):
if ord(s[i]) <= 90:
cnt += 1
if cnt != 2:
print("WA")
else:
print("AC")
else:
print("WA")
| false | 7.692308 |
[
"- quit()"
] | false | 0.059999 | 0.063728 | 0.941479 |
[
"s308309198",
"s906043535"
] |
u670180528
|
p02863
|
python
|
s993260617
|
s003421564
| 293 | 252 | 42,860 | 40,176 |
Accepted
|
Accepted
| 13.99 |
_, t, *L = list(map(int, open(0).read().split()))
d = [0] * (t + max(L[::2]))
for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
for i in range(t + w - 1, w - 1, -1):
if d[i - w] + v > d[i]:
d[i] = d[i - w] + v
print((max(d)))
|
def main():
_, t, *L = list(map(int, open(0).read().split()))
d = [0] * (t + max(L[::2]))
for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
for i in range(t + w - 1, w - 1, -1):
if d[i - w] + v > d[i]:
d[i] = d[i - w] + v
print((max(d)))
if __name__=="__main__":
main()
#vs after contest
| 7 | 13 | 240 | 317 |
_, t, *L = list(map(int, open(0).read().split()))
d = [0] * (t + max(L[::2]))
for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
for i in range(t + w - 1, w - 1, -1):
if d[i - w] + v > d[i]:
d[i] = d[i - w] + v
print((max(d)))
|
def main():
_, t, *L = list(map(int, open(0).read().split()))
d = [0] * (t + max(L[::2]))
for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
for i in range(t + w - 1, w - 1, -1):
if d[i - w] + v > d[i]:
d[i] = d[i - w] + v
print((max(d)))
if __name__ == "__main__":
main()
# vs after contest
| false | 46.153846 |
[
"-_, t, *L = list(map(int, open(0).read().split()))",
"-d = [0] * (t + max(L[::2]))",
"-for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):",
"- for i in range(t + w - 1, w - 1, -1):",
"- if d[i - w] + v > d[i]:",
"- d[i] = d[i - w] + v",
"-print((max(d)))",
"+def main():",
"+ _, t, *L = list(map(int, open(0).read().split()))",
"+ d = [0] * (t + max(L[::2]))",
"+ for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):",
"+ for i in range(t + w - 1, w - 1, -1):",
"+ if d[i - w] + v > d[i]:",
"+ d[i] = d[i - w] + v",
"+ print((max(d)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()",
"+# vs after contest"
] | false | 0.037429 | 0.075423 | 0.496259 |
[
"s993260617",
"s003421564"
] |
u740284863
|
p02819
|
python
|
s757596413
|
s639818197
| 1,161 | 31 | 7,192 | 2,940 |
Accepted
|
Accepted
| 97.33 |
import math
import bisect
def eratosthenes(limit):
A = [i for i in range(2, limit+1)]
P = []
time = 0
while True:
prime = min(A)
if prime > math.sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return P
n = int(eval(input()))
P = eratosthenes(100100)
insert_index = bisect.bisect_left(P,n)
print((P[insert_index]))
|
n = int(eval(input()))
while True:
Flag = True
for i in range(2,n):
if n % i == 0:
Flag = False
break
if Flag:
print(n)
exit()
n += 1
| 30 | 11 | 622 | 201 |
import math
import bisect
def eratosthenes(limit):
A = [i for i in range(2, limit + 1)]
P = []
time = 0
while True:
prime = min(A)
if prime > math.sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return P
n = int(eval(input()))
P = eratosthenes(100100)
insert_index = bisect.bisect_left(P, n)
print((P[insert_index]))
|
n = int(eval(input()))
while True:
Flag = True
for i in range(2, n):
if n % i == 0:
Flag = False
break
if Flag:
print(n)
exit()
n += 1
| false | 63.333333 |
[
"-import math",
"-import bisect",
"-",
"-",
"-def eratosthenes(limit):",
"- A = [i for i in range(2, limit + 1)]",
"- P = []",
"- time = 0",
"- while True:",
"- prime = min(A)",
"- if prime > math.sqrt(limit):",
"+n = int(eval(input()))",
"+while True:",
"+ Flag = True",
"+ for i in range(2, n):",
"+ if n % i == 0:",
"+ Flag = False",
"- P.append(prime)",
"- i = 0",
"- while i < len(A):",
"- if A[i] % prime == 0:",
"- A.pop(i)",
"- continue",
"- i += 1",
"- for a in A:",
"- P.append(a)",
"- return P",
"-",
"-",
"-n = int(eval(input()))",
"-P = eratosthenes(100100)",
"-insert_index = bisect.bisect_left(P, n)",
"-print((P[insert_index]))",
"+ if Flag:",
"+ print(n)",
"+ exit()",
"+ n += 1"
] | false | 1.221624 | 0.031727 | 38.504723 |
[
"s757596413",
"s639818197"
] |
u997641430
|
p02971
|
python
|
s199614172
|
s054926657
| 634 | 526 | 15,660 | 14,176 |
Accepted
|
Accepted
| 17.03 |
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
l = 0
L = [l]
for a in A:
l = max(l, a)
L.append(l)
r = 0
R = [r]
for a in A[::-1]:
r = max(r, a)
R.append(r)
R.reverse()
for i in range(n):
print((max(L[i], R[i+1])))
|
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
A_ = sorted(A, reverse=True)
a0, a1 = A_[0], A_[1]
for a in A:
if a == a0:
print(a1)
else:
print(a0)
| 18 | 9 | 260 | 187 |
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
l = 0
L = [l]
for a in A:
l = max(l, a)
L.append(l)
r = 0
R = [r]
for a in A[::-1]:
r = max(r, a)
R.append(r)
R.reverse()
for i in range(n):
print((max(L[i], R[i + 1])))
|
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
A_ = sorted(A, reverse=True)
a0, a1 = A_[0], A_[1]
for a in A:
if a == a0:
print(a1)
else:
print(a0)
| false | 50 |
[
"-l = 0",
"-L = [l]",
"+A_ = sorted(A, reverse=True)",
"+a0, a1 = A_[0], A_[1]",
"- l = max(l, a)",
"- L.append(l)",
"-r = 0",
"-R = [r]",
"-for a in A[::-1]:",
"- r = max(r, a)",
"- R.append(r)",
"-R.reverse()",
"-for i in range(n):",
"- print((max(L[i], R[i + 1])))",
"+ if a == a0:",
"+ print(a1)",
"+ else:",
"+ print(a0)"
] | false | 0.049981 | 0.06171 | 0.809923 |
[
"s199614172",
"s054926657"
] |
u969850098
|
p03137
|
python
|
s200937333
|
s809614641
| 109 | 100 | 13,960 | 13,964 |
Accepted
|
Accepted
| 8.26 |
import sys
readline = sys.stdin.readline
def main():
N, M = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
if N >= M:
print((0))
return
X.sort()
X = [abs(X[i+1]-X[i]) for i in range(M-1)]
X.sort()
ans = sum(X)
for i in range(N-1):
ans -= X[-i-1]
print(ans)
if __name__ == '__main__':
main()
|
import sys
readline = sys.stdin.readline
def main():
N, M = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
if N >= M:
print((0))
return
X.sort()
X = [abs(X[i+1]-X[i]) for i in range(M-1)]
X.sort(reverse=True)
print((sum(X[N-1:])))
if __name__ == '__main__':
main()
| 23 | 19 | 423 | 370 |
import sys
readline = sys.stdin.readline
def main():
N, M = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
if N >= M:
print((0))
return
X.sort()
X = [abs(X[i + 1] - X[i]) for i in range(M - 1)]
X.sort()
ans = sum(X)
for i in range(N - 1):
ans -= X[-i - 1]
print(ans)
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.readline
def main():
N, M = list(map(int, readline().rstrip().split()))
X = list(map(int, readline().rstrip().split()))
if N >= M:
print((0))
return
X.sort()
X = [abs(X[i + 1] - X[i]) for i in range(M - 1)]
X.sort(reverse=True)
print((sum(X[N - 1 :])))
if __name__ == "__main__":
main()
| false | 17.391304 |
[
"- X.sort()",
"- ans = sum(X)",
"- for i in range(N - 1):",
"- ans -= X[-i - 1]",
"- print(ans)",
"+ X.sort(reverse=True)",
"+ print((sum(X[N - 1 :])))"
] | false | 0.033051 | 0.03208 | 1.030249 |
[
"s200937333",
"s809614641"
] |
u893063840
|
p03700
|
python
|
s848283532
|
s756997784
| 1,533 | 1,391 | 7,120 | 7,192 |
Accepted
|
Accepted
| 9.26 |
from math import ceil
n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(n)]
def f(x):
cnt = 0
for e in h:
cnt += max(0, ceil((e - b * x) / (a - b)))
if cnt > x:
return False
return True
l = 0
r = 10 ** 9 + 1
while r - l > 1:
mid = (l + r) // 2
if f(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 f(x):
cnt = 0
for e in h:
cnt += max(0, ceil((e - b * x) / (a - b)))
if cnt > x:
return False
return True
l = 0
r = ceil(max(h) / b)
while r - l > 1:
mid = (l + r) // 2
if f(mid):
r = mid
else:
l = mid
print(r)
| 27 | 27 | 399 | 404 |
from math import ceil
n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(n)]
def f(x):
cnt = 0
for e in h:
cnt += max(0, ceil((e - b * x) / (a - b)))
if cnt > x:
return False
return True
l = 0
r = 10**9 + 1
while r - l > 1:
mid = (l + r) // 2
if f(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 f(x):
cnt = 0
for e in h:
cnt += max(0, ceil((e - b * x) / (a - b)))
if cnt > x:
return False
return True
l = 0
r = ceil(max(h) / b)
while r - l > 1:
mid = (l + r) // 2
if f(mid):
r = mid
else:
l = mid
print(r)
| false | 0 |
[
"-r = 10**9 + 1",
"+r = ceil(max(h) / b)"
] | false | 0.11945 | 0.061501 | 1.942235 |
[
"s848283532",
"s756997784"
] |
u968166680
|
p03632
|
python
|
s467343855
|
s732982519
| 29 | 24 | 9,028 | 9,124 |
Accepted
|
Accepted
| 17.24 |
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():
A, B, C, D = list(map(int, readline().split()))
if B < C or D < A:
ans = 0
elif C > A:
if D < B:
ans = D - C
else:
ans = B - C
else:
if D < B:
ans = D - A
else:
ans = B - A
print(ans)
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():
A, B, C, D = list(map(int, readline().split()))
lower = max(A, C)
upper = min(B, D)
ans = max(upper - lower, 0)
print(ans)
return
if __name__ == '__main__':
main()
| 32 | 23 | 542 | 384 |
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():
A, B, C, D = list(map(int, readline().split()))
if B < C or D < A:
ans = 0
elif C > A:
if D < B:
ans = D - C
else:
ans = B - C
else:
if D < B:
ans = D - A
else:
ans = B - A
print(ans)
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():
A, B, C, D = list(map(int, readline().split()))
lower = max(A, C)
upper = min(B, D)
ans = max(upper - lower, 0)
print(ans)
return
if __name__ == "__main__":
main()
| false | 28.125 |
[
"- if B < C or D < A:",
"- ans = 0",
"- elif C > A:",
"- if D < B:",
"- ans = D - C",
"- else:",
"- ans = B - C",
"- else:",
"- if D < B:",
"- ans = D - A",
"- else:",
"- ans = B - A",
"+ lower = max(A, C)",
"+ upper = min(B, D)",
"+ ans = max(upper - lower, 0)"
] | false | 0.042751 | 0.041025 | 1.042074 |
[
"s467343855",
"s732982519"
] |
u367130284
|
p03053
|
python
|
s150066229
|
s423118401
| 716 | 647 | 130,908 | 130,908 |
Accepted
|
Accepted
| 9.64 |
def main():
from collections import deque
import sys;input=sys.stdin.readline
h,w=list(map(int,input().split()))
grid=[["#"]*(w+2)]+[list("#"+eval(input())+"#")for x in range(h)]+[["#"]*(w+2)]
stack=deque()
for y in range(1,h+1):
for x in range(1,w+1):
if grid[y][x]=="#":
#grid[y][x]=0
stack.append((y,x))
for i in range(h*w):
tmp=deque()
while stack:
my,mx=stack.pop()
for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
if grid[my+y][mx+x]==".":
#grid[my+y][mx+x]=i+1
grid[my+y][mx+x]="#"
tmp.append([my+y,mx+x])
stack=tmp
if not tmp:
print(i)
break
if __name__ == '__main__':
main()
|
import functools
@functools.lru_cache(maxsize=None)
def main():
from collections import deque
import sys;input=sys.stdin.readline
h,w=list(map(int,input().split()))
grid=[["#"]*(w+2)]+[list("#"+eval(input())+"#")for x in range(h)]+[["#"]*(w+2)]
stack=deque()
for y in range(1,h+1):
for x in range(1,w+1):
if grid[y][x]=="#":
#grid[y][x]=0
stack.append((y,x))
for i in range(h*w):
tmp=deque()
while stack:
my,mx=stack.pop()
for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
if grid[my+y][mx+x]==".":
#grid[my+y][mx+x]=i+1
grid[my+y][mx+x]="#"
tmp.append([my+y,mx+x])
stack=tmp
if not tmp:
print(i)
break
if __name__ == '__main__':
main()
| 29 | 33 | 833 | 892 |
def main():
from collections import deque
import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
grid = (
[["#"] * (w + 2)]
+ [list("#" + eval(input()) + "#") for x in range(h)]
+ [["#"] * (w + 2)]
)
stack = deque()
for y in range(1, h + 1):
for x in range(1, w + 1):
if grid[y][x] == "#":
# grid[y][x]=0
stack.append((y, x))
for i in range(h * w):
tmp = deque()
while stack:
my, mx = stack.pop()
for y, x in ([0, 1], [1, 0], [-1, 0], [0, -1]):
if grid[my + y][mx + x] == ".":
# grid[my+y][mx+x]=i+1
grid[my + y][mx + x] = "#"
tmp.append([my + y, mx + x])
stack = tmp
if not tmp:
print(i)
break
if __name__ == "__main__":
main()
|
import functools
@functools.lru_cache(maxsize=None)
def main():
from collections import deque
import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
grid = (
[["#"] * (w + 2)]
+ [list("#" + eval(input()) + "#") for x in range(h)]
+ [["#"] * (w + 2)]
)
stack = deque()
for y in range(1, h + 1):
for x in range(1, w + 1):
if grid[y][x] == "#":
# grid[y][x]=0
stack.append((y, x))
for i in range(h * w):
tmp = deque()
while stack:
my, mx = stack.pop()
for y, x in ([0, 1], [1, 0], [-1, 0], [0, -1]):
if grid[my + y][mx + x] == ".":
# grid[my+y][mx+x]=i+1
grid[my + y][mx + x] = "#"
tmp.append([my + y, mx + x])
stack = tmp
if not tmp:
print(i)
break
if __name__ == "__main__":
main()
| false | 12.121212 |
[
"+import functools",
"+",
"+",
"[email protected]_cache(maxsize=None)"
] | false | 0.115236 | 0.188046 | 0.612807 |
[
"s150066229",
"s423118401"
] |
u359358631
|
p02951
|
python
|
s603691089
|
s830023342
| 73 | 67 | 61,652 | 61,848 |
Accepted
|
Accepted
| 8.22 |
def main():
A, B, C = list(map(int, input().split()))
ans = C - (A - B)
print((max(ans, 0)))
if __name__ == "__main__":
main()
|
def main():
A, B, C = list(map(int, input().split()))
t = min(A - B, C)
ans = C - t
print(ans)
if __name__ == "__main__":
main()
| 10 | 11 | 148 | 157 |
def main():
A, B, C = list(map(int, input().split()))
ans = C - (A - B)
print((max(ans, 0)))
if __name__ == "__main__":
main()
|
def main():
A, B, C = list(map(int, input().split()))
t = min(A - B, C)
ans = C - t
print(ans)
if __name__ == "__main__":
main()
| false | 9.090909 |
[
"- ans = C - (A - B)",
"- print((max(ans, 0)))",
"+ t = min(A - B, C)",
"+ ans = C - t",
"+ print(ans)"
] | false | 0.048652 | 0.048575 | 1.001592 |
[
"s603691089",
"s830023342"
] |
u228232845
|
p02954
|
python
|
s625098610
|
s905538681
| 139 | 97 | 18,828 | 10,900 |
Accepted
|
Accepted
| 30.22 |
from collections import defaultdict
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
def LS(): return input().split()
INF = float('inf')
s = S()
n = len(s)
d = defaultdict(lambda: [0, 0]) # RL の位置 に対応する r, l の数の辞書
# 右から見ていって対応する r を探す
r = 0
i = 0
while i < n:
if s[i:i + 2] == 'RL':
d[i][0] = r
r = 0
i += 2
elif s[i] == 'R':
r += 1
i += 1
else:
i += 1
l = 0
i = 0
s = s[::-1]
while i < n:
if s[i:i + 2] == 'LR':
d[n - i - 2][1] = l
l = 0
i += 2
elif s[i] == 'L':
l += 1
i += 1
else:
i += 1
ans = [0] * n
for k, v in list(d.items()):
r, l = v
ans[k] += 1
ans[k + 1] += 1
if r % 2 == 0:
ans[k] += r // 2
ans[k + 1] += r // 2
else:
ans[k] += r // 2
ans[k + 1] += r // 2 + 1
if l % 2 == 0:
ans[k] += l // 2
ans[k + 1] += l // 2
else:
ans[k] += l // 2 + 1
ans[k + 1] += l // 2
print((*ans))
|
# ランレングス圧縮の考え方で解く
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
def LS(): return input().split()
INF = float('inf')
# 初期位置が R の人が最終的にどこに向かうかを考える
# 折り返し地点(移動中に訪れる初めての L) までの距離 d と操作回数の偶奇で決まる(今回の操作回数は偶数)
# d が奇数のとき 折り返し地点の 1 つ左側
# d が偶数のとき 折り返し地点
# L も同様に考える
# 連続する R と L をそれぞれグループ化することで折り返し地点を管理しやすくなる
# ランレングス圧縮と同じ
s = S()
n = len(s)
ans = [0] * n
# 初期位置が R の人について
# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算
r_cnt = 0
for i in range(n):
if s[i] == 'R':
r_cnt += 1
else: # 折り返し地点に来たら計算
even_num = r_cnt // 2
odd_num = r_cnt - even_num
ans[i] += even_num # 折り返し地点の人数
ans[i - 1] += odd_num # 折り返し地点の 1 つ左の人数
r_cnt = 0
# 初期位置が L の人について
# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算
l_cnt = 0
for i in range(n - 1, -1, -1): # 右側から見ていく
if s[i] == 'L':
l_cnt += 1
else: # 折り返し地点に来たら計算
even_num = l_cnt // 2
odd_num = l_cnt - even_num
ans[i] += even_num # 折り返し地点の人数
ans[i + 1] += odd_num # 折り返し地点の 1 つ左の人数
l_cnt = 0
print((*ans))
| 68 | 55 | 1,310 | 1,339 |
from collections import defaultdict
import sys
def input():
return sys.stdin.readline().strip()
def I():
return int(eval(input()))
def LI():
return list(map(int, input().split()))
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def S():
return eval(input())
def LS():
return input().split()
INF = float("inf")
s = S()
n = len(s)
d = defaultdict(lambda: [0, 0]) # RL の位置 に対応する r, l の数の辞書
# 右から見ていって対応する r を探す
r = 0
i = 0
while i < n:
if s[i : i + 2] == "RL":
d[i][0] = r
r = 0
i += 2
elif s[i] == "R":
r += 1
i += 1
else:
i += 1
l = 0
i = 0
s = s[::-1]
while i < n:
if s[i : i + 2] == "LR":
d[n - i - 2][1] = l
l = 0
i += 2
elif s[i] == "L":
l += 1
i += 1
else:
i += 1
ans = [0] * n
for k, v in list(d.items()):
r, l = v
ans[k] += 1
ans[k + 1] += 1
if r % 2 == 0:
ans[k] += r // 2
ans[k + 1] += r // 2
else:
ans[k] += r // 2
ans[k + 1] += r // 2 + 1
if l % 2 == 0:
ans[k] += l // 2
ans[k + 1] += l // 2
else:
ans[k] += l // 2 + 1
ans[k + 1] += l // 2
print((*ans))
|
# ランレングス圧縮の考え方で解く
import sys
def input():
return sys.stdin.readline().strip()
def I():
return int(eval(input()))
def LI():
return list(map(int, input().split()))
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def S():
return eval(input())
def LS():
return input().split()
INF = float("inf")
# 初期位置が R の人が最終的にどこに向かうかを考える
# 折り返し地点(移動中に訪れる初めての L) までの距離 d と操作回数の偶奇で決まる(今回の操作回数は偶数)
# d が奇数のとき 折り返し地点の 1 つ左側
# d が偶数のとき 折り返し地点
# L も同様に考える
# 連続する R と L をそれぞれグループ化することで折り返し地点を管理しやすくなる
# ランレングス圧縮と同じ
s = S()
n = len(s)
ans = [0] * n
# 初期位置が R の人について
# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算
r_cnt = 0
for i in range(n):
if s[i] == "R":
r_cnt += 1
else: # 折り返し地点に来たら計算
even_num = r_cnt // 2
odd_num = r_cnt - even_num
ans[i] += even_num # 折り返し地点の人数
ans[i - 1] += odd_num # 折り返し地点の 1 つ左の人数
r_cnt = 0
# 初期位置が L の人について
# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算
l_cnt = 0
for i in range(n - 1, -1, -1): # 右側から見ていく
if s[i] == "L":
l_cnt += 1
else: # 折り返し地点に来たら計算
even_num = l_cnt // 2
odd_num = l_cnt - even_num
ans[i] += even_num # 折り返し地点の人数
ans[i + 1] += odd_num # 折り返し地点の 1 つ左の人数
l_cnt = 0
print((*ans))
| false | 19.117647 |
[
"-from collections import defaultdict",
"+# ランレングス圧縮の考え方で解く",
"+# 初期位置が R の人が最終的にどこに向かうかを考える",
"+# 折り返し地点(移動中に訪れる初めての L) までの距離 d と操作回数の偶奇で決まる(今回の操作回数は偶数)",
"+# d が奇数のとき 折り返し地点の 1 つ左側",
"+# d が偶数のとき 折り返し地点",
"+# L も同様に考える",
"+# 連続する R と L をそれぞれグループ化することで折り返し地点を管理しやすくなる",
"+# ランレングス圧縮と同じ",
"-d = defaultdict(lambda: [0, 0]) # RL の位置 に対応する r, l の数の辞書",
"-# 右から見ていって対応する r を探す",
"-r = 0",
"-i = 0",
"-while i < n:",
"- if s[i : i + 2] == \"RL\":",
"- d[i][0] = r",
"- r = 0",
"- i += 2",
"- elif s[i] == \"R\":",
"- r += 1",
"- i += 1",
"- else:",
"- i += 1",
"-l = 0",
"-i = 0",
"-s = s[::-1]",
"-while i < n:",
"- if s[i : i + 2] == \"LR\":",
"- d[n - i - 2][1] = l",
"- l = 0",
"- i += 2",
"- elif s[i] == \"L\":",
"- l += 1",
"- i += 1",
"- else:",
"- i += 1",
"-for k, v in list(d.items()):",
"- r, l = v",
"- ans[k] += 1",
"- ans[k + 1] += 1",
"- if r % 2 == 0:",
"- ans[k] += r // 2",
"- ans[k + 1] += r // 2",
"- else:",
"- ans[k] += r // 2",
"- ans[k + 1] += r // 2 + 1",
"- if l % 2 == 0:",
"- ans[k] += l // 2",
"- ans[k + 1] += l // 2",
"- else:",
"- ans[k] += l // 2 + 1",
"- ans[k + 1] += l // 2",
"+# 初期位置が R の人について",
"+# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算",
"+r_cnt = 0",
"+for i in range(n):",
"+ if s[i] == \"R\":",
"+ r_cnt += 1",
"+ else: # 折り返し地点に来たら計算",
"+ even_num = r_cnt // 2",
"+ odd_num = r_cnt - even_num",
"+ ans[i] += even_num # 折り返し地点の人数",
"+ ans[i - 1] += odd_num # 折り返し地点の 1 つ左の人数",
"+ r_cnt = 0",
"+# 初期位置が L の人について",
"+# まとまりの人数、 その中で d が偶数の人の数、 d が奇数の人の数 を計算",
"+l_cnt = 0",
"+for i in range(n - 1, -1, -1): # 右側から見ていく",
"+ if s[i] == \"L\":",
"+ l_cnt += 1",
"+ else: # 折り返し地点に来たら計算",
"+ even_num = l_cnt // 2",
"+ odd_num = l_cnt - even_num",
"+ ans[i] += even_num # 折り返し地点の人数",
"+ ans[i + 1] += odd_num # 折り返し地点の 1 つ左の人数",
"+ l_cnt = 0"
] | false | 0.059386 | 0.080678 | 0.736089 |
[
"s625098610",
"s905538681"
] |
u532966492
|
p03987
|
python
|
s687013582
|
s735887753
| 1,127 | 452 | 47,448 | 46,840 |
Accepted
|
Accepted
| 59.89 |
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(list(enumerate(a)), key=lambda x: -x[1])
class unionfind():
# size:要素数,tree:unionfind木
def __init__(self, size): # self,要素数
self.size = size
self.tree = [i for i in range(self.size)] # root,depth
# rootを探す
def root(self, index):
temp_list = []
temp = self.tree[index]
while index != temp:
temp_list.append(index)
index = temp
temp = self.tree[index]
for i in temp_list:
self.tree[i] = index
return index
# 結合
def unite_r(self, index1, index2):
r1 = self.root(index1)
r2 = self.root(index2)
if r1 < r2:
self.tree[r1] = r2
else:
self.tree[r2] = r1
def unite_l(self, index1, index2):
r1 = self.root(index1)
r2 = self.root(index2)
if r1 > r2:
self.tree[r1] = r2
else:
self.tree[r2] = r1
# 同じか判定
def same(self, index1, index2):
r1 = self.root(index1)
r2 = self.root(index2)
return r1 == r2
ur = unionfind(n+2)
ul = unionfind(n+2)
vis = [False]*(n+2)
ans = 0
for i, j in a:
vis[i+1] = True
if vis[i+2]:
ur.unite_r(i+1, i+2)
ul.unite_l(i+1, i+2)
if vis[i]:
ur.unite_r(i, i+1)
ul.unite_l(i, i+1)
ans += j*(ur.root(i+1)-i)*(i+2-ul.root(i+1))
print(ans)
main()
|
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(list(enumerate(a)), key=lambda x: -x[1])
L = [i for i in range(n+2)] # 連結成分のうち一番左のindex
R = [i for i in range(n+2)] # 連結成分のうち一番右のindex
ans = 0
for i, j in a: # 1-indexなので1ずれる
M = R[i+1] # 連結成分の最大値
m = L[i+1] # 連結成分の最小値
ans += j*(M-i)*(i+2-m) # 計算
R[m-1] = M # 連結成分の左端の更新
L[M+1] = m # 連結成分の右端の更新
print(ans)
main()
| 63 | 17 | 1,735 | 486 |
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(list(enumerate(a)), key=lambda x: -x[1])
class unionfind:
# size:要素数,tree:unionfind木
def __init__(self, size): # self,要素数
self.size = size
self.tree = [i for i in range(self.size)] # root,depth
# rootを探す
def root(self, index):
temp_list = []
temp = self.tree[index]
while index != temp:
temp_list.append(index)
index = temp
temp = self.tree[index]
for i in temp_list:
self.tree[i] = index
return index
# 結合
def unite_r(self, index1, index2):
r1 = self.root(index1)
r2 = self.root(index2)
if r1 < r2:
self.tree[r1] = r2
else:
self.tree[r2] = r1
def unite_l(self, index1, index2):
r1 = self.root(index1)
r2 = self.root(index2)
if r1 > r2:
self.tree[r1] = r2
else:
self.tree[r2] = r1
# 同じか判定
def same(self, index1, index2):
r1 = self.root(index1)
r2 = self.root(index2)
return r1 == r2
ur = unionfind(n + 2)
ul = unionfind(n + 2)
vis = [False] * (n + 2)
ans = 0
for i, j in a:
vis[i + 1] = True
if vis[i + 2]:
ur.unite_r(i + 1, i + 2)
ul.unite_l(i + 1, i + 2)
if vis[i]:
ur.unite_r(i, i + 1)
ul.unite_l(i, i + 1)
ans += j * (ur.root(i + 1) - i) * (i + 2 - ul.root(i + 1))
print(ans)
main()
|
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(list(enumerate(a)), key=lambda x: -x[1])
L = [i for i in range(n + 2)] # 連結成分のうち一番左のindex
R = [i for i in range(n + 2)] # 連結成分のうち一番右のindex
ans = 0
for i, j in a: # 1-indexなので1ずれる
M = R[i + 1] # 連結成分の最大値
m = L[i + 1] # 連結成分の最小値
ans += j * (M - i) * (i + 2 - m) # 計算
R[m - 1] = M # 連結成分の左端の更新
L[M + 1] = m # 連結成分の右端の更新
print(ans)
main()
| false | 73.015873 |
[
"-",
"- class unionfind:",
"- # size:要素数,tree:unionfind木",
"- def __init__(self, size): # self,要素数",
"- self.size = size",
"- self.tree = [i for i in range(self.size)] # root,depth",
"-",
"- # rootを探す",
"- def root(self, index):",
"- temp_list = []",
"- temp = self.tree[index]",
"- while index != temp:",
"- temp_list.append(index)",
"- index = temp",
"- temp = self.tree[index]",
"- for i in temp_list:",
"- self.tree[i] = index",
"- return index",
"-",
"- # 結合",
"- def unite_r(self, index1, index2):",
"- r1 = self.root(index1)",
"- r2 = self.root(index2)",
"- if r1 < r2:",
"- self.tree[r1] = r2",
"- else:",
"- self.tree[r2] = r1",
"-",
"- def unite_l(self, index1, index2):",
"- r1 = self.root(index1)",
"- r2 = self.root(index2)",
"- if r1 > r2:",
"- self.tree[r1] = r2",
"- else:",
"- self.tree[r2] = r1",
"-",
"- # 同じか判定",
"- def same(self, index1, index2):",
"- r1 = self.root(index1)",
"- r2 = self.root(index2)",
"- return r1 == r2",
"-",
"- ur = unionfind(n + 2)",
"- ul = unionfind(n + 2)",
"- vis = [False] * (n + 2)",
"+ L = [i for i in range(n + 2)] # 連結成分のうち一番左のindex",
"+ R = [i for i in range(n + 2)] # 連結成分のうち一番右のindex",
"- for i, j in a:",
"- vis[i + 1] = True",
"- if vis[i + 2]:",
"- ur.unite_r(i + 1, i + 2)",
"- ul.unite_l(i + 1, i + 2)",
"- if vis[i]:",
"- ur.unite_r(i, i + 1)",
"- ul.unite_l(i, i + 1)",
"- ans += j * (ur.root(i + 1) - i) * (i + 2 - ul.root(i + 1))",
"+ for i, j in a: # 1-indexなので1ずれる",
"+ M = R[i + 1] # 連結成分の最大値",
"+ m = L[i + 1] # 連結成分の最小値",
"+ ans += j * (M - i) * (i + 2 - m) # 計算",
"+ R[m - 1] = M # 連結成分の左端の更新",
"+ L[M + 1] = m # 連結成分の右端の更新"
] | false | 0.196844 | 0.097329 | 2.022462 |
[
"s687013582",
"s735887753"
] |
u352394527
|
p02320
|
python
|
s189690551
|
s030508165
| 4,700 | 2,180 | 5,988 | 5,988 |
Accepted
|
Accepted
| 53.62 |
def main():
n, w = list(map(int, input().split()))
value = []
weight = []
num = []
for _ in range(n):
vi, wi, ni = list(map(int, input().split()))
value.append(vi)
weight.append(wi)
num.append(ni)
def to_digit(x):
acc = 1
ret = [0]
while x >= acc:
ret.append(acc)
x -= acc
acc *= 2
if x:
ret.append(x)
return ret
num = list(map(to_digit, num))
dp = [0 for _ in range(w + 1)]
for i in range(n):
vi = value[i]
wi = weight[i]
numsi = num[i]
for k in numsi:
wik = wi * k
vik = vi * k
for j in range(w, wik - 1, -1):
dp[j] = max(dp[j], dp[j - wik] + vik)
print((dp[w]))
main()
|
def main():
n, w = list(map(int, input().split()))
value = []
weight = []
num = []
for _ in range(n):
vi, wi, ni = list(map(int, input().split()))
value.append(vi)
weight.append(wi)
num.append(ni)
def summary(x):
acc = 1
ret = [0]
while x >= acc:
ret.append(acc)
x -= acc
acc *= 2
if x:
ret.append(x)
return ret
num = list(map(summary, num))
dp = [0 for _ in range(w + 1)]
for i in range(n):
vi = value[i]
wi = weight[i]
numsi = num[i]
for k in numsi:
wik = wi * k
vik = vi * k
for j in range(w, wik - 1, -1):
pre = dp[j - wik] + vik
if dp[j] < pre:
dp[j] = pre
print((dp[w]))
main()
| 40 | 42 | 738 | 770 |
def main():
n, w = list(map(int, input().split()))
value = []
weight = []
num = []
for _ in range(n):
vi, wi, ni = list(map(int, input().split()))
value.append(vi)
weight.append(wi)
num.append(ni)
def to_digit(x):
acc = 1
ret = [0]
while x >= acc:
ret.append(acc)
x -= acc
acc *= 2
if x:
ret.append(x)
return ret
num = list(map(to_digit, num))
dp = [0 for _ in range(w + 1)]
for i in range(n):
vi = value[i]
wi = weight[i]
numsi = num[i]
for k in numsi:
wik = wi * k
vik = vi * k
for j in range(w, wik - 1, -1):
dp[j] = max(dp[j], dp[j - wik] + vik)
print((dp[w]))
main()
|
def main():
n, w = list(map(int, input().split()))
value = []
weight = []
num = []
for _ in range(n):
vi, wi, ni = list(map(int, input().split()))
value.append(vi)
weight.append(wi)
num.append(ni)
def summary(x):
acc = 1
ret = [0]
while x >= acc:
ret.append(acc)
x -= acc
acc *= 2
if x:
ret.append(x)
return ret
num = list(map(summary, num))
dp = [0 for _ in range(w + 1)]
for i in range(n):
vi = value[i]
wi = weight[i]
numsi = num[i]
for k in numsi:
wik = wi * k
vik = vi * k
for j in range(w, wik - 1, -1):
pre = dp[j - wik] + vik
if dp[j] < pre:
dp[j] = pre
print((dp[w]))
main()
| false | 4.761905 |
[
"- def to_digit(x):",
"+ def summary(x):",
"- num = list(map(to_digit, num))",
"+ num = list(map(summary, num))",
"- dp[j] = max(dp[j], dp[j - wik] + vik)",
"+ pre = dp[j - wik] + vik",
"+ if dp[j] < pre:",
"+ dp[j] = pre"
] | false | 0.235836 | 0.034653 | 6.805606 |
[
"s189690551",
"s030508165"
] |
u888092736
|
p03262
|
python
|
s929649469
|
s543592719
| 105 | 92 | 16,280 | 13,040 |
Accepted
|
Accepted
| 12.38 |
from fractions import gcd
N, X = list(map(int, input().split()))
X = [X] + list(map(int, input().split()))
ans = 0
for i in range(N):
ans = gcd(ans, abs(X[i + 1] - X[i]))
print(ans)
|
from fractions import gcd
from functools import reduce
_, X = list(map(int, input().split()))
print((reduce(gcd, (abs(X - i) for i in map(int, input().split())))))
| 9 | 5 | 190 | 161 |
from fractions import gcd
N, X = list(map(int, input().split()))
X = [X] + list(map(int, input().split()))
ans = 0
for i in range(N):
ans = gcd(ans, abs(X[i + 1] - X[i]))
print(ans)
|
from fractions import gcd
from functools import reduce
_, X = list(map(int, input().split()))
print((reduce(gcd, (abs(X - i) for i in map(int, input().split())))))
| false | 44.444444 |
[
"+from functools import reduce",
"-N, X = list(map(int, input().split()))",
"-X = [X] + list(map(int, input().split()))",
"-ans = 0",
"-for i in range(N):",
"- ans = gcd(ans, abs(X[i + 1] - X[i]))",
"-print(ans)",
"+_, X = list(map(int, input().split()))",
"+print((reduce(gcd, (abs(X - i) for i in map(int, input().split())))))"
] | false | 0.057923 | 0.059865 | 0.96756 |
[
"s929649469",
"s543592719"
] |
u159228113
|
p02924
|
python
|
s795051100
|
s189356218
| 168 | 17 | 38,256 | 2,940 |
Accepted
|
Accepted
| 89.88 |
n = int(eval(input()))
print((int(n*(n-1)//2)))
|
n = int(eval(input()))
print((n*(n-1)//2))
| 2 | 2 | 41 | 35 |
n = int(eval(input()))
print((int(n * (n - 1) // 2)))
|
n = int(eval(input()))
print((n * (n - 1) // 2))
| false | 0 |
[
"-print((int(n * (n - 1) // 2)))",
"+print((n * (n - 1) // 2))"
] | false | 0.066501 | 0.037226 | 1.786406 |
[
"s795051100",
"s189356218"
] |
u500297289
|
p03806
|
python
|
s043871741
|
s936332644
| 731 | 662 | 136,412 | 142,812 |
Accepted
|
Accepted
| 9.44 |
N, Ma, Mb = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]
inf = float('inf')
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for j in range(401):
for k in range(401):
dp[i + 1][j][k] = dp[i][j][k]
if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2])
ans = inf
for a in range(1, 401):
for b in range(1, 401):
if a * Mb == b * Ma:
ans = min(ans, dp[N][a][b])
if ans == inf:
ans = -1
print(ans)
|
N, Ma, Mb = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]
inf = float('inf')
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for j in range(401):
for k in range(401):
if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2])
else:
dp[i + 1][j][k] = dp[i][j][k]
ans = inf
for a in range(1, 401):
if a % Ma == 0:
b = a // Ma * Mb
if b <= 401:
ans = min(ans, dp[N][a][b])
if ans == inf:
ans = -1
print(ans)
| 22 | 24 | 665 | 694 |
N, Ma, Mb = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]
inf = float("inf")
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for j in range(401):
for k in range(401):
dp[i + 1][j][k] = dp[i][j][k]
if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
dp[i + 1][j][k] = min(
dp[i + 1][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2]
)
ans = inf
for a in range(1, 401):
for b in range(1, 401):
if a * Mb == b * Ma:
ans = min(ans, dp[N][a][b])
if ans == inf:
ans = -1
print(ans)
|
N, Ma, Mb = list(map(int, input().split()))
abc = [list(map(int, input().split())) for _ in range(N)]
inf = float("inf")
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for j in range(401):
for k in range(401):
if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
dp[i + 1][j][k] = min(
dp[i][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2]
)
else:
dp[i + 1][j][k] = dp[i][j][k]
ans = inf
for a in range(1, 401):
if a % Ma == 0:
b = a // Ma * Mb
if b <= 401:
ans = min(ans, dp[N][a][b])
if ans == inf:
ans = -1
print(ans)
| false | 8.333333 |
[
"- dp[i + 1][j][k] = dp[i][j][k]",
"- dp[i + 1][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2]",
"+ dp[i][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2]",
"+ else:",
"+ dp[i + 1][j][k] = dp[i][j][k]",
"- for b in range(1, 401):",
"- if a * Mb == b * Ma:",
"+ if a % Ma == 0:",
"+ b = a // Ma * Mb",
"+ if b <= 401:"
] | false | 0.906839 | 0.7534 | 1.203663 |
[
"s043871741",
"s936332644"
] |
u761320129
|
p03201
|
python
|
s311239761
|
s153511901
| 964 | 809 | 70,436 | 56,056 |
Accepted
|
Accepted
| 16.08 |
from collections import Counter
N = int(eval(input()))
A = list(map(int,input().split()))
ctr = Counter(A)
lctr = sorted(list(ctr.items()),reverse=True)
ans = 0
for k,_ in lctr:
beki = 2**(len(bin(k))-2)
a = beki-k
if a == k:
ans += ctr[k]//2
else:
tmp = min(ctr[k], ctr[a])
ans += tmp
ctr[a] -= tmp
print(ans)
|
from collections import Counter
N = int(eval(input()))
A = list(map(int,input().split()))
ctr = Counter(A)
sa = sorted(list(ctr.keys()),reverse=True)
ans = 0
for a in sa:
p = 2**(len(bin(a))-2)
rem = p - a
if a == rem:
v = ctr[a] // 2
else:
v = min(ctr[a], ctr[rem])
ans += v
ctr[a] -= v
ctr[rem] -= v
print(ans)
| 18 | 18 | 371 | 362 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
ctr = Counter(A)
lctr = sorted(list(ctr.items()), reverse=True)
ans = 0
for k, _ in lctr:
beki = 2 ** (len(bin(k)) - 2)
a = beki - k
if a == k:
ans += ctr[k] // 2
else:
tmp = min(ctr[k], ctr[a])
ans += tmp
ctr[a] -= tmp
print(ans)
|
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
ctr = Counter(A)
sa = sorted(list(ctr.keys()), reverse=True)
ans = 0
for a in sa:
p = 2 ** (len(bin(a)) - 2)
rem = p - a
if a == rem:
v = ctr[a] // 2
else:
v = min(ctr[a], ctr[rem])
ans += v
ctr[a] -= v
ctr[rem] -= v
print(ans)
| false | 0 |
[
"-lctr = sorted(list(ctr.items()), reverse=True)",
"+sa = sorted(list(ctr.keys()), reverse=True)",
"-for k, _ in lctr:",
"- beki = 2 ** (len(bin(k)) - 2)",
"- a = beki - k",
"- if a == k:",
"- ans += ctr[k] // 2",
"+for a in sa:",
"+ p = 2 ** (len(bin(a)) - 2)",
"+ rem = p - a",
"+ if a == rem:",
"+ v = ctr[a] // 2",
"- tmp = min(ctr[k], ctr[a])",
"- ans += tmp",
"- ctr[a] -= tmp",
"+ v = min(ctr[a], ctr[rem])",
"+ ans += v",
"+ ctr[a] -= v",
"+ ctr[rem] -= v"
] | false | 0.036278 | 0.03753 | 0.966649 |
[
"s311239761",
"s153511901"
] |
u581187895
|
p02866
|
python
|
s141869915
|
s970261786
| 143 | 123 | 24,404 | 20,572 |
Accepted
|
Accepted
| 13.99 |
from collections import Counter
def resolve():
MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
print((0))
return
CNT = Counter(D)
if CNT[0] > 1: # 距離0は1個
print((0))
return
ans = 1
for i in range(1, max(D) + 1):
ans *= pow(CNT[i - 1], CNT[i], MOD)
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
|
def resolve():
MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
print((0))
return
CNT = [0] * N
for i in D:
CNT[i] += 1
if CNT[0] > 1:
print((0))
return
ans = 1
for i in range(1, N):
ans *= pow(CNT[i - 1], CNT[i], MOD)
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
| 26 | 28 | 458 | 443 |
from collections import Counter
def resolve():
MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
print((0))
return
CNT = Counter(D)
if CNT[0] > 1: # 距離0は1個
print((0))
return
ans = 1
for i in range(1, max(D) + 1):
ans *= pow(CNT[i - 1], CNT[i], MOD)
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
|
def resolve():
MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
print((0))
return
CNT = [0] * N
for i in D:
CNT[i] += 1
if CNT[0] > 1:
print((0))
return
ans = 1
for i in range(1, N):
ans *= pow(CNT[i - 1], CNT[i], MOD)
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
| false | 7.142857 |
[
"-from collections import Counter",
"-",
"-",
"- CNT = Counter(D)",
"- if CNT[0] > 1: # 距離0は1個",
"+ CNT = [0] * N",
"+ for i in D:",
"+ CNT[i] += 1",
"+ if CNT[0] > 1:",
"- for i in range(1, max(D) + 1):",
"+ for i in range(1, N):"
] | false | 0.037993 | 0.041086 | 0.924729 |
[
"s141869915",
"s970261786"
] |
u860002137
|
p03031
|
python
|
s192865342
|
s784449424
| 166 | 44 | 12,504 | 9,448 |
Accepted
|
Accepted
| 73.49 |
import numpy as np
from itertools import product
N, M = list(map(int, input().split()))
switch = []
for i in range(M):
switch.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
st = list(product([0,1],repeat=N))
ans = 0
for i, s in enumerate(st):
tmp = []
for j, sw in enumerate(switch):
on = 0
for x in sw:
on += s[x-1]
if (on%2)==p[j]:
tmp.append(True)
else:
tmp.append(False)
if all(tmp)==True:
ans += 1
print(ans)
|
from collections import defaultdict
n, m = list(map(int, input().split()))
s = defaultdict(list)
for i in range(1, m + 1):
_, *x = list(map(int, input().split()))
for j in x:
s[j].append(i)
p = list(map(int, input().split()))
ans = []
for i in range(2**n):
tmp = [0] * len(p)
for j in range(n):
if ((i >> j) & 1):
for k in s[j + 1]:
tmp[k - 1] += 1
if all([x % 2 == y for x, y in zip(tmp, p)]):
ans.append(True)
else:
ans.append(False)
print((sum(ans)))
| 29 | 26 | 567 | 554 |
import numpy as np
from itertools import product
N, M = list(map(int, input().split()))
switch = []
for i in range(M):
switch.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
st = list(product([0, 1], repeat=N))
ans = 0
for i, s in enumerate(st):
tmp = []
for j, sw in enumerate(switch):
on = 0
for x in sw:
on += s[x - 1]
if (on % 2) == p[j]:
tmp.append(True)
else:
tmp.append(False)
if all(tmp) == True:
ans += 1
print(ans)
|
from collections import defaultdict
n, m = list(map(int, input().split()))
s = defaultdict(list)
for i in range(1, m + 1):
_, *x = list(map(int, input().split()))
for j in x:
s[j].append(i)
p = list(map(int, input().split()))
ans = []
for i in range(2**n):
tmp = [0] * len(p)
for j in range(n):
if (i >> j) & 1:
for k in s[j + 1]:
tmp[k - 1] += 1
if all([x % 2 == y for x, y in zip(tmp, p)]):
ans.append(True)
else:
ans.append(False)
print((sum(ans)))
| false | 10.344828 |
[
"-import numpy as np",
"-from itertools import product",
"+from collections import defaultdict",
"-N, M = list(map(int, input().split()))",
"-switch = []",
"-for i in range(M):",
"- switch.append(list(map(int, input().split()))[1:])",
"+n, m = list(map(int, input().split()))",
"+s = defaultdict(list)",
"+for i in range(1, m + 1):",
"+ _, *x = list(map(int, input().split()))",
"+ for j in x:",
"+ s[j].append(i)",
"-st = list(product([0, 1], repeat=N))",
"-ans = 0",
"-for i, s in enumerate(st):",
"- tmp = []",
"- for j, sw in enumerate(switch):",
"- on = 0",
"- for x in sw:",
"- on += s[x - 1]",
"- if (on % 2) == p[j]:",
"- tmp.append(True)",
"- else:",
"- tmp.append(False)",
"- if all(tmp) == True:",
"- ans += 1",
"-print(ans)",
"+ans = []",
"+for i in range(2**n):",
"+ tmp = [0] * len(p)",
"+ for j in range(n):",
"+ if (i >> j) & 1:",
"+ for k in s[j + 1]:",
"+ tmp[k - 1] += 1",
"+ if all([x % 2 == y for x, y in zip(tmp, p)]):",
"+ ans.append(True)",
"+ else:",
"+ ans.append(False)",
"+print((sum(ans)))"
] | false | 0.068987 | 0.04385 | 1.57326 |
[
"s192865342",
"s784449424"
] |
u989074104
|
p03449
|
python
|
s938636546
|
s117480500
| 148 | 17 | 12,428 | 3,060 |
Accepted
|
Accepted
| 88.51 |
import numpy as np
N=int(eval(input()))
num_list=[]
while True:
try:
num_list.append(list(map(int,input().split())))
except:
break;
sum_list=[]
for k in range(N):
sum_list.append(sum(num_list[0][0:k+1])+sum(num_list[1][k:N+1]))
print((max(sum_list)))
|
N=int(eval(input()))
num_list=[]
while True:
try:
num_list.append(list(map(int,input().split())))
except:
break;
sum_list=[]
for k in range(N):
sum_list.append(sum(num_list[0][0:k+1])+sum(num_list[1][k:N+1]))
print((max(sum_list)))
| 16 | 13 | 297 | 273 |
import numpy as np
N = int(eval(input()))
num_list = []
while True:
try:
num_list.append(list(map(int, input().split())))
except:
break
sum_list = []
for k in range(N):
sum_list.append(sum(num_list[0][0 : k + 1]) + sum(num_list[1][k : N + 1]))
print((max(sum_list)))
|
N = int(eval(input()))
num_list = []
while True:
try:
num_list.append(list(map(int, input().split())))
except:
break
sum_list = []
for k in range(N):
sum_list.append(sum(num_list[0][0 : k + 1]) + sum(num_list[1][k : N + 1]))
print((max(sum_list)))
| false | 18.75 |
[
"-import numpy as np",
"-"
] | false | 0.061255 | 0.036828 | 1.663278 |
[
"s938636546",
"s117480500"
] |
u677523557
|
p03488
|
python
|
s875286100
|
s585703493
| 829 | 305 | 172,168 | 43,996 |
Accepted
|
Accepted
| 63.21 |
import sys
input = sys.stdin.readline
def main():
S = list(eval(input()))
X, Y = list(map(int, input().split()))
Xs = []
Ys = []
line = True
first = True
x0, y0 = 0, 0
a = 0
for s in S:
if s == 'F':
a += 1
else:
if first:
if a > 0:
x0 = a
a = 0
first = False
line = False
continue
if a > 0:
if line:
Xs.append(a)
else:
Ys.append(a)
a = 0
if line:
line = False
else:
line = True
if a > 0:
if line:
Xs.append(a)
else:
Ys.append(a)
Lx = sum(Xs)+x0
dpx = [[False for _ in range(2*Lx+1)] for _ in range(len(Xs)+1)]
dpx[0][x0+Lx] = True
for i, x in enumerate(Xs):
for j in range(2*Lx+1):
if j+x <= 2*Lx:
dpx[i+1][j+x] = dpx[i][j] or dpx[i+1][j+x]
if j-x >= 0:
dpx[i+1][j-x] = dpx[i][j] or dpx[i+1][j-x]
Ly = sum(Ys)+y0
dpy = [[False for _ in range(2*Ly+1)] for _ in range(len(Ys)+1)]
dpy[0][y0+Ly] = True
for i, y in enumerate(Ys):
for j in range(2*Ly+1):
if j+y <= 2*Ly:
dpy[i+1][j+y] = dpy[i][j] or dpy[i+1][j+y]
if j-y >= 0:
dpy[i+1][j-y] = dpy[i][j] or dpy[i+1][j-y]
#print(Lx, Ly)
if (not -Lx <= X <= Lx) or (not -Ly <= Y <= Ly):
print('No')
elif dpx[-1][X+Lx] and dpy[-1][Y+Ly]:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
S = input().rstrip()
gx, gy = list(map(int, input().split()))
L = len(S)
XY = [[], []]
d = 0
c = 0
begin = True
for s in S:
if begin and s == "F":
gx -= 1
elif s == 'T':
begin = False
if c > 0:
XY[d].append(c)
d ^= 1
c = 0
else:
c += 1
if c > 0:
XY[d].append(c)
XY[0].append(abs(gx))
XY[1].append(abs(gy))
ans = True
for X in XY:
G = sum(X)
if G%2 != 0:
ans = False
break
G //= 2
ok = False
W = len(X)
dp = [False]*(G+1)
dp[0] = True
for i, x in enumerate(X):
for g in reversed(list(range(G+1))):
if g >= x:
dp[g] = dp[g-x] or dp[g]
if dp[G]:
ok = True
break
ans = ok and ans
print(("Yes" if ans else "No"))
| 72 | 48 | 1,791 | 878 |
import sys
input = sys.stdin.readline
def main():
S = list(eval(input()))
X, Y = list(map(int, input().split()))
Xs = []
Ys = []
line = True
first = True
x0, y0 = 0, 0
a = 0
for s in S:
if s == "F":
a += 1
else:
if first:
if a > 0:
x0 = a
a = 0
first = False
line = False
continue
if a > 0:
if line:
Xs.append(a)
else:
Ys.append(a)
a = 0
if line:
line = False
else:
line = True
if a > 0:
if line:
Xs.append(a)
else:
Ys.append(a)
Lx = sum(Xs) + x0
dpx = [[False for _ in range(2 * Lx + 1)] for _ in range(len(Xs) + 1)]
dpx[0][x0 + Lx] = True
for i, x in enumerate(Xs):
for j in range(2 * Lx + 1):
if j + x <= 2 * Lx:
dpx[i + 1][j + x] = dpx[i][j] or dpx[i + 1][j + x]
if j - x >= 0:
dpx[i + 1][j - x] = dpx[i][j] or dpx[i + 1][j - x]
Ly = sum(Ys) + y0
dpy = [[False for _ in range(2 * Ly + 1)] for _ in range(len(Ys) + 1)]
dpy[0][y0 + Ly] = True
for i, y in enumerate(Ys):
for j in range(2 * Ly + 1):
if j + y <= 2 * Ly:
dpy[i + 1][j + y] = dpy[i][j] or dpy[i + 1][j + y]
if j - y >= 0:
dpy[i + 1][j - y] = dpy[i][j] or dpy[i + 1][j - y]
# print(Lx, Ly)
if (not -Lx <= X <= Lx) or (not -Ly <= Y <= Ly):
print("No")
elif dpx[-1][X + Lx] and dpy[-1][Y + Ly]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.readline
S = input().rstrip()
gx, gy = list(map(int, input().split()))
L = len(S)
XY = [[], []]
d = 0
c = 0
begin = True
for s in S:
if begin and s == "F":
gx -= 1
elif s == "T":
begin = False
if c > 0:
XY[d].append(c)
d ^= 1
c = 0
else:
c += 1
if c > 0:
XY[d].append(c)
XY[0].append(abs(gx))
XY[1].append(abs(gy))
ans = True
for X in XY:
G = sum(X)
if G % 2 != 0:
ans = False
break
G //= 2
ok = False
W = len(X)
dp = [False] * (G + 1)
dp[0] = True
for i, x in enumerate(X):
for g in reversed(list(range(G + 1))):
if g >= x:
dp[g] = dp[g - x] or dp[g]
if dp[G]:
ok = True
break
ans = ok and ans
print(("Yes" if ans else "No"))
| false | 33.333333 |
[
"-",
"-",
"-def main():",
"- S = list(eval(input()))",
"- X, Y = list(map(int, input().split()))",
"- Xs = []",
"- Ys = []",
"- line = True",
"- first = True",
"- x0, y0 = 0, 0",
"- a = 0",
"- for s in S:",
"- if s == \"F\":",
"- a += 1",
"- else:",
"- if first:",
"- if a > 0:",
"- x0 = a",
"- a = 0",
"- first = False",
"- line = False",
"- continue",
"- if a > 0:",
"- if line:",
"- Xs.append(a)",
"- else:",
"- Ys.append(a)",
"- a = 0",
"- if line:",
"- line = False",
"- else:",
"- line = True",
"- if a > 0:",
"- if line:",
"- Xs.append(a)",
"- else:",
"- Ys.append(a)",
"- Lx = sum(Xs) + x0",
"- dpx = [[False for _ in range(2 * Lx + 1)] for _ in range(len(Xs) + 1)]",
"- dpx[0][x0 + Lx] = True",
"- for i, x in enumerate(Xs):",
"- for j in range(2 * Lx + 1):",
"- if j + x <= 2 * Lx:",
"- dpx[i + 1][j + x] = dpx[i][j] or dpx[i + 1][j + x]",
"- if j - x >= 0:",
"- dpx[i + 1][j - x] = dpx[i][j] or dpx[i + 1][j - x]",
"- Ly = sum(Ys) + y0",
"- dpy = [[False for _ in range(2 * Ly + 1)] for _ in range(len(Ys) + 1)]",
"- dpy[0][y0 + Ly] = True",
"- for i, y in enumerate(Ys):",
"- for j in range(2 * Ly + 1):",
"- if j + y <= 2 * Ly:",
"- dpy[i + 1][j + y] = dpy[i][j] or dpy[i + 1][j + y]",
"- if j - y >= 0:",
"- dpy[i + 1][j - y] = dpy[i][j] or dpy[i + 1][j - y]",
"- # print(Lx, Ly)",
"- if (not -Lx <= X <= Lx) or (not -Ly <= Y <= Ly):",
"- print(\"No\")",
"- elif dpx[-1][X + Lx] and dpy[-1][Y + Ly]:",
"- print(\"Yes\")",
"+S = input().rstrip()",
"+gx, gy = list(map(int, input().split()))",
"+L = len(S)",
"+XY = [[], []]",
"+d = 0",
"+c = 0",
"+begin = True",
"+for s in S:",
"+ if begin and s == \"F\":",
"+ gx -= 1",
"+ elif s == \"T\":",
"+ begin = False",
"+ if c > 0:",
"+ XY[d].append(c)",
"+ d ^= 1",
"+ c = 0",
"- print(\"No\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ c += 1",
"+if c > 0:",
"+ XY[d].append(c)",
"+XY[0].append(abs(gx))",
"+XY[1].append(abs(gy))",
"+ans = True",
"+for X in XY:",
"+ G = sum(X)",
"+ if G % 2 != 0:",
"+ ans = False",
"+ break",
"+ G //= 2",
"+ ok = False",
"+ W = len(X)",
"+ dp = [False] * (G + 1)",
"+ dp[0] = True",
"+ for i, x in enumerate(X):",
"+ for g in reversed(list(range(G + 1))):",
"+ if g >= x:",
"+ dp[g] = dp[g - x] or dp[g]",
"+ if dp[G]:",
"+ ok = True",
"+ break",
"+ ans = ok and ans",
"+print((\"Yes\" if ans else \"No\"))"
] | false | 0.040573 | 0.045762 | 0.88661 |
[
"s875286100",
"s585703493"
] |
u072053884
|
p02243
|
python
|
s792407378
|
s524921283
| 960 | 430 | 70,532 | 70,488 |
Accepted
|
Accepted
| 55.21 |
import sys
f_i = sys.stdin
n = int(f_i.readline())
adj = [[(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])] for x in f_i]
import heapq
def dijkstra():
PQ = [(0, 0)]
distance = [999900001] * n
distance[0] = 0
while PQ:
uc = heapq.heappop(PQ)
u = uc[1]
for vc in adj[u]:
v = vc[1]
t_cost = distance[u] + vc[0]
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, (t_cost, v))
for v, d in enumerate(distance):
print((v, d))
dijkstra()
|
import sys
f_i = sys.stdin
n = int(f_i.readline())
adj = [[]] * n
for x in f_i:
x = list(map(int, x.split()))
adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]
import heapq
def dijkstra():
PQ = [(0, 0)]
isVisited = [False] * n
distance = [999900001] * n
distance[0] = 0
while PQ:
uc = heapq.heappop(PQ)
u = uc[1]
if uc[0] > distance[u]:
continue
isVisited[u] = True
for vc in adj[u]:
v = vc[1]
if isVisited[v] == True:
continue
t_cost = distance[u] + vc[0]
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, (t_cost, v))
for v, d in enumerate(distance):
print((v, d))
dijkstra()
| 32 | 43 | 644 | 846 |
import sys
f_i = sys.stdin
n = int(f_i.readline())
adj = [
[(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])]
for x in f_i
]
import heapq
def dijkstra():
PQ = [(0, 0)]
distance = [999900001] * n
distance[0] = 0
while PQ:
uc = heapq.heappop(PQ)
u = uc[1]
for vc in adj[u]:
v = vc[1]
t_cost = distance[u] + vc[0]
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, (t_cost, v))
for v, d in enumerate(distance):
print((v, d))
dijkstra()
|
import sys
f_i = sys.stdin
n = int(f_i.readline())
adj = [[]] * n
for x in f_i:
x = list(map(int, x.split()))
adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]
import heapq
def dijkstra():
PQ = [(0, 0)]
isVisited = [False] * n
distance = [999900001] * n
distance[0] = 0
while PQ:
uc = heapq.heappop(PQ)
u = uc[1]
if uc[0] > distance[u]:
continue
isVisited[u] = True
for vc in adj[u]:
v = vc[1]
if isVisited[v] == True:
continue
t_cost = distance[u] + vc[0]
if t_cost < distance[v]:
distance[v] = t_cost
heapq.heappush(PQ, (t_cost, v))
for v, d in enumerate(distance):
print((v, d))
dijkstra()
| false | 25.581395 |
[
"-adj = [",
"- [(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])]",
"- for x in f_i",
"-]",
"+adj = [[]] * n",
"+for x in f_i:",
"+ x = list(map(int, x.split()))",
"+ adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]",
"+ isVisited = [False] * n",
"+ if uc[0] > distance[u]:",
"+ continue",
"+ isVisited[u] = True",
"+ if isVisited[v] == True:",
"+ continue"
] | false | 0.046563 | 0.070039 | 0.664817 |
[
"s792407378",
"s524921283"
] |
u340781749
|
p02930
|
python
|
s744701582
|
s484553509
| 93 | 78 | 3,952 | 3,952 |
Accepted
|
Accepted
| 16.13 |
n = int(eval(input()))
for i in range(n):
print((*((i ^ j & -(i ^ j)).bit_length() for j in range(i + 1, n))))
|
n = int(eval(input()))
for i in range(n):
print((*((i ^ j).bit_length() for j in range(i + 1, n))))
| 3 | 3 | 109 | 98 |
n = int(eval(input()))
for i in range(n):
print((*((i ^ j & -(i ^ j)).bit_length() for j in range(i + 1, n))))
|
n = int(eval(input()))
for i in range(n):
print((*((i ^ j).bit_length() for j in range(i + 1, n))))
| false | 0 |
[
"- print((*((i ^ j & -(i ^ j)).bit_length() for j in range(i + 1, n))))",
"+ print((*((i ^ j).bit_length() for j in range(i + 1, n))))"
] | false | 0.037044 | 0.037398 | 0.990528 |
[
"s744701582",
"s484553509"
] |
u275685840
|
p03456
|
python
|
s900328320
|
s053884790
| 28 | 23 | 9,412 | 9,236 |
Accepted
|
Accepted
| 17.86 |
a, b = list(map(int,input().split()))
ab = int(str(a) + str(b))
abroot = str(ab**0.5)
if abroot.split(".")[1:][0] == "0":
print("Yes")
else:
print("No")
|
a, b = list(map(int,input().split()))
if str(int(str(a) + str(b))**0.5).split(".")[1:][0] == "0":
print("Yes")
else:
print("No")
| 7 | 5 | 160 | 134 |
a, b = list(map(int, input().split()))
ab = int(str(a) + str(b))
abroot = str(ab**0.5)
if abroot.split(".")[1:][0] == "0":
print("Yes")
else:
print("No")
|
a, b = list(map(int, input().split()))
if str(int(str(a) + str(b)) ** 0.5).split(".")[1:][0] == "0":
print("Yes")
else:
print("No")
| false | 28.571429 |
[
"-ab = int(str(a) + str(b))",
"-abroot = str(ab**0.5)",
"-if abroot.split(\".\")[1:][0] == \"0\":",
"+if str(int(str(a) + str(b)) ** 0.5).split(\".\")[1:][0] == \"0\":"
] | false | 0.109392 | 0.048207 | 2.269209 |
[
"s900328320",
"s053884790"
] |
u508732591
|
p02257
|
python
|
s248629750
|
s927049014
| 70 | 60 | 7,744 | 7,792 |
Accepted
|
Accepted
| 14.29 |
def maybe_prime(d,s,n):
for a in (2,3,5,7):
p = False
x = pow(a,d,n)
if x==1 or x==n-1:
continue
for i in range(1,s):
x = x*x%n
if x==1: return False
elif x == n-1:
p = True
break
if not p: return False
return True
def is_prime(n):
if n in (2,3,5,7): return True
elif 0 in (n%2,n%3,n%5,n%7): return False
elif 0 in [ n%i for i in range(11,min(n-1,50),2) ]:return False
else:
d,s = n-1, 0
while not d%2:
d,s = d>>1,s+1
return maybe_prime(d,s,n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n): cnt+=1
print(cnt)
|
def maybe_prime(d,s,n):
for a in (2,3,5,7):
p = False
x = pow(a,d,n)
if x==1 or x==n-1:
continue
for i in range(1,s):
x = x*x%n
if x==1: return False
elif x == n-1:
p = True
break
if not p: return False
return True
def is_prime(n):
if n in (2,3,5,7): return True
elif 0 in (n%2,n%3,n%5,n%7): return False
elif 0 in [ n%i for i in range(11,min(n-1,30),2) ]:return False
else:
d,s = n-1, 0
while not d%2:
d,s = d>>1,s+1
return maybe_prime(d,s,n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n): cnt+=1
print(cnt)
| 31 | 31 | 754 | 754 |
def maybe_prime(d, s, n):
for a in (2, 3, 5, 7):
p = False
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for i in range(1, s):
x = x * x % n
if x == 1:
return False
elif x == n - 1:
p = True
break
if not p:
return False
return True
def is_prime(n):
if n in (2, 3, 5, 7):
return True
elif 0 in (n % 2, n % 3, n % 5, n % 7):
return False
elif 0 in [n % i for i in range(11, min(n - 1, 50), 2)]:
return False
else:
d, s = n - 1, 0
while not d % 2:
d, s = d >> 1, s + 1
return maybe_prime(d, s, n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n):
cnt += 1
print(cnt)
|
def maybe_prime(d, s, n):
for a in (2, 3, 5, 7):
p = False
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for i in range(1, s):
x = x * x % n
if x == 1:
return False
elif x == n - 1:
p = True
break
if not p:
return False
return True
def is_prime(n):
if n in (2, 3, 5, 7):
return True
elif 0 in (n % 2, n % 3, n % 5, n % 7):
return False
elif 0 in [n % i for i in range(11, min(n - 1, 30), 2)]:
return False
else:
d, s = n - 1, 0
while not d % 2:
d, s = d >> 1, s + 1
return maybe_prime(d, s, n)
cnt = 0
n = int(eval(input()))
for i in range(n):
n = int(eval(input()))
if is_prime(n):
cnt += 1
print(cnt)
| false | 0 |
[
"- elif 0 in [n % i for i in range(11, min(n - 1, 50), 2)]:",
"+ elif 0 in [n % i for i in range(11, min(n - 1, 30), 2)]:"
] | false | 0.048934 | 0.049131 | 0.995993 |
[
"s248629750",
"s927049014"
] |
u858748695
|
p02861
|
python
|
s384452688
|
s365725143
| 280 | 101 | 13,848 | 9,128 |
Accepted
|
Accepted
| 63.93 |
from itertools import permutations
def dfs(p, bit):
res = 0
for k in range(n):
if bit >> k & 1:
continue
d = ((x[k] - x[p]) ** 2 + (y[k] - y[p]) ** 2) ** 0.5
res += d + dfs(k, bit | (1 << k))
return res
n = int(eval(input()))
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
ans = 0
# for i in range(n):
# ans += dfs(i, 1 << i)
# for i in range(n):
# ans /= i + 1
for li in list(permutations(list(range(n)), n)):
tmp = 0
for i in range(n - 1):
p = li[i]
k = li[i + 1]
tmp += ((x[k] - x[p]) ** 2 + (y[k] - y[p]) ** 2) ** 0.5
ans += tmp
for i in range(n):
ans /= i + 1
print(ans)
|
from math import hypot, factorial
def dfs(d, p):
if all(used):
return d
res = 0
for i in range(n):
if used[i]:
continue
used[i] = True
res += dfs(d + hypot(x[i] - x[p], y[i] - y[p]), i)
used[i] = False
return res
n = int(eval(input()))
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
ans = 0
used = [False] * n
for i in range(n):
used[i] = True
ans += dfs(0, i)
used[i] = False
ans /= factorial(n)
print(ans)
| 35 | 31 | 739 | 557 |
from itertools import permutations
def dfs(p, bit):
res = 0
for k in range(n):
if bit >> k & 1:
continue
d = ((x[k] - x[p]) ** 2 + (y[k] - y[p]) ** 2) ** 0.5
res += d + dfs(k, bit | (1 << k))
return res
n = int(eval(input()))
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
ans = 0
# for i in range(n):
# ans += dfs(i, 1 << i)
# for i in range(n):
# ans /= i + 1
for li in list(permutations(list(range(n)), n)):
tmp = 0
for i in range(n - 1):
p = li[i]
k = li[i + 1]
tmp += ((x[k] - x[p]) ** 2 + (y[k] - y[p]) ** 2) ** 0.5
ans += tmp
for i in range(n):
ans /= i + 1
print(ans)
|
from math import hypot, factorial
def dfs(d, p):
if all(used):
return d
res = 0
for i in range(n):
if used[i]:
continue
used[i] = True
res += dfs(d + hypot(x[i] - x[p], y[i] - y[p]), i)
used[i] = False
return res
n = int(eval(input()))
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
ans = 0
used = [False] * n
for i in range(n):
used[i] = True
ans += dfs(0, i)
used[i] = False
ans /= factorial(n)
print(ans)
| false | 11.428571 |
[
"-from itertools import permutations",
"+from math import hypot, factorial",
"-def dfs(p, bit):",
"+def dfs(d, p):",
"+ if all(used):",
"+ return d",
"- for k in range(n):",
"- if bit >> k & 1:",
"+ for i in range(n):",
"+ if used[i]:",
"- d = ((x[k] - x[p]) ** 2 + (y[k] - y[p]) ** 2) ** 0.5",
"- res += d + dfs(k, bit | (1 << k))",
"+ used[i] = True",
"+ res += dfs(d + hypot(x[i] - x[p], y[i] - y[p]), i)",
"+ used[i] = False",
"-# for i in range(n):",
"-# ans += dfs(i, 1 << i)",
"-# for i in range(n):",
"-# ans /= i + 1",
"-for li in list(permutations(list(range(n)), n)):",
"- tmp = 0",
"- for i in range(n - 1):",
"- p = li[i]",
"- k = li[i + 1]",
"- tmp += ((x[k] - x[p]) ** 2 + (y[k] - y[p]) ** 2) ** 0.5",
"- ans += tmp",
"+used = [False] * n",
"- ans /= i + 1",
"+ used[i] = True",
"+ ans += dfs(0, i)",
"+ used[i] = False",
"+ans /= factorial(n)"
] | false | 0.041423 | 0.04246 | 0.975595 |
[
"s384452688",
"s365725143"
] |
u540761833
|
p03112
|
python
|
s039990211
|
s227714163
| 1,213 | 1,070 | 80,092 | 76,764 |
Accepted
|
Accepted
| 11.79 |
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
x = int(eval(input()))
cand = []
for i in range(2):
st = stlist[i]
cand1 = set()
l1 = bisect.bisect_left(st,x)
r1 = bisect.bisect_right(st,x)
if 0 <= l1 <= ab[i]-1:
cand1.add(st[l1])
if 0 <= l1-1 <= ab[i]-1:
cand1.add(st[l1-1])
cand.append(cand1)
ans = float('inf')
for a,b in product(cand[0],cand[1]):
c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
ans = min(ans,c)
print(ans)
|
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
x = int(eval(input()))
cand = []
for i in range(2):
st = stlist[i]
cand1 = set()
l1 = bisect.bisect_left(st,x)
if 0 <= l1 <= ab[i]-1:
cand1.add(st[l1])
if 0 <= l1-1 <= ab[i]-1:
cand1.add(st[l1-1])
cand.append(cand1)
ans = float('inf')
for a,b in product(cand[0],cand[1]):
c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
ans = min(ans,c)
print(ans)
| 31 | 29 | 807 | 757 |
import sys
import bisect
from itertools import product
def input():
return sys.stdin.readline().strip()
A, B, Q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s, t]
ab = [A, B]
for i in range(Q):
x = int(eval(input()))
cand = []
for i in range(2):
st = stlist[i]
cand1 = set()
l1 = bisect.bisect_left(st, x)
r1 = bisect.bisect_right(st, x)
if 0 <= l1 <= ab[i] - 1:
cand1.add(st[l1])
if 0 <= l1 - 1 <= ab[i] - 1:
cand1.add(st[l1 - 1])
cand.append(cand1)
ans = float("inf")
for a, b in product(cand[0], cand[1]):
c = min(abs(x - a) + abs(b - a), abs(x - b) + abs(b - a))
ans = min(ans, c)
print(ans)
|
import sys
import bisect
from itertools import product
def input():
return sys.stdin.readline().strip()
A, B, Q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s, t]
ab = [A, B]
for i in range(Q):
x = int(eval(input()))
cand = []
for i in range(2):
st = stlist[i]
cand1 = set()
l1 = bisect.bisect_left(st, x)
if 0 <= l1 <= ab[i] - 1:
cand1.add(st[l1])
if 0 <= l1 - 1 <= ab[i] - 1:
cand1.add(st[l1 - 1])
cand.append(cand1)
ans = float("inf")
for a, b in product(cand[0], cand[1]):
c = min(abs(x - a) + abs(b - a), abs(x - b) + abs(b - a))
ans = min(ans, c)
print(ans)
| false | 6.451613 |
[
"- r1 = bisect.bisect_right(st, x)"
] | false | 0.032523 | 0.036794 | 0.883922 |
[
"s039990211",
"s227714163"
] |
u145231176
|
p02973
|
python
|
s799162268
|
s775753701
| 447 | 202 | 82,444 | 89,500 |
Accepted
|
Accepted
| 54.81 |
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 998244353
#############
# Main Code #
#############
N = getN()
A = getArray(N)
ans = deque([A[0]])
for i in range(1, N):
index = bisect_left(ans, A[i])
if index == 0:
ans.appendleft(A[i])
else:
ans[index - 1] = A[i]
print((len(ans)))
|
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
A = getArray(N)
def lis(A):
L = deque([A[0]])
for a in A[1:]:
# Lのどの数より小さくければ
# 繋げられるものがない
if a <= L[0]:
L.appendleft(a)
else:
# L[bisect_left(L, a) - 1]
# Lの中のa未満の数字のうちの最大値
L[bisect_left(L, a) - 1] = a
return len(L)
print((lis(A)))
| 65 | 70 | 1,528 | 1,661 |
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 998244353
#############
# Main Code #
#############
N = getN()
A = getArray(N)
ans = deque([A[0]])
for i in range(1, N):
index = bisect_left(ans, A[i])
if index == 0:
ans.appendleft(A[i])
else:
ans[index - 1] = A[i]
print((len(ans)))
|
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(eval(input())) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N = getN()
A = getArray(N)
def lis(A):
L = deque([A[0]])
for a in A[1:]:
# Lのどの数より小さくければ
# 繋げられるものがない
if a <= L[0]:
L.appendleft(a)
else:
# L[bisect_left(L, a) - 1]
# Lの中のa未満の数字のうちの最大値
L[bisect_left(L, a) - 1] = a
return len(L)
print((lis(A)))
| false | 7.142857 |
[
"-mod = 998244353",
"+mod = 10**9 + 7",
"-ans = deque([A[0]])",
"-for i in range(1, N):",
"- index = bisect_left(ans, A[i])",
"- if index == 0:",
"- ans.appendleft(A[i])",
"- else:",
"- ans[index - 1] = A[i]",
"-print((len(ans)))",
"+",
"+",
"+def lis(A):",
"+ L = deque([A[0]])",
"+ for a in A[1:]:",
"+ # Lのどの数より小さくければ",
"+ # 繋げられるものがない",
"+ if a <= L[0]:",
"+ L.appendleft(a)",
"+ else:",
"+ # L[bisect_left(L, a) - 1]",
"+ # Lの中のa未満の数字のうちの最大値",
"+ L[bisect_left(L, a) - 1] = a",
"+ return len(L)",
"+",
"+",
"+print((lis(A)))"
] | false | 0.044627 | 0.062483 | 0.714218 |
[
"s799162268",
"s775753701"
] |
u753803401
|
p02714
|
python
|
s579421725
|
s356475475
| 1,596 | 180 | 69,636 | 68,060 |
Accepted
|
Accepted
| 88.72 |
import sys
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
s = str(readline().rstrip().decode('utf-8'))
c = collections.Counter(list(s))
left = collections.defaultdict(int)
cnt = 0
for i in range(n - 2):
left[s[i]] += 1
mid = collections.defaultdict(int)
for k, v in list(left.items()):
mid[k] += v
for j in range(i + 1, n - 1):
mid[s[j]] += 1
if s[i] != s[j]:
if [s[i], s[j]].count("R") == 0:
cnt += c["R"] - mid["R"]
if j + j - i < n:
if s[j+j-i] == "R":
cnt -= 1
elif [s[i], s[j]].count("G") == 0:
cnt += c["G"] - mid["G"]
if j + j - i < n:
if s[j+j-i] == "G":
cnt -= 1
elif [s[i], s[j]].count("B") == 0:
cnt += c["B"] - mid["B"]
if j + j - i < n:
if s[j+j-i] == "B":
cnt -= 1
print(cnt)
if __name__ == '__main__':
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
s = str(readline().rstrip().decode('utf-8'))
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt = r * g * b
for i in range(n - 2):
for j in range(i + 1, n - 1):
k = j + j - i
if k < n:
if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
cnt -= 1
print(cnt)
if __name__ == '__main__':
solve()
| 40 | 23 | 1,254 | 532 |
import sys
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
n = int(readline())
s = str(readline().rstrip().decode("utf-8"))
c = collections.Counter(list(s))
left = collections.defaultdict(int)
cnt = 0
for i in range(n - 2):
left[s[i]] += 1
mid = collections.defaultdict(int)
for k, v in list(left.items()):
mid[k] += v
for j in range(i + 1, n - 1):
mid[s[j]] += 1
if s[i] != s[j]:
if [s[i], s[j]].count("R") == 0:
cnt += c["R"] - mid["R"]
if j + j - i < n:
if s[j + j - i] == "R":
cnt -= 1
elif [s[i], s[j]].count("G") == 0:
cnt += c["G"] - mid["G"]
if j + j - i < n:
if s[j + j - i] == "G":
cnt -= 1
elif [s[i], s[j]].count("B") == 0:
cnt += c["B"] - mid["B"]
if j + j - i < n:
if s[j + j - i] == "B":
cnt -= 1
print(cnt)
if __name__ == "__main__":
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
n = int(readline())
s = str(readline().rstrip().decode("utf-8"))
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt = r * g * b
for i in range(n - 2):
for j in range(i + 1, n - 1):
k = j + j - i
if k < n:
if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
cnt -= 1
print(cnt)
if __name__ == "__main__":
solve()
| false | 42.5 |
[
"-import collections",
"- c = collections.Counter(list(s))",
"- left = collections.defaultdict(int)",
"- cnt = 0",
"+ r = s.count(\"R\")",
"+ g = s.count(\"G\")",
"+ b = s.count(\"B\")",
"+ cnt = r * g * b",
"- left[s[i]] += 1",
"- mid = collections.defaultdict(int)",
"- for k, v in list(left.items()):",
"- mid[k] += v",
"- mid[s[j]] += 1",
"- if s[i] != s[j]:",
"- if [s[i], s[j]].count(\"R\") == 0:",
"- cnt += c[\"R\"] - mid[\"R\"]",
"- if j + j - i < n:",
"- if s[j + j - i] == \"R\":",
"- cnt -= 1",
"- elif [s[i], s[j]].count(\"G\") == 0:",
"- cnt += c[\"G\"] - mid[\"G\"]",
"- if j + j - i < n:",
"- if s[j + j - i] == \"G\":",
"- cnt -= 1",
"- elif [s[i], s[j]].count(\"B\") == 0:",
"- cnt += c[\"B\"] - mid[\"B\"]",
"- if j + j - i < n:",
"- if s[j + j - i] == \"B\":",
"- cnt -= 1",
"+ k = j + j - i",
"+ if k < n:",
"+ if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:",
"+ cnt -= 1"
] | false | 0.071487 | 0.036685 | 1.948669 |
[
"s579421725",
"s356475475"
] |
u223663729
|
p03854
|
python
|
s757275251
|
s187519382
| 93 | 58 | 3,188 | 26,008 |
Accepted
|
Accepted
| 37.63 |
def main():
s = eval(input())
dream = False
erase = False
while s:
if s.startswith('dream'):
s = s[5:]
dream = True
erase = False
elif s.startswith('erase'):
s = s[5:]
dream = False
erase = True
elif s.startswith('er') and dream:
s = s[2:]
dream = False
elif s.startswith('r') and erase:
s = s[1:]
erase = False
else:
return False
return True
if main():
print('YES')
else:
print('NO')
|
# dfs
import sys
sys.setrecursionlimit(10**6)
C = ['dream', 'dreamer', 'erase', 'eraser']
S = eval(input())
L = len(S)
def dfs(x, l):
if l == L:
return True
elif l > L:
return False
match = S[l:l+7]
for c in C:
if match.find(c) == 0:
if dfs(c, l+len(c)):
return True
return False
print(('YES' if dfs('', 0) else 'NO'))
| 29 | 24 | 511 | 412 |
def main():
s = eval(input())
dream = False
erase = False
while s:
if s.startswith("dream"):
s = s[5:]
dream = True
erase = False
elif s.startswith("erase"):
s = s[5:]
dream = False
erase = True
elif s.startswith("er") and dream:
s = s[2:]
dream = False
elif s.startswith("r") and erase:
s = s[1:]
erase = False
else:
return False
return True
if main():
print("YES")
else:
print("NO")
|
# dfs
import sys
sys.setrecursionlimit(10**6)
C = ["dream", "dreamer", "erase", "eraser"]
S = eval(input())
L = len(S)
def dfs(x, l):
if l == L:
return True
elif l > L:
return False
match = S[l : l + 7]
for c in C:
if match.find(c) == 0:
if dfs(c, l + len(c)):
return True
return False
print(("YES" if dfs("", 0) else "NO"))
| false | 17.241379 |
[
"-def main():",
"- s = eval(input())",
"- dream = False",
"- erase = False",
"- while s:",
"- if s.startswith(\"dream\"):",
"- s = s[5:]",
"- dream = True",
"- erase = False",
"- elif s.startswith(\"erase\"):",
"- s = s[5:]",
"- dream = False",
"- erase = True",
"- elif s.startswith(\"er\") and dream:",
"- s = s[2:]",
"- dream = False",
"- elif s.startswith(\"r\") and erase:",
"- s = s[1:]",
"- erase = False",
"- else:",
"- return False",
"- return True",
"+# dfs",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+C = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]",
"+S = eval(input())",
"+L = len(S)",
"-if main():",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"+def dfs(x, l):",
"+ if l == L:",
"+ return True",
"+ elif l > L:",
"+ return False",
"+ match = S[l : l + 7]",
"+ for c in C:",
"+ if match.find(c) == 0:",
"+ if dfs(c, l + len(c)):",
"+ return True",
"+ return False",
"+",
"+",
"+print((\"YES\" if dfs(\"\", 0) else \"NO\"))"
] | false | 0.036604 | 0.037088 | 0.986962 |
[
"s757275251",
"s187519382"
] |
u816631826
|
p03264
|
python
|
s841163966
|
s681000991
| 19 | 17 | 3,064 | 2,940 |
Accepted
|
Accepted
| 10.53 |
K=int(eval(input()))
a=[]
for i in range(1,K+1):
a.append(i)
counter=0
if K>=2 and K<=100 :
for x in range(len(a)):
for j in range(x+1,len(a)):
if a[x]&1==0 and a[j]&1==1 or a[x]&1==1 and a[j]&1==0:
a[x]*a[j]%2==0
if a[x]*a[j]%2==0:
counter+=1
print(counter)
|
x=int(eval(input()))
z=0
if x<2:
print((0))
for i in range(2,x+1,2):
for j in range(1,x+1,2):
z+=1
print(z)
| 16 | 8 | 379 | 122 |
K = int(eval(input()))
a = []
for i in range(1, K + 1):
a.append(i)
counter = 0
if K >= 2 and K <= 100:
for x in range(len(a)):
for j in range(x + 1, len(a)):
if a[x] & 1 == 0 and a[j] & 1 == 1 or a[x] & 1 == 1 and a[j] & 1 == 0:
a[x] * a[j] % 2 == 0
if a[x] * a[j] % 2 == 0:
counter += 1
print(counter)
|
x = int(eval(input()))
z = 0
if x < 2:
print((0))
for i in range(2, x + 1, 2):
for j in range(1, x + 1, 2):
z += 1
print(z)
| false | 50 |
[
"-K = int(eval(input()))",
"-a = []",
"-for i in range(1, K + 1):",
"- a.append(i)",
"-counter = 0",
"-if K >= 2 and K <= 100:",
"- for x in range(len(a)):",
"- for j in range(x + 1, len(a)):",
"- if a[x] & 1 == 0 and a[j] & 1 == 1 or a[x] & 1 == 1 and a[j] & 1 == 0:",
"- a[x] * a[j] % 2 == 0",
"- if a[x] * a[j] % 2 == 0:",
"- counter += 1",
"- print(counter)",
"+x = int(eval(input()))",
"+z = 0",
"+if x < 2:",
"+ print((0))",
"+for i in range(2, x + 1, 2):",
"+ for j in range(1, x + 1, 2):",
"+ z += 1",
"+print(z)"
] | false | 0.062951 | 0.06372 | 0.987944 |
[
"s841163966",
"s681000991"
] |
u977193988
|
p02720
|
python
|
s876262535
|
s739703295
| 95 | 69 | 11,976 | 18,784 |
Accepted
|
Accepted
| 27.37 |
import sys
from collections import deque
def input():
return sys.stdin.readline().strip()
def main():
K = int(eval(input()))
ans = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for _ in range(K - 1):
a = ans.popleft()
if a % 10 == 0:
ans.append(a * 10)
ans.append(a * 10 + 1)
elif a % 10 == 9:
ans.append(a * 10 + 8)
ans.append(a * 10 + 9)
else:
w = a % 10
ans.append(a * 10 + w - 1)
ans.append(a * 10 + w)
ans.append(a * 10 + w + 1)
print((ans.popleft()))
if __name__ == "__main__":
main()
|
import sys
from collections import deque
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7
INF = float("inf")
def main():
K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
d = q.popleft()
a = d % 10
if a == 0:
q.append(d * 10)
q.append(d * 10 + 1)
elif a == 9:
q.append(d * 10 + a - 1)
q.append(d * 10 + a)
else:
q.append(d * 10 + a - 1)
q.append(d * 10 + a)
q.append(d * 10 + a + 1)
print(d)
if __name__ == "__main__":
main()
| 29 | 35 | 658 | 692 |
import sys
from collections import deque
def input():
return sys.stdin.readline().strip()
def main():
K = int(eval(input()))
ans = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for _ in range(K - 1):
a = ans.popleft()
if a % 10 == 0:
ans.append(a * 10)
ans.append(a * 10 + 1)
elif a % 10 == 9:
ans.append(a * 10 + 8)
ans.append(a * 10 + 9)
else:
w = a % 10
ans.append(a * 10 + w - 1)
ans.append(a * 10 + w)
ans.append(a * 10 + w + 1)
print((ans.popleft()))
if __name__ == "__main__":
main()
|
import sys
from collections import deque
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10**9 + 7
INF = float("inf")
def main():
K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
d = q.popleft()
a = d % 10
if a == 0:
q.append(d * 10)
q.append(d * 10 + 1)
elif a == 9:
q.append(d * 10 + a - 1)
q.append(d * 10 + a)
else:
q.append(d * 10 + a - 1)
q.append(d * 10 + a)
q.append(d * 10 + a + 1)
print(d)
if __name__ == "__main__":
main()
| false | 17.142857 |
[
"+sys.setrecursionlimit(20000000)",
"+MOD = 10**9 + 7",
"+INF = float(\"inf\")",
"+",
"+",
"- ans = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])",
"- for _ in range(K - 1):",
"- a = ans.popleft()",
"- if a % 10 == 0:",
"- ans.append(a * 10)",
"- ans.append(a * 10 + 1)",
"- elif a % 10 == 9:",
"- ans.append(a * 10 + 8)",
"- ans.append(a * 10 + 9)",
"+ q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])",
"+ for i in range(K):",
"+ d = q.popleft()",
"+ a = d % 10",
"+ if a == 0:",
"+ q.append(d * 10)",
"+ q.append(d * 10 + 1)",
"+ elif a == 9:",
"+ q.append(d * 10 + a - 1)",
"+ q.append(d * 10 + a)",
"- w = a % 10",
"- ans.append(a * 10 + w - 1)",
"- ans.append(a * 10 + w)",
"- ans.append(a * 10 + w + 1)",
"- print((ans.popleft()))",
"+ q.append(d * 10 + a - 1)",
"+ q.append(d * 10 + a)",
"+ q.append(d * 10 + a + 1)",
"+ print(d)"
] | false | 0.140379 | 0.200132 | 0.701434 |
[
"s876262535",
"s739703295"
] |
u970197315
|
p02720
|
python
|
s558821851
|
s853084066
| 1,360 | 112 | 20,880 | 12,404 |
Accepted
|
Accepted
| 91.76 |
def dfs(s):
d=len(s)
if d>10:
return
if s!='':
if s[0]!='0':
num.add(int(s))
for c in '0123456789':
if s=='':
dfs(s+c)
else:
if abs(int(s[-1])-int(c))<=1:
dfs(s+c)
k=int(eval(input()))
num=set()
dfs('')
ans=list(num)
ans.sort()
print((ans[k-1]))
|
from collections import deque
k=int(eval(input()))
q=deque([i for i in range(1,10)])
ans=0
cnt=0
while 1:
x=q.popleft()
cnt+=1
if cnt==k:
ans=x
break
xmod10 = x % 10
if xmod10 != 0:
q.append(10*x+(xmod10-1))
q.append(10*x+(xmod10))
if xmod10 != 9:
q.append(10*x+(xmod10+1))
print(ans)
| 23 | 21 | 367 | 362 |
def dfs(s):
d = len(s)
if d > 10:
return
if s != "":
if s[0] != "0":
num.add(int(s))
for c in "0123456789":
if s == "":
dfs(s + c)
else:
if abs(int(s[-1]) - int(c)) <= 1:
dfs(s + c)
k = int(eval(input()))
num = set()
dfs("")
ans = list(num)
ans.sort()
print((ans[k - 1]))
|
from collections import deque
k = int(eval(input()))
q = deque([i for i in range(1, 10)])
ans = 0
cnt = 0
while 1:
x = q.popleft()
cnt += 1
if cnt == k:
ans = x
break
xmod10 = x % 10
if xmod10 != 0:
q.append(10 * x + (xmod10 - 1))
q.append(10 * x + (xmod10))
if xmod10 != 9:
q.append(10 * x + (xmod10 + 1))
print(ans)
| false | 8.695652 |
[
"-def dfs(s):",
"- d = len(s)",
"- if d > 10:",
"- return",
"- if s != \"\":",
"- if s[0] != \"0\":",
"- num.add(int(s))",
"- for c in \"0123456789\":",
"- if s == \"\":",
"- dfs(s + c)",
"- else:",
"- if abs(int(s[-1]) - int(c)) <= 1:",
"- dfs(s + c)",
"-",
"+from collections import deque",
"-num = set()",
"-dfs(\"\")",
"-ans = list(num)",
"-ans.sort()",
"-print((ans[k - 1]))",
"+q = deque([i for i in range(1, 10)])",
"+ans = 0",
"+cnt = 0",
"+while 1:",
"+ x = q.popleft()",
"+ cnt += 1",
"+ if cnt == k:",
"+ ans = x",
"+ break",
"+ xmod10 = x % 10",
"+ if xmod10 != 0:",
"+ q.append(10 * x + (xmod10 - 1))",
"+ q.append(10 * x + (xmod10))",
"+ if xmod10 != 9:",
"+ q.append(10 * x + (xmod10 + 1))",
"+print(ans)"
] | false | 1.870931 | 0.042605 | 43.913807 |
[
"s558821851",
"s853084066"
] |
u318029285
|
p03030
|
python
|
s591188787
|
s774335813
| 20 | 17 | 3,064 | 3,060 |
Accepted
|
Accepted
| 15 |
N = int(eval(input()))
S = [""] * N
P = [0] * N
for i in range(N):
S[i], P[i] = input().split()
P[i] = int(P[i])
new_S = sorted(S)
same_v = []
same_i = []
for i, name in enumerate(new_S):
for k in range(N):
if new_S[i] == S[k]:
same_v.append(P[k])
same_i.append(k)
x = same_i[same_v.index(max(same_v))]
print((x + 1))
same_v = []
same_i = []
P[x] = -1
|
N = int(eval(input()))
SP = []
for i in range(N):
s, p = input().split()
SP.append([s] + [int(p)] + [i + 1])
new_SP = sorted(SP, key=lambda x: (x[0], -x[1]))
for _, _, i in new_SP:
print(i)
| 24 | 11 | 435 | 208 |
N = int(eval(input()))
S = [""] * N
P = [0] * N
for i in range(N):
S[i], P[i] = input().split()
P[i] = int(P[i])
new_S = sorted(S)
same_v = []
same_i = []
for i, name in enumerate(new_S):
for k in range(N):
if new_S[i] == S[k]:
same_v.append(P[k])
same_i.append(k)
x = same_i[same_v.index(max(same_v))]
print((x + 1))
same_v = []
same_i = []
P[x] = -1
|
N = int(eval(input()))
SP = []
for i in range(N):
s, p = input().split()
SP.append([s] + [int(p)] + [i + 1])
new_SP = sorted(SP, key=lambda x: (x[0], -x[1]))
for _, _, i in new_SP:
print(i)
| false | 54.166667 |
[
"-S = [\"\"] * N",
"-P = [0] * N",
"+SP = []",
"- S[i], P[i] = input().split()",
"- P[i] = int(P[i])",
"-new_S = sorted(S)",
"-same_v = []",
"-same_i = []",
"-for i, name in enumerate(new_S):",
"- for k in range(N):",
"- if new_S[i] == S[k]:",
"- same_v.append(P[k])",
"- same_i.append(k)",
"- x = same_i[same_v.index(max(same_v))]",
"- print((x + 1))",
"- same_v = []",
"- same_i = []",
"- P[x] = -1",
"+ s, p = input().split()",
"+ SP.append([s] + [int(p)] + [i + 1])",
"+new_SP = sorted(SP, key=lambda x: (x[0], -x[1]))",
"+for _, _, i in new_SP:",
"+ print(i)"
] | false | 0.052541 | 0.061231 | 0.858068 |
[
"s591188787",
"s774335813"
] |
u552738814
|
p03852
|
python
|
s158112065
|
s989038687
| 27 | 24 | 8,916 | 9,100 |
Accepted
|
Accepted
| 11.11 |
C = eval(input())
if C in ["a","i","u","e","o"]:
print("vowel")
else:
print("consonant")
|
c = eval(input())
if c in ["a","i","u","e","o"]:
print("vowel")
else:
print("consonant")
| 6 | 5 | 96 | 95 |
C = eval(input())
if C in ["a", "i", "u", "e", "o"]:
print("vowel")
else:
print("consonant")
|
c = eval(input())
if c in ["a", "i", "u", "e", "o"]:
print("vowel")
else:
print("consonant")
| false | 16.666667 |
[
"-C = eval(input())",
"-if C in [\"a\", \"i\", \"u\", \"e\", \"o\"]:",
"+c = eval(input())",
"+if c in [\"a\", \"i\", \"u\", \"e\", \"o\"]:"
] | false | 0.045092 | 0.089985 | 0.501112 |
[
"s158112065",
"s989038687"
] |
u588341295
|
p03816
|
python
|
s774380368
|
s601211972
| 104 | 88 | 21,076 | 18,628 |
Accepted
|
Accepted
| 15.38 |
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
from collections import Counter
N = int(eval(input()))
aN = list(map(int, input().split()))
dups = Counter(aN)
for k, v in list(dups.items()):
dups[k] -= 1
aN = sorted(set(aN))
if sum(dups.values()) % 2 == 0:
print((len(aN)))
else:
print((len(aN)-1))
|
# -*- coding: utf-8 -*-
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
C = Counter(A)
for k in list(C.keys()):
C[k] -= 1
cnt = ceil(sum(C.values()), 2)
ans = N - cnt * 2
print(ans)
| 22 | 31 | 425 | 870 |
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
from collections import Counter
N = int(eval(input()))
aN = list(map(int, input().split()))
dups = Counter(aN)
for k, v in list(dups.items()):
dups[k] -= 1
aN = sorted(set(aN))
if sum(dups.values()) % 2 == 0:
print((len(aN)))
else:
print((len(aN) - 1))
|
# -*- coding: utf-8 -*-
import sys
from collections import Counter
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N = INT()
A = LIST()
C = Counter(A)
for k in list(C.keys()):
C[k] -= 1
cnt = ceil(sum(C.values()), 2)
ans = N - cnt * 2
print(ans)
| false | 29.032258 |
[
"+from collections import Counter",
"+def list2d(a, b, c):",
"+ return [[c] * b for i in range(a)]",
"+",
"+",
"+def list3d(a, b, c, d):",
"+ return [[[d] * c for j in range(b)] for i in range(a)]",
"+",
"+",
"+def list4d(a, b, c, d, e):",
"+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]",
"+",
"+",
"+def ceil(x, y=1):",
"+ return int(-(-x // y))",
"+",
"+",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LIST(N=None):",
"+ return list(MAP()) if N is None else [INT() for i in range(N)]",
"+",
"+",
"+def Yes():",
"+ print(\"Yes\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def YES():",
"+ print(\"YES\")",
"+",
"+",
"+def NO():",
"+ print(\"NO\")",
"+",
"+",
"-INF = float(\"inf\")",
"+INF = 10**18",
"-from collections import Counter",
"-",
"-N = int(eval(input()))",
"-aN = list(map(int, input().split()))",
"-dups = Counter(aN)",
"-for k, v in list(dups.items()):",
"- dups[k] -= 1",
"-aN = sorted(set(aN))",
"-if sum(dups.values()) % 2 == 0:",
"- print((len(aN)))",
"-else:",
"- print((len(aN) - 1))",
"+N = INT()",
"+A = LIST()",
"+C = Counter(A)",
"+for k in list(C.keys()):",
"+ C[k] -= 1",
"+cnt = ceil(sum(C.values()), 2)",
"+ans = N - cnt * 2",
"+print(ans)"
] | false | 0.044225 | 0.046061 | 0.960127 |
[
"s774380368",
"s601211972"
] |
u477977638
|
p02614
|
python
|
s540244232
|
s353276461
| 91 | 82 | 68,516 | 74,040 |
Accepted
|
Accepted
| 9.89 |
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
h,w,k=MI()
G=[]
for _ in range(h):
G.append(list(eval(input())))
#print(G)
ans=0
for i in range(1<<h):
for j in range(1<<w):
cnt=0
for ii in range(h):
for jj in range(w):
#print(i,j,ii,jj,)
if i&1<<ii and j&1<<jj and G[ii-1][jj-1]=="#":
#print(1<<i)
cnt+=1
if cnt==k:
ans+=1
print(ans)
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
h,w,k=MI()
G=[]
for _ in range(h):
G.append(list(input().rstrip().decode()))
#print(G)
ans=0
for i in range(1<<h):
for j in range(1<<w):
cnt=0
for ii in range(h):
for jj in range(w):
#print(i,j,ii,jj,)
if i&1<<ii and j&1<<jj and G[ii-1][jj-1]=="#":
#print(1<<i)
cnt+=1
if cnt==k:
ans+=1
print(ans)
if __name__ == "__main__":
main()
| 47 | 47 | 882 | 899 |
import sys
# input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
return sys.stdin.read()
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode()
# import numpy as np
def main():
h, w, k = MI()
G = []
for _ in range(h):
G.append(list(eval(input())))
# print(G)
ans = 0
for i in range(1 << h):
for j in range(1 << w):
cnt = 0
for ii in range(h):
for jj in range(w):
# print(i,j,ii,jj,)
if i & 1 << ii and j & 1 << jj and G[ii - 1][jj - 1] == "#":
# print(1<<i)
cnt += 1
if cnt == k:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
import sys
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
return sys.stdin.read()
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MF():
return list(map(float, input().split()))
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode()
# import numpy as np
def main():
h, w, k = MI()
G = []
for _ in range(h):
G.append(list(input().rstrip().decode()))
# print(G)
ans = 0
for i in range(1 << h):
for j in range(1 << w):
cnt = 0
for ii in range(h):
for jj in range(w):
# print(i,j,ii,jj,)
if i & 1 << ii and j & 1 << jj and G[ii - 1][jj - 1] == "#":
# print(1<<i)
cnt += 1
if cnt == k:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 0 |
[
"-# input = sys.stdin.buffer.readline",
"+input = sys.stdin.buffer.readline",
"- G.append(list(eval(input())))",
"+ G.append(list(input().rstrip().decode()))"
] | false | 0.049684 | 0.090451 | 0.549295 |
[
"s540244232",
"s353276461"
] |
u893063840
|
p02913
|
python
|
s716877375
|
s681557846
| 1,332 | 1,185 | 14,664 | 20,876 |
Accepted
|
Accepted
| 11.04 |
import numpy as np
n = int(eval(input()))
s = np.array(list(eval(input())))
l = s.size
dp = np.zeros(l, dtype=np.int16)
ans = 0
for i, e in enumerate(s, 1):
dp_prev = dp[:]
mx = np.arange(1, l + 1) - i
idx = np.hstack([np.full(i, False), s[i:] == e]).astype(np.bool)
idx_prev = np.hstack([np.full(i-1, False), s[i:] == e, False]).astype(np.bool)
dp = np.zeros(l, dtype=np.int16)
dp[idx] = np.minimum(dp_prev[idx_prev] + 1, mx[idx])
ans = max(ans, dp.max())
print(ans)
|
import numpy as np
n = int(eval(input()))
s = np.array(list(eval(input())))
l = s.size
dp = np.zeros(l, dtype=np.int16)
ans = 0
for i, e in enumerate(s, 1):
dp_prev = dp.copy()
mx = np.arange(1, l + 1) - i
idx = np.hstack([np.full(i, False), s[i:] == e]).astype(np.bool)
idx_prev = np.roll(idx, -1)
dp = np.zeros(l, dtype=np.int16)
dp[idx] = np.minimum(dp_prev[idx_prev] + 1, mx[idx])
ans = max(ans, dp.max())
print(ans)
| 19 | 19 | 506 | 459 |
import numpy as np
n = int(eval(input()))
s = np.array(list(eval(input())))
l = s.size
dp = np.zeros(l, dtype=np.int16)
ans = 0
for i, e in enumerate(s, 1):
dp_prev = dp[:]
mx = np.arange(1, l + 1) - i
idx = np.hstack([np.full(i, False), s[i:] == e]).astype(np.bool)
idx_prev = np.hstack([np.full(i - 1, False), s[i:] == e, False]).astype(np.bool)
dp = np.zeros(l, dtype=np.int16)
dp[idx] = np.minimum(dp_prev[idx_prev] + 1, mx[idx])
ans = max(ans, dp.max())
print(ans)
|
import numpy as np
n = int(eval(input()))
s = np.array(list(eval(input())))
l = s.size
dp = np.zeros(l, dtype=np.int16)
ans = 0
for i, e in enumerate(s, 1):
dp_prev = dp.copy()
mx = np.arange(1, l + 1) - i
idx = np.hstack([np.full(i, False), s[i:] == e]).astype(np.bool)
idx_prev = np.roll(idx, -1)
dp = np.zeros(l, dtype=np.int16)
dp[idx] = np.minimum(dp_prev[idx_prev] + 1, mx[idx])
ans = max(ans, dp.max())
print(ans)
| false | 0 |
[
"- dp_prev = dp[:]",
"+ dp_prev = dp.copy()",
"- idx_prev = np.hstack([np.full(i - 1, False), s[i:] == e, False]).astype(np.bool)",
"+ idx_prev = np.roll(idx, -1)"
] | false | 0.202949 | 0.253136 | 0.801738 |
[
"s716877375",
"s681557846"
] |
u930705402
|
p03222
|
python
|
s140295121
|
s686867136
| 137 | 114 | 9,260 | 74,468 |
Accepted
|
Accepted
| 16.79 |
MOD=10**9+7
H,W,K=list(map(int,input().split()))
dp=[[0]*W for i in range(H+1)]
dp[0][0]=1
for i in range(1,H+1):
for k in range(W):
l,c,r=0,0,0
for bit in range(2**(W-1)):
ok=True
for t in range(W-2):
if (bit>>t&1) and (bit>>(t+1)&1):
ok=False
break
if not ok:
continue
if ((k>0 and not(bit>>(k-1)&1)) or k==0) and ((k<W-1 and not(bit>>k&1))or k==W-1):
c+=1
if (k>0):
if ((k>1 and not(bit>>(k-2)&1)) or k==1) and ((k<W-1 and not(bit>>k&1))or k==W-1) and (bit>>(k-1)&1):
l+=1
if (k<W-1):
if ((k>0 and not(bit>>(k-1)&1)) or k==0) and ((k<W-2 and not (bit>>(k+1)&1))or k==W-2) and (bit>>k&1):
r+=1
dp[i][k]=(dp[i][k]+dp[i-1][k]*c)%MOD
if k>0:
dp[i][k]=(dp[i][k]+dp[i-1][k-1]*l)%MOD
if k<W-1:
dp[i][k]=(dp[i][k]+dp[i-1][k+1]*r)%MOD
print((dp[H][K-1]))
|
MOD=10**9+7
def isvalid(bit):
for t in range(W-2):
if (bit>>t&1) and (bit>>(t+1)&1):
return False
return True
H,W,K=list(map(int,input().split()))
dp=[[0]*W for i in range(H+1)]
dp[0][0]=1
for i in range(1,H+1):
for k in range(W):
l,c,r=0,0,0
for bit in range(2**(W-1)):
if not isvalid(bit):
continue
if ((k>0 and not(bit>>(k-1)&1)) or k==0) and ((k<W-1 and not(bit>>k&1))or k==W-1):
c+=1
if (k>0) and (bit>>(k-1)&1):
l+=1
if (k<W-1) and (bit>>k&1):
r+=1
dp[i][k]=(dp[i][k]+dp[i-1][k]*c)%MOD
if k>0:
dp[i][k]=(dp[i][k]+dp[i-1][k-1]*l)%MOD
if k<W-1:
dp[i][k]=(dp[i][k]+dp[i-1][k+1]*r)%MOD
print((dp[H][K-1]))
| 30 | 30 | 1,070 | 839 |
MOD = 10**9 + 7
H, W, K = list(map(int, input().split()))
dp = [[0] * W for i in range(H + 1)]
dp[0][0] = 1
for i in range(1, H + 1):
for k in range(W):
l, c, r = 0, 0, 0
for bit in range(2 ** (W - 1)):
ok = True
for t in range(W - 2):
if (bit >> t & 1) and (bit >> (t + 1) & 1):
ok = False
break
if not ok:
continue
if ((k > 0 and not (bit >> (k - 1) & 1)) or k == 0) and (
(k < W - 1 and not (bit >> k & 1)) or k == W - 1
):
c += 1
if k > 0:
if (
((k > 1 and not (bit >> (k - 2) & 1)) or k == 1)
and ((k < W - 1 and not (bit >> k & 1)) or k == W - 1)
and (bit >> (k - 1) & 1)
):
l += 1
if k < W - 1:
if (
((k > 0 and not (bit >> (k - 1) & 1)) or k == 0)
and ((k < W - 2 and not (bit >> (k + 1) & 1)) or k == W - 2)
and (bit >> k & 1)
):
r += 1
dp[i][k] = (dp[i][k] + dp[i - 1][k] * c) % MOD
if k > 0:
dp[i][k] = (dp[i][k] + dp[i - 1][k - 1] * l) % MOD
if k < W - 1:
dp[i][k] = (dp[i][k] + dp[i - 1][k + 1] * r) % MOD
print((dp[H][K - 1]))
|
MOD = 10**9 + 7
def isvalid(bit):
for t in range(W - 2):
if (bit >> t & 1) and (bit >> (t + 1) & 1):
return False
return True
H, W, K = list(map(int, input().split()))
dp = [[0] * W for i in range(H + 1)]
dp[0][0] = 1
for i in range(1, H + 1):
for k in range(W):
l, c, r = 0, 0, 0
for bit in range(2 ** (W - 1)):
if not isvalid(bit):
continue
if ((k > 0 and not (bit >> (k - 1) & 1)) or k == 0) and (
(k < W - 1 and not (bit >> k & 1)) or k == W - 1
):
c += 1
if (k > 0) and (bit >> (k - 1) & 1):
l += 1
if (k < W - 1) and (bit >> k & 1):
r += 1
dp[i][k] = (dp[i][k] + dp[i - 1][k] * c) % MOD
if k > 0:
dp[i][k] = (dp[i][k] + dp[i - 1][k - 1] * l) % MOD
if k < W - 1:
dp[i][k] = (dp[i][k] + dp[i - 1][k + 1] * r) % MOD
print((dp[H][K - 1]))
| false | 0 |
[
"+",
"+",
"+def isvalid(bit):",
"+ for t in range(W - 2):",
"+ if (bit >> t & 1) and (bit >> (t + 1) & 1):",
"+ return False",
"+ return True",
"+",
"+",
"- ok = True",
"- for t in range(W - 2):",
"- if (bit >> t & 1) and (bit >> (t + 1) & 1):",
"- ok = False",
"- break",
"- if not ok:",
"+ if not isvalid(bit):",
"- if k > 0:",
"- if (",
"- ((k > 1 and not (bit >> (k - 2) & 1)) or k == 1)",
"- and ((k < W - 1 and not (bit >> k & 1)) or k == W - 1)",
"- and (bit >> (k - 1) & 1)",
"- ):",
"- l += 1",
"- if k < W - 1:",
"- if (",
"- ((k > 0 and not (bit >> (k - 1) & 1)) or k == 0)",
"- and ((k < W - 2 and not (bit >> (k + 1) & 1)) or k == W - 2)",
"- and (bit >> k & 1)",
"- ):",
"- r += 1",
"+ if (k > 0) and (bit >> (k - 1) & 1):",
"+ l += 1",
"+ if (k < W - 1) and (bit >> k & 1):",
"+ r += 1"
] | false | 0.054186 | 0.045752 | 1.184354 |
[
"s140295121",
"s686867136"
] |
u225388820
|
p02598
|
python
|
s858783862
|
s788837932
| 1,588 | 168 | 93,860 | 93,828 |
Accepted
|
Accepted
| 89.42 |
from math import ceil
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def c(x):
cnt=0
for i in a:
cnt += i // x
return cnt<=k
l, r = 0, max(a)
for i in range(100):
mid = (l + r) / 2
if c(mid):
r = mid
else:
l = mid
print((ceil(l)))
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def c(x):
cnt=0
for i in a:
cnt += (i - 1) // x
return cnt <= k
l, r = 0, max(a)
while l + 1 < r:
mid = (l + r) // 2
if c(mid):
r = mid
else:
l = mid
print(r)
| 16 | 18 | 313 | 299 |
from math import ceil
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def c(x):
cnt = 0
for i in a:
cnt += i // x
return cnt <= k
l, r = 0, max(a)
for i in range(100):
mid = (l + r) / 2
if c(mid):
r = mid
else:
l = mid
print((ceil(l)))
|
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
def c(x):
cnt = 0
for i in a:
cnt += (i - 1) // x
return cnt <= k
l, r = 0, max(a)
while l + 1 < r:
mid = (l + r) // 2
if c(mid):
r = mid
else:
l = mid
print(r)
| false | 11.111111 |
[
"-from math import ceil",
"-",
"- cnt += i // x",
"+ cnt += (i - 1) // x",
"-for i in range(100):",
"- mid = (l + r) / 2",
"+while l + 1 < r:",
"+ mid = (l + r) // 2",
"-print((ceil(l)))",
"+print(r)"
] | false | 0.071253 | 0.08121 | 0.877393 |
[
"s858783862",
"s788837932"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.