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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u368249389 | p02784 | python | s000004615 | s273759263 | 199 | 42 | 52,292 | 13,964 | Accepted | Accepted | 78.89 | # Problem B - Common Raccoon vs Monster
# input
h, n = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
a_sum = sum(a_list)
# output
if h - a_sum<=0:
print("Yes")
else:
print("No")
| # Problem B - Common Raccoon vs Monster
# input
H, N = list(map(int, input().split()))
a_nums = list(map(int, input().split()))
# initialization
a_sum = sum(a_nums)
# output
if a_sum>=H:
print("Yes")
else:
print("No")
| 14 | 14 | 240 | 236 | # Problem B - Common Raccoon vs Monster
# input
h, n = list(map(int, input().split()))
a_list = list(map(int, input().split()))
# initialization
a_sum = sum(a_list)
# output
if h - a_sum <= 0:
print("Yes")
else:
print("No")
| # Problem B - Common Raccoon vs Monster
# input
H, N = list(map(int, input().split()))
a_nums = list(map(int, input().split()))
# initialization
a_sum = sum(a_nums)
# output
if a_sum >= H:
print("Yes")
else:
print("No")
| false | 0 | [
"-h, n = list(map(int, input().split()))",
"-a_list = list(map(int, input().split()))",
"+H, N = list(map(int, input().split()))",
"+a_nums = list(map(int, input().split()))",
"-a_sum = sum(a_list)",
"+a_sum = sum(a_nums)",
"-if h - a_sum <= 0:",
"+if a_sum >= H:"
]
| false | 0.040683 | 0.074239 | 0.548007 | [
"s000004615",
"s273759263"
]
|
u489959379 | p03212 | python | s762740447 | s014126268 | 74 | 67 | 2,940 | 3,064 | Accepted | Accepted | 9.46 | n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
for i in '753':
if s.count(i) == 0:
res = 0
break
else:
res = 1
for i in '753':
res += dfs(s + i)
return res
print((dfs('0')))
| import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = 0
def resolve():
n = int(eval(input()))
def is_ok(L):
l = "".join(L)
if int(l) <= n:
for i in ["7", "5", "3"]:
if i not in l:
return False
else:
return True
else:
return False
def dfs(L):
global res
if len(L) == len(str(n)):
return
for i in ["7", "5", "3"]:
L.append(i)
if is_ok(L):
res += 1
dfs(L)
L.pop()
return res
print((dfs([])))
if __name__ == '__main__':
resolve()
| 19 | 41 | 277 | 741 | n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
for i in "753":
if s.count(i) == 0:
res = 0
break
else:
res = 1
for i in "753":
res += dfs(s + i)
return res
print((dfs("0")))
| import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
res = 0
def resolve():
n = int(eval(input()))
def is_ok(L):
l = "".join(L)
if int(l) <= n:
for i in ["7", "5", "3"]:
if i not in l:
return False
else:
return True
else:
return False
def dfs(L):
global res
if len(L) == len(str(n)):
return
for i in ["7", "5", "3"]:
L.append(i)
if is_ok(L):
res += 1
dfs(L)
L.pop()
return res
print((dfs([])))
if __name__ == "__main__":
resolve()
| false | 53.658537 | [
"-n = int(eval(input()))",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+res = 0",
"-def dfs(s):",
"- if int(s) > n:",
"- return 0",
"- for i in \"753\":",
"- if s.count(i) == 0:",
"- res = 0",
"- break",
"- else:",
"- res = 1",
"- for i in \"753\":",
"- res += dfs(s + i)",
"- return res",
"+def resolve():",
"+ n = int(eval(input()))",
"+",
"+ def is_ok(L):",
"+ l = \"\".join(L)",
"+ if int(l) <= n:",
"+ for i in [\"7\", \"5\", \"3\"]:",
"+ if i not in l:",
"+ return False",
"+ else:",
"+ return True",
"+ else:",
"+ return False",
"+",
"+ def dfs(L):",
"+ global res",
"+ if len(L) == len(str(n)):",
"+ return",
"+ for i in [\"7\", \"5\", \"3\"]:",
"+ L.append(i)",
"+ if is_ok(L):",
"+ res += 1",
"+ dfs(L)",
"+ L.pop()",
"+ return res",
"+",
"+ print((dfs([])))",
"-print((dfs(\"0\")))",
"+if __name__ == \"__main__\":",
"+ resolve()"
]
| false | 0.044585 | 0.160311 | 0.278112 | [
"s762740447",
"s014126268"
]
|
u588341295 | p03776 | python | s425939787 | s193330110 | 25 | 22 | 3,316 | 3,316 | Accepted | Accepted | 12 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
from collections import Counter
from math import factorial
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n-r)
return factorial(n) / factorial(r) / factorial(n-r)
round = lambda x: int((x*2+1) // 2)
N, A, B = list(map(int, input().split()))
vN = list(map(int, input().split()))
# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値が欲しいので降順ソートしておく
vN.sort(reverse=True)
mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
avg = sum(vN[:i]) / i
if avg == mx_avg:
# 平均値が最大になるなら、選び方リストに追加
lists.append(vN[:i])
ans = 0
for l in lists:
# 選び方を、同じ値の個数毎にまとめる
c2 = Counter(l)
combs = 1
for k, v in list(c2.items()):
# 同じ値が複数ある場合の組み合わせを出す
combs *= nCr(c[k], v)
ans += combs
print(mx_avg)
print((round(ans)))
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
from collections import Counter
MAX = 51
# 階乗テーブル
factorial = [1] * (MAX)
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
factorial[i] = factorial[i-1] * i
# 組み合わせの数(必要な階乗のテーブルを事前に作っておく)
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n-r)
# 分子の計算
numerator = factorial[n]
# 分母の計算
denominator = factorial[r] * factorial[n-r]
return numerator / denominator
round = lambda x: int((x*2+1) // 2)
N, A, B = list(map(int, input().split()))
vN = list(map(int, input().split()))
# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値から欲しいので降順ソートしておく
vN.sort(reverse=True)
mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
avg = sum(vN[:i]) / i
if avg == mx_avg:
# 平均値が最大になるなら、選び方リストに追加
lists.append(vN[:i])
ans = 0
for l in lists:
# 選び方を、同じ値の個数毎にまとめる
c2 = Counter(l)
combs = 1
for k, v in list(c2.items()):
# 同じ値が複数ある場合の組み合わせを出す
combs *= nCr(c[k], v)
ans += combs
print(mx_avg)
print((round(ans)))
| 43 | 54 | 922 | 1,155 | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
from collections import Counter
from math import factorial
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n - r)
return factorial(n) / factorial(r) / factorial(n - r)
round = lambda x: int((x * 2 + 1) // 2)
N, A, B = list(map(int, input().split()))
vN = list(map(int, input().split()))
# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値が欲しいので降順ソートしておく
vN.sort(reverse=True)
mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A + 1, B + 1):
avg = sum(vN[:i]) / i
if avg == mx_avg:
# 平均値が最大になるなら、選び方リストに追加
lists.append(vN[:i])
ans = 0
for l in lists:
# 選び方を、同じ値の個数毎にまとめる
c2 = Counter(l)
combs = 1
for k, v in list(c2.items()):
# 同じ値が複数ある場合の組み合わせを出す
combs *= nCr(c[k], v)
ans += combs
print(mx_avg)
print((round(ans)))
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10**9)
from collections import Counter
MAX = 51
# 階乗テーブル
factorial = [1] * (MAX)
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
factorial[i] = factorial[i - 1] * i
# 組み合わせの数(必要な階乗のテーブルを事前に作っておく)
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n - r)
# 分子の計算
numerator = factorial[n]
# 分母の計算
denominator = factorial[r] * factorial[n - r]
return numerator / denominator
round = lambda x: int((x * 2 + 1) // 2)
N, A, B = list(map(int, input().split()))
vN = list(map(int, input().split()))
# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値から欲しいので降順ソートしておく
vN.sort(reverse=True)
mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A + 1, B + 1):
avg = sum(vN[:i]) / i
if avg == mx_avg:
# 平均値が最大になるなら、選び方リストに追加
lists.append(vN[:i])
ans = 0
for l in lists:
# 選び方を、同じ値の個数毎にまとめる
c2 = Counter(l)
combs = 1
for k, v in list(c2.items()):
# 同じ値が複数ある場合の組み合わせを出す
combs *= nCr(c[k], v)
ans += combs
print(mx_avg)
print((round(ans)))
| false | 20.37037 | [
"-from math import factorial",
"-",
"+MAX = 51",
"+# 階乗テーブル",
"+factorial = [1] * (MAX)",
"+factorial[0] = factorial[1] = 1",
"+for i in range(2, MAX):",
"+ factorial[i] = factorial[i - 1] * i",
"+# 組み合わせの数(必要な階乗のテーブルを事前に作っておく)",
"- return factorial(n) / factorial(r) / factorial(n - r)",
"+ # 分子の計算",
"+ numerator = factorial[n]",
"+ # 分母の計算",
"+ denominator = factorial[r] * factorial[n - r]",
"+ return numerator / denominator",
"-# 大きい値が欲しいので降順ソートしておく",
"+# 大きい値から欲しいので降順ソートしておく"
]
| false | 0.049505 | 0.050621 | 0.977961 | [
"s425939787",
"s193330110"
]
|
u698031448 | p03165 | python | s450661371 | s545250445 | 794 | 283 | 153,096 | 144,560 | Accepted | Accepted | 64.36 |
# Returns length of LCS for X[0..m-1], Y[0..n-1]
def lcs(X, Y, m, n):
L = [[0 for x in range(n+1)] for x in range(m+1)]
# Following steps build L[m+1][n+1] in bottom up fashion. Note
# that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1]
for i in range(m+1):
for j in range(n+1):
if i == 0 or j == 0:
L[i][j] = 0
elif X[i-1] == Y[j-1]:
L[i][j] = L[i-1][j-1] + 1
else:
L[i][j] = max(L[i-1][j], L[i][j-1])
# Following code is used to print LCS
index = L[m][n]
# Create a character array to store the lcs string
lcs = [""] * (index+1)
lcs[index] = ""
# Start from the right-most-bottom-most corner and
# one by one store characters in lcs[]
i = m
j = n
while i > 0 and j > 0:
# If current character in X[] and Y are same, then
# current character is part of LCS
if X[i-1] == Y[j-1]:
lcs[index-1] = X[i-1]
i-=1
j-=1
index-=1
# If not same, then find the larger of two and
# go in the direction of larger value
elif L[i-1][j] > L[i][j-1]:
i-=1
else:
j-=1
print((''.join(lcs)))
# Driver program
s=eval(input())
t=eval(input())
m = len(s)
n = len(t)
lcs(s, t, m, n) | s=eval(input())
t=eval(input())
dp=[[0]*(len(t)+1) for i in range(len(s)+1)]
for i in range(1,len(s)+1):
for j in range(1,len(t)+1):
if s[i-1]==t[j-1]:
dp[i][j]=dp[i-1][j-1]+1
else:
dp[i][j]=max(dp[i-1][j],dp[i][j-1])
# print(dp[i])
ans=''
i,j=len(s),len(t)
while i > 0 and j > 0:
if s[i-1]==t[j-1]:
ans=s[i-1]+ans
i=i-1
j=j-1
else:
if dp[i-1][j]>dp[i][j-1]:
i-=1
else:
j-=1
print(ans)
| 53 | 25 | 1,220 | 484 | # Returns length of LCS for X[0..m-1], Y[0..n-1]
def lcs(X, Y, m, n):
L = [[0 for x in range(n + 1)] for x in range(m + 1)]
# Following steps build L[m+1][n+1] in bottom up fashion. Note
# that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
L[i][j] = 0
elif X[i - 1] == Y[j - 1]:
L[i][j] = L[i - 1][j - 1] + 1
else:
L[i][j] = max(L[i - 1][j], L[i][j - 1])
# Following code is used to print LCS
index = L[m][n]
# Create a character array to store the lcs string
lcs = [""] * (index + 1)
lcs[index] = ""
# Start from the right-most-bottom-most corner and
# one by one store characters in lcs[]
i = m
j = n
while i > 0 and j > 0:
# If current character in X[] and Y are same, then
# current character is part of LCS
if X[i - 1] == Y[j - 1]:
lcs[index - 1] = X[i - 1]
i -= 1
j -= 1
index -= 1
# If not same, then find the larger of two and
# go in the direction of larger value
elif L[i - 1][j] > L[i][j - 1]:
i -= 1
else:
j -= 1
print(("".join(lcs)))
# Driver program
s = eval(input())
t = eval(input())
m = len(s)
n = len(t)
lcs(s, t, m, n)
| s = eval(input())
t = eval(input())
dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]
for i in range(1, len(s) + 1):
for j in range(1, len(t) + 1):
if s[i - 1] == t[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
# print(dp[i])
ans = ""
i, j = len(s), len(t)
while i > 0 and j > 0:
if s[i - 1] == t[j - 1]:
ans = s[i - 1] + ans
i = i - 1
j = j - 1
else:
if dp[i - 1][j] > dp[i][j - 1]:
i -= 1
else:
j -= 1
print(ans)
| false | 52.830189 | [
"-# Returns length of LCS for X[0..m-1], Y[0..n-1]",
"-def lcs(X, Y, m, n):",
"- L = [[0 for x in range(n + 1)] for x in range(m + 1)]",
"- # Following steps build L[m+1][n+1] in bottom up fashion. Note",
"- # that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1]",
"- for i in range(m + 1):",
"- for j in range(n + 1):",
"- if i == 0 or j == 0:",
"- L[i][j] = 0",
"- elif X[i - 1] == Y[j - 1]:",
"- L[i][j] = L[i - 1][j - 1] + 1",
"- else:",
"- L[i][j] = max(L[i - 1][j], L[i][j - 1])",
"- # Following code is used to print LCS",
"- index = L[m][n]",
"- # Create a character array to store the lcs string",
"- lcs = [\"\"] * (index + 1)",
"- lcs[index] = \"\"",
"- # Start from the right-most-bottom-most corner and",
"- # one by one store characters in lcs[]",
"- i = m",
"- j = n",
"- while i > 0 and j > 0:",
"- # If current character in X[] and Y are same, then",
"- # current character is part of LCS",
"- if X[i - 1] == Y[j - 1]:",
"- lcs[index - 1] = X[i - 1]",
"- i -= 1",
"- j -= 1",
"- index -= 1",
"- # If not same, then find the larger of two and",
"- # go in the direction of larger value",
"- elif L[i - 1][j] > L[i][j - 1]:",
"+s = eval(input())",
"+t = eval(input())",
"+dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]",
"+for i in range(1, len(s) + 1):",
"+ for j in range(1, len(t) + 1):",
"+ if s[i - 1] == t[j - 1]:",
"+ dp[i][j] = dp[i - 1][j - 1] + 1",
"+ else:",
"+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])",
"+ # print(dp[i])",
"+ans = \"\"",
"+i, j = len(s), len(t)",
"+while i > 0 and j > 0:",
"+ if s[i - 1] == t[j - 1]:",
"+ ans = s[i - 1] + ans",
"+ i = i - 1",
"+ j = j - 1",
"+ else:",
"+ if dp[i - 1][j] > dp[i][j - 1]:",
"- print((\"\".join(lcs)))",
"-",
"-",
"-# Driver program",
"-s = eval(input())",
"-t = eval(input())",
"-m = len(s)",
"-n = len(t)",
"-lcs(s, t, m, n)",
"+print(ans)"
]
| false | 0.077915 | 0.038655 | 2.015655 | [
"s450661371",
"s545250445"
]
|
u757117214 | p03680 | python | s066123125 | s375618191 | 209 | 66 | 7,192 | 13,940 | Accepted | Accepted | 68.42 | n=int(eval(input()))
a=[]
cnt=0
now=0
for i in range(n):
a.append(int(eval(input()))-1)
flg=False
for i in range(n):
if now==1:
flg=True
break
now=a[now]
cnt+=1
print((cnt if flg else -1)) | N,*a = list(map(int,open(0).read().split()))
a.insert(0,0)
flg = False
on = 1
cnt = 0
for i in range(N):
on = a[on]
cnt += 1
if on == 2:
print(cnt)
exit()
print((-1)) | 14 | 12 | 205 | 205 | n = int(eval(input()))
a = []
cnt = 0
now = 0
for i in range(n):
a.append(int(eval(input())) - 1)
flg = False
for i in range(n):
if now == 1:
flg = True
break
now = a[now]
cnt += 1
print((cnt if flg else -1))
| N, *a = list(map(int, open(0).read().split()))
a.insert(0, 0)
flg = False
on = 1
cnt = 0
for i in range(N):
on = a[on]
cnt += 1
if on == 2:
print(cnt)
exit()
print((-1))
| false | 14.285714 | [
"-n = int(eval(input()))",
"-a = []",
"+N, *a = list(map(int, open(0).read().split()))",
"+a.insert(0, 0)",
"+flg = False",
"+on = 1",
"-now = 0",
"-for i in range(n):",
"- a.append(int(eval(input())) - 1)",
"-flg = False",
"-for i in range(n):",
"- if now == 1:",
"- flg = True",
"- break",
"- now = a[now]",
"+for i in range(N):",
"+ on = a[on]",
"-print((cnt if flg else -1))",
"+ if on == 2:",
"+ print(cnt)",
"+ exit()",
"+print((-1))"
]
| false | 0.034707 | 0.035978 | 0.964667 | [
"s066123125",
"s375618191"
]
|
u606045429 | p03241 | python | s154008626 | s187599901 | 24 | 22 | 3,060 | 2,940 | Accepted | Accepted | 8.33 | def divisors(N):
res = []
i = 1
while i * i <= N:
q, r = N // i, N % i
if r == 0:
res.append(i)
if i != q:
res.append(q)
i += 1
res.sort()
return res
N, M = list(map(int, input().split()))
print((max(d for d in divisors(M) if d * N <= M)))
| def divisors(N):
res = []
i = 1
while i * i <= N:
if N % i == 0:
res.append(i)
q = N // i
if i != q:
res.append(q)
i += 1
res.sort()
return res
N, M = list(map(int, input().split()))
print((max(d for d in divisors(M) if d * N <= M)))
| 15 | 15 | 331 | 329 | def divisors(N):
res = []
i = 1
while i * i <= N:
q, r = N // i, N % i
if r == 0:
res.append(i)
if i != q:
res.append(q)
i += 1
res.sort()
return res
N, M = list(map(int, input().split()))
print((max(d for d in divisors(M) if d * N <= M)))
| def divisors(N):
res = []
i = 1
while i * i <= N:
if N % i == 0:
res.append(i)
q = N // i
if i != q:
res.append(q)
i += 1
res.sort()
return res
N, M = list(map(int, input().split()))
print((max(d for d in divisors(M) if d * N <= M)))
| false | 0 | [
"- q, r = N // i, N % i",
"- if r == 0:",
"+ if N % i == 0:",
"+ q = N // i"
]
| false | 0.048779 | 0.053329 | 0.914677 | [
"s154008626",
"s187599901"
]
|
u475503988 | p02734 | python | s915111777 | s419988846 | 620 | 531 | 112,988 | 43,372 | Accepted | Accepted | 14.35 | import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353
N, S = list(map(int, input().split()))
A = list(map(int, list(input().split())))
ans = 0
dp = [[0]*(S+1) for _ in range(N+1)]
for i in range(N):
dp[i][0] += 1 # Lがiからを足す
for j in range(S+1):
dp[i+1][j] += dp[i][j] # A[i]を選ばない
dp[i+1][j] %= MOD
if j+A[i]<=S:
dp[i+1][j+A[i]] += dp[i][j] # A[i]を選ぶ
dp[i+1][j+A[i]] %= MOD
ans += dp[i+1][S] # Rがiまでを足す
ans %= MOD
print(ans) | import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353
N, S = list(map(int, input().split()))
A = list(map(int, list(input().split())))
ans = 0
dp = [0]*(S+1)
for i in range(N):
dp[0] += 1 # Lがiからを足す
next_dp = [0]*(S+1)
for j in range(S+1):
next_dp[j] += dp[j] # A[i]を選ばない
next_dp[j] %= MOD
if j+A[i]<=S:
next_dp[j+A[i]] += dp[j] # A[i]を選ぶ
next_dp[j+A[i]] %= MOD
dp = next_dp
ans += dp[S] # Rがiまでを足す
ans %= MOD
print(ans) | 22 | 24 | 583 | 589 | import sys
def input():
return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
MOD = 998244353
N, S = list(map(int, input().split()))
A = list(map(int, list(input().split())))
ans = 0
dp = [[0] * (S + 1) for _ in range(N + 1)]
for i in range(N):
dp[i][0] += 1 # Lがiからを足す
for j in range(S + 1):
dp[i + 1][j] += dp[i][j] # A[i]を選ばない
dp[i + 1][j] %= MOD
if j + A[i] <= S:
dp[i + 1][j + A[i]] += dp[i][j] # A[i]を選ぶ
dp[i + 1][j + A[i]] %= MOD
ans += dp[i + 1][S] # Rがiまでを足す
ans %= MOD
print(ans)
| import sys
def input():
return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
MOD = 998244353
N, S = list(map(int, input().split()))
A = list(map(int, list(input().split())))
ans = 0
dp = [0] * (S + 1)
for i in range(N):
dp[0] += 1 # Lがiからを足す
next_dp = [0] * (S + 1)
for j in range(S + 1):
next_dp[j] += dp[j] # A[i]を選ばない
next_dp[j] %= MOD
if j + A[i] <= S:
next_dp[j + A[i]] += dp[j] # A[i]を選ぶ
next_dp[j + A[i]] %= MOD
dp = next_dp
ans += dp[S] # Rがiまでを足す
ans %= MOD
print(ans)
| false | 8.333333 | [
"-dp = [[0] * (S + 1) for _ in range(N + 1)]",
"+dp = [0] * (S + 1)",
"- dp[i][0] += 1 # Lがiからを足す",
"+ dp[0] += 1 # Lがiからを足す",
"+ next_dp = [0] * (S + 1)",
"- dp[i + 1][j] += dp[i][j] # A[i]を選ばない",
"- dp[i + 1][j] %= MOD",
"+ next_dp[j] += dp[j] # A[i]を選ばない",
"+ next_dp[j] %= MOD",
"- dp[i + 1][j + A[i]] += dp[i][j] # A[i]を選ぶ",
"- dp[i + 1][j + A[i]] %= MOD",
"- ans += dp[i + 1][S] # Rがiまでを足す",
"+ next_dp[j + A[i]] += dp[j] # A[i]を選ぶ",
"+ next_dp[j + A[i]] %= MOD",
"+ dp = next_dp",
"+ ans += dp[S] # Rがiまでを足す"
]
| false | 0.038446 | 0.111402 | 0.345112 | [
"s915111777",
"s419988846"
]
|
u561231954 | p02617 | python | s963937140 | s526828270 | 668 | 388 | 46,676 | 9,076 | Accepted | Accepted | 41.92 | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
a,b = list(map(int,input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
parents = [-1] * N
stack = [0]
while stack:
v = stack.pop()
for e in G[v]:
if e == 0 or parents[e] >= 0:
continue
parents[e] = v
stack.append(e)
ans = N
for i in range(1,N):
if parents[i] > i:
ans += (parents[i] - i) * (i + 1)
else:
ans += (i - parents[i]) * (N - i)
print(ans)
if __name__ == '__main__':
main() | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
N = int(eval(input()))
ans = 0
for i in range(N):
ans += (i + 1)*(N - i)
for _ in range(N - 1):
a,b = list(map(int,input().split()))
a -= 1
b -= 1
if a > b:
a,b = b,a
ans -= (N - b) * (a + 1)
print(ans)
if __name__ == '__main__':
main() | 34 | 20 | 773 | 416 | import sys
sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15
def main():
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
parents = [-1] * N
stack = [0]
while stack:
v = stack.pop()
for e in G[v]:
if e == 0 or parents[e] >= 0:
continue
parents[e] = v
stack.append(e)
ans = N
for i in range(1, N):
if parents[i] > i:
ans += (parents[i] - i) * (i + 1)
else:
ans += (i - parents[i]) * (N - i)
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10000000)
MOD = 10**9 + 7
INF = 10**15
def main():
N = int(eval(input()))
ans = 0
for i in range(N):
ans += (i + 1) * (N - i)
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
if a > b:
a, b = b, a
ans -= (N - b) * (a + 1)
print(ans)
if __name__ == "__main__":
main()
| false | 41.176471 | [
"- G = [[] for _ in range(N)]",
"+ ans = 0",
"+ for i in range(N):",
"+ ans += (i + 1) * (N - i)",
"- G[a].append(b)",
"- G[b].append(a)",
"- parents = [-1] * N",
"- stack = [0]",
"- while stack:",
"- v = stack.pop()",
"- for e in G[v]:",
"- if e == 0 or parents[e] >= 0:",
"- continue",
"- parents[e] = v",
"- stack.append(e)",
"- ans = N",
"- for i in range(1, N):",
"- if parents[i] > i:",
"- ans += (parents[i] - i) * (i + 1)",
"- else:",
"- ans += (i - parents[i]) * (N - i)",
"+ if a > b:",
"+ a, b = b, a",
"+ ans -= (N - b) * (a + 1)"
]
| false | 0.119537 | 0.081482 | 1.467039 | [
"s963937140",
"s526828270"
]
|
u658288444 | p03408 | python | s945307954 | s458097600 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | b = [eval(input()) for i in range(int(eval(input())))]
r = [eval(input()) for i in range(int(eval(input())))]
o = 0
for w in list(set(b)):
o = max(o, b.count(w) - r.count(w))
print(o) | b = [eval(input()) for i in range(int(eval(input())))]
r = [eval(input()) for i in range(int(eval(input())))]
k = 0
for w in list(set(b)):
k = max(k, b.count(w) - r.count(w))
print(k) | 7 | 6 | 170 | 166 | b = [eval(input()) for i in range(int(eval(input())))]
r = [eval(input()) for i in range(int(eval(input())))]
o = 0
for w in list(set(b)):
o = max(o, b.count(w) - r.count(w))
print(o)
| b = [eval(input()) for i in range(int(eval(input())))]
r = [eval(input()) for i in range(int(eval(input())))]
k = 0
for w in list(set(b)):
k = max(k, b.count(w) - r.count(w))
print(k)
| false | 14.285714 | [
"-o = 0",
"+k = 0",
"- o = max(o, b.count(w) - r.count(w))",
"-print(o)",
"+ k = max(k, b.count(w) - r.count(w))",
"+print(k)"
]
| false | 0.039553 | 0.034796 | 1.136719 | [
"s945307954",
"s458097600"
]
|
u537962130 | p02841 | python | s628960877 | s515709375 | 185 | 169 | 38,256 | 38,384 | Accepted | Accepted | 8.65 | m1,d1=list(map(int,input().split()))
m2,d2=list(map(int,input().split()))
print(((m1<m2 and d1>d2)+0)) | m,d=list(map(int,input().split()))
mm,dd=list(map(int,input().split()))
print(('01'[m<mm])) | 3 | 3 | 90 | 79 | m1, d1 = list(map(int, input().split()))
m2, d2 = list(map(int, input().split()))
print(((m1 < m2 and d1 > d2) + 0))
| m, d = list(map(int, input().split()))
mm, dd = list(map(int, input().split()))
print(("01"[m < mm]))
| false | 0 | [
"-m1, d1 = list(map(int, input().split()))",
"-m2, d2 = list(map(int, input().split()))",
"-print(((m1 < m2 and d1 > d2) + 0))",
"+m, d = list(map(int, input().split()))",
"+mm, dd = list(map(int, input().split()))",
"+print((\"01\"[m < mm]))"
]
| false | 0.110885 | 0.111225 | 0.996943 | [
"s628960877",
"s515709375"
]
|
u540761833 | p03699 | python | s130099243 | s404796632 | 997 | 18 | 28,516 | 3,060 | Accepted | Accepted | 98.19 | N = int(eval(input()))
s = []
for i in range(N):
s.append(int(eval(input())))
ssum = sum(s)
dp = [[-(10**5) for i in range(ssum+1)] for j in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
for j in range(ssum+1):
if j-s[i-1] >= 0:
dp[i][j] = max(dp[i-1][j],dp[i-1][j-s[i-1]]+s[i-1])
else:
dp[i][j] = dp[i-1][j]
maxa = 0
for j in range(N+1):
for i in range(ssum+1):
if (dp[j][i])%10 == 0:
continue
else:
now = dp[j][i]
maxa = max(maxa,now)
print(maxa) | N = int(eval(input()))
s = []
for i in range(N):
s.append(int(eval(input())))
s.sort()
ssum = sum(s)
c = 0
for i in s:
if ssum%10 != 0:
print(ssum)
c = 1
break
if i%10 != 0:
ssum -= i
if c == 0:
print((0)) | 25 | 16 | 569 | 254 | N = int(eval(input()))
s = []
for i in range(N):
s.append(int(eval(input())))
ssum = sum(s)
dp = [[-(10**5) for i in range(ssum + 1)] for j in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
for j in range(ssum + 1):
if j - s[i - 1] >= 0:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - s[i - 1]] + s[i - 1])
else:
dp[i][j] = dp[i - 1][j]
maxa = 0
for j in range(N + 1):
for i in range(ssum + 1):
if (dp[j][i]) % 10 == 0:
continue
else:
now = dp[j][i]
maxa = max(maxa, now)
print(maxa)
| N = int(eval(input()))
s = []
for i in range(N):
s.append(int(eval(input())))
s.sort()
ssum = sum(s)
c = 0
for i in s:
if ssum % 10 != 0:
print(ssum)
c = 1
break
if i % 10 != 0:
ssum -= i
if c == 0:
print((0))
| false | 36 | [
"+s.sort()",
"-dp = [[-(10**5) for i in range(ssum + 1)] for j in range(N + 1)]",
"-dp[0][0] = 0",
"-for i in range(1, N + 1):",
"- for j in range(ssum + 1):",
"- if j - s[i - 1] >= 0:",
"- dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - s[i - 1]] + s[i - 1])",
"- else:",
"- dp[i][j] = dp[i - 1][j]",
"-maxa = 0",
"-for j in range(N + 1):",
"- for i in range(ssum + 1):",
"- if (dp[j][i]) % 10 == 0:",
"- continue",
"- else:",
"- now = dp[j][i]",
"- maxa = max(maxa, now)",
"-print(maxa)",
"+c = 0",
"+for i in s:",
"+ if ssum % 10 != 0:",
"+ print(ssum)",
"+ c = 1",
"+ break",
"+ if i % 10 != 0:",
"+ ssum -= i",
"+if c == 0:",
"+ print((0))"
]
| false | 0.116295 | 0.048349 | 2.405302 | [
"s130099243",
"s404796632"
]
|
u895660619 | p02267 | python | s633448374 | s655470989 | 60 | 20 | 8,160 | 8,196 | Accepted | Accepted | 66.67 | n = int(eval(input()))
s = input().split()
q = int(eval(input()))
t = input().split()
cont = 0
for i in t:
for o in s:
if i == o:
cont +=1
break
print(cont) | n = int(eval(input()))
s = set(input().split())
q = int(eval(input()))
t = set(input().split())
print((len(s & t))) | 12 | 6 | 192 | 107 | n = int(eval(input()))
s = input().split()
q = int(eval(input()))
t = input().split()
cont = 0
for i in t:
for o in s:
if i == o:
cont += 1
break
print(cont)
| n = int(eval(input()))
s = set(input().split())
q = int(eval(input()))
t = set(input().split())
print((len(s & t)))
| false | 50 | [
"-s = input().split()",
"+s = set(input().split())",
"-t = input().split()",
"-cont = 0",
"-for i in t:",
"- for o in s:",
"- if i == o:",
"- cont += 1",
"- break",
"-print(cont)",
"+t = set(input().split())",
"+print((len(s & t)))"
]
| false | 0.033844 | 0.034167 | 0.990543 | [
"s633448374",
"s655470989"
]
|
u197615397 | p02323 | python | s616626089 | s694169494 | 190 | 160 | 8,916 | 8,704 | Accepted | Accepted | 15.79 | def solve():
V, E = list(map(int, input().split()))
edges = [[] for _ in [0]*V]
for _ in [0]*E:
s, t, d = list(map(int, input().split()))
edges[s].append((t, d))
result = float("inf")
beam_width = 80
for i in range(V):
q = [(0, i, {i})]
for j in range(V-1):
_q = []
append = _q.append
for cost, v, visited in q[:beam_width+1]:
for dest, d_cost in edges[v]:
if dest not in visited:
append((cost+d_cost, dest, visited | {dest}))
q = sorted(_q)
for cost, v, visited in q[:beam_width+1]:
for dest, d_cost in edges[v]:
if dest == i:
if result > cost + d_cost:
result = cost + d_cost
break
print((result if result < float("inf") else -1))
if __name__ == "__main__":
solve() | def solve():
V, E = list(map(int, input().split()))
edges = [[] for _ in [0]*V]
for _ in [0]*E:
s, t, d = list(map(int, input().split()))
edges[s].append((t, d))
result = float("inf")
beam_width = 70
for i in range(V):
q = [(0, i, {i})]
for j in range(V-1):
_q = []
append = _q.append
for cost, v, visited in q[:beam_width+1]:
for dest, d_cost in edges[v]:
if dest not in visited:
append((cost+d_cost, dest, visited | {dest}))
q = sorted(_q)
for cost, v, visited in q[:beam_width+1]:
for dest, d_cost in edges[v]:
if dest == i:
if result > cost + d_cost:
result = cost + d_cost
break
print((result if result < float("inf") else -1))
if __name__ == "__main__":
solve() | 31 | 31 | 963 | 963 | def solve():
V, E = list(map(int, input().split()))
edges = [[] for _ in [0] * V]
for _ in [0] * E:
s, t, d = list(map(int, input().split()))
edges[s].append((t, d))
result = float("inf")
beam_width = 80
for i in range(V):
q = [(0, i, {i})]
for j in range(V - 1):
_q = []
append = _q.append
for cost, v, visited in q[: beam_width + 1]:
for dest, d_cost in edges[v]:
if dest not in visited:
append((cost + d_cost, dest, visited | {dest}))
q = sorted(_q)
for cost, v, visited in q[: beam_width + 1]:
for dest, d_cost in edges[v]:
if dest == i:
if result > cost + d_cost:
result = cost + d_cost
break
print((result if result < float("inf") else -1))
if __name__ == "__main__":
solve()
| def solve():
V, E = list(map(int, input().split()))
edges = [[] for _ in [0] * V]
for _ in [0] * E:
s, t, d = list(map(int, input().split()))
edges[s].append((t, d))
result = float("inf")
beam_width = 70
for i in range(V):
q = [(0, i, {i})]
for j in range(V - 1):
_q = []
append = _q.append
for cost, v, visited in q[: beam_width + 1]:
for dest, d_cost in edges[v]:
if dest not in visited:
append((cost + d_cost, dest, visited | {dest}))
q = sorted(_q)
for cost, v, visited in q[: beam_width + 1]:
for dest, d_cost in edges[v]:
if dest == i:
if result > cost + d_cost:
result = cost + d_cost
break
print((result if result < float("inf") else -1))
if __name__ == "__main__":
solve()
| false | 0 | [
"- beam_width = 80",
"+ beam_width = 70"
]
| false | 0.044821 | 0.044626 | 1.004359 | [
"s616626089",
"s694169494"
]
|
u906337264 | p03239 | python | s887989231 | s346988464 | 21 | 17 | 2,940 | 2,940 | Accepted | Accepted | 19.05 | N, T = list(map(int, input().split()))
c = []
t = []
for _ in range(N):
_c, _t = list(map(int, input().split()))
if _t <= T:
c.append(_c)
t.append(_t)
if len(c) == 0:
print('TLE')
else:
print((min(c)))
| N, T = list(map(int, input().split()))
min_c = 1001
for _ in range(N):
_c, _t = list(map(int, input().split()))
if _t <= T:
min_c = min(min_c, _c)
if min_c == 1001:
print('TLE')
else:
print(min_c)
| 16 | 14 | 242 | 226 | N, T = list(map(int, input().split()))
c = []
t = []
for _ in range(N):
_c, _t = list(map(int, input().split()))
if _t <= T:
c.append(_c)
t.append(_t)
if len(c) == 0:
print("TLE")
else:
print((min(c)))
| N, T = list(map(int, input().split()))
min_c = 1001
for _ in range(N):
_c, _t = list(map(int, input().split()))
if _t <= T:
min_c = min(min_c, _c)
if min_c == 1001:
print("TLE")
else:
print(min_c)
| false | 12.5 | [
"-c = []",
"-t = []",
"+min_c = 1001",
"- c.append(_c)",
"- t.append(_t)",
"-if len(c) == 0:",
"+ min_c = min(min_c, _c)",
"+if min_c == 1001:",
"- print((min(c)))",
"+ print(min_c)"
]
| false | 0.04032 | 0.044007 | 0.916217 | [
"s887989231",
"s346988464"
]
|
u380524497 | p03295 | python | s525140232 | s449760696 | 300 | 234 | 27,740 | 6,900 | Accepted | Accepted | 22 | import sys
from collections import defaultdict
input = sys.stdin.readline
n, m = list(map(int, input().split()))
path = defaultdict(list)
for _ in range(m):
a, b = list(map(int, input().split()))
path[a].append(b)
idx = 1
ans = 1
right = n
while idx <= n:
candidate = path[idx]
if not candidate:
idx += 1
continue
if right <= idx:
ans += 1
right = n
cut = min(candidate)
right = min(right, cut)
idx += 1
print(ans) | import sys
input = sys.stdin.readline
INF = float('INF')
n, m = list(map(int, input().split()))
path = [INF]*(n+1)
for _ in range(m):
a, b = list(map(int, input().split()))
path[a] = min(path[a], b)
left = 1
ans = 1
right = n
while left <= n:
cut = path[left]
if cut == INF:
left += 1
continue
if right <= left:
ans += 1
right = n
right = min(right, cut)
left += 1
print(ans) | 28 | 26 | 498 | 452 | import sys
from collections import defaultdict
input = sys.stdin.readline
n, m = list(map(int, input().split()))
path = defaultdict(list)
for _ in range(m):
a, b = list(map(int, input().split()))
path[a].append(b)
idx = 1
ans = 1
right = n
while idx <= n:
candidate = path[idx]
if not candidate:
idx += 1
continue
if right <= idx:
ans += 1
right = n
cut = min(candidate)
right = min(right, cut)
idx += 1
print(ans)
| import sys
input = sys.stdin.readline
INF = float("INF")
n, m = list(map(int, input().split()))
path = [INF] * (n + 1)
for _ in range(m):
a, b = list(map(int, input().split()))
path[a] = min(path[a], b)
left = 1
ans = 1
right = n
while left <= n:
cut = path[left]
if cut == INF:
left += 1
continue
if right <= left:
ans += 1
right = n
right = min(right, cut)
left += 1
print(ans)
| false | 7.142857 | [
"-from collections import defaultdict",
"+INF = float(\"INF\")",
"-path = defaultdict(list)",
"+path = [INF] * (n + 1)",
"- path[a].append(b)",
"-idx = 1",
"+ path[a] = min(path[a], b)",
"+left = 1",
"-while idx <= n:",
"- candidate = path[idx]",
"- if not candidate:",
"- idx += 1",
"+while left <= n:",
"+ cut = path[left]",
"+ if cut == INF:",
"+ left += 1",
"- if right <= idx:",
"+ if right <= left:",
"- cut = min(candidate)",
"- idx += 1",
"+ left += 1"
]
| false | 0.079825 | 0.078132 | 1.021663 | [
"s525140232",
"s449760696"
]
|
u088552457 | p02888 | python | s005078456 | s855126461 | 732 | 341 | 42,204 | 74,176 | Accepted | Accepted | 53.42 | import sys
input = sys.stdin.readline
import collections
import bisect
def main():
n = int(eval(input()))
l = input_list()
l.sort()
ans = 0
for i in range(n-2):
for j in range(i+1, n-1):
ind = bisect.bisect_left(l, l[i]+l[j])
num = ind - 1 - j
ans += num
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
import bisect
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
n = int(eval(input()))
l = sorted(input_list())
ans = 0
for a in range(n):
for b in range(a+1, n):
ans += bisect.bisect_left(l, l[a]+l[b]) - (b+1)
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 28 | 27 | 526 | 514 | import sys
input = sys.stdin.readline
import collections
import bisect
def main():
n = int(eval(input()))
l = input_list()
l.sort()
ans = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
ind = bisect.bisect_left(l, l[i] + l[j])
num = ind - 1 - j
ans += num
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
import bisect
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
n = int(eval(input()))
l = sorted(input_list())
ans = 0
for a in range(n):
for b in range(a + 1, n):
ans += bisect.bisect_left(l, l[a] + l[b]) - (b + 1)
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| false | 3.571429 | [
"-import collections",
"-",
"+# 持っているビスケットを叩き、1枚増やす",
"+# ビスケット A枚を 1円に交換する",
"+# 1円をビスケット B枚に交換する",
"- l = input_list()",
"- l.sort()",
"+ l = sorted(input_list())",
"- for i in range(n - 2):",
"- for j in range(i + 1, n - 1):",
"- ind = bisect.bisect_left(l, l[i] + l[j])",
"- num = ind - 1 - j",
"- ans += num",
"+ for a in range(n):",
"+ for b in range(a + 1, n):",
"+ ans += bisect.bisect_left(l, l[a] + l[b]) - (b + 1)"
]
| false | 0.033175 | 0.034199 | 0.970051 | [
"s005078456",
"s855126461"
]
|
u863442865 | p02838 | python | s531123079 | s325303086 | 642 | 557 | 123,132 | 123,132 | Accepted | Accepted | 13.24 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
#from itertools import product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
#from operator import itemgetter
#inf = 10**17
mod = 10**9 + 7
n = int(eval(input()))
a = list(map(int, input().split()))
res = 0
for i in range(60):
cnt = 0
for j in a:
if (j>>i) & 1:
cnt += 1
res += ((cnt*(n-cnt))*2**i) % mod
print((res%mod))
| def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
#from itertools import product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
#from operator import itemgetter
#inf = 10**17
mod = 10**9 + 7
n = int(eval(input()))
a = list(map(int, input().split()))
res = 0
for i in range(60):
cnt = 0
for j in a:
if (j>>i) & 1:
cnt += 1
res += ((cnt*(n-cnt))*2**i) % mod
print((res%mod))
if __name__ == '__main__':
main() | 25 | 29 | 657 | 803 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
# from itertools import product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
# from operator import itemgetter
# inf = 10**17
mod = 10**9 + 7
n = int(eval(input()))
a = list(map(int, input().split()))
res = 0
for i in range(60):
cnt = 0
for j in a:
if (j >> i) & 1:
cnt += 1
res += ((cnt * (n - cnt)) * 2**i) % mod
print((res % mod))
| def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
# from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
# from itertools import product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
# from operator import itemgetter
# inf = 10**17
mod = 10**9 + 7
n = int(eval(input()))
a = list(map(int, input().split()))
res = 0
for i in range(60):
cnt = 0
for j in a:
if (j >> i) & 1:
cnt += 1
res += ((cnt * (n - cnt)) * 2**i) % mod
print((res % mod))
if __name__ == "__main__":
main()
| false | 13.793103 | [
"-import sys",
"+def main():",
"+ import sys",
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-from collections import Counter, deque",
"+ input = sys.stdin.readline",
"+ sys.setrecursionlimit(10**7)",
"+ from collections import Counter, deque",
"-# from collections import defaultdict",
"-from itertools import combinations, permutations, accumulate, groupby",
"+ # from collections import defaultdict",
"+ from itertools import combinations, permutations, accumulate, groupby",
"-# from itertools import product",
"-from bisect import bisect_left, bisect_right",
"-from heapq import heapify, heappop, heappush",
"-from math import floor, ceil",
"+ # from itertools import product",
"+ from bisect import bisect_left, bisect_right",
"+ from heapq import heapify, heappop, heappush",
"+ from math import floor, ceil",
"-# from operator import itemgetter",
"-# inf = 10**17",
"-mod = 10**9 + 7",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-res = 0",
"-for i in range(60):",
"- cnt = 0",
"- for j in a:",
"- if (j >> i) & 1:",
"- cnt += 1",
"- res += ((cnt * (n - cnt)) * 2**i) % mod",
"-print((res % mod))",
"+ # from operator import itemgetter",
"+ # inf = 10**17",
"+ mod = 10**9 + 7",
"+ n = int(eval(input()))",
"+ a = list(map(int, input().split()))",
"+ res = 0",
"+ for i in range(60):",
"+ cnt = 0",
"+ for j in a:",
"+ if (j >> i) & 1:",
"+ cnt += 1",
"+ res += ((cnt * (n - cnt)) * 2**i) % mod",
"+ print((res % mod))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.038343 | 0.038923 | 0.985112 | [
"s531123079",
"s325303086"
]
|
u394721319 | p03436 | python | s232147982 | s730151787 | 312 | 155 | 21,040 | 14,416 | Accepted | Accepted | 50.32 | from collections import deque
import numpy as np
H,W = [int(i) for i in input().split()]
l = [list(eval(input())) for _ in range(H)]
check = [[False]*W for _ in range(H)]
ans = [[0]*W for _ in range(H)]
q = deque()
q.append([0,0])
check[0][0] = True
while q:
i,j = q.popleft()
for next_i, next_j in [[i+1,j], [i-1,j], [i,j+1], [i,j-1]]:
if 0 <= next_i < H and 0 <= next_j < W:
if not check[next_i][next_j] and l[next_i][next_j] != '#':
q.append([next_i,next_j])
check[next_i][next_j] = True
ans[next_i][next_j] = ans[i][j]+1
cnt = 0
for i in range(H):
for j in range(W):
if l[i][j] == '.':
cnt += 1
if ans[H-1][W-1]:
print((cnt-ans[H-1][W-1]-1))
else:
print((-1))
| from collections import deque
import numpy as np
H,W = [int(zz) for zz in input().split()]
map = [['#']*(W+2) for _ in range(H+2)]
ans = 0
for i in range(1,H+1):
tmp = eval(input())
s = list('#'+tmp+'#')
map[i] = s
ans += tmp.count('#')
check = [[1]*(W+2) for _ in range(H+2)]
count = [[0]*(W+2) for _ in range(H+2)]
q = deque([(1,1)])
check[1][1] = 0
while q:
x,y = q.popleft()
for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
if check[x+i][y+j] and map[x+i][y+j] == '.':
check[x+i][y+j] = 0
q.append((x+i,y+j))
count[x+i][y+j] = count[x][y]+1
zz = count[H][W]
if zz == 0:
print((-1))
else:
count = set((np.array(count)).flatten())
for i in count:
if i > zz:
ans -= 1
print((H*W-len(count)-ans))
| 31 | 33 | 797 | 817 | from collections import deque
import numpy as np
H, W = [int(i) for i in input().split()]
l = [list(eval(input())) for _ in range(H)]
check = [[False] * W for _ in range(H)]
ans = [[0] * W for _ in range(H)]
q = deque()
q.append([0, 0])
check[0][0] = True
while q:
i, j = q.popleft()
for next_i, next_j in [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]:
if 0 <= next_i < H and 0 <= next_j < W:
if not check[next_i][next_j] and l[next_i][next_j] != "#":
q.append([next_i, next_j])
check[next_i][next_j] = True
ans[next_i][next_j] = ans[i][j] + 1
cnt = 0
for i in range(H):
for j in range(W):
if l[i][j] == ".":
cnt += 1
if ans[H - 1][W - 1]:
print((cnt - ans[H - 1][W - 1] - 1))
else:
print((-1))
| from collections import deque
import numpy as np
H, W = [int(zz) for zz in input().split()]
map = [["#"] * (W + 2) for _ in range(H + 2)]
ans = 0
for i in range(1, H + 1):
tmp = eval(input())
s = list("#" + tmp + "#")
map[i] = s
ans += tmp.count("#")
check = [[1] * (W + 2) for _ in range(H + 2)]
count = [[0] * (W + 2) for _ in range(H + 2)]
q = deque([(1, 1)])
check[1][1] = 0
while q:
x, y = q.popleft()
for i, j in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
if check[x + i][y + j] and map[x + i][y + j] == ".":
check[x + i][y + j] = 0
q.append((x + i, y + j))
count[x + i][y + j] = count[x][y] + 1
zz = count[H][W]
if zz == 0:
print((-1))
else:
count = set((np.array(count)).flatten())
for i in count:
if i > zz:
ans -= 1
print((H * W - len(count) - ans))
| false | 6.060606 | [
"-H, W = [int(i) for i in input().split()]",
"-l = [list(eval(input())) for _ in range(H)]",
"-check = [[False] * W for _ in range(H)]",
"-ans = [[0] * W for _ in range(H)]",
"-q = deque()",
"-q.append([0, 0])",
"-check[0][0] = True",
"+H, W = [int(zz) for zz in input().split()]",
"+map = [[\"#\"] * (W + 2) for _ in range(H + 2)]",
"+ans = 0",
"+for i in range(1, H + 1):",
"+ tmp = eval(input())",
"+ s = list(\"#\" + tmp + \"#\")",
"+ map[i] = s",
"+ ans += tmp.count(\"#\")",
"+check = [[1] * (W + 2) for _ in range(H + 2)]",
"+count = [[0] * (W + 2) for _ in range(H + 2)]",
"+q = deque([(1, 1)])",
"+check[1][1] = 0",
"- i, j = q.popleft()",
"- for next_i, next_j in [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]:",
"- if 0 <= next_i < H and 0 <= next_j < W:",
"- if not check[next_i][next_j] and l[next_i][next_j] != \"#\":",
"- q.append([next_i, next_j])",
"- check[next_i][next_j] = True",
"- ans[next_i][next_j] = ans[i][j] + 1",
"-cnt = 0",
"-for i in range(H):",
"- for j in range(W):",
"- if l[i][j] == \".\":",
"- cnt += 1",
"-if ans[H - 1][W - 1]:",
"- print((cnt - ans[H - 1][W - 1] - 1))",
"+ x, y = q.popleft()",
"+ for i, j in [(1, 0), (0, 1), (-1, 0), (0, -1)]:",
"+ if check[x + i][y + j] and map[x + i][y + j] == \".\":",
"+ check[x + i][y + j] = 0",
"+ q.append((x + i, y + j))",
"+ count[x + i][y + j] = count[x][y] + 1",
"+zz = count[H][W]",
"+if zz == 0:",
"+ print((-1))",
"- print((-1))",
"+ count = set((np.array(count)).flatten())",
"+ for i in count:",
"+ if i > zz:",
"+ ans -= 1",
"+ print((H * W - len(count) - ans))"
]
| false | 0.054341 | 0.184003 | 0.295327 | [
"s232147982",
"s730151787"
]
|
u223133214 | p03379 | python | s987504621 | s108660838 | 302 | 191 | 25,220 | 105,140 | Accepted | Accepted | 36.75 | N = int(eval(input()))
X = list(map(int, input().split()))
X0 = X[::]
X.sort()
num = int(N / 2 - 1) # index は num
ans0, ans1 = X[num], X[num + 1]
for i in range(N):
if X0[i] > ans0:
print(ans0)
else:
print(ans1)
| n = int(eval(input()))
X = list(map(int, input().split()))
Y = X[::]
Y.sort()
m = n // 2
median = (Y[m] + Y[m - 1]) / 2
for x in X:
if x < median:
print((Y[m]))
else:
print((Y[m-1]))
| 11 | 15 | 241 | 215 | N = int(eval(input()))
X = list(map(int, input().split()))
X0 = X[::]
X.sort()
num = int(N / 2 - 1) # index は num
ans0, ans1 = X[num], X[num + 1]
for i in range(N):
if X0[i] > ans0:
print(ans0)
else:
print(ans1)
| n = int(eval(input()))
X = list(map(int, input().split()))
Y = X[::]
Y.sort()
m = n // 2
median = (Y[m] + Y[m - 1]) / 2
for x in X:
if x < median:
print((Y[m]))
else:
print((Y[m - 1]))
| false | 26.666667 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-X0 = X[::]",
"-X.sort()",
"-num = int(N / 2 - 1) # index は num",
"-ans0, ans1 = X[num], X[num + 1]",
"-for i in range(N):",
"- if X0[i] > ans0:",
"- print(ans0)",
"+Y = X[::]",
"+Y.sort()",
"+m = n // 2",
"+median = (Y[m] + Y[m - 1]) / 2",
"+for x in X:",
"+ if x < median:",
"+ print((Y[m]))",
"- print(ans1)",
"+ print((Y[m - 1]))"
]
| false | 0.162479 | 0.122065 | 1.33109 | [
"s987504621",
"s108660838"
]
|
u769870836 | p03634 | python | s946632351 | s066529548 | 1,671 | 608 | 93,344 | 83,376 | Accepted | Accepted | 63.61 | n=int(eval(input()))
l=[[] for i in range(n)]
for i in range(n-1):
a,b,c=list(map(int,input().split()))
l[a-1].append([b-1,c])
l[b-1].append([a-1,c])
ans=[-1]*n
q,k=list(map(int,input().split()))
ans[k-1]=0
from collections import deque
d=deque([k-1])
while d:
now=d.pop()
for x in l[now]:
a,b=x
if ans[a]<0:
ans[a]=ans[now]+b
d.appendleft(a)
for i in range(q):
a,b=list(map(int,input().split()))
print((ans[a-1]+ans[b-1])) | import sys
from collections import deque
input = sys.stdin.readline
n=int(eval(input()))
l=[[] for i in range(n)]
for i in range(n-1):
a,b,c=list(map(int,input().split()))
l[a-1].append([b-1,c])
l[b-1].append([a-1,c])
ans=[-1]*n
q,k=list(map(int,input().split()))
ans[k-1]=0
d=deque([k-1])
while d:
now=d.pop()
for x in l[now]:
a,b=x
if ans[a]<0:
ans[a]=ans[now]+b
d.appendleft(a)
for i in range(q):
a,b=list(map(int,input().split()))
print((ans[a-1]+ans[b-1])) | 21 | 23 | 451 | 491 | n = int(eval(input()))
l = [[] for i in range(n)]
for i in range(n - 1):
a, b, c = list(map(int, input().split()))
l[a - 1].append([b - 1, c])
l[b - 1].append([a - 1, c])
ans = [-1] * n
q, k = list(map(int, input().split()))
ans[k - 1] = 0
from collections import deque
d = deque([k - 1])
while d:
now = d.pop()
for x in l[now]:
a, b = x
if ans[a] < 0:
ans[a] = ans[now] + b
d.appendleft(a)
for i in range(q):
a, b = list(map(int, input().split()))
print((ans[a - 1] + ans[b - 1]))
| import sys
from collections import deque
input = sys.stdin.readline
n = int(eval(input()))
l = [[] for i in range(n)]
for i in range(n - 1):
a, b, c = list(map(int, input().split()))
l[a - 1].append([b - 1, c])
l[b - 1].append([a - 1, c])
ans = [-1] * n
q, k = list(map(int, input().split()))
ans[k - 1] = 0
d = deque([k - 1])
while d:
now = d.pop()
for x in l[now]:
a, b = x
if ans[a] < 0:
ans[a] = ans[now] + b
d.appendleft(a)
for i in range(q):
a, b = list(map(int, input().split()))
print((ans[a - 1] + ans[b - 1]))
| false | 8.695652 | [
"+import sys",
"+from collections import deque",
"+",
"+input = sys.stdin.readline",
"-from collections import deque",
"-"
]
| false | 0.093507 | 0.146557 | 0.638024 | [
"s946632351",
"s066529548"
]
|
u319725914 | p00213 | python | s322027500 | s756629088 | 3,500 | 2,910 | 5,712 | 5,716 | Accepted | Accepted | 16.86 |
def putpiece(bitmap,unused,pieces,numans,pcsans,FINFLAG):
# print(bin(bitmap))
# print(unused,"***",pieces,"***",numans)
if FINFLAG:
return numans,pcsans
if not unused:
pcsans = pieces
return numans + 1, pcsans
if numans > 1:
return 2, pieces
b,k,y,x = unused[-1]
# print(set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1))]))
for h,w in set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1)) if not (k//i)*(k//(k//i)) - k]):
for pt,qt in product(list(range(max(0,y-h+1),min(Y-h+1,y+1))),list(range(max(0,x-w+1),min(X-w+1,x+1)))):
rt,st = pt+h-1, qt+w-1
piece = 0
piece2 = 0
for i in range(st-qt+1): piece |= 1 << i
for j in range(rt-pt+1): piece2 |= piece << j*X
piece = piece2
piece = piece << X-st-1
piece = piece << (Y-rt-1)*X
mark = 1
mark = mark << X-x-1
mark = mark << (Y-y-1)*X
if not (bitmap&piece)^mark: numans,pcsans = putpiece(bitmap|piece,unused[:-1],pieces+[[b,k,pt,qt,rt,st]],numans,pcsans,False)
if numans > 1: return 2, pcsans
if numans > 1: return 2, pcsans
else:
return numans,pcsans
from itertools import product
while(True):
numans = 0
pcsans = []
X,Y,n = list(map(int,input().split()))
if not X: break
bk = sorted([list(map(int,input().split())) for _ in range(n)])
ss = [list(map(int,input().split())) for _ in range(Y)]
yxs = sorted([ss[i][j],i,j] for i,j in product(list(range(Y)),list(range(X))) if ss[i][j])
bkyx = [ bk[i]+yxs[i][1:] for i in range(n)]
# from pprint import pprint
# pprint(bk)
# pprint(ss)
filled = "".join([ "".join(["1" if ss[i][j] else "0" for j in range(X)]) for i in range(Y)])
# pprint(filled)
# pprint([filled[i*X:i*X+X] for i in range(Y)])
# pprint(bkyx)
nans,pcs = putpiece(int(filled,2),bkyx,[],0,0,False)
# print(nans,pcs)
if nans > 1:
print("NA")
elif nans:
toprint = [[0]*X for _ in range(Y)]
for i,m,sy,sx,ey,ex in pcs:
for j in range(sy,ey+1): toprint[j][sx:ex+1] = [i]*(ex-sx+1)
for a in toprint: print((" ".join(str(b) for b in a)))
else:
print("NA")
# print("***********************************::")
# break
# numans = 0
# mapans = []
# bitmap,[[b1,k1,x1,y1]],[[p,q,r,s]]
# if not len([]):
# numans += 0
# mapans = p,q,r,s
# return None
# pt,qt,rt,st
# if not bitmap & bitpiece
# bitmap |= bitpeace
# putpiece(bitmap|bitpiece,[][:-1],[]+[pt,qt,rt,st])
| from itertools import product
# from line_profiler import LineProfiler
def putpiece(X,Y,bitmap,unused,pieces,numans,pcsans,FINFLAG):
if FINFLAG:
return numans,pcsans
if not unused:
pcsans = pieces
return numans + 1, pcsans
if numans > 1:
return 2, pieces
b,k,y,x = unused[-1]
for h,w in set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1)) if not (k//i)*(k//(k//i)) - k]):
for pt,qt in product(list(range(max(0,y-h+1),min(Y-h+1,y+1))),list(range(max(0,x-w+1),min(X-w+1,x+1)))):
rt,st = pt+h-1, qt+w-1
piece = 2**(st-qt+1)-1
piece2 = 0
for j in range(rt-pt+1): piece2 |= piece << j*X
piece = ( piece2 << X-st-1 ) << (Y-rt-1)*X
mark = ( 1 << X-x-1 ) << (Y-y-1)*X
if not (bitmap&piece)^mark: numans,pcsans = putpiece(X,Y,bitmap|piece,unused[:-1],pieces+[[b,k,pt,qt,rt,st]],numans,pcsans,False)
if numans > 1: return 2, pcsans
else:
return numans,pcsans
def main():
while(True):
X,Y,n = list(map(int,input().split()))
if not X: break
bk = sorted([list(map(int,input().split())) for _ in range(n)])
ss = [list(map(int,input().split())) for _ in range(Y)]
yxs = sorted([ss[i][j],i,j] for i,j in product(list(range(Y)),list(range(X))) if ss[i][j])
bkyx = [ bk[i]+yxs[i][1:] for i in range(n)]
filled = "".join([ "".join(["1" if ss[i][j] else "0" for j in range(X)]) for i in range(Y)])
nans,pcs = putpiece(X,Y,int(filled,2),bkyx,[],0,0,False)
if nans > 1:
print("NA")
elif nans:
toprint = [[0]*X for _ in range(Y)]
for i,_,sy,sx,ey,ex in pcs:
for j in range(sy,ey+1): toprint[j][sx:ex+1] = [i]*(ex-sx+1)
for a in toprint: print((" ".join(str(b) for b in a)))
else:
print("NA")
if __name__ == "__main__":
# prf = LineProfiler()
# prf.add_function(main)
# prf.add_function(putpiece)
# prf.runcall(main)
# prf.print_stats()
main()
| 84 | 53 | 2,672 | 2,106 | def putpiece(bitmap, unused, pieces, numans, pcsans, FINFLAG):
# print(bin(bitmap))
# print(unused,"***",pieces,"***",numans)
if FINFLAG:
return numans, pcsans
if not unused:
pcsans = pieces
return numans + 1, pcsans
if numans > 1:
return 2, pieces
b, k, y, x = unused[-1]
# print(set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1))]))
for h, w in set(
[
(k // i, k // (k // i))
for i in range(1, min(X + 1, k + 1))
if not (k // i) * (k // (k // i)) - k
]
):
for pt, qt in product(
list(range(max(0, y - h + 1), min(Y - h + 1, y + 1))),
list(range(max(0, x - w + 1), min(X - w + 1, x + 1))),
):
rt, st = pt + h - 1, qt + w - 1
piece = 0
piece2 = 0
for i in range(st - qt + 1):
piece |= 1 << i
for j in range(rt - pt + 1):
piece2 |= piece << j * X
piece = piece2
piece = piece << X - st - 1
piece = piece << (Y - rt - 1) * X
mark = 1
mark = mark << X - x - 1
mark = mark << (Y - y - 1) * X
if not (bitmap & piece) ^ mark:
numans, pcsans = putpiece(
bitmap | piece,
unused[:-1],
pieces + [[b, k, pt, qt, rt, st]],
numans,
pcsans,
False,
)
if numans > 1:
return 2, pcsans
if numans > 1:
return 2, pcsans
else:
return numans, pcsans
from itertools import product
while True:
numans = 0
pcsans = []
X, Y, n = list(map(int, input().split()))
if not X:
break
bk = sorted([list(map(int, input().split())) for _ in range(n)])
ss = [list(map(int, input().split())) for _ in range(Y)]
yxs = sorted(
[ss[i][j], i, j] for i, j in product(list(range(Y)), list(range(X))) if ss[i][j]
)
bkyx = [bk[i] + yxs[i][1:] for i in range(n)]
# from pprint import pprint
# pprint(bk)
# pprint(ss)
filled = "".join(
["".join(["1" if ss[i][j] else "0" for j in range(X)]) for i in range(Y)]
)
# pprint(filled)
# pprint([filled[i*X:i*X+X] for i in range(Y)])
# pprint(bkyx)
nans, pcs = putpiece(int(filled, 2), bkyx, [], 0, 0, False)
# print(nans,pcs)
if nans > 1:
print("NA")
elif nans:
toprint = [[0] * X for _ in range(Y)]
for i, m, sy, sx, ey, ex in pcs:
for j in range(sy, ey + 1):
toprint[j][sx : ex + 1] = [i] * (ex - sx + 1)
for a in toprint:
print((" ".join(str(b) for b in a)))
else:
print("NA")
# print("***********************************::")
# break
# numans = 0
# mapans = []
# bitmap,[[b1,k1,x1,y1]],[[p,q,r,s]]
# if not len([]):
# numans += 0
# mapans = p,q,r,s
# return None
# pt,qt,rt,st
# if not bitmap & bitpiece
# bitmap |= bitpeace
# putpiece(bitmap|bitpiece,[][:-1],[]+[pt,qt,rt,st])
| from itertools import product
# from line_profiler import LineProfiler
def putpiece(X, Y, bitmap, unused, pieces, numans, pcsans, FINFLAG):
if FINFLAG:
return numans, pcsans
if not unused:
pcsans = pieces
return numans + 1, pcsans
if numans > 1:
return 2, pieces
b, k, y, x = unused[-1]
for h, w in set(
[
(k // i, k // (k // i))
for i in range(1, min(X + 1, k + 1))
if not (k // i) * (k // (k // i)) - k
]
):
for pt, qt in product(
list(range(max(0, y - h + 1), min(Y - h + 1, y + 1))),
list(range(max(0, x - w + 1), min(X - w + 1, x + 1))),
):
rt, st = pt + h - 1, qt + w - 1
piece = 2 ** (st - qt + 1) - 1
piece2 = 0
for j in range(rt - pt + 1):
piece2 |= piece << j * X
piece = (piece2 << X - st - 1) << (Y - rt - 1) * X
mark = (1 << X - x - 1) << (Y - y - 1) * X
if not (bitmap & piece) ^ mark:
numans, pcsans = putpiece(
X,
Y,
bitmap | piece,
unused[:-1],
pieces + [[b, k, pt, qt, rt, st]],
numans,
pcsans,
False,
)
if numans > 1:
return 2, pcsans
else:
return numans, pcsans
def main():
while True:
X, Y, n = list(map(int, input().split()))
if not X:
break
bk = sorted([list(map(int, input().split())) for _ in range(n)])
ss = [list(map(int, input().split())) for _ in range(Y)]
yxs = sorted(
[ss[i][j], i, j]
for i, j in product(list(range(Y)), list(range(X)))
if ss[i][j]
)
bkyx = [bk[i] + yxs[i][1:] for i in range(n)]
filled = "".join(
["".join(["1" if ss[i][j] else "0" for j in range(X)]) for i in range(Y)]
)
nans, pcs = putpiece(X, Y, int(filled, 2), bkyx, [], 0, 0, False)
if nans > 1:
print("NA")
elif nans:
toprint = [[0] * X for _ in range(Y)]
for i, _, sy, sx, ey, ex in pcs:
for j in range(sy, ey + 1):
toprint[j][sx : ex + 1] = [i] * (ex - sx + 1)
for a in toprint:
print((" ".join(str(b) for b in a)))
else:
print("NA")
if __name__ == "__main__":
# prf = LineProfiler()
# prf.add_function(main)
# prf.add_function(putpiece)
# prf.runcall(main)
# prf.print_stats()
main()
| false | 36.904762 | [
"-def putpiece(bitmap, unused, pieces, numans, pcsans, FINFLAG):",
"- # print(bin(bitmap))",
"- # print(unused,\"***\",pieces,\"***\",numans)",
"+from itertools import product",
"+",
"+# from line_profiler import LineProfiler",
"+def putpiece(X, Y, bitmap, unused, pieces, numans, pcsans, FINFLAG):",
"- # print(set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1))]))",
"- piece = 0",
"+ piece = 2 ** (st - qt + 1) - 1",
"- for i in range(st - qt + 1):",
"- piece |= 1 << i",
"- piece = piece2",
"- piece = piece << X - st - 1",
"- piece = piece << (Y - rt - 1) * X",
"- mark = 1",
"- mark = mark << X - x - 1",
"- mark = mark << (Y - y - 1) * X",
"+ piece = (piece2 << X - st - 1) << (Y - rt - 1) * X",
"+ mark = (1 << X - x - 1) << (Y - y - 1) * X",
"+ X,",
"+ Y,",
"- if numans > 1:",
"- return 2, pcsans",
"-from itertools import product",
"+def main():",
"+ while True:",
"+ X, Y, n = list(map(int, input().split()))",
"+ if not X:",
"+ break",
"+ bk = sorted([list(map(int, input().split())) for _ in range(n)])",
"+ ss = [list(map(int, input().split())) for _ in range(Y)]",
"+ yxs = sorted(",
"+ [ss[i][j], i, j]",
"+ for i, j in product(list(range(Y)), list(range(X)))",
"+ if ss[i][j]",
"+ )",
"+ bkyx = [bk[i] + yxs[i][1:] for i in range(n)]",
"+ filled = \"\".join(",
"+ [\"\".join([\"1\" if ss[i][j] else \"0\" for j in range(X)]) for i in range(Y)]",
"+ )",
"+ nans, pcs = putpiece(X, Y, int(filled, 2), bkyx, [], 0, 0, False)",
"+ if nans > 1:",
"+ print(\"NA\")",
"+ elif nans:",
"+ toprint = [[0] * X for _ in range(Y)]",
"+ for i, _, sy, sx, ey, ex in pcs:",
"+ for j in range(sy, ey + 1):",
"+ toprint[j][sx : ex + 1] = [i] * (ex - sx + 1)",
"+ for a in toprint:",
"+ print((\" \".join(str(b) for b in a)))",
"+ else:",
"+ print(\"NA\")",
"-while True:",
"- numans = 0",
"- pcsans = []",
"- X, Y, n = list(map(int, input().split()))",
"- if not X:",
"- break",
"- bk = sorted([list(map(int, input().split())) for _ in range(n)])",
"- ss = [list(map(int, input().split())) for _ in range(Y)]",
"- yxs = sorted(",
"- [ss[i][j], i, j] for i, j in product(list(range(Y)), list(range(X))) if ss[i][j]",
"- )",
"- bkyx = [bk[i] + yxs[i][1:] for i in range(n)]",
"- # from pprint import pprint",
"- # pprint(bk)",
"- # pprint(ss)",
"- filled = \"\".join(",
"- [\"\".join([\"1\" if ss[i][j] else \"0\" for j in range(X)]) for i in range(Y)]",
"- )",
"- # pprint(filled)",
"- # pprint([filled[i*X:i*X+X] for i in range(Y)])",
"- # pprint(bkyx)",
"- nans, pcs = putpiece(int(filled, 2), bkyx, [], 0, 0, False)",
"- # print(nans,pcs)",
"- if nans > 1:",
"- print(\"NA\")",
"- elif nans:",
"- toprint = [[0] * X for _ in range(Y)]",
"- for i, m, sy, sx, ey, ex in pcs:",
"- for j in range(sy, ey + 1):",
"- toprint[j][sx : ex + 1] = [i] * (ex - sx + 1)",
"- for a in toprint:",
"- print((\" \".join(str(b) for b in a)))",
"- else:",
"- print(\"NA\")",
"- # print(\"***********************************::\")",
"- # break",
"-# numans = 0",
"-# mapans = []",
"-# bitmap,[[b1,k1,x1,y1]],[[p,q,r,s]]",
"-# if not len([]):",
"-# numans += 0",
"-# mapans = p,q,r,s",
"-# return None",
"-# pt,qt,rt,st",
"-# if not bitmap & bitpiece",
"-# bitmap |= bitpeace",
"-# putpiece(bitmap|bitpiece,[][:-1],[]+[pt,qt,rt,st])",
"+",
"+if __name__ == \"__main__\":",
"+ # prf = LineProfiler()",
"+ # prf.add_function(main)",
"+ # prf.add_function(putpiece)",
"+ # prf.runcall(main)",
"+ # prf.print_stats()",
"+ main()"
]
| false | 0.037516 | 0.067372 | 0.556852 | [
"s322027500",
"s756629088"
]
|
u631277801 | p03426 | python | s193308752 | s077994318 | 477 | 395 | 43,224 | 22,808 | Accepted | Accepted | 17.19 | import sys
sdin = sys.stdin.readline
H,W,D = list(map(int, sdin().split()))
A = []
for h in range(H):
A.append(list(map(int, sdin().split())))
Q = int(sdin())
RL = []
for q in range(Q):
RL.append(tuple(map(int, sdin().split())))
codn = {}
for h in range(H):
for w in range(W):
codn[A[h][w]] = (h+1, w+1)
# mod D上での累積和
cums = []
for d in range(D):
cum = []
res = D
if d!=0:
res = d
cum = [0]
while res+D <= H*W:
prev = codn[res]
nex = codn[res+D]
cost = abs(nex[0]-prev[0]) + abs(nex[1]-prev[1])
cum.append(cum[-1]+cost)
res += D
cums.append(cum)
# 各クエリの処理
ans = 0
for query in range(Q):
q = RL[query]
mod = q[0] % D
start = (q[0]-mod) // D
last = (q[1]-mod) // D
if mod == 0:
start -= 1
last -= 1
ans = cums[mod][last] - cums[mod][start]
print(ans) | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
# パスを計算
h,w,d = li()
grid = []
dic = {}
for i in range(h):
row = list(li())
for j in range(w):
dic.update({row[j]: (i,j)})
dist = [0]*(h*w+1)
for i in range(d+1,h*w+1):
dist[i] = dist[i-d] + abs(dic[i][0] - dic[i-d][0]) + abs(dic[i][1] - dic[i-d][1])
q = ni()
for _ in range(q):
l,r = li()
print((dist[r] - dist[l])) | 51 | 32 | 977 | 811 | import sys
sdin = sys.stdin.readline
H, W, D = list(map(int, sdin().split()))
A = []
for h in range(H):
A.append(list(map(int, sdin().split())))
Q = int(sdin())
RL = []
for q in range(Q):
RL.append(tuple(map(int, sdin().split())))
codn = {}
for h in range(H):
for w in range(W):
codn[A[h][w]] = (h + 1, w + 1)
# mod D上での累積和
cums = []
for d in range(D):
cum = []
res = D
if d != 0:
res = d
cum = [0]
while res + D <= H * W:
prev = codn[res]
nex = codn[res + D]
cost = abs(nex[0] - prev[0]) + abs(nex[1] - prev[1])
cum.append(cum[-1] + cost)
res += D
cums.append(cum)
# 各クエリの処理
ans = 0
for query in range(Q):
q = RL[query]
mod = q[0] % D
start = (q[0] - mod) // D
last = (q[1] - mod) // D
if mod == 0:
start -= 1
last -= 1
ans = cums[mod][last] - cums[mod][start]
print(ans)
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return list(map(int, stdin.readline().split()))
def li_():
return [int(x) - 1 for x in stdin.readline().split()]
def lf():
return list(map(float, stdin.readline().split()))
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
# パスを計算
h, w, d = li()
grid = []
dic = {}
for i in range(h):
row = list(li())
for j in range(w):
dic.update({row[j]: (i, j)})
dist = [0] * (h * w + 1)
for i in range(d + 1, h * w + 1):
dist[i] = (
dist[i - d] + abs(dic[i][0] - dic[i - d][0]) + abs(dic[i][1] - dic[i - d][1])
)
q = ni()
for _ in range(q):
l, r = li()
print((dist[r] - dist[l]))
| false | 37.254902 | [
"-sdin = sys.stdin.readline",
"-H, W, D = list(map(int, sdin().split()))",
"-A = []",
"-for h in range(H):",
"- A.append(list(map(int, sdin().split())))",
"-Q = int(sdin())",
"-RL = []",
"-for q in range(Q):",
"- RL.append(tuple(map(int, sdin().split())))",
"-codn = {}",
"-for h in range(H):",
"- for w in range(W):",
"- codn[A[h][w]] = (h + 1, w + 1)",
"-# mod D上での累積和",
"-cums = []",
"-for d in range(D):",
"- cum = []",
"- res = D",
"- if d != 0:",
"- res = d",
"- cum = [0]",
"- while res + D <= H * W:",
"- prev = codn[res]",
"- nex = codn[res + D]",
"- cost = abs(nex[0] - prev[0]) + abs(nex[1] - prev[1])",
"- cum.append(cum[-1] + cost)",
"- res += D",
"- cums.append(cum)",
"-# 各クエリの処理",
"-ans = 0",
"-for query in range(Q):",
"- q = RL[query]",
"- mod = q[0] % D",
"- start = (q[0] - mod) // D",
"- last = (q[1] - mod) // D",
"- if mod == 0:",
"- start -= 1",
"- last -= 1",
"- ans = cums[mod][last] - cums[mod][start]",
"- print(ans)",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**5)",
"+",
"+",
"+def li():",
"+ return list(map(int, stdin.readline().split()))",
"+",
"+",
"+def li_():",
"+ return [int(x) - 1 for x in stdin.readline().split()]",
"+",
"+",
"+def lf():",
"+ return list(map(float, stdin.readline().split()))",
"+",
"+",
"+def ls():",
"+ return stdin.readline().split()",
"+",
"+",
"+def ns():",
"+ return stdin.readline().rstrip()",
"+",
"+",
"+def lc():",
"+ return list(ns())",
"+",
"+",
"+def ni():",
"+ return int(stdin.readline())",
"+",
"+",
"+def nf():",
"+ return float(stdin.readline())",
"+",
"+",
"+# パスを計算",
"+h, w, d = li()",
"+grid = []",
"+dic = {}",
"+for i in range(h):",
"+ row = list(li())",
"+ for j in range(w):",
"+ dic.update({row[j]: (i, j)})",
"+dist = [0] * (h * w + 1)",
"+for i in range(d + 1, h * w + 1):",
"+ dist[i] = (",
"+ dist[i - d] + abs(dic[i][0] - dic[i - d][0]) + abs(dic[i][1] - dic[i - d][1])",
"+ )",
"+q = ni()",
"+for _ in range(q):",
"+ l, r = li()",
"+ print((dist[r] - dist[l]))"
]
| false | 0.044366 | 0.045045 | 0.984919 | [
"s193308752",
"s077994318"
]
|
u405256066 | p02743 | python | s281990050 | s205444194 | 34 | 17 | 5,076 | 2,940 | Accepted | Accepted | 50 | from sys import stdin
from decimal import Decimal,getcontext
getcontext().prec = 50
a,b,c = [Decimal(x) for x in stdin.readline().rstrip().split()]
if a.sqrt() + b.sqrt() < c.sqrt():
print("Yes")
else:
print("No") | from sys import stdin
a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
if 4*a*b < (c-a-b)**2 and (c-a-b) > 0:
print("Yes")
else:
print("No") | 8 | 6 | 228 | 164 | from sys import stdin
from decimal import Decimal, getcontext
getcontext().prec = 50
a, b, c = [Decimal(x) for x in stdin.readline().rstrip().split()]
if a.sqrt() + b.sqrt() < c.sqrt():
print("Yes")
else:
print("No")
| from sys import stdin
a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
if 4 * a * b < (c - a - b) ** 2 and (c - a - b) > 0:
print("Yes")
else:
print("No")
| false | 25 | [
"-from decimal import Decimal, getcontext",
"-getcontext().prec = 50",
"-a, b, c = [Decimal(x) for x in stdin.readline().rstrip().split()]",
"-if a.sqrt() + b.sqrt() < c.sqrt():",
"+a, b, c = [int(x) for x in stdin.readline().rstrip().split()]",
"+if 4 * a * b < (c - a - b) ** 2 and (c - a - b) > 0:"
]
| false | 0.103441 | 0.088711 | 1.166044 | [
"s281990050",
"s205444194"
]
|
u716660050 | p03338 | python | s406397411 | s069677562 | 29 | 26 | 9,152 | 9,120 | Accepted | Accepted | 10.34 | N,S=int(eval(input())),eval(input())
ans=0
for i in range(1,N):
a,b,c=S[:i],S[i:],0
for j in range(97,123):
if chr(j)in a and chr(j)in b:c+=1
ans=max(ans,c)
print(ans) | N,S,z=int(eval(input())),eval(input()),0
for i in range(1,N):a,b=S[:i],S[i:];z=max(z,len([0 for j in range(97,123)if chr(j)in a and chr(j)in b]))
print(z) | 8 | 3 | 182 | 144 | N, S = int(eval(input())), eval(input())
ans = 0
for i in range(1, N):
a, b, c = S[:i], S[i:], 0
for j in range(97, 123):
if chr(j) in a and chr(j) in b:
c += 1
ans = max(ans, c)
print(ans)
| N, S, z = int(eval(input())), eval(input()), 0
for i in range(1, N):
a, b = S[:i], S[i:]
z = max(z, len([0 for j in range(97, 123) if chr(j) in a and chr(j) in b]))
print(z)
| false | 62.5 | [
"-N, S = int(eval(input())), eval(input())",
"-ans = 0",
"+N, S, z = int(eval(input())), eval(input()), 0",
"- a, b, c = S[:i], S[i:], 0",
"- for j in range(97, 123):",
"- if chr(j) in a and chr(j) in b:",
"- c += 1",
"- ans = max(ans, c)",
"-print(ans)",
"+ a, b = S[:i], S[i:]",
"+ z = max(z, len([0 for j in range(97, 123) if chr(j) in a and chr(j) in b]))",
"+print(z)"
]
| false | 0.037907 | 0.04256 | 0.890666 | [
"s406397411",
"s069677562"
]
|
u973840923 | p03107 | python | s042318773 | s291391293 | 52 | 48 | 3,956 | 3,956 | Accepted | Accepted | 7.69 | list = []
cnt = 0
for i in eval(input()):
if list:
if list[-1] != i:
list.pop(-1)
cnt += 2
else:
list.append(i)
else:
list.append(i)
print(cnt) | list = []
cnt = 0
for i in eval(input()):
if not list:
list.append(i)
elif list[-1] != i:
list.pop(-1)
cnt += 2
else:
list.append(i)
print(cnt)
| 14 | 12 | 220 | 194 | list = []
cnt = 0
for i in eval(input()):
if list:
if list[-1] != i:
list.pop(-1)
cnt += 2
else:
list.append(i)
else:
list.append(i)
print(cnt)
| list = []
cnt = 0
for i in eval(input()):
if not list:
list.append(i)
elif list[-1] != i:
list.pop(-1)
cnt += 2
else:
list.append(i)
print(cnt)
| false | 14.285714 | [
"- if list:",
"- if list[-1] != i:",
"- list.pop(-1)",
"- cnt += 2",
"- else:",
"- list.append(i)",
"+ if not list:",
"+ list.append(i)",
"+ elif list[-1] != i:",
"+ list.pop(-1)",
"+ cnt += 2"
]
| false | 0.090741 | 0.083009 | 1.093148 | [
"s042318773",
"s291391293"
]
|
u279605379 | p02235 | python | s773487339 | s633844118 | 4,510 | 3,650 | 5,628 | 5,632 | Accepted | Accepted | 19.07 | def calc(x,y):
n = len(x)
m = len(y)
dp1 = [0]*(m+1)
for i in range(n):
dp2 = dp1[:]
for j in range(m):
if x[i] == y[j]:
dp1[j+1] = dp2[j]+1
elif dp1[j+1] < dp1[j]:
dp1[j+1] = dp1[j]
return dp1[-1]
q = int(eval(input()))
for i in range(q):
x = eval(input())
y = eval(input())
print((calc(x,y)))
| def calc(x,y):
n = len(x)
m = len(y)
dp1 = [0]*(m+1)
for i in range(n):
s = x[i]
dp2 = dp1[:]
for j in range(m):
if s == y[j]:
dp1[j+1] = dp2[j]+1
elif dp1[j+1] < dp1[j]:
dp1[j+1] = dp1[j]
return dp1[-1]
q = int(eval(input()))
for i in range(q):
x = eval(input())
y = eval(input())
print((calc(x,y)))
| 18 | 19 | 397 | 412 | def calc(x, y):
n = len(x)
m = len(y)
dp1 = [0] * (m + 1)
for i in range(n):
dp2 = dp1[:]
for j in range(m):
if x[i] == y[j]:
dp1[j + 1] = dp2[j] + 1
elif dp1[j + 1] < dp1[j]:
dp1[j + 1] = dp1[j]
return dp1[-1]
q = int(eval(input()))
for i in range(q):
x = eval(input())
y = eval(input())
print((calc(x, y)))
| def calc(x, y):
n = len(x)
m = len(y)
dp1 = [0] * (m + 1)
for i in range(n):
s = x[i]
dp2 = dp1[:]
for j in range(m):
if s == y[j]:
dp1[j + 1] = dp2[j] + 1
elif dp1[j + 1] < dp1[j]:
dp1[j + 1] = dp1[j]
return dp1[-1]
q = int(eval(input()))
for i in range(q):
x = eval(input())
y = eval(input())
print((calc(x, y)))
| false | 5.263158 | [
"+ s = x[i]",
"- if x[i] == y[j]:",
"+ if s == y[j]:"
]
| false | 0.045127 | 0.038935 | 1.159038 | [
"s773487339",
"s633844118"
]
|
u413021823 | p03086 | python | s438343453 | s791638997 | 166 | 67 | 38,256 | 64,988 | Accepted | Accepted | 59.64 | import sys
from itertools import combinations
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
ans = 0
temp = 0
for a in s:
if a in 'ACGT':
temp += 1
else:
temp = 0
ans = max(ans, temp)
print(ans)
| import sys
from collections import deque
from itertools import *
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
ans = 0
temp = 0
for s_s in s:
if s_s in 'ACGT':
temp += 1
else:
temp = 0
ans = max(ans, temp)
print(ans)
| 28 | 28 | 463 | 474 | import sys
from itertools import combinations
import math
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split())
s = S()
ans = 0
temp = 0
for a in s:
if a in "ACGT":
temp += 1
else:
temp = 0
ans = max(ans, temp)
print(ans)
| import sys
from collections import deque
from itertools import *
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split())
s = S()
ans = 0
temp = 0
for s_s in s:
if s_s in "ACGT":
temp += 1
else:
temp = 0
ans = max(ans, temp)
print(ans)
| false | 0 | [
"-from itertools import combinations",
"-import math",
"+from collections import deque",
"+from itertools import *",
"-for a in s:",
"- if a in \"ACGT\":",
"+for s_s in s:",
"+ if s_s in \"ACGT\":"
]
| false | 0.03811 | 0.037417 | 1.01852 | [
"s438343453",
"s791638997"
]
|
u325227960 | p02774 | python | s660191697 | s444733254 | 677 | 466 | 92,116 | 106,092 | Accepted | Accepted | 31.17 | import sys
input = sys.stdin.readline
n, k = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
A00 = A[:]
A0 = []
A1 = []
F = [0,0,0]
for i in range(n):
if A[i] > 0:
F[0] += 1
A0.append(A[i])
elif A[i] == 0:
F[1] += 1
else:
F[2] += 1
A1.append(A[i])
G = [F[2]*(F[2]-1)//2 + F[0]*(F[0]-1)//2,
(F[0]+F[2]) * F[1] + F[1]*(F[1]-1)//2,
F[2] * F[0]]
# print("G",G)
g = 2
if G[2] < k and G[2]+G[1] >= k:
k -= G[2]
g = 1
if G[2]+G[1] < k:
k -= G[2]+G[1]
g = 0
if g==2:
k = n*(n-1)//2 + 1 - k # 上からk番目
k -= G[0]+G[1] # 負になるペアの中で上からk番目
k -= 1 # これで「それより絶対値が下の数がk個」になる
# print("k",k)
# print("g",g)
if g==1:
print((0))
elif g==0:
A = A0[:]
B = [-i for i in A1]
B.sort()
le = -1
ri = 10**18+2
m = (le+ri) // 2
while ri-le > 1:
ans = 0
if len(A) > 0:
j0 = len(A)-1
for i in range(len(A)):
while j0 > i and A[i]*A[j0] >= m:
j0 -= 1
ans += j0-i
j0 = max(i+1,j0)
if len(B) > 0:
j1 = len(B)-1
for i in range(len(B)):
while j1 > i and B[i]*B[j1] >= m:
j1 -= 1
ans += j1-i
j1 = max(i+1,j1)
# print(le,ri,m,ans) # ansはm未満の数の個数
if ans > k:
ri = m
else:
le = m
m = (le+ri)//2
print(le)
else:
# print("k",k)
A = A0[:]
B = [-i for i in A1]
B.sort()
# print(A,B)
le = -1
ri = 10**18+2
m = (le+ri) // 2
while ri-le > 1:
ans = 0
if len(A) > 0:
j0 = len(B)-1
for i in range(len(A)):
# print("seki",A[i]*B[j0])
while j0 >= 0 and A[i]*B[j0] >= m:
j0 -= 1
ans += j0+1
# print("plus",j0)
# print(le,ri,m,ans) # ansはm未満の数の個数
if ans > k:
ri = m
else:
le = m
m = (le+ri)//2
print((-le))
# CC = []
# A = A00[:]
# for i in range(n):
# for j in range(i+1,n):
# CC.append(A[i]*A[j])
# CC.sort()
# print("lenCC", len(CC))
# print(CC)
# print(CC[400:420]) | import sys
input = sys.stdin.readline
n, k = list(map(int,input().split()))
A = list(map(int,input().split()))
minus = 0
for i in range(n):
if A[i] < 0:
minus += 1
zplus = n - minus
B = []
C = []
for i in range(n):
if A[i] < 0:
C.append(A[i])
else:
B.append(A[i])
B.sort(reverse=True)
C.sort()
if k <= minus * zplus:
ok = 1
ng = -10**20
m = (ok+ng) // 2
while abs(ng-ok) > 1:
co = 0
j = len(C)-1
for i in range(len(B)):
while j >= 0 and B[i]*C[j] > m:
j -= 1
co += j+1
# print(m, co)
if co >= k:
ok = m
# print("ok")
else:
ng = m
# print("ng")
m = (ok+ng) // 2
print(ok)
else:
k -= minus * zplus
ok = 10**20
ng = -1
m = (ok+ng) // 2
while abs(ng-ok) > 1:
co = 0
j = len(C)-1
for i in range(len(C)):
while j > i and C[i]*C[j] <= m:
j -= 1
co += len(C)-1-j
j = max(j, i+1)
j = len(B)-1
for i in range(len(B)):
while j > i and B[i]*B[j] <= m:
j -= 1
co += len(B)-1-j
j = max(j, i+1)
if co >= k:
ok = m
# print("ok")
else:
ng = m
# print("ng")
m = (ok+ng) // 2
print(ok) | 112 | 70 | 2,387 | 1,474 | import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
A00 = A[:]
A0 = []
A1 = []
F = [0, 0, 0]
for i in range(n):
if A[i] > 0:
F[0] += 1
A0.append(A[i])
elif A[i] == 0:
F[1] += 1
else:
F[2] += 1
A1.append(A[i])
G = [
F[2] * (F[2] - 1) // 2 + F[0] * (F[0] - 1) // 2,
(F[0] + F[2]) * F[1] + F[1] * (F[1] - 1) // 2,
F[2] * F[0],
]
# print("G",G)
g = 2
if G[2] < k and G[2] + G[1] >= k:
k -= G[2]
g = 1
if G[2] + G[1] < k:
k -= G[2] + G[1]
g = 0
if g == 2:
k = n * (n - 1) // 2 + 1 - k # 上からk番目
k -= G[0] + G[1] # 負になるペアの中で上からk番目
k -= 1 # これで「それより絶対値が下の数がk個」になる
# print("k",k)
# print("g",g)
if g == 1:
print((0))
elif g == 0:
A = A0[:]
B = [-i for i in A1]
B.sort()
le = -1
ri = 10**18 + 2
m = (le + ri) // 2
while ri - le > 1:
ans = 0
if len(A) > 0:
j0 = len(A) - 1
for i in range(len(A)):
while j0 > i and A[i] * A[j0] >= m:
j0 -= 1
ans += j0 - i
j0 = max(i + 1, j0)
if len(B) > 0:
j1 = len(B) - 1
for i in range(len(B)):
while j1 > i and B[i] * B[j1] >= m:
j1 -= 1
ans += j1 - i
j1 = max(i + 1, j1)
# print(le,ri,m,ans) # ansはm未満の数の個数
if ans > k:
ri = m
else:
le = m
m = (le + ri) // 2
print(le)
else:
# print("k",k)
A = A0[:]
B = [-i for i in A1]
B.sort()
# print(A,B)
le = -1
ri = 10**18 + 2
m = (le + ri) // 2
while ri - le > 1:
ans = 0
if len(A) > 0:
j0 = len(B) - 1
for i in range(len(A)):
# print("seki",A[i]*B[j0])
while j0 >= 0 and A[i] * B[j0] >= m:
j0 -= 1
ans += j0 + 1
# print("plus",j0)
# print(le,ri,m,ans) # ansはm未満の数の個数
if ans > k:
ri = m
else:
le = m
m = (le + ri) // 2
print((-le))
# CC = []
# A = A00[:]
# for i in range(n):
# for j in range(i+1,n):
# CC.append(A[i]*A[j])
# CC.sort()
# print("lenCC", len(CC))
# print(CC)
# print(CC[400:420])
| import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
minus = 0
for i in range(n):
if A[i] < 0:
minus += 1
zplus = n - minus
B = []
C = []
for i in range(n):
if A[i] < 0:
C.append(A[i])
else:
B.append(A[i])
B.sort(reverse=True)
C.sort()
if k <= minus * zplus:
ok = 1
ng = -(10**20)
m = (ok + ng) // 2
while abs(ng - ok) > 1:
co = 0
j = len(C) - 1
for i in range(len(B)):
while j >= 0 and B[i] * C[j] > m:
j -= 1
co += j + 1
# print(m, co)
if co >= k:
ok = m
# print("ok")
else:
ng = m
# print("ng")
m = (ok + ng) // 2
print(ok)
else:
k -= minus * zplus
ok = 10**20
ng = -1
m = (ok + ng) // 2
while abs(ng - ok) > 1:
co = 0
j = len(C) - 1
for i in range(len(C)):
while j > i and C[i] * C[j] <= m:
j -= 1
co += len(C) - 1 - j
j = max(j, i + 1)
j = len(B) - 1
for i in range(len(B)):
while j > i and B[i] * B[j] <= m:
j -= 1
co += len(B) - 1 - j
j = max(j, i + 1)
if co >= k:
ok = m
# print("ok")
else:
ng = m
# print("ng")
m = (ok + ng) // 2
print(ok)
| false | 37.5 | [
"-A.sort()",
"-A00 = A[:]",
"-A0 = []",
"-A1 = []",
"-F = [0, 0, 0]",
"+minus = 0",
"- if A[i] > 0:",
"- F[0] += 1",
"- A0.append(A[i])",
"- elif A[i] == 0:",
"- F[1] += 1",
"+ if A[i] < 0:",
"+ minus += 1",
"+zplus = n - minus",
"+B = []",
"+C = []",
"+for i in range(n):",
"+ if A[i] < 0:",
"+ C.append(A[i])",
"- F[2] += 1",
"- A1.append(A[i])",
"-G = [",
"- F[2] * (F[2] - 1) // 2 + F[0] * (F[0] - 1) // 2,",
"- (F[0] + F[2]) * F[1] + F[1] * (F[1] - 1) // 2,",
"- F[2] * F[0],",
"-]",
"-# print(\"G\",G)",
"-g = 2",
"-if G[2] < k and G[2] + G[1] >= k:",
"- k -= G[2]",
"- g = 1",
"-if G[2] + G[1] < k:",
"- k -= G[2] + G[1]",
"- g = 0",
"-if g == 2:",
"- k = n * (n - 1) // 2 + 1 - k # 上からk番目",
"- k -= G[0] + G[1] # 負になるペアの中で上からk番目",
"-k -= 1 # これで「それより絶対値が下の数がk個」になる",
"-# print(\"k\",k)",
"-# print(\"g\",g)",
"-if g == 1:",
"- print((0))",
"-elif g == 0:",
"- A = A0[:]",
"- B = [-i for i in A1]",
"- B.sort()",
"- le = -1",
"- ri = 10**18 + 2",
"- m = (le + ri) // 2",
"- while ri - le > 1:",
"- ans = 0",
"- if len(A) > 0:",
"- j0 = len(A) - 1",
"- for i in range(len(A)):",
"- while j0 > i and A[i] * A[j0] >= m:",
"- j0 -= 1",
"- ans += j0 - i",
"- j0 = max(i + 1, j0)",
"- if len(B) > 0:",
"- j1 = len(B) - 1",
"- for i in range(len(B)):",
"- while j1 > i and B[i] * B[j1] >= m:",
"- j1 -= 1",
"- ans += j1 - i",
"- j1 = max(i + 1, j1)",
"- # print(le,ri,m,ans) # ansはm未満の数の個数",
"- if ans > k:",
"- ri = m",
"+ B.append(A[i])",
"+B.sort(reverse=True)",
"+C.sort()",
"+if k <= minus * zplus:",
"+ ok = 1",
"+ ng = -(10**20)",
"+ m = (ok + ng) // 2",
"+ while abs(ng - ok) > 1:",
"+ co = 0",
"+ j = len(C) - 1",
"+ for i in range(len(B)):",
"+ while j >= 0 and B[i] * C[j] > m:",
"+ j -= 1",
"+ co += j + 1",
"+ # print(m, co)",
"+ if co >= k:",
"+ ok = m",
"+ # print(\"ok\")",
"- le = m",
"- m = (le + ri) // 2",
"- print(le)",
"+ ng = m",
"+ # print(\"ng\")",
"+ m = (ok + ng) // 2",
"+ print(ok)",
"- # print(\"k\",k)",
"- A = A0[:]",
"- B = [-i for i in A1]",
"- B.sort()",
"- # print(A,B)",
"- le = -1",
"- ri = 10**18 + 2",
"- m = (le + ri) // 2",
"- while ri - le > 1:",
"- ans = 0",
"- if len(A) > 0:",
"- j0 = len(B) - 1",
"- for i in range(len(A)):",
"- # print(\"seki\",A[i]*B[j0])",
"- while j0 >= 0 and A[i] * B[j0] >= m:",
"- j0 -= 1",
"- ans += j0 + 1",
"- # print(\"plus\",j0)",
"- # print(le,ri,m,ans) # ansはm未満の数の個数",
"- if ans > k:",
"- ri = m",
"+ k -= minus * zplus",
"+ ok = 10**20",
"+ ng = -1",
"+ m = (ok + ng) // 2",
"+ while abs(ng - ok) > 1:",
"+ co = 0",
"+ j = len(C) - 1",
"+ for i in range(len(C)):",
"+ while j > i and C[i] * C[j] <= m:",
"+ j -= 1",
"+ co += len(C) - 1 - j",
"+ j = max(j, i + 1)",
"+ j = len(B) - 1",
"+ for i in range(len(B)):",
"+ while j > i and B[i] * B[j] <= m:",
"+ j -= 1",
"+ co += len(B) - 1 - j",
"+ j = max(j, i + 1)",
"+ if co >= k:",
"+ ok = m",
"+ # print(\"ok\")",
"- le = m",
"- m = (le + ri) // 2",
"- print((-le))",
"-# CC = []",
"-# A = A00[:]",
"-# for i in range(n):",
"-# for j in range(i+1,n):",
"-# CC.append(A[i]*A[j])",
"-# CC.sort()",
"-# print(\"lenCC\", len(CC))",
"-# print(CC)",
"-# print(CC[400:420])",
"+ ng = m",
"+ # print(\"ng\")",
"+ m = (ok + ng) // 2",
"+ print(ok)"
]
| false | 0.038633 | 0.038471 | 1.004231 | [
"s660191697",
"s444733254"
]
|
u682860781 | p02714 | python | s031953167 | s480001811 | 1,943 | 1,191 | 9,092 | 9,156 | Accepted | Accepted | 38.7 | n = int(eval(input()))
s = eval(input())
cnt = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
for j in range(i+1, n-1):
if s[i] == s[j]:
continue
k = j - i + j
if k > n-1:
continue
if s[i] == s[k] or s[j] == s[k]:
continue
cnt -= 1
print(cnt)
| n = int(eval(input()))
s = eval(input())
cnt = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
for j in range(i+1, n-1):
if s[i] == s[j]:
continue
k = j - i + j
if k > n-1:
break
if s[i] == s[k] or s[j] == s[k]:
continue
cnt -= 1
print(cnt)
| 14 | 14 | 345 | 342 | n = int(eval(input()))
s = eval(input())
cnt = s.count("R") * s.count("G") * s.count("B")
for i in range(n - 2):
for j in range(i + 1, n - 1):
if s[i] == s[j]:
continue
k = j - i + j
if k > n - 1:
continue
if s[i] == s[k] or s[j] == s[k]:
continue
cnt -= 1
print(cnt)
| n = int(eval(input()))
s = eval(input())
cnt = s.count("R") * s.count("G") * s.count("B")
for i in range(n - 2):
for j in range(i + 1, n - 1):
if s[i] == s[j]:
continue
k = j - i + j
if k > n - 1:
break
if s[i] == s[k] or s[j] == s[k]:
continue
cnt -= 1
print(cnt)
| false | 0 | [
"- continue",
"+ break"
]
| false | 0.03761 | 0.046946 | 0.801137 | [
"s031953167",
"s480001811"
]
|
u813387707 | p02793 | python | s002525524 | s026777975 | 1,999 | 1,618 | 264,700 | 264,572 | Accepted | Accepted | 19.06 | from fractions import gcd
from functools import reduce
n = int(eval(input()))
a_list = [int(x) for x in input().split()]
temp = reduce(lambda x, y: (x * y) // gcd(x, y), a_list)
mod = 10 ** 9 + 7
ans = sum([temp // a for a in a_list]) % mod
print(ans) | from fractions import gcd
from functools import reduce
n = int(eval(input()))
a_list = [int(x) for x in input().split()]
temp = 1
for a in a_list:
temp *= a // gcd(a, temp)
mod = 10 ** 9 + 7
ans = sum([temp // a for a in a_list]) % mod
print(ans) | 13 | 15 | 262 | 263 | from fractions import gcd
from functools import reduce
n = int(eval(input()))
a_list = [int(x) for x in input().split()]
temp = reduce(lambda x, y: (x * y) // gcd(x, y), a_list)
mod = 10**9 + 7
ans = sum([temp // a for a in a_list]) % mod
print(ans)
| from fractions import gcd
from functools import reduce
n = int(eval(input()))
a_list = [int(x) for x in input().split()]
temp = 1
for a in a_list:
temp *= a // gcd(a, temp)
mod = 10**9 + 7
ans = sum([temp // a for a in a_list]) % mod
print(ans)
| false | 13.333333 | [
"-temp = reduce(lambda x, y: (x * y) // gcd(x, y), a_list)",
"+temp = 1",
"+for a in a_list:",
"+ temp *= a // gcd(a, temp)"
]
| false | 0.139044 | 0.056853 | 2.445684 | [
"s002525524",
"s026777975"
]
|
u357751375 | p03470 | python | s642596887 | s136650277 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | n = int(eval(input()))
d = []
for i in range(n):
d.append(int(eval(input())))
i = 1
c = 1
list.sort(d,reverse = True)
j = d[0]
for i in range(len(d)):
if j > d[i]:
c += 1
j = d[i]
print(c) | n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
a = set(a)
print((len(a))) | 17 | 7 | 221 | 101 | n = int(eval(input()))
d = []
for i in range(n):
d.append(int(eval(input())))
i = 1
c = 1
list.sort(d, reverse=True)
j = d[0]
for i in range(len(d)):
if j > d[i]:
c += 1
j = d[i]
print(c)
| n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
a = set(a)
print((len(a)))
| false | 58.823529 | [
"-d = []",
"+a = []",
"- d.append(int(eval(input())))",
"-i = 1",
"-c = 1",
"-list.sort(d, reverse=True)",
"-j = d[0]",
"-for i in range(len(d)):",
"- if j > d[i]:",
"- c += 1",
"- j = d[i]",
"-print(c)",
"+ a.append(int(eval(input())))",
"+a = set(a)",
"+print((len(a)))"
]
| false | 0.048143 | 0.047615 | 1.011101 | [
"s642596887",
"s136650277"
]
|
u787562674 | p03377 | python | s173561313 | s169891738 | 21 | 19 | 3,316 | 2,940 | Accepted | Accepted | 9.52 | # Aは猫, Bはどっちかわからん
A, B, X = list(map(int, input().split()))
if X - A < 0:
print('NO')
elif X - A > B:
print('NO')
else:
print('YES')
| A, B, X = list(map(int, input().split()))
print(('NO' if X - A < 0 or X - A > B else 'YES'))
| 9 | 3 | 148 | 88 | # Aは猫, Bはどっちかわからん
A, B, X = list(map(int, input().split()))
if X - A < 0:
print("NO")
elif X - A > B:
print("NO")
else:
print("YES")
| A, B, X = list(map(int, input().split()))
print(("NO" if X - A < 0 or X - A > B else "YES"))
| false | 66.666667 | [
"-# Aは猫, Bはどっちかわからん",
"-if X - A < 0:",
"- print(\"NO\")",
"-elif X - A > B:",
"- print(\"NO\")",
"-else:",
"- print(\"YES\")",
"+print((\"NO\" if X - A < 0 or X - A > B else \"YES\"))"
]
| false | 0.044042 | 0.04452 | 0.98926 | [
"s173561313",
"s169891738"
]
|
u537976628 | p03485 | python | s007637629 | s090058548 | 26 | 24 | 9,052 | 8,976 | Accepted | Accepted | 7.69 | a, b = list(map(int, input().split()))
print((-(-(a + b) // 2))) | a, b = list(map(int, input().split()))
print(((a + b + 1) // 2)) | 2 | 2 | 57 | 57 | a, b = list(map(int, input().split()))
print((-(-(a + b) // 2)))
| a, b = list(map(int, input().split()))
print(((a + b + 1) // 2))
| false | 0 | [
"-print((-(-(a + b) // 2)))",
"+print(((a + b + 1) // 2))"
]
| false | 0.047651 | 0.048385 | 0.984829 | [
"s007637629",
"s090058548"
]
|
u674588203 | p02583 | python | s471790898 | s660717470 | 202 | 81 | 9,104 | 9,156 | Accepted | Accepted | 59.9 | # AtCoder Beginner Contest 175
# B - Making Triangle
import bisect
N=int(eval(input()))
L=list(map(int,input().split()))
ans=0
for i in range (N):
for j in range (i+1,N):
for k in range (j+1,N):
# print(i,j,k)
a=min(L[i],L[j],L[k])
c=max(L[i],L[j],L[k])
b=(L[i]+L[j]+L[k]-a-c)
if a+b>c and a<b<c:
ans+=1
print(ans) | # AtCoder Beginner Contest 175
# B - Making Triangle
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range (N):
for j in range (i+1,N):
for k in range (j+1,N):
if L[i]+L[j]>L[k] and L[i]<L[j]<L[k]:
ans+=1
print(ans) | 21 | 16 | 421 | 298 | # AtCoder Beginner Contest 175
# B - Making Triangle
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
# print(i,j,k)
a = min(L[i], L[j], L[k])
c = max(L[i], L[j], L[k])
b = L[i] + L[j] + L[k] - a - c
if a + b > c and a < b < c:
ans += 1
print(ans)
| # AtCoder Beginner Contest 175
# B - Making Triangle
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if L[i] + L[j] > L[k] and L[i] < L[j] < L[k]:
ans += 1
print(ans)
| false | 23.809524 | [
"-import bisect",
"-",
"+L.sort()",
"- # print(i,j,k)",
"- a = min(L[i], L[j], L[k])",
"- c = max(L[i], L[j], L[k])",
"- b = L[i] + L[j] + L[k] - a - c",
"- if a + b > c and a < b < c:",
"+ if L[i] + L[j] > L[k] and L[i] < L[j] < L[k]:"
]
| false | 0.081404 | 0.053896 | 1.510373 | [
"s471790898",
"s660717470"
]
|
u941753895 | p02918 | python | s891177433 | s524066145 | 173 | 45 | 11,004 | 10,820 | Accepted | Accepted | 73.99 | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
# Summarize count of factor within list -- START --
def summarize_list(sl):
a=sl[0]
c=1
res=[]
for x in sl[1:]:
if x==a:
c+=1
else:
res.append(c)
a=x
c=1
res.append(c)
return res
# Summarize count of factor within list --- END ---
def main():
n,k=LI()
s=list(S())
s=summarize_list(s)
if 2*k+1>=len(s):
return n-1
s=[0]+s
for i in range(len(s)-1):
s[i+1]+=s[i]
# print(s)
l1=[0]*len(s)
l2=[0]*len(s)
for i in range(1,len(s)):
l1[i]+=l1[i-1]
l1[i]+=s[i]-s[i-1]-1
for i in range(1,len(s))[::-1]:
l2[i-1]+=l2[i]
l2[i-1]+=s[i]-s[i-1]-1
# print(s)
# print(l1)
# print(l2)
ans=-inf
for i in range(len(s)-(2*k+1)):
a=s[2*k+1+i]
b=s[i]
# print(a,b)
c=l1[i]
d=l2[2*k+1+i]
ans=max(ans,a-b+c+d)
return ans-1
# main()
print((main()))
| import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())
def main():
n,k=LI()
s=S()
ans=0
x=s[0]
cnt=0
for y in s[1:]:
if x==y:
cnt+=1
else:
ans+=cnt
cnt=0
x=y
ans+=cnt
ans=min(n-1,ans+2*k)
return ans
# main()
print((main()))
| 75 | 36 | 1,329 | 759 | import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
# Summarize count of factor within list -- START --
def summarize_list(sl):
a = sl[0]
c = 1
res = []
for x in sl[1:]:
if x == a:
c += 1
else:
res.append(c)
a = x
c = 1
res.append(c)
return res
# Summarize count of factor within list --- END ---
def main():
n, k = LI()
s = list(S())
s = summarize_list(s)
if 2 * k + 1 >= len(s):
return n - 1
s = [0] + s
for i in range(len(s) - 1):
s[i + 1] += s[i]
# print(s)
l1 = [0] * len(s)
l2 = [0] * len(s)
for i in range(1, len(s)):
l1[i] += l1[i - 1]
l1[i] += s[i] - s[i - 1] - 1
for i in range(1, len(s))[::-1]:
l2[i - 1] += l2[i]
l2[i - 1] += s[i] - s[i - 1] - 1
# print(s)
# print(l1)
# print(l2)
ans = -inf
for i in range(len(s) - (2 * k + 1)):
a = s[2 * k + 1 + i]
b = s[i]
# print(a,b)
c = l1[i]
d = l2[2 * k + 1 + i]
ans = max(ans, a - b + c + d)
return ans - 1
# main()
print((main()))
| import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return eval(input())
def main():
n, k = LI()
s = S()
ans = 0
x = s[0]
cnt = 0
for y in s[1:]:
if x == y:
cnt += 1
else:
ans += cnt
cnt = 0
x = y
ans += cnt
ans = min(n - 1, ans + 2 * k)
return ans
# main()
print((main()))
| false | 52 | [
"+# def LF(): return [float(x) for x in sys.stdin.readline().split()]",
"+",
"+",
"+def F():",
"+ return float(sys.stdin.readline())",
"-# Summarize count of factor within list -- START --",
"-def summarize_list(sl):",
"- a = sl[0]",
"- c = 1",
"- res = []",
"- for x in sl[1:]:",
"- if x == a:",
"- c += 1",
"- else:",
"- res.append(c)",
"- a = x",
"- c = 1",
"- res.append(c)",
"- return res",
"-",
"-",
"- s = list(S())",
"- s = summarize_list(s)",
"- if 2 * k + 1 >= len(s):",
"- return n - 1",
"- s = [0] + s",
"- for i in range(len(s) - 1):",
"- s[i + 1] += s[i]",
"- # print(s)",
"- l1 = [0] * len(s)",
"- l2 = [0] * len(s)",
"- for i in range(1, len(s)):",
"- l1[i] += l1[i - 1]",
"- l1[i] += s[i] - s[i - 1] - 1",
"- for i in range(1, len(s))[::-1]:",
"- l2[i - 1] += l2[i]",
"- l2[i - 1] += s[i] - s[i - 1] - 1",
"- # print(s)",
"- # print(l1)",
"- # print(l2)",
"- ans = -inf",
"- for i in range(len(s) - (2 * k + 1)):",
"- a = s[2 * k + 1 + i]",
"- b = s[i]",
"- # print(a,b)",
"- c = l1[i]",
"- d = l2[2 * k + 1 + i]",
"- ans = max(ans, a - b + c + d)",
"- return ans - 1",
"+ s = S()",
"+ ans = 0",
"+ x = s[0]",
"+ cnt = 0",
"+ for y in s[1:]:",
"+ if x == y:",
"+ cnt += 1",
"+ else:",
"+ ans += cnt",
"+ cnt = 0",
"+ x = y",
"+ ans += cnt",
"+ ans = min(n - 1, ans + 2 * k)",
"+ return ans"
]
| false | 0.036577 | 0.036945 | 0.990035 | [
"s891177433",
"s524066145"
]
|
u036104576 | p03003 | python | s183023822 | s548544053 | 212 | 158 | 133,200 | 96,012 | Accepted | Accepted | 25.47 | import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
S.append(0)
T.append(0)
MAX = 2005
dp0 = [[0] * MAX for _ in range(MAX)]
dp1 = [[0] * MAX for _ in range(MAX)]
dp0[0][0] = 1
for i in range(N + 1):
for j in range(M + 1):
dp0[i + 1][j] += dp0[i][j] % MOD
dp1[i][j] += dp0[i][j] % MOD
dp1[i][j + 1] += dp1[i][j] % MOD
if S[i] == T[j]:
dp0[i + 1][j + 1] += dp1[i][j] % MOD
print((dp1[N][M] % MOD))
| import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = list(map(int, input().split()))
S = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
dp_cum = [[0] * (M+1) for _ in range(N+1)]
dp_cum[0][0] = 1
for n in range(N+1):
dp_cum[n][0] = 1
for m in range(M+1):
dp_cum[0][m] = 1
for n in range(1,N+1):
for m in range(1,M+1):
now = 0
if S[n] == T[m]:
now = dp_cum[n-1][m-1]
dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + now
dp_cum[n][m] %= MOD
print((dp_cum[N][M])) | 37 | 37 | 942 | 963 | import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
S.append(0)
T.append(0)
MAX = 2005
dp0 = [[0] * MAX for _ in range(MAX)]
dp1 = [[0] * MAX for _ in range(MAX)]
dp0[0][0] = 1
for i in range(N + 1):
for j in range(M + 1):
dp0[i + 1][j] += dp0[i][j] % MOD
dp1[i][j] += dp0[i][j] % MOD
dp1[i][j + 1] += dp1[i][j] % MOD
if S[i] == T[j]:
dp0[i + 1][j + 1] += dp1[i][j] % MOD
print((dp1[N][M] % MOD))
| import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = list(map(int, input().split()))
S = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
dp_cum = [[0] * (M + 1) for _ in range(N + 1)]
dp_cum[0][0] = 1
for n in range(N + 1):
dp_cum[n][0] = 1
for m in range(M + 1):
dp_cum[0][m] = 1
for n in range(1, N + 1):
for m in range(1, M + 1):
now = 0
if S[n] == T[m]:
now = dp_cum[n - 1][m - 1]
dp_cum[n][m] = dp_cum[n - 1][m] + dp_cum[n][m - 1] - dp_cum[n - 1][m - 1] + now
dp_cum[n][m] %= MOD
print((dp_cum[N][M]))
| false | 0 | [
"-S = list(map(int, input().split()))",
"-T = list(map(int, input().split()))",
"-S.append(0)",
"-T.append(0)",
"-MAX = 2005",
"-dp0 = [[0] * MAX for _ in range(MAX)]",
"-dp1 = [[0] * MAX for _ in range(MAX)]",
"-dp0[0][0] = 1",
"-for i in range(N + 1):",
"- for j in range(M + 1):",
"- dp0[i + 1][j] += dp0[i][j] % MOD",
"- dp1[i][j] += dp0[i][j] % MOD",
"- dp1[i][j + 1] += dp1[i][j] % MOD",
"- if S[i] == T[j]:",
"- dp0[i + 1][j + 1] += dp1[i][j] % MOD",
"-print((dp1[N][M] % MOD))",
"+S = [0] + list(map(int, input().split()))",
"+T = [0] + list(map(int, input().split()))",
"+dp_cum = [[0] * (M + 1) for _ in range(N + 1)]",
"+dp_cum[0][0] = 1",
"+for n in range(N + 1):",
"+ dp_cum[n][0] = 1",
"+for m in range(M + 1):",
"+ dp_cum[0][m] = 1",
"+for n in range(1, N + 1):",
"+ for m in range(1, M + 1):",
"+ now = 0",
"+ if S[n] == T[m]:",
"+ now = dp_cum[n - 1][m - 1]",
"+ dp_cum[n][m] = dp_cum[n - 1][m] + dp_cum[n][m - 1] - dp_cum[n - 1][m - 1] + now",
"+ dp_cum[n][m] %= MOD",
"+print((dp_cum[N][M]))"
]
| false | 0.333889 | 0.03632 | 9.192985 | [
"s183023822",
"s548544053"
]
|
u562935282 | p03148 | python | s318450072 | s961757826 | 539 | 289 | 23,876 | 20,556 | Accepted | Accepted | 46.38 | # 解説放送
N, K = list(map(int, input().split()))
e = [None for _ in range(N + 1)] # 種別の美味しさ
t_kinds_count = 0 # 何種類あるか
rest_length = 0 # 各種の2番手以降の個数の総数
tops = [] # 各種の最大美味しさ
c_tops = [0] # 各種の最大美味しさの累積和
rests = [] # 各種の2番手以降
c_rests = [0] # 各種の2番手以降の累積和
for _ in range(N):
t, d = list(map(int, input().split()))
if e[t] is None:
e[t] = []
t_kinds_count += 1
e[t].append(d)
for t in range(1, N + 1):
if e[t] is None:
continue
e[t].sort(reverse=True)
tops.append(e[t][0])
rests.extend(e[t][1:])
tops.sort(reverse=True)
rests.sort(reverse=True)
s = 0
for tt in tops:
s += tt
c_tops.append(s)
s = 0
for rr in rests:
s += rr
c_rests.append(s)
rest_length += 1
ans = 0
for yy in range(1, min(t_kinds_count, K) + 1):
if 0 <= K - yy <= rest_length:
ans = max(ans, c_tops[yy] + c_rests[K - yy] + yy * yy)
# print(e)
# print(tops)
# print(c_tops)
# print(rests)
# print(c_rests)
print(ans)
| from heapq import heappush, heappop
from operator import itemgetter
import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
e = []
for _ in range(n):
t, d = list(map(int, input().split()))
t -= 1
e.append((d, t))
e.sort(key=itemgetter(0), reverse=True)
b = e[:k] # 暫定選択(おいしさ基礎ポイント降順取得)
used = [False] * n
hq = []
ans = 0 # 暫定選択(おいしさ基礎ポイント降順取得)
tn = 0 # 種類数
for d, t in b:
if not used[t]:
used[t] = True
tn += 1
else:
heappush(hq, (d, t))
ans += d
ans += pow(tn, 2) # 種類ボーナス
c = e[k:] # 取得しなかった予備
# print(b)
# print(c)
# print(hq)
# print(used)
s = ans
cur = 0
while hq:
d, t = heappop(hq)
s -= d
changed = False
while cur < n - k:
cd, ct = c[cur]
cur += 1
if not used[ct]:
used[ct] = True
changed = True
s += cd
s += tn * 2 + 1
tn += 1
if s > ans:
ans = s
break
if not changed:
break
print(ans)
| 53 | 58 | 1,012 | 1,074 | # 解説放送
N, K = list(map(int, input().split()))
e = [None for _ in range(N + 1)] # 種別の美味しさ
t_kinds_count = 0 # 何種類あるか
rest_length = 0 # 各種の2番手以降の個数の総数
tops = [] # 各種の最大美味しさ
c_tops = [0] # 各種の最大美味しさの累積和
rests = [] # 各種の2番手以降
c_rests = [0] # 各種の2番手以降の累積和
for _ in range(N):
t, d = list(map(int, input().split()))
if e[t] is None:
e[t] = []
t_kinds_count += 1
e[t].append(d)
for t in range(1, N + 1):
if e[t] is None:
continue
e[t].sort(reverse=True)
tops.append(e[t][0])
rests.extend(e[t][1:])
tops.sort(reverse=True)
rests.sort(reverse=True)
s = 0
for tt in tops:
s += tt
c_tops.append(s)
s = 0
for rr in rests:
s += rr
c_rests.append(s)
rest_length += 1
ans = 0
for yy in range(1, min(t_kinds_count, K) + 1):
if 0 <= K - yy <= rest_length:
ans = max(ans, c_tops[yy] + c_rests[K - yy] + yy * yy)
# print(e)
# print(tops)
# print(c_tops)
# print(rests)
# print(c_rests)
print(ans)
| from heapq import heappush, heappop
from operator import itemgetter
import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
e = []
for _ in range(n):
t, d = list(map(int, input().split()))
t -= 1
e.append((d, t))
e.sort(key=itemgetter(0), reverse=True)
b = e[:k] # 暫定選択(おいしさ基礎ポイント降順取得)
used = [False] * n
hq = []
ans = 0 # 暫定選択(おいしさ基礎ポイント降順取得)
tn = 0 # 種類数
for d, t in b:
if not used[t]:
used[t] = True
tn += 1
else:
heappush(hq, (d, t))
ans += d
ans += pow(tn, 2) # 種類ボーナス
c = e[k:] # 取得しなかった予備
# print(b)
# print(c)
# print(hq)
# print(used)
s = ans
cur = 0
while hq:
d, t = heappop(hq)
s -= d
changed = False
while cur < n - k:
cd, ct = c[cur]
cur += 1
if not used[ct]:
used[ct] = True
changed = True
s += cd
s += tn * 2 + 1
tn += 1
if s > ans:
ans = s
break
if not changed:
break
print(ans)
| false | 8.62069 | [
"-# 解説放送",
"-N, K = list(map(int, input().split()))",
"-e = [None for _ in range(N + 1)] # 種別の美味しさ",
"-t_kinds_count = 0 # 何種類あるか",
"-rest_length = 0 # 各種の2番手以降の個数の総数",
"-tops = [] # 各種の最大美味しさ",
"-c_tops = [0] # 各種の最大美味しさの累積和",
"-rests = [] # 各種の2番手以降",
"-c_rests = [0] # 各種の2番手以降の累積和",
"-for _ in range(N):",
"+from heapq import heappush, heappop",
"+from operator import itemgetter",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+n, k = list(map(int, input().split()))",
"+e = []",
"+for _ in range(n):",
"- if e[t] is None:",
"- e[t] = []",
"- t_kinds_count += 1",
"- e[t].append(d)",
"-for t in range(1, N + 1):",
"- if e[t] is None:",
"- continue",
"- e[t].sort(reverse=True)",
"- tops.append(e[t][0])",
"- rests.extend(e[t][1:])",
"-tops.sort(reverse=True)",
"-rests.sort(reverse=True)",
"-s = 0",
"-for tt in tops:",
"- s += tt",
"- c_tops.append(s)",
"-s = 0",
"-for rr in rests:",
"- s += rr",
"- c_rests.append(s)",
"- rest_length += 1",
"-ans = 0",
"-for yy in range(1, min(t_kinds_count, K) + 1):",
"- if 0 <= K - yy <= rest_length:",
"- ans = max(ans, c_tops[yy] + c_rests[K - yy] + yy * yy)",
"-# print(e)",
"-# print(tops)",
"-# print(c_tops)",
"-# print(rests)",
"-# print(c_rests)",
"+ t -= 1",
"+ e.append((d, t))",
"+e.sort(key=itemgetter(0), reverse=True)",
"+b = e[:k] # 暫定選択(おいしさ基礎ポイント降順取得)",
"+used = [False] * n",
"+hq = []",
"+ans = 0 # 暫定選択(おいしさ基礎ポイント降順取得)",
"+tn = 0 # 種類数",
"+for d, t in b:",
"+ if not used[t]:",
"+ used[t] = True",
"+ tn += 1",
"+ else:",
"+ heappush(hq, (d, t))",
"+ ans += d",
"+ans += pow(tn, 2) # 種類ボーナス",
"+c = e[k:] # 取得しなかった予備",
"+# print(b)",
"+# print(c)",
"+# print(hq)",
"+# print(used)",
"+s = ans",
"+cur = 0",
"+while hq:",
"+ d, t = heappop(hq)",
"+ s -= d",
"+ changed = False",
"+ while cur < n - k:",
"+ cd, ct = c[cur]",
"+ cur += 1",
"+ if not used[ct]:",
"+ used[ct] = True",
"+ changed = True",
"+ s += cd",
"+ s += tn * 2 + 1",
"+ tn += 1",
"+ if s > ans:",
"+ ans = s",
"+ break",
"+ if not changed:",
"+ break"
]
| false | 0.035459 | 0.036253 | 0.978108 | [
"s318450072",
"s961757826"
]
|
u786020649 | p03504 | python | s577781516 | s151493204 | 914 | 557 | 74,832 | 94,440 | Accepted | Accepted | 39.06 | import sys
readline=sys.stdin.readline
read=sys.stdin.read
n,c=list(map(int,readline().split()))
m=2*10**5
stc=[list(map(int,l.split())) for l in read().splitlines()]
cht=[[0]*(m+1) for _ in range(c)]
for e in stc:
cht[e[2]-1][2*e[0]-1:2*e[1]]=[1 for _ in range(2*e[1]-2*e[0]+1)]
mnr=0
for i in range(1,m+1):
mnr=max(mnr,sum(cht[ch][i] for ch in range(c)))
print(mnr)
| import sys
import numpy as np
readline=sys.stdin.readline
read=sys.stdin.read
n,c=list(map(int,readline().split()))
m=2*10**5
stc=[list(map(int,l.split())) for l in read().splitlines()]
cht=np.zeros((c,m+1),dtype='int64')
for e in stc:
cht[e[2]-1,2*e[0]-1:2*e[1]]=np.ones(2*e[1]-2*e[0]+1)
print((max(np.sum(cht,axis=0))))
| 14 | 12 | 380 | 328 | import sys
readline = sys.stdin.readline
read = sys.stdin.read
n, c = list(map(int, readline().split()))
m = 2 * 10**5
stc = [list(map(int, l.split())) for l in read().splitlines()]
cht = [[0] * (m + 1) for _ in range(c)]
for e in stc:
cht[e[2] - 1][2 * e[0] - 1 : 2 * e[1]] = [1 for _ in range(2 * e[1] - 2 * e[0] + 1)]
mnr = 0
for i in range(1, m + 1):
mnr = max(mnr, sum(cht[ch][i] for ch in range(c)))
print(mnr)
| import sys
import numpy as np
readline = sys.stdin.readline
read = sys.stdin.read
n, c = list(map(int, readline().split()))
m = 2 * 10**5
stc = [list(map(int, l.split())) for l in read().splitlines()]
cht = np.zeros((c, m + 1), dtype="int64")
for e in stc:
cht[e[2] - 1, 2 * e[0] - 1 : 2 * e[1]] = np.ones(2 * e[1] - 2 * e[0] + 1)
print((max(np.sum(cht, axis=0))))
| false | 14.285714 | [
"+import numpy as np",
"-cht = [[0] * (m + 1) for _ in range(c)]",
"+cht = np.zeros((c, m + 1), dtype=\"int64\")",
"- cht[e[2] - 1][2 * e[0] - 1 : 2 * e[1]] = [1 for _ in range(2 * e[1] - 2 * e[0] + 1)]",
"-mnr = 0",
"-for i in range(1, m + 1):",
"- mnr = max(mnr, sum(cht[ch][i] for ch in range(c)))",
"-print(mnr)",
"+ cht[e[2] - 1, 2 * e[0] - 1 : 2 * e[1]] = np.ones(2 * e[1] - 2 * e[0] + 1)",
"+print((max(np.sum(cht, axis=0))))"
]
| false | 0.528355 | 0.504376 | 1.047541 | [
"s577781516",
"s151493204"
]
|
u170839742 | p02629 | python | s241078971 | s783008369 | 33 | 29 | 9,172 | 9,136 | Accepted | Accepted | 12.12 | N = int(eval(input()))
res = []
while N:
r = N % 26
if r == 0:
r = 26
res.append(chr(r + 96))
if r == 26:
N -= 1
N //= 26
res.reverse()
print((''.join(res))) | N = int(eval(input()))
res = []
while N:
N -= 1
N, r = divmod(N, 26)
res.append(chr(r + ord('a')))
res.reverse()
print((''.join(res)))
| 12 | 8 | 196 | 146 | N = int(eval(input()))
res = []
while N:
r = N % 26
if r == 0:
r = 26
res.append(chr(r + 96))
if r == 26:
N -= 1
N //= 26
res.reverse()
print(("".join(res)))
| N = int(eval(input()))
res = []
while N:
N -= 1
N, r = divmod(N, 26)
res.append(chr(r + ord("a")))
res.reverse()
print(("".join(res)))
| false | 33.333333 | [
"- r = N % 26",
"- if r == 0:",
"- r = 26",
"- res.append(chr(r + 96))",
"- if r == 26:",
"- N -= 1",
"- N //= 26",
"+ N -= 1",
"+ N, r = divmod(N, 26)",
"+ res.append(chr(r + ord(\"a\")))"
]
| false | 0.041269 | 0.04096 | 1.007537 | [
"s241078971",
"s783008369"
]
|
u393512980 | p02821 | python | s962348096 | s157141750 | 1,414 | 920 | 14,428 | 30,080 | Accepted | Accepted | 34.94 | import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
MOD = 10**9+7
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
A.sort()
l, r = 0, 10**6
while l+1 < r:
m = (l+r)//2
cnt = 0
for a in A:
cnt += N-bisect_left(A, m-a)
if cnt < M:
r = m
else:
l = m
f = [0]+A[::-1]
for i in range(N):
f[i+1] += f[i]
cnt, ans = 0, 0
for a in A:
i = bisect_right(A, l-a)
ans += f[N-i]+(N-i)*a
cnt += N-i
print((ans+(M-cnt)*l))
| import numpy as np
from numpy.fft import rfft, irfft
import sys
input=sys.stdin.readline
N, M = list(map(int, input().split()))
fft_len = 1<<18
MAX = 2*10**5
A = np.zeros(fft_len)
for a in [int(x) for x in input().split()]:
A[a] += 1
F = rfft(A, fft_len)
f = np.rint(irfft(F*F))
n, ans = 0, 0
for i, c in enumerate(f[:MAX+1][::-1]):
if M < n+c:
ans += (M-n)*(MAX-i)
break
ans += c*(MAX-i)
n += c
print((int(ans)))
| 34 | 21 | 676 | 459 | import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
A.sort()
l, r = 0, 10**6
while l + 1 < r:
m = (l + r) // 2
cnt = 0
for a in A:
cnt += N - bisect_left(A, m - a)
if cnt < M:
r = m
else:
l = m
f = [0] + A[::-1]
for i in range(N):
f[i + 1] += f[i]
cnt, ans = 0, 0
for a in A:
i = bisect_right(A, l - a)
ans += f[N - i] + (N - i) * a
cnt += N - i
print((ans + (M - cnt) * l))
| import numpy as np
from numpy.fft import rfft, irfft
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
fft_len = 1 << 18
MAX = 2 * 10**5
A = np.zeros(fft_len)
for a in [int(x) for x in input().split()]:
A[a] += 1
F = rfft(A, fft_len)
f = np.rint(irfft(F * F))
n, ans = 0, 0
for i, c in enumerate(f[: MAX + 1][::-1]):
if M < n + c:
ans += (M - n) * (MAX - i)
break
ans += c * (MAX - i)
n += c
print((int(ans)))
| false | 38.235294 | [
"+import numpy as np",
"+from numpy.fft import rfft, irfft",
"-sys.setrecursionlimit(10000000)",
"-# input = sys.stdin.readline",
"-from bisect import *",
"-",
"-# from collections import *",
"-# from heapq import *",
"-# import functools",
"-# import itertools",
"-# import math",
"-INF = 500000",
"-MOD = 10**9 + 7",
"+input = sys.stdin.readline",
"-A = [int(x) for x in input().split()]",
"-A.sort()",
"-l, r = 0, 10**6",
"-while l + 1 < r:",
"- m = (l + r) // 2",
"- cnt = 0",
"- for a in A:",
"- cnt += N - bisect_left(A, m - a)",
"- if cnt < M:",
"- r = m",
"- else:",
"- l = m",
"-f = [0] + A[::-1]",
"-for i in range(N):",
"- f[i + 1] += f[i]",
"-cnt, ans = 0, 0",
"-for a in A:",
"- i = bisect_right(A, l - a)",
"- ans += f[N - i] + (N - i) * a",
"- cnt += N - i",
"-print((ans + (M - cnt) * l))",
"+fft_len = 1 << 18",
"+MAX = 2 * 10**5",
"+A = np.zeros(fft_len)",
"+for a in [int(x) for x in input().split()]:",
"+ A[a] += 1",
"+F = rfft(A, fft_len)",
"+f = np.rint(irfft(F * F))",
"+n, ans = 0, 0",
"+for i, c in enumerate(f[: MAX + 1][::-1]):",
"+ if M < n + c:",
"+ ans += (M - n) * (MAX - i)",
"+ break",
"+ ans += c * (MAX - i)",
"+ n += c",
"+print((int(ans)))"
]
| false | 0.082601 | 0.365067 | 0.226262 | [
"s962348096",
"s157141750"
]
|
u317710033 | p03493 | python | s090996061 | s764594860 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a = eval(input())
b = a.count('1')
print((1*b)) | a = eval(input())
b = a.count('1')
print(b) | 3 | 3 | 41 | 39 | a = eval(input())
b = a.count("1")
print((1 * b))
| a = eval(input())
b = a.count("1")
print(b)
| false | 0 | [
"-print((1 * b))",
"+print(b)"
]
| false | 0.083074 | 0.202875 | 0.409484 | [
"s090996061",
"s764594860"
]
|
u867826040 | p03425 | python | s515949134 | s231740560 | 59 | 49 | 9,184 | 8,988 | Accepted | Accepted | 16.95 | from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(int(eval(input()))):
si = sys.stdin.readline()[0]
if si in c:
c[si] += 1
ans = sum(i*j*k for i,j,k in cmbs(list(c.values()),r=3))
print(ans)
| from itertools import combinations as cmbs
import sys
c = {"M":0,"A":0,"R":0,"C":0,"H":0}
sys.stdin.readline()
for si in sys.stdin:
if si[0] in c:
c[si[0]] += 1
ans = sum(i*j*k for i,j,k in cmbs(list(c.values()),r=3))
print(ans)
| 9 | 9 | 250 | 243 | from itertools import combinations as cmbs
import sys
c = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(int(eval(input()))):
si = sys.stdin.readline()[0]
if si in c:
c[si] += 1
ans = sum(i * j * k for i, j, k in cmbs(list(c.values()), r=3))
print(ans)
| from itertools import combinations as cmbs
import sys
c = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
sys.stdin.readline()
for si in sys.stdin:
if si[0] in c:
c[si[0]] += 1
ans = sum(i * j * k for i, j, k in cmbs(list(c.values()), r=3))
print(ans)
| false | 0 | [
"-for i in range(int(eval(input()))):",
"- si = sys.stdin.readline()[0]",
"- if si in c:",
"- c[si] += 1",
"+sys.stdin.readline()",
"+for si in sys.stdin:",
"+ if si[0] in c:",
"+ c[si[0]] += 1"
]
| false | 0.035782 | 0.038484 | 0.929772 | [
"s515949134",
"s231740560"
]
|
u392319141 | p03112 | python | s861778636 | s405842339 | 1,646 | 1,505 | 13,848 | 12,816 | Accepted | Accepted | 8.57 | from bisect import bisect_right, bisect_left
A, B, Q = list(map(int, input().split()))
INF = 10**18
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for _ in range(Q):
x = int(eval(input()))
lS, lT = S[bisect_right(S, x) - 1], T[bisect_right(T, x) - 1]
rS, rT = S[bisect_left(S, x)], T[bisect_left(T, x)]
ans = min(
abs(lS - lT) + (x - max(lS, lT)),
abs(rS - rT) + (min(rS, rT) - x),
(rT - lS) + min(x - lS, rT - x),
(rS - lT) + min(x - lT, rS - x)
)
print(ans)
| from bisect import bisect_left
A, B, Q = list(map(int, input().split()))
INF = 10**18
S = [int(eval(input())) for _ in range(A)] + [INF, INF, -INF, -INF]
T = [int(eval(input())) for _ in range(B)] + [INF, INF, -INF, -INF]
S.sort()
T.sort()
for _ in range(Q):
x = int(eval(input()))
s = bisect_left(S, x)
ls = S[s - 1]
rs = S[s]
t = bisect_left(T, x)
lt = T[t - 1]
rt = T[t]
ans = min(
abs(ls - rt) + min(abs(x - ls), abs(x - rt)),
abs(lt - rs) + min(abs(x - lt), abs(x - rs)),
max(abs(x - ls), abs(x - lt)),
max(abs(x - rs), abs(x - rt))
)
print(ans)
| 21 | 29 | 590 | 634 | from bisect import bisect_right, bisect_left
A, B, Q = list(map(int, input().split()))
INF = 10**18
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for _ in range(Q):
x = int(eval(input()))
lS, lT = S[bisect_right(S, x) - 1], T[bisect_right(T, x) - 1]
rS, rT = S[bisect_left(S, x)], T[bisect_left(T, x)]
ans = min(
abs(lS - lT) + (x - max(lS, lT)),
abs(rS - rT) + (min(rS, rT) - x),
(rT - lS) + min(x - lS, rT - x),
(rS - lT) + min(x - lT, rS - x),
)
print(ans)
| from bisect import bisect_left
A, B, Q = list(map(int, input().split()))
INF = 10**18
S = [int(eval(input())) for _ in range(A)] + [INF, INF, -INF, -INF]
T = [int(eval(input())) for _ in range(B)] + [INF, INF, -INF, -INF]
S.sort()
T.sort()
for _ in range(Q):
x = int(eval(input()))
s = bisect_left(S, x)
ls = S[s - 1]
rs = S[s]
t = bisect_left(T, x)
lt = T[t - 1]
rt = T[t]
ans = min(
abs(ls - rt) + min(abs(x - ls), abs(x - rt)),
abs(lt - rs) + min(abs(x - lt), abs(x - rs)),
max(abs(x - ls), abs(x - lt)),
max(abs(x - rs), abs(x - rt)),
)
print(ans)
| false | 27.586207 | [
"-from bisect import bisect_right, bisect_left",
"+from bisect import bisect_left",
"-S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]",
"-T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]",
"+S = [int(eval(input())) for _ in range(A)] + [INF, INF, -INF, -INF]",
"+T = [int(eval(input())) for _ in range(B)] + [INF, INF, -INF, -INF]",
"+S.sort()",
"+T.sort()",
"- lS, lT = S[bisect_right(S, x) - 1], T[bisect_right(T, x) - 1]",
"- rS, rT = S[bisect_left(S, x)], T[bisect_left(T, x)]",
"+ s = bisect_left(S, x)",
"+ ls = S[s - 1]",
"+ rs = S[s]",
"+ t = bisect_left(T, x)",
"+ lt = T[t - 1]",
"+ rt = T[t]",
"- abs(lS - lT) + (x - max(lS, lT)),",
"- abs(rS - rT) + (min(rS, rT) - x),",
"- (rT - lS) + min(x - lS, rT - x),",
"- (rS - lT) + min(x - lT, rS - x),",
"+ abs(ls - rt) + min(abs(x - ls), abs(x - rt)),",
"+ abs(lt - rs) + min(abs(x - lt), abs(x - rs)),",
"+ max(abs(x - ls), abs(x - lt)),",
"+ max(abs(x - rs), abs(x - rt)),"
]
| false | 0.039145 | 0.09162 | 0.427254 | [
"s861778636",
"s405842339"
]
|
u055941944 | p03043 | python | s374680473 | s059253329 | 64 | 47 | 3,060 | 3,060 | Accepted | Accepted | 26.56 | n,k = list(map(int,input().split()))
ans = 0
for i in range(1,n+1):
y = 0
while i*2**y < k:
y +=1
else:
ans += (1/2)**y*1/n
print(ans) | n, k = list(map(int, input().split()))
ans = 0
for i in range(1,n+1):
a = i
x = 0
while a < k:
x += 1
a = a * 2
ans += (1/n)*(1/2)**x
print(ans) | 10 | 11 | 145 | 157 | n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
y = 0
while i * 2**y < k:
y += 1
else:
ans += (1 / 2) ** y * 1 / n
print(ans)
| n, k = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
a = i
x = 0
while a < k:
x += 1
a = a * 2
ans += (1 / n) * (1 / 2) ** x
print(ans)
| false | 9.090909 | [
"- y = 0",
"- while i * 2**y < k:",
"- y += 1",
"- else:",
"- ans += (1 / 2) ** y * 1 / n",
"+ a = i",
"+ x = 0",
"+ while a < k:",
"+ x += 1",
"+ a = a * 2",
"+ ans += (1 / n) * (1 / 2) ** x"
]
| false | 0.058482 | 0.054763 | 1.06791 | [
"s374680473",
"s059253329"
]
|
u054514819 | p02615 | python | s213814463 | s891137393 | 304 | 195 | 107,180 | 105,704 | Accepted | Accepted | 35.86 | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = list(mapint())
As.sort(reverse=True)
from heapq import heappush, heappop
first = (As.pop(0))
hq = []
if N<2:
print((0))
else:
ans = 0
second = As.pop(0)
ans += first
heappush(hq, (-second, -first))
heappush(hq, (-second, -first))
for a in As:
s, f = heappop(hq)
ans -= s
heappush(hq, (-a, s))
heappush(hq, (-a, f))
print(ans) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = list(mapint())
conf = 0
from heapq import heapify, heappop, heappush
As.sort(reverse=True)
m = As.pop(0)
s = As.pop(0)
conf += m
Q = []
heappush(Q, -s)
heappush(Q, -s)
for a in As:
s = heappop(Q)
conf -= s
heappush(Q, -a)
heappush(Q, -a)
print(conf) | 27 | 23 | 570 | 447 | import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = list(mapint())
As.sort(reverse=True)
from heapq import heappush, heappop
first = As.pop(0)
hq = []
if N < 2:
print((0))
else:
ans = 0
second = As.pop(0)
ans += first
heappush(hq, (-second, -first))
heappush(hq, (-second, -first))
for a in As:
s, f = heappop(hq)
ans -= s
heappush(hq, (-a, s))
heappush(hq, (-a, f))
print(ans)
| import sys
def input():
return sys.stdin.readline().strip()
def mapint():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
N = int(eval(input()))
As = list(mapint())
conf = 0
from heapq import heapify, heappop, heappush
As.sort(reverse=True)
m = As.pop(0)
s = As.pop(0)
conf += m
Q = []
heappush(Q, -s)
heappush(Q, -s)
for a in As:
s = heappop(Q)
conf -= s
heappush(Q, -a)
heappush(Q, -a)
print(conf)
| false | 14.814815 | [
"+conf = 0",
"+from heapq import heapify, heappop, heappush",
"+",
"-from heapq import heappush, heappop",
"-",
"-first = As.pop(0)",
"-hq = []",
"-if N < 2:",
"- print((0))",
"-else:",
"- ans = 0",
"- second = As.pop(0)",
"- ans += first",
"- heappush(hq, (-second, -first))",
"- heappush(hq, (-second, -first))",
"- for a in As:",
"- s, f = heappop(hq)",
"- ans -= s",
"- heappush(hq, (-a, s))",
"- heappush(hq, (-a, f))",
"-print(ans)",
"+m = As.pop(0)",
"+s = As.pop(0)",
"+conf += m",
"+Q = []",
"+heappush(Q, -s)",
"+heappush(Q, -s)",
"+for a in As:",
"+ s = heappop(Q)",
"+ conf -= s",
"+ heappush(Q, -a)",
"+ heappush(Q, -a)",
"+print(conf)"
]
| false | 0.04746 | 0.036406 | 1.303651 | [
"s213814463",
"s891137393"
]
|
u537976628 | p03434 | python | s842785074 | s839399708 | 28 | 25 | 9,184 | 9,148 | Accepted | Accepted | 10.71 | n = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
alc = 0
bb = 0
for i in range(0, n, 2):
alc += A[i]
for j in range(1, n, 2):
bb += A[j]
print((alc - bb)) | n = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
print((sum(A[::2]) - sum(A[1::2]))) | 9 | 3 | 194 | 110 | n = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
alc = 0
bb = 0
for i in range(0, n, 2):
alc += A[i]
for j in range(1, n, 2):
bb += A[j]
print((alc - bb))
| n = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
print((sum(A[::2]) - sum(A[1::2])))
| false | 66.666667 | [
"-alc = 0",
"-bb = 0",
"-for i in range(0, n, 2):",
"- alc += A[i]",
"-for j in range(1, n, 2):",
"- bb += A[j]",
"-print((alc - bb))",
"+print((sum(A[::2]) - sum(A[1::2])))"
]
| false | 0.038201 | 0.037943 | 1.006798 | [
"s842785074",
"s839399708"
]
|
u103657515 | p03286 | python | s443043177 | s688765530 | 249 | 175 | 43,996 | 38,512 | Accepted | Accepted | 29.72 | import bisect
n = int(eval(input()))
ps = [0] * (1 << 16)
for i in range(1 << 16):
temp = 0
x = 1
for j in range(16):
if (i >> j) & 1:
# temp += (-2) ** (2 *j)
temp += x
x *= 4
ps[i] = temp
pattern1 = None
pattern2 = None
for i in range(1 << 16):
temp2 = 0
x = 2
for j in range(16):
if (i >> j) & 1:
# temp2 += (-2) ** (2 *j + 1)
temp2 += x
x *= 4
n2 = n + temp2
pattern1 = bisect.bisect_left(ps, n2)
if pattern1 != (1 << 16) and ps[pattern1] == n2:
pattern2 = bin(i)[2:].zfill(16)
pattern1 = bin(pattern1)[2:].zfill(16)
break
ans = ""
for i in range(16):
ans += pattern2[i]
ans += pattern1[i]
true_ans = ""
flag = False
for i in range(len(ans)):
if ans[i]=="1":
true_ans += "1"
flag = True
elif flag:
true_ans += "0"
if true_ans == "":
true_ans = "0"
print(true_ans) | n = int(eval(input()))
n2 = n
ans = ""
for i in range(100):
while n != 0:
r = (n % 2)
n = (n - r) // (-2)
ans = str(r) + ans
if n2==0:
print("0")
else:
print(ans) | 49 | 12 | 1,025 | 203 | import bisect
n = int(eval(input()))
ps = [0] * (1 << 16)
for i in range(1 << 16):
temp = 0
x = 1
for j in range(16):
if (i >> j) & 1:
# temp += (-2) ** (2 *j)
temp += x
x *= 4
ps[i] = temp
pattern1 = None
pattern2 = None
for i in range(1 << 16):
temp2 = 0
x = 2
for j in range(16):
if (i >> j) & 1:
# temp2 += (-2) ** (2 *j + 1)
temp2 += x
x *= 4
n2 = n + temp2
pattern1 = bisect.bisect_left(ps, n2)
if pattern1 != (1 << 16) and ps[pattern1] == n2:
pattern2 = bin(i)[2:].zfill(16)
pattern1 = bin(pattern1)[2:].zfill(16)
break
ans = ""
for i in range(16):
ans += pattern2[i]
ans += pattern1[i]
true_ans = ""
flag = False
for i in range(len(ans)):
if ans[i] == "1":
true_ans += "1"
flag = True
elif flag:
true_ans += "0"
if true_ans == "":
true_ans = "0"
print(true_ans)
| n = int(eval(input()))
n2 = n
ans = ""
for i in range(100):
while n != 0:
r = n % 2
n = (n - r) // (-2)
ans = str(r) + ans
if n2 == 0:
print("0")
else:
print(ans)
| false | 75.510204 | [
"-import bisect",
"-",
"-ps = [0] * (1 << 16)",
"-for i in range(1 << 16):",
"- temp = 0",
"- x = 1",
"- for j in range(16):",
"- if (i >> j) & 1:",
"- # temp += (-2) ** (2 *j)",
"- temp += x",
"- x *= 4",
"- ps[i] = temp",
"-pattern1 = None",
"-pattern2 = None",
"-for i in range(1 << 16):",
"- temp2 = 0",
"- x = 2",
"- for j in range(16):",
"- if (i >> j) & 1:",
"- # temp2 += (-2) ** (2 *j + 1)",
"- temp2 += x",
"- x *= 4",
"- n2 = n + temp2",
"- pattern1 = bisect.bisect_left(ps, n2)",
"- if pattern1 != (1 << 16) and ps[pattern1] == n2:",
"- pattern2 = bin(i)[2:].zfill(16)",
"- pattern1 = bin(pattern1)[2:].zfill(16)",
"- break",
"+n2 = n",
"-for i in range(16):",
"- ans += pattern2[i]",
"- ans += pattern1[i]",
"-true_ans = \"\"",
"-flag = False",
"-for i in range(len(ans)):",
"- if ans[i] == \"1\":",
"- true_ans += \"1\"",
"- flag = True",
"- elif flag:",
"- true_ans += \"0\"",
"-if true_ans == \"\":",
"- true_ans = \"0\"",
"-print(true_ans)",
"+for i in range(100):",
"+ while n != 0:",
"+ r = n % 2",
"+ n = (n - r) // (-2)",
"+ ans = str(r) + ans",
"+if n2 == 0:",
"+ print(\"0\")",
"+else:",
"+ print(ans)"
]
| false | 1.10611 | 0.073112 | 15.128995 | [
"s443043177",
"s688765530"
]
|
u072717685 | p02614 | python | s677899452 | s941033006 | 73 | 29 | 67,856 | 9,224 | Accepted | Accepted | 60.27 | from itertools import product
import sys
read = sys.stdin.read
def main():
h, w, k = list(map(int, input().split()))
c = []
for _ in range(h):
row = [c == '#' for c in list(eval(input()))]
c.append(row)
r = 0
p1 = tuple(product((0, 1), repeat=w))
p2 = tuple(product((0, 1), repeat=h))
pat = tuple(product(p1, p2))
for pe in pat:
t = 0
for x, col in enumerate(pe[0]):
for y, row in enumerate(pe[1]):
t += col * row * c[y][x]
if t == k:
r += 1
print(r)
if __name__ == '__main__':
main() | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from itertools import product
def main():
h, w, k = list(map(int, input().split()))
gg = []
for _ in range(h):
row = [1 if c == '#' else 0 for c in list(eval(input()))]
gg.extend(row)
row_pro = tuple(product((0, 1), repeat=h))
col_pro = tuple(product((0, 1), repeat=w))
rows = []
for re in row_pro:
rows.append([i for i, b in enumerate(re) if b])
cols = []
for ce in col_pro:
cols.append([i for i, b in enumerate(ce) if b])
pat = tuple(product(rows, cols))
r = 0
for pate in pat:
t0 = 0
for p0 in pate[0]:
for p1 in pate[1]:
t0 += gg[p0*w + p1]
if t0 == k:
r += 1
print(r)
if __name__ == '__main__':
main()
| 23 | 32 | 614 | 874 | from itertools import product
import sys
read = sys.stdin.read
def main():
h, w, k = list(map(int, input().split()))
c = []
for _ in range(h):
row = [c == "#" for c in list(eval(input()))]
c.append(row)
r = 0
p1 = tuple(product((0, 1), repeat=w))
p2 = tuple(product((0, 1), repeat=h))
pat = tuple(product(p1, p2))
for pe in pat:
t = 0
for x, col in enumerate(pe[0]):
for y, row in enumerate(pe[1]):
t += col * row * c[y][x]
if t == k:
r += 1
print(r)
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from itertools import product
def main():
h, w, k = list(map(int, input().split()))
gg = []
for _ in range(h):
row = [1 if c == "#" else 0 for c in list(eval(input()))]
gg.extend(row)
row_pro = tuple(product((0, 1), repeat=h))
col_pro = tuple(product((0, 1), repeat=w))
rows = []
for re in row_pro:
rows.append([i for i, b in enumerate(re) if b])
cols = []
for ce in col_pro:
cols.append([i for i, b in enumerate(ce) if b])
pat = tuple(product(rows, cols))
r = 0
for pate in pat:
t0 = 0
for p0 in pate[0]:
for p1 in pate[1]:
t0 += gg[p0 * w + p1]
if t0 == k:
r += 1
print(r)
if __name__ == "__main__":
main()
| false | 28.125 | [
"-from itertools import product",
"+readline = sys.stdin.readline",
"+readlines = sys.stdin.readlines",
"+from itertools import product",
"- c = []",
"+ gg = []",
"- row = [c == \"#\" for c in list(eval(input()))]",
"- c.append(row)",
"+ row = [1 if c == \"#\" else 0 for c in list(eval(input()))]",
"+ gg.extend(row)",
"+ row_pro = tuple(product((0, 1), repeat=h))",
"+ col_pro = tuple(product((0, 1), repeat=w))",
"+ rows = []",
"+ for re in row_pro:",
"+ rows.append([i for i, b in enumerate(re) if b])",
"+ cols = []",
"+ for ce in col_pro:",
"+ cols.append([i for i, b in enumerate(ce) if b])",
"+ pat = tuple(product(rows, cols))",
"- p1 = tuple(product((0, 1), repeat=w))",
"- p2 = tuple(product((0, 1), repeat=h))",
"- pat = tuple(product(p1, p2))",
"- for pe in pat:",
"- t = 0",
"- for x, col in enumerate(pe[0]):",
"- for y, row in enumerate(pe[1]):",
"- t += col * row * c[y][x]",
"- if t == k:",
"+ for pate in pat:",
"+ t0 = 0",
"+ for p0 in pate[0]:",
"+ for p1 in pate[1]:",
"+ t0 += gg[p0 * w + p1]",
"+ if t0 == k:"
]
| false | 0.05221 | 0.007222 | 7.229014 | [
"s677899452",
"s941033006"
]
|
u974935538 | p02713 | python | s993849794 | s365981060 | 1,387 | 950 | 209,264 | 75,000 | Accepted | Accepted | 31.51 | K = int(eval(input()))
import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
temp = []
for i in range(1,K+1):
for j in range(1,K+1):
for k in range(1,K+1):
temp.append(gcd(i,j,k))
print((sum(temp))) | K = int(eval(input()))
import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
ans = 0
for i in range(1,K+1):
for j in range(1,K+1):
for k in range(1,K+1):
ans += (gcd(i,j,k))
print(ans) | 15 | 14 | 275 | 261 | K = int(eval(input()))
import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
temp = []
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
temp.append(gcd(i, j, k))
print((sum(temp)))
| K = int(eval(input()))
import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
ans = 0
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += gcd(i, j, k)
print(ans)
| false | 6.666667 | [
"-temp = []",
"+ans = 0",
"- temp.append(gcd(i, j, k))",
"-print((sum(temp)))",
"+ ans += gcd(i, j, k)",
"+print(ans)"
]
| false | 0.094535 | 0.041971 | 2.252356 | [
"s993849794",
"s365981060"
]
|
u221264296 | p02598 | python | s325707608 | s137402776 | 1,986 | 1,045 | 31,000 | 31,012 | Accepted | Accepted | 47.38 | from math import *
def trycut(val):
ret = 0
for i in range(n):
ret += ceil(a[i]/val)-1
return ret
n,k=list(map(int,input().split()))
a = [int(i) for i in input().split()]
low = 0
high = 1000000000
ans =-1
while low <= high:
mid = (low + high)/2
cut = trycut(mid)
# ~ print("low=",low, "high=", high,"val = ",mid,"ret = ",cut)
if cut <= k:
high = mid-0.0000001
ans = mid
else:
low = mid+0.0000001
# ~ if low < high: print(low, high, "je reviens")
ans = int(ans*1000000)/1000000
# ~ print(ans)
print((int(ceil(ans))))
| from math import *
def trycut(val):
if val == 0 : return float('inf')
ret = 0
for i in range(n):
ret += ceil(a[i]/val)-1
return ret
n,k=list(map(int,input().split()))
a = [int(i) for i in input().split()]
low = 0
high = 1000000000
ans =-1
while low <= high:
mid = (low + high)//2
cut = trycut(mid)
if cut <= k:
high = mid-1
ans = mid
else:
low = mid+1
print(ans)
| 30 | 27 | 563 | 408 | from math import *
def trycut(val):
ret = 0
for i in range(n):
ret += ceil(a[i] / val) - 1
return ret
n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
low = 0
high = 1000000000
ans = -1
while low <= high:
mid = (low + high) / 2
cut = trycut(mid)
# ~ print("low=",low, "high=", high,"val = ",mid,"ret = ",cut)
if cut <= k:
high = mid - 0.0000001
ans = mid
else:
low = mid + 0.0000001
# ~ if low < high: print(low, high, "je reviens")
ans = int(ans * 1000000) / 1000000
# ~ print(ans)
print((int(ceil(ans))))
| from math import *
def trycut(val):
if val == 0:
return float("inf")
ret = 0
for i in range(n):
ret += ceil(a[i] / val) - 1
return ret
n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
low = 0
high = 1000000000
ans = -1
while low <= high:
mid = (low + high) // 2
cut = trycut(mid)
if cut <= k:
high = mid - 1
ans = mid
else:
low = mid + 1
print(ans)
| false | 10 | [
"+ if val == 0:",
"+ return float(\"inf\")",
"- mid = (low + high) / 2",
"+ mid = (low + high) // 2",
"- # ~ print(\"low=\",low, \"high=\", high,\"val = \",mid,\"ret = \",cut)",
"- high = mid - 0.0000001",
"+ high = mid - 1",
"- low = mid + 0.0000001",
"- # ~ if low < high: print(low, high, \"je reviens\")",
"-ans = int(ans * 1000000) / 1000000",
"-# ~ print(ans)",
"-print((int(ceil(ans))))",
"+ low = mid + 1",
"+print(ans)"
]
| false | 0.045191 | 0.077827 | 0.580664 | [
"s325707608",
"s137402776"
]
|
u539692012 | p02658 | python | s980713144 | s481257154 | 122 | 89 | 83,540 | 20,584 | Accepted | Accepted | 27.05 | _,a=open(0)
t=1
for b in sorted(a.split()):
t*=int(b)
if t>10**18:t=-1;break
print(t) | _,a=open(0)
t=1
for b in sorted(a.split()):
t*=int(b)
if t>1e18:t=-1;break
print(t) | 6 | 6 | 92 | 90 | _, a = open(0)
t = 1
for b in sorted(a.split()):
t *= int(b)
if t > 10**18:
t = -1
break
print(t)
| _, a = open(0)
t = 1
for b in sorted(a.split()):
t *= int(b)
if t > 1e18:
t = -1
break
print(t)
| false | 0 | [
"- if t > 10**18:",
"+ if t > 1e18:"
]
| false | 0.038026 | 0.038825 | 0.979421 | [
"s980713144",
"s481257154"
]
|
u186838327 | p03610 | python | s339007607 | s433128499 | 174 | 71 | 41,840 | 69,568 | Accepted | Accepted | 59.2 | s = str(eval(input()))
ans = []
for i in range(len(s)):
if i%2 == 0:
ans.append(s[i])
print((''.join(ans)))
| s = str(eval(input()))
n = len(s)
ans = []
for i in range(n):
if i%2 == 0:
ans.append(s[i])
print((''.join(ans)))
| 6 | 7 | 117 | 124 | s = str(eval(input()))
ans = []
for i in range(len(s)):
if i % 2 == 0:
ans.append(s[i])
print(("".join(ans)))
| s = str(eval(input()))
n = len(s)
ans = []
for i in range(n):
if i % 2 == 0:
ans.append(s[i])
print(("".join(ans)))
| false | 14.285714 | [
"+n = len(s)",
"-for i in range(len(s)):",
"+for i in range(n):"
]
| false | 0.040873 | 0.052215 | 0.782772 | [
"s339007607",
"s433128499"
]
|
u612721349 | p03695 | python | s927303635 | s309881476 | 183 | 165 | 38,384 | 38,384 | Accepted | Accepted | 9.84 | al=[0]*13
eval(input())
for i in input().split():
al[int(i)//400]+=1
tuyoi=sum(al[8:])
iru=sum([1 for a in al[:8] if a > 0])
print((max(1,iru),iru+tuyoi)) | l=[0]*13
eval(input())
for i in input().split():
l[int(i)//400]+=1
r=sum([1 for a in l[:8] if a > 0])
print((max(1,r),r+sum(l[8:]))) | 7 | 6 | 156 | 131 | al = [0] * 13
eval(input())
for i in input().split():
al[int(i) // 400] += 1
tuyoi = sum(al[8:])
iru = sum([1 for a in al[:8] if a > 0])
print((max(1, iru), iru + tuyoi))
| l = [0] * 13
eval(input())
for i in input().split():
l[int(i) // 400] += 1
r = sum([1 for a in l[:8] if a > 0])
print((max(1, r), r + sum(l[8:])))
| false | 14.285714 | [
"-al = [0] * 13",
"+l = [0] * 13",
"- al[int(i) // 400] += 1",
"-tuyoi = sum(al[8:])",
"-iru = sum([1 for a in al[:8] if a > 0])",
"-print((max(1, iru), iru + tuyoi))",
"+ l[int(i) // 400] += 1",
"+r = sum([1 for a in l[:8] if a > 0])",
"+print((max(1, r), r + sum(l[8:])))"
]
| false | 0.043603 | 0.079311 | 0.549776 | [
"s927303635",
"s309881476"
]
|
u729133443 | p02912 | python | s960054106 | s399529159 | 155 | 135 | 14,180 | 14,180 | Accepted | Accepted | 12.9 | from heapq import*
n,m,*a=[-int(i)for i in open(0).read().split()]
heapify(a)
while m:heappush(a,0--heappop(a)//2);m+=1
print((-sum(a))) | def main():
from heapq import heapify,heappush,heappop
n,m,*a=[-int(i)for i in open(0).read().split()]
heapify(a)
for _ in range(-m):heappush(a,0--heappop(a)//2)
print((-sum(a)))
main() | 5 | 7 | 138 | 199 | from heapq import *
n, m, *a = [-int(i) for i in open(0).read().split()]
heapify(a)
while m:
heappush(a, 0 - -heappop(a) // 2)
m += 1
print((-sum(a)))
| def main():
from heapq import heapify, heappush, heappop
n, m, *a = [-int(i) for i in open(0).read().split()]
heapify(a)
for _ in range(-m):
heappush(a, 0 - -heappop(a) // 2)
print((-sum(a)))
main()
| false | 28.571429 | [
"-from heapq import *",
"+def main():",
"+ from heapq import heapify, heappush, heappop",
"-n, m, *a = [-int(i) for i in open(0).read().split()]",
"-heapify(a)",
"-while m:",
"- heappush(a, 0 - -heappop(a) // 2)",
"- m += 1",
"-print((-sum(a)))",
"+ n, m, *a = [-int(i) for i in open(0).read().split()]",
"+ heapify(a)",
"+ for _ in range(-m):",
"+ heappush(a, 0 - -heappop(a) // 2)",
"+ print((-sum(a)))",
"+",
"+",
"+main()"
]
| false | 0.067651 | 0.034604 | 1.954992 | [
"s960054106",
"s399529159"
]
|
u426534722 | p02385 | python | s386557135 | s063703439 | 40 | 20 | 6,356 | 5,620 | Accepted | Accepted | 50 | from copy import deepcopy, copy
class dice:
men = [0] * 7
def __init__(self, li = [0] * 6):
self.men = [0] + li
def move0(self, a, b, c, d):
self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
def move(self, h):
if h == "A":
pass
elif h == "N":
self.move0(1, 2, 6, 5)
elif h == "S":
self.move0(1, 5, 6, 2)
elif h == "W":
self.move0(1, 3, 6, 4)
elif h == "E":
self.move0(1, 4, 6, 3)
elif h == "O":
self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
elif h == "L":
self.move0(2, 3, 5, 4)
elif h == "R":
self.move0(2, 4, 5, 3)
elif h == "B":
self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
else:
print("笆イ繧ィ繝ゥ繝シ")
def move2(self, a, b):
if self.men[1] != a:
for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
if self.men[i] == a:
self.move(s)
break
if self.men[2] != b:
if b == self.men[3]:
self.move("L")
elif b == self.men[4]:
self.move("R")
else:
self.move("B")
saikoro1 = dice(list(map(int, input().split())))
saikoro2 = dice(list(map(int, input().split())))
ans = []
saikoro3 = deepcopy(saikoro2)
for i in range(6):
ans.append(saikoro3.men[:])
saikoro3.move("L")
ans.append(saikoro3.men[:])
saikoro3.move("L")
ans.append(saikoro3.men[:])
saikoro3.move("L")
ans.append(saikoro3.men[:])
saikoro3 = deepcopy(saikoro2)
saikoro3.move("SWENOOO"[i])
print(("Yes" if saikoro1.men in ans else "No"))
| class dice:
def __init__(self, li = [0] * 6):
self.men = [0] + li
def move0(self, a, b, c, d):
self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
def move(self, h):
if h == "N":
self.move0(1, 2, 6, 5)
elif h == "S":
self.move0(1, 5, 6, 2)
elif h == "W":
self.move0(1, 3, 6, 4)
elif h == "E":
self.move0(1, 4, 6, 3)
elif h == "O":
self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
elif h == "L":
self.move0(2, 3, 5, 4)
elif h == "R":
self.move0(2, 4, 5, 3)
elif h == "B":
self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
else:
print("▲err")
def move2(self, a, b):
if self.men[1] != a:
for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
if self.men[i] == a:
self.move(s)
break
if self.men[2] != b:
if b == self.men[3]:
self.move("L")
elif b == self.men[4]:
self.move("R")
else:
self.move("B")
def solve():
saikoro1 = dice(list(map(int, input().split())))
li = list(map(int, input().split()))
for i in range(6):
saikoro3 = dice(li)
if i:
saikoro3.move("_SWENOOO"[i])
if saikoro3.men == saikoro1.men:
return "Yes"
for _ in range(3):
saikoro3.move("L")
if saikoro3.men == saikoro1.men:
return "Yes"
return "No"
print((solve()))
| 57 | 53 | 1,962 | 1,841 | from copy import deepcopy, copy
class dice:
men = [0] * 7
def __init__(self, li=[0] * 6):
self.men = [0] + li
def move0(self, a, b, c, d):
self.men[a], self.men[b], self.men[c], self.men[d] = (
self.men[b],
self.men[c],
self.men[d],
self.men[a],
)
def move(self, h):
if h == "A":
pass
elif h == "N":
self.move0(1, 2, 6, 5)
elif h == "S":
self.move0(1, 5, 6, 2)
elif h == "W":
self.move0(1, 3, 6, 4)
elif h == "E":
self.move0(1, 4, 6, 3)
elif h == "O":
self.men[1], self.men[6], self.men[2], self.men[5] = (
self.men[6],
self.men[1],
self.men[5],
self.men[2],
)
elif h == "L":
self.move0(2, 3, 5, 4)
elif h == "R":
self.move0(2, 4, 5, 3)
elif h == "B":
self.men[3], self.men[4], self.men[2], self.men[5] = (
self.men[4],
self.men[3],
self.men[5],
self.men[2],
)
else:
print("笆イ繧ィ繝ゥ繝シ")
def move2(self, a, b):
if self.men[1] != a:
for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
if self.men[i] == a:
self.move(s)
break
if self.men[2] != b:
if b == self.men[3]:
self.move("L")
elif b == self.men[4]:
self.move("R")
else:
self.move("B")
saikoro1 = dice(list(map(int, input().split())))
saikoro2 = dice(list(map(int, input().split())))
ans = []
saikoro3 = deepcopy(saikoro2)
for i in range(6):
ans.append(saikoro3.men[:])
saikoro3.move("L")
ans.append(saikoro3.men[:])
saikoro3.move("L")
ans.append(saikoro3.men[:])
saikoro3.move("L")
ans.append(saikoro3.men[:])
saikoro3 = deepcopy(saikoro2)
saikoro3.move("SWENOOO"[i])
print(("Yes" if saikoro1.men in ans else "No"))
| class dice:
def __init__(self, li=[0] * 6):
self.men = [0] + li
def move0(self, a, b, c, d):
self.men[a], self.men[b], self.men[c], self.men[d] = (
self.men[b],
self.men[c],
self.men[d],
self.men[a],
)
def move(self, h):
if h == "N":
self.move0(1, 2, 6, 5)
elif h == "S":
self.move0(1, 5, 6, 2)
elif h == "W":
self.move0(1, 3, 6, 4)
elif h == "E":
self.move0(1, 4, 6, 3)
elif h == "O":
self.men[1], self.men[6], self.men[2], self.men[5] = (
self.men[6],
self.men[1],
self.men[5],
self.men[2],
)
elif h == "L":
self.move0(2, 3, 5, 4)
elif h == "R":
self.move0(2, 4, 5, 3)
elif h == "B":
self.men[3], self.men[4], self.men[2], self.men[5] = (
self.men[4],
self.men[3],
self.men[5],
self.men[2],
)
else:
print("▲err")
def move2(self, a, b):
if self.men[1] != a:
for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
if self.men[i] == a:
self.move(s)
break
if self.men[2] != b:
if b == self.men[3]:
self.move("L")
elif b == self.men[4]:
self.move("R")
else:
self.move("B")
def solve():
saikoro1 = dice(list(map(int, input().split())))
li = list(map(int, input().split()))
for i in range(6):
saikoro3 = dice(li)
if i:
saikoro3.move("_SWENOOO"[i])
if saikoro3.men == saikoro1.men:
return "Yes"
for _ in range(3):
saikoro3.move("L")
if saikoro3.men == saikoro1.men:
return "Yes"
return "No"
print((solve()))
| false | 7.017544 | [
"-from copy import deepcopy, copy",
"-",
"-",
"- men = [0] * 7",
"-",
"- if h == \"A\":",
"- pass",
"- elif h == \"N\":",
"+ if h == \"N\":",
"- print(\"笆イ繧ィ繝ゥ繝シ\")",
"+ print(\"▲err\")",
"-saikoro1 = dice(list(map(int, input().split())))",
"-saikoro2 = dice(list(map(int, input().split())))",
"-ans = []",
"-saikoro3 = deepcopy(saikoro2)",
"-for i in range(6):",
"- ans.append(saikoro3.men[:])",
"- saikoro3.move(\"L\")",
"- ans.append(saikoro3.men[:])",
"- saikoro3.move(\"L\")",
"- ans.append(saikoro3.men[:])",
"- saikoro3.move(\"L\")",
"- ans.append(saikoro3.men[:])",
"- saikoro3 = deepcopy(saikoro2)",
"- saikoro3.move(\"SWENOOO\"[i])",
"-print((\"Yes\" if saikoro1.men in ans else \"No\"))",
"+def solve():",
"+ saikoro1 = dice(list(map(int, input().split())))",
"+ li = list(map(int, input().split()))",
"+ for i in range(6):",
"+ saikoro3 = dice(li)",
"+ if i:",
"+ saikoro3.move(\"_SWENOOO\"[i])",
"+ if saikoro3.men == saikoro1.men:",
"+ return \"Yes\"",
"+ for _ in range(3):",
"+ saikoro3.move(\"L\")",
"+ if saikoro3.men == saikoro1.men:",
"+ return \"Yes\"",
"+ return \"No\"",
"+",
"+",
"+print((solve()))"
]
| false | 0.051593 | 0.201822 | 0.255638 | [
"s386557135",
"s063703439"
]
|
u373047809 | p03659 | python | s437476130 | s264504561 | 283 | 111 | 86,264 | 26,408 | Accepted | Accepted | 60.78 | from itertools import*;*a,s=list(accumulate(list(map(int,open(0).read().split()[1:]))));print((min(abs(s-x*2)for x in a))) | from itertools import*;eval(input());*a,s=accumulate(list(map(int,input().split())));print((min(abs(s-x*2)for x in a))) | 1 | 1 | 114 | 105 | from itertools import *
*a, s = list(accumulate(list(map(int, open(0).read().split()[1:]))))
print((min(abs(s - x * 2) for x in a)))
| from itertools import *
eval(input())
*a, s = accumulate(list(map(int, input().split())))
print((min(abs(s - x * 2) for x in a)))
| false | 0 | [
"-*a, s = list(accumulate(list(map(int, open(0).read().split()[1:]))))",
"+eval(input())",
"+*a, s = accumulate(list(map(int, input().split())))"
]
| false | 0.04 | 0.037286 | 1.072804 | [
"s437476130",
"s264504561"
]
|
u078349616 | p03408 | python | s912861005 | s649954574 | 21 | 18 | 3,316 | 3,060 | Accepted | Accepted | 14.29 | from collections import defaultdict
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
ans = 0
for s in set(S+T):
ans = max(ans, S.count(s) - T.count(s))
print(ans) | N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
ans = 0
for s in set(S+T):
ans = max(ans, S.count(s) - T.count(s))
print(ans) | 12 | 8 | 227 | 184 | from collections import defaultdict
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
ans = 0
for s in set(S + T):
ans = max(ans, S.count(s) - T.count(s))
print(ans)
| N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
M = int(eval(input()))
T = [eval(input()) for _ in range(M)]
ans = 0
for s in set(S + T):
ans = max(ans, S.count(s) - T.count(s))
print(ans)
| false | 33.333333 | [
"-from collections import defaultdict",
"-"
]
| false | 0.036791 | 0.057324 | 0.641798 | [
"s912861005",
"s649954574"
]
|
u832039789 | p03713 | python | s010336394 | s547132276 | 552 | 426 | 7,096 | 7,096 | Accepted | Accepted | 22.83 | h,w=list(map(int,input().split()));f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]),f([j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]))for i in range(1,h)]);print((min(g(h,w),g(w,h)))) | h,w=list(map(int,input().split()));f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]),f([i*w,(h-i)*(w//2),(h-i)*(w-w//2)]))for i in range(1,h)]);print((min(g(h,w),g(w,h)))) | 1 | 1 | 253 | 201 | h, w = list(map(int, input().split()))
f = lambda x: max(x) - min(x)
g = lambda h, w: min(
[
min(
f(
[
j if j else -1e9
for j in [i * w, ((h - i) // 2) * w, ((h - i) - (h - i) // 2) * w]
]
),
f(
[
j if j else -1e9
for j in [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]
]
),
)
for i in range(1, h)
]
)
print((min(g(h, w), g(w, h))))
| h, w = list(map(int, input().split()))
f = lambda x: max(x) - min(x)
g = lambda h, w: min(
[
min(
f([i * w, ((h - i) // 2) * w, ((h - i) - (h - i) // 2) * w]),
f([i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]),
)
for i in range(1, h)
]
)
print((min(g(h, w), g(w, h))))
| false | 0 | [
"- f(",
"- [",
"- j if j else -1e9",
"- for j in [i * w, ((h - i) // 2) * w, ((h - i) - (h - i) // 2) * w]",
"- ]",
"- ),",
"- f(",
"- [",
"- j if j else -1e9",
"- for j in [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]",
"- ]",
"- ),",
"+ f([i * w, ((h - i) // 2) * w, ((h - i) - (h - i) // 2) * w]),",
"+ f([i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]),"
]
| false | 0.008026 | 0.316875 | 0.025328 | [
"s010336394",
"s547132276"
]
|
u869790980 | p03737 | python | s932910533 | s825216420 | 383 | 319 | 85,436 | 84,916 | Accepted | Accepted | 16.71 | s = input().split()
print(''.join([w[0] for w in s]).upper())
| print(''.join([w[0] for w in input().split()]).upper()) | 2 | 1 | 66 | 58 | s = input().split()
print("".join([w[0] for w in s]).upper())
| print("".join([w[0] for w in input().split()]).upper())
| false | 50 | [
"-s = input().split()",
"-print(\"\".join([w[0] for w in s]).upper())",
"+print(\"\".join([w[0] for w in input().split()]).upper())"
]
| false | 0.042346 | 0.05398 | 0.784467 | [
"s932910533",
"s825216420"
]
|
u296518383 | p03796 | python | s274679590 | s294800627 | 231 | 35 | 4,024 | 2,940 | Accepted | Accepted | 84.85 | import math
print((math.factorial(int(eval(input())))%(10**9+7))) | N = int(eval(input()))
MOD = 10 ** 9 + 7
answer = 1
for i in range(1, N + 1):
answer = (answer * i) % MOD
print(answer) | 2 | 8 | 58 | 126 | import math
print((math.factorial(int(eval(input()))) % (10**9 + 7)))
| N = int(eval(input()))
MOD = 10**9 + 7
answer = 1
for i in range(1, N + 1):
answer = (answer * i) % MOD
print(answer)
| false | 75 | [
"-import math",
"-",
"-print((math.factorial(int(eval(input()))) % (10**9 + 7)))",
"+N = int(eval(input()))",
"+MOD = 10**9 + 7",
"+answer = 1",
"+for i in range(1, N + 1):",
"+ answer = (answer * i) % MOD",
"+print(answer)"
]
| false | 0.132624 | 0.10944 | 1.211842 | [
"s274679590",
"s294800627"
]
|
u131984977 | p02397 | python | s372035331 | s938138226 | 60 | 50 | 6,720 | 7,664 | Accepted | Accepted | 16.67 | while True:
(x, y) = [int(i) for i in input().split()]
if x == y == 0:
break
if x < y:
print((x, y))
else:
print((y, x)) | while True:
x, y = [int(i) for i in input().split()]
if x == y == 0:
break
if x > y:
x, y = y, x
print((x, y)) | 9 | 10 | 165 | 152 | while True:
(x, y) = [int(i) for i in input().split()]
if x == y == 0:
break
if x < y:
print((x, y))
else:
print((y, x))
| while True:
x, y = [int(i) for i in input().split()]
if x == y == 0:
break
if x > y:
x, y = y, x
print((x, y))
| false | 10 | [
"- (x, y) = [int(i) for i in input().split()]",
"+ x, y = [int(i) for i in input().split()]",
"- if x < y:",
"- print((x, y))",
"- else:",
"- print((y, x))",
"+ if x > y:",
"+ x, y = y, x",
"+ print((x, y))"
]
| false | 0.238314 | 0.070046 | 3.402241 | [
"s372035331",
"s938138226"
]
|
u572144347 | p03128 | python | s610551851 | s098348482 | 218 | 64 | 43,484 | 3,316 | Accepted | Accepted | 70.64 | #!/mnt/c/Users/moiki/bash/env/bin/python
N,M = list(map(int, input().split()))
cost = [0,2,5,5,4,5,6,3,7,6]
A =list(map(int, input().split()))
dp = [-1]*(N+1)
dp[0] = 0
for i in range(N):
if dp[i] == -1:
continue
for c,a in zip( [cost[a] for a in A], A):
if i + c <= N:
dp[i+c] = dp[i]+1
# print(dp)
i = N
ans = ""
A = sorted(A, reverse=True)
while i > 0:
for c,a in zip([cost[a] for a in A], A):
if i-c >= 0 and dp[i-c] == dp[i]-1:
ans += str(a)
i -= c
break # difficult !!
print(ans)
| costs = [2,5,5,4,5,6,3,7,6]
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
neginf = -1 * 1e20
D = [neginf]*(N+1)
def dp(n_match):
D[0] = 0
for n in range(1,n_match+1):
arr = [D[n-costs[a-1]] if n-costs[a-1]>=0 else neginf for a in A]
if max(arr) < 0:
continue
D[n] = max(arr)+1
def main():
dp(N)
n = N
ans = ''
while n>0:
arr = [ a for a in A if n-costs[a-1] >= 0 and D[n-costs[a-1]]==D[n]-1 ]
if len(arr)>0:
a = max(arr)
ans += str(a)
n -= costs[a-1]
# else:
# break
print(ans)
main()
| 28 | 32 | 605 | 681 | #!/mnt/c/Users/moiki/bash/env/bin/python
N, M = list(map(int, input().split()))
cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A = list(map(int, input().split()))
dp = [-1] * (N + 1)
dp[0] = 0
for i in range(N):
if dp[i] == -1:
continue
for c, a in zip([cost[a] for a in A], A):
if i + c <= N:
dp[i + c] = dp[i] + 1
# print(dp)
i = N
ans = ""
A = sorted(A, reverse=True)
while i > 0:
for c, a in zip([cost[a] for a in A], A):
if i - c >= 0 and dp[i - c] == dp[i] - 1:
ans += str(a)
i -= c
break # difficult !!
print(ans)
| costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
neginf = -1 * 1e20
D = [neginf] * (N + 1)
def dp(n_match):
D[0] = 0
for n in range(1, n_match + 1):
arr = [D[n - costs[a - 1]] if n - costs[a - 1] >= 0 else neginf for a in A]
if max(arr) < 0:
continue
D[n] = max(arr) + 1
def main():
dp(N)
n = N
ans = ""
while n > 0:
arr = [
a for a in A if n - costs[a - 1] >= 0 and D[n - costs[a - 1]] == D[n] - 1
]
if len(arr) > 0:
a = max(arr)
ans += str(a)
n -= costs[a - 1]
# else:
# break
print(ans)
main()
| false | 12.5 | [
"-#!/mnt/c/Users/moiki/bash/env/bin/python",
"+costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]",
"-cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]",
"-dp = [-1] * (N + 1)",
"-dp[0] = 0",
"-for i in range(N):",
"- if dp[i] == -1:",
"- continue",
"- for c, a in zip([cost[a] for a in A], A):",
"- if i + c <= N:",
"- dp[i + c] = dp[i] + 1",
"-# print(dp)",
"-i = N",
"-ans = \"\"",
"-A = sorted(A, reverse=True)",
"-while i > 0:",
"- for c, a in zip([cost[a] for a in A], A):",
"- if i - c >= 0 and dp[i - c] == dp[i] - 1:",
"+neginf = -1 * 1e20",
"+D = [neginf] * (N + 1)",
"+",
"+",
"+def dp(n_match):",
"+ D[0] = 0",
"+ for n in range(1, n_match + 1):",
"+ arr = [D[n - costs[a - 1]] if n - costs[a - 1] >= 0 else neginf for a in A]",
"+ if max(arr) < 0:",
"+ continue",
"+ D[n] = max(arr) + 1",
"+",
"+",
"+def main():",
"+ dp(N)",
"+ n = N",
"+ ans = \"\"",
"+ while n > 0:",
"+ arr = [",
"+ a for a in A if n - costs[a - 1] >= 0 and D[n - costs[a - 1]] == D[n] - 1",
"+ ]",
"+ if len(arr) > 0:",
"+ a = max(arr)",
"- i -= c",
"- break # difficult !!",
"-print(ans)",
"+ n -= costs[a - 1]",
"+ # else:",
"+ # break",
"+ print(ans)",
"+",
"+",
"+main()"
]
| false | 0.084123 | 0.162735 | 0.516932 | [
"s610551851",
"s098348482"
]
|
u863370423 | p02835 | python | s078088314 | s262969177 | 170 | 27 | 38,384 | 9,140 | Accepted | Accepted | 84.12 | def main():
a, b, c = list(map(int, input().split()))
if (a + b + c) >= 22:
print("bust")
else:
print("win")
main() | n = list(map(int, input().split()))
if n[0]+n[1]+n[2] >= 22:
print("bust")
else:
print("win") | 7 | 6 | 143 | 107 | def main():
a, b, c = list(map(int, input().split()))
if (a + b + c) >= 22:
print("bust")
else:
print("win")
main()
| n = list(map(int, input().split()))
if n[0] + n[1] + n[2] >= 22:
print("bust")
else:
print("win")
| false | 14.285714 | [
"-def main():",
"- a, b, c = list(map(int, input().split()))",
"- if (a + b + c) >= 22:",
"- print(\"bust\")",
"- else:",
"- print(\"win\")",
"-",
"-",
"-main()",
"+n = list(map(int, input().split()))",
"+if n[0] + n[1] + n[2] >= 22:",
"+ print(\"bust\")",
"+else:",
"+ print(\"win\")"
]
| false | 0.047557 | 0.047272 | 1.006031 | [
"s078088314",
"s262969177"
]
|
u498487134 | p02815 | python | s133661373 | s414325220 | 291 | 266 | 87,500 | 103,896 | Accepted | Accepted | 8.59 | N=int(eval(input()))
C=list(map(int,input().split()))
C.sort()
mod=10**9+7
ans=0
for i in range(N):
ans+=C[i]*(N-i+1)
ans%=mod
p=pow(4,N-1,mod)
print(((ans*p)%mod))
| import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
"""
Sは全部0と仮定して良い,最後に2^N倍
Cはソートしておく,後ろから使う.
iは0indexとする
各C[i]ごとに見るか,そうしたら,それが何番目かによって寄与が決まる
i桁目なので左にi桁あるけど,これは通り数にしか関与しない
右側にN-i-1(=aとする)桁分ある.a桁のうちj桁1があるとして,寄与がj*C[i]
通り数:
右:a個からj個えらぶ=aCj
左:0でも1でも置ける=2^i
変更時のD:j+1
i,jの2つのΣで考えると,j側は結局Σ((j+1) * aCj)
j=0~aでΣ(j+1 * aCj) = (a+2) * pow(2,a-1) = (N-i+2) * pow(2,a-1)
"""
def main():
mod=10**9+7
N=I()
C=LI()
C.sort()
ans=0
def calc(ii):
a = N-ii-1
if a==0:
temp_j=1
else:
temp_j = (a+2) * pow(2,a-1,mod)
temp = C[ii]*pow(2,ii,mod)*temp_j
return temp%mod
for i in range(N):
ans=(ans+calc(i))%mod
ans=(ans*pow(2,N,mod))%mod
print(ans)
main()
| 15 | 53 | 188 | 943 | N = int(eval(input()))
C = list(map(int, input().split()))
C.sort()
mod = 10**9 + 7
ans = 0
for i in range(N):
ans += C[i] * (N - i + 1)
ans %= mod
p = pow(4, N - 1, mod)
print(((ans * p) % mod))
| import sys
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
"""
Sは全部0と仮定して良い,最後に2^N倍
Cはソートしておく,後ろから使う.
iは0indexとする
各C[i]ごとに見るか,そうしたら,それが何番目かによって寄与が決まる
i桁目なので左にi桁あるけど,これは通り数にしか関与しない
右側にN-i-1(=aとする)桁分ある.a桁のうちj桁1があるとして,寄与がj*C[i]
通り数:
右:a個からj個えらぶ=aCj
左:0でも1でも置ける=2^i
変更時のD:j+1
i,jの2つのΣで考えると,j側は結局Σ((j+1) * aCj)
j=0~aでΣ(j+1 * aCj) = (a+2) * pow(2,a-1) = (N-i+2) * pow(2,a-1)
"""
def main():
mod = 10**9 + 7
N = I()
C = LI()
C.sort()
ans = 0
def calc(ii):
a = N - ii - 1
if a == 0:
temp_j = 1
else:
temp_j = (a + 2) * pow(2, a - 1, mod)
temp = C[ii] * pow(2, ii, mod) * temp_j
return temp % mod
for i in range(N):
ans = (ans + calc(i)) % mod
ans = (ans * pow(2, N, mod)) % mod
print(ans)
main()
| false | 71.698113 | [
"-N = int(eval(input()))",
"-C = list(map(int, input().split()))",
"-C.sort()",
"-mod = 10**9 + 7",
"-ans = 0",
"-for i in range(N):",
"- ans += C[i] * (N - i + 1)",
"- ans %= mod",
"-p = pow(4, N - 1, mod)",
"-print(((ans * p) % mod))",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+\"\"\"",
"+Sは全部0と仮定して良い,最後に2^N倍",
"+Cはソートしておく,後ろから使う.",
"+iは0indexとする",
"+各C[i]ごとに見るか,そうしたら,それが何番目かによって寄与が決まる",
"+i桁目なので左にi桁あるけど,これは通り数にしか関与しない",
"+右側にN-i-1(=aとする)桁分ある.a桁のうちj桁1があるとして,寄与がj*C[i]",
"+通り数:",
"+右:a個からj個えらぶ=aCj",
"+左:0でも1でも置ける=2^i",
"+変更時のD:j+1",
"+i,jの2つのΣで考えると,j側は結局Σ((j+1) * aCj)",
"+j=0~aでΣ(j+1 * aCj) = (a+2) * pow(2,a-1) = (N-i+2) * pow(2,a-1)",
"+\"\"\"",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ N = I()",
"+ C = LI()",
"+ C.sort()",
"+ ans = 0",
"+",
"+ def calc(ii):",
"+ a = N - ii - 1",
"+ if a == 0:",
"+ temp_j = 1",
"+ else:",
"+ temp_j = (a + 2) * pow(2, a - 1, mod)",
"+ temp = C[ii] * pow(2, ii, mod) * temp_j",
"+ return temp % mod",
"+",
"+ for i in range(N):",
"+ ans = (ans + calc(i)) % mod",
"+ ans = (ans * pow(2, N, mod)) % mod",
"+ print(ans)",
"+",
"+",
"+main()"
]
| false | 0.033937 | 0.033666 | 1.008026 | [
"s133661373",
"s414325220"
]
|
u270886147 | p02707 | python | s279548635 | s436188798 | 185 | 153 | 32,408 | 32,192 | Accepted | Accepted | 17.3 | N = int(eval(input()))
A = list(map(int,input().strip().split()))
M = [0] * N
for i in range(0, len(A)):
M[(A[i]-1)] += 1
i += 1
for j in range(0, N):
print((M[j]))
j += 1
| N = int(eval(input()))
A = list(map(int,input().strip().split()))
M = [0] * N
for i in range(0, len(A)):
M[(A[i]-1)] += 1
for j in range(0, N):
print((M[j]))
| 11 | 9 | 192 | 170 | N = int(eval(input()))
A = list(map(int, input().strip().split()))
M = [0] * N
for i in range(0, len(A)):
M[(A[i] - 1)] += 1
i += 1
for j in range(0, N):
print((M[j]))
j += 1
| N = int(eval(input()))
A = list(map(int, input().strip().split()))
M = [0] * N
for i in range(0, len(A)):
M[(A[i] - 1)] += 1
for j in range(0, N):
print((M[j]))
| false | 18.181818 | [
"- i += 1",
"- j += 1"
]
| false | 0.060111 | 0.036822 | 1.632463 | [
"s279548635",
"s436188798"
]
|
u461993794 | p02631 | python | s458434616 | s852645430 | 292 | 157 | 116,268 | 121,844 | Accepted | Accepted | 46.23 | n = int(eval(input()))
a = list(map(int, input().split()))
b = a[0]
for v in a[1:]:
b ^= v
print((*[x ^ b for x in a]))
| from functools import reduce
n = int(eval(input()))
a = list(map(int, input().split()))
b = reduce(lambda acc, x: acc ^ x, a[1:], a[0])
print((*[x ^ b for x in a]))
| 7 | 7 | 128 | 170 | n = int(eval(input()))
a = list(map(int, input().split()))
b = a[0]
for v in a[1:]:
b ^= v
print((*[x ^ b for x in a]))
| from functools import reduce
n = int(eval(input()))
a = list(map(int, input().split()))
b = reduce(lambda acc, x: acc ^ x, a[1:], a[0])
print((*[x ^ b for x in a]))
| false | 0 | [
"+from functools import reduce",
"+",
"-b = a[0]",
"-for v in a[1:]:",
"- b ^= v",
"+b = reduce(lambda acc, x: acc ^ x, a[1:], a[0])"
]
| false | 0.104275 | 0.091953 | 1.134 | [
"s458434616",
"s852645430"
]
|
u991567869 | p03730 | python | s822189468 | s348108636 | 20 | 17 | 3,064 | 2,940 | Accepted | Accepted | 15 | a, b, c = list(map(int, input().split()))
for i in range(10000):
if (a*i)%b == c:
print("YES")
exit()
print("NO") | a, b, c = list(map(int, input().split()))
for i in range(b):
if (a*i)%b == c:
print("YES")
exit()
print("NO") | 9 | 9 | 138 | 134 | a, b, c = list(map(int, input().split()))
for i in range(10000):
if (a * i) % b == c:
print("YES")
exit()
print("NO")
| a, b, c = list(map(int, input().split()))
for i in range(b):
if (a * i) % b == c:
print("YES")
exit()
print("NO")
| false | 0 | [
"-for i in range(10000):",
"+for i in range(b):"
]
| false | 0.036008 | 0.037649 | 0.956426 | [
"s822189468",
"s348108636"
]
|
u396518935 | p02972 | python | s633632094 | s658710581 | 281 | 247 | 18,764 | 19,396 | Accepted | Accepted | 12.1 | N = int(eval(input()))
A = list(map(int, input().split()))
B = [0 for n in range(N+1)]
x = []
for n in range(N):
i = N-n
# print(i)
BB = B[::i]
if (sum(BB))%2 == A[i-1]:
B[i] = 0
else:
B[i] = 1
# print(B)
if B[i] == 1:
x.append(str(i))
if len(x) == 0:
print((0))
else:
print((len(x)))
print((' '.join(x))) | N = int(eval(input()))
A = list(map(int, input().split()))
B = [0]*(N+1)
x = []
for n in range(N):
i = N-n
BB = B[::i]
if (sum(BB))%2 == A[i-1]:
B[i] = 0
else:
B[i] = 1
x.append(str(i))
if len(x) == 0:
print((0))
else:
print((len(x)))
print((' '.join(x))) | 22 | 19 | 352 | 291 | N = int(eval(input()))
A = list(map(int, input().split()))
B = [0 for n in range(N + 1)]
x = []
for n in range(N):
i = N - n
# print(i)
BB = B[::i]
if (sum(BB)) % 2 == A[i - 1]:
B[i] = 0
else:
B[i] = 1
# print(B)
if B[i] == 1:
x.append(str(i))
if len(x) == 0:
print((0))
else:
print((len(x)))
print((" ".join(x)))
| N = int(eval(input()))
A = list(map(int, input().split()))
B = [0] * (N + 1)
x = []
for n in range(N):
i = N - n
BB = B[::i]
if (sum(BB)) % 2 == A[i - 1]:
B[i] = 0
else:
B[i] = 1
x.append(str(i))
if len(x) == 0:
print((0))
else:
print((len(x)))
print((" ".join(x)))
| false | 13.636364 | [
"-B = [0 for n in range(N + 1)]",
"+B = [0] * (N + 1)",
"- # print(i)",
"- # print(B)",
"- if B[i] == 1:"
]
| false | 0.155633 | 0.156173 | 0.996545 | [
"s633632094",
"s658710581"
]
|
u077291787 | p03095 | python | s804229669 | s374741849 | 27 | 22 | 3,812 | 3,188 | Accepted | Accepted | 18.52 | # AGC031A - Colorful Subsequence
from functools import reduce
def main():
_ = int(eval(input()))
S = input().rstrip()
MOD = 10 ** 9 + 7
C = [S.count(i) + 1 for i in set(S)]
ans = reduce(lambda x, y: (x * y) % MOD, C)
print((ans - 1))
if __name__ == "__main__":
main() | # AGC031A - Colorful Subsequence
def main():
_ = int(eval(input()))
S = input().rstrip()
MOD = 10 ** 9 + 7
ans = 1
for i in set(S):
ans *= S.count(i) + 1
print((ans % MOD - 1))
if __name__ == "__main__":
main() | 15 | 13 | 305 | 252 | # AGC031A - Colorful Subsequence
from functools import reduce
def main():
_ = int(eval(input()))
S = input().rstrip()
MOD = 10**9 + 7
C = [S.count(i) + 1 for i in set(S)]
ans = reduce(lambda x, y: (x * y) % MOD, C)
print((ans - 1))
if __name__ == "__main__":
main()
| # AGC031A - Colorful Subsequence
def main():
_ = int(eval(input()))
S = input().rstrip()
MOD = 10**9 + 7
ans = 1
for i in set(S):
ans *= S.count(i) + 1
print((ans % MOD - 1))
if __name__ == "__main__":
main()
| false | 13.333333 | [
"-from functools import reduce",
"-",
"-",
"- C = [S.count(i) + 1 for i in set(S)]",
"- ans = reduce(lambda x, y: (x * y) % MOD, C)",
"- print((ans - 1))",
"+ ans = 1",
"+ for i in set(S):",
"+ ans *= S.count(i) + 1",
"+ print((ans % MOD - 1))"
]
| false | 0.046116 | 0.049708 | 0.927737 | [
"s804229669",
"s374741849"
]
|
u681444474 | p03775 | python | s908193717 | s111776341 | 184 | 30 | 38,512 | 3,060 | Accepted | Accepted | 83.7 | # coding: utf-8
# Your code here!
import math
N=int(eval(input()))
n=int(math.sqrt(N))
dev=0
for i in range(1,n+1):
if N%i==0:
dev=i
print((max(len(str(dev)),len(str(N//dev))))) | #codng utf-8
import math
N=int(eval(input()))
n=int(math.sqrt(N))
for i in range(n,0,-1):
if N%i==0:
ans=max(len(str(i)),len(str(N//i)))
break
print(ans) | 10 | 9 | 190 | 175 | # coding: utf-8
# Your code here!
import math
N = int(eval(input()))
n = int(math.sqrt(N))
dev = 0
for i in range(1, n + 1):
if N % i == 0:
dev = i
print((max(len(str(dev)), len(str(N // dev)))))
| # codng utf-8
import math
N = int(eval(input()))
n = int(math.sqrt(N))
for i in range(n, 0, -1):
if N % i == 0:
ans = max(len(str(i)), len(str(N // i)))
break
print(ans)
| false | 10 | [
"-# coding: utf-8",
"-# Your code here!",
"+# codng utf-8",
"-dev = 0",
"-for i in range(1, n + 1):",
"+for i in range(n, 0, -1):",
"- dev = i",
"-print((max(len(str(dev)), len(str(N // dev)))))",
"+ ans = max(len(str(i)), len(str(N // i)))",
"+ break",
"+print(ans)"
]
| false | 0.047415 | 0.038226 | 1.240414 | [
"s908193717",
"s111776341"
]
|
u810356688 | p03166 | python | s715327044 | s863037127 | 995 | 480 | 150,728 | 72,384 | Accepted | Accepted | 51.76 | import sys
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache
sys.setrecursionlimit(10**6)
@lru_cache(maxsize=None)
def rec(v):
res=0
for nv in graph[v]:
res=max(res,rec(nv)+1)
return res
def main():
n,m=list(map(int,input().split()))
XY=[tuple(map(int,input().split())) for i in range(m)]
global graph
graph=[[]for _ in range(n)]
for x,y in XY:
graph[x-1].append(y-1)
ans=0
for v in range(n):
ans=max(ans,rec(v))
print(ans)
if __name__=='__main__':
main() | import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
def rec(v):
if dp[v]!=-1:return dp[v]
res=0
for nv in graph[v]:
res=max(res,rec(nv)+1)
dp[v]=res
return res
def main():
n,m=list(map(int,input().split()))
XY=[tuple(map(int,input().split())) for i in range(m)]
global dp,graph
graph=[[]for _ in range(n)]
for x,y in XY:
graph[x-1].append(y-1)
dp=[-1]*n #頂点i(0-)を始点としたときの有効パスの長さの最大値
ans=0
for v in range(n):
ans=max(ans,rec(v))
print(ans)
if __name__=='__main__':
main()
| 24 | 25 | 577 | 612 | import sys
def input():
return sys.stdin.readline().rstrip()
from functools import lru_cache
sys.setrecursionlimit(10**6)
@lru_cache(maxsize=None)
def rec(v):
res = 0
for nv in graph[v]:
res = max(res, rec(nv) + 1)
return res
def main():
n, m = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(m)]
global graph
graph = [[] for _ in range(n)]
for x, y in XY:
graph[x - 1].append(y - 1)
ans = 0
for v in range(n):
ans = max(ans, rec(v))
print(ans)
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
def rec(v):
if dp[v] != -1:
return dp[v]
res = 0
for nv in graph[v]:
res = max(res, rec(nv) + 1)
dp[v] = res
return res
def main():
n, m = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(m)]
global dp, graph
graph = [[] for _ in range(n)]
for x, y in XY:
graph[x - 1].append(y - 1)
dp = [-1] * n # 頂点i(0-)を始点としたときの有効パスの長さの最大値
ans = 0
for v in range(n):
ans = max(ans, rec(v))
print(ans)
if __name__ == "__main__":
main()
| false | 4 | [
"-from functools import lru_cache",
"-",
"-@lru_cache(maxsize=None)",
"+ if dp[v] != -1:",
"+ return dp[v]",
"+ dp[v] = res",
"- global graph",
"+ global dp, graph",
"+ dp = [-1] * n # 頂点i(0-)を始点としたときの有効パスの長さの最大値"
]
| false | 0.095815 | 0.041177 | 2.326903 | [
"s715327044",
"s863037127"
]
|
u896451538 | p02767 | python | s793068456 | s986640343 | 40 | 21 | 5,040 | 3,060 | Accepted | Accepted | 47.5 | import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy
sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return eval(input())
n = I()
x = LI()
mx = max(x)
mn = min(x)
ans = inf
for i in range(mn,mx+1):
tmp = 0
for j in x:
tmp+=(j-i)**2
ans = min(ans,tmp)
print(ans) | n = int(eval(input()))
x = list(map(int,input().split()))
ans = 10**9+7
for i in range(min(x),max(x)+1):
tmp=0
for j in x:
tmp+=(i-j)**2
ans = min(ans,tmp)
print(ans) | 35 | 10 | 797 | 190 | import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy
sys.setrecursionlimit(10**9)
mod = 10**7 + 9
inf = 10**20
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI():
return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return eval(input())
n = I()
x = LI()
mx = max(x)
mn = min(x)
ans = inf
for i in range(mn, mx + 1):
tmp = 0
for j in x:
tmp += (j - i) ** 2
ans = min(ans, tmp)
print(ans)
| n = int(eval(input()))
x = list(map(int, input().split()))
ans = 10**9 + 7
for i in range(min(x), max(x) + 1):
tmp = 0
for j in x:
tmp += (i - j) ** 2
ans = min(ans, tmp)
print(ans)
| false | 71.428571 | [
"-import math",
"-import itertools",
"-import fractions",
"-import heapq",
"-import collections",
"-import bisect",
"-import sys",
"-import copy",
"-",
"-sys.setrecursionlimit(10**9)",
"-mod = 10**7 + 9",
"-inf = 10**20",
"-",
"-",
"-def LI():",
"- return list(map(int, sys.stdin.readline().split()))",
"-",
"-",
"-def LLI():",
"- return [list(map(int, l.split())) for l in sys.stdin.readlines()]",
"-",
"-",
"-def LI_():",
"- return [int(x) - 1 for x in sys.stdin.readline().split()]",
"-",
"-",
"-def LF():",
"- return [float(x) for x in sys.stdin.readline().split()]",
"-",
"-",
"-def LS():",
"- return sys.stdin.readline().split()",
"-",
"-",
"-def I():",
"- return int(sys.stdin.readline())",
"-",
"-",
"-def F():",
"- return float(sys.stdin.readline())",
"-",
"-",
"-def S():",
"- return eval(input())",
"-",
"-",
"-n = I()",
"-x = LI()",
"-mx = max(x)",
"-mn = min(x)",
"-ans = inf",
"-for i in range(mn, mx + 1):",
"+n = int(eval(input()))",
"+x = list(map(int, input().split()))",
"+ans = 10**9 + 7",
"+for i in range(min(x), max(x) + 1):",
"- tmp += (j - i) ** 2",
"+ tmp += (i - j) ** 2"
]
| false | 0.037696 | 0.037441 | 1.006794 | [
"s793068456",
"s986640343"
]
|
u125545880 | p02756 | python | s498655238 | s734708959 | 1,612 | 471 | 4,412 | 5,740 | Accepted | Accepted | 70.78 | # 文字列の操作だけでできるか
S = eval(input())
Q = int(eval(input()))
T = 0
l = ""
r = ""
for i in range(Q):
Query = list(input().split())
if len(Query) == 1:
# T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0)
T ^= 1
elif T == 0:
s = Query[2]
if Query[1] == '1':
#S = s + S
l = s + l
else:
#S = S + s
r = r + s
else:
s = Query[2]
if Query[1] == '1':
#S = S + s
r = r + s
else:
#S = s + S
l = s + l
S = l + S + r
if T == 1:
S = S[::-1]
print(S)
| # list の append だけで実装する
S = eval(input())
Q = int(eval(input()))
T = 0
l = []
r = []
for _ in range(Q):
Query = list(input().split())
if len(Query) == 1:
T ^= 1
elif T == 0:
s = Query[2]
if Query[1] == '1':
l.append(s)
else:
r.append(s)
else:
s = Query[2]
if Query[1] == '1':
r.append(s)
else:
l.append(s)
if T == 1:
r.reverse()
ans = ''.join(r) + S[::-1] + ''.join(l)
else:
l.reverse()
ans = ''.join(l) + S + ''.join(r)
print(ans)
| 36 | 33 | 635 | 592 | # 文字列の操作だけでできるか
S = eval(input())
Q = int(eval(input()))
T = 0
l = ""
r = ""
for i in range(Q):
Query = list(input().split())
if len(Query) == 1:
# T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0)
T ^= 1
elif T == 0:
s = Query[2]
if Query[1] == "1":
# S = s + S
l = s + l
else:
# S = S + s
r = r + s
else:
s = Query[2]
if Query[1] == "1":
# S = S + s
r = r + s
else:
# S = s + S
l = s + l
S = l + S + r
if T == 1:
S = S[::-1]
print(S)
| # list の append だけで実装する
S = eval(input())
Q = int(eval(input()))
T = 0
l = []
r = []
for _ in range(Q):
Query = list(input().split())
if len(Query) == 1:
T ^= 1
elif T == 0:
s = Query[2]
if Query[1] == "1":
l.append(s)
else:
r.append(s)
else:
s = Query[2]
if Query[1] == "1":
r.append(s)
else:
l.append(s)
if T == 1:
r.reverse()
ans = "".join(r) + S[::-1] + "".join(l)
else:
l.reverse()
ans = "".join(l) + S + "".join(r)
print(ans)
| false | 8.333333 | [
"-# 文字列の操作だけでできるか",
"+# list の append だけで実装する",
"-l = \"\"",
"-r = \"\"",
"-for i in range(Q):",
"+l = []",
"+r = []",
"+for _ in range(Q):",
"- # T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0)",
"- # S = s + S",
"- l = s + l",
"+ l.append(s)",
"- # S = S + s",
"- r = r + s",
"+ r.append(s)",
"- # S = S + s",
"- r = r + s",
"+ r.append(s)",
"- # S = s + S",
"- l = s + l",
"-S = l + S + r",
"+ l.append(s)",
"- S = S[::-1]",
"-print(S)",
"+ r.reverse()",
"+ ans = \"\".join(r) + S[::-1] + \"\".join(l)",
"+else:",
"+ l.reverse()",
"+ ans = \"\".join(l) + S + \"\".join(r)",
"+print(ans)"
]
| false | 0.037366 | 0.062839 | 0.594637 | [
"s498655238",
"s734708959"
]
|
u200887663 | p03087 | python | s395665890 | s076724027 | 865 | 479 | 6,828 | 13,024 | Accepted | Accepted | 44.62 | #n=int(input())
n,q=list(map(int,input().split()))
s=list(eval(input()))
#bl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
count=[0]*n
for i in range(1,n):
st=s[i-1:i+1]
if st==["A","C"]:
count[i]=count[i-1]+1
else:
count[i]=count[i-1]
for i in range(q):
l,r=list(map(int,input().split()))
print((count[r-1]-count[l-1]))
| #n = int(input())
n, q = list(map(int, input().split()))
#bl = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
s = eval(input())
acnum = [0]*(n+1)
for i in range(2, n+1):
if s[i-2:i] == 'AC':
acnum[i] += acnum[i-1]+1
else:
acnum[i] += acnum[i-1]
for i in range(q):
l, r = list(map(int, input().split()))
print((acnum[r]-acnum[l]))
| 19 | 15 | 398 | 380 | # n=int(input())
n, q = list(map(int, input().split()))
s = list(eval(input()))
# bl=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
count = [0] * n
for i in range(1, n):
st = s[i - 1 : i + 1]
if st == ["A", "C"]:
count[i] = count[i - 1] + 1
else:
count[i] = count[i - 1]
for i in range(q):
l, r = list(map(int, input().split()))
print((count[r - 1] - count[l - 1]))
| # n = int(input())
n, q = list(map(int, input().split()))
# bl = list(map(int, input().split()))
# al=[list(input()) for i in range(n)]
s = eval(input())
acnum = [0] * (n + 1)
for i in range(2, n + 1):
if s[i - 2 : i] == "AC":
acnum[i] += acnum[i - 1] + 1
else:
acnum[i] += acnum[i - 1]
for i in range(q):
l, r = list(map(int, input().split()))
print((acnum[r] - acnum[l]))
| false | 21.052632 | [
"-# n=int(input())",
"+# n = int(input())",
"-s = list(eval(input()))",
"-# bl=list(map(int,input().split()))",
"-# l=[list(map(int,input().split())) for i in range(n)]",
"-count = [0] * n",
"-for i in range(1, n):",
"- st = s[i - 1 : i + 1]",
"- if st == [\"A\", \"C\"]:",
"- count[i] = count[i - 1] + 1",
"+# bl = list(map(int, input().split()))",
"+# al=[list(input()) for i in range(n)]",
"+s = eval(input())",
"+acnum = [0] * (n + 1)",
"+for i in range(2, n + 1):",
"+ if s[i - 2 : i] == \"AC\":",
"+ acnum[i] += acnum[i - 1] + 1",
"- count[i] = count[i - 1]",
"+ acnum[i] += acnum[i - 1]",
"- print((count[r - 1] - count[l - 1]))",
"+ print((acnum[r] - acnum[l]))"
]
| false | 0.057338 | 0.05508 | 1.040993 | [
"s395665890",
"s076724027"
]
|
u084320347 | p03105 | python | s679075579 | s419777144 | 164 | 17 | 38,256 | 2,940 | Accepted | Accepted | 89.63 | a,b,c = list(map(int,input().split()))
sound_max = b//a
if c >= sound_max:
print(sound_max)
elif c <= sound_max:
print(c)
| a,b,c = list(map(int,input().split()))
if b//a >= c:
print(c)
else:
print((b//a)) | 11 | 5 | 145 | 91 | a, b, c = list(map(int, input().split()))
sound_max = b // a
if c >= sound_max:
print(sound_max)
elif c <= sound_max:
print(c)
| a, b, c = list(map(int, input().split()))
if b // a >= c:
print(c)
else:
print((b // a))
| false | 54.545455 | [
"-sound_max = b // a",
"-if c >= sound_max:",
"- print(sound_max)",
"-elif c <= sound_max:",
"+if b // a >= c:",
"+else:",
"+ print((b // a))"
]
| false | 0.069983 | 0.037273 | 1.877583 | [
"s679075579",
"s419777144"
]
|
u037430802 | p02936 | python | s349142152 | s220692192 | 1,908 | 1,708 | 62,572 | 56,180 | Accepted | Accepted | 10.48 | N,Q = list(map(int, input().split()))
es = [[] for _ in range(N)]
for i in range(N-1):
a,b = list(map(int, input().split()))
es[a-1].append(b-1)
es[b-1].append(a-1)
ans = [0] * N
px = [0] * N
for i in range(Q):
p, x = list(map(int, input().split()))
px[p-1] += x
visited = [False] * N
stack = [0]
while stack:
i = stack.pop()
ans[i] += px[i]
visited[i] = True
for j in es[i]:
#print(i,j,es)
if visited[j] == False:
ans[j] += ans[i]
stack.append(j)
print((*ans)) |
from collections import deque
N,Q = list(map(int, input().split()))
es = [[] for _ in range(N)]
for i in range(N-1):
a,b = list(map(int, input().split()))
es[a-1].append(b-1)
es[b-1].append(a-1)
ans = [0] * N
for _ in range(Q):
p,x = list(map(int, input().split()))
ans[p-1] += x
checked = [False] * N
q = deque()
q.append(0)
while q:
node = q.popleft()
checked[node] = True
for nxt in es[node]:
if not checked[nxt]:
ans[nxt] += ans[node]
q.append(nxt)
print((*ans)) | 31 | 29 | 559 | 553 | N, Q = list(map(int, input().split()))
es = [[] for _ in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
es[a - 1].append(b - 1)
es[b - 1].append(a - 1)
ans = [0] * N
px = [0] * N
for i in range(Q):
p, x = list(map(int, input().split()))
px[p - 1] += x
visited = [False] * N
stack = [0]
while stack:
i = stack.pop()
ans[i] += px[i]
visited[i] = True
for j in es[i]:
# print(i,j,es)
if visited[j] == False:
ans[j] += ans[i]
stack.append(j)
print((*ans))
| from collections import deque
N, Q = list(map(int, input().split()))
es = [[] for _ in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
es[a - 1].append(b - 1)
es[b - 1].append(a - 1)
ans = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
ans[p - 1] += x
checked = [False] * N
q = deque()
q.append(0)
while q:
node = q.popleft()
checked[node] = True
for nxt in es[node]:
if not checked[nxt]:
ans[nxt] += ans[node]
q.append(nxt)
print((*ans))
| false | 6.451613 | [
"+from collections import deque",
"+",
"-px = [0] * N",
"-for i in range(Q):",
"+for _ in range(Q):",
"- px[p - 1] += x",
"-visited = [False] * N",
"-stack = [0]",
"-while stack:",
"- i = stack.pop()",
"- ans[i] += px[i]",
"- visited[i] = True",
"- for j in es[i]:",
"- # print(i,j,es)",
"- if visited[j] == False:",
"- ans[j] += ans[i]",
"- stack.append(j)",
"+ ans[p - 1] += x",
"+checked = [False] * N",
"+q = deque()",
"+q.append(0)",
"+while q:",
"+ node = q.popleft()",
"+ checked[node] = True",
"+ for nxt in es[node]:",
"+ if not checked[nxt]:",
"+ ans[nxt] += ans[node]",
"+ q.append(nxt)"
]
| false | 0.05656 | 0.069096 | 0.818563 | [
"s349142152",
"s220692192"
]
|
u188827677 | p03293 | python | s601173573 | s473581823 | 30 | 26 | 9,348 | 9,096 | Accepted | Accepted | 13.33 | from collections import deque
s = deque(list(eval(input())))
t = deque(list(eval(input())))
for i in range(len(s)+1):
if s == t:
print("Yes")
exit()
p = s.pop()
s.appendleft(p)
print("No") | s = eval(input())
t = eval(input())
n = 0
m = len(s)
while n != m:
if s == t:
print("Yes")
exit()
s = s[-1]+s[:m-1]
n += 1
print("No") | 11 | 12 | 201 | 148 | from collections import deque
s = deque(list(eval(input())))
t = deque(list(eval(input())))
for i in range(len(s) + 1):
if s == t:
print("Yes")
exit()
p = s.pop()
s.appendleft(p)
print("No")
| s = eval(input())
t = eval(input())
n = 0
m = len(s)
while n != m:
if s == t:
print("Yes")
exit()
s = s[-1] + s[: m - 1]
n += 1
print("No")
| false | 8.333333 | [
"-from collections import deque",
"-",
"-s = deque(list(eval(input())))",
"-t = deque(list(eval(input())))",
"-for i in range(len(s) + 1):",
"+s = eval(input())",
"+t = eval(input())",
"+n = 0",
"+m = len(s)",
"+while n != m:",
"- p = s.pop()",
"- s.appendleft(p)",
"+ s = s[-1] + s[: m - 1]",
"+ n += 1"
]
| false | 0.039257 | 0.036409 | 1.078239 | [
"s601173573",
"s473581823"
]
|
u711238850 | p02754 | python | s855916254 | s372022343 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | import math
from collections import deque
def main():
n,a,b = tuple([int(t)for t in input().split()])
if b == 0:
print(n)
else:
t = a+b
res = (n // t)*a+min(n%t,a)
print(res)
if __name__ == "__main__":
main() | n,a,b = tuple(map(int,input().split()))
ans = n//(a+b)*a
ans += min(n%(a+b),a)
print(ans) | 13 | 7 | 270 | 98 | import math
from collections import deque
def main():
n, a, b = tuple([int(t) for t in input().split()])
if b == 0:
print(n)
else:
t = a + b
res = (n // t) * a + min(n % t, a)
print(res)
if __name__ == "__main__":
main()
| n, a, b = tuple(map(int, input().split()))
ans = n // (a + b) * a
ans += min(n % (a + b), a)
print(ans)
| false | 46.153846 | [
"-import math",
"-from collections import deque",
"-",
"-",
"-def main():",
"- n, a, b = tuple([int(t) for t in input().split()])",
"- if b == 0:",
"- print(n)",
"- else:",
"- t = a + b",
"- res = (n // t) * a + min(n % t, a)",
"- print(res)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+n, a, b = tuple(map(int, input().split()))",
"+ans = n // (a + b) * a",
"+ans += min(n % (a + b), a)",
"+print(ans)"
]
| false | 0.087605 | 0.03239 | 2.704688 | [
"s855916254",
"s372022343"
]
|
u708255304 | p02659 | python | s892120914 | s790829194 | 23 | 21 | 9,164 | 9,100 | Accepted | Accepted | 8.7 | A, B = list(map(str, input().split()))
A = int(A)
B = B.replace(".", "")
B = int(B)
print((A*B//100))
| A, B = list(map(str, input().split()))
A = int(A)
B = B.replace(".", "")
B = int(B)
print(((A*B)//100))
| 5 | 5 | 98 | 100 | A, B = list(map(str, input().split()))
A = int(A)
B = B.replace(".", "")
B = int(B)
print((A * B // 100))
| A, B = list(map(str, input().split()))
A = int(A)
B = B.replace(".", "")
B = int(B)
print(((A * B) // 100))
| false | 0 | [
"-print((A * B // 100))",
"+print(((A * B) // 100))"
]
| false | 0.041497 | 0.035082 | 1.182872 | [
"s892120914",
"s790829194"
]
|
u887207211 | p03240 | python | s178279122 | s090760870 | 36 | 30 | 3,064 | 3,064 | Accepted | Accepted | 16.67 | N = int(eval(input()))
xyh = [list(map(int,input().split())) for _ in range(N)]
xyh = sorted(xyh, key = lambda x:-x[2])
mx, my, mh = xyh[0]
for Cx in range(101):
for Cy in range(101):
H = mh+abs(mx-Cx)+abs(my-Cy)
if(all(h == max(0, H-abs(x-Cx)-abs(y-Cy)) for x,y,h in xyh)):
print((Cx,Cy,H))
exit() | from operator import itemgetter
N = int(eval(input()))
xyh = [[int(i) for i in input().split()] for _ in range(N)]
xyh.sort(key = itemgetter(2))
tx, ty, th = xyh[-1]
for Cx in range(101):
for Cy in range(101):
H = th + abs(tx-Cx) + abs(ty-Cy)
if all(h == max(H-abs(x-Cx)-abs(y-Cy), 0) for x, y, h in xyh):
print((Cx, Cy, H))
exit() | 10 | 13 | 321 | 359 | N = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh = sorted(xyh, key=lambda x: -x[2])
mx, my, mh = xyh[0]
for Cx in range(101):
for Cy in range(101):
H = mh + abs(mx - Cx) + abs(my - Cy)
if all(h == max(0, H - abs(x - Cx) - abs(y - Cy)) for x, y, h in xyh):
print((Cx, Cy, H))
exit()
| from operator import itemgetter
N = int(eval(input()))
xyh = [[int(i) for i in input().split()] for _ in range(N)]
xyh.sort(key=itemgetter(2))
tx, ty, th = xyh[-1]
for Cx in range(101):
for Cy in range(101):
H = th + abs(tx - Cx) + abs(ty - Cy)
if all(h == max(H - abs(x - Cx) - abs(y - Cy), 0) for x, y, h in xyh):
print((Cx, Cy, H))
exit()
| false | 23.076923 | [
"+from operator import itemgetter",
"+",
"-xyh = [list(map(int, input().split())) for _ in range(N)]",
"-xyh = sorted(xyh, key=lambda x: -x[2])",
"-mx, my, mh = xyh[0]",
"+xyh = [[int(i) for i in input().split()] for _ in range(N)]",
"+xyh.sort(key=itemgetter(2))",
"+tx, ty, th = xyh[-1]",
"- H = mh + abs(mx - Cx) + abs(my - Cy)",
"- if all(h == max(0, H - abs(x - Cx) - abs(y - Cy)) for x, y, h in xyh):",
"+ H = th + abs(tx - Cx) + abs(ty - Cy)",
"+ if all(h == max(H - abs(x - Cx) - abs(y - Cy), 0) for x, y, h in xyh):"
]
| false | 0.052127 | 0.047021 | 1.108599 | [
"s178279122",
"s090760870"
]
|
u919633157 | p03998 | python | s767300895 | s169167163 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | from collections import deque
a=deque(list(eval(input())))
b=deque(list(eval(input())))
c=deque(list(eval(input())))
tmp=a.popleft()
while 1:
if tmp=='a':
if not len(a):
print('A')
break
tmp=a.popleft()
elif tmp=='b':
if not len(b):
print('B')
break
tmp=b.popleft()
else:
if not len(c):
print('C')
break
tmp=c.popleft()
| s={i:list(eval(input())) for i in 'abc'}
tmp='a'
while s[tmp]:
tmp=s[tmp].pop(0)
print((tmp.upper()))
# (#4130525) | 21 | 7 | 454 | 117 | from collections import deque
a = deque(list(eval(input())))
b = deque(list(eval(input())))
c = deque(list(eval(input())))
tmp = a.popleft()
while 1:
if tmp == "a":
if not len(a):
print("A")
break
tmp = a.popleft()
elif tmp == "b":
if not len(b):
print("B")
break
tmp = b.popleft()
else:
if not len(c):
print("C")
break
tmp = c.popleft()
| s = {i: list(eval(input())) for i in "abc"}
tmp = "a"
while s[tmp]:
tmp = s[tmp].pop(0)
print((tmp.upper()))
# (#4130525)
| false | 66.666667 | [
"-from collections import deque",
"-",
"-a = deque(list(eval(input())))",
"-b = deque(list(eval(input())))",
"-c = deque(list(eval(input())))",
"-tmp = a.popleft()",
"-while 1:",
"- if tmp == \"a\":",
"- if not len(a):",
"- print(\"A\")",
"- break",
"- tmp = a.popleft()",
"- elif tmp == \"b\":",
"- if not len(b):",
"- print(\"B\")",
"- break",
"- tmp = b.popleft()",
"- else:",
"- if not len(c):",
"- print(\"C\")",
"- break",
"- tmp = c.popleft()",
"+s = {i: list(eval(input())) for i in \"abc\"}",
"+tmp = \"a\"",
"+while s[tmp]:",
"+ tmp = s[tmp].pop(0)",
"+print((tmp.upper()))",
"+# (#4130525)"
]
| false | 0.03852 | 0.042114 | 0.91465 | [
"s767300895",
"s169167163"
]
|
u039864635 | p02785 | python | s183369959 | s538996080 | 162 | 148 | 26,180 | 26,024 | Accepted | Accepted | 8.64 | n, k = list(map(int, input().split()))
h = [int(x) for x in input().split()]
if len(h) <= k:
print((0))
else:
sorted_h = sorted(h, reverse=True)
print((sum(sorted_h[k:]))) | def find_minimum_normal_attack(monster_num, special_move_num, monster_healths):
return sum(sorted(monster_healths, reverse=True)[special_move_num:])
if __name__ == '__main__':
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
print((find_minimum_normal_attack(n, k, h)))
| 9 | 8 | 183 | 313 | n, k = list(map(int, input().split()))
h = [int(x) for x in input().split()]
if len(h) <= k:
print((0))
else:
sorted_h = sorted(h, reverse=True)
print((sum(sorted_h[k:])))
| def find_minimum_normal_attack(monster_num, special_move_num, monster_healths):
return sum(sorted(monster_healths, reverse=True)[special_move_num:])
if __name__ == "__main__":
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
print((find_minimum_normal_attack(n, k, h)))
| false | 11.111111 | [
"-n, k = list(map(int, input().split()))",
"-h = [int(x) for x in input().split()]",
"-if len(h) <= k:",
"- print((0))",
"-else:",
"- sorted_h = sorted(h, reverse=True)",
"- print((sum(sorted_h[k:])))",
"+def find_minimum_normal_attack(monster_num, special_move_num, monster_healths):",
"+ return sum(sorted(monster_healths, reverse=True)[special_move_num:])",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ n, k = list(map(int, input().split()))",
"+ h = list(map(int, input().split()))",
"+ print((find_minimum_normal_attack(n, k, h)))"
]
| false | 0.080655 | 0.046347 | 1.740224 | [
"s183369959",
"s538996080"
]
|
u185896732 | p02657 | python | s483962216 | s659214771 | 108 | 22 | 27,092 | 9,008 | Accepted | Accepted | 79.63 | import numpy
a,b=list(map(int,input().split()))
print((a*b)) | a,b=list(map(int,input().split()))
print((a*b)) | 3 | 2 | 54 | 40 | import numpy
a, b = list(map(int, input().split()))
print((a * b))
| a, b = list(map(int, input().split()))
print((a * b))
| false | 33.333333 | [
"-import numpy",
"-"
]
| false | 0.034361 | 0.036353 | 0.945195 | [
"s483962216",
"s659214771"
]
|
u254871849 | p02983 | python | s766547775 | s899056858 | 609 | 503 | 3,060 | 75,416 | Accepted | Accepted | 17.41 | # 2019-11-15 13:51:51(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
mod = 2019
def main():
l, r = [int(x) for x in sys.stdin.readline().split()]
if l + 2019 <= r:
m = l + 2018
else:
m = r
minimum = 2018
for i in range(l, m):
for j in range(i+1, m+1):
minimum = min(minimum, i * j % mod)
print(minimum)
if __name__ == "__main__":
main()
| # 2019-11-15 13:51:51(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
mod = 2019
def main():
l, r = [int(x) for x in sys.stdin.readline().split()]
if l + 2019 <= r:
m = l + 2018
else:
m = r
remainders = []
for i in range(l, m):
for j in range(i+1, m+1):
remainders.append(i * j % mod)
print((min(remainders)))
if __name__ == "__main__":
main()
| 34 | 31 | 712 | 712 | # 2019-11-15 13:51:51(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
mod = 2019
def main():
l, r = [int(x) for x in sys.stdin.readline().split()]
if l + 2019 <= r:
m = l + 2018
else:
m = r
minimum = 2018
for i in range(l, m):
for j in range(i + 1, m + 1):
minimum = min(minimum, i * j % mod)
print(minimum)
if __name__ == "__main__":
main()
| # 2019-11-15 13:51:51(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
mod = 2019
def main():
l, r = [int(x) for x in sys.stdin.readline().split()]
if l + 2019 <= r:
m = l + 2018
else:
m = r
remainders = []
for i in range(l, m):
for j in range(i + 1, m + 1):
remainders.append(i * j % mod)
print((min(remainders)))
if __name__ == "__main__":
main()
| false | 8.823529 | [
"-import math",
"-",
"+# import math",
"- minimum = 2018",
"+ remainders = []",
"- minimum = min(minimum, i * j % mod)",
"- print(minimum)",
"+ remainders.append(i * j % mod)",
"+ print((min(remainders)))"
]
| false | 0.069957 | 0.069096 | 1.012453 | [
"s766547775",
"s899056858"
]
|
u945181840 | p03721 | python | s434389852 | s920891247 | 457 | 310 | 25,972 | 25,972 | Accepted | Accepted | 32.17 | N, K = list(map(int, input().split()))
a = [0] * N
b = [0] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a, b = list(zip(*sorted(zip(a, b))))
count = 0
while K > 0:
K -= b[count]
count += 1
print((a[count - 1])) | import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
a = [0] * N
b = [0] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a, b = list(zip(*sorted(zip(a, b))))
count = 0
while K > 0:
K -= b[count]
count += 1
print((a[count - 1])) | 15 | 18 | 243 | 285 | N, K = list(map(int, input().split()))
a = [0] * N
b = [0] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a, b = list(zip(*sorted(zip(a, b))))
count = 0
while K > 0:
K -= b[count]
count += 1
print((a[count - 1]))
| import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
a = [0] * N
b = [0] * N
for i in range(N):
a[i], b[i] = list(map(int, input().split()))
a, b = list(zip(*sorted(zip(a, b))))
count = 0
while K > 0:
K -= b[count]
count += 1
print((a[count - 1]))
| false | 16.666667 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
]
| false | 0.037166 | 0.034946 | 1.063524 | [
"s434389852",
"s920891247"
]
|
u894114233 | p00526 | python | s335416123 | s368555288 | 120 | 90 | 7,708 | 7,804 | Accepted | Accepted | 25 | n=int(input())
il=list(map(int,input().split()))
s=0
t=0
cnt=[]
while t<n-1:
if il[t]==il[t+1]:
cnt.append(t+1-s)
s=t+1
t+=1
if t==n-1:
cnt.append(t+1-s)
ans=0
if len(cnt)<=3:
print((sum(cnt)))
else:
for i in range(len(cnt)-2):
ans=max(ans,cnt[i]+cnt[i+1]+cnt[i+2])
print(ans) | n=int(input())
il=list(map(int,input().split()))
s=0
cnt=[]
for t in range(n):
if t==n-1:
cnt.append(t+1-s)
break
if il[t]==il[t+1]:
cnt.append(t+1-s)
s=t+1
ans=0
if len(cnt)<=3:
print((sum(cnt)))
else:
for i in range(len(cnt)-2):
ans=max(ans,cnt[i]+cnt[i+1]+cnt[i+2])
print(ans) | 19 | 18 | 351 | 358 | n = int(input())
il = list(map(int, input().split()))
s = 0
t = 0
cnt = []
while t < n - 1:
if il[t] == il[t + 1]:
cnt.append(t + 1 - s)
s = t + 1
t += 1
if t == n - 1:
cnt.append(t + 1 - s)
ans = 0
if len(cnt) <= 3:
print((sum(cnt)))
else:
for i in range(len(cnt) - 2):
ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2])
print(ans)
| n = int(input())
il = list(map(int, input().split()))
s = 0
cnt = []
for t in range(n):
if t == n - 1:
cnt.append(t + 1 - s)
break
if il[t] == il[t + 1]:
cnt.append(t + 1 - s)
s = t + 1
ans = 0
if len(cnt) <= 3:
print((sum(cnt)))
else:
for i in range(len(cnt) - 2):
ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2])
print(ans)
| false | 5.263158 | [
"-t = 0",
"-while t < n - 1:",
"+for t in range(n):",
"+ if t == n - 1:",
"+ cnt.append(t + 1 - s)",
"+ break",
"- t += 1",
"- if t == n - 1:",
"- cnt.append(t + 1 - s)"
]
| false | 0.034625 | 0.038174 | 0.90704 | [
"s335416123",
"s368555288"
]
|
u545368057 | p02665 | python | s842958646 | s754468135 | 183 | 78 | 84,508 | 85,964 | Accepted | Accepted | 57.38 | n = int(eval(input()))
As = list(map(int, input().split()))
# ps = [0] * (n+1)
# qs = [0] * (n+1)
# ps[-1] = As[-1]
# qs[-1] = As[-1]
p = As[-1]
q = As[-1]
Asr = As[::-1]
qs = [q]
# 深い方から見ていく
for j,a in enumerate(Asr[1:]):
i = n - (j + 1)
p = (p+1)//2 + a
q = min(q + a, 2**i)
# 最小値が、2**iを超えると、深さ0畳めないのでアウト
if p > 2**i:
print((-1))
exit()
# 2**iを超えない範囲での最大値
qs.append(q)
if p != 1:
print((-1))
exit()
qs.reverse()
qs[0] = 1
ans = 1
for i in range(1,n+1):
if qs[i] > 2**i:
qs[i] = 2 ** i
if qs[i] > 2*(qs[i-1]-As[i-1]):
qs[i] = 2 * (qs[i-1]-As[i-1])
ans += qs[i]
print(ans) | from itertools import accumulate
n = int(eval(input()))
As = list(map(int, input().split()))
if n == 0:
if As[0] == 1:print((1))
else:print((-1))
exit()
if As[0] != 0:
print((-1))
exit()
b = 1
ans = 1
acc = list(accumulate(As))
s = acc[-1]
for ac,a in zip(acc[1:], As[1:]):
# print(s-ac,2*b-a)
b = min(2*b-a, s-ac)
if b < 0:
print((-1))
exit()
ans += b+a
print(ans)
| 40 | 27 | 701 | 438 | n = int(eval(input()))
As = list(map(int, input().split()))
# ps = [0] * (n+1)
# qs = [0] * (n+1)
# ps[-1] = As[-1]
# qs[-1] = As[-1]
p = As[-1]
q = As[-1]
Asr = As[::-1]
qs = [q]
# 深い方から見ていく
for j, a in enumerate(Asr[1:]):
i = n - (j + 1)
p = (p + 1) // 2 + a
q = min(q + a, 2**i)
# 最小値が、2**iを超えると、深さ0畳めないのでアウト
if p > 2**i:
print((-1))
exit()
# 2**iを超えない範囲での最大値
qs.append(q)
if p != 1:
print((-1))
exit()
qs.reverse()
qs[0] = 1
ans = 1
for i in range(1, n + 1):
if qs[i] > 2**i:
qs[i] = 2**i
if qs[i] > 2 * (qs[i - 1] - As[i - 1]):
qs[i] = 2 * (qs[i - 1] - As[i - 1])
ans += qs[i]
print(ans)
| from itertools import accumulate
n = int(eval(input()))
As = list(map(int, input().split()))
if n == 0:
if As[0] == 1:
print((1))
else:
print((-1))
exit()
if As[0] != 0:
print((-1))
exit()
b = 1
ans = 1
acc = list(accumulate(As))
s = acc[-1]
for ac, a in zip(acc[1:], As[1:]):
# print(s-ac,2*b-a)
b = min(2 * b - a, s - ac)
if b < 0:
print((-1))
exit()
ans += b + a
print(ans)
| false | 32.5 | [
"+from itertools import accumulate",
"+",
"-# ps = [0] * (n+1)",
"-# qs = [0] * (n+1)",
"-# ps[-1] = As[-1]",
"-# qs[-1] = As[-1]",
"-p = As[-1]",
"-q = As[-1]",
"-Asr = As[::-1]",
"-qs = [q]",
"-# 深い方から見ていく",
"-for j, a in enumerate(Asr[1:]):",
"- i = n - (j + 1)",
"- p = (p + 1) // 2 + a",
"- q = min(q + a, 2**i)",
"- # 最小値が、2**iを超えると、深さ0畳めないのでアウト",
"- if p > 2**i:",
"+if n == 0:",
"+ if As[0] == 1:",
"+ print((1))",
"+ else:",
"+ print((-1))",
"+ exit()",
"+if As[0] != 0:",
"+ print((-1))",
"+ exit()",
"+b = 1",
"+ans = 1",
"+acc = list(accumulate(As))",
"+s = acc[-1]",
"+for ac, a in zip(acc[1:], As[1:]):",
"+ # print(s-ac,2*b-a)",
"+ b = min(2 * b - a, s - ac)",
"+ if b < 0:",
"- # 2**iを超えない範囲での最大値",
"- qs.append(q)",
"-if p != 1:",
"- print((-1))",
"- exit()",
"-qs.reverse()",
"-qs[0] = 1",
"-ans = 1",
"-for i in range(1, n + 1):",
"- if qs[i] > 2**i:",
"- qs[i] = 2**i",
"- if qs[i] > 2 * (qs[i - 1] - As[i - 1]):",
"- qs[i] = 2 * (qs[i - 1] - As[i - 1])",
"- ans += qs[i]",
"+ ans += b + a"
]
| false | 0.070898 | 0.071125 | 0.99681 | [
"s842958646",
"s754468135"
]
|
u780962115 | p03053 | python | s044136879 | s583266789 | 509 | 333 | 99,036 | 164,788 | Accepted | Accepted | 34.58 | #darker and darker
from collections import deque
d=deque()
e=deque()
h,w=list(map(int,input().split()))
field=[0 for i in range(h+2)]
field[0]=[True for i in range(w+2)]
distance=0
for i in range(h):
s=eval(input())
a=[False for i in range(w+2)]
a[0]=True
for j in range(w):
if s[j]=="#":
a[j+1]=True
d.append((i+1,j+1))
a[w+1]=True
field[i+1]=a
field[h+1]=[True for i in range(w+2)]
while d:
while d:
some=d.popleft()
index1,index2=some[0],some[1]
if field[index1-1][index2]==False:
field[index1-1][index2]=True
e.append((index1-1,index2))
if field[index1+1][index2]==False:
field[index1+1][index2]=True
e.append((index1+1,index2))
if field[index1][index2+1]==False:
field[index1][index2+1]=True
e.append((index1,index2+1))
if field[index1][index2-1]==False:
field[index1][index2-1]=True
e.append((index1,index2-1))
distance+=1
d=e
e=deque()
print((distance-1))
| # Review problem
from collections import deque
H, W = list(map(int, input().split()))
D = [list(eval(input())) for i in range(H)]
visited = [[False for i in range(W)] for j in range(H)]
dis = [[0 for i in range(W)] for j in range(H)]
black = deque()
dif = [(-1, 0), (1, 0), (0, 1), (0, -1)]
for i in range(H):
for j in range(W):
if D[i][j] == "#":
visited[i][j] = True
black.append((i, j))
while black:
x, y = black.popleft()
for dx, dy in dif:
if 0 <= dx+x < H and 0 <= dy+y < W and visited[dx+x][dy+y] == False:
visited[dx+x][dy+y] = True
dis[dx+x][dy+y] = dis[x][y]+1
black.append((dx+x, dy+y))
ans = 0
for i in range(H):
for j in range(W):
ans = max(ans, dis[i][j])
print(ans) | 40 | 28 | 1,142 | 798 | # darker and darker
from collections import deque
d = deque()
e = deque()
h, w = list(map(int, input().split()))
field = [0 for i in range(h + 2)]
field[0] = [True for i in range(w + 2)]
distance = 0
for i in range(h):
s = eval(input())
a = [False for i in range(w + 2)]
a[0] = True
for j in range(w):
if s[j] == "#":
a[j + 1] = True
d.append((i + 1, j + 1))
a[w + 1] = True
field[i + 1] = a
field[h + 1] = [True for i in range(w + 2)]
while d:
while d:
some = d.popleft()
index1, index2 = some[0], some[1]
if field[index1 - 1][index2] == False:
field[index1 - 1][index2] = True
e.append((index1 - 1, index2))
if field[index1 + 1][index2] == False:
field[index1 + 1][index2] = True
e.append((index1 + 1, index2))
if field[index1][index2 + 1] == False:
field[index1][index2 + 1] = True
e.append((index1, index2 + 1))
if field[index1][index2 - 1] == False:
field[index1][index2 - 1] = True
e.append((index1, index2 - 1))
distance += 1
d = e
e = deque()
print((distance - 1))
| # Review problem
from collections import deque
H, W = list(map(int, input().split()))
D = [list(eval(input())) for i in range(H)]
visited = [[False for i in range(W)] for j in range(H)]
dis = [[0 for i in range(W)] for j in range(H)]
black = deque()
dif = [(-1, 0), (1, 0), (0, 1), (0, -1)]
for i in range(H):
for j in range(W):
if D[i][j] == "#":
visited[i][j] = True
black.append((i, j))
while black:
x, y = black.popleft()
for dx, dy in dif:
if 0 <= dx + x < H and 0 <= dy + y < W and visited[dx + x][dy + y] == False:
visited[dx + x][dy + y] = True
dis[dx + x][dy + y] = dis[x][y] + 1
black.append((dx + x, dy + y))
ans = 0
for i in range(H):
for j in range(W):
ans = max(ans, dis[i][j])
print(ans)
| false | 30 | [
"-# darker and darker",
"+# Review problem",
"-d = deque()",
"-e = deque()",
"-h, w = list(map(int, input().split()))",
"-field = [0 for i in range(h + 2)]",
"-field[0] = [True for i in range(w + 2)]",
"-distance = 0",
"-for i in range(h):",
"- s = eval(input())",
"- a = [False for i in range(w + 2)]",
"- a[0] = True",
"- for j in range(w):",
"- if s[j] == \"#\":",
"- a[j + 1] = True",
"- d.append((i + 1, j + 1))",
"- a[w + 1] = True",
"- field[i + 1] = a",
"-field[h + 1] = [True for i in range(w + 2)]",
"-while d:",
"- while d:",
"- some = d.popleft()",
"- index1, index2 = some[0], some[1]",
"- if field[index1 - 1][index2] == False:",
"- field[index1 - 1][index2] = True",
"- e.append((index1 - 1, index2))",
"- if field[index1 + 1][index2] == False:",
"- field[index1 + 1][index2] = True",
"- e.append((index1 + 1, index2))",
"- if field[index1][index2 + 1] == False:",
"- field[index1][index2 + 1] = True",
"- e.append((index1, index2 + 1))",
"- if field[index1][index2 - 1] == False:",
"- field[index1][index2 - 1] = True",
"- e.append((index1, index2 - 1))",
"- distance += 1",
"- d = e",
"- e = deque()",
"-print((distance - 1))",
"+H, W = list(map(int, input().split()))",
"+D = [list(eval(input())) for i in range(H)]",
"+visited = [[False for i in range(W)] for j in range(H)]",
"+dis = [[0 for i in range(W)] for j in range(H)]",
"+black = deque()",
"+dif = [(-1, 0), (1, 0), (0, 1), (0, -1)]",
"+for i in range(H):",
"+ for j in range(W):",
"+ if D[i][j] == \"#\":",
"+ visited[i][j] = True",
"+ black.append((i, j))",
"+while black:",
"+ x, y = black.popleft()",
"+ for dx, dy in dif:",
"+ if 0 <= dx + x < H and 0 <= dy + y < W and visited[dx + x][dy + y] == False:",
"+ visited[dx + x][dy + y] = True",
"+ dis[dx + x][dy + y] = dis[x][y] + 1",
"+ black.append((dx + x, dy + y))",
"+ans = 0",
"+for i in range(H):",
"+ for j in range(W):",
"+ ans = max(ans, dis[i][j])",
"+print(ans)"
]
| false | 0.214248 | 0.058879 | 3.638783 | [
"s044136879",
"s583266789"
]
|
u002459665 | p03611 | python | s253048118 | s234798065 | 85 | 68 | 13,964 | 13,964 | Accepted | Accepted | 20 | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
c = [0] * (100000 + 1)
for ai in A:
c[ai] += 1
ans = 0
for i in range(len(c) - 2):
ans = max(ans, c[i] + c[i+1] + c[i+2])
print(ans)
if __name__ == "__main__":
main() | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
c = [0] * (100000 + 2)
for ai in A:
c[ai+1] += 1
c[ai] += 1
c[ai+2] += 1
print((max(c)))
if __name__ == "__main__":
main() | 15 | 14 | 296 | 249 | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
c = [0] * (100000 + 1)
for ai in A:
c[ai] += 1
ans = 0
for i in range(len(c) - 2):
ans = max(ans, c[i] + c[i + 1] + c[i + 2])
print(ans)
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
A = list(map(int, input().split()))
c = [0] * (100000 + 2)
for ai in A:
c[ai + 1] += 1
c[ai] += 1
c[ai + 2] += 1
print((max(c)))
if __name__ == "__main__":
main()
| false | 6.666667 | [
"- c = [0] * (100000 + 1)",
"+ c = [0] * (100000 + 2)",
"+ c[ai + 1] += 1",
"- ans = 0",
"- for i in range(len(c) - 2):",
"- ans = max(ans, c[i] + c[i + 1] + c[i + 2])",
"- print(ans)",
"+ c[ai + 2] += 1",
"+ print((max(c)))"
]
| false | 0.105411 | 0.054035 | 1.950796 | [
"s253048118",
"s234798065"
]
|
u580920947 | p03775 | python | s048419368 | s916575694 | 314 | 178 | 66,540 | 39,152 | Accepted | Accepted | 43.31 | #!/usr/bin/env python
from fractions import gcd
def main():
N = int(eval(input()))
ans = len(str(N))
for i in range(len(str(N)) // 2 + 1):
for j in reversed(list(range(10**i, 10**(i+1)))):
if N % j == 0:
tmp = max(len(str(j)), len(str(N // j)))
if ans > tmp:
ans = tmp
break
print(ans)
if __name__ == '__main__':
main() | #!/usr/bin/env python
import math
def main():
N = int(eval(input()))
ans = len(str(N))
for i in range(1, math.ceil(math.sqrt(N))+1):
if N % i == 0:
tmp = max(len(str(i)), len(str(N // i)))
if ans > tmp:
ans = tmp
print(ans)
if __name__ == '__main__':
main() | 16 | 14 | 455 | 333 | #!/usr/bin/env python
from fractions import gcd
def main():
N = int(eval(input()))
ans = len(str(N))
for i in range(len(str(N)) // 2 + 1):
for j in reversed(list(range(10**i, 10 ** (i + 1)))):
if N % j == 0:
tmp = max(len(str(j)), len(str(N // j)))
if ans > tmp:
ans = tmp
break
print(ans)
if __name__ == "__main__":
main()
| #!/usr/bin/env python
import math
def main():
N = int(eval(input()))
ans = len(str(N))
for i in range(1, math.ceil(math.sqrt(N)) + 1):
if N % i == 0:
tmp = max(len(str(i)), len(str(N // i)))
if ans > tmp:
ans = tmp
print(ans)
if __name__ == "__main__":
main()
| false | 12.5 | [
"-from fractions import gcd",
"+import math",
"- for i in range(len(str(N)) // 2 + 1):",
"- for j in reversed(list(range(10**i, 10 ** (i + 1)))):",
"- if N % j == 0:",
"- tmp = max(len(str(j)), len(str(N // j)))",
"- if ans > tmp:",
"- ans = tmp",
"- break",
"+ for i in range(1, math.ceil(math.sqrt(N)) + 1):",
"+ if N % i == 0:",
"+ tmp = max(len(str(i)), len(str(N // i)))",
"+ if ans > tmp:",
"+ ans = tmp"
]
| false | 0.11282 | 0.041377 | 2.726647 | [
"s048419368",
"s916575694"
]
|
u687053495 | p03128 | python | s052886228 | s826589306 | 176 | 161 | 14,692 | 30,196 | Accepted | Accepted | 8.52 | N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
weight = [0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)
dp[0] = 0
for i in range(N+1):
if dp[i] == -1: continue
for a in A:
if i+weight[a]<N+1:
dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)
print((dp[-1])) |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
numbers = [0,2,5,5,4,5,6,3,7,6]
dp = ["-" for i in range(11000)]
dp[0] = ""
def cal(x, y):
lenx = len(x)
leny = len(y)
if lenx > leny:
return x
if leny > lenx:
return y
return max(x, y)
for i in range(N):
if dp[i] == "-":
continue
for j in range(M):
num = numbers[A[j]]
dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num])
print((dp[N])) | 13 | 29 | 290 | 473 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
weight = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (N + 1)
dp[0] = 0
for i in range(N + 1):
if dp[i] == -1:
continue
for a in A:
if i + weight[a] < N + 1:
dp[i + weight[a]] = max(dp[i + weight[a]], dp[i] * 10 + a)
print((dp[-1]))
| N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
numbers = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = ["-" for i in range(11000)]
dp[0] = ""
def cal(x, y):
lenx = len(x)
leny = len(y)
if lenx > leny:
return x
if leny > lenx:
return y
return max(x, y)
for i in range(N):
if dp[i] == "-":
continue
for j in range(M):
num = numbers[A[j]]
dp[i + num] = cal(dp[i] + str(A[j]), dp[i + num])
print((dp[N]))
| false | 55.172414 | [
"-weight = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]",
"-dp = [-1] * (N + 1)",
"-dp[0] = 0",
"-for i in range(N + 1):",
"- if dp[i] == -1:",
"+numbers = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]",
"+dp = [\"-\" for i in range(11000)]",
"+dp[0] = \"\"",
"+",
"+",
"+def cal(x, y):",
"+ lenx = len(x)",
"+ leny = len(y)",
"+ if lenx > leny:",
"+ return x",
"+ if leny > lenx:",
"+ return y",
"+ return max(x, y)",
"+",
"+",
"+for i in range(N):",
"+ if dp[i] == \"-\":",
"- for a in A:",
"- if i + weight[a] < N + 1:",
"- dp[i + weight[a]] = max(dp[i + weight[a]], dp[i] * 10 + a)",
"-print((dp[-1]))",
"+ for j in range(M):",
"+ num = numbers[A[j]]",
"+ dp[i + num] = cal(dp[i] + str(A[j]), dp[i + num])",
"+print((dp[N]))"
]
| false | 0.078574 | 0.082898 | 0.947846 | [
"s052886228",
"s826589306"
]
|
u476124554 | p03106 | python | s648394828 | s231760647 | 37 | 27 | 4,208 | 3,952 | Accepted | Accepted | 27.03 | import queue
a,b,c = list(map(int,input().split()))
l = list()
for i in range(1,101):
if(a%i == 0 and b%i == 0):
l.append(i)
print((l[len(l)-c])) | import queue
a,b,c = list(map(int,input().split()))
q = queue.LifoQueue()
for i in range(1,101):
if(a%i == 0 and b%i == 0):
q.put(i)
for i in range(c-1):
q.get()
print((q.get())) | 7 | 9 | 149 | 186 | import queue
a, b, c = list(map(int, input().split()))
l = list()
for i in range(1, 101):
if a % i == 0 and b % i == 0:
l.append(i)
print((l[len(l) - c]))
| import queue
a, b, c = list(map(int, input().split()))
q = queue.LifoQueue()
for i in range(1, 101):
if a % i == 0 and b % i == 0:
q.put(i)
for i in range(c - 1):
q.get()
print((q.get()))
| false | 22.222222 | [
"-l = list()",
"+q = queue.LifoQueue()",
"- l.append(i)",
"-print((l[len(l) - c]))",
"+ q.put(i)",
"+for i in range(c - 1):",
"+ q.get()",
"+print((q.get()))"
]
| false | 0.035793 | 0.038631 | 0.926524 | [
"s648394828",
"s231760647"
]
|
u606045429 | p02930 | python | s834620813 | s226832361 | 104 | 83 | 3,952 | 3,952 | Accepted | Accepted | 20.19 | N = int(eval(input()))
for i in range(N):
A = []
for j in range(i + 1, N):
d = i ^ j
A.append((d & -d).bit_length())
print((*A))
| N = int(eval(input()))
for i in range(N):
A = []
for j in range(i + 1, N):
A.append((i ^ j).bit_length())
print((*A))
| 8 | 7 | 157 | 137 | N = int(eval(input()))
for i in range(N):
A = []
for j in range(i + 1, N):
d = i ^ j
A.append((d & -d).bit_length())
print((*A))
| N = int(eval(input()))
for i in range(N):
A = []
for j in range(i + 1, N):
A.append((i ^ j).bit_length())
print((*A))
| false | 12.5 | [
"- d = i ^ j",
"- A.append((d & -d).bit_length())",
"+ A.append((i ^ j).bit_length())"
]
| false | 0.12243 | 0.111364 | 1.099366 | [
"s834620813",
"s226832361"
]
|
u747602774 | p02850 | python | s744249949 | s925230069 | 954 | 608 | 74,912 | 85,688 | Accepted | Accepted | 36.27 | from collections import deque
n = int(eval(input()))
ab = [list(map(int,input().split())) for i in range(n-1)]
ver = [[] for i in range(n)]
for i in range(n-1):
a,b = ab[i][0],ab[i][1]
ver[a-1].append(b-1)
ver[b-1].append(a-1)
#print(ver)
color = [dict() for i in range(n)]
q = deque()
i = 1
for v in ver[0]:
color[0][v] = i
color[v][0] = i
q.append((0,v))
i += 1
#print(q)
while q:
f,t = q.popleft()
i = 1
for v in ver[t]:
if v == f:
continue
if i == color[f][t]:
i += 1
color[t][v] = i
color[v][t] = i
q.append((t,v))
i += 1
#print(color)
k = 0
for i in range(n):
k = max(k,len(ver[i]))
print(k)
for i in range(n-1):
a,b = ab[i][0],ab[i][1]
print((color[a-1][b-1]))
| import sys
sys.setrecursionlimit(10**8)
n = int(eval(input()))
edge = [[] for i in range(n)]
for i in range(n-1):
a,b = list(map(int,input().split()))
edge[a-1].append((b-1,i))
edge[b-1].append((a-1,i))
k = max(len(e) for e in edge)
print(k)
ans = [-1]*(n-1)
def dfs(v=0, p=-1, to_p_col = -1):
col = 1
for u, idx in edge[v]:
if u != p:
if col == to_p_col:
col += 1
ans[idx] = col
dfs(u, v, col)
col += 1
dfs()
print(('\n'.join(map(str,ans))))
| 47 | 28 | 839 | 554 | from collections import deque
n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n - 1)]
ver = [[] for i in range(n)]
for i in range(n - 1):
a, b = ab[i][0], ab[i][1]
ver[a - 1].append(b - 1)
ver[b - 1].append(a - 1)
# print(ver)
color = [dict() for i in range(n)]
q = deque()
i = 1
for v in ver[0]:
color[0][v] = i
color[v][0] = i
q.append((0, v))
i += 1
# print(q)
while q:
f, t = q.popleft()
i = 1
for v in ver[t]:
if v == f:
continue
if i == color[f][t]:
i += 1
color[t][v] = i
color[v][t] = i
q.append((t, v))
i += 1
# print(color)
k = 0
for i in range(n):
k = max(k, len(ver[i]))
print(k)
for i in range(n - 1):
a, b = ab[i][0], ab[i][1]
print((color[a - 1][b - 1]))
| import sys
sys.setrecursionlimit(10**8)
n = int(eval(input()))
edge = [[] for i in range(n)]
for i in range(n - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append((b - 1, i))
edge[b - 1].append((a - 1, i))
k = max(len(e) for e in edge)
print(k)
ans = [-1] * (n - 1)
def dfs(v=0, p=-1, to_p_col=-1):
col = 1
for u, idx in edge[v]:
if u != p:
if col == to_p_col:
col += 1
ans[idx] = col
dfs(u, v, col)
col += 1
dfs()
print(("\n".join(map(str, ans))))
| false | 40.425532 | [
"-from collections import deque",
"+import sys",
"+sys.setrecursionlimit(10**8)",
"-ab = [list(map(int, input().split())) for i in range(n - 1)]",
"-ver = [[] for i in range(n)]",
"+edge = [[] for i in range(n)]",
"- a, b = ab[i][0], ab[i][1]",
"- ver[a - 1].append(b - 1)",
"- ver[b - 1].append(a - 1)",
"-# print(ver)",
"-color = [dict() for i in range(n)]",
"-q = deque()",
"-i = 1",
"-for v in ver[0]:",
"- color[0][v] = i",
"- color[v][0] = i",
"- q.append((0, v))",
"- i += 1",
"-# print(q)",
"-while q:",
"- f, t = q.popleft()",
"- i = 1",
"- for v in ver[t]:",
"- if v == f:",
"- continue",
"- if i == color[f][t]:",
"- i += 1",
"- color[t][v] = i",
"- color[v][t] = i",
"- q.append((t, v))",
"- i += 1",
"-# print(color)",
"-k = 0",
"-for i in range(n):",
"- k = max(k, len(ver[i]))",
"+ a, b = list(map(int, input().split()))",
"+ edge[a - 1].append((b - 1, i))",
"+ edge[b - 1].append((a - 1, i))",
"+k = max(len(e) for e in edge)",
"-for i in range(n - 1):",
"- a, b = ab[i][0], ab[i][1]",
"- print((color[a - 1][b - 1]))",
"+ans = [-1] * (n - 1)",
"+",
"+",
"+def dfs(v=0, p=-1, to_p_col=-1):",
"+ col = 1",
"+ for u, idx in edge[v]:",
"+ if u != p:",
"+ if col == to_p_col:",
"+ col += 1",
"+ ans[idx] = col",
"+ dfs(u, v, col)",
"+ col += 1",
"+",
"+",
"+dfs()",
"+print((\"\\n\".join(map(str, ans))))"
]
| false | 0.044852 | 0.037178 | 1.206408 | [
"s744249949",
"s925230069"
]
|
u219417113 | p03163 | python | s844635061 | s319747855 | 518 | 171 | 120,172 | 14,584 | Accepted | Accepted | 66.99 | N, W = list(map(int, input().split()))
WV = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * (W+1) for _ in range(N+1)]
for i in range(1, N+1):
for w in range(1, W+1):
if w >= WV[i-1][0]:
dp[i][w] = max(dp[i-1][w], dp[i-1][w-WV[i-1][0]] + WV[i-1][1])
else:
dp[i][w] = dp[i-1][w]
print((dp[N][W]))
| import numpy as np
n, W = list(map(int, input().split()))
w, v = [0] * n, [0] * n
for i in range(n):
w[i], v[i] = list(map(int, input().split()))
ndp = np.zeros(W + 1, dtype=np.int64)
for w, v in zip(w, v):
# [:w]は品物の重量がナップサックの空きよりも重いので更新しない。
# ndp[w:] は通常DPでのdp[i][w]=dp[i-1][w]。そのままでの更新。
# ndp[:-w] + v は[:-w]が[w-weight]に相当。
np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:])
print((ndp[-1]))
| 13 | 15 | 364 | 414 | N, W = list(map(int, input().split()))
WV = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for w in range(1, W + 1):
if w >= WV[i - 1][0]:
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - WV[i - 1][0]] + WV[i - 1][1])
else:
dp[i][w] = dp[i - 1][w]
print((dp[N][W]))
| import numpy as np
n, W = list(map(int, input().split()))
w, v = [0] * n, [0] * n
for i in range(n):
w[i], v[i] = list(map(int, input().split()))
ndp = np.zeros(W + 1, dtype=np.int64)
for w, v in zip(w, v):
# [:w]は品物の重量がナップサックの空きよりも重いので更新しない。
# ndp[w:] は通常DPでのdp[i][w]=dp[i-1][w]。そのままでの更新。
# ndp[:-w] + v は[:-w]が[w-weight]に相当。
np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:])
print((ndp[-1]))
| false | 13.333333 | [
"-N, W = list(map(int, input().split()))",
"-WV = [tuple(map(int, input().split())) for _ in range(N)]",
"-dp = [[0] * (W + 1) for _ in range(N + 1)]",
"-for i in range(1, N + 1):",
"- for w in range(1, W + 1):",
"- if w >= WV[i - 1][0]:",
"- dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - WV[i - 1][0]] + WV[i - 1][1])",
"- else:",
"- dp[i][w] = dp[i - 1][w]",
"-print((dp[N][W]))",
"+import numpy as np",
"+",
"+n, W = list(map(int, input().split()))",
"+w, v = [0] * n, [0] * n",
"+for i in range(n):",
"+ w[i], v[i] = list(map(int, input().split()))",
"+ndp = np.zeros(W + 1, dtype=np.int64)",
"+for w, v in zip(w, v):",
"+ # [:w]は品物の重量がナップサックの空きよりも重いので更新しない。",
"+ # ndp[w:] は通常DPでのdp[i][w]=dp[i-1][w]。そのままでの更新。",
"+ # ndp[:-w] + v は[:-w]が[w-weight]に相当。",
"+ np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:])",
"+print((ndp[-1]))"
]
| false | 0.044265 | 0.182104 | 0.243075 | [
"s844635061",
"s319747855"
]
|
u414980766 | p02883 | python | s804238249 | s754091865 | 561 | 447 | 37,292 | 38,624 | Accepted | Accepted | 20.32 | # 時間内に解ける
import numpy as np
N, K = list(map(int, input().split()))
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
left = - 1
right = 10**12
def f(x):
#return np.maximum(0, A - x//F) .sum()<= K
return A.sum() - np.minimum(A, x//F).sum()<= K
while right - left > 1:
mid = (left + right)//2
if f(mid):
right = mid
else:
left = mid
print(right) | import numpy as np
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))
A.sort(); F.sort(); F = F[::- 1]
left = - 1
right = 10**12
def f(x):
l = x//F
return A[A > l].sum() <= K + l[A > l].sum()
while right - left > 1:
mid = (left + right)//2
if f(mid):
right = mid
else:
left = mid
print(right) | 21 | 22 | 474 | 432 | # 時間内に解ける
import numpy as np
N, K = list(map(int, input().split()))
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
left = -1
right = 10**12
def f(x):
# return np.maximum(0, A - x//F) .sum()<= K
return A.sum() - np.minimum(A, x // F).sum() <= K
while right - left > 1:
mid = (left + right) // 2
if f(mid):
right = mid
else:
left = mid
print(right)
| import numpy as np
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))
A.sort()
F.sort()
F = F[::-1]
left = -1
right = 10**12
def f(x):
l = x // F
return A[A > l].sum() <= K + l[A > l].sum()
while right - left > 1:
mid = (left + right) // 2
if f(mid):
right = mid
else:
left = mid
print(right)
| false | 4.545455 | [
"-# 時間内に解ける",
"-A = np.array(sorted(list(map(int, input().split()))))",
"-F = np.array(sorted(list(map(int, input().split())), reverse=True))",
"+A = np.array(list(map(int, input().split())))",
"+F = np.array(list(map(int, input().split())))",
"+A.sort()",
"+F.sort()",
"+F = F[::-1]",
"- # return np.maximum(0, A - x//F) .sum()<= K",
"- return A.sum() - np.minimum(A, x // F).sum() <= K",
"+ l = x // F",
"+ return A[A > l].sum() <= K + l[A > l].sum()"
]
| false | 0.370376 | 0.292768 | 1.265084 | [
"s804238249",
"s754091865"
]
|
u493520238 | p02787 | python | s859188086 | s709419268 | 479 | 165 | 41,964 | 74,056 | Accepted | Accepted | 65.55 | H, N = list(map(int, input().split()))
abl = []
for _ in range(N):
ab = list(map(int, input().split()) )
abl.append(ab)
dp = [10**8]*(2*10**4+1)
dp[0] = 0
for h in range(H+1):
for ab in abl:
a,b = ab
dp[h+a] = min(dp[h+a], dp[h]+b)
print((min( dp[H:] ))) | h,n = list(map(int, input().split()))
abl = [tuple(map(int, input().split())) for _ in range(n)]
dp = [10**18]*(h+1)
dp[0] = 0
for i in range(h):
for a,b in abl:
next_h = min(h,i+a)
dp[next_h] = min(dp[next_h], dp[i]+b)
print((dp[-1])) | 14 | 11 | 290 | 259 | H, N = list(map(int, input().split()))
abl = []
for _ in range(N):
ab = list(map(int, input().split()))
abl.append(ab)
dp = [10**8] * (2 * 10**4 + 1)
dp[0] = 0
for h in range(H + 1):
for ab in abl:
a, b = ab
dp[h + a] = min(dp[h + a], dp[h] + b)
print((min(dp[H:])))
| h, n = list(map(int, input().split()))
abl = [tuple(map(int, input().split())) for _ in range(n)]
dp = [10**18] * (h + 1)
dp[0] = 0
for i in range(h):
for a, b in abl:
next_h = min(h, i + a)
dp[next_h] = min(dp[next_h], dp[i] + b)
print((dp[-1]))
| false | 21.428571 | [
"-H, N = list(map(int, input().split()))",
"-abl = []",
"-for _ in range(N):",
"- ab = list(map(int, input().split()))",
"- abl.append(ab)",
"-dp = [10**8] * (2 * 10**4 + 1)",
"+h, n = list(map(int, input().split()))",
"+abl = [tuple(map(int, input().split())) for _ in range(n)]",
"+dp = [10**18] * (h + 1)",
"-for h in range(H + 1):",
"- for ab in abl:",
"- a, b = ab",
"- dp[h + a] = min(dp[h + a], dp[h] + b)",
"-print((min(dp[H:])))",
"+for i in range(h):",
"+ for a, b in abl:",
"+ next_h = min(h, i + a)",
"+ dp[next_h] = min(dp[next_h], dp[i] + b)",
"+print((dp[-1]))"
]
| false | 0.133807 | 0.260258 | 0.514132 | [
"s859188086",
"s709419268"
]
|
u644907318 | p03244 | python | s067731968 | s391901287 | 270 | 147 | 66,668 | 102,196 | Accepted | Accepted | 45.56 | n = int(eval(input()))
V = list(map(int,input().split()))
Ce = {}
Co = {}
for i in range(n):
v = V[i]
if i%2==0:
if v not in Ce:
Ce[v] = 0
Ce[v] += 1
else:
if v not in Co:
Co[v] = 0
Co[v] += 1
Ce = sorted(list(Ce.items()),key=lambda x:x[1],reverse=True)
Co = sorted(list(Co.items()),key=lambda x:x[1],reverse=True)
if len(Ce)==1 and len(Co)==1 and Ce[0][0]==Co[0][0]:
m = n//2
else:
if Ce[0][0]!=Co[0][0]:
m = n-Ce[0][1]-Co[0][1]
else:
m1 = n-Ce[1][1]-Co[0][1]
m2 = n-Ce[0][1]-Co[1][1]
m = min(m1,m2)
print(m) | n = int(eval(input()))
V = list(map(int,input().split()))
Ce = {}
Co = {}
for i in range(n):
v = V[i]
if i%2==0:
if v not in Ce:
Ce[v]=0
Ce[v] += 1
else:
if v not in Co:
Co[v]=0
Co[v] += 1
Ce = sorted(list(Ce.items()),key=lambda x:x[1],reverse=True)
Co = sorted(list(Co.items()),key=lambda x:x[1],reverse=True)
if Ce[0][0]!=Co[0][0]:
cnt = 0
for i in range(1,len(Ce)):
cnt += Ce[i][1]
for i in range(1,len(Co)):
cnt += Co[i][1]
print(cnt)
else:
cnt1 = 0
for i in range(1,len(Ce)):
cnt1 += Ce[i][1]
if Ce[0][1]>n//2:
cnt1 += Ce[0][1]-n//2
cnt1 += Co[0][1]
for i in range(2,len(Co)):
cnt1 += Co[i][1]
cnt2 = 0
for i in range(1,len(Co)):
cnt2 += Co[i][1]
if Co[0][1]>n//2:
cnt2 += Co[0][1]-n//2
cnt2 += Ce[0][1]
for i in range(2,len(Ce)):
cnt2 += Ce[i][1]
print((min(cnt1,cnt2))) | 26 | 41 | 640 | 1,000 | n = int(eval(input()))
V = list(map(int, input().split()))
Ce = {}
Co = {}
for i in range(n):
v = V[i]
if i % 2 == 0:
if v not in Ce:
Ce[v] = 0
Ce[v] += 1
else:
if v not in Co:
Co[v] = 0
Co[v] += 1
Ce = sorted(list(Ce.items()), key=lambda x: x[1], reverse=True)
Co = sorted(list(Co.items()), key=lambda x: x[1], reverse=True)
if len(Ce) == 1 and len(Co) == 1 and Ce[0][0] == Co[0][0]:
m = n // 2
else:
if Ce[0][0] != Co[0][0]:
m = n - Ce[0][1] - Co[0][1]
else:
m1 = n - Ce[1][1] - Co[0][1]
m2 = n - Ce[0][1] - Co[1][1]
m = min(m1, m2)
print(m)
| n = int(eval(input()))
V = list(map(int, input().split()))
Ce = {}
Co = {}
for i in range(n):
v = V[i]
if i % 2 == 0:
if v not in Ce:
Ce[v] = 0
Ce[v] += 1
else:
if v not in Co:
Co[v] = 0
Co[v] += 1
Ce = sorted(list(Ce.items()), key=lambda x: x[1], reverse=True)
Co = sorted(list(Co.items()), key=lambda x: x[1], reverse=True)
if Ce[0][0] != Co[0][0]:
cnt = 0
for i in range(1, len(Ce)):
cnt += Ce[i][1]
for i in range(1, len(Co)):
cnt += Co[i][1]
print(cnt)
else:
cnt1 = 0
for i in range(1, len(Ce)):
cnt1 += Ce[i][1]
if Ce[0][1] > n // 2:
cnt1 += Ce[0][1] - n // 2
cnt1 += Co[0][1]
for i in range(2, len(Co)):
cnt1 += Co[i][1]
cnt2 = 0
for i in range(1, len(Co)):
cnt2 += Co[i][1]
if Co[0][1] > n // 2:
cnt2 += Co[0][1] - n // 2
cnt2 += Ce[0][1]
for i in range(2, len(Ce)):
cnt2 += Ce[i][1]
print((min(cnt1, cnt2)))
| false | 36.585366 | [
"-if len(Ce) == 1 and len(Co) == 1 and Ce[0][0] == Co[0][0]:",
"- m = n // 2",
"+if Ce[0][0] != Co[0][0]:",
"+ cnt = 0",
"+ for i in range(1, len(Ce)):",
"+ cnt += Ce[i][1]",
"+ for i in range(1, len(Co)):",
"+ cnt += Co[i][1]",
"+ print(cnt)",
"- if Ce[0][0] != Co[0][0]:",
"- m = n - Ce[0][1] - Co[0][1]",
"- else:",
"- m1 = n - Ce[1][1] - Co[0][1]",
"- m2 = n - Ce[0][1] - Co[1][1]",
"- m = min(m1, m2)",
"-print(m)",
"+ cnt1 = 0",
"+ for i in range(1, len(Ce)):",
"+ cnt1 += Ce[i][1]",
"+ if Ce[0][1] > n // 2:",
"+ cnt1 += Ce[0][1] - n // 2",
"+ cnt1 += Co[0][1]",
"+ for i in range(2, len(Co)):",
"+ cnt1 += Co[i][1]",
"+ cnt2 = 0",
"+ for i in range(1, len(Co)):",
"+ cnt2 += Co[i][1]",
"+ if Co[0][1] > n // 2:",
"+ cnt2 += Co[0][1] - n // 2",
"+ cnt2 += Ce[0][1]",
"+ for i in range(2, len(Ce)):",
"+ cnt2 += Ce[i][1]",
"+ print((min(cnt1, cnt2)))"
]
| false | 0.038069 | 0.037299 | 1.020646 | [
"s067731968",
"s391901287"
]
|
u808585569 | p03087 | python | s574908070 | s418830225 | 937 | 785 | 40,368 | 40,324 | Accepted | Accepted | 16.22 | import numpy as np
N, Q=list(map(int,input().split()))
S=eval(input())
L =[list(map(int,input().split()))for i in range(Q)]
c = [0]*(N) #ACのチェック
s = [0]*(N) #ACの累積和
ans = [0]*Q
for i in range(N-1):
if S[i] == "A" and S[i+1] == "C":
c[i+1] = 1
s = np.cumsum(c)
for i in range(Q):
ans[i] = s[L[i][1]-1]-s[L[i][0]-1]
for i in ans:
print(i)
| from sys import stdin
import numpy as np
N, Q=list(map(int,input().split()))
S=eval(input())
L =[list(map(int, stdin.readline().split())) for _ in range(Q)]
c = [0]*(N) #ACのチェック
s = [0]*(N) #ACの累積和
ans = [0]*Q
for i in range(N-1):
if S[i] == "A" and S[i+1] == "C":
c[i+1] = 1
s = np.cumsum(c)
for i in range(Q):
ans[i] = s[L[i][1]-1]-s[L[i][0]-1]
for i in ans:
print(i)
| 17 | 18 | 356 | 390 | import numpy as np
N, Q = list(map(int, input().split()))
S = eval(input())
L = [list(map(int, input().split())) for i in range(Q)]
c = [0] * (N) # ACのチェック
s = [0] * (N) # ACの累積和
ans = [0] * Q
for i in range(N - 1):
if S[i] == "A" and S[i + 1] == "C":
c[i + 1] = 1
s = np.cumsum(c)
for i in range(Q):
ans[i] = s[L[i][1] - 1] - s[L[i][0] - 1]
for i in ans:
print(i)
| from sys import stdin
import numpy as np
N, Q = list(map(int, input().split()))
S = eval(input())
L = [list(map(int, stdin.readline().split())) for _ in range(Q)]
c = [0] * (N) # ACのチェック
s = [0] * (N) # ACの累積和
ans = [0] * Q
for i in range(N - 1):
if S[i] == "A" and S[i + 1] == "C":
c[i + 1] = 1
s = np.cumsum(c)
for i in range(Q):
ans[i] = s[L[i][1] - 1] - s[L[i][0] - 1]
for i in ans:
print(i)
| false | 5.555556 | [
"+from sys import stdin",
"-L = [list(map(int, input().split())) for i in range(Q)]",
"+L = [list(map(int, stdin.readline().split())) for _ in range(Q)]"
]
| false | 0.28487 | 0.605396 | 0.470551 | [
"s574908070",
"s418830225"
]
|
u040298438 | p03759 | python | s154628267 | s883248843 | 33 | 29 | 9,152 | 9,144 | Accepted | Accepted | 12.12 | a, b, c = list(map(int, input().split()))
print(("YES" if b - a == c - b else "NO"))
| a, b, c = list(map(int, input().split()))
print((("NO", "YES")[b - a == c - b])) | 2 | 2 | 78 | 73 | a, b, c = list(map(int, input().split()))
print(("YES" if b - a == c - b else "NO"))
| a, b, c = list(map(int, input().split()))
print((("NO", "YES")[b - a == c - b]))
| false | 0 | [
"-print((\"YES\" if b - a == c - b else \"NO\"))",
"+print(((\"NO\", \"YES\")[b - a == c - b]))"
]
| false | 0.047115 | 0.047509 | 0.991707 | [
"s154628267",
"s883248843"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.