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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s099143645 | p03808 | u828766688 | 1579295668 | Python | PyPy3 (2.4.0) | py | Runtime Error | 218 | 62832 | 528 | import sys
N = int(input())
A = list(map(int,input().split()))
M = N*(N+1)//2
if sum(A) % M != 0:
print ("NO")
sys.exit()
able = sum(A) // M
print (M,able)
A.append(A[0])
now = 0
for i in range(N):
if A[i+1] - A[i] == able:
continue
else:
#print (A[i+1],A[i],able,1-N)
if ((A[i+1]-A[i])-able) % (1-N) != 0:
print ("NO")
sys.exit()
else:
now += ((A[i+1]-A[i])-able) // (1-N)
if now <= able:
print ("YES")
else:
print ("NO")
|
s619316620 | p03808 | u670180528 | 1575103079 | Python | Python (3.4.3) | py | Runtime Error | 76 | 14956 | 238 | n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if (n==2 and sum(a)%3) or any(x%n for x in dd) or sum(x//n for x in dd)!=M or sum(a)//M!=n*(n+1)//2:
print("NO")
else:
print("YES") |
s266306578 | p03808 | u670180528 | 1575102398 | Python | Python (3.4.3) | py | Runtime Error | 78 | 14956 | 230 | n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if n==1 or (all(x%n==0 for x in dd) and sum(x//n for x in dd)==M and sum(a)//M==n*(n+1)//2):
print("YES")
else:
print("NO") |
s805822997 | p03808 | u670180528 | 1575102250 | Python | Python (3.4.3) | py | Runtime Error | 78 | 14956 | 220 | n,*a=map(int,open(0).read().split())
d=[j-i for i,j in zip(a,a[1:]+[a[0]])]
M=max(d)
dd=[M-x for x in d]
if all(x%n==0 for x in dd) and sum(x//n for x in dd)==M and sum(a)//M==n*(n+1)//2:
print("YES")
else:
print("NO") |
s448778260 | p03808 | u039623862 | 1569626473 | Python | Python (3.4.3) | py | Runtime Error | 28 | 11104 | 257 | n = int(input())
a = list(map, input().split())
suma = sum(a)
if sum(a) % (n*(n+1)//2) > 0:
print('NO')
exit()
k = 2*suma//(n*(n+1))
diffs = [a[i+1] - a[i] + k for i in range(n-1)]
if all([d % n == 0 for d in diffs]):
print('YES')
else:
print('NO')
|
s912504755 | p03808 | u201234972 | 1567043095 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 850 | #import sys
#input = sys.stdin.readline
from itertools import accumulate
def main():
N = int( input())
A = list( map( int, input().split()))
C = [0]*(N*2+2)
L = [0]*(N*2+2)
cnt = 0
if sum(A)%(N*(N+1)//2) != 0:
print("NO")
return
t = sum(A)//(N*(N+1)//2)
for i in range(N):
if (A[i] - A[i-1] + (N-1)*t)%N != 0:
print("NO")
return
k = (A[i] - A[i-1] + (N-1)*t)//N
C[i] += t-k
C[i+N] -= t-k
cnt += t-k
L[i+N] -= (t-k)*N
S = list( accumulate(C))
if cnt > t:
print("NO")
break
for i in range(N*2+1):
S[i+1] += S[i] + L[i+1]
for i in range(N):
if A[i] != S[i] + S[i+N]:
print("NO")
return
print("YES")
if __name__ == '__main__':
main()
|
s202276608 | p03808 | u729133443 | 1566050106 | Python | Python (3.4.3) | py | Runtime Error | 111 | 14068 | 177 | n,*a=map(int,open(0).read().split())
b,m=sum(a),n*-~n//2
n-=1
c=b//m
f=b%m>0
for i,j in zip(*[iter([a[-1]]+a*2)]*2):
j-=i
t=min(0,j//n)
f|=c!=j+n*-t-t
print('YNEOS'[f::2]) |
s490731799 | p03808 | u163320134 | 1562950588 | Python | Python (3.4.3) | py | Runtime Error | 45 | 14228 | 320 | def gcd(a,b):
if b==0:
return a
else:
return(b,a%b)
n=int(input())
arr=list(map(int,input().split()))
sum1=sum(arr)
sum2=(n*(n+1))//2
cnt=sum1//sum2
if sum1%sum2!=0:
print('NO')
else:
s=set()
l=n//(gcd(n,cnt))
for val in arr:
s.add(val%n)
if len(s)==l:
print('YES')
else:
print('NO') |
s354485281 | p03808 | u623819879 | 1559605776 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38640 | 472 | #n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=False
c=[]
t=sum(a)//((n*(n+1))//2)
if sum(a)%((n*(n+1))//2)!=0:
ans=False
else:
for i in range(n):
if i==0:
d=a[0]-a[-1]
else:
d=a[i]-a[i-1]
if (t-d)%n!=0:
ans=False
break
s=(t-d)//n
c.append(s)
if sum(c)==t:
#ans=True
if n==1:
ans=True
print('YES' if ans else 'NO') |
s675583999 | p03808 | u623819879 | 1559605609 | Python | PyPy3 (2.4.0) | py | Runtime Error | 176 | 38356 | 493 | #n,a,b,c,d=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
ans=False
c=[]
t=sum(a)//((n*(n+1))//2)
if sum(a)%((n*(n+1))//2)!=0:
ans=False
else:
if n==1:
ans=True
break
for i in range(n):
if i==0:
d=a[0]-a[-1]
else:
d=a[i]-a[i-1]
if (t-d)%n!=0:
ans=False
break
s=(t-d)//n
c.append(s)
if sum(c)==t:
ans=True
print('YES' if ans else 'NO') |
s565744081 | p03808 | u310678820 | 1559434758 | Python | PyPy3 (2.4.0) | py | Runtime Error | 264 | 68080 | 277 |
import math
n=int(input())
a=list(map(int, input().split()))
tmp=0
for i in range(n-1):
if a[i]>(a[i+1]+tmp*n):
tmp=math.ceil((a[i]-a[i+1])/n)
a[i+1]+=tmp*n
tmp = a[1]-a[0]
if all(a[i+1]-a[i]==tmp for i in range(1, n-1)):
print('YES')
else:
print('NO') |
s107436329 | p03808 | u923279197 | 1553737776 | Python | PyPy3 (2.4.0) | py | Runtime Error | 229 | 62832 | 529 | n = int(input())
a = list(map(int,input().split()))
global count
count = 0
def solve(a):
count += 1
if count > 10**7:
print('NO')
exit()
if min(a) < 0:
return False
for i in range(n):
if a[i] != 0:
break
if i == n-1:
return True
for i in range(n):
b = []
for j in range(n):
c = a[(i+j)%n]-j-1
b.append(c)
if solve(b):
return True
if solve(a):
print('YES')
else:
print('NO') |
s612836191 | p03808 | u923279197 | 1553737513 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2118 | 236752 | 439 | n = int(input())
a = list(map(int,input().split()))
def solve(a):
if min(a) < 0:
return False
for i in range(n):
if a[i] != 0:
break
if i == n-1:
return True
for i in range(n):
b = []
for j in range(n):
c = a[(i+j)%n]-j-1
b.append(c)
if solve(b):
return True
if solve(a):
print('YES')
else:
print('NO') |
s801949388 | p03808 | u923279197 | 1553737460 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2113 | 256184 | 461 | n = int(input())
a = list(map(int,input().split()))
def solve(a):
print(a)
for i in range(n):
if a[i] != 0:
break
if i == n-1:
return True
for i in range(n):
b = []
for j in range(n):
if a[j] < 0:
return False
c = a[(i+j)%n]-j-1
b.append(c)
if solve(b):
return True
if solve(a):
print('YES')
else:
print('NO') |
s170268636 | p03808 | u785578220 | 1552600298 | Python | Python (3.4.3) | py | Runtime Error | 78 | 14476 | 243 | N = int(input())
A = list(map(int, input().split()))
K = sum(A) / sum(range(1, N+1))
for i in range(-1,N-1):
D = A[i+1] - A[i] - K
for d in D:
if not (d <= 0 and d % N == 0):
print("NO")
break
else:
print("YES")
|
s442471091 | p03808 | u299869545 | 1546416542 | Python | Python (2.7.6) | py | Runtime Error | 12 | 2568 | 875 | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
Int sum;
Int sumone, n, cnt;
Int a[216000];
void ok(){
cout << "YES" << endl;
exit(0);
}
void ng(){
cout << "NO" << endl;
exit(0);
}
int main(){
cin >> n;
for(int i = 0;i < n;i++)cin >> a[i], sum += a[i];
sumone = n * (n+1) / 2;
if(sum % sumone)ng();
sumone /= sum;
for(int i = 0;i < n;i++){
int b = (i + n - 1) % n;
int diff = a[b] - a[i];
diff += sumone;
if(diff < 0 || diff % n)ng();
cnt += diff / (n-2);
}
if(sumone != cnt)ng();
ok();
return 0;
} |
s052986304 | p03808 | u236127431 | 1543865811 | Python | PyPy3 (2.4.0) | py | Runtime Error | 236 | 63472 | 213 | N=int(input())
a=[int(i) for i in input().split()]
k=sum(a)//(N*(N-1)//2)
D=[]
a.append(a[0])
for i in range(N):
D.append(a[i+1]-a[i]-k)
for d in D:
if d%N!=0:
print("NO")
exit()
print("YES")
|
s912145302 | p03808 | u667024514 | 1539099313 | Python | Python (3.4.3) | py | Runtime Error | 44 | 14104 | 303 | n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
print("NO")
exit()
ans=0
for k in range(n):
if -(lis[i]-lis[i-1]-sum(lis)//num)%n!=0:
print("NO")
exit()
ans+=-(lis[i]-lis[i-1]-sum(lis)//num)//n
if ans == sum(lis)//num:print("YES")
else:print("NO")
|
s344360697 | p03808 | u667024514 | 1539098360 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 301 | n=int(input())
lis=list(map(int,input.split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
print("No")
exit()
li=[lis[i]-lis[i-1]-sum(lis)//num for i in range(n)]
ans=0
for k in range(n):
if -li[k]%n!=0:
print("No")
exit()
ans+=-li[k]//n
if ans == sum(lis)//num:print("Yes")
else:print("No") |
s051630209 | p03808 | u690536347 | 1536633653 | Python | Python (3.4.3) | py | Runtime Error | 84 | 14292 | 249 | n=int(input())
*l,=map(int,input().split())
m=[0]*n
a=n*(n+1)//2
b=sum(l)
if b%a:
print("NO")
else:
k=b//a
for i in range(n):
m[i]=(l[(i+1)%n]-l[i]-k)
*o,=filter(lambda x:x<0 and x%n==0,m)
if len(o)==k:
print("YES")
else:
print("NO") |
s373275879 | p03808 | u218843509 | 1536447511 | Python | Python (3.4.3) | py | Runtime Error | 97 | 14484 | 375 | n = int(input())
a = list(map(int, input().split()))
if sum(a) % (n * (n + 1) // 2) != 0:
print("NO")
else:
k = sum(a) // (n * (n + 1) // 2)
ok = True
for i in range(n - 1):
if (a[i] + k) % n != a[i + 1] % n or a[i] + k < a[i + 1]:
ok = False
break
if (a[-1] + k) % n != a[0] % n or a[-1] + k < a[i + 1]:
ok = False
if ok:
print("YES")
else:
print("NO") |
s773329139 | p03808 | u870262604 | 1515955985 | Python | Python (3.4.3) | py | Runtime Error | 87 | 14996 | 674 |
def solve():
n = int(input())
a = list(map(int, input().split()))
one = n*(n+1)/2
if sum(a) % one != 0:
print("NO")
else:
nop = sum(a) / one
d = [0 for i in range(n)]
for i in range(n):
d[i] = a[(i+1)%n] - a[i]
d[i] = d[i] - nop
count = 0
for i in range(n):
if d[i] != 0:
if d[i] % n != 0:
print("NO")
return
count = count + (-1*d[i]) / n
d[i] = 0
if count > nop:
print("NO")
return
if sum(d) == 0 and count == nop:
print("YES")
else:
print("NO")
solve() |
s818538729 | p03808 | u761320129 | 1515800236 | Python | Python (3.4.3) | py | Runtime Error | 41 | 11104 | 272 | N = int(input())
src = map(int,input().split())
S = sum(src)
M = N*(N+1)//2
if S%M:
print('NO')
exit()
K = S//M
mem = [src[i] - K*i for i in range(N)]
mem.append(mem[0])
for a,b in zip(mem,mem[1:]):
if (a-b)%N:
print('NO')
exit()
print('YES') |
s983075499 | p03808 | u667084803 | 1498111722 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 470 | import sys
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
total+=A[i]
if total*2/((N+1)*N)%1!=0:
print("NO")
sys.exit()
times=int(total*2/((N+1)*N))
if (times-A[0]+A[N-1])/N%1! or times-A[0]+A[N-1]<0=0:
print("NO")
sys.exit()
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
B+=(times-A[i+1]+A[i])/N
if (times-A[i+1]+A[i])/N%1!=0 or times-A[i+1]+A[i]<0:
print("NO")
sys.exit()
if B==times:
print("YES")
else:
print("NO") |
s818830740 | p03808 | u026450699 | 1491406889 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2820 | 504 | def getMaxIndex(list):
maxVal = 0
maxIdx = 0
for i in range(0, len(list)):
if(maxVal < list[i]):
maxIdx = i
maxVal = list[i]
return maxIdx
def check(list):
for i in range(0, N):
index = getMaxIndex(A)
for j in range(0, N):
A[(index + j + 1) % N] -= (j + 1)
if(min(A) <= 0):
for j in range(0, N):
if(A[j] != 0):
return False
return True
print check(A)
|
s807097087 | p03808 | u369752439 | 1486270606 | Python | Python (2.7.6) | py | Runtime Error | 75 | 11344 | 828 | N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
tmpFlag = True
if(sum(inList)%key != 0):
flag = False
if(max(inList) > min(inList)*N):
flag = False
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
#while(max(tmpList) > 0 and flag):
# if(min(tmpList) < 0):
# break
# minId = tmpList.index(min(tmpList))
# tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
#if(max(tmpList)==0 and min(tmpList)==0):
# ans = "YES"
# tmpFlag = False
while(max(inList) > 0 and flag and tmpFlag):
if(min(inList) < 0):
break
minId = inList.index(min(inList))
inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0 and min(inList)==0):
ans = "YES"
print ans |
s753592245 | p03808 | u369752439 | 1486270368 | Python | Python (2.7.6) | py | Runtime Error | 78 | 11360 | 820 | N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
tmpFlag = True
if(sum(inList)%key != 0):
flag = False
if(max(inList) > min(inList)*N):
flag = False
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
while(max(tmpList) > 0 and flag):
if(min(tmpList) < 0):
break
minId = tmpList.index(min(tmpList))
tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
ans = "YES"
tmpFlag = False
while(max(inList) > 0 and flag and tmpFlag):
if(min(inList) < 0):
break
minId = inList.index(min(inList))
inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0 and min(inList)==0):
ans = "YES"
print ans |
s776571697 | p03808 | u369752439 | 1486270221 | Python | Python (2.7.6) | py | Runtime Error | 77 | 11344 | 820 | N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
tmpFlag = True
if(sum(inList)%key != 0):
flag = False
if(max(inList) > min(inList)*N):
flag = False
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
while(max(tmpList) > 0 and flag):
if(min(tmpList) < 0):
break
minId = tmpList.index(min(tmpList))
tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
ans = "YES"
tmpFlag = False
while(max(inList) > 0 and flag and tmpFlag):
if(min(inList) < 0):
break
minId = inList.index(min(inList))
inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0 and min(inList)==0):
ans = "YES"
print ans |
s001672911 | p03808 | u369752439 | 1486270141 | Python | Python (2.7.6) | py | Runtime Error | 74 | 11364 | 852 | N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
tmpFlag = True
if(sum(inList)%key != 0):
flag = False
if(max(inList) > min(inList)*N):
flag = False
minKey = min(inList) / key
print key, minKey
tmpList = [inList[(minId + i)%N] - minKey * key for i in range(N)]
print tmpList
while(max(tmpList) > 0 and flag):
if(min(tmpList) < 0):
break
minId = tmpList.index(min(tmpList))
tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
ans = "YES"
tmpFlag = False
while(max(inList) > 0 and flag and tmpFlag):
if(min(inList) < 0):
break
minId = inList.index(min(inList))
inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0 and min(inList)==0):
ans = "YES"
print ans |
s094494860 | p03808 | u369752439 | 1486269988 | Python | Python (2.7.6) | py | Runtime Error | 75 | 11344 | 827 | N = int(raw_input())
inList = map(int, raw_input().split())
ans = "NO"
key = sum(range(1,N+1))
flag = True
tmpFlag = True
if(sum(inList)%key != 0):
flag = False
if(max(inList) > min(inList)*N):
flag = False
minKey = min(inList) / key
tmpList = [inList[(minId + i)%N] - i - 1 - minKey * key for i in range(N)]
while(max(tmpList) > 0 and flag):
if(min(tmpList) < 0):
break
minId = tmpList.index(min(inList))
tmpList = [tmpList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(tmpList)==0 and min(tmpList)==0):
ans = "YES"
tmpFlag = False
while(max(inList) > 0 and flag and tmpFlag):
if(min(inList) < 0):
break
minId = inList.index(min(inList))
inList = [inList[(minId + i)%N] - i - 1 for i in range(N)]
if(max(inList)==0 and min(inList)==0):
ans = "YES"
print ans |
s996337960 | p03808 | u973712798 | 1486266641 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 1268 |
n = int(input())
a = [int(i) for i in input().split()]
def get_inv_diff(a):
prev_val = a[-1]
idx_lst = []
for idx, cur_val in enumerate(a):
# print("cur,pre",cur_val,prev_val)
if cur_val <= prev_val:
idx_lst.append(idx)
if idx != 0 and prev_val - cur_val > 3:
for prev_val - cur_val / 4:
idx_lst.append(idx)
# print("detect!")
prev_val = cur_val
return idx_lst
def check_sum(a):
sum = 0
for val in a:
sum += val
cmp = [i+1 for i in range(n)]
cmp_sum = 0
for val in cmp:
cmp_sum += val
if sum % cmp_sum != 0:
return -1
else:
result = sum / cmp_sum
return result
result = check_sum(a)
if result == -1:
print("NO")
else:
indices = get_inv_diff(a)
if len(indices) != result:
print("NO")
else:
# print("indices:", indices)
test_lst = [0 for i in range(n)]
for begin_idx in indices:
for count in range(n):
# print("count:",count)
test_lst[(begin_idx + count) % n] += count+1
# print(test_lst)
if test_lst == a:
print("YES")
else:
print("NO")
|
s220044977 | p03808 | u272028993 | 1486266425 | Python | Python (2.7.6) | py | Runtime Error | 117 | 11344 | 426 | n=int(raw_input())
a=map(int,raw_input().split())
sn=n*(n+1)/2
if sum(a)%sn!=0:
print("NO")
exit()
c=sum(a)/sn
sa=sorted(a)
if sa[0]<c or sa[n-1]>n*c:
print("NO")
exit()
for i in xrange(n):
if a[i]-a[(i+1)%n]<0:
if abs(a[i]-a[i+1])>c:
print("NO")
exit()
elif a[i]-a[(i+1)%n]>0:
if abs(a[i]-a[i+1])>c*(n-1):
print("NO")
exit()
print("YES") |
s269305127 | p03808 | u369752439 | 1486266333 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2696 | 386 | import sys
N = int(next(sys.stdin))
inList = map(int, next.stdin.split())
def checkList(inList, N):
maxId = inList.index(max(inList))
for i in range(N):
inList[(maxId-i)%N] -= N - i
print inList
if(max(inList) == 0 and min(inList) == 0):
return "Yes"
if(min(inList) < 0):
return "No"
return checkList(inList, N)
print checkList(inList, N) |
s902844880 | p03808 | u012693733 | 1486266234 | Python | Python (2.7.6) | py | Runtime Error | 15 | 2568 | 260 | n = int(raw_input())
a = map(int, raw_input().split())
if 0 max(a) >= len(a) and sum(a) % (n * (n + 1) / 2) == 0:
for j in xrange(n + 1):
i = a.index(max(a))
a[(i + j) % n] -= j
if not 0 in a:
print 'YES'
else:
print 'NO'
|
s272291772 | p03808 | u439009525 | 1486264791 | Python | Python (3.4.3) | py | Runtime Error | 40 | 11172 | 319 | N=int(input())
A_list=map(int, input().split())
# N=7
# A_list=[1,2,3,4,5,6,7]
# N=5
# A_list=[4,5,1,2,3]
# A_list=[6,9,12,10,8]
# N=4
# A_list=[1,2,3,1]
d_list=[A_list[j]-A_list[j-1] for j in range(0, N)]
if 0 in d_list:
print("NO")
else:
if sum(d_list)==0:
print("YES")
else:
print("NO")
|
s252500516 | p03808 | u720968399 | 1486264241 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 382 | import numpy as np
N = int(raw_input())
n = np.array(map(int, raw_input().split()))
Nsum = np.sum(n)
if Nsum % np.sum(np.arange(N+1)[1:]):
print 'NO'
exit()
sa = np.append(n[1:], n[0]) - n
tmp = np.sum(sa % N != Nsum / np.sum(np.arange(N+1)[1:]))
tmp2 = np.sum(np.abs(sa) / N > (N-1)*Nsum / np.sum(np.arange(N+1)[1:])
if tmp or tmp2:
print 'NO'
else:
print 'YES' |
s019118791 | p03808 | u439009525 | 1486264096 | Python | Python (3.4.3) | py | Runtime Error | 39 | 11172 | 385 | N=int(input())
A_list=map(int, input().split())
# N=7
# A_list=[1,2,3,4,5,6,7]
# N=5
# A_list=[4,5,1,2,3]
# A_list=[6,9,12,10,8]
# N=4
# A_list=[1,2,3,1]
m=1
while m>0:
i=(A_list.index(max(A_list)))
A_list=[A_list[(i+j)%N]-j for j in range(1, N+1)]
m=min(A_list)
if m<0:
print("NO")
elif m==0:
if max(A_list)==0:
print("YES")
else:
print("NO") |
s222673991 | p03808 | u720968399 | 1486262223 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2572 | 304 | import numpy as np
N = int(raw_input())
n = np.array(map(int, raw_input().split()))
Nsum = np.sum(n)
if not Nsum % np.cumsum(np.arange(N)):
print 'NO'
return
sa = n[1:-1] - n
for s in sa:
if s % n != Nsum / np.cumsum(np.arange(N)):
print 'NO'
return
print 'YES'
return |
s031695535 | p03809 | u906428167 | 1593205897 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2208 | 101244 | 1198 | from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
if n == 2:
print('YES' if a[0] == a[1] else 'NO')
exit()
for _ in range(n-1):
aa, b = map(int, input().split())
aa -= 1
b -= 1
g[aa].append(b)
g[b].append(aa)
if len(g[aa]) == 2:
root = aa
if len(g[b]) == 2:
root = b
visited = [False]*n
def dfs(v):
visited[v] = True
chl = []
for w in g[v]:
if not visited[w]:
ret = dfs(w)
chl.append(ret)
if len(chl) == 0:
return a[v]
elif len(chl) == 1:
if a[v] == chl[0]:
return a[v]
else:
print('NO')
exit()
ret = 2*a[v]-sum(chl)
res = sum(chl)-a[v]
if res < 0 or (v == root and ret != 0):
print('NO')
exit()
chl = sorted(chl)
l = 0
r = len(chl) - 1
while res > 0:
if chl[l] == 0:
l += 1
if chl[r] == 0:
r -= 1
if l != r:
chl[l] -= 1
chl[r] -= 1
res -= 1
else:
print('NO')
exit()
return ret
dfs(root)
print('YES')
|
s361668185 | p03809 | u488401358 | 1592634104 | Python | PyPy3 (7.3.0) | py | Runtime Error | 85 | 74780 | 726 | import sys
input=sys.stdin.readline
sys.setrcursionlimit(2*10**5)
N=int(input())
A=list(map(int,input().split()))
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
root=0
for i in range(N):
if len(edge[i])!=1:
root=i
break
def dfs(v,pv):
s=A[v]
t=0
for nv in edge[v]:
if nv!=pv:
y=dfs(nv,v)
t+=y
#2*a+b=t
#a+b=s
if t==0:
if len(edge[v])!=1:
print("NO")
exit()
else:
return s
a=t-s
b=2*s-t
if 2*a>t:
print("NO")
exit()
return b
res=dfs(root,-1)
print("YES" if res==0 else "NO")
|
s824065077 | p03809 | u488401358 | 1592634064 | Python | PyPy3 (7.3.0) | py | Runtime Error | 102 | 74788 | 733 | import sys
input=sys.stdin.buffer.readline
sys.setrcursionlimit(2*10**5)
N=int(input())
A=list(map(int,input().split()))
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
root=0
for i in range(N):
if len(edge[i])!=1:
root=i
break
def dfs(v,pv):
s=A[v]
t=0
for nv in edge[v]:
if nv!=pv:
y=dfs(nv,v)
t+=y
#2*a+b=t
#a+b=s
if t==0:
if len(edge[v])!=1:
print("NO")
exit()
else:
return s
a=t-s
b=2*s-t
if 2*a>t:
print("NO")
exit()
return b
res=dfs(root,-1)
print("YES" if res==0 else "NO")
|
s114497051 | p03809 | u638795007 | 1591457525 | Python | PyPy3 (2.4.0) | py | Runtime Error | 488 | 78500 | 1879 | def examA():
N = I()
A = LI()
ans = "YES"
cur = 0
for a in A:
if a%2==1:
cur +=1
if cur%2==1:
ans = "NO"
print(ans)
return
def examB():
N = I()
A = LI()
ans = "YES"
sumA = sum(A)
oneA = (1+N)*N//2
if sumA%oneA!=0:
ans = "NO"
ope = sumA//oneA
#各Aについて何回始点としたか二分探索
cur = 0
for i in range(N):
now = ope - (A[i]-A[i-1])
if now%N!=0 or now<0:
# print(now,i)
ans = "NO"
break
cur += now//N
if cur!=ope:
ans = "NO"
print(ans)
return
def examC():
N = I()
A = LI()
V = [[]for _ in range(N)]
for i in range(N-1):
a, b = LI()
V[a-1].append(b-1)
V[b-1].append(a-1)
s = -1
for i,v in enumerate(V):
if len(v)>1:
s = i
break
flag = True
def dfs(s,p,flag):
rep = 0
for v in V[s]:
if v==p:
continue
rep += dfs(v,s,flag)[0]
if len(V[s])==1:
rep = A[s]
if (rep+1)//2>A[s] or rep<A[s]:
flag = False
#print(s,rep)
rep -= (rep-A[s])*2
return rep,flag
rep,flag = dfs(s,-1,flag)
if rep!=0:
flag = False
if flag:
print("YES")
else:
print("NO")
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18
if __name__ == '__main__':
examC()
|
s189892650 | p03809 | u682686221 | 1586298551 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1779 | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
vector<vi> adj;
vll A;
vll dp;
bool ng=false;
void dfs(int v, int p){
if (ng) return;
if (v!=0 && adj[v].size()==1){
dp[v] = A[v];
return;
}
ll sum=0,cnt=0;
for(auto u:adj[v]){
if (u==p) continue;
dfs(u,v);
sum+=dp[u];
cnt++;
}
if (cnt==1){
if (sum==A[v]) dp[v]=A[v];
else{
ng=true;
return;
}
}
ll x = sum-A[v];
if (x<0){ng=true; return;}
ll y = A[v]-x;
if (y<0){ng=true; return;}
dp[v] = y;
}
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin>>n;
adj.resize(n);
A.resize(n);
dp.resize(n);
rep(i,n) cin>>A[i];
rep(i,n-1){
int a,b; cin>>a>>b; a--; b--;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(0,-1);
if (ng){
cout<<"NO\n";
}else{
cout<<"YES\n";
}
return 0;
}
|
s730188996 | p03809 | u905582793 | 1585160448 | Python | PyPy3 (2.4.0) | py | Runtime Error | 548 | 97240 | 1029 | import random
import sys
input = sys.stdin.readline
n = int(input())
stone = [0]+list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
dp = [[] for i in range(n+1)]
deg = [0]*(n+1)
stack = []
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
deg[a] += 1
deg[b] += 1
root = 0
for i in range(1,n+1):
if deg[i] == 1:
stack.append(i)
elif root == 0:
root = i
if root == 0:
print(2/0)
if stone[0] == stone[1]:
print("YES")
else:
print("NO")
exit()
deg[root] += 1
flg = 1
while stack:
x = stack.pop()
if x == root:
if sum(dp[x]) != 2*stone[x] or max(dp[x]) > stone[x]:
flg = 0
break
elif dp[x]:
if max(max(dp[x])*2,sum(dp[x])) > stone[x]*2 or stone[x] > sum(dp[x]):
flg = 0
break
stone[x] = 2*stone[x]-sum(dp[x])
for y in graph[x]:
if deg[y] > 1:
dp[y].append(stone[x])
deg[y] -= 1
if deg[y] == 1:
stack.append(y)
if flg:
print("YES")
else:
print("NO") |
s248834002 | p03809 | u340781749 | 1582936892 | Python | Python (3.4.3) | py | Runtime Error | 621 | 117928 | 1119 | import sys
sys.setrecursionlimit(10 ** 6)
def dfs(v, p, aaa):
if len(links[v]) == 1:
return aaa[v]
children = []
for u in links[v]:
if u == p:
continue
result = dfs(u, v, aaa)
if result == -1:
return -1
children.append(result)
if len(children) == 1:
if aaa[v] != children[0]:
return -1
return children[0]
c_sum = sum(children)
c_max = max(children)
o_max = c_sum - c_max
if o_max >= c_max:
max_pairs = c_sum // 2
else:
max_pairs = o_max
min_remain = c_sum - max_pairs
if not min_remain <= aaa[v] <= c_sum:
return -1
return aaa[v] * 2 - c_sum
def solve(n, aaa, links):
# 葉でない頂点探し
s = 0
while len(links[s]) == 1:
s += 1
return dfs(s, -1, aaa) == 0
n = int(input())
aaa = list(map(int, input().split()))
links = [set() for _ in range(n)]
for line in sys.stdin:
a, b = map(int, line.split())
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
print('YES' if solve(n, aaa, links) else 'NO')
|
s328037082 | p03809 | u340781749 | 1582936799 | Python | Python (3.4.3) | py | Runtime Error | 683 | 117924 | 1123 | import sys
sys.setrecursionlimit(10 ** 5 + 5)
def dfs(v, p, aaa):
if len(links[v]) == 1:
return aaa[v]
children = []
for u in links[v]:
if u == p:
continue
result = dfs(u, v, aaa)
if result == -1:
return -1
children.append(result)
if len(children) == 1:
if aaa[v] != children[0]:
return -1
return children[0]
c_sum = sum(children)
c_max = max(children)
o_max = c_sum - c_max
if o_max >= c_max:
max_pairs = c_sum // 2
else:
max_pairs = o_max
min_remain = c_sum - max_pairs
if not min_remain <= aaa[v] <= c_sum:
return -1
return aaa[v] * 2 - c_sum
def solve(n, aaa, links):
# 葉でない頂点探し
s = 0
while len(links[s]) == 1:
s += 1
return dfs(s, -1, aaa) == 0
n = int(input())
aaa = list(map(int, input().split()))
links = [set() for _ in range(n)]
for line in sys.stdin:
a, b = map(int, line.split())
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
print('YES' if solve(n, aaa, links) else 'NO')
|
s630132472 | p03809 | u892251744 | 1578939750 | Python | PyPy3 (2.4.0) | py | Runtime Error | 446 | 82540 | 1572 | def main():
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
adj = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
for v in range(1, N+1):
if len(adj[v]) != 1:
v0 = v
break
# from collections import deque
que = deque()
que.append(v0)
seen = [-1] * (N+1)
seen[v0] = 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)
for v in reversed(seq):
if not child[v]:
if A[v-1] == 0:
print('NO')
exit()
continue
L = []
for u in child[v]:
L.append(A[u-1])
if len(L) == 1:
if L[0] != A[v-1]:
print('NO')
exit()
continue
s = sum(L)
m = max(L)
if s < A[v-1]:
print('NO')
exit()
if A[v-1] < (s+1) // 2:
print('NO')
exit()
if A[v-1] < m:
print('NO')
exit()
A[v-1] = 2 * A[v-1] - s
if A[v0-1]:
print('NO')
else:
print('YES')
if __name__ == '__main__':
main()
|
s909841088 | p03809 | u368780724 | 1576547494 | Python | PyPy3 (2.4.0) | py | Runtime Error | 492 | 95596 | 1487 | import sys
readline = sys.stdin.readline
from collections import Counter
def calc(A):
s = sum(A)
ma = max(A)
if 2*ma > s:
return s - ma
return s//2
def check():
candi = [[] for _ in range(N)]
for l in L[:0:-1]:
p = P[l]
if candi[l]:
x = sum(candi[l]) - candi[l]
y = A[l] - x
if 0 <= y <= calc(candi[l]):
return 'NO'
else:
x = 0
y = A[l]
x = sum(candi[0]) - candi[0]
y = A[0] - x
if candi[0]:
if not 0 <= sum(candi[0]) - A[0] <= calc(candi[0]):
return 'NO'
if y:
return 'NO'
return 'YES'
def parorder(Edge, p):
N = len(Edge)
par = [0]*N
par[p] = -1
stack = [p]
order = []
visited = set([p])
ast = stack.append
apo = order.append
while stack:
vn = stack.pop()
apo(vn)
for vf in Edge[vn]:
if vf in visited:
continue
visited.add(vf)
par[vf] = vn
ast(vf)
return par, order
def getcld(p):
res = [[] for _ in range(len(p))]
for i, v in enumerate(p[1:], 1):
res[v].append(i)
return res
N = int(readline())
A = list(map(int, readline().split()))
Edge = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, readline().split())
a -= 1
b -= 1
Edge[a].append(b)
Edge[b].append(a)
P, L = parorder(Edge, 0)
C = getcld(P)
print(check()) |
s746520461 | p03809 | u627417051 | 1576117354 | Python | Python (3.4.3) | py | Runtime Error | 743 | 121952 | 1413 | #設定
import sys
input = sys.stdin.buffer.readline
#ライブラリインポート
from collections import defaultdict
#入力受け取り
def getlist():
return list(map(int, input().split()))
#部分木 大きさ
import sys
sys.setrecursionlimit(10**7)
from collections import defaultdict
class Graph(object):
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return len(self.graph)
def add_edge(self, a, b):
self.graph[a].append(b)
def get_nodes(self):
return self.graph.keys()
def DFS(G, A, use, Wlist, visit, node):
for i in G.graph[node]:
if visit[i] != "Yes":
visit[i] = "Yes"
DFS(G, A, use, Wlist, visit, i)
Wlist[node].append(use[i])
#抜けの処理
if Wlist[node] == []:
use[node] = A[node]
else:
Z = sum(Wlist[node])
if max(max(Wlist[node]), (Z + 1) // 2) <= A[node] and A[node] <= Z:
use[node] = 2 * A[node] - Z
else:
judge = "NO"
#処理内容
def main():
N = int(input())
A = getlist()
G = Graph()
for i in range(N - 1):
a, b = getlist()
a -= 1; b -= 1
G.add_edge(a, b)
G.add_edge(b, a)
s = None
for i in range(N):
if len(G.graph[i]) >= 2:
s = i
break
#DFS
judge = "YES"
use = [None] * N
Wlist = [[] for i in range(N)]
visit = ["No"] * N
visit[s] = "Yes"
DFS(G, A, use, Wlist, visit, s)
# print(use)
if use[s] != 0:
judge = "NO"
#答え
print(judge)
if __name__ == '__main__':
main() |
s510487517 | p03809 | u236127431 | 1545071149 | Python | PyPy3 (2.4.0) | py | Runtime Error | 826 | 80628 | 682 | N=int(input())
A=[int(i) for i in input().split()]
G=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
Visited=[False]*N
B=[0]*N
def B_map(x):
C=[]
S=-1
Visited[x]=True
for i in G[x]:
if not Visited[i]:
res=B_map(i)
if S<0:
S=res
else:
S+=res
C.append(res)
if S<0:
B[x]=A[x]
else:
M=max(max(C),sum(C)//2)
T=2*A[x]-S
if 0<=(S-T)//2<=M:
B[x]=2*A[x]-S
else:
print("NO")
exit()
if x==0 and T!=0:
print("NO")
exit()
return B[x]
B_map(0)
for i in range(N):
if B[i]<0:
print("NO")
exit()
print("YES") |
s554340960 | p03809 | u236127431 | 1545063006 | Python | PyPy3 (2.4.0) | py | Runtime Error | 769 | 80756 | 496 | N=int(input())
A=[int(i) for i in input().split()]
G=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
Visited=[False]*N
B=[0]*N
def B_map(x):
res=-1
Visited[x]=True
for i in G[x]:
if not Visited[i]:
if res<0:
res=B_map(i)
else:
res+=B_map(i)
if res<0:
B[x]=A[x]
else:
B[x]=2*A[x]-res
return B[x]
B_map(0)
for i in range(N):
if B[i]<0:
print("NO")
exit()
print("YES") |
s772790663 | p03809 | u884982181 | 1544396093 | Python | Python (3.4.3) | py | Runtime Error | 869 | 45360 | 863 | n = int(input())
a = list(map(int,input().split()))
g = [[]for i in range(n)]
for i in range(n-1):
x,y = map(int,input().split())
x-=1;y-=1
g[x].append(y)
g[y].append(x)
used = [0]*n
ue = [0]*n
for i in range(n):
if len(g[i])== 1:
ne = i
break
huka = [0]*n
def dfs(x,y,z):
if used[x]:
return 0
used[x] = 1
huka[x] = y
ue[x] = z
for ix in g[x]:
dfs(ix,y+1,x)
dfs(ne,0,-1)
for i in range(n):
huka[i] = [huka[i],i]
huka.sort(key=lambda x:-x[0])
hen = [0]*(n)
for i in range(n-1):
x = huka[i][1]
if len(g[x]) == 1:
hen[x] = a[x]
hen[ue[x]] += hen[x]
if hen[x] > a[ue[x]]:
print("NO")
exit()
continue
hen[x] = a[x]*2-hen[x]
hen[ue[x]] += hen[x]
if hen[x] > a[ue[x]]:
print("NO")
exit()
if hen[x] <0:
print("NO")
exit()
if hen[ne] != a[ne]:
print("NO")
else:
print("YES") |
s651437517 | p03809 | u767131578 | 1489754431 | Python | Python (3.4.3) | py | Runtime Error | 1285 | 55812 | 1545 | import copy
def traverse(N,A,mm):
if N<2 or len(A)!=N+1 or len(mm)!=N+1:
return(False)
m=copy.deepcopy(mm)
t=[]
rp=[]
c=[]
for i in range(N+1):
t.extend([0])
rp.extend([0])
c.extend([[0]])
start=1
for i in range(start,N+1):
if len(m[i])==1 and A[i]>0:
#if A[i]>0:
root=i
break
eerror=False
if len(m[root]) in [0,1]:
t[root]=A[root]
else:
t[root]=2*A[root]
r=0
i=root
while not(i==root and len(m[i])==0):
#print(i,t[i],m[i],rp[i])
if len(m[i])==0:
#print('back')
c[i][0]=t[i]
r=i
i=rp[i]
#print(i,t[i],m[i],rp[i])
t[i]-=t[r]
c[i].extend([t[r]])
#print('minus')
#print(c)
if t[i]<0:
return(False)
#eerror=True
#break
else:
#print('forward')
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
#print(i,t[i],m[i],rp[i])
if len(m[i]) in [0,1]:
t[i]=A[i]
else:
t[i]=2*A[i]
#print('plus')
#print(i,t[i],m[i],rp[i])
if r in m[i]:
m[i].remove(r)
#print('remove')
for cc in c[1:]:
cc_max=cc.index(max(cc))
if len(cc)>2 and cc[cc_max]>sum([cc[i] for i in range(len(cc)) if i!=cc_max]):
return(False)
if t[root]==0 and eerror==False:
return(True)
else:
return(False)
N= int(input())
A=[0]
for x in input().split():
A.extend([int(x)])
m=[]
for i in range(N+1):
m.extend([[]])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
#l=[int(xx) for xx in L.pop()]
if 0<l[0]<=N and 0<l[1]<=N:
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
if traverse(N,A,m):
print('YES')
else:
print('NO')
|
s899450949 | p03809 | u767131578 | 1489754042 | Python | Python (3.4.3) | py | Runtime Error | 1394 | 56196 | 1545 | import copy
def traverse(N,A,mm):
if N<2 or len(A)!=N+1 or len(mm)!=N+1:
return(False)
m=copy.deepcopy(mm)
t=[]
rp=[]
c=[]
for i in range(N+1):
t.extend([0])
rp.extend([0])
c.extend([[0]])
start=1
for i in range(start,N+1):
#if len(m[i])==1 and A[i]>0:
if A[i]>0:
root=i
break
eerror=False
if len(m[root]) in [0,1]:
t[root]=A[root]
else:
t[root]=2*A[root]
r=0
i=root
while not(i==root and len(m[i])==0):
#print(i,t[i],m[i],rp[i])
if len(m[i])==0:
#print('back')
c[i][0]=t[i]
r=i
i=rp[i]
#print(i,t[i],m[i],rp[i])
t[i]-=t[r]
c[i].extend([t[r]])
#print('minus')
#print(c)
if t[i]<0:
return(False)
#eerror=True
#break
else:
#print('forward')
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
#print(i,t[i],m[i],rp[i])
if len(m[i]) in [0,1]:
t[i]=A[i]
else:
t[i]=2*A[i]
#print('plus')
#print(i,t[i],m[i],rp[i])
if r in m[i]:
m[i].remove(r)
#print('remove')
for cc in c[1:]:
cc_max=cc.index(max(cc))
if len(cc)>2 and cc[cc_max]>sum([cc[i] for i in range(len(cc)) if i!=cc_max]):
return(False)
if t[root]==0 and eerror==False:
return(True)
else:
return(False)
N= int(input())
A=[0]
for x in input().split():
A.extend([int(x)])
m=[]
for i in range(N+1):
m.extend([[]])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
#l=[int(xx) for xx in L.pop()]
if 0<l[0]<=N and 0<l[1]<=N:
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
if traverse(N,A,m):
print('YES')
else:
print('NO')
|
s162064402 | p03809 | u767131578 | 1489752955 | Python | Python (3.4.3) | py | Runtime Error | 1345 | 56184 | 1485 | import copy
def traverse(N,A,mm):
m=copy.deepcopy(mm)
t=[]
rp=[]
c=[]
for i in range(N+1):
t.extend([0])
rp.extend([0])
c.extend([[0]])
start=1
for i in range(start,N+1):
#if len(m[i])==1 and A[i]>0:
if A[i]>0:
root=i
break
eerror=False
if len(m[root]) in [0,1]:
t[root]=A[root]
else:
t[root]=2*A[root]
i=root
while not(i==root and len(m[i])==0):
#print(i,t[i],m[i],rp[i])
if len(m[i])==0:
#print('back')
c[i][0]=t[i]
r=i
i=rp[i]
#print(i,t[i],m[i],rp[i])
t[i]-=t[r]
c[i].extend([t[r]])
#print('minus')
#print(c)
if t[i]<0:
return(False)
#eerror=True
#break
else:
#print('forward')
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
#print(i,t[i],m[i],rp[i])
if len(m[i]) in [0,1]:
t[i]=A[i]
else:
t[i]=2*A[i]
#print('plus')
#print(i,t[i],m[i],rp[i])
if r in m[i]:
m[i].remove(r)
#print('remove')
for cc in c[1:]:
cc_max=cc.index(max(cc))
if len(cc)>2 and cc[cc_max]>sum([cc[i] for i in range(len(cc)) if i!=cc_max]):
return(False)
if t[root]==0 and eerror==False:
return(True)
else:
return(False)
N= int(input())
A=[0]
for x in input().split():
A.extend([int(x)])
m=[]
for i in range(N+1):
m.extend([[]])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
#l=[int(xx) for xx in L.pop()]
if 0<l[0]<=N and 0<l[1]<=N:
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
if traverse(N,A,m):
print('YES')
else:
print('NO')
|
s228028104 | p03809 | u767131578 | 1489655372 | Python | Python (3.4.3) | py | Runtime Error | 1270 | 55940 | 1477 | import copy
def traverse(N,A,mm):
m=copy.deepcopy(mm)
t=[]
rp=[]
c=[]
for i in range(N+1):
t.extend([0])
rp.extend([0])
c.extend([[0]])
start=1
for i in range(start,N+1):
#if len(m[i])==1 and A[i]>0:
if A[i]>0:
root=i
break
eerror=False
if len(m[root]) in [0,1]:
t[root]=A[root]
else:
t[root]=2*A[root]
while not(i==root and len(m[i])==0):
#print(i,t[i],m[i],rp[i])
if len(m[i])==0:
#print('back')
c[i][0]=t[i]
r=i
i=rp[i]
#print(i,t[i],m[i],rp[i])
t[i]-=t[r]
c[i].extend([t[r]])
#print('minus')
#print(c)
if t[i]<0:
return(False)
#eerror=True
#break
else:
#print('forward')
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
#print(i,t[i],m[i],rp[i])
if len(m[i]) in [0,1]:
t[i]=A[i]
else:
t[i]=2*A[i]
#print('plus')
#print(i,t[i],m[i],rp[i])
if r in m[i]:
m[i].remove(r)
#print('remove')
for cc in c[1:]:
cc_max=cc.index(max(cc))
if len(cc)>2 and cc[cc_max]>sum([cc[i] for i in range(len(cc)) if i!=cc_max]):
return(False)
if t[root]==0 and eerror==False:
return(True)
else:
return(False)
N= int(input())
A=[0]
for x in input().split():
A.extend([int(x)])
m=[]
for i in range(N+1):
m.extend([[]])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
#l=[int(xx) for xx in L.pop()]
if 0<l[0]<=N and 0<l[1]<=N:
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
if traverse(N,A,m):
print('YES')
else:
print('NO')
|
s854778786 | p03809 | u767131578 | 1489619946 | Python | Python (3.4.3) | py | Runtime Error | 1246 | 55812 | 1426 | import copy
def traverse(N,A,mm):
m=copy.deepcopy(mm)
t=[]
rp=[]
c=[]
for i in range(N+1):
t.extend([0])
rp.extend([0])
c.extend([[0]])
start=1
for i in range(start,N+1):
#if len(m[i])==1 and A[i]>0:
if A[i]>0:
root=i
break
eerror=False
if len(m[root]) in [0,1]:
t[root]=A[root]
else:
t[root]=2*A[root]
while not(i==root and len(m[i])==0):
#print(i,t[i],m[i],rp[i])
if len(m[i])==0:
#print('back')
c[i][0]=t[i]
r=i
i=rp[i]
#print(i,t[i],m[i],rp[i])
t[i]-=t[r]
c[i].extend([t[r]])
#print('minus')
#print(c)
if t[i]<0:
eerror=True
break
else:
#print('forward')
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
#print(i,t[i],m[i],rp[i])
if len(m[i]) in [0,1]:
t[i]=A[i]
else:
t[i]=2*A[i]
#print('plus')
#print(i,t[i],m[i],rp[i])
if r in m[i]:
m[i].remove(r)
#print('remove')
for cc in c[1:]:
cc_max=cc.index(max(cc))
if len(cc)>2 and cc[cc_max]>sum([cc[i] for i in range(len(cc)) if i!=cc_max]):
return(False)
if t[root]==0 and eerror==False:
return(True)
else:
return(False)
N= int(input())
A=[0]
for x in input().split():
A.extend([int(x)])
m=[]
for i in range(N+1):
m.extend([[]])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
#l=[int(xx) for xx in L.pop()]
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
if traverse(N,A,m):
print('YES')
else:
print('NO')
|
s512857364 | p03809 | u767131578 | 1489619215 | Python | Python (3.4.3) | py | Runtime Error | 1361 | 55940 | 1426 | import copy
def traverse(N,A,mm):
m=copy.deepcopy(mm)
t=[]
rp=[]
c=[]
for i in range(N+1):
t.extend([0])
rp.extend([0])
c.extend([[0]])
start=1
for i in range(start,N+1):
#if len(m[i])==1 and A[i]>0:
if A[i]>0:
root=i
break
eerror=False
if len(m[root]) in [0,1]:
t[root]=A[root]
else:
t[root]=2*A[root]
while not(i==root and len(m[i])==0):
#print(i,t[i],m[i],rp[i])
if len(m[i])==0:
#print('back')
c[i][0]=t[i]
r=i
i=rp[i]
#print(i,t[i],m[i],rp[i])
t[i]-=t[r]
c[i].extend([t[r]])
#print('minus')
#print(c)
if t[i]<0:
eerror=True
break
else:
#print('forward')
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
#print(i,t[i],m[i],rp[i])
if len(m[i]) in [0,1]:
t[i]=A[i]
else:
t[i]=2*A[i]
#print('plus')
#print(i,t[i],m[i],rp[i])
if r in m[i]:
m[i].remove(r)
#print('remove')
for cc in c[1:]:
cc_max=cc.index(max(cc))
if len(cc)>1 and cc[cc_max]>sum([cc[i] for i in range(len(cc)) if i!=cc_max]):
return(False)
if t[root]==0 and eerror==False:
return(True)
else:
return(False)
N= int(input())
A=[0]
for x in input().split():
A.extend([int(x)])
m=[]
for i in range(N+1):
m.extend([[]])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
#l=[int(xx) for xx in L.pop()]
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
if traverse(N,A,m):
print('YES')
else:
print('NO')
|
s811801326 | p03809 | u767131578 | 1489212327 | Python | Python (3.4.3) | py | Runtime Error | 710 | 26928 | 867 | N= int(input())
A=[[]]
for x in input().split():
A.extend([int(x)])
m=[]
t=[]
rp=[]
for i in range(N+1):
m.extend([[]])
t.extend([0])
rp.extend([0])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
for i in range(1,N+1):
if len(m[i])==1 and A[i]>0:
root=i
break
eerror=False
t[root]=2*A[root]
r=root
i=m[root].pop()
rp[i]=r
if r in m[i]:
m[i].remove(r)
if len(m[i])==0:
t[i]=A[i]
else:
t[i]=2*A[i]
while i!=root:
#print(r,t[r],m[r],rp[r],'->',i,t[i],m[i],rp[i])
if len(m[i])==0:
r=i
i=rp[i]
t[i]-=t[r]
if t[i]<0:
eerror=True
break
else:
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
if r in m[i]:
m[i].remove(r)
if len(m[i])==0:
t[i]=A[i]
else:
t[i]=2*A[i]
#print(r,t[r],m[r],'->',i)
if t[r]==A[root] and eerror==False:
print('YES')
else:
print('NO')
|
s468252023 | p03809 | u767131578 | 1489211570 | Python | Python (3.4.3) | py | Runtime Error | 770 | 26928 | 784 | N= int(input())
A=[[]]
for x in input().split():
A.extend([int(x)])
m=[]
t=[]
rp=[]
for i in range(N+1):
m.extend([[]])
t.extend([0])
rp.extend([0])
for i in range(N-1):
l=[int(xx) for xx in input().split()]
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
for i in range(1,N+1):
if len(m[i])==1 and A[i]>0:
root=i
break
eerror=False
r=root
i=m[root].pop()
rp[i]=r
t[root]=2*A[i]
if r in m[i]:
m[i].remove(r)
if len(m[i])==0:
t[i]=A[i]
else:
t[i]=2*A[i]
while i!=root:
if len(m[i])==0:
r=i
i=rp[i]
t[i]-=t[r]
if t[i]<0:
eerror=True
break
else:
r=i
i=m[i].pop()
if rp[i]==0:
rp[i]=r
if r in m[i]:
m[i].remove(r)
if len(m[i])==0:
t[i]=A[i]
else:
t[i]=2*A[i]
if t[r]==A[root] and eerror==False:
print('YES')
else:
print('NO')
|
s020265364 | p03809 | u767131578 | 1489030406 | Python | Python (3.4.3) | py | Runtime Error | 618 | 38052 | 598 | def TTT(me=0,r=0):
mm=m[me]
l=len(mm)
if l==1:
if r!=0:
ret=A[me]
else:
ret=TTT(mm[0],me)
else:
c=0
for i in range(l):
if mm[i]!=r:
c+=TTT(mm[i],me)
ret=2*A[me]-c
#print(me,r,ret)
return(ret)
N= int(input())
A=[[]]+[int(x) for x in input().split()]
L=[]
for i in range(N-1):
L.extend([[int(xx)for xx in input().split()]])
m=[]
for i in range(N+1):
m.extend([[]])
for l in L:
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
for i in range(N):
if len(m[i])==1:
break
root=i
Tvalue=TTT(m[root][0],root)
if Tvalue==A[root]:
print('YES')
else:
print('NO')
|
s160498773 | p03809 | u767131578 | 1489030123 | Python | Python (3.4.3) | py | Runtime Error | 616 | 38080 | 620 | def TTT(A=[],m=[],me=0,r=0):
mm=m[me]
l=len(mm)
if l==1:
if r!=0:
ret=A[me]
else:
ret=TTT(A,m,mm[0],me)
else:
c=0
for i in range(l):
if mm[i]!=r:
c+=TTT(A,m,mm[i],me)
ret=2*A[me]-c
#print(me,r,ret)
return(ret)
N= int(input())
A=[[]]+[int(x) for x in input().split()]
L=[]
for i in range(N-1):
L.extend([[int(xx)for xx in input().split()]])
m=[]
for i in range(N+1):
m.extend([[]])
for l in L:
m[l[0]]+=[l[1]]
m[l[1]]+=[l[0]]
for i in range(N):
if len(m[i])==1:
break
root=i
Tvalue=TTT(A,m,m[root][0],root)
if Tvalue==A[root]:
print('YES')
else:
print('NO')
|
s191923899 | p03809 | u767131578 | 1488861652 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 768 | def T(A=[],lines=[],me=0,parent=0):
if [x for y in lines for x in y].count(me)==1 and parent==0:
for a in lines:
if a[0]==me:
return(T(A,lines,a[1],me))
elif a[1]==me:
return(T(A,lines,a[0],me))
elif [me,parent] not in lines and [parent,me] not in lines:
return(0)
else:
sl=0
for a in lines:
if a[0]==me and a[1]!=parent:
sl=sl+T(A,lines,a[1],me)
elif a[1]==me and a[0]!=parent:
sl=sl+T(A,lines,a[0],me)
if sl==0:
return(A[me-1])
else:
return(A[me-1]*2-sl)
N= Int(input())
A=[int(x) for x in input().split()]
L=[]
for i in range(N-1):
L=L+[int(xx)for xx in input().split()]
LF=[x for y in L for x in y]
LF1= [x for x in LF if LF.count(x)==1]
if T(A,L,min(LF1))==A[min(LF1)]-1:
print('YES')
else:
print('NO') |
s882283410 | p03810 | u905582793 | 1590274881 | Python | PyPy3 (2.4.0) | py | Runtime Error | 172 | 38384 | 721 | from math import gcd
n = int(input())
a = list(map(int,input().split()))
def gcds(ls):
ret = 0
for i in ls:
ret = gcd(ret,i)
return ret
def flg(ls):
if (sum(ls)-len(ls))%2:
ret = 1
else:
ret = 2
return ret
if n%2 == 0:
if sum(a)%2:
print("Second")
else:
print("First")
else:
cnt = 0
while flg(a)%2 == 0:
odd = 0
oddidx = -1
even = 0
for i,x in enumerate(a):
if x%2:
odd += 1
oddidx = i
else:
even += 1
if odd == 1 and a[oddidx] > 1:
a[oddidx] -= 1
g = gcds(a)
for i in range(n):
a[i] //= g
cnt += 1
else:
break
if (flg(a)+cnt)%2 == 1:
print("First")
else:
print("Second") |
s863390982 | p03810 | u368780724 | 1590146192 | Python | PyPy3 (2.4.0) | py | Runtime Error | 647 | 104212 | 472 | import sys
readline = sys.stdin.readline
from functools import reduce
def gcd(a,b):
while b:
a, b = b, a%b
return a
def calc(A):
N = len(A)
K = sum(1 for a in A if a % 2 == 0)
if K & 1:
return True
if N-1 != K:
return False
A = [a-a%2 for a in A]
g = reduce(gcd, A)
A = [a//g for a in A]
return not calc(A)
N = int(readline())
A = list(map(int, readline().split()))
print('First' if calc(A) else 'Second') |
s803007937 | p03810 | u693716675 | 1586033280 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 997 | #d
#the niumbers of evens is important
#the point is, there is no influence to odd/even if you divide them by odd numbers.
#You should do simulation only in the case where there is one odd over 3 and even numbers of even numbers
from math import gcd
def count(a):
odd, even = 0,0
for x in a:
if x % 2 == 1: odd = odd + 1
else: even = even + 1
return odd,even
def deal(n,a):
odd,even = count(a)
if even == 0:
return False
if even % 2 == 1:
return True
if odd > 1:
return False
#the case where there is one odd (over 3) and even numbers of even numbers
#calculate gcd by step by step
g = 1
for i in range(0,n):
if a[i] % 2 == 1:
if a[i] == 1:
return False
a[i] -= 1
g = gcd(a[i], g)
return not deal(n,list(map(lambda x: x//g,a)))
n = int(input())
a = [int(i) for i in input().split()]
if deal(n,a):
print('First')
else:
print('Second')
|
s957145700 | p03810 | u785578220 | 1549404735 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 363 | n = int(input())
x = list(map(int, input().split()))
j = 1
k=1
while j:
s=0
if 1 in x:
s = sum(x)-n
break
for i in range(n):
if x[i]%2 == 0:
x[i]/=2
s+=1
else:
x[i] = (x[i]-1)/2
if s == n-1 and s%2==0):j = 1
else:j=0
if s %2 != 0:
print("First")
else:
print("Second") |
s617303369 | p03810 | u767131578 | 1490415795 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 16080 | 986 | import copy
def gcd(a, b):
while b:
a, b = b, a % b
return a
def gcdm(x):
g=x[0]
for i in range(1,len(x)):
g=gcd(g,x[i])
return(g)
def score(A):
return(sum(A)-len(A))
def Ifavor(A):
return(score(A)%2==1)
def playmove(A,i):
A[i]-=1
g=gcdm(A)
A=[x//g for x in A]
def testmove(A,i):
N=len(A)
A[i]-=1
g=gcdm(A)
A=[x//g for x in A]
if Ifavor(A):
A=[x*g for x in A]
A[i]+=1
return(False)
else:
j=0
while j<N:
A[j]-=1
h=gcdm(A)
if Ifavor([x//h for x in A])==False:
A[j]+=1
A=[x*g for x in A]
A[i]+=1
return(False)
A[j]+=1
j+=1
A=[x*g for x in A]
A[i]+=1
return(True)
N=int(input())
B=[int(x) for x in input().split()]
#inp=St.splitlines()
#N=int(inp[0])
#B=[int(x) for x in inp[1].split()]
if Ifavor(B):
print('First')
else:
maxply=sum(B)-N
ply=1
e=0
while e<N:
if testmove(B,e):
break
e+=1
if e!=N:
playmove(B,e)
ply+=1
if (ply%2==1)!=Ifavor(B):
print('Second')
else:
print('First')
|
s728028618 | p03811 | u767131578 | 1492217568 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 214172 | 1686 | import random
def tester(N=0):
maxno1=10
maxno2=1e2
s=input()
if s!='':
return(s)
if N==0:
return(6)
return(random.randint(2,maxno1))
else:
print('Testing...')
print('N=',N)
return('2 3 4 5 6 25')
A=[]
for i in range(N):
A.extend([random.randint(1,maxno2)])
r=' '.join(list(map(str,A)))
print(r)
return(r)
def factorint(n):
i = 2
T = []
while i * i <= n:
while n % i == 0:
n //= i
T.append(i)
i += 1
if n > 1:
T.append(n)
return(T)
import logging
# create logger
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.WARNING)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
import copy
N=int(tester())
A=[int(x) for x in tester(N).split()]
A.sort(reverse=False)
logger.debug('A is %s',str(A))
F=dict()
P=dict()
for x in A:
F[x]=set(factorint(x))
for y in F[x]:
if y not in P.keys():
P[y]=set()
P[y].add(x)
G=dict()
for x in F.keys():
G[x]=set()
for y in F[x]:
G[x]=G[x].union(P[y])
G[x].remove(x)
Ac=copy.deepcopy(A)
Gc=copy.deepcopy(G)
Tr=dict()
while len(Ac)>0:
Tmp=[]
rt=min(Ac)
me=rt
Tmp.extend([me])
Ac.remove(me)
while len(Gc[me])>0:
nxt=min(Gc[me])
if nxt not in Ac:
Gc[me].remove(nxt)
continue
else:
me=nxt
Tmp.extend([me])
Ac.remove(me)
Tr[rt]=Tmp
OoTr=list(Tr.keys())
OoTr.sort(reverse=True)
Ans=[]
for x in OoTr:
Ans.extend(Tr[x])
print(' '.join(list(map(str,Ans))))
(logger).removeHandler(ch)
|
s278872893 | p03811 | u637175065 | 1486266000 | Python | Python (3.4.3) | py | Runtime Error | 84 | 7756 | 1405 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n = II()
a = LI()
a.sort()
i = n-1
m = {}
def g(a,b):
if (a,b) in m:
return m[(a,b)]
c = math.gcd(a,b)
if c == 1:
m[(a,b)] = True
else:
m[(a,b)] = False
return c == 1
def f(i):
ai = a[i]
ii = i
ff = False
while ii > 0:
j = ii-1
aj = a[j]
mj = ii
while g(ai,a[j]) and j >= 0:
if a[j] < ai:
mj = j
j -= 1
if mj != ii:
a[mj:ii+1] = [ai] + a[mj:ii]
ff = True
ii = mj
else:
if f(ii-1):
continue
else:
break
return ff
for i in range(n-1,-1,-1):
while f(i):
pass
sa = a[:]
for _ in range(100):
random.shuffle(a)
for i in range(n-1,-1,-1):
while f(i):
pass
if a < sa:
sa = a[:]
return ' '.join(map(str, sa))
print(main())
|
s094281848 | p03812 | u284102701 | 1518874404 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1032 | #include <bits/stdc++.h>
//#include <math.h>
using namespace std;
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
//-----------------------------------------------------------------------------
int n;
vector<int> g[3000];
ll a[3000];
int dp[3000];
int dfs(int v,int prv) {
if(dp[v]!=0) return dp[v];
for(auto u:g[v]) {
if(u!=prv&&a[u]<a[v]&&dfs(u,v)==-1) return dp[v]=1;
}
return dp[v]=-1;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n;
REP(i,n) cin>>a[i];
REP(i,n-1) {
int u,v;cin>>u>>v;;u--,v--;
g[u].pb(v),g[v].pb(u);
}
REP(i,n) {
dfs(i,-1);
}
bool fst=true;
REP(i,n) {
if(!fst) cout<<' ';
if(dp[i]==1) {
cout<<i+1;
fst=false;
}
}
cout<<endl;
return 0;
}
|
s097084348 | p03812 | u934019430 | 1486349773 | Python | Python (3.4.3) | py | Runtime Error | 68 | 7100 | 1199 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fractions import gcd
def readln():
_res = list(map(int,str(input()).split(' ')))
return _res
def calc(x,line):
if line == 0:
for l in v[x]:
if e[l][0] == x: son = e[l][1]
else: son = e[l][0]
if a[son-1] < a[x-1] and calc(son,l) == -1:
return 1
return -1
else:
if e[line][0] == x: y = 0
else: y = 1
if f[x][y] != 0: return f[x][y]
if len(v[x]) == 1:
f[x][y] = -1
return -1
for l in v[x]:
if l != line:
if e[l][0] == x: son = e[l][1]
else: son = e[l][0]
if a[son-1] < a[x-1] and calc(son,l) == -1:
f[x][y] = 1
return 1
f[x][y] = -1
return -1
n = int(input())
v = [set([]) for i in range(0,n+1)]
e = [0 for i in range(0,n)]
a = readln()
for i in range(1,n):
s = readln()
v[s[0]].add(i)
v[s[1]].add(i)
e[i] = s
f = [[0,0] for i in range(0,n)]
ans = []
for i in range(1,n+1):
if calc(i,0) == 1:
ans.append(i)
ans = list(map(str,ans))
print(' '.join(ans))
|
s588315936 | p03813 | u987039273 | 1601235899 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9100 | 88 | X= (int(x) for x in input().split())
if X>1200:
print("ARC")
else :
print("ABC") |
s719587586 | p03813 | u546853743 | 1598379319 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9024 | 68 | x = int,input()
if x < 1200:
print('ABC')
else:
print("ARC") |
s026967484 | p03813 | u834301346 | 1598052193 | Python | Python (3.8.2) | py | Runtime Error | 33 | 9740 | 114 | import re
letter = str(input())
pattern = 'A(.*)Z'
target = re.search(pattern, letter).group()
print(len(target)) |
s271141635 | p03813 | u909716307 | 1597790576 | Python | Python (3.8.2) | py | Runtime Error | 20 | 8940 | 43 | print('ABC'if x=int(input())<1200else'ARC') |
s120725941 | p03813 | u075303794 | 1597636475 | Python | Python (3.8.2) | py | Runtime Error | 26 | 8960 | 62 | x=int(inptu())
if x<1200:
print('ABC')
else:
print('ARC') |
s237899161 | p03813 | u608355135 | 1597293046 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9028 | 60 | x=input()
if x<1200:
print("ABC")
else:
print("ARC") |
s513013833 | p03813 | u835575472 | 1597261782 | Python | Python (3.8.2) | py | Runtime Error | 22 | 9024 | 70 | rate = int(input())
if rate < 1200:
print("ABC")
else:
print("ARC) |
s839549993 | p03813 | u886907961 | 1597139552 | Python | Python (3.8.2) | py | Runtime Error | 39 | 8980 | 61 | n = int(input)
if n<1200:
print("ABC")
else:
print("ARC") |
s125597182 | p03813 | u886907961 | 1597139509 | Python | Python (3.8.2) | py | Runtime Error | 19 | 8772 | 62 | n = int(input)
if n<1200:
print("ABC")
else:
print("ARC") |
s971234758 | p03813 | u684743124 | 1595922463 | Python | Python (3.8.2) | py | Runtime Error | 22 | 8848 | 40 | print("ABC" if input()<1200 else "ARC")
|
s414565791 | p03813 | u309716323 | 1594602770 | Python | PyPy3 (7.3.0) | py | Runtime Error | 94 | 74896 | 240 |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
A, B, C, D = read_ints()
return max(A*B, C*D)
if __name__ == '__main__':
print(solve())
|
s389129325 | p03813 | u099217546 | 1593523870 | Python | Python (3.8.2) | py | Runtime Error | 22 | 8952 | 81 | input_line = int(input())
if input_line >= 1200
print("ARC")
else
print("ABC") |
s095364909 | p03813 | u095844416 | 1590565424 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 67 | a=int(input())
if x < 1200:
print('ABC')
else:
print('ARC') |
s178198309 | p03813 | u732743460 | 1590468022 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3316 | 170 | from collections import Counter
N = int(input())
A = sorted(list(map(int,input().split())))
edible = sum(i-1 for i in Counter(A).values())
print(len(set(A))-edible%2) |
s920527595 | p03813 | u475966842 | 1590097002 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 39 | print("A"+"RB"[int(input())<1200)]+"C") |
s528766918 | p03813 | u381282312 | 1589555197 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 156 | s = input()
t = []
u = []
for i in range(len(s)):
if s[i] == 'A':
t.append(i)
if s[i] == 'Z':
u.append(i)
print(max(u) - min(t) + 1) |
s513673650 | p03813 | u891217808 | 1588726493 | Python | PyPy3 (2.4.0) | py | Runtime Error | 180 | 38384 | 69 | n = int(input())
if x < 1200:
print('ABC')
else:
print('ARC') |
s625660165 | p03813 | u600261652 | 1588526563 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 58 | x = input()
if x<1200:
print("ABC")
else:
print("ARC") |
s113967742 | p03813 | u600261652 | 1588526475 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 58 | x = input()
if x<1200:
print("ABC")
else:
pritn("ARC") |
s891398369 | p03813 | u227085629 | 1587764406 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 63 | a = int(input())
if a<1200:
pirnt('ABC')
else:
print('ARC') |
s305437268 | p03813 | u896741788 | 1587613778 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 54 | print("A{}C".format("B" if int(input()<1200 else "R")) |
s914372660 | p03813 | u735335967 | 1587603887 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 177 | s = input()
ca = []
cz = []
ans = 0
for i in range(len(s)):
if s[i] == "A":
ca.append(i)
if s[i] == "Z":
cz.append(i)
ans = max(cz)-min(ca)+1
print(ans)
|
s918384396 | p03813 | u172780602 | 1586711948 | Python | Python (3.4.3) | py | Runtime Error | 16 | 2940 | 61 | x=input()
if x>=1200:
print("ARC")
else:
print("ABC") |
s390162191 | p03813 | u457957084 | 1586708149 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 69 | x = int(input())
if x < 1200:
print(ABC)
else:
print(ARC)
|
s189679704 | p03813 | u457957084 | 1586708122 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 64 | x = int(input())
if x, 1200:
print(ABC)
else:
print(ARC) |
s817118155 | p03813 | u787449825 | 1586218310 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 63 | x = int(inout())
if x>1200:
print('ARC')
else:
print('ABC') |
s913176923 | p03813 | u760961723 | 1585196062 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 65 | X = int(input())
if x < 1200:
print("ABC")
else:
print("ARC") |
s001219213 | p03813 | u623819879 | 1584855586 | Python | PyPy3 (2.4.0) | py | Runtime Error | 168 | 38256 | 41 | print('A'+'RB'[input()[:2]<’12’]+'C') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.