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
s559206705
p03822
u509368316
1570064446
Python
Python (3.4.3)
py
Runtime Error
526
133864
372
import sys def input(): return sys.stdin.readline().strip() N=int(input()) A=[int(input()) for i in range(N-1)] c=[[] for i in range(N)] for i,a in enumerate(A): c[a-1].append(i+1) import sys sys.setrecursionlimit(10**5) def f(i): if len(c[i])==0: return 0 return max([e+i+1 for i,e in enumerate(sorted([f(j) for j in c[i]],reverse=True))]) print(f(0))
s259333019
p03822
u392319141
1568674493
Python
Python (3.4.3)
py
Runtime Error
386
22980
419
N = int(input()) A = [0, 0] + [int(input()) for _ in range(N - 1)] child = [[] for _ in range(N + 1)] for i, a in enumerate(A): child[a].append(i) def depth(i): if not child[i]: return 0 childDepth = [depth(to) for to in child[i]] childDepth.sort(reverse=True) ret = 0 for j, d in enumerate(childDepth, start=1): ret = max(j + d, ret) return ret ans = depth(1) print(ans)
s394414904
p03822
u794173881
1567814678
Python
Python (3.4.3)
py
Runtime Error
385
23032
543
n = int(input()) tree = [[] for i in range(n)] for i in range(n - 1): j = int(input()) j -= 1 i += 1 tree[i].append(j) tree[j].append(i) def dfs(pos): if pos != 0 and len(tree[pos]) == 1: return 1 li = [] for next_pos in tree[pos]: if visited[next_pos]: continue visited[next_pos] = True li.append(dfs(next_pos)) max_li = max(li) len_li = len(li) res = max(len_li + 1, max_li + 1) return res visited = [False] * n visited[0] = True print(dfs(0) - 1)
s112495609
p03822
u414425367
1567713214
Python
PyPy3 (2.4.0)
py
Runtime Error
1122
171340
356
N=int(input()) edges=[[] for _ in range(N)] def dfs(curr): nrets = sorted([dfs(dst) for dst in edges[curr]]) prev=0 for n in nrets: if n>prev: prev=n else: prev=prev+1 return prev+1 for i in range(N-1): looser = i+1 winner = int(input())-1 edges[winner].append(looser) print(dfs(0)-1)
s306774124
p03822
u214617707
1565447076
Python
PyPy3 (2.4.0)
py
Runtime Error
1031
193740
325
N = int(input()) G = [[] for i in range(N + 1)] for i in range(1, N): a = int(input()) G[a - 1].append(i) def dfs(v): D = [] for w in G[v]: D.append(dfs(w)) D = sorted(D, reverse=True) num = 0 for i in range(len(D)): num = max(num, D[i] + i + 1) return num print(dfs(0))
s161650181
p03822
u163320134
1562957386
Python
Python (3.4.3)
py
Runtime Error
17
3064
351
import sys sys.setrecurtionlimit(10**9) def dfs(v): if len(g[v])==0: return 0 dic={} for u in g[v]: tmp=dfs(u) if tmp not in dic: dic[tmp]=1 else: dic[tmp]+=1 pos=max(dic.keys()) return pos+dic[pos] n=int(input()) g=[[] for _ in range(n+1)] for i in range(n-1): v=int(input()) g[v].append(i+2) print(dfs(1))
s773189563
p03822
u052499405
1559872584
Python
Python (3.4.3)
py
Runtime Error
432
23616
528
n = int(input()) a = [] edge = [[] for _ in range(n)] visited = [0] * n def dfs(n): visited[n] = 1 if len(edge[n]) == 1 and n != 0: return 0 childrank = [] for item in edge[n]: if visited[item] == 1: continue childrank.append(dfs(item)) childrank.sort(reverse=True) for i in range(len(childrank)): childrank[i] += i + 1 return max(childrank) for i in range(1, n): val = int(input()) - 1 edge[i].append(val) edge[val].append(i) print(dfs(0))
s899555286
p03822
u761989513
1553184318
Python
Python (3.4.3)
py
Runtime Error
280
22880
335
def dfs(i, count): global res if not last[i]: res.append(count) for j in last[i]: dfs(j, count + 1) n = int(input()) a = [int(input()) for i in range(n - 1)] last = [[] for i in range(n + 1)] for i in range(2, n + 1): last[a[i - 2]].append(i) res = [] dfs(1, 0) m = max(res) print(m + res.count(m) - 1)
s289268596
p03822
u368780724
1552777258
Python
Python (3.4.3)
py
Runtime Error
304
28892
363
import sys from collections import defaultdict N = int(input()) A = [int(sys.stdin.readline()) for _ in range(N-1)] H = defaultdict(lambda: []) for i, a in enumerate(A, 2): H[a].append(i) def depth(x): if not H[x]: return 0 k = len(H[x]) return max([k - i + j for i, j in zip(range(k), sorted([depth(x) for x in H[x]]))]) print(depth(1))
s953249816
p03822
u894258749
1550878769
Python
Python (3.4.3)
py
Runtime Error
2109
28760
460
import numpy as np N = int(input()) a = np.empty(N+1,dtype=np.int) for i in range(2,N+1): a[i] = int(input()) beated = np.empty(N+1,dtype=np.object) for i in range(1,N+1): beated[i] = [] for i in range(2,N+1): beated[a[i]].append(i) def depth(n): leaves = beated[n] if len(leaves) == 0: return 0 else: dd = np.array([ depth(l) for l in leaves ], dtype=np.int) return (np.sort(dd)[::-1] + range(len(leaves))).max() + 1 print(depth(1))
s634884621
p03822
u894258749
1550874410
Python
Python (3.4.3)
py
Runtime Error
1573
28756
441
import numpy as np N = int(input()) a = np.empty(N+1,dtype=np.int) for i in range(2,N+1): a[i] = int(input()) beated = np.empty(N+2,dtype=np.object) for i in range(1,N+1): beated[i] = [] for i in range(2,N+1): beated[a[i]].append(i) def depth(n): leaves = beated[n] if len(leaves) == 0: return 0 else: dd = np.array([ depth(l) for l in leaves],dtype=np.int) return max(dd.max()+1, dd.min()+len(dd)) print(depth(1))
s795472598
p03822
u894258749
1550873405
Python
Python (3.4.3)
py
Runtime Error
2108
15588
321
import numpy as np N = int(input()) a = np.empty(N+1,dtype=np.int) for i in range(2,N+1): a[i] = int(input()) def depth(n): leaves = np.where(a==n)[0] if len(leaves) == 0: return 0 else: dd = np.array([ depth(l) for l in leaves],dtype=np.int) return max(dd.max()+1, dd.min()+len(dd)) print(depth(1))
s601268105
p03822
u631277801
1550846129
Python
Python (3.4.3)
py
Runtime Error
686
139896
970
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) 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 Counter def rec(n, memo): if memo[n] != -1: return memo[n] if len(graph[n]) == 0: memo[n] = 0 return 0 else: cnt = Counter() for child in graph[n]: cnt[rec(child, memo)] += 1 memo[n] = max(cnt.keys())+1 + (sum(cnt.values()) - len(cnt)) return memo[n] n = ni() memo = [-1]*n graph = [[] for _ in range(n)] i = 1 for _ in range(n-1): ai = ni() - 1 graph[ai].append(i) i += 1 print(rec(0, memo))
s974696343
p03822
u270681687
1550842150
Python
PyPy3 (2.4.0)
py
Runtime Error
1033
179532
752
import heapq n = int(input()) rev_g = [[] for _ in range(n+1)] for i in range(n-1): a = int(input()) rev_g[a].append(i+2) def f(v): if len(rev_g[v]) == 0: return 0 q = [] for nv in rev_g[v]: heapq.heappush(q, f(nv)) max_count = 0 max_num = -1 while q: num = heapq.heappop(q) if max_num == num: max_count += 1 else: max_num += max_count max_count = 0 if num > max_num: max_num = num elif num == max_num: max_count = 1 else: heapq.heappush(q, max_num) max_num = num max_count = 0 return max_num + max_count + 1 print(f(1))
s504454772
p03822
u270681687
1550840822
Python
PyPy3 (2.4.0)
py
Runtime Error
1019
110880
811
import heapq n = int(input()) rev_g = [[] for _ in range(n+1)] for i in range(n-1): a = int(input()) rev_g[a].append(i+2) def f(v): if len(rev_g[v]) == 0: return 0 q = [] for nv in rev_g[v]: heapq.heappush(q, f(nv)) max_count = 0 max_num = 0 while q: num = heapq.heappop(q) if num > max_num + max_count: max_num = num max_count = 0 elif num == max_num + max_count: max_num = num max_count = 1 elif max_num == num: max_count += 1 else: max_num += max_count if max_num > num: heapq.heappush(q, max_num) max_num = num max_count = 0 max_num += max_count return max_num print(f(1)+1)
s768339238
p03822
u562016607
1550807776
Python
Python (3.4.3)
py
Runtime Error
649
155692
345
import sys sys.setrecursionlimit(114514) N=int(input()) a=[-1]+[int(input())-1 for i in range(1,N)] G=[[] for i in range(N)] for i in range(1,N): G[a[i]].append(i) def dp(i): if len(G[i])==0: return 0 X=sorted([dp(j) for j in G[i]],reverse=True) K=len(X) Y=[X[i]+i+1 for i in range(K)] return max(Y) print(dp(0))
s557461881
p03822
u562016607
1550807746
Python
Python (3.4.3)
py
Runtime Error
455
35376
344
import sys sys.setrecursionlimit(11514) N=int(input()) a=[-1]+[int(input())-1 for i in range(1,N)] G=[[] for i in range(N)] for i in range(1,N): G[a[i]].append(i) def dp(i): if len(G[i])==0: return 0 X=sorted([dp(j) for j in G[i]],reverse=True) K=len(X) Y=[X[i]+i+1 for i in range(K)] return max(Y) print(dp(0))
s145580120
p03822
u562016607
1550807694
Python
Python (3.4.3)
py
Runtime Error
664
141108
345
import sys sys.setrecursionlimit(102030) N=int(input()) a=[-1]+[int(input())-1 for i in range(1,N)] G=[[] for i in range(N)] for i in range(1,N): G[a[i]].append(i) def dp(i): if len(G[i])==0: return 0 X=sorted([dp(j) for j in G[i]],reverse=True) K=len(X) Y=[X[i]+i+1 for i in range(K)] return max(Y) print(dp(0))
s489408367
p03822
u562016607
1550807664
Python
Python (3.4.3)
py
Runtime Error
619
138772
345
import sys sys.setrecursionlimit(100030) N=int(input()) a=[-1]+[int(input())-1 for i in range(1,N)] G=[[] for i in range(N)] for i in range(1,N): G[a[i]].append(i) def dp(i): if len(G[i])==0: return 0 X=sorted([dp(j) for j in G[i]],reverse=True) K=len(X) Y=[X[i]+i+1 for i in range(K)] return max(Y) print(dp(0))
s319146570
p03822
u562016607
1550807010
Python
Python (3.4.3)
py
Runtime Error
627
139880
434
import sys sys.setrecursionlimit(10**5+10) N=int(input()) a=[-1]+[int(input())-1 for i in range(1,N)] DP=[-1 for i in range(N)] G=[[] for i in range(N)] for i in range(1,N): G[a[i]].append(i) def dp(i): if DP[i]!=-1: return DP[i] if len(G[i])==0: DP[i]=0 return 0 X=sorted([(dp(j),j) for j in G[i]],reverse=True) K=len(X) Y=[X[i][0]+i+1 for i in range(K)] return max(Y) print(dp(0))
s236821238
p03822
u562016607
1550806953
Python
Python (3.4.3)
py
Runtime Error
496
27008
391
N=int(input()) a=[-1]+[int(input())-1 for i in range(1,N)] DP=[-1 for i in range(N)] G=[[] for i in range(N)] for i in range(1,N): G[a[i]].append(i) def dp(i): if DP[i]!=-1: return DP[i] if len(G[i])==0: DP[i]=0 return 0 X=sorted([(dp(j),j) for j in G[i]],reverse=True) K=len(X) Y=[X[i][0]+i+1 for i in range(K)] return max(Y) print(dp(0))
s825028221
p03822
u884982181
1544147077
Python
PyPy3 (2.4.0)
py
Runtime Error
1019
135456
494
n = int(input()) a=[[]for i in range(n)] for i in range(n-1): x = int(input()) x-=1 a[x].append(i+1) dp=[0]*n huka = [0]*n def dfs(x,y): huka[x]=y for i in a[x]: dfs(i,y+1) dfs(0,0) ya = [] for i in range(n): ya.append([huka[i],i]) ya.sort() ya=ya[::-1] for i in range(n): bb=ya[i][1] tmp=[] for j in a[bb]: tmp.append(dp[j]) tmp.sort() tmp=tmp[::-1] for i in range(1,len(tmp)+1): tmp[i-1]+=i if tmp==[]: tmp.append(0) dp[bb]=max(tmp) print(dp[0])
s170726920
p03822
u236127431
1544040349
Python
PyPy3 (2.4.0)
py
Runtime Error
891
112288
299
N=int(input()) List=[[] for i in range(N)] for i in range(1,N): a=int(input()) List[a-1].append(i) def f(x): if len(List[x])==0: return 0 L=list(map(lambda a:f(a),List[x])) L.sort(key=lambda x:-x) res=0 for i in range(len(L)): res=max(res,L[i]+i+1) return res print(f(0))
s881674356
p03822
u729707098
1541619800
Python
Python (3.4.3)
py
Runtime Error
411
19796
340
n = int(input()) x,q = [[] for i in range(n)],[-1]*n for i in range(n-1): a = int(input())-1 x[a].append(i+1) def f(z): y = [] if x[z]: for i in x[z]: if q[i]+1: y.append(q(i)) else: y.append(f(i)) y = sorted(y)[::-1] for i in range(len(y)): y[i]+=i+1 q[z] = max(y) return max(y) else: q[z] = 0 return 0 print(f(0))
s866469566
p03822
u777923818
1535598655
Python
Python (3.4.3)
py
Runtime Error
598
123040
427
# -*- coding: utf-8 -*- from sys import setrecursionlimit setrecursionlimit(100000) N = int(input()) C = [[] for _ in range(N)] for i in range(1, N): C[int(input())-1].append(i) def cal(x): if len(C[x]) == 0: return 0 else: D = sorted([cal(a) for a in C[x]], reverse=True) res = 0 for i, d in enumerate(D, start=1): res = max(res, i+d) return res print(cal(0))
s537362475
p03822
u777923818
1535598497
Python
Python (3.4.3)
py
Runtime Error
418
19024
367
# -*- coding: utf-8 -*- N = int(input()) C = [[] for _ in range(N)] for i in range(1, N): C[int(input())-1].append(i) def cal(x): if len(C[x]) == 0: return 0 else: D = sorted([cal(a) for a in C[x]], reverse=True) res = 0 for i, d in enumerate(D, start=1): res = max(res, i+d) return res print(cal(0))
s723203888
p03822
u761320129
1526996883
Python
Python (3.4.3)
py
Runtime Error
530
124100
360
import sys sys.setrecursionlimit(101010) N = int(input()) won = [[] for i in range(N)] for i in range(1,N): a = int(input()) - 1 won[a].append(i) def height(v): if not won[v]: return 0 hs = [height(op) for op in won[v]] ret = 0 for i,h in enumerate(sorted(hs)): ret = max(ret, h + len(hs) - i) return ret print(height(0))
s112765089
p03822
u858748695
1514534025
Python
Python (3.4.3)
py
Runtime Error
619
140712
427
#!/usr/bin/env python3 import sys sys.setrecursionlimit(int(10**5)) N = int(input()) a = [int(input()) - 1 for _ in range(N)[1:]] children = [[] * N for i in range(N)] for i in range(N)[:-1]: children[a[i]].append(i + 1) def dfs(n): if children[n] == []: return 0 dp = [dfs(child) for child in children[n]] dp.sort(reverse=True) return max(dp[i] + (i + 1) for i in range(len(dp))) print(dfs(0))
s379853044
p03822
u858748695
1514533902
Python
Python (3.4.3)
py
Runtime Error
414
23096
381
#!/usr/bin/env python3 N = int(input()) a = [int(input()) - 1 for _ in range(N)[1:]] children = [[] * N for i in range(N)] for i in range(N)[:-1]: children[a[i]].append(i + 1) def dfs(n): if children[n] == []: return 0 dp = [dfs(child) for child in children[n]] dp.sort(reverse=True) return max(dp[i] + (i + 1) for i in range(len(dp))) print(dfs(0))
s346408121
p03822
u763975133
1513470635
Python
Python (3.4.3)
py
Runtime Error
17
2940
2772
#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::stdin; mod util { use std::io::stdin; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } } #[allow(unused_macros)] macro_rules! get { ($t:ty) => { { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().parse::<$t>().unwrap() } }; ($($t:ty),*) => { { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( $(iter.next().unwrap().parse::<$t>().unwrap(),)* ) } }; ($t:ty; $n:expr) => { (0..$n).map(|_| get!($t) ).collect::<Vec<_>>() }; ($($t:ty),*; $n:expr) => { (0..$n).map(|_| get!($($t),*) ).collect::<Vec<_>>() }; ($t:ty ;;) => { { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse::<$t>().unwrap()) .collect::<Vec<_>>() } }; } #[allow(unused_macros)] macro_rules! debug { ($($a:expr),*) => { println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*); } } fn rec(v: usize, g: &Vec<Vec<usize>>, dp: &mut Vec<Option<usize>>) -> usize { if let Some(res) = dp[v] { return res; } let mut childs: Vec<usize> = g[v].iter().map(|&v2| rec(v2, g, dp)).collect(); childs.sort(); let res = childs .iter() .rev() .zip(1..g[v].len() + 1) .map(|(&c, m)| c + m) .max() .unwrap_or(0); dp[v] = Some(res); res } fn main() { let n = get!(usize); let aa = get!(usize; n-1); let mut g = vec![Vec::new(); n]; for (&w, l) in aa.iter().zip(1..) { let w = w - 1; g[w].push(l); } let ans = rec(0, &g, &mut vec![None; n]); println!("{}", ans); }
s477914944
p03822
u226155577
1493769014
Python
Python (2.7.6)
py
Runtime Error
317
26300
201
n = input() A = {} for i in xrange(2, n+1): v = int(raw_input()) A.setdefault(v, []).append(i) f = lambda v: (v in A)/1 and 1+max(e+i for i,e in enumerate(sorted(map(f,A[v]))[::-1])) print f(1)
s764952050
p03822
u890165321
1488774996
Python
PyPy3 (2.4.0)
py
Runtime Error
177
38640
148
N, K = map(int, input().split()) A = [int(n) for n in input().split()] A.sort() answer = 0 for k in range(K): answer += A[k] + k print(answer)
s515477286
p03822
u268210555
1485638304
Python
Python (3.4.3)
py
Runtime Error
510
27616
220
d = {} for i in range(2,int(input())+1): d.setdefault(int(input()),[]).append(i) def f(i): if i not in d: return 0 return max(i+v for i,v in enumerate(sorted(map(f,d[i]),reverse=True),1)) print(f(1))
s657558895
p03822
u332385682
1485150234
Python
Python (3.4.3)
py
Runtime Error
615
37784
419
import sys def calc_depth(n): if children[n] == set(): return 0 depth_l = [calc_depth(child) for child in children[n]] depth_l.sort(reverse=True) return max(depth + (i+1) for (i, depth) in enumerate(depth_l)) N = int(input()) children = [set() for i in range(N + 1)] for i in range(N - 1): a = int(input()) children[a].add(i + 2) ans = calc_depth(1) # print(children) print(ans)
s543004565
p03822
u272028993
1485145941
Python
PyPy2 (5.6.0)
py
Runtime Error
177
32028
588
import sys sys.setrecursionlimit(10**8) def dfs(now): visited[now]=1 l=max(0,len(g[now])-1) for nx in g[now]: if not visited[nx]: dep[now].append(dfs(nx)) if len(dep[now])==0: return 1 dep[now].sort() cost=0 for i in xrange(len(dep[now])): cost=max(cost,dep[now][i]+l-i) return cost+1 def main(): n=int(raw_input()) g=[[] for _ in xrange(n)] for i in xrange(n-1): a=int(raw_input()) g[a-1].append(i+1) visited=[0]*n dep=[[] for _ in xrange(n)] ans=dfs(0) print ans-1 main()
s384751255
p03822
u425351967
1485143194
Python
Python (3.4.3)
py
Runtime Error
539
20796
578
N=int(input()) depth=[-1]*N parent=[-1]*N childs=[[] for i in range(N)] depth[0]=0 def calc_depth(n): for child in childs[n]: depth[child]=depth[n]+1 calc_depth(child) def calc_height(n): if childs[n]==[]: return 0 childs_height=[] for child in childs[n]: childs_height.append(calc_height(child)) childs_height.sort(reverse=True) heightlist=[childs_height[i]+i for i in range(len(childs_height))] return max(heightlist)+1 for i in range (1,N): a=int(input())-1 childs[a].append(i) print(calc_height(0))
s319059622
p03822
u755962107
1485143126
Python
Python (3.4.3)
py
Runtime Error
934
55536
498
from operator import add from functools import lru_cache n = int(input()) data = list([int(input()) for i in range(n-1)]) tree = [set() for i in range(n)] @lru_cache(maxsize = None) def depth(x): k = len(tree[x]) if k: a = sorted([depth(z) for z in tree[x]], reverse = True) b = map(add, a, range(1,k+1)) return max(b) else: return 0 for i, v in enumerate(data): tree[v-1].add(i+1) for i in sorted(range(n), key = lambda x: len(tree[x])): depth(i) print(depth(0))
s348801004
p03822
u425351967
1485143078
Python
Python (3.4.3)
py
Runtime Error
24
3188
563
depth=[-1]*N parent=[-1]*N childs=[[] for i in range(N)] depth[0]=0 def calc_depth(n): for child in childs[n]: depth[child]=depth[n]+1 calc_depth(child) def calc_height(n): if childs[n]==[]: return 0 childs_height=[] for child in childs[n]: childs_height.append(calc_height(child)) childs_height.sort(reverse=True) heightlist=[childs_height[i]+i for i in range(len(childs_height))] return max(heightlist)+1 for i in range (1,N): a=int(input())-1 childs[a].append(i) print(calc_height(0))
s035888475
p03822
u755962107
1485142636
Python
Python (3.4.3)
py
Runtime Error
552
41768
382
from operator import add def depth(tree, x): k = len(tree[x]) if k: a = sorted([depth(tree,z) for z in tree[x]], reverse = True) b = map(add, a, range(1,k+1)) return max(b) else: return 0 n = int(input()) data = list([int(input()) for i in range(n-1)]) tree = [set() for i in range(n)] for i, v in enumerate(data): tree[v-1].add(i+1) print(depth(tree,0))
s093585305
p03822
u810735437
1485139798
Python
Python (3.4.3)
py
Runtime Error
676
28804
615
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import functools from collections import * N = int(input()) d = defaultdict(list) for n in range(N-1): loser = n + 2 winner = int(input()) d[winner].append(loser) @functools.lru_cache(maxsize = None) def dfs(n): # print("n:", n) if n not in d: return 0 else: size = len(d[n]) depth = [dfs(x) for x in d[n]] depth.sort() order = list(range(1, size + 1)) order.reverse() mx = 0 for a, b in zip(depth, order): mx = max(mx, a + b) return mx print(dfs(1))
s215889254
p03823
u102461423
1592632896
Python
Python (3.8.2)
py
Runtime Error
149
36096
1367
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 def main(N, A, B, S): if A > B: A, B = B, A if np.max(S[2:] - S[:-2]) < A: return 0 INF = 1 << 62 S = np.append(S, INF) # A 未満でたどって、Xがどこまで置けるか X = np.zeros_like(S) for i in range(1, N + 1): if S[i] - S[i - 1] >= A: X[i] = X[i - 1] else: X[i] = i # 直前の Y としてありうる最も右 Y = np.searchsorted(S, S - B, side='right') - 1 dp = np.zeros_like(S) dp_cum = np.zeros_like(S) dp[0] = 1 dp_cum[0] = 1 for n in range(1, N + 1): if X[n - 1] == 0: # 初出の Y dp[n] = 1 # 直前の Y の範囲 l, r = max(0, X[n - 1] - 1), min(n - 1, Y[n]) if l <= r: dp[n] += dp_cum[r] - dp_cum[l] + dp[l] dp[n] %= MOD dp_cum[n] = (dp_cum[n - 1] + dp[n]) % MOD return dp[-1] signature = '(i8,i8,i8,i8[:],)' if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC cc = CC('my_module') cc.export('main', signature)(main) cc.compile() from my_module import main N, A, B = map(int, readline().split()) S = np.array(read().split(), np.int64) print(main(N, A, B, S))
s448977539
p03823
u102461423
1567534108
Python
Python (3.4.3)
py
Runtime Error
334
23640
1210
import sys input = sys.stdin.readline from bisect import bisect_left, bisect_right INF = 10**18 + 100 N,A,B = map(int,input().split()) S = [-INF] + [int(x) for x in sys.stdin.read().split()] MOD = 10**9 + 7 dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか dpX[0] = 1 dpY[0] = 1 dpX_cum = [1] * (N+1) + [0] dpY_cum = [1] * (N+1) + [0] dpX_left = 0 dpY_left = 0 for n,x in enumerate(S[2:],2): iA = bisect_right(S,x-A) iB = bisect_right(S,x-B) # ....XY xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1] # ....YX yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1] # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ if iA != n: dpY_left = n-1 if iB != n: dpX_left = n-1 dpX[n-1] = xy dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD dpX_cum[n] = dpX_cum[n-1] dpY[n-1] = yx dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD dpY_cum[n] = dpY_cum[n-1] answer = dpX_cum[n] - dpX_cum[dpX_left-1] answer += dpY_cum[n] - dpY_cum[dpY_left-1] answer %= MOD print(answer) dpX
s481461361
p03823
u102461423
1567533718
Python
Python (3.4.3)
py
Runtime Error
314
14944
1191
import sys input = sys.stdin.readline from bisect import bisect_left, bisect_right INF = 10**18 + 100 N,A,B = map(int,input().split()) S = [-INF] + [int(x) for x in sys.stdin.read().split()] MOD = 10**9 + 7 dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか dpX[0] = 1 dpY[0] = 1 dpX_cum = [1] * (N+1) dpY_cum = [1] * (N+1) dpX_left = 0 dpY_left = 0 for n,x in enumerate(S[2:],2): iA = bisect_right(S,x-A) iB = bisect_right(S,x-B) # ....XY xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1] # ....YX yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1] # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ if iA != n: dpY_left = n-1 if iB != n: dpX_left = n-1 dpX[n-1] = xy dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD dpX_cum[n] = dpX_cum[n-1] dpY[n-1] = yx dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD dpY_cum[n] = dpY_cum[n-1] answer = dpX_cum[n] - dpX_cum[dpX_left-1] answer += dpY_cum[n] - dpY_cum[dpY_left-1] answer %= MOD print(answer)
s418969981
p03823
u102461423
1567533536
Python
Python (3.4.3)
py
Runtime Error
336
23624
1252
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) from bisect import bisect_left, bisect_right INF = 10**18 + 100 N,A,B = map(int,input().split()) S = [-INF] + [int(x) for x in sys.stdin.read().split()] MOD = 10**9 + 7 dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか dpX[0] = 1 dpY[0] = 1 dpX_cum = [0] * (N+1) dpY_cum = [0] * (N+1) dpX_cum[0] = 1 dpY_cum[0] = 1 dpX_left = 0 dpY_left = 0 for n,x in enumerate(S[2:],2): iA = bisect_right(S,x-A) iB = bisect_right(S,x-B) # ....XY xy = dpY_cum[iB-1] - dpY_cum[dpY_left-1] # ....YX yx = dpX_cum[iA-1] - dpX_cum[dpX_left-1] # ....XX が不可能なら捨てる。明示的に捨てるのではなく、生きている番号だけ持つ if iA != n: dpY_left = n-1 if iB != n: dpX_left = n-1 dpX[n-1] = xy dpX_cum[n-1] = (dpX_cum[n-2] + xy) % MOD dpX_cum[n] = dpX_cum[n-1] dpY[n-1] = yx dpY_cum[n-1] = (dpY_cum[n-2] + yx) % MOD dpY_cum[n] = dpY_cum[n-1] answer = dpX_cum[n] - dpX_cum[dpX_left-1] answer += dpY_cum[n] - dpY_cum[dpY_left-1] answer %= MOD print(answer)
s766618625
p03826
u708211626
1600280185
Python
Python (3.8.2)
py
Runtime Error
25
9032
165
a,b=[input() for i in range(2)] p=0 ans=0 for i in b: if i =='I': p+=1 elif i =='D' and p>0: p-=1 else: p-=1 if ans<p: ans=p print(ans)
s036053187
p03826
u960570220
1599952277
Python
Python (3.8.2)
py
Runtime Error
25
9104
116
S1 = int(input()) S2 = int(input()) if S1 > S2: print(S1) elif S1 == S2: print(S1 * S2) else: print(S2)
s613862477
p03826
u847033024
1599894503
Python
Python (3.8.2)
py
Runtime Error
28
8996
121
a, b, c, d = int(input().split()) x = a * b y = c * d if x == y: print(x) elif x > y: print(x) elif y > x: print(y)
s770901720
p03826
u894623942
1599860947
Python
Python (3.8.2)
py
Runtime Error
25
8896
304
def main(): with open('../param.txt') as f: line_list = f.read().split() A = int(line_list[0])*int(line_list[1]) B = int(line_list[2])*int(line_list[3]) if A > B: print(A) elif A < B: print(B) else: print(A) if __name__ == '__main__': main()
s239849151
p03826
u011872685
1599332125
Python
Python (3.8.2)
py
Runtime Error
25
9040
111
#52 A=int(input()) B=int(input()) C=int(input()) D=int(input()) if A*B>c*D: print(A*B) else: print(C*D)
s397929400
p03826
u681502232
1599276699
Python
Python (3.8.2)
py
Runtime Error
26
9092
308
# 052 # 1.値を正しく取得 A = int(input()) B = int(input()) C = int(input()) D = int(input()) # 2.正しく処理 menseki1 = A * B print(menseki1) menseki2 = C * D print(menseki2) if menseki1 > menseki2: print(menseki1) elif menseki1 < menseki2: print(menseki2) else : print(menseki1)
s445384030
p03826
u681502232
1599276559
Python
Python (3.8.2)
py
Runtime Error
25
9160
316
# 052 # 1.値を正しく取得 x1 = int(input()) y1 = int(input()) x2 = int(input()) y2 = int(input()) # 2.正しく処理 menseki1 = x1 * y1 print(menseki1) menseki2 = x2 * y2 print(menseki2) if menseki1 > menseki2: print(menseki1) elif menseki1 < menseki2: print(menseki2) else : print(menseki1)
s988505532
p03826
u681502232
1599276151
Python
Python (3.8.2)
py
Runtime Error
25
9092
226
#052 #1.値を正しく取得 x1=int(input()) y1=int(input()) x2=int(input()) y2=int(input()) #2.正しく処理 menseki1 = x1 * y1 menseki2 = x2 * y2 if menseki1 >=menseki2 : print(menseki1) else : print(menseki2)
s189711413
p03826
u265118937
1597941720
Python
Python (3.8.2)
py
Runtime Error
26
8820
60
a, ,b, c, d = map(int, input().split()) print(max(a*b, c*d))
s084307546
p03826
u274615057
1596951451
Python
Python (3.8.2)
py
Runtime Error
27
9164
155
def main(): a, b, c, d = map(int, input()) if a*b >= c*d: print(a*b) else: print(c*d) if __name__ == "__main__": main()
s818556829
p03826
u629607744
1596427156
Python
Python (3.8.2)
py
Runtime Error
23
9132
58
a,b,c,b = map(int,input().split()) print( max(a*b, c*d) )
s256689203
p03826
u629607744
1596427142
Python
Python (3.8.2)
py
Runtime Error
25
8800
55
a,b,c,b = map(int,input().split()) print( max(a*b, c*d)
s835290769
p03826
u736479342
1594924038
Python
Python (3.8.2)
py
Runtime Error
21
8900
84
a = map(int, input().split()) b = a[0]*a[1] c = a[2]*a[3] A = [b, c] print(max(A))
s730796998
p03826
u417096287
1592842621
Python
PyPy3 (7.3.0)
py
Runtime Error
100
68700
43
A, B, C, D = MI() print(max(A * B, C * D))
s425241313
p03826
u607920888
1590111007
Python
Python (3.4.3)
py
Runtime Error
17
2940
144
a,b,x=input().split() a=int() b=int() x=a*b c,d,y=input().split() c=int() d=int() y=b*c if x>y: print(x) elif:y>x print(y) elif:x=y print(x)
s613330668
p03826
u607920888
1590110923
Python
Python (3.4.3)
py
Runtime Error
17
2940
145
a,b,x=input().split() a=int() b=int() x=a*b c,d,y=input().split() c=int() d=int() y=b*c if x>y: print(x) elif: y>x print(y) elif:x=y print(x)
s415242644
p03826
u607920888
1590110858
Python
Python (3.4.3)
py
Runtime Error
17
3060
145
a,b,x=input().split() a=int() b=int() x=a*b b,c,y=input().split() b=int() c=int() y=b*c if x>y: print(x) elif: y>x print(y) elif:x=y print(x)
s145555844
p03826
u607920888
1590110738
Python
Python (3.4.3)
py
Runtime Error
17
2940
138
a,b=input().split() a=int() b=int() x=a*b b,c=input().split() b=int() c=int() y=b*c if x>y: print(x) elif: y>x print(y) else: print(x)
s102260188
p03826
u607920888
1590110628
Python
Python (3.4.3)
py
Runtime Error
17
2940
143
a,b=input().split() a=int() b=int() x=a*b b,c=input().split() b=int() c=int() y=b*c if x>y: print(x) elif: y>x print(y) elif:x=y print(x)
s896531535
p03826
u426764965
1589936082
Python
Python (3.4.3)
py
Runtime Error
17
2940
86
a,b,c,d = map(int, input().split()) s = a*b t = c*d if s > t = print(s) else: print(t)
s567819101
p03826
u863397945
1589195468
Python
Python (3.4.3)
py
Runtime Error
17
3064
80
S1 = int(A)*int(B) s2 = int(C)*int(D) if s1 < s2: print(s2) else: print(s1)
s175678724
p03826
u629350026
1589138503
Python
Python (3.4.3)
py
Runtime Error
17
2940
54
a,b,c,d=map(int,input().split()) print(max(a*b),(c*d))
s069764358
p03826
u379142263
1588912425
Python
Python (3.4.3)
py
Runtime Error
21
3420
219
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections MOD = 10**9 + 7 a,b,c.d = map(int,input().split()) print(max(a*b,c*d))
s874408642
p03826
u973108807
1588643344
Python
Python (3.4.3)
py
Runtime Error
17
2940
55
a,b,c,d = map(int, input().split()) print(max(a*b, c*d)
s923272862
p03826
u578323547
1588298669
Python
Python (3.4.3)
py
Runtime Error
17
2940
152
n,a,b = map(int, input().split()) x = [int(x) for x in input().split(' ')] mp = 0 for i in range(n-1): mp += min(a*(x[i+1]-x[i]), b) print(mp)
s996925796
p03826
u289162337
1588221409
Python
Python (3.4.3)
py
Runtime Error
17
2940
59
a, b, c, d = map(int, input(),split()) print(max(a*b, c*d))
s448514858
p03826
u896741788
1587614043
Python
Python (3.4.3)
py
Runtime Error
18
2940
52
print("A{}C".format("B"if int(input())<1200else"R"))
s183883631
p03826
u383450070
1587467672
Python
Python (3.4.3)
py
Runtime Error
17
3064
53
a,b,c,d=,ap(int,input().split()) print(max(a*b, c*d))
s165805304
p03826
u535659144
1586967797
Python
Python (3.4.3)
py
Runtime Error
18
2940
66
x=list(map(int(),input().split())) print(max(x[0]*x[1],x[2]*x[3]))
s201978793
p03826
u516447519
1586479355
Python
Python (3.4.3)
py
Runtime Error
18
2940
173
N = int(input()) S = str(input()) max = 0 x = 0 for i in range(N): if S[i] == 'I': x += 1 else: x -= 1 if x > max: max = x print(max)
s538681396
p03826
u516447519
1586479046
Python
Python (3.4.3)
py
Runtime Error
17
2940
166
A,B,C,D = [int(i) for i in input().split()] S1 = int(A*B) S2 = int(C*D) if S1 >= S2: print(S1) else: return 0 if S2 >= S1: print(S2) else: return 0
s327807608
p03826
u852790844
1586398006
Python
Python (3.4.3)
py
Runtime Error
17
3060
203
import itertools n = int(input()) s = list(input()) s1 = [1 if s[i] == 'I' else -1 for i in range(n)] cumsum = list(itertools.accumulate(s1)) print(s1) print(cumsum) ans = max(cumsum) print(max(ans, 0))
s905722585
p03826
u790048565
1585506561
Python
Python (3.4.3)
py
Runtime Error
17
2940
131
A, B, C, D = map(int, input().split()) areaA = A*B areaB = C*D result = areaA if (areaA > areaB) else areaB print(result)
s424415938
p03826
u440129511
1585241971
Python
Python (3.4.3)
py
Runtime Error
17
3060
99
A,B,C,D=list(map(int,input())) ab=A*B cd=C*D if ab>cd:print(ab) elif cd>ab:print(cd) else:print(ab)
s098464992
p03826
u577170763
1585240241
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38256
59
, b, c, d = map(int, input().split()) print(max(a*b, c*d))
s992731148
p03826
u066455063
1584488262
Python
Python (3.4.3)
py
Runtime Error
18
2940
55
if A * B > C * D: print(A*B) else: print(C*D)
s692233784
p03826
u867320886
1584390347
Python
Python (3.4.3)
py
Runtime Error
18
2940
127
#include <iostream> using namespace std; int main(void){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<max(a*b,c*d)<<endl; }
s849439576
p03826
u955251526
1584259756
Python
Python (3.4.3)
py
Runtime Error
17
2940
89
a = int(input()) b = int(input()) c = int(input()) d = int(input()) print(max(a*b, c*d))
s530597632
p03826
u841623074
1584057258
Python
Python (3.4.3)
py
Runtime Error
17
3064
361
n=int(input()) array=[] for i in range(2,n+1): s=i while s!=1: turn=0 for j in range(2,s+1): if s%j==0: s=s//j array.append(j) break ans=1 import collections c=collections.Counter(array) l=list(c.values()) print(l) for i in range(len(l)): ans*=l[i]+1 print(ans%(10**9+7))
s141260935
p03826
u923270446
1583107174
Python
Python (3.4.3)
py
Runtime Error
17
2940
149
input1 = list(map(int,input().split())) A = input1[0] B = input1[1] C = input1[2] D = input1[3] if A * B >= C * D print(A * B) else: print(C * D)
s987700100
p03826
u634248565
1582738408
Python
Python (3.4.3)
py
Runtime Error
17
2940
53
N = int(input()) x = 800*N - ((N//15)*200) print (x)
s813596475
p03826
u634248565
1582735384
Python
Python (3.4.3)
py
Runtime Error
17
3060
133
A = int(input()) B = int(input()) C = int(input()) D = int(input()) ab = A*B cd = C*D if ab >= cd: print (ab) else: print (cd)
s084087097
p03826
u634248565
1582691834
Python
Python (3.4.3)
py
Runtime Error
17
2940
118
A = int(input()) B = int(input()) C = int(input()) D = int(input()) if A*B >= C*D: print (A*B) else: print (C*D)
s312139223
p03826
u634248565
1582691680
Python
Python (3.4.3)
py
Runtime Error
17
2940
115
A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()] if A*B >= C*D: print (A*B) else: print (C*D)
s938529175
p03826
u634248565
1582691651
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38384
114
A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()] if A*B >= C*D: print (A*B) else: print (C*D)
s038964090
p03826
u634248565
1582691435
Python
PyPy3 (2.4.0)
py
Runtime Error
165
38384
164
A = int(input()) B = int(input()) C = int(input()) D = int(input()) areaAB = (A*B) areaCD = (C*D) if areaAB >= areaCD: print (areaAB) else: print (areaCD)
s448241451
p03826
u634248565
1582691264
Python
PyPy3 (2.4.0)
py
Runtime Error
177
39152
216
A = int(input()) B = int(input()) C = int(input()) D = int(input()) areaAB = (A*B) areaCD = (C*D) if areaAB == areaCD: print (areaAB) if areaAB > areaCD: print (areaAB) if areaCD > areaAB: print (areaCD)
s867345986
p03826
u634248565
1582691240
Python
Python (2.7.6)
py
Runtime Error
10
2568
216
A = int(input()) B = int(input()) C = int(input()) D = int(input()) areaAB = (A*B) areaCD = (C*D) if areaAB == areaCD: print (areaAB) if areaAB > areaCD: print (areaAB) if areaCD > areaAB: print (areaCD)
s851002787
p03826
u634248565
1582691156
Python
Python (3.4.3)
py
Runtime Error
17
2940
216
A = int(input()) B = int(input()) C = int(input()) D = int(input()) areaAB = (A*B) areaCD = (C*D) if areaAB == areaCD: print (areaAB) if areaAB > areaCD: print (areaAB) if areaCD > areaAB: print (areaCD)
s444971311
p03826
u634248565
1582691100
Python
Python (3.4.3)
py
Runtime Error
17
3060
211
A = int(input()) B = int(input()) C = int(input()) D = int(input()) areaAB = A*B areaCD = C*D if areaAB == areaCD: print (areaAB) if areaAB > areaCD: print (areaAB) if areaCD > areaAB: print (areaCD)
s429267204
p03826
u073549161
1582079753
Python
PyPy3 (2.4.0)
py
Runtime Error
168
38384
726
mod = 1000000000 + 7 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 n = int(input()) dat = [0] * 2000 # 約数として求められたある数の合計 # N! の各要素の素因数分解をする res = 1 for i in range(1, n + 1): d = factorization(i) for j in range(len(d)): dat[d[j][0]] += d[j][1] for i in range(2, n + 1): res *= (dat[i] + 1) res %= mod print(res)
s017999127
p03826
u467831546
1581549677
Python
Python (3.4.3)
py
Runtime Error
17
2940
147
A = input() B = input() C = input() D = input() volume1 = A * B volume2 = C * D if volume1 > volume2: print(volume1) else: print(volume2)
s453350463
p03826
u187058053
1581513001
Python
Python (3.4.3)
py
Runtime Error
17
3060
147
n = int(input()) s = input() x=0 ans=0 for i in range(n): if s[i]=="I": x += 1 else: x -= 1 ans = max(ans,x) print(ans)
s665463163
p03826
u187058053
1581512890
Python
Python (3.4.3)
py
Runtime Error
17
3060
147
n = int(input()) s = input() x=0 max=0 for i in range(n): if s[i]=="I": x += 1 else: x -= 1 max = max(max,x) print(max)
s627956481
p03826
u279493135
1580593423
Python
Python (3.4.3)
py
Runtime Error
26
3888
583
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 print(max(A*B, C*D))
s726073427
p03826
u686036872
1578989118
Python
Python (3.4.3)
py
Runtime Error
17
2940
55
A, B, C, D=map(int, input().split()) print(max(AB, CD))