s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s387903052
p04049
u284854859
1550812204
Python
Python (3.4.3)
py
Runtime Error
1775
4664
781
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append([a-1,b-1]) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e != y: if c > d and e >= 0 and e<= n-1: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) #f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s691044328
p04049
u284854859
1550811642
Python
Python (3.4.3)
py
Runtime Error
2104
4652
835
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append([a-1,b-1]) if n==2: print(0) exit() def f(x,y,c): c += 1 if len(edge)-1 >=x and x >= 0: for e in edge[x]: if e != y: if c > d and e >= 0 and e<= n-1: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s299004138
p04049
u284854859
1550811039
Python
Python (3.4.3)
py
Runtime Error
1969
4664
832
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append([a-1,b-1]) if n==2: print(0) exit() def f(x,y,c): c += 1 if len(edge)-1 >=x and x >= 0: for e in edge[x]: if e != y: if c > d: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: nag = [0]*n used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s584456806
p04049
u284854859
1550810901
Python
Python (3.4.3)
py
Runtime Error
1121
4668
775
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append([a-1,b-1]) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e != y: #if c > d: #used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: nag = [0]*n used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s310044627
p04049
u284854859
1550810751
Python
Python (3.4.3)
py
Runtime Error
1951
4676
944
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append([a-1,b-1]) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e == y: continue if c > d: used[e] = 1 f(e,x,c) def g(x,y): for e in edge[x]: if e == y: continue nag[e] = nag[x]+1 if nag[e] > d: used[e] = 1 g(e,x) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: nag = [0]*n used = [0]*n g(e1[0],e1[1]) g(e1[1],e1[0]) res.append(sum(used)) print(min(res))
s621226825
p04049
u284854859
1550810351
Python
Python (3.4.3)
py
Runtime Error
1438
4648
767
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append([a-1,b-1]) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e == y: continue if c > d: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s726216232
p04049
u284854859
1550809842
Python
Python (3.4.3)
py
Runtime Error
1514
4596
816
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append((a-1,b-1)) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e == y: continue if c > d: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: if k == 1: print(n-2) exit() d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s811438918
p04049
u284854859
1550809375
Python
Python (3.4.3)
py
Runtime Error
1368
4588
791
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append((a-1,b-1)) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e == y: continue if c > d: used[e] = 1 f(e,x,c) if k % 2 == 0: print(0) exit() d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s626659322
p04049
u284854859
1550809114
Python
Python (3.4.3)
py
Runtime Error
1461
4588
768
#import sys #input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append((a-1,b-1)) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e == y: continue if c > d: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s397303827
p04049
u284854859
1550808843
Python
Python (3.4.3)
py
Runtime Error
1473
4592
766
import sys input = sys.stdin.readline n,k = map(int,input().split()) edge = [[] for i in range(n)] alledge = [] for i in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) alledge.append((a-1,b-1)) if n==2: print(0) exit() def f(x,y,c): c += 1 for e in edge[x]: if e == y: continue if c > d: used[e] = 1 f(e,x,c) if k % 2 == 0: d = k//2 res = [] for i in range(n): used = [0]*n f(i,-1,0) res.append(sum(used)) print(min(res)) else: d = (k-1)//2 res = [] for e1 in alledge: used = [0]*n f(e1[0],e1[1],0) f(e1[1],e1[0],0) res.append(sum(used)) print(min(res))
s098360855
p04049
u111421568
1537411803
Python
Python (3.4.3)
py
Runtime Error
1280
5208
873
n, k = map(int, input().split()) import sys sys.setrecursionlimit(2000) l = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) l[a-1].append(b-1) l[b-1].append(a-1) def first_search(first, depth): record = 0 for i in l[first]: temp = search(first, i, depth-1) if record < temp: record = temp return record + 1 def search(before, now, depth): if depth <= 0: return 1 else: ans = 1 for i in l[now]: if before != i: ans += search(now, i, depth-1) return ans ret = 0 if k%2 == 0: for i in range(n): temp = search(-1, i, k//2) if temp > ret: ret = temp else: for i in range(n): temp = first_search(i, k) if temp > ret: ret = temp print(n-ret)
s651912799
p04049
u111421568
1537411224
Python
Python (3.4.3)
py
Runtime Error
1203
5204
724
n, k = map(int, input().split()) import sys sys.setrecursionlimit(2000) l = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) l[a-1].append(b-1) l[b-1].append(a-1) def first_search(first, depth): record = 0 for i in l[first]: temp = search(first, i, depth-1) if record < temp: record = temp return record + 1 def search(before, now, depth): if depth <= 0: return 1 else: ans = 1 for i in l[now]: if before != i: ans += search(now, i, depth-1) return ans ret = 0 for i in range(n): temp = first_search(i, k) if temp > ret: ret = temp print(n-ret)
s070727505
p04049
u111421568
1537402449
Python
Python (3.4.3)
py
Runtime Error
1207
5200
763
n, k = map(int, input().split()) import sys sys.setrecursionlimit(2000) l = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) l[a-1].append(b-1) l[b-1].append(a-1) def first_search(first, depth): record = 0 for i in l[first]: temp = search(first, i, depth-1) if record < temp: record = temp return record + 1 def search(before, now, depth): if depth == 0: return 1 else: ans = 1 for i in l[now]: if before != i: ans += search(now, i, depth-1) return ans ret = 0 for i in range(n): temp = first_search(i, k) if temp > ret: ret = temp if ret > n: print(0) else: print(n-ret)
s799452240
p04049
u111421568
1537400641
Python
Python (3.4.3)
py
Runtime Error
1187
4300
749
n, k = map(int, input().split()) l = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) l[a-1].append(b-1) l[b-1].append(a-1) l2 = [0 for i in range(n)] def first_search(first, depth): record = 0 for i in l[first]: temp = search(first, i, depth-1) if record < temp: record = temp return record+1 def search(before, now, depth): if depth == 0: return 1 else: ans = 1 for i in l[now]: if before != i: ans += search(now, i, depth-1) return ans ret = 0 for i in range(n): temp = first_search(i, k) if temp > ret: ret = temp if ret > n: print(0) else: print(n-ret)
s284151588
p04049
u631277801
1536947230
Python
PyPy3 (2.4.0)
py
Runtime Error
419
48988
1780
import sys stdin = sys.stdin def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import deque from collections import defaultdict def bfs(graph:list, start:int) -> list: # 未探索のノードは距離null node = len(graph) dist = [None]*node # 始点ノードの距離を0とし、bfsのためのqueueを作成 dist[start] = 0 que = deque([(0,start)]) # 未探索のノードをqueueに入れる # kより大きいの距離のものを数える while que: cost, cur_node = que.popleft() for nex_cost, nex_node in graph[cur_node]: if dist[nex_node] is not None: continue else: dist[nex_node] = dist[cur_node] + nex_cost que.append((dist[nex_node], nex_node)) return dist # 入力, グラフ作成 n,k = li() adj_list = [[(1,i+1)] for i in range(1999)] adj_list.append([]) edges = [] for i in range(1,2000): adj_list[i].append((1,i-1)) edges.append((i-1,i)) for i in range(2000): d = bfs(adj_list, i) start = t.clock() ans = n # kが奇数の時 if k%2: for a,b in edges: dist1 = bfs(adj_list, a) dist2 = bfs(adj_list, b) ans = min(ans, sum([min(d1,d2) > (k-1)//2 for d1,d2 in zip(dist1, dist2)])) # kが偶数の時 else: for st in range(n): dist = bfs(adj_list, st) ans = min(ans, sum([d > k//2 for d in dist])) print(ans)
s304854364
p04049
u224119305
1533123762
Python
Python (3.4.3)
py
Runtime Error
170
73124
723
import numpy as np N, K = map(int, input().split()) E = np.zeros((N, N), dtype=int) # Elist = [] for e in range(N-1): i, o = map(int, input().split()) # Elist.append((i-1, o-1)) E[i-1][o-1] = 1 E[o-1][i-1] = 1 # print("N, K=", N, K) # for e in Elist: # print(e[0], e[1]) I = np.eye(N, dtype=int) # print("I=", I) ie = I for k in range(K): ie = ie + np.matmul(I, E) # print("I + IE =", ie) exit(0) # withinK = np.count_nonzero(ie, axis=0) withinK = np.zeros(N, dtype=int) for i in range(N): for j in range(N): if ie[i][j] > 0: withinK[i] += 1 # print("withinK=", withinK) maxBall = np.amax(withinK) # print("maxBall=", maxBall) solution = N - maxBall print(solution)
s669543599
p04049
u224119305
1533123464
Python
Python (3.4.3)
py
Runtime Error
343
73036
715
import numpy as np N, K = map(int, input().split()) E = np.zeros((N, N), dtype=int) Elist = [] for e in range(N-1): i, o = map(int, input().split()) Elist.append((i-1, o-1)) E[i-1][o-1] = 1 E[o-1][i-1] = 1 # print("N, K=", N, K) # for e in Elist: # print(e[0], e[1]) I = np.eye(N, dtype=int) # print("I=", I) ie = I for k in range(K): ie = ie + np.matmul(I, E) # print("I + IE =", ie) # withinK = np.count_nonzero(ie, axis=0) withinK = np.zeros(N, dtype=int) for i in range(N): for j in range(N): if ie[i][j] > 0: withinK[i] += 1 # print("withinK=", withinK) maxBall = np.amax(withinK) # print("maxBall=", maxBall) solution = N - maxBall print(solution)
s624676471
p04049
u224119305
1533123191
Python
Python (3.4.3)
py
Runtime Error
173
73032
648
import numpy as np N, K = map(int, input().split()) E = np.zeros((N, N), dtype=int) Elist = [] for e in range(N-1): i, o = map(int, input().split()) Elist.append((i-1, o-1)) E[i-1][o-1] = 1 E[o-1][i-1] = 1 # print("N, K=", N, K) # for e in Elist: # print(e[0], e[1]) I = np.eye(N, dtype=int) # print("I=", I) ie = I for k in range(K): ie = ie + np.matmul(I, E) # print("I + IE =", ie) withinK = np.count_nonzero(ie, axis=0) # for i in range(N): # withinK[i] = np.count_nonzero(ie[i]) # print("withinK=", withinK) maxBall = np.amax(withinK) # print("maxBall=", maxBall) solution = N - maxBall print(solution)
s423454121
p04049
u075012704
1531432306
Python
PyPy3 (2.4.0)
py
Runtime Error
741
85208
1008
from collections import deque N, K = map(int, input().split()) T = [[] for i in range(N)] E = [] for i in range(N-1): a, b = map(int, input().split()) a, b = a-1, b-1 T[a].append(b) T[b].append(a) E.append((a, b)) def bfs(n): visited = [False] * N dist = [0] * N queue = deque([n]) while queue: node = queue.pop() if visited[node]: continue visited[node] = True for n in T[node]: if not visited[n]: dist[n] = dist[node] + 1 queue.appendleft(n) return dist dist = [] for i in range(N): dist.append(bfs(i)) ans = float('inf') if K % 2 == 0: # 全ての頂点について全探索 for i in range(N): ans = min(ans, len(d for d in dist[i] if d > K / 2)) else: # 全ての辺について全探索 for a, b in E: adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])] ans = min(ans, sum(adist)) print(ans)
s889802136
p04049
u075012704
1531431902
Python
PyPy3 (2.4.0)
py
Runtime Error
1359
85720
1030
from collections import deque N, K = map(int, input().split()) T = [[] for i in range(N)] E = [] for i in range(N-1): a, b = map(int, input().split()) a, b = a-1, b-1 T[a].append(b) T[b].append(a) E.append((a, b)) def bfs(n): visited = [False] * N dist = [0] * N queue = deque([n]) while queue: node = queue.pop() if visited[node]: continue visited[node] = True for n in T[node]: if not visited[n]: dist[n] = dist[node] + 1 queue.appendleft(n) return dist dist = [] for i in range(N): dist.append(bfs(i)) ans = float('inf') if K % 2 == 0: # 全ての頂点について全探索 for i in range(N): ans = min(ans, len(list(filter(lambda x: K / 2 < x, dist[i])))) else: # 全ての辺について全探索 for a, b in E: dist = [min(d1, d2) for d1, d2 in zip(dist[a], dist[b])] ans = min(ans, len(list(filter(lambda x: (K-1) / 2 < x, dist)))) print(ans)
s566373062
p04049
u132291455
1478317767
Python
PyPy2 (5.6.0)
py
Runtime Error
41
8944
423
o=lambda:map(int,raw_input().split());r=range(n);a=10**5 n,k=o() e=[[]for _ in [0]*n] for _ in [0]*(n-1):a,b=o();e[a-1]+=[b-1];e[b-1]+=[a-1] def U(x,f): l[f]=1;q=[(x,0)] while len(q): v,c=q.pop(0) if c>k/2:break l[v]=1 for w in e[v]: if not l[w]:q+=[(w,c+1)] return n-l.count(1) if k%2: for i in r: for j in e[i]: if i<j:l=[0]*n;U(i,j);a=min(a,U(j,i)) else: for i in r:l=[0]*n;a=min(a,U(i,-1)) print a
s671156005
p04049
u707500405
1468766326
Python
PyPy2 (5.6.0)
py
Runtime Error
1393
52892
780
def calc_dist(b,h,dist,E,D,ne): D[dist] += 1 for nxt in E[h]: if nxt == b or nxt == ne: continue calc_dist(h,nxt,dist+1,E,D,ne) def solve(): N,K = map(int,raw_input().split()) pairs = [] E = [[] for i in xrange(N)] for i in xrange(N-1): a,b = map(lambda x:int(x)-1,raw_input().split()) E[a].append(b) E[b].append(a) pairs.append((a,b)) ans = N rad = K/2 if K % 2 == 0: for i in xrange(N): D = [0]*N calc_dist(-1,i,0,E,D,-1) for j in xrange(rad): D[rad-j-1] += D[rad-j] ans = min(N-D[0],ans) else: for a,b in pairs: D1 = [0]*N D2 = [0]*N calc_dist(-1,a,0,E,D1,b) calc_dist(-1,b,0,E,D2,a) for j in xrange(rad): D1[rad-j-1] += D1[rad-j] D2[rad-j-1] += D2[rad-j] ans = min(N-D1[0]-D2[0],ans) print ans solve()
s960682356
p04050
u211706121
1576372801
Python
Python (3.4.3)
py
Runtime Error
17
3064
691
n,m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] breakFlag = False for i in range(1,m-1): if a[i]%2==1: if a[0]%2==1: if a[len(a)-1]%2==1: print("Impossible") breakFlag = True break else: a[i],a[len(a)-1] = a[len(a)-1],a[i] else: a[i],a[0] = a[0],a[i] if breakFlag==False: ans = ''.join([str(s)+" " for s in a]) print(ans[:-1]) if a[len(a)-1]==1: print(m-1) a.pop() a[0]+=1 else: print(m) a[0]+=1 a[len(a)-1] -= 1 ans = ''.join([str(s)+" " for s in a]) print(ans[:-1])
s347349727
p04050
u102461423
1569523773
Python
Python (3.4.3)
py
Runtime Error
18
3064
658
import sys readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) N,M = map(int,readline().split()) A = [int(x) for x in readline().split()] OD = [x for x in A if x&1] EV = [x for x in A if not x&1] if len(OD) >= 3: print('Impossible') exit() if len(A) == 1: if N == 1: B = [1] else: B = [1,N-1] elif len(OD) == 0: B = A.copy() B[0] -= 1 B[-1] += 1 elif len(OD) == 1: A = OD + EV B = A.copy() B[0] += 1 B[-1] -= 1 else: A = OD[0] + EV + OD[-1] B = A.copy() B[0] += 1 B[-1] -= 1 B = [x for x in B if x > 0] print(*A) print(len(B)) print(*B)
s747140087
p04050
u816116805
1542177662
Python
Python (3.4.3)
py
Runtime Error
18
3064
689
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # """ agc001 D """ n, m = map(int, input().split()) ali = list(map(int, input().split())) if m == 1: print(ali[0]) print(2) print(ali[0]-1, 1) exit() flag = 0 c = [] for a in ali: if a % 2 == 1: if flag == 0: lm = a flag += 1 elif flag == 1: rm = a flag += 1 elif flag == 2: print('Impossible') exit() else: c.append(a) if flag == 1: rm = c.pop() b = [lm+1] + c d = [lm] + c + [rm] if rm > 1: b.append(rm-1) print(" ".join(map(str, d))) print(len(b)) print(" ".join(map(str, b)))
s950372139
p04050
u816116805
1542177393
Python
Python (3.4.3)
py
Runtime Error
19
3064
684
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # """ agc001 D """ n, m = map(int, input().split()) ali = list(map(int, input().split())) if m == 1: print(ali[0]) print(1) print(ali[0]-1, 1) exit() flag = 0 c = [] for a in ali: if a & 1: if flag == 0: lm = a flag += 1 elif flag == 1: rm = a flag += 1 elif flag == 2: print('Impossible') exit() else: c.append(a) if flag == 1: rm = c.pop() b = [lm+1] + c d = [lm] + c + [rm] if rm > 1: b.append(rm-1) print(" ".join(map(str, d))) print(len(b)) print(" ".join(map(str, b)))
s482351851
p04051
u556571816
1593818777
Python
Python (3.8.2)
py
Runtime Error
2206
67468
382
import math n = int(input()) list = [] for i in range(n): list.append(input().split()) sum = 0 for j in range(n): for k in range(j+1,n): if j!=k: num = math.factorial(int(list[j][0])+int(list[j][1])+int(list[k][0])+int(list[k][1])) / (math.factorial(int(list[j][0])+int(list[k][0]))*math.factorial(int(list[j][1])+int(list[k][1]))) sum += num print(int(sum%(10**9+7)))
s525778405
p04051
u426964396
1576632184
Python
Python (3.4.3)
py
Runtime Error
17
2940
695
#include<bits/stdc++.h> using namespace std; const int N=2e5+50,M=4040,mod=1e9+7,L=2000; int n,a[N],b[N],f[M][M],ans,J[N],I[N]; int C(int n,int m){return 1ll*J[n]*I[m]%mod*I[n-m]%mod;} int main(){ scanf("%d",&n);J[0]=I[0]=I[1]=1; for(int i=2;i<=4*L;i++)I[i]=mod-1ll*mod/i*I[mod%i]%mod; for(int i=1;i<=4*L;i++)J[i]=1ll*J[i-1]*i%mod,I[i]=1ll*I[i-1]*I[i]%mod; for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]); for(int i=1;i<=n;i++)f[L-a[i]][L-b[i]]++; for(int i=0;i<=2*L;i++)for(int j=0;j<=2*L;j++){ if(i)(f[i][j]+=f[i-1][j])%=mod; if(j)(f[i][j]+=f[i][j-1])%=mod; } for(int i=1;i<=n;i++)(ans+=f[L+a[i]][L+b[i]]-C(2*(a[i]+b[i]),2*a[i]))%=mod; printf("%d\n",1ll*ans*I[2]%mod); return 0; }
s389585547
p04051
u102461423
1574125830
Python
Python (3.4.3)
py
Runtime Error
451
40124
1223
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv fact,fact_inv = make_fact(10 ** 4,MOD) fact = fact.tolist() fact_inv = fact_inv.tolist() C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] remove %= MOD dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[:0:-1] += dp[-1::-1] np.add.at(dp,A,1) dp %= MOD x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove if x&1: x += MOD x //= 2 x %= MOD print(x)
s797478744
p04051
u102461423
1574125305
Python
Python (3.4.3)
py
Runtime Error
486
35124
1202
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv fact,fact_inv = make_fact(D+D+100,MOD) fact = fact.tolist() fact_inv = fact_inv.tolist() C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] remove %= MOD dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[1:] += dp[:-1] np.add.at(dp,A,1) x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove if x&1: x += MOD x //= 2 x %= MOD print(x)
s089948526
p04051
u902468164
1549757752
Python
Python (3.4.3)
py
Runtime Error
2104
20520
411
def co(a, b): a += b res = 1 for i in range(1,b+1): res *= ((a-i+1) / i) return int(res) n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] for ni in range(n): a[ni], b[ni] = (int(i) for i in input().split(" ")) a = tuple(a) b = tuple(b) res = 0 for i in range(n): for j in range(i+1,n): res += co(a[i]+a[j], b[i]+b[j]) res %= (10**9+7) print(res)
s293146402
p04051
u902468164
1549757578
Python
Python (3.4.3)
py
Runtime Error
2104
18976
382
def co(a, b): a += b res = 1 for i in range(1,b+1): res *= ((a-i+1) / i) return int(res) n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] for ni in range(n): a[ni], b[ni] = (int(i) for i in input().split(" ")) res = 0 for i in range(n): for j in range(i+1,n): res += co(a[i]+a[j], b[i]+b[j]) res %= 10**9+7 print(res)
s140871420
p04051
u902468164
1549757471
Python
Python (3.4.3)
py
Runtime Error
2103
18984
378
def co(a, b): res = 1 for i in range(1,b+1): res *= ((a-i+1) / i) return int(res) n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] for ni in range(n): a[ni], b[ni] = (int(i) for i in input().split(" ")) res = 0 for i in range(n): for j in range(i+1,n): res += co(a[i]+a[j]+b[i]+b[j], b[i]+b[j]) print(res % (10**9+7))
s200518468
p04051
u638357064
1547945247
Python
Python (3.4.3)
py
Runtime Error
2109
37488
386
# your code goes here from itertools import combinations from scipy.misc import comb N = int(input()) A = [] B = [] for n in range(N): a, b = [int(x) for x in input().split()] A.append(a) B.append(b) S = 0 for n1, n2 in combinations(range(N),2): a1, b1 = A[n1], B[n1] a2, b2 = A[n2], B[n2] s = comb(a1+b1+a2+b2, a1+a2, exact=True) S += s % (1e+9 + 7) S %= 1e+9+7 print(int(S))
s350121004
p04051
u638357064
1547945047
Python
Python (3.4.3)
py
Runtime Error
329
23444
435
# your code goes here from itertools import combinations from scipy.special import comb # a = comb(n, r) # a = comb(n, r, exact=True) N = int(input()) A = [] B = [] for n in range(N): a, b = [int(x) for x in input().split()] A.append(a) B.append(b) S = 0 for n1, n2 in combinations(range(N),2): a1, b1 = A[n1], B[n1] a2, b2 = A[n2], B[n2] s = comb(a1+b1+a2+b2, a1+a2, exact=True) S += s % (1e+9 + 7) S %= 1e+9+7 print(int(S))
s504475340
p04051
u789840108
1539891470
Python
Python (3.4.3)
py
Runtime Error
2106
51748
434
def fact(n): ret = 1 for i in range(2, n+1): ret *= i return ret def C(a,b,c): ret = 1 for i in range(b+1, a + 1): ret *= i return int(ret / fact(c)) n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += C(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1], gu[i][0] + gu[j][0], gu[i][1] + gu[j][1]) print(ret)
s917522426
p04051
u789840108
1539891400
Python
Python (3.4.3)
py
Runtime Error
2106
51748
462
def fact(n): ret = 1 for i in range(2, n+1): ret *= i return ret def C(a,b,c): ret = 1 for i in range(b+1, a + 1): ret *= i return int(ret / fact(c)) n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += C(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1], gu[i][0] + gu[j][0], gu[i][1] + gu[j][1]) print(ret)
s853958902
p04051
u789840108
1539891024
Python
Python (3.4.3)
py
Runtime Error
2106
51748
378
def fact(n): ret = 1 for i in range(2, n+1): ret *= i return ret n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += int(fact(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1]) / fact(gu[i][0] + gu[j][0]) / fact(gu[i][1] + gu[j][1])) print(ret)
s608875432
p04051
u789840108
1539890915
Python
Python (3.4.3)
py
Runtime Error
2106
52692
379
def fact(n): if n == 1: return 1 else: return fact(n - 1) * n n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += int(fact(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1]) / fact(gu[i][0] + gu[j][0]) / fact(gu[i][1] + gu[j][1])) print(ret)
s997331653
p04051
u821262411
1468728349
Python
PyPy3 (2.4.0)
py
Runtime Error
387
43120
357
import scipy.misc as scm def combi(p,q): return scm.comb(p,q,1) ans=0 n=int(input()) k=[] for i in range(n): a,b=map(int,input().split()) k.append([a,b]) for i in range(n-1): for j in range(i+1,n): p=k[i][0]+k[i][1]+k[j][0]+k[j][1] q=k[i][0]+k[j][0] ans += combi(p,q) % (10**9+7) ans = ans % (10**9+7) print(ans)
s741244779
p04051
u821262411
1468723721
Python
PyPy3 (2.4.0)
py
Runtime Error
382
43376
344
import scipy.misc as scm def combi(p,q): return scm.comb(p,q,1) ans=0 n=int(input()) k=[] for i in range(n): a,b=map(int,input().split()) k.append([a,b]) for i in range(n-1): for j in range(1,n): p=k[i][0]+k[i][1]+k[j][0]+k[j][1] q=k[i][0]+k[j][0] ans += combi(p,q) % (10**9+7) print(ans)
s510438237
p04051
u493520238
1468720629
Python
Python (3.4.3)
py
Runtime Error
1741
97888
607
def calc(ab1,ab2): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,2*max_ab): fact_list[i] = fact_list[i-1] * i sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j]) print( int(sum_count % (10**9 + 7)) )
s959683316
p04051
u493520238
1468719899
Python
Python (3.4.3)
py
Runtime Error
1772
97888
626
def calc(ab1,ab2,fact_list): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,2*max_ab): fact_list[i] = fact_list[i-1] * i sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j],fact_list) print( int(sum_count % (10**9 + 7)) )