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
u803848678
p03912
python
s893582320
s862562307
217
151
35,160
22,636
Accepted
Accepted
30.41
from collections import defaultdict, Counter N, M = list(map(int, input().split())) #X = list(map(int, input().split())) C = Counter(list(map(int, input().split()))) D = defaultdict(int) E = defaultdict(int) for k, v in list(C.items()): D[k%M] += v E[k%M] += v//2 ans = D[0] // 2 for i in range(1, M): j = M - i if i < j: x = min(D[i], D[j]) y = min((D[i] - x)//2, E[i]) + min((D[j] - x)//2, E[j]) ans += x + y elif i == j: ans += D[i] //2 else: break print(ans)
from collections import defaultdict, Counter N, M = list(map(int, input().split())) C = Counter(list(map(int, input().split()))) #D = defaultdict(int) #E = defaultdict(int) D = [0]*M E = [0]*M for k, v in list(C.items()): D[k%M] += v E[k%M] += v//2 ans = D[0] // 2 for i in range(1, M): j = M - i if i < j: x = min(D[i], D[j]) y = min((D[i] - x)//2, E[i]) + min((D[j] - x)//2, E[j]) ans += x + y elif i == j: ans += D[i] //2 else: break print(ans)
24
25
534
520
from collections import defaultdict, Counter N, M = list(map(int, input().split())) # X = list(map(int, input().split())) C = Counter(list(map(int, input().split()))) D = defaultdict(int) E = defaultdict(int) for k, v in list(C.items()): D[k % M] += v E[k % M] += v // 2 ans = D[0] // 2 for i in range(1, M): j = M - i if i < j: x = min(D[i], D[j]) y = min((D[i] - x) // 2, E[i]) + min((D[j] - x) // 2, E[j]) ans += x + y elif i == j: ans += D[i] // 2 else: break print(ans)
from collections import defaultdict, Counter N, M = list(map(int, input().split())) C = Counter(list(map(int, input().split()))) # D = defaultdict(int) # E = defaultdict(int) D = [0] * M E = [0] * M for k, v in list(C.items()): D[k % M] += v E[k % M] += v // 2 ans = D[0] // 2 for i in range(1, M): j = M - i if i < j: x = min(D[i], D[j]) y = min((D[i] - x) // 2, E[i]) + min((D[j] - x) // 2, E[j]) ans += x + y elif i == j: ans += D[i] // 2 else: break print(ans)
false
4
[ "-# X = list(map(int, input().split()))", "-D = defaultdict(int)", "-E = defaultdict(int)", "+# D = defaultdict(int)", "+# E = defaultdict(int)", "+D = [0] * M", "+E = [0] * M" ]
false
0.04149
0.173276
0.239445
[ "s893582320", "s862562307" ]
u254871849
p03574
python
s202919825
s835043963
29
24
3,316
3,064
Accepted
Accepted
17.24
import sys from collections import deque h, w = (int(x) for x in sys.stdin.readline().split()) strings = deque(sys.stdin.read().split()) for i in range(h): strings[i] = ''.join(['-', strings[i], '-']) strings.append('-' * (w + 2)); strings.appendleft('-' * (w + 2)) ans = [] for i in range(1, h + 1): s = '' for j in range(1, w + 1): current = strings[i][j] if current == '#': s += '#' elif current == '.': count = 0 for t in range(i-1, i+2): for u in range(j-1, j+2): if strings[t][u] == '#': count += 1 s += str(count) ans.append(s) for s in ans: print(s)
import sys h, w = map(int, sys.stdin.readline().split()) canvas = ['.' * (w + 2)] + ['.' + sys.stdin.readline().rstrip() + '.' for _ in range(h)] + ['.' * (w + 2)] def main(): res = [[0] * (w + 1) for _ in range(h + 1)] for i in range(1, h + 1): for j in range(1, w + 1): if canvas[i][j] == '#': res[i][j] = '#' continue for di in range(-1, 2): for dj in range(-1, 2): y = i + di x = j + dj if canvas[y][x] == '#': res[i][j] += 1 for i in range(1, h+1): yield ''.join(list(map(str, res[i][1:]))) if __name__ == '__main__': ans = main() print(*ans, sep='\n')
26
26
700
783
import sys from collections import deque h, w = (int(x) for x in sys.stdin.readline().split()) strings = deque(sys.stdin.read().split()) for i in range(h): strings[i] = "".join(["-", strings[i], "-"]) strings.append("-" * (w + 2)) strings.appendleft("-" * (w + 2)) ans = [] for i in range(1, h + 1): s = "" for j in range(1, w + 1): current = strings[i][j] if current == "#": s += "#" elif current == ".": count = 0 for t in range(i - 1, i + 2): for u in range(j - 1, j + 2): if strings[t][u] == "#": count += 1 s += str(count) ans.append(s) for s in ans: print(s)
import sys h, w = map(int, sys.stdin.readline().split()) canvas = ( ["." * (w + 2)] + ["." + sys.stdin.readline().rstrip() + "." for _ in range(h)] + ["." * (w + 2)] ) def main(): res = [[0] * (w + 1) for _ in range(h + 1)] for i in range(1, h + 1): for j in range(1, w + 1): if canvas[i][j] == "#": res[i][j] = "#" continue for di in range(-1, 2): for dj in range(-1, 2): y = i + di x = j + dj if canvas[y][x] == "#": res[i][j] += 1 for i in range(1, h + 1): yield "".join(list(map(str, res[i][1:]))) if __name__ == "__main__": ans = main() print(*ans, sep="\n")
false
0
[ "-from collections import deque", "-h, w = (int(x) for x in sys.stdin.readline().split())", "-strings = deque(sys.stdin.read().split())", "-for i in range(h):", "- strings[i] = \"\".join([\"-\", strings[i], \"-\"])", "-strings.append(\"-\" * (w + 2))", "-strings.appendleft(\"-\" * (w + 2))", "-ans ...
false
0.039325
0.065301
0.602219
[ "s202919825", "s835043963" ]
u514894322
p02947
python
s263996982
s382213781
413
319
11,204
24,972
Accepted
Accepted
22.76
n = int(eval(input())) sl = sorted([''.join(sorted(eval(input()))) for _ in [0]*n]) count = 0 while len(sl)>1: i = 1 flag = True while flag: if sl[-1] == sl[-(i+1)]: i += 1 if i == len(sl): flag=False else: flag = False if i>1: count += i*(i-1)//2 del sl[-i:] flag=True print(count)
n = int(eval(input())) sl = [eval(input()) for _ in [0]*n] count = 0 dict = {} for s_raw in sl: s = ''.join(sorted(s_raw)) if s in dict: count += dict[s] dict[s] += 1 else: dict.setdefault(s, 1) print(count)
18
12
338
224
n = int(eval(input())) sl = sorted(["".join(sorted(eval(input()))) for _ in [0] * n]) count = 0 while len(sl) > 1: i = 1 flag = True while flag: if sl[-1] == sl[-(i + 1)]: i += 1 if i == len(sl): flag = False else: flag = False if i > 1: count += i * (i - 1) // 2 del sl[-i:] flag = True print(count)
n = int(eval(input())) sl = [eval(input()) for _ in [0] * n] count = 0 dict = {} for s_raw in sl: s = "".join(sorted(s_raw)) if s in dict: count += dict[s] dict[s] += 1 else: dict.setdefault(s, 1) print(count)
false
33.333333
[ "-sl = sorted([\"\".join(sorted(eval(input()))) for _ in [0] * n])", "+sl = [eval(input()) for _ in [0] * n]", "-while len(sl) > 1:", "- i = 1", "- flag = True", "- while flag:", "- if sl[-1] == sl[-(i + 1)]:", "- i += 1", "- if i == len(sl):", "- ...
false
0.047715
0.047677
1.000791
[ "s263996982", "s382213781" ]
u648881683
p02755
python
s885540649
s522536324
19
17
2,940
3,060
Accepted
Accepted
10.53
import sys input = lambda: sys.stdin.readline().rstrip() import math def resolve(): A, B = list(map(int, input().split())) ans = -1 for i in range(2000): if math.floor(i*0.08)==A and math.floor(i*0.10)==B: ans = i break print(ans) if __name__ == '__main__': resolve()
import sys input = lambda: sys.stdin.readline().rstrip() import math def resolve(): A, B = list(map(int, input().split())) aa_min = A / 0.08 aa_max = (A+1) / 0.08 bb_min = B / 0.1 bb_max = (B+1) / 0.1 if aa_min < bb_max and bb_min < aa_max: print((math.ceil(max(aa_min, bb_min)))) else: print('-1') if __name__ == '__main__': resolve()
16
17
333
395
import sys input = lambda: sys.stdin.readline().rstrip() import math def resolve(): A, B = list(map(int, input().split())) ans = -1 for i in range(2000): if math.floor(i * 0.08) == A and math.floor(i * 0.10) == B: ans = i break print(ans) if __name__ == "__main__": resolve()
import sys input = lambda: sys.stdin.readline().rstrip() import math def resolve(): A, B = list(map(int, input().split())) aa_min = A / 0.08 aa_max = (A + 1) / 0.08 bb_min = B / 0.1 bb_max = (B + 1) / 0.1 if aa_min < bb_max and bb_min < aa_max: print((math.ceil(max(aa_min, bb_min)))) else: print("-1") if __name__ == "__main__": resolve()
false
5.882353
[ "- ans = -1", "- for i in range(2000):", "- if math.floor(i * 0.08) == A and math.floor(i * 0.10) == B:", "- ans = i", "- break", "- print(ans)", "+ aa_min = A / 0.08", "+ aa_max = (A + 1) / 0.08", "+ bb_min = B / 0.1", "+ bb_max = (B + 1) / 0.1", ...
false
0.042615
0.048761
0.873957
[ "s885540649", "s522536324" ]
u131273629
p03448
python
s459282200
s985004302
42
19
3,060
3,060
Accepted
Accepted
54.76
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input()))/50 count = 0 for i in range(a+1): if 10*i>x: break for j in range(b+1): if 10*i+2*j>x: break for k in range(c+1): if 10*i+2*j+k == x: count += 1 print(count)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for i in range(a+1): if 500*i>x: break for j in range(b+1): if 500*i+100*j > x: break if x-500*i-100*j <= 50*c: count += 1 print(count)
15
14
255
237
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) / 50 count = 0 for i in range(a + 1): if 10 * i > x: break for j in range(b + 1): if 10 * i + 2 * j > x: break for k in range(c + 1): if 10 * i + 2 * j + k == x: count += 1 print(count)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) count = 0 for i in range(a + 1): if 500 * i > x: break for j in range(b + 1): if 500 * i + 100 * j > x: break if x - 500 * i - 100 * j <= 50 * c: count += 1 print(count)
false
6.666667
[ "-x = int(eval(input())) / 50", "+x = int(eval(input()))", "- if 10 * i > x:", "+ if 500 * i > x:", "- if 10 * i + 2 * j > x:", "+ if 500 * i + 100 * j > x:", "- for k in range(c + 1):", "- if 10 * i + 2 * j + k == x:", "- count += 1", "+ ...
false
0.077994
0.083539
0.933627
[ "s459282200", "s985004302" ]
u644907318
p02960
python
s327718331
s555794555
705
336
65,884
91,508
Accepted
Accepted
52.34
p = 10**9+7 S = input().strip() A = [[0 for k in range(13)] for j in range(13)] for j in range(13): for k in range(13): for m in range(10): if (10*k+m)%13==j: A[j][k] = 1 break B = [[0 for _ in range(10)] for _ in range(13)] for j in range(13): for m in range(10): for k in range(13): if (10*k+m)%13==j: B[j][m] = k break N = len(S) dp = [[0 for _ in range(13)] for _ in range(N+1)] for j in range(13): if S[0]!="?": dp[1][j] = int(int(S[0])==j) else: if j<10: dp[1][j] = 1 for i in range(2,N+1): for j in range(13): if S[i-1]!="?": dp[i][j] = (dp[i][j]+dp[i-1][B[j][int(S[i-1])]])%p else: for k in range(13): dp[i][j] = (dp[i][j]+dp[i-1][k]*A[j][k])%p print((dp[N][5]))
p = 10**9+7 S = input().strip() N = len(S) dp = [[0 for _ in range(13)] for _ in range(N+1)] for m in range(13): dp[0][0] = 1 for i in range(1,N+1): for m in range(13): if S[i-1]=="?": for j in range(10): dp[i][(m*10+j)%13] = (dp[i][(m*10+j)%13]+dp[i-1][m])%p else: dp[i][(m*10+int(S[i-1]))%13] = (dp[i][(m*10+int(S[i-1]))%13]+dp[i-1][m])%p print((dp[N][5]))
32
14
907
433
p = 10**9 + 7 S = input().strip() A = [[0 for k in range(13)] for j in range(13)] for j in range(13): for k in range(13): for m in range(10): if (10 * k + m) % 13 == j: A[j][k] = 1 break B = [[0 for _ in range(10)] for _ in range(13)] for j in range(13): for m in range(10): for k in range(13): if (10 * k + m) % 13 == j: B[j][m] = k break N = len(S) dp = [[0 for _ in range(13)] for _ in range(N + 1)] for j in range(13): if S[0] != "?": dp[1][j] = int(int(S[0]) == j) else: if j < 10: dp[1][j] = 1 for i in range(2, N + 1): for j in range(13): if S[i - 1] != "?": dp[i][j] = (dp[i][j] + dp[i - 1][B[j][int(S[i - 1])]]) % p else: for k in range(13): dp[i][j] = (dp[i][j] + dp[i - 1][k] * A[j][k]) % p print((dp[N][5]))
p = 10**9 + 7 S = input().strip() N = len(S) dp = [[0 for _ in range(13)] for _ in range(N + 1)] for m in range(13): dp[0][0] = 1 for i in range(1, N + 1): for m in range(13): if S[i - 1] == "?": for j in range(10): dp[i][(m * 10 + j) % 13] = (dp[i][(m * 10 + j) % 13] + dp[i - 1][m]) % p else: dp[i][(m * 10 + int(S[i - 1])) % 13] = ( dp[i][(m * 10 + int(S[i - 1])) % 13] + dp[i - 1][m] ) % p print((dp[N][5]))
false
56.25
[ "-A = [[0 for k in range(13)] for j in range(13)]", "-for j in range(13):", "- for k in range(13):", "- for m in range(10):", "- if (10 * k + m) % 13 == j:", "- A[j][k] = 1", "- break", "-B = [[0 for _ in range(10)] for _ in range(13)]", "-for j in ...
false
0.1294
0.045323
2.85508
[ "s327718331", "s555794555" ]
u423665486
p04031
python
s800227979
s544666348
187
170
38,768
38,768
Accepted
Accepted
9.09
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) ans = 100**6 for i in range(-100, 101): tmp = 0 for j in a: if i == j: continue tmp += (j - i)**2 if tmp < ans: ans = tmp print(ans) resolve()
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) ans = 10000000 for i in range(-100, 101): s = 0 for j in a: s += (i-j)**2 if ans > s: ans = s print(ans) resolve()
14
12
247
210
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) ans = 100**6 for i in range(-100, 101): tmp = 0 for j in a: if i == j: continue tmp += (j - i) ** 2 if tmp < ans: ans = tmp print(ans) resolve()
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) ans = 10000000 for i in range(-100, 101): s = 0 for j in a: s += (i - j) ** 2 if ans > s: ans = s print(ans) resolve()
false
14.285714
[ "- ans = 100**6", "+ ans = 10000000", "- tmp = 0", "+ s = 0", "- if i == j:", "- continue", "- tmp += (j - i) ** 2", "- if tmp < ans:", "- ans = tmp", "+ s += (i - j) ** 2", "+ if ans > s:", "+ ...
false
0.03974
0.039821
0.997973
[ "s800227979", "s544666348" ]
u126232616
p03252
python
s381455143
s195101269
173
43
20,400
4,144
Accepted
Accepted
75.14
S,T = eval(input()),eval(input()) str = "abcdefghijklmnopqrstuvwxyz" dic,dic2 = [[] for _ in str],[[] for _ in str] for i in range(len(S)): dic[str.index(S[i])].append(i) for i in range(len(T)): dic2[str.index(T[i])].append(i) dic.sort() dic2.sort() print(("Yes" if dic == dic2 else "No"))
from collections import Counter S,T = eval(input()),eval(input()) Sc, Tc = Counter(S),Counter(T) print(("Yes" if sorted(Sc.values()) == sorted(Tc.values()) else "No"))
10
5
293
158
S, T = eval(input()), eval(input()) str = "abcdefghijklmnopqrstuvwxyz" dic, dic2 = [[] for _ in str], [[] for _ in str] for i in range(len(S)): dic[str.index(S[i])].append(i) for i in range(len(T)): dic2[str.index(T[i])].append(i) dic.sort() dic2.sort() print(("Yes" if dic == dic2 else "No"))
from collections import Counter S, T = eval(input()), eval(input()) Sc, Tc = Counter(S), Counter(T) print(("Yes" if sorted(Sc.values()) == sorted(Tc.values()) else "No"))
false
50
[ "+from collections import Counter", "+", "-str = \"abcdefghijklmnopqrstuvwxyz\"", "-dic, dic2 = [[] for _ in str], [[] for _ in str]", "-for i in range(len(S)):", "- dic[str.index(S[i])].append(i)", "-for i in range(len(T)):", "- dic2[str.index(T[i])].append(i)", "-dic.sort()", "-dic2.sort()...
false
0.047062
0.03487
1.349665
[ "s381455143", "s195101269" ]
u459418423
p00001
python
s565037689
s678708145
30
20
7,556
7,628
Accepted
Accepted
33.33
heights = [] for i in range(10): heights.append(int(eval(input()))) for i in range(10): for j in range(i,10): if (heights[j] > heights[i]): w = heights[i] heights[i] = heights[j] heights[j] = w for i in range(3): print((heights[i]))
heights = [] for i in range(10): heights.append(int(eval(input()))) for i in range(10): for j in range(i,10): if (heights[j] > heights[i]): w = heights[i] heights[i] = heights[j] heights[j] = w print((heights[0])) print((heights[1])) print((heights[2]))
13
14
294
308
heights = [] for i in range(10): heights.append(int(eval(input()))) for i in range(10): for j in range(i, 10): if heights[j] > heights[i]: w = heights[i] heights[i] = heights[j] heights[j] = w for i in range(3): print((heights[i]))
heights = [] for i in range(10): heights.append(int(eval(input()))) for i in range(10): for j in range(i, 10): if heights[j] > heights[i]: w = heights[i] heights[i] = heights[j] heights[j] = w print((heights[0])) print((heights[1])) print((heights[2]))
false
7.142857
[ "-for i in range(3):", "- print((heights[i]))", "+print((heights[0]))", "+print((heights[1]))", "+print((heights[2]))" ]
false
0.121628
0.085586
1.421118
[ "s565037689", "s678708145" ]
u011062360
p02947
python
s790376028
s957025426
374
234
26,632
24,060
Accepted
Accepted
37.43
import math n = int(eval(input())) list_voc = [str(eval(input())) for _ in range(n)] list_mo = [] for i, s in enumerate(list_voc): list_n = list(s) list_n.sort() list_n = ''.join(list_n) list_mo.append(list_n) ans = {} for s in list_mo: if s in ans: ans[s] += 1 else: ans[s] = 1 ans_val = [] def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result for s in ans: if ans[s] != 1: ans_val.append(cmb(ans[s], 2)) print((sum(ans_val)))
from operator import mul from functools import reduce def cmb(n,r): r = min(n-r,r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1,r + 1))) return over // under from collections import Counter n = int(eval(input())) list_N = [] ans = 0 for _ in range(n): s = sorted(eval(input())) list_N.append("".join(s)) list_M = list(Counter(list_N).values()) for i in list_M: if i != 1: ans += cmb(i, 2) print(ans)
50
24
1,025
496
import math n = int(eval(input())) list_voc = [str(eval(input())) for _ in range(n)] list_mo = [] for i, s in enumerate(list_voc): list_n = list(s) list_n.sort() list_n = "".join(list_n) list_mo.append(list_n) ans = {} for s in list_mo: if s in ans: ans[s] += 1 else: ans[s] = 1 ans_val = [] def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result for s in ans: if ans[s] != 1: ans_val.append(cmb(ans[s], 2)) print((sum(ans_val)))
from operator import mul from functools import reduce def cmb(n, r): r = min(n - r, r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1, r + 1))) return over // under from collections import Counter n = int(eval(input())) list_N = [] ans = 0 for _ in range(n): s = sorted(eval(input())) list_N.append("".join(s)) list_M = list(Counter(list_N).values()) for i in list_M: if i != 1: ans += cmb(i, 2) print(ans)
false
52
[ "-import math", "-", "-n = int(eval(input()))", "-list_voc = [str(eval(input())) for _ in range(n)]", "-list_mo = []", "-for i, s in enumerate(list_voc):", "- list_n = list(s)", "- list_n.sort()", "- list_n = \"\".join(list_n)", "- list_mo.append(list_n)", "-ans = {}", "-for s in l...
false
0.044294
0.077283
0.573135
[ "s790376028", "s957025426" ]
u285022453
p03371
python
s889325034
s885414560
206
89
2,940
8,972
Accepted
Accepted
56.8
# https://atcoder.jp/contests/abc095/tasks/arc096 # 値段,枚数 A, B, C, X, Y = list(map(int, input().split())) ans = float("inf") for i in range(10 ** 5 * 2): ans = min(ans, max(X - i, 0) * A + max(Y - i, 0) * B + 2 * i * C) print(ans)
a, b, c, x, y = list(map(int, input().split())) ans = float('inf') for i in range(10 ** 5 + 1): price = i * 2 * c if x > i: price += a * (x - i) if y > i: price += b * (y - i) ans = min(ans, price) print(ans)
10
12
241
248
# https://atcoder.jp/contests/abc095/tasks/arc096 # 値段,枚数 A, B, C, X, Y = list(map(int, input().split())) ans = float("inf") for i in range(10**5 * 2): ans = min(ans, max(X - i, 0) * A + max(Y - i, 0) * B + 2 * i * C) print(ans)
a, b, c, x, y = list(map(int, input().split())) ans = float("inf") for i in range(10**5 + 1): price = i * 2 * c if x > i: price += a * (x - i) if y > i: price += b * (y - i) ans = min(ans, price) print(ans)
false
16.666667
[ "-# https://atcoder.jp/contests/abc095/tasks/arc096", "-# 値段,枚数", "-A, B, C, X, Y = list(map(int, input().split()))", "+a, b, c, x, y = list(map(int, input().split()))", "-for i in range(10**5 * 2):", "- ans = min(ans, max(X - i, 0) * A + max(Y - i, 0) * B + 2 * i * C)", "+for i in range(10**5 + 1):"...
false
0.651545
0.422112
1.543534
[ "s889325034", "s885414560" ]
u745514010
p02603
python
s243181691
s672457262
34
29
9,232
9,192
Accepted
Accepted
14.71
n = int(eval(input())) alst = list(map(int, input().split())) lst = [[0, [0, 0]] for _ in range(n)] lst[0][0] = 1000 lst[0][1][0] = 1000 // alst[0] lst[0][1][1] = 1000 % alst[0] for i, num in enumerate(alst[1:], start = 1): m1 = lst[i - 1][1][1] + lst[i - 1][1][0] * num lst[i][0] = max(lst[i - 1][0], m1) lst[i][1][0] = lst[i][0] // num lst[i][1][1] = lst[i][0] % num print((lst[-1][0]))
n = int(eval(input())) alst = list(map(int, input().split())) dp = [[1000, [0, 0]]] for a in alst: tmp1 = max(dp[-1][0], dp[-1][1][0] * a + dp[-1][1][1]) tmp2 = tmp1 // a tmp3 = tmp1 % a dp.append([tmp1, [tmp2, tmp3]]) print((dp[-1][0]))
14
10
415
255
n = int(eval(input())) alst = list(map(int, input().split())) lst = [[0, [0, 0]] for _ in range(n)] lst[0][0] = 1000 lst[0][1][0] = 1000 // alst[0] lst[0][1][1] = 1000 % alst[0] for i, num in enumerate(alst[1:], start=1): m1 = lst[i - 1][1][1] + lst[i - 1][1][0] * num lst[i][0] = max(lst[i - 1][0], m1) lst[i][1][0] = lst[i][0] // num lst[i][1][1] = lst[i][0] % num print((lst[-1][0]))
n = int(eval(input())) alst = list(map(int, input().split())) dp = [[1000, [0, 0]]] for a in alst: tmp1 = max(dp[-1][0], dp[-1][1][0] * a + dp[-1][1][1]) tmp2 = tmp1 // a tmp3 = tmp1 % a dp.append([tmp1, [tmp2, tmp3]]) print((dp[-1][0]))
false
28.571429
[ "-lst = [[0, [0, 0]] for _ in range(n)]", "-lst[0][0] = 1000", "-lst[0][1][0] = 1000 // alst[0]", "-lst[0][1][1] = 1000 % alst[0]", "-for i, num in enumerate(alst[1:], start=1):", "- m1 = lst[i - 1][1][1] + lst[i - 1][1][0] * num", "- lst[i][0] = max(lst[i - 1][0], m1)", "- lst[i][1][0] = lst...
false
0.035492
0.033391
1.062933
[ "s243181691", "s672457262" ]
u442396147
p03164
python
s810369857
s729985575
1,196
710
310,628
178,040
Accepted
Accepted
40.64
import sys import pdb input = sys.stdin.readline N, W = list(map(int, input().split())) ws = [0] vs = [0] for _ in range(N): w, v = list(map(int, input().split())) ws.append(w) vs.append(v) inf = 2e11 V = int(sum(vs)) # N * max(vs) # V = int(100 * 1e3) # N * max(vs) # Weight[i番目までの品番][価値j] Weight = [[inf for _ in range(V+1)] for __ in range(N+1)] if ws[1] <= W: Weight[1][vs[1]] = ws[1] value_max = vs[1] else: value_max = 0 for _ in range(N+1): Weight[_][0] = 0 # pdb.set_trace() for num in range(2, N+1): for value in range(1, V+1): if value >= vs[num]: # 新しい品物を入れられるとき Weight[num][value] = min(Weight[num][value], Weight[num-1][value], Weight[num-1][value-vs[num]] + ws[num]) if Weight[num][value] <= W: value_max = max(value_max, value) else: Weight[num][value] = inf else: # 新しい品物を入れられないとき # 重さを変えることはできない Weight[num][value] = Weight[num-1][value] # Weight[num][value] = max(Weight[num][value], Weight[num-1][value]) # print(Weight) print(value_max)
import sys import pdb input = sys.stdin.readline N, W = list(map(int, input().split())) ws = [0] vs = [0] for _ in range(N): w, v = list(map(int, input().split())) ws.append(w) vs.append(v) inf = sum(ws)+1 V = int(sum(vs)) # N * max(vs) # V = int(100 * 1e3) # N * max(vs) # Weight[i番目までの品番][価値j] Weight = [[inf for _ in range(V+1)] for __ in range(N+1)] if ws[1] <= W: Weight[1][vs[1]] = ws[1] value_max = vs[1] else: value_max = 0 for _ in range(N+1): Weight[_][0] = 0 # pdb.set_trace() for num in range(2, N+1): for value in range(1, V+1): if value >= vs[num]: # 新しい品物を入れられるとき Weight[num][value] = min(Weight[num][value], Weight[num-1][value], Weight[num-1][value-vs[num]] + ws[num]) if Weight[num][value] <= W: value_max = max(value_max, value) else: Weight[num][value] = inf else: # 新しい品物を入れられないとき # 重さを変えることはできない Weight[num][value] = Weight[num-1][value] # Weight[num][value] = max(Weight[num][value], Weight[num-1][value]) # print(Weight) print(value_max)
45
45
1,081
1,086
import sys import pdb input = sys.stdin.readline N, W = list(map(int, input().split())) ws = [0] vs = [0] for _ in range(N): w, v = list(map(int, input().split())) ws.append(w) vs.append(v) inf = 2e11 V = int(sum(vs)) # N * max(vs) # V = int(100 * 1e3) # N * max(vs) # Weight[i番目までの品番][価値j] Weight = [[inf for _ in range(V + 1)] for __ in range(N + 1)] if ws[1] <= W: Weight[1][vs[1]] = ws[1] value_max = vs[1] else: value_max = 0 for _ in range(N + 1): Weight[_][0] = 0 # pdb.set_trace() for num in range(2, N + 1): for value in range(1, V + 1): if value >= vs[num]: # 新しい品物を入れられるとき Weight[num][value] = min( Weight[num][value], Weight[num - 1][value], Weight[num - 1][value - vs[num]] + ws[num], ) if Weight[num][value] <= W: value_max = max(value_max, value) else: Weight[num][value] = inf else: # 新しい品物を入れられないとき # 重さを変えることはできない Weight[num][value] = Weight[num - 1][value] # Weight[num][value] = max(Weight[num][value], Weight[num-1][value]) # print(Weight) print(value_max)
import sys import pdb input = sys.stdin.readline N, W = list(map(int, input().split())) ws = [0] vs = [0] for _ in range(N): w, v = list(map(int, input().split())) ws.append(w) vs.append(v) inf = sum(ws) + 1 V = int(sum(vs)) # N * max(vs) # V = int(100 * 1e3) # N * max(vs) # Weight[i番目までの品番][価値j] Weight = [[inf for _ in range(V + 1)] for __ in range(N + 1)] if ws[1] <= W: Weight[1][vs[1]] = ws[1] value_max = vs[1] else: value_max = 0 for _ in range(N + 1): Weight[_][0] = 0 # pdb.set_trace() for num in range(2, N + 1): for value in range(1, V + 1): if value >= vs[num]: # 新しい品物を入れられるとき Weight[num][value] = min( Weight[num][value], Weight[num - 1][value], Weight[num - 1][value - vs[num]] + ws[num], ) if Weight[num][value] <= W: value_max = max(value_max, value) else: Weight[num][value] = inf else: # 新しい品物を入れられないとき # 重さを変えることはできない Weight[num][value] = Weight[num - 1][value] # Weight[num][value] = max(Weight[num][value], Weight[num-1][value]) # print(Weight) print(value_max)
false
0
[ "-inf = 2e11", "+inf = sum(ws) + 1" ]
false
0.096258
0.042455
2.267261
[ "s810369857", "s729985575" ]
u994988729
p03403
python
s826520910
s206241206
232
144
14,176
20,628
Accepted
Accepted
37.93
N = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] dist = 0 for x, y in zip(A[:-1], A[1:]): dist += abs(x - y) for i in range(1, N + 1): l, m, r = A[i - 1], A[i], A[i + 1] d = dist d -= abs(l - m) d -= abs(r - m) d += abs(r - l) print(d)
N = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] d = [x - y for y, x in zip(A[:-1], A[1:])] dist = sum(abs(i) for i in d) for i in range(N): ans = dist - abs(d[i]) - abs(d[i + 1]) ans += abs(A[i] - A[i + 2]) print(ans)
14
10
294
257
N = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] dist = 0 for x, y in zip(A[:-1], A[1:]): dist += abs(x - y) for i in range(1, N + 1): l, m, r = A[i - 1], A[i], A[i + 1] d = dist d -= abs(l - m) d -= abs(r - m) d += abs(r - l) print(d)
N = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] d = [x - y for y, x in zip(A[:-1], A[1:])] dist = sum(abs(i) for i in d) for i in range(N): ans = dist - abs(d[i]) - abs(d[i + 1]) ans += abs(A[i] - A[i + 2]) print(ans)
false
28.571429
[ "-dist = 0", "-for x, y in zip(A[:-1], A[1:]):", "- dist += abs(x - y)", "-for i in range(1, N + 1):", "- l, m, r = A[i - 1], A[i], A[i + 1]", "- d = dist", "- d -= abs(l - m)", "- d -= abs(r - m)", "- d += abs(r - l)", "- print(d)", "+d = [x - y for y, x in zip(A[:-1], A[1:...
false
0.039853
0.045032
0.885006
[ "s826520910", "s206241206" ]
u689780189
p03478
python
s522116453
s755633518
39
28
2,940
3,060
Accepted
Accepted
28.21
N, A, B = list(map(int, input().split())) Total = 0 for i in range(1, N + 1): total = 0 str_i = str(i) len_i = len(str_i) for l in range(len_i): total += int(str_i[l]) if A <= total <= B: Total += i print(Total)
N, A, B = list(map(int, input().split())) All = 0 for i in range(1, N + 1): total = 0 j = i while j != 0: total += j % 10 j = j // 10 if A <= total <= B: All += i print(All)
11
13
252
221
N, A, B = list(map(int, input().split())) Total = 0 for i in range(1, N + 1): total = 0 str_i = str(i) len_i = len(str_i) for l in range(len_i): total += int(str_i[l]) if A <= total <= B: Total += i print(Total)
N, A, B = list(map(int, input().split())) All = 0 for i in range(1, N + 1): total = 0 j = i while j != 0: total += j % 10 j = j // 10 if A <= total <= B: All += i print(All)
false
15.384615
[ "-Total = 0", "+All = 0", "- str_i = str(i)", "- len_i = len(str_i)", "- for l in range(len_i):", "- total += int(str_i[l])", "+ j = i", "+ while j != 0:", "+ total += j % 10", "+ j = j // 10", "- Total += i", "-print(Total)", "+ All += i", ...
false
0.032731
0.041163
0.795158
[ "s522116453", "s755633518" ]
u200887663
p03325
python
s891215511
s183370603
80
62
4,148
4,212
Accepted
Accepted
22.5
n=int(eval(input())) #a,b=map(int,input().split()) al=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] count=0 for a in al: temp=0 v=a while v%2==0: v=v//2 temp+=1 count+=temp print(count)
n=int(eval(input())) #a,b,n=map(int,input().split()) al=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] def div2(v): res=0 if v==0: return res while v%2==0: v=v//2 res+=1 return res ans=0 for ai in al: ans+=div2(ai) print(ans)
15
18
267
321
n = int(eval(input())) # a,b=map(int,input().split()) al = list(map(int, input().split())) # l=[list(map(int,input().split())) for i in range(n)] count = 0 for a in al: temp = 0 v = a while v % 2 == 0: v = v // 2 temp += 1 count += temp print(count)
n = int(eval(input())) # a,b,n=map(int,input().split()) al = list(map(int, input().split())) # l=[list(map(int,input().split())) for i in range(n)] def div2(v): res = 0 if v == 0: return res while v % 2 == 0: v = v // 2 res += 1 return res ans = 0 for ai in al: ans += div2(ai) print(ans)
false
16.666667
[ "-# a,b=map(int,input().split())", "+# a,b,n=map(int,input().split())", "-count = 0", "-for a in al:", "- temp = 0", "- v = a", "+def div2(v):", "+ res = 0", "+ if v == 0:", "+ return res", "- temp += 1", "- count += temp", "-print(count)", "+ res += 1",...
false
0.037275
0.036402
1.023976
[ "s891215511", "s183370603" ]
u113971909
p02601
python
s625920521
s763952181
39
27
9,260
9,188
Accepted
Accepted
30.77
#!/usr/bin python3 # -*- coding: utf-8 -*- RGB_ = list(map(int, input().split())) K = int(eval(input())) from itertools import product L = list(product(list(range(3)), repeat=K)) for l in L: RGB=RGB_[:] for i in l: RGB[i] = RGB[i]*2 if RGB[2]>RGB[1]>RGB[0]: print('Yes') exit() print('No')
#!/usr/bin python3 # -*- coding: utf-8 -*- A, B, C = list(map(int, input().split())) K = int(eval(input())) ret = 0 while B<=A: B *= 2 ret += 1 while C<=B: C *= 2 ret += 1 if ret <=K: print('Yes') else: print('No')
16
16
343
243
#!/usr/bin python3 # -*- coding: utf-8 -*- RGB_ = list(map(int, input().split())) K = int(eval(input())) from itertools import product L = list(product(list(range(3)), repeat=K)) for l in L: RGB = RGB_[:] for i in l: RGB[i] = RGB[i] * 2 if RGB[2] > RGB[1] > RGB[0]: print("Yes") exit() print("No")
#!/usr/bin python3 # -*- coding: utf-8 -*- A, B, C = list(map(int, input().split())) K = int(eval(input())) ret = 0 while B <= A: B *= 2 ret += 1 while C <= B: C *= 2 ret += 1 if ret <= K: print("Yes") else: print("No")
false
0
[ "-RGB_ = list(map(int, input().split()))", "+A, B, C = list(map(int, input().split()))", "-from itertools import product", "-", "-L = list(product(list(range(3)), repeat=K))", "-for l in L:", "- RGB = RGB_[:]", "- for i in l:", "- RGB[i] = RGB[i] * 2", "- if RGB[2] > RGB[1] > R...
false
0.16973
0.037395
4.538824
[ "s625920521", "s763952181" ]
u887207211
p03564
python
s623940016
s243329034
20
18
3,060
2,940
Accepted
Accepted
10
N = int(eval(input())) K = int(eval(input())) ans = 1 for i in range(N): if(ans*2 > ans+K): ans += K else: ans *= 2 print(ans)
N = int(eval(input())) K = int(eval(input())) ans = 0 num = 1 for i in range(N): if(num*2 < num+K): num *= 2 else: num += K ans = max(ans, num) print(ans)
10
11
136
166
N = int(eval(input())) K = int(eval(input())) ans = 1 for i in range(N): if ans * 2 > ans + K: ans += K else: ans *= 2 print(ans)
N = int(eval(input())) K = int(eval(input())) ans = 0 num = 1 for i in range(N): if num * 2 < num + K: num *= 2 else: num += K ans = max(ans, num) print(ans)
false
9.090909
[ "-ans = 1", "+ans = 0", "+num = 1", "- if ans * 2 > ans + K:", "- ans += K", "+ if num * 2 < num + K:", "+ num *= 2", "- ans *= 2", "+ num += K", "+ ans = max(ans, num)" ]
false
0.036175
0.037198
0.972482
[ "s623940016", "s243329034" ]
u179169725
p02768
python
s615888428
s878857611
822
704
3,192
3,192
Accepted
Accepted
14.36
# https://atcoder.jp/contests/abc156/submissions/10277689 # コンテスト中に通せたけどmodintクラスで実装してみる import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) class ModInt: def __init__(self, x, MOD=10 ** 9 + 7): self.mod = MOD self.x = x if 0 <= x < MOD else x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): if isinstance(other, ModInt): return ModInt(self.x + other.x, self.mod) else: return ModInt(self.x + other, self.mod) def __sub__(self, other): if isinstance(other, ModInt): return ModInt(self.x - other.x, self.mod) else: return ModInt(self.x - other, self.mod) def __mul__(self, other): if isinstance(other, ModInt): return ModInt(self.x * other.x, self.mod) else: return ModInt(self.x * other, self.mod) def __truediv__(self, other): if isinstance(other, ModInt): return ModInt(self.x * pow(other.x, self.mod - 2, self.mod)) else: return ModInt(self.x * pow(other, self.mod - 2, self.mod)) def __pow__(self, other): if isinstance(other, ModInt): return ModInt(pow(self.x, other.x, self.mod)) else: return ModInt(pow(self.x, other, self.mod)) __radd__ = __add__ def __rsub__(self, other): # 演算の順序が逆 if isinstance(other, ModInt): return ModInt(other.x - self.x, self.mod) else: return ModInt(other - self.x, self.mod) __rmul__ = __mul__ def __rtruediv__(self, other): if isinstance(other, ModInt): return ModInt(other.x * pow(self.x, self.mod - 2, self.mod)) else: return ModInt(other * pow(self.x, self.mod - 2, self.mod)) def __rpow__(self, other): if isinstance(other, ModInt): return ModInt(pow(other.x, self.x, self.mod)) else: return ModInt(pow(other, self.x, self.mod)) def combination_mod(n, r, mod): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = 1 for i in range(r): nf = nf * (n - i) % mod rf = rf * (i + 1) % mod return nf * pow(rf, mod - 2, mod) % mod def combination(n, r): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = ModInt(1) for i in range(r): nf = nf * (n - i) rf = rf * (i + 1) return nf / rf # すべての通り(2^n-1)からnCa,nCbを引けば良い MOD = 10**9 + 7 n, a, b = read_ints() # tmp = pow(2, n, MOD) - 1 # ans = tmp - combination_mod(n, a, MOD) - combination_mod(n, b, MOD) # print(ans % MOD) tmp = ModInt(2)**n - 1 ans = tmp - combination(n, a) - combination(n, b) print(ans)
# https://atcoder.jp/contests/abc156/submissions/10277689 # コンテスト中に通せたけどmodintクラスで実装してみる import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): if isinstance(other, ModInt): return ModInt(self.x + other.x) else: return ModInt(self.x + other) def __sub__(self, other): if isinstance(other, ModInt): return ModInt(self.x - other.x) else: return ModInt(self.x - other) def __mul__(self, other): if isinstance(other, ModInt): return ModInt(self.x * other.x) else: return ModInt(self.x * other) def __truediv__(self, other): if isinstance(other, ModInt): return ModInt(self.x * pow(other.x, MOD - 2, MOD)) else: return ModInt(self.x * pow(other, MOD - 2, MOD)) def __pow__(self, other): if isinstance(other, ModInt): return ModInt(pow(self.x, other.x, MOD)) else: return ModInt(pow(self.x, other, MOD)) __radd__ = __add__ def __rsub__(self, other): # 演算の順序が逆 if isinstance(other, ModInt): return ModInt(other.x - self.x) else: return ModInt(other - self.x) __rmul__ = __mul__ def __rtruediv__(self, other): if isinstance(other, ModInt): return ModInt(other.x * pow(self.x, MOD - 2, MOD)) else: return ModInt(other * pow(self.x, MOD - 2, MOD)) def __rpow__(self, other): if isinstance(other, ModInt): return ModInt(pow(other.x, self.x, MOD)) else: return ModInt(pow(other, self.x, MOD)) def combination_mod(n, r, mod): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = 1 for i in range(r): nf = nf * (n - i) % mod rf = rf * (i + 1) % mod return nf * pow(rf, mod - 2, mod) % mod def combination(n, r): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = ModInt(1) for i in range(r): nf = nf * (n - i) rf = rf * (i + 1) return nf / rf # すべての通り(2^n-1)からnCa,nCbを引けば良い MOD = 10**9 + 7 n, a, b = read_ints() # tmp = pow(2, n, MOD) - 1 # ans = tmp - combination_mod(n, a, MOD) - combination_mod(n, b, MOD) # print(ans % MOD) tmp = ModInt(2)**n - 1 ans = tmp - combination(n, a) - combination(n, b) print(ans)
106
105
2,929
2,725
# https://atcoder.jp/contests/abc156/submissions/10277689 # コンテスト中に通せたけどmodintクラスで実装してみる import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) class ModInt: def __init__(self, x, MOD=10**9 + 7): self.mod = MOD self.x = x if 0 <= x < MOD else x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): if isinstance(other, ModInt): return ModInt(self.x + other.x, self.mod) else: return ModInt(self.x + other, self.mod) def __sub__(self, other): if isinstance(other, ModInt): return ModInt(self.x - other.x, self.mod) else: return ModInt(self.x - other, self.mod) def __mul__(self, other): if isinstance(other, ModInt): return ModInt(self.x * other.x, self.mod) else: return ModInt(self.x * other, self.mod) def __truediv__(self, other): if isinstance(other, ModInt): return ModInt(self.x * pow(other.x, self.mod - 2, self.mod)) else: return ModInt(self.x * pow(other, self.mod - 2, self.mod)) def __pow__(self, other): if isinstance(other, ModInt): return ModInt(pow(self.x, other.x, self.mod)) else: return ModInt(pow(self.x, other, self.mod)) __radd__ = __add__ def __rsub__(self, other): # 演算の順序が逆 if isinstance(other, ModInt): return ModInt(other.x - self.x, self.mod) else: return ModInt(other - self.x, self.mod) __rmul__ = __mul__ def __rtruediv__(self, other): if isinstance(other, ModInt): return ModInt(other.x * pow(self.x, self.mod - 2, self.mod)) else: return ModInt(other * pow(self.x, self.mod - 2, self.mod)) def __rpow__(self, other): if isinstance(other, ModInt): return ModInt(pow(other.x, self.x, self.mod)) else: return ModInt(pow(other, self.x, self.mod)) def combination_mod(n, r, mod): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = 1 for i in range(r): nf = nf * (n - i) % mod rf = rf * (i + 1) % mod return nf * pow(rf, mod - 2, mod) % mod def combination(n, r): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = ModInt(1) for i in range(r): nf = nf * (n - i) rf = rf * (i + 1) return nf / rf # すべての通り(2^n-1)からnCa,nCbを引けば良い MOD = 10**9 + 7 n, a, b = read_ints() # tmp = pow(2, n, MOD) - 1 # ans = tmp - combination_mod(n, a, MOD) - combination_mod(n, b, MOD) # print(ans % MOD) tmp = ModInt(2) ** n - 1 ans = tmp - combination(n, a) - combination(n, b) print(ans)
# https://atcoder.jp/contests/abc156/submissions/10277689 # コンテスト中に通せたけどmodintクラスで実装してみる import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): if isinstance(other, ModInt): return ModInt(self.x + other.x) else: return ModInt(self.x + other) def __sub__(self, other): if isinstance(other, ModInt): return ModInt(self.x - other.x) else: return ModInt(self.x - other) def __mul__(self, other): if isinstance(other, ModInt): return ModInt(self.x * other.x) else: return ModInt(self.x * other) def __truediv__(self, other): if isinstance(other, ModInt): return ModInt(self.x * pow(other.x, MOD - 2, MOD)) else: return ModInt(self.x * pow(other, MOD - 2, MOD)) def __pow__(self, other): if isinstance(other, ModInt): return ModInt(pow(self.x, other.x, MOD)) else: return ModInt(pow(self.x, other, MOD)) __radd__ = __add__ def __rsub__(self, other): # 演算の順序が逆 if isinstance(other, ModInt): return ModInt(other.x - self.x) else: return ModInt(other - self.x) __rmul__ = __mul__ def __rtruediv__(self, other): if isinstance(other, ModInt): return ModInt(other.x * pow(self.x, MOD - 2, MOD)) else: return ModInt(other * pow(self.x, MOD - 2, MOD)) def __rpow__(self, other): if isinstance(other, ModInt): return ModInt(pow(other.x, self.x, MOD)) else: return ModInt(pow(other, self.x, MOD)) def combination_mod(n, r, mod): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = 1 for i in range(r): nf = nf * (n - i) % mod rf = rf * (i + 1) % mod return nf * pow(rf, mod - 2, mod) % mod def combination(n, r): if r > n: return 0 # このような通りの数は無いため便宜上こう定義する r = min(r, n - r) nf = rf = ModInt(1) for i in range(r): nf = nf * (n - i) rf = rf * (i + 1) return nf / rf # すべての通り(2^n-1)からnCa,nCbを引けば良い MOD = 10**9 + 7 n, a, b = read_ints() # tmp = pow(2, n, MOD) - 1 # ans = tmp - combination_mod(n, a, MOD) - combination_mod(n, b, MOD) # print(ans % MOD) tmp = ModInt(2) ** n - 1 ans = tmp - combination(n, a) - combination(n, b) print(ans)
false
0.943396
[ "- def __init__(self, x, MOD=10**9 + 7):", "- self.mod = MOD", "- self.x = x if 0 <= x < MOD else x % MOD", "+ def __init__(self, x):", "+ self.x = x % MOD", "- return ModInt(self.x + other.x, self.mod)", "+ return ModInt(self.x + other.x)", "- ...
false
0.617201
0.44255
1.394647
[ "s615888428", "s878857611" ]
u127499732
p02854
python
s348446998
s658467655
135
80
25,748
25,744
Accepted
Accepted
40.74
def main(): import sys from itertools import accumulate n = int(eval(input())) a = list(map(int, sys.stdin.readline().split())) b = list(accumulate(a)) diff = b[-1] total = b[-1] for x in b: diff = min(diff, abs(total - 2 * x)) print(diff) if __name__ == '__main__': main()
def main(): import sys import bisect from itertools import accumulate n = int(eval(input())) a = list(map(int, sys.stdin.readline().split())) b = list(accumulate(a)) l = b[-1] i = bisect.bisect(b, l // 2) ans = min(abs(l - 2 * b[i - 1]), abs(l - 2 * b[i])) print(ans) if __name__ == '__main__': main()
16
17
335
360
def main(): import sys from itertools import accumulate n = int(eval(input())) a = list(map(int, sys.stdin.readline().split())) b = list(accumulate(a)) diff = b[-1] total = b[-1] for x in b: diff = min(diff, abs(total - 2 * x)) print(diff) if __name__ == "__main__": main()
def main(): import sys import bisect from itertools import accumulate n = int(eval(input())) a = list(map(int, sys.stdin.readline().split())) b = list(accumulate(a)) l = b[-1] i = bisect.bisect(b, l // 2) ans = min(abs(l - 2 * b[i - 1]), abs(l - 2 * b[i])) print(ans) if __name__ == "__main__": main()
false
5.882353
[ "+ import bisect", "- diff = b[-1]", "- total = b[-1]", "- for x in b:", "- diff = min(diff, abs(total - 2 * x))", "- print(diff)", "+ l = b[-1]", "+ i = bisect.bisect(b, l // 2)", "+ ans = min(abs(l - 2 * b[i - 1]), abs(l - 2 * b[i]))", "+ print(ans)" ]
false
0.042038
0.038782
1.083948
[ "s348446998", "s658467655" ]
u579699847
p03161
python
s662562630
s630586128
515
402
57,312
55,008
Accepted
Accepted
21.94
import itertools,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() h = LI() dp = [float('INF')]*N dp[0] = 0 for i,j in itertools.product(list(range(N)),list(range(1,K+1))): if i+j>=N: continue dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i])) print((dp[-1]))
import sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() h = LI() dp = [float('INF')]*(N) dp[0] = 0 for i in range(1,N): for j in range(max(0,i-K),i): dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j])) print((dp[-1]))
11
10
302
260
import itertools, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = LI() h = LI() dp = [float("INF")] * N dp[0] = 0 for i, j in itertools.product(list(range(N)), list(range(1, K + 1))): if i + j >= N: continue dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) print((dp[-1]))
import sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = LI() h = LI() dp = [float("INF")] * (N) dp[0] = 0 for i in range(1, N): for j in range(max(0, i - K), i): dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])) print((dp[-1]))
false
9.090909
[ "-import itertools, sys", "+import sys", "-dp = [float(\"INF\")] * N", "+dp = [float(\"INF\")] * (N)", "-for i, j in itertools.product(list(range(N)), list(range(1, K + 1))):", "- if i + j >= N:", "- continue", "- dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))", "+for i in ran...
false
0.043183
0.080095
0.539154
[ "s662562630", "s630586128" ]
u029251499
p02598
python
s557613750
s007857562
1,932
1,406
31,108
31,064
Accepted
Accepted
27.23
import math n,k = list(map(int,input().split())) a = [int(i) for i in input().split()] a.sort() r = a[n-1] l = 0 def calc(t,x): return math.ceil(t / x) - 1 while r - l > 1: mid = (r+l)//2 count = 0 for i in a: count += calc(i,mid) if count > k: l = mid else: r = mid print(r)
import math n,k = list(map(int,input().split())) a = [int(i) for i in input().split()] a.sort() r = a[n-1] l = 0 def calc(t,x): return (t-1) // x while r - l > 1: mid = (r+l)//2 count = 0 for i in a: count += calc(i,mid) if count > k: l = mid else: r = mid print(r)
25
25
349
339
import math n, k = list(map(int, input().split())) a = [int(i) for i in input().split()] a.sort() r = a[n - 1] l = 0 def calc(t, x): return math.ceil(t / x) - 1 while r - l > 1: mid = (r + l) // 2 count = 0 for i in a: count += calc(i, mid) if count > k: l = mid else: r = mid print(r)
import math n, k = list(map(int, input().split())) a = [int(i) for i in input().split()] a.sort() r = a[n - 1] l = 0 def calc(t, x): return (t - 1) // x while r - l > 1: mid = (r + l) // 2 count = 0 for i in a: count += calc(i, mid) if count > k: l = mid else: r = mid print(r)
false
0
[ "- return math.ceil(t / x) - 1", "+ return (t - 1) // x" ]
false
0.153171
0.037704
4.062438
[ "s557613750", "s007857562" ]
u525065967
p02888
python
s842537341
s413401228
1,400
1,074
3,188
3,188
Accepted
Accepted
23.29
import bisect N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ans += bisect.bisect_left(L, L[a] + L[b])-(b+1) print(ans)
N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): r = b + 1 for a in range(b): while r<N and L[r]<L[a]+L[b]: r += 1 ans += r-(b+1) print(ans)
9
10
199
212
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ans += bisect.bisect_left(L, L[a] + L[b]) - (b + 1) print(ans)
N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for b in range(N): r = b + 1 for a in range(b): while r < N and L[r] < L[a] + L[b]: r += 1 ans += r - (b + 1) print(ans)
false
10
[ "-import bisect", "-", "+ r = b + 1", "- ans += bisect.bisect_left(L, L[a] + L[b]) - (b + 1)", "+ while r < N and L[r] < L[a] + L[b]:", "+ r += 1", "+ ans += r - (b + 1)" ]
false
0.036197
0.099278
0.3646
[ "s842537341", "s413401228" ]
u761320129
p03817
python
s726857972
s787592253
24
17
3,060
3,064
Accepted
Accepted
29.17
x = int(eval(input())) n = -(-x//11) print((2*n-1 if 0<x%11<7 else 2*n))
x = int(eval(input()))-1 d,m = divmod(x,11) ans = d*2 + 1 + int(m>=6) print(ans)
3
4
66
78
x = int(eval(input())) n = -(-x // 11) print((2 * n - 1 if 0 < x % 11 < 7 else 2 * n))
x = int(eval(input())) - 1 d, m = divmod(x, 11) ans = d * 2 + 1 + int(m >= 6) print(ans)
false
25
[ "-x = int(eval(input()))", "-n = -(-x // 11)", "-print((2 * n - 1 if 0 < x % 11 < 7 else 2 * n))", "+x = int(eval(input())) - 1", "+d, m = divmod(x, 11)", "+ans = d * 2 + 1 + int(m >= 6)", "+print(ans)" ]
false
0.078448
0.113059
0.693867
[ "s726857972", "s787592253" ]
u383015480
p02698
python
s432764832
s232088809
1,938
1,368
556,864
345,652
Accepted
Accepted
29.41
#!/usr/bin/python3 import sys from bisect import bisect_left sys.setrecursionlimit(1000000) n = int(eval(input())) a = [int(i) for i in input().split()] nbs = [ [] for _ in range(n) ] for _ in range(n - 1): (u, v) = list(map(int, input().split())) nbs[u - 1].append(v - 1) nbs[v - 1].append(u - 1) mlen = [ 0 ] * n dp = [ float('inf') ] * n def getmlen(cur, p, ctail): for ch in nbs[cur]: if ch == p: continue idx = bisect_left(dp, a[ch]) ov = dp[idx] ntail = max(ctail, idx) dp[idx] = a[ch] mlen[ch] = ntail + 1 getmlen(ch, cur, ntail) dp[idx] = ov dp[0] = a[0] mlen[0] = 1 getmlen(0, -1, 0) for i in range(n): print((mlen[i]))
#!/usr/bin/python3 import sys from bisect import bisect_left sys.setrecursionlimit(1000000) n = int(eval(input())) a = [int(i) for i in input().split()] nbs = [ [] for _ in range(n) ] for _ in range(n - 1): (u, v) = list(map(int, input().split())) nbs[u - 1].append(v - 1) nbs[v - 1].append(u - 1) mlen = [ 0 ] * n def getmlen(cur, p): for ch in nbs[cur]: if ch == p: continue if a[ch] > dp[-1]: dp.append(a[ch]) mlen[ch] = len(dp) getmlen(ch, cur) dp.pop(-1) else: idx = bisect_left(dp, a[ch]) ov = dp[idx] dp[idx] = a[ch] mlen[ch] = len(dp) getmlen(ch, cur) dp[idx] = ov dp = [] dp.append(a[0]) mlen[0] = 1 getmlen(0, -1) for i in range(n): print((mlen[i]))
43
46
775
891
#!/usr/bin/python3 import sys from bisect import bisect_left sys.setrecursionlimit(1000000) n = int(eval(input())) a = [int(i) for i in input().split()] nbs = [[] for _ in range(n)] for _ in range(n - 1): (u, v) = list(map(int, input().split())) nbs[u - 1].append(v - 1) nbs[v - 1].append(u - 1) mlen = [0] * n dp = [float("inf")] * n def getmlen(cur, p, ctail): for ch in nbs[cur]: if ch == p: continue idx = bisect_left(dp, a[ch]) ov = dp[idx] ntail = max(ctail, idx) dp[idx] = a[ch] mlen[ch] = ntail + 1 getmlen(ch, cur, ntail) dp[idx] = ov dp[0] = a[0] mlen[0] = 1 getmlen(0, -1, 0) for i in range(n): print((mlen[i]))
#!/usr/bin/python3 import sys from bisect import bisect_left sys.setrecursionlimit(1000000) n = int(eval(input())) a = [int(i) for i in input().split()] nbs = [[] for _ in range(n)] for _ in range(n - 1): (u, v) = list(map(int, input().split())) nbs[u - 1].append(v - 1) nbs[v - 1].append(u - 1) mlen = [0] * n def getmlen(cur, p): for ch in nbs[cur]: if ch == p: continue if a[ch] > dp[-1]: dp.append(a[ch]) mlen[ch] = len(dp) getmlen(ch, cur) dp.pop(-1) else: idx = bisect_left(dp, a[ch]) ov = dp[idx] dp[idx] = a[ch] mlen[ch] = len(dp) getmlen(ch, cur) dp[idx] = ov dp = [] dp.append(a[0]) mlen[0] = 1 getmlen(0, -1) for i in range(n): print((mlen[i]))
false
6.521739
[ "-dp = [float(\"inf\")] * n", "-def getmlen(cur, p, ctail):", "+def getmlen(cur, p):", "- idx = bisect_left(dp, a[ch])", "- ov = dp[idx]", "- ntail = max(ctail, idx)", "- dp[idx] = a[ch]", "- mlen[ch] = ntail + 1", "- getmlen(ch, cur, ntail)", "- dp...
false
0.043383
0.043415
0.99928
[ "s432764832", "s232088809" ]
u702208001
p03631
python
s673769587
s831929550
24
17
2,940
2,940
Accepted
Accepted
29.17
n = eval(input()) print(('Yes' if n[0] == n[-1] else 'No'))
n = eval(input()) print(('Yes' if n[0] == n[2] else 'No'))
2
2
53
52
n = eval(input()) print(("Yes" if n[0] == n[-1] else "No"))
n = eval(input()) print(("Yes" if n[0] == n[2] else "No"))
false
0
[ "-print((\"Yes\" if n[0] == n[-1] else \"No\"))", "+print((\"Yes\" if n[0] == n[2] else \"No\"))" ]
false
0.046218
0.092206
0.501249
[ "s673769587", "s831929550" ]
u970937288
p02601
python
s301494464
s280840200
31
25
9,164
9,096
Accepted
Accepted
19.35
a,b,c=map(int,input().split()) k=int(input()) while b<=a: b*=2 k-=1 while c<=b: c*=2 k-=1 print("Yes")if k>=0 else print("No")
a,b,c=map(int,input().split()) k=int(input()) while b<=a: b*=2 k-=1 while c<=b: c*=2 k-=1 print("No")if k<0 else print("Yes")
9
9
150
149
a, b, c = map(int, input().split()) k = int(input()) while b <= a: b *= 2 k -= 1 while c <= b: c *= 2 k -= 1 print("Yes") if k >= 0 else print("No")
a, b, c = map(int, input().split()) k = int(input()) while b <= a: b *= 2 k -= 1 while c <= b: c *= 2 k -= 1 print("No") if k < 0 else print("Yes")
false
0
[ "-print(\"Yes\") if k >= 0 else print(\"No\")", "+print(\"No\") if k < 0 else print(\"Yes\")" ]
false
0.05747
0.056057
1.025201
[ "s301494464", "s280840200" ]
u102461423
p03855
python
s169479601
s109083861
790
652
80,584
57,872
Accepted
Accepted
17.47
import sys input = sys.stdin.readline from collections import Counter from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix N,K,L = list(map(int,input().split())) PQ = [[int(x) for x in input().split()] for _ in range(K)] RS = [[int(x) for x in input().split()] for _ in range(L)] P,Q = list(zip(*PQ)) R,S = list(zip(*RS)) g1 = csr_matrix(([1]*K,(P,Q)),(N+1,N+1)) g2 = csr_matrix(([1]*L,(R,S)),(N+1,N+1)) _,comp1 = connected_components(g1,directed = False,return_labels = True) _,comp2 = connected_components(g2,directed = False,return_labels = True) comp_pair = comp1.astype('int64') * (N+1) + comp2 c = Counter(comp_pair) answer = [c[comp_pair[i]] for i in range(1,N+1)] print((*answer))
import sys input = sys.stdin.readline from collections import Counter from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix N,K,L = list(map(int,input().split())) P = [None] * K Q = [None] * K for i in range(K): P[i], Q[i] = list(map(int,input().split())) R = [None] * L S = [None] * L for i in range(L): R[i], S[i] = list(map(int,input().split())) g1 = csr_matrix(([1]*K,(P,Q)),(N+1,N+1)) g2 = csr_matrix(([1]*L,(R,S)),(N+1,N+1)) _,comp1 = connected_components(g1,directed = False,return_labels = True) _,comp2 = connected_components(g2,directed = False,return_labels = True) comp_pair = comp1.astype('int64') * (N+1) + comp2 c = Counter(comp_pair) answer = [c[comp_pair[i]] for i in range(1,N+1)] print((*answer))
25
30
736
772
import sys input = sys.stdin.readline from collections import Counter from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix N, K, L = list(map(int, input().split())) PQ = [[int(x) for x in input().split()] for _ in range(K)] RS = [[int(x) for x in input().split()] for _ in range(L)] P, Q = list(zip(*PQ)) R, S = list(zip(*RS)) g1 = csr_matrix(([1] * K, (P, Q)), (N + 1, N + 1)) g2 = csr_matrix(([1] * L, (R, S)), (N + 1, N + 1)) _, comp1 = connected_components(g1, directed=False, return_labels=True) _, comp2 = connected_components(g2, directed=False, return_labels=True) comp_pair = comp1.astype("int64") * (N + 1) + comp2 c = Counter(comp_pair) answer = [c[comp_pair[i]] for i in range(1, N + 1)] print((*answer))
import sys input = sys.stdin.readline from collections import Counter from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix N, K, L = list(map(int, input().split())) P = [None] * K Q = [None] * K for i in range(K): P[i], Q[i] = list(map(int, input().split())) R = [None] * L S = [None] * L for i in range(L): R[i], S[i] = list(map(int, input().split())) g1 = csr_matrix(([1] * K, (P, Q)), (N + 1, N + 1)) g2 = csr_matrix(([1] * L, (R, S)), (N + 1, N + 1)) _, comp1 = connected_components(g1, directed=False, return_labels=True) _, comp2 = connected_components(g2, directed=False, return_labels=True) comp_pair = comp1.astype("int64") * (N + 1) + comp2 c = Counter(comp_pair) answer = [c[comp_pair[i]] for i in range(1, N + 1)] print((*answer))
false
16.666667
[ "-PQ = [[int(x) for x in input().split()] for _ in range(K)]", "-RS = [[int(x) for x in input().split()] for _ in range(L)]", "-P, Q = list(zip(*PQ))", "-R, S = list(zip(*RS))", "+P = [None] * K", "+Q = [None] * K", "+for i in range(K):", "+ P[i], Q[i] = list(map(int, input().split()))", "+R = [N...
false
0.357877
0.360753
0.992028
[ "s169479601", "s109083861" ]
u894258749
p03061
python
s923591598
s301992975
1,120
559
70,500
103,016
Accepted
Accepted
50.09
from collections import defaultdict from math import sqrt inpl = lambda: list(map(int,input().split())) def primes(N): P = [] for i in range(2,N): sieve = 1 for p in P: if p*p > i: break elif i % p == 0: sieve = 0 break if sieve == 0: continue else: P.append(i) return P def factorize(n, P=None): if P is None: P = primes(int(sqrt(n))+1) factor = [] power = [] for p in P: if p * p > n: break elif n % p == 0: k = 0 while n % p == 0: n //= p k += 1 factor.append(p) power.append(k) if n > 1: factor.append(n) power.append(1) return factor, power class Counter: def __init__(self, start=0): self.index = start-1 def __call__(self): self.index += 1 return self.index N = int(eval(input())) A = inpl() P_MAX = 32000 infty = 100 P = primes(P_MAX) np = defaultdict(Counter()) Np = 0 lowest_powers = [] bottle_necks = [] primelist = [] all_factors = set() for n in range(N): primes, powers = factorize(A[n],P) pp = [0]*Np for i in range(len(primes)): k = np[primes[i]] if k >= Np: Np += 1 pp.append(powers[i]) primelist.append(primes[i]) if n > 1: lowest_powers.append([0,0]) bottle_necks.append(-1) elif n == 1: lowest_powers.append([0,infty]) bottle_necks.append(0) else: lowest_powers.append([infty,infty]) bottle_necks.append(-1) else: pp[k] = powers[i] for k in range(Np): lowest = lowest_powers[k] if pp[k] == lowest[0]: lowest[1] = lowest[0] bottle_necks[k] = -1 elif pp[k] < lowest[0]: lowest[1] = lowest[0] lowest[0] = pp[k] bottle_necks[k] = n elif pp[k] < lowest[1]: lowest[1] = pp[k] bottleneck_factors = [ [] for _ in range(N) ] for k in range(Np): n = bottle_necks[k] if n >= 0: lowest = lowest_powers[k] bottleneck_factors[n].append([primelist[k],lowest[1]-lowest[0]]) best_n = -1 largest_f = 1 for n in range(N): f = 1 for pp in bottleneck_factors[n]: f *= pp[0]**pp[1] if f > largest_f: largest_f = f best_n = n ans = 1 pn = [ s[0] for s in bottleneck_factors[best_n] ] for k in range(Np): p = primelist[k] if bottle_necks[k] == best_n: ans *= p**lowest_powers[k][1] else: ans *= p**lowest_powers[k][0] print(ans)
from fractions import gcd inpl = lambda: list(map(int,input().split())) class SegCalcTree: def __init__(self, value, N=0, calc=lambda x,y: x+y): M = max(len(value),N) N = 2**(len(bin(M))-3) if N < M: N *= 2 self.N = N self.node = [None] * (2*N-1) for i, v in enumerate(value): self.node[i+N-1] = v self.calc = lambda x, y: x if y is None else y if x is None else calc(x,y) for i in range(N-2,-1,-1): left, right = self.node[2*i+1], self.node[2*i+2] self.node[i] = self.calc(left, right) def set_value(self, n, v): i = (self.N-1) + n self.node[i] = v while i > 0: i = (i-1)//2 left, right = self.node[2*i+1], self.node[2*i+2] new = self.calc(left,right) if self.node[i] == new: break else: self.node[i] = new def get(self, a=0, b=-1, k=0, l=0, r=-1): if b < 0: b = self.N if r < 0: r = self.N if a <= l and r <= b: return self.node[k] elif r <= a or b <= l: return None else: left = self.get(a,b,2*k+1,l,(l+r)//2) right = self.get(a,b,2*k+2,(l+r)//2,r) return self.calc(left,right) N = int(eval(input())) A = inpl() sct = SegCalcTree(A,calc=gcd) ans = 0 for i in range(N): a = A[i] sct.set_value(i,None) c = sct.get() if c > ans: ans = c sct.set_value(i,a) print(ans)
119
57
2,896
1,624
from collections import defaultdict from math import sqrt inpl = lambda: list(map(int, input().split())) def primes(N): P = [] for i in range(2, N): sieve = 1 for p in P: if p * p > i: break elif i % p == 0: sieve = 0 break if sieve == 0: continue else: P.append(i) return P def factorize(n, P=None): if P is None: P = primes(int(sqrt(n)) + 1) factor = [] power = [] for p in P: if p * p > n: break elif n % p == 0: k = 0 while n % p == 0: n //= p k += 1 factor.append(p) power.append(k) if n > 1: factor.append(n) power.append(1) return factor, power class Counter: def __init__(self, start=0): self.index = start - 1 def __call__(self): self.index += 1 return self.index N = int(eval(input())) A = inpl() P_MAX = 32000 infty = 100 P = primes(P_MAX) np = defaultdict(Counter()) Np = 0 lowest_powers = [] bottle_necks = [] primelist = [] all_factors = set() for n in range(N): primes, powers = factorize(A[n], P) pp = [0] * Np for i in range(len(primes)): k = np[primes[i]] if k >= Np: Np += 1 pp.append(powers[i]) primelist.append(primes[i]) if n > 1: lowest_powers.append([0, 0]) bottle_necks.append(-1) elif n == 1: lowest_powers.append([0, infty]) bottle_necks.append(0) else: lowest_powers.append([infty, infty]) bottle_necks.append(-1) else: pp[k] = powers[i] for k in range(Np): lowest = lowest_powers[k] if pp[k] == lowest[0]: lowest[1] = lowest[0] bottle_necks[k] = -1 elif pp[k] < lowest[0]: lowest[1] = lowest[0] lowest[0] = pp[k] bottle_necks[k] = n elif pp[k] < lowest[1]: lowest[1] = pp[k] bottleneck_factors = [[] for _ in range(N)] for k in range(Np): n = bottle_necks[k] if n >= 0: lowest = lowest_powers[k] bottleneck_factors[n].append([primelist[k], lowest[1] - lowest[0]]) best_n = -1 largest_f = 1 for n in range(N): f = 1 for pp in bottleneck_factors[n]: f *= pp[0] ** pp[1] if f > largest_f: largest_f = f best_n = n ans = 1 pn = [s[0] for s in bottleneck_factors[best_n]] for k in range(Np): p = primelist[k] if bottle_necks[k] == best_n: ans *= p ** lowest_powers[k][1] else: ans *= p ** lowest_powers[k][0] print(ans)
from fractions import gcd inpl = lambda: list(map(int, input().split())) class SegCalcTree: def __init__(self, value, N=0, calc=lambda x, y: x + y): M = max(len(value), N) N = 2 ** (len(bin(M)) - 3) if N < M: N *= 2 self.N = N self.node = [None] * (2 * N - 1) for i, v in enumerate(value): self.node[i + N - 1] = v self.calc = lambda x, y: x if y is None else y if x is None else calc(x, y) for i in range(N - 2, -1, -1): left, right = self.node[2 * i + 1], self.node[2 * i + 2] self.node[i] = self.calc(left, right) def set_value(self, n, v): i = (self.N - 1) + n self.node[i] = v while i > 0: i = (i - 1) // 2 left, right = self.node[2 * i + 1], self.node[2 * i + 2] new = self.calc(left, right) if self.node[i] == new: break else: self.node[i] = new def get(self, a=0, b=-1, k=0, l=0, r=-1): if b < 0: b = self.N if r < 0: r = self.N if a <= l and r <= b: return self.node[k] elif r <= a or b <= l: return None else: left = self.get(a, b, 2 * k + 1, l, (l + r) // 2) right = self.get(a, b, 2 * k + 2, (l + r) // 2, r) return self.calc(left, right) N = int(eval(input())) A = inpl() sct = SegCalcTree(A, calc=gcd) ans = 0 for i in range(N): a = A[i] sct.set_value(i, None) c = sct.get() if c > ans: ans = c sct.set_value(i, a) print(ans)
false
52.10084
[ "-from collections import defaultdict", "-from math import sqrt", "+from fractions import gcd", "-def primes(N):", "- P = []", "- for i in range(2, N):", "- sieve = 1", "- for p in P:", "- if p * p > i:", "+class SegCalcTree:", "+ def __init__(self, value, N=0, ...
false
0.056791
0.044804
1.267539
[ "s923591598", "s301992975" ]
u766684188
p03087
python
s729335409
s991451106
540
382
59,272
54,560
Accepted
Accepted
29.26
import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) from bisect import bisect_left n,q=list(map(int,input().split())) S=eval(input()) A=[] for i in range(len(S)-1): if S[i]=='A' and S[i+1]=='C': A.append(i) for _ in range(q): l,r=list(map(int,input().split())) left=bisect_left(A,l-1) right=bisect_left(A,r-1) print((right-left))
import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) from itertools import accumulate n,q=list(map(int,input().split())) S=eval(input()) A=[0]*(n-1) for i in range(len(S)-1): if S[i]=='A' and S[i+1]=='C': A[i]=1 B=[0]+list(accumulate(A)) for _ in range(q): l,r=list(map(int,input().split())) print((B[r-1]-B[l-1]))
15
14
364
339
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) from bisect import bisect_left n, q = list(map(int, input().split())) S = eval(input()) A = [] for i in range(len(S) - 1): if S[i] == "A" and S[i + 1] == "C": A.append(i) for _ in range(q): l, r = list(map(int, input().split())) left = bisect_left(A, l - 1) right = bisect_left(A, r - 1) print((right - left))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) from itertools import accumulate n, q = list(map(int, input().split())) S = eval(input()) A = [0] * (n - 1) for i in range(len(S) - 1): if S[i] == "A" and S[i + 1] == "C": A[i] = 1 B = [0] + list(accumulate(A)) for _ in range(q): l, r = list(map(int, input().split())) print((B[r - 1] - B[l - 1]))
false
6.666667
[ "-from bisect import bisect_left", "+from itertools import accumulate", "-A = []", "+A = [0] * (n - 1)", "- A.append(i)", "+ A[i] = 1", "+B = [0] + list(accumulate(A))", "- left = bisect_left(A, l - 1)", "- right = bisect_left(A, r - 1)", "- print((right - left))", "+ p...
false
0.062625
0.006757
9.268856
[ "s729335409", "s991451106" ]
u970197315
p03111
python
s314231402
s776280942
78
67
3,064
9,232
Accepted
Accepted
14.1
n,A,B,C,=list(map(int,input().split())) l=[int(eval(input())) for i in range(n)] INF=1e9 def dfs(i,a,b,c): if i==n: if min(a,b,c)>0: return abs(A-a)+abs(B-b)+abs(C-c)-30 else: return INF ret0 = dfs(i+1,a,b,c) ret1 = dfs(i+1,a+l[i],b,c)+10 ret2 = dfs(i+1,a,b+l[i],c)+10 ret3 = dfs(i+1,a,b,c+l[i])+10 return min(ret0,ret1,ret2,ret3) print((dfs(0,0,0,0)))
N,A,B,C=list(map(int,input().split())) l=[int(eval(input())) for _ in range(N)] inf=10**18 def dfs(cur,a,b,c): if cur==N: if min(a,b,c)>0: return abs(A-a)+abs(B-b)+abs(C-c)-30 else: return inf res0 = dfs(cur+1,a,b,c) res1 = dfs(cur+1,a+l[cur],b,c)+10 res2 = dfs(cur+1,a,b+l[cur],c)+10 res3 = dfs(cur+1,a,b,c+l[cur])+10 return min(res0,res1,res2,res3) print((dfs(0,0,0,0)))
17
15
389
404
( n, A, B, C, ) = list(map(int, input().split())) l = [int(eval(input())) for i in range(n)] INF = 1e9 def dfs(i, a, b, c): if i == n: if min(a, b, c) > 0: return abs(A - a) + abs(B - b) + abs(C - c) - 30 else: return INF ret0 = dfs(i + 1, a, b, c) ret1 = dfs(i + 1, a + l[i], b, c) + 10 ret2 = dfs(i + 1, a, b + l[i], c) + 10 ret3 = dfs(i + 1, a, b, c + l[i]) + 10 return min(ret0, ret1, ret2, ret3) print((dfs(0, 0, 0, 0)))
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for _ in range(N)] inf = 10**18 def dfs(cur, a, b, c): if cur == N: if min(a, b, c) > 0: return abs(A - a) + abs(B - b) + abs(C - c) - 30 else: return inf res0 = dfs(cur + 1, a, b, c) res1 = dfs(cur + 1, a + l[cur], b, c) + 10 res2 = dfs(cur + 1, a, b + l[cur], c) + 10 res3 = dfs(cur + 1, a, b, c + l[cur]) + 10 return min(res0, res1, res2, res3) print((dfs(0, 0, 0, 0)))
false
11.764706
[ "-(", "- n,", "- A,", "- B,", "- C,", "-) = list(map(int, input().split()))", "-l = [int(eval(input())) for i in range(n)]", "-INF = 1e9", "+N, A, B, C = list(map(int, input().split()))", "+l = [int(eval(input())) for _ in range(N)]", "+inf = 10**18", "-def dfs(i, a, b, c):", "- ...
false
0.089645
0.089927
0.996857
[ "s314231402", "s776280942" ]
u050103511
p02396
python
s208546044
s261264904
60
50
7,460
7,468
Accepted
Accepted
16.67
import sys a = 1 for i in sys.stdin: x = i.strip() if x == "0": break; print(("Case {}: {}".format(a,x))) a += 1
import sys a = 1 for i in sys.stdin: x = i.strip() if x == "0": break; print(("Case {0}: {1}".format(a,x))) a += 1
9
9
167
169
import sys a = 1 for i in sys.stdin: x = i.strip() if x == "0": break print(("Case {}: {}".format(a, x))) a += 1
import sys a = 1 for i in sys.stdin: x = i.strip() if x == "0": break print(("Case {0}: {1}".format(a, x))) a += 1
false
0
[ "- print((\"Case {}: {}\".format(a, x)))", "+ print((\"Case {0}: {1}\".format(a, x)))" ]
false
0.048734
0.048405
1.006792
[ "s208546044", "s261264904" ]
u699089116
p03555
python
s573167902
s335059956
180
64
38,256
61,836
Accepted
Accepted
64.44
c1 = eval(input()) c2 = eval(input()) if c1[::-1] == c2: print("YES") else: print("NO")
c = eval(input()) d = input()[::-1] if c == d: print("YES") else: print("NO")
7
7
86
86
c1 = eval(input()) c2 = eval(input()) if c1[::-1] == c2: print("YES") else: print("NO")
c = eval(input()) d = input()[::-1] if c == d: print("YES") else: print("NO")
false
0
[ "-c1 = eval(input())", "-c2 = eval(input())", "-if c1[::-1] == c2:", "+c = eval(input())", "+d = input()[::-1]", "+if c == d:" ]
false
0.037896
0.037783
1.00299
[ "s573167902", "s335059956" ]
u150984829
p00449
python
s951202470
s560865782
4,670
3,990
5,996
5,780
Accepted
Accepted
14.56
I=float('inf') for e in iter(input,'0 0'): n,k=list(map(int,e.split())) F=[[I]*-~n for _ in[0]*-~n] for i in range(1,n+1):F[i][i]=0 for _ in[0]*k: f=eval(input());g=list(map(int,f[2:].split())) if'0'==f[0]:a,b=g;A=F[a][b];print(([A,-1][A==I])) else: c,d,e=g if e<F[c][d]: for i in range(2,n+1): for j in range(1,i): F[i][j]=min(F[i][j],F[i][c]+e+F[d][j],F[i][d]+e+F[c][j]) for j in range(2,n+1): for i in range(1,j): F[i][j]=F[j][i]
I=float('inf') for e in iter(input,'0 0'): n,k=list(map(int,e.split())) F=[[I]*-~n for _ in[0]*-~n] for i in range(1,n+1):F[i][i]=0 for _ in[0]*k: f=eval(input());g=list(map(int,f[2:].split())) if'0'==f[0]:a,b=g;A=F[a][b];print(([A,-1][A==I])) else: c,d,e=g if e<F[c][d]: for i in range(2,n+1): for j in range(1,i): F[i][j]=F[j][i]=min(F[i][j],F[i][c]+e+F[d][j],F[i][d]+e+F[c][j])
17
14
475
405
I = float("inf") for e in iter(input, "0 0"): n, k = list(map(int, e.split())) F = [[I] * -~n for _ in [0] * -~n] for i in range(1, n + 1): F[i][i] = 0 for _ in [0] * k: f = eval(input()) g = list(map(int, f[2:].split())) if "0" == f[0]: a, b = g A = F[a][b] print(([A, -1][A == I])) else: c, d, e = g if e < F[c][d]: for i in range(2, n + 1): for j in range(1, i): F[i][j] = min( F[i][j], F[i][c] + e + F[d][j], F[i][d] + e + F[c][j] ) for j in range(2, n + 1): for i in range(1, j): F[i][j] = F[j][i]
I = float("inf") for e in iter(input, "0 0"): n, k = list(map(int, e.split())) F = [[I] * -~n for _ in [0] * -~n] for i in range(1, n + 1): F[i][i] = 0 for _ in [0] * k: f = eval(input()) g = list(map(int, f[2:].split())) if "0" == f[0]: a, b = g A = F[a][b] print(([A, -1][A == I])) else: c, d, e = g if e < F[c][d]: for i in range(2, n + 1): for j in range(1, i): F[i][j] = F[j][i] = min( F[i][j], F[i][c] + e + F[d][j], F[i][d] + e + F[c][j] )
false
17.647059
[ "- F[i][j] = min(", "+ F[i][j] = F[j][i] = min(", "- for j in range(2, n + 1):", "- for i in range(1, j):", "- F[i][j] = F[j][i]" ]
false
0.050186
0.048401
1.036874
[ "s951202470", "s560865782" ]
u663710122
p02767
python
s768188942
s815239379
25
21
3,060
3,060
Accepted
Accepted
16
N = int(eval(input())) X = list(map(int, input().split())) res = float('inf') for i in range(-100, 101): tmp = 0 for x in X: tmp += (i - x) ** 2 res = min(tmp, res) print(res)
N = int(eval(input())) X = list(map(int, input().split())) res = float('inf') for i in range(min(X), max(X)+1): tmp = 0 for x in X: tmp += (i - x) ** 2 res = min(tmp, res) print(res)
13
13
205
212
N = int(eval(input())) X = list(map(int, input().split())) res = float("inf") for i in range(-100, 101): tmp = 0 for x in X: tmp += (i - x) ** 2 res = min(tmp, res) print(res)
N = int(eval(input())) X = list(map(int, input().split())) res = float("inf") for i in range(min(X), max(X) + 1): tmp = 0 for x in X: tmp += (i - x) ** 2 res = min(tmp, res) print(res)
false
0
[ "-for i in range(-100, 101):", "+for i in range(min(X), max(X) + 1):" ]
false
0.049112
0.047928
1.024696
[ "s768188942", "s815239379" ]
u714642969
p02726
python
s704234402
s698889001
1,409
874
12,720
66,012
Accepted
Accepted
37.97
# -*- coding: utf-8 -*- import sys import numpy as np sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): N,X,Y=list(map(int,input().split())) X-=1 Y-=1 ans=[0]*N for i in range(N-1): for j in range(i+1,N): ans[min(j-i,abs(X-i)+1+abs(Y-j),abs(X-j)+1+abs(Y-i))]+=1 for row in ans[1:]: print(row) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import sys from heapq import heappush,heappop sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): N,X,Y=list(map(int,input().split())) X-=1 Y-=1 def dijkstra(start,n,edges): d=[INF]*n used=[False]*n d[start]=0 used[start]=True edgelist=[] for edge in edges[start]: heappush(edgelist,edge) while edgelist: minedge=heappop(edgelist) if used[minedge[1]]: continue v=minedge[1] d[v]=minedge[0] used[v]=True for edge in edges[v]: if not used[edge[1]]: heappush(edgelist,(edge[0]+d[v],edge[1])) return d edges=[[] for _ in range(N)] for i in range(N-1): edges[i].append((1,i+1)) edges[i+1].append((1,i)) edges[X].append((1,Y)) edges[Y].append((1,X)) ans=[0]*N for i in range(N): d=dijkstra(i,N,edges) for x in d: ans[x]+=1 for row in ans[1:]: print((row//2)) if __name__ == '__main__': main()
21
50
463
1,227
# -*- coding: utf-8 -*- import sys import numpy as np sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 def input(): return sys.stdin.readline().rstrip() def main(): N, X, Y = list(map(int, input().split())) X -= 1 Y -= 1 ans = [0] * N for i in range(N - 1): for j in range(i + 1, N): ans[ min(j - i, abs(X - i) + 1 + abs(Y - j), abs(X - j) + 1 + abs(Y - i)) ] += 1 for row in ans[1:]: print(row) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import sys from heapq import heappush, heappop sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 def input(): return sys.stdin.readline().rstrip() def main(): N, X, Y = list(map(int, input().split())) X -= 1 Y -= 1 def dijkstra(start, n, edges): d = [INF] * n used = [False] * n d[start] = 0 used[start] = True edgelist = [] for edge in edges[start]: heappush(edgelist, edge) while edgelist: minedge = heappop(edgelist) if used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = True for edge in edges[v]: if not used[edge[1]]: heappush(edgelist, (edge[0] + d[v], edge[1])) return d edges = [[] for _ in range(N)] for i in range(N - 1): edges[i].append((1, i + 1)) edges[i + 1].append((1, i)) edges[X].append((1, Y)) edges[Y].append((1, X)) ans = [0] * N for i in range(N): d = dijkstra(i, N, edges) for x in d: ans[x] += 1 for row in ans[1:]: print((row // 2)) if __name__ == "__main__": main()
false
58
[ "-import numpy as np", "+from heapq import heappush, heappop", "+", "+ def dijkstra(start, n, edges):", "+ d = [INF] * n", "+ used = [False] * n", "+ d[start] = 0", "+ used[start] = True", "+ edgelist = []", "+ for edge in edges[start]:", "+ ...
false
0.045607
0.067102
0.679659
[ "s704234402", "s698889001" ]
u785578220
p03603
python
s695111963
s999669732
83
38
3,572
3,440
Accepted
Accepted
54.22
#copy for experience import sys sys.setrecursionlimit(10**8) N=int(eval(input())) P=[int(i) for i in input().split()] X=[int(i) for i in input().split()] table=[[] for i in range(N)] for i in range(N-1): table[P[i]-1].append(i+1) dp=[0]*N #shiro def tree(pa): for i in table[pa]: tree(i) t=len(table[pa]) if t==0: return T=set() s=0 for i in range(t): x=table[pa][i] s+=X[x]+dp[x] if i==0: if X[x]<=X[pa]: T.add(X[x]) if dp[x]<=X[pa]: T.add(dp[x]) continue S=set() for k in T: if k+X[x]<=X[pa]: S.add(k+X[x]) if k+dp[x]<=X[pa]: S.add(k+dp[x]) T=S if len(T)==0: print('IMPOSSIBLE') sys.exit() dp[pa]=s-max(T) return tree(0) print('POSSIBLE')
#copy for experience # E N = int(eval(input())) P_list = list(map(int, input().split())) X_list = list(map(int, input().split())) # graph child_list = [[] for _ in range(N+1)] for i in range(2, N+1): child_list[P_list[i-2]].append(i) # from root # minimize local total weight color1 = [0]+X_list color2 = [0]*(N+1) # solve knapsack def solve_knapsack(L, M): min_acc = sum([min(color1[j], color2[j]) for j in L]) if min_acc > M: return -1 else: add_can = M - min_acc add_set = set([0]) for j in L: add_j = max(color1[j], color2[j]) - min(color1[j], color2[j]) add_set_ = set(add_set) for s in add_set: if s + add_j <= add_can: add_set_.add(s + add_j) add_set = add_set_ total = sum([color1[j]+color2[j] for j in L]) return total - max(add_set) - min_acc res = "POSSIBLE" for i in range(N, 0, -1): if len(child_list[i]) == 0: pass elif len(child_list[i]) == 1: j = child_list[i][0] if min(color1[j], color2[j]) > X_list[i-1]: res = "IMPOSSIBLE" break elif max(color1[j], color2[j]) > X_list[i-1]: color2[i] = max(color1[j], color2[j]) else: color2[i] = min(color1[j], color2[j]) else: c2 = solve_knapsack(child_list[i], X_list[i-1]) if c2 < 0: res = "IMPOSSIBLE" break else: color2[i] = c2 print(res)
43
59
927
1,579
# copy for experience import sys sys.setrecursionlimit(10**8) N = int(eval(input())) P = [int(i) for i in input().split()] X = [int(i) for i in input().split()] table = [[] for i in range(N)] for i in range(N - 1): table[P[i] - 1].append(i + 1) dp = [0] * N # shiro def tree(pa): for i in table[pa]: tree(i) t = len(table[pa]) if t == 0: return T = set() s = 0 for i in range(t): x = table[pa][i] s += X[x] + dp[x] if i == 0: if X[x] <= X[pa]: T.add(X[x]) if dp[x] <= X[pa]: T.add(dp[x]) continue S = set() for k in T: if k + X[x] <= X[pa]: S.add(k + X[x]) if k + dp[x] <= X[pa]: S.add(k + dp[x]) T = S if len(T) == 0: print("IMPOSSIBLE") sys.exit() dp[pa] = s - max(T) return tree(0) print("POSSIBLE")
# copy for experience # E N = int(eval(input())) P_list = list(map(int, input().split())) X_list = list(map(int, input().split())) # graph child_list = [[] for _ in range(N + 1)] for i in range(2, N + 1): child_list[P_list[i - 2]].append(i) # from root # minimize local total weight color1 = [0] + X_list color2 = [0] * (N + 1) # solve knapsack def solve_knapsack(L, M): min_acc = sum([min(color1[j], color2[j]) for j in L]) if min_acc > M: return -1 else: add_can = M - min_acc add_set = set([0]) for j in L: add_j = max(color1[j], color2[j]) - min(color1[j], color2[j]) add_set_ = set(add_set) for s in add_set: if s + add_j <= add_can: add_set_.add(s + add_j) add_set = add_set_ total = sum([color1[j] + color2[j] for j in L]) return total - max(add_set) - min_acc res = "POSSIBLE" for i in range(N, 0, -1): if len(child_list[i]) == 0: pass elif len(child_list[i]) == 1: j = child_list[i][0] if min(color1[j], color2[j]) > X_list[i - 1]: res = "IMPOSSIBLE" break elif max(color1[j], color2[j]) > X_list[i - 1]: color2[i] = max(color1[j], color2[j]) else: color2[i] = min(color1[j], color2[j]) else: c2 = solve_knapsack(child_list[i], X_list[i - 1]) if c2 < 0: res = "IMPOSSIBLE" break else: color2[i] = c2 print(res)
false
27.118644
[ "-import sys", "-", "-sys.setrecursionlimit(10**8)", "+# E", "-P = [int(i) for i in input().split()]", "-X = [int(i) for i in input().split()]", "-table = [[] for i in range(N)]", "-for i in range(N - 1):", "- table[P[i] - 1].append(i + 1)", "-dp = [0] * N # shiro", "+P_list = list(map(int, ...
false
0.080112
0.060152
1.331813
[ "s695111963", "s999669732" ]
u510722570
p02714
python
s429971209
s600090344
1,579
1,346
9,144
9,208
Accepted
Accepted
14.76
n = int(eval(input())) s = str(eval(input())) rn = s.count("R") gn = s.count("G") bn = s.count("B") ct=0 for i in range(n): for j in range(i+1,n): if 2*j - i >= n: break elif s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]: ct += 1 print((rn*gn*bn-ct))
n = int(eval(input())) s = str(eval(input())) rn = s.count("R") gn = s.count("G") bn = s.count("B") ct=0 for i in range(n): for j in range(i+1,n): k = 2*j - i if k >= n: break elif s[i]!=s[j] and s[j]!=s[k]and s[i]!=s[k]: ct += 1 print((rn*gn*bn-ct))
15
16
278
281
n = int(eval(input())) s = str(eval(input())) rn = s.count("R") gn = s.count("G") bn = s.count("B") ct = 0 for i in range(n): for j in range(i + 1, n): if 2 * j - i >= n: break elif s[i] != s[j] and s[j] != s[2 * j - i] and s[i] != s[2 * j - i]: ct += 1 print((rn * gn * bn - ct))
n = int(eval(input())) s = str(eval(input())) rn = s.count("R") gn = s.count("G") bn = s.count("B") ct = 0 for i in range(n): for j in range(i + 1, n): k = 2 * j - i if k >= n: break elif s[i] != s[j] and s[j] != s[k] and s[i] != s[k]: ct += 1 print((rn * gn * bn - ct))
false
6.25
[ "- if 2 * j - i >= n:", "+ k = 2 * j - i", "+ if k >= n:", "- elif s[i] != s[j] and s[j] != s[2 * j - i] and s[i] != s[2 * j - i]:", "+ elif s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:" ]
false
0.042515
0.041123
1.033856
[ "s429971209", "s600090344" ]
u694810977
p03325
python
s347028526
s374993501
142
109
4,148
4,148
Accepted
Accepted
23.24
n = int(eval(input())) a = list(map(int,input().split())) Sum = 0 for i in range(n): while a[i] % 2 == 0: a[i] /= 2 Sum += 1 print(Sum)
n = int(eval(input())) a = list(map(int,input().split())) cnt = 0 for i in range(n): if a[i] % 2 == 0: while a[i] % 2 == 0: a[i] = a[i] // 2 cnt += 1 print(cnt)
8
9
157
198
n = int(eval(input())) a = list(map(int, input().split())) Sum = 0 for i in range(n): while a[i] % 2 == 0: a[i] /= 2 Sum += 1 print(Sum)
n = int(eval(input())) a = list(map(int, input().split())) cnt = 0 for i in range(n): if a[i] % 2 == 0: while a[i] % 2 == 0: a[i] = a[i] // 2 cnt += 1 print(cnt)
false
11.111111
[ "-Sum = 0", "+cnt = 0", "- while a[i] % 2 == 0:", "- a[i] /= 2", "- Sum += 1", "-print(Sum)", "+ if a[i] % 2 == 0:", "+ while a[i] % 2 == 0:", "+ a[i] = a[i] // 2", "+ cnt += 1", "+print(cnt)" ]
false
0.035898
0.155087
0.231473
[ "s347028526", "s374993501" ]
u038815010
p03673
python
s673835159
s844094016
239
219
102,488
25,424
Accepted
Accepted
8.37
n = int(eval(input())) a = input().split() b = [] for i in range(n - 1, -1, -2): b.extend([a[i]]) for j in range(n % 2, n, 2): b.extend([a[j]]) print((" ".join(b)))
import os import sys from collections import deque if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) que = deque() for i in range(N): if i % 2 == 0: que.append(A[i]) else: que.appendleft(A[i]) if N % 2: que.reverse() print((*que))
8
24
168
460
n = int(eval(input())) a = input().split() b = [] for i in range(n - 1, -1, -2): b.extend([a[i]]) for j in range(n % 2, n, 2): b.extend([a[j]]) print((" ".join(b)))
import os import sys from collections import deque if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) que = deque() for i in range(N): if i % 2 == 0: que.append(A[i]) else: que.appendleft(A[i]) if N % 2: que.reverse() print((*que))
false
66.666667
[ "-n = int(eval(input()))", "-a = input().split()", "-b = []", "-for i in range(n - 1, -1, -2):", "- b.extend([a[i]])", "-for j in range(n % 2, n, 2):", "- b.extend([a[j]])", "-print((\" \".join(b)))", "+import os", "+import sys", "+from collections import deque", "+", "+if os.getenv(\"...
false
0.04005
0.068455
0.585054
[ "s673835159", "s844094016" ]
u083960235
p04045
python
s310222186
s532283126
243
116
5,196
7,416
Accepted
Accepted
52.26
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, K = MAP() D = LIST() d_s = set(D) moto = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} amari = d_s & moto l = list(str(N)) l = list(map(int, l)) # for i in range(len(l)): i = N while 1: l = list(str(i)) l = list(map(int, l)) l_s = set(l) s_intersection = d_s & l_s if len(s_intersection) == 0: print(i) exit() i += 1 # if d_s.isdisjoint(l_s): # print(i) # exit()
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, K = MAP() D = LIST() q = deque([""]) s = set([i for i in range(0, 10)]) d = set(D) kouho = s - d kouho = sorted(list(set(kouho))) while q: a = q.popleft() # print(q) if len(a) != 0: if int(a) >= N: print(a) break for d in kouho: b = deepcopy(a) # if len(b) == 0 and d == 0: # pass # else: b += str(d) q.append(b)
48
45
1,173
1,149
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, K = MAP() D = LIST() d_s = set(D) moto = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} amari = d_s & moto l = list(str(N)) l = list(map(int, l)) # for i in range(len(l)): i = N while 1: l = list(str(i)) l = list(map(int, l)) l_s = set(l) s_intersection = d_s & l_s if len(s_intersection) == 0: print(i) exit() i += 1 # if d_s.isdisjoint(l_s): # print(i) # exit()
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, K = MAP() D = LIST() q = deque([""]) s = set([i for i in range(0, 10)]) d = set(D) kouho = s - d kouho = sorted(list(set(kouho))) while q: a = q.popleft() # print(q) if len(a) != 0: if int(a) >= N: print(a) break for d in kouho: b = deepcopy(a) # if len(b) == 0 and d == 0: # pass # else: b += str(d) q.append(b)
false
6.25
[ "-from fractions import gcd", "-d_s = set(D)", "-moto = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}", "-amari = d_s & moto", "-l = list(str(N))", "-l = list(map(int, l))", "-# for i in range(len(l)):", "-i = N", "-while 1:", "- l = list(str(i))", "- l = list(map(int, l))", "- l_s = set(l)", "- ...
false
0.051978
0.039803
1.30588
[ "s310222186", "s532283126" ]
u548545174
p03341
python
s011550110
s691596235
478
416
27,128
27,124
Accepted
Accepted
12.97
N = int(eval(input())) S = eval(input()) E_count = [0] * (N+1) for i in range(N): E_count[i+1] = E_count[i] + int(S[i] == "E") W_count = [0] * (N+1) for i in range(N): W_count[i+1] = W_count[i] + int(S[i] == "W") ans = 10 ** 6 for i in range(1, N + 1): change_dir_cnt = (W_count[i - 1] - W_count[0]) + (E_count[-1] - E_count[i]) ans = min(change_dir_cnt, ans) print(ans)
N = int(eval(input())) S = eval(input()) E_count = [0] * (N+1) W_count = [0] * (N+1) for i in range(N): E_count[i + 1] = E_count[i] + int(S[i] == "E") W_count[i + 1] = (i + 1) - E_count[i + 1] ans = 10 ** 6 for i in range(1, N + 1): change_dir_cnt = (W_count[i - 1] - W_count[0]) + (E_count[-1] - E_count[i]) ans = min(change_dir_cnt, ans) print(ans)
16
15
392
371
N = int(eval(input())) S = eval(input()) E_count = [0] * (N + 1) for i in range(N): E_count[i + 1] = E_count[i] + int(S[i] == "E") W_count = [0] * (N + 1) for i in range(N): W_count[i + 1] = W_count[i] + int(S[i] == "W") ans = 10**6 for i in range(1, N + 1): change_dir_cnt = (W_count[i - 1] - W_count[0]) + (E_count[-1] - E_count[i]) ans = min(change_dir_cnt, ans) print(ans)
N = int(eval(input())) S = eval(input()) E_count = [0] * (N + 1) W_count = [0] * (N + 1) for i in range(N): E_count[i + 1] = E_count[i] + int(S[i] == "E") W_count[i + 1] = (i + 1) - E_count[i + 1] ans = 10**6 for i in range(1, N + 1): change_dir_cnt = (W_count[i - 1] - W_count[0]) + (E_count[-1] - E_count[i]) ans = min(change_dir_cnt, ans) print(ans)
false
6.25
[ "+W_count = [0] * (N + 1)", "-W_count = [0] * (N + 1)", "-for i in range(N):", "- W_count[i + 1] = W_count[i] + int(S[i] == \"W\")", "+ W_count[i + 1] = (i + 1) - E_count[i + 1]" ]
false
0.083435
0.081689
1.021374
[ "s011550110", "s691596235" ]
u797673668
p00588
python
s211766845
s384548735
390
300
9,484
9,624
Accepted
Accepted
23.08
pre = [ ((0, 1, 2), (1, 0, 1), (2, 1, 0)), ((3, 2, 2), (2, 1, 1), (2, 1, 1)), ((1, 1, 2), (1, 1, 2), (2, 2, 3)), ((3, 2, 2), (2, 2, 2), (2, 2, 3)), ] q = int(eval(input())) for _ in range(q): n = int(eval(input())) books = [c == 'Y' for c in eval(input())] books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)] shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)] ans = [0, 1, 2] for key in shelves: new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]] ans = new_ans print((ans[0] + n))
pre = [ ((0, 1, 2), (1, 0, 1), (2, 1, 0)), ((3, 2, 2), (2, 1, 1), (2, 1, 1)), ((1, 1, 2), (1, 1, 2), (2, 2, 3)), ((3, 2, 2), (2, 2, 2), (2, 2, 3)), ] q = int(eval(input())) for _ in range(q): n = int(eval(input())) books = [c == 'Y' for c in eval(input())] books = [(0, 0)] + list(zip(books[:2 * n], books[2 * n:])) + [(0, 0)] shelves = [(u1 | u2) * 2 + (l1 | l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)] ans = [0, 1, 2] for key in shelves: new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]] ans = new_ans print((ans[0] + n))
18
18
660
615
pre = [ ((0, 1, 2), (1, 0, 1), (2, 1, 0)), ((3, 2, 2), (2, 1, 1), (2, 1, 1)), ((1, 1, 2), (1, 1, 2), (2, 2, 3)), ((3, 2, 2), (2, 2, 2), (2, 2, 3)), ] q = int(eval(input())) for _ in range(q): n = int(eval(input())) books = [c == "Y" for c in eval(input())] books = ( [(False, False)] + list(map(lambda u, l: (u, l), books[: 2 * n], books[2 * n :])) + [(False, False)] ) shelves = [ int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2) ] ans = [0, 1, 2] for key in shelves: new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]] ans = new_ans print((ans[0] + n))
pre = [ ((0, 1, 2), (1, 0, 1), (2, 1, 0)), ((3, 2, 2), (2, 1, 1), (2, 1, 1)), ((1, 1, 2), (1, 1, 2), (2, 2, 3)), ((3, 2, 2), (2, 2, 2), (2, 2, 3)), ] q = int(eval(input())) for _ in range(q): n = int(eval(input())) books = [c == "Y" for c in eval(input())] books = [(0, 0)] + list(zip(books[: 2 * n], books[2 * n :])) + [(0, 0)] shelves = [ (u1 | u2) * 2 + (l1 | l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2) ] ans = [0, 1, 2] for key in shelves: new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]] ans = new_ans print((ans[0] + n))
false
0
[ "- books = (", "- [(False, False)]", "- + list(map(lambda u, l: (u, l), books[: 2 * n], books[2 * n :]))", "- + [(False, False)]", "- )", "+ books = [(0, 0)] + list(zip(books[: 2 * n], books[2 * n :])) + [(0, 0)]", "- int(u1 or u2) * 2 + int(l1 or l2)", "- f...
false
0.044533
0.037887
1.175413
[ "s211766845", "s384548735" ]
u620084012
p02768
python
s577485458
s810722409
370
146
108,236
107,168
Accepted
Accepted
60.54
n, a, b = list(map(int,input().split())) MOD = 10**9 + 7 ans = pow(2,n,MOD)-1 def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= MOD return result ans -= (cmb(n,a) + cmb(n,b)) print((ans%MOD))
MOD = 10**9 + 7 def nCr(n, r, MOD): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= MOD return result n, a, b = list(map(int,input().split())) ans = pow(2,n,MOD)-1-nCr(n,a,MOD)-nCr(n,b,MOD) while ans < 0: ans += MOD print(ans)
29
29
726
753
n, a, b = list(map(int, input().split())) MOD = 10**9 + 7 ans = pow(2, n, MOD) - 1 def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= MOD return result ans -= cmb(n, a) + cmb(n, b) print((ans % MOD))
MOD = 10**9 + 7 def nCr(n, r, MOD): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) result %= MOD return result n, a, b = list(map(int, input().split())) ans = pow(2, n, MOD) - 1 - nCr(n, a, MOD) - nCr(n, b, MOD) while ans < 0: ans += MOD print(ans)
false
0
[ "-n, a, b = list(map(int, input().split()))", "-ans = pow(2, n, MOD) - 1", "-def cmb(n, r):", "+def nCr(n, r, MOD):", "-ans -= cmb(n, a) + cmb(n, b)", "-print((ans % MOD))", "+n, a, b = list(map(int, input().split()))", "+ans = pow(2, n, MOD) - 1 - nCr(n, a, MOD) - nCr(n, b, MOD)", "+while ans < 0:"...
false
0.73068
0.979931
0.745644
[ "s577485458", "s810722409" ]
u368796742
p02598
python
s022057153
s933198765
1,114
908
30,988
30,880
Accepted
Accepted
18.49
n,k = list(map(int,input().split())) a = list(map(int,input().split())) l = 0 r = 10**10 while r > l + 1: m = (r+l)//2 count = 0 for i in a: if i <= m: continue count += (i-1)//m if count > k: l = m else: r = m print(r)
n,k = list(map(int,input().split())) a = list(map(int,input().split())) l = 0 r = 10**10 while r > l + 1: m = (r+l)//2 count = 0 for i in a: if i <= m: continue count += (i)//m if count > k: l = m else: r = m print(r)
20
20
312
310
n, k = list(map(int, input().split())) a = list(map(int, input().split())) l = 0 r = 10**10 while r > l + 1: m = (r + l) // 2 count = 0 for i in a: if i <= m: continue count += (i - 1) // m if count > k: l = m else: r = m print(r)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) l = 0 r = 10**10 while r > l + 1: m = (r + l) // 2 count = 0 for i in a: if i <= m: continue count += (i) // m if count > k: l = m else: r = m print(r)
false
0
[ "- count += (i - 1) // m", "+ count += (i) // m" ]
false
0.047224
0.047343
0.997496
[ "s022057153", "s933198765" ]
u644907318
p04045
python
s373833767
s449927326
193
27
41,836
9,196
Accepted
Accepted
86.01
import itertools N,K = list(map(int,input().split())) D = list(map(int,input().split())) A = [] for i in range(10): if i not in D: A.append(i) cmin = 100000 k = len(str(N)) for i in range(k,6): for x in itertools.product(A,repeat=i): cnt = 0 for j in range(i): cnt += x[j]*10**(i-1-j) if cnt>=N: cmin = min(cmin,cnt) print(cmin)
N,K = list(map(int,input().split())) D = list(map(int,input().split())) E = [] for i in range(10): if i not in D: E.append(i) E = sorted(E) N = str(N) ind = len(N) for i in range(len(N)): if int(N[i]) not in E: ind = i break if ind==len(N): print(N) else: flag = 0 x = "" for i in range(ind,-1,-1): n = int(N[i]) for e in E: if e>n: x = N[:i]+str(e)+str(E[0])*(len(N)-i-1) flag = 1 break if flag==1:break if flag==0: if E[0]>0: a = E[0] else: a = E[1] x = str(a)+str(E[0])*len(N) print(x)
17
33
402
702
import itertools N, K = list(map(int, input().split())) D = list(map(int, input().split())) A = [] for i in range(10): if i not in D: A.append(i) cmin = 100000 k = len(str(N)) for i in range(k, 6): for x in itertools.product(A, repeat=i): cnt = 0 for j in range(i): cnt += x[j] * 10 ** (i - 1 - j) if cnt >= N: cmin = min(cmin, cnt) print(cmin)
N, K = list(map(int, input().split())) D = list(map(int, input().split())) E = [] for i in range(10): if i not in D: E.append(i) E = sorted(E) N = str(N) ind = len(N) for i in range(len(N)): if int(N[i]) not in E: ind = i break if ind == len(N): print(N) else: flag = 0 x = "" for i in range(ind, -1, -1): n = int(N[i]) for e in E: if e > n: x = N[:i] + str(e) + str(E[0]) * (len(N) - i - 1) flag = 1 break if flag == 1: break if flag == 0: if E[0] > 0: a = E[0] else: a = E[1] x = str(a) + str(E[0]) * len(N) print(x)
false
48.484848
[ "-import itertools", "-", "-A = []", "+E = []", "- A.append(i)", "-cmin = 100000", "-k = len(str(N))", "-for i in range(k, 6):", "- for x in itertools.product(A, repeat=i):", "- cnt = 0", "- for j in range(i):", "- cnt += x[j] * 10 ** (i - 1 - j)", "- ...
false
0.041328
0.07187
0.575043
[ "s373833767", "s449927326" ]
u761320129
p03449
python
s184394965
s025042468
25
19
3,060
3,060
Accepted
Accepted
24
N = int(eval(input())) s1 = list(map(int,input().split())) s2 = list(map(int,input().split())) ans = 0 for i in range(N): tmp = sum(s1[:i+1]) + sum(s2[i:]) ans = max(ans, tmp) print(ans)
N = int(eval(input())) S0 = list(map(int,input().split())) S1 = list(map(int,input().split())) ans = 0 for i in range(N): tmp = sum(S0[:i+1]) + sum(S1[i:]) ans = max(tmp,ans) print(ans)
9
9
197
196
N = int(eval(input())) s1 = list(map(int, input().split())) s2 = list(map(int, input().split())) ans = 0 for i in range(N): tmp = sum(s1[: i + 1]) + sum(s2[i:]) ans = max(ans, tmp) print(ans)
N = int(eval(input())) S0 = list(map(int, input().split())) S1 = list(map(int, input().split())) ans = 0 for i in range(N): tmp = sum(S0[: i + 1]) + sum(S1[i:]) ans = max(tmp, ans) print(ans)
false
0
[ "-s1 = list(map(int, input().split()))", "-s2 = list(map(int, input().split()))", "+S0 = list(map(int, input().split()))", "+S1 = list(map(int, input().split()))", "- tmp = sum(s1[: i + 1]) + sum(s2[i:])", "- ans = max(ans, tmp)", "+ tmp = sum(S0[: i + 1]) + sum(S1[i:])", "+ ans = max(tmp,...
false
0.056744
0.055116
1.029539
[ "s184394965", "s025042468" ]
u745812846
p02554
python
s368393418
s166234476
386
28
10,964
9,140
Accepted
Accepted
92.75
prime = 10 ** 9 + 7 n = int(eval(input())) ans = 10 ** n - (9 ** n) * 2 + 8 ** n ans %= prime print(ans)
mod = 10 ** 9 + 7 n = int(input()) ans = pow(10, n, mod) - pow(9, n, mod ) * 2\ + pow(8, n, mod) ans %= mod print(ans)
5
6
102
128
prime = 10**9 + 7 n = int(eval(input())) ans = 10**n - (9**n) * 2 + 8**n ans %= prime print(ans)
mod = 10**9 + 7 n = int(input()) ans = pow(10, n, mod) - pow(9, n, mod) * 2 + pow(8, n, mod) ans %= mod print(ans)
false
16.666667
[ "-prime = 10**9 + 7", "-n = int(eval(input()))", "-ans = 10**n - (9**n) * 2 + 8**n", "-ans %= prime", "+mod = 10**9 + 7", "+n = int(input())", "+ans = pow(10, n, mod) - pow(9, n, mod) * 2 + pow(8, n, mod)", "+ans %= mod" ]
false
0.168704
0.035155
4.798874
[ "s368393418", "s166234476" ]
u501643136
p03331
python
s958552520
s671855316
104
17
2,940
2,940
Accepted
Accepted
83.65
N = int(eval(input())) def sumof(N): sum = 0 while(N>0): sum += N % 10 N //= 10 return sum minsum = 9*10 for i in range(1,N//2+1): minsum = min(minsum,sumof(i) + sumof(N-i)) print(minsum)
NL = [int(x) for x in str(eval(input()))] if NL[0] == 1 and sum(NL) == 1: print((10)) else: print((sum(NL)))
12
5
210
110
N = int(eval(input())) def sumof(N): sum = 0 while N > 0: sum += N % 10 N //= 10 return sum minsum = 9 * 10 for i in range(1, N // 2 + 1): minsum = min(minsum, sumof(i) + sumof(N - i)) print(minsum)
NL = [int(x) for x in str(eval(input()))] if NL[0] == 1 and sum(NL) == 1: print((10)) else: print((sum(NL)))
false
58.333333
[ "-N = int(eval(input()))", "-", "-", "-def sumof(N):", "- sum = 0", "- while N > 0:", "- sum += N % 10", "- N //= 10", "- return sum", "-", "-", "-minsum = 9 * 10", "-for i in range(1, N // 2 + 1):", "- minsum = min(minsum, sumof(i) + sumof(N - i))", "-print(min...
false
0.074305
0.034569
2.149485
[ "s958552520", "s671855316" ]
u508732591
p02314
python
s779495396
s034976855
440
390
9,604
9,620
Accepted
Accepted
11.36
n = int(input().split()[0]) c = list([x for x in map(int,input().split()) if x <= n]) minimum = [ i for i in range(n+1) ] for i in range(2,n+1): for j in c: if j <= i and minimum[i-j] + 1 < minimum[i]: minimum[i] = minimum[i-j]+1 print((minimum[n]))
n = int(input().split()[0]) c = list(map(int,input().split())) minimum = [ i for i in range(n+1) ] for i in range(2,n+1): for j in c: if j <= i and minimum[i-j] + 1 < minimum[i]: minimum[i] = minimum[i-j]+1 print((minimum[n]))
11
10
285
259
n = int(input().split()[0]) c = list([x for x in map(int, input().split()) if x <= n]) minimum = [i for i in range(n + 1)] for i in range(2, n + 1): for j in c: if j <= i and minimum[i - j] + 1 < minimum[i]: minimum[i] = minimum[i - j] + 1 print((minimum[n]))
n = int(input().split()[0]) c = list(map(int, input().split())) minimum = [i for i in range(n + 1)] for i in range(2, n + 1): for j in c: if j <= i and minimum[i - j] + 1 < minimum[i]: minimum[i] = minimum[i - j] + 1 print((minimum[n]))
false
9.090909
[ "-c = list([x for x in map(int, input().split()) if x <= n])", "+c = list(map(int, input().split()))" ]
false
0.125143
0.129509
0.966287
[ "s779495396", "s034976855" ]
u197615397
p00508
python
s553723829
s413164039
3,720
2,850
79,872
108,312
Accepted
Accepted
23.39
from operator import itemgetter N = int(eval(input())) a = [tuple(map(int, input().split())) for _ in [0]*N] ans = float("inf") a.sort() for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1-x2)**2 + (y1-y2)**2 if ans > dist: ans = dist a.sort(key=itemgetter(1)) for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1-x2)**2 + (y1-y2)**2 if ans > dist: ans = dist print(ans)
import sys from operator import itemgetter N = int(eval(input())) a = sorted(tuple(map(int, l.split())) for l in sys.stdin.readlines()) ans = float("inf") for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1-x2)**2 + (y1-y2)**2 if ans > dist: ans = dist a.sort(key=itemgetter(1)) for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1-x2)**2 + (y1-y2)**2 if ans > dist: ans = dist print(ans)
18
18
416
434
from operator import itemgetter N = int(eval(input())) a = [tuple(map(int, input().split())) for _ in [0] * N] ans = float("inf") a.sort() for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1 - x2) ** 2 + (y1 - y2) ** 2 if ans > dist: ans = dist a.sort(key=itemgetter(1)) for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1 - x2) ** 2 + (y1 - y2) ** 2 if ans > dist: ans = dist print(ans)
import sys from operator import itemgetter N = int(eval(input())) a = sorted(tuple(map(int, l.split())) for l in sys.stdin.readlines()) ans = float("inf") for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1 - x2) ** 2 + (y1 - y2) ** 2 if ans > dist: ans = dist a.sort(key=itemgetter(1)) for (x1, y1), (x2, y2) in zip(a, a[1:]): dist = (x1 - x2) ** 2 + (y1 - y2) ** 2 if ans > dist: ans = dist print(ans)
false
0
[ "+import sys", "-a = [tuple(map(int, input().split())) for _ in [0] * N]", "+a = sorted(tuple(map(int, l.split())) for l in sys.stdin.readlines())", "-a.sort()" ]
false
0.045321
0.045795
0.989661
[ "s553723829", "s413164039" ]
u496344397
p03329
python
s514981266
s932446566
592
514
4,632
6,900
Accepted
Accepted
13.18
N = int(eval(input())) INF = N dp = [0, 1, 2, 3, 4, 5] + [INF for _ in range(N-5)] for amount in range(6, N+1): dp[amount] = amount unit = 6 while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= 6 unit = 9 while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= 9 print((dp[N]))
N = int(eval(input())) dp = list(range(N+1)) for amount in range(6, N+1): unit = 6 while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= 6 unit = 9 while unit <= amount: dp[amount] = min(dp[amount], dp[amount-unit]+1) unit *= 9 print((dp[N]))
19
16
391
325
N = int(eval(input())) INF = N dp = [0, 1, 2, 3, 4, 5] + [INF for _ in range(N - 5)] for amount in range(6, N + 1): dp[amount] = amount unit = 6 while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= 6 unit = 9 while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= 9 print((dp[N]))
N = int(eval(input())) dp = list(range(N + 1)) for amount in range(6, N + 1): unit = 6 while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= 6 unit = 9 while unit <= amount: dp[amount] = min(dp[amount], dp[amount - unit] + 1) unit *= 9 print((dp[N]))
false
15.789474
[ "-INF = N", "-dp = [0, 1, 2, 3, 4, 5] + [INF for _ in range(N - 5)]", "+dp = list(range(N + 1))", "- dp[amount] = amount" ]
false
0.128241
0.099253
1.292056
[ "s514981266", "s932446566" ]
u489959379
p03038
python
s032544209
s759670356
597
271
33,640
33,440
Accepted
Accepted
54.61
n, m = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) BC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True) ans = 0 j = 0 for b, c in BC: for i in range(b): if j < n: ans += max(c, A[j]) j += 1 else: break if j < n: for i in range(n - j): ans += A[n - 1 - i] print(ans)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) query = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True) B = [] for i in range(m): b, c = query[i] while b and len(B) != n: B.append(c) b -= 1 B.sort(reverse=True) for i in range(len(B)): if A[i] < B[i]: A[i] = B[i] print((sum(A))) if __name__ == '__main__': resolve()
19
29
427
643
n, m = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) BC = sorted( [list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True, ) ans = 0 j = 0 for b, c in BC: for i in range(b): if j < n: ans += max(c, A[j]) j += 1 else: break if j < n: for i in range(n - j): ans += A[n - 1 - i] print(ans)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline f_inf = float("inf") mod = 10**9 + 7 def resolve(): n, m = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) query = sorted( [list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True, ) B = [] for i in range(m): b, c = query[i] while b and len(B) != n: B.append(c) b -= 1 B.sort(reverse=True) for i in range(len(B)): if A[i] < B[i]: A[i] = B[i] print((sum(A))) if __name__ == "__main__": resolve()
false
34.482759
[ "-n, m = list(map(int, input().split()))", "-A = sorted(list(map(int, input().split())))", "-BC = sorted(", "- [list(map(int, input().split())) for _ in range(m)],", "- key=lambda x: x[1],", "- reverse=True,", "-)", "-ans = 0", "-j = 0", "-for b, c in BC:", "- for i in range(b):", ...
false
0.037542
0.12289
0.305488
[ "s032544209", "s759670356" ]
u049191820
p02720
python
s807889850
s849037045
105
96
16,936
16,936
Accepted
Accepted
8.57
k = int(eval(input())) a=['1','2','3','4','5','6','7','8','9'] while 1: if k<=len(a): print((a[k-1])) exit() b=[] for i in a: if i[-1]!='0': b.append(i+chr(ord(i[-1])-1)) b.append(i+i[-1]) if i[-1]!='9': b.append(i+chr(ord(i[-1])+1)) k-=len(a) a=b.copy()
k = int(eval(input())) a=['1','2','3','4','5','6','7','8','9'] while k>len(a): b=[] for i in a: if i[-1]!='0': b.append(i+chr(ord(i[-1])-1)) b.append(i+i[-1]) if i[-1]!='9': b.append(i+chr(ord(i[-1])+1)) k-=len(a) a=b.copy() print((a[k-1]))
16
15
346
312
k = int(eval(input())) a = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] while 1: if k <= len(a): print((a[k - 1])) exit() b = [] for i in a: if i[-1] != "0": b.append(i + chr(ord(i[-1]) - 1)) b.append(i + i[-1]) if i[-1] != "9": b.append(i + chr(ord(i[-1]) + 1)) k -= len(a) a = b.copy()
k = int(eval(input())) a = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] while k > len(a): b = [] for i in a: if i[-1] != "0": b.append(i + chr(ord(i[-1]) - 1)) b.append(i + i[-1]) if i[-1] != "9": b.append(i + chr(ord(i[-1]) + 1)) k -= len(a) a = b.copy() print((a[k - 1]))
false
6.25
[ "-while 1:", "- if k <= len(a):", "- print((a[k - 1]))", "- exit()", "+while k > len(a):", "+print((a[k - 1]))" ]
false
0.043272
0.040489
1.068739
[ "s807889850", "s849037045" ]
u367130284
p03660
python
s914950297
s144822334
1,006
549
126,172
121,564
Accepted
Accepted
45.43
#高速化heapqダイクストラ from collections import * from heapq import* import sys input=lambda:sys.stdin.readline() def BFS(point,d): cost=[1e7]*(n+1) cost[point]=0 Q=[] heappush(Q,(0,point)) while Q: c,p=heappop(Q) for np in d[p]: if cost[np]==1e7: cost[np]=c+1 heappush(Q,(c+1,np)) return cost n=int(eval(input())) d=[deque()for i in range(n+1)] for i in range(n-1): a,b=list(map(int,input().split())) d[a].append(b) d[b].append(a) x=BFS(1,d)[1:] y=BFS(n,d)[1:] #print(x,y) F=0 S=0 for s,t in zip(x,y): if s<=t: F+=1 else: S+=1 if F<=S: print("Snuke") else: print("Fennec")
from collections import * from heapq import* import sys input=lambda:sys.stdin.readline() def BFS(point,d): cost=[1e7]*(n+1) cost[point]=0 Q=[] Q.append((0,point)) while Q: c,p=Q.pop() for np in d[p]: if cost[np]==1e7: cost[np]=c+1 Q.append((c+1,np)) return cost n=int(eval(input())) d=[deque()for i in range(n+1)] for i in range(n-1): a,b=list(map(int,input().split())) d[a].append(b) d[b].append(a) x=BFS(1,d)[1:] y=BFS(n,d)[1:] #print(x,y) F=0 S=0 for s,t in zip(x,y): if s<=t: F+=1 else: S+=1 if F<=S: print("Snuke") else: print("Fennec")
46
45
748
724
# 高速化heapqダイクストラ from collections import * from heapq import * import sys input = lambda: sys.stdin.readline() def BFS(point, d): cost = [1e7] * (n + 1) cost[point] = 0 Q = [] heappush(Q, (0, point)) while Q: c, p = heappop(Q) for np in d[p]: if cost[np] == 1e7: cost[np] = c + 1 heappush(Q, (c + 1, np)) return cost n = int(eval(input())) d = [deque() for i in range(n + 1)] for i in range(n - 1): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) x = BFS(1, d)[1:] y = BFS(n, d)[1:] # print(x,y) F = 0 S = 0 for s, t in zip(x, y): if s <= t: F += 1 else: S += 1 if F <= S: print("Snuke") else: print("Fennec")
from collections import * from heapq import * import sys input = lambda: sys.stdin.readline() def BFS(point, d): cost = [1e7] * (n + 1) cost[point] = 0 Q = [] Q.append((0, point)) while Q: c, p = Q.pop() for np in d[p]: if cost[np] == 1e7: cost[np] = c + 1 Q.append((c + 1, np)) return cost n = int(eval(input())) d = [deque() for i in range(n + 1)] for i in range(n - 1): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) x = BFS(1, d)[1:] y = BFS(n, d)[1:] # print(x,y) F = 0 S = 0 for s, t in zip(x, y): if s <= t: F += 1 else: S += 1 if F <= S: print("Snuke") else: print("Fennec")
false
2.173913
[ "-# 高速化heapqダイクストラ", "- heappush(Q, (0, point))", "+ Q.append((0, point))", "- c, p = heappop(Q)", "+ c, p = Q.pop()", "- heappush(Q, (c + 1, np))", "+ Q.append((c + 1, np))" ]
false
0.038248
0.041496
0.921726
[ "s914950297", "s144822334" ]
u073852194
p03304
python
s282034618
s343392586
166
25
38,256
9,168
Accepted
Accepted
84.94
n,m,d = list(map(int,input().split())) if d==0: print(((m-1)/n)) else: print((2*(n-d)*(m-1)/n**2))
N, M, D = list(map(int, input().split())) if D == 0: print(((M - 1) / N)) else: print(((N - D) * (M - 1) * 2 / (N ** 2)))
6
5
102
123
n, m, d = list(map(int, input().split())) if d == 0: print(((m - 1) / n)) else: print((2 * (n - d) * (m - 1) / n**2))
N, M, D = list(map(int, input().split())) if D == 0: print(((M - 1) / N)) else: print(((N - D) * (M - 1) * 2 / (N**2)))
false
16.666667
[ "-n, m, d = list(map(int, input().split()))", "-if d == 0:", "- print(((m - 1) / n))", "+N, M, D = list(map(int, input().split()))", "+if D == 0:", "+ print(((M - 1) / N))", "- print((2 * (n - d) * (m - 1) / n**2))", "+ print(((N - D) * (M - 1) * 2 / (N**2)))" ]
false
0.084701
0.044658
1.896649
[ "s282034618", "s343392586" ]
u253389610
p02685
python
s235008209
s212993658
1,332
269
16,776
32,648
Accepted
Accepted
79.8
def main(): N, M, K = [int(x) for x in input().split()] if M == 1: if K == N - 1: return 1 else: return 0 if N == 1: return M mod = 998244353 fact = [1] for i in range(1, N): fact.append(fact[-1] * i % mod) count = 0 for k in range(K + 1): current = pow(M - 1, N - k - 1, mod) * M % mod rev = pow(fact[k] * fact[N - 1 - k] % mod, mod - 2, mod) current = (current * fact[N - 1] % mod) * rev % mod count = (count + current) % mod return count if __name__ == "__main__": print((main()))
def main(): N, M, K = [int(x) for x in input().split()] if M == 1: if K == N - 1: return 1 else: return 0 if N == 1: return M mod = 998244353 fact = [1] for i in range(1, N): fact.append(fact[-1] * i % mod) fact_inv = [pow(fact[-1], mod - 2, mod)] for n in range(N - 1, 0, -1): fact_inv.append(fact_inv[-1] * n % mod) fact_inv = fact_inv[::-1] m_1_pow = [1] for _ in range(N): m_1_pow.append(m_1_pow[-1] * (M - 1) % mod) count = 0 for k in range(K + 1): current = ((((m_1_pow[N - k - 1] * M) % mod) * fact[N - 1] % mod) * fact_inv[k] % mod) * fact_inv[N - 1 - k] % mod count = (count + current) % mod return count if __name__ == "__main__": print((main()))
24
29
635
833
def main(): N, M, K = [int(x) for x in input().split()] if M == 1: if K == N - 1: return 1 else: return 0 if N == 1: return M mod = 998244353 fact = [1] for i in range(1, N): fact.append(fact[-1] * i % mod) count = 0 for k in range(K + 1): current = pow(M - 1, N - k - 1, mod) * M % mod rev = pow(fact[k] * fact[N - 1 - k] % mod, mod - 2, mod) current = (current * fact[N - 1] % mod) * rev % mod count = (count + current) % mod return count if __name__ == "__main__": print((main()))
def main(): N, M, K = [int(x) for x in input().split()] if M == 1: if K == N - 1: return 1 else: return 0 if N == 1: return M mod = 998244353 fact = [1] for i in range(1, N): fact.append(fact[-1] * i % mod) fact_inv = [pow(fact[-1], mod - 2, mod)] for n in range(N - 1, 0, -1): fact_inv.append(fact_inv[-1] * n % mod) fact_inv = fact_inv[::-1] m_1_pow = [1] for _ in range(N): m_1_pow.append(m_1_pow[-1] * (M - 1) % mod) count = 0 for k in range(K + 1): current = ( ((((m_1_pow[N - k - 1] * M) % mod) * fact[N - 1] % mod) * fact_inv[k] % mod) * fact_inv[N - 1 - k] % mod ) count = (count + current) % mod return count if __name__ == "__main__": print((main()))
false
17.241379
[ "+ fact_inv = [pow(fact[-1], mod - 2, mod)]", "+ for n in range(N - 1, 0, -1):", "+ fact_inv.append(fact_inv[-1] * n % mod)", "+ fact_inv = fact_inv[::-1]", "+ m_1_pow = [1]", "+ for _ in range(N):", "+ m_1_pow.append(m_1_pow[-1] * (M - 1) % mod)", "- current = pow(...
false
0.077916
0.114932
0.677927
[ "s235008209", "s212993658" ]
u133936772
p02983
python
s194714737
s915950177
675
97
3,060
3,060
Accepted
Accepted
85.63
mod = 2019 l, r = list(map(int, input().split())) if r//mod - l//mod > 0: print((0)) else: l %= mod r %= mod ans = mod - 1 for i in range(l+1, r+1): for j in range(l, i): ans = min(i*j%mod, ans) print(ans)
mod = 2019 l, r = list(map(int, input().split())) if r//mod - l//mod > 0: print((0)) else: l %= mod r %= mod ans = mod for i in range(l+1, r+1): for j in range(l, i): ans = min(i*j%mod, ans) if ans == 0: break print(ans)
13
15
232
259
mod = 2019 l, r = list(map(int, input().split())) if r // mod - l // mod > 0: print((0)) else: l %= mod r %= mod ans = mod - 1 for i in range(l + 1, r + 1): for j in range(l, i): ans = min(i * j % mod, ans) print(ans)
mod = 2019 l, r = list(map(int, input().split())) if r // mod - l // mod > 0: print((0)) else: l %= mod r %= mod ans = mod for i in range(l + 1, r + 1): for j in range(l, i): ans = min(i * j % mod, ans) if ans == 0: break print(ans)
false
13.333333
[ "- ans = mod - 1", "+ ans = mod", "+ if ans == 0:", "+ break" ]
false
0.080727
0.038883
2.076157
[ "s194714737", "s915950177" ]
u250583425
p02733
python
s396053054
s244239681
338
210
42,972
41,820
Accepted
Accepted
37.87
import sys def input(): return sys.stdin.readline().rstrip() def main(): H, W, K = list(map(int, input().split())) S = [tuple(map(int, list(eval(input())))) for _ in range(H)] ans = 10 ** 9 for bit in range(1 << (H-1)): canSolve = True ord = [0] * (H + 1) N = 0 for i in range(H): if bit & 1 << i: ord[i+1] = ord[i] + 1 N += 1 else: ord[i+1] = ord[i] nums = [0] * (H + 1) for w in range(W): one = [0] * (H + 1) overK = False for h in range(H): one[ord[h]] += S[h][w] nums[ord[h]] += S[h][w] if one[ord[h]] > K: canSolve = False if nums[ord[h]] > K: overK = True if not canSolve: break if overK: N += 1 nums = one if canSolve and ans > N: ans = N print(ans) if __name__ == '__main__': main()
import sys def input(): return sys.stdin.readline().rstrip() def main(): H, W, K = list(map(int, input().split())) S = [tuple(map(int, list(eval(input())))) for _ in range(H)] ans = 10 ** 9 for bit in range(1 << (H-1)): canSolve = True order = [0] * (H + 1) tmp_ans = 0 for i in range(H): if bit & 1 << i: order[i+1] = order[i] + 1 tmp_ans += 1 else: order[i+1] = order[i] sum_block = [0] * (H + 1) for w in range(W): one_block = [0] * (H + 1) overK = False for h in range(H): h_index = order[h] one_block[h_index] += S[h][w] sum_block[h_index] += S[h][w] if one_block[h_index] > K: canSolve = False if sum_block[h_index] > K: overK = True if not canSolve: break if overK: tmp_ans += 1 sum_block = one_block if tmp_ans >= ans: canSolve = False break if canSolve: ans = tmp_ans print(ans) if __name__ == '__main__': main()
41
44
1,099
1,292
import sys def input(): return sys.stdin.readline().rstrip() def main(): H, W, K = list(map(int, input().split())) S = [tuple(map(int, list(eval(input())))) for _ in range(H)] ans = 10**9 for bit in range(1 << (H - 1)): canSolve = True ord = [0] * (H + 1) N = 0 for i in range(H): if bit & 1 << i: ord[i + 1] = ord[i] + 1 N += 1 else: ord[i + 1] = ord[i] nums = [0] * (H + 1) for w in range(W): one = [0] * (H + 1) overK = False for h in range(H): one[ord[h]] += S[h][w] nums[ord[h]] += S[h][w] if one[ord[h]] > K: canSolve = False if nums[ord[h]] > K: overK = True if not canSolve: break if overK: N += 1 nums = one if canSolve and ans > N: ans = N print(ans) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().rstrip() def main(): H, W, K = list(map(int, input().split())) S = [tuple(map(int, list(eval(input())))) for _ in range(H)] ans = 10**9 for bit in range(1 << (H - 1)): canSolve = True order = [0] * (H + 1) tmp_ans = 0 for i in range(H): if bit & 1 << i: order[i + 1] = order[i] + 1 tmp_ans += 1 else: order[i + 1] = order[i] sum_block = [0] * (H + 1) for w in range(W): one_block = [0] * (H + 1) overK = False for h in range(H): h_index = order[h] one_block[h_index] += S[h][w] sum_block[h_index] += S[h][w] if one_block[h_index] > K: canSolve = False if sum_block[h_index] > K: overK = True if not canSolve: break if overK: tmp_ans += 1 sum_block = one_block if tmp_ans >= ans: canSolve = False break if canSolve: ans = tmp_ans print(ans) if __name__ == "__main__": main()
false
6.818182
[ "- ord = [0] * (H + 1)", "- N = 0", "+ order = [0] * (H + 1)", "+ tmp_ans = 0", "- ord[i + 1] = ord[i] + 1", "- N += 1", "+ order[i + 1] = order[i] + 1", "+ tmp_ans += 1", "- ord[i + 1] = ord[i]", ...
false
0.106264
0.093658
1.134598
[ "s396053054", "s244239681" ]
u043048943
p02947
python
s139271498
s708050064
1,443
334
66,012
58,076
Accepted
Accepted
76.85
import sys sys.setrecursionlimit(2**31-1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) dbg = lambda *something : print(*something) if DEBUG is True else 0 DEBUG = True def cmb(n,r): #nCr = n!/(n-r)!r! retVal = 1 for i in range(n-r+1,n+1): retVal *= i for i in range(2,r+1): retVal //= i return retVal def main(): from collections import defaultdict N = int(input()) d = defaultdict(lambda:0) base = ord('a') ans = 0 for _ in range(N): s = input().strip() num = 0 for c in s: num += 26 ** (ord(c) - base) ans += d[num] d[num] += 1 print(ans) pass if __name__ == '__main__': main()
import sys sys.setrecursionlimit(2**31-1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) dbg = lambda *something : print(*something) if DEBUG is True else 0 DEBUG = True def cmb(n,r): #nCr = n!/(n-r)!r! retVal = 1 for i in range(n-r+1,n+1): retVal *= i for i in range(2,r+1): retVal //= i return retVal def main(): from collections import defaultdict N = int(input()) d = defaultdict(lambda:0) base = ord('a') ans = 0 for _ in range(N): s = input().strip() s = ''.join(sorted(s)) ans += d[s] d[s] += 1 print(ans) pass if __name__ == '__main__': main()
43
41
851
800
import sys sys.setrecursionlimit(2**31 - 1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda: list(map(int, input().split())) II = lambda: int(input()) dbg = lambda *something: print(*something) if DEBUG is True else 0 DEBUG = True def cmb(n, r): # nCr = n!/(n-r)!r! retVal = 1 for i in range(n - r + 1, n + 1): retVal *= i for i in range(2, r + 1): retVal //= i return retVal def main(): from collections import defaultdict N = int(input()) d = defaultdict(lambda: 0) base = ord("a") ans = 0 for _ in range(N): s = input().strip() num = 0 for c in s: num += 26 ** (ord(c) - base) ans += d[num] d[num] += 1 print(ans) pass if __name__ == "__main__": main()
import sys sys.setrecursionlimit(2**31 - 1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda: list(map(int, input().split())) II = lambda: int(input()) dbg = lambda *something: print(*something) if DEBUG is True else 0 DEBUG = True def cmb(n, r): # nCr = n!/(n-r)!r! retVal = 1 for i in range(n - r + 1, n + 1): retVal *= i for i in range(2, r + 1): retVal //= i return retVal def main(): from collections import defaultdict N = int(input()) d = defaultdict(lambda: 0) base = ord("a") ans = 0 for _ in range(N): s = input().strip() s = "".join(sorted(s)) ans += d[s] d[s] += 1 print(ans) pass if __name__ == "__main__": main()
false
4.651163
[ "- num = 0", "- for c in s:", "- num += 26 ** (ord(c) - base)", "- ans += d[num]", "- d[num] += 1", "+ s = \"\".join(sorted(s))", "+ ans += d[s]", "+ d[s] += 1" ]
false
0.106041
0.041653
2.545827
[ "s139271498", "s708050064" ]
u408071652
p02608
python
s860517447
s655959858
852
229
9,464
9,588
Accepted
Accepted
73.12
import sys import math import heapq def input(): return sys.stdin.readline().rstrip() def tc(): N = int(eval(input())) def main(): N = int(eval(input())) dp = [0]*(N+1) rt = int(N **0.5) +2 for i in range(1,rt): for j in range(1,rt): for k in range(1,rt): case =int( i**2 + j **2 + k **2 + i*j + i*k + j*k ) if case <=N: dp[case] +=1 for l in range(1,N+1): print((dp[l])) if __name__ == "__main__": main()
import sys import math import heapq def input(): return sys.stdin.readline().rstrip() def tc(): N = int(eval(input())) def main(): N = int(eval(input())) dp = [0]*(N+1) rt = int(N **0.5) +2 for i in range(1,rt): for j in range(1,rt): if int( i**2 + j **2 + 1 + i*j + i*1 + j*1 ) >N: break for k in range(1,rt): case =int( i**2 + j **2 + k **2 + i*j + i*k + j*k ) if case <=N: dp[case] +=1 else: break for l in range(1,N+1): print((dp[l])) if __name__ == "__main__": main()
41
44
564
697
import sys import math import heapq def input(): return sys.stdin.readline().rstrip() def tc(): N = int(eval(input())) def main(): N = int(eval(input())) dp = [0] * (N + 1) rt = int(N**0.5) + 2 for i in range(1, rt): for j in range(1, rt): for k in range(1, rt): case = int(i**2 + j**2 + k**2 + i * j + i * k + j * k) if case <= N: dp[case] += 1 for l in range(1, N + 1): print((dp[l])) if __name__ == "__main__": main()
import sys import math import heapq def input(): return sys.stdin.readline().rstrip() def tc(): N = int(eval(input())) def main(): N = int(eval(input())) dp = [0] * (N + 1) rt = int(N**0.5) + 2 for i in range(1, rt): for j in range(1, rt): if int(i**2 + j**2 + 1 + i * j + i * 1 + j * 1) > N: break for k in range(1, rt): case = int(i**2 + j**2 + k**2 + i * j + i * k + j * k) if case <= N: dp[case] += 1 else: break for l in range(1, N + 1): print((dp[l])) if __name__ == "__main__": main()
false
6.818182
[ "+ if int(i**2 + j**2 + 1 + i * j + i * 1 + j * 1) > N:", "+ break", "+ else:", "+ break" ]
false
0.045945
0.03877
1.185063
[ "s860517447", "s655959858" ]
u545368057
p02839
python
s951503101
s632995581
115
71
20,980
12,788
Accepted
Accepted
38.26
M = 6400*4 mid = M//2 INF = 10**18 H,W = list(map(int, input().split())) As = [] for i in range(H): As.append(list(map(int, input().split()))) diffs = [] for i in range(H): bs = list(map(int, input().split())) diffs.append([abs(a-b) for a,b in zip(As[i],bs)]) # bitset高速化 # 初期値 dp = [[0]*W for j in range(H)] dp[0][0] = 1 << (mid+diffs[0][0]) #プラスマイナス考慮して、下駄をはかせる for i in range(H): for j in range(W): # 行方向 if i+1 < H: d = diffs[i+1][j] dp[i+1][j] |= dp[i][j] >> d dp[i+1][j] |= dp[i][j] << d # 列方向 if j+1 < W: d = diffs[i][j+1] dp[i][j+1] |= dp[i][j] >> d dp[i][j+1] |= dp[i][j] << d ans = INF for i in range(M): if dp[H-1][W-1] >> i & 1: # print(i-mid) ans = min(ans, abs(i-mid)) print(ans)
M = 6400 mid = M//2 INF = 10**18 H,W = list(map(int, input().split())) As = [] for i in range(H): As.append(list(map(int, input().split()))) diffs = [] for i in range(H): bs = list(map(int, input().split())) diffs.append([abs(a-b) for a,b in zip(As[i],bs)]) # bitset高速化 # 初期値 dp = [[0]*W for j in range(H)] dp[0][0] = 1 << (mid+diffs[0][0]) #プラスマイナス考慮して、下駄をはかせる for i in range(H): for j in range(W): # 行方向 if i+1 < H: d = diffs[i+1][j] dp[i+1][j] |= dp[i][j] >> d dp[i+1][j] |= dp[i][j] << d # 列方向 if j+1 < W: d = diffs[i][j+1] dp[i][j+1] |= dp[i][j] >> d dp[i][j+1] |= dp[i][j] << d ans = INF for i in range(M): if dp[H-1][W-1] >> i & 1: # print(i-mid) ans = min(ans, abs(i-mid)) print(ans)
36
36
869
868
M = 6400 * 4 mid = M // 2 INF = 10**18 H, W = list(map(int, input().split())) As = [] for i in range(H): As.append(list(map(int, input().split()))) diffs = [] for i in range(H): bs = list(map(int, input().split())) diffs.append([abs(a - b) for a, b in zip(As[i], bs)]) # bitset高速化 # 初期値 dp = [[0] * W for j in range(H)] dp[0][0] = 1 << (mid + diffs[0][0]) # プラスマイナス考慮して、下駄をはかせる for i in range(H): for j in range(W): # 行方向 if i + 1 < H: d = diffs[i + 1][j] dp[i + 1][j] |= dp[i][j] >> d dp[i + 1][j] |= dp[i][j] << d # 列方向 if j + 1 < W: d = diffs[i][j + 1] dp[i][j + 1] |= dp[i][j] >> d dp[i][j + 1] |= dp[i][j] << d ans = INF for i in range(M): if dp[H - 1][W - 1] >> i & 1: # print(i-mid) ans = min(ans, abs(i - mid)) print(ans)
M = 6400 mid = M // 2 INF = 10**18 H, W = list(map(int, input().split())) As = [] for i in range(H): As.append(list(map(int, input().split()))) diffs = [] for i in range(H): bs = list(map(int, input().split())) diffs.append([abs(a - b) for a, b in zip(As[i], bs)]) # bitset高速化 # 初期値 dp = [[0] * W for j in range(H)] dp[0][0] = 1 << (mid + diffs[0][0]) # プラスマイナス考慮して、下駄をはかせる for i in range(H): for j in range(W): # 行方向 if i + 1 < H: d = diffs[i + 1][j] dp[i + 1][j] |= dp[i][j] >> d dp[i + 1][j] |= dp[i][j] << d # 列方向 if j + 1 < W: d = diffs[i][j + 1] dp[i][j + 1] |= dp[i][j] >> d dp[i][j + 1] |= dp[i][j] << d ans = INF for i in range(M): if dp[H - 1][W - 1] >> i & 1: # print(i-mid) ans = min(ans, abs(i - mid)) print(ans)
false
0
[ "-M = 6400 * 4", "+M = 6400" ]
false
0.053423
0.069565
0.767957
[ "s951503101", "s632995581" ]
u581187895
p02851
python
s884534557
s488640261
292
201
41,992
44,184
Accepted
Accepted
31.16
from itertools import accumulate from collections import defaultdict N, K = list(map(int, input().split())) A = [0] + [a-1 for a in map(int, input().split())] A_cum = list(accumulate(A)) A_cum = [a%K for a in A_cum] ans = 0 dd = defaultdict(int) q = [] for j in range(N+1): ans += dd[A_cum[j]] dd[A_cum[j]] += 1 q.append(A_cum[j]) if len(q) == K: dd[q[0]] -= 1 q.pop(0) print(ans)
from itertools import accumulate from collections import defaultdict, deque def resolve(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = accumulate([a % K for a in A]) A = [0] + list(A) # 区間 [i,j] の和(累積和): dj+1−di # 区間 [i,j] の要素の数(0_indの為 +1): j−i+1 # 上記を一般化: dr−dl=r−l となるものの個数を求める # r−l<K の時、mod K において式変形が成り立つ, dr−r=dl−l # rを固定し辞書で管理すれば、dl−lと同じ値なので個数を求められる。 cnt = defaultdict(int) q = deque() ans = 0 for r in range(N + 1): t = (A[r] - r) % K ans += cnt[t] cnt[t] += 1 q.append(t) if len(q) == K: left = q.popleft() cnt[left] -= 1 print(ans) if __name__ == "__main__": resolve()
20
33
421
774
from itertools import accumulate from collections import defaultdict N, K = list(map(int, input().split())) A = [0] + [a - 1 for a in map(int, input().split())] A_cum = list(accumulate(A)) A_cum = [a % K for a in A_cum] ans = 0 dd = defaultdict(int) q = [] for j in range(N + 1): ans += dd[A_cum[j]] dd[A_cum[j]] += 1 q.append(A_cum[j]) if len(q) == K: dd[q[0]] -= 1 q.pop(0) print(ans)
from itertools import accumulate from collections import defaultdict, deque def resolve(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = accumulate([a % K for a in A]) A = [0] + list(A) # 区間 [i,j] の和(累積和): dj+1−di # 区間 [i,j] の要素の数(0_indの為 +1): j−i+1 # 上記を一般化: dr−dl=r−l となるものの個数を求める # r−l<K の時、mod K において式変形が成り立つ, dr−r=dl−l # rを固定し辞書で管理すれば、dl−lと同じ値なので個数を求められる。 cnt = defaultdict(int) q = deque() ans = 0 for r in range(N + 1): t = (A[r] - r) % K ans += cnt[t] cnt[t] += 1 q.append(t) if len(q) == K: left = q.popleft() cnt[left] -= 1 print(ans) if __name__ == "__main__": resolve()
false
39.393939
[ "-from collections import defaultdict", "+from collections import defaultdict, deque", "-N, K = list(map(int, input().split()))", "-A = [0] + [a - 1 for a in map(int, input().split())]", "-A_cum = list(accumulate(A))", "-A_cum = [a % K for a in A_cum]", "-ans = 0", "-dd = defaultdict(int)", "-q = []...
false
0.032822
0.032555
1.008192
[ "s884534557", "s488640261" ]
u251515715
p03495
python
s285100084
s435185925
232
193
48,424
48,432
Accepted
Accepted
16.81
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) now_k=len(set(a)) d=now_k-k arr=collections.Counter(a).most_common() #print(arr) b=sorted([arr[i][1] for i in range(now_k)]) #print(b) cnt=now_k cnt2=0 flg=0 for i in b: cnt-=1 cnt2+=i if cnt==k: print(cnt2) flg=1 break if flg==0: print((0))
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) now_k=len(set(a)) d=now_k-k arr=collections.Counter(a).most_common() b=sorted([arr[i][1] for i in range(now_k)]) print((sum(b[:d])))
22
10
362
222
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) now_k = len(set(a)) d = now_k - k arr = collections.Counter(a).most_common() # print(arr) b = sorted([arr[i][1] for i in range(now_k)]) # print(b) cnt = now_k cnt2 = 0 flg = 0 for i in b: cnt -= 1 cnt2 += i if cnt == k: print(cnt2) flg = 1 break if flg == 0: print((0))
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) now_k = len(set(a)) d = now_k - k arr = collections.Counter(a).most_common() b = sorted([arr[i][1] for i in range(now_k)]) print((sum(b[:d])))
false
54.545455
[ "-# print(arr)", "-# print(b)", "-cnt = now_k", "-cnt2 = 0", "-flg = 0", "-for i in b:", "- cnt -= 1", "- cnt2 += i", "- if cnt == k:", "- print(cnt2)", "- flg = 1", "- break", "-if flg == 0:", "- print((0))", "+print((sum(b[:d])))" ]
false
0.039842
0.118982
0.334861
[ "s285100084", "s435185925" ]
u102960641
p02786
python
s032095079
s398419623
23
17
3,572
2,940
Accepted
Accepted
26.09
from functools import lru_cache import sys sys.setrecursionlimit(10000000) @lru_cache(maxsize= 10 ** 7) def solve(n): if n == 1: return 1 else: return solve(n//2) * 2 + 1 h = int(eval(input())) print((solve(h)))
def solve(n): if n == 1: return 1 else: return solve(n//2) * 2 + 1 h = int(eval(input())) print((solve(h)))
11
7
226
117
from functools import lru_cache import sys sys.setrecursionlimit(10000000) @lru_cache(maxsize=10**7) def solve(n): if n == 1: return 1 else: return solve(n // 2) * 2 + 1 h = int(eval(input())) print((solve(h)))
def solve(n): if n == 1: return 1 else: return solve(n // 2) * 2 + 1 h = int(eval(input())) print((solve(h)))
false
36.363636
[ "-from functools import lru_cache", "-import sys", "-", "-sys.setrecursionlimit(10000000)", "-", "-", "-@lru_cache(maxsize=10**7)" ]
false
0.037753
0.036879
1.023692
[ "s032095079", "s398419623" ]
u736729525
p02775
python
s212188065
s021801131
411
349
21,444
116,260
Accepted
Accepted
15.09
X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] def solve(N): N = [int(c) for c in N][::-1] p = 0 b = 0 for i in range(len(N)): c = N[i] + b p += X[c] if c == 5: b = 0 if i == len(N)-1 or N[i+1] < 5 else 1 elif c > 5: b = 1 else: b = 0 return p + b print((solve(eval(input()))))
X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] def solve(N): N = [int(c) for c in N][::-1] p = 0 b = 0 for i in range(len(N)): c = N[i] + b p += X[c] if c == 5: b = 0 if i == len(N)-1 or N[i+1] < 5 else 1 else: b = c > 5 return p + b print((solve(eval(input()))))
17
15
374
338
X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] def solve(N): N = [int(c) for c in N][::-1] p = 0 b = 0 for i in range(len(N)): c = N[i] + b p += X[c] if c == 5: b = 0 if i == len(N) - 1 or N[i + 1] < 5 else 1 elif c > 5: b = 1 else: b = 0 return p + b print((solve(eval(input()))))
X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] def solve(N): N = [int(c) for c in N][::-1] p = 0 b = 0 for i in range(len(N)): c = N[i] + b p += X[c] if c == 5: b = 0 if i == len(N) - 1 or N[i + 1] < 5 else 1 else: b = c > 5 return p + b print((solve(eval(input()))))
false
11.764706
[ "- elif c > 5:", "- b = 1", "- b = 0", "+ b = c > 5" ]
false
0.041819
0.038203
1.094652
[ "s212188065", "s021801131" ]
u810356688
p03200
python
s332096887
s017751026
202
33
40,048
3,500
Accepted
Accepted
83.66
import sys def input(): return sys.stdin.readline().rstrip() def main(): s=eval(input()) n=len(s) flag=-1 for i in range(n): if s[i]=='W': flag=i else: break cunt_b=0 cunt_w=0 ans=0 for i in range(n): if s[i]=='B': cunt_b+=1 elif cunt_b>0: ans+=i-flag-1-cunt_w cunt_w+=1 print(ans) if __name__=='__main__': main()
import sys def input(): return sys.stdin.readline().rstrip() def main(): s=eval(input()) cunt_b=0 ans=0 for ss in s: if ss=='B': cunt_b+=1 else: ans+=cunt_b print(ans) if __name__=='__main__': main()
26
15
467
272
import sys def input(): return sys.stdin.readline().rstrip() def main(): s = eval(input()) n = len(s) flag = -1 for i in range(n): if s[i] == "W": flag = i else: break cunt_b = 0 cunt_w = 0 ans = 0 for i in range(n): if s[i] == "B": cunt_b += 1 elif cunt_b > 0: ans += i - flag - 1 - cunt_w cunt_w += 1 print(ans) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().rstrip() def main(): s = eval(input()) cunt_b = 0 ans = 0 for ss in s: if ss == "B": cunt_b += 1 else: ans += cunt_b print(ans) if __name__ == "__main__": main()
false
42.307692
[ "- n = len(s)", "- flag = -1", "- for i in range(n):", "- if s[i] == \"W\":", "- flag = i", "+ cunt_b = 0", "+ ans = 0", "+ for ss in s:", "+ if ss == \"B\":", "+ cunt_b += 1", "- break", "- cunt_b = 0", "- cunt_w = 0", ...
false
0.047061
0.067064
0.701731
[ "s332096887", "s017751026" ]
u077291787
p03436
python
s695699230
s258189777
25
22
3,316
3,064
Accepted
Accepted
12
# ABC088D - Grid Repainting from collections import deque def bfs() -> None: dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] q = deque([(0, 0)]) while q: x, y = q.popleft() for dx, dy in dxy: nx, ny = x + dx, y + dy # next x, y # find unsearched grids of S and keep them in the queue if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and D[nx][ny] == 0: q.append((nx, ny)) D[nx][ny] = D[x][y] + 1 def main(): # shortest path needs to remain white, the rest can be black global H, W, S, D H, W, *S = open(0).read().split() H, W = int(H), int(W) D = [[0] * W for _ in range(H)] # distance from (0, 0) to (x, y) D[0][0] = 1 bfs() white, x = sum(s.count(".") for s in S), D[-1][-1] ans = white - x if x else -1 # x = 0 <-> can't make a path to goal print(ans) if __name__ == "__main__": main()
# ABC088D - Grid Repainting def bfs() -> None: dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] q = [(0, 0)] while q: x, y = q.pop(0) for dx, dy in dxy: nx, ny = x + dx, y + dy # next x, y # find unsearched grids of S and keep them in the queue if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and D[nx][ny] == 0: q.append((nx, ny)) D[nx][ny] = D[x][y] + 1 def main(): # shortest path needs to remain white, the rest can be black global H, W, S, D H, W, *S = open(0).read().split() H, W = int(H), int(W) D = [[0] * W for _ in range(H)] # distance from (0, 0) to (x, y) D[0][0] = 1 bfs() white, x = sum(s.count(".") for s in S), D[-1][-1] ans = white - x if x else -1 # x = 0 <-> can't make a path to goal print(ans) if __name__ == "__main__": main()
31
29
962
919
# ABC088D - Grid Repainting from collections import deque def bfs() -> None: dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] q = deque([(0, 0)]) while q: x, y = q.popleft() for dx, dy in dxy: nx, ny = x + dx, y + dy # next x, y # find unsearched grids of S and keep them in the queue if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and D[nx][ny] == 0: q.append((nx, ny)) D[nx][ny] = D[x][y] + 1 def main(): # shortest path needs to remain white, the rest can be black global H, W, S, D H, W, *S = open(0).read().split() H, W = int(H), int(W) D = [[0] * W for _ in range(H)] # distance from (0, 0) to (x, y) D[0][0] = 1 bfs() white, x = sum(s.count(".") for s in S), D[-1][-1] ans = white - x if x else -1 # x = 0 <-> can't make a path to goal print(ans) if __name__ == "__main__": main()
# ABC088D - Grid Repainting def bfs() -> None: dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] q = [(0, 0)] while q: x, y = q.pop(0) for dx, dy in dxy: nx, ny = x + dx, y + dy # next x, y # find unsearched grids of S and keep them in the queue if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and D[nx][ny] == 0: q.append((nx, ny)) D[nx][ny] = D[x][y] + 1 def main(): # shortest path needs to remain white, the rest can be black global H, W, S, D H, W, *S = open(0).read().split() H, W = int(H), int(W) D = [[0] * W for _ in range(H)] # distance from (0, 0) to (x, y) D[0][0] = 1 bfs() white, x = sum(s.count(".") for s in S), D[-1][-1] ans = white - x if x else -1 # x = 0 <-> can't make a path to goal print(ans) if __name__ == "__main__": main()
false
6.451613
[ "-from collections import deque", "-", "-", "- q = deque([(0, 0)])", "+ q = [(0, 0)]", "- x, y = q.popleft()", "+ x, y = q.pop(0)" ]
false
0.046968
0.046049
1.019958
[ "s695699230", "s258189777" ]
u979552932
p04025
python
s821607752
s095995039
174
18
13,336
2,940
Accepted
Accepted
89.66
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split()))) b = round(sum(a) / n) m = int(sum((a - b) ** 2)) print(m)
n = int(eval(input())) a = list(map(int, input().split())) b = round(sum(a) / n) m = sum([(x - b) ** 2 for x in a]) print(m)
6
5
144
122
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split()))) b = round(sum(a) / n) m = int(sum((a - b) ** 2)) print(m)
n = int(eval(input())) a = list(map(int, input().split())) b = round(sum(a) / n) m = sum([(x - b) ** 2 for x in a]) print(m)
false
16.666667
[ "-import numpy as np", "-", "-a = np.array(list(map(int, input().split())))", "+a = list(map(int, input().split()))", "-m = int(sum((a - b) ** 2))", "+m = sum([(x - b) ** 2 for x in a])" ]
false
0.609234
0.041098
14.82386
[ "s821607752", "s095995039" ]
u966695319
p03546
python
s005841453
s746721998
196
80
40,556
73,800
Accepted
Accepted
59.18
H, W = list(map(int, input().split())) change_costs = [list(map(int, input().split())) for _ in range(10)] # change_costsは9*9のコスト for k in range(10): for i in range(10): for j in range(10): # print(k, i, j) change_costs[i][j] = min(change_costs[i][j], change_costs[i][k] + change_costs[k][j]) # print(change_costs) # nums = [] cost = 0 for _ in range(H): nums = list(map(int, input().split())) for num in nums: if num == -1: cost += 0 else: cost += change_costs[num][1] # nums.append(list(map(int, input().split()))) print(cost)
H, W = list(map(int, input().split())) costs = [list(map(int, input().split())) for _ in range(10)] nums = [0 for _ in range(10)] for k in range(10): for i in range(10): for j in range(10): costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]) ans = 0 for i in range(H): for num in list(map(int, input().split())): if num == -1: continue else: ans += costs[num][1] print(ans)
23
19
636
464
H, W = list(map(int, input().split())) change_costs = [list(map(int, input().split())) for _ in range(10)] # change_costsは9*9のコスト for k in range(10): for i in range(10): for j in range(10): # print(k, i, j) change_costs[i][j] = min( change_costs[i][j], change_costs[i][k] + change_costs[k][j] ) # print(change_costs) # nums = [] cost = 0 for _ in range(H): nums = list(map(int, input().split())) for num in nums: if num == -1: cost += 0 else: cost += change_costs[num][1] # nums.append(list(map(int, input().split()))) print(cost)
H, W = list(map(int, input().split())) costs = [list(map(int, input().split())) for _ in range(10)] nums = [0 for _ in range(10)] for k in range(10): for i in range(10): for j in range(10): costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]) ans = 0 for i in range(H): for num in list(map(int, input().split())): if num == -1: continue else: ans += costs[num][1] print(ans)
false
17.391304
[ "-change_costs = [list(map(int, input().split())) for _ in range(10)]", "-# change_costsは9*9のコスト", "+costs = [list(map(int, input().split())) for _ in range(10)]", "+nums = [0 for _ in range(10)]", "- # print(k, i, j)", "- change_costs[i][j] = min(", "- change_costs[...
false
0.114593
0.057404
1.99623
[ "s005841453", "s746721998" ]
u729133443
p03264
python
s674259227
s419719412
17
10
2,940
2,568
Accepted
Accepted
41.18
n=int(eval(input()));print(([(n//2)**2,n//2*(n//2+1)][n%2]))
print(int((eval(input())*1.0/2)**2))
1
1
52
29
n = int(eval(input())) print(([(n // 2) ** 2, n // 2 * (n // 2 + 1)][n % 2]))
print(int((eval(input()) * 1.0 / 2) ** 2))
false
0
[ "-n = int(eval(input()))", "-print(([(n // 2) ** 2, n // 2 * (n // 2 + 1)][n % 2]))", "+print(int((eval(input()) * 1.0 / 2) ** 2))" ]
false
0.108647
0.03692
2.942788
[ "s674259227", "s419719412" ]
u614628638
p02726
python
s897415197
s234907190
1,573
1,293
3,572
3,444
Accepted
Accepted
17.8
n,x,y=list(map(int,input().split())) c=[0]*~-n for i in range(n): for j in range(i): c[min(~j+i,abs(~j+x)+abs(~i+y))]+=1 for i in c: print(i)
n,x,y=list(map(int,input().split())) c=[0]*~-n for i in range(n): for j in range(i): c[min(~j+i,abs(~j+x)+abs(~i+y))]+=1 print((*c))
7
6
149
135
n, x, y = list(map(int, input().split())) c = [0] * ~-n for i in range(n): for j in range(i): c[min(~j + i, abs(~j + x) + abs(~i + y))] += 1 for i in c: print(i)
n, x, y = list(map(int, input().split())) c = [0] * ~-n for i in range(n): for j in range(i): c[min(~j + i, abs(~j + x) + abs(~i + y))] += 1 print((*c))
false
14.285714
[ "-for i in c:", "- print(i)", "+print((*c))" ]
false
0.043049
0.043429
0.991258
[ "s897415197", "s234907190" ]
u681444474
p03549
python
s291991915
s295951580
170
28
38,256
9,060
Accepted
Accepted
83.53
# coding: utf-8 # Your code here! N,M=list(map(int,input().split())) tmp=M*1900+(N-M)*100 cnt=1 for i in range(M): cnt*=2 #print(cnt) print((tmp*cnt))
# coding: utf-8 N, M = list(map(int,input().split())) ans = 2**M*(1900*M+100*(N-M)) print(ans)
9
5
154
93
# coding: utf-8 # Your code here! N, M = list(map(int, input().split())) tmp = M * 1900 + (N - M) * 100 cnt = 1 for i in range(M): cnt *= 2 # print(cnt) print((tmp * cnt))
# coding: utf-8 N, M = list(map(int, input().split())) ans = 2**M * (1900 * M + 100 * (N - M)) print(ans)
false
44.444444
[ "-# Your code here!", "-tmp = M * 1900 + (N - M) * 100", "-cnt = 1", "-for i in range(M):", "- cnt *= 2", "-# print(cnt)", "-print((tmp * cnt))", "+ans = 2**M * (1900 * M + 100 * (N - M))", "+print(ans)" ]
false
0.033796
0.037464
0.902101
[ "s291991915", "s295951580" ]
u392029857
p03854
python
s700025331
s310689915
125
69
4,724
3,316
Accepted
Accepted
44.8
S = eval(input()) dd = ['dream', 'dreamer', 'erase', 'eraser'] chara = ''.join(reversed(list(S))) flag = True while flag: cnt = 0 for i in dd: r = ''.join(reversed(list(i))) if r in chara[:len(r)]: chara = chara[len(r):] break cnt += 1 if cnt == 4: flag = False if chara == '': print('YES') else: print('NO')
S = eval(input()) while len(S) > 0: if 'dream' in S[-5:]: S = S[:-5] continue if 'dreamer' in S[-7:]: S = S[:-7] continue if 'erase' in S[-5:]: S = S[:-5] continue if 'eraser' in S[-6:]: S = S[:-6] continue break if S == '': print('YES') else: print('NO')
19
19
397
359
S = eval(input()) dd = ["dream", "dreamer", "erase", "eraser"] chara = "".join(reversed(list(S))) flag = True while flag: cnt = 0 for i in dd: r = "".join(reversed(list(i))) if r in chara[: len(r)]: chara = chara[len(r) :] break cnt += 1 if cnt == 4: flag = False if chara == "": print("YES") else: print("NO")
S = eval(input()) while len(S) > 0: if "dream" in S[-5:]: S = S[:-5] continue if "dreamer" in S[-7:]: S = S[:-7] continue if "erase" in S[-5:]: S = S[:-5] continue if "eraser" in S[-6:]: S = S[:-6] continue break if S == "": print("YES") else: print("NO")
false
0
[ "-dd = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]", "-chara = \"\".join(reversed(list(S)))", "-flag = True", "-while flag:", "- cnt = 0", "- for i in dd:", "- r = \"\".join(reversed(list(i)))", "- if r in chara[: len(r)]:", "- chara = chara[len(r) :]", "- ...
false
0.03756
0.037423
1.003644
[ "s700025331", "s310689915" ]
u162911959
p02837
python
s411380876
s874217483
1,311
735
3,064
3,188
Accepted
Accepted
43.94
#!/usr/bin/env python3 import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) N = int(readline()) tes = [[-1]*N for i in range(N)] for i in range(N): A = int(readline()) for j in range(A): x,y = list(map(int,readline().rstrip().split())) tes[i][x-1] = y #ここまでが入力 cnt = 0 for i in range(2**N): hon = [0]*N for j in range(N): if (i>>j)&1: hon[j] = 1 #全状態2**N通りを作っておく flag = True for j in range(N): if hon[j]: #hon=1ならtesとの整合性を比較 for k in range(N): if tes[j][k] == -1: continue #証言されていない部分は飛ばす if tes[j][k] != hon[k]: flag = False if flag: cnt = max(cnt,hon.count(1)) print(cnt)
#!/usr/bin/env python3 import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) N = int(readline()) tes = [[-1]*N for i in range(N)] for i in range(N): A = int(readline()) for j in range(A): x,y = list(map(int,readline().rstrip().split())) tes[i][x-1] = y cnt = 0 for i in range(2**N): hon = [0]*N for j in range(N): if (i>>j)&1: hon[j] = 1 flag = True for j in range(N): if hon[j]: for k in range(N): if tes[j][k] == -1: continue if tes[j][k] != hon[k]: flag = False break if not flag: break if flag: cnt = max(cnt,hon.count(1)) print(cnt)
32
35
845
843
#!/usr/bin/env python3 import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**7) N = int(readline()) tes = [[-1] * N for i in range(N)] for i in range(N): A = int(readline()) for j in range(A): x, y = list(map(int, readline().rstrip().split())) tes[i][x - 1] = y # ここまでが入力 cnt = 0 for i in range(2**N): hon = [0] * N for j in range(N): if (i >> j) & 1: hon[j] = 1 # 全状態2**N通りを作っておく flag = True for j in range(N): if hon[j]: # hon=1ならtesとの整合性を比較 for k in range(N): if tes[j][k] == -1: continue # 証言されていない部分は飛ばす if tes[j][k] != hon[k]: flag = False if flag: cnt = max(cnt, hon.count(1)) print(cnt)
#!/usr/bin/env python3 import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**7) N = int(readline()) tes = [[-1] * N for i in range(N)] for i in range(N): A = int(readline()) for j in range(A): x, y = list(map(int, readline().rstrip().split())) tes[i][x - 1] = y cnt = 0 for i in range(2**N): hon = [0] * N for j in range(N): if (i >> j) & 1: hon[j] = 1 flag = True for j in range(N): if hon[j]: for k in range(N): if tes[j][k] == -1: continue if tes[j][k] != hon[k]: flag = False break if not flag: break if flag: cnt = max(cnt, hon.count(1)) print(cnt)
false
8.571429
[ "- tes[i][x - 1] = y # ここまでが入力", "+ tes[i][x - 1] = y", "- hon[j] = 1 # 全状態2**N通りを作っておく", "+ hon[j] = 1", "- if hon[j]: # hon=1ならtesとの整合性を比較", "+ if hon[j]:", "- continue # 証言されていない部分は飛ばす", "+ continue", "+ ...
false
0.046848
0.045473
1.030228
[ "s411380876", "s874217483" ]
u875541136
p02771
python
s070431141
s270412188
25
17
3,444
2,940
Accepted
Accepted
32
import collections A = list(map(int, input().split())) if len(collections.Counter(A)) == 2: print('Yes') else: print('No')
A = list(map(int, input().split())) if len(set(A)) == 2: print('Yes') else: print('No')
5
4
128
92
import collections A = list(map(int, input().split())) if len(collections.Counter(A)) == 2: print("Yes") else: print("No")
A = list(map(int, input().split())) if len(set(A)) == 2: print("Yes") else: print("No")
false
20
[ "-import collections", "-", "-if len(collections.Counter(A)) == 2:", "+if len(set(A)) == 2:" ]
false
0.035326
0.039117
0.903074
[ "s070431141", "s270412188" ]
u372102441
p02701
python
s017571449
s730264327
110
93
38,900
35,580
Accepted
Accepted
15.45
import sys input = sys.stdin.readline #n = int(input()) #l = list(map(int, input().split())) ''' A=[] B=[] for i in range(): a, b = map(int, input().split()) A.append(a) B.append(b)''' import collections n= int(eval(input())) s=[] for i in range(n): s.append(input().rstrip()) ss=collections.Counter(s) print((len(ss)))
import sys input = sys.stdin.readline #n = int(input()) #l = list(map(int, input().split())) ''' A=[] B=[] for i in range(): a, b = map(int, input().split()) A.append(a) B.append(b)''' n=int(eval(input())) print((len(set([eval(input()) for i in range(n)]))))
21
14
350
270
import sys input = sys.stdin.readline # n = int(input()) # l = list(map(int, input().split())) """ A=[] B=[] for i in range(): a, b = map(int, input().split()) A.append(a) B.append(b)""" import collections n = int(eval(input())) s = [] for i in range(n): s.append(input().rstrip()) ss = collections.Counter(s) print((len(ss)))
import sys input = sys.stdin.readline # n = int(input()) # l = list(map(int, input().split())) """ A=[] B=[] for i in range(): a, b = map(int, input().split()) A.append(a) B.append(b)""" n = int(eval(input())) print((len(set([eval(input()) for i in range(n)]))))
false
33.333333
[ "-import collections", "-", "-s = []", "-for i in range(n):", "- s.append(input().rstrip())", "-ss = collections.Counter(s)", "-print((len(ss)))", "+print((len(set([eval(input()) for i in range(n)]))))" ]
false
0.046071
0.094301
0.488552
[ "s017571449", "s730264327" ]
u153665391
p02277
python
s663033625
s007460053
1,730
1,600
39,444
39,448
Accepted
Accepted
7.51
import copy def partition(p, r): i = p for j in range(p, r): if A[r][1] >= A[j][1]: A[i], A[j] = A[j], A[i] i += 1 A[r], A[i] = A[i], A[r] return i def quick_sort(p, r): if p < r: q = partition(p, r) quick_sort(p, q-1) quick_sort(q+1, r) def correct_same_num_suits(l, num, first, ele_cnt): suits = [] for i in range(first, N): if num == l[i][1]: suits.append(l[i][0]) if ele_cnt == len(suits): break return suits def is_stable(): idx = 0 while idx < N-1: idx_incr_flg = True if A[idx][1] == A[idx+1][1]: num = A[idx][1] j = idx ele_cnt = 0 while j < N and num == A[j][1]: ele_cnt += 1 j += 1 sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt) orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt) if sorted_suits != orig_suits: return False idx += len(sorted_suits) idx_incr_flg = False if idx_incr_flg: idx += 1 return True N = int(eval(input())) A = [] for _ in range(N): suit, num = input().split() num = int(num) A.append([suit, num]) orig_list = copy.deepcopy(A) quick_sort(0, N-1) is_stable = is_stable() if is_stable: print("Stable") else: print("Not stable") for card in A: print(("%s %d" % (card[0], card[1])))
import copy def partition(p, r): i = p for j in range(p, r): if A[r][1] >= A[j][1]: A[i], A[j] = A[j], A[i] i += 1 A[r], A[i] = A[i], A[r] return i def quick_sort(p, r): if p < r: q = partition(p, r) quick_sort(p, q-1) quick_sort(q+1, r) def correct_same_num_suits(l, num, first, ele_cnt): suits = [] append_cnt = 0 for i in range(first, N): if num == l[i][1]: suits.append(l[i][0]) append_cnt += 1 if ele_cnt == append_cnt: break return suits def is_stable(): idx = 0 while idx < N-1: idx_incr_flg = True if A[idx][1] == A[idx+1][1]: num = A[idx][1] j = idx ele_cnt = 0 while j < N and num == A[j][1]: ele_cnt += 1 j += 1 sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt) orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt) if sorted_suits != orig_suits: return False idx += len(sorted_suits) idx_incr_flg = False if idx_incr_flg: idx += 1 return True N = int(eval(input())) A = [] for _ in range(N): suit, num = input().split() num = int(num) A.append([suit, num]) orig_list = copy.deepcopy(A) quick_sort(0, N-1) is_stable = is_stable() if is_stable: print("Stable") else: print("Not stable") for card in A: print(("%s %d" % (card[0], card[1])))
66
68
1,561
1,610
import copy def partition(p, r): i = p for j in range(p, r): if A[r][1] >= A[j][1]: A[i], A[j] = A[j], A[i] i += 1 A[r], A[i] = A[i], A[r] return i def quick_sort(p, r): if p < r: q = partition(p, r) quick_sort(p, q - 1) quick_sort(q + 1, r) def correct_same_num_suits(l, num, first, ele_cnt): suits = [] for i in range(first, N): if num == l[i][1]: suits.append(l[i][0]) if ele_cnt == len(suits): break return suits def is_stable(): idx = 0 while idx < N - 1: idx_incr_flg = True if A[idx][1] == A[idx + 1][1]: num = A[idx][1] j = idx ele_cnt = 0 while j < N and num == A[j][1]: ele_cnt += 1 j += 1 sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt) orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt) if sorted_suits != orig_suits: return False idx += len(sorted_suits) idx_incr_flg = False if idx_incr_flg: idx += 1 return True N = int(eval(input())) A = [] for _ in range(N): suit, num = input().split() num = int(num) A.append([suit, num]) orig_list = copy.deepcopy(A) quick_sort(0, N - 1) is_stable = is_stable() if is_stable: print("Stable") else: print("Not stable") for card in A: print(("%s %d" % (card[0], card[1])))
import copy def partition(p, r): i = p for j in range(p, r): if A[r][1] >= A[j][1]: A[i], A[j] = A[j], A[i] i += 1 A[r], A[i] = A[i], A[r] return i def quick_sort(p, r): if p < r: q = partition(p, r) quick_sort(p, q - 1) quick_sort(q + 1, r) def correct_same_num_suits(l, num, first, ele_cnt): suits = [] append_cnt = 0 for i in range(first, N): if num == l[i][1]: suits.append(l[i][0]) append_cnt += 1 if ele_cnt == append_cnt: break return suits def is_stable(): idx = 0 while idx < N - 1: idx_incr_flg = True if A[idx][1] == A[idx + 1][1]: num = A[idx][1] j = idx ele_cnt = 0 while j < N and num == A[j][1]: ele_cnt += 1 j += 1 sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt) orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt) if sorted_suits != orig_suits: return False idx += len(sorted_suits) idx_incr_flg = False if idx_incr_flg: idx += 1 return True N = int(eval(input())) A = [] for _ in range(N): suit, num = input().split() num = int(num) A.append([suit, num]) orig_list = copy.deepcopy(A) quick_sort(0, N - 1) is_stable = is_stable() if is_stable: print("Stable") else: print("Not stable") for card in A: print(("%s %d" % (card[0], card[1])))
false
2.941176
[ "+ append_cnt = 0", "- if ele_cnt == len(suits):", "+ append_cnt += 1", "+ if ele_cnt == append_cnt:" ]
false
0.067222
0.178086
0.377472
[ "s663033625", "s007460053" ]
u488127128
p03607
python
s495358900
s166660679
207
95
11,884
19,172
Accepted
Accepted
54.11
n = int(eval(input())) A = set() for _ in range(n): a = int(eval(input())) if a in A: A.remove(a) else: A.add(a) print((len(A)))
import sys n,*A = sys.stdin B = set() for a in A: if int(a) in B: B.remove(int(a)) else: B.add(int(a)) print((len(B)))
9
9
150
148
n = int(eval(input())) A = set() for _ in range(n): a = int(eval(input())) if a in A: A.remove(a) else: A.add(a) print((len(A)))
import sys n, *A = sys.stdin B = set() for a in A: if int(a) in B: B.remove(int(a)) else: B.add(int(a)) print((len(B)))
false
0
[ "-n = int(eval(input()))", "-A = set()", "-for _ in range(n):", "- a = int(eval(input()))", "- if a in A:", "- A.remove(a)", "+import sys", "+", "+n, *A = sys.stdin", "+B = set()", "+for a in A:", "+ if int(a) in B:", "+ B.remove(int(a))", "- A.add(a)", "-pr...
false
0.037029
0.04267
0.86781
[ "s495358900", "s166660679" ]
u227020436
p03241
python
s518900150
s930883399
166
23
38,512
3,060
Accepted
Accepted
86.14
import math N, M = list(map(int, input().split())) def divisors(M): for d in range(1, math.floor(math.sqrt(M)) + 1): if M % d == 0: yield d yield M // d d = max(d for d in divisors(M) if d <= M // N) print(d)
import math N, M = list(map(int, input().split())) sqrtM = math.floor(math.sqrt(M)) maxd = min(sqrtM, M // N) d1 = max( d for d in range(1, maxd + 1) if M % d == 0) d2 = max((M // d for d in range(N, sqrtM + 1) if M % d == 0), default=1) print((max(d1, d2)))
12
10
252
270
import math N, M = list(map(int, input().split())) def divisors(M): for d in range(1, math.floor(math.sqrt(M)) + 1): if M % d == 0: yield d yield M // d d = max(d for d in divisors(M) if d <= M // N) print(d)
import math N, M = list(map(int, input().split())) sqrtM = math.floor(math.sqrt(M)) maxd = min(sqrtM, M // N) d1 = max(d for d in range(1, maxd + 1) if M % d == 0) d2 = max((M // d for d in range(N, sqrtM + 1) if M % d == 0), default=1) print((max(d1, d2)))
false
16.666667
[ "-", "-", "-def divisors(M):", "- for d in range(1, math.floor(math.sqrt(M)) + 1):", "- if M % d == 0:", "- yield d", "- yield M // d", "-", "-", "-d = max(d for d in divisors(M) if d <= M // N)", "-print(d)", "+sqrtM = math.floor(math.sqrt(M))", "+maxd = min(...
false
0.03837
0.113472
0.338147
[ "s518900150", "s930883399" ]
u347600233
p02712
python
s586663143
s892592867
103
95
34,432
9,128
Accepted
Accepted
7.77
# maspy 入力input() ver. import numpy as np n = int(eval(input())) x = np.arange(n + 1, dtype=np.int64) x[::3] = 0 x[::5] = 0 print((x.sum()))
n = int(eval(input())) print((sum(i for i in range(1, n + 1) if i % 3 and i % 5)))
7
2
138
75
# maspy 入力input() ver. import numpy as np n = int(eval(input())) x = np.arange(n + 1, dtype=np.int64) x[::3] = 0 x[::5] = 0 print((x.sum()))
n = int(eval(input())) print((sum(i for i in range(1, n + 1) if i % 3 and i % 5)))
false
71.428571
[ "-# maspy 入力input() ver.", "-import numpy as np", "-", "-x = np.arange(n + 1, dtype=np.int64)", "-x[::3] = 0", "-x[::5] = 0", "-print((x.sum()))", "+print((sum(i for i in range(1, n + 1) if i % 3 and i % 5)))" ]
false
0.335607
0.090028
3.727804
[ "s586663143", "s892592867" ]
u905203728
p03069
python
s026651618
s041801639
115
95
3,500
3,628
Accepted
Accepted
17.39
N=int(eval(input())) S=eval(input()) cnt=0 for s in S: if s!="#": cnt+=1 ans=cnt for s in S: if s==".": cnt-=1 else: cnt+=1 ans=min(ans,cnt) print(ans)
n=int(eval(input())) s=eval(input()) cnt=s.count(".") ans=cnt for i in s: if i==".":cnt -=1 else:cnt +=1 ans=min(ans,cnt) print(ans)
16
9
176
134
N = int(eval(input())) S = eval(input()) cnt = 0 for s in S: if s != "#": cnt += 1 ans = cnt for s in S: if s == ".": cnt -= 1 else: cnt += 1 ans = min(ans, cnt) print(ans)
n = int(eval(input())) s = eval(input()) cnt = s.count(".") ans = cnt for i in s: if i == ".": cnt -= 1 else: cnt += 1 ans = min(ans, cnt) print(ans)
false
43.75
[ "-N = int(eval(input()))", "-S = eval(input())", "-cnt = 0", "-for s in S:", "- if s != \"#\":", "- cnt += 1", "+n = int(eval(input()))", "+s = eval(input())", "+cnt = s.count(\".\")", "-for s in S:", "- if s == \".\":", "+for i in s:", "+ if i == \".\":" ]
false
0.04289
0.042199
1.01637
[ "s026651618", "s041801639" ]
u262646906
p02713
python
s698960900
s369296452
1,760
1,019
78,252
89,444
Accepted
Accepted
42.1
K = int(eval(input())) s = 0 cache = {} def gcd(a, b): key = (a, b) r = cache.get(key, None) if r: return r while b != 0: a, b = b, a % b cache[key] = a return a for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): a, b, c = tuple(sorted([i, j, k])) s += gcd(a, gcd(b, c)) print(s)
import array K = int(eval(input())) s = 0 cache = [1] * K def gcd(a, b): while b != 0: a, b = b, a % b return a for i in range(1, K+1): cache[i-1] = [1] * K for j in range(i, K+1): cache[i-1][j-1] = array.array('i', [1] * K) for k in range(j, K+1): cache[i-1][j-1][k-1] = gcd(k, gcd(j, i)) for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): a, b, c = sorted([i, j, k]) s += cache[a-1][b-1][c-1] print(s)
24
28
400
542
K = int(eval(input())) s = 0 cache = {} def gcd(a, b): key = (a, b) r = cache.get(key, None) if r: return r while b != 0: a, b = b, a % b cache[key] = a return a for i in range(1, K + 1): for j in range(1, K + 1): for k in range(1, K + 1): a, b, c = tuple(sorted([i, j, k])) s += gcd(a, gcd(b, c)) print(s)
import array K = int(eval(input())) s = 0 cache = [1] * K def gcd(a, b): while b != 0: a, b = b, a % b return a for i in range(1, K + 1): cache[i - 1] = [1] * K for j in range(i, K + 1): cache[i - 1][j - 1] = array.array("i", [1] * K) for k in range(j, K + 1): cache[i - 1][j - 1][k - 1] = gcd(k, gcd(j, i)) for i in range(1, K + 1): for j in range(1, K + 1): for k in range(1, K + 1): a, b, c = sorted([i, j, k]) s += cache[a - 1][b - 1][c - 1] print(s)
false
14.285714
[ "+import array", "+", "-cache = {}", "+cache = [1] * K", "- key = (a, b)", "- r = cache.get(key, None)", "- if r:", "- return r", "- cache[key] = a", "+ cache[i - 1] = [1] * K", "+ for j in range(i, K + 1):", "+ cache[i - 1][j - 1] = array.array(\"i\", [1] * K)"...
false
0.040026
0.059454
0.67322
[ "s698960900", "s369296452" ]
u729133443
p02791
python
s394052115
s843966289
134
91
17,808
17,020
Accepted
Accepted
32.09
_,p=open(0) m=9e9 c=0 for p in map(int,p.split()):c+=p<m;m=min(m,p) print(c)
_,p=open(0) m=9e9 c=0 for p in map(int,p.split()): if p<m:c+=1;m=p print(c)
5
6
80
81
_, p = open(0) m = 9e9 c = 0 for p in map(int, p.split()): c += p < m m = min(m, p) print(c)
_, p = open(0) m = 9e9 c = 0 for p in map(int, p.split()): if p < m: c += 1 m = p print(c)
false
16.666667
[ "- c += p < m", "- m = min(m, p)", "+ if p < m:", "+ c += 1", "+ m = p" ]
false
0.056767
0.037094
1.530349
[ "s394052115", "s843966289" ]
u945181840
p02788
python
s578988443
s172736334
859
701
54,100
49,364
Accepted
Accepted
18.39
import sys from bisect import bisect_right read = sys.stdin.read N, D, A, *XH = list(map(int, read().split())) X = XH[::2] + [-1] H = XH[1::2] + [-1] D *= 2 X, H = list(zip(*sorted(zip(X, H)))) damages = [0] * (N + 2) answer = 0 for i in range(1, N + 1): damages[i] += damages[i - 1] h = H[i] if damages[i] >= h: continue else: h -= damages[i] x = X[i] cnt = (h + A - 1) // A answer += cnt damage = A * cnt damages[i] += damage damages[bisect_right(X, x + D)] -= damage print(answer)
import sys from bisect import bisect_right from operator import itemgetter read = sys.stdin.read N, D, A, *XH = list(map(int, read().split())) XH = sorted(zip(*[iter(XH)] * 2), key=itemgetter(0)) D *= 2 X = [i for i, _ in XH] damages = [0] * (N + 2) answer = 0 for i, (x, h) in enumerate(XH, 1): damages[i] += damages[i - 1] if damages[i] >= h: continue h -= damages[i] cnt = (h + A - 1) // A answer += cnt damage = A * cnt damages[i] += damage damages[bisect_right(X, x + D) + 1] -= damage print(answer)
30
27
563
571
import sys from bisect import bisect_right read = sys.stdin.read N, D, A, *XH = list(map(int, read().split())) X = XH[::2] + [-1] H = XH[1::2] + [-1] D *= 2 X, H = list(zip(*sorted(zip(X, H)))) damages = [0] * (N + 2) answer = 0 for i in range(1, N + 1): damages[i] += damages[i - 1] h = H[i] if damages[i] >= h: continue else: h -= damages[i] x = X[i] cnt = (h + A - 1) // A answer += cnt damage = A * cnt damages[i] += damage damages[bisect_right(X, x + D)] -= damage print(answer)
import sys from bisect import bisect_right from operator import itemgetter read = sys.stdin.read N, D, A, *XH = list(map(int, read().split())) XH = sorted(zip(*[iter(XH)] * 2), key=itemgetter(0)) D *= 2 X = [i for i, _ in XH] damages = [0] * (N + 2) answer = 0 for i, (x, h) in enumerate(XH, 1): damages[i] += damages[i - 1] if damages[i] >= h: continue h -= damages[i] cnt = (h + A - 1) // A answer += cnt damage = A * cnt damages[i] += damage damages[bisect_right(X, x + D) + 1] -= damage print(answer)
false
10
[ "+from operator import itemgetter", "-X = XH[::2] + [-1]", "-H = XH[1::2] + [-1]", "+XH = sorted(zip(*[iter(XH)] * 2), key=itemgetter(0))", "-X, H = list(zip(*sorted(zip(X, H))))", "+X = [i for i, _ in XH]", "-for i in range(1, N + 1):", "+for i, (x, h) in enumerate(XH, 1):", "- h = H[i]", "- ...
false
0.037559
0.040338
0.931117
[ "s578988443", "s172736334" ]
u297574184
p03312
python
s037248862
s505592996
1,928
499
24,176
25,056
Accepted
Accepted
74.12
from itertools import accumulate from bisect import bisect_right N = int(eval(input())) As = list(map(int, input().split())) accAs = [0] + list(accumulate(As)) # As[iFr]~As[iTo]の和を求める def getSum(iFr, iTo): return accAs[iTo+1] - accAs[iFr] # As[iFr]~As[iTo]を前後半の総和の差が最小となるように分解する def getDivision(iFr, iTo): sumB = getSum(iFr, iTo) iMid = bisect_right(accAs, accAs[iFr]+sumB/2, iFr+1, iTo+2) - 1 diff1, diff2 = float('inf'), float('inf') if iMid != iFr: sum1L = getSum(iFr, iMid-1) sum1R = getSum(iMid, iTo) diff1 = abs(sum1L - sum1R) if iMid != iTo: sum2L = getSum(iFr, iMid) sum2R = getSum(iMid+1, iTo) diff2 = abs(sum2L - sum2R) return [sum1L, sum1R] if diff1 <= diff2 else [sum2L, sum2R] # 真ん中の区切りを全通り試す ans = float('inf') for iMid in range(1, N-3+1): sumD = [] sumD += getDivision(0, iMid) sumD += getDivision(iMid+1, N-1) ans = min(ans, max(sumD) - min(sumD)) print(ans)
N = int(eval(input())) As = list(map(int, input().split())) ans = float('inf') iB, iD = 1, 3 (P, Q, R), S = As[:3], sum(As[3:]) # 真ん中の区切りを全通り試す for iC in range(2, N - 1): while P < Q and As[iB] <= Q - P: P += As[iB] Q -= As[iB] iB += 1 while R < S and As[iD] <= S - R: R += As[iD] S -= As[iD] iD += 1 ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S)) Q += As[iC] R -= As[iC] print(ans)
41
25
1,012
478
from itertools import accumulate from bisect import bisect_right N = int(eval(input())) As = list(map(int, input().split())) accAs = [0] + list(accumulate(As)) # As[iFr]~As[iTo]の和を求める def getSum(iFr, iTo): return accAs[iTo + 1] - accAs[iFr] # As[iFr]~As[iTo]を前後半の総和の差が最小となるように分解する def getDivision(iFr, iTo): sumB = getSum(iFr, iTo) iMid = bisect_right(accAs, accAs[iFr] + sumB / 2, iFr + 1, iTo + 2) - 1 diff1, diff2 = float("inf"), float("inf") if iMid != iFr: sum1L = getSum(iFr, iMid - 1) sum1R = getSum(iMid, iTo) diff1 = abs(sum1L - sum1R) if iMid != iTo: sum2L = getSum(iFr, iMid) sum2R = getSum(iMid + 1, iTo) diff2 = abs(sum2L - sum2R) return [sum1L, sum1R] if diff1 <= diff2 else [sum2L, sum2R] # 真ん中の区切りを全通り試す ans = float("inf") for iMid in range(1, N - 3 + 1): sumD = [] sumD += getDivision(0, iMid) sumD += getDivision(iMid + 1, N - 1) ans = min(ans, max(sumD) - min(sumD)) print(ans)
N = int(eval(input())) As = list(map(int, input().split())) ans = float("inf") iB, iD = 1, 3 (P, Q, R), S = As[:3], sum(As[3:]) # 真ん中の区切りを全通り試す for iC in range(2, N - 1): while P < Q and As[iB] <= Q - P: P += As[iB] Q -= As[iB] iB += 1 while R < S and As[iD] <= S - R: R += As[iD] S -= As[iD] iD += 1 ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S)) Q += As[iC] R -= As[iC] print(ans)
false
39.02439
[ "-from itertools import accumulate", "-from bisect import bisect_right", "-", "-accAs = [0] + list(accumulate(As))", "-# As[iFr]~As[iTo]の和を求める", "-def getSum(iFr, iTo):", "- return accAs[iTo + 1] - accAs[iFr]", "-", "-", "-# As[iFr]~As[iTo]を前後半の総和の差が最小となるように分解する", "-def getDivision(iFr, iTo):...
false
0.089017
0.072325
1.230799
[ "s037248862", "s505592996" ]
u623814058
p02724
python
s018357866
s673192637
35
29
9,156
9,020
Accepted
Accepted
17.14
X = int(eval(input())) print(((X//500)*1000 + (X%500)//5*5))
X=int(eval(input())) print((X//500*1000+X%500//5*5))
2
2
53
45
X = int(eval(input())) print(((X // 500) * 1000 + (X % 500) // 5 * 5))
X = int(eval(input())) print((X // 500 * 1000 + X % 500 // 5 * 5))
false
0
[ "-print(((X // 500) * 1000 + (X % 500) // 5 * 5))", "+print((X // 500 * 1000 + X % 500 // 5 * 5))" ]
false
0.078488
0.043662
1.797629
[ "s018357866", "s673192637" ]
u287500079
p03476
python
s685818757
s674893769
1,173
494
7,248
75,436
Accepted
Accepted
57.89
q = int(eval(input())) primes = [True for _ in range(100000)] c = [0 for _ in range(100000)] for i in range(2, 100000): if primes[i]: for j in range(2*i, 100000, i): primes[j] = False #print(primes[:20]) for i in range(3, 100000, 2): if primes[i] and primes[(i+1)//2]: c[i] += 1 for i in range(3, 100000): c[i] += c[i-1] #print(c[:20]) for i in range(q): l, r = list(map(int,input().split())) print((c[r] - c[l-1]))
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10 from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def debug(*args): if debugmode: print((*args)) def input(): return sys.stdin.readline().strip() def STR(): return eval(input()) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 dx = [0, 0, 1, -1, 1, -1, -1, 1] dy = [1, -1, 0, 0, 1, -1, 1, -1] debugmode = True NN = 10 ** 5 + 100 primes = [] isprime = [True for _ in range(NN + 1)] min_factor = [-1 for _ in range(NN + 1)] #エラトステネスの篩 for i in range(2, NN + 1): if not isprime[i]: continue primes.append(i) min_factor[i] = i for j in range(i * 2, NN + 1, i): isprime[j] = False if min_factor[j] == -1: min_factor[j] = i primescnt = [0 for _ in range(NN + 1)] for i in range(3, NN + 1): primescnt[i] = primescnt[i - 1] + int(isprime[i] and isprime[(i + 1) // 2]) q = INT() for _ in range(q): l, r = MAP() print((primescnt[r] - primescnt[l - 1]))
22
48
476
1,615
q = int(eval(input())) primes = [True for _ in range(100000)] c = [0 for _ in range(100000)] for i in range(2, 100000): if primes[i]: for j in range(2 * i, 100000, i): primes[j] = False # print(primes[:20]) for i in range(3, 100000, 2): if primes[i] and primes[(i + 1) // 2]: c[i] += 1 for i in range(3, 100000): c[i] += c[i - 1] # print(c[:20]) for i in range(q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
import sys, re, os from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, ) from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def debug(*args): if debugmode: print((*args)) def input(): return sys.stdin.readline().strip() def STR(): return eval(input()) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10**9) inf = sys.maxsize mod = 10**9 + 7 dx = [0, 0, 1, -1, 1, -1, -1, 1] dy = [1, -1, 0, 0, 1, -1, 1, -1] debugmode = True NN = 10**5 + 100 primes = [] isprime = [True for _ in range(NN + 1)] min_factor = [-1 for _ in range(NN + 1)] # エラトステネスの篩 for i in range(2, NN + 1): if not isprime[i]: continue primes.append(i) min_factor[i] = i for j in range(i * 2, NN + 1, i): isprime[j] = False if min_factor[j] == -1: min_factor[j] = i primescnt = [0 for _ in range(NN + 1)] for i in range(3, NN + 1): primescnt[i] = primescnt[i - 1] + int(isprime[i] and isprime[(i + 1) // 2]) q = INT() for _ in range(q): l, r = MAP() print((primescnt[r] - primescnt[l - 1]))
false
54.166667
[ "-q = int(eval(input()))", "-primes = [True for _ in range(100000)]", "-c = [0 for _ in range(100000)]", "-for i in range(2, 100000):", "- if primes[i]:", "- for j in range(2 * i, 100000, i):", "- primes[j] = False", "-# print(primes[:20])", "-for i in range(3, 100000, 2):", "...
false
0.138718
0.252508
0.549359
[ "s685818757", "s674893769" ]
u936988827
p02554
python
s100943067
s772645325
392
26
10,960
9,144
Accepted
Accepted
93.37
n = int(eval(input())) mod = 10**9+7 ans = pow(10,n) ans -= pow(9,n)*2 ans += pow(8,n) print((ans%mod))
n = int(eval(input())) mod = 10**9+7 ans = pow(10,n,mod) ans -= pow(9,n,mod)*2 ans += pow(8,n,mod) print((ans%mod))
8
8
105
117
n = int(eval(input())) mod = 10**9 + 7 ans = pow(10, n) ans -= pow(9, n) * 2 ans += pow(8, n) print((ans % mod))
n = int(eval(input())) mod = 10**9 + 7 ans = pow(10, n, mod) ans -= pow(9, n, mod) * 2 ans += pow(8, n, mod) print((ans % mod))
false
0
[ "-ans = pow(10, n)", "-ans -= pow(9, n) * 2", "-ans += pow(8, n)", "+ans = pow(10, n, mod)", "+ans -= pow(9, n, mod) * 2", "+ans += pow(8, n, mod)" ]
false
0.292636
0.036268
8.068612
[ "s100943067", "s772645325" ]
u017415492
p02833
python
s569074410
s050042780
25
17
3,064
2,940
Accepted
Accepted
32
n=int(eval(input())) if n%2!=0: print((0)) else: a=0 for i in range(1,26): a+=(n//(2*5**i)) print(a)
n=int(eval(input())) ans=0 if n%2==1: print((0)) else: n=n//2 for i in range(1,50): ans+=(n//(5**i)) print((int(ans)))
8
9
111
128
n = int(eval(input())) if n % 2 != 0: print((0)) else: a = 0 for i in range(1, 26): a += n // (2 * 5**i) print(a)
n = int(eval(input())) ans = 0 if n % 2 == 1: print((0)) else: n = n // 2 for i in range(1, 50): ans += n // (5**i) print((int(ans)))
false
11.111111
[ "-if n % 2 != 0:", "+ans = 0", "+if n % 2 == 1:", "- a = 0", "- for i in range(1, 26):", "- a += n // (2 * 5**i)", "- print(a)", "+ n = n // 2", "+ for i in range(1, 50):", "+ ans += n // (5**i)", "+ print((int(ans)))" ]
false
0.032624
0.041717
0.782037
[ "s569074410", "s050042780" ]
u995004106
p02659
python
s129606998
s609825036
333
129
77,080
72,576
Accepted
Accepted
61.26
import math import pprint import fractions import collections import itertools from decimal import * A,B=list(map(str,input().split())) #print(A*B) getcontext().prec=40 A=int(A) #print(Decimal(A)*Decimal(B)) A=str(A) A=list(map(int,A)) b=list(str(B)) B=[0]*3 #print(A,b) N=len(A) #Aの桁数 table=[[0 for _ in range(len(A)+1)] for _ in range(10)] for i in range(1,10): career=0 for j in range(N,0,-1): buf=A[j-1]*i+career career=buf//10 table[i][j]=buf%10 table[i][0]=career #print(table) A=list(A) A.insert(0,0) A.insert(len(A),0) A.insert(len(A),0) #print(A) ans=[0]*(len(A)) B=[int(b[0]),int(b[2]),int(b[3])] #print(B) #print(ans) for i in range(2,-1,-1): piv=B[i] buf=[] buf = table[piv] #print(buf) career=0 for j in range(N,-1,-1): num=ans[j+i]+buf[j]+career career=num//10 ans[j+i]=num%10 #print(ans) #input() ans=list(map(str,ans)) s="".join(ans) print((int(s[:len(s)-2])))
import math import pprint import fractions import collections import itertools from decimal import * A,B=list(map(str,input().split())) A=int(A) B=str(B) num=int(B[0])*100+int(B[2])*10+int(B[3]) #print(A,num) print(((A*num)//100))
56
12
1,031
234
import math import pprint import fractions import collections import itertools from decimal import * A, B = list(map(str, input().split())) # print(A*B) getcontext().prec = 40 A = int(A) # print(Decimal(A)*Decimal(B)) A = str(A) A = list(map(int, A)) b = list(str(B)) B = [0] * 3 # print(A,b) N = len(A) # Aの桁数 table = [[0 for _ in range(len(A) + 1)] for _ in range(10)] for i in range(1, 10): career = 0 for j in range(N, 0, -1): buf = A[j - 1] * i + career career = buf // 10 table[i][j] = buf % 10 table[i][0] = career # print(table) A = list(A) A.insert(0, 0) A.insert(len(A), 0) A.insert(len(A), 0) # print(A) ans = [0] * (len(A)) B = [int(b[0]), int(b[2]), int(b[3])] # print(B) # print(ans) for i in range(2, -1, -1): piv = B[i] buf = [] buf = table[piv] # print(buf) career = 0 for j in range(N, -1, -1): num = ans[j + i] + buf[j] + career career = num // 10 ans[j + i] = num % 10 # print(ans) # input() ans = list(map(str, ans)) s = "".join(ans) print((int(s[: len(s) - 2])))
import math import pprint import fractions import collections import itertools from decimal import * A, B = list(map(str, input().split())) A = int(A) B = str(B) num = int(B[0]) * 100 + int(B[2]) * 10 + int(B[3]) # print(A,num) print(((A * num) // 100))
false
78.571429
[ "-# print(A*B)", "-getcontext().prec = 40", "-# print(Decimal(A)*Decimal(B))", "-A = str(A)", "-A = list(map(int, A))", "-b = list(str(B))", "-B = [0] * 3", "-# print(A,b)", "-N = len(A) # Aの桁数", "-table = [[0 for _ in range(len(A) + 1)] for _ in range(10)]", "-for i in range(1, 10):", "- ...
false
0.047156
0.036931
1.276858
[ "s129606998", "s609825036" ]
u667135132
p02793
python
s010136263
s110355763
1,505
357
71,396
42,992
Accepted
Accepted
76.28
from fractions import gcd import sys input = sys.stdin.readline def pow_mod(x,n): if n==0: return 1 K = 1 while n>1: if n%2 != 0: K *= x K %= mod x *= x x %= mod n //= 2 return K*x mod=10**9+7 N = int(eval(input())) A = list(map(int,input().split())) if N==1: print((1)) exit() Gcd = gcd(A[0],A[1]) ans = (A[0]//Gcd+A[1]//Gcd)%mod temp = A[0]//Gcd for i in range(1,N-1): #Gcd = lcm(A[i],A[i+1]) Gcd = gcd(A[i],A[i+1]) #temp2 = Gcd//A[i] temp2 = A[i+1]//Gcd #Gcd2 = lcm(temp,temp2) Gcd2 = gcd(temp,temp2) #a = Gcd2//temp a = temp2//Gcd2 #b = Gcd2//temp2 b = temp//Gcd2 temp = A[i]//Gcd*b a %= mod b %= mod ans *= a ans %= mod Gcd %= mod #注意 c = A[i] c %= mod d = c*pow_mod(Gcd,mod-2) #d = Gcd//c d %= mod e = b*d%mod ans += e #ans += Gcd//A[i+1]*b ans %= mod print(ans)
import sys input = sys.stdin.readline #main関数 def main(): """"ここに今までのコード""" N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9+7 plist = [0]*1000 lcm = 1 nokori=set() for a in A: for j in range(2, 1001): count_j=0 while a % j == 0: count_j += 1 a //= j plist[j-1]=max(plist[j-1],count_j) nokori |= {a} for x in nokori: lcm *= x lcm %= mod #print(plist) #print(lcm) for i in range(1000): lcm *= pow(i+1, plist[i], mod) lcm %= mod #print(lcm) ans = 0 for a in A: ans += lcm * pow(a, mod-2, mod) ans %= mod print(ans) if __name__ == '__main__': main()
69
46
1,040
823
from fractions import gcd import sys input = sys.stdin.readline def pow_mod(x, n): if n == 0: return 1 K = 1 while n > 1: if n % 2 != 0: K *= x K %= mod x *= x x %= mod n //= 2 return K * x mod = 10**9 + 7 N = int(eval(input())) A = list(map(int, input().split())) if N == 1: print((1)) exit() Gcd = gcd(A[0], A[1]) ans = (A[0] // Gcd + A[1] // Gcd) % mod temp = A[0] // Gcd for i in range(1, N - 1): # Gcd = lcm(A[i],A[i+1]) Gcd = gcd(A[i], A[i + 1]) # temp2 = Gcd//A[i] temp2 = A[i + 1] // Gcd # Gcd2 = lcm(temp,temp2) Gcd2 = gcd(temp, temp2) # a = Gcd2//temp a = temp2 // Gcd2 # b = Gcd2//temp2 b = temp // Gcd2 temp = A[i] // Gcd * b a %= mod b %= mod ans *= a ans %= mod Gcd %= mod # 注意 c = A[i] c %= mod d = c * pow_mod(Gcd, mod - 2) # d = Gcd//c d %= mod e = b * d % mod ans += e # ans += Gcd//A[i+1]*b ans %= mod print(ans)
import sys input = sys.stdin.readline # main関数 def main(): """ "ここに今までのコード""" N = int(eval(input())) A = list(map(int, input().split())) mod = 10**9 + 7 plist = [0] * 1000 lcm = 1 nokori = set() for a in A: for j in range(2, 1001): count_j = 0 while a % j == 0: count_j += 1 a //= j plist[j - 1] = max(plist[j - 1], count_j) nokori |= {a} for x in nokori: lcm *= x lcm %= mod # print(plist) # print(lcm) for i in range(1000): lcm *= pow(i + 1, plist[i], mod) lcm %= mod # print(lcm) ans = 0 for a in A: ans += lcm * pow(a, mod - 2, mod) ans %= mod print(ans) if __name__ == "__main__": main()
false
33.333333
[ "-from fractions import gcd", "+# main関数", "+def main():", "+ \"\"\" \"ここに今までのコード\"\"\"", "+ N = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ mod = 10**9 + 7", "+ plist = [0] * 1000", "+ lcm = 1", "+ nokori = set()", "+ for a in A:", "+ for j ...
false
0.050796
0.11588
0.438347
[ "s010136263", "s110355763" ]
u441064181
p03326
python
s097901331
s869720786
164
32
12,316
3,360
Accepted
Accepted
80.49
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys from operator import itemgetter def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N, M = LI() A = [LI() for _ in range(N)] m = [[0] * 3 for _ in range(8)] for c in range(4): A.sort(key=lambda x:(((c>>2)&1)*2-1)*x[0]+(((c>>1)&1)*2-1)*(-1)*x[1]+((c&1)*2-1)*x[2]) for i in range(M): for j in range(3): m[c*2][j] += A[i][j] m[c*2+1][j] += A[N-1-i][j] print((max([abs(x[0])+abs(x[1])+abs(x[2]) for x in m])))
#import bisect,collections,copy,heapq,itertools,math,numpy,string #from operator import itemgetter import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N, M = LI() A = [LI() for _ in range(N)] m = [[0] * 3 for _ in range(8)] for c in range(4): A.sort(key=lambda x:(((c>>2)&1)*2-1)*x[0]+(((c>>1)&1)*2-1)*(-1)*x[1]+((c&1)*2-1)*x[2]) for i in range(M): for j in range(3): m[c*2][j] += A[i][j] m[c*2+1][j] += A[N-1-i][j] print((max([abs(x[0])+abs(x[1])+abs(x[2]) for x in m])))
19
19
691
693
import bisect, collections, copy, heapq, itertools, math, numpy, string import sys from operator import itemgetter def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N, M = LI() A = [LI() for _ in range(N)] m = [[0] * 3 for _ in range(8)] for c in range(4): A.sort( key=lambda x: (((c >> 2) & 1) * 2 - 1) * x[0] + (((c >> 1) & 1) * 2 - 1) * (-1) * x[1] + ((c & 1) * 2 - 1) * x[2] ) for i in range(M): for j in range(3): m[c * 2][j] += A[i][j] m[c * 2 + 1][j] += A[N - 1 - i][j] print((max([abs(x[0]) + abs(x[1]) + abs(x[2]) for x in m])))
# import bisect,collections,copy,heapq,itertools,math,numpy,string # from operator import itemgetter import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) N, M = LI() A = [LI() for _ in range(N)] m = [[0] * 3 for _ in range(8)] for c in range(4): A.sort( key=lambda x: (((c >> 2) & 1) * 2 - 1) * x[0] + (((c >> 1) & 1) * 2 - 1) * (-1) * x[1] + ((c & 1) * 2 - 1) * x[2] ) for i in range(M): for j in range(3): m[c * 2][j] += A[i][j] m[c * 2 + 1][j] += A[N - 1 - i][j] print((max([abs(x[0]) + abs(x[1]) + abs(x[2]) for x in m])))
false
0
[ "-import bisect, collections, copy, heapq, itertools, math, numpy, string", "+# import bisect,collections,copy,heapq,itertools,math,numpy,string", "+# from operator import itemgetter", "-from operator import itemgetter" ]
false
0.04372
0.037942
1.152293
[ "s097901331", "s869720786" ]
u421674761
p02681
python
s168347536
s685619676
31
26
9,052
8,976
Accepted
Accepted
16.13
s = eval(input()) t = eval(input()) if s == t[:-1]: print('Yes') else: print('No')
s = eval(input()) t = eval(input()) if t[:-1] == s: print('Yes') else: print('No')
7
7
86
86
s = eval(input()) t = eval(input()) if s == t[:-1]: print("Yes") else: print("No")
s = eval(input()) t = eval(input()) if t[:-1] == s: print("Yes") else: print("No")
false
0
[ "-if s == t[:-1]:", "+if t[:-1] == s:" ]
false
0.065957
0.065412
1.008336
[ "s168347536", "s685619676" ]
u852690916
p03837
python
s498393071
s702292060
343
230
54,748
41,964
Accepted
Accepted
32.94
N,M=list(map(int, input().split())) E=[[] for _ in range(N)] for i in range(M): a,b,c=list(map(int, input().split())) E[a-1].append((b-1,c,i)) E[b-1].append((a-1,c,i)) ans=[1]*M import heapq def dijkstra(s): distance=[-1]*N parent_n=[-1]*N parent_e=[-1]*N distance[s]=0 parent_n[s]=s q=[(0,s)] while q: nc,n=heapq.heappop(q) for to,c,eid in E[n]: if distance[to]<0 or nc+c<distance[to]: distance[to]=nc+c parent_n[to]=n parent_e[to]=eid heapq.heappush(q,(nc+c,to)) checked=[False]*N checked[s]=True for i in range(N): if checked[i]: continue n=i while n!=s: checked[n]=True ans[parent_e[n]]=0 n=parent_n[n] for i in range(N): dijkstra(i) print((sum(ans)))
N,M=list(map(int, input().split())) E=[] for i in range(M): a,b,c=list(map(int, input().split())) E.append((a-1,b-1,c)) INF=1<<60 D=[[INF]*N for _ in range(N)] for a,b,c in E: D[a][b]=D[b][a]=c for z in range(N): for x in range(N): Dx=D[x] for y in range(N): Dx[y]=min(Dx[y], Dx[z]+D[z][y]) ans=M for a,b,c in E: if D[a][b]==c: ans-=1 print(ans)
37
20
884
403
N, M = list(map(int, input().split())) E = [[] for _ in range(N)] for i in range(M): a, b, c = list(map(int, input().split())) E[a - 1].append((b - 1, c, i)) E[b - 1].append((a - 1, c, i)) ans = [1] * M import heapq def dijkstra(s): distance = [-1] * N parent_n = [-1] * N parent_e = [-1] * N distance[s] = 0 parent_n[s] = s q = [(0, s)] while q: nc, n = heapq.heappop(q) for to, c, eid in E[n]: if distance[to] < 0 or nc + c < distance[to]: distance[to] = nc + c parent_n[to] = n parent_e[to] = eid heapq.heappush(q, (nc + c, to)) checked = [False] * N checked[s] = True for i in range(N): if checked[i]: continue n = i while n != s: checked[n] = True ans[parent_e[n]] = 0 n = parent_n[n] for i in range(N): dijkstra(i) print((sum(ans)))
N, M = list(map(int, input().split())) E = [] for i in range(M): a, b, c = list(map(int, input().split())) E.append((a - 1, b - 1, c)) INF = 1 << 60 D = [[INF] * N for _ in range(N)] for a, b, c in E: D[a][b] = D[b][a] = c for z in range(N): for x in range(N): Dx = D[x] for y in range(N): Dx[y] = min(Dx[y], Dx[z] + D[z][y]) ans = M for a, b, c in E: if D[a][b] == c: ans -= 1 print(ans)
false
45.945946
[ "-E = [[] for _ in range(N)]", "+E = []", "- E[a - 1].append((b - 1, c, i))", "- E[b - 1].append((a - 1, c, i))", "-ans = [1] * M", "-import heapq", "-", "-", "-def dijkstra(s):", "- distance = [-1] * N", "- parent_n = [-1] * N", "- parent_e = [-1] * N", "- distance[s] = 0"...
false
0.047408
0.046699
1.015193
[ "s498393071", "s702292060" ]
u357751375
p02982
python
s814728907
s315131703
29
26
9,144
9,192
Accepted
Accepted
10.34
n,d = list(map(int,input().split())) x = [list(map(int,input().split())) for i in range(n)] l = [] o = [] for i in range(n): for j in range(i+1,n): t = 0 for k in range(d): t += abs(x[i][k] - x[j][k]) ** 2 l.append(t) l.sort() i = 1 while i ** 2 <= l[-1]: o.append(i ** 2) i += 1 p = 0 for i in range(len(o)): p += l.count(o[i]) print(p)
from math import sqrt n,d = list(map(int,input().split())) x = [list(map(int,input().split())) for i in range(n)] ans = 0 for i in range(n): for j in range(i+1,n): t = 0 for k in range(d): t += (x[i][k] - x[j][k]) ** 2 if float.is_integer(sqrt(t)): ans += 1 print(ans)
23
12
409
325
n, d = list(map(int, input().split())) x = [list(map(int, input().split())) for i in range(n)] l = [] o = [] for i in range(n): for j in range(i + 1, n): t = 0 for k in range(d): t += abs(x[i][k] - x[j][k]) ** 2 l.append(t) l.sort() i = 1 while i**2 <= l[-1]: o.append(i**2) i += 1 p = 0 for i in range(len(o)): p += l.count(o[i]) print(p)
from math import sqrt n, d = list(map(int, input().split())) x = [list(map(int, input().split())) for i in range(n)] ans = 0 for i in range(n): for j in range(i + 1, n): t = 0 for k in range(d): t += (x[i][k] - x[j][k]) ** 2 if float.is_integer(sqrt(t)): ans += 1 print(ans)
false
47.826087
[ "+from math import sqrt", "+", "-l = []", "-o = []", "+ans = 0", "- t += abs(x[i][k] - x[j][k]) ** 2", "- l.append(t)", "-l.sort()", "-i = 1", "-while i**2 <= l[-1]:", "- o.append(i**2)", "- i += 1", "-p = 0", "-for i in range(len(o)):", "- p += l.count(o[i])",...
false
0.09136
0.038225
2.390076
[ "s814728907", "s315131703" ]
u905203728
p02844
python
s454200406
s532168576
517
220
41,180
38,508
Accepted
Accepted
57.45
n=int(eval(input())) s=eval(input()) cnt=0 for i in range(1000): num=str(i).zfill(3) add=0 for j in s: if num[add]==j:add +=1 if add==3: cnt +=1 break print(cnt)
n=int(eval(input())) s=eval(input()) cnt=0 for i in range(1000): num=str(i).zfill(3) x=s.find(num[0]) y=s.find(num[1],x+1) z=s.find(num[2],y+1) if x!=-1 and y!=-1 and z!=-1: cnt +=1 print(cnt)
13
13
214
222
n = int(eval(input())) s = eval(input()) cnt = 0 for i in range(1000): num = str(i).zfill(3) add = 0 for j in s: if num[add] == j: add += 1 if add == 3: cnt += 1 break print(cnt)
n = int(eval(input())) s = eval(input()) cnt = 0 for i in range(1000): num = str(i).zfill(3) x = s.find(num[0]) y = s.find(num[1], x + 1) z = s.find(num[2], y + 1) if x != -1 and y != -1 and z != -1: cnt += 1 print(cnt)
false
0
[ "- add = 0", "- for j in s:", "- if num[add] == j:", "- add += 1", "- if add == 3:", "- cnt += 1", "- break", "+ x = s.find(num[0])", "+ y = s.find(num[1], x + 1)", "+ z = s.find(num[2], y + 1)", "+ if x != -1 and y != -1 and z != ...
false
0.09292
0.113713
0.817139
[ "s454200406", "s532168576" ]
u906428167
p03682
python
s765540655
s176343115
1,509
1,158
123,224
112,348
Accepted
Accepted
23.26
from heapq import heappop,heappush n = int(eval(input())) p = [] for i in range(n): x,y = list(map(int,input().split())) p.append((i,x,y)) e = [[] for _ in range(n)] p = sorted(p,key=lambda x:x[1]) n0,x0,y0 = p[0] for i in range(n-1): n1,x1,y1 = p[i+1] e[n0].append((min(abs(x1-x0),abs(y1-y0)),n1)) e[n1].append((min(abs(x1-x0),abs(y1-y0)),n0)) n0,x0,y0 = n1,x1,y1 p = sorted(p,key=lambda x:x[2]) n0,x0,y0 = p[0] for i in range(n-1): n1,x1,y1 = p[i+1] e[n0].append((min(abs(x1-x0),abs(y1-y0)),n1)) e[n1].append((min(abs(x1-x0),abs(y1-y0)),n0)) n0,x0,y0 = n1,x1,y1 def Prim(n,edge): #edge[source] = [(cost_1,target_1),(cost_2,target_2),...] used = [False] * n q = [] #e = [cost,target] for e in edge[0]: heappush(q,e) used[0] = True res = 0 while q: c,v = heappop(q) if used[v]: continue used[v] = True for e in edge[v]: if not used[e[1]]: heappush(q,e) res += c return res print((Prim(n,e)))
import sys input = sys.stdin.readline from heapq import heappop,heappush n = int(eval(input())) p = [] for i in range(n): x,y = list(map(int,input().split())) p.append((i,x,y)) e = [[] for _ in range(n)] p = sorted(p,key=lambda x:x[1]) n0,x0,y0 = p[0] for i in range(n-1): n1,x1,y1 = p[i+1] e[n0].append((min(abs(x1-x0),abs(y1-y0)),n1)) e[n1].append((min(abs(x1-x0),abs(y1-y0)),n0)) n0,x0,y0 = n1,x1,y1 p = sorted(p,key=lambda x:x[2]) n0,x0,y0 = p[0] for i in range(n-1): n1,x1,y1 = p[i+1] e[n0].append((min(abs(x1-x0),abs(y1-y0)),n1)) e[n1].append((min(abs(x1-x0),abs(y1-y0)),n0)) n0,x0,y0 = n1,x1,y1 def Prim(n,edge): #edge[source] = [(cost_1,target_1),(cost_2,target_2),...] used = [False] * n q = [] #e = [cost,target] for e in edge[0]: heappush(q,e) used[0] = True res = 0 while q: c,v = heappop(q) if used[v]: continue used[v] = True for e in edge[v]: if not used[e[1]]: heappush(q,e) res += c return res print((Prim(n,e)))
47
50
1,093
1,135
from heapq import heappop, heappush n = int(eval(input())) p = [] for i in range(n): x, y = list(map(int, input().split())) p.append((i, x, y)) e = [[] for _ in range(n)] p = sorted(p, key=lambda x: x[1]) n0, x0, y0 = p[0] for i in range(n - 1): n1, x1, y1 = p[i + 1] e[n0].append((min(abs(x1 - x0), abs(y1 - y0)), n1)) e[n1].append((min(abs(x1 - x0), abs(y1 - y0)), n0)) n0, x0, y0 = n1, x1, y1 p = sorted(p, key=lambda x: x[2]) n0, x0, y0 = p[0] for i in range(n - 1): n1, x1, y1 = p[i + 1] e[n0].append((min(abs(x1 - x0), abs(y1 - y0)), n1)) e[n1].append((min(abs(x1 - x0), abs(y1 - y0)), n0)) n0, x0, y0 = n1, x1, y1 def Prim(n, edge): # edge[source] = [(cost_1,target_1),(cost_2,target_2),...] used = [False] * n q = [] # e = [cost,target] for e in edge[0]: heappush(q, e) used[0] = True res = 0 while q: c, v = heappop(q) if used[v]: continue used[v] = True for e in edge[v]: if not used[e[1]]: heappush(q, e) res += c return res print((Prim(n, e)))
import sys input = sys.stdin.readline from heapq import heappop, heappush n = int(eval(input())) p = [] for i in range(n): x, y = list(map(int, input().split())) p.append((i, x, y)) e = [[] for _ in range(n)] p = sorted(p, key=lambda x: x[1]) n0, x0, y0 = p[0] for i in range(n - 1): n1, x1, y1 = p[i + 1] e[n0].append((min(abs(x1 - x0), abs(y1 - y0)), n1)) e[n1].append((min(abs(x1 - x0), abs(y1 - y0)), n0)) n0, x0, y0 = n1, x1, y1 p = sorted(p, key=lambda x: x[2]) n0, x0, y0 = p[0] for i in range(n - 1): n1, x1, y1 = p[i + 1] e[n0].append((min(abs(x1 - x0), abs(y1 - y0)), n1)) e[n1].append((min(abs(x1 - x0), abs(y1 - y0)), n0)) n0, x0, y0 = n1, x1, y1 def Prim(n, edge): # edge[source] = [(cost_1,target_1),(cost_2,target_2),...] used = [False] * n q = [] # e = [cost,target] for e in edge[0]: heappush(q, e) used[0] = True res = 0 while q: c, v = heappop(q) if used[v]: continue used[v] = True for e in edge[v]: if not used[e[1]]: heappush(q, e) res += c return res print((Prim(n, e)))
false
6
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.231265
0.08388
2.7571
[ "s765540655", "s176343115" ]
u428012835
p03567
python
s618660588
s802162407
23
18
3,188
2,940
Accepted
Accepted
21.74
import re n = eval(input()) if re.search("AC", n): print("Yes") else: print("No")
n = eval(input()) if "AC" in n: print("Yes") else: print("No")
6
5
89
69
import re n = eval(input()) if re.search("AC", n): print("Yes") else: print("No")
n = eval(input()) if "AC" in n: print("Yes") else: print("No")
false
16.666667
[ "-import re", "-", "-if re.search(\"AC\", n):", "+if \"AC\" in n:" ]
false
0.0379
0.036866
1.028038
[ "s618660588", "s802162407" ]
u562935282
p03007
python
s239484016
s348966444
374
243
63,500
20,192
Accepted
Accepted
35.03
from bisect import bisect_left N = int(eval(input())) a = tuple(sorted(map(int, input().split()))) cnt = bisect_left(a, 0) # 正の開始点==負の個数 if cnt <= 1: print((sum(a) - 2 * a[0])) t = a[0] for i in range(1, N - 1): print((t, a[i])) t -= a[i] print((a[-1], t)) else: # cnt-1個は正最大に連結 if cnt == N: print((sum(map(abs, a)) + 2 * a[-1])) t = a[-1] for i in range(N - 1): print((t, a[i])) t -= a[i] else: print((sum(map(abs, a)))) t = a[-1] for i in range(cnt - 1): print((t, a[i])) t -= a[i] s = a[cnt - 1] for i in range(cnt, N - 1): print((s, a[i])) s -= a[i] print((t, s))
N = int(eval(input())) a = tuple(sorted(map(int, input().split()))) ans = [] res = 0 m = a[0] # 最後に引く側 p = a[-1] # 最後に足す側 for aa in a[1:N - 1]: if aa < 0: res -= aa ans.append((p, aa)) p -= aa else: res += aa ans.append((m, aa)) m -= aa ans.append((p, m)) res += a[-1] - a[0] print(res) for aa in ans: print((*aa))
35
22
772
392
from bisect import bisect_left N = int(eval(input())) a = tuple(sorted(map(int, input().split()))) cnt = bisect_left(a, 0) # 正の開始点==負の個数 if cnt <= 1: print((sum(a) - 2 * a[0])) t = a[0] for i in range(1, N - 1): print((t, a[i])) t -= a[i] print((a[-1], t)) else: # cnt-1個は正最大に連結 if cnt == N: print((sum(map(abs, a)) + 2 * a[-1])) t = a[-1] for i in range(N - 1): print((t, a[i])) t -= a[i] else: print((sum(map(abs, a)))) t = a[-1] for i in range(cnt - 1): print((t, a[i])) t -= a[i] s = a[cnt - 1] for i in range(cnt, N - 1): print((s, a[i])) s -= a[i] print((t, s))
N = int(eval(input())) a = tuple(sorted(map(int, input().split()))) ans = [] res = 0 m = a[0] # 最後に引く側 p = a[-1] # 最後に足す側 for aa in a[1 : N - 1]: if aa < 0: res -= aa ans.append((p, aa)) p -= aa else: res += aa ans.append((m, aa)) m -= aa ans.append((p, m)) res += a[-1] - a[0] print(res) for aa in ans: print((*aa))
false
37.142857
[ "-from bisect import bisect_left", "-", "-cnt = bisect_left(a, 0) # 正の開始点==負の個数", "-if cnt <= 1:", "- print((sum(a) - 2 * a[0]))", "- t = a[0]", "- for i in range(1, N - 1):", "- print((t, a[i]))", "- t -= a[i]", "- print((a[-1], t))", "-else:", "- # cnt-1個は正最大に連結...
false
0.092241
0.086366
1.06802
[ "s239484016", "s348966444" ]