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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u054825571 | p02577 | python | s613415912 | s803900798 | 205 | 56 | 9,260 | 10,832 | Accepted | Accepted | 72.68 | print(("Yes" if int(eval(input()))%9==0 else "No")) | n=sum([int(c) for c in eval(input())])
print(("Yes" if n%9==0 else "No")) | 1 | 2 | 43 | 66 | print(("Yes" if int(eval(input())) % 9 == 0 else "No"))
| n = sum([int(c) for c in eval(input())])
print(("Yes" if n % 9 == 0 else "No"))
| false | 50 | [
"-print((\"Yes\" if int(eval(input())) % 9 == 0 else \"No\"))",
"+n = sum([int(c) for c in eval(input())])",
"+print((\"Yes\" if n % 9 == 0 else \"No\"))"
] | false | 0.035824 | 0.036889 | 0.971126 | [
"s613415912",
"s803900798"
] |
u415875614 | p02711 | python | s059567154 | s276369965 | 338 | 61 | 79,700 | 61,452 | Accepted | Accepted | 81.95 | N = input()
print('Yes') if '7' in N else print('No')
| print('Yes') if '7' in input() else print('No')
| 2 | 1 | 54 | 47 | N = input()
print("Yes") if "7" in N else print("No")
| print("Yes") if "7" in input() else print("No")
| false | 50 | [
"-N = input()",
"-print(\"Yes\") if \"7\" in N else print(\"No\")",
"+print(\"Yes\") if \"7\" in input() else print(\"No\")"
] | false | 0.008134 | 0.052358 | 0.155343 | [
"s059567154",
"s276369965"
] |
u191874006 | p03048 | python | s907262178 | s222393482 | 1,598 | 249 | 3,188 | 40,940 | Accepted | Accepted | 84.42 | import re
a,b,c,n = list(map(int,re.split(" ",eval(input()))))
N = n
s = []
s.append(a)
s.append(b)
s.append(c)
s.sort()
a,b,c = s
#print(a,b,c)
ans = 0
for i in range(int(N/c)+1):
for j in range(int((N-i*c)/b)+1):
if (N - i*c - j*b)%a == 0:
ans += 1
print(ans) | #!/usr/bin/env python3
#diverta2019 B
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
r,g,b,n = list(map(int,input().split()))
ans = 0
for i in range(n//r+1):
for j in range(n//g+1):
if n - i*r - j*g >= 0:
if (n - i*r - j*g) % b == 0:
ans += 1
print(ans)
| 17 | 25 | 298 | 589 | import re
a, b, c, n = list(map(int, re.split(" ", eval(input()))))
N = n
s = []
s.append(a)
s.append(b)
s.append(c)
s.sort()
a, b, c = s
# print(a,b,c)
ans = 0
for i in range(int(N / c) + 1):
for j in range(int((N - i * c) / b) + 1):
if (N - i * c - j * b) % a == 0:
ans += 1
print(ans)
| #!/usr/bin/env python3
# diverta2019 B
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
r, g, b, n = list(map(int, input().split()))
ans = 0
for i in range(n // r + 1):
for j in range(n // g + 1):
if n - i * r - j * g >= 0:
if (n - i * r - j * g) % b == 0:
ans += 1
print(ans)
| false | 32 | [
"-import re",
"+#!/usr/bin/env python3",
"+# diverta2019 B",
"+import sys",
"+import math",
"+import bisect",
"-a, b, c, n = list(map(int, re.split(\" \", eval(input()))))",
"-N = n",
"-s = []",
"-s.append(a)",
"-s.append(b)",
"-s.append(c)",
"-s.sort()",
"-a, b, c = s",
"-# print(a,b,c)... | false | 0.041303 | 0.305779 | 0.135073 | [
"s907262178",
"s222393482"
] |
u244203620 | p02859 | python | s081434393 | s132382071 | 17 | 15 | 2,940 | 2,824 | Accepted | Accepted | 11.76 | print((int(eval(input()))**2)) | print((input()**2)) | 1 | 1 | 22 | 17 | print((int(eval(input())) ** 2))
| print((input() ** 2))
| false | 0 | [
"-print((int(eval(input())) ** 2))",
"+print((input() ** 2))"
] | false | 0.040482 | 0.040468 | 1.000362 | [
"s081434393",
"s132382071"
] |
u434966508 | p03456 | python | s548654685 | s727039964 | 113 | 67 | 62,028 | 62,096 | Accepted | Accepted | 40.71 | a,b=list(map(str,input().split()))
c=int(a+b)
d=int(c**(1/2))
if d**2==c:
print('Yes')
else:
print('No') | a,b=input().split()
print(('Yes' if int(int((int(a+b))**0.5)**2)==int(a+b) else 'No')) | 8 | 2 | 114 | 85 | a, b = list(map(str, input().split()))
c = int(a + b)
d = int(c ** (1 / 2))
if d**2 == c:
print("Yes")
else:
print("No")
| a, b = input().split()
print(("Yes" if int(int((int(a + b)) ** 0.5) ** 2) == int(a + b) else "No"))
| false | 75 | [
"-a, b = list(map(str, input().split()))",
"-c = int(a + b)",
"-d = int(c ** (1 / 2))",
"-if d**2 == c:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+a, b = input().split()",
"+print((\"Yes\" if int(int((int(a + b)) ** 0.5) ** 2) == int(a + b) else \"No\"))"
] | false | 0.03833 | 0.036558 | 1.048469 | [
"s548654685",
"s727039964"
] |
u191874006 | p03221 | python | s490280273 | s220468913 | 930 | 720 | 93,788 | 114,460 | Accepted | Accepted | 22.58 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,m = LI()
py = [LI()+[i] for i in range(m)]
py.sort(key = lambda x:(x[0],x[1]))
ans = []
flag = True
cnt = 0
for p,y,i in py:
s = '0'*6
t = '0'*6
if flag:
cnt += 1
tmp = p
flag = False
elif tmp == p:
cnt += 1
else:
cnt = 1
tmp = p
s += str(p)
s = s[-6:]
t += str(cnt)
t = t[-6:]
ans.append([s+t,i])
ans.sort(key = lambda x:x[1])
for i,j in ans:
print(i)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n, m = LI()
lst = [[] for _ in range(n)]
for i in range(m):
p, y = LI()
lst[p-1].append([y, i])
for i in lst:
i.sort()
ans = []
for i in range(n):
for idx, [j, k] in enumerate(lst[i]):
s = "0" * 6 + str(i+1)
s = s[-6:]
t = "0" * 6 + str(idx+1)
t = t[-6:]
ans.append([k, s+t])
ans.sort()
for i, j in ans:
print(j) | 46 | 40 | 1,034 | 955 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n, m = LI()
py = [LI() + [i] for i in range(m)]
py.sort(key=lambda x: (x[0], x[1]))
ans = []
flag = True
cnt = 0
for p, y, i in py:
s = "0" * 6
t = "0" * 6
if flag:
cnt += 1
tmp = p
flag = False
elif tmp == p:
cnt += 1
else:
cnt = 1
tmp = p
s += str(p)
s = s[-6:]
t += str(cnt)
t = t[-6:]
ans.append([s + t, i])
ans.sort(key=lambda x: x[1])
for i, j in ans:
print(i)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n, m = LI()
lst = [[] for _ in range(n)]
for i in range(m):
p, y = LI()
lst[p - 1].append([y, i])
for i in lst:
i.sort()
ans = []
for i in range(n):
for idx, [j, k] in enumerate(lst[i]):
s = "0" * 6 + str(i + 1)
s = s[-6:]
t = "0" * 6 + str(idx + 1)
t = t[-6:]
ans.append([k, s + t])
ans.sort()
for i, j in ans:
print(j)
| false | 13.043478 | [
"-py = [LI() + [i] for i in range(m)]",
"-py.sort(key=lambda x: (x[0], x[1]))",
"+lst = [[] for _ in range(n)]",
"+for i in range(m):",
"+ p, y = LI()",
"+ lst[p - 1].append([y, i])",
"+for i in lst:",
"+ i.sort()",
"-flag = True",
"-cnt = 0",
"-for p, y, i in py:",
"- s = \"0\" * ... | false | 0.157802 | 0.102818 | 1.534764 | [
"s490280273",
"s220468913"
] |
u173230196 | p03045 | python | s482210683 | s639562004 | 1,370 | 483 | 7,088 | 7,088 | Accepted | Accepted | 64.74 | n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
a = []
while i != xy[i]:
i = xy[i]
a += [i]
for b in a:
xy[b] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
xy[root(x)] = root(y)
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)
| n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
while i != xy[i]:
i = xy[i]
xy[x] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
xy[root(x)] = root(y)
print((sum(i == v for i, v in enumerate(xy)) - 1))
| 23 | 18 | 376 | 312 | n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
a = []
while i != xy[i]:
i = xy[i]
a += [i]
for b in a:
xy[b] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
xy[root(x)] = root(y)
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)
| n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]
def root(x):
i = x
while i != xy[i]:
i = xy[i]
xy[x] = i
return i
for _ in range(m):
x, y = list(map(int, input().split()[:2]))
xy[root(x)] = root(y)
print((sum(i == v for i, v in enumerate(xy)) - 1))
| false | 21.73913 | [
"- a = []",
"- a += [i]",
"- for b in a:",
"- xy[b] = i",
"+ xy[x] = i",
"-ans = sum(i == v for i, v in enumerate(xy)) - 1",
"-print(ans)",
"+print((sum(i == v for i, v in enumerate(xy)) - 1))"
] | false | 0.046901 | 0.046941 | 0.999163 | [
"s482210683",
"s639562004"
] |
u873915460 | p02559 | python | s338019914 | s754407098 | 1,677 | 793 | 228,160 | 198,964 | Accepted | Accepted | 52.71 | from copy import *
import sys
S=sys.stdin.readlines()
def init(N,node,unit,func):
n=1
while n<N:
n<<=1
for i in range(n*2-1):
if len(node)<=i:
node.append(deepcopy(unit))
else:
node[i]=deepcopy(unit)
node.append(func)
node.append(unit)
node.append(n)
def upd(node,x,a):
y=node[-1]+x
node[y-1]=a
while y>1:
y=y>>1
node[y-1]=node[-3](node[(y<<1)-1],node[y<<1])
def query(node,l,r):
x,y=l,r
z=node[-1]-1
r=node[-2]
while True:
if x==y:
return r
if x&1:
r=node[-3](r,node[x+z])
x+=1
if y&1:
r=node[-3](r,node[y+z-1])
x>>=1
y>>=1
z>>=1
if z==0:
return r
def bis_min_k(node,k,cond):
x=k+1
while True:
if node[-1]<=x:
return x-node[-1]
if cond(node[(x<<1)-1]):
x=x<<1
else:
x=(x<<1)+1
def bis_min(node,l,r,cond):
x,y=l,r
z=node[-1]-1
for i in range(30):
if x+(1<<i)>y:
break
if x&(1<<i):
if cond(node[z+(x>>i)]):
return bis_min_k(node,z+(x>>i),cond)
x+=(1<<i)
if z==0:
break
z>>=1
for i in range(29,-1,-1):
if i and ((node[-1]-1)>>(i-1))==0:
continue
if x+(1<<i)>y:
continue
if (y-x)&(1<<i):
if cond(node[((node[-1]-1)>>i)+(x>>i)]):
return bis_min_k(node,((node[-1]-1)>>i)+(x>>i),cond)
x+=(1<<i)
return node[-1]
N,Q=list(map(int,S[0].split()))
A=list(map(int,S[1].split()))
X=[]
init(N+1,X,0,lambda x,y:x+y)
for i in range(N):
upd(X,i,A[i])
a,b,c=0,0,0
for i in range(Q):
a,b,c=list(map(int,S[i+2].split()))
if a:
print((query(X,b,c)))
else:
upd(X,b,X[X[-1]+b-1]+c) | import sys
S=sys.stdin.readlines()
def Binit(B,siz):
while len(B)<siz+1:
B.append(0)
while len(B)>siz+1:
del B[-1]
for i in range(siz+1):
B[i]=0
B.append(siz)
def Badd(B,a,x):
z=a
while z<=B[-1]:
B[z]+=x
z+=(z&(-z))
def Bsum(B,a):
r=0
z=a
while z>0:
r+=B[z]
z-=(z&(-z))
return r
def Bssum(B,a,b):
return Bsum(B,max(a,b))-Bsum(B,min(a,b)-1)
BIT=[]
N,Q=list(map(int,S[0].split()))
Binit(BIT,N+1)
A=list(map(int,S[1].split()))
for i in range(N):
Badd(BIT,i+1,A[i])
a,b,c=0,0,0
for i in range(Q):
a,b,c=list(map(int,S[i+2].split()))
if a:
print((Bssum(BIT,b+1,c)))
else:
Badd(BIT,b+1,c) | 89 | 41 | 1,706 | 678 | from copy import *
import sys
S = sys.stdin.readlines()
def init(N, node, unit, func):
n = 1
while n < N:
n <<= 1
for i in range(n * 2 - 1):
if len(node) <= i:
node.append(deepcopy(unit))
else:
node[i] = deepcopy(unit)
node.append(func)
node.append(unit)
node.append(n)
def upd(node, x, a):
y = node[-1] + x
node[y - 1] = a
while y > 1:
y = y >> 1
node[y - 1] = node[-3](node[(y << 1) - 1], node[y << 1])
def query(node, l, r):
x, y = l, r
z = node[-1] - 1
r = node[-2]
while True:
if x == y:
return r
if x & 1:
r = node[-3](r, node[x + z])
x += 1
if y & 1:
r = node[-3](r, node[y + z - 1])
x >>= 1
y >>= 1
z >>= 1
if z == 0:
return r
def bis_min_k(node, k, cond):
x = k + 1
while True:
if node[-1] <= x:
return x - node[-1]
if cond(node[(x << 1) - 1]):
x = x << 1
else:
x = (x << 1) + 1
def bis_min(node, l, r, cond):
x, y = l, r
z = node[-1] - 1
for i in range(30):
if x + (1 << i) > y:
break
if x & (1 << i):
if cond(node[z + (x >> i)]):
return bis_min_k(node, z + (x >> i), cond)
x += 1 << i
if z == 0:
break
z >>= 1
for i in range(29, -1, -1):
if i and ((node[-1] - 1) >> (i - 1)) == 0:
continue
if x + (1 << i) > y:
continue
if (y - x) & (1 << i):
if cond(node[((node[-1] - 1) >> i) + (x >> i)]):
return bis_min_k(node, ((node[-1] - 1) >> i) + (x >> i), cond)
x += 1 << i
return node[-1]
N, Q = list(map(int, S[0].split()))
A = list(map(int, S[1].split()))
X = []
init(N + 1, X, 0, lambda x, y: x + y)
for i in range(N):
upd(X, i, A[i])
a, b, c = 0, 0, 0
for i in range(Q):
a, b, c = list(map(int, S[i + 2].split()))
if a:
print((query(X, b, c)))
else:
upd(X, b, X[X[-1] + b - 1] + c)
| import sys
S = sys.stdin.readlines()
def Binit(B, siz):
while len(B) < siz + 1:
B.append(0)
while len(B) > siz + 1:
del B[-1]
for i in range(siz + 1):
B[i] = 0
B.append(siz)
def Badd(B, a, x):
z = a
while z <= B[-1]:
B[z] += x
z += z & (-z)
def Bsum(B, a):
r = 0
z = a
while z > 0:
r += B[z]
z -= z & (-z)
return r
def Bssum(B, a, b):
return Bsum(B, max(a, b)) - Bsum(B, min(a, b) - 1)
BIT = []
N, Q = list(map(int, S[0].split()))
Binit(BIT, N + 1)
A = list(map(int, S[1].split()))
for i in range(N):
Badd(BIT, i + 1, A[i])
a, b, c = 0, 0, 0
for i in range(Q):
a, b, c = list(map(int, S[i + 2].split()))
if a:
print((Bssum(BIT, b + 1, c)))
else:
Badd(BIT, b + 1, c)
| false | 53.932584 | [
"-from copy import *",
"-def init(N, node, unit, func):",
"- n = 1",
"- while n < N:",
"- n <<= 1",
"- for i in range(n * 2 - 1):",
"- if len(node) <= i:",
"- node.append(deepcopy(unit))",
"- else:",
"- node[i] = deepcopy(unit)",
"- node.app... | false | 0.156174 | 0.007334 | 21.294288 | [
"s338019914",
"s754407098"
] |
u955125992 | p03338 | python | s082317118 | s021277698 | 24 | 17 | 3,316 | 3,060 | Accepted | Accepted | 29.17 | from collections import Counter
n = int(eval(input()))
s = list(str(eval(input())))
ans = 0
for i in range(n):
count = 0
cnt1 = Counter(s[0:i])
cnt2 = Counter(s[i:n])
l = []
for k, j in list(cnt1.items()):
l.append(k)
for k, j in list(cnt2.items()):
l.append(k)
cnt3 = Counter(l)
for k, j in list(cnt3.items()):
if j == 2:
count += 1
ans = max(ans, count)
print(ans) | n = int(eval(input()))
s = list(str(eval(input())))
ans = 0
for i in range(n):
#print(set(s[0:i]), set(s[i:n]))
ans = max(ans, len(set(s[0:i])&set(s[i:n])))
print(ans) | 24 | 10 | 440 | 175 | from collections import Counter
n = int(eval(input()))
s = list(str(eval(input())))
ans = 0
for i in range(n):
count = 0
cnt1 = Counter(s[0:i])
cnt2 = Counter(s[i:n])
l = []
for k, j in list(cnt1.items()):
l.append(k)
for k, j in list(cnt2.items()):
l.append(k)
cnt3 = Counter(l)
for k, j in list(cnt3.items()):
if j == 2:
count += 1
ans = max(ans, count)
print(ans)
| n = int(eval(input()))
s = list(str(eval(input())))
ans = 0
for i in range(n):
# print(set(s[0:i]), set(s[i:n]))
ans = max(ans, len(set(s[0:i]) & set(s[i:n])))
print(ans)
| false | 58.333333 | [
"-from collections import Counter",
"-",
"- count = 0",
"- cnt1 = Counter(s[0:i])",
"- cnt2 = Counter(s[i:n])",
"- l = []",
"- for k, j in list(cnt1.items()):",
"- l.append(k)",
"- for k, j in list(cnt2.items()):",
"- l.append(k)",
"- cnt3 = Counter(l)",
"- ... | false | 0.042212 | 0.041843 | 1.00883 | [
"s082317118",
"s021277698"
] |
u214617707 | p03361 | python | s790719216 | s284541395 | 25 | 23 | 3,064 | 3,064 | Accepted | Accepted | 8 | h, w = list(map(int, input().split()))
F = [[] for i in range(h)]
for i in range(h):
a = list(eval(input()))
F[i] = a
flag = True
for i in range(h):
for j in range(w):
if F[i][j] == "#":
flag2 = False
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
nx, ny = i + dx, j + dy
if 0 <= nx < h and 0 <= ny < w and F[nx][ny] == "#":
flag2 = True
if not flag2:
flag = False
break
if flag:
print("Yes")
else:
print("No") | h, w = list(map(int, input().split()))
T = [[] for i in range(h)]
for i in range(h):
a = list(eval(input()))
T[i] = a
# for i in range(h):
# print("".join(map(str, T[i])))
flag = True
for i in range(h):
for j in range(w):
if T[i][j] == "#":
flag2 = False
for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
nx, ny = i + dx, j + dy
if 0 <= nx < h and 0 <= ny < w and T[nx][ny] == "#":
flag2 = True
if not flag2:
flag = False
if flag:
print("Yes")
else:
print("No")
| 23 | 28 | 573 | 619 | h, w = list(map(int, input().split()))
F = [[] for i in range(h)]
for i in range(h):
a = list(eval(input()))
F[i] = a
flag = True
for i in range(h):
for j in range(w):
if F[i][j] == "#":
flag2 = False
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
nx, ny = i + dx, j + dy
if 0 <= nx < h and 0 <= ny < w and F[nx][ny] == "#":
flag2 = True
if not flag2:
flag = False
break
if flag:
print("Yes")
else:
print("No")
| h, w = list(map(int, input().split()))
T = [[] for i in range(h)]
for i in range(h):
a = list(eval(input()))
T[i] = a
# for i in range(h):
# print("".join(map(str, T[i])))
flag = True
for i in range(h):
for j in range(w):
if T[i][j] == "#":
flag2 = False
for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
nx, ny = i + dx, j + dy
if 0 <= nx < h and 0 <= ny < w and T[nx][ny] == "#":
flag2 = True
if not flag2:
flag = False
if flag:
print("Yes")
else:
print("No")
| false | 17.857143 | [
"-F = [[] for i in range(h)]",
"+T = [[] for i in range(h)]",
"- F[i] = a",
"+ T[i] = a",
"+# for i in range(h):",
"+# print(\"\".join(map(str, T[i])))",
"- if F[i][j] == \"#\":",
"+ if T[i][j] == \"#\":",
"- for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:",
"+... | false | 0.037865 | 0.042576 | 0.889362 | [
"s790719216",
"s284541395"
] |
u929461484 | p02915 | python | s857458327 | s518693999 | 31 | 26 | 8,948 | 9,096 | Accepted | Accepted | 16.13 | n = eval(input())
n = int(n)
typ = n ** 3
print(typ) | n = int(eval(input()))
print((n ** 3)) | 4 | 2 | 49 | 31 | n = eval(input())
n = int(n)
typ = n**3
print(typ)
| n = int(eval(input()))
print((n**3))
| false | 50 | [
"-n = eval(input())",
"-n = int(n)",
"-typ = n**3",
"-print(typ)",
"+n = int(eval(input()))",
"+print((n**3))"
] | false | 0.09219 | 0.135475 | 0.680499 | [
"s857458327",
"s518693999"
] |
u813387707 | p02983 | python | s896684621 | s184269196 | 516 | 38 | 3,064 | 3,064 | Accepted | Accepted | 92.64 | l, r = [int(x) for x in input().split()]
if r - l >= 2019:
skip_flag = [False] * 2019
else:
a = l % 2019
temp = r % 2019
b = temp if temp > a else temp + 2019
skip_flag = [True] * 2019
for i in range(a, b + 1):
skip_flag[i % 2019] = False
if not skip_flag[0]:
print((0))
exit()
ans = 2019
for i in range(1, 2019):
if skip_flag[i]:
continue
for j in range(i + 1, 2019):
if skip_flag[j]:
continue
temp = (i * j) % 2019
if temp < ans:
ans = temp
print(ans) | l, r = [int(x) for x in input().split()]
if r - l >= 2019:
a = 0
b = 2019
else:
a = l % 2019
temp = r % 2019
b = temp if a < temp else temp + 2019
ans = 2019
for i in range(a, b):
for j in range(i + 1, b + 1):
temp = (i * j) % 2019
if temp < ans:
ans = temp
if ans == 0:
print((0))
exit()
print(ans) | 28 | 20 | 594 | 414 | l, r = [int(x) for x in input().split()]
if r - l >= 2019:
skip_flag = [False] * 2019
else:
a = l % 2019
temp = r % 2019
b = temp if temp > a else temp + 2019
skip_flag = [True] * 2019
for i in range(a, b + 1):
skip_flag[i % 2019] = False
if not skip_flag[0]:
print((0))
exit()
ans = 2019
for i in range(1, 2019):
if skip_flag[i]:
continue
for j in range(i + 1, 2019):
if skip_flag[j]:
continue
temp = (i * j) % 2019
if temp < ans:
ans = temp
print(ans)
| l, r = [int(x) for x in input().split()]
if r - l >= 2019:
a = 0
b = 2019
else:
a = l % 2019
temp = r % 2019
b = temp if a < temp else temp + 2019
ans = 2019
for i in range(a, b):
for j in range(i + 1, b + 1):
temp = (i * j) % 2019
if temp < ans:
ans = temp
if ans == 0:
print((0))
exit()
print(ans)
| false | 28.571429 | [
"- skip_flag = [False] * 2019",
"+ a = 0",
"+ b = 2019",
"- b = temp if temp > a else temp + 2019",
"- skip_flag = [True] * 2019",
"- for i in range(a, b + 1):",
"- skip_flag[i % 2019] = False",
"-if not skip_flag[0]:",
"- print((0))",
"- exit()",
"+ b = temp if... | false | 0.046997 | 0.036334 | 1.293447 | [
"s896684621",
"s184269196"
] |
u283220417 | p02784 | python | s057857911 | s027758834 | 52 | 43 | 13,964 | 13,964 | Accepted | Accepted | 17.31 | H,N = list(map(int,input().split()))
A = list(map(int,input().split()))
ans = "No"
sumA = 0
for a in A:
sumA += a
if sumA >= H:
ans = "Yes"
break
print(ans) | H,N = list(map(int,input().split()))
A = list(map(int,input().split()))
ans = "No"
if sum(A) >= H:
ans = "Yes"
print(ans) | 12 | 8 | 177 | 128 | H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = "No"
sumA = 0
for a in A:
sumA += a
if sumA >= H:
ans = "Yes"
break
print(ans)
| H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = "No"
if sum(A) >= H:
ans = "Yes"
print(ans)
| false | 33.333333 | [
"-sumA = 0",
"-for a in A:",
"- sumA += a",
"- if sumA >= H:",
"- ans = \"Yes\"",
"- break",
"+if sum(A) >= H:",
"+ ans = \"Yes\""
] | false | 0.047808 | 0.042773 | 1.117714 | [
"s057857911",
"s027758834"
] |
u004423772 | p02726 | python | s518011583 | s907204480 | 936 | 798 | 93,404 | 126,760 | Accepted | Accepted | 14.74 | import sys
input = sys.stdin.readline
import collections
N, X, Y = list(map(int, input().split()))
def bfs(i):
dist = [-1]*N
dist[i] = 0
que = collections.deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:continue
dist[nv] = dist[v]+1
que.append(nv)
return dist[i+1:]
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N-1):
graph[i].add(i+1)
graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)
d = collections.Counter([])
for i in range(N):
d += collections.Counter(bfs(i))
for i in range(1,N):
if i == N-1:
print((0))
else:
print((d[i])) | import sys
input = sys.stdin.readline
from collections import deque
from collections import Counter
def main():
N, X, Y = list(map(int, input().split()))
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N-1):
graph[i].add(i+1)
graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)
ans = []
for i in range(N):
dist = [-1] * N
dist[i] = 0
que = deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:continue
dist[nv] = dist[v] + 1
que.append(nv)
ans += dist
ans = Counter(ans)
for i in range(1, N):
print((ans[i]//2))
if __name__ == "__main__":
main() | 38 | 33 | 760 | 834 | import sys
input = sys.stdin.readline
import collections
N, X, Y = list(map(int, input().split()))
def bfs(i):
dist = [-1] * N
dist[i] = 0
que = collections.deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
que.append(nv)
return dist[i + 1 :]
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N - 1):
graph[i].add(i + 1)
graph[i + 1].add(i)
graph[X - 1].add(Y - 1)
graph[Y - 1].add(X - 1)
d = collections.Counter([])
for i in range(N):
d += collections.Counter(bfs(i))
for i in range(1, N):
if i == N - 1:
print((0))
else:
print((d[i]))
| import sys
input = sys.stdin.readline
from collections import deque
from collections import Counter
def main():
N, X, Y = list(map(int, input().split()))
graph = {}
for i in range(N):
graph[i] = set()
for i in range(N - 1):
graph[i].add(i + 1)
graph[i + 1].add(i)
graph[X - 1].add(Y - 1)
graph[Y - 1].add(X - 1)
ans = []
for i in range(N):
dist = [-1] * N
dist[i] = 0
que = deque([])
que.append(i)
while len(que) != 0:
v = que.popleft()
for nv in graph[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
que.append(nv)
ans += dist
ans = Counter(ans)
for i in range(1, N):
print((ans[i] // 2))
if __name__ == "__main__":
main()
| false | 13.157895 | [
"-import collections",
"-",
"-N, X, Y = list(map(int, input().split()))",
"+from collections import deque",
"+from collections import Counter",
"-def bfs(i):",
"- dist = [-1] * N",
"- dist[i] = 0",
"- que = collections.deque([])",
"- que.append(i)",
"- while len(que) != 0:",
"- ... | false | 0.040987 | 0.040152 | 1.020787 | [
"s518011583",
"s907204480"
] |
u450956662 | p03835 | python | s366331406 | s207807612 | 1,790 | 18 | 3,060 | 2,940 | Accepted | Accepted | 98.99 | K, S = list(map(int, input().split()))
ans = 0
if 3*K < S:
print(ans)
exit()
for X in range(K+1):
for Y in range(K+1):
Z = S - X - Y
if Z < K + 1 and Z > -1:
ans += 1
print(ans) | K, S = list(map(int, input().split()))
ans = 0
for T in range(S-K, S+1):
if T <= K:
ans += max(0, T+1)
else:
ans += max(0, 2*K - T +1)
print(ans) | 13 | 9 | 225 | 172 | K, S = list(map(int, input().split()))
ans = 0
if 3 * K < S:
print(ans)
exit()
for X in range(K + 1):
for Y in range(K + 1):
Z = S - X - Y
if Z < K + 1 and Z > -1:
ans += 1
print(ans)
| K, S = list(map(int, input().split()))
ans = 0
for T in range(S - K, S + 1):
if T <= K:
ans += max(0, T + 1)
else:
ans += max(0, 2 * K - T + 1)
print(ans)
| false | 30.769231 | [
"-if 3 * K < S:",
"- print(ans)",
"- exit()",
"-for X in range(K + 1):",
"- for Y in range(K + 1):",
"- Z = S - X - Y",
"- if Z < K + 1 and Z > -1:",
"- ans += 1",
"+for T in range(S - K, S + 1):",
"+ if T <= K:",
"+ ans += max(0, T + 1)",
"+ else... | false | 0.051382 | 0.050716 | 1.013136 | [
"s366331406",
"s207807612"
] |
u183509493 | p02819 | python | s532168997 | s178270500 | 28 | 25 | 9,400 | 9,044 | Accepted | Accepted | 10.71 | # Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
import sys
sys.setrecursionlimit(1000000)
x= int(eval(input()))
def prime_check(num,count):
if (num % count) != 0:
if num <= count**2:
print(num)
else:
prime_check(num,count+1)
else :
prime_check(num+1,2)
if x==2 :
print((2))
else:
prime_check(x,2)
| # Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
x= int(eval(input()))
def prime_check(num,count):
while True:
while num % count == 0:
num = num + 1
count = 2
if num <= count**2:
print(num)
break
else:
count = count + 1
if x==2 :
print((2))
else:
prime_check(x,2)
| 19 | 18 | 409 | 405 | # Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
import sys
sys.setrecursionlimit(1000000)
x = int(eval(input()))
def prime_check(num, count):
if (num % count) != 0:
if num <= count**2:
print(num)
else:
prime_check(num, count + 1)
else:
prime_check(num + 1, 2)
if x == 2:
print((2))
else:
prime_check(x, 2)
| # Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
x = int(eval(input()))
def prime_check(num, count):
while True:
while num % count == 0:
num = num + 1
count = 2
if num <= count**2:
print(num)
break
else:
count = count + 1
if x == 2:
print((2))
else:
prime_check(x, 2)
| false | 5.263158 | [
"-import sys",
"-",
"-sys.setrecursionlimit(1000000)",
"- if (num % count) != 0:",
"+ while True:",
"+ while num % count == 0:",
"+ num = num + 1",
"+ count = 2",
"+ break",
"- prime_check(num, count + 1)",
"- else:",
"- prime_... | false | 0.040006 | 0.108591 | 0.368414 | [
"s532168997",
"s178270500"
] |
u738898077 | p02833 | python | s935858096 | s306241859 | 163 | 17 | 38,444 | 2,940 | Accepted | Accepted | 89.57 | n = int(eval(input()))
ans = 0
a = 1
na = n
if n % 2 == 1:
print((0))
else:
# for i in range(3):
# n100 = n // 100
# n50 = n // 50
# n = n // 10
# ans += n + n50 - n100
# print(n,n50,n100)
# print(ans)
# for i in range(1,20):
# for j in range(1,40):
# ans += (n // ((5**j)*(10**i)))
# # ans += (n //(5*10**i))
# n10 = n // 10
# print(ans+n10)
for j in range(1,40):
ans += (n // ((5**j)*10))
n10 = n // 10
print((ans+n10))
# while na != 0:
# a *= na
# na -= 2
# # print(a)
# a = list(str(a))
# i = -1
# cnt = 0
# # print(a)
# while a[i] == "0":
# cnt += 1
# i -= 1
# print(cnt) | n = int(eval(input()))
ans = 0
if n % 2 == 1:
print((0))
exit()
for i in range(50):
if n >= 10*(5**(i)):
ans += n//(10*(5**(i)))
print(ans)
| 41 | 10 | 771 | 162 | n = int(eval(input()))
ans = 0
a = 1
na = n
if n % 2 == 1:
print((0))
else:
# for i in range(3):
# n100 = n // 100
# n50 = n // 50
# n = n // 10
# ans += n + n50 - n100
# print(n,n50,n100)
# print(ans)
# for i in range(1,20):
# for j in range(1,40):
# ans += (n // ((5**j)*(10**i)))
# # ans += (n //(5*10**i))
# n10 = n // 10
# print(ans+n10)
for j in range(1, 40):
ans += n // ((5**j) * 10)
n10 = n // 10
print((ans + n10))
# while na != 0:
# a *= na
# na -= 2
# # print(a)
# a = list(str(a))
# i = -1
# cnt = 0
# # print(a)
# while a[i] == "0":
# cnt += 1
# i -= 1
# print(cnt)
| n = int(eval(input()))
ans = 0
if n % 2 == 1:
print((0))
exit()
for i in range(50):
if n >= 10 * (5 ** (i)):
ans += n // (10 * (5 ** (i)))
print(ans)
| false | 75.609756 | [
"-a = 1",
"-na = n",
"-else:",
"- # for i in range(3):",
"- # n100 = n // 100",
"- # n50 = n // 50",
"- # n = n // 10",
"- # ans += n + n50 - n100",
"- # print(n,n50,n100)",
"- # print(ans)",
"- # for i in range(1,20):",
"- # for j in range(1,... | false | 0.041807 | 0.036405 | 1.148373 | [
"s935858096",
"s306241859"
] |
u077291787 | p02947 | python | s037801134 | s085222597 | 360 | 226 | 18,228 | 18,184 | Accepted | Accepted | 37.22 | # ABC137C - Green Bin
from collections import Counter
def main():
N = int(eval(input()))
A = Counter("".join(sorted(eval(input()))) for _ in range(N))
ans = sum(i * (i - 1) // 2 for i in list(A.values()))
print(ans)
if __name__ == "__main__":
main() | # ABC137C - Green Bin
import sys
input = sys.stdin.readline
from collections import Counter
def main():
N = int(eval(input()))
A = Counter("".join(sorted(eval(input()))) for _ in range(N))
ans = sum(i * (i - 1) // 2 for i in list(A.values()))
print(ans)
if __name__ == "__main__":
main() | 13 | 16 | 267 | 309 | # ABC137C - Green Bin
from collections import Counter
def main():
N = int(eval(input()))
A = Counter("".join(sorted(eval(input()))) for _ in range(N))
ans = sum(i * (i - 1) // 2 for i in list(A.values()))
print(ans)
if __name__ == "__main__":
main()
| # ABC137C - Green Bin
import sys
input = sys.stdin.readline
from collections import Counter
def main():
N = int(eval(input()))
A = Counter("".join(sorted(eval(input()))) for _ in range(N))
ans = sum(i * (i - 1) // 2 for i in list(A.values()))
print(ans)
if __name__ == "__main__":
main()
| false | 18.75 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.059938 | 0.038571 | 1.553959 | [
"s037801134",
"s085222597"
] |
u072053884 | p02362 | python | s989132394 | s562952989 | 520 | 460 | 8,256 | 8,288 | Accepted | Accepted | 11.54 | # Input acceptance
import sys
file_input = sys.stdin
V, E, r = map(int, file_input.readline().split())
edges = []
for line in file_input:
edges.append(tuple(map(int, line.split())))
# Bellman???Ford algorithm
distance = [float("inf")] * V
distance[r] = 0
for i in range(V):
notUpdated = True
for e in edges:
t = e[1]
temp_d = distance[e[0]] + e[2]
if temp_d < distance[t]:
distance[t] = temp_d
notUpdated = False
if notUpdated:
break
# Output
if i == V - 1 and V != 1:
print("NEGATIVE CYCLE")
else:
print(*map(lambda x: str(x).upper(), distance), sep = '\n')
| # Input acceptance
import sys
file_input = sys.stdin
V, E, r = map(int, file_input.readline().split())
edges = []
for line in file_input:
edges.append(tuple(map(int, line.split())))
# Bellman???Ford algorithm
distance = [float("inf")] * V
distance[r] = 0
notUpdated = True
for i in range(V - 1):
notUpdated = True
for s, t, w in edges:
temp_d = distance[s] + w
if temp_d < distance[t]:
distance[t] = temp_d
notUpdated = False
if notUpdated:
break
# Output
if notUpdated:
print(*map(lambda x: str(x).upper(), distance), sep = '\n')
else:
flag = True
for s, t, w in edges:
temp_d = distance[s] + w
if temp_d < distance[t]:
print("NEGATIVE CYCLE")
flag = False
break
if flag:
print(*map(lambda x: str(x).upper(), distance), sep = '\n')
| 34 | 42 | 680 | 922 | # Input acceptance
import sys
file_input = sys.stdin
V, E, r = map(int, file_input.readline().split())
edges = []
for line in file_input:
edges.append(tuple(map(int, line.split())))
# Bellman???Ford algorithm
distance = [float("inf")] * V
distance[r] = 0
for i in range(V):
notUpdated = True
for e in edges:
t = e[1]
temp_d = distance[e[0]] + e[2]
if temp_d < distance[t]:
distance[t] = temp_d
notUpdated = False
if notUpdated:
break
# Output
if i == V - 1 and V != 1:
print("NEGATIVE CYCLE")
else:
print(*map(lambda x: str(x).upper(), distance), sep="\n")
| # Input acceptance
import sys
file_input = sys.stdin
V, E, r = map(int, file_input.readline().split())
edges = []
for line in file_input:
edges.append(tuple(map(int, line.split())))
# Bellman???Ford algorithm
distance = [float("inf")] * V
distance[r] = 0
notUpdated = True
for i in range(V - 1):
notUpdated = True
for s, t, w in edges:
temp_d = distance[s] + w
if temp_d < distance[t]:
distance[t] = temp_d
notUpdated = False
if notUpdated:
break
# Output
if notUpdated:
print(*map(lambda x: str(x).upper(), distance), sep="\n")
else:
flag = True
for s, t, w in edges:
temp_d = distance[s] + w
if temp_d < distance[t]:
print("NEGATIVE CYCLE")
flag = False
break
if flag:
print(*map(lambda x: str(x).upper(), distance), sep="\n")
| false | 19.047619 | [
"-for i in range(V):",
"+notUpdated = True",
"+for i in range(V - 1):",
"- for e in edges:",
"- t = e[1]",
"- temp_d = distance[e[0]] + e[2]",
"+ for s, t, w in edges:",
"+ temp_d = distance[s] + w",
"-if i == V - 1 and V != 1:",
"- print(\"NEGATIVE CYCLE\")",
"+if ... | false | 0.04241 | 0.042966 | 0.98707 | [
"s989132394",
"s562952989"
] |
u745097373 | p03161 | python | s549262168 | s497580210 | 1,964 | 383 | 13,928 | 68,956 | Accepted | Accepted | 80.5 | def solve():
h, k = read()
result = think(h, k)
write(result)
def read():
n, k = read_int(2)
return read_int(n), k
def read_int(n):
return list([int(x) for x in read_line().split(' ')])[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(h, k):
cost = [0 for x in range(len(h))]
for dst in range(1, len(h)):
start_point = max(0, dst - k)
cost[dst] = min([cost[src] + abs(h[src] - h[dst]) for src in range(start_point, dst)])
return cost[len(h) - 1]
def write(result):
print(result)
if __name__ == '__main__':
solve() | import unittest
class TestB(unittest.TestCase):
def test_1(self):
self.assertEqual(
think(3, [10, 30, 40, 50, 20]),
30
)
def test_2(self):
self.assertEqual(
think(1, [10, 20, 10]),
20
)
def test_3(self):
self.assertEqual(
think(100, [10, 10]),
0
)
def test_4(self):
self.assertEqual(
think(4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]),
40
)
def solve():
k, h = read()
result = think(k, h)
write(result)
def read():
n, k = read_int(2)
return k, read_int(n)
def read_int(n):
return read_type(int, n, sep=' ')
def read_float(n):
return read_type(float, n, sep=' ')
def read_type(t, n, sep):
return list([t(x) for x in read_line().split(sep)])[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(k, h):
n_max = 10 ** 5
h_max = 10 ** 4
dp = [h_max * n_max for _ in range(len(h))]
dp[0] = 0
for i in range(1, len(dp)):
for j in range(1, k + 1):
if i - j < 0:
break
dp[i] = min(
dp[i],
dp[i - j] + abs(h[i] - h[i - j])
)
return dp[len(h) - 1]
def write(result):
print(result)
if __name__ == '__main__':
# unittest.main()
solve() | 36 | 83 | 703 | 1,575 | def solve():
h, k = read()
result = think(h, k)
write(result)
def read():
n, k = read_int(2)
return read_int(n), k
def read_int(n):
return list([int(x) for x in read_line().split(" ")])[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(h, k):
cost = [0 for x in range(len(h))]
for dst in range(1, len(h)):
start_point = max(0, dst - k)
cost[dst] = min(
[cost[src] + abs(h[src] - h[dst]) for src in range(start_point, dst)]
)
return cost[len(h) - 1]
def write(result):
print(result)
if __name__ == "__main__":
solve()
| import unittest
class TestB(unittest.TestCase):
def test_1(self):
self.assertEqual(think(3, [10, 30, 40, 50, 20]), 30)
def test_2(self):
self.assertEqual(think(1, [10, 20, 10]), 20)
def test_3(self):
self.assertEqual(think(100, [10, 10]), 0)
def test_4(self):
self.assertEqual(think(4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]), 40)
def solve():
k, h = read()
result = think(k, h)
write(result)
def read():
n, k = read_int(2)
return k, read_int(n)
def read_int(n):
return read_type(int, n, sep=" ")
def read_float(n):
return read_type(float, n, sep=" ")
def read_type(t, n, sep):
return list([t(x) for x in read_line().split(sep)])[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(k, h):
n_max = 10**5
h_max = 10**4
dp = [h_max * n_max for _ in range(len(h))]
dp[0] = 0
for i in range(1, len(dp)):
for j in range(1, k + 1):
if i - j < 0:
break
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
return dp[len(h) - 1]
def write(result):
print(result)
if __name__ == "__main__":
# unittest.main()
solve()
| false | 56.626506 | [
"+import unittest",
"+",
"+",
"+class TestB(unittest.TestCase):",
"+ def test_1(self):",
"+ self.assertEqual(think(3, [10, 30, 40, 50, 20]), 30)",
"+",
"+ def test_2(self):",
"+ self.assertEqual(think(1, [10, 20, 10]), 20)",
"+",
"+ def test_3(self):",
"+ self.ass... | false | 0.115679 | 0.220229 | 0.525265 | [
"s549262168",
"s497580210"
] |
u389910364 | p03297 | python | s343663805 | s574122501 | 158 | 38 | 13,668 | 5,328 | Accepted | Accepted | 75.95 | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]
def solve(A, B, C, D):
if B > D:
return False
if A < B:
return False
if C >= B:
return True
# C < B <= D
# A から D を無限に足してったとき、mod B が C より大きくなったらだめ
p = gcd(D, B) # p ごとの値しか取らない
if p < B - C:
return False
if (B - A - 1) % p < B - C - 1:
return False
return True
ans = []
for a, b, c, d in ABCD:
ans.append('Yes' if solve(a, b, c, d) else 'No')
print(*ans, sep='\n')
| import os
import sys
from fractions import gcd
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]
def solve(A, B, C, D):
if B > D:
return False
if A < B:
return False
if C >= B:
return True
# C < B <= D
# A から D を無限に足してったとき、mod B が C より大きくなったらだめ
p = gcd(D, B) # p ごとの値しか取らない
if p < B - C:
return False
if (B - A - 1) % p < B - C - 1:
return False
return True
ans = []
for a, b, c, d in ABCD:
ans.append('Yes' if solve(a, b, c, d) else 'No')
print(*ans, sep='\n')
| 51 | 37 | 1,108 | 785 | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]
def solve(A, B, C, D):
if B > D:
return False
if A < B:
return False
if C >= B:
return True
# C < B <= D
# A から D を無限に足してったとき、mod B が C より大きくなったらだめ
p = gcd(D, B) # p ごとの値しか取らない
if p < B - C:
return False
if (B - A - 1) % p < B - C - 1:
return False
return True
ans = []
for a, b, c, d in ABCD:
ans.append("Yes" if solve(a, b, c, d) else "No")
print(*ans, sep="\n")
| import os
import sys
from fractions import gcd
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]
def solve(A, B, C, D):
if B > D:
return False
if A < B:
return False
if C >= B:
return True
# C < B <= D
# A から D を無限に足してったとき、mod B が C より大きくなったらだめ
p = gcd(D, B) # p ごとの値しか取らない
if p < B - C:
return False
if (B - A - 1) % p < B - C - 1:
return False
return True
ans = []
for a, b, c, d in ABCD:
ans.append("Yes" if solve(a, b, c, d) else "No")
print(*ans, sep="\n")
| false | 27.45098 | [
"-import bisect",
"-import heapq",
"-import itertools",
"-import math",
"-import operator",
"-import re",
"-import string",
"-from collections import Counter, deque, defaultdict",
"-from copy import deepcopy",
"-from decimal import Decimal",
"-from functools import lru_cache, reduce",
"-from o... | false | 0.091141 | 0.060537 | 1.505543 | [
"s343663805",
"s574122501"
] |
u844005364 | p03087 | python | s523572805 | s483560793 | 526 | 392 | 39,272 | 11,844 | Accepted | Accepted | 25.48 | import sys
input = sys.stdin.readline
import numpy as np
import bisect
left = bisect.bisect_left
right = bisect.bisect_right
def question():
n, q = list(map(int, input().split()))
s = eval(input())
lr = [list(map(int, input().split())) for i in range(q)]
a = [i for i in range(n-1) if s[i:i+2]=="AC"]
for i in range(q):
left_index = left(a, lr[i][0]-1)
right_index = right(a, lr[i][1]-2)
print((right_index - left_index))
question() | n, q = map(int, input().split())
arr = input()
ac_count = [0]
ac = 0
for i in range(1, n):
if arr[i-1:i+1] == "AC":
ac += 1
ac_count.append(ac)
ans = []
for _ in range(q):
left, right = map(int, input().split())
ans.append(ac_count[right-1] - ac_count[left-1])
print(*ans, sep="\n")
| 19 | 17 | 489 | 326 | import sys
input = sys.stdin.readline
import numpy as np
import bisect
left = bisect.bisect_left
right = bisect.bisect_right
def question():
n, q = list(map(int, input().split()))
s = eval(input())
lr = [list(map(int, input().split())) for i in range(q)]
a = [i for i in range(n - 1) if s[i : i + 2] == "AC"]
for i in range(q):
left_index = left(a, lr[i][0] - 1)
right_index = right(a, lr[i][1] - 2)
print((right_index - left_index))
question()
| n, q = map(int, input().split())
arr = input()
ac_count = [0]
ac = 0
for i in range(1, n):
if arr[i - 1 : i + 1] == "AC":
ac += 1
ac_count.append(ac)
ans = []
for _ in range(q):
left, right = map(int, input().split())
ans.append(ac_count[right - 1] - ac_count[left - 1])
print(*ans, sep="\n")
| false | 10.526316 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-import numpy as np",
"-import bisect",
"-",
"-left = bisect.bisect_left",
"-right = bisect.bisect_right",
"-",
"-",
"-def question():",
"- n, q = list(map(int, input().split()))",
"- s = eval(input())",
"- lr = [list(map(int, in... | false | 0.048593 | 0.044224 | 1.09878 | [
"s523572805",
"s483560793"
] |
u506858457 | p02744 | python | s564909401 | s577971368 | 193 | 144 | 25,716 | 4,340 | Accepted | Accepted | 25.39 | n=int(eval(input()))
dic={0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j'}
#標準形の文字列は同型の文字列の中で辞書順最小であることから、新たに付け加えるべき文字は順にa,b,c...となる
ans=[['a',1]]
for i in range(1,n):
tmp=[]
for prev,val in ans:
for j in range(val+1):
#(今見ている文字列に使われている文字の種類数+1)種類の文字を付け加える
if j!=val:
#今見ている文字列に使われている文字を付け加えるとき、文字の種類数は増加しない
tmp.append([prev+dic[j],val])
else:
#今見ている文字列に使われていない文字を付け加えるとき、文字の種類数が増加する
tmp.append([prev+dic[j],val+1])
ans=tmp
ans=sorted(ans,key=lambda x:x[0])
#生成した標準形の文字列を辞書順昇順に並べ替える
for i in range(len(ans)):
print((ans[i][0])) | import sys
sys.setrecursionlimit(100000)
def dfs(s, mx):
if len(s) == N:
print(s)
return 0
for c in range(ord("a"), mx + 2):
t = s
t += chr(c)
dfs(t, max(mx, c))
N = int(eval(input()))
dfs("", ord("a") - 1) | 20 | 14 | 604 | 263 | n = int(eval(input()))
dic = {0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g", 7: "h", 8: "i", 9: "j"}
# 標準形の文字列は同型の文字列の中で辞書順最小であることから、新たに付け加えるべき文字は順にa,b,c...となる
ans = [["a", 1]]
for i in range(1, n):
tmp = []
for prev, val in ans:
for j in range(val + 1):
# (今見ている文字列に使われている文字の種類数+1)種類の文字を付け加える
if j != val:
# 今見ている文字列に使われている文字を付け加えるとき、文字の種類数は増加しない
tmp.append([prev + dic[j], val])
else:
# 今見ている文字列に使われていない文字を付け加えるとき、文字の種類数が増加する
tmp.append([prev + dic[j], val + 1])
ans = tmp
ans = sorted(ans, key=lambda x: x[0])
# 生成した標準形の文字列を辞書順昇順に並べ替える
for i in range(len(ans)):
print((ans[i][0]))
| import sys
sys.setrecursionlimit(100000)
def dfs(s, mx):
if len(s) == N:
print(s)
return 0
for c in range(ord("a"), mx + 2):
t = s
t += chr(c)
dfs(t, max(mx, c))
N = int(eval(input()))
dfs("", ord("a") - 1)
| false | 30 | [
"-n = int(eval(input()))",
"-dic = {0: \"a\", 1: \"b\", 2: \"c\", 3: \"d\", 4: \"e\", 5: \"f\", 6: \"g\", 7: \"h\", 8: \"i\", 9: \"j\"}",
"-# 標準形の文字列は同型の文字列の中で辞書順最小であることから、新たに付け加えるべき文字は順にa,b,c...となる",
"-ans = [[\"a\", 1]]",
"-for i in range(1, n):",
"- tmp = []",
"- for prev, val in ans:",
"- ... | false | 0.038289 | 0.217465 | 0.176068 | [
"s564909401",
"s577971368"
] |
u955125992 | p02838 | python | s250003326 | s221752428 | 684 | 339 | 122,936 | 48,824 | Accepted | Accepted | 50.44 | n = int(eval(input()))
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
m = 1
for i in range(60):
#mbit目に情報を持つものをすべて足し合わせる。
#m = 1: 1bit目(2^0の位)、m=10: 2bit目(2^1の位)
#sum = sigma(1の数 * 2^(m-1))
one = sum(a_e & m for a_e in a)
one //= m
zero = n - one
ans += one * zero * m
ans %= MOD
m <<= 1
print(ans) | import numpy as np
n = int(eval(input()))
a = np.array(list(map(int, input().split())))
MOD = 10 ** 9 + 7
ans = 0
for i in range(60):
one = np.count_nonzero(a >> i & 1)
zero = n - one
ans += one * zero * 2 ** i
ans %= MOD
print(ans) | 20 | 15 | 370 | 260 | n = int(eval(input()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0
m = 1
for i in range(60):
# mbit目に情報を持つものをすべて足し合わせる。
# m = 1: 1bit目(2^0の位)、m=10: 2bit目(2^1の位)
# sum = sigma(1の数 * 2^(m-1))
one = sum(a_e & m for a_e in a)
one //= m
zero = n - one
ans += one * zero * m
ans %= MOD
m <<= 1
print(ans)
| import numpy as np
n = int(eval(input()))
a = np.array(list(map(int, input().split())))
MOD = 10**9 + 7
ans = 0
for i in range(60):
one = np.count_nonzero(a >> i & 1)
zero = n - one
ans += one * zero * 2**i
ans %= MOD
print(ans)
| false | 25 | [
"+import numpy as np",
"+",
"-a = list(map(int, input().split()))",
"+a = np.array(list(map(int, input().split())))",
"-m = 1",
"- # mbit目に情報を持つものをすべて足し合わせる。",
"- # m = 1: 1bit目(2^0の位)、m=10: 2bit目(2^1の位)",
"- # sum = sigma(1の数 * 2^(m-1))",
"- one = sum(a_e & m for a_e in a)",
"- one... | false | 0.065085 | 0.792755 | 0.0821 | [
"s250003326",
"s221752428"
] |
u344030307 | p02923 | python | s214639104 | s234336129 | 92 | 75 | 20,516 | 20,516 | Accepted | Accepted | 18.48 | n = int(eval(input()))
h = list(map(int, input().split()))
higher = [0]
move = [0]
for i in range(1, n):
if h[i-1] < h[i]:
m = i - higher[len(higher) - 1] - 1
move.append(m)
higher.append(i)
move.append(len(h) - 1 - higher[len(higher) - 1])
print((max(move))) | n = int(eval(input()))
h = list(map(int, input().split()))
move = [0]
cnt = 0
for i in range(n-1):
if h[i] >= h[i+1]:
cnt += 1
if i == n-2:
move.append(cnt)
else:
move.append(cnt)
cnt = 0
print((max(move))) | 16 | 17 | 285 | 244 | n = int(eval(input()))
h = list(map(int, input().split()))
higher = [0]
move = [0]
for i in range(1, n):
if h[i - 1] < h[i]:
m = i - higher[len(higher) - 1] - 1
move.append(m)
higher.append(i)
move.append(len(h) - 1 - higher[len(higher) - 1])
print((max(move)))
| n = int(eval(input()))
h = list(map(int, input().split()))
move = [0]
cnt = 0
for i in range(n - 1):
if h[i] >= h[i + 1]:
cnt += 1
if i == n - 2:
move.append(cnt)
else:
move.append(cnt)
cnt = 0
print((max(move)))
| false | 5.882353 | [
"-higher = [0]",
"-for i in range(1, n):",
"- if h[i - 1] < h[i]:",
"- m = i - higher[len(higher) - 1] - 1",
"- move.append(m)",
"- higher.append(i)",
"-move.append(len(h) - 1 - higher[len(higher) - 1])",
"+cnt = 0",
"+for i in range(n - 1):",
"+ if h[i] >= h[i + 1]:",
... | false | 0.039772 | 0.040066 | 0.992663 | [
"s214639104",
"s234336129"
] |
u404676457 | p03147 | python | s816700702 | s191398357 | 198 | 19 | 12,500 | 3,064 | Accepted | Accepted | 90.4 | import numpy as np
n = int(eval(input()))
s = np.array(list(map(int, input().split())), dtype='int64')
count = 0
sidx = 0
ls = [s]
count = 0
while len(ls) != 0:
l = ls.pop()
mins = min(l)
l -= mins
count += mins
tmpl = np.array([], dtype='int64')
for i in l:
if i == 0:
if len(tmpl) != 0:
ls.append(tmpl)
tmpl = np.array([], dtype='int64')
else:
tmpl = np.append(tmpl, i)
else:
if len(tmpl) != 0:
ls.append(tmpl)
print((int(count))) | n = int(eval(input()))
s = list(map(int, input().split()))
count = 0
sidx = 0
ls = [s]
count = 0
while len(ls) != 0:
l = ls.pop()
mins = min(l)
for i in range(len(l)):
l[i] -= mins
count += mins
tmpl = []
for i in l:
if i == 0:
if len(tmpl) != 0:
ls.append(tmpl)
tmpl = []
else:
tmpl.append(i)
else:
if len(tmpl) != 0:
ls.append(tmpl)
print(count) | 26 | 26 | 567 | 492 | import numpy as np
n = int(eval(input()))
s = np.array(list(map(int, input().split())), dtype="int64")
count = 0
sidx = 0
ls = [s]
count = 0
while len(ls) != 0:
l = ls.pop()
mins = min(l)
l -= mins
count += mins
tmpl = np.array([], dtype="int64")
for i in l:
if i == 0:
if len(tmpl) != 0:
ls.append(tmpl)
tmpl = np.array([], dtype="int64")
else:
tmpl = np.append(tmpl, i)
else:
if len(tmpl) != 0:
ls.append(tmpl)
print((int(count)))
| n = int(eval(input()))
s = list(map(int, input().split()))
count = 0
sidx = 0
ls = [s]
count = 0
while len(ls) != 0:
l = ls.pop()
mins = min(l)
for i in range(len(l)):
l[i] -= mins
count += mins
tmpl = []
for i in l:
if i == 0:
if len(tmpl) != 0:
ls.append(tmpl)
tmpl = []
else:
tmpl.append(i)
else:
if len(tmpl) != 0:
ls.append(tmpl)
print(count)
| false | 0 | [
"-import numpy as np",
"-",
"-s = np.array(list(map(int, input().split())), dtype=\"int64\")",
"+s = list(map(int, input().split()))",
"- l -= mins",
"+ for i in range(len(l)):",
"+ l[i] -= mins",
"- tmpl = np.array([], dtype=\"int64\")",
"+ tmpl = []",
"- tmpl = np.a... | false | 0.367886 | 0.037851 | 9.719411 | [
"s816700702",
"s191398357"
] |
u968166680 | p03752 | python | s083056196 | s863090450 | 79 | 32 | 3,188 | 3,064 | Accepted | Accepted | 59.49 | N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 1 << 60
for i in range(1 << N):
if i % 2 == 0:
continue
selected = [j for j in range(N) if i & (1 << j)]
if len(selected) != K:
continue
h_max = a[0]
cost = 0
for j in range(1, N):
if j in selected:
if a[j] <= h_max:
cost += h_max + 1 - a[j]
h_max += 1
else:
h_max = a[j]
else:
h_max = max(h_max, a[j])
ans = min(ans, cost)
print(ans) | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
N, K, *A = list(map(int, read().split()))
ans = INF
for bit in range(1 << N):
if (not (bit & 1)) or bin(bit).count('1') != K:
continue
total = 0
max_height = A[0]
for i, a in enumerate(A[1:], 1):
if a <= max_height:
if bit & (1 << i):
total += max_height - a + 1
max_height += 1
else:
max_height = a
if ans > total:
ans = total
print(ans)
return
if __name__ == '__main__':
main()
| 27 | 37 | 596 | 756 | N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 1 << 60
for i in range(1 << N):
if i % 2 == 0:
continue
selected = [j for j in range(N) if i & (1 << j)]
if len(selected) != K:
continue
h_max = a[0]
cost = 0
for j in range(1, N):
if j in selected:
if a[j] <= h_max:
cost += h_max + 1 - a[j]
h_max += 1
else:
h_max = a[j]
else:
h_max = max(h_max, a[j])
ans = min(ans, cost)
print(ans)
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def main():
N, K, *A = list(map(int, read().split()))
ans = INF
for bit in range(1 << N):
if (not (bit & 1)) or bin(bit).count("1") != K:
continue
total = 0
max_height = A[0]
for i, a in enumerate(A[1:], 1):
if a <= max_height:
if bit & (1 << i):
total += max_height - a + 1
max_height += 1
else:
max_height = a
if ans > total:
ans = total
print(ans)
return
if __name__ == "__main__":
main()
| false | 27.027027 | [
"-N, K = list(map(int, input().split()))",
"-a = list(map(int, input().split()))",
"-ans = 1 << 60",
"-for i in range(1 << N):",
"- if i % 2 == 0:",
"- continue",
"- selected = [j for j in range(N) if i & (1 << j)]",
"- if len(selected) != K:",
"- continue",
"- h_max = a[... | false | 0.097333 | 0.007693 | 12.651655 | [
"s083056196",
"s863090450"
] |
u422104747 | p03331 | python | s767297094 | s174602279 | 346 | 17 | 3,060 | 2,940 | Accepted | Accepted | 95.09 | n=int(eval(input()))
res=100000
for i in range(1,n):
j=n-i
s=0
for c in str(i):
s+=int(c)
for c in str(j):
s+=int(c)
res=min(res,s)
print(res) | n=int(eval(input()))
s=0
while n>0:
s+=n%10
n//=10
if s==1:
print((10))
else:
print(s) | 11 | 9 | 182 | 94 | n = int(eval(input()))
res = 100000
for i in range(1, n):
j = n - i
s = 0
for c in str(i):
s += int(c)
for c in str(j):
s += int(c)
res = min(res, s)
print(res)
| n = int(eval(input()))
s = 0
while n > 0:
s += n % 10
n //= 10
if s == 1:
print((10))
else:
print(s)
| false | 18.181818 | [
"-res = 100000",
"-for i in range(1, n):",
"- j = n - i",
"- s = 0",
"- for c in str(i):",
"- s += int(c)",
"- for c in str(j):",
"- s += int(c)",
"- res = min(res, s)",
"-print(res)",
"+s = 0",
"+while n > 0:",
"+ s += n % 10",
"+ n //= 10",
"+if s == ... | false | 0.263377 | 0.035366 | 7.447148 | [
"s767297094",
"s174602279"
] |
u970197315 | p02787 | python | s675679082 | s527937302 | 1,155 | 491 | 289,544 | 221,196 | Accepted | Accepted | 57.49 | h,n=list(map(int,input().split()))
a,b=[],[]
for i in range(n):
aa,bb=list(map(int,input().split()))
a.append(aa)
b.append(bb)
inf=float("inf")
dp=[[inf]*(h+1) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
for j in range(h+1):
dp[i+1][j]=min(dp[i+1][j],dp[i][j])
dp[i+1][min(h,j+a[i])]=min(dp[i+1][j]+b[i],dp[i+1][min(h,j+a[i])])
print((dp[n][h])) | h,n=list(map(int,input().split()))
a,b=[],[]
for i in range(n):
aa,bb=list(map(int,input().split()))
a.append(aa)
b.append(bb)
inf=float("inf")
dp=[[inf]*(h+1) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
for j in range(h+1):
dp[i+1][j]=min(dp[i+1][j],dp[i][j])
dp[i+1][min(j+a[i],h)]=min(dp[i+1][j]+b[i],dp[i+1][min(j+a[i],h)])
print((dp[n][h]))
| 15 | 14 | 373 | 372 | h, n = list(map(int, input().split()))
a, b = [], []
for i in range(n):
aa, bb = list(map(int, input().split()))
a.append(aa)
b.append(bb)
inf = float("inf")
dp = [[inf] * (h + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(h + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
dp[i + 1][min(h, j + a[i])] = min(
dp[i + 1][j] + b[i], dp[i + 1][min(h, j + a[i])]
)
print((dp[n][h]))
| h, n = list(map(int, input().split()))
a, b = [], []
for i in range(n):
aa, bb = list(map(int, input().split()))
a.append(aa)
b.append(bb)
inf = float("inf")
dp = [[inf] * (h + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(h + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
dp[i + 1][min(j + a[i], h)] = min(
dp[i + 1][j] + b[i], dp[i + 1][min(j + a[i], h)]
)
print((dp[n][h]))
| false | 6.666667 | [
"- dp[i + 1][min(h, j + a[i])] = min(",
"- dp[i + 1][j] + b[i], dp[i + 1][min(h, j + a[i])]",
"+ dp[i + 1][min(j + a[i], h)] = min(",
"+ dp[i + 1][j] + b[i], dp[i + 1][min(j + a[i], h)]"
] | false | 0.417009 | 0.286854 | 1.453734 | [
"s675679082",
"s527937302"
] |
u823885866 | p03238 | python | s867528155 | s815715515 | 116 | 29 | 27,076 | 9,084 | Accepted | Accepted | 75 | import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
if ri() == 1:
print('Hello World')
exit()
else:
print((ri()+ri()))
| import sys
ri = lambda: int(sys.stdin.readline())
if ri() == 1:
print('Hello World')
exit()
else:
print((ri()+ri())) | 33 | 9 | 501 | 130 | import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float("inf")
mod = 10**9 + 7
if ri() == 1:
print("Hello World")
exit()
else:
print((ri() + ri()))
| import sys
ri = lambda: int(sys.stdin.readline())
if ri() == 1:
print("Hello World")
exit()
else:
print((ri() + ri()))
| false | 72.727273 | [
"-import math",
"-import itertools",
"-import collections",
"-import heapq",
"-import re",
"-import numpy as np",
"-rr = lambda: sys.stdin.readline().rstrip()",
"-rs = lambda: sys.stdin.buffer.readline().split()",
"-rm = lambda: list(map(int, sys.stdin.buffer.readline().split()))",
"-rl = lambda: ... | false | 0.039904 | 0.03667 | 1.088172 | [
"s867528155",
"s815715515"
] |
u133936772 | p03361 | python | s608145837 | s418589729 | 23 | 18 | 3,064 | 3,064 | Accepted | Accepted | 21.74 | h,w=list(map(int,input().split()))
g=[eval(input()) for _ in range(h)]
for x in range(h):
for y in range(w):
if g[x][y]=='#':
f=1
for dx,dy in ((1,0),(0,1),(-1,0),(0,-1)):
nx,ny=x+dx,y+dy
if nx<0 or nx>=h or ny<0 or ny>=w:
continue
elif g[nx][ny]=='#':
f=0
if f:
print('No')
break
else:
continue
break
else:
print('Yes') | h,w=list(map(int,input().split()))
g=[eval(input()) for _ in range(h)]
for x in range(1,h-1):
for y in range(1,w-1):
if g[x][y]=='#' and all(g[x+dx][y+dy]=='.' for dx,dy in ((1,0),(0,1),(-1,0),(0,-1))):
print('No'); exit()
print('Yes') | 20 | 7 | 421 | 241 | h, w = list(map(int, input().split()))
g = [eval(input()) for _ in range(h)]
for x in range(h):
for y in range(w):
if g[x][y] == "#":
f = 1
for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
nx, ny = x + dx, y + dy
if nx < 0 or nx >= h or ny < 0 or ny >= w:
continue
elif g[nx][ny] == "#":
f = 0
if f:
print("No")
break
else:
continue
break
else:
print("Yes")
| h, w = list(map(int, input().split()))
g = [eval(input()) for _ in range(h)]
for x in range(1, h - 1):
for y in range(1, w - 1):
if g[x][y] == "#" and all(
g[x + dx][y + dy] == "." for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1))
):
print("No")
exit()
print("Yes")
| false | 65 | [
"-for x in range(h):",
"- for y in range(w):",
"- if g[x][y] == \"#\":",
"- f = 1",
"- for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):",
"- nx, ny = x + dx, y + dy",
"- if nx < 0 or nx >= h or ny < 0 or ny >= w:",
"- co... | false | 0.073595 | 0.042814 | 1.718931 | [
"s608145837",
"s418589729"
] |
u342869120 | p03488 | python | s195885540 | s617691971 | 1,440 | 230 | 467,296 | 81,156 | Accepted | Accepted | 84.03 |
def YesNo(b):
print(("Yes" if b else "No"))
def solve(v, l, ini):
ml = 8000*2+1
dp = [[False]*ml for i in range(len(l)+1)]
for i in range(len(ini)):
dp[0][ini[i]+8000] = True
for i in range(1, len(l)+1):
for j in range(ml):
if (j+l[i-1]) < ml and dp[i-1][j]:
dp[i][j+l[i-1]] = True
if (j-l[i-1]) >= 0 and dp[i-1][j]:
dp[i][j-l[i-1]] = True
return dp[len(l)][v+8000]
s = eval(input())
x, y = list(map(int, input().split()))
si = 0
while si < len(s) and s[si] == 'F':
si += 1
s = s[si:]
if len(s) == 0:
YesNo(x == si and y == 0)
else:
f = s.split('T')[1:]
xl, yl = [0], [0]
for i in range(len(f)):
if len(f[i]) == 0:
continue
if i % 2 == 0:
yl.append(len(f[i]))
else:
xl.append(len(f[i]))
YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))
| def YesNo(b):
print(("Yes" if b else "No"))
def solve(l, t0, t):
s = {t0}
for v in l:
s, ps = set(), s
for a in ps:
s.add(a+v)
s.add(a-v)
return t in s
s = eval(input())
x, y = list(map(int, input().split()))
f = s.split('T')
x0 = len(f[0])
xl = [len(v) for v in f[2::2]]
yl = [len(v) for v in f[1::2]]
YesNo(solve(xl, x0, x) and solve(yl, 0, y)) | 40 | 23 | 963 | 416 | def YesNo(b):
print(("Yes" if b else "No"))
def solve(v, l, ini):
ml = 8000 * 2 + 1
dp = [[False] * ml for i in range(len(l) + 1)]
for i in range(len(ini)):
dp[0][ini[i] + 8000] = True
for i in range(1, len(l) + 1):
for j in range(ml):
if (j + l[i - 1]) < ml and dp[i - 1][j]:
dp[i][j + l[i - 1]] = True
if (j - l[i - 1]) >= 0 and dp[i - 1][j]:
dp[i][j - l[i - 1]] = True
return dp[len(l)][v + 8000]
s = eval(input())
x, y = list(map(int, input().split()))
si = 0
while si < len(s) and s[si] == "F":
si += 1
s = s[si:]
if len(s) == 0:
YesNo(x == si and y == 0)
else:
f = s.split("T")[1:]
xl, yl = [0], [0]
for i in range(len(f)):
if len(f[i]) == 0:
continue
if i % 2 == 0:
yl.append(len(f[i]))
else:
xl.append(len(f[i]))
YesNo(solve(x, xl, [si]) and solve(y, yl[1:], [-yl[0], yl[0]]))
| def YesNo(b):
print(("Yes" if b else "No"))
def solve(l, t0, t):
s = {t0}
for v in l:
s, ps = set(), s
for a in ps:
s.add(a + v)
s.add(a - v)
return t in s
s = eval(input())
x, y = list(map(int, input().split()))
f = s.split("T")
x0 = len(f[0])
xl = [len(v) for v in f[2::2]]
yl = [len(v) for v in f[1::2]]
YesNo(solve(xl, x0, x) and solve(yl, 0, y))
| false | 42.5 | [
"-def solve(v, l, ini):",
"- ml = 8000 * 2 + 1",
"- dp = [[False] * ml for i in range(len(l) + 1)]",
"- for i in range(len(ini)):",
"- dp[0][ini[i] + 8000] = True",
"- for i in range(1, len(l) + 1):",
"- for j in range(ml):",
"- if (j + l[i - 1]) < ml and dp[i - 1]... | false | 0.048739 | 0.082195 | 0.592962 | [
"s195885540",
"s617691971"
] |
u723792785 | p02947 | python | s637224726 | s928310120 | 1,921 | 375 | 136,708 | 19,400 | Accepted | Accepted | 80.48 | import math
import collections
n=int(eval(input()))
s=[sorted(eval(input())) for _ in range(n)]
c=[str(collections.Counter(s[i])) for i in range(n)]
k=list(collections.Counter(c).values())
ans = 0
for i in k:
if i >= 2:
ans += math.factorial(i)//2//math.factorial(i-2)
print(ans) | n=int(eval(input()))
s=["".join(sorted(eval(input()))) for _ in range(n)]
d={}
ans = 0
for i in s:
k = d.get(i, 0)
ans += k
if k == 0:
d[i] = 1
else:
d[i] += 1
print(ans) | 11 | 12 | 274 | 177 | import math
import collections
n = int(eval(input()))
s = [sorted(eval(input())) for _ in range(n)]
c = [str(collections.Counter(s[i])) for i in range(n)]
k = list(collections.Counter(c).values())
ans = 0
for i in k:
if i >= 2:
ans += math.factorial(i) // 2 // math.factorial(i - 2)
print(ans)
| n = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(n)]
d = {}
ans = 0
for i in s:
k = d.get(i, 0)
ans += k
if k == 0:
d[i] = 1
else:
d[i] += 1
print(ans)
| false | 8.333333 | [
"-import math",
"-import collections",
"-",
"-s = [sorted(eval(input())) for _ in range(n)]",
"-c = [str(collections.Counter(s[i])) for i in range(n)]",
"-k = list(collections.Counter(c).values())",
"+s = [\"\".join(sorted(eval(input()))) for _ in range(n)]",
"+d = {}",
"-for i in k:",
"- if i ... | false | 0.036656 | 0.035754 | 1.025231 | [
"s637224726",
"s928310120"
] |
u438621426 | p02922 | python | s227757275 | s780034750 | 188 | 171 | 38,636 | 38,384 | Accepted | Accepted | 9.04 | from sys import stdin
import queue
import sys
import math
a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1))))
| import math
a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1)))) | 7 | 4 | 124 | 75 | from sys import stdin
import queue
import sys
import math
a, b = list(map(int, input().split()))
print((math.ceil((b - 1) / (a - 1))))
| import math
a, b = list(map(int, input().split()))
print((math.ceil((b - 1) / (a - 1))))
| false | 42.857143 | [
"-from sys import stdin",
"-import queue",
"-import sys"
] | false | 0.037966 | 0.045736 | 0.830112 | [
"s227757275",
"s780034750"
] |
u816631826 | p03556 | python | s131827096 | s100377469 | 54 | 17 | 2,940 | 2,940 | Accepted | Accepted | 68.52 | import math
n = int(eval(input()))
while(n>0):
r = int(math.sqrt(n))
if(r*r == n):
print(n)
exit()
else:
n-=1 | n=int(eval(input()))
import math
print((pow(int(math.sqrt(n)),2))) | 9 | 3 | 129 | 60 | import math
n = int(eval(input()))
while n > 0:
r = int(math.sqrt(n))
if r * r == n:
print(n)
exit()
else:
n -= 1
| n = int(eval(input()))
import math
print((pow(int(math.sqrt(n)), 2)))
| false | 66.666667 | [
"+n = int(eval(input()))",
"-n = int(eval(input()))",
"-while n > 0:",
"- r = int(math.sqrt(n))",
"- if r * r == n:",
"- print(n)",
"- exit()",
"- else:",
"- n -= 1",
"+print((pow(int(math.sqrt(n)), 2)))"
] | false | 0.045267 | 0.037162 | 1.218086 | [
"s131827096",
"s100377469"
] |
u037430802 | p03713 | python | s655220589 | s400471649 | 587 | 533 | 3,064 | 3,064 | Accepted | Accepted | 9.2 | import math
H, W = list(map(int, input().split()))
ans = 10**10
for h in range(1, H):
A = h * W
#残りを横に割る
B = W*math.ceil((H-h)/2)
C = H*W - A - B
tmp = max([A,B,C]) - min([A,B,C])
ans = min(ans, tmp)
#残りを縦に割る
B = (H-h)*math.ceil(W/2)
C = H*W - A - B
tmp = max([A,B,C]) - min([A,B,C])
ans = min(ans, tmp)
# 縦横入れ替え
H, W = W, H
for h in range(1, H):
A = h * W
#残りを横に割る
B = W*math.ceil((H-h)/2)
C = H*W - A - B
tmp = max([A,B,C]) - min([A,B,C])
ans = min(ans, tmp)
#残りを縦に割る
B = (H-h)*math.ceil(W/2)
C = H*W - A - B
tmp = max([A,B,C]) - min([A,B,C])
ans = min(ans, tmp)
print(ans) | H, W = list(map(int, input().split()))
if H % 3 == 0 or W % 3 == 0:
print((0))
exit()
ans = H*W
# 高さを変えて調べる
for h in range(1, H+1):
a = h*W
#残りを高さで割る場合
b = ((H-h)//2) * W
c = H*W - a - b
ans = min(ans, max([a,b,c]) - min([a,b,c]))
#残りを幅で割る場合
b = (H-h) * (W//2)
c = H*W - a - b
ans = min(ans, max([a,b,c]) - min([a,b,c]))
# 幅を変えて調べる
for w in range(1, W+1):
a = H*w
#残りを高さで割る場合
b = (W-w) * (H//2)
c = H*W - a - b
ans = min(ans, max([a,b,c]) - min([a,b,c]))
#残りを幅で割る場合
b = ((W-w)//2) * H
c = H*W - a - b
ans = min(ans, max([a,b,c]) - min([a,b,c]))
print(ans) | 31 | 39 | 688 | 676 | import math
H, W = list(map(int, input().split()))
ans = 10**10
for h in range(1, H):
A = h * W
# 残りを横に割る
B = W * math.ceil((H - h) / 2)
C = H * W - A - B
tmp = max([A, B, C]) - min([A, B, C])
ans = min(ans, tmp)
# 残りを縦に割る
B = (H - h) * math.ceil(W / 2)
C = H * W - A - B
tmp = max([A, B, C]) - min([A, B, C])
ans = min(ans, tmp)
# 縦横入れ替え
H, W = W, H
for h in range(1, H):
A = h * W
# 残りを横に割る
B = W * math.ceil((H - h) / 2)
C = H * W - A - B
tmp = max([A, B, C]) - min([A, B, C])
ans = min(ans, tmp)
# 残りを縦に割る
B = (H - h) * math.ceil(W / 2)
C = H * W - A - B
tmp = max([A, B, C]) - min([A, B, C])
ans = min(ans, tmp)
print(ans)
| H, W = list(map(int, input().split()))
if H % 3 == 0 or W % 3 == 0:
print((0))
exit()
ans = H * W
# 高さを変えて調べる
for h in range(1, H + 1):
a = h * W
# 残りを高さで割る場合
b = ((H - h) // 2) * W
c = H * W - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))
# 残りを幅で割る場合
b = (H - h) * (W // 2)
c = H * W - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))
# 幅を変えて調べる
for w in range(1, W + 1):
a = H * w
# 残りを高さで割る場合
b = (W - w) * (H // 2)
c = H * W - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))
# 残りを幅で割る場合
b = ((W - w) // 2) * H
c = H * W - a - b
ans = min(ans, max([a, b, c]) - min([a, b, c]))
print(ans)
| false | 20.512821 | [
"-import math",
"-",
"-ans = 10**10",
"-for h in range(1, H):",
"- A = h * W",
"- # 残りを横に割る",
"- B = W * math.ceil((H - h) / 2)",
"- C = H * W - A - B",
"- tmp = max([A, B, C]) - min([A, B, C])",
"- ans = min(ans, tmp)",
"- # 残りを縦に割る",
"- B = (H - h) * math.ceil(W / 2)"... | false | 0.600474 | 1.103701 | 0.544055 | [
"s655220589",
"s400471649"
] |
u232852711 | p03330 | python | s381025500 | s018312069 | 1,969 | 182 | 7,668 | 5,620 | Accepted | Accepted | 90.76 | from itertools import permutations
n, c = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]
colors = [[0]*c for _ in range(3)]
for i in range(n):
for j in range(n):
c_ij = C[i][j]-1
index = (i+j)%3
for col in range(c):
colors[index][col] += D[c_ij][col]
ans = 1000*500**2
for c0, c1, c2 in permutations(list(range(c)), 3):
diff = colors[0][c0] + colors[1][c1] + colors[2][c2]
ans = min(ans, diff)
print(ans)
| from itertools import permutations
n, c = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]
colors = [[0]*c for _ in range(3)]
for i in range(n):
for j in range(n):
c_ij = C[i][j]-1
index = (i+j)%3
colors[index][c_ij] += 1
costs = [[0]*c for _ in range(3)]
for i in range(3):
for c_cur in range(c):
for c_tar in range(c):
costs[i][c_tar] += D[c_cur][c_tar]*colors[i][c_cur]
ans = 1000*500**2
for c0, c1, c2 in permutations(list(range(c)), 3):
diff = costs[0][c0] + costs[1][c1] + costs[2][c2]
ans = min(ans, diff)
print(ans)
| 18 | 23 | 557 | 692 | from itertools import permutations
n, c = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]
colors = [[0] * c for _ in range(3)]
for i in range(n):
for j in range(n):
c_ij = C[i][j] - 1
index = (i + j) % 3
for col in range(c):
colors[index][col] += D[c_ij][col]
ans = 1000 * 500**2
for c0, c1, c2 in permutations(list(range(c)), 3):
diff = colors[0][c0] + colors[1][c1] + colors[2][c2]
ans = min(ans, diff)
print(ans)
| from itertools import permutations
n, c = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]
colors = [[0] * c for _ in range(3)]
for i in range(n):
for j in range(n):
c_ij = C[i][j] - 1
index = (i + j) % 3
colors[index][c_ij] += 1
costs = [[0] * c for _ in range(3)]
for i in range(3):
for c_cur in range(c):
for c_tar in range(c):
costs[i][c_tar] += D[c_cur][c_tar] * colors[i][c_cur]
ans = 1000 * 500**2
for c0, c1, c2 in permutations(list(range(c)), 3):
diff = costs[0][c0] + costs[1][c1] + costs[2][c2]
ans = min(ans, diff)
print(ans)
| false | 21.73913 | [
"- for col in range(c):",
"- colors[index][col] += D[c_ij][col]",
"+ colors[index][c_ij] += 1",
"+costs = [[0] * c for _ in range(3)]",
"+for i in range(3):",
"+ for c_cur in range(c):",
"+ for c_tar in range(c):",
"+ costs[i][c_tar] += D[c_cur][c_tar] * c... | false | 0.041376 | 0.036041 | 1.148028 | [
"s381025500",
"s018312069"
] |
u952708174 | p03308 | python | s550261787 | s664119672 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | N = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
for j in range(len(A) - 1):
for k in range(j + 1, len(A)):
ans = max(ans, abs(A[j] - A[k]))
print(ans) | N = int(eval(input()))
A = [int(i) for i in input().split()]
ans = max(A) - min(A)
print(ans) | 8 | 5 | 179 | 92 | N = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
for j in range(len(A) - 1):
for k in range(j + 1, len(A)):
ans = max(ans, abs(A[j] - A[k]))
print(ans)
| N = int(eval(input()))
A = [int(i) for i in input().split()]
ans = max(A) - min(A)
print(ans)
| false | 37.5 | [
"-ans = 0",
"-for j in range(len(A) - 1):",
"- for k in range(j + 1, len(A)):",
"- ans = max(ans, abs(A[j] - A[k]))",
"+ans = max(A) - min(A)"
] | false | 0.039722 | 0.103518 | 0.38372 | [
"s550261787",
"s664119672"
] |
u072053884 | p02233 | python | s268324649 | s700069314 | 40 | 20 | 7,736 | 7,748 | Accepted | Accepted | 50 | def fib2(n):
a1, a2 = 1, 0
while n > 0:
a1, a2 = a1 + a2, a1
n -= 1
return a1
n = int(eval(input()))
print((fib2(n))) | answer_list = [1, 1] + [None] * 43
def fib(num):
ans = answer_list[num]
if ans:
return ans
ans = fib(num - 1) + fib(num - 2)
answer_list[num] = ans
return ans
n = int(eval(input()))
print((fib(n))) | 11 | 14 | 150 | 234 | def fib2(n):
a1, a2 = 1, 0
while n > 0:
a1, a2 = a1 + a2, a1
n -= 1
return a1
n = int(eval(input()))
print((fib2(n)))
| answer_list = [1, 1] + [None] * 43
def fib(num):
ans = answer_list[num]
if ans:
return ans
ans = fib(num - 1) + fib(num - 2)
answer_list[num] = ans
return ans
n = int(eval(input()))
print((fib(n)))
| false | 21.428571 | [
"-def fib2(n):",
"- a1, a2 = 1, 0",
"- while n > 0:",
"- a1, a2 = a1 + a2, a1",
"- n -= 1",
"- return a1",
"+answer_list = [1, 1] + [None] * 43",
"+",
"+",
"+def fib(num):",
"+ ans = answer_list[num]",
"+ if ans:",
"+ return ans",
"+ ans = fib(num - 1... | false | 0.03611 | 0.073032 | 0.494449 | [
"s268324649",
"s700069314"
] |
u934442292 | p03053 | python | s371308796 | s152298056 | 885 | 783 | 143,748 | 113,316 | Accepted | Accepted | 11.53 | import sys
from collections import deque
input = sys.stdin.readline
def solve(H, W, A):
WALL = - 10 ** 7
dist = [[WALL] + [-1] * W + [WALL] for _ in range(H + 2)]
dist[0] = dist[-1] = [WALL] * (W + 2)
queue = deque()
for h in range(H):
for w in range(W):
if A[h][w] == "#":
dist[h + 1][w + 1] = 0
queue.append((h + 1, w + 1))
while queue:
h, w = queue.popleft()
d = dist[h][w]
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
y, x = h + i, w + j
if dist[y][x] == -1:
dist[y][x] = d + 1
queue.append((y, x))
res = max(list(map(max, dist)))
return res
def main():
H, W = list(map(int, input().split()))
A = [None] * H
for i in range(H):
A[i] = list(input().rstrip())
ans = solve(H, W, A)
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import deque
input = sys.stdin.readline
def solve(H, W, A):
dist = [[0] + [-1] * W + [0] for _ in range(H + 2)]
dist[0] = dist[-1] = [0] * (W + 2)
queue = deque()
for h in range(1, H + 1):
for w in range(1, W + 1):
if A[h][w] == "#":
dist[h][w] = 0
queue.append((h, w))
while queue:
h, w = queue.popleft()
d = dist[h][w]
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
y, x = h + i, w + j
if dist[y][x] == -1:
dist[y][x] = d + 1
queue.append((y, x))
res = max(list(map(max, dist)))
return res
def main():
H, W = list(map(int, input().split()))
A = [None] * (H + 2)
A[0] = A[-1] = "." * (W + 2)
for i in range(1, H + 1):
A[i] = "".join((".", input().rstrip(), "."))
ans = solve(H, W, A)
print(ans)
if __name__ == "__main__":
main()
| 43 | 43 | 967 | 996 | import sys
from collections import deque
input = sys.stdin.readline
def solve(H, W, A):
WALL = -(10**7)
dist = [[WALL] + [-1] * W + [WALL] for _ in range(H + 2)]
dist[0] = dist[-1] = [WALL] * (W + 2)
queue = deque()
for h in range(H):
for w in range(W):
if A[h][w] == "#":
dist[h + 1][w + 1] = 0
queue.append((h + 1, w + 1))
while queue:
h, w = queue.popleft()
d = dist[h][w]
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
y, x = h + i, w + j
if dist[y][x] == -1:
dist[y][x] = d + 1
queue.append((y, x))
res = max(list(map(max, dist)))
return res
def main():
H, W = list(map(int, input().split()))
A = [None] * H
for i in range(H):
A[i] = list(input().rstrip())
ans = solve(H, W, A)
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import deque
input = sys.stdin.readline
def solve(H, W, A):
dist = [[0] + [-1] * W + [0] for _ in range(H + 2)]
dist[0] = dist[-1] = [0] * (W + 2)
queue = deque()
for h in range(1, H + 1):
for w in range(1, W + 1):
if A[h][w] == "#":
dist[h][w] = 0
queue.append((h, w))
while queue:
h, w = queue.popleft()
d = dist[h][w]
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
y, x = h + i, w + j
if dist[y][x] == -1:
dist[y][x] = d + 1
queue.append((y, x))
res = max(list(map(max, dist)))
return res
def main():
H, W = list(map(int, input().split()))
A = [None] * (H + 2)
A[0] = A[-1] = "." * (W + 2)
for i in range(1, H + 1):
A[i] = "".join((".", input().rstrip(), "."))
ans = solve(H, W, A)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- WALL = -(10**7)",
"- dist = [[WALL] + [-1] * W + [WALL] for _ in range(H + 2)]",
"- dist[0] = dist[-1] = [WALL] * (W + 2)",
"+ dist = [[0] + [-1] * W + [0] for _ in range(H + 2)]",
"+ dist[0] = dist[-1] = [0] * (W + 2)",
"- for h in range(H):",
"- for w in range(W):",
"+ ... | false | 0.037977 | 0.038528 | 0.985709 | [
"s371308796",
"s152298056"
] |
u222668979 | p03171 | python | s926149135 | s923432836 | 462 | 368 | 112,476 | 112,220 | Accepted | Accepted | 20.35 | n = int(eval(input()))
a = list(map(int, input().split()))
dp = [[0] * (n+1) for _ in range(n+1)]
for i in range(n)[::-1]:
for j in range(n + 1):
if i >= j:
continue
minus = (n - i + j) % 2 * (-2) + 1
dp[i][j] = max(a[j - 1]-dp[i][j - 1], a[i]-dp[i + 1][j])
print((dp[0][n]))
| n = int(eval(input()))
a = list(map(int, input().split()))
dp = [[0] * (n+1) for _ in range(n+1)]
for i in range(n)[::-1]:
for j in range(n + 1):
if i >= j:
continue
dp[i][j] = max(a[j - 1] - dp[i][j - 1], a[i] - dp[i + 1][j])
print((dp[0][n]))
| 13 | 12 | 323 | 283 | n = int(eval(input()))
a = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n)[::-1]:
for j in range(n + 1):
if i >= j:
continue
minus = (n - i + j) % 2 * (-2) + 1
dp[i][j] = max(a[j - 1] - dp[i][j - 1], a[i] - dp[i + 1][j])
print((dp[0][n]))
| n = int(eval(input()))
a = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n)[::-1]:
for j in range(n + 1):
if i >= j:
continue
dp[i][j] = max(a[j - 1] - dp[i][j - 1], a[i] - dp[i + 1][j])
print((dp[0][n]))
| false | 7.692308 | [
"- minus = (n - i + j) % 2 * (-2) + 1"
] | false | 0.046492 | 0.045944 | 1.011944 | [
"s926149135",
"s923432836"
] |
u700636661 | p03037 | python | s424293699 | s142959986 | 185 | 155 | 21,148 | 22,848 | Accepted | Accepted | 16.22 | import sys
def main():
sinputl = sys.stdin.readline
num_card, num_gate = [int(x) for x in sinputl().split()]
input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]
card = [1, num_card]
for gate in input:
card[0] = max(card[0], gate[0])
card[1] = min(card[1], gate[1])
print((max(card[1] - card[0] + 1, 0)))
if __name__ == "__main__":
main()
| import sys
def main():
sinputl = sys.stdin.readline
num_card, num_gate = [int(x) for x in sinputl().split()]
input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]
under_limit = [x[0] for x in input]
over_limit = [x[1] for x in input]
print((max(min(over_limit) - max(under_limit) + 1, 0)))
if __name__ == "__main__":
main() | 19 | 16 | 424 | 410 | import sys
def main():
sinputl = sys.stdin.readline
num_card, num_gate = [int(x) for x in sinputl().split()]
input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]
card = [1, num_card]
for gate in input:
card[0] = max(card[0], gate[0])
card[1] = min(card[1], gate[1])
print((max(card[1] - card[0] + 1, 0)))
if __name__ == "__main__":
main()
| import sys
def main():
sinputl = sys.stdin.readline
num_card, num_gate = [int(x) for x in sinputl().split()]
input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]
under_limit = [x[0] for x in input]
over_limit = [x[1] for x in input]
print((max(min(over_limit) - max(under_limit) + 1, 0)))
if __name__ == "__main__":
main()
| false | 15.789474 | [
"- card = [1, num_card]",
"- for gate in input:",
"- card[0] = max(card[0], gate[0])",
"- card[1] = min(card[1], gate[1])",
"- print((max(card[1] - card[0] + 1, 0)))",
"+ under_limit = [x[0] for x in input]",
"+ over_limit = [x[1] for x in input]",
"+ print((max(min(ove... | false | 0.039201 | 0.063231 | 0.619964 | [
"s424293699",
"s142959986"
] |
u761320129 | p02954 | python | s584496832 | s945183226 | 116 | 88 | 9,020 | 11,424 | Accepted | Accepted | 24.14 | S = eval(input())
seq = [1]
pos = []
for i,(a,b) in enumerate(zip(S,S[1:])):
if a+b == 'RL':
pos.append(i)
if a==b:
seq[-1] += 1
else:
seq.append(1)
ans = [0] * len(S)
for r,l,p in zip(seq[::2],seq[1::2],pos):
ans[p] = ans[p+1] = (r+l)//2
if (r+l)%2:
if r > l:
ans[p] += 1
else:
ans[p+1] += 1
if max(r,l)%2==0:
ans[p],ans[p+1] = ans[p+1],ans[p]
print((*ans)) | S = eval(input())
arr = []
seq = 1
for i,(a,b) in enumerate(zip(S,S[1:])):
if a==b:
seq += 1
else:
arr.append(seq)
seq = 1
arr.append(seq)
assert len(arr)%2==0
ans = [0]*len(S)
i = 0
for r,l in zip(arr[::2],arr[1::2]):
i += r
ans[i-1] = ans[i] = (r+l)//2
if (r+l)%2:
if r<l:
if l%2:
ans[i] += 1
else:
ans[i-1] += 1
else:
if r%2:
ans[i-1] += 1
else:
ans[i] += 1
i += l
print((*ans)) | 22 | 33 | 476 | 585 | S = eval(input())
seq = [1]
pos = []
for i, (a, b) in enumerate(zip(S, S[1:])):
if a + b == "RL":
pos.append(i)
if a == b:
seq[-1] += 1
else:
seq.append(1)
ans = [0] * len(S)
for r, l, p in zip(seq[::2], seq[1::2], pos):
ans[p] = ans[p + 1] = (r + l) // 2
if (r + l) % 2:
if r > l:
ans[p] += 1
else:
ans[p + 1] += 1
if max(r, l) % 2 == 0:
ans[p], ans[p + 1] = ans[p + 1], ans[p]
print((*ans))
| S = eval(input())
arr = []
seq = 1
for i, (a, b) in enumerate(zip(S, S[1:])):
if a == b:
seq += 1
else:
arr.append(seq)
seq = 1
arr.append(seq)
assert len(arr) % 2 == 0
ans = [0] * len(S)
i = 0
for r, l in zip(arr[::2], arr[1::2]):
i += r
ans[i - 1] = ans[i] = (r + l) // 2
if (r + l) % 2:
if r < l:
if l % 2:
ans[i] += 1
else:
ans[i - 1] += 1
else:
if r % 2:
ans[i - 1] += 1
else:
ans[i] += 1
i += l
print((*ans))
| false | 33.333333 | [
"-seq = [1]",
"-pos = []",
"+arr = []",
"+seq = 1",
"- if a + b == \"RL\":",
"- pos.append(i)",
"- seq[-1] += 1",
"+ seq += 1",
"- seq.append(1)",
"+ arr.append(seq)",
"+ seq = 1",
"+arr.append(seq)",
"+assert len(arr) % 2 == 0",
"-for r, l, p i... | false | 0.123165 | 0.0468 | 2.63174 | [
"s584496832",
"s945183226"
] |
u320511454 | p02899 | python | s458824955 | s617818671 | 153 | 84 | 13,812 | 17,892 | Accepted | Accepted | 45.1 | n=int(eval(input()))
a=list(map(int,input().split()))
b=[0 for _ in range(n)]
for i in range(n):
b[a[i]-1] = i+1
for j in range(n):
print((b[j])) | n=int(eval(input()))
a=list(map(int,input().split()))
b=[0 for _ in range(n)]
for i in range(n):
b[a[i]-1] = i+1
str_b = list(map(str, b))
print((' '.join(str_b))) | 7 | 7 | 147 | 157 | n = int(eval(input()))
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
for i in range(n):
b[a[i] - 1] = i + 1
for j in range(n):
print((b[j]))
| n = int(eval(input()))
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
for i in range(n):
b[a[i] - 1] = i + 1
str_b = list(map(str, b))
print((" ".join(str_b)))
| false | 0 | [
"-for j in range(n):",
"- print((b[j]))",
"+str_b = list(map(str, b))",
"+print((\" \".join(str_b)))"
] | false | 0.036466 | 0.038742 | 0.941231 | [
"s458824955",
"s617818671"
] |
u717626627 | p02946 | python | s126087104 | s619039838 | 150 | 17 | 12,500 | 3,060 | Accepted | Accepted | 88.67 | import numpy as np
a,b = list(map(int, input().split()))
ans = np.array(list(range(b - (a - 1), b + (a))))
print((' '.join(map(str, ans)))) | a,b = map(int, input().split())
for i in range(b - (a-1), b+a):
print(i, end=" ")
| 7 | 4 | 134 | 87 | import numpy as np
a, b = list(map(int, input().split()))
ans = np.array(list(range(b - (a - 1), b + (a))))
print((" ".join(map(str, ans))))
| a, b = map(int, input().split())
for i in range(b - (a - 1), b + a):
print(i, end=" ")
| false | 42.857143 | [
"-import numpy as np",
"-",
"-a, b = list(map(int, input().split()))",
"-ans = np.array(list(range(b - (a - 1), b + (a))))",
"-print((\" \".join(map(str, ans))))",
"+a, b = map(int, input().split())",
"+for i in range(b - (a - 1), b + a):",
"+ print(i, end=\" \")"
] | false | 0.182794 | 0.036593 | 4.995338 | [
"s126087104",
"s619039838"
] |
u054514819 | p02789 | python | s124232895 | s962936068 | 177 | 63 | 38,256 | 61,924 | Accepted | Accepted | 64.41 | N, M = list(map(int, input().split()))
if N==M:
print('Yes')
else:
print('No') | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N, M = mapint()
if N==M:
print('Yes')
else:
print('No') | 5 | 10 | 84 | 209 | N, M = list(map(int, input().split()))
if N == M:
print("Yes")
else:
print("No")
| import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N, M = mapint()
if N == M:
print("Yes")
else:
print("No")
| false | 50 | [
"-N, M = list(map(int, input().split()))",
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def mapint():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+N, M = mapint()"
] | false | 0.032965 | 0.041725 | 0.790045 | [
"s124232895",
"s962936068"
] |
u203843959 | p02603 | python | s074301324 | s356332789 | 66 | 29 | 62,116 | 9,152 | Accepted | Accepted | 56.06 | import sys
N=int(eval(input()))
alist=list(map(int,input().split()))
a2list=[alist[0]]
for i in range(1,N):
if a2list[-1]!=alist[i]:
a2list.append(alist[i])
#print(a2list)
N2=len(a2list)
if N2==1:
print((1000))
sys.exit(0)
yama_list=[False]*N2
tani_list=[False]*N2
if a2list[0]>a2list[1]:
yama_list[0]=True
if a2list[0]<a2list[1]:
tani_list[0]=True
for i in range(1,N2-1):
if a2list[i-1]<a2list[i]>a2list[i+1]:
yama_list[i]=True
if a2list[i-1]>a2list[i]<a2list[i+1]:
tani_list[i]=True
if a2list[N2-2]<a2list[N2-1]:
yama_list[N2-1]=True
if a2list[N2-2]>a2list[N2-1]:
tani_list[N2-1]=True
#print(yama_list)
#print(tani_list)
money=1000
kabu=0
for i in range(N2):
if yama_list[i]:
#sell all
money+=a2list[i]*kabu
kabu=0
if tani_list[i] and i<N2-1:
#buy as possible
k=money//a2list[i]
kabu+=k
money-=k*a2list[i]
print(money) | N=int(eval(input()))
alist=list(map(int,input().split()))
money=1000
kabu=0
for i in range(N-1):
if alist[i]<alist[i+1]:
#buy as possible
k=money//alist[i]
kabu+=k
money-=k*alist[i]
elif alist[i]>alist[i+1]:
#sell all
money+=alist[i]*kabu
kabu=0
money+=alist[N-1]*kabu
print(money) | 50 | 18 | 943 | 330 | import sys
N = int(eval(input()))
alist = list(map(int, input().split()))
a2list = [alist[0]]
for i in range(1, N):
if a2list[-1] != alist[i]:
a2list.append(alist[i])
# print(a2list)
N2 = len(a2list)
if N2 == 1:
print((1000))
sys.exit(0)
yama_list = [False] * N2
tani_list = [False] * N2
if a2list[0] > a2list[1]:
yama_list[0] = True
if a2list[0] < a2list[1]:
tani_list[0] = True
for i in range(1, N2 - 1):
if a2list[i - 1] < a2list[i] > a2list[i + 1]:
yama_list[i] = True
if a2list[i - 1] > a2list[i] < a2list[i + 1]:
tani_list[i] = True
if a2list[N2 - 2] < a2list[N2 - 1]:
yama_list[N2 - 1] = True
if a2list[N2 - 2] > a2list[N2 - 1]:
tani_list[N2 - 1] = True
# print(yama_list)
# print(tani_list)
money = 1000
kabu = 0
for i in range(N2):
if yama_list[i]:
# sell all
money += a2list[i] * kabu
kabu = 0
if tani_list[i] and i < N2 - 1:
# buy as possible
k = money // a2list[i]
kabu += k
money -= k * a2list[i]
print(money)
| N = int(eval(input()))
alist = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(N - 1):
if alist[i] < alist[i + 1]:
# buy as possible
k = money // alist[i]
kabu += k
money -= k * alist[i]
elif alist[i] > alist[i + 1]:
# sell all
money += alist[i] * kabu
kabu = 0
money += alist[N - 1] * kabu
print(money)
| false | 64 | [
"-import sys",
"-",
"-a2list = [alist[0]]",
"-for i in range(1, N):",
"- if a2list[-1] != alist[i]:",
"- a2list.append(alist[i])",
"-# print(a2list)",
"-N2 = len(a2list)",
"-if N2 == 1:",
"- print((1000))",
"- sys.exit(0)",
"-yama_list = [False] * N2",
"-tani_list = [False] *... | false | 0.062186 | 0.085029 | 0.731351 | [
"s074301324",
"s356332789"
] |
u033839917 | p02657 | python | s948408720 | s436213492 | 29 | 26 | 9,128 | 9,136 | Accepted | Accepted | 10.34 | num = [int(i) for i in input().split() ]
print((num[0] * num[1])) | A,B = [int(i) for i in input().split()]
print((A*B)) | 2 | 2 | 64 | 51 | num = [int(i) for i in input().split()]
print((num[0] * num[1]))
| A, B = [int(i) for i in input().split()]
print((A * B))
| false | 0 | [
"-num = [int(i) for i in input().split()]",
"-print((num[0] * num[1]))",
"+A, B = [int(i) for i in input().split()]",
"+print((A * B))"
] | false | 0.037737 | 0.037791 | 0.99857 | [
"s948408720",
"s436213492"
] |
u644907318 | p03273 | python | s591209877 | s686375641 | 457 | 175 | 73,944 | 69,768 | Accepted | Accepted | 61.71 | import copy
H,W = list(map(int,input().split()))
A = [list(input().strip()) for _ in range(H)]
while True:
flag = 0
for i in range(len(A)-1,-1,-1):
fr = 0
for j in range(len(A[0])):
if A[i][j]=="#":
fr = 1
break
if fr==0:
B = [[0 for _ in range(len(A[0]))] for _ in range(len(A)-1)]
for i1 in range(len(A)):
if i1<i:
for j1 in range(len(A[0])):
B[i1][j1] = A[i1][j1]
elif i1>i:
for j1 in range(len(A[0])):
B[i1-1][j1] = A[i1][j1]
A = copy.deepcopy(B)
flag = 1
for j in range(len(A[0])-1,-1,-1):
fc = 0
for i in range(len(A)):
if A[i][j]=="#":
fc=1
break
if fc==0:
B = [[0 for _ in range(len(A[0])-1)] for _ in range(len(A))]
for j1 in range(len(A[0])):
if j1<j:
for i1 in range(len(A)):
B[i1][j1] = A[i1][j1]
elif j1>j:
for i1 in range(len(A)):
B[i1][j1-1] = A[i1][j1]
A = copy.deepcopy(B)
flag = 1
if flag==0:break
for i in range(len(A)):
print(("".join(A[i]))) | H,W = list(map(int,input().split()))
A = [list(eval(input())) for _ in range(H)]
B = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if A[i][j]=="#":
B[i][j] = 1
C = []
for i in range(H-1,-1,-1):
if sum(B[i])==0:
C.append(i)
B1 = []
for i in range(H):
if i not in C:
B1.append(B[i])
C = []
for j in range(W):
flag = 0
for i in range(len(B1)):
if B1[i][j]==1:
flag = 1
break
if flag==0:
C.append(j)
B2 = []
for i in range(len(B1)):
row = []
for j in range(W):
if j not in C:
row.append(B1[i][j])
B2.append(row)
B3 = []
for i in range(len(B2)):
x = ""
for j in range(len(B2[i])):
if B2[i][j]==0:
x += "."
else:
x += "#"
B3.append(x)
for i in range(len(B3)):
print((B3[i])) | 42 | 42 | 1,387 | 917 | import copy
H, W = list(map(int, input().split()))
A = [list(input().strip()) for _ in range(H)]
while True:
flag = 0
for i in range(len(A) - 1, -1, -1):
fr = 0
for j in range(len(A[0])):
if A[i][j] == "#":
fr = 1
break
if fr == 0:
B = [[0 for _ in range(len(A[0]))] for _ in range(len(A) - 1)]
for i1 in range(len(A)):
if i1 < i:
for j1 in range(len(A[0])):
B[i1][j1] = A[i1][j1]
elif i1 > i:
for j1 in range(len(A[0])):
B[i1 - 1][j1] = A[i1][j1]
A = copy.deepcopy(B)
flag = 1
for j in range(len(A[0]) - 1, -1, -1):
fc = 0
for i in range(len(A)):
if A[i][j] == "#":
fc = 1
break
if fc == 0:
B = [[0 for _ in range(len(A[0]) - 1)] for _ in range(len(A))]
for j1 in range(len(A[0])):
if j1 < j:
for i1 in range(len(A)):
B[i1][j1] = A[i1][j1]
elif j1 > j:
for i1 in range(len(A)):
B[i1][j1 - 1] = A[i1][j1]
A = copy.deepcopy(B)
flag = 1
if flag == 0:
break
for i in range(len(A)):
print(("".join(A[i])))
| H, W = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
B = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if A[i][j] == "#":
B[i][j] = 1
C = []
for i in range(H - 1, -1, -1):
if sum(B[i]) == 0:
C.append(i)
B1 = []
for i in range(H):
if i not in C:
B1.append(B[i])
C = []
for j in range(W):
flag = 0
for i in range(len(B1)):
if B1[i][j] == 1:
flag = 1
break
if flag == 0:
C.append(j)
B2 = []
for i in range(len(B1)):
row = []
for j in range(W):
if j not in C:
row.append(B1[i][j])
B2.append(row)
B3 = []
for i in range(len(B2)):
x = ""
for j in range(len(B2[i])):
if B2[i][j] == 0:
x += "."
else:
x += "#"
B3.append(x)
for i in range(len(B3)):
print((B3[i]))
| false | 0 | [
"-import copy",
"-",
"-A = [list(input().strip()) for _ in range(H)]",
"-while True:",
"+A = [list(eval(input())) for _ in range(H)]",
"+B = [[0 for _ in range(W)] for _ in range(H)]",
"+for i in range(H):",
"+ for j in range(W):",
"+ if A[i][j] == \"#\":",
"+ B[i][j] = 1",
... | false | 0.082628 | 0.132917 | 0.621646 | [
"s591209877",
"s686375641"
] |
u490553751 | p02785 | python | s345672622 | s412372146 | 191 | 170 | 27,660 | 26,024 | Accepted | Accepted | 10.99 | #template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
N,K = inputlist()
H = inputlist()
H.sort()
H.reverse()
ans = 0
for i in range(K,N):
ans += H[i]
print(ans) | #template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
H = inputlist()
if K >= N:
print((0))
exit()
H.sort(reverse=True)
ha = H[K:]
print((sum(ha))) | 11 | 11 | 220 | 203 | # template
from collections import Counter
def inputlist():
return [int(j) for j in input().split()]
N, K = inputlist()
H = inputlist()
H.sort()
H.reverse()
ans = 0
for i in range(K, N):
ans += H[i]
print(ans)
| # template
def inputlist():
return [int(k) for k in input().split()]
# template
N, K = inputlist()
H = inputlist()
if K >= N:
print((0))
exit()
H.sort(reverse=True)
ha = H[K:]
print((sum(ha)))
| false | 0 | [
"-from collections import Counter",
"+def inputlist():",
"+ return [int(k) for k in input().split()]",
"-def inputlist():",
"- return [int(j) for j in input().split()]",
"-",
"-",
"+# template",
"-H.sort()",
"-H.reverse()",
"-ans = 0",
"-for i in range(K, N):",
"- ans += H[i]",
"-... | false | 0.081254 | 0.081153 | 1.001247 | [
"s345672622",
"s412372146"
] |
u254871849 | p03625 | python | s750193310 | s449766473 | 219 | 94 | 20,956 | 14,052 | Accepted | Accepted | 57.08 | from sys import stdin
n, *a = list(map(int, stdin.read().split()))
l_count = {}
for l in a:
l_count.update({l: l_count.get(l, 0) + 1})
long_side, short_side = 0, 0
for l, c in sorted(list(l_count.items()), reverse=1):
if c != 1:
if not long_side:
if c >= 4:
print((l ** 2))
exit()
else:
long_side = l
else:
short_side = l
break
print((long_side * short_side)) | import sys
n, *l = list(map(int, sys.stdin.read().split()))
def main():
l.sort(reverse=True)
a = b = 0
i = 0
while i <= n - 2:
if l[i] == l[i+1]:
if a:
b = l[i]
break
else:
a = l[i]
i += 2
continue
i += 1
return a * b
if __name__ == '__main__':
ans = main()
print(ans) | 22 | 25 | 491 | 443 | from sys import stdin
n, *a = list(map(int, stdin.read().split()))
l_count = {}
for l in a:
l_count.update({l: l_count.get(l, 0) + 1})
long_side, short_side = 0, 0
for l, c in sorted(list(l_count.items()), reverse=1):
if c != 1:
if not long_side:
if c >= 4:
print((l**2))
exit()
else:
long_side = l
else:
short_side = l
break
print((long_side * short_side))
| import sys
n, *l = list(map(int, sys.stdin.read().split()))
def main():
l.sort(reverse=True)
a = b = 0
i = 0
while i <= n - 2:
if l[i] == l[i + 1]:
if a:
b = l[i]
break
else:
a = l[i]
i += 2
continue
i += 1
return a * b
if __name__ == "__main__":
ans = main()
print(ans)
| false | 12 | [
"-from sys import stdin",
"+import sys",
"-n, *a = list(map(int, stdin.read().split()))",
"-l_count = {}",
"-for l in a:",
"- l_count.update({l: l_count.get(l, 0) + 1})",
"-long_side, short_side = 0, 0",
"-for l, c in sorted(list(l_count.items()), reverse=1):",
"- if c != 1:",
"- if n... | false | 0.043528 | 0.043288 | 1.00555 | [
"s750193310",
"s449766473"
] |
u118642796 | p03283 | python | s436709300 | s072409935 | 1,630 | 694 | 21,076 | 42,496 | Accepted | Accepted | 57.42 | N,M,Q = list(map(int,input().split()))
Section = [[0]*N for _ in range(N)]
for _ in range(M):
L,R = list(map(int,input().split()))
Section[L-1][R-1] += 1
Sum = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
for j in range(N):
Sum[i+1][j+1] = Sum[i][j+1]+Sum[i+1][j]-Sum[i][j]+Section[i][j]
Ans = [[0]*N for _ in range(N)]
for i in range(N):
for j in range(i,N):
Ans[i][j] = Sum[j+1][j+1]-Sum[i][j+1]
for _ in range(Q):
p,q = list(map(int,input().split()))
print((Ans[p-1][q-1])) | import sys
s = sys.stdin.readlines()
N,M,Q = list(map(int,s[0].split()))
Section = [[0]*N for _ in range(N)]
for L,R in (list(map(int, e.split())) for e in s[1:M+1]):
Section[L-1][R-1] += 1
Sum = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
for j in range(N):
Sum[i+1][j+1] = Sum[i][j+1]+Sum[i+1][j]-Sum[i][j]+Section[i][j]
Ans = [[0]*N for _ in range(N)]
for i in range(N):
for j in range(i,N):
Ans[i][j] = Sum[j+1][j+1]-Sum[i][j+1]
for p,q in (list(map(int, e.split())) for e in s[M+1:]):
print((Ans[p-1][q-1])) | 20 | 20 | 525 | 554 | N, M, Q = list(map(int, input().split()))
Section = [[0] * N for _ in range(N)]
for _ in range(M):
L, R = list(map(int, input().split()))
Section[L - 1][R - 1] += 1
Sum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(N):
Sum[i + 1][j + 1] = Sum[i][j + 1] + Sum[i + 1][j] - Sum[i][j] + Section[i][j]
Ans = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i, N):
Ans[i][j] = Sum[j + 1][j + 1] - Sum[i][j + 1]
for _ in range(Q):
p, q = list(map(int, input().split()))
print((Ans[p - 1][q - 1]))
| import sys
s = sys.stdin.readlines()
N, M, Q = list(map(int, s[0].split()))
Section = [[0] * N for _ in range(N)]
for L, R in (list(map(int, e.split())) for e in s[1 : M + 1]):
Section[L - 1][R - 1] += 1
Sum = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
for j in range(N):
Sum[i + 1][j + 1] = Sum[i][j + 1] + Sum[i + 1][j] - Sum[i][j] + Section[i][j]
Ans = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i, N):
Ans[i][j] = Sum[j + 1][j + 1] - Sum[i][j + 1]
for p, q in (list(map(int, e.split())) for e in s[M + 1 :]):
print((Ans[p - 1][q - 1]))
| false | 0 | [
"-N, M, Q = list(map(int, input().split()))",
"+import sys",
"+",
"+s = sys.stdin.readlines()",
"+N, M, Q = list(map(int, s[0].split()))",
"-for _ in range(M):",
"- L, R = list(map(int, input().split()))",
"+for L, R in (list(map(int, e.split())) for e in s[1 : M + 1]):",
"-for _ in range(Q):",
... | false | 0.04271 | 0.041868 | 1.02011 | [
"s436709300",
"s072409935"
] |
u620945921 | p03288 | python | s914220470 | s398809606 | 165 | 18 | 38,256 | 2,940 | Accepted | Accepted | 89.09 | r=int(eval(input()))
data=(1200,2800)
name=('ABC', 'ARC', 'AGC')
z=[name[0] if r < 1200 else name[1] if data[0] <= r < data[1] else name[2] if data[1] <= r else i for i in range(1)]
print((z[0])) | r=int(eval(input()))
if r<1200:
print('ABC')
elif r<2800:
print('ARC')
else:
print('AGC') | 6 | 8 | 193 | 97 | r = int(eval(input()))
data = (1200, 2800)
name = ("ABC", "ARC", "AGC")
z = [
name[0]
if r < 1200
else name[1]
if data[0] <= r < data[1]
else name[2]
if data[1] <= r
else i
for i in range(1)
]
print((z[0]))
| r = int(eval(input()))
if r < 1200:
print("ABC")
elif r < 2800:
print("ARC")
else:
print("AGC")
| false | 25 | [
"-data = (1200, 2800)",
"-name = (\"ABC\", \"ARC\", \"AGC\")",
"-z = [",
"- name[0]",
"- if r < 1200",
"- else name[1]",
"- if data[0] <= r < data[1]",
"- else name[2]",
"- if data[1] <= r",
"- else i",
"- for i in range(1)",
"-]",
"-print((z[0]))",
"+if r < 1200:",... | false | 0.047182 | 0.041336 | 1.14142 | [
"s914220470",
"s398809606"
] |
u981931040 | p02881 | python | s562061218 | s357856963 | 202 | 114 | 3,060 | 3,296 | Accepted | Accepted | 43.56 | N = int(eval(input()))
ans = float('inf')
for i in range(1,int(N**0.5) + 1):
tmp = N / i
if tmp.is_integer():
if tmp == N:
tmp_ans = N - 1
else:
tmp_ans = int(tmp) + i - 2
if ans > tmp_ans:
ans = tmp_ans
print(ans) | def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
10
N = int(eval(input()))
divisors = make_divisors(N)
ans = float('inf')
div_len = len(divisors)
if div_len % 2 == 0:
i = div_len // 2
j = div_len // 2 - 1
ans = divisors[i] + divisors[j] - 2
else:
ans = divisors[div_len // 2] * 2 - 2
print(ans) | 12 | 23 | 287 | 517 | N = int(eval(input()))
ans = float("inf")
for i in range(1, int(N**0.5) + 1):
tmp = N / i
if tmp.is_integer():
if tmp == N:
tmp_ans = N - 1
else:
tmp_ans = int(tmp) + i - 2
if ans > tmp_ans:
ans = tmp_ans
print(ans)
| def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
10
N = int(eval(input()))
divisors = make_divisors(N)
ans = float("inf")
div_len = len(divisors)
if div_len % 2 == 0:
i = div_len // 2
j = div_len // 2 - 1
ans = divisors[i] + divisors[j] - 2
else:
ans = divisors[div_len // 2] * 2 - 2
print(ans)
| false | 47.826087 | [
"+def make_divisors(n):",
"+ divisors = []",
"+ for i in range(1, int(n**0.5) + 1):",
"+ if n % i == 0:",
"+ divisors.append(i)",
"+ if i != n // i:",
"+ divisors.append(n // i)",
"+ divisors.sort()",
"+ return divisors",
"+",
"+",
"+10",... | false | 0.0574 | 0.047121 | 1.218146 | [
"s562061218",
"s357856963"
] |
u133936772 | p02574 | python | s644252912 | s061206503 | 729 | 632 | 197,708 | 202,820 | Accepted | Accepted | 13.31 | n=int(input())
l=[*map(int,input().split())]
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
from math import *
g=l[0]
for x in l: g=gcd(g,x)
if g>1: f(2)
from collections import *
C=Counter()
for x in l:
for i in range(2,int(x**0.5)+1):
if x%i<1:
if C[i]: f(1)
C[i]=1
while x%i<1: x//=i
if x<2: break
if x>1:
if C[x]: f(1)
C[x]=1
f(0)
| M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n,*l=map(int,open(0).read().split())
from math import *
g=l[0]
for x in l: g=gcd(g,x)
if g>1: f(2)
C=[0]*M
for x in l: C[x]=1
for i in range(2,M):
if sum(C[j] for j in range(i,M,i))>1: f(1)
f(0)
| 20 | 12 | 410 | 285 | n = int(input())
l = [*map(int, input().split())]
f = lambda p: exit(print(["pairwise", "setwise", "not"][p] + " coprime"))
from math import *
g = l[0]
for x in l:
g = gcd(g, x)
if g > 1:
f(2)
from collections import *
C = Counter()
for x in l:
for i in range(2, int(x**0.5) + 1):
if x % i < 1:
if C[i]:
f(1)
C[i] = 1
while x % i < 1:
x //= i
if x < 2:
break
if x > 1:
if C[x]:
f(1)
C[x] = 1
f(0)
| M = 10**6 + 1
f = lambda p: exit(print(["pairwise", "setwise", "not"][p] + " coprime"))
n, *l = map(int, open(0).read().split())
from math import *
g = l[0]
for x in l:
g = gcd(g, x)
if g > 1:
f(2)
C = [0] * M
for x in l:
C[x] = 1
for i in range(2, M):
if sum(C[j] for j in range(i, M, i)) > 1:
f(1)
f(0)
| false | 40 | [
"-n = int(input())",
"-l = [*map(int, input().split())]",
"+M = 10**6 + 1",
"+n, *l = map(int, open(0).read().split())",
"-from collections import *",
"-",
"-C = Counter()",
"+C = [0] * M",
"- for i in range(2, int(x**0.5) + 1):",
"- if x % i < 1:",
"- if C[i]:",
"- ... | false | 0.046142 | 1.861843 | 0.024783 | [
"s644252912",
"s061206503"
] |
u936985471 | p03108 | python | s329520394 | s088423054 | 680 | 432 | 27,272 | 32,412 | Accepted | Accepted | 36.47 | # 逆順に見ていく
# M本の橋が全て崩落した状態=全ての島が行き来できない=不便さ:N*(N-1)//2
# 橋ができたら、UnionFindで一つに島グループとしてつなぐ
# 新たにできた橋が、今まで別の島グループだったときは
# 二つの島グループの間の組み合わせの数だけ不便さが減る
# 島グループ1の数 * 島グループ2の数だけ不便さが減る
# 新たにできた島グループが同じ島グループだったときは何も変わらない
import sys
readline=sys.stdin.readline
# 0-indexed
class UnionFind:
N=0
parent=None
size=None
def __init__(self,N):
self.N=N
self.parent=[i for i in range(self.N)]
self.size=[1]*self.N
def root(self,x):
while x!=self.parent[x]:
self.parent[x]=self.parent[self.parent[x]]
x=self.parent[x]
return x
def same(self,x,y):
return self.root(x)==self.root(y)
def unite(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return
if self.size[x]>self.size[y]:
# 大きい方にくっつける
self.parent[y]=x
self.size[x]+=self.size[y]
else:
self.parent[x]=y
self.size[y]+=self.size[x]
def get_group_size(self,x):
return self.size[self.root(x)]
def get_roots(self):
r=set()
for i in range(self.N):
r.add(root(i))
return r
def show_parent(self):
print((self.parent))
def show_size(self):
print((self.size))
N,M=list(map(int,readline().split()))
UF=UnionFind(N)
ans=[N*(N-1)//2]
decay=[None]*M
for i in range(M):
a,b=list(map(int,readline().split()))
decay[M-1-i]=[a-1,b-1]
# decayは逆順になっている
for i in range(M):
a,b=decay[i]
if UF.same(a,b):
ans+=[ans[-1]]
else:
asize=UF.get_group_size(a)
bsize=UF.get_group_size(b)
ans+=[ans[-1]-asize*bsize]
UF.unite(a,b)
for i in range(len(ans)-2,-1,-1):
print((ans[i]))
| import sys
readline = sys.stdin.readline
class UnionFind:
N=0
parent=None
size=None
def __init__(self,N):
self.N=N
self.parent=[i for i in range(self.N)]
self.size=[1]*self.N
def root(self,x):
while x!=self.parent[x]:
self.parent[x]=self.parent[self.parent[x]]
x=self.parent[x]
return x
def same(self,x,y):
return self.root(x)==self.root(y)
def unite(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return
if self.size[x]>self.size[y]:
# 大きい方にくっつける
self.parent[y]=x
self.size[x]+=self.size[y]
else:
self.parent[x]=y
self.size[y]+=self.size[x]
def get_group_size(self,x):
return self.size[self.root(x)]
def get_roots(self):
r=set()
for i in range(self.N):
r.add(self.root(i))
return r
def show_parent(self):
print(self.parent)
def show_size(self):
print(self.size)
N,M = map(int,readline().split())
bridges = [tuple(map(int,readline().split())) for i in range(M)]
# 順に崩落していく = 最後に崩落するものから順に建設されていくと考える
# 最初の不便さは(N * (N - 1)) // 2
# 新たにa,bの間に橋が繋がると、[aが属していた島々 * bが属していた島々]だけ不便さが減る
UF = UnionFind(N)
ans = [0] * M
num = (N * (N - 1)) // 2
for i in range(len(bridges) - 1, -1, -1):
ans[i] = num
a,b = bridges[i]
a,b = a - 1,b - 1
if not UF.same(a,b):
num -= UF.get_group_size(a) * UF.get_group_size(b)
UF.unite(a,b)
print(*ans, sep = "\n")
| 79 | 68 | 1,663 | 1,500 | # 逆順に見ていく
# M本の橋が全て崩落した状態=全ての島が行き来できない=不便さ:N*(N-1)//2
# 橋ができたら、UnionFindで一つに島グループとしてつなぐ
# 新たにできた橋が、今まで別の島グループだったときは
# 二つの島グループの間の組み合わせの数だけ不便さが減る
# 島グループ1の数 * 島グループ2の数だけ不便さが減る
# 新たにできた島グループが同じ島グループだったときは何も変わらない
import sys
readline = sys.stdin.readline
# 0-indexed
class UnionFind:
N = 0
parent = None
size = None
def __init__(self, N):
self.N = N
self.parent = [i for i in range(self.N)]
self.size = [1] * self.N
def root(self, x):
while x != self.parent[x]:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def same(self, x, y):
return self.root(x) == self.root(y)
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.size[x] > self.size[y]:
# 大きい方にくっつける
self.parent[y] = x
self.size[x] += self.size[y]
else:
self.parent[x] = y
self.size[y] += self.size[x]
def get_group_size(self, x):
return self.size[self.root(x)]
def get_roots(self):
r = set()
for i in range(self.N):
r.add(root(i))
return r
def show_parent(self):
print((self.parent))
def show_size(self):
print((self.size))
N, M = list(map(int, readline().split()))
UF = UnionFind(N)
ans = [N * (N - 1) // 2]
decay = [None] * M
for i in range(M):
a, b = list(map(int, readline().split()))
decay[M - 1 - i] = [a - 1, b - 1]
# decayは逆順になっている
for i in range(M):
a, b = decay[i]
if UF.same(a, b):
ans += [ans[-1]]
else:
asize = UF.get_group_size(a)
bsize = UF.get_group_size(b)
ans += [ans[-1] - asize * bsize]
UF.unite(a, b)
for i in range(len(ans) - 2, -1, -1):
print((ans[i]))
| import sys
readline = sys.stdin.readline
class UnionFind:
N = 0
parent = None
size = None
def __init__(self, N):
self.N = N
self.parent = [i for i in range(self.N)]
self.size = [1] * self.N
def root(self, x):
while x != self.parent[x]:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def same(self, x, y):
return self.root(x) == self.root(y)
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.size[x] > self.size[y]:
# 大きい方にくっつける
self.parent[y] = x
self.size[x] += self.size[y]
else:
self.parent[x] = y
self.size[y] += self.size[x]
def get_group_size(self, x):
return self.size[self.root(x)]
def get_roots(self):
r = set()
for i in range(self.N):
r.add(self.root(i))
return r
def show_parent(self):
print(self.parent)
def show_size(self):
print(self.size)
N, M = map(int, readline().split())
bridges = [tuple(map(int, readline().split())) for i in range(M)]
# 順に崩落していく = 最後に崩落するものから順に建設されていくと考える
# 最初の不便さは(N * (N - 1)) // 2
# 新たにa,bの間に橋が繋がると、[aが属していた島々 * bが属していた島々]だけ不便さが減る
UF = UnionFind(N)
ans = [0] * M
num = (N * (N - 1)) // 2
for i in range(len(bridges) - 1, -1, -1):
ans[i] = num
a, b = bridges[i]
a, b = a - 1, b - 1
if not UF.same(a, b):
num -= UF.get_group_size(a) * UF.get_group_size(b)
UF.unite(a, b)
print(*ans, sep="\n")
| false | 13.924051 | [
"-# 逆順に見ていく",
"-# M本の橋が全て崩落した状態=全ての島が行き来できない=不便さ:N*(N-1)//2",
"-# 橋ができたら、UnionFindで一つに島グループとしてつなぐ",
"-# 新たにできた橋が、今まで別の島グループだったときは",
"-# 二つの島グループの間の組み合わせの数だけ不便さが減る",
"-# 島グループ1の数 * 島グループ2の数だけ不便さが減る",
"-# 新たにできた島グループが同じ島グループだったときは何も変わらない",
"-# 0-indexed",
"+",
"+",
"- r.add(root(i))",
... | false | 0.037197 | 0.062945 | 0.590936 | [
"s329520394",
"s088423054"
] |
u248424983 | p02412 | python | s952842110 | s968184872 | 1,130 | 850 | 33,308 | 7,676 | Accepted | Accepted | 24.78 | import itertools
while True:
n,x = list(map(int,input().split()))
if n==x==0: break
li = list(itertools.combinations([i+1 for i in range(n)],3))
ret = 0
for i in range(len(li)):
if sum(li[i]) == x: ret+= 1
print(ret) | import itertools
while True:
n,x = list(map(int,input().split()))
if n==x==0: break
ret = 0
for i in itertools.combinations([i+1 for i in range(n)],3):
if sum(i) == x: ret+= 1
print(ret) | 9 | 8 | 256 | 221 | import itertools
while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
li = list(itertools.combinations([i + 1 for i in range(n)], 3))
ret = 0
for i in range(len(li)):
if sum(li[i]) == x:
ret += 1
print(ret)
| import itertools
while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
ret = 0
for i in itertools.combinations([i + 1 for i in range(n)], 3):
if sum(i) == x:
ret += 1
print(ret)
| false | 11.111111 | [
"- li = list(itertools.combinations([i + 1 for i in range(n)], 3))",
"- for i in range(len(li)):",
"- if sum(li[i]) == x:",
"+ for i in itertools.combinations([i + 1 for i in range(n)], 3):",
"+ if sum(i) == x:"
] | false | 0.039096 | 0.067223 | 0.581589 | [
"s952842110",
"s968184872"
] |
u782850731 | p02242 | python | s830577202 | s762778076 | 30 | 20 | 4,392 | 4,672 | Accepted | Accepted | 33.33 | #!/usr/bin/env python
from sys import stdin, maxint
def main():
num = int(stdin.readline())
L = []
for _ in range(num):
L.append([int(s) for s in stdin.readline().split()])
weight = [maxint] * num
weight[0] = 0
V = set(range(1, num))
index = 0
while V:
Li = L[index]
for i in range(Li[1]):
v = Li[i*2+2]
if v not in V:
continue
c = Li[i*2+3]
weight[v] = min(weight[v], c + weight[index])
index = min(V, key=lambda i: weight[i])
V.remove(index)
for i, d in enumerate(weight):
print(i, d)
main() | #!/usr/bin/env python
from sys import stdin, maxint
def main():
num = int(stdin.readline())
L = []
for _ in range(num):
it = iter(int(s) for s in stdin.readline().split()[1:])
L.append([(next(it), next(it)) for _ in range(next(it))])
weight = [maxint] * num
weight[0] = 0
V = set(range(1, num))
index = 0
while V:
for v, cost in L[index]:
if v not in V:
continue
weight[v] = min(weight[v], cost + weight[index])
index = min(V, key=lambda i: weight[i])
V.remove(index)
for i, d in enumerate(weight):
print(i, d)
main() | 34 | 32 | 734 | 732 | #!/usr/bin/env python
from sys import stdin, maxint
def main():
num = int(stdin.readline())
L = []
for _ in range(num):
L.append([int(s) for s in stdin.readline().split()])
weight = [maxint] * num
weight[0] = 0
V = set(range(1, num))
index = 0
while V:
Li = L[index]
for i in range(Li[1]):
v = Li[i * 2 + 2]
if v not in V:
continue
c = Li[i * 2 + 3]
weight[v] = min(weight[v], c + weight[index])
index = min(V, key=lambda i: weight[i])
V.remove(index)
for i, d in enumerate(weight):
print(i, d)
main()
| #!/usr/bin/env python
from sys import stdin, maxint
def main():
num = int(stdin.readline())
L = []
for _ in range(num):
it = iter(int(s) for s in stdin.readline().split()[1:])
L.append([(next(it), next(it)) for _ in range(next(it))])
weight = [maxint] * num
weight[0] = 0
V = set(range(1, num))
index = 0
while V:
for v, cost in L[index]:
if v not in V:
continue
weight[v] = min(weight[v], cost + weight[index])
index = min(V, key=lambda i: weight[i])
V.remove(index)
for i, d in enumerate(weight):
print(i, d)
main()
| false | 5.882353 | [
"- L.append([int(s) for s in stdin.readline().split()])",
"+ it = iter(int(s) for s in stdin.readline().split()[1:])",
"+ L.append([(next(it), next(it)) for _ in range(next(it))])",
"- Li = L[index]",
"- for i in range(Li[1]):",
"- v = Li[i * 2 + 2]",
"+ ... | false | 0.044258 | 0.045584 | 0.970914 | [
"s830577202",
"s762778076"
] |
u753803401 | p02960 | python | s056548798 | s536353378 | 718 | 537 | 63,896 | 61,788 | Accepted | Accepted | 25.21 | def slove():
import sys
input = sys.stdin.readline
s = str(input().rstrip('\n'))
is_first = True
ls = [[0] * 13 for _ in range(len(s))]
mod = 10 ** 9 + 7
for i in range(len(s)):
if is_first:
is_first = False
if s[-i-1] == "?":
for j in range(10):
ls[i][j] += 1
else:
t = int(s[-i-1])
ls[i][t] += 1
else:
mlt = pow(10, i, 13)
if s[-i-1] == "?":
for j in range(13):
for k in range(10):
r = (j + mlt * k) % 13
ls[i][r] += ls[i-1][j]
ls[i][r] %= mod
else:
t = int(s[-i-1])
for j in range(13):
r = (j + mlt * t) % 13
ls[i][r] += ls[i-1][j]
ls[i][r] %= mod
print((ls[-1][5]))
if __name__ == '__main__':
slove()
| import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
s = str(input().rstrip('\n'))
ls = [[0] * 13 for _ in range(len(s))]
for i in range(len(s)):
if i == 0:
if s[-i-1] == "?":
for j in range(10):
ls[i][j] += 1
else:
ls[i][int(s[-i-1])] += 1
else:
mult = pow(10, i, 13)
if s[-i-1] == "?":
for j in range(13):
for k in range(10):
ls[i][(k * mult + j) % 13] += ls[i-1][j]
else:
st = int(s[-i-1])
for j in range(13):
ls[i][(st * mult + j) % 13] += ls[i-1][j]
for j in range(13):
ls[i][j] = ls[i][j] % mod
print((ls[-1][5]))
if __name__ == '__main__':
solve()
| 35 | 32 | 1,031 | 892 | def slove():
import sys
input = sys.stdin.readline
s = str(input().rstrip("\n"))
is_first = True
ls = [[0] * 13 for _ in range(len(s))]
mod = 10**9 + 7
for i in range(len(s)):
if is_first:
is_first = False
if s[-i - 1] == "?":
for j in range(10):
ls[i][j] += 1
else:
t = int(s[-i - 1])
ls[i][t] += 1
else:
mlt = pow(10, i, 13)
if s[-i - 1] == "?":
for j in range(13):
for k in range(10):
r = (j + mlt * k) % 13
ls[i][r] += ls[i - 1][j]
ls[i][r] %= mod
else:
t = int(s[-i - 1])
for j in range(13):
r = (j + mlt * t) % 13
ls[i][r] += ls[i - 1][j]
ls[i][r] %= mod
print((ls[-1][5]))
if __name__ == "__main__":
slove()
| import sys
def solve():
input = sys.stdin.readline
mod = 10**9 + 7
s = str(input().rstrip("\n"))
ls = [[0] * 13 for _ in range(len(s))]
for i in range(len(s)):
if i == 0:
if s[-i - 1] == "?":
for j in range(10):
ls[i][j] += 1
else:
ls[i][int(s[-i - 1])] += 1
else:
mult = pow(10, i, 13)
if s[-i - 1] == "?":
for j in range(13):
for k in range(10):
ls[i][(k * mult + j) % 13] += ls[i - 1][j]
else:
st = int(s[-i - 1])
for j in range(13):
ls[i][(st * mult + j) % 13] += ls[i - 1][j]
for j in range(13):
ls[i][j] = ls[i][j] % mod
print((ls[-1][5]))
if __name__ == "__main__":
solve()
| false | 8.571429 | [
"-def slove():",
"- import sys",
"+import sys",
"+",
"+def solve():",
"+ mod = 10**9 + 7",
"- is_first = True",
"- mod = 10**9 + 7",
"- if is_first:",
"- is_first = False",
"+ if i == 0:",
"- t = int(s[-i - 1])",
"- ls[i][t] ... | false | 0.037801 | 0.124672 | 0.303207 | [
"s056548798",
"s536353378"
] |
u484229314 | p03166 | python | s203913032 | s621015712 | 1,312 | 586 | 168,140 | 23,860 | Accepted | Accepted | 55.34 | import sys
sys.setrecursionlimit(10**5+100)
N, M = [int(_) for _ in input().split()]
E = [[] for _ in range(N)]
indegree = [0] * N # 入次数
for i in range(M):
a, b = [int(_) - 1 for _ in input().split()]
E[a].append(b)
indegree[b] += 1
sorted_nodes = []
dp = [0] * N
def rep(v):
"""初めて呼ばれたときに, そのノードからの最長ノード数を数えるイメージ"""
if dp[v] != 0: return dp[v]
for n in E[v]:
dp[v] = max(dp[v], rep(n) + 1)
return dp[v]
ans = 0
for i in range(N):
ans = max(ans, rep(i))
print(ans)
| from collections import deque
class TPSort:
"""
トポロジカルソート
# https://csacademy.com/lesson/topological_sorting/
# 入次数0のノードから確定し, そのノードから伸びるエッジを削除. を繰り返すことによって DAGのソートをする
"""
def __init__(self, N):
self.N = N
self.indegree = [0] * N # 入次数
self.length = [0] * N
self.edges = [[] for _ in range(N)]
def add_edge(self, a, b):
self.edges[a].append(b)
self.indegree[b] += 1
def sort(self):
que = deque([i for i in range(self.N) if self.indegree[i] == 0])
res = []
while que:
n = que.popleft()
res.append(n)
for next_n in self.edges[n]:
self.length[next_n] = max(self.length[next_n], self.length[n] + 1)
self.indegree[next_n] = self.indegree[next_n] - 1 # 枝刈り
if self.indegree[next_n] == 0: # 入次数0なら queue に追加
que.append(next_n)
return res
if __name__ == '__main__':
n, m = [int(_) for _ in input().split()]
tp = TPSort(n + 1)
for i in range(m):
tp.add_edge(*[int(_) for _ in input().split()])
tp.sort()
print((max(tp.length)))
| 27 | 45 | 538 | 1,219 | import sys
sys.setrecursionlimit(10**5 + 100)
N, M = [int(_) for _ in input().split()]
E = [[] for _ in range(N)]
indegree = [0] * N # 入次数
for i in range(M):
a, b = [int(_) - 1 for _ in input().split()]
E[a].append(b)
indegree[b] += 1
sorted_nodes = []
dp = [0] * N
def rep(v):
"""初めて呼ばれたときに, そのノードからの最長ノード数を数えるイメージ"""
if dp[v] != 0:
return dp[v]
for n in E[v]:
dp[v] = max(dp[v], rep(n) + 1)
return dp[v]
ans = 0
for i in range(N):
ans = max(ans, rep(i))
print(ans)
| from collections import deque
class TPSort:
"""
トポロジカルソート
# https://csacademy.com/lesson/topological_sorting/
# 入次数0のノードから確定し, そのノードから伸びるエッジを削除. を繰り返すことによって DAGのソートをする
"""
def __init__(self, N):
self.N = N
self.indegree = [0] * N # 入次数
self.length = [0] * N
self.edges = [[] for _ in range(N)]
def add_edge(self, a, b):
self.edges[a].append(b)
self.indegree[b] += 1
def sort(self):
que = deque([i for i in range(self.N) if self.indegree[i] == 0])
res = []
while que:
n = que.popleft()
res.append(n)
for next_n in self.edges[n]:
self.length[next_n] = max(self.length[next_n], self.length[n] + 1)
self.indegree[next_n] = self.indegree[next_n] - 1 # 枝刈り
if self.indegree[next_n] == 0: # 入次数0なら queue に追加
que.append(next_n)
return res
if __name__ == "__main__":
n, m = [int(_) for _ in input().split()]
tp = TPSort(n + 1)
for i in range(m):
tp.add_edge(*[int(_) for _ in input().split()])
tp.sort()
print((max(tp.length)))
| false | 40 | [
"-import sys",
"-",
"-sys.setrecursionlimit(10**5 + 100)",
"-N, M = [int(_) for _ in input().split()]",
"-E = [[] for _ in range(N)]",
"-indegree = [0] * N # 入次数",
"-for i in range(M):",
"- a, b = [int(_) - 1 for _ in input().split()]",
"- E[a].append(b)",
"- indegree[b] += 1",
"-sorte... | false | 0.040722 | 0.038147 | 1.067505 | [
"s203913032",
"s621015712"
] |
u531631168 | p02614 | python | s585449997 | s922950515 | 138 | 55 | 9,352 | 9,072 | Accepted | Accepted | 60.14 | import copy
h, w, k = list(map(int, input().split()))
mas_global = [[] for _ in range(h)]
for i in range(h):
mas_global[i] = list(eval(input()))
# a, bはh, wからどれを選ぶかの情報2進数
def calc_black_cnt(a, b):
mas = copy.deepcopy(mas_global)
i = 0
while 1<<i <= a:
if a & 1<<i != 0:
mas[i] = ['r' for _ in range(w)]
i += 1
j = 0
while 1<<j <= b:
if b & 1<<j != 0:
for ii in range(h):
mas[ii][j] = 'r'
j += 1
res = 0
for i in range(h):
res += mas[i].count('#')
return res
ans = 0
for i in range(2**h):
for j in range(2**w):
cnt = calc_black_cnt(i, j)
if cnt == k:
ans += 1
print(ans)
# calc_black_cnt(0, 4) | h, w, k = list(map(int, input().split()))
c = []
for _ in range(h):
c.append(list(eval(input())))
def calc_black_cnt(maskR, maskC):
cnt = 0
for i in range(h):
for j in range(w):
if maskR>>i & 1 == 0 and maskC>>j & 1 == 0 and c[i][j] == '#':
cnt += 1
return cnt
ans = 0
for maskR in range(1<<h):
for maskC in range(1<<w):
if calc_black_cnt(maskR, maskC) == k:
ans += 1
print(ans) | 33 | 17 | 762 | 463 | import copy
h, w, k = list(map(int, input().split()))
mas_global = [[] for _ in range(h)]
for i in range(h):
mas_global[i] = list(eval(input()))
# a, bはh, wからどれを選ぶかの情報2進数
def calc_black_cnt(a, b):
mas = copy.deepcopy(mas_global)
i = 0
while 1 << i <= a:
if a & 1 << i != 0:
mas[i] = ["r" for _ in range(w)]
i += 1
j = 0
while 1 << j <= b:
if b & 1 << j != 0:
for ii in range(h):
mas[ii][j] = "r"
j += 1
res = 0
for i in range(h):
res += mas[i].count("#")
return res
ans = 0
for i in range(2**h):
for j in range(2**w):
cnt = calc_black_cnt(i, j)
if cnt == k:
ans += 1
print(ans)
# calc_black_cnt(0, 4)
| h, w, k = list(map(int, input().split()))
c = []
for _ in range(h):
c.append(list(eval(input())))
def calc_black_cnt(maskR, maskC):
cnt = 0
for i in range(h):
for j in range(w):
if maskR >> i & 1 == 0 and maskC >> j & 1 == 0 and c[i][j] == "#":
cnt += 1
return cnt
ans = 0
for maskR in range(1 << h):
for maskC in range(1 << w):
if calc_black_cnt(maskR, maskC) == k:
ans += 1
print(ans)
| false | 48.484848 | [
"-import copy",
"+h, w, k = list(map(int, input().split()))",
"+c = []",
"+for _ in range(h):",
"+ c.append(list(eval(input())))",
"-h, w, k = list(map(int, input().split()))",
"-mas_global = [[] for _ in range(h)]",
"-for i in range(h):",
"- mas_global[i] = list(eval(input()))",
"-# a, bはh,... | false | 0.049864 | 0.036146 | 1.379505 | [
"s585449997",
"s922950515"
] |
u142415823 | p03201 | python | s030444184 | s688855629 | 439 | 393 | 33,296 | 33,296 | Accepted | Accepted | 10.48 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
c = Counter(A)
ans = 0
for a in A:
b = (1 << a.bit_length()) - a
if a == b and c[a] > 1:
c[a] -= 2
ans += 1
elif a != b and c[a] > 0 and c[b] > 0:
c[a] -= 1
c[b] -= 1
ans += 1
print(ans) | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
c = Counter(A)
ans = 0
for a in A:
b = (1 << a.bit_length()) - a
if b in list(c.keys()):
if a == b and c[a] > 1:
c[a] -= 2
ans += 1
elif a != b and c[a] > 0 and c[b] > 0:
c[a] -= 1
c[b] -= 1
ans += 1
print(ans) | 19 | 20 | 365 | 416 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
c = Counter(A)
ans = 0
for a in A:
b = (1 << a.bit_length()) - a
if a == b and c[a] > 1:
c[a] -= 2
ans += 1
elif a != b and c[a] > 0 and c[b] > 0:
c[a] -= 1
c[b] -= 1
ans += 1
print(ans)
| from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
c = Counter(A)
ans = 0
for a in A:
b = (1 << a.bit_length()) - a
if b in list(c.keys()):
if a == b and c[a] > 1:
c[a] -= 2
ans += 1
elif a != b and c[a] > 0 and c[b] > 0:
c[a] -= 1
c[b] -= 1
ans += 1
print(ans)
| false | 5 | [
"- if a == b and c[a] > 1:",
"- c[a] -= 2",
"- ans += 1",
"- elif a != b and c[a] > 0 and c[b] > 0:",
"- c[a] -= 1",
"- c[b] -= 1",
"- ans += 1",
"+ if b in list(c.keys()):",
"+ if a == b and c[a] > 1:",
"+ c[a] -= 2",
"+ a... | false | 0.064151 | 0.063361 | 1.012481 | [
"s030444184",
"s688855629"
] |
u896726004 | p02596 | python | s317635074 | s056543445 | 195 | 179 | 9,072 | 9,168 | Accepted | Accepted | 8.21 | K = int(eval(input()))
a = 7 % K
for i in range(999983):
if a == 0:
print((i+1))
exit()
a = (a * 10 + 7) % K
print((-1)) | K = int(eval(input()))
a = 7 % K
for i in range(K):
if a == 0:
print((i+1))
exit()
a = (a * 10 + 7) % K
print((-1)) | 11 | 11 | 147 | 145 | K = int(eval(input()))
a = 7 % K
for i in range(999983):
if a == 0:
print((i + 1))
exit()
a = (a * 10 + 7) % K
print((-1))
| K = int(eval(input()))
a = 7 % K
for i in range(K):
if a == 0:
print((i + 1))
exit()
a = (a * 10 + 7) % K
print((-1))
| false | 0 | [
"-for i in range(999983):",
"+for i in range(K):"
] | false | 0.087843 | 0.07988 | 1.099699 | [
"s317635074",
"s056543445"
] |
u002459665 | p02719 | python | s547866159 | s435458092 | 24 | 17 | 3,064 | 3,060 | Accepted | Accepted | 29.17 | N, K = list(map(int, input().split()))
ans = None
if N < K:
ans = min(N, abs(N - K))
else:
N = N % K
ans = min(N, abs(N-K))
print(ans) | N, K = list(map(int, input().split()))
if N == K:
ans = 0
elif N == 0:
ans = 0
elif N > K:
t = N % K
ans = min(t, abs(t-K))
else:
ans = min(N, abs(N-K))
print(ans) | 11 | 13 | 159 | 197 | N, K = list(map(int, input().split()))
ans = None
if N < K:
ans = min(N, abs(N - K))
else:
N = N % K
ans = min(N, abs(N - K))
print(ans)
| N, K = list(map(int, input().split()))
if N == K:
ans = 0
elif N == 0:
ans = 0
elif N > K:
t = N % K
ans = min(t, abs(t - K))
else:
ans = min(N, abs(N - K))
print(ans)
| false | 15.384615 | [
"-ans = None",
"-if N < K:",
"- ans = min(N, abs(N - K))",
"+if N == K:",
"+ ans = 0",
"+elif N == 0:",
"+ ans = 0",
"+elif N > K:",
"+ t = N % K",
"+ ans = min(t, abs(t - K))",
"- N = N % K"
] | false | 0.036118 | 0.04327 | 0.834708 | [
"s547866159",
"s435458092"
] |
u576917603 | p03107 | python | s560847916 | s676545907 | 61 | 21 | 4,904 | 3,956 | Accepted | Accepted | 65.57 | s=list(eval(input()))
x=len(s)
from collections import deque
d=deque()
for i in s:
if len(d)==0:
d.append(i)
elif d[-1]!=i:
d.pop()
elif d[-1]==i:
d.append(i)
print((x-len(d))) | s=list(eval(input()))
c0=s.count('0')
c1=s.count("1")
print((min(c0,c1)*2)) | 14 | 4 | 219 | 70 | s = list(eval(input()))
x = len(s)
from collections import deque
d = deque()
for i in s:
if len(d) == 0:
d.append(i)
elif d[-1] != i:
d.pop()
elif d[-1] == i:
d.append(i)
print((x - len(d)))
| s = list(eval(input()))
c0 = s.count("0")
c1 = s.count("1")
print((min(c0, c1) * 2))
| false | 71.428571 | [
"-x = len(s)",
"-from collections import deque",
"-",
"-d = deque()",
"-for i in s:",
"- if len(d) == 0:",
"- d.append(i)",
"- elif d[-1] != i:",
"- d.pop()",
"- elif d[-1] == i:",
"- d.append(i)",
"-print((x - len(d)))",
"+c0 = s.count(\"0\")",
"+c1 = s.count... | false | 0.086027 | 0.075802 | 1.134884 | [
"s560847916",
"s676545907"
] |
u266014018 | p02727 | python | s981525331 | s469416482 | 243 | 162 | 23,328 | 29,508 | Accepted | Accepted | 33.33 | X,Y,A,B,C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
P = P[:X]
Q = Q[:Y]
All = P + Q + R
All.sort(reverse = True)
print((sum(All[:X+Y]))) | def main():
import sys
def input(): return sys.stdin.readline().rstrip()
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r = p[:x]+q[:y]+r
r.sort(reverse=True)
print((sum(r[:x+y])))
if __name__ == '__main__':
main() | 12 | 17 | 302 | 424 | X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
P = P[:X]
Q = Q[:Y]
All = P + Q + R
All.sort(reverse=True)
print((sum(All[: X + Y])))
| def main():
import sys
def input():
return sys.stdin.readline().rstrip()
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r = p[:x] + q[:y] + r
r.sort(reverse=True)
print((sum(r[: x + y])))
if __name__ == "__main__":
main()
| false | 29.411765 | [
"-X, Y, A, B, C = list(map(int, input().split()))",
"-P = list(map(int, input().split()))",
"-Q = list(map(int, input().split()))",
"-R = list(map(int, input().split()))",
"-P.sort(reverse=True)",
"-Q.sort(reverse=True)",
"-R.sort(reverse=True)",
"-P = P[:X]",
"-Q = Q[:Y]",
"-All = P + Q + R",
"... | false | 0.051037 | 0.037164 | 1.37331 | [
"s981525331",
"s469416482"
] |
u227082700 | p03221 | python | s892658804 | s523964954 | 1,210 | 511 | 99,928 | 50,108 | Accepted | Accepted | 57.77 | n,m = list(map(int,input().split()))
py = []
for i in range(m):
py.append(list(map(int,input().split())))
py[i].append(i)
py.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
if x != py[i][0]:
j = 1
x = py[i][0]
else:
j+=1
s = str(py[i][0]).zfill(6) + str(j).zfill(6)
py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
print((py[i][3])) | n,m=list(map(int,input().split()))
e=[[]for _ in range(n)]
py=[]
for _ in range(m):
p,y=list(map(int,input().split()))
py.append((p,y))
e[p-1].append(y)
for i in range(n):e[i].sort()
xy=lambda x,y:y*1000000+x
d={}
for i in range(n):
for j in range(len(e[i])):
d[xy(i+1,e[i][j])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for p,y in py:
print((d[xy(p,y)]))
| 20 | 15 | 447 | 364 | n, m = list(map(int, input().split()))
py = []
for i in range(m):
py.append(list(map(int, input().split())))
py[i].append(i)
py.sort(key=lambda x: x[1])
py.sort(key=lambda x: x[0])
x = py[0][0]
j = 0
for i in range(m):
if x != py[i][0]:
j = 1
x = py[i][0]
else:
j += 1
s = str(py[i][0]).zfill(6) + str(j).zfill(6)
py[i].append(s)
py.sort(key=lambda x: x[2])
for i in range(m):
print((py[i][3]))
| n, m = list(map(int, input().split()))
e = [[] for _ in range(n)]
py = []
for _ in range(m):
p, y = list(map(int, input().split()))
py.append((p, y))
e[p - 1].append(y)
for i in range(n):
e[i].sort()
xy = lambda x, y: y * 1000000 + x
d = {}
for i in range(n):
for j in range(len(e[i])):
d[xy(i + 1, e[i][j])] = str(i + 1).zfill(6) + str(j + 1).zfill(6)
for p, y in py:
print((d[xy(p, y)]))
| false | 25 | [
"+e = [[] for _ in range(n)]",
"-for i in range(m):",
"- py.append(list(map(int, input().split())))",
"- py[i].append(i)",
"-py.sort(key=lambda x: x[1])",
"-py.sort(key=lambda x: x[0])",
"-x = py[0][0]",
"-j = 0",
"-for i in range(m):",
"- if x != py[i][0]:",
"- j = 1",
"- ... | false | 0.115086 | 0.04281 | 2.688288 | [
"s892658804",
"s523964954"
] |
u989345508 | p03401 | python | s247939980 | s590032439 | 301 | 233 | 59,116 | 14,048 | Accepted | Accepted | 22.59 | n=int(eval(input()))
a=list(map(int,input().split()))
base=0
for i in range(n+1):
if i==0:
base+=abs(a[0])
elif i==n:
base+=abs(a[n-1])
else:
base+=abs(a[i]-a[i-1])
ans=[]
for i in range(n):
if i==0:
ans.append(base+abs(a[1])-abs(a[0])-abs(a[1]-a[0]))
elif i==n-1:
ans.append(base+abs(a[n-2])-abs(a[n-1])-abs(a[n-2]-a[n-1]))
else:
ans.append(base+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1]))
for i in range(n):
print((ans[i])) | n=int(eval(input()))
a=list(map(int,input().split()))
b=[0]
b.extend(a)
b.append(0)
a=b
base=0
for i in range(n+1):
base+=abs(a[i+1]-a[i])
ans=[]
for i in range(1,n+1):
ans.append(base+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1]))
for i in range(n):
print((ans[i])) | 20 | 14 | 522 | 290 | n = int(eval(input()))
a = list(map(int, input().split()))
base = 0
for i in range(n + 1):
if i == 0:
base += abs(a[0])
elif i == n:
base += abs(a[n - 1])
else:
base += abs(a[i] - a[i - 1])
ans = []
for i in range(n):
if i == 0:
ans.append(base + abs(a[1]) - abs(a[0]) - abs(a[1] - a[0]))
elif i == n - 1:
ans.append(base + abs(a[n - 2]) - abs(a[n - 1]) - abs(a[n - 2] - a[n - 1]))
else:
ans.append(
base
+ abs(a[i + 1] - a[i - 1])
- abs(a[i + 1] - a[i])
- abs(a[i] - a[i - 1])
)
for i in range(n):
print((ans[i]))
| n = int(eval(input()))
a = list(map(int, input().split()))
b = [0]
b.extend(a)
b.append(0)
a = b
base = 0
for i in range(n + 1):
base += abs(a[i + 1] - a[i])
ans = []
for i in range(1, n + 1):
ans.append(
base + abs(a[i + 1] - a[i - 1]) - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1])
)
for i in range(n):
print((ans[i]))
| false | 30 | [
"+b = [0]",
"+b.extend(a)",
"+b.append(0)",
"+a = b",
"- if i == 0:",
"- base += abs(a[0])",
"- elif i == n:",
"- base += abs(a[n - 1])",
"- else:",
"- base += abs(a[i] - a[i - 1])",
"+ base += abs(a[i + 1] - a[i])",
"-for i in range(n):",
"- if i == 0:",
... | false | 0.045811 | 0.088383 | 0.518324 | [
"s247939980",
"s590032439"
] |
u367130284 | p03032 | python | s159089113 | s600902659 | 24 | 22 | 3,316 | 3,188 | Accepted | Accepted | 8.33 | from heapq import*
n,k=list(map(int,input().split()))
*v,=list(map(int,input().split()))
motimono=[]
ans=[]
if k>=n:
k-=n
heapify(v)
ans.append(sum(v))
for i in range(k):
if len(v)>0:
heappop(v)
ans.append(sum(v))
print((max(ans)))
else:
v*=2
for j in range(1,k+1):
for i in range(n-j,n+1):
motimono=v[i:i+j]
ans.append(sum(motimono))
heapify(motimono)
for i in range(k-j):
if len(motimono)>0:
heappop(motimono)
ans.append(sum(motimono))
print((max(ans))) | n,k=list(map(int,input().split()))
*v,=list(map(int,input().split()))
motimono=[]
ans=[]
if k>=n:
k-=n
ans.append(sum(v))
v.sort()
for i in range(min(k,len(v))):
v[i]=0
ans.append(sum(v))
print((max(ans)))
else:
v*=2
for j in range(1,k+1):
for i in range(n-j,n+1):
motimono=v[i:i+j]
ans.append(sum(motimono))
motimono.sort()
for i in range(min(k-j,len(motimono))):
motimono[i]=0
ans.append(sum(motimono))
print((max(ans)))
| 26 | 23 | 632 | 565 | from heapq import *
n, k = list(map(int, input().split()))
(*v,) = list(map(int, input().split()))
motimono = []
ans = []
if k >= n:
k -= n
heapify(v)
ans.append(sum(v))
for i in range(k):
if len(v) > 0:
heappop(v)
ans.append(sum(v))
print((max(ans)))
else:
v *= 2
for j in range(1, k + 1):
for i in range(n - j, n + 1):
motimono = v[i : i + j]
ans.append(sum(motimono))
heapify(motimono)
for i in range(k - j):
if len(motimono) > 0:
heappop(motimono)
ans.append(sum(motimono))
print((max(ans)))
| n, k = list(map(int, input().split()))
(*v,) = list(map(int, input().split()))
motimono = []
ans = []
if k >= n:
k -= n
ans.append(sum(v))
v.sort()
for i in range(min(k, len(v))):
v[i] = 0
ans.append(sum(v))
print((max(ans)))
else:
v *= 2
for j in range(1, k + 1):
for i in range(n - j, n + 1):
motimono = v[i : i + j]
ans.append(sum(motimono))
motimono.sort()
for i in range(min(k - j, len(motimono))):
motimono[i] = 0
ans.append(sum(motimono))
print((max(ans)))
| false | 11.538462 | [
"-from heapq import *",
"-",
"- heapify(v)",
"- for i in range(k):",
"- if len(v) > 0:",
"- heappop(v)",
"+ v.sort()",
"+ for i in range(min(k, len(v))):",
"+ v[i] = 0",
"- heapify(motimono)",
"- for i in range(k - j):",
"- ... | false | 0.091016 | 0.083227 | 1.093591 | [
"s159089113",
"s600902659"
] |
u272028993 | p03818 | python | s180286536 | s955338844 | 104 | 80 | 11,304 | 11,304 | Accepted | Accepted | 23.08 | n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(max(a)+1)
for i in range(n):
cnt[a[i]]+=1
for i in range(max(a)+1):
while cnt[i]>=3:
cnt[i]=cnt[i]/3+cnt[i]%3
ans=0
cnt1=0
cnt2=0
tmp=0
for i in range(max(a)+1):
if cnt[i]==2:
cnt2+=1
tmp+=2
if cnt[i]==1:
cnt1+=1
if cnt2%2==1:
print((cnt1+tmp/2-1))
else:
print((cnt1+tmp/2))
| n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(10**5+1)
for i in range(n):
cnt[a[i]]+=1
cnt1=0
cnt2=0
for i in range(10**5+1):
if cnt[i]==0:continue
if cnt[i]%2==0:
cnt2+=1
else:
cnt1+=1
if cnt2%2==0:
print(cnt1+cnt2)
else:
print(cnt1+cnt2-1)
| 22 | 17 | 410 | 311 | n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (max(a) + 1)
for i in range(n):
cnt[a[i]] += 1
for i in range(max(a) + 1):
while cnt[i] >= 3:
cnt[i] = cnt[i] / 3 + cnt[i] % 3
ans = 0
cnt1 = 0
cnt2 = 0
tmp = 0
for i in range(max(a) + 1):
if cnt[i] == 2:
cnt2 += 1
tmp += 2
if cnt[i] == 1:
cnt1 += 1
if cnt2 % 2 == 1:
print((cnt1 + tmp / 2 - 1))
else:
print((cnt1 + tmp / 2))
| n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (10**5 + 1)
for i in range(n):
cnt[a[i]] += 1
cnt1 = 0
cnt2 = 0
for i in range(10**5 + 1):
if cnt[i] == 0:
continue
if cnt[i] % 2 == 0:
cnt2 += 1
else:
cnt1 += 1
if cnt2 % 2 == 0:
print(cnt1 + cnt2)
else:
print(cnt1 + cnt2 - 1)
| false | 22.727273 | [
"-cnt = [0] * (max(a) + 1)",
"+cnt = [0] * (10**5 + 1)",
"-for i in range(max(a) + 1):",
"- while cnt[i] >= 3:",
"- cnt[i] = cnt[i] / 3 + cnt[i] % 3",
"-ans = 0",
"-tmp = 0",
"-for i in range(max(a) + 1):",
"- if cnt[i] == 2:",
"+for i in range(10**5 + 1):",
"+ if cnt[i] == 0:",
... | false | 0.091317 | 0.325575 | 0.28048 | [
"s180286536",
"s955338844"
] |
u077291787 | p02791 | python | s738190683 | s684431081 | 106 | 76 | 25,116 | 25,116 | Accepted | Accepted | 28.3 | # C - Low Elements
def main():
N, *P = list(map(int, open(0).read().split()))
ans, cur_min = 0, P[0]
for i in P:
if i <= cur_min:
ans += 1
cur_min = min(cur_min, i)
print(ans)
if __name__ == "__main__":
main()
| # C - Low Elements
def main():
N, *P = list(map(int, open(0).read().split()))
ans, cur_min = 0, P[0]
for i in P:
if i <= cur_min:
ans += 1
cur_min = i
print(ans)
if __name__ == "__main__":
main()
| 13 | 13 | 266 | 256 | # C - Low Elements
def main():
N, *P = list(map(int, open(0).read().split()))
ans, cur_min = 0, P[0]
for i in P:
if i <= cur_min:
ans += 1
cur_min = min(cur_min, i)
print(ans)
if __name__ == "__main__":
main()
| # C - Low Elements
def main():
N, *P = list(map(int, open(0).read().split()))
ans, cur_min = 0, P[0]
for i in P:
if i <= cur_min:
ans += 1
cur_min = i
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- cur_min = min(cur_min, i)",
"+ cur_min = i"
] | false | 0.040966 | 0.048692 | 0.841326 | [
"s738190683",
"s684431081"
] |
u879870653 | p03164 | python | s047735737 | s692532998 | 385 | 352 | 54,144 | 54,144 | Accepted | Accepted | 8.57 | N,W = list(map(int,input().split()))
L = list(list(map(int,input().split())) for i in range(N))
upper = 10**5
dp = [float("inf") for i in range(upper+1)]
dp[0] = 0
for item in range(N) :
weight_i,value_i = L[item]
for value in range(upper, value_i-1, -1) :
if dp[value - value_i] + weight_i <= W :
dp[value] = min(dp[value], dp[value - value_i] + weight_i)
for value in range(upper, -1, -1) :
if dp[value] < float("inf") :
ans = value
break
print(ans)
| N,W = list(map(int,input().split()))
L = list(list(map(int,input().split())) for i in range(N))
upper = 10**5
dp = [float("inf") for i in range(upper+1)] #dp[i] = "価値の総和=i"の最小重さ
dp[0] = 0
for item in range(N) :
weight_i,value_i = L[item]
for value in range(upper, value_i-1, -1) :
if dp[value - value_i] + weight_i <= W :
dp[value] = min(dp[value], dp[value - value_i] + weight_i)
for value in range(upper, -1, -1) :
if dp[value] < float("inf") :
ans = value
break
print(ans)
| 19 | 18 | 516 | 538 | N, W = list(map(int, input().split()))
L = list(list(map(int, input().split())) for i in range(N))
upper = 10**5
dp = [float("inf") for i in range(upper + 1)]
dp[0] = 0
for item in range(N):
weight_i, value_i = L[item]
for value in range(upper, value_i - 1, -1):
if dp[value - value_i] + weight_i <= W:
dp[value] = min(dp[value], dp[value - value_i] + weight_i)
for value in range(upper, -1, -1):
if dp[value] < float("inf"):
ans = value
break
print(ans)
| N, W = list(map(int, input().split()))
L = list(list(map(int, input().split())) for i in range(N))
upper = 10**5
dp = [float("inf") for i in range(upper + 1)] # dp[i] = "価値の総和=i"の最小重さ
dp[0] = 0
for item in range(N):
weight_i, value_i = L[item]
for value in range(upper, value_i - 1, -1):
if dp[value - value_i] + weight_i <= W:
dp[value] = min(dp[value], dp[value - value_i] + weight_i)
for value in range(upper, -1, -1):
if dp[value] < float("inf"):
ans = value
break
print(ans)
| false | 5.263158 | [
"-dp = [float(\"inf\") for i in range(upper + 1)]",
"+dp = [float(\"inf\") for i in range(upper + 1)] # dp[i] = \"価値の総和=i\"の最小重さ"
] | false | 0.393344 | 0.178344 | 2.205537 | [
"s047735737",
"s692532998"
] |
u955547613 | p02767 | python | s255104422 | s547286835 | 21 | 17 | 3,064 | 2,940 | Accepted | Accepted | 19.05 | def main():
n = eval(input())
array = list(map(int, input().split(" ")))
minX = min(array)
maxX = max(array)
p_sum = 0
power_list = []
for p in range(minX, maxX + 1):
for x in array:
p_sum += power(x, p)
power_list.append(p_sum)
p_sum = 0
print((min(power_list)))
def power(x, p):
return (x - p)**2
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
x = [int(i) for i in input().split()]
min_x = round(sum(x) / n)
ans = sum([(min_x - i)**2 for i in x])
print(ans)
if __name__ == "__main__":
main()
| 19 | 9 | 429 | 210 | def main():
n = eval(input())
array = list(map(int, input().split(" ")))
minX = min(array)
maxX = max(array)
p_sum = 0
power_list = []
for p in range(minX, maxX + 1):
for x in array:
p_sum += power(x, p)
power_list.append(p_sum)
p_sum = 0
print((min(power_list)))
def power(x, p):
return (x - p) ** 2
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
x = [int(i) for i in input().split()]
min_x = round(sum(x) / n)
ans = sum([(min_x - i) ** 2 for i in x])
print(ans)
if __name__ == "__main__":
main()
| false | 52.631579 | [
"- n = eval(input())",
"- array = list(map(int, input().split(\" \")))",
"- minX = min(array)",
"- maxX = max(array)",
"- p_sum = 0",
"- power_list = []",
"- for p in range(minX, maxX + 1):",
"- for x in array:",
"- p_sum += power(x, p)",
"- power_list... | false | 0.040187 | 0.040597 | 0.9899 | [
"s255104422",
"s547286835"
] |
u128456980 | p02775 | python | s502401964 | s897346121 | 670 | 531 | 157,628 | 137,952 | Accepted | Accepted | 20.75 | s = eval(input())
n = len(s)
dp = [ [0,1e18] for i in range(n+1) ]
for i in range(n):
d = int(s[i])
dp[i+1][0] = min(dp[i][0], dp[i][1])+d
dp[i+1][1] = min(dp[i][0], dp[i][1]-2)+11-d
print((min(dp[n][0],dp[n][1]))) | s = eval(input()); n = len(s); INF=1<<32
dp = [ [0,INF] for i in range(n+1) ]
for i in range(n):
d = int(s[i])
dp[i+1][0] = min(dp[i][0], dp[i][1])+d
dp[i+1][1] = min(dp[i][0], dp[i][1]-2)+11-d
print((min(dp[n][0],dp[n][1]))) | 8 | 7 | 219 | 229 | s = eval(input())
n = len(s)
dp = [[0, 1e18] for i in range(n + 1)]
for i in range(n):
d = int(s[i])
dp[i + 1][0] = min(dp[i][0], dp[i][1]) + d
dp[i + 1][1] = min(dp[i][0], dp[i][1] - 2) + 11 - d
print((min(dp[n][0], dp[n][1])))
| s = eval(input())
n = len(s)
INF = 1 << 32
dp = [[0, INF] for i in range(n + 1)]
for i in range(n):
d = int(s[i])
dp[i + 1][0] = min(dp[i][0], dp[i][1]) + d
dp[i + 1][1] = min(dp[i][0], dp[i][1] - 2) + 11 - d
print((min(dp[n][0], dp[n][1])))
| false | 12.5 | [
"-dp = [[0, 1e18] for i in range(n + 1)]",
"+INF = 1 << 32",
"+dp = [[0, INF] for i in range(n + 1)]"
] | false | 0.090931 | 0.075707 | 1.201084 | [
"s502401964",
"s897346121"
] |
u647766105 | p00008 | python | s792104929 | s215619978 | 170 | 130 | 5,068 | 5,068 | Accepted | Accepted | 23.53 | import sys
table={}
def dfs(a,b):
global table
if not a in table:
if a==0:return 1
elif b==0 or a < 0:return 0
table[(a,b)]=sum([dfs(a-i,b-1) for i in range(10)])
return table[(a,b)]
for i in sys.stdin.readlines():
print(dfs(int(i.strip()),4)) | import sys
def dfs(a,b):
if a==0:return 1
elif b==0 or a < 0:return 0
return sum([dfs(a-i,b-1) for i in range(10)])
for line in sys.stdin.readlines():
print(dfs(int(line.strip()),4)) | 11 | 7 | 293 | 204 | import sys
table = {}
def dfs(a, b):
global table
if not a in table:
if a == 0:
return 1
elif b == 0 or a < 0:
return 0
table[(a, b)] = sum([dfs(a - i, b - 1) for i in range(10)])
return table[(a, b)]
for i in sys.stdin.readlines():
print(dfs(int(i.strip()), 4))
| import sys
def dfs(a, b):
if a == 0:
return 1
elif b == 0 or a < 0:
return 0
return sum([dfs(a - i, b - 1) for i in range(10)])
for line in sys.stdin.readlines():
print(dfs(int(line.strip()), 4))
| false | 36.363636 | [
"-",
"-table = {}",
"- global table",
"- if not a in table:",
"- if a == 0:",
"- return 1",
"- elif b == 0 or a < 0:",
"- return 0",
"- table[(a, b)] = sum([dfs(a - i, b - 1) for i in range(10)])",
"- return table[(a, b)]",
"+ if a == 0:",
... | false | 0.110091 | 0.050258 | 2.190506 | [
"s792104929",
"s215619978"
] |
u504562455 | p02714 | python | s917310262 | s531757516 | 273 | 232 | 69,220 | 68,584 | Accepted | Accepted | 15.02 | N = int(eval(input()))
S = eval(input())
r = 0
g = 0
b = 0
cnt_S = []
for i, s in enumerate(S):
if s == 'R':
r += 1
elif s == 'G':
g += 1
else:
b += 1
cnt_S.append([r, g, b])
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
if S[i] == 'R':
if S[j] == 'G':
ans += cnt_S[-1][2] - cnt_S[j][2]
if 2 * j - i < N and S[j + j - i] == 'B':
ans -= 1
if S[j] == 'B':
ans += cnt_S[-1][1] - cnt_S[j][1]
if 2 * j - i < N and S[j + j - i] == 'G':
ans -= 1
elif S[i] == 'G':
if S[j] == 'R':
ans += cnt_S[-1][2] - cnt_S[j][2]
if 2 * j - i < N and S[j + j - i] == 'B':
ans -= 1
if S[j] == 'B':
ans += cnt_S[-1][0] - cnt_S[j][0]
if 2 * j - i < N and S[j + j - i] == 'R':
ans -= 1
else:
if S[j] == 'R':
ans += cnt_S[-1][1] - cnt_S[j][1]
if 2 * j - i < N and S[j + j - i] == 'G':
ans -= 1
if S[j] == 'G':
ans += cnt_S[-1][0] - cnt_S[j][0]
if 2 * j - i < N and S[j + j - i] == 'R':
ans -= 1
print(ans)
| N = int(eval(input()))
S = eval(input())
r = 0
g = 0
b = 0
for i, s in enumerate(S):
if s == 'R':
r += 1
elif s == 'G':
g += 1
else:
b += 1
ans = r * g * b
for i in range(N-2):
for j in range(i+1, N-1):
if S[i] == 'R':
if S[j] == 'G':
if 2 * j - i < N and S[j + j - i] == 'B':
ans -= 1
if S[j] == 'B':
if 2 * j - i < N and S[j + j - i] == 'G':
ans -= 1
elif S[i] == 'G':
if S[j] == 'R':
if 2 * j - i < N and S[j + j - i] == 'B':
ans -= 1
if S[j] == 'B':
if 2 * j - i < N and S[j + j - i] == 'R':
ans -= 1
else:
if S[j] == 'R':
if 2 * j - i < N and S[j + j - i] == 'G':
ans -= 1
if S[j] == 'G':
if 2 * j - i < N and S[j + j - i] == 'R':
ans -= 1
print(ans)
| 50 | 42 | 1,381 | 1,042 | N = int(eval(input()))
S = eval(input())
r = 0
g = 0
b = 0
cnt_S = []
for i, s in enumerate(S):
if s == "R":
r += 1
elif s == "G":
g += 1
else:
b += 1
cnt_S.append([r, g, b])
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if S[i] == "R":
if S[j] == "G":
ans += cnt_S[-1][2] - cnt_S[j][2]
if 2 * j - i < N and S[j + j - i] == "B":
ans -= 1
if S[j] == "B":
ans += cnt_S[-1][1] - cnt_S[j][1]
if 2 * j - i < N and S[j + j - i] == "G":
ans -= 1
elif S[i] == "G":
if S[j] == "R":
ans += cnt_S[-1][2] - cnt_S[j][2]
if 2 * j - i < N and S[j + j - i] == "B":
ans -= 1
if S[j] == "B":
ans += cnt_S[-1][0] - cnt_S[j][0]
if 2 * j - i < N and S[j + j - i] == "R":
ans -= 1
else:
if S[j] == "R":
ans += cnt_S[-1][1] - cnt_S[j][1]
if 2 * j - i < N and S[j + j - i] == "G":
ans -= 1
if S[j] == "G":
ans += cnt_S[-1][0] - cnt_S[j][0]
if 2 * j - i < N and S[j + j - i] == "R":
ans -= 1
print(ans)
| N = int(eval(input()))
S = eval(input())
r = 0
g = 0
b = 0
for i, s in enumerate(S):
if s == "R":
r += 1
elif s == "G":
g += 1
else:
b += 1
ans = r * g * b
for i in range(N - 2):
for j in range(i + 1, N - 1):
if S[i] == "R":
if S[j] == "G":
if 2 * j - i < N and S[j + j - i] == "B":
ans -= 1
if S[j] == "B":
if 2 * j - i < N and S[j + j - i] == "G":
ans -= 1
elif S[i] == "G":
if S[j] == "R":
if 2 * j - i < N and S[j + j - i] == "B":
ans -= 1
if S[j] == "B":
if 2 * j - i < N and S[j + j - i] == "R":
ans -= 1
else:
if S[j] == "R":
if 2 * j - i < N and S[j + j - i] == "G":
ans -= 1
if S[j] == "G":
if 2 * j - i < N and S[j + j - i] == "R":
ans -= 1
print(ans)
| false | 16 | [
"-cnt_S = []",
"- cnt_S.append([r, g, b])",
"-ans = 0",
"+ans = r * g * b",
"- ans += cnt_S[-1][2] - cnt_S[j][2]",
"- ans += cnt_S[-1][1] - cnt_S[j][1]",
"- ans += cnt_S[-1][2] - cnt_S[j][2]",
"- ans += cnt_S[-1][0] - cnt_S[j][0]",
"- ... | false | 0.055811 | 0.065957 | 0.846163 | [
"s917310262",
"s531757516"
] |
u026075806 | p03229 | python | s050012902 | s311470135 | 1,743 | 211 | 9,328 | 8,532 | Accepted | Accepted | 87.89 | def main():
N = int(eval(input()))
array = [int(eval(input())) for _ in range(N)]
array.sort()
div, mod = divmod(N, 2)
if mod == 0:
fore, last_in_fore, first_in_rear, rear = array[:div-1], array[div-1], array[div], array[div+1:]
a = 2 * sum(rear) + first_in_rear - last_in_fore - 2 * sum(fore)
print(a)
return
else:
#mode1 (mrfrm):(1,2,-2,2,1)
array1=array[:]
fore1=[]
rear1=[]
while True:
fore1.append(array1.pop(0))
if len(array1) <= 2:
break
rear1.append(array1.pop(-1))
mid1 = array1
a1 = 2 * sum(rear1) + sum(mid1) - 2 * sum(fore1)
#mode2 (mfrfm):(1,-2,2,-2,1)
array2 = array[:]
fore2=[]
rear2=[]
while True:
rear2.append(array2.pop(-1))
if len(array2) <= 2:
break
fore2.append(array2.pop(0))
mid2 = array2
a2 = 2 * sum(rear2) - sum(mid2) - 2 * sum(fore2)
print((max(a1, a2)))
return
return
main() | def main():
N = int(eval(input()))
array = [int(eval(input())) for _ in range(N)]
array.sort()
div, mod = divmod(N, 2)
if mod == 0:
fore, last_in_fore, first_in_rear, rear = array[:div-1], array[div-1], array[div], array[div+1:]
a = 2 * sum(rear) + first_in_rear - last_in_fore - 2 * sum(fore)
print(a)
return
else:
#mode1 (mfrfm):(1,-2,2,-2,1)
fore1, mid1, rear1 = array[:div], array[div:div+2], array[div+2:]
a1 = -2 * sum(fore1) + sum(mid1) + 2 * sum(rear1)
#mode2 (mrfrm):(1,2,-2,2,1)
fore2, mid2, rear2 = array[:div-1], array[div-1:div+1], array[div+1:]
a2 = -2 * sum(fore2) - sum(mid2) + 2 * sum(rear2)
print((max(a1, a2)))
return
return
main() | 43 | 25 | 1,128 | 788 | def main():
N = int(eval(input()))
array = [int(eval(input())) for _ in range(N)]
array.sort()
div, mod = divmod(N, 2)
if mod == 0:
fore, last_in_fore, first_in_rear, rear = (
array[: div - 1],
array[div - 1],
array[div],
array[div + 1 :],
)
a = 2 * sum(rear) + first_in_rear - last_in_fore - 2 * sum(fore)
print(a)
return
else:
# mode1 (mrfrm):(1,2,-2,2,1)
array1 = array[:]
fore1 = []
rear1 = []
while True:
fore1.append(array1.pop(0))
if len(array1) <= 2:
break
rear1.append(array1.pop(-1))
mid1 = array1
a1 = 2 * sum(rear1) + sum(mid1) - 2 * sum(fore1)
# mode2 (mfrfm):(1,-2,2,-2,1)
array2 = array[:]
fore2 = []
rear2 = []
while True:
rear2.append(array2.pop(-1))
if len(array2) <= 2:
break
fore2.append(array2.pop(0))
mid2 = array2
a2 = 2 * sum(rear2) - sum(mid2) - 2 * sum(fore2)
print((max(a1, a2)))
return
return
main()
| def main():
N = int(eval(input()))
array = [int(eval(input())) for _ in range(N)]
array.sort()
div, mod = divmod(N, 2)
if mod == 0:
fore, last_in_fore, first_in_rear, rear = (
array[: div - 1],
array[div - 1],
array[div],
array[div + 1 :],
)
a = 2 * sum(rear) + first_in_rear - last_in_fore - 2 * sum(fore)
print(a)
return
else:
# mode1 (mfrfm):(1,-2,2,-2,1)
fore1, mid1, rear1 = array[:div], array[div : div + 2], array[div + 2 :]
a1 = -2 * sum(fore1) + sum(mid1) + 2 * sum(rear1)
# mode2 (mrfrm):(1,2,-2,2,1)
fore2, mid2, rear2 = (
array[: div - 1],
array[div - 1 : div + 1],
array[div + 1 :],
)
a2 = -2 * sum(fore2) - sum(mid2) + 2 * sum(rear2)
print((max(a1, a2)))
return
return
main()
| false | 41.860465 | [
"- # mode1 (mrfrm):(1,2,-2,2,1)",
"- array1 = array[:]",
"- fore1 = []",
"- rear1 = []",
"- while True:",
"- fore1.append(array1.pop(0))",
"- if len(array1) <= 2:",
"- break",
"- rear1.append(array1.pop(-1))",
"- ... | false | 0.045681 | 0.037834 | 1.20739 | [
"s050012902",
"s311470135"
] |
u619819312 | p03242 | python | s756660469 | s413877808 | 22 | 18 | 3,572 | 2,940 | Accepted | Accepted | 18.18 | from functools import reduce
n=int(eval(input()))
s=[int(x) for x in list(str(n))]
for i in range(0,len(s)):
if s[i]==1:
s[i]=9
else:
s[i]=1
print((int(reduce(lambda x, y: x + y, [str(x) for x in s])))) | n=list(eval(input()))
p=""
for i in range(len(n)):
n[i]=10-int(n[i])
p+=str(n[i])
print(p) | 9 | 6 | 226 | 97 | from functools import reduce
n = int(eval(input()))
s = [int(x) for x in list(str(n))]
for i in range(0, len(s)):
if s[i] == 1:
s[i] = 9
else:
s[i] = 1
print((int(reduce(lambda x, y: x + y, [str(x) for x in s]))))
| n = list(eval(input()))
p = ""
for i in range(len(n)):
n[i] = 10 - int(n[i])
p += str(n[i])
print(p)
| false | 33.333333 | [
"-from functools import reduce",
"-",
"-n = int(eval(input()))",
"-s = [int(x) for x in list(str(n))]",
"-for i in range(0, len(s)):",
"- if s[i] == 1:",
"- s[i] = 9",
"- else:",
"- s[i] = 1",
"-print((int(reduce(lambda x, y: x + y, [str(x) for x in s]))))",
"+n = list(eval(i... | false | 0.034998 | 0.037302 | 0.938222 | [
"s756660469",
"s413877808"
] |
u843175622 | p03546 | python | s614658009 | s918455330 | 406 | 40 | 25,244 | 9,148 | Accepted | Accepted | 90.15 | from scipy.sparse.csgraph import johnson
h, w = list(map(int, input().split()))
c = johnson([list(map(int, input().split())) for _ in range(10)])
ans = 0
for _ in range(h):
for j in map(int, input().split()):
ans += (j != -1) * int(c[j][1])
print(ans) | h, w = list(map(int, input().split()))
g = []
for _ in range(10):
a = list(map(int, input().split()))
g.append(a)
for k in range(10):
for i in range(10):
for j in range(10):
g[i][j] = min(g[i][j], g[i][k] + g[k][j])
ans = 0
for i in range(h):
ans += sum([g[x][1] for x in [x for x in map(int, input().split()) if x != -1]])
print(ans)
| 9 | 17 | 266 | 411 | from scipy.sparse.csgraph import johnson
h, w = list(map(int, input().split()))
c = johnson([list(map(int, input().split())) for _ in range(10)])
ans = 0
for _ in range(h):
for j in map(int, input().split()):
ans += (j != -1) * int(c[j][1])
print(ans)
| h, w = list(map(int, input().split()))
g = []
for _ in range(10):
a = list(map(int, input().split()))
g.append(a)
for k in range(10):
for i in range(10):
for j in range(10):
g[i][j] = min(g[i][j], g[i][k] + g[k][j])
ans = 0
for i in range(h):
ans += sum([g[x][1] for x in [x for x in map(int, input().split()) if x != -1]])
print(ans)
| false | 47.058824 | [
"-from scipy.sparse.csgraph import johnson",
"-",
"-c = johnson([list(map(int, input().split())) for _ in range(10)])",
"+g = []",
"+for _ in range(10):",
"+ a = list(map(int, input().split()))",
"+ g.append(a)",
"+for k in range(10):",
"+ for i in range(10):",
"+ for j in range(10... | false | 0.715811 | 0.08761 | 8.170425 | [
"s614658009",
"s918455330"
] |
u794173881 | p03073 | python | s252594446 | s608512479 | 189 | 67 | 49,620 | 3,956 | Accepted | Accepted | 64.55 | s = list(eval(input()))
ans = 0
for i in range(1,len(s)):
if s[i] == "0" and s[i-1] == "0":
s[i] = "1"
ans += 1
if s[i] == "1" and s[i-1] == "1":
s[i] = "0"
ans += 1
print(ans) | s = list(eval(input()))
ans = 0
for i in range(1, len(s)):
if s[i] == s[i-1] == "0":
s[i] = "1"
ans += 1
elif s[i] == s[i-1] == "1":
s[i] = "0"
ans += 1
print(ans) | 12 | 12 | 223 | 210 | s = list(eval(input()))
ans = 0
for i in range(1, len(s)):
if s[i] == "0" and s[i - 1] == "0":
s[i] = "1"
ans += 1
if s[i] == "1" and s[i - 1] == "1":
s[i] = "0"
ans += 1
print(ans)
| s = list(eval(input()))
ans = 0
for i in range(1, len(s)):
if s[i] == s[i - 1] == "0":
s[i] = "1"
ans += 1
elif s[i] == s[i - 1] == "1":
s[i] = "0"
ans += 1
print(ans)
| false | 0 | [
"- if s[i] == \"0\" and s[i - 1] == \"0\":",
"+ if s[i] == s[i - 1] == \"0\":",
"- if s[i] == \"1\" and s[i - 1] == \"1\":",
"+ elif s[i] == s[i - 1] == \"1\":"
] | false | 0.0373 | 0.036279 | 1.028143 | [
"s252594446",
"s608512479"
] |
u135847648 | p03681 | python | s888812346 | s942065315 | 703 | 444 | 5,184 | 4,096 | Accepted | Accepted | 36.84 | import math
MOD = 10**9+7
n,m = list(map(int,input().split()))
#大きい順に並べる
if n < m:
n,m = m,n
# mがn-1より小さいとどこかで犬・サル同士が隣り合う
if n-1 > m:
print((0))
exit()
if n == m:
ans = math.factorial(n)* math.factorial(m)*2
print((ans%MOD))
elif n-1 == m:
ans = math.factorial(n)* math.factorial(m)
print((ans%MOD))
| import math
MOD = 10**9+7
n,m = list(map(int,input().split()))
#大きい順に並べる
if n < m:
n,m = m,n
# mがn-1より小さいとどこかで犬・サル同士が隣り合う
if n-1 > m:
print((0))
exit()
if n == m:
ans = (math.factorial(n)%MOD) * (math.factorial(m)%MOD)*2
print((ans%MOD))
elif n-1 == m:
ans = (math.factorial(n)%MOD) * (math.factorial(m)%MOD)
print((ans%MOD))
| 21 | 21 | 336 | 362 | import math
MOD = 10**9 + 7
n, m = list(map(int, input().split()))
# 大きい順に並べる
if n < m:
n, m = m, n
# mがn-1より小さいとどこかで犬・サル同士が隣り合う
if n - 1 > m:
print((0))
exit()
if n == m:
ans = math.factorial(n) * math.factorial(m) * 2
print((ans % MOD))
elif n - 1 == m:
ans = math.factorial(n) * math.factorial(m)
print((ans % MOD))
| import math
MOD = 10**9 + 7
n, m = list(map(int, input().split()))
# 大きい順に並べる
if n < m:
n, m = m, n
# mがn-1より小さいとどこかで犬・サル同士が隣り合う
if n - 1 > m:
print((0))
exit()
if n == m:
ans = (math.factorial(n) % MOD) * (math.factorial(m) % MOD) * 2
print((ans % MOD))
elif n - 1 == m:
ans = (math.factorial(n) % MOD) * (math.factorial(m) % MOD)
print((ans % MOD))
| false | 0 | [
"- ans = math.factorial(n) * math.factorial(m) * 2",
"+ ans = (math.factorial(n) % MOD) * (math.factorial(m) % MOD) * 2",
"- ans = math.factorial(n) * math.factorial(m)",
"+ ans = (math.factorial(n) % MOD) * (math.factorial(m) % MOD)"
] | false | 0.042901 | 0.039711 | 1.080336 | [
"s888812346",
"s942065315"
] |
u077291787 | p03673 | python | s947595447 | s819148470 | 195 | 45 | 25,948 | 23,644 | Accepted | Accepted | 76.92 | # ABC066C - pushpush (ARC077)
from collections import deque
def main():
N, *A = list(map(int, open(0).read().split()))
B, x = deque(), N & 1
for i, a in enumerate(A, start=x):
if i & 1:
B.appendleft(a)
else:
B.append(a)
print((*B))
if __name__ == "__main__":
main() | # ABC066C - pushpush (ARC077)
def main():
N, *A = open(0).read().split()
if int(N) & 1:
B, C = A[::2][::-1], A[1::2]
else:
B, C = A[1::2][::-1], A[::2]
print(" ".join(B), end=" ")
print(" ".join(C))
if __name__ == "__main__":
main()
| 17 | 13 | 337 | 286 | # ABC066C - pushpush (ARC077)
from collections import deque
def main():
N, *A = list(map(int, open(0).read().split()))
B, x = deque(), N & 1
for i, a in enumerate(A, start=x):
if i & 1:
B.appendleft(a)
else:
B.append(a)
print((*B))
if __name__ == "__main__":
main()
| # ABC066C - pushpush (ARC077)
def main():
N, *A = open(0).read().split()
if int(N) & 1:
B, C = A[::2][::-1], A[1::2]
else:
B, C = A[1::2][::-1], A[::2]
print(" ".join(B), end=" ")
print(" ".join(C))
if __name__ == "__main__":
main()
| false | 23.529412 | [
"-from collections import deque",
"-",
"-",
"- N, *A = list(map(int, open(0).read().split()))",
"- B, x = deque(), N & 1",
"- for i, a in enumerate(A, start=x):",
"- if i & 1:",
"- B.appendleft(a)",
"- else:",
"- B.append(a)",
"- print((*B))",
"+... | false | 0.037251 | 0.036031 | 1.033874 | [
"s947595447",
"s819148470"
] |
u948524308 | p02844 | python | s039060292 | s853072287 | 1,335 | 24 | 193,140 | 3,064 | Accepted | Accepted | 98.2 | N=int(eval(input()))
S=eval(input())
L0=[]
L1=[]
ans=[]
for i in range(N-2):
if S[i] in L0:
continue
else:
L0.append(S[i])
for j in range(i+1,N-1):
temp=S[i]+S[j]
if temp in L1:
continue
else:
L1.append(temp)
for k in range(j+1,N):
ans.append(temp+S[k])
print((len(set(ans)))) | N=int(eval(input()))
S=eval(input())
L=len(S)
cnt=0
for i in range(1000):
key=str(i).zfill(3)
if key[0] in S:
idx1=S.index(key[0])
else:
continue
if key[1] in S[idx1+1:L-1]:
idx2=S[idx1+1:L-1].index(key[1])+idx1+2
else:
continue
if key[2] in S[idx2:L]:
cnt+=1
else:
continue
print(cnt)
| 23 | 21 | 384 | 372 | N = int(eval(input()))
S = eval(input())
L0 = []
L1 = []
ans = []
for i in range(N - 2):
if S[i] in L0:
continue
else:
L0.append(S[i])
for j in range(i + 1, N - 1):
temp = S[i] + S[j]
if temp in L1:
continue
else:
L1.append(temp)
for k in range(j + 1, N):
ans.append(temp + S[k])
print((len(set(ans))))
| N = int(eval(input()))
S = eval(input())
L = len(S)
cnt = 0
for i in range(1000):
key = str(i).zfill(3)
if key[0] in S:
idx1 = S.index(key[0])
else:
continue
if key[1] in S[idx1 + 1 : L - 1]:
idx2 = S[idx1 + 1 : L - 1].index(key[1]) + idx1 + 2
else:
continue
if key[2] in S[idx2:L]:
cnt += 1
else:
continue
print(cnt)
| false | 8.695652 | [
"-L0 = []",
"-L1 = []",
"-ans = []",
"-for i in range(N - 2):",
"- if S[i] in L0:",
"+L = len(S)",
"+cnt = 0",
"+for i in range(1000):",
"+ key = str(i).zfill(3)",
"+ if key[0] in S:",
"+ idx1 = S.index(key[0])",
"+ else:",
"+ if key[1] in S[idx1 + 1 : L - 1]:",
"+ ... | false | 0.125908 | 0.049289 | 2.55448 | [
"s039060292",
"s853072287"
] |
u046187684 | p02712 | python | s206163093 | s182576053 | 108 | 24 | 9,092 | 9,096 | Accepted | Accepted | 77.78 | def solve(string):
return str(sum(i for i in range(int(string) + 1) if i % 3 > 0 and i % 5 > 0))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| def solve(string):
n = int(string)
def f(n):
return n * (n + 1) // 2
return str(f(n) - 3 * f(n // 3) - 5 * f(n // 5) + 15 * f(n // 15))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| 7 | 12 | 194 | 256 | def solve(string):
return str(sum(i for i in range(int(string) + 1) if i % 3 > 0 and i % 5 > 0))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| def solve(string):
n = int(string)
def f(n):
return n * (n + 1) // 2
return str(f(n) - 3 * f(n // 3) - 5 * f(n // 5) + 15 * f(n // 15))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| false | 41.666667 | [
"- return str(sum(i for i in range(int(string) + 1) if i % 3 > 0 and i % 5 > 0))",
"+ n = int(string)",
"+",
"+ def f(n):",
"+ return n * (n + 1) // 2",
"+",
"+ return str(f(n) - 3 * f(n // 3) - 5 * f(n // 5) + 15 * f(n // 15))"
] | false | 0.188168 | 0.073198 | 2.570665 | [
"s206163093",
"s182576053"
] |
u748241164 | p02862 | python | s545981089 | s073804557 | 947 | 585 | 102,028 | 132,908 | Accepted | Accepted | 38.23 | from math import factorial
X, Y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
#a(1,2)+b(2,1)
if (2 * Y - X) % 3 != 0:
ans = 0
print(ans)
quit()
if (2 * X - Y) % 3 != 0:
ans = 0
print(ans)
quit()
a = int((2 * Y - X) / 3)
b = int((2 * X - Y) / 3)
if (a < 0) or (b < 0):
ans = 0
print(ans)
quit()
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
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
ans = cmb(a + b,a)
print((int(ans % MOD)))
| def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 2 * 10 ** 6 # N は必要分だけ用意する
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) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
X, Y = list(map(int, input().split()))
#(1, 2)の回数をn, (2, 1)の回数をmとする。
n = (-X + 2 * Y) / 3
m = (-Y + 2 * X) / 3
#いけない場合を除外
if n % 1 != 0:
print((0))
quit()
elif m % 1 != 0:
print((0))
quit()
#n + m C nで答え
ans = cmb(int(n + m), int(n), p)
print(ans)
| 47 | 33 | 963 | 741 | from math import factorial
X, Y = list(map(int, input().split()))
MOD = 10**9 + 7
# a(1,2)+b(2,1)
if (2 * Y - X) % 3 != 0:
ans = 0
print(ans)
quit()
if (2 * X - Y) % 3 != 0:
ans = 0
print(ans)
quit()
a = int((2 * Y - X) / 3)
b = int((2 * X - Y) / 3)
if (a < 0) or (b < 0):
ans = 0
print(ans)
quit()
def cmb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
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
ans = cmb(a + b, a)
print((int(ans % MOD)))
| def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n - r] % p
p = 10**9 + 7
N = 2 * 10**6 # N は必要分だけ用意する
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) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
X, Y = list(map(int, input().split()))
# (1, 2)の回数をn, (2, 1)の回数をmとする。
n = (-X + 2 * Y) / 3
m = (-Y + 2 * X) / 3
# いけない場合を除外
if n % 1 != 0:
print((0))
quit()
elif m % 1 != 0:
print((0))
quit()
# n + m C nで答え
ans = cmb(int(n + m), int(n), p)
print(ans)
| false | 29.787234 | [
"-from math import factorial",
"-",
"-X, Y = list(map(int, input().split()))",
"-MOD = 10**9 + 7",
"-# a(1,2)+b(2,1)",
"-if (2 * Y - X) % 3 != 0:",
"- ans = 0",
"- print(ans)",
"- quit()",
"-if (2 * X - Y) % 3 != 0:",
"- ans = 0",
"- print(ans)",
"- quit()",
"-a = int((2 ... | false | 0.188436 | 2.882217 | 0.065379 | [
"s545981089",
"s073804557"
] |
u150984829 | p02257 | python | s706382358 | s653012522 | 1,220 | 640 | 5,784 | 5,756 | Accepted | Accepted | 47.54 | def p(x):
i=2
while i<=x**.5:
if x%i==0:return 0
i+=1
return 1
n=int(eval(input()))
print((sum([p(int(eval(input())))for _ in range(n)]))) | def p(x):
if x==2:return 1
if x%2==0:return 0
i=3
while i<=x**.5:
if x%i==0:return 0
i+=2
return 1
n=int(eval(input()))
print((sum([p(int(eval(input())))for _ in range(n)]))) | 8 | 10 | 138 | 178 | def p(x):
i = 2
while i <= x**0.5:
if x % i == 0:
return 0
i += 1
return 1
n = int(eval(input()))
print((sum([p(int(eval(input()))) for _ in range(n)])))
| def p(x):
if x == 2:
return 1
if x % 2 == 0:
return 0
i = 3
while i <= x**0.5:
if x % i == 0:
return 0
i += 2
return 1
n = int(eval(input()))
print((sum([p(int(eval(input()))) for _ in range(n)])))
| false | 20 | [
"- i = 2",
"+ if x == 2:",
"+ return 1",
"+ if x % 2 == 0:",
"+ return 0",
"+ i = 3",
"- i += 1",
"+ i += 2"
] | false | 0.045628 | 0.036644 | 1.245167 | [
"s706382358",
"s653012522"
] |
u588341295 | p02644 | python | s185959328 | s137256774 | 617 | 482 | 175,268 | 175,400 | Accepted | Accepted | 21.88 | import sys
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 ** 19
MOD = 10 ** 9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H+offset*2, W+offset*2, intv)
for i in range(offset, H+offset):
row = _list()
for j in range(offset, W+offset):
grid[i][j] = row[j-offset]
return grid
def bfs(grid, src):
""" BFS(グリッド、重みなし) """
from collections import deque
H, W = len(grid), len(grid[0])
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
dist = list2d(H, W, INF)
que = deque()
for h, w in src:
que.append((h, w))
dist[h][w] = 0
while que:
h, w = que.popleft()
for dh, dw in directions:
for k in range(1, K+1):
h2 = h + dh*k
w2 = w + dw*k
if grid[h2][w2] == '@':
break
if dist[h2][w2] < dist[h][w] + 1:
break
elif dist[h2][w2] != INF:
continue
dist[h2][w2] = dist[h][w] + 1
que.append((h2, w2))
return dist
H, W, K = MAP()
x1, y1, x2, y2 = MAP()
grid = build_grid(H, W, '@', str, space=0, padding=1)
res = bfs(grid, [(x1, y1)])
ans = res[x2][y2]
if ans == INF:
print((-1))
else:
print(ans)
| import sys
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 ** 19
MOD = 10 ** 9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H+offset*2, W+offset*2, intv)
for i in range(offset, H+offset):
row = _list()
for j in range(offset, W+offset):
grid[i][j] = row[j-offset]
return grid
def bfs(grid, src):
""" BFS(グリッド、重みなし) """
from collections import deque
H, W = len(grid), len(grid[0])
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
dist = list2d(H, W, INF)
que = deque()
for h, w in src:
que.append((h, w))
dist[h][w] = 0
while que:
h, w = que.popleft()
for dh, dw in directions:
for k in range(1, K+1):
h2 = h + dh*k
w2 = w + dw*k
if grid[h2][w2] == '@':
break
# 枝刈り
if dist[h2][w2] < dist[h][w] + 1:
break
elif dist[h2][w2] == dist[h][w] + 1:
continue
else:
dist[h2][w2] = dist[h][w] + 1
que.append((h2, w2))
return dist
H, W, K = MAP()
x1, y1, x2, y2 = MAP()
grid = build_grid(H, W, '@', str, space=0, padding=1)
res = bfs(grid, [(x1, y1)])
ans = res[x2][y2]
if ans == INF:
print((-1))
else:
print(ans)
| 74 | 76 | 2,199 | 2,264 | import sys
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**19
MOD = 10**9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H + offset * 2, W + offset * 2, intv)
for i in range(offset, H + offset):
row = _list()
for j in range(offset, W + offset):
grid[i][j] = row[j - offset]
return grid
def bfs(grid, src):
"""BFS(グリッド、重みなし)"""
from collections import deque
H, W = len(grid), len(grid[0])
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
dist = list2d(H, W, INF)
que = deque()
for h, w in src:
que.append((h, w))
dist[h][w] = 0
while que:
h, w = que.popleft()
for dh, dw in directions:
for k in range(1, K + 1):
h2 = h + dh * k
w2 = w + dw * k
if grid[h2][w2] == "@":
break
if dist[h2][w2] < dist[h][w] + 1:
break
elif dist[h2][w2] != INF:
continue
dist[h2][w2] = dist[h][w] + 1
que.append((h2, w2))
return dist
H, W, K = MAP()
x1, y1, x2, y2 = MAP()
grid = build_grid(H, W, "@", str, space=0, padding=1)
res = bfs(grid, [(x1, y1)])
ans = res[x2][y2]
if ans == INF:
print((-1))
else:
print(ans)
| import sys
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**19
MOD = 10**9 + 7
def build_grid(H, W, intv, _type, space=True, padding=False):
# 入力がスペース区切りかどうか
if space:
_input = lambda: input().split()
else:
_input = lambda: eval(input())
_list = lambda: list(map(_type, _input()))
# 余白の有無
if padding:
offset = 1
else:
offset = 0
grid = list2d(H + offset * 2, W + offset * 2, intv)
for i in range(offset, H + offset):
row = _list()
for j in range(offset, W + offset):
grid[i][j] = row[j - offset]
return grid
def bfs(grid, src):
"""BFS(グリッド、重みなし)"""
from collections import deque
H, W = len(grid), len(grid[0])
directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
dist = list2d(H, W, INF)
que = deque()
for h, w in src:
que.append((h, w))
dist[h][w] = 0
while que:
h, w = que.popleft()
for dh, dw in directions:
for k in range(1, K + 1):
h2 = h + dh * k
w2 = w + dw * k
if grid[h2][w2] == "@":
break
# 枝刈り
if dist[h2][w2] < dist[h][w] + 1:
break
elif dist[h2][w2] == dist[h][w] + 1:
continue
else:
dist[h2][w2] = dist[h][w] + 1
que.append((h2, w2))
return dist
H, W, K = MAP()
x1, y1, x2, y2 = MAP()
grid = build_grid(H, W, "@", str, space=0, padding=1)
res = bfs(grid, [(x1, y1)])
ans = res[x2][y2]
if ans == INF:
print((-1))
else:
print(ans)
| false | 2.631579 | [
"+ # 枝刈り",
"- elif dist[h2][w2] != INF:",
"+ elif dist[h2][w2] == dist[h][w] + 1:",
"- dist[h2][w2] = dist[h][w] + 1",
"- que.append((h2, w2))",
"+ else:",
"+ dist[h2][w2] = dist[h][w] + 1",
"+... | false | 0.047972 | 0.050487 | 0.950192 | [
"s185959328",
"s137256774"
] |
u706414019 | p03986 | python | s382520937 | s517414036 | 51 | 47 | 9,252 | 9,208 | Accepted | Accepted | 7.84 | S = eval(input())
s_cnt =0
t_cnt =0
for s in S:
if s == 'S':
s_cnt += 1
else:
if s_cnt >0:
s_cnt -= 1
else:
t_cnt += 1
print((t_cnt + s_cnt))
| import sys
input = sys.stdin.readline
S = input().rstrip()
s_cnt =0
t_cnt =0
for s in S:
if s == 'S':
s_cnt += 1
else:
if s_cnt >0:
s_cnt -= 1
else:
t_cnt += 1
print((t_cnt + s_cnt))
| 14 | 17 | 217 | 268 | S = eval(input())
s_cnt = 0
t_cnt = 0
for s in S:
if s == "S":
s_cnt += 1
else:
if s_cnt > 0:
s_cnt -= 1
else:
t_cnt += 1
print((t_cnt + s_cnt))
| import sys
input = sys.stdin.readline
S = input().rstrip()
s_cnt = 0
t_cnt = 0
for s in S:
if s == "S":
s_cnt += 1
else:
if s_cnt > 0:
s_cnt -= 1
else:
t_cnt += 1
print((t_cnt + s_cnt))
| false | 17.647059 | [
"-S = eval(input())",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+S = input().rstrip()"
] | false | 0.086555 | 0.039907 | 2.168906 | [
"s382520937",
"s517414036"
] |
u367130284 | p03568 | python | s883160180 | s481940800 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | print((3**int(eval(input()))-2**sum(int(s)%2==0for s in input().split()))) | print((3**int(eval(input()))-2**sum(~int(s)%2for s in input().split()))) | 1 | 1 | 66 | 64 | print((3 ** int(eval(input())) - 2 ** sum(int(s) % 2 == 0 for s in input().split())))
| print((3 ** int(eval(input())) - 2 ** sum(~int(s) % 2 for s in input().split())))
| false | 0 | [
"-print((3 ** int(eval(input())) - 2 ** sum(int(s) % 2 == 0 for s in input().split())))",
"+print((3 ** int(eval(input())) - 2 ** sum(~int(s) % 2 for s in input().split())))"
] | false | 0.036163 | 0.036447 | 0.992197 | [
"s883160180",
"s481940800"
] |
u138952651 | p03455 | python | s761640844 | s160387409 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | # -*- coding: utf-8 -*-
a,b = list(map(int, input().split()))
if a&0b1 and b&0b1:
print('Odd')
else:
print('Even') | # -*- coding: utf-8 -*-
a,b = list(map(int, input().split()))
if (a*b)&0b1:
print('Odd')
else:
print('Even') | 6 | 6 | 117 | 111 | # -*- coding: utf-8 -*-
a, b = list(map(int, input().split()))
if a & 0b1 and b & 0b1:
print("Odd")
else:
print("Even")
| # -*- coding: utf-8 -*-
a, b = list(map(int, input().split()))
if (a * b) & 0b1:
print("Odd")
else:
print("Even")
| false | 0 | [
"-if a & 0b1 and b & 0b1:",
"+if (a * b) & 0b1:"
] | false | 0.047856 | 0.046964 | 1.018995 | [
"s761640844",
"s160387409"
] |
u088552457 | p03127 | python | s737258844 | s055395302 | 235 | 79 | 16,280 | 16,296 | Accepted | Accepted | 66.38 | import fractions
def lcm(a, b):
return (a * b) / fractions.gcd(a, b)
N = int(eval(input()))
A = list(map(int, input().split()))
g = []
for index, a in enumerate(A):
if index == len(A) - 1:
break
g.append(fractions.gcd(a, A[index+1]))
print((min(g))) | def count_section_by_zero(data):
count = 0
flg = False
start = 0
for i, d in enumerate(data):
if flg is False and d != 0:
count += 1
flg = True
if d == 0:
flg = False
return count
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
# 2で割り切れる回数
def divide_two(arg):
c = 0
while True:
if c >= 2:
break
if arg % 2 != 0:
break
arg //= 2
c += 1
return c
# 素因数分解
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
def main():
n = int(eval(input()))
a = input_list()
g = gcd_list(a)
print(g)
import math
import fractions
import collections
from functools import reduce
main() | 16 | 71 | 275 | 1,266 | import fractions
def lcm(a, b):
return (a * b) / fractions.gcd(a, b)
N = int(eval(input()))
A = list(map(int, input().split()))
g = []
for index, a in enumerate(A):
if index == len(A) - 1:
break
g.append(fractions.gcd(a, A[index + 1]))
print((min(g)))
| def count_section_by_zero(data):
count = 0
flg = False
start = 0
for i, d in enumerate(data):
if flg is False and d != 0:
count += 1
flg = True
if d == 0:
flg = False
return count
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
# 2で割り切れる回数
def divide_two(arg):
c = 0
while True:
if c >= 2:
break
if arg % 2 != 0:
break
arg //= 2
c += 1
return c
# 素因数分解
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
def main():
n = int(eval(input()))
a = input_list()
g = gcd_list(a)
print(g)
import math
import fractions
import collections
from functools import reduce
main()
| false | 77.464789 | [
"-import fractions",
"+def count_section_by_zero(data):",
"+ count = 0",
"+ flg = False",
"+ start = 0",
"+ for i, d in enumerate(data):",
"+ if flg is False and d != 0:",
"+ count += 1",
"+ flg = True",
"+ if d == 0:",
"+ flg = False",
... | false | 0.052444 | 0.044511 | 1.178215 | [
"s737258844",
"s055395302"
] |
u588341295 | p02788 | python | s256669057 | s311514975 | 1,734 | 1,412 | 117,124 | 98,240 | Accepted | Accepted | 18.57 | # -*- coding: utf-8 -*-
import sys
from bisect import bisect_right
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
class StarrySkyTree:
""" Starry Sky Tree(区間加算・区間最小(大)値取得) """
def __init__(self, N, func, intv):
self.intv = intv
self.func = func
LV = (N-1).bit_length()
self.N0 = 2**LV
self.data = [0]*(2*self.N0)
self.lazy = [0]*(2*self.N0)
# 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
def gindex(self, l, r):
L = l + self.N0; R = r + self.N0
lm = (L // (L & -L)) >> 1
rm = (R // (R & -R)) >> 1
while L < R:
if R <= rm:
yield R
if L <= lm:
yield L
L >>= 1; R >>= 1
while L:
yield L
L >>= 1
# 遅延評価の伝搬処理
def propagates(self, *ids):
# 1-indexedで単調増加のインデックスリスト
for i in reversed(ids):
v = self.lazy[i-1]
if not v:
continue
self.lazy[2*i-1] += v; self.lazy[2*i] += v
self.data[2*i-1] += v; self.data[2*i] += v
self.lazy[i-1] = 0
def update(self, l, r, x):
""" 区間[l,r)の値にxを加算 """
# 1. lazyの値は伝搬させない
# 2. 区間[l,r)のdata, lazyの値を更新
L = self.N0 + l; R = self.N0 + r
while L < R:
if R & 1:
R -= 1
self.lazy[R-1] += x; self.data[R-1] += x
if L & 1:
self.lazy[L-1] += x; self.data[L-1] += x
L += 1
L >>= 1; R >>= 1
# 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)
for i in self.gindex(l, r):
self.data[i-1] = self.func(self.data[2*i-1], self.data[2*i]) + self.lazy[i-1]
def query(self, l, r):
""" 区間[l,r)の最小(大)値を取得 """
# 1. トップダウンにlazyの値を伝搬
self.propagates(*self.gindex(l, r))
L = self.N0 + l; R = self.N0 + r
# 2. 区間[l, r)の最小(大)値を求める
s = self.intv
while L < R:
if R & 1:
R -= 1
s = self.func(s, self.data[R-1])
if L & 1:
s = self.func(s, self.data[L-1])
L += 1
L >>= 1; R >>= 1
return s
N, D, K = MAP()
XH = []
for i in range(N):
x, h = MAP()
XH.append((x, h))
XH.sort()
X, H = list(zip(*XH))
D = D * 2
sst = StarrySkyTree(N, max, 0)
ans = 0
for i, (x, h) in enumerate(XH):
h -= sst.query(i, i+1) * K
if h <= 0:
continue
cnt = ceil(h, K)
idx = bisect_right(X, x+D) - 1
sst.update(i, idx+1, cnt)
ans += cnt
print(ans)
| # -*- coding: utf-8 -*-
import sys
from bisect import bisect_right
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(input())
def MAP(): return 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
class BIT2:
""" 区間加算BIT(区間加算・区間合計取得) """
def __init__(self, N):
# 添字0が使えないので、内部的には全て1-indexedとして扱う
N += 1
self.N = N
self.data0 = [0] * N
self.data1 = [0] * N
def _add(self, data, k, x):
k += 1
while k < self.N:
data[k] += x
k += k & -k
def _get(self, data, k):
k += 1
s = 0
while k:
s += data[k]
k -= k & -k
return s
def add(self, l, r, x):
""" 区間[l,r)に値xを追加 """
self._add(self.data0, l, -x*(l-1))
self._add(self.data0, r, x*(r-1))
self._add(self.data1, l, x)
self._add(self.data1, r, -x)
def query(self, l, r):
""" 区間[l,r)の和を取得 """
return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
- self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)
N, D, K = MAP()
XH = []
for i in range(N):
x, h = MAP()
XH.append((x, h))
XH.sort()
X, H = zip(*XH)
D = D * 2
bit = BIT2(N)
ans = 0
for i, (x, h) in enumerate(XH):
h -= bit.query(i, i+1) * K
if h <= 0:
continue
cnt = ceil(h, K)
idx = bisect_right(X, x+D) - 1
bit.add(i, idx+1, cnt)
ans += cnt
print(ans)
| 117 | 81 | 3,292 | 2,046 | # -*- coding: utf-8 -*-
import sys
from bisect import bisect_right
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
class StarrySkyTree:
"""Starry Sky Tree(区間加算・区間最小(大)値取得)"""
def __init__(self, N, func, intv):
self.intv = intv
self.func = func
LV = (N - 1).bit_length()
self.N0 = 2**LV
self.data = [0] * (2 * self.N0)
self.lazy = [0] * (2 * self.N0)
# 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
def gindex(self, l, r):
L = l + self.N0
R = r + self.N0
lm = (L // (L & -L)) >> 1
rm = (R // (R & -R)) >> 1
while L < R:
if R <= rm:
yield R
if L <= lm:
yield L
L >>= 1
R >>= 1
while L:
yield L
L >>= 1
# 遅延評価の伝搬処理
def propagates(self, *ids):
# 1-indexedで単調増加のインデックスリスト
for i in reversed(ids):
v = self.lazy[i - 1]
if not v:
continue
self.lazy[2 * i - 1] += v
self.lazy[2 * i] += v
self.data[2 * i - 1] += v
self.data[2 * i] += v
self.lazy[i - 1] = 0
def update(self, l, r, x):
"""区間[l,r)の値にxを加算"""
# 1. lazyの値は伝搬させない
# 2. 区間[l,r)のdata, lazyの値を更新
L = self.N0 + l
R = self.N0 + r
while L < R:
if R & 1:
R -= 1
self.lazy[R - 1] += x
self.data[R - 1] += x
if L & 1:
self.lazy[L - 1] += x
self.data[L - 1] += x
L += 1
L >>= 1
R >>= 1
# 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)
for i in self.gindex(l, r):
self.data[i - 1] = (
self.func(self.data[2 * i - 1], self.data[2 * i]) + self.lazy[i - 1]
)
def query(self, l, r):
"""区間[l,r)の最小(大)値を取得"""
# 1. トップダウンにlazyの値を伝搬
self.propagates(*self.gindex(l, r))
L = self.N0 + l
R = self.N0 + r
# 2. 区間[l, r)の最小(大)値を求める
s = self.intv
while L < R:
if R & 1:
R -= 1
s = self.func(s, self.data[R - 1])
if L & 1:
s = self.func(s, self.data[L - 1])
L += 1
L >>= 1
R >>= 1
return s
N, D, K = MAP()
XH = []
for i in range(N):
x, h = MAP()
XH.append((x, h))
XH.sort()
X, H = list(zip(*XH))
D = D * 2
sst = StarrySkyTree(N, max, 0)
ans = 0
for i, (x, h) in enumerate(XH):
h -= sst.query(i, i + 1) * K
if h <= 0:
continue
cnt = ceil(h, K)
idx = bisect_right(X, x + D) - 1
sst.update(i, idx + 1, cnt)
ans += cnt
print(ans)
| # -*- coding: utf-8 -*-
import sys
from bisect import bisect_right
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(input())
def MAP():
return 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
class BIT2:
"""区間加算BIT(区間加算・区間合計取得)"""
def __init__(self, N):
# 添字0が使えないので、内部的には全て1-indexedとして扱う
N += 1
self.N = N
self.data0 = [0] * N
self.data1 = [0] * N
def _add(self, data, k, x):
k += 1
while k < self.N:
data[k] += x
k += k & -k
def _get(self, data, k):
k += 1
s = 0
while k:
s += data[k]
k -= k & -k
return s
def add(self, l, r, x):
"""区間[l,r)に値xを追加"""
self._add(self.data0, l, -x * (l - 1))
self._add(self.data0, r, x * (r - 1))
self._add(self.data1, l, x)
self._add(self.data1, r, -x)
def query(self, l, r):
"""区間[l,r)の和を取得"""
return (
self._get(self.data1, r - 1) * (r - 1)
+ self._get(self.data0, r - 1)
- self._get(self.data1, l - 1) * (l - 1)
- self._get(self.data0, l - 1)
)
N, D, K = MAP()
XH = []
for i in range(N):
x, h = MAP()
XH.append((x, h))
XH.sort()
X, H = zip(*XH)
D = D * 2
bit = BIT2(N)
ans = 0
for i, (x, h) in enumerate(XH):
h -= bit.query(i, i + 1) * K
if h <= 0:
continue
cnt = ceil(h, K)
idx = bisect_right(X, x + D) - 1
bit.add(i, idx + 1, cnt)
ans += cnt
print(ans)
| false | 30.769231 | [
"- return int(eval(input()))",
"+ return int(input())",
"- return list(map(int, input().split()))",
"+ return map(int, input().split())",
"-class StarrySkyTree:",
"- \"\"\"Starry Sky Tree(区間加算・区間最小(大)値取得)\"\"\"",
"+class BIT2:",
"+ \"\"\"区間加算BIT(区間加算・区間合計取得)\"\"\"",
"- def __ini... | false | 0.039201 | 0.034754 | 1.127961 | [
"s256669057",
"s311514975"
] |
u301624971 | p03273 | python | s400040124 | s999104686 | 21 | 18 | 3,316 | 3,316 | Accepted | Accepted | 14.29 | H,W=list(map(int,input().split()))
A=[]
for _ in range(H):
a=list(eval(input()))
if("#" in a):
A.append(a)
answer=[]
for i in range(W):
tmp=[]
hantei=True
for a in A:
if(a[i]=="#"):
hantei=False
tmp.append(a[i])
if(hantei==False):
answer.append(tmp)
result = list(zip(*answer))
for r in result:
print(("".join(r))) | H, W = list(map(int, input().split()))
A = []
answer = []
for _ in range(H):
a = list(eval(input()))
if("#" in a): A.append(a)
for a in list(zip(*A)):
if("#" in a): answer.append(a)
for result in list(zip(*answer)): print(("".join(result))) | 20 | 12 | 392 | 252 | H, W = list(map(int, input().split()))
A = []
for _ in range(H):
a = list(eval(input()))
if "#" in a:
A.append(a)
answer = []
for i in range(W):
tmp = []
hantei = True
for a in A:
if a[i] == "#":
hantei = False
tmp.append(a[i])
if hantei == False:
answer.append(tmp)
result = list(zip(*answer))
for r in result:
print(("".join(r)))
| H, W = list(map(int, input().split()))
A = []
answer = []
for _ in range(H):
a = list(eval(input()))
if "#" in a:
A.append(a)
for a in list(zip(*A)):
if "#" in a:
answer.append(a)
for result in list(zip(*answer)):
print(("".join(result)))
| false | 40 | [
"+answer = []",
"-answer = []",
"-for i in range(W):",
"- tmp = []",
"- hantei = True",
"- for a in A:",
"- if a[i] == \"#\":",
"- hantei = False",
"- tmp.append(a[i])",
"- if hantei == False:",
"- answer.append(tmp)",
"-result = list(zip(*answer))",... | false | 0.044507 | 0.046143 | 0.964561 | [
"s400040124",
"s999104686"
] |
u724563664 | p02787 | python | s242634280 | s626753199 | 372 | 329 | 41,072 | 45,936 | Accepted | Accepted | 11.56 | #coding:utf-8
def main():
h, n = list(map(int, input().split()))
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
inf = 100000000000
# indexがモンスターに与えたダメージで、中身がトキのダメージ
damages = [0] + [inf] * h
for i in range(1, h + 1):
for j in range(n):
damage_monster = ab[j][0]
damage_toki = ab[j][1]
damages[i] = min(damages[max(0, i - damage_monster)] + damage_toki, damages[i])
print((min(damages[h:])))
main() | #coding:utf-8
def main():
h, n = list(map(int, input().split()))
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
inf = 100000000000
# indexがモンスターに与えたダメージで、中身がトキのダメージ
damages = [inf for _ in range(100000)]
damages[0] = 0
pre_damage = -1
for i in range(h):
if damages[i] == inf:
continue
for j in range(n):
new_damage = ab[j][0]
if damages[i + new_damage] > damages[i] + ab[j][1]:
damages[i + new_damage] = damages[i] + ab[j][1]
print((min(damages[h:])))
main() | 21 | 24 | 537 | 630 | # coding:utf-8
def main():
h, n = list(map(int, input().split()))
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
inf = 100000000000
# indexがモンスターに与えたダメージで、中身がトキのダメージ
damages = [0] + [inf] * h
for i in range(1, h + 1):
for j in range(n):
damage_monster = ab[j][0]
damage_toki = ab[j][1]
damages[i] = min(
damages[max(0, i - damage_monster)] + damage_toki, damages[i]
)
print((min(damages[h:])))
main()
| # coding:utf-8
def main():
h, n = list(map(int, input().split()))
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
inf = 100000000000
# indexがモンスターに与えたダメージで、中身がトキのダメージ
damages = [inf for _ in range(100000)]
damages[0] = 0
pre_damage = -1
for i in range(h):
if damages[i] == inf:
continue
for j in range(n):
new_damage = ab[j][0]
if damages[i + new_damage] > damages[i] + ab[j][1]:
damages[i + new_damage] = damages[i] + ab[j][1]
print((min(damages[h:])))
main()
| false | 12.5 | [
"- damages = [0] + [inf] * h",
"- for i in range(1, h + 1):",
"+ damages = [inf for _ in range(100000)]",
"+ damages[0] = 0",
"+ pre_damage = -1",
"+ for i in range(h):",
"+ if damages[i] == inf:",
"+ continue",
"- damage_monster = ab[j][0]",
"- ... | false | 0.180217 | 0.069503 | 2.592924 | [
"s242634280",
"s626753199"
] |
u254871849 | p03611 | python | s935743300 | s242467471 | 106 | 75 | 19,056 | 14,044 | Accepted | Accepted | 29.25 | import sys
from collections import defaultdict
n, *a = list(map(int, sys.stdin.read().split()))
def main():
res = defaultdict(int)
for i in a:
res[i-1] += 1
res[i] += 1
res[i+1] += 1
return max(res.values())
if __name__ == '__main__':
ans = main()
print(ans) | import sys
n, *a = list(map(int, sys.stdin.read().split()))
def main():
m = 10 ** 5
cnt = [0] * (m + 1)
for x in a:
cnt[x] += 1
if x > 0: cnt[x-1] += 1
if x < m: cnt[x+1] += 1
print((max(cnt)))
if __name__ == '__main__':
main() | 17 | 15 | 321 | 281 | import sys
from collections import defaultdict
n, *a = list(map(int, sys.stdin.read().split()))
def main():
res = defaultdict(int)
for i in a:
res[i - 1] += 1
res[i] += 1
res[i + 1] += 1
return max(res.values())
if __name__ == "__main__":
ans = main()
print(ans)
| import sys
n, *a = list(map(int, sys.stdin.read().split()))
def main():
m = 10**5
cnt = [0] * (m + 1)
for x in a:
cnt[x] += 1
if x > 0:
cnt[x - 1] += 1
if x < m:
cnt[x + 1] += 1
print((max(cnt)))
if __name__ == "__main__":
main()
| false | 11.764706 | [
"-from collections import defaultdict",
"- res = defaultdict(int)",
"- for i in a:",
"- res[i - 1] += 1",
"- res[i] += 1",
"- res[i + 1] += 1",
"- return max(res.values())",
"+ m = 10**5",
"+ cnt = [0] * (m + 1)",
"+ for x in a:",
"+ cnt[x] += 1",
... | false | 0.07989 | 0.042077 | 1.898667 | [
"s935743300",
"s242467471"
] |
u414458988 | p02748 | python | s974018947 | s813971111 | 706 | 649 | 68,940 | 66,156 | Accepted | Accepted | 8.07 | def main():
#from sys import stdin, setrecursionlimit
#setrecursionlimit(10**9)
#r = input()
#n = int(input())
#a, b = map(int, input().split())
#s, y = input().split()
#a = input().split()
#a = list(map(int, input().split()))
#a = [input().split() for i in range(n)]
#a = [int(input()) for i in range(n)]
#a = [list(map(int, input().split())) for i in range(n)]
#a = [int(s) - 1 for s in input().split()]
#l=[int(input()) for _ in range(int(input()))]
#res = 0
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [0] * (M+1)
res[-1] = min(a)+min(b)
for i in range(M):
x,y,c = list(map(int,input().split()))
res[i] = a[x-1]+b[y-1]-c
print((min(res)))
if __name__ == '__main__':
main()
| def main():
_,_,m = list(map(int,input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [0]*(m+1)
res[-1] = min(a)+min(b)
for i in range(m):
x,y,c = list(map(int,input().split()))
res[i] = a[x-1]+b[y-1]-c
print((min(res)))
if __name__ == '__main__':
main()
| 31 | 13 | 878 | 345 | def main():
# from sys import stdin, setrecursionlimit
# setrecursionlimit(10**9)
# r = input()
# n = int(input())
# a, b = map(int, input().split())
# s, y = input().split()
# a = input().split()
# a = list(map(int, input().split()))
# a = [input().split() for i in range(n)]
# a = [int(input()) for i in range(n)]
# a = [list(map(int, input().split())) for i in range(n)]
# a = [int(s) - 1 for s in input().split()]
# l=[int(input()) for _ in range(int(input()))]
# res = 0
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [0] * (M + 1)
res[-1] = min(a) + min(b)
for i in range(M):
x, y, c = list(map(int, input().split()))
res[i] = a[x - 1] + b[y - 1] - c
print((min(res)))
if __name__ == "__main__":
main()
| def main():
_, _, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = [0] * (m + 1)
res[-1] = min(a) + min(b)
for i in range(m):
x, y, c = list(map(int, input().split()))
res[i] = a[x - 1] + b[y - 1] - c
print((min(res)))
if __name__ == "__main__":
main()
| false | 58.064516 | [
"- # from sys import stdin, setrecursionlimit",
"- # setrecursionlimit(10**9)",
"- # r = input()",
"- # n = int(input())",
"- # a, b = map(int, input().split())",
"- # s, y = input().split()",
"- # a = input().split()",
"- # a = list(map(int, input().split()))",
"- # a = [... | false | 0.043607 | 0.042565 | 1.024471 | [
"s974018947",
"s813971111"
] |
u746419473 | p03557 | python | s437369362 | s409150378 | 335 | 301 | 23,092 | 23,360 | Accepted | Accepted | 10.15 | import bisect
n = int(eval(input()))
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))
ans = 0
for _b in b:
aNum = bisect.bisect_left(a, _b)
cNum = len(c) - bisect.bisect_right(c, _b)
ans += aNum*cNum
print(ans)
| import bisect
n = int(eval(input()))
*a, = list(map(int, input().split()))
*b, = list(map(int, input().split()))
*c, = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for _b in b:
ans += bisect.bisect_left(a, _b)*(n - bisect.bisect_right(c, _b))
print(ans)
| 14 | 15 | 304 | 273 | import bisect
n = int(eval(input()))
(*a,) = sorted(map(int, input().split()))
(*b,) = sorted(map(int, input().split()))
(*c,) = sorted(map(int, input().split()))
ans = 0
for _b in b:
aNum = bisect.bisect_left(a, _b)
cNum = len(c) - bisect.bisect_right(c, _b)
ans += aNum * cNum
print(ans)
| import bisect
n = int(eval(input()))
(*a,) = list(map(int, input().split()))
(*b,) = list(map(int, input().split()))
(*c,) = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for _b in b:
ans += bisect.bisect_left(a, _b) * (n - bisect.bisect_right(c, _b))
print(ans)
| false | 6.666667 | [
"-(*a,) = sorted(map(int, input().split()))",
"-(*b,) = sorted(map(int, input().split()))",
"-(*c,) = sorted(map(int, input().split()))",
"+(*a,) = list(map(int, input().split()))",
"+(*b,) = list(map(int, input().split()))",
"+(*c,) = list(map(int, input().split()))",
"+a.sort()",
"+b.sort()",
"+c.... | false | 0.037554 | 0.038738 | 0.969436 | [
"s437369362",
"s409150378"
] |
u490553751 | p03338 | python | s440941066 | s451512567 | 26 | 23 | 3,316 | 3,316 | Accepted | Accepted | 11.54 | import sys
import collections
from collections import Counter
input = sys.stdin.readline
N = int(eval(input()))
S = list(eval(input()))
count = -1000
del S[-1]
for i in range(N) :
a = 0
Sa = S[:i]
Sb = S[i:]
ca = collections.Counter(Sa)
cb = collections.Counter(Sb)
ka = list(ca.keys())
kb = list(cb.keys())
for j in ka :
for k in kb :
if j == k :
a +=1
count = max(a,count)
print(count) | #template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N = int(eval(input()))
s = list(eval(input()))
ans = -1
for i in range(N):
lif = s[:i]
lib = s[i:]
cf= list(Counter(lif).keys())
cb= list(Counter(lib).keys())
k = len(cf) + len(cb) - len(set(cf+cb))
ans = max(ans,k)
print(ans) | 22 | 16 | 468 | 375 | import sys
import collections
from collections import Counter
input = sys.stdin.readline
N = int(eval(input()))
S = list(eval(input()))
count = -1000
del S[-1]
for i in range(N):
a = 0
Sa = S[:i]
Sb = S[i:]
ca = collections.Counter(Sa)
cb = collections.Counter(Sb)
ka = list(ca.keys())
kb = list(cb.keys())
for j in ka:
for k in kb:
if j == k:
a += 1
count = max(a, count)
print(count)
| # template
def inputlist():
return [int(j) for j in input().split()]
from collections import Counter
# template
# issueから始める
N = int(eval(input()))
s = list(eval(input()))
ans = -1
for i in range(N):
lif = s[:i]
lib = s[i:]
cf = list(Counter(lif).keys())
cb = list(Counter(lib).keys())
k = len(cf) + len(cb) - len(set(cf + cb))
ans = max(ans, k)
print(ans)
| false | 27.272727 | [
"-import sys",
"-import collections",
"+# template",
"+def inputlist():",
"+ return [int(j) for j in input().split()]",
"+",
"+",
"-input = sys.stdin.readline",
"+# template",
"+# issueから始める",
"-S = list(eval(input()))",
"-count = -1000",
"-del S[-1]",
"+s = list(eval(input()))",
"+an... | false | 0.191469 | 0.047587 | 4.023518 | [
"s440941066",
"s451512567"
] |
u034128150 | p02607 | python | s590955535 | s679745550 | 82 | 27 | 61,672 | 9,024 | Accepted | Accepted | 67.07 | N = int(eval(input()))
c = 0
for i, a in enumerate(map(int, input().split())):
if i % 2 == 0 and a % 2 == 1:
c += 1
print(c) | N = int(eval(input()))
As = list(map(int, input().split()))
ans = 0
for i, A in enumerate(As):
if i % 2 == 0 and A % 2 == 1:
ans += 1
print(ans) | 7 | 9 | 137 | 158 | N = int(eval(input()))
c = 0
for i, a in enumerate(map(int, input().split())):
if i % 2 == 0 and a % 2 == 1:
c += 1
print(c)
| N = int(eval(input()))
As = list(map(int, input().split()))
ans = 0
for i, A in enumerate(As):
if i % 2 == 0 and A % 2 == 1:
ans += 1
print(ans)
| false | 22.222222 | [
"-c = 0",
"-for i, a in enumerate(map(int, input().split())):",
"- if i % 2 == 0 and a % 2 == 1:",
"- c += 1",
"-print(c)",
"+As = list(map(int, input().split()))",
"+ans = 0",
"+for i, A in enumerate(As):",
"+ if i % 2 == 0 and A % 2 == 1:",
"+ ans += 1",
"+print(ans)"
] | false | 0.082863 | 0.040593 | 2.041321 | [
"s590955535",
"s679745550"
] |
u319899784 | p03805 | python | s101797791 | s662497023 | 44 | 34 | 9,132 | 9,196 | Accepted | Accepted | 22.73 | import itertools
N, M = list(map(int, input().split()))
ab = []
for _ in range(M):
a, b = list(map(int, input().split()))
ab.append({a-1, b-1})
ans = 0
for v in itertools.permutations(list(range(1, N))):
ok = True
a = 0
for b in v:
if {a, b} not in ab:
ok = False
break
a = b
if ok:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
ab = [[] for _ 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)
ans = 0
def dfs(x, visited):
global ans
if len(visited) == N:
ans += 1
return
for b in ab[x]:
if b not in visited:
dfs(b, visited + [b])
return
dfs(0, [0])
print(ans)
| 21 | 21 | 380 | 407 | import itertools
N, M = list(map(int, input().split()))
ab = []
for _ in range(M):
a, b = list(map(int, input().split()))
ab.append({a - 1, b - 1})
ans = 0
for v in itertools.permutations(list(range(1, N))):
ok = True
a = 0
for b in v:
if {a, b} not in ab:
ok = False
break
a = b
if ok:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
ab = [[] for _ 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)
ans = 0
def dfs(x, visited):
global ans
if len(visited) == N:
ans += 1
return
for b in ab[x]:
if b not in visited:
dfs(b, visited + [b])
return
dfs(0, [0])
print(ans)
| false | 0 | [
"-import itertools",
"-",
"-ab = []",
"+ab = [[] for _ in range(N)]",
"- ab.append({a - 1, b - 1})",
"+ ab[a - 1].append(b - 1)",
"+ ab[b - 1].append(a - 1)",
"-for v in itertools.permutations(list(range(1, N))):",
"- ok = True",
"- a = 0",
"- for b in v:",
"- if {a, b... | false | 0.050464 | 0.038464 | 1.311977 | [
"s101797791",
"s662497023"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.