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
u764956288
p02691
python
s372862352
s494148715
188
114
36,612
32,224
Accepted
Accepted
39.36
from collections import defaultdict def main(): N = int(eval(input())) heights = list(map(int, input().split())) """ for j>i, j-i = Ai + Aj i + Ai = j -Aj """ L = defaultdict(int) R = defaultdict(int) for i, height in enumerate(heights): if i + height < N: L[i + height] += 1 if i - height > 0: R[i - height] += 1 total_count = 0 for x, count_l in list(L.items()): if x in R: count_r = R[x] total_count += count_l * count_r print(total_count) if __name__ == "__main__": main()
def main(): N = int(eval(input())) heights = list(map(int, input().split())) """ for j>i, j-i = Ai + Aj i + Ai = j -Aj """ L = [0] * N R = [0] * N count = 0 for i, height in enumerate(heights): right = i + height left = i - height if right < N: R[right] += 1 if left > 0: L[left] += 1 count += R[left] print(count) if __name__ == "__main__": main()
33
29
639
495
from collections import defaultdict def main(): N = int(eval(input())) heights = list(map(int, input().split())) """ for j>i, j-i = Ai + Aj i + Ai = j -Aj """ L = defaultdict(int) R = defaultdict(int) for i, height in enumerate(heights): if i + height < N: L[i + height] += 1 if i - height > 0: R[i - height] += 1 total_count = 0 for x, count_l in list(L.items()): if x in R: count_r = R[x] total_count += count_l * count_r print(total_count) if __name__ == "__main__": main()
def main(): N = int(eval(input())) heights = list(map(int, input().split())) """ for j>i, j-i = Ai + Aj i + Ai = j -Aj """ L = [0] * N R = [0] * N count = 0 for i, height in enumerate(heights): right = i + height left = i - height if right < N: R[right] += 1 if left > 0: L[left] += 1 count += R[left] print(count) if __name__ == "__main__": main()
false
12.121212
[ "-from collections import defaultdict", "-", "-", "- L = defaultdict(int)", "- R = defaultdict(int)", "+ L = [0] * N", "+ R = [0] * N", "+ count = 0", "- if i + height < N:", "- L[i + height] += 1", "- if i - height > 0:", "- R[i - height] += 1", "- total_count = 0", "- for x, count_l in list(L.items()):", "- if x in R:", "- count_r = R[x]", "- total_count += count_l * count_r", "- print(total_count)", "+ right = i + height", "+ left = i - height", "+ if right < N:", "+ R[right] += 1", "+ if left > 0:", "+ L[left] += 1", "+ count += R[left]", "+ print(count)" ]
false
0.044666
0.044356
1.006996
[ "s372862352", "s494148715" ]
u057109575
p02792
python
s436195247
s651163983
233
72
40,460
64,488
Accepted
Accepted
69.1
N = int(eval(input())) cnt = [[0] * 10 for _ in range(10)] for i in range(1, N + 1): cnt[int(str(i)[0])][int(str(i)[-1])] += 1 ans = 0 for i in range(10): for j in range(10): ans += cnt[i][j] * cnt[j][i] print(ans)
N = int(eval(input())) dp = [[0] * 10 for _ in range(10)] for x in range(1, N + 1): j = x % 10 while x >= 10: x //= 10 i = x % 10 dp[i][j] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += dp[i][j] * dp[j][i] print(ans)
11
16
245
296
N = int(eval(input())) cnt = [[0] * 10 for _ in range(10)] for i in range(1, N + 1): cnt[int(str(i)[0])][int(str(i)[-1])] += 1 ans = 0 for i in range(10): for j in range(10): ans += cnt[i][j] * cnt[j][i] print(ans)
N = int(eval(input())) dp = [[0] * 10 for _ in range(10)] for x in range(1, N + 1): j = x % 10 while x >= 10: x //= 10 i = x % 10 dp[i][j] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += dp[i][j] * dp[j][i] print(ans)
false
31.25
[ "-cnt = [[0] * 10 for _ in range(10)]", "-for i in range(1, N + 1):", "- cnt[int(str(i)[0])][int(str(i)[-1])] += 1", "+dp = [[0] * 10 for _ in range(10)]", "+for x in range(1, N + 1):", "+ j = x % 10", "+ while x >= 10:", "+ x //= 10", "+ i = x % 10", "+ dp[i][j] += 1", "-for i in range(10):", "- for j in range(10):", "- ans += cnt[i][j] * cnt[j][i]", "+for i in range(1, 10):", "+ for j in range(1, 10):", "+ ans += dp[i][j] * dp[j][i]" ]
false
0.134736
0.076284
1.766233
[ "s436195247", "s651163983" ]
u312025627
p03136
python
s073029191
s907714383
169
59
38,384
61,828
Accepted
Accepted
65.09
def main(): N = int(eval(input())) L = [int(i) for i in input().split()] sumL = sum(L) maxL = max(L) print(("Yes" if maxL < sumL - maxL else "No")) if __name__ == '__main__': main()
def main(): N = int(eval(input())) L = [int(i) for i in input().split()] maxL = max(L) sumL = sum(L) - maxL if maxL < sumL: print("Yes") else: print("No") if __name__ == '__main__': main()
10
13
209
241
def main(): N = int(eval(input())) L = [int(i) for i in input().split()] sumL = sum(L) maxL = max(L) print(("Yes" if maxL < sumL - maxL else "No")) if __name__ == "__main__": main()
def main(): N = int(eval(input())) L = [int(i) for i in input().split()] maxL = max(L) sumL = sum(L) - maxL if maxL < sumL: print("Yes") else: print("No") if __name__ == "__main__": main()
false
23.076923
[ "- sumL = sum(L)", "- print((\"Yes\" if maxL < sumL - maxL else \"No\"))", "+ sumL = sum(L) - maxL", "+ if maxL < sumL:", "+ print(\"Yes\")", "+ else:", "+ print(\"No\")" ]
false
0.047703
0.035964
1.326422
[ "s073029191", "s907714383" ]
u972658925
p02848
python
s663990116
s723335007
36
28
3,064
3,064
Accepted
Accepted
22.22
N = int(eval(input())) S = list(eval(input())) lst = [chr(ord('a') + i) for i in range(26)] lst_up = list(map(str.upper,lst)) for i in range(len(S)): if int(lst_up.index(S[i])+N+1) <= len(lst_up): S[i] = lst_up[lst_up.index(S[i])+N] elif int(lst_up.index(S[i])+N+1) > len(lst_up): S[i] = lst_up[lst_up.index(S[i])+N-26] lst_2 = "".join(S) print(lst_2)
n = int(eval(input())) s = list(eval(input())) lst_26 = [(chr(ord("a") + i)).upper() for i in range(26)] for i in range(len(s)): if lst_26.index(s[i])+n >= 26: s[i] = lst_26[lst_26.index(s[i])+n-26] else: s[i] = lst_26[lst_26.index(s[i])+n] print(("".join(s)))
14
10
380
280
N = int(eval(input())) S = list(eval(input())) lst = [chr(ord("a") + i) for i in range(26)] lst_up = list(map(str.upper, lst)) for i in range(len(S)): if int(lst_up.index(S[i]) + N + 1) <= len(lst_up): S[i] = lst_up[lst_up.index(S[i]) + N] elif int(lst_up.index(S[i]) + N + 1) > len(lst_up): S[i] = lst_up[lst_up.index(S[i]) + N - 26] lst_2 = "".join(S) print(lst_2)
n = int(eval(input())) s = list(eval(input())) lst_26 = [(chr(ord("a") + i)).upper() for i in range(26)] for i in range(len(s)): if lst_26.index(s[i]) + n >= 26: s[i] = lst_26[lst_26.index(s[i]) + n - 26] else: s[i] = lst_26[lst_26.index(s[i]) + n] print(("".join(s)))
false
28.571429
[ "-N = int(eval(input()))", "-S = list(eval(input()))", "-lst = [chr(ord(\"a\") + i) for i in range(26)]", "-lst_up = list(map(str.upper, lst))", "-for i in range(len(S)):", "- if int(lst_up.index(S[i]) + N + 1) <= len(lst_up):", "- S[i] = lst_up[lst_up.index(S[i]) + N]", "- elif int(lst_up.index(S[i]) + N + 1) > len(lst_up):", "- S[i] = lst_up[lst_up.index(S[i]) + N - 26]", "-lst_2 = \"\".join(S)", "-print(lst_2)", "+n = int(eval(input()))", "+s = list(eval(input()))", "+lst_26 = [(chr(ord(\"a\") + i)).upper() for i in range(26)]", "+for i in range(len(s)):", "+ if lst_26.index(s[i]) + n >= 26:", "+ s[i] = lst_26[lst_26.index(s[i]) + n - 26]", "+ else:", "+ s[i] = lst_26[lst_26.index(s[i]) + n]", "+print((\"\".join(s)))" ]
false
0.127501
0.039423
3.234166
[ "s663990116", "s723335007" ]
u350248178
p03775
python
s814785306
s650628110
185
27
39,792
3,064
Accepted
Accepted
85.41
n=int(eval(input())) def f(a,b): a=str(a) b=str(b) return(max(len(a),len(b))) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors l=make_divisors(n) ans=10**9+7 for i in l: ans=min(ans,f(i,n//i)) print(ans)
n=int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors l=make_divisors(n) m=len(l) ans=10**100 for i in range(min(m//2+1,m)): a,b=len(str(l[i])),len(str(n//l[i])) ans=min(ans,max(a,b)) print(ans)
23
19
429
422
n = int(eval(input())) def f(a, b): a = str(a) b = str(b) return max(len(a), len(b)) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors l = make_divisors(n) ans = 10**9 + 7 for i in l: ans = min(ans, f(i, n // i)) print(ans)
n = int(eval(input())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors l = make_divisors(n) m = len(l) ans = 10**100 for i in range(min(m // 2 + 1, m)): a, b = len(str(l[i])), len(str(n // l[i])) ans = min(ans, max(a, b)) print(ans)
false
17.391304
[ "-", "-", "-def f(a, b):", "- a = str(a)", "- b = str(b)", "- return max(len(a), len(b))", "-ans = 10**9 + 7", "-for i in l:", "- ans = min(ans, f(i, n // i))", "+m = len(l)", "+ans = 10**100", "+for i in range(min(m // 2 + 1, m)):", "+ a, b = len(str(l[i])), len(str(n // l[i]))", "+ ans = min(ans, max(a, b))" ]
false
0.041296
0.052303
0.789551
[ "s814785306", "s650628110" ]
u721407235
p02837
python
s162228089
s163142864
411
163
3,064
8,820
Accepted
Accepted
60.34
N=int(eval(input())) A=[] arr=[] ans=0 for n in range(N): a=int(eval(input())) A.append(a) arr.append([ list(map(int,input().split())) for _ in range(a)]) for i in range(2**N): ord =[0]*N count=0 flg=0 for n in range(N): if (i >>n)&1: count +=1 ord[n]=1 for n in range(N): if ord[n]==1: for m in range(A[n]): if ord[arr[n][m][0]-1]!= arr[n][m][1]: flg=1 break if flg==1: continue ans=max(ans,count) print(ans)
import itertools N=int(eval(input())) A=[] arr=[] ans=0 li=list(itertools.product([0,1], repeat=N)) for n in range(N): a=int(eval(input())) A.append(a) arr.append([ list(map(int,input().split())) for _ in range(a)]) for l in li: flg=0 for n in range(N): if l[n]==1: for m in range(A[n]): if l[arr[n][m][0]-1]!=arr[n][m][1]: flg=1 break if flg==1: break if flg==1: continue count=l.count(1) ans=max(ans,count) print(ans)
36
31
569
545
N = int(eval(input())) A = [] arr = [] ans = 0 for n in range(N): a = int(eval(input())) A.append(a) arr.append([list(map(int, input().split())) for _ in range(a)]) for i in range(2**N): ord = [0] * N count = 0 flg = 0 for n in range(N): if (i >> n) & 1: count += 1 ord[n] = 1 for n in range(N): if ord[n] == 1: for m in range(A[n]): if ord[arr[n][m][0] - 1] != arr[n][m][1]: flg = 1 break if flg == 1: continue ans = max(ans, count) print(ans)
import itertools N = int(eval(input())) A = [] arr = [] ans = 0 li = list(itertools.product([0, 1], repeat=N)) for n in range(N): a = int(eval(input())) A.append(a) arr.append([list(map(int, input().split())) for _ in range(a)]) for l in li: flg = 0 for n in range(N): if l[n] == 1: for m in range(A[n]): if l[arr[n][m][0] - 1] != arr[n][m][1]: flg = 1 break if flg == 1: break if flg == 1: continue count = l.count(1) ans = max(ans, count) print(ans)
false
13.888889
[ "+import itertools", "+", "+li = list(itertools.product([0, 1], repeat=N))", "-for i in range(2**N):", "- ord = [0] * N", "- count = 0", "+for l in li:", "- if (i >> n) & 1:", "- count += 1", "- ord[n] = 1", "- for n in range(N):", "- if ord[n] == 1:", "+ if l[n] == 1:", "- if ord[arr[n][m][0] - 1] != arr[n][m][1]:", "+ if l[arr[n][m][0] - 1] != arr[n][m][1]:", "+ if flg == 1:", "+ break", "+ count = l.count(1)" ]
false
0.056494
0.035755
1.580021
[ "s162228089", "s163142864" ]
u606045429
p02888
python
s078280124
s531159571
1,960
1,155
3,188
3,316
Accepted
Accepted
41.07
from itertools import combinations from bisect import bisect_right def main(): N, *L = list(map(int, open(0).read().split())) L.sort() print((sum(bisect_right(L, L[i] + L[j] - 1, lo=j + 1) - (j + 1) for i, j in combinations(list(range(N)), 2)))) if __name__ == '__main__': main()
from itertools import combinations from bisect import bisect_right def main(): N, *L = list(map(int, open(0).read().split())) L.sort() print((sum(bisect_right(L, L[i] + L[j] - 1, j + 1) - (j + 1) for i, j in combinations(list(range(N)), 2)))) if __name__ == '__main__': main()
12
12
297
293
from itertools import combinations from bisect import bisect_right def main(): N, *L = list(map(int, open(0).read().split())) L.sort() print( ( sum( bisect_right(L, L[i] + L[j] - 1, lo=j + 1) - (j + 1) for i, j in combinations(list(range(N)), 2) ) ) ) if __name__ == "__main__": main()
from itertools import combinations from bisect import bisect_right def main(): N, *L = list(map(int, open(0).read().split())) L.sort() print( ( sum( bisect_right(L, L[i] + L[j] - 1, j + 1) - (j + 1) for i, j in combinations(list(range(N)), 2) ) ) ) if __name__ == "__main__": main()
false
0
[ "- bisect_right(L, L[i] + L[j] - 1, lo=j + 1) - (j + 1)", "+ bisect_right(L, L[i] + L[j] - 1, j + 1) - (j + 1)" ]
false
0.047512
0.037528
1.266032
[ "s078280124", "s531159571" ]
u392319141
p03253
python
s131781606
s614844122
161
145
15,788
18,916
Accepted
Accepted
9.94
class Combination: def __init__(self, size, mod=10**9 + 7): self.size = size + 2 self.mod = mod self.fact = [1, 1] + [0] * size self.factInv = [1, 1] + [0] * size self.inv = [0, 1] + [0] * size for i in range(2, self.size): self.fact[i] = self.fact[i - 1] * i % self.mod self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod def npr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * self.factInv[n - r] % self.mod def ncr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod def factN(self, n): if n < 0: return 0 return self.fact[n] N, M = list(map(int, input().split())) MOD = 10**9 + 7 def primeCount(N): R = int(N**(0.5)) + 1 # 素数の範囲 primes = {} # 素数のリスト n = N for num in range(2, R): primes[num] = 0 while n % num == 0: n //= num primes[num] += 1 if n > 1 : primes[n] = 1 return { key : val for key, val in list(primes.items()) if val > 0} # フィルターをかける primeM = primeCount(M) ans = 1 comb = Combination(sum(primeM.values()) + N + 100) for cnt in list(primeM.values()): ans *= comb.ncr(cnt + N - 1, cnt) ans %= MOD print(ans)
MOD = 10**9 + 7 class Combination: def __init__(self, size): self.size = size + 2 self.fact = [1, 1] + [0] * size self.factInv = [1, 1] + [0] * size self.inv = [0, 1] + [0] * size for i in range(2, self.size): self.fact[i] = self.fact[i - 1] * i % MOD self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD def npr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * self.factInv[n - r] % MOD def ncr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD def nhr(self, n, r): # 重複組合せ: x_1 + ... + x_n = r return self.ncr(n + r - 1, n - 1) N, M = list(map(int, input().split())) comb = Combination(N + 100) def primeCount(N): R = int(N**(0.5)) + 1 # 素数の範囲 primes = {} # 素数のリスト n = N for num in range(2, R): primes[num] = 0 while n % num == 0: n //= num primes[num] += 1 if n > 1 : primes[n] = 1 return { key : val for key, val in list(primes.items()) if val > 0} # フィルターをかける ans = 1 for c in list(primeCount(M).values()): ans *= comb.nhr(N, c) ans %= MOD print(ans)
53
48
1,518
1,387
class Combination: def __init__(self, size, mod=10**9 + 7): self.size = size + 2 self.mod = mod self.fact = [1, 1] + [0] * size self.factInv = [1, 1] + [0] * size self.inv = [0, 1] + [0] * size for i in range(2, self.size): self.fact[i] = self.fact[i - 1] * i % self.mod self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod def npr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * self.factInv[n - r] % self.mod def ncr(self, n, r): if n < r or n < 0 or r < 0: return 0 return ( self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod ) def factN(self, n): if n < 0: return 0 return self.fact[n] N, M = list(map(int, input().split())) MOD = 10**9 + 7 def primeCount(N): R = int(N ** (0.5)) + 1 # 素数の範囲 primes = {} # 素数のリスト n = N for num in range(2, R): primes[num] = 0 while n % num == 0: n //= num primes[num] += 1 if n > 1: primes[n] = 1 return {key: val for key, val in list(primes.items()) if val > 0} # フィルターをかける primeM = primeCount(M) ans = 1 comb = Combination(sum(primeM.values()) + N + 100) for cnt in list(primeM.values()): ans *= comb.ncr(cnt + N - 1, cnt) ans %= MOD print(ans)
MOD = 10**9 + 7 class Combination: def __init__(self, size): self.size = size + 2 self.fact = [1, 1] + [0] * size self.factInv = [1, 1] + [0] * size self.inv = [0, 1] + [0] * size for i in range(2, self.size): self.fact[i] = self.fact[i - 1] * i % MOD self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD def npr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * self.factInv[n - r] % MOD def ncr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD def nhr(self, n, r): # 重複組合せ: x_1 + ... + x_n = r return self.ncr(n + r - 1, n - 1) N, M = list(map(int, input().split())) comb = Combination(N + 100) def primeCount(N): R = int(N ** (0.5)) + 1 # 素数の範囲 primes = {} # 素数のリスト n = N for num in range(2, R): primes[num] = 0 while n % num == 0: n //= num primes[num] += 1 if n > 1: primes[n] = 1 return {key: val for key, val in list(primes.items()) if val > 0} # フィルターをかける ans = 1 for c in list(primeCount(M).values()): ans *= comb.nhr(N, c) ans %= MOD print(ans)
false
9.433962
[ "+MOD = 10**9 + 7", "+", "+", "- def __init__(self, size, mod=10**9 + 7):", "+ def __init__(self, size):", "- self.mod = mod", "- self.fact[i] = self.fact[i - 1] * i % self.mod", "- self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod", "- self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod", "+ self.fact[i] = self.fact[i - 1] * i % MOD", "+ self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD", "+ self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD", "- return self.fact[n] * self.factInv[n - r] % self.mod", "+ return self.fact[n] * self.factInv[n - r] % MOD", "- return (", "- self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod", "- )", "+ return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD", "- def factN(self, n):", "- if n < 0:", "- return 0", "- return self.fact[n]", "+ def nhr(self, n, r): # 重複組合せ: x_1 + ... + x_n = r", "+ return self.ncr(n + r - 1, n - 1)", "-MOD = 10**9 + 7", "+comb = Combination(N + 100)", "-primeM = primeCount(M)", "-comb = Combination(sum(primeM.values()) + N + 100)", "-for cnt in list(primeM.values()):", "- ans *= comb.ncr(cnt + N - 1, cnt)", "+for c in list(primeCount(M).values()):", "+ ans *= comb.nhr(N, c)" ]
false
0.077094
0.091881
0.839062
[ "s131781606", "s614844122" ]
u015593272
p02727
python
s903642381
s061488966
447
236
23,616
22,720
Accepted
Accepted
47.2
from collections import deque N_red_toEat, N_green_toEat, N_red, N_green, N_white = list(map(int, input().split())) delicious_red = list(map(int, input().split())) delicious_green = list(map(int, input().split())) delicious_white = list(map(int, input().split())) delicious_red.sort(reverse=True) delicious_green.sort(reverse=True) delicious_white.sort(reverse=True) delicious_red = delicious_red[:N_red_toEat] delicious_green = delicious_green[:N_green_toEat] Q_red = deque(delicious_red) Q_green = deque(delicious_green) Q_white = deque(delicious_white) summ = 0 for n in range(N_red_toEat + N_green_toEat): if (len(Q_red) > 0): r_tmp = Q_red.popleft() else: r_tmp = 0 if (len(Q_green) > 0): g_tmp = Q_green.popleft() else: g_tmp = 0 if (len(Q_white) > 0): w_tmp = Q_white.popleft() else: w_tmp = 0 MAX_tmp = max(r_tmp, g_tmp, w_tmp) if (MAX_tmp == r_tmp): eat = r_tmp Q_green.appendleft(g_tmp) Q_white.appendleft(w_tmp) elif (MAX_tmp == g_tmp): eat = g_tmp Q_red.appendleft(r_tmp) Q_white.appendleft(w_tmp) else: eat = w_tmp Q_red.appendleft(r_tmp) Q_green.appendleft(g_tmp) summ += eat print(summ)
x, y, a, b, c = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a = sorted(a, reverse=True)[:x] b = sorted(b, reverse=True)[:y] al = a + b + c al.sort(reverse=True) ans = sum(al[: x + y]) print(ans)
58
15
1,364
303
from collections import deque N_red_toEat, N_green_toEat, N_red, N_green, N_white = list(map(int, input().split())) delicious_red = list(map(int, input().split())) delicious_green = list(map(int, input().split())) delicious_white = list(map(int, input().split())) delicious_red.sort(reverse=True) delicious_green.sort(reverse=True) delicious_white.sort(reverse=True) delicious_red = delicious_red[:N_red_toEat] delicious_green = delicious_green[:N_green_toEat] Q_red = deque(delicious_red) Q_green = deque(delicious_green) Q_white = deque(delicious_white) summ = 0 for n in range(N_red_toEat + N_green_toEat): if len(Q_red) > 0: r_tmp = Q_red.popleft() else: r_tmp = 0 if len(Q_green) > 0: g_tmp = Q_green.popleft() else: g_tmp = 0 if len(Q_white) > 0: w_tmp = Q_white.popleft() else: w_tmp = 0 MAX_tmp = max(r_tmp, g_tmp, w_tmp) if MAX_tmp == r_tmp: eat = r_tmp Q_green.appendleft(g_tmp) Q_white.appendleft(w_tmp) elif MAX_tmp == g_tmp: eat = g_tmp Q_red.appendleft(r_tmp) Q_white.appendleft(w_tmp) else: eat = w_tmp Q_red.appendleft(r_tmp) Q_green.appendleft(g_tmp) summ += eat print(summ)
x, y, a, b, c = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a = sorted(a, reverse=True)[:x] b = sorted(b, reverse=True)[:y] al = a + b + c al.sort(reverse=True) ans = sum(al[: x + y]) print(ans)
false
74.137931
[ "-from collections import deque", "-", "-N_red_toEat, N_green_toEat, N_red, N_green, N_white = list(map(int, input().split()))", "-delicious_red = list(map(int, input().split()))", "-delicious_green = list(map(int, input().split()))", "-delicious_white = list(map(int, input().split()))", "-delicious_red.sort(reverse=True)", "-delicious_green.sort(reverse=True)", "-delicious_white.sort(reverse=True)", "-delicious_red = delicious_red[:N_red_toEat]", "-delicious_green = delicious_green[:N_green_toEat]", "-Q_red = deque(delicious_red)", "-Q_green = deque(delicious_green)", "-Q_white = deque(delicious_white)", "-summ = 0", "-for n in range(N_red_toEat + N_green_toEat):", "- if len(Q_red) > 0:", "- r_tmp = Q_red.popleft()", "- else:", "- r_tmp = 0", "- if len(Q_green) > 0:", "- g_tmp = Q_green.popleft()", "- else:", "- g_tmp = 0", "- if len(Q_white) > 0:", "- w_tmp = Q_white.popleft()", "- else:", "- w_tmp = 0", "- MAX_tmp = max(r_tmp, g_tmp, w_tmp)", "- if MAX_tmp == r_tmp:", "- eat = r_tmp", "- Q_green.appendleft(g_tmp)", "- Q_white.appendleft(w_tmp)", "- elif MAX_tmp == g_tmp:", "- eat = g_tmp", "- Q_red.appendleft(r_tmp)", "- Q_white.appendleft(w_tmp)", "- else:", "- eat = w_tmp", "- Q_red.appendleft(r_tmp)", "- Q_green.appendleft(g_tmp)", "- summ += eat", "-print(summ)", "+x, y, a, b, c = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+b = list(map(int, input().split()))", "+c = list(map(int, input().split()))", "+a = sorted(a, reverse=True)[:x]", "+b = sorted(b, reverse=True)[:y]", "+al = a + b + c", "+al.sort(reverse=True)", "+ans = sum(al[: x + y])", "+print(ans)" ]
false
0.103852
0.036123
2.874957
[ "s903642381", "s061488966" ]
u334712262
p02839
python
s731495260
s680864043
1,986
1,711
550,668
552,232
Accepted
Accepted
13.85
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(H, W, A, B): C = [[abs(a-b) for a, b in zip(ar, br)] for ar, br in zip(A, B)] memo = [[set() for _ in range(W)] for __ in range(H)] memo[0][0].add(C[0][0]) for i in range(H): for j in range(W): c = C[i][j] if i > 0: for d in memo[i-1][j]: memo[i][j].add(abs(d + c)) memo[i][j].add(abs(d - c)) if j > 0: for d in memo[i][j-1]: memo[i][j].add(abs(d + c)) memo[i][j].add(abs(d - c)) return min(map(abs, memo[H-1][W-1])) def main(): H, W = read_int_n() A = [read_int_n() for _ in range(H)] B = [read_int_n() for _ in range(H)] print(slv(H, W, A, B)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(H, W, A, B): C = [[abs(a-b) for a, b in zip(ar, br)] for ar, br in zip(A, B)] memo = [[set() for _ in range(W)] for __ in range(H)] memo[0][0].add(C[0][0]) for i in range(H): for j in range(W): c = C[i][j] s = memo[i][j] if i > 0: for d in memo[i-1][j]: s.add(abs(d + c)) s.add(abs(d - c)) if j > 0: for d in memo[i][j-1]: s.add(abs(d + c)) s.add(abs(d - c)) return min(map(abs, memo[H-1][W-1])) def main(): H, W = read_int_n() A = [read_int_n() for _ in range(H)] B = [read_int_n() for _ in range(H)] print(slv(H, W, A, B)) if __name__ == '__main__': main()
95
95
2,040
2,030
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(H, W, A, B): C = [[abs(a - b) for a, b in zip(ar, br)] for ar, br in zip(A, B)] memo = [[set() for _ in range(W)] for __ in range(H)] memo[0][0].add(C[0][0]) for i in range(H): for j in range(W): c = C[i][j] if i > 0: for d in memo[i - 1][j]: memo[i][j].add(abs(d + c)) memo[i][j].add(abs(d - c)) if j > 0: for d in memo[i][j - 1]: memo[i][j].add(abs(d + c)) memo[i][j].add(abs(d - c)) return min(map(abs, memo[H - 1][W - 1])) def main(): H, W = read_int_n() A = [read_int_n() for _ in range(H)] B = [read_int_n() for _ in range(H)] print(slv(H, W, A, B)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(H, W, A, B): C = [[abs(a - b) for a, b in zip(ar, br)] for ar, br in zip(A, B)] memo = [[set() for _ in range(W)] for __ in range(H)] memo[0][0].add(C[0][0]) for i in range(H): for j in range(W): c = C[i][j] s = memo[i][j] if i > 0: for d in memo[i - 1][j]: s.add(abs(d + c)) s.add(abs(d - c)) if j > 0: for d in memo[i][j - 1]: s.add(abs(d + c)) s.add(abs(d - c)) return min(map(abs, memo[H - 1][W - 1])) def main(): H, W = read_int_n() A = [read_int_n() for _ in range(H)] B = [read_int_n() for _ in range(H)] print(slv(H, W, A, B)) if __name__ == "__main__": main()
false
0
[ "+ s = memo[i][j]", "- memo[i][j].add(abs(d + c))", "- memo[i][j].add(abs(d - c))", "+ s.add(abs(d + c))", "+ s.add(abs(d - c))", "- memo[i][j].add(abs(d + c))", "- memo[i][j].add(abs(d - c))", "+ s.add(abs(d + c))", "+ s.add(abs(d - c))" ]
false
0.046305
0.046195
1.002391
[ "s731495260", "s680864043" ]
u288280761
p03032
python
s657137358
s295757664
43
39
3,064
3,064
Accepted
Accepted
9.3
from heapq import heappop, heappush N, K = list(map(int, input().split())) V = list(map(int, input().split())) ans = 0 for left in range(min(N, K) + 1): for right in range(min(N, K) - left + 1): heap = [] for v in V[:left]: heappush(heap, v) for v in V[N - right:]: heappush(heap, v) cnt = left + right v = 0 while cnt < K and len(heap) > 0: v = heappop(heap) if v >= 0: heappush(heap, v) break cnt += 1 ans = max(ans, sum(heap)) print(ans)
N, K = list(map(int, input().strip().split())) V = list(map(int, input().strip().split())) maxi = 0 for i in range(min(N, K)): for o in range(i+2): hand = [] for p in range(o): hand.append(V[p]) for p in range(N-(i-o)-1, N): hand.append(V[p]) hand.sort() for j in range(K-i-1): if len(hand) > 0: if hand[0] < 0: del hand[0] else: break ts = 0 for k in hand: ts += k if ts > maxi: maxi = ts print(maxi)
29
24
623
619
from heapq import heappop, heappush N, K = list(map(int, input().split())) V = list(map(int, input().split())) ans = 0 for left in range(min(N, K) + 1): for right in range(min(N, K) - left + 1): heap = [] for v in V[:left]: heappush(heap, v) for v in V[N - right :]: heappush(heap, v) cnt = left + right v = 0 while cnt < K and len(heap) > 0: v = heappop(heap) if v >= 0: heappush(heap, v) break cnt += 1 ans = max(ans, sum(heap)) print(ans)
N, K = list(map(int, input().strip().split())) V = list(map(int, input().strip().split())) maxi = 0 for i in range(min(N, K)): for o in range(i + 2): hand = [] for p in range(o): hand.append(V[p]) for p in range(N - (i - o) - 1, N): hand.append(V[p]) hand.sort() for j in range(K - i - 1): if len(hand) > 0: if hand[0] < 0: del hand[0] else: break ts = 0 for k in hand: ts += k if ts > maxi: maxi = ts print(maxi)
false
17.241379
[ "-from heapq import heappop, heappush", "-", "-N, K = list(map(int, input().split()))", "-V = list(map(int, input().split()))", "-ans = 0", "-for left in range(min(N, K) + 1):", "- for right in range(min(N, K) - left + 1):", "- heap = []", "- for v in V[:left]:", "- heappush(heap, v)", "- for v in V[N - right :]:", "- heappush(heap, v)", "- cnt = left + right", "- v = 0", "- while cnt < K and len(heap) > 0:", "- v = heappop(heap)", "- if v >= 0:", "- heappush(heap, v)", "- break", "- cnt += 1", "- ans = max(ans, sum(heap))", "-print(ans)", "+N, K = list(map(int, input().strip().split()))", "+V = list(map(int, input().strip().split()))", "+maxi = 0", "+for i in range(min(N, K)):", "+ for o in range(i + 2):", "+ hand = []", "+ for p in range(o):", "+ hand.append(V[p])", "+ for p in range(N - (i - o) - 1, N):", "+ hand.append(V[p])", "+ hand.sort()", "+ for j in range(K - i - 1):", "+ if len(hand) > 0:", "+ if hand[0] < 0:", "+ del hand[0]", "+ else:", "+ break", "+ ts = 0", "+ for k in hand:", "+ ts += k", "+ if ts > maxi:", "+ maxi = ts", "+print(maxi)" ]
false
0.038923
0.041618
0.935243
[ "s657137358", "s295757664" ]
u759412327
p03307
python
s048682843
s062711439
19
17
3,060
2,940
Accepted
Accepted
10.53
N = int(eval(input())) if N%2==0: print(N) else: print((2*N))
N = int(eval(input())) print((N+N%2*N))
6
2
63
32
N = int(eval(input())) if N % 2 == 0: print(N) else: print((2 * N))
N = int(eval(input())) print((N + N % 2 * N))
false
66.666667
[ "-if N % 2 == 0:", "- print(N)", "-else:", "- print((2 * N))", "+print((N + N % 2 * N))" ]
false
0.043051
0.044055
0.977216
[ "s048682843", "s062711439" ]
u150984829
p00008
python
s141831825
s422396125
110
20
5,608
5,596
Accepted
Accepted
81.82
import sys for e in sys.stdin: e=int(e);x=list(range(10)) print((sum([1 for a in x for b in x for c in x for d in x if a+b+c+d==e])))
import sys a=[0]*51 for i in range(19): a[i]=a[36-i]=(i+3)*(i+2)*(i+1)//6-max(2*(i-9)*(i-8)*(i-7)//3,0) for e in sys.stdin: print((a[int(e)]))
4
6
131
148
import sys for e in sys.stdin: e = int(e) x = list(range(10)) print((sum([1 for a in x for b in x for c in x for d in x if a + b + c + d == e])))
import sys a = [0] * 51 for i in range(19): a[i] = a[36 - i] = (i + 3) * (i + 2) * (i + 1) // 6 - max( 2 * (i - 9) * (i - 8) * (i - 7) // 3, 0 ) for e in sys.stdin: print((a[int(e)]))
false
33.333333
[ "+a = [0] * 51", "+for i in range(19):", "+ a[i] = a[36 - i] = (i + 3) * (i + 2) * (i + 1) // 6 - max(", "+ 2 * (i - 9) * (i - 8) * (i - 7) // 3, 0", "+ )", "- e = int(e)", "- x = list(range(10))", "- print((sum([1 for a in x for b in x for c in x for d in x if a + b + c + d == e])))", "+ print((a[int(e)]))" ]
false
0.037864
0.058004
0.652786
[ "s141831825", "s422396125" ]
u368796742
p03700
python
s538326641
s833722867
1,114
545
7,384
50,392
Accepted
Accepted
51.08
n,a,b = list(map(int,input().split())) h = [int(eval(input())) for i in range(n)] h.sort() t = a-b r = 10**9+5 l = 0 while r-l > 1: m = (r+l)//2 mi = m*b count = 0 for i in h: if i > mi: count += (i-mi+t-1)//t if count <= m: r = m else: l = m print(r)
n,a,b = list(map(int,input().split())) h = [int(eval(input())) for i in range(n)] t = a-b r = (max(h)+b-1)//b l = 0 while r-l > 1: m = (r+l)//2 mi = m*b count = 0 for i in h: if i > mi: count += (i-mi+t-1)//t if count <= m: r = m else: l = m print(r)
19
17
318
314
n, a, b = list(map(int, input().split())) h = [int(eval(input())) for i in range(n)] h.sort() t = a - b r = 10**9 + 5 l = 0 while r - l > 1: m = (r + l) // 2 mi = m * b count = 0 for i in h: if i > mi: count += (i - mi + t - 1) // t if count <= m: r = m else: l = m print(r)
n, a, b = list(map(int, input().split())) h = [int(eval(input())) for i in range(n)] t = a - b r = (max(h) + b - 1) // b l = 0 while r - l > 1: m = (r + l) // 2 mi = m * b count = 0 for i in h: if i > mi: count += (i - mi + t - 1) // t if count <= m: r = m else: l = m print(r)
false
10.526316
[ "-h.sort()", "-r = 10**9 + 5", "+r = (max(h) + b - 1) // b" ]
false
0.036398
0.122231
0.297778
[ "s538326641", "s833722867" ]
u811733736
p00203
python
s865490913
s303254178
50
40
8,056
8,080
Accepted
Accepted
20
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if (ny >= y_limit - 1) and field[ny][nx] == BLANK: ans += num else: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = list(map(int, input().strip().split())) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict(int) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = '{}_{}'.format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = '{}_{}'.format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy+2 > y_limit-1: ans += num else: t = '{}_{}'.format(cx, cy+2) if not path[t]: Q.append((cx, cy+2)) path[t] += num continue elif cy == y_limit -1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0<= nx < x_limit: if field[ny][nx] == JUMP and dx[i] == 0: # ?????£????????°????????£??????????????\????????´??? if ny+2 > y_limit - 1: ans += num else: t = '{}_{}'.format(nx, ny+2) if not path[t]: Q.append((nx, ny+2)) path[t] += num elif field[ny][nx] == BLANK: if (ny >= y_limit - 1): ans += num else: t = '{}_{}'.format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = list(map(int, input().strip().split())) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == '__main__': main(sys.argv[1:])
87
87
2,811
2,792
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict( int ) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = "{}_{}".format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = "{}_{}".format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy + 2 > y_limit - 1: ans += num else: t = "{}_{}".format(cx, cy + 2) if not path[t]: Q.append((cx, cy + 2)) path[t] += num continue elif cy == y_limit - 1: ans += num continue for i in range(len(dx)): nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0 <= nx < x_limit: if (ny >= y_limit - 1) and field[ny][nx] == BLANK: ans += num else: if ( field[ny][nx] == JUMP and dx[i] == 0 ): # ?????£????????°????????£??????????????\????????´??? if ny + 2 > y_limit - 1: ans += num else: t = "{}_{}".format(nx, ny + 2) if not path[t]: Q.append((nx, ny + 2)) path[t] += num elif field[ny][nx] == BLANK: t = "{}_{}".format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = list(map(int, input().strip().split())) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == "__main__": main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203 """ import sys from sys import stdin from collections import deque, defaultdict input = stdin.readline def solve(field): BLANK, OBSTACLE, JUMP = 0, 1, 2 ans = 0 # ??????????????°???????????° dy = [1, 1, 1] # ?????????????????????????????????????§??????? dx = [0, -1, 1] x_limit = len(field[0]) y_limit = len(field) path = defaultdict( int ) # ??????????????????????????°???????????°????????????'x???_y???'??????????????? Q = deque() for x, m in enumerate(field[0]): if m == BLANK: # ?????????????????°?????´????????????????????????????????? t = "{}_{}".format(x, 0) Q.append((x, 0)) path[t] = 1 while Q: cx, cy = Q.popleft() # ?????¨??°?????§?¨? t = "{}_{}".format(cx, cy) num = path.pop(t) if field[cy][cx] == OBSTACLE: continue elif field[cy][cx] == JUMP: # ?????£????????§?????°?????????????????£????????° if cy + 2 > y_limit - 1: ans += num else: t = "{}_{}".format(cx, cy + 2) if not path[t]: Q.append((cx, cy + 2)) path[t] += num continue elif cy == y_limit - 1: ans += num continue for i in range(3): # ?????????3???len(dy)????????? nx = cx + dx[i] # ?????°????????§?¨? ny = cy + dy[i] if 0 <= nx < x_limit: if ( field[ny][nx] == JUMP and dx[i] == 0 ): # ?????£????????°????????£??????????????\????????´??? if ny + 2 > y_limit - 1: ans += num else: t = "{}_{}".format(nx, ny + 2) if not path[t]: Q.append((nx, ny + 2)) path[t] += num elif field[ny][nx] == BLANK: if ny >= y_limit - 1: ans += num else: t = "{}_{}".format(nx, ny) if not path[t]: Q.append((nx, ny)) path[t] += num return ans def main(args): while True: X, Y = list(map(int, input().strip().split())) if X == 0 and Y == 0: break field = [] for _ in range(Y): temp = [int(x) for x in input().strip().split()] field.append(temp) result = solve(field) print(result) if __name__ == "__main__": main(sys.argv[1:])
false
0
[ "- for i in range(len(dx)):", "+ for i in range(3): # ?????????3???len(dy)?????????", "- if (ny >= y_limit - 1) and field[ny][nx] == BLANK:", "- ans += num", "- else:", "- if (", "- field[ny][nx] == JUMP and dx[i] == 0", "- ): # ?????£????????°????????£??????????????\\????????´???", "- if ny + 2 > y_limit - 1:", "- ans += num", "- else:", "- t = \"{}_{}\".format(nx, ny + 2)", "- if not path[t]:", "- Q.append((nx, ny + 2))", "- path[t] += num", "- elif field[ny][nx] == BLANK:", "+ if (", "+ field[ny][nx] == JUMP and dx[i] == 0", "+ ): # ?????£????????°????????£??????????????\\????????´???", "+ if ny + 2 > y_limit - 1:", "+ ans += num", "+ else:", "+ t = \"{}_{}\".format(nx, ny + 2)", "+ if not path[t]:", "+ Q.append((nx, ny + 2))", "+ path[t] += num", "+ elif field[ny][nx] == BLANK:", "+ if ny >= y_limit - 1:", "+ ans += num", "+ else:" ]
false
0.038998
0.039811
0.979582
[ "s865490913", "s303254178" ]
u620084012
p04034
python
s204863322
s980395299
731
615
4,784
61,656
Accepted
Accepted
15.87
N, M = list(map(int, input().split())) A = [1 for k in range(N)] B = [0 for k in range(N)] ans = 0 B[0] = 1 for k in range(M): x, y = list(map(int, input().split())) x -= 1 y -= 1 if B[x] == 1 and A[x] >= 2: A[x] -= 1 A[y] += 1 B[y] = 1 elif B[x] == 1 and A[x] == 1: A[x] -= 1 A[y] += 1 B[x] = 0 B[y] = 1 else: A[x] -= 1 A[y] += 1 print((B.count(1)))
N, M = list(map(int,input().split())) B = [list(map(int,input().split())) for k in range(M)] H = [1]*N E = [0]*N E[0] = 1 for e in B: x, y = e[0]-1, e[1]-1 if E[x] == 1: if H[x] == 1: E[x] = 0 E[y] = 1 else: E[y] = 1 H[x] -= 1 H[y] += 1 print((E.count(1)))
24
16
457
332
N, M = list(map(int, input().split())) A = [1 for k in range(N)] B = [0 for k in range(N)] ans = 0 B[0] = 1 for k in range(M): x, y = list(map(int, input().split())) x -= 1 y -= 1 if B[x] == 1 and A[x] >= 2: A[x] -= 1 A[y] += 1 B[y] = 1 elif B[x] == 1 and A[x] == 1: A[x] -= 1 A[y] += 1 B[x] = 0 B[y] = 1 else: A[x] -= 1 A[y] += 1 print((B.count(1)))
N, M = list(map(int, input().split())) B = [list(map(int, input().split())) for k in range(M)] H = [1] * N E = [0] * N E[0] = 1 for e in B: x, y = e[0] - 1, e[1] - 1 if E[x] == 1: if H[x] == 1: E[x] = 0 E[y] = 1 else: E[y] = 1 H[x] -= 1 H[y] += 1 print((E.count(1)))
false
33.333333
[ "-A = [1 for k in range(N)]", "-B = [0 for k in range(N)]", "-ans = 0", "-B[0] = 1", "-for k in range(M):", "- x, y = list(map(int, input().split()))", "- x -= 1", "- y -= 1", "- if B[x] == 1 and A[x] >= 2:", "- A[x] -= 1", "- A[y] += 1", "- B[y] = 1", "- elif B[x] == 1 and A[x] == 1:", "- A[x] -= 1", "- A[y] += 1", "- B[x] = 0", "- B[y] = 1", "- else:", "- A[x] -= 1", "- A[y] += 1", "-print((B.count(1)))", "+B = [list(map(int, input().split())) for k in range(M)]", "+H = [1] * N", "+E = [0] * N", "+E[0] = 1", "+for e in B:", "+ x, y = e[0] - 1, e[1] - 1", "+ if E[x] == 1:", "+ if H[x] == 1:", "+ E[x] = 0", "+ E[y] = 1", "+ else:", "+ E[y] = 1", "+ H[x] -= 1", "+ H[y] += 1", "+print((E.count(1)))" ]
false
0.03309
0.034916
0.947715
[ "s204863322", "s980395299" ]
u414920281
p02726
python
s484918761
s226726376
1,830
107
9,224
74,328
Accepted
Accepted
94.15
n,x,y=list(map(int,input().split())) num=[0]*(n-1) for i in range(n-1): for j in range(i+1,n): d=int(min(j-i,abs(x-j-1)+1+abs(y-1-i),abs(y-1-j)+1+abs(x-1-i))) num[d-1]+=1 for i in range(n-1): print((num[i]))
n,x,y=list(map(int,input().split())) ans=[0]*n for i in range(1,n): for j in range(i+1,n+1): ans[int(min(j-i,abs(x-i)+abs(y-j)+1))]+=1 for i in range(1,n): print((ans[i]))
8
7
230
185
n, x, y = list(map(int, input().split())) num = [0] * (n - 1) for i in range(n - 1): for j in range(i + 1, n): d = int( min( j - i, abs(x - j - 1) + 1 + abs(y - 1 - i), abs(y - 1 - j) + 1 + abs(x - 1 - i), ) ) num[d - 1] += 1 for i in range(n - 1): print((num[i]))
n, x, y = list(map(int, input().split())) ans = [0] * n for i in range(1, n): for j in range(i + 1, n + 1): ans[int(min(j - i, abs(x - i) + abs(y - j) + 1))] += 1 for i in range(1, n): print((ans[i]))
false
12.5
[ "-num = [0] * (n - 1)", "-for i in range(n - 1):", "- for j in range(i + 1, n):", "- d = int(", "- min(", "- j - i,", "- abs(x - j - 1) + 1 + abs(y - 1 - i),", "- abs(y - 1 - j) + 1 + abs(x - 1 - i),", "- )", "- )", "- num[d - 1] += 1", "-for i in range(n - 1):", "- print((num[i]))", "+ans = [0] * n", "+for i in range(1, n):", "+ for j in range(i + 1, n + 1):", "+ ans[int(min(j - i, abs(x - i) + abs(y - j) + 1))] += 1", "+for i in range(1, n):", "+ print((ans[i]))" ]
false
0.075716
0.036296
2.086069
[ "s484918761", "s226726376" ]
u075012704
p03222
python
s052471599
s380586686
46
34
3,064
3,064
Accepted
Accepted
26.09
H, W, K = list(map(int, input().split())) mod = 10 ** 9 + 7 # 高さiにおいて左からj番目の棒にいる通り数 dp = [[0] * W for i in range(H + 1)] dp[0][0] = 1 def pattern(w): """ 幅wのあみだにおいて、validなものの通り数を返す """ # 例外処理 if w < 0: return 1 cnt = 0 for i in range(2 ** w): b = bin(2 ** w + i)[3:] if '11' not in b: cnt += 1 return cnt for i in range(1, H + 1): for j in range(W): tmp = 0 # 上からおりてくる tmp += dp[i - 1][j] * pattern(j - 1) * pattern(W - j - 2) % mod # 左からおりてくる if j > 0: tmp += dp[i - 1][j - 1] * pattern(j - 2) * pattern(W - j - 2) % mod # 右からおりてくる if j < W - 1: tmp += dp[i - 1][j + 1] * pattern(j - 1) * pattern(W - j - 3) % mod dp[i][j] += tmp print((dp[H][K - 1] % mod))
from itertools import product H, W, K = list(map(int, input().split())) mod = 10 ** 9 + 7 # dp[i][j]:= 上からi番目, 左からj番目にいる通り数 dp = [[0] * W for i in range(H + 1)] dp[0][0] = 1 def calc(x): if x < 0: return 1 ret = 0 for p in product(['0', '1'], repeat=x): p = ''.join(p) if '11' not in p: ret += 1 return ret for i in range(1, H + 1): for j in range(W): tmp = 0 if j > 0: # 左から tmp += dp[i - 1][j - 1] * calc(j - 2) * calc(W - j - 2) % mod # 上から tmp += dp[i - 1][j] * calc(j - 1) * calc(W - j - 2) % mod if j + 1 < W: # 右から tmp += dp[i - 1][j + 1] * calc(j - 1) * calc(W - j - 3) % mod dp[i][j] = tmp print((dp[H][K - 1] % mod))
39
35
851
792
H, W, K = list(map(int, input().split())) mod = 10**9 + 7 # 高さiにおいて左からj番目の棒にいる通り数 dp = [[0] * W for i in range(H + 1)] dp[0][0] = 1 def pattern(w): """幅wのあみだにおいて、validなものの通り数を返す""" # 例外処理 if w < 0: return 1 cnt = 0 for i in range(2**w): b = bin(2**w + i)[3:] if "11" not in b: cnt += 1 return cnt for i in range(1, H + 1): for j in range(W): tmp = 0 # 上からおりてくる tmp += dp[i - 1][j] * pattern(j - 1) * pattern(W - j - 2) % mod # 左からおりてくる if j > 0: tmp += dp[i - 1][j - 1] * pattern(j - 2) * pattern(W - j - 2) % mod # 右からおりてくる if j < W - 1: tmp += dp[i - 1][j + 1] * pattern(j - 1) * pattern(W - j - 3) % mod dp[i][j] += tmp print((dp[H][K - 1] % mod))
from itertools import product H, W, K = list(map(int, input().split())) mod = 10**9 + 7 # dp[i][j]:= 上からi番目, 左からj番目にいる通り数 dp = [[0] * W for i in range(H + 1)] dp[0][0] = 1 def calc(x): if x < 0: return 1 ret = 0 for p in product(["0", "1"], repeat=x): p = "".join(p) if "11" not in p: ret += 1 return ret for i in range(1, H + 1): for j in range(W): tmp = 0 if j > 0: # 左から tmp += dp[i - 1][j - 1] * calc(j - 2) * calc(W - j - 2) % mod # 上から tmp += dp[i - 1][j] * calc(j - 1) * calc(W - j - 2) % mod if j + 1 < W: # 右から tmp += dp[i - 1][j + 1] * calc(j - 1) * calc(W - j - 3) % mod dp[i][j] = tmp print((dp[H][K - 1] % mod))
false
10.25641
[ "+from itertools import product", "+", "-# 高さiにおいて左からj番目の棒にいる通り数", "+# dp[i][j]:= 上からi番目, 左からj番目にいる通り数", "-def pattern(w):", "- \"\"\"幅wのあみだにおいて、validなものの通り数を返す\"\"\"", "- # 例外処理", "- if w < 0:", "+def calc(x):", "+ if x < 0:", "- cnt = 0", "- for i in range(2**w):", "- b = bin(2**w + i)[3:]", "- if \"11\" not in b:", "- cnt += 1", "- return cnt", "+ ret = 0", "+ for p in product([\"0\", \"1\"], repeat=x):", "+ p = \"\".join(p)", "+ if \"11\" not in p:", "+ ret += 1", "+ return ret", "- # 上からおりてくる", "- tmp += dp[i - 1][j] * pattern(j - 1) * pattern(W - j - 2) % mod", "- # 左からおりてくる", "- if j > 0:", "- tmp += dp[i - 1][j - 1] * pattern(j - 2) * pattern(W - j - 2) % mod", "- # 右からおりてくる", "- if j < W - 1:", "- tmp += dp[i - 1][j + 1] * pattern(j - 1) * pattern(W - j - 3) % mod", "- dp[i][j] += tmp", "+ if j > 0: # 左から", "+ tmp += dp[i - 1][j - 1] * calc(j - 2) * calc(W - j - 2) % mod", "+ # 上から", "+ tmp += dp[i - 1][j] * calc(j - 1) * calc(W - j - 2) % mod", "+ if j + 1 < W: # 右から", "+ tmp += dp[i - 1][j + 1] * calc(j - 1) * calc(W - j - 3) % mod", "+ dp[i][j] = tmp" ]
false
0.039906
0.034121
1.169534
[ "s052471599", "s380586686" ]
u058781705
p02996
python
s739990469
s195797941
1,766
1,291
89,816
88,152
Accepted
Accepted
26.9
n = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort(key=lambda x: (x[1], -x[0])) time = 0 for a, b in AB: time += a if time > b: print('No') break else: print('Yes')
n = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort(key=lambda x: (x[1])) time = 0 for a, b in AB: time += a if time > b: print('No') break else: print('Yes')
11
11
234
227
n = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort(key=lambda x: (x[1], -x[0])) time = 0 for a, b in AB: time += a if time > b: print("No") break else: print("Yes")
n = int(eval(input())) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort(key=lambda x: (x[1])) time = 0 for a, b in AB: time += a if time > b: print("No") break else: print("Yes")
false
0
[ "-AB.sort(key=lambda x: (x[1], -x[0]))", "+AB.sort(key=lambda x: (x[1]))" ]
false
0.042155
0.041423
1.01767
[ "s739990469", "s195797941" ]
u013617325
p03363
python
s449944550
s848417240
193
174
44,252
31,576
Accepted
Accepted
9.84
import collections def main(N,A): B=[0] count = 0 for i in range(N): T = A[i] + B[i] B.append(T) c = collections.Counter(B) for i in range(len(c)): k, v = c.popitem() for z in range(v): count += z return print(count) if __name__ == "__main__": N=int(input()) A=list(map(int,input().split())) main(N,A)
def main(N,A): B=[0] count = 0 for i in range(N): T = A[i] + B[i] #print('count:',count) # # B = [A[i] +B[i] for i in range(N)] # # count = [ count + 1 for m in range(len(B)) if B[i] - B[i-m] == 0] # for m in range(len(B)): # if T - B[m] == 0: # # print(i, m) # # print(B[i],B[i-m]) # # print(T) # # print("kore",B[i],B[i-m]) # count += 1 B.append(T) B = sorted(B) # print(B) c = 0 for i in range(len(B)): if i==0: continue if B[i] == B[i-1]: c+=1 count +=c # print(c) # # print(count) else: c = 0 # # c = collections.Counter(B) # for i in range(len(c)): # k, v = c.popitem() # for z in range(v): # count += z #print(count) #print(B) return print(count) if __name__ == "__main__": N=int(input()) A=list(map(int,input().split())) main(N,A)
23
60
409
1,153
import collections def main(N, A): B = [0] count = 0 for i in range(N): T = A[i] + B[i] B.append(T) c = collections.Counter(B) for i in range(len(c)): k, v = c.popitem() for z in range(v): count += z return print(count) if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) main(N, A)
def main(N, A): B = [0] count = 0 for i in range(N): T = A[i] + B[i] # print('count:',count) # # B = [A[i] +B[i] for i in range(N)] # # count = [ count + 1 for m in range(len(B)) if B[i] - B[i-m] == 0] # for m in range(len(B)): # if T - B[m] == 0: # # print(i, m) # # print(B[i],B[i-m]) # # print(T) # # print("kore",B[i],B[i-m]) # count += 1 B.append(T) B = sorted(B) # print(B) c = 0 for i in range(len(B)): if i == 0: continue if B[i] == B[i - 1]: c += 1 count += c # print(c) # # print(count) else: c = 0 # # c = collections.Counter(B) # for i in range(len(c)): # k, v = c.popitem() # for z in range(v): # count += z # print(count) # print(B) return print(count) if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) main(N, A)
false
61.666667
[ "-import collections", "-", "-", "+ # print('count:',count)", "+ #", "+ # B = [A[i] +B[i] for i in range(N)]", "+ #", "+ # count = [ count + 1 for m in range(len(B)) if B[i] - B[i-m] == 0]", "+ # for m in range(len(B)):", "+ # if T - B[m] == 0:", "+ # # print(i, m)", "+ # # print(B[i],B[i-m])", "+ # # print(T)", "+ # # print(\"kore\",B[i],B[i-m])", "+ # count += 1", "- c = collections.Counter(B)", "- for i in range(len(c)):", "- k, v = c.popitem()", "- for z in range(v):", "- count += z", "+ B = sorted(B)", "+ # print(B)", "+ c = 0", "+ for i in range(len(B)):", "+ if i == 0:", "+ continue", "+ if B[i] == B[i - 1]:", "+ c += 1", "+ count += c", "+ # print(c)", "+ #", "+ # print(count)", "+ else:", "+ c = 0", "+ #", "+ # c = collections.Counter(B)", "+ # for i in range(len(c)):", "+ # k, v = c.popitem()", "+ # for z in range(v):", "+ # count += z", "+ # print(count)", "+ # print(B)" ]
false
0.038814
0.007427
5.226145
[ "s449944550", "s848417240" ]
u645250356
p03659
python
s121559365
s578350198
202
151
25,384
30,404
Accepted
Accepted
25.25
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue mod = 10**9+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()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n = inp() a = inpl() sum_a = sum(a) acc = list(itertools.accumulate(a)) ans = mod if n == 2: print((abs(a[0] - a[1]))) else: for i in range(n-1): tmp = abs(acc[i] - (acc[-1]-acc[i])) ans = min(ans, tmp) print(ans)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() su = sum(a) acc = list(itertools.accumulate(a)) b = [abs((su-acc[i]) - acc[i]) for i in range(n-1)] # print(b) print((min(b)))
20
17
606
514
from collections import Counter, defaultdict import sys, heapq, bisect, math, itertools, string, queue mod = 10**9 + 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()) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) n = inp() a = inpl() sum_a = sum(a) acc = list(itertools.accumulate(a)) ans = mod if n == 2: print((abs(a[0] - a[1]))) else: for i in range(n - 1): tmp = abs(acc[i] - (acc[-1] - acc[i])) ans = min(ans, tmp) print(ans)
from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heapify from bisect import bisect_left, bisect_right import sys, math, itertools, fractions, pprint sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() su = sum(a) acc = list(itertools.accumulate(a)) b = [abs((su - acc[i]) - acc[i]) for i in range(n - 1)] # print(b) print((min(b)))
false
15
[ "-from collections import Counter, defaultdict", "-import sys, heapq, bisect, math, itertools, string, queue", "+from collections import Counter, defaultdict, deque", "+from heapq import heappop, heappush, heapify", "+from bisect import bisect_left, bisect_right", "+import sys, math, itertools, fractions, pprint", "+sys.setrecursionlimit(10**8)", "+INF = float(\"inf\")", "-def inpl_str():", "- return list(sys.stdin.readline().split())", "-", "-", "-def inpln(n):", "- return list(int(sys.stdin.readline()) for i in range(n))", "-", "-", "-sum_a = sum(a)", "+su = sum(a)", "-ans = mod", "-if n == 2:", "- print((abs(a[0] - a[1])))", "-else:", "- for i in range(n - 1):", "- tmp = abs(acc[i] - (acc[-1] - acc[i]))", "- ans = min(ans, tmp)", "- print(ans)", "+b = [abs((su - acc[i]) - acc[i]) for i in range(n - 1)]", "+# print(b)", "+print((min(b)))" ]
false
0.057817
0.042556
1.358608
[ "s121559365", "s578350198" ]
u855775311
p02362
python
s636102279
s911175958
620
350
8,164
8,208
Accepted
Accepted
43.55
import math def main(): nvertices, nedges, s = list(map(int, input().split())) E = [] for i in range(nedges): u, v, w = list(map(int, input().split())) E.append((u, v, w)) INF = float('inf') d = [INF] * nvertices d[s] = 0 for i in range(nvertices - 1): for u, v, w in E: if d[u] + w < d[v]: d[v] = d[u] + w for i in range(nvertices - 1): for u, v, w in E: if d[v] > d[u] + w: print("NEGATIVE CYCLE") return for val in d: if math.isinf(val): print("INF") else: print(val) main()
import math def main(): nvertices, nedges, s = list(map(int, input().split())) E = [] for i in range(nedges): u, v, w = list(map(int, input().split())) E.append((u, v, w)) INF = float('inf') weights = [INF] * nvertices weights[s] = 0 for i in range(nvertices - 1): for u, v, w in E: if weights[v] > weights[u] + w: weights[v] = weights[u] + w for u, v, w in E: if weights[v] > weights[u] + w: print("NEGATIVE CYCLE") return for w in weights: if math.isinf(w): print("INF") else: print(w) main()
32
29
683
675
import math def main(): nvertices, nedges, s = list(map(int, input().split())) E = [] for i in range(nedges): u, v, w = list(map(int, input().split())) E.append((u, v, w)) INF = float("inf") d = [INF] * nvertices d[s] = 0 for i in range(nvertices - 1): for u, v, w in E: if d[u] + w < d[v]: d[v] = d[u] + w for i in range(nvertices - 1): for u, v, w in E: if d[v] > d[u] + w: print("NEGATIVE CYCLE") return for val in d: if math.isinf(val): print("INF") else: print(val) main()
import math def main(): nvertices, nedges, s = list(map(int, input().split())) E = [] for i in range(nedges): u, v, w = list(map(int, input().split())) E.append((u, v, w)) INF = float("inf") weights = [INF] * nvertices weights[s] = 0 for i in range(nvertices - 1): for u, v, w in E: if weights[v] > weights[u] + w: weights[v] = weights[u] + w for u, v, w in E: if weights[v] > weights[u] + w: print("NEGATIVE CYCLE") return for w in weights: if math.isinf(w): print("INF") else: print(w) main()
false
9.375
[ "- d = [INF] * nvertices", "- d[s] = 0", "+ weights = [INF] * nvertices", "+ weights[s] = 0", "- if d[u] + w < d[v]:", "- d[v] = d[u] + w", "- for i in range(nvertices - 1):", "- for u, v, w in E:", "- if d[v] > d[u] + w:", "- print(\"NEGATIVE CYCLE\")", "- return", "- for val in d:", "- if math.isinf(val):", "+ if weights[v] > weights[u] + w:", "+ weights[v] = weights[u] + w", "+ for u, v, w in E:", "+ if weights[v] > weights[u] + w:", "+ print(\"NEGATIVE CYCLE\")", "+ return", "+ for w in weights:", "+ if math.isinf(w):", "- print(val)", "+ print(w)" ]
false
0.043339
0.04329
1.00112
[ "s636102279", "s911175958" ]
u057964173
p02831
python
s334849781
s705938561
47
35
5,560
5,044
Accepted
Accepted
25.53
import sys def input(): return sys.stdin.readline().strip() import fractions def resolve(): a, b = list(map(int, input().split())) print(((a * b) // fractions.gcd(a, b))) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): a,b=list(map(int, input().split())) import fractions print((a*b//fractions.gcd(a,b))) resolve()
13
10
199
186
import sys def input(): return sys.stdin.readline().strip() import fractions def resolve(): a, b = list(map(int, input().split())) print(((a * b) // fractions.gcd(a, b))) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): a, b = list(map(int, input().split())) import fractions print((a * b // fractions.gcd(a, b))) resolve()
false
23.076923
[ "-import fractions", "-", "-", "- print(((a * b) // fractions.gcd(a, b)))", "+ import fractions", "+", "+ print((a * b // fractions.gcd(a, b)))" ]
false
0.05861
0.060453
0.969509
[ "s334849781", "s705938561" ]
u420332509
p02553
python
s493278459
s523853778
32
29
9,264
9,216
Accepted
Accepted
9.38
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(eval(input())) def m_in(type_): return list(map(type_, input().split())) def r_in(n, type_): return [type_(eval(input())) for _ in range(n)] ans = None def absmax(a, b): if abs(a) > abs(b): return a return b def absmin(a, b): if abs(a) < abs(b): return a return b a, b, c, d = m_in(int) aa, bb, cc, dd = abs(a), abs(b), abs(c), abs(d) x, y = 0, 0 abm = absmax(a, b) cdm = absmax(c, d) if (abm>0) == (cdm>0): ans = abm*cdm else: abi = absmin(a, b) cdi = absmin(c, d) if (abi>0) == (cdm>0): k = abi*cdm if ans is None or k > ans: ans = k if (abm>0) == (cdi>0): k = abm*cdi if ans is None or k > ans: ans = k k = abi*cdi if ans is None: ans = k print(ans)
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(eval(input())) def m_in(type_): return list(map(type_, input().split())) def r_in(n, type_): return [type_(eval(input())) for _ in range(n)] ans = None a, b, c, d = m_in(int) ans = max(a*c, a*d, b*c, b*d) print(ans)
35
10
831
290
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(eval(input())) def m_in(type_): return list(map(type_, input().split())) def r_in(n, type_): return [type_(eval(input())) for _ in range(n)] ans = None def absmax(a, b): if abs(a) > abs(b): return a return b def absmin(a, b): if abs(a) < abs(b): return a return b a, b, c, d = m_in(int) aa, bb, cc, dd = abs(a), abs(b), abs(c), abs(d) x, y = 0, 0 abm = absmax(a, b) cdm = absmax(c, d) if (abm > 0) == (cdm > 0): ans = abm * cdm else: abi = absmin(a, b) cdi = absmin(c, d) if (abi > 0) == (cdm > 0): k = abi * cdm if ans is None or k > ans: ans = k if (abm > 0) == (cdi > 0): k = abm * cdi if ans is None or k > ans: ans = k k = abi * cdi if ans is None: ans = k print(ans)
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(eval(input())) def m_in(type_): return list(map(type_, input().split())) def r_in(n, type_): return [type_(eval(input())) for _ in range(n)] ans = None a, b, c, d = m_in(int) ans = max(a * c, a * d, b * c, b * d) print(ans)
false
71.428571
[ "-", "-", "-def absmax(a, b):", "- if abs(a) > abs(b):", "- return a", "- return b", "-", "-", "-def absmin(a, b):", "- if abs(a) < abs(b):", "- return a", "- return b", "-", "-", "-aa, bb, cc, dd = abs(a), abs(b), abs(c), abs(d)", "-x, y = 0, 0", "-abm = absmax(a, b)", "-cdm = absmax(c, d)", "-if (abm > 0) == (cdm > 0):", "- ans = abm * cdm", "-else:", "- abi = absmin(a, b)", "- cdi = absmin(c, d)", "- if (abi > 0) == (cdm > 0):", "- k = abi * cdm", "- if ans is None or k > ans:", "- ans = k", "- if (abm > 0) == (cdi > 0):", "- k = abm * cdi", "- if ans is None or k > ans:", "- ans = k", "- k = abi * cdi", "- if ans is None:", "- ans = k", "+ans = max(a * c, a * d, b * c, b * d)" ]
false
0.048453
0.048226
1.004711
[ "s493278459", "s523853778" ]
u389910364
p03242
python
s950046071
s276313270
158
17
13,556
2,940
Accepted
Accepted
89.24
from collections import Counter, deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import sys sys.setrecursionlimit(10000) INF = float('inf') S = eval(input()) print((S.replace('1', 'a').replace('9', '1').replace('a', '9')))
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 n = sys.stdin.buffer.readline().decode().rstrip() for a in n: if a == '9': print(1, end='') if a == '1': print(9, end='') print()
16
20
355
360
from collections import Counter, deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import sys sys.setrecursionlimit(10000) INF = float("inf") S = eval(input()) print((S.replace("1", "a").replace("9", "1").replace("a", "9")))
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 n = sys.stdin.buffer.readline().decode().rstrip() for a in n: if a == "9": print(1, end="") if a == "1": print(9, end="") print()
false
20
[ "-from collections import Counter, deque", "-from fractions import gcd", "-from functools import lru_cache", "-from functools import reduce", "-import functools", "-import heapq", "-import itertools", "-import math", "-import numpy as np", "+import os", "-sys.setrecursionlimit(10000)", "+if os.getenv(\"LOCAL\"):", "+ sys.stdin = open(\"_in.txt\", \"r\")", "+sys.setrecursionlimit(10**9)", "-S = eval(input())", "-print((S.replace(\"1\", \"a\").replace(\"9\", \"1\").replace(\"a\", \"9\")))", "+IINF = 10**18", "+MOD = 10**9 + 7", "+# MOD = 998244353", "+n = sys.stdin.buffer.readline().decode().rstrip()", "+for a in n:", "+ if a == \"9\":", "+ print(1, end=\"\")", "+ if a == \"1\":", "+ print(9, end=\"\")", "+print()" ]
false
0.047703
0.046662
1.022323
[ "s950046071", "s276313270" ]
u695811449
p03354
python
s144893169
s704977073
1,049
871
35,276
35,324
Accepted
Accepted
16.97
N, M = list(map(int,input().split())) P=list(map(int,input().split())) Group=[i for i in range(N+1)] Swap=[None]*M for i in range(M): Swap[i]=sorted(map(int,input().split())) def find(x): while Group[x] != x: x=Group[x] return x for i in range(M): if find(Swap[i][1]) != find(Swap[i][0]): Group[find(Swap[i][1])]=min(find(Swap[i][1]),find(Swap[i][0])) Group[find(Swap[i][0])]=min(find(Swap[i][1]),find(Swap[i][0])) Group[Swap[i][1]]=min(find(Swap[i][1]),find(Swap[i][0])) Group[Swap[i][1]]=min(find(Swap[i][1]),find(Swap[i][0])) count=0 for i in range(N): if find(P[i])==find(i+1): count+=1 print(count)
N,M = list(map(int,input().split())) P = list(map(int,input().split())) S = [list(map(int,input().split())) for i in range(M)] class Union_find(): def __init__(self, N): self.Group = [i for i in range(N)] def find(self,x):# find(a)=find(b)のとき同じグループ while self.Group[x] != x: x = self.Group[x] return x def Union(self,x,y): # xとyが同じグループになるよう更新 if self.find(x) != self.find(y): self.Group[self.find(y)] = self.Group[self.find(x)] = min(self.find(y),self.find(x)) A = Union_find(N) for x,y in S: A.Union(x-1,y-1) ANS = 0 for i in range(N): P[i]-=1 for i in range(N): if A.find(i) == A.find (P[i]): ANS += 1 print(ANS)
30
32
704
745
N, M = list(map(int, input().split())) P = list(map(int, input().split())) Group = [i for i in range(N + 1)] Swap = [None] * M for i in range(M): Swap[i] = sorted(map(int, input().split())) def find(x): while Group[x] != x: x = Group[x] return x for i in range(M): if find(Swap[i][1]) != find(Swap[i][0]): Group[find(Swap[i][1])] = min(find(Swap[i][1]), find(Swap[i][0])) Group[find(Swap[i][0])] = min(find(Swap[i][1]), find(Swap[i][0])) Group[Swap[i][1]] = min(find(Swap[i][1]), find(Swap[i][0])) Group[Swap[i][1]] = min(find(Swap[i][1]), find(Swap[i][0])) count = 0 for i in range(N): if find(P[i]) == find(i + 1): count += 1 print(count)
N, M = list(map(int, input().split())) P = list(map(int, input().split())) S = [list(map(int, input().split())) for i in range(M)] class Union_find: def __init__(self, N): self.Group = [i for i in range(N)] def find(self, x): # find(a)=find(b)のとき同じグループ while self.Group[x] != x: x = self.Group[x] return x def Union(self, x, y): # xとyが同じグループになるよう更新 if self.find(x) != self.find(y): self.Group[self.find(y)] = self.Group[self.find(x)] = min( self.find(y), self.find(x) ) A = Union_find(N) for x, y in S: A.Union(x - 1, y - 1) ANS = 0 for i in range(N): P[i] -= 1 for i in range(N): if A.find(i) == A.find(P[i]): ANS += 1 print(ANS)
false
6.25
[ "-Group = [i for i in range(N + 1)]", "-Swap = [None] * M", "-for i in range(M):", "- Swap[i] = sorted(map(int, input().split()))", "+S = [list(map(int, input().split())) for i in range(M)]", "-def find(x):", "- while Group[x] != x:", "- x = Group[x]", "- return x", "+class Union_find:", "+ def __init__(self, N):", "+ self.Group = [i for i in range(N)]", "+", "+ def find(self, x): # find(a)=find(b)のとき同じグループ", "+ while self.Group[x] != x:", "+ x = self.Group[x]", "+ return x", "+", "+ def Union(self, x, y): # xとyが同じグループになるよう更新", "+ if self.find(x) != self.find(y):", "+ self.Group[self.find(y)] = self.Group[self.find(x)] = min(", "+ self.find(y), self.find(x)", "+ )", "-for i in range(M):", "- if find(Swap[i][1]) != find(Swap[i][0]):", "- Group[find(Swap[i][1])] = min(find(Swap[i][1]), find(Swap[i][0]))", "- Group[find(Swap[i][0])] = min(find(Swap[i][1]), find(Swap[i][0]))", "- Group[Swap[i][1]] = min(find(Swap[i][1]), find(Swap[i][0]))", "- Group[Swap[i][1]] = min(find(Swap[i][1]), find(Swap[i][0]))", "-count = 0", "+A = Union_find(N)", "+for x, y in S:", "+ A.Union(x - 1, y - 1)", "+ANS = 0", "- if find(P[i]) == find(i + 1):", "- count += 1", "-print(count)", "+ P[i] -= 1", "+for i in range(N):", "+ if A.find(i) == A.find(P[i]):", "+ ANS += 1", "+print(ANS)" ]
false
0.037098
0.093419
0.397114
[ "s144893169", "s704977073" ]
u638456847
p03557
python
s945394803
s889878734
376
256
33,344
26,776
Accepted
Accepted
31.91
import numpy as np import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) A = [int(i) for i in readline().split()] B = [int(i) for i in readline().split()] C = [int(i) for i in readline().split()] A = np.array(sorted(A), dtype=np.int64) B = np.array(sorted(B), dtype=np.int64) C = np.array(sorted(C), dtype=np.int64) A_bisect = np.searchsorted(A, B, side="left") C_bisect = np.searchsorted(C, B, side="right") ans = A_bisect * (N - C_bisect) print((ans.sum())) if __name__ == "__main__": main()
import numpy as np import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) A = np.array(readline().split(), dtype=np.int64) B = np.array(readline().split(), dtype=np.int64) C = np.array(readline().split(), dtype=np.int64) A.sort() B.sort() C.sort() A_bisect = np.searchsorted(A, B, side="left") C_bisect = np.searchsorted(C, B, side="right") ans = A_bisect * (N - C_bisect) print((ans.sum())) if __name__ == "__main__": main()
25
25
643
574
import numpy as np import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) A = [int(i) for i in readline().split()] B = [int(i) for i in readline().split()] C = [int(i) for i in readline().split()] A = np.array(sorted(A), dtype=np.int64) B = np.array(sorted(B), dtype=np.int64) C = np.array(sorted(C), dtype=np.int64) A_bisect = np.searchsorted(A, B, side="left") C_bisect = np.searchsorted(C, B, side="right") ans = A_bisect * (N - C_bisect) print((ans.sum())) if __name__ == "__main__": main()
import numpy as np import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) A = np.array(readline().split(), dtype=np.int64) B = np.array(readline().split(), dtype=np.int64) C = np.array(readline().split(), dtype=np.int64) A.sort() B.sort() C.sort() A_bisect = np.searchsorted(A, B, side="left") C_bisect = np.searchsorted(C, B, side="right") ans = A_bisect * (N - C_bisect) print((ans.sum())) if __name__ == "__main__": main()
false
0
[ "- A = [int(i) for i in readline().split()]", "- B = [int(i) for i in readline().split()]", "- C = [int(i) for i in readline().split()]", "- A = np.array(sorted(A), dtype=np.int64)", "- B = np.array(sorted(B), dtype=np.int64)", "- C = np.array(sorted(C), dtype=np.int64)", "+ A = np.array(readline().split(), dtype=np.int64)", "+ B = np.array(readline().split(), dtype=np.int64)", "+ C = np.array(readline().split(), dtype=np.int64)", "+ A.sort()", "+ B.sort()", "+ C.sort()" ]
false
0.23376
0.18994
1.230701
[ "s945394803", "s889878734" ]
u333945892
p03323
python
s099526204
s647892209
29
18
4,212
2,940
Accepted
Accepted
37.93
from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(eval(input())) def inpl(): return list(map(int, input().split())) def inpl_s(): return list(input().split()) atoz = [chr(i) for i in range(97,97+26)] A,B = inpl() if A<=8 and B<=8: print('Yay!') else: print(':(')
A,B = list(map(int, input().split())) if A<=8 and B<=8: print('Yay!') else: print(':(')
16
5
425
93
from collections import defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue, datetime sys.setrecursionlimit(10**8) INF = float("inf") mod = 10**9 + 7 eps = 10**-7 def inp(): return int(eval(input())) def inpl(): return list(map(int, input().split())) def inpl_s(): return list(input().split()) atoz = [chr(i) for i in range(97, 97 + 26)] A, B = inpl() if A <= 8 and B <= 8: print("Yay!") else: print(":(")
A, B = list(map(int, input().split())) if A <= 8 and B <= 8: print("Yay!") else: print(":(")
false
68.75
[ "-from collections import defaultdict, deque", "-import sys, heapq, bisect, math, itertools, string, queue, datetime", "-", "-sys.setrecursionlimit(10**8)", "-INF = float(\"inf\")", "-mod = 10**9 + 7", "-eps = 10**-7", "-", "-", "-def inp():", "- return int(eval(input()))", "-", "-", "-def inpl():", "- return list(map(int, input().split()))", "-", "-", "-def inpl_s():", "- return list(input().split())", "-", "-", "-atoz = [chr(i) for i in range(97, 97 + 26)]", "-A, B = inpl()", "+A, B = list(map(int, input().split()))" ]
false
0.037674
0.033704
1.11781
[ "s099526204", "s647892209" ]
u186838327
p02973
python
s693253730
s219448786
572
197
55,000
84,384
Accepted
Accepted
65.56
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] B = [] import bisect for i, a in enumerate(A): if len(B) == 0: B.append(-a) else: j = bisect.bisect_right(B, -a) #print(j) if j == len(B): B.append(-a) elif j == 0: B[0] = -a else: B[j] = -a #print(B) #print(B) print((len(B)))
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] A.reverse() import bisect B = [10**18] for a in A: i = bisect.bisect_right(B, a) if 0 <= i < len(B): B[i] = a else: B.append(a) print((len(B)))
20
14
395
238
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] B = [] import bisect for i, a in enumerate(A): if len(B) == 0: B.append(-a) else: j = bisect.bisect_right(B, -a) # print(j) if j == len(B): B.append(-a) elif j == 0: B[0] = -a else: B[j] = -a # print(B) # print(B) print((len(B)))
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] A.reverse() import bisect B = [10**18] for a in A: i = bisect.bisect_right(B, a) if 0 <= i < len(B): B[i] = a else: B.append(a) print((len(B)))
false
30
[ "-B = []", "+A.reverse()", "-for i, a in enumerate(A):", "- if len(B) == 0:", "- B.append(-a)", "+B = [10**18]", "+for a in A:", "+ i = bisect.bisect_right(B, a)", "+ if 0 <= i < len(B):", "+ B[i] = a", "- j = bisect.bisect_right(B, -a)", "- # print(j)", "- if j == len(B):", "- B.append(-a)", "- elif j == 0:", "- B[0] = -a", "- else:", "- B[j] = -a", "- # print(B)", "-# print(B)", "+ B.append(a)" ]
false
0.036422
0.101548
0.358669
[ "s693253730", "s219448786" ]
u685983477
p02608
python
s884440942
s747951711
741
110
9,424
74,416
Accepted
Accepted
85.16
def main(): n = int(eval(input())) res = [0]*(n+1) for i in range(1,100): for j in range(1,100): for k in range(1,100): tmp = i**2 + j**2 + k**2 + i*j + j*k + k*i if(tmp<=n): res[tmp]+=1 for i in range(1,n+1): print((res[i])) if __name__ == '__main__': main()
def main(): n = int(eval(input())) res = [0]*(n+1) for i in range(1,100): for j in range(1,100): for k in range(1,100): if(i**2 + j**2 + k**2 +i*j+j*k + k*i<=n): res[i**2 + j**2 + k**2 +i*j+j*k + k*i]+=1 for i in range(1,n+1): print((res[i])) if __name__ == '__main__': main()
18
14
378
388
def main(): n = int(eval(input())) res = [0] * (n + 1) for i in range(1, 100): for j in range(1, 100): for k in range(1, 100): tmp = i**2 + j**2 + k**2 + i * j + j * k + k * i if tmp <= n: res[tmp] += 1 for i in range(1, n + 1): print((res[i])) if __name__ == "__main__": main()
def main(): n = int(eval(input())) res = [0] * (n + 1) for i in range(1, 100): for j in range(1, 100): for k in range(1, 100): if i**2 + j**2 + k**2 + i * j + j * k + k * i <= n: res[i**2 + j**2 + k**2 + i * j + j * k + k * i] += 1 for i in range(1, n + 1): print((res[i])) if __name__ == "__main__": main()
false
22.222222
[ "- tmp = i**2 + j**2 + k**2 + i * j + j * k + k * i", "- if tmp <= n:", "- res[tmp] += 1", "+ if i**2 + j**2 + k**2 + i * j + j * k + k * i <= n:", "+ res[i**2 + j**2 + k**2 + i * j + j * k + k * i] += 1" ]
false
0.936467
0.92955
1.007442
[ "s884440942", "s747951711" ]
u102461423
p02679
python
s194188381
s525580091
1,582
1,162
231,760
174,560
Accepted
Accepted
26.55
import sys from collections import defaultdict from functools import lru_cache read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 P = 2 ** 61 - 1 N = int(readline()) m = list(map(int, read().split())) A, B = list(zip(*list(zip(m, m)))) pow2 = [1] * (N + 10) for n in range(1, N + 10): pow2[n] = pow2[n - 1] * 2 % MOD @lru_cache(None) def inv_mod(a): b = P u, v = 1, 0 while a: t = b // a a, b = b - t * a, a u, v = v - t * u, u if b < 0: v = -v return v % P def to_key(a, b): if a == 0: return -1 x = inv_mod(a) * b % P return x def pair_key(key): if key == -1: return 0 if key == 0: return -1 return P - inv_mod(key) counter = defaultdict(int) origin = 0 for a, b in zip(A, B): if a == b == 0: origin += 1 continue key = to_key(a, b) counter[key] += 1 answer = origin k = 1 for key, cnt in list(counter.items()): key1 = pair_key(key) if key1 not in counter: k *= pow(2, cnt, MOD) elif key < key1: x, y = cnt, counter[key1] k *= pow(2, x, MOD) + pow(2, y, MOD) - 1 k %= MOD answer += k - 1 answer %= MOD print(answer)
import sys from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 P = 2 ** 61 - 1 N = int(readline()) m = list(map(int, read().split())) A, B = list(zip(*list(zip(m, m)))) pow2 = [1] * (N + 10) for n in range(1, N + 10): pow2[n] = pow2[n - 1] * 2 % MOD def inv_mod(a): b = P u, v = 1, 0 while a: t = b // a a, b = b - t * a, a u, v = v - t * u, u if b < 0: v = -v return v % P def to_key(a, b): if a == 0: return -1 x = inv_mod(a) * b % P return x def pair_key(key): if key == -1: return 0 if key == 0: return -1 return P - inv_mod(key) counter = defaultdict(int) origin = 0 for a, b in zip(A, B): if a == b == 0: origin += 1 continue key = to_key(a, b) counter[key] += 1 answer = origin k = 1 for key, cnt in list(counter.items()): key1 = pair_key(key) if key1 not in counter: k *= pow2[cnt] elif key < key1: x, y = cnt, counter[key1] k *= pow2[x] + pow2[y] - 1 k %= MOD answer += k - 1 answer %= MOD print(answer)
66
64
1,312
1,240
import sys from collections import defaultdict from functools import lru_cache read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 P = 2**61 - 1 N = int(readline()) m = list(map(int, read().split())) A, B = list(zip(*list(zip(m, m)))) pow2 = [1] * (N + 10) for n in range(1, N + 10): pow2[n] = pow2[n - 1] * 2 % MOD @lru_cache(None) def inv_mod(a): b = P u, v = 1, 0 while a: t = b // a a, b = b - t * a, a u, v = v - t * u, u if b < 0: v = -v return v % P def to_key(a, b): if a == 0: return -1 x = inv_mod(a) * b % P return x def pair_key(key): if key == -1: return 0 if key == 0: return -1 return P - inv_mod(key) counter = defaultdict(int) origin = 0 for a, b in zip(A, B): if a == b == 0: origin += 1 continue key = to_key(a, b) counter[key] += 1 answer = origin k = 1 for key, cnt in list(counter.items()): key1 = pair_key(key) if key1 not in counter: k *= pow(2, cnt, MOD) elif key < key1: x, y = cnt, counter[key1] k *= pow(2, x, MOD) + pow(2, y, MOD) - 1 k %= MOD answer += k - 1 answer %= MOD print(answer)
import sys from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 P = 2**61 - 1 N = int(readline()) m = list(map(int, read().split())) A, B = list(zip(*list(zip(m, m)))) pow2 = [1] * (N + 10) for n in range(1, N + 10): pow2[n] = pow2[n - 1] * 2 % MOD def inv_mod(a): b = P u, v = 1, 0 while a: t = b // a a, b = b - t * a, a u, v = v - t * u, u if b < 0: v = -v return v % P def to_key(a, b): if a == 0: return -1 x = inv_mod(a) * b % P return x def pair_key(key): if key == -1: return 0 if key == 0: return -1 return P - inv_mod(key) counter = defaultdict(int) origin = 0 for a, b in zip(A, B): if a == b == 0: origin += 1 continue key = to_key(a, b) counter[key] += 1 answer = origin k = 1 for key, cnt in list(counter.items()): key1 = pair_key(key) if key1 not in counter: k *= pow2[cnt] elif key < key1: x, y = cnt, counter[key1] k *= pow2[x] + pow2[y] - 1 k %= MOD answer += k - 1 answer %= MOD print(answer)
false
3.030303
[ "-from functools import lru_cache", "-@lru_cache(None)", "- k *= pow(2, cnt, MOD)", "+ k *= pow2[cnt]", "- k *= pow(2, x, MOD) + pow(2, y, MOD) - 1", "+ k *= pow2[x] + pow2[y] - 1" ]
false
0.08248
0.043734
1.885936
[ "s194188381", "s525580091" ]
u760794812
p02984
python
s438166982
s043230593
140
109
14,092
20,612
Accepted
Accepted
22.14
N = int(eval(input())) List = list(map(int,input().split())) Ans = [0]*N for i in range(N): if i % 2 == 0: Ans[0] += List[i] else: Ans[0] -= List[i] for i in range(1,N): Ans[i] = 2*List[i-1] - Ans[i-1] print((*Ans))
N = int(eval(input())) A = list(map(int,input().split())) ans = [0] for i in range(N): if i%2==0: ans[0] += A[i] else: ans[0] -= A[i] for i in range(N-1): ans.append(2*(A[i] - ans[i]//2)) print((*ans))
11
11
231
217
N = int(eval(input())) List = list(map(int, input().split())) Ans = [0] * N for i in range(N): if i % 2 == 0: Ans[0] += List[i] else: Ans[0] -= List[i] for i in range(1, N): Ans[i] = 2 * List[i - 1] - Ans[i - 1] print((*Ans))
N = int(eval(input())) A = list(map(int, input().split())) ans = [0] for i in range(N): if i % 2 == 0: ans[0] += A[i] else: ans[0] -= A[i] for i in range(N - 1): ans.append(2 * (A[i] - ans[i] // 2)) print((*ans))
false
0
[ "-List = list(map(int, input().split()))", "-Ans = [0] * N", "+A = list(map(int, input().split()))", "+ans = [0]", "- Ans[0] += List[i]", "+ ans[0] += A[i]", "- Ans[0] -= List[i]", "-for i in range(1, N):", "- Ans[i] = 2 * List[i - 1] - Ans[i - 1]", "-print((*Ans))", "+ ans[0] -= A[i]", "+for i in range(N - 1):", "+ ans.append(2 * (A[i] - ans[i] // 2))", "+print((*ans))" ]
false
0.108048
0.113108
0.955262
[ "s438166982", "s043230593" ]
u644907318
p03737
python
s406875443
s908927802
176
29
38,384
8,932
Accepted
Accepted
83.52
s1,s2,s3 = input().strip().split() print((s1[0].upper()+s2[0].upper()+s3[0].upper()))
s1,s2,s3 = input().split() s1 = s1.upper() s2 = s2.upper() s3 = s3.upper() print((s1[0]+s2[0]+s3[0]))
2
5
84
103
s1, s2, s3 = input().strip().split() print((s1[0].upper() + s2[0].upper() + s3[0].upper()))
s1, s2, s3 = input().split() s1 = s1.upper() s2 = s2.upper() s3 = s3.upper() print((s1[0] + s2[0] + s3[0]))
false
60
[ "-s1, s2, s3 = input().strip().split()", "-print((s1[0].upper() + s2[0].upper() + s3[0].upper()))", "+s1, s2, s3 = input().split()", "+s1 = s1.upper()", "+s2 = s2.upper()", "+s3 = s3.upper()", "+print((s1[0] + s2[0] + s3[0]))" ]
false
0.080662
0.043975
1.834294
[ "s406875443", "s908927802" ]
u667084803
p03132
python
s989572717
s583930588
1,355
1,097
74,104
11,040
Accepted
Accepted
19.04
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d #2019-02-10 #DP L = int(eval(input())) A = [int(eval(input())) for i in range(L)] DP = [[0 for i in range(5)] for j in range(L+1)] def cost(s, a): if s == 0 or s == 4: return a elif s == 1 or s == 3: if a > 0: return a%2 else: return 2 else: return (a+1)%2 for i in range(L): a = A[i] DP[i+1][0] = min(DP[i][:1]) + cost(0, a) DP[i+1][1] = min(DP[i][:2]) + cost(1, a) DP[i+1][2] = min(DP[i][:3]) + cost(2, a) DP[i+1][3] = min(DP[i][:4]) + cost(3, a) DP[i+1][4] = min(DP[i][:5]) + cost(4, a) print((min(DP[L])))
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d #2019-02-10 #DP L = int(eval(input())) A = [int(eval(input())) for i in range(L)] DP = [0 for i in range(5)] def cost(s, a): if s == 0 or s == 4: return a elif s == 1 or s == 3: if a > 0: return a%2 else: return 2 else: return (a+1)%2 for i in range(L): n = [min(DP[:i+1]) for i in range(5)] a = A[i] DP[0] = n[0] + cost(0, a) DP[1] = n[1] + cost(1, a) DP[2] = n[2] + cost(2, a) DP[3] = n[3] + cost(3, a) DP[4] = n[4] + cost(4, a) print((min(DP)))
32
33
707
650
# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d # 2019-02-10 # DP L = int(eval(input())) A = [int(eval(input())) for i in range(L)] DP = [[0 for i in range(5)] for j in range(L + 1)] def cost(s, a): if s == 0 or s == 4: return a elif s == 1 or s == 3: if a > 0: return a % 2 else: return 2 else: return (a + 1) % 2 for i in range(L): a = A[i] DP[i + 1][0] = min(DP[i][:1]) + cost(0, a) DP[i + 1][1] = min(DP[i][:2]) + cost(1, a) DP[i + 1][2] = min(DP[i][:3]) + cost(2, a) DP[i + 1][3] = min(DP[i][:4]) + cost(3, a) DP[i + 1][4] = min(DP[i][:5]) + cost(4, a) print((min(DP[L])))
# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d # 2019-02-10 # DP L = int(eval(input())) A = [int(eval(input())) for i in range(L)] DP = [0 for i in range(5)] def cost(s, a): if s == 0 or s == 4: return a elif s == 1 or s == 3: if a > 0: return a % 2 else: return 2 else: return (a + 1) % 2 for i in range(L): n = [min(DP[: i + 1]) for i in range(5)] a = A[i] DP[0] = n[0] + cost(0, a) DP[1] = n[1] + cost(1, a) DP[2] = n[2] + cost(2, a) DP[3] = n[3] + cost(3, a) DP[4] = n[4] + cost(4, a) print((min(DP)))
false
3.030303
[ "-DP = [[0 for i in range(5)] for j in range(L + 1)]", "+DP = [0 for i in range(5)]", "+ n = [min(DP[: i + 1]) for i in range(5)]", "- DP[i + 1][0] = min(DP[i][:1]) + cost(0, a)", "- DP[i + 1][1] = min(DP[i][:2]) + cost(1, a)", "- DP[i + 1][2] = min(DP[i][:3]) + cost(2, a)", "- DP[i + 1][3] = min(DP[i][:4]) + cost(3, a)", "- DP[i + 1][4] = min(DP[i][:5]) + cost(4, a)", "-print((min(DP[L])))", "+ DP[0] = n[0] + cost(0, a)", "+ DP[1] = n[1] + cost(1, a)", "+ DP[2] = n[2] + cost(2, a)", "+ DP[3] = n[3] + cost(3, a)", "+ DP[4] = n[4] + cost(4, a)", "+print((min(DP)))" ]
false
0.042899
0.042652
1.005773
[ "s989572717", "s583930588" ]
u952467214
p03167
python
s306890503
s079873989
1,599
794
43,628
47,112
Accepted
Accepted
50.34
import sys input = sys.stdin.readline H, W = list(map(int, input().split())) MOD = 10 ** 9 + 7 A = [eval(input()) for _ in range(H)] dp = [[0]*W for _ in range(H)] dp[0][0] = 1 for y in range(H): for x in range(W): if y+1 < H and A[y+1][x] == '.': dp[y+1][x] += dp[y][x] dp[y+1][x] = dp[y+1][x] % MOD if x+1 < W and A[y][x+1] == '.': dp[y][x+1] += dp[y][x] dp[y][x+1] = dp[y][x+1] % MOD print((dp[H-1][W-1]))
p = 10**9+7 h, w = list(map(int, input().split())) maze = [[-1 for i in range(w)] for j in range(h)] ans = 0 for i in range(h): maze[i] = eval(input()) dp = [[0]*(w+1) for _ in range(h+1)] dp[1][1] = 1 for i in range(1,h+1): for j in range(1,w+1): if maze[i-1][j-1] == '.': dp[i][j] += dp[i-1][j]%p + dp[i][j-1]%p ans = dp[h][w]%p print(ans)
21
20
454
382
import sys input = sys.stdin.readline H, W = list(map(int, input().split())) MOD = 10**9 + 7 A = [eval(input()) for _ in range(H)] dp = [[0] * W for _ in range(H)] dp[0][0] = 1 for y in range(H): for x in range(W): if y + 1 < H and A[y + 1][x] == ".": dp[y + 1][x] += dp[y][x] dp[y + 1][x] = dp[y + 1][x] % MOD if x + 1 < W and A[y][x + 1] == ".": dp[y][x + 1] += dp[y][x] dp[y][x + 1] = dp[y][x + 1] % MOD print((dp[H - 1][W - 1]))
p = 10**9 + 7 h, w = list(map(int, input().split())) maze = [[-1 for i in range(w)] for j in range(h)] ans = 0 for i in range(h): maze[i] = eval(input()) dp = [[0] * (w + 1) for _ in range(h + 1)] dp[1][1] = 1 for i in range(1, h + 1): for j in range(1, w + 1): if maze[i - 1][j - 1] == ".": dp[i][j] += dp[i - 1][j] % p + dp[i][j - 1] % p ans = dp[h][w] % p print(ans)
false
4.761905
[ "-import sys", "-", "-input = sys.stdin.readline", "-H, W = list(map(int, input().split()))", "-MOD = 10**9 + 7", "-A = [eval(input()) for _ in range(H)]", "-dp = [[0] * W for _ in range(H)]", "-dp[0][0] = 1", "-for y in range(H):", "- for x in range(W):", "- if y + 1 < H and A[y + 1][x] == \".\":", "- dp[y + 1][x] += dp[y][x]", "- dp[y + 1][x] = dp[y + 1][x] % MOD", "- if x + 1 < W and A[y][x + 1] == \".\":", "- dp[y][x + 1] += dp[y][x]", "- dp[y][x + 1] = dp[y][x + 1] % MOD", "-print((dp[H - 1][W - 1]))", "+p = 10**9 + 7", "+h, w = list(map(int, input().split()))", "+maze = [[-1 for i in range(w)] for j in range(h)]", "+ans = 0", "+for i in range(h):", "+ maze[i] = eval(input())", "+dp = [[0] * (w + 1) for _ in range(h + 1)]", "+dp[1][1] = 1", "+for i in range(1, h + 1):", "+ for j in range(1, w + 1):", "+ if maze[i - 1][j - 1] == \".\":", "+ dp[i][j] += dp[i - 1][j] % p + dp[i][j - 1] % p", "+ans = dp[h][w] % p", "+print(ans)" ]
false
0.053376
0.037409
1.426821
[ "s306890503", "s079873989" ]
u498575211
p02910
python
s983586804
s028757551
19
17
2,940
2,940
Accepted
Accepted
10.53
S = eval(input()) k = 'Yes' for i in range(len(S)): if i % 2 == 0: if S[i] == 'L': k = 'No' break else: if S[i] == 'R': k = 'No' break print(k)
S = eval(input()) result = 'Yes' for i in range(1, len(S)+1): #print(i) if (i % 2 == 0 and S[i-1] == "R") or (i % 2 == 1 and S[i-1] == "L"): result = 'No' break print(result)
14
10
173
208
S = eval(input()) k = "Yes" for i in range(len(S)): if i % 2 == 0: if S[i] == "L": k = "No" break else: if S[i] == "R": k = "No" break print(k)
S = eval(input()) result = "Yes" for i in range(1, len(S) + 1): # print(i) if (i % 2 == 0 and S[i - 1] == "R") or (i % 2 == 1 and S[i - 1] == "L"): result = "No" break print(result)
false
28.571429
[ "-k = \"Yes\"", "-for i in range(len(S)):", "- if i % 2 == 0:", "- if S[i] == \"L\":", "- k = \"No\"", "- break", "- else:", "- if S[i] == \"R\":", "- k = \"No\"", "- break", "-print(k)", "+result = \"Yes\"", "+for i in range(1, len(S) + 1):", "+ # print(i)", "+ if (i % 2 == 0 and S[i - 1] == \"R\") or (i % 2 == 1 and S[i - 1] == \"L\"):", "+ result = \"No\"", "+ break", "+print(result)" ]
false
0.043744
0.04566
0.958034
[ "s983586804", "s028757551" ]
u047796752
p03148
python
s244054152
s345530570
617
520
84,700
72,028
Accepted
Accepted
15.72
import sys input = sys.stdin.readline from collections import * from heapq import * N, K = list(map(int, input().split())) td = [tuple(map(int, input().split())) for _ in range(N)] td.sort(key=lambda t: t[1], reverse=True) d = defaultdict(list) now = 0 for ti, di in td[:K]: d[ti].append(di) now += di remove = [] for k in list(d.keys()): d[k].sort(reverse=True) for i in range(1, len(d[k])): heappush(remove, d[k][i]) s = set(list(d.keys())) add = [] for ti, di in td: if ti in s: continue s.add(ti) heappush(add, -di) x = len(d) ans = now+x**2 while len(remove)>0 and len(add)>0: now -= heappop(remove) now -= heappop(add) x += 1 ans = max(ans, now+x**2) print(ans)
import sys input = sys.stdin.readline from collections import * N, K = list(map(int, input().split())) td = [tuple(map(int, input().split())) for _ in range(N)] td.sort(key=lambda t: t[1], reverse=True) d = defaultdict(list) now = 0 for ti, di in td[:K]: d[ti].append(di) now += di rem = [] for k in list(d.keys()): d[k].sort(reverse=True) for i in range(1, len(d[k])): rem.append(d[k][i]) add = [] s = set() for ti, di in td[K:]: if ti not in d and ti not in s: add.append(di) s.add(ti) rem.sort() add.sort(reverse=True) var = len(list(d.keys())) ans = now+var**2 for i in range(min(len(rem), len(add))): now -= rem[i] now += add[i] ans = max(ans, now+(var+i+1)**2) print(ans)
43
41
780
775
import sys input = sys.stdin.readline from collections import * from heapq import * N, K = list(map(int, input().split())) td = [tuple(map(int, input().split())) for _ in range(N)] td.sort(key=lambda t: t[1], reverse=True) d = defaultdict(list) now = 0 for ti, di in td[:K]: d[ti].append(di) now += di remove = [] for k in list(d.keys()): d[k].sort(reverse=True) for i in range(1, len(d[k])): heappush(remove, d[k][i]) s = set(list(d.keys())) add = [] for ti, di in td: if ti in s: continue s.add(ti) heappush(add, -di) x = len(d) ans = now + x**2 while len(remove) > 0 and len(add) > 0: now -= heappop(remove) now -= heappop(add) x += 1 ans = max(ans, now + x**2) print(ans)
import sys input = sys.stdin.readline from collections import * N, K = list(map(int, input().split())) td = [tuple(map(int, input().split())) for _ in range(N)] td.sort(key=lambda t: t[1], reverse=True) d = defaultdict(list) now = 0 for ti, di in td[:K]: d[ti].append(di) now += di rem = [] for k in list(d.keys()): d[k].sort(reverse=True) for i in range(1, len(d[k])): rem.append(d[k][i]) add = [] s = set() for ti, di in td[K:]: if ti not in d and ti not in s: add.append(di) s.add(ti) rem.sort() add.sort(reverse=True) var = len(list(d.keys())) ans = now + var**2 for i in range(min(len(rem), len(add))): now -= rem[i] now += add[i] ans = max(ans, now + (var + i + 1) ** 2) print(ans)
false
4.651163
[ "-from heapq import *", "-remove = []", "+rem = []", "- heappush(remove, d[k][i])", "-s = set(list(d.keys()))", "+ rem.append(d[k][i])", "-for ti, di in td:", "- if ti in s:", "- continue", "- s.add(ti)", "- heappush(add, -di)", "-x = len(d)", "-ans = now + x**2", "-while len(remove) > 0 and len(add) > 0:", "- now -= heappop(remove)", "- now -= heappop(add)", "- x += 1", "- ans = max(ans, now + x**2)", "+s = set()", "+for ti, di in td[K:]:", "+ if ti not in d and ti not in s:", "+ add.append(di)", "+ s.add(ti)", "+rem.sort()", "+add.sort(reverse=True)", "+var = len(list(d.keys()))", "+ans = now + var**2", "+for i in range(min(len(rem), len(add))):", "+ now -= rem[i]", "+ now += add[i]", "+ ans = max(ans, now + (var + i + 1) ** 2)" ]
false
0.038909
0.067765
0.574168
[ "s244054152", "s345530570" ]
u029000441
p02756
python
s952802558
s929224376
1,082
139
51,840
92,004
Accepted
Accepted
87.15
import sys S =eval(input()) Q=int(eval(input())) orders=[] for line in sys.stdin.readlines(): orders.append(line.rstrip().split(" ")) dire=1 right="" left="" center="" for order in orders: if order[0]=="1": dire=dire*(-1) center=right right=left left=center elif order[0]=="2" and order[1]=="1": if dire==1: left=order[2]+left if dire==-1: left=left+order[2] elif order[0]=="2" and order[1]=="2": if dire==1: right=right+order[2] if dire==-1: right=order[2]+right if dire==1: S=S right=right left=left elif dire==-1: S=S[::-1] right=right[::-1] left=left[::-1] print((left+S+right))
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print(('\n'.join(x))) def printni(x): print(('\n'.join(list(map(str,x))))) inf = 10**17 mod = 10**9 + 7 #main code here! s=SI() turn=0 q=I() ortop=[] orbot=[] for i in range(q): query=list(input().rstrip().split(" ")) if query[0]=="1": turn=(turn+1)%2 else: x=int(query[1]) if (x+turn)%2==1: ortop.append(query[2]) else: orbot.append(query[2]) if turn%2==0: s1="".join(list(reversed(ortop))) s2="".join(orbot) print((s1+s+s2)) else: s1="".join(list(reversed(orbot))) s2="".join(ortop) s="".join(list(reversed(s))) print((s1+s+s2)) if __name__=="__main__": main()
35
62
754
1,672
import sys S = eval(input()) Q = int(eval(input())) orders = [] for line in sys.stdin.readlines(): orders.append(line.rstrip().split(" ")) dire = 1 right = "" left = "" center = "" for order in orders: if order[0] == "1": dire = dire * (-1) center = right right = left left = center elif order[0] == "2" and order[1] == "1": if dire == 1: left = order[2] + left if dire == -1: left = left + order[2] elif order[0] == "2" and order[1] == "2": if dire == 1: right = right + order[2] if dire == -1: right = order[2] + right if dire == 1: S = S right = right left = left elif dire == -1: S = S[::-1] right = right[::-1] left = left[::-1] print((left + S + right))
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left, bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil, pi, factorial from operator import itemgetter def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI2(): return [int(eval(input())) for i in range(n)] def MXI(): return [[LI()] for i in range(n)] def SI(): return input().rstrip() def printns(x): print(("\n".join(x))) def printni(x): print(("\n".join(list(map(str, x))))) inf = 10**17 mod = 10**9 + 7 # main code here! s = SI() turn = 0 q = I() ortop = [] orbot = [] for i in range(q): query = list(input().rstrip().split(" ")) if query[0] == "1": turn = (turn + 1) % 2 else: x = int(query[1]) if (x + turn) % 2 == 1: ortop.append(query[2]) else: orbot.append(query[2]) if turn % 2 == 0: s1 = "".join(list(reversed(ortop))) s2 = "".join(orbot) print((s1 + s + s2)) else: s1 = "".join(list(reversed(orbot))) s2 = "".join(ortop) s = "".join(list(reversed(s))) print((s1 + s + s2)) if __name__ == "__main__": main()
false
43.548387
[ "-import sys", "+def main():", "+ import sys", "-S = eval(input())", "-Q = int(eval(input()))", "-orders = []", "-for line in sys.stdin.readlines():", "- orders.append(line.rstrip().split(\" \"))", "-dire = 1", "-right = \"\"", "-left = \"\"", "-center = \"\"", "-for order in orders:", "- if order[0] == \"1\":", "- dire = dire * (-1)", "- center = right", "- right = left", "- left = center", "- elif order[0] == \"2\" and order[1] == \"1\":", "- if dire == 1:", "- left = order[2] + left", "- if dire == -1:", "- left = left + order[2]", "- elif order[0] == \"2\" and order[1] == \"2\":", "- if dire == 1:", "- right = right + order[2]", "- if dire == -1:", "- right = order[2] + right", "-if dire == 1:", "- S = S", "- right = right", "- left = left", "-elif dire == -1:", "- S = S[::-1]", "- right = right[::-1]", "- left = left[::-1]", "-print((left + S + right))", "+ input = sys.stdin.readline", "+ sys.setrecursionlimit(10**7)", "+ from collections import Counter, deque", "+ from collections import defaultdict", "+ from itertools import combinations, permutations, accumulate, groupby, product", "+ from bisect import bisect_left, bisect_right", "+ from heapq import heapify, heappop, heappush", "+ from math import floor, ceil, pi, factorial", "+ from operator import itemgetter", "+", "+ def I():", "+ return int(eval(input()))", "+", "+ def MI():", "+ return list(map(int, input().split()))", "+", "+ def LI():", "+ return list(map(int, input().split()))", "+", "+ def LI2():", "+ return [int(eval(input())) for i in range(n)]", "+", "+ def MXI():", "+ return [[LI()] for i in range(n)]", "+", "+ def SI():", "+ return input().rstrip()", "+", "+ def printns(x):", "+ print((\"\\n\".join(x)))", "+", "+ def printni(x):", "+ print((\"\\n\".join(list(map(str, x)))))", "+", "+ inf = 10**17", "+ mod = 10**9 + 7", "+ # main code here!", "+ s = SI()", "+ turn = 0", "+ q = I()", "+ ortop = []", "+ orbot = []", "+ for i in range(q):", "+ query = list(input().rstrip().split(\" \"))", "+ if query[0] == \"1\":", "+ turn = (turn + 1) % 2", "+ else:", "+ x = int(query[1])", "+ if (x + turn) % 2 == 1:", "+ ortop.append(query[2])", "+ else:", "+ orbot.append(query[2])", "+ if turn % 2 == 0:", "+ s1 = \"\".join(list(reversed(ortop)))", "+ s2 = \"\".join(orbot)", "+ print((s1 + s + s2))", "+ else:", "+ s1 = \"\".join(list(reversed(orbot)))", "+ s2 = \"\".join(ortop)", "+ s = \"\".join(list(reversed(s)))", "+ print((s1 + s + s2))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.058174
0.042959
1.354174
[ "s952802558", "s929224376" ]
u476604182
p03332
python
s668071891
s092715611
1,841
486
124,100
127,560
Accepted
Accepted
73.6
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) N, A, B, K = list(map(int, input().split())) ans = 0 for i in range(N+1): m = K-A*i if m%B!=0: continue ans += cmb(N,i,mod)*cmb(N,m//B,mod) ans %= mod print(ans)
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) N,A,B,K = list(map(int, input().split())) ans = 0 for i in range(N+1): if (K-A*i)%B!=0: continue j = (K-A*i)//B m = cmb(N,i,mod)*cmb(N,j,mod)%mod ans += m ans %= mod print(ans)
27
27
596
612
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 998244353 # 出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) N, A, B, K = list(map(int, input().split())) ans = 0 for i in range(N + 1): m = K - A * i if m % B != 0: continue ans += cmb(N, i, mod) * cmb(N, m // B, mod) ans %= mod print(ans)
def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 998244353 # 出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) N, A, B, K = list(map(int, input().split())) ans = 0 for i in range(N + 1): if (K - A * i) % B != 0: continue j = (K - A * i) // B m = cmb(N, i, mod) * cmb(N, j, mod) % mod ans += m ans %= mod print(ans)
false
0
[ "- m = K - A * i", "- if m % B != 0:", "+ if (K - A * i) % B != 0:", "- ans += cmb(N, i, mod) * cmb(N, m // B, mod)", "+ j = (K - A * i) // B", "+ m = cmb(N, i, mod) * cmb(N, j, mod) % mod", "+ ans += m" ]
false
2.842523
1.495832
1.900296
[ "s668071891", "s092715611" ]
u256678932
p02416
python
s144410896
s630087057
30
20
7,628
5,608
Accepted
Accepted
33.33
from sys import stdin for l in stdin: l = l.rstrip() if 0 == int(l): break print((sum([int(ch) for ch in l])))
def main(): while True: num = eval(input()) if num == "0": break print((sum([int(x) for x in num]))) if __name__ == '__main__': main()
8
11
137
184
from sys import stdin for l in stdin: l = l.rstrip() if 0 == int(l): break print((sum([int(ch) for ch in l])))
def main(): while True: num = eval(input()) if num == "0": break print((sum([int(x) for x in num]))) if __name__ == "__main__": main()
false
27.272727
[ "-from sys import stdin", "+def main():", "+ while True:", "+ num = eval(input())", "+ if num == \"0\":", "+ break", "+ print((sum([int(x) for x in num])))", "-for l in stdin:", "- l = l.rstrip()", "- if 0 == int(l):", "- break", "- print((sum([int(ch) for ch in l])))", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.04985
0.050199
0.99305
[ "s144410896", "s630087057" ]
u401452016
p03031
python
s539471220
s119649114
32
24
3,316
3,316
Accepted
Accepted
25
#ABC 128C def main(): import sys import itertools as ite N, M = list(map(int, sys.stdin.readline().split())) Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] P = list(map(int, sys.stdin.readline().split())) S = list(ite.product([0,1], repeat=N)) #スイッチの状態 ans = 0 for s_state in S: L_result = [0 for _ in range(M)] for m in range(M): for s_no in Light[m][1:]: L_result[m] += s_state[s_no-1] L_result = list([x%2 for x in L_result]) if P == L_result: ans +=1 print(ans) if __name__=='__main__': main()
#ABC128C def main(): import sys, itertools as ite N, M = list(map(int, sys.stdin.readline().split())) KS = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] P = tuple(map(int, sys.stdin.readline().split())) #print(KS) #bit全探索 SWS = tuple(ite.product([0,1], repeat=N)) def judge(on_off): for i in range(M): on_cnt = 0 for s in KS[i][1:]: on_cnt += on_off[s-1] if on_cnt %2 !=P[i]: return 0 else: return 1 ans = 0 for on_off in SWS: ans +=judge(on_off) print(ans) if __name__=='__main__': main()
21
32
656
704
# ABC 128C def main(): import sys import itertools as ite N, M = list(map(int, sys.stdin.readline().split())) Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] P = list(map(int, sys.stdin.readline().split())) S = list(ite.product([0, 1], repeat=N)) # スイッチの状態 ans = 0 for s_state in S: L_result = [0 for _ in range(M)] for m in range(M): for s_no in Light[m][1:]: L_result[m] += s_state[s_no - 1] L_result = list([x % 2 for x in L_result]) if P == L_result: ans += 1 print(ans) if __name__ == "__main__": main()
# ABC128C def main(): import sys, itertools as ite N, M = list(map(int, sys.stdin.readline().split())) KS = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] P = tuple(map(int, sys.stdin.readline().split())) # print(KS) # bit全探索 SWS = tuple(ite.product([0, 1], repeat=N)) def judge(on_off): for i in range(M): on_cnt = 0 for s in KS[i][1:]: on_cnt += on_off[s - 1] if on_cnt % 2 != P[i]: return 0 else: return 1 ans = 0 for on_off in SWS: ans += judge(on_off) print(ans) if __name__ == "__main__": main()
false
34.375
[ "-# ABC 128C", "+# ABC128C", "- import sys", "- import itertools as ite", "+ import sys, itertools as ite", "- Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]", "- P = list(map(int, sys.stdin.readline().split()))", "- S = list(ite.product([0, 1], repeat=N)) # スイッチの状態", "+ KS = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]", "+ P = tuple(map(int, sys.stdin.readline().split()))", "+ # print(KS)", "+ # bit全探索", "+ SWS = tuple(ite.product([0, 1], repeat=N))", "+", "+ def judge(on_off):", "+ for i in range(M):", "+ on_cnt = 0", "+ for s in KS[i][1:]:", "+ on_cnt += on_off[s - 1]", "+ if on_cnt % 2 != P[i]:", "+ return 0", "+ else:", "+ return 1", "+", "- for s_state in S:", "- L_result = [0 for _ in range(M)]", "- for m in range(M):", "- for s_no in Light[m][1:]:", "- L_result[m] += s_state[s_no - 1]", "- L_result = list([x % 2 for x in L_result])", "- if P == L_result:", "- ans += 1", "+ for on_off in SWS:", "+ ans += judge(on_off)" ]
false
0.043472
0.037514
1.158847
[ "s539471220", "s119649114" ]
u156815136
p02899
python
s186714170
s257935918
218
173
23,480
27,252
Accepted
Accepted
20.64
#from statistics import median #import collections #aa = collections.Counter(a) # list to list #from itertools import combinations # (string,3) 3回 # # # pythonで無理なときは、pypyでやると正解するかも!! # # mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): n = int(eval(input())) A = list(zip(list(map(int,input().split())), list(range(1,n+1)))) print((*[a[1] for a in sorted(A)])) if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) n = I() A = readInts() nya = [] for i in range(n): nya.append((i+1,A[i])) nya = sorted(nya,key = lambda x:x[1]) ans = [] for (idx,po) in nya: ans.append(idx) print((*ans))
20
39
440
910
# from statistics import median # import collections # aa = collections.Counter(a) # list to list # from itertools import combinations # (string,3) 3回 # # # pythonで無理なときは、pypyでやると正解するかも!! # # mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): n = int(eval(input())) A = list(zip(list(map(int, input().split())), list(range(1, n + 1)))) print((*[a[1] for a in sorted(A)])) if __name__ == "__main__": main()
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations, permutations, accumulate # (string,3) 3回 # from collections import deque from collections import deque, defaultdict, Counter import decimal import re # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) n = I() A = readInts() nya = [] for i in range(n): nya.append((i + 1, A[i])) nya = sorted(nya, key=lambda x: x[1]) ans = [] for (idx, po) in nya: ans.append(idx) print((*ans))
false
48.717949
[ "-# aa = collections.Counter(a) # list to list", "-# from itertools import combinations # (string,3) 3回", "+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]", "+from fractions import gcd", "+from itertools import combinations, permutations, accumulate # (string,3) 3回", "+", "+# from collections import deque", "+from collections import deque, defaultdict, Counter", "+import decimal", "+import re", "+", "+# import bisect", "+#", "+# d = m - k[i] - k[j]", "+# if kk[bisect.bisect_right(kk,d) - 1] == d:", "+#", "+# my_round_int = lambda x:np.round((x*2 + 1)//2)", "+# 四捨五入", "+import sys", "+", "+sys.setrecursionlimit(10000000)", "-", "-", "+# mod = 9982443453", "-def main():", "- n = int(eval(input()))", "- A = list(zip(list(map(int, input().split())), list(range(1, n + 1))))", "- print((*[a[1] for a in sorted(A)]))", "+def I():", "+ return int(eval(input()))", "-if __name__ == \"__main__\":", "- main()", "+n = I()", "+A = readInts()", "+nya = []", "+for i in range(n):", "+ nya.append((i + 1, A[i]))", "+nya = sorted(nya, key=lambda x: x[1])", "+ans = []", "+for (idx, po) in nya:", "+ ans.append(idx)", "+print((*ans))" ]
false
0.037392
0.04093
0.91356
[ "s186714170", "s257935918" ]
u230621983
p03821
python
s205931236
s008933550
384
256
11,048
28,168
Accepted
Accepted
33.33
n = int(eval(input())) a_li = [] b_li = [] for _ in range(n): a,b = list(map(int, input().split())) a_li.append(a) b_li.append(b) cnt = 0 for i in range(1,n+1): if (a_li[-i]+cnt) % b_li[-i] != 0: cnt += b_li[-i] - ((a_li[-i]+cnt) % b_li[-i]) print(cnt)
n = int(eval(input())) cnt = 0 ab_l = [list(map(int, input().split())) for _ in range(n)] for ab in ab_l[::-1]: a, b = ab[0], ab[1] a += cnt if a % b != 0: cnt += b - a%b print(cnt)
13
9
278
203
n = int(eval(input())) a_li = [] b_li = [] for _ in range(n): a, b = list(map(int, input().split())) a_li.append(a) b_li.append(b) cnt = 0 for i in range(1, n + 1): if (a_li[-i] + cnt) % b_li[-i] != 0: cnt += b_li[-i] - ((a_li[-i] + cnt) % b_li[-i]) print(cnt)
n = int(eval(input())) cnt = 0 ab_l = [list(map(int, input().split())) for _ in range(n)] for ab in ab_l[::-1]: a, b = ab[0], ab[1] a += cnt if a % b != 0: cnt += b - a % b print(cnt)
false
30.769231
[ "-a_li = []", "-b_li = []", "-for _ in range(n):", "- a, b = list(map(int, input().split()))", "- a_li.append(a)", "- b_li.append(b)", "-for i in range(1, n + 1):", "- if (a_li[-i] + cnt) % b_li[-i] != 0:", "- cnt += b_li[-i] - ((a_li[-i] + cnt) % b_li[-i])", "+ab_l = [list(map(int, input().split())) for _ in range(n)]", "+for ab in ab_l[::-1]:", "+ a, b = ab[0], ab[1]", "+ a += cnt", "+ if a % b != 0:", "+ cnt += b - a % b" ]
false
0.0657
0.068422
0.960217
[ "s205931236", "s008933550" ]
u856775981
p02725
python
s110878142
s896897494
231
83
34,168
26,444
Accepted
Accepted
64.07
import numpy as np K, N = list(map(int, input().split())) a = np.array(list(map(int, input().split()))) print((K - max(np.diff(np.append(a, a[0] + K)))))
from operator import sub K, N = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + K) print((K - max(list(map(sub, a[1:], a[:-1])))))
6
7
159
172
import numpy as np K, N = list(map(int, input().split())) a = np.array(list(map(int, input().split()))) print((K - max(np.diff(np.append(a, a[0] + K)))))
from operator import sub K, N = list(map(int, input().split())) a = list(map(int, input().split())) a.append(a[0] + K) print((K - max(list(map(sub, a[1:], a[:-1])))))
false
14.285714
[ "-import numpy as np", "+from operator import sub", "-a = np.array(list(map(int, input().split())))", "-print((K - max(np.diff(np.append(a, a[0] + K)))))", "+a = list(map(int, input().split()))", "+a.append(a[0] + K)", "+print((K - max(list(map(sub, a[1:], a[:-1])))))" ]
false
0.400917
0.076433
5.245319
[ "s110878142", "s896897494" ]
u729133443
p03666
python
s002127861
s731206844
259
205
3,060
3,060
Accepted
Accepted
20.85
n,a,b,c,d=list(map(int,input().split())) f=0 for i in range(n):f|=i*c-(~i+n)*d<=b-a<=i*d-(~i+n)*c print(('NYOE S'[f::2]))
n,a,b,c,d=list(map(int,input().split()));print(('NYOE S'[any(c*i-d*(~i+n)<=b-a<=d*i-c*(~i+n)for i in range(n))::2]))
4
1
116
108
n, a, b, c, d = list(map(int, input().split())) f = 0 for i in range(n): f |= i * c - (~i + n) * d <= b - a <= i * d - (~i + n) * c print(("NYOE S"[f::2]))
n, a, b, c, d = list(map(int, input().split())) print( ( "NYOE S"[ any( c * i - d * (~i + n) <= b - a <= d * i - c * (~i + n) for i in range(n) ) :: 2 ] ) )
false
75
[ "-f = 0", "-for i in range(n):", "- f |= i * c - (~i + n) * d <= b - a <= i * d - (~i + n) * c", "-print((\"NYOE S\"[f::2]))", "+print(", "+ (", "+ \"NYOE S\"[", "+ any(", "+ c * i - d * (~i + n) <= b - a <= d * i - c * (~i + n) for i in range(n)", "+ ) :: 2", "+ ]", "+ )", "+)" ]
false
0.135296
0.096901
1.396224
[ "s002127861", "s731206844" ]
u952708174
p02680
python
s901557374
s607047763
2,751
2,447
713,648
713,580
Accepted
Accepted
11.05
def f_single_dot(): # https://atcoder.jp/contests/abc168/submissions/13368489 import sys from collections import deque input = sys.stdin.readline N, M = [int(i) for i in input().split()] x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要) vertical_lines = [] for _ in range(N): a, b, c = list(map(int, input().split())) vertical_lines.append((a, b, c)) x_set |= {a, b} y_set |= {c} horizontal_lines = [] for _ in range(M): d, e, f = list(map(int, input().split())) horizontal_lines.append((d, e, f)) x_set |= {d} y_set |= {e, f} x_set = sorted(x_set) y_set = sorted(y_set) # 座標圧縮 (壁も配列に格納するので、2 倍している) x_encoded = {n: i * 2 for i, n in enumerate(x_set)} y_encoded = {n: i * 2 for i, n in enumerate(y_set)} # 座標圧縮されたグリッドで縦横に 1 マス分進むことは実際にはどれくらい進んだことなのか x_length = [x_set[i // 2 + 1] - x_set[i // 2] if i % 2 else 0 for i in range(len(x_set) * 2 - 1)] y_length = [y_set[i // 2 + 1] - y_set[i // 2] if i % 2 else 0 for i in range(len(y_set) * 2 - 1)] grid = [[0] * (len(x_set) * 2 - 1) for _ in range(len(y_set) * 2 - 1)] for a, b, c in vertical_lines: a, b, c = x_encoded[a], x_encoded[b], y_encoded[c] for x in range(a, b + 1): grid[c][x] = 1 for d, e, f in horizontal_lines: d, e, f = x_encoded[d], y_encoded[e], y_encoded[f] for y in range(e, f + 1): grid[y][d] = 1 que = deque() used = [[0] * len(x_set) * 2 for _ in range(len(y_set) * 2)] dy = [1, 1, -1, -1] dx = [1, -1, 1, -1] for k in range(4): nny, nnx = y_encoded[0] + dy[k], x_encoded[0] + dx[k] if 1 <= nny < len(y_set) * 2 - 1 and 1 <= nnx < len(x_set) * 2 - 1: que.append((nny, nnx)) used[nny][nnx] = 1 ans = 0 dy = [1, 0, -1, 0] dx = [0, 1, 0, -1] while que: y, x = que.popleft() if y % 2 and x % 2: ans += y_length[y] * x_length[x] for k in range(4): ny, nx = y + dy[k], x + dx[k] nny, nnx = ny + dy[k], nx + dx[k] if grid[ny][nx] == 0: if nny < 0 or nny >= len(y_set) * 2 - 1 or nnx < 0 or nnx >= len(x_set) * 2 - 1: return 'INF' if not used[nny][nnx]: que.append((nny, nnx)) used[nny][nnx] = 1 return ans print((f_single_dot()))
def f_single_dot(): # https://atcoder.jp/contests/abc168/submissions/13368489 import sys from collections import deque input = sys.stdin.readline N, M = [int(i) for i in input().split()] x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要) vertical_lines = [] for _ in range(N): a, b, c = list(map(int, input().split())) vertical_lines.append((a, b, c)) x_set |= {a, b} y_set |= {c} horizontal_lines = [] for _ in range(M): d, e, f = list(map(int, input().split())) horizontal_lines.append((d, e, f)) x_set |= {d} y_set |= {e, f} x_set = sorted(x_set) y_set = sorted(y_set) # 座標圧縮 (壁も配列に格納するので、2 倍している) x_encoded = {n: i * 2 for i, n in enumerate(x_set)} y_encoded = {n: i * 2 for i, n in enumerate(y_set)} # 座標圧縮されたグリッドで縦横に 1 マス分進むことは実際にはどれくらい進んだことなのか x_length = [x_set[i // 2 + 1] - x_set[i // 2] if i % 2 else 0 for i in range(len(x_set) * 2 - 1)] y_length = [y_set[i // 2 + 1] - y_set[i // 2] if i % 2 else 0 for i in range(len(y_set) * 2 - 1)] grid = [[0] * (len(y_set) * 2 - 1) for _ in range(len(x_set) * 2 - 1)] for a, b, c in vertical_lines: a, b, c = x_encoded[a], x_encoded[b], y_encoded[c] for x in range(a, b + 1): grid[x][c] = 1 for d, e, f in horizontal_lines: d, e, f = x_encoded[d], y_encoded[e], y_encoded[f] for y in range(e, f + 1): grid[d][y] = 1 que = deque() used = [[0] * len(y_set) * 2 for _ in range(len(x_set) * 2)] dy = [1, 1, -1, -1] dx = [1, -1, 1, -1] for k in range(4): nnx, nny = x_encoded[0] + dx[k], y_encoded[0] + dy[k] if 1 <= nnx < len(x_set) * 2 - 1 and 1 <= nny < len(y_set) * 2 - 1: que.append((nnx, nny)) used[nnx][nny] = 1 ans = 0 dy = [1, 0, -1, 0] dx = [0, 1, 0, -1] while que: x, y = que.popleft() if x % 2 and y % 2: ans += x_length[x] * y_length[y] for k in range(4): nx, ny = x + dx[k], y + dy[k] nnx, nny = nx + dx[k], ny + dy[k] if grid[nx][ny] == 0: if nnx < 0 or nnx >= len(x_set) * 2 - 1 or nny < 0 or nny >= len(y_set) * 2 - 1: return 'INF' if not used[nnx][nny]: que.append((nnx, nny)) used[nnx][nny] = 1 return ans print((f_single_dot()))
73
73
2,551
2,551
def f_single_dot(): # https://atcoder.jp/contests/abc168/submissions/13368489 import sys from collections import deque input = sys.stdin.readline N, M = [int(i) for i in input().split()] x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要) vertical_lines = [] for _ in range(N): a, b, c = list(map(int, input().split())) vertical_lines.append((a, b, c)) x_set |= {a, b} y_set |= {c} horizontal_lines = [] for _ in range(M): d, e, f = list(map(int, input().split())) horizontal_lines.append((d, e, f)) x_set |= {d} y_set |= {e, f} x_set = sorted(x_set) y_set = sorted(y_set) # 座標圧縮 (壁も配列に格納するので、2 倍している) x_encoded = {n: i * 2 for i, n in enumerate(x_set)} y_encoded = {n: i * 2 for i, n in enumerate(y_set)} # 座標圧縮されたグリッドで縦横に 1 マス分進むことは実際にはどれくらい進んだことなのか x_length = [ x_set[i // 2 + 1] - x_set[i // 2] if i % 2 else 0 for i in range(len(x_set) * 2 - 1) ] y_length = [ y_set[i // 2 + 1] - y_set[i // 2] if i % 2 else 0 for i in range(len(y_set) * 2 - 1) ] grid = [[0] * (len(x_set) * 2 - 1) for _ in range(len(y_set) * 2 - 1)] for a, b, c in vertical_lines: a, b, c = x_encoded[a], x_encoded[b], y_encoded[c] for x in range(a, b + 1): grid[c][x] = 1 for d, e, f in horizontal_lines: d, e, f = x_encoded[d], y_encoded[e], y_encoded[f] for y in range(e, f + 1): grid[y][d] = 1 que = deque() used = [[0] * len(x_set) * 2 for _ in range(len(y_set) * 2)] dy = [1, 1, -1, -1] dx = [1, -1, 1, -1] for k in range(4): nny, nnx = y_encoded[0] + dy[k], x_encoded[0] + dx[k] if 1 <= nny < len(y_set) * 2 - 1 and 1 <= nnx < len(x_set) * 2 - 1: que.append((nny, nnx)) used[nny][nnx] = 1 ans = 0 dy = [1, 0, -1, 0] dx = [0, 1, 0, -1] while que: y, x = que.popleft() if y % 2 and x % 2: ans += y_length[y] * x_length[x] for k in range(4): ny, nx = y + dy[k], x + dx[k] nny, nnx = ny + dy[k], nx + dx[k] if grid[ny][nx] == 0: if ( nny < 0 or nny >= len(y_set) * 2 - 1 or nnx < 0 or nnx >= len(x_set) * 2 - 1 ): return "INF" if not used[nny][nnx]: que.append((nny, nnx)) used[nny][nnx] = 1 return ans print((f_single_dot()))
def f_single_dot(): # https://atcoder.jp/contests/abc168/submissions/13368489 import sys from collections import deque input = sys.stdin.readline N, M = [int(i) for i in input().split()] x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要) vertical_lines = [] for _ in range(N): a, b, c = list(map(int, input().split())) vertical_lines.append((a, b, c)) x_set |= {a, b} y_set |= {c} horizontal_lines = [] for _ in range(M): d, e, f = list(map(int, input().split())) horizontal_lines.append((d, e, f)) x_set |= {d} y_set |= {e, f} x_set = sorted(x_set) y_set = sorted(y_set) # 座標圧縮 (壁も配列に格納するので、2 倍している) x_encoded = {n: i * 2 for i, n in enumerate(x_set)} y_encoded = {n: i * 2 for i, n in enumerate(y_set)} # 座標圧縮されたグリッドで縦横に 1 マス分進むことは実際にはどれくらい進んだことなのか x_length = [ x_set[i // 2 + 1] - x_set[i // 2] if i % 2 else 0 for i in range(len(x_set) * 2 - 1) ] y_length = [ y_set[i // 2 + 1] - y_set[i // 2] if i % 2 else 0 for i in range(len(y_set) * 2 - 1) ] grid = [[0] * (len(y_set) * 2 - 1) for _ in range(len(x_set) * 2 - 1)] for a, b, c in vertical_lines: a, b, c = x_encoded[a], x_encoded[b], y_encoded[c] for x in range(a, b + 1): grid[x][c] = 1 for d, e, f in horizontal_lines: d, e, f = x_encoded[d], y_encoded[e], y_encoded[f] for y in range(e, f + 1): grid[d][y] = 1 que = deque() used = [[0] * len(y_set) * 2 for _ in range(len(x_set) * 2)] dy = [1, 1, -1, -1] dx = [1, -1, 1, -1] for k in range(4): nnx, nny = x_encoded[0] + dx[k], y_encoded[0] + dy[k] if 1 <= nnx < len(x_set) * 2 - 1 and 1 <= nny < len(y_set) * 2 - 1: que.append((nnx, nny)) used[nnx][nny] = 1 ans = 0 dy = [1, 0, -1, 0] dx = [0, 1, 0, -1] while que: x, y = que.popleft() if x % 2 and y % 2: ans += x_length[x] * y_length[y] for k in range(4): nx, ny = x + dx[k], y + dy[k] nnx, nny = nx + dx[k], ny + dy[k] if grid[nx][ny] == 0: if ( nnx < 0 or nnx >= len(x_set) * 2 - 1 or nny < 0 or nny >= len(y_set) * 2 - 1 ): return "INF" if not used[nnx][nny]: que.append((nnx, nny)) used[nnx][nny] = 1 return ans print((f_single_dot()))
false
0
[ "- grid = [[0] * (len(x_set) * 2 - 1) for _ in range(len(y_set) * 2 - 1)]", "+ grid = [[0] * (len(y_set) * 2 - 1) for _ in range(len(x_set) * 2 - 1)]", "- grid[c][x] = 1", "+ grid[x][c] = 1", "- grid[y][d] = 1", "+ grid[d][y] = 1", "- used = [[0] * len(x_set) * 2 for _ in range(len(y_set) * 2)]", "+ used = [[0] * len(y_set) * 2 for _ in range(len(x_set) * 2)]", "- nny, nnx = y_encoded[0] + dy[k], x_encoded[0] + dx[k]", "- if 1 <= nny < len(y_set) * 2 - 1 and 1 <= nnx < len(x_set) * 2 - 1:", "- que.append((nny, nnx))", "- used[nny][nnx] = 1", "+ nnx, nny = x_encoded[0] + dx[k], y_encoded[0] + dy[k]", "+ if 1 <= nnx < len(x_set) * 2 - 1 and 1 <= nny < len(y_set) * 2 - 1:", "+ que.append((nnx, nny))", "+ used[nnx][nny] = 1", "- y, x = que.popleft()", "- if y % 2 and x % 2:", "- ans += y_length[y] * x_length[x]", "+ x, y = que.popleft()", "+ if x % 2 and y % 2:", "+ ans += x_length[x] * y_length[y]", "- ny, nx = y + dy[k], x + dx[k]", "- nny, nnx = ny + dy[k], nx + dx[k]", "- if grid[ny][nx] == 0:", "+ nx, ny = x + dx[k], y + dy[k]", "+ nnx, nny = nx + dx[k], ny + dy[k]", "+ if grid[nx][ny] == 0:", "- nny < 0", "+ nnx < 0", "+ or nnx >= len(x_set) * 2 - 1", "+ or nny < 0", "- or nnx < 0", "- or nnx >= len(x_set) * 2 - 1", "- if not used[nny][nnx]:", "- que.append((nny, nnx))", "- used[nny][nnx] = 1", "+ if not used[nnx][nny]:", "+ que.append((nnx, nny))", "+ used[nnx][nny] = 1" ]
false
0.050362
0.049778
1.011732
[ "s901557374", "s607047763" ]
u678167152
p04020
python
s392552538
s594395967
202
162
7,072
13,044
Accepted
Accepted
19.8
def solve(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] ans = 0 for a in A: ans += a//2 prev = 0 for a in A: new = a%2 if prev == 1: if new == 1: ans += 1 elif a>0: prev = 1 else: prev = 0 prev = prev^new return ans print((solve()))
def solve(): ans = 0 N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] rem = 0 for i in range(N): ans += (A[i]+rem)//2 if A[i]>0: rem = (A[i]+rem)%2 else: rem = 0 return ans print((solve()))
19
13
403
240
def solve(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] ans = 0 for a in A: ans += a // 2 prev = 0 for a in A: new = a % 2 if prev == 1: if new == 1: ans += 1 elif a > 0: prev = 1 else: prev = 0 prev = prev ^ new return ans print((solve()))
def solve(): ans = 0 N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] rem = 0 for i in range(N): ans += (A[i] + rem) // 2 if A[i] > 0: rem = (A[i] + rem) % 2 else: rem = 0 return ans print((solve()))
false
31.578947
[ "+ ans = 0", "- ans = 0", "- for a in A:", "- ans += a // 2", "- prev = 0", "- for a in A:", "- new = a % 2", "- if prev == 1:", "- if new == 1:", "- ans += 1", "- elif a > 0:", "- prev = 1", "- else:", "- prev = 0", "- prev = prev ^ new", "+ rem = 0", "+ for i in range(N):", "+ ans += (A[i] + rem) // 2", "+ if A[i] > 0:", "+ rem = (A[i] + rem) % 2", "+ else:", "+ rem = 0" ]
false
0.087878
0.043191
2.034652
[ "s392552538", "s594395967" ]
u266874640
p03043
python
s372814907
s600175286
47
34
5,348
3,060
Accepted
Accepted
27.66
N, K = list(map(int,input().split())) ans = 0 if K <= N: ans += (1/N)*(N-K+1) dp = [0] + [1/N] * K else: dp = [0] + [1/N] * N + [0] * (K-N) for i in range(1,K): if i % 2 == 0: dp[i] += dp[i//2] * (1/2) if K % 2 == 0: ans += sum(dp[K//2:K])*(1/2) else: ans += sum(dp[K//2+1:K])*(1/2) print(ans)
import math N,K = list(map(int,input().split())) ans = 0 for i in range(1,N+1): if i >= K: ans += (1/N) continue X = int(math.log((K/i), 2)) if (K/i) % 2**X == 0: pass else: X += 1 ans += (1/N) * (1/2) ** X print(ans)
15
15
334
279
N, K = list(map(int, input().split())) ans = 0 if K <= N: ans += (1 / N) * (N - K + 1) dp = [0] + [1 / N] * K else: dp = [0] + [1 / N] * N + [0] * (K - N) for i in range(1, K): if i % 2 == 0: dp[i] += dp[i // 2] * (1 / 2) if K % 2 == 0: ans += sum(dp[K // 2 : K]) * (1 / 2) else: ans += sum(dp[K // 2 + 1 : K]) * (1 / 2) print(ans)
import math N, K = list(map(int, input().split())) ans = 0 for i in range(1, N + 1): if i >= K: ans += 1 / N continue X = int(math.log((K / i), 2)) if (K / i) % 2**X == 0: pass else: X += 1 ans += (1 / N) * (1 / 2) ** X print(ans)
false
0
[ "+import math", "+", "-if K <= N:", "- ans += (1 / N) * (N - K + 1)", "- dp = [0] + [1 / N] * K", "-else:", "- dp = [0] + [1 / N] * N + [0] * (K - N)", "-for i in range(1, K):", "- if i % 2 == 0:", "- dp[i] += dp[i // 2] * (1 / 2)", "-if K % 2 == 0:", "- ans += sum(dp[K // 2 : K]) * (1 / 2)", "-else:", "- ans += sum(dp[K // 2 + 1 : K]) * (1 / 2)", "+for i in range(1, N + 1):", "+ if i >= K:", "+ ans += 1 / N", "+ continue", "+ X = int(math.log((K / i), 2))", "+ if (K / i) % 2**X == 0:", "+ pass", "+ else:", "+ X += 1", "+ ans += (1 / N) * (1 / 2) ** X" ]
false
0.039759
0.056072
0.709079
[ "s372814907", "s600175286" ]
u454022848
p02388
python
s769698447
s922047638
30
10
6,724
6,368
Accepted
Accepted
66.67
print((int(eval(input()))**3))
print((input()**3))
1
1
22
17
print((int(eval(input())) ** 3))
print((input() ** 3))
false
0
[ "-print((int(eval(input())) ** 3))", "+print((input() ** 3))" ]
false
0.080245
0.042433
1.891106
[ "s769698447", "s922047638" ]
u054825571
p02923
python
s334148281
s551550491
227
72
63,984
20,328
Accepted
Accepted
68.28
N=int(eval(input())) H=list(map(int, input().split())) s=0 t=0 pre=H[0] for h in H[1:]: if h <= pre: t+=1 else: s=max(s,t) t=0 pre = h print((max(s,t)))
N = int(eval(input())) H = list(map(int, input().split())) ans = 0 s = 0 for i in range(N-1): if H[i] >= H[i+1]: s+=1 else: ans = max(ans, s) s = 0 ans = max(ans, s) print(ans)
13
13
174
201
N = int(eval(input())) H = list(map(int, input().split())) s = 0 t = 0 pre = H[0] for h in H[1:]: if h <= pre: t += 1 else: s = max(s, t) t = 0 pre = h print((max(s, t)))
N = int(eval(input())) H = list(map(int, input().split())) ans = 0 s = 0 for i in range(N - 1): if H[i] >= H[i + 1]: s += 1 else: ans = max(ans, s) s = 0 ans = max(ans, s) print(ans)
false
0
[ "+ans = 0", "-t = 0", "-pre = H[0]", "-for h in H[1:]:", "- if h <= pre:", "- t += 1", "+for i in range(N - 1):", "+ if H[i] >= H[i + 1]:", "+ s += 1", "- s = max(s, t)", "- t = 0", "- pre = h", "-print((max(s, t)))", "+ ans = max(ans, s)", "+ s = 0", "+ans = max(ans, s)", "+print(ans)" ]
false
0.044378
0.044584
0.995373
[ "s334148281", "s551550491" ]
u411203878
p02861
python
s140400106
s122870372
170
114
38,384
75,128
Accepted
Accepted
32.94
n=int(eval(input())) l=[[int(i) for i in input().split()] for j in range(n)] d=[] for i in range(n): for j in range(i): d.append(((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5) print((sum(d)*(n-1)/len(d)))
import itertools n=int(eval(input())) ab = [] for _ in range(n): a, b = (int(x) for x in input().split()) ab.append([a, b]) narabi = [0+i for i in range(n)] ans = 0 count = 0 for v in itertools.permutations(narabi, n): count += 1 tmp_len = 0 for i in range(1,n): x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2 tmp_len += (x + y)**0.5 ans += tmp_len print((ans/count))
8
21
213
452
n = int(eval(input())) l = [[int(i) for i in input().split()] for j in range(n)] d = [] for i in range(n): for j in range(i): d.append(((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** 0.5) print((sum(d) * (n - 1) / len(d)))
import itertools n = int(eval(input())) ab = [] for _ in range(n): a, b = (int(x) for x in input().split()) ab.append([a, b]) narabi = [0 + i for i in range(n)] ans = 0 count = 0 for v in itertools.permutations(narabi, n): count += 1 tmp_len = 0 for i in range(1, n): x, y = ( abs(ab[v[i - 1]][0] - ab[v[i]][0]) ** 2, abs(ab[v[i - 1]][1] - ab[v[i]][1]) ** 2, ) tmp_len += (x + y) ** 0.5 ans += tmp_len print((ans / count))
false
61.904762
[ "+import itertools", "+", "-l = [[int(i) for i in input().split()] for j in range(n)]", "-d = []", "-for i in range(n):", "- for j in range(i):", "- d.append(((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** 0.5)", "-print((sum(d) * (n - 1) / len(d)))", "+ab = []", "+for _ in range(n):", "+ a, b = (int(x) for x in input().split())", "+ ab.append([a, b])", "+narabi = [0 + i for i in range(n)]", "+ans = 0", "+count = 0", "+for v in itertools.permutations(narabi, n):", "+ count += 1", "+ tmp_len = 0", "+ for i in range(1, n):", "+ x, y = (", "+ abs(ab[v[i - 1]][0] - ab[v[i]][0]) ** 2,", "+ abs(ab[v[i - 1]][1] - ab[v[i]][1]) ** 2,", "+ )", "+ tmp_len += (x + y) ** 0.5", "+ ans += tmp_len", "+print((ans / count))" ]
false
0.085289
0.037472
2.276076
[ "s140400106", "s122870372" ]
u312025627
p03351
python
s164174761
s550036047
177
69
38,256
61,960
Accepted
Accepted
61.02
def main(): A = [int(i) for i in input().split()] if abs(A[0] - A[2]) <= A[3] or (abs(A[0] - A[1]) <= A[3] and abs(A[1] - A[2]) <= A[3]): print("Yes") else: print("No") if __name__ == '__main__': main()
def main(): a, b, c, d = (int(i) for i in input().split()) if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d): print("Yes") else: print("No") if __name__ == '__main__': main()
10
10
246
222
def main(): A = [int(i) for i in input().split()] if abs(A[0] - A[2]) <= A[3] or ( abs(A[0] - A[1]) <= A[3] and abs(A[1] - A[2]) <= A[3] ): print("Yes") else: print("No") if __name__ == "__main__": main()
def main(): a, b, c, d = (int(i) for i in input().split()) if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d): print("Yes") else: print("No") if __name__ == "__main__": main()
false
0
[ "- A = [int(i) for i in input().split()]", "- if abs(A[0] - A[2]) <= A[3] or (", "- abs(A[0] - A[1]) <= A[3] and abs(A[1] - A[2]) <= A[3]", "- ):", "+ a, b, c, d = (int(i) for i in input().split())", "+ if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):" ]
false
0.061029
0.042928
1.421641
[ "s164174761", "s550036047" ]
u600402037
p03579
python
s555965853
s657541061
634
575
42,128
42,124
Accepted
Accepted
9.31
import sys sys.setrecursionlimit(10 ** 7) N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] graph = [[] for _ in range(N)] for a, b in AB: graph[a-1].append(b-1) graph[b-1].append(a-1) # 二部グラフかどうかの判定 color = [None] * N color[0] = 0 q = [0] while q: x = q.pop() for y in graph[x]: if color[y] is None: color[y] = 1 - color[x] q.append(y) # 二部グラフかどうか is_bg = all(color[a-1] != color[b-1] for a, b in AB) if is_bg: # 完全二部グラフにする x = sum(color) y = N - x answer = x*y - M else: # 完全グラフにする(奇数長のパスがある場合は必ず2ずつ減らしていけば長さが3になる) answer = N*(N-1)//2 - M print(answer)
# C - 3 Steps import sys sys.setrecursionlimit(10 ** 7) N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] graph = [[] for _ in range(N)] for a, b in AB: graph[a-1].append(b-1) graph[b-1].append(a-1) # 二部グラフかどうかの判定 colors = [None] * N colors[0] = 0 q = [0] while q: x = q.pop() for y in graph[x]: if colors[y] is None: colors[y] = 1 - colors[x] q.append(y) # 二部グラフかどうか is_bg = all(colors[a-1] != colors[b-1] for a, b in AB) if is_bg: # 完全二部グラフにする x = sum(colors) y = N - x answer = x*y - M else: # 完全グラフにする(奇数長のパスがある場合は必ず2ずつ減らしていけば長さが3になる) answer = N*(N-1)//2 - M print(answer)
35
36
706
729
import sys sys.setrecursionlimit(10**7) N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] graph = [[] for _ in range(N)] for a, b in AB: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) # 二部グラフかどうかの判定 color = [None] * N color[0] = 0 q = [0] while q: x = q.pop() for y in graph[x]: if color[y] is None: color[y] = 1 - color[x] q.append(y) # 二部グラフかどうか is_bg = all(color[a - 1] != color[b - 1] for a, b in AB) if is_bg: # 完全二部グラフにする x = sum(color) y = N - x answer = x * y - M else: # 完全グラフにする(奇数長のパスがある場合は必ず2ずつ減らしていけば長さが3になる) answer = N * (N - 1) // 2 - M print(answer)
# C - 3 Steps import sys sys.setrecursionlimit(10**7) N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] graph = [[] for _ in range(N)] for a, b in AB: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) # 二部グラフかどうかの判定 colors = [None] * N colors[0] = 0 q = [0] while q: x = q.pop() for y in graph[x]: if colors[y] is None: colors[y] = 1 - colors[x] q.append(y) # 二部グラフかどうか is_bg = all(colors[a - 1] != colors[b - 1] for a, b in AB) if is_bg: # 完全二部グラフにする x = sum(colors) y = N - x answer = x * y - M else: # 完全グラフにする(奇数長のパスがある場合は必ず2ずつ減らしていけば長さが3になる) answer = N * (N - 1) // 2 - M print(answer)
false
2.777778
[ "+# C - 3 Steps", "-color = [None] * N", "-color[0] = 0", "+colors = [None] * N", "+colors[0] = 0", "- if color[y] is None:", "- color[y] = 1 - color[x]", "+ if colors[y] is None:", "+ colors[y] = 1 - colors[x]", "-is_bg = all(color[a - 1] != color[b - 1] for a, b in AB)", "+is_bg = all(colors[a - 1] != colors[b - 1] for a, b in AB)", "- x = sum(color)", "+ x = sum(colors)" ]
false
0.049061
0.04799
1.0223
[ "s555965853", "s657541061" ]
u698693989
p02388
python
s379607745
s182929874
30
20
7,640
5,572
Accepted
Accepted
33.33
x = int(eval(input())) print((x**3))
n=int(eval(input())); print((n**3))
2
2
29
29
x = int(eval(input())) print((x**3))
n = int(eval(input())) print((n**3))
false
0
[ "-x = int(eval(input()))", "-print((x**3))", "+n = int(eval(input()))", "+print((n**3))" ]
false
0.037164
0.032388
1.14745
[ "s379607745", "s182929874" ]
u197968862
p03163
python
s962483579
s061742261
688
577
171,784
217,964
Accepted
Accepted
16.13
n, w = list(map(int,input().split())) wv = [list(map(int,input().split())) for _ in range(n)] dp = [[0 for _ in range(w+1)] for _ in range(n+1)] for i in range(n): for j in range(w+1): if wv[i][0] <= j: dp[i+1][j] = max(dp[i][j-wv[i][0]]+wv[i][1],dp[i][j]) else: dp[i+1][j] = dp[i][j] print((max(dp[-1])))
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] dp = [[0 for _ in range(w+1)] for _ in range(n+1)] for i in range(n): for j in range(w+1): if j - wv[i][0] >= 0: dp[i+1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i][j]) else: dp[i+1][j] = max(dp[i][j], dp[i+1][j]) print((max(dp[-1])))
13
13
356
384
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)] for i in range(n): for j in range(w + 1): if wv[i][0] <= j: dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i][j]) else: dp[i + 1][j] = dp[i][j] print((max(dp[-1])))
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)] for i in range(n): for j in range(w + 1): if j - wv[i][0] >= 0: dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i][j]) else: dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]) print((max(dp[-1])))
false
0
[ "- if wv[i][0] <= j:", "+ if j - wv[i][0] >= 0:", "- dp[i + 1][j] = dp[i][j]", "+ dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])" ]
false
0.044283
0.039116
1.132092
[ "s962483579", "s061742261" ]
u734548018
p03033
python
s487309676
s017475107
1,832
1,219
73,108
75,764
Accepted
Accepted
33.46
import sys from bisect import bisect_left N,Q = list(map(int, input().split())) STX = [None] * N for i in range(N): s,t,x = list(map(int, input().split())) STX[i] = [x,s,t] STX.sort() Dn = [None] * (Q+1) for i in range(Q): Dn[i] = int(eval(input())) Dn[Q] = 10**10 ans = [-1] * Q skip = [-1] * Q for x, s, t in STX: ss = bisect_left(Dn, s - x) tt = bisect_left(Dn, t - x) while ss < tt: sk = skip[ss] if sk == -1: ans[ss] = x skip[ss] = tt ss += 1 else: ss = sk print(('\n'.join(map(str, ans))))
# -*- coding: utf-8 -*- from bisect import bisect_left from sys import stdin readl = stdin.readline ## input N,Q = list(map(int, readl().rstrip().split())) STX = [list(map(int, readl().rstrip().split())) for _ in range(N)] Dn = [None for _ in range(Q+1)] for i in range(Q): Dn[i] = int(readl().rstrip()) Dn[Q] = 10**10 ans = [-1] * (Q+1) skip = [-1] * (Q+1) for s,t,x in sorted(STX,key=lambda x:x[2]): l = bisect_left(Dn,s-x) r = bisect_left(Dn,t-x) while l < r: if skip[l] < 0: ans[l] = x skip[l] = r l += 1 else: l = skip[l] for d in ans[:-1]: print(d)
31
31
559
626
import sys from bisect import bisect_left N, Q = list(map(int, input().split())) STX = [None] * N for i in range(N): s, t, x = list(map(int, input().split())) STX[i] = [x, s, t] STX.sort() Dn = [None] * (Q + 1) for i in range(Q): Dn[i] = int(eval(input())) Dn[Q] = 10**10 ans = [-1] * Q skip = [-1] * Q for x, s, t in STX: ss = bisect_left(Dn, s - x) tt = bisect_left(Dn, t - x) while ss < tt: sk = skip[ss] if sk == -1: ans[ss] = x skip[ss] = tt ss += 1 else: ss = sk print(("\n".join(map(str, ans))))
# -*- coding: utf-8 -*- from bisect import bisect_left from sys import stdin readl = stdin.readline ## input N, Q = list(map(int, readl().rstrip().split())) STX = [list(map(int, readl().rstrip().split())) for _ in range(N)] Dn = [None for _ in range(Q + 1)] for i in range(Q): Dn[i] = int(readl().rstrip()) Dn[Q] = 10**10 ans = [-1] * (Q + 1) skip = [-1] * (Q + 1) for s, t, x in sorted(STX, key=lambda x: x[2]): l = bisect_left(Dn, s - x) r = bisect_left(Dn, t - x) while l < r: if skip[l] < 0: ans[l] = x skip[l] = r l += 1 else: l = skip[l] for d in ans[:-1]: print(d)
false
0
[ "-import sys", "+# -*- coding: utf-8 -*-", "+from sys import stdin", "-N, Q = list(map(int, input().split()))", "-STX = [None] * N", "-for i in range(N):", "- s, t, x = list(map(int, input().split()))", "- STX[i] = [x, s, t]", "-STX.sort()", "-Dn = [None] * (Q + 1)", "+readl = stdin.readline", "+## input", "+N, Q = list(map(int, readl().rstrip().split()))", "+STX = [list(map(int, readl().rstrip().split())) for _ in range(N)]", "+Dn = [None for _ in range(Q + 1)]", "- Dn[i] = int(eval(input()))", "+ Dn[i] = int(readl().rstrip())", "-ans = [-1] * Q", "-skip = [-1] * Q", "-for x, s, t in STX:", "- ss = bisect_left(Dn, s - x)", "- tt = bisect_left(Dn, t - x)", "- while ss < tt:", "- sk = skip[ss]", "- if sk == -1:", "- ans[ss] = x", "- skip[ss] = tt", "- ss += 1", "+ans = [-1] * (Q + 1)", "+skip = [-1] * (Q + 1)", "+for s, t, x in sorted(STX, key=lambda x: x[2]):", "+ l = bisect_left(Dn, s - x)", "+ r = bisect_left(Dn, t - x)", "+ while l < r:", "+ if skip[l] < 0:", "+ ans[l] = x", "+ skip[l] = r", "+ l += 1", "- ss = sk", "-print((\"\\n\".join(map(str, ans))))", "+ l = skip[l]", "+for d in ans[:-1]:", "+ print(d)" ]
false
0.040862
0.007329
5.575439
[ "s487309676", "s017475107" ]
u535171899
p02756
python
s919586502
s036588919
620
305
6,900
93,124
Accepted
Accepted
50.81
from collections import deque s = eval(input()) q = int(eval(input())) queue = deque([s]) tmp = 1 for i in range(q): x = eval(input()) if x[0]==str(1): tmp*=-1 else: t,f,c = x.split() t,f = int(t),int(f) if tmp==-1: if f==1: queue.append(c) if f==2: queue.appendleft(c) if tmp==1: if f==1: queue.appendleft(c) if f==2: queue.append(c) print((''.join(queue)[::tmp]))
from collections import deque s = eval(input()) q = int(eval(input())) deq = deque([s]) flag = 1 for i in range(q): query = input().split() if query[0]==str(1): flag*=-1 if query[0]==str(2): x = 1 if query[1]==str(1) else -1 if flag*x==1: deq.appendleft(query[2]) else: deq.append(query[2]) if flag==-1: print((''.join(deq)[::-1])) else: print((''.join(deq)))
25
22
535
444
from collections import deque s = eval(input()) q = int(eval(input())) queue = deque([s]) tmp = 1 for i in range(q): x = eval(input()) if x[0] == str(1): tmp *= -1 else: t, f, c = x.split() t, f = int(t), int(f) if tmp == -1: if f == 1: queue.append(c) if f == 2: queue.appendleft(c) if tmp == 1: if f == 1: queue.appendleft(c) if f == 2: queue.append(c) print(("".join(queue)[::tmp]))
from collections import deque s = eval(input()) q = int(eval(input())) deq = deque([s]) flag = 1 for i in range(q): query = input().split() if query[0] == str(1): flag *= -1 if query[0] == str(2): x = 1 if query[1] == str(1) else -1 if flag * x == 1: deq.appendleft(query[2]) else: deq.append(query[2]) if flag == -1: print(("".join(deq)[::-1])) else: print(("".join(deq)))
false
12
[ "-queue = deque([s])", "-tmp = 1", "+deq = deque([s])", "+flag = 1", "- x = eval(input())", "- if x[0] == str(1):", "- tmp *= -1", "- else:", "- t, f, c = x.split()", "- t, f = int(t), int(f)", "- if tmp == -1:", "- if f == 1:", "- queue.append(c)", "- if f == 2:", "- queue.appendleft(c)", "- if tmp == 1:", "- if f == 1:", "- queue.appendleft(c)", "- if f == 2:", "- queue.append(c)", "-print((\"\".join(queue)[::tmp]))", "+ query = input().split()", "+ if query[0] == str(1):", "+ flag *= -1", "+ if query[0] == str(2):", "+ x = 1 if query[1] == str(1) else -1", "+ if flag * x == 1:", "+ deq.appendleft(query[2])", "+ else:", "+ deq.append(query[2])", "+if flag == -1:", "+ print((\"\".join(deq)[::-1]))", "+else:", "+ print((\"\".join(deq)))" ]
false
0.038522
0.037339
1.031681
[ "s919586502", "s036588919" ]
u279493135
p03331
python
s202085668
s021389522
205
41
5,400
5,384
Accepted
Accepted
80
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 def ketawa(x): return sum(map(int, list(str(x)))) N = INT() ans = INF for a in range(1, N//2+1): b = N-a ans = min(ans, ketawa(a)+ketawa(b)) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul, add from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() if N%10 == 0: print((10)) else: print((reduce(add, list(map(int, list(str(N)))))))
31
26
942
870
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 def ketawa(x): return sum(map(int, list(str(x)))) N = INT() ans = INF for a in range(1, N // 2 + 1): b = N - a ans = min(ans, ketawa(a) + ketawa(b)) print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul, add from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N = INT() if N % 10 == 0: print((10)) else: print((reduce(add, list(map(int, list(str(N)))))))
false
16.129032
[ "-from operator import itemgetter, mul", "+from operator import itemgetter, mul, add", "-", "-", "-def ketawa(x):", "- return sum(map(int, list(str(x))))", "-", "-", "-ans = INF", "-for a in range(1, N // 2 + 1):", "- b = N - a", "- ans = min(ans, ketawa(a) + ketawa(b))", "-print(ans)", "+if N % 10 == 0:", "+ print((10))", "+else:", "+ print((reduce(add, list(map(int, list(str(N)))))))" ]
false
0.090405
0.08858
1.020599
[ "s202085668", "s021389522" ]
u145231176
p02960
python
s641372213
s061277656
995
351
75,988
99,976
Accepted
Accepted
64.72
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() from collections import defaultdict, deque, Counter from sys import exit import heapq import math import fractions import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 S = eval(input()) N = len(S) modlist = [0] * 13 splitmod = [] if S[0] == "?": for i in range(10): modlist[i % 13] += 1 else: modlist[int(S[0])] += 1 S = S[1:] # 前から処理していく # 10と13は互いに素なので # a == b (mod z)なら # 10a == 10b (mod z) # 例 # 18 == 5 (mod 13) # 180 == 50 (mod 13) # 13 * 13 + 11 == 13 * 3 + 11 (mod 13) for st in S: modalta = [0] * 13 if st == "?": # 例えば 7?4の時 # 7 * 10 + 1, 2, 3... for i in range(10): # modlist for j in range(13): opt = (j * 10 + i) % 13 modalta[opt] += modlist[j] else: for j in range(13): opt = (j * 10 + int(st)) % 13 modalta[opt] += modlist[j] # mod調整 for i in range(13): modalta[i] %= mod modlist = copy.deepcopy(modalta) print((modlist[5] % mod))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# S = eval(input()) N = len(S) dp = [[0] * 13 for i in range(N)] str_int = '0123456789' if S[0] in str_int: dp[0][int(S[0])] += 1 else: for i in range(10): dp[0][i] += 1 for i in range(1, N): if S[i] in str_int: # 前の段 for j in range(13): dp[i][(10 * j + int(S[i])) % 13] += (dp[i - 1][j] % mod) else: # 前の段 for j in range(13): # 後ろの段 # ?なら0 ~ 10で回す for l in range(10): dp[i][(10 * j + l) % 13] += (dp[i - 1][j] % mod) print((dp[N - 1][5] % mod))
66
77
1,490
1,890
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() from collections import defaultdict, deque, Counter from sys import exit import heapq import math import fractions import copy from itertools import permutations from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 S = eval(input()) N = len(S) modlist = [0] * 13 splitmod = [] if S[0] == "?": for i in range(10): modlist[i % 13] += 1 else: modlist[int(S[0])] += 1 S = S[1:] # 前から処理していく # 10と13は互いに素なので # a == b (mod z)なら # 10a == 10b (mod z) # 例 # 18 == 5 (mod 13) # 180 == 50 (mod 13) # 13 * 13 + 11 == 13 * 3 + 11 (mod 13) for st in S: modalta = [0] * 13 if st == "?": # 例えば 7?4の時 # 7 * 10 + 1, 2, 3... for i in range(10): # modlist for j in range(13): opt = (j * 10 + i) % 13 modalta[opt] += modlist[j] else: for j in range(13): opt = (j * 10 + int(st)) % 13 modalta[opt] += modlist[j] # mod調整 for i in range(13): modalta[i] %= mod modlist = copy.deepcopy(modalta) print((modlist[5] % mod))
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10**9 + 7 ############# # Main Code # ############# S = eval(input()) N = len(S) dp = [[0] * 13 for i in range(N)] str_int = "0123456789" if S[0] in str_int: dp[0][int(S[0])] += 1 else: for i in range(10): dp[0][i] += 1 for i in range(1, N): if S[i] in str_int: # 前の段 for j in range(13): dp[i][(10 * j + int(S[i])) % 13] += dp[i - 1][j] % mod else: # 前の段 for j in range(13): # 後ろの段 # ?なら0 ~ 10で回す for l in range(10): dp[i][(10 * j + l) % 13] += dp[i - 1][j] % mod print((dp[N - 1][5] % mod))
false
14.285714
[ "+def rand_N(ran1, ran2):", "+ return random.randint(ran1, ran2)", "+", "+", "+def rand_List(ran1, ran2, rantime):", "+ return [random.randint(ran1, ran2) for i in range(rantime)]", "+", "+", "+def rand_ints_nodup(ran1, ran2, rantime):", "+ ns = []", "+ while len(ns) < rantime:", "+ n = random.randint(ran1, ran2)", "+ if not n in ns:", "+ ns.append(n)", "+ return sorted(ns)", "+", "+", "+def rand_query(ran1, ran2, rantime):", "+ r_query = []", "+ while len(r_query) < rantime:", "+ n_q = rand_ints_nodup(ran1, ran2, 2)", "+ if not n_q in r_query:", "+ r_query.append(n_q)", "+ return sorted(r_query)", "+", "+", "+from decimal import *", "-import fractions", "+from fractions import gcd", "+import random", "+import string", "-from itertools import permutations", "+from itertools import combinations, permutations, product", "+#############", "+# Main Code #", "+#############", "-modlist = [0] * 13", "-splitmod = []", "-if S[0] == \"?\":", "+dp = [[0] * 13 for i in range(N)]", "+str_int = \"0123456789\"", "+if S[0] in str_int:", "+ dp[0][int(S[0])] += 1", "+else:", "- modlist[i % 13] += 1", "-else:", "- modlist[int(S[0])] += 1", "-S = S[1:]", "-# 前から処理していく", "-# 10と13は互いに素なので", "-# a == b (mod z)なら", "-# 10a == 10b (mod z)", "-# 例", "-# 18 == 5 (mod 13)", "-# 180 == 50 (mod 13)", "-# 13 * 13 + 11 == 13 * 3 + 11 (mod 13)", "-for st in S:", "- modalta = [0] * 13", "- if st == \"?\":", "- # 例えば 7?4の時", "- # 7 * 10 + 1, 2, 3...", "- for i in range(10):", "- # modlist", "- for j in range(13):", "- opt = (j * 10 + i) % 13", "- modalta[opt] += modlist[j]", "+ dp[0][i] += 1", "+for i in range(1, N):", "+ if S[i] in str_int:", "+ # 前の段", "+ for j in range(13):", "+ dp[i][(10 * j + int(S[i])) % 13] += dp[i - 1][j] % mod", "+ # 前の段", "- opt = (j * 10 + int(st)) % 13", "- modalta[opt] += modlist[j]", "- # mod調整", "- for i in range(13):", "- modalta[i] %= mod", "- modlist = copy.deepcopy(modalta)", "-print((modlist[5] % mod))", "+ # 後ろの段", "+ # ?なら0 ~ 10で回す", "+ for l in range(10):", "+ dp[i][(10 * j + l) % 13] += dp[i - 1][j] % mod", "+print((dp[N - 1][5] % mod))" ]
false
0.038725
0.039654
0.976589
[ "s641372213", "s061277656" ]
u562935282
p03166
python
s791174375
s603101654
1,111
708
177,084
71,044
Accepted
Accepted
36.27
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline inf = float('inf') def rec(v): if used[v]: return dp[v] used[v] = True res = 0 for u in es[v]: res = max(res, rec(u) + 1) dp[v] = res return res n, m = list(map(int, input().split())) es = tuple(set() for _ in range(n)) for _ in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 es[x].add(y) used = [False] * n dp = [inf] * n ans = 0 for i in range(n): ans = max(ans, rec(i)) print(ans)
import sys sys.setrecursionlimit(10 ** 7) def dfs(v): if d[v] != -1: return d[v] res = -1 for u in e[v]: res = max(res, dfs(u)) res += 1 d[v] = res return res n, m = list(map(int, input().split())) e = tuple(set() for _ in range(n)) for _ in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 e[x].add(y) d = [-1] * n res = -1 for v in range(n): res = max(res, dfs(v)) print(res)
36
29
562
474
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline inf = float("inf") def rec(v): if used[v]: return dp[v] used[v] = True res = 0 for u in es[v]: res = max(res, rec(u) + 1) dp[v] = res return res n, m = list(map(int, input().split())) es = tuple(set() for _ in range(n)) for _ in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 es[x].add(y) used = [False] * n dp = [inf] * n ans = 0 for i in range(n): ans = max(ans, rec(i)) print(ans)
import sys sys.setrecursionlimit(10**7) def dfs(v): if d[v] != -1: return d[v] res = -1 for u in e[v]: res = max(res, dfs(u)) res += 1 d[v] = res return res n, m = list(map(int, input().split())) e = tuple(set() for _ in range(n)) for _ in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 e[x].add(y) d = [-1] * n res = -1 for v in range(n): res = max(res, dfs(v)) print(res)
false
19.444444
[ "-input = sys.stdin.readline", "-inf = float(\"inf\")", "-def rec(v):", "- if used[v]:", "- return dp[v]", "- used[v] = True", "- res = 0", "- for u in es[v]:", "- res = max(res, rec(u) + 1)", "- dp[v] = res", "+def dfs(v):", "+ if d[v] != -1:", "+ return d[v]", "+ res = -1", "+ for u in e[v]:", "+ res = max(res, dfs(u))", "+ res += 1", "+ d[v] = res", "-es = tuple(set() for _ in range(n))", "+e = tuple(set() for _ in range(n))", "- es[x].add(y)", "-used = [False] * n", "-dp = [inf] * n", "-ans = 0", "-for i in range(n):", "- ans = max(ans, rec(i))", "-print(ans)", "+ e[x].add(y)", "+d = [-1] * n", "+res = -1", "+for v in range(n):", "+ res = max(res, dfs(v))", "+print(res)" ]
false
0.079794
0.048284
1.652582
[ "s791174375", "s603101654" ]
u885634168
p02732
python
s495867298
s296521936
282
247
124,920
111,800
Accepted
Accepted
12.41
from operator import mul from functools import reduce N = int(eval(input())) A = list(map(int,input().split())) def cmb(n, r): if n < r: return 0 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 dic = {} ma = max(A) for i in range(N): if A[i] in dic: dic[A[i]] += 1 else: dic[A[i]] = 1 c = [0 for _ in range(ma + 1)] for i in dic: c[i] = cmb(dic[i], 2) sum_ = sum(c) for i in range(N): ans = sum_ - c[A[i]] + cmb(dic[A[i]] - 1, 2) print(ans)
from operator import mul from functools import reduce N = int(eval(input())) A = list(map(int,input().split())) def cmb(n, r): if n < r: return 0 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 dic = {} for i in range(N): if A[i] in dic: dic[A[i]] += 1 else: dic[A[i]] = 1 sum_ = 0 for i in dic: sum_ += cmb(dic[i], 2) for i in range(N): ans = sum_ - (dic[A[i]] - 1) print(ans)
30
26
625
547
from operator import mul from functools import reduce N = int(eval(input())) A = list(map(int, input().split())) def cmb(n, r): if n < r: return 0 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 dic = {} ma = max(A) for i in range(N): if A[i] in dic: dic[A[i]] += 1 else: dic[A[i]] = 1 c = [0 for _ in range(ma + 1)] for i in dic: c[i] = cmb(dic[i], 2) sum_ = sum(c) for i in range(N): ans = sum_ - c[A[i]] + cmb(dic[A[i]] - 1, 2) print(ans)
from operator import mul from functools import reduce N = int(eval(input())) A = list(map(int, input().split())) def cmb(n, r): if n < r: return 0 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 dic = {} for i in range(N): if A[i] in dic: dic[A[i]] += 1 else: dic[A[i]] = 1 sum_ = 0 for i in dic: sum_ += cmb(dic[i], 2) for i in range(N): ans = sum_ - (dic[A[i]] - 1) print(ans)
false
13.333333
[ "-ma = max(A)", "-c = [0 for _ in range(ma + 1)]", "+sum_ = 0", "- c[i] = cmb(dic[i], 2)", "-sum_ = sum(c)", "+ sum_ += cmb(dic[i], 2)", "- ans = sum_ - c[A[i]] + cmb(dic[A[i]] - 1, 2)", "+ ans = sum_ - (dic[A[i]] - 1)" ]
false
0.157772
0.156349
1.009101
[ "s495867298", "s296521936" ]
u338225045
p03633
python
s112369246
s427663873
63
17
5,560
3,060
Accepted
Accepted
73.02
import fractions import functools N = int( eval(input()) ) T = [ int(eval(input())) for _ in range(N) ] def lcm( x, y ): return x * y // fractions.gcd( x, y ) def lcm_list( numbers ): return functools.reduce( lcm, numbers, 1 ) if N == 1: print(( T[0] )) else : print(( lcm_list(T) ))
N = int( eval(input()) ) T = [ int( eval(input()) ) for _ in range(N) ] # 最小公倍数を求めたい # aとbの最小公倍数 = a*b / aとbの最大公約数 # 最大公約数 (Greatest Common Divisor) def GCD( a, b ): if b == 0: return a return GCD(b, a%b) # 最小公倍数 (Least Common Multiple) def LCM( a, b ): return a*b // GCD(a,b) ans = 1 for i in range(N): ans = LCM( ans, T[i] ) print( ans )
14
19
296
362
import fractions import functools N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] def lcm(x, y): return x * y // fractions.gcd(x, y) def lcm_list(numbers): return functools.reduce(lcm, numbers, 1) if N == 1: print((T[0])) else: print((lcm_list(T)))
N = int(eval(input())) T = [int(eval(input())) for _ in range(N)] # 最小公倍数を求めたい # aとbの最小公倍数 = a*b / aとbの最大公約数 # 最大公約数 (Greatest Common Divisor) def GCD(a, b): if b == 0: return a return GCD(b, a % b) # 最小公倍数 (Least Common Multiple) def LCM(a, b): return a * b // GCD(a, b) ans = 1 for i in range(N): ans = LCM(ans, T[i]) print(ans)
false
26.315789
[ "-import fractions", "-import functools", "-", "+# 最小公倍数を求めたい", "+# aとbの最小公倍数 = a*b / aとbの最大公約数", "+# 最大公約数 (Greatest Common Divisor)", "+def GCD(a, b):", "+ if b == 0:", "+ return a", "+ return GCD(b, a % b)", "-def lcm(x, y):", "- return x * y // fractions.gcd(x, y)", "+# 最小公倍数 (Least Common Multiple)", "+def LCM(a, b):", "+ return a * b // GCD(a, b)", "-def lcm_list(numbers):", "- return functools.reduce(lcm, numbers, 1)", "-", "-", "-if N == 1:", "- print((T[0]))", "-else:", "- print((lcm_list(T)))", "+ans = 1", "+for i in range(N):", "+ ans = LCM(ans, T[i])", "+print(ans)" ]
false
0.045854
0.055201
0.830672
[ "s112369246", "s427663873" ]
u423585790
p02983
python
s765280260
s317167399
610
212
3,700
39,408
Accepted
Accepted
65.25
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x)-1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): n, a, b = LI() print((min(n * a, b))) return #B def B(): n, d = LI() x = LIR(n) a = list(itertools.combinations(list(range(n)), 2)) ans = 0 for a1,a2 in a: b = 0 for bi in range(d): b += (x[a1][bi] - x[a2][bi])** 2 if float.is_integer(math.sqrt(b)): ans += 1 print(ans) return #C def C(): l, r = LI() ans = 2018 if l // 2019 == r // 2019: for i in range(l, r + 1): for k in range(i+1, r + 1): ans = min(ans, (i * k) % 2019) print(ans) else: print((0)) return #D def D(): n = II() a = LI() return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == '__main__': C()
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x)-1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): n, a, b = LI() print((min(n * a, b))) return #B def B(): n, d = LI() x = LIR(n) a = list(itertools.combinations(list(range(n)), 2)) ans = 0 for a1,a2 in a: b = 0 for bi in range(d): b += (x[a1][bi] - x[a2][bi])** 2 if float.is_integer(math.sqrt(b)): ans += 1 print(ans) return #C def C(): l, r = LI() ans = 2018 if l // 2019 == r // 2019: for i in range(l, r + 1): for k in range(i+1, r + 1): ans = min(ans, (i * k) % 2019) print(ans) else: print((0)) return #D def D(): n = II() a = LI() a = a + [a[0]] ans = [0] * n x = 0 for i in range(1, n, 2): x = x + a[i + 1] - a[i] ans[1] = a[0] - x ans[0] = ans[1] + 2 * x for i in range(2, n): ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2 print((" ".join(map(str, ans)))) return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == '__main__': C()
90
100
1,936
2,211
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x) - 1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): n, a, b = LI() print((min(n * a, b))) return # B def B(): n, d = LI() x = LIR(n) a = list(itertools.combinations(list(range(n)), 2)) ans = 0 for a1, a2 in a: b = 0 for bi in range(d): b += (x[a1][bi] - x[a2][bi]) ** 2 if float.is_integer(math.sqrt(b)): ans += 1 print(ans) return # C def C(): l, r = LI() ans = 2018 if l // 2019 == r // 2019: for i in range(l, r + 1): for k in range(i + 1, r + 1): ans = min(ans, (i * k) % 2019) print(ans) else: print((0)) return # D def D(): n = II() a = LI() return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": C()
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list([int(x) - 1 for x in stdin.readline().split()]) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): n, a, b = LI() print((min(n * a, b))) return # B def B(): n, d = LI() x = LIR(n) a = list(itertools.combinations(list(range(n)), 2)) ans = 0 for a1, a2 in a: b = 0 for bi in range(d): b += (x[a1][bi] - x[a2][bi]) ** 2 if float.is_integer(math.sqrt(b)): ans += 1 print(ans) return # C def C(): l, r = LI() ans = 2018 if l // 2019 == r // 2019: for i in range(l, r + 1): for k in range(i + 1, r + 1): ans = min(ans, (i * k) % 2019) print(ans) else: print((0)) return # D def D(): n = II() a = LI() a = a + [a[0]] ans = [0] * n x = 0 for i in range(1, n, 2): x = x + a[i + 1] - a[i] ans[1] = a[0] - x ans[0] = ans[1] + 2 * x for i in range(2, n): ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2 print((" ".join(map(str, ans)))) return # E def E(): return # F def F(): return # G def G(): return # H def H(): return # Solve if __name__ == "__main__": C()
false
10
[ "+ a = a + [a[0]]", "+ ans = [0] * n", "+ x = 0", "+ for i in range(1, n, 2):", "+ x = x + a[i + 1] - a[i]", "+ ans[1] = a[0] - x", "+ ans[0] = ans[1] + 2 * x", "+ for i in range(2, n):", "+ ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2", "+ print((\" \".join(map(str, ans))))" ]
false
0.038927
0.037956
1.02557
[ "s765280260", "s317167399" ]
u249218227
p03494
python
s714350175
s356918778
166
19
38,512
3,060
Accepted
Accepted
88.55
length = int(eval(input())) num_li = list(map(int, input().split())) count = 0 loop = True while True: for i in range(length): if num_li[i]%2 == 1: loop = False break else: num_li[i] /= 2 if loop == False: break else: count += 1 print(count)
length = int(eval(input())) num_li = list(map(int, input().split())) count = 0 loop = True while loop == True: for i in range(length): if num_li[i]%2 == 1: loop = False break else: num_li[i] /= 2 if loop == True: count += 1 print(count)
16
14
330
311
length = int(eval(input())) num_li = list(map(int, input().split())) count = 0 loop = True while True: for i in range(length): if num_li[i] % 2 == 1: loop = False break else: num_li[i] /= 2 if loop == False: break else: count += 1 print(count)
length = int(eval(input())) num_li = list(map(int, input().split())) count = 0 loop = True while loop == True: for i in range(length): if num_li[i] % 2 == 1: loop = False break else: num_li[i] /= 2 if loop == True: count += 1 print(count)
false
12.5
[ "-while True:", "+while loop == True:", "- if loop == False:", "- break", "- else:", "+ if loop == True:" ]
false
0.036926
0.035911
1.028275
[ "s714350175", "s356918778" ]
u566428756
p02780
python
s475744637
s530110505
239
214
25,700
25,700
Accepted
Accepted
10.46
from collections import deque N,K=list(map(int,input().split())) P=list(map(int,input().split())) cnt=0 ans=0 buf=0 buf_2=0 q=deque([]) cnt=0 for i in range(N): cnt+=1 buf=P[i]*(P[i]+1)//2/P[i] q.append(buf) buf_2+=buf if cnt>=K: if ans<buf_2: ans=buf_2 buf_2-=q.popleft() # if len(q)==K: # if sum(q)>ans: # ans=sum(q) # q.popleft() print(ans)
from collections import deque N,K=list(map(int,input().split())) P=list(map(int,input().split())) Ary=deque([]) ans,res,cnt=0,0,0 k=0 for i in range(N): cnt+=1 k=(P[i]+1)/2 Ary.append(k) res+=k if cnt<K: continue if ans<res: ans=res res-=Ary.popleft() print(ans)
24
21
442
324
from collections import deque N, K = list(map(int, input().split())) P = list(map(int, input().split())) cnt = 0 ans = 0 buf = 0 buf_2 = 0 q = deque([]) cnt = 0 for i in range(N): cnt += 1 buf = P[i] * (P[i] + 1) // 2 / P[i] q.append(buf) buf_2 += buf if cnt >= K: if ans < buf_2: ans = buf_2 buf_2 -= q.popleft() # if len(q)==K: # if sum(q)>ans: # ans=sum(q) # q.popleft() print(ans)
from collections import deque N, K = list(map(int, input().split())) P = list(map(int, input().split())) Ary = deque([]) ans, res, cnt = 0, 0, 0 k = 0 for i in range(N): cnt += 1 k = (P[i] + 1) / 2 Ary.append(k) res += k if cnt < K: continue if ans < res: ans = res res -= Ary.popleft() print(ans)
false
12.5
[ "-cnt = 0", "-ans = 0", "-buf = 0", "-buf_2 = 0", "-q = deque([])", "-cnt = 0", "+Ary = deque([])", "+ans, res, cnt = 0, 0, 0", "+k = 0", "- buf = P[i] * (P[i] + 1) // 2 / P[i]", "- q.append(buf)", "- buf_2 += buf", "- if cnt >= K:", "- if ans < buf_2:", "- ans = buf_2", "- buf_2 -= q.popleft()", "- # if len(q)==K:", "- # if sum(q)>ans:", "- # ans=sum(q)", "- # q.popleft()", "+ k = (P[i] + 1) / 2", "+ Ary.append(k)", "+ res += k", "+ if cnt < K:", "+ continue", "+ if ans < res:", "+ ans = res", "+ res -= Ary.popleft()" ]
false
0.063556
0.064241
0.989342
[ "s475744637", "s530110505" ]
u445404615
p03030
python
s889117214
s908017109
182
165
38,256
38,384
Accepted
Accepted
9.34
n = int(eval(input())) l = [] ans = [] for i in range(1, n+1): s, p = input().split() l.append([s, int(p), i]) ans = sorted(l, key=lambda x:(x[0],-x[1])) for j in ans: print((j[2]))
n = int(eval(input())) l = [] for i in range(1, n+1): s, p = input().split() l.append([s, int(p), i]) l = sorted(l, key=lambda x: x[1],reverse=True) l = sorted(l, key=lambda x: x[0]) for j in l: print((j[2]))
12
13
203
235
n = int(eval(input())) l = [] ans = [] for i in range(1, n + 1): s, p = input().split() l.append([s, int(p), i]) ans = sorted(l, key=lambda x: (x[0], -x[1])) for j in ans: print((j[2]))
n = int(eval(input())) l = [] for i in range(1, n + 1): s, p = input().split() l.append([s, int(p), i]) l = sorted(l, key=lambda x: x[1], reverse=True) l = sorted(l, key=lambda x: x[0]) for j in l: print((j[2]))
false
7.692308
[ "-ans = []", "-ans = sorted(l, key=lambda x: (x[0], -x[1]))", "-for j in ans:", "+l = sorted(l, key=lambda x: x[1], reverse=True)", "+l = sorted(l, key=lambda x: x[0])", "+for j in l:" ]
false
0.049568
0.00845
5.865869
[ "s889117214", "s908017109" ]
u692746605
p02678
python
s811141466
s948787270
1,262
653
33,640
34,056
Accepted
Accepted
48.26
def main(): N,M=list(map(int,input().split())) r=[[]for i in range(N)] for i in range(M): a,b=list(map(int,input().split())) r[a-1].append(b-1) r[b-1].append(a-1) p=[-1]*N q=[0] while q: i=q.pop(0) for j in r[i]: if p[j]==-1: p[j]=i q.append(j) print('Yes') for i in range(1,N): print((p[i]+1)) main()
from collections import deque def main(): N,M=list(map(int,input().split())) r=[[]for i in range(N)] for i in range(M): a,b=list(map(int,input().split())) r[a-1].append(b-1) r[b-1].append(a-1) p=[-1]*N q=deque([0]) while q: i=q.popleft() for j in r[i]: if p[j]==-1: p[j]=i q.append(j) print('Yes') for i in range(1,N): print((p[i]+1)) main()
23
25
376
419
def main(): N, M = list(map(int, input().split())) r = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) r[a - 1].append(b - 1) r[b - 1].append(a - 1) p = [-1] * N q = [0] while q: i = q.pop(0) for j in r[i]: if p[j] == -1: p[j] = i q.append(j) print("Yes") for i in range(1, N): print((p[i] + 1)) main()
from collections import deque def main(): N, M = list(map(int, input().split())) r = [[] for i in range(N)] for i in range(M): a, b = list(map(int, input().split())) r[a - 1].append(b - 1) r[b - 1].append(a - 1) p = [-1] * N q = deque([0]) while q: i = q.popleft() for j in r[i]: if p[j] == -1: p[j] = i q.append(j) print("Yes") for i in range(1, N): print((p[i] + 1)) main()
false
8
[ "+from collections import deque", "+", "+", "- q = [0]", "+ q = deque([0])", "- i = q.pop(0)", "+ i = q.popleft()" ]
false
0.038564
0.037022
1.041643
[ "s811141466", "s948787270" ]
u936985471
p02756
python
s693593099
s006499821
261
120
4,396
14,176
Accepted
Accepted
54.02
import sys readline=sys.stdin.readline S=readline().rstrip() Q=int(readline()) cur=True front="" back="" for i in range(Q): q=list(readline().rstrip().split()) if q[0]=="1": cur^=True elif q[0]=="2": f,c=q[1],q[2] if f=="1": if cur: front+=c else: back+=c elif f=="2": if cur: back+=c else: front+=c front=front[::-1] ans=front+S+back if not cur: ans=ans[::-1] print(ans)
import sys readline = sys.stdin.readline S = readline().rstrip() from collections import deque S = deque(S) Q = int(readline()) turn = False for i in range(Q): query = readline().split() if query[0] == "1": turn ^= True elif query[0] == "2": if query[1] == "1": if turn: S.append(query[2]) else: S.appendleft(query[2]) elif query[1] == "2": if turn: S.appendleft(query[2]) else: S.append(query[2]) S = "".join(S) if turn: S = S[::-1] print(S)
32
31
493
555
import sys readline = sys.stdin.readline S = readline().rstrip() Q = int(readline()) cur = True front = "" back = "" for i in range(Q): q = list(readline().rstrip().split()) if q[0] == "1": cur ^= True elif q[0] == "2": f, c = q[1], q[2] if f == "1": if cur: front += c else: back += c elif f == "2": if cur: back += c else: front += c front = front[::-1] ans = front + S + back if not cur: ans = ans[::-1] print(ans)
import sys readline = sys.stdin.readline S = readline().rstrip() from collections import deque S = deque(S) Q = int(readline()) turn = False for i in range(Q): query = readline().split() if query[0] == "1": turn ^= True elif query[0] == "2": if query[1] == "1": if turn: S.append(query[2]) else: S.appendleft(query[2]) elif query[1] == "2": if turn: S.appendleft(query[2]) else: S.append(query[2]) S = "".join(S) if turn: S = S[::-1] print(S)
false
3.125
[ "+from collections import deque", "+", "+S = deque(S)", "-cur = True", "-front = \"\"", "-back = \"\"", "+turn = False", "- q = list(readline().rstrip().split())", "- if q[0] == \"1\":", "- cur ^= True", "- elif q[0] == \"2\":", "- f, c = q[1], q[2]", "- if f == \"1\":", "- if cur:", "- front += c", "+ query = readline().split()", "+ if query[0] == \"1\":", "+ turn ^= True", "+ elif query[0] == \"2\":", "+ if query[1] == \"1\":", "+ if turn:", "+ S.append(query[2])", "- back += c", "- elif f == \"2\":", "- if cur:", "- back += c", "+ S.appendleft(query[2])", "+ elif query[1] == \"2\":", "+ if turn:", "+ S.appendleft(query[2])", "- front += c", "-front = front[::-1]", "-ans = front + S + back", "-if not cur:", "- ans = ans[::-1]", "-print(ans)", "+ S.append(query[2])", "+S = \"\".join(S)", "+if turn:", "+ S = S[::-1]", "+print(S)" ]
false
0.037972
0.045172
0.84061
[ "s693593099", "s006499821" ]
u850491413
p03835
python
s573464276
s261598208
270
166
40,796
38,768
Accepted
Accepted
38.52
K, S = list(map(int, input().split())) num = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if z <= K and 0 <= z: num += 1 print(num)
K, S = list(map(int, input().split())) num = 0 for x in range(K + 1): rest = S - x if 0 <= rest and rest <= K: num += rest + 1 elif K < rest and rest <=2*K: num += 2*K + 1 - rest print(num)
9
10
165
206
K, S = list(map(int, input().split())) num = 0 for x in range(K + 1): for y in range(K + 1): z = S - x - y if z <= K and 0 <= z: num += 1 print(num)
K, S = list(map(int, input().split())) num = 0 for x in range(K + 1): rest = S - x if 0 <= rest and rest <= K: num += rest + 1 elif K < rest and rest <= 2 * K: num += 2 * K + 1 - rest print(num)
false
10
[ "- for y in range(K + 1):", "- z = S - x - y", "- if z <= K and 0 <= z:", "- num += 1", "+ rest = S - x", "+ if 0 <= rest and rest <= K:", "+ num += rest + 1", "+ elif K < rest and rest <= 2 * K:", "+ num += 2 * K + 1 - rest" ]
false
0.034661
0.04033
0.859425
[ "s573464276", "s261598208" ]
u148981246
p02732
python
s450497050
s748044527
1,939
258
33,920
33,912
Accepted
Accepted
86.69
import collections import math def cmb_factorial(s): return math.factorial(s) // (math.factorial(2) * math.factorial(s - 2)) n = int(eval(input())) a = list(map(int, input().split())) c = collections.Counter(a) f = {} cmb = 0 for x in list(c.values()): f[1] = 0 f[2] = 1 if x >= 3: f[x] = cmb_factorial(x) if x - 1 not in f: f[x - 1] = cmb_factorial(x - 1) cmb += f.get(x) for z in a: y = c.get(z) ans = cmb if y >= 2: ans = cmb - f.get(y) + f.get(y - 1) print(ans)
import collections n = int(eval(input())) a = list(map(int, input().split())) c = collections.Counter(a) cmb = 0 for x in list(c.values()): cmb += x * (x - 1) // 2 for z in a: y = c.get(z) before = y * (y - 1) // 2 after = (y - 1) * (y - 2) //2 ans = cmb - before + after print(ans)
27
16
555
316
import collections import math def cmb_factorial(s): return math.factorial(s) // (math.factorial(2) * math.factorial(s - 2)) n = int(eval(input())) a = list(map(int, input().split())) c = collections.Counter(a) f = {} cmb = 0 for x in list(c.values()): f[1] = 0 f[2] = 1 if x >= 3: f[x] = cmb_factorial(x) if x - 1 not in f: f[x - 1] = cmb_factorial(x - 1) cmb += f.get(x) for z in a: y = c.get(z) ans = cmb if y >= 2: ans = cmb - f.get(y) + f.get(y - 1) print(ans)
import collections n = int(eval(input())) a = list(map(int, input().split())) c = collections.Counter(a) cmb = 0 for x in list(c.values()): cmb += x * (x - 1) // 2 for z in a: y = c.get(z) before = y * (y - 1) // 2 after = (y - 1) * (y - 2) // 2 ans = cmb - before + after print(ans)
false
40.740741
[ "-import math", "-", "-", "-def cmb_factorial(s):", "- return math.factorial(s) // (math.factorial(2) * math.factorial(s - 2))", "-", "-f = {}", "- f[1] = 0", "- f[2] = 1", "- if x >= 3:", "- f[x] = cmb_factorial(x)", "- if x - 1 not in f:", "- f[x - 1] = cmb_factorial(x - 1)", "- cmb += f.get(x)", "+ cmb += x * (x - 1) // 2", "- ans = cmb", "- if y >= 2:", "- ans = cmb - f.get(y) + f.get(y - 1)", "+ before = y * (y - 1) // 2", "+ after = (y - 1) * (y - 2) // 2", "+ ans = cmb - before + after" ]
false
0.150325
0.036595
4.107825
[ "s450497050", "s748044527" ]
u991567869
p02598
python
s685529261
s929322825
1,145
987
31,036
31,228
Accepted
Accepted
13.8
n, k = list(map(int, input().split())) a = list(map(int, input().split())) l = 0 r = 10**9 + 1 ref = 0 ans = 10**9 while r - l > 1: now = (l + r)//2 for i in a: ref += 0 - -i//now - 1 if ref > k: ref = 0 l = now break else: ans = now ref = 0 r = now print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) l = 0 r = 10**9 + 1 ref = 0 ans = 10**9 while r - l > 1: now = (l + r)//2 for i in a: ref += 0 - -i//now - 1 if ref <= k: ans = now ref = 0 r = now else: ref = 0 l = now print(ans)
21
20
364
334
n, k = list(map(int, input().split())) a = list(map(int, input().split())) l = 0 r = 10**9 + 1 ref = 0 ans = 10**9 while r - l > 1: now = (l + r) // 2 for i in a: ref += 0 - -i // now - 1 if ref > k: ref = 0 l = now break else: ans = now ref = 0 r = now print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) l = 0 r = 10**9 + 1 ref = 0 ans = 10**9 while r - l > 1: now = (l + r) // 2 for i in a: ref += 0 - -i // now - 1 if ref <= k: ans = now ref = 0 r = now else: ref = 0 l = now print(ans)
false
4.761905
[ "- if ref > k:", "- ref = 0", "- l = now", "- break", "- else:", "+ if ref <= k:", "+ else:", "+ ref = 0", "+ l = now" ]
false
0.042107
0.03673
1.146392
[ "s685529261", "s929322825" ]
u453055089
p03165
python
s684623967
s485367577
490
350
112,988
138,976
Accepted
Accepted
28.57
s = eval(input()) t = eval(input()) len_s = len(s) len_t = len(t) dp = [[0]*(len_t+1) for _ in range(len_s+1)] # dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ for i in range(len_s): for j in range(len_t): if s[i] == t[j]: dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1]) #print(dp) ans = "" while len_t > 0 and len_s > 0: if dp[len_s][len_t] == dp[len_s-1][len_t]: len_s -= 1 elif dp[len_s][len_t] == dp[len_s][len_t-1]: len_t -= 1 else: ans += s[len_s-1] len_s -= 1 len_t -= 1 print((ans[::-1]))
s = eval(input()) t = eval(input()) n_s = len(s) n_t = len(t) dp = [[0]*(n_t+1) for _ in range(n_s+1)] #dp[i][j]はsのi文字目までとtのj文字目までのLCSの長さ for i in range(n_s+1): for j in range(n_t+1): if i == 0 or j == 0: continue dp[i][j] = max(dp[i-1][j], dp[i][j-1]) if s[i-1] == t[j-1]: dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1) sna = "" while n_s > 0 and n_t > 0: if dp[n_s][n_t] == dp[n_s-1][n_t]: n_s -= 1 elif dp[n_s][n_t] == dp[n_s][n_t-1]: n_t -= 1 else: sna += s[n_s-1] n_s -= 1 n_t -= 1 ans = "" for i in range(len(sna))[::-1]: ans += sna[i] print(ans)
24
30
646
674
s = eval(input()) t = eval(input()) len_s = len(s) len_t = len(t) dp = [[0] * (len_t + 1) for _ in range(len_s + 1)] # dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ for i in range(len_s): for j in range(len_t): if s[i] == t[j]: dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1]) # print(dp) ans = "" while len_t > 0 and len_s > 0: if dp[len_s][len_t] == dp[len_s - 1][len_t]: len_s -= 1 elif dp[len_s][len_t] == dp[len_s][len_t - 1]: len_t -= 1 else: ans += s[len_s - 1] len_s -= 1 len_t -= 1 print((ans[::-1]))
s = eval(input()) t = eval(input()) n_s = len(s) n_t = len(t) dp = [[0] * (n_t + 1) for _ in range(n_s + 1)] # dp[i][j]はsのi文字目までとtのj文字目までのLCSの長さ for i in range(n_s + 1): for j in range(n_t + 1): if i == 0 or j == 0: continue dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) if s[i - 1] == t[j - 1]: dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1) sna = "" while n_s > 0 and n_t > 0: if dp[n_s][n_t] == dp[n_s - 1][n_t]: n_s -= 1 elif dp[n_s][n_t] == dp[n_s][n_t - 1]: n_t -= 1 else: sna += s[n_s - 1] n_s -= 1 n_t -= 1 ans = "" for i in range(len(sna))[::-1]: ans += sna[i] print(ans)
false
20
[ "-len_s = len(s)", "-len_t = len(t)", "-dp = [[0] * (len_t + 1) for _ in range(len_s + 1)]", "-# dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ", "-for i in range(len_s):", "- for j in range(len_t):", "- if s[i] == t[j]:", "- dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])", "- dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1])", "-# print(dp)", "+n_s = len(s)", "+n_t = len(t)", "+dp = [[0] * (n_t + 1) for _ in range(n_s + 1)]", "+# dp[i][j]はsのi文字目までとtのj文字目までのLCSの長さ", "+for i in range(n_s + 1):", "+ for j in range(n_t + 1):", "+ if i == 0 or j == 0:", "+ continue", "+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])", "+ if s[i - 1] == t[j - 1]:", "+ dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)", "+sna = \"\"", "+while n_s > 0 and n_t > 0:", "+ if dp[n_s][n_t] == dp[n_s - 1][n_t]:", "+ n_s -= 1", "+ elif dp[n_s][n_t] == dp[n_s][n_t - 1]:", "+ n_t -= 1", "+ else:", "+ sna += s[n_s - 1]", "+ n_s -= 1", "+ n_t -= 1", "-while len_t > 0 and len_s > 0:", "- if dp[len_s][len_t] == dp[len_s - 1][len_t]:", "- len_s -= 1", "- elif dp[len_s][len_t] == dp[len_s][len_t - 1]:", "- len_t -= 1", "- else:", "- ans += s[len_s - 1]", "- len_s -= 1", "- len_t -= 1", "-print((ans[::-1]))", "+for i in range(len(sna))[::-1]:", "+ ans += sna[i]", "+print(ans)" ]
false
0.081859
0.084958
0.963522
[ "s684623967", "s485367577" ]
u952708174
p03964
python
s765777806
s825489002
101
21
5,588
3,188
Accepted
Accepted
79.21
def c_AtCoDeer_and_ElectionReport(N, R): from math import ceil from decimal import Decimal t = 1 # 高橋の票数 a = 1 # 青木の票数 for x, y in R: n = Decimal(max(ceil(t / x), ceil(a / y))) t = n * x a = n * y return t + a N = int(eval(input())) R = [[int(i) for i in input().split()] for j in range(N)] print((c_AtCoDeer_and_ElectionReport(N, R)))
def c_atcodeer_and_election_report(N, R): t, a = 1, 1 # 高橋, 青木の票数 for x, y in R: # t<=nx ∧ a<=ny を満たす最小のnを求める n = max(t // x, a // y) if t > n * x or a > n * y: n += 1 t = n * x a = n * y return t + a N = int(eval(input())) R = [[int(i) for i in input().split()] for j in range(N)] print((c_atcodeer_and_election_report(N, R)))
14
14
391
398
def c_AtCoDeer_and_ElectionReport(N, R): from math import ceil from decimal import Decimal t = 1 # 高橋の票数 a = 1 # 青木の票数 for x, y in R: n = Decimal(max(ceil(t / x), ceil(a / y))) t = n * x a = n * y return t + a N = int(eval(input())) R = [[int(i) for i in input().split()] for j in range(N)] print((c_AtCoDeer_and_ElectionReport(N, R)))
def c_atcodeer_and_election_report(N, R): t, a = 1, 1 # 高橋, 青木の票数 for x, y in R: # t<=nx ∧ a<=ny を満たす最小のnを求める n = max(t // x, a // y) if t > n * x or a > n * y: n += 1 t = n * x a = n * y return t + a N = int(eval(input())) R = [[int(i) for i in input().split()] for j in range(N)] print((c_atcodeer_and_election_report(N, R)))
false
0
[ "-def c_AtCoDeer_and_ElectionReport(N, R):", "- from math import ceil", "- from decimal import Decimal", "-", "- t = 1 # 高橋の票数", "- a = 1 # 青木の票数", "+def c_atcodeer_and_election_report(N, R):", "+ t, a = 1, 1 # 高橋, 青木の票数", "- n = Decimal(max(ceil(t / x), ceil(a / y)))", "+ # t<=nx ∧ a<=ny を満たす最小のnを求める", "+ n = max(t // x, a // y)", "+ if t > n * x or a > n * y:", "+ n += 1", "-print((c_AtCoDeer_and_ElectionReport(N, R)))", "+print((c_atcodeer_and_election_report(N, R)))" ]
false
0.039937
0.036783
1.085759
[ "s765777806", "s825489002" ]
u762420987
p02768
python
s306649940
s616372199
180
110
38,768
3,064
Accepted
Accepted
38.89
def sq(a, b, mod): # aのb乗を剰余,kは初期値#20191116-D-Knight if b == 0: return 1 elif b % 2 == 0: return sq(a, b // 2, mod)**2 % mod else: return sq(a, b - 1, mod) * a % mod def nCk(n, k, mod=10 ** 9 + 7): x = max(k, n - k) y = min(k, n - k) kkai = 1 for i in range(2, y + 1): kkai = (kkai * i) % mod nkkai = 1 for i in range(x + 1, n + 1): nkkai = (nkkai * i) % mod answer = sq(kkai, mod - 2, mod) * nkkai % mod return answer mod = 10**9+7 n, a, b = list(map(int, input().split())) def modpow(x, y): res = 1 while y > 0: if y & 1: res = res*x % (10**9+7) x = x*x%(10**9+7) y >>= 1 y = int(y) return res ans = 0 ans -= nCk(n, b) ans -= nCk(n, a) ans -= 1 ans += modpow(2, n) print(((ans+10**9+7)%(10**9+7)))
def sq(a, b, mod): # aのb乗を剰余,kは初期値#20191116-D-Knight if b == 0: return 1 elif b % 2 == 0: return sq(a, b // 2, mod)**2 % mod else: return sq(a, b - 1, mod) * a % mod def nCk(n, k, mod=10 ** 9 + 7): x = max(k, n - k) y = min(k, n - k) kkai = 1 for i in range(2, y + 1): kkai = (kkai * i) % mod nkkai = 1 for i in range(x + 1, n + 1): nkkai = (nkkai * i) % mod answer = sq(kkai, mod - 2, mod) * nkkai % mod return answer n, a, b = list(map(int, input().split())) mod = 10**9 + 7 ans = pow(2, n, mod) + mod ans -= nCk(n, a) ans -= nCk(n, b) print(((ans-1)%mod))
39
27
874
665
def sq(a, b, mod): # aのb乗を剰余,kは初期値#20191116-D-Knight if b == 0: return 1 elif b % 2 == 0: return sq(a, b // 2, mod) ** 2 % mod else: return sq(a, b - 1, mod) * a % mod def nCk(n, k, mod=10**9 + 7): x = max(k, n - k) y = min(k, n - k) kkai = 1 for i in range(2, y + 1): kkai = (kkai * i) % mod nkkai = 1 for i in range(x + 1, n + 1): nkkai = (nkkai * i) % mod answer = sq(kkai, mod - 2, mod) * nkkai % mod return answer mod = 10**9 + 7 n, a, b = list(map(int, input().split())) def modpow(x, y): res = 1 while y > 0: if y & 1: res = res * x % (10**9 + 7) x = x * x % (10**9 + 7) y >>= 1 y = int(y) return res ans = 0 ans -= nCk(n, b) ans -= nCk(n, a) ans -= 1 ans += modpow(2, n) print(((ans + 10**9 + 7) % (10**9 + 7)))
def sq(a, b, mod): # aのb乗を剰余,kは初期値#20191116-D-Knight if b == 0: return 1 elif b % 2 == 0: return sq(a, b // 2, mod) ** 2 % mod else: return sq(a, b - 1, mod) * a % mod def nCk(n, k, mod=10**9 + 7): x = max(k, n - k) y = min(k, n - k) kkai = 1 for i in range(2, y + 1): kkai = (kkai * i) % mod nkkai = 1 for i in range(x + 1, n + 1): nkkai = (nkkai * i) % mod answer = sq(kkai, mod - 2, mod) * nkkai % mod return answer n, a, b = list(map(int, input().split())) mod = 10**9 + 7 ans = pow(2, n, mod) + mod ans -= nCk(n, a) ans -= nCk(n, b) print(((ans - 1) % mod))
false
30.769231
[ "+n, a, b = list(map(int, input().split()))", "-n, a, b = list(map(int, input().split()))", "-", "-", "-def modpow(x, y):", "- res = 1", "- while y > 0:", "- if y & 1:", "- res = res * x % (10**9 + 7)", "- x = x * x % (10**9 + 7)", "- y >>= 1", "- y = int(y)", "- return res", "-", "-", "-ans = 0", "+ans = pow(2, n, mod) + mod", "+ans -= nCk(n, a)", "-ans -= nCk(n, a)", "-ans -= 1", "-ans += modpow(2, n)", "-print(((ans + 10**9 + 7) % (10**9 + 7)))", "+print(((ans - 1) % mod))" ]
false
0.201825
0.21477
0.939728
[ "s306649940", "s616372199" ]
u119148115
p03264
python
s183136261
s211093742
75
65
61,912
61,728
Accepted
Accepted
13.33
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()) #空白なし K = I() a = K//2 b = K-a print((a*b))
import sys def I(): return int(sys.stdin.readline().rstrip()) K = I() print(((K//2)*(K-K//2)))
16
6
531
100
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()) # 空白なし K = I() a = K // 2 b = K - a print((a * b))
import sys def I(): return int(sys.stdin.readline().rstrip()) K = I() print(((K // 2) * (K - K // 2)))
false
62.5
[ "-", "-sys.setrecursionlimit(10**7)", "-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()) # 空白なし", "-", "-", "-a = K // 2", "-b = K - a", "-print((a * b))", "+print(((K // 2) * (K - K // 2)))" ]
false
0.036155
0.036452
0.991827
[ "s183136261", "s211093742" ]
u607865971
p03253
python
s339716093
s491605414
812
19
40,044
3,064
Accepted
Accepted
97.66
import math N, M = [int(x) for x in input().split()] MOD = 10 ** 9 + 7 divisor = [] dict = {} m = M d = 2 while m != 1: while m % d == 0: # divisor.append(d) m //= d dict[d] = dict.get(d, 0) + 1 d += 1 C = list(dict.values()) ret = 1 # def combinations_count(n, r): # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def combinations_count(n, r): a = max(r, n-r) b = min(r, n-r) r = 1 for i in range(a+1, n+1): r *= i return r // math.factorial(b) for c in C: ret *= combinations_count(c + N - 1, c) ret %= MOD print(ret)
import math N, M = [int(x) for x in input().split()] MOD = 10 ** 9 + 7 divisor = [] dict = {} m = M d = 2 while d*d <= m: while m % d == 0: m //= d dict[d] = dict.get(d, 0) + 1 d += 1 if m > 1: dict[d] = dict.get(m, 0) + 1 C = list(dict.values()) ret = 1 # def combinations_count(n, r): # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def combinations_count(n, r): a = max(r, n-r) b = min(r, n-r) r = 1 for i in range(a+1, n+1): r *= i return r // math.factorial(b) for c in C: ret *= combinations_count(c + N - 1, c) ret %= MOD print(ret)
37
39
656
676
import math N, M = [int(x) for x in input().split()] MOD = 10**9 + 7 divisor = [] dict = {} m = M d = 2 while m != 1: while m % d == 0: # divisor.append(d) m //= d dict[d] = dict.get(d, 0) + 1 d += 1 C = list(dict.values()) ret = 1 # def combinations_count(n, r): # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def combinations_count(n, r): a = max(r, n - r) b = min(r, n - r) r = 1 for i in range(a + 1, n + 1): r *= i return r // math.factorial(b) for c in C: ret *= combinations_count(c + N - 1, c) ret %= MOD print(ret)
import math N, M = [int(x) for x in input().split()] MOD = 10**9 + 7 divisor = [] dict = {} m = M d = 2 while d * d <= m: while m % d == 0: m //= d dict[d] = dict.get(d, 0) + 1 d += 1 if m > 1: dict[d] = dict.get(m, 0) + 1 C = list(dict.values()) ret = 1 # def combinations_count(n, r): # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def combinations_count(n, r): a = max(r, n - r) b = min(r, n - r) r = 1 for i in range(a + 1, n + 1): r *= i return r // math.factorial(b) for c in C: ret *= combinations_count(c + N - 1, c) ret %= MOD print(ret)
false
5.128205
[ "-while m != 1:", "+while d * d <= m:", "- # divisor.append(d)", "+if m > 1:", "+ dict[d] = dict.get(m, 0) + 1" ]
false
0.073894
0.043686
1.691476
[ "s339716093", "s491605414" ]
u437351386
p03087
python
s832934031
s759150098
500
312
17,508
23,116
Accepted
Accepted
37.6
from itertools import accumulate n,q=list(map(int,input().split())) s=eval(input()) l=[0]*q r=[0]*q for i in range(q): l[i],r[i]=list(map(int,input().split())) L=min(l) R=max(r) #前処理 A=[] for i in range(L,R): if s[i-1]=="A"and s[i]=="C": A.append(1) else: A.append(0) A.append(0) s=[0]+A S=list(accumulate(s)) #累積和 for i in range(q): print((S[r[i]-L]-S[l[i]-L]))
from itertools import accumulate n,q=list(map(int,input().split())) s=list(eval(input())) l=[] r=[] for i in range(q): o,p=list(map(int,input().split())) l.append(o) r.append(p) ruiseki=[] for i in range(n-1): if s[i]=="A" and s[i+1]=="C": ruiseki.append(1) else: ruiseki.append(0) ruiseki=[0]+list(accumulate(ruiseki)) for i in range(q): print((ruiseki[r[i]-1]-ruiseki[l[i]-1]))
27
22
430
424
from itertools import accumulate n, q = list(map(int, input().split())) s = eval(input()) l = [0] * q r = [0] * q for i in range(q): l[i], r[i] = list(map(int, input().split())) L = min(l) R = max(r) # 前処理 A = [] for i in range(L, R): if s[i - 1] == "A" and s[i] == "C": A.append(1) else: A.append(0) A.append(0) s = [0] + A S = list(accumulate(s)) # 累積和 for i in range(q): print((S[r[i] - L] - S[l[i] - L]))
from itertools import accumulate n, q = list(map(int, input().split())) s = list(eval(input())) l = [] r = [] for i in range(q): o, p = list(map(int, input().split())) l.append(o) r.append(p) ruiseki = [] for i in range(n - 1): if s[i] == "A" and s[i + 1] == "C": ruiseki.append(1) else: ruiseki.append(0) ruiseki = [0] + list(accumulate(ruiseki)) for i in range(q): print((ruiseki[r[i] - 1] - ruiseki[l[i] - 1]))
false
18.518519
[ "-s = eval(input())", "-l = [0] * q", "-r = [0] * q", "+s = list(eval(input()))", "+l = []", "+r = []", "- l[i], r[i] = list(map(int, input().split()))", "-L = min(l)", "-R = max(r)", "-# 前処理", "-A = []", "-for i in range(L, R):", "- if s[i - 1] == \"A\" and s[i] == \"C\":", "- A.append(1)", "+ o, p = list(map(int, input().split()))", "+ l.append(o)", "+ r.append(p)", "+ruiseki = []", "+for i in range(n - 1):", "+ if s[i] == \"A\" and s[i + 1] == \"C\":", "+ ruiseki.append(1)", "- A.append(0)", "-A.append(0)", "-s = [0] + A", "-S = list(accumulate(s))", "-# 累積和", "+ ruiseki.append(0)", "+ruiseki = [0] + list(accumulate(ruiseki))", "- print((S[r[i] - L] - S[l[i] - L]))", "+ print((ruiseki[r[i] - 1] - ruiseki[l[i] - 1]))" ]
false
0.044656
0.039677
1.125486
[ "s832934031", "s759150098" ]
u321035578
p03160
python
s069075348
s648923478
243
100
52,208
13,980
Accepted
Accepted
58.85
def main(): n=int(eval(input())) h=list(map(int,input().split())) dp=[None]*n dp[0]=0 dp[1]=abs(h[1]-h[0]) for i in range(2,n): temp2=dp[i-2]+abs(h[i]-h[i-2]) temp1=dp[i-1]+abs(h[i]-h[i-1]) dp[i]=min(temp1,temp2) print((dp[n-1])) if __name__=='__main__': main()
def main(): n = int(eval(input())) h = list(map(int,input().split())) dp = [0] * (n + 1) dp[1] = abs(h[1]-h[0]) for i in range(2,n): dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])) print((dp[n-1])) if __name__=='__main__': main()
16
12
328
295
def main(): n = int(eval(input())) h = list(map(int, input().split())) dp = [None] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): temp2 = dp[i - 2] + abs(h[i] - h[i - 2]) temp1 = dp[i - 1] + abs(h[i] - h[i - 1]) dp[i] = min(temp1, temp2) print((dp[n - 1])) if __name__ == "__main__": main()
def main(): n = int(eval(input())) h = list(map(int, input().split())) dp = [0] * (n + 1) dp[1] = abs(h[1] - h[0]) for i in range(2, n): dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1])) print((dp[n - 1])) if __name__ == "__main__": main()
false
25
[ "- dp = [None] * n", "- dp[0] = 0", "+ dp = [0] * (n + 1)", "- temp2 = dp[i - 2] + abs(h[i] - h[i - 2])", "- temp1 = dp[i - 1] + abs(h[i] - h[i - 1])", "- dp[i] = min(temp1, temp2)", "+ dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))" ]
false
0.040841
0.036848
1.108354
[ "s069075348", "s648923478" ]
u842747358
p03378
python
s140771837
s798013576
19
17
3,188
2,940
Accepted
Accepted
10.53
N, M, X = list(map(int, input().split())) A = list(map(int, input().split())) to_0 = 0 if A[-1] < X: to_0 = M to_N = 0 elif A[0] < X < A[-1]: for i in A: if i < X: to_0 += 1 to_N = M - to_0 elif X < A[0]: to_0 = 0 to_N = M print((min(to_0, to_N)))
n, m, x = list(map(int, input().split())) a = list(map(int, input().split())) left = 0 right = 0 for ai in a: if ai < x: left += 1 else: right += 1 print((min(left, right)))
16
12
299
203
N, M, X = list(map(int, input().split())) A = list(map(int, input().split())) to_0 = 0 if A[-1] < X: to_0 = M to_N = 0 elif A[0] < X < A[-1]: for i in A: if i < X: to_0 += 1 to_N = M - to_0 elif X < A[0]: to_0 = 0 to_N = M print((min(to_0, to_N)))
n, m, x = list(map(int, input().split())) a = list(map(int, input().split())) left = 0 right = 0 for ai in a: if ai < x: left += 1 else: right += 1 print((min(left, right)))
false
25
[ "-N, M, X = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-to_0 = 0", "-if A[-1] < X:", "- to_0 = M", "- to_N = 0", "-elif A[0] < X < A[-1]:", "- for i in A:", "- if i < X:", "- to_0 += 1", "- to_N = M - to_0", "-elif X < A[0]:", "- to_0 = 0", "- to_N = M", "-print((min(to_0, to_N)))", "+n, m, x = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+left = 0", "+right = 0", "+for ai in a:", "+ if ai < x:", "+ left += 1", "+ else:", "+ right += 1", "+print((min(left, right)))" ]
false
0.079567
0.070248
1.132653
[ "s140771837", "s798013576" ]
u860002137
p03611
python
s485443561
s744691608
160
120
30,172
23,600
Accepted
Accepted
25
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) for i in range(N): a.append(a[i]+1) a.append(a[i]-1) ans = Counter(a) print((ans.most_common()[0][1]))
from collections import defaultdict n = int(eval(input())) arr = list(map(int, input().split())) d = defaultdict(int) for x in arr: d[x] += 1 d[x - 1] += 1 d[x + 1] += 1 result = [y for x, y in list(d.items())] print((max(result)))
12
15
208
248
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) for i in range(N): a.append(a[i] + 1) a.append(a[i] - 1) ans = Counter(a) print((ans.most_common()[0][1]))
from collections import defaultdict n = int(eval(input())) arr = list(map(int, input().split())) d = defaultdict(int) for x in arr: d[x] += 1 d[x - 1] += 1 d[x + 1] += 1 result = [y for x, y in list(d.items())] print((max(result)))
false
20
[ "-from collections import Counter", "+from collections import defaultdict", "-N = int(eval(input()))", "-a = list(map(int, input().split()))", "-for i in range(N):", "- a.append(a[i] + 1)", "- a.append(a[i] - 1)", "-ans = Counter(a)", "-print((ans.most_common()[0][1]))", "+n = int(eval(input()))", "+arr = list(map(int, input().split()))", "+d = defaultdict(int)", "+for x in arr:", "+ d[x] += 1", "+ d[x - 1] += 1", "+ d[x + 1] += 1", "+result = [y for x, y in list(d.items())]", "+print((max(result)))" ]
false
0.045543
0.041525
1.096771
[ "s485443561", "s744691608" ]
u312025627
p03545
python
s060178688
s504159601
196
18
38,384
3,064
Accepted
Accepted
90.82
def main(): S = input() for bit in range(1 << 3): calc_v = int(S[0]) ans = [S[0]] for i in range(3): if bit & (1 << i): calc_v += int(S[i+1]) ans.append("+") ans.append(S[i+1]) else: calc_v -= int(S[i+1]) ans.append("-") ans.append(S[i+1]) if calc_v == 7: return print("".join(ans)+"=7") if __name__ == '__main__': main()
def main(): S = input() for bit in range(1 << 3): ans = int(S[0]) T = S[0] for i in range(3): if bit & (1 << i): ans += int(S[i+1]) T += "+"+S[i+1] else: ans -= int(S[i+1]) T += "-"+S[i+1] if ans == 7: return print(T+"=7") if __name__ == '__main__': main()
20
18
519
420
def main(): S = input() for bit in range(1 << 3): calc_v = int(S[0]) ans = [S[0]] for i in range(3): if bit & (1 << i): calc_v += int(S[i + 1]) ans.append("+") ans.append(S[i + 1]) else: calc_v -= int(S[i + 1]) ans.append("-") ans.append(S[i + 1]) if calc_v == 7: return print("".join(ans) + "=7") if __name__ == "__main__": main()
def main(): S = input() for bit in range(1 << 3): ans = int(S[0]) T = S[0] for i in range(3): if bit & (1 << i): ans += int(S[i + 1]) T += "+" + S[i + 1] else: ans -= int(S[i + 1]) T += "-" + S[i + 1] if ans == 7: return print(T + "=7") if __name__ == "__main__": main()
false
10
[ "- calc_v = int(S[0])", "- ans = [S[0]]", "+ ans = int(S[0])", "+ T = S[0]", "- calc_v += int(S[i + 1])", "- ans.append(\"+\")", "- ans.append(S[i + 1])", "+ ans += int(S[i + 1])", "+ T += \"+\" + S[i + 1]", "- calc_v -= int(S[i + 1])", "- ans.append(\"-\")", "- ans.append(S[i + 1])", "- if calc_v == 7:", "- return print(\"\".join(ans) + \"=7\")", "+ ans -= int(S[i + 1])", "+ T += \"-\" + S[i + 1]", "+ if ans == 7:", "+ return print(T + \"=7\")" ]
false
0.037227
0.053964
0.689861
[ "s060178688", "s504159601" ]
u089376182
p02946
python
s526419928
s912695727
149
17
12,396
3,060
Accepted
Accepted
88.59
import numpy as np k, x = map(int, input().split()) upper = x + k - 1 lower = x - k + 1 if lower == upper: print(lower) else: for i in range(lower, upper + 1): print(i, end = " ")
k, x = map(int, input().split()) lower = x - k + 1 upper = x + k - 1 for i in range(lower, upper + 1): print(i, end = " ")
12
6
202
130
import numpy as np k, x = map(int, input().split()) upper = x + k - 1 lower = x - k + 1 if lower == upper: print(lower) else: for i in range(lower, upper + 1): print(i, end=" ")
k, x = map(int, input().split()) lower = x - k + 1 upper = x + k - 1 for i in range(lower, upper + 1): print(i, end=" ")
false
50
[ "-import numpy as np", "-", "+lower = x - k + 1", "-lower = x - k + 1", "-if lower == upper:", "- print(lower)", "-else:", "- for i in range(lower, upper + 1):", "- print(i, end=\" \")", "+for i in range(lower, upper + 1):", "+ print(i, end=\" \")" ]
false
0.036124
0.081614
0.442615
[ "s526419928", "s912695727" ]
u096616343
p03241
python
s699641740
s892338207
489
171
40,044
38,640
Accepted
Accepted
65.03
N, M = list(map(int,input().split())) for i in range(M // N, 0, -1): if M % i == 0: print(i) break
N, M = list(map(int,input().split())) lim = M // N ans = 0 for i in range(1, int(M ** (1/2)) + 1): if M % i == 0: if ans < i <= lim: ans = i if ans < M // i <= lim: ans = M // i print(ans)
5
10
116
235
N, M = list(map(int, input().split())) for i in range(M // N, 0, -1): if M % i == 0: print(i) break
N, M = list(map(int, input().split())) lim = M // N ans = 0 for i in range(1, int(M ** (1 / 2)) + 1): if M % i == 0: if ans < i <= lim: ans = i if ans < M // i <= lim: ans = M // i print(ans)
false
50
[ "-for i in range(M // N, 0, -1):", "+lim = M // N", "+ans = 0", "+for i in range(1, int(M ** (1 / 2)) + 1):", "- print(i)", "- break", "+ if ans < i <= lim:", "+ ans = i", "+ if ans < M // i <= lim:", "+ ans = M // i", "+print(ans)" ]
false
0.110677
0.063603
1.740133
[ "s699641740", "s892338207" ]
u469700628
p03369
python
s090159846
s359979947
24
17
3,684
2,940
Accepted
Accepted
29.17
from functools import reduce order = eval(input()) res = 700 + reduce(lambda x, y: x + y, [100 if x == "o" else 0 for x in list(order)]) print(res)
# from functools import reduce order = eval(input()) res = 700 # res = 700 + reduce(lambda x, y: x + y, # map(lambda x: 100 if x == "o" else 0, list(order))) for i in order: if i == "o": res += 100 print(res)
6
10
171
243
from functools import reduce order = eval(input()) res = 700 + reduce(lambda x, y: x + y, [100 if x == "o" else 0 for x in list(order)]) print(res)
# from functools import reduce order = eval(input()) res = 700 # res = 700 + reduce(lambda x, y: x + y, # map(lambda x: 100 if x == "o" else 0, list(order))) for i in order: if i == "o": res += 100 print(res)
false
40
[ "-from functools import reduce", "-", "+# from functools import reduce", "-res = 700 + reduce(lambda x, y: x + y, [100 if x == \"o\" else 0 for x in list(order)])", "+res = 700", "+# res = 700 + reduce(lambda x, y: x + y,", "+# map(lambda x: 100 if x == \"o\" else 0, list(order)))", "+for i in order:", "+ if i == \"o\":", "+ res += 100" ]
false
0.041759
0.041436
1.007788
[ "s090159846", "s359979947" ]
u974620347
p03163
python
s267206809
s137159318
633
567
119,148
120,684
Accepted
Accepted
10.43
def main(): N, W = [int(n) for n in input().split()] baggages = [[int(n) for n in input().split()] for i in range(N)] VALUE, WEIGHT = 1, 0 dp = [[-1] * (W+1) for n in range(N)] # dp[baggage][weight] := baggage番目までの荷物を使ってweight以下に抑える dp[0] = [0 if weight < baggages[0][WEIGHT] else baggages[0][VALUE] for weight in range(W+1)] for baggage in range(N): for max_weight in range(W+1): if dp[baggage][max_weight] != -1: continue bag_w = baggages[baggage][WEIGHT] bag_v = baggages[baggage][VALUE] val1 = dp[baggage-1][max_weight] val2 = dp[baggage-1][max_weight-bag_w]+bag_v if max_weight >= bag_w else 0 dp[baggage][max_weight] = max(val1, val2) print((dp[N-1][W])) if __name__ == "__main__": main()
N,W = [int(_n) for _n in input().split()] A = [] for i in range(N): w,v = [int(_n) for _n in input().split()] A.append((w,v)) dp = [[0]*(W+1) for _ in range(N)] for w in range(W+1): dp[0][w] = 0 if w < A[0][0] else A[0][1] for i in range(N): for w in range(W+1): dp[i][w] = dp[i-1][w] if w >= A[i][0]: dp[i][w] = max(dp[i-1][w], dp[i-1][w-A[i][0]] + A[i][1]) print((dp[N-1][W]))
25
16
866
437
def main(): N, W = [int(n) for n in input().split()] baggages = [[int(n) for n in input().split()] for i in range(N)] VALUE, WEIGHT = 1, 0 dp = [[-1] * (W + 1) for n in range(N)] # dp[baggage][weight] := baggage番目までの荷物を使ってweight以下に抑える dp[0] = [ 0 if weight < baggages[0][WEIGHT] else baggages[0][VALUE] for weight in range(W + 1) ] for baggage in range(N): for max_weight in range(W + 1): if dp[baggage][max_weight] != -1: continue bag_w = baggages[baggage][WEIGHT] bag_v = baggages[baggage][VALUE] val1 = dp[baggage - 1][max_weight] val2 = ( dp[baggage - 1][max_weight - bag_w] + bag_v if max_weight >= bag_w else 0 ) dp[baggage][max_weight] = max(val1, val2) print((dp[N - 1][W])) if __name__ == "__main__": main()
N, W = [int(_n) for _n in input().split()] A = [] for i in range(N): w, v = [int(_n) for _n in input().split()] A.append((w, v)) dp = [[0] * (W + 1) for _ in range(N)] for w in range(W + 1): dp[0][w] = 0 if w < A[0][0] else A[0][1] for i in range(N): for w in range(W + 1): dp[i][w] = dp[i - 1][w] if w >= A[i][0]: dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - A[i][0]] + A[i][1]) print((dp[N - 1][W]))
false
36
[ "-def main():", "- N, W = [int(n) for n in input().split()]", "- baggages = [[int(n) for n in input().split()] for i in range(N)]", "- VALUE, WEIGHT = 1, 0", "- dp = [[-1] * (W + 1) for n in range(N)]", "- # dp[baggage][weight] := baggage番目までの荷物を使ってweight以下に抑える", "- dp[0] = [", "- 0 if weight < baggages[0][WEIGHT] else baggages[0][VALUE]", "- for weight in range(W + 1)", "- ]", "- for baggage in range(N):", "- for max_weight in range(W + 1):", "- if dp[baggage][max_weight] != -1:", "- continue", "- bag_w = baggages[baggage][WEIGHT]", "- bag_v = baggages[baggage][VALUE]", "- val1 = dp[baggage - 1][max_weight]", "- val2 = (", "- dp[baggage - 1][max_weight - bag_w] + bag_v", "- if max_weight >= bag_w", "- else 0", "- )", "- dp[baggage][max_weight] = max(val1, val2)", "- print((dp[N - 1][W]))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N, W = [int(_n) for _n in input().split()]", "+A = []", "+for i in range(N):", "+ w, v = [int(_n) for _n in input().split()]", "+ A.append((w, v))", "+dp = [[0] * (W + 1) for _ in range(N)]", "+for w in range(W + 1):", "+ dp[0][w] = 0 if w < A[0][0] else A[0][1]", "+for i in range(N):", "+ for w in range(W + 1):", "+ dp[i][w] = dp[i - 1][w]", "+ if w >= A[i][0]:", "+ dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - A[i][0]] + A[i][1])", "+print((dp[N - 1][W]))" ]
false
0.036825
0.036609
1.005925
[ "s267206809", "s137159318" ]
u638456847
p02972
python
s224957352
s379158085
635
232
14,088
14,088
Accepted
Accepted
63.46
N = int(eval(input())) a = [int(i) for i in input().split()] b = [0]*N ans = [] for i in range(N, 0, -1): s = 0 for j in range(i, N+1, i): s += b[j-1] if s % 2 != a[i-1]: b[i-1] += 1 ans.append(i) print((sum(b))) if len(ans) > 0: print((*ans))
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) A = [int(i) for i in readline().split()] ans = [] B = [0] * N for i in reversed(list(range(N))): s = sum(B[i::i+1]) if s % 2 == A[i]: continue else: B[i] += 1 ans.append(i+1) print((sum(B))) if len(ans): print((*ans)) if __name__ == "__main__": main()
16
27
290
505
N = int(eval(input())) a = [int(i) for i in input().split()] b = [0] * N ans = [] for i in range(N, 0, -1): s = 0 for j in range(i, N + 1, i): s += b[j - 1] if s % 2 != a[i - 1]: b[i - 1] += 1 ans.append(i) print((sum(b))) if len(ans) > 0: print((*ans))
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N = int(readline()) A = [int(i) for i in readline().split()] ans = [] B = [0] * N for i in reversed(list(range(N))): s = sum(B[i :: i + 1]) if s % 2 == A[i]: continue else: B[i] += 1 ans.append(i + 1) print((sum(B))) if len(ans): print((*ans)) if __name__ == "__main__": main()
false
40.740741
[ "-N = int(eval(input()))", "-a = [int(i) for i in input().split()]", "-b = [0] * N", "-ans = []", "-for i in range(N, 0, -1):", "- s = 0", "- for j in range(i, N + 1, i):", "- s += b[j - 1]", "- if s % 2 != a[i - 1]:", "- b[i - 1] += 1", "- ans.append(i)", "-print((sum(b)))", "-if len(ans) > 0:", "- print((*ans))", "+import sys", "+", "+read = sys.stdin.read", "+readline = sys.stdin.readline", "+readlines = sys.stdin.readlines", "+", "+", "+def main():", "+ N = int(readline())", "+ A = [int(i) for i in readline().split()]", "+ ans = []", "+ B = [0] * N", "+ for i in reversed(list(range(N))):", "+ s = sum(B[i :: i + 1])", "+ if s % 2 == A[i]:", "+ continue", "+ else:", "+ B[i] += 1", "+ ans.append(i + 1)", "+ print((sum(B)))", "+ if len(ans):", "+ print((*ans))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.085125
0.038765
2.19591
[ "s224957352", "s379158085" ]
u644907318
p02990
python
s214360638
s055205250
212
85
42,352
74,244
Accepted
Accepted
59.91
p = 10**9+7 def pow(x,m): if m==0: return 1 if m==1: return x if m%2==0: return (pow(x,m//2)**2)%p else: return (x*pow(x,(m-1)//2)**2)%p N,K = list(map(int,input().split())) A = [1 for _ in range(N+1)] for i in range(2,N+1): A[i] = (i*A[i-1])%p B = [1 for _ in range(N+1)] B[N] = pow(A[N],p-2) for i in range(N-1,1,-1): B[i] = ((i+1)*B[i+1])%p for i in range(1,K+1): if N-K-i+1>=0: a = (A[K-1]*B[i-1])%p a = (a*B[K-i])%p a = (a*A[N-K+1])%p a = (a*B[i])%p a = (a*B[N-K-i+1])%p else: a = 0 print(a)
p = 10**9+7 def pow(x,m): if m==0: return 1 if m==1: return x if m%2==0: return (pow(x,m//2)**2)%p else: return (x*(pow(x,(m-1)//2)**2)%p)%p N,K = list(map(int,input().split())) A = [1 for _ in range(N+1)] for i in range(2,N+1): A[i] = (i*A[i-1])%p B = [1 for _ in range(N+1)] B[N] = pow(A[N],p-2) for i in range(N-1,1,-1): B[i] = ((i+1)*B[i+1])%p for i in range(1,K+1): if N-K<i-1: ans = 0 else: a = A[K-1] a = (a*B[K-i])%p a = (a*B[i-1])%p b = A[N-K+1] b = (b*B[N-K+1-i])%p b = (b*B[i])%p ans = (a*b)%p print(ans)
28
30
633
670
p = 10**9 + 7 def pow(x, m): if m == 0: return 1 if m == 1: return x if m % 2 == 0: return (pow(x, m // 2) ** 2) % p else: return (x * pow(x, (m - 1) // 2) ** 2) % p N, K = list(map(int, input().split())) A = [1 for _ in range(N + 1)] for i in range(2, N + 1): A[i] = (i * A[i - 1]) % p B = [1 for _ in range(N + 1)] B[N] = pow(A[N], p - 2) for i in range(N - 1, 1, -1): B[i] = ((i + 1) * B[i + 1]) % p for i in range(1, K + 1): if N - K - i + 1 >= 0: a = (A[K - 1] * B[i - 1]) % p a = (a * B[K - i]) % p a = (a * A[N - K + 1]) % p a = (a * B[i]) % p a = (a * B[N - K - i + 1]) % p else: a = 0 print(a)
p = 10**9 + 7 def pow(x, m): if m == 0: return 1 if m == 1: return x if m % 2 == 0: return (pow(x, m // 2) ** 2) % p else: return (x * (pow(x, (m - 1) // 2) ** 2) % p) % p N, K = list(map(int, input().split())) A = [1 for _ in range(N + 1)] for i in range(2, N + 1): A[i] = (i * A[i - 1]) % p B = [1 for _ in range(N + 1)] B[N] = pow(A[N], p - 2) for i in range(N - 1, 1, -1): B[i] = ((i + 1) * B[i + 1]) % p for i in range(1, K + 1): if N - K < i - 1: ans = 0 else: a = A[K - 1] a = (a * B[K - i]) % p a = (a * B[i - 1]) % p b = A[N - K + 1] b = (b * B[N - K + 1 - i]) % p b = (b * B[i]) % p ans = (a * b) % p print(ans)
false
6.666667
[ "- return (x * pow(x, (m - 1) // 2) ** 2) % p", "+ return (x * (pow(x, (m - 1) // 2) ** 2) % p) % p", "- if N - K - i + 1 >= 0:", "- a = (A[K - 1] * B[i - 1]) % p", "+ if N - K < i - 1:", "+ ans = 0", "+ else:", "+ a = A[K - 1]", "- a = (a * A[N - K + 1]) % p", "- a = (a * B[i]) % p", "- a = (a * B[N - K - i + 1]) % p", "- else:", "- a = 0", "- print(a)", "+ a = (a * B[i - 1]) % p", "+ b = A[N - K + 1]", "+ b = (b * B[N - K + 1 - i]) % p", "+ b = (b * B[i]) % p", "+ ans = (a * b) % p", "+ print(ans)" ]
false
0.03906
0.038091
1.025427
[ "s214360638", "s055205250" ]
u638456847
p03027
python
s850898730
s361217471
1,297
602
77,000
76,252
Accepted
Accepted
53.59
#################### # AC: ms (PyPy) #################### def main(): MOD = 10**6+3 # preprocess fac = [None] * (MOD+1) fac[0] = fac[1] = 1 for i in range(2, MOD+1): fac[i] = (fac[i-1] * i) % MOD Q = int(eval(input())) for i in range(Q): x, d, n = list(map(int, input().split())) if x == 0: print((0)) continue if d == 0: print((pow(x, n, MOD))) continue xd = (x * pow(d, MOD-2, MOD)) % MOD if xd + (n-1) >= MOD: print((0)) continue print((pow(d, n, MOD) * fac[xd+(n-1)] * pow(fac[xd-1], MOD-2, MOD) % MOD)) if __name__ == "__main__": main()
import sys def main(): MOD = 10**6+3 # preprocess fac = [None] * (MOD+1) fac[0] = fac[1] = 1 for i in range(2, MOD+1): fac[i] = (fac[i-1] * i) % MOD Q = int(eval(input())) for i in range(Q): x, d, n = list(map(int, sys.stdin.readline().split())) if d == 0: print((pow(x, n, MOD))) continue xd = (x * pow(d, MOD-2, MOD)) % MOD if xd == 0 or xd + (n-1) >= MOD: print((0)) continue print((pow(d, n, MOD) * fac[xd+(n-1)] * pow(fac[xd-1], MOD-2, MOD) % MOD)) if __name__ == "__main__": main()
34
29
735
641
#################### # AC: ms (PyPy) #################### def main(): MOD = 10**6 + 3 # preprocess fac = [None] * (MOD + 1) fac[0] = fac[1] = 1 for i in range(2, MOD + 1): fac[i] = (fac[i - 1] * i) % MOD Q = int(eval(input())) for i in range(Q): x, d, n = list(map(int, input().split())) if x == 0: print((0)) continue if d == 0: print((pow(x, n, MOD))) continue xd = (x * pow(d, MOD - 2, MOD)) % MOD if xd + (n - 1) >= MOD: print((0)) continue print( (pow(d, n, MOD) * fac[xd + (n - 1)] * pow(fac[xd - 1], MOD - 2, MOD) % MOD) ) if __name__ == "__main__": main()
import sys def main(): MOD = 10**6 + 3 # preprocess fac = [None] * (MOD + 1) fac[0] = fac[1] = 1 for i in range(2, MOD + 1): fac[i] = (fac[i - 1] * i) % MOD Q = int(eval(input())) for i in range(Q): x, d, n = list(map(int, sys.stdin.readline().split())) if d == 0: print((pow(x, n, MOD))) continue xd = (x * pow(d, MOD - 2, MOD)) % MOD if xd == 0 or xd + (n - 1) >= MOD: print((0)) continue print( (pow(d, n, MOD) * fac[xd + (n - 1)] * pow(fac[xd - 1], MOD - 2, MOD) % MOD) ) if __name__ == "__main__": main()
false
14.705882
[ "-####################", "-# AC: ms (PyPy)", "-####################", "+import sys", "+", "+", "- x, d, n = list(map(int, input().split()))", "- if x == 0:", "- print((0))", "- continue", "+ x, d, n = list(map(int, sys.stdin.readline().split()))", "- if xd + (n - 1) >= MOD:", "+ if xd == 0 or xd + (n - 1) >= MOD:" ]
false
0.754022
0.358863
2.10114
[ "s850898730", "s361217471" ]
u072053884
p02315
python
s132030714
s474849596
380
350
8,480
8,356
Accepted
Accepted
7.89
import sys def solve(): file_input = sys.stdin N, W = list(map(int, file_input.readline().split())) C = [0] * (W + 1) for line in file_input: item_v, item_w = list(map(int, line.split())) for i, vals in enumerate(zip(C[item_w:], C)): C[i] = max(vals[0] + item_v, vals[1]) print((C[0])) solve()
import sys def solve(): file_input = sys.stdin N, W = list(map(int, file_input.readline().split())) C = [0] * (W + 1) for line in file_input: item_v, item_w = list(map(int, line.split())) for i, vals in enumerate(zip(C[item_w:], C)): v1, v2 = vals C[i] = max(v1 + item_v, v2) print((C[0])) solve()
13
14
341
358
import sys def solve(): file_input = sys.stdin N, W = list(map(int, file_input.readline().split())) C = [0] * (W + 1) for line in file_input: item_v, item_w = list(map(int, line.split())) for i, vals in enumerate(zip(C[item_w:], C)): C[i] = max(vals[0] + item_v, vals[1]) print((C[0])) solve()
import sys def solve(): file_input = sys.stdin N, W = list(map(int, file_input.readline().split())) C = [0] * (W + 1) for line in file_input: item_v, item_w = list(map(int, line.split())) for i, vals in enumerate(zip(C[item_w:], C)): v1, v2 = vals C[i] = max(v1 + item_v, v2) print((C[0])) solve()
false
7.142857
[ "- C[i] = max(vals[0] + item_v, vals[1])", "+ v1, v2 = vals", "+ C[i] = max(v1 + item_v, v2)" ]
false
0.04828
0.040472
1.192922
[ "s132030714", "s474849596" ]
u729133443
p03623
python
s344717753
s041364774
169
23
38,428
9,132
Accepted
Accepted
86.39
x,a,b=list(map(int,input().split()));print(('AB'[abs(a-x)>abs(b-x)]))
x,a,b=list(map(int,input().split())) print(('AB'[(x+x>a+b)^(a>b)]))
1
2
61
60
x, a, b = list(map(int, input().split())) print(("AB"[abs(a - x) > abs(b - x)]))
x, a, b = list(map(int, input().split())) print(("AB"[(x + x > a + b) ^ (a > b)]))
false
50
[ "-print((\"AB\"[abs(a - x) > abs(b - x)]))", "+print((\"AB\"[(x + x > a + b) ^ (a > b)]))" ]
false
0.063613
0.036127
1.760811
[ "s344717753", "s041364774" ]
u672898046
p03723
python
s892086997
s479546950
29
24
9,096
9,044
Accepted
Accepted
17.24
a, b, c = list(map(int, input().split())) if a % 2 != 0 or b % 2 != 0 or c % 2 != 0: print((0)) exit() if a == b == c: print((-1)) exit() cnt = 0 while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0): a, b, c = (b+c)//2, (a+c)//2, (a+b)//2 cnt += 1 print(cnt)
def resolve(): a, b, c = list(map(int, input().split())) if a%2 != 0 or b%2 != 0 or c%2 != 0: print((0)) exit() if a == b == c: print((-1)) exit() ans = 0 while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0): a, b, c = (b+c)//2, (a+c)//2, (a+b)//2 ans += 1 print(ans) resolve()
16
14
304
349
a, b, c = list(map(int, input().split())) if a % 2 != 0 or b % 2 != 0 or c % 2 != 0: print((0)) exit() if a == b == c: print((-1)) exit() cnt = 0 while a % 2 == 0 and b % 2 == 0 and c % 2 == 0: a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2 cnt += 1 print(cnt)
def resolve(): a, b, c = list(map(int, input().split())) if a % 2 != 0 or b % 2 != 0 or c % 2 != 0: print((0)) exit() if a == b == c: print((-1)) exit() ans = 0 while a % 2 == 0 and b % 2 == 0 and c % 2 == 0: a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2 ans += 1 print(ans) resolve()
false
12.5
[ "-a, b, c = list(map(int, input().split()))", "-if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:", "- print((0))", "- exit()", "-if a == b == c:", "- print((-1))", "- exit()", "-cnt = 0", "-while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:", "- a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2", "- cnt += 1", "-print(cnt)", "+def resolve():", "+ a, b, c = list(map(int, input().split()))", "+ if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:", "+ print((0))", "+ exit()", "+ if a == b == c:", "+ print((-1))", "+ exit()", "+ ans = 0", "+ while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:", "+ a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2", "+ ans += 1", "+ print(ans)", "+", "+", "+resolve()" ]
false
0.059704
0.03545
1.684195
[ "s892086997", "s479546950" ]
u780025254
p02408
python
s525642682
s801968316
40
20
7,784
5,604
Accepted
Accepted
50
num = int(eval(input())) cards = [ (design, rank) for design in ['S','H','C','D'] for rank in range(1,14) ] for i in range(num): design, rank = input().split() cards.remove((design, int(rank))) for (design, rank) in cards: print((design, rank))
list = [] for x in ["S", "H", "C", "D"]: for y in [str(i) for i in range(1, 14)]: list.append(x+" "+y) n = int(eval(input())) while n > 0: list.remove(eval(input())) n -= 1 for i in list: print(i)
8
10
260
218
num = int(eval(input())) cards = [(design, rank) for design in ["S", "H", "C", "D"] for rank in range(1, 14)] for i in range(num): design, rank = input().split() cards.remove((design, int(rank))) for (design, rank) in cards: print((design, rank))
list = [] for x in ["S", "H", "C", "D"]: for y in [str(i) for i in range(1, 14)]: list.append(x + " " + y) n = int(eval(input())) while n > 0: list.remove(eval(input())) n -= 1 for i in list: print(i)
false
20
[ "-num = int(eval(input()))", "-cards = [(design, rank) for design in [\"S\", \"H\", \"C\", \"D\"] for rank in range(1, 14)]", "-for i in range(num):", "- design, rank = input().split()", "- cards.remove((design, int(rank)))", "-for (design, rank) in cards:", "- print((design, rank))", "+list = []", "+for x in [\"S\", \"H\", \"C\", \"D\"]:", "+ for y in [str(i) for i in range(1, 14)]:", "+ list.append(x + \" \" + y)", "+n = int(eval(input()))", "+while n > 0:", "+ list.remove(eval(input()))", "+ n -= 1", "+for i in list:", "+ print(i)" ]
false
0.047586
0.047469
1.002464
[ "s525642682", "s801968316" ]
u279955105
p02390
python
s468354899
s566806393
70
20
7,664
7,668
Accepted
Accepted
71.43
t = int(eval(input())) h = int(t/3600) m = int(t%3600/60) s = int(t%3600%60) print((str(h) + ":" + str(m) + ":" + str(s)))
S = int(eval(input())) h = int(S/3600) m = int(S%3600/60) s = int(S%3600%60) print((str(h) + ":" + str(m) + ":" + str(s)))
5
5
118
118
t = int(eval(input())) h = int(t / 3600) m = int(t % 3600 / 60) s = int(t % 3600 % 60) print((str(h) + ":" + str(m) + ":" + str(s)))
S = int(eval(input())) h = int(S / 3600) m = int(S % 3600 / 60) s = int(S % 3600 % 60) print((str(h) + ":" + str(m) + ":" + str(s)))
false
0
[ "-t = int(eval(input()))", "-h = int(t / 3600)", "-m = int(t % 3600 / 60)", "-s = int(t % 3600 % 60)", "+S = int(eval(input()))", "+h = int(S / 3600)", "+m = int(S % 3600 / 60)", "+s = int(S % 3600 % 60)" ]
false
0.037416
0.085146
0.439431
[ "s468354899", "s566806393" ]
u270144704
p02683
python
s334864683
s347865097
98
86
69,300
69,288
Accepted
Accepted
12.24
n, m, x = list(map(int, input().split())) CA = [tuple(map(int, input().split())) for _ in range(n)] minimum = float("inf") for i in range(2**n): select = [0] * n a = [0] * m money = 0 for j in range(n): if (i>>j)&1: select[n-1-j] = 1 for i, v in enumerate(select): if v == 1: money += CA[i][0] for j, u in enumerate(CA[i][1:]): a[j] += u if all(l >= x for l in a): minimum = min(minimum, money) print((-1 if minimum == float("inf") else minimum))
n, m, x = list(map(int, input().split())) CA = [tuple(map(int, input().split())) for _ in range(n)] minimum = float("inf") for i in range(2**n): select = [0] * n a = [0] * m money = 0 for j in range(n): if (i>>j)&1: select[n-1-j] = 1 for i, v in enumerate(select): if v == 1: money += CA[i][0] for j, u in enumerate(CA[i][1:]): a[j] += u if not len([l for l in a if l < x]): minimum = min(minimum, money) print((-1 if minimum == float("inf") else minimum))
19
19
557
567
n, m, x = list(map(int, input().split())) CA = [tuple(map(int, input().split())) for _ in range(n)] minimum = float("inf") for i in range(2**n): select = [0] * n a = [0] * m money = 0 for j in range(n): if (i >> j) & 1: select[n - 1 - j] = 1 for i, v in enumerate(select): if v == 1: money += CA[i][0] for j, u in enumerate(CA[i][1:]): a[j] += u if all(l >= x for l in a): minimum = min(minimum, money) print((-1 if minimum == float("inf") else minimum))
n, m, x = list(map(int, input().split())) CA = [tuple(map(int, input().split())) for _ in range(n)] minimum = float("inf") for i in range(2**n): select = [0] * n a = [0] * m money = 0 for j in range(n): if (i >> j) & 1: select[n - 1 - j] = 1 for i, v in enumerate(select): if v == 1: money += CA[i][0] for j, u in enumerate(CA[i][1:]): a[j] += u if not len([l for l in a if l < x]): minimum = min(minimum, money) print((-1 if minimum == float("inf") else minimum))
false
0
[ "- if all(l >= x for l in a):", "+ if not len([l for l in a if l < x]):" ]
false
0.038314
0.039831
0.96191
[ "s334864683", "s347865097" ]
u044220565
p02617
python
s441860115
s164522744
649
552
9,276
9,004
Accepted
Accepted
14.95
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10 ** 7) from heapq import heappop, heappush #from collections import OrderedDict, defaultdict #import math #from itertools import product, accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque #import numba def sum_between(a, b): l, r = min(a,b), max(a,b) return (r-l+1) * (r+l) // 2 def run(): N = int(eval(input())) n_dots = 0 for i in range(1, N+1): n_dots += (1+i) * i // 2 #print(n_dots) ans = (N-1) * (N+1) * N // 2 #print(ans) for i in range(N-1): u, v = list(map(int, input().split())) l, r = min(u, v), max(u, v) tmp = 0 if l > 1: tmp += sum_between(r-1, r-l+1) tmp += r-l tmp += sum_between(N-l, 1) #print(tmp) ans -= tmp print((n_dots - ans)) ans = (N-1) * N * N if __name__ == "__main__": run()
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10 ** 7) from heapq import heappop, heappush #from collections import OrderedDict, defaultdict #import math #from itertools import product, accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque #import numba def sum_between(a, b): if a > b:a, b = b, a return (b-a+1) * (b+a) // 2 def run(): N = int(eval(input())) n_dots = 0 for i in range(1, N+1): n_dots += (1+i) * i // 2 #print(n_dots) ans = (N-1) * (N+1) * N // 2 #print(ans) for i in range(N-1): u, v = list(map(int, input().split())) l, r = min(u, v), max(u, v) tmp = 0 if l > 1: tmp += sum_between(r-1, r-l+1) tmp += r-l tmp += sum_between(N-l, 1) #print(tmp) ans -= tmp print((n_dots - ans)) ans = (N-1) * N * N if __name__ == "__main__": run()
46
46
1,089
1,084
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10**7) from heapq import heappop, heappush # from collections import OrderedDict, defaultdict # import math # from itertools import product, accumulate, combinations, product # import bisect# lower_bound etc # import numpy as np # from copy import deepcopy # from collections import deque # import numba def sum_between(a, b): l, r = min(a, b), max(a, b) return (r - l + 1) * (r + l) // 2 def run(): N = int(eval(input())) n_dots = 0 for i in range(1, N + 1): n_dots += (1 + i) * i // 2 # print(n_dots) ans = (N - 1) * (N + 1) * N // 2 # print(ans) for i in range(N - 1): u, v = list(map(int, input().split())) l, r = min(u, v), max(u, v) tmp = 0 if l > 1: tmp += sum_between(r - 1, r - l + 1) tmp += r - l tmp += sum_between(N - l, 1) # print(tmp) ans -= tmp print((n_dots - ans)) ans = (N - 1) * N * N if __name__ == "__main__": run()
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read sys.setrecursionlimit(10**7) from heapq import heappop, heappush # from collections import OrderedDict, defaultdict # import math # from itertools import product, accumulate, combinations, product # import bisect# lower_bound etc # import numpy as np # from copy import deepcopy # from collections import deque # import numba def sum_between(a, b): if a > b: a, b = b, a return (b - a + 1) * (b + a) // 2 def run(): N = int(eval(input())) n_dots = 0 for i in range(1, N + 1): n_dots += (1 + i) * i // 2 # print(n_dots) ans = (N - 1) * (N + 1) * N // 2 # print(ans) for i in range(N - 1): u, v = list(map(int, input().split())) l, r = min(u, v), max(u, v) tmp = 0 if l > 1: tmp += sum_between(r - 1, r - l + 1) tmp += r - l tmp += sum_between(N - l, 1) # print(tmp) ans -= tmp print((n_dots - ans)) ans = (N - 1) * N * N if __name__ == "__main__": run()
false
0
[ "- l, r = min(a, b), max(a, b)", "- return (r - l + 1) * (r + l) // 2", "+ if a > b:", "+ a, b = b, a", "+ return (b - a + 1) * (b + a) // 2" ]
false
0.073396
0.070569
1.040058
[ "s441860115", "s164522744" ]
u002459665
p03086
python
s575815739
s688899449
44
17
2,940
3,060
Accepted
Accepted
61.36
s = eval(input()) c = 0 mx = 0 for si in s: if si in ("A", "C", "G", "T"): c += 1 if c > mx: mx = c else: c = 0 print(mx)
S = eval(input()) mx = 0 for i in range(len(S)): for j in range(i, len(S) + 1): s = S[i:j] flag = True for si in s: if si not in ["A", "C", "G", "T"]: flag = False if flag: mx = max(mx, len(s)) print(mx)
13
13
174
287
s = eval(input()) c = 0 mx = 0 for si in s: if si in ("A", "C", "G", "T"): c += 1 if c > mx: mx = c else: c = 0 print(mx)
S = eval(input()) mx = 0 for i in range(len(S)): for j in range(i, len(S) + 1): s = S[i:j] flag = True for si in s: if si not in ["A", "C", "G", "T"]: flag = False if flag: mx = max(mx, len(s)) print(mx)
false
0
[ "-s = eval(input())", "-c = 0", "+S = eval(input())", "-for si in s:", "- if si in (\"A\", \"C\", \"G\", \"T\"):", "- c += 1", "- if c > mx:", "- mx = c", "- else:", "- c = 0", "+for i in range(len(S)):", "+ for j in range(i, len(S) + 1):", "+ s = S[i:j]", "+ flag = True", "+ for si in s:", "+ if si not in [\"A\", \"C\", \"G\", \"T\"]:", "+ flag = False", "+ if flag:", "+ mx = max(mx, len(s))" ]
false
0.042845
0.077314
0.554165
[ "s575815739", "s688899449" ]
u223646582
p03426
python
s972063139
s751604345
951
730
19,544
114,908
Accepted
Accepted
23.24
H, W, D = list(map(int, input().split())) A = [[int(j) for j in input().split()] for i in range(H)] B = [(-1, -1) for j in range(H*W)] for i in range(H): for j in range(W): B[A[i][j]-1] = (i, j) C = [-1] * H*W for i in range(H*W-D): fx, fy = B[i+D] tx, ty = B[i] C[i] = abs(fx-tx)+abs(fy-ty) E = [0] * H*W for i in range(D): S = 0 for j in range(i, H*W-D, D): S += C[j] E[j+D] = S # print(E) Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) print((E[R-1]-E[L-1]))
H, W, D = list(map(int, input().split())) A = [[int(i) for i in input().split()] for _ in range(H)] Q = int(eval(input())) query = [(int(i) for i in input().split()) for _ in range(Q)] x = [-1]*H*W y = [-1]*H*W for i in range(H): for j in range(W): x[A[i][j]-1] = i y[A[i][j]-1] = j X = [0]*H*W Y = [0]*H*W # 累積和行列化 for k in range(D, H*W): X[k] = X[k-D]+abs(x[k]-x[k-D]) Y[k] = Y[k-D]+abs(y[k]-y[k-D]) for L, R in query: L -= 1 # 0-indexed R -= 1 # 0-indexed print((X[R]-X[L]+Y[R]-Y[L]))
25
24
559
543
H, W, D = list(map(int, input().split())) A = [[int(j) for j in input().split()] for i in range(H)] B = [(-1, -1) for j in range(H * W)] for i in range(H): for j in range(W): B[A[i][j] - 1] = (i, j) C = [-1] * H * W for i in range(H * W - D): fx, fy = B[i + D] tx, ty = B[i] C[i] = abs(fx - tx) + abs(fy - ty) E = [0] * H * W for i in range(D): S = 0 for j in range(i, H * W - D, D): S += C[j] E[j + D] = S # print(E) Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) print((E[R - 1] - E[L - 1]))
H, W, D = list(map(int, input().split())) A = [[int(i) for i in input().split()] for _ in range(H)] Q = int(eval(input())) query = [(int(i) for i in input().split()) for _ in range(Q)] x = [-1] * H * W y = [-1] * H * W for i in range(H): for j in range(W): x[A[i][j] - 1] = i y[A[i][j] - 1] = j X = [0] * H * W Y = [0] * H * W # 累積和行列化 for k in range(D, H * W): X[k] = X[k - D] + abs(x[k] - x[k - D]) Y[k] = Y[k - D] + abs(y[k] - y[k - D]) for L, R in query: L -= 1 # 0-indexed R -= 1 # 0-indexed print((X[R] - X[L] + Y[R] - Y[L]))
false
4
[ "-A = [[int(j) for j in input().split()] for i in range(H)]", "-B = [(-1, -1) for j in range(H * W)]", "+A = [[int(i) for i in input().split()] for _ in range(H)]", "+Q = int(eval(input()))", "+query = [(int(i) for i in input().split()) for _ in range(Q)]", "+x = [-1] * H * W", "+y = [-1] * H * W", "- B[A[i][j] - 1] = (i, j)", "-C = [-1] * H * W", "-for i in range(H * W - D):", "- fx, fy = B[i + D]", "- tx, ty = B[i]", "- C[i] = abs(fx - tx) + abs(fy - ty)", "-E = [0] * H * W", "-for i in range(D):", "- S = 0", "- for j in range(i, H * W - D, D):", "- S += C[j]", "- E[j + D] = S", "-# print(E)", "-Q = int(eval(input()))", "-for _ in range(Q):", "- L, R = list(map(int, input().split()))", "- print((E[R - 1] - E[L - 1]))", "+ x[A[i][j] - 1] = i", "+ y[A[i][j] - 1] = j", "+X = [0] * H * W", "+Y = [0] * H * W", "+# 累積和行列化", "+for k in range(D, H * W):", "+ X[k] = X[k - D] + abs(x[k] - x[k - D])", "+ Y[k] = Y[k - D] + abs(y[k] - y[k - D])", "+for L, R in query:", "+ L -= 1 # 0-indexed", "+ R -= 1 # 0-indexed", "+ print((X[R] - X[L] + Y[R] - Y[L]))" ]
false
0.043983
0.046235
0.951287
[ "s972063139", "s751604345" ]
u426534722
p02245
python
s515806773
s234078733
880
60
31,360
8,884
Accepted
Accepted
93.18
from heapq import heapify, heappush, heappop from collections import deque from copy import deepcopy, copy N = 3 m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}} def g(i, j, a): if i > j: i, j = j, i return a[:i] + a[j] + a[i + 1:j] + a[i] + a[j + 1:] def MAIN(): MAP = "".join(input().replace(" ", "") for _ in range(N)) goal = "123456780" if MAP == goal: print((0)) return start = MAP.find("0") dp = [(0, MAP, start)] LOG = {MAP} while dp: cnt, M, yx = heappop(dp) cnt += 1 for nyx in m[yx]: CM = g(yx, nyx, M) if not CM in LOG: if CM == goal: print(cnt) return heappush(dp, (cnt, CM, nyx)) LOG.add(CM) MAIN()
from collections import deque N = 3 def g(i, j, a): if i > j: i, j = j, i return a[:i] + a[j] + a[i + 1:j] + a[i] + a[j + 1:] goal = "123456780" def solve(): m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}} MAP = "".join(input().replace(" ", "") for _ in range(N)) if MAP == goal: return 0 start = MAP.find("0") dp = deque([(0, MAP, start, 1), (0, goal, 8, 0)]) TABLE = {MAP:(1, 0), goal:(0, 0)} while dp: cnt, M, yx, flg = dp.popleft() cnt += 1 for nyx in m[yx]: CM = g(yx, nyx, M) if CM in TABLE: if TABLE[CM][0] != flg: return TABLE[CM][1] + cnt continue TABLE[CM] = (flg, cnt) dp.append((cnt, CM, nyx, flg)) def MAIN(): print((solve())) MAIN()
31
30
901
920
from heapq import heapify, heappush, heappop from collections import deque from copy import deepcopy, copy N = 3 m = { 8: {7, 5}, 7: {8, 6, 4}, 6: {7, 3}, 5: {8, 4, 2}, 4: {7, 5, 3, 1}, 3: {6, 4, 0}, 2: {5, 1}, 1: {4, 2, 0}, 0: {3, 1}, } def g(i, j, a): if i > j: i, j = j, i return a[:i] + a[j] + a[i + 1 : j] + a[i] + a[j + 1 :] def MAIN(): MAP = "".join(input().replace(" ", "") for _ in range(N)) goal = "123456780" if MAP == goal: print((0)) return start = MAP.find("0") dp = [(0, MAP, start)] LOG = {MAP} while dp: cnt, M, yx = heappop(dp) cnt += 1 for nyx in m[yx]: CM = g(yx, nyx, M) if not CM in LOG: if CM == goal: print(cnt) return heappush(dp, (cnt, CM, nyx)) LOG.add(CM) MAIN()
from collections import deque N = 3 def g(i, j, a): if i > j: i, j = j, i return a[:i] + a[j] + a[i + 1 : j] + a[i] + a[j + 1 :] goal = "123456780" def solve(): m = { 8: {7, 5}, 7: {8, 6, 4}, 6: {7, 3}, 5: {8, 4, 2}, 4: {7, 5, 3, 1}, 3: {6, 4, 0}, 2: {5, 1}, 1: {4, 2, 0}, 0: {3, 1}, } MAP = "".join(input().replace(" ", "") for _ in range(N)) if MAP == goal: return 0 start = MAP.find("0") dp = deque([(0, MAP, start, 1), (0, goal, 8, 0)]) TABLE = {MAP: (1, 0), goal: (0, 0)} while dp: cnt, M, yx, flg = dp.popleft() cnt += 1 for nyx in m[yx]: CM = g(yx, nyx, M) if CM in TABLE: if TABLE[CM][0] != flg: return TABLE[CM][1] + cnt continue TABLE[CM] = (flg, cnt) dp.append((cnt, CM, nyx, flg)) def MAIN(): print((solve())) MAIN()
false
3.225806
[ "-from heapq import heapify, heappush, heappop", "-from copy import deepcopy, copy", "-m = {", "- 8: {7, 5},", "- 7: {8, 6, 4},", "- 6: {7, 3},", "- 5: {8, 4, 2},", "- 4: {7, 5, 3, 1},", "- 3: {6, 4, 0},", "- 2: {5, 1},", "- 1: {4, 2, 0},", "- 0: {3, 1},", "-}", "-def MAIN():", "+goal = \"123456780\"", "+", "+", "+def solve():", "+ m = {", "+ 8: {7, 5},", "+ 7: {8, 6, 4},", "+ 6: {7, 3},", "+ 5: {8, 4, 2},", "+ 4: {7, 5, 3, 1},", "+ 3: {6, 4, 0},", "+ 2: {5, 1},", "+ 1: {4, 2, 0},", "+ 0: {3, 1},", "+ }", "- goal = \"123456780\"", "- print((0))", "- return", "+ return 0", "- dp = [(0, MAP, start)]", "- LOG = {MAP}", "+ dp = deque([(0, MAP, start, 1), (0, goal, 8, 0)])", "+ TABLE = {MAP: (1, 0), goal: (0, 0)}", "- cnt, M, yx = heappop(dp)", "+ cnt, M, yx, flg = dp.popleft()", "- if not CM in LOG:", "- if CM == goal:", "- print(cnt)", "- return", "- heappush(dp, (cnt, CM, nyx))", "- LOG.add(CM)", "+ if CM in TABLE:", "+ if TABLE[CM][0] != flg:", "+ return TABLE[CM][1] + cnt", "+ continue", "+ TABLE[CM] = (flg, cnt)", "+ dp.append((cnt, CM, nyx, flg))", "+", "+", "+def MAIN():", "+ print((solve()))" ]
false
0.117803
0.03993
2.950264
[ "s515806773", "s234078733" ]
u263830634
p02936
python
s308320229
s418884715
1,862
1,188
55,856
55,856
Accepted
Accepted
36.2
N, Q = list(map(int, input().split())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) count = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) count[p - 1] += x used = [False] * N stack = [0] used[0] = True while len(stack) != 0: tmp = stack.pop() for i in graph[tmp]: if not used[i]: stack.append(i) count[i] += count[tmp] used[i] = True print((*count))
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) count = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) count[p - 1] += x used = [False] * N stack = [0] s_pop = stack.pop s_append = stack.append used[0] = True while len(stack) != 0: tmp = s_pop() for i in graph[tmp]: if not used[i]: s_append(i) count[i] += count[tmp] used[i] = True print((*count))
26
30
558
634
N, Q = list(map(int, input().split())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) count = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) count[p - 1] += x used = [False] * N stack = [0] used[0] = True while len(stack) != 0: tmp = stack.pop() for i in graph[tmp]: if not used[i]: stack.append(i) count[i] += count[tmp] used[i] = True print((*count))
import sys input = sys.stdin.readline N, Q = list(map(int, input().split())) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) count = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) count[p - 1] += x used = [False] * N stack = [0] s_pop = stack.pop s_append = stack.append used[0] = True while len(stack) != 0: tmp = s_pop() for i in graph[tmp]: if not used[i]: s_append(i) count[i] += count[tmp] used[i] = True print((*count))
false
13.333333
[ "+import sys", "+", "+input = sys.stdin.readline", "+s_pop = stack.pop", "+s_append = stack.append", "- tmp = stack.pop()", "+ tmp = s_pop()", "- stack.append(i)", "+ s_append(i)" ]
false
0.042103
0.058768
0.71643
[ "s308320229", "s418884715" ]
u386819480
p04045
python
s751677948
s929094410
264
76
3,064
3,064
Accepted
Accepted
71.21
#!/usr/bin/env python3 import sys def solve(N: int, K: int, D: "List[int]"): while(True): nl = list(map(int,list(str(N)))) f = True for i in range(len(nl)): if(nl[i] in D): f = False if(f): print(N) exit() else: N += 1 return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int D = [int(next(tokens)) for _ in range(K)] # type: "List[int]" solve(N, K, D) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(N: int, K: int, D: "List[int]"): d = set(map(str, D)) while set(str(N))&d: N += 1 print(N) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int D = [int(next(tokens)) for _ in range(K)] # type: "List[int]" solve(N, K, D) if __name__ == '__main__': main()
35
28
915
732
#!/usr/bin/env python3 import sys def solve(N: int, K: int, D: "List[int]"): while True: nl = list(map(int, list(str(N)))) f = True for i in range(len(nl)): if nl[i] in D: f = False if f: print(N) exit() else: N += 1 return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int D = [int(next(tokens)) for _ in range(K)] # type: "List[int]" solve(N, K, D) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def solve(N: int, K: int, D: "List[int]"): d = set(map(str, D)) while set(str(N)) & d: N += 1 print(N) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int D = [int(next(tokens)) for _ in range(K)] # type: "List[int]" solve(N, K, D) if __name__ == "__main__": main()
false
20
[ "- while True:", "- nl = list(map(int, list(str(N))))", "- f = True", "- for i in range(len(nl)):", "- if nl[i] in D:", "- f = False", "- if f:", "- print(N)", "- exit()", "- else:", "- N += 1", "+ d = set(map(str, D))", "+ while set(str(N)) & d:", "+ N += 1", "+ print(N)" ]
false
0.042171
0.006917
6.096648
[ "s751677948", "s929094410" ]