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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u505420467
|
p03061
|
python
|
s545503877
|
s183604231
| 379
| 232
| 85,228
| 16,120
|
Accepted
|
Accepted
| 38.79
|
from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
rev_a = list(reversed(a))
ans = 0
accumulation_gcd = [0] * n
rev_accumulation_gcd = [0] * n
accumulation_gcd[0] = a[0]
rev_accumulation_gcd[0] = rev_a[0]
for i in range(1, n):
accumulation_gcd[i] = f.gcd(a[i], accumulation_gcd[i-1])
rev_accumulation_gcd[i] = f.gcd(rev_a[i], rev_accumulation_gcd[i-1])
rev_accumulation_gcd.reverse()
for i in range(n):
if i == 0:
ans = max(ans, rev_accumulation_gcd[1])
elif i == (n - 1):
ans = max(ans, accumulation_gcd[n-2])
else:
ans = max(ans, f.gcd(accumulation_gcd[i-1], rev_accumulation_gcd[i+1]))
print(ans)
|
import fractions
n = int(eval(input()))
a = list(map(int, input().split()))
gcd_from_left = [a[0]]
gcd_from_right = [a[-1]]
for i in range(1, n):
gcd_from_left.append(fractions.gcd(gcd_from_left[i - 1], a[i]))
gcd_from_right.append(fractions.gcd(gcd_from_right[i - 1], a[n - 1 - i]))
gcd_from_right.reverse()
ans = 0
for i in range(n):
if i == 0:
ans = max(ans, gcd_from_right[1])
elif i == n - 1:
ans = max(ans, gcd_from_left[n - 2])
else:
ans = max(ans, fractions.gcd(gcd_from_left[i - 1], gcd_from_right[i + 1]))
print(ans)
| 31
| 22
| 803
| 590
|
from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
rev_a = list(reversed(a))
ans = 0
accumulation_gcd = [0] * n
rev_accumulation_gcd = [0] * n
accumulation_gcd[0] = a[0]
rev_accumulation_gcd[0] = rev_a[0]
for i in range(1, n):
accumulation_gcd[i] = f.gcd(a[i], accumulation_gcd[i - 1])
rev_accumulation_gcd[i] = f.gcd(rev_a[i], rev_accumulation_gcd[i - 1])
rev_accumulation_gcd.reverse()
for i in range(n):
if i == 0:
ans = max(ans, rev_accumulation_gcd[1])
elif i == (n - 1):
ans = max(ans, accumulation_gcd[n - 2])
else:
ans = max(ans, f.gcd(accumulation_gcd[i - 1], rev_accumulation_gcd[i + 1]))
print(ans)
|
import fractions
n = int(eval(input()))
a = list(map(int, input().split()))
gcd_from_left = [a[0]]
gcd_from_right = [a[-1]]
for i in range(1, n):
gcd_from_left.append(fractions.gcd(gcd_from_left[i - 1], a[i]))
gcd_from_right.append(fractions.gcd(gcd_from_right[i - 1], a[n - 1 - i]))
gcd_from_right.reverse()
ans = 0
for i in range(n):
if i == 0:
ans = max(ans, gcd_from_right[1])
elif i == n - 1:
ans = max(ans, gcd_from_left[n - 2])
else:
ans = max(ans, fractions.gcd(gcd_from_left[i - 1], gcd_from_right[i + 1]))
print(ans)
| false
| 29.032258
|
[
"-from operator import itemgetter",
"-from functools import reduce",
"-import fractions as f",
"-import sys",
"+import fractions",
"-input = sys.stdin.readline",
"-rev_a = list(reversed(a))",
"+gcd_from_left = [a[0]]",
"+gcd_from_right = [a[-1]]",
"+for i in range(1, n):",
"+ gcd_from_left.append(fractions.gcd(gcd_from_left[i - 1], a[i]))",
"+ gcd_from_right.append(fractions.gcd(gcd_from_right[i - 1], a[n - 1 - i]))",
"+gcd_from_right.reverse()",
"-accumulation_gcd = [0] * n",
"-rev_accumulation_gcd = [0] * n",
"-accumulation_gcd[0] = a[0]",
"-rev_accumulation_gcd[0] = rev_a[0]",
"-for i in range(1, n):",
"- accumulation_gcd[i] = f.gcd(a[i], accumulation_gcd[i - 1])",
"- rev_accumulation_gcd[i] = f.gcd(rev_a[i], rev_accumulation_gcd[i - 1])",
"-rev_accumulation_gcd.reverse()",
"- ans = max(ans, rev_accumulation_gcd[1])",
"- elif i == (n - 1):",
"- ans = max(ans, accumulation_gcd[n - 2])",
"+ ans = max(ans, gcd_from_right[1])",
"+ elif i == n - 1:",
"+ ans = max(ans, gcd_from_left[n - 2])",
"- ans = max(ans, f.gcd(accumulation_gcd[i - 1], rev_accumulation_gcd[i + 1]))",
"+ ans = max(ans, fractions.gcd(gcd_from_left[i - 1], gcd_from_right[i + 1]))"
] | false
| 0.044381
| 0.044568
| 0.995799
|
[
"s545503877",
"s183604231"
] |
u525065967
|
p02642
|
python
|
s587898839
|
s164794170
| 523
| 471
| 32,304
| 32,248
|
Accepted
|
Accepted
| 9.94
|
n = int(eval(input()))
A = [*list(map(int, input().split()))]
mx = max(A)
c = [0]*(1000000+1)
for a in A:
for i in range(a, mx+1, a): c[i] += 1
ans = 0
for a in A:
if c[a] == 1: ans += 1
print(ans)
|
n = int(eval(input()))
A = [*list(map(int, input().split()))]
mx = max(A)
c = [0]*(mx+1)
for a in A:
for i in range(a, mx+1, a): c[i] += 1
ans = 0
for a in A:
if c[a] == 1: ans += 1
print(ans)
| 10
| 10
| 203
| 198
|
n = int(eval(input()))
A = [*list(map(int, input().split()))]
mx = max(A)
c = [0] * (1000000 + 1)
for a in A:
for i in range(a, mx + 1, a):
c[i] += 1
ans = 0
for a in A:
if c[a] == 1:
ans += 1
print(ans)
|
n = int(eval(input()))
A = [*list(map(int, input().split()))]
mx = max(A)
c = [0] * (mx + 1)
for a in A:
for i in range(a, mx + 1, a):
c[i] += 1
ans = 0
for a in A:
if c[a] == 1:
ans += 1
print(ans)
| false
| 0
|
[
"-c = [0] * (1000000 + 1)",
"+c = [0] * (mx + 1)"
] | false
| 0.061697
| 0.073524
| 0.839139
|
[
"s587898839",
"s164794170"
] |
u788703383
|
p02971
|
python
|
s947376009
|
s159569554
| 315
| 266
| 25,156
| 25,036
|
Accepted
|
Accepted
| 15.56
|
n,*a = list(map(int,open(0).read().split()))
b = sorted(a)
max = b[-1]
maxs= b[-2]
for i in range(n):
if a[i] == max:
print(maxs)
else:
print(max)
|
def main():
n,*a = list(map(int,open(0).read().split()))
b = sorted(a)
max = b[-1]
maxs= b[-2]
for i in range(n):
if a[i] == max:
print(maxs)
else:
print(max)
return()
if __name__=='__main__':
main()
| 10
| 16
| 175
| 279
|
n, *a = list(map(int, open(0).read().split()))
b = sorted(a)
max = b[-1]
maxs = b[-2]
for i in range(n):
if a[i] == max:
print(maxs)
else:
print(max)
|
def main():
n, *a = list(map(int, open(0).read().split()))
b = sorted(a)
max = b[-1]
maxs = b[-2]
for i in range(n):
if a[i] == max:
print(maxs)
else:
print(max)
return ()
if __name__ == "__main__":
main()
| false
| 37.5
|
[
"-n, *a = list(map(int, open(0).read().split()))",
"-b = sorted(a)",
"-max = b[-1]",
"-maxs = b[-2]",
"-for i in range(n):",
"- if a[i] == max:",
"- print(maxs)",
"- else:",
"- print(max)",
"+def main():",
"+ n, *a = list(map(int, open(0).read().split()))",
"+ b = sorted(a)",
"+ max = b[-1]",
"+ maxs = b[-2]",
"+ for i in range(n):",
"+ if a[i] == max:",
"+ print(maxs)",
"+ else:",
"+ print(max)",
"+ return ()",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.036426
| 0.036366
| 1.001665
|
[
"s947376009",
"s159569554"
] |
u392319141
|
p02744
|
python
|
s592039576
|
s694317959
| 1,060
| 113
| 66,476
| 5,232
|
Accepted
|
Accepted
| 89.34
|
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache
N = int(input())
alph = string.ascii_lowercase
ans = defaultdict(int)
@lru_cache(maxsize=None)
def search(S, nums):
if nums in ans:
return
if len(nums) == N:
ans[nums] = S
return
for i in range(len(nums)):
for s, n in zip(S, nums):
if n == i:
search(S + s, nums + (n, ))
break
C = set(list(S))
for s in alph:
if not s in C:
search(S + s, nums + (len(nums), ))
break
search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')
|
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache
N = int(eval(input()))
alph = string.ascii_lowercase
def search(S, mx):
if len(S) == N:
print(S)
else:
for s in alph[: mx + 1]:
search(S + s, mx)
search(S + alph[mx + 1], mx + 1)
search('a', 0)
| 34
| 18
| 733
| 376
|
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache
N = int(input())
alph = string.ascii_lowercase
ans = defaultdict(int)
@lru_cache(maxsize=None)
def search(S, nums):
if nums in ans:
return
if len(nums) == N:
ans[nums] = S
return
for i in range(len(nums)):
for s, n in zip(S, nums):
if n == i:
search(S + s, nums + (n,))
break
C = set(list(S))
for s in alph:
if not s in C:
search(S + s, nums + (len(nums),))
break
search("a", (0,))
ans = list(ans.values())
ans.sort()
print(*ans, sep="\n")
|
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache
N = int(eval(input()))
alph = string.ascii_lowercase
def search(S, mx):
if len(S) == N:
print(S)
else:
for s in alph[: mx + 1]:
search(S + s, mx)
search(S + alph[mx + 1], mx + 1)
search("a", 0)
| false
| 47.058824
|
[
"-N = int(input())",
"+N = int(eval(input()))",
"-ans = defaultdict(int)",
"-@lru_cache(maxsize=None)",
"-def search(S, nums):",
"- if nums in ans:",
"- return",
"- if len(nums) == N:",
"- ans[nums] = S",
"- return",
"- for i in range(len(nums)):",
"- for s, n in zip(S, nums):",
"- if n == i:",
"- search(S + s, nums + (n,))",
"- break",
"- C = set(list(S))",
"- for s in alph:",
"- if not s in C:",
"- search(S + s, nums + (len(nums),))",
"- break",
"+def search(S, mx):",
"+ if len(S) == N:",
"+ print(S)",
"+ else:",
"+ for s in alph[: mx + 1]:",
"+ search(S + s, mx)",
"+ search(S + alph[mx + 1], mx + 1)",
"-search(\"a\", (0,))",
"-ans = list(ans.values())",
"-ans.sort()",
"-print(*ans, sep=\"\\n\")",
"+search(\"a\", 0)"
] | false
| 0.057135
| 0.053973
| 1.058583
|
[
"s592039576",
"s694317959"
] |
u724687935
|
p03003
|
python
|
s569964011
|
s071590838
| 413
| 330
| 104,540
| 72,668
|
Accepted
|
Accepted
| 20.1
|
MOD = 10 ** 9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 1
sm = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, M + 1):
if S[i - 1] == T[j - 1]:
dp[i][j] = (sm[i - 1][j - 1] + 1) % MOD
else:
dp[i][j] = 0
sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + dp[i][j]) % MOD
print((sm[N][M] + 1))
|
MOD = 10 ** 9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
sm = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N + 1):
sm[i][0] = 1
for j in range(M + 1):
sm[0][j] = 1
for i in range(1, N + 1):
for j in range(1, M + 1):
tmp = sm[i - 1][j - 1] if S[i - 1] == T[j - 1] else 0
sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + tmp) % MOD
print((sm[N][M]))
| 19
| 17
| 529
| 479
|
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 1
sm = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, M + 1):
if S[i - 1] == T[j - 1]:
dp[i][j] = (sm[i - 1][j - 1] + 1) % MOD
else:
dp[i][j] = 0
sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + dp[i][j]) % MOD
print((sm[N][M] + 1))
|
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
sm = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N + 1):
sm[i][0] = 1
for j in range(M + 1):
sm[0][j] = 1
for i in range(1, N + 1):
for j in range(1, M + 1):
tmp = sm[i - 1][j - 1] if S[i - 1] == T[j - 1] else 0
sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + tmp) % MOD
print((sm[N][M]))
| false
| 10.526316
|
[
"-dp = [[0] * (M + 1) for _ in range(N + 1)]",
"-dp[0][0] = 1",
"+for i in range(N + 1):",
"+ sm[i][0] = 1",
"+for j in range(M + 1):",
"+ sm[0][j] = 1",
"- if S[i - 1] == T[j - 1]:",
"- dp[i][j] = (sm[i - 1][j - 1] + 1) % MOD",
"- else:",
"- dp[i][j] = 0",
"- sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + dp[i][j]) % MOD",
"-print((sm[N][M] + 1))",
"+ tmp = sm[i - 1][j - 1] if S[i - 1] == T[j - 1] else 0",
"+ sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + tmp) % MOD",
"+print((sm[N][M]))"
] | false
| 0.03794
| 0.038
| 0.998428
|
[
"s569964011",
"s071590838"
] |
u992910889
|
p03273
|
python
|
s494213701
|
s575123096
| 159
| 21
| 14,704
| 4,596
|
Accepted
|
Accepted
| 86.79
|
import bisect
import copy
import fractions
import math
import numpy as np
from collections import Counter, deque
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product
def resolve():
h, w = map(int, input().split())
A = [[_ for _ in input()] for _ in range(h)]
B = [i for i in A if '#' in i]
C = zip(*[i for i in zip(*B) if '#' in i])
for i in C:
print(*i, sep='')
resolve()
|
def resolve():
h, w = map(int, input().split())
A = [[_ for _ in input()] for _ in range(h)]
B = [i for i in A if '#' in i]
C = zip(*[i for i in zip(*B) if '#' in i])
for i in C:
print(*i, sep='')
# print(*C,sep='')
resolve()
| 20
| 12
| 476
| 275
|
import bisect
import copy
import fractions
import math
import numpy as np
from collections import Counter, deque
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
)
def resolve():
h, w = map(int, input().split())
A = [[_ for _ in input()] for _ in range(h)]
B = [i for i in A if "#" in i]
C = zip(*[i for i in zip(*B) if "#" in i])
for i in C:
print(*i, sep="")
resolve()
|
def resolve():
h, w = map(int, input().split())
A = [[_ for _ in input()] for _ in range(h)]
B = [i for i in A if "#" in i]
C = zip(*[i for i in zip(*B) if "#" in i])
for i in C:
print(*i, sep="")
# print(*C,sep='')
resolve()
| false
| 40
|
[
"-import bisect",
"-import copy",
"-import fractions",
"-import math",
"-import numpy as np",
"-from collections import Counter, deque",
"-from itertools import (",
"- accumulate,",
"- permutations,",
"- combinations,",
"- combinations_with_replacement,",
"- product,",
"-)",
"-",
"-",
"+ # print(*C,sep='')"
] | false
| 0.063559
| 0.065479
| 0.97067
|
[
"s494213701",
"s575123096"
] |
u459419927
|
p03752
|
python
|
s597953364
|
s915792713
| 339
| 73
| 3,192
| 3,064
|
Accepted
|
Accepted
| 78.47
|
N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
ans = 10 ** 10
if N==K:
cost=0
for i in range(1,N):
if height[i-1]>=height[i]:
cost+=height[i-1]-height[i]+1
height[i]+=height[i-1]-height[i]+1
print(cost)
exit()
for i in range(2 ** N):
count=1
cost = 0
height2 = height.copy()
for j in range(N):
if i >> j & 1:
if j!=0:
tarou=max(height2[:j])
if height2[j]<=tarou:
cost+=tarou-height2[j]+1
height2[j]+=tarou-height2[j]+1
count+=1
else:count+=1
# zenkai=0
# for x in range(1,N):
# if height2[zenkai] < height2[x]:
# count += 1
# zenkai=x
if ans > cost and count >= K:
ans = cost
print(ans)
|
N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
height2=height.copy()
ans = 10 ** 10
if N==K:
cost=0
for i in range(1,N):
tarou=max(height2[:i])
if tarou>=height2[i]:
cost+=tarou-height2[i]+1
height2[i]=tarou+1
print(cost)
exit()
for i in range(2 ** N):
cost = 0
height2 = height.copy()
if bin(i).count("1")==K:
for j in range(1,N):
if i >> j & 1:
if N==K:
if height2[j-1]>=height2[j]:
cost+=height2[j-1]-height2[j]+1
height2[j]+=height2[j-1]-height2[j]+1
else:
tarou=max(height2[:j])
if height2[j]<=tarou:
cost+=tarou-height2[j]+1
height2[j]=tarou+1
if ans > cost:
ans = cost
print(ans)
| 33
| 33
| 896
| 957
|
N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
ans = 10**10
if N == K:
cost = 0
for i in range(1, N):
if height[i - 1] >= height[i]:
cost += height[i - 1] - height[i] + 1
height[i] += height[i - 1] - height[i] + 1
print(cost)
exit()
for i in range(2**N):
count = 1
cost = 0
height2 = height.copy()
for j in range(N):
if i >> j & 1:
if j != 0:
tarou = max(height2[:j])
if height2[j] <= tarou:
cost += tarou - height2[j] + 1
height2[j] += tarou - height2[j] + 1
count += 1
else:
count += 1
# zenkai=0
# for x in range(1,N):
# if height2[zenkai] < height2[x]:
# count += 1
# zenkai=x
if ans > cost and count >= K:
ans = cost
print(ans)
|
N, K = list(map(int, input().split()))
height = list(map(int, input().split()))
height2 = height.copy()
ans = 10**10
if N == K:
cost = 0
for i in range(1, N):
tarou = max(height2[:i])
if tarou >= height2[i]:
cost += tarou - height2[i] + 1
height2[i] = tarou + 1
print(cost)
exit()
for i in range(2**N):
cost = 0
height2 = height.copy()
if bin(i).count("1") == K:
for j in range(1, N):
if i >> j & 1:
if N == K:
if height2[j - 1] >= height2[j]:
cost += height2[j - 1] - height2[j] + 1
height2[j] += height2[j - 1] - height2[j] + 1
else:
tarou = max(height2[:j])
if height2[j] <= tarou:
cost += tarou - height2[j] + 1
height2[j] = tarou + 1
if ans > cost:
ans = cost
print(ans)
| false
| 0
|
[
"+height2 = height.copy()",
"- if height[i - 1] >= height[i]:",
"- cost += height[i - 1] - height[i] + 1",
"- height[i] += height[i - 1] - height[i] + 1",
"+ tarou = max(height2[:i])",
"+ if tarou >= height2[i]:",
"+ cost += tarou - height2[i] + 1",
"+ height2[i] = tarou + 1",
"- count = 1",
"- for j in range(N):",
"- if i >> j & 1:",
"- if j != 0:",
"- tarou = max(height2[:j])",
"- if height2[j] <= tarou:",
"- cost += tarou - height2[j] + 1",
"- height2[j] += tarou - height2[j] + 1",
"- count += 1",
"+ if bin(i).count(\"1\") == K:",
"+ for j in range(1, N):",
"+ if i >> j & 1:",
"+ if N == K:",
"+ if height2[j - 1] >= height2[j]:",
"+ cost += height2[j - 1] - height2[j] + 1",
"+ height2[j] += height2[j - 1] - height2[j] + 1",
"- count += 1",
"- # zenkai=0",
"- # for x in range(1,N):",
"- # if height2[zenkai] < height2[x]:",
"- # count += 1",
"- # zenkai=x",
"- if ans > cost and count >= K:",
"- ans = cost",
"+ tarou = max(height2[:j])",
"+ if height2[j] <= tarou:",
"+ cost += tarou - height2[j] + 1",
"+ height2[j] = tarou + 1",
"+ if ans > cost:",
"+ ans = cost"
] | false
| 0.043298
| 0.079022
| 0.547922
|
[
"s597953364",
"s915792713"
] |
u391731808
|
p03026
|
python
|
s835220927
|
s456847317
| 350
| 71
| 53,208
| 7,800
|
Accepted
|
Accepted
| 79.71
|
N = int(eval(input()))
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
*C, = list(map(int,input().split()))
connect = [[] for _ in [0]*N]
for a,b in AB:
connect[a-1].append(b-1)
connect[b-1].append(a-1)
d = [-1]*N
d[0] = 0
q = [0]
while q:
qq = []
for i in q:
for j in connect[i]:
if d[j] == -1:
d[j] = d[i]+1
qq.append(j)
q = qq
o = sorted(zip(d,list(range(N))),key =lambda x:-x[0])
C.sort()
ans = [0]*N
for j,tmp in enumerate(o):
d,i = tmp
ans[i] = C[j]
print((sum(C)-C[-1]))
print((*ans))
|
N = int(eval(input()))
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
*C, = sorted(map(int,input().split()))
print((sum(C[:-1])))
E = [[] for _ in [0]*N]
d = [0]*N
for a,b in AB:
E[a-1].append(b-1)
E[b-1].append(a-1)
for i in range(N):
if len(E[i])>1:break
q = [i]
while q:
i = q.pop()
d[i] = C.pop()
for j in E[i]:
if d[j] != 0:continue
q.append(j)
print((*d))
| 28
| 20
| 587
| 421
|
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in [0] * (N - 1)]
(*C,) = list(map(int, input().split()))
connect = [[] for _ in [0] * N]
for a, b in AB:
connect[a - 1].append(b - 1)
connect[b - 1].append(a - 1)
d = [-1] * N
d[0] = 0
q = [0]
while q:
qq = []
for i in q:
for j in connect[i]:
if d[j] == -1:
d[j] = d[i] + 1
qq.append(j)
q = qq
o = sorted(zip(d, list(range(N))), key=lambda x: -x[0])
C.sort()
ans = [0] * N
for j, tmp in enumerate(o):
d, i = tmp
ans[i] = C[j]
print((sum(C) - C[-1]))
print((*ans))
|
N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in [0] * (N - 1)]
(*C,) = sorted(map(int, input().split()))
print((sum(C[:-1])))
E = [[] for _ in [0] * N]
d = [0] * N
for a, b in AB:
E[a - 1].append(b - 1)
E[b - 1].append(a - 1)
for i in range(N):
if len(E[i]) > 1:
break
q = [i]
while q:
i = q.pop()
d[i] = C.pop()
for j in E[i]:
if d[j] != 0:
continue
q.append(j)
print((*d))
| false
| 28.571429
|
[
"-(*C,) = list(map(int, input().split()))",
"-connect = [[] for _ in [0] * N]",
"+(*C,) = sorted(map(int, input().split()))",
"+print((sum(C[:-1])))",
"+E = [[] for _ in [0] * N]",
"+d = [0] * N",
"- connect[a - 1].append(b - 1)",
"- connect[b - 1].append(a - 1)",
"-d = [-1] * N",
"-d[0] = 0",
"-q = [0]",
"+ E[a - 1].append(b - 1)",
"+ E[b - 1].append(a - 1)",
"+for i in range(N):",
"+ if len(E[i]) > 1:",
"+ break",
"+q = [i]",
"- qq = []",
"- for i in q:",
"- for j in connect[i]:",
"- if d[j] == -1:",
"- d[j] = d[i] + 1",
"- qq.append(j)",
"- q = qq",
"-o = sorted(zip(d, list(range(N))), key=lambda x: -x[0])",
"-C.sort()",
"-ans = [0] * N",
"-for j, tmp in enumerate(o):",
"- d, i = tmp",
"- ans[i] = C[j]",
"-print((sum(C) - C[-1]))",
"-print((*ans))",
"+ i = q.pop()",
"+ d[i] = C.pop()",
"+ for j in E[i]:",
"+ if d[j] != 0:",
"+ continue",
"+ q.append(j)",
"+print((*d))"
] | false
| 0.038219
| 0.091189
| 0.419115
|
[
"s835220927",
"s456847317"
] |
u445624660
|
p02928
|
python
|
s407816129
|
s592943800
| 810
| 539
| 3,188
| 9,272
|
Accepted
|
Accepted
| 33.46
|
# つよいさんすう
# 最初のAを単独で考えたらいける 等差数列の和の公式はググった
# ex) k = 3, a = [1, 3, 2]
# 1 3 2 1 3 2 1 3 2
# 最初の1 3 2
# 3...[2,1,2,1,2]で5
# 2...[1.1]で2
# 二番目の1 3 2
# 3...[2,1,2]
# 2...[1]
# 三番目の1 3 2
# 3...[2]で1
# 3だけでみると初項1 末項5 公差2で n(2*a1 +(n-1)*2)/2 = 3*(2*1 + (3-1)*2)/2 = 3*6/2 = 9
# n*(a1+an)/2 = 3*(1+5)/2 = 9
# これを一般化すればいけそう
# ex) k = 3, a = [3, 5, 2, 4, 1]とすると
# 3 5 2 4 1 3 5 2 4 1 3 5 2 4 1
# 3の初項は2で公差2 -> 3*(2*2+(3-1)*2)/2 = 12 (6+4+2)
# 5の初項は3で公差4 -> 3*(2*3 + (3-1)*4)/2 = 21 (11+7+3)
# 2の初項は1で公差2 -> 3*(2*1 + (3-1)*2)/2 = 9
# 4の初項は1で公差2 -> 3*(2*1 + (3-1)*3)/2 = 12
# 1の初項は0で公差0 -> 3*(2*0 + (3-1)*0)/2 = 0
# ...みたいな感じ
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
first_subarr = [0] * n
rest_arr = [0] * n
for i in range(n):
for j in range(i, n):
if a[i] > a[j]:
first_subarr[i] += 1
for i in range(n - 1, -1, -1):
for j in range(i, -1, -1):
if a[j] < a[i]:
rest_arr[i] += 1
diffs = [0] * n
for i in range(n):
diffs[i] = first_subarr[i] + rest_arr[i]
ans = 0
for i in range(n):
# print("{}について".format(a[i]))
# print("初項:{} 公差:{}なので".format(first_subarr[i], diffs[i]))
tmp = k * (2 * first_subarr[i] + (k - 1) * diffs[i]) // 2
# print("総和は{}".format(tmp))
ans += tmp
ans %= MOD
print(ans)
|
# A内で完結するものと、連結したときに変わるものがある
#
# 3 4 2 1 2 -> 3+3+1+0+0 = 7
# 3 4 2 1 2 | 3 4 2 1 2 -> (3*2)+(1*1+3*2)+(1*2)+0+(1*1) + 7 = 16 + 7
# 3 4 2 1 2 | 3 4 2 1 2 | 3 4 2 1 2 -> (3*3)+(2*1+3*3)+(1*3)+0+(2*1) + 16+7 = 25+16+7
# Aについて、i<jなるjでAi>Ajになるものがk個、Ai<Ajになるものがk-1個ある
# k=3で考えると
# 順方向: (m*3)+(m*3)+(m*1)+(0)+(0), m=1~3 = 7+14+21=42
# 逆方向:(0)+(m*1)+(0)+(0)+(m*1), m=1~2 = 2+4=6 (逆方向はk-1個)
# 合わせて48となりこれは上記で試してたのと等しい
# ということで、それぞれ等差数列の和が使えそう
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9 + 7
# 順方向
base = 0
for i in range(n):
for j in range(i, n):
if a[i] > a[j]:
base += 1
# 逆方向
additional = 0
for i in range(n):
for j in range(i):
if a[i] > a[j]:
additional += 1
ans = (k * (k + 1) // 2 % mod * base +
(k - 1) * k // 2 % mod * additional) % mod
print(ans)
| 54
| 31
| 1,359
| 874
|
# つよいさんすう
# 最初のAを単独で考えたらいける 等差数列の和の公式はググった
# ex) k = 3, a = [1, 3, 2]
# 1 3 2 1 3 2 1 3 2
# 最初の1 3 2
# 3...[2,1,2,1,2]で5
# 2...[1.1]で2
# 二番目の1 3 2
# 3...[2,1,2]
# 2...[1]
# 三番目の1 3 2
# 3...[2]で1
# 3だけでみると初項1 末項5 公差2で n(2*a1 +(n-1)*2)/2 = 3*(2*1 + (3-1)*2)/2 = 3*6/2 = 9
# n*(a1+an)/2 = 3*(1+5)/2 = 9
# これを一般化すればいけそう
# ex) k = 3, a = [3, 5, 2, 4, 1]とすると
# 3 5 2 4 1 3 5 2 4 1 3 5 2 4 1
# 3の初項は2で公差2 -> 3*(2*2+(3-1)*2)/2 = 12 (6+4+2)
# 5の初項は3で公差4 -> 3*(2*3 + (3-1)*4)/2 = 21 (11+7+3)
# 2の初項は1で公差2 -> 3*(2*1 + (3-1)*2)/2 = 9
# 4の初項は1で公差2 -> 3*(2*1 + (3-1)*3)/2 = 12
# 1の初項は0で公差0 -> 3*(2*0 + (3-1)*0)/2 = 0
# ...みたいな感じ
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7
first_subarr = [0] * n
rest_arr = [0] * n
for i in range(n):
for j in range(i, n):
if a[i] > a[j]:
first_subarr[i] += 1
for i in range(n - 1, -1, -1):
for j in range(i, -1, -1):
if a[j] < a[i]:
rest_arr[i] += 1
diffs = [0] * n
for i in range(n):
diffs[i] = first_subarr[i] + rest_arr[i]
ans = 0
for i in range(n):
# print("{}について".format(a[i]))
# print("初項:{} 公差:{}なので".format(first_subarr[i], diffs[i]))
tmp = k * (2 * first_subarr[i] + (k - 1) * diffs[i]) // 2
# print("総和は{}".format(tmp))
ans += tmp
ans %= MOD
print(ans)
|
# A内で完結するものと、連結したときに変わるものがある
#
# 3 4 2 1 2 -> 3+3+1+0+0 = 7
# 3 4 2 1 2 | 3 4 2 1 2 -> (3*2)+(1*1+3*2)+(1*2)+0+(1*1) + 7 = 16 + 7
# 3 4 2 1 2 | 3 4 2 1 2 | 3 4 2 1 2 -> (3*3)+(2*1+3*3)+(1*3)+0+(2*1) + 16+7 = 25+16+7
# Aについて、i<jなるjでAi>Ajになるものがk個、Ai<Ajになるものがk-1個ある
# k=3で考えると
# 順方向: (m*3)+(m*3)+(m*1)+(0)+(0), m=1~3 = 7+14+21=42
# 逆方向:(0)+(m*1)+(0)+(0)+(m*1), m=1~2 = 2+4=6 (逆方向はk-1個)
# 合わせて48となりこれは上記で試してたのと等しい
# ということで、それぞれ等差数列の和が使えそう
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9 + 7
# 順方向
base = 0
for i in range(n):
for j in range(i, n):
if a[i] > a[j]:
base += 1
# 逆方向
additional = 0
for i in range(n):
for j in range(i):
if a[i] > a[j]:
additional += 1
ans = (k * (k + 1) // 2 % mod * base + (k - 1) * k // 2 % mod * additional) % mod
print(ans)
| false
| 42.592593
|
[
"-# つよいさんすう",
"-# 最初のAを単独で考えたらいける 等差数列の和の公式はググった",
"-# ex) k = 3, a = [1, 3, 2]",
"-# 1 3 2 1 3 2 1 3 2",
"-# 最初の1 3 2",
"-# 3...[2,1,2,1,2]で5",
"-# 2...[1.1]で2",
"-# 二番目の1 3 2",
"-# 3...[2,1,2]",
"-# 2...[1]",
"-# 三番目の1 3 2",
"-# 3...[2]で1",
"-# 3だけでみると初項1 末項5 公差2で n(2*a1 +(n-1)*2)/2 = 3*(2*1 + (3-1)*2)/2 = 3*6/2 = 9",
"-# n*(a1+an)/2 = 3*(1+5)/2 = 9",
"-# これを一般化すればいけそう",
"-# ex) k = 3, a = [3, 5, 2, 4, 1]とすると",
"-# 3 5 2 4 1 3 5 2 4 1 3 5 2 4 1",
"-# 3の初項は2で公差2 -> 3*(2*2+(3-1)*2)/2 = 12 (6+4+2)",
"-# 5の初項は3で公差4 -> 3*(2*3 + (3-1)*4)/2 = 21 (11+7+3)",
"-# 2の初項は1で公差2 -> 3*(2*1 + (3-1)*2)/2 = 9",
"-# 4の初項は1で公差2 -> 3*(2*1 + (3-1)*3)/2 = 12",
"-# 1の初項は0で公差0 -> 3*(2*0 + (3-1)*0)/2 = 0",
"-# ...みたいな感じ",
"+# A\b内で完結するものと、連結したときに変わるものがある",
"+#",
"+# 3 4 2 1 2 -> 3+3+1+0+0 = 7",
"+# 3 4 2 1 2 | 3 4 2 1 2 -> (3*2)+(1*1+3*2)+(1*2)+0+(1*1) + 7 = 16 + 7",
"+# 3 4 2 1 2 | 3 4 2 1 2 | 3 4 2 1 2 -> (3*3)+(2*1+3*3)+(1*3)+0+(2*1) + 16+7 = 25+16+7",
"+# Aについて、i<jなるjでAi>Ajになるものがk個、Ai<Ajになるものがk-1個ある",
"+# k=3で考えると",
"+# 順方向: (m*3)+(m*3)+(m*1)+(0)+(0), m=1~3 = 7+14+21=42",
"+# 逆方向:(0)+(m*1)+(0)+(0)+(m*1), m=1~2 = 2+4=6 (逆方向はk-1個)",
"+# 合わせて48となりこれは上記で試してたのと等しい",
"+# ということで、それぞれ等差数列の和が使えそう",
"-MOD = 10**9 + 7",
"-first_subarr = [0] * n",
"-rest_arr = [0] * n",
"+mod = 10**9 + 7",
"+# 順方向",
"+base = 0",
"- first_subarr[i] += 1",
"-for i in range(n - 1, -1, -1):",
"- for j in range(i, -1, -1):",
"- if a[j] < a[i]:",
"- rest_arr[i] += 1",
"-diffs = [0] * n",
"+ base += 1",
"+# 逆方向",
"+additional = 0",
"- diffs[i] = first_subarr[i] + rest_arr[i]",
"-ans = 0",
"-for i in range(n):",
"- # print(\"{}について\".format(a[i]))",
"- # print(\"初項:{} 公差:{}なので\".format(first_subarr[i], diffs[i]))",
"- tmp = k * (2 * first_subarr[i] + (k - 1) * diffs[i]) // 2",
"- # print(\"総和は{}\".format(tmp))",
"- ans += tmp",
"- ans %= MOD",
"+ for j in range(i):",
"+ if a[i] > a[j]:",
"+ additional += 1",
"+ans = (k * (k + 1) // 2 % mod * base + (k - 1) * k // 2 % mod * additional) % mod"
] | false
| 0.038858
| 0.06819
| 0.569845
|
[
"s407816129",
"s592943800"
] |
u525065967
|
p02617
|
python
|
s565680096
|
s012172163
| 433
| 380
| 9,184
| 9,192
|
Accepted
|
Accepted
| 12.24
|
n = int(eval(input()))
V = E = 0
for i in range(1, n+1): V += i * (n - i + 1)
for _ in range(n-1):
a, b = list(map(int, input().split()))
if a > b: a, b = b, a
E += a * (n - b + 1)
print((V - E))
|
n = int(eval(input()))
V = n*(n+1)*(n+2)//6; E = 0
for _ in range(n-1):
a, b = list(map(int, input().split()))
if a > b: a, b = b, a
E += a * (n - b + 1)
print((V - E))
| 8
| 7
| 201
| 173
|
n = int(eval(input()))
V = E = 0
for i in range(1, n + 1):
V += i * (n - i + 1)
for _ in range(n - 1):
a, b = list(map(int, input().split()))
if a > b:
a, b = b, a
E += a * (n - b + 1)
print((V - E))
|
n = int(eval(input()))
V = n * (n + 1) * (n + 2) // 6
E = 0
for _ in range(n - 1):
a, b = list(map(int, input().split()))
if a > b:
a, b = b, a
E += a * (n - b + 1)
print((V - E))
| false
| 12.5
|
[
"-V = E = 0",
"-for i in range(1, n + 1):",
"- V += i * (n - i + 1)",
"+V = n * (n + 1) * (n + 2) // 6",
"+E = 0"
] | false
| 0.096727
| 0.05299
| 1.825385
|
[
"s565680096",
"s012172163"
] |
u995004106
|
p02603
|
python
|
s657326917
|
s407434482
| 80
| 70
| 64,896
| 64,984
|
Accepted
|
Accepted
| 12.5
|
import collections
N=int(eval(input()))
A=list(map(int,input().split()))
i=0
A.insert(0,float("inf"))
#print(A)
buy=[0]*N
sell=[0]*N
for i in range(N-1):
if (A[i]>=A[i+1])and(A[i+2]>=A[i+1]):
buy[i]=1
if (A[i]<=A[i+1])and(A[i+2]<=A[i+1]):
sell[i]=1
kabu=0
money=1000
#print(buy,sell)
#print(money,kabu)
A=A[1:]
#print(A)
for i in range(N):
if sell[i]==1:
money=money+kabu*A[i]
kabu=0
if buy[i]==1:
kabu=kabu+money//A[i]
money=money-(money//A[i])*A[i]
#print(money,kabu,A[i])
#input()
#print(money,kabu)
money=money+kabu*A[N-1]
print(money)
|
import collections
N=int(eval(input()))
A=list(map(int,input().split()))
i=0
A.insert(0,float("inf"))
#print(A)
buy=[0]*N
sell=[0]*N
for i in range(N-1):
if (A[i]>=A[i+1])and(A[i+2]>=A[i+1]):
buy[i]=1
if (A[i]<=A[i+1])and(A[i+2]<=A[i+1]):
sell[i]=1
kabu=0
money=1000
#print(buy,sell)
#print(money,kabu)
A=A[1:]
#print(A)
for i in range(N):
if buy[i]==1:
kabu=kabu+money//A[i]
money=money-(money//A[i])*A[i]
if sell[i]==1:
money=money+kabu*A[i]
kabu=0
#print(money,kabu,A[i])
#input()
#print(money,kabu)
money=money+kabu*A[N-1]
print(money)
| 33
| 35
| 640
| 644
|
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
A.insert(0, float("inf"))
# print(A)
buy = [0] * N
sell = [0] * N
for i in range(N - 1):
if (A[i] >= A[i + 1]) and (A[i + 2] >= A[i + 1]):
buy[i] = 1
if (A[i] <= A[i + 1]) and (A[i + 2] <= A[i + 1]):
sell[i] = 1
kabu = 0
money = 1000
# print(buy,sell)
# print(money,kabu)
A = A[1:]
# print(A)
for i in range(N):
if sell[i] == 1:
money = money + kabu * A[i]
kabu = 0
if buy[i] == 1:
kabu = kabu + money // A[i]
money = money - (money // A[i]) * A[i]
# print(money,kabu,A[i])
# input()
# print(money,kabu)
money = money + kabu * A[N - 1]
print(money)
|
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
A.insert(0, float("inf"))
# print(A)
buy = [0] * N
sell = [0] * N
for i in range(N - 1):
if (A[i] >= A[i + 1]) and (A[i + 2] >= A[i + 1]):
buy[i] = 1
if (A[i] <= A[i + 1]) and (A[i + 2] <= A[i + 1]):
sell[i] = 1
kabu = 0
money = 1000
# print(buy,sell)
# print(money,kabu)
A = A[1:]
# print(A)
for i in range(N):
if buy[i] == 1:
kabu = kabu + money // A[i]
money = money - (money // A[i]) * A[i]
if sell[i] == 1:
money = money + kabu * A[i]
kabu = 0
# print(money,kabu,A[i])
# input()
# print(money,kabu)
money = money + kabu * A[N - 1]
print(money)
| false
| 5.714286
|
[
"+ if buy[i] == 1:",
"+ kabu = kabu + money // A[i]",
"+ money = money - (money // A[i]) * A[i]",
"- if buy[i] == 1:",
"- kabu = kabu + money // A[i]",
"- money = money - (money // A[i]) * A[i]"
] | false
| 0.04381
| 0.046653
| 0.939065
|
[
"s657326917",
"s407434482"
] |
u040298438
|
p03943
|
python
|
s455321840
|
s317517929
| 31
| 24
| 9,120
| 9,052
|
Accepted
|
Accepted
| 22.58
|
a = list(map(int, input().split()))
print(("Yes" if sum(a) == max(a) * 2 else "No"))
|
a, b, c = sorted(map(int, input().split()))
print((("No", "Yes")[a + b == c]))
| 2
| 2
| 84
| 77
|
a = list(map(int, input().split()))
print(("Yes" if sum(a) == max(a) * 2 else "No"))
|
a, b, c = sorted(map(int, input().split()))
print((("No", "Yes")[a + b == c]))
| false
| 0
|
[
"-a = list(map(int, input().split()))",
"-print((\"Yes\" if sum(a) == max(a) * 2 else \"No\"))",
"+a, b, c = sorted(map(int, input().split()))",
"+print(((\"No\", \"Yes\")[a + b == c]))"
] | false
| 0.04812
| 0.048484
| 0.992484
|
[
"s455321840",
"s317517929"
] |
u022407960
|
p02378
|
python
|
s071216115
|
s077655269
| 70
| 50
| 8,428
| 9,260
|
Accepted
|
Accepted
| 28.57
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3
output:
3
"""
import sys
def generate_adj_table(_edges):
for edge in _edges:
vx, vy = list(map(int, edge))
init_adj_table[vx].append(vy)
return init_adj_table
def graph_dfs(current, matching, visited):
for adj in range(y_num):
if (not visited[adj]) and (adj in adj_table[current]):
visited[adj] = True
if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
matching[adj] = current
return True
return False
def mbm():
matching = [-1] * y_num
res = 0
for v in range(x_num):
visited = [False] * y_num
if graph_dfs(v, matching, visited):
res += 1
# print(matching)
return res
if __name__ == '__main__':
_input = sys.stdin.readlines()
x_num, y_num, e_num = list(map(int, _input[0].split()))
edges = [x.split() for x in _input[1:]]
init_adj_table = [[] for _ in range(x_num)]
adj_table = generate_adj_table(edges)
print((mbm()))
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3
output:
3
"""
import sys
def generate_adj_table(_edges):
for edge in _edges:
vx, vy = list(map(int, edge))
init_adj_table[vx].add(vy)
return init_adj_table
def graph_dfs(current, matching, visited):
for adj in range(y_num):
if (not visited[adj]) and (adj in adj_table[current]):
visited[adj] = True
# matching[adj] = -1: target in y not assigned to any of x
# matching[adj] -> an assigned source in x
# graph_dfs(matching[adj], matching, visited) = True indicates that source has been
if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
matching[adj] = current
return True
return False
def mbm():
matching = [-1] * y_num
res = 0
for v in range(x_num):
visited = [False] * y_num
if graph_dfs(v, matching, visited):
res += 1
# print(matching)
return res
if __name__ == '__main__':
_input = sys.stdin.readlines()
x_num, y_num, e_num = list(map(int, _input[0].split()))
edges = [x.split() for x in _input[1:]]
init_adj_table = [set() for _ in range(x_num)]
adj_table = generate_adj_table(edges)
print((mbm()))
| 57
| 60
| 1,153
| 1,378
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3
output:
3
"""
import sys
def generate_adj_table(_edges):
for edge in _edges:
vx, vy = list(map(int, edge))
init_adj_table[vx].append(vy)
return init_adj_table
def graph_dfs(current, matching, visited):
for adj in range(y_num):
if (not visited[adj]) and (adj in adj_table[current]):
visited[adj] = True
if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
matching[adj] = current
return True
return False
def mbm():
matching = [-1] * y_num
res = 0
for v in range(x_num):
visited = [False] * y_num
if graph_dfs(v, matching, visited):
res += 1
# print(matching)
return res
if __name__ == "__main__":
_input = sys.stdin.readlines()
x_num, y_num, e_num = list(map(int, _input[0].split()))
edges = [x.split() for x in _input[1:]]
init_adj_table = [[] for _ in range(x_num)]
adj_table = generate_adj_table(edges)
print((mbm()))
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3
output:
3
"""
import sys
def generate_adj_table(_edges):
for edge in _edges:
vx, vy = list(map(int, edge))
init_adj_table[vx].add(vy)
return init_adj_table
def graph_dfs(current, matching, visited):
for adj in range(y_num):
if (not visited[adj]) and (adj in adj_table[current]):
visited[adj] = True
# matching[adj] = -1: target in y not assigned to any of x
# matching[adj] -> an assigned source in x
# graph_dfs(matching[adj], matching, visited) = True indicates that source has been
if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
matching[adj] = current
return True
return False
def mbm():
matching = [-1] * y_num
res = 0
for v in range(x_num):
visited = [False] * y_num
if graph_dfs(v, matching, visited):
res += 1
# print(matching)
return res
if __name__ == "__main__":
_input = sys.stdin.readlines()
x_num, y_num, e_num = list(map(int, _input[0].split()))
edges = [x.split() for x in _input[1:]]
init_adj_table = [set() for _ in range(x_num)]
adj_table = generate_adj_table(edges)
print((mbm()))
| false
| 5
|
[
"- init_adj_table[vx].append(vy)",
"+ init_adj_table[vx].add(vy)",
"+ # matching[adj] = -1: target in y not assigned to any of x",
"+ # matching[adj] -> an assigned source in x",
"+ # graph_dfs(matching[adj], matching, visited) = True indicates that source has been",
"- init_adj_table = [[] for _ in range(x_num)]",
"+ init_adj_table = [set() for _ in range(x_num)]"
] | false
| 0.048785
| 0.076718
| 0.635896
|
[
"s071216115",
"s077655269"
] |
u279266699
|
p02614
|
python
|
s849516757
|
s009536294
| 237
| 60
| 27,024
| 9,116
|
Accepted
|
Accepted
| 74.68
|
import copy
import numpy as np
def count_black(c):
count = 0
for row in c:
count += row.count('#')
return count
h, w, k = list(map(int, input().split()))
c = [list(eval(input())) for _ in range(h)]
ans = 0
for h_p in range(2 ** h):
for w_p in range(2 ** w):
c_cp = np.array(copy.deepcopy(c))
for i in range(h):
if (h_p >> i) & 1:
c_cp[i, :] = 'r'
for j in range(w):
if (w_p >> j) & 1:
c_cp[:, j] = 'r'
if count_black(c_cp.tolist()) == k:
ans += 1
print(ans)
|
h, w, k = list(map(int, input().split()))
c = [eval(input()) for _ in range(h)]
ans = 0
for h_p in range(2 ** h):
for w_p in range(2 ** w):
cnt = 0
for i in range(h):
for j in range(w):
if (h_p >> i) & 1 and (w_p >> j) & 1 and c[i][j] == '#':
cnt += 1
if cnt == k:
ans += 1
print(ans)
| 29
| 13
| 605
| 372
|
import copy
import numpy as np
def count_black(c):
count = 0
for row in c:
count += row.count("#")
return count
h, w, k = list(map(int, input().split()))
c = [list(eval(input())) for _ in range(h)]
ans = 0
for h_p in range(2**h):
for w_p in range(2**w):
c_cp = np.array(copy.deepcopy(c))
for i in range(h):
if (h_p >> i) & 1:
c_cp[i, :] = "r"
for j in range(w):
if (w_p >> j) & 1:
c_cp[:, j] = "r"
if count_black(c_cp.tolist()) == k:
ans += 1
print(ans)
|
h, w, k = list(map(int, input().split()))
c = [eval(input()) for _ in range(h)]
ans = 0
for h_p in range(2**h):
for w_p in range(2**w):
cnt = 0
for i in range(h):
for j in range(w):
if (h_p >> i) & 1 and (w_p >> j) & 1 and c[i][j] == "#":
cnt += 1
if cnt == k:
ans += 1
print(ans)
| false
| 55.172414
|
[
"-import copy",
"-import numpy as np",
"-",
"-",
"-def count_black(c):",
"- count = 0",
"- for row in c:",
"- count += row.count(\"#\")",
"- return count",
"-",
"-",
"-c = [list(eval(input())) for _ in range(h)]",
"+c = [eval(input()) for _ in range(h)]",
"- c_cp = np.array(copy.deepcopy(c))",
"+ cnt = 0",
"- if (h_p >> i) & 1:",
"- c_cp[i, :] = \"r\"",
"- for j in range(w):",
"- if (w_p >> j) & 1:",
"- c_cp[:, j] = \"r\"",
"- if count_black(c_cp.tolist()) == k:",
"+ for j in range(w):",
"+ if (h_p >> i) & 1 and (w_p >> j) & 1 and c[i][j] == \"#\":",
"+ cnt += 1",
"+ if cnt == k:"
] | false
| 0.283339
| 0.045382
| 6.243409
|
[
"s849516757",
"s009536294"
] |
u750990077
|
p02691
|
python
|
s602340774
|
s279831533
| 904
| 171
| 139,580
| 149,920
|
Accepted
|
Accepted
| 81.08
|
from collections import Counter
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
bigger = [None]*n
smaller = [None]*n
for i, ai in enumerate(a):
bigger[i] = i - ai
smaller[i] = i + ai
b = sorted(Counter(bigger).items())
s = sorted(Counter(smaller).items())
nb = len(b)
ns = len(s)
b.append((10**10, 0))
s.append((10**11, 0))
i, j = 0, 0
ans = 0
while i < nb or j < ns:
bi, nbi = b[i]
si, nsi = s[j]
if bi == si:
ans += nbi*nsi
i += 1
j += 1
elif bi > si:
j += 1
else:
i += 1
print(ans)
if __name__ == "__main__":
main()
|
from collections import defaultdict
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
d = defaultdict(lambda : 0)
ans = 0
for i, ai in enumerate(a):
sa = i - ai
ans += d[sa]
wa = i + ai
d[wa] += 1
print(ans)
if __name__ == "__main__":
main()
| 34
| 17
| 759
| 343
|
from collections import Counter
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
bigger = [None] * n
smaller = [None] * n
for i, ai in enumerate(a):
bigger[i] = i - ai
smaller[i] = i + ai
b = sorted(Counter(bigger).items())
s = sorted(Counter(smaller).items())
nb = len(b)
ns = len(s)
b.append((10**10, 0))
s.append((10**11, 0))
i, j = 0, 0
ans = 0
while i < nb or j < ns:
bi, nbi = b[i]
si, nsi = s[j]
if bi == si:
ans += nbi * nsi
i += 1
j += 1
elif bi > si:
j += 1
else:
i += 1
print(ans)
if __name__ == "__main__":
main()
|
from collections import defaultdict
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
d = defaultdict(lambda: 0)
ans = 0
for i, ai in enumerate(a):
sa = i - ai
ans += d[sa]
wa = i + ai
d[wa] += 1
print(ans)
if __name__ == "__main__":
main()
| false
| 50
|
[
"-from collections import Counter",
"+from collections import defaultdict",
"- bigger = [None] * n",
"- smaller = [None] * n",
"+ d = defaultdict(lambda: 0)",
"+ ans = 0",
"- bigger[i] = i - ai",
"- smaller[i] = i + ai",
"- b = sorted(Counter(bigger).items())",
"- s = sorted(Counter(smaller).items())",
"- nb = len(b)",
"- ns = len(s)",
"- b.append((10**10, 0))",
"- s.append((10**11, 0))",
"- i, j = 0, 0",
"- ans = 0",
"- while i < nb or j < ns:",
"- bi, nbi = b[i]",
"- si, nsi = s[j]",
"- if bi == si:",
"- ans += nbi * nsi",
"- i += 1",
"- j += 1",
"- elif bi > si:",
"- j += 1",
"- else:",
"- i += 1",
"+ sa = i - ai",
"+ ans += d[sa]",
"+ wa = i + ai",
"+ d[wa] += 1"
] | false
| 0.04267
| 0.03637
| 1.173231
|
[
"s602340774",
"s279831533"
] |
u150984829
|
p00086
|
python
|
s141884066
|
s296401853
| 30
| 20
| 5,616
| 5,608
|
Accepted
|
Accepted
| 33.33
|
import sys
v=[0]*101
for e in sys.stdin:
a,b=list(map(int,e.split()))
v[a]+=1;v[b]+=1
if a==0:
print((['NG','OK'][1&v[1]and 1&v[2]and sum(x&1 for x in v)==2]))
v=[0]*101
|
import sys
v=[0]*101
for e in sys.stdin:
a,b=list(map(int,e.split()))
v[a]+=1;v[b]+=1
if a==0:
print((['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2]))
v=[0]*101
| 8
| 8
| 176
| 174
|
import sys
v = [0] * 101
for e in sys.stdin:
a, b = list(map(int, e.split()))
v[a] += 1
v[b] += 1
if a == 0:
print((["NG", "OK"][1 & v[1] and 1 & v[2] and sum(x & 1 for x in v) == 2]))
v = [0] * 101
|
import sys
v = [0] * 101
for e in sys.stdin:
a, b = list(map(int, e.split()))
v[a] += 1
v[b] += 1
if a == 0:
print((["NG", "OK"][(v[1] & 1) * (v[2] & 1) * sum(x & 1 for x in v) == 2]))
v = [0] * 101
| false
| 0
|
[
"- print(([\"NG\", \"OK\"][1 & v[1] and 1 & v[2] and sum(x & 1 for x in v) == 2]))",
"+ print(([\"NG\", \"OK\"][(v[1] & 1) * (v[2] & 1) * sum(x & 1 for x in v) == 2]))"
] | false
| 0.045905
| 0.07162
| 0.640952
|
[
"s141884066",
"s296401853"
] |
u434428594
|
p00494
|
python
|
s437673115
|
s606756278
| 1,280
| 430
| 5,320
| 49,564
|
Accepted
|
Accepted
| 66.41
|
s = input()
p = 0
ans = 0
while p < len(s):
joi = 'JOI'
cnt = [0] * 3
for i in range(3):
while p < len(s) and s[p] == joi[i]:
cnt[i] += 1
p += 1
if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]:
ans = max(ans, cnt[1])
print(ans)
|
import re
s = input()
ans = 0
for joi_str in re.findall('(J*)(O*)(I*)', s):
j = len(joi_str[0])
o = len(joi_str[1])
i = len(joi_str[2])
if j >= o and o <= i:
ans = max(ans, o)
print(ans)
| 15
| 12
| 296
| 226
|
s = input()
p = 0
ans = 0
while p < len(s):
joi = "JOI"
cnt = [0] * 3
for i in range(3):
while p < len(s) and s[p] == joi[i]:
cnt[i] += 1
p += 1
if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]:
ans = max(ans, cnt[1])
print(ans)
|
import re
s = input()
ans = 0
for joi_str in re.findall("(J*)(O*)(I*)", s):
j = len(joi_str[0])
o = len(joi_str[1])
i = len(joi_str[2])
if j >= o and o <= i:
ans = max(ans, o)
print(ans)
| false
| 20
|
[
"+import re",
"+",
"-p = 0",
"-while p < len(s):",
"- joi = \"JOI\"",
"- cnt = [0] * 3",
"- for i in range(3):",
"- while p < len(s) and s[p] == joi[i]:",
"- cnt[i] += 1",
"- p += 1",
"- if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]:",
"- ans = max(ans, cnt[1])",
"+for joi_str in re.findall(\"(J*)(O*)(I*)\", s):",
"+ j = len(joi_str[0])",
"+ o = len(joi_str[1])",
"+ i = len(joi_str[2])",
"+ if j >= o and o <= i:",
"+ ans = max(ans, o)"
] | false
| 0.043382
| 0.135745
| 0.319585
|
[
"s437673115",
"s606756278"
] |
u714225686
|
p03013
|
python
|
s347633613
|
s443937083
| 384
| 91
| 461,736
| 8,744
|
Accepted
|
Accepted
| 76.3
|
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654
import math
import sys
import itertools
import queue
mod = 1000000007
if __name__ == "__main__":
N, M = list(map(int, sys.stdin.readline().split()))
broken = [False for _ in range(N + 2)]
for _ in range(M):
broken[int(sys.stdin.readline())] = True
dp = [0 for _ in range(N + 2)]
dp[N] = 1
for i in range(0, N)[::-1]:
if not broken[i]:
dp[i] = dp[i + 1] + dp[i + 2]
print((dp[0] % mod))
|
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654
import math
import sys
import itertools
import queue
mod = 1000000007
if __name__ == "__main__":
N, M = list(map(int, sys.stdin.readline().split()))
broken = [False for _ in range(N + 2)]
for _ in range(M):
broken[int(sys.stdin.readline())] = True
dp = [0 for _ in range(N + 2)]
dp[N] = 1
for i in range(0, N)[::-1]:
if not broken[i]:
dp[i] = (dp[i + 1] + dp[i + 2]) % mod
print((dp[0]))
| 30
| 30
| 802
| 804
|
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654
import math
import sys
import itertools
import queue
mod = 1000000007
if __name__ == "__main__":
N, M = list(map(int, sys.stdin.readline().split()))
broken = [False for _ in range(N + 2)]
for _ in range(M):
broken[int(sys.stdin.readline())] = True
dp = [0 for _ in range(N + 2)]
dp[N] = 1
for i in range(0, N)[::-1]:
if not broken[i]:
dp[i] = dp[i + 1] + dp[i + 2]
print((dp[0] % mod))
|
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)] # 二次元配列入力 二次元マップみたいな入力のとき
# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b)) # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654
import math
import sys
import itertools
import queue
mod = 1000000007
if __name__ == "__main__":
N, M = list(map(int, sys.stdin.readline().split()))
broken = [False for _ in range(N + 2)]
for _ in range(M):
broken[int(sys.stdin.readline())] = True
dp = [0 for _ in range(N + 2)]
dp[N] = 1
for i in range(0, N)[::-1]:
if not broken[i]:
dp[i] = (dp[i + 1] + dp[i + 2]) % mod
print((dp[0]))
| false
| 0
|
[
"- dp[i] = dp[i + 1] + dp[i + 2]",
"- print((dp[0] % mod))",
"+ dp[i] = (dp[i + 1] + dp[i + 2]) % mod",
"+ print((dp[0]))"
] | false
| 0.043984
| 0.045723
| 0.961983
|
[
"s347633613",
"s443937083"
] |
u505830998
|
p02642
|
python
|
s160587586
|
s353565744
| 517
| 227
| 165,396
| 122,084
|
Accepted
|
Accepted
| 56.09
|
import sys
import collections
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : list(map(int, input().split()))
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
n = int(eval(input()))
#b , c = tin()
al = lin()
al.sort()
unique_al = list(set(al))
unique_al.sort()
al_counter = collections.Counter(al)
ok=[v for v in list(al_counter.keys()) if al_counter[v] == 1]
d = {v:i for i,v in enumerate(ok)}
max_v = 10**6+1
for check in unique_al:
for v in range(2*check, max_v, check):
if v in d:
ok[d[v]]=0
return sum([v > 0 for v in ok ])
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : list(map(int, input().split()))
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
n = int(eval(input()))
#b , c = tin()
#s = input()
al=lin()
vm=10**6+1
rr = [0]*(vm)
for v in al:
rr[v]+=1
for v in list(set(al)):
for i in range(2*v, vm, v):
rr[i]=0
ret = rr.count(1)
print(ret)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| 69
| 59
| 1,235
| 1,016
|
import sys
import collections
input_methods = ["clipboard", "file", "key"]
using_method = 0
input_method = input_methods[using_method]
tin = lambda: list(map(int, input().split()))
lin = lambda: list(tin())
mod = 1000000007
# +++++
def main():
n = int(eval(input()))
# b , c = tin()
al = lin()
al.sort()
unique_al = list(set(al))
unique_al.sort()
al_counter = collections.Counter(al)
ok = [v for v in list(al_counter.keys()) if al_counter[v] == 1]
d = {v: i for i, v in enumerate(ok)}
max_v = 10**6 + 1
for check in unique_al:
for v in range(2 * check, max_v, check):
if v in d:
ok[d[v]] = 0
return sum([v > 0 for v in ok])
# +++++
isTest = False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text = clipboard.get()
input_l = input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform == "ios":
if input_method == input_methods[0]:
ic = input_clipboard()
input = lambda: ic.__next__()
elif input_method == input_methods[1]:
sys.stdin = open("inputFile.txt")
else:
pass
isTest = True
else:
pass
# input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
import sys
input_methods = ["clipboard", "file", "key"]
using_method = 0
input_method = input_methods[using_method]
tin = lambda: list(map(int, input().split()))
lin = lambda: list(tin())
mod = 1000000007
# +++++
def main():
n = int(eval(input()))
# b , c = tin()
# s = input()
al = lin()
vm = 10**6 + 1
rr = [0] * (vm)
for v in al:
rr[v] += 1
for v in list(set(al)):
for i in range(2 * v, vm, v):
rr[i] = 0
ret = rr.count(1)
print(ret)
# +++++
isTest = False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text = clipboard.get()
input_l = input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform == "ios":
if input_method == input_methods[0]:
ic = input_clipboard()
input = lambda: ic.__next__()
elif input_method == input_methods[1]:
sys.stdin = open("inputFile.txt")
else:
pass
isTest = True
else:
pass
# input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| false
| 14.492754
|
[
"-import collections",
"+ # s = input()",
"- al.sort()",
"- unique_al = list(set(al))",
"- unique_al.sort()",
"- al_counter = collections.Counter(al)",
"- ok = [v for v in list(al_counter.keys()) if al_counter[v] == 1]",
"- d = {v: i for i, v in enumerate(ok)}",
"- max_v = 10**6 + 1",
"- for check in unique_al:",
"- for v in range(2 * check, max_v, check):",
"- if v in d:",
"- ok[d[v]] = 0",
"- return sum([v > 0 for v in ok])",
"+ vm = 10**6 + 1",
"+ rr = [0] * (vm)",
"+ for v in al:",
"+ rr[v] += 1",
"+ for v in list(set(al)):",
"+ for i in range(2 * v, vm, v):",
"+ rr[i] = 0",
"+ ret = rr.count(1)",
"+ print(ret)"
] | false
| 0.085292
| 0.109391
| 0.779698
|
[
"s160587586",
"s353565744"
] |
u373499377
|
p03853
|
python
|
s150606828
|
s847333842
| 22
| 17
| 3,316
| 3,060
|
Accepted
|
Accepted
| 22.73
|
def main():
h, w = list(map(int, input().split()))
px = [[0 for j in range(w)] for i in range(h)]
px_stretch = [[0 for j in range(w)] for i in range(2 * h)]
for row in range(h):
px[row] = list(eval(input()))
for row in range(2 * h):
px_stretch[row] = [px[row // 2][i] for i in range(w)]
print((''.join(px_stretch[row])))
if __name__ == "__main__":
main()
|
def main():
h, w = map(int, input().split())
px = [input() for i in range(h)]
for row in range(h):
print(px[row], px[row], sep='\n')
# px = [[0 for j in range(w)] for i in range(h)]
# px_stretch = [[0 for j in range(w)] for i in range(2 * h)]
#
# for row in range(h):
# px[row] = list(input())
#
# for row in range(2 * h):
# px_stretch[row] = [px[row // 2][i] for i in range(w)]
# print(''.join(px_stretch[row]))
if __name__ == "__main__":
main()
| 17
| 21
| 411
| 546
|
def main():
h, w = list(map(int, input().split()))
px = [[0 for j in range(w)] for i in range(h)]
px_stretch = [[0 for j in range(w)] for i in range(2 * h)]
for row in range(h):
px[row] = list(eval(input()))
for row in range(2 * h):
px_stretch[row] = [px[row // 2][i] for i in range(w)]
print(("".join(px_stretch[row])))
if __name__ == "__main__":
main()
|
def main():
h, w = map(int, input().split())
px = [input() for i in range(h)]
for row in range(h):
print(px[row], px[row], sep="\n")
# px = [[0 for j in range(w)] for i in range(h)]
# px_stretch = [[0 for j in range(w)] for i in range(2 * h)]
#
# for row in range(h):
# px[row] = list(input())
#
# for row in range(2 * h):
# px_stretch[row] = [px[row // 2][i] for i in range(w)]
# print(''.join(px_stretch[row]))
if __name__ == "__main__":
main()
| false
| 19.047619
|
[
"- h, w = list(map(int, input().split()))",
"- px = [[0 for j in range(w)] for i in range(h)]",
"- px_stretch = [[0 for j in range(w)] for i in range(2 * h)]",
"+ h, w = map(int, input().split())",
"+ px = [input() for i in range(h)]",
"- px[row] = list(eval(input()))",
"- for row in range(2 * h):",
"- px_stretch[row] = [px[row // 2][i] for i in range(w)]",
"- print((\"\".join(px_stretch[row])))",
"+ print(px[row], px[row], sep=\"\\n\")",
"+ # px = [[0 for j in range(w)] for i in range(h)]",
"+ # px_stretch = [[0 for j in range(w)] for i in range(2 * h)]",
"+ #",
"+ # for row in range(h):",
"+ # px[row] = list(input())",
"+ #",
"+ # for row in range(2 * h):",
"+ # px_stretch[row] = [px[row // 2][i] for i in range(w)]",
"+ # print(''.join(px_stretch[row]))"
] | false
| 0.049375
| 0.0467
| 1.057268
|
[
"s150606828",
"s847333842"
] |
u371350984
|
p03494
|
python
|
s825859201
|
s365134552
| 31
| 28
| 9,128
| 9,084
|
Accepted
|
Accepted
| 9.68
|
n = int(eval(input()))
a = list(map(int, input().split()))
i = 0
per = True
while per == True:
for index in range(n):
num = a[index]
ans = divmod(num, 2)
if num == 0 or ans[1] != 0:
per = False
break
a[index] = ans[0]
if per == True:
i += 1
print(i)
|
import math
n = eval(input())
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print((round(ans)))
| 16
| 7
| 331
| 170
|
n = int(eval(input()))
a = list(map(int, input().split()))
i = 0
per = True
while per == True:
for index in range(n):
num = a[index]
ans = divmod(num, 2)
if num == 0 or ans[1] != 0:
per = False
break
a[index] = ans[0]
if per == True:
i += 1
print(i)
|
import math
n = eval(input())
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print((round(ans)))
| false
| 56.25
|
[
"-n = int(eval(input()))",
"+import math",
"+",
"+n = eval(input())",
"-i = 0",
"-per = True",
"-while per == True:",
"- for index in range(n):",
"- num = a[index]",
"- ans = divmod(num, 2)",
"- if num == 0 or ans[1] != 0:",
"- per = False",
"- break",
"- a[index] = ans[0]",
"- if per == True:",
"- i += 1",
"-print(i)",
"+ans = float(\"inf\")",
"+for i in a:",
"+ ans = min(ans, len(bin(i)) - bin(i).rfind(\"1\") - 1)",
"+print((round(ans)))"
] | false
| 0.038217
| 0.037546
| 1.017875
|
[
"s825859201",
"s365134552"
] |
u968166680
|
p02960
|
python
|
s000689872
|
s182208561
| 271
| 248
| 80,368
| 73,756
|
Accepted
|
Accepted
| 8.49
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
N = len(S)
power = [0] * N
power[0] = 1
for i in range(N - 1):
power[i + 1] = 10 * power[i] % 13
S = S[::-1]
Q = []
const = 0
for i, c in enumerate(S):
if c == '?':
Q.append(i)
else:
const = (const + power[i] * int(c)) % 13
dp = [0] * 13
dp[const] = 1
for i in range(len(Q)):
dp, dp_prev = [0] * 13, dp
p = power[Q[i]]
for j in range(10):
for k in range(13):
idx = (p * j + k) % 13
dp[idx] = (dp[idx] + dp_prev[k]) % MOD
print((dp[5]))
return
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
S = S[::-1]
dp = [0] * 13
dp[0] = 1
p = 1
for i, c in enumerate(S):
dp, dp_prev = [0] * 13, dp
for k in range(13):
if c == '?':
for j in range(10):
dp[(p * j + k) % 13] = (dp[(p * j + k) % 13] + dp_prev[k]) % MOD
else:
dp[(p * int(c) + k) % 13] = (dp[(p * int(c) + k) % 13] + dp_prev[k]) % MOD
p = p * 10 % 13
print((dp[5]))
return
if __name__ == '__main__':
main()
| 45
| 35
| 897
| 735
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
N = len(S)
power = [0] * N
power[0] = 1
for i in range(N - 1):
power[i + 1] = 10 * power[i] % 13
S = S[::-1]
Q = []
const = 0
for i, c in enumerate(S):
if c == "?":
Q.append(i)
else:
const = (const + power[i] * int(c)) % 13
dp = [0] * 13
dp[const] = 1
for i in range(len(Q)):
dp, dp_prev = [0] * 13, dp
p = power[Q[i]]
for j in range(10):
for k in range(13):
idx = (p * j + k) % 13
dp[idx] = (dp[idx] + dp_prev[k]) % MOD
print((dp[5]))
return
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
S = S[::-1]
dp = [0] * 13
dp[0] = 1
p = 1
for i, c in enumerate(S):
dp, dp_prev = [0] * 13, dp
for k in range(13):
if c == "?":
for j in range(10):
dp[(p * j + k) % 13] = (dp[(p * j + k) % 13] + dp_prev[k]) % MOD
else:
dp[(p * int(c) + k) % 13] = (
dp[(p * int(c) + k) % 13] + dp_prev[k]
) % MOD
p = p * 10 % 13
print((dp[5]))
return
if __name__ == "__main__":
main()
| false
| 22.222222
|
[
"- N = len(S)",
"- power = [0] * N",
"- power[0] = 1",
"- for i in range(N - 1):",
"- power[i + 1] = 10 * power[i] % 13",
"- Q = []",
"- const = 0",
"+ dp = [0] * 13",
"+ dp[0] = 1",
"+ p = 1",
"- if c == \"?\":",
"- Q.append(i)",
"- else:",
"- const = (const + power[i] * int(c)) % 13",
"- dp = [0] * 13",
"- dp[const] = 1",
"- for i in range(len(Q)):",
"- p = power[Q[i]]",
"- for j in range(10):",
"- for k in range(13):",
"- idx = (p * j + k) % 13",
"- dp[idx] = (dp[idx] + dp_prev[k]) % MOD",
"+ for k in range(13):",
"+ if c == \"?\":",
"+ for j in range(10):",
"+ dp[(p * j + k) % 13] = (dp[(p * j + k) % 13] + dp_prev[k]) % MOD",
"+ else:",
"+ dp[(p * int(c) + k) % 13] = (",
"+ dp[(p * int(c) + k) % 13] + dp_prev[k]",
"+ ) % MOD",
"+ p = p * 10 % 13"
] | false
| 0.072046
| 0.080143
| 0.898965
|
[
"s000689872",
"s182208561"
] |
u222668979
|
p02579
|
python
|
s324525120
|
s522865461
| 1,493
| 1,377
| 99,728
| 99,736
|
Accepted
|
Accepted
| 7.77
|
from collections import deque
from itertools import product
def bfs(x, y):
dist = [[10 ** 9] * w for _ in range(h)]
dist[y][x] = 0
que = deque([(x,y)])
while len(que) > 0:
x, y = que.popleft()
near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
num = product([-2, -1, 0, 1, 2], repeat=2)
near_b = [(x + dx, y + dy) for dx, dy in num]
for cnt, l in enumerate((near_a, near_b)):
for i, j in l:
if (0 <= i < w and 0 <= j < h and
dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'):
dist[j][i] = dist[y][x] + cnt
if cnt == 0:
que.appendleft((i, j))
elif cnt == 1:
que.append((i, j))
return dist
h, w = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = bfs(Cw - 1, Ch - 1)[Dh - 1][Dw - 1]
print((-1 if ans == 10 ** 9 else ans))
|
from collections import deque
from itertools import product
def bfs(x, y):
dist = [[10 ** 9] * w for _ in range(h)]
dist[y][x] = 0
for i, si in enumerate(s):
for j, sij in enumerate(si):
if sij == '#':
dist[i][j] = -1
que = deque([(x, y)])
while len(que) > 0:
x, y = que.popleft()
near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
num = product([-2, -1, 0, 1, 2], repeat=2)
near_b = [(x + dx, y + dy) for dx, dy in num]
for cnt, l in enumerate((near_a, near_b)):
for i, j in l:
if (0 <= i < w and 0 <= j < h and
dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'):
dist[j][i] = dist[y][x] + cnt
if cnt == 0:
que.appendleft((i, j))
elif cnt == 1:
que.append((i, j))
return dist
h, w = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = bfs(Cw - 1, Ch - 1)[Dh - 1][Dw - 1]
print((-1 if ans == 10 ** 9 else ans))
| 34
| 38
| 1,069
| 1,201
|
from collections import deque
from itertools import product
def bfs(x, y):
dist = [[10**9] * w for _ in range(h)]
dist[y][x] = 0
que = deque([(x, y)])
while len(que) > 0:
x, y = que.popleft()
near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
num = product([-2, -1, 0, 1, 2], repeat=2)
near_b = [(x + dx, y + dy) for dx, dy in num]
for cnt, l in enumerate((near_a, near_b)):
for i, j in l:
if (
0 <= i < w
and 0 <= j < h
and dist[j][i] > dist[y][x] + cnt
and s[j][i] == "."
):
dist[j][i] = dist[y][x] + cnt
if cnt == 0:
que.appendleft((i, j))
elif cnt == 1:
que.append((i, j))
return dist
h, w = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = bfs(Cw - 1, Ch - 1)[Dh - 1][Dw - 1]
print((-1 if ans == 10**9 else ans))
|
from collections import deque
from itertools import product
def bfs(x, y):
dist = [[10**9] * w for _ in range(h)]
dist[y][x] = 0
for i, si in enumerate(s):
for j, sij in enumerate(si):
if sij == "#":
dist[i][j] = -1
que = deque([(x, y)])
while len(que) > 0:
x, y = que.popleft()
near_a = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
num = product([-2, -1, 0, 1, 2], repeat=2)
near_b = [(x + dx, y + dy) for dx, dy in num]
for cnt, l in enumerate((near_a, near_b)):
for i, j in l:
if (
0 <= i < w
and 0 <= j < h
and dist[j][i] > dist[y][x] + cnt
and s[j][i] == "."
):
dist[j][i] = dist[y][x] + cnt
if cnt == 0:
que.appendleft((i, j))
elif cnt == 1:
que.append((i, j))
return dist
h, w = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = bfs(Cw - 1, Ch - 1)[Dh - 1][Dw - 1]
print((-1 if ans == 10**9 else ans))
| false
| 10.526316
|
[
"+ for i, si in enumerate(s):",
"+ for j, sij in enumerate(si):",
"+ if sij == \"#\":",
"+ dist[i][j] = -1"
] | false
| 0.043111
| 0.038414
| 1.122279
|
[
"s324525120",
"s522865461"
] |
u633068244
|
p00116
|
python
|
s092585220
|
s063283905
| 2,430
| 2,050
| 10,316
| 10,308
|
Accepted
|
Accepted
| 15.64
|
while 1:
H,W = list(map(int,input().split()))
if H == 0: break
M = [input() for i in range(H)]
A = [[0]*W for i in range(H)]
B = [[0]*W for i in range(H)]
ans = 0
for h in range(H):
L = 0
for w in range(W):
if M[h][w] == ".":
L += 1
else:
L = 0
A[h][w] = L
B[h][w] = (B[h-1][w] if h > 0 else 0) + 1 if L > 0 else 0
if L*B[h][w] > ans:
a = min([A[h-i][w] for i in range(ans/L+1)])
for hi in range(B[h][w]):
a = min(a,A[h-hi][w])
if a*B[h][w] <= ans:
break
ans = max(ans,a*(hi+1))
print(ans)
|
while 1:
H,W = list(map(int,input().split()))
if H == 0: break
M = [input() for i in range(H)]
A = [[0]*W for i in range(H)]
B = [[0]*W for i in range(H)]
ans = 0
for h in range(H):
L = 0
for w in range(W):
if M[h][w] == ".":
L += 1
else:
L = 0
A[h][w] = L
B[h][w] = (B[h-1][w] if h > 0 else 0) + 1 if L > 0 else 0
if L*B[h][w] > ans:
a = L
for hi in range(B[h][w]):
a = min(a,A[h-hi][w])
if a*B[h][w] <= ans:
break
ans = max(ans,a*(hi+1))
print(ans)
| 24
| 24
| 577
| 538
|
while 1:
H, W = list(map(int, input().split()))
if H == 0:
break
M = [input() for i in range(H)]
A = [[0] * W for i in range(H)]
B = [[0] * W for i in range(H)]
ans = 0
for h in range(H):
L = 0
for w in range(W):
if M[h][w] == ".":
L += 1
else:
L = 0
A[h][w] = L
B[h][w] = (B[h - 1][w] if h > 0 else 0) + 1 if L > 0 else 0
if L * B[h][w] > ans:
a = min([A[h - i][w] for i in range(ans / L + 1)])
for hi in range(B[h][w]):
a = min(a, A[h - hi][w])
if a * B[h][w] <= ans:
break
ans = max(ans, a * (hi + 1))
print(ans)
|
while 1:
H, W = list(map(int, input().split()))
if H == 0:
break
M = [input() for i in range(H)]
A = [[0] * W for i in range(H)]
B = [[0] * W for i in range(H)]
ans = 0
for h in range(H):
L = 0
for w in range(W):
if M[h][w] == ".":
L += 1
else:
L = 0
A[h][w] = L
B[h][w] = (B[h - 1][w] if h > 0 else 0) + 1 if L > 0 else 0
if L * B[h][w] > ans:
a = L
for hi in range(B[h][w]):
a = min(a, A[h - hi][w])
if a * B[h][w] <= ans:
break
ans = max(ans, a * (hi + 1))
print(ans)
| false
| 0
|
[
"- a = min([A[h - i][w] for i in range(ans / L + 1)])",
"+ a = L"
] | false
| 0.035684
| 0.054863
| 0.65042
|
[
"s092585220",
"s063283905"
] |
u465699806
|
p03111
|
python
|
s063846553
|
s703036074
| 485
| 60
| 3,828
| 3,188
|
Accepted
|
Accepted
| 87.63
|
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
def dump_impl(*objects):
print(*objects, file=sys.stderr)
def dump_dummy(*objects):
pass
dump = dump_impl if "DEBUG" in sys.argv else dump_dummy
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
ans = 10**20
for use in it.product({0, 1, 2, 3}, repeat=N):
ABC = {0: [], 1: [], 2: [], 3: []}
for i, u in enumerate(use):
dump(i, u, use)
ABC[u].append(l[i])
if any([len(ABC[u]) == 0 for u in {1, 2, 3}]):
continue
ans = min(ans, sum([abs(sum(ABC[i]) - x) + (len(ABC[i]) - 1)
* 10 for i, x in zip([1, 2, 3], [A, B, C])]))
print(ans)
|
n, a, b, c = [int(it) for it in input().split()]
ls = [int(eval(input())) for it in range(n)]
def dfs(cur, tmpA, tmpB, tmpC):
if cur == n:
return abs(a - tmpA) + abs(b - tmpB) + abs(c - tmpC) if tmpA > 0 and tmpB > 0 and tmpC else 10**20
return min(
dfs(cur + 1, tmpA + ls[cur], tmpB, tmpC) + (10 if tmpA > 0 else 0),
dfs(cur + 1, tmpA, tmpB + ls[cur], tmpC) + (10 if tmpB > 0 else 0),
dfs(cur + 1, tmpA, tmpB, tmpC + ls[cur]) + (10 if tmpC > 0 else 0),
dfs(cur + 1, tmpA, tmpB, tmpC)
)
print((dfs(0, 0, 0, 0)))
| 32
| 13
| 811
| 569
|
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
def dump_impl(*objects):
print(*objects, file=sys.stderr)
def dump_dummy(*objects):
pass
dump = dump_impl if "DEBUG" in sys.argv else dump_dummy
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
ans = 10**20
for use in it.product({0, 1, 2, 3}, repeat=N):
ABC = {0: [], 1: [], 2: [], 3: []}
for i, u in enumerate(use):
dump(i, u, use)
ABC[u].append(l[i])
if any([len(ABC[u]) == 0 for u in {1, 2, 3}]):
continue
ans = min(
ans,
sum(
[
abs(sum(ABC[i]) - x) + (len(ABC[i]) - 1) * 10
for i, x in zip([1, 2, 3], [A, B, C])
]
),
)
print(ans)
|
n, a, b, c = [int(it) for it in input().split()]
ls = [int(eval(input())) for it in range(n)]
def dfs(cur, tmpA, tmpB, tmpC):
if cur == n:
return (
abs(a - tmpA) + abs(b - tmpB) + abs(c - tmpC)
if tmpA > 0 and tmpB > 0 and tmpC
else 10**20
)
return min(
dfs(cur + 1, tmpA + ls[cur], tmpB, tmpC) + (10 if tmpA > 0 else 0),
dfs(cur + 1, tmpA, tmpB + ls[cur], tmpC) + (10 if tmpB > 0 else 0),
dfs(cur + 1, tmpA, tmpB, tmpC + ls[cur]) + (10 if tmpC > 0 else 0),
dfs(cur + 1, tmpA, tmpB, tmpC),
)
print((dfs(0, 0, 0, 0)))
| false
| 59.375
|
[
"-import random as rng",
"-import itertools as it",
"-import collections as col",
"-import heapq as hq",
"-import sys",
"-import copy as cp",
"-",
"-sys.setrecursionlimit(10**9)",
"+n, a, b, c = [int(it) for it in input().split()]",
"+ls = [int(eval(input())) for it in range(n)]",
"-def dump_impl(*objects):",
"- print(*objects, file=sys.stderr)",
"+def dfs(cur, tmpA, tmpB, tmpC):",
"+ if cur == n:",
"+ return (",
"+ abs(a - tmpA) + abs(b - tmpB) + abs(c - tmpC)",
"+ if tmpA > 0 and tmpB > 0 and tmpC",
"+ else 10**20",
"+ )",
"+ return min(",
"+ dfs(cur + 1, tmpA + ls[cur], tmpB, tmpC) + (10 if tmpA > 0 else 0),",
"+ dfs(cur + 1, tmpA, tmpB + ls[cur], tmpC) + (10 if tmpB > 0 else 0),",
"+ dfs(cur + 1, tmpA, tmpB, tmpC + ls[cur]) + (10 if tmpC > 0 else 0),",
"+ dfs(cur + 1, tmpA, tmpB, tmpC),",
"+ )",
"-def dump_dummy(*objects):",
"- pass",
"-",
"-",
"-dump = dump_impl if \"DEBUG\" in sys.argv else dump_dummy",
"-N, A, B, C = map(int, input().split())",
"-l = [int(input()) for i in range(N)]",
"-ans = 10**20",
"-for use in it.product({0, 1, 2, 3}, repeat=N):",
"- ABC = {0: [], 1: [], 2: [], 3: []}",
"- for i, u in enumerate(use):",
"- dump(i, u, use)",
"- ABC[u].append(l[i])",
"- if any([len(ABC[u]) == 0 for u in {1, 2, 3}]):",
"- continue",
"- ans = min(",
"- ans,",
"- sum(",
"- [",
"- abs(sum(ABC[i]) - x) + (len(ABC[i]) - 1) * 10",
"- for i, x in zip([1, 2, 3], [A, B, C])",
"- ]",
"- ),",
"- )",
"-print(ans)",
"+print((dfs(0, 0, 0, 0)))"
] | false
| 0.367132
| 0.134578
| 2.728019
|
[
"s063846553",
"s703036074"
] |
u887207211
|
p03307
|
python
|
s184852002
|
s178773130
| 19
| 17
| 3,064
| 2,940
|
Accepted
|
Accepted
| 10.53
|
N = int(eval(input()))
def gcd(m, n):
while n:
m, n = n, m%n
return m
def lcm(m, n):
return int((m * n) / gcd(m, n))
print((lcm(N,2)))
|
N = int(eval(input()))
def gcd(m, n):
while n:
m, n = n, m%n
return m
def lcm(m, n):
print((m * n // gcd(m, n)))
lcm(N,2)
| 11
| 11
| 149
| 136
|
N = int(eval(input()))
def gcd(m, n):
while n:
m, n = n, m % n
return m
def lcm(m, n):
return int((m * n) / gcd(m, n))
print((lcm(N, 2)))
|
N = int(eval(input()))
def gcd(m, n):
while n:
m, n = n, m % n
return m
def lcm(m, n):
print((m * n // gcd(m, n)))
lcm(N, 2)
| false
| 0
|
[
"- return int((m * n) / gcd(m, n))",
"+ print((m * n // gcd(m, n)))",
"-print((lcm(N, 2)))",
"+lcm(N, 2)"
] | false
| 0.051334
| 0.050814
| 1.010238
|
[
"s184852002",
"s178773130"
] |
u614181788
|
p03329
|
python
|
s287014635
|
s635911655
| 1,218
| 1,003
| 9,616
| 9,592
|
Accepted
|
Accepted
| 17.65
|
n = int(eval(input()))
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n):
for j in range(1,6):
if i + j > n:
break
dp[i+j] = min(dp[i+j], dp[i] + j)
for j in range(1,n//6+1):
if i + 6**j > n:
break
dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)
for j in range(1,n//9+1):
if i + 9**j > n:
break
dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)
print((dp[-1]))
|
n = int(eval(input()))
dp = [float("Inf")]*(n+1)
for i in range(min(6, n+1)):
dp[i] = i
for i in range(n):
for j in range(1,n//6+1):
if i + 6**j > n:
break
dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)
for j in range(1,n//9+1):
if i + 9**j > n:
break
dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)
print((dp[-1]))
| 17
| 14
| 450
| 373
|
n = int(eval(input()))
dp = [float("Inf")] * (n + 1)
dp[0] = 0
for i in range(n):
for j in range(1, 6):
if i + j > n:
break
dp[i + j] = min(dp[i + j], dp[i] + j)
for j in range(1, n // 6 + 1):
if i + 6**j > n:
break
dp[i + 6**j] = min(dp[i + 6**j], dp[i] + 1)
for j in range(1, n // 9 + 1):
if i + 9**j > n:
break
dp[i + 9**j] = min(dp[i + 9**j], dp[i] + 1)
print((dp[-1]))
|
n = int(eval(input()))
dp = [float("Inf")] * (n + 1)
for i in range(min(6, n + 1)):
dp[i] = i
for i in range(n):
for j in range(1, n // 6 + 1):
if i + 6**j > n:
break
dp[i + 6**j] = min(dp[i + 6**j], dp[i] + 1)
for j in range(1, n // 9 + 1):
if i + 9**j > n:
break
dp[i + 9**j] = min(dp[i + 9**j], dp[i] + 1)
print((dp[-1]))
| false
| 17.647059
|
[
"-dp[0] = 0",
"+for i in range(min(6, n + 1)):",
"+ dp[i] = i",
"- for j in range(1, 6):",
"- if i + j > n:",
"- break",
"- dp[i + j] = min(dp[i + j], dp[i] + j)"
] | false
| 0.427141
| 0.250294
| 1.706557
|
[
"s287014635",
"s635911655"
] |
u968166680
|
p04013
|
python
|
s283997454
|
s309894581
| 102
| 87
| 70,268
| 67,276
|
Accepted
|
Accepted
| 14.71
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
dp = [[0] * (N * 50 + 1) for j in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(N, -1, -1):
for k in range(N * 50 + 1):
if k - X[i] >= 0 and j > 0:
dp[j][k] += dp[j - 1][k - X[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[j][A * j]
print(ans)
return
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
dp = [[0] * (N * 50 + 1) for j in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(N, 0, -1):
for k in range(X[i], N * 50 + 1):
dp[j][k] += dp[j - 1][k - X[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[j][A * j]
print(ans)
return
if __name__ == '__main__':
main()
| 32
| 31
| 646
| 602
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
dp = [[0] * (N * 50 + 1) for j in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(N, -1, -1):
for k in range(N * 50 + 1):
if k - X[i] >= 0 and j > 0:
dp[j][k] += dp[j - 1][k - X[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[j][A * j]
print(ans)
return
if __name__ == "__main__":
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
dp = [[0] * (N * 50 + 1) for j in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(N, 0, -1):
for k in range(X[i], N * 50 + 1):
dp[j][k] += dp[j - 1][k - X[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[j][A * j]
print(ans)
return
if __name__ == "__main__":
main()
| false
| 3.125
|
[
"- for j in range(N, -1, -1):",
"- for k in range(N * 50 + 1):",
"- if k - X[i] >= 0 and j > 0:",
"- dp[j][k] += dp[j - 1][k - X[i]]",
"+ for j in range(N, 0, -1):",
"+ for k in range(X[i], N * 50 + 1):",
"+ dp[j][k] += dp[j - 1][k - X[i]]"
] | false
| 0.046325
| 0.033187
| 1.39586
|
[
"s283997454",
"s309894581"
] |
u951814007
|
p02714
|
python
|
s714496235
|
s130843323
| 768
| 135
| 75,532
| 68,280
|
Accepted
|
Accepted
| 82.42
|
n = int(eval(input()))
s = eval(input())
count = {"R":0,"G":0,"B":0}
for c in s:
count[c] += 1
r,g,b = list(count.values())
ans = r*g*b
for i in range(1,(n-1)//2+1): #1から
for rgb in zip(s,s[i:],s[i*2:]): #rgbに連続した三つのリストの要素を入れ込む
if len(set(rgb)) == 3: #リストrgbをセットにまとめ、長さが
ans -=1
print(ans)
|
n = int(eval(input()))
s = eval(input())
r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')
ans = r_cnt * g_cnt * b_cnt
for i in range(n): #s[i]
for d in range(n):
j = i + d #s[j] s[i]etcこれらは等間隔となるが
k = j + d #s[k] この時点でi!=j, j!=k, i!=k
if k >= n:break #kが一番大きいが、n以上になることはない
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
ans -= 1 #等間隔でRGB揃っているものを引く
print(ans)
| 14
| 18
| 318
| 454
|
n = int(eval(input()))
s = eval(input())
count = {"R": 0, "G": 0, "B": 0}
for c in s:
count[c] += 1
r, g, b = list(count.values())
ans = r * g * b
for i in range(1, (n - 1) // 2 + 1): # 1から
for rgb in zip(s, s[i:], s[i * 2 :]): # rgbに連続した三つのリストの要素を入れ込む
if len(set(rgb)) == 3: # リストrgbをセットにまとめ、長さが
ans -= 1
print(ans)
|
n = int(eval(input()))
s = eval(input())
r_cnt = s.count("R")
g_cnt = s.count("G")
b_cnt = s.count("B")
ans = r_cnt * g_cnt * b_cnt
for i in range(n): # s[i]
for d in range(n):
j = i + d # s[j] s[i]etcこれらは等間隔となるが
k = j + d # s[k] この時点でi!=j, j!=k, i!=k
if k >= n:
break # kが一番大きいが、n以上になることはない
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
ans -= 1 # 等間隔でRGB揃っているものを引く
print(ans)
| false
| 22.222222
|
[
"-count = {\"R\": 0, \"G\": 0, \"B\": 0}",
"-for c in s:",
"- count[c] += 1",
"-r, g, b = list(count.values())",
"-ans = r * g * b",
"-for i in range(1, (n - 1) // 2 + 1): # 1から",
"- for rgb in zip(s, s[i:], s[i * 2 :]): # rgbに連続した三つのリストの要素を入れ込む",
"- if len(set(rgb)) == 3: # リストrgbをセットにまとめ、長さが",
"- ans -= 1",
"+r_cnt = s.count(\"R\")",
"+g_cnt = s.count(\"G\")",
"+b_cnt = s.count(\"B\")",
"+ans = r_cnt * g_cnt * b_cnt",
"+for i in range(n): # s[i]",
"+ for d in range(n):",
"+ j = i + d # s[j] s[i]etcこれらは等間隔となるが",
"+ k = j + d # s[k] この時点でi!=j, j!=k, i!=k",
"+ if k >= n:",
"+ break # kが一番大きいが、n以上になることはない",
"+ if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:",
"+ ans -= 1 # 等間隔でRGB揃っているものを引く"
] | false
| 0.038754
| 0.047264
| 0.819945
|
[
"s714496235",
"s130843323"
] |
u103902792
|
p03295
|
python
|
s026578427
|
s393148452
| 444
| 379
| 17,468
| 18,204
|
Accepted
|
Accepted
| 14.64
|
n,m = list(map(int,input().split()))
cut = []
for _ in range(m):
a,b = list(map(int,input().split()))
cut.append((a,b))
cut.sort()
b_min = cut[0][1]
count = 0
for a,b in cut[1:]:
if b_min > b:
b_min = b
continue
if b_min <= a:
count += 1
b_min = b
print((count+1))
|
n,m = list(map(int,input().split()))
cut = []
for _ in range(m):
a,b = list(map(int,input().split()))
cut.append((a,b))
cut.sort(key = lambda x:x[1])
ex_b = cut[0][1]
count = 0
for a,b in cut[1:]:
if a >= ex_b:
count += 1
ex_b = b
print((count+1))
| 22
| 15
| 303
| 265
|
n, m = list(map(int, input().split()))
cut = []
for _ in range(m):
a, b = list(map(int, input().split()))
cut.append((a, b))
cut.sort()
b_min = cut[0][1]
count = 0
for a, b in cut[1:]:
if b_min > b:
b_min = b
continue
if b_min <= a:
count += 1
b_min = b
print((count + 1))
|
n, m = list(map(int, input().split()))
cut = []
for _ in range(m):
a, b = list(map(int, input().split()))
cut.append((a, b))
cut.sort(key=lambda x: x[1])
ex_b = cut[0][1]
count = 0
for a, b in cut[1:]:
if a >= ex_b:
count += 1
ex_b = b
print((count + 1))
| false
| 31.818182
|
[
"-cut.sort()",
"-b_min = cut[0][1]",
"+cut.sort(key=lambda x: x[1])",
"+ex_b = cut[0][1]",
"- if b_min > b:",
"- b_min = b",
"- continue",
"- if b_min <= a:",
"+ if a >= ex_b:",
"- b_min = b",
"+ ex_b = b"
] | false
| 0.0407
| 0.037349
| 1.089722
|
[
"s026578427",
"s393148452"
] |
u135847648
|
p03339
|
python
|
s281558813
|
s119361640
| 499
| 355
| 43,852
| 4,084
|
Accepted
|
Accepted
| 28.86
|
import collections
n = int(eval(input()))
s = eval(input())
dic = dict(collections.Counter(s))
#W,Eどちらかしか無い場合
if len(dic)==1:
print((0))
exit()
left_w = 0
right_e = dic["E"]
cnt = [[] for _ in range(n)]
#(左にあるWの数+右にあるEの数)の最小値が答え
ans = n
for i in range(n):
if s[i] == "W":
cnt[i] = [left_w,right_e]
ans = min(ans,left_w+right_e)
left_w += 1
elif s[i] == "E":
cnt[i] = [left_w,right_e]
ans = min(ans,left_w+right_e)
right_e -= 1
#(右にあるWの数+左にあるEの数)の最小値が答えの場合もあるか
left_e = 0
right_w = dic["W"]
for i in range(n-1,-1,-1):
if s[i] == "E":
ans = min(ans,left_e+right_w)
left_e += 1
elif s[i] == "W":
ans = min(ans,left_e + right_w)
right_w -= 1
print(ans)
|
import collections
n = int(eval(input()))
s = eval(input())
dic = dict(collections.Counter(s))
#W,Eどちらかしか無い場合
if len(dic)==1:
print((0))
exit()
left_w = 0
right_e = dic["E"]
#(左にあるWの数+右にあるEの数)の最小値が答え
ans = n
for i in range(n):
if s[i] == "W":
ans = min(ans,left_w+right_e)
left_w += 1
elif s[i] == "E":
ans = min(ans,left_w+right_e)
right_e -= 1
#(右にあるWの数+左にあるEの数)の最小値が答えの場合もあるか
left_e = 0
right_w = dic["W"]
for i in range(n-1,-1,-1):
if s[i] == "E":
ans = min(ans,left_e+right_w)
left_e += 1
elif s[i] == "W":
ans = min(ans,left_e + right_w)
right_w -= 1
print(ans)
| 39
| 35
| 731
| 637
|
import collections
n = int(eval(input()))
s = eval(input())
dic = dict(collections.Counter(s))
# W,Eどちらかしか無い場合
if len(dic) == 1:
print((0))
exit()
left_w = 0
right_e = dic["E"]
cnt = [[] for _ in range(n)]
# (左にあるWの数+右にあるEの数)の最小値が答え
ans = n
for i in range(n):
if s[i] == "W":
cnt[i] = [left_w, right_e]
ans = min(ans, left_w + right_e)
left_w += 1
elif s[i] == "E":
cnt[i] = [left_w, right_e]
ans = min(ans, left_w + right_e)
right_e -= 1
# (右にあるWの数+左にあるEの数)の最小値が答えの場合もあるか
left_e = 0
right_w = dic["W"]
for i in range(n - 1, -1, -1):
if s[i] == "E":
ans = min(ans, left_e + right_w)
left_e += 1
elif s[i] == "W":
ans = min(ans, left_e + right_w)
right_w -= 1
print(ans)
|
import collections
n = int(eval(input()))
s = eval(input())
dic = dict(collections.Counter(s))
# W,Eどちらかしか無い場合
if len(dic) == 1:
print((0))
exit()
left_w = 0
right_e = dic["E"]
# (左にあるWの数+右にあるEの数)の最小値が答え
ans = n
for i in range(n):
if s[i] == "W":
ans = min(ans, left_w + right_e)
left_w += 1
elif s[i] == "E":
ans = min(ans, left_w + right_e)
right_e -= 1
# (右にあるWの数+左にあるEの数)の最小値が答えの場合もあるか
left_e = 0
right_w = dic["W"]
for i in range(n - 1, -1, -1):
if s[i] == "E":
ans = min(ans, left_e + right_w)
left_e += 1
elif s[i] == "W":
ans = min(ans, left_e + right_w)
right_w -= 1
print(ans)
| false
| 10.25641
|
[
"-cnt = [[] for _ in range(n)]",
"- cnt[i] = [left_w, right_e]",
"- cnt[i] = [left_w, right_e]"
] | false
| 0.045946
| 0.045664
| 1.00618
|
[
"s281558813",
"s119361640"
] |
u131811591
|
p02329
|
python
|
s912345391
|
s647350387
| 1,120
| 1,020
| 179,080
| 179,044
|
Accepted
|
Accepted
| 8.93
|
import sys
from collections import defaultdict
if __name__ == '__main__':
n, v = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))
d = list(map(int, sys.stdin.readline().split()))
mp = defaultdict(int)
ls = []
for val1 in c:
for val2 in d:
mp[val1+val2] += 1
ans = 0
for val1 in a:
for val2 in b:
ans += mp[v-val1-val2]
print(ans)
|
import sys
from collections import defaultdict
if __name__ == '__main__':
n, v = list(map(int, sys.stdin.readline().split()))
a = tuple(map(int, sys.stdin.readline().split()))
b = tuple(map(int, sys.stdin.readline().split()))
c = tuple(map(int, sys.stdin.readline().split()))
d = tuple(map(int, sys.stdin.readline().split()))
mp = defaultdict(int)
ls = []
for val1 in c:
for val2 in d:
mp[val1+val2] += 1
ans = 0
for val1 in a:
for val2 in b:
ans += mp[v-val1-val2]
print(ans)
| 20
| 20
| 571
| 575
|
import sys
from collections import defaultdict
if __name__ == "__main__":
n, v = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))
d = list(map(int, sys.stdin.readline().split()))
mp = defaultdict(int)
ls = []
for val1 in c:
for val2 in d:
mp[val1 + val2] += 1
ans = 0
for val1 in a:
for val2 in b:
ans += mp[v - val1 - val2]
print(ans)
|
import sys
from collections import defaultdict
if __name__ == "__main__":
n, v = list(map(int, sys.stdin.readline().split()))
a = tuple(map(int, sys.stdin.readline().split()))
b = tuple(map(int, sys.stdin.readline().split()))
c = tuple(map(int, sys.stdin.readline().split()))
d = tuple(map(int, sys.stdin.readline().split()))
mp = defaultdict(int)
ls = []
for val1 in c:
for val2 in d:
mp[val1 + val2] += 1
ans = 0
for val1 in a:
for val2 in b:
ans += mp[v - val1 - val2]
print(ans)
| false
| 0
|
[
"- a = list(map(int, sys.stdin.readline().split()))",
"- b = list(map(int, sys.stdin.readline().split()))",
"- c = list(map(int, sys.stdin.readline().split()))",
"- d = list(map(int, sys.stdin.readline().split()))",
"+ a = tuple(map(int, sys.stdin.readline().split()))",
"+ b = tuple(map(int, sys.stdin.readline().split()))",
"+ c = tuple(map(int, sys.stdin.readline().split()))",
"+ d = tuple(map(int, sys.stdin.readline().split()))"
] | false
| 0.04179
| 0.086562
| 0.482776
|
[
"s912345391",
"s647350387"
] |
u119148115
|
p03311
|
python
|
s779472868
|
s365607907
| 142
| 130
| 94,456
| 104,448
|
Accepted
|
Accepted
| 8.45
|
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N = I()
A = LI()
for i in range(N):
A[i] -= i+1
A.sort()
def f(x):
return sum(abs(A[i]-x) for i in range(N))
print((f((A[(N-1)//2]+A[N//2])//2)))
# 中間値
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
A = LI()
for i in range(N):
A[i] -= i+1
A.sort()
x = A[N//2]
y = A[(N-1)//2]
z = (x+y)//2
print((sum(abs(A[i]-z) for i in range(N))))
| 18
| 23
| 320
| 648
|
import sys
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
N = I()
A = LI()
for i in range(N):
A[i] -= i + 1
A.sort()
def f(x):
return sum(abs(A[i] - x) for i in range(N))
print((f((A[(N - 1) // 2] + A[N // 2]) // 2)))
# 中間値
|
import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
A = LI()
for i in range(N):
A[i] -= i + 1
A.sort()
x = A[N // 2]
y = A[(N - 1) // 2]
z = (x + y) // 2
print((sum(abs(A[i] - z) for i in range(N))))
| false
| 21.73913
|
[
"+",
"+sys.setrecursionlimit(10**7)",
"+def MI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split()))",
"+",
"+",
"+",
"+",
"+def LI2():",
"+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"+",
"+",
"+def S():",
"+ return sys.stdin.readline().rstrip()",
"+",
"+",
"+def LS():",
"+ return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"+",
"+",
"+def LS2():",
"+ return list(sys.stdin.readline().rstrip()) # 空白なし",
"-",
"-",
"-def f(x):",
"- return sum(abs(A[i] - x) for i in range(N))",
"-",
"-",
"-print((f((A[(N - 1) // 2] + A[N // 2]) // 2)))",
"-# 中間値",
"+x = A[N // 2]",
"+y = A[(N - 1) // 2]",
"+z = (x + y) // 2",
"+print((sum(abs(A[i] - z) for i in range(N))))"
] | false
| 0.086456
| 0.087471
| 0.988396
|
[
"s779472868",
"s365607907"
] |
u919633157
|
p03107
|
python
|
s228176656
|
s662821856
| 34
| 18
| 3,188
| 3,188
|
Accepted
|
Accepted
| 47.06
|
# 2019/07/25
s=eval(input())
cnt=0
for e in s:
if e=='1':cnt+=1
else:cnt-=1
print((len(s)-abs(cnt)))
|
s=eval(input())
z=s.count('0')
o=s.count('1')
print((len(s)-abs(z-o)))
| 9
| 4
| 110
| 65
|
# 2019/07/25
s = eval(input())
cnt = 0
for e in s:
if e == "1":
cnt += 1
else:
cnt -= 1
print((len(s) - abs(cnt)))
|
s = eval(input())
z = s.count("0")
o = s.count("1")
print((len(s) - abs(z - o)))
| false
| 55.555556
|
[
"-# 2019/07/25",
"-cnt = 0",
"-for e in s:",
"- if e == \"1\":",
"- cnt += 1",
"- else:",
"- cnt -= 1",
"-print((len(s) - abs(cnt)))",
"+z = s.count(\"0\")",
"+o = s.count(\"1\")",
"+print((len(s) - abs(z - o)))"
] | false
| 0.04462
| 0.043597
| 1.023467
|
[
"s228176656",
"s662821856"
] |
u546285759
|
p00011
|
python
|
s660766099
|
s257798072
| 30
| 20
| 7,604
| 5,600
|
Accepted
|
Accepted
| 33.33
|
w = int(input())
n = int(input())
am = [i for i in range(w+1)]
for _ in range(n):
a, b = map(int, input().split(','))
am[a], am[b] = am[b], am[a]
print(*am[1:], sep="\n")
|
w = int(input())
n = int(input())
kuji = [i+1 for i in range(w)]
for _ in range(n):
a, b = map(int, input().split(','))
kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1]
print(*kuji, sep="\n")
| 7
| 8
| 184
| 203
|
w = int(input())
n = int(input())
am = [i for i in range(w + 1)]
for _ in range(n):
a, b = map(int, input().split(","))
am[a], am[b] = am[b], am[a]
print(*am[1:], sep="\n")
|
w = int(input())
n = int(input())
kuji = [i + 1 for i in range(w)]
for _ in range(n):
a, b = map(int, input().split(","))
kuji[a - 1], kuji[b - 1] = kuji[b - 1], kuji[a - 1]
print(*kuji, sep="\n")
| false
| 12.5
|
[
"-am = [i for i in range(w + 1)]",
"+kuji = [i + 1 for i in range(w)]",
"- am[a], am[b] = am[b], am[a]",
"-print(*am[1:], sep=\"\\n\")",
"+ kuji[a - 1], kuji[b - 1] = kuji[b - 1], kuji[a - 1]",
"+print(*kuji, sep=\"\\n\")"
] | false
| 0.153163
| 0.056361
| 2.717528
|
[
"s660766099",
"s257798072"
] |
u436807165
|
p02388
|
python
|
s322614691
|
s723950792
| 30
| 10
| 6,424
| 6,424
|
Accepted
|
Accepted
| 66.67
|
input = input()
print(int(input) ** 3)
|
x = eval(input())
print(x**3)
| 2
| 2
| 42
| 23
|
input = input()
print(int(input) ** 3)
|
x = eval(input())
print(x**3)
| false
| 0
|
[
"-input = input()",
"-print(int(input) ** 3)",
"+x = eval(input())",
"+print(x**3)"
] | false
| 0.078395
| 0.045304
| 1.730416
|
[
"s322614691",
"s723950792"
] |
u670180528
|
p03295
|
python
|
s691112087
|
s041176321
| 141
| 127
| 25,132
| 25,132
|
Accepted
|
Accepted
| 9.93
|
n,m,*t=list(map(int,open(0).read().split()));r=[n+1]*(n+1)
for a,b in zip(*[iter(t)]*2):
r[a]=min(r[a],b)
a=0;cur=n+1
for i in range(n+1):
cur=min(cur, r[i])
if i==cur:
cur=r[i]
a+=1
print(a)
|
def solve():
n,_,*t=list(map(int,open(0).read().split()));r=[n+1]*(n+1)
for a,b in zip(*[iter(t)]*2):
r[a]=min(r[a],b)
a=0;cur=n+1
for i in range(n+1):
cur=min(cur, r[i])
if i==cur:
#追いついた
cur=r[i]
a+=1
print(a)
if __name__=="__main__":
solve()
| 10
| 14
| 201
| 272
|
n, m, *t = list(map(int, open(0).read().split()))
r = [n + 1] * (n + 1)
for a, b in zip(*[iter(t)] * 2):
r[a] = min(r[a], b)
a = 0
cur = n + 1
for i in range(n + 1):
cur = min(cur, r[i])
if i == cur:
cur = r[i]
a += 1
print(a)
|
def solve():
n, _, *t = list(map(int, open(0).read().split()))
r = [n + 1] * (n + 1)
for a, b in zip(*[iter(t)] * 2):
r[a] = min(r[a], b)
a = 0
cur = n + 1
for i in range(n + 1):
cur = min(cur, r[i])
if i == cur:
# 追いついた
cur = r[i]
a += 1
print(a)
if __name__ == "__main__":
solve()
| false
| 28.571429
|
[
"-n, m, *t = list(map(int, open(0).read().split()))",
"-r = [n + 1] * (n + 1)",
"-for a, b in zip(*[iter(t)] * 2):",
"- r[a] = min(r[a], b)",
"-a = 0",
"-cur = n + 1",
"-for i in range(n + 1):",
"- cur = min(cur, r[i])",
"- if i == cur:",
"- cur = r[i]",
"- a += 1",
"-print(a)",
"+def solve():",
"+ n, _, *t = list(map(int, open(0).read().split()))",
"+ r = [n + 1] * (n + 1)",
"+ for a, b in zip(*[iter(t)] * 2):",
"+ r[a] = min(r[a], b)",
"+ a = 0",
"+ cur = n + 1",
"+ for i in range(n + 1):",
"+ cur = min(cur, r[i])",
"+ if i == cur:",
"+ # 追いついた",
"+ cur = r[i]",
"+ a += 1",
"+ print(a)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false
| 0.035886
| 0.041625
| 0.862128
|
[
"s691112087",
"s041176321"
] |
u952708174
|
p03472
|
python
|
s739247466
|
s974530419
| 615
| 360
| 36,624
| 22,284
|
Accepted
|
Accepted
| 41.46
|
def d_Katana_Thrower(N, H, S):
import numpy
import math
swing = numpy.asarray([x[0] for x in S])
throw = numpy.asarray([x[1] for x in S])
swing_max = numpy.max(swing)
throw_t = throw[throw >= swing_max]
throw_t = sorted(throw_t, reverse=True)
hp = H
ans = 0
for d in throw_t:
if hp <= 0:
break
hp -= d
ans += 1
if hp > 0:
ans += math.ceil(hp / swing_max)
return ans
N,H=[int(i) for i in input().split()]
S=[[int(i) for i in input().split()] for j in range(N)]
print((d_Katana_Thrower(N, H, S)))
|
def d_katana_thrower(N, H, Swords):
import math
# 振ったとき最もダメージが大きい刀以上に投げたときのダメージが大きな刀
# について、ダメージが大きなものから投げていく。そのダメージの総和が
# 敵の体力より大きければ投げて倒せばいいし、足りなければ刀を降って倒せばいい。
# ただし、振る刀の投げダメージが振るより高ければ、投げる前に振らなければならないが、
# 計算時には「投げてから振る」とみなしても問題ない。
swing_damage_max = max([s[0] for s in Swords])
throw_higher_than_swing = [s[1] for s in Swords if s[1] >= swing_damage_max]
throw_higher_than_swing.sort(reverse=True)
minimum_moving = 0
for damage in throw_higher_than_swing:
if H <= 0: # 刀を投げている途中で敵を倒したら終わり
H = 0
break
H -= damage
minimum_moving += 1
minimum_moving += math.ceil(H / swing_damage_max)
return minimum_moving
N, H = [int(i) for i in input().split()]
Swords = [[int(i) for i in input().split()] for j in range(N)]
print((d_katana_thrower(N, H, Swords)))
| 25
| 24
| 614
| 875
|
def d_Katana_Thrower(N, H, S):
import numpy
import math
swing = numpy.asarray([x[0] for x in S])
throw = numpy.asarray([x[1] for x in S])
swing_max = numpy.max(swing)
throw_t = throw[throw >= swing_max]
throw_t = sorted(throw_t, reverse=True)
hp = H
ans = 0
for d in throw_t:
if hp <= 0:
break
hp -= d
ans += 1
if hp > 0:
ans += math.ceil(hp / swing_max)
return ans
N, H = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(N)]
print((d_Katana_Thrower(N, H, S)))
|
def d_katana_thrower(N, H, Swords):
import math
# 振ったとき最もダメージが大きい刀以上に投げたときのダメージが大きな刀
# について、ダメージが大きなものから投げていく。そのダメージの総和が
# 敵の体力より大きければ投げて倒せばいいし、足りなければ刀を降って倒せばいい。
# ただし、振る刀の投げダメージが振るより高ければ、投げる前に振らなければならないが、
# 計算時には「投げてから振る」とみなしても問題ない。
swing_damage_max = max([s[0] for s in Swords])
throw_higher_than_swing = [s[1] for s in Swords if s[1] >= swing_damage_max]
throw_higher_than_swing.sort(reverse=True)
minimum_moving = 0
for damage in throw_higher_than_swing:
if H <= 0: # 刀を投げている途中で敵を倒したら終わり
H = 0
break
H -= damage
minimum_moving += 1
minimum_moving += math.ceil(H / swing_damage_max)
return minimum_moving
N, H = [int(i) for i in input().split()]
Swords = [[int(i) for i in input().split()] for j in range(N)]
print((d_katana_thrower(N, H, Swords)))
| false
| 4
|
[
"-def d_Katana_Thrower(N, H, S):",
"- import numpy",
"+def d_katana_thrower(N, H, Swords):",
"- swing = numpy.asarray([x[0] for x in S])",
"- throw = numpy.asarray([x[1] for x in S])",
"- swing_max = numpy.max(swing)",
"- throw_t = throw[throw >= swing_max]",
"- throw_t = sorted(throw_t, reverse=True)",
"- hp = H",
"- ans = 0",
"- for d in throw_t:",
"- if hp <= 0:",
"+ # 振ったとき最もダメージが大きい刀以上に投げたときのダメージが大きな刀",
"+ # について、ダメージが大きなものから投げていく。そのダメージの総和が",
"+ # 敵の体力より大きければ投げて倒せばいいし、足りなければ刀を降って倒せばいい。",
"+ # ただし、振る刀の投げダメージが振るより高ければ、投げる前に振らなければならないが、",
"+ # 計算時には「投げてから振る」とみなしても問題ない。",
"+ swing_damage_max = max([s[0] for s in Swords])",
"+ throw_higher_than_swing = [s[1] for s in Swords if s[1] >= swing_damage_max]",
"+ throw_higher_than_swing.sort(reverse=True)",
"+ minimum_moving = 0",
"+ for damage in throw_higher_than_swing:",
"+ if H <= 0: # 刀を投げている途中で敵を倒したら終わり",
"+ H = 0",
"- hp -= d",
"- ans += 1",
"- if hp > 0:",
"- ans += math.ceil(hp / swing_max)",
"- return ans",
"+ H -= damage",
"+ minimum_moving += 1",
"+ minimum_moving += math.ceil(H / swing_damage_max)",
"+ return minimum_moving",
"-S = [[int(i) for i in input().split()] for j in range(N)]",
"-print((d_Katana_Thrower(N, H, S)))",
"+Swords = [[int(i) for i in input().split()] for j in range(N)]",
"+print((d_katana_thrower(N, H, Swords)))"
] | false
| 0.241095
| 0.045371
| 5.313838
|
[
"s739247466",
"s974530419"
] |
u620084012
|
p02835
|
python
|
s760035256
|
s741996088
| 205
| 17
| 38,384
| 2,940
|
Accepted
|
Accepted
| 91.71
|
A, B, C = list(map(int,input().split()))
if A+B+C >= 22:
print("bust")
else:
print("win")
|
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
# N = int(input())
A, B, C = list(map(int,input().split()))
# S = input()
print(("bust" if (A+B+C) >= 22 else "win"))
if __name__ == '__main__':
main()
| 5
| 10
| 96
| 244
|
A, B, C = list(map(int, input().split()))
if A + B + C >= 22:
print("bust")
else:
print("win")
|
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
# N = int(input())
A, B, C = list(map(int, input().split()))
# S = input()
print(("bust" if (A + B + C) >= 22 else "win"))
if __name__ == "__main__":
main()
| false
| 50
|
[
"-A, B, C = list(map(int, input().split()))",
"-if A + B + C >= 22:",
"- print(\"bust\")",
"-else:",
"- print(\"win\")",
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"+def main():",
"+ # N = int(input())",
"+ A, B, C = list(map(int, input().split()))",
"+ # S = input()",
"+ print((\"bust\" if (A + B + C) >= 22 else \"win\"))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.066831
| 0.037386
| 1.787564
|
[
"s760035256",
"s741996088"
] |
u746419473
|
p02813
|
python
|
s993618348
|
s037488834
| 29
| 26
| 8,052
| 8,052
|
Accepted
|
Accepted
| 10.34
|
import itertools
import bisect
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
*per, = itertools.permutations(list(range(1, n+1)))
a = bisect.bisect_right(per, p)
b = bisect.bisect_right(per, q)
print((abs(a-b)))
|
import bisect
import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
*perm, = itertools.permutations(list(range(1, n+1)), n)
a = bisect.bisect_right(perm, p)
b = bisect.bisect_right(perm, q)
print((abs(a-b)))
| 12
| 10
| 262
| 270
|
import itertools
import bisect
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
(*per,) = itertools.permutations(list(range(1, n + 1)))
a = bisect.bisect_right(per, p)
b = bisect.bisect_right(per, q)
print((abs(a - b)))
|
import bisect
import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
(*perm,) = itertools.permutations(list(range(1, n + 1)), n)
a = bisect.bisect_right(perm, p)
b = bisect.bisect_right(perm, q)
print((abs(a - b)))
| false
| 16.666667
|
[
"+import bisect",
"-import bisect",
"-(*per,) = itertools.permutations(list(range(1, n + 1)))",
"-a = bisect.bisect_right(per, p)",
"-b = bisect.bisect_right(per, q)",
"+(*perm,) = itertools.permutations(list(range(1, n + 1)), n)",
"+a = bisect.bisect_right(perm, p)",
"+b = bisect.bisect_right(perm, q)"
] | false
| 0.047882
| 0.090238
| 0.530622
|
[
"s993618348",
"s037488834"
] |
u513081876
|
p03252
|
python
|
s325974456
|
s537079097
| 258
| 121
| 6,832
| 3,888
|
Accepted
|
Accepted
| 53.1
|
S = eval(input())
T = eval(input())
used = []
res = []
for i in range(len(S)):
if S[i] not in used:
used.append(S[i])
res.append(used.index(S[i]))
#print(used)
#print(res)
used = []
ret = []
for i in range(len(T)):
if T[i] not in used:
used.append(T[i])
ret.append(used.index(T[i]))
if res == ret:
print('Yes')
else:
print('No')
|
import sys
from collections import defaultdict
S = eval(input())
T = eval(input())
L = len(S)
dcts = defaultdict(int)
dctt = defaultdict(int)
for i in range(L):
s = S[i]
t = T[i]
if dcts[s] == 0:
dcts[s] = t
else:
if dcts[s] != t:
print('No')
sys.exit()
if dctt[t] == 0:
dctt[t] = s
else:
if dctt[t] != s:
print('No')
sys.exit()
print('Yes')
| 25
| 25
| 386
| 459
|
S = eval(input())
T = eval(input())
used = []
res = []
for i in range(len(S)):
if S[i] not in used:
used.append(S[i])
res.append(used.index(S[i]))
# print(used)
# print(res)
used = []
ret = []
for i in range(len(T)):
if T[i] not in used:
used.append(T[i])
ret.append(used.index(T[i]))
if res == ret:
print("Yes")
else:
print("No")
|
import sys
from collections import defaultdict
S = eval(input())
T = eval(input())
L = len(S)
dcts = defaultdict(int)
dctt = defaultdict(int)
for i in range(L):
s = S[i]
t = T[i]
if dcts[s] == 0:
dcts[s] = t
else:
if dcts[s] != t:
print("No")
sys.exit()
if dctt[t] == 0:
dctt[t] = s
else:
if dctt[t] != s:
print("No")
sys.exit()
print("Yes")
| false
| 0
|
[
"+import sys",
"+from collections import defaultdict",
"+",
"-used = []",
"-res = []",
"-for i in range(len(S)):",
"- if S[i] not in used:",
"- used.append(S[i])",
"- res.append(used.index(S[i]))",
"-# print(used)",
"-# print(res)",
"-used = []",
"-ret = []",
"-for i in range(len(T)):",
"- if T[i] not in used:",
"- used.append(T[i])",
"- ret.append(used.index(T[i]))",
"-if res == ret:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+L = len(S)",
"+dcts = defaultdict(int)",
"+dctt = defaultdict(int)",
"+for i in range(L):",
"+ s = S[i]",
"+ t = T[i]",
"+ if dcts[s] == 0:",
"+ dcts[s] = t",
"+ else:",
"+ if dcts[s] != t:",
"+ print(\"No\")",
"+ sys.exit()",
"+ if dctt[t] == 0:",
"+ dctt[t] = s",
"+ else:",
"+ if dctt[t] != s:",
"+ print(\"No\")",
"+ sys.exit()",
"+print(\"Yes\")"
] | false
| 0.042795
| 0.043999
| 0.972618
|
[
"s325974456",
"s537079097"
] |
u506549878
|
p03835
|
python
|
s211252062
|
s207832943
| 1,476
| 1,358
| 2,940
| 2,940
|
Accepted
|
Accepted
| 7.99
|
k, s = list(map(int, input().split()))
flg = 0
for x in range(k+1):
for y in range(k+1):
z = s-x-y
if 0<= z <= k:
flg += 1
print(flg)
|
k, s =list(map(int,input().split()))
cnt = 0
for i in range(k+1):
for j in range(k+1):
if 0<=s-i-j<=k:
cnt += 1
print(cnt)
| 8
| 7
| 178
| 152
|
k, s = list(map(int, input().split()))
flg = 0
for x in range(k + 1):
for y in range(k + 1):
z = s - x - y
if 0 <= z <= k:
flg += 1
print(flg)
|
k, s = list(map(int, input().split()))
cnt = 0
for i in range(k + 1):
for j in range(k + 1):
if 0 <= s - i - j <= k:
cnt += 1
print(cnt)
| false
| 12.5
|
[
"-flg = 0",
"-for x in range(k + 1):",
"- for y in range(k + 1):",
"- z = s - x - y",
"- if 0 <= z <= k:",
"- flg += 1",
"-print(flg)",
"+cnt = 0",
"+for i in range(k + 1):",
"+ for j in range(k + 1):",
"+ if 0 <= s - i - j <= k:",
"+ cnt += 1",
"+print(cnt)"
] | false
| 0.044741
| 0.110405
| 0.405244
|
[
"s211252062",
"s207832943"
] |
u914797917
|
p03814
|
python
|
s117393340
|
s428496228
| 36
| 18
| 3,512
| 3,516
|
Accepted
|
Accepted
| 50
|
S=eval(input())
for i in range(len(S)):
if S[i]=='A':
S=S[i:]
break
for i in range(len(S)-1,0,-1):
if S[i]=='Z':
S=S[:i+1]
break
print((len(S)))
|
S=eval(input())
S=S[S.find('A'):S.rfind('Z')+1]
print((len(S)))
| 13
| 3
| 175
| 57
|
S = eval(input())
for i in range(len(S)):
if S[i] == "A":
S = S[i:]
break
for i in range(len(S) - 1, 0, -1):
if S[i] == "Z":
S = S[: i + 1]
break
print((len(S)))
|
S = eval(input())
S = S[S.find("A") : S.rfind("Z") + 1]
print((len(S)))
| false
| 76.923077
|
[
"-for i in range(len(S)):",
"- if S[i] == \"A\":",
"- S = S[i:]",
"- break",
"-for i in range(len(S) - 1, 0, -1):",
"- if S[i] == \"Z\":",
"- S = S[: i + 1]",
"- break",
"+S = S[S.find(\"A\") : S.rfind(\"Z\") + 1]"
] | false
| 0.034903
| 0.036724
| 0.950412
|
[
"s117393340",
"s428496228"
] |
u346812984
|
p02939
|
python
|
s727939591
|
s793575356
| 435
| 335
| 22,064
| 19,108
|
Accepted
|
Accepted
| 22.99
|
S = list(eval(input()))
N = len(S)
# n文字まで見て最後が1文字か2文字化
dp_1 = [0] * N
dp_2 = [0] * N
dp_1[0] = 1
dp_2[1] = 1
if S[0] != S[1]:
dp_1[1] = 2
for i, s in enumerate(S[2:], 2):
# dp_1
# 2 -> 1
tmp = dp_2[i - 1] + 1
# 1 -> 1
if S[i - 1] != S[i]:
tmp = max(tmp, dp_1[i - 1] + 1)
dp_1[i] = tmp
# dp_2
# 1->2
tmp = dp_1[i - 2] + 1
# 2->2
if S[i - 3 : i - 1] != S[i - 1 : i + 1]:
tmp = max(tmp, dp_2[i - 2] + 1)
dp_2[i] = tmp
print((max(dp_1[-1], dp_2[-1])))
|
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
S = eval(input())
N = len(S)
# n文字まで見て最後が1文字か2文字か
dp_1 = [0] * N
dp_2 = [0] * N
dp_1[0] = 1
dp_2[1] = 1
if S[0] != S[1]:
dp_1[1] = 2
for i in range(2, N):
# 2 -> 1
dp_1[i] = max(dp_2[i - 1] + 1, dp_1[i])
# 2 -> 2
if S[i - 2 : i] != S[i : i + 2]:
dp_2[i] = max(dp_2[i - 2] + 1, dp_2[i])
# 1 -> 2
dp_2[i] = max(dp_1[i - 2] + 1, dp_2[i])
# 1 -> 1
if S[i - 1] != S[i]:
dp_1[i] = max(dp_1[i - 1] + 1, dp_1[i])
ans = max(dp_1[-1], dp_2[-1])
print(ans)
if __name__ == "__main__":
main()
| 30
| 44
| 543
| 818
|
S = list(eval(input()))
N = len(S)
# n文字まで見て最後が1文字か2文字化
dp_1 = [0] * N
dp_2 = [0] * N
dp_1[0] = 1
dp_2[1] = 1
if S[0] != S[1]:
dp_1[1] = 2
for i, s in enumerate(S[2:], 2):
# dp_1
# 2 -> 1
tmp = dp_2[i - 1] + 1
# 1 -> 1
if S[i - 1] != S[i]:
tmp = max(tmp, dp_1[i - 1] + 1)
dp_1[i] = tmp
# dp_2
# 1->2
tmp = dp_1[i - 2] + 1
# 2->2
if S[i - 3 : i - 1] != S[i - 1 : i + 1]:
tmp = max(tmp, dp_2[i - 2] + 1)
dp_2[i] = tmp
print((max(dp_1[-1], dp_2[-1])))
|
import sys
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
S = eval(input())
N = len(S)
# n文字まで見て最後が1文字か2文字か
dp_1 = [0] * N
dp_2 = [0] * N
dp_1[0] = 1
dp_2[1] = 1
if S[0] != S[1]:
dp_1[1] = 2
for i in range(2, N):
# 2 -> 1
dp_1[i] = max(dp_2[i - 1] + 1, dp_1[i])
# 2 -> 2
if S[i - 2 : i] != S[i : i + 2]:
dp_2[i] = max(dp_2[i - 2] + 1, dp_2[i])
# 1 -> 2
dp_2[i] = max(dp_1[i - 2] + 1, dp_2[i])
# 1 -> 1
if S[i - 1] != S[i]:
dp_1[i] = max(dp_1[i - 1] + 1, dp_1[i])
ans = max(dp_1[-1], dp_2[-1])
print(ans)
if __name__ == "__main__":
main()
| false
| 31.818182
|
[
"-S = list(eval(input()))",
"-N = len(S)",
"-# n文字まで見て最後が1文字か2文字化",
"-dp_1 = [0] * N",
"-dp_2 = [0] * N",
"-dp_1[0] = 1",
"-dp_2[1] = 1",
"-if S[0] != S[1]:",
"- dp_1[1] = 2",
"-for i, s in enumerate(S[2:], 2):",
"- # dp_1",
"- # 2 -> 1",
"- tmp = dp_2[i - 1] + 1",
"- # 1 -> 1",
"- if S[i - 1] != S[i]:",
"- tmp = max(tmp, dp_1[i - 1] + 1)",
"- dp_1[i] = tmp",
"- # dp_2",
"- # 1->2",
"- tmp = dp_1[i - 2] + 1",
"- # 2->2",
"- if S[i - 3 : i - 1] != S[i - 1 : i + 1]:",
"- tmp = max(tmp, dp_2[i - 2] + 1)",
"- dp_2[i] = tmp",
"-print((max(dp_1[-1], dp_2[-1])))",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def main():",
"+ S = eval(input())",
"+ N = len(S)",
"+ # n文字まで見て最後が1文字か2文字か",
"+ dp_1 = [0] * N",
"+ dp_2 = [0] * N",
"+ dp_1[0] = 1",
"+ dp_2[1] = 1",
"+ if S[0] != S[1]:",
"+ dp_1[1] = 2",
"+ for i in range(2, N):",
"+ # 2 -> 1",
"+ dp_1[i] = max(dp_2[i - 1] + 1, dp_1[i])",
"+ # 2 -> 2",
"+ if S[i - 2 : i] != S[i : i + 2]:",
"+ dp_2[i] = max(dp_2[i - 2] + 1, dp_2[i])",
"+ # 1 -> 2",
"+ dp_2[i] = max(dp_1[i - 2] + 1, dp_2[i])",
"+ # 1 -> 1",
"+ if S[i - 1] != S[i]:",
"+ dp_1[i] = max(dp_1[i - 1] + 1, dp_1[i])",
"+ ans = max(dp_1[-1], dp_2[-1])",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.045595
| 0.085546
| 0.532995
|
[
"s727939591",
"s793575356"
] |
u498487134
|
p02755
|
python
|
s499349093
|
s916222635
| 189
| 70
| 39,536
| 63,976
|
Accepted
|
Accepted
| 62.96
|
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()))
def main():
mod=10**9+7
a,b=MI()
ans=-1
for i in range(10000):
aa=int(i*0.08)
bb=i//10
if a==aa and b==bb:
ans=i
break
print(ans)
main()
|
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()))
def main():
mod=10**9+7
ans=-1
A,B=MI()
for i in range(10000):
a=int(i*0.08)
b=int(i*0.1)
if a==A and b==B:
ans=i
break
print(ans)
main()
| 20
| 24
| 386
| 415
|
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()))
def main():
mod = 10**9 + 7
a, b = MI()
ans = -1
for i in range(10000):
aa = int(i * 0.08)
bb = i // 10
if a == aa and b == bb:
ans = i
break
print(ans)
main()
|
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()))
def main():
mod = 10**9 + 7
ans = -1
A, B = MI()
for i in range(10000):
a = int(i * 0.08)
b = int(i * 0.1)
if a == A and b == B:
ans = i
break
print(ans)
main()
| false
| 16.666667
|
[
"- a, b = MI()",
"+ A, B = MI()",
"- aa = int(i * 0.08)",
"- bb = i // 10",
"- if a == aa and b == bb:",
"+ a = int(i * 0.08)",
"+ b = int(i * 0.1)",
"+ if a == A and b == B:"
] | false
| 0.050121
| 0.145563
| 0.344325
|
[
"s499349093",
"s916222635"
] |
u562935282
|
p03055
|
python
|
s742596075
|
s295555535
| 1,471
| 994
| 49,212
| 47,616
|
Accepted
|
Accepted
| 32.43
|
from collections import deque
N = int(eval(input()))
e = [[] for _ in range(N)]
# 隣接リスト
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
# BFS*2で直径を求める
dist = [-1 for _ in range(N)]
dist[0] = 0
q = deque()
q.append(0)
while q:
v = q.popleft()
d = dist[v]
for nv in [x for x in e[v] if dist[x] == -1]:
dist[nv] = d + 1
q.append(nv)
# 探索終了後
# (v,d)=頂点0から最遠点の頂点番号v,頂点0からの距離d
dist = [-1 for _ in range(N)]
dist[v] = 0
q = deque()
q.append(v)
while q:
w = q.popleft()
d = dist[w]
for nw in [x for x in e[w] if dist[x] == -1]:
dist[nw] = d + 1
q.append(nw)
# 探索終了後
# (w,d)=頂点vから最遠点の頂点番号w,頂点vからの距離d
print(('Second' if d % 3 == 1 else 'First'))
|
from collections import deque
import sys
input = sys.stdin.readline
N = int(eval(input()))
e = [[] for _ in range(N)]
# 隣接リスト
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
# BFS*2で直径を求める
def bfs(i):
"""
:param i: bfsの始点, 0-indexed
:return: (v,d), iの最遠点vまでの距離d
"""
dist = [-1 for _ in range(N)]
dist[i] = 0
q = deque((i,))
while q:
v = q.popleft()
d = dist[v]
for nv in [x for x in e[v] if dist[x] == -1]:
dist[nv] = d + 1
q.append(nv)
return v, d
x, _ = bfs(0)
_, d = bfs(x)
print(('Second' if d % 3 == 1 else 'First'))
| 45
| 40
| 814
| 721
|
from collections import deque
N = int(eval(input()))
e = [[] for _ in range(N)]
# 隣接リスト
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
# BFS*2で直径を求める
dist = [-1 for _ in range(N)]
dist[0] = 0
q = deque()
q.append(0)
while q:
v = q.popleft()
d = dist[v]
for nv in [x for x in e[v] if dist[x] == -1]:
dist[nv] = d + 1
q.append(nv)
# 探索終了後
# (v,d)=頂点0から最遠点の頂点番号v,頂点0からの距離d
dist = [-1 for _ in range(N)]
dist[v] = 0
q = deque()
q.append(v)
while q:
w = q.popleft()
d = dist[w]
for nw in [x for x in e[w] if dist[x] == -1]:
dist[nw] = d + 1
q.append(nw)
# 探索終了後
# (w,d)=頂点vから最遠点の頂点番号w,頂点vからの距離d
print(("Second" if d % 3 == 1 else "First"))
|
from collections import deque
import sys
input = sys.stdin.readline
N = int(eval(input()))
e = [[] for _ in range(N)]
# 隣接リスト
for _ in range(N - 1):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
# BFS*2で直径を求める
def bfs(i):
"""
:param i: bfsの始点, 0-indexed
:return: (v,d), iの最遠点vまでの距離d
"""
dist = [-1 for _ in range(N)]
dist[i] = 0
q = deque((i,))
while q:
v = q.popleft()
d = dist[v]
for nv in [x for x in e[v] if dist[x] == -1]:
dist[nv] = d + 1
q.append(nv)
return v, d
x, _ = bfs(0)
_, d = bfs(x)
print(("Second" if d % 3 == 1 else "First"))
| false
| 11.111111
|
[
"+import sys",
"+input = sys.stdin.readline",
"-dist = [-1 for _ in range(N)]",
"-dist[0] = 0",
"-q = deque()",
"-q.append(0)",
"-while q:",
"- v = q.popleft()",
"- d = dist[v]",
"- for nv in [x for x in e[v] if dist[x] == -1]:",
"- dist[nv] = d + 1",
"- q.append(nv)",
"-# 探索終了後",
"-# (v,d)=頂点0から最遠点の頂点番号v,頂点0からの距離d",
"-dist = [-1 for _ in range(N)]",
"-dist[v] = 0",
"-q = deque()",
"-q.append(v)",
"-while q:",
"- w = q.popleft()",
"- d = dist[w]",
"- for nw in [x for x in e[w] if dist[x] == -1]:",
"- dist[nw] = d + 1",
"- q.append(nw)",
"-# 探索終了後",
"-# (w,d)=頂点vから最遠点の頂点番号w,頂点vからの距離d",
"+def bfs(i):",
"+ \"\"\"",
"+ :param i: bfsの始点, 0-indexed",
"+ :return: (v,d), iの最遠点vまでの距離d",
"+ \"\"\"",
"+ dist = [-1 for _ in range(N)]",
"+ dist[i] = 0",
"+ q = deque((i,))",
"+ while q:",
"+ v = q.popleft()",
"+ d = dist[v]",
"+ for nv in [x for x in e[v] if dist[x] == -1]:",
"+ dist[nv] = d + 1",
"+ q.append(nv)",
"+ return v, d",
"+",
"+",
"+x, _ = bfs(0)",
"+_, d = bfs(x)"
] | false
| 0.040697
| 0.036312
| 1.12077
|
[
"s742596075",
"s295555535"
] |
u492605584
|
p03164
|
python
|
s107163941
|
s667284909
| 1,125
| 1,021
| 310,808
| 308,296
|
Accepted
|
Accepted
| 9.24
|
n,w=list(map(int, input().split()))
m=10**5+1
x=[list(map(int, input().split())) for i in range(n)]
dp=[[float('inf')]*m for i in range(n+1)]
dp[0][0]=0
for i in range(n):
for j in range(m):
if j>=x[i][1]:
dp[i+1][j]=min(dp[i][j],dp[i][j-x[i][1]]+x[i][0])
else:
dp[i+1][j]=dp[i][j]
ans=0
for i in range(m):
if dp[-1][i]<=w:ans=max(ans,i)
print(ans)
|
N, W = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(N)]
V = 0
for i in range(N):
V += L[i][1]
dp = [[float('inf')] * (V + 1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
for j in range(V+1):
if j - L[i][1] >= 0:
dp[i+1][j] = min(dp[i][j], dp[i][j-L[i][1]] + L[i][0])
else:
dp[i+1][j] = dp[i][j]
ans = 0
for j in range(V+1):
if W >= dp[-1][j]:
ans = max(ans, j)
print(ans)
| 15
| 19
| 404
| 486
|
n, w = list(map(int, input().split()))
m = 10**5 + 1
x = [list(map(int, input().split())) for i in range(n)]
dp = [[float("inf")] * m for i in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(m):
if j >= x[i][1]:
dp[i + 1][j] = min(dp[i][j], dp[i][j - x[i][1]] + x[i][0])
else:
dp[i + 1][j] = dp[i][j]
ans = 0
for i in range(m):
if dp[-1][i] <= w:
ans = max(ans, i)
print(ans)
|
N, W = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(N)]
V = 0
for i in range(N):
V += L[i][1]
dp = [[float("inf")] * (V + 1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(V + 1):
if j - L[i][1] >= 0:
dp[i + 1][j] = min(dp[i][j], dp[i][j - L[i][1]] + L[i][0])
else:
dp[i + 1][j] = dp[i][j]
ans = 0
for j in range(V + 1):
if W >= dp[-1][j]:
ans = max(ans, j)
print(ans)
| false
| 21.052632
|
[
"-n, w = list(map(int, input().split()))",
"-m = 10**5 + 1",
"-x = [list(map(int, input().split())) for i in range(n)]",
"-dp = [[float(\"inf\")] * m for i in range(n + 1)]",
"+N, W = list(map(int, input().split()))",
"+L = [list(map(int, input().split())) for i in range(N)]",
"+V = 0",
"+for i in range(N):",
"+ V += L[i][1]",
"+dp = [[float(\"inf\")] * (V + 1) for i in range(N + 1)]",
"-for i in range(n):",
"- for j in range(m):",
"- if j >= x[i][1]:",
"- dp[i + 1][j] = min(dp[i][j], dp[i][j - x[i][1]] + x[i][0])",
"+for i in range(N):",
"+ for j in range(V + 1):",
"+ if j - L[i][1] >= 0:",
"+ dp[i + 1][j] = min(dp[i][j], dp[i][j - L[i][1]] + L[i][0])",
"-for i in range(m):",
"- if dp[-1][i] <= w:",
"- ans = max(ans, i)",
"+for j in range(V + 1):",
"+ if W >= dp[-1][j]:",
"+ ans = max(ans, j)"
] | false
| 0.381087
| 0.060143
| 6.336334
|
[
"s107163941",
"s667284909"
] |
u970197315
|
p02756
|
python
|
s276083392
|
s911388304
| 722
| 407
| 46,936
| 13,908
|
Accepted
|
Accepted
| 43.63
|
# ABC158 D
from collections import deque
s=eval(input())
q=int(eval(input()))
l=[]
for i in range(q):
l.append(list(map(str,input().split())))
cnt=0
front_str=''
end_str=''
t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)
for ll in l:
if ll[0]=='1':
cnt+=1
elif ll[0]=='2':
if cnt%2==0:
if ll[1]=='1':
front_str.appendleft(ll[2])
elif ll[1]=='2':
end_str.append(ll[2])
elif cnt%2==1:
if ll[1]=='1':
end_str.append(ll[2])
elif ll[1]=='2':
front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)
if cnt%2==0:
ans=''.join(ans)
else:
ans=ans[::-1]
ans=''.join(ans)
print(ans)
|
s=eval(input())
q=int(eval(input()))
m=0
from collections import deque
s=deque(s)
for i in range(q):
l=list(map(str,input().split()))
if l[0]=="1":
m+=1
m%=2
else:
if m==0:
if l[1]=="1":
s.appendleft(l[2])
else:
s.append(l[2])
else:
if l[1]=="1":
s.append(l[2])
else:
s.appendleft(l[2])
s=list(s)
if m==1:
s=s[::-1]
print(("".join(s)))
| 40
| 26
| 799
| 428
|
# ABC158 D
from collections import deque
s = eval(input())
q = int(eval(input()))
l = []
for i in range(q):
l.append(list(map(str, input().split())))
cnt = 0
front_str = ""
end_str = ""
t_str = deque(s)
front_str = deque(front_str)
end_str = deque(end_str)
for ll in l:
if ll[0] == "1":
cnt += 1
elif ll[0] == "2":
if cnt % 2 == 0:
if ll[1] == "1":
front_str.appendleft(ll[2])
elif ll[1] == "2":
end_str.append(ll[2])
elif cnt % 2 == 1:
if ll[1] == "1":
end_str.append(ll[2])
elif ll[1] == "2":
front_str.appendleft(ll[2])
ans = list(front_str) + list(t_str) + list(end_str)
if cnt % 2 == 0:
ans = "".join(ans)
else:
ans = ans[::-1]
ans = "".join(ans)
print(ans)
|
s = eval(input())
q = int(eval(input()))
m = 0
from collections import deque
s = deque(s)
for i in range(q):
l = list(map(str, input().split()))
if l[0] == "1":
m += 1
m %= 2
else:
if m == 0:
if l[1] == "1":
s.appendleft(l[2])
else:
s.append(l[2])
else:
if l[1] == "1":
s.append(l[2])
else:
s.appendleft(l[2])
s = list(s)
if m == 1:
s = s[::-1]
print(("".join(s)))
| false
| 35
|
[
"-# ABC158 D",
"+s = eval(input())",
"+q = int(eval(input()))",
"+m = 0",
"-s = eval(input())",
"-q = int(eval(input()))",
"-l = []",
"+s = deque(s)",
"- l.append(list(map(str, input().split())))",
"-cnt = 0",
"-front_str = \"\"",
"-end_str = \"\"",
"-t_str = deque(s)",
"-front_str = deque(front_str)",
"-end_str = deque(end_str)",
"-for ll in l:",
"- if ll[0] == \"1\":",
"- cnt += 1",
"- elif ll[0] == \"2\":",
"- if cnt % 2 == 0:",
"- if ll[1] == \"1\":",
"- front_str.appendleft(ll[2])",
"- elif ll[1] == \"2\":",
"- end_str.append(ll[2])",
"- elif cnt % 2 == 1:",
"- if ll[1] == \"1\":",
"- end_str.append(ll[2])",
"- elif ll[1] == \"2\":",
"- front_str.appendleft(ll[2])",
"-ans = list(front_str) + list(t_str) + list(end_str)",
"-if cnt % 2 == 0:",
"- ans = \"\".join(ans)",
"-else:",
"- ans = ans[::-1]",
"- ans = \"\".join(ans)",
"-print(ans)",
"+ l = list(map(str, input().split()))",
"+ if l[0] == \"1\":",
"+ m += 1",
"+ m %= 2",
"+ else:",
"+ if m == 0:",
"+ if l[1] == \"1\":",
"+ s.appendleft(l[2])",
"+ else:",
"+ s.append(l[2])",
"+ else:",
"+ if l[1] == \"1\":",
"+ s.append(l[2])",
"+ else:",
"+ s.appendleft(l[2])",
"+s = list(s)",
"+if m == 1:",
"+ s = s[::-1]",
"+print((\"\".join(s)))"
] | false
| 0.038849
| 0.03821
| 1.016736
|
[
"s276083392",
"s911388304"
] |
u367130284
|
p04039
|
python
|
s833194681
|
s908224081
| 123
| 87
| 2,940
| 3,864
|
Accepted
|
Accepted
| 29.27
|
n,k,*a=open(0).read().split();n=int(n)
while any(s in set(a)for s in str(n)):n+=1
print(n)
|
n,_=input().split();s=set(list(eval(input())));n=int(n);print((n+[len(s&set(str(b)))for b in range(n,99999)].index(0)))
| 3
| 1
| 92
| 111
|
n, k, *a = open(0).read().split()
n = int(n)
while any(s in set(a) for s in str(n)):
n += 1
print(n)
|
n, _ = input().split()
s = set(list(eval(input())))
n = int(n)
print((n + [len(s & set(str(b))) for b in range(n, 99999)].index(0)))
| false
| 66.666667
|
[
"-n, k, *a = open(0).read().split()",
"+n, _ = input().split()",
"+s = set(list(eval(input())))",
"-while any(s in set(a) for s in str(n)):",
"- n += 1",
"-print(n)",
"+print((n + [len(s & set(str(b))) for b in range(n, 99999)].index(0)))"
] | false
| 0.095253
| 0.036526
| 2.60782
|
[
"s833194681",
"s908224081"
] |
u585482323
|
p03229
|
python
|
s139938152
|
s126509361
| 812
| 535
| 67,932
| 53,212
|
Accepted
|
Accepted
| 34.11
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
b = IR(n)
b.sort()
a = deque(b)
q = deque([a.pop()])
n -= 1
for i in range(n):
if i&1:
ai = a.pop()
else:
ai = a.popleft()
x = q[0]
y = q[-1]
if abs(x-ai) < abs(y-ai):
q.append(ai)
else:
q.appendleft(ai)
ans = 0
for i in range(n):
ans += abs(q[i+1]-q[i])
a = deque(b)
q = deque([a.popleft()])
for i in range(n):
if i&1:
ai = a.popleft()
else:
ai = a.pop()
x = q[0]
y = q[-1]
if abs(x-ai) < abs(y-ai):
q.append(ai)
else:
q.appendleft(ai)
ans2 = 0
for i in range(n):
ans2 += abs(q[i+1]-q[i])
a = deque(b)
q = deque([a.pop()])
for i in range(n):
if i&2:
ai = a.pop()
else:
ai = a.popleft()
x = q[0]
y = q[-1]
if abs(x-ai) < abs(y-ai):
q.append(ai)
else:
q.appendleft(ai)
ans3 = 0
for i in range(n):
ans3 += abs(q[i+1]-q[i])
a = deque(b)
q = deque([a.popleft()])
for i in range(n):
if i&2:
ai = a.popleft()
else:
ai = a.pop()
x = q[0]
y = q[-1]
if abs(x-ai) < abs(y-ai):
q.append(ai)
else:
q.appendleft(ai)
ans4 = 0
for i in range(n):
ans4 += abs(q[i+1]-q[i])
print((max(ans,ans2,ans3,ans4)))
return
#Solve
if __name__ == "__main__":
solve()
|
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
b = IR(n)
b.sort()
a = deque(b)
q = deque([a.pop()])
n -= 1
for i in range(n):
if i&2:
ai = a.pop()
else:
ai = a.popleft()
x = q[0]
y = q[-1]
if i&1:
q.append(ai)
else:
q.appendleft(ai)
ans = 0
for i in range(n):
ans += abs(q[i+1]-q[i])
a = deque(b)
q = deque([a.popleft()])
for i in range(n):
if i&2:
ai = a.popleft()
else:
ai = a.pop()
if i&1:
q.append(ai)
else:
q.appendleft(ai)
ans2 = 0
for i in range(n):
ans2 += abs(q[i+1]-q[i])
print((max(ans,ans2)))
return
#Solve
if __name__ == "__main__":
solve()
| 103
| 69
| 2,353
| 1,524
|
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
b = IR(n)
b.sort()
a = deque(b)
q = deque([a.pop()])
n -= 1
for i in range(n):
if i & 1:
ai = a.pop()
else:
ai = a.popleft()
x = q[0]
y = q[-1]
if abs(x - ai) < abs(y - ai):
q.append(ai)
else:
q.appendleft(ai)
ans = 0
for i in range(n):
ans += abs(q[i + 1] - q[i])
a = deque(b)
q = deque([a.popleft()])
for i in range(n):
if i & 1:
ai = a.popleft()
else:
ai = a.pop()
x = q[0]
y = q[-1]
if abs(x - ai) < abs(y - ai):
q.append(ai)
else:
q.appendleft(ai)
ans2 = 0
for i in range(n):
ans2 += abs(q[i + 1] - q[i])
a = deque(b)
q = deque([a.pop()])
for i in range(n):
if i & 2:
ai = a.pop()
else:
ai = a.popleft()
x = q[0]
y = q[-1]
if abs(x - ai) < abs(y - ai):
q.append(ai)
else:
q.appendleft(ai)
ans3 = 0
for i in range(n):
ans3 += abs(q[i + 1] - q[i])
a = deque(b)
q = deque([a.popleft()])
for i in range(n):
if i & 2:
ai = a.popleft()
else:
ai = a.pop()
x = q[0]
y = q[-1]
if abs(x - ai) < abs(y - ai):
q.append(ai)
else:
q.appendleft(ai)
ans4 = 0
for i in range(n):
ans4 += abs(q[i + 1] - q[i])
print((max(ans, ans2, ans3, ans4)))
return
# Solve
if __name__ == "__main__":
solve()
|
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
b = IR(n)
b.sort()
a = deque(b)
q = deque([a.pop()])
n -= 1
for i in range(n):
if i & 2:
ai = a.pop()
else:
ai = a.popleft()
x = q[0]
y = q[-1]
if i & 1:
q.append(ai)
else:
q.appendleft(ai)
ans = 0
for i in range(n):
ans += abs(q[i + 1] - q[i])
a = deque(b)
q = deque([a.popleft()])
for i in range(n):
if i & 2:
ai = a.popleft()
else:
ai = a.pop()
if i & 1:
q.append(ai)
else:
q.appendleft(ai)
ans2 = 0
for i in range(n):
ans2 += abs(q[i + 1] - q[i])
print((max(ans, ans2)))
return
# Solve
if __name__ == "__main__":
solve()
| false
| 33.009709
|
[
"- if i & 1:",
"+ if i & 2:",
"- if abs(x - ai) < abs(y - ai):",
"+ if i & 1:",
"- if i & 1:",
"+ if i & 2:",
"- x = q[0]",
"- y = q[-1]",
"- if abs(x - ai) < abs(y - ai):",
"+ if i & 1:",
"- a = deque(b)",
"- q = deque([a.pop()])",
"- for i in range(n):",
"- if i & 2:",
"- ai = a.pop()",
"- else:",
"- ai = a.popleft()",
"- x = q[0]",
"- y = q[-1]",
"- if abs(x - ai) < abs(y - ai):",
"- q.append(ai)",
"- else:",
"- q.appendleft(ai)",
"- ans3 = 0",
"- for i in range(n):",
"- ans3 += abs(q[i + 1] - q[i])",
"- a = deque(b)",
"- q = deque([a.popleft()])",
"- for i in range(n):",
"- if i & 2:",
"- ai = a.popleft()",
"- else:",
"- ai = a.pop()",
"- x = q[0]",
"- y = q[-1]",
"- if abs(x - ai) < abs(y - ai):",
"- q.append(ai)",
"- else:",
"- q.appendleft(ai)",
"- ans4 = 0",
"- for i in range(n):",
"- ans4 += abs(q[i + 1] - q[i])",
"- print((max(ans, ans2, ans3, ans4)))",
"+ print((max(ans, ans2)))"
] | false
| 0.04951
| 0.085644
| 0.578093
|
[
"s139938152",
"s126509361"
] |
u094191970
|
p03006
|
python
|
s039276250
|
s316611747
| 757
| 106
| 9,316
| 9,280
|
Accepted
|
Accepted
| 86
|
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(eval(input()))
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])
ans=n
pq=[]
for i in range(n-1):
for j in range(i+1,n):
t_p=xy[j][0]-xy[i][0]
t_q=xy[j][1]-xy[i][1]
pq.append([t_p,t_q])
for p,q in pq:
cnt=0
# for x,y in xy:
# if [x+p,y+q] in xy:
# cnt+=1
for i in range(n):
for j in range(n):
if i==j:
continue
x1,y1=xy[i]
x2,y2=xy[j]
if (x2-x1)==p and (y2-y1)==q:
cnt+=1
ans=min(ans,n-cnt)
print(ans)
|
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(eval(input()))
xy=[lnii() for i in range(n)]
xy.sort(key=lambda x:x[0])
pq=[]
for i in range(n-1):
for j in range(i+1,n):
t_p=xy[j][0]-xy[i][0]
t_q=xy[j][1]-xy[i][1]
pq.append([t_p,t_q])
ans=n
for p,q in pq:
cnt=0
for x,y in xy:
if [x+p,y+q] in xy:
cnt+=1
'''
for i in range(n):
for j in range(n):
if i==j:
continue
x1,y1=xy[i]
x2,y2=xy[j]
if (x2-x1)==p and (y2-y1)==q:
cnt+=1
'''
ans=min(ans,n-cnt)
print(ans)
| 32
| 34
| 635
| 646
|
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n = int(eval(input()))
xy = [lnii() for i in range(n)]
xy.sort(key=lambda x: x[0])
ans = n
pq = []
for i in range(n - 1):
for j in range(i + 1, n):
t_p = xy[j][0] - xy[i][0]
t_q = xy[j][1] - xy[i][1]
pq.append([t_p, t_q])
for p, q in pq:
cnt = 0
# for x,y in xy:
# if [x+p,y+q] in xy:
# cnt+=1
for i in range(n):
for j in range(n):
if i == j:
continue
x1, y1 = xy[i]
x2, y2 = xy[j]
if (x2 - x1) == p and (y2 - y1) == q:
cnt += 1
ans = min(ans, n - cnt)
print(ans)
|
from sys import stdin
nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
n = int(eval(input()))
xy = [lnii() for i in range(n)]
xy.sort(key=lambda x: x[0])
pq = []
for i in range(n - 1):
for j in range(i + 1, n):
t_p = xy[j][0] - xy[i][0]
t_q = xy[j][1] - xy[i][1]
pq.append([t_p, t_q])
ans = n
for p, q in pq:
cnt = 0
for x, y in xy:
if [x + p, y + q] in xy:
cnt += 1
"""
for i in range(n):
for j in range(n):
if i==j:
continue
x1,y1=xy[i]
x2,y2=xy[j]
if (x2-x1)==p and (y2-y1)==q:
cnt+=1
"""
ans = min(ans, n - cnt)
print(ans)
| false
| 5.882353
|
[
"-ans = n",
"+ans = n",
"- # for x,y in xy:",
"- # if [x+p,y+q] in xy:",
"- # cnt+=1",
"- for i in range(n):",
"- for j in range(n):",
"- if i == j:",
"- continue",
"- x1, y1 = xy[i]",
"- x2, y2 = xy[j]",
"- if (x2 - x1) == p and (y2 - y1) == q:",
"- cnt += 1",
"+ for x, y in xy:",
"+ if [x + p, y + q] in xy:",
"+ cnt += 1",
"+ \"\"\"",
"+ for i in range(n):",
"+ for j in range(n):",
"+ if i==j:",
"+ continue",
"+ x1,y1=xy[i]",
"+ x2,y2=xy[j]",
"+ if (x2-x1)==p and (y2-y1)==q:",
"+ cnt+=1",
"+ \"\"\""
] | false
| 0.074264
| 0.072438
| 1.025213
|
[
"s039276250",
"s316611747"
] |
u380524497
|
p03739
|
python
|
s686549689
|
s789813279
| 109
| 75
| 14,468
| 20,460
|
Accepted
|
Accepted
| 31.19
|
n = int(eval(input()))
a_list = list(map(int, input().split()))
total = 0
count = 0
pos_or_neg = True # True = +, False = -
for a in a_list:
total += a
if pos_or_neg:
if total <= 0:
count += -total + 1
total += -total + 1
pos_or_neg = False
else:
if total >= 0:
count += total + 1
total -= total + 1
pos_or_neg = True
first_count = count
count = 0
total = 0
pos_or_neg = False
for a in a_list:
total += a
if pos_or_neg:
if total <= 0:
count += -total + 1
total += -total + 1
pos_or_neg = False
else:
if total >= 0:
count += total + 1
total -= total + 1
pos_or_neg = True
print((min(count, first_count)))
|
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
ans1 = 0
total = 0
is_plus = True
for a in A:
total += a
if is_plus:
if total <= 0:
ans1 += -total + 1
total = 1
else:
if total >= 0:
ans1 += total + 1
total = -1
is_plus = not is_plus
ans2 = 0
total = 0
is_plus = False
for a in A:
total += a
if is_plus:
if total <= 0:
ans2 += -total + 1
total = 1
else:
if total >= 0:
ans2 += total + 1
total = -1
is_plus = not is_plus
print((min(ans1, ans2)))
if __name__ == "__main__":
main()
| 41
| 43
| 827
| 832
|
n = int(eval(input()))
a_list = list(map(int, input().split()))
total = 0
count = 0
pos_or_neg = True # True = +, False = -
for a in a_list:
total += a
if pos_or_neg:
if total <= 0:
count += -total + 1
total += -total + 1
pos_or_neg = False
else:
if total >= 0:
count += total + 1
total -= total + 1
pos_or_neg = True
first_count = count
count = 0
total = 0
pos_or_neg = False
for a in a_list:
total += a
if pos_or_neg:
if total <= 0:
count += -total + 1
total += -total + 1
pos_or_neg = False
else:
if total >= 0:
count += total + 1
total -= total + 1
pos_or_neg = True
print((min(count, first_count)))
|
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
ans1 = 0
total = 0
is_plus = True
for a in A:
total += a
if is_plus:
if total <= 0:
ans1 += -total + 1
total = 1
else:
if total >= 0:
ans1 += total + 1
total = -1
is_plus = not is_plus
ans2 = 0
total = 0
is_plus = False
for a in A:
total += a
if is_plus:
if total <= 0:
ans2 += -total + 1
total = 1
else:
if total >= 0:
ans2 += total + 1
total = -1
is_plus = not is_plus
print((min(ans1, ans2)))
if __name__ == "__main__":
main()
| false
| 4.651163
|
[
"-n = int(eval(input()))",
"-a_list = list(map(int, input().split()))",
"-total = 0",
"-count = 0",
"-pos_or_neg = True # True = +, False = -",
"-for a in a_list:",
"- total += a",
"- if pos_or_neg:",
"- if total <= 0:",
"- count += -total + 1",
"- total += -total + 1",
"- pos_or_neg = False",
"- else:",
"- if total >= 0:",
"- count += total + 1",
"- total -= total + 1",
"- pos_or_neg = True",
"-first_count = count",
"-count = 0",
"-total = 0",
"-pos_or_neg = False",
"-for a in a_list:",
"- total += a",
"- if pos_or_neg:",
"- if total <= 0:",
"- count += -total + 1",
"- total += -total + 1",
"- pos_or_neg = False",
"- else:",
"- if total >= 0:",
"- count += total + 1",
"- total -= total + 1",
"- pos_or_neg = True",
"-print((min(count, first_count)))",
"+def main():",
"+ n = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ ans1 = 0",
"+ total = 0",
"+ is_plus = True",
"+ for a in A:",
"+ total += a",
"+ if is_plus:",
"+ if total <= 0:",
"+ ans1 += -total + 1",
"+ total = 1",
"+ else:",
"+ if total >= 0:",
"+ ans1 += total + 1",
"+ total = -1",
"+ is_plus = not is_plus",
"+ ans2 = 0",
"+ total = 0",
"+ is_plus = False",
"+ for a in A:",
"+ total += a",
"+ if is_plus:",
"+ if total <= 0:",
"+ ans2 += -total + 1",
"+ total = 1",
"+ else:",
"+ if total >= 0:",
"+ ans2 += total + 1",
"+ total = -1",
"+ is_plus = not is_plus",
"+ print((min(ans1, ans2)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.112768
| 0.1672
| 0.67445
|
[
"s686549689",
"s789813279"
] |
u624475441
|
p03285
|
python
|
s068024900
|
s593785868
| 20
| 18
| 2,940
| 2,940
|
Accepted
|
Accepted
| 10
|
N = int(eval(input()))
for i in range(101):
if N - 7 * i < 0:
break
if (N - 7 * i) % 4 == 0:
print('Yes')
exit()
print('No')
|
if int(eval(input())) in [1, 2, 3, 5, 6, 9, 10, 13, 17]:
print('No')
else:
print('Yes')
| 8
| 4
| 157
| 92
|
N = int(eval(input()))
for i in range(101):
if N - 7 * i < 0:
break
if (N - 7 * i) % 4 == 0:
print("Yes")
exit()
print("No")
|
if int(eval(input())) in [1, 2, 3, 5, 6, 9, 10, 13, 17]:
print("No")
else:
print("Yes")
| false
| 50
|
[
"-N = int(eval(input()))",
"-for i in range(101):",
"- if N - 7 * i < 0:",
"- break",
"- if (N - 7 * i) % 4 == 0:",
"- print(\"Yes\")",
"- exit()",
"-print(\"No\")",
"+if int(eval(input())) in [1, 2, 3, 5, 6, 9, 10, 13, 17]:",
"+ print(\"No\")",
"+else:",
"+ print(\"Yes\")"
] | false
| 0.036091
| 0.038172
| 0.945486
|
[
"s068024900",
"s593785868"
] |
u731896389
|
p02410
|
python
|
s694941631
|
s577138881
| 30
| 20
| 7,976
| 8,072
|
Accepted
|
Accepted
| 33.33
|
n,m = list(map(int,input().split()))
A = []
b = []
for i in range(n):
A.append([int(j) for j in input().split()])
for i in range(m):
b.append(int(eval(input())))
for i in range(n):
sum = 0
for j in range(m):
sum += A[i][j]*b[j]
print(sum)
|
n,m=list(map(int,input().split()))
A =[[int(i) for i in input().split()] for j in range(n)]
b = []
for i in range(m):
b.append(int(eval(input())))
ans = [0 for i in range(n)]
for i in range(n):
for j in range(m):
ans[i] += A[i][j]*b[j]
for i in ans:
print(i)
| 12
| 11
| 265
| 276
|
n, m = list(map(int, input().split()))
A = []
b = []
for i in range(n):
A.append([int(j) for j in input().split()])
for i in range(m):
b.append(int(eval(input())))
for i in range(n):
sum = 0
for j in range(m):
sum += A[i][j] * b[j]
print(sum)
|
n, m = list(map(int, input().split()))
A = [[int(i) for i in input().split()] for j in range(n)]
b = []
for i in range(m):
b.append(int(eval(input())))
ans = [0 for i in range(n)]
for i in range(n):
for j in range(m):
ans[i] += A[i][j] * b[j]
for i in ans:
print(i)
| false
| 8.333333
|
[
"-A = []",
"+A = [[int(i) for i in input().split()] for j in range(n)]",
"-for i in range(n):",
"- A.append([int(j) for j in input().split()])",
"+ans = [0 for i in range(n)]",
"- sum = 0",
"- sum += A[i][j] * b[j]",
"- print(sum)",
"+ ans[i] += A[i][j] * b[j]",
"+for i in ans:",
"+ print(i)"
] | false
| 0.042558
| 0.043872
| 0.970068
|
[
"s694941631",
"s577138881"
] |
u489959379
|
p03696
|
python
|
s632552495
|
s634684891
| 162
| 25
| 38,256
| 9,192
|
Accepted
|
Accepted
| 84.57
|
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
S = eval(input())
insert_L = 0
cnt_L = 0
for s in S:
if s == '(':
cnt_L += 1
else:
if cnt_L:
cnt_L -= 1
else:
insert_L += 1
insert_R = cnt_L
res = '(' * insert_L + S + ')' * insert_R
print(res)
if __name__ == '__main__':
resolve()
|
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
S = eval(input())
right = 0
left = 0
for i in range(n):
if S[i] == "(":
left += 1
else:
if left:
left -= 1
else:
right += 1
res = "(" * right + S + ")" * left
print(res)
if __name__ == '__main__':
resolve()
| 31
| 27
| 497
| 462
|
import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
S = eval(input())
insert_L = 0
cnt_L = 0
for s in S:
if s == "(":
cnt_L += 1
else:
if cnt_L:
cnt_L -= 1
else:
insert_L += 1
insert_R = cnt_L
res = "(" * insert_L + S + ")" * insert_R
print(res)
if __name__ == "__main__":
resolve()
|
import sys
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
S = eval(input())
right = 0
left = 0
for i in range(n):
if S[i] == "(":
left += 1
else:
if left:
left -= 1
else:
right += 1
res = "(" * right + S + ")" * left
print(res)
if __name__ == "__main__":
resolve()
| false
| 12.903226
|
[
"- insert_L = 0",
"- cnt_L = 0",
"- for s in S:",
"- if s == \"(\":",
"- cnt_L += 1",
"+ right = 0",
"+ left = 0",
"+ for i in range(n):",
"+ if S[i] == \"(\":",
"+ left += 1",
"- if cnt_L:",
"- cnt_L -= 1",
"+ if left:",
"+ left -= 1",
"- insert_L += 1",
"- insert_R = cnt_L",
"- res = \"(\" * insert_L + S + \")\" * insert_R",
"+ right += 1",
"+ res = \"(\" * right + S + \")\" * left"
] | false
| 0.037461
| 0.056965
| 0.657621
|
[
"s632552495",
"s634684891"
] |
u062691227
|
p04046
|
python
|
s539781020
|
s811976266
| 376
| 173
| 88,692
| 73,692
|
Accepted
|
Accepted
| 53.99
|
H, W, A, B = list(map(int, open(0).read().split()))
MOD = 10**9+7
factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)
tmp = 1
for i in range(H + W):
tmp = tmp * (i + 1) % MOD
factorials[i+1] = tmp
inv_factorials = list([pow(n, MOD - 2, MOD) for n in factorials])
def modcomb(m, n, mod):
return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD
# total = modcomb(H + W - 2, W - 1, MOD)
total = 0
# for i in range(B):
for i in range(B, W):
total += modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD
total %= MOD
print(total)
|
H, W, A, B = list(map(int, open(0).read().split()))
MOD = 10**9+7
factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)
for i in range(H + W):
factorials[i+1] = factorials[i] * (i + 1) % MOD
for i in range(H + W):
inv_factorials[i+1] = inv_factorials[i] * pow(i + 1, MOD - 2, MOD) % MOD
def modcomb(m, n, mod):
return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD
# total = modcomb(H + W - 2, W - 1, MOD)
total = 0
# for i in range(B):
for i in range(B, W):
total += modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD
total %= MOD
print(total)
| 25
| 24
| 641
| 658
|
H, W, A, B = list(map(int, open(0).read().split()))
MOD = 10**9 + 7
factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)
tmp = 1
for i in range(H + W):
tmp = tmp * (i + 1) % MOD
factorials[i + 1] = tmp
inv_factorials = list([pow(n, MOD - 2, MOD) for n in factorials])
def modcomb(m, n, mod):
return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD
# total = modcomb(H + W - 2, W - 1, MOD)
total = 0
# for i in range(B):
for i in range(B, W):
total += (
modcomb(H - A - 1 + i, i, MOD)
* modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD)
% MOD
)
total %= MOD
print(total)
|
H, W, A, B = list(map(int, open(0).read().split()))
MOD = 10**9 + 7
factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)
for i in range(H + W):
factorials[i + 1] = factorials[i] * (i + 1) % MOD
for i in range(H + W):
inv_factorials[i + 1] = inv_factorials[i] * pow(i + 1, MOD - 2, MOD) % MOD
def modcomb(m, n, mod):
return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD
# total = modcomb(H + W - 2, W - 1, MOD)
total = 0
# for i in range(B):
for i in range(B, W):
total += (
modcomb(H - A - 1 + i, i, MOD)
* modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD)
% MOD
)
total %= MOD
print(total)
| false
| 4
|
[
"-tmp = 1",
"- tmp = tmp * (i + 1) % MOD",
"- factorials[i + 1] = tmp",
"-inv_factorials = list([pow(n, MOD - 2, MOD) for n in factorials])",
"+ factorials[i + 1] = factorials[i] * (i + 1) % MOD",
"+for i in range(H + W):",
"+ inv_factorials[i + 1] = inv_factorials[i] * pow(i + 1, MOD - 2, MOD) % MOD"
] | false
| 0.040502
| 0.041577
| 0.974146
|
[
"s539781020",
"s811976266"
] |
u935558307
|
p03716
|
python
|
s917352118
|
s468289416
| 671
| 291
| 120,080
| 125,988
|
Accepted
|
Accepted
| 56.63
|
import heapq
N = int(eval(input()))
A = list(map(int,input().split()))
#前半部分の最適化辞書作成
SUM = sum(A[:N])
firstDic = {N-1:SUM}
que = A[:N]
heapq.heapify(que)
for i in range(N,2*N):
SUM += A[i]
heapq.heappush(que,A[i])
SUM -= heapq.heappop(que)
firstDic[i] = SUM
#後半部分の最適化辞書作成
SUM = sum(A[2*N:])*-1
latterDic = {2*N-1:SUM*-1}
que = [A[i]*-1 for i in range(2*N,3*N)]
heapq.heapify(que)
for i in range(2*N-1,N-1,-1):
SUM += A[i]*-1
heapq.heappush(que,A[i]*-1)
SUM -= heapq.heappop(que)
latterDic[i-1] = SUM*-1
ans = -1*float("INF")
for k,v in list(firstDic.items()):
ans = max(ans,v-latterDic[k])
print(ans)
|
N = int(eval(input()))
A = list(map(int,input().split()))
B = []
for i in range(3*N-1,-1,-1):
B.append(A[i]*-1)
"""
前半をできるだけおおきく、後半をできるだけ小さくする。
前半はpriority queにぶっこんでいって、最小値を除去していく
"""
import heapq
frontSum = sum(A[:N])
frontQue = A[:N]
heapq.heapify(frontQue)
front = [frontSum]
for i in range(N,2*N):
frontSum += A[i]
heapq.heappush(frontQue,A[i])
frontSum -= heapq.heappop(frontQue)
front.append(frontSum)
backSum = sum(B[:N])
backQue = B[:N]
heapq.heapify(backQue)
back = [backSum*-1]
for i in range(N,2*N):
backSum += B[i]
heapq.heappush(backQue,B[i])
backSum -= heapq.heappop(backQue)
back.append(backSum*-1)
back = back[::-1]
candi = []
for i in range(len(front)):
candi.append(front[i]-back[i])
print((max(candi)))
| 31
| 35
| 658
| 790
|
import heapq
N = int(eval(input()))
A = list(map(int, input().split()))
# 前半部分の最適化辞書作成
SUM = sum(A[:N])
firstDic = {N - 1: SUM}
que = A[:N]
heapq.heapify(que)
for i in range(N, 2 * N):
SUM += A[i]
heapq.heappush(que, A[i])
SUM -= heapq.heappop(que)
firstDic[i] = SUM
# 後半部分の最適化辞書作成
SUM = sum(A[2 * N :]) * -1
latterDic = {2 * N - 1: SUM * -1}
que = [A[i] * -1 for i in range(2 * N, 3 * N)]
heapq.heapify(que)
for i in range(2 * N - 1, N - 1, -1):
SUM += A[i] * -1
heapq.heappush(que, A[i] * -1)
SUM -= heapq.heappop(que)
latterDic[i - 1] = SUM * -1
ans = -1 * float("INF")
for k, v in list(firstDic.items()):
ans = max(ans, v - latterDic[k])
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
B = []
for i in range(3 * N - 1, -1, -1):
B.append(A[i] * -1)
"""
前半をできるだけおおきく、後半をできるだけ小さくする。
前半はpriority queにぶっこんでいって、最小値を除去していく
"""
import heapq
frontSum = sum(A[:N])
frontQue = A[:N]
heapq.heapify(frontQue)
front = [frontSum]
for i in range(N, 2 * N):
frontSum += A[i]
heapq.heappush(frontQue, A[i])
frontSum -= heapq.heappop(frontQue)
front.append(frontSum)
backSum = sum(B[:N])
backQue = B[:N]
heapq.heapify(backQue)
back = [backSum * -1]
for i in range(N, 2 * N):
backSum += B[i]
heapq.heappush(backQue, B[i])
backSum -= heapq.heappop(backQue)
back.append(backSum * -1)
back = back[::-1]
candi = []
for i in range(len(front)):
candi.append(front[i] - back[i])
print((max(candi)))
| false
| 11.428571
|
[
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"+B = []",
"+for i in range(3 * N - 1, -1, -1):",
"+ B.append(A[i] * -1)",
"+\"\"\"",
"+前半をできるだけおおきく、後半をできるだけ小さくする。",
"+前半はpriority queにぶっこんでいって、最小値を除去していく",
"+\"\"\"",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-# 前半部分の最適化辞書作成",
"-SUM = sum(A[:N])",
"-firstDic = {N - 1: SUM}",
"-que = A[:N]",
"-heapq.heapify(que)",
"+frontSum = sum(A[:N])",
"+frontQue = A[:N]",
"+heapq.heapify(frontQue)",
"+front = [frontSum]",
"- SUM += A[i]",
"- heapq.heappush(que, A[i])",
"- SUM -= heapq.heappop(que)",
"- firstDic[i] = SUM",
"-# 後半部分の最適化辞書作成",
"-SUM = sum(A[2 * N :]) * -1",
"-latterDic = {2 * N - 1: SUM * -1}",
"-que = [A[i] * -1 for i in range(2 * N, 3 * N)]",
"-heapq.heapify(que)",
"-for i in range(2 * N - 1, N - 1, -1):",
"- SUM += A[i] * -1",
"- heapq.heappush(que, A[i] * -1)",
"- SUM -= heapq.heappop(que)",
"- latterDic[i - 1] = SUM * -1",
"-ans = -1 * float(\"INF\")",
"-for k, v in list(firstDic.items()):",
"- ans = max(ans, v - latterDic[k])",
"-print(ans)",
"+ frontSum += A[i]",
"+ heapq.heappush(frontQue, A[i])",
"+ frontSum -= heapq.heappop(frontQue)",
"+ front.append(frontSum)",
"+backSum = sum(B[:N])",
"+backQue = B[:N]",
"+heapq.heapify(backQue)",
"+back = [backSum * -1]",
"+for i in range(N, 2 * N):",
"+ backSum += B[i]",
"+ heapq.heappush(backQue, B[i])",
"+ backSum -= heapq.heappop(backQue)",
"+ back.append(backSum * -1)",
"+back = back[::-1]",
"+candi = []",
"+for i in range(len(front)):",
"+ candi.append(front[i] - back[i])",
"+print((max(candi)))"
] | false
| 0.044663
| 0.090408
| 0.494018
|
[
"s917352118",
"s468289416"
] |
u673361376
|
p03380
|
python
|
s704394686
|
s613426752
| 236
| 137
| 62,704
| 14,052
|
Accepted
|
Accepted
| 41.95
|
from operator import mul
from functools import reduce
import bisect
def cmb(n,r):
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1,r + 1)))
return over // under
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)
if idx == len(A):
print((maxA,A[-1]))
elif idx == 0:
print((maxA, idx))
else:
if abs(maxA//2 - A[idx]) > abs(maxA//2 - A[idx-1]):
print((maxA,A[idx-1]))
else:
print((maxA,A[idx]))
|
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
n = A[-1]
r_val = -float('inf')
r_row = None
for idx in range(N - 1):
if r_val < min(n - A[idx], A[idx]):
r_val = min(n - A[idx], A[idx])
r_row = A[idx]
print((n, r_row))
| 26
| 11
| 569
| 261
|
from operator import mul
from functools import reduce
import bisect
def cmb(n, r):
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, list(range(n, n - r, -1)))
under = reduce(mul, list(range(1, r + 1)))
return over // under
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A, maxA // 2)
if idx == len(A):
print((maxA, A[-1]))
elif idx == 0:
print((maxA, idx))
else:
if abs(maxA // 2 - A[idx]) > abs(maxA // 2 - A[idx - 1]):
print((maxA, A[idx - 1]))
else:
print((maxA, A[idx]))
|
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
n = A[-1]
r_val = -float("inf")
r_row = None
for idx in range(N - 1):
if r_val < min(n - A[idx], A[idx]):
r_val = min(n - A[idx], A[idx])
r_row = A[idx]
print((n, r_row))
| false
| 57.692308
|
[
"-from operator import mul",
"-from functools import reduce",
"-import bisect",
"-",
"-",
"-def cmb(n, r):",
"- r = min(n - r, r)",
"- if r == 0:",
"- return 1",
"- over = reduce(mul, list(range(n, n - r, -1)))",
"- under = reduce(mul, list(range(1, r + 1)))",
"- return over // under",
"-",
"-",
"-maxA = max(A)",
"-A.remove(maxA)",
"-idx = bisect.bisect(A, maxA // 2)",
"-if idx == len(A):",
"- print((maxA, A[-1]))",
"-elif idx == 0:",
"- print((maxA, idx))",
"-else:",
"- if abs(maxA // 2 - A[idx]) > abs(maxA // 2 - A[idx - 1]):",
"- print((maxA, A[idx - 1]))",
"- else:",
"- print((maxA, A[idx]))",
"+n = A[-1]",
"+r_val = -float(\"inf\")",
"+r_row = None",
"+for idx in range(N - 1):",
"+ if r_val < min(n - A[idx], A[idx]):",
"+ r_val = min(n - A[idx], A[idx])",
"+ r_row = A[idx]",
"+print((n, r_row))"
] | false
| 0.038397
| 0.038094
| 1.00795
|
[
"s704394686",
"s613426752"
] |
u579699847
|
p03993
|
python
|
s540750439
|
s532012152
| 228
| 202
| 29,596
| 23,464
|
Accepted
|
Accepted
| 11.4
|
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
count = 0
a_dict = {}
for i,x in enumerate(a,1):
a_dict[i] = x
for k,v in list(a_dict.items()):
if k in [a_dict[v]]:
count +=1
print((count//2))
|
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
for i,x in enumerate(a,1):
if x=='*':
continue
if a[x-1]==i:
ans += 1
a[x-1] = '*'
print(ans)
| 14
| 14
| 380
| 361
|
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
count = 0
a_dict = {}
for i, x in enumerate(a, 1):
a_dict[i] = x
for k, v in list(a_dict.items()):
if k in [a_dict[v]]:
count += 1
print((count // 2))
|
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
def I():
return int(sys.stdin.readline().rstrip())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
for i, x in enumerate(a, 1):
if x == "*":
continue
if a[x - 1] == i:
ans += 1
a[x - 1] = "*"
print(ans)
| false
| 0
|
[
"-count = 0",
"-a_dict = {}",
"+ans = 0",
"- a_dict[i] = x",
"-for k, v in list(a_dict.items()):",
"- if k in [a_dict[v]]:",
"- count += 1",
"-print((count // 2))",
"+ if x == \"*\":",
"+ continue",
"+ if a[x - 1] == i:",
"+ ans += 1",
"+ a[x - 1] = \"*\"",
"+print(ans)"
] | false
| 0.034524
| 0.034779
| 0.992676
|
[
"s540750439",
"s532012152"
] |
u707808519
|
p03854
|
python
|
s814675348
|
s228476961
| 86
| 71
| 3,188
| 3,236
|
Accepted
|
Accepted
| 17.44
|
S = eval(input())
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]
while len(S) > 0:
for i in range(4):
if S[:len(divide[i])] == divide[i]:
flag = "YES"
S = S[len(divide[i]):]
break
else:
flag = "NO"
if flag == "NO":
break
print(flag)
|
S = eval(input())
buff = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
buff[i] = buff[i][::-1]
S = S[::-1]
while len(S) > 0:
if S[:7] == buff[1]:
S = S[7:]
elif S[:6] == buff[3]:
S = S[6:]
elif S[:5] == buff[0] or S[:5] == buff[2]:
S = S[5:]
else:
break
if S: print('NO')
else: print('YES')
| 17
| 16
| 384
| 364
|
S = eval(input())
divide = ["dream", "dreamer", "erase", "eraser"]
S = S[::-1]
divide = [divide[i][::-1] for i in range(4)]
while len(S) > 0:
for i in range(4):
if S[: len(divide[i])] == divide[i]:
flag = "YES"
S = S[len(divide[i]) :]
break
else:
flag = "NO"
if flag == "NO":
break
print(flag)
|
S = eval(input())
buff = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
buff[i] = buff[i][::-1]
S = S[::-1]
while len(S) > 0:
if S[:7] == buff[1]:
S = S[7:]
elif S[:6] == buff[3]:
S = S[6:]
elif S[:5] == buff[0] or S[:5] == buff[2]:
S = S[5:]
else:
break
if S:
print("NO")
else:
print("YES")
| false
| 5.882353
|
[
"-divide = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]",
"+buff = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]",
"+for i in range(4):",
"+ buff[i] = buff[i][::-1]",
"-divide = [divide[i][::-1] for i in range(4)]",
"- for i in range(4):",
"- if S[: len(divide[i])] == divide[i]:",
"- flag = \"YES\"",
"- S = S[len(divide[i]) :]",
"- break",
"- else:",
"- flag = \"NO\"",
"- if flag == \"NO\":",
"+ if S[:7] == buff[1]:",
"+ S = S[7:]",
"+ elif S[:6] == buff[3]:",
"+ S = S[6:]",
"+ elif S[:5] == buff[0] or S[:5] == buff[2]:",
"+ S = S[5:]",
"+ else:",
"-print(flag)",
"+if S:",
"+ print(\"NO\")",
"+else:",
"+ print(\"YES\")"
] | false
| 0.041757
| 0.044179
| 0.945195
|
[
"s814675348",
"s228476961"
] |
u753803401
|
p03565
|
python
|
s359584852
|
s856106269
| 166
| 17
| 38,384
| 3,192
|
Accepted
|
Accepted
| 89.76
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
s = str(readline().rstrip().decode('utf-8'))
t = str(readline().rstrip().decode('utf-8'))
k = len(t)
for i in range(len(s) - k, -1, -1):
ts = s[i:i+k]
b = True
for j in range(k):
if ts[j] != "?" and ts[j] != t[j]:
b = False
break
if b:
a = []
f = True
for j in range(len(s)):
if j < i or i + k <= j:
if s[j] == "?":
a.append("a")
else:
a.append(s[j])
else:
if f:
a = a + list(t)
f = False
print(("".join(a)))
exit()
print("UNRESTORABLE")
if __name__ == '__main__':
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
s = str(readline().rstrip().decode('utf-8'))
t = str(readline().rstrip().decode('utf-8'))
lt = len(t)
for i in range(len(s) - lt, -1, -1):
ts = s[i:i+lt]
b = True
for j in range(len(ts)):
if ts[j] != "?" and ts[j] != t[j]:
b = False
break
if b:
ans = []
for j in range(len(s)):
if i <= j < i + lt:
ans.append(t[j-i])
else:
if s[j] == "?":
ans.append("a")
else:
ans.append(s[j])
print(("".join(ans)))
exit()
print("UNRESTORABLE")
if __name__ == '__main__':
solve()
| 36
| 33
| 945
| 873
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
s = str(readline().rstrip().decode("utf-8"))
t = str(readline().rstrip().decode("utf-8"))
k = len(t)
for i in range(len(s) - k, -1, -1):
ts = s[i : i + k]
b = True
for j in range(k):
if ts[j] != "?" and ts[j] != t[j]:
b = False
break
if b:
a = []
f = True
for j in range(len(s)):
if j < i or i + k <= j:
if s[j] == "?":
a.append("a")
else:
a.append(s[j])
else:
if f:
a = a + list(t)
f = False
print(("".join(a)))
exit()
print("UNRESTORABLE")
if __name__ == "__main__":
solve()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
s = str(readline().rstrip().decode("utf-8"))
t = str(readline().rstrip().decode("utf-8"))
lt = len(t)
for i in range(len(s) - lt, -1, -1):
ts = s[i : i + lt]
b = True
for j in range(len(ts)):
if ts[j] != "?" and ts[j] != t[j]:
b = False
break
if b:
ans = []
for j in range(len(s)):
if i <= j < i + lt:
ans.append(t[j - i])
else:
if s[j] == "?":
ans.append("a")
else:
ans.append(s[j])
print(("".join(ans)))
exit()
print("UNRESTORABLE")
if __name__ == "__main__":
solve()
| false
| 8.333333
|
[
"- k = len(t)",
"- for i in range(len(s) - k, -1, -1):",
"- ts = s[i : i + k]",
"+ lt = len(t)",
"+ for i in range(len(s) - lt, -1, -1):",
"+ ts = s[i : i + lt]",
"- for j in range(k):",
"+ for j in range(len(ts)):",
"- a = []",
"- f = True",
"+ ans = []",
"- if j < i or i + k <= j:",
"+ if i <= j < i + lt:",
"+ ans.append(t[j - i])",
"+ else:",
"- a.append(\"a\")",
"+ ans.append(\"a\")",
"- a.append(s[j])",
"- else:",
"- if f:",
"- a = a + list(t)",
"- f = False",
"- print((\"\".join(a)))",
"+ ans.append(s[j])",
"+ print((\"\".join(ans)))"
] | false
| 0.044397
| 0.043722
| 1.015446
|
[
"s359584852",
"s856106269"
] |
u487252913
|
p03108
|
python
|
s295638294
|
s048514460
| 712
| 655
| 62,600
| 15,768
|
Accepted
|
Accepted
| 8.01
|
import sys
sys.setrecursionlimit(10 ** 7)
class UnionFind:
def __init__(self, size: int):
self.parent = [-1 for _ in range(size)]
self.size = [1 for _ in range(size)]
def unite(self, x, y):
px = self.find(x)
py = self.find(y)
if px != py:
if self.parent[px] > self.parent[py]:
self.parent[py] = px
self.parent[px] -= 1
self.size[px] += self.size[py]
self.size[py] = 0
else:
self.parent[px] = py
self.parent[py] -= 1
self.size[py] += self.size[px]
self.size[px] = 0
return
def find(self, x: int) -> int:
if self.parent[x] < 0:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x: int, y: int) -> bool:
return self.find(x) == self.find(y)
def main():
# input
N, M = map(int, input().split())
brs = [list(map(int, input().split())) for _ in range(M)]
# solve
# ref: http://drken1215.hatenablog.com/entry/2019/03/03/224600
# ref: https://atcoder.jp/contests/abc120/submissions/4450601
uf = UnionFind(N)
ans = [N*(N-1)//2]
for i in range(M-1, 0, -1):
a, b = brs[i][0], brs[i][1]
a, b = a-1, b-1
p1 = uf.find(a)
p2 = uf.find(b)
if p1 != p2:
ans.append(ans[-1] - uf.size[p1]*uf.size[p2])
else:
ans.append(ans[-1])
uf.unite(p1, p2)
return ans
print(*list(reversed(main())), sep="\n")
|
class UnionFind:
def __init__(self, size: int):
self.parent = [-1 for _ in range(size)]
def unite(self, x, y):
px = self.find(x)
py = self.find(y)
if px == py:
return
if self.size(px) > self.size(py):
px, py = py, px
self.parent[py] += self.parent[px]
self.parent[px] = py
return
def find(self, x: int) -> int:
if self.parent[x] < 0:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def size(self, x):
return -self.parent[self.find(x)]
def is_same(self, x: int, y: int) -> bool:
return self.find(x) == self.find(y)
def main():
# input
N, M = map(int, input().split())
A, B = [], []
for _ in range(M):
a, b = map(int, input().split())
A.append(a-1)
B.append(b-1)
# solve
# ref: http://drken1215.hatenablog.com/entry/2019/03/03/224600
# ref: https://atcoder.jp/contests/abc120/submissions/4450601
uf = UnionFind(N)
ans = [N*(N-1)//2]
for i in range(M-1, 0, -1):
p1 = uf.find(A[i])
p2 = uf.find(B[i])
if p1 != p2:
ans.append(ans[-1] - uf.size(p1)*uf.size(p2))
else:
ans.append(ans[-1])
uf.unite(p1, p2)
return ans
print(*list(reversed(main())), sep="\n")
| 59
| 55
| 1,666
| 1,433
|
import sys
sys.setrecursionlimit(10**7)
class UnionFind:
def __init__(self, size: int):
self.parent = [-1 for _ in range(size)]
self.size = [1 for _ in range(size)]
def unite(self, x, y):
px = self.find(x)
py = self.find(y)
if px != py:
if self.parent[px] > self.parent[py]:
self.parent[py] = px
self.parent[px] -= 1
self.size[px] += self.size[py]
self.size[py] = 0
else:
self.parent[px] = py
self.parent[py] -= 1
self.size[py] += self.size[px]
self.size[px] = 0
return
def find(self, x: int) -> int:
if self.parent[x] < 0:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def is_same(self, x: int, y: int) -> bool:
return self.find(x) == self.find(y)
def main():
# input
N, M = map(int, input().split())
brs = [list(map(int, input().split())) for _ in range(M)]
# solve
# ref: http://drken1215.hatenablog.com/entry/2019/03/03/224600
# ref: https://atcoder.jp/contests/abc120/submissions/4450601
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
for i in range(M - 1, 0, -1):
a, b = brs[i][0], brs[i][1]
a, b = a - 1, b - 1
p1 = uf.find(a)
p2 = uf.find(b)
if p1 != p2:
ans.append(ans[-1] - uf.size[p1] * uf.size[p2])
else:
ans.append(ans[-1])
uf.unite(p1, p2)
return ans
print(*list(reversed(main())), sep="\n")
|
class UnionFind:
def __init__(self, size: int):
self.parent = [-1 for _ in range(size)]
def unite(self, x, y):
px = self.find(x)
py = self.find(y)
if px == py:
return
if self.size(px) > self.size(py):
px, py = py, px
self.parent[py] += self.parent[px]
self.parent[px] = py
return
def find(self, x: int) -> int:
if self.parent[x] < 0:
return x
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def size(self, x):
return -self.parent[self.find(x)]
def is_same(self, x: int, y: int) -> bool:
return self.find(x) == self.find(y)
def main():
# input
N, M = map(int, input().split())
A, B = [], []
for _ in range(M):
a, b = map(int, input().split())
A.append(a - 1)
B.append(b - 1)
# solve
# ref: http://drken1215.hatenablog.com/entry/2019/03/03/224600
# ref: https://atcoder.jp/contests/abc120/submissions/4450601
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
for i in range(M - 1, 0, -1):
p1 = uf.find(A[i])
p2 = uf.find(B[i])
if p1 != p2:
ans.append(ans[-1] - uf.size(p1) * uf.size(p2))
else:
ans.append(ans[-1])
uf.unite(p1, p2)
return ans
print(*list(reversed(main())), sep="\n")
| false
| 6.779661
|
[
"-import sys",
"-",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"- self.size = [1 for _ in range(size)]",
"- if px != py:",
"- if self.parent[px] > self.parent[py]:",
"- self.parent[py] = px",
"- self.parent[px] -= 1",
"- self.size[px] += self.size[py]",
"- self.size[py] = 0",
"- else:",
"- self.parent[px] = py",
"- self.parent[py] -= 1",
"- self.size[py] += self.size[px]",
"- self.size[px] = 0",
"+ if px == py:",
"+ return",
"+ if self.size(px) > self.size(py):",
"+ px, py = py, px",
"+ self.parent[py] += self.parent[px]",
"+ self.parent[px] = py",
"+ def size(self, x):",
"+ return -self.parent[self.find(x)]",
"+",
"- brs = [list(map(int, input().split())) for _ in range(M)]",
"+ A, B = [], []",
"+ for _ in range(M):",
"+ a, b = map(int, input().split())",
"+ A.append(a - 1)",
"+ B.append(b - 1)",
"- a, b = brs[i][0], brs[i][1]",
"- a, b = a - 1, b - 1",
"- p1 = uf.find(a)",
"- p2 = uf.find(b)",
"+ p1 = uf.find(A[i])",
"+ p2 = uf.find(B[i])",
"- ans.append(ans[-1] - uf.size[p1] * uf.size[p2])",
"+ ans.append(ans[-1] - uf.size(p1) * uf.size(p2))"
] | false
| 0.039998
| 0.0388
| 1.030886
|
[
"s295638294",
"s048514460"
] |
u922172470
|
p03448
|
python
|
s126200966
|
s116381067
| 43
| 17
| 3,064
| 3,060
|
Accepted
|
Accepted
| 60.47
|
def resolve():
A,B,C,X = [int(eval(input())) for i in range(4)]
res = 0
for a in range(A+1):
for b in range(B+1):
for c in range(C+1):
total = 500*a + 100*b + 50*c
if total == X:
res += 1
print(res)
resolve()
|
def resolve():
A,B,C,X = [int(eval(input())) for i in range(4)]
res = 0
mA = min(X//500, A)
for i in range(mA+1):
Y = X - 500 * i
mB = min(Y//100, B)
for j in range(mB+1):
Z = Y - 100 * j
if Z <= 50*C:
res += 1
print(res)
resolve()
| 14
| 16
| 310
| 331
|
def resolve():
A, B, C, X = [int(eval(input())) for i in range(4)]
res = 0
for a in range(A + 1):
for b in range(B + 1):
for c in range(C + 1):
total = 500 * a + 100 * b + 50 * c
if total == X:
res += 1
print(res)
resolve()
|
def resolve():
A, B, C, X = [int(eval(input())) for i in range(4)]
res = 0
mA = min(X // 500, A)
for i in range(mA + 1):
Y = X - 500 * i
mB = min(Y // 100, B)
for j in range(mB + 1):
Z = Y - 100 * j
if Z <= 50 * C:
res += 1
print(res)
resolve()
| false
| 12.5
|
[
"- for a in range(A + 1):",
"- for b in range(B + 1):",
"- for c in range(C + 1):",
"- total = 500 * a + 100 * b + 50 * c",
"- if total == X:",
"- res += 1",
"+ mA = min(X // 500, A)",
"+ for i in range(mA + 1):",
"+ Y = X - 500 * i",
"+ mB = min(Y // 100, B)",
"+ for j in range(mB + 1):",
"+ Z = Y - 100 * j",
"+ if Z <= 50 * C:",
"+ res += 1"
] | false
| 0.061363
| 0.036613
| 1.67599
|
[
"s126200966",
"s116381067"
] |
u595289165
|
p02629
|
python
|
s815030426
|
s024515678
| 32
| 29
| 9,216
| 9,092
|
Accepted
|
Accepted
| 9.38
|
def base_k(n, k=26):
ret = []
ny = n
while ny:
ret.append(ny % k)
ny //= k
return ret[::-1]
def letter(i):
return chr(i+97)
def solve(n):
check = 26
cnt = 1
k = n
while True:
if n <= check:
break
check *= 26
check += 26
cnt += 1
k -= check//26 - 1
t = base_k(k-1)
ans = ""
if not t:
ans = "a" * cnt
else:
for _ in range(cnt):
if not t:
ans += "a"
continue
ans += letter(t.pop())
return ans[::-1]
n = int(eval(input()))
print((solve(n)))
|
def answer(n):
if n <= 26:
return chr(n-1 + 97)
r = n % 26 - 1
if r == -1:
r += 26
return answer((n-r) // 26) + chr(r + 97)
n = int(eval(input()))
print((answer(n)))
| 41
| 11
| 669
| 201
|
def base_k(n, k=26):
ret = []
ny = n
while ny:
ret.append(ny % k)
ny //= k
return ret[::-1]
def letter(i):
return chr(i + 97)
def solve(n):
check = 26
cnt = 1
k = n
while True:
if n <= check:
break
check *= 26
check += 26
cnt += 1
k -= check // 26 - 1
t = base_k(k - 1)
ans = ""
if not t:
ans = "a" * cnt
else:
for _ in range(cnt):
if not t:
ans += "a"
continue
ans += letter(t.pop())
return ans[::-1]
n = int(eval(input()))
print((solve(n)))
|
def answer(n):
if n <= 26:
return chr(n - 1 + 97)
r = n % 26 - 1
if r == -1:
r += 26
return answer((n - r) // 26) + chr(r + 97)
n = int(eval(input()))
print((answer(n)))
| false
| 73.170732
|
[
"-def base_k(n, k=26):",
"- ret = []",
"- ny = n",
"- while ny:",
"- ret.append(ny % k)",
"- ny //= k",
"- return ret[::-1]",
"-",
"-",
"-def letter(i):",
"- return chr(i + 97)",
"-",
"-",
"-def solve(n):",
"- check = 26",
"- cnt = 1",
"- k = n",
"- while True:",
"- if n <= check:",
"- break",
"- check *= 26",
"- check += 26",
"- cnt += 1",
"- k -= check // 26 - 1",
"- t = base_k(k - 1)",
"- ans = \"\"",
"- if not t:",
"- ans = \"a\" * cnt",
"- else:",
"- for _ in range(cnt):",
"- if not t:",
"- ans += \"a\"",
"- continue",
"- ans += letter(t.pop())",
"- return ans[::-1]",
"+def answer(n):",
"+ if n <= 26:",
"+ return chr(n - 1 + 97)",
"+ r = n % 26 - 1",
"+ if r == -1:",
"+ r += 26",
"+ return answer((n - r) // 26) + chr(r + 97)",
"-print((solve(n)))",
"+print((answer(n)))"
] | false
| 0.038125
| 0.090343
| 0.421997
|
[
"s815030426",
"s024515678"
] |
u609061751
|
p03033
|
python
|
s254876951
|
s854231952
| 1,499
| 1,227
| 129,784
| 112,348
|
Accepted
|
Accepted
| 18.15
|
import sys
input = lambda : sys.stdin.readline().rstrip()
def segfun(x, y):
return min(x, y)
ide_ele = float("inf")
class SegmentTree:
def __init__(self, n, ele, segfun):
self.ide_ele = ele
self.segfun = segfun
self.n = n
self.N0 = 1 << n.bit_length()
self.data = [self.ide_ele] * (self.N0 * 2)
def update(self, l, r, val):
l += self.N0
r += self.N0
while l < r:
if l & 1:
self.data[l] = self.segfun(self.data[l], val)
l += 1
if r & 1:
self.data[r - 1] = self.segfun(self.data[r - 1], val)
r -= 1
l //= 2
r //= 2
def query(self, i):
i += len(self.data) // 2
ret = self.data[i]
while i > 0:
i //= 2
ret = self.segfun(ret, self.data[i])
return ret
n, q = list(map(int, input().split()))
stx = []
for _ in range(n):
s, t, x = list(map(int, input().split()))
stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(eval(input())) for _ in range(q)]
import bisect
seg = SegmentTree(q, ide_ele, segfun)
for x, start, last in stx:
l = bisect.bisect_left(d, start)
r = bisect.bisect_left(d, last)
seg.update(l, r, x)
for i, j in enumerate(d):
res = seg.query(i)
if res == float("inf"):
print((-1))
else:
print(res)
|
import sys
input = lambda : sys.stdin.readline().rstrip()
def segfun(x, y):
return min(x, y)
ide_ele = 10**9 + 1
class SegmentTree:
def __init__(self, n, ele, segfun):
self.ide_ele = ele
self.segfun = segfun
self.n = n
self.N0 = 1 << n.bit_length()
self.data = [self.ide_ele] * (self.N0 * 2)
def update(self, l, r, val):
l += self.N0
r += self.N0
while l < r:
if l & 1:
self.data[l] = self.segfun(self.data[l], val)
l += 1
if r & 1:
self.data[r - 1] = self.segfun(self.data[r - 1], val)
r -= 1
l //= 2
r //= 2
def query(self, i):
i += len(self.data) // 2
ret = self.data[i]
while i > 0:
i //= 2
ret = self.segfun(ret, self.data[i])
return ret
n, q = list(map(int, input().split()))
stx = []
for _ in range(n):
s, t, x = list(map(int, input().split()))
stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(eval(input())) for _ in range(q)]
import bisect
seg = SegmentTree(q, ide_ele, segfun)
for x, start, last in stx:
l = bisect.bisect_left(d, start)
r = bisect.bisect_left(d, last)
seg.update(l, r, x)
for i, j in enumerate(d):
res = seg.query(i)
if res == ide_ele:
print((-1))
else:
print(res)
| 63
| 63
| 1,472
| 1,464
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def segfun(x, y):
return min(x, y)
ide_ele = float("inf")
class SegmentTree:
def __init__(self, n, ele, segfun):
self.ide_ele = ele
self.segfun = segfun
self.n = n
self.N0 = 1 << n.bit_length()
self.data = [self.ide_ele] * (self.N0 * 2)
def update(self, l, r, val):
l += self.N0
r += self.N0
while l < r:
if l & 1:
self.data[l] = self.segfun(self.data[l], val)
l += 1
if r & 1:
self.data[r - 1] = self.segfun(self.data[r - 1], val)
r -= 1
l //= 2
r //= 2
def query(self, i):
i += len(self.data) // 2
ret = self.data[i]
while i > 0:
i //= 2
ret = self.segfun(ret, self.data[i])
return ret
n, q = list(map(int, input().split()))
stx = []
for _ in range(n):
s, t, x = list(map(int, input().split()))
stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(eval(input())) for _ in range(q)]
import bisect
seg = SegmentTree(q, ide_ele, segfun)
for x, start, last in stx:
l = bisect.bisect_left(d, start)
r = bisect.bisect_left(d, last)
seg.update(l, r, x)
for i, j in enumerate(d):
res = seg.query(i)
if res == float("inf"):
print((-1))
else:
print(res)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def segfun(x, y):
return min(x, y)
ide_ele = 10**9 + 1
class SegmentTree:
def __init__(self, n, ele, segfun):
self.ide_ele = ele
self.segfun = segfun
self.n = n
self.N0 = 1 << n.bit_length()
self.data = [self.ide_ele] * (self.N0 * 2)
def update(self, l, r, val):
l += self.N0
r += self.N0
while l < r:
if l & 1:
self.data[l] = self.segfun(self.data[l], val)
l += 1
if r & 1:
self.data[r - 1] = self.segfun(self.data[r - 1], val)
r -= 1
l //= 2
r //= 2
def query(self, i):
i += len(self.data) // 2
ret = self.data[i]
while i > 0:
i //= 2
ret = self.segfun(ret, self.data[i])
return ret
n, q = list(map(int, input().split()))
stx = []
for _ in range(n):
s, t, x = list(map(int, input().split()))
stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(eval(input())) for _ in range(q)]
import bisect
seg = SegmentTree(q, ide_ele, segfun)
for x, start, last in stx:
l = bisect.bisect_left(d, start)
r = bisect.bisect_left(d, last)
seg.update(l, r, x)
for i, j in enumerate(d):
res = seg.query(i)
if res == ide_ele:
print((-1))
else:
print(res)
| false
| 0
|
[
"-ide_ele = float(\"inf\")",
"+ide_ele = 10**9 + 1",
"- if res == float(\"inf\"):",
"+ if res == ide_ele:"
] | false
| 0.050664
| 0.050425
| 1.004752
|
[
"s254876951",
"s854231952"
] |
u116038906
|
p02678
|
python
|
s738822544
|
s262303927
| 791
| 539
| 82,668
| 54,076
|
Accepted
|
Accepted
| 31.86
|
from collections import deque
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}
#構造入力
for i in range(1,M+1):
a,b = (int(x) for x in input().split())
connection[a].add(b)
connection[b].add(a)
#幅優先探索
dq =deque()
dq.append(1)
parent ={i:-1 for i in range(1,N+1)} #1につながっている=答え
parent[1] =0
while dq:
now =dq.popleft()
for next in connection[now]:
if parent[next] !=-1:
continue
else:
parent[next] =now
dq.append(next)
if -1 not in parent.values():
del parent[1]
print("Yes")
print(*parent.values(),sep="\n")
|
from collections import deque
from copy import copy
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
connection ={i:[] for i in range(0,N+1)}
connection[0] =[1]
#connection[1] =[0]
#構造入力
for i in range(M):
a,b = (int(x) for x in input().split())
connection[a].append(b)
connection[b].append(a)
# 幅優先探索
parent ={i:-1 for i in range(1,N+1)} #親=通過済、通過してない部屋はー1
parent[1] =0
children = deque()
children.extend(connection[1])
for i in children:
parent[i] =1
while children:
next =children.popleft()
for i in connection[next]:
if parent[i] != -1:
continue
else:
parent[i] =next
children.append(i)
#出力
print("Yes")
for i in range(2,N+1):
print((parent[i]))
| 30
| 35
| 692
| 793
|
from collections import deque
import sys
input = sys.stdin.readline
N, M = (int(x) for x in input().split())
connection = {i: set() for i in range(1, N + 1)}
# 構造入力
for i in range(1, M + 1):
a, b = (int(x) for x in input().split())
connection[a].add(b)
connection[b].add(a)
# 幅優先探索
dq = deque()
dq.append(1)
parent = {i: -1 for i in range(1, N + 1)} # 1につながっている=答え
parent[1] = 0
while dq:
now = dq.popleft()
for next in connection[now]:
if parent[next] != -1:
continue
else:
parent[next] = now
dq.append(next)
if -1 not in parent.values():
del parent[1]
print("Yes")
print(*parent.values(), sep="\n")
|
from collections import deque
from copy import copy
import sys
input = sys.stdin.readline
N, M = (int(x) for x in input().split())
connection = {i: [] for i in range(0, N + 1)}
connection[0] = [1]
# connection[1] =[0]
# 構造入力
for i in range(M):
a, b = (int(x) for x in input().split())
connection[a].append(b)
connection[b].append(a)
# 幅優先探索
parent = {i: -1 for i in range(1, N + 1)} # 親=通過済、通過してない部屋はー1
parent[1] = 0
children = deque()
children.extend(connection[1])
for i in children:
parent[i] = 1
while children:
next = children.popleft()
for i in connection[next]:
if parent[i] != -1:
continue
else:
parent[i] = next
children.append(i)
# 出力
print("Yes")
for i in range(2, N + 1):
print((parent[i]))
| false
| 14.285714
|
[
"+from copy import copy",
"-connection = {i: set() for i in range(1, N + 1)}",
"+connection = {i: [] for i in range(0, N + 1)}",
"+connection[0] = [1]",
"+# connection[1] =[0]",
"-for i in range(1, M + 1):",
"+for i in range(M):",
"- connection[a].add(b)",
"- connection[b].add(a)",
"+ connection[a].append(b)",
"+ connection[b].append(a)",
"-dq = deque()",
"-dq.append(1)",
"-parent = {i: -1 for i in range(1, N + 1)} # 1につながっている=答え",
"+parent = {i: -1 for i in range(1, N + 1)} # 親=通過済、通過してない部屋はー1",
"-while dq:",
"- now = dq.popleft()",
"- for next in connection[now]:",
"- if parent[next] != -1:",
"+children = deque()",
"+children.extend(connection[1])",
"+for i in children:",
"+ parent[i] = 1",
"+while children:",
"+ next = children.popleft()",
"+ for i in connection[next]:",
"+ if parent[i] != -1:",
"- parent[next] = now",
"- dq.append(next)",
"-if -1 not in parent.values():",
"- del parent[1]",
"- print(\"Yes\")",
"- print(*parent.values(), sep=\"\\n\")",
"+ parent[i] = next",
"+ children.append(i)",
"+# 出力",
"+print(\"Yes\")",
"+for i in range(2, N + 1):",
"+ print((parent[i]))"
] | false
| 0.037134
| 0.037241
| 0.997124
|
[
"s738822544",
"s262303927"
] |
u816587940
|
p02713
|
python
|
s051144224
|
s050721066
| 241
| 125
| 68,528
| 67,764
|
Accepted
|
Accepted
| 48.13
|
k = int(eval(input()))
def gcd(a, b):
if a < b: a, b = b, a
c = a % b
if c == 0: return b
while c!=0:
c = a % b
a, b = b, c
return a
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
t = gcd(a, b)
if t == 1:
ans += k
continue
for c in range(1, k+1):
ans += gcd(t, c)
print(ans)
|
from math import gcd
k = int(eval(input()))
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
t = gcd(a, b)
if t == 1:
ans += k
continue
for c in range(1, k+1): ans += gcd(t, c)
print(ans)
| 21
| 11
| 400
| 250
|
k = int(eval(input()))
def gcd(a, b):
if a < b:
a, b = b, a
c = a % b
if c == 0:
return b
while c != 0:
c = a % b
a, b = b, c
return a
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
t = gcd(a, b)
if t == 1:
ans += k
continue
for c in range(1, k + 1):
ans += gcd(t, c)
print(ans)
|
from math import gcd
k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
t = gcd(a, b)
if t == 1:
ans += k
continue
for c in range(1, k + 1):
ans += gcd(t, c)
print(ans)
| false
| 47.619048
|
[
"+from math import gcd",
"+",
"-",
"-",
"-def gcd(a, b):",
"- if a < b:",
"- a, b = b, a",
"- c = a % b",
"- if c == 0:",
"- return b",
"- while c != 0:",
"- c = a % b",
"- a, b = b, c",
"- return a",
"-",
"-"
] | false
| 0.118687
| 0.090338
| 1.313809
|
[
"s051144224",
"s050721066"
] |
u978313283
|
p03160
|
python
|
s937136917
|
s460568070
| 209
| 144
| 51,236
| 13,980
|
Accepted
|
Accepted
| 31.1
|
import sys
INF=100000000
def frog(i,h,dp):
global INF
if dp[i]!=INF:
return dp[i]
else:
if i==1:
dp[i]=0
return dp[i]
elif i==2:
dp[i]=abs(h[1]-h[0])
return dp[i]
else:
dp[i]=min(frog(i-2,h,dp)+abs(h[i-1]-h[i-3]),frog(i-1,h,dp)+abs(h[i-1]-h[i-2]))
return dp[i]
sys.setrecursionlimit(INF)
N=int(eval(input()))
h=list(map(int,input().split()))
dp=[INF for i in range(N+1)]
print((frog(N,h,dp)))
|
INF=10**15
N=int(eval(input()))
h=list(map(int,input().split()))
dp=[INF for i in range(N)]
dp[0]=0
for i in range(1,N):
if i>1:
dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
else:
dp[i]=dp[i-1]+abs(h[i]-h[i-1])
print((dp[N-1]))
| 21
| 11
| 521
| 269
|
import sys
INF = 100000000
def frog(i, h, dp):
global INF
if dp[i] != INF:
return dp[i]
else:
if i == 1:
dp[i] = 0
return dp[i]
elif i == 2:
dp[i] = abs(h[1] - h[0])
return dp[i]
else:
dp[i] = min(
frog(i - 2, h, dp) + abs(h[i - 1] - h[i - 3]),
frog(i - 1, h, dp) + abs(h[i - 1] - h[i - 2]),
)
return dp[i]
sys.setrecursionlimit(INF)
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [INF for i in range(N + 1)]
print((frog(N, h, dp)))
|
INF = 10**15
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [INF for i in range(N)]
dp[0] = 0
for i in range(1, N):
if i > 1:
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
else:
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
print((dp[N - 1]))
| false
| 47.619048
|
[
"-import sys",
"-",
"-INF = 100000000",
"-",
"-",
"-def frog(i, h, dp):",
"- global INF",
"- if dp[i] != INF:",
"- return dp[i]",
"- else:",
"- if i == 1:",
"- dp[i] = 0",
"- return dp[i]",
"- elif i == 2:",
"- dp[i] = abs(h[1] - h[0])",
"- return dp[i]",
"- else:",
"- dp[i] = min(",
"- frog(i - 2, h, dp) + abs(h[i - 1] - h[i - 3]),",
"- frog(i - 1, h, dp) + abs(h[i - 1] - h[i - 2]),",
"- )",
"- return dp[i]",
"-",
"-",
"-sys.setrecursionlimit(INF)",
"+INF = 10**15",
"-dp = [INF for i in range(N + 1)]",
"-print((frog(N, h, dp)))",
"+dp = [INF for i in range(N)]",
"+dp[0] = 0",
"+for i in range(1, N):",
"+ if i > 1:",
"+ dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"+ else:",
"+ dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])",
"+print((dp[N - 1]))"
] | false
| 0.06012
| 0.041336
| 1.454426
|
[
"s937136917",
"s460568070"
] |
u017810624
|
p03152
|
python
|
s419901655
|
s105093027
| 777
| 716
| 12,404
| 3,188
|
Accepted
|
Accepted
| 7.85
|
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=set(a);B=set(b)
if len(A)!=len(a) or len(B)!=len(b):
print((0))
else:
L=[]
for i in range(n):
l=[]
for j in range(m):
l.append(0)
L.append(l)
ct=1;ctn=0;ctm=0
for k in range(m*n,0,-1):
if k in A and k in B:
L[n-ctn-1][m-ctm-1]=k
ctn+=1;ctm+=1
elif k in A:
ct*=ctm;ctn+=1
elif k in B:
ct*=ctn;ctm+=1
else:
ct*=(ctm*ctn-m*n+k)
if ct==0:
break
ct=ct%(10**9+7)
print(ct)
|
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=set(a);B=set(b)
if len(A)!=len(a) or len(B)!=len(b):
print((0))
else:
L=[]
l=[0 for j in range(m)]
for i in range(n):
L.append(l)
ct=1;ctn=0;ctm=0
for k in range(m*n,0,-1):
if k in A and k in B:
L[n-ctn-1][m-ctm-1]=k
ctn+=1;ctm+=1
elif k in A:
ct*=ctm;ctn+=1
elif k in B:
ct*=ctn;ctm+=1
else:
ct*=(ctm*ctn-m*n+k)
if ct==0:
break
ct=ct%(10**9+7)
print(ct)
| 28
| 26
| 578
| 552
|
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = set(a)
B = set(b)
if len(A) != len(a) or len(B) != len(b):
print((0))
else:
L = []
for i in range(n):
l = []
for j in range(m):
l.append(0)
L.append(l)
ct = 1
ctn = 0
ctm = 0
for k in range(m * n, 0, -1):
if k in A and k in B:
L[n - ctn - 1][m - ctm - 1] = k
ctn += 1
ctm += 1
elif k in A:
ct *= ctm
ctn += 1
elif k in B:
ct *= ctn
ctm += 1
else:
ct *= ctm * ctn - m * n + k
if ct == 0:
break
ct = ct % (10**9 + 7)
print(ct)
|
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = set(a)
B = set(b)
if len(A) != len(a) or len(B) != len(b):
print((0))
else:
L = []
l = [0 for j in range(m)]
for i in range(n):
L.append(l)
ct = 1
ctn = 0
ctm = 0
for k in range(m * n, 0, -1):
if k in A and k in B:
L[n - ctn - 1][m - ctm - 1] = k
ctn += 1
ctm += 1
elif k in A:
ct *= ctm
ctn += 1
elif k in B:
ct *= ctn
ctm += 1
else:
ct *= ctm * ctn - m * n + k
if ct == 0:
break
ct = ct % (10**9 + 7)
print(ct)
| false
| 7.142857
|
[
"+ l = [0 for j in range(m)]",
"- l = []",
"- for j in range(m):",
"- l.append(0)"
] | false
| 0.03991
| 0.047482
| 0.84052
|
[
"s419901655",
"s105093027"
] |
u441064181
|
p02701
|
python
|
s672999419
|
s521073361
| 137
| 121
| 38,396
| 38,468
|
Accepted
|
Accepted
| 11.68
|
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
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())
N = I()
S = [S() for _ in range(N)]
dict = {}
for s in S:
if s not in dict:
dict[s] = 1
print((len(dict)))
|
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
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())
N = I()
S = [S() for _ in range(N)]
dict = {}
for s in S:
dict[s] = 1
print((len(dict)))
| 15
| 14
| 461
| 440
|
# import bisect,collections,copy,heapq,itertools,math,numpy,string
# from operator import itemgetter
import sys
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())
N = I()
S = [S() for _ in range(N)]
dict = {}
for s in S:
if s not in dict:
dict[s] = 1
print((len(dict)))
|
# import bisect,collections,copy,heapq,itertools,math,numpy,string
# from operator import itemgetter
import sys
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())
N = I()
S = [S() for _ in range(N)]
dict = {}
for s in S:
dict[s] = 1
print((len(dict)))
| false
| 6.666667
|
[
"- if s not in dict:",
"- dict[s] = 1",
"+ dict[s] = 1"
] | false
| 0.068402
| 0.048767
| 1.402626
|
[
"s672999419",
"s521073361"
] |
u059210959
|
p03377
|
python
|
s342559056
|
s411786859
| 156
| 39
| 13,124
| 10,820
|
Accepted
|
Accepted
| 75
|
# encoding:utf-8
import copy
import numpy as np
import random
a,b,x = list(map(int,input().split()))
if a<= x <= a+b:
ans = True
else:
ans = False
if ans:
print("YES")
else:
print("NO")
|
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
A, B, X = LI()
if A <= X <= A + B:
print("YES")
else:
print("NO")
| 17
| 23
| 216
| 471
|
# encoding:utf-8
import copy
import numpy as np
import random
a, b, x = list(map(int, input().split()))
if a <= x <= a + b:
ans = True
else:
ans = False
if ans:
print("YES")
else:
print("NO")
|
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect # bisect_left これで二部探索の大小検索が行える
import fractions # 最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9 + 7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI():
return list(map(int, sys.stdin.readline().split()))
A, B, X = LI()
if A <= X <= A + B:
print("YES")
else:
print("NO")
| false
| 26.086957
|
[
"+#!/usr/bin/env python3",
"-import numpy as np",
"+import bisect # bisect_left これで二部探索の大小検索が行える",
"+import fractions # 最小公倍数などはこっち",
"+import math",
"+import sys",
"+import collections",
"+from decimal import Decimal # 10進数で考慮できる",
"-a, b, x = list(map(int, input().split()))",
"-if a <= x <= a + b:",
"- ans = True",
"-else:",
"- ans = False",
"-if ans:",
"+mod = 10**9 + 7",
"+sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000",
"+d = collections.deque()",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+A, B, X = LI()",
"+if A <= X <= A + B:"
] | false
| 0.076095
| 0.045497
| 1.672546
|
[
"s342559056",
"s411786859"
] |
u186838327
|
p03695
|
python
|
s471432108
|
s934392177
| 163
| 18
| 38,256
| 3,064
|
Accepted
|
Accepted
| 88.96
|
n = int(eval(input()))
l = list(map(int, input().split()))
d = {}
for i in range(n):
if 1<=l[i]<=399:
a = 0
elif 400<=l[i]<=799:
a = 1
elif 800<=l[i]<=1199:
a = 2
elif 1200<=l[i]<=1599:
a = 3
elif 1600<=l[i]<=1999:
a = 4
elif 2000<=l[i]<=2399:
a = 5
elif 2400<=l[i]<=2799:
a = 6
elif 2800<=l[i]<=3199:
a = 7
else:
a = 8
if a in d:
d[a] += 1
else:
d[a] = 1
if not(8 in d):
print((len(list(d.keys())), len(list(d.keys()))))
else:
if len(list(d.keys())) == 1:
print((len(list(d.keys())), len(list(d.keys()))-1+d[8]))
else:
print((len(list(d.keys()))-1, len(list(d.keys()))-1+d[8]))
|
n = int(eval(input()))
A =list(map(int, input().split()))
cnt = 0
B = []
for i in range(n):
if 1 <= A[i] <= 399:
B.append(0)
elif 400 <= A[i] <= 799:
B.append(1)
elif 800 <= A[i] <= 1199:
B.append(2)
elif 1200 <= A[i] <= 1599:
B.append(3)
elif 1600 <= A[i] <= 1999:
B.append(4)
elif 2000 <= A[i] <= 2399:
B.append(5)
elif 2400 <= A[i] <= 2799:
B.append(6)
elif 2800 <= A[i] <= 3199:
B.append(7)
else:
#A[i] = 8
cnt += 1
#ans =len(set(A))+cnt-1
if len(B) == 0 and cnt != 0:
print((1, cnt))
else:
print((len(set(B)), len(set(B))+cnt))
| 34
| 29
| 640
| 675
|
n = int(eval(input()))
l = list(map(int, input().split()))
d = {}
for i in range(n):
if 1 <= l[i] <= 399:
a = 0
elif 400 <= l[i] <= 799:
a = 1
elif 800 <= l[i] <= 1199:
a = 2
elif 1200 <= l[i] <= 1599:
a = 3
elif 1600 <= l[i] <= 1999:
a = 4
elif 2000 <= l[i] <= 2399:
a = 5
elif 2400 <= l[i] <= 2799:
a = 6
elif 2800 <= l[i] <= 3199:
a = 7
else:
a = 8
if a in d:
d[a] += 1
else:
d[a] = 1
if not (8 in d):
print((len(list(d.keys())), len(list(d.keys()))))
else:
if len(list(d.keys())) == 1:
print((len(list(d.keys())), len(list(d.keys())) - 1 + d[8]))
else:
print((len(list(d.keys())) - 1, len(list(d.keys())) - 1 + d[8]))
|
n = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
B = []
for i in range(n):
if 1 <= A[i] <= 399:
B.append(0)
elif 400 <= A[i] <= 799:
B.append(1)
elif 800 <= A[i] <= 1199:
B.append(2)
elif 1200 <= A[i] <= 1599:
B.append(3)
elif 1600 <= A[i] <= 1999:
B.append(4)
elif 2000 <= A[i] <= 2399:
B.append(5)
elif 2400 <= A[i] <= 2799:
B.append(6)
elif 2800 <= A[i] <= 3199:
B.append(7)
else:
# A[i] = 8
cnt += 1
# ans =len(set(A))+cnt-1
if len(B) == 0 and cnt != 0:
print((1, cnt))
else:
print((len(set(B)), len(set(B)) + cnt))
| false
| 14.705882
|
[
"-l = list(map(int, input().split()))",
"-d = {}",
"+A = list(map(int, input().split()))",
"+cnt = 0",
"+B = []",
"- if 1 <= l[i] <= 399:",
"- a = 0",
"- elif 400 <= l[i] <= 799:",
"- a = 1",
"- elif 800 <= l[i] <= 1199:",
"- a = 2",
"- elif 1200 <= l[i] <= 1599:",
"- a = 3",
"- elif 1600 <= l[i] <= 1999:",
"- a = 4",
"- elif 2000 <= l[i] <= 2399:",
"- a = 5",
"- elif 2400 <= l[i] <= 2799:",
"- a = 6",
"- elif 2800 <= l[i] <= 3199:",
"- a = 7",
"+ if 1 <= A[i] <= 399:",
"+ B.append(0)",
"+ elif 400 <= A[i] <= 799:",
"+ B.append(1)",
"+ elif 800 <= A[i] <= 1199:",
"+ B.append(2)",
"+ elif 1200 <= A[i] <= 1599:",
"+ B.append(3)",
"+ elif 1600 <= A[i] <= 1999:",
"+ B.append(4)",
"+ elif 2000 <= A[i] <= 2399:",
"+ B.append(5)",
"+ elif 2400 <= A[i] <= 2799:",
"+ B.append(6)",
"+ elif 2800 <= A[i] <= 3199:",
"+ B.append(7)",
"- a = 8",
"- if a in d:",
"- d[a] += 1",
"- else:",
"- d[a] = 1",
"-if not (8 in d):",
"- print((len(list(d.keys())), len(list(d.keys()))))",
"+ # A[i] = 8",
"+ cnt += 1",
"+# ans =len(set(A))+cnt-1",
"+if len(B) == 0 and cnt != 0:",
"+ print((1, cnt))",
"- if len(list(d.keys())) == 1:",
"- print((len(list(d.keys())), len(list(d.keys())) - 1 + d[8]))",
"- else:",
"- print((len(list(d.keys())) - 1, len(list(d.keys())) - 1 + d[8]))",
"+ print((len(set(B)), len(set(B)) + cnt))"
] | false
| 0.08229
| 0.153426
| 0.536348
|
[
"s471432108",
"s934392177"
] |
u094191970
|
p03730
|
python
|
s379446548
|
s106693637
| 180
| 17
| 2,940
| 2,940
|
Accepted
|
Accepted
| 90.56
|
a,b,c=list(map(int,input().split()))
for i in range(1,10**6):
if (a*i)%b==c:
print('YES')
exit()
print('NO')
|
a,b,c=list(map(int,input().split()))
for i in range(1,b):
if (i*a)%b==c:
print('YES')
exit()
print('NO')
| 8
| 7
| 121
| 115
|
a, b, c = list(map(int, input().split()))
for i in range(1, 10**6):
if (a * i) % b == c:
print("YES")
exit()
print("NO")
|
a, b, c = list(map(int, input().split()))
for i in range(1, b):
if (i * a) % b == c:
print("YES")
exit()
print("NO")
| false
| 12.5
|
[
"-for i in range(1, 10**6):",
"- if (a * i) % b == c:",
"+for i in range(1, b):",
"+ if (i * a) % b == c:"
] | false
| 0.098002
| 0.042255
| 2.319315
|
[
"s379446548",
"s106693637"
] |
u970197315
|
p02762
|
python
|
s713218119
|
s526391499
| 1,622
| 972
| 63,988
| 37,944
|
Accepted
|
Accepted
| 40.07
|
# D - Friend Suggestions
from collections import Counter
N,M,K = list(map(int,input().split()))
AB = [tuple(map(int,input().split())) for i in range(M)]
CD = [tuple(map(int,input().split())) for i in range(K)]
class UnionFind:
def __init__(self,N):
self.parent = [i for i in range(N)]
self.rank = [0] * N
self.count = 0
def root(self,a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self,a,b):
return self.root(a) == self.root(b)
def unite(self,a,b):
ra = self.root(a)
rb = self.root(b)
if ra == rb: return
if self.rank[ra] < self.rank[rb]:
self.parent[ra] = rb
else:
self.parent[rb] = ra
if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
self.count += 1
blocks = [[] for _ in range(N)]
for c,d in CD:
c,d = c-1,d-1
blocks[c].append(d)
blocks[d].append(c)
friends = [0] * N
uf = UnionFind(N)
for a,b in AB:
a,b = a-1,b-1
friends[a] += 1
friends[b] += 1
if uf.is_same(a,b): continue
uf.unite(a,b)
for i in range(N):
uf.root(i)
ctr = Counter()
for i in range(N):
r = uf.root(i)
ctr[r] += 1
ans = []
for i in range(N):
tmp = ctr[uf.root(i)] - 1 - friends[i]
for b in blocks[i]:
if uf.is_same(i,b):
tmp -= 1
ans.append(tmp)
print((*ans))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m, k = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.p = [-1]*n
# union by rank
self.r = [1]*n
def find(self, x):
if self.p[x] < 0:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
rx, ry = self.find(x), self.find(y)
if rx != ry:
if self.r[rx] > self.r[ry]:
rx, ry = ry, rx
if self.r[rx] == self.r[ry]:
self.r[ry] += 1
self.p[ry] += self.p[rx]
self.p[rx] = ry
def same(self, x, y):
return self.find(x) == self.find(y)
def count_member(self, x):
return -self.p[self.find(x)]
uf = UnionFind(n)
ab = []
cd = []
for _ in range(m):
a, b = [int(x)-1 for x in input().split()]
ab.append((a, b))
uf.union(a, b)
for _ in range(k):
c, d = [int(x)-1 for x in input().split()]
cd.append((c, d))
ans = [uf.count_member(i)-1 for i in range(n)]
for a, b in ab:
if uf.same(a, b):
ans[a] -= 1
ans[b] -= 1
for c, d in cd:
if uf.same(c, d):
ans[c] -= 1
ans[d] -= 1
print((*ans))
| 60
| 62
| 1,525
| 1,345
|
# D - Friend Suggestions
from collections import Counter
N, M, K = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for i in range(M)]
CD = [tuple(map(int, input().split())) for i in range(K)]
class UnionFind:
def __init__(self, N):
self.parent = [i for i in range(N)]
self.rank = [0] * N
self.count = 0
def root(self, a):
if self.parent[a] == a:
return a
else:
self.parent[a] = self.root(self.parent[a])
return self.parent[a]
def is_same(self, a, b):
return self.root(a) == self.root(b)
def unite(self, a, b):
ra = self.root(a)
rb = self.root(b)
if ra == rb:
return
if self.rank[ra] < self.rank[rb]:
self.parent[ra] = rb
else:
self.parent[rb] = ra
if self.rank[ra] == self.rank[rb]:
self.rank[ra] += 1
self.count += 1
blocks = [[] for _ in range(N)]
for c, d in CD:
c, d = c - 1, d - 1
blocks[c].append(d)
blocks[d].append(c)
friends = [0] * N
uf = UnionFind(N)
for a, b in AB:
a, b = a - 1, b - 1
friends[a] += 1
friends[b] += 1
if uf.is_same(a, b):
continue
uf.unite(a, b)
for i in range(N):
uf.root(i)
ctr = Counter()
for i in range(N):
r = uf.root(i)
ctr[r] += 1
ans = []
for i in range(N):
tmp = ctr[uf.root(i)] - 1 - friends[i]
for b in blocks[i]:
if uf.is_same(i, b):
tmp -= 1
ans.append(tmp)
print((*ans))
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m, k = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.p = [-1] * n
# union by rank
self.r = [1] * n
def find(self, x):
if self.p[x] < 0:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
rx, ry = self.find(x), self.find(y)
if rx != ry:
if self.r[rx] > self.r[ry]:
rx, ry = ry, rx
if self.r[rx] == self.r[ry]:
self.r[ry] += 1
self.p[ry] += self.p[rx]
self.p[rx] = ry
def same(self, x, y):
return self.find(x) == self.find(y)
def count_member(self, x):
return -self.p[self.find(x)]
uf = UnionFind(n)
ab = []
cd = []
for _ in range(m):
a, b = [int(x) - 1 for x in input().split()]
ab.append((a, b))
uf.union(a, b)
for _ in range(k):
c, d = [int(x) - 1 for x in input().split()]
cd.append((c, d))
ans = [uf.count_member(i) - 1 for i in range(n)]
for a, b in ab:
if uf.same(a, b):
ans[a] -= 1
ans[b] -= 1
for c, d in cd:
if uf.same(c, d):
ans[c] -= 1
ans[d] -= 1
print((*ans))
| false
| 3.225806
|
[
"-# D - Friend Suggestions",
"-from collections import Counter",
"+import sys",
"-N, M, K = list(map(int, input().split()))",
"-AB = [tuple(map(int, input().split())) for i in range(M)]",
"-CD = [tuple(map(int, input().split())) for i in range(K)]",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**7)",
"+n, m, k = list(map(int, input().split()))",
"- def __init__(self, N):",
"- self.parent = [i for i in range(N)]",
"- self.rank = [0] * N",
"- self.count = 0",
"+ def __init__(self, n):",
"+ self.p = [-1] * n",
"+ # union by rank",
"+ self.r = [1] * n",
"- def root(self, a):",
"- if self.parent[a] == a:",
"- return a",
"+ def find(self, x):",
"+ if self.p[x] < 0:",
"+ return x",
"- self.parent[a] = self.root(self.parent[a])",
"- return self.parent[a]",
"+ self.p[x] = self.find(self.p[x])",
"+ return self.p[x]",
"- def is_same(self, a, b):",
"- return self.root(a) == self.root(b)",
"+ def union(self, x, y):",
"+ rx, ry = self.find(x), self.find(y)",
"+ if rx != ry:",
"+ if self.r[rx] > self.r[ry]:",
"+ rx, ry = ry, rx",
"+ if self.r[rx] == self.r[ry]:",
"+ self.r[ry] += 1",
"+ self.p[ry] += self.p[rx]",
"+ self.p[rx] = ry",
"- def unite(self, a, b):",
"- ra = self.root(a)",
"- rb = self.root(b)",
"- if ra == rb:",
"- return",
"- if self.rank[ra] < self.rank[rb]:",
"- self.parent[ra] = rb",
"- else:",
"- self.parent[rb] = ra",
"- if self.rank[ra] == self.rank[rb]:",
"- self.rank[ra] += 1",
"- self.count += 1",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def count_member(self, x):",
"+ return -self.p[self.find(x)]",
"-blocks = [[] for _ in range(N)]",
"-for c, d in CD:",
"- c, d = c - 1, d - 1",
"- blocks[c].append(d)",
"- blocks[d].append(c)",
"-friends = [0] * N",
"-uf = UnionFind(N)",
"-for a, b in AB:",
"- a, b = a - 1, b - 1",
"- friends[a] += 1",
"- friends[b] += 1",
"- if uf.is_same(a, b):",
"- continue",
"- uf.unite(a, b)",
"-for i in range(N):",
"- uf.root(i)",
"-ctr = Counter()",
"-for i in range(N):",
"- r = uf.root(i)",
"- ctr[r] += 1",
"-ans = []",
"-for i in range(N):",
"- tmp = ctr[uf.root(i)] - 1 - friends[i]",
"- for b in blocks[i]:",
"- if uf.is_same(i, b):",
"- tmp -= 1",
"- ans.append(tmp)",
"+uf = UnionFind(n)",
"+ab = []",
"+cd = []",
"+for _ in range(m):",
"+ a, b = [int(x) - 1 for x in input().split()]",
"+ ab.append((a, b))",
"+ uf.union(a, b)",
"+for _ in range(k):",
"+ c, d = [int(x) - 1 for x in input().split()]",
"+ cd.append((c, d))",
"+ans = [uf.count_member(i) - 1 for i in range(n)]",
"+for a, b in ab:",
"+ if uf.same(a, b):",
"+ ans[a] -= 1",
"+ ans[b] -= 1",
"+for c, d in cd:",
"+ if uf.same(c, d):",
"+ ans[c] -= 1",
"+ ans[d] -= 1"
] | false
| 0.039947
| 0.110907
| 0.360183
|
[
"s713218119",
"s526391499"
] |
u906428167
|
p02821
|
python
|
s466439957
|
s228028161
| 1,050
| 305
| 57,220
| 55,448
|
Accepted
|
Accepted
| 70.95
|
from bisect import bisect_left
from bisect import bisect_right
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0]*110000
a_sum = [0]*110000
for i in range(n):
a_count[a[i]] += 1
a_sum[a[i]] += a[i]
for i in range(100005,0,-1):
a_count[i] += a_count[i+1]
a_sum[i] += a_sum[i+1]
def chk(x):
case = 0
for i in range(n):
case += n-bisect_right(a,x-a[i]-1)
if case >= m:
ch = True
else:
ch = False
return ch
l = 2*a[-1]+1 #NG
r = 1 #OK
while abs(r-l) > 1:
kk = (r+l)//2
if chk(kk):
r = kk
else:
l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
num = n-bisect_right(a,l-a[i]-1)
case += num
ans += num*a[i]*2
ans -= (case-m)*l
print(ans)
|
from bisect import bisect_left
from bisect import bisect_right
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0]*100010
a_sum = [0]*100010
for i in range(n):
a_count[a[i]] += 1
a_sum[a[i]] += a[i]
for i in range(100005,-1,-1):
a_count[i] += a_count[i+1]
a_sum[i] += a_sum[i+1]
def chk(x):
case = 0
for i in range(n):
if 0<= x-a[i]<= 10**5+5:
case += a_count[x-a[i]]
elif x-a[i] < 0:
case += n
if case >= m:
ch = True
else:
ch = False
return ch
l = 2*a[-1]+1 #NG
r = 1 #OK
while abs(r-l) > 1:
kk = (r+l)//2
if chk(kk):
r = kk
else:
l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
num = n-bisect_right(a,l-a[i]-1)
case += num
ans += num*a[i]*2
ans -= (case-m)*l
print(ans)
| 53
| 55
| 855
| 930
|
from bisect import bisect_left
from bisect import bisect_right
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0] * 110000
a_sum = [0] * 110000
for i in range(n):
a_count[a[i]] += 1
a_sum[a[i]] += a[i]
for i in range(100005, 0, -1):
a_count[i] += a_count[i + 1]
a_sum[i] += a_sum[i + 1]
def chk(x):
case = 0
for i in range(n):
case += n - bisect_right(a, x - a[i] - 1)
if case >= m:
ch = True
else:
ch = False
return ch
l = 2 * a[-1] + 1 # NG
r = 1 # OK
while abs(r - l) > 1:
kk = (r + l) // 2
if chk(kk):
r = kk
else:
l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
num = n - bisect_right(a, l - a[i] - 1)
case += num
ans += num * a[i] * 2
ans -= (case - m) * l
print(ans)
|
from bisect import bisect_left
from bisect import bisect_right
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0] * 100010
a_sum = [0] * 100010
for i in range(n):
a_count[a[i]] += 1
a_sum[a[i]] += a[i]
for i in range(100005, -1, -1):
a_count[i] += a_count[i + 1]
a_sum[i] += a_sum[i + 1]
def chk(x):
case = 0
for i in range(n):
if 0 <= x - a[i] <= 10**5 + 5:
case += a_count[x - a[i]]
elif x - a[i] < 0:
case += n
if case >= m:
ch = True
else:
ch = False
return ch
l = 2 * a[-1] + 1 # NG
r = 1 # OK
while abs(r - l) > 1:
kk = (r + l) // 2
if chk(kk):
r = kk
else:
l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
num = n - bisect_right(a, l - a[i] - 1)
case += num
ans += num * a[i] * 2
ans -= (case - m) * l
print(ans)
| false
| 3.636364
|
[
"-a_count = [0] * 110000",
"-a_sum = [0] * 110000",
"+a_count = [0] * 100010",
"+a_sum = [0] * 100010",
"-for i in range(100005, 0, -1):",
"+for i in range(100005, -1, -1):",
"- case += n - bisect_right(a, x - a[i] - 1)",
"+ if 0 <= x - a[i] <= 10**5 + 5:",
"+ case += a_count[x - a[i]]",
"+ elif x - a[i] < 0:",
"+ case += n"
] | false
| 0.099495
| 0.092737
| 1.072877
|
[
"s466439957",
"s228028161"
] |
u811733736
|
p02271
|
python
|
s445190921
|
s804921818
| 6,150
| 830
| 7,756
| 135,424
|
Accepted
|
Accepted
| 86.5
|
from itertools import combinations
if __name__ == '__main__':
# ??????????????\???
num1 = int(eval(input()))
A = [int(x) for x in input().split(' ')]
num2 = int(eval(input()))
M = [int(x) for x in input().split(' ')]
#A = [1, 5, 7, 10, 21]
#pick = 4
#M = [2, 4, 17, 8]
# ????????????
results = ['no' for x in range(len(M))] # M?????¨??????????´?????????????????????????????????§????????????????????±???(no)??¨????????????
for p in range(1, len(A)+1): # A????????????1????????¨????????°?????????????????¢????????????
combi = combinations(A, p) # n??????????????¢??????????????´????????¨?????????????????????
for choice in combi:
total = sum(choice)
while total in M:
i = M.index(total)
results[i] = 'yes'
M[i] = 'Done'
# ???????????????
for txt in results:
print(txt)
|
from functools import lru_cache
@lru_cache(maxsize=None)
def is_possible(n, target, total):
if n == 0:
return total == target
return is_possible(n-1, target, total) or is_possible(n-1, target, total + A[n-1])
n = int(eval(input()))
A = [int(i) for i in input().split()]
_ = int(eval(input()))
for target in map(int, input().split()):
print(('yes' if is_possible(n, target, 0) else'no'))
| 27
| 17
| 935
| 415
|
from itertools import combinations
if __name__ == "__main__":
# ??????????????\???
num1 = int(eval(input()))
A = [int(x) for x in input().split(" ")]
num2 = int(eval(input()))
M = [int(x) for x in input().split(" ")]
# A = [1, 5, 7, 10, 21]
# pick = 4
# M = [2, 4, 17, 8]
# ????????????
results = [
"no" for x in range(len(M))
] # M?????¨??????????´?????????????????????????????????§????????????????????±???(no)??¨????????????
for p in range(
1, len(A) + 1
): # A????????????1????????¨????????°?????????????????¢????????????
combi = combinations(
A, p
) # n??????????????¢??????????????´????????¨?????????????????????
for choice in combi:
total = sum(choice)
while total in M:
i = M.index(total)
results[i] = "yes"
M[i] = "Done"
# ???????????????
for txt in results:
print(txt)
|
from functools import lru_cache
@lru_cache(maxsize=None)
def is_possible(n, target, total):
if n == 0:
return total == target
return is_possible(n - 1, target, total) or is_possible(
n - 1, target, total + A[n - 1]
)
n = int(eval(input()))
A = [int(i) for i in input().split()]
_ = int(eval(input()))
for target in map(int, input().split()):
print(("yes" if is_possible(n, target, 0) else "no"))
| false
| 37.037037
|
[
"-from itertools import combinations",
"+from functools import lru_cache",
"-if __name__ == \"__main__\":",
"- # ??????????????\\???",
"- num1 = int(eval(input()))",
"- A = [int(x) for x in input().split(\" \")]",
"- num2 = int(eval(input()))",
"- M = [int(x) for x in input().split(\" \")]",
"- # A = [1, 5, 7, 10, 21]",
"- # pick = 4",
"- # M = [2, 4, 17, 8]",
"- # ????????????",
"- results = [",
"- \"no\" for x in range(len(M))",
"- ] # M?????¨??????????´?????????????????????????????????§????????????????????±???(no)??¨????????????",
"- for p in range(",
"- 1, len(A) + 1",
"- ): # A????????????1????????¨????????°?????????????????¢????????????",
"- combi = combinations(",
"- A, p",
"- ) # n??????????????¢??????????????´????????¨?????????????????????",
"- for choice in combi:",
"- total = sum(choice)",
"- while total in M:",
"- i = M.index(total)",
"- results[i] = \"yes\"",
"- M[i] = \"Done\"",
"- # ???????????????",
"- for txt in results:",
"- print(txt)",
"+",
"+@lru_cache(maxsize=None)",
"+def is_possible(n, target, total):",
"+ if n == 0:",
"+ return total == target",
"+ return is_possible(n - 1, target, total) or is_possible(",
"+ n - 1, target, total + A[n - 1]",
"+ )",
"+",
"+",
"+n = int(eval(input()))",
"+A = [int(i) for i in input().split()]",
"+_ = int(eval(input()))",
"+for target in map(int, input().split()):",
"+ print((\"yes\" if is_possible(n, target, 0) else \"no\"))"
] | false
| 0.036723
| 0.036594
| 1.003527
|
[
"s445190921",
"s804921818"
] |
u910288980
|
p03416
|
python
|
s828545791
|
s091411646
| 104
| 53
| 2,940
| 2,940
|
Accepted
|
Accepted
| 49.04
|
a, b = list(map(int, input().split()))
ans = 0
for x in range(a,b+1):
s = str(x)
if s == ''.join(reversed(s)):
ans += 1
print(ans)
|
a, b = list(map(int, input().split()))
ans = 0
for x in range(a,b+1):
s = str(x)
# if s == ''.join(reversed(s)):
if s == s[::-1] :
ans += 1
print(ans)
| 9
| 10
| 151
| 176
|
a, b = list(map(int, input().split()))
ans = 0
for x in range(a, b + 1):
s = str(x)
if s == "".join(reversed(s)):
ans += 1
print(ans)
|
a, b = list(map(int, input().split()))
ans = 0
for x in range(a, b + 1):
s = str(x)
# if s == ''.join(reversed(s)):
if s == s[::-1]:
ans += 1
print(ans)
| false
| 10
|
[
"- if s == \"\".join(reversed(s)):",
"+ # if s == ''.join(reversed(s)):",
"+ if s == s[::-1]:"
] | false
| 0.050231
| 0.04443
| 1.130563
|
[
"s828545791",
"s091411646"
] |
u698868214
|
p02898
|
python
|
s790087177
|
s024333140
| 63
| 58
| 18,532
| 18,652
|
Accepted
|
Accepted
| 7.94
|
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
h = sorted(h)
line = 0
bool1 = False
for i in range(N):
if h[i] >= K:
line = i
bool1 = True
break
if bool1:
print((N-i))
else:
print((0))
|
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
ans = 0
for i in h:
if i >= K:
ans += 1
print(ans)
| 16
| 8
| 234
| 130
|
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
h = sorted(h)
line = 0
bool1 = False
for i in range(N):
if h[i] >= K:
line = i
bool1 = True
break
if bool1:
print((N - i))
else:
print((0))
|
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = 0
for i in h:
if i >= K:
ans += 1
print(ans)
| false
| 50
|
[
"-h = sorted(h)",
"-line = 0",
"-bool1 = False",
"-for i in range(N):",
"- if h[i] >= K:",
"- line = i",
"- bool1 = True",
"- break",
"-if bool1:",
"- print((N - i))",
"-else:",
"- print((0))",
"+ans = 0",
"+for i in h:",
"+ if i >= K:",
"+ ans += 1",
"+print(ans)"
] | false
| 0.048011
| 0.044964
| 1.067773
|
[
"s790087177",
"s024333140"
] |
u401452016
|
p02936
|
python
|
s227915521
|
s991455134
| 1,897
| 1,660
| 351,060
| 328,172
|
Accepted
|
Accepted
| 12.49
|
import sys
sys.setrecursionlimit(1000000)
L = sys.stdin.readlines()
for i in range(len(L)):
L[i] = list(map(int, L[i].split()))
n =L[0][0]
rin = [[] for _ in range(n)]
for v in L[1:n]:
rin[v[0]-1].append(v[1]-1)
rin[v[1]-1].append(v[0]-1)
score = [0 for _ in range(n)]
for ele in L[n:]:
score[ele[0]-1] +=ele[1]
#print(score)
def dfs(p, bp=-1):
for c in rin[p]:
if c != bp:
#print(c)
score[c]+= score[p]
dfs(c, p)
dfs(0)
print((*score))
|
#ABC138D
#node:節 edge:枝
def main():
import sys
sys.setrecursionlimit(200005)
N, Q = list(map(int, sys.stdin.readline().split()))
edge = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
#1:ノードのリストを作る
nodeL = [[] for _ in range(N)]
for a, b in edge:
nodeL[a-1].append(b-1)
nodeL[b-1].append(a-1)
#print(nodeL)
px = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
#print(px)
score = [0 for i in range(N)]
for p, x in px:
score[p-1] +=x
#print(score)
result = score.copy()
def dfs(p, g=-1):
for c in nodeL[p]:
if c !=g:
score[c] +=score[p]
dfs(c, p)
dfs(0)
print((*score))
if __name__=='__main__':
main()
| 26
| 35
| 533
| 834
|
import sys
sys.setrecursionlimit(1000000)
L = sys.stdin.readlines()
for i in range(len(L)):
L[i] = list(map(int, L[i].split()))
n = L[0][0]
rin = [[] for _ in range(n)]
for v in L[1:n]:
rin[v[0] - 1].append(v[1] - 1)
rin[v[1] - 1].append(v[0] - 1)
score = [0 for _ in range(n)]
for ele in L[n:]:
score[ele[0] - 1] += ele[1]
# print(score)
def dfs(p, bp=-1):
for c in rin[p]:
if c != bp:
# print(c)
score[c] += score[p]
dfs(c, p)
dfs(0)
print((*score))
|
# ABC138D
# node:節 edge:枝
def main():
import sys
sys.setrecursionlimit(200005)
N, Q = list(map(int, sys.stdin.readline().split()))
edge = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]
# 1:ノードのリストを作る
nodeL = [[] for _ in range(N)]
for a, b in edge:
nodeL[a - 1].append(b - 1)
nodeL[b - 1].append(a - 1)
# print(nodeL)
px = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
# print(px)
score = [0 for i in range(N)]
for p, x in px:
score[p - 1] += x
# print(score)
result = score.copy()
def dfs(p, g=-1):
for c in nodeL[p]:
if c != g:
score[c] += score[p]
dfs(c, p)
dfs(0)
print((*score))
if __name__ == "__main__":
main()
| false
| 25.714286
|
[
"-import sys",
"+# ABC138D",
"+# node:節 edge:枝",
"+def main():",
"+ import sys",
"-sys.setrecursionlimit(1000000)",
"-L = sys.stdin.readlines()",
"-for i in range(len(L)):",
"- L[i] = list(map(int, L[i].split()))",
"-n = L[0][0]",
"-rin = [[] for _ in range(n)]",
"-for v in L[1:n]:",
"- rin[v[0] - 1].append(v[1] - 1)",
"- rin[v[1] - 1].append(v[0] - 1)",
"-score = [0 for _ in range(n)]",
"-for ele in L[n:]:",
"- score[ele[0] - 1] += ele[1]",
"-# print(score)",
"-def dfs(p, bp=-1):",
"- for c in rin[p]:",
"- if c != bp:",
"- # print(c)",
"- score[c] += score[p]",
"- dfs(c, p)",
"+ sys.setrecursionlimit(200005)",
"+ N, Q = list(map(int, sys.stdin.readline().split()))",
"+ edge = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]",
"+ # 1:ノードのリストを作る",
"+ nodeL = [[] for _ in range(N)]",
"+ for a, b in edge:",
"+ nodeL[a - 1].append(b - 1)",
"+ nodeL[b - 1].append(a - 1)",
"+ # print(nodeL)",
"+ px = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]",
"+ # print(px)",
"+ score = [0 for i in range(N)]",
"+ for p, x in px:",
"+ score[p - 1] += x",
"+ # print(score)",
"+ result = score.copy()",
"+",
"+ def dfs(p, g=-1):",
"+ for c in nodeL[p]:",
"+ if c != g:",
"+ score[c] += score[p]",
"+ dfs(c, p)",
"+",
"+ dfs(0)",
"+ print((*score))",
"-dfs(0)",
"-print((*score))",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.040481
| 0.040663
| 0.995509
|
[
"s227915521",
"s991455134"
] |
u102242691
|
p03658
|
python
|
s615073701
|
s316258470
| 20
| 17
| 2,940
| 2,940
|
Accepted
|
Accepted
| 15
|
N,K = list(map(int,input().split()))
l = list(map(int,input().split()))
k = sorted(l)
ans = 0
for i in range(K):
ans += k.pop()
print(ans)
|
n,k = list(map(int,input().split()))
l = list(map(int,input().split()))
l.sort(reverse = True)
ans = 0
for i in range(k):
ans += l[i]
print(ans)
| 12
| 9
| 153
| 153
|
N, K = list(map(int, input().split()))
l = list(map(int, input().split()))
k = sorted(l)
ans = 0
for i in range(K):
ans += k.pop()
print(ans)
|
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(k):
ans += l[i]
print(ans)
| false
| 25
|
[
"-N, K = list(map(int, input().split()))",
"+n, k = list(map(int, input().split()))",
"-k = sorted(l)",
"+l.sort(reverse=True)",
"-for i in range(K):",
"- ans += k.pop()",
"+for i in range(k):",
"+ ans += l[i]"
] | false
| 0.0468
| 0.044821
| 1.044139
|
[
"s615073701",
"s316258470"
] |
u229973939
|
p02388
|
python
|
s636003275
|
s963204137
| 20
| 10
| 5,576
| 5,576
|
Accepted
|
Accepted
| 50
|
x = eval(input())
print((int(x) ** 3))
|
x = int(eval(input()))
print((x*x*x))
| 3
| 3
| 34
| 33
|
x = eval(input())
print((int(x) ** 3))
|
x = int(eval(input()))
print((x * x * x))
| false
| 0
|
[
"-x = eval(input())",
"-print((int(x) ** 3))",
"+x = int(eval(input()))",
"+print((x * x * x))"
] | false
| 0.039025
| 0.074343
| 0.524936
|
[
"s636003275",
"s963204137"
] |
u425762225
|
p03971
|
python
|
s011244473
|
s826927679
| 407
| 69
| 4,000
| 9,780
|
Accepted
|
Accepted
| 83.05
|
N, A, B = list(map(int,input().split()))
S = eval(input())
a_counter = 0
b_counter = 0
for i in range(N):
s = S[0]
if s == "a" and a_counter + b_counter <A+B:
a_counter += 1
print("Yes")
elif s == "b" and b_counter < B and a_counter + b_counter <A+B:
b_counter += 1
print("Yes")
else:
print("No")
S = S[1:]
|
#!/usr/bin/env python3
# from numba import njit
# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left
# @njit
def solve(n,a,b,s):
ans = [""]*n
japaneseStudents = 0
foreignStudents = 0
for i in range(n):
if s[i] == "a" and japaneseStudents + foreignStudents < a+b:
ans[i] = "Yes"
japaneseStudents += 1
elif s[i] == "b" and japaneseStudents + foreignStudents < a+b and foreignStudents < b:
ans[i] = "Yes"
foreignStudents += 1
else:
ans[i] = "No"
return ans
def main():
N,A,B = list(map(int,input().split()))
s = eval(input())
ans = solve(N,A,B,s)
for i in range(N):
print((ans[i]))
return
if __name__ == '__main__':
main()
| 18
| 38
| 346
| 825
|
N, A, B = list(map(int, input().split()))
S = eval(input())
a_counter = 0
b_counter = 0
for i in range(N):
s = S[0]
if s == "a" and a_counter + b_counter < A + B:
a_counter += 1
print("Yes")
elif s == "b" and b_counter < B and a_counter + b_counter < A + B:
b_counter += 1
print("Yes")
else:
print("No")
S = S[1:]
|
#!/usr/bin/env python3
# from numba import njit
# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left
# @njit
def solve(n, a, b, s):
ans = [""] * n
japaneseStudents = 0
foreignStudents = 0
for i in range(n):
if s[i] == "a" and japaneseStudents + foreignStudents < a + b:
ans[i] = "Yes"
japaneseStudents += 1
elif (
s[i] == "b"
and japaneseStudents + foreignStudents < a + b
and foreignStudents < b
):
ans[i] = "Yes"
foreignStudents += 1
else:
ans[i] = "No"
return ans
def main():
N, A, B = list(map(int, input().split()))
s = eval(input())
ans = solve(N, A, B, s)
for i in range(N):
print((ans[i]))
return
if __name__ == "__main__":
main()
| false
| 52.631579
|
[
"-N, A, B = list(map(int, input().split()))",
"-S = eval(input())",
"-a_counter = 0",
"-b_counter = 0",
"-for i in range(N):",
"- s = S[0]",
"- if s == \"a\" and a_counter + b_counter < A + B:",
"- a_counter += 1",
"- print(\"Yes\")",
"- elif s == \"b\" and b_counter < B and a_counter + b_counter < A + B:",
"- b_counter += 1",
"- print(\"Yes\")",
"- else:",
"- print(\"No\")",
"- S = S[1:]",
"+#!/usr/bin/env python3",
"+# from numba import njit",
"+# from collections import Counter",
"+# from itertools import accumulate",
"+# import numpy as np",
"+# from heapq import heappop,heappush",
"+# from bisect import bisect_left",
"+# @njit",
"+def solve(n, a, b, s):",
"+ ans = [\"\"] * n",
"+ japaneseStudents = 0",
"+ foreignStudents = 0",
"+ for i in range(n):",
"+ if s[i] == \"a\" and japaneseStudents + foreignStudents < a + b:",
"+ ans[i] = \"Yes\"",
"+ japaneseStudents += 1",
"+ elif (",
"+ s[i] == \"b\"",
"+ and japaneseStudents + foreignStudents < a + b",
"+ and foreignStudents < b",
"+ ):",
"+ ans[i] = \"Yes\"",
"+ foreignStudents += 1",
"+ else:",
"+ ans[i] = \"No\"",
"+ return ans",
"+",
"+",
"+def main():",
"+ N, A, B = list(map(int, input().split()))",
"+ s = eval(input())",
"+ ans = solve(N, A, B, s)",
"+ for i in range(N):",
"+ print((ans[i]))",
"+ return",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.11444
| 0.036171
| 3.163887
|
[
"s011244473",
"s826927679"
] |
u761529120
|
p02949
|
python
|
s963096695
|
s873243156
| 1,635
| 717
| 54,748
| 48,876
|
Accepted
|
Accepted
| 56.15
|
from collections import deque
import sys
input = sys.stdin.readline
def main():
N, M, P = list(map(int, input().split()))
edge = [[] for _ in range(N)]
redge = [[] for _ in range(N)]
for _ in range(M):
A, B, C = list(map(int, input().split()))
A -= 1
B -= 1
C -= P
C = -C
edge[A].append((B,C))
redge[B].append(A)
# 0 => N-1の間にある閉路を検出したいので
# 0とN-1からたどりつけない場所は前処理で取り除く
visited1, visited2 = {0}, {N-1}
stack = [0]
while stack:
v = stack.pop()
for dest, _ in edge[v]:
if dest in visited1:
continue
visited1.add(dest)
stack.append(dest)
stack = [N-1]
while stack:
v = stack.pop()
for dest in redge[v]:
if dest in visited2:
continue
visited2.add(dest)
stack.append(dest)
OK = visited1 & visited2
new_edge = [[] for _ in range(N)]
for s in range(N):
for t, c in edge[s]:
if t in OK:
new_edge[s].append((t,c))
flag = True
d = [float('inf')] * N
d[0] = 0
#ベルマンフォード法、N回実行してまだ更新されている場合は負の閉路が存在する
for _ in range(N):
flag = False
for v, e in enumerate(new_edge):
for t, c in e:
if d[v] != float('inf') and d[v] + c < d[t]:
d[t] = d[v] + c
flag = True
if not flag:
print((max(0,-d[N-1])))
exit()
else:
print((-1))
exit()
if __name__ == "__main__":
main()
|
from collections import deque
import sys
input = sys.stdin.readline
def main():
N, M, P = list(map(int, input().split()))
edge = []
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(M):
A, B, C = list(map(int, input().split()))
A -= 1
B -= 1
C -= P
C = -C
edge.append((A,B,C))
g[A].append(B)
rg[B].append(A)
# 0 => N-1の間にある閉路を検出したいので
# 0とN-1からたどりつけない場所は前処理で取り除く
visited1 = set()
visited2 = set()
visited1.add(0)
visited2.add(N-1)
Q = deque()
Q.append(0)
while Q:
v = Q.popleft()
for dest in g[v]:
if dest in visited1:
continue
visited1.add(dest)
Q.append(dest)
Q.append(N-1)
while Q:
v = Q.popleft()
for dest in rg[v]:
if dest in visited2:
continue
visited2.add(dest)
Q.append(dest)
OK = visited1 & visited2
flag = True
d = [float('inf')] * N
d[0] = 0
#ベルマンフォード法、N回実行してまだ更新されている場合は負の閉路が存在する
for _ in range(N):
flag = False
for a, b, c in edge:
if not a in OK:
continue
if not b in OK:
continue
newD = d[a] + c
if newD < d[b]:
d[b] = newD
flag = True
if not flag:
print((max(0,-d[N-1])))
exit()
else:
print((-1))
exit()
if __name__ == "__main__":
main()
| 70
| 73
| 1,668
| 1,626
|
from collections import deque
import sys
input = sys.stdin.readline
def main():
N, M, P = list(map(int, input().split()))
edge = [[] for _ in range(N)]
redge = [[] for _ in range(N)]
for _ in range(M):
A, B, C = list(map(int, input().split()))
A -= 1
B -= 1
C -= P
C = -C
edge[A].append((B, C))
redge[B].append(A)
# 0 => N-1の間にある閉路を検出したいので
# 0とN-1からたどりつけない場所は前処理で取り除く
visited1, visited2 = {0}, {N - 1}
stack = [0]
while stack:
v = stack.pop()
for dest, _ in edge[v]:
if dest in visited1:
continue
visited1.add(dest)
stack.append(dest)
stack = [N - 1]
while stack:
v = stack.pop()
for dest in redge[v]:
if dest in visited2:
continue
visited2.add(dest)
stack.append(dest)
OK = visited1 & visited2
new_edge = [[] for _ in range(N)]
for s in range(N):
for t, c in edge[s]:
if t in OK:
new_edge[s].append((t, c))
flag = True
d = [float("inf")] * N
d[0] = 0
# ベルマンフォード法、N回実行してまだ更新されている場合は負の閉路が存在する
for _ in range(N):
flag = False
for v, e in enumerate(new_edge):
for t, c in e:
if d[v] != float("inf") and d[v] + c < d[t]:
d[t] = d[v] + c
flag = True
if not flag:
print((max(0, -d[N - 1])))
exit()
else:
print((-1))
exit()
if __name__ == "__main__":
main()
|
from collections import deque
import sys
input = sys.stdin.readline
def main():
N, M, P = list(map(int, input().split()))
edge = []
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(M):
A, B, C = list(map(int, input().split()))
A -= 1
B -= 1
C -= P
C = -C
edge.append((A, B, C))
g[A].append(B)
rg[B].append(A)
# 0 => N-1の間にある閉路を検出したいので
# 0とN-1からたどりつけない場所は前処理で取り除く
visited1 = set()
visited2 = set()
visited1.add(0)
visited2.add(N - 1)
Q = deque()
Q.append(0)
while Q:
v = Q.popleft()
for dest in g[v]:
if dest in visited1:
continue
visited1.add(dest)
Q.append(dest)
Q.append(N - 1)
while Q:
v = Q.popleft()
for dest in rg[v]:
if dest in visited2:
continue
visited2.add(dest)
Q.append(dest)
OK = visited1 & visited2
flag = True
d = [float("inf")] * N
d[0] = 0
# ベルマンフォード法、N回実行してまだ更新されている場合は負の閉路が存在する
for _ in range(N):
flag = False
for a, b, c in edge:
if not a in OK:
continue
if not b in OK:
continue
newD = d[a] + c
if newD < d[b]:
d[b] = newD
flag = True
if not flag:
print((max(0, -d[N - 1])))
exit()
else:
print((-1))
exit()
if __name__ == "__main__":
main()
| false
| 4.109589
|
[
"- edge = [[] for _ in range(N)]",
"- redge = [[] for _ in range(N)]",
"+ edge = []",
"+ g = [[] for _ in range(N)]",
"+ rg = [[] for _ in range(N)]",
"- edge[A].append((B, C))",
"- redge[B].append(A)",
"+ edge.append((A, B, C))",
"+ g[A].append(B)",
"+ rg[B].append(A)",
"- visited1, visited2 = {0}, {N - 1}",
"- stack = [0]",
"- while stack:",
"- v = stack.pop()",
"- for dest, _ in edge[v]:",
"+ visited1 = set()",
"+ visited2 = set()",
"+ visited1.add(0)",
"+ visited2.add(N - 1)",
"+ Q = deque()",
"+ Q.append(0)",
"+ while Q:",
"+ v = Q.popleft()",
"+ for dest in g[v]:",
"- stack.append(dest)",
"- stack = [N - 1]",
"- while stack:",
"- v = stack.pop()",
"- for dest in redge[v]:",
"+ Q.append(dest)",
"+ Q.append(N - 1)",
"+ while Q:",
"+ v = Q.popleft()",
"+ for dest in rg[v]:",
"- stack.append(dest)",
"+ Q.append(dest)",
"- new_edge = [[] for _ in range(N)]",
"- for s in range(N):",
"- for t, c in edge[s]:",
"- if t in OK:",
"- new_edge[s].append((t, c))",
"- for v, e in enumerate(new_edge):",
"- for t, c in e:",
"- if d[v] != float(\"inf\") and d[v] + c < d[t]:",
"- d[t] = d[v] + c",
"- flag = True",
"+ for a, b, c in edge:",
"+ if not a in OK:",
"+ continue",
"+ if not b in OK:",
"+ continue",
"+ newD = d[a] + c",
"+ if newD < d[b]:",
"+ d[b] = newD",
"+ flag = True"
] | false
| 0.081132
| 0.099846
| 0.812568
|
[
"s963096695",
"s873243156"
] |
u633068244
|
p01225
|
python
|
s787475387
|
s286757113
| 20
| 10
| 4,280
| 4,276
|
Accepted
|
Accepted
| 50
|
def rm_123(A):
if len(A) == 0: return 1
for a in set(A):
if set([a,a+1,a+2]) <= set(A):
if len(A) == 3: return 1
A1 = A[:]
for i in range(3): A1.remove(a+i)
return judge(A1)
def rm_111(A):
if len(A) == 0: return 1
for a in set(A):
if A.count(a) >= 3:
if len(A) == 3: return 1
A1 = A[:]
for i in range(3): A1.remove(a)
return judge(A1)
def judge(A):
return rm_123(A) or rm_111(A)
for _ in range(eval(input())):
n = list(map(int,input().split()))
R = []; G = []; B = []
s = input().split()
for i in range(len(n)):
if s[i] == "R": R.append(n[i])
elif s[i] == "G": G.append(n[i])
elif s[i] == "B": B.append(n[i])
print(1 if judge(R) and judge(G) and judge(B) else 0)
|
def rm_123(A):
if len(A) == 0: return 1
for a in set(A):
if set([a,a+1,a+2]) <= set(A):
A1 = A[:]
for i in range(3): A1.remove(a+i)
return judge(A1)
def rm_111(A):
if len(A) == 0: return 1
for a in set(A):
if A.count(a) >= 3:
A1 = A[:]
for i in range(3): A1.remove(a)
return judge(A1)
def judge(A):
return rm_123(A) or rm_111(A)
for _ in range(eval(input())):
n = list(map(int,input().split()))
R = []; G = []; B = []
s = input().split()
for i in range(len(n)):
if s[i] == "R": R.append(n[i])
elif s[i] == "G": G.append(n[i])
elif s[i] == "B": B.append(n[i])
print(1 if judge(R) and judge(G) and judge(B) else 0)
| 31
| 29
| 739
| 681
|
def rm_123(A):
if len(A) == 0:
return 1
for a in set(A):
if set([a, a + 1, a + 2]) <= set(A):
if len(A) == 3:
return 1
A1 = A[:]
for i in range(3):
A1.remove(a + i)
return judge(A1)
def rm_111(A):
if len(A) == 0:
return 1
for a in set(A):
if A.count(a) >= 3:
if len(A) == 3:
return 1
A1 = A[:]
for i in range(3):
A1.remove(a)
return judge(A1)
def judge(A):
return rm_123(A) or rm_111(A)
for _ in range(eval(input())):
n = list(map(int, input().split()))
R = []
G = []
B = []
s = input().split()
for i in range(len(n)):
if s[i] == "R":
R.append(n[i])
elif s[i] == "G":
G.append(n[i])
elif s[i] == "B":
B.append(n[i])
print(1 if judge(R) and judge(G) and judge(B) else 0)
|
def rm_123(A):
if len(A) == 0:
return 1
for a in set(A):
if set([a, a + 1, a + 2]) <= set(A):
A1 = A[:]
for i in range(3):
A1.remove(a + i)
return judge(A1)
def rm_111(A):
if len(A) == 0:
return 1
for a in set(A):
if A.count(a) >= 3:
A1 = A[:]
for i in range(3):
A1.remove(a)
return judge(A1)
def judge(A):
return rm_123(A) or rm_111(A)
for _ in range(eval(input())):
n = list(map(int, input().split()))
R = []
G = []
B = []
s = input().split()
for i in range(len(n)):
if s[i] == "R":
R.append(n[i])
elif s[i] == "G":
G.append(n[i])
elif s[i] == "B":
B.append(n[i])
print(1 if judge(R) and judge(G) and judge(B) else 0)
| false
| 6.451613
|
[
"- if len(A) == 3:",
"- return 1",
"- if len(A) == 3:",
"- return 1"
] | false
| 0.036398
| 0.042036
| 0.865881
|
[
"s787475387",
"s286757113"
] |
u347184682
|
p02947
|
python
|
s732045366
|
s024886464
| 461
| 288
| 44,800
| 28,048
|
Accepted
|
Accepted
| 37.53
|
n=int(eval(input()))
ans=0
s=[[x for x in eval(input())] for i in range(n)]
dic={}
for i in s:
temp=tuple(sorted(i))
if temp in dic:
ans+=dic[temp]
dic[temp]+=1
else:
dic[temp]=1
print(ans)
|
import collections
ans=0
dic={}
n=int(eval(input()))
for i in range(n):
s=eval(input())
sl=[i for i in s]
sl.sort()
ss=tuple(sl)
if ss not in dic:
dic[ss]=1
else:
ans+=dic[ss]
dic[ss]+=1
print(ans)
| 13
| 18
| 208
| 229
|
n = int(eval(input()))
ans = 0
s = [[x for x in eval(input())] for i in range(n)]
dic = {}
for i in s:
temp = tuple(sorted(i))
if temp in dic:
ans += dic[temp]
dic[temp] += 1
else:
dic[temp] = 1
print(ans)
|
import collections
ans = 0
dic = {}
n = int(eval(input()))
for i in range(n):
s = eval(input())
sl = [i for i in s]
sl.sort()
ss = tuple(sl)
if ss not in dic:
dic[ss] = 1
else:
ans += dic[ss]
dic[ss] += 1
print(ans)
| false
| 27.777778
|
[
"+import collections",
"+",
"+ans = 0",
"+dic = {}",
"-ans = 0",
"-s = [[x for x in eval(input())] for i in range(n)]",
"-dic = {}",
"-for i in s:",
"- temp = tuple(sorted(i))",
"- if temp in dic:",
"- ans += dic[temp]",
"- dic[temp] += 1",
"+for i in range(n):",
"+ s = eval(input())",
"+ sl = [i for i in s]",
"+ sl.sort()",
"+ ss = tuple(sl)",
"+ if ss not in dic:",
"+ dic[ss] = 1",
"- dic[temp] = 1",
"+ ans += dic[ss]",
"+ dic[ss] += 1"
] | false
| 0.07756
| 0.04317
| 1.796627
|
[
"s732045366",
"s024886464"
] |
u347640436
|
p03295
|
python
|
s479933886
|
s901028856
| 1,059
| 310
| 32,272
| 23,368
|
Accepted
|
Accepted
| 70.73
|
# Segment tree
class SegmentTree():
_data = []
_offset = 0
_size = 0
def __init__(self, size):
_size = size
t = 1
while t < size:
t *= 2
self._offset = t - 1
self._data = [0 for _ in range(t * 2 - 1)]
def update(self, index, value):
i = self._offset + index
self._data[i] = value
while i >= 1:
i = (i - 1) // 2
self._data[i] = self._data[i * 2 + 1] + self._data[i * 2 + 2]
def query(self, start, stop):
result = 0
l = start + self._offset
r = stop + self._offset
while l < r:
if l & 1 == 0:
result = result + self._data[l]
if r & 1 == 0:
result = result + self._data[r - 1]
l = l // 2
r = (r - 1) // 2
return result
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
st = SegmentTree(N - 1)
result = 0
for a, b in ab:
a, b = a - 1, b - 1
if st.query(a, b) != 0:
continue
result += 1
st.update(b - 1, 1)
print(result)
|
N, M = list(map(int, input().split()))
ab = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
ab[a].append(b)
dp = [0] * (N + 1)
for i in range(1, N + 1):
dp[i] = max(dp[i], dp[i - 1])
for j in ab[i]:
dp[j] = max(dp[j], dp[i] + 1)
print((dp[N]))
| 49
| 14
| 1,207
| 307
|
# Segment tree
class SegmentTree:
_data = []
_offset = 0
_size = 0
def __init__(self, size):
_size = size
t = 1
while t < size:
t *= 2
self._offset = t - 1
self._data = [0 for _ in range(t * 2 - 1)]
def update(self, index, value):
i = self._offset + index
self._data[i] = value
while i >= 1:
i = (i - 1) // 2
self._data[i] = self._data[i * 2 + 1] + self._data[i * 2 + 2]
def query(self, start, stop):
result = 0
l = start + self._offset
r = stop + self._offset
while l < r:
if l & 1 == 0:
result = result + self._data[l]
if r & 1 == 0:
result = result + self._data[r - 1]
l = l // 2
r = (r - 1) // 2
return result
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
st = SegmentTree(N - 1)
result = 0
for a, b in ab:
a, b = a - 1, b - 1
if st.query(a, b) != 0:
continue
result += 1
st.update(b - 1, 1)
print(result)
|
N, M = list(map(int, input().split()))
ab = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
ab[a].append(b)
dp = [0] * (N + 1)
for i in range(1, N + 1):
dp[i] = max(dp[i], dp[i - 1])
for j in ab[i]:
dp[j] = max(dp[j], dp[i] + 1)
print((dp[N]))
| false
| 71.428571
|
[
"-# Segment tree",
"-class SegmentTree:",
"- _data = []",
"- _offset = 0",
"- _size = 0",
"-",
"- def __init__(self, size):",
"- _size = size",
"- t = 1",
"- while t < size:",
"- t *= 2",
"- self._offset = t - 1",
"- self._data = [0 for _ in range(t * 2 - 1)]",
"-",
"- def update(self, index, value):",
"- i = self._offset + index",
"- self._data[i] = value",
"- while i >= 1:",
"- i = (i - 1) // 2",
"- self._data[i] = self._data[i * 2 + 1] + self._data[i * 2 + 2]",
"-",
"- def query(self, start, stop):",
"- result = 0",
"- l = start + self._offset",
"- r = stop + self._offset",
"- while l < r:",
"- if l & 1 == 0:",
"- result = result + self._data[l]",
"- if r & 1 == 0:",
"- result = result + self._data[r - 1]",
"- l = l // 2",
"- r = (r - 1) // 2",
"- return result",
"-",
"-",
"-ab = [list(map(int, input().split())) for _ in range(M)]",
"-ab.sort(key=lambda x: x[1])",
"-st = SegmentTree(N - 1)",
"-result = 0",
"-for a, b in ab:",
"- a, b = a - 1, b - 1",
"- if st.query(a, b) != 0:",
"- continue",
"- result += 1",
"- st.update(b - 1, 1)",
"-print(result)",
"+ab = [[] for _ in range(N + 1)]",
"+for _ in range(M):",
"+ a, b = list(map(int, input().split()))",
"+ ab[a].append(b)",
"+dp = [0] * (N + 1)",
"+for i in range(1, N + 1):",
"+ dp[i] = max(dp[i], dp[i - 1])",
"+ for j in ab[i]:",
"+ dp[j] = max(dp[j], dp[i] + 1)",
"+print((dp[N]))"
] | false
| 0.085413
| 0.119762
| 0.713188
|
[
"s479933886",
"s901028856"
] |
u182765930
|
p02909
|
python
|
s148687581
|
s751990326
| 20
| 17
| 2,940
| 2,940
|
Accepted
|
Accepted
| 15
|
l=["Sunny","Cloudy","Rainy"]
print((l[(l.index(eval(input()))+1)%3]))
|
l=["Rainy","Cloudy","Sunny"]
print((l[l.index(eval(input()))-1]))
| 2
| 2
| 63
| 58
|
l = ["Sunny", "Cloudy", "Rainy"]
print((l[(l.index(eval(input())) + 1) % 3]))
|
l = ["Rainy", "Cloudy", "Sunny"]
print((l[l.index(eval(input())) - 1]))
| false
| 0
|
[
"-l = [\"Sunny\", \"Cloudy\", \"Rainy\"]",
"-print((l[(l.index(eval(input())) + 1) % 3]))",
"+l = [\"Rainy\", \"Cloudy\", \"Sunny\"]",
"+print((l[l.index(eval(input())) - 1]))"
] | false
| 0.041914
| 0.040708
| 1.029623
|
[
"s148687581",
"s751990326"
] |
u743164083
|
p03106
|
python
|
s803555823
|
s496907768
| 28
| 25
| 8,968
| 8,992
|
Accepted
|
Accepted
| 10.71
|
def com_div(x, y):
dv = []
m = min(x, y)
for i in range(1, m + 1):
if x % i == 0 and y % i == 0:
dv.append(i)
dv.sort()
return dv[::-1]
a, b, k = list(map(int, input().split()))
print((com_div(a, b)[k - 1]))
|
def com_div(x, y):
dv = []
for i in range(min(x, y), 0, -1):
if x % i == 0 and y % i == 0:
dv.append(i)
return dv
a, b, k = list(map(int, input().split()))
print((com_div(a, b)[k - 1]))
| 12
| 10
| 258
| 227
|
def com_div(x, y):
dv = []
m = min(x, y)
for i in range(1, m + 1):
if x % i == 0 and y % i == 0:
dv.append(i)
dv.sort()
return dv[::-1]
a, b, k = list(map(int, input().split()))
print((com_div(a, b)[k - 1]))
|
def com_div(x, y):
dv = []
for i in range(min(x, y), 0, -1):
if x % i == 0 and y % i == 0:
dv.append(i)
return dv
a, b, k = list(map(int, input().split()))
print((com_div(a, b)[k - 1]))
| false
| 16.666667
|
[
"- m = min(x, y)",
"- for i in range(1, m + 1):",
"+ for i in range(min(x, y), 0, -1):",
"- dv.sort()",
"- return dv[::-1]",
"+ return dv"
] | false
| 0.047383
| 0.04742
| 0.999218
|
[
"s803555823",
"s496907768"
] |
u784022244
|
p02897
|
python
|
s930165673
|
s028661612
| 19
| 17
| 2,940
| 2,940
|
Accepted
|
Accepted
| 10.53
|
N=int(eval(input()))
if N%2==0:
print(((N/2)/N))
else:
print(((N//2+1)/N))
|
N=int(eval(input()))
if N%2==0:
print((0.5))
else:
print(((N//2+1)/N))
| 7
| 6
| 78
| 70
|
N = int(eval(input()))
if N % 2 == 0:
print(((N / 2) / N))
else:
print(((N // 2 + 1) / N))
|
N = int(eval(input()))
if N % 2 == 0:
print((0.5))
else:
print(((N // 2 + 1) / N))
| false
| 14.285714
|
[
"- print(((N / 2) / N))",
"+ print((0.5))"
] | false
| 0.042899
| 0.04592
| 0.934214
|
[
"s930165673",
"s028661612"
] |
u309977459
|
p03682
|
python
|
s845983461
|
s153301268
| 1,798
| 1,137
| 122,968
| 54,488
|
Accepted
|
Accepted
| 36.76
|
from operator import itemgetter
import heapq
N = int(eval(input()))
X = []
Y = []
for i in range(N):
x, y = list(map(int, input().split()))
X.append((x, i))
Y.append((y, i))
X.sort(key=itemgetter(0))
Y.sort(key=itemgetter(0))
G = [[] for _ in range(N)]
for i in range(N-1):
G[X[i][1]].append((X[i+1][0]-X[i][0], X[i+1][1]))
G[X[i+1][1]].append((X[i+1][0]-X[i][0], X[i][1]))
G[Y[i][1]].append((Y[i+1][0]-Y[i][0], Y[i+1][1]))
G[Y[i+1][1]].append((Y[i+1][0]-Y[i][0], Y[i][1]))
q = []
heapq.heapify(q)
for elem in G[0]:
heapq.heappush(q, elem)
used = [False] * N
used[0] = True
ans = 0
while q:
res = heapq.heappop(q)
cost, nq = res
if not used[nq]:
used[nq] = True
ans += cost
for elem in G[nq]:
heapq.heappush(q, elem)
print(ans)
|
from operator import itemgetter
import heapq
N = int(eval(input()))
X = []
Y = []
for i in range(N):
x, y = list(map(int, input().split()))
X.append((x, i))
Y.append((y, i))
X.sort(key=itemgetter(0))
Y.sort(key=itemgetter(0))
import sys
sys.setrecursionlimit(10**6)
class UnionFind(object):
def __init__(self, size):
self.table = [-1 for _ in range(size)]
def find(self, x):
if self.table[x] < 0:
return x
else:
self.table[x] = self.find(self.table[x])
return self.table[x]
def union(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
if self.table[s1] <= self.table[s2]:
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
return True
else:
return False
u = UnionFind(N)
q = []
for i in range(N-1):
q.append((X[i+1][0]-X[i][0], X[i+1][1], X[i][1]))
q.append((Y[i+1][0]-Y[i][0], Y[i+1][1], Y[i][1]))
q.sort(key=itemgetter(0))
ans = 0
for elem in q:
cost, a, b = elem
if u.union(a, b):
ans += cost
print(ans)
| 34
| 53
| 830
| 1,277
|
from operator import itemgetter
import heapq
N = int(eval(input()))
X = []
Y = []
for i in range(N):
x, y = list(map(int, input().split()))
X.append((x, i))
Y.append((y, i))
X.sort(key=itemgetter(0))
Y.sort(key=itemgetter(0))
G = [[] for _ in range(N)]
for i in range(N - 1):
G[X[i][1]].append((X[i + 1][0] - X[i][0], X[i + 1][1]))
G[X[i + 1][1]].append((X[i + 1][0] - X[i][0], X[i][1]))
G[Y[i][1]].append((Y[i + 1][0] - Y[i][0], Y[i + 1][1]))
G[Y[i + 1][1]].append((Y[i + 1][0] - Y[i][0], Y[i][1]))
q = []
heapq.heapify(q)
for elem in G[0]:
heapq.heappush(q, elem)
used = [False] * N
used[0] = True
ans = 0
while q:
res = heapq.heappop(q)
cost, nq = res
if not used[nq]:
used[nq] = True
ans += cost
for elem in G[nq]:
heapq.heappush(q, elem)
print(ans)
|
from operator import itemgetter
import heapq
N = int(eval(input()))
X = []
Y = []
for i in range(N):
x, y = list(map(int, input().split()))
X.append((x, i))
Y.append((y, i))
X.sort(key=itemgetter(0))
Y.sort(key=itemgetter(0))
import sys
sys.setrecursionlimit(10**6)
class UnionFind(object):
def __init__(self, size):
self.table = [-1 for _ in range(size)]
def find(self, x):
if self.table[x] < 0:
return x
else:
self.table[x] = self.find(self.table[x])
return self.table[x]
def union(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
if self.table[s1] <= self.table[s2]:
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
return True
else:
return False
u = UnionFind(N)
q = []
for i in range(N - 1):
q.append((X[i + 1][0] - X[i][0], X[i + 1][1], X[i][1]))
q.append((Y[i + 1][0] - Y[i][0], Y[i + 1][1], Y[i][1]))
q.sort(key=itemgetter(0))
ans = 0
for elem in q:
cost, a, b = elem
if u.union(a, b):
ans += cost
print(ans)
| false
| 35.849057
|
[
"-G = [[] for _ in range(N)]",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+",
"+",
"+class UnionFind(object):",
"+ def __init__(self, size):",
"+ self.table = [-1 for _ in range(size)]",
"+",
"+ def find(self, x):",
"+ if self.table[x] < 0:",
"+ return x",
"+ else:",
"+ self.table[x] = self.find(self.table[x])",
"+ return self.table[x]",
"+",
"+ def union(self, x, y):",
"+ s1 = self.find(x)",
"+ s2 = self.find(y)",
"+ if s1 != s2:",
"+ if self.table[s1] <= self.table[s2]:",
"+ self.table[s1] += self.table[s2]",
"+ self.table[s2] = s1",
"+ else:",
"+ self.table[s2] += self.table[s1]",
"+ self.table[s1] = s2",
"+ return True",
"+ else:",
"+ return False",
"+",
"+",
"+u = UnionFind(N)",
"+q = []",
"- G[X[i][1]].append((X[i + 1][0] - X[i][0], X[i + 1][1]))",
"- G[X[i + 1][1]].append((X[i + 1][0] - X[i][0], X[i][1]))",
"- G[Y[i][1]].append((Y[i + 1][0] - Y[i][0], Y[i + 1][1]))",
"- G[Y[i + 1][1]].append((Y[i + 1][0] - Y[i][0], Y[i][1]))",
"-q = []",
"-heapq.heapify(q)",
"-for elem in G[0]:",
"- heapq.heappush(q, elem)",
"-used = [False] * N",
"-used[0] = True",
"+ q.append((X[i + 1][0] - X[i][0], X[i + 1][1], X[i][1]))",
"+ q.append((Y[i + 1][0] - Y[i][0], Y[i + 1][1], Y[i][1]))",
"+q.sort(key=itemgetter(0))",
"-while q:",
"- res = heapq.heappop(q)",
"- cost, nq = res",
"- if not used[nq]:",
"- used[nq] = True",
"+for elem in q:",
"+ cost, a, b = elem",
"+ if u.union(a, b):",
"- for elem in G[nq]:",
"- heapq.heappush(q, elem)"
] | false
| 0.170722
| 0.088064
| 1.938624
|
[
"s845983461",
"s153301268"
] |
u606878291
|
p03208
|
python
|
s500959832
|
s148271409
| 233
| 214
| 11,628
| 8,280
|
Accepted
|
Accepted
| 8.15
|
N, K = list(map(int, input().split(' ')))
heights = sorted([int(eval(input())) for _ in range(N)])
print((min([_max - _min for _min, _max in zip(heights, heights[K - 1:])])))
|
N, K = list(map(int, input().split(' ')))
heights = sorted([int(eval(input())) for _ in range(N)])
print((min((_max - _min for _min, _max in zip(heights, heights[K - 1:])))))
| 3
| 3
| 163
| 163
|
N, K = list(map(int, input().split(" ")))
heights = sorted([int(eval(input())) for _ in range(N)])
print((min([_max - _min for _min, _max in zip(heights, heights[K - 1 :])])))
|
N, K = list(map(int, input().split(" ")))
heights = sorted([int(eval(input())) for _ in range(N)])
print((min((_max - _min for _min, _max in zip(heights, heights[K - 1 :])))))
| false
| 0
|
[
"-print((min([_max - _min for _min, _max in zip(heights, heights[K - 1 :])])))",
"+print((min((_max - _min for _min, _max in zip(heights, heights[K - 1 :])))))"
] | false
| 0.046896
| 0.040987
| 1.144174
|
[
"s500959832",
"s148271409"
] |
u333945892
|
p02845
|
python
|
s039444088
|
s283610645
| 97
| 76
| 15,412
| 15,164
|
Accepted
|
Accepted
| 21.65
|
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
N = inp()
AA = inpl()
cnts = [0]*(N+1)
cnts[-1] = 3
ans = 1
for a in AA:
ans *= (cnts[a-1] - cnts[a])
ans %= mod
cnts[a] += 1
print(ans)
|
c = [0]*(int(eval(input()))+1)
c[-1] = 3
ans = 1
for a in list(map(int, input().split())):
ans = (ans * (c[a-1] - c[a]))%(10**9+7)
c[a] += 1
print(ans)
| 25
| 7
| 524
| 160
|
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
N = inp()
AA = inpl()
cnts = [0] * (N + 1)
cnts[-1] = 3
ans = 1
for a in AA:
ans *= cnts[a - 1] - cnts[a]
ans %= mod
cnts[a] += 1
print(ans)
|
c = [0] * (int(eval(input())) + 1)
c[-1] = 3
ans = 1
for a in list(map(int, input().split())):
ans = (ans * (c[a - 1] - c[a])) % (10**9 + 7)
c[a] += 1
print(ans)
| false
| 72
|
[
"-from collections import defaultdict, deque",
"-import sys, heapq, bisect, math, itertools, string, queue, copy, time",
"-",
"-sys.setrecursionlimit(10**8)",
"-INF = float(\"inf\")",
"-mod = 10**9 + 7",
"-eps = 10**-7",
"-",
"-",
"-def inp():",
"- return int(sys.stdin.readline())",
"-",
"-",
"-def inpl():",
"- return list(map(int, sys.stdin.readline().split()))",
"-",
"-",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"-",
"-",
"-N = inp()",
"-AA = inpl()",
"-cnts = [0] * (N + 1)",
"-cnts[-1] = 3",
"+c = [0] * (int(eval(input())) + 1)",
"+c[-1] = 3",
"-for a in AA:",
"- ans *= cnts[a - 1] - cnts[a]",
"- ans %= mod",
"- cnts[a] += 1",
"+for a in list(map(int, input().split())):",
"+ ans = (ans * (c[a - 1] - c[a])) % (10**9 + 7)",
"+ c[a] += 1"
] | false
| 0.095322
| 0.120956
| 0.788072
|
[
"s039444088",
"s283610645"
] |
u509739538
|
p02708
|
python
|
s659151314
|
s719878584
| 162
| 140
| 9,648
| 9,188
|
Accepted
|
Accepted
| 13.58
|
import math
import queue
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChars():
return input().split()
x = readInts()
n = x[0]
k = x[1]
def ts(l):
return int((l*(l-1))/2)
def ts2(l):
return int(l*(n+n-(l-1))/2)
s = 0
for i in range(k,n+2):
s += ts2(i)+1-ts(i)
print((s%(1000000007)))
|
x=list(map(int,input().split()))
n,k=x
s=0
for i in range(k,n+2):
s+=int(i*(n+n-(i-1))/2)+1-int((i*(i-1))/2)
print((s%(1000000007)))
| 28
| 6
| 378
| 136
|
import math
import queue
def readInt():
return int(eval(input()))
def readInts():
return list(map(int, input().split()))
def readChars():
return input().split()
x = readInts()
n = x[0]
k = x[1]
def ts(l):
return int((l * (l - 1)) / 2)
def ts2(l):
return int(l * (n + n - (l - 1)) / 2)
s = 0
for i in range(k, n + 2):
s += ts2(i) + 1 - ts(i)
print((s % (1000000007)))
|
x = list(map(int, input().split()))
n, k = x
s = 0
for i in range(k, n + 2):
s += int(i * (n + n - (i - 1)) / 2) + 1 - int((i * (i - 1)) / 2)
print((s % (1000000007)))
| false
| 78.571429
|
[
"-import math",
"-import queue",
"-",
"-",
"-def readInt():",
"- return int(eval(input()))",
"-",
"-",
"-def readInts():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def readChars():",
"- return input().split()",
"-",
"-",
"-x = readInts()",
"-n = x[0]",
"-k = x[1]",
"-",
"-",
"-def ts(l):",
"- return int((l * (l - 1)) / 2)",
"-",
"-",
"-def ts2(l):",
"- return int(l * (n + n - (l - 1)) / 2)",
"-",
"-",
"+x = list(map(int, input().split()))",
"+n, k = x",
"- s += ts2(i) + 1 - ts(i)",
"+ s += int(i * (n + n - (i - 1)) / 2) + 1 - int((i * (i - 1)) / 2)"
] | false
| 0.071888
| 0.062141
| 1.156843
|
[
"s659151314",
"s719878584"
] |
u761529120
|
p03286
|
python
|
s895046572
|
s508938357
| 165
| 64
| 38,256
| 61,864
|
Accepted
|
Accepted
| 61.21
|
def main():
N = int(eval(input()))
ans = ''
while N != 0:
if N % 2 != 0:
N -= 1
ans = '1' + ans
else:
ans = "0" + ans
N = N // (-2)
if ans == "":
ans = "0"
print(ans)
main()
|
def main():
N = int(eval(input()))
if N == 0:
print((0))
ans = ''
base = 1
while N != 0:
if N % (base * -2) == 0:
ans += '0'
else:
ans += "1"
N -= base
base *= -2
ans = list(ans)
ans.reverse()
print((''.join(ans)))
if __name__ == "__main__":
main()
| 19
| 19
| 294
| 361
|
def main():
N = int(eval(input()))
ans = ""
while N != 0:
if N % 2 != 0:
N -= 1
ans = "1" + ans
else:
ans = "0" + ans
N = N // (-2)
if ans == "":
ans = "0"
print(ans)
main()
|
def main():
N = int(eval(input()))
if N == 0:
print((0))
ans = ""
base = 1
while N != 0:
if N % (base * -2) == 0:
ans += "0"
else:
ans += "1"
N -= base
base *= -2
ans = list(ans)
ans.reverse()
print(("".join(ans)))
if __name__ == "__main__":
main()
| false
| 0
|
[
"+ if N == 0:",
"+ print((0))",
"+ base = 1",
"- if N % 2 != 0:",
"- N -= 1",
"- ans = \"1\" + ans",
"+ if N % (base * -2) == 0:",
"+ ans += \"0\"",
"- ans = \"0\" + ans",
"- N = N // (-2)",
"- if ans == \"\":",
"- ans = \"0\"",
"- print(ans)",
"+ ans += \"1\"",
"+ N -= base",
"+ base *= -2",
"+ ans = list(ans)",
"+ ans.reverse()",
"+ print((\"\".join(ans)))",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.058838
| 0.037227
| 1.580516
|
[
"s895046572",
"s508938357"
] |
u072717685
|
p02819
|
python
|
s557886135
|
s066756729
| 98
| 71
| 86,600
| 62,744
|
Accepted
|
Accepted
| 27.55
|
from bisect import bisect
def main():
maxa2 = 200000
maxa2 = max(6, maxa2) # maxa2が6未満だとエラーになる
p = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)]
p[0] = p[1] = False
p[2] = p[3] = p[5] = True
for is1 in range(3, maxa2, 2):
for is2 in range(is1 ** 2, maxa2, is1):
p[is2] = False
prime_list = [i for i, b in enumerate(p) if b]
x = int(eval(input()))
if x in prime_list:
print(x)
else:
xp = bisect(prime_list, x)
r = prime_list[xp]
print(r)
if __name__ == '__main__':
main()
|
from math import sqrt, ceil
def main():
x = int(eval(input()))
while True:
for i1 in range(2, ceil(sqrt(x))):
if x % i1 == 0:
x += 1
break
else:
break
print(x)
if __name__ == '__main__':
main()
| 22
| 14
| 620
| 290
|
from bisect import bisect
def main():
maxa2 = 200000
maxa2 = max(6, maxa2) # maxa2が6未満だとエラーになる
p = [
False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)
]
p[0] = p[1] = False
p[2] = p[3] = p[5] = True
for is1 in range(3, maxa2, 2):
for is2 in range(is1**2, maxa2, is1):
p[is2] = False
prime_list = [i for i, b in enumerate(p) if b]
x = int(eval(input()))
if x in prime_list:
print(x)
else:
xp = bisect(prime_list, x)
r = prime_list[xp]
print(r)
if __name__ == "__main__":
main()
|
from math import sqrt, ceil
def main():
x = int(eval(input()))
while True:
for i1 in range(2, ceil(sqrt(x))):
if x % i1 == 0:
x += 1
break
else:
break
print(x)
if __name__ == "__main__":
main()
| false
| 36.363636
|
[
"-from bisect import bisect",
"+from math import sqrt, ceil",
"- maxa2 = 200000",
"- maxa2 = max(6, maxa2) # maxa2が6未満だとエラーになる",
"- p = [",
"- False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(maxa2)",
"- ]",
"- p[0] = p[1] = False",
"- p[2] = p[3] = p[5] = True",
"- for is1 in range(3, maxa2, 2):",
"- for is2 in range(is1**2, maxa2, is1):",
"- p[is2] = False",
"- prime_list = [i for i, b in enumerate(p) if b]",
"- if x in prime_list:",
"- print(x)",
"- else:",
"- xp = bisect(prime_list, x)",
"- r = prime_list[xp]",
"- print(r)",
"+ while True:",
"+ for i1 in range(2, ceil(sqrt(x))):",
"+ if x % i1 == 0:",
"+ x += 1",
"+ break",
"+ else:",
"+ break",
"+ print(x)"
] | false
| 0.651809
| 0.039674
| 16.429013
|
[
"s557886135",
"s066756729"
] |
u326609687
|
p03108
|
python
|
s596927420
|
s824053492
| 598
| 423
| 23,252
| 23,224
|
Accepted
|
Accepted
| 29.26
|
N, M = list(map(int, input().split()))
ab = [tuple([int(x)-1 for x in input().split()]) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1 for _ in range(size)]
self.number = [1 for _ in range(size)]
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
def main():
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in reversed(ab[1:]):
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
for a in reversed(ans):
print(a)
main()
|
import sys
N, M = list(map(int, input().split()))
ab = [tuple([int(x)-1 for x in sys.stdin.readline().split()]) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1 for _ in range(size)]
self.number = [1 for _ in range(size)]
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
def main():
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in reversed(ab[1:]):
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
for a in reversed(ans):
print(a)
main()
| 46
| 48
| 1,161
| 1,188
|
N, M = list(map(int, input().split()))
ab = [tuple([int(x) - 1 for x in input().split()]) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1 for _ in range(size)]
self.number = [1 for _ in range(size)]
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
def main():
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in reversed(ab[1:]):
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
for a in reversed(ans):
print(a)
main()
|
import sys
N, M = list(map(int, input().split()))
ab = [tuple([int(x) - 1 for x in sys.stdin.readline().split()]) for _ in range(M)]
class UnionFind:
def __init__(self, size):
self.rank = [-1 for _ in range(size)]
self.number = [1 for _ in range(size)]
def find(self, x):
while self.rank[x] >= 0:
x = self.rank[x]
return x
def union(self, s1, s2):
if s1 == s2:
return
if self.rank[s1] == self.rank[s2]:
self.rank[s1] -= 1
self.rank[s2] = s1
self.number[s1] += self.number[s2]
elif self.rank[s1] < self.rank[s2]:
self.rank[s2] = s1
self.number[s1] += self.number[s2]
else:
self.rank[s1] = s2
self.number[s2] += self.number[s1]
def main():
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for x, y in reversed(ab[1:]):
px = uf.find(x)
py = uf.find(y)
if px != py:
p -= uf.number[px] * uf.number[py]
uf.union(px, py)
ans.append(p)
for a in reversed(ans):
print(a)
main()
| false
| 4.166667
|
[
"+import sys",
"+",
"-ab = [tuple([int(x) - 1 for x in input().split()]) for _ in range(M)]",
"+ab = [tuple([int(x) - 1 for x in sys.stdin.readline().split()]) for _ in range(M)]"
] | false
| 0.079896
| 0.03372
| 2.369378
|
[
"s596927420",
"s824053492"
] |
u532966492
|
p03766
|
python
|
s241458769
|
s374508116
| 742
| 490
| 2,940
| 10,740
|
Accepted
|
Accepted
| 33.96
|
n=int(eval(input()));a,b,c,p=1,1,n,n-1
for i in range(n-1):
p+=a-1;a,b,c=b,c,((n-1)**2+p+c)%(10**9+7)
print(c)
|
n=int(eval(input()))-1;a,b,c,p=1,1,n+1,n
for _ in[0]*n:p+=a-1;a,b,c=b,c,(n*n+p+c)%(10**9+7)
print(c)
| 4
| 3
| 108
| 96
|
n = int(eval(input()))
a, b, c, p = 1, 1, n, n - 1
for i in range(n - 1):
p += a - 1
a, b, c = b, c, ((n - 1) ** 2 + p + c) % (10**9 + 7)
print(c)
|
n = int(eval(input())) - 1
a, b, c, p = 1, 1, n + 1, n
for _ in [0] * n:
p += a - 1
a, b, c = b, c, (n * n + p + c) % (10**9 + 7)
print(c)
| false
| 25
|
[
"-n = int(eval(input()))",
"-a, b, c, p = 1, 1, n, n - 1",
"-for i in range(n - 1):",
"+n = int(eval(input())) - 1",
"+a, b, c, p = 1, 1, n + 1, n",
"+for _ in [0] * n:",
"- a, b, c = b, c, ((n - 1) ** 2 + p + c) % (10**9 + 7)",
"+ a, b, c = b, c, (n * n + p + c) % (10**9 + 7)"
] | false
| 0.182729
| 0.139388
| 1.310933
|
[
"s241458769",
"s374508116"
] |
u711693740
|
p02733
|
python
|
s312762237
|
s383524023
| 417
| 360
| 3,188
| 3,188
|
Accepted
|
Accepted
| 13.67
|
from itertools import product
H, W, K = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
S_T = [[int(s[w]) for s in S] for w in range(W)]
sumS = sum(map(sum, S_T))
ans = (H - 1) * (W - 1)
if sumS <= K:
print((0))
else:
for i in product([True, False], repeat=H-1):
cnt = sum(i)
if cnt >= ans:
continue
M = [[0]]
for j, k in enumerate(i):
if k:
M.append([])
M[-1].append(j+1)
A = [0] * len(M)
for s_t in S_T:
for l, m in enumerate(M):
A[l] += sum(s_t[i] for i in m)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(s_t[i] for i in m) for m in M]
if any(a > K for a in A):
cnt = ans + 1
break
ans = min(cnt, ans)
print(ans)
|
def main():
from itertools import product
H, W, K = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
S_T = [[int(s[w]) for s in S] for w in range(W)]
sumS = sum(map(sum, S_T))
ans = (H - 1) * (W - 1)
if sumS <= K:
print((0))
else:
for i in product([True, False], repeat=H-1):
cnt = sum(i)
if cnt >= ans:
continue
M = [[0]]
for j, k in enumerate(i):
if k:
M.append([])
M[-1].append(j+1)
A = [0] * len(M)
for s_t in S_T:
for l, m in enumerate(M):
A[l] += sum(s_t[i] for i in m)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(s_t[i] for i in m) for m in M]
if any(a > K for a in A):
cnt = ans + 1
break
ans = min(cnt, ans)
print(ans)
if __name__ == '__main__':
main()
| 34
| 38
| 963
| 1,145
|
from itertools import product
H, W, K = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
S_T = [[int(s[w]) for s in S] for w in range(W)]
sumS = sum(map(sum, S_T))
ans = (H - 1) * (W - 1)
if sumS <= K:
print((0))
else:
for i in product([True, False], repeat=H - 1):
cnt = sum(i)
if cnt >= ans:
continue
M = [[0]]
for j, k in enumerate(i):
if k:
M.append([])
M[-1].append(j + 1)
A = [0] * len(M)
for s_t in S_T:
for l, m in enumerate(M):
A[l] += sum(s_t[i] for i in m)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(s_t[i] for i in m) for m in M]
if any(a > K for a in A):
cnt = ans + 1
break
ans = min(cnt, ans)
print(ans)
|
def main():
from itertools import product
H, W, K = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
S_T = [[int(s[w]) for s in S] for w in range(W)]
sumS = sum(map(sum, S_T))
ans = (H - 1) * (W - 1)
if sumS <= K:
print((0))
else:
for i in product([True, False], repeat=H - 1):
cnt = sum(i)
if cnt >= ans:
continue
M = [[0]]
for j, k in enumerate(i):
if k:
M.append([])
M[-1].append(j + 1)
A = [0] * len(M)
for s_t in S_T:
for l, m in enumerate(M):
A[l] += sum(s_t[i] for i in m)
if any(a > K for a in A):
cnt += 1
if cnt >= ans:
break
A = [sum(s_t[i] for i in m) for m in M]
if any(a > K for a in A):
cnt = ans + 1
break
ans = min(cnt, ans)
print(ans)
if __name__ == "__main__":
main()
| false
| 10.526316
|
[
"-from itertools import product",
"+def main():",
"+ from itertools import product",
"-H, W, K = list(map(int, input().split()))",
"-S = [eval(input()) for _ in range(H)]",
"-S_T = [[int(s[w]) for s in S] for w in range(W)]",
"-sumS = sum(map(sum, S_T))",
"-ans = (H - 1) * (W - 1)",
"-if sumS <= K:",
"- print((0))",
"-else:",
"- for i in product([True, False], repeat=H - 1):",
"- cnt = sum(i)",
"- if cnt >= ans:",
"- continue",
"- M = [[0]]",
"- for j, k in enumerate(i):",
"- if k:",
"- M.append([])",
"- M[-1].append(j + 1)",
"- A = [0] * len(M)",
"- for s_t in S_T:",
"- for l, m in enumerate(M):",
"- A[l] += sum(s_t[i] for i in m)",
"- if any(a > K for a in A):",
"- cnt += 1",
"- if cnt >= ans:",
"- break",
"- A = [sum(s_t[i] for i in m) for m in M]",
"+ H, W, K = list(map(int, input().split()))",
"+ S = [eval(input()) for _ in range(H)]",
"+ S_T = [[int(s[w]) for s in S] for w in range(W)]",
"+ sumS = sum(map(sum, S_T))",
"+ ans = (H - 1) * (W - 1)",
"+ if sumS <= K:",
"+ print((0))",
"+ else:",
"+ for i in product([True, False], repeat=H - 1):",
"+ cnt = sum(i)",
"+ if cnt >= ans:",
"+ continue",
"+ M = [[0]]",
"+ for j, k in enumerate(i):",
"+ if k:",
"+ M.append([])",
"+ M[-1].append(j + 1)",
"+ A = [0] * len(M)",
"+ for s_t in S_T:",
"+ for l, m in enumerate(M):",
"+ A[l] += sum(s_t[i] for i in m)",
"- cnt = ans + 1",
"- break",
"- ans = min(cnt, ans)",
"- print(ans)",
"+ cnt += 1",
"+ if cnt >= ans:",
"+ break",
"+ A = [sum(s_t[i] for i in m) for m in M]",
"+ if any(a > K for a in A):",
"+ cnt = ans + 1",
"+ break",
"+ ans = min(cnt, ans)",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false
| 0.074642
| 0.034568
| 2.159309
|
[
"s312762237",
"s383524023"
] |
u957872856
|
p03273
|
python
|
s697756143
|
s532660600
| 30
| 18
| 4,468
| 3,188
|
Accepted
|
Accepted
| 40
|
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
a[i] = input()
row = [False] * h
col = [False] * w
for i in range(h):
for j in range(w):
if a[i][j] == '#':
row[i] = True
col[j] = True
for i in range(h):
if row[i]:
for j in range(w):
if col[j]:
print(a[i][j], end = '')
print()
|
h,w = list(map(int,input().split()))
a = [[j for j in eval(input())] for i in range(h)]
b = [x for x in a if "#" in x]
c = list(zip(*[y for y in zip(*b) if "#" in y]))
for d in c:
print(("".join(d)))
| 17
| 6
| 331
| 186
|
h, w = map(int, input().split())
a = [""] * h
for i in range(h):
a[i] = input()
row = [False] * h
col = [False] * w
for i in range(h):
for j in range(w):
if a[i][j] == "#":
row[i] = True
col[j] = True
for i in range(h):
if row[i]:
for j in range(w):
if col[j]:
print(a[i][j], end="")
print()
|
h, w = list(map(int, input().split()))
a = [[j for j in eval(input())] for i in range(h)]
b = [x for x in a if "#" in x]
c = list(zip(*[y for y in zip(*b) if "#" in y]))
for d in c:
print(("".join(d)))
| false
| 64.705882
|
[
"-h, w = map(int, input().split())",
"-a = [\"\"] * h",
"-for i in range(h):",
"- a[i] = input()",
"-row = [False] * h",
"-col = [False] * w",
"-for i in range(h):",
"- for j in range(w):",
"- if a[i][j] == \"#\":",
"- row[i] = True",
"- col[j] = True",
"-for i in range(h):",
"- if row[i]:",
"- for j in range(w):",
"- if col[j]:",
"- print(a[i][j], end=\"\")",
"- print()",
"+h, w = list(map(int, input().split()))",
"+a = [[j for j in eval(input())] for i in range(h)]",
"+b = [x for x in a if \"#\" in x]",
"+c = list(zip(*[y for y in zip(*b) if \"#\" in y]))",
"+for d in c:",
"+ print((\"\".join(d)))"
] | false
| 0.046484
| 0.046372
| 1.002416
|
[
"s697756143",
"s532660600"
] |
u571281863
|
p02660
|
python
|
s704216152
|
s529504381
| 201
| 82
| 9,276
| 9,292
|
Accepted
|
Accepted
| 59.2
|
N=int(eval(input()))
p=[]
r=0
if N%2==0:
c=0
while N%2==0:
c+=1
N/=2
p.append([c])
i=3
while i<N**0.5+1:
if N%i==0:
c=0
while N%i==0:
c+=1
N/=i
p.append([c])
i+=2
if N!=1:
p.append([1])
for i in range(len(p)):
j=1
while p[i][0]>=j:
p[i][0]-=j
j+=1
r+=1
print(r)
|
N=int(eval(input()))
p=[]
r=0
if N%2==0:
c=0
while N%2==0:
c+=1
N/=2
p.append(c)
for i in range(3,int(N**0.5)+1,2):
if N%i==0:
c=0
while N%i==0:
c+=1
N/=i
p.append(c)
if N!=1:
p.append(1)
for i in p:
r+=int(((8*i+1)**0.5-1)/2)
print(r)
| 32
| 25
| 361
| 307
|
N = int(eval(input()))
p = []
r = 0
if N % 2 == 0:
c = 0
while N % 2 == 0:
c += 1
N /= 2
p.append([c])
i = 3
while i < N**0.5 + 1:
if N % i == 0:
c = 0
while N % i == 0:
c += 1
N /= i
p.append([c])
i += 2
if N != 1:
p.append([1])
for i in range(len(p)):
j = 1
while p[i][0] >= j:
p[i][0] -= j
j += 1
r += 1
print(r)
|
N = int(eval(input()))
p = []
r = 0
if N % 2 == 0:
c = 0
while N % 2 == 0:
c += 1
N /= 2
p.append(c)
for i in range(3, int(N**0.5) + 1, 2):
if N % i == 0:
c = 0
while N % i == 0:
c += 1
N /= i
p.append(c)
if N != 1:
p.append(1)
for i in p:
r += int(((8 * i + 1) ** 0.5 - 1) / 2)
print(r)
| false
| 21.875
|
[
"- p.append([c])",
"-i = 3",
"-while i < N**0.5 + 1:",
"+ p.append(c)",
"+for i in range(3, int(N**0.5) + 1, 2):",
"- p.append([c])",
"- i += 2",
"+ p.append(c)",
"- p.append([1])",
"-for i in range(len(p)):",
"- j = 1",
"- while p[i][0] >= j:",
"- p[i][0] -= j",
"- j += 1",
"- r += 1",
"+ p.append(1)",
"+for i in p:",
"+ r += int(((8 * i + 1) ** 0.5 - 1) / 2)"
] | false
| 0.037475
| 0.04208
| 0.89058
|
[
"s704216152",
"s529504381"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.