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
u312025627
p03196
python
s484629137
s654926402
176
70
38,640
63,996
Accepted
Accepted
60.23
def main(): N, P = (int(i) for i in input().split()) def trial_division(n): divs = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divs.append(i) if i != n//i: divs.append(n//i) return divs divs = trial_division(P) divs.sort() ans = 1 for d in divs[1:]: # print(d, d**N, d**N <= P, P / d**N) # print(d) cur = 1 for i in range(N): cur *= d if P < cur: break if P < cur: break if P % (d**N) == 0: ans = d print(ans) if __name__ == '__main__': main()
def main(): N, P = (int(i) for i in input().split()) def enum_divisors(n): # 約数列挙 divs = [] for i in range(1, n+1): if i*i > n: break if n % i == 0: divs.append(i) if n//i != i: # i が平方数でない divs.append(n//i) return divs divs = enum_divisors(P) divs.sort() ans = 1 for d in divs[-1:0:-1]: v = 1 for _ in range(N): v *= d if v > P: break else: if P % v == 0: ans = d break print(ans) if __name__ == '__main__': main()
31
34
717
737
def main(): N, P = (int(i) for i in input().split()) def trial_division(n): divs = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divs.append(i) if i != n // i: divs.append(n // i) return divs divs = trial_division(P) divs.sort() ans = 1 for d in divs[1:]: # print(d, d**N, d**N <= P, P / d**N) # print(d) cur = 1 for i in range(N): cur *= d if P < cur: break if P < cur: break if P % (d**N) == 0: ans = d print(ans) if __name__ == "__main__": main()
def main(): N, P = (int(i) for i in input().split()) def enum_divisors(n): # 約数列挙 divs = [] for i in range(1, n + 1): if i * i > n: break if n % i == 0: divs.append(i) if n // i != i: # i が平方数でない divs.append(n // i) return divs divs = enum_divisors(P) divs.sort() ans = 1 for d in divs[-1:0:-1]: v = 1 for _ in range(N): v *= d if v > P: break else: if P % v == 0: ans = d break print(ans) if __name__ == "__main__": main()
false
8.823529
[ "- def trial_division(n):", "+ def enum_divisors(n):", "+ # 約数列挙", "- for i in range(1, int(n**0.5) + 1):", "+ for i in range(1, n + 1):", "+ if i * i > n:", "+ break", "- if i != n // i:", "+ if n // i != i:", "+ # i が平方数でない", "- divs = trial_division(P)", "+ divs = enum_divisors(P)", "- for d in divs[1:]:", "- # print(d, d**N, d**N <= P, P / d**N)", "- # print(d)", "- cur = 1", "- for i in range(N):", "- cur *= d", "- if P < cur:", "+ for d in divs[-1:0:-1]:", "+ v = 1", "+ for _ in range(N):", "+ v *= d", "+ if v > P:", "- if P < cur:", "- break", "- if P % (d**N) == 0:", "- ans = d", "+ else:", "+ if P % v == 0:", "+ ans = d", "+ break" ]
false
0.079848
0.131948
0.605147
[ "s484629137", "s654926402" ]
u994988729
p04035
python
s549158805
s077587844
761
106
32,472
14,056
Accepted
Accepted
86.07
import heapq N, K = map(int, input().split()) A = list(map(int, input().split())) knot = [] for i in range(N - 1): heapq.heappush(knot, (-A[i]-A[i+1], i)) ans = [] seen = [False]*N while knot: L, i = heapq.heappop(knot) L = -L if seen[i]: continue if L < K: break seen[i] = True ans.append(i + 1) if i + 1 < N - 1: heapq.heappush(knot, (-L - A[i + 1], i + 1)) if i - 1 >= 0: heapq.heappush(knot, (-L - A[i - 1], i - 1)) if len(ans) != N - 1: print("Impossible") else: print("Possible") print(*ans[::-1], sep="\n")
def know(N, K, A): isOK = False for i in range(1, N): if A[i] + A[i - 1] >= K: isOK = True first = i if not isOK: return ["Impossible"] ans = [first] for i in range(first + 1, N): ans.append(i) for i in range(first - 1, 0, -1): ans.append(i) return ["Possible"] + ans[::-1] if __name__ == "__main__": N, K = map(int, input().split()) A = list(map(int, input().split())) ans = know(N, K, A) print(*ans, sep="\n")
32
24
631
540
import heapq N, K = map(int, input().split()) A = list(map(int, input().split())) knot = [] for i in range(N - 1): heapq.heappush(knot, (-A[i] - A[i + 1], i)) ans = [] seen = [False] * N while knot: L, i = heapq.heappop(knot) L = -L if seen[i]: continue if L < K: break seen[i] = True ans.append(i + 1) if i + 1 < N - 1: heapq.heappush(knot, (-L - A[i + 1], i + 1)) if i - 1 >= 0: heapq.heappush(knot, (-L - A[i - 1], i - 1)) if len(ans) != N - 1: print("Impossible") else: print("Possible") print(*ans[::-1], sep="\n")
def know(N, K, A): isOK = False for i in range(1, N): if A[i] + A[i - 1] >= K: isOK = True first = i if not isOK: return ["Impossible"] ans = [first] for i in range(first + 1, N): ans.append(i) for i in range(first - 1, 0, -1): ans.append(i) return ["Possible"] + ans[::-1] if __name__ == "__main__": N, K = map(int, input().split()) A = list(map(int, input().split())) ans = know(N, K, A) print(*ans, sep="\n")
false
25
[ "-import heapq", "+def know(N, K, A):", "+ isOK = False", "+ for i in range(1, N):", "+ if A[i] + A[i - 1] >= K:", "+ isOK = True", "+ first = i", "+ if not isOK:", "+ return [\"Impossible\"]", "+ ans = [first]", "+ for i in range(first + 1, N):", "+ ans.append(i)", "+ for i in range(first - 1, 0, -1):", "+ ans.append(i)", "+ return [\"Possible\"] + ans[::-1]", "-N, K = map(int, input().split())", "-A = list(map(int, input().split()))", "-knot = []", "-for i in range(N - 1):", "- heapq.heappush(knot, (-A[i] - A[i + 1], i))", "-ans = []", "-seen = [False] * N", "-while knot:", "- L, i = heapq.heappop(knot)", "- L = -L", "- if seen[i]:", "- continue", "- if L < K:", "- break", "- seen[i] = True", "- ans.append(i + 1)", "- if i + 1 < N - 1:", "- heapq.heappush(knot, (-L - A[i + 1], i + 1))", "- if i - 1 >= 0:", "- heapq.heappush(knot, (-L - A[i - 1], i - 1))", "-if len(ans) != N - 1:", "- print(\"Impossible\")", "-else:", "- print(\"Possible\")", "- print(*ans[::-1], sep=\"\\n\")", "+", "+if __name__ == \"__main__\":", "+ N, K = map(int, input().split())", "+ A = list(map(int, input().split()))", "+ ans = know(N, K, A)", "+ print(*ans, sep=\"\\n\")" ]
false
0.03653
0.145239
0.251516
[ "s549158805", "s077587844" ]
u526094365
p02688
python
s254904634
s892054839
24
22
9,200
9,016
Accepted
Accepted
8.33
N, K = list(map(int, input().split())) d = [] A = [] for i in range(K): d.append(int(eval(input()))) A.append(list(map(int, input().split()))) hito = [i for i in range(1, N+1)] for i in range(N): name = hito[i] for j in range(K): if name in A[j]: hito[i] = -1 break ans = set(hito) print((len(ans)-1))
N, K = list(map(int, input().split())) d = [] A = [] for i in range(K): d.append(int(eval(input()))) st = list(map(int, input().split())) for j in st: A.append(j) print((N-len(set(A))))
19
10
358
201
N, K = list(map(int, input().split())) d = [] A = [] for i in range(K): d.append(int(eval(input()))) A.append(list(map(int, input().split()))) hito = [i for i in range(1, N + 1)] for i in range(N): name = hito[i] for j in range(K): if name in A[j]: hito[i] = -1 break ans = set(hito) print((len(ans) - 1))
N, K = list(map(int, input().split())) d = [] A = [] for i in range(K): d.append(int(eval(input()))) st = list(map(int, input().split())) for j in st: A.append(j) print((N - len(set(A))))
false
47.368421
[ "- A.append(list(map(int, input().split())))", "-hito = [i for i in range(1, N + 1)]", "-for i in range(N):", "- name = hito[i]", "- for j in range(K):", "- if name in A[j]:", "- hito[i] = -1", "- break", "-ans = set(hito)", "-print((len(ans) - 1))", "+ st = list(map(int, input().split()))", "+ for j in st:", "+ A.append(j)", "+print((N - len(set(A))))" ]
false
0.081535
0.044048
1.851061
[ "s254904634", "s892054839" ]
u353919145
p02771
python
s502455021
s033514913
165
17
38,256
2,940
Accepted
Accepted
89.7
def main(): a, b, c = list(map(int, input().split())) if (a == b and a != c) or (a == c and b != c) or (b == c and a != b): print("Yes") else: print("No") if __name__ == '__main__': main()
listt = list(map(int,input().split(" "))) sett = set(listt) if(len(sett)== 2): print("Yes") else: print("No")
9
7
223
124
def main(): a, b, c = list(map(int, input().split())) if (a == b and a != c) or (a == c and b != c) or (b == c and a != b): print("Yes") else: print("No") if __name__ == "__main__": main()
listt = list(map(int, input().split(" "))) sett = set(listt) if len(sett) == 2: print("Yes") else: print("No")
false
22.222222
[ "-def main():", "- a, b, c = list(map(int, input().split()))", "- if (a == b and a != c) or (a == c and b != c) or (b == c and a != b):", "- print(\"Yes\")", "- else:", "- print(\"No\")", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+listt = list(map(int, input().split(\" \")))", "+sett = set(listt)", "+if len(sett) == 2:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.076255
0.042834
1.780231
[ "s502455021", "s033514913" ]
u600402037
p03253
python
s933961489
s129980427
1,717
176
4,608
7,284
Accepted
Accepted
89.75
from math import factorial from collections import Counter N, M = list(map(int, input().split())) MOD = 10 ** 9 + 7 def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a A = prime_factorize(M) c = Counter(A) cases = 1 for v in list(c.values()): if v > 1: x = factorial(v+N-1)%MOD*pow(factorial(N-1)*factorial(v) % MOD, MOD-2, MOD)%MOD cases *= x else: cases *= N cases %= MOD print(cases)
import sys from collections import Counter sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() MOD = 10 ** 9 + 7 def prime_factorize(n): # Nの素因数分解 a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def combination(n, x, mod=10**9+7): # nCx 組み合わせ ex) combination(5, 2) = 10 factorial = [1] * (n+1) t = 1 for i in range(1, n+1): t = (t * i) % mod factorial[i] = t tmp = factorial[n] tmp = (tmp * pow(factorial[x], mod-2, mod)) % mod tmp = (tmp * pow(factorial[n-x], mod-2, mod)) % mod return tmp A = prime_factorize(M) counter = Counter(A) answer = 1 for c in list(counter.values()): answer *= combination((N-1+c), c) answer %= MOD print(answer) # 19
34
47
669
1,016
from math import factorial from collections import Counter N, M = list(map(int, input().split())) MOD = 10**9 + 7 def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a A = prime_factorize(M) c = Counter(A) cases = 1 for v in list(c.values()): if v > 1: x = ( factorial(v + N - 1) % MOD * pow(factorial(N - 1) * factorial(v) % MOD, MOD - 2, MOD) % MOD ) cases *= x else: cases *= N cases %= MOD print(cases)
import sys from collections import Counter sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() MOD = 10**9 + 7 def prime_factorize(n): # Nの素因数分解 a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def combination(n, x, mod=10**9 + 7): # nCx 組み合わせ ex) combination(5, 2) = 10 factorial = [1] * (n + 1) t = 1 for i in range(1, n + 1): t = (t * i) % mod factorial[i] = t tmp = factorial[n] tmp = (tmp * pow(factorial[x], mod - 2, mod)) % mod tmp = (tmp * pow(factorial[n - x], mod - 2, mod)) % mod return tmp A = prime_factorize(M) counter = Counter(A) answer = 1 for c in list(counter.values()): answer *= combination((N - 1 + c), c) answer %= MOD print(answer) # 19
false
27.659574
[ "-from math import factorial", "+import sys", "-N, M = list(map(int, input().split()))", "+sr = lambda: sys.stdin.readline().rstrip()", "+ir = lambda: int(sr())", "+lr = lambda: list(map(int, sr().split()))", "+N, M = lr()", "-def prime_factorize(n):", "+def prime_factorize(n): # Nの素因数分解", "+def combination(n, x, mod=10**9 + 7):", "+ # nCx 組み合わせ ex) combination(5, 2) = 10", "+ factorial = [1] * (n + 1)", "+ t = 1", "+ for i in range(1, n + 1):", "+ t = (t * i) % mod", "+ factorial[i] = t", "+ tmp = factorial[n]", "+ tmp = (tmp * pow(factorial[x], mod - 2, mod)) % mod", "+ tmp = (tmp * pow(factorial[n - x], mod - 2, mod)) % mod", "+ return tmp", "+", "+", "-c = Counter(A)", "-cases = 1", "-for v in list(c.values()):", "- if v > 1:", "- x = (", "- factorial(v + N - 1)", "- % MOD", "- * pow(factorial(N - 1) * factorial(v) % MOD, MOD - 2, MOD)", "- % MOD", "- )", "- cases *= x", "- else:", "- cases *= N", "- cases %= MOD", "-print(cases)", "+counter = Counter(A)", "+answer = 1", "+for c in list(counter.values()):", "+ answer *= combination((N - 1 + c), c)", "+ answer %= MOD", "+print(answer)", "+# 19" ]
false
0.269099
0.053255
5.053023
[ "s933961489", "s129980427" ]
u903005414
p02975
python
s052420079
s872386479
1,149
54
14,496
14,468
Accepted
Accepted
95.3
from itertools import permutations N = int(eval(input())) A = list(map(int, input().split())) # 1 ^ 2 ^ 3 ^ 4 ^ 4 などが0になる順番は関係ない # 各桁のビットが偶数になるかカウントする D = [0] * 30 for a in A: bit = bin(a)[2:][::-1] for i in range(len(bit)): D[i] += int(bit[i]) # print('D', D) ans = 'Yes' if all([d % 2 == 0 for d in D]) else 'No' print(ans)
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) if sum(A) == 0: print('Yes') exit() if len(A) % 3 != 0: print('No') exit() c = Counter(A) if len(list(c.values())) == 2: values = list(c.values()) if min(values) == N // 3: keys = list(c.keys()) if 0 in keys: print('Yes') exit() if len(list(c.values())) != 3: print('No') exit() keys = list(c.keys()) for i, j, k in ([0, 1, 2], [1, 2, 0], [2, 1, 0]): if keys[i] ^ keys[j] != keys[k]: print('No') exit() values = list(c.values()) if values[0] != values[1] or values[1] != values[2]: print('No') exit() print('Yes') # a b c a b c ... # a xor b = c # b xor c = a # c xor a = b # 全員0 # x 0 x x 0 x ...
15
46
352
826
from itertools import permutations N = int(eval(input())) A = list(map(int, input().split())) # 1 ^ 2 ^ 3 ^ 4 ^ 4 などが0になる順番は関係ない # 各桁のビットが偶数になるかカウントする D = [0] * 30 for a in A: bit = bin(a)[2:][::-1] for i in range(len(bit)): D[i] += int(bit[i]) # print('D', D) ans = "Yes" if all([d % 2 == 0 for d in D]) else "No" print(ans)
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) if sum(A) == 0: print("Yes") exit() if len(A) % 3 != 0: print("No") exit() c = Counter(A) if len(list(c.values())) == 2: values = list(c.values()) if min(values) == N // 3: keys = list(c.keys()) if 0 in keys: print("Yes") exit() if len(list(c.values())) != 3: print("No") exit() keys = list(c.keys()) for i, j, k in ([0, 1, 2], [1, 2, 0], [2, 1, 0]): if keys[i] ^ keys[j] != keys[k]: print("No") exit() values = list(c.values()) if values[0] != values[1] or values[1] != values[2]: print("No") exit() print("Yes") # a b c a b c ... # a xor b = c # b xor c = a # c xor a = b # 全員0 # x 0 x x 0 x ...
false
67.391304
[ "-from itertools import permutations", "+from collections import Counter", "-# 1 ^ 2 ^ 3 ^ 4 ^ 4 などが0になる順番は関係ない", "-# 各桁のビットが偶数になるかカウントする", "-D = [0] * 30", "-for a in A:", "- bit = bin(a)[2:][::-1]", "- for i in range(len(bit)):", "- D[i] += int(bit[i])", "-# print('D', D)", "-ans = \"Yes\" if all([d % 2 == 0 for d in D]) else \"No\"", "-print(ans)", "+if sum(A) == 0:", "+ print(\"Yes\")", "+ exit()", "+if len(A) % 3 != 0:", "+ print(\"No\")", "+ exit()", "+c = Counter(A)", "+if len(list(c.values())) == 2:", "+ values = list(c.values())", "+ if min(values) == N // 3:", "+ keys = list(c.keys())", "+ if 0 in keys:", "+ print(\"Yes\")", "+ exit()", "+if len(list(c.values())) != 3:", "+ print(\"No\")", "+ exit()", "+keys = list(c.keys())", "+for i, j, k in ([0, 1, 2], [1, 2, 0], [2, 1, 0]):", "+ if keys[i] ^ keys[j] != keys[k]:", "+ print(\"No\")", "+ exit()", "+values = list(c.values())", "+if values[0] != values[1] or values[1] != values[2]:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")", "+# a b c a b c ...", "+# a xor b = c", "+# b xor c = a", "+# c xor a = b", "+# 全員0", "+# x 0 x x 0 x ..." ]
false
0.04318
0.034873
1.238205
[ "s052420079", "s872386479" ]
u714878632
p02898
python
s406388860
s548613923
303
63
21,624
9,992
Accepted
Accepted
79.21
from sys import stdin import numpy as np # noinspection PyShadowingBuiltinsInspection def main(): n, k = [int(x) for x in input().split()] hs = [int(x) for x in input().split()] cnt = 0 for h in hs: if h >= k: cnt += 1 print(cnt) return if __name__ == "__main__": main()
N, K = input().split() N = int(N) K = int(K) heights = input().split() result = 0 for i in range(N): h = int(heights[i]) if h >= K: result += 1 print(result)
19
12
341
178
from sys import stdin import numpy as np # noinspection PyShadowingBuiltinsInspection def main(): n, k = [int(x) for x in input().split()] hs = [int(x) for x in input().split()] cnt = 0 for h in hs: if h >= k: cnt += 1 print(cnt) return if __name__ == "__main__": main()
N, K = input().split() N = int(N) K = int(K) heights = input().split() result = 0 for i in range(N): h = int(heights[i]) if h >= K: result += 1 print(result)
false
36.842105
[ "-from sys import stdin", "-import numpy as np", "-", "-# noinspection PyShadowingBuiltinsInspection", "-def main():", "- n, k = [int(x) for x in input().split()]", "- hs = [int(x) for x in input().split()]", "- cnt = 0", "- for h in hs:", "- if h >= k:", "- cnt += 1", "- print(cnt)", "- return", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+N, K = input().split()", "+N = int(N)", "+K = int(K)", "+heights = input().split()", "+result = 0", "+for i in range(N):", "+ h = int(heights[i])", "+ if h >= K:", "+ result += 1", "+print(result)" ]
false
0.045772
0.038577
1.186525
[ "s406388860", "s548613923" ]
u367130284
p03147
python
s007808617
s196203636
167
17
12,512
2,940
Accepted
Accepted
89.82
from itertools import* from numpy import* n,*a=list(map(int,open(0).read().split())) if set(a)=={0}: print((0)) exit() a=array(a) count=0 ans=0 while 1: count=min(a[a!=0]) ans+=count*sum(k for k,v in groupby(a>0)if k==True) a=a-min(a[a!=0]) a[a<0]=0 if sum(a)==0: break print(ans)
n,*a=list(map(int,open(0).read().split())) ans=0 pre=0 for i in a: if i>pre: ans+=i-pre pre=i print(ans)
17
8
324
121
from itertools import * from numpy import * n, *a = list(map(int, open(0).read().split())) if set(a) == {0}: print((0)) exit() a = array(a) count = 0 ans = 0 while 1: count = min(a[a != 0]) ans += count * sum(k for k, v in groupby(a > 0) if k == True) a = a - min(a[a != 0]) a[a < 0] = 0 if sum(a) == 0: break print(ans)
n, *a = list(map(int, open(0).read().split())) ans = 0 pre = 0 for i in a: if i > pre: ans += i - pre pre = i print(ans)
false
52.941176
[ "-from itertools import *", "-from numpy import *", "-", "-if set(a) == {0}:", "- print((0))", "- exit()", "-a = array(a)", "-count = 0", "-while 1:", "- count = min(a[a != 0])", "- ans += count * sum(k for k, v in groupby(a > 0) if k == True)", "- a = a - min(a[a != 0])", "- a[a < 0] = 0", "- if sum(a) == 0:", "- break", "+pre = 0", "+for i in a:", "+ if i > pre:", "+ ans += i - pre", "+ pre = i" ]
false
0.294618
0.043677
6.745395
[ "s007808617", "s196203636" ]
u845620905
p02694
python
s548924605
s305977190
25
21
9,164
9,148
Accepted
Accepted
16
k = int(eval(input())) now = 100 cnt = 0 while (now < k): now *= 1.01 now = int(now) cnt += 1 print(cnt)
x = int(eval(input())) money = 100 ans = 0 while(money < x): ans += 1 money *= 1.01 money = int(money) print(ans)
10
10
121
131
k = int(eval(input())) now = 100 cnt = 0 while now < k: now *= 1.01 now = int(now) cnt += 1 print(cnt)
x = int(eval(input())) money = 100 ans = 0 while money < x: ans += 1 money *= 1.01 money = int(money) print(ans)
false
0
[ "-k = int(eval(input()))", "-now = 100", "-cnt = 0", "-while now < k:", "- now *= 1.01", "- now = int(now)", "- cnt += 1", "-print(cnt)", "+x = int(eval(input()))", "+money = 100", "+ans = 0", "+while money < x:", "+ ans += 1", "+ money *= 1.01", "+ money = int(money)", "+print(ans)" ]
false
0.065921
0.042778
1.541017
[ "s548924605", "s305977190" ]
u433532588
p03103
python
s257403680
s447873462
473
289
29,032
20,072
Accepted
Accepted
38.9
N, M = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] A.sort(key=lambda x: x[0]) total = 0 remain = M for x in A: yen, num = x purchase = min(num, remain) total += (yen * purchase) remain -= purchase if remain == 0: print(total) exit()
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## N, M = list(map(int, input().split())) AB = [] for i in range(N): a, b = list(map(int, input().split())) AB.append([a, b]) AB.sort() ans = 0 for (yen, num) in AB: if num <= M: ans += (yen * num) M -= num else: ans += (yen * M) print(ans) exit() print(ans)
16
25
324
426
N, M = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] A.sort(key=lambda x: x[0]) total = 0 remain = M for x in A: yen, num = x purchase = min(num, remain) total += yen * purchase remain -= purchase if remain == 0: print(total) exit()
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## N, M = list(map(int, input().split())) AB = [] for i in range(N): a, b = list(map(int, input().split())) AB.append([a, b]) AB.sort() ans = 0 for (yen, num) in AB: if num <= M: ans += yen * num M -= num else: ans += yen * M print(ans) exit() print(ans)
false
36
[ "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**6)", "+##############################", "-A = [list(map(int, input().split())) for _ in range(N)]", "-A.sort(key=lambda x: x[0])", "-total = 0", "-remain = M", "-for x in A:", "- yen, num = x", "- purchase = min(num, remain)", "- total += yen * purchase", "- remain -= purchase", "- if remain == 0:", "- print(total)", "+AB = []", "+for i in range(N):", "+ a, b = list(map(int, input().split()))", "+ AB.append([a, b])", "+AB.sort()", "+ans = 0", "+for (yen, num) in AB:", "+ if num <= M:", "+ ans += yen * num", "+ M -= num", "+ else:", "+ ans += yen * M", "+ print(ans)", "+print(ans)" ]
false
0.008007
0.032105
0.249401
[ "s257403680", "s447873462" ]
u926678805
p04001
python
s710972640
s456049542
30
20
3,064
3,060
Accepted
Accepted
33.33
# coding: utf-8 s='+'.join(list(eval(input()))) ans=0 memo=set() def check(w,n): global ans if w in memo: return memo.add(w) ans+=eval(w) for i in range(1,n+1): count=0 for j in range(len(w)): if w[j]=='+': count+=1 if count==i: check(w[:j]+w[j+1:],n-1) check(s,(len(s)-1)//2) print(ans)
s=eval(input()) n=0 ans=0 while n<2**(len(s)-1): p=0 for i in range(len(s)-1): if n&(1<<i): ans+=int(s[p:i+1]) p=i+1 if p<len(s): ans+=int(s[p:]) n+=1 print(ans)
20
14
409
226
# coding: utf-8 s = "+".join(list(eval(input()))) ans = 0 memo = set() def check(w, n): global ans if w in memo: return memo.add(w) ans += eval(w) for i in range(1, n + 1): count = 0 for j in range(len(w)): if w[j] == "+": count += 1 if count == i: check(w[:j] + w[j + 1 :], n - 1) check(s, (len(s) - 1) // 2) print(ans)
s = eval(input()) n = 0 ans = 0 while n < 2 ** (len(s) - 1): p = 0 for i in range(len(s) - 1): if n & (1 << i): ans += int(s[p : i + 1]) p = i + 1 if p < len(s): ans += int(s[p:]) n += 1 print(ans)
false
30
[ "-# coding: utf-8", "-s = \"+\".join(list(eval(input())))", "+s = eval(input())", "+n = 0", "-memo = set()", "-", "-", "-def check(w, n):", "- global ans", "- if w in memo:", "- return", "- memo.add(w)", "- ans += eval(w)", "- for i in range(1, n + 1):", "- count = 0", "- for j in range(len(w)):", "- if w[j] == \"+\":", "- count += 1", "- if count == i:", "- check(w[:j] + w[j + 1 :], n - 1)", "-", "-", "-check(s, (len(s) - 1) // 2)", "+while n < 2 ** (len(s) - 1):", "+ p = 0", "+ for i in range(len(s) - 1):", "+ if n & (1 << i):", "+ ans += int(s[p : i + 1])", "+ p = i + 1", "+ if p < len(s):", "+ ans += int(s[p:])", "+ n += 1" ]
false
0.04634
0.081224
0.570516
[ "s710972640", "s456049542" ]
u156815136
p03481
python
s295996445
s295827078
37
21
5,276
3,316
Accepted
Accepted
43.24
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 # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): x,y = readInts() cnt = 0 while x <= y: cnt += 1 x *= 2 print(cnt) 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 # (string,3) 3回 #from collections import deque from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # 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())) x,y = readInts() cnt = 0 while x <= y: cnt += 1 x += x print(cnt)
34
32
705
683
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 # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): x, y = readInts() cnt = 0 while x <= y: cnt += 1 x *= 2 print(cnt) 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 # (string,3) 3回 # from collections import deque from collections import defaultdict # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # 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())) x, y = readInts() cnt = 0 while x <= y: cnt += 1 x += x print(cnt)
false
5.882353
[ "-from statistics import median", "-", "+# from statistics import median", "-from fractions import gcd", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "+# from fractions import gcd", "+# from itertools import combinations # (string,3) 3回", "+# from collections import deque", "-import bisect", "+# import bisect", "-", "-", "+# mod = 9982443453", "-def main():", "- x, y = readInts()", "- cnt = 0", "- while x <= y:", "- cnt += 1", "- x *= 2", "- print(cnt)", "+def I():", "+ return int(eval(input()))", "-if __name__ == \"__main__\":", "- main()", "+x, y = readInts()", "+cnt = 0", "+while x <= y:", "+ cnt += 1", "+ x += x", "+print(cnt)" ]
false
0.080696
0.038797
2.079927
[ "s295996445", "s295827078" ]
u961674365
p02678
python
s491475652
s701643793
924
842
52,092
58,840
Accepted
Accepted
8.87
from collections import deque n,m = list(map(int,input().split())) ab = [[] for _ in range(m)] kr = [[] for _ in range(n)] dist = [-1 for _ in range(n)] dist[0] = 0 ans = [-1 for _ in range(n)] qn = deque([1]) for i in range(m): a,b = list(map(int,input().split())) a,b = min(a,b),max(a,b) ab[i] = [a,b] kr[a-1].append(b) kr[b-1].append(a) dis = 1 while len(qn) > 0: v = qn.popleft() d = dist[v-1] for w in kr[v-1]: if dist[w-1] > -1: continue dist[w-1] = d + 1 qn.append(w) ans[w-1] = v #print(dist) #ab.sort() #print(ab) #print(kr) print('Yes') for i in range(1,n): print((ans[i]))
from collections import deque n,m = list(map(int,input().split())) ab = [list(map(int,input().split())) for _ in range(m)] conn = [[] for _ in range(n)] for a,b in ab: conn[a-1].append(b) conn[b-1].append(a) q = deque([1]) #for x in conn[0]: # q.append(x) ans = [-1 for _ in range(n)] depth = ans[:] depth[0] = 0 while q: v = q.popleft() d = depth[v-1] #print(v) for w in conn[v-1]: if depth[w-1] != -1: continue depth[w-1] = d + 1 ans[w-1] = v q.append(w) #print(v,w,d) print('Yes') for i in range(1,n): print((ans[i])) #print(conn)
39
30
695
639
from collections import deque n, m = list(map(int, input().split())) ab = [[] for _ in range(m)] kr = [[] for _ in range(n)] dist = [-1 for _ in range(n)] dist[0] = 0 ans = [-1 for _ in range(n)] qn = deque([1]) for i in range(m): a, b = list(map(int, input().split())) a, b = min(a, b), max(a, b) ab[i] = [a, b] kr[a - 1].append(b) kr[b - 1].append(a) dis = 1 while len(qn) > 0: v = qn.popleft() d = dist[v - 1] for w in kr[v - 1]: if dist[w - 1] > -1: continue dist[w - 1] = d + 1 qn.append(w) ans[w - 1] = v # print(dist) # ab.sort() # print(ab) # print(kr) print("Yes") for i in range(1, n): print((ans[i]))
from collections import deque n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] conn = [[] for _ in range(n)] for a, b in ab: conn[a - 1].append(b) conn[b - 1].append(a) q = deque([1]) # for x in conn[0]: # q.append(x) ans = [-1 for _ in range(n)] depth = ans[:] depth[0] = 0 while q: v = q.popleft() d = depth[v - 1] # print(v) for w in conn[v - 1]: if depth[w - 1] != -1: continue depth[w - 1] = d + 1 ans[w - 1] = v q.append(w) # print(v,w,d) print("Yes") for i in range(1, n): print((ans[i])) # print(conn)
false
23.076923
[ "-ab = [[] for _ in range(m)]", "-kr = [[] for _ in range(n)]", "-dist = [-1 for _ in range(n)]", "-dist[0] = 0", "+ab = [list(map(int, input().split())) for _ in range(m)]", "+conn = [[] for _ in range(n)]", "+for a, b in ab:", "+ conn[a - 1].append(b)", "+ conn[b - 1].append(a)", "+q = deque([1])", "+# for x in conn[0]:", "+# q.append(x)", "-qn = deque([1])", "-for i in range(m):", "- a, b = list(map(int, input().split()))", "- a, b = min(a, b), max(a, b)", "- ab[i] = [a, b]", "- kr[a - 1].append(b)", "- kr[b - 1].append(a)", "-dis = 1", "-while len(qn) > 0:", "- v = qn.popleft()", "- d = dist[v - 1]", "- for w in kr[v - 1]:", "- if dist[w - 1] > -1:", "+depth = ans[:]", "+depth[0] = 0", "+while q:", "+ v = q.popleft()", "+ d = depth[v - 1]", "+ # print(v)", "+ for w in conn[v - 1]:", "+ if depth[w - 1] != -1:", "- dist[w - 1] = d + 1", "- qn.append(w)", "+ depth[w - 1] = d + 1", "-# print(dist)", "-# ab.sort()", "-# print(ab)", "-# print(kr)", "+ q.append(w)", "+ # print(v,w,d)", "+# print(conn)" ]
false
0.006935
0.042384
0.163634
[ "s491475652", "s701643793" ]
u389910364
p03262
python
s999597887
s895022880
288
258
24,084
22,532
Accepted
Accepted
10.42
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N, S = list(map(int, sys.stdin.readline().split())) X = list(map(int, sys.stdin.readline().split())) X = np.array(X + [S]) X -= X.min() print((reduce(gcd, X)))
import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 N, X0 = list(map(int, sys.stdin.buffer.readline().split())) X = list(map(int, sys.stdin.buffer.readline().split())) X = np.array(X, dtype=int) - X0 X = np.abs(X) ans = reduce(gcd, X) print(ans)
32
35
666
763
import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 N, S = list(map(int, sys.stdin.readline().split())) X = list(map(int, sys.stdin.readline().split())) X = np.array(X + [S]) X -= X.min() print((reduce(gcd, X)))
import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10**9) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 # MOD = 998244353 N, X0 = list(map(int, sys.stdin.buffer.readline().split())) X = list(map(int, sys.stdin.buffer.readline().split())) X = np.array(X, dtype=int) - X0 X = np.abs(X) ans = reduce(gcd, X) print(ans)
false
8.571429
[ "+import cmath", "+import operator", "-from operator import itemgetter", "+from operator import itemgetter, mul, add, xor", "-sys.setrecursionlimit(2147483647)", "+sys.setrecursionlimit(10**9)", "-N, S = list(map(int, sys.stdin.readline().split()))", "-X = list(map(int, sys.stdin.readline().split()))", "-X = np.array(X + [S])", "-X -= X.min()", "-print((reduce(gcd, X)))", "+# MOD = 998244353", "+N, X0 = list(map(int, sys.stdin.buffer.readline().split()))", "+X = list(map(int, sys.stdin.buffer.readline().split()))", "+X = np.array(X, dtype=int) - X0", "+X = np.abs(X)", "+ans = reduce(gcd, X)", "+print(ans)" ]
false
0.253262
0.260851
0.970906
[ "s999597887", "s895022880" ]
u827202523
p02696
python
s288598175
s926521403
71
65
65,392
62,360
Accepted
Accepted
8.45
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) from collections import defaultdict from sys import exit import math def main(): a,b,x = getList() if x < b: print((math.floor( (a*x) / b) - a * math.floor(x/b) )) else: k = b - 1 print((math.floor( (a * k) / b) - a * math.floor(k / b) )) if __name__ == "__main__": main()
import sys # from collections import defaultdict, deque import math # import copy # from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10 ** 20 MOD = 1000000007 def solve(): a, b, n = getList() if n >= b-1: x = b - 1 else: x = n print((math.floor((a * x) / b) - a * math.floor(x/b))) return def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
22
35
485
739
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) from collections import defaultdict from sys import exit import math def main(): a, b, x = getList() if x < b: print((math.floor((a * x) / b) - a * math.floor(x / b))) else: k = b - 1 print((math.floor((a * k) / b) - a * math.floor(k / b))) if __name__ == "__main__": main()
import sys # from collections import defaultdict, deque import math # import copy # from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(eval(input())) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10**20 MOD = 1000000007 def solve(): a, b, n = getList() if n >= b - 1: x = b - 1 else: x = n print((math.floor((a * x) / b) - a * math.floor(x / b))) return def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
false
37.142857
[ "-def getN():", "- return int(eval(input()))", "+import sys", "+", "+# from collections import defaultdict, deque", "+import math", "+", "+# import copy", "+# from bisect import bisect_left, bisect_right", "+# import heapq", "+# sys.setrecursionlimit(1000000)", "+# input aliases", "+input = sys.stdin.readline", "+getS = lambda: input().strip()", "+getN = lambda: int(eval(input()))", "+getList = lambda: list(map(int, input().split()))", "+getZList = lambda: [int(x) - 1 for x in input().split()]", "+INF = 10**20", "+MOD = 1000000007", "-def getNM():", "- return list(map(int, input().split()))", "-", "-", "-def getList():", "- return list(map(int, input().split()))", "-", "-", "-from collections import defaultdict", "-from sys import exit", "-import math", "+def solve():", "+ a, b, n = getList()", "+ if n >= b - 1:", "+ x = b - 1", "+ else:", "+ x = n", "+ print((math.floor((a * x) / b) - a * math.floor(x / b)))", "+ return", "- a, b, x = getList()", "- if x < b:", "- print((math.floor((a * x) / b) - a * math.floor(x / b)))", "- else:", "- k = b - 1", "- print((math.floor((a * k) / b) - a * math.floor(k / b)))", "+ n = getN()", "+ for _ in range(n):", "+ solve()", "- main()", "+ # main()", "+ solve()" ]
false
0.051097
0.051228
0.99745
[ "s288598175", "s926521403" ]
u891847179
p02726
python
s046778614
s958529449
1,133
344
3,444
48,220
Accepted
Accepted
69.64
N, X, Y = list(map(int, input().split())) res = [0] * N for j in range(1, N + 1): for i in range(1, j): res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1 for i in range(1, N): print((res[i]))
from collections import defaultdict import math N, X, Y = list(map(int, input().split())) res = defaultdict(int) x = [] for i in range(1, N + 1): for j in range(1, N + 1): if i >= j: continue if i == X and Y == j: key = 1 else: key = int(min(j - i, math.fabs(X - i) + math.fabs(Y - j) + 1)) res[key] += 1 for i in range(1, N): print((res[i]))
8
18
214
436
N, X, Y = list(map(int, input().split())) res = [0] * N for j in range(1, N + 1): for i in range(1, j): res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1 for i in range(1, N): print((res[i]))
from collections import defaultdict import math N, X, Y = list(map(int, input().split())) res = defaultdict(int) x = [] for i in range(1, N + 1): for j in range(1, N + 1): if i >= j: continue if i == X and Y == j: key = 1 else: key = int(min(j - i, math.fabs(X - i) + math.fabs(Y - j) + 1)) res[key] += 1 for i in range(1, N): print((res[i]))
false
55.555556
[ "+from collections import defaultdict", "+import math", "+", "-res = [0] * N", "-for j in range(1, N + 1):", "- for i in range(1, j):", "- res[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1", "+res = defaultdict(int)", "+x = []", "+for i in range(1, N + 1):", "+ for j in range(1, N + 1):", "+ if i >= j:", "+ continue", "+ if i == X and Y == j:", "+ key = 1", "+ else:", "+ key = int(min(j - i, math.fabs(X - i) + math.fabs(Y - j) + 1))", "+ res[key] += 1" ]
false
0.037946
0.073641
0.515279
[ "s046778614", "s958529449" ]
u576432509
p02899
python
s120638213
s389636575
229
189
22,252
14,008
Accepted
Accepted
17.47
n=int(input()) a=(input().split()) a1={} for i in range(n): a1[(a[i])]=i+1 str1="" for i in range(n): print(str(a1[str(i+1)]),end=" ") print()
n=int(input()) a=list(map(int,input().split())) rev=[0]*n for i in range(n): rev[a[i]-1]=i+1 for i in range(n): print(rev[i],end=" ") print()
9
10
158
160
n = int(input()) a = input().split() a1 = {} for i in range(n): a1[(a[i])] = i + 1 str1 = "" for i in range(n): print(str(a1[str(i + 1)]), end=" ") print()
n = int(input()) a = list(map(int, input().split())) rev = [0] * n for i in range(n): rev[a[i] - 1] = i + 1 for i in range(n): print(rev[i], end=" ") print()
false
10
[ "-a = input().split()", "-a1 = {}", "+a = list(map(int, input().split()))", "+rev = [0] * n", "- a1[(a[i])] = i + 1", "-str1 = \"\"", "+ rev[a[i] - 1] = i + 1", "- print(str(a1[str(i + 1)]), end=\" \")", "+ print(rev[i], end=\" \")" ]
false
0.050069
0.052426
0.955041
[ "s120638213", "s389636575" ]
u013408661
p03096
python
s722795515
s845203150
268
223
16,556
18,072
Accepted
Accepted
16.79
import sys n=int(eval(input())) c=[int(i) for i in sys.stdin] x=[0]*(200001) c.append(0) x[c[0]]+= 1 num=1 p=10**9 +7 for i in range(1,n): if c[i]-c[i-1]: x[c[i]]+= num x[c[i]]= x[c[i]]%p if c[i]-c[i+1]: num=x[c[i]]%p else: num=0 print(num)
import sys n=int(eval(input())) c=[int(i) for i in sys.stdin] #連続した数を除去したlist d=[] #前の数を保存する変数 stack=0 for i in c: if i!=stack: d.append(i) stack=i #0で初期化 x=[0]*200001 sum=1 p=10**9+7 for i in range(0,len(d)): x[d[i]]= (x[d[i]]+sum)%p sum=x[d[i]]%p print(sum)
17
19
272
283
import sys n = int(eval(input())) c = [int(i) for i in sys.stdin] x = [0] * (200001) c.append(0) x[c[0]] += 1 num = 1 p = 10**9 + 7 for i in range(1, n): if c[i] - c[i - 1]: x[c[i]] += num x[c[i]] = x[c[i]] % p if c[i] - c[i + 1]: num = x[c[i]] % p else: num = 0 print(num)
import sys n = int(eval(input())) c = [int(i) for i in sys.stdin] # 連続した数を除去したlist d = [] # 前の数を保存する変数 stack = 0 for i in c: if i != stack: d.append(i) stack = i # 0で初期化 x = [0] * 200001 sum = 1 p = 10**9 + 7 for i in range(0, len(d)): x[d[i]] = (x[d[i]] + sum) % p sum = x[d[i]] % p print(sum)
false
10.526316
[ "-x = [0] * (200001)", "-c.append(0)", "-x[c[0]] += 1", "-num = 1", "+# 連続した数を除去したlist", "+d = []", "+# 前の数を保存する変数", "+stack = 0", "+for i in c:", "+ if i != stack:", "+ d.append(i)", "+ stack = i", "+# 0で初期化", "+x = [0] * 200001", "+sum = 1", "-for i in range(1, n):", "- if c[i] - c[i - 1]:", "- x[c[i]] += num", "- x[c[i]] = x[c[i]] % p", "- if c[i] - c[i + 1]:", "- num = x[c[i]] % p", "- else:", "- num = 0", "-print(num)", "+for i in range(0, len(d)):", "+ x[d[i]] = (x[d[i]] + sum) % p", "+ sum = x[d[i]] % p", "+print(sum)" ]
false
0.093484
0.08457
1.105401
[ "s722795515", "s845203150" ]
u686036872
p03487
python
s652244357
s467031292
129
80
20,592
18,676
Accepted
Accepted
37.98
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) ans = 0 for i in set(A): if i > c[i]: ans += c[i] if i < c[i]: ans += (c[i] -i) print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) ans = 0 for k, v in list(c.items()): if k > v: ans += v else: ans += (v-k) print(ans)
14
15
229
221
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) ans = 0 for i in set(A): if i > c[i]: ans += c[i] if i < c[i]: ans += c[i] - i print(ans)
from collections import Counter N = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) ans = 0 for k, v in list(c.items()): if k > v: ans += v else: ans += v - k print(ans)
false
6.666667
[ "-import collections", "+from collections import Counter", "-A = list(map(int, input().split()))", "-c = collections.Counter(A)", "+a = list(map(int, input().split()))", "+c = Counter(a)", "-for i in set(A):", "- if i > c[i]:", "- ans += c[i]", "- if i < c[i]:", "- ans += c[i] - i", "+for k, v in list(c.items()):", "+ if k > v:", "+ ans += v", "+ else:", "+ ans += v - k" ]
false
0.038313
0.052029
0.736377
[ "s652244357", "s467031292" ]
u678167152
p03221
python
s759665405
s362873728
625
520
29,920
109,116
Accepted
Accepted
16.8
N, M = map(int, input().split()) from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort def solve(N,M): pref = [[] for _ in range(N)] P = [0]*M Y = [0]*M for i in range(M): P[i],Y[i] = map(int, input().split()) pref[P[i]-1].append(Y[i]) for i in range(N): pref[i].sort() ans = [] for i in range(M): ind = bisect_left(pref[P[i]-1],Y[i]) ans.append('0'*(6-len(str(P[i])))+str(P[i])+'0'*(6-len(str(ind+1)))+str(ind+1)) return ans print(*solve(N,M),sep='\n')
def solve(): N, M = map(int, input().split()) A = [list(map(int, input().split()))+[i] for i in range(M)] A.sort(key=lambda x:(x[0],x[1])) ans = [0]*M before = -1 for p,y,i in A: if p!=before: year = 1 else: year += 1 ans[i] = '0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(year)))+str(year) before = p return ans print(*solve(),sep='\n')
17
16
576
391
N, M = map(int, input().split()) from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort def solve(N, M): pref = [[] for _ in range(N)] P = [0] * M Y = [0] * M for i in range(M): P[i], Y[i] = map(int, input().split()) pref[P[i] - 1].append(Y[i]) for i in range(N): pref[i].sort() ans = [] for i in range(M): ind = bisect_left(pref[P[i] - 1], Y[i]) ans.append( "0" * (6 - len(str(P[i]))) + str(P[i]) + "0" * (6 - len(str(ind + 1))) + str(ind + 1) ) return ans print(*solve(N, M), sep="\n")
def solve(): N, M = map(int, input().split()) A = [list(map(int, input().split())) + [i] for i in range(M)] A.sort(key=lambda x: (x[0], x[1])) ans = [0] * M before = -1 for p, y, i in A: if p != before: year = 1 else: year += 1 ans[i] = ( "0" * (6 - len(str(p))) + str(p) + "0" * (6 - len(str(year))) + str(year) ) before = p return ans print(*solve(), sep="\n")
false
5.882353
[ "-N, M = map(int, input().split())", "-from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort", "-", "-", "-def solve(N, M):", "- pref = [[] for _ in range(N)]", "- P = [0] * M", "- Y = [0] * M", "- for i in range(M):", "- P[i], Y[i] = map(int, input().split())", "- pref[P[i] - 1].append(Y[i])", "- for i in range(N):", "- pref[i].sort()", "- ans = []", "- for i in range(M):", "- ind = bisect_left(pref[P[i] - 1], Y[i])", "- ans.append(", "- \"0\" * (6 - len(str(P[i])))", "- + str(P[i])", "- + \"0\" * (6 - len(str(ind + 1)))", "- + str(ind + 1)", "+def solve():", "+ N, M = map(int, input().split())", "+ A = [list(map(int, input().split())) + [i] for i in range(M)]", "+ A.sort(key=lambda x: (x[0], x[1]))", "+ ans = [0] * M", "+ before = -1", "+ for p, y, i in A:", "+ if p != before:", "+ year = 1", "+ else:", "+ year += 1", "+ ans[i] = (", "+ \"0\" * (6 - len(str(p))) + str(p) + \"0\" * (6 - len(str(year))) + str(year)", "+ before = p", "-print(*solve(N, M), sep=\"\\n\")", "+print(*solve(), sep=\"\\n\")" ]
false
0.059789
0.037036
1.61434
[ "s759665405", "s362873728" ]
u729939940
p02761
python
s487708039
s018871904
29
26
9,104
9,176
Accepted
Accepted
10.34
N,M=list(map(int,input().split())) SC=[input().split() for _ in range(M)] ans=["0"]*N for s,c in SC: if ans[int(s)-1]!="0" and ans[int(s)-1]!=c: print((-1)) exit() if N>1 and s=="1" and c=="0": print((-1)) exit() ans[int(s)-1]=c if ans[0]=="0" and N>1: ans[0]="1" print(("".join(ans)))
N,M=list(map(int,input().split())) SC=[input().split() for _ in range(M)] ans=["0"]*N for s,c in SC: if ans[int(s)-1]!="0" and ans[int(s)-1]!=c: print((-1)) exit() if N>1 and int(s)==1 and c=="0": print((-1)) exit() ans[int(s)-1]=c if N>1 and ans[0]=="0": ans[0]="1" print(("".join(ans)))
14
14
310
313
N, M = list(map(int, input().split())) SC = [input().split() for _ in range(M)] ans = ["0"] * N for s, c in SC: if ans[int(s) - 1] != "0" and ans[int(s) - 1] != c: print((-1)) exit() if N > 1 and s == "1" and c == "0": print((-1)) exit() ans[int(s) - 1] = c if ans[0] == "0" and N > 1: ans[0] = "1" print(("".join(ans)))
N, M = list(map(int, input().split())) SC = [input().split() for _ in range(M)] ans = ["0"] * N for s, c in SC: if ans[int(s) - 1] != "0" and ans[int(s) - 1] != c: print((-1)) exit() if N > 1 and int(s) == 1 and c == "0": print((-1)) exit() ans[int(s) - 1] = c if N > 1 and ans[0] == "0": ans[0] = "1" print(("".join(ans)))
false
0
[ "- if N > 1 and s == \"1\" and c == \"0\":", "+ if N > 1 and int(s) == 1 and c == \"0\":", "-if ans[0] == \"0\" and N > 1:", "+if N > 1 and ans[0] == \"0\":" ]
false
0.048412
0.048462
0.998969
[ "s487708039", "s018871904" ]
u602677143
p03610
python
s986200255
s519998986
84
18
4,596
3,188
Accepted
Accepted
78.57
s = input() for i in range(1,len(s)+1): if i % 2 == 1: print(s[i-1],end="")
s = eval(input()) print((s[0::2]))
4
2
90
27
s = input() for i in range(1, len(s) + 1): if i % 2 == 1: print(s[i - 1], end="")
s = eval(input()) print((s[0::2]))
false
50
[ "-s = input()", "-for i in range(1, len(s) + 1):", "- if i % 2 == 1:", "- print(s[i - 1], end=\"\")", "+s = eval(input())", "+print((s[0::2]))" ]
false
0.04062
0.039327
1.032861
[ "s986200255", "s519998986" ]
u163783894
p02617
python
s421973305
s691017684
479
187
9,176
57,216
Accepted
Accepted
60.96
N = int(eval(input())) ans = 0 for i in range(1, N + 1): ans += i * (N + 1 - i) for i in range(N - 1): u, v = list(map(int, input().split())) u, v = min(u, v), max(u, v) ans -= (N - v + 1) * u print(ans)
N,*t=list(map(int,open(0).read().split())) t=iter(t) print((N*(N+1)*(N+2)//6+sum([-min(a,b)*(N-max(a,b)+1) for a,b in zip(t,t)])))
12
3
222
124
N = int(eval(input())) ans = 0 for i in range(1, N + 1): ans += i * (N + 1 - i) for i in range(N - 1): u, v = list(map(int, input().split())) u, v = min(u, v), max(u, v) ans -= (N - v + 1) * u print(ans)
N, *t = list(map(int, open(0).read().split())) t = iter(t) print( ( N * (N + 1) * (N + 2) // 6 + sum([-min(a, b) * (N - max(a, b) + 1) for a, b in zip(t, t)]) ) )
false
75
[ "-N = int(eval(input()))", "-ans = 0", "-for i in range(1, N + 1):", "- ans += i * (N + 1 - i)", "-for i in range(N - 1):", "- u, v = list(map(int, input().split()))", "- u, v = min(u, v), max(u, v)", "- ans -= (N - v + 1) * u", "-print(ans)", "+N, *t = list(map(int, open(0).read().split()))", "+t = iter(t)", "+print(", "+ (", "+ N * (N + 1) * (N + 2) // 6", "+ + sum([-min(a, b) * (N - max(a, b) + 1) for a, b in zip(t, t)])", "+ )", "+)" ]
false
0.036021
0.036473
0.987622
[ "s421973305", "s691017684" ]
u432251613
p02792
python
s947496033
s644342403
190
165
3,064
3,064
Accepted
Accepted
13.16
def main(): N = int(eval(input())) # ある数値nについて、n[0]..n[-1]とすると # 1~n-1の中のある数値mに対して、n[0]==m[-1]&&n[-1]==m[0]となるようなmがいくつ存在するか調べたい # n:1...3 -> m:3...1かつlen(n)>len(m)を満たすもの*2 # n:3...1 -> m:1...3かつlen(n)>=len(m)を満たすもの*2 # n:1...1 -> m:1...1かつlen(n)>=len(m)を満たすもの*2 # 下のパターンで、n[0]==n[-1]のときだけ(n,n)が重複するので-1する if N<=9: print(N) else: count = 9 for n in range(10,N+1): n = str(n) nlen = len(n) if n[-1] == '0': continue if n[0]<n[-1]: tmp = int('1'*(nlen-2)) if nlen>2 else 0 count += tmp*2 elif n[0]>n[-1]: tmp = int('1'*(nlen-1)) if nlen>2 else 1 count += tmp*2 else: # 2桁以上(10~)と比較 tmp = int('1'*(nlen-2))+int(n[1:-1])+1 if nlen>2 else 1 count += tmp*2-1 # 1桁(1~9)と比較 count += 2 print(count) main()
def main(): N = int(eval(input())) # cnt[a][b] := 先頭がa,末尾がqである数の個数 cnt = [[0]*10 for i in range(10)] for i in range(1,N+1): s = str(i) cnt[int(s[0])][int(s[-1])] += 1 ans = 0 for a in range(10): for b in range(10): ans += cnt[a][b]*cnt[b][a] print(ans) main()
32
14
1,022
332
def main(): N = int(eval(input())) # ある数値nについて、n[0]..n[-1]とすると # 1~n-1の中のある数値mに対して、n[0]==m[-1]&&n[-1]==m[0]となるようなmがいくつ存在するか調べたい # n:1...3 -> m:3...1かつlen(n)>len(m)を満たすもの*2 # n:3...1 -> m:1...3かつlen(n)>=len(m)を満たすもの*2 # n:1...1 -> m:1...1かつlen(n)>=len(m)を満たすもの*2 # 下のパターンで、n[0]==n[-1]のときだけ(n,n)が重複するので-1する if N <= 9: print(N) else: count = 9 for n in range(10, N + 1): n = str(n) nlen = len(n) if n[-1] == "0": continue if n[0] < n[-1]: tmp = int("1" * (nlen - 2)) if nlen > 2 else 0 count += tmp * 2 elif n[0] > n[-1]: tmp = int("1" * (nlen - 1)) if nlen > 2 else 1 count += tmp * 2 else: # 2桁以上(10~)と比較 tmp = int("1" * (nlen - 2)) + int(n[1:-1]) + 1 if nlen > 2 else 1 count += tmp * 2 - 1 # 1桁(1~9)と比較 count += 2 print(count) main()
def main(): N = int(eval(input())) # cnt[a][b] := 先頭がa,末尾がqである数の個数 cnt = [[0] * 10 for i in range(10)] for i in range(1, N + 1): s = str(i) cnt[int(s[0])][int(s[-1])] += 1 ans = 0 for a in range(10): for b in range(10): ans += cnt[a][b] * cnt[b][a] print(ans) main()
false
56.25
[ "- # ある数値nについて、n[0]..n[-1]とすると", "- # 1~n-1の中のある数値mに対して、n[0]==m[-1]&&n[-1]==m[0]となるようなmがいくつ存在するか調べたい", "- # n:1...3 -> m:3...1かつlen(n)>len(m)を満たすもの*2", "- # n:3...1 -> m:1...3かつlen(n)>=len(m)を満たすもの*2", "- # n:1...1 -> m:1...1かつlen(n)>=len(m)を満たすもの*2", "- # 下のパターンで、n[0]==n[-1]のときだけ(n,n)が重複するので-1する", "- if N <= 9:", "- print(N)", "- else:", "- count = 9", "- for n in range(10, N + 1):", "- n = str(n)", "- nlen = len(n)", "- if n[-1] == \"0\":", "- continue", "- if n[0] < n[-1]:", "- tmp = int(\"1\" * (nlen - 2)) if nlen > 2 else 0", "- count += tmp * 2", "- elif n[0] > n[-1]:", "- tmp = int(\"1\" * (nlen - 1)) if nlen > 2 else 1", "- count += tmp * 2", "- else:", "- # 2桁以上(10~)と比較", "- tmp = int(\"1\" * (nlen - 2)) + int(n[1:-1]) + 1 if nlen > 2 else 1", "- count += tmp * 2 - 1", "- # 1桁(1~9)と比較", "- count += 2", "- print(count)", "+ # cnt[a][b] := 先頭がa,末尾がqである数の個数", "+ cnt = [[0] * 10 for i in range(10)]", "+ for i in range(1, N + 1):", "+ s = str(i)", "+ cnt[int(s[0])][int(s[-1])] += 1", "+ ans = 0", "+ for a in range(10):", "+ for b in range(10):", "+ ans += cnt[a][b] * cnt[b][a]", "+ print(ans)" ]
false
0.043166
0.044121
0.978358
[ "s947496033", "s644342403" ]
u150984829
p00467
python
s518968235
s767832719
40
30
5,640
5,644
Accepted
Accepted
25
for e in iter(input,'0 0'): N,M=list(map(int,e.split())) k,p=1,0 S=[int(eval(input())) for _ in[0]*N] for d in[int(eval(input()))for _ in[0]*M]: p+=d if N<=p+d else d+S[p+d] if N<=p+1:break k+=1 print(k)
def s(): import sys r=sys.stdin.readline for e in iter(r,'0 0\n'): N,M=list(map(int,e.split())) k,p=1,0 S=[int(r()) for _ in[0]*N] for d in[int(r())for _ in[0]*M]: p+=d if N<=p+d else d+S[p+d] if N<=p+1:break k+=1 print(k) if'__main__'==__name__:s()
9
13
205
278
for e in iter(input, "0 0"): N, M = list(map(int, e.split())) k, p = 1, 0 S = [int(eval(input())) for _ in [0] * N] for d in [int(eval(input())) for _ in [0] * M]: p += d if N <= p + d else d + S[p + d] if N <= p + 1: break k += 1 print(k)
def s(): import sys r = sys.stdin.readline for e in iter(r, "0 0\n"): N, M = list(map(int, e.split())) k, p = 1, 0 S = [int(r()) for _ in [0] * N] for d in [int(r()) for _ in [0] * M]: p += d if N <= p + d else d + S[p + d] if N <= p + 1: break k += 1 print(k) if "__main__" == __name__: s()
false
30.769231
[ "-for e in iter(input, \"0 0\"):", "- N, M = list(map(int, e.split()))", "- k, p = 1, 0", "- S = [int(eval(input())) for _ in [0] * N]", "- for d in [int(eval(input())) for _ in [0] * M]:", "- p += d if N <= p + d else d + S[p + d]", "- if N <= p + 1:", "- break", "- k += 1", "- print(k)", "+def s():", "+ import sys", "+", "+ r = sys.stdin.readline", "+ for e in iter(r, \"0 0\\n\"):", "+ N, M = list(map(int, e.split()))", "+ k, p = 1, 0", "+ S = [int(r()) for _ in [0] * N]", "+ for d in [int(r()) for _ in [0] * M]:", "+ p += d if N <= p + d else d + S[p + d]", "+ if N <= p + 1:", "+ break", "+ k += 1", "+ print(k)", "+", "+", "+if \"__main__\" == __name__:", "+ s()" ]
false
0.037275
0.044402
0.839489
[ "s518968235", "s767832719" ]
u555649269
p02690
python
s260373583
s507998704
994
33
8,980
9,188
Accepted
Accepted
96.68
def get(n): for i in range(-1000,1001): for j in range(-1000,1001): if(i**5-j**5==n): print((i,j)) return n=int(eval(input())) get(n)
l=[] for i in range(0,1001): l.append(i**5) n=int(eval(input())) for i in range(0,1001): if((l[i]-n) in l): print((i,l.index(l[i]-n))) break elif((n-l[i]) in l): print((i,-l.index(-l[i]+n))) break
8
14
188
258
def get(n): for i in range(-1000, 1001): for j in range(-1000, 1001): if i**5 - j**5 == n: print((i, j)) return n = int(eval(input())) get(n)
l = [] for i in range(0, 1001): l.append(i**5) n = int(eval(input())) for i in range(0, 1001): if (l[i] - n) in l: print((i, l.index(l[i] - n))) break elif (n - l[i]) in l: print((i, -l.index(-l[i] + n))) break
false
42.857143
[ "-def get(n):", "- for i in range(-1000, 1001):", "- for j in range(-1000, 1001):", "- if i**5 - j**5 == n:", "- print((i, j))", "- return", "-", "-", "+l = []", "+for i in range(0, 1001):", "+ l.append(i**5)", "-get(n)", "+for i in range(0, 1001):", "+ if (l[i] - n) in l:", "+ print((i, l.index(l[i] - n)))", "+ break", "+ elif (n - l[i]) in l:", "+ print((i, -l.index(-l[i] + n)))", "+ break" ]
false
2.63191
0.037603
69.992841
[ "s260373583", "s507998704" ]
u530383736
p03998
python
s150391333
s480588110
19
17
3,064
3,060
Accepted
Accepted
10.53
# -*- coding: utf-8 -*- SA,SB,SC = [input().strip() for _ in range(3)] ia,ib,ic=0,0,0 turn="a" while True: if turn == "a": if SA == "": print("A") break turn = SA[0] SA = SA[1:] if turn == "b": if SB == "": print("B") break turn = SB[0] SB = SB[1:] if turn == "c": if SC == "": print("C") break turn = SC[0] SC = SC[1:]
# -*- coding: utf-8 -*- SA,SB,SC = [input().strip() for _ in range(3)] S_dic={} S_dic['a']=SA S_dic['b']=SB S_dic['c']=SC turn="a" while True: if S_dic[turn] == "": print((turn.upper())) break next_turn = S_dic[turn][0] S_dic[turn] = S_dic[turn][1:] turn = next_turn
31
18
448
318
# -*- coding: utf-8 -*- SA, SB, SC = [input().strip() for _ in range(3)] ia, ib, ic = 0, 0, 0 turn = "a" while True: if turn == "a": if SA == "": print("A") break turn = SA[0] SA = SA[1:] if turn == "b": if SB == "": print("B") break turn = SB[0] SB = SB[1:] if turn == "c": if SC == "": print("C") break turn = SC[0] SC = SC[1:]
# -*- coding: utf-8 -*- SA, SB, SC = [input().strip() for _ in range(3)] S_dic = {} S_dic["a"] = SA S_dic["b"] = SB S_dic["c"] = SC turn = "a" while True: if S_dic[turn] == "": print((turn.upper())) break next_turn = S_dic[turn][0] S_dic[turn] = S_dic[turn][1:] turn = next_turn
false
41.935484
[ "-ia, ib, ic = 0, 0, 0", "+S_dic = {}", "+S_dic[\"a\"] = SA", "+S_dic[\"b\"] = SB", "+S_dic[\"c\"] = SC", "- if turn == \"a\":", "- if SA == \"\":", "- print(\"A\")", "- break", "- turn = SA[0]", "- SA = SA[1:]", "- if turn == \"b\":", "- if SB == \"\":", "- print(\"B\")", "- break", "- turn = SB[0]", "- SB = SB[1:]", "- if turn == \"c\":", "- if SC == \"\":", "- print(\"C\")", "- break", "- turn = SC[0]", "- SC = SC[1:]", "+ if S_dic[turn] == \"\":", "+ print((turn.upper()))", "+ break", "+ next_turn = S_dic[turn][0]", "+ S_dic[turn] = S_dic[turn][1:]", "+ turn = next_turn" ]
false
0.052537
0.075139
0.699191
[ "s150391333", "s480588110" ]
u922449550
p02586
python
s990754217
s126823976
2,890
2,184
151,664
162,344
Accepted
Accepted
24.43
# pypy import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines R, C, K = list(map(int, readline().split())) rcv = list(map(int, read().split())) rc2v = {} for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]): rc2v[(rr-1, cc-1)] = vv dp = [[[0]*4 for c in range(C)] for r in range(2)] dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0 for c in range(1, C): for k in range(1, 4): v = rc2v[(0, c)] if (0, c) in rc2v else 0 dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v) for r in range(1, R): rr = r % 2 dp[rr][0][0] = max(dp[rr-1][0]) v = rc2v[(r, 0)] if (r, 0) in rc2v else 0 dp[rr][0][1] = dp[rr][0][0] + v for c in range(1, C): v = rc2v[(r, c)] if (r, c) in rc2v else 0 temp_max = max(dp[rr-1][c]) dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v) for k in range(2, 4): dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v) if R % 2: print((max(dp[0][-1]))) else: print((max(dp[-1][-1])))
# pypy import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines R, C, K = list(map(int, readline().split())) rcv = list(map(int, read().split())) rc2v = {} for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]): rc2v[(rr, cc)] = vv dp = [[0]*4 for c in range(C+1)] for r in range(1, R+1): for c in range(1, C+1): v = rc2v[(r, c)] if (r, c) in rc2v else 0 dp[c][0] = max(dp[c-1][0], max(dp[c])) dp[c][1] = max(dp[c-1][1], dp[c][0] + v) for k in range(2, 4): dp[c][k] = max(dp[c-1][k], dp[c-1][k-1] + v) print((max(dp[-1])))
36
22
1,038
603
# pypy import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines R, C, K = list(map(int, readline().split())) rcv = list(map(int, read().split())) rc2v = {} for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]): rc2v[(rr - 1, cc - 1)] = vv dp = [[[0] * 4 for c in range(C)] for r in range(2)] dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0 for c in range(1, C): for k in range(1, 4): v = rc2v[(0, c)] if (0, c) in rc2v else 0 dp[0][c][k] = max(dp[0][c - 1][k], dp[0][c - 1][k - 1] + v) for r in range(1, R): rr = r % 2 dp[rr][0][0] = max(dp[rr - 1][0]) v = rc2v[(r, 0)] if (r, 0) in rc2v else 0 dp[rr][0][1] = dp[rr][0][0] + v for c in range(1, C): v = rc2v[(r, c)] if (r, c) in rc2v else 0 temp_max = max(dp[rr - 1][c]) dp[rr][c][1] = max(dp[rr][c - 1][1], max(dp[rr][c - 1][0], temp_max) + v) for k in range(2, 4): dp[rr][c][k] = max(dp[rr][c - 1][k], dp[rr][c - 1][k - 1] + v) if R % 2: print((max(dp[0][-1]))) else: print((max(dp[-1][-1])))
# pypy import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines R, C, K = list(map(int, readline().split())) rcv = list(map(int, read().split())) rc2v = {} for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]): rc2v[(rr, cc)] = vv dp = [[0] * 4 for c in range(C + 1)] for r in range(1, R + 1): for c in range(1, C + 1): v = rc2v[(r, c)] if (r, c) in rc2v else 0 dp[c][0] = max(dp[c - 1][0], max(dp[c])) dp[c][1] = max(dp[c - 1][1], dp[c][0] + v) for k in range(2, 4): dp[c][k] = max(dp[c - 1][k], dp[c - 1][k - 1] + v) print((max(dp[-1])))
false
38.888889
[ "- rc2v[(rr - 1, cc - 1)] = vv", "-dp = [[[0] * 4 for c in range(C)] for r in range(2)]", "-dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0", "-for c in range(1, C):", "- for k in range(1, 4):", "- v = rc2v[(0, c)] if (0, c) in rc2v else 0", "- dp[0][c][k] = max(dp[0][c - 1][k], dp[0][c - 1][k - 1] + v)", "-for r in range(1, R):", "- rr = r % 2", "- dp[rr][0][0] = max(dp[rr - 1][0])", "- v = rc2v[(r, 0)] if (r, 0) in rc2v else 0", "- dp[rr][0][1] = dp[rr][0][0] + v", "- for c in range(1, C):", "+ rc2v[(rr, cc)] = vv", "+dp = [[0] * 4 for c in range(C + 1)]", "+for r in range(1, R + 1):", "+ for c in range(1, C + 1):", "- temp_max = max(dp[rr - 1][c])", "- dp[rr][c][1] = max(dp[rr][c - 1][1], max(dp[rr][c - 1][0], temp_max) + v)", "+ dp[c][0] = max(dp[c - 1][0], max(dp[c]))", "+ dp[c][1] = max(dp[c - 1][1], dp[c][0] + v)", "- dp[rr][c][k] = max(dp[rr][c - 1][k], dp[rr][c - 1][k - 1] + v)", "-if R % 2:", "- print((max(dp[0][-1])))", "-else:", "- print((max(dp[-1][-1])))", "+ dp[c][k] = max(dp[c - 1][k], dp[c - 1][k - 1] + v)", "+print((max(dp[-1])))" ]
false
0.11828
0.056166
2.10589
[ "s990754217", "s126823976" ]
u638456847
p02744
python
s010332417
s643926309
92
83
16,340
16,340
Accepted
Accepted
9.78
# 幅優先探索による全探索 from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(N): """ param N:文字列の長さ """ S = "abcdefghij" result = [] queue = deque(["a"]) while queue: s = queue.popleft() if len(s) == N: result.append(s + "\n") continue else: for i in S[:len(set(s))+1]: queue.append(s + i) return result def main(): N = int(readline()) ans = bfs(N) print(("".join(ans))) if __name__ == "__main__": main()
# 幅優先探索による全探索 from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(N): """ param N:文字列の長さ """ S = "abcdefghij" result = [] queue = deque(["a"]) while queue: s = queue.popleft() if len(s) == N: result.append(s) continue else: for i in S[:len(set(s))+1]: queue.append(s + i) return result def main(): N = int(readline()) ans = bfs(N) print(("\n".join(ans))) if __name__ == "__main__": main()
38
38
652
647
# 幅優先探索による全探索 from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(N): """ param N:文字列の長さ """ S = "abcdefghij" result = [] queue = deque(["a"]) while queue: s = queue.popleft() if len(s) == N: result.append(s + "\n") continue else: for i in S[: len(set(s)) + 1]: queue.append(s + i) return result def main(): N = int(readline()) ans = bfs(N) print(("".join(ans))) if __name__ == "__main__": main()
# 幅優先探索による全探索 from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(N): """ param N:文字列の長さ """ S = "abcdefghij" result = [] queue = deque(["a"]) while queue: s = queue.popleft() if len(s) == N: result.append(s) continue else: for i in S[: len(set(s)) + 1]: queue.append(s + i) return result def main(): N = int(readline()) ans = bfs(N) print(("\n".join(ans))) if __name__ == "__main__": main()
false
0
[ "- result.append(s + \"\\n\")", "+ result.append(s)", "- print((\"\".join(ans)))", "+ print((\"\\n\".join(ans)))" ]
false
0.037942
0.037534
1.010846
[ "s010332417", "s643926309" ]
u936985471
p02937
python
s966383059
s751558761
1,779
166
3,760
12,148
Accepted
Accepted
90.67
s=eval(input()) t=eval(input()) if len(set(t)-set(s))>0: print((-1)) exit(0) ss=s*2 ind=-1 turn=0 for c in t: nex=ss[ind+1:].find(c) ind=(ind+1)+nex if ind>=len(s): ind-=len(s) turn+=1 print((turn*len(s)+ind+1))
s=eval(input()) t=eval(input()) if len(set(t)-set(s))>0: print((-1)) else: s2=s*2 s2pos={} for i in range(len(s2)): if s2[i] in s2pos: s2pos[s2[i]].append(i) else: s2pos[s2[i]]=[i] cur=-1 import bisect rev=0 for c in t: cur+=1 pos=s2pos[c] p=bisect.bisect_left(pos,cur) cur=pos[p] if cur>=len(s): cur-=len(s) rev+=1 else: print((rev*len(s)+cur+1))
17
27
231
434
s = eval(input()) t = eval(input()) if len(set(t) - set(s)) > 0: print((-1)) exit(0) ss = s * 2 ind = -1 turn = 0 for c in t: nex = ss[ind + 1 :].find(c) ind = (ind + 1) + nex if ind >= len(s): ind -= len(s) turn += 1 print((turn * len(s) + ind + 1))
s = eval(input()) t = eval(input()) if len(set(t) - set(s)) > 0: print((-1)) else: s2 = s * 2 s2pos = {} for i in range(len(s2)): if s2[i] in s2pos: s2pos[s2[i]].append(i) else: s2pos[s2[i]] = [i] cur = -1 import bisect rev = 0 for c in t: cur += 1 pos = s2pos[c] p = bisect.bisect_left(pos, cur) cur = pos[p] if cur >= len(s): cur -= len(s) rev += 1 else: print((rev * len(s) + cur + 1))
false
37.037037
[ "- exit(0)", "-ss = s * 2", "-ind = -1", "-turn = 0", "-for c in t:", "- nex = ss[ind + 1 :].find(c)", "- ind = (ind + 1) + nex", "- if ind >= len(s):", "- ind -= len(s)", "- turn += 1", "-print((turn * len(s) + ind + 1))", "+else:", "+ s2 = s * 2", "+ s2pos = {}", "+ for i in range(len(s2)):", "+ if s2[i] in s2pos:", "+ s2pos[s2[i]].append(i)", "+ else:", "+ s2pos[s2[i]] = [i]", "+ cur = -1", "+ import bisect", "+", "+ rev = 0", "+ for c in t:", "+ cur += 1", "+ pos = s2pos[c]", "+ p = bisect.bisect_left(pos, cur)", "+ cur = pos[p]", "+ if cur >= len(s):", "+ cur -= len(s)", "+ rev += 1", "+ else:", "+ print((rev * len(s) + cur + 1))" ]
false
0.09254
0.037781
2.449371
[ "s966383059", "s751558761" ]
u562935282
p03062
python
s203635175
s642347604
248
96
70,688
14,412
Accepted
Accepted
61.29
def solve(): n = int(eval(input())) a = list(map(int, input().split())) dp = [[-1] * 2 for _ in range(n + 1)] dp[0][False] = 0 # dp[idx][マイナスをかける必要があるか]:=総和の最大値 for j, x in enumerate(a): if dp[j][True] == -1: dp[j + 1][False] = dp[j][False] + x dp[j + 1][True] = dp[j][False] - x else: dp[j + 1][False] = max(dp[j][False] + x, dp[j][True] - x) dp[j + 1][True] = max(dp[j][False] - x, dp[j][True] + x) return dp[n][False] if __name__ == '__main__': print((solve()))
def main(): inf = 10 ** 14 + 1 n = int(eval(input())) *a, = list(map(int, input().split())) stay = 0 # -1を乗算しない done = -inf # -1を乗算した for x in a: stay, done = max(stay + x, done - x), max(stay - x, done + x) print(stay) if __name__ == '__main__': main()
20
17
570
306
def solve(): n = int(eval(input())) a = list(map(int, input().split())) dp = [[-1] * 2 for _ in range(n + 1)] dp[0][False] = 0 # dp[idx][マイナスをかける必要があるか]:=総和の最大値 for j, x in enumerate(a): if dp[j][True] == -1: dp[j + 1][False] = dp[j][False] + x dp[j + 1][True] = dp[j][False] - x else: dp[j + 1][False] = max(dp[j][False] + x, dp[j][True] - x) dp[j + 1][True] = max(dp[j][False] - x, dp[j][True] + x) return dp[n][False] if __name__ == "__main__": print((solve()))
def main(): inf = 10**14 + 1 n = int(eval(input())) (*a,) = list(map(int, input().split())) stay = 0 # -1を乗算しない done = -inf # -1を乗算した for x in a: stay, done = max(stay + x, done - x), max(stay - x, done + x) print(stay) if __name__ == "__main__": main()
false
15
[ "-def solve():", "+def main():", "+ inf = 10**14 + 1", "- a = list(map(int, input().split()))", "- dp = [[-1] * 2 for _ in range(n + 1)]", "- dp[0][False] = 0", "- # dp[idx][マイナスをかける必要があるか]:=総和の最大値", "- for j, x in enumerate(a):", "- if dp[j][True] == -1:", "- dp[j + 1][False] = dp[j][False] + x", "- dp[j + 1][True] = dp[j][False] - x", "- else:", "- dp[j + 1][False] = max(dp[j][False] + x, dp[j][True] - x)", "- dp[j + 1][True] = max(dp[j][False] - x, dp[j][True] + x)", "- return dp[n][False]", "+ (*a,) = list(map(int, input().split()))", "+ stay = 0 # -1を乗算しない", "+ done = -inf # -1を乗算した", "+ for x in a:", "+ stay, done = max(stay + x, done - x), max(stay - x, done + x)", "+ print(stay)", "- print((solve()))", "+ main()" ]
false
0.04197
0.041922
1.001137
[ "s203635175", "s642347604" ]
u232852711
p03863
python
s299170455
s373530904
755
17
3,316
3,316
Accepted
Accepted
97.75
s = eval(input()) ans = 'Second' idx = 1 while(True): if s[idx-1] == s[idx+1] or idx == 0: idx += 1 else: s = s[:idx]+s[idx+1:] idx -= 1 if ans == 'First': ans = 'Second' else: ans = 'First' # print(s, idx) if idx == len(s)-1: break print(ans)
s = eval(input()) ans = {0:'Second', 1:'First'} if s[0] == s[-1]: print((ans[(len(s)-1)%2])) else: print((ans[len(s)%2]))
19
7
332
127
s = eval(input()) ans = "Second" idx = 1 while True: if s[idx - 1] == s[idx + 1] or idx == 0: idx += 1 else: s = s[:idx] + s[idx + 1 :] idx -= 1 if ans == "First": ans = "Second" else: ans = "First" # print(s, idx) if idx == len(s) - 1: break print(ans)
s = eval(input()) ans = {0: "Second", 1: "First"} if s[0] == s[-1]: print((ans[(len(s) - 1) % 2])) else: print((ans[len(s) % 2]))
false
63.157895
[ "-ans = \"Second\"", "-idx = 1", "-while True:", "- if s[idx - 1] == s[idx + 1] or idx == 0:", "- idx += 1", "- else:", "- s = s[:idx] + s[idx + 1 :]", "- idx -= 1", "- if ans == \"First\":", "- ans = \"Second\"", "- else:", "- ans = \"First\"", "- # print(s, idx)", "- if idx == len(s) - 1:", "- break", "-print(ans)", "+ans = {0: \"Second\", 1: \"First\"}", "+if s[0] == s[-1]:", "+ print((ans[(len(s) - 1) % 2]))", "+else:", "+ print((ans[len(s) % 2]))" ]
false
0.047207
0.038515
1.225678
[ "s299170455", "s373530904" ]
u724963150
p00710
python
s136164157
s144201910
80
60
7,620
7,616
Accepted
Accepted
25
while True: a=[int(num)for num in input().split(' ')] n=a[0] if n==0:break hanafuda=[i+1 for i in range(n)] for i in range(a[1]): b=[int(num)for num in input().split(' ')] for j in range(b[1]):hanafuda.append(hanafuda.pop(n-(b[0]+b[1])+1)) print((hanafuda.pop()))
while True: n,r=[int(s)for s in input().split(" ")] if n==r==0:break ops=[[int(s)for s in input().split(" ")]for i in range(r)] cd=[n-i for i in range(n)] for op in ops: p,c=op l=cd[p-1:p+c-1] del cd[p-1:p+c-1] cd=l+cd print((cd[0]))
9
11
309
297
while True: a = [int(num) for num in input().split(" ")] n = a[0] if n == 0: break hanafuda = [i + 1 for i in range(n)] for i in range(a[1]): b = [int(num) for num in input().split(" ")] for j in range(b[1]): hanafuda.append(hanafuda.pop(n - (b[0] + b[1]) + 1)) print((hanafuda.pop()))
while True: n, r = [int(s) for s in input().split(" ")] if n == r == 0: break ops = [[int(s) for s in input().split(" ")] for i in range(r)] cd = [n - i for i in range(n)] for op in ops: p, c = op l = cd[p - 1 : p + c - 1] del cd[p - 1 : p + c - 1] cd = l + cd print((cd[0]))
false
18.181818
[ "- a = [int(num) for num in input().split(\" \")]", "- n = a[0]", "- if n == 0:", "+ n, r = [int(s) for s in input().split(\" \")]", "+ if n == r == 0:", "- hanafuda = [i + 1 for i in range(n)]", "- for i in range(a[1]):", "- b = [int(num) for num in input().split(\" \")]", "- for j in range(b[1]):", "- hanafuda.append(hanafuda.pop(n - (b[0] + b[1]) + 1))", "- print((hanafuda.pop()))", "+ ops = [[int(s) for s in input().split(\" \")] for i in range(r)]", "+ cd = [n - i for i in range(n)]", "+ for op in ops:", "+ p, c = op", "+ l = cd[p - 1 : p + c - 1]", "+ del cd[p - 1 : p + c - 1]", "+ cd = l + cd", "+ print((cd[0]))" ]
false
0.036215
0.036313
0.997282
[ "s136164157", "s144201910" ]
u670180528
p02949
python
s391427909
s363734486
1,702
1,537
57,176
54,616
Accepted
Accepted
9.69
n,m,p = list(map(int,input().split())) graph = [[] for _ in range(n)] INF = float("inf") dist = [INF]*n dist[0] = 0 for _ in range(m): f,t,c = list(map(int,input().split())) graph[f-1].append((t-1,p-c)) #print(graph) for _ in range(n): update = False for f,e in enumerate(graph): for t,c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = dist[f] + c update = True if not update: break else: prev = dist[-1] for _ in range(n): update = False for f,e in enumerate(graph): for t,c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = dist[f] + c update = True if not update: break if dist[-1] != prev: print((-1)) exit() #print(dist) print((max(0,dist[-1]*(-1))))
n,m,p = list(map(int,input().split())) graph = [[] for _ in range(n)] INF = float("inf") dist = [INF]*n dist[0] = 0 for _ in range(m): f,t,c = list(map(int,input().split())) graph[f-1].append((t-1,p-c)) #print(graph) for _ in range(n): update = False for f,e in enumerate(graph): for t,c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = dist[f] + c update = True if not update: break else: prev = dist[-1] for _ in range(n): for f,e in enumerate(graph): for t,c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = -INF if dist[-1] != prev: print((-1)) exit() #print(dist) print((max(0,dist[-1]*(-1))))
37
33
755
682
n, m, p = list(map(int, input().split())) graph = [[] for _ in range(n)] INF = float("inf") dist = [INF] * n dist[0] = 0 for _ in range(m): f, t, c = list(map(int, input().split())) graph[f - 1].append((t - 1, p - c)) # print(graph) for _ in range(n): update = False for f, e in enumerate(graph): for t, c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = dist[f] + c update = True if not update: break else: prev = dist[-1] for _ in range(n): update = False for f, e in enumerate(graph): for t, c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = dist[f] + c update = True if not update: break if dist[-1] != prev: print((-1)) exit() # print(dist) print((max(0, dist[-1] * (-1))))
n, m, p = list(map(int, input().split())) graph = [[] for _ in range(n)] INF = float("inf") dist = [INF] * n dist[0] = 0 for _ in range(m): f, t, c = list(map(int, input().split())) graph[f - 1].append((t - 1, p - c)) # print(graph) for _ in range(n): update = False for f, e in enumerate(graph): for t, c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = dist[f] + c update = True if not update: break else: prev = dist[-1] for _ in range(n): for f, e in enumerate(graph): for t, c in e: if dist[f] != INF and dist[t] > dist[f] + c: dist[t] = -INF if dist[-1] != prev: print((-1)) exit() # print(dist) print((max(0, dist[-1] * (-1))))
false
10.810811
[ "- update = False", "- dist[t] = dist[f] + c", "- update = True", "- if not update:", "- break", "+ dist[t] = -INF" ]
false
0.045746
0.040586
1.127124
[ "s391427909", "s363734486" ]
u807028974
p02678
python
s415414760
s655901906
1,048
868
42,400
34,552
Accepted
Accepted
17.18
# import sys # import math #sqrt,gcd,pi # import decimal import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce # mod = int(1e9+7) mod = 998244353 INF = 1<<29 lINF = 1<<35 def readInt(): return list(map(int,input().split())) def main(): n,m = readInt() g = [[] for i in range(n)] for i in range(m): x,y = readInt() g[x-1].append(y-1) g[y-1].append(x-1) v = [[-1,-1] for i in range(n)] v[0] = [0,0] q = queue.Queue() q.put(0) while not q.empty(): x = q.get() for y in g[x]: if v[y][0]!=(-1): continue q.put(y) v[y][0] = v[x][0] + 1 v[y][1] = x print("Yes") for i in range(1,n): print((v[i][1]+1)) return if __name__=='__main__': main()
# import sys # import math #sqrt,gcd,pi # import decimal import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce # mod = int(1e9+7) mod = 998244353 INF = 1<<29 lINF = 1<<35 def readInt(): return list(map(int,input().split())) def main(): n,m = readInt() # インデックスを部屋番号として、各部屋から繋がっている部屋の番号をリストに持つ graph = [[] for i in range(n)] for i in range(m): x,y = readInt() graph[x-1].append(y-1) graph[y-1].append(x-1) # 各部屋に設定する番号を記録する v = [-1 for i in range(n)] # 部屋1は -1 以外にしておく v[0] = [0] # queueを作成し部屋1(インデックスは0)を入れる q = queue.Queue() q.put(0) while not q.empty(): # queueの先頭(今いる部屋の番号)を取り出す x = q.get() # 今いる部屋と繋がっている部屋を順に探索する for y in graph[x]: # -1ではない場合は既に探索済みなのでスキップする if v[y]!=(-1): continue # あとで探索する為にqueueに入れておく q.put(y) v[y] = x print("Yes") for i in range(1,n): print((v[i]+1)) return if __name__=='__main__': main()
49
56
1,132
1,362
# import sys # import math #sqrt,gcd,pi # import decimal import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce # mod = int(1e9+7) mod = 998244353 INF = 1 << 29 lINF = 1 << 35 def readInt(): return list(map(int, input().split())) def main(): n, m = readInt() g = [[] for i in range(n)] for i in range(m): x, y = readInt() g[x - 1].append(y - 1) g[y - 1].append(x - 1) v = [[-1, -1] for i in range(n)] v[0] = [0, 0] q = queue.Queue() q.put(0) while not q.empty(): x = q.get() for y in g[x]: if v[y][0] != (-1): continue q.put(y) v[y][0] = v[x][0] + 1 v[y][1] = x print("Yes") for i in range(1, n): print((v[i][1] + 1)) return if __name__ == "__main__": main()
# import sys # import math #sqrt,gcd,pi # import decimal import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce # mod = int(1e9+7) mod = 998244353 INF = 1 << 29 lINF = 1 << 35 def readInt(): return list(map(int, input().split())) def main(): n, m = readInt() # インデックスを部屋番号として、各部屋から繋がっている部屋の番号をリストに持つ graph = [[] for i in range(n)] for i in range(m): x, y = readInt() graph[x - 1].append(y - 1) graph[y - 1].append(x - 1) # 各部屋に設定する番号を記録する v = [-1 for i in range(n)] # 部屋1は -1 以外にしておく v[0] = [0] # queueを作成し部屋1(インデックスは0)を入れる q = queue.Queue() q.put(0) while not q.empty(): # queueの先頭(今いる部屋の番号)を取り出す x = q.get() # 今いる部屋と繋がっている部屋を順に探索する for y in graph[x]: # -1ではない場合は既に探索済みなのでスキップする if v[y] != (-1): continue # あとで探索する為にqueueに入れておく q.put(y) v[y] = x print("Yes") for i in range(1, n): print((v[i] + 1)) return if __name__ == "__main__": main()
false
12.5
[ "- g = [[] for i in range(n)]", "+ # インデックスを部屋番号として、各部屋から繋がっている部屋の番号をリストに持つ", "+ graph = [[] for i in range(n)]", "- g[x - 1].append(y - 1)", "- g[y - 1].append(x - 1)", "- v = [[-1, -1] for i in range(n)]", "- v[0] = [0, 0]", "+ graph[x - 1].append(y - 1)", "+ graph[y - 1].append(x - 1)", "+ # 各部屋に設定する番号を記録する", "+ v = [-1 for i in range(n)]", "+ # 部屋1は -1 以外にしておく", "+ v[0] = [0]", "+ # queueを作成し部屋1(インデックスは0)を入れる", "+ # queueの先頭(今いる部屋の番号)を取り出す", "- for y in g[x]:", "- if v[y][0] != (-1):", "+ # 今いる部屋と繋がっている部屋を順に探索する", "+ for y in graph[x]:", "+ # -1ではない場合は既に探索済みなのでスキップする", "+ if v[y] != (-1):", "+ # あとで探索する為にqueueに入れておく", "- v[y][0] = v[x][0] + 1", "- v[y][1] = x", "+ v[y] = x", "- print((v[i][1] + 1))", "+ print((v[i] + 1))" ]
false
0.039736
0.038069
1.043794
[ "s415414760", "s655901906" ]
u499381410
p03045
python
s056534190
s665068921
693
627
78,296
68,056
Accepted
Accepted
9.52
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 n, m = LI() U = UnionFind(n) for i in range(m): x, y, z = LI() U.union(x - 1, y - 1) print((len(set([U.root(j) for j in range(n)]))))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float('inf') def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size -= 1 n, m = LI() U = UnionFind(n) for i in range(m): x, y, z = LI() U.union(x - 1, y - 1) print((U.size))
71
75
1,743
1,761
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float("inf") def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9 + 7 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 n, m = LI() U = UnionFind(n) for i in range(m): x, y, z = LI() U.union(x - 1, y - 1) print((len(set([U.root(j) for j in range(n)]))))
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float("inf") def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9 + 7 class UnionFind: def __init__(self, n): # 負 : 根であることを示す。絶対値はランクを示す # 非負: 根でないことを示す。値は親を示す self.table = [-1] * n self.size = n def root(self, x): if self.table[x] < 0: return x else: self.table[x] = self.root(self.table[x]) return self.table[x] def is_same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): r1 = self.root(x) r2 = self.root(y) if r1 == r2: return # ランクの取得 d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 if d1 == d2: self.table[r1] -= 1 else: self.table[r1] = r2 self.size -= 1 n, m = LI() U = UnionFind(n) for i in range(m): x, y, z = LI() U.union(x - 1, y - 1) print((U.size))
false
5.333333
[ "+ self.size = n", "+ self.size -= 1", "-print((len(set([U.root(j) for j in range(n)]))))", "+print((U.size))" ]
false
0.054567
0.049935
1.092762
[ "s056534190", "s665068921" ]
u633450100
p03713
python
s178517990
s060702200
320
261
9,100
24,592
Accepted
Accepted
18.44
def answer(H,W,ans): for x in range(1,W): y1 = H // 2 Sa1 = H * x Sb1 = (W - x) * y1 Sc1 = (W - x) * (H - y1) M = max(Sa1,Sb1,Sc1) m = min(Sa1,Sb1,Sc1) y2 = (W - x) // 2 Sa2 = H * x Sb2 = H * y2 Sc2 = H * (W - x - y2) M2 = max(Sa2,Sb2,Sc2) m2 = min(Sa2,Sb2,Sc2) if ans > min(M-m,M2-m2): ans = min(M-m,M2-m2) return ans if __name__ == '__main__': H,W = [int(i) for i in input().split()] ans = H * W ans = answer(H,W,ans) H,W = W,H if answer(H,W,ans) < ans: ans = answer(H,W,ans) print(ans)
def answer(H,W,ans): global ans_list for x in range(1,W): y1 = H // 2 S1 = [H * x,(W - x) * y1,(W - x) * (H - y1)] ans_list.append(max(S1)-min(S1)) y2 = (W - x) // 2 S2 = [H * x,H * y2,H * (W - x - y2)] ans_list.append(max(S2)-min(S2)) if __name__ == '__main__': H,W = [int(i) for i in input().split()] ans_list = [] answer(H,W,ans_list) answer(W,H,ans_list) print((min(ans_list)))
33
18
685
476
def answer(H, W, ans): for x in range(1, W): y1 = H // 2 Sa1 = H * x Sb1 = (W - x) * y1 Sc1 = (W - x) * (H - y1) M = max(Sa1, Sb1, Sc1) m = min(Sa1, Sb1, Sc1) y2 = (W - x) // 2 Sa2 = H * x Sb2 = H * y2 Sc2 = H * (W - x - y2) M2 = max(Sa2, Sb2, Sc2) m2 = min(Sa2, Sb2, Sc2) if ans > min(M - m, M2 - m2): ans = min(M - m, M2 - m2) return ans if __name__ == "__main__": H, W = [int(i) for i in input().split()] ans = H * W ans = answer(H, W, ans) H, W = W, H if answer(H, W, ans) < ans: ans = answer(H, W, ans) print(ans)
def answer(H, W, ans): global ans_list for x in range(1, W): y1 = H // 2 S1 = [H * x, (W - x) * y1, (W - x) * (H - y1)] ans_list.append(max(S1) - min(S1)) y2 = (W - x) // 2 S2 = [H * x, H * y2, H * (W - x - y2)] ans_list.append(max(S2) - min(S2)) if __name__ == "__main__": H, W = [int(i) for i in input().split()] ans_list = [] answer(H, W, ans_list) answer(W, H, ans_list) print((min(ans_list)))
false
45.454545
[ "+ global ans_list", "- Sa1 = H * x", "- Sb1 = (W - x) * y1", "- Sc1 = (W - x) * (H - y1)", "- M = max(Sa1, Sb1, Sc1)", "- m = min(Sa1, Sb1, Sc1)", "+ S1 = [H * x, (W - x) * y1, (W - x) * (H - y1)]", "+ ans_list.append(max(S1) - min(S1))", "- Sa2 = H * x", "- Sb2 = H * y2", "- Sc2 = H * (W - x - y2)", "- M2 = max(Sa2, Sb2, Sc2)", "- m2 = min(Sa2, Sb2, Sc2)", "- if ans > min(M - m, M2 - m2):", "- ans = min(M - m, M2 - m2)", "- return ans", "+ S2 = [H * x, H * y2, H * (W - x - y2)]", "+ ans_list.append(max(S2) - min(S2))", "- ans = H * W", "- ans = answer(H, W, ans)", "- H, W = W, H", "- if answer(H, W, ans) < ans:", "- ans = answer(H, W, ans)", "- print(ans)", "+ ans_list = []", "+ answer(H, W, ans_list)", "+ answer(W, H, ans_list)", "+ print((min(ans_list)))" ]
false
0.565147
0.766699
0.737118
[ "s178517990", "s060702200" ]
u150984829
p02269
python
s193000573
s155159965
900
800
31,616
33,668
Accepted
Accepted
11.11
import sys def m(): d={0};eval(input()) for e in sys.stdin: if'f'==e[0]:print((['no','yes'][e[5:]in d])) else:d|={e[7:]} if'__main__'==__name__:m()
import sys def m(): d={};eval(input()) for e in sys.stdin: if'f'==e[0]:print((['no','yes'][e[5:]in d])) else:d[e[7:]]=0 if'__main__'==__name__:m()
7
7
152
151
import sys def m(): d = {0} eval(input()) for e in sys.stdin: if "f" == e[0]: print((["no", "yes"][e[5:] in d])) else: d |= {e[7:]} if "__main__" == __name__: m()
import sys def m(): d = {} eval(input()) for e in sys.stdin: if "f" == e[0]: print((["no", "yes"][e[5:] in d])) else: d[e[7:]] = 0 if "__main__" == __name__: m()
false
0
[ "- d = {0}", "+ d = {}", "- d |= {e[7:]}", "+ d[e[7:]] = 0" ]
false
0.04796
0.047567
1.008268
[ "s193000573", "s155159965" ]
u250583425
p02843
python
s681975811
s394067758
19
17
2,940
2,940
Accepted
Accepted
10.53
x = int(eval(input())) v = x // 100 modv = x % 100 if v > 0 and (modv == 0 or modv / v <= 5): print((1)) else: print((0))
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c x = int(eval(input())) v = x // 100 modv = x % 100 if v > 0 and modv / v <= 5: print((1)) else: print((0))
7
9
125
177
x = int(eval(input())) v = x // 100 modv = x % 100 if v > 0 and (modv == 0 or modv / v <= 5): print((1)) else: print((0))
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c x = int(eval(input())) v = x // 100 modv = x % 100 if v > 0 and modv / v <= 5: print((1)) else: print((0))
false
22.222222
[ "+# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c", "-if v > 0 and (modv == 0 or modv / v <= 5):", "+if v > 0 and modv / v <= 5:" ]
false
0.078839
0.07524
1.047837
[ "s681975811", "s394067758" ]
u057993957
p02953
python
s764021166
s284560337
91
74
14,252
14,252
Accepted
Accepted
18.68
def hoge(x, y): return y if x >= y else y - 1 N = int(eval(input())) H = list(map(int, input().split())) H = list(reversed(H)) flag = 0 for i in range(N - 1): H[i + 1] = hoge(H[i], H[i + 1]) if H[i] < H[i + 1]: flag = 1 print("No") break if flag == 0: print("Yes")
n = int(eval(input())) S = list(map(int, input().split()))[::-1] flag = True for i in range(1, n): if S[i] > S[i-1]: S[i] -= 1 if S[i] > S[i-1]: flag = False break print(("Yes" if flag else "No"))
21
14
333
227
def hoge(x, y): return y if x >= y else y - 1 N = int(eval(input())) H = list(map(int, input().split())) H = list(reversed(H)) flag = 0 for i in range(N - 1): H[i + 1] = hoge(H[i], H[i + 1]) if H[i] < H[i + 1]: flag = 1 print("No") break if flag == 0: print("Yes")
n = int(eval(input())) S = list(map(int, input().split()))[::-1] flag = True for i in range(1, n): if S[i] > S[i - 1]: S[i] -= 1 if S[i] > S[i - 1]: flag = False break print(("Yes" if flag else "No"))
false
33.333333
[ "-def hoge(x, y):", "- return y if x >= y else y - 1", "-", "-", "-N = int(eval(input()))", "-H = list(map(int, input().split()))", "-H = list(reversed(H))", "-flag = 0", "-for i in range(N - 1):", "- H[i + 1] = hoge(H[i], H[i + 1])", "- if H[i] < H[i + 1]:", "- flag = 1", "- print(\"No\")", "+n = int(eval(input()))", "+S = list(map(int, input().split()))[::-1]", "+flag = True", "+for i in range(1, n):", "+ if S[i] > S[i - 1]:", "+ S[i] -= 1", "+ if S[i] > S[i - 1]:", "+ flag = False", "-if flag == 0:", "- print(\"Yes\")", "+print((\"Yes\" if flag else \"No\"))" ]
false
0.032402
0.035154
0.921713
[ "s764021166", "s284560337" ]
u078349616
p02886
python
s335930079
s778997345
23
17
3,316
2,940
Accepted
Accepted
26.09
N = int(eval(input())) d = input().split() sum = 0 for i in range(len(d)): for j in range(i+1, len(d)): sum = sum + int(d[i])*int(d[j]) print(sum)
N = int(eval(input())) d = list(map(int, input().split())) sum = 0 for i in range(N): for j in range(i+1, N): sum += d[i]*d[j] print(sum)
9
9
160
151
N = int(eval(input())) d = input().split() sum = 0 for i in range(len(d)): for j in range(i + 1, len(d)): sum = sum + int(d[i]) * int(d[j]) print(sum)
N = int(eval(input())) d = list(map(int, input().split())) sum = 0 for i in range(N): for j in range(i + 1, N): sum += d[i] * d[j] print(sum)
false
0
[ "-d = input().split()", "+d = list(map(int, input().split()))", "-for i in range(len(d)):", "- for j in range(i + 1, len(d)):", "- sum = sum + int(d[i]) * int(d[j])", "+for i in range(N):", "+ for j in range(i + 1, N):", "+ sum += d[i] * d[j]" ]
false
0.185478
0.038242
4.850079
[ "s335930079", "s778997345" ]
u531220228
p02958
python
s374484354
s875363829
150
17
12,500
3,060
Accepted
Accepted
88.67
import numpy as np N = int(eval(input())) p_raw = np.array(list(map(int, input().split()))) p_sort = np.sort(p_raw) compare = (p_raw==p_sort) if np.count_nonzero(compare == False) > 2: print('NO') else: print('YES')
N = int(eval(input())) p = list(map(int, input().split())) p_sorted = sorted(p) is_changed = [0 if x==y else 1 for x,y in zip(p, p_sorted)] if sum(is_changed) <= 2: print("YES") else: print("NO")
12
11
227
210
import numpy as np N = int(eval(input())) p_raw = np.array(list(map(int, input().split()))) p_sort = np.sort(p_raw) compare = p_raw == p_sort if np.count_nonzero(compare == False) > 2: print("NO") else: print("YES")
N = int(eval(input())) p = list(map(int, input().split())) p_sorted = sorted(p) is_changed = [0 if x == y else 1 for x, y in zip(p, p_sorted)] if sum(is_changed) <= 2: print("YES") else: print("NO")
false
8.333333
[ "-import numpy as np", "-", "-p_raw = np.array(list(map(int, input().split())))", "-p_sort = np.sort(p_raw)", "-compare = p_raw == p_sort", "-if np.count_nonzero(compare == False) > 2:", "+p = list(map(int, input().split()))", "+p_sorted = sorted(p)", "+is_changed = [0 if x == y else 1 for x, y in zip(p, p_sorted)]", "+if sum(is_changed) <= 2:", "+ print(\"YES\")", "+else:", "-else:", "- print(\"YES\")" ]
false
0.680519
0.043723
15.564179
[ "s374484354", "s875363829" ]
u537782349
p03001
python
s482264093
s960450800
20
17
2,940
2,940
Accepted
Accepted
15
a, b, c, d = list(map(int, input().split())) if a == c * 2 and b == d * 2: print((str(a * b / 2) + " 1")) else: print((str(a * b / 2) + " 0"))
a, b, c, d = list(map(int, input().split())) if c * 2 == a and d * 2 == b: print((a * b / 2, 1)) else: print((a * b / 2, 0))
5
5
145
127
a, b, c, d = list(map(int, input().split())) if a == c * 2 and b == d * 2: print((str(a * b / 2) + " 1")) else: print((str(a * b / 2) + " 0"))
a, b, c, d = list(map(int, input().split())) if c * 2 == a and d * 2 == b: print((a * b / 2, 1)) else: print((a * b / 2, 0))
false
0
[ "-if a == c * 2 and b == d * 2:", "- print((str(a * b / 2) + \" 1\"))", "+if c * 2 == a and d * 2 == b:", "+ print((a * b / 2, 1))", "- print((str(a * b / 2) + \" 0\"))", "+ print((a * b / 2, 0))" ]
false
0.049782
0.050537
0.985066
[ "s482264093", "s960450800" ]
u764956288
p02856
python
s532803312
s884705044
291
255
12,520
3,060
Accepted
Accepted
12.37
import sys def answer(): input = sys.stdin.readline M = int(eval(input())) Ds = [0] * M Cs = [0] * M total = 0 for i in range(M): c, d = list(map(int, input().split())) Cs[i] = c Ds[i] = d total += d * c digits = sum(Ds) ans = (digits-1) + (total-1) // 9 print(ans) if __name__ == '__main__': answer()
import sys def answer(): input = sys.stdin.readline M = int(eval(input())) digits = 0 total = 0 for i in range(M): c, d = list(map(int, input().split())) digits += d total += d * c ans = (digits-1) + (total-1) // 9 print(ans) if __name__ == '__main__': answer()
25
21
394
333
import sys def answer(): input = sys.stdin.readline M = int(eval(input())) Ds = [0] * M Cs = [0] * M total = 0 for i in range(M): c, d = list(map(int, input().split())) Cs[i] = c Ds[i] = d total += d * c digits = sum(Ds) ans = (digits - 1) + (total - 1) // 9 print(ans) if __name__ == "__main__": answer()
import sys def answer(): input = sys.stdin.readline M = int(eval(input())) digits = 0 total = 0 for i in range(M): c, d = list(map(int, input().split())) digits += d total += d * c ans = (digits - 1) + (total - 1) // 9 print(ans) if __name__ == "__main__": answer()
false
16
[ "- Ds = [0] * M", "- Cs = [0] * M", "+ digits = 0", "- Cs[i] = c", "- Ds[i] = d", "+ digits += d", "- digits = sum(Ds)" ]
false
0.158425
0.165476
0.957387
[ "s532803312", "s884705044" ]
u665415433
p03805
python
s984250955
s313499935
388
29
3,444
3,064
Accepted
Accepted
92.53
from copy import deepcopy def solve(road, num, ans, n): pattern = 0 test = deepcopy(road) for s in test: if num in s: s.remove(num) if len(ans) is n: return 1 if len(test[num - 1]) == int(0): return 0 else: for i in range(len(test[num - 1])): tmp = test[num - 1][i] if tmp is not 0: word = ans + str(tmp) pattern += solve(test, tmp, word, n) return pattern N, M = [int(i) for i in input().split()] town = [] for i in range(N): town.append(deepcopy([])) for i in range(M): a, b = [int(i) for i in input().split()] if a is not 1 or b is not 1: town[a - 1].append(b) town[b - 1].append(a) print((solve(town, 1, '1', N)))
N, M = [int(i) for i in input().split()] road = [list() for i in range(N + 1)] for i in range(M): a, b = [int(i) for i in input().split()] road[a].append(b) road[b].append(a) def solve(before, visited, now): visited.append(now) if len(visited) is N: return 1 pattern = 0 for way in road[now]: if way is now: continue if way in visited: continue pattern += solve(now, visited[:], way) return pattern print((solve(0, [], 1)))
33
23
805
536
from copy import deepcopy def solve(road, num, ans, n): pattern = 0 test = deepcopy(road) for s in test: if num in s: s.remove(num) if len(ans) is n: return 1 if len(test[num - 1]) == int(0): return 0 else: for i in range(len(test[num - 1])): tmp = test[num - 1][i] if tmp is not 0: word = ans + str(tmp) pattern += solve(test, tmp, word, n) return pattern N, M = [int(i) for i in input().split()] town = [] for i in range(N): town.append(deepcopy([])) for i in range(M): a, b = [int(i) for i in input().split()] if a is not 1 or b is not 1: town[a - 1].append(b) town[b - 1].append(a) print((solve(town, 1, "1", N)))
N, M = [int(i) for i in input().split()] road = [list() for i in range(N + 1)] for i in range(M): a, b = [int(i) for i in input().split()] road[a].append(b) road[b].append(a) def solve(before, visited, now): visited.append(now) if len(visited) is N: return 1 pattern = 0 for way in road[now]: if way is now: continue if way in visited: continue pattern += solve(now, visited[:], way) return pattern print((solve(0, [], 1)))
false
30.30303
[ "-from copy import deepcopy", "+N, M = [int(i) for i in input().split()]", "+road = [list() for i in range(N + 1)]", "+for i in range(M):", "+ a, b = [int(i) for i in input().split()]", "+ road[a].append(b)", "+ road[b].append(a)", "-def solve(road, num, ans, n):", "+def solve(before, visited, now):", "+ visited.append(now)", "+ if len(visited) is N:", "+ return 1", "- test = deepcopy(road)", "- for s in test:", "- if num in s:", "- s.remove(num)", "- if len(ans) is n:", "- return 1", "- if len(test[num - 1]) == int(0):", "- return 0", "- else:", "- for i in range(len(test[num - 1])):", "- tmp = test[num - 1][i]", "- if tmp is not 0:", "- word = ans + str(tmp)", "- pattern += solve(test, tmp, word, n)", "+ for way in road[now]:", "+ if way is now:", "+ continue", "+ if way in visited:", "+ continue", "+ pattern += solve(now, visited[:], way)", "-N, M = [int(i) for i in input().split()]", "-town = []", "-for i in range(N):", "- town.append(deepcopy([]))", "-for i in range(M):", "- a, b = [int(i) for i in input().split()]", "- if a is not 1 or b is not 1:", "- town[a - 1].append(b)", "- town[b - 1].append(a)", "-print((solve(town, 1, \"1\", N)))", "+print((solve(0, [], 1)))" ]
false
0.051742
0.036078
1.434202
[ "s984250955", "s313499935" ]
u261103969
p02700
python
s823811773
s538389335
64
21
61,696
9,096
Accepted
Accepted
67.19
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): a, b, c, d = list(map(int, readline().split())) while True: c -= b if c <= 0: print("Yes") break a -= d if a <= 0: print("No") break if __name__ == '__main__': main()
tkhp, tkat, aohp, aoat = list(map(int, input().split())) while True: aohp -= tkat if aohp <= 0: print("Yes") break tkhp -= aoat if tkhp <= 0: print("No") break
25
12
411
220
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): a, b, c, d = list(map(int, readline().split())) while True: c -= b if c <= 0: print("Yes") break a -= d if a <= 0: print("No") break if __name__ == "__main__": main()
tkhp, tkat, aohp, aoat = list(map(int, input().split())) while True: aohp -= tkat if aohp <= 0: print("Yes") break tkhp -= aoat if tkhp <= 0: print("No") break
false
52
[ "-import sys", "-", "-readline = sys.stdin.readline", "-MOD = 10**9 + 7", "-INF = float(\"INF\")", "-sys.setrecursionlimit(10**5)", "-", "-", "-def main():", "- a, b, c, d = list(map(int, readline().split()))", "- while True:", "- c -= b", "- if c <= 0:", "- print(\"Yes\")", "- break", "- a -= d", "- if a <= 0:", "- print(\"No\")", "- break", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+tkhp, tkat, aohp, aoat = list(map(int, input().split()))", "+while True:", "+ aohp -= tkat", "+ if aohp <= 0:", "+ print(\"Yes\")", "+ break", "+ tkhp -= aoat", "+ if tkhp <= 0:", "+ print(\"No\")", "+ break" ]
false
0.135194
0.03736
3.618704
[ "s823811773", "s538389335" ]
u034128150
p02708
python
s659382474
s458468422
128
77
9,124
9,172
Accepted
Accepted
39.84
N, K = list(map(int, input().split())) counter = 0 for i in range(K, N+2): smallest = (i-1) * i // 2 largest = ((2 * N + 1) - i) * i // 2 counter += (largest - smallest + 1) counter %= (10 ** 9 + 7) print(counter)
N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 counter = 0 for k in range(K, N+2): counter += (N-k+1) * k + 1 counter %= MOD print(counter)
10
10
234
157
N, K = list(map(int, input().split())) counter = 0 for i in range(K, N + 2): smallest = (i - 1) * i // 2 largest = ((2 * N + 1) - i) * i // 2 counter += largest - smallest + 1 counter %= 10**9 + 7 print(counter)
N, K = list(map(int, input().split())) MOD = 10**9 + 7 counter = 0 for k in range(K, N + 2): counter += (N - k + 1) * k + 1 counter %= MOD print(counter)
false
0
[ "+MOD = 10**9 + 7", "-for i in range(K, N + 2):", "- smallest = (i - 1) * i // 2", "- largest = ((2 * N + 1) - i) * i // 2", "- counter += largest - smallest + 1", "- counter %= 10**9 + 7", "+for k in range(K, N + 2):", "+ counter += (N - k + 1) * k + 1", "+ counter %= MOD" ]
false
0.05453
0.059877
0.910697
[ "s659382474", "s458468422" ]
u556594202
p02583
python
s177412800
s735436575
127
78
9,204
73,484
Accepted
Accepted
38.58
S = int(eval(input())) L = sorted(list(map(int,input().split()))) count=0 for i in range(len(L)): for j in range(i+1,len(L)): for k in range(j+1,len(L)): if (L[i]!=L[j] and L[j]!=L[k]): if ((L[i]+L[j]>L[k]) and (L[j]+L[k]>L[i]) and ((L[k]+L[i]>L[j]))): count+=1 print(count)
n=int(eval(input())) l=list(map(int,input().split())) l.sort() cnt=0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if (l[i]==l[j] or l[j]==l[k] or l[k]==l[i]): continue if l[k]-l[j]-l[i]<0: cnt+=1 print(cnt)
11
14
340
304
S = int(eval(input())) L = sorted(list(map(int, input().split()))) count = 0 for i in range(len(L)): for j in range(i + 1, len(L)): for k in range(j + 1, len(L)): if L[i] != L[j] and L[j] != L[k]: if ( (L[i] + L[j] > L[k]) and (L[j] + L[k] > L[i]) and ((L[k] + L[i] > L[j])) ): count += 1 print(count)
n = int(eval(input())) l = list(map(int, input().split())) l.sort() cnt = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]: continue if l[k] - l[j] - l[i] < 0: cnt += 1 print(cnt)
false
21.428571
[ "-S = int(eval(input()))", "-L = sorted(list(map(int, input().split())))", "-count = 0", "-for i in range(len(L)):", "- for j in range(i + 1, len(L)):", "- for k in range(j + 1, len(L)):", "- if L[i] != L[j] and L[j] != L[k]:", "- if (", "- (L[i] + L[j] > L[k])", "- and (L[j] + L[k] > L[i])", "- and ((L[k] + L[i] > L[j]))", "- ):", "- count += 1", "-print(count)", "+n = int(eval(input()))", "+l = list(map(int, input().split()))", "+l.sort()", "+cnt = 0", "+for i in range(n):", "+ for j in range(i + 1, n):", "+ for k in range(j + 1, n):", "+ if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]:", "+ continue", "+ if l[k] - l[j] - l[i] < 0:", "+ cnt += 1", "+print(cnt)" ]
false
0.036506
0.035791
1.019998
[ "s177412800", "s735436575" ]
u677121387
p03163
python
s271121429
s643963432
1,058
477
131,036
120,428
Accepted
Accepted
54.91
N,W = list(map(int,input().split())) w = [0]*(N+1) v = [0]*(N+1) for i in range(1,N+1): w[i],v[i] = list(map(int,input().split())) dp = [[0]*(N+1) for _ in range(W+1)] for i in range(1,W+1): for j in range(1,N+1): if i < w[j]: dp[i][j] = dp[i][j-1] else: dp[i][j] = max(dp[i][j-1],dp[i-w[j]][j-1]+v[j]) print((dp[W][N]))
N,W = list(map(int,input().split())) w = [0]*(N+1) v = [0]*(N+1) for i in range(1,N+1): w[i],v[i] = list(map(int,input().split())) dp = [[0]*(W+1) for _ in range(N+1)] for i in range(1,N+1): for j in range(1,W+1): if j < w[i]: dp[i][j] = dp[i-1][j] else: dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]) print((dp[N][W]))
11
11
337
337
N, W = list(map(int, input().split())) w = [0] * (N + 1) v = [0] * (N + 1) for i in range(1, N + 1): w[i], v[i] = list(map(int, input().split())) dp = [[0] * (N + 1) for _ in range(W + 1)] for i in range(1, W + 1): for j in range(1, N + 1): if i < w[j]: dp[i][j] = dp[i][j - 1] else: dp[i][j] = max(dp[i][j - 1], dp[i - w[j]][j - 1] + v[j]) print((dp[W][N]))
N, W = list(map(int, input().split())) w = [0] * (N + 1) v = [0] * (N + 1) for i in range(1, N + 1): w[i], v[i] = list(map(int, input().split())) dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(1, N + 1): for j in range(1, W + 1): if j < w[i]: dp[i][j] = dp[i - 1][j] else: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]) print((dp[N][W]))
false
0
[ "-dp = [[0] * (N + 1) for _ in range(W + 1)]", "-for i in range(1, W + 1):", "- for j in range(1, N + 1):", "- if i < w[j]:", "- dp[i][j] = dp[i][j - 1]", "+dp = [[0] * (W + 1) for _ in range(N + 1)]", "+for i in range(1, N + 1):", "+ for j in range(1, W + 1):", "+ if j < w[i]:", "+ dp[i][j] = dp[i - 1][j]", "- dp[i][j] = max(dp[i][j - 1], dp[i - w[j]][j - 1] + v[j])", "-print((dp[W][N]))", "+ dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i])", "+print((dp[N][W]))" ]
false
0.046249
0.044256
1.045022
[ "s271121429", "s643963432" ]
u339199690
p03775
python
s528807965
s991002826
164
30
12,488
3,060
Accepted
Accepted
81.71
import numpy def F(A, B): count = 0 while A > 0 or B > 0: A //= 10 B //= 10 count += 1 return count N = int(eval(input())) res = 10 for A in range(1, int(numpy.sqrt(N)) + 1): if N % A == 0: B = N // A res = min(res, F(A, B)) print(res)
import math N = int(eval(input())) res = N for A in range(1, int(math.sqrt(N)) + 1): if N % A == 0: B = N // A res = min(res, max(len(str(A)), len(str(B)))) print(res)
19
9
307
190
import numpy def F(A, B): count = 0 while A > 0 or B > 0: A //= 10 B //= 10 count += 1 return count N = int(eval(input())) res = 10 for A in range(1, int(numpy.sqrt(N)) + 1): if N % A == 0: B = N // A res = min(res, F(A, B)) print(res)
import math N = int(eval(input())) res = N for A in range(1, int(math.sqrt(N)) + 1): if N % A == 0: B = N // A res = min(res, max(len(str(A)), len(str(B)))) print(res)
false
52.631579
[ "-import numpy", "-", "-", "-def F(A, B):", "- count = 0", "- while A > 0 or B > 0:", "- A //= 10", "- B //= 10", "- count += 1", "- return count", "-", "+import math", "-res = 10", "-for A in range(1, int(numpy.sqrt(N)) + 1):", "+res = N", "+for A in range(1, int(math.sqrt(N)) + 1):", "- res = min(res, F(A, B))", "+ res = min(res, max(len(str(A)), len(str(B))))" ]
false
0.280405
0.03831
7.319312
[ "s528807965", "s991002826" ]
u829859091
p02706
python
s032219410
s454032721
23
21
10,052
10,056
Accepted
Accepted
8.7
n, m = list(map(int, input().split())) A = list(map(int, input().split())) if sum(A) <= n: print((n - sum(A))) else: print((-1))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) if N - sum(A) >= 0: print((N - sum(A))) else: print((-1))
7
7
133
137
n, m = list(map(int, input().split())) A = list(map(int, input().split())) if sum(A) <= n: print((n - sum(A))) else: print((-1))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) if N - sum(A) >= 0: print((N - sum(A))) else: print((-1))
false
0
[ "-n, m = list(map(int, input().split()))", "+N, M = list(map(int, input().split()))", "-if sum(A) <= n:", "- print((n - sum(A)))", "+if N - sum(A) >= 0:", "+ print((N - sum(A)))" ]
false
0.045533
0.046097
0.987765
[ "s032219410", "s454032721" ]
u802963389
p02792
python
s454661777
s902251246
230
155
3,064
3,060
Accepted
Accepted
32.61
n = int(eval(input())) c = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): p = int(str(i)[0]) q = int(str(i)[-1]) c[p][q] += 1 ans = 0 for i in range(10): for j in range(10): ans += c[i][j] * c[j][i] print(ans)
n = int(eval(input())) C = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): C[int(str(i)[0])][i % 10] += 1 ans = 0 for i in range(10): for j in range(10): ans += C[i][j] * C[j][i] print(ans)
13
10
238
211
n = int(eval(input())) c = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): p = int(str(i)[0]) q = int(str(i)[-1]) c[p][q] += 1 ans = 0 for i in range(10): for j in range(10): ans += c[i][j] * c[j][i] print(ans)
n = int(eval(input())) C = [[0] * 10 for _ in range(10)] for i in range(1, n + 1): C[int(str(i)[0])][i % 10] += 1 ans = 0 for i in range(10): for j in range(10): ans += C[i][j] * C[j][i] print(ans)
false
23.076923
[ "-c = [[0] * 10 for _ in range(10)]", "+C = [[0] * 10 for _ in range(10)]", "- p = int(str(i)[0])", "- q = int(str(i)[-1])", "- c[p][q] += 1", "+ C[int(str(i)[0])][i % 10] += 1", "- ans += c[i][j] * c[j][i]", "+ ans += C[i][j] * C[j][i]" ]
false
0.049968
0.060625
0.824213
[ "s454661777", "s902251246" ]
u303059352
p03071
python
s662070927
s820869823
21
17
3,316
2,940
Accepted
Accepted
19.05
a,b=list(map(int, input().split())) if a == b: print((a*2)) else: print((max(a,b)*2-1))
a,b=list(map(int,input().split())) print((max(a+b,2*a-1,2*b-1)))
5
2
91
57
a, b = list(map(int, input().split())) if a == b: print((a * 2)) else: print((max(a, b) * 2 - 1))
a, b = list(map(int, input().split())) print((max(a + b, 2 * a - 1, 2 * b - 1)))
false
60
[ "-if a == b:", "- print((a * 2))", "-else:", "- print((max(a, b) * 2 - 1))", "+print((max(a + b, 2 * a - 1, 2 * b - 1)))" ]
false
0.042234
0.03929
1.074919
[ "s662070927", "s820869823" ]
u375616706
p03017
python
s015863920
s085672172
280
19
8,180
3,572
Accepted
Accepted
93.21
# python template for atcoder1 import sys N, A, B, C, D = list(map(int, input().split())) L = list([v for v in eval(input())]) HOP = [1, 2] dp_d = [0]*N dp_d[B-1] = 1 for i in range(N): if L[i] == "#": continue for h in HOP: dst = i+h if dst < N and L[dst] == ".": dp_d[dst] = max(dp_d[dst], dp_d[i]) dp_c = [0]*N dp_c[A-1] = 1 for i in range(N): if L[i] == "#": continue for h in HOP: dst = i+h if dst < N and L[dst] == ".": dp_c[dst] = max(dp_c[dst], dp_c[i]) reachable = False if dp_c[C-1] == 1 and dp_d[D-1] == 1: reachable = True if not reachable: print("No") elif C < D: print("Yes") else: if "..." in "".join(L[B-2:min(C, D)+1]): print("Yes") else: print("No")
# python template for atcoder1 import sys N, A, B, C, D = [int(x)-1 for x in input().split()] L = eval(input()) reachable = True if "##" in L[A:C+1] or "##" in L[B:D+1]: reachable = False if not reachable: print("No") elif C < D: print("Yes") else: if "..." in L[B-1:D+2]: print("Yes") else: print("No")
38
19
820
360
# python template for atcoder1 import sys N, A, B, C, D = list(map(int, input().split())) L = list([v for v in eval(input())]) HOP = [1, 2] dp_d = [0] * N dp_d[B - 1] = 1 for i in range(N): if L[i] == "#": continue for h in HOP: dst = i + h if dst < N and L[dst] == ".": dp_d[dst] = max(dp_d[dst], dp_d[i]) dp_c = [0] * N dp_c[A - 1] = 1 for i in range(N): if L[i] == "#": continue for h in HOP: dst = i + h if dst < N and L[dst] == ".": dp_c[dst] = max(dp_c[dst], dp_c[i]) reachable = False if dp_c[C - 1] == 1 and dp_d[D - 1] == 1: reachable = True if not reachable: print("No") elif C < D: print("Yes") else: if "..." in "".join(L[B - 2 : min(C, D) + 1]): print("Yes") else: print("No")
# python template for atcoder1 import sys N, A, B, C, D = [int(x) - 1 for x in input().split()] L = eval(input()) reachable = True if "##" in L[A : C + 1] or "##" in L[B : D + 1]: reachable = False if not reachable: print("No") elif C < D: print("Yes") else: if "..." in L[B - 1 : D + 2]: print("Yes") else: print("No")
false
50
[ "-N, A, B, C, D = list(map(int, input().split()))", "-L = list([v for v in eval(input())])", "-HOP = [1, 2]", "-dp_d = [0] * N", "-dp_d[B - 1] = 1", "-for i in range(N):", "- if L[i] == \"#\":", "- continue", "- for h in HOP:", "- dst = i + h", "- if dst < N and L[dst] == \".\":", "- dp_d[dst] = max(dp_d[dst], dp_d[i])", "-dp_c = [0] * N", "-dp_c[A - 1] = 1", "-for i in range(N):", "- if L[i] == \"#\":", "- continue", "- for h in HOP:", "- dst = i + h", "- if dst < N and L[dst] == \".\":", "- dp_c[dst] = max(dp_c[dst], dp_c[i])", "-reachable = False", "-if dp_c[C - 1] == 1 and dp_d[D - 1] == 1:", "- reachable = True", "+N, A, B, C, D = [int(x) - 1 for x in input().split()]", "+L = eval(input())", "+reachable = True", "+if \"##\" in L[A : C + 1] or \"##\" in L[B : D + 1]:", "+ reachable = False", "- if \"...\" in \"\".join(L[B - 2 : min(C, D) + 1]):", "+ if \"...\" in L[B - 1 : D + 2]:" ]
false
0.052672
0.036601
1.43908
[ "s015863920", "s085672172" ]
u523087093
p03752
python
s085408062
s577836293
45
37
9,192
9,208
Accepted
Accepted
17.78
import itertools N, K = list(map(int, input().split())) # Nは建物の数、K色以上に塗る A = list(map(int, input().split())) N_index = list(range(1,N)) min_cost = float('inf') for target_indexes in itertools.combinations(N_index, K-1): # N_indexからK個選ぶ方法を全通り試す cost = 0 copy_A = A.copy() for i in range(1, N): if i in target_indexes: if copy_A[i] <= max(copy_A[:i]): diff = max(copy_A[:i]) - copy_A[i] # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする copy_A[i] += diff + 1 cost += diff + 1 min_cost = min(min_cost, cost) print(min_cost)
import itertools N, K = list(map(int, input().split())) # Nは建物の数、K色以上に塗る A = list(map(int, input().split())) N_index = list(range(1,N)) # 一番左は固定なので min_cost = float('inf') for target_indexes in itertools.combinations(N_index, K-1): # N_indexからK-1個選ぶ方法を全通り試す cost = 0 copy_A = A.copy() for i in target_indexes: if copy_A[i] <= max(copy_A[:i]): diff = max(copy_A[:i]) - copy_A[i] # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする copy_A[i] += diff + 1 cost += diff + 1 min_cost = min(min_cost, cost) print(min_cost)
20
19
610
578
import itertools N, K = list(map(int, input().split())) # Nは建物の数、K色以上に塗る A = list(map(int, input().split())) N_index = list(range(1, N)) min_cost = float("inf") for target_indexes in itertools.combinations(N_index, K - 1): # N_indexからK個選ぶ方法を全通り試す cost = 0 copy_A = A.copy() for i in range(1, N): if i in target_indexes: if copy_A[i] <= max(copy_A[:i]): diff = ( max(copy_A[:i]) - copy_A[i] ) # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする copy_A[i] += diff + 1 cost += diff + 1 min_cost = min(min_cost, cost) print(min_cost)
import itertools N, K = list(map(int, input().split())) # Nは建物の数、K色以上に塗る A = list(map(int, input().split())) N_index = list(range(1, N)) # 一番左は固定なので min_cost = float("inf") for target_indexes in itertools.combinations(N_index, K - 1): # N_indexからK-1個選ぶ方法を全通り試す cost = 0 copy_A = A.copy() for i in target_indexes: if copy_A[i] <= max(copy_A[:i]): diff = max(copy_A[:i]) - copy_A[i] # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする copy_A[i] += diff + 1 cost += diff + 1 min_cost = min(min_cost, cost) print(min_cost)
false
5
[ "-N_index = list(range(1, N))", "+N_index = list(range(1, N)) # 一番左は固定なので", "-for target_indexes in itertools.combinations(N_index, K - 1): # N_indexからK個選ぶ方法を全通り試す", "+for target_indexes in itertools.combinations(N_index, K - 1): # N_indexからK-1個選ぶ方法を全通り試す", "- for i in range(1, N):", "- if i in target_indexes:", "- if copy_A[i] <= max(copy_A[:i]):", "- diff = (", "- max(copy_A[:i]) - copy_A[i]", "- ) # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする", "- copy_A[i] += diff + 1", "- cost += diff + 1", "+ for i in target_indexes:", "+ if copy_A[i] <= max(copy_A[:i]):", "+ diff = max(copy_A[:i]) - copy_A[i] # ターゲットの建物の場合はそれより左側の建物のmaxより1だけ大きくする", "+ copy_A[i] += diff + 1", "+ cost += diff + 1" ]
false
0.044892
0.044425
1.010499
[ "s085408062", "s577836293" ]
u476604182
p03287
python
s901997476
s441393921
141
96
16,596
16,604
Accepted
Accepted
31.91
from collections import defaultdict N, M = list(map(int, input().split())) a = [int(c)%M for c in input().split()] L = [0] for i in range(N): L += [(L[-1]+a[i])%M] log = defaultdict(int) log[0] = 1 ans = 0 for i in range(1,N+1): x = L[i]%M ans += log[x] log[x] += 1 print(ans)
from collections import Counter from itertools import accumulate N, M, *A = list(map(int, open(0).read().split())) B = [b%M for b in accumulate(A)] C = Counter(B) ans = C[0] for k in list(C.keys()): ans += C[k]*(C[k]-1)//2 print(ans)
14
9
291
231
from collections import defaultdict N, M = list(map(int, input().split())) a = [int(c) % M for c in input().split()] L = [0] for i in range(N): L += [(L[-1] + a[i]) % M] log = defaultdict(int) log[0] = 1 ans = 0 for i in range(1, N + 1): x = L[i] % M ans += log[x] log[x] += 1 print(ans)
from collections import Counter from itertools import accumulate N, M, *A = list(map(int, open(0).read().split())) B = [b % M for b in accumulate(A)] C = Counter(B) ans = C[0] for k in list(C.keys()): ans += C[k] * (C[k] - 1) // 2 print(ans)
false
35.714286
[ "-from collections import defaultdict", "+from collections import Counter", "+from itertools import accumulate", "-N, M = list(map(int, input().split()))", "-a = [int(c) % M for c in input().split()]", "-L = [0]", "-for i in range(N):", "- L += [(L[-1] + a[i]) % M]", "-log = defaultdict(int)", "-log[0] = 1", "-ans = 0", "-for i in range(1, N + 1):", "- x = L[i] % M", "- ans += log[x]", "- log[x] += 1", "+N, M, *A = list(map(int, open(0).read().split()))", "+B = [b % M for b in accumulate(A)]", "+C = Counter(B)", "+ans = C[0]", "+for k in list(C.keys()):", "+ ans += C[k] * (C[k] - 1) // 2" ]
false
0.099886
0.04693
2.128397
[ "s901997476", "s441393921" ]
u532966492
p03128
python
s308303871
s048740205
379
151
137,180
5,356
Accepted
Accepted
60.16
N,M=list(map(int,input().split())) A=list((list(map(int,input().split())))) m=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]] B=[] for a in A: B.append(m[a-1]) if [5,5] in B: if [2,5] in B: B.remove([2,5]) if [3,5] in B: B.remove([3,5]) if [3,5] in B and [2,5] in B: B.remove([2,5]) if [7,3] in B: if [6,6] in B: B.remove([6,6]) if [9,6] in B: B.remove([9,6]) if [9,6] in B and [6,6] in B: B.remove([6,6]) if [1,2] in B and [7,3] in B: if [2,5] in B: B.remove([2,5]) if [3,5] in B: B.remove([3,5]) if [5,5] in B: B.remove([5,5]) if [8,7] in B: B.remove([8,7]) if [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B: B.remove([8,7]) if [4,4] in B and [7,3] in B and [8,7] in B: B.remove([8,7]) if [1,2] in B and [4,4] in B: B.remove([4,4]) maxlist=[""]*(N+1) for i in range(N+1): if i!=0 and maxlist[i]=="": continue else: for b in B: if i+b[1]>N: continue ans=maxlist[i]+str(b[0]) _max=maxlist[i+b[1]] if len(ans)<len(_max): continue elif len(ans)>len(_max): maxlist[i+b[1]] = ans else: for j in range(len(ans)): if ans[j]<_max[j]: break if ans[j]>_max[j]: maxlist[i+b[1]] = ans break print((maxlist[N]))
def comp(a,b): if sum(a)<sum(b): return "right" elif sum(a)>sum(b): return "left" else: for i in range(8,-1,-1): if a[i]<b[i]: return "right" elif a[i]>b[i]: return "left" else: return "equal" N,M=map(int,input().split()) A=list((map(int,input().split()))) m=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]] B=[] for a in A: B.append(m[a-1]) if [5,5] in B: if [2,5] in B: B.remove([2,5]) if [3,5] in B: B.remove([3,5]) if [3,5] in B and [2,5] in B: B.remove([2,5]) if [7,3] in B: if [6,6] in B: B.remove([6,6]) if [9,6] in B: B.remove([9,6]) if [9,6] in B and [6,6] in B: B.remove([6,6]) if [1,2] in B and [7,3] in B: if [2,5] in B: B.remove([2,5]) if [3,5] in B: B.remove([3,5]) if [5,5] in B: B.remove([5,5]) if [8,7] in B: B.remove([8,7]) if [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B: B.remove([8,7]) if [4,4] in B and [7,3] in B and [8,7] in B: B.remove([8,7]) if [1,2] in B and [4,4] in B: B.remove([4,4]) maxlist=[[0]*9 for _ in range(N+1)] for i in range(N+1): if i!=0 and sum(maxlist[i])==0: continue else: for b in B: if i+b[1]>N: continue #ans=maxlist[i]+str(b[0]) ans=[maxlist[i][k] for k in range(9)] ans[b[0]-1]+=1 _max=maxlist[i+b[1]] if comp(ans,_max) == "left": maxlist[i+b[1]]=[ans[k] for k in range(9)] for i in range(8,-1,-1): print(str(i+1)*maxlist[N][i],end="") print()
70
79
1,614
1,809
N, M = list(map(int, input().split())) A = list((list(map(int, input().split())))) m = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] B = [] for a in A: B.append(m[a - 1]) if [5, 5] in B: if [2, 5] in B: B.remove([2, 5]) if [3, 5] in B: B.remove([3, 5]) if [3, 5] in B and [2, 5] in B: B.remove([2, 5]) if [7, 3] in B: if [6, 6] in B: B.remove([6, 6]) if [9, 6] in B: B.remove([9, 6]) if [9, 6] in B and [6, 6] in B: B.remove([6, 6]) if [1, 2] in B and [7, 3] in B: if [2, 5] in B: B.remove([2, 5]) if [3, 5] in B: B.remove([3, 5]) if [5, 5] in B: B.remove([5, 5]) if [8, 7] in B: B.remove([8, 7]) if [1, 2] in B and ([2, 5] in B or [3, 5] in B or [5, 5] in B) and [8, 7] in B: B.remove([8, 7]) if [4, 4] in B and [7, 3] in B and [8, 7] in B: B.remove([8, 7]) if [1, 2] in B and [4, 4] in B: B.remove([4, 4]) maxlist = [""] * (N + 1) for i in range(N + 1): if i != 0 and maxlist[i] == "": continue else: for b in B: if i + b[1] > N: continue ans = maxlist[i] + str(b[0]) _max = maxlist[i + b[1]] if len(ans) < len(_max): continue elif len(ans) > len(_max): maxlist[i + b[1]] = ans else: for j in range(len(ans)): if ans[j] < _max[j]: break if ans[j] > _max[j]: maxlist[i + b[1]] = ans break print((maxlist[N]))
def comp(a, b): if sum(a) < sum(b): return "right" elif sum(a) > sum(b): return "left" else: for i in range(8, -1, -1): if a[i] < b[i]: return "right" elif a[i] > b[i]: return "left" else: return "equal" N, M = map(int, input().split()) A = list((map(int, input().split()))) m = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]] B = [] for a in A: B.append(m[a - 1]) if [5, 5] in B: if [2, 5] in B: B.remove([2, 5]) if [3, 5] in B: B.remove([3, 5]) if [3, 5] in B and [2, 5] in B: B.remove([2, 5]) if [7, 3] in B: if [6, 6] in B: B.remove([6, 6]) if [9, 6] in B: B.remove([9, 6]) if [9, 6] in B and [6, 6] in B: B.remove([6, 6]) if [1, 2] in B and [7, 3] in B: if [2, 5] in B: B.remove([2, 5]) if [3, 5] in B: B.remove([3, 5]) if [5, 5] in B: B.remove([5, 5]) if [8, 7] in B: B.remove([8, 7]) if [1, 2] in B and ([2, 5] in B or [3, 5] in B or [5, 5] in B) and [8, 7] in B: B.remove([8, 7]) if [4, 4] in B and [7, 3] in B and [8, 7] in B: B.remove([8, 7]) if [1, 2] in B and [4, 4] in B: B.remove([4, 4]) maxlist = [[0] * 9 for _ in range(N + 1)] for i in range(N + 1): if i != 0 and sum(maxlist[i]) == 0: continue else: for b in B: if i + b[1] > N: continue # ans=maxlist[i]+str(b[0]) ans = [maxlist[i][k] for k in range(9)] ans[b[0] - 1] += 1 _max = maxlist[i + b[1]] if comp(ans, _max) == "left": maxlist[i + b[1]] = [ans[k] for k in range(9)] for i in range(8, -1, -1): print(str(i + 1) * maxlist[N][i], end="") print()
false
11.392405
[ "-N, M = list(map(int, input().split()))", "-A = list((list(map(int, input().split()))))", "+def comp(a, b):", "+ if sum(a) < sum(b):", "+ return \"right\"", "+ elif sum(a) > sum(b):", "+ return \"left\"", "+ else:", "+ for i in range(8, -1, -1):", "+ if a[i] < b[i]:", "+ return \"right\"", "+ elif a[i] > b[i]:", "+ return \"left\"", "+ else:", "+ return \"equal\"", "+", "+", "+N, M = map(int, input().split())", "+A = list((map(int, input().split())))", "-maxlist = [\"\"] * (N + 1)", "+maxlist = [[0] * 9 for _ in range(N + 1)]", "- if i != 0 and maxlist[i] == \"\":", "+ if i != 0 and sum(maxlist[i]) == 0:", "- ans = maxlist[i] + str(b[0])", "+ # ans=maxlist[i]+str(b[0])", "+ ans = [maxlist[i][k] for k in range(9)]", "+ ans[b[0] - 1] += 1", "- if len(ans) < len(_max):", "- continue", "- elif len(ans) > len(_max):", "- maxlist[i + b[1]] = ans", "- else:", "- for j in range(len(ans)):", "- if ans[j] < _max[j]:", "- break", "- if ans[j] > _max[j]:", "- maxlist[i + b[1]] = ans", "- break", "-print((maxlist[N]))", "+ if comp(ans, _max) == \"left\":", "+ maxlist[i + b[1]] = [ans[k] for k in range(9)]", "+for i in range(8, -1, -1):", "+ print(str(i + 1) * maxlist[N][i], end=\"\")", "+print()" ]
false
0.044198
0.007325
6.033717
[ "s308303871", "s048740205" ]
u133936772
p02803
python
s233926317
s453531653
365
303
9,464
27,088
Accepted
Accepted
16.99
h,w=list(map(int,input().split())) g=[[*eval(input())] for _ in range(h)] from collections import * a=0 for sx in range(h): for sy in range(w): if g[sx][sy]=='#': continue d=[[-1]*w for _ in range(h)] d[sx][sy]=0 q=deque([(sx,sy)]) while q: x,y=q.popleft() t=d[x][y]+1 for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]: nx,ny=x+dx,y+dy if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0: d[nx][ny]=t q.append((nx,ny)) a=max(a,t) print(a)
h,w=list(map(int,input().split())) g=[[*eval(input())] for _ in range(h)] from collections import * def bfs(sx,sy): d=[[-1]*w for _ in range(h)] d[sx][sy]=0 q=deque([(sx,sy)]) while q: x,y=q.popleft() t=d[x][y]+1 for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]: nx,ny=x+dx,y+dy if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0: d[nx][ny]=t q.append((nx,ny)) return d import numpy as np a=0 for sx in range(h): for sy in range(w): if g[sx][sy]=='#': continue a=max(a,np.max(bfs(sx,sy))) print(a)
20
23
528
566
h, w = list(map(int, input().split())) g = [[*eval(input())] for _ in range(h)] from collections import * a = 0 for sx in range(h): for sy in range(w): if g[sx][sy] == "#": continue d = [[-1] * w for _ in range(h)] d[sx][sy] = 0 q = deque([(sx, sy)]) while q: x, y = q.popleft() t = d[x][y] + 1 for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == "." and d[nx][ny] < 0: d[nx][ny] = t q.append((nx, ny)) a = max(a, t) print(a)
h, w = list(map(int, input().split())) g = [[*eval(input())] for _ in range(h)] from collections import * def bfs(sx, sy): d = [[-1] * w for _ in range(h)] d[sx][sy] = 0 q = deque([(sx, sy)]) while q: x, y = q.popleft() t = d[x][y] + 1 for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]: nx, ny = x + dx, y + dy if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == "." and d[nx][ny] < 0: d[nx][ny] = t q.append((nx, ny)) return d import numpy as np a = 0 for sx in range(h): for sy in range(w): if g[sx][sy] == "#": continue a = max(a, np.max(bfs(sx, sy))) print(a)
false
13.043478
[ "+", "+", "+def bfs(sx, sy):", "+ d = [[-1] * w for _ in range(h)]", "+ d[sx][sy] = 0", "+ q = deque([(sx, sy)])", "+ while q:", "+ x, y = q.popleft()", "+ t = d[x][y] + 1", "+ for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:", "+ nx, ny = x + dx, y + dy", "+ if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == \".\" and d[nx][ny] < 0:", "+ d[nx][ny] = t", "+ q.append((nx, ny))", "+ return d", "+", "+", "+import numpy as np", "- d = [[-1] * w for _ in range(h)]", "- d[sx][sy] = 0", "- q = deque([(sx, sy)])", "- while q:", "- x, y = q.popleft()", "- t = d[x][y] + 1", "- for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:", "- nx, ny = x + dx, y + dy", "- if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == \".\" and d[nx][ny] < 0:", "- d[nx][ny] = t", "- q.append((nx, ny))", "- a = max(a, t)", "+ a = max(a, np.max(bfs(sx, sy)))" ]
false
0.051615
0.113069
0.45649
[ "s233926317", "s453531653" ]
u170201762
p03291
python
s490975280
s590701021
239
123
15,108
3,188
Accepted
Accepted
48.54
Mod = 10**9+7 S = eval(input()) N = len(S) O = 1 A = [0]*N AB = [0]*N ABC = [0]*N for i in range(N): A[i] = A[i-1] AB[i] = AB[i-1] ABC[i] = ABC[i-1] if S[i] == 'A': A[i] += O if S[i] == 'B': AB[i] += A[i-1] if S[i] == 'C': ABC[i] += AB[i-1] if S[i] == '?': A[i] *= 3 A[i] += O AB[i] *= 3 AB[i] += A[i-1] ABC[i] *= 3 ABC[i] += AB[i-1] O *= 3 A[i] %= Mod AB[i] %= Mod ABC[i] %= Mod O %= Mod print((ABC[-1]))
mod = 10**9+7 S = eval(input()) A = 0 AB = 0 ABC = 0 N = 1 for i in range(len(S)): if S[i] == 'A': A += N elif S[i] == 'B': AB += A elif S[i] == 'C': ABC += AB else: ABC = 3*ABC + AB AB = 3*AB + A A = 3*A + N N *= 3 A %= mod AB %= mod ABC %= mod N %= mod print(ABC)
31
25
552
374
Mod = 10**9 + 7 S = eval(input()) N = len(S) O = 1 A = [0] * N AB = [0] * N ABC = [0] * N for i in range(N): A[i] = A[i - 1] AB[i] = AB[i - 1] ABC[i] = ABC[i - 1] if S[i] == "A": A[i] += O if S[i] == "B": AB[i] += A[i - 1] if S[i] == "C": ABC[i] += AB[i - 1] if S[i] == "?": A[i] *= 3 A[i] += O AB[i] *= 3 AB[i] += A[i - 1] ABC[i] *= 3 ABC[i] += AB[i - 1] O *= 3 A[i] %= Mod AB[i] %= Mod ABC[i] %= Mod O %= Mod print((ABC[-1]))
mod = 10**9 + 7 S = eval(input()) A = 0 AB = 0 ABC = 0 N = 1 for i in range(len(S)): if S[i] == "A": A += N elif S[i] == "B": AB += A elif S[i] == "C": ABC += AB else: ABC = 3 * ABC + AB AB = 3 * AB + A A = 3 * A + N N *= 3 A %= mod AB %= mod ABC %= mod N %= mod print(ABC)
false
19.354839
[ "-Mod = 10**9 + 7", "+mod = 10**9 + 7", "-N = len(S)", "-O = 1", "-A = [0] * N", "-AB = [0] * N", "-ABC = [0] * N", "-for i in range(N):", "- A[i] = A[i - 1]", "- AB[i] = AB[i - 1]", "- ABC[i] = ABC[i - 1]", "+A = 0", "+AB = 0", "+ABC = 0", "+N = 1", "+for i in range(len(S)):", "- A[i] += O", "- if S[i] == \"B\":", "- AB[i] += A[i - 1]", "- if S[i] == \"C\":", "- ABC[i] += AB[i - 1]", "- if S[i] == \"?\":", "- A[i] *= 3", "- A[i] += O", "- AB[i] *= 3", "- AB[i] += A[i - 1]", "- ABC[i] *= 3", "- ABC[i] += AB[i - 1]", "- O *= 3", "- A[i] %= Mod", "- AB[i] %= Mod", "- ABC[i] %= Mod", "- O %= Mod", "-print((ABC[-1]))", "+ A += N", "+ elif S[i] == \"B\":", "+ AB += A", "+ elif S[i] == \"C\":", "+ ABC += AB", "+ else:", "+ ABC = 3 * ABC + AB", "+ AB = 3 * AB + A", "+ A = 3 * A + N", "+ N *= 3", "+ A %= mod", "+ AB %= mod", "+ ABC %= mod", "+ N %= mod", "+print(ABC)" ]
false
0.084995
0.045973
1.848803
[ "s490975280", "s590701021" ]
u896741788
p03475
python
s071664529
s916126757
66
45
3,188
3,188
Accepted
Accepted
31.82
import sys input = sys.stdin.readline def f(): n=int(eval(input())) l=tuple(tuple(map(int,input().split())) for i in range(n-1)) for i in range(n): now=0 for a,s,d in l[i:]: now=a+s-(-max(0,now-s)//d)*d print(now) if __name__=="__main__": f()
import sys input = sys.stdin.readline def f(): n=int(eval(input())) l=tuple(tuple(map(int,input().split())) for i in range(n-1)) for i in range(n): now=0 for a,s,d in l[i:]: if now<=s:now=s+a else:now=-(-now//d)*d+a print(now) if __name__=="__main__": f()
12
13
274
294
import sys input = sys.stdin.readline def f(): n = int(eval(input())) l = tuple(tuple(map(int, input().split())) for i in range(n - 1)) for i in range(n): now = 0 for a, s, d in l[i:]: now = a + s - (-max(0, now - s) // d) * d print(now) if __name__ == "__main__": f()
import sys input = sys.stdin.readline def f(): n = int(eval(input())) l = tuple(tuple(map(int, input().split())) for i in range(n - 1)) for i in range(n): now = 0 for a, s, d in l[i:]: if now <= s: now = s + a else: now = -(-now // d) * d + a print(now) if __name__ == "__main__": f()
false
7.692308
[ "- now = a + s - (-max(0, now - s) // d) * d", "+ if now <= s:", "+ now = s + a", "+ else:", "+ now = -(-now // d) * d + a" ]
false
0.035436
0.046401
0.763692
[ "s071664529", "s916126757" ]
u762420987
p02923
python
s161544347
s118500653
91
74
14,252
14,252
Accepted
Accepted
18.68
N = int(eval(input())) Hlist = list(map(int, input().split())) now = Hlist[0] ans = 0 num = 0 for i in range(N - 1): if Hlist[i + 1] <= now: num += 1 else: ans = max(ans, num) num = 0 now = Hlist[i + 1] # print(ans, num) print((max(ans, num)))
N = int(eval(input())) Hlist = list(map(int, input().split())) ans = 0 c = 0 now = Hlist[0] for next_step in Hlist[1:]: if next_step <= now: c += 1 else: ans = max(ans, c) c = 0 now = next_step ans = max(ans, c) print(ans)
14
15
289
268
N = int(eval(input())) Hlist = list(map(int, input().split())) now = Hlist[0] ans = 0 num = 0 for i in range(N - 1): if Hlist[i + 1] <= now: num += 1 else: ans = max(ans, num) num = 0 now = Hlist[i + 1] # print(ans, num) print((max(ans, num)))
N = int(eval(input())) Hlist = list(map(int, input().split())) ans = 0 c = 0 now = Hlist[0] for next_step in Hlist[1:]: if next_step <= now: c += 1 else: ans = max(ans, c) c = 0 now = next_step ans = max(ans, c) print(ans)
false
6.666667
[ "+ans = 0", "+c = 0", "-ans = 0", "-num = 0", "-for i in range(N - 1):", "- if Hlist[i + 1] <= now:", "- num += 1", "+for next_step in Hlist[1:]:", "+ if next_step <= now:", "+ c += 1", "- ans = max(ans, num)", "- num = 0", "- now = Hlist[i + 1]", "- # print(ans, num)", "-print((max(ans, num)))", "+ ans = max(ans, c)", "+ c = 0", "+ now = next_step", "+ans = max(ans, c)", "+print(ans)" ]
false
0.09445
0.084632
1.116008
[ "s161544347", "s118500653" ]
u562935282
p02612
python
s100443985
s860459040
31
28
8,916
9,088
Accepted
Accepted
9.68
def main(): N = int(eval(input())) change = -N % 1000 print(change) if __name__ == '__main__': main()
def main(): N = int(eval(input())) ans = - N % 1000 if ans < 0: ans += 1000 print(ans) if __name__ == '__main__': main()
9
12
123
158
def main(): N = int(eval(input())) change = -N % 1000 print(change) if __name__ == "__main__": main()
def main(): N = int(eval(input())) ans = -N % 1000 if ans < 0: ans += 1000 print(ans) if __name__ == "__main__": main()
false
25
[ "- change = -N % 1000", "- print(change)", "+ ans = -N % 1000", "+ if ans < 0:", "+ ans += 1000", "+ print(ans)" ]
false
0.047429
0.04827
0.982569
[ "s100443985", "s860459040" ]
u744920373
p03252
python
s819426360
s673748940
174
88
3,760
3,760
Accepted
Accepted
49.43
S = eval(input()) T = eval(input()) #ad_list = [[] for i in range(26)] #ad_list2 = [[] for i in range(26)] num = 97 al_dict = {} al_dict2 = {} new = '' new2 = '' for i, moji in enumerate(S): if moji not in al_dict: al_dict[moji] = i new += chr(num) num += 1 else: new += new[al_dict[moji]] num = 97 for i, moji in enumerate(T): if moji not in al_dict2: al_dict2[moji] = i new2 += chr(num) num += 1 else: new2 += new2[al_dict2[moji]] if new==new2: print('Yes') else: print('No')
def norm_s(S): num = 97 al_dict = {} new = '' for i, moji in enumerate(S): if moji not in al_dict: al_dict[moji] = i new += chr(num) num += 1 else: new += new[al_dict[moji]] return new S = eval(input()) T = eval(input()) new = norm_s(S) new2 = norm_s(T) if new==new2: print('Yes') else: print('No')
32
23
588
407
S = eval(input()) T = eval(input()) # ad_list = [[] for i in range(26)] # ad_list2 = [[] for i in range(26)] num = 97 al_dict = {} al_dict2 = {} new = "" new2 = "" for i, moji in enumerate(S): if moji not in al_dict: al_dict[moji] = i new += chr(num) num += 1 else: new += new[al_dict[moji]] num = 97 for i, moji in enumerate(T): if moji not in al_dict2: al_dict2[moji] = i new2 += chr(num) num += 1 else: new2 += new2[al_dict2[moji]] if new == new2: print("Yes") else: print("No")
def norm_s(S): num = 97 al_dict = {} new = "" for i, moji in enumerate(S): if moji not in al_dict: al_dict[moji] = i new += chr(num) num += 1 else: new += new[al_dict[moji]] return new S = eval(input()) T = eval(input()) new = norm_s(S) new2 = norm_s(T) if new == new2: print("Yes") else: print("No")
false
28.125
[ "+def norm_s(S):", "+ num = 97", "+ al_dict = {}", "+ new = \"\"", "+ for i, moji in enumerate(S):", "+ if moji not in al_dict:", "+ al_dict[moji] = i", "+ new += chr(num)", "+ num += 1", "+ else:", "+ new += new[al_dict[moji]]", "+ return new", "+", "+", "-# ad_list = [[] for i in range(26)]", "-# ad_list2 = [[] for i in range(26)]", "-num = 97", "-al_dict = {}", "-al_dict2 = {}", "-new = \"\"", "-new2 = \"\"", "-for i, moji in enumerate(S):", "- if moji not in al_dict:", "- al_dict[moji] = i", "- new += chr(num)", "- num += 1", "- else:", "- new += new[al_dict[moji]]", "-num = 97", "-for i, moji in enumerate(T):", "- if moji not in al_dict2:", "- al_dict2[moji] = i", "- new2 += chr(num)", "- num += 1", "- else:", "- new2 += new2[al_dict2[moji]]", "+new = norm_s(S)", "+new2 = norm_s(T)" ]
false
0.055489
0.053271
1.041639
[ "s819426360", "s673748940" ]
u537782349
p03325
python
s640360725
s951311369
102
79
4,148
4,148
Accepted
Accepted
22.55
a = int(eval(input())) b = list(map(int, input().split())) cnt = 0 for i in range(len(b)): while True: if b[i] % 2 == 0: b[i] //= 2 cnt += 1 else: break print(cnt)
a = int(eval(input())) b = list(map(int, input().split())) c = 0 for i in b: while True: if i % 2 == 0: c += 1 i //= 2 else: break print(c)
11
11
224
200
a = int(eval(input())) b = list(map(int, input().split())) cnt = 0 for i in range(len(b)): while True: if b[i] % 2 == 0: b[i] //= 2 cnt += 1 else: break print(cnt)
a = int(eval(input())) b = list(map(int, input().split())) c = 0 for i in b: while True: if i % 2 == 0: c += 1 i //= 2 else: break print(c)
false
0
[ "-cnt = 0", "-for i in range(len(b)):", "+c = 0", "+for i in b:", "- if b[i] % 2 == 0:", "- b[i] //= 2", "- cnt += 1", "+ if i % 2 == 0:", "+ c += 1", "+ i //= 2", "-print(cnt)", "+print(c)" ]
false
0.041425
0.036495
1.135079
[ "s640360725", "s951311369" ]
u699296734
p03695
python
s976205968
s219689129
29
26
9,176
9,192
Accepted
Accepted
10.34
n = int(eval(input())) a = list(map(int, input().split())) rate = [0] * 9 for i in range(n): if a[i] < 400: rate[0] += 1 elif a[i] < 800: rate[1] += 1 elif a[i] < 1200: rate[2] += 1 elif a[i] < 1600: rate[3] += 1 elif a[i] < 2000: rate[4] += 1 elif a[i] < 2400: rate[5] += 1 elif a[i] < 2800: rate[6] += 1 elif a[i] < 3200: rate[7] += 1 else: rate[8] += 1 counter = 0 for i in range(8): if rate[i] >= 1: counter += 1 print((max(1, counter), counter + rate[8]))
n = int(eval(input())) a = list(map(int, input().split())) rate = [0] * 9 for i in range(n): for j in range(8): if 400 * j <= a[i] < 400 * (j + 1): rate[j] += 1 break else: rate[8] += 1 counter = 0 for i in range(8): if rate[i] >= 1: counter += 1 print((max(1, counter), counter + rate[8]))
30
17
605
361
n = int(eval(input())) a = list(map(int, input().split())) rate = [0] * 9 for i in range(n): if a[i] < 400: rate[0] += 1 elif a[i] < 800: rate[1] += 1 elif a[i] < 1200: rate[2] += 1 elif a[i] < 1600: rate[3] += 1 elif a[i] < 2000: rate[4] += 1 elif a[i] < 2400: rate[5] += 1 elif a[i] < 2800: rate[6] += 1 elif a[i] < 3200: rate[7] += 1 else: rate[8] += 1 counter = 0 for i in range(8): if rate[i] >= 1: counter += 1 print((max(1, counter), counter + rate[8]))
n = int(eval(input())) a = list(map(int, input().split())) rate = [0] * 9 for i in range(n): for j in range(8): if 400 * j <= a[i] < 400 * (j + 1): rate[j] += 1 break else: rate[8] += 1 counter = 0 for i in range(8): if rate[i] >= 1: counter += 1 print((max(1, counter), counter + rate[8]))
false
43.333333
[ "- if a[i] < 400:", "- rate[0] += 1", "- elif a[i] < 800:", "- rate[1] += 1", "- elif a[i] < 1200:", "- rate[2] += 1", "- elif a[i] < 1600:", "- rate[3] += 1", "- elif a[i] < 2000:", "- rate[4] += 1", "- elif a[i] < 2400:", "- rate[5] += 1", "- elif a[i] < 2800:", "- rate[6] += 1", "- elif a[i] < 3200:", "- rate[7] += 1", "+ for j in range(8):", "+ if 400 * j <= a[i] < 400 * (j + 1):", "+ rate[j] += 1", "+ break" ]
false
0.037369
0.03739
0.999432
[ "s976205968", "s219689129" ]
u693953100
p03633
python
s040592884
s474512500
169
17
38,384
3,060
Accepted
Accepted
89.94
def gcd(a,b): if b==0: return a return gcd(b,a%b) n = int(eval(input())) ans = 1 l = [int(eval(input())) for i in range(n)] for i in l: ans = ans*i//gcd(ans,i) print(ans)
def gcd(a,b): if b==0: return a else: return gcd(b,a%b) n = int(eval(input())) ans = 0 for i in range(n): t = int(eval(input())) if ans==0: ans=t else: ans = (ans*t)//gcd(ans,t) print(ans)
13
15
193
243
def gcd(a, b): if b == 0: return a return gcd(b, a % b) n = int(eval(input())) ans = 1 l = [int(eval(input())) for i in range(n)] for i in l: ans = ans * i // gcd(ans, i) print(ans)
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) n = int(eval(input())) ans = 0 for i in range(n): t = int(eval(input())) if ans == 0: ans = t else: ans = (ans * t) // gcd(ans, t) print(ans)
false
13.333333
[ "- return gcd(b, a % b)", "+ else:", "+ return gcd(b, a % b)", "-ans = 1", "-l = [int(eval(input())) for i in range(n)]", "-for i in l:", "- ans = ans * i // gcd(ans, i)", "+ans = 0", "+for i in range(n):", "+ t = int(eval(input()))", "+ if ans == 0:", "+ ans = t", "+ else:", "+ ans = (ans * t) // gcd(ans, t)" ]
false
0.067871
0.039584
1.714628
[ "s040592884", "s474512500" ]
u614314290
p02766
python
s092854724
s873440079
27
21
3,444
3,316
Accepted
Accepted
22.22
from collections import deque, Counter as cnt from collections import defaultdict as dd from operator import itemgetter as ig from bisect import bisect_right as bsr from math import factorial, ceil, floor import sys sys.setrecursionlimit(1000000) # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def input(*ps): if type(ps[0]) is list: return [eval(input(*ps[0][:-1])) for _ in range(ps[0][-1])] elif len(ps) == 1: return ps[0](next(args)) else: return [p(next(args)) for p in ps] def nlist(n, v): if not n: return [] if type(v) is list else v return [nlist(n[1:], v) for _ in range(n[0])] def yesno(v): print((["Yes", "No"][not v])) def main(): """エントリーポイント""" N, K = eval(input(int, int)) n = N ans = 0 while 1 < n: n //= K ans += 1 print((ans + (n == 1))) if __name__ == '__main__': args = iter(sys.stdin.read().split()) main()
from collections import deque, Counter as cnt from collections import defaultdict as dd from operator import itemgetter as ig from bisect import bisect_right as bsr from math import factorial, ceil, floor import sys sys.setrecursionlimit(1000000) # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def input(*ps): if type(ps[0]) is list: return [eval(input(*ps[0][:-1])) for _ in range(ps[0][-1])] elif len(ps) == 1: return ps[0](next(args)) else: return [p(next(args)) for p in ps] def nlist(n, v): if not n: return [] if type(v) is list else v return [nlist(n[1:], v) for _ in range(n[0])] def yesno(v): print((["Yes", "No"][not v])) def main(): """エントリーポイント""" N, K = eval(input(int, int)) n = N ans = 0 while 0 < n: n //= K ans += 1 print(ans) if __name__ == '__main__': args = iter(sys.stdin.read().split()) main()
47
47
983
972
from collections import deque, Counter as cnt from collections import defaultdict as dd from operator import itemgetter as ig from bisect import bisect_right as bsr from math import factorial, ceil, floor import sys sys.setrecursionlimit(1000000) # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def input(*ps): if type(ps[0]) is list: return [eval(input(*ps[0][:-1])) for _ in range(ps[0][-1])] elif len(ps) == 1: return ps[0](next(args)) else: return [p(next(args)) for p in ps] def nlist(n, v): if not n: return [] if type(v) is list else v return [nlist(n[1:], v) for _ in range(n[0])] def yesno(v): print((["Yes", "No"][not v])) def main(): """エントリーポイント""" N, K = eval(input(int, int)) n = N ans = 0 while 1 < n: n //= K ans += 1 print((ans + (n == 1))) if __name__ == "__main__": args = iter(sys.stdin.read().split()) main()
from collections import deque, Counter as cnt from collections import defaultdict as dd from operator import itemgetter as ig from bisect import bisect_right as bsr from math import factorial, ceil, floor import sys sys.setrecursionlimit(1000000) # お約束 args = None INF = float("inf") MOD = int(1e9 + 7) def input(*ps): if type(ps[0]) is list: return [eval(input(*ps[0][:-1])) for _ in range(ps[0][-1])] elif len(ps) == 1: return ps[0](next(args)) else: return [p(next(args)) for p in ps] def nlist(n, v): if not n: return [] if type(v) is list else v return [nlist(n[1:], v) for _ in range(n[0])] def yesno(v): print((["Yes", "No"][not v])) def main(): """エントリーポイント""" N, K = eval(input(int, int)) n = N ans = 0 while 0 < n: n //= K ans += 1 print(ans) if __name__ == "__main__": args = iter(sys.stdin.read().split()) main()
false
0
[ "- while 1 < n:", "+ while 0 < n:", "- print((ans + (n == 1)))", "+ print(ans)" ]
false
0.036122
0.037607
0.960506
[ "s092854724", "s873440079" ]
u070201429
p02862
python
s531478992
s582279381
365
81
60,984
74,680
Accepted
Accepted
77.81
class Combination: def __init__(self, n, mod): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) l = [1] num = 1 for i in range(1, n+1): num *= i num %= mod l.append(num) self.fac = l.copy() # self.rec[i] ≡ 1 / i! (reciprocal:逆数) num = pow(num, mod-2, mod) l = [1 for i in range(n+1)] l[n] = num for i in range(n-1, 0, -1): num *= i + 1 num %= mod l[i] = num self.rec = l.copy() # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod mod = 10**9 + 7 x, y = list(map(int, input().split())) if (x + y) % 3 != 0: print((0)) exit() if y < x/2 or 2*x < y: print((0)) exit() n = (x + y) // 3 r = x - n c = Combination(n, mod) print((c.comb(n, r)))
class Factorials: def __init__(self, n=10**6, mod=10**9 + 7): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) self.fac = [1] * (n+1) for i in range(2, n+1): self.fac[i] = self.fac[i-1] * i % mod # self.rec[i] ≡ 1 / i! (reciprocal:逆数) self.rec = [1] * (n+1) self.rec[n] = pow(self.fac[n], mod-2, mod) for i in range(n-1, 1, -1): self.rec[i] = self.rec[i+1] * (i+1) % mod # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod x, y = list(map(int, input().split())) if (x + y) % 3 != 0: print((0)) exit() if y < x/2 or 2*x < y: print((0)) exit() n = (x + y) // 3 r = x - n c = Factorials(n) print((c.comb(n, r)))
41
32
926
809
class Combination: def __init__(self, n, mod): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) l = [1] num = 1 for i in range(1, n + 1): num *= i num %= mod l.append(num) self.fac = l.copy() # self.rec[i] ≡ 1 / i! (reciprocal:逆数) num = pow(num, mod - 2, mod) l = [1 for i in range(n + 1)] l[n] = num for i in range(n - 1, 0, -1): num *= i + 1 num %= mod l[i] = num self.rec = l.copy() # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod mod = 10**9 + 7 x, y = list(map(int, input().split())) if (x + y) % 3 != 0: print((0)) exit() if y < x / 2 or 2 * x < y: print((0)) exit() n = (x + y) // 3 r = x - n c = Combination(n, mod) print((c.comb(n, r)))
class Factorials: def __init__(self, n=10**6, mod=10**9 + 7): self.mod = mod # self.fac[i] ≡ i! (factorial:階乗) self.fac = [1] * (n + 1) for i in range(2, n + 1): self.fac[i] = self.fac[i - 1] * i % mod # self.rec[i] ≡ 1 / i! (reciprocal:逆数) self.rec = [1] * (n + 1) self.rec[n] = pow(self.fac[n], mod - 2, mod) for i in range(n - 1, 1, -1): self.rec[i] = self.rec[i + 1] * (i + 1) % mod # comb(n, r) ≡ nCr def comb(self, n, r): return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod x, y = list(map(int, input().split())) if (x + y) % 3 != 0: print((0)) exit() if y < x / 2 or 2 * x < y: print((0)) exit() n = (x + y) // 3 r = x - n c = Factorials(n) print((c.comb(n, r)))
false
21.95122
[ "-class Combination:", "- def __init__(self, n, mod):", "+class Factorials:", "+ def __init__(self, n=10**6, mod=10**9 + 7):", "- l = [1]", "- num = 1", "- for i in range(1, n + 1):", "- num *= i", "- num %= mod", "- l.append(num)", "- self.fac = l.copy()", "+ self.fac = [1] * (n + 1)", "+ for i in range(2, n + 1):", "+ self.fac[i] = self.fac[i - 1] * i % mod", "- num = pow(num, mod - 2, mod)", "- l = [1 for i in range(n + 1)]", "- l[n] = num", "- for i in range(n - 1, 0, -1):", "- num *= i + 1", "- num %= mod", "- l[i] = num", "- self.rec = l.copy()", "+ self.rec = [1] * (n + 1)", "+ self.rec[n] = pow(self.fac[n], mod - 2, mod)", "+ for i in range(n - 1, 1, -1):", "+ self.rec[i] = self.rec[i + 1] * (i + 1) % mod", "-mod = 10**9 + 7", "-c = Combination(n, mod)", "+c = Factorials(n)" ]
false
0.705528
0.199894
3.529522
[ "s531478992", "s582279381" ]
u133936772
p03401
python
s244659560
s051035267
280
212
14,048
14,048
Accepted
Accepted
24.29
n=int(eval(input())) l=[0]+list(map(int,input().split()))+[0] s=sum(abs(l[i+1]-l[i]) for i in range(n+1)) for i in range(n): a,b,c=l[i:i+3] print((s-min(abs(b-c),abs(b-a))*2*(max(a,c)<b or min(a,c)>b)))
n=int(eval(input())) l=[0]+list(map(int,input().split()))+[0] s=sum(abs(l[i+1]-l[i]) for i in range(n+1)) for i in range(n): a,b,c=l[i:i+3] print((s-abs(b-a)-abs(c-b)+abs(c-a)))
6
6
203
178
n = int(eval(input())) l = [0] + list(map(int, input().split())) + [0] s = sum(abs(l[i + 1] - l[i]) for i in range(n + 1)) for i in range(n): a, b, c = l[i : i + 3] print((s - min(abs(b - c), abs(b - a)) * 2 * (max(a, c) < b or min(a, c) > b)))
n = int(eval(input())) l = [0] + list(map(int, input().split())) + [0] s = sum(abs(l[i + 1] - l[i]) for i in range(n + 1)) for i in range(n): a, b, c = l[i : i + 3] print((s - abs(b - a) - abs(c - b) + abs(c - a)))
false
0
[ "- print((s - min(abs(b - c), abs(b - a)) * 2 * (max(a, c) < b or min(a, c) > b)))", "+ print((s - abs(b - a) - abs(c - b) + abs(c - a)))" ]
false
0.08027
0.040016
2.005937
[ "s244659560", "s051035267" ]
u197300773
p03317
python
s308119304
s494816618
40
17
13,812
3,060
Accepted
Accepted
57.5
import math N,K=list(map(int,input().split())) a=list(map(int,input().split())) ans=math.ceil( (N-K)/(K-1) ) +1 print(ans)
import math N,K=list(map(int,input().split())) print((math.ceil( (N-K)/(K-1) ) +1))
7
3
124
77
import math N, K = list(map(int, input().split())) a = list(map(int, input().split())) ans = math.ceil((N - K) / (K - 1)) + 1 print(ans)
import math N, K = list(map(int, input().split())) print((math.ceil((N - K) / (K - 1)) + 1))
false
57.142857
[ "-a = list(map(int, input().split()))", "-ans = math.ceil((N - K) / (K - 1)) + 1", "-print(ans)", "+print((math.ceil((N - K) / (K - 1)) + 1))" ]
false
0.043378
0.039659
1.093777
[ "s308119304", "s494816618" ]
u802963389
p03145
python
s155216229
s533531009
19
17
2,940
2,940
Accepted
Accepted
10.53
a, b, c = list(map(int, input().split())) print((int(a*b/2)))
a, b, c = list(map(int, input().split())) ans = a * b // 2 print(ans)
2
3
54
66
a, b, c = list(map(int, input().split())) print((int(a * b / 2)))
a, b, c = list(map(int, input().split())) ans = a * b // 2 print(ans)
false
33.333333
[ "-print((int(a * b / 2)))", "+ans = a * b // 2", "+print(ans)" ]
false
0.007748
0.044064
0.175842
[ "s155216229", "s533531009" ]
u799428010
p02627
python
s588547650
s748386513
47
27
9,076
8,904
Accepted
Accepted
42.55
a=eval(input()) if a in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': print('A') else: print('a')
x=str(eval(input())) X=x.islower() if X: print('a') else: print('A')
5
6
88
75
a = eval(input()) if a in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": print("A") else: print("a")
x = str(eval(input())) X = x.islower() if X: print("a") else: print("A")
false
16.666667
[ "-a = eval(input())", "-if a in \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\":", "+x = str(eval(input()))", "+X = x.islower()", "+if X:", "+ print(\"a\")", "+else:", "-else:", "- print(\"a\")" ]
false
0.048017
0.037417
1.283302
[ "s588547650", "s748386513" ]
u735335967
p02748
python
s533891095
s269249516
475
423
38,568
18,612
Accepted
Accepted
10.95
a,b,m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) xyc = [list(map(int,input().split())) for _ in range(m)] yes_m = a[xyc[0][0]-1]+b[xyc[0][1]-1] - xyc[0][2] for i in range(1,m): if yes_m > a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]: yes_m = a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2] no_m = min(a)+min(b) print((min(no_m,yes_m)))
a,b,m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = min(a)+min(b) for i in range(m): x,y,c = list(map(int, input().split())) ans = min(ans, a[x-1]+b[y-1]-c) print(ans)
15
10
413
241
a, b, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) xyc = [list(map(int, input().split())) for _ in range(m)] yes_m = a[xyc[0][0] - 1] + b[xyc[0][1] - 1] - xyc[0][2] for i in range(1, m): if yes_m > a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2]: yes_m = a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2] no_m = min(a) + min(b) print((min(no_m, yes_m)))
a, b, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = min(a) + min(b) for i in range(m): x, y, c = list(map(int, input().split())) ans = min(ans, a[x - 1] + b[y - 1] - c) print(ans)
false
33.333333
[ "-xyc = [list(map(int, input().split())) for _ in range(m)]", "-yes_m = a[xyc[0][0] - 1] + b[xyc[0][1] - 1] - xyc[0][2]", "-for i in range(1, m):", "- if yes_m > a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2]:", "- yes_m = a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2]", "-no_m = min(a) + min(b)", "-print((min(no_m, yes_m)))", "+ans = min(a) + min(b)", "+for i in range(m):", "+ x, y, c = list(map(int, input().split()))", "+ ans = min(ans, a[x - 1] + b[y - 1] - c)", "+print(ans)" ]
false
0.04405
0.044593
0.987826
[ "s533891095", "s269249516" ]
u628707847
p02706
python
s247476621
s876416416
24
22
9,932
10,060
Accepted
Accepted
8.33
n,m = list(map(int,input().split())) a = list(map(int,input().split())) if sum(a)>n: print('-1') else: print((n-sum(a)))
n,m = list(map(int,input().split())) a = list(map(int,input().split())) print(('-1' if sum(a)>n else n-sum(a)))
6
3
122
105
n, m = list(map(int, input().split())) a = list(map(int, input().split())) if sum(a) > n: print("-1") else: print((n - sum(a)))
n, m = list(map(int, input().split())) a = list(map(int, input().split())) print(("-1" if sum(a) > n else n - sum(a)))
false
50
[ "-if sum(a) > n:", "- print(\"-1\")", "-else:", "- print((n - sum(a)))", "+print((\"-1\" if sum(a) > n else n - sum(a)))" ]
false
0.047862
0.042044
1.138383
[ "s247476621", "s876416416" ]
u581187895
p02686
python
s308802342
s722782323
1,484
660
80,332
80,172
Accepted
Accepted
55.53
def resolve(): def check(arr): height = 0 for b, h in arr: if height+b < 0: return False height += h return True N = int(eval(input())) plus = [] minus = [] total = 0 for _ in range(N): # 1つのパーツを処理 S = eval(input()) cum = 0 # 累積和(最高地点) bottom = 0 # 最下地点 for s in S: if s == "(": cum += 1 else: cum -= 1 bottom = min(bottom, cum) total += cum if cum > 0: plus.append((bottom, cum)) else: minus.append((bottom-cum, -cum)) plus.sort(reverse=True) minus.sort(reverse=True) if check(plus) and check(minus) and total == 0: print("Yes") else: print("No") if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read inp = sys.stdin.buffer.readline def inpS(): return inp().rstrip().decode() def resolve(): def check(arr): height = 0 for b, h in arr: if height+b < 0: return False height += h return True N = int(inp()) plus = [] minus = [] total = 0 for _ in range(N): # 1つのパーツを処理 S = inpS() cum = 0 # 累積和(最高地点) bottom = 0 # 最下地点 for s in S: if s == "(": cum += 1 else: cum -= 1 bottom = min(bottom, cum) total += cum if cum > 0: plus.append((bottom, cum)) else: minus.append((bottom-cum, -cum)) plus.sort(reverse=True) minus.sort(reverse=True) if check(plus) and check(minus) and total == 0: print("Yes") else: print("No") if __name__ == "__main__": resolve()
42
47
900
1,053
def resolve(): def check(arr): height = 0 for b, h in arr: if height + b < 0: return False height += h return True N = int(eval(input())) plus = [] minus = [] total = 0 for _ in range(N): # 1つのパーツを処理 S = eval(input()) cum = 0 # 累積和(最高地点) bottom = 0 # 最下地点 for s in S: if s == "(": cum += 1 else: cum -= 1 bottom = min(bottom, cum) total += cum if cum > 0: plus.append((bottom, cum)) else: minus.append((bottom - cum, -cum)) plus.sort(reverse=True) minus.sort(reverse=True) if check(plus) and check(minus) and total == 0: print("Yes") else: print("No") if __name__ == "__main__": resolve()
import sys sys.setrecursionlimit(10**7) read = sys.stdin.buffer.read inp = sys.stdin.buffer.readline def inpS(): return inp().rstrip().decode() def resolve(): def check(arr): height = 0 for b, h in arr: if height + b < 0: return False height += h return True N = int(inp()) plus = [] minus = [] total = 0 for _ in range(N): # 1つのパーツを処理 S = inpS() cum = 0 # 累積和(最高地点) bottom = 0 # 最下地点 for s in S: if s == "(": cum += 1 else: cum -= 1 bottom = min(bottom, cum) total += cum if cum > 0: plus.append((bottom, cum)) else: minus.append((bottom - cum, -cum)) plus.sort(reverse=True) minus.sort(reverse=True) if check(plus) and check(minus) and total == 0: print("Yes") else: print("No") if __name__ == "__main__": resolve()
false
10.638298
[ "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+read = sys.stdin.buffer.read", "+inp = sys.stdin.buffer.readline", "+", "+", "+def inpS():", "+ return inp().rstrip().decode()", "+", "+", "- N = int(eval(input()))", "+ N = int(inp())", "- S = eval(input())", "+ S = inpS()", "- bottom = min(bottom, cum)", "+ bottom = min(bottom, cum)" ]
false
0.043116
0.078803
0.547141
[ "s308802342", "s722782323" ]
u525065967
p02555
python
s437661377
s630483252
32
29
9,064
9,232
Accepted
Accepted
9.38
s = int(eval(input())) MOD = 10**9 + 7 b3 = 1; b2 = 0; now = 0 # now == b1 for _ in range(s-2): b1 = now now = (b1 + b3) % MOD b3, b2 = b2, b1 print(now)
# nCr(n, r, m): 組合せ # nHr(n, r, m): 重複組合せ MOD = 10**9 + 7 fac = [1,1] # 階乗 n! inv = [0,1] # 逆元 1/n finv = [1,1] # 逆元の階乗 (n^-1)! = (1/n)! def finv_init(n, m): for i in range(2, n+1): fac.append( (fac[-1] * i ) % m ) inv.append( (-inv[m%i] * (m//i)) % m ) finv.append( (finv[-1] * inv[-1]) % m ) def nCr(n, r, m): if (n<0 or r<0 or n<r): return 0 r = min(r, n-r) return fac[n] * finv[n-r] * finv[r] % m def nHr(n, r, m): return nCr(n+r-1, r, m) s = int(eval(input())) finv_init(s, MOD) # 初期設定 ans = 0 for n in range(1, s+1): if s < 3*n: continue ans += nHr(n, s - 3*n, MOD) print((ans % MOD))
8
27
167
661
s = int(eval(input())) MOD = 10**9 + 7 b3 = 1 b2 = 0 now = 0 # now == b1 for _ in range(s - 2): b1 = now now = (b1 + b3) % MOD b3, b2 = b2, b1 print(now)
# nCr(n, r, m): 組合せ # nHr(n, r, m): 重複組合せ MOD = 10**9 + 7 fac = [1, 1] # 階乗 n! inv = [0, 1] # 逆元 1/n finv = [1, 1] # 逆元の階乗 (n^-1)! = (1/n)! def finv_init(n, m): for i in range(2, n + 1): fac.append((fac[-1] * i) % m) inv.append((-inv[m % i] * (m // i)) % m) finv.append((finv[-1] * inv[-1]) % m) def nCr(n, r, m): if n < 0 or r < 0 or n < r: return 0 r = min(r, n - r) return fac[n] * finv[n - r] * finv[r] % m def nHr(n, r, m): return nCr(n + r - 1, r, m) s = int(eval(input())) finv_init(s, MOD) # 初期設定 ans = 0 for n in range(1, s + 1): if s < 3 * n: continue ans += nHr(n, s - 3 * n, MOD) print((ans % MOD))
false
70.37037
[ "+# nCr(n, r, m): 組合せ", "+# nHr(n, r, m): 重複組合せ", "+MOD = 10**9 + 7", "+fac = [1, 1] # 階乗 n!", "+inv = [0, 1] # 逆元 1/n", "+finv = [1, 1] # 逆元の階乗 (n^-1)! = (1/n)!", "+", "+", "+def finv_init(n, m):", "+ for i in range(2, n + 1):", "+ fac.append((fac[-1] * i) % m)", "+ inv.append((-inv[m % i] * (m // i)) % m)", "+ finv.append((finv[-1] * inv[-1]) % m)", "+", "+", "+def nCr(n, r, m):", "+ if n < 0 or r < 0 or n < r:", "+ return 0", "+ r = min(r, n - r)", "+ return fac[n] * finv[n - r] * finv[r] % m", "+", "+", "+def nHr(n, r, m):", "+ return nCr(n + r - 1, r, m)", "+", "+", "-MOD = 10**9 + 7", "-b3 = 1", "-b2 = 0", "-now = 0 # now == b1", "-for _ in range(s - 2):", "- b1 = now", "- now = (b1 + b3) % MOD", "- b3, b2 = b2, b1", "-print(now)", "+finv_init(s, MOD) # 初期設定", "+ans = 0", "+for n in range(1, s + 1):", "+ if s < 3 * n:", "+ continue", "+ ans += nHr(n, s - 3 * n, MOD)", "+print((ans % MOD))" ]
false
0.115967
0.045022
2.575813
[ "s437661377", "s630483252" ]
u775681539
p02614
python
s383312915
s486985792
156
112
72,228
75,376
Accepted
Accepted
28.21
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def contBlack(g, h, w): cnt = 0 for i in range(h): for j in range(w): if g[i][j] == '#': cnt += 1 return cnt def turnrow(g, a, w): for j in range(w): g[a][j] = 'R' def turnclumn(g, a, h): for i in range(h): g[i][a] = 'R' from copy import deepcopy def main(): H, W, K = list(map(int, readline().split())) grid = [] for _ in range(H): grid.append(list(eval(input()))) cnt = 0 for i in range(1<<H): G = deepcopy(grid) for j in range(H): if (i>>j) & 1: turnrow(G, j, W) for k in range(1<<W): Gg = deepcopy(G) for l in range(W): if (k>>l) & 1: turnclumn(Gg, l, H) # for i in range(H): # print(Gg[i]) # print() if contBlack(Gg, H, W) == K: cnt += 1 print(cnt) if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines ans = 0 def main(): H, W, K = list(map(int, readline().split())) grid = [] for _ in range(H): grid.append(list(eval(input()))) #再帰関数で二組の全bit探索を組む #リストをコピーしない方法 bitr = [0 for _ in range(H)] bitc = [0 for _ in range(W)] def dfsr(i): if i == H: dfsc(0) return dfsr(i+1) bitr[i] = 1 dfsr(i+1) bitr[i] = 0 def dfsc(i): global ans cnt = 0 if i == W: #ここで処理をおこなう for j in range(H): #1が立っているならその行は全て赤とするので飛ばす if bitr[j] == 1: continue for k in range(W): #1が立っているならその列は全て赤とするので飛ばす if bitc[k] == 1: continue #飛ばされなかったマスのうち黒の数を数える if grid[j][k] == '#': cnt += 1 if cnt == K: ans += 1 return dfsc(i+1) bitc[i] = 1 dfsc(i+1) bitc[i] = 0 dfsr(0) print(ans) if __name__ == '__main__': main()
54
54
1,168
1,299
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def contBlack(g, h, w): cnt = 0 for i in range(h): for j in range(w): if g[i][j] == "#": cnt += 1 return cnt def turnrow(g, a, w): for j in range(w): g[a][j] = "R" def turnclumn(g, a, h): for i in range(h): g[i][a] = "R" from copy import deepcopy def main(): H, W, K = list(map(int, readline().split())) grid = [] for _ in range(H): grid.append(list(eval(input()))) cnt = 0 for i in range(1 << H): G = deepcopy(grid) for j in range(H): if (i >> j) & 1: turnrow(G, j, W) for k in range(1 << W): Gg = deepcopy(G) for l in range(W): if (k >> l) & 1: turnclumn(Gg, l, H) # for i in range(H): # print(Gg[i]) # print() if contBlack(Gg, H, W) == K: cnt += 1 print(cnt) if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines ans = 0 def main(): H, W, K = list(map(int, readline().split())) grid = [] for _ in range(H): grid.append(list(eval(input()))) # 再帰関数で二組の全bit探索を組む # リストをコピーしない方法 bitr = [0 for _ in range(H)] bitc = [0 for _ in range(W)] def dfsr(i): if i == H: dfsc(0) return dfsr(i + 1) bitr[i] = 1 dfsr(i + 1) bitr[i] = 0 def dfsc(i): global ans cnt = 0 if i == W: # ここで処理をおこなう for j in range(H): # 1が立っているならその行は全て赤とするので飛ばす if bitr[j] == 1: continue for k in range(W): # 1が立っているならその列は全て赤とするので飛ばす if bitc[k] == 1: continue # 飛ばされなかったマスのうち黒の数を数える if grid[j][k] == "#": cnt += 1 if cnt == K: ans += 1 return dfsc(i + 1) bitc[i] = 1 dfsc(i + 1) bitc[i] = 0 dfsr(0) print(ans) if __name__ == "__main__": main()
false
0
[ "-", "-", "-def contBlack(g, h, w):", "- cnt = 0", "- for i in range(h):", "- for j in range(w):", "- if g[i][j] == \"#\":", "- cnt += 1", "- return cnt", "-", "-", "-def turnrow(g, a, w):", "- for j in range(w):", "- g[a][j] = \"R\"", "-", "-", "-def turnclumn(g, a, h):", "- for i in range(h):", "- g[i][a] = \"R\"", "-", "-", "-from copy import deepcopy", "+ans = 0", "- cnt = 0", "- for i in range(1 << H):", "- G = deepcopy(grid)", "- for j in range(H):", "- if (i >> j) & 1:", "- turnrow(G, j, W)", "- for k in range(1 << W):", "- Gg = deepcopy(G)", "- for l in range(W):", "- if (k >> l) & 1:", "- turnclumn(Gg, l, H)", "- # for i in range(H):", "- # print(Gg[i])", "- # print()", "- if contBlack(Gg, H, W) == K:", "- cnt += 1", "- print(cnt)", "+ # 再帰関数で二組の全bit探索を組む", "+ # リストをコピーしない方法", "+ bitr = [0 for _ in range(H)]", "+ bitc = [0 for _ in range(W)]", "+", "+ def dfsr(i):", "+ if i == H:", "+ dfsc(0)", "+ return", "+ dfsr(i + 1)", "+ bitr[i] = 1", "+ dfsr(i + 1)", "+ bitr[i] = 0", "+", "+ def dfsc(i):", "+ global ans", "+ cnt = 0", "+ if i == W:", "+ # ここで処理をおこなう", "+ for j in range(H):", "+ # 1が立っているならその行は全て赤とするので飛ばす", "+ if bitr[j] == 1:", "+ continue", "+ for k in range(W):", "+ # 1が立っているならその列は全て赤とするので飛ばす", "+ if bitc[k] == 1:", "+ continue", "+ # 飛ばされなかったマスのうち黒の数を数える", "+ if grid[j][k] == \"#\":", "+ cnt += 1", "+ if cnt == K:", "+ ans += 1", "+ return", "+ dfsc(i + 1)", "+ bitc[i] = 1", "+ dfsc(i + 1)", "+ bitc[i] = 0", "+", "+ dfsr(0)", "+ print(ans)" ]
false
0.051697
0.039223
1.318008
[ "s383312915", "s486985792" ]
u514401521
p03286
python
s760687290
s118562549
20
17
3,188
3,060
Accepted
Accepted
15
n = int(eval(input())) st = "" while n != 0: r = n % 2 if r < 0: r += 2 n = int((n - r) / (-2)) st += str(r) st = st[::-1] if st == "": st = "0" print(st)
n = int(eval(input())) ans = "" while n != 0: r = n % (-2) if r < 0: r += 2 n = int((n - r) / (-2)) ans += str(r) if ans == "": print((0)) else: print((ans[::-1]))
15
12
193
196
n = int(eval(input())) st = "" while n != 0: r = n % 2 if r < 0: r += 2 n = int((n - r) / (-2)) st += str(r) st = st[::-1] if st == "": st = "0" print(st)
n = int(eval(input())) ans = "" while n != 0: r = n % (-2) if r < 0: r += 2 n = int((n - r) / (-2)) ans += str(r) if ans == "": print((0)) else: print((ans[::-1]))
false
20
[ "-st = \"\"", "+ans = \"\"", "- r = n % 2", "+ r = n % (-2)", "- st += str(r)", "-st = st[::-1]", "-if st == \"\":", "- st = \"0\"", "-print(st)", "+ ans += str(r)", "+if ans == \"\":", "+ print((0))", "+else:", "+ print((ans[::-1]))" ]
false
0.009157
0.04022
0.227675
[ "s760687290", "s118562549" ]
u775681539
p02996
python
s755290752
s230128286
1,205
554
75,352
61,904
Accepted
Accepted
54.02
#python3 from operator import itemgetter from itertools import accumulate def main(): n = int(eval(input())) d = [] for _ in range(n): x, y = list(map(int, input().split())) d.append((x, y)) d.sort(key=itemgetter(1)) acc = 0 f = True for i in range(n): acc = acc+d[i][0] if acc > d[i][1]: f = False if f: print('Yes') else: print('No') main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter def main(): N = int(readline()) tasks = [] for _ in range(N): a, b = list(map(int, readline().split())) tasks.append((a, b)) tasks.sort(key=itemgetter(1)) time = 0 for a, b in tasks: time += a if time > b: print('No') return print('Yes') if __name__ == '__main__': main()
21
22
449
527
# python3 from operator import itemgetter from itertools import accumulate def main(): n = int(eval(input())) d = [] for _ in range(n): x, y = list(map(int, input().split())) d.append((x, y)) d.sort(key=itemgetter(1)) acc = 0 f = True for i in range(n): acc = acc + d[i][0] if acc > d[i][1]: f = False if f: print("Yes") else: print("No") main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter def main(): N = int(readline()) tasks = [] for _ in range(N): a, b = list(map(int, readline().split())) tasks.append((a, b)) tasks.sort(key=itemgetter(1)) time = 0 for a, b in tasks: time += a if time > b: print("No") return print("Yes") if __name__ == "__main__": main()
false
4.545455
[ "-# python3", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "-from itertools import accumulate", "- n = int(eval(input()))", "- d = []", "- for _ in range(n):", "- x, y = list(map(int, input().split()))", "- d.append((x, y))", "- d.sort(key=itemgetter(1))", "- acc = 0", "- f = True", "- for i in range(n):", "- acc = acc + d[i][0]", "- if acc > d[i][1]:", "- f = False", "- if f:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+ N = int(readline())", "+ tasks = []", "+ for _ in range(N):", "+ a, b = list(map(int, readline().split()))", "+ tasks.append((a, b))", "+ tasks.sort(key=itemgetter(1))", "+ time = 0", "+ for a, b in tasks:", "+ time += a", "+ if time > b:", "+ print(\"No\")", "+ return", "+ print(\"Yes\")", "-main()", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045658
0.045674
0.999637
[ "s755290752", "s230128286" ]
u762420987
p03408
python
s320484974
s590742933
27
21
3,564
3,316
Accepted
Accepted
22.22
from collections import Counter N = int(eval(input())) scounter = Counter([eval(input()) for _ in range(N)]) M = int(eval(input())) tcounter = Counter([eval(input()) for _ in range(M)]) nums = [] for s in list(scounter.keys()): nums.append(scounter[s] - tcounter[s]) max_num = max(nums) print((max_num if max_num > 0 else 0))
from collections import Counter N = int(eval(input())) sc = Counter([eval(input()) for _ in range(N)]) M = int(eval(input())) tc = Counter([eval(input()) for _ in range(M)]) ans = 0 for s in sc.most_common(): k, v = s ans = max(ans, v - tc[k]) print(ans)
12
12
311
252
from collections import Counter N = int(eval(input())) scounter = Counter([eval(input()) for _ in range(N)]) M = int(eval(input())) tcounter = Counter([eval(input()) for _ in range(M)]) nums = [] for s in list(scounter.keys()): nums.append(scounter[s] - tcounter[s]) max_num = max(nums) print((max_num if max_num > 0 else 0))
from collections import Counter N = int(eval(input())) sc = Counter([eval(input()) for _ in range(N)]) M = int(eval(input())) tc = Counter([eval(input()) for _ in range(M)]) ans = 0 for s in sc.most_common(): k, v = s ans = max(ans, v - tc[k]) print(ans)
false
0
[ "-scounter = Counter([eval(input()) for _ in range(N)])", "+sc = Counter([eval(input()) for _ in range(N)])", "-tcounter = Counter([eval(input()) for _ in range(M)])", "-nums = []", "-for s in list(scounter.keys()):", "- nums.append(scounter[s] - tcounter[s])", "-max_num = max(nums)", "-print((max_num if max_num > 0 else 0))", "+tc = Counter([eval(input()) for _ in range(M)])", "+ans = 0", "+for s in sc.most_common():", "+ k, v = s", "+ ans = max(ans, v - tc[k])", "+print(ans)" ]
false
0.088568
0.080058
1.106299
[ "s320484974", "s590742933" ]
u133936772
p02860
python
s020655868
s915226182
19
17
3,060
2,940
Accepted
Accepted
10.53
n = int(eval(input())) s = eval(input()) if n % 2 == 0 and s[:n//2] == s[n//2:]: print('Yes') else: print('No')
n = int(eval(input())) s = eval(input()) print(('Yes' if s[:n//2] == s[n//2:] else 'No'))
7
4
110
79
n = int(eval(input())) s = eval(input()) if n % 2 == 0 and s[: n // 2] == s[n // 2 :]: print("Yes") else: print("No")
n = int(eval(input())) s = eval(input()) print(("Yes" if s[: n // 2] == s[n // 2 :] else "No"))
false
42.857143
[ "-if n % 2 == 0 and s[: n // 2] == s[n // 2 :]:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+print((\"Yes\" if s[: n // 2] == s[n // 2 :] else \"No\"))" ]
false
0.043403
0.042708
1.016272
[ "s020655868", "s915226182" ]
u102461423
p03166
python
s516450691
s173317603
622
394
106,648
42,488
Accepted
Accepted
36.66
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N,M = list(map(int,input().split())) graph = [[] for _ in range(N+1)] for _ in range(M): x,y = list(map(int,input().split())) graph[x].append(y) dp = [None] * (N+1) def dfs(x): if dp[x] is not None: return dp[x] if graph[x]: dp[x] = 1 + max(dfs(y) for y in graph[x]) else: dp[x] = 0 return dp[x] answer = max(dfs(x) for x in range(1,N+1)) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,M = list(map(int,readline().split())) m = list(map(int,read().split())) XY = list(zip(m,m)) in_edge = [[] for _ in range(N+1)] out_edge = [[] for _ in range(N+1)] for x,y in XY: out_edge[x].append(y) in_edge[y].append(x) out_deg = [len(x) for x in out_edge] stack = [i for i,x in enumerate(out_deg[1:],1) if x==0] dp = [0] * (N+1) while stack: c = stack.pop() for p in in_edge[c]: y = dp[c]+1 if dp[p] < y: dp[p] = y out_deg[p] -= 1 if not out_deg[p]: stack.append(p) answer = max(dp) print(answer)
24
32
485
707
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N, M = list(map(int, input().split())) graph = [[] for _ in range(N + 1)] for _ in range(M): x, y = list(map(int, input().split())) graph[x].append(y) dp = [None] * (N + 1) def dfs(x): if dp[x] is not None: return dp[x] if graph[x]: dp[x] = 1 + max(dfs(y) for y in graph[x]) else: dp[x] = 0 return dp[x] answer = max(dfs(x) for x in range(1, N + 1)) print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, M = list(map(int, readline().split())) m = list(map(int, read().split())) XY = list(zip(m, m)) in_edge = [[] for _ in range(N + 1)] out_edge = [[] for _ in range(N + 1)] for x, y in XY: out_edge[x].append(y) in_edge[y].append(x) out_deg = [len(x) for x in out_edge] stack = [i for i, x in enumerate(out_deg[1:], 1) if x == 0] dp = [0] * (N + 1) while stack: c = stack.pop() for p in in_edge[c]: y = dp[c] + 1 if dp[p] < y: dp[p] = y out_deg[p] -= 1 if not out_deg[p]: stack.append(p) answer = max(dp) print(answer)
false
25
[ "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-N, M = list(map(int, input().split()))", "-graph = [[] for _ in range(N + 1)]", "-for _ in range(M):", "- x, y = list(map(int, input().split()))", "- graph[x].append(y)", "-dp = [None] * (N + 1)", "-", "-", "-def dfs(x):", "- if dp[x] is not None:", "- return dp[x]", "- if graph[x]:", "- dp[x] = 1 + max(dfs(y) for y in graph[x])", "- else:", "- dp[x] = 0", "- return dp[x]", "-", "-", "-answer = max(dfs(x) for x in range(1, N + 1))", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N, M = list(map(int, readline().split()))", "+m = list(map(int, read().split()))", "+XY = list(zip(m, m))", "+in_edge = [[] for _ in range(N + 1)]", "+out_edge = [[] for _ in range(N + 1)]", "+for x, y in XY:", "+ out_edge[x].append(y)", "+ in_edge[y].append(x)", "+out_deg = [len(x) for x in out_edge]", "+stack = [i for i, x in enumerate(out_deg[1:], 1) if x == 0]", "+dp = [0] * (N + 1)", "+while stack:", "+ c = stack.pop()", "+ for p in in_edge[c]:", "+ y = dp[c] + 1", "+ if dp[p] < y:", "+ dp[p] = y", "+ out_deg[p] -= 1", "+ if not out_deg[p]:", "+ stack.append(p)", "+answer = max(dp)" ]
false
0.078603
0.0364
2.159388
[ "s516450691", "s173317603" ]
u538276565
p02889
python
s704941539
s819070196
815
575
17,628
20,252
Accepted
Accepted
29.45
from scipy.sparse.csgraph import floyd_warshall import numpy as np N, M, L = map(int, input().split()) graph = np.full((N, N), 10 ** 10) for _ in range(M): s, t, w = map(int, input().split()) if w <= L: graph[s - 1][t - 1] = graph[t - 1][s - 1] = w graph = floyd_warshall(graph, directed=False) graph = floyd_warshall(graph <= L, directed=False) graph[np.isinf(graph)] = 0 Q = int(input()) ans = [] for _ in range(Q): s, t = map(int, input().split()) ans.append(int(graph[s - 1][t - 1]) - 1) print(*ans, sep='\n')
def use_fast_io(): global input import io import sys f = io.BytesIO(sys.stdin.buffer.read()) input = f.readline use_fast_io() from scipy.sparse.csgraph import floyd_warshall import numpy as np N, M, L = map(int, input().split()) graph = np.full((N, N), 10**10) for _ in range(M): s, t, w = map(int, input().split()) if w <= L: graph[s-1][t-1] = graph[t-1][s-1] = w graph = floyd_warshall(graph, directed=False) graph = floyd_warshall(graph <= L, directed=False) graph[np.isinf(graph)] = 0 Q = int(input()) ans = [] for _ in range(Q): s, t = map(int, input().split()) ans.append(int(graph[s-1][t-1]) - 1) print(*ans, sep='\n')
20
28
559
704
from scipy.sparse.csgraph import floyd_warshall import numpy as np N, M, L = map(int, input().split()) graph = np.full((N, N), 10**10) for _ in range(M): s, t, w = map(int, input().split()) if w <= L: graph[s - 1][t - 1] = graph[t - 1][s - 1] = w graph = floyd_warshall(graph, directed=False) graph = floyd_warshall(graph <= L, directed=False) graph[np.isinf(graph)] = 0 Q = int(input()) ans = [] for _ in range(Q): s, t = map(int, input().split()) ans.append(int(graph[s - 1][t - 1]) - 1) print(*ans, sep="\n")
def use_fast_io(): global input import io import sys f = io.BytesIO(sys.stdin.buffer.read()) input = f.readline use_fast_io() from scipy.sparse.csgraph import floyd_warshall import numpy as np N, M, L = map(int, input().split()) graph = np.full((N, N), 10**10) for _ in range(M): s, t, w = map(int, input().split()) if w <= L: graph[s - 1][t - 1] = graph[t - 1][s - 1] = w graph = floyd_warshall(graph, directed=False) graph = floyd_warshall(graph <= L, directed=False) graph[np.isinf(graph)] = 0 Q = int(input()) ans = [] for _ in range(Q): s, t = map(int, input().split()) ans.append(int(graph[s - 1][t - 1]) - 1) print(*ans, sep="\n")
false
28.571429
[ "+def use_fast_io():", "+ global input", "+ import io", "+ import sys", "+", "+ f = io.BytesIO(sys.stdin.buffer.read())", "+ input = f.readline", "+", "+", "+use_fast_io()" ]
false
0.550582
0.945265
0.582462
[ "s704941539", "s819070196" ]
u729972685
p03163
python
s798543732
s226602663
437
281
59,144
41,580
Accepted
Accepted
35.7
# using dp with memoization, TLE from sys import stdin N, W = list(map(int, input().split())) m = stdin.read().splitlines() s = [[int(i) for i in line.split()] for line in m] dp = [0] * (W + 1) next_dp = [0] * (W + 1) for n in range(1, N + 1): for w in range(0, W + 1): if w >= s[n - 1][0]: next_dp[w] = max(next_dp[w], dp[w - s[n - 1][0]] + s[n - 1][1]) dp = next_dp[:] print((dp[W]))
# using dp with memoization, TLE from sys import stdin N, W = list(map(int, input().split())) m = stdin.read().splitlines() s = [[int(i) for i in line.split()] for line in m] dp = [0] * (W + 1) for n in range(1, N + 1): w0, v0 = s[n - 1] for w in range(W, w0 - 1, -1): dp[w] = max(dp[w], dp[w - w0] + v0) print((dp[W]))
14
15
420
346
# using dp with memoization, TLE from sys import stdin N, W = list(map(int, input().split())) m = stdin.read().splitlines() s = [[int(i) for i in line.split()] for line in m] dp = [0] * (W + 1) next_dp = [0] * (W + 1) for n in range(1, N + 1): for w in range(0, W + 1): if w >= s[n - 1][0]: next_dp[w] = max(next_dp[w], dp[w - s[n - 1][0]] + s[n - 1][1]) dp = next_dp[:] print((dp[W]))
# using dp with memoization, TLE from sys import stdin N, W = list(map(int, input().split())) m = stdin.read().splitlines() s = [[int(i) for i in line.split()] for line in m] dp = [0] * (W + 1) for n in range(1, N + 1): w0, v0 = s[n - 1] for w in range(W, w0 - 1, -1): dp[w] = max(dp[w], dp[w - w0] + v0) print((dp[W]))
false
6.666667
[ "-next_dp = [0] * (W + 1)", "- for w in range(0, W + 1):", "- if w >= s[n - 1][0]:", "- next_dp[w] = max(next_dp[w], dp[w - s[n - 1][0]] + s[n - 1][1])", "- dp = next_dp[:]", "+ w0, v0 = s[n - 1]", "+ for w in range(W, w0 - 1, -1):", "+ dp[w] = max(dp[w], dp[w - w0] + v0)" ]
false
0.043058
0.042462
1.014029
[ "s798543732", "s226602663" ]
u963468276
p02818
python
s501776551
s048553929
186
171
38,384
38,384
Accepted
Accepted
8.06
A, B, K =list(map(int, input().split())) if K <= A: print((str(A - K) + ' ' + str(B))) elif K > A and B >= (K - A): print(('0 ' + str(B - (K - A)))) else: print('0 0')
A, B, K = list(map(int, input().split())) if K <= A: print(((A - K), B)) elif (K > A) and ((K - A) <= B ): print((0, (B - (K - A)))) else: print((0, 0))
10
9
186
162
A, B, K = list(map(int, input().split())) if K <= A: print((str(A - K) + " " + str(B))) elif K > A and B >= (K - A): print(("0 " + str(B - (K - A)))) else: print("0 0")
A, B, K = list(map(int, input().split())) if K <= A: print(((A - K), B)) elif (K > A) and ((K - A) <= B): print((0, (B - (K - A)))) else: print((0, 0))
false
10
[ "- print((str(A - K) + \" \" + str(B)))", "-elif K > A and B >= (K - A):", "- print((\"0 \" + str(B - (K - A))))", "+ print(((A - K), B))", "+elif (K > A) and ((K - A) <= B):", "+ print((0, (B - (K - A))))", "- print(\"0 0\")", "+ print((0, 0))" ]
false
0.102384
0.072995
1.402614
[ "s501776551", "s048553929" ]
u143492911
p03599
python
s627088221
s569485241
2,460
1,872
12,440
12,440
Accepted
Accepted
23.9
a,b,c,d,e,f=list(map(int,input().split()))#ć­Łč§Ł w=[] for i in range(f//100+1): for j in range(f//100+1): x=100*a*i+100*b*j if x<=f: w.append(x) s=[] for i in range(f): for j in range(f): y=i*c+j*d if y<=f: s.append(y) max_con=0 ans,ans_2=0,0 for i in w: for j in s: if i!=0 or j!=0: if j<=e*(i//100): if i+j<=f: con=(100*j)/(i+j) if max_con<=con: max_con=con ans,ans_2=i+j,j print((ans,ans_2))
a,b,c,d,e,f=list(map(int,input().split())) water=[] sugar=[] ans,ans_2,con=0,0,0 for i in range(f//100+1):#f//100+1によりTLEを解消 for j in range(f//100+1): x=100*a*i+100*j*b if x<=f: water.append(x) for i in range(f): for j in range(f): y=c*i+d*j if y<=f: sugar.append(y) sugar=list(set(sugar)) for i in water: for j in sugar: if i+j<=f: if i!=0 or j!=0: if j<=(i//100)*e: now=(100*j)/(i+j) if con<=now: ans=i+j ans_2=j con=now print((ans,ans_2))
25
26
604
675
a, b, c, d, e, f = list(map(int, input().split())) # ć­Łč§Ł w = [] for i in range(f // 100 + 1): for j in range(f // 100 + 1): x = 100 * a * i + 100 * b * j if x <= f: w.append(x) s = [] for i in range(f): for j in range(f): y = i * c + j * d if y <= f: s.append(y) max_con = 0 ans, ans_2 = 0, 0 for i in w: for j in s: if i != 0 or j != 0: if j <= e * (i // 100): if i + j <= f: con = (100 * j) / (i + j) if max_con <= con: max_con = con ans, ans_2 = i + j, j print((ans, ans_2))
a, b, c, d, e, f = list(map(int, input().split())) water = [] sugar = [] ans, ans_2, con = 0, 0, 0 for i in range(f // 100 + 1): # f//100+1によりTLEを解消 for j in range(f // 100 + 1): x = 100 * a * i + 100 * j * b if x <= f: water.append(x) for i in range(f): for j in range(f): y = c * i + d * j if y <= f: sugar.append(y) sugar = list(set(sugar)) for i in water: for j in sugar: if i + j <= f: if i != 0 or j != 0: if j <= (i // 100) * e: now = (100 * j) / (i + j) if con <= now: ans = i + j ans_2 = j con = now print((ans, ans_2))
false
3.846154
[ "-a, b, c, d, e, f = list(map(int, input().split())) # ć­Łč§Ł", "-w = []", "-for i in range(f // 100 + 1):", "+a, b, c, d, e, f = list(map(int, input().split()))", "+water = []", "+sugar = []", "+ans, ans_2, con = 0, 0, 0", "+for i in range(f // 100 + 1): # f//100+1によりTLEを解消", "- x = 100 * a * i + 100 * b * j", "+ x = 100 * a * i + 100 * j * b", "- w.append(x)", "-s = []", "+ water.append(x)", "- y = i * c + j * d", "+ y = c * i + d * j", "- s.append(y)", "-max_con = 0", "-ans, ans_2 = 0, 0", "-for i in w:", "- for j in s:", "- if i != 0 or j != 0:", "- if j <= e * (i // 100):", "- if i + j <= f:", "- con = (100 * j) / (i + j)", "- if max_con <= con:", "- max_con = con", "- ans, ans_2 = i + j, j", "+ sugar.append(y)", "+sugar = list(set(sugar))", "+for i in water:", "+ for j in sugar:", "+ if i + j <= f:", "+ if i != 0 or j != 0:", "+ if j <= (i // 100) * e:", "+ now = (100 * j) / (i + j)", "+ if con <= now:", "+ ans = i + j", "+ ans_2 = j", "+ con = now" ]
false
2.090336
1.098788
1.902401
[ "s627088221", "s569485241" ]
u339199690
p02954
python
s490688833
s688644920
155
111
7,088
10,652
Accepted
Accepted
28.39
import sys, heapq S = list(eval(input())) N = len(S) res = [0] * len(S) i = 0 while i < len(S): s = S[i] h = i cntR = 0 cntL = 0 while s == "R": i += 1 cntR += 1 s = S[i] tmp = i res[tmp] += cntR // 2 res[tmp - 1] += cntR // 2 + int(cntR % 2 == 1) while s == "L": i += 1 cntL += 1 if i < N: s = S[i] else: break res[tmp] += cntL // 2 + int(cntL % 2 == 1) res[tmp - 1] += cntL // 2 print((*res))
S = eval(input()) res = [0] * len(S) childlen = 0 for i in range(len(S)): if S[i] == "R": childlen += 1 else: tmp = (childlen + int(childlen % 2 == 1)) // 2 res[i - 1] += tmp res[i] += childlen - tmp # print(i, tmp, childlen, res[i - 1], res[i]) childlen = 0 for i in reversed(list(range(len(S)))): if S[i] == "L": childlen += 1 else: tmp = (childlen + int(childlen % 2 == 1)) // 2 res[i + 1] += tmp res[i] += childlen - tmp childlen = 0 print((*res))
31
24
544
567
import sys, heapq S = list(eval(input())) N = len(S) res = [0] * len(S) i = 0 while i < len(S): s = S[i] h = i cntR = 0 cntL = 0 while s == "R": i += 1 cntR += 1 s = S[i] tmp = i res[tmp] += cntR // 2 res[tmp - 1] += cntR // 2 + int(cntR % 2 == 1) while s == "L": i += 1 cntL += 1 if i < N: s = S[i] else: break res[tmp] += cntL // 2 + int(cntL % 2 == 1) res[tmp - 1] += cntL // 2 print((*res))
S = eval(input()) res = [0] * len(S) childlen = 0 for i in range(len(S)): if S[i] == "R": childlen += 1 else: tmp = (childlen + int(childlen % 2 == 1)) // 2 res[i - 1] += tmp res[i] += childlen - tmp # print(i, tmp, childlen, res[i - 1], res[i]) childlen = 0 for i in reversed(list(range(len(S)))): if S[i] == "L": childlen += 1 else: tmp = (childlen + int(childlen % 2 == 1)) // 2 res[i + 1] += tmp res[i] += childlen - tmp childlen = 0 print((*res))
false
22.580645
[ "-import sys, heapq", "-", "-S = list(eval(input()))", "-N = len(S)", "+S = eval(input())", "-i = 0", "-while i < len(S):", "- s = S[i]", "- h = i", "- cntR = 0", "- cntL = 0", "- while s == \"R\":", "- i += 1", "- cntR += 1", "- s = S[i]", "- tmp = i", "- res[tmp] += cntR // 2", "- res[tmp - 1] += cntR // 2 + int(cntR % 2 == 1)", "- while s == \"L\":", "- i += 1", "- cntL += 1", "- if i < N:", "- s = S[i]", "- else:", "- break", "- res[tmp] += cntL // 2 + int(cntL % 2 == 1)", "- res[tmp - 1] += cntL // 2", "+childlen = 0", "+for i in range(len(S)):", "+ if S[i] == \"R\":", "+ childlen += 1", "+ else:", "+ tmp = (childlen + int(childlen % 2 == 1)) // 2", "+ res[i - 1] += tmp", "+ res[i] += childlen - tmp", "+ # print(i, tmp, childlen, res[i - 1], res[i])", "+ childlen = 0", "+for i in reversed(list(range(len(S)))):", "+ if S[i] == \"L\":", "+ childlen += 1", "+ else:", "+ tmp = (childlen + int(childlen % 2 == 1)) // 2", "+ res[i + 1] += tmp", "+ res[i] += childlen - tmp", "+ childlen = 0" ]
false
0.070749
0.006942
10.192015
[ "s490688833", "s688644920" ]
u763380276
p02887
python
s556576221
s589576042
402
43
7,796
3,956
Accepted
Accepted
89.3
N=int(eval(input())) S=list(eval(input())) check=[] for i in range(N-1): if S[i]==S[i+1]: check.append(i) check=reversed(check) for i in check: S.pop(i) print((len(S)))
N=int(eval(input())) S=list(eval(input())) check=0 for i in range(N-1): if S[i]==S[i+1]: check+=1 print((len(S)-check))
10
8
171
119
N = int(eval(input())) S = list(eval(input())) check = [] for i in range(N - 1): if S[i] == S[i + 1]: check.append(i) check = reversed(check) for i in check: S.pop(i) print((len(S)))
N = int(eval(input())) S = list(eval(input())) check = 0 for i in range(N - 1): if S[i] == S[i + 1]: check += 1 print((len(S) - check))
false
20
[ "-check = []", "+check = 0", "- check.append(i)", "-check = reversed(check)", "-for i in check:", "- S.pop(i)", "-print((len(S)))", "+ check += 1", "+print((len(S) - check))" ]
false
0.034486
0.036226
0.951942
[ "s556576221", "s589576042" ]
u936401118
p02406
python
s835445003
s268921217
30
20
8,004
8,168
Accepted
Accepted
33.33
num = int(input()) for i in range(1,num + 1): x = str(i) if i % 3 == 0 or '3' in x: print (end = ' ') print (i, end = '') print()
num = int(input()) for i in range(1,num + 1): x = str(i) if i % 3 == 0 or '3' in x: print ('', i, end = '') print()
9
8
163
140
num = int(input()) for i in range(1, num + 1): x = str(i) if i % 3 == 0 or "3" in x: print(end=" ") print(i, end="") print()
num = int(input()) for i in range(1, num + 1): x = str(i) if i % 3 == 0 or "3" in x: print("", i, end="") print()
false
11.111111
[ "- print(end=\" \")", "- print(i, end=\"\")", "+ print(\"\", i, end=\"\")" ]
false
0.067388
0.048151
1.399518
[ "s835445003", "s268921217" ]
u057109575
p03031
python
s409504648
s966641710
255
85
45,788
73,832
Accepted
Accepted
66.67
N, M = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] P = list(map(int, input().split())) ans = 0 for bit in range(2 ** N): ons = set([i + 1 for i in range(N) if bit >> i & 1]) flg = True for i in range(M): k, *s = X[i] p = P[i] flg &= len(set(s) & ons) % 2 == p ans += int(flg) print(ans)
N, M = list(map(int, input().split())) K = [] X = [] for _ in range(M): k, *x = list(map(int, input().split())) K.append(k) X.append(x) P = list(map(int, input().split())) ans = 0 for bit in range(2 ** N): light_on = [False] * M for i in range(M): tmp = 0 for s in X[i]: tmp += bit >> (s - 1) & 1 light_on[i] = tmp % 2 == P[i] ans += all(light_on) print(ans)
15
22
385
438
N, M = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(M)] P = list(map(int, input().split())) ans = 0 for bit in range(2**N): ons = set([i + 1 for i in range(N) if bit >> i & 1]) flg = True for i in range(M): k, *s = X[i] p = P[i] flg &= len(set(s) & ons) % 2 == p ans += int(flg) print(ans)
N, M = list(map(int, input().split())) K = [] X = [] for _ in range(M): k, *x = list(map(int, input().split())) K.append(k) X.append(x) P = list(map(int, input().split())) ans = 0 for bit in range(2**N): light_on = [False] * M for i in range(M): tmp = 0 for s in X[i]: tmp += bit >> (s - 1) & 1 light_on[i] = tmp % 2 == P[i] ans += all(light_on) print(ans)
false
31.818182
[ "-X = [list(map(int, input().split())) for _ in range(M)]", "+K = []", "+X = []", "+for _ in range(M):", "+ k, *x = list(map(int, input().split()))", "+ K.append(k)", "+ X.append(x)", "- ons = set([i + 1 for i in range(N) if bit >> i & 1])", "- flg = True", "+ light_on = [False] * M", "- k, *s = X[i]", "- p = P[i]", "- flg &= len(set(s) & ons) % 2 == p", "- ans += int(flg)", "+ tmp = 0", "+ for s in X[i]:", "+ tmp += bit >> (s - 1) & 1", "+ light_on[i] = tmp % 2 == P[i]", "+ ans += all(light_on)" ]
false
0.037699
0.031637
1.191599
[ "s409504648", "s966641710" ]
u298297089
p02887
python
s822690646
s623232915
44
34
3,316
9,664
Accepted
Accepted
22.73
n = int(eval(input())) tmp = '' ans = 0 for c in eval(input()): if tmp != c: ans += 1 tmp = c print(ans)
def run_length(data, init=''): length = [] tmp = init cnt = 0 for c in data: if tmp != c: length.append(cnt) cnt = 0 tmp = c cnt += 1 length.append(cnt) return length def resolve(): n = int(eval(input())) s = eval(input()) length = run_length(s, '') print((len(length) - 1)) if __name__ == "__main__": resolve()
8
23
115
416
n = int(eval(input())) tmp = "" ans = 0 for c in eval(input()): if tmp != c: ans += 1 tmp = c print(ans)
def run_length(data, init=""): length = [] tmp = init cnt = 0 for c in data: if tmp != c: length.append(cnt) cnt = 0 tmp = c cnt += 1 length.append(cnt) return length def resolve(): n = int(eval(input())) s = eval(input()) length = run_length(s, "") print((len(length) - 1)) if __name__ == "__main__": resolve()
false
65.217391
[ "-n = int(eval(input()))", "-tmp = \"\"", "-ans = 0", "-for c in eval(input()):", "- if tmp != c:", "- ans += 1", "- tmp = c", "-print(ans)", "+def run_length(data, init=\"\"):", "+ length = []", "+ tmp = init", "+ cnt = 0", "+ for c in data:", "+ if tmp != c:", "+ length.append(cnt)", "+ cnt = 0", "+ tmp = c", "+ cnt += 1", "+ length.append(cnt)", "+ return length", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ s = eval(input())", "+ length = run_length(s, \"\")", "+ print((len(length) - 1))", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.049088
0.008166
6.01102
[ "s822690646", "s623232915" ]
u667024514
p03345
python
s552570154
s749400689
20
17
3,316
2,940
Accepted
Accepted
15
a,b,c,k = list(map(int,input().split())) if k % 2 == 0: print((a-b)) else: print((b-a))
a,b,c,k = list(map(int,input().split())) print(((a-b)*(-1)**(k%2)))
5
2
89
61
a, b, c, k = list(map(int, input().split())) if k % 2 == 0: print((a - b)) else: print((b - a))
a, b, c, k = list(map(int, input().split())) print(((a - b) * (-1) ** (k % 2)))
false
60
[ "-if k % 2 == 0:", "- print((a - b))", "-else:", "- print((b - a))", "+print(((a - b) * (-1) ** (k % 2)))" ]
false
0.041241
0.041205
1.000879
[ "s552570154", "s749400689" ]
u156815136
p03319
python
s376628148
s751870230
61
56
15,900
14,196
Accepted
Accepted
8.2
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 # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) n,k = readInts() A = readInts() import math print((1 if len(A) <= k else 1 + math.ceil((n-k)/(k-1))))
#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 # (string,3) 3回 #from collections import deque from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # 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,k = readInts() A = readInts() cnt = 1 now = k while now < n: cnt += 1 now += k - 1 print(cnt)
30
34
685
715
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 # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) n, k = readInts() A = readInts() import math print((1 if len(A) <= k else 1 + math.ceil((n - k) / (k - 1))))
# 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 # (string,3) 3回 # from collections import deque from collections import defaultdict # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # 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, k = readInts() A = readInts() cnt = 1 now = k while now < n: cnt += 1 now += k - 1 print(cnt)
false
11.764706
[ "-from statistics import median", "-", "+# from statistics import median", "-from fractions import gcd", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "+# from fractions import gcd", "+# from itertools import combinations # (string,3) 3回", "+# from collections import deque", "-import bisect", "+# import bisect", "-", "-", "+# mod = 9982443453", "-import math", "-", "-print((1 if len(A) <= k else 1 + math.ceil((n - k) / (k - 1))))", "+cnt = 1", "+now = k", "+while now < n:", "+ cnt += 1", "+ now += k - 1", "+print(cnt)" ]
false
0.128083
0.048227
2.655856
[ "s376628148", "s751870230" ]
u604839890
p03835
python
s208200479
s854587974
1,965
1,054
9,128
9,056
Accepted
Accepted
46.36
k, s = list(map(int, input().split())) ans = 0 for x in range(k+1): if x > s: break if x+k+k < s: continue for y in range(k+1): ans += max(0, 0<=s-x-y<=k) print(ans)
k, s = list(map(int, input().split())) ans = 0 for i in range(k+1): for j in range(k+1): if 0 <= s-i-j <= k: ans += 1 print(ans)
11
8
207
154
k, s = list(map(int, input().split())) ans = 0 for x in range(k + 1): if x > s: break if x + k + k < s: continue for y in range(k + 1): ans += max(0, 0 <= s - x - y <= k) print(ans)
k, s = list(map(int, input().split())) ans = 0 for i in range(k + 1): for j in range(k + 1): if 0 <= s - i - j <= k: ans += 1 print(ans)
false
27.272727
[ "-for x in range(k + 1):", "- if x > s:", "- break", "- if x + k + k < s:", "- continue", "- for y in range(k + 1):", "- ans += max(0, 0 <= s - x - y <= k)", "+for i in range(k + 1):", "+ for j in range(k + 1):", "+ if 0 <= s - i - j <= k:", "+ ans += 1" ]
false
0.037288
0.084114
0.443307
[ "s208200479", "s854587974" ]
u699296734
p03220
python
s676402812
s090894866
33
29
9,260
9,292
Accepted
Accepted
12.12
n = int(eval(input())) t, a = list(map(int, input().split())) h = list(map(int, input().split())) min_tmp = 10 ** 5 index = 0 for i in range(n): tmp = abs(a - (t - 0.006 * h[i])) if tmp <= min_tmp: min_tmp = tmp index = i # print(tmp) print((index + 1))
""" 半ば強引に二分探査で書いた。 """ #入力 n = int(eval(input())) t, a = list(map(int, input().split())) h = list(map(int, input().split())) h_not_sorted = h h = sorted(h) x = abs((t - a) / 0.006) #二分探査 l = 0 r = n - 1 x_index = 0 while l + 1 != r : middle = (l + r) // 2 if h[middle] == x: x_index = middle break elif h[middle] < x: x_index = middle + 1 l = middle else: x_index = middle - 1 r = middle #x_indexが両橋の場合とそれ以外で場合わけ。 res = abs(a - (t - 0.006 * h[x_index])) ans = x_index flag_r = True flag_l = True if x_index == n - 1: flag_r = False elif x_index == 0: flag_l = False else: pass #x_indexの両橋と比較。x_indexが際数値でない可能性があるため。 if flag_r: if abs(a - (t - 0.006 * h[x_index + 1])) < res: res = abs(a - (t - 0.006 * h[x_index + 1])) ans += 1 if flag_l: if abs(a - (t - 0.006 * h[x_index - 1])) < res: res = abs(a - (t - 0.006 * h[x_index - 1])) ans -= 1 print((h_not_sorted.index(h[ans]) + 1))
13
51
281
1,037
n = int(eval(input())) t, a = list(map(int, input().split())) h = list(map(int, input().split())) min_tmp = 10**5 index = 0 for i in range(n): tmp = abs(a - (t - 0.006 * h[i])) if tmp <= min_tmp: min_tmp = tmp index = i # print(tmp) print((index + 1))
""" 半ば強引に二分探査で書いた。 """ # 入力 n = int(eval(input())) t, a = list(map(int, input().split())) h = list(map(int, input().split())) h_not_sorted = h h = sorted(h) x = abs((t - a) / 0.006) # 二分探査 l = 0 r = n - 1 x_index = 0 while l + 1 != r: middle = (l + r) // 2 if h[middle] == x: x_index = middle break elif h[middle] < x: x_index = middle + 1 l = middle else: x_index = middle - 1 r = middle # x_indexが両橋の場合とそれ以外で場合わけ。 res = abs(a - (t - 0.006 * h[x_index])) ans = x_index flag_r = True flag_l = True if x_index == n - 1: flag_r = False elif x_index == 0: flag_l = False else: pass # x_indexの両橋と比較。x_indexが際数値でない可能性があるため。 if flag_r: if abs(a - (t - 0.006 * h[x_index + 1])) < res: res = abs(a - (t - 0.006 * h[x_index + 1])) ans += 1 if flag_l: if abs(a - (t - 0.006 * h[x_index - 1])) < res: res = abs(a - (t - 0.006 * h[x_index - 1])) ans -= 1 print((h_not_sorted.index(h[ans]) + 1))
false
74.509804
[ "+\"\"\"", "+半ば強引に二分探査で書いた。", "+\"\"\"", "+# 入力", "-min_tmp = 10**5", "-index = 0", "-for i in range(n):", "- tmp = abs(a - (t - 0.006 * h[i]))", "- if tmp <= min_tmp:", "- min_tmp = tmp", "- index = i", "- # print(tmp)", "-print((index + 1))", "+h_not_sorted = h", "+h = sorted(h)", "+x = abs((t - a) / 0.006)", "+# 二分探査", "+l = 0", "+r = n - 1", "+x_index = 0", "+while l + 1 != r:", "+ middle = (l + r) // 2", "+ if h[middle] == x:", "+ x_index = middle", "+ break", "+ elif h[middle] < x:", "+ x_index = middle + 1", "+ l = middle", "+ else:", "+ x_index = middle - 1", "+ r = middle", "+# x_indexが両橋の場合とそれ以外で場合わけ。", "+res = abs(a - (t - 0.006 * h[x_index]))", "+ans = x_index", "+flag_r = True", "+flag_l = True", "+if x_index == n - 1:", "+ flag_r = False", "+elif x_index == 0:", "+ flag_l = False", "+else:", "+ pass", "+# x_indexの両橋と比較。x_indexが際数値でない可能性があるため。", "+if flag_r:", "+ if abs(a - (t - 0.006 * h[x_index + 1])) < res:", "+ res = abs(a - (t - 0.006 * h[x_index + 1]))", "+ ans += 1", "+if flag_l:", "+ if abs(a - (t - 0.006 * h[x_index - 1])) < res:", "+ res = abs(a - (t - 0.006 * h[x_index - 1]))", "+ ans -= 1", "+print((h_not_sorted.index(h[ans]) + 1))" ]
false
0.072513
0.085127
0.851819
[ "s676402812", "s090894866" ]
u327466606
p02579
python
s913746972
s830835775
783
208
23,056
87,804
Accepted
Accepted
73.44
max2 = lambda x,y: x if x > y else y min2 = lambda x,y: x if x < y else y import sys from itertools import count read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline MOVES = [ ((1, 0), [(2,-1),(2,0),(2,1),(2,2),(1,1)]), ((-1, 0),[(-2,-1),(-2,0),(-2,1),(-2,-2),(-1,-1)]), ((0, 1), [(1,2),(0,2),(-1,2),(-2,2),(-1,1)]), ((0, -1), [(1,-2),(0,-2),(-1,-2),(2,-2),(1,-1)]), ] CONVERTED_MOVES = None def solve(dist, start, goal): q = [start] cnt = 0 while q: nq = [] while q: x = q.pop() if x == goal: return cnt if dist[x] < cnt: continue for d,l in CONVERTED_MOVES: nx = x+d if dist[nx] > cnt: dist[nx] = cnt q.append(nx) if dist[nx] < 0: for t in l: p = x+t if dist[p] > cnt+1: dist[p] = cnt+1 nq.append(p) q = nq cnt += 1 return -1 if __name__ == '__main__': H,W = list(map(int,readline().split())) start = tuple([int(i)+1 for i in readline().split()]) goal = tuple([int(i)+1 for i in readline().split()]) H += 4 W += 4 dist = [-1]*(W*H) start = start[0]*W+start[1] goal = goal[0]*W+goal[1] for t,s in zip(count(2*W,W),read().split()): for i,c in zip(count(t+2),s.decode()): if c == '.': dist[i] = 10**7 convert = lambda x,y: x*W+y CONVERTED_MOVES = [] for d,l in MOVES: d = convert(*d) l = [convert(*d) for d in l] CONVERTED_MOVES.append((d,l)) # print(CONVERTED_MOVES) print((solve(dist,start,goal)))
import sys from itertools import count read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline MOVES = [ ((1, 0), [(2,-1),(2,0),(2,1),(2,2),(1,1)]), ((-1, 0),[(-2,-1),(-2,0),(-2,1),(-2,-2),(-1,-1)]), ((0, 1), [(1,2),(0,2),(-1,2),(-2,2),(-1,1)]), ((0, -1), [(1,-2),(0,-2),(-1,-2),(2,-2),(1,-1)]), ] CONVERTED_MOVES = None def solve(dist, start, goal): q = [start] cnt = 0 while q: nq = [] while q: x = q.pop() if x == goal: return cnt if dist[x] < cnt: continue for d,l in CONVERTED_MOVES: nx = x+d if dist[nx] > cnt: dist[nx] = cnt q.append(nx) if dist[nx] < 0: for t in l: p = x+t if dist[p] > cnt+1: dist[p] = cnt+1 nq.append(p) q = nq cnt += 1 return -1 if __name__ == '__main__': H,W = list(map(int,readline().split())) start = tuple([int(i)+1 for i in readline().split()]) goal = tuple([int(i)+1 for i in readline().split()]) H += 4 W += 4 dist = [-1]*(W*H) start = start[0]*W+start[1] goal = goal[0]*W+goal[1] for t,s in zip(count(2*W,W),read().split()): for i,c in zip(count(t+2),s.decode()): if c == '.': dist[i] = 10**7 convert = lambda x,y: x*W+y CONVERTED_MOVES = [] for d,l in MOVES: d = convert(*d) l = [convert(*d) for d in l] CONVERTED_MOVES.append((d,l)) print((solve(dist,start,goal)))
76
71
1,878
1,768
max2 = lambda x, y: x if x > y else y min2 = lambda x, y: x if x < y else y import sys from itertools import count read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline MOVES = [ ((1, 0), [(2, -1), (2, 0), (2, 1), (2, 2), (1, 1)]), ((-1, 0), [(-2, -1), (-2, 0), (-2, 1), (-2, -2), (-1, -1)]), ((0, 1), [(1, 2), (0, 2), (-1, 2), (-2, 2), (-1, 1)]), ((0, -1), [(1, -2), (0, -2), (-1, -2), (2, -2), (1, -1)]), ] CONVERTED_MOVES = None def solve(dist, start, goal): q = [start] cnt = 0 while q: nq = [] while q: x = q.pop() if x == goal: return cnt if dist[x] < cnt: continue for d, l in CONVERTED_MOVES: nx = x + d if dist[nx] > cnt: dist[nx] = cnt q.append(nx) if dist[nx] < 0: for t in l: p = x + t if dist[p] > cnt + 1: dist[p] = cnt + 1 nq.append(p) q = nq cnt += 1 return -1 if __name__ == "__main__": H, W = list(map(int, readline().split())) start = tuple([int(i) + 1 for i in readline().split()]) goal = tuple([int(i) + 1 for i in readline().split()]) H += 4 W += 4 dist = [-1] * (W * H) start = start[0] * W + start[1] goal = goal[0] * W + goal[1] for t, s in zip(count(2 * W, W), read().split()): for i, c in zip(count(t + 2), s.decode()): if c == ".": dist[i] = 10**7 convert = lambda x, y: x * W + y CONVERTED_MOVES = [] for d, l in MOVES: d = convert(*d) l = [convert(*d) for d in l] CONVERTED_MOVES.append((d, l)) # print(CONVERTED_MOVES) print((solve(dist, start, goal)))
import sys from itertools import count read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline MOVES = [ ((1, 0), [(2, -1), (2, 0), (2, 1), (2, 2), (1, 1)]), ((-1, 0), [(-2, -1), (-2, 0), (-2, 1), (-2, -2), (-1, -1)]), ((0, 1), [(1, 2), (0, 2), (-1, 2), (-2, 2), (-1, 1)]), ((0, -1), [(1, -2), (0, -2), (-1, -2), (2, -2), (1, -1)]), ] CONVERTED_MOVES = None def solve(dist, start, goal): q = [start] cnt = 0 while q: nq = [] while q: x = q.pop() if x == goal: return cnt if dist[x] < cnt: continue for d, l in CONVERTED_MOVES: nx = x + d if dist[nx] > cnt: dist[nx] = cnt q.append(nx) if dist[nx] < 0: for t in l: p = x + t if dist[p] > cnt + 1: dist[p] = cnt + 1 nq.append(p) q = nq cnt += 1 return -1 if __name__ == "__main__": H, W = list(map(int, readline().split())) start = tuple([int(i) + 1 for i in readline().split()]) goal = tuple([int(i) + 1 for i in readline().split()]) H += 4 W += 4 dist = [-1] * (W * H) start = start[0] * W + start[1] goal = goal[0] * W + goal[1] for t, s in zip(count(2 * W, W), read().split()): for i, c in zip(count(t + 2), s.decode()): if c == ".": dist[i] = 10**7 convert = lambda x, y: x * W + y CONVERTED_MOVES = [] for d, l in MOVES: d = convert(*d) l = [convert(*d) for d in l] CONVERTED_MOVES.append((d, l)) print((solve(dist, start, goal)))
false
6.578947
[ "-max2 = lambda x, y: x if x > y else y", "-min2 = lambda x, y: x if x < y else y", "- # print(CONVERTED_MOVES)" ]
false
0.045908
0.045773
1.002962
[ "s913746972", "s830835775" ]
u618002097
p03086
python
s202106553
s378573890
175
64
38,384
61,772
Accepted
Accepted
63.43
S = eval(input()) ans = 0 ACGT = ("A", "C", "G", "T") count = 0 count_list = [0] for s in S: if s not in ACGT: count_list.append(count) count = 0 continue else: count += 1 count_list.append(count) print((max(count_list)))
S = eval(input()) ACGT = ['A', 'C', 'G', 'T'] count = 0 max_count = 0 for s in S: if s in ACGT: count += 1 else: max_count = max(max_count, count) count = 0 max_count = max(max_count, count) print(max_count)
16
14
270
248
S = eval(input()) ans = 0 ACGT = ("A", "C", "G", "T") count = 0 count_list = [0] for s in S: if s not in ACGT: count_list.append(count) count = 0 continue else: count += 1 count_list.append(count) print((max(count_list)))
S = eval(input()) ACGT = ["A", "C", "G", "T"] count = 0 max_count = 0 for s in S: if s in ACGT: count += 1 else: max_count = max(max_count, count) count = 0 max_count = max(max_count, count) print(max_count)
false
12.5
[ "-ans = 0", "-ACGT = (\"A\", \"C\", \"G\", \"T\")", "+ACGT = [\"A\", \"C\", \"G\", \"T\"]", "-count_list = [0]", "+max_count = 0", "- if s not in ACGT:", "- count_list.append(count)", "+ if s in ACGT:", "+ count += 1", "+ else:", "+ max_count = max(max_count, count)", "- continue", "- else:", "- count += 1", "-count_list.append(count)", "-print((max(count_list)))", "+max_count = max(max_count, count)", "+print(max_count)" ]
false
0.041376
0.075245
0.549889
[ "s202106553", "s378573890" ]
u334667251
p00523
python
s073774257
s194435693
4,680
1,010
21,076
20,944
Accepted
Accepted
78.42
def isok(m): p0 = 0 p1 = 1 p2 = 1 while p0 < N: # l0>=m ??¨???????????????p1????±??????? if p1 <= p0: p1 = p0 + 1 while d[p1] - d[p0] < m and p1 - p0 < N: p1 += 1 if d[p1] - d[p0] < m: p0 += 1 continue l0 = d[p1] - d[p0] # l1>=l0??¨???????????????p2????±??????? if p2 <= p1: p2 = p1 + 1 while d[p2] - d[p1] < m and p2 - p0 < N: p2 += 1 if d[p2] - d[p1] < m: p0 += 1 continue l1 = d[p2] - d[p1] if L - l0 - l1 >= l1: return True p0 += 1 return False N = int(eval(input())) A = [0] * N L = 0 for i in range(N): A[i] = int(eval(input())) L += A[i] d = [0] * (2*N) for i in range(1, 2*N): d[i] = d[i-1] + A[(i-1)%N] left = 1 right = L // 3 ans = 0 while left <= right: m = (left + right) // 2 if isok(m): ans = m left = m + 1 else: right = m - 1 print(ans)
def d(p, q): return pos[p] - pos[q] def solve(): p0, p1, p2 = 0, 0, 0 best = 0 while p0 < N: # p1????±??????? if p1 <= p0: p1 = p0 + 1 while d(p1, p0) <= best and p1 - p0 < N: p1 += 1 if d(p1, p0) <= best: p0 += 1 continue # p2????±??????? while d(p2, p1) > d(p1, p0) and p2 > p1: p2 -= 1 if p2 <= p1: p2 = p1 + 1 while d(p2,p1) < d(p1, p0) and p2 - p0 < N: p2 += 1 if d(p2, p1) < d(p1, p0): p0 += 1 continue # check if L - d(p2, p0) >= d(p1, p0): best = d(p1, p0) if best >= L//3: return best else: p0 += 1 return best N = int(eval(input())) A = [0] * N L = 0 for i in range(N): A[i] = int(eval(input())) L += A[i] pos = [0] * (2*N) for i in range(1, 2*N): pos[i] = pos[i-1] + A[(i-1)%N] print((solve()))
47
43
1,036
1,000
def isok(m): p0 = 0 p1 = 1 p2 = 1 while p0 < N: # l0>=m ??¨???????????????p1????±??????? if p1 <= p0: p1 = p0 + 1 while d[p1] - d[p0] < m and p1 - p0 < N: p1 += 1 if d[p1] - d[p0] < m: p0 += 1 continue l0 = d[p1] - d[p0] # l1>=l0??¨???????????????p2????±??????? if p2 <= p1: p2 = p1 + 1 while d[p2] - d[p1] < m and p2 - p0 < N: p2 += 1 if d[p2] - d[p1] < m: p0 += 1 continue l1 = d[p2] - d[p1] if L - l0 - l1 >= l1: return True p0 += 1 return False N = int(eval(input())) A = [0] * N L = 0 for i in range(N): A[i] = int(eval(input())) L += A[i] d = [0] * (2 * N) for i in range(1, 2 * N): d[i] = d[i - 1] + A[(i - 1) % N] left = 1 right = L // 3 ans = 0 while left <= right: m = (left + right) // 2 if isok(m): ans = m left = m + 1 else: right = m - 1 print(ans)
def d(p, q): return pos[p] - pos[q] def solve(): p0, p1, p2 = 0, 0, 0 best = 0 while p0 < N: # p1????±??????? if p1 <= p0: p1 = p0 + 1 while d(p1, p0) <= best and p1 - p0 < N: p1 += 1 if d(p1, p0) <= best: p0 += 1 continue # p2????±??????? while d(p2, p1) > d(p1, p0) and p2 > p1: p2 -= 1 if p2 <= p1: p2 = p1 + 1 while d(p2, p1) < d(p1, p0) and p2 - p0 < N: p2 += 1 if d(p2, p1) < d(p1, p0): p0 += 1 continue # check if L - d(p2, p0) >= d(p1, p0): best = d(p1, p0) if best >= L // 3: return best else: p0 += 1 return best N = int(eval(input())) A = [0] * N L = 0 for i in range(N): A[i] = int(eval(input())) L += A[i] pos = [0] * (2 * N) for i in range(1, 2 * N): pos[i] = pos[i - 1] + A[(i - 1) % N] print((solve()))
false
8.510638
[ "-def isok(m):", "- p0 = 0", "- p1 = 1", "- p2 = 1", "+def d(p, q):", "+ return pos[p] - pos[q]", "+", "+", "+def solve():", "+ p0, p1, p2 = 0, 0, 0", "+ best = 0", "- # l0>=m ??¨???????????????p1????±???????", "+ # p1????±???????", "- while d[p1] - d[p0] < m and p1 - p0 < N:", "+ while d(p1, p0) <= best and p1 - p0 < N:", "- if d[p1] - d[p0] < m:", "+ if d(p1, p0) <= best:", "- l0 = d[p1] - d[p0]", "- # l1>=l0??¨???????????????p2????±???????", "+ # p2????±???????", "+ while d(p2, p1) > d(p1, p0) and p2 > p1:", "+ p2 -= 1", "- while d[p2] - d[p1] < m and p2 - p0 < N:", "+ while d(p2, p1) < d(p1, p0) and p2 - p0 < N:", "- if d[p2] - d[p1] < m:", "+ if d(p2, p1) < d(p1, p0):", "- l1 = d[p2] - d[p1]", "- if L - l0 - l1 >= l1:", "- return True", "- p0 += 1", "- return False", "+ # check", "+ if L - d(p2, p0) >= d(p1, p0):", "+ best = d(p1, p0)", "+ if best >= L // 3:", "+ return best", "+ else:", "+ p0 += 1", "+ return best", "-d = [0] * (2 * N)", "+pos = [0] * (2 * N)", "- d[i] = d[i - 1] + A[(i - 1) % N]", "-left = 1", "-right = L // 3", "-ans = 0", "-while left <= right:", "- m = (left + right) // 2", "- if isok(m):", "- ans = m", "- left = m + 1", "- else:", "- right = m - 1", "-print(ans)", "+ pos[i] = pos[i - 1] + A[(i - 1) % N]", "+print((solve()))" ]
false
0.039066
0.034493
1.13256
[ "s073774257", "s194435693" ]
u757030836
p02761
python
s496725442
s308709593
21
18
3,060
3,064
Accepted
Accepted
14.29
n,m = list(map(int,input().split())) req = [list(map(int,input().split())) for i in range(m)] for i in range(10000): st = str(i) if len(st) != n: continue ok = True for s,c in req: if int(st[s-1]) != int(c): ok = False if ok: print(st) exit() print((-1))
N,M = list(map(int,input().split())) sc = [list(map(int,input().split())) for m in range(M)] for i in range(10**N): if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc): print(i) break else: print((-1))
16
10
299
229
n, m = list(map(int, input().split())) req = [list(map(int, input().split())) for i in range(m)] for i in range(10000): st = str(i) if len(st) != n: continue ok = True for s, c in req: if int(st[s - 1]) != int(c): ok = False if ok: print(st) exit() print((-1))
N, M = list(map(int, input().split())) sc = [list(map(int, input().split())) for m in range(M)] for i in range(10**N): if len(str(i)) == N and all(str(i)[s - 1] == str(c) for s, c in sc): print(i) break else: print((-1))
false
37.5
[ "-n, m = list(map(int, input().split()))", "-req = [list(map(int, input().split())) for i in range(m)]", "-for i in range(10000):", "- st = str(i)", "- if len(st) != n:", "- continue", "- ok = True", "- for s, c in req:", "- if int(st[s - 1]) != int(c):", "- ok = False", "- if ok:", "- print(st)", "- exit()", "-print((-1))", "+N, M = list(map(int, input().split()))", "+sc = [list(map(int, input().split())) for m in range(M)]", "+for i in range(10**N):", "+ if len(str(i)) == N and all(str(i)[s - 1] == str(c) for s, c in sc):", "+ print(i)", "+ break", "+else:", "+ print((-1))" ]
false
0.044202
0.101824
0.434102
[ "s496725442", "s308709593" ]
u855967722
p02622
python
s572137452
s676522557
66
51
9,396
9,344
Accepted
Accepted
22.73
S = eval(input()) T = eval(input()) C = 0 for i in range(len(S)): if S[i] == T[i]: pass else: C += 1 print(C)
def main(): S = eval(input()) T = eval(input()) count = 0 for i in range(len(S)): if S[i] != T[i]: count+=1 print(count) if __name__ == '__main__': main()
9
12
117
200
S = eval(input()) T = eval(input()) C = 0 for i in range(len(S)): if S[i] == T[i]: pass else: C += 1 print(C)
def main(): S = eval(input()) T = eval(input()) count = 0 for i in range(len(S)): if S[i] != T[i]: count += 1 print(count) if __name__ == "__main__": main()
false
25
[ "-S = eval(input())", "-T = eval(input())", "-C = 0", "-for i in range(len(S)):", "- if S[i] == T[i]:", "- pass", "- else:", "- C += 1", "-print(C)", "+def main():", "+ S = eval(input())", "+ T = eval(input())", "+ count = 0", "+ for i in range(len(S)):", "+ if S[i] != T[i]:", "+ count += 1", "+ print(count)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.070086
0.031303
2.238928
[ "s572137452", "s676522557" ]