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
sequence
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
sequence
u995004106
p02696
python
s232705104
s058563539
397
132
73,144
72,728
Accepted
Accepted
66.75
from math import floor,ceil import fractions import collections import itertools from collections import deque A,B,N=list(map(int,input().split())) piv=B/A #基本数 #for i in range(0,30): # print(A,i,B,floor(A*i/B)-A*floor(i/B)) #A<=Bなら #0,0,.. 1,1,.. ... (A-1),(A-1),...が #先頭から(B%A)の数字まではceil(piv)こ、あとはfloor(piv)こ cnt=0 #print(ceil(piv)*(B%A)) if A<=B: if N>=B-1: print((A-1)) else: if ceil(piv)*(B%A)>N: print((floor(N/ceil(piv)))) else: N=N-ceil(piv)*(B%A) #print(N,N//floor(piv)) cnt=(B%A) print((cnt+N//floor(piv))) else: #A>B l=[0] for i in range(1,B): l.append(max(l[i-1],floor(A*i/B)-A*floor(i/B))) #print(l) if N>=len(l): print((l[len(l)-1])) else: print((l[N]))
from math import floor,ceil import fractions import collections import itertools from collections import deque A,B,N=list(map(int,input().split())) piv=B/A #基本数 #for i in range(0,30): # print(A,i,B,floor(A*i/B)-A*floor(i/B)) #A<=Bなら #0,0,.. 1,1,.. ... (A-1),(A-1),...が #先頭から(B%A)の数字まではceil(piv)こ、あとはfloor(piv)こ #→これより、この答えはmod(B)の空間で単調増加とわかる #よって、f(min(B-1,N))が答え #A>Bでも同じくmod(B)にて単調増加なのを調べてたはずなので #いずれにせよf(min(B-1,N))が答え cnt=0 #print(ceil(piv)*(B%A)) """ if A<=B: if N>=B-1: print(A-1) else: if ceil(piv)*(B%A)>N: print(floor(N/ceil(piv))) else: N=N-ceil(piv)*(B%A) #print(N,N//floor(piv)) cnt=(B%A) print(cnt+N//floor(piv)) else: #A>B l=[0] for i in range(1,B): l.append(max(l[i-1],floor(A*i/B)-A*floor(i/B))) #print(l) if N>=len(l): print(l[len(l)-1]) else: print(l[N]) """ def f(A,B,N): return floor(A*N/B)-A*floor(N/B) print((f(A,B,min(B-1,N))))
41
49
840
1,042
from math import floor, ceil import fractions import collections import itertools from collections import deque A, B, N = list(map(int, input().split())) piv = B / A # 基本数 # for i in range(0,30): # print(A,i,B,floor(A*i/B)-A*floor(i/B)) # A<=Bなら # 0,0,.. 1,1,.. ... (A-1),(A-1),...が # 先頭から(B%A)の数字まではceil(piv)こ、あとはfloor(piv)こ cnt = 0 # print(ceil(piv)*(B%A)) if A <= B: if N >= B - 1: print((A - 1)) else: if ceil(piv) * (B % A) > N: print((floor(N / ceil(piv)))) else: N = N - ceil(piv) * (B % A) # print(N,N//floor(piv)) cnt = B % A print((cnt + N // floor(piv))) else: # A>B l = [0] for i in range(1, B): l.append(max(l[i - 1], floor(A * i / B) - A * floor(i / B))) # print(l) if N >= len(l): print((l[len(l) - 1])) else: print((l[N]))
from math import floor, ceil import fractions import collections import itertools from collections import deque A, B, N = list(map(int, input().split())) piv = B / A # 基本数 # for i in range(0,30): # print(A,i,B,floor(A*i/B)-A*floor(i/B)) # A<=Bなら # 0,0,.. 1,1,.. ... (A-1),(A-1),...が # 先頭から(B%A)の数字まではceil(piv)こ、あとはfloor(piv)こ # →これより、この答えはmod(B)の空間で単調増加とわかる # よって、f(min(B-1,N))が答え # A>Bでも同じくmod(B)にて単調増加なのを調べてたはずなので # いずれにせよf(min(B-1,N))が答え cnt = 0 # print(ceil(piv)*(B%A)) """ if A<=B: if N>=B-1: print(A-1) else: if ceil(piv)*(B%A)>N: print(floor(N/ceil(piv))) else: N=N-ceil(piv)*(B%A) #print(N,N//floor(piv)) cnt=(B%A) print(cnt+N//floor(piv)) else: #A>B l=[0] for i in range(1,B): l.append(max(l[i-1],floor(A*i/B)-A*floor(i/B))) #print(l) if N>=len(l): print(l[len(l)-1]) else: print(l[N]) """ def f(A, B, N): return floor(A * N / B) - A * floor(N / B) print((f(A, B, min(B - 1, N))))
false
16.326531
[ "+# →これより、この答えはmod(B)の空間で単調増加とわかる", "+# よって、f(min(B-1,N))が答え", "+# A>Bでも同じくmod(B)にて単調増加なのを調べてたはずなので", "+# いずれにせよf(min(B-1,N))が答え", "-if A <= B:", "- if N >= B - 1:", "- print((A - 1))", "+\"\"\"", "+if A<=B:", "+ if N>=B-1:", "+ print(A-1)", "- if ceil(piv) * (B % A) > N:", "- print((floor(N / ceil(piv))))", "+ if ceil(piv)*(B%A)>N:", "+ print(floor(N/ceil(piv)))", "- N = N - ceil(piv) * (B % A)", "- # print(N,N//floor(piv))", "- cnt = B % A", "- print((cnt + N // floor(piv)))", "-else: # A>B", "- l = [0]", "- for i in range(1, B):", "- l.append(max(l[i - 1], floor(A * i / B) - A * floor(i / B)))", "- # print(l)", "- if N >= len(l):", "- print((l[len(l) - 1]))", "+ N=N-ceil(piv)*(B%A)", "+ #print(N,N//floor(piv))", "+ cnt=(B%A)", "+ print(cnt+N//floor(piv))", "+else: #A>B", "+ l=[0]", "+ for i in range(1,B):", "+ l.append(max(l[i-1],floor(A*i/B)-A*floor(i/B)))", "+ #print(l)", "+ if N>=len(l):", "+ print(l[len(l)-1])", "- print((l[N]))", "+ print(l[N])", "+\"\"\"", "+", "+", "+def f(A, B, N):", "+ return floor(A * N / B) - A * floor(N / B)", "+", "+", "+print((f(A, B, min(B - 1, N))))" ]
false
0.056444
0.036784
1.53446
[ "s232705104", "s058563539" ]
u600402037
p02841
python
s032669213
s693900782
149
17
12,396
2,940
Accepted
Accepted
88.59
import sys import numpy as np sys.setrecursionlimit(10 ** 9) stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces M1, D1 = rl() M2, D2 = rl() print((1 if M1 != M2 else 0))
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces M1, D1 = rl() M2, D2 = rl() print((1 if M1 != M2 else 0))
13
11
293
241
import sys import numpy as np sys.setrecursionlimit(10**9) stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces M1, D1 = rl() M2, D2 = rl() print((1 if M1 != M2 else 0))
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces M1, D1 = rl() M2, D2 = rl() print((1 if M1 != M2 else 0))
false
15.384615
[ "-import numpy as np", "-sys.setrecursionlimit(10**9)" ]
false
0.036174
0.039603
0.913424
[ "s032669213", "s693900782" ]
u581187895
p02555
python
s759249960
s325590054
708
32
9,068
9,196
Accepted
Accepted
95.48
def resolve(): MOD = 10 ** 9 + 7 N = int(eval(input())) dp = [0] * (N + 1) dp[0] = 1 for n in range(N + 1): for i in range(3, N + 1): dp[n] += dp[n - i] dp[n] %= MOD print((dp[N])) if __name__ == "__main__": resolve()
def resolve(): MOD = 10 ** 9 + 7 N = int(eval(input())) dp = [0] * (N + 1) res = 1 for i in range(3, N + 1): res += dp[i - 3] res %= MOD dp[i] = res print((dp[N])) if __name__ == "__main__": resolve()
17
17
290
265
def resolve(): MOD = 10**9 + 7 N = int(eval(input())) dp = [0] * (N + 1) dp[0] = 1 for n in range(N + 1): for i in range(3, N + 1): dp[n] += dp[n - i] dp[n] %= MOD print((dp[N])) if __name__ == "__main__": resolve()
def resolve(): MOD = 10**9 + 7 N = int(eval(input())) dp = [0] * (N + 1) res = 1 for i in range(3, N + 1): res += dp[i - 3] res %= MOD dp[i] = res print((dp[N])) if __name__ == "__main__": resolve()
false
0
[ "- dp[0] = 1", "- for n in range(N + 1):", "- for i in range(3, N + 1):", "- dp[n] += dp[n - i]", "- dp[n] %= MOD", "+ res = 1", "+ for i in range(3, N + 1):", "+ res += dp[i - 3]", "+ res %= MOD", "+ dp[i] = res" ]
false
0.4393
0.035046
12.534919
[ "s759249960", "s325590054" ]
u163783894
p02774
python
s277125530
s991527270
1,766
1,062
116,504
124,184
Accepted
Accepted
39.86
import sys import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode('utf-8') INF = 10**18 def binary_search(min_n, max_n, judge): while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge(tn): max_n = tn else: min_n = tn return max_n def main(): N, K = in_nn() A = in_nl() Ap = [] Am = [] Nz = 0 for i in range(N): if A[i] > 0: Ap.append(A[i]) elif A[i] == 0: Nz += 1 else: Am.append(A[i]) Np = len(Ap) Nm = len(Am) m_count = Np * Nm z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2 # p_count = Np * (Np - 1) // 2 + Nm * (Nm - 1) // 2 if K <= m_count: Ap.sort() Am.sort() def judge(tn): count = 0 for i in range(Nm): search = -(-tn // Am[i]) j = bisect.bisect_left(Ap, search) count += Np - j return count >= K ans = binary_search(-INF, -1, judge) elif K <= m_count + z_count: ans = 0 else: Ap.sort() Am = sorted([-a for a in Am]) def judge(tn): count = 0 for i in range(Np): search = tn // Ap[i] j = bisect.bisect_right(Ap, search) count += max(0, j - i - 1) for i in range(Nm): search = tn // Am[i] j = bisect.bisect_right(Am, search) count += max(0, j - i - 1) return count >= (K - m_count - z_count) ans = binary_search(1, INF, judge) print(ans) if __name__ == '__main__': main()
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode('utf-8') @njit('(i8,i8,i4[:],i4[:],i8,i8)', cache=True) def judge1(tn, K, Ap, Am, Nm, Np): count = 0 for i in range(Nm): search = -(-tn // -Am[i]) j = np.searchsorted(Ap, search, side='left') count += Np - j return count >= K @njit('(i8,i8,i4[:],i4[:],i8,i8,i8,i8)', cache=True) def judge2(tn, K, Ap, Am, Nm, Np, m_count, z_count): count = 0 for i in range(Np): search = tn // Ap[i] j = np.searchsorted(Ap, search, side='right') count += max(0, j - i - 1) for i in range(Nm): search = tn // Am[i] j = np.searchsorted(Am, search, side='right') count += max(0, j - i - 1) return count >= (K - m_count - z_count) @njit('(i8,i8,i4[:],i4[:],i8,)', cache=True) def solve(N, K, Ap, Am, Nz): INF = 10**18 Np = Ap.size Nm = Am.size m_count = Np * Nm z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2 if K <= m_count: min_n, max_n = -INF, -1 while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge1(tn, K, Ap, Am, Nm, Np): max_n = tn else: min_n = tn ans = max_n elif K <= m_count + z_count: ans = 0 else: min_n, max_n = 1, INF while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge2(tn, K, Ap, Am, Nm, Np, m_count, z_count): max_n = tn else: min_n = tn ans = max_n return ans def main(): N, K = in_nn() A = in_nl() Ap, Am = [], [] Nz = 0 for i in range(N): if A[i] > 0: Ap.append(A[i]) elif A[i] == 0: Nz += 1 else: Am.append(A[i]) Ap = np.array(sorted(Ap), np.int32) Am = np.array(sorted([-a for a in Am]), np.int32) print((solve(N, K, Ap, Am, Nz))) if __name__ == '__main__': main()
96
105
2,021
2,368
import sys import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode("utf-8") INF = 10**18 def binary_search(min_n, max_n, judge): while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge(tn): max_n = tn else: min_n = tn return max_n def main(): N, K = in_nn() A = in_nl() Ap = [] Am = [] Nz = 0 for i in range(N): if A[i] > 0: Ap.append(A[i]) elif A[i] == 0: Nz += 1 else: Am.append(A[i]) Np = len(Ap) Nm = len(Am) m_count = Np * Nm z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2 # p_count = Np * (Np - 1) // 2 + Nm * (Nm - 1) // 2 if K <= m_count: Ap.sort() Am.sort() def judge(tn): count = 0 for i in range(Nm): search = -(-tn // Am[i]) j = bisect.bisect_left(Ap, search) count += Np - j return count >= K ans = binary_search(-INF, -1, judge) elif K <= m_count + z_count: ans = 0 else: Ap.sort() Am = sorted([-a for a in Am]) def judge(tn): count = 0 for i in range(Np): search = tn // Ap[i] j = bisect.bisect_right(Ap, search) count += max(0, j - i - 1) for i in range(Nm): search = tn // Am[i] j = bisect.bisect_right(Am, search) count += max(0, j - i - 1) return count >= (K - m_count - z_count) ans = binary_search(1, INF, judge) print(ans) if __name__ == "__main__": main()
import sys import numpy as np from numba import njit read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: list(map(int, readline().split())) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: list(map(int, read().split())) in_s = lambda: readline().rstrip().decode("utf-8") @njit("(i8,i8,i4[:],i4[:],i8,i8)", cache=True) def judge1(tn, K, Ap, Am, Nm, Np): count = 0 for i in range(Nm): search = -(-tn // -Am[i]) j = np.searchsorted(Ap, search, side="left") count += Np - j return count >= K @njit("(i8,i8,i4[:],i4[:],i8,i8,i8,i8)", cache=True) def judge2(tn, K, Ap, Am, Nm, Np, m_count, z_count): count = 0 for i in range(Np): search = tn // Ap[i] j = np.searchsorted(Ap, search, side="right") count += max(0, j - i - 1) for i in range(Nm): search = tn // Am[i] j = np.searchsorted(Am, search, side="right") count += max(0, j - i - 1) return count >= (K - m_count - z_count) @njit("(i8,i8,i4[:],i4[:],i8,)", cache=True) def solve(N, K, Ap, Am, Nz): INF = 10**18 Np = Ap.size Nm = Am.size m_count = Np * Nm z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2 if K <= m_count: min_n, max_n = -INF, -1 while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge1(tn, K, Ap, Am, Nm, Np): max_n = tn else: min_n = tn ans = max_n elif K <= m_count + z_count: ans = 0 else: min_n, max_n = 1, INF while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge2(tn, K, Ap, Am, Nm, Np, m_count, z_count): max_n = tn else: min_n = tn ans = max_n return ans def main(): N, K = in_nn() A = in_nl() Ap, Am = [], [] Nz = 0 for i in range(N): if A[i] > 0: Ap.append(A[i]) elif A[i] == 0: Nz += 1 else: Am.append(A[i]) Ap = np.array(sorted(Ap), np.int32) Am = np.array(sorted([-a for a in Am]), np.int32) print((solve(N, K, Ap, Am, Nz))) if __name__ == "__main__": main()
false
8.571429
[ "-import bisect", "+import numpy as np", "+from numba import njit", "-INF = 10**18", "-def binary_search(min_n, max_n, judge):", "- while max_n - min_n != 1:", "- tn = (min_n + max_n) // 2", "- if judge(tn):", "- max_n = tn", "- else:", "- min_n = tn", "- return max_n", "+@njit(\"(i8,i8,i4[:],i4[:],i8,i8)\", cache=True)", "+def judge1(tn, K, Ap, Am, Nm, Np):", "+ count = 0", "+ for i in range(Nm):", "+ search = -(-tn // -Am[i])", "+ j = np.searchsorted(Ap, search, side=\"left\")", "+ count += Np - j", "+ return count >= K", "+", "+", "+@njit(\"(i8,i8,i4[:],i4[:],i8,i8,i8,i8)\", cache=True)", "+def judge2(tn, K, Ap, Am, Nm, Np, m_count, z_count):", "+ count = 0", "+ for i in range(Np):", "+ search = tn // Ap[i]", "+ j = np.searchsorted(Ap, search, side=\"right\")", "+ count += max(0, j - i - 1)", "+ for i in range(Nm):", "+ search = tn // Am[i]", "+ j = np.searchsorted(Am, search, side=\"right\")", "+ count += max(0, j - i - 1)", "+ return count >= (K - m_count - z_count)", "+", "+", "+@njit(\"(i8,i8,i4[:],i4[:],i8,)\", cache=True)", "+def solve(N, K, Ap, Am, Nz):", "+ INF = 10**18", "+ Np = Ap.size", "+ Nm = Am.size", "+ m_count = Np * Nm", "+ z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2", "+ if K <= m_count:", "+ min_n, max_n = -INF, -1", "+ while max_n - min_n != 1:", "+ tn = (min_n + max_n) // 2", "+ if judge1(tn, K, Ap, Am, Nm, Np):", "+ max_n = tn", "+ else:", "+ min_n = tn", "+ ans = max_n", "+ elif K <= m_count + z_count:", "+ ans = 0", "+ else:", "+ min_n, max_n = 1, INF", "+ while max_n - min_n != 1:", "+ tn = (min_n + max_n) // 2", "+ if judge2(tn, K, Ap, Am, Nm, Np, m_count, z_count):", "+ max_n = tn", "+ else:", "+ min_n = tn", "+ ans = max_n", "+ return ans", "- Ap = []", "- Am = []", "+ Ap, Am = [], []", "- Np = len(Ap)", "- Nm = len(Am)", "- m_count = Np * Nm", "- z_count = Nz * (Np + Nm) + Nz * (Nz - 1) // 2", "- # p_count = Np * (Np - 1) // 2 + Nm * (Nm - 1) // 2", "- if K <= m_count:", "- Ap.sort()", "- Am.sort()", "-", "- def judge(tn):", "- count = 0", "- for i in range(Nm):", "- search = -(-tn // Am[i])", "- j = bisect.bisect_left(Ap, search)", "- count += Np - j", "- return count >= K", "-", "- ans = binary_search(-INF, -1, judge)", "- elif K <= m_count + z_count:", "- ans = 0", "- else:", "- Ap.sort()", "- Am = sorted([-a for a in Am])", "-", "- def judge(tn):", "- count = 0", "- for i in range(Np):", "- search = tn // Ap[i]", "- j = bisect.bisect_right(Ap, search)", "- count += max(0, j - i - 1)", "- for i in range(Nm):", "- search = tn // Am[i]", "- j = bisect.bisect_right(Am, search)", "- count += max(0, j - i - 1)", "- return count >= (K - m_count - z_count)", "-", "- ans = binary_search(1, INF, judge)", "- print(ans)", "+ Ap = np.array(sorted(Ap), np.int32)", "+ Am = np.array(sorted([-a for a in Am]), np.int32)", "+ print((solve(N, K, Ap, Am, Nz)))" ]
false
0.047135
0.271951
0.173321
[ "s277125530", "s991527270" ]
u392029857
p03331
python
s822660745
s257520943
363
17
3,064
3,060
Accepted
Accepted
95.32
def digit_sum(x): a = list(range(1, x)) min_n = x for i in a: b = x - i p = sum(list(map(int, list(str(i))))) q = sum(list(map(int, list(str(b))))) if min_n > (p+q): min_n = p+q if a == b: break return min_n N = int(eval(input())) print((digit_sum(N)))
N = int(eval(input())) p = N sums = 0 if N == 10 or N == 100 or N == 1000 or N == 10000 or N == 100000: print((10)) else: while p >= 1: sums += p%10 p //= 10 print(sums)
14
10
331
198
def digit_sum(x): a = list(range(1, x)) min_n = x for i in a: b = x - i p = sum(list(map(int, list(str(i))))) q = sum(list(map(int, list(str(b))))) if min_n > (p + q): min_n = p + q if a == b: break return min_n N = int(eval(input())) print((digit_sum(N)))
N = int(eval(input())) p = N sums = 0 if N == 10 or N == 100 or N == 1000 or N == 10000 or N == 100000: print((10)) else: while p >= 1: sums += p % 10 p //= 10 print(sums)
false
28.571429
[ "-def digit_sum(x):", "- a = list(range(1, x))", "- min_n = x", "- for i in a:", "- b = x - i", "- p = sum(list(map(int, list(str(i)))))", "- q = sum(list(map(int, list(str(b)))))", "- if min_n > (p + q):", "- min_n = p + q", "- if a == b:", "- break", "- return min_n", "-", "-", "-print((digit_sum(N)))", "+p = N", "+sums = 0", "+if N == 10 or N == 100 or N == 1000 or N == 10000 or N == 100000:", "+ print((10))", "+else:", "+ while p >= 1:", "+ sums += p % 10", "+ p //= 10", "+ print(sums)" ]
false
0.255655
0.034727
7.361891
[ "s822660745", "s257520943" ]
u036104576
p02851
python
s349488533
s033725468
245
152
42,808
130,564
Accepted
Accepted
37.96
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0] * (N + 1) for i in range(1, N + 1): acc[i] = acc[i - 1] + A[i - 1] - 1 acc[i] %= K mp = defaultdict(int) ans = 0 for j in range(N + 1): if j >= K: mp[acc[j - K]] -= 1 ans += mp[acc[j]] mp[acc[j]] += 1 print(ans)
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0] * (N + 1) for i in range(1, N + 1): acc[i] = acc[i - 1] + A[i - 1] acc[i] %= K for i in range(0, N + 1): acc[i] -= i acc[i] %= K mp = defaultdict(int) ans = 0 for j in range(N + 1): if j >= K: mp[acc[j - K]] -= 1 ans += mp[acc[j]] mp[acc[j]] += 1 print(ans)
52
55
1,133
1,190
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0] * (N + 1) for i in range(1, N + 1): acc[i] = acc[i - 1] + A[i - 1] - 1 acc[i] %= K mp = defaultdict(int) ans = 0 for j in range(N + 1): if j >= K: mp[acc[j - K]] -= 1 ans += mp[acc[j]] mp[acc[j]] += 1 print(ans)
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = list(map(int, input().split())) A = list(map(int, input().split())) acc = [0] * (N + 1) for i in range(1, N + 1): acc[i] = acc[i - 1] + A[i - 1] acc[i] %= K for i in range(0, N + 1): acc[i] -= i acc[i] %= K mp = defaultdict(int) ans = 0 for j in range(N + 1): if j >= K: mp[acc[j - K]] -= 1 ans += mp[acc[j]] mp[acc[j]] += 1 print(ans)
false
5.454545
[ "- acc[i] = acc[i - 1] + A[i - 1] - 1", "+ acc[i] = acc[i - 1] + A[i - 1]", "+ acc[i] %= K", "+for i in range(0, N + 1):", "+ acc[i] -= i" ]
false
0.129975
0.038264
3.396809
[ "s349488533", "s033725468" ]
u436733497
p04044
python
s707351368
s101364283
129
64
62,232
62,432
Accepted
Accepted
50.39
x, y = list(map(int, input().split())) s = sorted([eval(input ()) for i in range(x)]) print(("".join(s)))
n, l = list(map(int, input().split())) k = [eval(input()) for _ in range(n)] s = sorted(k) print(("".join(s)))
3
4
93
99
x, y = list(map(int, input().split())) s = sorted([eval(input()) for i in range(x)]) print(("".join(s)))
n, l = list(map(int, input().split())) k = [eval(input()) for _ in range(n)] s = sorted(k) print(("".join(s)))
false
25
[ "-x, y = list(map(int, input().split()))", "-s = sorted([eval(input()) for i in range(x)])", "+n, l = list(map(int, input().split()))", "+k = [eval(input()) for _ in range(n)]", "+s = sorted(k)" ]
false
0.041677
0.038677
1.077559
[ "s707351368", "s101364283" ]
u189023301
p02574
python
s791424821
s519089131
503
440
194,456
195,252
Accepted
Accepted
12.52
from math import gcd n = int(eval(input())) s = list(map(int, input().split())) s.sort() dp = [0] * ((10 ** 6) + 100) res = s[0] for ss in s: dp[ss] += 1 res = gcd(res, ss) A = max(s) pairwise = True setwise = (res == 1) for i in range(2, A + 1): cnt = 0 for j in range(i, A + 1, i): cnt += dp[j] if cnt > 1: pairwise = False if pairwise: print("pairwise coprime") elif setwise: print("setwise coprime") else: print("not coprime")
from math import gcd n = int(eval(input())) s = list(map(int, input().split())) s.sort() dp = [0] * ((10 ** 6) + 100) res = s[0] for ss in s: dp[ss] += 1 res = gcd(res, ss) A = max(s) pairwise = True setwise = (res == 1) for i in range(2, A + 1): cnt = 0 for j in range(i, A + 1, i): cnt += dp[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") elif setwise: print("setwise coprime") else: print("not coprime")
28
29
504
519
from math import gcd n = int(eval(input())) s = list(map(int, input().split())) s.sort() dp = [0] * ((10**6) + 100) res = s[0] for ss in s: dp[ss] += 1 res = gcd(res, ss) A = max(s) pairwise = True setwise = res == 1 for i in range(2, A + 1): cnt = 0 for j in range(i, A + 1, i): cnt += dp[j] if cnt > 1: pairwise = False if pairwise: print("pairwise coprime") elif setwise: print("setwise coprime") else: print("not coprime")
from math import gcd n = int(eval(input())) s = list(map(int, input().split())) s.sort() dp = [0] * ((10**6) + 100) res = s[0] for ss in s: dp[ss] += 1 res = gcd(res, ss) A = max(s) pairwise = True setwise = res == 1 for i in range(2, A + 1): cnt = 0 for j in range(i, A + 1, i): cnt += dp[j] if cnt > 1: pairwise = False break if pairwise: print("pairwise coprime") elif setwise: print("setwise coprime") else: print("not coprime")
false
3.448276
[ "+ break" ]
false
0.103106
0.050387
2.046279
[ "s791424821", "s519089131" ]
u095021077
p02958
python
s598765337
s785692887
187
151
38,256
12,508
Accepted
Accepted
19.25
N=int(eval(input())) p=list(map(int, input().split())) counter=0 for i in range(N): if p[i]!=int(i+1): counter+=1 if counter==0 or counter==2: print('YES') else: print('NO')
import numpy as np N=int(eval(input())) p=np.array(list(map(int, input().split()))) q=np.arange(N)+1 temp=np.sum(~(p==q)) if temp==0 or temp==2: print('YES') else: print('NO')
12
12
194
189
N = int(eval(input())) p = list(map(int, input().split())) counter = 0 for i in range(N): if p[i] != int(i + 1): counter += 1 if counter == 0 or counter == 2: print("YES") else: print("NO")
import numpy as np N = int(eval(input())) p = np.array(list(map(int, input().split()))) q = np.arange(N) + 1 temp = np.sum(~(p == q)) if temp == 0 or temp == 2: print("YES") else: print("NO")
false
0
[ "+import numpy as np", "+", "-p = list(map(int, input().split()))", "-counter = 0", "-for i in range(N):", "- if p[i] != int(i + 1):", "- counter += 1", "-if counter == 0 or counter == 2:", "+p = np.array(list(map(int, input().split())))", "+q = np.arange(N) + 1", "+temp = np.sum(~(p == q))", "+if temp == 0 or temp == 2:" ]
false
0.037503
0.421691
0.088934
[ "s598765337", "s785692887" ]
u606033239
p03378
python
s000355513
s113743631
20
18
3,064
3,060
Accepted
Accepted
10
n,m,x=list(map(int,input().split())) a=list(map(int,input().split())) s=0 i=0 while a[i]<=x: s+=1 i+=1 print((min(s,m-s)))
n,m,x=list(map(int,input().split())) a=list(map(int,input().split())) i=0 while a[i]<=x: i+=1 print((min(i,m-i)))
8
6
129
114
n, m, x = list(map(int, input().split())) a = list(map(int, input().split())) s = 0 i = 0 while a[i] <= x: s += 1 i += 1 print((min(s, m - s)))
n, m, x = list(map(int, input().split())) a = list(map(int, input().split())) i = 0 while a[i] <= x: i += 1 print((min(i, m - i)))
false
25
[ "-s = 0", "- s += 1", "-print((min(s, m - s)))", "+print((min(i, m - i)))" ]
false
0.042746
0.038392
1.113415
[ "s000355513", "s113743631" ]
u347600233
p02724
python
s440287822
s126255076
30
23
9,032
9,100
Accepted
Accepted
23.33
x = int(eval(input())) print((1000*(x // 500) + 5*((x % 500) // 5) ))
x = int(eval(input())) print((1000*(x // 500) + 5*(x%500 // 5) ))
2
2
62
58
x = int(eval(input())) print((1000 * (x // 500) + 5 * ((x % 500) // 5)))
x = int(eval(input())) print((1000 * (x // 500) + 5 * (x % 500 // 5)))
false
0
[ "-print((1000 * (x // 500) + 5 * ((x % 500) // 5)))", "+print((1000 * (x // 500) + 5 * (x % 500 // 5)))" ]
false
0.037335
0.042325
0.882081
[ "s440287822", "s126255076" ]
u562935282
p03837
python
s216743736
s337620534
215
121
3,444
3,316
Accepted
Accepted
43.72
# https://atcoder.jp/contests/abc051/submissions/1055446 def main(): import sys input = sys.stdin.readline inf = 1000 * 100 + 10 N, M = list(map(int, input().split())) dist = [[inf for _ in range(N)] for _ in range(N)] for j in range(N): dist[j][j] = 0 es = [] for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 es.append((a, b, c)) dist[a][b] = dist[b][a] = c for k in range(N): for i in range(N): for j in range(N): d = dist[i][k] + dist[k][j] if dist[i][j] > d: dist[i][j] = d ans = 0 for a, b, c in es: if dist[a][b] == c: continue ans += 1 print(ans) if __name__ == '__main__': main()
# https://atcoder.jp/contests/abc051/submissions/1055446 def main(): import sys input = sys.stdin.readline inf = 1000 * 100 + 10 N, M = list(map(int, input().split())) dist = [[inf for _ in range(N)] for _ in range(N)] for j in range(N): dist[j][j] = 0 es = [] for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 es.append((a, b, c)) dist[a][b] = dist[b][a] = c for k in range(N): for j in range(N): for i in range(j): d = dist[i][k] + dist[k][j] if dist[i][j] > d: dist[i][j] = dist[j][i] = d ans = 0 for a, b, c in es: if dist[a][b] == c: continue ans += 1 print(ans) if __name__ == '__main__': main()
38
38
836
849
# https://atcoder.jp/contests/abc051/submissions/1055446 def main(): import sys input = sys.stdin.readline inf = 1000 * 100 + 10 N, M = list(map(int, input().split())) dist = [[inf for _ in range(N)] for _ in range(N)] for j in range(N): dist[j][j] = 0 es = [] for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 es.append((a, b, c)) dist[a][b] = dist[b][a] = c for k in range(N): for i in range(N): for j in range(N): d = dist[i][k] + dist[k][j] if dist[i][j] > d: dist[i][j] = d ans = 0 for a, b, c in es: if dist[a][b] == c: continue ans += 1 print(ans) if __name__ == "__main__": main()
# https://atcoder.jp/contests/abc051/submissions/1055446 def main(): import sys input = sys.stdin.readline inf = 1000 * 100 + 10 N, M = list(map(int, input().split())) dist = [[inf for _ in range(N)] for _ in range(N)] for j in range(N): dist[j][j] = 0 es = [] for _ in range(M): a, b, c = list(map(int, input().split())) a -= 1 b -= 1 es.append((a, b, c)) dist[a][b] = dist[b][a] = c for k in range(N): for j in range(N): for i in range(j): d = dist[i][k] + dist[k][j] if dist[i][j] > d: dist[i][j] = dist[j][i] = d ans = 0 for a, b, c in es: if dist[a][b] == c: continue ans += 1 print(ans) if __name__ == "__main__": main()
false
0
[ "- for i in range(N):", "- for j in range(N):", "+ for j in range(N):", "+ for i in range(j):", "- dist[i][j] = d", "+ dist[i][j] = dist[j][i] = d" ]
false
0.056481
0.091193
0.619355
[ "s216743736", "s337620534" ]
u619144316
p02813
python
s493177253
s370953553
19
17
3,064
3,064
Accepted
Accepted
10.53
N = int(eval(input())) P = [int(i) for i in input().split(' ')] Q = [int(i) for i in input().split(' ')] fact = [1] * 8 for i in range(1,8): fact[i] = fact[i-1] * i a = 0 remain = list(range(1,N+1)) for i , v in enumerate(P): num = remain.index(v) remain.remove(v) a += num * fact[(N - i - 1)] b = 0 remain = list(range(1,N+1)) for i , v in enumerate(Q): num = remain.index(v) remain.remove(v) b += num * fact[(N - i - 1)] print((abs(b-a)))
N = int(eval(input())) P = list(map(int,input().split())) Q = list(map(int,input().split())) fact = [1] *(N+1) for i in range(1,N+1): fact[i] = fact[i-1] *i a = 1 b = 1 P2 = sorted(P) Q2 = sorted(Q) for i,(p,q) in enumerate(zip(P,Q)): a += P2.index(p)*fact[N-i-1] b += Q2.index(q)*fact[N-i-1] P2.remove(p) Q2.remove(q) print((abs(b-a)))
25
18
493
368
N = int(eval(input())) P = [int(i) for i in input().split(" ")] Q = [int(i) for i in input().split(" ")] fact = [1] * 8 for i in range(1, 8): fact[i] = fact[i - 1] * i a = 0 remain = list(range(1, N + 1)) for i, v in enumerate(P): num = remain.index(v) remain.remove(v) a += num * fact[(N - i - 1)] b = 0 remain = list(range(1, N + 1)) for i, v in enumerate(Q): num = remain.index(v) remain.remove(v) b += num * fact[(N - i - 1)] print((abs(b - a)))
N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) fact = [1] * (N + 1) for i in range(1, N + 1): fact[i] = fact[i - 1] * i a = 1 b = 1 P2 = sorted(P) Q2 = sorted(Q) for i, (p, q) in enumerate(zip(P, Q)): a += P2.index(p) * fact[N - i - 1] b += Q2.index(q) * fact[N - i - 1] P2.remove(p) Q2.remove(q) print((abs(b - a)))
false
28
[ "-P = [int(i) for i in input().split(\" \")]", "-Q = [int(i) for i in input().split(\" \")]", "-fact = [1] * 8", "-for i in range(1, 8):", "+P = list(map(int, input().split()))", "+Q = list(map(int, input().split()))", "+fact = [1] * (N + 1)", "+for i in range(1, N + 1):", "-a = 0", "-remain = list(range(1, N + 1))", "-for i, v in enumerate(P):", "- num = remain.index(v)", "- remain.remove(v)", "- a += num * fact[(N - i - 1)]", "-b = 0", "-remain = list(range(1, N + 1))", "-for i, v in enumerate(Q):", "- num = remain.index(v)", "- remain.remove(v)", "- b += num * fact[(N - i - 1)]", "+a = 1", "+b = 1", "+P2 = sorted(P)", "+Q2 = sorted(Q)", "+for i, (p, q) in enumerate(zip(P, Q)):", "+ a += P2.index(p) * fact[N - i - 1]", "+ b += Q2.index(q) * fact[N - i - 1]", "+ P2.remove(p)", "+ Q2.remove(q)" ]
false
0.040803
0.042163
0.967745
[ "s493177253", "s370953553" ]
u389910364
p03988
python
s940129777
s303845900
163
21
13,684
3,316
Accepted
Accepted
87.12
import bisect import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) counts = Counter(A) m = max(A) ok = True if m % 2 == 0: ok &= min(A) == max(A) // 2 ok &= counts[min(A)] == 1 else: ok &= min(A) == max(A) // 2 + 1 ok &= counts[min(A)] == 2 for d in range(max(A), min(A), -1): ok &= counts[d] >= 2 if ok: print('Possible') else: print('Impossible')
import os import sys from collections import Counter 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())) counts = Counter(A) ma = max(A) mi = min(A) ok = True if ma % 2 == 0: ok &= mi == ma // 2 ok &= counts[mi] == 1 else: ok &= mi == ma // 2 + 1 ok &= counts[mi] == 2 for d in range(ma, mi, -1): ok &= counts[d] >= 2 if ok: print('Possible') else: print('Impossible')
44
31
939
605
import bisect import heapq import itertools import math import operator import os import re import string import sys from collections import Counter, deque, defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache, reduce from operator import itemgetter, mul, add, xor import numpy as np if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 10**9 + 7 N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) counts = Counter(A) m = max(A) ok = True if m % 2 == 0: ok &= min(A) == max(A) // 2 ok &= counts[min(A)] == 1 else: ok &= min(A) == max(A) // 2 + 1 ok &= counts[min(A)] == 2 for d in range(max(A), min(A), -1): ok &= counts[d] >= 2 if ok: print("Possible") else: print("Impossible")
import os import sys from collections import Counter 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())) counts = Counter(A) ma = max(A) mi = min(A) ok = True if ma % 2 == 0: ok &= mi == ma // 2 ok &= counts[mi] == 1 else: ok &= mi == ma // 2 + 1 ok &= counts[mi] == 2 for d in range(ma, mi, -1): ok &= counts[d] >= 2 if ok: print("Possible") else: print("Impossible")
false
29.545455
[ "-import bisect", "-import heapq", "-import itertools", "-import math", "-import operator", "-import re", "-import string", "-from collections import Counter, deque, defaultdict", "-from copy import deepcopy", "-from decimal import Decimal", "-from fractions import gcd", "-from functools import lru_cache, reduce", "-from operator import itemgetter, mul, add, xor", "-import numpy as np", "+from collections import Counter", "-m = max(A)", "+ma = max(A)", "+mi = min(A)", "-if m % 2 == 0:", "- ok &= min(A) == max(A) // 2", "- ok &= counts[min(A)] == 1", "+if ma % 2 == 0:", "+ ok &= mi == ma // 2", "+ ok &= counts[mi] == 1", "- ok &= min(A) == max(A) // 2 + 1", "- ok &= counts[min(A)] == 2", "-for d in range(max(A), min(A), -1):", "+ ok &= mi == ma // 2 + 1", "+ ok &= counts[mi] == 2", "+for d in range(ma, mi, -1):" ]
false
0.150485
0.034715
4.33486
[ "s940129777", "s303845900" ]
u883048396
p03645
python
s268058814
s754118640
309
263
56,620
6,132
Accepted
Accepted
14.89
import sys def 解(): iN,iM = [int(_) for _ in input().split()] a1 = [0]*iN aN = [0]*iN aAB = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] for a,b in aAB: if a == 1: a1[b] = 1 if b == iN: aN[a] = 1 for i in range(iN): if a1[i] and aN[i]: print("POSSIBLE") exit() print("IMPOSSIBLE") 解()
import sys input = sys.stdin.readline def 解(): iN,iM = [int(_) for _ in input().split()] a1 = [0]*iN aN = [0]*iN for i in range(iM): a,b = [int(_) for _ in input().split()] if a == 1: a1[b] = 1 if b == iN: aN[a] = 1 for i in range(iN): if a1[i] and aN[i]: print("POSSIBLE") exit() print("IMPOSSIBLE") 解()
17
18
425
426
import sys def 解(): iN, iM = [int(_) for _ in input().split()] a1 = [0] * iN aN = [0] * iN aAB = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] for a, b in aAB: if a == 1: a1[b] = 1 if b == iN: aN[a] = 1 for i in range(iN): if a1[i] and aN[i]: print("POSSIBLE") exit() print("IMPOSSIBLE") 解()
import sys input = sys.stdin.readline def 解(): iN, iM = [int(_) for _ in input().split()] a1 = [0] * iN aN = [0] * iN for i in range(iM): a, b = [int(_) for _ in input().split()] if a == 1: a1[b] = 1 if b == iN: aN[a] = 1 for i in range(iN): if a1[i] and aN[i]: print("POSSIBLE") exit() print("IMPOSSIBLE") 解()
false
5.555556
[ "+", "+input = sys.stdin.readline", "- aAB = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]", "- for a, b in aAB:", "+ for i in range(iM):", "+ a, b = [int(_) for _ in input().split()]" ]
false
0.044257
0.045322
0.976482
[ "s268058814", "s754118640" ]
u277312083
p03835
python
s429407541
s176998513
1,768
1,158
2,940
9,076
Accepted
Accepted
34.5
k, s = list(map(int, input().split())) c = 0 for x in range(k + 1): for y in range(k + 1): if 0 <= s - x - y and s - x - y <= k: c += 1 print(c)
k, s = list(map(int, input().split())) ans = 0 for x in range(k + 1): for y in range(k + 1): z = s - x - y if 0 <= z and z <= k: ans += 1 print(ans)
7
8
169
182
k, s = list(map(int, input().split())) c = 0 for x in range(k + 1): for y in range(k + 1): if 0 <= s - x - y and s - x - y <= k: c += 1 print(c)
k, s = list(map(int, input().split())) ans = 0 for x in range(k + 1): for y in range(k + 1): z = s - x - y if 0 <= z and z <= k: ans += 1 print(ans)
false
12.5
[ "-c = 0", "+ans = 0", "- if 0 <= s - x - y and s - x - y <= k:", "- c += 1", "-print(c)", "+ z = s - x - y", "+ if 0 <= z and z <= k:", "+ ans += 1", "+print(ans)" ]
false
0.039102
0.036743
1.064215
[ "s429407541", "s176998513" ]
u480200603
p02629
python
s345968014
s842315881
33
27
9,048
9,184
Accepted
Accepted
18.18
n = int(input()) s = "abcdefghijklmnopqrstuvwxyz" ans = [] t = 1 while n > 26: tmp = n % 26 if tmp == 0: tmp = 26 n //= 26 n -= 1 ans.append(tmp) continue ans.append(tmp) n //= 26 ans.append(n) for i in ans[::-1]: print(s[i-1], end="")
n = int(input()) s = "abcdefghijklmnopqrstuvwxyz" ans = [] while n > 26: n -= 1 tmp = n % 26 ans.append(tmp) n //= 26 ans.append(n-1) for i in ans[::-1]: print(s[i], end="")
21
14
320
210
n = int(input()) s = "abcdefghijklmnopqrstuvwxyz" ans = [] t = 1 while n > 26: tmp = n % 26 if tmp == 0: tmp = 26 n //= 26 n -= 1 ans.append(tmp) continue ans.append(tmp) n //= 26 ans.append(n) for i in ans[::-1]: print(s[i - 1], end="")
n = int(input()) s = "abcdefghijklmnopqrstuvwxyz" ans = [] while n > 26: n -= 1 tmp = n % 26 ans.append(tmp) n //= 26 ans.append(n - 1) for i in ans[::-1]: print(s[i], end="")
false
33.333333
[ "-t = 1", "+ n -= 1", "- if tmp == 0:", "- tmp = 26", "- n //= 26", "- n -= 1", "- ans.append(tmp)", "- continue", "-ans.append(n)", "+ans.append(n - 1)", "- print(s[i - 1], end=\"\")", "+ print(s[i], end=\"\")" ]
false
0.033467
0.035736
0.936487
[ "s345968014", "s842315881" ]
u246401133
p02584
python
s725387205
s627597758
30
26
9,176
9,188
Accepted
Accepted
13.33
y, k, d = list(map(int, input().split())) x = abs(y) i = int(x / d) if i >= k: p = x - k * d elif i == x / d: if (i + k) % 2 == 0: p = 0 else: p = d else: if ((2 * i + 1) * d == 2 * x) or ((i + k) % 2 == 0): p = x - i * d else: p = (i + 1) * d - x print((int(p)))
y, k, d = list(map(int, input().split())) x = abs(y) if k * d <= x: a = x - k * d else: if x % d == 0: if (k - (x / d)) % 2 == 0: a = 0 else: a = d else: b = x // d if (k - b) % 2 == 0: a = x - d * b else: a = -x + b * d + d print(a)
16
17
322
343
y, k, d = list(map(int, input().split())) x = abs(y) i = int(x / d) if i >= k: p = x - k * d elif i == x / d: if (i + k) % 2 == 0: p = 0 else: p = d else: if ((2 * i + 1) * d == 2 * x) or ((i + k) % 2 == 0): p = x - i * d else: p = (i + 1) * d - x print((int(p)))
y, k, d = list(map(int, input().split())) x = abs(y) if k * d <= x: a = x - k * d else: if x % d == 0: if (k - (x / d)) % 2 == 0: a = 0 else: a = d else: b = x // d if (k - b) % 2 == 0: a = x - d * b else: a = -x + b * d + d print(a)
false
5.882353
[ "-i = int(x / d)", "-if i >= k:", "- p = x - k * d", "-elif i == x / d:", "- if (i + k) % 2 == 0:", "- p = 0", "+if k * d <= x:", "+ a = x - k * d", "+else:", "+ if x % d == 0:", "+ if (k - (x / d)) % 2 == 0:", "+ a = 0", "+ else:", "+ a = d", "- p = d", "-else:", "- if ((2 * i + 1) * d == 2 * x) or ((i + k) % 2 == 0):", "- p = x - i * d", "- else:", "- p = (i + 1) * d - x", "-print((int(p)))", "+ b = x // d", "+ if (k - b) % 2 == 0:", "+ a = x - d * b", "+ else:", "+ a = -x + b * d + d", "+print(a)" ]
false
0.033958
0.033477
1.014387
[ "s725387205", "s627597758" ]
u958506960
p03767
python
s801548213
s450256988
229
209
39,492
37,084
Accepted
Accepted
8.73
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=True) ans = 0 for i in range(n): ans += a[i * 2 + 1] print(ans)
n = int(eval(input())) a = sorted(map(int, input().split())) print((sum(a[n::2])))
8
3
145
76
n = int(eval(input())) a = sorted(list(map(int, input().split())), reverse=True) ans = 0 for i in range(n): ans += a[i * 2 + 1] print(ans)
n = int(eval(input())) a = sorted(map(int, input().split())) print((sum(a[n::2])))
false
62.5
[ "-a = sorted(list(map(int, input().split())), reverse=True)", "-ans = 0", "-for i in range(n):", "- ans += a[i * 2 + 1]", "-print(ans)", "+a = sorted(map(int, input().split()))", "+print((sum(a[n::2])))" ]
false
0.04538
0.036659
1.237912
[ "s801548213", "s450256988" ]
u997521090
p03704
python
s749282574
s548682202
15
13
2,568
2,568
Accepted
Accepted
13.33
def func(d, cnt9, cnt0): if cnt9 < 1 : return d == 0 n = int("9" * cnt9 + "0" * cnt0) return sum(func(d + i * n, cnt9 - 2, cnt0 + 1) * (9 - abs(i) + 1 - (cnt0 < 1)) for i in range(-9, 10) if abs(d + i * n) < n) D = eval(input()) print(sum(func(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21)))
def func(d, x, y): n = int("9" * x + "0" * y) return d == 0 if x < 1 else sum(func(d + i * n, x - 2, y + 1) * (10 - abs(i) - (y < 1)) for i in range(-9, 10) if abs(d + i * n) < n) D = eval(input());print(sum(func(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21)))
7
4
307
268
def func(d, cnt9, cnt0): if cnt9 < 1: return d == 0 n = int("9" * cnt9 + "0" * cnt0) return sum( func(d + i * n, cnt9 - 2, cnt0 + 1) * (9 - abs(i) + 1 - (cnt0 < 1)) for i in range(-9, 10) if abs(d + i * n) < n ) D = eval(input()) print(sum(func(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21)))
def func(d, x, y): n = int("9" * x + "0" * y) return ( d == 0 if x < 1 else sum( func(d + i * n, x - 2, y + 1) * (10 - abs(i) - (y < 1)) for i in range(-9, 10) if abs(d + i * n) < n ) ) D = eval(input()) print(sum(func(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21)))
false
42.857143
[ "-def func(d, cnt9, cnt0):", "- if cnt9 < 1:", "- return d == 0", "- n = int(\"9\" * cnt9 + \"0\" * cnt0)", "- return sum(", "- func(d + i * n, cnt9 - 2, cnt0 + 1) * (9 - abs(i) + 1 - (cnt0 < 1))", "- for i in range(-9, 10)", "- if abs(d + i * n) < n", "+def func(d, x, y):", "+ n = int(\"9\" * x + \"0\" * y)", "+ return (", "+ d == 0", "+ if x < 1", "+ else sum(", "+ func(d + i * n, x - 2, y + 1) * (10 - abs(i) - (y < 1))", "+ for i in range(-9, 10)", "+ if abs(d + i * n) < n", "+ )" ]
false
0.043954
0.03387
1.297706
[ "s749282574", "s548682202" ]
u987164499
p03611
python
s847560820
s814190486
204
82
14,300
13,964
Accepted
Accepted
59.8
from sys import stdin import bisect n = int(stdin.readline().rstrip()) li = list(map(int,stdin.readline().rstrip().split())) li.sort() ma = 0 if len(li) == 1: print((1)) elif len(li) == 2: if abs(li[0] - li[1]) <= 1: print((2)) else: print((1)) else: for i in range(1,n-1): ma = max(ma,bisect.bisect(li,i+1)-bisect.bisect_left(li,i-1)) print(ma)
n = int(eval(input())) a = list(map(int,input().split())) point = [0]*(10**5+2) for i in a: if i == 1: point[1] += 1 point[2] += 1 else: point[i] += 1 point[i-1] += 1 point[i+1] += 1 print((max(point)))
22
15
409
259
from sys import stdin import bisect n = int(stdin.readline().rstrip()) li = list(map(int, stdin.readline().rstrip().split())) li.sort() ma = 0 if len(li) == 1: print((1)) elif len(li) == 2: if abs(li[0] - li[1]) <= 1: print((2)) else: print((1)) else: for i in range(1, n - 1): ma = max(ma, bisect.bisect(li, i + 1) - bisect.bisect_left(li, i - 1)) print(ma)
n = int(eval(input())) a = list(map(int, input().split())) point = [0] * (10**5 + 2) for i in a: if i == 1: point[1] += 1 point[2] += 1 else: point[i] += 1 point[i - 1] += 1 point[i + 1] += 1 print((max(point)))
false
31.818182
[ "-from sys import stdin", "-import bisect", "-", "-n = int(stdin.readline().rstrip())", "-li = list(map(int, stdin.readline().rstrip().split()))", "-li.sort()", "-ma = 0", "-if len(li) == 1:", "- print((1))", "-elif len(li) == 2:", "- if abs(li[0] - li[1]) <= 1:", "- print((2))", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+point = [0] * (10**5 + 2)", "+for i in a:", "+ if i == 1:", "+ point[1] += 1", "+ point[2] += 1", "- print((1))", "-else:", "- for i in range(1, n - 1):", "- ma = max(ma, bisect.bisect(li, i + 1) - bisect.bisect_left(li, i - 1))", "- print(ma)", "+ point[i] += 1", "+ point[i - 1] += 1", "+ point[i + 1] += 1", "+print((max(point)))" ]
false
0.041537
0.047136
0.881223
[ "s847560820", "s814190486" ]
u480138356
p03108
python
s931447643
s742810255
1,132
514
51,800
49,944
Accepted
Accepted
54.59
import sys input = sys.stdin.readline class Node: def __init__(self): self.is_root = True self.parent = None self.child_num = 0 def root_node(self): node = self while not node.is_root: node = node.parent return node def main(): N, M = list(map(int, input().split())) nodes = [Node() for i in range(N)] ab = [list(map(int, input().split())) for i in range(M)] inc = (N * (N-1)) // 2 ans = [inc] for i in range(M-1, -1, -1): a, b = ab[i] a -= 1 b -= 1 root_a = nodes[a].root_node() if root_a != nodes[a]: nodes[a].parent = root_a root_b = nodes[b].root_node() if root_b != nodes[b]: nodes[b].parent = root_b if root_a == root_b:# もともと連結成分だった場合 ans.append(inc) else:# 新たに連結成分になった場合 # if root_b.child_num > root_a.child_num: # tmp = root_a # root_a = root_b # root_b = tmp inc -= (root_a.child_num + 1) * (root_b.child_num + 1) ans.append(inc) root_b.is_root = False root_b.parent = root_a root_a.child_num += root_b.child_num + 1 for i in range(M-1, -1, -1): print((ans[i])) if __name__ == "__main__": main()
import sys input = sys.stdin.readline class Node: def __init__(self): self.is_root = True self.parent = None self.child_num = 0 def root_node(self): node = self while not node.is_root: node = node.parent return node def main(): N, M = list(map(int, input().split())) nodes = [Node() for i in range(N)] ab = [list(map(int, input().split())) for i in range(M)] inc = (N * (N-1)) // 2 ans = [inc] for i in range(M-1, -1, -1): a, b = ab[i] a -= 1 b -= 1 root_a = nodes[a].root_node() if root_a != nodes[a]: nodes[a].parent = root_a root_b = nodes[b].root_node() if root_b != nodes[b]: nodes[b].parent = root_b if root_a == root_b:# もともと連結成分だった場合 ans.append(inc) else:# 新たに連結成分になった場合 if root_b.child_num > root_a.child_num: tmp = root_a root_a = root_b root_b = tmp inc -= (root_a.child_num + 1) * (root_b.child_num + 1) ans.append(inc) root_b.is_root = False root_b.parent = root_a root_a.child_num += root_b.child_num + 1 for i in range(M-1, -1, -1): print((ans[i])) if __name__ == "__main__": main()
53
53
1,403
1,395
import sys input = sys.stdin.readline class Node: def __init__(self): self.is_root = True self.parent = None self.child_num = 0 def root_node(self): node = self while not node.is_root: node = node.parent return node def main(): N, M = list(map(int, input().split())) nodes = [Node() for i in range(N)] ab = [list(map(int, input().split())) for i in range(M)] inc = (N * (N - 1)) // 2 ans = [inc] for i in range(M - 1, -1, -1): a, b = ab[i] a -= 1 b -= 1 root_a = nodes[a].root_node() if root_a != nodes[a]: nodes[a].parent = root_a root_b = nodes[b].root_node() if root_b != nodes[b]: nodes[b].parent = root_b if root_a == root_b: # もともと連結成分だった場合 ans.append(inc) else: # 新たに連結成分になった場合 # if root_b.child_num > root_a.child_num: # tmp = root_a # root_a = root_b # root_b = tmp inc -= (root_a.child_num + 1) * (root_b.child_num + 1) ans.append(inc) root_b.is_root = False root_b.parent = root_a root_a.child_num += root_b.child_num + 1 for i in range(M - 1, -1, -1): print((ans[i])) if __name__ == "__main__": main()
import sys input = sys.stdin.readline class Node: def __init__(self): self.is_root = True self.parent = None self.child_num = 0 def root_node(self): node = self while not node.is_root: node = node.parent return node def main(): N, M = list(map(int, input().split())) nodes = [Node() for i in range(N)] ab = [list(map(int, input().split())) for i in range(M)] inc = (N * (N - 1)) // 2 ans = [inc] for i in range(M - 1, -1, -1): a, b = ab[i] a -= 1 b -= 1 root_a = nodes[a].root_node() if root_a != nodes[a]: nodes[a].parent = root_a root_b = nodes[b].root_node() if root_b != nodes[b]: nodes[b].parent = root_b if root_a == root_b: # もともと連結成分だった場合 ans.append(inc) else: # 新たに連結成分になった場合 if root_b.child_num > root_a.child_num: tmp = root_a root_a = root_b root_b = tmp inc -= (root_a.child_num + 1) * (root_b.child_num + 1) ans.append(inc) root_b.is_root = False root_b.parent = root_a root_a.child_num += root_b.child_num + 1 for i in range(M - 1, -1, -1): print((ans[i])) if __name__ == "__main__": main()
false
0
[ "- # if root_b.child_num > root_a.child_num:", "- # tmp = root_a", "- # root_a = root_b", "- # root_b = tmp", "+ if root_b.child_num > root_a.child_num:", "+ tmp = root_a", "+ root_a = root_b", "+ root_b = tmp" ]
false
0.11057
0.075205
1.47025
[ "s931447643", "s742810255" ]
u981931040
p02996
python
s631256743
s576235009
1,041
910
55,256
53,660
Accepted
Accepted
12.58
N = int (eval(input())) work = [] work_time = 0 flag = 0 for i in range(N): work.append(list(map(int , input().split()))) #print(work) work = sorted(work , key = lambda x: x[1]) #work.sort() #sort(work) #print() #print("sorting ... ") #print() #print(work) for i in range(N): work_time += work[i][0] if work_time > work[i][1]: flag = 1 break if flag == 1: print('No') else: print('Yes')
N = int(eval(input())) AB = list(list(map(int, input().split())) for _ in range(N)) AB.sort(key=lambda x: x[1]) now = 0 for a, b in AB: now += a if now > b: print("No") exit() print("Yes")
25
10
442
215
N = int(eval(input())) work = [] work_time = 0 flag = 0 for i in range(N): work.append(list(map(int, input().split()))) # print(work) work = sorted(work, key=lambda x: x[1]) # work.sort() # sort(work) # print() # print("sorting ... ") # print() # print(work) for i in range(N): work_time += work[i][0] if work_time > work[i][1]: flag = 1 break if flag == 1: print("No") else: print("Yes")
N = int(eval(input())) AB = list(list(map(int, input().split())) for _ in range(N)) AB.sort(key=lambda x: x[1]) now = 0 for a, b in AB: now += a if now > b: print("No") exit() print("Yes")
false
60
[ "-work = []", "-work_time = 0", "-flag = 0", "-for i in range(N):", "- work.append(list(map(int, input().split())))", "-# print(work)", "-work = sorted(work, key=lambda x: x[1])", "-# work.sort()", "-# sort(work)", "-# print()", "-# print(\"sorting ... \")", "-# print()", "-# print(work)", "-for i in range(N):", "- work_time += work[i][0]", "- if work_time > work[i][1]:", "- flag = 1", "- break", "-if flag == 1:", "- print(\"No\")", "-else:", "- print(\"Yes\")", "+AB = list(list(map(int, input().split())) for _ in range(N))", "+AB.sort(key=lambda x: x[1])", "+now = 0", "+for a, b in AB:", "+ now += a", "+ if now > b:", "+ print(\"No\")", "+ exit()", "+print(\"Yes\")" ]
false
0.121536
0.038416
3.163678
[ "s631256743", "s576235009" ]
u077291787
p02837
python
s582203568
s850921436
50
45
3,064
3,064
Accepted
Accepted
10
# ABC147C - HonestOrUnkind2 from itertools import combinations def main(): N = int(eval(input())) testimonies = {i: {} for i in range(1, N + 1)} for i in range(1, N + 1): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) testimonies[i][x] = y for cnt_honest in range(N, 0, -1): for honest_people in combinations(list(range(1, N + 1)), cnt_honest): honest_people = set(honest_people) is_consistent = True for i in honest_people: for x, y in list(testimonies[i].items()): if (x in honest_people and not y) or (x not in honest_people and y): is_consistent = False break if not is_consistent: break if is_consistent: print(cnt_honest) return print((0)) if __name__ == "__main__": main()
# ABC147C - HonestOrUnkind2 from itertools import combinations def main(): N = int(eval(input())) testimonies = [[] for i in range(N + 1)] for i in range(1, N + 1): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) testimonies[i].append((x, y)) for cnt_honest in range(N, 0, -1): for honest_people in combinations(list(range(1, N + 1)), cnt_honest): honest_people = set(honest_people) is_consistent = True for i in honest_people: for x, y in testimonies[i]: if (x in honest_people and not y) or (x not in honest_people and y): is_consistent = False break if not is_consistent: break if is_consistent: print(cnt_honest) return print((0)) if __name__ == "__main__": main()
32
32
990
983
# ABC147C - HonestOrUnkind2 from itertools import combinations def main(): N = int(eval(input())) testimonies = {i: {} for i in range(1, N + 1)} for i in range(1, N + 1): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) testimonies[i][x] = y for cnt_honest in range(N, 0, -1): for honest_people in combinations(list(range(1, N + 1)), cnt_honest): honest_people = set(honest_people) is_consistent = True for i in honest_people: for x, y in list(testimonies[i].items()): if (x in honest_people and not y) or (x not in honest_people and y): is_consistent = False break if not is_consistent: break if is_consistent: print(cnt_honest) return print((0)) if __name__ == "__main__": main()
# ABC147C - HonestOrUnkind2 from itertools import combinations def main(): N = int(eval(input())) testimonies = [[] for i in range(N + 1)] for i in range(1, N + 1): A = int(eval(input())) for _ in range(A): x, y = list(map(int, input().split())) testimonies[i].append((x, y)) for cnt_honest in range(N, 0, -1): for honest_people in combinations(list(range(1, N + 1)), cnt_honest): honest_people = set(honest_people) is_consistent = True for i in honest_people: for x, y in testimonies[i]: if (x in honest_people and not y) or (x not in honest_people and y): is_consistent = False break if not is_consistent: break if is_consistent: print(cnt_honest) return print((0)) if __name__ == "__main__": main()
false
0
[ "- testimonies = {i: {} for i in range(1, N + 1)}", "+ testimonies = [[] for i in range(N + 1)]", "- testimonies[i][x] = y", "+ testimonies[i].append((x, y))", "- for x, y in list(testimonies[i].items()):", "+ for x, y in testimonies[i]:" ]
false
0.038078
0.046616
0.816836
[ "s582203568", "s850921436" ]
u102461423
p03464
python
s355279915
s245298532
101
80
14,168
18,836
Accepted
Accepted
20.79
import sys input = sys.stdin.readline N = list(map(int,input().split())) A = [int(x) for x in input().split()] low,high = 2,2 for a in A[::-1]: low += (-low)%a high -= high%a high += (a-1) if low > high: print((-1)) else: print((low,high))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = list(map(int, read().split())) def f(A): low, high = 2, 2 for x in A[::-1]: low += (-low) % x high -= (high) % x if low > high: print((-1)) return low, high = low, high+(x-1) print((low, high)) f(A)
17
20
269
403
import sys input = sys.stdin.readline N = list(map(int, input().split())) A = [int(x) for x in input().split()] low, high = 2, 2 for a in A[::-1]: low += (-low) % a high -= high % a high += a - 1 if low > high: print((-1)) else: print((low, high))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = list(map(int, read().split())) def f(A): low, high = 2, 2 for x in A[::-1]: low += (-low) % x high -= (high) % x if low > high: print((-1)) return low, high = low, high + (x - 1) print((low, high)) f(A)
false
15
[ "-input = sys.stdin.readline", "-N = list(map(int, input().split()))", "-A = [int(x) for x in input().split()]", "-low, high = 2, 2", "-for a in A[::-1]:", "- low += (-low) % a", "- high -= high % a", "- high += a - 1", "-if low > high:", "- print((-1))", "-else:", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+N, *A = list(map(int, read().split()))", "+", "+", "+def f(A):", "+ low, high = 2, 2", "+ for x in A[::-1]:", "+ low += (-low) % x", "+ high -= (high) % x", "+ if low > high:", "+ print((-1))", "+ return", "+ low, high = low, high + (x - 1)", "+", "+", "+f(A)" ]
false
0.10001
0.037324
2.679519
[ "s355279915", "s245298532" ]
u738898077
p02580
python
s311675710
s471982115
584
473
196,704
219,860
Accepted
Accepted
19.01
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [[-1,10**6] for i in range(H+1)] for i in range(m): a,b = list(map(int,input().split())) h[a] += 1 w[b] += 1 c[a].append(b) mh = max(h) mw = max(w) hkouho = [] wkouho = [] for i in range(H+1): if h[i] == mh: hkouho.append(i) for i in range(W+1): if w[i] == mw: wkouho.append(i) for i in hkouho: c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh+mw)) exit() print((mh+mw-1))
from bisect import bisect_left import sys input = sys.stdin.readline H,W,m = list(map(int,input().split())) h = [0]*(H+1) w = [0]*(W+1) c = [{-1,10**6} for i in range(H+1)] for i in range(m): a,b = list(map(int,input().split())) h[a] += 1 w[b] += 1 c[a].add(b) mh = max(h) mw = max(w) hkouho = [] wkouho = [] for i in range(H+1): if h[i] == mh: hkouho.append(i) for i in range(W+1): if w[i] == mw: wkouho.append(i) for i in hkouho: # c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh+mw)) exit() print((mh+mw-1))
30
30
663
662
from bisect import bisect_left import sys input = sys.stdin.readline H, W, m = list(map(int, input().split())) h = [0] * (H + 1) w = [0] * (W + 1) c = [[-1, 10**6] for i in range(H + 1)] for i in range(m): a, b = list(map(int, input().split())) h[a] += 1 w[b] += 1 c[a].append(b) mh = max(h) mw = max(w) hkouho = [] wkouho = [] for i in range(H + 1): if h[i] == mh: hkouho.append(i) for i in range(W + 1): if w[i] == mw: wkouho.append(i) for i in hkouho: c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh + mw)) exit() print((mh + mw - 1))
from bisect import bisect_left import sys input = sys.stdin.readline H, W, m = list(map(int, input().split())) h = [0] * (H + 1) w = [0] * (W + 1) c = [{-1, 10**6} for i in range(H + 1)] for i in range(m): a, b = list(map(int, input().split())) h[a] += 1 w[b] += 1 c[a].add(b) mh = max(h) mw = max(w) hkouho = [] wkouho = [] for i in range(H + 1): if h[i] == mh: hkouho.append(i) for i in range(W + 1): if w[i] == mw: wkouho.append(i) for i in hkouho: # c[i] = set(c[i]) for j in wkouho: # if c[i][bisect_left(c[i],j)] != j: if j not in c[i]: print((mh + mw)) exit() print((mh + mw - 1))
false
0
[ "-c = [[-1, 10**6] for i in range(H + 1)]", "+c = [{-1, 10**6} for i in range(H + 1)]", "- c[a].append(b)", "+ c[a].add(b)", "- c[i] = set(c[i])", "+ # c[i] = set(c[i])" ]
false
0.048014
0.04877
0.984497
[ "s311675710", "s471982115" ]
u345966487
p03682
python
s128814384
s694618162
1,909
1,141
126,108
62,776
Accepted
Accepted
40.23
import sys class UnionFind: def __init__(self, n): # total number of nodes. self.n = n # node id -> root node id self._root_table = list(range(n)) # root node id -> group size self._size_table = [1] * n def find(self, x): """Returns x's root node id.""" r = self._root_table[x] if r != x: # Update the cache on query. r = self._root_table[x] = self.find(r) return r def union(self, x, y): """Merges two groups.""" x = self.find(x) y = self.find(y) if x == y: return # Ensure that x is the larger (or equal) group. if self._size_table[x] < self._size_table[y]: x, y = y, x self._size_table[x] += self._size_table[y] self._root_table[y] = x def size(self, x): return self._size_table[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self._root_table) if x == i] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) input = sys.stdin.readline def main(): N = int(eval(input())) cities, xs, ys = [], [], [] for i in range(N): x, y = list(map(int, input().split())) cities.append((x, y)) xs.append((x, i)) ys.append((y, i)) xs.sort() ys.sort() xd, yd = [], [] for i in range(1, N): x1, c1 = xs[i - 1] x2, c2 = xs[i] if x2 - x1 <= abs(cities[c1][1] - cities[c2][1]): xd.append((x2 - x1, c1, c2)) y1, c1 = ys[i - 1] y2, c2 = ys[i] if y2 - y1 < abs(cities[c1][0] - cities[c2][0]): xd.append((y2 - y1, c1, c2)) xd.sort() uf = UnionFind(N) cost = 0 merged_cnt = 0 for d1, c1, c2 in xd: if not uf.same(c1, c2): uf.union(c1, c2) cost += d1 merged_cnt += 1 if merged_cnt == N - 1: break print(cost) if __name__ == "__main__": main()
"""Minimum spanning tree with Kruskal's algorithm""" import sys class UnionFind: def __init__(self, n): # total number of nodes. self.n = n # node id -> root node id self._root_table = list(range(n)) # root node id -> group size self._size_table = [1] * n def find(self, x): """Returns x's root node id.""" r = self._root_table[x] if r != x: # Update the cache on query. r = self._root_table[x] = self.find(r) return r def union(self, x, y): """Merges two groups.""" x = self.find(x) y = self.find(y) if x == y: return # Ensure that x is the larger (or equal) group. if self._size_table[x] < self._size_table[y]: x, y = y, x self._size_table[x] += self._size_table[y] self._root_table[y] = x def size(self, x): return self._size_table[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self._root_table) if x == i] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) input = sys.stdin.readline def main(): N = int(eval(input())) cities, xs, ys = [], [], [] for i in range(N): x, y = list(map(int, input().split())) cities.append((x, y)) xs.append((x, i)) ys.append((y, i)) xs.sort() ys.sort() xd, yd = [], [] for i in range(1, N): x1, c1 = xs[i - 1] x2, c2 = xs[i] if x2 - x1 <= abs(cities[c1][1] - cities[c2][1]): xd.append((x2 - x1, c1, c2)) y1, c1 = ys[i - 1] y2, c2 = ys[i] if y2 - y1 < abs(cities[c1][0] - cities[c2][0]): xd.append((y2 - y1, c1, c2)) xd.sort() uf = UnionFind(N) cost = 0 merged_cnt = 0 for d1, c1, c2 in xd: if not uf.same(c1, c2): uf.union(c1, c2) cost += d1 merged_cnt += 1 if merged_cnt == N - 1: break print(cost) if __name__ == "__main__": main()
98
99
2,495
2,549
import sys class UnionFind: def __init__(self, n): # total number of nodes. self.n = n # node id -> root node id self._root_table = list(range(n)) # root node id -> group size self._size_table = [1] * n def find(self, x): """Returns x's root node id.""" r = self._root_table[x] if r != x: # Update the cache on query. r = self._root_table[x] = self.find(r) return r def union(self, x, y): """Merges two groups.""" x = self.find(x) y = self.find(y) if x == y: return # Ensure that x is the larger (or equal) group. if self._size_table[x] < self._size_table[y]: x, y = y, x self._size_table[x] += self._size_table[y] self._root_table[y] = x def size(self, x): return self._size_table[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self._root_table) if x == i] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) input = sys.stdin.readline def main(): N = int(eval(input())) cities, xs, ys = [], [], [] for i in range(N): x, y = list(map(int, input().split())) cities.append((x, y)) xs.append((x, i)) ys.append((y, i)) xs.sort() ys.sort() xd, yd = [], [] for i in range(1, N): x1, c1 = xs[i - 1] x2, c2 = xs[i] if x2 - x1 <= abs(cities[c1][1] - cities[c2][1]): xd.append((x2 - x1, c1, c2)) y1, c1 = ys[i - 1] y2, c2 = ys[i] if y2 - y1 < abs(cities[c1][0] - cities[c2][0]): xd.append((y2 - y1, c1, c2)) xd.sort() uf = UnionFind(N) cost = 0 merged_cnt = 0 for d1, c1, c2 in xd: if not uf.same(c1, c2): uf.union(c1, c2) cost += d1 merged_cnt += 1 if merged_cnt == N - 1: break print(cost) if __name__ == "__main__": main()
"""Minimum spanning tree with Kruskal's algorithm""" import sys class UnionFind: def __init__(self, n): # total number of nodes. self.n = n # node id -> root node id self._root_table = list(range(n)) # root node id -> group size self._size_table = [1] * n def find(self, x): """Returns x's root node id.""" r = self._root_table[x] if r != x: # Update the cache on query. r = self._root_table[x] = self.find(r) return r def union(self, x, y): """Merges two groups.""" x = self.find(x) y = self.find(y) if x == y: return # Ensure that x is the larger (or equal) group. if self._size_table[x] < self._size_table[y]: x, y = y, x self._size_table[x] += self._size_table[y] self._root_table[y] = x def size(self, x): return self._size_table[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self._root_table) if x == i] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) input = sys.stdin.readline def main(): N = int(eval(input())) cities, xs, ys = [], [], [] for i in range(N): x, y = list(map(int, input().split())) cities.append((x, y)) xs.append((x, i)) ys.append((y, i)) xs.sort() ys.sort() xd, yd = [], [] for i in range(1, N): x1, c1 = xs[i - 1] x2, c2 = xs[i] if x2 - x1 <= abs(cities[c1][1] - cities[c2][1]): xd.append((x2 - x1, c1, c2)) y1, c1 = ys[i - 1] y2, c2 = ys[i] if y2 - y1 < abs(cities[c1][0] - cities[c2][0]): xd.append((y2 - y1, c1, c2)) xd.sort() uf = UnionFind(N) cost = 0 merged_cnt = 0 for d1, c1, c2 in xd: if not uf.same(c1, c2): uf.union(c1, c2) cost += d1 merged_cnt += 1 if merged_cnt == N - 1: break print(cost) if __name__ == "__main__": main()
false
1.010101
[ "+\"\"\"Minimum spanning tree with Kruskal's algorithm\"\"\"" ]
false
0.041378
0.038403
1.077457
[ "s128814384", "s694618162" ]
u079022693
p03044
python
s236244882
s294932037
571
478
43,924
43,924
Accepted
Accepted
16.29
from sys import stdin from collections import deque def main(): #入力 readline=stdin.readline N=int(readline()) g=[[] for _ in range(N)] for _ in range(N-1): u,v,w=list(map(int,readline().split())) u-=1 v-=1 g[u].append((v,w)) g[v].append((u,w)) #0からの距離を幅優先探索 d=[0]*N is_searched=[False]*N is_searched[0]=True que=deque([0]) while len(que)>=1: now=que.popleft() for x in g[now]: if is_searched[x[0]]==False: is_searched[x[0]]=True d[x[0]]=d[now]+x[1] que.append(x[0]) for x in d: if x%2==0: print((0)) else: print((1)) if __name__=="__main__": main()
from sys import stdin from collections import deque def main(): #入力 readline=stdin.readline n=int(readline()) G=[[] for _ in range(n+1)] for _ in range(n-1): u,v,w=list(map(int,readline().split())) G[u].append((v,w)) G[v].append((u,w)) d=[0]*(n+1) flags=[False]*(n+1) flags[1]=True q=deque([1]) while len(q)>0: now=q.popleft() for nex in G[now]: if flags[nex[0]]==False: flags[nex[0]]=True q.append(nex[0]) d[nex[0]]=d[now]+nex[1] for i in range(1,n+1): if d[i]%2==0: print((0)) else: print((1)) if __name__=="__main__": main()
36
32
789
739
from sys import stdin from collections import deque def main(): # 入力 readline = stdin.readline N = int(readline()) g = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, readline().split())) u -= 1 v -= 1 g[u].append((v, w)) g[v].append((u, w)) # 0からの距離を幅優先探索 d = [0] * N is_searched = [False] * N is_searched[0] = True que = deque([0]) while len(que) >= 1: now = que.popleft() for x in g[now]: if is_searched[x[0]] == False: is_searched[x[0]] = True d[x[0]] = d[now] + x[1] que.append(x[0]) for x in d: if x % 2 == 0: print((0)) else: print((1)) if __name__ == "__main__": main()
from sys import stdin from collections import deque def main(): # 入力 readline = stdin.readline n = int(readline()) G = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v, w = list(map(int, readline().split())) G[u].append((v, w)) G[v].append((u, w)) d = [0] * (n + 1) flags = [False] * (n + 1) flags[1] = True q = deque([1]) while len(q) > 0: now = q.popleft() for nex in G[now]: if flags[nex[0]] == False: flags[nex[0]] = True q.append(nex[0]) d[nex[0]] = d[now] + nex[1] for i in range(1, n + 1): if d[i] % 2 == 0: print((0)) else: print((1)) if __name__ == "__main__": main()
false
11.111111
[ "- N = int(readline())", "- g = [[] for _ in range(N)]", "- for _ in range(N - 1):", "+ n = int(readline())", "+ G = [[] for _ in range(n + 1)]", "+ for _ in range(n - 1):", "- u -= 1", "- v -= 1", "- g[u].append((v, w))", "- g[v].append((u, w))", "- # 0からの距離を幅優先探索", "- d = [0] * N", "- is_searched = [False] * N", "- is_searched[0] = True", "- que = deque([0])", "- while len(que) >= 1:", "- now = que.popleft()", "- for x in g[now]:", "- if is_searched[x[0]] == False:", "- is_searched[x[0]] = True", "- d[x[0]] = d[now] + x[1]", "- que.append(x[0])", "- for x in d:", "- if x % 2 == 0:", "+ G[u].append((v, w))", "+ G[v].append((u, w))", "+ d = [0] * (n + 1)", "+ flags = [False] * (n + 1)", "+ flags[1] = True", "+ q = deque([1])", "+ while len(q) > 0:", "+ now = q.popleft()", "+ for nex in G[now]:", "+ if flags[nex[0]] == False:", "+ flags[nex[0]] = True", "+ q.append(nex[0])", "+ d[nex[0]] = d[now] + nex[1]", "+ for i in range(1, n + 1):", "+ if d[i] % 2 == 0:" ]
false
0.046267
0.050873
0.90947
[ "s236244882", "s294932037" ]
u235376569
p02725
python
s728234773
s323605224
235
175
26,444
24,948
Accepted
Accepted
25.53
K,N=[int(x) for x in input().rstrip().split()] A=[int(x) for x in input().rstrip().split()] flag=1 now=0 mae=[] back=[] for i in range(N-1): mae.append(A[i+1]-A[i]) mae.append(A[len(A)-1]-A[0]) for i in range(N-1,0,-1): back.append(A[i]-A[i-1]) back.append(abs(A[0])+abs(K-A[N-1])) back.sort() mae.sort() ans=min(sum(mae[:len(mae)-1]),sum(back[:len(back)-1])) print(ans)
K,N=[int(x) for x in input().rstrip().split()] A=[int(x) for x in input().rstrip().split()] A14=K-A[N-1]+A[0] sa=[A14] for i in range(N-1): sa.append(A[i+1]-A[i]) sa.sort() ans=0 for i in range(N-1): ans+=sa[i] print(ans)
19
13
395
239
K, N = [int(x) for x in input().rstrip().split()] A = [int(x) for x in input().rstrip().split()] flag = 1 now = 0 mae = [] back = [] for i in range(N - 1): mae.append(A[i + 1] - A[i]) mae.append(A[len(A) - 1] - A[0]) for i in range(N - 1, 0, -1): back.append(A[i] - A[i - 1]) back.append(abs(A[0]) + abs(K - A[N - 1])) back.sort() mae.sort() ans = min(sum(mae[: len(mae) - 1]), sum(back[: len(back) - 1])) print(ans)
K, N = [int(x) for x in input().rstrip().split()] A = [int(x) for x in input().rstrip().split()] A14 = K - A[N - 1] + A[0] sa = [A14] for i in range(N - 1): sa.append(A[i + 1] - A[i]) sa.sort() ans = 0 for i in range(N - 1): ans += sa[i] print(ans)
false
31.578947
[ "-flag = 1", "-now = 0", "-mae = []", "-back = []", "+A14 = K - A[N - 1] + A[0]", "+sa = [A14]", "- mae.append(A[i + 1] - A[i])", "-mae.append(A[len(A) - 1] - A[0])", "-for i in range(N - 1, 0, -1):", "- back.append(A[i] - A[i - 1])", "-back.append(abs(A[0]) + abs(K - A[N - 1]))", "-back.sort()", "-mae.sort()", "-ans = min(sum(mae[: len(mae) - 1]), sum(back[: len(back) - 1]))", "+ sa.append(A[i + 1] - A[i])", "+sa.sort()", "+ans = 0", "+for i in range(N - 1):", "+ ans += sa[i]" ]
false
0.068919
0.042897
1.606641
[ "s728234773", "s323605224" ]
u554133763
p02689
python
s654582434
s082641905
430
259
86,240
20,052
Accepted
Accepted
39.77
n, m= list(map(int, input().split())) high = list(map(int, input().split())) ans = [1]*n for i in range(m): a, b = list(map(int, input().split())) if high[a-1] > high[b-1]: ans[b-1] = 0 elif high[a-1] < high[b-1]: ans[a-1] = 0 else: ans[a-1] = 0 ans[b-1] = 0 print((sum(ans)))
n, m= list(map(int, input().split())) high = list(map(int, input().split())) ans = [0]*n for i in range(m): a,b = list(map(int, input().split())) if high[a-1] > high[b-1]: if ans[a-1] == 0: ans[a-1] = 1 ans[b-1] = -1 elif high[a-1] < high[b-1]: if ans[b-1] == 0: ans[b-1] = 1 ans[a-1] = -1 else: ans[b-1] = -1 ans[a-1] = -1 print((ans.count(0) + ans.count(1)))
14
18
324
453
n, m = list(map(int, input().split())) high = list(map(int, input().split())) ans = [1] * n for i in range(m): a, b = list(map(int, input().split())) if high[a - 1] > high[b - 1]: ans[b - 1] = 0 elif high[a - 1] < high[b - 1]: ans[a - 1] = 0 else: ans[a - 1] = 0 ans[b - 1] = 0 print((sum(ans)))
n, m = list(map(int, input().split())) high = list(map(int, input().split())) ans = [0] * n for i in range(m): a, b = list(map(int, input().split())) if high[a - 1] > high[b - 1]: if ans[a - 1] == 0: ans[a - 1] = 1 ans[b - 1] = -1 elif high[a - 1] < high[b - 1]: if ans[b - 1] == 0: ans[b - 1] = 1 ans[a - 1] = -1 else: ans[b - 1] = -1 ans[a - 1] = -1 print((ans.count(0) + ans.count(1)))
false
22.222222
[ "-ans = [1] * n", "+ans = [0] * n", "- ans[b - 1] = 0", "+ if ans[a - 1] == 0:", "+ ans[a - 1] = 1", "+ ans[b - 1] = -1", "- ans[a - 1] = 0", "+ if ans[b - 1] == 0:", "+ ans[b - 1] = 1", "+ ans[a - 1] = -1", "- ans[a - 1] = 0", "- ans[b - 1] = 0", "-print((sum(ans)))", "+ ans[b - 1] = -1", "+ ans[a - 1] = -1", "+print((ans.count(0) + ans.count(1)))" ]
false
0.047307
0.037455
1.263053
[ "s654582434", "s082641905" ]
u075595666
p03450
python
s415859802
s611906430
1,296
811
9,068
9,288
Accepted
Accepted
37.42
#重み付きUnion-Find #xの根を求める def find(x): if par[x] < 0: return x else: px = find(par[x]) wei[x] += wei[par[x]] par[x] = px return px #xの根から距離 def weight(x): find(x) return wei[x] #w[y]=w[x]+wとなるようにxとyを併合 def unite(x,y,w): w += wei[x]-wei[y] x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x w = -w par[x] += par[y] par[y] = x wei[y] = w return True #xとyが同じ集合に属するかの判定 def same(x,y): return find(x) == find(y) #x,yが同じ集合に属するときのwei[y]-wei[x] def diff(x,y): return weight(y)-weight(x) n,m = [int(i) for i in input().split()] par = [-1]*n wei = [0]*n for i in range(m): l,r,d = [int(i) for i in input().split()] if not same(l-1,r-1): unite(l-1,r-1,d) else: if diff(l-1,r-1) == d: continue else: print('No') exit() print('Yes')
#重み付きUnion-Find #xの根を求める def find(x): if par[x] < 0: return x else: px = find(par[x]) wei[x] += wei[par[x]] par[x] = px return px #xの根から距離 def weight(x): find(x) return wei[x] #w[y]=w[x]+wとなるようにxとyを併合 def unite(x,y,w): w += wei[x]-wei[y] x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x w = -w par[x] += par[y] par[y] = x wei[y] = w return True #xとyが同じ集合に属するかの判定 def same(x,y): return find(x) == find(y) #x,yが同じ集合に属するときのwei[y]-wei[x] def diff(x,y): return weight(y)-weight(x) import sys input = sys.stdin.readline n,m = [int(i) for i in input().split()] par = [-1]*n wei = [0]*n for i in range(m): l,r,d = [int(i) for i in input().split()] if not same(l-1,r-1): unite(l-1,r-1,d) else: if diff(l-1,r-1) == d: continue else: print('No') exit() print('Yes')
60
62
1,040
1,082
# 重み付きUnion-Find # xの根を求める def find(x): if par[x] < 0: return x else: px = find(par[x]) wei[x] += wei[par[x]] par[x] = px return px # xの根から距離 def weight(x): find(x) return wei[x] # w[y]=w[x]+wとなるようにxとyを併合 def unite(x, y, w): w += wei[x] - wei[y] x = find(x) y = find(y) if x == y: return False else: # sizeの大きいほうがx if par[x] > par[y]: x, y = y, x w = -w par[x] += par[y] par[y] = x wei[y] = w return True # xとyが同じ集合に属するかの判定 def same(x, y): return find(x) == find(y) # x,yが同じ集合に属するときのwei[y]-wei[x] def diff(x, y): return weight(y) - weight(x) n, m = [int(i) for i in input().split()] par = [-1] * n wei = [0] * n for i in range(m): l, r, d = [int(i) for i in input().split()] if not same(l - 1, r - 1): unite(l - 1, r - 1, d) else: if diff(l - 1, r - 1) == d: continue else: print("No") exit() print("Yes")
# 重み付きUnion-Find # xの根を求める def find(x): if par[x] < 0: return x else: px = find(par[x]) wei[x] += wei[par[x]] par[x] = px return px # xの根から距離 def weight(x): find(x) return wei[x] # w[y]=w[x]+wとなるようにxとyを併合 def unite(x, y, w): w += wei[x] - wei[y] x = find(x) y = find(y) if x == y: return False else: # sizeの大きいほうがx if par[x] > par[y]: x, y = y, x w = -w par[x] += par[y] par[y] = x wei[y] = w return True # xとyが同じ集合に属するかの判定 def same(x, y): return find(x) == find(y) # x,yが同じ集合に属するときのwei[y]-wei[x] def diff(x, y): return weight(y) - weight(x) import sys input = sys.stdin.readline n, m = [int(i) for i in input().split()] par = [-1] * n wei = [0] * n for i in range(m): l, r, d = [int(i) for i in input().split()] if not same(l - 1, r - 1): unite(l - 1, r - 1, d) else: if diff(l - 1, r - 1) == d: continue else: print("No") exit() print("Yes")
false
3.225806
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.048207
0.213586
0.225705
[ "s415859802", "s611906430" ]
u223663729
p03045
python
s845444504
s928097080
611
194
119,292
40,068
Accepted
Accepted
68.25
class UnionFind: def __init__(self, n=0): self.d = [-1]*n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False self.u -= 1 if x > y: x, y = y, x self.d[x] += self.d[y] self.d[y] = x return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.d[self.root(x)] def num_union(self): return self.u N, M, *X = list(map(int, open(0).read().split())) X = tuple(zip(*[iter(X)]*3)) uf = UnionFind(N) for x, y, z in X: uf.unite(x-1, y-1) print((uf.num_union()))
N, M, *X = list(map(int, open(0).read().split())) class UnionFind: def __init__(self, n=0): self.d = [-1]*n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False if x > y: x, y = y, x self.d[x] += self.d[y] self.d[y] = x self.u -= 1 return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.d[self.root(x)] def num_union(self): return self.u u = UnionFind(N) for x, y, z in zip(*[iter(X)]*3): u.unite(x-1, y-1) print((u.num_union()))
43
39
858
835
class UnionFind: def __init__(self, n=0): self.d = [-1] * n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False self.u -= 1 if x > y: x, y = y, x self.d[x] += self.d[y] self.d[y] = x return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.d[self.root(x)] def num_union(self): return self.u N, M, *X = list(map(int, open(0).read().split())) X = tuple(zip(*[iter(X)] * 3)) uf = UnionFind(N) for x, y, z in X: uf.unite(x - 1, y - 1) print((uf.num_union()))
N, M, *X = list(map(int, open(0).read().split())) class UnionFind: def __init__(self, n=0): self.d = [-1] * n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False if x > y: x, y = y, x self.d[x] += self.d[y] self.d[y] = x self.u -= 1 return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.d[self.root(x)] def num_union(self): return self.u u = UnionFind(N) for x, y, z in zip(*[iter(X)] * 3): u.unite(x - 1, y - 1) print((u.num_union()))
false
9.302326
[ "+N, M, *X = list(map(int, open(0).read().split()))", "+", "+", "- self.u -= 1", "+ self.u -= 1", "-N, M, *X = list(map(int, open(0).read().split()))", "-X = tuple(zip(*[iter(X)] * 3))", "-uf = UnionFind(N)", "-for x, y, z in X:", "- uf.unite(x - 1, y - 1)", "-print((uf.num_union()))", "+u = UnionFind(N)", "+for x, y, z in zip(*[iter(X)] * 3):", "+ u.unite(x - 1, y - 1)", "+print((u.num_union()))" ]
false
0.037319
0.037029
1.00785
[ "s845444504", "s928097080" ]
u553605501
p02614
python
s798579324
s576691531
191
159
74,880
76,884
Accepted
Accepted
16.75
import itertools import copy h,w,k=list(map(int,input().split())) c=[list(eval(input())) for _ in range(h)] num=0 for i in range(h): for j in range(w): if c[i][j]=='#': num+=1 ans=0 for a in range(1,h+1): for b in range(1,w+1): l=list(range(1,h+1)) m=list(range(1,w+1)) for p in itertools.combinations(l, a): for q in itertools.combinations(m, b): sum=0 d=copy.deepcopy(c) for i in p: for j in q: for s in range(w): if d[i-1][s]=='#': sum+=1 d[i-1][s]='.' for t in range(h): if d[t][j-1]=='#': sum+=1 d[t][j-1]='.' if num-sum==k: ans+=1 for a in range(1,h+1): l=list(range(1,h+1)) for p in itertools.combinations(l, a): sum=0 d=copy.deepcopy(c) for i in p: for s in range(w): if d[i-1][s]=='#': sum+=1 d[i-1][s]='.' if num-sum==k: ans+=1 for b in range(1,w+1): m=list(range(1,w+1)) for q in itertools.combinations(m, b): sum=0 d=copy.deepcopy(c) for j in q: for t in range(h): if d[t][j-1]=='#': sum+=1 d[t][j-1]='.' if num-sum==k: ans+=1 if num==k: ans+=1 print(ans)
import copy h,w,k = list(map(int,input().split())) c=[list(eval(input())) for _ in range(h)] ans = 0 for row in range(1<<h): for col in range(1<<w): d = copy.deepcopy(c) sum = 0 for i in range(h): if row & (1<<i): for j in range(w): d[i][j] = '.' for j in range(w): if col & (1<<j): for i in range(h): d[i][j] = '.' for i in range(h): for j in range(w): if d[i][j] == '#': sum+=1 if sum == k: ans+=1 print(ans)
57
28
1,720
643
import itertools import copy h, w, k = list(map(int, input().split())) c = [list(eval(input())) for _ in range(h)] num = 0 for i in range(h): for j in range(w): if c[i][j] == "#": num += 1 ans = 0 for a in range(1, h + 1): for b in range(1, w + 1): l = list(range(1, h + 1)) m = list(range(1, w + 1)) for p in itertools.combinations(l, a): for q in itertools.combinations(m, b): sum = 0 d = copy.deepcopy(c) for i in p: for j in q: for s in range(w): if d[i - 1][s] == "#": sum += 1 d[i - 1][s] = "." for t in range(h): if d[t][j - 1] == "#": sum += 1 d[t][j - 1] = "." if num - sum == k: ans += 1 for a in range(1, h + 1): l = list(range(1, h + 1)) for p in itertools.combinations(l, a): sum = 0 d = copy.deepcopy(c) for i in p: for s in range(w): if d[i - 1][s] == "#": sum += 1 d[i - 1][s] = "." if num - sum == k: ans += 1 for b in range(1, w + 1): m = list(range(1, w + 1)) for q in itertools.combinations(m, b): sum = 0 d = copy.deepcopy(c) for j in q: for t in range(h): if d[t][j - 1] == "#": sum += 1 d[t][j - 1] = "." if num - sum == k: ans += 1 if num == k: ans += 1 print(ans)
import copy h, w, k = list(map(int, input().split())) c = [list(eval(input())) for _ in range(h)] ans = 0 for row in range(1 << h): for col in range(1 << w): d = copy.deepcopy(c) sum = 0 for i in range(h): if row & (1 << i): for j in range(w): d[i][j] = "." for j in range(w): if col & (1 << j): for i in range(h): d[i][j] = "." for i in range(h): for j in range(w): if d[i][j] == "#": sum += 1 if sum == k: ans += 1 print(ans)
false
50.877193
[ "-import itertools", "-num = 0", "-for i in range(h):", "- for j in range(w):", "- if c[i][j] == \"#\":", "- num += 1", "-for a in range(1, h + 1):", "- for b in range(1, w + 1):", "- l = list(range(1, h + 1))", "- m = list(range(1, w + 1))", "- for p in itertools.combinations(l, a):", "- for q in itertools.combinations(m, b):", "- sum = 0", "- d = copy.deepcopy(c)", "- for i in p:", "- for j in q:", "- for s in range(w):", "- if d[i - 1][s] == \"#\":", "- sum += 1", "- d[i - 1][s] = \".\"", "- for t in range(h):", "- if d[t][j - 1] == \"#\":", "- sum += 1", "- d[t][j - 1] = \".\"", "- if num - sum == k:", "- ans += 1", "-for a in range(1, h + 1):", "- l = list(range(1, h + 1))", "- for p in itertools.combinations(l, a):", "+for row in range(1 << h):", "+ for col in range(1 << w):", "+ d = copy.deepcopy(c)", "- d = copy.deepcopy(c)", "- for i in p:", "- for s in range(w):", "- if d[i - 1][s] == \"#\":", "+ for i in range(h):", "+ if row & (1 << i):", "+ for j in range(w):", "+ d[i][j] = \".\"", "+ for j in range(w):", "+ if col & (1 << j):", "+ for i in range(h):", "+ d[i][j] = \".\"", "+ for i in range(h):", "+ for j in range(w):", "+ if d[i][j] == \"#\":", "- d[i - 1][s] = \".\"", "- if num - sum == k:", "+ if sum == k:", "-for b in range(1, w + 1):", "- m = list(range(1, w + 1))", "- for q in itertools.combinations(m, b):", "- sum = 0", "- d = copy.deepcopy(c)", "- for j in q:", "- for t in range(h):", "- if d[t][j - 1] == \"#\":", "- sum += 1", "- d[t][j - 1] = \".\"", "- if num - sum == k:", "- ans += 1", "-if num == k:", "- ans += 1" ]
false
0.048235
0.047758
1.009988
[ "s798579324", "s576691531" ]
u623231048
p03166
python
s177838628
s672197414
1,113
975
33,660
22,704
Accepted
Accepted
12.4
import sys input = sys.stdin.readline n,m = list(map(int,input().split())) edges = [[] for _ in range(n)] edges2 = [[] for _ in range(n)] dis = [0] * n for _ in range(m): x,y = list(map(int,input().split())) edges[y-1].append(x-1) edges2[x-1].append(y-1) dis[x-1] = -1 q = [] for i in range(n): if dis[i] == 0: q.append(i) while q: l = q.pop(0) for i in edges[l]: dis[i] = max(dis[i], dis[l] + 1) edges2[i].remove(l) if not edges2[i]: q.append(i) print((max(dis)))
import sys input = sys.stdin.readline n,m = list(map(int,input().split())) edges = [[] for _ in range(n)] edges2 = [0] * n dis = [0] * n for _ in range(m): x,y = list(map(int,input().split())) edges[y-1].append(x-1) edges2[x-1] += 1 dis[x-1] = -1 q = [] for i in range(n): if dis[i] == 0: q.append(i) while q: l = q.pop(0) for i in edges[l]: dis[i] = max(dis[i], dis[l] + 1) edges2[i] -= 1 if edges2[i] == 0: q.append(i) print((max(dis)))
30
30
559
533
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] edges2 = [[] for _ in range(n)] dis = [0] * n for _ in range(m): x, y = list(map(int, input().split())) edges[y - 1].append(x - 1) edges2[x - 1].append(y - 1) dis[x - 1] = -1 q = [] for i in range(n): if dis[i] == 0: q.append(i) while q: l = q.pop(0) for i in edges[l]: dis[i] = max(dis[i], dis[l] + 1) edges2[i].remove(l) if not edges2[i]: q.append(i) print((max(dis)))
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] edges2 = [0] * n dis = [0] * n for _ in range(m): x, y = list(map(int, input().split())) edges[y - 1].append(x - 1) edges2[x - 1] += 1 dis[x - 1] = -1 q = [] for i in range(n): if dis[i] == 0: q.append(i) while q: l = q.pop(0) for i in edges[l]: dis[i] = max(dis[i], dis[l] + 1) edges2[i] -= 1 if edges2[i] == 0: q.append(i) print((max(dis)))
false
0
[ "-edges2 = [[] for _ in range(n)]", "+edges2 = [0] * n", "- edges2[x - 1].append(y - 1)", "+ edges2[x - 1] += 1", "- edges2[i].remove(l)", "- if not edges2[i]:", "+ edges2[i] -= 1", "+ if edges2[i] == 0:" ]
false
0.037923
0.038128
0.99463
[ "s177838628", "s672197414" ]
u191874006
p02841
python
s452945333
s499374400
173
71
38,384
65,508
Accepted
Accepted
58.96
#!/usr/bin/env python3 #三井住友信託銀行プログラミングコンテスト2019 A import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) m1,d1 = LI() m2,d2 = LI() if m1 == m2: print((0)) else: print((1))
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) m1, d1 = LI() m2, d2 = LI() if m1 != m2: print((1)) else: print((0))
26
25
662
637
#!/usr/bin/env python3 # 三井住友信託銀行プログラミングコンテスト2019 A import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) m1, d1 = LI() m2, d2 = LI() if m1 == m2: print((0)) else: print((1))
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) m1, d1 = LI() m2, d2 = LI() if m1 != m2: print((1)) else: print((0))
false
3.846154
[ "-# 三井住友信託銀行プログラミングコンテスト2019 A", "-sys.setrecursionlimit(1000000)", "+sys.setrecursionlimit(2147483647)", "-if m1 == m2:", "+if m1 != m2:", "+ print((1))", "+else:", "-else:", "- print((1))" ]
false
0.068838
0.046307
1.486548
[ "s452945333", "s499374400" ]
u017415492
p02873
python
s510069532
s143925478
423
279
23,336
29,168
Accepted
Accepted
34.04
s=eval(input()) d=[0]*(len(s)+1) Z=[] scount=0 ans=0 if s[0]=="<": d[1]=d[0]+1 for i in range(1,len(s)-1): if s[i]==">": d[i+1]=0 scount+=1 Q=scount X=i if s[i-1]=="<": Z.append(i) elif s[i]=="<": d[i+1]=d[i]+1 for j in range(scount): d[i-scount+j]=(scount-j) scount=0 if s[-1]==">": d[-1]=0 scount+=1 Q=scount X=len(s)-1 if scount>0: for j in range(scount): d[X-scount+j+1]=Q Q-=1 for i in Z: d[i]=max(d[i+1]+1,d[i-1]+1) if i==0 and s[0]=="<": d[i]=0 if s[-1]=="<": d[-1]=d[-2]+1 if s[0]==">": d[0]=d[1]+1 print((sum(d)))
s=eval(input()) n=len(s) ans=[0]*(n+1) for i in range(0,n): if s[i]=='<': ans[i+1]=ans[i]+1 for i in range(n-1,-1,-1): if s[i]=='>': ans[i]=max(ans[i+1]+1,ans[i]) print((sum(ans)))
41
11
641
197
s = eval(input()) d = [0] * (len(s) + 1) Z = [] scount = 0 ans = 0 if s[0] == "<": d[1] = d[0] + 1 for i in range(1, len(s) - 1): if s[i] == ">": d[i + 1] = 0 scount += 1 Q = scount X = i if s[i - 1] == "<": Z.append(i) elif s[i] == "<": d[i + 1] = d[i] + 1 for j in range(scount): d[i - scount + j] = scount - j scount = 0 if s[-1] == ">": d[-1] = 0 scount += 1 Q = scount X = len(s) - 1 if scount > 0: for j in range(scount): d[X - scount + j + 1] = Q Q -= 1 for i in Z: d[i] = max(d[i + 1] + 1, d[i - 1] + 1) if i == 0 and s[0] == "<": d[i] = 0 if s[-1] == "<": d[-1] = d[-2] + 1 if s[0] == ">": d[0] = d[1] + 1 print((sum(d)))
s = eval(input()) n = len(s) ans = [0] * (n + 1) for i in range(0, n): if s[i] == "<": ans[i + 1] = ans[i] + 1 for i in range(n - 1, -1, -1): if s[i] == ">": ans[i] = max(ans[i + 1] + 1, ans[i]) print((sum(ans)))
false
73.170732
[ "-d = [0] * (len(s) + 1)", "-Z = []", "-scount = 0", "-ans = 0", "-if s[0] == \"<\":", "- d[1] = d[0] + 1", "-for i in range(1, len(s) - 1):", "+n = len(s)", "+ans = [0] * (n + 1)", "+for i in range(0, n):", "+ if s[i] == \"<\":", "+ ans[i + 1] = ans[i] + 1", "+for i in range(n - 1, -1, -1):", "- d[i + 1] = 0", "- scount += 1", "- Q = scount", "- X = i", "- if s[i - 1] == \"<\":", "- Z.append(i)", "- elif s[i] == \"<\":", "- d[i + 1] = d[i] + 1", "- for j in range(scount):", "- d[i - scount + j] = scount - j", "- scount = 0", "-if s[-1] == \">\":", "- d[-1] = 0", "- scount += 1", "- Q = scount", "- X = len(s) - 1", "-if scount > 0:", "- for j in range(scount):", "- d[X - scount + j + 1] = Q", "- Q -= 1", "-for i in Z:", "- d[i] = max(d[i + 1] + 1, d[i - 1] + 1)", "- if i == 0 and s[0] == \"<\":", "- d[i] = 0", "-if s[-1] == \"<\":", "- d[-1] = d[-2] + 1", "-if s[0] == \">\":", "- d[0] = d[1] + 1", "-print((sum(d)))", "+ ans[i] = max(ans[i + 1] + 1, ans[i])", "+print((sum(ans)))" ]
false
0.04583
0.039561
1.158464
[ "s510069532", "s143925478" ]
u633068244
p00631
python
s230676743
s418442068
130
70
4,236
4,244
Accepted
Accepted
46.15
def S(i,x,y): d=2*max(x,y)-sum(a) return d if d>=0 else min(S(i+1,x+a[i],y),S(i+1,x,y+a[i])) while 1: if eval(input())==0:break a=sorted(map(int,input().split()))[::-1] print(S(1,a[0],0))
def S(i,x,y): if 2*x >= A: return 2*x-A if 2*y >= A: return 2*y-A return min(S(i+1,x+a[i],y),S(i+1,x,y+a[i])) while 1: n = eval(input()) if n == 0: break a = sorted(map(int,input().split()))[::-1] A = sum(a) print(S(1,a[0],0))
7
10
195
240
def S(i, x, y): d = 2 * max(x, y) - sum(a) return d if d >= 0 else min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i])) while 1: if eval(input()) == 0: break a = sorted(map(int, input().split()))[::-1] print(S(1, a[0], 0))
def S(i, x, y): if 2 * x >= A: return 2 * x - A if 2 * y >= A: return 2 * y - A return min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i])) while 1: n = eval(input()) if n == 0: break a = sorted(map(int, input().split()))[::-1] A = sum(a) print(S(1, a[0], 0))
false
30
[ "- d = 2 * max(x, y) - sum(a)", "- return d if d >= 0 else min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i]))", "+ if 2 * x >= A:", "+ return 2 * x - A", "+ if 2 * y >= A:", "+ return 2 * y - A", "+ return min(S(i + 1, x + a[i], y), S(i + 1, x, y + a[i]))", "- if eval(input()) == 0:", "+ n = eval(input())", "+ if n == 0:", "+ A = sum(a)" ]
false
0.044013
0.037963
1.159363
[ "s230676743", "s418442068" ]
u191874006
p02607
python
s488226737
s509565919
126
65
65,356
61,816
Accepted
Accepted
48.41
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n = I() a = LI() ans = 0 for i in range(n): if (i+1) % 2: if a[i] % 2: ans += 1 print(ans)
#!/usr/bin/env python3 n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(0, n, 2): if a[i] % 2: ans += 1 print(ans)
27
9
681
162
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) n = I() a = LI() ans = 0 for i in range(n): if (i + 1) % 2: if a[i] % 2: ans += 1 print(ans)
#!/usr/bin/env python3 n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(0, n, 2): if a[i] % 2: ans += 1 print(ans)
false
66.666667
[ "-import sys", "-import math", "-from bisect import bisect_right as br", "-from bisect import bisect_left as bl", "-", "-sys.setrecursionlimit(2147483647)", "-from heapq import heappush, heappop, heappushpop", "-from collections import defaultdict", "-from itertools import accumulate", "-from collections import Counter", "-from collections import deque", "-from operator import itemgetter", "-from itertools import permutations", "-", "-mod = 10**9 + 7", "-inf = float(\"inf\")", "-", "-", "-def I():", "- return int(sys.stdin.readline())", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().split()))", "-", "-", "-n = I()", "-a = LI()", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "-for i in range(n):", "- if (i + 1) % 2:", "- if a[i] % 2:", "- ans += 1", "+for i in range(0, n, 2):", "+ if a[i] % 2:", "+ ans += 1" ]
false
0.045448
0.045755
0.993277
[ "s488226737", "s509565919" ]
u242580186
p02640
python
s204709103
s215174528
30
27
9,084
9,184
Accepted
Accepted
10
import sys import time st = time.perf_counter() # ------------------------------ x, y = map(int, input().split()) ok = False for i in range(x + 1): if i * 4 + (x - i) * 2 == y: ok = True break if ok: print('Yes') else: print('No') # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ X, Y = map(int, input().split()) for i in range(X+1): if i*4 + (X-i)*2 == Y: print('Yes') sys.exit() print('No') # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
19
18
376
382
import sys import time st = time.perf_counter() # ------------------------------ x, y = map(int, input().split()) ok = False for i in range(x + 1): if i * 4 + (x - i) * 2 == y: ok = True break if ok: print("Yes") else: print("No") # ------------------------------ ed = time.perf_counter() print("time:", ed - st, file=sys.stderr)
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ X, Y = map(int, input().split()) for i in range(X + 1): if i * 4 + (X - i) * 2 == Y: print("Yes") sys.exit() print("No") # ------------------------------ ed = time.perf_counter() print("time:", ed - st, file=sys.stderr)
false
5.263158
[ "+import math", "+", "+", "+def inpl():", "+ return list(map(int, input().split()))", "+", "-x, y = map(int, input().split())", "-ok = False", "-for i in range(x + 1):", "- if i * 4 + (x - i) * 2 == y:", "- ok = True", "- break", "-if ok:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+X, Y = map(int, input().split())", "+for i in range(X + 1):", "+ if i * 4 + (X - i) * 2 == Y:", "+ print(\"Yes\")", "+ sys.exit()", "+print(\"No\")" ]
false
0.038557
0.04378
0.880696
[ "s204709103", "s215174528" ]
u357751375
p03474
python
s555254600
s763533589
30
27
9,132
9,116
Accepted
Accepted
10
a,b = list(map(int,input().split())) s = eval(input()) for i in range(a): if s[i] == '-': print('No') exit(0) if s[a] != '-': print('No') exit(0) for i in range(a+1,a+b): if s[i] == '-': print('No') exit(0) print('Yes')
a,b = list(map(int,input().split())) s = eval(input()) if '-' in s[:a]: print('No') elif s[a] != '-': print('No') elif '-' in s[a+1:]: print('No') else: print('Yes')
17
10
274
178
a, b = list(map(int, input().split())) s = eval(input()) for i in range(a): if s[i] == "-": print("No") exit(0) if s[a] != "-": print("No") exit(0) for i in range(a + 1, a + b): if s[i] == "-": print("No") exit(0) print("Yes")
a, b = list(map(int, input().split())) s = eval(input()) if "-" in s[:a]: print("No") elif s[a] != "-": print("No") elif "-" in s[a + 1 :]: print("No") else: print("Yes")
false
41.176471
[ "-for i in range(a):", "- if s[i] == \"-\":", "- print(\"No\")", "- exit(0)", "-if s[a] != \"-\":", "+if \"-\" in s[:a]:", "- exit(0)", "-for i in range(a + 1, a + b):", "- if s[i] == \"-\":", "- print(\"No\")", "- exit(0)", "-print(\"Yes\")", "+elif s[a] != \"-\":", "+ print(\"No\")", "+elif \"-\" in s[a + 1 :]:", "+ print(\"No\")", "+else:", "+ print(\"Yes\")" ]
false
0.038226
0.037779
1.011833
[ "s555254600", "s763533589" ]
u695261159
p03161
python
s732052895
s152474078
1,934
389
13,980
84,748
Accepted
Accepted
79.89
def main(): N,K=list(map(int, input().split())) A = list(map(int, input().split())) dp = [float('inf')] * N dp[0] = 0 for i in range(1,len(A)): jmp = max(0,i-K) dp[i] = min([dp[j]+abs(A[i]-A[j]) for j in range(jmp, i)]) print((dp[N-1])) main()
N,K=list(map(int, input().split())) A = list(map(int, input().split())) INF = 10**9 dp = [INF]*N for i in range(len(A)): if i == 0: dp[0] = 0 elif i == 1: dp[1] = abs(A[1]-A[0]) else: jmp = min(i,K) for j in range(1,jmp+1): dp[i] = min(dp[i], dp[i-j]+abs(A[i]-A[i-j])) print((dp[N-1]))
12
17
288
366
def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) dp = [float("inf")] * N dp[0] = 0 for i in range(1, len(A)): jmp = max(0, i - K) dp[i] = min([dp[j] + abs(A[i] - A[j]) for j in range(jmp, i)]) print((dp[N - 1])) main()
N, K = list(map(int, input().split())) A = list(map(int, input().split())) INF = 10**9 dp = [INF] * N for i in range(len(A)): if i == 0: dp[0] = 0 elif i == 1: dp[1] = abs(A[1] - A[0]) else: jmp = min(i, K) for j in range(1, jmp + 1): dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j])) print((dp[N - 1]))
false
29.411765
[ "-def main():", "- N, K = list(map(int, input().split()))", "- A = list(map(int, input().split()))", "- dp = [float(\"inf\")] * N", "- dp[0] = 0", "- for i in range(1, len(A)):", "- jmp = max(0, i - K)", "- dp[i] = min([dp[j] + abs(A[i] - A[j]) for j in range(jmp, i)])", "- print((dp[N - 1]))", "-", "-", "-main()", "+N, K = list(map(int, input().split()))", "+A = list(map(int, input().split()))", "+INF = 10**9", "+dp = [INF] * N", "+for i in range(len(A)):", "+ if i == 0:", "+ dp[0] = 0", "+ elif i == 1:", "+ dp[1] = abs(A[1] - A[0])", "+ else:", "+ jmp = min(i, K)", "+ for j in range(1, jmp + 1):", "+ dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))", "+print((dp[N - 1]))" ]
false
0.06117
0.061113
1.000931
[ "s732052895", "s152474078" ]
u426764965
p03557
python
s067604184
s756592679
323
242
24,932
20,468
Accepted
Accepted
25.08
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def abc077_c(): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) C = list(map(int, readline().split())) A.sort() B.sort() C.sort() ans = 0 from bisect import bisect_left # Bjに対するCの使える個数は、前処理で求めておく B2C = [0] * N # 真に大きいが条件なので Ai + 1 が入るポイントを探す for j in range(N): B2C[j] = N - bisect_left(C, B[j]+1) # 累積和 accum = [0] for j in range(N): accum.append(accum[-1] + B2C[j]) # Ai -> B は二分探索 for i in range(N): jst = bisect_left(B, A[i]+1) if jst == N: continue # 前処理済みなので、Bj以降を使ったときにCが何個使えるかはすぐわかる ans += accum[N] - accum[jst] print(ans) abc077_c()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def abc077_c(): ''' maspyさんお手本 ''' N = int(readline()) A = np.array(readline().split(), dtype=np.int64) B = np.array(readline().split(), dtype=np.int64) C = np.array(readline().split(), dtype=np.int64) A.sort() B.sort() C.sort() # 各Bに対して使えるAの個数 cnt_A = np.searchsorted(A, B, side='left') # 各Bに対して使えないCの個数 cnt_C_not = np.searchsorted(C, B, side='right') # 各Bに対して使えるCの個数 cnt_C = N - cnt_C_not # 別の書き方 # cnt_C_alt = np.searchsorted(-1 * np.flip(C), -1 * B, side='left') ans = np.multiply(cnt_A, cnt_C).sum() print(ans) abc077_c()
36
30
870
767
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def abc077_c(): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) C = list(map(int, readline().split())) A.sort() B.sort() C.sort() ans = 0 from bisect import bisect_left # Bjに対するCの使える個数は、前処理で求めておく B2C = [0] * N # 真に大きいが条件なので Ai + 1 が入るポイントを探す for j in range(N): B2C[j] = N - bisect_left(C, B[j] + 1) # 累積和 accum = [0] for j in range(N): accum.append(accum[-1] + B2C[j]) # Ai -> B は二分探索 for i in range(N): jst = bisect_left(B, A[i] + 1) if jst == N: continue # 前処理済みなので、Bj以降を使ったときにCが何個使えるかはすぐわかる ans += accum[N] - accum[jst] print(ans) abc077_c()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np def abc077_c(): """maspyさんお手本""" N = int(readline()) A = np.array(readline().split(), dtype=np.int64) B = np.array(readline().split(), dtype=np.int64) C = np.array(readline().split(), dtype=np.int64) A.sort() B.sort() C.sort() # 各Bに対して使えるAの個数 cnt_A = np.searchsorted(A, B, side="left") # 各Bに対して使えないCの個数 cnt_C_not = np.searchsorted(C, B, side="right") # 各Bに対して使えるCの個数 cnt_C = N - cnt_C_not # 別の書き方 # cnt_C_alt = np.searchsorted(-1 * np.flip(C), -1 * B, side='left') ans = np.multiply(cnt_A, cnt_C).sum() print(ans) abc077_c()
false
16.666667
[ "+import numpy as np", "+ \"\"\"maspyさんお手本\"\"\"", "- A = list(map(int, readline().split()))", "- B = list(map(int, readline().split()))", "- C = list(map(int, readline().split()))", "+ A = np.array(readline().split(), dtype=np.int64)", "+ B = np.array(readline().split(), dtype=np.int64)", "+ C = np.array(readline().split(), dtype=np.int64)", "- ans = 0", "- from bisect import bisect_left", "-", "- # Bjに対するCの使える個数は、前処理で求めておく", "- B2C = [0] * N", "- # 真に大きいが条件なので Ai + 1 が入るポイントを探す", "- for j in range(N):", "- B2C[j] = N - bisect_left(C, B[j] + 1)", "- # 累積和", "- accum = [0]", "- for j in range(N):", "- accum.append(accum[-1] + B2C[j])", "- # Ai -> B は二分探索", "- for i in range(N):", "- jst = bisect_left(B, A[i] + 1)", "- if jst == N:", "- continue", "- # 前処理済みなので、Bj以降を使ったときにCが何個使えるかはすぐわかる", "- ans += accum[N] - accum[jst]", "+ # 各Bに対して使えるAの個数", "+ cnt_A = np.searchsorted(A, B, side=\"left\")", "+ # 各Bに対して使えないCの個数", "+ cnt_C_not = np.searchsorted(C, B, side=\"right\")", "+ # 各Bに対して使えるCの個数", "+ cnt_C = N - cnt_C_not", "+ # 別の書き方", "+ # cnt_C_alt = np.searchsorted(-1 * np.flip(C), -1 * B, side='left')", "+ ans = np.multiply(cnt_A, cnt_C).sum()" ]
false
0.04351
0.421179
0.103306
[ "s067604184", "s756592679" ]
u729133443
p03102
python
s931686308
s142299279
165
21
38,384
3,188
Accepted
Accepted
87.27
I=lambda:list(map(int,input().split()));n,m,c=I();*b,=I();print((sum(-c<sum(x*y for x,y in zip(I(),b))for _ in[0]*n)))
I=lambda:list(map(int,input().split()));n,m,c=I();*b,=I();print((eval('+(-c<sum(x*y for x,y in zip(I(),b)))'*n)))
1
1
110
105
I = lambda: list(map(int, input().split())) n, m, c = I() (*b,) = I() print((sum(-c < sum(x * y for x, y in zip(I(), b)) for _ in [0] * n)))
I = lambda: list(map(int, input().split())) n, m, c = I() (*b,) = I() print((eval("+(-c<sum(x*y for x,y in zip(I(),b)))" * n)))
false
0
[ "-print((sum(-c < sum(x * y for x, y in zip(I(), b)) for _ in [0] * n)))", "+print((eval(\"+(-c<sum(x*y for x,y in zip(I(),b)))\" * n)))" ]
false
0.035203
0.041521
0.847834
[ "s931686308", "s142299279" ]
u528470578
p03164
python
s739748828
s523969938
476
418
120,556
119,916
Accepted
Accepted
12.18
# Educational DP Contest E-knapsack 2 N,W=list(map(int,input().split())) items=[] for _ in range(N): w,v=list(map(int,input().strip().split())) items+=[(w,v)] MAX_val=N*10**3+1 # 最大の価値 dp=[[10**9+1]*MAX_val for i in range(N)] # 最大の価値でinitialize(価値の表) dp[0][items[0][1]]=items[0][0] # 最初の品物の価値の場所に、最初の品物の重さを入れる for i in range(1,N): for val in range(1,MAX_val): if val-items[i][1]>0: # アイテムの価値がvalを上回っていた場合 dp[i][val]=min(dp[i-1][val],dp[i-1][val-items[i][1]]+items[i][0]) elif val==items[i][1]: # アイテムの価値がvalと同様の場合 dp[i][val]=min(items[i][0],dp[i-1][val]) dp[i][val]=min(dp[i][val],dp[i-1][val]) MAX=0 for i in range(len(dp[-1])): # dpの最終行の数を調べて、最もWに近いものを出力 if dp[-1][i]<=W: #print(i) MAX=i print(MAX)
N, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(N)] dp = [] valmax = int(1e5) INF = int(1e10) for _ in range(N+1): dp.append([INF] * (valmax+1)) dp[0][0] = 0 for i in range(N): for v in range(valmax+1): dp[i+1][v] = min(dp[i][v], dp[i][v - wv[i][1]] + wv[i][0]) maxval = 0 for k, l in enumerate(dp[N]): if l <= W: maxval = max(maxval, k) else: continue print(maxval)
27
21
819
467
# Educational DP Contest E-knapsack 2 N, W = list(map(int, input().split())) items = [] for _ in range(N): w, v = list(map(int, input().strip().split())) items += [(w, v)] MAX_val = N * 10**3 + 1 # 最大の価値 dp = [[10**9 + 1] * MAX_val for i in range(N)] # 最大の価値でinitialize(価値の表) dp[0][items[0][1]] = items[0][0] # 最初の品物の価値の場所に、最初の品物の重さを入れる for i in range(1, N): for val in range(1, MAX_val): if val - items[i][1] > 0: # アイテムの価値がvalを上回っていた場合 dp[i][val] = min(dp[i - 1][val], dp[i - 1][val - items[i][1]] + items[i][0]) elif val == items[i][1]: # アイテムの価値がvalと同様の場合 dp[i][val] = min(items[i][0], dp[i - 1][val]) dp[i][val] = min(dp[i][val], dp[i - 1][val]) MAX = 0 for i in range(len(dp[-1])): # dpの最終行の数を調べて、最もWに近いものを出力 if dp[-1][i] <= W: # print(i) MAX = i print(MAX)
N, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(N)] dp = [] valmax = int(1e5) INF = int(1e10) for _ in range(N + 1): dp.append([INF] * (valmax + 1)) dp[0][0] = 0 for i in range(N): for v in range(valmax + 1): dp[i + 1][v] = min(dp[i][v], dp[i][v - wv[i][1]] + wv[i][0]) maxval = 0 for k, l in enumerate(dp[N]): if l <= W: maxval = max(maxval, k) else: continue print(maxval)
false
22.222222
[ "-# Educational DP Contest E-knapsack 2", "-items = []", "-for _ in range(N):", "- w, v = list(map(int, input().strip().split()))", "- items += [(w, v)]", "-MAX_val = N * 10**3 + 1 # 最大の価値", "-dp = [[10**9 + 1] * MAX_val for i in range(N)] # 最大の価値でinitialize(価値の表)", "-dp[0][items[0][1]] = items[0][0] # 最初の品物の価値の場所に、最初の品物の重さを入れる", "-for i in range(1, N):", "- for val in range(1, MAX_val):", "- if val - items[i][1] > 0: # アイテムの価値がvalを上回っていた場合", "- dp[i][val] = min(dp[i - 1][val], dp[i - 1][val - items[i][1]] + items[i][0])", "- elif val == items[i][1]: # アイテムの価値がvalと同様の場合", "- dp[i][val] = min(items[i][0], dp[i - 1][val])", "- dp[i][val] = min(dp[i][val], dp[i - 1][val])", "-MAX = 0", "-for i in range(len(dp[-1])): # dpの最終行の数を調べて、最もWに近いものを出力", "- if dp[-1][i] <= W:", "- # print(i)", "- MAX = i", "-print(MAX)", "+wv = [list(map(int, input().split())) for _ in range(N)]", "+dp = []", "+valmax = int(1e5)", "+INF = int(1e10)", "+for _ in range(N + 1):", "+ dp.append([INF] * (valmax + 1))", "+dp[0][0] = 0", "+for i in range(N):", "+ for v in range(valmax + 1):", "+ dp[i + 1][v] = min(dp[i][v], dp[i][v - wv[i][1]] + wv[i][0])", "+maxval = 0", "+for k, l in enumerate(dp[N]):", "+ if l <= W:", "+ maxval = max(maxval, k)", "+ else:", "+ continue", "+print(maxval)" ]
false
0.133101
0.721082
0.184585
[ "s739748828", "s523969938" ]
u511965386
p02815
python
s899164897
s116499174
638
322
87,628
87,500
Accepted
Accepted
49.53
N = int(eval(input())) C = [int(i) for i in input().split()] mod = 10 ** 9 + 7 C.sort() ret = 0 for i in range(N) : rest = N - i - 1 if rest == 0 : ret += C[i] * pow(4, i, mod) * pow(2, N - i, mod) * pow(2, rest, mod) % mod else : ret += C[i] * pow(4, i, mod) * pow(2, N - i, mod) * (rest + 2) * pow(2, rest - 1, mod) % mod ret %= mod print(ret)
N = int(eval(input())) C = [int(i) for i in input().split()] mod = 10 ** 9 + 7 C.sort() ret = 0 P = pow(4, N - 1, mod) for i in range(N) : ret += C[i] * P * (N - i + 1) % mod ret %= mod print(ret)
16
13
373
209
N = int(eval(input())) C = [int(i) for i in input().split()] mod = 10**9 + 7 C.sort() ret = 0 for i in range(N): rest = N - i - 1 if rest == 0: ret += C[i] * pow(4, i, mod) * pow(2, N - i, mod) * pow(2, rest, mod) % mod else: ret += ( C[i] * pow(4, i, mod) * pow(2, N - i, mod) * (rest + 2) * pow(2, rest - 1, mod) % mod ) ret %= mod print(ret)
N = int(eval(input())) C = [int(i) for i in input().split()] mod = 10**9 + 7 C.sort() ret = 0 P = pow(4, N - 1, mod) for i in range(N): ret += C[i] * P * (N - i + 1) % mod ret %= mod print(ret)
false
18.75
[ "+P = pow(4, N - 1, mod)", "- rest = N - i - 1", "- if rest == 0:", "- ret += C[i] * pow(4, i, mod) * pow(2, N - i, mod) * pow(2, rest, mod) % mod", "- else:", "- ret += (", "- C[i]", "- * pow(4, i, mod)", "- * pow(2, N - i, mod)", "- * (rest + 2)", "- * pow(2, rest - 1, mod)", "- % mod", "- )", "+ ret += C[i] * P * (N - i + 1) % mod" ]
false
0.052806
0.036287
1.455255
[ "s899164897", "s116499174" ]
u189487046
p03627
python
s348978751
s094800572
87
69
18,600
18,600
Accepted
Accepted
20.69
import collections N = int(eval(input())) A = list(map(int, input().split())) CA = collections.Counter(A) max1 = 0 max2 = 0 for item in list(CA.items()): if item[1] >= 2 and item[0] > max1: if item[1] >= 4: max1 = item[0] max2 = item[0] else: max2 = max1 max1 = item[0] elif item[1] >= 2 and item[0] > max2: max2 = item[0] print((max1*max2))
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) max_1 = 0 max_2 = 0 for k, v in list(c.items()): if v >= 2: if k > max_1: if v >= 4: max_1, max_2 = k, k else: max_1, max_2 = k, max_1 elif k > max_2: max_2 = k print((max_1*max_2))
20
19
430
382
import collections N = int(eval(input())) A = list(map(int, input().split())) CA = collections.Counter(A) max1 = 0 max2 = 0 for item in list(CA.items()): if item[1] >= 2 and item[0] > max1: if item[1] >= 4: max1 = item[0] max2 = item[0] else: max2 = max1 max1 = item[0] elif item[1] >= 2 and item[0] > max2: max2 = item[0] print((max1 * max2))
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) max_1 = 0 max_2 = 0 for k, v in list(c.items()): if v >= 2: if k > max_1: if v >= 4: max_1, max_2 = k, k else: max_1, max_2 = k, max_1 elif k > max_2: max_2 = k print((max_1 * max_2))
false
5
[ "-CA = collections.Counter(A)", "-max1 = 0", "-max2 = 0", "-for item in list(CA.items()):", "- if item[1] >= 2 and item[0] > max1:", "- if item[1] >= 4:", "- max1 = item[0]", "- max2 = item[0]", "- else:", "- max2 = max1", "- max1 = item[0]", "- elif item[1] >= 2 and item[0] > max2:", "- max2 = item[0]", "-print((max1 * max2))", "+c = collections.Counter(A)", "+max_1 = 0", "+max_2 = 0", "+for k, v in list(c.items()):", "+ if v >= 2:", "+ if k > max_1:", "+ if v >= 4:", "+ max_1, max_2 = k, k", "+ else:", "+ max_1, max_2 = k, max_1", "+ elif k > max_2:", "+ max_2 = k", "+print((max_1 * max_2))" ]
false
0.044162
0.109844
0.40204
[ "s348978751", "s094800572" ]
u968166680
p02888
python
s007481159
s551519811
195
83
74,008
73,976
Accepted
Accepted
57.44
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *L = list(map(int, read().split())) L.sort() max_L = max(L) C = [0] * (max_L + 1) for l in L: C[l] += 1 C = list(accumulate(C)) ans = 0 for i, a in enumerate(L): for j, b in enumerate(L[i + 1 :], i + 1): if a + b > max_L: ans += N - j - 1 else: ans += C[a + b - 1] - j - 1 print(ans) return if __name__ == '__main__': main()
import sys from itertools import accumulate read = sys.stdin.buffer.read def main(): N, *L = list(map(int, read().split())) L.sort() max_L = L[-1] C = [0] * (max_L + 1) for l in L: C[l] += 1 C = list(accumulate(C)) ans = 0 for i, a in enumerate(L): for j, b in enumerate(L[i + 1 :], i + 1): if a + b > max_L: ans += N - j - 1 else: ans += C[a + b - 1] - j - 1 print(ans) return if __name__ == '__main__': main()
37
31
686
561
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *L = list(map(int, read().split())) L.sort() max_L = max(L) C = [0] * (max_L + 1) for l in L: C[l] += 1 C = list(accumulate(C)) ans = 0 for i, a in enumerate(L): for j, b in enumerate(L[i + 1 :], i + 1): if a + b > max_L: ans += N - j - 1 else: ans += C[a + b - 1] - j - 1 print(ans) return if __name__ == "__main__": main()
import sys from itertools import accumulate read = sys.stdin.buffer.read def main(): N, *L = list(map(int, read().split())) L.sort() max_L = L[-1] C = [0] * (max_L + 1) for l in L: C[l] += 1 C = list(accumulate(C)) ans = 0 for i, a in enumerate(L): for j, b in enumerate(L[i + 1 :], i + 1): if a + b > max_L: ans += N - j - 1 else: ans += C[a + b - 1] - j - 1 print(ans) return if __name__ == "__main__": main()
false
16.216216
[ "-read = sys.stdin.read", "-readline = sys.stdin.readline", "-readlines = sys.stdin.readlines", "-sys.setrecursionlimit(10**9)", "-INF = 1 << 60", "-MOD = 1000000007", "+read = sys.stdin.buffer.read", "- max_L = max(L)", "+ max_L = L[-1]" ]
false
0.036952
0.055395
0.667061
[ "s007481159", "s551519811" ]
u504256702
p02887
python
s156390904
s663562271
57
44
4,652
3,316
Accepted
Accepted
22.81
N = int(eval(input())) S = list(eval(input())) prior = "" fusion = "" for i in range(N): if prior != S[i]: fusion += S[i] prior = S[i] #print(prior, end="") print((len(list(fusion))))
N = int(eval(input())) S = eval(input()) ans = 1 for i in range(1, N): if S[i - 1] != S[i]: ans += 1 print(ans)
11
7
190
111
N = int(eval(input())) S = list(eval(input())) prior = "" fusion = "" for i in range(N): if prior != S[i]: fusion += S[i] prior = S[i] # print(prior, end="") print((len(list(fusion))))
N = int(eval(input())) S = eval(input()) ans = 1 for i in range(1, N): if S[i - 1] != S[i]: ans += 1 print(ans)
false
36.363636
[ "-S = list(eval(input()))", "-prior = \"\"", "-fusion = \"\"", "-for i in range(N):", "- if prior != S[i]:", "- fusion += S[i]", "- prior = S[i]", "- # print(prior, end=\"\")", "-print((len(list(fusion))))", "+S = eval(input())", "+ans = 1", "+for i in range(1, N):", "+ if S[i - 1] != S[i]:", "+ ans += 1", "+print(ans)" ]
false
0.038439
0.084175
0.456659
[ "s156390904", "s663562271" ]
u995004106
p03525
python
s627110221
s723178277
442
72
217,964
71,148
Accepted
Accepted
83.71
import collections from collections import deque N=int(eval(input())) D=list(map(int,input().split())) c=collections.Counter(D) count0=0 count12=0 zeroflag=0 l=[] if c[12]>0: count12=c[12] if c[0]>0: count0=c[0]+1 #print(l,count0,count12) #print(n) allmax=0 q=deque() l=[] if (count0==0)and(zeroflag==0): q.append([0]) q.append([24]) elif (count0==1)and(zeroflag==0): q.append([0,0]) q.append([0,24]) q.append([24,24]) else: zeroflag=1 if (count12==1)and(zeroflag==0): length=len(q) j=0 while j<length: buf1=[] l=q.popleft() buf1.extend(l) l.append(12) q.append(l) j=j+1 elif count12>1: zeroflag=1 if zeroflag==0: for i in range(1,12): length=len(q) j=0 if c[i]==0: continue if c[i]==1: while j<length: buf1=[] buf2=[] l=q.popleft() buf1.extend(l) buf1.append(i) buf2.extend(l) buf2.append(24-i) q.append(buf1) q.append(buf2) j=j+1 if c[i]==2: while j<length: buf1=[] buf2=[] buf3=[] l=q.popleft() buf1.extend(l) buf1.extend([i,i]) buf2.extend(l) buf2.extend([24-i,24-i]) buf3.extend(l) buf3.extend([i,24-i]) q.append(buf1) q.append(buf2) q.append(buf3) j=j+1 if c[i]>2: zeroflag=1 break #print(q) #print(q) if zeroflag==0: for l in q: l.sort() mi=100 n=len(l) for j in range(n-1): mi=min(mi,l[j+1]-l[j],24-l[j+1]+l[j]) mi=min(mi,l[n-1],24-l[n-1]) #print(mi) allmax=max(allmax,mi) else: allmax=0 print(allmax) """ for i in range(pow(2,n)): buf=[0] bit=[0]*n mi=100 if count12==1: buf.append(12) buf.append(0) for j in range(n): if (i>>j)&1: bit[j]=1 #print(bit) for j in range(n): buf.append(l[j][bit[j]]) buf.sort() buf.append(24) #print(buf) for j in range(len(buf)-1): mi=min(mi,buf[j+1]-buf[j]) allmax=max(allmax,mi) print(allmax) """
import collections from collections import deque N=int(eval(input())) D=list(map(int,input().split())) c=collections.Counter(D) count0=0 count12=0 zeroflag=0 l=[] if c[12]>0: count12=c[12] if c[0]>0: count0=c[0]+1 #print(l,count0,count12) #print(n) allmax=0 q=deque() l=[] if (count0==0)and(zeroflag==0): q.append([0]) else: zeroflag=1 if (count12==1)and(zeroflag==0): length=len(q) j=0 while j<length: buf1=[] l=q.popleft() buf1.extend(l) l.append(12) q.append(l) j=j+1 elif count12>1: zeroflag=1 if zeroflag==0: for i in range(1,12): length=len(q) j=0 if c[i]==0: continue if c[i]==1: while j<length: buf1=[] buf2=[] l=q.popleft() buf1.extend(l) buf1.append(i) buf2.extend(l) buf2.append(24-i) q.append(buf1) q.append(buf2) j=j+1 if c[i]==2: while j<length: buf1=[] buf2=[] buf3=[] l=q.popleft() #buf1.extend(l) #buf1.extend([i,i]) #buf2.extend(l) #buf2.extend([24-i,24-i]) buf3.extend(l) buf3.extend([i,24-i]) #q.append(buf1) #q.append(buf2) q.append(buf3) j=j+1 if c[i]>2: zeroflag=1 break #print(q) #print(q) if zeroflag==0: for l in q: l.sort() mi=100 n=len(l) for j in range(n-1): mi=min(mi,l[j+1]-l[j],24-l[j+1]+l[j]) mi=min(mi,l[n-1],24-l[n-1]) #print(mi) allmax=max(allmax,mi) else: allmax=0 print(allmax)
120
92
2,516
1,952
import collections from collections import deque N = int(eval(input())) D = list(map(int, input().split())) c = collections.Counter(D) count0 = 0 count12 = 0 zeroflag = 0 l = [] if c[12] > 0: count12 = c[12] if c[0] > 0: count0 = c[0] + 1 # print(l,count0,count12) # print(n) allmax = 0 q = deque() l = [] if (count0 == 0) and (zeroflag == 0): q.append([0]) q.append([24]) elif (count0 == 1) and (zeroflag == 0): q.append([0, 0]) q.append([0, 24]) q.append([24, 24]) else: zeroflag = 1 if (count12 == 1) and (zeroflag == 0): length = len(q) j = 0 while j < length: buf1 = [] l = q.popleft() buf1.extend(l) l.append(12) q.append(l) j = j + 1 elif count12 > 1: zeroflag = 1 if zeroflag == 0: for i in range(1, 12): length = len(q) j = 0 if c[i] == 0: continue if c[i] == 1: while j < length: buf1 = [] buf2 = [] l = q.popleft() buf1.extend(l) buf1.append(i) buf2.extend(l) buf2.append(24 - i) q.append(buf1) q.append(buf2) j = j + 1 if c[i] == 2: while j < length: buf1 = [] buf2 = [] buf3 = [] l = q.popleft() buf1.extend(l) buf1.extend([i, i]) buf2.extend(l) buf2.extend([24 - i, 24 - i]) buf3.extend(l) buf3.extend([i, 24 - i]) q.append(buf1) q.append(buf2) q.append(buf3) j = j + 1 if c[i] > 2: zeroflag = 1 break # print(q) # print(q) if zeroflag == 0: for l in q: l.sort() mi = 100 n = len(l) for j in range(n - 1): mi = min(mi, l[j + 1] - l[j], 24 - l[j + 1] + l[j]) mi = min(mi, l[n - 1], 24 - l[n - 1]) # print(mi) allmax = max(allmax, mi) else: allmax = 0 print(allmax) """ for i in range(pow(2,n)): buf=[0] bit=[0]*n mi=100 if count12==1: buf.append(12) buf.append(0) for j in range(n): if (i>>j)&1: bit[j]=1 #print(bit) for j in range(n): buf.append(l[j][bit[j]]) buf.sort() buf.append(24) #print(buf) for j in range(len(buf)-1): mi=min(mi,buf[j+1]-buf[j]) allmax=max(allmax,mi) print(allmax) """
import collections from collections import deque N = int(eval(input())) D = list(map(int, input().split())) c = collections.Counter(D) count0 = 0 count12 = 0 zeroflag = 0 l = [] if c[12] > 0: count12 = c[12] if c[0] > 0: count0 = c[0] + 1 # print(l,count0,count12) # print(n) allmax = 0 q = deque() l = [] if (count0 == 0) and (zeroflag == 0): q.append([0]) else: zeroflag = 1 if (count12 == 1) and (zeroflag == 0): length = len(q) j = 0 while j < length: buf1 = [] l = q.popleft() buf1.extend(l) l.append(12) q.append(l) j = j + 1 elif count12 > 1: zeroflag = 1 if zeroflag == 0: for i in range(1, 12): length = len(q) j = 0 if c[i] == 0: continue if c[i] == 1: while j < length: buf1 = [] buf2 = [] l = q.popleft() buf1.extend(l) buf1.append(i) buf2.extend(l) buf2.append(24 - i) q.append(buf1) q.append(buf2) j = j + 1 if c[i] == 2: while j < length: buf1 = [] buf2 = [] buf3 = [] l = q.popleft() # buf1.extend(l) # buf1.extend([i,i]) # buf2.extend(l) # buf2.extend([24-i,24-i]) buf3.extend(l) buf3.extend([i, 24 - i]) # q.append(buf1) # q.append(buf2) q.append(buf3) j = j + 1 if c[i] > 2: zeroflag = 1 break # print(q) # print(q) if zeroflag == 0: for l in q: l.sort() mi = 100 n = len(l) for j in range(n - 1): mi = min(mi, l[j + 1] - l[j], 24 - l[j + 1] + l[j]) mi = min(mi, l[n - 1], 24 - l[n - 1]) # print(mi) allmax = max(allmax, mi) else: allmax = 0 print(allmax)
false
23.333333
[ "- q.append([24])", "-elif (count0 == 1) and (zeroflag == 0):", "- q.append([0, 0])", "- q.append([0, 24])", "- q.append([24, 24])", "- buf1.extend(l)", "- buf1.extend([i, i])", "- buf2.extend(l)", "- buf2.extend([24 - i, 24 - i])", "+ # buf1.extend(l)", "+ # buf1.extend([i,i])", "+ # buf2.extend(l)", "+ # buf2.extend([24-i,24-i])", "- q.append(buf1)", "- q.append(buf2)", "+ # q.append(buf1)", "+ # q.append(buf2)", "-\"\"\"", "-for i in range(pow(2,n)):", "- buf=[0]", "- bit=[0]*n", "- mi=100", "- if count12==1:", "- buf.append(12)", "- buf.append(0)", "- for j in range(n):", "- if (i>>j)&1:", "- bit[j]=1", "- #print(bit)", "- for j in range(n):", "- buf.append(l[j][bit[j]])", "- buf.sort()", "- buf.append(24)", "- #print(buf)", "- for j in range(len(buf)-1):", "- mi=min(mi,buf[j+1]-buf[j])", "- allmax=max(allmax,mi)", "-print(allmax)", "-\"\"\"" ]
false
0.041714
0.037234
1.120334
[ "s627110221", "s723178277" ]
u981931040
p03262
python
s568912323
s427040499
185
104
14,252
14,252
Accepted
Accepted
43.78
import bisect def gcd(x , y): max_val = max(x , y) min_val = min(x , y) while min_val != 0: max_val , min_val = min_val , max_val % min_val return max_val N , X = list(map(int,input().split())) x = list(map(int,input().split())) x.sort() split_idx = bisect.bisect_left(x , X) BeforeList = x[:split_idx] AfterList = x[split_idx:] now = X ans = 0 DistanceList = [] for val in AfterList: distance = abs(val - now) DistanceList.append(distance) now = val for val in BeforeList: distance = abs(val - now) DistanceList.append(distance) now = val ans = DistanceList[0] for i in range(1,len(DistanceList)): ans = gcd(DistanceList[i] , ans) print(ans)
def gcd(a, b): while b != 0: a, b = b, a % b return a N, X = list(map(int, input().split())) x = list(map(int, input().split())) x.insert(0, X) distance = [] for i in range(1, len(x)): distance.append(abs(x[i] - x[i - 1])) ans = distance[0] for i in range(1, len(distance)): ans = gcd(distance[i], ans) print(ans)
29
18
717
352
import bisect def gcd(x, y): max_val = max(x, y) min_val = min(x, y) while min_val != 0: max_val, min_val = min_val, max_val % min_val return max_val N, X = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() split_idx = bisect.bisect_left(x, X) BeforeList = x[:split_idx] AfterList = x[split_idx:] now = X ans = 0 DistanceList = [] for val in AfterList: distance = abs(val - now) DistanceList.append(distance) now = val for val in BeforeList: distance = abs(val - now) DistanceList.append(distance) now = val ans = DistanceList[0] for i in range(1, len(DistanceList)): ans = gcd(DistanceList[i], ans) print(ans)
def gcd(a, b): while b != 0: a, b = b, a % b return a N, X = list(map(int, input().split())) x = list(map(int, input().split())) x.insert(0, X) distance = [] for i in range(1, len(x)): distance.append(abs(x[i] - x[i - 1])) ans = distance[0] for i in range(1, len(distance)): ans = gcd(distance[i], ans) print(ans)
false
37.931034
[ "-import bisect", "-", "-", "-def gcd(x, y):", "- max_val = max(x, y)", "- min_val = min(x, y)", "- while min_val != 0:", "- max_val, min_val = min_val, max_val % min_val", "- return max_val", "+def gcd(a, b):", "+ while b != 0:", "+ a, b = b, a % b", "+ return a", "-x.sort()", "-split_idx = bisect.bisect_left(x, X)", "-BeforeList = x[:split_idx]", "-AfterList = x[split_idx:]", "-now = X", "-ans = 0", "-DistanceList = []", "-for val in AfterList:", "- distance = abs(val - now)", "- DistanceList.append(distance)", "- now = val", "-for val in BeforeList:", "- distance = abs(val - now)", "- DistanceList.append(distance)", "- now = val", "-ans = DistanceList[0]", "-for i in range(1, len(DistanceList)):", "- ans = gcd(DistanceList[i], ans)", "+x.insert(0, X)", "+distance = []", "+for i in range(1, len(x)):", "+ distance.append(abs(x[i] - x[i - 1]))", "+ans = distance[0]", "+for i in range(1, len(distance)):", "+ ans = gcd(distance[i], ans)" ]
false
0.036184
0.07237
0.499992
[ "s568912323", "s427040499" ]
u475675023
p02787
python
s365385832
s173524162
1,884
76
3,832
30,180
Accepted
Accepted
95.97
h,n=list(map(int,input().split())) ab=[list(map(int,input().split())) for _ in range(n)] mx=max(a for a,b in ab) dp=[10**10]*(h+1+mx) dp[0]=0 for i in range(1,h+1+mx): dp[i]=min(dp[i-a]+b for a,b in ab) print((min(dp[h:])))
from functools import lru_cache import sys sys.setrecursionlimit(10 ** 8) h,n=list(map(int,input().split())) ab=[tuple(map(int,input().split())) for _ in range(n)] ab.sort(key=lambda abi:(abi[1]/abi[0],abi[0])) @lru_cache(maxsize=None) def dp(i): if i<=0: return 0 else: ans=float('inf') for a,b in ab: val=b+dp(i-a) if val<ans: ans=val else: break return ans print((dp(h)))
8
22
224
443
h, n = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] mx = max(a for a, b in ab) dp = [10**10] * (h + 1 + mx) dp[0] = 0 for i in range(1, h + 1 + mx): dp[i] = min(dp[i - a] + b for a, b in ab) print((min(dp[h:])))
from functools import lru_cache import sys sys.setrecursionlimit(10**8) h, n = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda abi: (abi[1] / abi[0], abi[0])) @lru_cache(maxsize=None) def dp(i): if i <= 0: return 0 else: ans = float("inf") for a, b in ab: val = b + dp(i - a) if val < ans: ans = val else: break return ans print((dp(h)))
false
63.636364
[ "+from functools import lru_cache", "+import sys", "+", "+sys.setrecursionlimit(10**8)", "-ab = [list(map(int, input().split())) for _ in range(n)]", "-mx = max(a for a, b in ab)", "-dp = [10**10] * (h + 1 + mx)", "-dp[0] = 0", "-for i in range(1, h + 1 + mx):", "- dp[i] = min(dp[i - a] + b for a, b in ab)", "-print((min(dp[h:])))", "+ab = [tuple(map(int, input().split())) for _ in range(n)]", "+ab.sort(key=lambda abi: (abi[1] / abi[0], abi[0]))", "+", "+", "+@lru_cache(maxsize=None)", "+def dp(i):", "+ if i <= 0:", "+ return 0", "+ else:", "+ ans = float(\"inf\")", "+ for a, b in ab:", "+ val = b + dp(i - a)", "+ if val < ans:", "+ ans = val", "+ else:", "+ break", "+ return ans", "+", "+", "+print((dp(h)))" ]
false
0.192903
0.037217
5.183166
[ "s365385832", "s173524162" ]
u700929101
p02923
python
s381466011
s626224047
81
69
14,252
15,020
Accepted
Accepted
14.81
n = int(eval(input())) h = list(map(int, input().split())) answer = 0#これなに m = 0#カウントするやつやね for i in range(n-1): if h[i] >= h[i+1]: m += 1 else: answer = max(answer,m) m = 0 answer = max(answer,m) print(answer)
n = int(eval(input())) h = list(map(int,input().split(" "))) plsl = [] plsn = 0 for i in range(n-1): if h[i]>= h[i+1]: plsn += 1 else: #i<i+1の時 plsl.append(plsn) plsn = 0 plsl.append(plsn) plsl.sort(reverse = True) print((plsl[0]))
12
13
248
268
n = int(eval(input())) h = list(map(int, input().split())) answer = 0 # これなに m = 0 # カウントするやつやね for i in range(n - 1): if h[i] >= h[i + 1]: m += 1 else: answer = max(answer, m) m = 0 answer = max(answer, m) print(answer)
n = int(eval(input())) h = list(map(int, input().split(" "))) plsl = [] plsn = 0 for i in range(n - 1): if h[i] >= h[i + 1]: plsn += 1 else: # i<i+1の時 plsl.append(plsn) plsn = 0 plsl.append(plsn) plsl.sort(reverse=True) print((plsl[0]))
false
7.692308
[ "-h = list(map(int, input().split()))", "-answer = 0 # これなに", "-m = 0 # カウントするやつやね", "+h = list(map(int, input().split(\" \")))", "+plsl = []", "+plsn = 0", "- m += 1", "- else:", "- answer = max(answer, m)", "- m = 0", "-answer = max(answer, m)", "-print(answer)", "+ plsn += 1", "+ else: # i<i+1の時", "+ plsl.append(plsn)", "+ plsn = 0", "+plsl.append(plsn)", "+plsl.sort(reverse=True)", "+print((plsl[0]))" ]
false
0.040763
0.08179
0.498387
[ "s381466011", "s626224047" ]
u254871849
p03945
python
s324588928
s886459783
38
27
3,316
3,188
Accepted
Accepted
28.95
import sys s = sys.stdin.readline().rstrip() def main(): cnt = 0 for i in range(len(s) - 1): if s[i] != s[i+1]: cnt += 1 return cnt if __name__ == '__main__': ans = main() print(ans)
import sys s = sys.stdin.readline().rstrip() def main(): prev = '$' cnt = -1 for c in s: cnt += c != prev prev = c print(cnt) if __name__ == '__main__': main()
14
14
238
212
import sys s = sys.stdin.readline().rstrip() def main(): cnt = 0 for i in range(len(s) - 1): if s[i] != s[i + 1]: cnt += 1 return cnt if __name__ == "__main__": ans = main() print(ans)
import sys s = sys.stdin.readline().rstrip() def main(): prev = "$" cnt = -1 for c in s: cnt += c != prev prev = c print(cnt) if __name__ == "__main__": main()
false
0
[ "- cnt = 0", "- for i in range(len(s) - 1):", "- if s[i] != s[i + 1]:", "- cnt += 1", "- return cnt", "+ prev = \"$\"", "+ cnt = -1", "+ for c in s:", "+ cnt += c != prev", "+ prev = c", "+ print(cnt)", "- ans = main()", "- print(ans)", "+ main()" ]
false
0.043035
0.047035
0.914967
[ "s324588928", "s886459783" ]
u367701763
p03148
python
s454637950
s720232013
236
153
90,532
80,248
Accepted
Accepted
35.17
import sys from heapq import * input = sys.stdin.readline N, K = list(map(int, input().split())) D, H, var, res = [], [], set(), 0 for _ in range(N): t,d = list(map(int, input().split())) D.append((t,d)) D.sort(key=lambda x: x[1], reverse=True) for t, d in D[:K]: if t not in var: var.add(t) else: heappush(H, d) res += d x = len(var) res += x**2 tmp = res for t, d in D[K:]: if H and t not in var: tmp += d-heappop(H)+2*x+1 x += 1 var.add(t) res = max(res,tmp) print(res)
import sys from heapq import * input = sys.stdin.readline N, K = list(map(int, input().split())) D, H, var, res, L = [], [], set(), 0, N.bit_length()+2 for _ in range(N): t,d = list(map(int, input().split())) D.append((d<<L)+t) D.sort(reverse=True) for z in D[:K]: d, t = z>>L, z%(1<<L) if t not in var: var.add(t) else: heappush(H, d) res += d x = len(var) res += x**2 tmp = res for z in D[K:]: d, t = z>>L, z%(1<<L) if H and t not in var: tmp += d-heappop(H)+2*x+1 x += 1 var.add(t) res = max(res,tmp) print(res)
23
25
538
590
import sys from heapq import * input = sys.stdin.readline N, K = list(map(int, input().split())) D, H, var, res = [], [], set(), 0 for _ in range(N): t, d = list(map(int, input().split())) D.append((t, d)) D.sort(key=lambda x: x[1], reverse=True) for t, d in D[:K]: if t not in var: var.add(t) else: heappush(H, d) res += d x = len(var) res += x**2 tmp = res for t, d in D[K:]: if H and t not in var: tmp += d - heappop(H) + 2 * x + 1 x += 1 var.add(t) res = max(res, tmp) print(res)
import sys from heapq import * input = sys.stdin.readline N, K = list(map(int, input().split())) D, H, var, res, L = [], [], set(), 0, N.bit_length() + 2 for _ in range(N): t, d = list(map(int, input().split())) D.append((d << L) + t) D.sort(reverse=True) for z in D[:K]: d, t = z >> L, z % (1 << L) if t not in var: var.add(t) else: heappush(H, d) res += d x = len(var) res += x**2 tmp = res for z in D[K:]: d, t = z >> L, z % (1 << L) if H and t not in var: tmp += d - heappop(H) + 2 * x + 1 x += 1 var.add(t) res = max(res, tmp) print(res)
false
8
[ "-D, H, var, res = [], [], set(), 0", "+D, H, var, res, L = [], [], set(), 0, N.bit_length() + 2", "- D.append((t, d))", "-D.sort(key=lambda x: x[1], reverse=True)", "-for t, d in D[:K]:", "+ D.append((d << L) + t)", "+D.sort(reverse=True)", "+for z in D[:K]:", "+ d, t = z >> L, z % (1 << L)", "-for t, d in D[K:]:", "+for z in D[K:]:", "+ d, t = z >> L, z % (1 << L)" ]
false
0.063671
0.080818
0.787835
[ "s454637950", "s720232013" ]
u010110540
p03732
python
s057753748
s148718310
1,046
163
3,444
20,760
Accepted
Accepted
84.42
from collections import Counter from itertools import product N, W = list(map(int, input().split())) items = {} weight = [] for i in range(N): w, v = list(map(int, input().split())) weight.append(w) if items.get(w, None) is None: items[w] = [] items[w].append(v) items[w] = sorted(items[w], reverse = True) cnt = Counter(weight) w_num = [] #各重さの個数。組み合わせのために使う。[range(0,2), range(0,3), range(0,2)]のような出力 w_set = [] # 重さは w0 <= wi <= w0+3の4通りしかない for w in range(weight[0], weight[0] + 4): if cnt[w] == 0: continue w_num.append(list(range(cnt[w] + 1))) w_set.append(w) ans = 0 for i in product(*w_num): w = sum([x[0] * x[1] for x in zip(i, w_set)]) if 1 > w or w > W: continue v = sum([sum(items[k][:j]) for j, k in zip(i, w_set)]) if ans < v: ans = v print(ans)
N, W = list(map(int, input().split())) w, v = [], [] for _ in range(N): a, b = list(map(int, input().split())) w.append(a) v.append(b) memo = {} def nap(i, j): if i == N: return 0 if (i, j) in memo: return memo[i, j] elif j < w[i]: temp = nap(i+1, j) else: temp = max(nap(i+1, j), nap(i+1, j-w[i]) + v[i]) memo[i,j] = temp return memo[i,j] print((nap(0, W)))
39
25
882
458
from collections import Counter from itertools import product N, W = list(map(int, input().split())) items = {} weight = [] for i in range(N): w, v = list(map(int, input().split())) weight.append(w) if items.get(w, None) is None: items[w] = [] items[w].append(v) items[w] = sorted(items[w], reverse=True) cnt = Counter(weight) w_num = [] # 各重さの個数。組み合わせのために使う。[range(0,2), range(0,3), range(0,2)]のような出力 w_set = [] # 重さは w0 <= wi <= w0+3の4通りしかない for w in range(weight[0], weight[0] + 4): if cnt[w] == 0: continue w_num.append(list(range(cnt[w] + 1))) w_set.append(w) ans = 0 for i in product(*w_num): w = sum([x[0] * x[1] for x in zip(i, w_set)]) if 1 > w or w > W: continue v = sum([sum(items[k][:j]) for j, k in zip(i, w_set)]) if ans < v: ans = v print(ans)
N, W = list(map(int, input().split())) w, v = [], [] for _ in range(N): a, b = list(map(int, input().split())) w.append(a) v.append(b) memo = {} def nap(i, j): if i == N: return 0 if (i, j) in memo: return memo[i, j] elif j < w[i]: temp = nap(i + 1, j) else: temp = max(nap(i + 1, j), nap(i + 1, j - w[i]) + v[i]) memo[i, j] = temp return memo[i, j] print((nap(0, W)))
false
35.897436
[ "-from collections import Counter", "-from itertools import product", "+N, W = list(map(int, input().split()))", "+w, v = [], []", "+for _ in range(N):", "+ a, b = list(map(int, input().split()))", "+ w.append(a)", "+ v.append(b)", "+memo = {}", "-N, W = list(map(int, input().split()))", "-items = {}", "-weight = []", "-for i in range(N):", "- w, v = list(map(int, input().split()))", "- weight.append(w)", "- if items.get(w, None) is None:", "- items[w] = []", "- items[w].append(v)", "- items[w] = sorted(items[w], reverse=True)", "-cnt = Counter(weight)", "-w_num = [] # 各重さの個数。組み合わせのために使う。[range(0,2), range(0,3), range(0,2)]のような出力", "-w_set = [] # 重さは w0 <= wi <= w0+3の4通りしかない", "-for w in range(weight[0], weight[0] + 4):", "- if cnt[w] == 0:", "- continue", "- w_num.append(list(range(cnt[w] + 1)))", "- w_set.append(w)", "-ans = 0", "-for i in product(*w_num):", "- w = sum([x[0] * x[1] for x in zip(i, w_set)])", "- if 1 > w or w > W:", "- continue", "- v = sum([sum(items[k][:j]) for j, k in zip(i, w_set)])", "- if ans < v:", "- ans = v", "-print(ans)", "+", "+def nap(i, j):", "+ if i == N:", "+ return 0", "+ if (i, j) in memo:", "+ return memo[i, j]", "+ elif j < w[i]:", "+ temp = nap(i + 1, j)", "+ else:", "+ temp = max(nap(i + 1, j), nap(i + 1, j - w[i]) + v[i])", "+ memo[i, j] = temp", "+ return memo[i, j]", "+", "+", "+print((nap(0, W)))" ]
false
0.040886
0.03899
1.048636
[ "s057753748", "s148718310" ]
u697690147
p03151
python
s212293727
s742898493
164
118
24,256
24,240
Accepted
Accepted
28.05
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) surplus = [] short = [] for i in range(n): if a[i] > b[i]: surplus.append(a[i]-b[i]) elif b[i] > a[i]: short.append(b[i]-a[i]) surplus = sorted(surplus) taken = False cnt = 0 for i in range(len(short)): cost = short.pop() cnt += 1 while cost > 0: if len(surplus) == 0: print((-1)) exit() take = min(cost, surplus[-1]) cost -= take surplus[-1] -= take if not taken: taken = True cnt += 1 if surplus[-1] == 0: surplus.pop() taken = False print(cnt)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) surplus = [] short = 0 cnt = 0 for i in range(n): if a[i] > b[i]: surplus.append(a[i]-b[i]) elif b[i] > a[i]: short += b[i]-a[i] cnt += 1 surplus = sorted(surplus) s = 0 while s < short: if len(surplus) == 0: print((-1)) exit() s += surplus.pop() cnt += 1 print(cnt)
38
27
734
445
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) surplus = [] short = [] for i in range(n): if a[i] > b[i]: surplus.append(a[i] - b[i]) elif b[i] > a[i]: short.append(b[i] - a[i]) surplus = sorted(surplus) taken = False cnt = 0 for i in range(len(short)): cost = short.pop() cnt += 1 while cost > 0: if len(surplus) == 0: print((-1)) exit() take = min(cost, surplus[-1]) cost -= take surplus[-1] -= take if not taken: taken = True cnt += 1 if surplus[-1] == 0: surplus.pop() taken = False print(cnt)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) surplus = [] short = 0 cnt = 0 for i in range(n): if a[i] > b[i]: surplus.append(a[i] - b[i]) elif b[i] > a[i]: short += b[i] - a[i] cnt += 1 surplus = sorted(surplus) s = 0 while s < short: if len(surplus) == 0: print((-1)) exit() s += surplus.pop() cnt += 1 print(cnt)
false
28.947368
[ "-short = []", "+short = 0", "+cnt = 0", "- short.append(b[i] - a[i])", "+ short += b[i] - a[i]", "+ cnt += 1", "-taken = False", "-cnt = 0", "-for i in range(len(short)):", "- cost = short.pop()", "+s = 0", "+while s < short:", "+ if len(surplus) == 0:", "+ print((-1))", "+ exit()", "+ s += surplus.pop()", "- while cost > 0:", "- if len(surplus) == 0:", "- print((-1))", "- exit()", "- take = min(cost, surplus[-1])", "- cost -= take", "- surplus[-1] -= take", "- if not taken:", "- taken = True", "- cnt += 1", "- if surplus[-1] == 0:", "- surplus.pop()", "- taken = False" ]
false
0.034698
0.042438
0.817612
[ "s212293727", "s742898493" ]
u661290476
p00009
python
s025906539
s865844259
2,470
1,160
14,944
24,092
Accepted
Accepted
53.04
import sys prime=[False]*1000000 for i in range(2,1001): for j in range(i*2,1000000,i): prime[j]=True for n in sys.stdin: cnt=0 for i in range(2,int(n)+1): if not prime[i]: cnt+=1 print(cnt)
prime=[False]*1000000 for i in range(2,1001): for j in range(i*2,1000000,i): prime[j]=True while True: try: n=int(eval(input())) except: break print((prime[2:n+1].count(False)))
12
12
246
222
import sys prime = [False] * 1000000 for i in range(2, 1001): for j in range(i * 2, 1000000, i): prime[j] = True for n in sys.stdin: cnt = 0 for i in range(2, int(n) + 1): if not prime[i]: cnt += 1 print(cnt)
prime = [False] * 1000000 for i in range(2, 1001): for j in range(i * 2, 1000000, i): prime[j] = True while True: try: n = int(eval(input())) except: break print((prime[2 : n + 1].count(False)))
false
0
[ "-import sys", "-", "-for n in sys.stdin:", "- cnt = 0", "- for i in range(2, int(n) + 1):", "- if not prime[i]:", "- cnt += 1", "- print(cnt)", "+while True:", "+ try:", "+ n = int(eval(input()))", "+ except:", "+ break", "+ print((prime[2 : n + 1].count(False)))" ]
false
2.819951
1.768683
1.594379
[ "s025906539", "s865844259" ]
u089230684
p03448
python
s162744193
s114719746
46
20
3,064
4,672
Accepted
Accepted
56.52
#!/usr/bin/env python3 from itertools import product import sys def solve(AA: int, BB: int, CC: int, XX: int): print((sum( 1 for a, b, c in product(list(range(AA + 1)), list(range(BB + 1)), list(range(CC + 1))) if a * 500 + b * 100 + c * 50 == XX ))) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int X = int(next(tokens)) # type: int solve(A, B, C, X) if __name__ == '__main__': main()
a = eval(input()) b = eval(input()) c = eval(input()) x = eval(input()) cache = {} def d(a, b, c, r): if r == 0: return 1 if r < 0: return 0 if (a, b, c, r) in cache: return cache[(a, b, c, r)] s = 0 if a > 0: s += d(a - 1, b, c, r - 500) if b > 0: s += d(0, b - 1, c, r - 100) if c > 0: s += d(0, 0, c - 1, r - 50) cache[(a, b, c, r)] = s return s print(d(a, b, c, x))
28
19
681
408
#!/usr/bin/env python3 from itertools import product import sys def solve(AA: int, BB: int, CC: int, XX: int): print( ( sum( 1 for a, b, c in product( list(range(AA + 1)), list(range(BB + 1)), list(range(CC + 1)) ) if a * 500 + b * 100 + c * 50 == XX ) ) ) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int X = int(next(tokens)) # type: int solve(A, B, C, X) if __name__ == "__main__": main()
a = eval(input()) b = eval(input()) c = eval(input()) x = eval(input()) cache = {} def d(a, b, c, r): if r == 0: return 1 if r < 0: return 0 if (a, b, c, r) in cache: return cache[(a, b, c, r)] s = 0 if a > 0: s += d(a - 1, b, c, r - 500) if b > 0: s += d(0, b - 1, c, r - 100) if c > 0: s += d(0, 0, c - 1, r - 50) cache[(a, b, c, r)] = s return s print(d(a, b, c, x))
false
32.142857
[ "-#!/usr/bin/env python3", "-from itertools import product", "-import sys", "+a = eval(input())", "+b = eval(input())", "+c = eval(input())", "+x = eval(input())", "+cache = {}", "-def solve(AA: int, BB: int, CC: int, XX: int):", "- print(", "- (", "- sum(", "- 1", "- for a, b, c in product(", "- list(range(AA + 1)), list(range(BB + 1)), list(range(CC + 1))", "- )", "- if a * 500 + b * 100 + c * 50 == XX", "- )", "- )", "- )", "+def d(a, b, c, r):", "+ if r == 0:", "+ return 1", "+ if r < 0:", "+ return 0", "+ if (a, b, c, r) in cache:", "+ return cache[(a, b, c, r)]", "+ s = 0", "+ if a > 0:", "+ s += d(a - 1, b, c, r - 500)", "+ if b > 0:", "+ s += d(0, b - 1, c, r - 100)", "+ if c > 0:", "+ s += d(0, 0, c - 1, r - 50)", "+ cache[(a, b, c, r)] = s", "+ return s", "-def main():", "- def iterate_tokens():", "- for line in sys.stdin:", "- for word in line.split():", "- yield word", "-", "- tokens = iterate_tokens()", "- A = int(next(tokens)) # type: int", "- B = int(next(tokens)) # type: int", "- C = int(next(tokens)) # type: int", "- X = int(next(tokens)) # type: int", "- solve(A, B, C, X)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+print(d(a, b, c, x))" ]
false
0.079992
0.03627
2.205445
[ "s162744193", "s114719746" ]
u638795007
p03039
python
s242061391
s856618448
285
195
52,788
42,096
Accepted
Accepted
31.58
from operator import mul from functools import reduce def comb2(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 def comb3(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 import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) mod = 10**9 + 7 inf = float('inf') ans = int(0) N, M, K = LI() cou = int(0) #maxL = N + M -2 L = int(0) #距離i+1の組み合わせ #for i in range(maxL): for j in range(N): L += (N - j - 1) * (M ** 2) * (j + 1) for j in range(M): L += (M - j - 1) * (N ** 2) * (j + 1) # for j in range(i+2): # if i>1 and i+1>j>0: # L[i] += max((N-j)*(M-(1+i)+j),0)*(i+1)*2 # else: # L[i] += max(((N - j) * (M - (1 + i) + j)), 0) * (i + 1) cou = comb3(N*M-2,K-2)%mod ans = cou *L%mod print(ans)
class combination(): #素数のmod取るときのみ 速い def __init__(self, n, mod): self.n = n self.fac = [1] * (n + 1) self.inv = [1] * (n + 1) for j in range(1, n + 1): self.fac[j] = self.fac[j - 1] * j % mod self.inv[n] = pow(self.fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): self.inv[j] = self.inv[j + 1] * (j + 1) % mod def comb(self, n, r, mod): if r > n or n < 0 or r < 0: return 0 return self.fac[n] * self.inv[n - r] * self.inv[r] % mod import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) mod = 10**9 + 7 inf = float('inf') ans = int(0) N, M, K = LI() cou = int(0) #maxL = N + M -2 L = int(0) #距離i+1の組み合わせ #for i in range(maxL): for j in range(N): L += (N - j - 1) * (M ** 2) * (j + 1) L %= mod for j in range(M): L += (M - j - 1) * (N ** 2) * (j + 1) L %= mod # for j in range(i+2): # if i>1 and i+1>j>0: # L[i] += max((N-j)*(M-(1+i)+j),0)*(i+1)*2 # else: # L[i] += max(((N - j) * (M - (1 + i) + j)), 0) * (i + 1) C = combination(N*M-2,mod) cou = C.comb(N*M-2,K-2,mod)*L%mod print(cou)
62
49
1,475
1,270
from operator import mul from functools import reduce def comb2(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 def comb3(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 import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) mod = 10**9 + 7 inf = float("inf") ans = int(0) N, M, K = LI() cou = int(0) # maxL = N + M -2 L = int(0) # 距離i+1の組み合わせ # for i in range(maxL): for j in range(N): L += (N - j - 1) * (M**2) * (j + 1) for j in range(M): L += (M - j - 1) * (N**2) * (j + 1) # for j in range(i+2): # if i>1 and i+1>j>0: # L[i] += max((N-j)*(M-(1+i)+j),0)*(i+1)*2 # else: # L[i] += max(((N - j) * (M - (1 + i) + j)), 0) * (i + 1) cou = comb3(N * M - 2, K - 2) % mod ans = cou * L % mod print(ans)
class combination: # 素数のmod取るときのみ 速い def __init__(self, n, mod): self.n = n self.fac = [1] * (n + 1) self.inv = [1] * (n + 1) for j in range(1, n + 1): self.fac[j] = self.fac[j - 1] * j % mod self.inv[n] = pow(self.fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): self.inv[j] = self.inv[j + 1] * (j + 1) % mod def comb(self, n, r, mod): if r > n or n < 0 or r < 0: return 0 return self.fac[n] * self.inv[n - r] * self.inv[r] % mod import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) mod = 10**9 + 7 inf = float("inf") ans = int(0) N, M, K = LI() cou = int(0) # maxL = N + M -2 L = int(0) # 距離i+1の組み合わせ # for i in range(maxL): for j in range(N): L += (N - j - 1) * (M**2) * (j + 1) L %= mod for j in range(M): L += (M - j - 1) * (N**2) * (j + 1) L %= mod # for j in range(i+2): # if i>1 and i+1>j>0: # L[i] += max((N-j)*(M-(1+i)+j),0)*(i+1)*2 # else: # L[i] += max(((N - j) * (M - (1 + i) + j)), 0) * (i + 1) C = combination(N * M - 2, mod) cou = C.comb(N * M - 2, K - 2, mod) * L % mod print(cou)
false
20.967742
[ "-from operator import mul", "-from functools import reduce", "+class combination:", "+ # 素数のmod取るときのみ 速い", "+ def __init__(self, n, mod):", "+ self.n = n", "+ self.fac = [1] * (n + 1)", "+ self.inv = [1] * (n + 1)", "+ for j in range(1, n + 1):", "+ self.fac[j] = self.fac[j - 1] * j % mod", "+ self.inv[n] = pow(self.fac[n], mod - 2, mod)", "+ for j in range(n - 1, -1, -1):", "+ self.inv[j] = self.inv[j + 1] * (j + 1) % mod", "-", "-def comb2(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", "-", "-", "-def comb3(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", "+ def comb(self, n, r, mod):", "+ if r > n or n < 0 or r < 0:", "+ return 0", "+ return self.fac[n] * self.inv[n - r] * self.inv[r] % mod", "+ L %= mod", "+ L %= mod", "-cou = comb3(N * M - 2, K - 2) % mod", "-ans = cou * L % mod", "-print(ans)", "+C = combination(N * M - 2, mod)", "+cou = C.comb(N * M - 2, K - 2, mod) * L % mod", "+print(cou)" ]
false
0.093219
0.039463
2.362164
[ "s242061391", "s856618448" ]
u241159583
p03545
python
s717148425
s269057223
20
18
3,060
3,060
Accepted
Accepted
10
from itertools import product A, B, C, D = list(eval(input())) l = len(A) for ops in product(["+", "-"], repeat=3): eq = A + ops[0] + B + ops[1] + C + ops[2] + D x = eval(eq) if x == 7: break print((eq + "=7"))
import itertools a,b,c,d = list(eval(input())) for i in itertools.product(["+", "-"], repeat=3): x = a + i[0] + b + i[1] + c + i[2] + d if eval(x) == 7:break print((x+"=7"))
10
6
222
174
from itertools import product A, B, C, D = list(eval(input())) l = len(A) for ops in product(["+", "-"], repeat=3): eq = A + ops[0] + B + ops[1] + C + ops[2] + D x = eval(eq) if x == 7: break print((eq + "=7"))
import itertools a, b, c, d = list(eval(input())) for i in itertools.product(["+", "-"], repeat=3): x = a + i[0] + b + i[1] + c + i[2] + d if eval(x) == 7: break print((x + "=7"))
false
40
[ "-from itertools import product", "+import itertools", "-A, B, C, D = list(eval(input()))", "-l = len(A)", "-for ops in product([\"+\", \"-\"], repeat=3):", "- eq = A + ops[0] + B + ops[1] + C + ops[2] + D", "- x = eval(eq)", "- if x == 7:", "+a, b, c, d = list(eval(input()))", "+for i in itertools.product([\"+\", \"-\"], repeat=3):", "+ x = a + i[0] + b + i[1] + c + i[2] + d", "+ if eval(x) == 7:", "-print((eq + \"=7\"))", "+print((x + \"=7\"))" ]
false
0.037911
0.038848
0.975868
[ "s717148425", "s269057223" ]
u736524428
p02775
python
s368413560
s207464974
1,313
1,128
84,696
5,492
Accepted
Accepted
14.09
N = eval(input()) DP_just = [0] DP_plus = [1] for c in N: d = int(c) last_just = DP_just[-1] last_plus = DP_plus[-1] DP_just.append(min(last_just + d, last_plus + 10 - d)) d += 1 DP_plus.append(min(last_just + d, last_plus + 10 - d)) print((DP_just[-1]))
N = eval(input()) DP_just = 0 DP_plus = 1 for c in N: d = int(c) last_just = DP_just last_plus = DP_plus DP_just = min(last_just + d, last_plus + 10 - d) d += 1 DP_plus = min(last_just + d, last_plus + 10 - d) print(DP_just)
14
14
286
258
N = eval(input()) DP_just = [0] DP_plus = [1] for c in N: d = int(c) last_just = DP_just[-1] last_plus = DP_plus[-1] DP_just.append(min(last_just + d, last_plus + 10 - d)) d += 1 DP_plus.append(min(last_just + d, last_plus + 10 - d)) print((DP_just[-1]))
N = eval(input()) DP_just = 0 DP_plus = 1 for c in N: d = int(c) last_just = DP_just last_plus = DP_plus DP_just = min(last_just + d, last_plus + 10 - d) d += 1 DP_plus = min(last_just + d, last_plus + 10 - d) print(DP_just)
false
0
[ "-DP_just = [0]", "-DP_plus = [1]", "+DP_just = 0", "+DP_plus = 1", "- last_just = DP_just[-1]", "- last_plus = DP_plus[-1]", "- DP_just.append(min(last_just + d, last_plus + 10 - d))", "+ last_just = DP_just", "+ last_plus = DP_plus", "+ DP_just = min(last_just + d, last_plus + 10 - d)", "- DP_plus.append(min(last_just + d, last_plus + 10 - d))", "-print((DP_just[-1]))", "+ DP_plus = min(last_just + d, last_plus + 10 - d)", "+print(DP_just)" ]
false
0.044765
0.045204
0.990296
[ "s368413560", "s207464974" ]
u773265208
p02700
python
s182680656
s876264571
24
19
9,156
9,152
Accepted
Accepted
20.83
import math a,b,c,d = list(map(int,input().split())) ans1 = math.ceil(a / d) ans2 = math.ceil(c / b) if ans1 < ans2: print('No') else: print('Yes')
import math a,b,c,d = list(map(int,input().split())) num1 = math.ceil(c / b) num2 = math.ceil(a / d) if num1 <= num2: print('Yes') else: print('No')
11
11
159
164
import math a, b, c, d = list(map(int, input().split())) ans1 = math.ceil(a / d) ans2 = math.ceil(c / b) if ans1 < ans2: print("No") else: print("Yes")
import math a, b, c, d = list(map(int, input().split())) num1 = math.ceil(c / b) num2 = math.ceil(a / d) if num1 <= num2: print("Yes") else: print("No")
false
0
[ "-ans1 = math.ceil(a / d)", "-ans2 = math.ceil(c / b)", "-if ans1 < ans2:", "+num1 = math.ceil(c / b)", "+num2 = math.ceil(a / d)", "+if num1 <= num2:", "+ print(\"Yes\")", "+else:", "-else:", "- print(\"Yes\")" ]
false
0.043018
0.043978
0.978174
[ "s182680656", "s876264571" ]
u411203878
p03032
python
s939643993
s687200064
202
70
41,836
68,432
Accepted
Accepted
65.35
n,k=list(map(int,input().split())) V=list(map(int,input().split())) ans=0 for i in range(n+1): for j in range(n-i+1): #print(i, j) if i+j>k: continue tmp=V[:i]+V[n-j:] tmp.sort(reverse=True) for l in range(k-i-j): if tmp and tmp[-1]<0: tmp.pop() else: break ans=max(ans,sum(tmp)) print(ans)
n,k = list(map(int,input().split())) v = list(map(int,input().split())) res = 0 for i in range(n+1): for j in range(n-i+1): if k < i+j: continue memo = v[:i] + v[n-j:] memo.sort() for _ in range(k-i-j): if memo and memo[0] < 0: memo.pop(0) else: break res = max(res,sum(memo)) print(res)
17
21
420
426
n, k = list(map(int, input().split())) V = list(map(int, input().split())) ans = 0 for i in range(n + 1): for j in range(n - i + 1): # print(i, j) if i + j > k: continue tmp = V[:i] + V[n - j :] tmp.sort(reverse=True) for l in range(k - i - j): if tmp and tmp[-1] < 0: tmp.pop() else: break ans = max(ans, sum(tmp)) print(ans)
n, k = list(map(int, input().split())) v = list(map(int, input().split())) res = 0 for i in range(n + 1): for j in range(n - i + 1): if k < i + j: continue memo = v[:i] + v[n - j :] memo.sort() for _ in range(k - i - j): if memo and memo[0] < 0: memo.pop(0) else: break res = max(res, sum(memo)) print(res)
false
19.047619
[ "-V = list(map(int, input().split()))", "-ans = 0", "+v = list(map(int, input().split()))", "+res = 0", "- # print(i, j)", "- if i + j > k:", "+ if k < i + j:", "- tmp = V[:i] + V[n - j :]", "- tmp.sort(reverse=True)", "- for l in range(k - i - j):", "- if tmp and tmp[-1] < 0:", "- tmp.pop()", "+ memo = v[:i] + v[n - j :]", "+ memo.sort()", "+ for _ in range(k - i - j):", "+ if memo and memo[0] < 0:", "+ memo.pop(0)", "- ans = max(ans, sum(tmp))", "-print(ans)", "+ res = max(res, sum(memo))", "+print(res)" ]
false
0.037866
0.043154
0.877454
[ "s939643993", "s687200064" ]
u879870653
p03163
python
s498982507
s942221718
645
498
171,656
120,300
Accepted
Accepted
22.79
N,W = list(map(int,input().split())) L = [list(map(int,input().split())) for i in range(N)] dp = [[0 for i in range(W+1)] for j in range(N+1)] for i in range(N) : weight_i,value_i = L[i] for weight in range(W+1) : if weight - weight_i >= 0 : dp[i+1][weight] = max(dp[i][weight], dp[i][weight - weight_i] + value_i) else : dp[i+1][weight] = dp[i][weight] ans = dp[N][W] print(ans)
n,w = list(map(int,input().split())) dp = [[0]*(w+1) for i in range(n+1)] for i in range(1, n+1) : a, v = list(map(int,input().split())) for j in range(1, w+1) : if j < a : dp[i][j] = max(dp[i-1][j], dp[i][j-1]) else : dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-a]+v) print((dp[n][w]))
16
13
441
341
N, W = list(map(int, input().split())) L = [list(map(int, input().split())) for i in range(N)] dp = [[0 for i in range(W + 1)] for j in range(N + 1)] for i in range(N): weight_i, value_i = L[i] for weight in range(W + 1): if weight - weight_i >= 0: dp[i + 1][weight] = max(dp[i][weight], dp[i][weight - weight_i] + value_i) else: dp[i + 1][weight] = dp[i][weight] ans = dp[N][W] print(ans)
n, w = list(map(int, input().split())) dp = [[0] * (w + 1) for i in range(n + 1)] for i in range(1, n + 1): a, v = list(map(int, input().split())) for j in range(1, w + 1): if j < a: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - a] + v) print((dp[n][w]))
false
18.75
[ "-N, W = list(map(int, input().split()))", "-L = [list(map(int, input().split())) for i in range(N)]", "-dp = [[0 for i in range(W + 1)] for j in range(N + 1)]", "-for i in range(N):", "- weight_i, value_i = L[i]", "- for weight in range(W + 1):", "- if weight - weight_i >= 0:", "- dp[i + 1][weight] = max(dp[i][weight], dp[i][weight - weight_i] + value_i)", "+n, w = list(map(int, input().split()))", "+dp = [[0] * (w + 1) for i in range(n + 1)]", "+for i in range(1, n + 1):", "+ a, v = list(map(int, input().split()))", "+ for j in range(1, w + 1):", "+ if j < a:", "+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])", "- dp[i + 1][weight] = dp[i][weight]", "-ans = dp[N][W]", "-print(ans)", "+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - a] + v)", "+print((dp[n][w]))" ]
false
0.044351
0.095993
0.462026
[ "s498982507", "s942221718" ]
u337626942
p03038
python
s736493420
s503754232
938
402
71,064
88,936
Accepted
Accepted
57.14
N, M=list(map(int, input().split())) a=list(map(int, input().split())) a.sort() card=[] for i in range(M): b, c=list(map(int, input().split())) card.append((c, b)) card.sort(reverse=True) k=0 for c, b in card: while k < N and b > 0: if a[k]<c: a[k]=c b-=1 k+=1 print((sum(a)))
n, m=list(map(int, input().split())) a=list(map(int, input().split())) a.sort() change=[] for i in range(m): b, c=list(map(int, input().split())) change.append((c, b)) change.sort(reverse=True) elem=0 for c, b in change: while elem<n and b>0: if a[elem]<c: a[elem]=c b-=1 elem+=1 print((sum(a)))
20
20
337
356
N, M = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() card = [] for i in range(M): b, c = list(map(int, input().split())) card.append((c, b)) card.sort(reverse=True) k = 0 for c, b in card: while k < N and b > 0: if a[k] < c: a[k] = c b -= 1 k += 1 print((sum(a)))
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() change = [] for i in range(m): b, c = list(map(int, input().split())) change.append((c, b)) change.sort(reverse=True) elem = 0 for c, b in change: while elem < n and b > 0: if a[elem] < c: a[elem] = c b -= 1 elem += 1 print((sum(a)))
false
0
[ "-N, M = list(map(int, input().split()))", "+n, m = list(map(int, input().split()))", "-card = []", "-for i in range(M):", "+change = []", "+for i in range(m):", "- card.append((c, b))", "-card.sort(reverse=True)", "-k = 0", "-for c, b in card:", "- while k < N and b > 0:", "- if a[k] < c:", "- a[k] = c", "+ change.append((c, b))", "+change.sort(reverse=True)", "+elem = 0", "+for c, b in change:", "+ while elem < n and b > 0:", "+ if a[elem] < c:", "+ a[elem] = c", "- k += 1", "+ elem += 1" ]
false
0.126883
0.006803
18.651809
[ "s736493420", "s503754232" ]
u046158516
p03213
python
s574375882
s532437189
174
75
38,512
61,976
Accepted
Accepted
56.9
n=int(eval(input())) m=[0]*101 for i in range(1,n+1): for j in range(2,n+1): while i%j==0: a=i//j while (a+1)*j<=i: a+=1 i=a m[j]+=1 counter75=0 counter25=0 counter15=0 counter5=0 counter3=0 for i in range(101): if m[i]>=74: counter75+=1 if m[i]>=24: counter25+=1 if m[i]>=14: counter15+=1 if m[i]>=4: counter5+=1 if m[i]>=2: counter3+=1 a=(counter5*(counter5-1)*(counter3-2))//2 while (a+1)*2<=(counter5*(counter5-1)*(counter3-2)): a+=1 print((counter75+counter25*(counter3-1)+counter15*(counter5-1)+a))
import sys primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] num3=0 num5=0 num15=0 num25=0 num75=0 n=int(eval(input())) for i in primes: tmp=0 j=1 while n//pow(i,j)>0: tmp+=n//pow(i,j) j+=1 if tmp>=2: num3+=1 if tmp>=4: num5+=1 if tmp>=14: num15+=1 if tmp>=24: num25+=1 if tmp>=74: num75+=1 print((num75+max(0,(num3-1)*num25)+max(0,((num3-2)*(num5-1)*num5)//2)+max(0,((num5-1)*num15))))
30
27
596
506
n = int(eval(input())) m = [0] * 101 for i in range(1, n + 1): for j in range(2, n + 1): while i % j == 0: a = i // j while (a + 1) * j <= i: a += 1 i = a m[j] += 1 counter75 = 0 counter25 = 0 counter15 = 0 counter5 = 0 counter3 = 0 for i in range(101): if m[i] >= 74: counter75 += 1 if m[i] >= 24: counter25 += 1 if m[i] >= 14: counter15 += 1 if m[i] >= 4: counter5 += 1 if m[i] >= 2: counter3 += 1 a = (counter5 * (counter5 - 1) * (counter3 - 2)) // 2 while (a + 1) * 2 <= (counter5 * (counter5 - 1) * (counter3 - 2)): a += 1 print((counter75 + counter25 * (counter3 - 1) + counter15 * (counter5 - 1) + a))
import sys primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] num3 = 0 num5 = 0 num15 = 0 num25 = 0 num75 = 0 n = int(eval(input())) for i in primes: tmp = 0 j = 1 while n // pow(i, j) > 0: tmp += n // pow(i, j) j += 1 if tmp >= 2: num3 += 1 if tmp >= 4: num5 += 1 if tmp >= 14: num15 += 1 if tmp >= 24: num25 += 1 if tmp >= 74: num75 += 1 print( ( num75 + max(0, (num3 - 1) * num25) + max(0, ((num3 - 2) * (num5 - 1) * num5) // 2) + max(0, ((num5 - 1) * num15)) ) )
false
10
[ "+import sys", "+", "+primes = [", "+ 2,", "+ 3,", "+ 5,", "+ 7,", "+ 11,", "+ 13,", "+ 17,", "+ 19,", "+ 23,", "+ 29,", "+ 31,", "+ 37,", "+ 41,", "+ 43,", "+ 47,", "+ 53,", "+ 59,", "+ 61,", "+ 67,", "+ 71,", "+ 73,", "+ 79,", "+ 83,", "+ 89,", "+ 97,", "+]", "+num3 = 0", "+num5 = 0", "+num15 = 0", "+num25 = 0", "+num75 = 0", "-m = [0] * 101", "-for i in range(1, n + 1):", "- for j in range(2, n + 1):", "- while i % j == 0:", "- a = i // j", "- while (a + 1) * j <= i:", "- a += 1", "- i = a", "- m[j] += 1", "-counter75 = 0", "-counter25 = 0", "-counter15 = 0", "-counter5 = 0", "-counter3 = 0", "-for i in range(101):", "- if m[i] >= 74:", "- counter75 += 1", "- if m[i] >= 24:", "- counter25 += 1", "- if m[i] >= 14:", "- counter15 += 1", "- if m[i] >= 4:", "- counter5 += 1", "- if m[i] >= 2:", "- counter3 += 1", "-a = (counter5 * (counter5 - 1) * (counter3 - 2)) // 2", "-while (a + 1) * 2 <= (counter5 * (counter5 - 1) * (counter3 - 2)):", "- a += 1", "-print((counter75 + counter25 * (counter3 - 1) + counter15 * (counter5 - 1) + a))", "+for i in primes:", "+ tmp = 0", "+ j = 1", "+ while n // pow(i, j) > 0:", "+ tmp += n // pow(i, j)", "+ j += 1", "+ if tmp >= 2:", "+ num3 += 1", "+ if tmp >= 4:", "+ num5 += 1", "+ if tmp >= 14:", "+ num15 += 1", "+ if tmp >= 24:", "+ num25 += 1", "+ if tmp >= 74:", "+ num75 += 1", "+print(", "+ (", "+ num75", "+ + max(0, (num3 - 1) * num25)", "+ + max(0, ((num3 - 2) * (num5 - 1) * num5) // 2)", "+ + max(0, ((num5 - 1) * num15))", "+ )", "+)" ]
false
0.089695
0.046624
1.923792
[ "s574375882", "s532437189" ]
u888337853
p02586
python
s480985521
s638658901
2,605
1,641
230,824
224,280
Accepted
Accepted
37.01
import sys import math import collections import bisect import itertools # import numpy as np sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline().rstrip()) ns = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()]) # ===CODE=== def main(): r, c, k = ns() mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)] for _ in range(k): x, y, v = ns() x, y = x - 1, y - 1 mat[x][y] = v dp = [[0 for __ in range(4)] for _ in range(c + 1)] for i in range(r): ndp = [[0 for __ in range(4)] for _ in range(c + 1)] for j in range(c): for n in range(2, -1, -1): dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j]) ndp[j][0] = max(dp[j]) for n in range(4): dp[j + 1][n] = max(dp[j + 1][n], dp[j][n]) dp = ndp print((max(dp[c - 1]))) if __name__ == '__main__': main()
import sys import math import collections import bisect import itertools # import numpy as np sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline().rstrip()) ns = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()]) # ===CODE=== def main(): r, c, k = ns() mat = [[0]*(c + 1) for __ in range(r + 1)] for _ in range(k): x, y, v = ns() x, y = x - 1, y - 1 mat[x][y] = v dp = [[0]*4 for _ in range(c + 1)] for i in range(r): ndp = [[0]*4 for _ in range(c + 1)] for j in range(c): for n in range(2, -1, -1): dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j]) ndp[j][0] = max(dp[j]) for n in range(4): dp[j + 1][n] = max(dp[j + 1][n], dp[j][n]) dp = ndp print((max(dp[c - 1]))) if __name__ == '__main__': main()
48
48
1,181
1,133
import sys import math import collections import bisect import itertools # import numpy as np sys.setrecursionlimit(10**7) INF = 10**20 MOD = 10**9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline().rstrip()) ns = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()]) # ===CODE=== def main(): r, c, k = ns() mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)] for _ in range(k): x, y, v = ns() x, y = x - 1, y - 1 mat[x][y] = v dp = [[0 for __ in range(4)] for _ in range(c + 1)] for i in range(r): ndp = [[0 for __ in range(4)] for _ in range(c + 1)] for j in range(c): for n in range(2, -1, -1): dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j]) ndp[j][0] = max(dp[j]) for n in range(4): dp[j + 1][n] = max(dp[j + 1][n], dp[j][n]) dp = ndp print((max(dp[c - 1]))) if __name__ == "__main__": main()
import sys import math import collections import bisect import itertools # import numpy as np sys.setrecursionlimit(10**7) INF = 10**20 MOD = 10**9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline().rstrip()) ns = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()]) # ===CODE=== def main(): r, c, k = ns() mat = [[0] * (c + 1) for __ in range(r + 1)] for _ in range(k): x, y, v = ns() x, y = x - 1, y - 1 mat[x][y] = v dp = [[0] * 4 for _ in range(c + 1)] for i in range(r): ndp = [[0] * 4 for _ in range(c + 1)] for j in range(c): for n in range(2, -1, -1): dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j]) ndp[j][0] = max(dp[j]) for n in range(4): dp[j + 1][n] = max(dp[j + 1][n], dp[j][n]) dp = ndp print((max(dp[c - 1]))) if __name__ == "__main__": main()
false
0
[ "- mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]", "+ mat = [[0] * (c + 1) for __ in range(r + 1)]", "- dp = [[0 for __ in range(4)] for _ in range(c + 1)]", "+ dp = [[0] * 4 for _ in range(c + 1)]", "- ndp = [[0 for __ in range(4)] for _ in range(c + 1)]", "+ ndp = [[0] * 4 for _ in range(c + 1)]" ]
false
0.042384
0.067526
0.627668
[ "s480985521", "s638658901" ]
u540631540
p02819
python
s656843419
s254376544
46
31
3,828
3,060
Accepted
Accepted
32.61
x = int(eval(input())) p = [True] * 100004 p[0] = False p[1] = False for i in range(int(100003 ** 0.5)): if p[i] == False: continue for j in range(2, 100003 // i + 1): p[i * j] = False for i in range(x, 100004): if p[i] == True: print(i) break
x = int(eval(input())) for i in range(x, 100003 + 1): for j in range(2, i): if i % j == 0: break else: print(i) break
13
8
293
162
x = int(eval(input())) p = [True] * 100004 p[0] = False p[1] = False for i in range(int(100003**0.5)): if p[i] == False: continue for j in range(2, 100003 // i + 1): p[i * j] = False for i in range(x, 100004): if p[i] == True: print(i) break
x = int(eval(input())) for i in range(x, 100003 + 1): for j in range(2, i): if i % j == 0: break else: print(i) break
false
38.461538
[ "-p = [True] * 100004", "-p[0] = False", "-p[1] = False", "-for i in range(int(100003**0.5)):", "- if p[i] == False:", "- continue", "- for j in range(2, 100003 // i + 1):", "- p[i * j] = False", "-for i in range(x, 100004):", "- if p[i] == True:", "+for i in range(x, 100003 + 1):", "+ for j in range(2, i):", "+ if i % j == 0:", "+ break", "+ else:" ]
false
0.070868
0.10132
0.699446
[ "s656843419", "s254376544" ]
u562935282
p03283
python
s207773638
s195323597
720
575
15,588
19,084
Accepted
Accepted
20.14
class Acc2D: def __init__(self, src): self.acc2d = self._build(src) def _build(self, src): h, w = len(src), len(src[0]) ret = [[0] * w for _ in range(h)] for r in range(h): for c in range(w): ret[r][c] = src[r][c] if r > 0: ret[r][c] += ret[r - 1][c] if c > 0: ret[r][c] += ret[r][c - 1] if r > 0 and c > 0: ret[r][c] -= ret[r - 1][c - 1] return ret def get(self, r1, c1, r2, c2): """[(r1,c1),(r2,c2)]""" acc2d = self.acc2d ret = acc2d[r2][c2] if r1 > 0: ret -= acc2d[r1 - 1][c2] if c1 > 0: ret -= acc2d[r2][c1 - 1] if r1 > 0 and c1 > 0: ret += acc2d[r1 - 1][c1 - 1] return ret def main(): import sys input = sys.stdin.readline N, M, Q = list(map(int, input().split())) table = [[0] * (N + 1) for _ in range(N + 1)] for _ in range(M): L, R = list(map(int, input().split())) table[L][R] += 1 acc2d = Acc2D(table) for _ in range(Q): p, q = list(map(int, input().split())) res = acc2d.get(p, p, q, q) print(res) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.readline N, M, Q = map(int, input().split()) tb = [[0] * (N + 1) for _ in range(N + 1)] # tb[L][R]:=区間LR内を走る列車総数 for _ in range(M): L, R = map(int, input().split()) tb[L][R] += 1 for L in range(1, N + 1): for R in range(1, N + 1): tb[L][R] += tb[L - 1][R] tb[L][R] += tb[L][R - 1] tb[L][R] -= tb[L - 1][R - 1] ans = [] for _ in range(Q): p, q = map(int, input().split()) ans.append(tb[q][q] - tb[p - 1][q] - tb[q][p - 1] + tb[p - 1][p - 1]) print(*ans, sep='\n') if __name__ == '__main__': main()
55
28
1,344
692
class Acc2D: def __init__(self, src): self.acc2d = self._build(src) def _build(self, src): h, w = len(src), len(src[0]) ret = [[0] * w for _ in range(h)] for r in range(h): for c in range(w): ret[r][c] = src[r][c] if r > 0: ret[r][c] += ret[r - 1][c] if c > 0: ret[r][c] += ret[r][c - 1] if r > 0 and c > 0: ret[r][c] -= ret[r - 1][c - 1] return ret def get(self, r1, c1, r2, c2): """[(r1,c1),(r2,c2)]""" acc2d = self.acc2d ret = acc2d[r2][c2] if r1 > 0: ret -= acc2d[r1 - 1][c2] if c1 > 0: ret -= acc2d[r2][c1 - 1] if r1 > 0 and c1 > 0: ret += acc2d[r1 - 1][c1 - 1] return ret def main(): import sys input = sys.stdin.readline N, M, Q = list(map(int, input().split())) table = [[0] * (N + 1) for _ in range(N + 1)] for _ in range(M): L, R = list(map(int, input().split())) table[L][R] += 1 acc2d = Acc2D(table) for _ in range(Q): p, q = list(map(int, input().split())) res = acc2d.get(p, p, q, q) print(res) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.readline N, M, Q = map(int, input().split()) tb = [[0] * (N + 1) for _ in range(N + 1)] # tb[L][R]:=区間LR内を走る列車総数 for _ in range(M): L, R = map(int, input().split()) tb[L][R] += 1 for L in range(1, N + 1): for R in range(1, N + 1): tb[L][R] += tb[L - 1][R] tb[L][R] += tb[L][R - 1] tb[L][R] -= tb[L - 1][R - 1] ans = [] for _ in range(Q): p, q = map(int, input().split()) ans.append(tb[q][q] - tb[p - 1][q] - tb[q][p - 1] + tb[p - 1][p - 1]) print(*ans, sep="\n") if __name__ == "__main__": main()
false
49.090909
[ "-class Acc2D:", "- def __init__(self, src):", "- self.acc2d = self._build(src)", "-", "- def _build(self, src):", "- h, w = len(src), len(src[0])", "- ret = [[0] * w for _ in range(h)]", "- for r in range(h):", "- for c in range(w):", "- ret[r][c] = src[r][c]", "- if r > 0:", "- ret[r][c] += ret[r - 1][c]", "- if c > 0:", "- ret[r][c] += ret[r][c - 1]", "- if r > 0 and c > 0:", "- ret[r][c] -= ret[r - 1][c - 1]", "- return ret", "-", "- def get(self, r1, c1, r2, c2):", "- \"\"\"[(r1,c1),(r2,c2)]\"\"\"", "- acc2d = self.acc2d", "- ret = acc2d[r2][c2]", "- if r1 > 0:", "- ret -= acc2d[r1 - 1][c2]", "- if c1 > 0:", "- ret -= acc2d[r2][c1 - 1]", "- if r1 > 0 and c1 > 0:", "- ret += acc2d[r1 - 1][c1 - 1]", "- return ret", "-", "-", "- N, M, Q = list(map(int, input().split()))", "- table = [[0] * (N + 1) for _ in range(N + 1)]", "+ N, M, Q = map(int, input().split())", "+ tb = [[0] * (N + 1) for _ in range(N + 1)]", "+ # tb[L][R]:=区間LR内を走る列車総数", "- L, R = list(map(int, input().split()))", "- table[L][R] += 1", "- acc2d = Acc2D(table)", "+ L, R = map(int, input().split())", "+ tb[L][R] += 1", "+ for L in range(1, N + 1):", "+ for R in range(1, N + 1):", "+ tb[L][R] += tb[L - 1][R]", "+ tb[L][R] += tb[L][R - 1]", "+ tb[L][R] -= tb[L - 1][R - 1]", "+ ans = []", "- p, q = list(map(int, input().split()))", "- res = acc2d.get(p, p, q, q)", "- print(res)", "+ p, q = map(int, input().split())", "+ ans.append(tb[q][q] - tb[p - 1][q] - tb[q][p - 1] + tb[p - 1][p - 1])", "+ print(*ans, sep=\"\\n\")" ]
false
0.065391
0.04261
1.534626
[ "s207773638", "s195323597" ]
u823044869
p03478
python
s917336548
s505452515
46
40
2,940
2,940
Accepted
Accepted
13.04
n, a, b = list(map(int,input().split())) result_sum = 0 for i in range(1,n+1): keta_sum = 0 for j in range(len(str(i))): keta_sum += int(str(i)[j]) if a <= keta_sum and b >= keta_sum: result_sum += i keta_sum = 0 print(result_sum)
n,b,c = list(map(int,input().split())) count = 0 for i in range(1,n+1): #startnumber, endnumber s = str(i) numSum = 0 for si in range(len(s)): numSum += int(s[si]) if numSum >= b and numSum <= c: count += i print(count)
14
13
274
248
n, a, b = list(map(int, input().split())) result_sum = 0 for i in range(1, n + 1): keta_sum = 0 for j in range(len(str(i))): keta_sum += int(str(i)[j]) if a <= keta_sum and b >= keta_sum: result_sum += i keta_sum = 0 print(result_sum)
n, b, c = list(map(int, input().split())) count = 0 for i in range(1, n + 1): # startnumber, endnumber s = str(i) numSum = 0 for si in range(len(s)): numSum += int(s[si]) if numSum >= b and numSum <= c: count += i print(count)
false
7.142857
[ "-n, a, b = list(map(int, input().split()))", "-result_sum = 0", "-for i in range(1, n + 1):", "- keta_sum = 0", "- for j in range(len(str(i))):", "- keta_sum += int(str(i)[j])", "- if a <= keta_sum and b >= keta_sum:", "- result_sum += i", "- keta_sum = 0", "-print(result_sum)", "+n, b, c = list(map(int, input().split()))", "+count = 0", "+for i in range(1, n + 1): # startnumber, endnumber", "+ s = str(i)", "+ numSum = 0", "+ for si in range(len(s)):", "+ numSum += int(s[si])", "+ if numSum >= b and numSum <= c:", "+ count += i", "+print(count)" ]
false
0.008012
0.039912
0.20075
[ "s917336548", "s505452515" ]
u875361824
p03401
python
s926582534
s694718932
219
199
17,104
14,164
Accepted
Accepted
9.13
def main(): N = int(eval(input())) *A, = list(map(int, input().split())) f(N, A) def f(N, A): """ 2 ≤ N ≤ 10^5 −5000 ≤ Ai ≤ 5000 (1≤ i≤ N) 第一印象: 累積和? """ costs = [abs(A[0])] costs_cumsum = [abs(A[0])] for i in range(1, N): cost = abs(A[i] - A[i-1]) cumsum = cost + costs_cumsum[-1] costs.append(cost) costs_cumsum.append(cumsum) # 0へ戻る cost_N_to_start = abs(A[-1]) costs.append(cost_N_to_start) costs_cumsum.append(cost_N_to_start + costs_cumsum[-1]) for i in range(N): total = costs_cumsum[-1] # skip: i-1 to i and i to i+1 total -= (costs[i] + costs[i+1]) # add: i-1 to i+1 bef, aft = 0, 0 if i - 1 >= 0: bef = A[i-1] if i + 1 < N: aft = A[i+1] total += abs(bef - aft) print(total) if __name__ == '__main__': main()
def main(): N = int(eval(input())) *A, = list(map(int, input().split())) f(N, A) def f(N, A): """ 2 ≤ N ≤ 10^5 −5000 ≤ Ai ≤ 5000 (1≤ i≤ N) 第一印象: 累積和? →不要,合計のみ必要だった """ costs = [abs(A[0])] for i in range(1, N): cost = abs(A[i] - A[i-1]) costs.append(cost) # 0へ戻る cost_N_to_start = abs(A[-1]) costs.append(cost_N_to_start) costs_cumsum = sum(costs) for i in range(N): total = costs_cumsum # skip: i-1 to i and i to i+1 total -= (costs[i] + costs[i+1]) # add: i-1 to i+1 bef, aft = 0, 0 if i - 1 >= 0: bef = A[i-1] if i + 1 < N: aft = A[i+1] total += abs(bef - aft) print(total) if __name__ == '__main__': main()
46
43
958
830
def main(): N = int(eval(input())) (*A,) = list(map(int, input().split())) f(N, A) def f(N, A): """ 2 ≤ N ≤ 10^5 −5000 ≤ Ai ≤ 5000 (1≤ i≤ N) 第一印象: 累積和? """ costs = [abs(A[0])] costs_cumsum = [abs(A[0])] for i in range(1, N): cost = abs(A[i] - A[i - 1]) cumsum = cost + costs_cumsum[-1] costs.append(cost) costs_cumsum.append(cumsum) # 0へ戻る cost_N_to_start = abs(A[-1]) costs.append(cost_N_to_start) costs_cumsum.append(cost_N_to_start + costs_cumsum[-1]) for i in range(N): total = costs_cumsum[-1] # skip: i-1 to i and i to i+1 total -= costs[i] + costs[i + 1] # add: i-1 to i+1 bef, aft = 0, 0 if i - 1 >= 0: bef = A[i - 1] if i + 1 < N: aft = A[i + 1] total += abs(bef - aft) print(total) if __name__ == "__main__": main()
def main(): N = int(eval(input())) (*A,) = list(map(int, input().split())) f(N, A) def f(N, A): """ 2 ≤ N ≤ 10^5 −5000 ≤ Ai ≤ 5000 (1≤ i≤ N) 第一印象: 累積和? →不要,合計のみ必要だった """ costs = [abs(A[0])] for i in range(1, N): cost = abs(A[i] - A[i - 1]) costs.append(cost) # 0へ戻る cost_N_to_start = abs(A[-1]) costs.append(cost_N_to_start) costs_cumsum = sum(costs) for i in range(N): total = costs_cumsum # skip: i-1 to i and i to i+1 total -= costs[i] + costs[i + 1] # add: i-1 to i+1 bef, aft = 0, 0 if i - 1 >= 0: bef = A[i - 1] if i + 1 < N: aft = A[i + 1] total += abs(bef - aft) print(total) if __name__ == "__main__": main()
false
6.521739
[ "+ →不要,合計のみ必要だった", "- costs_cumsum = [abs(A[0])]", "- cumsum = cost + costs_cumsum[-1]", "- costs_cumsum.append(cumsum)", "- costs_cumsum.append(cost_N_to_start + costs_cumsum[-1])", "+ costs_cumsum = sum(costs)", "- total = costs_cumsum[-1]", "+ total = costs_cumsum" ]
false
0.045861
0.080543
0.569394
[ "s926582534", "s694718932" ]
u707124227
p03438
python
s694206503
s197834435
306
25
21,260
4,852
Accepted
Accepted
91.83
import numpy as np n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) d,e=0,0 for i in range(n): c=a[i]-b[i] if c>0: d+=c elif c%2==0: e+=-c else: e+=-c-1 print(('Yes' if 2*d<=e else 'No'))
def main(): n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=[a[i]-b[i] for i in range(n)] c0=sum([ci for ci in c if ci>0]) c1=sum([-2*((ci+2-1)//2) for ci in c if ci<0]) print(('Yes' if c1>=2*c0 else 'No')) if __name__=='__main__': main()
14
10
251
297
import numpy as np n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) d, e = 0, 0 for i in range(n): c = a[i] - b[i] if c > 0: d += c elif c % 2 == 0: e += -c else: e += -c - 1 print(("Yes" if 2 * d <= e else "No"))
def main(): n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [a[i] - b[i] for i in range(n)] c0 = sum([ci for ci in c if ci > 0]) c1 = sum([-2 * ((ci + 2 - 1) // 2) for ci in c if ci < 0]) print(("Yes" if c1 >= 2 * c0 else "No")) if __name__ == "__main__": main()
false
28.571429
[ "-import numpy as np", "+def main():", "+ n = int(eval(input()))", "+ a = list(map(int, input().split()))", "+ b = list(map(int, input().split()))", "+ c = [a[i] - b[i] for i in range(n)]", "+ c0 = sum([ci for ci in c if ci > 0])", "+ c1 = sum([-2 * ((ci + 2 - 1) // 2) for ci in c if ci < 0])", "+ print((\"Yes\" if c1 >= 2 * c0 else \"No\"))", "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-b = list(map(int, input().split()))", "-d, e = 0, 0", "-for i in range(n):", "- c = a[i] - b[i]", "- if c > 0:", "- d += c", "- elif c % 2 == 0:", "- e += -c", "- else:", "- e += -c - 1", "-print((\"Yes\" if 2 * d <= e else \"No\"))", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.036769
0.036612
1.004297
[ "s694206503", "s197834435" ]
u334712262
p02925
python
s884865252
s971864661
1,708
1,544
46,452
46,448
Accepted
Accepted
9.6
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, A): ans = 0 A = [list(reversed(a)) for a in A] s1 = set() s2 = set() def update(i): if not A[i-1]: return d = A[i-1][-1] n = (min(i, d), max(i, d)) if n not in s1: s1.add(n) else: s2.add(n) s1.remove(n) for i in range(1, N+1): update(i) while s2: ans += 1 for k in tuple(s2): a, b = k A[a-1].pop() A[b-1].pop() update(a) update(b) s2.remove(k) for a in A: if a: return -1 return ans def main(): N = read_int() A = [read_int_n() for _ in range(N)] print(slv(N, A)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, A): ans = 0 A = [list(reversed(a)) for a in A] s1 = set() s2 = set() def update(i): if not A[i-1]: return d = A[i-1][-1] n = (min(i, d), max(i, d)) if n not in s1: s1.add(n) else: s2.add(n) s1.remove(n) for i in range(1, N+1): update(i) while s2: ans += 1 s2_, s2 = s2, set() for k in s2_: a, b = k A[a-1].pop() A[b-1].pop() update(a) update(b) for a in A: if a: return -1 return ans def main(): N = read_int() A = [read_int_n() for _ in range(N)] print(slv(N, A)) if __name__ == '__main__': main()
106
106
1,906
1,903
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, A): ans = 0 A = [list(reversed(a)) for a in A] s1 = set() s2 = set() def update(i): if not A[i - 1]: return d = A[i - 1][-1] n = (min(i, d), max(i, d)) if n not in s1: s1.add(n) else: s2.add(n) s1.remove(n) for i in range(1, N + 1): update(i) while s2: ans += 1 for k in tuple(s2): a, b = k A[a - 1].pop() A[b - 1].pop() update(a) update(b) s2.remove(k) for a in A: if a: return -1 return ans def main(): N = read_int() A = [read_int_n() for _ in range(N)] print(slv(N, A)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, A): ans = 0 A = [list(reversed(a)) for a in A] s1 = set() s2 = set() def update(i): if not A[i - 1]: return d = A[i - 1][-1] n = (min(i, d), max(i, d)) if n not in s1: s1.add(n) else: s2.add(n) s1.remove(n) for i in range(1, N + 1): update(i) while s2: ans += 1 s2_, s2 = s2, set() for k in s2_: a, b = k A[a - 1].pop() A[b - 1].pop() update(a) update(b) for a in A: if a: return -1 return ans def main(): N = read_int() A = [read_int_n() for _ in range(N)] print(slv(N, A)) if __name__ == "__main__": main()
false
0
[ "- for k in tuple(s2):", "+ s2_, s2 = s2, set()", "+ for k in s2_:", "- s2.remove(k)" ]
false
0.038373
0.037105
1.034189
[ "s884865252", "s971864661" ]
u073549161
p03457
python
s587781133
s279707702
566
227
46,184
9,084
Accepted
Accepted
59.89
n = int(eval(input())) pt = 0 px, py = 0, 0 f = True for i in range(n): t, x, y = list(map(int, input().split())) dis = abs(px-x) + abs(py-y) dt = t - pt #print("dis{0} dt = {1}".format(dis, dt)) if dt >= dis and abs(dis - dt) % 2 == 0: pass else: f = False pt, px, py = t, x, y print(("Yes" if f else "No"))
n = int(eval(input())) can = True time = 0 x = 0 y = 0 for _ in range(n): t, xx, yy = list(map(int,input().split())) distance = abs(x-xx) + abs(y - yy) difft = t - time if difft < distance: can = False break if (distance - difft) % 2 == 1: can = False break x = xx y = yy time = t print(("Yes" if can else "No"))
15
21
353
384
n = int(eval(input())) pt = 0 px, py = 0, 0 f = True for i in range(n): t, x, y = list(map(int, input().split())) dis = abs(px - x) + abs(py - y) dt = t - pt # print("dis{0} dt = {1}".format(dis, dt)) if dt >= dis and abs(dis - dt) % 2 == 0: pass else: f = False pt, px, py = t, x, y print(("Yes" if f else "No"))
n = int(eval(input())) can = True time = 0 x = 0 y = 0 for _ in range(n): t, xx, yy = list(map(int, input().split())) distance = abs(x - xx) + abs(y - yy) difft = t - time if difft < distance: can = False break if (distance - difft) % 2 == 1: can = False break x = xx y = yy time = t print(("Yes" if can else "No"))
false
28.571429
[ "-pt = 0", "-px, py = 0, 0", "-f = True", "-for i in range(n):", "- t, x, y = list(map(int, input().split()))", "- dis = abs(px - x) + abs(py - y)", "- dt = t - pt", "- # print(\"dis{0} dt = {1}\".format(dis, dt))", "- if dt >= dis and abs(dis - dt) % 2 == 0:", "- pass", "- else:", "- f = False", "- pt, px, py = t, x, y", "-print((\"Yes\" if f else \"No\"))", "+can = True", "+time = 0", "+x = 0", "+y = 0", "+for _ in range(n):", "+ t, xx, yy = list(map(int, input().split()))", "+ distance = abs(x - xx) + abs(y - yy)", "+ difft = t - time", "+ if difft < distance:", "+ can = False", "+ break", "+ if (distance - difft) % 2 == 1:", "+ can = False", "+ break", "+ x = xx", "+ y = yy", "+ time = t", "+print((\"Yes\" if can else \"No\"))" ]
false
0.039653
0.04464
0.888273
[ "s587781133", "s279707702" ]
u367130284
p03986
python
s826813764
s611890193
81
63
5,096
4,328
Accepted
Accepted
22.22
ans=0 stack=[] for s in eval(input()): if len(stack)>0 and s=="T": if stack[-1]=="S": del stack[-1] else: stack.append(s) else: stack.append(s) print((len(stack)))
s=eval(input()) stack=[] ans=0 for i in s: if i=="S": stack.append(1) elif len(stack)>0 and i=="T": stack.pop() ans+=1 print((len(s)-ans*2))
11
10
221
174
ans = 0 stack = [] for s in eval(input()): if len(stack) > 0 and s == "T": if stack[-1] == "S": del stack[-1] else: stack.append(s) else: stack.append(s) print((len(stack)))
s = eval(input()) stack = [] ans = 0 for i in s: if i == "S": stack.append(1) elif len(stack) > 0 and i == "T": stack.pop() ans += 1 print((len(s) - ans * 2))
false
9.090909
[ "+s = eval(input())", "+stack = []", "-stack = []", "-for s in eval(input()):", "- if len(stack) > 0 and s == \"T\":", "- if stack[-1] == \"S\":", "- del stack[-1]", "- else:", "- stack.append(s)", "- else:", "- stack.append(s)", "-print((len(stack)))", "+for i in s:", "+ if i == \"S\":", "+ stack.append(1)", "+ elif len(stack) > 0 and i == \"T\":", "+ stack.pop()", "+ ans += 1", "+print((len(s) - ans * 2))" ]
false
0.047276
0.039419
1.19932
[ "s826813764", "s611890193" ]
u840310460
p03160
python
s974565524
s318642802
224
129
52,208
13,928
Accepted
Accepted
42.41
def func(): N = int(eval(input())) H = [int(i) for i in input().split()] dp = [0]*N for i in range(1, N): L = [] for j in range(max(0, i-2), i): L.append(dp[j] + abs(H[i] - H[j])) dp[i] = min(L) print((dp[-1])) if __name__=="__main__": func()
N = int(eval(input())) H = [int(i) for i in input().split()] dp = [0] * N dp[1] = abs(H[1] - H[0]) for i in range(2, N): dp[i] = min(dp[i-2] + abs(H[i] - H[i-2]), dp[i-1] + abs(H[i] - H[i-1])) print((dp[-1]))
15
9
319
214
def func(): N = int(eval(input())) H = [int(i) for i in input().split()] dp = [0] * N for i in range(1, N): L = [] for j in range(max(0, i - 2), i): L.append(dp[j] + abs(H[i] - H[j])) dp[i] = min(L) print((dp[-1])) if __name__ == "__main__": func()
N = int(eval(input())) H = [int(i) for i in input().split()] dp = [0] * N dp[1] = abs(H[1] - H[0]) for i in range(2, N): dp[i] = min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1])) print((dp[-1]))
false
40
[ "-def func():", "- N = int(eval(input()))", "- H = [int(i) for i in input().split()]", "- dp = [0] * N", "- for i in range(1, N):", "- L = []", "- for j in range(max(0, i - 2), i):", "- L.append(dp[j] + abs(H[i] - H[j]))", "- dp[i] = min(L)", "- print((dp[-1]))", "-", "-", "-if __name__ == \"__main__\":", "- func()", "+N = int(eval(input()))", "+H = [int(i) for i in input().split()]", "+dp = [0] * N", "+dp[1] = abs(H[1] - H[0])", "+for i in range(2, N):", "+ dp[i] = min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1]))", "+print((dp[-1]))" ]
false
0.038579
0.045648
0.845154
[ "s974565524", "s318642802" ]
u721316601
p03262
python
s469826129
s276711993
670
141
23,244
16,284
Accepted
Accepted
78.96
import numpy as np N, X = list(map(int, input().split())) x = np.array(list(map(int, input().split()))) x = np.abs(X - x) for i in range(N-1): a, b = x[i:i+2] while b > 0: a, b = b, a % b x[i+1] = a print((x[-1]))
#import math import fractions as math N, X = list(map(int, input().split())) x = sorted([X] + list(map(int, input().split()))) nums = [-(x[i]-x[i+1]) for i in range(N)] ans = 0 for n in nums: ans = math.gcd(ans, n) print(ans)
13
10
247
239
import numpy as np N, X = list(map(int, input().split())) x = np.array(list(map(int, input().split()))) x = np.abs(X - x) for i in range(N - 1): a, b = x[i : i + 2] while b > 0: a, b = b, a % b x[i + 1] = a print((x[-1]))
# import math import fractions as math N, X = list(map(int, input().split())) x = sorted([X] + list(map(int, input().split()))) nums = [-(x[i] - x[i + 1]) for i in range(N)] ans = 0 for n in nums: ans = math.gcd(ans, n) print(ans)
false
23.076923
[ "-import numpy as np", "+# import math", "+import fractions as math", "-x = np.array(list(map(int, input().split())))", "-x = np.abs(X - x)", "-for i in range(N - 1):", "- a, b = x[i : i + 2]", "- while b > 0:", "- a, b = b, a % b", "- x[i + 1] = a", "-print((x[-1]))", "+x = sorted([X] + list(map(int, input().split())))", "+nums = [-(x[i] - x[i + 1]) for i in range(N)]", "+ans = 0", "+for n in nums:", "+ ans = math.gcd(ans, n)", "+print(ans)" ]
false
0.17322
0.113508
1.526061
[ "s469826129", "s276711993" ]
u347640436
p02848
python
s435573703
s100073094
25
19
3,060
3,060
Accepted
Accepted
24
N = int(eval(input())) S = eval(input()) print((''.join(chr((ord(c) - ord('A') + N) % 26 + ord('A')) for c in S)))
N = int(eval(input())) S = eval(input()) bs = S.encode('us-ascii') print((bytes((b - 65 + N) % 26 + 65 for b in bs).decode('us-ascii')))
4
5
105
128
N = int(eval(input())) S = eval(input()) print(("".join(chr((ord(c) - ord("A") + N) % 26 + ord("A")) for c in S)))
N = int(eval(input())) S = eval(input()) bs = S.encode("us-ascii") print((bytes((b - 65 + N) % 26 + 65 for b in bs).decode("us-ascii")))
false
20
[ "-print((\"\".join(chr((ord(c) - ord(\"A\") + N) % 26 + ord(\"A\")) for c in S)))", "+bs = S.encode(\"us-ascii\")", "+print((bytes((b - 65 + N) % 26 + 65 for b in bs).decode(\"us-ascii\")))" ]
false
0.046101
0.038323
1.202964
[ "s435573703", "s100073094" ]
u059210959
p03625
python
s462920234
s309886775
204
88
25,868
24,140
Accepted
Accepted
56.86
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import math N = int(eval(input())) A = [int(i) for i in input().split()] A.sort() len_dic = {} for a in A: if a in list(len_dic.keys()): len_dic[a] += 1 else: len_dic[a] = 1 ans = [0,0] for k, v in sorted(list(len_dic.items()),key=lambda x:-x[0]): if v >= 4 and ans[0] == 0: ans = [k,k] elif v >= 2: if ans[0]==0: ans[0] = k elif ans[1] == 0: ans[1] = k print((ans[0]*ans[1]))
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N = int(eval(input())) A = LI() A_collection = collections.Counter(A) bars = [] for key in list(A_collection.keys()): if A_collection[key] > 1: bars.append(key) ans = 0 bars.sort(reverse = 1) if len(bars) > 1: ans = bars[0] * bars[1] if A_collection[bars[0]] > 3: ans = bars[0] ** 2 print(ans)
30
33
559
719
# encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import math N = int(eval(input())) A = [int(i) for i in input().split()] A.sort() len_dic = {} for a in A: if a in list(len_dic.keys()): len_dic[a] += 1 else: len_dic[a] = 1 ans = [0, 0] for k, v in sorted(list(len_dic.items()), key=lambda x: -x[0]): if v >= 4 and ans[0] == 0: ans = [k, k] elif v >= 2: if ans[0] == 0: ans[0] = k elif ans[1] == 0: ans[1] = k print((ans[0] * ans[1]))
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9 + 7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N = int(eval(input())) A = LI() A_collection = collections.Counter(A) bars = [] for key in list(A_collection.keys()): if A_collection[key] > 1: bars.append(key) ans = 0 bars.sort(reverse=1) if len(bars) > 1: ans = bars[0] * bars[1] if A_collection[bars[0]] > 3: ans = bars[0] ** 2 print(ans)
false
9.090909
[ "+#!/usr/bin/env python3", "+import fractions # 最小公倍数などはこっち", "+import sys", "+import collections", "+from decimal import Decimal # 10進数で考慮できる", "+", "+mod = 10**9 + 7", "+sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000", "+d = collections.deque()", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "-A = [int(i) for i in input().split()]", "-A.sort()", "-len_dic = {}", "-for a in A:", "- if a in list(len_dic.keys()):", "- len_dic[a] += 1", "- else:", "- len_dic[a] = 1", "-ans = [0, 0]", "-for k, v in sorted(list(len_dic.items()), key=lambda x: -x[0]):", "- if v >= 4 and ans[0] == 0:", "- ans = [k, k]", "- elif v >= 2:", "- if ans[0] == 0:", "- ans[0] = k", "- elif ans[1] == 0:", "- ans[1] = k", "-print((ans[0] * ans[1]))", "+A = LI()", "+A_collection = collections.Counter(A)", "+bars = []", "+for key in list(A_collection.keys()):", "+ if A_collection[key] > 1:", "+ bars.append(key)", "+ans = 0", "+bars.sort(reverse=1)", "+if len(bars) > 1:", "+ ans = bars[0] * bars[1]", "+ if A_collection[bars[0]] > 3:", "+ ans = bars[0] ** 2", "+print(ans)" ]
false
0.085664
0.182708
0.468857
[ "s462920234", "s309886775" ]
u035907840
p03171
python
s980639667
s726422894
445
209
206,040
135,168
Accepted
Accepted
53.03
N = int(eval(input())) *a, = list(map(int, input().split())) dp = [[None] * N for _ in range(N)] for i in range(N): dp[i][i] = a[i] for j in range(1, N): for i in range(j-1, -1, -1): dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]) print((dp[0][N-1]))
N = int(eval(input())) *a, = list(map(int, input().split())) dp = [[0] * N for _ in range(N)] for i in range(N): dp[i][i] = a[i] for j in range(1, N): for i in range(j-1, -1, -1): dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]) print((dp[0][N-1]))
11
11
267
264
N = int(eval(input())) (*a,) = list(map(int, input().split())) dp = [[None] * N for _ in range(N)] for i in range(N): dp[i][i] = a[i] for j in range(1, N): for i in range(j - 1, -1, -1): dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]) print((dp[0][N - 1]))
N = int(eval(input())) (*a,) = list(map(int, input().split())) dp = [[0] * N for _ in range(N)] for i in range(N): dp[i][i] = a[i] for j in range(1, N): for i in range(j - 1, -1, -1): dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]) print((dp[0][N - 1]))
false
0
[ "-dp = [[None] * N for _ in range(N)]", "+dp = [[0] * N for _ in range(N)]" ]
false
0.046781
0.047137
0.992455
[ "s980639667", "s726422894" ]
u977389981
p03241
python
s809560316
s224489839
38
21
2,940
3,064
Accepted
Accepted
44.74
N, M = list(map(int, input().split())) if M % N == 0: ans = M // N else: for i in range(1, M // N + 1): if M % i == 0: ans = i if M // i > i and M // i <= M // N: ans = M // i break print(ans)
N, M = list(map(int, input().split())) if M % N == 0: ans = M // N else: ans = 0 for i in range(1, int(M ** 0.5) + 1): if M % i == 0: if i <= M // N: ans = max(ans, i) if M // i <= M // N: ans = max(ans, M // i) print(ans)
13
14
280
315
N, M = list(map(int, input().split())) if M % N == 0: ans = M // N else: for i in range(1, M // N + 1): if M % i == 0: ans = i if M // i > i and M // i <= M // N: ans = M // i break print(ans)
N, M = list(map(int, input().split())) if M % N == 0: ans = M // N else: ans = 0 for i in range(1, int(M**0.5) + 1): if M % i == 0: if i <= M // N: ans = max(ans, i) if M // i <= M // N: ans = max(ans, M // i) print(ans)
false
7.142857
[ "- for i in range(1, M // N + 1):", "+ ans = 0", "+ for i in range(1, int(M**0.5) + 1):", "- ans = i", "- if M // i > i and M // i <= M // N:", "- ans = M // i", "- break", "+ if i <= M // N:", "+ ans = max(ans, i)", "+ if M // i <= M // N:", "+ ans = max(ans, M // i)" ]
false
0.063243
0.07568
0.835664
[ "s809560316", "s224489839" ]
u956318161
p02577
python
s398912151
s923710875
742
72
9,200
9,216
Accepted
Accepted
90.3
N=int(eval(input())) n= str(N) total=0 for i in range(len(n)): k = n[i] k = int(k) total += k if total%9==0: print("Yes") else: print("No")
n = eval(input()) point=0 for i in range(len(n)): point+=int(n[i]) if point%9==0: print("Yes") else: print("No")
12
9
157
123
N = int(eval(input())) n = str(N) total = 0 for i in range(len(n)): k = n[i] k = int(k) total += k if total % 9 == 0: print("Yes") else: print("No")
n = eval(input()) point = 0 for i in range(len(n)): point += int(n[i]) if point % 9 == 0: print("Yes") else: print("No")
false
25
[ "-N = int(eval(input()))", "-n = str(N)", "-total = 0", "+n = eval(input())", "+point = 0", "- k = n[i]", "- k = int(k)", "- total += k", "-if total % 9 == 0:", "+ point += int(n[i])", "+if point % 9 == 0:" ]
false
0.089738
0.076269
1.176596
[ "s398912151", "s923710875" ]
u571281863
p02630
python
s018501586
s135306136
520
278
20,848
24,012
Accepted
Accepted
46.54
N=int(eval(input())) A=list(map(int,input().split())) Q=int(eval(input())) D=dict() s=0 for i in A: s+=i if i in D: D[i]+=1 else: D[i]=1 for _ in range(Q): b,c=list(map(int,input().split())) if b in D: s+=(c-b)*D[b] if c in D: D[c]+=D[b] else: D[c]=D[b] del D[b] print(s)
import sys from collections import Counter readline=sys.stdin.readline n=readline() A=list(map(int,readline().split())) q=int(readline()) D=Counter(A) s=sum(A) for _ in range(q): b,c=list(map(int,readline().split())) s+=(c-b)*D[b] D[c]+=D[b] del D[b] print(s)
21
14
321
276
N = int(eval(input())) A = list(map(int, input().split())) Q = int(eval(input())) D = dict() s = 0 for i in A: s += i if i in D: D[i] += 1 else: D[i] = 1 for _ in range(Q): b, c = list(map(int, input().split())) if b in D: s += (c - b) * D[b] if c in D: D[c] += D[b] else: D[c] = D[b] del D[b] print(s)
import sys from collections import Counter readline = sys.stdin.readline n = readline() A = list(map(int, readline().split())) q = int(readline()) D = Counter(A) s = sum(A) for _ in range(q): b, c = list(map(int, readline().split())) s += (c - b) * D[b] D[c] += D[b] del D[b] print(s)
false
33.333333
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-Q = int(eval(input()))", "-D = dict()", "-s = 0", "-for i in A:", "- s += i", "- if i in D:", "- D[i] += 1", "- else:", "- D[i] = 1", "-for _ in range(Q):", "- b, c = list(map(int, input().split()))", "- if b in D:", "- s += (c - b) * D[b]", "- if c in D:", "- D[c] += D[b]", "- else:", "- D[c] = D[b]", "- del D[b]", "+import sys", "+from collections import Counter", "+", "+readline = sys.stdin.readline", "+n = readline()", "+A = list(map(int, readline().split()))", "+q = int(readline())", "+D = Counter(A)", "+s = sum(A)", "+for _ in range(q):", "+ b, c = list(map(int, readline().split()))", "+ s += (c - b) * D[b]", "+ D[c] += D[b]", "+ del D[b]" ]
false
0.04631
0.046369
0.998723
[ "s018501586", "s135306136" ]
u017415492
p02695
python
s075642490
s197382285
1,650
1,357
21,616
21,620
Accepted
Accepted
17.76
import itertools n,m,q=list(map(int,input().split())) abcd=[list(map(int,input().split())) for i in range(q)] d=list(itertools.combinations_with_replacement(list(range(1,m+1)), n)) ans=0 count=0 for i in range(len(d)): for j in range(q): if abcd[j][2]==d[i][abcd[j][1]-1]-d[i][abcd[j][0]-1]: count+=abcd[j][3] if ans<count: ans=count count=0 print(ans)
import itertools n,m,q=list(map(int,input().split())) d=[list(map(int,input().split())) for i in range(q)] ans=0 for i in list(itertools.combinations_with_replacement(list(range(1,m+1)), n)): a=list(i) hantei=0 for j in range(q): if (a[d[j][1]-1]-a[d[j][0]-1])==d[j][2]: hantei+=d[j][3] ans=max(ans,hantei) print(ans)
15
12
383
340
import itertools n, m, q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for i in range(q)] d = list(itertools.combinations_with_replacement(list(range(1, m + 1)), n)) ans = 0 count = 0 for i in range(len(d)): for j in range(q): if abcd[j][2] == d[i][abcd[j][1] - 1] - d[i][abcd[j][0] - 1]: count += abcd[j][3] if ans < count: ans = count count = 0 print(ans)
import itertools n, m, q = list(map(int, input().split())) d = [list(map(int, input().split())) for i in range(q)] ans = 0 for i in list(itertools.combinations_with_replacement(list(range(1, m + 1)), n)): a = list(i) hantei = 0 for j in range(q): if (a[d[j][1] - 1] - a[d[j][0] - 1]) == d[j][2]: hantei += d[j][3] ans = max(ans, hantei) print(ans)
false
20
[ "-abcd = [list(map(int, input().split())) for i in range(q)]", "-d = list(itertools.combinations_with_replacement(list(range(1, m + 1)), n))", "+d = [list(map(int, input().split())) for i in range(q)]", "-count = 0", "-for i in range(len(d)):", "+for i in list(itertools.combinations_with_replacement(list(range(1, m + 1)), n)):", "+ a = list(i)", "+ hantei = 0", "- if abcd[j][2] == d[i][abcd[j][1] - 1] - d[i][abcd[j][0] - 1]:", "- count += abcd[j][3]", "- if ans < count:", "- ans = count", "- count = 0", "+ if (a[d[j][1] - 1] - a[d[j][0] - 1]) == d[j][2]:", "+ hantei += d[j][3]", "+ ans = max(ans, hantei)" ]
false
0.151927
0.076301
1.991163
[ "s075642490", "s197382285" ]
u709304134
p02684
python
s189026339
s890288470
279
151
39,600
32,348
Accepted
Accepted
45.88
N,K = list(map(int,input().split())) A = [0] + list(map(int,input().split())) d = dict() c = 1 loop = False k = 0 while(k<K): if not loop and str(c) in d: T = k-d[str(c)] #print ('K',k) a = max((((K-k) // T)) - 1,0) #print(a) k += a*T #print ('K',k) loop = True d[str(c)] = k c = A[c] k+=1 print (c)
N,K = list(map(int,input().split())) A = [0] + list(map(int,input().split())) turn = [-1] * (N+1) # いつ訪問したかを記録する c = 1 for k in range(K): if turn[c]!=-1: T = k - turn[c] # 周期 bias = turn[c] # バイアス break turn[c] = k c = A[c] else: print (c) exit() K -= bias # Kを減らしてリスタート K %= T K += bias c = 1 for k in range(K): c = A[c] print (c)
20
22
386
397
N, K = list(map(int, input().split())) A = [0] + list(map(int, input().split())) d = dict() c = 1 loop = False k = 0 while k < K: if not loop and str(c) in d: T = k - d[str(c)] # print ('K',k) a = max((((K - k) // T)) - 1, 0) # print(a) k += a * T # print ('K',k) loop = True d[str(c)] = k c = A[c] k += 1 print(c)
N, K = list(map(int, input().split())) A = [0] + list(map(int, input().split())) turn = [-1] * (N + 1) # いつ訪問したかを記録する c = 1 for k in range(K): if turn[c] != -1: T = k - turn[c] # 周期 bias = turn[c] # バイアス break turn[c] = k c = A[c] else: print(c) exit() K -= bias # Kを減らしてリスタート K %= T K += bias c = 1 for k in range(K): c = A[c] print(c)
false
9.090909
[ "-d = dict()", "+turn = [-1] * (N + 1) # いつ訪問したかを記録する", "-loop = False", "-k = 0", "-while k < K:", "- if not loop and str(c) in d:", "- T = k - d[str(c)]", "- # print ('K',k)", "- a = max((((K - k) // T)) - 1, 0)", "- # print(a)", "- k += a * T", "- # print ('K',k)", "- loop = True", "- d[str(c)] = k", "+for k in range(K):", "+ if turn[c] != -1:", "+ T = k - turn[c] # 周期", "+ bias = turn[c] # バイアス", "+ break", "+ turn[c] = k", "- k += 1", "+else:", "+ print(c)", "+ exit()", "+K -= bias # Kを減らしてリスタート", "+K %= T", "+K += bias", "+c = 1", "+for k in range(K):", "+ c = A[c]" ]
false
0.006501
0.072995
0.089061
[ "s189026339", "s890288470" ]
u780364430
p03061
python
s463209504
s444924847
351
301
24,776
23,148
Accepted
Accepted
14.25
from functools import reduce import numpy as np def _gcd(a, b): while b: a, b = b, a % b return a def gcd(*n): return reduce(_gcd, n) def my_bisect(x): def find_pos(left, right): return left + (right - left - 1) // 2 def func(left, right, prev): if right - left == 1: return [left] if right - left == 2: return [left, left+1] pos = find_pos(left, right) g1 = gcd(*x[left:pos+1]) g2 = gcd(*x[pos+1:right]) if prev is not None: g1, g2 = gcd(g1, prev), gcd(g2, prev) if g1 < g2: return func(left, pos + 1, max(g1, g2)) else: return func(pos + 1, right, max(g1, g2)) return func(0, len(x), None) N = int(eval(input())) A = list(map(int, input().split())) print((max([gcd(*np.delete(A, i)) for i in my_bisect(A)])))
from functools import reduce import numpy as np def _gcd(a, b): while b: a, b = b, a % b return a def gcd(*n): return reduce(_gcd, n) def my_bisect(x): def find_pos(left, right): return left + (right - left - 1) // 2 def func(left, right, prev): if right - left == 1: return left pos = find_pos(left, right) g1 = gcd(*x[left:pos+1]) g2 = gcd(*x[pos+1:right]) if prev is not None: g1, g2 = gcd(g1, prev), gcd(g2, prev) if g1 < g2: return func(left, pos + 1, max(g1, g2)) else: return func(pos + 1, right, max(g1, g2)) return func(0, len(x), None) N = int(eval(input())) A = list(map(int, input().split())) print((gcd(*np.delete(A, my_bisect(A)))))
40
38
917
831
from functools import reduce import numpy as np def _gcd(a, b): while b: a, b = b, a % b return a def gcd(*n): return reduce(_gcd, n) def my_bisect(x): def find_pos(left, right): return left + (right - left - 1) // 2 def func(left, right, prev): if right - left == 1: return [left] if right - left == 2: return [left, left + 1] pos = find_pos(left, right) g1 = gcd(*x[left : pos + 1]) g2 = gcd(*x[pos + 1 : right]) if prev is not None: g1, g2 = gcd(g1, prev), gcd(g2, prev) if g1 < g2: return func(left, pos + 1, max(g1, g2)) else: return func(pos + 1, right, max(g1, g2)) return func(0, len(x), None) N = int(eval(input())) A = list(map(int, input().split())) print((max([gcd(*np.delete(A, i)) for i in my_bisect(A)])))
from functools import reduce import numpy as np def _gcd(a, b): while b: a, b = b, a % b return a def gcd(*n): return reduce(_gcd, n) def my_bisect(x): def find_pos(left, right): return left + (right - left - 1) // 2 def func(left, right, prev): if right - left == 1: return left pos = find_pos(left, right) g1 = gcd(*x[left : pos + 1]) g2 = gcd(*x[pos + 1 : right]) if prev is not None: g1, g2 = gcd(g1, prev), gcd(g2, prev) if g1 < g2: return func(left, pos + 1, max(g1, g2)) else: return func(pos + 1, right, max(g1, g2)) return func(0, len(x), None) N = int(eval(input())) A = list(map(int, input().split())) print((gcd(*np.delete(A, my_bisect(A)))))
false
5
[ "- return [left]", "- if right - left == 2:", "- return [left, left + 1]", "+ return left", "-print((max([gcd(*np.delete(A, i)) for i in my_bisect(A)])))", "+print((gcd(*np.delete(A, my_bisect(A)))))" ]
false
0.678047
0.330219
2.053328
[ "s463209504", "s444924847" ]
u116002573
p03378
python
s840054776
s288698641
19
17
3,060
2,940
Accepted
Accepted
10.53
def main(): N, M, X = list(map(int, input().split())) A = [int(a) for a in input().split()] costL = 0 for i in range(len(A)): if A[i] < X: costL += 1 return min(costL, M-costL) if __name__ == '__main__': print((main()))
def main(): N, M, X = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() count1 = 0 for i in range(M): if A[i] < X: count1 += 1 return min(count1, len(A)-count1) if __name__ == '__main__': print((main()))
11
14
270
276
def main(): N, M, X = list(map(int, input().split())) A = [int(a) for a in input().split()] costL = 0 for i in range(len(A)): if A[i] < X: costL += 1 return min(costL, M - costL) if __name__ == "__main__": print((main()))
def main(): N, M, X = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() count1 = 0 for i in range(M): if A[i] < X: count1 += 1 return min(count1, len(A) - count1) if __name__ == "__main__": print((main()))
false
21.428571
[ "- A = [int(a) for a in input().split()]", "- costL = 0", "- for i in range(len(A)):", "+ A = list(map(int, input().split()))", "+ A.sort()", "+ count1 = 0", "+ for i in range(M):", "- costL += 1", "- return min(costL, M - costL)", "+ count1 += 1", "+ return min(count1, len(A) - count1)" ]
false
0.046259
0.048003
0.963669
[ "s840054776", "s288698641" ]
u873915460
p03837
python
s455271493
s364074374
106
98
74,344
74,172
Accepted
Accepted
7.55
N,M=list(map(int,input().split())) E=[list(map(int,input().split())) for i in range(M)] INF=10**12 D=[[INF]*N for i in range(N)] for i in range(N): D[i][i]=0 for i in range(M): D[E[i][0]-1][E[i][1]-1]=E[i][2] D[E[i][1]-1][E[i][0]-1]=E[i][2] for k in range(N): for i in range(N): for j in range(N): D[i][j]=min(D[i][j],D[i][k]+D[k][j]) P=0 for i in range(M): for j in range(N): if D[j][E[i][0]-1]+E[i][2]==D[j][E[i][1]-1] or D[j][E[i][1]-1]+E[i][2]==D[j][E[i][0]-1]: break if j==N-1: P+=1 print(P)
N,M=list(map(int,input().split())) a,b,c=0,0,0 E=[] INF=10**12 D=[[INF]*N for i in range(N)] for i in range(N): D[i][i]=0 for i in range(M): a,b,c=list(map(int,input().split())) a,b=a-1,b-1 D[a][b]=c D[b][a]=c E.append((a,b,c)) for k in range(N): for i in range(N): for j in range(N): D[i][j]=min(D[i][j],D[i][k]+D[k][j]) P=0 for i in range(M): if D[E[i][0]][E[i][1]]!=E[i][2]: P+=1 print(P)
21
22
550
430
N, M = list(map(int, input().split())) E = [list(map(int, input().split())) for i in range(M)] INF = 10**12 D = [[INF] * N for i in range(N)] for i in range(N): D[i][i] = 0 for i in range(M): D[E[i][0] - 1][E[i][1] - 1] = E[i][2] D[E[i][1] - 1][E[i][0] - 1] = E[i][2] for k in range(N): for i in range(N): for j in range(N): D[i][j] = min(D[i][j], D[i][k] + D[k][j]) P = 0 for i in range(M): for j in range(N): if ( D[j][E[i][0] - 1] + E[i][2] == D[j][E[i][1] - 1] or D[j][E[i][1] - 1] + E[i][2] == D[j][E[i][0] - 1] ): break if j == N - 1: P += 1 print(P)
N, M = list(map(int, input().split())) a, b, c = 0, 0, 0 E = [] INF = 10**12 D = [[INF] * N for i in range(N)] for i in range(N): D[i][i] = 0 for i in range(M): a, b, c = list(map(int, input().split())) a, b = a - 1, b - 1 D[a][b] = c D[b][a] = c E.append((a, b, c)) for k in range(N): for i in range(N): for j in range(N): D[i][j] = min(D[i][j], D[i][k] + D[k][j]) P = 0 for i in range(M): if D[E[i][0]][E[i][1]] != E[i][2]: P += 1 print(P)
false
4.545455
[ "-E = [list(map(int, input().split())) for i in range(M)]", "+a, b, c = 0, 0, 0", "+E = []", "- D[E[i][0] - 1][E[i][1] - 1] = E[i][2]", "- D[E[i][1] - 1][E[i][0] - 1] = E[i][2]", "+ a, b, c = list(map(int, input().split()))", "+ a, b = a - 1, b - 1", "+ D[a][b] = c", "+ D[b][a] = c", "+ E.append((a, b, c))", "- for j in range(N):", "- if (", "- D[j][E[i][0] - 1] + E[i][2] == D[j][E[i][1] - 1]", "- or D[j][E[i][1] - 1] + E[i][2] == D[j][E[i][0] - 1]", "- ):", "- break", "- if j == N - 1:", "- P += 1", "+ if D[E[i][0]][E[i][1]] != E[i][2]:", "+ P += 1" ]
false
0.037435
0.043279
0.864977
[ "s455271493", "s364074374" ]
u854992222
p02713
python
s585019998
s934752491
1,806
1,498
9,204
9,184
Accepted
Accepted
17.05
from math import gcd k = int(eval(input())) sum =0 for a in range(1, k+1): for b in range(1, k+1): for c in range(1, k+1): sum += gcd(gcd(a, b), c) print(sum)
import math k = int(eval(input())) sum =0 for a in range(1, k+1): for b in range(1, k+1): x = math.gcd(a, b) for c in range(1, k+1): sum += math.gcd(x, c) print(sum)
8
9
186
203
from math import gcd k = int(eval(input())) sum = 0 for a in range(1, k + 1): for b in range(1, k + 1): for c in range(1, k + 1): sum += gcd(gcd(a, b), c) print(sum)
import math k = int(eval(input())) sum = 0 for a in range(1, k + 1): for b in range(1, k + 1): x = math.gcd(a, b) for c in range(1, k + 1): sum += math.gcd(x, c) print(sum)
false
11.111111
[ "-from math import gcd", "+import math", "+ x = math.gcd(a, b)", "- sum += gcd(gcd(a, b), c)", "+ sum += math.gcd(x, c)" ]
false
0.11611
0.083579
1.389222
[ "s585019998", "s934752491" ]
u678505520
p02725
python
s264746014
s052970421
135
102
25,928
26,444
Accepted
Accepted
24.44
K,N=list(map(int,input().split())) A=list(map(int,input().split())) M = 0 i = 0 while i<N-1: if M<(A[i+1]-A[i]): M=(A[i+1]-A[i]) i+=1 print((min(K-M,A[N-1]-A[0])))
k,n = list(map(int,input().split())) A = list(map(int,input().split())) A.append(k+A[0]) M = 0 for i in range(n): if A[i+1] - A[i] > M: M = A[i+1] - A[i] print((k-M))
10
8
181
177
K, N = list(map(int, input().split())) A = list(map(int, input().split())) M = 0 i = 0 while i < N - 1: if M < (A[i + 1] - A[i]): M = A[i + 1] - A[i] i += 1 print((min(K - M, A[N - 1] - A[0])))
k, n = list(map(int, input().split())) A = list(map(int, input().split())) A.append(k + A[0]) M = 0 for i in range(n): if A[i + 1] - A[i] > M: M = A[i + 1] - A[i] print((k - M))
false
20
[ "-K, N = list(map(int, input().split()))", "+k, n = list(map(int, input().split()))", "+A.append(k + A[0])", "-i = 0", "-while i < N - 1:", "- if M < (A[i + 1] - A[i]):", "+for i in range(n):", "+ if A[i + 1] - A[i] > M:", "- i += 1", "-print((min(K - M, A[N - 1] - A[0])))", "+print((k - M))" ]
false
0.080021
0.122624
0.652575
[ "s264746014", "s052970421" ]
u968166680
p02838
python
s392786525
s322668655
348
195
126,056
125,868
Accepted
Accepted
43.97
import sys read = sys.stdin.buffer.read MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) M = 60 ans = 0 p = 1 for _ in range(M): n = 0 for i, a in enumerate(A): if not a: continue A[i], d = a // 2, a % 2 if d: n += 1 ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) M = 60 ans = 0 p = 1 for _ in range(M): n = 0 for i in range(N): A[i], d = A[i] // 2, A[i] % 2 n += d ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
29
26
501
428
import sys read = sys.stdin.buffer.read MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) M = 60 ans = 0 p = 1 for _ in range(M): n = 0 for i, a in enumerate(A): if not a: continue A[i], d = a // 2, a % 2 if d: n += 1 ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) M = 60 ans = 0 p = 1 for _ in range(M): n = 0 for i in range(N): A[i], d = A[i] // 2, A[i] % 2 n += d ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == "__main__": main()
false
10.344828
[ "- for i, a in enumerate(A):", "- if not a:", "- continue", "- A[i], d = a // 2, a % 2", "- if d:", "- n += 1", "+ for i in range(N):", "+ A[i], d = A[i] // 2, A[i] % 2", "+ n += d" ]
false
0.036723
0.033634
1.091833
[ "s392786525", "s322668655" ]
u808429775
p00111
python
s584564795
s408209812
70
60
5,608
5,600
Accepted
Accepted
14.29
import sys CharToSign = { "A": "00000", "B": "00001", "C": "00010", "D": "00011", "E": "00100", "F": "00101", "G": "00110", "H": "00111", "I": "01000", "J": "01001", "K": "01010", "L": "01011", "M": "01100", "N": "01101", "O": "01110", "P": "01111", "Q": "10000", "R": "10001", "S": "10010", "T": "10011", "U": "10100", "V": "10101", "W": "10110", "X": "10111", "Y": "11000", "Z": "11001", " ": "11010", ".": "11011", ",": "11100", "-": "11101", "'": "11110", "?": "11111", } SignToChar = { "101": " ", "000000": "'", "000011": ",", "10010001": "-", "010001": ".", "000001": "?", "100101": "A", "10011010": "B", "0101": "C", "0001": "D", "110": "E", "01001": "F", "10011011": "G", "010000": "H", "0111": "I", "10011000": "J", "0110": "K", "00100": "L", "10011001": "M", "10011110": "N", "00101": "O", "111": "P", "10011111": "Q", "1000": "R", "00110": "S", "00111": "T", "10011100": "U", "10011101": "V", "000010": "W", "10010010": "X", "10010011": "Y", "10010000": "Z", } for line in sys.stdin: line = line[:-1] sign = [] for char in line: convert = CharToSign[char] sign.append(convert) sign = "".join(sign) startIndex = 0 endIndex = 3 string = [] length = len(sign) while endIndex <= length: part = sign[startIndex:endIndex] if part in SignToChar: convert = SignToChar[part] string.append(convert) startIndex = endIndex endIndex += 3 else: endIndex += 1 string = "".join(string) print(string)
import sys CharToSign = { "A": "00000", "B": "00001", "C": "00010", "D": "00011", "E": "00100", "F": "00101", "G": "00110", "H": "00111", "I": "01000", "J": "01001", "K": "01010", "L": "01011", "M": "01100", "N": "01101", "O": "01110", "P": "01111", "Q": "10000", "R": "10001", "S": "10010", "T": "10011", "U": "10100", "V": "10101", "W": "10110", "X": "10111", "Y": "11000", "Z": "11001", " ": "11010", ".": "11011", ",": "11100", "-": "11101", "'": "11110", "?": "11111", } SignToChar = { "101": " ", "000000": "'", "000011": ",", "10010001": "-", "010001": ".", "000001": "?", "100101": "A", "10011010": "B", "0101": "C", "0001": "D", "110": "E", "01001": "F", "10011011": "G", "010000": "H", "0111": "I", "10011000": "J", "0110": "K", "00100": "L", "10011001": "M", "10011110": "N", "00101": "O", "111": "P", "10011111": "Q", "1000": "R", "00110": "S", "00111": "T", "10011100": "U", "10011101": "V", "000010": "W", "10010010": "X", "10010011": "Y", "10010000": "Z", } for line in sys.stdin: line = line[:-1] sign = "" for char in line: sign += CharToSign[char] string = "" part = "" for item in sign: part += item if part in SignToChar: string += SignToChar[part] part = "" print(string)
53
42
1,666
1,382
import sys CharToSign = { "A": "00000", "B": "00001", "C": "00010", "D": "00011", "E": "00100", "F": "00101", "G": "00110", "H": "00111", "I": "01000", "J": "01001", "K": "01010", "L": "01011", "M": "01100", "N": "01101", "O": "01110", "P": "01111", "Q": "10000", "R": "10001", "S": "10010", "T": "10011", "U": "10100", "V": "10101", "W": "10110", "X": "10111", "Y": "11000", "Z": "11001", " ": "11010", ".": "11011", ",": "11100", "-": "11101", "'": "11110", "?": "11111", } SignToChar = { "101": " ", "000000": "'", "000011": ",", "10010001": "-", "010001": ".", "000001": "?", "100101": "A", "10011010": "B", "0101": "C", "0001": "D", "110": "E", "01001": "F", "10011011": "G", "010000": "H", "0111": "I", "10011000": "J", "0110": "K", "00100": "L", "10011001": "M", "10011110": "N", "00101": "O", "111": "P", "10011111": "Q", "1000": "R", "00110": "S", "00111": "T", "10011100": "U", "10011101": "V", "000010": "W", "10010010": "X", "10010011": "Y", "10010000": "Z", } for line in sys.stdin: line = line[:-1] sign = [] for char in line: convert = CharToSign[char] sign.append(convert) sign = "".join(sign) startIndex = 0 endIndex = 3 string = [] length = len(sign) while endIndex <= length: part = sign[startIndex:endIndex] if part in SignToChar: convert = SignToChar[part] string.append(convert) startIndex = endIndex endIndex += 3 else: endIndex += 1 string = "".join(string) print(string)
import sys CharToSign = { "A": "00000", "B": "00001", "C": "00010", "D": "00011", "E": "00100", "F": "00101", "G": "00110", "H": "00111", "I": "01000", "J": "01001", "K": "01010", "L": "01011", "M": "01100", "N": "01101", "O": "01110", "P": "01111", "Q": "10000", "R": "10001", "S": "10010", "T": "10011", "U": "10100", "V": "10101", "W": "10110", "X": "10111", "Y": "11000", "Z": "11001", " ": "11010", ".": "11011", ",": "11100", "-": "11101", "'": "11110", "?": "11111", } SignToChar = { "101": " ", "000000": "'", "000011": ",", "10010001": "-", "010001": ".", "000001": "?", "100101": "A", "10011010": "B", "0101": "C", "0001": "D", "110": "E", "01001": "F", "10011011": "G", "010000": "H", "0111": "I", "10011000": "J", "0110": "K", "00100": "L", "10011001": "M", "10011110": "N", "00101": "O", "111": "P", "10011111": "Q", "1000": "R", "00110": "S", "00111": "T", "10011100": "U", "10011101": "V", "000010": "W", "10010010": "X", "10010011": "Y", "10010000": "Z", } for line in sys.stdin: line = line[:-1] sign = "" for char in line: sign += CharToSign[char] string = "" part = "" for item in sign: part += item if part in SignToChar: string += SignToChar[part] part = "" print(string)
false
20.754717
[ "- sign = []", "+ sign = \"\"", "- convert = CharToSign[char]", "- sign.append(convert)", "- sign = \"\".join(sign)", "- startIndex = 0", "- endIndex = 3", "- string = []", "- length = len(sign)", "- while endIndex <= length:", "- part = sign[startIndex:endIndex]", "+ sign += CharToSign[char]", "+ string = \"\"", "+ part = \"\"", "+ for item in sign:", "+ part += item", "- convert = SignToChar[part]", "- string.append(convert)", "- startIndex = endIndex", "- endIndex += 3", "- else:", "- endIndex += 1", "- string = \"\".join(string)", "+ string += SignToChar[part]", "+ part = \"\"" ]
false
0.120356
0.18733
0.642483
[ "s584564795", "s408209812" ]
u193264896
p02713
python
s883858875
s170802558
1,247
226
10,680
9,188
Accepted
Accepted
81.88
from fractions import gcd def main(): k = int(eval(input())) ans = 0 for a in range(1, k+1): for b in range(a, k+1): x = gcd(a,b) for c in range(b,k+1): if a==b and b==c: ans += a elif a==b or b==c: ans += gcd(x,c) * 3 else: ans += gcd(x,c) * 6 print(ans) if __name__ == '__main__': main()
from math import gcd def main(): k = int(eval(input())) ans = 0 for a in range(1, k+1): for b in range(a, k+1): x = gcd(a,b) for c in range(b,k+1): if a==b and b==c: ans += a elif a==b or b==c: ans += gcd(x,c) * 3 else: ans += gcd(x,c) * 6 print(ans) if __name__ == '__main__': main()
20
20
390
386
from fractions import gcd def main(): k = int(eval(input())) ans = 0 for a in range(1, k + 1): for b in range(a, k + 1): x = gcd(a, b) for c in range(b, k + 1): if a == b and b == c: ans += a elif a == b or b == c: ans += gcd(x, c) * 3 else: ans += gcd(x, c) * 6 print(ans) if __name__ == "__main__": main()
from math import gcd def main(): k = int(eval(input())) ans = 0 for a in range(1, k + 1): for b in range(a, k + 1): x = gcd(a, b) for c in range(b, k + 1): if a == b and b == c: ans += a elif a == b or b == c: ans += gcd(x, c) * 3 else: ans += gcd(x, c) * 6 print(ans) if __name__ == "__main__": main()
false
0
[ "-from fractions import gcd", "+from math import gcd" ]
false
0.159177
0.112871
1.410254
[ "s883858875", "s170802558" ]
u747220349
p02811
python
s317207115
s024634851
171
17
38,256
2,940
Accepted
Accepted
90.06
n,k=list(map(int,input().split())) g=500*n if g>=k: print("Yes") else: print("No")
k,n=list(map(int,input().split())) if 500*k>=n: print("Yes") else: print("No")
6
5
89
84
n, k = list(map(int, input().split())) g = 500 * n if g >= k: print("Yes") else: print("No")
k, n = list(map(int, input().split())) if 500 * k >= n: print("Yes") else: print("No")
false
16.666667
[ "-n, k = list(map(int, input().split()))", "-g = 500 * n", "-if g >= k:", "+k, n = list(map(int, input().split()))", "+if 500 * k >= n:" ]
false
0.083019
0.036783
2.256972
[ "s317207115", "s024634851" ]
u771167374
p03290
python
s028370241
s565065867
46
34
9,120
9,140
Accepted
Accepted
26.09
#abc104c all green d, g = list(map(int, input().split())) pc = [list(map(int, input().split())) for _ in range(d)] all_sum = [] for bit in range(1<<d): s = 0 a = 0 rest = [] for i in range(d): if bit & (1<<i): s += pc[i][0]*100*(i+1) + pc[i][1] a += pc[i][0] else : rest.append(i) if s >= g : all_sum.append(a) else : k = max(rest) diff = g - s for j in range(pc[k][0]): if j*(k+1)*100 >= diff: all_sum.append(a+j) print((min(all_sum)))
def dfs(i, sum, count, rest): global ans if i == d: if sum < g: rest_max = max(rest) n = min(l[rest_max-1][0], -(-(g-sum)//(rest_max*100))) count += n sum += n * rest_max * 100 if sum >= g: ans = min(ans, count) else : dfs(i+1, sum, count, rest) #二分岐のうち解かない選択 dfs(i+1, sum + l[i][0]*(i+1)*100+l[i][1], count + l[i][0], rest - {i+1}) #解く選択 d, g = list(map(int, input().split())) l = [list((list(map(int, input().split())))) for _ in range(d)] ans = float("inf") dfs(0, 0, 0, set(range(1, d+1))) print(ans)
24
19
593
616
# abc104c all green d, g = list(map(int, input().split())) pc = [list(map(int, input().split())) for _ in range(d)] all_sum = [] for bit in range(1 << d): s = 0 a = 0 rest = [] for i in range(d): if bit & (1 << i): s += pc[i][0] * 100 * (i + 1) + pc[i][1] a += pc[i][0] else: rest.append(i) if s >= g: all_sum.append(a) else: k = max(rest) diff = g - s for j in range(pc[k][0]): if j * (k + 1) * 100 >= diff: all_sum.append(a + j) print((min(all_sum)))
def dfs(i, sum, count, rest): global ans if i == d: if sum < g: rest_max = max(rest) n = min(l[rest_max - 1][0], -(-(g - sum) // (rest_max * 100))) count += n sum += n * rest_max * 100 if sum >= g: ans = min(ans, count) else: dfs(i + 1, sum, count, rest) # 二分岐のうち解かない選択 dfs( i + 1, sum + l[i][0] * (i + 1) * 100 + l[i][1], count + l[i][0], rest - {i + 1}, ) # 解く選択 d, g = list(map(int, input().split())) l = [list((list(map(int, input().split())))) for _ in range(d)] ans = float("inf") dfs(0, 0, 0, set(range(1, d + 1))) print(ans)
false
20.833333
[ "-# abc104c all green", "+def dfs(i, sum, count, rest):", "+ global ans", "+ if i == d:", "+ if sum < g:", "+ rest_max = max(rest)", "+ n = min(l[rest_max - 1][0], -(-(g - sum) // (rest_max * 100)))", "+ count += n", "+ sum += n * rest_max * 100", "+ if sum >= g:", "+ ans = min(ans, count)", "+ else:", "+ dfs(i + 1, sum, count, rest) # 二分岐のうち解かない選択", "+ dfs(", "+ i + 1,", "+ sum + l[i][0] * (i + 1) * 100 + l[i][1],", "+ count + l[i][0],", "+ rest - {i + 1},", "+ ) # 解く選択", "+", "+", "-pc = [list(map(int, input().split())) for _ in range(d)]", "-all_sum = []", "-for bit in range(1 << d):", "- s = 0", "- a = 0", "- rest = []", "- for i in range(d):", "- if bit & (1 << i):", "- s += pc[i][0] * 100 * (i + 1) + pc[i][1]", "- a += pc[i][0]", "- else:", "- rest.append(i)", "- if s >= g:", "- all_sum.append(a)", "- else:", "- k = max(rest)", "- diff = g - s", "- for j in range(pc[k][0]):", "- if j * (k + 1) * 100 >= diff:", "- all_sum.append(a + j)", "-print((min(all_sum)))", "+l = [list((list(map(int, input().split())))) for _ in range(d)]", "+ans = float(\"inf\")", "+dfs(0, 0, 0, set(range(1, d + 1)))", "+print(ans)" ]
false
0.042336
0.042361
0.999421
[ "s028370241", "s565065867" ]
u050428930
p03592
python
s821458987
s216121361
331
305
3,060
42,648
Accepted
Accepted
7.85
n,m,k=list(map(int,input().split())) for i in range(n+1): for j in range(m+1): if m*i+n*j-2*(i*j)==k: print("Yes") exit() print("No")
n,m,k=list(map(int,input().split())) s=[] u=n for i in range(1,n+1): u-=2 for j in range(m+1): s.append(m*i+u*j) if k in s: print("Yes") else: print("No")
7
11
172
182
n, m, k = list(map(int, input().split())) for i in range(n + 1): for j in range(m + 1): if m * i + n * j - 2 * (i * j) == k: print("Yes") exit() print("No")
n, m, k = list(map(int, input().split())) s = [] u = n for i in range(1, n + 1): u -= 2 for j in range(m + 1): s.append(m * i + u * j) if k in s: print("Yes") else: print("No")
false
36.363636
[ "-for i in range(n + 1):", "+s = []", "+u = n", "+for i in range(1, n + 1):", "+ u -= 2", "- if m * i + n * j - 2 * (i * j) == k:", "- print(\"Yes\")", "- exit()", "-print(\"No\")", "+ s.append(m * i + u * j)", "+if k in s:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.035863
0.03619
0.990947
[ "s821458987", "s216121361" ]
u982896977
p03494
python
s980993319
s226277045
21
19
2,940
3,060
Accepted
Accepted
9.52
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 10**10 for i in range(n): counter = 0 while a[i] % 2 == 0: a[i] /= 2 counter += 1 if counter <= ans: ans = counter print(ans)
n = int(eval(input())) A = list(map(int,input().split())) counter = 0 breaker = 0 while True: for i in range(n): if A[i]%2 == 0: A[i] = A[i] // 2 else: breaker = 1 if breaker == 0: counter += 1 else: break print(counter)
11
15
205
245
n = int(eval(input())) a = [int(i) for i in input().split()] ans = 10**10 for i in range(n): counter = 0 while a[i] % 2 == 0: a[i] /= 2 counter += 1 if counter <= ans: ans = counter print(ans)
n = int(eval(input())) A = list(map(int, input().split())) counter = 0 breaker = 0 while True: for i in range(n): if A[i] % 2 == 0: A[i] = A[i] // 2 else: breaker = 1 if breaker == 0: counter += 1 else: break print(counter)
false
26.666667
[ "-a = [int(i) for i in input().split()]", "-ans = 10**10", "-for i in range(n):", "- counter = 0", "- while a[i] % 2 == 0:", "- a[i] /= 2", "+A = list(map(int, input().split()))", "+counter = 0", "+breaker = 0", "+while True:", "+ for i in range(n):", "+ if A[i] % 2 == 0:", "+ A[i] = A[i] // 2", "+ else:", "+ breaker = 1", "+ if breaker == 0:", "- if counter <= ans:", "- ans = counter", "-print(ans)", "+ else:", "+ break", "+print(counter)" ]
false
0.059344
0.071082
0.834864
[ "s980993319", "s226277045" ]
u598699652
p03846
python
s311107348
s609392518
113
65
14,768
14,008
Accepted
Accepted
42.48
N = int(eval(input())) evenFlg = False flg = False lastIndex = int((N - (N % 2))/2) if N % 2 == 0: evenFlg = True ary = [2 for i in range(lastIndex)] l = list(map(int, input().split())) # for i in range(lastIndex): # ary.append(2) if not evenFlg: ary.insert(0, 1) for r in range(N): if evenFlg: l[r] = (l[r] - 1) / 2 else: l[r] /= 2 l[r] = int(l[r]) ary[l[r]] -= 1 for k in range(lastIndex): if ary[k] != 0: flg = True break ans = 0 if flg else (2**lastIndex) % (10**9 + 7) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = pow(2, N // 2) # 0*1 2*2 4*2 2^N/2*2 check = [0 for p in range(0, N // 2 + N % 2)] for o in A: check[o // 2] += 1 for q in range(0, N // 2 + N % 2): if q == 0 and N % 2 == 1: if check[q] != 1: ans = 0 break else: if check[q] != 2: ans = 0 break print((ans % (pow(10, 9) + 7)))
26
18
561
427
N = int(eval(input())) evenFlg = False flg = False lastIndex = int((N - (N % 2)) / 2) if N % 2 == 0: evenFlg = True ary = [2 for i in range(lastIndex)] l = list(map(int, input().split())) # for i in range(lastIndex): # ary.append(2) if not evenFlg: ary.insert(0, 1) for r in range(N): if evenFlg: l[r] = (l[r] - 1) / 2 else: l[r] /= 2 l[r] = int(l[r]) ary[l[r]] -= 1 for k in range(lastIndex): if ary[k] != 0: flg = True break ans = 0 if flg else (2**lastIndex) % (10**9 + 7) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = pow(2, N // 2) # 0*1 2*2 4*2 2^N/2*2 check = [0 for p in range(0, N // 2 + N % 2)] for o in A: check[o // 2] += 1 for q in range(0, N // 2 + N % 2): if q == 0 and N % 2 == 1: if check[q] != 1: ans = 0 break else: if check[q] != 2: ans = 0 break print((ans % (pow(10, 9) + 7)))
false
30.769231
[ "-evenFlg = False", "-flg = False", "-lastIndex = int((N - (N % 2)) / 2)", "-if N % 2 == 0:", "- evenFlg = True", "-ary = [2 for i in range(lastIndex)]", "-l = list(map(int, input().split()))", "-# for i in range(lastIndex):", "-# ary.append(2)", "-if not evenFlg:", "- ary.insert(0, 1)", "-for r in range(N):", "- if evenFlg:", "- l[r] = (l[r] - 1) / 2", "+A = list(map(int, input().split()))", "+ans = pow(2, N // 2)", "+# 0*1 2*2 4*2 2^N/2*2", "+check = [0 for p in range(0, N // 2 + N % 2)]", "+for o in A:", "+ check[o // 2] += 1", "+for q in range(0, N // 2 + N % 2):", "+ if q == 0 and N % 2 == 1:", "+ if check[q] != 1:", "+ ans = 0", "+ break", "- l[r] /= 2", "- l[r] = int(l[r])", "- ary[l[r]] -= 1", "-for k in range(lastIndex):", "- if ary[k] != 0:", "- flg = True", "- break", "-ans = 0 if flg else (2**lastIndex) % (10**9 + 7)", "-print(ans)", "+ if check[q] != 2:", "+ ans = 0", "+ break", "+print((ans % (pow(10, 9) + 7)))" ]
false
0.06179
0.082769
0.746541
[ "s311107348", "s609392518" ]
u546285759
p00136
python
s079799982
s956610618
30
20
7,760
7,652
Accepted
Accepted
33.33
h = [float(eval(input())) for _ in range(int(eval(input())))] d = {"1": ":","2": ":","3": ":","4": ":","5": ":","6": ":"} for v in h: if v < 165.0: d["1"] += "*" elif v >= 165.0 and v < 170.0: d["2"] += "*" elif v >= 170.0 and v < 175.0: d["3"] += "*" elif v >= 175.0 and v < 180.0: d["4"] += "*" elif v >= 180.0 and v < 185.0: d["5"] += "*" else: d["6"] += "*" for k, v in sorted(list(d.items()), key=lambda x: int(x[0])): print((k+v))
n = int(eval(input())) data = {k: 0 for k in range(1, 7)} for _ in range(n): tmp = float(eval(input())) if tmp < 165.0: data[1] += 1 elif 165.0 <= tmp < 170.0: data[2] += 1 elif 170.0 <= tmp < 175.0: data[3] += 1 elif 175.0 <= tmp < 180.0: data[4] += 1 elif 180.0 <= tmp < 185.0: data[5] += 1 else: data[6] += 1 for k, v in list(data.items()): print(("{}:{}".format(k, v*"*")))
18
19
510
456
h = [float(eval(input())) for _ in range(int(eval(input())))] d = {"1": ":", "2": ":", "3": ":", "4": ":", "5": ":", "6": ":"} for v in h: if v < 165.0: d["1"] += "*" elif v >= 165.0 and v < 170.0: d["2"] += "*" elif v >= 170.0 and v < 175.0: d["3"] += "*" elif v >= 175.0 and v < 180.0: d["4"] += "*" elif v >= 180.0 and v < 185.0: d["5"] += "*" else: d["6"] += "*" for k, v in sorted(list(d.items()), key=lambda x: int(x[0])): print((k + v))
n = int(eval(input())) data = {k: 0 for k in range(1, 7)} for _ in range(n): tmp = float(eval(input())) if tmp < 165.0: data[1] += 1 elif 165.0 <= tmp < 170.0: data[2] += 1 elif 170.0 <= tmp < 175.0: data[3] += 1 elif 175.0 <= tmp < 180.0: data[4] += 1 elif 180.0 <= tmp < 185.0: data[5] += 1 else: data[6] += 1 for k, v in list(data.items()): print(("{}:{}".format(k, v * "*")))
false
5.263158
[ "-h = [float(eval(input())) for _ in range(int(eval(input())))]", "-d = {\"1\": \":\", \"2\": \":\", \"3\": \":\", \"4\": \":\", \"5\": \":\", \"6\": \":\"}", "-for v in h:", "- if v < 165.0:", "- d[\"1\"] += \"*\"", "- elif v >= 165.0 and v < 170.0:", "- d[\"2\"] += \"*\"", "- elif v >= 170.0 and v < 175.0:", "- d[\"3\"] += \"*\"", "- elif v >= 175.0 and v < 180.0:", "- d[\"4\"] += \"*\"", "- elif v >= 180.0 and v < 185.0:", "- d[\"5\"] += \"*\"", "+n = int(eval(input()))", "+data = {k: 0 for k in range(1, 7)}", "+for _ in range(n):", "+ tmp = float(eval(input()))", "+ if tmp < 165.0:", "+ data[1] += 1", "+ elif 165.0 <= tmp < 170.0:", "+ data[2] += 1", "+ elif 170.0 <= tmp < 175.0:", "+ data[3] += 1", "+ elif 175.0 <= tmp < 180.0:", "+ data[4] += 1", "+ elif 180.0 <= tmp < 185.0:", "+ data[5] += 1", "- d[\"6\"] += \"*\"", "-for k, v in sorted(list(d.items()), key=lambda x: int(x[0])):", "- print((k + v))", "+ data[6] += 1", "+for k, v in list(data.items()):", "+ print((\"{}:{}\".format(k, v * \"*\")))" ]
false
0.043861
0.046211
0.949147
[ "s079799982", "s956610618" ]
u352394527
p00484
python
s733108918
s465156517
500
410
6,324
6,320
Accepted
Accepted
18
def solve(): n, k = list(map(int,input().split())) group_num = 10 book_map = [[] for i in range(group_num)] acc_map = [[0] for i in range(group_num)] for i in range(n): c, g = list(map(int,input().split())) book_map[g - 1].append(c) for i in range(group_num): bmi = book_map[i] bmi.sort(reverse=True) ami = acc_map[i] acc = 0 for j in range(len(bmi)): acc += (bmi[j] + j * 2) ami.append(acc) dp = [[0] * (k + 1) for i in range(group_num + 1)] for y in range(1, k + 1): for x in range(1, group_num + 1): accs = acc_map[x - 1] dp_pre = dp[x - 1] dp[x][y] = max([dp_pre[y - z] + accs[z] for z in range(min(y + 1, len(accs)))]) print((dp[group_num][k])) solve()
def solve(): n, k = list(map(int,input().split())) group_num = 10 book_map = [[] for i in range(group_num)] acc_map = [] for i in range(n): c, g = list(map(int,input().split())) book_map[g - 1].append(c) for i in range(group_num): bmi = book_map[i] bmi.sort(reverse=True) ami = [0 for i in range(len(bmi) + 1)] for j in range(len(bmi)): ami[j + 1] = ami[j] + bmi[j] + j * 2 acc_map.append(ami) dp = [[0] * (k + 1) for i in range(group_num + 1)] for y in range(1, k + 1): for x in range(1, group_num + 1): accs = acc_map[x - 1] dp_pre = dp[x - 1] dp[x][y] = max([dp_pre[y - z] + accs[z] for z in range(min(y + 1, len(accs)))]) print((dp[group_num][k])) solve()
30
29
765
760
def solve(): n, k = list(map(int, input().split())) group_num = 10 book_map = [[] for i in range(group_num)] acc_map = [[0] for i in range(group_num)] for i in range(n): c, g = list(map(int, input().split())) book_map[g - 1].append(c) for i in range(group_num): bmi = book_map[i] bmi.sort(reverse=True) ami = acc_map[i] acc = 0 for j in range(len(bmi)): acc += bmi[j] + j * 2 ami.append(acc) dp = [[0] * (k + 1) for i in range(group_num + 1)] for y in range(1, k + 1): for x in range(1, group_num + 1): accs = acc_map[x - 1] dp_pre = dp[x - 1] dp[x][y] = max( [dp_pre[y - z] + accs[z] for z in range(min(y + 1, len(accs)))] ) print((dp[group_num][k])) solve()
def solve(): n, k = list(map(int, input().split())) group_num = 10 book_map = [[] for i in range(group_num)] acc_map = [] for i in range(n): c, g = list(map(int, input().split())) book_map[g - 1].append(c) for i in range(group_num): bmi = book_map[i] bmi.sort(reverse=True) ami = [0 for i in range(len(bmi) + 1)] for j in range(len(bmi)): ami[j + 1] = ami[j] + bmi[j] + j * 2 acc_map.append(ami) dp = [[0] * (k + 1) for i in range(group_num + 1)] for y in range(1, k + 1): for x in range(1, group_num + 1): accs = acc_map[x - 1] dp_pre = dp[x - 1] dp[x][y] = max( [dp_pre[y - z] + accs[z] for z in range(min(y + 1, len(accs)))] ) print((dp[group_num][k])) solve()
false
3.333333
[ "- acc_map = [[0] for i in range(group_num)]", "+ acc_map = []", "- ami = acc_map[i]", "- acc = 0", "+ ami = [0 for i in range(len(bmi) + 1)]", "- acc += bmi[j] + j * 2", "- ami.append(acc)", "+ ami[j + 1] = ami[j] + bmi[j] + j * 2", "+ acc_map.append(ami)" ]
false
0.037159
0.035399
1.049728
[ "s733108918", "s465156517" ]