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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u929569377 | p03478 | python | s731442361 | s662967413 | 37 | 29 | 3,060 | 3,060 | Accepted | Accepted | 21.62 | N, A, B = [int(x) for x in input().split()]
ans = 0
for i in range(1, N + 1):
s = str(i)
SUM = 0
for j in range(len(s)):
SUM += int(s[j])
if SUM >= A and SUM <= B:
ans += i
print(ans) | N, A, B = [int(x) for x in input().split()]
ans = 0
for i in range(1, N + 1):
SUM = 0
n = i
while n > 0:
SUM += n % 10
n = n // 10
if SUM >= A and SUM <= B:
ans += i
print(ans) | 13 | 14 | 206 | 202 | N, A, B = [int(x) for x in input().split()]
ans = 0
for i in range(1, N + 1):
s = str(i)
SUM = 0
for j in range(len(s)):
SUM += int(s[j])
if SUM >= A and SUM <= B:
ans += i
print(ans)
| N, A, B = [int(x) for x in input().split()]
ans = 0
for i in range(1, N + 1):
SUM = 0
n = i
while n > 0:
SUM += n % 10
n = n // 10
if SUM >= A and SUM <= B:
ans += i
print(ans)
| false | 7.142857 | [
"- s = str(i)",
"- for j in range(len(s)):",
"- SUM += int(s[j])",
"+ n = i",
"+ while n > 0:",
"+ SUM += n % 10",
"+ n = n // 10"
] | false | 0.048215 | 0.040474 | 1.191249 | [
"s731442361",
"s662967413"
] |
u645250356 | p03151 | python | s360659394 | s943901783 | 309 | 124 | 75,932 | 26,308 | Accepted | Accepted | 59.87 | from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
b = inpl()
dif = sum(a) - sum(b)
if dif < 0:
print((-1))
else:
m_cnt = 0
m_num = 0
p = []
for i in range(n):
if a[i] - b[i] > 0:
p.append(a[i] - b[i])
elif a[i] - b[i] < 0:
m_cnt += 1
m_num += b[i] - a[i]
cnt = 0
p.sort()
while m_num > 0:
cnt += 1
tmp = p.pop()
m_num -= tmp
print((m_cnt + cnt)) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
b = inpl()
p = []
m = 0
c = 0
for i in range(n):
if a[i] - b[i] < 0:
m += b[i]-a[i]
c += 1
elif a[i]-b[i] > 0:
p.append(a[i] - b[i])
p.sort(reverse = True)
if m > sum(p):
print((-1))
quit()
for x in p:
if m <= 0:
break
c += 1
m -= x
print(c)
| 32 | 33 | 838 | 698 | from collections import Counter, defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
b = inpl()
dif = sum(a) - sum(b)
if dif < 0:
print((-1))
else:
m_cnt = 0
m_num = 0
p = []
for i in range(n):
if a[i] - b[i] > 0:
p.append(a[i] - b[i])
elif a[i] - b[i] < 0:
m_cnt += 1
m_num += b[i] - a[i]
cnt = 0
p.sort()
while m_num > 0:
cnt += 1
tmp = p.pop()
m_num -= tmp
print((m_cnt + cnt))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
b = inpl()
p = []
m = 0
c = 0
for i in range(n):
if a[i] - b[i] < 0:
m += b[i] - a[i]
c += 1
elif a[i] - b[i] > 0:
p.append(a[i] - b[i])
p.sort(reverse=True)
if m > sum(p):
print((-1))
quit()
for x in p:
if m <= 0:
break
c += 1
m -= x
print(c)
| false | 3.030303 | [
"-import sys, heapq, bisect, math, itertools, string, queue",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())",
"-",
... | false | 0.077625 | 0.076643 | 1.012808 | [
"s360659394",
"s943901783"
] |
u569457056 | p02720 | python | s228741931 | s018466537 | 886 | 34 | 4,792 | 4,868 | Accepted | Accepted | 96.16 | def is_valid(num):
if 1 <= num < 10:
return True
ns = list(map(int, str(num)))
n = len(ns)
for i in range(n - 1):
if abs(ns[i] - ns[i + 1]) > 1:
return False
return True
lunluns = []
for i in range(1, 100000):
if is_valid(i):
lunluns.append(i)
d = {}
def dfs2(rem, pre):
if rem == 0:
return 1
key = (rem, pre)
if key in d:
return d[key]
res = 0
if pre == -1:
for i in range(10):
res += dfs2(rem - 1, -1 if i == 0 else i)
else:
for i in range(10):
if abs(i - pre) <= 1:
res += dfs2(rem - 1, i)
d[key] = res
return res
assert dfs2(1, -1) == 10
assert dfs2(1, 1) == 3
def dfs(cur, n, k, pre, buf):
if cur == n:
return k == 1
for i in range(10):
if pre == -1 or abs(i - pre) <= 1:
u = dfs2(n - cur - 1, -1 if pre == -1 and i == 0 else i)
if u < k:
k -= u
else:
buf.append(i)
assert dfs(cur + 1, n, k, -1 if pre == -1 and i == 0 else i, buf)
break
return True
def solve(k):
N = 500
res = []
assert dfs(0, N, k, -1, res)
res = res[::-1]
while res and res[-1] == 0:
res.pop()
if not res:
res = [0]
return ''.join(map(str, res[::-1]))
assert solve(3) == '2'
assert solve(1) == '0'
assert solve(2) == '1'
assert solve(4) == '3'
for i, num in enumerate(lunluns):
assert solve(i + 2) == str(num)
if __name__ == '__main__':
k = int(input())
k += 1
print(solve(k))
| # 20/05/10 cost:20min
def is_valid(num):
if 1 <= num < 10:
return True
ns = list(map(int, str(num)))
n = len(ns)
for i in range(n - 1):
if abs(ns[i] - ns[i + 1]) > 1:
return False
return True
lunluns = []
for i in range(1, 10):
if is_valid(i):
lunluns.append(i)
d = {}
def dfs2(rem, pre, lt):
if rem == 0:
return 1
key = (rem, pre, lt)
if key in d:
return d[key]
res = 0
if lt:
for i in range(10):
res += dfs2(rem - 1, i, lt and i == 0)
else:
for i in range(10):
if abs(i - pre) <= 1:
res += dfs2(rem - 1, i, False)
d[key] = res
return res
assert dfs2(1, -1, True) == 10
assert dfs2(1, 1, False) == 3
def dfs(cur, n, k, pre, lt, buf):
if cur == n:
return k == 1
for i in range(10):
if lt or abs(i - pre) <= 1:
u = dfs2(n - cur - 1, i, lt and i == 0)
if u < k:
k -= u
else:
buf.append(i)
assert dfs(cur + 1, n, k, i, lt and i == 0, buf)
break
return True
def solve(k):
N = 500
res = []
assert dfs(0, N, k, -1, True, res)
res = res[::-1]
while res and res[-1] == 0:
res.pop()
if not res:
res = [0]
return ''.join(map(str, res[::-1]))
assert solve(3) == '2'
assert solve(1) == '0'
assert solve(2) == '1'
assert solve(4) == '3'
for i, num in enumerate(lunluns):
assert solve(i + 2) == str(num)
if __name__ == '__main__':
k = int(input())
k += 1
print(solve(k))
| 76 | 78 | 1,692 | 1,700 | def is_valid(num):
if 1 <= num < 10:
return True
ns = list(map(int, str(num)))
n = len(ns)
for i in range(n - 1):
if abs(ns[i] - ns[i + 1]) > 1:
return False
return True
lunluns = []
for i in range(1, 100000):
if is_valid(i):
lunluns.append(i)
d = {}
def dfs2(rem, pre):
if rem == 0:
return 1
key = (rem, pre)
if key in d:
return d[key]
res = 0
if pre == -1:
for i in range(10):
res += dfs2(rem - 1, -1 if i == 0 else i)
else:
for i in range(10):
if abs(i - pre) <= 1:
res += dfs2(rem - 1, i)
d[key] = res
return res
assert dfs2(1, -1) == 10
assert dfs2(1, 1) == 3
def dfs(cur, n, k, pre, buf):
if cur == n:
return k == 1
for i in range(10):
if pre == -1 or abs(i - pre) <= 1:
u = dfs2(n - cur - 1, -1 if pre == -1 and i == 0 else i)
if u < k:
k -= u
else:
buf.append(i)
assert dfs(cur + 1, n, k, -1 if pre == -1 and i == 0 else i, buf)
break
return True
def solve(k):
N = 500
res = []
assert dfs(0, N, k, -1, res)
res = res[::-1]
while res and res[-1] == 0:
res.pop()
if not res:
res = [0]
return "".join(map(str, res[::-1]))
assert solve(3) == "2"
assert solve(1) == "0"
assert solve(2) == "1"
assert solve(4) == "3"
for i, num in enumerate(lunluns):
assert solve(i + 2) == str(num)
if __name__ == "__main__":
k = int(input())
k += 1
print(solve(k))
| # 20/05/10 cost:20min
def is_valid(num):
if 1 <= num < 10:
return True
ns = list(map(int, str(num)))
n = len(ns)
for i in range(n - 1):
if abs(ns[i] - ns[i + 1]) > 1:
return False
return True
lunluns = []
for i in range(1, 10):
if is_valid(i):
lunluns.append(i)
d = {}
def dfs2(rem, pre, lt):
if rem == 0:
return 1
key = (rem, pre, lt)
if key in d:
return d[key]
res = 0
if lt:
for i in range(10):
res += dfs2(rem - 1, i, lt and i == 0)
else:
for i in range(10):
if abs(i - pre) <= 1:
res += dfs2(rem - 1, i, False)
d[key] = res
return res
assert dfs2(1, -1, True) == 10
assert dfs2(1, 1, False) == 3
def dfs(cur, n, k, pre, lt, buf):
if cur == n:
return k == 1
for i in range(10):
if lt or abs(i - pre) <= 1:
u = dfs2(n - cur - 1, i, lt and i == 0)
if u < k:
k -= u
else:
buf.append(i)
assert dfs(cur + 1, n, k, i, lt and i == 0, buf)
break
return True
def solve(k):
N = 500
res = []
assert dfs(0, N, k, -1, True, res)
res = res[::-1]
while res and res[-1] == 0:
res.pop()
if not res:
res = [0]
return "".join(map(str, res[::-1]))
assert solve(3) == "2"
assert solve(1) == "0"
assert solve(2) == "1"
assert solve(4) == "3"
for i, num in enumerate(lunluns):
assert solve(i + 2) == str(num)
if __name__ == "__main__":
k = int(input())
k += 1
print(solve(k))
| false | 2.564103 | [
"+# 20/05/10 cost:20min",
"-for i in range(1, 100000):",
"+for i in range(1, 10):",
"-def dfs2(rem, pre):",
"+def dfs2(rem, pre, lt):",
"- key = (rem, pre)",
"+ key = (rem, pre, lt)",
"- if pre == -1:",
"+ if lt:",
"- res += dfs2(rem - 1, -1 if i == 0 else i)",
"+ ... | false | 0.955968 | 0.055701 | 17.162525 | [
"s228741931",
"s018466537"
] |
u600402037 | p02881 | python | s503525146 | s833909356 | 139 | 117 | 2,940 | 3,268 | Accepted | Accepted | 15.83 | N = int(eval(input()))
root = int(N ** (1/2)) + 1
num = 1
for i in range(root, 0, -1):
if N % i == 0:
num = i
break
num2 = N // num
print((num+num2-2)) | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
N = ir()
D = make_divisors(N)
answer = 10 ** 12
for d in D:
e = N // d
result = (d - 1) + (e - 1)
if result < answer:
answer = result
print(answer)
| 9 | 26 | 171 | 564 | N = int(eval(input()))
root = int(N ** (1 / 2)) + 1
num = 1
for i in range(root, 0, -1):
if N % i == 0:
num = i
break
num2 = N // num
print((num + num2 - 2))
| import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
N = ir()
D = make_divisors(N)
answer = 10**12
for d in D:
e = N // d
result = (d - 1) + (e - 1)
if result < answer:
answer = result
print(answer)
| false | 65.384615 | [
"-N = int(eval(input()))",
"-root = int(N ** (1 / 2)) + 1",
"-num = 1",
"-for i in range(root, 0, -1):",
"- if N % i == 0:",
"- num = i",
"- break",
"-num2 = N // num",
"-print((num + num2 - 2))",
"+import sys",
"+",
"+sr = lambda: sys.stdin.readline().rstrip()",
"+ir = lamb... | false | 0.073684 | 0.045576 | 1.616737 | [
"s503525146",
"s833909356"
] |
u816587940 | p02713 | python | s050721066 | s991933972 | 125 | 65 | 67,764 | 68,416 | Accepted | Accepted | 48 | from math import gcd
k = int(eval(input()))
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
t = gcd(a, b)
if t == 1:
ans += k
continue
for c in range(1, k+1): ans += gcd(t, c)
print(ans) | from math import gcd
k = int(eval(input()))
ar = [0] * 41000
for i in range(1, 201):
for j in range(1, 201): ar[i*200+j] = gcd(i, j)
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
d = ar[a*200+b]
if d == 1:
ans += k
continue
for c in range(1, k+1): ans += ar[d*200+c]
print(ans)
| 11 | 16 | 250 | 355 | from math import gcd
k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
t = gcd(a, b)
if t == 1:
ans += k
continue
for c in range(1, k + 1):
ans += gcd(t, c)
print(ans)
| from math import gcd
k = int(eval(input()))
ar = [0] * 41000
for i in range(1, 201):
for j in range(1, 201):
ar[i * 200 + j] = gcd(i, j)
ans = 0
for a in range(1, k + 1):
for b in range(1, k + 1):
d = ar[a * 200 + b]
if d == 1:
ans += k
continue
for c in range(1, k + 1):
ans += ar[d * 200 + c]
print(ans)
| false | 31.25 | [
"+ar = [0] * 41000",
"+for i in range(1, 201):",
"+ for j in range(1, 201):",
"+ ar[i * 200 + j] = gcd(i, j)",
"- t = gcd(a, b)",
"- if t == 1:",
"+ d = ar[a * 200 + b]",
"+ if d == 1:",
"- ans += gcd(t, c)",
"+ ans += ar[d * 200 + c]"
] | false | 0.090338 | 0.090618 | 0.996903 | [
"s050721066",
"s991933972"
] |
u844646164 | p03436 | python | s480773989 | s964765660 | 200 | 80 | 40,816 | 74,364 | Accepted | Accepted | 60 |
from collections import deque
h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
def bfs(sy, sx):
q = deque([[sy, sx]])
dist = [[float('inf')]*w for _ in range(h)]
dist[sy][sx] = 0
while q:
y, x = q.popleft()
for dy, dx in moves:
ny = y + dy
nx = x + dx
if 0 <= ny < h and 0 <= nx < w and dist[ny][nx] == float('inf') and s[ny][nx] != '#':
dist[ny][nx] = dist[y][x] + 1
q += [[ny, nx]]
return dist
d = bfs(0, 0)[h-1][w-1]
if d == float('inf'):
print((-1))
exit()
block = 0
for i in range(h):
for j in range(w):
if s[i][j] == '#':
block += 1
print((h*w-d-block-1)) |
from collections import deque
H, W = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
def bfs(sy, sx):
q = deque([[sy, sx]])
dist = [[float('inf')]*(W) for _ in range(H)]
dist[sy][sx] = 0
while q:
y, x = q.popleft()
for dy, dx in moves:
ny = y + dy
nx = x + dx
if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == '.' and dist[ny][nx] == float('inf'):
dist[ny][nx] = dist[y][x] + 1
q += [[ny, nx]]
return dist
d = bfs(0, 0)
if d[-1][-1] == float('inf'):
print((-1))
exit()
ans = H*W
for i in range(H):
for j in range(W):
if s[i][j] == '#':
ans -= 1
ans -= d[-1][-1] + 1
print(ans) | 32 | 36 | 799 | 811 | from collections import deque
h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
def bfs(sy, sx):
q = deque([[sy, sx]])
dist = [[float("inf")] * w for _ in range(h)]
dist[sy][sx] = 0
while q:
y, x = q.popleft()
for dy, dx in moves:
ny = y + dy
nx = x + dx
if (
0 <= ny < h
and 0 <= nx < w
and dist[ny][nx] == float("inf")
and s[ny][nx] != "#"
):
dist[ny][nx] = dist[y][x] + 1
q += [[ny, nx]]
return dist
d = bfs(0, 0)[h - 1][w - 1]
if d == float("inf"):
print((-1))
exit()
block = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
block += 1
print((h * w - d - block - 1))
| from collections import deque
H, W = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))
def bfs(sy, sx):
q = deque([[sy, sx]])
dist = [[float("inf")] * (W) for _ in range(H)]
dist[sy][sx] = 0
while q:
y, x = q.popleft()
for dy, dx in moves:
ny = y + dy
nx = x + dx
if (
0 <= ny < H
and 0 <= nx < W
and s[ny][nx] == "."
and dist[ny][nx] == float("inf")
):
dist[ny][nx] = dist[y][x] + 1
q += [[ny, nx]]
return dist
d = bfs(0, 0)
if d[-1][-1] == float("inf"):
print((-1))
exit()
ans = H * W
for i in range(H):
for j in range(W):
if s[i][j] == "#":
ans -= 1
ans -= d[-1][-1] + 1
print(ans)
| false | 11.111111 | [
"-h, w = list(map(int, input().split()))",
"-s = [list(eval(input())) for _ in range(h)]",
"+H, W = list(map(int, input().split()))",
"+s = [list(eval(input())) for _ in range(H)]",
"- dist = [[float(\"inf\")] * w for _ in range(h)]",
"+ dist = [[float(\"inf\")] * (W) for _ in range(H)]",
"- ... | false | 0.054502 | 0.035823 | 1.521424 | [
"s480773989",
"s964765660"
] |
u108650331 | p02695 | python | s737012424 | s043964846 | 966 | 668 | 9,192 | 23,320 | Accepted | Accepted | 30.85 | #!/usr/bin/env python3
# スペース区切りの整数の入力
from itertools import combinations_with_replacement as comb_rplc
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
#配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
for seq in comb_rplc(list(range(1, M+1)), N):
score = 0
for a, b, c, d in data:
if seq[b-1] - seq[a-1] == c:
score += d
ans = max(ans, score)
print(ans)
| #!/usr/bin/env python3
# スペース区切りの整数の入力
from collections import deque
def calc(seq):
score = 0
for a, b, c, d in data:
if seq[b-1] - seq[a-1] == c:
score += d
return score
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
#配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
que = deque()
for i in range(1, M+1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == N:
score = calc(seq)
ans = max(ans, score)
else:
for i in range(seq[-1], M+1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
| 21 | 37 | 440 | 672 | #!/usr/bin/env python3
# スペース区切りの整数の入力
from itertools import combinations_with_replacement as comb_rplc
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
# 配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
for seq in comb_rplc(list(range(1, M + 1)), N):
score = 0
for a, b, c, d in data:
if seq[b - 1] - seq[a - 1] == c:
score += d
ans = max(ans, score)
print(ans)
| #!/usr/bin/env python3
# スペース区切りの整数の入力
from collections import deque
def calc(seq):
score = 0
for a, b, c, d in data:
if seq[b - 1] - seq[a - 1] == c:
score += d
return score
# スペース区切りの整数の入力
N, M, Q = list(map(int, input().split()))
# 配列の入力
data = [list(map(int, input().split())) for _ in range(Q)]
ans = -1
que = deque()
for i in range(1, M + 1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == N:
score = calc(seq)
ans = max(ans, score)
else:
for i in range(seq[-1], M + 1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
| false | 43.243243 | [
"-from itertools import combinations_with_replacement as comb_rplc",
"+from collections import deque",
"+",
"+",
"+def calc(seq):",
"+ score = 0",
"+ for a, b, c, d in data:",
"+ if seq[b - 1] - seq[a - 1] == c:",
"+ score += d",
"+ return score",
"+",
"-for seq in c... | false | 0.152714 | 0.102315 | 1.492591 | [
"s737012424",
"s043964846"
] |
u970197315 | p02803 | python | s315795535 | s237141903 | 472 | 300 | 3,316 | 9,332 | Accepted | Accepted | 36.44 | from collections import deque
def bfs(sy,sx):
dist[sy][sx]=0
q=deque([[sy,sx]])
while q:
cy,cx=q.popleft()
for i,j in ([1,0],[-1,0],[0,1],[0,-1]):
ny,nx=cy+i,cx+j
if ny<0 or h-1<ny or nx<0 or w-1<nx or path[ny][nx]=='#':continue
if path[ny][nx]=='.' and dist[ny][nx]==-1:
dist[ny][nx]=dist[cy][cx]+1
q.append([ny,nx])
max_dist=-1
for i in range(h):
for j in range(w):
if path[i][j]=='#':continue
max_dist=max(max_dist,dist[i][j])
return max_dist
h,w=list(map(int,input().split()))
path=[eval(input()) for i in range(h)]
ans=0
for i in range(h):
for j in range(w):
if path[i][j]=='#':
continue
dist=[[-1]*w for i in range(h)]
t=bfs(i,j)
ans=max(ans,t)
print(ans) | from collections import deque
def bfs(sy,sx):
q=deque([[sy,sx]])
visited[sy][sx]=0
while q:
y,x=q.popleft()
for dy,dx in ([1,0],[-1,0],[0,1],[0,-1]):
ny,nx=y+dy,x+dx
if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue
if path[ny][nx]=="." and visited[ny][nx]==-1:
visited[ny][nx]=visited[y][x]+1
q.append([ny,nx])
res=-1
for i in range(h):
for j in range(w):
res=max(visited[i][j],res)
return res
h,w=list(map(int,input().split()))
path=[eval(input()) for i in range(h)]
visited=[[-1]*w for i in range(h)]
sy,sx=0,0
gy,gx=0,0
ans=0
for i in range(h):
for j in range(w):
if path[i][j]=="#":continue
sy=i
sx=j
visited=[[-1]*w for _ in range(h)]
t=bfs(sy,sx)
ans=max(t,ans)
print(ans)
| 31 | 34 | 869 | 809 | from collections import deque
def bfs(sy, sx):
dist[sy][sx] = 0
q = deque([[sy, sx]])
while q:
cy, cx = q.popleft()
for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
ny, nx = cy + i, cx + j
if ny < 0 or h - 1 < ny or nx < 0 or w - 1 < nx or path[ny][nx] == "#":
continue
if path[ny][nx] == "." and dist[ny][nx] == -1:
dist[ny][nx] = dist[cy][cx] + 1
q.append([ny, nx])
max_dist = -1
for i in range(h):
for j in range(w):
if path[i][j] == "#":
continue
max_dist = max(max_dist, dist[i][j])
return max_dist
h, w = list(map(int, input().split()))
path = [eval(input()) for i in range(h)]
ans = 0
for i in range(h):
for j in range(w):
if path[i][j] == "#":
continue
dist = [[-1] * w for i in range(h)]
t = bfs(i, j)
ans = max(ans, t)
print(ans)
| from collections import deque
def bfs(sy, sx):
q = deque([[sy, sx]])
visited[sy][sx] = 0
while q:
y, x = q.popleft()
for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
ny, nx = y + dy, x + dx
if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == "#":
continue
if path[ny][nx] == "." and visited[ny][nx] == -1:
visited[ny][nx] = visited[y][x] + 1
q.append([ny, nx])
res = -1
for i in range(h):
for j in range(w):
res = max(visited[i][j], res)
return res
h, w = list(map(int, input().split()))
path = [eval(input()) for i in range(h)]
visited = [[-1] * w for i in range(h)]
sy, sx = 0, 0
gy, gx = 0, 0
ans = 0
for i in range(h):
for j in range(w):
if path[i][j] == "#":
continue
sy = i
sx = j
visited = [[-1] * w for _ in range(h)]
t = bfs(sy, sx)
ans = max(t, ans)
print(ans)
| false | 8.823529 | [
"- dist[sy][sx] = 0",
"+ visited[sy][sx] = 0",
"- cy, cx = q.popleft()",
"- for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):",
"- ny, nx = cy + i, cx + j",
"- if ny < 0 or h - 1 < ny or nx < 0 or w - 1 < nx or path[ny][nx] == \"#\":",
"+ y, x = q.popleft()... | false | 0.142638 | 0.03774 | 3.779478 | [
"s315795535",
"s237141903"
] |
u863370423 | p03162 | python | s453395436 | s675608085 | 817 | 505 | 97,620 | 45,352 | Accepted | Accepted | 38.19 | n = int(eval(input()))
h = []
for _ in range(n):
a, b, c = [int(x) for x in input().split()]
h.append((a, b, c))
vals = {}
a, b, c = h[0]
vals[(0, 'A')] = a
vals[(0, 'B')] = b
vals[(0, 'C')] = c
for i in range(1, n):
a, b, c = h[i]
vals[(i, 'A')] = max(vals[(i-1, 'B')], vals[(i-1, 'C')]) + a
vals[(i, 'B')] = max(vals[(i-1, 'A')], vals[(i-1, 'C')]) + b
vals[(i, 'C')] = max(vals[(i-1, 'B')], vals[(i-1, 'A')]) + c
print((max(vals[(n-1, 'A')], vals[(n-1, 'B')], vals[(n-1, 'C')])))
| n = int(eval(input()))
a=[0] * (n+1)
b=[0] * (n+1)
c=[0] * (n+1)
aux = [ [0] * 5 for _ in range(n+1)]
for i in range(1,n+1):
a[i],b[i],c[i] = input().split()
a = [int(i) for i in a]
b = [int(i) for i in b]
c = [int(i) for i in c]
aux[1][1]=a[1]
aux[1][2]=b[1]
aux[1][3]=c[1]
for i in range(2,n+1):
aux[i][1]+=max(aux[i-1][2],aux[i-1][3])+a[i]
aux[i][2]+=max(aux[i-1][1],aux[i-1][3])+b[i]
aux[i][3]+=max(aux[i-1][1],aux[i-1][2])+c[i]
print((max(aux[n][1],aux[n][2],aux[n][3]))) | 19 | 25 | 519 | 515 | n = int(eval(input()))
h = []
for _ in range(n):
a, b, c = [int(x) for x in input().split()]
h.append((a, b, c))
vals = {}
a, b, c = h[0]
vals[(0, "A")] = a
vals[(0, "B")] = b
vals[(0, "C")] = c
for i in range(1, n):
a, b, c = h[i]
vals[(i, "A")] = max(vals[(i - 1, "B")], vals[(i - 1, "C")]) + a
vals[(i, "B")] = max(vals[(i - 1, "A")], vals[(i - 1, "C")]) + b
vals[(i, "C")] = max(vals[(i - 1, "B")], vals[(i - 1, "A")]) + c
print((max(vals[(n - 1, "A")], vals[(n - 1, "B")], vals[(n - 1, "C")])))
| n = int(eval(input()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
aux = [[0] * 5 for _ in range(n + 1)]
for i in range(1, n + 1):
a[i], b[i], c[i] = input().split()
a = [int(i) for i in a]
b = [int(i) for i in b]
c = [int(i) for i in c]
aux[1][1] = a[1]
aux[1][2] = b[1]
aux[1][3] = c[1]
for i in range(2, n + 1):
aux[i][1] += max(aux[i - 1][2], aux[i - 1][3]) + a[i]
aux[i][2] += max(aux[i - 1][1], aux[i - 1][3]) + b[i]
aux[i][3] += max(aux[i - 1][1], aux[i - 1][2]) + c[i]
print((max(aux[n][1], aux[n][2], aux[n][3])))
| false | 24 | [
"-h = []",
"-for _ in range(n):",
"- a, b, c = [int(x) for x in input().split()]",
"- h.append((a, b, c))",
"-vals = {}",
"-a, b, c = h[0]",
"-vals[(0, \"A\")] = a",
"-vals[(0, \"B\")] = b",
"-vals[(0, \"C\")] = c",
"-for i in range(1, n):",
"- a, b, c = h[i]",
"- vals[(i, \"A\")] ... | false | 0.046314 | 0.03697 | 1.252745 | [
"s453395436",
"s675608085"
] |
u388297793 | p02922 | python | s791979832 | s311643453 | 30 | 25 | 9,000 | 9,056 | Accepted | Accepted | 16.67 | import math
a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1))))
| a,b=list(map(int,input().split()))
ans,num=0,1
while num<b:
num-=1
num+=a
ans+=1
print(ans) | 3 | 7 | 74 | 103 | import math
a, b = list(map(int, input().split()))
print((math.ceil((b - 1) / (a - 1))))
| a, b = list(map(int, input().split()))
ans, num = 0, 1
while num < b:
num -= 1
num += a
ans += 1
print(ans)
| false | 57.142857 | [
"-import math",
"-",
"-print((math.ceil((b - 1) / (a - 1))))",
"+ans, num = 0, 1",
"+while num < b:",
"+ num -= 1",
"+ num += a",
"+ ans += 1",
"+print(ans)"
] | false | 0.049393 | 0.049023 | 1.007536 | [
"s791979832",
"s311643453"
] |
u790710233 | p03339 | python | s047706496 | s167264396 | 294 | 137 | 27,148 | 3,700 | Accepted | Accepted | 53.4 | n = int(eval(input()))
s = eval(input())
dp_L = [0]*(n+1)
dp_R = [0]*(n+1)
for i in range(n):
dp_L[i+1] = dp_L[i]+[0, 1][s[i] == 'W']
for i in reversed(list(range(n))):
dp_R[i] = dp_R[i+1]+[0, 1][s[i] == 'E']
print((min(L+R for L, R in zip(dp_L, dp_R))))
| n = int(eval(input()))
s = eval(input())
cnt_R = s.count('E')
cnt_L = 0
INF = 10**18
ans = INF
for x in s:
if x == 'W':
ans = min(ans, cnt_L+cnt_R)
cnt_L += 1
else:
cnt_R -= 1
ans = min(ans, cnt_L+cnt_R)
print(ans)
| 12 | 14 | 261 | 256 | n = int(eval(input()))
s = eval(input())
dp_L = [0] * (n + 1)
dp_R = [0] * (n + 1)
for i in range(n):
dp_L[i + 1] = dp_L[i] + [0, 1][s[i] == "W"]
for i in reversed(list(range(n))):
dp_R[i] = dp_R[i + 1] + [0, 1][s[i] == "E"]
print((min(L + R for L, R in zip(dp_L, dp_R))))
| n = int(eval(input()))
s = eval(input())
cnt_R = s.count("E")
cnt_L = 0
INF = 10**18
ans = INF
for x in s:
if x == "W":
ans = min(ans, cnt_L + cnt_R)
cnt_L += 1
else:
cnt_R -= 1
ans = min(ans, cnt_L + cnt_R)
print(ans)
| false | 14.285714 | [
"-dp_L = [0] * (n + 1)",
"-dp_R = [0] * (n + 1)",
"-for i in range(n):",
"- dp_L[i + 1] = dp_L[i] + [0, 1][s[i] == \"W\"]",
"-for i in reversed(list(range(n))):",
"- dp_R[i] = dp_R[i + 1] + [0, 1][s[i] == \"E\"]",
"-print((min(L + R for L, R in zip(dp_L, dp_R))))",
"+cnt_R = s.count(\"E\")",
"... | false | 0.041484 | 0.038857 | 1.067597 | [
"s047706496",
"s167264396"
] |
u086503932 | p03476 | python | s084451329 | s814775179 | 1,139 | 558 | 4,084 | 13,720 | Accepted | Accepted | 51.01 | #!/usr/bin/env python3
import sys
from bisect import bisect_right
def cal_prime(N):
prime_list = set()
ans_list = set()
for i in range(2, N):
flag = True
for j in range(2, int(i**0.5)+1):
if i % j == 0:
flag = False
break
if flag:
prime_list.add(i)
if i > 2 and (i+2) // 2 in prime_list:
ans_list.add(i)
return sorted(ans_list)
def main():
Q = int(eval(input()))
ans_list = cal_prime(10**5)
for i in range(Q):
l, r = list(map(int, input().split()))
print((bisect_right(ans_list, r)-bisect_right(ans_list, l-1)))
if __name__ == '__main__':
main()
| def cal_primes(N):
candidate = [*list(range(2, N+1))]
primes = []
while candidate[0]**2 <= N:
primes.append(candidate[0])
candidate = [*[x for x in candidate if x % candidate[0] != 0]]
primes.extend(candidate)
return primes
Q = int(eval(input()))
primes = set(cal_primes(10**5))
# print(primes)
res = [0] * (10**5+1)
for i in range(1,10**5+1):
#print(i)
if i%2==1 and i in primes and (i+1)//2 in primes:
res[i] = res[i-1] + 1
else:
res[i] = res[i-1]
#print(res)
for i in range(Q):
l, r = list(map(int, input().split()))
print((res[r]-res[l-1])) | 32 | 25 | 726 | 630 | #!/usr/bin/env python3
import sys
from bisect import bisect_right
def cal_prime(N):
prime_list = set()
ans_list = set()
for i in range(2, N):
flag = True
for j in range(2, int(i**0.5) + 1):
if i % j == 0:
flag = False
break
if flag:
prime_list.add(i)
if i > 2 and (i + 2) // 2 in prime_list:
ans_list.add(i)
return sorted(ans_list)
def main():
Q = int(eval(input()))
ans_list = cal_prime(10**5)
for i in range(Q):
l, r = list(map(int, input().split()))
print((bisect_right(ans_list, r) - bisect_right(ans_list, l - 1)))
if __name__ == "__main__":
main()
| def cal_primes(N):
candidate = [*list(range(2, N + 1))]
primes = []
while candidate[0] ** 2 <= N:
primes.append(candidate[0])
candidate = [*[x for x in candidate if x % candidate[0] != 0]]
primes.extend(candidate)
return primes
Q = int(eval(input()))
primes = set(cal_primes(10**5))
# print(primes)
res = [0] * (10**5 + 1)
for i in range(1, 10**5 + 1):
# print(i)
if i % 2 == 1 and i in primes and (i + 1) // 2 in primes:
res[i] = res[i - 1] + 1
else:
res[i] = res[i - 1]
# print(res)
for i in range(Q):
l, r = list(map(int, input().split()))
print((res[r] - res[l - 1]))
| false | 21.875 | [
"-#!/usr/bin/env python3",
"-import sys",
"-from bisect import bisect_right",
"+def cal_primes(N):",
"+ candidate = [*list(range(2, N + 1))]",
"+ primes = []",
"+ while candidate[0] ** 2 <= N:",
"+ primes.append(candidate[0])",
"+ candidate = [*[x for x in candidate if x % can... | false | 0.860053 | 0.245602 | 3.501815 | [
"s084451329",
"s814775179"
] |
u214617707 | p03504 | python | s176229585 | s258895521 | 821 | 751 | 135,556 | 93,400 | Accepted | Accepted | 8.53 | N, C = list(map(int, input().split()))
M = 10 ** 5 * 2 + 5
T = [[0] * M for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
s = 2 * s - 1
t = 2 * t
c -= 1
T[c][s] += 1
T[c][t] -= 1
TT = [[0] * (2 * N) for i in range(C)]
for i in range(C):
for j in range(1, M):
T[i][j] += T[i][j - 1]
num = 0
for j in range(M):
tmp = 0
for i in range(C):
if T[i][j] >= 1:
tmp += 1
num = max(tmp, num)
print(num) | N, C = list(map(int, input().split()))
M = 200005
rec = [[0] * M for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
rec[c - 1][2 * s - 1] += 1
rec[c - 1][2 * t] -= 1
for j in range(C):
for i in range(1, M):
rec[j][i] += rec[j][i - 1]
num = 0
for j in range(M):
tmp = 0
for i in range(C):
if rec[i][j] >= 1:
tmp += 1
num = max(tmp, num)
print(num)
| 25 | 22 | 505 | 445 | N, C = list(map(int, input().split()))
M = 10**5 * 2 + 5
T = [[0] * M for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
s = 2 * s - 1
t = 2 * t
c -= 1
T[c][s] += 1
T[c][t] -= 1
TT = [[0] * (2 * N) for i in range(C)]
for i in range(C):
for j in range(1, M):
T[i][j] += T[i][j - 1]
num = 0
for j in range(M):
tmp = 0
for i in range(C):
if T[i][j] >= 1:
tmp += 1
num = max(tmp, num)
print(num)
| N, C = list(map(int, input().split()))
M = 200005
rec = [[0] * M for i in range(C)]
for i in range(N):
s, t, c = list(map(int, input().split()))
rec[c - 1][2 * s - 1] += 1
rec[c - 1][2 * t] -= 1
for j in range(C):
for i in range(1, M):
rec[j][i] += rec[j][i - 1]
num = 0
for j in range(M):
tmp = 0
for i in range(C):
if rec[i][j] >= 1:
tmp += 1
num = max(tmp, num)
print(num)
| false | 12 | [
"-M = 10**5 * 2 + 5",
"-T = [[0] * M for i in range(C)]",
"+M = 200005",
"+rec = [[0] * M for i in range(C)]",
"- s = 2 * s - 1",
"- t = 2 * t",
"- c -= 1",
"- T[c][s] += 1",
"- T[c][t] -= 1",
"-TT = [[0] * (2 * N) for i in range(C)]",
"-for i in range(C):",
"- for j in range... | false | 1.446836 | 1.557574 | 0.928904 | [
"s176229585",
"s258895521"
] |
u408325839 | p03169 | python | s279419467 | s714074014 | 1,270 | 965 | 322,832 | 318,288 | Accepted | Accepted | 24.02 | import numpy as np
from numba import njit
@njit('f8(i8,i8,i8,i8,f8[:,:,:])')
def get_expv(N, i, j, k, expv):
result = 0.0
if expv[i][j][k] != -1:
return expv[i][j][k]
nonlp = 1.0 - (N-i-j-k) / N
result += 1
if i != 0:
result += get_expv(N, i-1, j, k, expv) * (i / N)
if j != 0:
result += get_expv(N, i+1, j-1, k, expv) * (j / N)
if k != 0:
result += get_expv(N, i, j+1, k-1, expv) * (k / N)
result /= nonlp
expv[i][j][k] = result
return result
def main():
N = int(eval(input()))
sushi_count = {1:0, 2:0, 3:0}
for a in map(int, input().split()):
sushi_count[a] += 1
sh = (N+1, N-sushi_count[1]+1, sushi_count[3]+1)
expv = np.full(sh, -1.0)
expv[0][0][0] = 0.0
print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))
if __name__ == '__main__':
main() | import numpy as np
from numba import njit
@njit('f8(i8,i8,i8,i8,f8[:,:,:])', cache=True)
def get_expv(N, i, j, k, expv):
result = 0.0
if expv[i][j][k] != -1:
return expv[i][j][k]
nonlp = 1.0 - (N-i-j-k) / N
result += 1
if i != 0:
result += get_expv(N, i-1, j, k, expv) * (i / N)
if j != 0:
result += get_expv(N, i+1, j-1, k, expv) * (j / N)
if k != 0:
result += get_expv(N, i, j+1, k-1, expv) * (k / N)
result /= nonlp
expv[i][j][k] = result
return result
def main():
N = int(eval(input()))
sushi_count = {1:0, 2:0, 3:0}
for a in map(int, input().split()):
sushi_count[a] += 1
sh = (N+1, N-sushi_count[1]+1, sushi_count[3]+1)
expv = np.full(sh, -1.0)
expv[0][0][0] = 0.0
print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))
if __name__ == '__main__':
main() | 36 | 36 | 913 | 932 | import numpy as np
from numba import njit
@njit("f8(i8,i8,i8,i8,f8[:,:,:])")
def get_expv(N, i, j, k, expv):
result = 0.0
if expv[i][j][k] != -1:
return expv[i][j][k]
nonlp = 1.0 - (N - i - j - k) / N
result += 1
if i != 0:
result += get_expv(N, i - 1, j, k, expv) * (i / N)
if j != 0:
result += get_expv(N, i + 1, j - 1, k, expv) * (j / N)
if k != 0:
result += get_expv(N, i, j + 1, k - 1, expv) * (k / N)
result /= nonlp
expv[i][j][k] = result
return result
def main():
N = int(eval(input()))
sushi_count = {1: 0, 2: 0, 3: 0}
for a in map(int, input().split()):
sushi_count[a] += 1
sh = (N + 1, N - sushi_count[1] + 1, sushi_count[3] + 1)
expv = np.full(sh, -1.0)
expv[0][0][0] = 0.0
print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))
if __name__ == "__main__":
main()
| import numpy as np
from numba import njit
@njit("f8(i8,i8,i8,i8,f8[:,:,:])", cache=True)
def get_expv(N, i, j, k, expv):
result = 0.0
if expv[i][j][k] != -1:
return expv[i][j][k]
nonlp = 1.0 - (N - i - j - k) / N
result += 1
if i != 0:
result += get_expv(N, i - 1, j, k, expv) * (i / N)
if j != 0:
result += get_expv(N, i + 1, j - 1, k, expv) * (j / N)
if k != 0:
result += get_expv(N, i, j + 1, k - 1, expv) * (k / N)
result /= nonlp
expv[i][j][k] = result
return result
def main():
N = int(eval(input()))
sushi_count = {1: 0, 2: 0, 3: 0}
for a in map(int, input().split()):
sushi_count[a] += 1
sh = (N + 1, N - sushi_count[1] + 1, sushi_count[3] + 1)
expv = np.full(sh, -1.0)
expv[0][0][0] = 0.0
print((get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv)))
if __name__ == "__main__":
main()
| false | 0 | [
"-@njit(\"f8(i8,i8,i8,i8,f8[:,:,:])\")",
"+@njit(\"f8(i8,i8,i8,i8,f8[:,:,:])\", cache=True)"
] | false | 0.266247 | 0.291452 | 0.91352 | [
"s279419467",
"s714074014"
] |
u492779533 | p02608 | python | s141920146 | s143499677 | 198 | 137 | 9,608 | 9,580 | Accepted | Accepted | 30.81 | num_limit = int(eval(input()))
num_list = [0] * num_limit
j_limit = int(num_limit ** 0.5)
for j in range(1,j_limit+1):
for k in range(1,j + 1):
for l in range(1,k+1):
if num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j:
if j > k:
if k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1
for i in num_list:
print(i) | num_limit = int(eval(input()))
num_list = [0] * num_limit
j_limit = int(num_limit ** 0.5)
for j in range(1,j_limit+1):
for k in range(1,j + 1):
if num_limit < j**2 + k**2 + j*k:
break
for l in range(1,k+1):
if num_limit < j**2 + k**2 + l**2 + j*k + k*l + l*j:
break
elif num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j:
if j > k:
if k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1
for i in num_list:
print(i) | 18 | 22 | 723 | 876 | num_limit = int(eval(input()))
num_list = [0] * num_limit
j_limit = int(num_limit**0.5)
for j in range(1, j_limit + 1):
for k in range(1, j + 1):
for l in range(1, k + 1):
if num_limit >= j**2 + k**2 + l**2 + j * k + k * l + l * j:
if j > k:
if k > l:
num_list[
j**2 + k**2 + l**2 + j * k + k * l + l * j - 1
] += 6
else:
num_list[
j**2 + k**2 + l**2 + j * k + k * l + l * j - 1
] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j * k + k * l + l * j - 1] += 3
else:
num_list[j**2 + k**2 + l**2 + j * k + k * l + l * j - 1] += 1
for i in num_list:
print(i)
| num_limit = int(eval(input()))
num_list = [0] * num_limit
j_limit = int(num_limit**0.5)
for j in range(1, j_limit + 1):
for k in range(1, j + 1):
if num_limit < j**2 + k**2 + j * k:
break
for l in range(1, k + 1):
if num_limit < j**2 + k**2 + l**2 + j * k + k * l + l * j:
break
elif num_limit >= j**2 + k**2 + l**2 + j * k + k * l + l * j:
if j > k:
if k > l:
num_list[
j**2 + k**2 + l**2 + j * k + k * l + l * j - 1
] += 6
else:
num_list[
j**2 + k**2 + l**2 + j * k + k * l + l * j - 1
] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j * k + k * l + l * j - 1] += 3
else:
num_list[j**2 + k**2 + l**2 + j * k + k * l + l * j - 1] += 1
for i in num_list:
print(i)
| false | 18.181818 | [
"+ if num_limit < j**2 + k**2 + j * k:",
"+ break",
"- if num_limit >= j**2 + k**2 + l**2 + j * k + k * l + l * j:",
"+ if num_limit < j**2 + k**2 + l**2 + j * k + k * l + l * j:",
"+ break",
"+ elif num_limit >= j**2 + k**2 + l**2 + j * k ... | false | 0.036595 | 0.036296 | 1.008223 | [
"s141920146",
"s143499677"
] |
u255499778 | p03062 | python | s659812528 | s219206516 | 109 | 90 | 14,284 | 14,412 | Accepted | Accepted | 17.43 | n = int(eval(input()))
a = list(map(int, input().split()))
box = []
count = 0
zero = 0
for num in range(n):
box.append(abs(a[num]))
for num in a:
if num < 0:
count += 1
elif num == 0:
zero += 1
box.sort()
if count % 2 == 0 or zero > 0:
print((sum(box)))
else:
box[0] = -box[0]
print((sum(box))) | n = int(eval(input()))
a = list(map(int, input().split()))
pbox = []
nbox = []
if 0 in a:
count = 0
for i in a:
count += abs(i)
print(count)
else:
for i in a:
if i > 0:
pbox.append(i)
else:
nbox.append(i)
if len(nbox) % 2 == 0:
count = 0
for i in a:
count += abs(i)
print(count)
else:
box = []
for i in a:
box.append(abs(i))
mi = min(box)
count = 0
for i in a:
count += abs(i)
print((count - 2*mi)) | 19 | 29 | 343 | 598 | n = int(eval(input()))
a = list(map(int, input().split()))
box = []
count = 0
zero = 0
for num in range(n):
box.append(abs(a[num]))
for num in a:
if num < 0:
count += 1
elif num == 0:
zero += 1
box.sort()
if count % 2 == 0 or zero > 0:
print((sum(box)))
else:
box[0] = -box[0]
print((sum(box)))
| n = int(eval(input()))
a = list(map(int, input().split()))
pbox = []
nbox = []
if 0 in a:
count = 0
for i in a:
count += abs(i)
print(count)
else:
for i in a:
if i > 0:
pbox.append(i)
else:
nbox.append(i)
if len(nbox) % 2 == 0:
count = 0
for i in a:
count += abs(i)
print(count)
else:
box = []
for i in a:
box.append(abs(i))
mi = min(box)
count = 0
for i in a:
count += abs(i)
print((count - 2 * mi))
| false | 34.482759 | [
"-box = []",
"-count = 0",
"-zero = 0",
"-for num in range(n):",
"- box.append(abs(a[num]))",
"-for num in a:",
"- if num < 0:",
"- count += 1",
"- elif num == 0:",
"- zero += 1",
"-box.sort()",
"-if count % 2 == 0 or zero > 0:",
"- print((sum(box)))",
"+pbox = []... | false | 0.08913 | 0.044022 | 2.024643 | [
"s659812528",
"s219206516"
] |
u202619899 | p03807 | python | s570874762 | s887414392 | 78 | 69 | 11,452 | 14,052 | Accepted | Accepted | 11.54 | N = int(input())
A = list(map(int, input().split(' ')))
cnt = 0
for a in A:
cnt += 1 if a & 1 == 1 else 0
print(('YES' if cnt % 2 == 0 else 'NO')) | import sys
N = int(eval(input()))
A = list(map(int, sys.stdin.readline().split(' ')))
cnt = 0
for a in A:
cnt += 1 if a & 1 == 1 else 0
print(('YES' if cnt % 2 == 0 else 'NO')) | 8 | 9 | 165 | 182 | N = int(input())
A = list(map(int, input().split(" ")))
cnt = 0
for a in A:
cnt += 1 if a & 1 == 1 else 0
print(("YES" if cnt % 2 == 0 else "NO"))
| import sys
N = int(eval(input()))
A = list(map(int, sys.stdin.readline().split(" ")))
cnt = 0
for a in A:
cnt += 1 if a & 1 == 1 else 0
print(("YES" if cnt % 2 == 0 else "NO"))
| false | 11.111111 | [
"-N = int(input())",
"-A = list(map(int, input().split(\" \")))",
"+import sys",
"+",
"+N = int(eval(input()))",
"+A = list(map(int, sys.stdin.readline().split(\" \")))"
] | false | 0.039698 | 0.035239 | 1.126536 | [
"s570874762",
"s887414392"
] |
u966695411 | p03238 | python | s939401669 | s616558231 | 17 | 10 | 2,940 | 2,568 | Accepted | Accepted | 41.18 | i=input;print((eval(i()+'+'+i())if'1'<i()else'Hello World')) | i=input;print(i()+i()if 1<i()else'Hello World') | 1 | 1 | 58 | 46 | i = input
print((eval(i() + "+" + i()) if "1" < i() else "Hello World"))
| i = input
print(i() + i() if 1 < i() else "Hello World")
| false | 0 | [
"-print((eval(i() + \"+\" + i()) if \"1\" < i() else \"Hello World\"))",
"+print(i() + i() if 1 < i() else \"Hello World\")"
] | false | 0.041684 | 0.120707 | 0.345331 | [
"s939401669",
"s616558231"
] |
u645119489 | p03260 | python | s232695211 | s191651025 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | A, B = list(map(int,input().split()))
#偶数×偶数=偶数、偶数×奇数=偶数、奇数×奇数=奇数。
#A*Bが偶数なら、A*B*Cが奇数となるような整数Cは無い。A*Bが奇数なら、A*B*Cが奇数となるような整数Cは無い
if A*B %2 == 0:
print("No")
if A*B %2 == 1:
print("Yes") | A, B = list(map(int,input().split()))
flg =False #flgを初期化
for C in range(1,4):
if A*B*C %2 ==1:
flg = True#flgと言う変数にTrueを代入する
break #この時点で繰り返しを中断、終了する
if flg:#(if文にはじつは、後ろに==trueが省略されているので、これだけで、flg=trueならば、、と言う意味になる)
print("Yes")
else:#(flg=true では無いならば、)
print("No")
| 10 | 13 | 198 | 317 | A, B = list(map(int, input().split()))
# 偶数×偶数=偶数、偶数×奇数=偶数、奇数×奇数=奇数。
# A*Bが偶数なら、A*B*Cが奇数となるような整数Cは無い。A*Bが奇数なら、A*B*Cが奇数となるような整数Cは無い
if A * B % 2 == 0:
print("No")
if A * B % 2 == 1:
print("Yes")
| A, B = list(map(int, input().split()))
flg = False # flgを初期化
for C in range(1, 4):
if A * B * C % 2 == 1:
flg = True # flgと言う変数にTrueを代入する
break # この時点で繰り返しを中断、終了する
if flg: # (if文にはじつは、後ろに==trueが省略されているので、これだけで、flg=trueならば、、と言う意味になる)
print("Yes")
else: # (flg=true では無いならば、)
print("No")
| false | 23.076923 | [
"-# 偶数×偶数=偶数、偶数×奇数=偶数、奇数×奇数=奇数。",
"-# A*Bが偶数なら、A*B*Cが奇数となるような整数Cは無い。A*Bが奇数なら、A*B*Cが奇数となるような整数Cは無い",
"-if A * B % 2 == 0:",
"+flg = False # flgを初期化",
"+for C in range(1, 4):",
"+ if A * B * C % 2 == 1:",
"+ flg = True # flgと言う変数にTrueを代入する",
"+ break # この時点で繰り返しを中断、終了する",
"+if flg:... | false | 0.061348 | 0.13134 | 0.467091 | [
"s232695211",
"s191651025"
] |
u461454424 | p02860 | python | s426081829 | s542564318 | 151 | 17 | 12,508 | 2,940 | Accepted | Accepted | 88.74 | import sys
input = sys.stdin.readline
#input
N = int(eval(input()))
S = str(eval(input()))
#output
import numpy as np
if N % 2 == 1:
print("No")
exit()
else:
M = int(N/2)
T = [0] * M
for i in range(M):
if S[i] == S[M+i]:
T[i] = 1
else:
continue
if np.sum(T) == M:
print("Yes")
else:
print("No") | #input
N = int(eval(input()))
S = str(eval(input()))
#output
if N % 2 == 1:
print("No")
else:
M = int(N/2)
if S[:M] == S[M:]:
print("Yes")
else:
print("No")
| 26 | 13 | 379 | 190 | import sys
input = sys.stdin.readline
# input
N = int(eval(input()))
S = str(eval(input()))
# output
import numpy as np
if N % 2 == 1:
print("No")
exit()
else:
M = int(N / 2)
T = [0] * M
for i in range(M):
if S[i] == S[M + i]:
T[i] = 1
else:
continue
if np.sum(T) == M:
print("Yes")
else:
print("No")
| # input
N = int(eval(input()))
S = str(eval(input()))
# output
if N % 2 == 1:
print("No")
else:
M = int(N / 2)
if S[:M] == S[M:]:
print("Yes")
else:
print("No")
| false | 50 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-import numpy as np",
"-",
"- exit()",
"- T = [0] * M",
"- for i in range(M):",
"- if S[i] == S[M + i]:",
"- T[i] = 1",
"- else:",
"- continue",
"-if np.sum(T) == M:",
"- print(\"Yes\")",
... | false | 0.076746 | 0.036015 | 2.130961 | [
"s426081829",
"s542564318"
] |
u912237403 | p00020 | python | s056814953 | s143285856 | 20 | 10 | 4,176 | 4,176 | Accepted | Accepted | 50 | a=input().upper()
print(a) | a=input()
print(a.upper()) | 2 | 2 | 30 | 30 | a = input().upper()
print(a)
| a = input()
print(a.upper())
| false | 0 | [
"-a = input().upper()",
"-print(a)",
"+a = input()",
"+print(a.upper())"
] | false | 0.038564 | 0.039519 | 0.975838 | [
"s056814953",
"s143285856"
] |
u820351940 | p02861 | python | s121675160 | s337210928 | 429 | 22 | 4,504 | 3,188 | Accepted | Accepted | 94.87 | import itertools
n = int(eval(input()))
route = [list(map(int, input().split())) for _ in range(n)]
results = []
for v in itertools.permutations(route, r=n):
distance = 0
for i in range(n - 1):
start, goal = v[i], v[i + 1]
distance += ((goal[0] - start[0]) ** 2 + (goal[1] - start[1]) ** 2) ** 0.5
results.append(distance)
print((sum(results) / len(results)))
| n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
def distance(i1, i2):
p1 = xy[i1]
p2 = xy[i2]
return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5
dp = [None] * (1 << n)
def dfs(state=0):
if dp[state] is not None:
return dp[state]
ans = []
s = 0
for i in range(n):
target = 1 << i
if not state & target:
res = dfs(state | target)
ans.append(i)
for v in res[0]:
s += distance(i, v)
dp[state] = ans, s
return dp[state]
print((dfs()[1] / n))
| 13 | 26 | 394 | 611 | import itertools
n = int(eval(input()))
route = [list(map(int, input().split())) for _ in range(n)]
results = []
for v in itertools.permutations(route, r=n):
distance = 0
for i in range(n - 1):
start, goal = v[i], v[i + 1]
distance += ((goal[0] - start[0]) ** 2 + (goal[1] - start[1]) ** 2) ** 0.5
results.append(distance)
print((sum(results) / len(results)))
| n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
def distance(i1, i2):
p1 = xy[i1]
p2 = xy[i2]
return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5
dp = [None] * (1 << n)
def dfs(state=0):
if dp[state] is not None:
return dp[state]
ans = []
s = 0
for i in range(n):
target = 1 << i
if not state & target:
res = dfs(state | target)
ans.append(i)
for v in res[0]:
s += distance(i, v)
dp[state] = ans, s
return dp[state]
print((dfs()[1] / n))
| false | 50 | [
"-import itertools",
"+n = int(eval(input()))",
"+xy = [list(map(int, input().split())) for _ in range(n)]",
"-n = int(eval(input()))",
"-route = [list(map(int, input().split())) for _ in range(n)]",
"-results = []",
"-for v in itertools.permutations(route, r=n):",
"- distance = 0",
"- for i i... | false | 0.041112 | 0.03901 | 1.0539 | [
"s121675160",
"s337210928"
] |
u268793453 | p03363 | python | s988293115 | s997025321 | 238 | 202 | 41,568 | 41,568 | Accepted | Accepted | 15.13 | from collections import Counter
n = int(eval(input()))
a = [int(i) for i in input().split()]
a_ = [0]
for i in range(n):
a_.append(a_[i] + a[i])
cnt = 0
def sum(i):
return int((i + 1) / 2 * i)
for i in list(Counter(a_).values()):
cnt += sum(i-1)
print(cnt) | from collections import Counter
n = int(eval(input()))
a = [int(i) for i in input().split()]
a_ = [0]
for i in range(n):
a_.append(a_[i] + a[i])
cnt = 0
def sum(i):
return i * (i-1) // 2
for i in list(Counter(a_).values()):
cnt += sum(i)
print(cnt) | 19 | 19 | 281 | 273 | from collections import Counter
n = int(eval(input()))
a = [int(i) for i in input().split()]
a_ = [0]
for i in range(n):
a_.append(a_[i] + a[i])
cnt = 0
def sum(i):
return int((i + 1) / 2 * i)
for i in list(Counter(a_).values()):
cnt += sum(i - 1)
print(cnt)
| from collections import Counter
n = int(eval(input()))
a = [int(i) for i in input().split()]
a_ = [0]
for i in range(n):
a_.append(a_[i] + a[i])
cnt = 0
def sum(i):
return i * (i - 1) // 2
for i in list(Counter(a_).values()):
cnt += sum(i)
print(cnt)
| false | 0 | [
"- return int((i + 1) / 2 * i)",
"+ return i * (i - 1) // 2",
"- cnt += sum(i - 1)",
"+ cnt += sum(i)"
] | false | 0.036366 | 0.035539 | 1.023265 | [
"s988293115",
"s997025321"
] |
u724687935 | p03241 | python | s904700451 | s815425175 | 25 | 21 | 3,444 | 3,060 | Accepted | Accepted | 16 | from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
def factorization(n):
arr = Counter()
temp = n
for i in range(2, int(-(-n**0.5 // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if len(list(arr.keys())) == 0 and n != 1:
arr[n] = 1
return arr
def dfs(i, x):
global N, M, ans
if i == len(primeKeys):
if M // x >= N:
ans = max(ans, x)
else:
for j in range(primes[primeKeys[i]] + 1):
nx = x * (primeKeys[i] ** j)
if M // nx >= N:
dfs(i + 1, nx)
else:
break
N, M = list(map(int, input().split()))
primes = factorization(M)
# primeList = list(primes.elements())
primeKeys = list(primes.keys())
ans = 1
dfs(0, 1)
print(ans)
| from math import sqrt
N, M = list(map(int, input().split()))
ans = 1
for i in range(1, int(sqrt(M)) + 1):
if M % i == 0:
j = M // i
if M / N >= j:
ans = max(ans, j)
elif M / N >= i:
ans = max(ans, i)
print(ans)
| 48 | 15 | 983 | 275 | from collections import Counter
import sys
sys.setrecursionlimit(10**6)
def factorization(n):
arr = Counter()
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if len(list(arr.keys())) == 0 and n != 1:
arr[n] = 1
return arr
def dfs(i, x):
global N, M, ans
if i == len(primeKeys):
if M // x >= N:
ans = max(ans, x)
else:
for j in range(primes[primeKeys[i]] + 1):
nx = x * (primeKeys[i] ** j)
if M // nx >= N:
dfs(i + 1, nx)
else:
break
N, M = list(map(int, input().split()))
primes = factorization(M)
# primeList = list(primes.elements())
primeKeys = list(primes.keys())
ans = 1
dfs(0, 1)
print(ans)
| from math import sqrt
N, M = list(map(int, input().split()))
ans = 1
for i in range(1, int(sqrt(M)) + 1):
if M % i == 0:
j = M // i
if M / N >= j:
ans = max(ans, j)
elif M / N >= i:
ans = max(ans, i)
print(ans)
| false | 68.75 | [
"-from collections import Counter",
"-import sys",
"-",
"-sys.setrecursionlimit(10**6)",
"-",
"-",
"-def factorization(n):",
"- arr = Counter()",
"- temp = n",
"- for i in range(2, int(-(-(n**0.5) // 1)) + 1):",
"- if temp % i == 0:",
"- cnt = 0",
"- whi... | false | 0.089917 | 0.127134 | 0.707262 | [
"s904700451",
"s815425175"
] |
u968166680 | p04013 | python | s426729495 | s636131501 | 90 | 74 | 67,220 | 67,136 | Accepted | Accepted | 17.78 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
M = sum(X)
dp = [[0] * (M + 1) for j in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(N, 0, -1):
for k in range(X[i], M + 1):
dp[j][k] += dp[j - 1][k - X[i]]
ans = 0
for j in range(1, min(N, M // A) + 1):
ans += dp[j][A * j]
print(ans)
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
X = [x - A for x in X]
base = 2500
dp = [[0] * 5001 for _ in range(N + 1)]
dp[0][base] = 1
for i in range(N):
for s in range(5001):
dp[i + 1][s] = dp[i][s]
if 0 <= s - X[i] <= 5000:
dp[i + 1][s] += dp[i][s - X[i]]
print((dp[N][base] - 1))
return
if __name__ == '__main__':
main()
| 32 | 30 | 621 | 604 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
M = sum(X)
dp = [[0] * (M + 1) for j in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(N, 0, -1):
for k in range(X[i], M + 1):
dp[j][k] += dp[j - 1][k - X[i]]
ans = 0
for j in range(1, min(N, M // A) + 1):
ans += dp[j][A * j]
print(ans)
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, A, *X = list(map(int, read().split()))
X = [x - A for x in X]
base = 2500
dp = [[0] * 5001 for _ in range(N + 1)]
dp[0][base] = 1
for i in range(N):
for s in range(5001):
dp[i + 1][s] = dp[i][s]
if 0 <= s - X[i] <= 5000:
dp[i + 1][s] += dp[i][s - X[i]]
print((dp[N][base] - 1))
return
if __name__ == "__main__":
main()
| false | 6.25 | [
"- M = sum(X)",
"- dp = [[0] * (M + 1) for j in range(N + 1)]",
"- dp[0][0] = 1",
"+ X = [x - A for x in X]",
"+ base = 2500",
"+ dp = [[0] * 5001 for _ in range(N + 1)]",
"+ dp[0][base] = 1",
"- for j in range(N, 0, -1):",
"- for k in range(X[i], M + 1):",
"... | false | 0.04093 | 0.054148 | 0.755899 | [
"s426729495",
"s636131501"
] |
u006880673 | p03160 | python | s617559935 | s451231589 | 236 | 185 | 55,400 | 13,980 | Accepted | Accepted | 21.61 | dp=[]
#iまでに要したminコスト
#dp[i] = dp[i-1]+abs(l[i]-l[i-1]) or dp[i-2]+abs(l[i+1]-l[i-1])
n = int(eval(input()))
l = list(map(int, input().split()))
dp.append(0) #dp[0]
dp.append(abs(l[1]-l[0])) #dp[1]
for i in range(2, n):
new = min(dp[i-1]+abs(l[i]-l[i-1]), dp[i-2]+abs(l[i]-l[i-2]))
dp.append(new)
ans = min((dp[n-2]+abs(l[n-2]-l[n-1])), (dp[n-3] + abs(l[n-3]-l[n-1])))
print(ans) | N = int(eval(input()))
h = [0] + list(map(int, input().split()))
dp = [10**100] * (N+2)
dp[1] = 0
for i in range(1, N):
dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
if i < N-1:
dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
print((dp[N]))
| 16 | 12 | 400 | 271 | dp = []
# iまでに要したminコスト
# dp[i] = dp[i-1]+abs(l[i]-l[i-1]) or dp[i-2]+abs(l[i+1]-l[i-1])
n = int(eval(input()))
l = list(map(int, input().split()))
dp.append(0) # dp[0]
dp.append(abs(l[1] - l[0])) # dp[1]
for i in range(2, n):
new = min(dp[i - 1] + abs(l[i] - l[i - 1]), dp[i - 2] + abs(l[i] - l[i - 2]))
dp.append(new)
ans = min(
(dp[n - 2] + abs(l[n - 2] - l[n - 1])), (dp[n - 3] + abs(l[n - 3] - l[n - 1]))
)
print(ans)
| N = int(eval(input()))
h = [0] + list(map(int, input().split()))
dp = [10**100] * (N + 2)
dp[1] = 0
for i in range(1, N):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
if i < N - 1:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print((dp[N]))
| false | 25 | [
"-dp = []",
"-# iまでに要したminコスト",
"-# dp[i] = dp[i-1]+abs(l[i]-l[i-1]) or dp[i-2]+abs(l[i+1]-l[i-1])",
"-n = int(eval(input()))",
"-l = list(map(int, input().split()))",
"-dp.append(0) # dp[0]",
"-dp.append(abs(l[1] - l[0])) # dp[1]",
"-for i in range(2, n):",
"- new = min(dp[i - 1] + abs(l[i] - ... | false | 0.036044 | 0.034071 | 1.05791 | [
"s617559935",
"s451231589"
] |
u384935968 | p03962 | python | s033179460 | s246965165 | 31 | 28 | 9,048 | 9,068 | Accepted | Accepted | 9.68 | a,b,c = list(map(int,input().split()))
if a == b == c:
print((1))
elif a == c or a == b or b == c:
print((2))
else:
print((3)) | colors = list(map(int,input().split()))
print((len(set(colors)))) | 8 | 2 | 131 | 64 | a, b, c = list(map(int, input().split()))
if a == b == c:
print((1))
elif a == c or a == b or b == c:
print((2))
else:
print((3))
| colors = list(map(int, input().split()))
print((len(set(colors))))
| false | 75 | [
"-a, b, c = list(map(int, input().split()))",
"-if a == b == c:",
"- print((1))",
"-elif a == c or a == b or b == c:",
"- print((2))",
"-else:",
"- print((3))",
"+colors = list(map(int, input().split()))",
"+print((len(set(colors))))"
] | false | 0.047997 | 0.049044 | 0.978663 | [
"s033179460",
"s246965165"
] |
u056358163 | p02574 | python | s243712037 | s813638175 | 918 | 849 | 127,756 | 127,544 | Accepted | Accepted | 7.52 | import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial ** 2, num+1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for i in range(N):
k = A[i]
while k != 1:
if D[k] in use_divnum:
pairwise_coprime = False
break
else:
use_divnum.add(D[k])
div = D[k]
while k % div == 0 and k > 1:
k = k // div
if pairwise_coprime:
print("pairwise coprime")
exit()
from math import gcd
gcd_of_a = A[0]
for i in range(N):
gcd_of_a = gcd(gcd_of_a, A[i])
if gcd_of_a == 1:
print("setwise coprime")
else:
print("not coprime")
| import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial ** 2, num+1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for i in range(N):
k = A[i]
while k != 1:
if D[k] in use_divnum:
pairwise_coprime = False
break
else:
use_divnum.add(D[k])
div = D[k]
while k % div == 0 and k > 1:
k = k // div
if pairwise_coprime:
print('pairwise coprime')
exit()
if reduce(math.gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| 45 | 43 | 1,171 | 1,090 | import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num + 1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num + 1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial**2, num + 1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for i in range(N):
k = A[i]
while k != 1:
if D[k] in use_divnum:
pairwise_coprime = False
break
else:
use_divnum.add(D[k])
div = D[k]
while k % div == 0 and k > 1:
k = k // div
if pairwise_coprime:
print("pairwise coprime")
exit()
from math import gcd
gcd_of_a = A[0]
for i in range(N):
gcd_of_a = gcd(gcd_of_a, A[i])
if gcd_of_a == 1:
print("setwise coprime")
else:
print("not coprime")
| import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num + 1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num + 1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial**2, num + 1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(eval(input()))
A = list(map(int, input().split()))
D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for i in range(N):
k = A[i]
while k != 1:
if D[k] in use_divnum:
pairwise_coprime = False
break
else:
use_divnum.add(D[k])
div = D[k]
while k % div == 0 and k > 1:
k = k // div
if pairwise_coprime:
print("pairwise coprime")
exit()
if reduce(math.gcd, A) == 1:
print("setwise coprime")
else:
print("not coprime")
| false | 4.444444 | [
"-from math import gcd",
"-",
"-gcd_of_a = A[0]",
"-for i in range(N):",
"- gcd_of_a = gcd(gcd_of_a, A[i])",
"-if gcd_of_a == 1:",
"+if reduce(math.gcd, A) == 1:"
] | false | 0.040139 | 0.041139 | 0.975694 | [
"s243712037",
"s813638175"
] |
u852690916 | p03786 | python | s052222070 | s222114804 | 247 | 107 | 60,184 | 83,816 | Accepted | Accepted | 56.68 | import sys
from operator import itemgetter
from itertools import accumulate
def main():
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
C = list(accumulate(A))
dp = [0] * N
for i in range(N-1):
if C[i] * 2 >= A[i+1]:
dp[i+1] = dp[i] + 1
print((dp[N-1]+1))
if __name__ == '__main__':
main() | # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
A.sort()
s = 0
dp = [0] * (N + 1)
for i, a in enumerate(A):
dp[i + 1] = 1
if a <= s * 2: dp[i + 1] += dp[i]
s += a
print((dp[N]))
if __name__ == '__main__':
input = sys.stdin.readline
N = int(eval(input()))
*A, = list(map(int, input().split()))
main(N, A)
| 17 | 17 | 401 | 393 | import sys
from operator import itemgetter
from itertools import accumulate
def main():
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
C = list(accumulate(A))
dp = [0] * N
for i in range(N - 1):
if C[i] * 2 >= A[i + 1]:
dp[i + 1] = dp[i] + 1
print((dp[N - 1] + 1))
if __name__ == "__main__":
main()
| # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
A.sort()
s = 0
dp = [0] * (N + 1)
for i, a in enumerate(A):
dp[i + 1] = 1
if a <= s * 2:
dp[i + 1] += dp[i]
s += a
print((dp[N]))
if __name__ == "__main__":
input = sys.stdin.readline
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
main(N, A)
| false | 0 | [
"+# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)",
"-from operator import itemgetter",
"-from itertools import accumulate",
"-def main():",
"- input = sys.stdin.readline",
"- N = int(eval(input()))",
"- A = list(map(int, input().split()))",
"+def main(N, A):",
"- C = list(accumulate(A))"... | false | 0.062849 | 0.032251 | 1.948729 | [
"s052222070",
"s222114804"
] |
u847467233 | p02447 | python | s042162931 | s608562159 | 660 | 570 | 27,616 | 19,432 | Accepted | Accepted | 13.64 | # AOJ ITP2_5_A: Sorting Pairs
# Python3 2018.6.24 bal4u
ps = []
n = int(eval(input()))
for i in range(n):
x, y = list(map(int, input().split()))
ps.append((x, y))
a = sorted(ps, key=lambda x:(x[0], x[1]))
for i in range(n): print((*a[i]))
| # AOJ ITP2_5_A: Sorting Pairs
# Python3 2018.6.24 bal4u
ps = []
n = int(eval(input()))
for i in range(n):
x, y = list(map(int, input().split()))
ps.append((x, y))
ps.sort()
for i in ps: print((*i))
| 10 | 10 | 237 | 196 | # AOJ ITP2_5_A: Sorting Pairs
# Python3 2018.6.24 bal4u
ps = []
n = int(eval(input()))
for i in range(n):
x, y = list(map(int, input().split()))
ps.append((x, y))
a = sorted(ps, key=lambda x: (x[0], x[1]))
for i in range(n):
print((*a[i]))
| # AOJ ITP2_5_A: Sorting Pairs
# Python3 2018.6.24 bal4u
ps = []
n = int(eval(input()))
for i in range(n):
x, y = list(map(int, input().split()))
ps.append((x, y))
ps.sort()
for i in ps:
print((*i))
| false | 0 | [
"-a = sorted(ps, key=lambda x: (x[0], x[1]))",
"-for i in range(n):",
"- print((*a[i]))",
"+ps.sort()",
"+for i in ps:",
"+ print((*i))"
] | false | 0.038103 | 0.042678 | 0.892795 | [
"s042162931",
"s608562159"
] |
u252828980 | p03043 | python | s213989926 | s007799318 | 59 | 52 | 6,296 | 9,184 | Accepted | Accepted | 11.86 | n,k = list(map(int,input().split()))
li = []
for i in range(1,n+1):
a=0
while i*(2**a)<k:
a+=1
li.append((1/n)*(1/2**a))
print((sum(li))) | n,k = list(map(int,input().split()))
sum1 = 0
for i in range(1,n+1):
p = 0
while True:
if (2**p)*i >= k:
break
p +=1
sum1 += 1/(n*2**p)
print(sum1) | 10 | 11 | 164 | 192 | n, k = list(map(int, input().split()))
li = []
for i in range(1, n + 1):
a = 0
while i * (2**a) < k:
a += 1
li.append((1 / n) * (1 / 2**a))
print((sum(li)))
| n, k = list(map(int, input().split()))
sum1 = 0
for i in range(1, n + 1):
p = 0
while True:
if (2**p) * i >= k:
break
p += 1
sum1 += 1 / (n * 2**p)
print(sum1)
| false | 9.090909 | [
"-li = []",
"+sum1 = 0",
"- a = 0",
"- while i * (2**a) < k:",
"- a += 1",
"- li.append((1 / n) * (1 / 2**a))",
"-print((sum(li)))",
"+ p = 0",
"+ while True:",
"+ if (2**p) * i >= k:",
"+ break",
"+ p += 1",
"+ sum1 += 1 / (n * 2**p)",
"+p... | false | 0.073368 | 0.074192 | 0.98889 | [
"s213989926",
"s007799318"
] |
u721316601 | p02973 | python | s712348275 | s688628385 | 206 | 92 | 7,836 | 7,968 | Accepted | Accepted | 55.34 | from bisect import bisect_right
def main():
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
n = [A.pop(-1)]
A.reverse()
for a in A:
if n[-1] <= a: n.append(a)
else: n[bisect_right(n, a)] = a
print((len(n)))
if __name__ == '__main__':
main() | import sys
from bisect import bisect_right
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
n = [A.pop(-1)]
A.reverse()
for a in A:
if n[-1] <= a: n.append(a)
else: n[bisect_right(n, a)] = a
print((len(n)))
if __name__ == '__main__':
main() | 16 | 19 | 319 | 357 | from bisect import bisect_right
def main():
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
n = [A.pop(-1)]
A.reverse()
for a in A:
if n[-1] <= a:
n.append(a)
else:
n[bisect_right(n, a)] = a
print((len(n)))
if __name__ == "__main__":
main()
| import sys
from bisect import bisect_right
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
n = [A.pop(-1)]
A.reverse()
for a in A:
if n[-1] <= a:
n.append(a)
else:
n[bisect_right(n, a)] = a
print((len(n)))
if __name__ == "__main__":
main()
| false | 15.789474 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"- A = [int(eval(input())) for i in range(N)]",
"+ A = [int(eval(input())) for _ in range(N)]"
] | false | 0.067941 | 0.066773 | 1.017497 | [
"s712348275",
"s688628385"
] |
u744920373 | p03229 | python | s652807130 | s775943669 | 186 | 115 | 8,336 | 8,300 | Accepted | Accepted | 38.17 | import sys
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
N = ii()
A = sorted([ii() for _ in range(N)])
'''
if N > 2:
ans += A[-1] * 2 - A[0] - A[1]
l_ind = 2
r_ind = N-2
while True:
if r_ind - 2 >= l_ind:
'''
if N==2:
print((A[1]-A[0]))
#elif N%2:
else:
'''
ans_1 = A[N-1]*2 - A[0] - A[1]
ans_1 += sum(A[N//2:N-1])*2 - sum(A[:N//2])*2 - A[N//2] - A[N//2-1]
ans_2 = A[N-1] + A[N-2] - A[0]*2
ans_2 += sum(A[N//2+1:])*2 - sum(A[1:N//2+1])*2 - A[N//2] - A[N//2+1]
print(ans_1, ans_2)
'''
ans_1 = A[N-1]*2 - A[0] - A[1]
tmp = A[0] + A[1]
l_ind = 1
r_ind = N-1
while True:
r_ind -= 2
if N%2 and l_ind > r_ind:
break
if (not N%2) and r_ind == l_ind:
ans_1 += A[r_ind+1] - A[r_ind-1]
break
ans_1 += A[r_ind] + A[r_ind+1] - tmp
tmp = A[r_ind] + A[r_ind+1]
l_ind += 2
if N%2 and l_ind > r_ind:
break
if (not N%2) and r_ind == l_ind:
ans_1 += A[r_ind+1] - A[r_ind-1]
break
ans_1 += tmp - (A[l_ind] + A[l_ind-1])
tmp = A[l_ind] + A[l_ind-1]
ans_2 = A[N-1] + A[N-2] - A[0]*2
tmp = A[N-1] + A[N-2]
l_ind = 0
r_ind = N-2
while True:
l_ind += 2
if N%2 and l_ind > r_ind:
break
if (not N%2) and r_ind == l_ind:
ans_2 += A[r_ind+1] - A[r_ind-1]
break
ans_2 += tmp - (A[l_ind] + A[l_ind-1])
tmp = A[l_ind] + A[l_ind-1]
r_ind -= 2
if N%2 and l_ind > r_ind:
break
if (not N%2) and r_ind == l_ind:
ans_2 += A[r_ind+1] - A[r_ind-1]
break
ans_2 += A[r_ind] + A[r_ind+1] - tmp
tmp = A[r_ind] + A[r_ind+1]
print((max(ans_1, ans_2))) | import sys
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
N = ii()
A = sorted([ii() for _ in range(N)])
if N % 2:
ans_1 = sum(A[N//2+1:])*2 - sum(A[:N//2+1])*2
ans_1 += A[N//2-1] + A[N//2]
ans_2 = sum(A[N//2:])*2 - sum(A[:N//2])*2
ans_2 -= A[N//2] + A[N//2+1]
print((max(ans_1, ans_2)))
else:
ans = sum(A[N//2:])*2 - sum(A[:N//2])*2
ans -= A[N//2] - A[N//2-1]
print(ans) | 76 | 23 | 2,335 | 874 | import sys
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
N = ii()
A = sorted([ii() for _ in range(N)])
"""
if N > 2:
ans += A[-1] * 2 - A[0] - A[1]
l_ind = 2
r_ind = N-2
while True:
if r_ind - 2 >= l_ind:
"""
if N == 2:
print((A[1] - A[0]))
# elif N%2:
else:
"""
ans_1 = A[N-1]*2 - A[0] - A[1]
ans_1 += sum(A[N//2:N-1])*2 - sum(A[:N//2])*2 - A[N//2] - A[N//2-1]
ans_2 = A[N-1] + A[N-2] - A[0]*2
ans_2 += sum(A[N//2+1:])*2 - sum(A[1:N//2+1])*2 - A[N//2] - A[N//2+1]
print(ans_1, ans_2)
"""
ans_1 = A[N - 1] * 2 - A[0] - A[1]
tmp = A[0] + A[1]
l_ind = 1
r_ind = N - 1
while True:
r_ind -= 2
if N % 2 and l_ind > r_ind:
break
if (not N % 2) and r_ind == l_ind:
ans_1 += A[r_ind + 1] - A[r_ind - 1]
break
ans_1 += A[r_ind] + A[r_ind + 1] - tmp
tmp = A[r_ind] + A[r_ind + 1]
l_ind += 2
if N % 2 and l_ind > r_ind:
break
if (not N % 2) and r_ind == l_ind:
ans_1 += A[r_ind + 1] - A[r_ind - 1]
break
ans_1 += tmp - (A[l_ind] + A[l_ind - 1])
tmp = A[l_ind] + A[l_ind - 1]
ans_2 = A[N - 1] + A[N - 2] - A[0] * 2
tmp = A[N - 1] + A[N - 2]
l_ind = 0
r_ind = N - 2
while True:
l_ind += 2
if N % 2 and l_ind > r_ind:
break
if (not N % 2) and r_ind == l_ind:
ans_2 += A[r_ind + 1] - A[r_ind - 1]
break
ans_2 += tmp - (A[l_ind] + A[l_ind - 1])
tmp = A[l_ind] + A[l_ind - 1]
r_ind -= 2
if N % 2 and l_ind > r_ind:
break
if (not N % 2) and r_ind == l_ind:
ans_2 += A[r_ind + 1] - A[r_ind - 1]
break
ans_2 += A[r_ind] + A[r_ind + 1] - tmp
tmp = A[r_ind] + A[r_ind + 1]
print((max(ans_1, ans_2)))
| import sys
def ii():
return int(sys.stdin.readline())
def mi():
return list(map(int, sys.stdin.readline().split()))
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
N = ii()
A = sorted([ii() for _ in range(N)])
if N % 2:
ans_1 = sum(A[N // 2 + 1 :]) * 2 - sum(A[: N // 2 + 1]) * 2
ans_1 += A[N // 2 - 1] + A[N // 2]
ans_2 = sum(A[N // 2 :]) * 2 - sum(A[: N // 2]) * 2
ans_2 -= A[N // 2] + A[N // 2 + 1]
print((max(ans_1, ans_2)))
else:
ans = sum(A[N // 2 :]) * 2 - sum(A[: N // 2]) * 2
ans -= A[N // 2] - A[N // 2 - 1]
print(ans)
| false | 69.736842 | [
"-\"\"\"",
"-if N > 2:",
"- ans += A[-1] * 2 - A[0] - A[1]",
"- l_ind = 2",
"- r_ind = N-2",
"- while True:",
"- if r_ind - 2 >= l_ind:",
"-\"\"\"",
"-if N == 2:",
"- print((A[1] - A[0]))",
"-# elif N%2:",
"+if N % 2:",
"+ ans_1 = sum(A[N // 2 + 1 :]) * 2 - sum(A[: N... | false | 0.036575 | 0.035633 | 1.02644 | [
"s652807130",
"s775943669"
] |
u903005414 | p02684 | python | s355098548 | s039252715 | 298 | 160 | 42,692 | 27,796 | Accepted | Accepted | 46.31 | from collections import deque
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
T = set([0]) # 0-indexed
c = 0 # 0-indexed
for i in range(N + 1):
c = A[c] - 1
# print('c', c)
if c not in T:
T.add(c)
else:
break
C = deque([c])
T = set([c]) # 0-indexed
for i in range(N + 1):
c = A[c] - 1
# print('c', c)
if c not in T:
T.add(c)
C.append(c)
else:
break
c2 = 0 # 0-indexed
S = deque([0])
for i in range(N + 1):
c2 = A[c2] - 1
if c2 == c:
break
else:
S.append(c2)
# print('C', C)
# print('S', S)
# print('len(C), len(S)', len(C), len(S))
if C[0] == 0:
mod = K % len(C)
ans = C[mod]
else:
if len(S) > K:
ans = S[K]
else:
mod = (K - len(S)) % len(C)
ans = C[mod]
print((ans + 1))
| import sys
input = sys.stdin.buffer.readline
N, K = list(map(int, input().split()))
A = [-1] + list(map(int, input().split()))
I = [-1] * (N + 1)
S = []
idx = 1
while I[idx] == -1:
S.append(idx)
I[idx] = len(S)
idx = A[idx]
# print(f'{S=}, {idx=}, {I[idx]=}')
start_idx = I[idx] - 1
num_circles = len(S) - start_idx
# print(f'{start_idx=}, {num_circles=}')
if K < len(S) - 1:
ans = S[K]
else:
K -= start_idx
div, mod = divmod(K, num_circles)
ans = S[start_idx + mod]
print(ans)
| 46 | 25 | 883 | 527 | from collections import deque
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
T = set([0]) # 0-indexed
c = 0 # 0-indexed
for i in range(N + 1):
c = A[c] - 1
# print('c', c)
if c not in T:
T.add(c)
else:
break
C = deque([c])
T = set([c]) # 0-indexed
for i in range(N + 1):
c = A[c] - 1
# print('c', c)
if c not in T:
T.add(c)
C.append(c)
else:
break
c2 = 0 # 0-indexed
S = deque([0])
for i in range(N + 1):
c2 = A[c2] - 1
if c2 == c:
break
else:
S.append(c2)
# print('C', C)
# print('S', S)
# print('len(C), len(S)', len(C), len(S))
if C[0] == 0:
mod = K % len(C)
ans = C[mod]
else:
if len(S) > K:
ans = S[K]
else:
mod = (K - len(S)) % len(C)
ans = C[mod]
print((ans + 1))
| import sys
input = sys.stdin.buffer.readline
N, K = list(map(int, input().split()))
A = [-1] + list(map(int, input().split()))
I = [-1] * (N + 1)
S = []
idx = 1
while I[idx] == -1:
S.append(idx)
I[idx] = len(S)
idx = A[idx]
# print(f'{S=}, {idx=}, {I[idx]=}')
start_idx = I[idx] - 1
num_circles = len(S) - start_idx
# print(f'{start_idx=}, {num_circles=}')
if K < len(S) - 1:
ans = S[K]
else:
K -= start_idx
div, mod = divmod(K, num_circles)
ans = S[start_idx + mod]
print(ans)
| false | 45.652174 | [
"-from collections import deque",
"+import sys",
"+input = sys.stdin.buffer.readline",
"-A = list(map(int, input().split()))",
"-T = set([0]) # 0-indexed",
"-c = 0 # 0-indexed",
"-for i in range(N + 1):",
"- c = A[c] - 1",
"- # print('c', c)",
"- if c not in T:",
"- T.add(c)",
... | false | 0.087738 | 0.046044 | 1.905539 | [
"s355098548",
"s039252715"
] |
u609307781 | p02678 | python | s906824413 | s036647127 | 859 | 721 | 74,520 | 76,616 | Accepted | Accepted | 16.07 | # D
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order
N, M = list(map(int, input().split()))
row = []
col = []
for i in range(M):
r, c = list(map(int, input().split()))
row.append(c-1)
col.append(r-1)
data = [1] * (M)
csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)
if -9999 in proc[1:]:
print('No')
else:
print('Yes')
print(('\n'.join((proc[1:]+1).astype('str')))) | # D
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order
N, M = list(map(int, input().split()))
ABs = np.array([list(map(int, input().split())) for i in range(M)])
row = ABs.T[0]-1
col = ABs.T[1]-1
data = [1] * (M)
csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)
if -9999 in proc[1:]:
print('No')
else:
print('Yes')
print(('\n'.join((proc[1:]+1).astype('str')))) | 25 | 21 | 526 | 503 | # D
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order
N, M = list(map(int, input().split()))
row = []
col = []
for i in range(M):
r, c = list(map(int, input().split()))
row.append(c - 1)
col.append(r - 1)
data = [1] * (M)
csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)
if -9999 in proc[1:]:
print("No")
else:
print("Yes")
print(("\n".join((proc[1:] + 1).astype("str"))))
| # D
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order
N, M = list(map(int, input().split()))
ABs = np.array([list(map(int, input().split())) for i in range(M)])
row = ABs.T[0] - 1
col = ABs.T[1] - 1
data = [1] * (M)
csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)
if -9999 in proc[1:]:
print("No")
else:
print("Yes")
print(("\n".join((proc[1:] + 1).astype("str"))))
| false | 16 | [
"-row = []",
"-col = []",
"-for i in range(M):",
"- r, c = list(map(int, input().split()))",
"- row.append(c - 1)",
"- col.append(r - 1)",
"+ABs = np.array([list(map(int, input().split())) for i in range(M)])",
"+row = ABs.T[0] - 1",
"+col = ABs.T[1] - 1"
] | false | 0.425234 | 0.677721 | 0.627447 | [
"s906824413",
"s036647127"
] |
u948524308 | p02928 | python | s108945566 | s562499257 | 1,299 | 597 | 3,316 | 9,248 | Accepted | Accepted | 54.04 | N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
L=[0]*N
R=[0]*N
for i in range(N):
for j in range(N):
if j<i and A[j]<A[i]:
L[i]+=1
if j>i and A[j]<A[i]:
R[i]+=1
ans = 0
K1=((1+K)*K//2)%(10**9+7)
K2=(K*(K-1)//2)%(10**9+7)
for i in range(N):
ans +=(R[i]*K1+L[i]*K2)%(10**9+7)
ans =ans%(10**9+7)
print((int(ans)))
| N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
B=[]
for i in range(N):
l=0
r=0
for j in range(i):
if A[i]>A[j]:
l+=1
for k in range(i,N):
if A[i]>A[k]:
r+=1
B.append([l,r])
ans=0
for i in range(N):
ans+=B[i][0]*(K-1)*K//2+B[i][1]*K*(K+1)//2
ans%=mod
print(ans) | 23 | 24 | 400 | 379 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(N):
for j in range(N):
if j < i and A[j] < A[i]:
L[i] += 1
if j > i and A[j] < A[i]:
R[i] += 1
ans = 0
K1 = ((1 + K) * K // 2) % (10**9 + 7)
K2 = (K * (K - 1) // 2) % (10**9 + 7)
for i in range(N):
ans += (R[i] * K1 + L[i] * K2) % (10**9 + 7)
ans = ans % (10**9 + 7)
print((int(ans)))
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9 + 7
B = []
for i in range(N):
l = 0
r = 0
for j in range(i):
if A[i] > A[j]:
l += 1
for k in range(i, N):
if A[i] > A[k]:
r += 1
B.append([l, r])
ans = 0
for i in range(N):
ans += B[i][0] * (K - 1) * K // 2 + B[i][1] * K * (K + 1) // 2
ans %= mod
print(ans)
| false | 4.166667 | [
"-L = [0] * N",
"-R = [0] * N",
"+mod = 10**9 + 7",
"+B = []",
"- for j in range(N):",
"- if j < i and A[j] < A[i]:",
"- L[i] += 1",
"- if j > i and A[j] < A[i]:",
"- R[i] += 1",
"+ l = 0",
"+ r = 0",
"+ for j in range(i):",
"+ if A[i] >... | false | 0.037456 | 0.042433 | 0.882713 | [
"s108945566",
"s562499257"
] |
u790710233 | p03645 | python | s046889664 | s279485787 | 833 | 639 | 37,532 | 18,992 | Accepted | Accepted | 23.29 | n, m = list(map(int, input().split()))
s = {tuple(map(int, input().split())) for _ in range(m)}
for i in range(2, n):
route = [1, i, n]
if all(edge in s for edge in zip(route, route[1:])):
print('POSSIBLE')
break
else:
print('IMPOSSIBLE')
| n, m = list(map(int, input().split()))
transit_a = set()
transit_b = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
transit_b |= {b}
elif b == n:
transit_a |= {a}
print(('POSSIBLE' if len(transit_a & transit_b) else 'IMPOSSIBLE')) | 11 | 11 | 273 | 283 | n, m = list(map(int, input().split()))
s = {tuple(map(int, input().split())) for _ in range(m)}
for i in range(2, n):
route = [1, i, n]
if all(edge in s for edge in zip(route, route[1:])):
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
| n, m = list(map(int, input().split()))
transit_a = set()
transit_b = set()
for _ in range(m):
a, b = list(map(int, input().split()))
if a == 1:
transit_b |= {b}
elif b == n:
transit_a |= {a}
print(("POSSIBLE" if len(transit_a & transit_b) else "IMPOSSIBLE"))
| false | 0 | [
"-s = {tuple(map(int, input().split())) for _ in range(m)}",
"-for i in range(2, n):",
"- route = [1, i, n]",
"- if all(edge in s for edge in zip(route, route[1:])):",
"- print(\"POSSIBLE\")",
"- break",
"-else:",
"- print(\"IMPOSSIBLE\")",
"+transit_a = set()",
"+transit_b ... | false | 0.039455 | 0.038176 | 1.033499 | [
"s046889664",
"s279485787"
] |
u576917603 | p03425 | python | s056642512 | s970264991 | 250 | 195 | 20,300 | 3,064 | Accepted | Accepted | 22 | n=int(eval(input()))
a=[list(eval(input()))for i in range(n)]
d={'M':0,"A":0,"R":0,'C':0,'H':0}
for i in a:
if i[0] in d:
d[i[0]]+=1
dl=[]
for i in list(d.values()):
dl.append(i)
ans=0
for i in range(3):
for j in range(i+1,4):
for k in range(j+1,5):
ans+=dl[i]*dl[j]*dl[k]
print(ans) | n=int(eval(input()))
d={}
for i in range(n):
a=eval(input())
if a[0]=="M" or a[0]=="A" or a[0]=="R" or a[0]=="C" or a[0]=="H":
d[a[0]]=d.get(a[0],0)+1
a=list(d.values())
if len(a)<3:
print((0))
exit()
import itertools
c=list(itertools.combinations(a,3))
ans=0
for i,j,k in c:
ans+=i*j*k
print(ans) | 15 | 16 | 319 | 326 | n = int(eval(input()))
a = [list(eval(input())) for i in range(n)]
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in a:
if i[0] in d:
d[i[0]] += 1
dl = []
for i in list(d.values()):
dl.append(i)
ans = 0
for i in range(3):
for j in range(i + 1, 4):
for k in range(j + 1, 5):
ans += dl[i] * dl[j] * dl[k]
print(ans)
| n = int(eval(input()))
d = {}
for i in range(n):
a = eval(input())
if a[0] == "M" or a[0] == "A" or a[0] == "R" or a[0] == "C" or a[0] == "H":
d[a[0]] = d.get(a[0], 0) + 1
a = list(d.values())
if len(a) < 3:
print((0))
exit()
import itertools
c = list(itertools.combinations(a, 3))
ans = 0
for i, j, k in c:
ans += i * j * k
print(ans)
| false | 6.25 | [
"-a = [list(eval(input())) for i in range(n)]",
"-d = {\"M\": 0, \"A\": 0, \"R\": 0, \"C\": 0, \"H\": 0}",
"-for i in a:",
"- if i[0] in d:",
"- d[i[0]] += 1",
"-dl = []",
"-for i in list(d.values()):",
"- dl.append(i)",
"+d = {}",
"+for i in range(n):",
"+ a = eval(input())",
... | false | 0.042533 | 0.083632 | 0.508571 | [
"s056642512",
"s970264991"
] |
u757117214 | p02972 | python | s926499639 | s814763325 | 361 | 258 | 7,132 | 11,644 | Accepted | Accepted | 28.53 | from collections import Counter
N,*a = map(int,open(0).read().split())
ans = []
for i in range(N)[::-1]:
part_rem = sum(a[i::i+1]) % 2
if a[i] == 0:
if part_rem == 1:
a[i] = abs(a[i] - 1)
elif a[i] == 1:
if part_rem == 0:
a[i] = abs(a[i] - 1)
c = Counter(a)
print(c[1])
for i in range(N):
if a[i] == 1:
print(i+1,end=" ")
print()
| N,*a = list(map(int,open(0).read().split()))
ans = []
for i in range(N)[::-1]:
part_rem = sum(a[i::i+1]) % 2
if a[i] != part_rem:
a[i] = abs(a[i] - 1)
print((sum(a)))
print((*[i+1 for i,v in enumerate(a) if v == 1])) | 21 | 9 | 460 | 232 | from collections import Counter
N, *a = map(int, open(0).read().split())
ans = []
for i in range(N)[::-1]:
part_rem = sum(a[i :: i + 1]) % 2
if a[i] == 0:
if part_rem == 1:
a[i] = abs(a[i] - 1)
elif a[i] == 1:
if part_rem == 0:
a[i] = abs(a[i] - 1)
c = Counter(a)
print(c[1])
for i in range(N):
if a[i] == 1:
print(i + 1, end=" ")
print()
| N, *a = list(map(int, open(0).read().split()))
ans = []
for i in range(N)[::-1]:
part_rem = sum(a[i :: i + 1]) % 2
if a[i] != part_rem:
a[i] = abs(a[i] - 1)
print((sum(a)))
print((*[i + 1 for i, v in enumerate(a) if v == 1]))
| false | 57.142857 | [
"-from collections import Counter",
"-",
"-N, *a = map(int, open(0).read().split())",
"+N, *a = list(map(int, open(0).read().split()))",
"- if a[i] == 0:",
"- if part_rem == 1:",
"- a[i] = abs(a[i] - 1)",
"- elif a[i] == 1:",
"- if part_rem == 0:",
"- a[i]... | false | 0.120166 | 0.049708 | 2.417454 | [
"s926499639",
"s814763325"
] |
u512212329 | p02660 | python | s466838138 | s454602552 | 161 | 92 | 9,464 | 9,484 | Accepted | Accepted | 42.86 | from collections import defaultdict
from itertools import accumulate
def main():
n = int(eval(input()))
prime_counter = defaultdict(int)
acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39
f = 2
while f * f <= n:
if n % f == 0:
n //= f
prime_counter[f] += 1
else:
f += 1
if n != 1:
prime_counter[n] += 1
ans = 0
for c in list(prime_counter.values()):
for i, x in enumerate(acc):
if c < x:
tmp = i
break
ans += tmp
print(ans)
if __name__ == '__main__':
main()
| from collections import defaultdict
from itertools import accumulate
def main():
n = int(eval(input()))
prime_counter = defaultdict(int)
acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39
f = 2
while n % f == 0:
n //= f
prime_counter[f] += 1
f = 3
while f * f <= n:
if n % f == 0:
n //= f
prime_counter[f] += 1
else:
f += 2
if n != 1:
prime_counter[n] += 1
ans = 0
for c in list(prime_counter.values()):
for accum_index, x in enumerate(acc):
if c < x:
break
ans += accum_index
print(ans)
if __name__ == '__main__':
main()
| 31 | 34 | 645 | 720 | from collections import defaultdict
from itertools import accumulate
def main():
n = int(eval(input()))
prime_counter = defaultdict(int)
acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39
f = 2
while f * f <= n:
if n % f == 0:
n //= f
prime_counter[f] += 1
else:
f += 1
if n != 1:
prime_counter[n] += 1
ans = 0
for c in list(prime_counter.values()):
for i, x in enumerate(acc):
if c < x:
tmp = i
break
ans += tmp
print(ans)
if __name__ == "__main__":
main()
| from collections import defaultdict
from itertools import accumulate
def main():
n = int(eval(input()))
prime_counter = defaultdict(int)
acc = tuple(accumulate(list(range(1, 42)))) # 10^12 < 2^39
f = 2
while n % f == 0:
n //= f
prime_counter[f] += 1
f = 3
while f * f <= n:
if n % f == 0:
n //= f
prime_counter[f] += 1
else:
f += 2
if n != 1:
prime_counter[n] += 1
ans = 0
for c in list(prime_counter.values()):
for accum_index, x in enumerate(acc):
if c < x:
break
ans += accum_index
print(ans)
if __name__ == "__main__":
main()
| false | 8.823529 | [
"+ while n % f == 0:",
"+ n //= f",
"+ prime_counter[f] += 1",
"+ f = 3",
"- f += 1",
"+ f += 2",
"- for i, x in enumerate(acc):",
"+ for accum_index, x in enumerate(acc):",
"- tmp = i",
"- ans += tmp",
"+ ans +... | false | 0.038778 | 0.050986 | 0.760559 | [
"s466838138",
"s454602552"
] |
u592547545 | p02660 | python | s398209125 | s114908405 | 109 | 85 | 9,504 | 9,324 | Accepted | Accepted | 22.02 | def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def readinput():
n=int(eval(input()))
return n
def possibleCnt(n):
cnt=0
resu=n
for i in range(1,n+1):
if resu >= i:
cnt+=1
resu-=i
#print(cnt,resu)
return cnt
def main(n):
ansList=factorization(n)
#print(ansList)
count=0
for l in ansList:
if(l[0]!=1):
count+=possibleCnt(l[1])
return count
if __name__=='__main__':
n=readinput()
ans=main(n)
print(ans)
| def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
import math
def myFactorization(n):
'''nを素因数分解する
戻り値: factList = [[prime1, exp1], [prime2, exp2],...]
n=(prime1)**exp1 * (prime2)**exp2 * ...
'''
factList=[]
temp=n
cnt=0
while(temp%2==0):
temp=temp//2
cnt+=1
if(cnt>0):
factList.append([2,cnt])
m=int(math.sqrt(n))+1
for i in range(3,m+1,2):
cnt=0
while(temp%i==0):
temp=temp//i
cnt+=1
if(cnt>0):
factList.append([i,cnt])
if(temp==1):
break
if(temp>1):
factList.append([temp,1])
return factList
def readinput():
n=int(eval(input()))
return n
def possibleCnt(n):
cnt=0
resu=n
for i in range(1,n+1):
if resu >= i:
cnt+=1
resu-=i
#print(cnt,resu)
return cnt
def main(n):
#ansList=factorization(n)
ansList=myFactorization(n)
#print(ansList)
count=0
for l in ansList:
if(l[0]!=1):
count+=possibleCnt(l[1])
return count
if __name__=='__main__':
n=readinput()
ans=main(n)
print(ans)
| 47 | 81 | 881 | 1,582 | def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
def readinput():
n = int(eval(input()))
return n
def possibleCnt(n):
cnt = 0
resu = n
for i in range(1, n + 1):
if resu >= i:
cnt += 1
resu -= i
# print(cnt,resu)
return cnt
def main(n):
ansList = factorization(n)
# print(ansList)
count = 0
for l in ansList:
if l[0] != 1:
count += possibleCnt(l[1])
return count
if __name__ == "__main__":
n = readinput()
ans = main(n)
print(ans)
| def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
import math
def myFactorization(n):
"""nを素因数分解する
戻り値: factList = [[prime1, exp1], [prime2, exp2],...]
n=(prime1)**exp1 * (prime2)**exp2 * ...
"""
factList = []
temp = n
cnt = 0
while temp % 2 == 0:
temp = temp // 2
cnt += 1
if cnt > 0:
factList.append([2, cnt])
m = int(math.sqrt(n)) + 1
for i in range(3, m + 1, 2):
cnt = 0
while temp % i == 0:
temp = temp // i
cnt += 1
if cnt > 0:
factList.append([i, cnt])
if temp == 1:
break
if temp > 1:
factList.append([temp, 1])
return factList
def readinput():
n = int(eval(input()))
return n
def possibleCnt(n):
cnt = 0
resu = n
for i in range(1, n + 1):
if resu >= i:
cnt += 1
resu -= i
# print(cnt,resu)
return cnt
def main(n):
# ansList=factorization(n)
ansList = myFactorization(n)
# print(ansList)
count = 0
for l in ansList:
if l[0] != 1:
count += possibleCnt(l[1])
return count
if __name__ == "__main__":
n = readinput()
ans = main(n)
print(ans)
| false | 41.975309 | [
"+",
"+",
"+import math",
"+",
"+",
"+def myFactorization(n):",
"+ \"\"\"nを素因数分解する",
"+ 戻り値: factList = [[prime1, exp1], [prime2, exp2],...]",
"+ n=(prime1)**exp1 * (prime2)**exp2 * ...",
"+ \"\"\"",
"+ factList = []",
"+ temp = n",
"+ cnt = 0",
"+ while temp... | false | 0.060144 | 0.112141 | 0.536328 | [
"s398209125",
"s114908405"
] |
u779455925 | p03987 | python | s304413106 | s544011740 | 325 | 298 | 40,900 | 37,672 | Accepted | Accepted | 8.31 | #import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline
#N=int(input())
N=int(eval(input()))
A=list(map(int,input().split()))
lst=[[A[0],0,1]]
count=0
for i in range(1,N):
m=1
while lst and lst[-1][0]>A[i]:
a,b,c=lst.pop()
count+=a*(i-b)*c
m+=c
lst.append([A[i],i,m])
while lst:
a,b,c=lst.pop()
count+=a*(N-b)*c
print(count)
| #import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
"""
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys"""
#input = sys.stdin.readline
#N=int(input())
N=int(eval(input()))
A=list(map(int,input().split()))
lst=[[A[0],0,1]]
count=0
for i in range(1,N):
m=1
while lst and lst[-1][0]>A[i]:
a,b,c=lst.pop()
count+=a*(i-b)*c
m+=c
lst.append([A[i],i,m])
while lst:
a,b,c=lst.pop()
count+=a*(N-b)*c
print(count)
| 35 | 36 | 652 | 660 | # import decimal
# decimal.getcontext().prec==500 Floatの桁数を500まで増やす
# Decimal(c).sqrt() それで平方根を求める
# Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
# input = sys.stdin.readline
# N=int(input())
N = int(eval(input()))
A = list(map(int, input().split()))
lst = [[A[0], 0, 1]]
count = 0
for i in range(1, N):
m = 1
while lst and lst[-1][0] > A[i]:
a, b, c = lst.pop()
count += a * (i - b) * c
m += c
lst.append([A[i], i, m])
while lst:
a, b, c = lst.pop()
count += a * (N - b) * c
print(count)
| # import decimal
# decimal.getcontext().prec==500 Floatの桁数を500まで増やす
# Decimal(c).sqrt() それで平方根を求める
# Decimal(1) / Decimal(7) 1/7
"""
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys"""
# input = sys.stdin.readline
# N=int(input())
N = int(eval(input()))
A = list(map(int, input().split()))
lst = [[A[0], 0, 1]]
count = 0
for i in range(1, N):
m = 1
while lst and lst[-1][0] > A[i]:
a, b, c = lst.pop()
count += a * (i - b) * c
m += c
lst.append([A[i], i, m])
while lst:
a, b, c = lst.pop()
count += a * (N - b) * c
print(count)
| false | 2.777778 | [
"+\"\"\"",
"-import sys",
"-",
"+import sys\"\"\""
] | false | 0.035079 | 0.041807 | 0.839065 | [
"s304413106",
"s544011740"
] |
u281303342 | p03425 | python | s636683202 | s649256954 | 154 | 67 | 10,112 | 10,008 | Accepted | Accepted | 56.49 | from collections import defaultdict
from itertools import combinations
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
dic = defaultdict(int)
for s in S:
dic[s[0]] += 1
comb = combinations("MARCH", 3)
ans = 0
for x1,x2,x3 in comb:
ans += dic[x1]*dic[x2]*dic[x3]
print(ans)
| # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(eval(input()))
S = [input().rstrip() for _ in range(N)]
from collections import defaultdict
d = defaultdict(int)
for s in S:
key = s[0]
d[key] += 1
from itertools import combinations
c = combinations("MARCH",3)
ans = 0
for x,y,z in c:
ans += d[x]*d[y]*d[z]
print(ans) | 17 | 29 | 303 | 646 | from collections import defaultdict
from itertools import combinations
N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
dic = defaultdict(int)
for s in S:
dic[s[0]] += 1
comb = combinations("MARCH", 3)
ans = 0
for x1, x2, x3 in comb:
ans += dic[x1] * dic[x2] * dic[x3]
print(ans)
| # Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(eval(input()))
S = [input().rstrip() for _ in range(N)]
from collections import defaultdict
d = defaultdict(int)
for s in S:
key = s[0]
d[key] += 1
from itertools import combinations
c = combinations("MARCH", 3)
ans = 0
for x, y, z in c:
ans += d[x] * d[y] * d[z]
print(ans)
| false | 41.37931 | [
"+# Python3 (3.4.3)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+# function",
"+# main",
"+N = int(eval(input()))",
"+S = [input().rstrip() for _ in range(N)]",
"+",
"+d = defaultdict(int)",
"+for s in S:",
"+ key = s[0]",
"+ d[key] += 1",
"-N = int(eval(input()))",
"-S =... | false | 0.038145 | 0.044585 | 0.855558 | [
"s636683202",
"s649256954"
] |
u814986259 | p03478 | python | s760628604 | s190159758 | 35 | 29 | 3,060 | 2,940 | Accepted | Accepted | 17.14 | N,A,B=list(map(int,input().split()))
ans=0
for i in range(1,N+1):
s=list(map(int,str(i)))
s=sum(s)
if A<=s and s<=B:
ans+=i
print(ans)
| N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N+1):
k = i
tmp = 0
while k > 0:
tmp += k % 10
k = k // 10
if tmp >= A and tmp <= B:
ans += i
print(ans)
| 9 | 11 | 149 | 217 | N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
s = list(map(int, str(i)))
s = sum(s)
if A <= s and s <= B:
ans += i
print(ans)
| N, A, B = list(map(int, input().split()))
ans = 0
for i in range(1, N + 1):
k = i
tmp = 0
while k > 0:
tmp += k % 10
k = k // 10
if tmp >= A and tmp <= B:
ans += i
print(ans)
| false | 18.181818 | [
"- s = list(map(int, str(i)))",
"- s = sum(s)",
"- if A <= s and s <= B:",
"+ k = i",
"+ tmp = 0",
"+ while k > 0:",
"+ tmp += k % 10",
"+ k = k // 10",
"+ if tmp >= A and tmp <= B:"
] | false | 0.037202 | 0.038171 | 0.974629 | [
"s760628604",
"s190159758"
] |
u827202523 | p03912 | python | s463098485 | s316268437 | 291 | 225 | 80,784 | 58,908 | Accepted | Accepted | 22.68 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
n, m = getList()
nums = getList()
n_mods = [0 for i in range(m)]
pair_mods = [0 for i in range(m)]
num_mods = [{} for i in range(m)]
for num in nums:
modres = num % m
n_mods[modres] += 1
if num in num_mods[modres]:
num_mods[modres][num] += 1
else:
num_mods[modres][num] = 1
if num_mods[modres][num] % 2 == 0:
pair_mods[modres] += 1
# print(n_mods)
# print(pair_mods)
ans = 0
for i in range(1, (m+1) // 2):
left = i
right = m - i
ans += min(n_mods[left], n_mods[right])
if n_mods[left] > n_mods[right]:
ans += max(0, min(pair_mods[left], (n_mods[left] - n_mods[right]) // 2))
else:
ans += max(0, min(pair_mods[right], (n_mods[right] - n_mods[left]) // 2))
# print(left, right, ans)
ans += n_mods[0] // 2
if m % 2 == 0:
ans += n_mods[m//2] // 2
print(ans) | import sys
input = sys.stdin.buffer.readline
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getlist():
return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15
def main():
n,m = getlist()
nums = getlist()
cnt = Counter(nums)
mod = [0 for i in range(m)]
same = [0 for i in range(m)]
for k, v in list(cnt.items()):
mod[k%m] += v
same[k%m] += v // 2
ans = mod[0] // 2
for i in range(1, int((m+2) // 2)):
if i == m / 2:
ans += mod[i] // 2
else:
other = m - i
ans += min(mod[i], mod[other])
if mod[i] > mod[other]:
ans += min(same[i], (mod[i] - mod[other]) // 2)
if mod[i] < mod[other]:
ans += min(same[other], -(mod[i] - mod[other]) // 2)
print(ans)
# print(same, mod)
if __name__ == '__main__':
main()
"""
9999
3
2916
""" | 45 | 52 | 1,096 | 1,076 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
n, m = getList()
nums = getList()
n_mods = [0 for i in range(m)]
pair_mods = [0 for i in range(m)]
num_mods = [{} for i in range(m)]
for num in nums:
modres = num % m
n_mods[modres] += 1
if num in num_mods[modres]:
num_mods[modres][num] += 1
else:
num_mods[modres][num] = 1
if num_mods[modres][num] % 2 == 0:
pair_mods[modres] += 1
# print(n_mods)
# print(pair_mods)
ans = 0
for i in range(1, (m + 1) // 2):
left = i
right = m - i
ans += min(n_mods[left], n_mods[right])
if n_mods[left] > n_mods[right]:
ans += max(0, min(pair_mods[left], (n_mods[left] - n_mods[right]) // 2))
else:
ans += max(0, min(pair_mods[right], (n_mods[right] - n_mods[left]) // 2))
# print(left, right, ans)
ans += n_mods[0] // 2
if m % 2 == 0:
ans += n_mods[m // 2] // 2
print(ans)
| import sys
input = sys.stdin.buffer.readline
def getN():
return int(eval(input()))
def getNM():
return list(map(int, input().split()))
def getlist():
return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15
def main():
n, m = getlist()
nums = getlist()
cnt = Counter(nums)
mod = [0 for i in range(m)]
same = [0 for i in range(m)]
for k, v in list(cnt.items()):
mod[k % m] += v
same[k % m] += v // 2
ans = mod[0] // 2
for i in range(1, int((m + 2) // 2)):
if i == m / 2:
ans += mod[i] // 2
else:
other = m - i
ans += min(mod[i], mod[other])
if mod[i] > mod[other]:
ans += min(same[i], (mod[i] - mod[other]) // 2)
if mod[i] < mod[other]:
ans += min(same[other], -(mod[i] - mod[other]) // 2)
print(ans)
# print(same, mod)
if __name__ == "__main__":
main()
"""
9999
3
2916
"""
| false | 13.461538 | [
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(1000000)",
"-from collections import deque",
"+input = sys.stdin.buffer.readline",
"-def getList():",
"+def getNM():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def getlist():",
"+import heapq",
"+from collections import d... | false | 0.047665 | 0.209602 | 0.227408 | [
"s463098485",
"s316268437"
] |
u163703551 | p02803 | python | s304699832 | s242658011 | 578 | 499 | 3,700 | 3,608 | Accepted | Accepted | 13.67 | import sys
import socket
from heapq import heappush, heappop
hostname = socket.gethostname()
if hostname == 'F451C':
sys.stdin = open('d1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def dijkstra(a, s):
i0, j0 = s
debug = i0 == 1 and j0 == 2
H = len(a)
W = len(a[0])
inf = 1000
d = [[inf]*W for i in range(H)]
d[i0][j0] = 0
q = []
item = (0, i0, j0)
heappush(q, item)
for i in range(H):
for j in range(W):
if a[i][j] == '#':
continue
v = 0 if (i, j) == s else inf
item = (v, i, j)
# heappush(q, item)
# print('q:', q)
while q != []:
v, i, j = heappop(q)
di = [-1, 1, 0, 0]
dj = [0, 0, -1, 1]
for k in range(4):
ii = i + di[k]
jj = j + dj[k]
if not (0 <= ii < H and 0 <= jj < W):
continue
if a[ii][jj] == '#':
continue
# if debug:
# print(' ', i, j, ii, jj, d, d[i][j] + 1, d[ii][jj])
if d[i][j] + 1 < d[ii][jj]:
d[ii][jj] = d[i][j] + 1
item = (d[i][j] + 1, ii, jj)
heappush(q, item)
# print(' ', d[ii][jj])
return d
def main():
H, W = read_int_list()
a = [read_str() for i in range(H)]
res = 0
for i in range(H):
for j in range(W):
if a[i][j] == '#':
continue
s = (i, j)
d = dijkstra(a, s)
# print(' d:', d)
# break
for k in range(H):
for l in range(W):
if a[k][l] == '#':
continue
if d[k][l] > res:
res = d[k][l]
print(res)
main()
| import sys
import socket
from heapq import heappush, heappop
hostname = socket.gethostname()
if hostname == 'F451C':
sys.stdin = open('d2.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def dijkstra(a, s):
i0, j0 = s
debug = i0 == 1 and j0 == 2
H = len(a)
W = len(a[0])
inf = 1000
d = [[inf]*W for i in range(H)]
d[i0][j0] = 0
q = []
item = (0, i0, j0)
heappush(q, item)
for i in range(H):
for j in range(W):
if a[i][j] == '#':
continue
v = 0 if (i, j) == s else inf
item = (v, i, j)
# heappush(q, item)
# print('q:', q)
while q != []:
v, i, j = heappop(q)
di = [-1, 1, 0, 0]
dj = [0, 0, -1, 1]
for k in range(4):
ii = i + di[k]
jj = j + dj[k]
if not (0 <= ii < H and 0 <= jj < W):
continue
if a[ii][jj] == '#':
continue
# if debug:
# print(' ', i, j, ii, jj, d, d[i][j] + 1, d[ii][jj])
if d[i][j] + 1 < d[ii][jj]:
d[ii][jj] = d[i][j] + 1
item = (d[i][j] + 1, ii, jj)
heappush(q, item)
# print(' ', d[ii][jj])
return d
def main():
H, W = read_int_list()
a = [read_str() for i in range(H)]
res = 0
for i in range(H):
for j in range(W):
if a[i][j] == '#':
continue
s = (i, j)
d = dijkstra(a, s)
# print(' d:', d)
# break
for k in range(H):
for l in range(W):
if a[k][l] == '#':
continue
if d[k][l] > res:
res = d[k][l]
print(res)
def bfs(a, s):
i0, j0 = s
H = len(a)
W = len(a[0])
inf = 1000
d = [[inf]*W for i in range(H)]
d[i0][j0] = 0
state = [[0] * W for i in range(H)]
q = []
q.append(s)
state[i0][j0] = 1
while q != []:
u = q.pop(0)
i, j = u
state[i][j] = 2
di = [-1, 1, 0, 0]
dj = [0, 0, -1, 1]
for k in range(4):
ii = i + di[k]
jj = j + dj[k]
if not (0 <= ii < H and 0 <= jj < W):
continue
if a[ii][jj] == '#':
continue
# if d[i][j] + 1 < d[ii][jj]:
if state[ii][jj] == 0:
d[ii][jj] = d[i][j] + 1
q.append((ii, jj))
state[ii][jj] = 1
return d
def main2():
H, W = read_int_list()
a = [read_str() for i in range(H)]
res = 0
for i in range(H):
for j in range(W):
if a[i][j] == '#':
continue
s = (i, j)
d = bfs(a, s)
# print(' d:', d)
# break
for k in range(H):
for l in range(W):
if a[k][l] == '#':
continue
if d[k][l] > res:
res = d[k][l]
print(res)
main2()
| 97 | 156 | 1,841 | 3,016 | import sys
import socket
from heapq import heappush, heappop
hostname = socket.gethostname()
if hostname == "F451C":
sys.stdin = open("d1.in")
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def dijkstra(a, s):
i0, j0 = s
debug = i0 == 1 and j0 == 2
H = len(a)
W = len(a[0])
inf = 1000
d = [[inf] * W for i in range(H)]
d[i0][j0] = 0
q = []
item = (0, i0, j0)
heappush(q, item)
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
v = 0 if (i, j) == s else inf
item = (v, i, j)
# heappush(q, item)
# print('q:', q)
while q != []:
v, i, j = heappop(q)
di = [-1, 1, 0, 0]
dj = [0, 0, -1, 1]
for k in range(4):
ii = i + di[k]
jj = j + dj[k]
if not (0 <= ii < H and 0 <= jj < W):
continue
if a[ii][jj] == "#":
continue
# if debug:
# print(' ', i, j, ii, jj, d, d[i][j] + 1, d[ii][jj])
if d[i][j] + 1 < d[ii][jj]:
d[ii][jj] = d[i][j] + 1
item = (d[i][j] + 1, ii, jj)
heappush(q, item)
# print(' ', d[ii][jj])
return d
def main():
H, W = read_int_list()
a = [read_str() for i in range(H)]
res = 0
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
s = (i, j)
d = dijkstra(a, s)
# print(' d:', d)
# break
for k in range(H):
for l in range(W):
if a[k][l] == "#":
continue
if d[k][l] > res:
res = d[k][l]
print(res)
main()
| import sys
import socket
from heapq import heappush, heappop
hostname = socket.gethostname()
if hostname == "F451C":
sys.stdin = open("d2.in")
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def dijkstra(a, s):
i0, j0 = s
debug = i0 == 1 and j0 == 2
H = len(a)
W = len(a[0])
inf = 1000
d = [[inf] * W for i in range(H)]
d[i0][j0] = 0
q = []
item = (0, i0, j0)
heappush(q, item)
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
v = 0 if (i, j) == s else inf
item = (v, i, j)
# heappush(q, item)
# print('q:', q)
while q != []:
v, i, j = heappop(q)
di = [-1, 1, 0, 0]
dj = [0, 0, -1, 1]
for k in range(4):
ii = i + di[k]
jj = j + dj[k]
if not (0 <= ii < H and 0 <= jj < W):
continue
if a[ii][jj] == "#":
continue
# if debug:
# print(' ', i, j, ii, jj, d, d[i][j] + 1, d[ii][jj])
if d[i][j] + 1 < d[ii][jj]:
d[ii][jj] = d[i][j] + 1
item = (d[i][j] + 1, ii, jj)
heappush(q, item)
# print(' ', d[ii][jj])
return d
def main():
H, W = read_int_list()
a = [read_str() for i in range(H)]
res = 0
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
s = (i, j)
d = dijkstra(a, s)
# print(' d:', d)
# break
for k in range(H):
for l in range(W):
if a[k][l] == "#":
continue
if d[k][l] > res:
res = d[k][l]
print(res)
def bfs(a, s):
i0, j0 = s
H = len(a)
W = len(a[0])
inf = 1000
d = [[inf] * W for i in range(H)]
d[i0][j0] = 0
state = [[0] * W for i in range(H)]
q = []
q.append(s)
state[i0][j0] = 1
while q != []:
u = q.pop(0)
i, j = u
state[i][j] = 2
di = [-1, 1, 0, 0]
dj = [0, 0, -1, 1]
for k in range(4):
ii = i + di[k]
jj = j + dj[k]
if not (0 <= ii < H and 0 <= jj < W):
continue
if a[ii][jj] == "#":
continue
# if d[i][j] + 1 < d[ii][jj]:
if state[ii][jj] == 0:
d[ii][jj] = d[i][j] + 1
q.append((ii, jj))
state[ii][jj] = 1
return d
def main2():
H, W = read_int_list()
a = [read_str() for i in range(H)]
res = 0
for i in range(H):
for j in range(W):
if a[i][j] == "#":
continue
s = (i, j)
d = bfs(a, s)
# print(' d:', d)
# break
for k in range(H):
for l in range(W):
if a[k][l] == "#":
continue
if d[k][l] > res:
res = d[k][l]
print(res)
main2()
| false | 37.820513 | [
"- sys.stdin = open(\"d1.in\")",
"+ sys.stdin = open(\"d2.in\")",
"-main()",
"+def bfs(a, s):",
"+ i0, j0 = s",
"+ H = len(a)",
"+ W = len(a[0])",
"+ inf = 1000",
"+ d = [[inf] * W for i in range(H)]",
"+ d[i0][j0] = 0",
"+ state = [[0] * W for i in range(H)]",
"+ ... | false | 0.048038 | 0.054556 | 0.880532 | [
"s304699832",
"s242658011"
] |
u624475441 | p03330 | python | s647238054 | s654163778 | 922 | 831 | 7,696 | 3,064 | Accepted | Accepted | 9.87 | from itertools import *
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in [0]*C]
c = [list(map(int, input().split())) for _ in [0]*N]
tri = [[] for _ in [0]*3]
for i in range(1, N+1):
for j in range(1, N+1):
tri[(i+j) % 3] += [c[i-1][j-1] - 1]
incom = [[0]*C for _ in [0]*3]
for i in range(3):
for color in range(C):
incom[i][color] = sum(D[x][color] for x in tri[i])
ans = 1<<30
for p in permutations(list(range(C)), 3):
t = sum(incom[x][y]for x,y in enumerate(p))
if t < ans: ans = t
print(ans) | from itertools import *
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in [0]*C]
tri = [[0]*C for _ in [0]*3]
for i in range(N):
for j,x in enumerate(map(int, input().split())):
tri[(i+j)%3][x-1] += 1
res = 1<<30
for p in permutations(list(range(C)), 3):
tt = sum(D[l][p[m]] * tri[m][l] for l in range(C) for m in range(3))
if tt < res: res = tt
print(res) | 17 | 12 | 567 | 410 | from itertools import *
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in [0] * C]
c = [list(map(int, input().split())) for _ in [0] * N]
tri = [[] for _ in [0] * 3]
for i in range(1, N + 1):
for j in range(1, N + 1):
tri[(i + j) % 3] += [c[i - 1][j - 1] - 1]
incom = [[0] * C for _ in [0] * 3]
for i in range(3):
for color in range(C):
incom[i][color] = sum(D[x][color] for x in tri[i])
ans = 1 << 30
for p in permutations(list(range(C)), 3):
t = sum(incom[x][y] for x, y in enumerate(p))
if t < ans:
ans = t
print(ans)
| from itertools import *
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in [0] * C]
tri = [[0] * C for _ in [0] * 3]
for i in range(N):
for j, x in enumerate(map(int, input().split())):
tri[(i + j) % 3][x - 1] += 1
res = 1 << 30
for p in permutations(list(range(C)), 3):
tt = sum(D[l][p[m]] * tri[m][l] for l in range(C) for m in range(3))
if tt < res:
res = tt
print(res)
| false | 29.411765 | [
"-c = [list(map(int, input().split())) for _ in [0] * N]",
"-tri = [[] for _ in [0] * 3]",
"-for i in range(1, N + 1):",
"- for j in range(1, N + 1):",
"- tri[(i + j) % 3] += [c[i - 1][j - 1] - 1]",
"-incom = [[0] * C for _ in [0] * 3]",
"-for i in range(3):",
"- for color in range(C):",
... | false | 0.038708 | 0.037219 | 1.040006 | [
"s647238054",
"s654163778"
] |
u014333473 | p02720 | python | s271516686 | s520800047 | 113 | 86 | 18,940 | 18,896 | Accepted | Accepted | 23.89 | from collections import deque
k=int(eval(input()))
d=deque()
for i in range(1,10): d.append(i)
for i in range(k):
x=d.popleft()
if i==k-1:
print(x)
break
if x%10!=0:
d.append(10*x+x%10-1)
d.append(10*x+x%10)
if x%10!=9:
d.append(10*x+x%10+1) | from collections import deque
d=deque(list(range(1,10)))
for i in range(int(eval(input()))):
x=d.popleft()
r=x%10;c=x*10+r
if r!=0:d.append(c-1)
d.append(c)
if r!=9:d.append(c+1)
print(x) | 14 | 9 | 274 | 199 | from collections import deque
k = int(eval(input()))
d = deque()
for i in range(1, 10):
d.append(i)
for i in range(k):
x = d.popleft()
if i == k - 1:
print(x)
break
if x % 10 != 0:
d.append(10 * x + x % 10 - 1)
d.append(10 * x + x % 10)
if x % 10 != 9:
d.append(10 * x + x % 10 + 1)
| from collections import deque
d = deque(list(range(1, 10)))
for i in range(int(eval(input()))):
x = d.popleft()
r = x % 10
c = x * 10 + r
if r != 0:
d.append(c - 1)
d.append(c)
if r != 9:
d.append(c + 1)
print(x)
| false | 35.714286 | [
"-k = int(eval(input()))",
"-d = deque()",
"-for i in range(1, 10):",
"- d.append(i)",
"-for i in range(k):",
"+d = deque(list(range(1, 10)))",
"+for i in range(int(eval(input()))):",
"- if i == k - 1:",
"- print(x)",
"- break",
"- if x % 10 != 0:",
"- d.append(10... | false | 0.050758 | 0.202978 | 0.250065 | [
"s271516686",
"s520800047"
] |
u968166680 | p02862 | python | s776847666 | s704472347 | 201 | 172 | 41,328 | 39,732 | Accepted | Accepted | 14.43 | from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 9)
INF = 1 << 60
def input():
return stdin.readline().strip()
MOD = 1000000007
X, Y = list(map(int, input().split()))
n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if (X + Y) % 3 or x < 0 or y < 0:
print((0))
exit()
def mod_com(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
if k > n - k:
k = n - k
if k == 0:
return 1
ans = 1
for i in range(n - k + 1, n + 1):
ans = ans * i % MOD
inv = [0] * (k + 1)
inv[1] = 1
for i in range(2, k + 1):
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
ans = ans * inv[i] % MOD
return ans
print((mod_com(n, x)))
| from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 9)
INF = 1 << 60
def input():
return stdin.readline().strip()
X, Y = list(map(int, input().split()))
n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if (X + Y) % 3 or x < 0 or y < 0:
print((0))
exit()
def mod_com(n, r):
MOD = 1000000007
r = min(r, n - r)
numer = denom = 1
for i in range(1, r + 1):
numer = numer * (n - r + i) % MOD
denom = denom * i % MOD
return numer * pow(denom, MOD - 2, MOD) % MOD
print((mod_com(n, x)))
| 44 | 31 | 783 | 581 | from sys import stdin, setrecursionlimit
setrecursionlimit(10**9)
INF = 1 << 60
def input():
return stdin.readline().strip()
MOD = 1000000007
X, Y = list(map(int, input().split()))
n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if (X + Y) % 3 or x < 0 or y < 0:
print((0))
exit()
def mod_com(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
if k > n - k:
k = n - k
if k == 0:
return 1
ans = 1
for i in range(n - k + 1, n + 1):
ans = ans * i % MOD
inv = [0] * (k + 1)
inv[1] = 1
for i in range(2, k + 1):
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
ans = ans * inv[i] % MOD
return ans
print((mod_com(n, x)))
| from sys import stdin, setrecursionlimit
setrecursionlimit(10**9)
INF = 1 << 60
def input():
return stdin.readline().strip()
X, Y = list(map(int, input().split()))
n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if (X + Y) % 3 or x < 0 or y < 0:
print((0))
exit()
def mod_com(n, r):
MOD = 1000000007
r = min(r, n - r)
numer = denom = 1
for i in range(1, r + 1):
numer = numer * (n - r + i) % MOD
denom = denom * i % MOD
return numer * pow(denom, MOD - 2, MOD) % MOD
print((mod_com(n, x)))
| false | 29.545455 | [
"-MOD = 1000000007",
"-def mod_com(n, k):",
"- if n < k:",
"- return 0",
"- if n < 0 or k < 0:",
"- return 0",
"- if k > n - k:",
"- k = n - k",
"- if k == 0:",
"- return 1",
"- ans = 1",
"- for i in range(n - k + 1, n + 1):",
"- ans = ans... | false | 0.104123 | 0.070134 | 1.484633 | [
"s776847666",
"s704472347"
] |
u119148115 | p02625 | python | s030486018 | s115877637 | 677 | 583 | 68,228 | 67,920 | Accepted | Accepted | 13.88 | import sys
def S(): return sys.stdin.readline().rstrip()
N,M = list(map(int,S().split()))
mod = 10**9+7
a = M # (M_P_N)**2
for i in range(1,N):
a *= M-i
a %= mod
# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
r *= (N-i+1)*pow(i,mod-2,mod)*pow(M-i+1,mod-2,mod)*(-1)
r %= mod
ans += r
ans %= mod
print(ans) | import sys
def S(): return sys.stdin.readline().rstrip()
N,M = list(map(int,S().split()))
mod = 10**9+7
a = M # (M_P_N)**2
for i in range(1,N):
a *= M-i
a %= mod
# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
r *= (N-i+1)
r %= mod
r *= pow(i,mod-2,mod)
r %= mod
r *= pow(M-i+1,mod-2,mod)*(-1)
r %= mod
ans += r
ans %= mod
print(ans) | 24 | 28 | 440 | 488 | import sys
def S():
return sys.stdin.readline().rstrip()
N, M = list(map(int, S().split()))
mod = 10**9 + 7
a = M # (M_P_N)**2
for i in range(1, N):
a *= M - i
a %= mod
# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1, N + 1):
r *= (N - i + 1) * pow(i, mod - 2, mod) * pow(M - i + 1, mod - 2, mod) * (-1)
r %= mod
ans += r
ans %= mod
print(ans)
| import sys
def S():
return sys.stdin.readline().rstrip()
N, M = list(map(int, S().split()))
mod = 10**9 + 7
a = M # (M_P_N)**2
for i in range(1, N):
a *= M - i
a %= mod
# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1, N + 1):
r *= N - i + 1
r %= mod
r *= pow(i, mod - 2, mod)
r %= mod
r *= pow(M - i + 1, mod - 2, mod) * (-1)
r %= mod
ans += r
ans %= mod
print(ans)
| false | 14.285714 | [
"- r *= (N - i + 1) * pow(i, mod - 2, mod) * pow(M - i + 1, mod - 2, mod) * (-1)",
"+ r *= N - i + 1",
"+ r %= mod",
"+ r *= pow(i, mod - 2, mod)",
"+ r %= mod",
"+ r *= pow(M - i + 1, mod - 2, mod) * (-1)"
] | false | 0.336573 | 0.672858 | 0.500214 | [
"s030486018",
"s115877637"
] |
u514401521 | p02762 | python | s632331606 | s090572281 | 1,574 | 1,408 | 62,116 | 31,192 | Accepted | Accepted | 10.55 | class UnionFind:
def __init__(self, n):
self.d = []
for _ in range(n):
self.d.append(-1)
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] = self.d[x] + self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
n, m, k = map(int, input().split())
uf = UnionFind(n)
dame = [set() for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.unite(a, b)
dame[a].add(b)
dame[b].add(a)
for i in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if not uf.same(c, d):
continue
dame[c].add(d)
dame[d].add(c)
for i in range(n):
ans = uf.size(i) - 1
ans -= len(dame[i])
print(ans, end=" ")
| class UnionFind:
def __init__(self, n):
self.d = [-1 for _ in range(n)]
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
N, M, K = map(int, input().split())
dame = [[] for _ in range(N)]
uf = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
dame[a].append(b)
dame[b].append(a)
for i in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
if not uf.same(c, d):
continue
dame[c].append(d)
dame[d].append(c)
for i in range(N):
ans = uf.size(i) - 1
ans -= len(dame[i])
print(ans, end=" ")
print()
| 55 | 56 | 1,210 | 1,191 | class UnionFind:
def __init__(self, n):
self.d = []
for _ in range(n):
self.d.append(-1)
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] = self.d[x] + self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
n, m, k = map(int, input().split())
uf = UnionFind(n)
dame = [set() for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.unite(a, b)
dame[a].add(b)
dame[b].add(a)
for i in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if not uf.same(c, d):
continue
dame[c].add(d)
dame[d].add(c)
for i in range(n):
ans = uf.size(i) - 1
ans -= len(dame[i])
print(ans, end=" ")
| class UnionFind:
def __init__(self, n):
self.d = [-1 for _ in range(n)]
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
N, M, K = map(int, input().split())
dame = [[] for _ in range(N)]
uf = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
dame[a].append(b)
dame[b].append(a)
for i in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
if not uf.same(c, d):
continue
dame[c].append(d)
dame[d].append(c)
for i in range(N):
ans = uf.size(i) - 1
ans -= len(dame[i])
print(ans, end=" ")
print()
| false | 1.785714 | [
"- self.d = []",
"- for _ in range(n):",
"- self.d.append(-1)",
"+ self.d = [-1 for _ in range(n)]",
"- def unite(self, x, y):",
"+ def union(self, x, y):",
"- self.d[x] = self.d[x] + self.d[y]",
"+ self.d[x] += self.d[y]",
"-n, m, k = map(int, inp... | false | 0.044823 | 0.045875 | 0.977079 | [
"s632331606",
"s090572281"
] |
u892251744 | p02728 | python | s906533072 | s575400919 | 1,601 | 1,030 | 124,748 | 126,736 | Accepted | Accepted | 35.67 | def main():
import sys
from collections import deque
input = sys.stdin.readline
# comb init
mod = 1000000007
nmax = 2*10 ** 5 + 10 # change here
fac = [0] * nmax
finv = [0] * nmax
inv = [0] * nmax
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def comb(n, r):
if n < r:
return 0
else:
return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod
N = int(eval(input()))
adj = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
adj[a].append(b)
adj[b].append(a)
que = deque()
que.append(1)
seen = [-1] * (N+1)
seen[1] = 0
par = [0] * (N+1)
child = [[] for _ in range(N+1)]
seq = []
while que:
v = que.popleft()
seq.append(v)
for u in adj[v]:
if seen[u] == -1:
seen[u] = seen[v] + 1
par[u] = v
child[v].append(u)
que.append(u)
seq.reverse()
dp = [1] * (N+1)
size = [1] * (N+1)
for v in seq:
for u in child[v]:
size[v] += size[u]
L = size[v] - 1
for u in child[v]:
dp[v] = (dp[v] * (dp[u] * comb(L, size[u]))%mod)%mod
L -= size[u]
seq.reverse()
dp2 = [0] * (N+1)
for v in seq:
if v == 1:
dp2[1] = dp[1]
continue
p = par[v]
dp2[v] = dp[v]
PP = (dp2[p] * pow((dp[v] * comb(N-1, size[v]))%mod, mod-2, mod))%mod
dp2[v] = (dp2[v] * PP * comb(N-1, size[v]-1))%mod
for v in range(1, N+1):
print((dp2[v]))
if __name__ == '__main__':
main()
| def main():
import sys
input = sys.stdin.readline
# comb init
mod = 1000000007
nmax = 2 * 10 ** 5 + 10 # change here
fac = [0] * nmax
finv = [0] * nmax
inv = [0] * nmax
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def comb(n, r):
if n < r:
return 0
else:
return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod
N = int(eval(input()))
adj = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
adj[a].append(b)
adj[b].append(a)
"""ここから変更"""
# op: 普通に根を固定した木DPで子の情報を親に集めるときの演算
def op(a, b):
return (((a[0] * b[0])%mod * comb(a[1]+b[1]+1, a[1]))%mod, a[1]+b[1]+1)
ident_op = (1, -1)
# cum_merge: 累積opどうしをマージするときの演算
def cum_merge(a, b):
return (((a[0] * b[0])%mod * comb(a[1]+b[1], a[1]))%mod, a[1]+b[1])
# 単位元(cum_merge(ident, x) = x)
ident_cum_merge = (1, 0)
"""ここまで変更"""
# root=1でまず普通に木DPをする
# 並行して各頂点につき、子の値の累積opを左右から求めておく
# その後根から順番に、親からの寄与を求めていく(from_par)
def Rerooting(adj):
N = len(adj) - 1
st = [1]
seen = [0] * (N + 1)
seen[1] = 1
par = [0] * (N + 1)
child = [[] for _ in range(N + 1)]
seq = []
while st:
v = st.pop()
seq.append(v)
for u in adj[v]:
if not seen[u]:
seen[u] = 1
par[u] = v
child[v].append(u)
st.append(u)
seq.reverse()
dp = [ident_op] * (N + 1)
left = [ident_cum_merge] * (N + 1)
right = [ident_cum_merge] * (N + 1)
for v in seq:
tmp = ident_cum_merge
for u in child[v]:
left[u] = tmp
tmp = op(tmp, dp[u])
tmp = ident_cum_merge
for u in reversed(child[v]):
right[u] = tmp
tmp = op(tmp, dp[u])
dp[v] = tmp
seq.reverse()
from_par = [ident_op] * (N + 1)
for v in seq:
if v == 1:
continue
from_par[v] = op(cum_merge(left[v], right[v]), from_par[par[v]])
dp[v] = op(dp[v], from_par[v])
return dp
dp = Rerooting(adj)
for v in range(1, N+1):
print((dp[v][0]))
if __name__ == '__main__':
main()
| 79 | 98 | 1,944 | 2,678 | def main():
import sys
from collections import deque
input = sys.stdin.readline
# comb init
mod = 1000000007
nmax = 2 * 10**5 + 10 # change here
fac = [0] * nmax
finv = [0] * nmax
inv = [0] * nmax
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def comb(n, r):
if n < r:
return 0
else:
return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod
N = int(eval(input()))
adj = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
adj[a].append(b)
adj[b].append(a)
que = deque()
que.append(1)
seen = [-1] * (N + 1)
seen[1] = 0
par = [0] * (N + 1)
child = [[] for _ in range(N + 1)]
seq = []
while que:
v = que.popleft()
seq.append(v)
for u in adj[v]:
if seen[u] == -1:
seen[u] = seen[v] + 1
par[u] = v
child[v].append(u)
que.append(u)
seq.reverse()
dp = [1] * (N + 1)
size = [1] * (N + 1)
for v in seq:
for u in child[v]:
size[v] += size[u]
L = size[v] - 1
for u in child[v]:
dp[v] = (dp[v] * (dp[u] * comb(L, size[u])) % mod) % mod
L -= size[u]
seq.reverse()
dp2 = [0] * (N + 1)
for v in seq:
if v == 1:
dp2[1] = dp[1]
continue
p = par[v]
dp2[v] = dp[v]
PP = (dp2[p] * pow((dp[v] * comb(N - 1, size[v])) % mod, mod - 2, mod)) % mod
dp2[v] = (dp2[v] * PP * comb(N - 1, size[v] - 1)) % mod
for v in range(1, N + 1):
print((dp2[v]))
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.readline
# comb init
mod = 1000000007
nmax = 2 * 10**5 + 10 # change here
fac = [0] * nmax
finv = [0] * nmax
inv = [0] * nmax
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def comb(n, r):
if n < r:
return 0
else:
return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod
N = int(eval(input()))
adj = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
adj[a].append(b)
adj[b].append(a)
"""ここから変更"""
# op: 普通に根を固定した木DPで子の情報を親に集めるときの演算
def op(a, b):
return (
((a[0] * b[0]) % mod * comb(a[1] + b[1] + 1, a[1])) % mod,
a[1] + b[1] + 1,
)
ident_op = (1, -1)
# cum_merge: 累積opどうしをマージするときの演算
def cum_merge(a, b):
return (((a[0] * b[0]) % mod * comb(a[1] + b[1], a[1])) % mod, a[1] + b[1])
# 単位元(cum_merge(ident, x) = x)
ident_cum_merge = (1, 0)
"""ここまで変更"""
# root=1でまず普通に木DPをする
# 並行して各頂点につき、子の値の累積opを左右から求めておく
# その後根から順番に、親からの寄与を求めていく(from_par)
def Rerooting(adj):
N = len(adj) - 1
st = [1]
seen = [0] * (N + 1)
seen[1] = 1
par = [0] * (N + 1)
child = [[] for _ in range(N + 1)]
seq = []
while st:
v = st.pop()
seq.append(v)
for u in adj[v]:
if not seen[u]:
seen[u] = 1
par[u] = v
child[v].append(u)
st.append(u)
seq.reverse()
dp = [ident_op] * (N + 1)
left = [ident_cum_merge] * (N + 1)
right = [ident_cum_merge] * (N + 1)
for v in seq:
tmp = ident_cum_merge
for u in child[v]:
left[u] = tmp
tmp = op(tmp, dp[u])
tmp = ident_cum_merge
for u in reversed(child[v]):
right[u] = tmp
tmp = op(tmp, dp[u])
dp[v] = tmp
seq.reverse()
from_par = [ident_op] * (N + 1)
for v in seq:
if v == 1:
continue
from_par[v] = op(cum_merge(left[v], right[v]), from_par[par[v]])
dp[v] = op(dp[v], from_par[v])
return dp
dp = Rerooting(adj)
for v in range(1, N + 1):
print((dp[v][0]))
if __name__ == "__main__":
main()
| false | 19.387755 | [
"- from collections import deque",
"- que = deque()",
"- que.append(1)",
"- seen = [-1] * (N + 1)",
"- seen[1] = 0",
"- par = [0] * (N + 1)",
"- child = [[] for _ in range(N + 1)]",
"- seq = []",
"- while que:",
"- v = que.popleft()",
"- seq.append(v)",
... | false | 0.340924 | 0.502286 | 0.678746 | [
"s906533072",
"s575400919"
] |
u079022693 | p03645 | python | s916604554 | s400216681 | 559 | 388 | 46,744 | 43,920 | Accepted | Accepted | 30.59 | from sys import stdin
from collections import deque
def main():
#入力
readline=stdin.readline
n,m=list(map(int,readline().split()))
G=[[] for _ in range(n+1)]
for _ in range(m):
a,b=list(map(int,readline().split()))
G[a].append(b)
G[b].append(a)
#bfs
q=deque([tuple((1,0))])
flags=[False]*(n+1)
flags[1]=True
ans=False
while len(q)>0:
now,d=q.popleft()
if now==n:
if d==2:
ans=True
break
for nex in G[now]:
if flags[nex]==False:
flags[nex]=True
q.append(tuple((nex,d+1)))
print(("POSSIBLE" if ans else "IMPOSSIBLE"))
if __name__=="__main__":
main() | from sys import stdin
def main():
#入力
readline=stdin.readline
n,m=list(map(int,readline().split()))
G=[[] for _ in range(n+1)]
for _ in range(m):
a,b=list(map(int,readline().split()))
G[a].append(b)
G[b].append(a)
s=set(G[1])
ans=False
while len(s)>0:
now=s.pop()
for nex in G[now]:
if nex==n:
ans=True
break
print(("POSSIBLE" if ans else "IMPOSSIBLE"))
if __name__=="__main__":
main() | 32 | 24 | 754 | 521 | from sys import stdin
from collections import deque
def main():
# 入力
readline = stdin.readline
n, m = list(map(int, readline().split()))
G = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, readline().split()))
G[a].append(b)
G[b].append(a)
# bfs
q = deque([tuple((1, 0))])
flags = [False] * (n + 1)
flags[1] = True
ans = False
while len(q) > 0:
now, d = q.popleft()
if now == n:
if d == 2:
ans = True
break
for nex in G[now]:
if flags[nex] == False:
flags[nex] = True
q.append(tuple((nex, d + 1)))
print(("POSSIBLE" if ans else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
| from sys import stdin
def main():
# 入力
readline = stdin.readline
n, m = list(map(int, readline().split()))
G = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, readline().split()))
G[a].append(b)
G[b].append(a)
s = set(G[1])
ans = False
while len(s) > 0:
now = s.pop()
for nex in G[now]:
if nex == n:
ans = True
break
print(("POSSIBLE" if ans else "IMPOSSIBLE"))
if __name__ == "__main__":
main()
| false | 25 | [
"-from collections import deque",
"- # bfs",
"- q = deque([tuple((1, 0))])",
"- flags = [False] * (n + 1)",
"- flags[1] = True",
"+ s = set(G[1])",
"- while len(q) > 0:",
"- now, d = q.popleft()",
"- if now == n:",
"- if d == 2:",
"+ while len(s) > 0... | false | 0.068867 | 0.038692 | 1.779881 | [
"s916604554",
"s400216681"
] |
u304050136 | p03197 | python | s522678948 | s815867035 | 194 | 52 | 3,060 | 7,828 | Accepted | Accepted | 73.2 | print(("second" if all(int(eval(input()))%2 == 0 for i in range(int(eval(input())))) else 'first'))
| import sys
print(('second' if all(i%2==0 for i in list(map(int,sys.stdin))[1:]) else 'first')) | 1 | 2 | 86 | 93 | print(
(
"second"
if all(int(eval(input())) % 2 == 0 for i in range(int(eval(input()))))
else "first"
)
)
| import sys
print(("second" if all(i % 2 == 0 for i in list(map(int, sys.stdin))[1:]) else "first"))
| false | 50 | [
"-print(",
"- (",
"- \"second\"",
"- if all(int(eval(input())) % 2 == 0 for i in range(int(eval(input()))))",
"- else \"first\"",
"- )",
"-)",
"+import sys",
"+",
"+print((\"second\" if all(i % 2 == 0 for i in list(map(int, sys.stdin))[1:]) else \"first\"))"
] | false | 0.036147 | 0.036599 | 0.987668 | [
"s522678948",
"s815867035"
] |
u922449550 | p03839 | python | s040582086 | s187678805 | 196 | 159 | 14,736 | 14,776 | Accepted | Accepted | 18.88 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]
s = sum(B[:K])
s_max = s
c = sum([1 for a in A[:K] if a <= 0])
c_max = c
for i in range(N-K):
s += B[i+K] - B[i]
s_max = max(s_max, s)
c += (A[i+K]<=0) - (A[i]<=0)
c_max = max(c_max, c)
if c_max == K:
print(ans)
quit()
B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N-K):
s += B[i+K] - B[i]
s_min = min(s_min, s)
print((max(ans+s_max, ans-s_min))) | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]
s = sum(B[:K])
s_max = s
for i in range(N-K):
s += B[i+K] - B[i]
s_max = max(s_max, s)
B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N-K):
s += B[i+K] - B[i]
s_min = min(s_min, s)
print((max(ans+s_max, ans-s_min))) | 28 | 20 | 561 | 412 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]
s = sum(B[:K])
s_max = s
c = sum([1 for a in A[:K] if a <= 0])
c_max = c
for i in range(N - K):
s += B[i + K] - B[i]
s_max = max(s_max, s)
c += (A[i + K] <= 0) - (A[i] <= 0)
c_max = max(c_max, c)
if c_max == K:
print(ans)
quit()
B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N - K):
s += B[i + K] - B[i]
s_min = min(s_min, s)
print((max(ans + s_max, ans - s_min)))
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]
s = sum(B[:K])
s_max = s
for i in range(N - K):
s += B[i + K] - B[i]
s_max = max(s_max, s)
B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N - K):
s += B[i + K] - B[i]
s_min = min(s_min, s)
print((max(ans + s_max, ans - s_min)))
| false | 28.571429 | [
"-c = sum([1 for a in A[:K] if a <= 0])",
"-c_max = c",
"- c += (A[i + K] <= 0) - (A[i] <= 0)",
"- c_max = max(c_max, c)",
"-if c_max == K:",
"- print(ans)",
"- quit()"
] | false | 0.046259 | 0.04617 | 1.001932 | [
"s040582086",
"s187678805"
] |
u607563136 | p02573 | python | s176725813 | s534512289 | 653 | 538 | 41,020 | 15,824 | Accepted | Accepted | 17.61 | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x,y = y,x
self.parents[x] += self.parents[y]
self.parents[y] = x
n, m = list(map(int,input().split()))
uf = UnionFind(n)
ab = [tuple(map(int,input().split())) for _ in range(m)]
for a,b in ab:
uf.union(a-1,b-1)
ans = -1
for i in uf.parents:
ans = min(i,ans)
print((-ans)) | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x,y = y,x
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
n, m = list(map(int,input().split()))
uf = UnionFind(n)
for i in range(m):
a,b = list(map(int,input().split()))
uf.union(a-1,b-1)
print((-min(list(uf.parents))))
main() | 39 | 34 | 834 | 817 | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
n, m = list(map(int, input().split()))
uf = UnionFind(n)
ab = [tuple(map(int, input().split())) for _ in range(m)]
for a, b in ab:
uf.union(a - 1, b - 1)
ans = -1
for i in uf.parents:
ans = min(i, ans)
print((-ans))
| class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def main():
n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
a, b = list(map(int, input().split()))
uf.union(a - 1, b - 1)
print((-min(list(uf.parents))))
main()
| false | 12.820513 | [
"-n, m = list(map(int, input().split()))",
"-uf = UnionFind(n)",
"-ab = [tuple(map(int, input().split())) for _ in range(m)]",
"-for a, b in ab:",
"- uf.union(a - 1, b - 1)",
"-ans = -1",
"-for i in uf.parents:",
"- ans = min(i, ans)",
"-print((-ans))",
"+def main():",
"+ n, m = list(ma... | false | 0.046188 | 0.04532 | 1.019151 | [
"s176725813",
"s534512289"
] |
u285681431 | p02954 | python | s539225914 | s525443847 | 115 | 96 | 12,488 | 79,400 | Accepted | Accepted | 16.52 | s = eval(input())
n = len(s)
boundary = []
ans = [0] * n
# "LR"を記録、Lの方のindexをboundaryにappend
for i in range(n - 1):
if s[i] == "L" and s[i + 1] == "R":
boundary.append(i)
# n-1があると後のfor文で都合が良いので足しておく
boundary.append(n - 1)
# RR...RLL...L の形に分割されている
l = 0
for r in boundary:
middle = 0
cnt = [0, 0]
for x in range(l, r + 1):
# xが偶数ならcnt[0], 奇数ならcnt[1]をincrement
cnt[x % 2] += 1
# "RL"を記録、Rの方のindexをmiddleに代入
if x < r and s[x] == "R" and s[x + 1] == "L":
middle = x
# indexが偶数のものが一か所に、奇数のものが別の一か所(左右隣り合う)に集約される
# middleが偶数の時
if middle % 2 == 0:
ans[middle] = cnt[0]
ans[middle + 1] = cnt[1]
# middleが奇数の時
elif middle % 2 == 1:
ans[middle] = cnt[1]
ans[middle + 1] = cnt[0]
l = r + 1
print((*ans))
| S = eval(input())
N = len(S)
# RR...RLL...L の形に分割したい
# 境界は"LR"となっているはず
# "LR"の"L"のindexを記録
boundary = []
for i in range(N - 1):
if S[i] == "L" and S[i + 1] == "R":
boundary.append(i)
# boundary は R..RL..Lの左端 として扱いたいので、N-1も追加
boundary.append(N - 1)
ans = [0] * N
l = 0
for r in boundary:
mid = 0
# [indexが偶数の個数, indexが奇数の個数]
cnt = [0, 0]
for x in range(l, r + 1):
cnt[x % 2] += 1
# R...RL...Lの"RL"の位置を探す
# "RL"の"R"のindexをmidに代入
if x < r and S[x] == "R" and S[x + 1] == "L":
mid = x
# 十分な操作をすると、indexの偶奇で[mid]か[mid+1]のどちらかに集まる
# midが偶数の場合
if mid % 2 == 0:
ans[mid] = cnt[0]
ans[mid + 1] = cnt[1]
# midが奇数の場合
elif mid % 2 == 1:
ans[mid] = cnt[1]
ans[mid + 1] = cnt[0]
# 次の区間の左端 = 今の区間の右端 + 1
l = r + 1
print((*ans))
| 38 | 43 | 854 | 887 | s = eval(input())
n = len(s)
boundary = []
ans = [0] * n
# "LR"を記録、Lの方のindexをboundaryにappend
for i in range(n - 1):
if s[i] == "L" and s[i + 1] == "R":
boundary.append(i)
# n-1があると後のfor文で都合が良いので足しておく
boundary.append(n - 1)
# RR...RLL...L の形に分割されている
l = 0
for r in boundary:
middle = 0
cnt = [0, 0]
for x in range(l, r + 1):
# xが偶数ならcnt[0], 奇数ならcnt[1]をincrement
cnt[x % 2] += 1
# "RL"を記録、Rの方のindexをmiddleに代入
if x < r and s[x] == "R" and s[x + 1] == "L":
middle = x
# indexが偶数のものが一か所に、奇数のものが別の一か所(左右隣り合う)に集約される
# middleが偶数の時
if middle % 2 == 0:
ans[middle] = cnt[0]
ans[middle + 1] = cnt[1]
# middleが奇数の時
elif middle % 2 == 1:
ans[middle] = cnt[1]
ans[middle + 1] = cnt[0]
l = r + 1
print((*ans))
| S = eval(input())
N = len(S)
# RR...RLL...L の形に分割したい
# 境界は"LR"となっているはず
# "LR"の"L"のindexを記録
boundary = []
for i in range(N - 1):
if S[i] == "L" and S[i + 1] == "R":
boundary.append(i)
# boundary は R..RL..Lの左端 として扱いたいので、N-1も追加
boundary.append(N - 1)
ans = [0] * N
l = 0
for r in boundary:
mid = 0
# [indexが偶数の個数, indexが奇数の個数]
cnt = [0, 0]
for x in range(l, r + 1):
cnt[x % 2] += 1
# R...RL...Lの"RL"の位置を探す
# "RL"の"R"のindexをmidに代入
if x < r and S[x] == "R" and S[x + 1] == "L":
mid = x
# 十分な操作をすると、indexの偶奇で[mid]か[mid+1]のどちらかに集まる
# midが偶数の場合
if mid % 2 == 0:
ans[mid] = cnt[0]
ans[mid + 1] = cnt[1]
# midが奇数の場合
elif mid % 2 == 1:
ans[mid] = cnt[1]
ans[mid + 1] = cnt[0]
# 次の区間の左端 = 今の区間の右端 + 1
l = r + 1
print((*ans))
| false | 11.627907 | [
"-s = eval(input())",
"-n = len(s)",
"+S = eval(input())",
"+N = len(S)",
"+# RR...RLL...L の形に分割したい",
"+# 境界は\"LR\"となっているはず",
"+# \"LR\"の\"L\"のindexを記録",
"-ans = [0] * n",
"-# \"LR\"を記録、Lの方のindexをboundaryにappend",
"-for i in range(n - 1):",
"- if s[i] == \"L\" and s[i + 1] == \"R\":",
"+for... | false | 0.038517 | 0.037738 | 1.020641 | [
"s539225914",
"s525443847"
] |
u771917453 | p02418 | python | s744392528 | s921407962 | 40 | 30 | 6,432 | 6,428 | Accepted | Accepted | 25 | a = input()
b = input()
a = a+a
if 0 < a.count(b):
print('Yes')
else:
print('No') | a = input()
b = input()
a = a+a
if 0 <= a.find(b):
print('Yes')
else:
print('No') | 7 | 7 | 101 | 101 | a = input()
b = input()
a = a + a
if 0 < a.count(b):
print("Yes")
else:
print("No")
| a = input()
b = input()
a = a + a
if 0 <= a.find(b):
print("Yes")
else:
print("No")
| false | 0 | [
"-if 0 < a.count(b):",
"+if 0 <= a.find(b):"
] | false | 0.185554 | 0.064963 | 2.856284 | [
"s744392528",
"s921407962"
] |
u067447457 | p02773 | python | s148421749 | s518526792 | 809 | 379 | 47,240 | 38,476 | Accepted | Accepted | 53.15 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
d = {}
for w in s:
if w not in d:
d[w] = 0
d[w] += 1
d2 = sorted(list(d.items()), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
print(ans) | from collections import Counter
stdin = open(0)
N = int(stdin.readline())
S = stdin.read().split()
counter = Counter(S)
max_cnt = max(counter.values())
names = [name for name, cnt in counter.items() if cnt == max_cnt]
names.sort()
print(*names, sep='\n')
| 12 | 14 | 283 | 277 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
d = {}
for w in s:
if w not in d:
d[w] = 0
d[w] += 1
d2 = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
print(ans)
| from collections import Counter
stdin = open(0)
N = int(stdin.readline())
S = stdin.read().split()
counter = Counter(S)
max_cnt = max(counter.values())
names = [name for name, cnt in counter.items() if cnt == max_cnt]
names.sort()
print(*names, sep="\n")
| false | 14.285714 | [
"-n = int(eval(input()))",
"-s = [eval(input()) for _ in range(n)]",
"-d = {}",
"-for w in s:",
"- if w not in d:",
"- d[w] = 0",
"- d[w] += 1",
"-d2 = sorted(list(d.items()), key=lambda x: x[1], reverse=True)",
"-maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]",
"-maxcnts.sort()",
... | false | 0.038486 | 0.040202 | 0.957299 | [
"s148421749",
"s518526792"
] |
u908763441 | p02629 | python | s872648760 | s455663907 | 83 | 66 | 61,752 | 61,640 | Accepted | Accepted | 20.48 | n = int(eval(input()))
s = 'abcdefghijklmnopqrstuvwxyz'
def calc(n, ans):
n, i = divmod((n - 1), 26)
ans = s[i] + ans
if (n > 0):
return calc(n, ans)
else:
return ans
ans = calc(n, '')
print(ans) | n = int(eval(input()))
s = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
while n > 0:
n, i = divmod(n - 1, 26)
ans = s[i] + ans
print(ans) | 15 | 7 | 223 | 134 | n = int(eval(input()))
s = "abcdefghijklmnopqrstuvwxyz"
def calc(n, ans):
n, i = divmod((n - 1), 26)
ans = s[i] + ans
if n > 0:
return calc(n, ans)
else:
return ans
ans = calc(n, "")
print(ans)
| n = int(eval(input()))
s = "abcdefghijklmnopqrstuvwxyz"
ans = ""
while n > 0:
n, i = divmod(n - 1, 26)
ans = s[i] + ans
print(ans)
| false | 53.333333 | [
"-",
"-",
"-def calc(n, ans):",
"- n, i = divmod((n - 1), 26)",
"+ans = \"\"",
"+while n > 0:",
"+ n, i = divmod(n - 1, 26)",
"- if n > 0:",
"- return calc(n, ans)",
"- else:",
"- return ans",
"-",
"-",
"-ans = calc(n, \"\")"
] | false | 0.056251 | 0.040633 | 1.384373 | [
"s872648760",
"s455663907"
] |
u761320129 | p03644 | python | s091085555 | s326685025 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | N = int(eval(input()))
k = len(bin(N))-3
print((2**k)) | N = int(eval(input()))
l = len(bin(N))-3
print((2**l)) | 3 | 3 | 48 | 48 | N = int(eval(input()))
k = len(bin(N)) - 3
print((2**k))
| N = int(eval(input()))
l = len(bin(N)) - 3
print((2**l))
| false | 0 | [
"-k = len(bin(N)) - 3",
"-print((2**k))",
"+l = len(bin(N)) - 3",
"+print((2**l))"
] | false | 0.046308 | 0.051685 | 0.895973 | [
"s091085555",
"s326685025"
] |
u151625340 | p03086 | python | s401666027 | s455859922 | 169 | 17 | 38,256 | 3,060 | Accepted | Accepted | 89.94 | S = eval(input())
ans = 0
l = 0
for i in range(len(S)):
if S[i] in ('A','C','G','T'):
l += 1
else:
ans = max(ans,l)
l = 0
ans = max(ans,l)
print(ans)
| S = eval(input())
ans = 0
now = 0
for i in range(len(S)):
if S[i] in ['A','T','G','C']:
now += 1
else:
ans = max(ans,now)
now = 0
ans = max(ans,now)
print(ans) | 11 | 11 | 186 | 195 | S = eval(input())
ans = 0
l = 0
for i in range(len(S)):
if S[i] in ("A", "C", "G", "T"):
l += 1
else:
ans = max(ans, l)
l = 0
ans = max(ans, l)
print(ans)
| S = eval(input())
ans = 0
now = 0
for i in range(len(S)):
if S[i] in ["A", "T", "G", "C"]:
now += 1
else:
ans = max(ans, now)
now = 0
ans = max(ans, now)
print(ans)
| false | 0 | [
"-l = 0",
"+now = 0",
"- if S[i] in (\"A\", \"C\", \"G\", \"T\"):",
"- l += 1",
"+ if S[i] in [\"A\", \"T\", \"G\", \"C\"]:",
"+ now += 1",
"- ans = max(ans, l)",
"- l = 0",
"-ans = max(ans, l)",
"+ ans = max(ans, now)",
"+ now = 0",
"+ans = max(... | false | 0.046261 | 0.084659 | 0.54644 | [
"s401666027",
"s455859922"
] |
u906501980 | p02661 | python | s114576519 | s739020920 | 459 | 373 | 29,408 | 99,060 | Accepted | Accepted | 18.74 | def main():
n = int(eval(input()))
al = []
bl = []
for _ in range(n):
a, b = list(map(int, input().split()))
al.append(a)
bl.append(b)
als = list(sorted(al))
bls = list(sorted(bl))
if n%2:
print((bls[n//2]-als[n//2]+1))
else:
print((bls[n//2-1]+bls[n//2]-als[n//2]-als[n//2-1]+1))
if __name__ == "__main__":
main() | def main():
n = int(eval(input()))
al = []
bl = []
for _ in range(n):
a, b = list(map(int, input().split()))
al.append(a)
bl.append(b)
al.sort()
bl.sort()
if n%2:
print((bl[n//2]-al[n//2]+1))
else:
print((bl[n//2]+bl[n//2-1]-al[n//2]-al[n//2-1]+1))
if __name__ == "__main__":
main() | 17 | 17 | 391 | 359 | def main():
n = int(eval(input()))
al = []
bl = []
for _ in range(n):
a, b = list(map(int, input().split()))
al.append(a)
bl.append(b)
als = list(sorted(al))
bls = list(sorted(bl))
if n % 2:
print((bls[n // 2] - als[n // 2] + 1))
else:
print((bls[n // 2 - 1] + bls[n // 2] - als[n // 2] - als[n // 2 - 1] + 1))
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
al = []
bl = []
for _ in range(n):
a, b = list(map(int, input().split()))
al.append(a)
bl.append(b)
al.sort()
bl.sort()
if n % 2:
print((bl[n // 2] - al[n // 2] + 1))
else:
print((bl[n // 2] + bl[n // 2 - 1] - al[n // 2] - al[n // 2 - 1] + 1))
if __name__ == "__main__":
main()
| false | 0 | [
"- als = list(sorted(al))",
"- bls = list(sorted(bl))",
"+ al.sort()",
"+ bl.sort()",
"- print((bls[n // 2] - als[n // 2] + 1))",
"+ print((bl[n // 2] - al[n // 2] + 1))",
"- print((bls[n // 2 - 1] + bls[n // 2] - als[n // 2] - als[n // 2 - 1] + 1))",
"+ print((... | false | 0.037265 | 0.037039 | 1.006089 | [
"s114576519",
"s739020920"
] |
u163783894 | p03583 | python | s725239204 | s989852900 | 1,602 | 99 | 9,208 | 65,936 | Accepted | Accepted | 93.82 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode('utf-8')
def main():
N = in_n()
for a in range(1, 3500):
for b in range(a, 3500):
t1 = N * a * b
t2 = 4 * a * b - N * (a + b)
if t2 == 0:
continue
else:
c = t1 / t2
if c.is_integer() and 1 <= c and c <= 3500:
print((a, b, int(c)))
exit()
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode('utf-8')
def main():
N = in_n()
for a in range(1, 3500):
for b in range(a, 3500):
t1 = N * a * b
t2 = 4 * a * b - N * (a + b)
if t2 == 0:
continue
else:
c = t1 / t2
if c.is_integer() and 1 <= c:
print((a, b, int(c)))
exit()
if __name__ == '__main__':
main()
| 30 | 30 | 749 | 735 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode("utf-8")
def main():
N = in_n()
for a in range(1, 3500):
for b in range(a, 3500):
t1 = N * a * b
t2 = 4 * a * b - N * (a + b)
if t2 == 0:
continue
else:
c = t1 / t2
if c.is_integer() and 1 <= c and c <= 3500:
print((a, b, int(c)))
exit()
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode("utf-8")
def main():
N = in_n()
for a in range(1, 3500):
for b in range(a, 3500):
t1 = N * a * b
t2 = 4 * a * b - N * (a + b)
if t2 == 0:
continue
else:
c = t1 / t2
if c.is_integer() and 1 <= c:
print((a, b, int(c)))
exit()
if __name__ == "__main__":
main()
| false | 0 | [
"- if c.is_integer() and 1 <= c and c <= 3500:",
"+ if c.is_integer() and 1 <= c:"
] | false | 2.014235 | 0.47264 | 4.261666 | [
"s725239204",
"s989852900"
] |
u608241985 | p02613 | python | s410220792 | s823817401 | 146 | 31 | 16,256 | 9,540 | Accepted | Accepted | 78.77 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
res = ["AC", "WA", "TLE", "RE"]
for r in res:
print((r, "x", s.count(r))) | s = open(0).read().count
for r in "AC", "WA", "TLE", "RE":
print((r, "x", s(r))) | 6 | 3 | 130 | 84 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
res = ["AC", "WA", "TLE", "RE"]
for r in res:
print((r, "x", s.count(r)))
| s = open(0).read().count
for r in "AC", "WA", "TLE", "RE":
print((r, "x", s(r)))
| false | 50 | [
"-n = int(eval(input()))",
"-s = [eval(input()) for _ in range(n)]",
"-res = [\"AC\", \"WA\", \"TLE\", \"RE\"]",
"-for r in res:",
"- print((r, \"x\", s.count(r)))",
"+s = open(0).read().count",
"+for r in \"AC\", \"WA\", \"TLE\", \"RE\":",
"+ print((r, \"x\", s(r)))"
] | false | 0.050723 | 0.038906 | 1.303716 | [
"s410220792",
"s823817401"
] |
u869790980 | p03673 | python | s410987866 | s340901198 | 457 | 409 | 147,248 | 130,592 | Accepted | Accepted | 10.5 | import collections
n,rev,q = int(input()) ,False,collections.deque()
class Node(object):
def __init__(self, val):
self.val = val
self.next = None
self.prev = None
head = None
tail = None
for ai in map(int, input().split()):
if head is None:
node = Node(ai)
head = node
tail = node
else:
node = Node(ai)
if rev:
head.prev = node
node.next= head
head = node
else:
tail.next = node
node.prev= tail
tail = node
rev ^= True
cur = head
temp = []
while(cur):
temp.append(cur.val)
cur = cur.__next__
print(' '.join(map(str, temp[::-1 if rev else 1]))) | import collections
n,rev = int(input()) ,False
class Node(object):
def __init__(self, val):
self.val = val
self.next, self.prev = None, None
for i,ai in enumerate(map(int, input().split())):
node = Node(ai)
if i == 0:
head,tail = node,node
else:
if rev:
head.prev, node.next = node, head
head = node
else:
tail.next, node.prev = node, tail
tail = node
rev ^= True
cur = head if not(rev) else tail
while(cur):
print(cur.val, end=' ')
cur = cur.__next__ if not(rev) else cur.prev
| 34 | 24 | 629 | 535 | import collections
n, rev, q = int(input()), False, collections.deque()
class Node(object):
def __init__(self, val):
self.val = val
self.next = None
self.prev = None
head = None
tail = None
for ai in map(int, input().split()):
if head is None:
node = Node(ai)
head = node
tail = node
else:
node = Node(ai)
if rev:
head.prev = node
node.next = head
head = node
else:
tail.next = node
node.prev = tail
tail = node
rev ^= True
cur = head
temp = []
while cur:
temp.append(cur.val)
cur = cur.__next__
print(" ".join(map(str, temp[:: -1 if rev else 1])))
| import collections
n, rev = int(input()), False
class Node(object):
def __init__(self, val):
self.val = val
self.next, self.prev = None, None
for i, ai in enumerate(map(int, input().split())):
node = Node(ai)
if i == 0:
head, tail = node, node
else:
if rev:
head.prev, node.next = node, head
head = node
else:
tail.next, node.prev = node, tail
tail = node
rev ^= True
cur = head if not (rev) else tail
while cur:
print(cur.val, end=" ")
cur = cur.__next__ if not (rev) else cur.prev
| false | 29.411765 | [
"-n, rev, q = int(input()), False, collections.deque()",
"+n, rev = int(input()), False",
"- self.next = None",
"- self.prev = None",
"+ self.next, self.prev = None, None",
"-head = None",
"-tail = None",
"-for ai in map(int, input().split()):",
"- if head is None:",
"- ... | false | 0.082218 | 0.085166 | 0.965396 | [
"s410987866",
"s340901198"
] |
u347640436 | p02947 | python | s232410484 | s434579057 | 359 | 241 | 19,764 | 19,748 | Accepted | Accepted | 32.87 | from collections import Counter
n = int(eval(input()))
t = Counter([''.join(sorted(eval(input()))) for _ in range(n)])
print((sum(t[k] * (t[k] -1) // 2 for k in t)))
| def main():
from collections import Counter
from sys import stdin
readline = stdin.readline
N = int(readline())
t = Counter([''.join(sorted(readline()[:-1])) for _ in range(N)])
print((sum(t[k] * (t[k] - 1) // 2 for k in t)))
main()
| 4 | 8 | 155 | 250 | from collections import Counter
n = int(eval(input()))
t = Counter(["".join(sorted(eval(input()))) for _ in range(n)])
print((sum(t[k] * (t[k] - 1) // 2 for k in t)))
| def main():
from collections import Counter
from sys import stdin
readline = stdin.readline
N = int(readline())
t = Counter(["".join(sorted(readline()[:-1])) for _ in range(N)])
print((sum(t[k] * (t[k] - 1) // 2 for k in t)))
main()
| false | 50 | [
"-from collections import Counter",
"+def main():",
"+ from collections import Counter",
"+ from sys import stdin",
"-n = int(eval(input()))",
"-t = Counter([\"\".join(sorted(eval(input()))) for _ in range(n)])",
"-print((sum(t[k] * (t[k] - 1) // 2 for k in t)))",
"+ readline = stdin.readline... | false | 0.036961 | 0.088872 | 0.415891 | [
"s232410484",
"s434579057"
] |
u620868411 | p03044 | python | s282921977 | s089690601 | 1,036 | 780 | 38,828 | 45,976 | Accepted | Accepted | 24.71 | # -*- coding: utf-8 -*-
n = int(eval(input()))
edge = [[] for _ in range(n)]
for _ in range(n-1):
u,v,w = list(map(int, input().split()))
u -= 1
v -= 1
edge[u].append((v,w))
edge[v].append((u,w))
res = [-1]*n
res[0] = 0
q = [0]
while len(q)>0:
u = q.pop(0)
if len(edge[u])==0:
continue
for v,w in edge[u]:
if res[v]!=-1:
continue
if w%2==0:
res[v] = res[u]
else:
res[v] = (res[u]+1)%2
q.append(v)
for r in res:
print(r)
| # -*- coding: utf-8 -*-
from collections import defaultdict
n = int(eval(input()))
e = defaultdict(lambda: [])
for _ in range(n-1):
v,u,w = list(map(int, input().split()))
v -= 1
u -= 1
e[v].append((u,w))
e[u].append((v,w))
col = [-1]*n
q = [0]
col[0] = 0
while len(q)>0:
v = q.pop()
for u,w in e[v]:
if col[u]<0:
if w%2==1:
col[u] = (col[v]+1)%2
else:
col[u] = col[v]
q.append(u)
print((*col)) | 29 | 26 | 551 | 512 | # -*- coding: utf-8 -*-
n = int(eval(input()))
edge = [[] for _ in range(n)]
for _ in range(n - 1):
u, v, w = list(map(int, input().split()))
u -= 1
v -= 1
edge[u].append((v, w))
edge[v].append((u, w))
res = [-1] * n
res[0] = 0
q = [0]
while len(q) > 0:
u = q.pop(0)
if len(edge[u]) == 0:
continue
for v, w in edge[u]:
if res[v] != -1:
continue
if w % 2 == 0:
res[v] = res[u]
else:
res[v] = (res[u] + 1) % 2
q.append(v)
for r in res:
print(r)
| # -*- coding: utf-8 -*-
from collections import defaultdict
n = int(eval(input()))
e = defaultdict(lambda: [])
for _ in range(n - 1):
v, u, w = list(map(int, input().split()))
v -= 1
u -= 1
e[v].append((u, w))
e[u].append((v, w))
col = [-1] * n
q = [0]
col[0] = 0
while len(q) > 0:
v = q.pop()
for u, w in e[v]:
if col[u] < 0:
if w % 2 == 1:
col[u] = (col[v] + 1) % 2
else:
col[u] = col[v]
q.append(u)
print((*col))
| false | 10.344828 | [
"+from collections import defaultdict",
"+",
"-edge = [[] for _ in range(n)]",
"+e = defaultdict(lambda: [])",
"- u, v, w = list(map(int, input().split()))",
"+ v, u, w = list(map(int, input().split()))",
"+ v -= 1",
"- v -= 1",
"- edge[u].append((v, w))",
"- edge[v].append((u, w... | false | 0.039168 | 0.044329 | 0.883577 | [
"s282921977",
"s089690601"
] |
u729939940 | p02911 | python | s613298578 | s287382425 | 209 | 68 | 11,316 | 12,624 | Accepted | Accepted | 67.46 | N, K, Q = list(map(int, input().split()))
A = []
for q in range(Q):
A.append(int(eval(input())))
score = [K - Q] * (N + 1)
for a in A:
score[a] += 1
ans = "\n".join("No" if s <= 0 else "Yes" for s in score[1:])
print(ans) | import sys
N, K, Q = list(map(int, input().split()))
A = (int(x) for x in sys.stdin.read().split())
score = [K - Q] * (N + 1)
for a in A:
score[a] += 1
ans = "\n".join("No" if s <= 0 else "Yes" for s in score[1:])
print(ans) | 9 | 8 | 225 | 229 | N, K, Q = list(map(int, input().split()))
A = []
for q in range(Q):
A.append(int(eval(input())))
score = [K - Q] * (N + 1)
for a in A:
score[a] += 1
ans = "\n".join("No" if s <= 0 else "Yes" for s in score[1:])
print(ans)
| import sys
N, K, Q = list(map(int, input().split()))
A = (int(x) for x in sys.stdin.read().split())
score = [K - Q] * (N + 1)
for a in A:
score[a] += 1
ans = "\n".join("No" if s <= 0 else "Yes" for s in score[1:])
print(ans)
| false | 11.111111 | [
"+import sys",
"+",
"-A = []",
"-for q in range(Q):",
"- A.append(int(eval(input())))",
"+A = (int(x) for x in sys.stdin.read().split())"
] | false | 0.128352 | 0.03655 | 3.511707 | [
"s613298578",
"s287382425"
] |
u644516473 | p03575 | python | s285267490 | s809944377 | 122 | 25 | 3,444 | 3,316 | Accepted | Accepted | 79.51 | from collections import deque
N, M = list(map(int, input().split()))
V = [list(map(int, input().split())) for _ in range(M)]
class UnionFind():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
ans = 0
for i in range(N):
for j in range(i+1, N):
uf = UnionFind(N)
for a, b in V:
if a-1 == i and b-1 ==j:
continue
uf.union(a-1, b-1)
if not uf.same(i, j):
ans += 1
print(ans)
| from collections import deque
N, M = list(map(int, input().split()))
V = [list(map(int, input().split())) for _ in range(M)]
class UnionFind():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
ans = 0
for i in range(M):
uf = UnionFind(N)
for j, (a, b) in enumerate(V):
if i != j:
uf.union(a-1, b-1)
if not uf.same(V[i][0]-1, V[i][1]-1):
ans += 1
print(ans)
| 46 | 44 | 1,110 | 1,077 | from collections import deque
N, M = list(map(int, input().split()))
V = [list(map(int, input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
ans = 0
for i in range(N):
for j in range(i + 1, N):
uf = UnionFind(N)
for a, b in V:
if a - 1 == i and b - 1 == j:
continue
uf.union(a - 1, b - 1)
if not uf.same(i, j):
ans += 1
print(ans)
| from collections import deque
N, M = list(map(int, input().split()))
V = [list(map(int, input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
ans = 0
for i in range(M):
uf = UnionFind(N)
for j, (a, b) in enumerate(V):
if i != j:
uf.union(a - 1, b - 1)
if not uf.same(V[i][0] - 1, V[i][1] - 1):
ans += 1
print(ans)
| false | 4.347826 | [
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- uf = UnionFind(N)",
"- for a, b in V:",
"- if a - 1 == i and b - 1 == j:",
"- continue",
"+for i in range(M):",
"+ uf = UnionFind(N)",
"+ for j, (a, b) in enumerate(V):",
"+ if i != j:"... | false | 0.084919 | 0.037192 | 2.283246 | [
"s285267490",
"s809944377"
] |
u006657459 | p03240 | python | s354863850 | s698195549 | 38 | 30 | 4,324 | 3,064 | Accepted | Accepted | 21.05 | N = int(eval(input()))
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
xi, yi, hi = list(map(int, input().split()))
if hi == 0:
x2.append(xi)
y2.append(yi)
h2.append(hi)
else:
x.append(xi)
y.append(yi)
h.append(hi)
def fn(H, X, Y, Cx, Cy):
return H + abs(Cx - X) + abs(Cy - Y)
heights = []
for Cx in range(101):
for Cy in range(101):
H = fn(h[0], x[0], y[0], Cx, Cy)
heights.append([H, Cx, Cy])
if len(h) == 1:
continue
flag = True
for i in range(1, len(h)):
if H != fn(h[i], x[i], y[i], Cx, Cy):
flag = False
break
if flag:
print((Cx, Cy, H))
exit()
print((x[0], y[0], h[0])) | N = int(eval(input()))
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
xi, yi, hi = list(map(int, input().split()))
if hi != 0:
x.append(xi)
y.append(yi)
h.append(hi)
def fn(H, X, Y, Cx, Cy):
return H + abs(Cx - X) + abs(Cy - Y)
if len(h) == 1:
print((x[0], y[0], h[0]))
exit()
for Cx in range(101):
for Cy in range(101):
H = fn(h[0], x[0], y[0], Cx, Cy)
flag = True
for i in range(1, len(h)):
if H != fn(h[i], x[i], y[i], Cx, Cy):
flag = False
break
if flag:
print((Cx, Cy, H))
exit()
| 35 | 31 | 810 | 670 | N = int(eval(input()))
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
xi, yi, hi = list(map(int, input().split()))
if hi == 0:
x2.append(xi)
y2.append(yi)
h2.append(hi)
else:
x.append(xi)
y.append(yi)
h.append(hi)
def fn(H, X, Y, Cx, Cy):
return H + abs(Cx - X) + abs(Cy - Y)
heights = []
for Cx in range(101):
for Cy in range(101):
H = fn(h[0], x[0], y[0], Cx, Cy)
heights.append([H, Cx, Cy])
if len(h) == 1:
continue
flag = True
for i in range(1, len(h)):
if H != fn(h[i], x[i], y[i], Cx, Cy):
flag = False
break
if flag:
print((Cx, Cy, H))
exit()
print((x[0], y[0], h[0]))
| N = int(eval(input()))
x, y, h = [], [], []
x2, y2, h2 = [], [], []
for i in range(N):
xi, yi, hi = list(map(int, input().split()))
if hi != 0:
x.append(xi)
y.append(yi)
h.append(hi)
def fn(H, X, Y, Cx, Cy):
return H + abs(Cx - X) + abs(Cy - Y)
if len(h) == 1:
print((x[0], y[0], h[0]))
exit()
for Cx in range(101):
for Cy in range(101):
H = fn(h[0], x[0], y[0], Cx, Cy)
flag = True
for i in range(1, len(h)):
if H != fn(h[i], x[i], y[i], Cx, Cy):
flag = False
break
if flag:
print((Cx, Cy, H))
exit()
| false | 11.428571 | [
"- if hi == 0:",
"- x2.append(xi)",
"- y2.append(yi)",
"- h2.append(hi)",
"- else:",
"+ if hi != 0:",
"-heights = []",
"+if len(h) == 1:",
"+ print((x[0], y[0], h[0]))",
"+ exit()",
"- heights.append([H, Cx, Cy])",
"- if len(h) == 1:",
"- ... | false | 0.038644 | 0.042297 | 0.913629 | [
"s354863850",
"s698195549"
] |
u906501980 | p03372 | python | s867484021 | s432678406 | 744 | 675 | 54,000 | 71,512 | Accepted | Accepted | 9.27 | from numpy import array as n
N, C = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum = 0
for x, cal in xy:
sum += cal
r1.append(max(r1[-1], sum-x))
r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
sum += cal
l1.append(max(l1[-1], sum-C+x))
l2.append(max(l2[-1], sum-2*(C-x)))
out = max(n(r1+r2)+n(l2[::-1]+l1[::-1]))
print(out) | def main():
n, c = list(map(int, input().split()))
xv = [list(map(int, input().split())) for _ in range(n)]
v, left_max, right_max = 0, 0, 0
gl = [None]*n
gr = [None]*n
_2oas = [None]*(n+1)
_2obs = [None]*(n+1)
_2oas[0], _2obs[0] = 0, 0
ans = 0
for i, (xi, vi) in enumerate(xv):
v += vi
left = v - xi
if left_max < left:
left_max = left
gl[i] = left_max
_2oas[i+1] = v - 2*xi
v = 0
for i, (xi, vi) in enumerate(xv[::-1]):
v += vi
right = v - c + xi
if right_max < right:
right_max = right
gr[i] = right_max
_2obs[i+1] = v - 2*(c - xi)
for i in range(1, n+1):
oa = gl[-i]
_2ob = _2obs[i-1]
ob = gr[-i]
_2oa = _2oas[i-1]
if ans < _2oa+ob:
ans = _2oa+ob
if ans < _2ob+oa:
ans = _2ob+oa
print(ans)
if __name__ == "__main__":
main() | 16 | 38 | 452 | 1,003 | from numpy import array as n
N, C = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0], [0], [0], [0]
sum = 0
for x, cal in xy:
sum += cal
r1.append(max(r1[-1], sum - x))
r2.append(max(r2[-1], sum - 2 * x))
sum = 0
for x, cal in xy[::-1]:
sum += cal
l1.append(max(l1[-1], sum - C + x))
l2.append(max(l2[-1], sum - 2 * (C - x)))
out = max(n(r1 + r2) + n(l2[::-1] + l1[::-1]))
print(out)
| def main():
n, c = list(map(int, input().split()))
xv = [list(map(int, input().split())) for _ in range(n)]
v, left_max, right_max = 0, 0, 0
gl = [None] * n
gr = [None] * n
_2oas = [None] * (n + 1)
_2obs = [None] * (n + 1)
_2oas[0], _2obs[0] = 0, 0
ans = 0
for i, (xi, vi) in enumerate(xv):
v += vi
left = v - xi
if left_max < left:
left_max = left
gl[i] = left_max
_2oas[i + 1] = v - 2 * xi
v = 0
for i, (xi, vi) in enumerate(xv[::-1]):
v += vi
right = v - c + xi
if right_max < right:
right_max = right
gr[i] = right_max
_2obs[i + 1] = v - 2 * (c - xi)
for i in range(1, n + 1):
oa = gl[-i]
_2ob = _2obs[i - 1]
ob = gr[-i]
_2oa = _2oas[i - 1]
if ans < _2oa + ob:
ans = _2oa + ob
if ans < _2ob + oa:
ans = _2ob + oa
print(ans)
if __name__ == "__main__":
main()
| false | 57.894737 | [
"-from numpy import array as n",
"+def main():",
"+ n, c = list(map(int, input().split()))",
"+ xv = [list(map(int, input().split())) for _ in range(n)]",
"+ v, left_max, right_max = 0, 0, 0",
"+ gl = [None] * n",
"+ gr = [None] * n",
"+ _2oas = [None] * (n + 1)",
"+ _2obs = [No... | false | 0.178889 | 0.043274 | 4.133889 | [
"s867484021",
"s432678406"
] |
u222668979 | p03031 | python | s156530530 | s664445382 | 211 | 38 | 42,480 | 9,204 | Accepted | Accepted | 81.99 | from itertools import product
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cnt = 0
for pat in product([0, 1], repeat=n):
for i in range(m):
if sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0])) % 2 != p[i]:
break
else:
cnt += 1
print(cnt)
| from itertools import product
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cnt = 0
for pat in product([0, 1], repeat=n):
for i in range(m):
tmp = sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0]))
if tmp % 2 != p[i]:
break
else:
cnt += 1
print(cnt)
| 15 | 15 | 374 | 392 | from itertools import product
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cnt = 0
for pat in product([0, 1], repeat=n):
for i in range(m):
if sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0])) % 2 != p[i]:
break
else:
cnt += 1
print(cnt)
| from itertools import product
n, m = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cnt = 0
for pat in product([0, 1], repeat=n):
for i in range(m):
tmp = sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0]))
if tmp % 2 != p[i]:
break
else:
cnt += 1
print(cnt)
| false | 0 | [
"- if sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0])) % 2 != p[i]:",
"+ tmp = sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0]))",
"+ if tmp % 2 != p[i]:"
] | false | 0.037802 | 0.165109 | 0.228953 | [
"s156530530",
"s664445382"
] |
u597622207 | p02873 | python | s166304556 | s112639101 | 508 | 246 | 34,612 | 12,956 | Accepted | Accepted | 51.57 | S = list(eval(input()))
L = len(S)
count = 0
count_minus = [0] * L
for i in range(L):
if S[i] == ">":
count = 0
else:
count += 1
count_minus[i] = count
count = 0
count_plus = [0] * L
for i in reversed(list(range(L))):
if S[i] == "<":
count = 0
else:
count += 1
count_plus[i] = count
result_list = [0] * (L-1)
for i in range(len(result_list)):
result_list[i] = max(count_minus[i], count_plus[i+1])
result = sum(result_list) + count_minus[L-1] + count_plus[0]
print(result) | s = eval(input())
partition = s.replace('><','>|<').split('|')
ans=0
for sub in partition:
left = sub.count('<')
right = sub.count('>')
ans += sum(range(1, max(left, right) + 1))
ans += sum(range(1, min(left, right)))
print(ans) | 26 | 11 | 548 | 250 | S = list(eval(input()))
L = len(S)
count = 0
count_minus = [0] * L
for i in range(L):
if S[i] == ">":
count = 0
else:
count += 1
count_minus[i] = count
count = 0
count_plus = [0] * L
for i in reversed(list(range(L))):
if S[i] == "<":
count = 0
else:
count += 1
count_plus[i] = count
result_list = [0] * (L - 1)
for i in range(len(result_list)):
result_list[i] = max(count_minus[i], count_plus[i + 1])
result = sum(result_list) + count_minus[L - 1] + count_plus[0]
print(result)
| s = eval(input())
partition = s.replace("><", ">|<").split("|")
ans = 0
for sub in partition:
left = sub.count("<")
right = sub.count(">")
ans += sum(range(1, max(left, right) + 1))
ans += sum(range(1, min(left, right)))
print(ans)
| false | 57.692308 | [
"-S = list(eval(input()))",
"-L = len(S)",
"-count = 0",
"-count_minus = [0] * L",
"-for i in range(L):",
"- if S[i] == \">\":",
"- count = 0",
"- else:",
"- count += 1",
"- count_minus[i] = count",
"-count = 0",
"-count_plus = [0] * L",
"-for i in reversed(list(range(... | false | 0.042842 | 0.150439 | 0.284781 | [
"s166304556",
"s112639101"
] |
u852690916 | p03044 | python | s992575731 | s220456324 | 496 | 392 | 67,120 | 67,232 | Accepted | Accepted | 20.97 | import sys
def main():
input = sys.stdin.readline
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N-1):
u,v,w = list(map(int, input().split()))
u,v = u-1,v-1
G[u].append((v,w))
G[v].append((u,w))
ans = [-1] * N
ans[0] = 0
stack = [(0,0)]
while stack:
v, w = stack.pop()
for to, to_w in G[v]:
if ans[to] >= 0: continue
ans[to] = 1 if (w + to_w) & 1 else 0
stack.append((to, w + to_w))
for a in ans: print(a)
if __name__ == '__main__':
main() | def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
a, b, c = (int(i) for i in input().split())
edge[a-1].append((c % 2, b-1))
edge[b-1].append((c % 2, a-1))
dist = [-1]*N
color = [-1]*N
def dfs(v, G):
todo = []
dist[v] = 0
color[v] = 0
todo.append((v, 0)) #最初は0でappend
while todo:
u, s = todo.pop() #ここでpopしちゃう
if s == 0:
# s==0: 潜っていく時の処理
todo.append((u, 1)) #1でappendして戻り処理の仕込み
for c, next_v in G[u]:
if dist[next_v] != -1:
continue
dist[next_v] = dist[u] + c
if dist[next_v] % 2 == 1:
color[next_v] = 1
else:
color[next_v] = 0
todo.append((next_v, 0))
#break
#else:
# s==1: 戻ってくる時の処理(この問題では特にやることなし)
dfs(0, edge)
print(*color, sep="\n")
# print("\n", *dist, sep="\n")
if __name__ == '__main__':
main()
| 25 | 43 | 600 | 1,229 | import sys
def main():
input = sys.stdin.readline
N = int(eval(input()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
u, v, w = list(map(int, input().split()))
u, v = u - 1, v - 1
G[u].append((v, w))
G[v].append((u, w))
ans = [-1] * N
ans[0] = 0
stack = [(0, 0)]
while stack:
v, w = stack.pop()
for to, to_w in G[v]:
if ans[to] >= 0:
continue
ans[to] = 1 if (w + to_w) & 1 else 0
stack.append((to, w + to_w))
for a in ans:
print(a)
if __name__ == "__main__":
main()
| def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
a, b, c = (int(i) for i in input().split())
edge[a - 1].append((c % 2, b - 1))
edge[b - 1].append((c % 2, a - 1))
dist = [-1] * N
color = [-1] * N
def dfs(v, G):
todo = []
dist[v] = 0
color[v] = 0
todo.append((v, 0)) # 最初は0でappend
while todo:
u, s = todo.pop() # ここでpopしちゃう
if s == 0:
# s==0: 潜っていく時の処理
todo.append((u, 1)) # 1でappendして戻り処理の仕込み
for c, next_v in G[u]:
if dist[next_v] != -1:
continue
dist[next_v] = dist[u] + c
if dist[next_v] % 2 == 1:
color[next_v] = 1
else:
color[next_v] = 0
todo.append((next_v, 0))
# break
# else:
# s==1: 戻ってくる時の処理(この問題では特にやることなし)
dfs(0, edge)
print(*color, sep="\n")
# print("\n", *dist, sep="\n")
if __name__ == "__main__":
main()
| false | 41.860465 | [
"-import sys",
"+def main():",
"+ import sys",
"+ input = sys.stdin.buffer.readline",
"+ N = int(input())",
"+ edge = [[] for _ in range(N)]",
"+ for i in range(N - 1):",
"+ a, b, c = (int(i) for i in input().split())",
"+ edge[a - 1].append((c % 2, b - 1))",
"+ ... | false | 0.110053 | 0.036155 | 3.043915 | [
"s992575731",
"s220456324"
] |
u780475861 | p03613 | python | s811000581 | s021207953 | 273 | 109 | 25,292 | 25,572 | Accepted | Accepted | 60.07 | import sys
import bisect
def main():
n, *a = list(map(int, sys.stdin.read().split()))
lr = [[i - 1,i + 1] for i in a]
lr.sort(key=lambda x: x[0])
l = [i[0] for i in lr]
res = 0
for i in range(n):
right = bisect.bisect(l, lr[i][1])
left = bisect.bisect_left(l, l[i])
res = max(res, right - left)
print(res)
if __name__ == '__main__':
main() | import sys
from itertools import accumulate
def main():
n, *A = list(map(int, sys.stdin.read().split()))
minA = min(A) - 1
lr = [[i - 1 - minA, i + 1 - minA] for i in A]
lst = [0] * (max(A) - minA + 3)
for i, j in lr:
lst[i] += 1
lst[j + 1] -= 1
lst = list(accumulate(lst))
print((max(lst)))
if __name__ == '__main__':
main() | 19 | 18 | 411 | 386 | import sys
import bisect
def main():
n, *a = list(map(int, sys.stdin.read().split()))
lr = [[i - 1, i + 1] for i in a]
lr.sort(key=lambda x: x[0])
l = [i[0] for i in lr]
res = 0
for i in range(n):
right = bisect.bisect(l, lr[i][1])
left = bisect.bisect_left(l, l[i])
res = max(res, right - left)
print(res)
if __name__ == "__main__":
main()
| import sys
from itertools import accumulate
def main():
n, *A = list(map(int, sys.stdin.read().split()))
minA = min(A) - 1
lr = [[i - 1 - minA, i + 1 - minA] for i in A]
lst = [0] * (max(A) - minA + 3)
for i, j in lr:
lst[i] += 1
lst[j + 1] -= 1
lst = list(accumulate(lst))
print((max(lst)))
if __name__ == "__main__":
main()
| false | 5.263158 | [
"-import bisect",
"+from itertools import accumulate",
"- n, *a = list(map(int, sys.stdin.read().split()))",
"- lr = [[i - 1, i + 1] for i in a]",
"- lr.sort(key=lambda x: x[0])",
"- l = [i[0] for i in lr]",
"- res = 0",
"- for i in range(n):",
"- right = bisect.bisect(l, lr... | false | 0.048164 | 0.083969 | 0.573601 | [
"s811000581",
"s021207953"
] |
u940139461 | p03944 | python | s867134626 | s528221986 | 213 | 167 | 43,500 | 38,256 | Accepted | Accepted | 21.6 | # https://atcoder.jp/contests/abc047/tasks/abc047_b
w, h, n = list(map(int, input().split()))
area = [[0] * w for _ in range(h)]
for _ in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
for i in range(h):
for j in range(w):
if j < x:
area[i][j] = 1
if a == 2:
for i in range(h):
for j in range(w):
if j >= x:
area[i][j] = 1
if a == 3:
for i in range(h):
for j in range(w):
if i < y:
area[i][j] = 1
if a == 4:
for i in range(h):
for j in range(w):
if i >= y:
area[i][j] = 1
ans = 0
for i in range(h):
for j in range(w):
if area[i][j] == 0:
ans += 1
print(ans) | w, h, n = list(map(int, input().split()))
left_x = 0
right_x = w
up_y = h
down_y = 0
for _ in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
left_x = max(left_x, x)
elif a == 2:
right_x = min(right_x, x)
elif a == 3:
down_y = max(down_y, y)
else:
up_y = min(up_y, y)
if right_x - left_x > 0 and up_y - down_y > 0:
ans = (right_x - left_x) * (up_y - down_y)
else:
ans = 0
print(ans) | 37 | 21 | 871 | 466 | # https://atcoder.jp/contests/abc047/tasks/abc047_b
w, h, n = list(map(int, input().split()))
area = [[0] * w for _ in range(h)]
for _ in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
for i in range(h):
for j in range(w):
if j < x:
area[i][j] = 1
if a == 2:
for i in range(h):
for j in range(w):
if j >= x:
area[i][j] = 1
if a == 3:
for i in range(h):
for j in range(w):
if i < y:
area[i][j] = 1
if a == 4:
for i in range(h):
for j in range(w):
if i >= y:
area[i][j] = 1
ans = 0
for i in range(h):
for j in range(w):
if area[i][j] == 0:
ans += 1
print(ans)
| w, h, n = list(map(int, input().split()))
left_x = 0
right_x = w
up_y = h
down_y = 0
for _ in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
left_x = max(left_x, x)
elif a == 2:
right_x = min(right_x, x)
elif a == 3:
down_y = max(down_y, y)
else:
up_y = min(up_y, y)
if right_x - left_x > 0 and up_y - down_y > 0:
ans = (right_x - left_x) * (up_y - down_y)
else:
ans = 0
print(ans)
| false | 43.243243 | [
"-# https://atcoder.jp/contests/abc047/tasks/abc047_b",
"-area = [[0] * w for _ in range(h)]",
"+left_x = 0",
"+right_x = w",
"+up_y = h",
"+down_y = 0",
"- for i in range(h):",
"- for j in range(w):",
"- if j < x:",
"- area[i][j] = 1",
"- i... | false | 0.063936 | 0.101944 | 0.627169 | [
"s867134626",
"s528221986"
] |
u036514535 | p02744 | python | s793815288 | s768774317 | 561 | 134 | 4,404 | 4,412 | Accepted | Accepted | 76.11 | def p(S):
str = ""
for s in S:
str += chr(ord("a")+int(s))
print(str)
N = int(eval(input()))
S = [0]*N
def up(i):
if i == 0:
return True
S[i] += 1
if S[i] == max(S[:i]) + 2:
S[i] = 0
return up(i-1)
return False
while True:
p(S)
if up(N-1):
break
| N = int(eval(input()))
def dfs(s, mx):
if len(s) == N:
print(s)
else:
for c in range(ord("a"),mx+1):
if c == mx:
dfs(s+chr(c),mx+1)
else:
dfs(s+chr(c),mx)
dfs("",ord("a"))
| 22 | 13 | 340 | 260 | def p(S):
str = ""
for s in S:
str += chr(ord("a") + int(s))
print(str)
N = int(eval(input()))
S = [0] * N
def up(i):
if i == 0:
return True
S[i] += 1
if S[i] == max(S[:i]) + 2:
S[i] = 0
return up(i - 1)
return False
while True:
p(S)
if up(N - 1):
break
| N = int(eval(input()))
def dfs(s, mx):
if len(s) == N:
print(s)
else:
for c in range(ord("a"), mx + 1):
if c == mx:
dfs(s + chr(c), mx + 1)
else:
dfs(s + chr(c), mx)
dfs("", ord("a"))
| false | 40.909091 | [
"-def p(S):",
"- str = \"\"",
"- for s in S:",
"- str += chr(ord(\"a\") + int(s))",
"- print(str)",
"+N = int(eval(input()))",
"-N = int(eval(input()))",
"-S = [0] * N",
"+def dfs(s, mx):",
"+ if len(s) == N:",
"+ print(s)",
"+ else:",
"+ for c in range(or... | false | 0.035851 | 0.078389 | 0.457351 | [
"s793815288",
"s768774317"
] |
u777923818 | p02934 | python | s310559211 | s067535465 | 169 | 28 | 38,484 | 9,168 | Accepted | Accepted | 83.43 | def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
print((1/sum([1/v for v in inpl()]))) | def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
print((1 / sum([1/a for a in inpl()]))) | 4 | 3 | 107 | 109 | def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
print((1 / sum([1 / v for v in inpl()])))
| def inpl():
return list(map(int, input().split()))
N = int(eval(input()))
print((1 / sum([1 / a for a in inpl()])))
| false | 25 | [
"-print((1 / sum([1 / v for v in inpl()])))",
"+print((1 / sum([1 / a for a in inpl()])))"
] | false | 0.046033 | 0.076253 | 0.603691 | [
"s310559211",
"s067535465"
] |
u716530146 | p03433 | python | s537155329 | s198506561 | 166 | 25 | 38,384 | 3,808 | Accepted | Accepted | 84.94 | #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0
n=int(eval(input()))
n%=500
a=int(eval(input()))
if a>=n:
print("Yes")
else:
print("No") | #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1
n=int(eval(input()))
a=int(eval(input()))
n%=500
if n<=a:
print("Yes")
else:
print("No") | 14 | 15 | 310 | 347 | #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
sys.setrecursionlimit(10**8)
inf = float("inf")
ans = count = 0
n = int(eval(input()))
n %= 500
a = int(eval(input()))
if a >= n:
print("Yes")
else:
print("No")
| #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode("utf-8")
sys.setrecursionlimit(10**7)
inf = float("inf")
mod = 10**9 + 7
ans = inf
count = 0
pro = 1
n = int(eval(input()))
a = int(eval(input()))
n %= 500
if n <= a:
print("Yes")
else:
print("No")
| false | 6.666667 | [
"-import sys, math, itertools, heapq, collections, bisect",
"+import sys, math, itertools, heapq, collections, bisect, string",
"-sys.setrecursionlimit(10**8)",
"+sys.setrecursionlimit(10**7)",
"-ans = count = 0",
"+mod = 10**9 + 7",
"+ans = inf",
"+count = 0",
"+pro = 1",
"+a = int(eval(input()))... | false | 0.12943 | 0.037513 | 3.450295 | [
"s537155329",
"s198506561"
] |
u424768586 | p02685 | python | s186562280 | s267375461 | 227 | 160 | 86,784 | 86,332 | Accepted | Accepted | 29.52 | import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def extgcd1(a0,b0):
u=1
v=0
a=a0
b=b0
while b:
t=a//b
a-=t*b
a,b=b,a
u-=t*v
u,v=v,u
if a!=1:
#print("not 素")
return -1
return u%b0 #a0*u=1(mod b0)
def main():
mod =998244353
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
N, M, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
# dp=[0]*2
# ndp=copy(dp)
# dp[0]=0
# dp[1]=M
# for i in range(2,N+1):
# if i<=K+1:
# ndp[0]=((M-1)*(dp[0]+dp[1])+dp[0])%mod
# ndp[1]=dp[1]
# else:
# ndp[0]=(M*dp[0]+(M-1)*dp[1])%mod
# ndp[1]=0
# dp=copy(ndp)
# ans=(dp[0]+dp[1])%mod
# #print(ans)
#n0=math.factorial(N-1)
#ks=[1]*(N-1+1)
#for k in range(2,N-1+1):
# ks[k]=ks[k-1]*k
ans=0
c0=1
c1=pow(M-1,N-1,mod)
inv=[1,1]+[pow(i,mod-2,mod) for i in range(2,N)]
#print("ok1")
ifac=[1]*(N)
nfac=1
for i in range(1,N):
nfac=(i*nfac)%mod
ifac[i]=(ifac[i-1]*inv[i])%mod
#print("ok2")
#print(ifac)
mp=[1]*(N)
for i in range(1,N):
mp[i]=(mp[i-1]*(M-1))%mod
#print("ok3")
ans=0
#print(nfac)
#print(mp)
for k in range(0,K+1):
#print((n0//ks[k]//ks[N-1-k]))
ans=ans+(mp[N-1-k]*nfac*ifac[k]*ifac[N-1-k])%mod
ans%=mod
#print(ans)
#print(ks)
ans=(ans*M)%mod
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def extgcd1(a0,b0):
u=1
v=0
a=a0
b=b0
while b:
t=a//b
a-=t*b
a,b=b,a
u-=t*v
u,v=v,u
if a!=1:
#print("not 素")
return -1
return u%b0 #a0*u=1(mod b0)
def main():
mod =998244353
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
N, M, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
# dp=[0]*2
# ndp=copy(dp)
# dp[0]=0
# dp[1]=M
# for i in range(2,N+1):
# if i<=K+1:
# ndp[0]=((M-1)*(dp[0]+dp[1])+dp[0])%mod
# ndp[1]=dp[1]
# else:
# ndp[0]=(M*dp[0]+(M-1)*dp[1])%mod
# ndp[1]=0
# dp=copy(ndp)
# ans=(dp[0]+dp[1])%mod
# #print(ans)
#n0=math.factorial(N-1)
#ks=[1]*(N-1+1)
#for k in range(2,N-1+1):
# ks[k]=ks[k-1]*k
ans=0
c0=1
c1=pow(M-1,N-1,mod)
inv=[1,1]+[extgcd1(i,mod) for i in range(2,N)]
#print("ok1")
ifac=[1]*(N)
nfac=1
for i in range(1,N):
nfac=(i*nfac)%mod
ifac[i]=(ifac[i-1]*inv[i])%mod
#print("ok2")
#print(ifac)
mp=[1]*(N)
for i in range(1,N):
mp[i]=(mp[i-1]*(M-1))%mod
#print("ok3")
ans=0
#print(nfac)
#print(mp)
for k in range(0,K+1):
#print((n0//ks[k]//ks[N-1-k]))
ans=ans+(mp[N-1-k]*nfac*ifac[k]*ifac[N-1-k])%mod
ans%=mod
#print(ans)
#print(ks)
ans=(ans*M)%mod
print(ans)
if __name__ == "__main__":
main()
| 106 | 106 | 2,879 | 2,877 | import sys
sys.setrecursionlimit(10**6) # 再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right # 2分探索
# bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
# deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter # 文字列を個数カウント辞書に、
# S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate # 累積和
# list(accumulate(l))
from heapq import heapify, heappop, heappush
# heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
# import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input():
return sys.stdin.readline()[:-1]
def printl(li):
print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds = sorted(range(len(s)), key=lambda k: s[k])
if return_sorted:
return inds, [s[i] for i in inds]
return inds
def alp2num(c, cap=False):
return ord(c) - 97 if not cap else ord(c) - 65
def num2alp(i, cap=False):
return chr(i + 97) if not cap else chr(i + 65)
def extgcd1(a0, b0):
u = 1
v = 0
a = a0
b = b0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
if a != 1:
# print("not 素")
return -1
return u % b0 # a0*u=1(mod b0)
def main():
mod = 998244353
# w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
# N = int(input())
N, M, K = map(int, input().split())
# A = tuple(map(int, input().split())) #1行ベクトル
# L = tuple(int(input()) for i in range(N)) #改行ベクトル
# S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
# dp=[0]*2
# ndp=copy(dp)
# dp[0]=0
# dp[1]=M
# for i in range(2,N+1):
# if i<=K+1:
# ndp[0]=((M-1)*(dp[0]+dp[1])+dp[0])%mod
# ndp[1]=dp[1]
# else:
# ndp[0]=(M*dp[0]+(M-1)*dp[1])%mod
# ndp[1]=0
# dp=copy(ndp)
# ans=(dp[0]+dp[1])%mod
# #print(ans)
# n0=math.factorial(N-1)
# ks=[1]*(N-1+1)
# for k in range(2,N-1+1):
# ks[k]=ks[k-1]*k
ans = 0
c0 = 1
c1 = pow(M - 1, N - 1, mod)
inv = [1, 1] + [pow(i, mod - 2, mod) for i in range(2, N)]
# print("ok1")
ifac = [1] * (N)
nfac = 1
for i in range(1, N):
nfac = (i * nfac) % mod
ifac[i] = (ifac[i - 1] * inv[i]) % mod
# print("ok2")
# print(ifac)
mp = [1] * (N)
for i in range(1, N):
mp[i] = (mp[i - 1] * (M - 1)) % mod
# print("ok3")
ans = 0
# print(nfac)
# print(mp)
for k in range(0, K + 1):
# print((n0//ks[k]//ks[N-1-k]))
ans = ans + (mp[N - 1 - k] * nfac * ifac[k] * ifac[N - 1 - k]) % mod
ans %= mod
# print(ans)
# print(ks)
ans = (ans * M) % mod
print(ans)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6) # 再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right # 2分探索
# bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
# deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter # 文字列を個数カウント辞書に、
# S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate # 累積和
# list(accumulate(l))
from heapq import heapify, heappop, heappush
# heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
# import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input():
return sys.stdin.readline()[:-1]
def printl(li):
print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds = sorted(range(len(s)), key=lambda k: s[k])
if return_sorted:
return inds, [s[i] for i in inds]
return inds
def alp2num(c, cap=False):
return ord(c) - 97 if not cap else ord(c) - 65
def num2alp(i, cap=False):
return chr(i + 97) if not cap else chr(i + 65)
def extgcd1(a0, b0):
u = 1
v = 0
a = a0
b = b0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
if a != 1:
# print("not 素")
return -1
return u % b0 # a0*u=1(mod b0)
def main():
mod = 998244353
# w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
# N = int(input())
N, M, K = map(int, input().split())
# A = tuple(map(int, input().split())) #1行ベクトル
# L = tuple(int(input()) for i in range(N)) #改行ベクトル
# S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
# dp=[0]*2
# ndp=copy(dp)
# dp[0]=0
# dp[1]=M
# for i in range(2,N+1):
# if i<=K+1:
# ndp[0]=((M-1)*(dp[0]+dp[1])+dp[0])%mod
# ndp[1]=dp[1]
# else:
# ndp[0]=(M*dp[0]+(M-1)*dp[1])%mod
# ndp[1]=0
# dp=copy(ndp)
# ans=(dp[0]+dp[1])%mod
# #print(ans)
# n0=math.factorial(N-1)
# ks=[1]*(N-1+1)
# for k in range(2,N-1+1):
# ks[k]=ks[k-1]*k
ans = 0
c0 = 1
c1 = pow(M - 1, N - 1, mod)
inv = [1, 1] + [extgcd1(i, mod) for i in range(2, N)]
# print("ok1")
ifac = [1] * (N)
nfac = 1
for i in range(1, N):
nfac = (i * nfac) % mod
ifac[i] = (ifac[i - 1] * inv[i]) % mod
# print("ok2")
# print(ifac)
mp = [1] * (N)
for i in range(1, N):
mp[i] = (mp[i - 1] * (M - 1)) % mod
# print("ok3")
ans = 0
# print(nfac)
# print(mp)
for k in range(0, K + 1):
# print((n0//ks[k]//ks[N-1-k]))
ans = ans + (mp[N - 1 - k] * nfac * ifac[k] * ifac[N - 1 - k]) % mod
ans %= mod
# print(ans)
# print(ks)
ans = (ans * M) % mod
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- inv = [1, 1] + [pow(i, mod - 2, mod) for i in range(2, N)]",
"+ inv = [1, 1] + [extgcd1(i, mod) for i in range(2, N)]"
] | false | 0.131158 | 0.385514 | 0.340215 | [
"s186562280",
"s267375461"
] |
u392319141 | p03674 | python | s011416307 | s802018310 | 815 | 456 | 30,996 | 30,560 | Accepted | Accepted | 44.05 | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
fact = [1 for _ in range(N + 10)]
invFact = [0 for _ in range(N + 10)]
def modInv(a):
b = MOD
u = 1
v = 0
while b :
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= MOD
return u
for i in range(1, N + 10):
fact[i] = (fact[i - 1] * i) % MOD
invFact[i] = modInv(fact[i])
index = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
index[a].append(i)
left = 0
right = 0
for count in index:
if len(count) == 2:
left = min(count)
right = max(count)
def comb(n, r):
if 0 < r < n:
return (fact[n] * invFact[r] % MOD) * invFact[n - r] % MOD
if r == 0 or r == n:
return 1
return 0
les = left + (N - right)
for k in range(1, N + 2):
r = comb(les, k - 1)
ans = comb(N + 1, k) - r
print((ans % MOD))
| from collections import Counter, defaultdict
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fact[i - 1] * i % self.mod
self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod
def npr(self, n, r):
if n < r or n < 0 or r < 0:
return 0
return self.fact[n] * self.factInv[n - r] % self.mod
def ncr(self, n, r):
if n < r or n < 0 or r < 0:
return 0
return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod
def nhr(self, n, r): # 重複組合せ
return self.ncr(n + r - 1, n - 1)
def factN(self, n):
if n < 0:
return 0
return self.fact[n]
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
comb = Combination(N + 100)
cntA = Counter(A)
I = [a for a, c in list(cntA.items()) if c == 2][0]
L, R = [i for i, a in enumerate(A) if a == I]
S = L + (N - R)
for i in range(1, N + 2):
if i == 1:
print(N)
continue
ans = comb.ncr(N + 1, i) - comb.ncr(S, i - 1)
print((ans % MOD))
| 49 | 50 | 961 | 1,446 | N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
fact = [1 for _ in range(N + 10)]
invFact = [0 for _ in range(N + 10)]
def modInv(a):
b = MOD
u = 1
v = 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= MOD
return u
for i in range(1, N + 10):
fact[i] = (fact[i - 1] * i) % MOD
invFact[i] = modInv(fact[i])
index = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
index[a].append(i)
left = 0
right = 0
for count in index:
if len(count) == 2:
left = min(count)
right = max(count)
def comb(n, r):
if 0 < r < n:
return (fact[n] * invFact[r] % MOD) * invFact[n - r] % MOD
if r == 0 or r == n:
return 1
return 0
les = left + (N - right)
for k in range(1, N + 2):
r = comb(les, k - 1)
ans = comb(N + 1, k) - r
print((ans % MOD))
| from collections import Counter, defaultdict
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fact[i - 1] * i % self.mod
self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod
def npr(self, n, r):
if n < r or n < 0 or r < 0:
return 0
return self.fact[n] * self.factInv[n - r] % self.mod
def ncr(self, n, r):
if n < r or n < 0 or r < 0:
return 0
return (
self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod
)
def nhr(self, n, r): # 重複組合せ
return self.ncr(n + r - 1, n - 1)
def factN(self, n):
if n < 0:
return 0
return self.fact[n]
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
comb = Combination(N + 100)
cntA = Counter(A)
I = [a for a, c in list(cntA.items()) if c == 2][0]
L, R = [i for i, a in enumerate(A) if a == I]
S = L + (N - R)
for i in range(1, N + 2):
if i == 1:
print(N)
continue
ans = comb.ncr(N + 1, i) - comb.ncr(S, i - 1)
print((ans % MOD))
| false | 2 | [
"+from collections import Counter, defaultdict",
"+",
"+",
"+class Combination:",
"+ def __init__(self, size, mod=10**9 + 7):",
"+ self.size = size + 2",
"+ self.mod = mod",
"+ self.fact = [1, 1] + [0] * size",
"+ self.factInv = [1, 1] + [0] * size",
"+ self.i... | false | 0.0081 | 0.036574 | 0.221472 | [
"s011416307",
"s802018310"
] |
u627417051 | p04002 | python | s591710614 | s494892509 | 2,466 | 2,186 | 135,976 | 135,888 | Accepted | Accepted | 11.35 | import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def getlist():
return list(map(int, input().split()))
H, W, N = getlist()
D = defaultdict(int)
D[0] += (H - 2) * (W - 2)
L = []
for i in range(N):
a, b = getlist()
for j in range(3):
for k in range(3):
if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
L.append((a - j, b - k))
L = sorted(L)
n = len(L)
if n != 0:
v = L[0]
c = 0
for i in range(n):
if v == L[i]:
c += 1
else:
D[c] += 1
c = 1
v = L[i]
if n != 0:
D[c] += 1
for i in range(1, 10):
D[0] -= D[i]
for i in range(10):
print((D[i])) | import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def getlist():
return list(map(int, input().split()))
def main():
H, W, N = getlist()
D = defaultdict(int)
D[0] += (H - 2) * (W - 2)
L = []
for i in range(N):
a, b = getlist()
for j in range(3):
for k in range(3):
if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
L.append((a - j, b - k))
L = sorted(L)
n = len(L)
if n != 0:
v = L[0]
c = 0
for i in range(n):
if v == L[i]:
c += 1
else:
D[c] += 1
c = 1
v = L[i]
if n != 0:
D[c] += 1
for i in range(1, 10):
D[0] -= D[i]
for i in range(10):
print((D[i]))
if __name__ == '__main__':
main()
| 39 | 47 | 655 | 745 | import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def getlist():
return list(map(int, input().split()))
H, W, N = getlist()
D = defaultdict(int)
D[0] += (H - 2) * (W - 2)
L = []
for i in range(N):
a, b = getlist()
for j in range(3):
for k in range(3):
if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
L.append((a - j, b - k))
L = sorted(L)
n = len(L)
if n != 0:
v = L[0]
c = 0
for i in range(n):
if v == L[i]:
c += 1
else:
D[c] += 1
c = 1
v = L[i]
if n != 0:
D[c] += 1
for i in range(1, 10):
D[0] -= D[i]
for i in range(10):
print((D[i]))
| import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def getlist():
return list(map(int, input().split()))
def main():
H, W, N = getlist()
D = defaultdict(int)
D[0] += (H - 2) * (W - 2)
L = []
for i in range(N):
a, b = getlist()
for j in range(3):
for k in range(3):
if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
L.append((a - j, b - k))
L = sorted(L)
n = len(L)
if n != 0:
v = L[0]
c = 0
for i in range(n):
if v == L[i]:
c += 1
else:
D[c] += 1
c = 1
v = L[i]
if n != 0:
D[c] += 1
for i in range(1, 10):
D[0] -= D[i]
for i in range(10):
print((D[i]))
if __name__ == "__main__":
main()
| false | 17.021277 | [
"-H, W, N = getlist()",
"-D = defaultdict(int)",
"-D[0] += (H - 2) * (W - 2)",
"-L = []",
"-for i in range(N):",
"- a, b = getlist()",
"- for j in range(3):",
"- for k in range(3):",
"- if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:",
"- ... | false | 0.172549 | 0.045844 | 3.763794 | [
"s591710614",
"s494892509"
] |
u645250356 | p03037 | python | s155863071 | s529963539 | 302 | 228 | 11,376 | 9,048 | Accepted | Accepted | 24.5 | import collections
n,m = list(map(int,input().split()))
r = []
l = []
for i in range(m):
ll,rr = list(map(int,input().split()))
r.append(rr)
l.append(ll)
ans = min(r) - max(l) +1
if ans > 0:
print(ans)
else :
print((0)) | from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
n,m = inpl()
cnt = [0]*(n+1)
for i in range(m):
l,r = inpl()
cnt[l-1] += 1
cnt[r] -= 1
cntsum = list(itertools.accumulate(cnt))
print((cntsum.count(m))) | 13 | 15 | 237 | 453 | import collections
n, m = list(map(int, input().split()))
r = []
l = []
for i in range(m):
ll, rr = list(map(int, input().split()))
r.append(rr)
l.append(ll)
ans = min(r) - max(l) + 1
if ans > 0:
print(ans)
else:
print((0))
| from collections import Counter, defaultdict
import sys, heapq, bisect, math, itertools, string, queue
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
n, m = inpl()
cnt = [0] * (n + 1)
for i in range(m):
l, r = inpl()
cnt[l - 1] += 1
cnt[r] -= 1
cntsum = list(itertools.accumulate(cnt))
print((cntsum.count(m)))
| false | 13.333333 | [
"-import collections",
"+from collections import Counter, defaultdict",
"+import sys, heapq, bisect, math, itertools, string, queue",
"-n, m = list(map(int, input().split()))",
"-r = []",
"-l = []",
"+mod = 10**9 + 7",
"+",
"+",
"+def inp():",
"+ return int(sys.stdin.readline())",
"+",
"+... | false | 0.072255 | 0.078821 | 0.916694 | [
"s155863071",
"s529963539"
] |
u790710233 | p04020 | python | s069678697 | s198854388 | 282 | 213 | 7,028 | 3,060 | Accepted | Accepted | 24.47 | n = int(eval(input()))
cnt = [0]*n
for i in range(n):
a = int(eval(input()))
cnt[i] += a
ans = 0
for i, j in zip(list(range(n-1)), list(range(1, n))):
x, y = cnt[i], cnt[j]
z = x//2
cnt[i] -= 2*z
ans += z
if cnt[i] == 0:
continue
if 0 < y:
ans += 1
cnt[i] -= 1
cnt[j] -= 1
else:
ans += cnt[-1]//2
print(ans) | n = int(eval(input()))
ans = x = 0
for _ in range(n):
a = int(eval(input()))
if a == 0:
ans += x//2
x = 0
x += a
else:
ans += x//2
print(ans) | 22 | 13 | 374 | 175 | n = int(eval(input()))
cnt = [0] * n
for i in range(n):
a = int(eval(input()))
cnt[i] += a
ans = 0
for i, j in zip(list(range(n - 1)), list(range(1, n))):
x, y = cnt[i], cnt[j]
z = x // 2
cnt[i] -= 2 * z
ans += z
if cnt[i] == 0:
continue
if 0 < y:
ans += 1
cnt[i] -= 1
cnt[j] -= 1
else:
ans += cnt[-1] // 2
print(ans)
| n = int(eval(input()))
ans = x = 0
for _ in range(n):
a = int(eval(input()))
if a == 0:
ans += x // 2
x = 0
x += a
else:
ans += x // 2
print(ans)
| false | 40.909091 | [
"-cnt = [0] * n",
"-for i in range(n):",
"+ans = x = 0",
"+for _ in range(n):",
"- cnt[i] += a",
"-ans = 0",
"-for i, j in zip(list(range(n - 1)), list(range(1, n))):",
"- x, y = cnt[i], cnt[j]",
"- z = x // 2",
"- cnt[i] -= 2 * z",
"- ans += z",
"- if cnt[i] == 0:",
"- ... | false | 0.034512 | 0.041792 | 0.825821 | [
"s069678697",
"s198854388"
] |
u012694084 | p02983 | python | s216809700 | s887850709 | 177 | 39 | 39,024 | 3,060 | Accepted | Accepted | 77.97 | l, r = list(map(int, input().split()))
result = None
for i in range(l, min(l + 2019 - l % 2019, r - 1) + 1):
for j in range(i + 1, min(i + 2019, r) + 1):
mod = i * j % 2019
if result is None or result > mod:
result = mod
if result == 0:
break
if result is not None and result == 0:
break
print(result)
| def search(lower, upper, mod):
min_remain = mod
for i in range(lower, min(lower + mod - lower % mod, upper - 1) + 1):
for j in range(i + 1, min(i + mod, upper) + 1):
remain = i * j % mod
if remain == 0:
return 0
if min_remain > remain:
min_remain = remain
return min_remain
l, r = list(map(int, input().split()))
print((search(l, r, 2019)))
| 13 | 14 | 381 | 436 | l, r = list(map(int, input().split()))
result = None
for i in range(l, min(l + 2019 - l % 2019, r - 1) + 1):
for j in range(i + 1, min(i + 2019, r) + 1):
mod = i * j % 2019
if result is None or result > mod:
result = mod
if result == 0:
break
if result is not None and result == 0:
break
print(result)
| def search(lower, upper, mod):
min_remain = mod
for i in range(lower, min(lower + mod - lower % mod, upper - 1) + 1):
for j in range(i + 1, min(i + mod, upper) + 1):
remain = i * j % mod
if remain == 0:
return 0
if min_remain > remain:
min_remain = remain
return min_remain
l, r = list(map(int, input().split()))
print((search(l, r, 2019)))
| false | 7.142857 | [
"+def search(lower, upper, mod):",
"+ min_remain = mod",
"+ for i in range(lower, min(lower + mod - lower % mod, upper - 1) + 1):",
"+ for j in range(i + 1, min(i + mod, upper) + 1):",
"+ remain = i * j % mod",
"+ if remain == 0:",
"+ return 0",
"+ ... | false | 0.079063 | 0.07922 | 0.99802 | [
"s216809700",
"s887850709"
] |
u088372268 | p02260 | python | s843731548 | s622568618 | 30 | 20 | 5,600 | 5,600 | Accepted | Accepted | 33.33 | n, data = int(eval(input())), list(map(int, input().split()))
idx, t = 0, 0
for i in range(n-1):
for j in range(i, n):
if j == i:
idx = j
elif data[idx] > data[j]:
idx = j
if data[i] > data[idx]:
data[i], data[idx] = data[idx], data[i]
t += 1
print((" ".join(map(str, data))))
print(t)
| n, data = int(eval(input())), list(map(int, input().split()))
idx, t = 0, 0
for i in range(n-1):
for j in range(i+1, n):
if j == i+1:
idx = j
elif data[idx] > data[j]:
idx = j
if data[i] > data[idx]:
data[i], data[idx] = data[idx], data[i]
t += 1
print((" ".join(map(str, data))))
print(t)
| 14 | 14 | 356 | 360 | n, data = int(eval(input())), list(map(int, input().split()))
idx, t = 0, 0
for i in range(n - 1):
for j in range(i, n):
if j == i:
idx = j
elif data[idx] > data[j]:
idx = j
if data[i] > data[idx]:
data[i], data[idx] = data[idx], data[i]
t += 1
print((" ".join(map(str, data))))
print(t)
| n, data = int(eval(input())), list(map(int, input().split()))
idx, t = 0, 0
for i in range(n - 1):
for j in range(i + 1, n):
if j == i + 1:
idx = j
elif data[idx] > data[j]:
idx = j
if data[i] > data[idx]:
data[i], data[idx] = data[idx], data[i]
t += 1
print((" ".join(map(str, data))))
print(t)
| false | 0 | [
"- for j in range(i, n):",
"- if j == i:",
"+ for j in range(i + 1, n):",
"+ if j == i + 1:"
] | false | 0.072472 | 0.069819 | 1.038 | [
"s843731548",
"s622568618"
] |
u833543158 | p02948 | python | s305034121 | s141870112 | 353 | 270 | 17,208 | 26,020 | Accepted | Accepted | 23.51 | import sys
import heapq
N, M = list(map(int, input().split()))
jobs = []
for line in sys.stdin:
A, B = list(map(int, line.split()))
if A > M:
continue
jobs.append((A, B))
jobs.sort(reverse=True)
q = []
ans = 0
for i in range(1, M + 1):
while jobs and jobs[-1][0] <= i:
A, B = jobs.pop()
heapq.heappush(q, -B)
if q:
ans += -heapq.heappop(q)
print(ans)
| import sys
import heapq
N, M = list(map(int, input().split()))
possiblyValidJobs = {}
for line in sys.stdin:
A, B = list(map(int, line.split()))
if A > M:
continue
if A in possiblyValidJobs:
possiblyValidJobs[A].append(B)
else:
possiblyValidJobs[A] = [B]
validJobsOnThisDay = []
ans = 0
for daysBeforeDeadline in range(1, M + 1):
if daysBeforeDeadline in possiblyValidJobs:
for wage in possiblyValidJobs[daysBeforeDeadline]:
heapq.heappush(validJobsOnThisDay, -wage)
if validJobsOnThisDay:
ans += -heapq.heappop(validJobsOnThisDay)
print(ans)
| 23 | 24 | 423 | 639 | import sys
import heapq
N, M = list(map(int, input().split()))
jobs = []
for line in sys.stdin:
A, B = list(map(int, line.split()))
if A > M:
continue
jobs.append((A, B))
jobs.sort(reverse=True)
q = []
ans = 0
for i in range(1, M + 1):
while jobs and jobs[-1][0] <= i:
A, B = jobs.pop()
heapq.heappush(q, -B)
if q:
ans += -heapq.heappop(q)
print(ans)
| import sys
import heapq
N, M = list(map(int, input().split()))
possiblyValidJobs = {}
for line in sys.stdin:
A, B = list(map(int, line.split()))
if A > M:
continue
if A in possiblyValidJobs:
possiblyValidJobs[A].append(B)
else:
possiblyValidJobs[A] = [B]
validJobsOnThisDay = []
ans = 0
for daysBeforeDeadline in range(1, M + 1):
if daysBeforeDeadline in possiblyValidJobs:
for wage in possiblyValidJobs[daysBeforeDeadline]:
heapq.heappush(validJobsOnThisDay, -wage)
if validJobsOnThisDay:
ans += -heapq.heappop(validJobsOnThisDay)
print(ans)
| false | 4.166667 | [
"-jobs = []",
"+possiblyValidJobs = {}",
"- jobs.append((A, B))",
"-jobs.sort(reverse=True)",
"-q = []",
"+ if A in possiblyValidJobs:",
"+ possiblyValidJobs[A].append(B)",
"+ else:",
"+ possiblyValidJobs[A] = [B]",
"+validJobsOnThisDay = []",
"-for i in range(1, M + 1):",... | false | 0.043376 | 0.036369 | 1.192666 | [
"s305034121",
"s141870112"
] |
u370661635 | p03317 | python | s362783739 | s123782105 | 40 | 17 | 13,880 | 3,064 | Accepted | Accepted | 57.5 | n,k=list(map(int,input().split()))
a = list(map(int,input().split()))
if (n-1)%(k-1) != 0:
cnt = (n-1)//(k-1)+1
else:
cnt = (n-1)//(k-1)
print(cnt) | import math
n,k=list(map(int,input().split()))
print((math.ceil((n-k)/(k-1))+1)) | 9 | 3 | 157 | 74 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if (n - 1) % (k - 1) != 0:
cnt = (n - 1) // (k - 1) + 1
else:
cnt = (n - 1) // (k - 1)
print(cnt)
| import math
n, k = list(map(int, input().split()))
print((math.ceil((n - k) / (k - 1)) + 1))
| false | 66.666667 | [
"+import math",
"+",
"-a = list(map(int, input().split()))",
"-if (n - 1) % (k - 1) != 0:",
"- cnt = (n - 1) // (k - 1) + 1",
"-else:",
"- cnt = (n - 1) // (k - 1)",
"-print(cnt)",
"+print((math.ceil((n - k) / (k - 1)) + 1))"
] | false | 0.142156 | 0.057424 | 2.475556 | [
"s362783739",
"s123782105"
] |
u763550415 | p02657 | python | s045677856 | s186395072 | 26 | 22 | 9,156 | 9,052 | Accepted | Accepted | 15.38 | A, B =list(map(int, input().split()))
print((A*B)) | a, b = list(map(int, input().split()))
print((a*b)) | 2 | 2 | 43 | 44 | A, B = list(map(int, input().split()))
print((A * B))
| a, b = list(map(int, input().split()))
print((a * b))
| false | 0 | [
"-A, B = list(map(int, input().split()))",
"-print((A * B))",
"+a, b = list(map(int, input().split()))",
"+print((a * b))"
] | false | 0.040871 | 0.132233 | 0.309083 | [
"s045677856",
"s186395072"
] |
u645250356 | p02954 | python | s310096876 | s683507968 | 190 | 146 | 13,752 | 9,432 | Accepted | Accepted | 23.16 | import sys,fractions
a = eval(input())
n = len(a)
t = []
ans = [0] * n
cnt = 0
tmp = a[0]
for i in range(n):
if a[i] == tmp:
cnt += 1
else:
t.append(cnt)
tmp = a[i]
cnt = 1
t.append(cnt)
N = len(t)
len = 0
for i in range(N)[::2]:
tmp_len = t[i] + t[i+1]
#R
ans[len + t[i] - 1] += int((t[i]+1)/2)
ans[len + t[i]] += int(t[i]/2)
#L
ans[len + t[i] - 1] += int(t[i+1]/2)
ans[len + t[i]] += int((t[i+1]+1)/2)
len += tmp_len
L = [str(i) for i in ans]
print((" ".join(L))) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
s = eval(input())
n = len(s)
aa = []
for i,t in enumerate(s):
if i == 0:
tmp = t
cnt = 1
continue
if tmp != t:
aa.append(cnt)
cnt = 1
tmp = t
else:
cnt += 1
aa.append(cnt)
# print(aa)
res = [0] * n
cnt = 0
for i in range(len(aa))[::2]:
l = aa[i]; r = aa[i+1]
av = (l+r)//2
if (l%2 and r%2) or (l%2==0 and r%2==0):
res[cnt+l-1] = av
res[cnt+l] = av
else:
if l%2:
res[cnt+l-1] = av+1
res[cnt+l] = av
else:
res[cnt+l-1] = av
res[cnt+l] = av+1
cnt += l+r
print((*res)) | 28 | 44 | 556 | 1,069 | import sys, fractions
a = eval(input())
n = len(a)
t = []
ans = [0] * n
cnt = 0
tmp = a[0]
for i in range(n):
if a[i] == tmp:
cnt += 1
else:
t.append(cnt)
tmp = a[i]
cnt = 1
t.append(cnt)
N = len(t)
len = 0
for i in range(N)[::2]:
tmp_len = t[i] + t[i + 1]
# R
ans[len + t[i] - 1] += int((t[i] + 1) / 2)
ans[len + t[i]] += int(t[i] / 2)
# L
ans[len + t[i] - 1] += int(t[i + 1] / 2)
ans[len + t[i]] += int((t[i + 1] + 1) / 2)
len += tmp_len
L = [str(i) for i in ans]
print((" ".join(L)))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
mod2 = 998244353
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
s = eval(input())
n = len(s)
aa = []
for i, t in enumerate(s):
if i == 0:
tmp = t
cnt = 1
continue
if tmp != t:
aa.append(cnt)
cnt = 1
tmp = t
else:
cnt += 1
aa.append(cnt)
# print(aa)
res = [0] * n
cnt = 0
for i in range(len(aa))[::2]:
l = aa[i]
r = aa[i + 1]
av = (l + r) // 2
if (l % 2 and r % 2) or (l % 2 == 0 and r % 2 == 0):
res[cnt + l - 1] = av
res[cnt + l] = av
else:
if l % 2:
res[cnt + l - 1] = av + 1
res[cnt + l] = av
else:
res[cnt + l - 1] = av
res[cnt + l] = av + 1
cnt += l + r
print((*res))
| false | 36.363636 | [
"-import sys, fractions",
"+from collections import Counter, defaultdict, deque",
"+from heapq import heappop, heappush, heapify",
"+import sys, bisect, math, itertools, fractions, pprint",
"-a = eval(input())",
"-n = len(a)",
"-t = []",
"-ans = [0] * n",
"+sys.setrecursionlimit(10**8)",
"+mod = 1... | false | 0.083645 | 0.038517 | 2.171606 | [
"s310096876",
"s683507968"
] |
u596505843 | p02991 | python | s187314072 | s535512459 | 795 | 276 | 116,068 | 124,972 | Accepted | Accepted | 65.28 | import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
N, M = rl()
E = defaultdict(list)
for i in range(M):
u, v = rl()
E[u-1].append(v-1)
S, T = rl()
S -= 1
T -= 1
dp = [[float('inf')]*3 for i in range(N)]
heap = []
heappush(heap, (0, S, 0))
while heap:
d, n, r = heappop(heap)
if n == T and r == 0:
continue
#if dp[n][r] != d:
# continue
nr = (d+1)%3
for m in E[n]:
if dp[m][nr] > d+1:
dp[m][nr] = d+1
heappush(heap, (d+1, m, nr))
if dp[T][0] != float('inf'):
print((dp[T][0]//3))
else:
print((-1))
| import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
N, M = rl()
E = defaultdict(list)
for i in range(M):
u, v = rl()
E[u-1].append(v-1)
S, T = rl()
S -= 1
T -= 1
queue = deque()
queue.append((S,0,0))
visited = set()
while queue:
n, r, d = queue.popleft()
if n == T and r == 0:
print((d//3))
exit()
nr = (r+1)%3
for m in E[n]:
if (m, nr) in visited: continue
visited.add((m, nr))
queue.append((m, nr, d+1))
print((-1)) | 42 | 36 | 922 | 829 | import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
N, M = rl()
E = defaultdict(list)
for i in range(M):
u, v = rl()
E[u - 1].append(v - 1)
S, T = rl()
S -= 1
T -= 1
dp = [[float("inf")] * 3 for i in range(N)]
heap = []
heappush(heap, (0, S, 0))
while heap:
d, n, r = heappop(heap)
if n == T and r == 0:
continue
# if dp[n][r] != d:
# continue
nr = (d + 1) % 3
for m in E[n]:
if dp[m][nr] > d + 1:
dp[m][nr] = d + 1
heappush(heap, (d + 1, m, nr))
if dp[T][0] != float("inf"):
print((dp[T][0] // 3))
else:
print((-1))
| import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
N, M = rl()
E = defaultdict(list)
for i in range(M):
u, v = rl()
E[u - 1].append(v - 1)
S, T = rl()
S -= 1
T -= 1
queue = deque()
queue.append((S, 0, 0))
visited = set()
while queue:
n, r, d = queue.popleft()
if n == T and r == 0:
print((d // 3))
exit()
nr = (r + 1) % 3
for m in E[n]:
if (m, nr) in visited:
continue
visited.add((m, nr))
queue.append((m, nr, d + 1))
print((-1))
| false | 14.285714 | [
"-dp = [[float(\"inf\")] * 3 for i in range(N)]",
"-heap = []",
"-heappush(heap, (0, S, 0))",
"-while heap:",
"- d, n, r = heappop(heap)",
"+queue = deque()",
"+queue.append((S, 0, 0))",
"+visited = set()",
"+while queue:",
"+ n, r, d = queue.popleft()",
"- continue",
"- # if d... | false | 0.107734 | 0.072849 | 1.47886 | [
"s187314072",
"s535512459"
] |
u631277801 | p03363 | python | s837621813 | s903571865 | 231 | 158 | 41,672 | 41,984 | Accepted | Accepted | 31.6 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A_sum = [A[0]]
for i in range(1,N):
A_sum.append(A_sum[i-1]+A[i])
a_cnt = Counter(A_sum)
ans = 0
for k,v in list(a_cnt.items()):
ans += v*(v-1)//2
if k==0:
ans += v
print(ans) | from collections import Counter
from itertools import accumulate
N = int(eval(input()))
A = list(map(int, input().split()))
B = [0] + list(accumulate(A))
cnt = Counter(B)
ans = 0
for v in list(cnt.values()):
ans += v*(v-1)//2
print(ans) | 20 | 15 | 308 | 251 | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A_sum = [A[0]]
for i in range(1, N):
A_sum.append(A_sum[i - 1] + A[i])
a_cnt = Counter(A_sum)
ans = 0
for k, v in list(a_cnt.items()):
ans += v * (v - 1) // 2
if k == 0:
ans += v
print(ans)
| from collections import Counter
from itertools import accumulate
N = int(eval(input()))
A = list(map(int, input().split()))
B = [0] + list(accumulate(A))
cnt = Counter(B)
ans = 0
for v in list(cnt.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 25 | [
"+from itertools import accumulate",
"-A_sum = [A[0]]",
"-for i in range(1, N):",
"- A_sum.append(A_sum[i - 1] + A[i])",
"-a_cnt = Counter(A_sum)",
"+B = [0] + list(accumulate(A))",
"+cnt = Counter(B)",
"-for k, v in list(a_cnt.items()):",
"+for v in list(cnt.values()):",
"- if k == 0:",
"... | false | 0.110018 | 0.04139 | 2.658062 | [
"s837621813",
"s903571865"
] |
u875291233 | p03045 | python | s210259076 | s288756158 | 602 | 520 | 8,564 | 8,564 | Accepted | Accepted | 13.62 | # coding: utf-8
# Your code here!
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))#親ノード
self.size = [1]*n #グループの要素数
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.size[x] < self.size[y]:
self.size[y] += self.size[x] #yの要素数を更新
self.parent[x] = y #xをyにつなぐ
else:
self.size[x] += self.size[y] #xの要素数を更新
self.parent[y] = x #yをxにつなぐ
return True
def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
return self.root(x) == self.root(y)
def size(self,x): #size(x): xのいるグループの要素数を返す
return self.size[self.root(x)]
n,m = [int(i) for i in input().split()]
T=UnionFind(n)
c=0
for _ in [0]*m:
x,y,z=[int(i) for i in input().split()]
if not T.issame(x-1,y-1):
T.merge(x-1,y-1)
c+=1
print((n-c)) | # coding: utf-8
# Your code here!
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))#親ノード
self.size = [1]*n #グループの要素数
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.size[x] < self.size[y]:
self.size[y] += self.size[x] #yの要素数を更新
self.parent[x] = y #xをyにつなぐ
else:
self.size[x] += self.size[y] #xの要素数を更新
self.parent[y] = x #yをxにつなぐ
return True
def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
return self.root(x) == self.root(y)
def size(self,x): #size(x): xのいるグループの要素数を返す
return self.size[self.root(x)]
n,m = [int(i) for i in input().split()]
T=UnionFind(n)
c=0
for _ in [0]*m:
x,y,z=[int(i) for i in input().split()]
if T.merge(x-1,y-1):
c+=1
print((n-c)) | 44 | 43 | 1,206 | 1,175 | # coding: utf-8
# Your code here!
class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) # 親ノード
self.size = [1] * n # グループの要素数
def root(self, x): # root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def merge(self, x, y): # merge(x,y): xのいるグループと$y$のいるグループをまとめる
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.size[x] < self.size[y]:
self.size[y] += self.size[x] # yの要素数を更新
self.parent[x] = y # xをyにつなぐ
else:
self.size[x] += self.size[y] # xの要素数を更新
self.parent[y] = x # yをxにつなぐ
return True
def issame(self, x, y): # same(x,y): xとyが同じグループにあるならTrue
return self.root(x) == self.root(y)
def size(self, x): # size(x): xのいるグループの要素数を返す
return self.size[self.root(x)]
n, m = [int(i) for i in input().split()]
T = UnionFind(n)
c = 0
for _ in [0] * m:
x, y, z = [int(i) for i in input().split()]
if not T.issame(x - 1, y - 1):
T.merge(x - 1, y - 1)
c += 1
print((n - c))
| # coding: utf-8
# Your code here!
class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) # 親ノード
self.size = [1] * n # グループの要素数
def root(self, x): # root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def merge(self, x, y): # merge(x,y): xのいるグループと$y$のいるグループをまとめる
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.size[x] < self.size[y]:
self.size[y] += self.size[x] # yの要素数を更新
self.parent[x] = y # xをyにつなぐ
else:
self.size[x] += self.size[y] # xの要素数を更新
self.parent[y] = x # yをxにつなぐ
return True
def issame(self, x, y): # same(x,y): xとyが同じグループにあるならTrue
return self.root(x) == self.root(y)
def size(self, x): # size(x): xのいるグループの要素数を返す
return self.size[self.root(x)]
n, m = [int(i) for i in input().split()]
T = UnionFind(n)
c = 0
for _ in [0] * m:
x, y, z = [int(i) for i in input().split()]
if T.merge(x - 1, y - 1):
c += 1
print((n - c))
| false | 2.272727 | [
"- if not T.issame(x - 1, y - 1):",
"- T.merge(x - 1, y - 1)",
"+ if T.merge(x - 1, y - 1):"
] | false | 0.049058 | 0.043356 | 1.131508 | [
"s210259076",
"s288756158"
] |
u440566786 | p02925 | python | s585844621 | s547459645 | 1,765 | 1,549 | 162,304 | 156,672 | Accepted | Accepted | 12.24 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n=int(eval(input()))
# id table
N=0
id=[[None]*n for _ in range(n)]
for i in range(n):
for j in range(i+1,n):
id[i][j]=N
N+=1
toID=lambda i,j:id[min(i,j)][max(i,j)]
E=[[] for _ in range(N)]
for i in range(n):
A=list([int(x)-1 for x in input().split()])
for j in range(n-2):
u=toID(i,A[j])
v=toID(i,A[j+1])
E[u].append(v)
# longest path problem
dp=[-1]*N
def dfs(v):
if(dp[v]>=0): return dp[v]
dp[v]=-2
res=0
for nv in E[v]:
if(dp[nv]==-2):
print((-1))
exit()
res=max(res,dfs(nv)+1)
dp[v]=res
return res
print((max(dfs(v) for v in range(N))+1))
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n=int(eval(input()))
# id table
N=0
id=[[None]*n for _ in range(n)]
from itertools import product
for i,j in product(list(range(n)),repeat=2):
if(i>=j): continue
id[i][j]=N
N+=1
toID=lambda i,j:id[min(i,j)][max(i,j)]
E=[[] for _ in range(N)]
for i in range(n):
A=list([int(x)-1 for x in input().split()])
for j in range(n-2):
u=toID(i,A[j])
v=toID(i,A[j+1])
E[u].append(v)
# longest path problem
dp=[-1]*N
def dfs(v):
if(dp[v]>=0): return dp[v]
dp[v]=-2
res=0
for nv in E[v]:
if(dp[nv]==-2):
print((-1))
exit()
res=max(res,dfs(nv)+1)
dp[v]=res
return res
print((max(dfs(v) for v in range(N))+1))
resolve() | 41 | 42 | 958 | 1,001 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
# id table
N = 0
id = [[None] * n for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
id[i][j] = N
N += 1
toID = lambda i, j: id[min(i, j)][max(i, j)]
E = [[] for _ in range(N)]
for i in range(n):
A = list([int(x) - 1 for x in input().split()])
for j in range(n - 2):
u = toID(i, A[j])
v = toID(i, A[j + 1])
E[u].append(v)
# longest path problem
dp = [-1] * N
def dfs(v):
if dp[v] >= 0:
return dp[v]
dp[v] = -2
res = 0
for nv in E[v]:
if dp[nv] == -2:
print((-1))
exit()
res = max(res, dfs(nv) + 1)
dp[v] = res
return res
print((max(dfs(v) for v in range(N)) + 1))
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n = int(eval(input()))
# id table
N = 0
id = [[None] * n for _ in range(n)]
from itertools import product
for i, j in product(list(range(n)), repeat=2):
if i >= j:
continue
id[i][j] = N
N += 1
toID = lambda i, j: id[min(i, j)][max(i, j)]
E = [[] for _ in range(N)]
for i in range(n):
A = list([int(x) - 1 for x in input().split()])
for j in range(n - 2):
u = toID(i, A[j])
v = toID(i, A[j + 1])
E[u].append(v)
# longest path problem
dp = [-1] * N
def dfs(v):
if dp[v] >= 0:
return dp[v]
dp[v] = -2
res = 0
for nv in E[v]:
if dp[nv] == -2:
print((-1))
exit()
res = max(res, dfs(nv) + 1)
dp[v] = res
return res
print((max(dfs(v) for v in range(N)) + 1))
resolve()
| false | 2.380952 | [
"- for i in range(n):",
"- for j in range(i + 1, n):",
"- id[i][j] = N",
"- N += 1",
"+ from itertools import product",
"+",
"+ for i, j in product(list(range(n)), repeat=2):",
"+ if i >= j:",
"+ continue",
"+ id[i][j] = N",
"+ ... | false | 0.038159 | 0.00801 | 4.763763 | [
"s585844621",
"s547459645"
] |
u440566786 | p02703 | python | s906008758 | s787230627 | 1,798 | 826 | 79,860 | 95,624 | Accepted | Accepted | 54.06 | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n, m, s = list(map(int,input().split()))
E = [None] * m
S = 0
for i in range(m):
u, v, a, b = list(map(int,input().split()))
S += a
E[i] = (u - 1, v - 1, -a, b)
exchange = [tuple(map(int,input().split())) for _ in range(n)]
dp = [[INF] * (S + 1) for _ in range(n)]
dp[0][min(s, S)] = 0
for _ in range(2 * n - 3):
# 先に両替を済ませる
for v in range(n):
for s in range(S + 1):
ds, dt = exchange[v]
dp[v][min(s + ds, S)] = min(dp[v][min(s + ds, S)], dp[v][s] + dt)
# 移動する
for u, v, ds, dt in E:
for s in range(S + 1):
ns = s + ds
if ns < 0:
continue
dp[u][ns] = min(dp[u][ns], dp[v][s] + dt)
dp[v][ns] = min(dp[v][ns], dp[u][s] + dt)
for v in range(1, n):
print((min(dp[v][j] for j in range(S + 1))))
resolve() | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from heapq import heappop, heappush
def resolve():
n, m, s = list(map(int,input().split()))
S = 0
E = [[] for _ in range(n)]
for _ in range(m):
u, v, a, b = list(map(int,input().split())) # a : cost silver
u -= 1; v -= 1
S += a
E[u].append((v, -a, b))
E[v].append((u, -a, b))
for v in range(n):
c, d = list(map(int,input().split()))
E[v].append((v, c, d))
# Dijkstra with heap
dist = [[INF] * (S + 1) for _ in range(n)]
s = min(s, S)
dist[0][s] = 0
heap = [(0, 0, s)] # dist, vertex, silver
while heap:
d, v, s = heappop(heap)
if dist[v][s] < d:
continue
for nv, ds, dd in E[v]:
ns = s + ds
if not (0 <= ns <= S):
continue
if dist[nv][ns] > dist[v][s] + dd:
dist[nv][ns] = dist[v][s] + dd
heappush(heap, (dist[nv][ns], nv, ns))
# output
for v in range(1, n):
print((min(dist[v][s] for s in range(S + 1))))
resolve() | 36 | 41 | 1,107 | 1,202 | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda: sys.stdin.readline().rstrip()
def resolve():
n, m, s = list(map(int, input().split()))
E = [None] * m
S = 0
for i in range(m):
u, v, a, b = list(map(int, input().split()))
S += a
E[i] = (u - 1, v - 1, -a, b)
exchange = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[INF] * (S + 1) for _ in range(n)]
dp[0][min(s, S)] = 0
for _ in range(2 * n - 3):
# 先に両替を済ませる
for v in range(n):
for s in range(S + 1):
ds, dt = exchange[v]
dp[v][min(s + ds, S)] = min(dp[v][min(s + ds, S)], dp[v][s] + dt)
# 移動する
for u, v, ds, dt in E:
for s in range(S + 1):
ns = s + ds
if ns < 0:
continue
dp[u][ns] = min(dp[u][ns], dp[v][s] + dt)
dp[v][ns] = min(dp[v][ns], dp[u][s] + dt)
for v in range(1, n):
print((min(dp[v][j] for j in range(S + 1))))
resolve()
| import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda: sys.stdin.readline().rstrip()
from heapq import heappop, heappush
def resolve():
n, m, s = list(map(int, input().split()))
S = 0
E = [[] for _ in range(n)]
for _ in range(m):
u, v, a, b = list(map(int, input().split())) # a : cost silver
u -= 1
v -= 1
S += a
E[u].append((v, -a, b))
E[v].append((u, -a, b))
for v in range(n):
c, d = list(map(int, input().split()))
E[v].append((v, c, d))
# Dijkstra with heap
dist = [[INF] * (S + 1) for _ in range(n)]
s = min(s, S)
dist[0][s] = 0
heap = [(0, 0, s)] # dist, vertex, silver
while heap:
d, v, s = heappop(heap)
if dist[v][s] < d:
continue
for nv, ds, dd in E[v]:
ns = s + ds
if not (0 <= ns <= S):
continue
if dist[nv][ns] > dist[v][s] + dd:
dist[nv][ns] = dist[v][s] + dd
heappush(heap, (dist[nv][ns], nv, ns))
# output
for v in range(1, n):
print((min(dist[v][s] for s in range(S + 1))))
resolve()
| false | 12.195122 | [
"+from heapq import heappop, heappush",
"- E = [None] * m",
"- for i in range(m):",
"- u, v, a, b = list(map(int, input().split()))",
"+ E = [[] for _ in range(n)]",
"+ for _ in range(m):",
"+ u, v, a, b = list(map(int, input().split())) # a : cost silver",
"+ u -= 1"... | false | 0.091195 | 0.065312 | 1.396285 | [
"s906008758",
"s787230627"
] |
u186838327 | p03254 | python | s502293992 | s094030786 | 169 | 63 | 38,512 | 61,936 | Accepted | Accepted | 62.72 | n, x = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
i = 0
ans = 0
while x > 0 and i<= n-1:
if x >= l[i]:
x -= l[i]
if i == n-1:
if x == 0:
ans += 1
break
else:
break
else:
i += 1
ans += 1
else:
x = 0
break
print(ans)
| n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
ans = 0
for i, a in enumerate(A):
if i != n-1:
if x >= a:
ans += 1
x -= a
else:
break
else:
if x == a:
ans += 1
else:
break
print(ans)
| 23 | 17 | 341 | 329 | n, x = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
i = 0
ans = 0
while x > 0 and i <= n - 1:
if x >= l[i]:
x -= l[i]
if i == n - 1:
if x == 0:
ans += 1
break
else:
break
else:
i += 1
ans += 1
else:
x = 0
break
print(ans)
| n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
ans = 0
for i, a in enumerate(A):
if i != n - 1:
if x >= a:
ans += 1
x -= a
else:
break
else:
if x == a:
ans += 1
else:
break
print(ans)
| false | 26.086957 | [
"-l = list(map(int, input().split()))",
"-l.sort()",
"-i = 0",
"+A = list(map(int, input().split()))",
"+A.sort()",
"-while x > 0 and i <= n - 1:",
"- if x >= l[i]:",
"- x -= l[i]",
"- if i == n - 1:",
"- if x == 0:",
"- ans += 1",
"- b... | false | 0.036618 | 0.032911 | 1.112648 | [
"s502293992",
"s094030786"
] |
u864197622 | p02604 | python | s312441578 | s856646686 | 1,928 | 1,610 | 88,628 | 88,760 | Accepted | Accepted | 16.49 | N = int(input())
X = []
Y = []
P = []
for _ in range(N):
x, y, p = map(int, input().split())
X.append(x)
Y.append(y)
P.append(p)
DX = [[0] * N for _ in range(1 << N)]
DY = [[0] * N for _ in range(1 << N)]
for i, x in enumerate(X):
for k in range(1 << N):
d = abs(x)
for j, xx in enumerate(X):
if k & (1 << j):
d = min(d, abs(xx - x))
DX[k][i] = d * P[i]
for i, y in enumerate(Y):
for k in range(1 << N):
d = abs(y)
for j, yy in enumerate(Y):
if k & (1 << j):
d = min(d, abs(yy - y))
DY[k][i] = d * P[i]
ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
PC[i] = PC[i^1] + 1 if i % 2 else PC[i//2]
RA = []
for i in range(1 << N):
t = []
for j in range(N):
if i & (1 << j):
t.append(j)
RA.append(t)
mm = (1 << N) - 1
for i in range(1 << N):
m = i ^ mm
j = m
while 1:
ans = 0
for k in RA[i^j^mm]:
ans += min(DX[i][k], DY[j][k])
pc = PC[i] + PC[j]
ANS[pc] = min(ANS[pc], ans)
if not j:
break
j = m & (j - 1)
print(*ANS, sep = "\n")
| N = int(input())
X = []
Y = []
P = []
for _ in range(N):
x, y, p = map(int, input().split())
X.append(x)
Y.append(y)
P.append(p)
DX = [[0] * N for _ in range(1 << N)]
DY = [[0] * N for _ in range(1 << N)]
for i, x in enumerate(X):
for k in range(1 << N):
d = abs(x)
for j, xx in enumerate(X):
if k & (1 << j):
d = min(d, abs(xx - x))
DX[k][i] = d * P[i]
for i, y in enumerate(Y):
for k in range(1 << N):
d = abs(y)
for j, yy in enumerate(Y):
if k & (1 << j):
d = min(d, abs(yy - y))
DY[k][i] = d * P[i]
ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
PC[i] = PC[i^1] + 1 if i % 2 else PC[i//2]
RA = []
for i in range(1 << N):
t = []
for j in range(N):
if i & (1 << j):
t.append(j)
RA.append(t)
mm = (1 << N) - 1
for i in range(1 << N):
m = i ^ mm
j = m
dxi = DX[i]
while 1:
dyj = DY[j]
ans = 0
for k in RA[i^j^mm]:
ans += min(dxi[k], dyj[k])
pc = PC[i] + PC[j]
ANS[pc] = min(ANS[pc], ans)
if not j:
break
j = m & (j - 1)
print(*ANS, sep = "\n")
| 59 | 61 | 1,282 | 1,316 | N = int(input())
X = []
Y = []
P = []
for _ in range(N):
x, y, p = map(int, input().split())
X.append(x)
Y.append(y)
P.append(p)
DX = [[0] * N for _ in range(1 << N)]
DY = [[0] * N for _ in range(1 << N)]
for i, x in enumerate(X):
for k in range(1 << N):
d = abs(x)
for j, xx in enumerate(X):
if k & (1 << j):
d = min(d, abs(xx - x))
DX[k][i] = d * P[i]
for i, y in enumerate(Y):
for k in range(1 << N):
d = abs(y)
for j, yy in enumerate(Y):
if k & (1 << j):
d = min(d, abs(yy - y))
DY[k][i] = d * P[i]
ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
PC[i] = PC[i ^ 1] + 1 if i % 2 else PC[i // 2]
RA = []
for i in range(1 << N):
t = []
for j in range(N):
if i & (1 << j):
t.append(j)
RA.append(t)
mm = (1 << N) - 1
for i in range(1 << N):
m = i ^ mm
j = m
while 1:
ans = 0
for k in RA[i ^ j ^ mm]:
ans += min(DX[i][k], DY[j][k])
pc = PC[i] + PC[j]
ANS[pc] = min(ANS[pc], ans)
if not j:
break
j = m & (j - 1)
print(*ANS, sep="\n")
| N = int(input())
X = []
Y = []
P = []
for _ in range(N):
x, y, p = map(int, input().split())
X.append(x)
Y.append(y)
P.append(p)
DX = [[0] * N for _ in range(1 << N)]
DY = [[0] * N for _ in range(1 << N)]
for i, x in enumerate(X):
for k in range(1 << N):
d = abs(x)
for j, xx in enumerate(X):
if k & (1 << j):
d = min(d, abs(xx - x))
DX[k][i] = d * P[i]
for i, y in enumerate(Y):
for k in range(1 << N):
d = abs(y)
for j, yy in enumerate(Y):
if k & (1 << j):
d = min(d, abs(yy - y))
DY[k][i] = d * P[i]
ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
PC[i] = PC[i ^ 1] + 1 if i % 2 else PC[i // 2]
RA = []
for i in range(1 << N):
t = []
for j in range(N):
if i & (1 << j):
t.append(j)
RA.append(t)
mm = (1 << N) - 1
for i in range(1 << N):
m = i ^ mm
j = m
dxi = DX[i]
while 1:
dyj = DY[j]
ans = 0
for k in RA[i ^ j ^ mm]:
ans += min(dxi[k], dyj[k])
pc = PC[i] + PC[j]
ANS[pc] = min(ANS[pc], ans)
if not j:
break
j = m & (j - 1)
print(*ANS, sep="\n")
| false | 3.278689 | [
"+ dxi = DX[i]",
"+ dyj = DY[j]",
"- ans += min(DX[i][k], DY[j][k])",
"+ ans += min(dxi[k], dyj[k])"
] | false | 0.062027 | 0.190931 | 0.324866 | [
"s312441578",
"s856646686"
] |
u489959379 | p03682 | python | s856882898 | s856509280 | 1,559 | 1,325 | 62,428 | 65,008 | Accepted | Accepted | 15.01 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
# Union Find(経路圧縮有)
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 親が同じか判別
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# 根を繋ぎ直す
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 親が同じか判別
def same(self, x, y):
return self.find(x) == self.find(y)
# 連結成分の大きさを返す
def size(self, x):
return -self.parents[self.find(x)]
def kruskal(max_node, edge):
"""
:param max_node: UnionFind木に渡す頂点数です
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
uf = UnionFind(max_node)
cost_sum = 0
for cost, node1, node2 in edge:
if not uf.same(node1, node2):
cost_sum += cost
uf.union(node1, node2)
return cost_sum
def resolve():
n = int(eval(input()))
X, Y = [], []
for i in range(n):
x, y = list(map(int, input().split()))
X.append([x, i])
Y.append([y, i])
X.sort()
Y.sort()
cost = []
for i in range(n - 1):
cost.append([abs(X[i][0] - X[i + 1][0]), X[i][1], X[i + 1][1]])
cost.append([abs(Y[i][0] - Y[i + 1][0]), Y[i][1], Y[i + 1][1]])
res = kruskal(n, cost)
print(res)
if __name__ == '__main__':
resolve()
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
"""
親が同じか判別する
"""
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
"""
yをxの根に繋ぐ
"""
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def same(self, x, y):
"""
xとyが同じ連結成分か判別する
"""
return self.find(x) == self.find(y)
def size(self, x):
"""
xの連結成分の大きさを返す
"""
return -self.parents[self.find(x)]
def kruskal(self, edge):
"""
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
cost_sum = 0
for cost, node1, node2 in edge:
if not self.same(node1, node2):
cost_sum += cost
self.union(node1, node2)
return cost_sum
def resolve():
n = int(eval(input()))
X, Y = [], []
for i in range(n):
x, y = list(map(int, input().split()))
X.append([x, i])
Y.append([y, i])
X.sort()
Y.sort()
edge = []
for i in range(1, n):
cost1 = X[i][0] - X[i - 1][0]
edge.append([cost1, X[i - 1][1], X[i][1]])
cost2 = Y[i][0] - Y[i - 1][0]
edge.append([cost2, Y[i - 1][1], Y[i][1]])
uf = UnionFind(n)
res = uf.kruskal(edge)
print(res)
if __name__ == '__main__':
resolve()
| 79 | 84 | 1,806 | 1,940 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
# Union Find(経路圧縮有)
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 親が同じか判別
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# 根を繋ぎ直す
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 親が同じか判別
def same(self, x, y):
return self.find(x) == self.find(y)
# 連結成分の大きさを返す
def size(self, x):
return -self.parents[self.find(x)]
def kruskal(max_node, edge):
"""
:param max_node: UnionFind木に渡す頂点数です
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
uf = UnionFind(max_node)
cost_sum = 0
for cost, node1, node2 in edge:
if not uf.same(node1, node2):
cost_sum += cost
uf.union(node1, node2)
return cost_sum
def resolve():
n = int(eval(input()))
X, Y = [], []
for i in range(n):
x, y = list(map(int, input().split()))
X.append([x, i])
Y.append([y, i])
X.sort()
Y.sort()
cost = []
for i in range(n - 1):
cost.append([abs(X[i][0] - X[i + 1][0]), X[i][1], X[i + 1][1]])
cost.append([abs(Y[i][0] - Y[i + 1][0]), Y[i][1], Y[i + 1][1]])
res = kruskal(n, cost)
print(res)
if __name__ == "__main__":
resolve()
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
"""
親が同じか判別する
"""
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
"""
yをxの根に繋ぐ
"""
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def same(self, x, y):
"""
xとyが同じ連結成分か判別する
"""
return self.find(x) == self.find(y)
def size(self, x):
"""
xの連結成分の大きさを返す
"""
return -self.parents[self.find(x)]
def kruskal(self, edge):
"""
:param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
:return: 最小全域木のコストの和
"""
edge.sort()
cost_sum = 0
for cost, node1, node2 in edge:
if not self.same(node1, node2):
cost_sum += cost
self.union(node1, node2)
return cost_sum
def resolve():
n = int(eval(input()))
X, Y = [], []
for i in range(n):
x, y = list(map(int, input().split()))
X.append([x, i])
Y.append([y, i])
X.sort()
Y.sort()
edge = []
for i in range(1, n):
cost1 = X[i][0] - X[i - 1][0]
edge.append([cost1, X[i - 1][1], X[i][1]])
cost2 = Y[i][0] - Y[i - 1][0]
edge.append([cost2, Y[i - 1][1], Y[i][1]])
uf = UnionFind(n)
res = uf.kruskal(edge)
print(res)
if __name__ == "__main__":
resolve()
| false | 5.952381 | [
"-# Union Find(経路圧縮有)",
"+",
"+",
"- # 親が同じか判別",
"+ \"\"\"",
"+ 親が同じか判別する",
"+ \"\"\"",
"- # 根を繋ぎ直す",
"+ \"\"\"",
"+ yをxの根に繋ぐ",
"+ \"\"\"",
"- # 親が同じか判別",
"+ \"\"\"",
"+ xとyが同じ連結成分か判別する",
"+ \"\"\"",
"- # 連結成分の大... | false | 0.039044 | 0.109026 | 0.35812 | [
"s856882898",
"s856509280"
] |
u414980766 | p02919 | python | s517151981 | s246780522 | 910 | 175 | 14,028 | 16,212 | Accepted | Accepted | 80.77 | import bisect
import array
N = int(eval(input()))
P = list(map(int, input().split()))
P_id = [0]*(N + 1)
for i in range(N):
P_id[P[i]] = i
A = array.array('i', [- 1, P_id[N], N])
res = 0
for i in range(N - 1, 0, - 1):
j = bisect.bisect_left(A, P_id[i])
A.insert(j, P_id[i])
l1 = A[j - 1]
r1 = A[j + 1]
l2 = l1
r2 = r1
if l1 != - 1:
l2 = A[j - 2]
if r1 != N:
r2 = A[j + 2]
res += i*((A[j] - l1)*(r2 - r1) + (l1 - l2)*(r1 - A[j]))
print(res) | N = int(eval(input()))
P_id = [0]*(N + 1) # P_id[i]は順列Pに置けるiのindex, P[0]は無視
for index, p in enumerate(map(int, input().split())):
P_id[p] = index
left_next_index = list(range(- 1, N - 1)) + ['うんこ', - 1] # + [- 1]ではないことに注意, left_next_index[r1] = l1においてr1 = Nの場合があるから
right_next_index = list(range(1, N + 1)) + [N, 'うんこ']
res = 0
for p in range(1, N):
l1 = left_next_index[P_id[p]]
l2 = left_next_index[l1]
r1 = right_next_index[P_id[p]]
r2 = right_next_index[r1]
res += p*((l1 - l2)*(r1 - P_id[p]) + (P_id[p] - l1)*(r2 - r1))
left_next_index[r1] = l1
right_next_index[l1] = r1
print(res) | 28 | 21 | 526 | 649 | import bisect
import array
N = int(eval(input()))
P = list(map(int, input().split()))
P_id = [0] * (N + 1)
for i in range(N):
P_id[P[i]] = i
A = array.array("i", [-1, P_id[N], N])
res = 0
for i in range(N - 1, 0, -1):
j = bisect.bisect_left(A, P_id[i])
A.insert(j, P_id[i])
l1 = A[j - 1]
r1 = A[j + 1]
l2 = l1
r2 = r1
if l1 != -1:
l2 = A[j - 2]
if r1 != N:
r2 = A[j + 2]
res += i * ((A[j] - l1) * (r2 - r1) + (l1 - l2) * (r1 - A[j]))
print(res)
| N = int(eval(input()))
P_id = [0] * (N + 1) # P_id[i]は順列Pに置けるiのindex, P[0]は無視
for index, p in enumerate(map(int, input().split())):
P_id[p] = index
left_next_index = list(range(-1, N - 1)) + [
"うんこ",
-1,
] # + [- 1]ではないことに注意, left_next_index[r1] = l1においてr1 = Nの場合があるから
right_next_index = list(range(1, N + 1)) + [N, "うんこ"]
res = 0
for p in range(1, N):
l1 = left_next_index[P_id[p]]
l2 = left_next_index[l1]
r1 = right_next_index[P_id[p]]
r2 = right_next_index[r1]
res += p * ((l1 - l2) * (r1 - P_id[p]) + (P_id[p] - l1) * (r2 - r1))
left_next_index[r1] = l1
right_next_index[l1] = r1
print(res)
| false | 25 | [
"-import bisect",
"-import array",
"-",
"-P = list(map(int, input().split()))",
"-P_id = [0] * (N + 1)",
"-for i in range(N):",
"- P_id[P[i]] = i",
"-A = array.array(\"i\", [-1, P_id[N], N])",
"+P_id = [0] * (N + 1) # P_id[i]は順列Pに置けるiのindex, P[0]は無視",
"+for index, p in enumerate(map(int, input... | false | 0.03832 | 0.039359 | 0.973584 | [
"s517151981",
"s246780522"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.