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
s041434638
p03957
u966695411
1477669845
Python
Python (3.4.3)
py
Runtime Error
23
3192
847
#! /usr/bin/env python3 def main(): d = 10 ** 9 + 7 ans = 1 N = int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) L = len(T) ST = [T[0]] + [0] * (L-2) + [T[-1] if T[-1] != T[-2] else 0] SA = [A[0] if A[0] != A[1] else 0] + [0] * (L-2) + [A[-1]] for i in range(0, L-1): if T[i] == T[i-1] and A[i] == A[i+1]: ans = (ans * min(T[i], A[i])) % d else: if T[i] != T[i-1] : ST[i] = T[i] if A[i] != A[i+1] : SA[i] = A[i] mt = ma = 0 for i in range(L): ma = max(ma, SA[i]) mt = max(mt, ST[L-i-1]) if ST[i] and SA[i] and ST[i] != SA[i]: ans = 0 if (ST[i] and ST[i] < ma) or (SA[-i-1] and SA[-i-1] < mt): ans = 0 print(ans) if __name__ == '__main__': main()
s046161952
p03957
u961867404
1477285697
Python
PyPy3 (2.4.0)
py
Runtime Error
201
38384
931
H , W = map(int,input().split()) table = [input() for _ in range(H)] def memo_rec(a,b,i,j, memo): if a == H or b == H: return 0 if memo[a][b] > -1: return memo[a][b] ret = 0 tmp = 0 memo[a][b] = min(memo_rec(a+1,b,i,j, memo= memo), memo_rec(a,b+1,i,j,memo=memo)) + cache[a][b] # print("(i,j) = (%d,%d) memo[%d][%d] = %d"% (i,j,a,b,memo[a][b])) return memo[a][b] ans = 0 for i in range(W-1): # print("%d,%d"%(i,i+1)) memo = [[-1 for _ in range(H)] for _ in range(H)] cache = [[-1 for _ in range(H+1)] for _ in range(H+1)] for a in range(H,-1,-1): for b in range(H,-1,-1): if a == H or b == H: cache[a][b] = 0 elif table[H-a-1][i] == table[H-b-1][i+1]: cache[a][b] = cache[a+1][b+1] + 1 else : cache[a][b] = cache[a+1][b+1] ans += (memo_rec(0,0,i,i+1,memo)) print (ans)
s984369310
p03957
u502175663
1477281561
Python
Python (3.4.3)
py
Runtime Error
23
3064
754
k_t = input().split() k = int(k_t[0]) t = int(k_t [1]) t_amount = input().split(' ') while True: if t == 1: max = k break max = 0 for i in range(t-1): if t_amount[i+1] >= t_amount [i]: max = t_amount[i+1] elif max == 0: max = t_amount[0] t_amount.remove(max) max2 = 0 for i in range(t-2): if t_amount[i+1] >= t_amount [i]: max2 = t_amount[i+1] elif max2 == 0 : max2 = t_amount[0] t_amount.remove(max2) if max2 == "0": break else: max = int(max) -1 max2 = int(max2) -1 t_amount.append(str(max)) t_amount.append(str(max2)) if max == "0": print(0) else: print(int(max)-1)
s369934970
p03957
u813098295
1477281226
Python
Python (3.4.3)
py
Runtime Error
23
3064
778
N = int(raw_input()) T = map(int, raw_input().split()) A = map(int, raw_input().split()) ans = 1 mod = 10 ** 9 + 7 if T[N - 1] != A[0]: print (0) exit() for i in xrange(N): if i == 0 or i == N - 1: continue elif T[i] > T[i-1]: if A[i] < T[i] and A[i] == A[i + 1]: print (0) exit() elif A[i] != T[i] and A[i] != A[i + 1]: print (0) exit() else: if T[i] == A[i]: if A[i] == A[i + 1]: ans *= T[i] elif T[i] > A[i]: if A[i] == A[i + 1]: ans *= A[i] else: if A[i] == A[i + 1]: ans *= T[i] else: print (0) exit() print (ans % mod)
s372618448
p03957
u436484848
1477277341
Python
Python (3.4.3)
py
Runtime Error
23
3064
489
def read(): return [int(i) for i in input().split(" ")] N = int(input()) T = read() A = read() L = [0] * N unknowL = [0] * N tempT, tempA = 0, 0 for i in range(N): if(T[i] > tempT): tempT = L[i] = T[i] else: unknowL[i] = T[i] for i in range(N-1, -1, -1): if(A[i] > tempA): if(L[i] != 0 and L[i] != A[i]): print(0) exit() tempA = L[i] = A[i] unknowL[i] = 0 else: unknowL[i] = min(unknowL[i], A[i]) P = 1 for i in unknowL: if(i != 0): P *= i print(P % (10**9 +7))
s564981442
p03957
u619384481
1477276304
Python
Python (2.7.6)
py
Runtime Error
16
2568
173
ini=raw_input() a=list(ini) check=0 if "C" in list and "F" in list: if list.index("C")<list.index("F"): check=1 if check==1: print "Yes" else: print "No"
s481740235
p03957
u664481257
1477276013
Python
Python (3.4.3)
py
Runtime Error
23
3192
1778
def read_input(): l_1 = input() day = int(l_1.split(" ")[0]) num_cake = [int(i) for i in input().split(" ")] return day, num_cake def get_max_index(target_list): return [i for i, j in enumerate(target_list) if j == max(target_list)] def get_second_max_index(target_list): return [i for i, j in enumerate(target_list) if j == list(sorted(set(target_list), reverse=True))[1]] def mog(day, num_cake): """ >>> mog(7, [3,2,2]) 0 >>> mog(6, [1,4,1]) 1 >>> mog(100, [100]) 99 """ printed = False previous_index = -1 for i in range(0, day): # print("num_cake: ", num_cake) # print("previous_index: ",previous_index) ate_flag = False mog_maybe_index = get_max_index(num_cake) # print("mog_maybe_index: {0}".format(mog_maybe_index)) for n in mog_maybe_index: if n == previous_index: continue else: num_cake[n] = num_cake[n] - 1 ate_flag = True previous_index = n break if ate_flag is False: try: mog_ext = get_second_max_index(num_cake) # print("mog_ext", mog_ext) if num_cake[mog_ext[0]] == 0: printed = True print(max(num_cake)) break except IndexError: print(max(num_cake)) printed = True break num_cake[mog_ext[0]] = num_cake[mog_ext[0]] - 1 previous_index = mog_ext[0] if printed is False: print(0) if __name__ == "__main__": #import doctest #doctest.testmod() day, num_cake = read_input() mog(day, num_cake)
s377671973
p03957
u469202254
1477275698
Python
Python (2.7.6)
py
Runtime Error
16
2568
273
s = input() first_letter = 'C' second_letter = 'F' found = False for l in s: if l == first_letter: for l in s: if l == second_letter: print "Yes" break if found: break if not found: print "No"
s893184611
p03957
u664481257
1477275528
Python
Python (3.4.3)
py
Runtime Error
282
8812
1560
def read_input(): l_1 = input() day = int(l_1.split(" ")[0]) num_cake = [int(i) for i in input().split(" ")] return day, num_cake def get_max_index(target_list): return [i for i, j in enumerate(target_list) if j == max(target_list)] def get_second_max_index(target_list): return [i for i, j in enumerate(target_list) if j == list(sorted(set(target_list), reverse=True))[1]] def mog(day, num_cake): """ >>> mog(7, [3,2,2]) 0 >>> mog(6, [1,4,1]) 1 >>> mog(100, [100]) 99 """ printed = False previous_index = -1 for i in range(0, day): # print(num_cake) # print(previous_index) ate_flag = False mog_maybe_index = get_max_index(num_cake) # print("mog_maybe_index: {0}".format(mog_maybe_index)) for n in mog_maybe_index: if n == previous_index: continue else: num_cake[n] = num_cake[n] - 1 ate_flag = True previous_index = n break if ate_flag is False: try: mog_ext = get_second_max_index(num_cake) # print("mog_ext", mog_ext) except IndexError: print(max(num_cake)) printed = True break num_cake[mog_ext[0]] = num_cake[mog_ext[0]] - 1 previous_index = mog_ext[0] if printed is False: print(0) if __name__ == "__main__": import doctest doctest.testmod() mog(read_input())
s442378596
p03957
u177721681
1477274936
Python
Python (2.7.6)
py
Runtime Error
16
2568
233
import sys s = sys.stdin.readline().strip() c_find = Fasle f_find = False for c in s: if c_find: if c == 'F': print 'Yes' exit(0) else: if c == 'C': c_find = True print 'No'
s123257496
p03957
u867933941
1477274793
Python
Python (2.7.6)
py
Runtime Error
16
2696
978
N = input() T = map(int,raw_input().split(" ")) A = map(int,raw_input().split(" ")) note = [1 for i in range(N)] fx = [0 for i in range(N)] def solve(): global note if T[-1] != A[0]: return 0 prev = 0 for i in range(N): if prev > T[i]: return 0 elif prev == T[i]: note[i] = prev else: note[i] = 1 prev = T[i] fx[i] = T[i] prev = 0 for i in range(N-1,-1,-1): if prev > A[i]: return 0 elif prev == A[i]: if not fx[i]: note[i] = min(note[i],prev) else: if fx[i] > A[i]: return 0 else: if fx[i] and fx[i] != A[i]: return 0 note[i] = 1 prev = A[i] ans = 1 for i in range(N): if not fx[i]: ans = (ans * note[i])%(10**9+7) return ans print solve()
s691312661
p03957
u657357805
1477274729
Python
Python (3.4.3)
py
Runtime Error
23
3064
500
import sys n = int(input()) t = [int(x) for x in input().split()] a = [int(x) for x in input().split()] if t[n-1]!=a[0]: print(0) sys.exit() m =[] for i in range(n): mx = min(t[i],a[i]) mn = 1 if i == 0: mn = t[i] elif i == n-1: mn = a[i] else : if t[i]!=t[i-1]: mn=t[i] if a[i]!=a[i+1]: mn=a[i] m.append([mx,min(mx,mn)]) ans = 1 for i in range(n): ans = (ans * (m[i][0]-m[i][1]+1))%(10**9+7) print(ans)
s935122236
p03957
u024016758
1477273823
Python
Python (2.7.6)
py
Runtime Error
16
2696
746
def getCakeRepeats(cakes): front_iter = 0 back_iter = len(cakes) - 1 while back_iter > front_iter: if cakes[back_iter] < cakes[front_iter]: cakes[front_iter] -= cakes[back_iter] cakes[back_iter] = 0 back_iter -= 1 elif cakes[back_iter] > cakes[front_iter]: cakes[back_iter] -= cakes[front_iter] cakes[front_iter] = 0 front_iter += 1 else: cakes[back_iter] = 0 cakes[front_iter] = 0 back_iter -= 1 front_iter += 1 return max(0, sum(cakes) - 1) if __name__ == "__main__": setup = raw_input() cakes = list(map(int, raw_input().split())) print getCakeRepeats(sorted(cakes))
s766020342
p03957
u525261764
1477273608
Python
Python (2.7.6)
py
Runtime Error
16
2568
232
import os import sys teststr = sys.argv[1] ch1 = 'C' ch2 = 'F' flag = 0 for c in teststr: print c if ch1 == c: flag = flag+1 if ch2 == c: flag = flag+1 if flag >= 2: print 'Yes' else: print 'No'
s251225789
p03957
u191667127
1477273479
Python
Python (3.4.3)
py
Runtime Error
23
3192
375
s = input().split() size = [] for n in s: size.append(int(n)) s2 = input().split() ss = [] for n in s2: ss.append(int(n)) if size[0] % 2 == 0: k = size[0]/2 else: k = (size[0] + 1) /2 l = 0 m = 3 for i in ss: if i > k: l+=1 while i > int((m-1) * size[0] / m) and m <= size[0]: m+=1 l+=1 print (l)
s634536006
p03957
u525261764
1477273426
Python
Python (2.7.6)
py
Runtime Error
19
2696
92
import os import sys teststr = sys.argv[1] ch1 = 'C' ch2 = 'F' flag = 0 if True: print 'Yes'
s292931070
p03957
u525261764
1477273376
Python
Python (2.7.6)
py
Runtime Error
16
2568
104
import os import sys teststr = sys.argv[1] ch1 = 'C' ch2 = 'F' flag = 0 if len(teststr): print 'Yes'
s633542145
p03957
u525261764
1477273030
Python
Python (2.7.6)
py
Runtime Error
16
2568
243
import os import sys teststr = sys.argv[1] ch1 = 'C' ch2 = 'F' flag = 0 for c in teststr: if ch1 == c: flag = flag+1 else: flag = flag+1 if flag >= 2: print 'Yes' else: print 'No'
s451057182
p03957
u525261764
1477272851
Python
Python (2.7.6)
py
Runtime Error
16
2568
211
import os import sys teststr = sys.argv[1] ch1 = 'C' ch2 = 'F' flag = 0 for c in teststr: if ch1 == c: flag = flag+1 else: flag = flag+1 if flag >= 2: print 'Yes' else: print 'No'
s214324791
p03957
u525261764
1477272789
Python
Python (2.7.6)
py
Runtime Error
16
2568
202
import os import sys teststr = sys.argv[1] ch1 = 'C' ch2 = 'F' for c in teststr: if ch1 == c: flag = flag+1 else: flag = flag+1 if flag >= 2: print 'Yes' else: print 'No'
s998314950
p03957
u293703028
1477272547
Python
Python (3.4.3)
py
Runtime Error
25
3068
151
s = input() if "C" in s and "F" in s: a = s.lindex("C") b = s.rindex("F") if a < b: print("Yes") else: print("No") else: print("No")
s620022336
p03957
u177721681
1477272504
Python
Python (2.7.6)
py
Runtime Error
16
2696
743
import sys def range_union(al,ah,bl,bh): cl = max(al,bl) ch = min(ah,bh) if cl > ch: return 0 else: return ch-cl +1 N = int(sys.stdin.readline()) T = map(int,sys.stdin.readline().strip().split()) A = map(int,sys.stdin.readline().strip().split()) p = 1 for i in xrange(1,N-1): if T[i-1] < T[i]: Tl = T[i] Th = T[i] elif T[i-1] == T[i]: Tl = 1 Th = T[i] else: p = 0 break if A[i] > A[i+1]: Al = A[i] Ah = A[i] elif A[i+1] == A[i]: Al = 1 Ah = A[i] else: p = 0 break r = range_union(Tl,Th,Al,Ah) if not r: p = 0 break else: p = p*r print p % 1000000007
s580134391
p03957
u227254381
1477272451
Python
Python (3.4.3)
py
Runtime Error
22
3064
152
str = raw_input() c = False for i in range(0, len(str)): if str[i] == "C": c = True if str[i] == "F" and c == True: print "Yes" print "No"
s013376858
p03957
u177721681
1477272414
Python
Python (2.7.6)
py
Runtime Error
16
2696
744
import sys def range_union(al,ah,bl,bh): cl = max(al,bl) ch = min(ah,bh) if cl > ch: return 0 else: return ch-cl +1 N = int(sys.stdin.readline()) T = map(int,sys.stdin.readline().strip().split()) A = map(int,sys.stdin.readline().strip().split()) p = 1 for i in xrange(1,N-1): if T[i-1] < T[i]: Tl = T[i] Th = T[i] elif T[i-1] == T[i]: Tl = 1 Th = T[i] else: p = 0 break if A[i] > A[i+1]: Al = A[i] Ah = A[i] elif A[i+1] == A[i]: Al = 1 Ah = A[i] else: p = 0 break r = range_union(Tl,Th,Al,Ah) if not r: p = 0 break else: p = p*r print p % 1000000007
s280032020
p03957
u227254381
1477272402
Python
Python (3.4.3)
py
Runtime Error
22
3064
151
str = raw_input() c = False for i in range(0, len(str)): if str[i] == "c": c = True if str[i] == "f" and c == True: print "YES" print "NO"
s196010226
p03957
u525261764
1477272365
Python
Python (2.7.6)
py
Runtime Error
16
2568
312
import os import sys def main(teststr): ch1 = 'C' ch2 = 'F' for c in teststr: if ch1 == c: flag = flag+1 else: flag = flag+1 if flag >= 2: print 'Yes' else: print 'No' if __name__=='__main__': teststr = sys.argv[1] main(teststr)
s708237370
p03957
u227254381
1477272243
Python
Python (3.4.3)
py
Runtime Error
22
3064
164
str = raw_input() c = False f = False for i in range(0, len(str)): if str[i] == "c": c = True if str[i] == "f" and c == True: return True return False
s160493982
p03957
u525261764
1477272051
Python
Python (2.7.6)
py
Runtime Error
17
2568
293
def main(teststr): ch1 = 'C' ch2 = 'F' for c in teststr: if ch1 == c: flag = flag+1 else: flag = flag+1 if flag >= 2: print 'Yes' else: print 'No' if __name__=='__main__': teststr = sys.argv[1] main(teststr)
s672962290
p03957
u901307908
1477271523
Python
Python (3.4.3)
py
Runtime Error
23
3064
261
s = input() cl = [] fl = [] for i, c_test in zip(range(len(s)), s): if c_test == 'C': cl.append(i) for i, f_test in zip(range(len(s)), s): if f_test == 'F': fl.append(i) if max(fl) > min(cl): print("Yes") else: print("No")
s520057190
p03957
u227254381
1477271439
Python
Python (3.4.3)
py
Runtime Error
22
3064
164
str = raw_input() c = false f = false for i in range(0, len(str)): if str[i] == "c": c = true if str[i] == "f" and c == true: return true return false
s351238714
p03957
u227254381
1477271246
Python
Python (3.4.3)
py
Runtime Error
22
3068
180
str = raw_input() is_c_found = false is_f_found = false for i in range(0, len(str)): if str[i] == "c": is_c_found = true if str[i] == "f" and is_c_found: return true return false
s112875630
p03957
u114277042
1477271086
Python
Python (2.7.6)
py
Runtime Error
764
6260
192
from random import random import math import re import fractions S = raw_input() pc = S.index("C") pf = S.rindex("F") if pc > -1 and pf > -1 and pc < pf: print "Yes" else: print "No"
s508269840
p03957
u406648710
1477271049
Python
Python (2.7.6)
py
Runtime Error
16
2572
155
s = raw_input() flag = 0 for i in s: if flag == 0 and i == 'C': flag = 1 elif: flag == 1 and i == 'F': flag = 2 print 'Yes' if flag == 2 else 'No'
s316446539
p03957
u132291455
1477271016
Python
Python (2.7.6)
py
Runtime Error
15
2568
167
import sys s=raw_input() flag=False for j in range(s): if s[j]=='C': flag=True if s[j]=='F' and flag: print "Yes" sys.exit() print "No"
s472647627
p03958
u162612857
1598068077
Python
Python (3.8.2)
py
Runtime Error
20
9144
174
k, t = list(map(int, input().split())) nums = list(map(int, input().split())) m = max(nums) rest = k - m if max - rest - 1 > 0: print(max - rest - 1) else: print(0)
s207553329
p03958
u036104576
1597549611
Python
Python (3.8.2)
py
Runtime Error
21
8740
134
K, T = map(int, input().split()) A = list(map(int, input().split())) A = sorted(A, reverse=True) print(max(0, A[0] - 1 - sum(A[1:]))
s088027586
p03958
u044220565
1597273671
Python
Python (3.8.2)
py
Runtime Error
21
9016
1275
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy from collections import deque #from decimal import Decimal INF = 1 << 50 def run(): K, T, *A = map(int, read().split()) A = sorted(A) A = deque(A) high, low = 0, 0 last = None while A: #print(A) if high == 1: A.appendleft(1) high = A.pop() if not high: high = A.pop() if high == 1:break elif not low: low = A.popleft() #print(high, low) val = min(low, high-1) if not val: last = None else: last = 'LOW' high -= val low -= val #print('-->', high, low) if high == 1 if last == None: print(max(low-high-1, 0)) return else: print(max(low - 1, 0))) return print(high - 1 + max(low - 1, 0)) if __name__ == "__main__": run()
s352984650
p03958
u813174766
1593834841
Python
Python (3.8.2)
py
Runtime Error
26
8936
89
n,k=map(int,input().split()) a=list(map(int,input()split())) s=max(a) print(max(2*s-n-1))
s315498697
p03958
u026155812
1592511254
Python
Python (3.4.3)
py
Runtime Error
23
3064
405
import sys import heapq K, T = map(int, input().split()) m = [-int(i) for i in input().split()] heapq.heapify(m) if T == 1: print(K-1) sys.exit() while len(m) > 0: l = heapq.heappop(m) if len(m) == 0: heapq.heappush(m, l) break r = heapq.heappop(m) if r+1 == 0: continue else: heapq.heappush(m, l+1) heapq.heappush(m, r+1) print(-m[0])
s813410950
p03958
u830054172
1590957237
Python
Python (3.4.3)
py
Runtime Error
19
2940
151
k, t = map(int, input().split()) a = list(map(int, input().split())) ans = max(a) for i in a: if i != max(a): ans -= i print(max(0, ans)
s467706795
p03958
u830054172
1590957213
Python
Python (3.4.3)
py
Runtime Error
17
2940
144
k, t = map(int, input().split()) a = list(map(int, input().split())) ans = max(a) for i in a: if i != max(a): ans -= i print(max(0, ans)
s994591449
p03958
u979552932
1590855637
Python
Python (3.4.3)
py
Runtime Error
22
3060
388
from sys import stdin def main(): import heapq input = stdin.readline input() a = [-1 * int(i) for i in input().split()] heapq.heapify(a) while len(a) > 1: u = heapq.heappop(a) v = heapq.heappop(a) if u + 1 < 0: heapq.heappush(a, u + 1) if v + 1 < 0: heapq.heappush(a, v + 1) print(abs(a[0] + 1)) main()
s737044807
p03958
u652656291
1589666194
Python
Python (3.4.3)
py
Runtime Error
17
2940
105
k,t = map(int,input().split()) A = list(map(int,input().split())) at = max(A) print(max(2*at−1−k,0))
s601115392
p03958
u652656291
1589665992
Python
Python (3.4.3)
py
Runtime Error
17
2940
109
k,t = map(int,input().split()) A = list(map(int,input().split())) at = max(A) print(max(at−1−(k−at),0))
s107180012
p03958
u408375121
1589548842
Python
Python (3.4.3)
py
Runtime Error
17
3064
241
k, t = map(int, input().split()) a = list(map(int, input().split())) a.sort() double_cnt = 0 total = 0 for i in range(t): b = a[i] - bouble_cnt c = total - (bouble_cnt + 1) + 2 bouble_cnt = max(0, b-c) total += a[i] print(bouble_cnt)
s934900261
p03958
u585482323
1587217336
Python
PyPy3 (2.4.0)
py
Runtime Error
244
46040
1124
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): k,t = LI() a = LI() q = [] for i in a: heappush(q,-i) while len(q) > 1: x = heappop(q) if not q: heappush(q,x) break y = heappop(q) x += 1 y += 1 if x: heappush(q,x) if y: heappush(q,y) print(-q[0]-1) return #Solve if __name__ == "__main__": solve()
s704968605
p03958
u585482323
1587217277
Python
PyPy3 (2.4.0)
py
Runtime Error
252
46040
1062
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): k,t = LI() a = LI() q = [] for i in a: heappush(q,-i) while len(q) > 1: x = heappop(q) y = heappop(q) x += 1 y += 1 if x: heappush(q,x) if y: heappush(q,y) print(-q[0]-1) return #Solve if __name__ == "__main__": solve()
s615131655
p03958
u539517139
1583399995
Python
Python (3.4.3)
py
Runtime Error
17
2940
123
k,t=map(int,input().split()) l=[0]*t a=list(map(int,input().split())) for i in a: l[i-1]+=1 print(max(0,max(l)-(k+1)//2))
s319356279
p03958
u898967808
1582410602
Python
Python (3.4.3)
py
Runtime Error
18
2940
98
k,t = map(int,input().split()) A = list(map(int,input().split())) print(max(2*max(A) - sum(A) -1))
s047041362
p03958
u375616706
1581121028
Python
Python (3.4.3)
py
Runtime Error
18
3060
272
import heapq K, T = map(int, input().split()) L = list(map(lambda x: -int(x), input().split())) heapq.heapify(L) while L and len(L) > 1: a = heapq.heappop(L) b = heapq.heappop(L) r = b-a if r > 0: heapq.heappush(L, -r) print(-heapq.heappop(L)-1)
s294192521
p03958
u608088992
1578148665
Python
Python (3.4.3)
py
Runtime Error
17
2940
149
K, T = map(int, input().split()) A = [int(a) for a in input().split()] A.sort() sumA = 0 for a in A[:N-1]: sumA += a print(max(0, A[N-1] - 1 - sumA))
s146203457
p03958
u116233709
1575479024
Python
Python (3.4.3)
py
Runtime Error
18
3060
152
k,t=map(int,input().split()) a=[] for i in range(t): a.append(int(input())) if max(a)*2-sum(a)-1<0: print(0) else: print(max(a)*2-sum(a)-1)
s878148473
p03958
u668503853
1570242962
Python
Python (3.4.3)
py
Runtime Error
17
2940
94
K,T=map(int,input().split()) A=list(map(int,input().split())) M=max(A) print(max(A-1-(K-A),0))
s549372261
p03958
u598229387
1568006809
Python
Python (3.4.3)
py
Runtime Error
34
3060
199
k,t=map(int,input().split()) a=[int(i) for i in input().split()] a=sorted(a,reverse=True) while True: if a[1]==0: ans=max(a[0]-1,0) break a[0]-=1 a[1]-=1 a=sorted(a,reverse=True) print(ans)
s369043429
p03958
u814986259
1567040674
Python
Python (3.4.3)
py
Runtime Error
17
3060
168
K,T = map(int,input().split()) a = list(map(int,input().split())) a = sorted(a,reverse = True) ans = a.pop(0) - sum(a) - 1 if a >= 0: print(ans) else: print(0)
s753589406
p03958
u444349080
1565102894
Python
Python (3.4.3)
py
Runtime Error
17
2940
450
#include <iostream> #include <math.h> #include <fstream> #include <algorithm> #include <string> #include <string.h> #include <queue> #include <vector> #include <set> #include <map> using namespace std; long long int maxi(long long int A, long long int B) { return (A > B) ? A : B; } int main() { int K, T, a, maxi = -1; cin >> K >> T; for (int i = 0; i < T; i++) { cin >> a; maxi = max(a, maxi); } cout << max(0, maxi - (K - maxi) - 1); }
s538787223
p03958
u572144347
1558069091
Python
Python (3.4.3)
py
Runtime Error
23
3316
337
K,T=map(int,input().split()) A=list(map(int,input().split())) from heapq import heappush,heappop from collections import deque A.sort(reverse=True) d=deque(A) d2=deque(A) ans=A[0] mod=1 while d: if len(d)==1: print(d[0]-1) a=d.pop() b=d.popleft() if not a==1: d.append(a-1) if not b==1: d.appendleft(b-1)
s090733527
p03958
u572144347
1558068664
Python
Python (3.4.3)
py
Runtime Error
17
3064
298
K,T=map(int,input.split()) A=list(map(int,input().split())) from heapq import heappush,heappop from collections import deque A.sort(reverse=True) d=deque(A) while d: if len(d)==1: print(d-1) exit() a=d.pop() b=d.popleft() if not a==1: d.append(a-1) d.appendleft(b-1)
s093641122
p03958
u123756661
1555567180
Python
Python (3.4.3)
py
Runtime Error
17
3064
348
k,t=map(int,input().split()) l=[int(i) for i in input().split()] x=[int(i) for i in l] nin=min(x) nen=t while 1: w=[] for i in x: if i-nin!=0: w.append(i-nin) x=[i for i in w] nin=min(x) if len(x)==1: print(x[0]-nin) exit() elif len(x)==0: print(0) exit() nen=len(x)
s414219710
p03958
u123756661
1555567045
Python
Python (3.4.3)
py
Runtime Error
17
3064
295
k,t=map(int,input().split()) l=[int(i) for i in input().split()] x=[int(i) for i in l] nin=min(x) nen=t while 1: w=[] for i in x: if i-nin!=0: w.append(i-nin) x=[i for i in w] nin=min(x) if len(x)<=1: print(x[0]-nin) exit() nen=len(x)
s585907563
p03958
u123756661
1555566855
Python
Python (3.4.3)
py
Runtime Error
18
3064
278
k,t=map(int,input().split()) l=[int(i) for i in input().split()] x=[int(i) for i in l] nin=min(x) nen=t while 1: w=[] for i in x: if i-nin!=0: w.append(i-nin) x=[i for i in w] nin=min(x) if len(x)<=1: print(x-nin) nen=len(x)
s711320870
p03958
u123756661
1555566823
Python
Python (3.4.3)
py
Runtime Error
17
3064
278
k,t=map(int,input().split()) l=[int(i) for i in input().split()] x=[int(i) for i in l] nin=min(x) nen=t while 1: w=[] for i in x: if i-nin!=0: w.append(i-nin) x=[i for i in w] nin=min(x) if len(x)<=1: print(x-nin) nen=len(x)
s023946901
p03958
u859897687
1554833651
Python
Python (3.4.3)
py
Runtime Error
17
2940
122
k,t=map(int,input().split()) l=list(map(int,input().split())) if len(l)==n: print(n-1) else: print(max(0,max(l)//2-n))
s675853764
p03958
u859897687
1554833565
Python
Python (3.4.3)
py
Runtime Error
17
2940
87
k,t=wap(int,input().split()) l=list(map(int,input().split())) print(max(0,max(l)//2-n))
s037287138
p03958
u766407523
1525748669
Python
Python (3.4.3)
py
Runtime Error
17
2940
103
def inpl(): return list(map(int, input().split())) K, T = inpl() a = inpl() print(max(max(a)*2-n-1, 0))
s366911646
p03958
u976162616
1487398961
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38384
641
import heapq if __name__ == "__main__": K,T = map(int, input().split()) data = list(map(int, input().split())) cake = [] for i,x in enumerate(data): cake.append([x, i]) heapq._heapify_max(cake) while (len(cake) > 1): heapq._heapify_max(cake) p = heapq.heappop(cake) q = heapq.heappop(cake) # print (p,q) p[0] -= 1 q[0] -= 1 if p[0] > 0: heapq.heappush(cake, p) if q[0] > 0: heapq.heappush(cake, q) result = 0 if len(cake) > 0: t = heapq.heappop(cake) result = t[0] print (max(0, result - 1))
s675536877
p03958
u976162616
1487398304
Python
Python (3.4.3)
py
Runtime Error
18
3064
601
import heapq if __name__ == "__main__": K,T = map(int, input().split()) data = list(map(int, input().split())) cake = [] for i,x in enumerate(data): cake.append([x, i]) heapq._heapify_max(cake) while (len(cake) > 1): p = heapq._heappop_max(cake) q = heapq._heappop_max(cake) p[0] -= 1 q[0] -= 1 if p[0] > 0: heapq.heappush(cake, p) if q[0] > 0: heapq.heappush(cake, q) result = 0 if len(cake) > 0: t = heapq._heappop_max(cake) result = t[0] print (max(0, result - 1))
s155121601
p03958
u976162616
1487398191
Python
Python (3.4.3)
py
Runtime Error
18
3064
570
import heapq if __name__ == "__main__": K,T = map(int, input().split()) data = list(map(int, input().split())) cake = [] for i,x in enumerate(data): cake.append([x, i]) heapq._heapify_max(cake) while (len(cake) > 1): p = heapq._heappop_max(cake) q = heapq._heappop_max(cake) p[0] -= 1 q[0] -= 1 if p[0] > 0: heapq.heappush(cake, p) if q[0] > 0: heapq.heappush(cake, q) result = 0 if len(cake) > 0: result = cake[0][0] print (max(0, result - 1))
s242108713
p03958
u976162616
1487398009
Python
Python (3.4.3)
py
Runtime Error
18
3064
586
import heapq if __name__ == "__main__": K,T = map(int, input().split()) data = list(map(int, input().split())) data.sort() cake = [] for i,x in enumerate(data): cake.append([x, i]) heapq._heapify_max(cake) while (len(cake) > 1): p = heapq._heappop_max(cake) q = heapq._heappop_max(cake) p[0] -= 1 q[0] -= 1 if p[0] > 0: heapq.heappush(cake, p) if q[0] > 0: heapq.heappush(cake, q) result = 0 if len(cake) > 0: result = cake[0][0] print (max(0, result - 1))
s096173015
p03958
u976162616
1487397980
Python
PyPy3 (2.4.0)
py
Runtime Error
172
38640
586
import heapq if __name__ == "__main__": K,T = map(int, input().split()) data = list(map(int, input().split())) data.sort() cake = [] for i,x in enumerate(data): cake.append([x, i]) heapq._heapify_max(cake) while (len(cake) > 1): p = heapq._heappop_max(cake) q = heapq._heappop_max(cake) p[0] -= 1 q[0] -= 1 if p[0] > 0: heapq.heappush(cake, p) if q[0] > 0: heapq.heappush(cake, q) result = 0 if len(cake) > 0: result = cake[0][0] print (max(0, result - 1))
s147815841
p03958
u098968285
1477276385
Python
PyPy3 (2.4.0)
py
Runtime Error
413
41068
637
# def makelist(n, m): # return [[0 for i in range(m)] for j in range(n)] # n = int(input()) # a, b = map(int, input().split()) # s = input() K, T = map(int, input().split()) hoge = list(map(int, input().split())) a = [0]*T for i in range(T): a[i] = (hoge[i], i) if T == 1: print(K-1) else: a.sort() a[-1] = (a[-1][0] - 1, a[-1][1]) pre = a[-1][1] while True: a.sort() if a[-1][0] == 0: print(0) break elif a[-1][1] != pre: a[-1] = (a[-1][0] - 1, a[-1][1]) pre = a[-1][1] else: if a[-2][0] == 0: print(a[-1][1]) a[T+2] break else: a[-2] = (a[-2][0] - 1, a[-2][1]) pre = a[-2][1]
s157435580
p03958
u098968285
1477276275
Python
PyPy3 (2.4.0)
py
Runtime Error
395
40940
658
# def makelist(n, m): # return [[0 for i in range(m)] for j in range(n)] # n = int(input()) # a, b = map(int, input().split()) # s = input() K, T = map(int, input().split()) hoge = list(map(int, input().split())) a = [0]*T for i in range(T): a[i] = (hoge[i], i) if T == 1: print(K-1) else: a.sort() a[-1] = (a[-1][0] - 1, a[-1][1]) pre = a[-1][1] while True: a.sort() if a[-1][0] == 0: print(0) break elif a[-1][1] != pre: a[-1] = (a[-1][0] - 1, a[-1][1]) pre = a[-1][1] else: if a[-2][0] == 0: print(a[-1][1]) raise NameError('error') break else: a[-2] = (a[-2][0] - 1, a[-2][1]) pre = a[-2][1]
s372991360
p03958
u668253056
1477272984
Python
Python (3.4.3)
py
Runtime Error
22
3064
323
input = raw_input().split(' ') K = int(input[0]) T = int(input[1]) input = raw_input().split(' ') max_num = 0 sum_num = 0 for i in range(0, T): temp = int(input[i]) if max_num < temp: max_num = temp sum_num += temp if max_num <= sum_num - max_num + 1: print "0" else: print max_num - (sum_num - max_num) - 1
s796109219
p03959
u651663683
1600706274
Python
PyPy3 (7.3.0)
py
Runtime Error
1292
252648
64
while True: print(" ".join([str(i) for i in range(10000)]))
s043583647
p03959
u644907318
1598583583
Python
PyPy3 (7.3.0)
py
Runtime Error
126
98476
1022
p = 10**9+7 N = int(input()) T = list(map(int,input().split())) A = list(map(int,input().split())) H = [0 for _ in range(N)] flag = 0 if T[N-1]!=A[0]: flag = 1 if flag==0: indmaxT=0 H[0] = T[0] for i in range(1,N): if T[i]>T[i-1]: H[i] = T[i] if H[i]==hmax: indmaxT = i break indmaxA = N-1 H[N-1] = A[N-1] for i in range(N-2,-1,-1): if A[i]>A[i+1]: H[i]=A[i] if H[i]==hmax: indmaxA = i break if indmaxA<indmaxT: flag = 1 if flag==1: print(0) else: hmax = max(H) cnt = 1 cur = 0 indH=0 for i in range(1,indmaxT): if H[i]==0: cnt = (cnt*H[cur])%p elif H[i]>0: cur = i cur = N-1 for i in range(N-2,indmaxA,-1): if H[i]==0: cnt = (cnt*H[cur])%p elif H[i]>0: cur = i for i in range(indmaxT+1,indmaxA): cnt = (cnt*hmax)%p print(cnt)
s991525573
p03959
u644907318
1598582474
Python
PyPy3 (7.3.0)
py
Runtime Error
122
98796
1134
p = 10**9+7 N = int(input()) T = list(map(int,input().split())) A = list(map(int,input().split())) H = [0 for _ in range(N)] flag = 0 if T[N-1]!=A[0]: flag = 1 if flag==0: H[0] = T[0] for i in range(1,N): if T[i]<T[i-1]: flag = 1 break if T[i]>T[i-1]: H[i] = T[i] if flag==0: H[N-1] = A[N-1] for i in range(N-2,-1,-1): if A[i]<A[i+1]: flag = 1 break if A[i]>A[i+1]: if H[i]>0 and H[i]!=A[i]: flag = 1 break else: H[i]=A[i] if flag==1: print(0) else: hmax = max(H) cnt = 1 cur = 0 for i in range(1,N): if H[i]==hmax: indH=i break if H[i]==0: cnt = (cnt*H[cur])%p elif H[i]>0: cur = i cur = N-1 for i in range(N-2,-1,-1): if H[i]==hmax: indA = i break if H[i]==0: cnt = (cnt*H[cur])%p elif H[i]>0: cur = i for i in range(indH+1,indA): cnt = (cnt*hmax)%p print(cnt)
s910866562
p03959
u222668979
1597773224
Python
PyPy3 (7.3.0)
py
Runtime Error
127
98720
527
n = int(input()) t = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 ans = 1 for i in range(1, n): if t[i] == t[i - 1]: ans = ans * t[i] % mod if t[i] == a[i]: l = i break for i in range(n - 1)[::-1]: if a[i] == a[i + 1]: ans = ans * a[i] % mod if t[i] == a[i]: r = i break if n == 1: print(int(t == a)) elif t[l] != max(t) or a[r] != max(a): print(0) else: print(ans * pow(t[l], max(r - l - 1, 0), mod) % mod)
s137505424
p03959
u790710233
1591505467
Python
Python (3.4.3)
py
Runtime Error
166
19172
701
MOD = 10**9+7 n = int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) n_cases = [0]*n n_cases[0] = n_cases[-1] = 1 height = [0]*n if T[-1] != A[0]: print(0) exit() height[0] = T[0] height[-1] = A[-1] for i, (t1, t2) in enumerate(zip(T, T[1:]), 1): if t1 != t2: n_cases[i] = 1 height[i] = t2 for i, (a1, a2) in enumerate(zip(A[::-1], A[::-1][1:]), 2): if a1 != a2: n_cases[-i] = 1 assert height[-i] == a2 or height[-i] == 0 height[-i] = a2 for i, (t, a) in enumerate(zip(T, A)): if n_cases[i]: continue n_cases[i] = min(t, a) ans = 1 for x in n_cases: ans *= x ans %= MOD print(ans)
s255284965
p03959
u408375121
1589576218
Python
Python (3.4.3)
py
Runtime Error
169
18972
649
n = int(input()) t = list(map(int, input().split())) a = list(map(int, input().split())) MOD = 10**9 + 7 t_max = max(t) for i in range(n): if a[i] == t_max: max_ind = i break if t[max_ind] != a[max_ind] or t[-1] != a[0]: print(0) else: idx = [] before = 0 for i in range(n): if before == t[i]: idx .append(i) before = t[i] if len(idx) == 0: print(1) else: new_idx = [] for j in idx: if j < n-1 and a[j] == a[j+1]: new_idx.append(j) if len(new_idx) == 0: print(0) else: ans = 1 for k in new_idx: ans *= min(t[k], a[k]) ans %= MOD print(ans)
s922414597
p03959
u408375121
1589574452
Python
Python (3.4.3)
py
Runtime Error
125
19136
488
n = int(input()) t = list(map(int, input().split())) a = list(map(int, input().split())) MOD = 10**9 + 7 if t[0] != a[-1]: print(0) else: idx = [] before = 0 for i in range(n): if before == t[i]: idx.append(i) before = t[i] new_index = [] for j in idx: if j < n-1: if a[j] == a[j+1]: new_index.append(j) if len(new_index) > 0: print(1) else: ans = 1 for k in new_index: ans *= min(t[k], a[k]) ans %= MOD print(ans)
s783342497
p03959
u346308892
1586913526
Python
PyPy3 (2.4.0)
py
Runtime Error
173
38384
1465
input = sys.stdin.readline def acinput(): return list(map(int, input().split(" "))) def II(): return int(input()) mod = 10**9+7 def factorial(n): fact = 1 for integer in range(1, n + 1): fact *= integer return fact def serch(x, count): #print("top", x, count) for d in directions: nx = d+x #print(nx) if np.all(0 <= nx) and np.all(nx < (H, W)): if field[nx[0]][nx[1]] == "E": count += 1 field[nx[0]][nx[1]] = "V" count = serch(nx, count) continue if field[nx[0]][nx[1]] == "#": field[nx[0]][nx[1]] = "V" count = serch(nx, count) return count N=II() t=acinput() a=acinput() st = [[] for i in range(N)] st[0]=[t[0],t[0]] for i in range(1,N): if t[i-1]<t[i]: st[i]=[t[i],t[i]] else: st[i]=[1,st[i-1][1]] sa = [[] for i in range(N)] sa[N-1] = [a[N-1], a[N-1]] for i in reversed(range(N-1)): if a[i] > a[i+1]: sa[i] = [a[i], a[i]] else: sa[i] = [1,sa[i+1][1]] def diff(x): return x[1]-x[0] res=1 for i in range(N): x=max(sa[i])-min(st[i])+1 y=max(st[i])-min(sa[i])+1 #print(x,y,np.diff(sa)) if x<=0 or y<=0: res=0 break res=res* min(x,y,diff(sa[i])+1,diff(st[i])+1) res=res%mod print(res%mod) #print(st) #print(sa)
s944390037
p03959
u779455925
1583960213
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38512
745
"""from collections import * from itertools import * from bisect import * from heapq import * import math from fractions import gcd""" N=int(input()) T=list(map(int,input().split())) A=list(map(int,input().split())) mod=10**9+7 lst=[0 for i in range(N)] lst[0]=T[0] lst[N-1]=A[N-1] if T[N-1]!=A[0]: print(0) exit() for i in range(1,N): if T[i]>T[i-1]: if lst[i] and lst[i]!=T[i]: print(0) exit() lst[i]=T[i] for i in range(N-2,-1,-1): if A[i]>A[i+1]: if lst[i] and lst[i]!=A[i]: print(0) exit() elif not lst[i] and T[i]<A[i] lst[i]=A[i] count=1 for i in range(N): if not lst[i]: count=count*min(T[i],A[i])%mod print(count)
s402285711
p03959
u118642796
1569377612
Python
PyPy3 (2.4.0)
py
Runtime Error
284
83812
503
N = int(input()) T = list(map(int,input().split())) A = list(map(int,input().split())) T_min = [0]*N T_min[0] = T[0] for i in range(1,N): if T[i-1]<T[i]: T_min[i] = T[i] A_min = [0]*N A_min[N-1] = A[N-1] for i in range(N-2,-1,-1): if A[i+1]<A[i]: A_min[i] = A[i] M = [0]*N M_min = [0]*N for i in range(N): M = min(T[i],A[i]) M_min = max(T_min[i],A_min[i]) ans = 1 mod = 10**9+7 for i in range(N): if M[i]<M_min[i]: ans = 0 else: ans*=M[i]+1-M_min[i] ans%=mod print(ans)
s951794344
p03959
u649373416
1556912638
Python
Python (3.4.3)
py
Runtime Error
2104
19136
833
n = int(input()) tli = [ int(it) for it in input().split() ] ali = [ int(it) for it in input().split() ] #print (tli,ali) mav1 = max(tli) mav2 = max(ali) mav = mav1 #print (mav1,mav2) if (mav1!=mav2): print (0) else: mai1 = tli.index(mav) mai2 = n-1-list(reversed(ali)).index(mav) #print (mai1,mai2) if (mai2<mai1): print (0) else: s = 1 tma = -1 for i in range(0,mai1+1): if tli[i]>tma: tma = tli[i] #print ("lt",tma) else: s*=(tli[i]) #print ("l") tma = -1 for i in range(n-1,mai2-1,-1): if ali[i]>tma: tma = ali[i] #print ("rt",tma) else: s*=(ali[i]) #print ("r") if (mai2-mai1>1): for i in range(mai2-mai1-1): s*=mav #print ( s ) print ( s%(1000000007) )
s847523365
p03959
u620480037
1546115931
Python
Python (3.4.3)
py
Runtime Error
284
21824
881
N=int(input()) T=list(map(int,input().split())) A=list(map(int,input().split())) if T[N-1]!=A[0]: print(0) elif N==1: print(1) else: L=[[T[0],0]] for i in range(1,N): if T[i]==T[i-1]: L.append([T[i],1]) else: L.append([T[i],0]) #print(L) if L[len(L)-1][0]>A[len(L)-1]: L[len(L)-1]=[A[len(L)-1],0] else: L[len(L)-1][1][0] for i in range(1,N): if L[len(L)-1-i][0]>=A[len(L)-1-i]: L[len(L)-1-i][0]=A[len(L)-1-i] if A[len(L)-1-i]==A[len(L)-i]: pass else: L[len(L)-1-i][1]=0 if L[len(L)-1-i][0]>L[len(L)-i][0]: L[len(L)-1-i][1]=0 #print(L) ans=1 for i in range(len(L)): if L[i][1]==1: ans*=L[i][0] ans%=(10**9+7) print(ans)
s982246631
p03959
u236127431
1544339397
Python
PyPy3 (2.4.0)
py
Runtime Error
309
84068
511
N=int(input()) T=[int(i) for i in input().split()] A=[int(i) for i in input().split()] ans=1 mod=10**9+7 for i in range(N): if i==0: if A[i]!=A[i+1] and T[i]!=A[i]: print(0) exit() elif i==N-1: if T[i]!=T[i-1] and T[i]!=A[i]: print(0) exit() else: if T[i]==T[i-1] and A[i]==A[i+1]: ans=(ans*min(T[i],A[i]))%mod elif T[i]!=T[i-1] and A[i]<T[i]: print(0) exit() elif A[i]!=A[i+1] and A[i]>T[i]: print(0) exit() print(ans)
s423922299
p03959
u397531548
1543515444
Python
Python (3.4.3)
py
Runtime Error
67
19136
443
N=int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) a = 1 if T[0]>A[0] or A[-1]>T[-1] or T[-1]!=A[-1]: a*=0 for i in range(1,n): if T[i-1]!=T[i]: if T[i]>A[i]: a*=0 break else: a*=1 if A[i]!=A[i+1]: if T[i]<A[i]: a*=0 break else: a*=1 else: a=a*(min(T[i],A[i]))%(10**9+7) print(a)
s478802674
p03959
u397531548
1543473093
Python
Python (3.4.3)
py
Runtime Error
2105
27352
371
N=int(input()) S=input().split() T=list(int(S[i]) for i in range(len(S))) B=input().split() A=list(int(B[i]) for i in range(len(B))) a=1 if max(T)!=max(A): print(0) else: for i in range(1,N-1): if T[i]==T[i-1] and A[N-i]==A[N-i+1]: a*=min(T[i],A[N-i]) if T[i]>T[i-1] or A[N-i]>A[N-i+1]: a*=1 print(a%(10**9+7))
s702207565
p03959
u397531548
1543472975
Python
Python (3.4.3)
py
Runtime Error
2105
26304
372
N=int(input()) S=input().split() T=list(int(S[i]) for i in range(len(S))) B=input().split() A=list(int(B[i]) for i in range(len(B))) a=1 if max(T)!=max(A): print(-1) else: for i in range(1,N-1): if T[i]==T[i-1] and A[N-i]==A[N-i+1]: a*=min(T[i],A[N-i]) if T[i]>T[i-1] or A[N-i]>A[N-i+1]: a*=1 print(a%(10**9+7))
s273047216
p03959
u102126195
1536529319
Python
Python (3.4.3)
py
Runtime Error
164
18756
660
N = int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) h = [] for i in range(N): if i == 0: h.append(1) elif i == N - 1: h.append(1) else: if T[i] > T[i - 1]: h.append(1) if T[i] > A[i]: h[i] = 0 break elif A[i] > A[i + 1]: h.append(1) if A[i] > T[i]: h[i] = 0 break else: h.append(min([A[i], T[i]]) % 1000000007) if max[T] != max[A]: h.append(0) cnt = 1 for i in range(len(h)): cnt *= h[i] print(cnt % 1000000007)
s919248840
p03959
u839537730
1501620719
Python
Python (3.4.3)
py
Runtime Error
2104
18752
935
N = int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) def judge(t): if t[0] == t[1]: return True else: return False if judge(A[0:2]) and A[0] < T[0]: ans = 0 ansable = False elif not judge(A[0:2]) and A[0] != T[0]: ans = 0 ansable = False else: ans = 1 ansable = True for i in range(1, N-1): if ansable == False: break elif not judge(A[i:i+2]) and not judge(T[i-1:i+1]): if A[i] != T[i]: ans = 0 ansable = False elif not judge(A[i:i+2]) and judge(T[i-1:i+1]): if A[i] > T[i]: ans = 0 ansable = False elif judge(A[i:i+2]) and not judge(T[i-1:i+1]): if A[i] < T[i]: ans = 0 ansable = False elif judge(A[i:i+2]) and judge(T[i-1:i+1]): ans *= (min(A[i],T[i]))%(10**9+7) print(ans%(10**9+7))
s112517693
p03959
u436484848
1477284247
Python
Python (3.4.3)
py
Runtime Error
22
3064
463
def read(): return [int(i) for i in input().split(" ")] N = int(input()) T = read() A = read() t = [(i != j, i) for i, j in zip(T, [None] + T)] a = [(i != j, i) for i, j in zip(A, (A + [None])[1:])] P = 1 for p, q in zip(t, a): if(p[0]): if(q[0]): if(p[1] != q[1]): print(0) exit() else: if(q[1] < p[1]): print(0) exit() elif(q[0]): if(p[1] < q[1]): print(0) exit() else: P = P * min(p[1], q[1]) % (10 ** 9 + 7)) print(P)
s750018552
p03959
u436484848
1477284057
Python
Python (3.4.3)
py
Runtime Error
23
3064
448
def read(): return [int(i) for i in input().split(" ")] N = int(input()) T = read() A = read() t = [(i != j, i) for i, j in zip(T, [None] + T)] a = [(i != j, i) for i, j in zip(A, (A + [None])[1:])] P = 1 for p, q in zip(t, a): if(p[0]): if(q[0]): if(p[1] != q[1]): print(0) exit() elif(q[1] < p[1]): print(0) exit() elif(q[0]): if(p[1] < q[1]): print(0) exit() else: P *= min(p[1], q[1]) print(P % (10 ** 9 + 7)
s830558058
p03959
u813098295
1477281250
Python
Python (3.4.3)
py
Runtime Error
23
3188
778
N = int(raw_input()) T = map(int, raw_input().split()) A = map(int, raw_input().split()) ans = 1 mod = 10 ** 9 + 7 if T[N - 1] != A[0]: print (0) exit() for i in xrange(N): if i == 0 or i == N - 1: continue elif T[i] > T[i-1]: if A[i] < T[i] and A[i] == A[i + 1]: print (0) exit() elif A[i] != T[i] and A[i] != A[i + 1]: print (0) exit() else: if T[i] == A[i]: if A[i] == A[i + 1]: ans *= T[i] elif T[i] > A[i]: if A[i] == A[i + 1]: ans *= A[i] else: if A[i] == A[i + 1]: ans *= T[i] else: print (0) exit() print (ans % mod)
s185938033
p03959
u813098295
1477280894
Python
Python (2.7.6)
py
Runtime Error
107
14496
763
N = int(raw_input()) T = map(int, raw_input().split()) A = map(int, raw_input().split()) ans = 1 mod = 10 ** 9 + 7 if T[n - 1] != A[0]: print 0 exit() for i in xrange(N): if i == 0 or i == n - 1: continue elif T[i] > T[i-1]: if A[i] < T[i] and A[i] == A[i + 1]: print 0 exit() elif A[i] != T[i] and A[i] != A[i + 1]: print 0 exit() else: if T[i] == A[i]: if A[i] == A[i + 1]: ans *= T[i] elif T[i] > A[i]: if A[i] == A[i + 1]: ans *= A[i] else: if A[i] == A[i + 1]: ans *= T[i] else: print 0 exit() print ans % mod
s068121675
p03959
u813098295
1477280157
Python
Python (2.7.6)
py
Runtime Error
105
14484
329
N = int(raw_input()) T = map(int, raw_input().split()) A = map(int, raw_input().split()) ans = 1 mod = 10 ** 9 + 7 if T[n - 1] != A[0]: ans = 0 else: for i in xrange(1, N - 1): if T[i] > A[i]: ans = (ans * A[i]) % mod elif T[i] < A[i]: ans = (ans * T[i]) % mod print ans % mod
s689994643
p03959
u335830383
1477278495
Python
Python (2.7.6)
py
Runtime Error
929
22012
823
import numpy as np N = int(raw_input()) T = map(int, raw_input().split()) A = map(int, raw_input().split()) T = np.array(T) A = np.array(A) arr = np.ones((len(A),)) res = 1 rest = np.zeros((len(A),)) if max(A) != max(T): res = 0 else: for t in range(T.shape[0]): if t > 0 and T[t] == T[t-1] and t != T.shape[0]-1: arr[t] = T[t] elif t != T.shape[0]-1: rest[t] = T[t] for a in range(A.shape[0])[::-1]: if rest[a]>1 and A[a]<rest[a]: arr = np.zeros((len(A),)) break elif a < A.shape[0]-1 and a != 0 and arr[a] != 1: if A[a] > A[a+1]: arr[a] = 1 elif A[a] < arr[a]: arr[a] = A[a] for j in arr: res *= j if res != 0: res = res % ((10**9) + 7) print int(res)
s629424579
p03959
u335830383
1477278350
Python
Python (2.7.6)
py
Runtime Error
1995
22012
846
# -*- coding: utf-8 -*- import numpy as np N = int(raw_input()) T = map(int, raw_input().split()) A = map(int, raw_input().split()) T = np.array(T) A = np.array(A) arr = np.ones((len(A),)) res = 1 rest = np.zeros((len(A),)) if max(A) != max(T): res = 0 else: for t in range(T.shape[0]): if t > 0 and T[t] == T[t-1] and t != T.shape[0]-1: arr[t] = T[t] elif t != T.shape[0]-1: rest[t] = T[t] for a in range(A.shape[0])[::-1]: if rest[a]>1 and A[a]<rest[a]: arr = np.zeros((len(A),)) break elif a < A.shape[0]-1 and a != 0 and arr[a] != 1: if A[a] > A[a+1]: arr[a] = 1 elif A[a] < arr[a]: arr[a] = A[a] for j in arr: res *= j if res != 0: res = res % ((10**9) + 7) print int(res)
s361959190
p03959
u386131832
1477278093
Python
Python (3.4.3)
py
Runtime Error
103
19136
366
import sys n=int(input()) t=[int(i) for i in input().split()] a=[int(i) for i in input().split()] a_max=max(a) t_max=max(t) if a_max != t_max(t): print(0) sys.exit() i=0 sum=1 while t[i]!=t_max: if t[i]==t[i+1]: sum*=t[i] j=len(a)-1 while a[j]!=a_max: if a[j]==a[j-1]: sum*=a[j] sum=sum*(a_max**(n-(i+j+1)))%((1e+9)+7) print(int(sum))
s845266465
p03959
u335830383
1477277900
Python
Python (2.7.6)
py
Runtime Error
1168
22928
1015
# -*- coding: utf-8 -*- from sys import stdin import numpy as np n = stdin.readline() n = n.strip().split(" ") N = int(n[0]) n = stdin.readline() n = n.strip().split(" ") T = [] for t in n: T.append(int(t)) T = np.array(T) n = stdin.readline() n = n.strip().split(" ") A = [] for a in n: A.append(int(a)) A = np.array(A) arr = np.ones((len(A),)) res = 1 rest = np.zeros((len(A),)) if max(A) != max(T): res = 0 else: for t in range(T.shape[0]): if t > 0 and T[t] == T[t-1] and t != T.shape[0]-1: arr[t] = T[t] elif t != T.shape[0]-1: rest[t] = T[t] for a in range(A.shape[0])[::-1]: if rest[a]>1 and A[a]<rest[a]: arr = np.zeros((len(A),)) break elif a < A.shape[0]-1 and a != 0 and arr[a] != 1: if A[a] > A[a+1]: arr[a] = 1 elif A[a] < arr[a]: arr[a] = A[a] for j in arr: res *= j if res != 0: res = res % ((10**9) + 7) print int(res)