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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u606045429 | p03716 | python | s648652479 | s973821392 | 473 | 339 | 40,276 | 40,164 | Accepted | Accepted | 28.33 | from heapq import heapify, heappop, heappush
N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for k in range(N, 2 * N):
heappush(Q, A[k])
m = heappop(Q)
R.append(R[-1] + A[k] - m)
Q = [-a for a in A[2 * N:]]
heapify(Q)
B = [sum(Q)]
for k in reversed(list(range(N, 2 * N))):
heappush(Q, -A[k])
m = heappop(Q)
B.append(B[-1] - A[k] - m)
print((max(r + b for r, b in zip(R, reversed(B)))))
| from heapq import heapify, heappop, heappush
N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for a in A[N:2 * N]:
heappush(Q, a)
R.append(R[-1] + a - heappop(Q))
Q = [-a for a in A[2 * N:]]
heapify(Q)
B = [sum(Q)]
for a in reversed(A[N:2 * N]):
heappush(Q, -a)
B.append(B[-1] - a - heappop(Q))
print((max(r + b for r, b in zip(R, reversed(B)))))
| 23 | 21 | 457 | 413 | from heapq import heapify, heappop, heappush
N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for k in range(N, 2 * N):
heappush(Q, A[k])
m = heappop(Q)
R.append(R[-1] + A[k] - m)
Q = [-a for a in A[2 * N :]]
heapify(Q)
B = [sum(Q)]
for k in reversed(list(range(N, 2 * N))):
heappush(Q, -A[k])
m = heappop(Q)
B.append(B[-1] - A[k] - m)
print((max(r + b for r, b in zip(R, reversed(B)))))
| from heapq import heapify, heappop, heappush
N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for a in A[N : 2 * N]:
heappush(Q, a)
R.append(R[-1] + a - heappop(Q))
Q = [-a for a in A[2 * N :]]
heapify(Q)
B = [sum(Q)]
for a in reversed(A[N : 2 * N]):
heappush(Q, -a)
B.append(B[-1] - a - heappop(Q))
print((max(r + b for r, b in zip(R, reversed(B)))))
| false | 8.695652 | [
"-for k in range(N, 2 * N):",
"- heappush(Q, A[k])",
"- m = heappop(Q)",
"- R.append(R[-1] + A[k] - m)",
"+for a in A[N : 2 * N]:",
"+ heappush(Q, a)",
"+ R.append(R[-1] + a - heappop(Q))",
"-for k in reversed(list(range(N, 2 * N))):",
"- heappush(Q, -A[k])",
"- m = heappop(Q)",
"- B.append(B[-1] - A[k] - m)",
"+for a in reversed(A[N : 2 * N]):",
"+ heappush(Q, -a)",
"+ B.append(B[-1] - a - heappop(Q))"
] | false | 0.047595 | 0.094344 | 0.504486 | [
"s648652479",
"s973821392"
] |
u079022693 | p02624 | python | s351705934 | s918816484 | 607 | 540 | 339,776 | 261,252 | Accepted | Accepted | 11.04 | import numpy as np
n=int(eval(input()))
a=np.arange(1,n+1)
b=n//a*a
c=n//a
print(((c*(a+b)//2).sum())) | import numpy as np
n=int(eval(input()))
a=np.arange(1,n+1)
print(((n//a*(a+n//a*a)//2).sum())) | 6 | 4 | 99 | 89 | import numpy as np
n = int(eval(input()))
a = np.arange(1, n + 1)
b = n // a * a
c = n // a
print(((c * (a + b) // 2).sum()))
| import numpy as np
n = int(eval(input()))
a = np.arange(1, n + 1)
print(((n // a * (a + n // a * a) // 2).sum()))
| false | 33.333333 | [
"-b = n // a * a",
"-c = n // a",
"-print(((c * (a + b) // 2).sum()))",
"+print(((n // a * (a + n // a * a) // 2).sum()))"
] | false | 0.467237 | 0.52052 | 0.897634 | [
"s351705934",
"s918816484"
] |
u615576660 | p02687 | python | s888476930 | s375036835 | 22 | 20 | 8,956 | 9,064 | Accepted | Accepted | 9.09 | contest = eval(input())
S = 'ABC'
if contest == S :
print('ARC')
else:
print('ABC') | if eval(input()) == "ARC":
print('ABC')
else:
print('ARC') | 6 | 4 | 90 | 63 | contest = eval(input())
S = "ABC"
if contest == S:
print("ARC")
else:
print("ABC")
| if eval(input()) == "ARC":
print("ABC")
else:
print("ARC")
| false | 33.333333 | [
"-contest = eval(input())",
"-S = \"ABC\"",
"-if contest == S:",
"+if eval(input()) == \"ARC\":",
"+ print(\"ABC\")",
"+else:",
"-else:",
"- print(\"ABC\")"
] | false | 0.038174 | 0.040572 | 0.940902 | [
"s888476930",
"s375036835"
] |
u334712262 | p02563 | python | s957410994 | s719832173 | 1,431 | 804 | 196,596 | 196,420 | Accepted | Accepted | 43.82 |
def butterfly(arr, MOD):
n = len(arr)
h = (n - 1).bit_length()
sum_e = (911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601,
842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for ph in range(1, h + 1):
w = 1 << (ph - 1)
p = 1 << (h - ph)
now = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p] * now
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (l - r) % MOD
now *= sum_e[(~s & -~s).bit_length() - 1]
now %= MOD
def butterfly_inv(arr, MOD):
n = len(arr)
h = (n - 1).bit_length()
sum_ie = (86583718, 372528824, 373294451, 645684063, 112220581, 692852209, 155456985, 797128860, 90816748, 860285882, 927414960, 354738543,
109331171, 293255632, 535113200, 308540755, 121186627, 608385704, 438932459, 359477183, 824071951, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for ph in range(1, h + 1)[::-1]:
w = 1 << (ph - 1)
p = 1 << (h - ph)
inow = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p]
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (MOD + l - r) * inow % MOD
inow *= sum_ie[(~s & -~s).bit_length() - 1]
inow %= MOD
def convolution(a, b, MOD=10**9+7):
n = len(a)
m = len(b)
if not n or not m: return []
if min(n, m) <= 50:
if n < m:
n, m = m, n
a, b = b, a
res = [0] * (n + m - 1)
for i in range(n):
for j in range(m):
res[i + j] += a[i] * b[j]
res[i + j] %= MOD
return res
z = 1 << (n + m - 2).bit_length()
a += [0] * (z - n)
b += [0] * (z - m)
butterfly(a, MOD)
butterfly(b, MOD)
for i in range(z):
a[i] *= b[i]
a[i] %= MOD
butterfly_inv(a, MOD)
a = a[:n + m - 1]
iz = pow(z, MOD - 2, MOD)
for i in range(n + m - 1):
a[i] *= iz
a[i] %= MOD
return a
import sys
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print((*convolution(A, B, 998244353)))
# def atcoder_practice2_f():
# import sys
# input = sys.stdin.buffer.readline
# N, M = map(int, input().split())
# A = [int(x) for x in input().split()]
# B = [int(x) for x in input().split()]
# print(*convolution(A, B, 998244353))
# if __name__ == "__main__":
# atcoder_practice2_f()
| MOD = 998244353
def butterfly(arr):
n = len(arr)
h = (n - 1).bit_length()
sum_e = (911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601,
842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for ph in range(1, h + 1):
w = 1 << (ph - 1)
p = 1 << (h - ph)
now = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p] * now
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (l - r) % MOD
now *= sum_e[(~s & -~s).bit_length() - 1]
now %= MOD
def butterfly_inv(arr):
n = len(arr)
h = (n - 1).bit_length()
sum_ie = (86583718, 372528824, 373294451, 645684063, 112220581, 692852209, 155456985, 797128860, 90816748, 860285882, 927414960, 354738543,
109331171, 293255632, 535113200, 308540755, 121186627, 608385704, 438932459, 359477183, 824071951, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for ph in range(1, h + 1)[::-1]:
w = 1 << (ph - 1)
p = 1 << (h - ph)
inow = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p]
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (MOD + l - r) * inow % MOD
inow *= sum_ie[(~s & -~s).bit_length() - 1]
inow %= MOD
def convolution(a, b):
n = len(a)
m = len(b)
if not n or not m: return []
if min(n, m) <= 50:
if n < m:
n, m = m, n
a, b = b, a
res = [0] * (n + m - 1)
for i in range(n):
for j in range(m):
res[i + j] += a[i] * b[j]
res[i + j] %= MOD
return res
z = 1 << (n + m - 2).bit_length()
a += [0] * (z - n)
b += [0] * (z - m)
butterfly(a)
butterfly(b)
for i in range(z):
a[i] *= b[i]
a[i] %= MOD
butterfly_inv(a)
a = a[:n + m - 1]
iz = pow(z, MOD - 2, MOD)
for i in range(n + m - 1):
a[i] *= iz
a[i] %= MOD
return a
def atcoder_practice2_f():
import sys
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print((*convolution(A, B)))
if __name__ == "__main__":
atcoder_practice2_f()
| 94 | 86 | 2,983 | 2,730 | def butterfly(arr, MOD):
n = len(arr)
h = (n - 1).bit_length()
sum_e = (
911660635,
509520358,
369330050,
332049552,
983190778,
123842337,
238493703,
975955924,
603855026,
856644456,
131300601,
842657263,
730768835,
942482514,
806263778,
151565301,
510815449,
503497456,
743006876,
741047443,
56250497,
0,
0,
0,
0,
0,
0,
0,
0,
0,
)
for ph in range(1, h + 1):
w = 1 << (ph - 1)
p = 1 << (h - ph)
now = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p] * now
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (l - r) % MOD
now *= sum_e[(~s & -~s).bit_length() - 1]
now %= MOD
def butterfly_inv(arr, MOD):
n = len(arr)
h = (n - 1).bit_length()
sum_ie = (
86583718,
372528824,
373294451,
645684063,
112220581,
692852209,
155456985,
797128860,
90816748,
860285882,
927414960,
354738543,
109331171,
293255632,
535113200,
308540755,
121186627,
608385704,
438932459,
359477183,
824071951,
0,
0,
0,
0,
0,
0,
0,
0,
0,
)
for ph in range(1, h + 1)[::-1]:
w = 1 << (ph - 1)
p = 1 << (h - ph)
inow = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p]
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (MOD + l - r) * inow % MOD
inow *= sum_ie[(~s & -~s).bit_length() - 1]
inow %= MOD
def convolution(a, b, MOD=10**9 + 7):
n = len(a)
m = len(b)
if not n or not m:
return []
if min(n, m) <= 50:
if n < m:
n, m = m, n
a, b = b, a
res = [0] * (n + m - 1)
for i in range(n):
for j in range(m):
res[i + j] += a[i] * b[j]
res[i + j] %= MOD
return res
z = 1 << (n + m - 2).bit_length()
a += [0] * (z - n)
b += [0] * (z - m)
butterfly(a, MOD)
butterfly(b, MOD)
for i in range(z):
a[i] *= b[i]
a[i] %= MOD
butterfly_inv(a, MOD)
a = a[: n + m - 1]
iz = pow(z, MOD - 2, MOD)
for i in range(n + m - 1):
a[i] *= iz
a[i] %= MOD
return a
import sys
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print((*convolution(A, B, 998244353)))
# def atcoder_practice2_f():
# import sys
# input = sys.stdin.buffer.readline
# N, M = map(int, input().split())
# A = [int(x) for x in input().split()]
# B = [int(x) for x in input().split()]
# print(*convolution(A, B, 998244353))
# if __name__ == "__main__":
# atcoder_practice2_f()
| MOD = 998244353
def butterfly(arr):
n = len(arr)
h = (n - 1).bit_length()
sum_e = (
911660635,
509520358,
369330050,
332049552,
983190778,
123842337,
238493703,
975955924,
603855026,
856644456,
131300601,
842657263,
730768835,
942482514,
806263778,
151565301,
510815449,
503497456,
743006876,
741047443,
56250497,
0,
0,
0,
0,
0,
0,
0,
0,
0,
)
for ph in range(1, h + 1):
w = 1 << (ph - 1)
p = 1 << (h - ph)
now = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p] * now
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (l - r) % MOD
now *= sum_e[(~s & -~s).bit_length() - 1]
now %= MOD
def butterfly_inv(arr):
n = len(arr)
h = (n - 1).bit_length()
sum_ie = (
86583718,
372528824,
373294451,
645684063,
112220581,
692852209,
155456985,
797128860,
90816748,
860285882,
927414960,
354738543,
109331171,
293255632,
535113200,
308540755,
121186627,
608385704,
438932459,
359477183,
824071951,
0,
0,
0,
0,
0,
0,
0,
0,
0,
)
for ph in range(1, h + 1)[::-1]:
w = 1 << (ph - 1)
p = 1 << (h - ph)
inow = 1
for s in range(w):
offset = s << (h - ph + 1)
for i in range(p):
l = arr[i + offset]
r = arr[i + offset + p]
arr[i + offset] = (l + r) % MOD
arr[i + offset + p] = (MOD + l - r) * inow % MOD
inow *= sum_ie[(~s & -~s).bit_length() - 1]
inow %= MOD
def convolution(a, b):
n = len(a)
m = len(b)
if not n or not m:
return []
if min(n, m) <= 50:
if n < m:
n, m = m, n
a, b = b, a
res = [0] * (n + m - 1)
for i in range(n):
for j in range(m):
res[i + j] += a[i] * b[j]
res[i + j] %= MOD
return res
z = 1 << (n + m - 2).bit_length()
a += [0] * (z - n)
b += [0] * (z - m)
butterfly(a)
butterfly(b)
for i in range(z):
a[i] *= b[i]
a[i] %= MOD
butterfly_inv(a)
a = a[: n + m - 1]
iz = pow(z, MOD - 2, MOD)
for i in range(n + m - 1):
a[i] *= iz
a[i] %= MOD
return a
def atcoder_practice2_f():
import sys
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print((*convolution(A, B)))
if __name__ == "__main__":
atcoder_practice2_f()
| false | 8.510638 | [
"-def butterfly(arr, MOD):",
"+MOD = 998244353",
"+",
"+",
"+def butterfly(arr):",
"-def butterfly_inv(arr, MOD):",
"+def butterfly_inv(arr):",
"-def convolution(a, b, MOD=10**9 + 7):",
"+def convolution(a, b):",
"- butterfly(a, MOD)",
"- butterfly(b, MOD)",
"+ butterfly(a)",
"+ butterfly(b)",
"- butterfly_inv(a, MOD)",
"+ butterfly_inv(a)",
"-import sys",
"+def atcoder_practice2_f():",
"+ import sys",
"-input = sys.stdin.buffer.readline",
"-N, M = list(map(int, input().split()))",
"-A = [int(x) for x in input().split()]",
"-B = [int(x) for x in input().split()]",
"-print((*convolution(A, B, 998244353)))",
"-# def atcoder_practice2_f():",
"-# import sys",
"-# input = sys.stdin.buffer.readline",
"-# N, M = map(int, input().split())",
"-# A = [int(x) for x in input().split()]",
"-# B = [int(x) for x in input().split()]",
"-# print(*convolution(A, B, 998244353))",
"-# if __name__ == \"__main__\":",
"-# atcoder_practice2_f()",
"+ input = sys.stdin.buffer.readline",
"+ N, M = list(map(int, input().split()))",
"+ A = [int(x) for x in input().split()]",
"+ B = [int(x) for x in input().split()]",
"+ print((*convolution(A, B)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ atcoder_practice2_f()"
] | false | 0.046664 | 0.129218 | 0.361127 | [
"s957410994",
"s719832173"
] |
u490642448 | p02632 | python | s864268640 | s593801058 | 1,042 | 337 | 133,368 | 133,256 | Accepted | Accepted | 67.66 | k = int(eval(input()))
s = eval(input())
n = len(s)
mod = 10**9 + 7
## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 2 * 10**6 + 100
fac, finv, inv = [0]*max, [0]*max, [0]*max
def comInit(max):
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,max):
fac[i] = fac[i-1]* i% mod
inv[i] = mod - inv[mod%i] * (mod // i) % mod
finv[i] = finv[i-1] * inv[i] % mod
comInit(max)
# 二項係数の計算
def com(n,k):
if(n < k):
return 0
if( (n<0) | (k < 0)):
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
ans = 0
ex25 = [1] * (k+1)
ex26 = [1] * (k+1)
for i in range(1,k+1):
ex25[i] = (ex25[i-1] * 25)%mod
ex26[i] = (ex26[i-1] * 26)%mod
for i in range(k+1):
j = k-i
tmp = pow(25,i,mod) * com(n+i-1,i) * pow(26,j,mod)
tmp = ex25[i] * com(n+i-1,i) * ex26[j]
ans = (ans+tmp)%mod
print(ans) | k = int(eval(input()))
s = eval(input())
n = len(s)
mod = 10**9 + 7
## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 2 * 10**6 + 100
fac, finv, inv = [0]*max, [0]*max, [0]*max
def comInit(max):
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,max):
fac[i] = fac[i-1]* i% mod
inv[i] = mod - inv[mod%i] * (mod // i) % mod
finv[i] = finv[i-1] * inv[i] % mod
comInit(max)
# 二項係数の計算
def com(n,k):
if(n < k):
return 0
if( (n<0) | (k < 0)):
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
ans = 0
ex25 = [1] * (k+1)
ex26 = [1] * (k+1)
for i in range(1,k+1):
ex25[i] = (ex25[i-1] * 25)%mod
ex26[i] = (ex26[i-1] * 26)%mod
for i in range(k+1):
j = k-i
tmp = ex25[i] * com(n+i-1,i) * ex26[j]
ans = (ans+tmp)%mod
print(ans) | 45 | 44 | 910 | 854 | k = int(eval(input()))
s = eval(input())
n = len(s)
mod = 10**9 + 7
## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 2 * 10**6 + 100
fac, finv, inv = [0] * max, [0] * max, [0] * max
def comInit(max):
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, max):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
comInit(max)
# 二項係数の計算
def com(n, k):
if n < k:
return 0
if (n < 0) | (k < 0):
return 0
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
ans = 0
ex25 = [1] * (k + 1)
ex26 = [1] * (k + 1)
for i in range(1, k + 1):
ex25[i] = (ex25[i - 1] * 25) % mod
ex26[i] = (ex26[i - 1] * 26) % mod
for i in range(k + 1):
j = k - i
tmp = pow(25, i, mod) * com(n + i - 1, i) * pow(26, j, mod)
tmp = ex25[i] * com(n + i - 1, i) * ex26[j]
ans = (ans + tmp) % mod
print(ans)
| k = int(eval(input()))
s = eval(input())
n = len(s)
mod = 10**9 + 7
## nCkのmodを求める関数
# テーブルを作る(前処理)
max = 2 * 10**6 + 100
fac, finv, inv = [0] * max, [0] * max, [0] * max
def comInit(max):
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, max):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
comInit(max)
# 二項係数の計算
def com(n, k):
if n < k:
return 0
if (n < 0) | (k < 0):
return 0
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
ans = 0
ex25 = [1] * (k + 1)
ex26 = [1] * (k + 1)
for i in range(1, k + 1):
ex25[i] = (ex25[i - 1] * 25) % mod
ex26[i] = (ex26[i - 1] * 26) % mod
for i in range(k + 1):
j = k - i
tmp = ex25[i] * com(n + i - 1, i) * ex26[j]
ans = (ans + tmp) % mod
print(ans)
| false | 2.222222 | [
"- tmp = pow(25, i, mod) * com(n + i - 1, i) * pow(26, j, mod)"
] | false | 0.181602 | 0.157108 | 1.155907 | [
"s864268640",
"s593801058"
] |
u758815106 | p03165 | python | s890431646 | s168659926 | 328 | 284 | 144,500 | 144,592 | Accepted | Accepted | 13.41 | #import
#import math
#import numpy as np
#= int(input())
#= input()
#= map(int, input().split())
#= [input(), input()]
s = eval(input())
t = eval(input())
sl = len(s)
tl = len(t)
dp = [[0] * (tl + 1) for _ in range(sl + 1)]
for i in range(1, sl + 1):
for j in range(1, tl + 1):
if s[i-1] == t[j-1]:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
res = ""
i = sl
j = tl
while i > 0 and j > 0:
if dp[i - 1][j] == dp[i][j]:
i -= 1
elif dp[i][j - 1] == dp[i][j]:
j -= 1
else:
res = s[i - 1] + res
i -= 1
j -= 1
print(res) | #!/usr/bin/env python3
#import
#import math
#import numpy as np
#= int(input())
S = eval(input())
T = eval(input())
ls = len(S)
lt = len(T)
dp = [[0] * (lt + 1) for _ in range(ls + 1)]
for i in range(1, ls + 1):
for j in range(1, lt + 1):
if S[i - 1] == T[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
i = ls
j = lt
ans = ""
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
ans = S[i - 1] + ans
i -= 1
j -= 1
print(ans)
| 38 | 39 | 689 | 673 | # import
# import math
# import numpy as np
# = int(input())
# = input()
# = map(int, input().split())
# = [input(), input()]
s = eval(input())
t = eval(input())
sl = len(s)
tl = len(t)
dp = [[0] * (tl + 1) for _ in range(sl + 1)]
for i in range(1, sl + 1):
for j in range(1, tl + 1):
if s[i - 1] == t[j - 1]:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
res = ""
i = sl
j = tl
while i > 0 and j > 0:
if dp[i - 1][j] == dp[i][j]:
i -= 1
elif dp[i][j - 1] == dp[i][j]:
j -= 1
else:
res = s[i - 1] + res
i -= 1
j -= 1
print(res)
| #!/usr/bin/env python3
# import
# import math
# import numpy as np
# = int(input())
S = eval(input())
T = eval(input())
ls = len(S)
lt = len(T)
dp = [[0] * (lt + 1) for _ in range(ls + 1)]
for i in range(1, ls + 1):
for j in range(1, lt + 1):
if S[i - 1] == T[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
i = ls
j = lt
ans = ""
while i > 0 and j > 0:
if dp[i][j] == dp[i - 1][j]:
i -= 1
elif dp[i][j] == dp[i][j - 1]:
j -= 1
else:
ans = S[i - 1] + ans
i -= 1
j -= 1
print(ans)
| false | 2.564103 | [
"+#!/usr/bin/env python3",
"-# = input()",
"-# = map(int, input().split())",
"-# = [input(), input()]",
"-s = eval(input())",
"-t = eval(input())",
"-sl = len(s)",
"-tl = len(t)",
"-dp = [[0] * (tl + 1) for _ in range(sl + 1)]",
"-for i in range(1, sl + 1):",
"- for j in range(1, tl + 1):",
"- if s[i - 1] == t[j - 1]:",
"- dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)",
"- dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])",
"-res = \"\"",
"-i = sl",
"-j = tl",
"+S = eval(input())",
"+T = eval(input())",
"+ls = len(S)",
"+lt = len(T)",
"+dp = [[0] * (lt + 1) for _ in range(ls + 1)]",
"+for i in range(1, ls + 1):",
"+ for j in range(1, lt + 1):",
"+ if S[i - 1] == T[j - 1]:",
"+ dp[i][j] = dp[i - 1][j - 1] + 1",
"+ else:",
"+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])",
"+i = ls",
"+j = lt",
"+ans = \"\"",
"- if dp[i - 1][j] == dp[i][j]:",
"+ if dp[i][j] == dp[i - 1][j]:",
"- elif dp[i][j - 1] == dp[i][j]:",
"+ elif dp[i][j] == dp[i][j - 1]:",
"- res = s[i - 1] + res",
"+ ans = S[i - 1] + ans",
"-print(res)",
"+print(ans)"
] | false | 0.045359 | 0.045689 | 0.992776 | [
"s890431646",
"s168659926"
] |
u246401133 | p02658 | python | s372524490 | s369321314 | 73 | 63 | 21,632 | 21,632 | Accepted | Accepted | 13.7 | n = int(eval(input()))
a = list(map(int, input().split()))
i = 1
if 0 in a:
i = 0
else:
for j in range(n):
if i >= 0:
i = i * a[j]
if i > 10 ** 18:
i = -1
print((int(i))) | n = int(eval(input()))
a = list(map(int, input().split()))
x = 1
if 0 in a:
x = 0
else:
for i in range(n):
if x != -1:
x = x * a[i]
if x > 10 ** 18:
x = -1
print(x) | 12 | 12 | 221 | 217 | n = int(eval(input()))
a = list(map(int, input().split()))
i = 1
if 0 in a:
i = 0
else:
for j in range(n):
if i >= 0:
i = i * a[j]
if i > 10**18:
i = -1
print((int(i)))
| n = int(eval(input()))
a = list(map(int, input().split()))
x = 1
if 0 in a:
x = 0
else:
for i in range(n):
if x != -1:
x = x * a[i]
if x > 10**18:
x = -1
print(x)
| false | 0 | [
"-i = 1",
"+x = 1",
"- i = 0",
"+ x = 0",
"- for j in range(n):",
"- if i >= 0:",
"- i = i * a[j]",
"- if i > 10**18:",
"- i = -1",
"-print((int(i)))",
"+ for i in range(n):",
"+ if x != -1:",
"+ x = x * a[i]",
"+ if x > 10**18:",
"+ x = -1",
"+print(x)"
] | false | 0.043644 | 0.047161 | 0.925416 | [
"s372524490",
"s369321314"
] |
u707498674 | p03309 | python | s238048740 | s577233856 | 209 | 190 | 25,968 | 27,580 | Accepted | Accepted | 9.09 | import math
N = int(eval(input()))
A = list(map(int, input().split()))
A = [A[i] - i - 1 for i in range(N)]
A.sort()
c = int(math.floor(N/2))
answer = sum(list(map(abs,[A[i] - A[c] for i in range(N)])))
print(answer) | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
B = sorted([A[i] - (i+1) for i in range(N)])
b = B[N//2]
print((sum([abs(val - b) for val in B])))
if __name__ == "__main__":
main() | 8 | 9 | 217 | 228 | import math
N = int(eval(input()))
A = list(map(int, input().split()))
A = [A[i] - i - 1 for i in range(N)]
A.sort()
c = int(math.floor(N / 2))
answer = sum(list(map(abs, [A[i] - A[c] for i in range(N)])))
print(answer)
| def main():
N = int(eval(input()))
A = list(map(int, input().split()))
B = sorted([A[i] - (i + 1) for i in range(N)])
b = B[N // 2]
print((sum([abs(val - b) for val in B])))
if __name__ == "__main__":
main()
| false | 11.111111 | [
"-import math",
"+def main():",
"+ N = int(eval(input()))",
"+ A = list(map(int, input().split()))",
"+ B = sorted([A[i] - (i + 1) for i in range(N)])",
"+ b = B[N // 2]",
"+ print((sum([abs(val - b) for val in B])))",
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-A = [A[i] - i - 1 for i in range(N)]",
"-A.sort()",
"-c = int(math.floor(N / 2))",
"-answer = sum(list(map(abs, [A[i] - A[c] for i in range(N)])))",
"-print(answer)",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.03815 | 0.096894 | 0.393733 | [
"s238048740",
"s577233856"
] |
u112317104 | p02837 | python | s812571898 | s361532964 | 778 | 582 | 3,064 | 3,064 | Accepted | Accepted | 25.19 | def int_to_list(bit, n):
l = []
for i in range(n):
if bit & (1 << i):
l.append(i)
return l
def solve():
N = int(eval(input()))
l = [[] for _ in range(N)]
for i in range(N):
for _ in range(int(eval(input()))):
p, q = list(map(int, input().split()))
l[i].append((p-1, q))
ans = 0
for i in range(1 << N):
partial = int_to_list(i, N)
f = True
for j in range(N):
if j not in partial: continue
for p, q in l[j]:
if q == 0 and p in partial:
f = False
if q == 1 and not p in partial:
f = False
if f:
ans = max(ans, len(partial))
return ans
print((solve())) | def int_to_list(bit, n):
l = []
for i in range(n):
if bit & (1 << i):
l.append(i)
return l
def solve():
N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
B = int(eval(input()))
for _ in range(B):
x, y = list(map(int, input().split()))
A[i].append((x-1, y))
ans = 0
for i in range(1 << N):
f = True
# 正直者のリスト
partial = int_to_list(i, N)
for p in partial:
for (a, b) in A[p]:
if b == 1:
if not a in partial:
f = False
else:
if a in partial:
f = False
if f:
ans = max(ans, len(partial))
return ans
print((solve())) | 34 | 35 | 805 | 828 | def int_to_list(bit, n):
l = []
for i in range(n):
if bit & (1 << i):
l.append(i)
return l
def solve():
N = int(eval(input()))
l = [[] for _ in range(N)]
for i in range(N):
for _ in range(int(eval(input()))):
p, q = list(map(int, input().split()))
l[i].append((p - 1, q))
ans = 0
for i in range(1 << N):
partial = int_to_list(i, N)
f = True
for j in range(N):
if j not in partial:
continue
for p, q in l[j]:
if q == 0 and p in partial:
f = False
if q == 1 and not p in partial:
f = False
if f:
ans = max(ans, len(partial))
return ans
print((solve()))
| def int_to_list(bit, n):
l = []
for i in range(n):
if bit & (1 << i):
l.append(i)
return l
def solve():
N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
B = int(eval(input()))
for _ in range(B):
x, y = list(map(int, input().split()))
A[i].append((x - 1, y))
ans = 0
for i in range(1 << N):
f = True
# 正直者のリスト
partial = int_to_list(i, N)
for p in partial:
for (a, b) in A[p]:
if b == 1:
if not a in partial:
f = False
else:
if a in partial:
f = False
if f:
ans = max(ans, len(partial))
return ans
print((solve()))
| false | 2.857143 | [
"- l = [[] for _ in range(N)]",
"+ A = [[] for _ in range(N)]",
"- for _ in range(int(eval(input()))):",
"- p, q = list(map(int, input().split()))",
"- l[i].append((p - 1, q))",
"+ B = int(eval(input()))",
"+ for _ in range(B):",
"+ x, y = list(map(int, input().split()))",
"+ A[i].append((x - 1, y))",
"+ f = True",
"+ # 正直者のリスト",
"- f = True",
"- for j in range(N):",
"- if j not in partial:",
"- continue",
"- for p, q in l[j]:",
"- if q == 0 and p in partial:",
"- f = False",
"- if q == 1 and not p in partial:",
"- f = False",
"+ for p in partial:",
"+ for (a, b) in A[p]:",
"+ if b == 1:",
"+ if not a in partial:",
"+ f = False",
"+ else:",
"+ if a in partial:",
"+ f = False"
] | false | 0.086545 | 0.044553 | 1.942511 | [
"s812571898",
"s361532964"
] |
u576917603 | p03212 | python | s663830529 | s741966059 | 87 | 54 | 4,320 | 6,756 | Accepted | Accepted | 37.93 | n=int(eval(input()))
option=[3,5,7]
completed=[]
a=[3,5,7]
ans=0
while option:
number=option.pop()
completed.append(number)
for add_number in a:
new_number=number*10+add_number
if new_number<=n:
option.append(new_number)
for i in completed:
i=list(str(i))
i=set(i)
if len(set(i))==3:
ans+=1
print(ans) | n=int(eval(input()))
import itertools as it
ans=0
for i in range(3,len(str(n))+1):
pr=list(it.product("753",repeat=i))
for j in pr:
s=set(j)
if len(s)==3:
num=int(''.join(j))
if num<=n:
ans+=1
print(ans) | 18 | 14 | 372 | 280 | n = int(eval(input()))
option = [3, 5, 7]
completed = []
a = [3, 5, 7]
ans = 0
while option:
number = option.pop()
completed.append(number)
for add_number in a:
new_number = number * 10 + add_number
if new_number <= n:
option.append(new_number)
for i in completed:
i = list(str(i))
i = set(i)
if len(set(i)) == 3:
ans += 1
print(ans)
| n = int(eval(input()))
import itertools as it
ans = 0
for i in range(3, len(str(n)) + 1):
pr = list(it.product("753", repeat=i))
for j in pr:
s = set(j)
if len(s) == 3:
num = int("".join(j))
if num <= n:
ans += 1
print(ans)
| false | 22.222222 | [
"-option = [3, 5, 7]",
"-completed = []",
"-a = [3, 5, 7]",
"+import itertools as it",
"+",
"-while option:",
"- number = option.pop()",
"- completed.append(number)",
"- for add_number in a:",
"- new_number = number * 10 + add_number",
"- if new_number <= n:",
"- option.append(new_number)",
"-for i in completed:",
"- i = list(str(i))",
"- i = set(i)",
"- if len(set(i)) == 3:",
"- ans += 1",
"+for i in range(3, len(str(n)) + 1):",
"+ pr = list(it.product(\"753\", repeat=i))",
"+ for j in pr:",
"+ s = set(j)",
"+ if len(s) == 3:",
"+ num = int(\"\".join(j))",
"+ if num <= n:",
"+ ans += 1"
] | false | 0.117511 | 0.05506 | 2.134221 | [
"s663830529",
"s741966059"
] |
u353797797 | p03078 | python | s586428704 | s525810164 | 1,558 | 860 | 4,976 | 4,980 | Accepted | Accepted | 44.8 | an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)
ans = [a[0] + b[0] + c[0]]
hq = [[a[0] + b[0] + c[0], 0, 0, 0]]
sumi = [[0, 0, 0]]
for _ in range(k - 1):
mx = hq[0][0]
ai = hq[0][1]
bi = hq[0][2]
ci = hq[0][3]
hq = hq[1:]
if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
hq += [[mx - a[ai] + a[ai + 1], ai + 1, bi, ci]]
sumi += [[ai + 1, bi, ci]]
if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
hq += [[mx - b[bi] + b[bi + 1], ai, bi + 1, ci]]
sumi += [[ai, bi + 1, ci]]
if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
hq += [[mx - c[ci] + c[ci + 1], ai, bi, ci + 1]]
sumi += [[ai, bi, ci + 1]]
hq.sort(reverse=True)
ans += [hq[0][0]]
print(*ans,sep="\n")
| from heapq import *
an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)
ans = []
hp = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapify(hp)
sumi = [[0, 0, 0]]
for _ in range(k):
hpk = heappop(hp)
mx = hpk[0]
ai = hpk[1]
bi = hpk[2]
ci = hpk[3]
if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
heappush(hp, [mx + a[ai] - a[ai + 1], ai + 1, bi, ci])
sumi += [[ai + 1, bi, ci]]
if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
heappush(hp, [mx + b[bi] - b[bi + 1], ai, bi + 1, ci])
sumi += [[ai, bi + 1, ci]]
if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
heappush(hp, [mx + c[ci] - c[ci + 1], ai, bi, ci + 1])
sumi += [[ai, bi, ci + 1]]
ans += [-mx]
print(*ans, sep="\n")
| 33 | 35 | 981 | 983 | an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)
ans = [a[0] + b[0] + c[0]]
hq = [[a[0] + b[0] + c[0], 0, 0, 0]]
sumi = [[0, 0, 0]]
for _ in range(k - 1):
mx = hq[0][0]
ai = hq[0][1]
bi = hq[0][2]
ci = hq[0][3]
hq = hq[1:]
if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
hq += [[mx - a[ai] + a[ai + 1], ai + 1, bi, ci]]
sumi += [[ai + 1, bi, ci]]
if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
hq += [[mx - b[bi] + b[bi + 1], ai, bi + 1, ci]]
sumi += [[ai, bi + 1, ci]]
if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
hq += [[mx - c[ci] + c[ci + 1], ai, bi, ci + 1]]
sumi += [[ai, bi, ci + 1]]
hq.sort(reverse=True)
ans += [hq[0][0]]
print(*ans, sep="\n")
| from heapq import *
an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)
ans = []
hp = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapify(hp)
sumi = [[0, 0, 0]]
for _ in range(k):
hpk = heappop(hp)
mx = hpk[0]
ai = hpk[1]
bi = hpk[2]
ci = hpk[3]
if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
heappush(hp, [mx + a[ai] - a[ai + 1], ai + 1, bi, ci])
sumi += [[ai + 1, bi, ci]]
if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
heappush(hp, [mx + b[bi] - b[bi + 1], ai, bi + 1, ci])
sumi += [[ai, bi + 1, ci]]
if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
heappush(hp, [mx + c[ci] - c[ci + 1], ai, bi, ci + 1])
sumi += [[ai, bi, ci + 1]]
ans += [-mx]
print(*ans, sep="\n")
| false | 5.714286 | [
"+from heapq import *",
"+",
"-ans = [a[0] + b[0] + c[0]]",
"-hq = [[a[0] + b[0] + c[0], 0, 0, 0]]",
"+ans = []",
"+hp = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]",
"+heapify(hp)",
"-for _ in range(k - 1):",
"- mx = hq[0][0]",
"- ai = hq[0][1]",
"- bi = hq[0][2]",
"- ci = hq[0][3]",
"- hq = hq[1:]",
"+for _ in range(k):",
"+ hpk = heappop(hp)",
"+ mx = hpk[0]",
"+ ai = hpk[1]",
"+ bi = hpk[2]",
"+ ci = hpk[3]",
"- hq += [[mx - a[ai] + a[ai + 1], ai + 1, bi, ci]]",
"+ heappush(hp, [mx + a[ai] - a[ai + 1], ai + 1, bi, ci])",
"- hq += [[mx - b[bi] + b[bi + 1], ai, bi + 1, ci]]",
"+ heappush(hp, [mx + b[bi] - b[bi + 1], ai, bi + 1, ci])",
"- hq += [[mx - c[ci] + c[ci + 1], ai, bi, ci + 1]]",
"+ heappush(hp, [mx + c[ci] - c[ci + 1], ai, bi, ci + 1])",
"- hq.sort(reverse=True)",
"- ans += [hq[0][0]]",
"+ ans += [-mx]"
] | false | 0.063151 | 0.080249 | 0.786935 | [
"s586428704",
"s525810164"
] |
u762540523 | p02747 | python | s311018134 | s146496563 | 19 | 17 | 3,188 | 2,940 | Accepted | Accepted | 10.53 | import re;print((re.match('(hi)+$',eval(input()))and'Yes'or'No')) | print(("NYoe s"[eval(input())in["hi"*x for x in range(6)]::2])) | 1 | 1 | 57 | 55 | import re
print((re.match("(hi)+$", eval(input())) and "Yes" or "No"))
| print(("NYoe s"[eval(input()) in ["hi" * x for x in range(6)] :: 2]))
| false | 0 | [
"-import re",
"-",
"-print((re.match(\"(hi)+$\", eval(input())) and \"Yes\" or \"No\"))",
"+print((\"NYoe s\"[eval(input()) in [\"hi\" * x for x in range(6)] :: 2]))"
] | false | 0.067273 | 0.150121 | 0.448123 | [
"s311018134",
"s146496563"
] |
u018168283 | p02660 | python | s466925985 | s348176555 | 267 | 245 | 9,120 | 9,260 | Accepted | Accepted | 8.24 | n = int(eval(input()))
ans = 0
i = 2
while n>1 and i*i<=n:
if n % i == 0:
c = 0
while n % i == 0:
n = n / i
c = c + 1
Y=1
U=2
while c>=Y:
ans=ans+1
Y=Y+U
U=U+1
i = i + 1
if n > 1:
ans = 1 + ans
print(ans) | n = int(eval(input()))
ans = 0
i = 2
while n>1 and i*i<=n:
if n % i == 0:
c = 0
while n % i == 0:
n = n / i
c = c + 1
Y=1
U=2
while c>=Y:
ans=ans+1
Y=Y+U
U=U+1
i += 1
if n > 1:
ans = 1 + ans
print(ans) | 24 | 24 | 292 | 289 | n = int(eval(input()))
ans = 0
i = 2
while n > 1 and i * i <= n:
if n % i == 0:
c = 0
while n % i == 0:
n = n / i
c = c + 1
Y = 1
U = 2
while c >= Y:
ans = ans + 1
Y = Y + U
U = U + 1
i = i + 1
if n > 1:
ans = 1 + ans
print(ans)
| n = int(eval(input()))
ans = 0
i = 2
while n > 1 and i * i <= n:
if n % i == 0:
c = 0
while n % i == 0:
n = n / i
c = c + 1
Y = 1
U = 2
while c >= Y:
ans = ans + 1
Y = Y + U
U = U + 1
i += 1
if n > 1:
ans = 1 + ans
print(ans)
| false | 0 | [
"- i = i + 1",
"+ i += 1"
] | false | 0.056132 | 0.061905 | 0.906737 | [
"s466925985",
"s348176555"
] |
u404678206 | p02700 | python | s315396938 | s149133430 | 23 | 20 | 9,092 | 9,028 | Accepted | Accepted | 13.04 | import math
a,b,c,d =list(map(int,input().split()))
print(('Yes'if math.ceil(a/d)>=math.ceil(c/b) else 'No')) | a,b,c,d =list(map(int,input().split()))
while True:
c=c-b
if c<=0:
print('Yes')
break
a=a-d
if a<=0:
print('No')
break | 3 | 10 | 103 | 169 | import math
a, b, c, d = list(map(int, input().split()))
print(("Yes" if math.ceil(a / d) >= math.ceil(c / b) else "No"))
| a, b, c, d = list(map(int, input().split()))
while True:
c = c - b
if c <= 0:
print("Yes")
break
a = a - d
if a <= 0:
print("No")
break
| false | 70 | [
"-import math",
"-",
"-print((\"Yes\" if math.ceil(a / d) >= math.ceil(c / b) else \"No\"))",
"+while True:",
"+ c = c - b",
"+ if c <= 0:",
"+ print(\"Yes\")",
"+ break",
"+ a = a - d",
"+ if a <= 0:",
"+ print(\"No\")",
"+ break"
] | false | 0.035521 | 0.065414 | 0.543022 | [
"s315396938",
"s149133430"
] |
u156815136 | p02615 | python | s424966587 | s364412564 | 240 | 219 | 32,948 | 32,936 | Accepted | Accepted | 8.75 | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
A = sorted(readInts(),reverse=True)
ans = 0
dic = defaultdict(int)
dq = deque()
for i in range(n):
#print(dq)
if i == 0:
dq.append(A[i])
else:
ans += dq.popleft()
for j in range(2):
dq.append(A[i])
print(ans)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
A = sorted(readInts(), reverse=True)
ans = 0
dic = defaultdict(int)
dq = deque()
for i in range(n):
if i == 0:
dq.append(A[i])
else:
ans += dq.popleft()
for j in range(2):
dq.append(A[i])
print(ans)
| 42 | 75 | 945 | 1,791 | # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
A = sorted(readInts(), reverse=True)
ans = 0
dic = defaultdict(int)
dq = deque()
for i in range(n):
# print(dq)
if i == 0:
dq.append(A[i])
else:
ans += dq.popleft()
for j in range(2):
dq.append(A[i])
print(ans)
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
# mod = 10**9 + 7
# mod = 9982443453
mod = 998244353
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
# mod = 998244353
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
A = sorted(readInts(), reverse=True)
ans = 0
dic = defaultdict(int)
dq = deque()
for i in range(n):
if i == 0:
dq.append(A[i])
else:
ans += dq.popleft()
for j in range(2):
dq.append(A[i])
print(ans)
| false | 44 | [
"-from itertools import combinations, permutations, accumulate # (string,3) 3回",
"+from itertools import combinations, permutations, accumulate, product # (string,3) 3回",
"+import math",
"+# my_round_int = lambda x:np.round((x*2 + 1)//2)",
"+# 四捨五入g",
"+import sys",
"+",
"+sys.setrecursionlimit(10000000)",
"+# mod = 10**9 + 7",
"+# mod = 9982443453",
"+mod = 998244353",
"+",
"+",
"+def readInts():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+# from statistics import median",
"+# import collections",
"+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]",
"+from fractions import gcd",
"+from itertools import combinations, permutations, accumulate, product # (string,3) 3回",
"+",
"+# from collections import deque",
"+from collections import deque, defaultdict, Counter",
"+import decimal",
"+import re",
"+import math",
"+",
"+# import bisect",
"+#",
"+# d = m - k[i] - k[j]",
"+# if kk[bisect.bisect_right(kk,d) - 1] == d:",
"+#",
"+#",
"+#",
"+# pythonで無理なときは、pypyでやると正解するかも!!",
"+#",
"+#",
"+# my_round_int = lambda x:np.round((x*2 + 1)//2)",
"+# 四捨五入g",
"+# mod = 998244353",
"- # print(dq)"
] | false | 0.061018 | 0.083796 | 0.728176 | [
"s424966587",
"s364412564"
] |
u389610071 | p02389 | python | s504647495 | s400296287 | 30 | 20 | 6,724 | 7,704 | Accepted | Accepted | 33.33 | nums = input().split()
a = int(nums[0])
b = int(nums[1])
print((a * b, (a + b) * 2)) | nums = input().split()
a = int(nums[0])
b = int(nums[1])
print((a * b, 2 * a + 2 * b)) | 4 | 5 | 85 | 89 | nums = input().split()
a = int(nums[0])
b = int(nums[1])
print((a * b, (a + b) * 2))
| nums = input().split()
a = int(nums[0])
b = int(nums[1])
print((a * b, 2 * a + 2 * b))
| false | 20 | [
"-print((a * b, (a + b) * 2))",
"+print((a * b, 2 * a + 2 * b))"
] | false | 0.042279 | 0.042015 | 1.006288 | [
"s504647495",
"s400296287"
] |
u104171359 | p02385 | python | s313589521 | s964267491 | 30 | 20 | 7,924 | 7,924 | Accepted | Accepted | 33.33 | #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == 'N':
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == 'S':
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == 'E':
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == 'W':
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip('\n'))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip('\n'))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
if q_pips[0] == die.pips[1]:
die.move_die('N')
elif q_pips[0] == die.pips[2]:
die.move_die('W')
elif q_pips[0] == die.pips[3]:
die.move_die('E')
elif q_pips[0] == die.pips[4]:
die.move_die('S')
elif q_pips[0] == die.pips[5]:
die.move_die('N')
die.move_die('N')
while die.pips[1] != q_pips[1]:
die.spin_die_clockwise()
print((die.pips[2]))
def main():
die1 = init_die()
die2 = init_die()
if sorted(die1.pips) != sorted(die2.pips):
print('No')
else:
for idx, pip in enumerate(die2.pips):
for spin in range(4):
if die1.pips == die2.pips:
print('Yes')
sys.exit(0)
else:
die1.spin_die_clockwise()
if idx in {0, 1, 2}:
die1.move_die('N')
if idx in {3}:
die1.move_die('N')
die1.move_die('E')
if idx in {4}:
die1.move_die('E')
die1.move_die('E')
print('No')
if __name__ == '__main__':
main() | #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == 'N':
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == 'S':
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == 'E':
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == 'W':
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip('\n'))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip('\n'))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
if q_pips[0] == die.pips[1]:
die.move_die('N')
elif q_pips[0] == die.pips[2]:
die.move_die('W')
elif q_pips[0] == die.pips[3]:
die.move_die('E')
elif q_pips[0] == die.pips[4]:
die.move_die('S')
elif q_pips[0] == die.pips[5]:
die.move_die('N')
die.move_die('N')
while die.pips[1] != q_pips[1]:
die.spin_die_clockwise()
print((die.pips[2]))
def are_identical(die1, die2):
if sorted(die1.pips) != sorted(die2.pips):
return 'No'
else:
for idx, pip in enumerate(die2.pips):
for spin in range(4):
if die1.pips == die2.pips:
return 'Yes'
else:
die1.spin_die_clockwise()
if idx in {0, 1, 2}:
die1.move_die('N')
if idx in {3}:
die1.move_die('N')
die1.move_die('E')
if idx in {4}:
die1.move_die('E')
die1.move_die('E')
return 'No'
def main():
die1 = init_die()
die2 = init_die()
print((are_identical(die1, die2)))
if __name__ == '__main__':
main() | 116 | 118 | 3,065 | 3,104 | #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == "N":
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == "S":
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == "E":
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == "W":
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip("\n"))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip("\n"))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
if q_pips[0] == die.pips[1]:
die.move_die("N")
elif q_pips[0] == die.pips[2]:
die.move_die("W")
elif q_pips[0] == die.pips[3]:
die.move_die("E")
elif q_pips[0] == die.pips[4]:
die.move_die("S")
elif q_pips[0] == die.pips[5]:
die.move_die("N")
die.move_die("N")
while die.pips[1] != q_pips[1]:
die.spin_die_clockwise()
print((die.pips[2]))
def main():
die1 = init_die()
die2 = init_die()
if sorted(die1.pips) != sorted(die2.pips):
print("No")
else:
for idx, pip in enumerate(die2.pips):
for spin in range(4):
if die1.pips == die2.pips:
print("Yes")
sys.exit(0)
else:
die1.spin_die_clockwise()
if idx in {0, 1, 2}:
die1.move_die("N")
if idx in {3}:
die1.move_die("N")
die1.move_die("E")
if idx in {4}:
die1.move_die("E")
die1.move_die("E")
print("No")
if __name__ == "__main__":
main()
| #!usr/bin/env python3
import sys
class Die:
def __init__(self, pips):
self.pips = pips
def move_die(self, direction):
if direction == "N":
tmp = self.pips[0]
self.pips[0] = self.pips[1]
self.pips[1] = self.pips[5]
self.pips[5] = self.pips[4]
self.pips[4] = tmp
del tmp
elif direction == "S":
tmp = self.pips[0]
self.pips[0] = self.pips[4]
self.pips[4] = self.pips[5]
self.pips[5] = self.pips[1]
self.pips[1] = tmp
del tmp
elif direction == "E":
tmp = self.pips[0]
self.pips[0] = self.pips[3]
self.pips[3] = self.pips[5]
self.pips[5] = self.pips[2]
self.pips[2] = tmp
del tmp
elif direction == "W":
tmp = self.pips[0]
self.pips[0] = self.pips[2]
self.pips[2] = self.pips[5]
self.pips[5] = self.pips[3]
self.pips[3] = tmp
del tmp
def spin_die_clockwise(self):
tmp = self.pips[1]
self.pips[1] = self.pips[2]
self.pips[2] = self.pips[4]
self.pips[4] = self.pips[3]
self.pips[3] = tmp
del tmp
def init_die():
pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
die = Die(pips)
return die
def roll_die(die):
directions = list(sys.stdin.readline().strip("\n"))
for direction in directions:
die.move_die(direction)
return die
def question_rightside(die):
q = int(sys.stdin.readline().strip("\n"))
for question in range(q):
q_pips = [int(pip) for pip in sys.stdin.readline().strip("\n").split()]
if q_pips[0] == die.pips[1]:
die.move_die("N")
elif q_pips[0] == die.pips[2]:
die.move_die("W")
elif q_pips[0] == die.pips[3]:
die.move_die("E")
elif q_pips[0] == die.pips[4]:
die.move_die("S")
elif q_pips[0] == die.pips[5]:
die.move_die("N")
die.move_die("N")
while die.pips[1] != q_pips[1]:
die.spin_die_clockwise()
print((die.pips[2]))
def are_identical(die1, die2):
if sorted(die1.pips) != sorted(die2.pips):
return "No"
else:
for idx, pip in enumerate(die2.pips):
for spin in range(4):
if die1.pips == die2.pips:
return "Yes"
else:
die1.spin_die_clockwise()
if idx in {0, 1, 2}:
die1.move_die("N")
if idx in {3}:
die1.move_die("N")
die1.move_die("E")
if idx in {4}:
die1.move_die("E")
die1.move_die("E")
return "No"
def main():
die1 = init_die()
die2 = init_die()
print((are_identical(die1, die2)))
if __name__ == "__main__":
main()
| false | 1.694915 | [
"-def main():",
"- die1 = init_die()",
"- die2 = init_die()",
"+def are_identical(die1, die2):",
"- print(\"No\")",
"+ return \"No\"",
"- print(\"Yes\")",
"- sys.exit(0)",
"+ return \"Yes\"",
"- print(\"No\")",
"+ return \"No\"",
"+",
"+",
"+def main():",
"+ die1 = init_die()",
"+ die2 = init_die()",
"+ print((are_identical(die1, die2)))"
] | false | 0.039913 | 0.035162 | 1.135118 | [
"s313589521",
"s964267491"
] |
u923279197 | p03665 | python | s598162125 | s986180509 | 21 | 18 | 3,316 | 3,060 | Accepted | Accepted | 14.29 | from collections import Counter
def combination(n, r): # nCrを求める
r = min(n-r, r)
result = 1
for i in range(n, n-r, -1):
result *= i
for i in range(1, r+1):
result //= i
return result
n,p = list(map(int,input().split()))
a =list(map(int,input().split()))
for i in range(n):
a[i] = a[i]%2
b = Counter(a)
c = b[1]
d = b[0]
ans = 0
if p ==0:
for i in range(0,c+1,2):
ans += combination(c,i)
else:
for i in range(1,c+1,2):
ans += combination(c, i)
ans *= 2**d
print(ans) | n, m = list(map(int,input().split()))
a = list(map(int,input().split()))
a = [i%2 for i in a]
if sum(a)>0:print((2**(n-1)))
else:
if m == 0:print((2**n))
else:print((0)) | 25 | 7 | 547 | 171 | from collections import Counter
def combination(n, r): # nCrを求める
r = min(n - r, r)
result = 1
for i in range(n, n - r, -1):
result *= i
for i in range(1, r + 1):
result //= i
return result
n, p = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
a[i] = a[i] % 2
b = Counter(a)
c = b[1]
d = b[0]
ans = 0
if p == 0:
for i in range(0, c + 1, 2):
ans += combination(c, i)
else:
for i in range(1, c + 1, 2):
ans += combination(c, i)
ans *= 2**d
print(ans)
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [i % 2 for i in a]
if sum(a) > 0:
print((2 ** (n - 1)))
else:
if m == 0:
print((2**n))
else:
print((0))
| false | 72 | [
"-from collections import Counter",
"-",
"-",
"-def combination(n, r): # nCrを求める",
"- r = min(n - r, r)",
"- result = 1",
"- for i in range(n, n - r, -1):",
"- result *= i",
"- for i in range(1, r + 1):",
"- result //= i",
"- return result",
"-",
"-",
"-n, p = list(map(int, input().split()))",
"+n, m = list(map(int, input().split()))",
"-for i in range(n):",
"- a[i] = a[i] % 2",
"-b = Counter(a)",
"-c = b[1]",
"-d = b[0]",
"-ans = 0",
"-if p == 0:",
"- for i in range(0, c + 1, 2):",
"- ans += combination(c, i)",
"+a = [i % 2 for i in a]",
"+if sum(a) > 0:",
"+ print((2 ** (n - 1)))",
"- for i in range(1, c + 1, 2):",
"- ans += combination(c, i)",
"-ans *= 2**d",
"-print(ans)",
"+ if m == 0:",
"+ print((2**n))",
"+ else:",
"+ print((0))"
] | false | 0.037432 | 0.035787 | 1.045972 | [
"s598162125",
"s986180509"
] |
u644907318 | p02954 | python | s031568920 | s578409830 | 129 | 118 | 6,408 | 17,844 | Accepted | Accepted | 8.53 | S = input().strip()
A = [0 for _ in range(len(S))]
i = 1
while i<len(S):
if S[i]=="L" and S[i-1]=="R":
cur = i-2
cntR = 0
while cur>=0:
if S[cur]=="R":
cntR += 1
cur -= 1
else:
break
cur = i+1
cntL = 0
while cur<len(S):
if S[cur]=="L":
cntL += 1
cur += 1
else:
break
A[i-1] = 1+cntR//2+(cntL+1)//2
A[i] = 1+(cntR+1)//2+cntL//2
i = cur
i += 1
print((*A)) | S = input().strip()
N = len(S)
A = []
cur = 0
for i in range(1,N):
if S[i]=="R" and S[i-1]=="L":
x = S[cur:i]
A.append((cur,x))
cur = i
A.append((cur,S[cur:N]))
B = [0 for _ in range(N)]
while A:
cur,x = A.pop()
n = len(x)
for i in range(1,n):
if x[i]=="L" and x[i-1]=="R":
ind = i
break
if n%2==0:
B[cur+ind]=n//2
B[cur+ind-1]=n//2
else:
if ind%2==0:
B[cur+ind] = (n+1)//2
B[cur+ind-1]=n//2
else:
B[cur+ind] = n//2
B[cur+ind-1]=(n+1)//2
print((*B)) | 26 | 29 | 600 | 635 | S = input().strip()
A = [0 for _ in range(len(S))]
i = 1
while i < len(S):
if S[i] == "L" and S[i - 1] == "R":
cur = i - 2
cntR = 0
while cur >= 0:
if S[cur] == "R":
cntR += 1
cur -= 1
else:
break
cur = i + 1
cntL = 0
while cur < len(S):
if S[cur] == "L":
cntL += 1
cur += 1
else:
break
A[i - 1] = 1 + cntR // 2 + (cntL + 1) // 2
A[i] = 1 + (cntR + 1) // 2 + cntL // 2
i = cur
i += 1
print((*A))
| S = input().strip()
N = len(S)
A = []
cur = 0
for i in range(1, N):
if S[i] == "R" and S[i - 1] == "L":
x = S[cur:i]
A.append((cur, x))
cur = i
A.append((cur, S[cur:N]))
B = [0 for _ in range(N)]
while A:
cur, x = A.pop()
n = len(x)
for i in range(1, n):
if x[i] == "L" and x[i - 1] == "R":
ind = i
break
if n % 2 == 0:
B[cur + ind] = n // 2
B[cur + ind - 1] = n // 2
else:
if ind % 2 == 0:
B[cur + ind] = (n + 1) // 2
B[cur + ind - 1] = n // 2
else:
B[cur + ind] = n // 2
B[cur + ind - 1] = (n + 1) // 2
print((*B))
| false | 10.344828 | [
"-A = [0 for _ in range(len(S))]",
"-i = 1",
"-while i < len(S):",
"- if S[i] == \"L\" and S[i - 1] == \"R\":",
"- cur = i - 2",
"- cntR = 0",
"- while cur >= 0:",
"- if S[cur] == \"R\":",
"- cntR += 1",
"- cur -= 1",
"- else:",
"- break",
"- cur = i + 1",
"- cntL = 0",
"- while cur < len(S):",
"- if S[cur] == \"L\":",
"- cntL += 1",
"- cur += 1",
"- else:",
"- break",
"- A[i - 1] = 1 + cntR // 2 + (cntL + 1) // 2",
"- A[i] = 1 + (cntR + 1) // 2 + cntL // 2",
"- i = cur",
"- i += 1",
"-print((*A))",
"+N = len(S)",
"+A = []",
"+cur = 0",
"+for i in range(1, N):",
"+ if S[i] == \"R\" and S[i - 1] == \"L\":",
"+ x = S[cur:i]",
"+ A.append((cur, x))",
"+ cur = i",
"+A.append((cur, S[cur:N]))",
"+B = [0 for _ in range(N)]",
"+while A:",
"+ cur, x = A.pop()",
"+ n = len(x)",
"+ for i in range(1, n):",
"+ if x[i] == \"L\" and x[i - 1] == \"R\":",
"+ ind = i",
"+ break",
"+ if n % 2 == 0:",
"+ B[cur + ind] = n // 2",
"+ B[cur + ind - 1] = n // 2",
"+ else:",
"+ if ind % 2 == 0:",
"+ B[cur + ind] = (n + 1) // 2",
"+ B[cur + ind - 1] = n // 2",
"+ else:",
"+ B[cur + ind] = n // 2",
"+ B[cur + ind - 1] = (n + 1) // 2",
"+print((*B))"
] | false | 0.217446 | 0.063187 | 3.441318 | [
"s031568920",
"s578409830"
] |
u912237403 | p00097 | python | s731026542 | s210033658 | 250 | 220 | 4,392 | 4,384 | Accepted | Accepted | 12 | m=1001
A=list(range(10))
d=[[0]*m for i in A]
d[0][0]=1
for i in range(101):
for j in A[1:][::-1]:
for k in range(m-i): d[j][k+i]+=d[j-1][k]
while 1:
n,s=list(map(int,input().split()))
if n==s==0: break
print(d[n][s]) | m=1001
A=list(range(9))
d=[[0]*m for i in A]
for i in range(101):
for j in A[1:][::-1]:
for k in range(m-i): d[j][k+i]+=d[j-1][k]
d[0][i]=1
while 1:
n,s=list(map(int,input().split()))
if n==s==0: break
print(d[n-1][s]) | 11 | 11 | 230 | 233 | m = 1001
A = list(range(10))
d = [[0] * m for i in A]
d[0][0] = 1
for i in range(101):
for j in A[1:][::-1]:
for k in range(m - i):
d[j][k + i] += d[j - 1][k]
while 1:
n, s = list(map(int, input().split()))
if n == s == 0:
break
print(d[n][s])
| m = 1001
A = list(range(9))
d = [[0] * m for i in A]
for i in range(101):
for j in A[1:][::-1]:
for k in range(m - i):
d[j][k + i] += d[j - 1][k]
d[0][i] = 1
while 1:
n, s = list(map(int, input().split()))
if n == s == 0:
break
print(d[n - 1][s])
| false | 0 | [
"-A = list(range(10))",
"+A = list(range(9))",
"-d[0][0] = 1",
"+ d[0][i] = 1",
"- print(d[n][s])",
"+ print(d[n - 1][s])"
] | false | 0.374195 | 1.059184 | 0.353286 | [
"s731026542",
"s210033658"
] |
u919902859 | p02879 | python | s743771124 | s725799130 | 176 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.34 | i = list(map(int, input().split()))
if ((i[0] >= 1 and i[0] <= 9) and (i[1] >= 1 and i[1] <= 9)):
print((i[0] * i[1]))
else:
print((-1)) | i = list(map(int, input().split()))
if ((i[0] <= 9) and (i[1] <= 9)):
print((i[0] * i[1]))
else:
print((-1)) | 5 | 5 | 146 | 118 | i = list(map(int, input().split()))
if (i[0] >= 1 and i[0] <= 9) and (i[1] >= 1 and i[1] <= 9):
print((i[0] * i[1]))
else:
print((-1))
| i = list(map(int, input().split()))
if (i[0] <= 9) and (i[1] <= 9):
print((i[0] * i[1]))
else:
print((-1))
| false | 0 | [
"-if (i[0] >= 1 and i[0] <= 9) and (i[1] >= 1 and i[1] <= 9):",
"+if (i[0] <= 9) and (i[1] <= 9):"
] | false | 0.178096 | 0.045448 | 3.918671 | [
"s743771124",
"s725799130"
] |
u843981036 | p03816 | python | s054137605 | s441008878 | 67 | 61 | 14,396 | 19,000 | Accepted | Accepted | 8.96 | n = int(eval(input()))
l = len(set(list(map(int, input().split()))))
print((l - 1 if (n - l) % 2 else l))
| n = int(eval(input()))
l = len(set(map(int, input().split())))
print((l - (n - l) % 2)) | 3 | 3 | 100 | 81 | n = int(eval(input()))
l = len(set(list(map(int, input().split()))))
print((l - 1 if (n - l) % 2 else l))
| n = int(eval(input()))
l = len(set(map(int, input().split())))
print((l - (n - l) % 2))
| false | 0 | [
"-l = len(set(list(map(int, input().split()))))",
"-print((l - 1 if (n - l) % 2 else l))",
"+l = len(set(map(int, input().split())))",
"+print((l - (n - l) % 2))"
] | false | 0.042063 | 0.042338 | 0.993491 | [
"s054137605",
"s441008878"
] |
u926412290 | p02819 | python | s383389818 | s209352326 | 19 | 17 | 2,940 | 3,064 | Accepted | Accepted | 10.53 | def is_prime(a):
if a == 2:
return True
for i in range(2, int(a**0.5)+2):
if a%i == 0:
return False
return True
X = int(eval(input()))
for i in range(X, 100004):
if is_prime(i):
print(i)
break | def is_prime(a):
for i in range(2, int(a**0.5)+1):
if a%i == 0:
return False
return True
X = int(eval(input()))
for i in range(X, 100004):
if is_prime(i):
print(i)
break | 14 | 12 | 261 | 224 | def is_prime(a):
if a == 2:
return True
for i in range(2, int(a**0.5) + 2):
if a % i == 0:
return False
return True
X = int(eval(input()))
for i in range(X, 100004):
if is_prime(i):
print(i)
break
| def is_prime(a):
for i in range(2, int(a**0.5) + 1):
if a % i == 0:
return False
return True
X = int(eval(input()))
for i in range(X, 100004):
if is_prime(i):
print(i)
break
| false | 14.285714 | [
"- if a == 2:",
"- return True",
"- for i in range(2, int(a**0.5) + 2):",
"+ for i in range(2, int(a**0.5) + 1):"
] | false | 0.086421 | 0.044378 | 1.947392 | [
"s383389818",
"s209352326"
] |
u588341295 | p04046 | python | s668782399 | s470616552 | 362 | 331 | 44,656 | 18,804 | Accepted | Accepted | 8.56 | # -*- coding: utf-8 -*-
H,W,A,B = list(map(int, input().split()))
mod = (10 ** 9 + 7)
# 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく
factorial = [0] * (H+W)
factorial[0] = 1
factorial[1] = 1
inverse = [0] * (H+W)
inverse[0] = 1
inverse[1] = 1
for i in range(2,H+W):
factorial[i] = factorial[i-1] * i % mod
# フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[i] = pow(factorial[i], mod-2, mod)
# 組み合わせの数だけ返してくれる関数(自作)
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n-r)
# 分子の計算
numerator = factorial[n]
# 分母の計算
denominator = inverse[r] * inverse[n-r] % mod
return numerator * denominator % mod
h = H - A
w = B + 1
ans = 0
# マスを右上に1つずつずらして、必ず通る場所でパターンを足し合わせていく
while h > 0 and w <= W:
ans = (ans + nCr(h+w-2, h-1) * nCr(H-h+W-w, H-h)) % mod
h -= 1
w += 1
print(ans) | # -*- coding: utf-8 -*-
H,W,A,B = list(map(int, input().split()))
mod = (10 ** 9 + 7)
# 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく
factorial = [1] * (H+W)
factorial[0] = 1
factorial[1] = 1
for i in range(2,H+W):
factorial[i] = factorial[i-1] * i % mod
inverse = [1] * (H+W)
# フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[H+W-1] = pow(factorial[H+W-1], mod-2, mod)
for i in range(H+W-2, 0, -1):
# 最後から戻っていくこのループならH+W回powするより処理が速い
inverse[i] = inverse[i+1] * (i+1) % mod
# 組み合わせの数だけ返してくれる関数(自作)
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n-r)
# 分子の計算
numerator = factorial[n]
# 分母の計算
denominator = inverse[r] * inverse[n-r] % mod
return numerator * denominator % mod
h = H - A
w = B + 1
ans = 0
# マスを右上に1つずつずらして、必ず通る場所でパターンを足し合わせていく
while h > 0 and w <= W:
ans = (ans + nCr(h+w-2, h-1) * nCr(H-h+W-w, H-h)) % mod
h -= 1
w += 1
print(ans) | 38 | 40 | 878 | 956 | # -*- coding: utf-8 -*-
H, W, A, B = list(map(int, input().split()))
mod = 10**9 + 7
# 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく
factorial = [0] * (H + W)
factorial[0] = 1
factorial[1] = 1
inverse = [0] * (H + W)
inverse[0] = 1
inverse[1] = 1
for i in range(2, H + W):
factorial[i] = factorial[i - 1] * i % mod
# フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[i] = pow(factorial[i], mod - 2, mod)
# 組み合わせの数だけ返してくれる関数(自作)
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n - r)
# 分子の計算
numerator = factorial[n]
# 分母の計算
denominator = inverse[r] * inverse[n - r] % mod
return numerator * denominator % mod
h = H - A
w = B + 1
ans = 0
# マスを右上に1つずつずらして、必ず通る場所でパターンを足し合わせていく
while h > 0 and w <= W:
ans = (ans + nCr(h + w - 2, h - 1) * nCr(H - h + W - w, H - h)) % mod
h -= 1
w += 1
print(ans)
| # -*- coding: utf-8 -*-
H, W, A, B = list(map(int, input().split()))
mod = 10**9 + 7
# 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく
factorial = [1] * (H + W)
factorial[0] = 1
factorial[1] = 1
for i in range(2, H + W):
factorial[i] = factorial[i - 1] * i % mod
inverse = [1] * (H + W)
# フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)
# powに第三引数入れると冪乗のmod付計算を高速にやってくれる
inverse[H + W - 1] = pow(factorial[H + W - 1], mod - 2, mod)
for i in range(H + W - 2, 0, -1):
# 最後から戻っていくこのループならH+W回powするより処理が速い
inverse[i] = inverse[i + 1] * (i + 1) % mod
# 組み合わせの数だけ返してくれる関数(自作)
def nCr(n, r):
# 10C7 = 10C3
r = min(r, n - r)
# 分子の計算
numerator = factorial[n]
# 分母の計算
denominator = inverse[r] * inverse[n - r] % mod
return numerator * denominator % mod
h = H - A
w = B + 1
ans = 0
# マスを右上に1つずつずらして、必ず通る場所でパターンを足し合わせていく
while h > 0 and w <= W:
ans = (ans + nCr(h + w - 2, h - 1) * nCr(H - h + W - w, H - h)) % mod
h -= 1
w += 1
print(ans)
| false | 5 | [
"-factorial = [0] * (H + W)",
"+factorial = [1] * (H + W)",
"-inverse = [0] * (H + W)",
"-inverse[0] = 1",
"-inverse[1] = 1",
"- # フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)",
"- # powに第三引数入れると冪乗のmod付計算を高速にやってくれる",
"- inverse[i] = pow(factorial[i], mod - 2, mod)",
"+inverse = [1] * (H + W)",
"+# フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod)",
"+# powに第三引数入れると冪乗のmod付計算を高速にやってくれる",
"+inverse[H + W - 1] = pow(factorial[H + W - 1], mod - 2, mod)",
"+for i in range(H + W - 2, 0, -1):",
"+ # 最後から戻っていくこのループならH+W回powするより処理が速い",
"+ inverse[i] = inverse[i + 1] * (i + 1) % mod"
] | false | 0.040133 | 0.04036 | 0.994374 | [
"s668782399",
"s470616552"
] |
u553987207 | p02953 | python | s935460876 | s825705714 | 90 | 71 | 14,396 | 20,832 | Accepted | Accepted | 21.11 | N = int(eval(input()))
H = list(map(int, input().split()))
H.reverse()
for i in range(1, N):
if H[i-1] < H[i] - 1:
print("No")
break
elif H[i-1] == H[i] - 1:
H[i] -= 1
else:
print("Yes") | N = int(eval(input()))
H = list(map(int, input().split()))
for i in range(N - 2, -1, -1):
if H[i] <= H[i+1]:
continue
elif H[i] - 1 == H[i+1]:
H[i] -= 1
else:
print("No")
break
else:
print("Yes") | 11 | 12 | 226 | 248 | N = int(eval(input()))
H = list(map(int, input().split()))
H.reverse()
for i in range(1, N):
if H[i - 1] < H[i] - 1:
print("No")
break
elif H[i - 1] == H[i] - 1:
H[i] -= 1
else:
print("Yes")
| N = int(eval(input()))
H = list(map(int, input().split()))
for i in range(N - 2, -1, -1):
if H[i] <= H[i + 1]:
continue
elif H[i] - 1 == H[i + 1]:
H[i] -= 1
else:
print("No")
break
else:
print("Yes")
| false | 8.333333 | [
"-H.reverse()",
"-for i in range(1, N):",
"- if H[i - 1] < H[i] - 1:",
"+for i in range(N - 2, -1, -1):",
"+ if H[i] <= H[i + 1]:",
"+ continue",
"+ elif H[i] - 1 == H[i + 1]:",
"+ H[i] -= 1",
"+ else:",
"- elif H[i - 1] == H[i] - 1:",
"- H[i] -= 1"
] | false | 0.048038 | 0.042902 | 1.119707 | [
"s935460876",
"s825705714"
] |
u375253797 | p03013 | python | s710504248 | s165510469 | 490 | 200 | 460,020 | 6,900 | Accepted | Accepted | 59.18 | N, M = list(map(int, input().split()))
dp = [0] * N
for _ in range(M):
a = int(eval(input()))
dp[a-1] = -1
k = 1000000007
for i in range(N):
if dp[i] == -1:
dp[i] = 0
continue
if i == 0:
dp[i] = 1
continue
if i == 1:
dp[i] = dp[i-1] + 1
continue
dp[i] = dp[i-1] + dp[i-2]
n = dp[-1] % k
print(n)
| N, M = list(map(int, input().split()))
dp = [0] * N
for _ in range(M):
a = int(eval(input()))
dp[a-1] = -1
k = 1000000007
for i in range(N):
if dp[i] == -1:
dp[i] = 0
continue
if i == 0:
dp[i] = 1
continue
if i == 1:
dp[i] = dp[i-1] + 1
continue
dp[i] = dp[i-1] + dp[i-2]
dp[i] %= k
print((dp[-1]))
| 25 | 26 | 386 | 393 | N, M = list(map(int, input().split()))
dp = [0] * N
for _ in range(M):
a = int(eval(input()))
dp[a - 1] = -1
k = 1000000007
for i in range(N):
if dp[i] == -1:
dp[i] = 0
continue
if i == 0:
dp[i] = 1
continue
if i == 1:
dp[i] = dp[i - 1] + 1
continue
dp[i] = dp[i - 1] + dp[i - 2]
n = dp[-1] % k
print(n)
| N, M = list(map(int, input().split()))
dp = [0] * N
for _ in range(M):
a = int(eval(input()))
dp[a - 1] = -1
k = 1000000007
for i in range(N):
if dp[i] == -1:
dp[i] = 0
continue
if i == 0:
dp[i] = 1
continue
if i == 1:
dp[i] = dp[i - 1] + 1
continue
dp[i] = dp[i - 1] + dp[i - 2]
dp[i] %= k
print((dp[-1]))
| false | 3.846154 | [
"-n = dp[-1] % k",
"-print(n)",
"+ dp[i] %= k",
"+print((dp[-1]))"
] | false | 0.092808 | 0.042119 | 2.203458 | [
"s710504248",
"s165510469"
] |
u069838609 | p03283 | python | s116607151 | s063060034 | 1,603 | 600 | 66,836 | 103,132 | Accepted | Accepted | 62.57 | from copy import deepcopy
N, M, Q = [int(elem) for elem in input().split(' ')]
lines = [[int(elem) for elem in input().split(' ')] for _ in range(M)]
queries = [[int(elem) for elem in input().split(' ')] for _ in range(Q)]
def cuml_1d(N, lines, queries):
coords = [[0] * N for _ in range(N)]
for l, r in lines:
coords[l - 1][r - 1] += 1
cuml_coords = deepcopy(coords)
for l in range(N):
for r in range(1, N):
cuml_coords[l][r] = cuml_coords[l][r - 1] + coords[l][r]
for query in queries:
p, q = query[0] - 1, query[1] - 1
num_lines = 0
for l in range(p, max(q + 1, N)):
if p == 0:
num_lines += cuml_coords[l][q]
else:
num_lines += cuml_coords[l][q] - cuml_coords[l][p - 1]
print(num_lines)
#cuml_1d(N, lines, queries)
def cuml_2d(N, lines, queries):
coords = [[0] * N for _ in range(N)]
for l, r in lines:
coords[l - 1][r - 1] += 1
cuml_l = deepcopy(coords)
for r in range(N):
for l in range(1, N):
cuml_l[l][r] = cuml_l[l - 1][r] + coords[l][r]
cuml_2d = deepcopy(cuml_l)
for l in range(N):
for r in range(1, N):
cuml_2d[l][r] = cuml_2d[l][r - 1] + cuml_l[l][r]
for query in queries:
p, q = query[0] - 1, query[1] - 1
if p != 0:
num_lines = cuml_2d[q][q] - cuml_2d[q][p-1] - cuml_2d[p-1][q] + cuml_2d[p-1][p-1]
else:
num_lines = cuml_2d[q][q]
print(num_lines)
cuml_2d(N, lines, queries)
| import sys
fin = sys.stdin.readline
N, M, Q = [int(elem) for elem in fin().split()]
trains = [[int(elem) - 1 for elem in fin().split()] for _ in range(M)]
queries = [[int(elem) - 1 for elem in fin().split()] for _ in range(Q)]
map_2D = [[0] * N for _ in range(N)]
for l, r in trains:
map_2D[l][r] += 1
cuml_1D = [[0] * N for _ in range(N)]
# vertical
for j in range(N):
cuml_sum = 0
for i in reversed(list(range(j + 1))):
cuml_sum += map_2D[i][j]
cuml_1D[i][j] = cuml_sum
cuml_2D = [[0] * N for _ in range(N)]
# horizontal
for i in range(N):
cuml_sum = 0
for j in range(N):
cuml_sum += cuml_1D[i][j]
cuml_2D[i][j] = cuml_sum
for p, q in queries:
print((cuml_2D[p][q]))
| 52 | 29 | 1,621 | 751 | from copy import deepcopy
N, M, Q = [int(elem) for elem in input().split(" ")]
lines = [[int(elem) for elem in input().split(" ")] for _ in range(M)]
queries = [[int(elem) for elem in input().split(" ")] for _ in range(Q)]
def cuml_1d(N, lines, queries):
coords = [[0] * N for _ in range(N)]
for l, r in lines:
coords[l - 1][r - 1] += 1
cuml_coords = deepcopy(coords)
for l in range(N):
for r in range(1, N):
cuml_coords[l][r] = cuml_coords[l][r - 1] + coords[l][r]
for query in queries:
p, q = query[0] - 1, query[1] - 1
num_lines = 0
for l in range(p, max(q + 1, N)):
if p == 0:
num_lines += cuml_coords[l][q]
else:
num_lines += cuml_coords[l][q] - cuml_coords[l][p - 1]
print(num_lines)
# cuml_1d(N, lines, queries)
def cuml_2d(N, lines, queries):
coords = [[0] * N for _ in range(N)]
for l, r in lines:
coords[l - 1][r - 1] += 1
cuml_l = deepcopy(coords)
for r in range(N):
for l in range(1, N):
cuml_l[l][r] = cuml_l[l - 1][r] + coords[l][r]
cuml_2d = deepcopy(cuml_l)
for l in range(N):
for r in range(1, N):
cuml_2d[l][r] = cuml_2d[l][r - 1] + cuml_l[l][r]
for query in queries:
p, q = query[0] - 1, query[1] - 1
if p != 0:
num_lines = (
cuml_2d[q][q]
- cuml_2d[q][p - 1]
- cuml_2d[p - 1][q]
+ cuml_2d[p - 1][p - 1]
)
else:
num_lines = cuml_2d[q][q]
print(num_lines)
cuml_2d(N, lines, queries)
| import sys
fin = sys.stdin.readline
N, M, Q = [int(elem) for elem in fin().split()]
trains = [[int(elem) - 1 for elem in fin().split()] for _ in range(M)]
queries = [[int(elem) - 1 for elem in fin().split()] for _ in range(Q)]
map_2D = [[0] * N for _ in range(N)]
for l, r in trains:
map_2D[l][r] += 1
cuml_1D = [[0] * N for _ in range(N)]
# vertical
for j in range(N):
cuml_sum = 0
for i in reversed(list(range(j + 1))):
cuml_sum += map_2D[i][j]
cuml_1D[i][j] = cuml_sum
cuml_2D = [[0] * N for _ in range(N)]
# horizontal
for i in range(N):
cuml_sum = 0
for j in range(N):
cuml_sum += cuml_1D[i][j]
cuml_2D[i][j] = cuml_sum
for p, q in queries:
print((cuml_2D[p][q]))
| false | 44.230769 | [
"-from copy import deepcopy",
"+import sys",
"-N, M, Q = [int(elem) for elem in input().split(\" \")]",
"-lines = [[int(elem) for elem in input().split(\" \")] for _ in range(M)]",
"-queries = [[int(elem) for elem in input().split(\" \")] for _ in range(Q)]",
"-",
"-",
"-def cuml_1d(N, lines, queries):",
"- coords = [[0] * N for _ in range(N)]",
"- for l, r in lines:",
"- coords[l - 1][r - 1] += 1",
"- cuml_coords = deepcopy(coords)",
"- for l in range(N):",
"- for r in range(1, N):",
"- cuml_coords[l][r] = cuml_coords[l][r - 1] + coords[l][r]",
"- for query in queries:",
"- p, q = query[0] - 1, query[1] - 1",
"- num_lines = 0",
"- for l in range(p, max(q + 1, N)):",
"- if p == 0:",
"- num_lines += cuml_coords[l][q]",
"- else:",
"- num_lines += cuml_coords[l][q] - cuml_coords[l][p - 1]",
"- print(num_lines)",
"-",
"-",
"-# cuml_1d(N, lines, queries)",
"-def cuml_2d(N, lines, queries):",
"- coords = [[0] * N for _ in range(N)]",
"- for l, r in lines:",
"- coords[l - 1][r - 1] += 1",
"- cuml_l = deepcopy(coords)",
"- for r in range(N):",
"- for l in range(1, N):",
"- cuml_l[l][r] = cuml_l[l - 1][r] + coords[l][r]",
"- cuml_2d = deepcopy(cuml_l)",
"- for l in range(N):",
"- for r in range(1, N):",
"- cuml_2d[l][r] = cuml_2d[l][r - 1] + cuml_l[l][r]",
"- for query in queries:",
"- p, q = query[0] - 1, query[1] - 1",
"- if p != 0:",
"- num_lines = (",
"- cuml_2d[q][q]",
"- - cuml_2d[q][p - 1]",
"- - cuml_2d[p - 1][q]",
"- + cuml_2d[p - 1][p - 1]",
"- )",
"- else:",
"- num_lines = cuml_2d[q][q]",
"- print(num_lines)",
"-",
"-",
"-cuml_2d(N, lines, queries)",
"+fin = sys.stdin.readline",
"+N, M, Q = [int(elem) for elem in fin().split()]",
"+trains = [[int(elem) - 1 for elem in fin().split()] for _ in range(M)]",
"+queries = [[int(elem) - 1 for elem in fin().split()] for _ in range(Q)]",
"+map_2D = [[0] * N for _ in range(N)]",
"+for l, r in trains:",
"+ map_2D[l][r] += 1",
"+cuml_1D = [[0] * N for _ in range(N)]",
"+# vertical",
"+for j in range(N):",
"+ cuml_sum = 0",
"+ for i in reversed(list(range(j + 1))):",
"+ cuml_sum += map_2D[i][j]",
"+ cuml_1D[i][j] = cuml_sum",
"+cuml_2D = [[0] * N for _ in range(N)]",
"+# horizontal",
"+for i in range(N):",
"+ cuml_sum = 0",
"+ for j in range(N):",
"+ cuml_sum += cuml_1D[i][j]",
"+ cuml_2D[i][j] = cuml_sum",
"+for p, q in queries:",
"+ print((cuml_2D[p][q]))"
] | false | 0.058886 | 0.036396 | 1.617922 | [
"s116607151",
"s063060034"
] |
u844646164 | p03339 | python | s667092783 | s278752074 | 1,145 | 234 | 29,424 | 67,824 | Accepted | Accepted | 79.56 | import numpy as np
N = int(eval(input()))
S = np.array(list(eval(input())))
n = []
for i in range(N):
if S[i] == 'E':
S[i] = 1
else:
S[i] = 0
S = np.array(S, dtype=int)
S = np.cumsum(S)
last = S[N-1]
n.append(last-S[0])
for i in range(1, N):
ls = i - S[i-1]
rs = last - S[i]
n.append(ls+rs)
print((min(n)))
| N = int(eval(input()))
S = list(eval(input()))
e = [0]*(N+1)
w = [0]*(N+1)
if S[0] == 'E':
e[0] += 1
else:
w[0] += 1
for i in range(1, N):
if S[i] == 'E':
e[i] += e[i-1] + 1
w[i] += w[i-1]
else:
e[i] += e[i-1]
w[i] += w[i-1] + 1
ans = float('inf')
for i in range(N):
tmp = w[i-1] + e[N-1] - e[i]
ans = min(ans, tmp)
print(ans) | 18 | 21 | 346 | 399 | import numpy as np
N = int(eval(input()))
S = np.array(list(eval(input())))
n = []
for i in range(N):
if S[i] == "E":
S[i] = 1
else:
S[i] = 0
S = np.array(S, dtype=int)
S = np.cumsum(S)
last = S[N - 1]
n.append(last - S[0])
for i in range(1, N):
ls = i - S[i - 1]
rs = last - S[i]
n.append(ls + rs)
print((min(n)))
| N = int(eval(input()))
S = list(eval(input()))
e = [0] * (N + 1)
w = [0] * (N + 1)
if S[0] == "E":
e[0] += 1
else:
w[0] += 1
for i in range(1, N):
if S[i] == "E":
e[i] += e[i - 1] + 1
w[i] += w[i - 1]
else:
e[i] += e[i - 1]
w[i] += w[i - 1] + 1
ans = float("inf")
for i in range(N):
tmp = w[i - 1] + e[N - 1] - e[i]
ans = min(ans, tmp)
print(ans)
| false | 14.285714 | [
"-import numpy as np",
"-",
"-S = np.array(list(eval(input())))",
"-n = []",
"+S = list(eval(input()))",
"+e = [0] * (N + 1)",
"+w = [0] * (N + 1)",
"+if S[0] == \"E\":",
"+ e[0] += 1",
"+else:",
"+ w[0] += 1",
"+for i in range(1, N):",
"+ if S[i] == \"E\":",
"+ e[i] += e[i - 1] + 1",
"+ w[i] += w[i - 1]",
"+ else:",
"+ e[i] += e[i - 1]",
"+ w[i] += w[i - 1] + 1",
"+ans = float(\"inf\")",
"- if S[i] == \"E\":",
"- S[i] = 1",
"- else:",
"- S[i] = 0",
"-S = np.array(S, dtype=int)",
"-S = np.cumsum(S)",
"-last = S[N - 1]",
"-n.append(last - S[0])",
"-for i in range(1, N):",
"- ls = i - S[i - 1]",
"- rs = last - S[i]",
"- n.append(ls + rs)",
"-print((min(n)))",
"+ tmp = w[i - 1] + e[N - 1] - e[i]",
"+ ans = min(ans, tmp)",
"+print(ans)"
] | false | 0.00678 | 0.040419 | 0.16773 | [
"s667092783",
"s278752074"
] |
u622847899 | p02629 | python | s178188524 | s190176353 | 29 | 25 | 9,240 | 9,160 | Accepted | Accepted | 13.79 | n=int(eval(input()))
alphabet=[None] + [chr(i) for i in range(97,97+26)]
rest=[]
while n!=0:
rest.append(n%26)
n = n // 26
rest.reverse()
for i in range(len(rest)-1):
if rest[len(rest)-1-i]<=0:
rest[len(rest)-1-i]+=26
rest[len(rest)-2-i]-=1
if rest[0]<=0:
rest=rest[1:]
ans=''
for i in range(len(rest)):
ans+=alphabet[rest[i]]
print(ans)
| n=int(eval(input()))
alphabet=[chr(i) for i in range(97,97+26)]
ans=''
while n>0:
n-=1
ans+=alphabet[n%26]
n //= 26
print((ans[::-1])) | 21 | 10 | 392 | 149 | n = int(eval(input()))
alphabet = [None] + [chr(i) for i in range(97, 97 + 26)]
rest = []
while n != 0:
rest.append(n % 26)
n = n // 26
rest.reverse()
for i in range(len(rest) - 1):
if rest[len(rest) - 1 - i] <= 0:
rest[len(rest) - 1 - i] += 26
rest[len(rest) - 2 - i] -= 1
if rest[0] <= 0:
rest = rest[1:]
ans = ""
for i in range(len(rest)):
ans += alphabet[rest[i]]
print(ans)
| n = int(eval(input()))
alphabet = [chr(i) for i in range(97, 97 + 26)]
ans = ""
while n > 0:
n -= 1
ans += alphabet[n % 26]
n //= 26
print((ans[::-1]))
| false | 52.380952 | [
"-alphabet = [None] + [chr(i) for i in range(97, 97 + 26)]",
"-rest = []",
"-while n != 0:",
"- rest.append(n % 26)",
"- n = n // 26",
"-rest.reverse()",
"-for i in range(len(rest) - 1):",
"- if rest[len(rest) - 1 - i] <= 0:",
"- rest[len(rest) - 1 - i] += 26",
"- rest[len(rest) - 2 - i] -= 1",
"-if rest[0] <= 0:",
"- rest = rest[1:]",
"+alphabet = [chr(i) for i in range(97, 97 + 26)]",
"-for i in range(len(rest)):",
"- ans += alphabet[rest[i]]",
"-print(ans)",
"+while n > 0:",
"+ n -= 1",
"+ ans += alphabet[n % 26]",
"+ n //= 26",
"+print((ans[::-1]))"
] | false | 0.038935 | 0.038905 | 1.000776 | [
"s178188524",
"s190176353"
] |
u951031728 | p02577 | python | s882089756 | s804104246 | 244 | 207 | 9,264 | 9,324 | Accepted | Accepted | 15.16 | N = eval(input())
sum = 0
if int(N) != 0:
data_size = len(N)
for data_size in range(data_size):
sum += int(N[data_size])
else:
sum = 0
if sum%9 == 0:
print('Yes')
else:
print('No') | if int(eval(input()))%9 == 0:
print('Yes')
else:
print('No') | 15 | 4 | 219 | 61 | N = eval(input())
sum = 0
if int(N) != 0:
data_size = len(N)
for data_size in range(data_size):
sum += int(N[data_size])
else:
sum = 0
if sum % 9 == 0:
print("Yes")
else:
print("No")
| if int(eval(input())) % 9 == 0:
print("Yes")
else:
print("No")
| false | 73.333333 | [
"-N = eval(input())",
"-sum = 0",
"-if int(N) != 0:",
"- data_size = len(N)",
"- for data_size in range(data_size):",
"- sum += int(N[data_size])",
"-else:",
"- sum = 0",
"-if sum % 9 == 0:",
"+if int(eval(input())) % 9 == 0:"
] | false | 0.041966 | 0.044785 | 0.937052 | [
"s882089756",
"s804104246"
] |
u002663801 | p02683 | python | s706369620 | s569034613 | 96 | 88 | 9,324 | 9,364 | Accepted | Accepted | 8.33 | import copy
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])
s_list = [[0 for i in range(m+1)] for j in range(n)]
for i in range(n):
r = input().split()
s_list[i][0] = int(r[0])
for j in range(1,m + 1):
s_list[i][j] = int(r[j])
gen = [0] * (m + 1)
kakaku = -1
for i in range(2 ** n):
k = i
kari = copy.copy(gen)
for j in reversed(list(range(n))):
if k >= 2 ** j:
k -= 2 ** j
for l in range(m+1):
kari[l] += s_list[j][l]
check = 0
for j in range(1,m + 1):
if kari[j] < x:
check = 1
break
if check == 0 and (kari[0] < kakaku or kakaku == -1):
kakaku = kari[0]
print(kakaku) | import copy
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])
s_list = [[0 for i in range(m+1)] for j in range(n)]
for i in range(n):
r = input().split()
s_list[i][0] = int(r[0])
for j in range(1,m + 1):
s_list[i][j] = int(r[j])
gen = [0] * (m + 1)
kakaku = -1
for i in range(2 ** n):
kari = copy.copy(gen)
for j in range(n):
if ((i >> j) & 1):
for l in range(m+1):
kari[l] += s_list[j][l]
check = 0
for j in range(1,m + 1):
if kari[j] < x:
check = 1
break
if check == 0 and (kari[0] < kakaku or kakaku == -1):
kakaku = kari[0]
print(kakaku) | 37 | 35 | 754 | 711 | import copy
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])
s_list = [[0 for i in range(m + 1)] for j in range(n)]
for i in range(n):
r = input().split()
s_list[i][0] = int(r[0])
for j in range(1, m + 1):
s_list[i][j] = int(r[j])
gen = [0] * (m + 1)
kakaku = -1
for i in range(2**n):
k = i
kari = copy.copy(gen)
for j in reversed(list(range(n))):
if k >= 2**j:
k -= 2**j
for l in range(m + 1):
kari[l] += s_list[j][l]
check = 0
for j in range(1, m + 1):
if kari[j] < x:
check = 1
break
if check == 0 and (kari[0] < kakaku or kakaku == -1):
kakaku = kari[0]
print(kakaku)
| import copy
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])
s_list = [[0 for i in range(m + 1)] for j in range(n)]
for i in range(n):
r = input().split()
s_list[i][0] = int(r[0])
for j in range(1, m + 1):
s_list[i][j] = int(r[j])
gen = [0] * (m + 1)
kakaku = -1
for i in range(2**n):
kari = copy.copy(gen)
for j in range(n):
if (i >> j) & 1:
for l in range(m + 1):
kari[l] += s_list[j][l]
check = 0
for j in range(1, m + 1):
if kari[j] < x:
check = 1
break
if check == 0 and (kari[0] < kakaku or kakaku == -1):
kakaku = kari[0]
print(kakaku)
| false | 5.405405 | [
"- k = i",
"- for j in reversed(list(range(n))):",
"- if k >= 2**j:",
"- k -= 2**j",
"+ for j in range(n):",
"+ if (i >> j) & 1:"
] | false | 0.03955 | 0.038812 | 1.019016 | [
"s706369620",
"s569034613"
] |
u007991836 | p03107 | python | s967098155 | s837048563 | 38 | 34 | 3,188 | 3,188 | Accepted | Accepted | 10.53 | s = eval(input())
0
count_0 = 0
count_1 = 0
for i in range(len(s)):
if s[i] == '0':
count_0 += 1
else:
count_1 += 1
print((min(count_0,count_1) * 2))
| s = eval(input())
count_0 = 0
count_1 = 0
for i in range(len(s)):
if s[i] == '0':
count_0 += 1
else:
count_1 += 1
print((min(count_0,count_1) * 2))
| 12 | 11 | 179 | 176 | s = eval(input())
0
count_0 = 0
count_1 = 0
for i in range(len(s)):
if s[i] == "0":
count_0 += 1
else:
count_1 += 1
print((min(count_0, count_1) * 2))
| s = eval(input())
count_0 = 0
count_1 = 0
for i in range(len(s)):
if s[i] == "0":
count_0 += 1
else:
count_1 += 1
print((min(count_0, count_1) * 2))
| false | 8.333333 | [
"-0"
] | false | 0.037956 | 0.039805 | 0.953535 | [
"s967098155",
"s837048563"
] |
u652656291 | p02708 | python | s423952514 | s990876568 | 142 | 123 | 9,124 | 9,172 | Accepted | Accepted | 13.38 | n,k=list(map(int,input().split()))
ans=0
for i in range(k,n+2):
a=0.5*i*(i-1)
b=0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
ans+=int(b-a+1)
print((ans%(10**9+7))) | MOD = 10 ** 9 + 7
n, k = list(map(int, input().split()))
def calc(a):
smallest = a * (a-1) // 2
largest = smallest + a * (n-a+1)
return largest - smallest + 1
ans = 0
for a in range(k, n+2):
ans += calc(a)
ans %= MOD
print(ans)
| 9 | 15 | 162 | 260 | n, k = list(map(int, input().split()))
ans = 0
for i in range(k, n + 2):
a = 0.5 * i * (i - 1)
b = 0.5 * n * (n + 1) - 0.5 * (n - i) * (n - i + 1)
ans += int(b - a + 1)
print((ans % (10**9 + 7)))
| MOD = 10**9 + 7
n, k = list(map(int, input().split()))
def calc(a):
smallest = a * (a - 1) // 2
largest = smallest + a * (n - a + 1)
return largest - smallest + 1
ans = 0
for a in range(k, n + 2):
ans += calc(a)
ans %= MOD
print(ans)
| false | 40 | [
"+MOD = 10**9 + 7",
"+",
"+",
"+def calc(a):",
"+ smallest = a * (a - 1) // 2",
"+ largest = smallest + a * (n - a + 1)",
"+ return largest - smallest + 1",
"+",
"+",
"-for i in range(k, n + 2):",
"- a = 0.5 * i * (i - 1)",
"- b = 0.5 * n * (n + 1) - 0.5 * (n - i) * (n - i + 1)",
"- ans += int(b - a + 1)",
"-print((ans % (10**9 + 7)))",
"+for a in range(k, n + 2):",
"+ ans += calc(a)",
"+ ans %= MOD",
"+print(ans)"
] | false | 0.188334 | 0.007815 | 24.099631 | [
"s423952514",
"s990876568"
] |
u620084012 | p03612 | python | s180463128 | s770047995 | 82 | 67 | 14,008 | 14,008 | Accepted | Accepted | 18.29 | N = int(eval(input()))
p = list(map(int,input().split()))
l = [0 for k in range(N+2)]
for k in range(N):
if p[k] == k+1:
l[k+1] = 1
t = 0
ans = 0
for e in l:
if e == 1:
t += 1
else:
ans += (t+1)//2
t = 0
print(ans)
| N = int(eval(input()))
p = list(map(int,input().split()))
ans = 0
k = 0
while k < N:
if p[k] == k+1:
k += 1
ans += 1
k += 1
print(ans)
| 17 | 10 | 271 | 162 | N = int(eval(input()))
p = list(map(int, input().split()))
l = [0 for k in range(N + 2)]
for k in range(N):
if p[k] == k + 1:
l[k + 1] = 1
t = 0
ans = 0
for e in l:
if e == 1:
t += 1
else:
ans += (t + 1) // 2
t = 0
print(ans)
| N = int(eval(input()))
p = list(map(int, input().split()))
ans = 0
k = 0
while k < N:
if p[k] == k + 1:
k += 1
ans += 1
k += 1
print(ans)
| false | 41.176471 | [
"-l = [0 for k in range(N + 2)]",
"-for k in range(N):",
"+ans = 0",
"+k = 0",
"+while k < N:",
"- l[k + 1] = 1",
"-t = 0",
"-ans = 0",
"-for e in l:",
"- if e == 1:",
"- t += 1",
"- else:",
"- ans += (t + 1) // 2",
"- t = 0",
"+ k += 1",
"+ ans += 1",
"+ k += 1"
] | false | 0.037199 | 0.03686 | 1.009199 | [
"s180463128",
"s770047995"
] |
u077291787 | p03846 | python | s767964934 | s415911937 | 66 | 44 | 16,624 | 14,324 | Accepted | Accepted | 33.33 | # ARC066C - Lining Up (ABC050C)
from collections import Counter
def main():
n = int(eval(input()))
a = sorted(Counter(list(map(int, input().rstrip().split()))).items())
MOD = 10 ** 9 + 7
if n % 2 == 1 and a[0][1] != 1:
print((0))
elif not all(i[1] == 2 for i in a[1:]):
print((0))
else:
if n % 2 == 0:
print((2 ** len(a) % MOD))
else:
print((2 ** (len(a) - 1) % MOD))
if __name__ == "__main__":
main() | # ARC066C - Lining Up (ABC050C)
from collections import Counter
def main():
n = int(eval(input()))
a = tuple(map(int, input().rstrip().split()))
MOD = 10 ** 9 + 7
s = (n // 2) * 2
l = (n + 1) // 2
p = l if n % 2 == 0 else l - 1
if sum(a) == s * l:
print((2 ** p % MOD))
else:
print((0))
if __name__ == "__main__":
main() | 21 | 19 | 489 | 384 | # ARC066C - Lining Up (ABC050C)
from collections import Counter
def main():
n = int(eval(input()))
a = sorted(Counter(list(map(int, input().rstrip().split()))).items())
MOD = 10**9 + 7
if n % 2 == 1 and a[0][1] != 1:
print((0))
elif not all(i[1] == 2 for i in a[1:]):
print((0))
else:
if n % 2 == 0:
print((2 ** len(a) % MOD))
else:
print((2 ** (len(a) - 1) % MOD))
if __name__ == "__main__":
main()
| # ARC066C - Lining Up (ABC050C)
from collections import Counter
def main():
n = int(eval(input()))
a = tuple(map(int, input().rstrip().split()))
MOD = 10**9 + 7
s = (n // 2) * 2
l = (n + 1) // 2
p = l if n % 2 == 0 else l - 1
if sum(a) == s * l:
print((2**p % MOD))
else:
print((0))
if __name__ == "__main__":
main()
| false | 9.52381 | [
"- a = sorted(Counter(list(map(int, input().rstrip().split()))).items())",
"+ a = tuple(map(int, input().rstrip().split()))",
"- if n % 2 == 1 and a[0][1] != 1:",
"+ s = (n // 2) * 2",
"+ l = (n + 1) // 2",
"+ p = l if n % 2 == 0 else l - 1",
"+ if sum(a) == s * l:",
"+ print((2**p % MOD))",
"+ else:",
"- elif not all(i[1] == 2 for i in a[1:]):",
"- print((0))",
"- else:",
"- if n % 2 == 0:",
"- print((2 ** len(a) % MOD))",
"- else:",
"- print((2 ** (len(a) - 1) % MOD))"
] | false | 0.059992 | 0.059514 | 1.008046 | [
"s767964934",
"s415911937"
] |
u423665486 | p02688 | python | s889733480 | s010623895 | 56 | 22 | 67,876 | 9,112 | Accepted | Accepted | 60.71 | def resolve():
n, k = list(map(int, input().split()))
p = [0]*n
for _ in range(k):
eval(input())
t = list(map(int, input().split()))
for i in t:
p[i-1] += 1
ans = 0
for i in p:
if i == 0:
ans += 1
print(ans)
resolve() | def resolve():
n, k = list(map(int, input().split()))
s = [False]*n
for i in range(k):
eval(input())
for j in list(map(int, input().split())):
s[j-1] = True
print((s.count(False)))
resolve() | 14 | 9 | 238 | 195 | def resolve():
n, k = list(map(int, input().split()))
p = [0] * n
for _ in range(k):
eval(input())
t = list(map(int, input().split()))
for i in t:
p[i - 1] += 1
ans = 0
for i in p:
if i == 0:
ans += 1
print(ans)
resolve()
| def resolve():
n, k = list(map(int, input().split()))
s = [False] * n
for i in range(k):
eval(input())
for j in list(map(int, input().split())):
s[j - 1] = True
print((s.count(False)))
resolve()
| false | 35.714286 | [
"- p = [0] * n",
"- for _ in range(k):",
"+ s = [False] * n",
"+ for i in range(k):",
"- t = list(map(int, input().split()))",
"- for i in t:",
"- p[i - 1] += 1",
"- ans = 0",
"- for i in p:",
"- if i == 0:",
"- ans += 1",
"- print(ans)",
"+ for j in list(map(int, input().split())):",
"+ s[j - 1] = True",
"+ print((s.count(False)))"
] | false | 0.080731 | 0.037319 | 2.163306 | [
"s889733480",
"s010623895"
] |
u753386263 | p03163 | python | s159413471 | s582537618 | 483 | 252 | 120,300 | 148,692 | Accepted | Accepted | 47.83 | N, W = list(map(int, input().split()))
w, v = [0] * N, [0] * N
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える
for i in range(N):
for j in range(W+1):#重さ0からWまでチェック
if j-w[i]>=0:#入れてもOKな場合,容量と価値を足す
dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i])
else:#何も入れずに先に進む
dp[i+1][j]=dp[i][j]
print((max(dp[N])))
| N, W = list(map(int, input().split()))
w, v = [0] * N, [0] * N
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
DP = [[0] * (W + 2) for i in range(N + 2)]
"""
DP[0][W]
DP[i][j]
i:荷物の個数
j:残り容量
"""
for i in range(N):
for j in range(W+1):
if j>=w[i]:#残り容量に余裕があるとき
DP[i+1][j]=max(DP[i][j],DP[i][j-w[i]]+v[i])
else:
DP[i+1][j]=DP[i][j]
print((max(DP[N]))) | 15 | 20 | 462 | 417 | N, W = list(map(int, input().split()))
w, v = [0] * N, [0] * N
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える
for i in range(N):
for j in range(W + 1): # 重さ0からWまでチェック
if j - w[i] >= 0: # 入れてもOKな場合,容量と価値を足す
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])
else: # 何も入れずに先に進む
dp[i + 1][j] = dp[i][j]
print((max(dp[N])))
| N, W = list(map(int, input().split()))
w, v = [0] * N, [0] * N
for i in range(N):
w[i], v[i] = list(map(int, input().split()))
DP = [[0] * (W + 2) for i in range(N + 2)]
"""
DP[0][W]
DP[i][j]
i:荷物の個数
j:残り容量
"""
for i in range(N):
for j in range(W + 1):
if j >= w[i]: # 残り容量に余裕があるとき
DP[i + 1][j] = max(DP[i][j], DP[i][j - w[i]] + v[i])
else:
DP[i + 1][j] = DP[i][j]
print((max(DP[N])))
| false | 25 | [
"-dp = [[0] * (W + 1) for _ in range(N + 1)]",
"-# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える",
"+DP = [[0] * (W + 2) for i in range(N + 2)]",
"+\"\"\"",
"+DP[0][W]",
"+DP[i][j]",
"+i:荷物の個数",
"+j:残り容量",
"+\"\"\"",
"- for j in range(W + 1): # 重さ0からWまでチェック",
"- if j - w[i] >= 0: # 入れてもOKな場合,容量と価値を足す",
"- dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])",
"- else: # 何も入れずに先に進む",
"- dp[i + 1][j] = dp[i][j]",
"-print((max(dp[N])))",
"+ for j in range(W + 1):",
"+ if j >= w[i]: # 残り容量に余裕があるとき",
"+ DP[i + 1][j] = max(DP[i][j], DP[i][j - w[i]] + v[i])",
"+ else:",
"+ DP[i + 1][j] = DP[i][j]",
"+print((max(DP[N])))"
] | false | 0.082082 | 0.082328 | 0.997002 | [
"s159413471",
"s582537618"
] |
u936985471 | p03044 | python | s571320926 | s038881242 | 748 | 388 | 45,396 | 42,684 | Accepted | Accepted | 48.13 | import sys
readline = sys.stdin.readline
# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
u,v,w = list(map(int,readline().split()))
G[u - 1].append([v - 1, w])
G[v - 1].append([u - 1, w])
ans = [-1] * N
stack = []
# 頂点, 色
stack.append([0,0])
while stack:
v,color = stack.pop()
if ans[v] != -1:
continue
ans[v] = color
for child in G[v]:
col = color
if child[1] % 2 == 1:
col ^= 1
stack.append([child[0], col])
for a in ans:
print(a) | import sys
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
u,v,w = list(map(int,readline().split()))
G[u - 1].append((v - 1, w))
G[v - 1].append((u - 1, w))
color = [-1] * N
stack = []
stack.append([0, -1, 0])
while stack:
v,parent,cost = stack.pop()
color[v] = cost
for child in G[v]:
if child[0] == parent:
continue
stack.append([child[0], v, (cost + child[1]) % 2])
for c in color:
print(c) | 30 | 24 | 556 | 496 | import sys
readline = sys.stdin.readline
# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, readline().split()))
G[u - 1].append([v - 1, w])
G[v - 1].append([u - 1, w])
ans = [-1] * N
stack = []
# 頂点, 色
stack.append([0, 0])
while stack:
v, color = stack.pop()
if ans[v] != -1:
continue
ans[v] = color
for child in G[v]:
col = color
if child[1] % 2 == 1:
col ^= 1
stack.append([child[0], col])
for a in ans:
print(a)
| import sys
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
u, v, w = list(map(int, readline().split()))
G[u - 1].append((v - 1, w))
G[v - 1].append((u - 1, w))
color = [-1] * N
stack = []
stack.append([0, -1, 0])
while stack:
v, parent, cost = stack.pop()
color[v] = cost
for child in G[v]:
if child[0] == parent:
continue
stack.append([child[0], v, (cost + child[1]) % 2])
for c in color:
print(c)
| false | 20 | [
"-# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい",
"- G[u - 1].append([v - 1, w])",
"- G[v - 1].append([u - 1, w])",
"-ans = [-1] * N",
"+ G[u - 1].append((v - 1, w))",
"+ G[v - 1].append((u - 1, w))",
"+color = [-1] * N",
"-# 頂点, 色",
"-stack.append([0, 0])",
"+stack.append([0, -1, 0])",
"- v, color = stack.pop()",
"- if ans[v] != -1:",
"- continue",
"- ans[v] = color",
"+ v, parent, cost = stack.pop()",
"+ color[v] = cost",
"- col = color",
"- if child[1] % 2 == 1:",
"- col ^= 1",
"- stack.append([child[0], col])",
"-for a in ans:",
"- print(a)",
"+ if child[0] == parent:",
"+ continue",
"+ stack.append([child[0], v, (cost + child[1]) % 2])",
"+for c in color:",
"+ print(c)"
] | false | 0.168455 | 0.086779 | 1.941187 | [
"s571320926",
"s038881242"
] |
u852690916 | p03240 | python | s760459903 | s168935451 | 651 | 209 | 3,064 | 42,972 | Accepted | Accepted | 67.9 | N=int(eval(input()))
xyh=[list(map(int,input().split())) for _ in range(N)]
def calcH(x,y,h,Cx,Cy):
if h>0:
return(h+abs(x-Cx)+abs(y-Cy))
return -1
for Cx in range(100+1):
for Cy in range(100+1):
H=-1
check=[]
for x,y,h in xyh:
Hi=calcH(x,y,h,Cx,Cy)
if Hi==-1:
check.append(abs(x-Cx)+abs(y-Cy))
continue
if H==-1:
H=Hi
elif Hi!=H:
break
else:
for c in check:
if H>c:
break
else:
print((Cx,Cy,H))
exit() | import sys
def main():
input = sys.stdin.readline
N = int(eval(input()))
xyh = [tuple(map(int, input().split())) for _ in range(N)]
xyh.sort(reverse=True, key=lambda x:x[2])
def check(cx, cy):
def dist(x, y): return abs(x-cx) + abs(y-cy)
tmp = 0
for x, y, h in xyh:
d = dist(x,y)
if h == 0:
if tmp > d: return -1
else:
if tmp != 0 and tmp != h+d: return -1
tmp = h+d
return tmp
for x in range(101):
for y in range(101):
H = check(x,y)
if H >= 0:
print(('{} {} {}'.format(x,y,H)))
return
if __name__ == '__main__':
main() | 28 | 28 | 679 | 754 | N = int(eval(input()))
xyh = [list(map(int, input().split())) for _ in range(N)]
def calcH(x, y, h, Cx, Cy):
if h > 0:
return h + abs(x - Cx) + abs(y - Cy)
return -1
for Cx in range(100 + 1):
for Cy in range(100 + 1):
H = -1
check = []
for x, y, h in xyh:
Hi = calcH(x, y, h, Cx, Cy)
if Hi == -1:
check.append(abs(x - Cx) + abs(y - Cy))
continue
if H == -1:
H = Hi
elif Hi != H:
break
else:
for c in check:
if H > c:
break
else:
print((Cx, Cy, H))
exit()
| import sys
def main():
input = sys.stdin.readline
N = int(eval(input()))
xyh = [tuple(map(int, input().split())) for _ in range(N)]
xyh.sort(reverse=True, key=lambda x: x[2])
def check(cx, cy):
def dist(x, y):
return abs(x - cx) + abs(y - cy)
tmp = 0
for x, y, h in xyh:
d = dist(x, y)
if h == 0:
if tmp > d:
return -1
else:
if tmp != 0 and tmp != h + d:
return -1
tmp = h + d
return tmp
for x in range(101):
for y in range(101):
H = check(x, y)
if H >= 0:
print(("{} {} {}".format(x, y, H)))
return
if __name__ == "__main__":
main()
| false | 0 | [
"-N = int(eval(input()))",
"-xyh = [list(map(int, input().split())) for _ in range(N)]",
"+import sys",
"-def calcH(x, y, h, Cx, Cy):",
"- if h > 0:",
"- return h + abs(x - Cx) + abs(y - Cy)",
"- return -1",
"+def main():",
"+ input = sys.stdin.readline",
"+ N = int(eval(input()))",
"+ xyh = [tuple(map(int, input().split())) for _ in range(N)]",
"+ xyh.sort(reverse=True, key=lambda x: x[2])",
"+",
"+ def check(cx, cy):",
"+ def dist(x, y):",
"+ return abs(x - cx) + abs(y - cy)",
"+",
"+ tmp = 0",
"+ for x, y, h in xyh:",
"+ d = dist(x, y)",
"+ if h == 0:",
"+ if tmp > d:",
"+ return -1",
"+ else:",
"+ if tmp != 0 and tmp != h + d:",
"+ return -1",
"+ tmp = h + d",
"+ return tmp",
"+",
"+ for x in range(101):",
"+ for y in range(101):",
"+ H = check(x, y)",
"+ if H >= 0:",
"+ print((\"{} {} {}\".format(x, y, H)))",
"+ return",
"-for Cx in range(100 + 1):",
"- for Cy in range(100 + 1):",
"- H = -1",
"- check = []",
"- for x, y, h in xyh:",
"- Hi = calcH(x, y, h, Cx, Cy)",
"- if Hi == -1:",
"- check.append(abs(x - Cx) + abs(y - Cy))",
"- continue",
"- if H == -1:",
"- H = Hi",
"- elif Hi != H:",
"- break",
"- else:",
"- for c in check:",
"- if H > c:",
"- break",
"- else:",
"- print((Cx, Cy, H))",
"- exit()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.04579 | 0.038578 | 1.186939 | [
"s760459903",
"s168935451"
] |
u089032001 | p02910 | python | s074942846 | s635349537 | 25 | 19 | 3,188 | 3,188 | Accepted | Accepted | 24 | import re
def inpl():
return list(map(int, input().split()))
S = eval(input())
p = re.compile(r'([^L][^R])*[^L]?$')
if p.match(S):
print('Yes')
else:
print('No') | import re
def inpl():
return list(map(int, input().split()))
S = eval(input())
p = re.compile(r'^([^L][^R])*[^L]?$')
if p.match(S):
print('Yes')
else:
print('No') | 15 | 15 | 187 | 188 | import re
def inpl():
return list(map(int, input().split()))
S = eval(input())
p = re.compile(r"([^L][^R])*[^L]?$")
if p.match(S):
print("Yes")
else:
print("No")
| import re
def inpl():
return list(map(int, input().split()))
S = eval(input())
p = re.compile(r"^([^L][^R])*[^L]?$")
if p.match(S):
print("Yes")
else:
print("No")
| false | 0 | [
"-p = re.compile(r\"([^L][^R])*[^L]?$\")",
"+p = re.compile(r\"^([^L][^R])*[^L]?$\")"
] | false | 0.041382 | 0.040495 | 1.021896 | [
"s074942846",
"s635349537"
] |
u432551953 | p02954 | python | s054077242 | s176547143 | 506 | 411 | 54,616 | 57,264 | Accepted | Accepted | 18.77 | import sys
input = sys.stdin.readline
def main():
s = input().strip()
rc = 0
lc = 0
i = 0
n = len(s)
ans = [0] * n
while i <= n-2:
if s[i] == 'R':
rc += 1
if s[i] == 'R' and s[i+1] == 'L':
# 上でカウントしたのを覗く
rc -= 1
k = 0
while i+2+k < n and s[i+2+k] != 'R':
k += 1
# print("{rc k}", rc, k)
tor = 1 + ((k+1) // 2) + (rc // 2)
tol = 1 + ((rc+1) // 2) + (k // 2)
# print('tor, rol',tor, tol)
if max(rc, k) % 2 == 0:
# RはRと同じ場所にいる
ans[i] = tor
ans[i+1] = tol
else:
# 違う場所
ans[i] = tor
ans[i+1] = tol
rc = 0
i = i + 1 + k
i += 1
for i in ans:
print("{} ".format(i) , end="")
print("")
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
def main():
S = input().strip()
n = len(S)
ans = [0] * n
for _ in range(2):
cnt = 0
for i in range(n):
if S[i] == 'R':
cnt += 1
else:
ans[i] += cnt // 2
ans[i-1] += (cnt + 1) // 2
cnt = 0
ans = ans[::-1]
S = S[::-1]
S = ['R' if S[i] == 'L' else 'L' for i in range(n)]
for i in range(n):
print("{} ".format(ans[i]), end="")
print("")
if __name__ == '__main__':
main()
| 40 | 25 | 738 | 472 | import sys
input = sys.stdin.readline
def main():
s = input().strip()
rc = 0
lc = 0
i = 0
n = len(s)
ans = [0] * n
while i <= n - 2:
if s[i] == "R":
rc += 1
if s[i] == "R" and s[i + 1] == "L":
# 上でカウントしたのを覗く
rc -= 1
k = 0
while i + 2 + k < n and s[i + 2 + k] != "R":
k += 1
# print("{rc k}", rc, k)
tor = 1 + ((k + 1) // 2) + (rc // 2)
tol = 1 + ((rc + 1) // 2) + (k // 2)
# print('tor, rol',tor, tol)
if max(rc, k) % 2 == 0:
# RはRと同じ場所にいる
ans[i] = tor
ans[i + 1] = tol
else:
# 違う場所
ans[i] = tor
ans[i + 1] = tol
rc = 0
i = i + 1 + k
i += 1
for i in ans:
print("{} ".format(i), end="")
print("")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
S = input().strip()
n = len(S)
ans = [0] * n
for _ in range(2):
cnt = 0
for i in range(n):
if S[i] == "R":
cnt += 1
else:
ans[i] += cnt // 2
ans[i - 1] += (cnt + 1) // 2
cnt = 0
ans = ans[::-1]
S = S[::-1]
S = ["R" if S[i] == "L" else "L" for i in range(n)]
for i in range(n):
print("{} ".format(ans[i]), end="")
print("")
if __name__ == "__main__":
main()
| false | 37.5 | [
"- s = input().strip()",
"- rc = 0",
"- lc = 0",
"- i = 0",
"- n = len(s)",
"+ S = input().strip()",
"+ n = len(S)",
"- while i <= n - 2:",
"- if s[i] == \"R\":",
"- rc += 1",
"- if s[i] == \"R\" and s[i + 1] == \"L\":",
"- # 上でカウントしたのを覗く",
"- rc -= 1",
"- k = 0",
"- while i + 2 + k < n and s[i + 2 + k] != \"R\":",
"- k += 1",
"- # print(\"{rc k}\", rc, k)",
"- tor = 1 + ((k + 1) // 2) + (rc // 2)",
"- tol = 1 + ((rc + 1) // 2) + (k // 2)",
"- # print('tor, rol',tor, tol)",
"- if max(rc, k) % 2 == 0:",
"- # RはRと同じ場所にいる",
"- ans[i] = tor",
"- ans[i + 1] = tol",
"+ for _ in range(2):",
"+ cnt = 0",
"+ for i in range(n):",
"+ if S[i] == \"R\":",
"+ cnt += 1",
"- # 違う場所",
"- ans[i] = tor",
"- ans[i + 1] = tol",
"- rc = 0",
"- i = i + 1 + k",
"- i += 1",
"- for i in ans:",
"- print(\"{} \".format(i), end=\"\")",
"+ ans[i] += cnt // 2",
"+ ans[i - 1] += (cnt + 1) // 2",
"+ cnt = 0",
"+ ans = ans[::-1]",
"+ S = S[::-1]",
"+ S = [\"R\" if S[i] == \"L\" else \"L\" for i in range(n)]",
"+ for i in range(n):",
"+ print(\"{} \".format(ans[i]), end=\"\")"
] | false | 0.035699 | 0.036597 | 0.975482 | [
"s054077242",
"s176547143"
] |
u941047297 | p03705 | python | s444791824 | s545182271 | 168 | 35 | 38,412 | 9,160 | Accepted | Accepted | 79.17 | def main():
n, a, b = list(map(int, input().split()))
if (n == 1 and a != b) or (b < a):
print((0))
exit()
mini = a * (n - 1) + b
maxi = a + b * (n - 1)
print((maxi - mini + 1))
if __name__ == '__main__':
main()
| def main():
n, a, b = list(map(int, input().split()))
print((0 if (n == 1 and a != b) or a > b else (b - a) * (n - 1) + a - b + 1))
if __name__ == '__main__':
main()
| 12 | 6 | 261 | 180 | def main():
n, a, b = list(map(int, input().split()))
if (n == 1 and a != b) or (b < a):
print((0))
exit()
mini = a * (n - 1) + b
maxi = a + b * (n - 1)
print((maxi - mini + 1))
if __name__ == "__main__":
main()
| def main():
n, a, b = list(map(int, input().split()))
print((0 if (n == 1 and a != b) or a > b else (b - a) * (n - 1) + a - b + 1))
if __name__ == "__main__":
main()
| false | 50 | [
"- if (n == 1 and a != b) or (b < a):",
"- print((0))",
"- exit()",
"- mini = a * (n - 1) + b",
"- maxi = a + b * (n - 1)",
"- print((maxi - mini + 1))",
"+ print((0 if (n == 1 and a != b) or a > b else (b - a) * (n - 1) + a - b + 1))"
] | false | 0.032664 | 0.039364 | 0.829782 | [
"s444791824",
"s545182271"
] |
u788260274 | p03013 | python | s798566961 | s405856857 | 608 | 204 | 522,316 | 95,856 | Accepted | Accepted | 66.45 | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
N, M = list(map(int, input().split()))
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
dp[i] = dp[i-1] + dp[i-2]
ans = 1
a = -1
for i in range(M):
b = int(eval(input()))
c = b - a - 2
if c < 0:
print((0))
sys.exit()
else:
ans = (ans * dp[c]) % mod
a = b
ans = (ans * dp[N-a-1]) % mod
print(ans) | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
N, M = list(map(int, input().split()))
a = set()
for i in range(M):
a.add(int(eval(input())))
dp = [0 for i in range(N+1)]
dp[0] = 1
if 1 not in a:
dp[1] = 1
else:
dp[1] = 0
for i in range(2,N+1):
if i not in a:
dp[i] = (dp[i-1] + dp[i-2]) % mod
else:
dp[i] = 0
print((dp[N] % mod)) | 44 | 39 | 790 | 730 | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque, Counter, defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9 + 7
# mod = 998244353
N, M = list(map(int, input().split()))
dp = [0 for i in range(N + 1)]
dp[0] = 1
dp[1] = 1
for i in range(2, N + 1):
dp[i] = dp[i - 1] + dp[i - 2]
ans = 1
a = -1
for i in range(M):
b = int(eval(input()))
c = b - a - 2
if c < 0:
print((0))
sys.exit()
else:
ans = (ans * dp[c]) % mod
a = b
ans = (ans * dp[N - a - 1]) % mod
print(ans)
| from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque, Counter, defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9 + 7
# mod = 998244353
N, M = list(map(int, input().split()))
a = set()
for i in range(M):
a.add(int(eval(input())))
dp = [0 for i in range(N + 1)]
dp[0] = 1
if 1 not in a:
dp[1] = 1
else:
dp[1] = 0
for i in range(2, N + 1):
if i not in a:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
else:
dp[i] = 0
print((dp[N] % mod))
| false | 11.363636 | [
"+a = set()",
"+for i in range(M):",
"+ a.add(int(eval(input())))",
"-dp[1] = 1",
"+if 1 not in a:",
"+ dp[1] = 1",
"+else:",
"+ dp[1] = 0",
"- dp[i] = dp[i - 1] + dp[i - 2]",
"-ans = 1",
"-a = -1",
"-for i in range(M):",
"- b = int(eval(input()))",
"- c = b - a - 2",
"- if c < 0:",
"- print((0))",
"- sys.exit()",
"+ if i not in a:",
"+ dp[i] = (dp[i - 1] + dp[i - 2]) % mod",
"- ans = (ans * dp[c]) % mod",
"- a = b",
"-ans = (ans * dp[N - a - 1]) % mod",
"-print(ans)",
"+ dp[i] = 0",
"+print((dp[N] % mod))"
] | false | 0.035615 | 0.007678 | 4.638492 | [
"s798566961",
"s405856857"
] |
u372144784 | p03363 | python | s350621635 | s065636115 | 322 | 266 | 85,780 | 83,988 | Accepted | Accepted | 17.39 | import sys
readline = sys.stdin.buffer.readline
from collections import Counter
n = int(readline())
lst1 = list(map(int,readline().split()))
def cumsum(lst): #元のリストを保持
res = lst[:]
for i in range(1,len(res)):
res[i] += res[i-1]
return res
lst2 = [0]+cumsum(lst1)
c = Counter(lst2)
ans = 0
for i in range(len(lst2)-1):
c[lst2[i]] -= 1
ans += c[lst2[i]]
print(ans) | import sys
readline = sys.stdin.buffer.readline
n = int(readline())
lst1 = list(map(int,readline().split()))
def cumsum(lst): #元のリストを保持
res = lst[:]
for i in range(1,len(res)):
res[i] += res[i-1]
return res
lst2 = [0] + cumsum(lst1)
ans = 0
dic1 = dict()
for i in lst2:
if i in dic1:
ans += dic1[i]
dic1[i] += 1
else:
dic1[i] = 1
print(ans) | 22 | 24 | 416 | 420 | import sys
readline = sys.stdin.buffer.readline
from collections import Counter
n = int(readline())
lst1 = list(map(int, readline().split()))
def cumsum(lst): # 元のリストを保持
res = lst[:]
for i in range(1, len(res)):
res[i] += res[i - 1]
return res
lst2 = [0] + cumsum(lst1)
c = Counter(lst2)
ans = 0
for i in range(len(lst2) - 1):
c[lst2[i]] -= 1
ans += c[lst2[i]]
print(ans)
| import sys
readline = sys.stdin.buffer.readline
n = int(readline())
lst1 = list(map(int, readline().split()))
def cumsum(lst): # 元のリストを保持
res = lst[:]
for i in range(1, len(res)):
res[i] += res[i - 1]
return res
lst2 = [0] + cumsum(lst1)
ans = 0
dic1 = dict()
for i in lst2:
if i in dic1:
ans += dic1[i]
dic1[i] += 1
else:
dic1[i] = 1
print(ans)
| false | 8.333333 | [
"-from collections import Counter",
"-",
"-c = Counter(lst2)",
"-for i in range(len(lst2) - 1):",
"- c[lst2[i]] -= 1",
"- ans += c[lst2[i]]",
"+dic1 = dict()",
"+for i in lst2:",
"+ if i in dic1:",
"+ ans += dic1[i]",
"+ dic1[i] += 1",
"+ else:",
"+ dic1[i] = 1"
] | false | 0.042033 | 0.044376 | 0.947218 | [
"s350621635",
"s065636115"
] |
u624475441 | p03339 | python | s984995822 | s215419537 | 216 | 161 | 15,244 | 3,700 | Accepted | Accepted | 25.46 | N = int(eval(input()))
S = eval(input())
ans = N
E = [0] * (N + 1)
for i in range(N):
E[i+1] = E[i] + (S[i] == 'E')
for i in range(N):
LR = i - E[i] + E[N] - E[i+1]
if LR < ans: ans = LR
print(ans) | eval(input())
S = eval(input())
res = cnt = S.count('E')
for c in S:
cnt -= c == 'E'
res = min(res, cnt)
cnt += c == 'W'
print(res) | 10 | 8 | 206 | 138 | N = int(eval(input()))
S = eval(input())
ans = N
E = [0] * (N + 1)
for i in range(N):
E[i + 1] = E[i] + (S[i] == "E")
for i in range(N):
LR = i - E[i] + E[N] - E[i + 1]
if LR < ans:
ans = LR
print(ans)
| eval(input())
S = eval(input())
res = cnt = S.count("E")
for c in S:
cnt -= c == "E"
res = min(res, cnt)
cnt += c == "W"
print(res)
| false | 20 | [
"-N = int(eval(input()))",
"+eval(input())",
"-ans = N",
"-E = [0] * (N + 1)",
"-for i in range(N):",
"- E[i + 1] = E[i] + (S[i] == \"E\")",
"-for i in range(N):",
"- LR = i - E[i] + E[N] - E[i + 1]",
"- if LR < ans:",
"- ans = LR",
"-print(ans)",
"+res = cnt = S.count(\"E\")",
"+for c in S:",
"+ cnt -= c == \"E\"",
"+ res = min(res, cnt)",
"+ cnt += c == \"W\"",
"+print(res)"
] | false | 0.043716 | 0.044403 | 0.984511 | [
"s984995822",
"s215419537"
] |
u608088992 | p03013 | python | s166105881 | s334610579 | 103 | 95 | 12,392 | 7,668 | Accepted | Accepted | 7.77 | import sys, math, collections, heapq, itertools
def gcd(a, b):
a, b = max(a, b), min(a, b)
while a % b > 0: a, b = b, a % b
return b
def solve():
file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
INF = 10 ** 25
mod = 7 + 10 ** 9
N, M = list(map(int, file().split()))
broken = set()
for i in range(M): broken |= {int(file())}
DP = [0] * (N + 1)
DP[0] = 1
for i in range(N):
if i + 1 not in broken:
DP[i+1] += DP[i]
DP[i+1] %= mod
if i + 2 <= N:
if i + 2 not in broken:
DP[i+2] += DP[i]
DP[i+2] %= mod
print((DP[N]))
return 0
if __name__ == "__main__":
solve() | import sys
def solve():
input = sys.stdin.readline
N, M= list(map(int, input().split()))
mod = 7 + 10 ** 9
A = [True] * (N + 1)
for _ in range(M):
A[int(eval(input()))] = False
DP = [0] * (N + 1)
DP[0] = 1
for i in range(N):
if i < N - 1:
if A[i + 2]:
DP[i + 2] += DP[i]
DP[i + 2] %= mod
if A[i + 1]:
DP[i + 1] += DP[i]
DP[i + 1] %= mod
print((DP[N]))
return 0
if __name__ == "__main__":
solve() | 29 | 26 | 759 | 547 | import sys, math, collections, heapq, itertools
def gcd(a, b):
a, b = max(a, b), min(a, b)
while a % b > 0:
a, b = b, a % b
return b
def solve():
file = sys.stdin.readline # single: int(file()), line: map(int, file().split())
INF = 10**25
mod = 7 + 10**9
N, M = list(map(int, file().split()))
broken = set()
for i in range(M):
broken |= {int(file())}
DP = [0] * (N + 1)
DP[0] = 1
for i in range(N):
if i + 1 not in broken:
DP[i + 1] += DP[i]
DP[i + 1] %= mod
if i + 2 <= N:
if i + 2 not in broken:
DP[i + 2] += DP[i]
DP[i + 2] %= mod
print((DP[N]))
return 0
if __name__ == "__main__":
solve()
| import sys
def solve():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
mod = 7 + 10**9
A = [True] * (N + 1)
for _ in range(M):
A[int(eval(input()))] = False
DP = [0] * (N + 1)
DP[0] = 1
for i in range(N):
if i < N - 1:
if A[i + 2]:
DP[i + 2] += DP[i]
DP[i + 2] %= mod
if A[i + 1]:
DP[i + 1] += DP[i]
DP[i + 1] %= mod
print((DP[N]))
return 0
if __name__ == "__main__":
solve()
| false | 10.344828 | [
"-import sys, math, collections, heapq, itertools",
"-",
"-",
"-def gcd(a, b):",
"- a, b = max(a, b), min(a, b)",
"- while a % b > 0:",
"- a, b = b, a % b",
"- return b",
"+import sys",
"- file = sys.stdin.readline # single: int(file()), line: map(int, file().split())",
"- INF = 10**25",
"+ input = sys.stdin.readline",
"+ N, M = list(map(int, input().split()))",
"- N, M = list(map(int, file().split()))",
"- broken = set()",
"- for i in range(M):",
"- broken |= {int(file())}",
"+ A = [True] * (N + 1)",
"+ for _ in range(M):",
"+ A[int(eval(input()))] = False",
"- if i + 1 not in broken:",
"+ if i < N - 1:",
"+ if A[i + 2]:",
"+ DP[i + 2] += DP[i]",
"+ DP[i + 2] %= mod",
"+ if A[i + 1]:",
"- if i + 2 <= N:",
"- if i + 2 not in broken:",
"- DP[i + 2] += DP[i]",
"- DP[i + 2] %= mod"
] | false | 0.049463 | 0.049622 | 0.996793 | [
"s166105881",
"s334610579"
] |
u354638986 | p03607 | python | s726417700 | s459998340 | 276 | 239 | 11,884 | 15,076 | Accepted | Accepted | 13.41 | n = int(eval(input()))
nums = set()
for i in range(n):
a = int(eval(input()))
try:
nums.remove(a)
except KeyError:
nums.add(a)
print((len(nums)))
| n = int(eval(input()))
times = {}
for i in range(n):
a = int(eval(input()))
times[a] = times.get(a, 0) + 1
cnt = 0
for i in times:
if times[i]%2 == 1:
cnt += 1
print(cnt)
| 12 | 14 | 174 | 196 | n = int(eval(input()))
nums = set()
for i in range(n):
a = int(eval(input()))
try:
nums.remove(a)
except KeyError:
nums.add(a)
print((len(nums)))
| n = int(eval(input()))
times = {}
for i in range(n):
a = int(eval(input()))
times[a] = times.get(a, 0) + 1
cnt = 0
for i in times:
if times[i] % 2 == 1:
cnt += 1
print(cnt)
| false | 14.285714 | [
"-nums = set()",
"+times = {}",
"- try:",
"- nums.remove(a)",
"- except KeyError:",
"- nums.add(a)",
"-print((len(nums)))",
"+ times[a] = times.get(a, 0) + 1",
"+cnt = 0",
"+for i in times:",
"+ if times[i] % 2 == 1:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.047647 | 0.037984 | 1.254398 | [
"s726417700",
"s459998340"
] |
u882460931 | p03273 | python | s965021054 | s236339950 | 29 | 22 | 4,468 | 3,064 | Accepted | Accepted | 24.14 | h, w = (int(v) for v in input().split())
a = [input() for _ in range(h)]
my = [True for _ in range(h)]
mx = [True for _ in range(w)]
for y in range(h):
for x in range(w):
if a[y][x] != '.':
break
else:
my[y] = False
for x in range(w):
for y in range(h):
if a[y][x] != '.':
break
else:
mx[x] = False
for y in range(h):
for x in range(w):
if my[y] and mx[x]:
print(a[y][x], end='')
if my[y]:
print()
| h, w = (int(v) for v in input().split())
a = [input() for _ in range(h)]
my = [True for _ in range(h)]
mx = [True for _ in range(w)]
for y in range(h):
for x in range(w):
if a[y][x] != '.':
break
else:
my[y] = False
for x in range(w):
for y in range(h):
if a[y][x] != '.':
break
else:
mx[x] = False
s = ''
for y in range(h):
for x in range(w):
if my[y] and mx[x]:
s += a[y][x]
if my[y]:
s += '\n'
print(s, end='')
| 26 | 28 | 534 | 552 | h, w = (int(v) for v in input().split())
a = [input() for _ in range(h)]
my = [True for _ in range(h)]
mx = [True for _ in range(w)]
for y in range(h):
for x in range(w):
if a[y][x] != ".":
break
else:
my[y] = False
for x in range(w):
for y in range(h):
if a[y][x] != ".":
break
else:
mx[x] = False
for y in range(h):
for x in range(w):
if my[y] and mx[x]:
print(a[y][x], end="")
if my[y]:
print()
| h, w = (int(v) for v in input().split())
a = [input() for _ in range(h)]
my = [True for _ in range(h)]
mx = [True for _ in range(w)]
for y in range(h):
for x in range(w):
if a[y][x] != ".":
break
else:
my[y] = False
for x in range(w):
for y in range(h):
if a[y][x] != ".":
break
else:
mx[x] = False
s = ""
for y in range(h):
for x in range(w):
if my[y] and mx[x]:
s += a[y][x]
if my[y]:
s += "\n"
print(s, end="")
| false | 7.142857 | [
"+s = \"\"",
"- print(a[y][x], end=\"\")",
"+ s += a[y][x]",
"- print()",
"+ s += \"\\n\"",
"+print(s, end=\"\")"
] | false | 0.041198 | 0.1145 | 0.359806 | [
"s965021054",
"s236339950"
] |
u707808519 | p02727 | python | s966244303 | s450553002 | 293 | 252 | 23,644 | 24,064 | Accepted | Accepted | 13.99 | X, Y, R, G, N = list(map(int, input().split()))
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
n = sorted(n, reverse=True)
nr = 0; ng = 0; nn = 0
for i in range(N):
if n[nn] <= min(r[nr], g[ng]):
break
if r[nr] < g[ng]:
r[nr] = n[nn]
nr += 1
if nr == X:
nr = X-1
else:
g[ng] = n[nn]
ng += 1
if ng == Y:
ng = Y-1
nn += 1
print((sum(r) + sum(g))) | X, Y, R, G, N = list(map(int, input().split()))
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
apple = r + g + n
apple = sorted(apple)[len(apple)-(X+Y):]
print((sum(apple))) | 25 | 10 | 565 | 282 | X, Y, R, G, N = list(map(int, input().split()))
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R - X :]
g = sorted(g)[G - Y :]
n = sorted(n, reverse=True)
nr = 0
ng = 0
nn = 0
for i in range(N):
if n[nn] <= min(r[nr], g[ng]):
break
if r[nr] < g[ng]:
r[nr] = n[nn]
nr += 1
if nr == X:
nr = X - 1
else:
g[ng] = n[nn]
ng += 1
if ng == Y:
ng = Y - 1
nn += 1
print((sum(r) + sum(g)))
| X, Y, R, G, N = list(map(int, input().split()))
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R - X :]
g = sorted(g)[G - Y :]
apple = r + g + n
apple = sorted(apple)[len(apple) - (X + Y) :]
print((sum(apple)))
| false | 60 | [
"-n = sorted(n, reverse=True)",
"-nr = 0",
"-ng = 0",
"-nn = 0",
"-for i in range(N):",
"- if n[nn] <= min(r[nr], g[ng]):",
"- break",
"- if r[nr] < g[ng]:",
"- r[nr] = n[nn]",
"- nr += 1",
"- if nr == X:",
"- nr = X - 1",
"- else:",
"- g[ng] = n[nn]",
"- ng += 1",
"- if ng == Y:",
"- ng = Y - 1",
"- nn += 1",
"-print((sum(r) + sum(g)))",
"+apple = r + g + n",
"+apple = sorted(apple)[len(apple) - (X + Y) :]",
"+print((sum(apple)))"
] | false | 0.034765 | 0.033354 | 1.042315 | [
"s966244303",
"s450553002"
] |
u340781749 | p03097 | python | s520375017 | s486883283 | 310 | 189 | 11,364 | 11,276 | Accepted | Accepted | 39.03 | def split(n, a, b, used, ai, ans, width):
# print(n, a, b, used, ai, ans, width)
# print(*(f'{c:5d}' for c in ans))
# print(*(f'{c:05b}' for c in ans))
if width == 2:
ans[ai] = a
ans[ai + 1] = b
return
x = a ^ b
y = x & -x # Rightmost Bit where is different a and b
l = y.bit_length() - 1
used.append(l)
i = 0
for i in range(n):
if i not in used:
break
la, lb = a, a ^ (1 << i)
ra, rb = lb ^ y, b
width >>= 1
split(n, la, lb, used, ai, ans, width)
split(n, ra, rb, used, ai + width, ans, width)
used.pop()
def solve(n, a, b):
if bin(a).count('1') % 2 == bin(b).count('1') % 2:
print('NO')
return
used = []
ans = [0] * (1 << n)
split(n, a, b, used, 0, ans, 1 << n)
print('YES')
print((*ans))
n, a, b = list(map(int, input().split()))
solve(n, a, b)
| def split(n, a, b, remain, ai, ans, width):
# print(n, a, b, remain, ai, ans, width)
# print(*(f'{c:5d}' for c in ans))
# print(*(f'{c:05b}' for c in ans))
if width == 2:
ans[ai] = a
ans[ai + 1] = b
return
x = a ^ b
y = x & -x # Rightmost Bit at which is different for a and b
l = y.bit_length() - 1
remain.remove(l)
i = next(iter(remain))
lb = a ^ (1 << i)
ra = lb ^ y
width >>= 1
split(n, a, a ^ (1 << i), remain, ai, ans, width)
split(n, ra, b, remain, ai + width, ans, width)
remain.add(l)
def solve(n, a, b):
if bin(a).count('1') % 2 == bin(b).count('1') % 2:
print('NO')
return
remain = set(range(n))
ans = [0] * (1 << n)
split(n, a, b, remain, 0, ans, 1 << n)
print('YES')
print((*ans))
n, a, b = list(map(int, input().split()))
solve(n, a, b)
| 37 | 34 | 935 | 911 | def split(n, a, b, used, ai, ans, width):
# print(n, a, b, used, ai, ans, width)
# print(*(f'{c:5d}' for c in ans))
# print(*(f'{c:05b}' for c in ans))
if width == 2:
ans[ai] = a
ans[ai + 1] = b
return
x = a ^ b
y = x & -x # Rightmost Bit where is different a and b
l = y.bit_length() - 1
used.append(l)
i = 0
for i in range(n):
if i not in used:
break
la, lb = a, a ^ (1 << i)
ra, rb = lb ^ y, b
width >>= 1
split(n, la, lb, used, ai, ans, width)
split(n, ra, rb, used, ai + width, ans, width)
used.pop()
def solve(n, a, b):
if bin(a).count("1") % 2 == bin(b).count("1") % 2:
print("NO")
return
used = []
ans = [0] * (1 << n)
split(n, a, b, used, 0, ans, 1 << n)
print("YES")
print((*ans))
n, a, b = list(map(int, input().split()))
solve(n, a, b)
| def split(n, a, b, remain, ai, ans, width):
# print(n, a, b, remain, ai, ans, width)
# print(*(f'{c:5d}' for c in ans))
# print(*(f'{c:05b}' for c in ans))
if width == 2:
ans[ai] = a
ans[ai + 1] = b
return
x = a ^ b
y = x & -x # Rightmost Bit at which is different for a and b
l = y.bit_length() - 1
remain.remove(l)
i = next(iter(remain))
lb = a ^ (1 << i)
ra = lb ^ y
width >>= 1
split(n, a, a ^ (1 << i), remain, ai, ans, width)
split(n, ra, b, remain, ai + width, ans, width)
remain.add(l)
def solve(n, a, b):
if bin(a).count("1") % 2 == bin(b).count("1") % 2:
print("NO")
return
remain = set(range(n))
ans = [0] * (1 << n)
split(n, a, b, remain, 0, ans, 1 << n)
print("YES")
print((*ans))
n, a, b = list(map(int, input().split()))
solve(n, a, b)
| false | 8.108108 | [
"-def split(n, a, b, used, ai, ans, width):",
"- # print(n, a, b, used, ai, ans, width)",
"+def split(n, a, b, remain, ai, ans, width):",
"+ # print(n, a, b, remain, ai, ans, width)",
"- y = x & -x # Rightmost Bit where is different a and b",
"+ y = x & -x # Rightmost Bit at which is different for a and b",
"- used.append(l)",
"- i = 0",
"- for i in range(n):",
"- if i not in used:",
"- break",
"- la, lb = a, a ^ (1 << i)",
"- ra, rb = lb ^ y, b",
"+ remain.remove(l)",
"+ i = next(iter(remain))",
"+ lb = a ^ (1 << i)",
"+ ra = lb ^ y",
"- split(n, la, lb, used, ai, ans, width)",
"- split(n, ra, rb, used, ai + width, ans, width)",
"- used.pop()",
"+ split(n, a, a ^ (1 << i), remain, ai, ans, width)",
"+ split(n, ra, b, remain, ai + width, ans, width)",
"+ remain.add(l)",
"- used = []",
"+ remain = set(range(n))",
"- split(n, a, b, used, 0, ans, 1 << n)",
"+ split(n, a, b, remain, 0, ans, 1 << n)"
] | false | 0.14862 | 0.048454 | 3.06722 | [
"s520375017",
"s486883283"
] |
u936985471 | p02947 | python | s979621907 | s673022054 | 398 | 354 | 11,368 | 19,748 | Accepted | Accepted | 11.06 | n=int(eval(input()))
s=[None]*n
for i in range(n):
s[i]="".join(sorted(eval(input())))
s=sorted(s)
total=0
count=1
for j in range(1,n):
if s[j]==s[j-1]:
count = count+1
else:
if count>1:
total = total+(count*(count-1))//2
count=1
if count>1:
total = total+(count*(count-1))//2
print(total) | n=int(eval(input()))
s=[None]*n
for i in range(n):
s[i]="".join(sorted(eval(input())))
import collections
c=collections.Counter(s)
ans=0
for v in list(c.values()):
ans+=(v*(v-1))//2
print(ans) | 21 | 10 | 327 | 187 | n = int(eval(input()))
s = [None] * n
for i in range(n):
s[i] = "".join(sorted(eval(input())))
s = sorted(s)
total = 0
count = 1
for j in range(1, n):
if s[j] == s[j - 1]:
count = count + 1
else:
if count > 1:
total = total + (count * (count - 1)) // 2
count = 1
if count > 1:
total = total + (count * (count - 1)) // 2
print(total)
| n = int(eval(input()))
s = [None] * n
for i in range(n):
s[i] = "".join(sorted(eval(input())))
import collections
c = collections.Counter(s)
ans = 0
for v in list(c.values()):
ans += (v * (v - 1)) // 2
print(ans)
| false | 52.380952 | [
"-s = sorted(s)",
"-total = 0",
"-count = 1",
"-for j in range(1, n):",
"- if s[j] == s[j - 1]:",
"- count = count + 1",
"- else:",
"- if count > 1:",
"- total = total + (count * (count - 1)) // 2",
"- count = 1",
"-if count > 1:",
"- total = total + (count * (count - 1)) // 2",
"-print(total)",
"+import collections",
"+",
"+c = collections.Counter(s)",
"+ans = 0",
"+for v in list(c.values()):",
"+ ans += (v * (v - 1)) // 2",
"+print(ans)"
] | false | 0.03279 | 0.036574 | 0.896561 | [
"s979621907",
"s673022054"
] |
u191874006 | p03504 | python | s645510581 | s995012618 | 669 | 443 | 138,632 | 67,420 | Accepted | Accepted | 33.78 | #!/usr/bin/env python3
#ABC80 D
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
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,C = LI()
stc = [LI() for _ in range(n)]
L = []
for i in range(C):
lst = []
for j in range(n):
s,t,c = stc[j]
if i+1 == c:
lst.append([s,t])
lst.sort(key = itemgetter(0))
lst2 = []
j = 0
while j < len(lst):
if j < len(lst)-1:
if lst[j][1] == lst[j+1][0]:
lst2.append((lst[j][0],lst[j+1][1]))
j += 2
continue
lst2.append(tuple(lst[j]))
j += 1
L.append(lst2)
x = [[0]*100002 for _ in range(C)]
for i in range(C):
for j,k in L[i]:
x[i][j] += 1
x[i][k+1] -= 1
x[i] = list(accumulate(x[i]))
ans = 0
for i in range(1,10**5+1):
s = 0
for j in range(C):
if x[j][i] == 1:
s += 1
ans = max(ans,s)
print(ans)
| #!/usr/bin/env python3
#ABC80 D
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
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,C = LI()
cha = [[] for _ in range(C)]
ans = 0
lst = [0]*(10**5+2)
for _ in range(n):
s,t,c = LI()
cha[c-1].append([s,t])
for i in range(C):
if len(cha[i]) == 0:
continue
cha[i].sort(key = itemgetter(0))
s,t = cha[i][0]
tmp = []
for j in range(1,len(cha[i])):
if t == cha[i][j][0]:
t = cha[i][j][1]
else:
tmp.append([s,t])
s,t = cha[i][j]
tmp.append([s,t])
for i,j in tmp:
lst[i] += 1
lst[j+1] -= 1
lst = list(accumulate(lst))
print((max(lst)))
| 56 | 44 | 1,341 | 1,088 | #!/usr/bin/env python3
# ABC80 D
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
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, C = LI()
stc = [LI() for _ in range(n)]
L = []
for i in range(C):
lst = []
for j in range(n):
s, t, c = stc[j]
if i + 1 == c:
lst.append([s, t])
lst.sort(key=itemgetter(0))
lst2 = []
j = 0
while j < len(lst):
if j < len(lst) - 1:
if lst[j][1] == lst[j + 1][0]:
lst2.append((lst[j][0], lst[j + 1][1]))
j += 2
continue
lst2.append(tuple(lst[j]))
j += 1
L.append(lst2)
x = [[0] * 100002 for _ in range(C)]
for i in range(C):
for j, k in L[i]:
x[i][j] += 1
x[i][k + 1] -= 1
x[i] = list(accumulate(x[i]))
ans = 0
for i in range(1, 10**5 + 1):
s = 0
for j in range(C):
if x[j][i] == 1:
s += 1
ans = max(ans, s)
print(ans)
| #!/usr/bin/env python3
# ABC80 D
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
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, C = LI()
cha = [[] for _ in range(C)]
ans = 0
lst = [0] * (10**5 + 2)
for _ in range(n):
s, t, c = LI()
cha[c - 1].append([s, t])
for i in range(C):
if len(cha[i]) == 0:
continue
cha[i].sort(key=itemgetter(0))
s, t = cha[i][0]
tmp = []
for j in range(1, len(cha[i])):
if t == cha[i][j][0]:
t = cha[i][j][1]
else:
tmp.append([s, t])
s, t = cha[i][j]
tmp.append([s, t])
for i, j in tmp:
lst[i] += 1
lst[j + 1] -= 1
lst = list(accumulate(lst))
print((max(lst)))
| false | 21.428571 | [
"-stc = [LI() for _ in range(n)]",
"-L = []",
"+cha = [[] for _ in range(C)]",
"+ans = 0",
"+lst = [0] * (10**5 + 2)",
"+for _ in range(n):",
"+ s, t, c = LI()",
"+ cha[c - 1].append([s, t])",
"- lst = []",
"- for j in range(n):",
"- s, t, c = stc[j]",
"- if i + 1 == c:",
"- lst.append([s, t])",
"- lst.sort(key=itemgetter(0))",
"- lst2 = []",
"- j = 0",
"- while j < len(lst):",
"- if j < len(lst) - 1:",
"- if lst[j][1] == lst[j + 1][0]:",
"- lst2.append((lst[j][0], lst[j + 1][1]))",
"- j += 2",
"- continue",
"- lst2.append(tuple(lst[j]))",
"- j += 1",
"- L.append(lst2)",
"-x = [[0] * 100002 for _ in range(C)]",
"-for i in range(C):",
"- for j, k in L[i]:",
"- x[i][j] += 1",
"- x[i][k + 1] -= 1",
"- x[i] = list(accumulate(x[i]))",
"-ans = 0",
"-for i in range(1, 10**5 + 1):",
"- s = 0",
"- for j in range(C):",
"- if x[j][i] == 1:",
"- s += 1",
"- ans = max(ans, s)",
"-print(ans)",
"+ if len(cha[i]) == 0:",
"+ continue",
"+ cha[i].sort(key=itemgetter(0))",
"+ s, t = cha[i][0]",
"+ tmp = []",
"+ for j in range(1, len(cha[i])):",
"+ if t == cha[i][j][0]:",
"+ t = cha[i][j][1]",
"+ else:",
"+ tmp.append([s, t])",
"+ s, t = cha[i][j]",
"+ tmp.append([s, t])",
"+ for i, j in tmp:",
"+ lst[i] += 1",
"+ lst[j + 1] -= 1",
"+lst = list(accumulate(lst))",
"+print((max(lst)))"
] | false | 0.195129 | 0.145403 | 1.341988 | [
"s645510581",
"s995012618"
] |
u312025627 | p02900 | python | s163103159 | s098358732 | 388 | 80 | 40,556 | 67,556 | Accepted | Accepted | 79.38 | def main():
A, B = (int(i) for i in input().split())
def trial_division(n):
divs = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divs.append(i)
if i != n//i:
divs.append(n//i)
return set(divs)
dA = trial_division(A)
dB = trial_division(B)
C = sorted(dA & dB)
N = len(C)
seen = [True]*(N)
for i in range(1, N):
for j in range(i+1, N):
if seen[j] and C[j] % C[i] == 0:
seen[j] = False
print((seen.count(True)))
if __name__ == '__main__':
main()
| def main():
N, M = (int(i) for i in input().split())
def enum_divisors(n):
# 約数列挙
divs = set()
for i in range(1, n+1):
if i*i > n:
break
if n % i == 0:
divs.add(i)
if n//i != i:
# i が平方数でない
divs.add(n//i)
return divs
divs = enum_divisors(N) & enum_divisors(M)
ans = 1
v = 1
from math import gcd
for s in sorted(divs):
if s == 1:
continue
if gcd(v, s) == 1:
v *= s
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 25 | 31 | 638 | 684 | def main():
A, B = (int(i) for i in input().split())
def trial_division(n):
divs = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divs.append(i)
if i != n // i:
divs.append(n // i)
return set(divs)
dA = trial_division(A)
dB = trial_division(B)
C = sorted(dA & dB)
N = len(C)
seen = [True] * (N)
for i in range(1, N):
for j in range(i + 1, N):
if seen[j] and C[j] % C[i] == 0:
seen[j] = False
print((seen.count(True)))
if __name__ == "__main__":
main()
| def main():
N, M = (int(i) for i in input().split())
def enum_divisors(n):
# 約数列挙
divs = set()
for i in range(1, n + 1):
if i * i > n:
break
if n % i == 0:
divs.add(i)
if n // i != i:
# i が平方数でない
divs.add(n // i)
return divs
divs = enum_divisors(N) & enum_divisors(M)
ans = 1
v = 1
from math import gcd
for s in sorted(divs):
if s == 1:
continue
if gcd(v, s) == 1:
v *= s
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 19.354839 | [
"- A, B = (int(i) for i in input().split())",
"+ N, M = (int(i) for i in input().split())",
"- def trial_division(n):",
"- divs = []",
"- for i in range(1, int(n**0.5) + 1):",
"+ def enum_divisors(n):",
"+ # 約数列挙",
"+ divs = set()",
"+ for i in range(1, n + 1):",
"+ if i * i > n:",
"+ break",
"- divs.append(i)",
"- if i != n // i:",
"- divs.append(n // i)",
"- return set(divs)",
"+ divs.add(i)",
"+ if n // i != i:",
"+ # i が平方数でない",
"+ divs.add(n // i)",
"+ return divs",
"- dA = trial_division(A)",
"- dB = trial_division(B)",
"- C = sorted(dA & dB)",
"- N = len(C)",
"- seen = [True] * (N)",
"- for i in range(1, N):",
"- for j in range(i + 1, N):",
"- if seen[j] and C[j] % C[i] == 0:",
"- seen[j] = False",
"- print((seen.count(True)))",
"+ divs = enum_divisors(N) & enum_divisors(M)",
"+ ans = 1",
"+ v = 1",
"+ from math import gcd",
"+",
"+ for s in sorted(divs):",
"+ if s == 1:",
"+ continue",
"+ if gcd(v, s) == 1:",
"+ v *= s",
"+ ans += 1",
"+ print(ans)"
] | false | 0.03895 | 0.038395 | 1.014465 | [
"s163103159",
"s098358732"
] |
u192154323 | p03329 | python | s764451181 | s320262104 | 216 | 103 | 46,032 | 74,828 | Accepted | Accepted | 52.31 | import math
n = int(eval(input()))
target_ls = [1]
target_6 = 6
while target_6 <= n:
target_ls.append(target_6)
target_6 *= 6
target_9 = 9
while target_9 <= n:
target_ls.append(target_9)
target_9 *= 9
dp = [float('inf')] * (n+1)
dp[0] = 0
for i in range(n):
for j in target_ls:
if i+j <= n:
dp[i+j] = min(dp[i+j],dp[i] + 1)
print((dp[n]))
| n = int(eval(input()))
min_time = [float('inf')] * (n+1)
min_time[0] = 0
for i in range(n):
min_time[i+1] = min(min_time[i+1],min_time[i]+1)
times_6 = 1
while i+6**times_6<=n:
min_time[i+6**times_6] = min(min_time[i+6**times_6],min_time[i]+1)
times_6 += 1
times_9 = 1
while i+9**times_9<=n:
min_time[i+9**times_9] = min(min_time[i+9**times_9],min_time[i]+1)
times_9 += 1
print((min_time[-1]))
| 21 | 18 | 397 | 458 | import math
n = int(eval(input()))
target_ls = [1]
target_6 = 6
while target_6 <= n:
target_ls.append(target_6)
target_6 *= 6
target_9 = 9
while target_9 <= n:
target_ls.append(target_9)
target_9 *= 9
dp = [float("inf")] * (n + 1)
dp[0] = 0
for i in range(n):
for j in target_ls:
if i + j <= n:
dp[i + j] = min(dp[i + j], dp[i] + 1)
print((dp[n]))
| n = int(eval(input()))
min_time = [float("inf")] * (n + 1)
min_time[0] = 0
for i in range(n):
min_time[i + 1] = min(min_time[i + 1], min_time[i] + 1)
times_6 = 1
while i + 6**times_6 <= n:
min_time[i + 6**times_6] = min(min_time[i + 6**times_6], min_time[i] + 1)
times_6 += 1
times_9 = 1
while i + 9**times_9 <= n:
min_time[i + 9**times_9] = min(min_time[i + 9**times_9], min_time[i] + 1)
times_9 += 1
print((min_time[-1]))
| false | 14.285714 | [
"-import math",
"-",
"-target_ls = [1]",
"-target_6 = 6",
"-while target_6 <= n:",
"- target_ls.append(target_6)",
"- target_6 *= 6",
"-target_9 = 9",
"-while target_9 <= n:",
"- target_ls.append(target_9)",
"- target_9 *= 9",
"-dp = [float(\"inf\")] * (n + 1)",
"-dp[0] = 0",
"+min_time = [float(\"inf\")] * (n + 1)",
"+min_time[0] = 0",
"- for j in target_ls:",
"- if i + j <= n:",
"- dp[i + j] = min(dp[i + j], dp[i] + 1)",
"-print((dp[n]))",
"+ min_time[i + 1] = min(min_time[i + 1], min_time[i] + 1)",
"+ times_6 = 1",
"+ while i + 6**times_6 <= n:",
"+ min_time[i + 6**times_6] = min(min_time[i + 6**times_6], min_time[i] + 1)",
"+ times_6 += 1",
"+ times_9 = 1",
"+ while i + 9**times_9 <= n:",
"+ min_time[i + 9**times_9] = min(min_time[i + 9**times_9], min_time[i] + 1)",
"+ times_9 += 1",
"+print((min_time[-1]))"
] | false | 0.098318 | 0.211441 | 0.464989 | [
"s764451181",
"s320262104"
] |
u058433718 | p02392 | python | s904566845 | s043296013 | 30 | 20 | 7,616 | 5,600 | Accepted | Accepted | 33.33 | import sys
data = sys.stdin.readline().strip()
a, b, c = data.split(' ')
a = int(a)
b = int(b)
c = int(c)
if a < b and b < c:
print('Yes')
else:
print('No') | data = eval(input())
a, b, c = [int(i) for i in data.split()]
if a < b < c:
print('Yes')
else:
print('No') | 12 | 7 | 177 | 115 | import sys
data = sys.stdin.readline().strip()
a, b, c = data.split(" ")
a = int(a)
b = int(b)
c = int(c)
if a < b and b < c:
print("Yes")
else:
print("No")
| data = eval(input())
a, b, c = [int(i) for i in data.split()]
if a < b < c:
print("Yes")
else:
print("No")
| false | 41.666667 | [
"-import sys",
"-",
"-data = sys.stdin.readline().strip()",
"-a, b, c = data.split(\" \")",
"-a = int(a)",
"-b = int(b)",
"-c = int(c)",
"-if a < b and b < c:",
"+data = eval(input())",
"+a, b, c = [int(i) for i in data.split()]",
"+if a < b < c:"
] | false | 0.057317 | 0.04333 | 1.322822 | [
"s904566845",
"s043296013"
] |
u079022693 | p02693 | python | s492824866 | s925617491 | 22 | 20 | 9,140 | 9,132 | Accepted | Accepted | 9.09 | from sys import stdin
def main():
#入力
readline=stdin.readline
K=int(readline())
A,B=list(map(int,readline().split()))
if A%K==0:
print("OK")
elif A//K<B//K:
print("OK")
else:
print("NG")
if __name__=="__main__":
main() | k=int(input())
a,b=map(int,input().split())
print("OK") if a<=b//k*k else print("NG")
| 14 | 3 | 281 | 87 | from sys import stdin
def main():
# 入力
readline = stdin.readline
K = int(readline())
A, B = list(map(int, readline().split()))
if A % K == 0:
print("OK")
elif A // K < B // K:
print("OK")
else:
print("NG")
if __name__ == "__main__":
main()
| k = int(input())
a, b = map(int, input().split())
print("OK") if a <= b // k * k else print("NG")
| false | 78.571429 | [
"-from sys import stdin",
"-",
"-",
"-def main():",
"- # 入力",
"- readline = stdin.readline",
"- K = int(readline())",
"- A, B = list(map(int, readline().split()))",
"- if A % K == 0:",
"- print(\"OK\")",
"- elif A // K < B // K:",
"- print(\"OK\")",
"- else:",
"- print(\"NG\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+k = int(input())",
"+a, b = map(int, input().split())",
"+print(\"OK\") if a <= b // k * k else print(\"NG\")"
] | false | 0.041389 | 0.046903 | 0.882449 | [
"s492824866",
"s925617491"
] |
u189479417 | p03680 | python | s707940117 | s899245492 | 225 | 159 | 13,216 | 12,996 | Accepted | Accepted | 29.33 | N = int(eval(input()))
A = [0]
for _ in range(N):
A.append(int(eval(input())))
S = set()
i = 1
cnt = 0
while i != 2 and not i in S:
S.add(i)
i = A[i]
cnt += 1
if i == 2:
print(cnt)
else:
print((-1)) | import sys
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
x = 0
cnt = 0
for _ in range(N):
x = A[x] - 1
cnt += 1
if x == 1:
print(cnt)
sys.exit()
print((-1)) | 15 | 12 | 222 | 201 | N = int(eval(input()))
A = [0]
for _ in range(N):
A.append(int(eval(input())))
S = set()
i = 1
cnt = 0
while i != 2 and not i in S:
S.add(i)
i = A[i]
cnt += 1
if i == 2:
print(cnt)
else:
print((-1))
| import sys
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
x = 0
cnt = 0
for _ in range(N):
x = A[x] - 1
cnt += 1
if x == 1:
print(cnt)
sys.exit()
print((-1))
| false | 20 | [
"+import sys",
"+",
"-A = [0]",
"+A = [int(eval(input())) for _ in range(N)]",
"+x = 0",
"+cnt = 0",
"- A.append(int(eval(input())))",
"-S = set()",
"-i = 1",
"-cnt = 0",
"-while i != 2 and not i in S:",
"- S.add(i)",
"- i = A[i]",
"+ x = A[x] - 1",
"-if i == 2:",
"- print(cnt)",
"-else:",
"- print((-1))",
"+ if x == 1:",
"+ print(cnt)",
"+ sys.exit()",
"+print((-1))"
] | false | 0.035514 | 0.053911 | 0.658754 | [
"s707940117",
"s899245492"
] |
u198440493 | p03128 | python | s236677705 | s856220290 | 154 | 39 | 14,516 | 14,452 | Accepted | Accepted | 74.68 | INF = float('inf')
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x-1]] for x in a]
l = sorted(l, key = lambda x: x[1]*10-x[0])
r = l[0]
_max = [0] + [-INF]*n
for i in range(1, n+1):
for x in l:
ind = i-x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind]*10 + x[0])
ans = str(_max[n])
print(ans) | INF = float('inf')
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x-1]] for x in a]
l = sorted(l, key = lambda x: x[1]*10-x[0])
r = l[0]
_max = [0] + [-INF]*n
for i in range(1, n+1):
if 42 < i < n-42:
_max[i] = max(_max[i], _max[i-r[1]]*10 + r[0])
else:
for x in l:
ind = i-x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind]*10 + x[0])
ans = str(_max[n])
print(ans) | 15 | 18 | 395 | 485 | INF = float("inf")
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x - 1]] for x in a]
l = sorted(l, key=lambda x: x[1] * 10 - x[0])
r = l[0]
_max = [0] + [-INF] * n
for i in range(1, n + 1):
for x in l:
ind = i - x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind] * 10 + x[0])
ans = str(_max[n])
print(ans)
| INF = float("inf")
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x - 1]] for x in a]
l = sorted(l, key=lambda x: x[1] * 10 - x[0])
r = l[0]
_max = [0] + [-INF] * n
for i in range(1, n + 1):
if 42 < i < n - 42:
_max[i] = max(_max[i], _max[i - r[1]] * 10 + r[0])
else:
for x in l:
ind = i - x[1]
if ind >= 0:
_max[i] = max(_max[i], _max[ind] * 10 + x[0])
ans = str(_max[n])
print(ans)
| false | 16.666667 | [
"- for x in l:",
"- ind = i - x[1]",
"- if ind >= 0:",
"- _max[i] = max(_max[i], _max[ind] * 10 + x[0])",
"+ if 42 < i < n - 42:",
"+ _max[i] = max(_max[i], _max[i - r[1]] * 10 + r[0])",
"+ else:",
"+ for x in l:",
"+ ind = i - x[1]",
"+ if ind >= 0:",
"+ _max[i] = max(_max[i], _max[ind] * 10 + x[0])"
] | false | 0.039087 | 0.039492 | 0.989747 | [
"s236677705",
"s856220290"
] |
u223133214 | p02725 | python | s354085702 | s492396176 | 282 | 257 | 78,668 | 86,140 | Accepted | Accepted | 8.87 | k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
big = 0
for i in range(n - 1):
big = max(big, abs(A[i + 1] - A[i]))
b = (k - A[-1]) + A[0]
big = max(big, b)
print((k - big))
| k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
kyori = []
for i in range(n - 1):
kyori.append(abs(A[i] - A[i + 1]))
kyori.append(A[0] + (k-A[-1]))
ans = k - max(kyori)
print(ans) | 12 | 11 | 212 | 217 | k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
big = 0
for i in range(n - 1):
big = max(big, abs(A[i + 1] - A[i]))
b = (k - A[-1]) + A[0]
big = max(big, b)
print((k - big))
| k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
kyori = []
for i in range(n - 1):
kyori.append(abs(A[i] - A[i + 1]))
kyori.append(A[0] + (k - A[-1]))
ans = k - max(kyori)
print(ans)
| false | 8.333333 | [
"-big = 0",
"+kyori = []",
"- big = max(big, abs(A[i + 1] - A[i]))",
"-b = (k - A[-1]) + A[0]",
"-big = max(big, b)",
"-print((k - big))",
"+ kyori.append(abs(A[i] - A[i + 1]))",
"+kyori.append(A[0] + (k - A[-1]))",
"+ans = k - max(kyori)",
"+print(ans)"
] | false | 0.043525 | 0.105829 | 0.411278 | [
"s354085702",
"s492396176"
] |
u957843607 | p02837 | python | s580859994 | s119588864 | 1,549 | 716 | 3,064 | 8,976 | Accepted | Accepted | 53.78 | N = int(eval(input()))
a = [[] for _ in range(N)]
for i in range(N):
A_i = int(eval(input()))
for j in range(A_i):
a[i].append(list(map(int, input().split())))
max_honest = 0
for i in range(2**N):
contradiction = False
honest_p = []
unkind_p = []
doubt_honest_p = []
doubt_unkind_p = []
length = len(format(2**N-1, "b"))
bin_num = format(i, "b").zfill(length)
for j in range(length):
if (i >> j) & 1:
if not j+1 in honest_p:
honest_p.append(j+1)
if not j+1 in doubt_honest_p:
doubt_honest_p.append(j+1)
for k in a[j]:
p = k[0]
t = k[1]
if t:
if not p in honest_p:
honest_p.append(p)
else:
if not p in unkind_p:
unkind_p.append(p)
else:
if not j+1 in unkind_p:
unkind_p.append(j+1)
if not j+1 in doubt_unkind_p:
doubt_unkind_p.append(j+1)
if len(list(set(honest_p) & set(unkind_p))) != 0:
contradiction = True
if not contradiction and max_honest <= len(doubt_honest_p):
max_honest = len(doubt_honest_p)
print(max_honest) | N = int(eval(input()))
a = [[] for _ in range(N)]
for i in range(N):
A_i = int(eval(input()))
for j in range(A_i):
a[i].append(list(map(int, input().split())))
max_person = 0
for i in range(2**N):
judge = True
bin_num = bin(i)
times = 0
end = False
for j in reversed(bin_num):
if j == "b":
break
if j == "1":
for k in a[times]:
if ((i >> k[0]-1) & 1) != k[1]:
judge = False
times += 1
true_person = bin_num.count("1")
if judge == True:
max_person = max(max_person, true_person)
print(max_person) | 42 | 25 | 1,133 | 576 | N = int(eval(input()))
a = [[] for _ in range(N)]
for i in range(N):
A_i = int(eval(input()))
for j in range(A_i):
a[i].append(list(map(int, input().split())))
max_honest = 0
for i in range(2**N):
contradiction = False
honest_p = []
unkind_p = []
doubt_honest_p = []
doubt_unkind_p = []
length = len(format(2**N - 1, "b"))
bin_num = format(i, "b").zfill(length)
for j in range(length):
if (i >> j) & 1:
if not j + 1 in honest_p:
honest_p.append(j + 1)
if not j + 1 in doubt_honest_p:
doubt_honest_p.append(j + 1)
for k in a[j]:
p = k[0]
t = k[1]
if t:
if not p in honest_p:
honest_p.append(p)
else:
if not p in unkind_p:
unkind_p.append(p)
else:
if not j + 1 in unkind_p:
unkind_p.append(j + 1)
if not j + 1 in doubt_unkind_p:
doubt_unkind_p.append(j + 1)
if len(list(set(honest_p) & set(unkind_p))) != 0:
contradiction = True
if not contradiction and max_honest <= len(doubt_honest_p):
max_honest = len(doubt_honest_p)
print(max_honest)
| N = int(eval(input()))
a = [[] for _ in range(N)]
for i in range(N):
A_i = int(eval(input()))
for j in range(A_i):
a[i].append(list(map(int, input().split())))
max_person = 0
for i in range(2**N):
judge = True
bin_num = bin(i)
times = 0
end = False
for j in reversed(bin_num):
if j == "b":
break
if j == "1":
for k in a[times]:
if ((i >> k[0] - 1) & 1) != k[1]:
judge = False
times += 1
true_person = bin_num.count("1")
if judge == True:
max_person = max(max_person, true_person)
print(max_person)
| false | 40.47619 | [
"-max_honest = 0",
"+max_person = 0",
"- contradiction = False",
"- honest_p = []",
"- unkind_p = []",
"- doubt_honest_p = []",
"- doubt_unkind_p = []",
"- length = len(format(2**N - 1, \"b\"))",
"- bin_num = format(i, \"b\").zfill(length)",
"- for j in range(length):",
"- if (i >> j) & 1:",
"- if not j + 1 in honest_p:",
"- honest_p.append(j + 1)",
"- if not j + 1 in doubt_honest_p:",
"- doubt_honest_p.append(j + 1)",
"- for k in a[j]:",
"- p = k[0]",
"- t = k[1]",
"- if t:",
"- if not p in honest_p:",
"- honest_p.append(p)",
"- else:",
"- if not p in unkind_p:",
"- unkind_p.append(p)",
"- else:",
"- if not j + 1 in unkind_p:",
"- unkind_p.append(j + 1)",
"- if not j + 1 in doubt_unkind_p:",
"- doubt_unkind_p.append(j + 1)",
"- if len(list(set(honest_p) & set(unkind_p))) != 0:",
"- contradiction = True",
"- if not contradiction and max_honest <= len(doubt_honest_p):",
"- max_honest = len(doubt_honest_p)",
"-print(max_honest)",
"+ judge = True",
"+ bin_num = bin(i)",
"+ times = 0",
"+ end = False",
"+ for j in reversed(bin_num):",
"+ if j == \"b\":",
"+ break",
"+ if j == \"1\":",
"+ for k in a[times]:",
"+ if ((i >> k[0] - 1) & 1) != k[1]:",
"+ judge = False",
"+ times += 1",
"+ true_person = bin_num.count(\"1\")",
"+ if judge == True:",
"+ max_person = max(max_person, true_person)",
"+print(max_person)"
] | false | 0.008253 | 0.041539 | 0.198672 | [
"s580859994",
"s119588864"
] |
u761529120 | p02845 | python | s446425036 | s379027099 | 216 | 94 | 52,696 | 84,760 | Accepted | Accepted | 56.48 | def main():
MOD = 10 ** 9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
d = [0] * (max(A) + 1)
for a in A:
if a == 0:
ans *= 3 - d[a]
ans %= MOD
d[a] += 1
else:
ans *= d[a-1] - d[a]
d[a] += 1
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 1
cnt = [0] * (N + 1)
for i in range(N):
if A[i] == 0:
ans *= 3 - cnt[A[i]]
cnt[A[i]] += 1
else:
ans *= cnt[A[i]-1] - cnt[A[i]]
cnt[A[i]] += 1
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 22 | 23 | 411 | 423 | def main():
MOD = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
d = [0] * (max(A) + 1)
for a in A:
if a == 0:
ans *= 3 - d[a]
ans %= MOD
d[a] += 1
else:
ans *= d[a - 1] - d[a]
d[a] += 1
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 1
cnt = [0] * (N + 1)
for i in range(N):
if A[i] == 0:
ans *= 3 - cnt[A[i]]
cnt[A[i]] += 1
else:
ans *= cnt[A[i] - 1] - cnt[A[i]]
cnt[A[i]] += 1
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| false | 4.347826 | [
"- MOD = 10**9 + 7",
"+ MOD = 10**9 + 7",
"- d = [0] * (max(A) + 1)",
"- for a in A:",
"- if a == 0:",
"- ans *= 3 - d[a]",
"- ans %= MOD",
"- d[a] += 1",
"+ cnt = [0] * (N + 1)",
"+ for i in range(N):",
"+ if A[i] == 0:",
"+ ans *= 3 - cnt[A[i]]",
"+ cnt[A[i]] += 1",
"- ans *= d[a - 1] - d[a]",
"- d[a] += 1",
"- ans %= MOD",
"+ ans *= cnt[A[i] - 1] - cnt[A[i]]",
"+ cnt[A[i]] += 1",
"+ ans %= MOD"
] | false | 0.043219 | 0.082884 | 0.52144 | [
"s446425036",
"s379027099"
] |
u197955752 | p02744 | python | s199345990 | s122761268 | 191 | 174 | 22,772 | 19,188 | Accepted | Accepted | 8.9 | from collections import deque
N = int(eval(input()))
alphabet = "abcdefghij"
visited = 1
st = deque([["a", visited]])
while len(st) > 0:
str, visited = st.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in alphabet[0 : visited]:
st.append([str + x, visited])
# まだ使っていない文字を使う
# len(str) < Nだから、visited < N
st.append([str + alphabet[visited], visited + 1])
| from collections import deque
N = int(eval(input()))
alphabet = "abcdefghij"
visited = 1
st = deque([("a", visited)])
while len(st) > 0:
str, visited = st.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in alphabet[0 : visited]:
st.append((str + x, visited))
# まだ使っていない文字を使う
# len(str) < Nだから、visited < N
st.append((str + alphabet[visited], visited + 1)) | 19 | 19 | 459 | 458 | from collections import deque
N = int(eval(input()))
alphabet = "abcdefghij"
visited = 1
st = deque([["a", visited]])
while len(st) > 0:
str, visited = st.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in alphabet[0:visited]:
st.append([str + x, visited])
# まだ使っていない文字を使う
# len(str) < Nだから、visited < N
st.append([str + alphabet[visited], visited + 1])
| from collections import deque
N = int(eval(input()))
alphabet = "abcdefghij"
visited = 1
st = deque([("a", visited)])
while len(st) > 0:
str, visited = st.popleft()
if len(str) == N:
print(str)
else:
# すでに使った文字を使う
for x in alphabet[0:visited]:
st.append((str + x, visited))
# まだ使っていない文字を使う
# len(str) < Nだから、visited < N
st.append((str + alphabet[visited], visited + 1))
| false | 0 | [
"-st = deque([[\"a\", visited]])",
"+st = deque([(\"a\", visited)])",
"- st.append([str + x, visited])",
"+ st.append((str + x, visited))",
"- st.append([str + alphabet[visited], visited + 1])",
"+ st.append((str + alphabet[visited], visited + 1))"
] | false | 0.044733 | 0.042734 | 1.046761 | [
"s199345990",
"s122761268"
] |
u906501980 | p02901 | python | s003161438 | s391778468 | 1,404 | 1,288 | 3,300 | 3,188 | Accepted | Accepted | 8.26 | n, m = list(map(int, input().split()))
ac = []
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2**(int(i)-1) for i in input().split()])
ac.append([a, c])
dp = [float('inf')] * 2**n
dp[0] = 0
for s in range(2**n):
for a, c in ac:
t = s|c
if dp[t] > dp[s] + a:
dp[t] = dp[s] + a
ans = dp[-1]
if ans == float('inf'):
ans = -1
print(ans) | n, m = list(map(int, input().split()))
dp = [float('inf')] * 2**n
dp[0] = 0
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2**(int(i)-1) for i in input().split()])
for s in range(2**n):
t = s|c
if dp[t] > dp[s] + a:
dp[t] = dp[s] + a
ans = dp[-1]
if ans == float('inf'):
ans = -1
print(ans) | 17 | 14 | 404 | 367 | n, m = list(map(int, input().split()))
ac = []
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2 ** (int(i) - 1) for i in input().split()])
ac.append([a, c])
dp = [float("inf")] * 2**n
dp[0] = 0
for s in range(2**n):
for a, c in ac:
t = s | c
if dp[t] > dp[s] + a:
dp[t] = dp[s] + a
ans = dp[-1]
if ans == float("inf"):
ans = -1
print(ans)
| n, m = list(map(int, input().split()))
dp = [float("inf")] * 2**n
dp[0] = 0
for _ in range(m):
a, _ = list(map(int, input().split()))
c = sum([2 ** (int(i) - 1) for i in input().split()])
for s in range(2**n):
t = s | c
if dp[t] > dp[s] + a:
dp[t] = dp[s] + a
ans = dp[-1]
if ans == float("inf"):
ans = -1
print(ans)
| false | 17.647059 | [
"-ac = []",
"+dp = [float(\"inf\")] * 2**n",
"+dp[0] = 0",
"- ac.append([a, c])",
"-dp = [float(\"inf\")] * 2**n",
"-dp[0] = 0",
"-for s in range(2**n):",
"- for a, c in ac:",
"+ for s in range(2**n):"
] | false | 0.040894 | 0.123025 | 0.332406 | [
"s003161438",
"s391778468"
] |
u562935282 | p02716 | python | s567606893 | s085207986 | 670 | 501 | 144,528 | 201,596 | Accepted | Accepted | 25.22 | def main():
from collections import defaultdict
inf = 10 ** 15
N = int(eval(input()))
*a, = list(map(int, input().split()))
it = iter(a)
dp = [defaultdict(lambda: -inf) for _ in range(N + 1)]
dp[0][0] = 0
dp[1][0] = 0
dp[1][1] = next(it)
for i, x in enumerate(it, 2):
mi = (i - 1) // 2
ma = (i + 1) // 2
for taken_count in range(mi, ma + 1):
dp[i][taken_count] = max(
dp[i - 1][taken_count],
dp[i - 2][taken_count - 1] + x
)
ans = dp[N][N // 2]
print(ans)
if __name__ == '__main__':
main()
| def main():
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)
inf = 2 * 10 ** 14 + 1
N = int(eval(input()))
*a, = list(map(int, input().split()))
@lru_cache(maxsize=None)
def recursion(cur, need):
"""
cur: pickableなindex
"""
if cur >= N:
if need == 0:
return 0
else:
return -inf
rest = N - cur
if (rest + 1) // 2 < need:
return -inf
return max(
a[cur] + recursion(cur + 2, need - 1),
recursion(cur + 1, need)
)
ans = recursion(0, N // 2)
print(ans)
if __name__ == '__main__':
main()
| 30 | 38 | 647 | 742 | def main():
from collections import defaultdict
inf = 10**15
N = int(eval(input()))
(*a,) = list(map(int, input().split()))
it = iter(a)
dp = [defaultdict(lambda: -inf) for _ in range(N + 1)]
dp[0][0] = 0
dp[1][0] = 0
dp[1][1] = next(it)
for i, x in enumerate(it, 2):
mi = (i - 1) // 2
ma = (i + 1) // 2
for taken_count in range(mi, ma + 1):
dp[i][taken_count] = max(
dp[i - 1][taken_count], dp[i - 2][taken_count - 1] + x
)
ans = dp[N][N // 2]
print(ans)
if __name__ == "__main__":
main()
| def main():
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)
inf = 2 * 10**14 + 1
N = int(eval(input()))
(*a,) = list(map(int, input().split()))
@lru_cache(maxsize=None)
def recursion(cur, need):
"""
cur: pickableなindex
"""
if cur >= N:
if need == 0:
return 0
else:
return -inf
rest = N - cur
if (rest + 1) // 2 < need:
return -inf
return max(a[cur] + recursion(cur + 2, need - 1), recursion(cur + 1, need))
ans = recursion(0, N // 2)
print(ans)
if __name__ == "__main__":
main()
| false | 21.052632 | [
"- from collections import defaultdict",
"+ from functools import lru_cache",
"+ import sys",
"- inf = 10**15",
"+ sys.setrecursionlimit(10**7)",
"+ inf = 2 * 10**14 + 1",
"- it = iter(a)",
"- dp = [defaultdict(lambda: -inf) for _ in range(N + 1)]",
"- dp[0][0] = 0",
"- dp[1][0] = 0",
"- dp[1][1] = next(it)",
"- for i, x in enumerate(it, 2):",
"- mi = (i - 1) // 2",
"- ma = (i + 1) // 2",
"- for taken_count in range(mi, ma + 1):",
"- dp[i][taken_count] = max(",
"- dp[i - 1][taken_count], dp[i - 2][taken_count - 1] + x",
"- )",
"- ans = dp[N][N // 2]",
"+",
"+ @lru_cache(maxsize=None)",
"+ def recursion(cur, need):",
"+ \"\"\"",
"+ cur: pickableなindex",
"+ \"\"\"",
"+ if cur >= N:",
"+ if need == 0:",
"+ return 0",
"+ else:",
"+ return -inf",
"+ rest = N - cur",
"+ if (rest + 1) // 2 < need:",
"+ return -inf",
"+ return max(a[cur] + recursion(cur + 2, need - 1), recursion(cur + 1, need))",
"+",
"+ ans = recursion(0, N // 2)"
] | false | 0.048357 | 0.039481 | 1.224807 | [
"s567606893",
"s085207986"
] |
u633068244 | p00174 | python | s868599118 | s953819373 | 20 | 10 | 4,196 | 4,196 | Accepted | Accepted | 50 | import sys
while True:
for i in range(3):
game = input()
if game == "0":sys.exit()
game = game[1:]+game[-1]
print(game.count("A"),game.count("B")) | import sys
while 1:
for i in range(3):
g=input()
if g=="0":sys.exit()
g=g[1:]+g[-1]
print(g.count("A"),g.count("B")) | 7 | 7 | 164 | 134 | import sys
while True:
for i in range(3):
game = input()
if game == "0":
sys.exit()
game = game[1:] + game[-1]
print(game.count("A"), game.count("B"))
| import sys
while 1:
for i in range(3):
g = input()
if g == "0":
sys.exit()
g = g[1:] + g[-1]
print(g.count("A"), g.count("B"))
| false | 0 | [
"-while True:",
"+while 1:",
"- game = input()",
"- if game == \"0\":",
"+ g = input()",
"+ if g == \"0\":",
"- game = game[1:] + game[-1]",
"- print(game.count(\"A\"), game.count(\"B\"))",
"+ g = g[1:] + g[-1]",
"+ print(g.count(\"A\"), g.count(\"B\"))"
] | false | 0.040723 | 0.069101 | 0.589325 | [
"s868599118",
"s953819373"
] |
u476604182 | p03550 | python | s066431331 | s958447935 | 188 | 18 | 39,408 | 3,188 | Accepted | Accepted | 90.43 | N, Z, W = list(map(int, input().split()))
a = [int(i) for i in input().split()]
if N==1:
print((abs(a[0]-W)))
else:
print((max(abs(a[-1]-W), abs(a[-1]-a[-2])))) | N, Z, W, *A = list(map(int, open(0).read().split()))
if N==1:
print((abs(A[0]-W)))
else:
print((max(abs(A[-1]-A[-2]),abs(A[-1]-W)))) | 6 | 5 | 160 | 130 | N, Z, W = list(map(int, input().split()))
a = [int(i) for i in input().split()]
if N == 1:
print((abs(a[0] - W)))
else:
print((max(abs(a[-1] - W), abs(a[-1] - a[-2]))))
| N, Z, W, *A = list(map(int, open(0).read().split()))
if N == 1:
print((abs(A[0] - W)))
else:
print((max(abs(A[-1] - A[-2]), abs(A[-1] - W))))
| false | 16.666667 | [
"-N, Z, W = list(map(int, input().split()))",
"-a = [int(i) for i in input().split()]",
"+N, Z, W, *A = list(map(int, open(0).read().split()))",
"- print((abs(a[0] - W)))",
"+ print((abs(A[0] - W)))",
"- print((max(abs(a[-1] - W), abs(a[-1] - a[-2]))))",
"+ print((max(abs(A[-1] - A[-2]), abs(A[-1] - W))))"
] | false | 0.047308 | 0.047708 | 0.991617 | [
"s066431331",
"s958447935"
] |
u932465688 | p03724 | python | s097847733 | s168617519 | 454 | 340 | 28,132 | 3,828 | Accepted | Accepted | 25.11 | N,M = list(map(int,input().split()))
L = []
for i in range(M):
L.append(list(map(int,input().split())))
K = [0]*(10**5)
for i in range(M):
for j in range(2):
K[L[i][j]-1] += 1
flag = True
for i in range(10**5):
if K[i]%2 != 0:
flag = False
break
if flag:
print('YES')
else:
print('NO') | N,M = list(map(int,input().split()))
K = [0]*(10**5)
for i in range(M):
P,Q = list(map(int,input().split()))
K[P-1] += 1
K[Q-1] += 1
flag = True
for i in range(10**5):
if K[i]%2 != 0:
flag = False
break
if flag:
print('YES')
else:
print('NO') | 17 | 15 | 317 | 264 | N, M = list(map(int, input().split()))
L = []
for i in range(M):
L.append(list(map(int, input().split())))
K = [0] * (10**5)
for i in range(M):
for j in range(2):
K[L[i][j] - 1] += 1
flag = True
for i in range(10**5):
if K[i] % 2 != 0:
flag = False
break
if flag:
print("YES")
else:
print("NO")
| N, M = list(map(int, input().split()))
K = [0] * (10**5)
for i in range(M):
P, Q = list(map(int, input().split()))
K[P - 1] += 1
K[Q - 1] += 1
flag = True
for i in range(10**5):
if K[i] % 2 != 0:
flag = False
break
if flag:
print("YES")
else:
print("NO")
| false | 11.764706 | [
"-L = []",
"-for i in range(M):",
"- L.append(list(map(int, input().split())))",
"- for j in range(2):",
"- K[L[i][j] - 1] += 1",
"+ P, Q = list(map(int, input().split()))",
"+ K[P - 1] += 1",
"+ K[Q - 1] += 1"
] | false | 0.093775 | 0.008054 | 11.642977 | [
"s097847733",
"s168617519"
] |
u133936772 | p02574 | python | s209102315 | s833363870 | 661 | 350 | 121,456 | 189,160 | Accepted | Accepted | 47.05 | M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n,*l=map(int,open(0).read().split())
from math import *
g,C=0,[0]*M
for x in l:
g=gcd(g,x)
C[x]=1
if g>1: f(2)
if any(sum(C[i::i])>1 for i in range(2,M)): f(1)
f(0)
| M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n=int(input())
l=[*map(int,input().split())]
g=0
from math import *
for x in l:
g=gcd(g,x)
if g>1: f(2)
def sieve(x):
p=[]
s=[0]*x
for i in range(2,x):
if s[i]<1:
p+=[i]
for j in range(i,x,i): s[j]=i
return s
s=sieve(M)
C=[0]*M
for x in l:
t=set()
while x>1:
t.add(s[x])
x//=s[x]
for y in t:
if C[y]: f(1)
C[y]=1
f(0)
| 11 | 28 | 256 | 470 | M = 10**6 + 1
f = lambda p: exit(print(["pairwise", "setwise", "not"][p] + " coprime"))
n, *l = map(int, open(0).read().split())
from math import *
g, C = 0, [0] * M
for x in l:
g = gcd(g, x)
C[x] = 1
if g > 1:
f(2)
if any(sum(C[i::i]) > 1 for i in range(2, M)):
f(1)
f(0)
| M = 10**6 + 1
f = lambda p: exit(print(["pairwise", "setwise", "not"][p] + " coprime"))
n = int(input())
l = [*map(int, input().split())]
g = 0
from math import *
for x in l:
g = gcd(g, x)
if g > 1:
f(2)
def sieve(x):
p = []
s = [0] * x
for i in range(2, x):
if s[i] < 1:
p += [i]
for j in range(i, x, i):
s[j] = i
return s
s = sieve(M)
C = [0] * M
for x in l:
t = set()
while x > 1:
t.add(s[x])
x //= s[x]
for y in t:
if C[y]:
f(1)
C[y] = 1
f(0)
| false | 60.714286 | [
"-n, *l = map(int, open(0).read().split())",
"+n = int(input())",
"+l = [*map(int, input().split())]",
"+g = 0",
"-g, C = 0, [0] * M",
"- C[x] = 1",
"-if any(sum(C[i::i]) > 1 for i in range(2, M)):",
"- f(1)",
"+",
"+",
"+def sieve(x):",
"+ p = []",
"+ s = [0] * x",
"+ for i in range(2, x):",
"+ if s[i] < 1:",
"+ p += [i]",
"+ for j in range(i, x, i):",
"+ s[j] = i",
"+ return s",
"+",
"+",
"+s = sieve(M)",
"+C = [0] * M",
"+for x in l:",
"+ t = set()",
"+ while x > 1:",
"+ t.add(s[x])",
"+ x //= s[x]",
"+ for y in t:",
"+ if C[y]:",
"+ f(1)",
"+ C[y] = 1"
] | false | 1.283329 | 0.931198 | 1.378148 | [
"s209102315",
"s833363870"
] |
u959421160 | p03073 | python | s165618124 | s592149998 | 79 | 67 | 3,188 | 3,188 | Accepted | Accepted | 15.19 | inpl = eval(input())
c1 = 0
c2 = 0
for i in range(1,len(inpl)+1):
if i % 2 != 0:
if inpl[i-1] == '0':
c1 += 1
else:
if inpl[i-1] == '1':
c1 += 1
for i in range(1,len(inpl)+1):
if i % 2 != 1:
if inpl[i-1] == '0':
c2 += 1
else:
if inpl[i-1] == '1':
c2 += 1
print((c1 if c1 < c2 else c2)) | inpl = eval(input())
c1 = 0
c2 = 0
for i,s in enumerate(inpl):
if i % 2 != 0:
if s == '0':
c1 += 1
else:
if s == '1':
c1 += 1
for i,s in enumerate(inpl):
if i % 2 != 1:
if s == '0':
c2 += 1
else:
if s == '1':
c2 += 1
print((c1 if c1 < c2 else c2)) | 20 | 20 | 394 | 356 | inpl = eval(input())
c1 = 0
c2 = 0
for i in range(1, len(inpl) + 1):
if i % 2 != 0:
if inpl[i - 1] == "0":
c1 += 1
else:
if inpl[i - 1] == "1":
c1 += 1
for i in range(1, len(inpl) + 1):
if i % 2 != 1:
if inpl[i - 1] == "0":
c2 += 1
else:
if inpl[i - 1] == "1":
c2 += 1
print((c1 if c1 < c2 else c2))
| inpl = eval(input())
c1 = 0
c2 = 0
for i, s in enumerate(inpl):
if i % 2 != 0:
if s == "0":
c1 += 1
else:
if s == "1":
c1 += 1
for i, s in enumerate(inpl):
if i % 2 != 1:
if s == "0":
c2 += 1
else:
if s == "1":
c2 += 1
print((c1 if c1 < c2 else c2))
| false | 0 | [
"-for i in range(1, len(inpl) + 1):",
"+for i, s in enumerate(inpl):",
"- if inpl[i - 1] == \"0\":",
"+ if s == \"0\":",
"- if inpl[i - 1] == \"1\":",
"+ if s == \"1\":",
"-for i in range(1, len(inpl) + 1):",
"+for i, s in enumerate(inpl):",
"- if inpl[i - 1] == \"0\":",
"+ if s == \"0\":",
"- if inpl[i - 1] == \"1\":",
"+ if s == \"1\":"
] | false | 0.038548 | 0.087357 | 0.441271 | [
"s165618124",
"s592149998"
] |
u647766105 | p01646 | python | s798047124 | s214339927 | 80 | 70 | 4,344 | 4,340 | Accepted | Accepted | 12.5 | graph = []
def init():
global graph
graph = [[False] * 26 + [True] for _ in range(27)]
graph[26][26] = False
def atoi(c):#index
if c == "#":
return 26
return ord(c) - ord("a")
def make_graph(L):
global graph, count
cur = 0
L = [L[0]] + [L[i] for i in range(1, len(L)) if L[i] != L[i-1]]
tmp = []
for s1, s2 in zip(L, L[1:]):
if s1[0] == s2[0]:
tmp += [s1[1:], s2[1:]]
else:
if not tmp == []:
make_graph(tmp)
tmp = []
graph[atoi(s2[0])][atoi(s1[0])] = True
if not tmp == []:
make_graph(tmp)
def check(start):
stack = set([start])
visited = [False] * 27
while len(stack) != 0:
cur = stack.pop()
visited[cur] = True
if graph[cur][start]:
return False
for i in range(27):
if graph[cur][i] and not visited[i]:
stack.add(i)
return True
while True:
n = eval(input())
if n == 0:
break
L = [input() + "#" for _ in range(n)]
init()
make_graph(L)
for i in range(27):
if not check(i):
print("no")
break
else:
print("yes") | graph = []
def init():
global graph
graph = [[False] * 26 + [True] for _ in range(27)]
graph[26][26] = False
def atoi(c):#index
if c == "#":
return 26
return ord(c) - ord("a")
def make_graph(L):
global graph
cur = 0
L = [L[0]] + [L[i] for i in range(1, len(L)) if L[i] != L[i-1]]
tmp = []
for s1, s2 in zip(L, L[1:]):
if s1[0] == s2[0]:
tmp += [s1[1:], s2[1:]]
else:
if not tmp == []:
make_graph(tmp)
tmp = []
graph[atoi(s2[0])][atoi(s1[0])] = True
if not tmp == []:
make_graph(tmp)
def check(start):
stack = set([start])
visited = [False] * 27
while len(stack) != 0:
cur = stack.pop()
visited[cur] = True
if graph[cur][start]:
return False
for i in range(27):
if graph[cur][i] and not visited[i]:
stack.add(i)
return True
while True:
n = eval(input())
if n == 0:
break
L = [input() + "#" for _ in range(n)]
init()
make_graph(L)
for i in range(27):
if not check(i):
print("no")
break
else:
print("yes") | 54 | 54 | 1,272 | 1,265 | graph = []
def init():
global graph
graph = [[False] * 26 + [True] for _ in range(27)]
graph[26][26] = False
def atoi(c): # index
if c == "#":
return 26
return ord(c) - ord("a")
def make_graph(L):
global graph, count
cur = 0
L = [L[0]] + [L[i] for i in range(1, len(L)) if L[i] != L[i - 1]]
tmp = []
for s1, s2 in zip(L, L[1:]):
if s1[0] == s2[0]:
tmp += [s1[1:], s2[1:]]
else:
if not tmp == []:
make_graph(tmp)
tmp = []
graph[atoi(s2[0])][atoi(s1[0])] = True
if not tmp == []:
make_graph(tmp)
def check(start):
stack = set([start])
visited = [False] * 27
while len(stack) != 0:
cur = stack.pop()
visited[cur] = True
if graph[cur][start]:
return False
for i in range(27):
if graph[cur][i] and not visited[i]:
stack.add(i)
return True
while True:
n = eval(input())
if n == 0:
break
L = [input() + "#" for _ in range(n)]
init()
make_graph(L)
for i in range(27):
if not check(i):
print("no")
break
else:
print("yes")
| graph = []
def init():
global graph
graph = [[False] * 26 + [True] for _ in range(27)]
graph[26][26] = False
def atoi(c): # index
if c == "#":
return 26
return ord(c) - ord("a")
def make_graph(L):
global graph
cur = 0
L = [L[0]] + [L[i] for i in range(1, len(L)) if L[i] != L[i - 1]]
tmp = []
for s1, s2 in zip(L, L[1:]):
if s1[0] == s2[0]:
tmp += [s1[1:], s2[1:]]
else:
if not tmp == []:
make_graph(tmp)
tmp = []
graph[atoi(s2[0])][atoi(s1[0])] = True
if not tmp == []:
make_graph(tmp)
def check(start):
stack = set([start])
visited = [False] * 27
while len(stack) != 0:
cur = stack.pop()
visited[cur] = True
if graph[cur][start]:
return False
for i in range(27):
if graph[cur][i] and not visited[i]:
stack.add(i)
return True
while True:
n = eval(input())
if n == 0:
break
L = [input() + "#" for _ in range(n)]
init()
make_graph(L)
for i in range(27):
if not check(i):
print("no")
break
else:
print("yes")
| false | 0 | [
"- global graph, count",
"+ global graph"
] | false | 0.04158 | 0.047011 | 0.884475 | [
"s798047124",
"s214339927"
] |
u271934630 | p04030 | python | s080429109 | s172689425 | 168 | 24 | 38,384 | 3,436 | Accepted | Accepted | 85.71 | S = input()
ans = []
for s in S:
if s == 'B' and ans:
ans.pop()
elif s != 'B':
ans.append(s)
print(*ans, sep='')
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from collections import deque
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
s = i_s()
d = deque()
for x in s:
if d and x == 'B':
d.pop()
elif x == '0' or x == '1':
d.append(x)
print(*d, sep='')
| 10 | 19 | 148 | 374 | S = input()
ans = []
for s in S:
if s == "B" and ans:
ans.pop()
elif s != "B":
ans.append(s)
print(*ans, sep="")
| import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
from collections import deque
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
s = i_s()
d = deque()
for x in s:
if d and x == "B":
d.pop()
elif x == "0" or x == "1":
d.append(x)
print(*d, sep="")
| false | 47.368421 | [
"-S = input()",
"-ans = []",
"-for s in S:",
"- if s == \"B\" and ans:",
"- ans.pop()",
"- elif s != \"B\":",
"- ans.append(s)",
"-print(*ans, sep=\"\")",
"+import sys",
"+",
"+stdin = sys.stdin",
"+sys.setrecursionlimit(10**7)",
"+from collections import deque",
"+",
"+i_i = lambda: int(i_s())",
"+i_l = lambda: list(map(int, stdin.readline().split()))",
"+i_s = lambda: stdin.readline().rstrip()",
"+s = i_s()",
"+d = deque()",
"+for x in s:",
"+ if d and x == \"B\":",
"+ d.pop()",
"+ elif x == \"0\" or x == \"1\":",
"+ d.append(x)",
"+print(*d, sep=\"\")"
] | false | 0.046564 | 0.046854 | 0.993817 | [
"s080429109",
"s172689425"
] |
u837673618 | p02709 | python | s862402215 | s475911594 | 1,560 | 1,139 | 9,984 | 9,948 | Accepted | Accepted | 26.99 | from collections import *
from itertools import *
N = int(eval(input()))
A = list(map(int, input().split()))
SA = SB = 0
ABI = sorted(((b:=max(N-i, i-1)*a, SA:=SA+a, SB:=SB+b) and (a, b, i) for i, a in enumerate(A, 1)), reverse=True)
prev = {0:0}
prev_max = 0
for k, (a, b, i) in enumerate(ABI):
curr = defaultdict(int)
curr_max = 0
for l, p in list(prev.items()):
r = k-l
if p + SB - min(l,r)*SA < prev_max:
continue
curr[l] = max(curr[l], p+abs(N-i-r)*a)
curr[l+1] = p+abs(i-l-1)*a
curr_max = max(curr_max, curr[l], curr[l+1])
SA -= a
SB -= b
prev = curr
prev_max = curr_max
print(curr_max)
| from collections import *
from itertools import *
N = int(eval(input()))
A = list(map(int, input().split()))
SA = SB = 0
ABI = sorted(((b:=max(N-i, i-1)*a, SA:=SA+a, SB:=SB+b) and (a, b, i) for i, a in enumerate(A, 1)), reverse=True)
prev = {0:0}
prev_max = 0
for k, (a, b, i) in enumerate(ABI):
curr = defaultdict(int)
curr_max = 0
for l, p in list(prev.items()):
r = k-l
if p + SB - max(l,r)*SA < prev_max:
continue
curr[l] = max(curr[l], p+abs(N-i-r)*a)
curr[l+1] = p+abs(i-l-1)*a
curr_max = max(curr_max, curr[l], curr[l+1])
SA -= a
SB -= b
prev = curr
prev_max = curr_max
print(curr_max)
| 27 | 27 | 645 | 645 | from collections import *
from itertools import *
N = int(eval(input()))
A = list(map(int, input().split()))
SA = SB = 0
ABI = sorted(
(
(b := max(N - i, i - 1) * a, SA := SA + a, SB := SB + b) and (a, b, i)
for i, a in enumerate(A, 1)
),
reverse=True,
)
prev = {0: 0}
prev_max = 0
for k, (a, b, i) in enumerate(ABI):
curr = defaultdict(int)
curr_max = 0
for l, p in list(prev.items()):
r = k - l
if p + SB - min(l, r) * SA < prev_max:
continue
curr[l] = max(curr[l], p + abs(N - i - r) * a)
curr[l + 1] = p + abs(i - l - 1) * a
curr_max = max(curr_max, curr[l], curr[l + 1])
SA -= a
SB -= b
prev = curr
prev_max = curr_max
print(curr_max)
| from collections import *
from itertools import *
N = int(eval(input()))
A = list(map(int, input().split()))
SA = SB = 0
ABI = sorted(
(
(b := max(N - i, i - 1) * a, SA := SA + a, SB := SB + b) and (a, b, i)
for i, a in enumerate(A, 1)
),
reverse=True,
)
prev = {0: 0}
prev_max = 0
for k, (a, b, i) in enumerate(ABI):
curr = defaultdict(int)
curr_max = 0
for l, p in list(prev.items()):
r = k - l
if p + SB - max(l, r) * SA < prev_max:
continue
curr[l] = max(curr[l], p + abs(N - i - r) * a)
curr[l + 1] = p + abs(i - l - 1) * a
curr_max = max(curr_max, curr[l], curr[l + 1])
SA -= a
SB -= b
prev = curr
prev_max = curr_max
print(curr_max)
| false | 0 | [
"- if p + SB - min(l, r) * SA < prev_max:",
"+ if p + SB - max(l, r) * SA < prev_max:"
] | false | 0.281922 | 0.170879 | 1.649834 | [
"s862402215",
"s475911594"
] |
u558242240 | p03128 | python | s703541039 | s762412627 | 294 | 236 | 46,428 | 51,804 | Accepted | Accepted | 19.73 | #123456789
#255456376
n, m = list(map(int, input().split()))
a = list(map(int , input().split()))
a.sort()
t = [2,5,5,4,5,6,3,7,6]
cost = []
for i in range(m):
cost.append(t[a[i]-1])
#print(a)
#print(cost)
min_c = min(cost)
digit = n // min_c # 最大桁数
s = n % min_c # 最大桁まで作った余りの本数
max_ai = 0
import itertools
for i in itertools.product(list(range(m+1)), repeat=min(digit, 5)):
#print(i)
t = list(i)
ci = sum(list([cost[j-1] if j != 0 else 0 for j in t]))
ai = ''.join([str(a[j-1]) if j != 0 else '' for j in t])
if digit <= 5:
if ci == n:
max_ai = max(max_ai, int(ai))
else:
if ci == (n - min_c * (digit - 5)):
max_ai = max(max_ai, int(ai))
#print(ci, max_ai)
min_chr = ''
for i in reversed(list(range(m))):
if min_c == cost[i]:
min_chr = a[i]
break
if digit <= 5:
print(max_ai)
else:
ans = list(str(max_ai)) + ([str(min_chr)] * (digit - 5))
ans.sort(reverse=True)
print((''.join(ans)))
"""
chg = []
while s > 0:
#print(s, chg)
for i in reversed(range(m)):
if min_c + s == cost[i]:
chg.append(a[i])
s = 0
break
for i in reversed(range(m)):
if min_c < cost[i] and cost[i] < min_c + s:
chg.append(a[i])
s = min_c + s - cost[i]
break
#print(chg)
min_chr = ''
for i in reversed(range(m)):
if min_c == cost[i]:
min_chr = a[i]
break
ans = chg + ([min_chr] * (d - len(chg)))
ans.sort(reverse=True)
print(''.join(map(str, ans)))
""" | n, m = list(map(int, input().split()))
a = list(map(int , input().split()))
t = [2,5,5,4,5,6,3,7,6]
cost = {ai: t[ai-1] for ai in a}
dp = [0] + [-1] * n
for i in range(n+1):
tmp = []
for ai, ci in list(cost.items()):
if i - ci >= 0 and dp[i-ci] >= 0:
tmp.append(dp[i-ci] * 10 + ai)
if len(tmp) > 0:
dp[i] = max(tmp)
print((dp[n])) | 69 | 15 | 1,621 | 372 | # 123456789
# 255456376
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
t = [2, 5, 5, 4, 5, 6, 3, 7, 6]
cost = []
for i in range(m):
cost.append(t[a[i] - 1])
# print(a)
# print(cost)
min_c = min(cost)
digit = n // min_c # 最大桁数
s = n % min_c # 最大桁まで作った余りの本数
max_ai = 0
import itertools
for i in itertools.product(list(range(m + 1)), repeat=min(digit, 5)):
# print(i)
t = list(i)
ci = sum(list([cost[j - 1] if j != 0 else 0 for j in t]))
ai = "".join([str(a[j - 1]) if j != 0 else "" for j in t])
if digit <= 5:
if ci == n:
max_ai = max(max_ai, int(ai))
else:
if ci == (n - min_c * (digit - 5)):
max_ai = max(max_ai, int(ai))
# print(ci, max_ai)
min_chr = ""
for i in reversed(list(range(m))):
if min_c == cost[i]:
min_chr = a[i]
break
if digit <= 5:
print(max_ai)
else:
ans = list(str(max_ai)) + ([str(min_chr)] * (digit - 5))
ans.sort(reverse=True)
print(("".join(ans)))
"""
chg = []
while s > 0:
#print(s, chg)
for i in reversed(range(m)):
if min_c + s == cost[i]:
chg.append(a[i])
s = 0
break
for i in reversed(range(m)):
if min_c < cost[i] and cost[i] < min_c + s:
chg.append(a[i])
s = min_c + s - cost[i]
break
#print(chg)
min_chr = ''
for i in reversed(range(m)):
if min_c == cost[i]:
min_chr = a[i]
break
ans = chg + ([min_chr] * (d - len(chg)))
ans.sort(reverse=True)
print(''.join(map(str, ans)))
"""
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
t = [2, 5, 5, 4, 5, 6, 3, 7, 6]
cost = {ai: t[ai - 1] for ai in a}
dp = [0] + [-1] * n
for i in range(n + 1):
tmp = []
for ai, ci in list(cost.items()):
if i - ci >= 0 and dp[i - ci] >= 0:
tmp.append(dp[i - ci] * 10 + ai)
if len(tmp) > 0:
dp[i] = max(tmp)
print((dp[n]))
| false | 78.26087 | [
"-# 123456789",
"-# 255456376",
"-a.sort()",
"-cost = []",
"-for i in range(m):",
"- cost.append(t[a[i] - 1])",
"-# print(a)",
"-# print(cost)",
"-min_c = min(cost)",
"-digit = n // min_c # 最大桁数",
"-s = n % min_c # 最大桁まで作った余りの本数",
"-max_ai = 0",
"-import itertools",
"-",
"-for i in itertools.product(list(range(m + 1)), repeat=min(digit, 5)):",
"- # print(i)",
"- t = list(i)",
"- ci = sum(list([cost[j - 1] if j != 0 else 0 for j in t]))",
"- ai = \"\".join([str(a[j - 1]) if j != 0 else \"\" for j in t])",
"- if digit <= 5:",
"- if ci == n:",
"- max_ai = max(max_ai, int(ai))",
"- else:",
"- if ci == (n - min_c * (digit - 5)):",
"- max_ai = max(max_ai, int(ai))",
"- # print(ci, max_ai)",
"-min_chr = \"\"",
"-for i in reversed(list(range(m))):",
"- if min_c == cost[i]:",
"- min_chr = a[i]",
"- break",
"-if digit <= 5:",
"- print(max_ai)",
"-else:",
"- ans = list(str(max_ai)) + ([str(min_chr)] * (digit - 5))",
"- ans.sort(reverse=True)",
"- print((\"\".join(ans)))",
"-\"\"\"",
"-chg = []",
"-while s > 0:",
"- #print(s, chg)",
"- for i in reversed(range(m)):",
"- if min_c + s == cost[i]:",
"- chg.append(a[i])",
"- s = 0",
"- break",
"- for i in reversed(range(m)):",
"- if min_c < cost[i] and cost[i] < min_c + s:",
"- chg.append(a[i])",
"- s = min_c + s - cost[i]",
"- break",
"-#print(chg)",
"-min_chr = ''",
"-for i in reversed(range(m)):",
"- if min_c == cost[i]:",
"- min_chr = a[i]",
"- break",
"-ans = chg + ([min_chr] * (d - len(chg)))",
"-ans.sort(reverse=True)",
"-print(''.join(map(str, ans)))",
"-\"\"\"",
"+cost = {ai: t[ai - 1] for ai in a}",
"+dp = [0] + [-1] * n",
"+for i in range(n + 1):",
"+ tmp = []",
"+ for ai, ci in list(cost.items()):",
"+ if i - ci >= 0 and dp[i - ci] >= 0:",
"+ tmp.append(dp[i - ci] * 10 + ai)",
"+ if len(tmp) > 0:",
"+ dp[i] = max(tmp)",
"+print((dp[n]))"
] | false | 0.105196 | 0.12415 | 0.847326 | [
"s703541039",
"s762412627"
] |
u071680334 | p02662 | python | s395345444 | s118115839 | 352 | 299 | 97,532 | 97,580 | Accepted | Accepted | 15.06 | import numpy as np
MOD = 998244353
def main():
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = np.zeros((n+1, s+1), dtype=np.int64)
dp[0][0] = 1
for i in range(n):
dp[i][dp[i] >= MOD] %= MOD
dp[i+1] += dp[i]*2
if a[i] <= s:
dp[i+1][a[i]:] += dp[i][:-a[i]]
print((dp[n][s]%MOD))
if __name__ == "__main__":
main() | import numpy as np
MOD = 998244353
def main():
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = np.zeros((n+1, s+1), dtype=np.int64)
dp[0][0] = 1
for i, v in enumerate(a):
dp[i+1] += dp[i]*2
if v <= s:
dp[i+1][v:] += dp[i][:-v]
dp[i+1] %= MOD
print((int(dp[n][s])%MOD))
if __name__ == "__main__":
main()
| 17 | 18 | 417 | 411 | import numpy as np
MOD = 998244353
def main():
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = np.zeros((n + 1, s + 1), dtype=np.int64)
dp[0][0] = 1
for i in range(n):
dp[i][dp[i] >= MOD] %= MOD
dp[i + 1] += dp[i] * 2
if a[i] <= s:
dp[i + 1][a[i] :] += dp[i][: -a[i]]
print((dp[n][s] % MOD))
if __name__ == "__main__":
main()
| import numpy as np
MOD = 998244353
def main():
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = np.zeros((n + 1, s + 1), dtype=np.int64)
dp[0][0] = 1
for i, v in enumerate(a):
dp[i + 1] += dp[i] * 2
if v <= s:
dp[i + 1][v:] += dp[i][:-v]
dp[i + 1] %= MOD
print((int(dp[n][s]) % MOD))
if __name__ == "__main__":
main()
| false | 5.555556 | [
"- for i in range(n):",
"- dp[i][dp[i] >= MOD] %= MOD",
"+ for i, v in enumerate(a):",
"- if a[i] <= s:",
"- dp[i + 1][a[i] :] += dp[i][: -a[i]]",
"- print((dp[n][s] % MOD))",
"+ if v <= s:",
"+ dp[i + 1][v:] += dp[i][:-v]",
"+ dp[i + 1] %= MOD",
"+ print((int(dp[n][s]) % MOD))"
] | false | 0.334539 | 0.254556 | 1.314204 | [
"s395345444",
"s118115839"
] |
u281303342 | p03354 | python | s846107482 | s493169803 | 654 | 479 | 25,220 | 25,188 | Accepted | Accepted | 26.76 | N,M = list(map(int,input().split()))
P = list(map(int,input().split()))
XY = [tuple(map(int,input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
# 交換可能な頂点でグルーピング
A = UnionFind(N)
for (x,y) in XY:
A.unite(x,y)
# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループかどうか
ans = 0
for i in range(N):
if A.check(i+1,P[i]):
ans += 1
print(ans) | # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0]*(n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = list(map(int,input().split()))
P = list(map(int,input().split()))
XY = [tuple(map(int,input().split())) for _ in range(M)]
# 交換可能な頂点でグルーピング
A = UnionFind(N)
for x,y in XY:
A.unite(x,y)
# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループなら, 操作を行うことで p_i == i とできる
ans = 0
for i in range(N):
if A.check(P[i],i+1):
ans += 1
print(ans) | 38 | 48 | 972 | 1,332 | N, M = list(map(int, input().split()))
P = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
# 交換可能な頂点でグルーピング
A = UnionFind(N)
for (x, y) in XY:
A.unite(x, y)
# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループかどうか
ans = 0
for i in range(N):
if A.check(i + 1, P[i]):
ans += 1
print(ans)
| # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def check(self, x, y):
return self.find(x) == self.find(y)
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N, M = list(map(int, input().split()))
P = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for _ in range(M)]
# 交換可能な頂点でグルーピング
A = UnionFind(N)
for x, y in XY:
A.unite(x, y)
# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループなら, 操作を行うことで p_i == i とできる
ans = 0
for i in range(N):
if A.check(P[i], i + 1):
ans += 1
print(ans)
| false | 20.833333 | [
"-N, M = list(map(int, input().split()))",
"-P = list(map(int, input().split()))",
"-XY = [tuple(map(int, input().split())) for _ in range(M)]",
"+# Python3 (3.4.3)",
"+import sys",
"-",
"+input = sys.stdin.readline",
"+# function",
"+# main",
"+N, M = list(map(int, input().split()))",
"+P = list(map(int, input().split()))",
"+XY = [tuple(map(int, input().split())) for _ in range(M)]",
"-for (x, y) in XY:",
"+for x, y in XY:",
"-# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループかどうか",
"+# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループなら, 操作を行うことで p_i == i とできる",
"- if A.check(i + 1, P[i]):",
"+ if A.check(P[i], i + 1):"
] | false | 0.046939 | 0.17633 | 0.266202 | [
"s846107482",
"s493169803"
] |
u405660020 | p02679 | python | s978830373 | s268373636 | 934 | 533 | 46,492 | 121,684 | Accepted | Accepted | 42.93 | import math
n=int(eval(input()))
D={}
for _ in range(n):
a,b=list(map(int, input().split()))
if a==0 and b==0:
key=(0,0)
elif a==0:
key=(0,1)
elif b==0:
key=(1,0)
else:
if a<0:
a=-a
b=-b
g=math.gcd(a, abs(b))
key=(a//g, b//g)
if key not in D:
D[key]=0
D[key]+=1
mod=10**9+7
ans=1
zz=0
for k1, v1 in list(D.items()):
if k1==(0,0):
zz+=v1
continue
if v1==0:
continue
if k1[1]>0:
k2=(k1[1], -k1[0])
else:
k2=(-k1[1], k1[0])
if k2 not in D:
ans=ans*pow(2, v1, mod)%mod
else:
v2=D[k2]
m=(pow(2, v1, mod)+pow(2, v2, mod)-1)%mod
ans=ans*m%mod
D[k2]=0
print(((ans+zz-1)%mod))
| import math
n=int(eval(input()))
D={}
for _ in range(n):
a,b=list(map(int, input().split()))
if a==0 and b==0:
key=(0,0)
elif a==0:
key=(0,1)
elif b==0:
key=(1,0)
else:
if a<0:
a=-a
b=-b
g=math.gcd(a, abs(b))
key=(a//g, b//g)
if key not in D:
D[key]=0
D[key]+=1
mod=10**9+7
ans=1
zz=0
for k1, v1 in list(D.items()):
if v1==0:
continue
if k1==(0,0):
zz+=v1
continue
if k1[1]>0:
k2=(k1[1], -k1[0])
else:
k2=(-k1[1], k1[0])
if k2 not in D:
ans=ans*pow(2, v1, mod)%mod
else:
v2=D[k2]
m=(pow(2, v1, mod)+pow(2, v2, mod)-1)%mod
ans=ans*m%mod
D[k2]=0
print(((ans+zz-1)%mod))
| 47 | 47 | 812 | 812 | import math
n = int(eval(input()))
D = {}
for _ in range(n):
a, b = list(map(int, input().split()))
if a == 0 and b == 0:
key = (0, 0)
elif a == 0:
key = (0, 1)
elif b == 0:
key = (1, 0)
else:
if a < 0:
a = -a
b = -b
g = math.gcd(a, abs(b))
key = (a // g, b // g)
if key not in D:
D[key] = 0
D[key] += 1
mod = 10**9 + 7
ans = 1
zz = 0
for k1, v1 in list(D.items()):
if k1 == (0, 0):
zz += v1
continue
if v1 == 0:
continue
if k1[1] > 0:
k2 = (k1[1], -k1[0])
else:
k2 = (-k1[1], k1[0])
if k2 not in D:
ans = ans * pow(2, v1, mod) % mod
else:
v2 = D[k2]
m = (pow(2, v1, mod) + pow(2, v2, mod) - 1) % mod
ans = ans * m % mod
D[k2] = 0
print(((ans + zz - 1) % mod))
| import math
n = int(eval(input()))
D = {}
for _ in range(n):
a, b = list(map(int, input().split()))
if a == 0 and b == 0:
key = (0, 0)
elif a == 0:
key = (0, 1)
elif b == 0:
key = (1, 0)
else:
if a < 0:
a = -a
b = -b
g = math.gcd(a, abs(b))
key = (a // g, b // g)
if key not in D:
D[key] = 0
D[key] += 1
mod = 10**9 + 7
ans = 1
zz = 0
for k1, v1 in list(D.items()):
if v1 == 0:
continue
if k1 == (0, 0):
zz += v1
continue
if k1[1] > 0:
k2 = (k1[1], -k1[0])
else:
k2 = (-k1[1], k1[0])
if k2 not in D:
ans = ans * pow(2, v1, mod) % mod
else:
v2 = D[k2]
m = (pow(2, v1, mod) + pow(2, v2, mod) - 1) % mod
ans = ans * m % mod
D[k2] = 0
print(((ans + zz - 1) % mod))
| false | 0 | [
"+ if v1 == 0:",
"+ continue",
"- continue",
"- if v1 == 0:"
] | false | 0.039617 | 0.038573 | 1.027051 | [
"s978830373",
"s268373636"
] |
u409306788 | p03578 | python | s609944595 | s292401785 | 293 | 257 | 41,816 | 41,316 | Accepted | Accepted | 12.29 | # B - Problem Set
def is_create(dic_d, t):
for ti in t:
if not ti in list(dic_d.keys()):
return False
elif dic[ti] == 0:
return False
else:
dic[ti] -= 1
return True
n = int(eval(input()))
d = list(map(int, input().split()))
m = int(eval(input()))
t = list(map(int, input().split()))
dic = dict()
for di in d:
if di in list(dic.keys()):
dic[di] += 1
else:
dic[di] = 1
if is_create(dic, t):
print('YES')
else:
print('NO') | # B - Problem Set
def is_create(dic_d, t):
for ti in t:
if not ti in list(dic_d.keys()):
return False
elif dic[ti] == 0:
return False
else:
dic[ti] -= 1
return True
n = int(eval(input()))
d = list(map(int, input().split()))
m = int(eval(input()))
t = list(map(int, input().split()))
dic = dict()
for di in d:
dic.setdefault(di, 0)
dic[di] += 1
'''if di in dic.keys():
dic[di] += 1
else:
dic[di] = 1'''
if is_create(dic, t):
print('YES')
else:
print('NO') | 30 | 32 | 457 | 502 | # B - Problem Set
def is_create(dic_d, t):
for ti in t:
if not ti in list(dic_d.keys()):
return False
elif dic[ti] == 0:
return False
else:
dic[ti] -= 1
return True
n = int(eval(input()))
d = list(map(int, input().split()))
m = int(eval(input()))
t = list(map(int, input().split()))
dic = dict()
for di in d:
if di in list(dic.keys()):
dic[di] += 1
else:
dic[di] = 1
if is_create(dic, t):
print("YES")
else:
print("NO")
| # B - Problem Set
def is_create(dic_d, t):
for ti in t:
if not ti in list(dic_d.keys()):
return False
elif dic[ti] == 0:
return False
else:
dic[ti] -= 1
return True
n = int(eval(input()))
d = list(map(int, input().split()))
m = int(eval(input()))
t = list(map(int, input().split()))
dic = dict()
for di in d:
dic.setdefault(di, 0)
dic[di] += 1
"""if di in dic.keys():
dic[di] += 1
else:
dic[di] = 1"""
if is_create(dic, t):
print("YES")
else:
print("NO")
| false | 6.25 | [
"- if di in list(dic.keys()):",
"- dic[di] += 1",
"- else:",
"- dic[di] = 1",
"+ dic.setdefault(di, 0)",
"+ dic[di] += 1",
"+ \"\"\"if di in dic.keys():",
"+\t\tdic[di] += 1",
"+\telse:",
"+\t\tdic[di] = 1\"\"\""
] | false | 0.036346 | 0.036247 | 1.002742 | [
"s609944595",
"s292401785"
] |
u182898140 | p02712 | python | s152105520 | s730336518 | 155 | 142 | 9,156 | 9,064 | Accepted | Accepted | 8.39 | N=int(eval(input()))
total=0
for i in range(N+1):
if i%3==0 or i%5==0:
continue
else:
total+=i
print(total) | N=int(eval(input()))
total=0
for i in range(1,N+1):
if i%3==0 or i%5==0:
pass
else:
total +=i
print(total) | 12 | 11 | 130 | 125 | N = int(eval(input()))
total = 0
for i in range(N + 1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
total += i
print(total)
| N = int(eval(input()))
total = 0
for i in range(1, N + 1):
if i % 3 == 0 or i % 5 == 0:
pass
else:
total += i
print(total)
| false | 8.333333 | [
"-for i in range(N + 1):",
"+for i in range(1, N + 1):",
"- continue",
"+ pass"
] | false | 0.135035 | 0.276298 | 0.488728 | [
"s152105520",
"s730336518"
] |
u638795007 | p04034 | python | s275096290 | s581064931 | 322 | 227 | 52,188 | 5,492 | Accepted | Accepted | 29.5 | def examA():
a, b = LI()
if a>0:
ans = "Positive"
print(ans)
return
if b>=0:
ans = "Zero"
else:
judge = b-a
if judge%2==1:
ans = "Positive"
else:
ans = "Negative"
print(ans)
return
def examB():
N, M = LI()
boal = [1]*N
d = defaultdict(bool)
d[0] = True
for _ in range(M):
x,y = LI()
boal[x-1] -=1
boal[y-1] +=1
if d[x-1]:
d[y-1] = True
if boal[x-1]==0:
d[x-1] = False
ans = sum(d.values())
print(ans)
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')
if __name__ == '__main__':
examB()
| def examA():
a, b = LI()
if b<a:
a,b = b,a
if a<=0 and 0<=b:
print("Zero")
elif 0<a:
print("Positive")
else:
judge = b-a+1
if judge%2==0:
print("Positive")
else:
print("Negative")
return
def examB():
N, M = LI()
flag_R = [False]*N
cnt = [1]*N
flag_R[0] = True
for _ in range(M):
x, y = LI()
x -= 1; y -= 1
if flag_R[x]:
flag_R[y] = True
cnt[y] += 1
cnt[x] -= 1
if cnt[x]==0:
flag_R[x] = False
ans = sum(flag_R)
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == '__main__':
examB()
"""
""" | 47 | 78 | 1,125 | 1,562 | def examA():
a, b = LI()
if a > 0:
ans = "Positive"
print(ans)
return
if b >= 0:
ans = "Zero"
else:
judge = b - a
if judge % 2 == 1:
ans = "Positive"
else:
ans = "Negative"
print(ans)
return
def examB():
N, M = LI()
boal = [1] * N
d = defaultdict(bool)
d[0] = True
for _ in range(M):
x, y = LI()
boal[x - 1] -= 1
boal[y - 1] += 1
if d[x - 1]:
d[y - 1] = True
if boal[x - 1] == 0:
d[x - 1] = False
ans = sum(d.values())
print(ans)
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
if __name__ == "__main__":
examB()
| def examA():
a, b = LI()
if b < a:
a, b = b, a
if a <= 0 and 0 <= b:
print("Zero")
elif 0 < a:
print("Positive")
else:
judge = b - a + 1
if judge % 2 == 0:
print("Positive")
else:
print("Negative")
return
def examB():
N, M = LI()
flag_R = [False] * N
cnt = [1] * N
flag_R[0] = True
for _ in range(M):
x, y = LI()
x -= 1
y -= 1
if flag_R[x]:
flag_R[y] = True
cnt[y] += 1
cnt[x] -= 1
if cnt[x] == 0:
flag_R[x] = False
ans = sum(flag_R)
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == "__main__":
examB()
"""
"""
| false | 39.74359 | [
"- if a > 0:",
"- ans = \"Positive\"",
"- print(ans)",
"- return",
"- if b >= 0:",
"- ans = \"Zero\"",
"+ if b < a:",
"+ a, b = b, a",
"+ if a <= 0 and 0 <= b:",
"+ print(\"Zero\")",
"+ elif 0 < a:",
"+ print(\"Positive\")",
"- judge = b - a",
"- if judge % 2 == 1:",
"- ans = \"Positive\"",
"+ judge = b - a + 1",
"+ if judge % 2 == 0:",
"+ print(\"Positive\")",
"- ans = \"Negative\"",
"- print(ans)",
"+ print(\"Negative\")",
"- boal = [1] * N",
"- d = defaultdict(bool)",
"- d[0] = True",
"+ flag_R = [False] * N",
"+ cnt = [1] * N",
"+ flag_R[0] = True",
"- boal[x - 1] -= 1",
"- boal[y - 1] += 1",
"- if d[x - 1]:",
"- d[y - 1] = True",
"- if boal[x - 1] == 0:",
"- d[x - 1] = False",
"- ans = sum(d.values())",
"+ x -= 1",
"+ y -= 1",
"+ if flag_R[x]:",
"+ flag_R[y] = True",
"+ cnt[y] += 1",
"+ cnt[x] -= 1",
"+ if cnt[x] == 0:",
"+ flag_R[x] = False",
"+ ans = sum(flag_R)",
"-import sys, copy, bisect, itertools, heapq, math",
"+def examC():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+def examD():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+def examE():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+def examF():",
"+ ans = 0",
"+ print(ans)",
"+ return",
"+",
"+",
"+import sys, bisect, itertools, heapq, math, random",
"+from copy import deepcopy",
"+global mod, mod2, inf, alphabet, _ep",
"-inf = float(\"inf\")",
"+mod2 = 998244353",
"+inf = 10**18",
"+_ep = 10 ** (-12)",
"+alphabet = [chr(ord(\"a\") + i) for i in range(26)]",
"+sys.setrecursionlimit(10**6)",
"+\"\"\"",
"+\"\"\""
] | false | 0.056448 | 0.095258 | 0.592579 | [
"s275096290",
"s581064931"
] |
u888337853 | p03030 | python | s519019330 | s264327838 | 187 | 18 | 38,384 | 3,064 | Accepted | Accepted | 90.37 | import math
import copy
class Score:
def set_data(self, town, score, idx):
self.town = set_town
self.score = set_score
self.idx = set_idx
inputa = input().split()
# inputb = input().split()
a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])
# x = int(inputb[0])
# y = int(inputb[1])
# inputList=[]
# for i in range(a):
# inputNum = input()
# inputList.append(inputNum)
inputList=[]
for i in range(a):
inputItem = input().split()
inputItem.append(i+1)
inputList.append(inputItem)
# listb = []
# listb = [int(n) for n in inputb]
inputNameListSorted = []
tmp = sorted(inputList, key=lambda x:int(x[1]), reverse = True)
inputNameListSorted = sorted(tmp, key=lambda x:x[0])
for i in range(len(inputNameListSorted)):
print((inputNameListSorted[i][2])) | import sys
# import math
# import bisect
# import copy
# import heapq
# from collections import deque
# import decimal
# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n = ni()
d = []
for i in range(n):
s, p = input().split()
d.append((s, int(p), i + 1))
tmp = sorted(d, key=lambda x: x[1], reverse=True)
tmp1 = sorted(tmp, key=lambda x: x[0])
for t in tmp1:
print((t[2]))
if __name__ == '__main__':
main()
| 40 | 38 | 854 | 703 | import math
import copy
class Score:
def set_data(self, town, score, idx):
self.town = set_town
self.score = set_score
self.idx = set_idx
inputa = input().split()
# inputb = input().split()
a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])
# x = int(inputb[0])
# y = int(inputb[1])
# inputList=[]
# for i in range(a):
# inputNum = input()
# inputList.append(inputNum)
inputList = []
for i in range(a):
inputItem = input().split()
inputItem.append(i + 1)
inputList.append(inputItem)
# listb = []
# listb = [int(n) for n in inputb]
inputNameListSorted = []
tmp = sorted(inputList, key=lambda x: int(x[1]), reverse=True)
inputNameListSorted = sorted(tmp, key=lambda x: x[0])
for i in range(len(inputNameListSorted)):
print((inputNameListSorted[i][2]))
| import sys
# import math
# import bisect
# import copy
# import heapq
# from collections import deque
# import decimal
# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n = ni()
d = []
for i in range(n):
s, p = input().split()
d.append((s, int(p), i + 1))
tmp = sorted(d, key=lambda x: x[1], reverse=True)
tmp1 = sorted(tmp, key=lambda x: x[0])
for t in tmp1:
print((t[2]))
if __name__ == "__main__":
main()
| false | 5 | [
"-import math",
"-import copy",
"+import sys",
"+",
"+# import math",
"+# import bisect",
"+# import copy",
"+# import heapq",
"+# from collections import deque",
"+# import decimal",
"+# sys.setrecursionlimit(100001)",
"+# INF = sys.maxsize",
"+# MOD = 10 ** 9 + 7",
"+ni = lambda: int(sys.stdin.readline())",
"+ns = lambda: list(map(int, sys.stdin.readline().split()))",
"+na = lambda: list(map(int, sys.stdin.readline().split()))",
"+# ===CODE===",
"+def main():",
"+ n = ni()",
"+ d = []",
"+ for i in range(n):",
"+ s, p = input().split()",
"+ d.append((s, int(p), i + 1))",
"+ tmp = sorted(d, key=lambda x: x[1], reverse=True)",
"+ tmp1 = sorted(tmp, key=lambda x: x[0])",
"+ for t in tmp1:",
"+ print((t[2]))",
"-class Score:",
"- def set_data(self, town, score, idx):",
"- self.town = set_town",
"- self.score = set_score",
"- self.idx = set_idx",
"-",
"-",
"-inputa = input().split()",
"-# inputb = input().split()",
"-a = int(inputa[0])",
"-# b = int(inputa[1])",
"-# c = int(inputa[2])",
"-# x = int(inputb[0])",
"-# y = int(inputb[1])",
"-# inputList=[]",
"-# for i in range(a):",
"-# inputNum = input()",
"-# inputList.append(inputNum)",
"-inputList = []",
"-for i in range(a):",
"- inputItem = input().split()",
"- inputItem.append(i + 1)",
"- inputList.append(inputItem)",
"-# listb = []",
"-# listb = [int(n) for n in inputb]",
"-inputNameListSorted = []",
"-tmp = sorted(inputList, key=lambda x: int(x[1]), reverse=True)",
"-inputNameListSorted = sorted(tmp, key=lambda x: x[0])",
"-for i in range(len(inputNameListSorted)):",
"- print((inputNameListSorted[i][2]))",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.066521 | 0.040049 | 1.660995 | [
"s519019330",
"s264327838"
] |
u176645218 | p02798 | python | s053147295 | s565820784 | 1,483 | 504 | 220,680 | 75,868 | Accepted | Accepted | 66.01 | from itertools import permutations, combinations, chain
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
def dpinit(ps, val=0):
import copy
res = [val for i in [0]*ps[-1]]
for i in ps[:-1][::-1]:
res = [copy.deepcopy(res) for k in [0]*i]
return res
inf = 10**10
dp = [defaultdict(lambda : inf) for i in range(2**N+1)]
dp[0][0] = 0
for b in range(2**N):
c = bin(b).count('1')
for i in range(1,N+1):
p = N-i
f = 1<<p
if b & f:
continue
nb = b | f
k = bin(b % f).count('1')
v = A[i-1] if (i-c) % 2 == 1 else B[i-1]
for val, inv in list(dp[b].items()):
if val <= v:
dp[nb][v] = min(dp[nb][v], inv+abs(c+1-(i+k)))
if not dp[2**N-1]:
print((-1))
exit()
ans = min(dp[2**N-1].values())
print((ans if ans != inf else -1))
| from itertools import chain
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
def count_bit(x):
res = 0
while x:
res += x % 2
x >>= 1
return res
def int2bin(x,N):
res = [0]*N
for i in range(N):
res[N-1-i] = x % 2
x >>= 1
return res
inf = 10**10
M = N//2 # the n of odd index
ans = inf
for b in range(2**N):
valid = True
if count_bit(b) == M:
odd_index = int2bin(b,N) # 1 : odd
evens = []
odds = []
for i in range(N):
if odd_index[i]:
if i % 2:
odds.append((A[i],i))
else:
odds.append((B[i],i))
else:
if i % 2:
evens.append((B[i],i))
else:
evens.append((A[i],i))
SE = sorted(evens)
SO = sorted(odds)
L = [None]*N
L[::2] = SE
L[1::2] = SO
for (a,_),(b,_) in zip(L,L[1:]):
if a > b:
valid = False
break
if valid:
L = list(zip(L,list(range(N))))
L = sorted(L,key=lambda x : x[0][1])
L = [(a,c) for (a,b),c in L]
temp = 0
for i in range(N):
for j in range(i):
if L[j] > L[i]:
temp += 1
ans = min(temp,ans)
if ans == inf:
ans = -1
print(ans)
| 38 | 65 | 956 | 1,540 | from itertools import permutations, combinations, chain
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def dpinit(ps, val=0):
import copy
res = [val for i in [0] * ps[-1]]
for i in ps[:-1][::-1]:
res = [copy.deepcopy(res) for k in [0] * i]
return res
inf = 10**10
dp = [defaultdict(lambda: inf) for i in range(2**N + 1)]
dp[0][0] = 0
for b in range(2**N):
c = bin(b).count("1")
for i in range(1, N + 1):
p = N - i
f = 1 << p
if b & f:
continue
nb = b | f
k = bin(b % f).count("1")
v = A[i - 1] if (i - c) % 2 == 1 else B[i - 1]
for val, inv in list(dp[b].items()):
if val <= v:
dp[nb][v] = min(dp[nb][v], inv + abs(c + 1 - (i + k)))
if not dp[2**N - 1]:
print((-1))
exit()
ans = min(dp[2**N - 1].values())
print((ans if ans != inf else -1))
| from itertools import chain
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def count_bit(x):
res = 0
while x:
res += x % 2
x >>= 1
return res
def int2bin(x, N):
res = [0] * N
for i in range(N):
res[N - 1 - i] = x % 2
x >>= 1
return res
inf = 10**10
M = N // 2 # the n of odd index
ans = inf
for b in range(2**N):
valid = True
if count_bit(b) == M:
odd_index = int2bin(b, N) # 1 : odd
evens = []
odds = []
for i in range(N):
if odd_index[i]:
if i % 2:
odds.append((A[i], i))
else:
odds.append((B[i], i))
else:
if i % 2:
evens.append((B[i], i))
else:
evens.append((A[i], i))
SE = sorted(evens)
SO = sorted(odds)
L = [None] * N
L[::2] = SE
L[1::2] = SO
for (a, _), (b, _) in zip(L, L[1:]):
if a > b:
valid = False
break
if valid:
L = list(zip(L, list(range(N))))
L = sorted(L, key=lambda x: x[0][1])
L = [(a, c) for (a, b), c in L]
temp = 0
for i in range(N):
for j in range(i):
if L[j] > L[i]:
temp += 1
ans = min(temp, ans)
if ans == inf:
ans = -1
print(ans)
| false | 41.538462 | [
"-from itertools import permutations, combinations, chain",
"-from collections import defaultdict",
"+from itertools import chain",
"-def dpinit(ps, val=0):",
"- import copy",
"+def count_bit(x):",
"+ res = 0",
"+ while x:",
"+ res += x % 2",
"+ x >>= 1",
"+ return res",
"- res = [val for i in [0] * ps[-1]]",
"- for i in ps[:-1][::-1]:",
"- res = [copy.deepcopy(res) for k in [0] * i]",
"+",
"+def int2bin(x, N):",
"+ res = [0] * N",
"+ for i in range(N):",
"+ res[N - 1 - i] = x % 2",
"+ x >>= 1",
"-dp = [defaultdict(lambda: inf) for i in range(2**N + 1)]",
"-dp[0][0] = 0",
"+M = N // 2 # the n of odd index",
"+ans = inf",
"- c = bin(b).count(\"1\")",
"- for i in range(1, N + 1):",
"- p = N - i",
"- f = 1 << p",
"- if b & f:",
"- continue",
"- nb = b | f",
"- k = bin(b % f).count(\"1\")",
"- v = A[i - 1] if (i - c) % 2 == 1 else B[i - 1]",
"- for val, inv in list(dp[b].items()):",
"- if val <= v:",
"- dp[nb][v] = min(dp[nb][v], inv + abs(c + 1 - (i + k)))",
"-if not dp[2**N - 1]:",
"- print((-1))",
"- exit()",
"-ans = min(dp[2**N - 1].values())",
"-print((ans if ans != inf else -1))",
"+ valid = True",
"+ if count_bit(b) == M:",
"+ odd_index = int2bin(b, N) # 1 : odd",
"+ evens = []",
"+ odds = []",
"+ for i in range(N):",
"+ if odd_index[i]:",
"+ if i % 2:",
"+ odds.append((A[i], i))",
"+ else:",
"+ odds.append((B[i], i))",
"+ else:",
"+ if i % 2:",
"+ evens.append((B[i], i))",
"+ else:",
"+ evens.append((A[i], i))",
"+ SE = sorted(evens)",
"+ SO = sorted(odds)",
"+ L = [None] * N",
"+ L[::2] = SE",
"+ L[1::2] = SO",
"+ for (a, _), (b, _) in zip(L, L[1:]):",
"+ if a > b:",
"+ valid = False",
"+ break",
"+ if valid:",
"+ L = list(zip(L, list(range(N))))",
"+ L = sorted(L, key=lambda x: x[0][1])",
"+ L = [(a, c) for (a, b), c in L]",
"+ temp = 0",
"+ for i in range(N):",
"+ for j in range(i):",
"+ if L[j] > L[i]:",
"+ temp += 1",
"+ ans = min(temp, ans)",
"+if ans == inf:",
"+ ans = -1",
"+print(ans)"
] | false | 0.06911 | 0.15485 | 0.446303 | [
"s053147295",
"s565820784"
] |
u346395915 | p02954 | python | s101591432 | s993955730 | 136 | 125 | 7,260 | 6,400 | Accepted | Accepted | 8.09 | s = list(eval(input()))
ans = [0] * len(s)
cnt = 0
r_temp = 0
l_temp = 0
temp = "R"
for i in range(len(s)):
if temp != s[i] and temp == "R":
r_temp = cnt
cnt = 0
temp = "L"
if temp != s[i] and temp == "L":
l_temp = cnt
cnt = 0
temp = "R"
if (r_temp-l_temp)%2 == 0:
ans[i-l_temp] = (r_temp+l_temp)//2
ans[i-l_temp-1] = (r_temp+l_temp)//2
elif r_temp > l_temp:
if r_temp%2 == 0:
ans[i-l_temp] = ((r_temp+l_temp-1)//2)+1
ans[i-l_temp-1] = (r_temp+l_temp-1)//2
else:
ans[i-l_temp] = (r_temp+l_temp-1)//2
ans[i-l_temp-1] = ((r_temp+l_temp-1)//2)+1
elif r_temp < l_temp:
if l_temp%2 == 0:
ans[i-l_temp] = (r_temp+l_temp-1)//2
ans[i-l_temp-1] = ((r_temp+l_temp-1)//2)+1
else:
ans[i-l_temp] = ((r_temp+l_temp-1)//2)+1
ans[i-l_temp-1] = (r_temp+l_temp-1)//2
if i == len(s)-1:
l_temp = cnt + 1
#print(r_temp)
#print(cnt)
if (r_temp-l_temp)%2 == 0:
ans[i-l_temp+1] = (r_temp+l_temp)//2
ans[i-l_temp] = (r_temp+l_temp)//2
elif r_temp > l_temp:
if r_temp%2 == 0:
ans[i-l_temp+1] = ((r_temp+l_temp-1)//2)+1
ans[i-l_temp] = (r_temp+l_temp-1)//2
else:
ans[i-l_temp+1] = (r_temp+l_temp-1)//2
ans[i-l_temp] = ((r_temp+l_temp-1)//2)+1
elif r_temp < l_temp:
if l_temp%2 == 0:
ans[i-l_temp+1] = (r_temp+l_temp-1)//2
ans[i-l_temp] = ((r_temp+l_temp-1)//2)+1
else:
ans[i-l_temp+1] = ((r_temp+l_temp-1)//2)+1
ans[i-l_temp] = (r_temp+l_temp-1)//2
cnt += 1
print((*ans))
| s = eval(input())
res = [0] * len(s)
cnt_r = 0
cnt_l = 0
curr = "R"
last_idx = 0
for idx, char in enumerate(s):
if curr == "R":
if char == "R":
cnt_r += 1
continue
else:
res[idx] += cnt_r // 2
res[idx - 1] += (cnt_r - cnt_r // 2)
last_idx = idx
curr = "L"
cnt_r = 0
cnt_l = 1
continue
else:
if char == "L":
cnt_l += 1
continue
else:
res[last_idx - 1] += cnt_l // 2
res[last_idx] += cnt_l - (cnt_l // 2)
curr = "R"
cnt_l = 0
cnt_r = 1
res[last_idx - 1] += cnt_l // 2
res[last_idx] += cnt_l - (cnt_l // 2)
print((*res)) | 65 | 36 | 1,991 | 780 | s = list(eval(input()))
ans = [0] * len(s)
cnt = 0
r_temp = 0
l_temp = 0
temp = "R"
for i in range(len(s)):
if temp != s[i] and temp == "R":
r_temp = cnt
cnt = 0
temp = "L"
if temp != s[i] and temp == "L":
l_temp = cnt
cnt = 0
temp = "R"
if (r_temp - l_temp) % 2 == 0:
ans[i - l_temp] = (r_temp + l_temp) // 2
ans[i - l_temp - 1] = (r_temp + l_temp) // 2
elif r_temp > l_temp:
if r_temp % 2 == 0:
ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1
ans[i - l_temp - 1] = (r_temp + l_temp - 1) // 2
else:
ans[i - l_temp] = (r_temp + l_temp - 1) // 2
ans[i - l_temp - 1] = ((r_temp + l_temp - 1) // 2) + 1
elif r_temp < l_temp:
if l_temp % 2 == 0:
ans[i - l_temp] = (r_temp + l_temp - 1) // 2
ans[i - l_temp - 1] = ((r_temp + l_temp - 1) // 2) + 1
else:
ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1
ans[i - l_temp - 1] = (r_temp + l_temp - 1) // 2
if i == len(s) - 1:
l_temp = cnt + 1
# print(r_temp)
# print(cnt)
if (r_temp - l_temp) % 2 == 0:
ans[i - l_temp + 1] = (r_temp + l_temp) // 2
ans[i - l_temp] = (r_temp + l_temp) // 2
elif r_temp > l_temp:
if r_temp % 2 == 0:
ans[i - l_temp + 1] = ((r_temp + l_temp - 1) // 2) + 1
ans[i - l_temp] = (r_temp + l_temp - 1) // 2
else:
ans[i - l_temp + 1] = (r_temp + l_temp - 1) // 2
ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1
elif r_temp < l_temp:
if l_temp % 2 == 0:
ans[i - l_temp + 1] = (r_temp + l_temp - 1) // 2
ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1
else:
ans[i - l_temp + 1] = ((r_temp + l_temp - 1) // 2) + 1
ans[i - l_temp] = (r_temp + l_temp - 1) // 2
cnt += 1
print((*ans))
| s = eval(input())
res = [0] * len(s)
cnt_r = 0
cnt_l = 0
curr = "R"
last_idx = 0
for idx, char in enumerate(s):
if curr == "R":
if char == "R":
cnt_r += 1
continue
else:
res[idx] += cnt_r // 2
res[idx - 1] += cnt_r - cnt_r // 2
last_idx = idx
curr = "L"
cnt_r = 0
cnt_l = 1
continue
else:
if char == "L":
cnt_l += 1
continue
else:
res[last_idx - 1] += cnt_l // 2
res[last_idx] += cnt_l - (cnt_l // 2)
curr = "R"
cnt_l = 0
cnt_r = 1
res[last_idx - 1] += cnt_l // 2
res[last_idx] += cnt_l - (cnt_l // 2)
print((*res))
| false | 44.615385 | [
"-s = list(eval(input()))",
"-ans = [0] * len(s)",
"-cnt = 0",
"-r_temp = 0",
"-l_temp = 0",
"-temp = \"R\"",
"-for i in range(len(s)):",
"- if temp != s[i] and temp == \"R\":",
"- r_temp = cnt",
"- cnt = 0",
"- temp = \"L\"",
"- if temp != s[i] and temp == \"L\":",
"- l_temp = cnt",
"- cnt = 0",
"- temp = \"R\"",
"- if (r_temp - l_temp) % 2 == 0:",
"- ans[i - l_temp] = (r_temp + l_temp) // 2",
"- ans[i - l_temp - 1] = (r_temp + l_temp) // 2",
"- elif r_temp > l_temp:",
"- if r_temp % 2 == 0:",
"- ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1",
"- ans[i - l_temp - 1] = (r_temp + l_temp - 1) // 2",
"- else:",
"- ans[i - l_temp] = (r_temp + l_temp - 1) // 2",
"- ans[i - l_temp - 1] = ((r_temp + l_temp - 1) // 2) + 1",
"- elif r_temp < l_temp:",
"- if l_temp % 2 == 0:",
"- ans[i - l_temp] = (r_temp + l_temp - 1) // 2",
"- ans[i - l_temp - 1] = ((r_temp + l_temp - 1) // 2) + 1",
"- else:",
"- ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1",
"- ans[i - l_temp - 1] = (r_temp + l_temp - 1) // 2",
"- if i == len(s) - 1:",
"- l_temp = cnt + 1",
"- # print(r_temp)",
"- # print(cnt)",
"- if (r_temp - l_temp) % 2 == 0:",
"- ans[i - l_temp + 1] = (r_temp + l_temp) // 2",
"- ans[i - l_temp] = (r_temp + l_temp) // 2",
"- elif r_temp > l_temp:",
"- if r_temp % 2 == 0:",
"- ans[i - l_temp + 1] = ((r_temp + l_temp - 1) // 2) + 1",
"- ans[i - l_temp] = (r_temp + l_temp - 1) // 2",
"- else:",
"- ans[i - l_temp + 1] = (r_temp + l_temp - 1) // 2",
"- ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1",
"- elif r_temp < l_temp:",
"- if l_temp % 2 == 0:",
"- ans[i - l_temp + 1] = (r_temp + l_temp - 1) // 2",
"- ans[i - l_temp] = ((r_temp + l_temp - 1) // 2) + 1",
"- else:",
"- ans[i - l_temp + 1] = ((r_temp + l_temp - 1) // 2) + 1",
"- ans[i - l_temp] = (r_temp + l_temp - 1) // 2",
"- cnt += 1",
"-print((*ans))",
"+s = eval(input())",
"+res = [0] * len(s)",
"+cnt_r = 0",
"+cnt_l = 0",
"+curr = \"R\"",
"+last_idx = 0",
"+for idx, char in enumerate(s):",
"+ if curr == \"R\":",
"+ if char == \"R\":",
"+ cnt_r += 1",
"+ continue",
"+ else:",
"+ res[idx] += cnt_r // 2",
"+ res[idx - 1] += cnt_r - cnt_r // 2",
"+ last_idx = idx",
"+ curr = \"L\"",
"+ cnt_r = 0",
"+ cnt_l = 1",
"+ continue",
"+ else:",
"+ if char == \"L\":",
"+ cnt_l += 1",
"+ continue",
"+ else:",
"+ res[last_idx - 1] += cnt_l // 2",
"+ res[last_idx] += cnt_l - (cnt_l // 2)",
"+ curr = \"R\"",
"+ cnt_l = 0",
"+ cnt_r = 1",
"+res[last_idx - 1] += cnt_l // 2",
"+res[last_idx] += cnt_l - (cnt_l // 2)",
"+print((*res))"
] | false | 0.042596 | 0.040248 | 1.05833 | [
"s101591432",
"s993955730"
] |
u579699847 | p03352 | python | s568638367 | s526399095 | 154 | 17 | 12,204 | 2,940 | Accepted | Accepted | 88.96 | import bisect,collections,copy,itertools,math,numpy,string
def I(): return int(eval(input()))
def S(): return eval(input())
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
X = I()
kouho = []
ans = 1
kouho.append(1)
for i in range(2,1000):
j = 1
while i**j<=1000:
j += 1
if i**j<=1000:
kouho.append(i**j)
kouho.sort()
for x in kouho:
if x<=X:
ans = x
else:
break
print(ans)
| x = int(eval(input()))
kouho = [1]
for i in range(2,32):
j = 2
while i**j<=x:
kouho.append(i**j)
j += 1
print((max(kouho)))
| 23 | 8 | 533 | 147 | import bisect, collections, copy, itertools, math, numpy, string
def I():
return int(eval(input()))
def S():
return eval(input())
def LI():
return list(map(int, input().split()))
def LS():
return list(input().split())
##################################################
X = I()
kouho = []
ans = 1
kouho.append(1)
for i in range(2, 1000):
j = 1
while i**j <= 1000:
j += 1
if i**j <= 1000:
kouho.append(i**j)
kouho.sort()
for x in kouho:
if x <= X:
ans = x
else:
break
print(ans)
| x = int(eval(input()))
kouho = [1]
for i in range(2, 32):
j = 2
while i**j <= x:
kouho.append(i**j)
j += 1
print((max(kouho)))
| false | 65.217391 | [
"-import bisect, collections, copy, itertools, math, numpy, string",
"-",
"-",
"-def I():",
"- return int(eval(input()))",
"-",
"-",
"-def S():",
"- return eval(input())",
"-",
"-",
"-def LI():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def LS():",
"- return list(input().split())",
"-",
"-",
"-##################################################",
"-X = I()",
"-kouho = []",
"-ans = 1",
"-kouho.append(1)",
"-for i in range(2, 1000):",
"- j = 1",
"- while i**j <= 1000:",
"+x = int(eval(input()))",
"+kouho = [1]",
"+for i in range(2, 32):",
"+ j = 2",
"+ while i**j <= x:",
"+ kouho.append(i**j)",
"- if i**j <= 1000:",
"- kouho.append(i**j)",
"-kouho.sort()",
"-for x in kouho:",
"- if x <= X:",
"- ans = x",
"- else:",
"- break",
"-print(ans)",
"+print((max(kouho)))"
] | false | 0.041976 | 0.033908 | 1.237949 | [
"s568638367",
"s526399095"
] |
u870297120 | p02681 | python | s074895045 | s937977024 | 23 | 20 | 9,040 | 8,968 | Accepted | Accepted | 13.04 | S=eval(input())
T=eval(input())
ans='No'
if S.islower() and T.islower() and 1<=len(S)<=10 and T[0:len(S)]==S:
ans='Yes'
print(ans) | S=eval(input())
T=eval(input())
if T[0:-1]==S:
print('Yes')
else:
print('No') | 6 | 7 | 127 | 80 | S = eval(input())
T = eval(input())
ans = "No"
if S.islower() and T.islower() and 1 <= len(S) <= 10 and T[0 : len(S)] == S:
ans = "Yes"
print(ans)
| S = eval(input())
T = eval(input())
if T[0:-1] == S:
print("Yes")
else:
print("No")
| false | 14.285714 | [
"-ans = \"No\"",
"-if S.islower() and T.islower() and 1 <= len(S) <= 10 and T[0 : len(S)] == S:",
"- ans = \"Yes\"",
"-print(ans)",
"+if T[0:-1] == S:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.114224 | 0.110874 | 1.030212 | [
"s074895045",
"s937977024"
] |
u656995812 | p03062 | python | s494543028 | s610836426 | 96 | 77 | 14,412 | 14,412 | Accepted | Accepted | 19.79 | n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
minus = 0
total = 0
for i in range(n):
if a[i] == 0:
count = i
if count == 0:
while count < n:
if a[count] < 0:
minus += 1
count += 1
else:
minus = 0
if minus%2 == 0:
for i in range(n):
a[i] = abs(a[i])
total = sum(a)
else:
for i in range(n):
a[i] = abs(a[i])
total = sum(a) - min(a)*2
print(total) | n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(n):
if a[i] < 0:
count += 1
if count % 2 == 0:
for i in range(n):
a[i] = abs(a[i])
total = sum(a)
else:
for i in range(n):
a[i] = abs(a[i])
total = sum(a) - min(a)*2
print(total) | 27 | 18 | 470 | 320 | n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
minus = 0
total = 0
for i in range(n):
if a[i] == 0:
count = i
if count == 0:
while count < n:
if a[count] < 0:
minus += 1
count += 1
else:
minus = 0
if minus % 2 == 0:
for i in range(n):
a[i] = abs(a[i])
total = sum(a)
else:
for i in range(n):
a[i] = abs(a[i])
total = sum(a) - min(a) * 2
print(total)
| n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in range(n):
if a[i] < 0:
count += 1
if count % 2 == 0:
for i in range(n):
a[i] = abs(a[i])
total = sum(a)
else:
for i in range(n):
a[i] = abs(a[i])
total = sum(a) - min(a) * 2
print(total)
| false | 33.333333 | [
"-minus = 0",
"-total = 0",
"- if a[i] == 0:",
"- count = i",
"-if count == 0:",
"- while count < n:",
"- if a[count] < 0:",
"- minus += 1",
"+ if a[i] < 0:",
"-else:",
"- minus = 0",
"-if minus % 2 == 0:",
"+if count % 2 == 0:"
] | false | 0.071087 | 0.047205 | 1.505925 | [
"s494543028",
"s610836426"
] |
u887207211 | p03495 | python | s556348321 | s398279958 | 117 | 93 | 32,184 | 35,996 | Accepted | Accepted | 20.51 | N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
d = {}
for a in A:
if(a in d):
d[a] += 1
else:
d[a] = 1
print((sum(sorted(d.values())[:-K]))) | from collections import Counter
N, K = list(map(int,input().split()))
A = input().split()
a = Counter(A)
print((sum(sorted(list(a.values()), reverse = True)[K:]))) | 10 | 7 | 180 | 157 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
d = {}
for a in A:
if a in d:
d[a] += 1
else:
d[a] = 1
print((sum(sorted(d.values())[:-K])))
| from collections import Counter
N, K = list(map(int, input().split()))
A = input().split()
a = Counter(A)
print((sum(sorted(list(a.values()), reverse=True)[K:])))
| false | 30 | [
"+from collections import Counter",
"+",
"-A = list(map(int, input().split()))",
"-d = {}",
"-for a in A:",
"- if a in d:",
"- d[a] += 1",
"- else:",
"- d[a] = 1",
"-print((sum(sorted(d.values())[:-K])))",
"+A = input().split()",
"+a = Counter(A)",
"+print((sum(sorted(list(a.values()), reverse=True)[K:])))"
] | false | 0.042958 | 0.042994 | 0.999145 | [
"s556348321",
"s398279958"
] |
u340781303 | p02779 | python | s139851926 | s313489584 | 207 | 94 | 32,692 | 31,152 | Accepted | Accepted | 54.59 | n=int(eval(input()))
a=sorted(input().split())
print(('YES'if len(set(a))==n else 'NO')) | n=int(eval(input()))
a=list(map(int, input().split()))
print(('YES' if len(set(a))==n else 'NO')) | 3 | 3 | 82 | 91 | n = int(eval(input()))
a = sorted(input().split())
print(("YES" if len(set(a)) == n else "NO"))
| n = int(eval(input()))
a = list(map(int, input().split()))
print(("YES" if len(set(a)) == n else "NO"))
| false | 0 | [
"-a = sorted(input().split())",
"+a = list(map(int, input().split()))"
] | false | 0.035828 | 0.034155 | 1.048973 | [
"s139851926",
"s313489584"
] |
u816587940 | p02839 | python | s450557616 | s127362489 | 345 | 296 | 64,732 | 63,452 | Accepted | Accepted | 14.2 | import sys
def main():
input=sys.stdin.readline
h,w=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(h)]
b=[list(map(int,input().split())) for _ in range(h)]
ofset = 80*164
mask = (1 << (ofset*2)) - 1
dp=[[0 for i in range(w)] for j in range(h)]
dp[0][0] |= 1 << (a[0][0] - b[0][0] + ofset)
dp[0][0] |= 1 << (b[0][0] - a[0][0] + ofset)
for i in range(h):
for j in range(w):
if i < h - 1:
A = abs(a[i+1][j] - b[i+1][j])
dp[i+1][j] |= (dp[i][j] << A) & mask
dp[i+1][j] |= (dp[i][j] >> A) & mask
if j < w - 1:
A = abs(a[i][j+1] - b[i][j+1])
dp[i][j+1] |= (dp[i][j] << A) & mask
dp[i][j+1] |= (dp[i][j] >> A) & mask
ans = 10000000000
for i in range(ofset, 80*330):
if (dp[h-1][w-1]>>i)&1: ans = min(ans, i - ofset)
for i in range(ofset):
if (dp[h-1][w-1]>>i)&1: ans = min(ans, ofset - i)
print(ans)
if __name__=='__main__':
main()
| import sys
def main():
input=sys.stdin.readline
h,w=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(h)]
b=[list(map(int,input().split())) for _ in range(h)]
ofset = 80*164
#mask = (1 << (ofset*2)) - 1
dp=[[0 for i in range(w)] for j in range(h)]
dp[0][0] |= 1 << (a[0][0] - b[0][0] + ofset)
dp[0][0] |= 1 << (b[0][0] - a[0][0] + ofset)
for i in range(h):
for j in range(w):
if i < h - 1:
A = abs(a[i+1][j] - b[i+1][j])
dp[i+1][j] |= (dp[i][j] << A)
dp[i+1][j] |= (dp[i][j] >> A)
if j < w - 1:
A = abs(a[i][j+1] - b[i][j+1])
dp[i][j+1] |= (dp[i][j] << A)
dp[i][j+1] |= (dp[i][j] >> A)
ans = 10000000000
for i in range(ofset, 80*330):
if (dp[h-1][w-1]>>i)&1: ans = min(ans, i - ofset)
for i in range(ofset):
if (dp[h-1][w-1]>>i)&1: ans = min(ans, ofset - i)
print(ans)
if __name__=='__main__':
main()
| 29 | 29 | 1,082 | 1,055 | import sys
def main():
input = sys.stdin.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
ofset = 80 * 164
mask = (1 << (ofset * 2)) - 1
dp = [[0 for i in range(w)] for j in range(h)]
dp[0][0] |= 1 << (a[0][0] - b[0][0] + ofset)
dp[0][0] |= 1 << (b[0][0] - a[0][0] + ofset)
for i in range(h):
for j in range(w):
if i < h - 1:
A = abs(a[i + 1][j] - b[i + 1][j])
dp[i + 1][j] |= (dp[i][j] << A) & mask
dp[i + 1][j] |= (dp[i][j] >> A) & mask
if j < w - 1:
A = abs(a[i][j + 1] - b[i][j + 1])
dp[i][j + 1] |= (dp[i][j] << A) & mask
dp[i][j + 1] |= (dp[i][j] >> A) & mask
ans = 10000000000
for i in range(ofset, 80 * 330):
if (dp[h - 1][w - 1] >> i) & 1:
ans = min(ans, i - ofset)
for i in range(ofset):
if (dp[h - 1][w - 1] >> i) & 1:
ans = min(ans, ofset - i)
print(ans)
if __name__ == "__main__":
main()
| import sys
def main():
input = sys.stdin.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
ofset = 80 * 164
# mask = (1 << (ofset*2)) - 1
dp = [[0 for i in range(w)] for j in range(h)]
dp[0][0] |= 1 << (a[0][0] - b[0][0] + ofset)
dp[0][0] |= 1 << (b[0][0] - a[0][0] + ofset)
for i in range(h):
for j in range(w):
if i < h - 1:
A = abs(a[i + 1][j] - b[i + 1][j])
dp[i + 1][j] |= dp[i][j] << A
dp[i + 1][j] |= dp[i][j] >> A
if j < w - 1:
A = abs(a[i][j + 1] - b[i][j + 1])
dp[i][j + 1] |= dp[i][j] << A
dp[i][j + 1] |= dp[i][j] >> A
ans = 10000000000
for i in range(ofset, 80 * 330):
if (dp[h - 1][w - 1] >> i) & 1:
ans = min(ans, i - ofset)
for i in range(ofset):
if (dp[h - 1][w - 1] >> i) & 1:
ans = min(ans, ofset - i)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- mask = (1 << (ofset * 2)) - 1",
"+ # mask = (1 << (ofset*2)) - 1",
"- dp[i + 1][j] |= (dp[i][j] << A) & mask",
"- dp[i + 1][j] |= (dp[i][j] >> A) & mask",
"+ dp[i + 1][j] |= dp[i][j] << A",
"+ dp[i + 1][j] |= dp[i][j] >> A",
"- dp[i][j + 1] |= (dp[i][j] << A) & mask",
"- dp[i][j + 1] |= (dp[i][j] >> A) & mask",
"+ dp[i][j + 1] |= dp[i][j] << A",
"+ dp[i][j + 1] |= dp[i][j] >> A"
] | false | 0.051015 | 0.050457 | 1.011047 | [
"s450557616",
"s127362489"
] |
u312025627 | p04035 | python | s199985181 | s230811909 | 296 | 260 | 63,984 | 59,624 | Accepted | Accepted | 12.16 | def main():
N, L = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
ma = 0
idx = -1
for i in range(N-1):
if ma < A[i] + A[i+1]:
ma = A[i] + A[i+1]
idx = i+1
if ma < L:
return print("Impossible")
print("Possible")
for i in range(1, idx):
print(i)
for i in range(idx, N)[::-1]:
print(i)
if __name__ == '__main__':
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N, L = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
last = -1
for i in range(N-1):
if L <= A[i] + A[i+1]:
last = i+1
if last < 0:
return print("Impossible")
ans = [i for i in range(1, last)] + \
[i for i in range(last+1, N)][::-1] + [last]
print("Possible")
print(*ans, sep="\n")
if __name__ == '__main__':
main()
| 21 | 19 | 461 | 498 | def main():
N, L = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
ma = 0
idx = -1
for i in range(N - 1):
if ma < A[i] + A[i + 1]:
ma = A[i] + A[i + 1]
idx = i + 1
if ma < L:
return print("Impossible")
print("Possible")
for i in range(1, idx):
print(i)
for i in range(idx, N)[::-1]:
print(i)
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N, L = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
last = -1
for i in range(N - 1):
if L <= A[i] + A[i + 1]:
last = i + 1
if last < 0:
return print("Impossible")
ans = [i for i in range(1, last)] + [i for i in range(last + 1, N)][::-1] + [last]
print("Possible")
print(*ans, sep="\n")
if __name__ == "__main__":
main()
| false | 9.52381 | [
"+ import sys",
"+",
"+ input = sys.stdin.buffer.readline",
"- ma = 0",
"- idx = -1",
"+ last = -1",
"- if ma < A[i] + A[i + 1]:",
"- ma = A[i] + A[i + 1]",
"- idx = i + 1",
"- if ma < L:",
"+ if L <= A[i] + A[i + 1]:",
"+ last = i + 1",
"+ if last < 0:",
"+ ans = [i for i in range(1, last)] + [i for i in range(last + 1, N)][::-1] + [last]",
"- for i in range(1, idx):",
"- print(i)",
"- for i in range(idx, N)[::-1]:",
"- print(i)",
"+ print(*ans, sep=\"\\n\")"
] | false | 0.039866 | 0.046282 | 0.861363 | [
"s199985181",
"s230811909"
] |
u089230684 | p03547 | python | s208540072 | s959770493 | 17 | 11 | 2,940 | 2,568 | Accepted | Accepted | 35.29 | x=input().split()
if x[0] == x[1] :
print('=')
elif x[0] > x[1] :
print('>')
else :
print('<')
| temp=list(input().split())
if temp[0]>temp[1]:
print('>')
elif temp[0]<temp[1]:
print('<')
else:
print('=') | 10 | 8 | 123 | 119 | x = input().split()
if x[0] == x[1]:
print("=")
elif x[0] > x[1]:
print(">")
else:
print("<")
| temp = list(input().split())
if temp[0] > temp[1]:
print(">")
elif temp[0] < temp[1]:
print("<")
else:
print("=")
| false | 20 | [
"-x = input().split()",
"-if x[0] == x[1]:",
"+temp = list(input().split())",
"+if temp[0] > temp[1]:",
"+ print(\">\")",
"+elif temp[0] < temp[1]:",
"+ print(\"<\")",
"+else:",
"-elif x[0] > x[1]:",
"- print(\">\")",
"-else:",
"- print(\"<\")"
] | false | 0.042784 | 0.034368 | 1.24489 | [
"s208540072",
"s959770493"
] |
u850491413 | p03332 | python | s643540820 | s641642436 | 1,085 | 312 | 65,500 | 65,880 | Accepted | Accepted | 71.24 | import sys
def input():
return sys.stdin.readline().strip()
N, A, B, K = list(map(int, input().split()))
mod = 998244353
fact_list = [1]
for i in range(1, N + 1):
fact_list.append((fact_list[-1]*i) % mod)
def pow(x, y, mod=1000000007):
pow_list = [x]
i = 1
while 2**i <= y:
a = pow_list[-1]**2
if mod != 0:
a = a % mod
pow_list.append(a)
i += 1
ans = 1
for bit in range(len(pow_list)):
if (2**bit) & y != 0:
ans *= pow_list[bit]
if mod != 0:
ans = ans % mod
return ans
def fact(n, mod=1000000007):
return fact_list[n]
rev_list = [1]
for i in range(N):
rev_list.append(pow(fact(i + 1, mod), mod - 2, mod))
def mod_rev(x, mod):
"""
関数powが必要
"""
return rev_list[x]
def comb(a, b, mod=1000000007):
"""
関数mod_rev, fact, powが必要
"""
if a < b or b < 0:
return 0
a_fact = fact(a, mod)
b_fact = fact(b, mod)
a_b_fact = fact(a - b, mod)
if mod != 0:
return (a_fact * mod_rev(b, mod) * mod_rev(a - b, mod))%mod
else:
return a_fact//(b_fact*a_b_fact)
ans = 0
for r in range(N + 1):
rest = K - r * A
if rest % B == 0 and rest // B >= 0 and rest // B <= N:
b = rest // B
ans += comb(N, r, mod)*comb(N, b, mod)
ans %= mod
print(ans) |
import sys
def input():
return sys.stdin.readline().strip()
N, A, B, K = list(map(int, input().split()))
mod = 998244353
fact_list = [1]
for i in range(1, N + 1):
fact_list.append((fact_list[-1]*i) % mod)
def pow(x, y, mod=1000000007):
pow_list = [x]
i = 1
while 2**i <= y:
a = pow_list[-1]**2
if mod != 0:
a = a % mod
pow_list.append(a)
i += 1
ans = 1
for bit in range(len(pow_list)):
if (2**bit) & y != 0:
ans *= pow_list[bit]
if mod != 0:
ans = ans % mod
return ans
def fact(n, mod=1000000007):
return fact_list[n]
inv_t = [0] + [1]
for i in range(2,N + 1):
inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
def mod_rev(x, mod):
"""
関数powが必要
"""
return inv_t[x]
inv_fact = [1] + [1]
for i in range(2, N + 1):
inv_fact.append((inv_fact[-1] * inv_t[i]) % mod)
def comb(a, b, mod=1000000007):
"""
関数mod_rev, fact, powが必要
"""
if a < b or b < 0:
return 0
if a == b or b == 0:
return 1
a_fact = fact(a, mod)
b_fact = fact(b, mod)
a_b_fact = fact(a - b, mod)
if mod != 0:
return (a_fact * inv_fact[b] * inv_fact[a - b])%mod
else:
return a_fact//(b_fact*a_b_fact)
ans = 0
times = 0
for r in range(N + 1):
rest = K - r * A
if rest % B == 0 and rest // B >= 0 and rest // B <= N:
b = rest // B
ans += comb(N, r, mod)*comb(N, b, mod)
ans %= mod
times += 1
print(ans) | 66 | 76 | 1,255 | 1,418 | import sys
def input():
return sys.stdin.readline().strip()
N, A, B, K = list(map(int, input().split()))
mod = 998244353
fact_list = [1]
for i in range(1, N + 1):
fact_list.append((fact_list[-1] * i) % mod)
def pow(x, y, mod=1000000007):
pow_list = [x]
i = 1
while 2**i <= y:
a = pow_list[-1] ** 2
if mod != 0:
a = a % mod
pow_list.append(a)
i += 1
ans = 1
for bit in range(len(pow_list)):
if (2**bit) & y != 0:
ans *= pow_list[bit]
if mod != 0:
ans = ans % mod
return ans
def fact(n, mod=1000000007):
return fact_list[n]
rev_list = [1]
for i in range(N):
rev_list.append(pow(fact(i + 1, mod), mod - 2, mod))
def mod_rev(x, mod):
"""
関数powが必要
"""
return rev_list[x]
def comb(a, b, mod=1000000007):
"""
関数mod_rev, fact, powが必要
"""
if a < b or b < 0:
return 0
a_fact = fact(a, mod)
b_fact = fact(b, mod)
a_b_fact = fact(a - b, mod)
if mod != 0:
return (a_fact * mod_rev(b, mod) * mod_rev(a - b, mod)) % mod
else:
return a_fact // (b_fact * a_b_fact)
ans = 0
for r in range(N + 1):
rest = K - r * A
if rest % B == 0 and rest // B >= 0 and rest // B <= N:
b = rest // B
ans += comb(N, r, mod) * comb(N, b, mod)
ans %= mod
print(ans)
| import sys
def input():
return sys.stdin.readline().strip()
N, A, B, K = list(map(int, input().split()))
mod = 998244353
fact_list = [1]
for i in range(1, N + 1):
fact_list.append((fact_list[-1] * i) % mod)
def pow(x, y, mod=1000000007):
pow_list = [x]
i = 1
while 2**i <= y:
a = pow_list[-1] ** 2
if mod != 0:
a = a % mod
pow_list.append(a)
i += 1
ans = 1
for bit in range(len(pow_list)):
if (2**bit) & y != 0:
ans *= pow_list[bit]
if mod != 0:
ans = ans % mod
return ans
def fact(n, mod=1000000007):
return fact_list[n]
inv_t = [0] + [1]
for i in range(2, N + 1):
inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
def mod_rev(x, mod):
"""
関数powが必要
"""
return inv_t[x]
inv_fact = [1] + [1]
for i in range(2, N + 1):
inv_fact.append((inv_fact[-1] * inv_t[i]) % mod)
def comb(a, b, mod=1000000007):
"""
関数mod_rev, fact, powが必要
"""
if a < b or b < 0:
return 0
if a == b or b == 0:
return 1
a_fact = fact(a, mod)
b_fact = fact(b, mod)
a_b_fact = fact(a - b, mod)
if mod != 0:
return (a_fact * inv_fact[b] * inv_fact[a - b]) % mod
else:
return a_fact // (b_fact * a_b_fact)
ans = 0
times = 0
for r in range(N + 1):
rest = K - r * A
if rest % B == 0 and rest // B >= 0 and rest // B <= N:
b = rest // B
ans += comb(N, r, mod) * comb(N, b, mod)
ans %= mod
times += 1
print(ans)
| false | 13.157895 | [
"-rev_list = [1]",
"-for i in range(N):",
"- rev_list.append(pow(fact(i + 1, mod), mod - 2, mod))",
"+inv_t = [0] + [1]",
"+for i in range(2, N + 1):",
"+ inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]",
"- return rev_list[x]",
"+ return inv_t[x]",
"+",
"+",
"+inv_fact = [1] + [1]",
"+for i in range(2, N + 1):",
"+ inv_fact.append((inv_fact[-1] * inv_t[i]) % mod)",
"+ if a == b or b == 0:",
"+ return 1",
"- return (a_fact * mod_rev(b, mod) * mod_rev(a - b, mod)) % mod",
"+ return (a_fact * inv_fact[b] * inv_fact[a - b]) % mod",
"+times = 0",
"+ times += 1"
] | false | 0.925322 | 0.236352 | 3.915018 | [
"s643540820",
"s641642436"
] |
u108617242 | p03014 | python | s059525701 | s611796913 | 1,982 | 1,683 | 426,188 | 249,608 | Accepted | Accepted | 15.09 | H, W = list(map(int, input().split()))
S = [list(eval(input())) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]
for h in range(H):
count = 0
for w in range(W):
if '#' == S[h][w]:
count = 0
else:
count += 1
count_matw[h][w] = count
for w in range(W-1, 0, -1):
if count_matw[h][w-1] == 0:
continue
count_matw[h][w-1] = max(count_matw[h][w], count_matw[h][w-1])
for w in range(W):
count = 0
for h in range(H):
if '#' == S[h][w]:
count = 0
else:
count += 1
count_math[h][w] = count
for h in range(H-1, 0, -1):
if count_math[h-1][w] == 0:
continue
count_math[h-1][w] = max(count_math[h][w], count_math[h-1][w])
ans = 1
# for h in range(H):
# for w in range(W):
# ans = max(ans, count_math[h][w] + count_matw[h][w])
ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print((ans-1))
| H, W = list(map(int, input().split()))
S = [list(eval(input())) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]
for h in range(H):
count = 0
for w in range(W):
if '#' == S[h][w]:
count = 0
else:
count += 1
count_matw[h][w] = count
for w in range(W-1, 0, -1):
if count_matw[h][w-1] == 0:
continue
count_matw[h][w-1] = max(count_matw[h][w], count_matw[h][w-1])
for w in range(W):
count = 0
for h in range(H):
if '#' == S[h][w]:
count = 0
else:
count += 1
count_math[h][w] = count
for h in range(H-1, 0, -1):
if count_math[h-1][w] == 0:
continue
count_math[h-1][w] = max(count_math[h][w], count_math[h-1][w])
ans = 1
for h in range(H):
for w in range(W):
ans = max(ans, count_math[h][w] + count_matw[h][w])
# ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print((ans-1))
| 38 | 38 | 1,142 | 1,138 | H, W = list(map(int, input().split()))
S = [list(eval(input())) for h in range(H)]
count_matw = [[0 for w in range(W)] for h in range(H)]
count_math = [[0 for w in range(W)] for h in range(H)]
for h in range(H):
count = 0
for w in range(W):
if "#" == S[h][w]:
count = 0
else:
count += 1
count_matw[h][w] = count
for w in range(W - 1, 0, -1):
if count_matw[h][w - 1] == 0:
continue
count_matw[h][w - 1] = max(count_matw[h][w], count_matw[h][w - 1])
for w in range(W):
count = 0
for h in range(H):
if "#" == S[h][w]:
count = 0
else:
count += 1
count_math[h][w] = count
for h in range(H - 1, 0, -1):
if count_math[h - 1][w] == 0:
continue
count_math[h - 1][w] = max(count_math[h][w], count_math[h - 1][w])
ans = 1
# for h in range(H):
# for w in range(W):
# ans = max(ans, count_math[h][w] + count_matw[h][w])
ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print((ans - 1))
| H, W = list(map(int, input().split()))
S = [list(eval(input())) for h in range(H)]
count_matw = [[0 for w in range(W)] for h in range(H)]
count_math = [[0 for w in range(W)] for h in range(H)]
for h in range(H):
count = 0
for w in range(W):
if "#" == S[h][w]:
count = 0
else:
count += 1
count_matw[h][w] = count
for w in range(W - 1, 0, -1):
if count_matw[h][w - 1] == 0:
continue
count_matw[h][w - 1] = max(count_matw[h][w], count_matw[h][w - 1])
for w in range(W):
count = 0
for h in range(H):
if "#" == S[h][w]:
count = 0
else:
count += 1
count_math[h][w] = count
for h in range(H - 1, 0, -1):
if count_math[h - 1][w] == 0:
continue
count_math[h - 1][w] = max(count_math[h][w], count_math[h - 1][w])
ans = 1
for h in range(H):
for w in range(W):
ans = max(ans, count_math[h][w] + count_matw[h][w])
# ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print((ans - 1))
| false | 0 | [
"-# for h in range(H):",
"-# for w in range(W):",
"-# ans = max(ans, count_math[h][w] + count_matw[h][w])",
"-ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])",
"+for h in range(H):",
"+ for w in range(W):",
"+ ans = max(ans, count_math[h][w] + count_matw[h][w])",
"+# ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])"
] | false | 0.047379 | 0.041986 | 1.128468 | [
"s059525701",
"s611796913"
] |
u461454424 | p02630 | python | s603611625 | s723862266 | 534 | 377 | 90,316 | 29,988 | Accepted | Accepted | 29.4 | #atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
D = Counter(A)
S = sum(A)
Q = int(eval(input()))
B = [0] * Q
C = [0] * Q
for i in range(Q):
b, c = list(map(int, input().split()))
x = D[b]
y = D[c]
temp = -x * b + x * c
print((S+temp))
S += temp
D[b] = 0
D[c] += x
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main() | #atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
B = [0] * Q
C = [0] * Q
for i in range(Q):
B[i], C[i] = list(map(int, input().split()))
#output
from collections import Counter
D = Counter(A)
S = sum(A)
for i in range(Q):
x = D[B[i]]
temp = S - x*B[i] + x*C[i]
print(temp)
D[B[i]] = 0
D[C[i]] += x
S = temp
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main()
| 28 | 31 | 610 | 662 | # atcoder template
def main():
import sys
imput = sys.stdin.readline
# 文字列入力の時は上記はerrorとなる。
# ここにコード
# input
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
D = Counter(A)
S = sum(A)
Q = int(eval(input()))
B = [0] * Q
C = [0] * Q
for i in range(Q):
b, c = list(map(int, input().split()))
x = D[b]
y = D[c]
temp = -x * b + x * c
print((S + temp))
S += temp
D[b] = 0
D[c] += x
# N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main()
| # atcoder template
def main():
import sys
imput = sys.stdin.readline
# 文字列入力の時は上記はerrorとなる。
# ここにコード
# input
N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
B = [0] * Q
C = [0] * Q
for i in range(Q):
B[i], C[i] = list(map(int, input().split()))
# output
from collections import Counter
D = Counter(A)
S = sum(A)
for i in range(Q):
x = D[B[i]]
temp = S - x * B[i] + x * C[i]
print(temp)
D[B[i]] = 0
D[C[i]] += x
S = temp
# N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main()
| false | 9.677419 | [
"- from collections import Counter",
"-",
"- D = Counter(A)",
"- S = sum(A)",
"- b, c = list(map(int, input().split()))",
"- x = D[b]",
"- y = D[c]",
"- temp = -x * b + x * c",
"- print((S + temp))",
"- S += temp",
"- D[b] = 0",
"- D[c] += x",
"+ B[i], C[i] = list(map(int, input().split()))",
"+ # output",
"+ from collections import Counter",
"+",
"+ D = Counter(A)",
"+ S = sum(A)",
"+ for i in range(Q):",
"+ x = D[B[i]]",
"+ temp = S - x * B[i] + x * C[i]",
"+ print(temp)",
"+ D[B[i]] = 0",
"+ D[C[i]] += x",
"+ S = temp"
] | false | 0.04194 | 0.0346 | 1.212132 | [
"s603611625",
"s723862266"
] |
u499381410 | p03726 | python | s219393492 | s404465540 | 511 | 419 | 100,132 | 98,984 | Accepted | Accepted | 18 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
G = [[] for _ in range(n)]
for _ in range(n-1):
a,b=LI()
G[a-1]+=[b-1]
G[b - 1] += [a - 1]
def dfs(v, visited):
"""
:param v: X側の未マッチングの頂点の1つ
:param visited: 空のsetを渡す(外部からの呼び出し時)
:return: 増大路が見つかればTrue
"""
for u in G[v]:
if u in visited:
continue
visited.add(u)
if matched[u] == -1 or dfs(matched[u], visited):
matched[u] = v
return True
return False
cnt = 0
matched = [-1] * n
for i in range(n):
cnt += int(dfs(i, set()))
if cnt == n:
print("Second")
else:
print("First")
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
G = [[] for _ in range(n)]
for _ in range(n-1):
a,b=LI()
G[a-1]+=[b-1]
G[b - 1] += [a - 1]
def dfs(v, visited):
"""
:param v: X側の未マッチングの頂点の1つ
:param visited: 空のsetを渡す(外部からの呼び出し時)
:return: 増大路が見つかればTrue
"""
for u in G[v]:
if u in visited:
continue
visited.add(u)
if matched[u] == -1 or dfs(matched[u], visited):
matched[u] = v
matched[v] = u
return True
return False
cnt = 0
matched = [-1] * n
for i in range(n):
if matched[i] != -1:
continue
cnt += int(dfs(i, set())) * 2
if cnt == n:
print("Second")
else:
print("First")
| 63 | 66 | 1,656 | 1,732 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = LI()
G[a - 1] += [b - 1]
G[b - 1] += [a - 1]
def dfs(v, visited):
"""
:param v: X側の未マッチングの頂点の1つ
:param visited: 空のsetを渡す(外部からの呼び出し時)
:return: 増大路が見つかればTrue
"""
for u in G[v]:
if u in visited:
continue
visited.add(u)
if matched[u] == -1 or dfs(matched[u], visited):
matched[u] = v
return True
return False
cnt = 0
matched = [-1] * n
for i in range(n):
cnt += int(dfs(i, set()))
if cnt == n:
print("Second")
else:
print("First")
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = LI()
G[a - 1] += [b - 1]
G[b - 1] += [a - 1]
def dfs(v, visited):
"""
:param v: X側の未マッチングの頂点の1つ
:param visited: 空のsetを渡す(外部からの呼び出し時)
:return: 増大路が見つかればTrue
"""
for u in G[v]:
if u in visited:
continue
visited.add(u)
if matched[u] == -1 or dfs(matched[u], visited):
matched[u] = v
matched[v] = u
return True
return False
cnt = 0
matched = [-1] * n
for i in range(n):
if matched[i] != -1:
continue
cnt += int(dfs(i, set())) * 2
if cnt == n:
print("Second")
else:
print("First")
| false | 4.545455 | [
"+ matched[v] = u",
"- cnt += int(dfs(i, set()))",
"+ if matched[i] != -1:",
"+ continue",
"+ cnt += int(dfs(i, set())) * 2"
] | false | 0.035743 | 0.036661 | 0.974958 | [
"s219393492",
"s404465540"
] |
u537782349 | p02983 | python | s766112002 | s647061673 | 80 | 60 | 2,940 | 2,940 | Accepted | Accepted | 25 | a, b = list(map(int, input().split()))
c = a * b
for i in range(a, b+1):
for j in range(a, b+1):
if i != j:
if c > i * j % 2019:
c = i * j % 2019
if c == 0:
print((0))
exit()
print(c)
| a, b = list(map(int, input().split()))
c = 10 ** 9
for i in range(a, b+1):
for j in range(i+1, b+1):
c = min(c, i * j % 2019)
if c == 0:
print(c)
exit()
print(c)
| 11 | 10 | 270 | 210 | a, b = list(map(int, input().split()))
c = a * b
for i in range(a, b + 1):
for j in range(a, b + 1):
if i != j:
if c > i * j % 2019:
c = i * j % 2019
if c == 0:
print((0))
exit()
print(c)
| a, b = list(map(int, input().split()))
c = 10**9
for i in range(a, b + 1):
for j in range(i + 1, b + 1):
c = min(c, i * j % 2019)
if c == 0:
print(c)
exit()
print(c)
| false | 9.090909 | [
"-c = a * b",
"+c = 10**9",
"- for j in range(a, b + 1):",
"- if i != j:",
"- if c > i * j % 2019:",
"- c = i * j % 2019",
"- if c == 0:",
"- print((0))",
"- exit()",
"+ for j in range(i + 1, b + 1):",
"+ c = min(c, i * j % 2019)",
"+ if c == 0:",
"+ print(c)",
"+ exit()"
] | false | 0.042701 | 0.042727 | 0.999379 | [
"s766112002",
"s647061673"
] |
u150984829 | p00056 | python | s149268894 | s429715472 | 2,380 | 1,790 | 7,800 | 7,796 | Accepted | Accepted | 24.79 | import bisect
from itertools import *
n=list(range(50001));a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print((sum(a[x-d]>0 for d in p[:bisect.bisect(p,x//2)])))
| import bisect
from itertools import *
n=list(range(50001));a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print((sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d])))
| 6 | 6 | 238 | 240 | import bisect
from itertools import *
n = list(range(50001))
a = list(n)
a[1] = 0
for i in range(2, 224):
a[i * 2 :: i] = [0] * len(a[i * 2 :: i])
p = list(compress(n, a))
for x in iter(input, "0"):
x = int(x)
print((sum(a[x - d] > 0 for d in p[: bisect.bisect(p, x // 2)])))
| import bisect
from itertools import *
n = list(range(50001))
a = list(n)
a[1] = 0
for i in range(2, 224):
a[i * 2 :: i] = [0] * len(a[i * 2 :: i])
p = list(compress(n, a))
for x in iter(input, "0"):
x = int(x)
print((sum(1 for d in p[: bisect.bisect(p, x // 2)] if a[x - d])))
| false | 0 | [
"- print((sum(a[x - d] > 0 for d in p[: bisect.bisect(p, x // 2)])))",
"+ print((sum(1 for d in p[: bisect.bisect(p, x // 2)] if a[x - d])))"
] | false | 0.048136 | 0.103306 | 0.465954 | [
"s149268894",
"s429715472"
] |
u787456042 | p03862 | python | s341255219 | s285937151 | 112 | 95 | 14,092 | 14,092 | Accepted | Accepted | 15.18 | N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A=[min(x,a)for a in A]
for i in range(N-1):A[i+1]-=max(0,A[i]+A[i+1]-x)
print((s-sum(A))) | N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A+=0,
for i in range(N):A[i]-=max(0,A[i]+A[i-1]-x)
print((s-sum(A))) | 3 | 3 | 137 | 116 | N, x, *A = list(map(int, open(0).read().split()))
s = sum(A)
A = [min(x, a) for a in A]
for i in range(N - 1):
A[i + 1] -= max(0, A[i] + A[i + 1] - x)
print((s - sum(A)))
| N, x, *A = list(map(int, open(0).read().split()))
s = sum(A)
A += (0,)
for i in range(N):
A[i] -= max(0, A[i] + A[i - 1] - x)
print((s - sum(A)))
| false | 0 | [
"-A = [min(x, a) for a in A]",
"-for i in range(N - 1):",
"- A[i + 1] -= max(0, A[i] + A[i + 1] - x)",
"+A += (0,)",
"+for i in range(N):",
"+ A[i] -= max(0, A[i] + A[i - 1] - x)"
] | false | 0.04135 | 0.145105 | 0.284962 | [
"s341255219",
"s285937151"
] |
u422104747 | p03222 | python | s239209400 | s529769581 | 195 | 150 | 41,200 | 12,500 | Accepted | Accepted | 23.08 | l=[[] for i in range(9)]
l[1]=[""]
l[2]=["0","1"]
for i in range(3,9):
for s in l[i-1]:
l[i].append("0"+s)
if s[0]!="1":
l[i].append("1"+s)
mod=1000000007
s=input().split()
h,w,k=int(s[0]),int(s[1]),int(s[2])
dp=[[0]*(w) for i in range(h+1)]
dp[0][0]=1
for i in range(h):
for s in l[w]:
s="0"+s+"0" #どの縦棒から見ても左右が参照できるように両端に0をつけておく
for j in range(w):
if s[j]=="0" and s[j+1]=="0": #直進
dp[i+1][j]+=dp[i][j]
dp[i+1][j]%=mod
if s[j]=="0" and s[j+1]=="1": #左列に移る
dp[i+1][j+1]+=dp[i][j]
dp[i+1][j+1]%=mod
if s[j]=="1" and s[j+1]=="0": #右列に移る
dp[i+1][j-1]+=dp[i][j]
dp[i+1][j-1]%=mod
print((dp[h][k-1])) | import numpy as np
mod=1000000007
s=input().split()
h,w,k=int(s[0]),int(s[1]),int(s[2])
l=[]
for i in range(2**(w-1)):
s=bin(i)[2:].zfill(w-1)
if s.find("11")==-1:
l.append(s)
mat=np.zeros((w,w),dtype="int64")
for s in l:
dest=[i for i in range(w)]
for i in range(w-1):
if s[i]=="1":
dest[i],dest[i+1]=dest[i+1],dest[i]
for i in range(w):
mat[i][dest[i]]+=1
res=np.zeros(w,dtype="int64")
res[0]=1
for i in range(h):
res=np.dot(mat,res)
for i in range(w):
res[i]%=mod
print((res[k-1])) | 28 | 25 | 806 | 583 | l = [[] for i in range(9)]
l[1] = [""]
l[2] = ["0", "1"]
for i in range(3, 9):
for s in l[i - 1]:
l[i].append("0" + s)
if s[0] != "1":
l[i].append("1" + s)
mod = 1000000007
s = input().split()
h, w, k = int(s[0]), int(s[1]), int(s[2])
dp = [[0] * (w) for i in range(h + 1)]
dp[0][0] = 1
for i in range(h):
for s in l[w]:
s = "0" + s + "0" # どの縦棒から見ても左右が参照できるように両端に0をつけておく
for j in range(w):
if s[j] == "0" and s[j + 1] == "0": # 直進
dp[i + 1][j] += dp[i][j]
dp[i + 1][j] %= mod
if s[j] == "0" and s[j + 1] == "1": # 左列に移る
dp[i + 1][j + 1] += dp[i][j]
dp[i + 1][j + 1] %= mod
if s[j] == "1" and s[j + 1] == "0": # 右列に移る
dp[i + 1][j - 1] += dp[i][j]
dp[i + 1][j - 1] %= mod
print((dp[h][k - 1]))
| import numpy as np
mod = 1000000007
s = input().split()
h, w, k = int(s[0]), int(s[1]), int(s[2])
l = []
for i in range(2 ** (w - 1)):
s = bin(i)[2:].zfill(w - 1)
if s.find("11") == -1:
l.append(s)
mat = np.zeros((w, w), dtype="int64")
for s in l:
dest = [i for i in range(w)]
for i in range(w - 1):
if s[i] == "1":
dest[i], dest[i + 1] = dest[i + 1], dest[i]
for i in range(w):
mat[i][dest[i]] += 1
res = np.zeros(w, dtype="int64")
res[0] = 1
for i in range(h):
res = np.dot(mat, res)
for i in range(w):
res[i] %= mod
print((res[k - 1]))
| false | 10.714286 | [
"-l = [[] for i in range(9)]",
"-l[1] = [\"\"]",
"-l[2] = [\"0\", \"1\"]",
"-for i in range(3, 9):",
"- for s in l[i - 1]:",
"- l[i].append(\"0\" + s)",
"- if s[0] != \"1\":",
"- l[i].append(\"1\" + s)",
"+import numpy as np",
"+",
"-dp = [[0] * (w) for i in range(h + 1)]",
"-dp[0][0] = 1",
"+l = []",
"+for i in range(2 ** (w - 1)):",
"+ s = bin(i)[2:].zfill(w - 1)",
"+ if s.find(\"11\") == -1:",
"+ l.append(s)",
"+mat = np.zeros((w, w), dtype=\"int64\")",
"+for s in l:",
"+ dest = [i for i in range(w)]",
"+ for i in range(w - 1):",
"+ if s[i] == \"1\":",
"+ dest[i], dest[i + 1] = dest[i + 1], dest[i]",
"+ for i in range(w):",
"+ mat[i][dest[i]] += 1",
"+res = np.zeros(w, dtype=\"int64\")",
"+res[0] = 1",
"- for s in l[w]:",
"- s = \"0\" + s + \"0\" # どの縦棒から見ても左右が参照できるように両端に0をつけておく",
"- for j in range(w):",
"- if s[j] == \"0\" and s[j + 1] == \"0\": # 直進",
"- dp[i + 1][j] += dp[i][j]",
"- dp[i + 1][j] %= mod",
"- if s[j] == \"0\" and s[j + 1] == \"1\": # 左列に移る",
"- dp[i + 1][j + 1] += dp[i][j]",
"- dp[i + 1][j + 1] %= mod",
"- if s[j] == \"1\" and s[j + 1] == \"0\": # 右列に移る",
"- dp[i + 1][j - 1] += dp[i][j]",
"- dp[i + 1][j - 1] %= mod",
"-print((dp[h][k - 1]))",
"+ res = np.dot(mat, res)",
"+ for i in range(w):",
"+ res[i] %= mod",
"+print((res[k - 1]))"
] | false | 0.040377 | 0.330512 | 0.122165 | [
"s239209400",
"s529769581"
] |
u885899351 | p03309 | python | s628574206 | s986048831 | 308 | 257 | 26,708 | 26,184 | Accepted | Accepted | 16.56 | n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n):a[i]-=i+1
a.sort()
if n%2==1:
ans=0
for i in a:ans+=abs(i-a[n//2])
else:
ans,ans2=0,0
for i in a:
ans+=abs(i-a[n//2])
ans2+=abs(i-a[n//2+1])
ans=min(ans,ans2)
print(ans) | n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n):a[i]-=i+1
a.sort()
if n%2==1:
ans,j=0,a[n//2]
for i in a:ans+=abs(i-j)
else:
ans,ans2,j,k=0,0,a[n//2],a[n//2+1]
for i in a:
ans+=abs(i-j)
ans2+=abs(i-k)
ans=min(ans,ans2)
print(ans) | 14 | 14 | 284 | 296 | n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
a[i] -= i + 1
a.sort()
if n % 2 == 1:
ans = 0
for i in a:
ans += abs(i - a[n // 2])
else:
ans, ans2 = 0, 0
for i in a:
ans += abs(i - a[n // 2])
ans2 += abs(i - a[n // 2 + 1])
ans = min(ans, ans2)
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(n):
a[i] -= i + 1
a.sort()
if n % 2 == 1:
ans, j = 0, a[n // 2]
for i in a:
ans += abs(i - j)
else:
ans, ans2, j, k = 0, 0, a[n // 2], a[n // 2 + 1]
for i in a:
ans += abs(i - j)
ans2 += abs(i - k)
ans = min(ans, ans2)
print(ans)
| false | 0 | [
"- ans = 0",
"+ ans, j = 0, a[n // 2]",
"- ans += abs(i - a[n // 2])",
"+ ans += abs(i - j)",
"- ans, ans2 = 0, 0",
"+ ans, ans2, j, k = 0, 0, a[n // 2], a[n // 2 + 1]",
"- ans += abs(i - a[n // 2])",
"- ans2 += abs(i - a[n // 2 + 1])",
"+ ans += abs(i - j)",
"+ ans2 += abs(i - k)"
] | false | 0.050426 | 0.049172 | 1.025494 | [
"s628574206",
"s986048831"
] |
u197955752 | p03379 | python | s708580977 | s384906410 | 266 | 203 | 30,732 | 30,772 | Accepted | Accepted | 23.68 | N = int(eval(input()))
X = [int(x) for x in input().split()]
ind = [i for i in range(N)]
# XのindexをXが昇順になるように並び替える
ind = sorted(ind, key = lambda i : X[i])
ans = [0] * N
for i in range(N // 2):
ans[ind[i]] = X[ind[N // 2]]
for i in range(N // 2, N):
ans[ind[i]] = X[ind[N // 2 - 1]]
for i in range(N):
print((ans[i])) | N = int(eval(input()))
X = [int(x) for x in input().split()]
Y = sorted(X)
for i in range(N):
if X[i] < Y[N // 2]:
print((Y[N // 2]))
else:
print((Y[N // 2 - 1])) | 14 | 9 | 336 | 185 | N = int(eval(input()))
X = [int(x) for x in input().split()]
ind = [i for i in range(N)]
# XのindexをXが昇順になるように並び替える
ind = sorted(ind, key=lambda i: X[i])
ans = [0] * N
for i in range(N // 2):
ans[ind[i]] = X[ind[N // 2]]
for i in range(N // 2, N):
ans[ind[i]] = X[ind[N // 2 - 1]]
for i in range(N):
print((ans[i]))
| N = int(eval(input()))
X = [int(x) for x in input().split()]
Y = sorted(X)
for i in range(N):
if X[i] < Y[N // 2]:
print((Y[N // 2]))
else:
print((Y[N // 2 - 1]))
| false | 35.714286 | [
"-ind = [i for i in range(N)]",
"-# XのindexをXが昇順になるように並び替える",
"-ind = sorted(ind, key=lambda i: X[i])",
"-ans = [0] * N",
"-for i in range(N // 2):",
"- ans[ind[i]] = X[ind[N // 2]]",
"-for i in range(N // 2, N):",
"- ans[ind[i]] = X[ind[N // 2 - 1]]",
"+Y = sorted(X)",
"- print((ans[i]))",
"+ if X[i] < Y[N // 2]:",
"+ print((Y[N // 2]))",
"+ else:",
"+ print((Y[N // 2 - 1]))"
] | false | 0.04131 | 0.040465 | 1.020881 | [
"s708580977",
"s384906410"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.