user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u133936772
p02837
python
s058773035
s862591719
1,281
85
12,792
3,064
Accepted
Accepted
93.36
import sys input = sys.stdin.readline n = int(eval(input())) la, lxy = [], [] for i in range(n): a = int(eval(input())) la.append(a) xy = [] for j in range(a): xy.append(list(map(int, input().split()))) lxy.append(xy) from itertools import product lb = [''.join(b) for b in product('01', repeat=n)] lc = [sum(int(j) for j in i) for i in lb] lc, lb = list(zip(*sorted(zip(lc, lb), reverse=True))) lb = [[int(j) for j in i] for i in lb] for l in lb: ok = 1 for i in range(n): a = la[i] for j in range(a): x, y = lxy[i][j] if l[i] == 1 and l[x-1] != y: ok = 0 break if ok: print((sum(int(k) for k in l))) break else: print((0))
import sys, itertools input = sys.stdin.readline n = int(eval(input())) ll = [] for i in range(n): a = int(eval(input())) for j in range(a): x, y = list(map(int, input().split())) ll.append([i, x-1, y]) ans = 0 for p in itertools.product([1,0], repeat=n): ok = 1 for l in ll: if p[l[0]] == 1 and p[l[1]] != l[2]: ok = 0 break if ok: ans = max(ans, sum(p)) print(ans)
34
23
705
412
import sys input = sys.stdin.readline n = int(eval(input())) la, lxy = [], [] for i in range(n): a = int(eval(input())) la.append(a) xy = [] for j in range(a): xy.append(list(map(int, input().split()))) lxy.append(xy) from itertools import product lb = ["".join(b) for b in product("01", repeat=n)] lc = [sum(int(j) for j in i) for i in lb] lc, lb = list(zip(*sorted(zip(lc, lb), reverse=True))) lb = [[int(j) for j in i] for i in lb] for l in lb: ok = 1 for i in range(n): a = la[i] for j in range(a): x, y = lxy[i][j] if l[i] == 1 and l[x - 1] != y: ok = 0 break if ok: print((sum(int(k) for k in l))) break else: print((0))
import sys, itertools input = sys.stdin.readline n = int(eval(input())) ll = [] for i in range(n): a = int(eval(input())) for j in range(a): x, y = list(map(int, input().split())) ll.append([i, x - 1, y]) ans = 0 for p in itertools.product([1, 0], repeat=n): ok = 1 for l in ll: if p[l[0]] == 1 and p[l[1]] != l[2]: ok = 0 break if ok: ans = max(ans, sum(p)) print(ans)
false
32.352941
[ "-import sys", "+import sys, itertools", "-la, lxy = [], []", "+ll = []", "- la.append(a)", "- xy = []", "- xy.append(list(map(int, input().split())))", "- lxy.append(xy)", "-from itertools import product", "-", "-lb = [\"\".join(b) for b in product(\"01\", repeat=n)]", "-lc = [sum(int(j) for j in i) for i in lb]", "-lc, lb = list(zip(*sorted(zip(lc, lb), reverse=True)))", "-lb = [[int(j) for j in i] for i in lb]", "-for l in lb:", "+ x, y = list(map(int, input().split()))", "+ ll.append([i, x - 1, y])", "+ans = 0", "+for p in itertools.product([1, 0], repeat=n):", "- for i in range(n):", "- a = la[i]", "- for j in range(a):", "- x, y = lxy[i][j]", "- if l[i] == 1 and l[x - 1] != y:", "- ok = 0", "- break", "+ for l in ll:", "+ if p[l[0]] == 1 and p[l[1]] != l[2]:", "+ ok = 0", "+ break", "- print((sum(int(k) for k in l)))", "- break", "-else:", "- print((0))", "+ ans = max(ans, sum(p))", "+print(ans)" ]
false
0.043442
0.035571
1.221264
[ "s058773035", "s862591719" ]
u780342333
p02268
python
s406573756
s444990259
510
50
18,992
16,600
Accepted
Accepted
90.2
n = int(eval(input())) S = [int(x) for x in input().split()] q = int(eval(input())) T = [int(x) for x in input().split()] res = 0 for key in T: left = 0 right = n while left < right: mid = (left + right) // 2 if S[mid] == key: res += 1 right = -1 elif key < S[mid]: right = mid else: left = mid + 1 print(res)
len_a = eval(input()) a = set(map(int, input().split())) len_b = eval(input()) b = set(map(int, input().split())) print((len(a & b)))
21
6
412
126
n = int(eval(input())) S = [int(x) for x in input().split()] q = int(eval(input())) T = [int(x) for x in input().split()] res = 0 for key in T: left = 0 right = n while left < right: mid = (left + right) // 2 if S[mid] == key: res += 1 right = -1 elif key < S[mid]: right = mid else: left = mid + 1 print(res)
len_a = eval(input()) a = set(map(int, input().split())) len_b = eval(input()) b = set(map(int, input().split())) print((len(a & b)))
false
71.428571
[ "-n = int(eval(input()))", "-S = [int(x) for x in input().split()]", "-q = int(eval(input()))", "-T = [int(x) for x in input().split()]", "-res = 0", "-for key in T:", "- left = 0", "- right = n", "- while left < right:", "- mid = (left + right) // 2", "- if S[mid] == key:", "- res += 1", "- right = -1", "- elif key < S[mid]:", "- right = mid", "- else:", "- left = mid + 1", "-print(res)", "+len_a = eval(input())", "+a = set(map(int, input().split()))", "+len_b = eval(input())", "+b = set(map(int, input().split()))", "+print((len(a & b)))" ]
false
0.088349
0.041192
2.14482
[ "s406573756", "s444990259" ]
u644907318
p02972
python
s145378907
s058554786
550
143
14,136
107,532
Accepted
Accepted
74
N = int(eval(input())) A = list(map(int,input().split())) A.insert(0,0) B = [0 for _ in range(N+1)] B[N//2+1:] = A[N//2+1:] for i in range(N//2,0,-1): tot = 0 for j in range(2*i,N+1,i): tot += B[j] B[i] = (A[i]+tot)%2 C = [] M = 0 for i in range(1,N+1): if B[i]==1: M += 1 C.append(i) print(M) if M!=0: print((*C))
N = int(eval(input())) A = list(map(int,input().split())) A.insert(0,0) B = [0 for _ in range(N+1)] for i in range(N//2+1,N+1): B[i] = A[i] for i in range(N//2,0,-1): cnt = A[i] for j in range(2,N//i+1): cnt = (cnt+B[i*j])%2 B[i] = cnt C = [] for i in range(1,N+1): if B[i]==1: C.append(i) print((len(C))) print((*C))
19
17
368
359
N = int(eval(input())) A = list(map(int, input().split())) A.insert(0, 0) B = [0 for _ in range(N + 1)] B[N // 2 + 1 :] = A[N // 2 + 1 :] for i in range(N // 2, 0, -1): tot = 0 for j in range(2 * i, N + 1, i): tot += B[j] B[i] = (A[i] + tot) % 2 C = [] M = 0 for i in range(1, N + 1): if B[i] == 1: M += 1 C.append(i) print(M) if M != 0: print((*C))
N = int(eval(input())) A = list(map(int, input().split())) A.insert(0, 0) B = [0 for _ in range(N + 1)] for i in range(N // 2 + 1, N + 1): B[i] = A[i] for i in range(N // 2, 0, -1): cnt = A[i] for j in range(2, N // i + 1): cnt = (cnt + B[i * j]) % 2 B[i] = cnt C = [] for i in range(1, N + 1): if B[i] == 1: C.append(i) print((len(C))) print((*C))
false
10.526316
[ "-B[N // 2 + 1 :] = A[N // 2 + 1 :]", "+for i in range(N // 2 + 1, N + 1):", "+ B[i] = A[i]", "- tot = 0", "- for j in range(2 * i, N + 1, i):", "- tot += B[j]", "- B[i] = (A[i] + tot) % 2", "+ cnt = A[i]", "+ for j in range(2, N // i + 1):", "+ cnt = (cnt + B[i * j]) % 2", "+ B[i] = cnt", "-M = 0", "- M += 1", "-print(M)", "-if M != 0:", "- print((*C))", "+print((len(C)))", "+print((*C))" ]
false
0.038227
0.038224
1.000077
[ "s145378907", "s058554786" ]
u983918956
p03147
python
s931826446
s084946727
63
45
3,064
3,060
Accepted
Accepted
28.57
N = int(eval(input())) h = list(map(int,input().split())) if h == [0]*N: print((0)) exit() for i in range(1,10001): f = False for j in range(N): if h[j] > 0: h[j] -= 1 f = True elif h[j] <= 0 and f: break if h == [0]*N: ans = i break print(ans)
N = int(eval(input())) H = list(map(int,input().split())) cnt = 0 for _ in range(10**4): if any(H) is False: break cnt += 1 f = False for i in range(len(H)): if H[i] > 0: H[i] -= 1 f = True elif f and H[i] == 0: break print(cnt)
17
15
340
312
N = int(eval(input())) h = list(map(int, input().split())) if h == [0] * N: print((0)) exit() for i in range(1, 10001): f = False for j in range(N): if h[j] > 0: h[j] -= 1 f = True elif h[j] <= 0 and f: break if h == [0] * N: ans = i break print(ans)
N = int(eval(input())) H = list(map(int, input().split())) cnt = 0 for _ in range(10**4): if any(H) is False: break cnt += 1 f = False for i in range(len(H)): if H[i] > 0: H[i] -= 1 f = True elif f and H[i] == 0: break print(cnt)
false
11.764706
[ "-h = list(map(int, input().split()))", "-if h == [0] * N:", "- print((0))", "- exit()", "-for i in range(1, 10001):", "+H = list(map(int, input().split()))", "+cnt = 0", "+for _ in range(10**4):", "+ if any(H) is False:", "+ break", "+ cnt += 1", "- for j in range(N):", "- if h[j] > 0:", "- h[j] -= 1", "+ for i in range(len(H)):", "+ if H[i] > 0:", "+ H[i] -= 1", "- elif h[j] <= 0 and f:", "+ elif f and H[i] == 0:", "- if h == [0] * N:", "- ans = i", "- break", "-print(ans)", "+print(cnt)" ]
false
0.04508
0.037616
1.19843
[ "s931826446", "s084946727" ]
u825981710
p03073
python
s401026608
s634841805
39
18
3,188
3,188
Accepted
Accepted
53.85
s=eval(input()) N=len(s) A=0 B=0 for i in range(0,N,2): if s[i]=='0': A+=1 if i+1==N: break if s[i+1]=='1': B+=1 if A+B<=N/2: print((A+B)) else: print((N-(A+B)))
s=eval(input()) ptn1=s[::2].count('0')+s[1::2].count('1') ptn2=s[::2].count('1')+s[1::2].count('0') print((min(ptn1,ptn2)))
15
4
210
119
s = eval(input()) N = len(s) A = 0 B = 0 for i in range(0, N, 2): if s[i] == "0": A += 1 if i + 1 == N: break if s[i + 1] == "1": B += 1 if A + B <= N / 2: print((A + B)) else: print((N - (A + B)))
s = eval(input()) ptn1 = s[::2].count("0") + s[1::2].count("1") ptn2 = s[::2].count("1") + s[1::2].count("0") print((min(ptn1, ptn2)))
false
73.333333
[ "-N = len(s)", "-A = 0", "-B = 0", "-for i in range(0, N, 2):", "- if s[i] == \"0\":", "- A += 1", "- if i + 1 == N:", "- break", "- if s[i + 1] == \"1\":", "- B += 1", "-if A + B <= N / 2:", "- print((A + B))", "-else:", "- print((N - (A + B)))", "+ptn1 = s[::2].count(\"0\") + s[1::2].count(\"1\")", "+ptn2 = s[::2].count(\"1\") + s[1::2].count(\"0\")", "+print((min(ptn1, ptn2)))" ]
false
0.036546
0.035198
1.038289
[ "s401026608", "s634841805" ]
u767664985
p03730
python
s498008790
s189395484
38
18
5,176
2,940
Accepted
Accepted
52.63
from fractions import gcd A, B, C = list(map(int, input().split())) if C % gcd(A, B) == 0: print("YES") else: print("NO")
A, B, C = list(map(int, input().split())) for i in range(B): if (A*i)%B == C: print("YES") exit() print("NO")
6
6
123
129
from fractions import gcd A, B, C = list(map(int, input().split())) if C % gcd(A, B) == 0: print("YES") else: print("NO")
A, B, C = list(map(int, input().split())) for i in range(B): if (A * i) % B == C: print("YES") exit() print("NO")
false
0
[ "-from fractions import gcd", "-", "-if C % gcd(A, B) == 0:", "- print(\"YES\")", "-else:", "- print(\"NO\")", "+for i in range(B):", "+ if (A * i) % B == C:", "+ print(\"YES\")", "+ exit()", "+print(\"NO\")" ]
false
0.042688
0.035198
1.212783
[ "s498008790", "s189395484" ]
u608088992
p03674
python
s792793855
s632136337
406
326
20,472
34,844
Accepted
Accepted
19.7
def Pow(i, n): if n == 0: return 1 else: ans = Pow(i * i % mod, n//2) if n % 2 == 1: ans *= i ans %= mod return ans N = int(eval(input())) A = [int(i) for i in input().split()] mod = 7 + 10 ** 9 num = [-1 for i in range(N)] for i, a in enumerate(A): if num[a-1] == -1: num[a-1] = i else: Double = [num[a-1], i] Nfact = [1] for i in range(1, N+2): Nfact.append((Nfact[i-1] * (i)) % mod) NfactRev = [Pow(Nfact[N+1], mod-2)] for i in range(1, N+1): NfactRev.append(NfactRev[i-1] * (N+2-i) % mod) NfactRev.append(1) NfactRev.reverse() doublearray = N + 1 - (Double[1] - Double[0]) for i in range(1, N+2): whole = Nfact[N+1] * NfactRev[N+1-i] * NfactRev[i] % mod if i <= doublearray: double = Nfact[doublearray-1] * NfactRev[doublearray-i] * NfactRev[i-1] % mod else: double = 0 print(((whole - double) % mod))
import sys mod = 7 + 10 ** 9 def comb(n, r, fact, revfact, mod): return (fact[n] * revfact[n-r] * revfact[r]) % mod def solve(): input = sys.stdin.readline N = int(eval(input())) A = [int(a) for a in input().split()] Ad = dict() double = [] for i, a in enumerate(A): if a in Ad: Ad[a].append(i) double = Ad[a] else: Ad[a] = [i] fact = [1] * (N + 2) for i in range(1, N + 2): fact[i] = (fact[i - 1] * i) % mod revfact = [1] * (N + 2) revfact[N + 1] = pow(fact[N + 1], mod - 2, mod) for i in reversed(list(range(1, N + 1))):revfact[i] = ((i + 1) * revfact[i + 1]) % mod mayOverCount = double[0] + N - double[1] for k in range(N + 1): total = comb(N + 1, k + 1, fact, revfact, mod) if k <= mayOverCount: total += mod - comb(mayOverCount, k, fact, revfact, mod) total %= mod print(total) return 0 if __name__ == "__main__": solve()
37
36
964
1,013
def Pow(i, n): if n == 0: return 1 else: ans = Pow(i * i % mod, n // 2) if n % 2 == 1: ans *= i ans %= mod return ans N = int(eval(input())) A = [int(i) for i in input().split()] mod = 7 + 10**9 num = [-1 for i in range(N)] for i, a in enumerate(A): if num[a - 1] == -1: num[a - 1] = i else: Double = [num[a - 1], i] Nfact = [1] for i in range(1, N + 2): Nfact.append((Nfact[i - 1] * (i)) % mod) NfactRev = [Pow(Nfact[N + 1], mod - 2)] for i in range(1, N + 1): NfactRev.append(NfactRev[i - 1] * (N + 2 - i) % mod) NfactRev.append(1) NfactRev.reverse() doublearray = N + 1 - (Double[1] - Double[0]) for i in range(1, N + 2): whole = Nfact[N + 1] * NfactRev[N + 1 - i] * NfactRev[i] % mod if i <= doublearray: double = ( Nfact[doublearray - 1] * NfactRev[doublearray - i] * NfactRev[i - 1] % mod ) else: double = 0 print(((whole - double) % mod))
import sys mod = 7 + 10**9 def comb(n, r, fact, revfact, mod): return (fact[n] * revfact[n - r] * revfact[r]) % mod def solve(): input = sys.stdin.readline N = int(eval(input())) A = [int(a) for a in input().split()] Ad = dict() double = [] for i, a in enumerate(A): if a in Ad: Ad[a].append(i) double = Ad[a] else: Ad[a] = [i] fact = [1] * (N + 2) for i in range(1, N + 2): fact[i] = (fact[i - 1] * i) % mod revfact = [1] * (N + 2) revfact[N + 1] = pow(fact[N + 1], mod - 2, mod) for i in reversed(list(range(1, N + 1))): revfact[i] = ((i + 1) * revfact[i + 1]) % mod mayOverCount = double[0] + N - double[1] for k in range(N + 1): total = comb(N + 1, k + 1, fact, revfact, mod) if k <= mayOverCount: total += mod - comb(mayOverCount, k, fact, revfact, mod) total %= mod print(total) return 0 if __name__ == "__main__": solve()
false
2.702703
[ "-def Pow(i, n):", "- if n == 0:", "- return 1", "- else:", "- ans = Pow(i * i % mod, n // 2)", "- if n % 2 == 1:", "- ans *= i", "- ans %= mod", "- return ans", "+import sys", "+", "+mod = 7 + 10**9", "-N = int(eval(input()))", "-A = [int(i) for i in input().split()]", "-mod = 7 + 10**9", "-num = [-1 for i in range(N)]", "-for i, a in enumerate(A):", "- if num[a - 1] == -1:", "- num[a - 1] = i", "- else:", "- Double = [num[a - 1], i]", "-Nfact = [1]", "-for i in range(1, N + 2):", "- Nfact.append((Nfact[i - 1] * (i)) % mod)", "-NfactRev = [Pow(Nfact[N + 1], mod - 2)]", "-for i in range(1, N + 1):", "- NfactRev.append(NfactRev[i - 1] * (N + 2 - i) % mod)", "-NfactRev.append(1)", "-NfactRev.reverse()", "-doublearray = N + 1 - (Double[1] - Double[0])", "-for i in range(1, N + 2):", "- whole = Nfact[N + 1] * NfactRev[N + 1 - i] * NfactRev[i] % mod", "- if i <= doublearray:", "- double = (", "- Nfact[doublearray - 1] * NfactRev[doublearray - i] * NfactRev[i - 1] % mod", "- )", "- else:", "- double = 0", "- print(((whole - double) % mod))", "+def comb(n, r, fact, revfact, mod):", "+ return (fact[n] * revfact[n - r] * revfact[r]) % mod", "+", "+", "+def solve():", "+ input = sys.stdin.readline", "+ N = int(eval(input()))", "+ A = [int(a) for a in input().split()]", "+ Ad = dict()", "+ double = []", "+ for i, a in enumerate(A):", "+ if a in Ad:", "+ Ad[a].append(i)", "+ double = Ad[a]", "+ else:", "+ Ad[a] = [i]", "+ fact = [1] * (N + 2)", "+ for i in range(1, N + 2):", "+ fact[i] = (fact[i - 1] * i) % mod", "+ revfact = [1] * (N + 2)", "+ revfact[N + 1] = pow(fact[N + 1], mod - 2, mod)", "+ for i in reversed(list(range(1, N + 1))):", "+ revfact[i] = ((i + 1) * revfact[i + 1]) % mod", "+ mayOverCount = double[0] + N - double[1]", "+ for k in range(N + 1):", "+ total = comb(N + 1, k + 1, fact, revfact, mod)", "+ if k <= mayOverCount:", "+ total += mod - comb(mayOverCount, k, fact, revfact, mod)", "+ total %= mod", "+ print(total)", "+ return 0", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.046365
0.081645
0.567883
[ "s792793855", "s632136337" ]
u955125992
p02631
python
s484209265
s405669048
1,035
176
53,344
31,700
Accepted
Accepted
83
import numpy as np n = int(eval(input())) a = np.array(input().split(), np.int64) S = a[0] for i in range(1, n): S = np.bitwise_xor(S, a[i]) #xor logic #print(format(S, 'b')) decimal number→binary number for i in range(n): print((np.bitwise_xor(S, a[i])))
n = int(eval(input())) a = list(map(int, input().split())) S = 0 for i in range(n): S ^= a[i] for i in range(n): ans = S^a[i] print(ans)
13
11
275
155
import numpy as np n = int(eval(input())) a = np.array(input().split(), np.int64) S = a[0] for i in range(1, n): S = np.bitwise_xor(S, a[i]) # xor logic # print(format(S, 'b')) decimal number→binary number for i in range(n): print((np.bitwise_xor(S, a[i])))
n = int(eval(input())) a = list(map(int, input().split())) S = 0 for i in range(n): S ^= a[i] for i in range(n): ans = S ^ a[i] print(ans)
false
15.384615
[ "-import numpy as np", "-", "-a = np.array(input().split(), np.int64)", "-S = a[0]", "-for i in range(1, n):", "- S = np.bitwise_xor(S, a[i]) # xor logic", "- # print(format(S, 'b')) decimal number→binary number", "+a = list(map(int, input().split()))", "+S = 0", "- print((np.bitwise_xor(S, a[i])))", "+ S ^= a[i]", "+for i in range(n):", "+ ans = S ^ a[i]", "+ print(ans)" ]
false
0.346785
0.037906
9.148644
[ "s484209265", "s405669048" ]
u778814286
p03126
python
s176230951
s873832408
21
17
3,060
2,940
Accepted
Accepted
19.05
N, M = list(map(int, input().split())) K = [0] * N A = [list(map(int, input().split())) for i in range(N)] count = 0 for i in range(1, M+1, 1): likecount = 0 for j in range(N): for k in range(1, A[j][0]+1, 1): if A[j][k] == i: likecount += 1 if likecount == N: count += 1 print(count)
N, M = list(map(int, input().split())) likeset = set(range(1, M+1)) for _ in range(N): a, *b = list(map(int, input().split())) likeset &= set(b) print((len(likeset)))
13
6
351
169
N, M = list(map(int, input().split())) K = [0] * N A = [list(map(int, input().split())) for i in range(N)] count = 0 for i in range(1, M + 1, 1): likecount = 0 for j in range(N): for k in range(1, A[j][0] + 1, 1): if A[j][k] == i: likecount += 1 if likecount == N: count += 1 print(count)
N, M = list(map(int, input().split())) likeset = set(range(1, M + 1)) for _ in range(N): a, *b = list(map(int, input().split())) likeset &= set(b) print((len(likeset)))
false
53.846154
[ "-K = [0] * N", "-A = [list(map(int, input().split())) for i in range(N)]", "-count = 0", "-for i in range(1, M + 1, 1):", "- likecount = 0", "- for j in range(N):", "- for k in range(1, A[j][0] + 1, 1):", "- if A[j][k] == i:", "- likecount += 1", "- if likecount == N:", "- count += 1", "-print(count)", "+likeset = set(range(1, M + 1))", "+for _ in range(N):", "+ a, *b = list(map(int, input().split()))", "+ likeset &= set(b)", "+print((len(likeset)))" ]
false
0.045752
0.043364
1.05507
[ "s176230951", "s873832408" ]
u241159583
p03733
python
s489150406
s324071082
147
134
26,708
30,808
Accepted
Accepted
8.84
N,T = list(map(int, input().split())) t = list(map(int, input().split())) ans = 0 for i in range(N-1): if t[i+1]-t[i] < T: ans += t[i+1]-t[i] else: ans += T ans += T print(ans)
n,t = list(map(int, input().split())) T = list(map(int, input().split())) ans = 0 for i in range(n-1): if T[i+1]-T[i]<t: ans += T[i+1]-T[i] else: ans += t print((ans+t))
9
8
183
177
N, T = list(map(int, input().split())) t = list(map(int, input().split())) ans = 0 for i in range(N - 1): if t[i + 1] - t[i] < T: ans += t[i + 1] - t[i] else: ans += T ans += T print(ans)
n, t = list(map(int, input().split())) T = list(map(int, input().split())) ans = 0 for i in range(n - 1): if T[i + 1] - T[i] < t: ans += T[i + 1] - T[i] else: ans += t print((ans + t))
false
11.111111
[ "-N, T = list(map(int, input().split()))", "-t = list(map(int, input().split()))", "+n, t = list(map(int, input().split()))", "+T = list(map(int, input().split()))", "-for i in range(N - 1):", "- if t[i + 1] - t[i] < T:", "- ans += t[i + 1] - t[i]", "+for i in range(n - 1):", "+ if T[i + 1] - T[i] < t:", "+ ans += T[i + 1] - T[i]", "- ans += T", "-ans += T", "-print(ans)", "+ ans += t", "+print((ans + t))" ]
false
0.084645
0.034931
2.423184
[ "s489150406", "s324071082" ]
u141610915
p02996
python
s290721658
s258189999
943
596
53,720
68,188
Accepted
Accepted
36.8
N = int(eval(input())) AB = [] for i in range(N): AB.append(list(map(int, input().split()))) AB.sort(key = lambda x: x[1]) time = 0 possibility = 1 for l in AB: if l[0] + time > l[1]: possibility = 0 break else: time += l[0] if possibility == 1: print("Yes") else: print("No")
import sys input = sys.stdin.readline N = int(eval(input())) a = [] for _ in range(N): l, r = list(map(int, input().split())) a.append((l, r)) a.sort(key = lambda x: x[1]) p = 0 for i in range(N): if p <= a[i][1] - a[i][0]: p += a[i][0] else: print("No") exit(0) print("Yes")
22
15
322
293
N = int(eval(input())) AB = [] for i in range(N): AB.append(list(map(int, input().split()))) AB.sort(key=lambda x: x[1]) time = 0 possibility = 1 for l in AB: if l[0] + time > l[1]: possibility = 0 break else: time += l[0] if possibility == 1: print("Yes") else: print("No")
import sys input = sys.stdin.readline N = int(eval(input())) a = [] for _ in range(N): l, r = list(map(int, input().split())) a.append((l, r)) a.sort(key=lambda x: x[1]) p = 0 for i in range(N): if p <= a[i][1] - a[i][0]: p += a[i][0] else: print("No") exit(0) print("Yes")
false
31.818182
[ "+import sys", "+", "+input = sys.stdin.readline", "-AB = []", "+a = []", "+for _ in range(N):", "+ l, r = list(map(int, input().split()))", "+ a.append((l, r))", "+a.sort(key=lambda x: x[1])", "+p = 0", "- AB.append(list(map(int, input().split())))", "-AB.sort(key=lambda x: x[1])", "-time = 0", "-possibility = 1", "-for l in AB:", "- if l[0] + time > l[1]:", "- possibility = 0", "- break", "+ if p <= a[i][1] - a[i][0]:", "+ p += a[i][0]", "- time += l[0]", "-if possibility == 1:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+ print(\"No\")", "+ exit(0)", "+print(\"Yes\")" ]
false
0.046361
0.045859
1.010961
[ "s290721658", "s258189999" ]
u137912513
p02720
python
s105663376
s102660050
207
105
41,584
78,052
Accepted
Accepted
49.28
k = int(eval(input())) count = 9 from collections import deque que = deque([1,2,3,4,5,6,7,8,9]) if k<10: print(k) exit() while que: v = que.popleft() matu = v%10 for i in range(10): if abs(matu-i)<=1: que.append(v*10+i) count +=1 if count == k: print((que.pop())) exit()
from collections import deque k = int(eval(input())) count = 0 que = deque([1,2,3,4,5,6,7,8,9]) while que: q = que.popleft() count +=1 if count == k: print(q) exit() tmp = q%10 if tmp == 0: for i in range(0,2): nq = q*10+i que.append(nq) elif tmp == 9: for i in range(8,10): nq = q*10+i que.append(nq) else: for i in range(tmp-1, tmp+2): nq = q * 10 + i que.append(nq)
17
23
375
524
k = int(eval(input())) count = 9 from collections import deque que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) if k < 10: print(k) exit() while que: v = que.popleft() matu = v % 10 for i in range(10): if abs(matu - i) <= 1: que.append(v * 10 + i) count += 1 if count == k: print((que.pop())) exit()
from collections import deque k = int(eval(input())) count = 0 que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) while que: q = que.popleft() count += 1 if count == k: print(q) exit() tmp = q % 10 if tmp == 0: for i in range(0, 2): nq = q * 10 + i que.append(nq) elif tmp == 9: for i in range(8, 10): nq = q * 10 + i que.append(nq) else: for i in range(tmp - 1, tmp + 2): nq = q * 10 + i que.append(nq)
false
26.086957
[ "-k = int(eval(input()))", "-count = 9", "+k = int(eval(input()))", "+count = 0", "-if k < 10:", "- print(k)", "- exit()", "- v = que.popleft()", "- matu = v % 10", "- for i in range(10):", "- if abs(matu - i) <= 1:", "- que.append(v * 10 + i)", "- count += 1", "- if count == k:", "- print((que.pop()))", "- exit()", "+ q = que.popleft()", "+ count += 1", "+ if count == k:", "+ print(q)", "+ exit()", "+ tmp = q % 10", "+ if tmp == 0:", "+ for i in range(0, 2):", "+ nq = q * 10 + i", "+ que.append(nq)", "+ elif tmp == 9:", "+ for i in range(8, 10):", "+ nq = q * 10 + i", "+ que.append(nq)", "+ else:", "+ for i in range(tmp - 1, tmp + 2):", "+ nq = q * 10 + i", "+ que.append(nq)" ]
false
0.042982
0.064184
0.669665
[ "s105663376", "s102660050" ]
u888337853
p03031
python
s358958390
s104512611
282
40
20,112
5,152
Accepted
Accepted
85.82
import math import copy import fractions import numpy as np # ===FUNCTION=== def getInputNum(): inputNum = int(eval(input())) return inputNum def getInputListInt(): outputoData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n, m = list(map(int, input().split())) status = getSomeInputListInt(m) condition = getInputListInt() ans = 0 mask = [] for i in range(len(status)): mask.append(0b0) for j in range(1, status[i][0]+1): tmp = 1 tmp = tmp << (status[i][j] - 1) mask[i] = mask[i] | tmp for i in range(2**n): flg = True for j in range(m): masked = i & mask[j] oneCnt = bin(masked).count("1") if oneCnt % 2 != condition[j]: flg = False break if flg: ans += 1 print(ans)
import math import copy from copy import deepcopy import sys import fractions # import numpy as np from functools import reduce # import statistics import decimal import heapq import collections import itertools from operator import mul sys.setrecursionlimit(100001) # input = sys.stdin.readline # sys.setrecursionlimit(10**6) # ===FUNCTION=== def getInputInt(): inputNum = int(eval(input())) return inputNum def getInputListInt(): outputData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n, m = list(map(int, input().split())) s = getSomeInputListInt(m) p = getInputListInt() s_bit = [] for tmp_s in s: tmp_bit = 0 for i in range(1, tmp_s[0] + 1, 1): aaa = 1 << (tmp_s[i] - 1) tmp_bit = aaa | tmp_bit s_bit.append(tmp_bit) ans = 0 for i in range(int(pow(2, n))): flg = True for j in range(m): cnt = bin(s_bit[j] & i).count("1") if cnt % 2 != p[j]: flg = False break if flg: ans += 1 print(ans)
69
83
1,355
1,585
import math import copy import fractions import numpy as np # ===FUNCTION=== def getInputNum(): inputNum = int(eval(input())) return inputNum def getInputListInt(): outputoData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n, m = list(map(int, input().split())) status = getSomeInputListInt(m) condition = getInputListInt() ans = 0 mask = [] for i in range(len(status)): mask.append(0b0) for j in range(1, status[i][0] + 1): tmp = 1 tmp = tmp << (status[i][j] - 1) mask[i] = mask[i] | tmp for i in range(2**n): flg = True for j in range(m): masked = i & mask[j] oneCnt = bin(masked).count("1") if oneCnt % 2 != condition[j]: flg = False break if flg: ans += 1 print(ans)
import math import copy from copy import deepcopy import sys import fractions # import numpy as np from functools import reduce # import statistics import decimal import heapq import collections import itertools from operator import mul sys.setrecursionlimit(100001) # input = sys.stdin.readline # sys.setrecursionlimit(10**6) # ===FUNCTION=== def getInputInt(): inputNum = int(eval(input())) return inputNum def getInputListInt(): outputData = [] inputData = input().split() outputData = [int(n) for n in inputData] return outputData def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n, m = list(map(int, input().split())) s = getSomeInputListInt(m) p = getInputListInt() s_bit = [] for tmp_s in s: tmp_bit = 0 for i in range(1, tmp_s[0] + 1, 1): aaa = 1 << (tmp_s[i] - 1) tmp_bit = aaa | tmp_bit s_bit.append(tmp_bit) ans = 0 for i in range(int(pow(2, n))): flg = True for j in range(m): cnt = bin(s_bit[j] & i).count("1") if cnt % 2 != p[j]: flg = False break if flg: ans += 1 print(ans)
false
16.86747
[ "+from copy import deepcopy", "+import sys", "-import numpy as np", "+# import numpy as np", "+from functools import reduce", "+", "+# import statistics", "+import decimal", "+import heapq", "+import collections", "+import itertools", "+from operator import mul", "+", "+sys.setrecursionlimit(100001)", "+# input = sys.stdin.readline", "+# sys.setrecursionlimit(10**6)", "-def getInputNum():", "+def getInputInt():", "- outputoData = []", "+ outputData = []", "-status = getSomeInputListInt(m)", "-condition = getInputListInt()", "+s = getSomeInputListInt(m)", "+p = getInputListInt()", "+s_bit = []", "+for tmp_s in s:", "+ tmp_bit = 0", "+ for i in range(1, tmp_s[0] + 1, 1):", "+ aaa = 1 << (tmp_s[i] - 1)", "+ tmp_bit = aaa | tmp_bit", "+ s_bit.append(tmp_bit)", "-mask = []", "-for i in range(len(status)):", "- mask.append(0b0)", "- for j in range(1, status[i][0] + 1):", "- tmp = 1", "- tmp = tmp << (status[i][j] - 1)", "- mask[i] = mask[i] | tmp", "-for i in range(2**n):", "+for i in range(int(pow(2, n))):", "- masked = i & mask[j]", "- oneCnt = bin(masked).count(\"1\")", "- if oneCnt % 2 != condition[j]:", "+ cnt = bin(s_bit[j] & i).count(\"1\")", "+ if cnt % 2 != p[j]:" ]
false
0.041343
0.036921
1.119778
[ "s358958390", "s104512611" ]
u606045429
p03878
python
s052620207
s500468837
749
666
27,652
27,652
Accepted
Accepted
11.08
mod = 10 ** 9 + 7 N = int(eval(input())) A = [(int(eval(input())), -1) for _ in range(N)] B = [(int(eval(input())), 1) for _ in range(N)] C = sorted(A + B) res = 1 cnt = 0 for _, delta in C: if cnt != 0 and cnt * delta < 0: res *= abs(cnt) res %= mod cnt += delta print(res)
mod = 10 ** 9 + 7 N = int(eval(input())) A = [(int(eval(input())), 1) for _ in range(N)] B = [(int(eval(input())), -1) for _ in range(N)] C = sorted(A + B) res = 1 cnt = 0 for _, delta in C: if cnt * delta < 0: res *= abs(cnt) res %= mod cnt += delta print(res)
17
17
300
287
mod = 10**9 + 7 N = int(eval(input())) A = [(int(eval(input())), -1) for _ in range(N)] B = [(int(eval(input())), 1) for _ in range(N)] C = sorted(A + B) res = 1 cnt = 0 for _, delta in C: if cnt != 0 and cnt * delta < 0: res *= abs(cnt) res %= mod cnt += delta print(res)
mod = 10**9 + 7 N = int(eval(input())) A = [(int(eval(input())), 1) for _ in range(N)] B = [(int(eval(input())), -1) for _ in range(N)] C = sorted(A + B) res = 1 cnt = 0 for _, delta in C: if cnt * delta < 0: res *= abs(cnt) res %= mod cnt += delta print(res)
false
0
[ "-A = [(int(eval(input())), -1) for _ in range(N)]", "-B = [(int(eval(input())), 1) for _ in range(N)]", "+A = [(int(eval(input())), 1) for _ in range(N)]", "+B = [(int(eval(input())), -1) for _ in range(N)]", "- if cnt != 0 and cnt * delta < 0:", "+ if cnt * delta < 0:" ]
false
0.049146
0.034738
1.414771
[ "s052620207", "s500468837" ]
u136811344
p03031
python
s079842066
s686959659
44
33
3,064
3,064
Accepted
Accepted
25
N, M = list(map(int, input().split())) int_switch_repr = 2**N light_bulbs_switches = [] for i in range(M): k_s = [int(x) for x in input().split()] k_i = k_s[0] light_bulbs_switches.append(k_s[1:]) # i-th light bulb P = [int(x) for x in input().split()] # p_i ans = 0 for itg in range(int_switch_repr): binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill='0', width=N) all_on = True for lbs_i, p_i in zip(light_bulbs_switches, P): is_light_on = sum([1 for sw in lbs_i if binary_switch_repr[int(sw)-1]=='1'])%2 == p_i if not is_light_on: all_on = False if all_on: ans+=1 print(ans)
N, M = list(map(int, input().split())) int_switch_repr = 2**N light_bulbs_switches = [] for i in range(M): k_s = [int(x) for x in input().split()] k_i = k_s[0] light_bulbs_switches.append(k_s[1:]) # i-th light bulb P = [int(x) for x in input().split()] # p_i ans = 0 for itg in range(int_switch_repr): binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill='0', width=N) all_on = True for lbs_i, p_i in zip(light_bulbs_switches, P): is_light_on = sum([1 for sw in lbs_i if binary_switch_repr[int(sw)-1]=='1'])%2 == p_i if not is_light_on: all_on = False break if all_on: ans+=1 print(ans)
21
22
637
650
N, M = list(map(int, input().split())) int_switch_repr = 2**N light_bulbs_switches = [] for i in range(M): k_s = [int(x) for x in input().split()] k_i = k_s[0] light_bulbs_switches.append(k_s[1:]) # i-th light bulb P = [int(x) for x in input().split()] # p_i ans = 0 for itg in range(int_switch_repr): binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill="0", width=N) all_on = True for lbs_i, p_i in zip(light_bulbs_switches, P): is_light_on = ( sum([1 for sw in lbs_i if binary_switch_repr[int(sw) - 1] == "1"]) % 2 == p_i ) if not is_light_on: all_on = False if all_on: ans += 1 print(ans)
N, M = list(map(int, input().split())) int_switch_repr = 2**N light_bulbs_switches = [] for i in range(M): k_s = [int(x) for x in input().split()] k_i = k_s[0] light_bulbs_switches.append(k_s[1:]) # i-th light bulb P = [int(x) for x in input().split()] # p_i ans = 0 for itg in range(int_switch_repr): binary_switch_repr = "{w:{fill}{width}b}".format(w=itg, fill="0", width=N) all_on = True for lbs_i, p_i in zip(light_bulbs_switches, P): is_light_on = ( sum([1 for sw in lbs_i if binary_switch_repr[int(sw) - 1] == "1"]) % 2 == p_i ) if not is_light_on: all_on = False break if all_on: ans += 1 print(ans)
false
4.545455
[ "+ break" ]
false
0.038925
0.039783
0.978421
[ "s079842066", "s686959659" ]
u191874006
p02609
python
s680567500
s131975990
339
291
104,540
90,516
Accepted
Accepted
14.16
#!/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() x = eval(input()) b = [] c = [0, 1, 1] for i in range(n+2): cnt = 0 for j in range(101): if i >> j & 1: cnt += 1 b.append(cnt) for i in range(3, n+2): c.append(c[i % b[i]]+1) ans = [] tmp1 = 0 tmp2 = 0 cnt = x.count("1") if cnt != 1: for i in range(n): if x[i] == "1": tmp1 += pow(2, n-(i+1), cnt+1) tmp2 += pow(2, n-(i+1), cnt-1) for i in range(n): if x[i] == "1": ans.append(c[(tmp2 - pow(2, n-(i+1), cnt-1)) % (cnt-1)]+1) else: ans.append(c[(tmp1 + pow(2, n-(i+1), cnt+1)) % (cnt+1)]+1) for i in ans: print(i) else: for i in range(n): if x[i] == "1": tmp1 += pow(2, n-(i+1), cnt+1) for i in range(n): if x[i] == "1": ans.append(0) else: ans.append(c[(tmp1 + pow(2, n-(i+1), cnt+1)) % (cnt+1)]+1) for i in ans: print(i)
#!/usr/bin/env python3 n = int(eval(input())) x = eval(input()) b = [0] * (n+1) for i in range(1, n+1): bit_count = 0 for j in range(20): if i >> j & 1: bit_count += 1 b[i] = bit_count popcount = [0] * (n+1) cnt = x.count('1') for i in range(1, n+1): popcount[i] = popcount[i % b[i]] + 1 ans = [] if cnt == 1: tmp = 0 for i in range(n): if x[i] == '1': tmp += pow(2, n-i-1, 2) tmp %= 2 for i in range(n): if x[i] == '1': ans.append(0) else: ans.append(popcount[(tmp - pow(2, n-i-1, 2)) % 2] + 1) else: tmp1 = 0 tmp2 = 0 for i in range(n): if x[i] == '1': tmp1 += pow(2, n-i-1, cnt + 1) tmp2 += pow(2, n-i-1, cnt - 1) for i in range(n): if x[i] == '1': ans.append(popcount[(tmp2 - pow(2, n-i-1, cnt - 1)) % (cnt - 1)] + 1) else: ans.append(popcount[(tmp1 + pow(2, n-i-1, cnt + 1)) % (cnt + 1)] + 1) for i in ans: print(i)
62
44
1,538
1,067
#!/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() x = eval(input()) b = [] c = [0, 1, 1] for i in range(n + 2): cnt = 0 for j in range(101): if i >> j & 1: cnt += 1 b.append(cnt) for i in range(3, n + 2): c.append(c[i % b[i]] + 1) ans = [] tmp1 = 0 tmp2 = 0 cnt = x.count("1") if cnt != 1: for i in range(n): if x[i] == "1": tmp1 += pow(2, n - (i + 1), cnt + 1) tmp2 += pow(2, n - (i + 1), cnt - 1) for i in range(n): if x[i] == "1": ans.append(c[(tmp2 - pow(2, n - (i + 1), cnt - 1)) % (cnt - 1)] + 1) else: ans.append(c[(tmp1 + pow(2, n - (i + 1), cnt + 1)) % (cnt + 1)] + 1) for i in ans: print(i) else: for i in range(n): if x[i] == "1": tmp1 += pow(2, n - (i + 1), cnt + 1) for i in range(n): if x[i] == "1": ans.append(0) else: ans.append(c[(tmp1 + pow(2, n - (i + 1), cnt + 1)) % (cnt + 1)] + 1) for i in ans: print(i)
#!/usr/bin/env python3 n = int(eval(input())) x = eval(input()) b = [0] * (n + 1) for i in range(1, n + 1): bit_count = 0 for j in range(20): if i >> j & 1: bit_count += 1 b[i] = bit_count popcount = [0] * (n + 1) cnt = x.count("1") for i in range(1, n + 1): popcount[i] = popcount[i % b[i]] + 1 ans = [] if cnt == 1: tmp = 0 for i in range(n): if x[i] == "1": tmp += pow(2, n - i - 1, 2) tmp %= 2 for i in range(n): if x[i] == "1": ans.append(0) else: ans.append(popcount[(tmp - pow(2, n - i - 1, 2)) % 2] + 1) else: tmp1 = 0 tmp2 = 0 for i in range(n): if x[i] == "1": tmp1 += pow(2, n - i - 1, cnt + 1) tmp2 += pow(2, n - i - 1, cnt - 1) for i in range(n): if x[i] == "1": ans.append(popcount[(tmp2 - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)] + 1) else: ans.append(popcount[(tmp1 + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)] + 1) for i in ans: print(i)
false
29.032258
[ "-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()", "+n = int(eval(input()))", "-b = []", "-c = [0, 1, 1]", "-for i in range(n + 2):", "- cnt = 0", "- for j in range(101):", "+b = [0] * (n + 1)", "+for i in range(1, n + 1):", "+ bit_count = 0", "+ for j in range(20):", "- cnt += 1", "- b.append(cnt)", "-for i in range(3, n + 2):", "- c.append(c[i % b[i]] + 1)", "+ bit_count += 1", "+ b[i] = bit_count", "+popcount = [0] * (n + 1)", "+cnt = x.count(\"1\")", "+for i in range(1, n + 1):", "+ popcount[i] = popcount[i % b[i]] + 1", "-tmp1 = 0", "-tmp2 = 0", "-cnt = x.count(\"1\")", "-if cnt != 1:", "+if cnt == 1:", "+ tmp = 0", "- tmp1 += pow(2, n - (i + 1), cnt + 1)", "- tmp2 += pow(2, n - (i + 1), cnt - 1)", "- for i in range(n):", "- if x[i] == \"1\":", "- ans.append(c[(tmp2 - pow(2, n - (i + 1), cnt - 1)) % (cnt - 1)] + 1)", "- else:", "- ans.append(c[(tmp1 + pow(2, n - (i + 1), cnt + 1)) % (cnt + 1)] + 1)", "- for i in ans:", "- print(i)", "-else:", "- for i in range(n):", "- if x[i] == \"1\":", "- tmp1 += pow(2, n - (i + 1), cnt + 1)", "+ tmp += pow(2, n - i - 1, 2)", "+ tmp %= 2", "- ans.append(c[(tmp1 + pow(2, n - (i + 1), cnt + 1)) % (cnt + 1)] + 1)", "- for i in ans:", "- print(i)", "+ ans.append(popcount[(tmp - pow(2, n - i - 1, 2)) % 2] + 1)", "+else:", "+ tmp1 = 0", "+ tmp2 = 0", "+ for i in range(n):", "+ if x[i] == \"1\":", "+ tmp1 += pow(2, n - i - 1, cnt + 1)", "+ tmp2 += pow(2, n - i - 1, cnt - 1)", "+ for i in range(n):", "+ if x[i] == \"1\":", "+ ans.append(popcount[(tmp2 - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)] + 1)", "+ else:", "+ ans.append(popcount[(tmp1 + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)] + 1)", "+for i in ans:", "+ print(i)" ]
false
0.090363
0.122534
0.737448
[ "s680567500", "s131975990" ]
u923279197
p03105
python
s274387122
s131186696
169
17
38,384
2,940
Accepted
Accepted
89.94
a,b,c = list(map(int,input().split())) print((min(b//a,c)))
a,b,c = list(map(int,input().split())) print((min(c,b//a)))
2
2
52
52
a, b, c = list(map(int, input().split())) print((min(b // a, c)))
a, b, c = list(map(int, input().split())) print((min(c, b // a)))
false
0
[ "-print((min(b // a, c)))", "+print((min(c, b // a)))" ]
false
0.118591
0.040347
2.939307
[ "s274387122", "s131186696" ]
u844789719
p04013
python
s114306591
s698138430
50
26
3,188
3,188
Accepted
Accepted
48
N, A = [int(_) for _ in input().split()] X = [int(_) - A for _ in input().split()] X_plus = [_ for _ in X if _ > 0] X_minus = [-_ for _ in X if _ < 0] l_plus = len(X_plus) l_minus = len(X_minus) l_zero = len(X) - l_plus - l_minus s_plus = sum(X_plus) s_minus = sum(X_minus) dp_plus = [1] + [0] * s_plus dp_minus = [1] + [0] * s_minus for i in range(l_plus): dp_plus_old = dp_plus.copy() for j in range(s_plus + 1 - X_plus[i]): dp_plus[j + X_plus[i]] += dp_plus_old[j] for i in range(l_minus): dp_minus_old = dp_minus.copy() for j in range(s_minus + 1 - X_minus[i]): dp_minus[j + X_minus[i]] += dp_minus_old[j] c_zero = 2 ** l_zero ans = c_zero - 1 for j in range(1, min(s_plus, s_minus) + 1): ans += c_zero * dp_plus[j] * dp_minus[j] print(ans)
N, A = [int(_) for _ in input().split()] X = [int(_) - A for _ in input().split()] X_plus = [_ for _ in X if _ > 0] X_minus = [-_ for _ in X if _ < 0] l_zero = len(X) - len(X_plus) - len(X_minus) s_plus = sum(X_plus) s_minus = sum(X_minus) dp_plus = {0: 1} dp_minus = {0: 1} for p in X_plus: dp_plus_old = dp_plus.copy() for k, v in list(dp_plus_old.items()): dp_plus[k + p] = dp_plus_old.get(k, 0) + dp_plus_old.get(k + p, 0) for m in X_minus: dp_minus_old = dp_minus.copy() for k, v in list(dp_minus_old.items()): dp_minus[k + m] = dp_minus_old.get(k, 0) + dp_minus_old.get(k + m, 0) c_zero = 2 ** l_zero ans = c_zero - 1 for j in range(1, min(s_plus, s_minus) + 1): ans += c_zero * dp_plus.get(j, 0) * dp_minus.get(j, 0) print(ans)
24
22
804
780
N, A = [int(_) for _ in input().split()] X = [int(_) - A for _ in input().split()] X_plus = [_ for _ in X if _ > 0] X_minus = [-_ for _ in X if _ < 0] l_plus = len(X_plus) l_minus = len(X_minus) l_zero = len(X) - l_plus - l_minus s_plus = sum(X_plus) s_minus = sum(X_minus) dp_plus = [1] + [0] * s_plus dp_minus = [1] + [0] * s_minus for i in range(l_plus): dp_plus_old = dp_plus.copy() for j in range(s_plus + 1 - X_plus[i]): dp_plus[j + X_plus[i]] += dp_plus_old[j] for i in range(l_minus): dp_minus_old = dp_minus.copy() for j in range(s_minus + 1 - X_minus[i]): dp_minus[j + X_minus[i]] += dp_minus_old[j] c_zero = 2**l_zero ans = c_zero - 1 for j in range(1, min(s_plus, s_minus) + 1): ans += c_zero * dp_plus[j] * dp_minus[j] print(ans)
N, A = [int(_) for _ in input().split()] X = [int(_) - A for _ in input().split()] X_plus = [_ for _ in X if _ > 0] X_minus = [-_ for _ in X if _ < 0] l_zero = len(X) - len(X_plus) - len(X_minus) s_plus = sum(X_plus) s_minus = sum(X_minus) dp_plus = {0: 1} dp_minus = {0: 1} for p in X_plus: dp_plus_old = dp_plus.copy() for k, v in list(dp_plus_old.items()): dp_plus[k + p] = dp_plus_old.get(k, 0) + dp_plus_old.get(k + p, 0) for m in X_minus: dp_minus_old = dp_minus.copy() for k, v in list(dp_minus_old.items()): dp_minus[k + m] = dp_minus_old.get(k, 0) + dp_minus_old.get(k + m, 0) c_zero = 2**l_zero ans = c_zero - 1 for j in range(1, min(s_plus, s_minus) + 1): ans += c_zero * dp_plus.get(j, 0) * dp_minus.get(j, 0) print(ans)
false
8.333333
[ "-l_plus = len(X_plus)", "-l_minus = len(X_minus)", "-l_zero = len(X) - l_plus - l_minus", "+l_zero = len(X) - len(X_plus) - len(X_minus)", "-dp_plus = [1] + [0] * s_plus", "-dp_minus = [1] + [0] * s_minus", "-for i in range(l_plus):", "+dp_plus = {0: 1}", "+dp_minus = {0: 1}", "+for p in X_plus:", "- for j in range(s_plus + 1 - X_plus[i]):", "- dp_plus[j + X_plus[i]] += dp_plus_old[j]", "-for i in range(l_minus):", "+ for k, v in list(dp_plus_old.items()):", "+ dp_plus[k + p] = dp_plus_old.get(k, 0) + dp_plus_old.get(k + p, 0)", "+for m in X_minus:", "- for j in range(s_minus + 1 - X_minus[i]):", "- dp_minus[j + X_minus[i]] += dp_minus_old[j]", "+ for k, v in list(dp_minus_old.items()):", "+ dp_minus[k + m] = dp_minus_old.get(k, 0) + dp_minus_old.get(k + m, 0)", "- ans += c_zero * dp_plus[j] * dp_minus[j]", "+ ans += c_zero * dp_plus.get(j, 0) * dp_minus.get(j, 0)" ]
false
0.041155
0.056256
0.731564
[ "s114306591", "s698138430" ]
u633068244
p00095
python
s054432345
s792518765
20
10
4,204
4,204
Accepted
Accepted
50
n = int(input()) mxs, minm = 0, 1000 for i in range(n): m, s = list(map(int, input().split())) if s > mxs: mxs = s minm = m elif s == mxs: if m < minm: minm = m print(minm, mxs)
n = int(input()) mxs, minm = 0, 21 for i in range(n): m, s = list(map(int, input().split())) if s > mxs: mxs = s minm = m elif s == mxs: if m < minm: minm = m print(minm, mxs)
11
11
237
235
n = int(input()) mxs, minm = 0, 1000 for i in range(n): m, s = list(map(int, input().split())) if s > mxs: mxs = s minm = m elif s == mxs: if m < minm: minm = m print(minm, mxs)
n = int(input()) mxs, minm = 0, 21 for i in range(n): m, s = list(map(int, input().split())) if s > mxs: mxs = s minm = m elif s == mxs: if m < minm: minm = m print(minm, mxs)
false
0
[ "-mxs, minm = 0, 1000", "+mxs, minm = 0, 21" ]
false
0.046728
0.046899
0.996343
[ "s054432345", "s792518765" ]
u143322814
p02714
python
s723183023
s802845596
1,913
1,034
9,196
9,216
Accepted
Accepted
45.95
n = int(eval(input())) s = eval(input()) ans = s.count('R') * s.count('G') * s.count('B') for j in range(n): for i in range(j): k = j+(j-i) if k < n: if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]: continue ans -= 1 print(ans)
def main(): n = int(eval(input())) s = eval(input()) r,g,b = 0,0,0 for i in s: if i == 'R': r += 1 elif i == 'G': g += 1 elif i == 'B': b += 1 ans = r*g*b for j in range(n): for i in range(j): k = j+(j-i) if k < n: if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]: continue ans -= 1 print(ans) if __name__ == "__main__": main()
12
20
287
474
n = int(eval(input())) s = eval(input()) ans = s.count("R") * s.count("G") * s.count("B") for j in range(n): for i in range(j): k = j + (j - i) if k < n: if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]: continue ans -= 1 print(ans)
def main(): n = int(eval(input())) s = eval(input()) r, g, b = 0, 0, 0 for i in s: if i == "R": r += 1 elif i == "G": g += 1 elif i == "B": b += 1 ans = r * g * b for j in range(n): for i in range(j): k = j + (j - i) if k < n: if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]: continue ans -= 1 print(ans) if __name__ == "__main__": main()
false
40
[ "-n = int(eval(input()))", "-s = eval(input())", "-ans = s.count(\"R\") * s.count(\"G\") * s.count(\"B\")", "-for j in range(n):", "- for i in range(j):", "- k = j + (j - i)", "- if k < n:", "- if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:", "- continue", "- ans -= 1", "-print(ans)", "+def main():", "+ n = int(eval(input()))", "+ s = eval(input())", "+ r, g, b = 0, 0, 0", "+ for i in s:", "+ if i == \"R\":", "+ r += 1", "+ elif i == \"G\":", "+ g += 1", "+ elif i == \"B\":", "+ b += 1", "+ ans = r * g * b", "+ for j in range(n):", "+ for i in range(j):", "+ k = j + (j - i)", "+ if k < n:", "+ if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:", "+ continue", "+ ans -= 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.036764
0.036355
1.01125
[ "s723183023", "s802845596" ]
u806976856
p03575
python
s587556006
s816850529
109
78
68,040
73,616
Accepted
Accepted
28.44
import sys sys.setrecursionlimit(10**9) n,m=list(map(int,input().split())) ab=[[0,0] for i in range(m)] for i in range(m): ab[i][0],ab[i][1]=list(map(int,input().split())) ans=0 for i in range(m): root=[j for j in range(n+1)] root[0]=1 def r(x): if root[x]==x: return x else: root[x]=r(root[x]) return root[x] def unite(x,y): x=r(x) y=r(y) if x==y: return else: x,y=min(x,y),max(x,y) root[y]=x for j in range(m): if j!=i: a,b=ab[j][0],ab[j][1] unite(a,b) if not all(r(j)==1 for j in range(1,n+1)): ans+=1 print(ans)
from _collections import deque n,m=list(map(int,input().split())) ab=[[0,0] for i in range(m)] for i in range(m): ab[i][0],ab[i][1]=list(map(int,input().split())) ans=0 for i in range(m): edg=[[] for j in range(n+1)] dep=[-1]*(n+1) dep[0]=1 dep[1]=1 for j in range(m): if j!=i: a,b=ab[j][0],ab[j][1] edg[a].append(b) edg[b].append(a) data=deque([1]) while len(data)>0: p=data.popleft() for j in edg[p]: if dep[j]==-1: dep[j]=1 data.append(j) if not all(dep[i]==1 for i in range(n+1)):ans+=1 print(ans)
34
25
729
654
import sys sys.setrecursionlimit(10**9) n, m = list(map(int, input().split())) ab = [[0, 0] for i in range(m)] for i in range(m): ab[i][0], ab[i][1] = list(map(int, input().split())) ans = 0 for i in range(m): root = [j for j in range(n + 1)] root[0] = 1 def r(x): if root[x] == x: return x else: root[x] = r(root[x]) return root[x] def unite(x, y): x = r(x) y = r(y) if x == y: return else: x, y = min(x, y), max(x, y) root[y] = x for j in range(m): if j != i: a, b = ab[j][0], ab[j][1] unite(a, b) if not all(r(j) == 1 for j in range(1, n + 1)): ans += 1 print(ans)
from _collections import deque n, m = list(map(int, input().split())) ab = [[0, 0] for i in range(m)] for i in range(m): ab[i][0], ab[i][1] = list(map(int, input().split())) ans = 0 for i in range(m): edg = [[] for j in range(n + 1)] dep = [-1] * (n + 1) dep[0] = 1 dep[1] = 1 for j in range(m): if j != i: a, b = ab[j][0], ab[j][1] edg[a].append(b) edg[b].append(a) data = deque([1]) while len(data) > 0: p = data.popleft() for j in edg[p]: if dep[j] == -1: dep[j] = 1 data.append(j) if not all(dep[i] == 1 for i in range(n + 1)): ans += 1 print(ans)
false
26.470588
[ "-import sys", "+from _collections import deque", "-sys.setrecursionlimit(10**9)", "- root = [j for j in range(n + 1)]", "- root[0] = 1", "-", "- def r(x):", "- if root[x] == x:", "- return x", "- else:", "- root[x] = r(root[x])", "- return root[x]", "-", "- def unite(x, y):", "- x = r(x)", "- y = r(y)", "- if x == y:", "- return", "- else:", "- x, y = min(x, y), max(x, y)", "- root[y] = x", "-", "+ edg = [[] for j in range(n + 1)]", "+ dep = [-1] * (n + 1)", "+ dep[0] = 1", "+ dep[1] = 1", "- unite(a, b)", "- if not all(r(j) == 1 for j in range(1, n + 1)):", "+ edg[a].append(b)", "+ edg[b].append(a)", "+ data = deque([1])", "+ while len(data) > 0:", "+ p = data.popleft()", "+ for j in edg[p]:", "+ if dep[j] == -1:", "+ dep[j] = 1", "+ data.append(j)", "+ if not all(dep[i] == 1 for i in range(n + 1)):" ]
false
0.037625
0.037383
1.006463
[ "s587556006", "s816850529" ]
u780475861
p03848
python
s834868565
s233860319
101
79
13,940
15,840
Accepted
Accepted
21.78
import sys n, *lst = list(map(int, sys.stdin.read().split())) lst.sort() mod = 10 ** 9 + 7 if n % 2: for i in range(1, n): if lst[i] != (i + 1) // 2 * 2: print((0)) quit() else: for i in range(n): if lst[i] != i // 2 * 2 + 1: print((0)) quit() print(((1 << (n >> 1)) % mod))
import sys from collections import Counter def main(): n, *lst = list(map(int, sys.stdin.read().split())) lst = sorted(Counter(lst).items()) l = len(lst) mod = 10 ** 9 + 7 if n % 2: for i in range(l): if not i: if lst[i][0] or lst[i][1] != 1: print((0)) quit() elif lst[i][0] != i * 2 or lst[i][1] != 2: print((0)) quit() else: for i in range(l): if lst[i][0] != i * 2 + 1 or lst[i][1] != 2: print((0)) quit() print(((1 << (n >> 1)) % mod)) if __name__ == '__main__': main()
16
28
314
593
import sys n, *lst = list(map(int, sys.stdin.read().split())) lst.sort() mod = 10**9 + 7 if n % 2: for i in range(1, n): if lst[i] != (i + 1) // 2 * 2: print((0)) quit() else: for i in range(n): if lst[i] != i // 2 * 2 + 1: print((0)) quit() print(((1 << (n >> 1)) % mod))
import sys from collections import Counter def main(): n, *lst = list(map(int, sys.stdin.read().split())) lst = sorted(Counter(lst).items()) l = len(lst) mod = 10**9 + 7 if n % 2: for i in range(l): if not i: if lst[i][0] or lst[i][1] != 1: print((0)) quit() elif lst[i][0] != i * 2 or lst[i][1] != 2: print((0)) quit() else: for i in range(l): if lst[i][0] != i * 2 + 1 or lst[i][1] != 2: print((0)) quit() print(((1 << (n >> 1)) % mod)) if __name__ == "__main__": main()
false
42.857143
[ "+from collections import Counter", "-n, *lst = list(map(int, sys.stdin.read().split()))", "-lst.sort()", "-mod = 10**9 + 7", "-if n % 2:", "- for i in range(1, n):", "- if lst[i] != (i + 1) // 2 * 2:", "- print((0))", "- quit()", "-else:", "- for i in range(n):", "- if lst[i] != i // 2 * 2 + 1:", "- print((0))", "- quit()", "-print(((1 << (n >> 1)) % mod))", "+", "+def main():", "+ n, *lst = list(map(int, sys.stdin.read().split()))", "+ lst = sorted(Counter(lst).items())", "+ l = len(lst)", "+ mod = 10**9 + 7", "+ if n % 2:", "+ for i in range(l):", "+ if not i:", "+ if lst[i][0] or lst[i][1] != 1:", "+ print((0))", "+ quit()", "+ elif lst[i][0] != i * 2 or lst[i][1] != 2:", "+ print((0))", "+ quit()", "+ else:", "+ for i in range(l):", "+ if lst[i][0] != i * 2 + 1 or lst[i][1] != 2:", "+ print((0))", "+ quit()", "+ print(((1 << (n >> 1)) % mod))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.039009
0.039079
0.99822
[ "s834868565", "s233860319" ]
u677121387
p03732
python
s096236950
s883628592
319
256
75,740
42,604
Accepted
Accepted
19.75
n,W = list(map(int,input().split())) w = [0]*n v = [0]*n for i in range(n): w[i],v[i] = list(map(int,input().split())) x = w[0] for i in range(n): w[i] -= x dp = [[[0]*(4*n+1) for _ in range(n+1)] for _ in range(n+1)] for i in range(n): for j in range(i+1): for k in range(4*n+1): if (j+1)*x+k <= W and k-w[i] >= 0: dp[i+1][j+1][k] = max(dp[i+1][j+1][k],dp[i][j][k-w[i]]+v[i]) dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]) """ for i in range(n+1): print(i,"///////////////////////////////////////////////") for j in range(n+1): print(dp[i][j]) """ print((max(max(dp[n][j]) for j in range(n+1))))
n,W = list(map(int,input().split())) lst = [[0]*(n+1) for _ in range(4)] for i in range(n): w,v = list(map(int,input().split())) if i == 0: x = w lst[w-x].append(v) for i in range(4): lst[i].sort(reverse=True) for j in range(n): lst[i][j+1] += lst[i][j] ans = 0 for a in range(n+1): for b in range(n+1-a): for c in range(n+1-a-b): if x*a+(x+1)*b+(x+2)*c > W: continue d = max((W-x*a-(x+1)*b-(x+2)*c)//(x+3),0) sumv = 0 for i,j in enumerate((a,b,c,d)): if j == 0: continue sumv += lst[i][j-1] ans = max(sumv,ans) print(ans)
22
21
673
654
n, W = list(map(int, input().split())) w = [0] * n v = [0] * n for i in range(n): w[i], v[i] = list(map(int, input().split())) x = w[0] for i in range(n): w[i] -= x dp = [[[0] * (4 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)] for i in range(n): for j in range(i + 1): for k in range(4 * n + 1): if (j + 1) * x + k <= W and k - w[i] >= 0: dp[i + 1][j + 1][k] = max( dp[i + 1][j + 1][k], dp[i][j][k - w[i]] + v[i] ) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]) """ for i in range(n+1): print(i,"///////////////////////////////////////////////") for j in range(n+1): print(dp[i][j]) """ print((max(max(dp[n][j]) for j in range(n + 1))))
n, W = list(map(int, input().split())) lst = [[0] * (n + 1) for _ in range(4)] for i in range(n): w, v = list(map(int, input().split())) if i == 0: x = w lst[w - x].append(v) for i in range(4): lst[i].sort(reverse=True) for j in range(n): lst[i][j + 1] += lst[i][j] ans = 0 for a in range(n + 1): for b in range(n + 1 - a): for c in range(n + 1 - a - b): if x * a + (x + 1) * b + (x + 2) * c > W: continue d = max((W - x * a - (x + 1) * b - (x + 2) * c) // (x + 3), 0) sumv = 0 for i, j in enumerate((a, b, c, d)): if j == 0: continue sumv += lst[i][j - 1] ans = max(sumv, ans) print(ans)
false
4.545455
[ "-w = [0] * n", "-v = [0] * n", "+lst = [[0] * (n + 1) for _ in range(4)]", "- w[i], v[i] = list(map(int, input().split()))", "-x = w[0]", "-for i in range(n):", "- w[i] -= x", "-dp = [[[0] * (4 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]", "-for i in range(n):", "- for j in range(i + 1):", "- for k in range(4 * n + 1):", "- if (j + 1) * x + k <= W and k - w[i] >= 0:", "- dp[i + 1][j + 1][k] = max(", "- dp[i + 1][j + 1][k], dp[i][j][k - w[i]] + v[i]", "- )", "- dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k])", "-\"\"\"", "-for i in range(n+1):", "- print(i,\"///////////////////////////////////////////////\")", "- for j in range(n+1):", "- print(dp[i][j])", "-\"\"\"", "-print((max(max(dp[n][j]) for j in range(n + 1))))", "+ w, v = list(map(int, input().split()))", "+ if i == 0:", "+ x = w", "+ lst[w - x].append(v)", "+for i in range(4):", "+ lst[i].sort(reverse=True)", "+ for j in range(n):", "+ lst[i][j + 1] += lst[i][j]", "+ans = 0", "+for a in range(n + 1):", "+ for b in range(n + 1 - a):", "+ for c in range(n + 1 - a - b):", "+ if x * a + (x + 1) * b + (x + 2) * c > W:", "+ continue", "+ d = max((W - x * a - (x + 1) * b - (x + 2) * c) // (x + 3), 0)", "+ sumv = 0", "+ for i, j in enumerate((a, b, c, d)):", "+ if j == 0:", "+ continue", "+ sumv += lst[i][j - 1]", "+ ans = max(sumv, ans)", "+print(ans)" ]
false
0.047452
0.048548
0.977426
[ "s096236950", "s883628592" ]
u780962115
p03014
python
s482470636
s766251560
1,336
713
364,164
154,592
Accepted
Accepted
46.63
#lamp import sys input=sys.stdin.readline h,w=list(map(int,input().split())) lists=[] for i in range(h): b=list(eval(input())) lists.append(b) right=[[0 for i in range(w)] for j in range(h)] left=[[0 for i in range(w)] for j in range(h)] up=[[0 for i in range(w)] for j in range(h)] down=[[0 for i in range(w)] for j in range(h)] #rightの累積和 for i in range(h): for j in range(w-1,-1,-1): if j==w-1: if lists[i][j]=="#": right[i][j]=0 else: right[i][j]=1 else: if lists[i][j+1]=="#": if lists[i][j]=="#": right[i][j]=0 else: right[i][j]=1 elif lists[i][j+1]==".": if lists[i][j]=="#": right[i][j]=0 else: right[i][j]=right[i][j+1]+1 #leftの累積和 for i in range(h): for j in range(w): if j==0: if lists[i][j]=="#": left[i][j]=0 else: left[i][j]=1 else: if lists[i][j]=="#": left[i][j]=0 else: left[i][j]=left[i][j-1]+1 #upの累積和 for i in range(w): for j in range(h): if j==0: if lists[j][i]=="#": up[j][i]=0 else: up[j][i]=1 else: if lists[j][i]=="#": up[j][i]=0 else: up[j][i]=up[j-1][i]+1 #downの累積和 for i in range(w): for j in range(h-1,-1,-1): if j==h-1: if lists[j][i]=="#": down[j][i]=0 else: down[j][i]=1 else: if lists[j][i]=="#": down[j][i]=0 else: down[j][i]=down[j+1][i]+1 maxi=0 for i in range(h): for j in range(w): maxi=max(maxi,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3) print(maxi)
h,w=list(map(int,input().split())) lists=[] for i in range(h): s=eval(input()) lists.append(s) ylists=[] for some in lists: some=some+"#" cnt=0 add=[] for i in range(w+1): if some[i]=="#": if cnt==0: add.append(0) cnt=0 else: add.extend([cnt]*cnt) add.append(0) cnt=0 elif some[i]!="#": cnt+=1 del add[-1] ylists.append(add) lists1=[] for i in range(w): adds="" for j in range(h): adds+=lists[j][i] lists1.append(adds) tlists=[] for some in lists1: some=some+"#" cnt=0 add=[] for i in range(h+1): if some[i]=="#": if cnt==0: add.append(0) cnt=0 else: add.extend([cnt]*cnt) add.append(0) cnt=0 elif some[i]!="#": cnt+=1 del add[-1] tlists.append(add) maximum=0 for i in range(h): for j in range(w): if ylists[i][j]==0 or tlists[j][i]==0: continue else: maximum=max(maximum,ylists[i][j]+tlists[j][i]-1) print(maximum)
84
63
2,079
1,314
# lamp import sys input = sys.stdin.readline h, w = list(map(int, input().split())) lists = [] for i in range(h): b = list(eval(input())) lists.append(b) right = [[0 for i in range(w)] for j in range(h)] left = [[0 for i in range(w)] for j in range(h)] up = [[0 for i in range(w)] for j in range(h)] down = [[0 for i in range(w)] for j in range(h)] # rightの累積和 for i in range(h): for j in range(w - 1, -1, -1): if j == w - 1: if lists[i][j] == "#": right[i][j] = 0 else: right[i][j] = 1 else: if lists[i][j + 1] == "#": if lists[i][j] == "#": right[i][j] = 0 else: right[i][j] = 1 elif lists[i][j + 1] == ".": if lists[i][j] == "#": right[i][j] = 0 else: right[i][j] = right[i][j + 1] + 1 # leftの累積和 for i in range(h): for j in range(w): if j == 0: if lists[i][j] == "#": left[i][j] = 0 else: left[i][j] = 1 else: if lists[i][j] == "#": left[i][j] = 0 else: left[i][j] = left[i][j - 1] + 1 # upの累積和 for i in range(w): for j in range(h): if j == 0: if lists[j][i] == "#": up[j][i] = 0 else: up[j][i] = 1 else: if lists[j][i] == "#": up[j][i] = 0 else: up[j][i] = up[j - 1][i] + 1 # downの累積和 for i in range(w): for j in range(h - 1, -1, -1): if j == h - 1: if lists[j][i] == "#": down[j][i] = 0 else: down[j][i] = 1 else: if lists[j][i] == "#": down[j][i] = 0 else: down[j][i] = down[j + 1][i] + 1 maxi = 0 for i in range(h): for j in range(w): maxi = max(maxi, right[i][j] + left[i][j] + up[i][j] + down[i][j] - 3) print(maxi)
h, w = list(map(int, input().split())) lists = [] for i in range(h): s = eval(input()) lists.append(s) ylists = [] for some in lists: some = some + "#" cnt = 0 add = [] for i in range(w + 1): if some[i] == "#": if cnt == 0: add.append(0) cnt = 0 else: add.extend([cnt] * cnt) add.append(0) cnt = 0 elif some[i] != "#": cnt += 1 del add[-1] ylists.append(add) lists1 = [] for i in range(w): adds = "" for j in range(h): adds += lists[j][i] lists1.append(adds) tlists = [] for some in lists1: some = some + "#" cnt = 0 add = [] for i in range(h + 1): if some[i] == "#": if cnt == 0: add.append(0) cnt = 0 else: add.extend([cnt] * cnt) add.append(0) cnt = 0 elif some[i] != "#": cnt += 1 del add[-1] tlists.append(add) maximum = 0 for i in range(h): for j in range(w): if ylists[i][j] == 0 or tlists[j][i] == 0: continue else: maximum = max(maximum, ylists[i][j] + tlists[j][i] - 1) print(maximum)
false
25
[ "-# lamp", "-import sys", "-", "-input = sys.stdin.readline", "- b = list(eval(input()))", "- lists.append(b)", "-right = [[0 for i in range(w)] for j in range(h)]", "-left = [[0 for i in range(w)] for j in range(h)]", "-up = [[0 for i in range(w)] for j in range(h)]", "-down = [[0 for i in range(w)] for j in range(h)]", "-# rightの累積和", "-for i in range(h):", "- for j in range(w - 1, -1, -1):", "- if j == w - 1:", "- if lists[i][j] == \"#\":", "- right[i][j] = 0", "+ s = eval(input())", "+ lists.append(s)", "+ylists = []", "+for some in lists:", "+ some = some + \"#\"", "+ cnt = 0", "+ add = []", "+ for i in range(w + 1):", "+ if some[i] == \"#\":", "+ if cnt == 0:", "+ add.append(0)", "+ cnt = 0", "- right[i][j] = 1", "- else:", "- if lists[i][j + 1] == \"#\":", "- if lists[i][j] == \"#\":", "- right[i][j] = 0", "- else:", "- right[i][j] = 1", "- elif lists[i][j + 1] == \".\":", "- if lists[i][j] == \"#\":", "- right[i][j] = 0", "- else:", "- right[i][j] = right[i][j + 1] + 1", "-# leftの累積和", "+ add.extend([cnt] * cnt)", "+ add.append(0)", "+ cnt = 0", "+ elif some[i] != \"#\":", "+ cnt += 1", "+ del add[-1]", "+ ylists.append(add)", "+lists1 = []", "+for i in range(w):", "+ adds = \"\"", "+ for j in range(h):", "+ adds += lists[j][i]", "+ lists1.append(adds)", "+tlists = []", "+for some in lists1:", "+ some = some + \"#\"", "+ cnt = 0", "+ add = []", "+ for i in range(h + 1):", "+ if some[i] == \"#\":", "+ if cnt == 0:", "+ add.append(0)", "+ cnt = 0", "+ else:", "+ add.extend([cnt] * cnt)", "+ add.append(0)", "+ cnt = 0", "+ elif some[i] != \"#\":", "+ cnt += 1", "+ del add[-1]", "+ tlists.append(add)", "+maximum = 0", "- if j == 0:", "- if lists[i][j] == \"#\":", "- left[i][j] = 0", "- else:", "- left[i][j] = 1", "+ if ylists[i][j] == 0 or tlists[j][i] == 0:", "+ continue", "- if lists[i][j] == \"#\":", "- left[i][j] = 0", "- else:", "- left[i][j] = left[i][j - 1] + 1", "-# upの累積和", "-for i in range(w):", "- for j in range(h):", "- if j == 0:", "- if lists[j][i] == \"#\":", "- up[j][i] = 0", "- else:", "- up[j][i] = 1", "- else:", "- if lists[j][i] == \"#\":", "- up[j][i] = 0", "- else:", "- up[j][i] = up[j - 1][i] + 1", "-# downの累積和", "-for i in range(w):", "- for j in range(h - 1, -1, -1):", "- if j == h - 1:", "- if lists[j][i] == \"#\":", "- down[j][i] = 0", "- else:", "- down[j][i] = 1", "- else:", "- if lists[j][i] == \"#\":", "- down[j][i] = 0", "- else:", "- down[j][i] = down[j + 1][i] + 1", "-maxi = 0", "-for i in range(h):", "- for j in range(w):", "- maxi = max(maxi, right[i][j] + left[i][j] + up[i][j] + down[i][j] - 3)", "-print(maxi)", "+ maximum = max(maximum, ylists[i][j] + tlists[j][i] - 1)", "+print(maximum)" ]
false
0.081472
0.060959
1.336495
[ "s482470636", "s766251560" ]
u787562674
p04012
python
s373427438
s152820447
20
17
3,316
2,940
Accepted
Accepted
15
from collections import Counter w = Counter(list(eval(input()))) for value in list(w.values()): if value % 2 != 0: print('No') break else: print('Yes')
w = eval(input()) for s in set(w): if w.count(s) % 2 != 0: print('No') break else: print('Yes')
10
7
174
119
from collections import Counter w = Counter(list(eval(input()))) for value in list(w.values()): if value % 2 != 0: print("No") break else: print("Yes")
w = eval(input()) for s in set(w): if w.count(s) % 2 != 0: print("No") break else: print("Yes")
false
30
[ "-from collections import Counter", "-", "-w = Counter(list(eval(input())))", "-for value in list(w.values()):", "- if value % 2 != 0:", "+w = eval(input())", "+for s in set(w):", "+ if w.count(s) % 2 != 0:" ]
false
0.072336
0.008486
8.524283
[ "s373427438", "s152820447" ]
u930705402
p03703
python
s472188725
s173620385
1,026
447
125,976
120,080
Accepted
Accepted
56.43
from bisect import bisect_left class SEGTree: def __init__(self,n): self.Unit=0 i=1 while(i<n): i*=2 self.SEG=[self.Unit]*(2*i-1) self.d=i def update(self,i,x): i+=self.d-1 self.SEG[i]+=x while i>0: i=(i-1)//2 self.SEG[i]=self.SEG[i*2+1]+self.SEG[i*2+2] def find(self,a,b,k,l,r): if r<=a or b<=l: return self.Unit if a<=l and r<=b: return self.SEG[k] else: c1=self.find(a,b,2*k+1,l,(l+r)//2) c2=self.find(a,b,2*k+2,(l+r)//2,r) return c1+c2 def get(self,a,b): return self.find(a,b,0,0,self.d) N,K=list(map(int,input().split())) a=[int(eval(input())) for i in range(N)] cum=[0]*(N+1) for i in range(N): cum[i+1]=cum[i]+a[i] B=[cum[i]-i*K for i in range(N+1)] dic={} li=sorted(B) for i in range(N+1): dic[B[i]]=bisect_left(li,B[i]) seg=SEGTree(N+1) ans=0 for i in range(N+1): ans+=seg.get(0,dic[B[i]]+1) seg.update(dic[B[i]],1) print(ans)
from bisect import bisect_left class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=self.bit[x] x=(x&(x+1))-1 return ret def cum(self,l,r): return self.get(r)-self.get(l) N,K=list(map(int,input().split())) a=[int(eval(input())) for i in range(N)] cum=[0]*(N+1) for i in range(N): cum[i+1]=cum[i]+a[i] B=[cum[i]-i*K for i in range(N+1)] dic={} li=sorted(B) for i in range(N+1): dic[B[i]]=bisect_left(li,B[i]) bit=BIT(N+1) ans=0 for i in range(N+1): ans+=bit.get(dic[B[i]]+1) bit.add(dic[B[i]],1) print(ans)
43
36
1,091
788
from bisect import bisect_left class SEGTree: def __init__(self, n): self.Unit = 0 i = 1 while i < n: i *= 2 self.SEG = [self.Unit] * (2 * i - 1) self.d = i def update(self, i, x): i += self.d - 1 self.SEG[i] += x while i > 0: i = (i - 1) // 2 self.SEG[i] = self.SEG[i * 2 + 1] + self.SEG[i * 2 + 2] def find(self, a, b, k, l, r): if r <= a or b <= l: return self.Unit if a <= l and r <= b: return self.SEG[k] else: c1 = self.find(a, b, 2 * k + 1, l, (l + r) // 2) c2 = self.find(a, b, 2 * k + 2, (l + r) // 2, r) return c1 + c2 def get(self, a, b): return self.find(a, b, 0, 0, self.d) N, K = list(map(int, input().split())) a = [int(eval(input())) for i in range(N)] cum = [0] * (N + 1) for i in range(N): cum[i + 1] = cum[i] + a[i] B = [cum[i] - i * K for i in range(N + 1)] dic = {} li = sorted(B) for i in range(N + 1): dic[B[i]] = bisect_left(li, B[i]) seg = SEGTree(N + 1) ans = 0 for i in range(N + 1): ans += seg.get(0, dic[B[i]] + 1) seg.update(dic[B[i]], 1) print(ans)
from bisect import bisect_left class BIT: def __init__(self, N): self.N = N self.bit = [0] * N def add(self, a, w): x = a while x < self.N: self.bit[x] += w x |= x + 1 def get(self, a): ret, x = 0, a - 1 while x >= 0: ret += self.bit[x] x = (x & (x + 1)) - 1 return ret def cum(self, l, r): return self.get(r) - self.get(l) N, K = list(map(int, input().split())) a = [int(eval(input())) for i in range(N)] cum = [0] * (N + 1) for i in range(N): cum[i + 1] = cum[i] + a[i] B = [cum[i] - i * K for i in range(N + 1)] dic = {} li = sorted(B) for i in range(N + 1): dic[B[i]] = bisect_left(li, B[i]) bit = BIT(N + 1) ans = 0 for i in range(N + 1): ans += bit.get(dic[B[i]] + 1) bit.add(dic[B[i]], 1) print(ans)
false
16.27907
[ "-class SEGTree:", "- def __init__(self, n):", "- self.Unit = 0", "- i = 1", "- while i < n:", "- i *= 2", "- self.SEG = [self.Unit] * (2 * i - 1)", "- self.d = i", "+class BIT:", "+ def __init__(self, N):", "+ self.N = N", "+ self.bit = [0] * N", "- def update(self, i, x):", "- i += self.d - 1", "- self.SEG[i] += x", "- while i > 0:", "- i = (i - 1) // 2", "- self.SEG[i] = self.SEG[i * 2 + 1] + self.SEG[i * 2 + 2]", "+ def add(self, a, w):", "+ x = a", "+ while x < self.N:", "+ self.bit[x] += w", "+ x |= x + 1", "- def find(self, a, b, k, l, r):", "- if r <= a or b <= l:", "- return self.Unit", "- if a <= l and r <= b:", "- return self.SEG[k]", "- else:", "- c1 = self.find(a, b, 2 * k + 1, l, (l + r) // 2)", "- c2 = self.find(a, b, 2 * k + 2, (l + r) // 2, r)", "- return c1 + c2", "+ def get(self, a):", "+ ret, x = 0, a - 1", "+ while x >= 0:", "+ ret += self.bit[x]", "+ x = (x & (x + 1)) - 1", "+ return ret", "- def get(self, a, b):", "- return self.find(a, b, 0, 0, self.d)", "+ def cum(self, l, r):", "+ return self.get(r) - self.get(l)", "-seg = SEGTree(N + 1)", "+bit = BIT(N + 1)", "- ans += seg.get(0, dic[B[i]] + 1)", "- seg.update(dic[B[i]], 1)", "+ ans += bit.get(dic[B[i]] + 1)", "+ bit.add(dic[B[i]], 1)" ]
false
0.09843
0.074652
1.318515
[ "s472188725", "s173620385" ]
u014333473
p03001
python
s391556277
s266779265
31
27
9,016
9,096
Accepted
Accepted
12.9
w,h,x,y=list(map(int,input().split()));print(((w*h)/2,int(2*x==w and 2*y==h)))
w,h,x,y=list(map(int,input().split()));print((w*h/2,int(2*x==w and 2*y==h)))
1
1
70
68
w, h, x, y = list(map(int, input().split())) print(((w * h) / 2, int(2 * x == w and 2 * y == h)))
w, h, x, y = list(map(int, input().split())) print((w * h / 2, int(2 * x == w and 2 * y == h)))
false
0
[ "-print(((w * h) / 2, int(2 * x == w and 2 * y == h)))", "+print((w * h / 2, int(2 * x == w and 2 * y == h)))" ]
false
0.045717
0.045809
0.998001
[ "s391556277", "s266779265" ]
u644516473
p02640
python
s165714855
s185591187
25
21
9,164
9,092
Accepted
Accepted
16
x, y = list(map(int, input().split())) for i in range(0, 101): for j in range(0, 101): if i + j == x and i*2 + j * 4 == y: print('Yes') exit() print('No') # print('Yes' if y%2 == 0 and x >= y//2 and y // 4 - (y%4) //2 <= x else 'No')
x, y = list(map(int, input().split())) print(('Yes' if y%2 == 0 and x <= y/2 and y / 4 <= x else 'No'))
8
2
272
98
x, y = list(map(int, input().split())) for i in range(0, 101): for j in range(0, 101): if i + j == x and i * 2 + j * 4 == y: print("Yes") exit() print("No") # print('Yes' if y%2 == 0 and x >= y//2 and y // 4 - (y%4) //2 <= x else 'No')
x, y = list(map(int, input().split())) print(("Yes" if y % 2 == 0 and x <= y / 2 and y / 4 <= x else "No"))
false
75
[ "-for i in range(0, 101):", "- for j in range(0, 101):", "- if i + j == x and i * 2 + j * 4 == y:", "- print(\"Yes\")", "- exit()", "-print(\"No\")", "-# print('Yes' if y%2 == 0 and x >= y//2 and y // 4 - (y%4) //2 <= x else 'No')", "+print((\"Yes\" if y % 2 == 0 and x <= y / 2 and y / 4 <= x else \"No\"))" ]
false
0.033073
0.036302
0.911067
[ "s165714855", "s185591187" ]
u989345508
p03325
python
s349362257
s758652665
130
98
4,148
4,148
Accepted
Accepted
24.62
#全ての要素を奇数にできれば良い #2で何回割れるか n=int(eval(input())) a=[int(i) for i in input().split()] k=0 while True: f=0 for i in range(n): if a[i]%2==0: k+=1 f=1 a[i]=a[i]//2 if f==0: break print(k)
n=int(eval(input())) a=list(map(int,input().split())) ans=0 for i in range(n): while a[i]%2==0: ans+=1 a[i]//=2 print(ans)
18
8
261
143
# 全ての要素を奇数にできれば良い # 2で何回割れるか n = int(eval(input())) a = [int(i) for i in input().split()] k = 0 while True: f = 0 for i in range(n): if a[i] % 2 == 0: k += 1 f = 1 a[i] = a[i] // 2 if f == 0: break print(k)
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(n): while a[i] % 2 == 0: ans += 1 a[i] //= 2 print(ans)
false
55.555556
[ "-# 全ての要素を奇数にできれば良い", "-# 2で何回割れるか", "-a = [int(i) for i in input().split()]", "-k = 0", "-while True:", "- f = 0", "- for i in range(n):", "- if a[i] % 2 == 0:", "- k += 1", "- f = 1", "- a[i] = a[i] // 2", "- if f == 0:", "- break", "-print(k)", "+a = list(map(int, input().split()))", "+ans = 0", "+for i in range(n):", "+ while a[i] % 2 == 0:", "+ ans += 1", "+ a[i] //= 2", "+print(ans)" ]
false
0.10703
0.044001
2.432431
[ "s349362257", "s758652665" ]
u330799501
p03835
python
s858946078
s038763572
1,597
1,201
9,160
9,164
Accepted
Accepted
24.8
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] 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 (z>=0 and z <= k and x+y+z == s): #print(x,y,z) ans += 1 print(ans)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] 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 (z>=0 and z <= k): #print(x,y,z) ans += 1 print(ans)
19
19
426
411
# k = int(input()) # s = input() # a, b = map(int, input().split()) # s, t = map(str, input().split()) # l = list(map(int, input().split())) # l = [list(map(int,input().split())) for i in range(n)] 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 z >= 0 and z <= k and x + y + z == s: # print(x,y,z) ans += 1 print(ans)
# k = int(input()) # s = input() # a, b = map(int, input().split()) # s, t = map(str, input().split()) # l = list(map(int, input().split())) # l = [list(map(int,input().split())) for i in range(n)] 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 z >= 0 and z <= k: # print(x,y,z) ans += 1 print(ans)
false
0
[ "- if z >= 0 and z <= k and x + y + z == s:", "+ if z >= 0 and z <= k:" ]
false
0.03654
0.041985
0.870318
[ "s858946078", "s038763572" ]
u439396449
p03472
python
s728005303
s753470932
521
200
44,508
12,712
Accepted
Accepted
61.61
import math N, H = list(map(int, input().split())) katana = {i: list(map(int, input().split())) for i in range(N)} # 振り攻撃最大 max_i, (max_a, max_b) = max(list(katana.items()), key=lambda x: x[1][0]) ans = 0 for i, (_, b) in sorted(list(katana.items()), key=lambda x: x[1][1], reverse=True): if i == max_i: continue if H <= max_b or H <= max_a: break if b < max_a: break H -= b ans += 1 if max_a < max_b and H > 0: H -= max_b ans += 1 if H > 0: ans += math.ceil(H / max_a) print(ans)
import sys input = sys.stdin.readline N, H = list(map(int, input().split())) a, b = [0] * N, [0] * N for i in range(N): a[i], b[i] = list(map(int, input().split())) max_a = max(a) b = [x for x in sorted(b, reverse=True) if x > max_a] cnt = 0 for bi in b: H -= bi cnt += 1 if H <= 0: break if H > 0: cnt += H // max_a if H % max_a != 0: cnt += 1 print(cnt)
26
24
549
412
import math N, H = list(map(int, input().split())) katana = {i: list(map(int, input().split())) for i in range(N)} # 振り攻撃最大 max_i, (max_a, max_b) = max(list(katana.items()), key=lambda x: x[1][0]) ans = 0 for i, (_, b) in sorted(list(katana.items()), key=lambda x: x[1][1], reverse=True): if i == max_i: continue if H <= max_b or H <= max_a: break if b < max_a: break H -= b ans += 1 if max_a < max_b and H > 0: H -= max_b ans += 1 if H > 0: ans += math.ceil(H / max_a) print(ans)
import sys input = sys.stdin.readline N, H = list(map(int, input().split())) a, b = [0] * N, [0] * N for i in range(N): a[i], b[i] = list(map(int, input().split())) max_a = max(a) b = [x for x in sorted(b, reverse=True) if x > max_a] cnt = 0 for bi in b: H -= bi cnt += 1 if H <= 0: break if H > 0: cnt += H // max_a if H % max_a != 0: cnt += 1 print(cnt)
false
7.692308
[ "-import math", "+import sys", "+input = sys.stdin.readline", "-katana = {i: list(map(int, input().split())) for i in range(N)}", "-# 振り攻撃最大", "-max_i, (max_a, max_b) = max(list(katana.items()), key=lambda x: x[1][0])", "-ans = 0", "-for i, (_, b) in sorted(list(katana.items()), key=lambda x: x[1][1], reverse=True):", "- if i == max_i:", "- continue", "- if H <= max_b or H <= max_a:", "+a, b = [0] * N, [0] * N", "+for i in range(N):", "+ a[i], b[i] = list(map(int, input().split()))", "+max_a = max(a)", "+b = [x for x in sorted(b, reverse=True) if x > max_a]", "+cnt = 0", "+for bi in b:", "+ H -= bi", "+ cnt += 1", "+ if H <= 0:", "- if b < max_a:", "- break", "- H -= b", "- ans += 1", "-if max_a < max_b and H > 0:", "- H -= max_b", "- ans += 1", "- ans += math.ceil(H / max_a)", "-print(ans)", "+ cnt += H // max_a", "+ if H % max_a != 0:", "+ cnt += 1", "+print(cnt)" ]
false
0.036897
0.109621
0.336591
[ "s728005303", "s753470932" ]
u670180528
p03053
python
s089787870
s324065379
672
359
161,756
40,000
Accepted
Accepted
46.58
from collections import deque h,w = list(map(int,input().split())) grid = [list(eval(input())) for _ in range(h)] nxt = deque() for i in range(h): for j in range(w): if grid[i][j] == "#": nxt.append((i,j,0)) a=0 while nxt: i,j,t = nxt.popleft() if t > a: a+=1 for i,j in ((i-1,j),(i+1,j),(i,j-1),(i,j+1)): if (-1<i<h)&(-1<j<w) and grid[i][j] == ".": grid[i][j] = "#" nxt.append((i,j,t+1)) print(a)
from scipy.ndimage import distance_transform_cdt h,w = list(map(int, input().split())) grid = [[i=="." for i in eval(input())] for _ in range(h)] print((distance_transform_cdt(grid, metric='taxicab').max())) # reference : https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.distance_transform_bf.html
18
6
426
325
from collections import deque h, w = list(map(int, input().split())) grid = [list(eval(input())) for _ in range(h)] nxt = deque() for i in range(h): for j in range(w): if grid[i][j] == "#": nxt.append((i, j, 0)) a = 0 while nxt: i, j, t = nxt.popleft() if t > a: a += 1 for i, j in ((i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)): if (-1 < i < h) & (-1 < j < w) and grid[i][j] == ".": grid[i][j] = "#" nxt.append((i, j, t + 1)) print(a)
from scipy.ndimage import distance_transform_cdt h, w = list(map(int, input().split())) grid = [[i == "." for i in eval(input())] for _ in range(h)] print((distance_transform_cdt(grid, metric="taxicab").max())) # reference : https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.distance_transform_bf.html
false
66.666667
[ "-from collections import deque", "+from scipy.ndimage import distance_transform_cdt", "-grid = [list(eval(input())) for _ in range(h)]", "-nxt = deque()", "-for i in range(h):", "- for j in range(w):", "- if grid[i][j] == \"#\":", "- nxt.append((i, j, 0))", "-a = 0", "-while nxt:", "- i, j, t = nxt.popleft()", "- if t > a:", "- a += 1", "- for i, j in ((i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)):", "- if (-1 < i < h) & (-1 < j < w) and grid[i][j] == \".\":", "- grid[i][j] = \"#\"", "- nxt.append((i, j, t + 1))", "-print(a)", "+grid = [[i == \".\" for i in eval(input())] for _ in range(h)]", "+print((distance_transform_cdt(grid, metric=\"taxicab\").max()))", "+# reference : https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.distance_transform_bf.html" ]
false
0.031126
0.367411
0.084718
[ "s089787870", "s324065379" ]
u133936772
p03240
python
s482517875
s613207426
38
31
3,064
3,064
Accepted
Accepted
18.42
n = int(eval(input())) ll = sorted([list(map(int,input().split())) for _ in range(n)],key=lambda k:k[2])[::-1] for cx in range(101): for cy in range(101): ch = ll[0][2]+abs(ll[0][0]-cx)+abs(ll[0][1]-cy) for x,y,h in ll: if max(ch-abs(x-cx)-abs(y-cy),0) != h: break else: print((cx,cy,ch)) break else: continue break
ll = [list(map(int,input().split())) for _ in range(int(eval(input())))] ll.sort(key=lambda k:k[2],reverse=1) x,y,h = ll[0] for cx in range(101): for cy in range(101): ch = h+abs(x-cx)+abs(y-cy) for x,y,h in ll: if max(ch-abs(x-cx)-abs(y-cy),0) != h: break else: print((cx,cy,ch)) break else: continue break
14
15
368
361
n = int(eval(input())) ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda k: k[2])[ ::-1 ] for cx in range(101): for cy in range(101): ch = ll[0][2] + abs(ll[0][0] - cx) + abs(ll[0][1] - cy) for x, y, h in ll: if max(ch - abs(x - cx) - abs(y - cy), 0) != h: break else: print((cx, cy, ch)) break else: continue break
ll = [list(map(int, input().split())) for _ in range(int(eval(input())))] ll.sort(key=lambda k: k[2], reverse=1) x, y, h = ll[0] for cx in range(101): for cy in range(101): ch = h + abs(x - cx) + abs(y - cy) for x, y, h in ll: if max(ch - abs(x - cx) - abs(y - cy), 0) != h: break else: print((cx, cy, ch)) break else: continue break
false
6.666667
[ "-n = int(eval(input()))", "-ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda k: k[2])[", "- ::-1", "-]", "+ll = [list(map(int, input().split())) for _ in range(int(eval(input())))]", "+ll.sort(key=lambda k: k[2], reverse=1)", "+x, y, h = ll[0]", "- ch = ll[0][2] + abs(ll[0][0] - cx) + abs(ll[0][1] - cy)", "+ ch = h + abs(x - cx) + abs(y - cy)" ]
false
0.047864
0.045207
1.058783
[ "s482517875", "s613207426" ]
u869919400
p02713
python
s444232680
s491183945
934
503
79,644
67,680
Accepted
Accepted
46.15
K = int(eval(input())) from itertools import product kumi = product(list(range(1, K+1)), repeat=3) from math import gcd memo = [[None for i in range(K+1)] for i in range(K+1)] # memo2 = {} ans = 0 for a, b, c in kumi: a, b, c = sorted([a, b, c]) if memo[a][b] is not None: v = memo[a][b] else: v = gcd(a, b) memo[a][b] = v memo[b][a] = v d = gcd(v, c) ans += d print(ans)
K = int(eval(input())) from math import gcd ans = 0 for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): ans += gcd(gcd(i, j), k) print(ans)
23
8
443
185
K = int(eval(input())) from itertools import product kumi = product(list(range(1, K + 1)), repeat=3) from math import gcd memo = [[None for i in range(K + 1)] for i in range(K + 1)] # memo2 = {} ans = 0 for a, b, c in kumi: a, b, c = sorted([a, b, c]) if memo[a][b] is not None: v = memo[a][b] else: v = gcd(a, b) memo[a][b] = v memo[b][a] = v d = gcd(v, c) ans += d print(ans)
K = int(eval(input())) from math import gcd ans = 0 for i in range(1, K + 1): for j in range(1, K + 1): for k in range(1, K + 1): ans += gcd(gcd(i, j), k) print(ans)
false
65.217391
[ "-from itertools import product", "-", "-kumi = product(list(range(1, K + 1)), repeat=3)", "-memo = [[None for i in range(K + 1)] for i in range(K + 1)]", "-# memo2 = {}", "-for a, b, c in kumi:", "- a, b, c = sorted([a, b, c])", "- if memo[a][b] is not None:", "- v = memo[a][b]", "- else:", "- v = gcd(a, b)", "- memo[a][b] = v", "- memo[b][a] = v", "- d = gcd(v, c)", "- ans += d", "+for i in range(1, K + 1):", "+ for j in range(1, K + 1):", "+ for k in range(1, K + 1):", "+ ans += gcd(gcd(i, j), k)" ]
false
0.087164
0.181644
0.479863
[ "s444232680", "s491183945" ]
u444732068
p02786
python
s798015471
s729290222
20
17
3,316
2,940
Accepted
Accepted
15
H = int(eval(input())) h = 0 while H != 1: H = int(H/2) h += 1 print((2**(h+1)-1))
H = int(eval(input())) def f(x): if x == 1: return 1 else: return 2*f(int(x/2)) + 1 print((f(H)))
7
10
83
108
H = int(eval(input())) h = 0 while H != 1: H = int(H / 2) h += 1 print((2 ** (h + 1) - 1))
H = int(eval(input())) def f(x): if x == 1: return 1 else: return 2 * f(int(x / 2)) + 1 print((f(H)))
false
30
[ "-h = 0", "-while H != 1:", "- H = int(H / 2)", "- h += 1", "-print((2 ** (h + 1) - 1))", "+", "+", "+def f(x):", "+ if x == 1:", "+ return 1", "+ else:", "+ return 2 * f(int(x / 2)) + 1", "+", "+", "+print((f(H)))" ]
false
0.04249
0.038253
1.110757
[ "s798015471", "s729290222" ]
u905582793
p04020
python
s688089182
s848957681
193
81
7,072
7,072
Accepted
Accepted
58.03
n=int(eval(input())) a = [int(eval(input())) for i in range(n)] a.append(0) ans = 0 tmp = 0 for i in range(n+1): if a[i]!=0: tmp += a[i] else: ans += tmp//2 tmp = 0 print(ans)
import sys input = sys.stdin.readline n=int(eval(input())) a = [int(eval(input())) for i in range(n)] a.append(0) ans = 0 tmp = 0 for i in range(n+1): if a[i]!=0: tmp += a[i] else: ans += tmp//2 tmp = 0 print(ans)
12
14
190
230
n = int(eval(input())) a = [int(eval(input())) for i in range(n)] a.append(0) ans = 0 tmp = 0 for i in range(n + 1): if a[i] != 0: tmp += a[i] else: ans += tmp // 2 tmp = 0 print(ans)
import sys input = sys.stdin.readline n = int(eval(input())) a = [int(eval(input())) for i in range(n)] a.append(0) ans = 0 tmp = 0 for i in range(n + 1): if a[i] != 0: tmp += a[i] else: ans += tmp // 2 tmp = 0 print(ans)
false
14.285714
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.048154
0.048062
1.001919
[ "s688089182", "s848957681" ]
u718706790
p02812
python
s956827235
s361654940
20
17
3,188
2,940
Accepted
Accepted
15
import re n = int(eval(input())) s = eval(input()) x = re.sub(r'ABC', 'o', s) print((x.count('o')))
n = int(eval(input())) s = eval(input()) print((s.count('ABC')))
8
4
95
54
import re n = int(eval(input())) s = eval(input()) x = re.sub(r"ABC", "o", s) print((x.count("o")))
n = int(eval(input())) s = eval(input()) print((s.count("ABC")))
false
50
[ "-import re", "-", "-x = re.sub(r\"ABC\", \"o\", s)", "-print((x.count(\"o\")))", "+print((s.count(\"ABC\")))" ]
false
0.04237
0.042121
1.005905
[ "s956827235", "s361654940" ]
u562016607
p03287
python
s727885573
s255992427
139
119
16,184
15,444
Accepted
Accepted
14.39
N,M=list(map(int,input().split())) A=[int(i) for i in input().split()] S=[0 for i in range(N+1)] for i in range(N): S[i+1]=(S[i]+A[i])%M D=dict() ans=0 for i in range(N+1): if S[i] in D: D[S[i]]+=1 else: D[S[i]]=1 ans+=D[S[i]]-1 print(ans)
N,M=list(map(int,input().split())) A=list(map(int,input().split())) D={0:1} S=[0 for i in range(N)] S[0]=A[0]%M if S[0] in D: D[S[0]]+=1 else: D[S[0]]=1 for i in range(1,N): S[i]=(S[i-1]+A[i])%M if S[i] in D: D[S[i]]+=1 else: D[S[i]]=1 ans=0 for i in D: ans+=(D[i]*(D[i]-1))//2 print(ans)
14
19
263
341
N, M = list(map(int, input().split())) A = [int(i) for i in input().split()] S = [0 for i in range(N + 1)] for i in range(N): S[i + 1] = (S[i] + A[i]) % M D = dict() ans = 0 for i in range(N + 1): if S[i] in D: D[S[i]] += 1 else: D[S[i]] = 1 ans += D[S[i]] - 1 print(ans)
N, M = list(map(int, input().split())) A = list(map(int, input().split())) D = {0: 1} S = [0 for i in range(N)] S[0] = A[0] % M if S[0] in D: D[S[0]] += 1 else: D[S[0]] = 1 for i in range(1, N): S[i] = (S[i - 1] + A[i]) % M if S[i] in D: D[S[i]] += 1 else: D[S[i]] = 1 ans = 0 for i in D: ans += (D[i] * (D[i] - 1)) // 2 print(ans)
false
26.315789
[ "-A = [int(i) for i in input().split()]", "-S = [0 for i in range(N + 1)]", "-for i in range(N):", "- S[i + 1] = (S[i] + A[i]) % M", "-D = dict()", "-ans = 0", "-for i in range(N + 1):", "+A = list(map(int, input().split()))", "+D = {0: 1}", "+S = [0 for i in range(N)]", "+S[0] = A[0] % M", "+if S[0] in D:", "+ D[S[0]] += 1", "+else:", "+ D[S[0]] = 1", "+for i in range(1, N):", "+ S[i] = (S[i - 1] + A[i]) % M", "- ans += D[S[i]] - 1", "+ans = 0", "+for i in D:", "+ ans += (D[i] * (D[i] - 1)) // 2" ]
false
0.040635
0.106943
0.379966
[ "s727885573", "s255992427" ]
u506858457
p02837
python
s265478370
s049083891
994
895
9,228
9,140
Accepted
Accepted
9.96
g = [[-1 for _ in range(15)] for _ in range(15)]#証言格納用 n = int(eval(input()))#証言なし-1で初期化 ans=0 for i in range(n):#n人の人について、一人一人、入力 m = int(eval(input()))#証言の個数をもらう for j in range(m):#m個の証言を入力 x,y = list(map(int, input().split())) g[i][x-1] = y#i番目の人の証言を格納、人の番号xは0始まり for i in range(1<<n):#Bit全探索開始 honests = [0 for _ in range(n)]#正直者フラグ、後で1で人数計算 for j in range(n):#n人を一人ずつ、チェックする if (i>>j) &1:#Bitが立っているかを1で表す honests[j] = 1#Bitが立っていれば、j番目は正直と仮定 ok = True#矛盾が無い仮定で、証言を検証する for j in range(n):#n人を一人ずつ、チェック(j番目の人を見る) if honests[j]:#j番目が、もし正直なら証言を検証(不正直の証言は無視) for k in range(n):#j番目の人の、k番目の人に対する証言を検証 if g[j][k] == -1: continue#証言していなければ、飛ばす if g[j][k] != honests[k]: ok = False#証言とフラグ仮定が不一致 if ok:#矛盾がないケースについて調べる ans = max(ans, honests.count(1))#正直であるフラグ1が立っている数 print(ans) ''' ・正直者の人の組を全ての組合せで仮定する。 ・正直者と仮定した人の証言が仮定に矛盾するとき、 その正直者の選び方の組はあり得ない。 ・正直者と仮定した人の証言同士の矛盾は調べる必要はない。 ある人に対して矛盾する二つの証言があるとき、 どちらか一方の証言は必ず仮定に矛盾する。したがって、 この仮定があり得ないことを調べるには仮定と証言の矛盾を調べるだけでよい。 ・全ての証言が矛盾しない正直者の選び方の組のうち、 正直者が最も多い組の正直者の人数を求めれば良い。 人xの人yに対する証言のデータを二次元配列gへ次のような対応関係で 格納しておく。なお、ここでは人の番号は配列のオフセットに合わせるため 0から始めるものとする。 ・人xが人yに対して正直者であると証言するとき、 二次元配列g[x][y]を1にする。 ・人xが人yに対して不親切な人であると証言するとき 二次元配列g[x][y]を0とする。 ・人xが人yに対して言及していないとき、 二次元配列g[x][y]を-1にする。 ・入力よりNの最大が15なので、 15行15列の二次元配列gをデフォルト値-1用意しておく ・全員の人数を表す値を受け取る。 ・用意した配列に人iが人jに対して述べる証言のデータを格納していく。 ・人iの証言の数mを受け取る。 ・人iの証言を受け取るためm回次のループを回す。 ・証言を表す二つの値を受け取り二次元配列gに格納する。 人iが「人xはyである」と証言しているときg[i][x]=yである。 (入力で受け取る「人の番号」は1から始まるため、 コードでは受け取った値から1引いている。) g = [[-1 for _ in range(15)] for _ in range(15)] n = int(input()) for i in range(n): m = int(input()) for j in range(m): x,y = map(int, input().split()) g[i][x-1] = y 二次元配列gの作成と入力の受け取りは以上である。 次に問題を解く中心となるコードを実装していく。 まず、全ての正直者の組を表現するために二進数表記を用いることを考える。 二進数の右端の桁を0桁目とする。またkを0から14までの整数とする。 ・「k桁目が1である」を「人kは正直者である」 ・「k桁目が0である」を「人kは不親切な人である」 作り出した正直者の組それぞれに対して何らかの処理を行うため、 これは全bit探索である。 「正直者の組を作りだす」部分のコード。 ・カウンタ変数iを1から2^15まで変化させ、次の処理を繰り返す。 ・正直者の番号を格納する要素数nの配列honestsをデフォルト値0で作る。 ・iを二進数で表現したときj桁目が1であればhonests[j]に1を追加する。 for i in range(1<<n): honests = [0 for _ in range(n)] for j in range(n): if (i>>j) &1: honests[j] = 1 honests[j]が1であることは,人jは正直者であると仮定することに対応する。 次はhonestsの仮定と証言gに矛盾がないか調べ、求める値「N人のうち 正直者であり得る最大人数」を出力するまでの実装をおこなう。 仮定と証言に矛盾があればそのhonestsで表現された組はあり得ない。 ・求める値「N人のうち正直者であり得る最大人数」を格納するための 変数ansをデフォルト値0で用意しておく。 求める値は0以上の値であり以下のループ処理によって、 より大きな値で更新され得る。最終的に最大値が格納される。 ・ある正直者の組に矛盾がなかったことを表す変数okをデフォルト値 Trueで用意しておく ・外側のループで配列honestsを作る。作ったhonestsの要素を順に調べる。 honests[j]が1ならば証言g[j]は正しいのでg [j]を以下のように調べる。 ・g[j][k]が-1ならば何もしなくてよいので次の証言を調べるループへ移る。 ・g[i][k]がhonests[k]の値と異なるならばこの正直者の組はあり得ないので 変数okをFalseにする。 ・okがTureのときhonestsの要素の値が1であるものの数(つまり正直者の数)を 数えてansより大きいならばその値をansに代入する。 ・最終的なansの値を出力する。 '''
def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N=II() ans=0 List=[[-1 for _ in range(N)] for _ in range(N)] for j in range(N): A=II() for i in range(A): x,y=MI() x-=1 List[j][x]=y for i in range(1<<N): honests=[0]*N for j in range(N): if 1&(i>>j): honests[j]=1 ok=True for j in range(N): if honests[j]: for k in range(N): if List[j][k]==-1: continue if List[j][k]!=honests[k]: ok=False if ok: ans=max(ans,honests.count(1)) print(ans)
97
29
2,851
623
g = [[-1 for _ in range(15)] for _ in range(15)] # 証言格納用 n = int(eval(input())) # 証言なし-1で初期化 ans = 0 for i in range(n): # n人の人について、一人一人、入力 m = int(eval(input())) # 証言の個数をもらう for j in range(m): # m個の証言を入力 x, y = list(map(int, input().split())) g[i][x - 1] = y # i番目の人の証言を格納、人の番号xは0始まり for i in range(1 << n): # Bit全探索開始 honests = [0 for _ in range(n)] # 正直者フラグ、後で1で人数計算 for j in range(n): # n人を一人ずつ、チェックする if (i >> j) & 1: # Bitが立っているかを1で表す honests[j] = 1 # Bitが立っていれば、j番目は正直と仮定 ok = True # 矛盾が無い仮定で、証言を検証する for j in range(n): # n人を一人ずつ、チェック(j番目の人を見る) if honests[j]: # j番目が、もし正直なら証言を検証(不正直の証言は無視) for k in range(n): # j番目の人の、k番目の人に対する証言を検証 if g[j][k] == -1: continue # 証言していなければ、飛ばす if g[j][k] != honests[k]: ok = False # 証言とフラグ仮定が不一致 if ok: # 矛盾がないケースについて調べる ans = max(ans, honests.count(1)) # 正直であるフラグ1が立っている数 print(ans) """ ・正直者の人の組を全ての組合せで仮定する。 ・正直者と仮定した人の証言が仮定に矛盾するとき、 その正直者の選び方の組はあり得ない。 ・正直者と仮定した人の証言同士の矛盾は調べる必要はない。 ある人に対して矛盾する二つの証言があるとき、 どちらか一方の証言は必ず仮定に矛盾する。したがって、 この仮定があり得ないことを調べるには仮定と証言の矛盾を調べるだけでよい。 ・全ての証言が矛盾しない正直者の選び方の組のうち、 正直者が最も多い組の正直者の人数を求めれば良い。 人xの人yに対する証言のデータを二次元配列gへ次のような対応関係で 格納しておく。なお、ここでは人の番号は配列のオフセットに合わせるため 0から始めるものとする。 ・人xが人yに対して正直者であると証言するとき、 二次元配列g[x][y]を1にする。 ・人xが人yに対して不親切な人であると証言するとき 二次元配列g[x][y]を0とする。 ・人xが人yに対して言及していないとき、 二次元配列g[x][y]を-1にする。 ・入力よりNの最大が15なので、 15行15列の二次元配列gをデフォルト値-1用意しておく ・全員の人数を表す値を受け取る。 ・用意した配列に人iが人jに対して述べる証言のデータを格納していく。 ・人iの証言の数mを受け取る。 ・人iの証言を受け取るためm回次のループを回す。 ・証言を表す二つの値を受け取り二次元配列gに格納する。 人iが「人xはyである」と証言しているときg[i][x]=yである。 (入力で受け取る「人の番号」は1から始まるため、 コードでは受け取った値から1引いている。) g = [[-1 for _ in range(15)] for _ in range(15)] n = int(input()) for i in range(n): m = int(input()) for j in range(m): x,y = map(int, input().split()) g[i][x-1] = y 二次元配列gの作成と入力の受け取りは以上である。 次に問題を解く中心となるコードを実装していく。 まず、全ての正直者の組を表現するために二進数表記を用いることを考える。 二進数の右端の桁を0桁目とする。またkを0から14までの整数とする。 ・「k桁目が1である」を「人kは正直者である」 ・「k桁目が0である」を「人kは不親切な人である」 作り出した正直者の組それぞれに対して何らかの処理を行うため、 これは全bit探索である。 「正直者の組を作りだす」部分のコード。 ・カウンタ変数iを1から2^15まで変化させ、次の処理を繰り返す。 ・正直者の番号を格納する要素数nの配列honestsをデフォルト値0で作る。 ・iを二進数で表現したときj桁目が1であればhonests[j]に1を追加する。 for i in range(1<<n): honests = [0 for _ in range(n)] for j in range(n): if (i>>j) &1: honests[j] = 1 honests[j]が1であることは,人jは正直者であると仮定することに対応する。 次はhonestsの仮定と証言gに矛盾がないか調べ、求める値「N人のうち 正直者であり得る最大人数」を出力するまでの実装をおこなう。 仮定と証言に矛盾があればそのhonestsで表現された組はあり得ない。 ・求める値「N人のうち正直者であり得る最大人数」を格納するための 変数ansをデフォルト値0で用意しておく。 求める値は0以上の値であり以下のループ処理によって、 より大きな値で更新され得る。最終的に最大値が格納される。 ・ある正直者の組に矛盾がなかったことを表す変数okをデフォルト値 Trueで用意しておく ・外側のループで配列honestsを作る。作ったhonestsの要素を順に調べる。 honests[j]が1ならば証言g[j]は正しいのでg [j]を以下のように調べる。 ・g[j][k]が-1ならば何もしなくてよいので次の証言を調べるループへ移る。 ・g[i][k]がhonests[k]の値と異なるならばこの正直者の組はあり得ないので 変数okをFalseにする。 ・okがTureのときhonestsの要素の値が1であるものの数(つまり正直者の数)を 数えてansより大きいならばその値をansに代入する。 ・最終的なansの値を出力する。 """
def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) N = II() ans = 0 List = [[-1 for _ in range(N)] for _ in range(N)] for j in range(N): A = II() for i in range(A): x, y = MI() x -= 1 List[j][x] = y for i in range(1 << N): honests = [0] * N for j in range(N): if 1 & (i >> j): honests[j] = 1 ok = True for j in range(N): if honests[j]: for k in range(N): if List[j][k] == -1: continue if List[j][k] != honests[k]: ok = False if ok: ans = max(ans, honests.count(1)) print(ans)
false
70.103093
[ "-g = [[-1 for _ in range(15)] for _ in range(15)] # 証言格納用", "-n = int(eval(input())) # 証言なし-1で初期化", "+def II():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+N = II()", "-for i in range(n): # n人の人について、一人一人、入力", "- m = int(eval(input())) # 証言の個数をもらう", "- for j in range(m): # m個の証言を入力", "- x, y = list(map(int, input().split()))", "- g[i][x - 1] = y # i番目の人の証言を格納、人の番号xは0始まり", "-for i in range(1 << n): # Bit全探索開始", "- honests = [0 for _ in range(n)] # 正直者フラグ、後で1で人数計算", "- for j in range(n): # n人を一人ずつ、チェックする", "- if (i >> j) & 1: # Bitが立っているかを1で表す", "- honests[j] = 1 # Bitが立っていれば、j番目は正直と仮定", "- ok = True # 矛盾が無い仮定で、証言を検証する", "- for j in range(n): # n人を一人ずつ、チェック(j番目の人を見る)", "- if honests[j]: # j番目が、もし正直なら証言を検証(不正直の証言は無視)", "- for k in range(n): # j番目の人の、k番目の人に対する証言を検証", "- if g[j][k] == -1:", "- continue # 証言していなければ、飛ばす", "- if g[j][k] != honests[k]:", "- ok = False # 証言とフラグ仮定が不一致", "- if ok: # 矛盾がないケースについて調べる", "- ans = max(ans, honests.count(1)) # 正直であるフラグ1が立っている数", "+List = [[-1 for _ in range(N)] for _ in range(N)]", "+for j in range(N):", "+ A = II()", "+ for i in range(A):", "+ x, y = MI()", "+ x -= 1", "+ List[j][x] = y", "+for i in range(1 << N):", "+ honests = [0] * N", "+ for j in range(N):", "+ if 1 & (i >> j):", "+ honests[j] = 1", "+ ok = True", "+ for j in range(N):", "+ if honests[j]:", "+ for k in range(N):", "+ if List[j][k] == -1:", "+ continue", "+ if List[j][k] != honests[k]:", "+ ok = False", "+ if ok:", "+ ans = max(ans, honests.count(1))", "-\"\"\"", "-・正直者の人の組を全ての組合せで仮定する。", "-・正直者と仮定した人の証言が仮定に矛盾するとき、", "-その正直者の選び方の組はあり得ない。", "-・正直者と仮定した人の証言同士の矛盾は調べる必要はない。", "-ある人に対して矛盾する二つの証言があるとき、", "-どちらか一方の証言は必ず仮定に矛盾する。したがって、", "-この仮定があり得ないことを調べるには仮定と証言の矛盾を調べるだけでよい。", "-・全ての証言が矛盾しない正直者の選び方の組のうち、", "-正直者が最も多い組の正直者の人数を求めれば良い。", "-人xの人yに対する証言のデータを二次元配列gへ次のような対応関係で", "-格納しておく。なお、ここでは人の番号は配列のオフセットに合わせるため", "-0から始めるものとする。", "-・人xが人yに対して正直者であると証言するとき、", "-二次元配列g[x][y]を1にする。", "-・人xが人yに対して不親切な人であると証言するとき", "-二次元配列g[x][y]を0とする。", "-・人xが人yに対して言及していないとき、", "-二次元配列g[x][y]を-1にする。", "-・入力よりNの最大が15なので、", "-15行15列の二次元配列gをデフォルト値-1用意しておく", "-・全員の人数を表す値を受け取る。", "-・用意した配列に人iが人jに対して述べる証言のデータを格納していく。", "-・人iの証言の数mを受け取る。", "-・人iの証言を受け取るためm回次のループを回す。", "-・証言を表す二つの値を受け取り二次元配列gに格納する。", "-人iが「人xはyである」と証言しているときg[i][x]=yである。", "-(入力で受け取る「人の番号」は1から始まるため、", "-コードでは受け取った値から1引いている。)", "-g = [[-1 for _ in range(15)] for _ in range(15)]", "-n = int(input())", "-for i in range(n):", "- m = int(input())", "- for j in range(m):", "- x,y = map(int, input().split())", "- g[i][x-1] = y", "-二次元配列gの作成と入力の受け取りは以上である。", "-次に問題を解く中心となるコードを実装していく。", "-まず、全ての正直者の組を表現するために二進数表記を用いることを考える。", "-二進数の右端の桁を0桁目とする。またkを0から14までの整数とする。", "-・「k桁目が1である」を「人kは正直者である」", "-・「k桁目が0である」を「人kは不親切な人である」", "-作り出した正直者の組それぞれに対して何らかの処理を行うため、", "-これは全bit探索である。", "-「正直者の組を作りだす」部分のコード。", "-・カウンタ変数iを1から2^15まで変化させ、次の処理を繰り返す。", "-・正直者の番号を格納する要素数nの配列honestsをデフォルト値0で作る。", "-・iを二進数で表現したときj桁目が1であればhonests[j]に1を追加する。", "-for i in range(1<<n):", "- honests = [0 for _ in range(n)]", "- for j in range(n):", "- if (i>>j) &1:", "- honests[j] = 1", "-honests[j]が1であることは,人jは正直者であると仮定することに対応する。", "-次はhonestsの仮定と証言gに矛盾がないか調べ、求める値「N人のうち", "-正直者であり得る最大人数」を出力するまでの実装をおこなう。", "-仮定と証言に矛盾があればそのhonestsで表現された組はあり得ない。", "-・求める値「N人のうち正直者であり得る最大人数」を格納するための", "-変数ansをデフォルト値0で用意しておく。", "-求める値は0以上の値であり以下のループ処理によって、", "-より大きな値で更新され得る。最終的に最大値が格納される。", "-・ある正直者の組に矛盾がなかったことを表す変数okをデフォルト値", "-Trueで用意しておく", "-・外側のループで配列honestsを作る。作ったhonestsの要素を順に調べる。", "-honests[j]が1ならば証言g[j]は正しいのでg [j]を以下のように調べる。", "-・g[j][k]が-1ならば何もしなくてよいので次の証言を調べるループへ移る。", "-・g[i][k]がhonests[k]の値と異なるならばこの正直者の組はあり得ないので", "-変数okをFalseにする。", "-・okがTureのときhonestsの要素の値が1であるものの数(つまり正直者の数)を", "-数えてansより大きいならばその値をansに代入する。", "-・最終的なansの値を出力する。", "-\"\"\"" ]
false
0.039956
0.039591
1.009218
[ "s265478370", "s049083891" ]
u241159583
p02861
python
s921556421
s110277890
333
292
10,844
9,120
Accepted
Accepted
12.31
import itertools n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] ans = [] for v in itertools.permutations(list(range(n)), n): a = 0 for i in range(len(v)-1): x1,y1 = xy[v[i]][0], xy[v[i]][1] x2,y2 = xy[v[i+1]][0], xy[v[i+1]][1] a += ((x1-x2)**2+(y1-y2)**2)**0.5 ans.append(a) print((sum(ans)/len(ans)))
import itertools from math import sqrt n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] ans = 0 cnt = 0 for v in itertools.permutations(list(range(n))): for i in range(n-1): x = (xy[v[i]][0]-xy[v[i+1]][0]) ** 2 y = (xy[v[i]][1]-xy[v[i+1]][1]) ** 2 ans += sqrt(x+y) cnt += 1 print((ans/cnt))
13
13
375
357
import itertools n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] ans = [] for v in itertools.permutations(list(range(n)), n): a = 0 for i in range(len(v) - 1): x1, y1 = xy[v[i]][0], xy[v[i]][1] x2, y2 = xy[v[i + 1]][0], xy[v[i + 1]][1] a += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 ans.append(a) print((sum(ans) / len(ans)))
import itertools from math import sqrt n = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(n)] ans = 0 cnt = 0 for v in itertools.permutations(list(range(n))): for i in range(n - 1): x = (xy[v[i]][0] - xy[v[i + 1]][0]) ** 2 y = (xy[v[i]][1] - xy[v[i + 1]][1]) ** 2 ans += sqrt(x + y) cnt += 1 print((ans / cnt))
false
0
[ "+from math import sqrt", "-ans = []", "-for v in itertools.permutations(list(range(n)), n):", "- a = 0", "- for i in range(len(v) - 1):", "- x1, y1 = xy[v[i]][0], xy[v[i]][1]", "- x2, y2 = xy[v[i + 1]][0], xy[v[i + 1]][1]", "- a += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5", "- ans.append(a)", "-print((sum(ans) / len(ans)))", "+ans = 0", "+cnt = 0", "+for v in itertools.permutations(list(range(n))):", "+ for i in range(n - 1):", "+ x = (xy[v[i]][0] - xy[v[i + 1]][0]) ** 2", "+ y = (xy[v[i]][1] - xy[v[i + 1]][1]) ** 2", "+ ans += sqrt(x + y)", "+ cnt += 1", "+print((ans / cnt))" ]
false
0.038426
0.007531
5.1025
[ "s921556421", "s110277890" ]
u803617136
p03611
python
s898393448
s296781179
221
181
20,976
21,028
Accepted
Accepted
18.1
from collections import defaultdict n = int(eval(input())) nums = list(map(int, input().split())) frequency = defaultdict(int) for n in nums: for x in [-1, 0, 1]: if 0 <= n + x and n + x <= 10 **5: frequency[n + x] += 1 ans = 0 for k, v in list(frequency.items()): ans = max(ans, v) print(ans)
from collections import defaultdict n = int(eval(input())) numbers = list(map(int, input().split())) d = defaultdict(int) for num in numbers: for x in [-1, 0, 1]: if num + x >= 0: d[num + x] += 1 ans = 0 for k, v in list(d.items()): ans = max(ans, v) print(ans)
16
16
329
296
from collections import defaultdict n = int(eval(input())) nums = list(map(int, input().split())) frequency = defaultdict(int) for n in nums: for x in [-1, 0, 1]: if 0 <= n + x and n + x <= 10**5: frequency[n + x] += 1 ans = 0 for k, v in list(frequency.items()): ans = max(ans, v) print(ans)
from collections import defaultdict n = int(eval(input())) numbers = list(map(int, input().split())) d = defaultdict(int) for num in numbers: for x in [-1, 0, 1]: if num + x >= 0: d[num + x] += 1 ans = 0 for k, v in list(d.items()): ans = max(ans, v) print(ans)
false
0
[ "-nums = list(map(int, input().split()))", "-frequency = defaultdict(int)", "-for n in nums:", "+numbers = list(map(int, input().split()))", "+d = defaultdict(int)", "+for num in numbers:", "- if 0 <= n + x and n + x <= 10**5:", "- frequency[n + x] += 1", "+ if num + x >= 0:", "+ d[num + x] += 1", "-for k, v in list(frequency.items()):", "+for k, v in list(d.items()):" ]
false
0.030707
0.105199
0.291895
[ "s898393448", "s296781179" ]
u381518904
p02971
python
s898929918
s575650452
933
252
70,104
14,076
Accepted
Accepted
72.99
n = int(eval(input())) numList = [int(eval(input())) for _ in range(n)] maxVal = max(numList) workList = numList[:] workList.remove(maxVal) secondVal = max(workList) for num in numList: if num != maxVal: print(maxVal) else: print(secondVal)
import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] max_val = max(A) AA = A[:] AA.remove(max_val) second_max_val = max(AA) for a in A: if a != max_val: print(max_val) else: print(second_max_val) if __name__ == '__main__': main()
11
18
251
373
n = int(eval(input())) numList = [int(eval(input())) for _ in range(n)] maxVal = max(numList) workList = numList[:] workList.remove(maxVal) secondVal = max(workList) for num in numList: if num != maxVal: print(maxVal) else: print(secondVal)
import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] max_val = max(A) AA = A[:] AA.remove(max_val) second_max_val = max(AA) for a in A: if a != max_val: print(max_val) else: print(second_max_val) if __name__ == "__main__": main()
false
38.888889
[ "-n = int(eval(input()))", "-numList = [int(eval(input())) for _ in range(n)]", "-maxVal = max(numList)", "-workList = numList[:]", "-workList.remove(maxVal)", "-secondVal = max(workList)", "-for num in numList:", "- if num != maxVal:", "- print(maxVal)", "- else:", "- print(secondVal)", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ N = int(eval(input()))", "+ A = [int(eval(input())) for _ in range(N)]", "+ max_val = max(A)", "+ AA = A[:]", "+ AA.remove(max_val)", "+ second_max_val = max(AA)", "+ for a in A:", "+ if a != max_val:", "+ print(max_val)", "+ else:", "+ print(second_max_val)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.036355
0.036809
0.987679
[ "s898929918", "s575650452" ]
u367701763
p02719
python
s961990859
s836067914
297
63
80,144
61,900
Accepted
Accepted
78.79
import sys input = sys.stdin.readline def binary_search_int(ok, ng, solve): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid return ok, ng ############################################################## def solve(x): """ ある点 x を境にして True と False が二分されるような関数""" return N - K*x >= 0 N, K = list(map(int, input().split())) a, b = binary_search_int(0, 10**18, solve) print((min(abs(N-a*K), abs(N-b*K))))
import sys input = sys.stdin.readline def binary_search_int(ok, ng): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid return ok, ng ############################################################## def solve(x): """ ある点 x を境にして True と False が二分されるような関数""" return N - K*x >= 0 N, K = list(map(int, input().split())) a, b = binary_search_int(0, 10**18) print((min(abs(N-a*K), abs(N-b*K))))
26
26
614
600
import sys input = sys.stdin.readline def binary_search_int(ok, ng, solve): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid return ok, ng ############################################################## def solve(x): """ある点 x を境にして True と False が二分されるような関数""" return N - K * x >= 0 N, K = list(map(int, input().split())) a, b = binary_search_int(0, 10**18, solve) print((min(abs(N - a * K), abs(N - b * K))))
import sys input = sys.stdin.readline def binary_search_int(ok, ng): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid return ok, ng ############################################################## def solve(x): """ある点 x を境にして True と False が二分されるような関数""" return N - K * x >= 0 N, K = list(map(int, input().split())) a, b = binary_search_int(0, 10**18) print((min(abs(N - a * K), abs(N - b * K))))
false
0
[ "-def binary_search_int(ok, ng, solve):", "+def binary_search_int(ok, ng):", "-a, b = binary_search_int(0, 10**18, solve)", "+a, b = binary_search_int(0, 10**18)" ]
false
0.031879
0.039762
0.80176
[ "s961990859", "s836067914" ]
u732061897
p03221
python
s759782439
s044326532
935
572
101,340
38,216
Accepted
Accepted
38.82
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) for i in range(M)] convertedPY = [ {'index': i, 'city': py[0], 'year': py[1] } for i, py in enumerate(PY) ] ''' 3 4 1 32 3 64 3 63 1 33 ''' convertedPY = sorted(convertedPY, key=lambda a: (a['city'], a['year'])) answer = [] cnt = 0 tmp = convertedPY[0]['city'] #print(convertedPY) result = [] for py in convertedPY: #print(tmp) temp_dict = {} if tmp == py['city']: cnt += 1 temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt) temp_dict['index'] = py['index'] result.append(temp_dict) else: cnt = 1 temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt) temp_dict['index'] = py['index'] result.append(temp_dict) tmp = py['city'] result = sorted(result, key=lambda a: a['index']) #print(result) for r in result: print((r['answer'])) ''' 3 21 -11 81234 52141 94124 ''' #print(PY)
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) + [i] + [0] for i in range(M)] PY_sorted = sorted(PY, key=lambda a: (a[0], a[1])) PY_sorted[0][3] = str(PY_sorted[0][0]).zfill(6) + str(1).zfill(6) #print(PY_sorted) cnt = 1 for i in range(1, M): cnt += 1 if PY_sorted[i][0] != PY_sorted[i - 1][0]: cnt = 1 PY_sorted[i][3] = str(PY_sorted[i][0]).zfill(6) + str(cnt).zfill(6) else: PY_sorted[i][3] = str(PY_sorted[i][0]).zfill(6) + str(cnt).zfill(6) #print(PY_sorted) ans = sorted(PY_sorted, key=lambda a: a[2]) for a in ans: print((a[3]))
51
19
1,052
617
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) for i in range(M)] convertedPY = [{"index": i, "city": py[0], "year": py[1]} for i, py in enumerate(PY)] """ 3 4 1 32 3 64 3 63 1 33 """ convertedPY = sorted(convertedPY, key=lambda a: (a["city"], a["year"])) answer = [] cnt = 0 tmp = convertedPY[0]["city"] # print(convertedPY) result = [] for py in convertedPY: # print(tmp) temp_dict = {} if tmp == py["city"]: cnt += 1 temp_dict["answer"] = "{:0=6}".format(py["city"]) + "{:0=6}".format(cnt) temp_dict["index"] = py["index"] result.append(temp_dict) else: cnt = 1 temp_dict["answer"] = "{:0=6}".format(py["city"]) + "{:0=6}".format(cnt) temp_dict["index"] = py["index"] result.append(temp_dict) tmp = py["city"] result = sorted(result, key=lambda a: a["index"]) # print(result) for r in result: print((r["answer"])) """ 3 21 -11 81234 52141 94124 """ # print(PY)
N, M = list(map(int, input().split())) PY = [list(map(int, input().split())) + [i] + [0] for i in range(M)] PY_sorted = sorted(PY, key=lambda a: (a[0], a[1])) PY_sorted[0][3] = str(PY_sorted[0][0]).zfill(6) + str(1).zfill(6) # print(PY_sorted) cnt = 1 for i in range(1, M): cnt += 1 if PY_sorted[i][0] != PY_sorted[i - 1][0]: cnt = 1 PY_sorted[i][3] = str(PY_sorted[i][0]).zfill(6) + str(cnt).zfill(6) else: PY_sorted[i][3] = str(PY_sorted[i][0]).zfill(6) + str(cnt).zfill(6) # print(PY_sorted) ans = sorted(PY_sorted, key=lambda a: a[2]) for a in ans: print((a[3]))
false
62.745098
[ "-PY = [list(map(int, input().split())) for i in range(M)]", "-convertedPY = [{\"index\": i, \"city\": py[0], \"year\": py[1]} for i, py in enumerate(PY)]", "-\"\"\"", "-3 4", "-1 32", "-3 64", "-3 63", "-1 33", "-\"\"\"", "-convertedPY = sorted(convertedPY, key=lambda a: (a[\"city\"], a[\"year\"]))", "-answer = []", "-cnt = 0", "-tmp = convertedPY[0][\"city\"]", "-# print(convertedPY)", "-result = []", "-for py in convertedPY:", "- # print(tmp)", "- temp_dict = {}", "- if tmp == py[\"city\"]:", "- cnt += 1", "- temp_dict[\"answer\"] = \"{:0=6}\".format(py[\"city\"]) + \"{:0=6}\".format(cnt)", "- temp_dict[\"index\"] = py[\"index\"]", "- result.append(temp_dict)", "+PY = [list(map(int, input().split())) + [i] + [0] for i in range(M)]", "+PY_sorted = sorted(PY, key=lambda a: (a[0], a[1]))", "+PY_sorted[0][3] = str(PY_sorted[0][0]).zfill(6) + str(1).zfill(6)", "+# print(PY_sorted)", "+cnt = 1", "+for i in range(1, M):", "+ cnt += 1", "+ if PY_sorted[i][0] != PY_sorted[i - 1][0]:", "+ cnt = 1", "+ PY_sorted[i][3] = str(PY_sorted[i][0]).zfill(6) + str(cnt).zfill(6)", "- cnt = 1", "- temp_dict[\"answer\"] = \"{:0=6}\".format(py[\"city\"]) + \"{:0=6}\".format(cnt)", "- temp_dict[\"index\"] = py[\"index\"]", "- result.append(temp_dict)", "- tmp = py[\"city\"]", "-result = sorted(result, key=lambda a: a[\"index\"])", "-# print(result)", "-for r in result:", "- print((r[\"answer\"]))", "-\"\"\"", "-3", "-21 -11", "-81234 52141 94124", "-\"\"\"", "-# print(PY)", "+ PY_sorted[i][3] = str(PY_sorted[i][0]).zfill(6) + str(cnt).zfill(6)", "+# print(PY_sorted)", "+ans = sorted(PY_sorted, key=lambda a: a[2])", "+for a in ans:", "+ print((a[3]))" ]
false
0.040931
0.03719
1.100599
[ "s759782439", "s044326532" ]
u780962115
p03347
python
s362112788
s601489087
800
421
57,628
11,048
Accepted
Accepted
47.38
n=int(eval(input())) lists=[int(eval(input()))for i in range(n)] lists.append(0) ans=0 if lists[0]!=0: print((-1)) else: flag=True for i in range(n-1): if lists[i]+1<lists[i+1]: flag=False break if not flag: print((-1)) else: for i in range(n): if lists[i]+1==lists[i+1]: ans+=1 else: ans+=lists[i+1] print(ans)
#sequence growing easy N=int(eval(input())) a=[int(eval(input())) for _ in range(N)] answer=0 now_value=10**9 for i in range(N-1,-1,-1): if a[i]>i: answer=-1 break if a[i]==now_value-1: now_value-=1 else: answer+=a[i] now_value=a[i] for i in range(N-1): if a[i+1]-a[i]>1: answer=-1 break print(answer)
23
19
467
382
n = int(eval(input())) lists = [int(eval(input())) for i in range(n)] lists.append(0) ans = 0 if lists[0] != 0: print((-1)) else: flag = True for i in range(n - 1): if lists[i] + 1 < lists[i + 1]: flag = False break if not flag: print((-1)) else: for i in range(n): if lists[i] + 1 == lists[i + 1]: ans += 1 else: ans += lists[i + 1] print(ans)
# sequence growing easy N = int(eval(input())) a = [int(eval(input())) for _ in range(N)] answer = 0 now_value = 10**9 for i in range(N - 1, -1, -1): if a[i] > i: answer = -1 break if a[i] == now_value - 1: now_value -= 1 else: answer += a[i] now_value = a[i] for i in range(N - 1): if a[i + 1] - a[i] > 1: answer = -1 break print(answer)
false
17.391304
[ "-n = int(eval(input()))", "-lists = [int(eval(input())) for i in range(n)]", "-lists.append(0)", "-ans = 0", "-if lists[0] != 0:", "- print((-1))", "-else:", "- flag = True", "- for i in range(n - 1):", "- if lists[i] + 1 < lists[i + 1]:", "- flag = False", "- break", "- if not flag:", "- print((-1))", "+# sequence growing easy", "+N = int(eval(input()))", "+a = [int(eval(input())) for _ in range(N)]", "+answer = 0", "+now_value = 10**9", "+for i in range(N - 1, -1, -1):", "+ if a[i] > i:", "+ answer = -1", "+ break", "+ if a[i] == now_value - 1:", "+ now_value -= 1", "- for i in range(n):", "- if lists[i] + 1 == lists[i + 1]:", "- ans += 1", "- else:", "- ans += lists[i + 1]", "- print(ans)", "+ answer += a[i]", "+ now_value = a[i]", "+for i in range(N - 1):", "+ if a[i + 1] - a[i] > 1:", "+ answer = -1", "+ break", "+print(answer)" ]
false
0.066976
0.037693
1.776864
[ "s362112788", "s601489087" ]
u164727245
p02598
python
s806564489
s157939991
686
240
33,528
50,932
Accepted
Accepted
65.01
# coding: utf-8 def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = tuple(map(int, args[1].split())) l, r = 0, max(A) while l+1 < r: m = (l+r)//2 cnt = 0 for a in A: cnt += -(-a//m)-1 if k < cnt: l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 import numpy as np def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = np.array(tuple(map(int, args[1].split()))) l, r = 0, np.max(A) while l+1 < r: m = (l+r)//2 if k < np.sum(-(-A//m)-1): l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
23
21
443
422
# coding: utf-8 def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = tuple(map(int, args[1].split())) l, r = 0, max(A) while l + 1 < r: m = (l + r) // 2 cnt = 0 for a in A: cnt += -(-a // m) - 1 if k < cnt: l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
# coding: utf-8 import numpy as np def solve(*args: str) -> str: n, k = list(map(int, args[0].split())) A = np.array(tuple(map(int, args[1].split()))) l, r = 0, np.max(A) while l + 1 < r: m = (l + r) // 2 if k < np.sum(-(-A // m) - 1): l = m else: r = m return str(r) if __name__ == "__main__": print((solve(*(open(0).read().splitlines()))))
false
8.695652
[ "+import numpy as np", "+", "+", "- A = tuple(map(int, args[1].split()))", "- l, r = 0, max(A)", "+ A = np.array(tuple(map(int, args[1].split())))", "+ l, r = 0, np.max(A)", "- cnt = 0", "- for a in A:", "- cnt += -(-a // m) - 1", "- if k < cnt:", "+ if k < np.sum(-(-A // m) - 1):" ]
false
0.04088
0.191433
0.213546
[ "s806564489", "s157939991" ]
u301624971
p03073
python
s987963425
s719394625
37
29
3,956
3,956
Accepted
Accepted
21.62
N=list(eval(input())) counter=0 pre = N.pop(0) for n in N: if(pre == n): counter+=1 if(pre == "0"): pre="1" else: pre="0" print(counter)
def myAnswer(s:list) -> str: ans = 0 pre =s.pop(0) for i in s: if(pre == i): ans += 1 pre = "1" if(i == "0") else "0" else: pre = i return ans def modelAnswer(): tmp=1 def main(): s = list(eval(input())) print((myAnswer(s))) if __name__ == '__main__': main()
14
19
183
333
N = list(eval(input())) counter = 0 pre = N.pop(0) for n in N: if pre == n: counter += 1 if pre == "0": pre = "1" else: pre = "0" print(counter)
def myAnswer(s: list) -> str: ans = 0 pre = s.pop(0) for i in s: if pre == i: ans += 1 pre = "1" if (i == "0") else "0" else: pre = i return ans def modelAnswer(): tmp = 1 def main(): s = list(eval(input())) print((myAnswer(s))) if __name__ == "__main__": main()
false
26.315789
[ "-N = list(eval(input()))", "-counter = 0", "-pre = N.pop(0)", "-for n in N:", "- if pre == n:", "- counter += 1", "- if pre == \"0\":", "- pre = \"1\"", "- else:", "- pre = \"0\"", "-print(counter)", "+def myAnswer(s: list) -> str:", "+ ans = 0", "+ pre = s.pop(0)", "+ for i in s:", "+ if pre == i:", "+ ans += 1", "+ pre = \"1\" if (i == \"0\") else \"0\"", "+ else:", "+ pre = i", "+ return ans", "+", "+", "+def modelAnswer():", "+ tmp = 1", "+", "+", "+def main():", "+ s = list(eval(input()))", "+ print((myAnswer(s)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.040428
0.04212
0.959822
[ "s987963425", "s719394625" ]
u063052907
p03633
python
s763653601
s196644793
38
17
5,384
3,064
Accepted
Accepted
55.26
from functools import reduce from fractions import gcd def lcm(a, b): return (a * b) // gcd(a, b) N = int(eval(input())) lst_T = [int(eval(input())) for _ in range(N)] ans = reduce(lcm, lst_T) print(ans)
def gcd(a, b): if b == 0: return a return gcd(b, a%b) def lcm(a, b): return (a * b) // gcd(a, b) N = int(eval(input())) lst_T = [int(eval(input())) for _ in range(N)] ans = 1 for t in lst_T: ans = lcm(ans, t) print(ans)
16
20
218
258
from functools import reduce from fractions import gcd def lcm(a, b): return (a * b) // gcd(a, b) N = int(eval(input())) lst_T = [int(eval(input())) for _ in range(N)] ans = reduce(lcm, lst_T) print(ans)
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return (a * b) // gcd(a, b) N = int(eval(input())) lst_T = [int(eval(input())) for _ in range(N)] ans = 1 for t in lst_T: ans = lcm(ans, t) print(ans)
false
20
[ "-from functools import reduce", "-from fractions import gcd", "+def gcd(a, b):", "+ if b == 0:", "+ return a", "+ return gcd(b, a % b)", "-ans = reduce(lcm, lst_T)", "+ans = 1", "+for t in lst_T:", "+ ans = lcm(ans, t)" ]
false
0.20704
0.069853
2.963928
[ "s763653601", "s196644793" ]
u923668099
p00740
python
s482484997
s266590643
4,940
4,100
7,508
7,672
Accepted
Accepted
17
from sys import stdin, stdout, stderr while 1: n, p = list(map(int, stdin.readline().split())) if n + p == 0: break a = [0] * n wan = p for i in range(10**6): if wan > 0: a[i % n] += 1 wan -= 1 else: wan += a[i % n] a[i % n] = 0 if a[i % n] == p: print((i % n)) break
from sys import stdin, stdout, stderr a = [0] * 50 while 1: n, p = list(map(int, stdin.readline().split())) if n + p == 0: break wan = p i = 0 while a[i] < p: if wan > 0: a[i] += 1 wan -= 1 else: wan += a[i] a[i] = 0 i = (i + 1) % n print(i) a[i] = 0
22
25
409
383
from sys import stdin, stdout, stderr while 1: n, p = list(map(int, stdin.readline().split())) if n + p == 0: break a = [0] * n wan = p for i in range(10**6): if wan > 0: a[i % n] += 1 wan -= 1 else: wan += a[i % n] a[i % n] = 0 if a[i % n] == p: print((i % n)) break
from sys import stdin, stdout, stderr a = [0] * 50 while 1: n, p = list(map(int, stdin.readline().split())) if n + p == 0: break wan = p i = 0 while a[i] < p: if wan > 0: a[i] += 1 wan -= 1 else: wan += a[i] a[i] = 0 i = (i + 1) % n print(i) a[i] = 0
false
12
[ "+a = [0] * 50", "- a = [0] * n", "- for i in range(10**6):", "+ i = 0", "+ while a[i] < p:", "- a[i % n] += 1", "+ a[i] += 1", "- wan += a[i % n]", "- a[i % n] = 0", "- if a[i % n] == p:", "- print((i % n))", "- break", "+ wan += a[i]", "+ a[i] = 0", "+ i = (i + 1) % n", "+ print(i)", "+ a[i] = 0" ]
false
0.539418
1.180632
0.456889
[ "s482484997", "s266590643" ]
u393486651
p03371
python
s893782481
s776248937
159
122
3,064
3,188
Accepted
Accepted
23.27
def main(): A,B,C,X,Y = list(map(int, input().split())) min_cost = 2 * (10 ** 5) * max(A, B, C) for i in range(max(X, Y) + 1): num_c = 2 * (max(X, Y) - i) num_b = max(0, min(Y - num_c // 2, i)) num_a = max(0, min(X - num_c // 2, i)) total = A * num_a + B * num_b + C * num_c min_cost = min(total, min_cost) print(min_cost) if __name__ == "__main__": main()
def main(): A,B,C,X,Y = list(map(int, input().split())) min_cost = 2 * (10 ** 5) * max(A, B, C) for i in range(max(X, Y) + 1): num_c = 2 * (max(X, Y) - i) num_b = max(0, Y - num_c // 2) num_a = max(0, X - num_c // 2) total = A * num_a + B * num_b + C * num_c min_cost = min(total, min_cost) print(min_cost) if __name__ == "__main__": main()
16
16
407
391
def main(): A, B, C, X, Y = list(map(int, input().split())) min_cost = 2 * (10**5) * max(A, B, C) for i in range(max(X, Y) + 1): num_c = 2 * (max(X, Y) - i) num_b = max(0, min(Y - num_c // 2, i)) num_a = max(0, min(X - num_c // 2, i)) total = A * num_a + B * num_b + C * num_c min_cost = min(total, min_cost) print(min_cost) if __name__ == "__main__": main()
def main(): A, B, C, X, Y = list(map(int, input().split())) min_cost = 2 * (10**5) * max(A, B, C) for i in range(max(X, Y) + 1): num_c = 2 * (max(X, Y) - i) num_b = max(0, Y - num_c // 2) num_a = max(0, X - num_c // 2) total = A * num_a + B * num_b + C * num_c min_cost = min(total, min_cost) print(min_cost) if __name__ == "__main__": main()
false
0
[ "- num_b = max(0, min(Y - num_c // 2, i))", "- num_a = max(0, min(X - num_c // 2, i))", "+ num_b = max(0, Y - num_c // 2)", "+ num_a = max(0, X - num_c // 2)" ]
false
0.120752
0.061794
1.954091
[ "s893782481", "s776248937" ]
u606033239
p03240
python
s005334001
s159227457
674
623
3,064
3,064
Accepted
Accepted
7.57
n=int(eval(input())) xyh=[] x,y,h=-1,-1,-1 nonzero=-1 for i in range(n): xyh.append(list(map(int,input().split()))) if xyh[i][2] != 0: nonzero = i for px in range(101): for py in range(101): nh = xyh[nonzero][2]+abs(xyh[nonzero][0]-px)+abs(xyh[nonzero][1]-py) ok = True for nn in range(n): if xyh[nn][2] > 0 and nh != xyh[nn][2]+abs(xyh[nn][0]-px) + abs(xyh[nn][1]-py): ok=False if xyh[nn][2] == 0 and nh > abs(xyh[nn][0]-px) +abs(xyh[nn][1]-py): ok=False if ok: x,y,h = px,py,nh print((x,y,h)) exit()
n=int(eval(input())) a=[] x,y,k=-1,-1,-1 t=-1 for o in range(n): a.append(list(map(int,input().split()))) if a[o][2] != 0: t=o for i in range(101): for j in range(101): h=a[t][2]+abs(a[t][0]-i)+abs(a[t][1]-j) d=True for l in range(n): if a[l][2] > 0 and h != a[l][2]+abs(a[l][0]-i)+abs(a[l][1]-j): d=False if a[l][2]==0 and h>abs(a[l][0]-i)+abs(a[l][1]-j): d=False if d: x,y,k=i,j,h print((x,y,k)) exit()
26
25
675
581
n = int(eval(input())) xyh = [] x, y, h = -1, -1, -1 nonzero = -1 for i in range(n): xyh.append(list(map(int, input().split()))) if xyh[i][2] != 0: nonzero = i for px in range(101): for py in range(101): nh = xyh[nonzero][2] + abs(xyh[nonzero][0] - px) + abs(xyh[nonzero][1] - py) ok = True for nn in range(n): if xyh[nn][2] > 0 and nh != xyh[nn][2] + abs(xyh[nn][0] - px) + abs( xyh[nn][1] - py ): ok = False if xyh[nn][2] == 0 and nh > abs(xyh[nn][0] - px) + abs(xyh[nn][1] - py): ok = False if ok: x, y, h = px, py, nh print((x, y, h)) exit()
n = int(eval(input())) a = [] x, y, k = -1, -1, -1 t = -1 for o in range(n): a.append(list(map(int, input().split()))) if a[o][2] != 0: t = o for i in range(101): for j in range(101): h = a[t][2] + abs(a[t][0] - i) + abs(a[t][1] - j) d = True for l in range(n): if a[l][2] > 0 and h != a[l][2] + abs(a[l][0] - i) + abs(a[l][1] - j): d = False if a[l][2] == 0 and h > abs(a[l][0] - i) + abs(a[l][1] - j): d = False if d: x, y, k = i, j, h print((x, y, k)) exit()
false
3.846154
[ "-xyh = []", "-x, y, h = -1, -1, -1", "-nonzero = -1", "-for i in range(n):", "- xyh.append(list(map(int, input().split())))", "- if xyh[i][2] != 0:", "- nonzero = i", "-for px in range(101):", "- for py in range(101):", "- nh = xyh[nonzero][2] + abs(xyh[nonzero][0] - px) + abs(xyh[nonzero][1] - py)", "- ok = True", "- for nn in range(n):", "- if xyh[nn][2] > 0 and nh != xyh[nn][2] + abs(xyh[nn][0] - px) + abs(", "- xyh[nn][1] - py", "- ):", "- ok = False", "- if xyh[nn][2] == 0 and nh > abs(xyh[nn][0] - px) + abs(xyh[nn][1] - py):", "- ok = False", "- if ok:", "- x, y, h = px, py, nh", "- print((x, y, h))", "+a = []", "+x, y, k = -1, -1, -1", "+t = -1", "+for o in range(n):", "+ a.append(list(map(int, input().split())))", "+ if a[o][2] != 0:", "+ t = o", "+for i in range(101):", "+ for j in range(101):", "+ h = a[t][2] + abs(a[t][0] - i) + abs(a[t][1] - j)", "+ d = True", "+ for l in range(n):", "+ if a[l][2] > 0 and h != a[l][2] + abs(a[l][0] - i) + abs(a[l][1] - j):", "+ d = False", "+ if a[l][2] == 0 and h > abs(a[l][0] - i) + abs(a[l][1] - j):", "+ d = False", "+ if d:", "+ x, y, k = i, j, h", "+ print((x, y, k))" ]
false
0.107993
0.050562
2.135842
[ "s005334001", "s159227457" ]
u537905693
p02614
python
s930422418
s922489897
77
59
9,268
9,144
Accepted
Accepted
23.38
#!/usr/bin/env python # coding: utf-8 def ri(): return int(eval(input())) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def simulate(mh, mw, H, W, K, grid): flags = [[1 for _ in range(W)] for _ in range(H)] for h in range(H): if not (mh>>h)&1: continue for w in range(W): flags[h][w] = 0 for w in range(W): if not (mw>>w)&1: continue for h in range(H): flags[h][w] = 0 cnt = 0 for h in range(H): for w in range(W): if flags[h][w] and grid[h][w] == '#': cnt += 1 if cnt == K: # print(flags) # print(mh, mw) return 1 return 0 def main(): H, W, K = rli() grid = [] for i in range(H): grid.append(eval(input())) ans = 0 for mh in range(0, 2**H): for mw in range(0, 2**W): ans += simulate(mh, mw, H, W, K, grid) print(ans) if __name__ == '__main__': main()
#!/usr/bin/env python # coding: utf-8 def ri(): return int(eval(input())) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def main(): H, W, K = rli() grid = [] for i in range(H): grid.append(eval(input())) ans = 0 for mh in range(0, 2**H): for mw in range(0, 2**W): cnt = 0 for h in range(H): for w in range(W): if grid[h][w] == '#' and ((mh>>h)&1) and ((mw>>w)&1): cnt += 1 if cnt == K: ans += 1 print(ans) if __name__ == '__main__': main()
50
33
1,076
678
#!/usr/bin/env python # coding: utf-8 def ri(): return int(eval(input())) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def simulate(mh, mw, H, W, K, grid): flags = [[1 for _ in range(W)] for _ in range(H)] for h in range(H): if not (mh >> h) & 1: continue for w in range(W): flags[h][w] = 0 for w in range(W): if not (mw >> w) & 1: continue for h in range(H): flags[h][w] = 0 cnt = 0 for h in range(H): for w in range(W): if flags[h][w] and grid[h][w] == "#": cnt += 1 if cnt == K: # print(flags) # print(mh, mw) return 1 return 0 def main(): H, W, K = rli() grid = [] for i in range(H): grid.append(eval(input())) ans = 0 for mh in range(0, 2**H): for mw in range(0, 2**W): ans += simulate(mh, mw, H, W, K, grid) print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python # coding: utf-8 def ri(): return int(eval(input())) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def main(): H, W, K = rli() grid = [] for i in range(H): grid.append(eval(input())) ans = 0 for mh in range(0, 2**H): for mw in range(0, 2**W): cnt = 0 for h in range(H): for w in range(W): if grid[h][w] == "#" and ((mh >> h) & 1) and ((mw >> w) & 1): cnt += 1 if cnt == K: ans += 1 print(ans) if __name__ == "__main__": main()
false
34
[ "-def simulate(mh, mw, H, W, K, grid):", "- flags = [[1 for _ in range(W)] for _ in range(H)]", "- for h in range(H):", "- if not (mh >> h) & 1:", "- continue", "- for w in range(W):", "- flags[h][w] = 0", "- for w in range(W):", "- if not (mw >> w) & 1:", "- continue", "- for h in range(H):", "- flags[h][w] = 0", "- cnt = 0", "- for h in range(H):", "- for w in range(W):", "- if flags[h][w] and grid[h][w] == \"#\":", "- cnt += 1", "- if cnt == K:", "- # print(flags)", "- # print(mh, mw)", "- return 1", "- return 0", "-", "-", "- ans += simulate(mh, mw, H, W, K, grid)", "+ cnt = 0", "+ for h in range(H):", "+ for w in range(W):", "+ if grid[h][w] == \"#\" and ((mh >> h) & 1) and ((mw >> w) & 1):", "+ cnt += 1", "+ if cnt == K:", "+ ans += 1" ]
false
0.040642
0.04029
1.008734
[ "s930422418", "s922489897" ]
u968166680
p02763
python
s046004692
s408891525
521
461
203,660
203,084
Accepted
Accepted
11.52
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def add(self, i, x=1): i += 1 while i <= self.n: self.data[i] += x i += i & -i def get_sum(self, i): i += 1 x = 0 while i > 0: x += self.data[i] i -= i & -i return x # Return sum for [l, r) def get_sum_range(self, l, r): return self.get_sum(r - 1) - self.get_sum(l - 1) def main(): N = int(readline()) S = readline().strip() Q = int(readline()) query = [readline().split() for _ in range(Q)] bit = [BIT(N) for _ in range(26)] for i, c in enumerate(S): bit[ord(c) - ord('a')].add(i) S = list(S) ans = [] for q in query: if q[0] == '1': i = int(q[1]) - 1 c = q[2] bit[ord(S[i]) - ord('a')].add(i, -1) bit[ord(c) - ord('a')].add(i, 1) S[i] = c else: res = 0 l, r = int(q[1]) - 1, int(q[2]) - 1 for i in range(26): if bit[i].get_sum_range(l, r + 1): res += 1 ans.append(res) print(*ans, sep='\n') return if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def add(self, i, x=1): i += 1 while i <= self.n: self.data[i] += x i += i & -i def get_sum(self, i): i += 1 x = 0 while i > 0: x += self.data[i] i -= i & -i return x # Return sum for [l, r) def get_sum_range(self, l, r): return self.get_sum(r - 1) - self.get_sum(l - 1) def main(): N = int(readline()) S = readline().strip() Q = int(readline()) bit = [BIT(N) for _ in range(26)] for i, c in enumerate(S): bit[ord(c) - ord('a')].add(i) S = list(S) ans = [] for _ in range(Q): n, a, b = readline().split() if n == '1': i = int(a) - 1 if b != S[i]: bit[ord(S[i]) - ord('a')].add(i, -1) bit[ord(b) - ord('a')].add(i, 1) S[i] = b else: res = 0 l, r = int(a) - 1, int(b) - 1 for i in range(26): if bit[i].get_sum_range(l, r + 1): res += 1 ans.append(res) print(*ans, sep='\n') return if __name__ == '__main__': main()
69
69
1,501
1,495
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def add(self, i, x=1): i += 1 while i <= self.n: self.data[i] += x i += i & -i def get_sum(self, i): i += 1 x = 0 while i > 0: x += self.data[i] i -= i & -i return x # Return sum for [l, r) def get_sum_range(self, l, r): return self.get_sum(r - 1) - self.get_sum(l - 1) def main(): N = int(readline()) S = readline().strip() Q = int(readline()) query = [readline().split() for _ in range(Q)] bit = [BIT(N) for _ in range(26)] for i, c in enumerate(S): bit[ord(c) - ord("a")].add(i) S = list(S) ans = [] for q in query: if q[0] == "1": i = int(q[1]) - 1 c = q[2] bit[ord(S[i]) - ord("a")].add(i, -1) bit[ord(c) - ord("a")].add(i, 1) S[i] = c else: res = 0 l, r = int(q[1]) - 1, int(q[2]) - 1 for i in range(26): if bit[i].get_sum_range(l, r + 1): res += 1 ans.append(res) print(*ans, sep="\n") return if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def add(self, i, x=1): i += 1 while i <= self.n: self.data[i] += x i += i & -i def get_sum(self, i): i += 1 x = 0 while i > 0: x += self.data[i] i -= i & -i return x # Return sum for [l, r) def get_sum_range(self, l, r): return self.get_sum(r - 1) - self.get_sum(l - 1) def main(): N = int(readline()) S = readline().strip() Q = int(readline()) bit = [BIT(N) for _ in range(26)] for i, c in enumerate(S): bit[ord(c) - ord("a")].add(i) S = list(S) ans = [] for _ in range(Q): n, a, b = readline().split() if n == "1": i = int(a) - 1 if b != S[i]: bit[ord(S[i]) - ord("a")].add(i, -1) bit[ord(b) - ord("a")].add(i, 1) S[i] = b else: res = 0 l, r = int(a) - 1, int(b) - 1 for i in range(26): if bit[i].get_sum_range(l, r + 1): res += 1 ans.append(res) print(*ans, sep="\n") return if __name__ == "__main__": main()
false
0
[ "- query = [readline().split() for _ in range(Q)]", "- for q in query:", "- if q[0] == \"1\":", "- i = int(q[1]) - 1", "- c = q[2]", "- bit[ord(S[i]) - ord(\"a\")].add(i, -1)", "- bit[ord(c) - ord(\"a\")].add(i, 1)", "- S[i] = c", "+ for _ in range(Q):", "+ n, a, b = readline().split()", "+ if n == \"1\":", "+ i = int(a) - 1", "+ if b != S[i]:", "+ bit[ord(S[i]) - ord(\"a\")].add(i, -1)", "+ bit[ord(b) - ord(\"a\")].add(i, 1)", "+ S[i] = b", "- l, r = int(q[1]) - 1, int(q[2]) - 1", "+ l, r = int(a) - 1, int(b) - 1" ]
false
0.044973
0.045113
0.996895
[ "s046004692", "s408891525" ]
u608241985
p02725
python
s713735446
s150232833
92
73
27,900
27,908
Accepted
Accepted
20.65
import sys read = sys.stdin.buffer.read k, n, *A = list(map(int, read().split())) far = k + A[0] - A[-1] y = A[0] for x in A[1:]: dis = x - y if far < dis: far = dis y = x print((k - far))
import sys def main(): read = sys.stdin.buffer.read k, n, *A = list(map(int, read().split())) far = k + A[0] - A[-1] y = A[0] for x in A[1:]: dis = x - y if far < dis: far = dis y = x print((k - far)) if __name__ == "__main__": main()
11
18
210
311
import sys read = sys.stdin.buffer.read k, n, *A = list(map(int, read().split())) far = k + A[0] - A[-1] y = A[0] for x in A[1:]: dis = x - y if far < dis: far = dis y = x print((k - far))
import sys def main(): read = sys.stdin.buffer.read k, n, *A = list(map(int, read().split())) far = k + A[0] - A[-1] y = A[0] for x in A[1:]: dis = x - y if far < dis: far = dis y = x print((k - far)) if __name__ == "__main__": main()
false
38.888889
[ "-read = sys.stdin.buffer.read", "-k, n, *A = list(map(int, read().split()))", "-far = k + A[0] - A[-1]", "-y = A[0]", "-for x in A[1:]:", "- dis = x - y", "- if far < dis:", "- far = dis", "- y = x", "-print((k - far))", "+", "+def main():", "+ read = sys.stdin.buffer.read", "+ k, n, *A = list(map(int, read().split()))", "+ far = k + A[0] - A[-1]", "+ y = A[0]", "+ for x in A[1:]:", "+ dis = x - y", "+ if far < dis:", "+ far = dis", "+ y = x", "+ print((k - far))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.093887
0.044556
2.107174
[ "s713735446", "s150232833" ]
u266874640
p03044
python
s971070100
s810853756
1,152
1,040
103,252
102,108
Accepted
Accepted
9.72
import sys sys.setrecursionlimit(500*500) N = int(eval(input())) edges = [list(map(int,input().split())) for _ in range(N-1)] A = [[]for _ in range(N+1)] ans = [-1]*(N+1) for u,v,w in edges: A[u].append([v,w%2]) A[v].append([u,w%2]) ans[1] = 0 def dfs(r): for a in A[r].copy(): n = a[0] d = a[1] if ans[n] == -1: ans[n] = (ans[r] + d) % 2 dfs(n) dfs(1) for a in ans[1:]: print((a%2))
import sys sys.setrecursionlimit(500*500) N = int(eval(input())) edges = [list(map(int,input().split())) for _ in range(N-1)] A = [[] for _ in range(N+1)] for edge in edges: A[edge[0]].append([edge[1],edge[2]]) A[edge[1]].append([edge[0],edge[2]]) depth = [-1] * (N+1) depth[1] = 0 def dfs(A,s): for v in A[s]: if depth[v[0]] == -1: depth[v[0]] = depth[s] + v[1] dfs(A,v[0]) dfs(A,1) for d in depth[1:]: if d % 2 == 0: print((0)) else: print((1))
21
24
461
534
import sys sys.setrecursionlimit(500 * 500) N = int(eval(input())) edges = [list(map(int, input().split())) for _ in range(N - 1)] A = [[] for _ in range(N + 1)] ans = [-1] * (N + 1) for u, v, w in edges: A[u].append([v, w % 2]) A[v].append([u, w % 2]) ans[1] = 0 def dfs(r): for a in A[r].copy(): n = a[0] d = a[1] if ans[n] == -1: ans[n] = (ans[r] + d) % 2 dfs(n) dfs(1) for a in ans[1:]: print((a % 2))
import sys sys.setrecursionlimit(500 * 500) N = int(eval(input())) edges = [list(map(int, input().split())) for _ in range(N - 1)] A = [[] for _ in range(N + 1)] for edge in edges: A[edge[0]].append([edge[1], edge[2]]) A[edge[1]].append([edge[0], edge[2]]) depth = [-1] * (N + 1) depth[1] = 0 def dfs(A, s): for v in A[s]: if depth[v[0]] == -1: depth[v[0]] = depth[s] + v[1] dfs(A, v[0]) dfs(A, 1) for d in depth[1:]: if d % 2 == 0: print((0)) else: print((1))
false
12.5
[ "-ans = [-1] * (N + 1)", "-for u, v, w in edges:", "- A[u].append([v, w % 2])", "- A[v].append([u, w % 2])", "-ans[1] = 0", "+for edge in edges:", "+ A[edge[0]].append([edge[1], edge[2]])", "+ A[edge[1]].append([edge[0], edge[2]])", "+depth = [-1] * (N + 1)", "+depth[1] = 0", "-def dfs(r):", "- for a in A[r].copy():", "- n = a[0]", "- d = a[1]", "- if ans[n] == -1:", "- ans[n] = (ans[r] + d) % 2", "- dfs(n)", "+def dfs(A, s):", "+ for v in A[s]:", "+ if depth[v[0]] == -1:", "+ depth[v[0]] = depth[s] + v[1]", "+ dfs(A, v[0])", "-dfs(1)", "-for a in ans[1:]:", "- print((a % 2))", "+dfs(A, 1)", "+for d in depth[1:]:", "+ if d % 2 == 0:", "+ print((0))", "+ else:", "+ print((1))" ]
false
0.037302
0.036678
1.017018
[ "s971070100", "s810853756" ]
u477977638
p02586
python
s987624033
s346682812
1,368
867
428,036
145,536
Accepted
Accepted
36.62
import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return input().rstrip().decode() def II(): return int(eval(input())) def FI(): return int(eval(input())) def MI(): return list(map(int,input().split())) def MF(): return list(map(float,input().split())) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() def main(): r,c,k=MI() G=[[0]*(c+1) for _ in range(r+1)] dp=[[[0]*(c+1) for i in range(r+1)] for j in range(4)] for _ in range(k): rrr,ccc,v=MI() G[rrr][ccc]=v #print(G) #print(dp) for rr in range(1,r+1): for cc in range(1,c+1): if G[rr][cc]==0: for i in range(4): dp[i][rr][cc]=max(dp[i][rr][cc-1],dp[3][rr-1][cc]) else: dp[0][rr][cc]=max(dp[3][rr-1][cc],dp[0][rr][cc-1]) dp[1][rr][cc]=max(dp[0][rr][cc]+G[rr][cc],dp[1][rr][cc-1]) dp[2][rr][cc]=max(dp[1][rr][cc-1]+G[rr][cc],dp[2][rr][cc-1],dp[1][rr][cc]) dp[3][rr][cc]=max(dp[2][rr][cc-1]+G[rr][cc],dp[3][rr][cc-1],dp[2][rr][cc]) #print(dp) print((dp[-1][-1][-1])) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return input().rstrip().decode() def II(): return int(eval(input())) def FI(): return int(eval(input())) def MI(): return list(map(int,input().split())) def MF(): return list(map(float,input().split())) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() def main(): r,c,k=MI() G=[[0]*(c+1) for _ in range(r+1)] dp=[[0]*(c+1) for j in range(4)] for _ in range(k): rrr,ccc,v=MI() G[rrr][ccc]=v #print(G) #print(dp) for rr in range(1,r+1): for cc in range(1,c+1): if G[rr][cc]==0: for i in range(4): dp[i][cc]=max(dp[i][cc-1],dp[3][cc]) else: dp[0][cc]=max(dp[3][cc],dp[0][cc-1]) dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1]) dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc]) dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc]) #print(dp) print((dp[-1][-1])) if __name__ == "__main__": main()
57
57
1,237
1,139
import sys input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**9) # from functools import lru_cache def RD(): return input().rstrip().decode() def II(): return int(eval(input())) def FI(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MF(): return list(map(float, input().split())) def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def TI(): return tuple(map(int, input().split())) # rstrip().decode() def main(): r, c, k = MI() G = [[0] * (c + 1) for _ in range(r + 1)] dp = [[[0] * (c + 1) for i in range(r + 1)] for j in range(4)] for _ in range(k): rrr, ccc, v = MI() G[rrr][ccc] = v # print(G) # print(dp) for rr in range(1, r + 1): for cc in range(1, c + 1): if G[rr][cc] == 0: for i in range(4): dp[i][rr][cc] = max(dp[i][rr][cc - 1], dp[3][rr - 1][cc]) else: dp[0][rr][cc] = max(dp[3][rr - 1][cc], dp[0][rr][cc - 1]) dp[1][rr][cc] = max(dp[0][rr][cc] + G[rr][cc], dp[1][rr][cc - 1]) dp[2][rr][cc] = max( dp[1][rr][cc - 1] + G[rr][cc], dp[2][rr][cc - 1], dp[1][rr][cc] ) dp[3][rr][cc] = max( dp[2][rr][cc - 1] + G[rr][cc], dp[3][rr][cc - 1], dp[2][rr][cc] ) # print(dp) print((dp[-1][-1][-1])) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**9) # from functools import lru_cache def RD(): return input().rstrip().decode() def II(): return int(eval(input())) def FI(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MF(): return list(map(float, input().split())) def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def TI(): return tuple(map(int, input().split())) # rstrip().decode() def main(): r, c, k = MI() G = [[0] * (c + 1) for _ in range(r + 1)] dp = [[0] * (c + 1) for j in range(4)] for _ in range(k): rrr, ccc, v = MI() G[rrr][ccc] = v # print(G) # print(dp) for rr in range(1, r + 1): for cc in range(1, c + 1): if G[rr][cc] == 0: for i in range(4): dp[i][cc] = max(dp[i][cc - 1], dp[3][cc]) else: dp[0][cc] = max(dp[3][cc], dp[0][cc - 1]) dp[1][cc] = max(dp[0][cc] + G[rr][cc], dp[1][cc - 1]) dp[2][cc] = max(dp[1][cc - 1] + G[rr][cc], dp[2][cc - 1], dp[1][cc]) dp[3][cc] = max(dp[2][cc - 1] + G[rr][cc], dp[3][cc - 1], dp[2][cc]) # print(dp) print((dp[-1][-1])) if __name__ == "__main__": main()
false
0
[ "- dp = [[[0] * (c + 1) for i in range(r + 1)] for j in range(4)]", "+ dp = [[0] * (c + 1) for j in range(4)]", "- dp[i][rr][cc] = max(dp[i][rr][cc - 1], dp[3][rr - 1][cc])", "+ dp[i][cc] = max(dp[i][cc - 1], dp[3][cc])", "- dp[0][rr][cc] = max(dp[3][rr - 1][cc], dp[0][rr][cc - 1])", "- dp[1][rr][cc] = max(dp[0][rr][cc] + G[rr][cc], dp[1][rr][cc - 1])", "- dp[2][rr][cc] = max(", "- dp[1][rr][cc - 1] + G[rr][cc], dp[2][rr][cc - 1], dp[1][rr][cc]", "- )", "- dp[3][rr][cc] = max(", "- dp[2][rr][cc - 1] + G[rr][cc], dp[3][rr][cc - 1], dp[2][rr][cc]", "- )", "+ dp[0][cc] = max(dp[3][cc], dp[0][cc - 1])", "+ dp[1][cc] = max(dp[0][cc] + G[rr][cc], dp[1][cc - 1])", "+ dp[2][cc] = max(dp[1][cc - 1] + G[rr][cc], dp[2][cc - 1], dp[1][cc])", "+ dp[3][cc] = max(dp[2][cc - 1] + G[rr][cc], dp[3][cc - 1], dp[2][cc])", "- print((dp[-1][-1][-1]))", "+ print((dp[-1][-1]))" ]
false
0.040605
0.042287
0.960232
[ "s987624033", "s346682812" ]
u078042885
p00510
python
s224744505
s356691793
60
50
7,708
7,664
Accepted
Accepted
16.67
# -*- coding: utf-8 -*- n=int(eval(input())) m=int(eval(input())) ans=c=m for i in range(n): a,b=[int(a) for a in input().split()] if c<0: continue c+=a-b if ans<c: ans=c if c<0: ans=0 print(ans)
n=int(eval(input())) ans=c=m=int(eval(input())) for i in[0]*n: a,b=list(map(int,input().split())) if c<0:ans=0;break c+=a-b ans=max(ans,c) print(ans)
14
8
240
154
# -*- coding: utf-8 -*- n = int(eval(input())) m = int(eval(input())) ans = c = m for i in range(n): a, b = [int(a) for a in input().split()] if c < 0: continue c += a - b if ans < c: ans = c if c < 0: ans = 0 print(ans)
n = int(eval(input())) ans = c = m = int(eval(input())) for i in [0] * n: a, b = list(map(int, input().split())) if c < 0: ans = 0 break c += a - b ans = max(ans, c) print(ans)
false
42.857143
[ "-# -*- coding: utf-8 -*-", "-m = int(eval(input()))", "-ans = c = m", "-for i in range(n):", "- a, b = [int(a) for a in input().split()]", "- if c < 0:", "- continue", "- c += a - b", "- if ans < c:", "- ans = c", "+ans = c = m = int(eval(input()))", "+for i in [0] * n:", "+ a, b = list(map(int, input().split()))", "+ break", "+ c += a - b", "+ ans = max(ans, c)" ]
false
0.039346
0.038408
1.024413
[ "s224744505", "s356691793" ]
u644907318
p03001
python
s367993695
s738204584
163
75
38,256
61,700
Accepted
Accepted
53.99
W,H,x,y = list(map(int,input().split())) s = W*H/2 if W/2==x and H/2==y: print((s,1)) else: print((s,0))
W,H,x,y = list(map(int,input().split())) if x*2==W and y*2==H: z = 1 else: z = 0 print((W*H/2,z))
6
6
107
102
W, H, x, y = list(map(int, input().split())) s = W * H / 2 if W / 2 == x and H / 2 == y: print((s, 1)) else: print((s, 0))
W, H, x, y = list(map(int, input().split())) if x * 2 == W and y * 2 == H: z = 1 else: z = 0 print((W * H / 2, z))
false
0
[ "-s = W * H / 2", "-if W / 2 == x and H / 2 == y:", "- print((s, 1))", "+if x * 2 == W and y * 2 == H:", "+ z = 1", "- print((s, 0))", "+ z = 0", "+print((W * H / 2, z))" ]
false
0.075237
0.035072
2.145193
[ "s367993695", "s738204584" ]
u373047809
p04045
python
s618316776
s936422904
99
82
2,940
2,940
Accepted
Accepted
17.17
n,_,*d=open(0).read().split() n=int(n) while 1: if all(d not in str(n)for d in d):exit(print(n)) n+=1
n=int(input().split()[0]) a=set(eval(input())) while a&set(str(n)):n+=1 print(n)
5
4
107
77
n, _, *d = open(0).read().split() n = int(n) while 1: if all(d not in str(n) for d in d): exit(print(n)) n += 1
n = int(input().split()[0]) a = set(eval(input())) while a & set(str(n)): n += 1 print(n)
false
20
[ "-n, _, *d = open(0).read().split()", "-n = int(n)", "-while 1:", "- if all(d not in str(n) for d in d):", "- exit(print(n))", "+n = int(input().split()[0])", "+a = set(eval(input()))", "+while a & set(str(n)):", "+print(n)" ]
false
0.04962
0.048521
1.022642
[ "s618316776", "s936422904" ]
u017810624
p03846
python
s144557236
s074563927
173
122
14,008
14,004
Accepted
Accepted
29.48
n=int(eval(input())) a=list(map(int,input().split())) a.sort() f=1 if n%2==0: for i in range(n): if i%2==0 and i+1!=a[i] or i%2==1 and i!=a[i]: f=0 break else: for i in range(n): if i%2==1 and i+1!=a[i] or i%2==0 and i!=a[i]: f=0 break if f==0:print((0)) else: ans=1 for j in range(n//2): ans*=2 print((ans%(10**9+7)))
n=int(eval(input())) a=list(map(int,input().split())) a.sort() f=1 for i in range(n): if i%2==n%2 and i+1!=a[i] or i%2==(n+1)%2 and i!=a[i]: f=0 break if f==0:print((0)) else:print(((2**(n//2))%(10**9+7)))
20
10
373
214
n = int(eval(input())) a = list(map(int, input().split())) a.sort() f = 1 if n % 2 == 0: for i in range(n): if i % 2 == 0 and i + 1 != a[i] or i % 2 == 1 and i != a[i]: f = 0 break else: for i in range(n): if i % 2 == 1 and i + 1 != a[i] or i % 2 == 0 and i != a[i]: f = 0 break if f == 0: print((0)) else: ans = 1 for j in range(n // 2): ans *= 2 print((ans % (10**9 + 7)))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() f = 1 for i in range(n): if i % 2 == n % 2 and i + 1 != a[i] or i % 2 == (n + 1) % 2 and i != a[i]: f = 0 break if f == 0: print((0)) else: print(((2 ** (n // 2)) % (10**9 + 7)))
false
50
[ "-if n % 2 == 0:", "- for i in range(n):", "- if i % 2 == 0 and i + 1 != a[i] or i % 2 == 1 and i != a[i]:", "- f = 0", "- break", "-else:", "- for i in range(n):", "- if i % 2 == 1 and i + 1 != a[i] or i % 2 == 0 and i != a[i]:", "- f = 0", "- break", "+for i in range(n):", "+ if i % 2 == n % 2 and i + 1 != a[i] or i % 2 == (n + 1) % 2 and i != a[i]:", "+ f = 0", "+ break", "- ans = 1", "- for j in range(n // 2):", "- ans *= 2", "- print((ans % (10**9 + 7)))", "+ print(((2 ** (n // 2)) % (10**9 + 7)))" ]
false
0.035782
0.035566
1.006057
[ "s144557236", "s074563927" ]
u133936772
p03816
python
s525034139
s086198132
65
52
21,824
20,208
Accepted
Accepted
20
n,*l=list(map(int,open(0).read().split())) from collections import * c=Counter(l) print((len(c)-sum(1-v%2 for v in list(c.values()))%2))
_,*l=list(map(int,open(0).read().split())) c=len(set(l)) print((c-1+c%2))
4
3
125
67
n, *l = list(map(int, open(0).read().split())) from collections import * c = Counter(l) print((len(c) - sum(1 - v % 2 for v in list(c.values())) % 2))
_, *l = list(map(int, open(0).read().split())) c = len(set(l)) print((c - 1 + c % 2))
false
25
[ "-n, *l = list(map(int, open(0).read().split()))", "-from collections import *", "-", "-c = Counter(l)", "-print((len(c) - sum(1 - v % 2 for v in list(c.values())) % 2))", "+_, *l = list(map(int, open(0).read().split()))", "+c = len(set(l))", "+print((c - 1 + c % 2))" ]
false
0.00783
0.038659
0.202553
[ "s525034139", "s086198132" ]
u440566786
p02862
python
s755422926
s669423205
251
200
49,136
49,008
Accepted
Accepted
20.32
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def modfact(n): fact=[1]*(n+1) invfact=[1]*(n+1) for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD invfact[n]=pow(fact[n],MOD-2,MOD) for i in range(n-1,-1,-1): invfact[i]=invfact[i+1]*(i+1)%MOD return fact,invfact def resolve(): x,y=list(map(int,input().split())) if((x+y)%3): print((0)) return z=(x+y)//3 if(x-z<0 or y-z<0): print((0)) return fact,invfact=modfact(z) print((fact[z]*invfact[x-z]%MOD*invfact[y-z]%MOD)) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() class modfact(object): def __init__(self,n): fact=[1]*(n+1) invfact=[1]*(n+1) for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD invfact[n]=pow(fact[n],MOD-2,MOD) for i in range(n-1,-1,-1): invfact[i]=invfact[i+1]*(i+1)%MOD self.__fact=fact self.__invfact=invfact def fact(self,n): return self.__fact[n] def invfact(self,n): return self.__invfact[n] def comb(self,n,k): if(k<0 or n-k<0): return 0 return (self.fact(n)*self.invfact(k)*self.invfact(n-k))%MOD def resolve(): x,y=list(map(int,input().split())) if((x+y)%3): print((0)) return z=(x+y)//3 mf=modfact(z) print((mf.comb(z,x-z))) resolve()
30
37
664
905
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def modfact(n): fact = [1] * (n + 1) invfact = [1] * (n + 1) for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD invfact[n] = pow(fact[n], MOD - 2, MOD) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD return fact, invfact def resolve(): x, y = list(map(int, input().split())) if (x + y) % 3: print((0)) return z = (x + y) // 3 if x - z < 0 or y - z < 0: print((0)) return fact, invfact = modfact(z) print((fact[z] * invfact[x - z] % MOD * invfact[y - z] % MOD)) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() class modfact(object): def __init__(self, n): fact = [1] * (n + 1) invfact = [1] * (n + 1) for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD invfact[n] = pow(fact[n], MOD - 2, MOD) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD self.__fact = fact self.__invfact = invfact def fact(self, n): return self.__fact[n] def invfact(self, n): return self.__invfact[n] def comb(self, n, k): if k < 0 or n - k < 0: return 0 return (self.fact(n) * self.invfact(k) * self.invfact(n - k)) % MOD def resolve(): x, y = list(map(int, input().split())) if (x + y) % 3: print((0)) return z = (x + y) // 3 mf = modfact(z) print((mf.comb(z, x - z))) resolve()
false
18.918919
[ "-def modfact(n):", "- fact = [1] * (n + 1)", "- invfact = [1] * (n + 1)", "- for i in range(1, n + 1):", "- fact[i] = i * fact[i - 1] % MOD", "- invfact[n] = pow(fact[n], MOD - 2, MOD)", "- for i in range(n - 1, -1, -1):", "- invfact[i] = invfact[i + 1] * (i + 1) % MOD", "- return fact, invfact", "+class modfact(object):", "+ def __init__(self, n):", "+ fact = [1] * (n + 1)", "+ invfact = [1] * (n + 1)", "+ for i in range(1, n + 1):", "+ fact[i] = i * fact[i - 1] % MOD", "+ invfact[n] = pow(fact[n], MOD - 2, MOD)", "+ for i in range(n - 1, -1, -1):", "+ invfact[i] = invfact[i + 1] * (i + 1) % MOD", "+ self.__fact = fact", "+ self.__invfact = invfact", "+", "+ def fact(self, n):", "+ return self.__fact[n]", "+", "+ def invfact(self, n):", "+ return self.__invfact[n]", "+", "+ def comb(self, n, k):", "+ if k < 0 or n - k < 0:", "+ return 0", "+ return (self.fact(n) * self.invfact(k) * self.invfact(n - k)) % MOD", "- if x - z < 0 or y - z < 0:", "- print((0))", "- return", "- fact, invfact = modfact(z)", "- print((fact[z] * invfact[x - z] % MOD * invfact[y - z] % MOD))", "+ mf = modfact(z)", "+ print((mf.comb(z, x - z)))" ]
false
0.165233
0.224656
0.735493
[ "s755422926", "s669423205" ]
u562935282
p03274
python
s931165064
s610108959
114
63
15,024
14,384
Accepted
Accepted
44.74
inf = float('inf') N, K = list(map(int, input().split())) x = tuple(map(int, input().split())) m, p = [], [] for xx in x: if xx > 0: p.append(xx) elif xx < 0: m.append(-xx) else: K -= 1 if K == 0: print((0)) exit() m.sort() lp = len(p) lm = len(m) ans = inf for from_minus in range(min(lm, K) + 1): from_plus = K - from_minus if from_plus > lp: continue if from_minus == 0: ans = min(ans, p[K - 1]) elif from_minus == K: ans = min(ans, m[K - 1]) else: ans = min(ans, p[from_plus - 1] * 2 + m[from_minus - 1]) ans = min(ans, m[from_minus - 1] * 2 + p[from_plus - 1]) print(ans)
def main(): N, K = list(map(int, input().split())) *x, = list(map(int, input().split())) ans = 3 * 10 ** 8 for left, right in zip(x, x[K - 1:]): if left * right < 0: ans = min(ans, right - left + min(-left, right)) else: ans = min(ans, -left if left < 0 else right) print(ans) if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
33
32
732
731
inf = float("inf") N, K = list(map(int, input().split())) x = tuple(map(int, input().split())) m, p = [], [] for xx in x: if xx > 0: p.append(xx) elif xx < 0: m.append(-xx) else: K -= 1 if K == 0: print((0)) exit() m.sort() lp = len(p) lm = len(m) ans = inf for from_minus in range(min(lm, K) + 1): from_plus = K - from_minus if from_plus > lp: continue if from_minus == 0: ans = min(ans, p[K - 1]) elif from_minus == K: ans = min(ans, m[K - 1]) else: ans = min(ans, p[from_plus - 1] * 2 + m[from_minus - 1]) ans = min(ans, m[from_minus - 1] * 2 + p[from_plus - 1]) print(ans)
def main(): N, K = list(map(int, input().split())) (*x,) = list(map(int, input().split())) ans = 3 * 10**8 for left, right in zip(x, x[K - 1 :]): if left * right < 0: ans = min(ans, right - left + min(-left, right)) else: ans = min(ans, -left if left < 0 else right) print(ans) if __name__ == "__main__": main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
false
3.030303
[ "-inf = float(\"inf\")", "-N, K = list(map(int, input().split()))", "-x = tuple(map(int, input().split()))", "-m, p = [], []", "-for xx in x:", "- if xx > 0:", "- p.append(xx)", "- elif xx < 0:", "- m.append(-xx)", "- else:", "- K -= 1", "- if K == 0:", "- print((0))", "- exit()", "-m.sort()", "-lp = len(p)", "-lm = len(m)", "-ans = inf", "-for from_minus in range(min(lm, K) + 1):", "- from_plus = K - from_minus", "- if from_plus > lp:", "- continue", "- if from_minus == 0:", "- ans = min(ans, p[K - 1])", "- elif from_minus == K:", "- ans = min(ans, m[K - 1])", "- else:", "- ans = min(ans, p[from_plus - 1] * 2 + m[from_minus - 1])", "- ans = min(ans, m[from_minus - 1] * 2 + p[from_plus - 1])", "-print(ans)", "+def main():", "+ N, K = list(map(int, input().split()))", "+ (*x,) = list(map(int, input().split()))", "+ ans = 3 * 10**8", "+ for left, right in zip(x, x[K - 1 :]):", "+ if left * right < 0:", "+ ans = min(ans, right - left + min(-left, right))", "+ else:", "+ ans = min(ans, -left if left < 0 else right)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()", "+# import sys", "+# input = sys.stdin.readline", "+#", "+# sys.setrecursionlimit(10 ** 7)", "+#", "+# (int(x)-1 for x in input().split())", "+# rstrip()", "+#", "+# def binary_search(*, ok, ng, func):", "+# while abs(ok - ng) > 1:", "+# mid = (ok + ng) // 2", "+# if func(mid):", "+# ok = mid", "+# else:", "+# ng = mid", "+# return ok" ]
false
0.0368
0.044288
0.830915
[ "s931165064", "s610108959" ]
u690536347
p03127
python
s622648352
s973891514
252
78
70,936
16,240
Accepted
Accepted
69.05
n=int(eval(input())) a=set(map(int,input().split())) while len(a)!=1: t=min(a) a=set(i for i in [x%t if x!=t else t for x in a] if i) print((a.pop()))
from fractions import gcd from functools import reduce _=eval(input()) *a,=list(map(int,input().split())) print((reduce(gcd,a)))
8
5
158
118
n = int(eval(input())) a = set(map(int, input().split())) while len(a) != 1: t = min(a) a = set(i for i in [x % t if x != t else t for x in a] if i) print((a.pop()))
from fractions import gcd from functools import reduce _ = eval(input()) (*a,) = list(map(int, input().split())) print((reduce(gcd, a)))
false
37.5
[ "-n = int(eval(input()))", "-a = set(map(int, input().split()))", "-while len(a) != 1:", "- t = min(a)", "- a = set(i for i in [x % t if x != t else t for x in a] if i)", "-print((a.pop()))", "+from fractions import gcd", "+from functools import reduce", "+", "+_ = eval(input())", "+(*a,) = list(map(int, input().split()))", "+print((reduce(gcd, a)))" ]
false
0.046092
0.05863
0.786141
[ "s622648352", "s973891514" ]
u310233294
p03112
python
s418788066
s803000174
1,132
907
16,144
16,776
Accepted
Accepted
19.88
import bisect A, B, Q = list(map(int, input().split())) s = [-10 ** 12] + [int(eval(input())) for _ in range(A)] + [10 ** 12] t = [-10 ** 12] + [int(eval(input())) for _ in range(B)] + [10 ** 12] x = [int(eval(input())) for _ in range(Q)] for i in x: si = bisect.bisect_left(s, i) ti = bisect.bisect_left(t, i) s1, s2 = s[si - 1], s[si] t1, t2 = t[ti - 1], t[ti] ans = 10 ** 12 for ss in [s1, s2]: for tt in [t1, t2]: ans = min(ans, abs(i - ss) + abs(ss - tt), abs(i - tt) + abs(ss - tt)) print(ans)
import bisect A, B, Q = list(map(int, input().split())) S = [int(eval(input())) for _ in range(A)] T = [int(eval(input())) for _ in range(B)] X = [int(eval(input())) for _ in range(Q)] S = [-10 ** 12] + S + [10 ** 12] T = [-10 ** 12] + T + [10 ** 12] for x in X: si = bisect.bisect_right(S, x) ti = bisect.bisect_right(T, x) Ls, Rs = x - S[si - 1], -x + S[si] Lt, Rt = x - T[ti - 1], -x + T[ti] ans = min(Ls * 2 + Rt, Ls + Rt * 2, Lt * 2 + Rs, Lt + Rs * 2, max(Ls, Lt), max(Rs, Rt)) print(ans)
18
17
564
526
import bisect A, B, Q = list(map(int, input().split())) s = [-(10**12)] + [int(eval(input())) for _ in range(A)] + [10**12] t = [-(10**12)] + [int(eval(input())) for _ in range(B)] + [10**12] x = [int(eval(input())) for _ in range(Q)] for i in x: si = bisect.bisect_left(s, i) ti = bisect.bisect_left(t, i) s1, s2 = s[si - 1], s[si] t1, t2 = t[ti - 1], t[ti] ans = 10**12 for ss in [s1, s2]: for tt in [t1, t2]: ans = min(ans, abs(i - ss) + abs(ss - tt), abs(i - tt) + abs(ss - tt)) print(ans)
import bisect A, B, Q = list(map(int, input().split())) S = [int(eval(input())) for _ in range(A)] T = [int(eval(input())) for _ in range(B)] X = [int(eval(input())) for _ in range(Q)] S = [-(10**12)] + S + [10**12] T = [-(10**12)] + T + [10**12] for x in X: si = bisect.bisect_right(S, x) ti = bisect.bisect_right(T, x) Ls, Rs = x - S[si - 1], -x + S[si] Lt, Rt = x - T[ti - 1], -x + T[ti] ans = min( Ls * 2 + Rt, Ls + Rt * 2, Lt * 2 + Rs, Lt + Rs * 2, max(Ls, Lt), max(Rs, Rt) ) print(ans)
false
5.555556
[ "-s = [-(10**12)] + [int(eval(input())) for _ in range(A)] + [10**12]", "-t = [-(10**12)] + [int(eval(input())) for _ in range(B)] + [10**12]", "-x = [int(eval(input())) for _ in range(Q)]", "-for i in x:", "- si = bisect.bisect_left(s, i)", "- ti = bisect.bisect_left(t, i)", "- s1, s2 = s[si - 1], s[si]", "- t1, t2 = t[ti - 1], t[ti]", "- ans = 10**12", "- for ss in [s1, s2]:", "- for tt in [t1, t2]:", "- ans = min(ans, abs(i - ss) + abs(ss - tt), abs(i - tt) + abs(ss - tt))", "+S = [int(eval(input())) for _ in range(A)]", "+T = [int(eval(input())) for _ in range(B)]", "+X = [int(eval(input())) for _ in range(Q)]", "+S = [-(10**12)] + S + [10**12]", "+T = [-(10**12)] + T + [10**12]", "+for x in X:", "+ si = bisect.bisect_right(S, x)", "+ ti = bisect.bisect_right(T, x)", "+ Ls, Rs = x - S[si - 1], -x + S[si]", "+ Lt, Rt = x - T[ti - 1], -x + T[ti]", "+ ans = min(", "+ Ls * 2 + Rt, Ls + Rt * 2, Lt * 2 + Rs, Lt + Rs * 2, max(Ls, Lt), max(Rs, Rt)", "+ )" ]
false
0.146636
0.107775
1.360582
[ "s418788066", "s803000174" ]
u893063840
p03649
python
s232333716
s026889140
484
199
3,060
12,504
Accepted
Accepted
58.88
n = int(eval(input())) a = list(map(int, input().split())) i = 0 ans = 0 while max(a) >= n: if a[i] >= n: cnt = a[i] // n ans += cnt a[i] -= n * cnt for j in range(n): if j == i: continue a[j] += cnt i = (i + 1) % n print(ans)
import numpy as np n = int(eval(input())) a = np.array(input().split(), np.int64) def check(x): cnt = np.maximum((a + x + 1) // (n + 1), 0) return cnt.sum() <= x l = -1 r = 10 ** 18 while r - l > 1: m = (l + r) // 2 if check(m): r = m else: l = m for i in range(max(r - n * n, 0), r + 1): if check(i): print(i) exit()
18
25
321
399
n = int(eval(input())) a = list(map(int, input().split())) i = 0 ans = 0 while max(a) >= n: if a[i] >= n: cnt = a[i] // n ans += cnt a[i] -= n * cnt for j in range(n): if j == i: continue a[j] += cnt i = (i + 1) % n print(ans)
import numpy as np n = int(eval(input())) a = np.array(input().split(), np.int64) def check(x): cnt = np.maximum((a + x + 1) // (n + 1), 0) return cnt.sum() <= x l = -1 r = 10**18 while r - l > 1: m = (l + r) // 2 if check(m): r = m else: l = m for i in range(max(r - n * n, 0), r + 1): if check(i): print(i) exit()
false
28
[ "+import numpy as np", "+", "-a = list(map(int, input().split()))", "-i = 0", "-ans = 0", "-while max(a) >= n:", "- if a[i] >= n:", "- cnt = a[i] // n", "- ans += cnt", "- a[i] -= n * cnt", "- for j in range(n):", "- if j == i:", "- continue", "- a[j] += cnt", "- i = (i + 1) % n", "-print(ans)", "+a = np.array(input().split(), np.int64)", "+", "+", "+def check(x):", "+ cnt = np.maximum((a + x + 1) // (n + 1), 0)", "+ return cnt.sum() <= x", "+", "+", "+l = -1", "+r = 10**18", "+while r - l > 1:", "+ m = (l + r) // 2", "+ if check(m):", "+ r = m", "+ else:", "+ l = m", "+for i in range(max(r - n * n, 0), r + 1):", "+ if check(i):", "+ print(i)", "+ exit()" ]
false
0.11994
0.466044
0.257359
[ "s232333716", "s026889140" ]
u673361376
p03379
python
s859346018
s256668642
1,701
335
128,084
26,016
Accepted
Accepted
80.31
N = int(input()) X = sorted([[x,i] for i, x in enumerate(map(int,input().split()))]) med1,med2 = X[(N-1)//2][0], X[(N-1)//2+1][0] ans = [] for idx1, x in enumerate(X): if idx1 <= (N-1)//2: ans.append([x[1],med2]) else: ans.append([x[1],med1]) #print(i) [print(med) for i, med in sorted(ans)]
N = int(eval(input())) X = list(map(int, input().split())) sorted_X = sorted(X) med_options = [sorted_X[N//2-1], sorted_X[N//2]] for i in range(N): if X[i] <= med_options[0]: print((med_options[1])) elif med_options[1] <= X[i]: print((med_options[0]))
9
10
305
276
N = int(input()) X = sorted([[x, i] for i, x in enumerate(map(int, input().split()))]) med1, med2 = X[(N - 1) // 2][0], X[(N - 1) // 2 + 1][0] ans = [] for idx1, x in enumerate(X): if idx1 <= (N - 1) // 2: ans.append([x[1], med2]) else: ans.append([x[1], med1]) # print(i) [print(med) for i, med in sorted(ans)]
N = int(eval(input())) X = list(map(int, input().split())) sorted_X = sorted(X) med_options = [sorted_X[N // 2 - 1], sorted_X[N // 2]] for i in range(N): if X[i] <= med_options[0]: print((med_options[1])) elif med_options[1] <= X[i]: print((med_options[0]))
false
10
[ "-N = int(input())", "-X = sorted([[x, i] for i, x in enumerate(map(int, input().split()))])", "-med1, med2 = X[(N - 1) // 2][0], X[(N - 1) // 2 + 1][0]", "-ans = []", "-for idx1, x in enumerate(X):", "- if idx1 <= (N - 1) // 2:", "- ans.append([x[1], med2])", "- else:", "- ans.append([x[1], med1])", "- # print(i)", "-[print(med) for i, med in sorted(ans)]", "+N = int(eval(input()))", "+X = list(map(int, input().split()))", "+sorted_X = sorted(X)", "+med_options = [sorted_X[N // 2 - 1], sorted_X[N // 2]]", "+for i in range(N):", "+ if X[i] <= med_options[0]:", "+ print((med_options[1]))", "+ elif med_options[1] <= X[i]:", "+ print((med_options[0]))" ]
false
0.078389
0.04064
1.928869
[ "s859346018", "s256668642" ]
u413165887
p03128
python
s986073025
s704529108
49
38
3,700
4,084
Accepted
Accepted
22.45
n , m = list(map(int, input().split(' '))) s = [0,2,5,5,4,5,6,3,7,6] a = list(map(int, input().split(' '))) r = [] for i in range(len(a)): r.append([s[a[i]],a[i]]) r.sort() d = [-1]*(n+1) d[0] = 0 for i in range(1,n+1): j = 0 while j < len(a): if i-s[r[j][1]] < 0: j += 1 elif d[i-s[r[j][1]]] >= 0: d[i] = d[i-s[r[j][1]]] +1 break else: j+= 1 result = [] a.sort(reverse = True) while n > 0: j = 0 while j < len(a): if n < s[a[j]]: j += 1 elif d[n-s[a[j]]] +1 == d[n]: result.append(a[j]) n -= s[a[j]] break else: j += 1 print((''.join(list(map(str, result)))))
def main(): n, m = list(map(int, input().split(' '))) a = list(map(int, input().split(' '))) b = [0,2,5,5,4,5,6,3,7,6] c = [[b[i], -i] for i in a] c.sort() result = [[] for _ in range(n+1)] dp = [-1]*(n+1) dp[0] = 0 for i in range(1, n+1): for j in c: if i-j[0] >= 0: if dp[i-j[0]] >= 0: dp[i] = dp[i-j[0]] +1 break c = [[-x[1], x[0]] for x in c] c.sort(reverse = True) result = [] i = n while i > 0: j = 0 while j < len(c): if i-c[j][1] >= 0: if dp[i-c[j][1]] + 1 == dp[i]: result.append(c[j][0]) i -= c[j][1] j = len(c) else: j += 1 else: j += 1 print((''.join(map(str, result)))) if __name__ =='__main__': main()
33
34
760
948
n, m = list(map(int, input().split(" "))) s = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] a = list(map(int, input().split(" "))) r = [] for i in range(len(a)): r.append([s[a[i]], a[i]]) r.sort() d = [-1] * (n + 1) d[0] = 0 for i in range(1, n + 1): j = 0 while j < len(a): if i - s[r[j][1]] < 0: j += 1 elif d[i - s[r[j][1]]] >= 0: d[i] = d[i - s[r[j][1]]] + 1 break else: j += 1 result = [] a.sort(reverse=True) while n > 0: j = 0 while j < len(a): if n < s[a[j]]: j += 1 elif d[n - s[a[j]]] + 1 == d[n]: result.append(a[j]) n -= s[a[j]] break else: j += 1 print(("".join(list(map(str, result)))))
def main(): n, m = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) b = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] c = [[b[i], -i] for i in a] c.sort() result = [[] for _ in range(n + 1)] dp = [-1] * (n + 1) dp[0] = 0 for i in range(1, n + 1): for j in c: if i - j[0] >= 0: if dp[i - j[0]] >= 0: dp[i] = dp[i - j[0]] + 1 break c = [[-x[1], x[0]] for x in c] c.sort(reverse=True) result = [] i = n while i > 0: j = 0 while j < len(c): if i - c[j][1] >= 0: if dp[i - c[j][1]] + 1 == dp[i]: result.append(c[j][0]) i -= c[j][1] j = len(c) else: j += 1 else: j += 1 print(("".join(map(str, result)))) if __name__ == "__main__": main()
false
2.941176
[ "-n, m = list(map(int, input().split(\" \")))", "-s = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "-a = list(map(int, input().split(\" \")))", "-r = []", "-for i in range(len(a)):", "- r.append([s[a[i]], a[i]])", "-r.sort()", "-d = [-1] * (n + 1)", "-d[0] = 0", "-for i in range(1, n + 1):", "- j = 0", "- while j < len(a):", "- if i - s[r[j][1]] < 0:", "- j += 1", "- elif d[i - s[r[j][1]]] >= 0:", "- d[i] = d[i - s[r[j][1]]] + 1", "- break", "- else:", "- j += 1", "-result = []", "-a.sort(reverse=True)", "-while n > 0:", "- j = 0", "- while j < len(a):", "- if n < s[a[j]]:", "- j += 1", "- elif d[n - s[a[j]]] + 1 == d[n]:", "- result.append(a[j])", "- n -= s[a[j]]", "- break", "- else:", "- j += 1", "-print((\"\".join(list(map(str, result)))))", "+def main():", "+ n, m = list(map(int, input().split(\" \")))", "+ a = list(map(int, input().split(\" \")))", "+ b = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]", "+ c = [[b[i], -i] for i in a]", "+ c.sort()", "+ result = [[] for _ in range(n + 1)]", "+ dp = [-1] * (n + 1)", "+ dp[0] = 0", "+ for i in range(1, n + 1):", "+ for j in c:", "+ if i - j[0] >= 0:", "+ if dp[i - j[0]] >= 0:", "+ dp[i] = dp[i - j[0]] + 1", "+ break", "+ c = [[-x[1], x[0]] for x in c]", "+ c.sort(reverse=True)", "+ result = []", "+ i = n", "+ while i > 0:", "+ j = 0", "+ while j < len(c):", "+ if i - c[j][1] >= 0:", "+ if dp[i - c[j][1]] + 1 == dp[i]:", "+ result.append(c[j][0])", "+ i -= c[j][1]", "+ j = len(c)", "+ else:", "+ j += 1", "+ else:", "+ j += 1", "+ print((\"\".join(map(str, result))))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.041721
0.039553
1.054804
[ "s986073025", "s704529108" ]
u353797797
p03167
python
s925600636
s822510829
710
565
43,708
43,616
Accepted
Accepted
20.42
from itertools import * import sys md=10**9+7 mis=list(map(int,sys.stdin.readline().split())) h,w=mis t=[[0]*(w+1) for _ in range(h+1)] s=[] for _ in range(h): s+=[eval(input())] for i,j in product(list(range(h)),list(range(w))): if i==0 and j==0: t[i+1][j+1]=1 elif s[i][j]==".": t[i+1][j+1]=(t[i][j+1]+t[i+1][j])%md else: t[i+1][j+1]=0 print((t[-1][-1]))
md = 10 ** 9 + 7 h, w = list(map(int, input().split())) a = [eval(input()) for _ in range(h)] t = [[1] * w for _ in range(h)] for i, ai in enumerate(a): ti = t[i] for j, aij in enumerate(ai): if aij == "#": ti[j] = 0 else: if j == 0: if i > 0: ti[j] = t[i - 1][j] elif i == 0: if j > 0: ti[j] = ti[j - 1] else: ti[j] = (ti[j - 1] + t[i - 1][j]) % md print((t[-1][-1]))
19
19
391
533
from itertools import * import sys md = 10**9 + 7 mis = list(map(int, sys.stdin.readline().split())) h, w = mis t = [[0] * (w + 1) for _ in range(h + 1)] s = [] for _ in range(h): s += [eval(input())] for i, j in product(list(range(h)), list(range(w))): if i == 0 and j == 0: t[i + 1][j + 1] = 1 elif s[i][j] == ".": t[i + 1][j + 1] = (t[i][j + 1] + t[i + 1][j]) % md else: t[i + 1][j + 1] = 0 print((t[-1][-1]))
md = 10**9 + 7 h, w = list(map(int, input().split())) a = [eval(input()) for _ in range(h)] t = [[1] * w for _ in range(h)] for i, ai in enumerate(a): ti = t[i] for j, aij in enumerate(ai): if aij == "#": ti[j] = 0 else: if j == 0: if i > 0: ti[j] = t[i - 1][j] elif i == 0: if j > 0: ti[j] = ti[j - 1] else: ti[j] = (ti[j - 1] + t[i - 1][j]) % md print((t[-1][-1]))
false
0
[ "-from itertools import *", "-import sys", "-", "-mis = list(map(int, sys.stdin.readline().split()))", "-h, w = mis", "-t = [[0] * (w + 1) for _ in range(h + 1)]", "-s = []", "-for _ in range(h):", "- s += [eval(input())]", "-for i, j in product(list(range(h)), list(range(w))):", "- if i == 0 and j == 0:", "- t[i + 1][j + 1] = 1", "- elif s[i][j] == \".\":", "- t[i + 1][j + 1] = (t[i][j + 1] + t[i + 1][j]) % md", "- else:", "- t[i + 1][j + 1] = 0", "+h, w = list(map(int, input().split()))", "+a = [eval(input()) for _ in range(h)]", "+t = [[1] * w for _ in range(h)]", "+for i, ai in enumerate(a):", "+ ti = t[i]", "+ for j, aij in enumerate(ai):", "+ if aij == \"#\":", "+ ti[j] = 0", "+ else:", "+ if j == 0:", "+ if i > 0:", "+ ti[j] = t[i - 1][j]", "+ elif i == 0:", "+ if j > 0:", "+ ti[j] = ti[j - 1]", "+ else:", "+ ti[j] = (ti[j - 1] + t[i - 1][j]) % md" ]
false
0.007051
0.073226
0.096296
[ "s925600636", "s822510829" ]
u368780724
p03452
python
s111933679
s535766825
1,305
489
10,024
49,624
Accepted
Accepted
62.53
def inpl(): return [int(i) for i in input().split()] def find(x): if par[x] == x: return x else: par[x],dist[x] = find(par[x]),dist[x]+dist[par[x]] return par[x] N, M = inpl() par = list(range(N+1)) dist = [0 for _ in range(N+1)] for _ in range(M): l, r, d = inpl() fl = find(l) fr = find(r) if fl != fr: par[fr] = fl dist[fr] = d + dist[l] - dist[r] elif d + dist[l] - dist[r] != 0: print('No') break else: print('Yes')
import sys readline = sys.stdin.readline class UFP(): def __init__(self, num): self.par = [-1]*num self.dist = [0]*num def find(self, x): if self.par[x] < 0: return x else: res = 0 xo = x while self.par[x] >= 0: res += self.dist[x] x = self.par[x] self.dist[xo] = res self.par[xo] = x return x def union(self, x, y, d): rx = self.find(x) ry = self.find(y) if rx != ry: if self.par[rx] > self.par[ry]: rx, ry = ry, rx x, y = y, x d = -d self.par[rx] += self.par[ry] self.par[ry] = rx self.dist[ry] = d + self.dist[x] - self.dist[y] return True else: if d + self.dist[x] - self.dist[y]: return False return True N, M = list(map(int, readline().split())) T = UFP(N) ans = 'No' for _ in range(M): l, r, d = list(map(int, readline().split())) l -= 1 r -= 1 if not T.union(l, r, d): break else: ans = 'Yes' print(ans)
23
48
532
1,221
def inpl(): return [int(i) for i in input().split()] def find(x): if par[x] == x: return x else: par[x], dist[x] = find(par[x]), dist[x] + dist[par[x]] return par[x] N, M = inpl() par = list(range(N + 1)) dist = [0 for _ in range(N + 1)] for _ in range(M): l, r, d = inpl() fl = find(l) fr = find(r) if fl != fr: par[fr] = fl dist[fr] = d + dist[l] - dist[r] elif d + dist[l] - dist[r] != 0: print("No") break else: print("Yes")
import sys readline = sys.stdin.readline class UFP: def __init__(self, num): self.par = [-1] * num self.dist = [0] * num def find(self, x): if self.par[x] < 0: return x else: res = 0 xo = x while self.par[x] >= 0: res += self.dist[x] x = self.par[x] self.dist[xo] = res self.par[xo] = x return x def union(self, x, y, d): rx = self.find(x) ry = self.find(y) if rx != ry: if self.par[rx] > self.par[ry]: rx, ry = ry, rx x, y = y, x d = -d self.par[rx] += self.par[ry] self.par[ry] = rx self.dist[ry] = d + self.dist[x] - self.dist[y] return True else: if d + self.dist[x] - self.dist[y]: return False return True N, M = list(map(int, readline().split())) T = UFP(N) ans = "No" for _ in range(M): l, r, d = list(map(int, readline().split())) l -= 1 r -= 1 if not T.union(l, r, d): break else: ans = "Yes" print(ans)
false
52.083333
[ "-def inpl():", "- return [int(i) for i in input().split()]", "+import sys", "+", "+readline = sys.stdin.readline", "-def find(x):", "- if par[x] == x:", "- return x", "- else:", "- par[x], dist[x] = find(par[x]), dist[x] + dist[par[x]]", "- return par[x]", "+class UFP:", "+ def __init__(self, num):", "+ self.par = [-1] * num", "+ self.dist = [0] * num", "+", "+ def find(self, x):", "+ if self.par[x] < 0:", "+ return x", "+ else:", "+ res = 0", "+ xo = x", "+ while self.par[x] >= 0:", "+ res += self.dist[x]", "+ x = self.par[x]", "+ self.dist[xo] = res", "+ self.par[xo] = x", "+ return x", "+", "+ def union(self, x, y, d):", "+ rx = self.find(x)", "+ ry = self.find(y)", "+ if rx != ry:", "+ if self.par[rx] > self.par[ry]:", "+ rx, ry = ry, rx", "+ x, y = y, x", "+ d = -d", "+ self.par[rx] += self.par[ry]", "+ self.par[ry] = rx", "+ self.dist[ry] = d + self.dist[x] - self.dist[y]", "+ return True", "+ else:", "+ if d + self.dist[x] - self.dist[y]:", "+ return False", "+ return True", "-N, M = inpl()", "-par = list(range(N + 1))", "-dist = [0 for _ in range(N + 1)]", "+N, M = list(map(int, readline().split()))", "+T = UFP(N)", "+ans = \"No\"", "- l, r, d = inpl()", "- fl = find(l)", "- fr = find(r)", "- if fl != fr:", "- par[fr] = fl", "- dist[fr] = d + dist[l] - dist[r]", "- elif d + dist[l] - dist[r] != 0:", "- print(\"No\")", "+ l, r, d = list(map(int, readline().split()))", "+ l -= 1", "+ r -= 1", "+ if not T.union(l, r, d):", "- print(\"Yes\")", "+ ans = \"Yes\"", "+print(ans)" ]
false
0.037852
0.041029
0.922562
[ "s111933679", "s535766825" ]
u411203878
p02873
python
s571761938
s965874665
280
109
113,140
100,808
Accepted
Accepted
61.07
s=list(eval(input())) right = [0] left = [0] count = 0 for i in range(len(s)): if s[i] == '<': count += 1 else: count = 0 right.append(count) count = 0 for i in range(len(s)-1,-1,-1): if s[i] == '>': count += 1 else: count = 0 left.append(count) left.reverse() ans = 0 for i in range(len(s)+1): ans += max(right[i],left[i]) print(ans)
S = list(eval(input())) left = [0]*(len(S)+1) right = [0]*(len(S)+1) for i in range(len(S)): if S[i] == '<': left[i+1] += 1+left[i] for i in range(len(S)-1,-1,-1): if S[i] == '>': right[i] = right[i+1]+1 ans = [0]*(len(S)+1) for i in range(len(S)+1): ans[i] = max(left[i],right[i]) print((sum(ans)))
27
18
419
341
s = list(eval(input())) right = [0] left = [0] count = 0 for i in range(len(s)): if s[i] == "<": count += 1 else: count = 0 right.append(count) count = 0 for i in range(len(s) - 1, -1, -1): if s[i] == ">": count += 1 else: count = 0 left.append(count) left.reverse() ans = 0 for i in range(len(s) + 1): ans += max(right[i], left[i]) print(ans)
S = list(eval(input())) left = [0] * (len(S) + 1) right = [0] * (len(S) + 1) for i in range(len(S)): if S[i] == "<": left[i + 1] += 1 + left[i] for i in range(len(S) - 1, -1, -1): if S[i] == ">": right[i] = right[i + 1] + 1 ans = [0] * (len(S) + 1) for i in range(len(S) + 1): ans[i] = max(left[i], right[i]) print((sum(ans)))
false
33.333333
[ "-s = list(eval(input()))", "-right = [0]", "-left = [0]", "-count = 0", "-for i in range(len(s)):", "- if s[i] == \"<\":", "- count += 1", "- else:", "- count = 0", "- right.append(count)", "-count = 0", "-for i in range(len(s) - 1, -1, -1):", "- if s[i] == \">\":", "- count += 1", "- else:", "- count = 0", "- left.append(count)", "-left.reverse()", "-ans = 0", "-for i in range(len(s) + 1):", "- ans += max(right[i], left[i])", "-print(ans)", "+S = list(eval(input()))", "+left = [0] * (len(S) + 1)", "+right = [0] * (len(S) + 1)", "+for i in range(len(S)):", "+ if S[i] == \"<\":", "+ left[i + 1] += 1 + left[i]", "+for i in range(len(S) - 1, -1, -1):", "+ if S[i] == \">\":", "+ right[i] = right[i + 1] + 1", "+ans = [0] * (len(S) + 1)", "+for i in range(len(S) + 1):", "+ ans[i] = max(left[i], right[i])", "+print((sum(ans)))" ]
false
0.146478
0.044548
3.288111
[ "s571761938", "s965874665" ]
u021019433
p02768
python
s189281759
s531889638
128
118
3,060
3,060
Accepted
Accepted
7.81
M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if i + 1 in (a, b): r -= c * pow(f, M - 2, M) print((r % M))
M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if a != i + 1 != b: continue r -= c * pow(f, M - 2, M) print((r % M))
10
11
218
230
M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if i + 1 in (a, b): r -= c * pow(f, M - 2, M) print((r % M))
M = 10**9 + 7 n, a, b = list(map(int, input().split())) r = pow(2, n, M) - 1 f = c = 1 for i in range(b): f = f * (i + 1) % M c = c * (n - i) % M if a != i + 1 != b: continue r -= c * pow(f, M - 2, M) print((r % M))
false
9.090909
[ "- if i + 1 in (a, b):", "- r -= c * pow(f, M - 2, M)", "+ if a != i + 1 != b:", "+ continue", "+ r -= c * pow(f, M - 2, M)" ]
false
0.409588
0.155624
2.631899
[ "s189281759", "s531889638" ]
u174273188
p02899
python
s798819935
s342937854
205
153
27,616
24,764
Accepted
Accepted
25.37
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) h = [] for i, ai in enumerate(a): h.append([i, ai]) h.sort(key=lambda x: x[1]) ans = " ".join([str(i + 1) for i, _ in h]) print(ans) if __name__ == "__main__": resolve()
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) b = sorted([(i, ai) for i, ai in enumerate(a)], key=lambda x: x[1]) print((" ".join([str(i + 1) for i, _ in b]))) if __name__ == "__main__": resolve()
13
9
292
247
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) h = [] for i, ai in enumerate(a): h.append([i, ai]) h.sort(key=lambda x: x[1]) ans = " ".join([str(i + 1) for i, _ in h]) print(ans) if __name__ == "__main__": resolve()
def resolve(): n = int(eval(input())) a = list(map(int, input().split())) b = sorted([(i, ai) for i, ai in enumerate(a)], key=lambda x: x[1]) print((" ".join([str(i + 1) for i, _ in b]))) if __name__ == "__main__": resolve()
false
30.769231
[ "- h = []", "- for i, ai in enumerate(a):", "- h.append([i, ai])", "- h.sort(key=lambda x: x[1])", "- ans = \" \".join([str(i + 1) for i, _ in h])", "- print(ans)", "+ b = sorted([(i, ai) for i, ai in enumerate(a)], key=lambda x: x[1])", "+ print((\" \".join([str(i + 1) for i, _ in b])))" ]
false
0.04233
0.07005
0.604281
[ "s798819935", "s342937854" ]
u909514237
p02585
python
s143407373
s169494559
759
687
77,084
80,984
Accepted
Accepted
9.49
N,K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -1*10**9 for si in range(N): x = si total = 0 l = 0 s = list() while(1): x = p[x]-1 s.append(c[x]) l += 1 total += c[x] if x == si: break t = 0 for i in range(l): now = 0 if (i+1) > K: break t += s[i] now += t if total > 0: e = (K-(i+1)) // l now += total * e ans = max(ans, now) print(ans)
N,K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -1* 10**9 for si in range(N): s = list() total = 0 l = 0 x = si while(1): x = p[x] - 1 s.append(c[x]) total += c[x] l += 1 if x == si: break t = 0 for j in range(l): t += s[j] now = t if j >= K: break if total > 0: e = (K-j-1)//l now += total * e ans = max(ans, now) print(ans)
29
29
511
495
N, K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -1 * 10**9 for si in range(N): x = si total = 0 l = 0 s = list() while 1: x = p[x] - 1 s.append(c[x]) l += 1 total += c[x] if x == si: break t = 0 for i in range(l): now = 0 if (i + 1) > K: break t += s[i] now += t if total > 0: e = (K - (i + 1)) // l now += total * e ans = max(ans, now) print(ans)
N, K = list(map(int, input().split())) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -1 * 10**9 for si in range(N): s = list() total = 0 l = 0 x = si while 1: x = p[x] - 1 s.append(c[x]) total += c[x] l += 1 if x == si: break t = 0 for j in range(l): t += s[j] now = t if j >= K: break if total > 0: e = (K - j - 1) // l now += total * e ans = max(ans, now) print(ans)
false
0
[ "- x = si", "+ s = list()", "- s = list()", "+ x = si", "+ total += c[x]", "- total += c[x]", "- for i in range(l):", "- now = 0", "- if (i + 1) > K:", "+ for j in range(l):", "+ t += s[j]", "+ now = t", "+ if j >= K:", "- t += s[i]", "- now += t", "- e = (K - (i + 1)) // l", "+ e = (K - j - 1) // l" ]
false
0.042828
0.044405
0.964482
[ "s143407373", "s169494559" ]
u556589653
p04012
python
s467722344
s775859724
20
17
3,316
3,064
Accepted
Accepted
15
#解法3 import collections w = eval(input()) s = list(w) c = collections.Counter(s) l = list(c.most_common()) #出現回数のリストがl flag = 0 for i in range(len(l)): if l[i][1]%2 == 0: continue else: flag += 1 break if flag == 0: print("Yes") else: print("No")
#解法2 w = eval(input()) ls = [0]*26 #各文字の出現回数リスト for i in range(len(w)): ls[ord(w[i])-97] += 1 #ASCIIコードに対応した配列を+1する flag = 0 for i in range(len(ls)): if ls[i]%2 == 0: continue else: flag += 1 break if flag == 0: print("Yes") else: print("No")
18
18
277
277
# 解法3 import collections w = eval(input()) s = list(w) c = collections.Counter(s) l = list(c.most_common()) # 出現回数のリストがl flag = 0 for i in range(len(l)): if l[i][1] % 2 == 0: continue else: flag += 1 break if flag == 0: print("Yes") else: print("No")
# 解法2 w = eval(input()) ls = [0] * 26 # 各文字の出現回数リスト for i in range(len(w)): ls[ord(w[i]) - 97] += 1 # ASCIIコードに対応した配列を+1する flag = 0 for i in range(len(ls)): if ls[i] % 2 == 0: continue else: flag += 1 break if flag == 0: print("Yes") else: print("No")
false
0
[ "-# 解法3", "-import collections", "-", "+# 解法2", "-s = list(w)", "-c = collections.Counter(s)", "-l = list(c.most_common())", "-# 出現回数のリストがl", "+ls = [0] * 26", "+# 各文字の出現回数リスト", "+for i in range(len(w)):", "+ ls[ord(w[i]) - 97] += 1", "+ # ASCIIコードに対応した配列を+1する", "-for i in range(len(l)):", "- if l[i][1] % 2 == 0:", "+for i in range(len(ls)):", "+ if ls[i] % 2 == 0:" ]
false
0.008949
0.047117
0.189924
[ "s467722344", "s775859724" ]
u968166680
p03944
python
s468945832
s994361458
34
28
9,256
9,112
Accepted
Accepted
17.65
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(): W, H, N, *XYA = list(map(int, read().split())) vec_x = [0] * (W + 1) vec_y = [0] * (H + 1) for x, y, a in zip(*[iter(XYA)] * 3): if a == 1: vec_x[0] += 1 vec_x[x] -= 1 elif a == 2: vec_x[x] += 1 vec_x[W] -= 1 elif a == 3: vec_y[0] += 1 vec_y[y] -= 1 else: vec_y[y] += 1 vec_y[H] -= 1 vec_x = list(accumulate(vec_x)) vec_y = list(accumulate(vec_y)) ans = 0 for i in range(W): for j in range(H): if vec_x[i] == 0 and vec_y[j] == 0: ans += 1 print(ans) return if __name__ == '__main__': main()
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(): W, H, N, *XYA = list(map(int, read().split())) x_left = 0 x_right = W y_left = 0 y_right = H for x, y, a in zip(*[iter(XYA)] * 3): if a == 1 and x_left < x: x_left = x elif a == 2 and x_right > x: x_right = x elif a == 3 and y_left < y: y_left = y elif a == 4 and y_right > y: y_right = y print((max(x_right - x_left, 0) * max(y_right - y_left, 0))) return if __name__ == '__main__': main()
45
34
948
741
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(): W, H, N, *XYA = list(map(int, read().split())) vec_x = [0] * (W + 1) vec_y = [0] * (H + 1) for x, y, a in zip(*[iter(XYA)] * 3): if a == 1: vec_x[0] += 1 vec_x[x] -= 1 elif a == 2: vec_x[x] += 1 vec_x[W] -= 1 elif a == 3: vec_y[0] += 1 vec_y[y] -= 1 else: vec_y[y] += 1 vec_y[H] -= 1 vec_x = list(accumulate(vec_x)) vec_y = list(accumulate(vec_y)) ans = 0 for i in range(W): for j in range(H): if vec_x[i] == 0 and vec_y[j] == 0: ans += 1 print(ans) return if __name__ == "__main__": main()
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(): W, H, N, *XYA = list(map(int, read().split())) x_left = 0 x_right = W y_left = 0 y_right = H for x, y, a in zip(*[iter(XYA)] * 3): if a == 1 and x_left < x: x_left = x elif a == 2 and x_right > x: x_right = x elif a == 3 and y_left < y: y_left = y elif a == 4 and y_right > y: y_right = y print((max(x_right - x_left, 0) * max(y_right - y_left, 0))) return if __name__ == "__main__": main()
false
24.444444
[ "- vec_x = [0] * (W + 1)", "- vec_y = [0] * (H + 1)", "+ x_left = 0", "+ x_right = W", "+ y_left = 0", "+ y_right = H", "- if a == 1:", "- vec_x[0] += 1", "- vec_x[x] -= 1", "- elif a == 2:", "- vec_x[x] += 1", "- vec_x[W] -= 1", "- elif a == 3:", "- vec_y[0] += 1", "- vec_y[y] -= 1", "- else:", "- vec_y[y] += 1", "- vec_y[H] -= 1", "- vec_x = list(accumulate(vec_x))", "- vec_y = list(accumulate(vec_y))", "- ans = 0", "- for i in range(W):", "- for j in range(H):", "- if vec_x[i] == 0 and vec_y[j] == 0:", "- ans += 1", "- print(ans)", "+ if a == 1 and x_left < x:", "+ x_left = x", "+ elif a == 2 and x_right > x:", "+ x_right = x", "+ elif a == 3 and y_left < y:", "+ y_left = y", "+ elif a == 4 and y_right > y:", "+ y_right = y", "+ print((max(x_right - x_left, 0) * max(y_right - y_left, 0)))" ]
false
0.037448
0.037253
1.00524
[ "s468945832", "s994361458" ]
u340781749
p02996
python
s649816646
s818590281
265
189
22,768
19,464
Accepted
Accepted
28.68
import sys import numpy as np n = int(eval(input())) tasks = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2)) a = tasks[:, 0] b = tasks[:, 1] i = b.argsort() print(('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No'))
import sys import numpy as np n = int(eval(input())) a, b = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=' ').reshape((n, 2)).T i = b.argsort() print(('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No'))
9
7
235
219
import sys import numpy as np n = int(eval(input())) tasks = np.fromstring(sys.stdin.read(), sep=" ").reshape((n, 2)) a = tasks[:, 0] b = tasks[:, 1] i = b.argsort() print(("Yes" if (np.add.accumulate(a[i]) <= b[i]).all() else "No"))
import sys import numpy as np n = int(eval(input())) a, b = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=" ").reshape((n, 2)).T i = b.argsort() print(("Yes" if (np.add.accumulate(a[i]) <= b[i]).all() else "No"))
false
22.222222
[ "-tasks = np.fromstring(sys.stdin.read(), sep=\" \").reshape((n, 2))", "-a = tasks[:, 0]", "-b = tasks[:, 1]", "+a, b = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=\" \").reshape((n, 2)).T" ]
false
0.27951
0.229924
1.215663
[ "s649816646", "s818590281" ]
u603745966
p03699
python
s409501632
s209637950
386
25
11,488
3,572
Accepted
Accepted
93.52
from functools import reduce import math def main(): # 文字列の2進数を数値にする # '101' → '5' # 文字列の頭に'0b'をつけてint()にわたす # binary = int('0b'+'101',0) # 2進数で立っているbitを数える # 101(0x5) → 2 # cnt_bit = bin(5).count('1') # N! を求める # f = math.factorial(N) # 切り捨て # 4 // 3 # 切り上げ #-(-4 // 3) # 初期値用:十分大きい数(100億) INF = float("inf") # 1文字のみを読み込み # 入力:2 # a = input().rstrip() # 変数:a='2' # スペース区切りで標準入力を配列として読み込み # 入力:2 4 5 7 # a, b, c, d = (int(_) for _ in input().split()) # 変数:a=2 b=4 c=5 d =7 # 1文字ずつ標準入力を配列として読み込み # 入力:2 4 5 7 # a = list(int(_) for _ in input().split()) # 変数:a = [2, 4, 5, 7] # 1文字ずつ標準入力を配列として読み込み # 入力:2457 # a = list(int(_) for _ in input()) # 変数:a = [2, 4, 5, 7] N = int(input().rstrip()) s = [] for i in range(N): s.append(int(input().rstrip())) dp = [] for i in range(N): dp.append([-1]*(100*100)) dp[0][s[0]] = 1 for i in range(1,N): for j in range(100*100): if(j == s[i] or (j-s[i]>=0 and dp[i-1][j-s[i]]==1)): dp[i][j] = 1 else: dp[i][j] = dp[i-1][j] ans = 0 # print('\n'.join(str(_) for _ in(dp[N-1]))) for i in range(100*100-1,0,-1): if(i%10 != 0 and dp[N-1][i]==1): ans = i break print(ans) if __name__ == '__main__': main()
from functools import reduce import math def main(): # 文字列の2進数を数値にする # '101' → '5' # 文字列の頭に'0b'をつけてint()にわたす # binary = int('0b'+'101',0) # 2進数で立っているbitを数える # 101(0x5) → 2 # cnt_bit = bin(5).count('1') # N! を求める # f = math.factorial(N) # 切り捨て # 4 // 3 # 切り上げ #-(-4 // 3) # 初期値用:十分大きい数(100億) INF = float("inf") # 1文字のみを読み込み # 入力:2 # a = input().rstrip() # 変数:a='2' # スペース区切りで標準入力を配列として読み込み # 入力:2 4 5 7 # a, b, c, d = (int(_) for _ in input().split()) # 変数:a=2 b=4 c=5 d =7 # 1文字ずつ標準入力を配列として読み込み # 入力:2 4 5 7 # a = list(int(_) for _ in input().split()) # 変数:a = [2, 4, 5, 7] # 1文字ずつ標準入力を配列として読み込み # 入力:2457 # a = list(int(_) for _ in input()) # 変数:a = [2, 4, 5, 7] N = int(input().rstrip()) s = [] for i in range(N): s.append(int(input().rstrip())) s.sort() ans = 0 if sum(s) % 10 != 0: ans = sum(s) print(ans) exit() for i in range(N): if(s[i]%10 !=0 ): ans = sum(s) - s[i] break # dp = [] # for i in range(N): # dp.append([-1]*(100*100)) # dp[0][s[0]] = 1 # for i in range(1,N): # for j in range(100*100): # if(j == s[i] or (j-s[i]>=0 and dp[i-1][j-s[i]]==1)): # dp[i][j] = 1 # else: # dp[i][j] = dp[i-1][j] # ans = 0 # for i in range(100*100-1,0,-1): # if(i%10 != 0 and dp[N-1][i]==1): # ans = i # break print(ans) if __name__ == '__main__': main()
66
76
1,526
1,726
from functools import reduce import math def main(): # 文字列の2進数を数値にする # '101' → '5' # 文字列の頭に'0b'をつけてint()にわたす # binary = int('0b'+'101',0) # 2進数で立っているbitを数える # 101(0x5) → 2 # cnt_bit = bin(5).count('1') # N! を求める # f = math.factorial(N) # 切り捨て # 4 // 3 # 切り上げ # -(-4 // 3) # 初期値用:十分大きい数(100億) INF = float("inf") # 1文字のみを読み込み # 入力:2 # a = input().rstrip() # 変数:a='2' # スペース区切りで標準入力を配列として読み込み # 入力:2 4 5 7 # a, b, c, d = (int(_) for _ in input().split()) # 変数:a=2 b=4 c=5 d =7 # 1文字ずつ標準入力を配列として読み込み # 入力:2 4 5 7 # a = list(int(_) for _ in input().split()) # 変数:a = [2, 4, 5, 7] # 1文字ずつ標準入力を配列として読み込み # 入力:2457 # a = list(int(_) for _ in input()) # 変数:a = [2, 4, 5, 7] N = int(input().rstrip()) s = [] for i in range(N): s.append(int(input().rstrip())) dp = [] for i in range(N): dp.append([-1] * (100 * 100)) dp[0][s[0]] = 1 for i in range(1, N): for j in range(100 * 100): if j == s[i] or (j - s[i] >= 0 and dp[i - 1][j - s[i]] == 1): dp[i][j] = 1 else: dp[i][j] = dp[i - 1][j] ans = 0 # print('\n'.join(str(_) for _ in(dp[N-1]))) for i in range(100 * 100 - 1, 0, -1): if i % 10 != 0 and dp[N - 1][i] == 1: ans = i break print(ans) if __name__ == "__main__": main()
from functools import reduce import math def main(): # 文字列の2進数を数値にする # '101' → '5' # 文字列の頭に'0b'をつけてint()にわたす # binary = int('0b'+'101',0) # 2進数で立っているbitを数える # 101(0x5) → 2 # cnt_bit = bin(5).count('1') # N! を求める # f = math.factorial(N) # 切り捨て # 4 // 3 # 切り上げ # -(-4 // 3) # 初期値用:十分大きい数(100億) INF = float("inf") # 1文字のみを読み込み # 入力:2 # a = input().rstrip() # 変数:a='2' # スペース区切りで標準入力を配列として読み込み # 入力:2 4 5 7 # a, b, c, d = (int(_) for _ in input().split()) # 変数:a=2 b=4 c=5 d =7 # 1文字ずつ標準入力を配列として読み込み # 入力:2 4 5 7 # a = list(int(_) for _ in input().split()) # 変数:a = [2, 4, 5, 7] # 1文字ずつ標準入力を配列として読み込み # 入力:2457 # a = list(int(_) for _ in input()) # 変数:a = [2, 4, 5, 7] N = int(input().rstrip()) s = [] for i in range(N): s.append(int(input().rstrip())) s.sort() ans = 0 if sum(s) % 10 != 0: ans = sum(s) print(ans) exit() for i in range(N): if s[i] % 10 != 0: ans = sum(s) - s[i] break # dp = [] # for i in range(N): # dp.append([-1]*(100*100)) # dp[0][s[0]] = 1 # for i in range(1,N): # for j in range(100*100): # if(j == s[i] or (j-s[i]>=0 and dp[i-1][j-s[i]]==1)): # dp[i][j] = 1 # else: # dp[i][j] = dp[i-1][j] # ans = 0 # for i in range(100*100-1,0,-1): # if(i%10 != 0 and dp[N-1][i]==1): # ans = i # break print(ans) if __name__ == "__main__": main()
false
13.157895
[ "- dp = []", "+ s.sort()", "+ ans = 0", "+ if sum(s) % 10 != 0:", "+ ans = sum(s)", "+ print(ans)", "+ exit()", "- dp.append([-1] * (100 * 100))", "- dp[0][s[0]] = 1", "- for i in range(1, N):", "- for j in range(100 * 100):", "- if j == s[i] or (j - s[i] >= 0 and dp[i - 1][j - s[i]] == 1):", "- dp[i][j] = 1", "- else:", "- dp[i][j] = dp[i - 1][j]", "- ans = 0", "- # print('\\n'.join(str(_) for _ in(dp[N-1])))", "- for i in range(100 * 100 - 1, 0, -1):", "- if i % 10 != 0 and dp[N - 1][i] == 1:", "- ans = i", "+ if s[i] % 10 != 0:", "+ ans = sum(s) - s[i]", "+ # dp = []", "+ # for i in range(N):", "+ # dp.append([-1]*(100*100))", "+ # dp[0][s[0]] = 1", "+ # for i in range(1,N):", "+ # for j in range(100*100):", "+ # if(j == s[i] or (j-s[i]>=0 and dp[i-1][j-s[i]]==1)):", "+ # dp[i][j] = 1", "+ # else:", "+ # dp[i][j] = dp[i-1][j]", "+ # ans = 0", "+ # for i in range(100*100-1,0,-1):", "+ # if(i%10 != 0 and dp[N-1][i]==1):", "+ # ans = i", "+ # break" ]
false
0.176854
0.036871
4.796607
[ "s409501632", "s209637950" ]
u971811058
p03730
python
s724568324
s885919710
34
30
9,448
9,408
Accepted
Accepted
11.76
# Begin Header {{{ from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations, combinations_with_replacement # }}} End Header # _________コーディングはここから!!___________ # ... 最小側の制約も確認した? # ... オーバーフローしない? a, b, c = list(map(int, input().split())) i = 1 ok = False while i<b+1: if (a*i-c)%b != 0: i+=1 else: ok = True break if ok: print("YES") else: print("NO")
# Begin Header {{{ from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations, combinations_with_replacement # }}} End Header # _________コーディングはここから!!___________ # ... 最小側の制約も確認した? # ... オーバーフローしない? a, b, c = list(map(int, input().split())) i = 1 ok = False while i<=b: if (a*i-c)%b != 0: i+=1 else: ok = True break if ok: print("YES") else: print("NO")
20
20
641
640
# Begin Header {{{ from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import ( accumulate, product, permutations, combinations, combinations_with_replacement, ) # }}} End Header # _________コーディングはここから!!___________ # ... 最小側の制約も確認した? # ... オーバーフローしない? a, b, c = list(map(int, input().split())) i = 1 ok = False while i < b + 1: if (a * i - c) % b != 0: i += 1 else: ok = True break if ok: print("YES") else: print("NO")
# Begin Header {{{ from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import ( accumulate, product, permutations, combinations, combinations_with_replacement, ) # }}} End Header # _________コーディングはここから!!___________ # ... 最小側の制約も確認した? # ... オーバーフローしない? a, b, c = list(map(int, input().split())) i = 1 ok = False while i <= b: if (a * i - c) % b != 0: i += 1 else: ok = True break if ok: print("YES") else: print("NO")
false
0
[ "-while i < b + 1:", "+while i <= b:" ]
false
0.115056
0.035213
3.267394
[ "s724568324", "s885919710" ]
u373047809
p03476
python
s414513087
s831468484
912
480
8,724
14,604
Accepted
Accepted
47.37
#!/usr/bin/env python3 from itertools import accumulate def erat(m): p = [1] * m p[0] = p[1] = 0 for x in range(2, int((~-m)**.5) + 1): if p[x]: for y in range(x*x, m, x): p[y] = 0 return p INF = 10**5 + 1 p = erat(INF) q = [0] * INF for n in range(INF): q[n] = n%2 * p[n] * p[-~n//2] *a, = accumulate([0] + q) for _ in [None] * int(eval(input())): l, r = list(map(int, input().split())) print((a[r + 1] - a[l]))
def erat(M): p = [1] * M p[0] = p[1] = 0 for x in range(2, int((M - 1)**.5) + 1): if p[x]: for y in range(x*x, M, x): p[y] = 0 return p INF = 10**5 + 1 p = erat(INF) q = [0] * INF from itertools import* for i in range(INF): q[i] = i%2 * p[i] * p[-~i//2] *a, = accumulate([0] + q) for _ in [None] * int(eval(input())): l, r = list(map(int, input().split())) print((a[-~r] - a[l]))
20
18
482
447
#!/usr/bin/env python3 from itertools import accumulate def erat(m): p = [1] * m p[0] = p[1] = 0 for x in range(2, int((~-m) ** 0.5) + 1): if p[x]: for y in range(x * x, m, x): p[y] = 0 return p INF = 10**5 + 1 p = erat(INF) q = [0] * INF for n in range(INF): q[n] = n % 2 * p[n] * p[-~n // 2] (*a,) = accumulate([0] + q) for _ in [None] * int(eval(input())): l, r = list(map(int, input().split())) print((a[r + 1] - a[l]))
def erat(M): p = [1] * M p[0] = p[1] = 0 for x in range(2, int((M - 1) ** 0.5) + 1): if p[x]: for y in range(x * x, M, x): p[y] = 0 return p INF = 10**5 + 1 p = erat(INF) q = [0] * INF from itertools import * for i in range(INF): q[i] = i % 2 * p[i] * p[-~i // 2] (*a,) = accumulate([0] + q) for _ in [None] * int(eval(input())): l, r = list(map(int, input().split())) print((a[-~r] - a[l]))
false
10
[ "-#!/usr/bin/env python3", "-from itertools import accumulate", "-", "-", "-def erat(m):", "- p = [1] * m", "+def erat(M):", "+ p = [1] * M", "- for x in range(2, int((~-m) ** 0.5) + 1):", "+ for x in range(2, int((M - 1) ** 0.5) + 1):", "- for y in range(x * x, m, x):", "+ for y in range(x * x, M, x):", "-for n in range(INF):", "- q[n] = n % 2 * p[n] * p[-~n // 2]", "+from itertools import *", "+", "+for i in range(INF):", "+ q[i] = i % 2 * p[i] * p[-~i // 2]", "- print((a[r + 1] - a[l]))", "+ print((a[-~r] - a[l]))" ]
false
0.116719
0.117907
0.989925
[ "s414513087", "s831468484" ]
u723711163
p02726
python
s669337503
s689643673
1,856
321
3,572
49,756
Accepted
Accepted
82.7
N, X, Y = list(map(int, input().split())) result = [0] * N for i in range(1, N): for j in range(i+1, N+1): step = min( j-i, abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X)) result[step] += 1 for e in result[1:]: print(e)
from collections import defaultdict N,X,Y = list(map(int,input().split())) counter = defaultdict(int) for i in range(1,N): for j in range(i+1, N+1): step = min(j-i, abs(X-i)+1+abs(Y-j)) counter[step] += 1 for i in range(1, N): print((counter[i]))
10
11
235
262
N, X, Y = list(map(int, input().split())) result = [0] * N for i in range(1, N): for j in range(i + 1, N + 1): step = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X)) result[step] += 1 for e in result[1:]: print(e)
from collections import defaultdict N, X, Y = list(map(int, input().split())) counter = defaultdict(int) for i in range(1, N): for j in range(i + 1, N + 1): step = min(j - i, abs(X - i) + 1 + abs(Y - j)) counter[step] += 1 for i in range(1, N): print((counter[i]))
false
9.090909
[ "+from collections import defaultdict", "+", "-result = [0] * N", "+counter = defaultdict(int)", "- step = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))", "- result[step] += 1", "-for e in result[1:]:", "- print(e)", "+ step = min(j - i, abs(X - i) + 1 + abs(Y - j))", "+ counter[step] += 1", "+for i in range(1, N):", "+ print((counter[i]))" ]
false
0.079728
0.109929
0.725269
[ "s669337503", "s689643673" ]
u792720861
p02993
python
s447883164
s212804528
30
25
9,008
8,956
Accepted
Accepted
16.67
s = eval(input()) print(('Bad' if s[0]==s[1] or s[1]==s[2] or s[2]==s[3] else 'Good'))
n = eval(input()) print(('Bad' if n[0]==n[1] or n[1]==n[2] or n[2]==n[3] else 'Good'))
2
2
80
80
s = eval(input()) print(("Bad" if s[0] == s[1] or s[1] == s[2] or s[2] == s[3] else "Good"))
n = eval(input()) print(("Bad" if n[0] == n[1] or n[1] == n[2] or n[2] == n[3] else "Good"))
false
0
[ "-s = eval(input())", "-print((\"Bad\" if s[0] == s[1] or s[1] == s[2] or s[2] == s[3] else \"Good\"))", "+n = eval(input())", "+print((\"Bad\" if n[0] == n[1] or n[1] == n[2] or n[2] == n[3] else \"Good\"))" ]
false
0.043742
0.042261
1.035063
[ "s447883164", "s212804528" ]
u241159583
p04020
python
s837012442
s576041747
192
175
12,936
13,096
Accepted
Accepted
8.85
n = int(eval(input())) A = list(int(eval(input())) for _ in range(n)) ans = 0 for i in range(n): tmp = A[i] ans += (tmp//2) if i < n-1 and tmp %2 and A[i+1] > 0: ans += 1 A[i+1] -= 1 print(ans)
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] ans = 0 for i in range(n-1): x,y = A[i], A[i+1] ans += x//2 if x%2!=0 and y > 0: ans += 1 A[i+1] -= 1 ans += A[-1]//2 print(ans)
10
12
218
222
n = int(eval(input())) A = list(int(eval(input())) for _ in range(n)) ans = 0 for i in range(n): tmp = A[i] ans += tmp // 2 if i < n - 1 and tmp % 2 and A[i + 1] > 0: ans += 1 A[i + 1] -= 1 print(ans)
n = int(eval(input())) A = [int(eval(input())) for _ in range(n)] ans = 0 for i in range(n - 1): x, y = A[i], A[i + 1] ans += x // 2 if x % 2 != 0 and y > 0: ans += 1 A[i + 1] -= 1 ans += A[-1] // 2 print(ans)
false
16.666667
[ "-A = list(int(eval(input())) for _ in range(n))", "+A = [int(eval(input())) for _ in range(n)]", "-for i in range(n):", "- tmp = A[i]", "- ans += tmp // 2", "- if i < n - 1 and tmp % 2 and A[i + 1] > 0:", "+for i in range(n - 1):", "+ x, y = A[i], A[i + 1]", "+ ans += x // 2", "+ if x % 2 != 0 and y > 0:", "+ans += A[-1] // 2" ]
false
0.036908
0.037373
0.987564
[ "s837012442", "s576041747" ]
u519968172
p03252
python
s053432213
s690339705
56
49
9,624
9,568
Accepted
Accepted
12.5
from collections import Counter s=eval(input()) t=eval(input()) sc=Counter(s) tc=Counter(t) if len(sc)!=len(tc): print("No") else: for s1,t1 in zip(sorted(list(sc.items()),key=lambda i: i[1]),sorted(list(tc.items()),key=lambda i: i[1])): if s1[1]!=t1[1]: print("No") break else: print("Yes")
from collections import Counter sc=Counter(eval(input())) tc=Counter(eval(input())) for s,t in zip(sorted(sc.values()),sorted(tc.values())): if s!=t: print("No") break else: print("Yes")
15
11
308
206
from collections import Counter s = eval(input()) t = eval(input()) sc = Counter(s) tc = Counter(t) if len(sc) != len(tc): print("No") else: for s1, t1 in zip( sorted(list(sc.items()), key=lambda i: i[1]), sorted(list(tc.items()), key=lambda i: i[1]), ): if s1[1] != t1[1]: print("No") break else: print("Yes")
from collections import Counter sc = Counter(eval(input())) tc = Counter(eval(input())) for s, t in zip(sorted(sc.values()), sorted(tc.values())): if s != t: print("No") break else: print("Yes")
false
26.666667
[ "-s = eval(input())", "-t = eval(input())", "-sc = Counter(s)", "-tc = Counter(t)", "-if len(sc) != len(tc):", "- print(\"No\")", "+sc = Counter(eval(input()))", "+tc = Counter(eval(input()))", "+for s, t in zip(sorted(sc.values()), sorted(tc.values())):", "+ if s != t:", "+ print(\"No\")", "+ break", "- for s1, t1 in zip(", "- sorted(list(sc.items()), key=lambda i: i[1]),", "- sorted(list(tc.items()), key=lambda i: i[1]),", "- ):", "- if s1[1] != t1[1]:", "- print(\"No\")", "- break", "- else:", "- print(\"Yes\")", "+ print(\"Yes\")" ]
false
0.038521
0.037101
1.038267
[ "s053432213", "s690339705" ]
u346395915
p03160
python
s492759374
s186789969
144
123
13,976
20,524
Accepted
Accepted
14.58
n = int(eval(input())) li = list(map(int,input().split())) dp = [10**8] * n for i in range(n): if i == 0: dp[i] = 0 elif i == 1: dp[i] = abs(li[i] - li[i-1]) else: dp[i] = min(abs(li[i] - li[i-1]) + dp[i-1], abs(li[i] - li[i-2]) + dp[i-2]) print((dp[-1]))
n = int(eval(input())) h_li = list(map(int, input().split())) dp = [10**18] * n dp[0] = 0 for i in range(1,n): if i == 1: dp[i] = abs(h_li[i] - h_li[0]) else: dp[i] = min(abs(h_li[i] - h_li[i-1]) + dp[i-1], abs(h_li[i] - h_li[i-2]) + dp[i-2]) print((dp[-1]))
14
12
300
287
n = int(eval(input())) li = list(map(int, input().split())) dp = [10**8] * n for i in range(n): if i == 0: dp[i] = 0 elif i == 1: dp[i] = abs(li[i] - li[i - 1]) else: dp[i] = min( abs(li[i] - li[i - 1]) + dp[i - 1], abs(li[i] - li[i - 2]) + dp[i - 2] ) print((dp[-1]))
n = int(eval(input())) h_li = list(map(int, input().split())) dp = [10**18] * n dp[0] = 0 for i in range(1, n): if i == 1: dp[i] = abs(h_li[i] - h_li[0]) else: dp[i] = min( abs(h_li[i] - h_li[i - 1]) + dp[i - 1], abs(h_li[i] - h_li[i - 2]) + dp[i - 2], ) print((dp[-1]))
false
14.285714
[ "-li = list(map(int, input().split()))", "-dp = [10**8] * n", "-for i in range(n):", "- if i == 0:", "- dp[i] = 0", "- elif i == 1:", "- dp[i] = abs(li[i] - li[i - 1])", "+h_li = list(map(int, input().split()))", "+dp = [10**18] * n", "+dp[0] = 0", "+for i in range(1, n):", "+ if i == 1:", "+ dp[i] = abs(h_li[i] - h_li[0])", "- abs(li[i] - li[i - 1]) + dp[i - 1], abs(li[i] - li[i - 2]) + dp[i - 2]", "+ abs(h_li[i] - h_li[i - 1]) + dp[i - 1],", "+ abs(h_li[i] - h_li[i - 2]) + dp[i - 2]," ]
false
0.037345
0.037432
0.997699
[ "s492759374", "s186789969" ]
u200887663
p02708
python
s488307581
s069834553
138
80
9,180
9,164
Accepted
Accepted
42.03
#n=int(input()) n,k=list(map(int,input().split())) #l=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] mod=10**9+7 ans=0 for kval in range(k,n+2): mx=kval*(2*n-kval+1)//2 mn=kval*(kval-1)//2 add=mx-mn+1 ans=(ans+add) % mod print(ans)
#l=int(input()) n,k=list(map(int,input().split())) #pl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] mod=10**9+7 total=0 for m in range(k,n+2): add=m*(n-m+1)+1 total=(total+add)%mod print(total)
15
15
297
255
# n=int(input()) n, k = list(map(int, input().split())) # l=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] mod = 10**9 + 7 ans = 0 for kval in range(k, n + 2): mx = kval * (2 * n - kval + 1) // 2 mn = kval * (kval - 1) // 2 add = mx - mn + 1 ans = (ans + add) % mod print(ans)
# l=int(input()) n, k = list(map(int, input().split())) # pl=list(map(int,input().split())) # l=[list(map(int,input().split())) for i in range(n)] mod = 10**9 + 7 total = 0 for m in range(k, n + 2): add = m * (n - m + 1) + 1 total = (total + add) % mod print(total)
false
0
[ "-# n=int(input())", "+# l=int(input())", "-# l=list(map(int,input().split()))", "+# pl=list(map(int,input().split()))", "-ans = 0", "-for kval in range(k, n + 2):", "- mx = kval * (2 * n - kval + 1) // 2", "- mn = kval * (kval - 1) // 2", "- add = mx - mn + 1", "- ans = (ans + add) % mod", "-print(ans)", "+total = 0", "+for m in range(k, n + 2):", "+ add = m * (n - m + 1) + 1", "+ total = (total + add) % mod", "+print(total)" ]
false
0.053509
0.115605
0.46286
[ "s488307581", "s069834553" ]
u998741086
p02802
python
s348703535
s319330650
338
309
14,924
15,320
Accepted
Accepted
8.58
#!/usr/bin/env python3 n, m = list(map(int, input().split())) p = [] s = [] for i in range(m): t1, t2 = input().split() p.append(int(t1)-1) s.append(t2) # 問題iがACしているかどうかを覚えておく配列 ac = [0 for _ in range(n)] # 問題iがWAしている回数 pena = [0 for _ in range(n)] # ac[], pena[]を作る。 for i in range(m): if ac[p[i]] == 1: continue # XXX if s[i] == 'AC': ac[p[i]] = 1 else: pena[p[i]] += 1 AC=0 PENA=0 for i in range(n): AC += ac[i] if ac[i] == 1: PENA += pena[i] print(("%d %d" % (AC,PENA)))
#!/usr/bin/env python3 n, m = list(map(int, input().split())) p = [] s = [] for i in range(m): t1, t2 = input().split() p.append(int(t1)-1) s.append(t2) # 問題iがACしているかどうかを覚えておく配列 ac = [0 for _ in range(n)] # 問題iがWAしている回数 pena = [0 for _ in range(n)] # ac[], pena[]を作る。 for i in range(m): if ac[p[i]] == 0: if s[i] == 'AC': ac[p[i]] = 1 else: pena[p[i]] += 1 AC=0 PENA=0 for i in range(n): AC += ac[i] if ac[i] == 1: PENA += pena[i] print(("%d %d" % (AC,PENA)))
32
31
568
560
#!/usr/bin/env python3 n, m = list(map(int, input().split())) p = [] s = [] for i in range(m): t1, t2 = input().split() p.append(int(t1) - 1) s.append(t2) # 問題iがACしているかどうかを覚えておく配列 ac = [0 for _ in range(n)] # 問題iがWAしている回数 pena = [0 for _ in range(n)] # ac[], pena[]を作る。 for i in range(m): if ac[p[i]] == 1: continue # XXX if s[i] == "AC": ac[p[i]] = 1 else: pena[p[i]] += 1 AC = 0 PENA = 0 for i in range(n): AC += ac[i] if ac[i] == 1: PENA += pena[i] print(("%d %d" % (AC, PENA)))
#!/usr/bin/env python3 n, m = list(map(int, input().split())) p = [] s = [] for i in range(m): t1, t2 = input().split() p.append(int(t1) - 1) s.append(t2) # 問題iがACしているかどうかを覚えておく配列 ac = [0 for _ in range(n)] # 問題iがWAしている回数 pena = [0 for _ in range(n)] # ac[], pena[]を作る。 for i in range(m): if ac[p[i]] == 0: if s[i] == "AC": ac[p[i]] = 1 else: pena[p[i]] += 1 AC = 0 PENA = 0 for i in range(n): AC += ac[i] if ac[i] == 1: PENA += pena[i] print(("%d %d" % (AC, PENA)))
false
3.125
[ "- if ac[p[i]] == 1:", "- continue # XXX", "- if s[i] == \"AC\":", "- ac[p[i]] = 1", "- else:", "- pena[p[i]] += 1", "+ if ac[p[i]] == 0:", "+ if s[i] == \"AC\":", "+ ac[p[i]] = 1", "+ else:", "+ pena[p[i]] += 1" ]
false
0.044334
0.056431
0.785627
[ "s348703535", "s319330650" ]
u689322583
p03730
python
s649766629
s347445024
23
18
3,828
2,940
Accepted
Accepted
21.74
#coding: utf-8 A, B ,C = map(int, input().split()) count = 0 for i in range(A*B): if(A*i % B == C): count = 1 else: print('',end='') if(count == 1): print('YES') else: print('NO')
#coding: utf-8 A, B ,C = list(map(int, input().split())) count = 0 for i in range(A*B): if(A*i % B == C): print('YES') break else: print('NO')
15
11
228
172
# coding: utf-8 A, B, C = map(int, input().split()) count = 0 for i in range(A * B): if A * i % B == C: count = 1 else: print("", end="") if count == 1: print("YES") else: print("NO")
# coding: utf-8 A, B, C = list(map(int, input().split())) count = 0 for i in range(A * B): if A * i % B == C: print("YES") break else: print("NO")
false
26.666667
[ "-A, B, C = map(int, input().split())", "+A, B, C = list(map(int, input().split()))", "- count = 1", "- else:", "- print(\"\", end=\"\")", "-if count == 1:", "- print(\"YES\")", "+ print(\"YES\")", "+ break" ]
false
0.033392
0.04213
0.792589
[ "s649766629", "s347445024" ]
u146816547
p00001
python
s857003841
s732542541
20
10
4,196
6,344
Accepted
Accepted
50
s = [] for i in range(10): s.append(int(input())) s.sort() s.reverse() for i in range(3): print(s[i])
s = [] for i in range(10): s.append(int(input())) s.sort() for i in range(3): print(s[9-i])
7
9
114
109
s = [] for i in range(10): s.append(int(input())) s.sort() s.reverse() for i in range(3): print(s[i])
s = [] for i in range(10): s.append(int(input())) s.sort() for i in range(3): print(s[9 - i])
false
22.222222
[ "-s.reverse()", "- print(s[i])", "+ print(s[9 - i])" ]
false
0.084845
0.040279
2.10641
[ "s857003841", "s732542541" ]
u296150111
p03450
python
s145825235
s305988116
1,435
1,206
66,824
66,316
Accepted
Accepted
15.96
inf=10**10 n,m=list(map(int,input().split())) x=[inf]*n con=[[] for _ in range(n)] for i in range(m): l,r,d=list(map(int,input().split())) con[l-1].append((r-1,d)) con[r-1].append((l-1,-d)) from collections import deque for i in range(n): if x[i]==inf: x[i]=0 q=deque([i]) while q: e=q.pop() for j,k in con[e]: if x[j]==inf: q.append(j) x[j]=x[e]+k for i in range(n): for j,k in con[i]: if x[i]+k!=x[j]: print("No") exit() print("Yes")
inf=10**10 n,m=list(map(int,input().split())) x=[inf]*n con=[[] for _ in range(n)] for i in range(m): l,r,d=list(map(int,input().split())) con[l-1].append((r-1,d)) con[r-1].append((l-1,-d)) from collections import deque for i in range(n): if x[i]==inf: x[i]=0 q=deque([i]) while q: e=q.pop() for j,k in con[e]: if x[j]==inf: q.append(j) x[j]=x[e]+k elif x[j]!=x[e]+k: print("No") exit() print("Yes")
25
23
486
453
inf = 10**10 n, m = list(map(int, input().split())) x = [inf] * n con = [[] for _ in range(n)] for i in range(m): l, r, d = list(map(int, input().split())) con[l - 1].append((r - 1, d)) con[r - 1].append((l - 1, -d)) from collections import deque for i in range(n): if x[i] == inf: x[i] = 0 q = deque([i]) while q: e = q.pop() for j, k in con[e]: if x[j] == inf: q.append(j) x[j] = x[e] + k for i in range(n): for j, k in con[i]: if x[i] + k != x[j]: print("No") exit() print("Yes")
inf = 10**10 n, m = list(map(int, input().split())) x = [inf] * n con = [[] for _ in range(n)] for i in range(m): l, r, d = list(map(int, input().split())) con[l - 1].append((r - 1, d)) con[r - 1].append((l - 1, -d)) from collections import deque for i in range(n): if x[i] == inf: x[i] = 0 q = deque([i]) while q: e = q.pop() for j, k in con[e]: if x[j] == inf: q.append(j) x[j] = x[e] + k elif x[j] != x[e] + k: print("No") exit() print("Yes")
false
8
[ "-for i in range(n):", "- for j, k in con[i]:", "- if x[i] + k != x[j]:", "- print(\"No\")", "- exit()", "+ elif x[j] != x[e] + k:", "+ print(\"No\")", "+ exit()" ]
false
0.039441
0.031485
1.252687
[ "s145825235", "s305988116" ]
u829249049
p03013
python
s815196558
s134474148
529
488
460,020
460,020
Accepted
Accepted
7.75
import sys N,M=list(map(int,input().split())) dp=[1]*N listA=[] for i in range(M): a=int(eval(input())) listA+=[a] dp[a-1]=0 for i in range(1,M): if listA[i]==listA[i-1]: print((0)) sys.exit() setA=set(listA) if (1 not in setA) and (2 not in setA) and N!=1: dp[1]=2 for i in range(2,N): if i+1 not in setA: dp[i]=dp[i-1]+dp[i-2] ans=dp[-1]%(10**9+7) print(ans)
N,M=list(map(int,input().split())) dp=[1]*N listA=[] for i in range(M): a=int(eval(input())) listA+=[a] dp[a-1]=0 setA=set(listA) if (1 not in setA) and (2 not in setA) and N!=1: dp[1]=2 for i in range(2,N): if i+1 not in setA: dp[i]=dp[i-1]+dp[i-2] ans=dp[-1]%(10**9+7) print(ans)
20
15
393
301
import sys N, M = list(map(int, input().split())) dp = [1] * N listA = [] for i in range(M): a = int(eval(input())) listA += [a] dp[a - 1] = 0 for i in range(1, M): if listA[i] == listA[i - 1]: print((0)) sys.exit() setA = set(listA) if (1 not in setA) and (2 not in setA) and N != 1: dp[1] = 2 for i in range(2, N): if i + 1 not in setA: dp[i] = dp[i - 1] + dp[i - 2] ans = dp[-1] % (10**9 + 7) print(ans)
N, M = list(map(int, input().split())) dp = [1] * N listA = [] for i in range(M): a = int(eval(input())) listA += [a] dp[a - 1] = 0 setA = set(listA) if (1 not in setA) and (2 not in setA) and N != 1: dp[1] = 2 for i in range(2, N): if i + 1 not in setA: dp[i] = dp[i - 1] + dp[i - 2] ans = dp[-1] % (10**9 + 7) print(ans)
false
25
[ "-import sys", "-", "-for i in range(1, M):", "- if listA[i] == listA[i - 1]:", "- print((0))", "- sys.exit()" ]
false
0.097788
0.04895
1.997721
[ "s815196558", "s134474148" ]
u017415492
p02947
python
s464348692
s844496955
509
391
11,372
17,932
Accepted
Accepted
23.18
n=int(eval(input())) s=[] ans=0 count=1 def comb(n,k): for i in range(k-1): n*=n-i-1 k*=k-i-1 return n//k for i in range(n): a=list(eval(input())) a.sort() " ".join(a) s.append(" ".join(a)) s.sort() for i in range(n-1): if s[i]==s[i+1]: count+=1 else: ans+=(comb(count,2)) count=1 if count>0: ans+=(comb(count,2)) print(ans)
n=int(eval(input())) ans=dict() for i in range(n): d=list(eval(input())) d.sort() s="".join(d) if not(s in ans): ans[s]=1 else: ans[s]+=1 anss=0 for i in ans: anss+=((ans[i]*(ans[i]-1))//2) print(anss)
25
14
375
222
n = int(eval(input())) s = [] ans = 0 count = 1 def comb(n, k): for i in range(k - 1): n *= n - i - 1 k *= k - i - 1 return n // k for i in range(n): a = list(eval(input())) a.sort() " ".join(a) s.append(" ".join(a)) s.sort() for i in range(n - 1): if s[i] == s[i + 1]: count += 1 else: ans += comb(count, 2) count = 1 if count > 0: ans += comb(count, 2) print(ans)
n = int(eval(input())) ans = dict() for i in range(n): d = list(eval(input())) d.sort() s = "".join(d) if not (s in ans): ans[s] = 1 else: ans[s] += 1 anss = 0 for i in ans: anss += (ans[i] * (ans[i] - 1)) // 2 print(anss)
false
44
[ "-s = []", "-ans = 0", "-count = 1", "-", "-", "-def comb(n, k):", "- for i in range(k - 1):", "- n *= n - i - 1", "- k *= k - i - 1", "- return n // k", "-", "-", "+ans = dict()", "- a = list(eval(input()))", "- a.sort()", "- \" \".join(a)", "- s.append(\" \".join(a))", "-s.sort()", "-for i in range(n - 1):", "- if s[i] == s[i + 1]:", "- count += 1", "+ d = list(eval(input()))", "+ d.sort()", "+ s = \"\".join(d)", "+ if not (s in ans):", "+ ans[s] = 1", "- ans += comb(count, 2)", "- count = 1", "-if count > 0:", "- ans += comb(count, 2)", "-print(ans)", "+ ans[s] += 1", "+anss = 0", "+for i in ans:", "+ anss += (ans[i] * (ans[i] - 1)) // 2", "+print(anss)" ]
false
0.070022
0.096715
0.724011
[ "s464348692", "s844496955" ]
u057109575
p02888
python
s511592943
s794131391
622
355
74,428
68,584
Accepted
Accepted
42.93
from bisect import bisect_left, bisect_right N, *X = list(map(int, open(0).read().split())) X.sort() ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): k1 = bisect_right(X, X[j] - X[i]) k2 = bisect_left(X, X[i] + X[j]) k1 = max(k1, j + 1) ans += max(0, k2 - k1) print(ans)
from bisect import bisect_left N = int(eval(input())) X = list(map(int, input().split())) X.sort() ans = 0 for i in range(N): for j in range(i + 1, N): k = bisect_left(X, X[i] + X[j]) ans += k - j - 1 print(ans)
14
14
329
243
from bisect import bisect_left, bisect_right N, *X = list(map(int, open(0).read().split())) X.sort() ans = 0 for i in range(N - 2): for j in range(i + 1, N - 1): k1 = bisect_right(X, X[j] - X[i]) k2 = bisect_left(X, X[i] + X[j]) k1 = max(k1, j + 1) ans += max(0, k2 - k1) print(ans)
from bisect import bisect_left N = int(eval(input())) X = list(map(int, input().split())) X.sort() ans = 0 for i in range(N): for j in range(i + 1, N): k = bisect_left(X, X[i] + X[j]) ans += k - j - 1 print(ans)
false
0
[ "-from bisect import bisect_left, bisect_right", "+from bisect import bisect_left", "-N, *X = list(map(int, open(0).read().split()))", "+N = int(eval(input()))", "+X = list(map(int, input().split()))", "-for i in range(N - 2):", "- for j in range(i + 1, N - 1):", "- k1 = bisect_right(X, X[j] - X[i])", "- k2 = bisect_left(X, X[i] + X[j])", "- k1 = max(k1, j + 1)", "- ans += max(0, k2 - k1)", "+for i in range(N):", "+ for j in range(i + 1, N):", "+ k = bisect_left(X, X[i] + X[j])", "+ ans += k - j - 1" ]
false
0.074149
0.038383
1.931815
[ "s511592943", "s794131391" ]
u211109468
p03024
python
s980585659
s530580426
70
61
61,748
61,668
Accepted
Accepted
12.86
S = eval(input()) print(('YES' if 7-len(S)>=-sum([c=='o' for c in S]) else 'NO'))
print(('YES' if sum([c=='x' for c in eval(input())])<8 else 'NO'))
2
1
74
58
S = eval(input()) print(("YES" if 7 - len(S) >= -sum([c == "o" for c in S]) else "NO"))
print(("YES" if sum([c == "x" for c in eval(input())]) < 8 else "NO"))
false
50
[ "-S = eval(input())", "-print((\"YES\" if 7 - len(S) >= -sum([c == \"o\" for c in S]) else \"NO\"))", "+print((\"YES\" if sum([c == \"x\" for c in eval(input())]) < 8 else \"NO\"))" ]
false
0.045531
0.125769
0.362023
[ "s980585659", "s530580426" ]
u133936772
p03062
python
s061491587
s016823258
95
60
15,020
14,224
Accepted
Accepted
36.84
n = int(eval(input())) l = list(map(int,input().split())) m = sorted(list(map(abs,l))) print((sum(m) - sum(i<0 for i in l)%2*m[0]*2))
n=int(eval(input())) l=list(map(int,input().split())) m=list(map(abs,l)) print((sum(m)-sum(i<0 for i in l)%2*min(m)*2))
4
4
128
114
n = int(eval(input())) l = list(map(int, input().split())) m = sorted(list(map(abs, l))) print((sum(m) - sum(i < 0 for i in l) % 2 * m[0] * 2))
n = int(eval(input())) l = list(map(int, input().split())) m = list(map(abs, l)) print((sum(m) - sum(i < 0 for i in l) % 2 * min(m) * 2))
false
0
[ "-m = sorted(list(map(abs, l)))", "-print((sum(m) - sum(i < 0 for i in l) % 2 * m[0] * 2))", "+m = list(map(abs, l))", "+print((sum(m) - sum(i < 0 for i in l) % 2 * min(m) * 2))" ]
false
0.036632
0.042733
0.857232
[ "s061491587", "s016823258" ]
u728992264
p00935
python
s365872661
s942407924
30
20
7,604
7,604
Accepted
Accepted
33.33
n=int(eval(input())) d=''.join([''.join(input().split())for i in range(n//19+(n%19!=0))]) i=0 while True: if d.find(str(i))==-1: print(i) exit() i+=1
n=int(eval(input())) d=''.join(''.join(input().split())for i in[0]*(n//19+(n%19!=0))) i=0 while 1: if d.find(str(i))==-1: print(i) exit() i+=1
8
8
157
150
n = int(eval(input())) d = "".join(["".join(input().split()) for i in range(n // 19 + (n % 19 != 0))]) i = 0 while True: if d.find(str(i)) == -1: print(i) exit() i += 1
n = int(eval(input())) d = "".join("".join(input().split()) for i in [0] * (n // 19 + (n % 19 != 0))) i = 0 while 1: if d.find(str(i)) == -1: print(i) exit() i += 1
false
0
[ "-d = \"\".join([\"\".join(input().split()) for i in range(n // 19 + (n % 19 != 0))])", "+d = \"\".join(\"\".join(input().split()) for i in [0] * (n // 19 + (n % 19 != 0)))", "-while True:", "+while 1:" ]
false
0.03876
0.0374
1.036373
[ "s365872661", "s942407924" ]
u561231954
p02727
python
s988671709
s696822564
315
251
22,720
22,720
Accepted
Accepted
20.32
import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) INF = 10 ** 10 MOD = 10 ** 9 + 7 from heapq import heapify,heappop,heappush input = sys.stdin.readline def main(): x,y,a,b,c = list(map(int,input().split())) R = list(map(int,input().split())) G = list(map(int,input().split())) M = list(map(int,input().split())) i,j,k = 0,0,0 R.sort(reverse = True) G.sort(reverse = True) M.sort(reverse = True) ans = 0 while i < x and j < y and k < c and k + i + j < x + y: tmp = max(R[i],G[j],M[k]) ans += tmp if tmp == R[i]: i += 1 elif tmp == G[j]: j += 1 else: k += 1 if i + j + k == x + y: print(ans) return elif k == c: while i < x and j < y and i + j + c < x + y: tmp = max(R[i],G[j]) ans += tmp if tmp == R[i]: i += 1 elif tmp == G[j]: j += 1 if i + j + k == x + y: print(ans) return elif i == x: t = y - k - j for _ in range(t): if k < c and G[j] < M[k]: ans += M[k] k += 1 else: ans += G[j] j += 1 elif j == y: t = x - i - k for _ in range(t): if k < c and R[i] < M[k]: ans += M[k] k += 1 else: ans += R[i] i += 1 print(ans) if __name__=='__main__': main()
import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) INF = 10 ** 10 MOD = 10 ** 9 + 7 from heapq import heapify,heappop,heappush input = sys.stdin.readline def main(): x,y,a,b,c = list(map(int,input().split())) R = list(map(int,input().split())) G = list(map(int,input().split())) M = list(map(int,input().split())) R.sort(reverse = True) G.sort(reverse = True) M.sort(reverse = True) apple = R[:x] + G[:y] + M apple.sort(reverse = True) ans = sum(apple[:x + y]) print(ans) if __name__=='__main__': main()
71
22
1,646
587
import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) INF = 10**10 MOD = 10**9 + 7 from heapq import heapify, heappop, heappush input = sys.stdin.readline def main(): x, y, a, b, c = list(map(int, input().split())) R = list(map(int, input().split())) G = list(map(int, input().split())) M = list(map(int, input().split())) i, j, k = 0, 0, 0 R.sort(reverse=True) G.sort(reverse=True) M.sort(reverse=True) ans = 0 while i < x and j < y and k < c and k + i + j < x + y: tmp = max(R[i], G[j], M[k]) ans += tmp if tmp == R[i]: i += 1 elif tmp == G[j]: j += 1 else: k += 1 if i + j + k == x + y: print(ans) return elif k == c: while i < x and j < y and i + j + c < x + y: tmp = max(R[i], G[j]) ans += tmp if tmp == R[i]: i += 1 elif tmp == G[j]: j += 1 if i + j + k == x + y: print(ans) return elif i == x: t = y - k - j for _ in range(t): if k < c and G[j] < M[k]: ans += M[k] k += 1 else: ans += G[j] j += 1 elif j == y: t = x - i - k for _ in range(t): if k < c and R[i] < M[k]: ans += M[k] k += 1 else: ans += R[i] i += 1 print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) INF = 10**10 MOD = 10**9 + 7 from heapq import heapify, heappop, heappush input = sys.stdin.readline def main(): x, y, a, b, c = list(map(int, input().split())) R = list(map(int, input().split())) G = list(map(int, input().split())) M = list(map(int, input().split())) R.sort(reverse=True) G.sort(reverse=True) M.sort(reverse=True) apple = R[:x] + G[:y] + M apple.sort(reverse=True) ans = sum(apple[: x + y]) print(ans) if __name__ == "__main__": main()
false
69.014085
[ "- i, j, k = 0, 0, 0", "- ans = 0", "- while i < x and j < y and k < c and k + i + j < x + y:", "- tmp = max(R[i], G[j], M[k])", "- ans += tmp", "- if tmp == R[i]:", "- i += 1", "- elif tmp == G[j]:", "- j += 1", "- else:", "- k += 1", "- if i + j + k == x + y:", "- print(ans)", "- return", "- elif k == c:", "- while i < x and j < y and i + j + c < x + y:", "- tmp = max(R[i], G[j])", "- ans += tmp", "- if tmp == R[i]:", "- i += 1", "- elif tmp == G[j]:", "- j += 1", "- if i + j + k == x + y:", "- print(ans)", "- return", "- elif i == x:", "- t = y - k - j", "- for _ in range(t):", "- if k < c and G[j] < M[k]:", "- ans += M[k]", "- k += 1", "- else:", "- ans += G[j]", "- j += 1", "- elif j == y:", "- t = x - i - k", "- for _ in range(t):", "- if k < c and R[i] < M[k]:", "- ans += M[k]", "- k += 1", "- else:", "- ans += R[i]", "- i += 1", "+ apple = R[:x] + G[:y] + M", "+ apple.sort(reverse=True)", "+ ans = sum(apple[: x + y])" ]
false
0.040741
0.110415
0.36898
[ "s988671709", "s696822564" ]
u029000441
p02850
python
s584200081
s037775300
904
655
74,912
74,684
Accepted
Accepted
27.54
#キューとdictionaryを利用したBFS from collections import deque n = int(eval(input())) ab = [list(map(int,input().split())) for i in range(n-1)] ver = [[] for i in range(n)] for i in range(n-1): a,b = ab[i][0],ab[i][1] ver[a-1].append(b-1) ver[b-1].append(a-1) #print(ver) color = [dict() for i in range(n)] q = deque() i = 1 for v in ver[0]: color[0][v] = i color[v][0] = i q.append((0,v)) i += 1 #print(q) while q: f,t = q.popleft() i = 1 for v in ver[t]: if v == f: continue if i == color[f][t]: i += 1 color[t][v] = i color[v][t] = i q.append((t,v)) i += 1 #print(color) #辞書のリストで辺の色を管理している k = 0 for i in range(n): k = max(k,len(ver[i])) print(k) for i in range(n-1): a,b = ab[i][0],ab[i][1] print((color[a-1][b-1]))
#d3と同一解法 n=int(eval(input())) import sys #再帰関数の再帰回数を変更 sys.setrecursionlimit(10**6) s=[[] for _ in range(n)] for i in range(n-1): a,b=list(map(int,input().split())) s[a-1].append((b-1,i)) s[b-1].append((a-1,i)) l=[0]*(n-1) def dfs(node,pre_col,par): col=1 for nei,i in s[node]: if nei==par: continue if col==pre_col: col+=1 l[i]=col dfs(nei,col,node) col+=1 dfs(0,-1,-1) print((max(l))) for i in l: print(i)
49
28
884
512
# キューとdictionaryを利用したBFS from collections import deque n = int(eval(input())) ab = [list(map(int, input().split())) for i in range(n - 1)] ver = [[] for i in range(n)] for i in range(n - 1): a, b = ab[i][0], ab[i][1] ver[a - 1].append(b - 1) ver[b - 1].append(a - 1) # print(ver) color = [dict() for i in range(n)] q = deque() i = 1 for v in ver[0]: color[0][v] = i color[v][0] = i q.append((0, v)) i += 1 # print(q) while q: f, t = q.popleft() i = 1 for v in ver[t]: if v == f: continue if i == color[f][t]: i += 1 color[t][v] = i color[v][t] = i q.append((t, v)) i += 1 # print(color) # 辞書のリストで辺の色を管理している k = 0 for i in range(n): k = max(k, len(ver[i])) print(k) for i in range(n - 1): a, b = ab[i][0], ab[i][1] print((color[a - 1][b - 1]))
# d3と同一解法 n = int(eval(input())) import sys # 再帰関数の再帰回数を変更 sys.setrecursionlimit(10**6) s = [[] for _ in range(n)] for i in range(n - 1): a, b = list(map(int, input().split())) s[a - 1].append((b - 1, i)) s[b - 1].append((a - 1, i)) l = [0] * (n - 1) def dfs(node, pre_col, par): col = 1 for nei, i in s[node]: if nei == par: continue if col == pre_col: col += 1 l[i] = col dfs(nei, col, node) col += 1 dfs(0, -1, -1) print((max(l))) for i in l: print(i)
false
42.857143
[ "-# キューとdictionaryを利用したBFS", "-from collections import deque", "+# d3と同一解法", "+n = int(eval(input()))", "+import sys", "-n = int(eval(input()))", "-ab = [list(map(int, input().split())) for i in range(n - 1)]", "-ver = [[] for i in range(n)]", "+# 再帰関数の再帰回数を変更", "+sys.setrecursionlimit(10**6)", "+s = [[] for _ in range(n)]", "- a, b = ab[i][0], ab[i][1]", "- ver[a - 1].append(b - 1)", "- ver[b - 1].append(a - 1)", "-# print(ver)", "-color = [dict() for i in range(n)]", "-q = deque()", "-i = 1", "-for v in ver[0]:", "- color[0][v] = i", "- color[v][0] = i", "- q.append((0, v))", "- i += 1", "-# print(q)", "-while q:", "- f, t = q.popleft()", "- i = 1", "- for v in ver[t]:", "- if v == f:", "+ a, b = list(map(int, input().split()))", "+ s[a - 1].append((b - 1, i))", "+ s[b - 1].append((a - 1, i))", "+l = [0] * (n - 1)", "+", "+", "+def dfs(node, pre_col, par):", "+ col = 1", "+ for nei, i in s[node]:", "+ if nei == par:", "- if i == color[f][t]:", "- i += 1", "- color[t][v] = i", "- color[v][t] = i", "- q.append((t, v))", "- i += 1", "-# print(color)", "-# 辞書のリストで辺の色を管理している", "-k = 0", "-for i in range(n):", "- k = max(k, len(ver[i]))", "-print(k)", "-for i in range(n - 1):", "- a, b = ab[i][0], ab[i][1]", "- print((color[a - 1][b - 1]))", "+ if col == pre_col:", "+ col += 1", "+ l[i] = col", "+ dfs(nei, col, node)", "+ col += 1", "+", "+", "+dfs(0, -1, -1)", "+print((max(l)))", "+for i in l:", "+ print(i)" ]
false
0.103245
0.037946
2.720871
[ "s584200081", "s037775300" ]
u638282348
p03732
python
s386006971
s366654815
143
84
11,960
3,632
Accepted
Accepted
41.26
N, W = list(map(int, input().split())) data = tuple(tuple(map(int, input().split())) for _ in range(N)) table = [dict() for _ in range(N + 1)] table[0][0] = 0 for n in range(N): weight, value = data[n] for w, now in list(table[n].items()): table[n + 1][w] = max(table[n + 1].get(w, 0), now) if w + weight <= W: table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value) print((max(table[N].values())))
N, W = list(map(int, input().split())) data = tuple(tuple(map(int, input().split())) for _ in range(N)) d = {0: 0} for n in range(N): weight, value = data[n] for w, now in list(d.copy().items()): if w + weight <= W: d[w + weight] = max(d.get(w + weight, 0), now + value) print((max(d.values())))
11
9
451
317
N, W = list(map(int, input().split())) data = tuple(tuple(map(int, input().split())) for _ in range(N)) table = [dict() for _ in range(N + 1)] table[0][0] = 0 for n in range(N): weight, value = data[n] for w, now in list(table[n].items()): table[n + 1][w] = max(table[n + 1].get(w, 0), now) if w + weight <= W: table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value) print((max(table[N].values())))
N, W = list(map(int, input().split())) data = tuple(tuple(map(int, input().split())) for _ in range(N)) d = {0: 0} for n in range(N): weight, value = data[n] for w, now in list(d.copy().items()): if w + weight <= W: d[w + weight] = max(d.get(w + weight, 0), now + value) print((max(d.values())))
false
18.181818
[ "-table = [dict() for _ in range(N + 1)]", "-table[0][0] = 0", "+d = {0: 0}", "- for w, now in list(table[n].items()):", "- table[n + 1][w] = max(table[n + 1].get(w, 0), now)", "+ for w, now in list(d.copy().items()):", "- table[n + 1][w + weight] = max(table[n + 1].get(w + weight, 0), now + value)", "-print((max(table[N].values())))", "+ d[w + weight] = max(d.get(w + weight, 0), now + value)", "+print((max(d.values())))" ]
false
0.037809
0.042996
0.879376
[ "s386006971", "s366654815" ]
u489959379
p02720
python
s276347961
s084848238
265
238
19,996
12,348
Accepted
Accepted
10.19
k = int(eval(input())) a = [] def dfs(x): a.append(x) if x > 3234566667: return for i in range(10): if abs(x % 10 - i) <= 1: dfs(x * 10 + i) for i in range(1, 10): dfs(i) a = sorted(a) print((a[k - 1]))
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): k = int(eval(input())) res = [] def dfs(x): res.append(x) if len(str(x)) == 10: return for i in range(10): if abs(x % 10 - i) <= 1: dfs(x * 10 + i) return for i in range(1, 10): dfs(i) res.sort() print((res[k - 1])) if __name__ == '__main__': resolve()
17
30
259
487
k = int(eval(input())) a = [] def dfs(x): a.append(x) if x > 3234566667: return for i in range(10): if abs(x % 10 - i) <= 1: dfs(x * 10 + i) for i in range(1, 10): dfs(i) a = sorted(a) print((a[k - 1]))
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): k = int(eval(input())) res = [] def dfs(x): res.append(x) if len(str(x)) == 10: return for i in range(10): if abs(x % 10 - i) <= 1: dfs(x * 10 + i) return for i in range(1, 10): dfs(i) res.sort() print((res[k - 1])) if __name__ == "__main__": resolve()
false
43.333333
[ "-k = int(eval(input()))", "-a = []", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "-def dfs(x):", "- a.append(x)", "- if x > 3234566667:", "+def resolve():", "+ k = int(eval(input()))", "+ res = []", "+", "+ def dfs(x):", "+ res.append(x)", "+ if len(str(x)) == 10:", "+ return", "+ for i in range(10):", "+ if abs(x % 10 - i) <= 1:", "+ dfs(x * 10 + i)", "- for i in range(10):", "- if abs(x % 10 - i) <= 1:", "- dfs(x * 10 + i)", "+", "+ for i in range(1, 10):", "+ dfs(i)", "+ res.sort()", "+ print((res[k - 1]))", "-for i in range(1, 10):", "- dfs(i)", "-a = sorted(a)", "-print((a[k - 1]))", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.415483
0.294471
1.410946
[ "s276347961", "s084848238" ]