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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s901040163 | p03946 | u984351908 | 1478907466 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 299 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
max_dif = 0
for i in range(n):
for j in range(i + 1, n):
if a[j] - a[i] > max_dif:
c = 1
max_dif = a[j] - a[i]
elif: a[j] - a[i] == max_dif:
c += 1
print(str(c))
|
s047995425 | p03946 | u984351908 | 1478907238 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 294 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
max_dif = 0
for i in range(n):
for j in range(i + 1, n):
if a[j] - a[i] > max_dif:
c = 1
max_dif = a[j] - a[i]
elif: a[j] - a[i] == max_dif:
c += 1
print(c)
|
s277035284 | p03946 | u984351908 | 1478907129 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 290 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
max_dif = 0
for i in range(n):
for j in range(i, n):
if a[j] - a[i] > max_dif:
c = 1
max_dif = a[j] - a[i]
elif: a[j] - a[i] == max_dif:
c += 1
print(c)
|
s248777598 | p03946 | u123756661 | 1478492441 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 181 | IS=float('inf')
x=IS
y=0
for i in a:
if x>i:
x=i
elif y<i:
y=i
if i-x>chk:
ans=1
elif i-x==chk:
ans+=1
chk=max(chk,i-x)
print ans |
s349058884 | p03946 | u272496669 | 1478488094 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 397 | list1 = input().split()
n = int(list1[0])
t = int(list1[1])
a = input().split()
list = []
l = 0
i = 0
while l < n:
i = l + 1
if i == n:
list.append(int(a[i-1])-int(a[l]))
break
else:
while i < n:
if a[i-1]<a[i]:
i += 1
else:
list.append(int(a[i-1])-int(a[l]))
break
l += 1
print(list.count(max(list))) |
s546545703 | p03946 | u731028462 | 1478486518 | Python | Python (3.4.2) | py | Runtime Error | 22 | 3064 | 298 | INF = 1000000
n, m = list(map(int, input().split()))
a = list(map(int, input().split())) + [0]
b = a[0]
arr = []
for i in range(1, n+1):
if a[i - 1] > a[i]:
x = a[i - 1] - b
arr += [x] if x != 0 else []
b = a[i]
mx = max(arr)g
ans = min(arr.count(mx),m//2)
print(ans)
|
s297569772 | p03947 | u863370423 | 1596657239 | Python | PyPy3 (7.3.0) | py | Runtime Error | 88 | 74588 | 195 | #include <bits/stdc++.h>
using namespace std;
string s;
int main() {
ios::sync_with_stdio(false);
cin >> s;
cout << unique(s.begin(), s.end()) - s.begin() - 1 << endl;
return 0;
} |
s311793120 | p03947 | u417014669 | 1577108580 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 79 | s=input()
cnt=0
for i range(1,len(s)):
if s[i]!=s[i-1]:
cnt+=1
print(cnt) |
s844940486 | p03947 | u374802266 | 1563249829 | Python | Python (3.4.3) | py | Runtime Error | 64 | 3188 | 115 | a=input()
n,b=0,0
while True:
if a[n]!=a[n+1]:
b+=1
n+=1
if n+1==len(a):
break
print(b) |
s230596724 | p03947 | u118642796 | 1554221735 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 58 | S = input()
print(sum([a!=b for a,b in zip(S[:-1],S[1:])]) |
s198306270 | p03947 | u485137520 | 1549054895 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 177 |
s_long = input()
count = 0
prev = ''
for s in s_long:
if prev == ''
prev = s
continue
if prev != s:
count += 1
prev = s
print(count) |
s958159862 | p03947 | u329865314 | 1524345718 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3188 | 83 | s=input()
ans = 0
for I in range(len(s)-1):
if s[i]!=s[i+1]:
ans += 1
print(ans) |
s336742521 | p03947 | u272028993 | 1497744859 | Python | PyPy2 (5.6.0) | py | Runtime Error | 40 | 29420 | 1116 | import sys
sys.setrecursionlimit(10**8)
class Segtree():
INT_MIN=-10**9
def __init__(self,size):
self.size=1
while self.size<size:
self.size=self.size*2
self.node=[self.INT_MIN]*(2*self.size-1)
def update(self,k,a):
k+=self.size-1
self.node[k]=a
while k>0:
k=(k-1)/2
self.node[k]=max(self.node[k*2+1],self.node[k*2+2])
def get_max(self,queryL,queryR,k=0,nodeL=0,nodeR=-1):
if nodeR==-1:nodeR=self.size
if (nodeR<=queryL or queryR<=nodeL):return self.INT_MIN
if (queryL<=nodeL and nodeR<=queryR):return self.node[k]
else:
nodeM=(nodeL+nodeR)/2
vl=self.get_max(queryL,queryR,k*2+1,nodeL,nodeM)
vr=self.get_max(queryL,queryR,k*2+2,nodeM,nodeR)
return max(vl,vr)
n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
seg=Segtree(n)
for i in xrange(n):
seg.update(i,a[i])
ans=0
mx=0
for i in xrange(n):
tmp=seg.get_max(i,n)-a[i]
if mx<tmp:
ans=1
mx=tmp
elif mx==tmp:
ans+=1
print ans
|
s522272279 | p03947 | u620868411 | 1479616843 | Python | Python (2.7.6) | py | Runtime Error | 43 | 3972 | 1040 | import unittest
class TestFunc(unittest.TestCase):
def test_1(self):
self.assertEqual(fun(5,8,[50,30,40,10,20]),2)
self.assertEqual(fun(3,2,[100,50,200]),1)
self.assertEqual(fun(10,100,[7,10,4,5,9,3,6,8,2,1]),2)
self.assertEqual(fun(5,2,[1,2,3,2,4]),1)
def fun(n,t,a):
aa = []
b = None
s = None
for i in range(n):
m = -1
for j in range(i+1,n):
if a[j]>a[i] and a[j]-a[i]>m:
m = a[j]-a[i]
if m>0:
aa.append(m)
c = aa[0]
ans = 1
for i in range(1,len(aa)):
if c<aa[i]:
c = aa[i]
ans = 1
elif c==aa[i]:
ans += 1
return ans
if __name__=='__main__':
#unittest.main()
n,t = [int(x) for x in raw_input().split(" ")]
a = [int(x) for x in raw_input().split(" ")]
print(fun(n,t,a))
|
s776488975 | p03947 | u382423941 | 1478980875 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 128 | s = open('input', 'r').read()
prev = s[0]
ans = 0
for c in s:
if c != prev:
ans += 1
prev = c
print(ans-1)
|
s995235276 | p03947 | u943885161 | 1478926258 | Python | Python (2.7.6) | py | Runtime Error | 17 | 2568 | 107 | s = raw_input()
cnt = 0
last
last = s[0]
for c in s[1:end]:
if c ! last
cnt = cnt+1
last = c
print cnt |
s967565909 | p03947 | u972416428 | 1478572700 | Python | Python (2.7.6) | py | Runtime Error | 18 | 2944 | 91 | inp = input().strip()
print len( [ i for i in range( len(inp)-1 ) if inp[i] != inp[i+1] ] ) |
s993069444 | p03947 | u972416428 | 1478572663 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 89 | inp = input().strip()
print len( [ for i in range( len(inp)-1 ) if inp[i] != inp[i+1] ] ) |
s728159169 | p03947 | u326569562 | 1478488603 | Python | Python (2.7.6) | py | Runtime Error | 18 | 3076 | 1961 |
def main():
N = input()
edges = [raw_input() for _ in range(N-1)]
K = input()
VP = [raw_input() for _ in range(K)]
VP = [map(int, _.strip().split()) for _ in VP]
edges = [map(int, _.strip().split()) for _ in edges]
# print VP
# print edges
scores = {}
for n_idx, value in VP:
scores[n_idx] = [value]
pre_defined = scores.keys()
# print scores
def check(value, n1, n2):
if value == (n1 - n2) or value == (n2 - n1):
return True
return False
for n1, n2 in edges:
# print n1, n2
if scores.get(n1) is None and scores.get(n2) is None:
pass
else:
if scores.get(n1) is None:
for v in scores.get(n2, []):
scores[n1] = [_ for _ in scores.get(n1, []) if check(_, n1, n2)] + [v - 1, v+1]
elif scores.get(n2) is None:
for v in scores.get(n1, []):
scores[n2] = [_ for _ in scores.get(n2, []) if check(_, n1, n2)] + [v - 1, v+1]
for n1, n2 in edges[-1::]:
# print n1, n2
if scores.get(n1) is None and scores.get(n2) is None:
pass
else:
if scores.get(n1) is None:
for v in scores.get(n2, []):
scores[n1] = [_ for _ in scores.get(n1, []) if check(_, n1, n2)] + [v - 1, v+1]
elif scores.get(n2) is None:
for v in scores.get(n1, []):
scores[n2] = [_ for _ in scores.get(n2, []) if check(_, n1, n2)] + [v - 1, v+1]
# print scores.get(n1), scores.get(n2)
# print "----------"
# decide step
adding = []
for n in range(1, N+1):
v = scores.get(n, [None])[0]
adding.append(v)
if all([_ is not None for _ in adding]):
print "Yes"
for a in adding:
print a
else:
print "No"
# print scores
if __name__ == '__main__':
main() |
s472944684 | p03947 | u232757112 | 1478487360 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3444 | 1337 | from sys import stdin
input = stdin.readline
N,T = map(int,input().split())
prices = list(map(int,input().split()))
last = 10000000000
highestTally = [prices[-1]]
highestCount = [1]
for price in prices[-2:-N-1:-1]:
if price==highestTally[-1]:
highestCount.append(highestCount[-1]+1)
else:
highestCount.append(1)
highestTally.append(max(highestTally[-1],price))
highestTally.reverse()
highestCount.reverse()
indexOfHighest={}
for i in range(N-1,-1,-1):
if highestTally[i]==prices[i]:
indexOfHighest[highestTally[i]]=i
biggestJump=0
sellingPriceForBiggestJump=0
HPcount=0
LPcount=0
for index,price in enumerate(prices):
if index==N-1:
break
bestSellingPrice = highestTally[index+1]
jump = bestSellingPrice-price
#print(jump,bestSellingPrice,biggestJump)
if jump>biggestJump:
biggestJump = jump
LPcount+=1
sellingPriceForBiggestJump = bestSellingPrice
HPcount=highestCount[indexOfHighest[bestSellingPrice]]
elif jump==biggestJump:
if bestSellingPrice!=sellingPriceForBiggestJump:
sellingPriceForBiggestJump = bestSellingPrice
HPcount+=highestCount[indexOfHighest[bestSellingPrice]]
LPcount+=1
count = min(LPcount,HPcount)
if T//2>=count:
print(count)
else:
print(int(T//2)) |
s775105370 | p03947 | u232757112 | 1478487312 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3444 | 1337 | from sys import stdin
input = stdin.readline
N,T = map(int,input().split())
prices = list(map(int,input().split()))
last = 10000000000
highestTally = [prices[-1]]
highestCount = [1]
for price in prices[-2:-N-1:-1]:
if price==highestTally[-1]:
highestCount.append(highestCount[-1]+1)
else:
highestCount.append(1)
highestTally.append(max(highestTally[-1],price))
highestTally.reverse()
highestCount.reverse()
indexOfHighest={}
for i in range(N-1,-1,-1):
if highestTally[i]==prices[i]:
indexOfHighest[highestTally[i]]=i
biggestJump=0
sellingPriceForBiggestJump=0
HPcount=0
LPcount=0
for index,price in enumerate(prices):
if index==N-1:
break
bestSellingPrice = highestTally[index+1]
jump = bestSellingPrice-price
#print(jump,bestSellingPrice,biggestJump)
if jump>biggestJump:
biggestJump = jump
LPcount+=1
sellingPriceForBiggestJump = bestSellingPrice
HPcount=highestCount[indexOfHighest[bestSellingPrice]]
elif jump==biggestJump:
if bestSellingPrice!=sellingPriceForBiggestJump:
sellingPriceForBiggestJump = bestSellingPrice
HPcount+=highestCount[indexOfHighest[bestSellingPrice]]
LPcount+=1
count = min(LPcount,HPcount)
if T//2>=count:
print(count)
else:
print(int(T//2)) |
s266914761 | p03947 | u232757112 | 1478485832 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3316 | 820 | from sys import stdin
input = stdin.readline
N,T = map(int,input().split())
prices = list(map(int,input().split()))
last = 10000000000
highestTally = [prices[-1]]
for price in prices[-2:-N-1:-1]:
highestTally.append(max(highestTally[-1],price))
highestTally.reverse()
biggestJump=0
sellingPriceForBiggestJump=0
count=0
for index,price in enumerate(prices):
if index==N-1:
break
bestSellingPrice = highestTally[index+1]
jump = bestSellingPrice-price
if jump>biggestJump:
biggestJump = jump
sellingPriceForBiggestJump = bestSellingPrice
count=1
elif jump==biggestJump:
if bestSellingPrice!=sellingPriceForBiggestJump:
sellingPriceForBiggestJump = bestSellingPrice
count+=1
if T//2>=count:
print(count)
else:
print(int(T//2))
|
s884839353 | p03947 | u765237551 | 1478484204 | Python | Python (3.4.3) | py | Runtime Error | 226 | 101176 | 116 | def solve(s):
if len(s)<=1:
return 0
return (s[0]!=s[1]) + solve(s[1:])
S = input()
print(solve(S)) |
s763590742 | p03948 | u918935103 | 1563307392 | Python | Python (3.4.3) | py | Runtime Error | 82 | 14676 | 283 | n,t = map(int,input().split())
a = list(map(int,input().split()))
l = []
count = 0
for i in range(n-1):
if a[i] <= a[i+1]:
count = count + a[i+1] - a[i]
else:
l.append(count)
count = 0
l.append(count)
l.remove(0)
d = max(l)
ans = l.count(d)
print(ans) |
s076004768 | p03948 | u422104747 | 1530912824 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 163 | s=input().split()
l=[]
for i in range(1,len(s)):
l.append(int(s[i])-int(s[i-1]))
l.sort()
m=l[-1]
for i in range(2,len(s)+1):
if l[-i]!=m:
break
print(i-1) |
s057137301 | p03948 | u639989198 | 1480826235 | Python | Python (3.4.3) | py | Runtime Error | 308 | 32312 | 105 | from numpy import *
input()
a=array(input().split())
d=a-minimum.accumulate(a)
print((d==d.max()).sum())
|
s571183108 | p03948 | u382423941 | 1478982224 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 283 | n, t = map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
max_diff = 0
min_a = A[0]
for a in A:
min_a = min(min_a, a)
if (a - min_a) == max_diff:
ans += 1
elif (a - min_a) > max_diff:
ans = 1
max_diff = (a - min_a)
print(ans)
|
s115458010 | p03948 | u281372625 | 1478489431 | Python | Python (2.7.6) | py | Runtime Error | 64 | 11304 | 394 | N, T = map(int, raw_input().split())
A_n = map(int, raw_input().split())
min_element = min(A_n[0], A_n[1])
for i in xrange(1, len(A_n)):
if A_n[i] - min_element > max_profit:
max_profit = A_n[i] - min_element
if A_n[i] < min_element:
min_element = A_n[i]
count = 0
for j in xrange(0, len(A_n)):
if (A_n[j] + max_profit) in A_n[j:]:
count += 1
print count
|
s098371544 | p03948 | u326569562 | 1478488824 | Python | Python (2.7.6) | py | Runtime Error | 17 | 2816 | 1685 | def main():
N = input()
edges = [raw_input() for _ in range(N-1)]
K = input()
VP = [raw_input() for _ in range(K)]
VP = [map(int, _.strip().split()) for _ in VP]
edges = [map(int, _.strip().split()) for _ in edges]
# print VP
# print edges
scores = {}
for n_idx, value in VP:
scores[n_idx] = [value]
pre_defined = scores.keys()
# print scores
def check(value, n1, n2):
if value == (n1 - n2) or value == (n2 - n1):
return True
return False
for idx in pre_defined:
for n1, n2 in [l for l in edges if idx in l]:
v = scores[idx][0]
n = n1 if idx == n2 else n2
scores[n] = [_ for _ in scores.get(n, []) if check(_, n1, n2)] + [v - 1, v+1]
for n1, n2 in edges:
# print n1, n2
if scores.get(n1) is None and scores.get(n2) is None:
pass
else:
if scores.get(n1) is None:
for v in scores.get(n2, []):
scores[n1] = [_ for _ in scores.get(n1, []) if check(_, n1, n2)] + [v - 1, v+1]
elif scores.get(n2) is None:
for v in scores.get(n1, []):
scores[n2] = [_ for _ in scores.get(n2, []) if check(_, n1, n2)] + [v - 1, v+1]
# print scores.get(n1), scores.get(n2)
# print "----------"
# decide step
adding = []
for n in range(1, N+1):
v = scores.get(n, [None])[0]
adding.append(v)
if all([_ is not None for _ in adding]):
print "Yes"
for a in adding:
print a
else:
print "No"
# print scores
if __name__ == '__main__':
main() |
s308661710 | p03949 | u340781749 | 1599539115 | Python | Python (3.8.2) | py | Runtime Error | 521 | 77368 | 1311 | import sys
def dfs(v, parent, odd):
hi = INF
lo = -INF
if fixed[v] != INF:
if odd_even[v] != odd:
print('No')
exit()
hi = lo = fixed[v]
for u in links[v]:
if u == parent:
continue
chi, clo = dfs(u, v, odd ^ 1)
if hi < clo or chi < lo:
print('No')
exit()
hi = min(hi, chi)
lo = max(lo, clo)
upper[v] = hi
lower[v] = lo
return hi + 1, lo - 1
def fill(v, parent, pp):
if pp + 1 > upper[v]:
assert pp - 1 >= lower[v]
vp = fixed[v] = pp - 1
else:
vp = fixed[v] = pp + 1
for u in links[v]:
if u == parent:
continue
fill(u, v, vp)
inp = list(map(int, sys.stdin.buffer.read().split()))
n = inp[0]
links = [set() for _ in range(n)]
for a, b in zip(inp[1:2 * n - 1:2], inp[2:2 * n - 1:2]):
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
INF = 10 ** 9
k = inp[2 * n - 1]
fixed = [INF] * n
odd_even = {}
fixed_v = 0
for v, p in zip(inp[2 * n::2], inp[2 * n + 1::2]):
v -= 1
fixed[v] = p
odd_even[v] = p % 2
fixed_v = v
lower = [-INF] * n
upper = [INF] * n
dfs(fixed_v, -1, odd_even[fixed_v])
fill(fixed_v, -1, fixed[fixed_v] + 1)
print('Yes')
print('\n'.join(map(str, fixed)))
|
s036026214 | p03949 | u754022296 | 1592461752 | Python | Python (3.4.3) | py | Runtime Error | 339 | 36476 | 985 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
T = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
T[a].append(b)
T[b].append(a)
k = int(input())
VP = tuple(tuple(map(int, input().split())) for _ in range(k))
P = [-1]*(n+1)
A = [-1]*(n+1)
r, c = PV[0]
for v, p in VP:
P[v] = p
C = [None]*(n+1)
def dfs1(v, par=-1, color=c%2):
if P[v] == -1:
l = -float("inf")
r = float("inf")
else:
l = P[v]
r = P[v]
for nv in T[v]:
if nv == par:
continue
nl, nr = dfs1(nv, v, color^1)
l = max(l, nl-1)
r = min(r, nr+1)
if l ^ color:
l += 1
if r ^ color:
r -= 1
if l > r:
print("No")
exit()
P[v] = (l, r)
return P[v]
dfs1(r)
def dfs2(v, ini, par=-1):
l, r = P[v]
if l <= ini-1 <= r:
A[v] = ini-1
else:
A[v] = ini+1
for nv in T[v]:
if nv == par:
continue
dfs2(nv, A[v], v)
dfs2(r, P[r][0])
print("Yes")
print(*A[1:], sep="\n") |
s948308343 | p03949 | u828766688 | 1587737736 | Python | Python (3.4.3) | py | Runtime Error | 1311 | 32272 | 1919 |
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc063/tasks/arc063_c
数字が置かれている頂点は範囲指定の制約になる
→制約をすべての点に伝播させれば、後はその範囲内から適当に選んで実装すればよい
一度根方向に制約を集め、それを全方位に伝播させればよい?
→それっぽさそう
偶奇に関してはちゃんと考えてね
→条件の両端の偶奇で判断可能
"""
import sys
N = int(input())
lis = [ [] for i in range(N) ]
for i in range(N-1):
a,b = map(int,input().split())
a -= 1
b -= 1
lis[a].append(b)
lis[b].append(a)
l = [float("-inf")] * N
r = [float("inf")] * N
K = int(input())
for i in range(K):
V,P = map(int,input().split())
V -= 1
l[V] = P
r[V] = P
#dfsで条件を根方向に集める
def dfs(v,p):
for nex in lis[v]:
if nex != p:
nl,nr = dfs(nex,v)
if l[v] != float("-inf") and nl != float("-inf") and l[v] % 2 != nl % 2:
print ("No")
sys.exit()
l[v] = max(l[v] , nl)
r[v] = min(r[v] , nr)
if l[v] > r[v]:
print ("No")
sys.exit()
return l[v] - 1 , r[v] + 1
dfs(0,0)
#bfsで条件を配る
from collections import deque
q = deque([0])
unvisit = [True] * N
ans = [None] * N
ans[0] = l[0]
while len(q) > 0:
v = q.popleft()
unvisit[v] = False
if l[v] > r[v]:
print ("No")
sys.exit()
for nex in lis[v]:
if unvisit[nex]:
if l[nex] != float("-inf") and l[v] != float("-inf") and l[v] % 2 == l[nex] % 2:
print ("No")
sys.exit()
l[nex] = max(l[nex] , l[v]-1)
r[nex] = min(r[nex] , r[v]+1)
ans[nex] = l[nex]
q.append(nex)
print ("Yes")
for i in ans:
print (i)
|
s222115755 | p03949 | u543954314 | 1571245295 | Python | Python (3.4.3) | py | Runtime Error | 1357 | 40828 | 1352 | import sys
sys.setrecursionlimit = 10**6
n = int(input())
tr = [list() for _ in range(n)]
num = [None]*n
ran = [0]*n
dep = [0]*n
for _ in range(n-1):
a,b = map(int,input().split())
a -= 1; b -= 1
tr[a].append(b)
tr[b].append(a)
k = int(input())
root,c = map(int,input().split())
root -= 1
num[root] = c
def dfs(v,p,dep):
for x in tr[v]:
if x == p:
continue
dep[x] = dep[v] + 1
dfs(x,v,dep)
return
dfs(root,None,dep)
for _ in range(k-1):
v,c = map(int,input().split())
v -= 1
if abs(c-num[root]) > dep[v] or dep[v]%2 != (c-num[root])%2:
print("No")
exit(0)
num[v] = c
def dfs2(v,p,ran):
cur = [-10**9,10**9] if (num[v] is None) else [num[v],num[v]]
if tr[v] == [p]:
ran[v] = tuple(cur)
return ran[v]
for x in tr[v]:
if x == p:
continue
ran[x] = dfs2(x,v,ran)
if ran[x][0] > cur[0]:
cur[0] = ran[x][0]
if ran[x][1] < cur[1]:
cur[1] = ran[x][1]
cur[0] -= 1; cur[1] += 1
ran[v] = tuple(cur)
return ran[v]
dfs2(root,None,ran)
q = [(root,None)]
while q:
v,p = q.pop()
for x in tr[v]:
if x == p:
continue
if ran[x][0]<=num[v]+1<=ran[x][1]:
num[x] = num[v] + 1
elif ran[x][0]<=num[v]-1<=ran[x][1]:
num[x] = num[v] - 1
else:
print("No")
exit(0)
q.append((x,v))
print("Yes")
for c in num:
print(c)
|
s913682422 | p03949 | u543954314 | 1571244240 | Python | Python (3.4.3) | py | Runtime Error | 1250 | 40348 | 1365 | import sys
sys.setrecursionlimit = 10**8
n = int(input())
tr = [list() for _ in range(n)]
num = [None]*n
ran = [0]*n
par = [-1]*n
dep = [0]*n
for _ in range(n-1):
a,b = map(int,input().split())
a -= 1; b -= 1
tr[a].append(b)
tr[b].append(a)
k = int(input())
root,c = map(int,input().split())
root -= 1
num[root] = c
def dfs(v,p,par,dep):
for x in tr[v]:
if x == p:
continue
par[x] = v
dep[x] = dep[v] + 1
dfs(x,v,par,dep)
return
dfs(root,-1,par,dep)
for _ in range(k-1):
v,c = map(int,input().split())
v -= 1
if abs(c-num[root]) > dep[v] or dep[v]%2 != (c-num[root])%2:
print("No")
exit(0)
num[v] = c
def dfs2(v,p,ran):
cur = [-10**9,10**9] if num[v] is None else [num[v],num[v]]
if tr[v] == [p]:
ran[v] = tuple(cur)
return
for x in tr[v]:
if x == p:
continue
dfs2(x,v,ran)
if ran[x][0] > cur[0]:
cur[0] = ran[x][0]
if ran[x][1] < cur[1]:
cur[1] = ran[x][1]
cur[0] -= 1; cur[1] += 1
ran[v] = tuple(cur)
return
dfs2(root,None,ran)
q = [(root,None)]
while q:
v,p = q.pop()
for x in tr[v]:
if x == p:
continue
if ran[x][0]<=num[v]+1<=ran[x][1]:
num[x] = num[v] + 1
elif ran[x][0]<=num[v]-1<=ran[x][1]:
num[x] = num[v] - 1
else:
print("No")
exit(0)
q.append((x,v))
print("Yes")
for c in num:
print(c)
|
s469845431 | p03949 | u543954314 | 1571244170 | Python | Python (3.4.3) | py | Runtime Error | 1211 | 40352 | 1365 | import sys
sys.setrecursionlimit = 10**6
n = int(input())
tr = [list() for _ in range(n)]
num = [None]*n
ran = [0]*n
par = [-1]*n
dep = [0]*n
for _ in range(n-1):
a,b = map(int,input().split())
a -= 1; b -= 1
tr[a].append(b)
tr[b].append(a)
k = int(input())
root,c = map(int,input().split())
root -= 1
num[root] = c
def dfs(v,p,par,dep):
for x in tr[v]:
if x == p:
continue
par[x] = v
dep[x] = dep[v] + 1
dfs(x,v,par,dep)
return
dfs(root,-1,par,dep)
for _ in range(k-1):
v,c = map(int,input().split())
v -= 1
if abs(c-num[root]) > dep[v] or dep[v]%2 != (c-num[root])%2:
print("No")
exit(0)
num[v] = c
def dfs2(v,p,ran):
cur = [-10**9,10**9] if num[v] is None else [num[v],num[v]]
if tr[v] == [p]:
ran[v] = tuple(cur)
return
for x in tr[v]:
if x == p:
continue
dfs2(x,v,ran)
if ran[x][0] > cur[0]:
cur[0] = ran[x][0]
if ran[x][1] < cur[1]:
cur[1] = ran[x][1]
cur[0] -= 1; cur[1] += 1
ran[v] = tuple(cur)
return
dfs2(root,None,ran)
q = [(root,None)]
while q:
v,p = q.pop()
for x in tr[v]:
if x == p:
continue
if ran[x][0]<=num[v]+1<=ran[x][1]:
num[x] = num[v] + 1
elif ran[x][0]<=num[v]-1<=ran[x][1]:
num[x] = num[v] - 1
else:
print("No")
exit(0)
q.append((x,v))
print("Yes")
for c in num:
print(c)
|
s658933141 | p03949 | u777923818 | 1548916238 | Python | Python (3.4.3) | py | Runtime Error | 1323 | 44360 | 1394 | from collections import deque
def inpl(): return list(map(int, input().split()))
N = int(input())
G = [[] for _ in range(N+1)]
X = [-1 for _ in range(N+1)] # is odd
U = [1e7 for _ in range(N+1)]
L = [-1e7 for _ in range(N+1)]
for _ in range(N-1):
a, b = inpl()
G[a].append(b)
G[b].append(a)
K = int(input())
for _ in range(K):
v, p = inpl()
U[v], L[v], X[v] = p, p, p%2
searched = [0]*(N+1)
def dfs(u, l, x, i):
searched[i] = True
if X[i] >= 0 and X[i] != x:
X[i] = 2
return -1e7, 1e7
U[i] = min(U[i], u)
L[i] = max(L[i], l)
X[i] = x
for j in G[i]:
if searched[j]:
continue
nu, nl = dfs(U[i]+1, L[i]-1, (X[i]+1)%2, j)
U[i] = min(U[i], nu+1)
L[i] = max(L[i], nl-1)
return U[i], L[i]
dfs(U[v], L[v], X[v], v)
Q = [v]
searched = [0]*(N+1)
answer = [0]*(N+1)
answer[v] = U[v]
OK = True
if max(X) == 2:
OK = False
Q = []
while Q:
p = Q.pop()
for q in G[p]:
if searched[q]:
continue
searched[q] = True
Q.append(q)
if L[q] <= answer[p] + 1 <= U[q]:
answer[q] = answer[p] + 1
elif L[q] <= answer[p] - 1 <= U[q]:
answer[q] = answer[p] - 1
else:
OK = False
Q = []
break
if OK:
print("Yes")
print(*answer[1:], sep="\n")
else:
print("No") |
s008015488 | p03949 | u777923818 | 1548915922 | Python | Python (3.4.3) | py | Runtime Error | 1232 | 44232 | 1358 | from collections import deque
def inpl(): return list(map(int, input().split()))
N = int(input())
G = [[] for _ in range(N+1)]
X = [-1 for _ in range(N+1)] # is odd
U = [1e7 for _ in range(N+1)]
L = [-1e7 for _ in range(N+1)]
for _ in range(N-1):
a, b = inpl()
G[a].append(b)
G[b].append(a)
K = int(input())
for _ in range(K):
v, p = inpl()
U[v], L[v], X[v] = p, p, p%2
searched = [0]*(N+1)
def dfs(u, l, x, i):
searched[i] = True
if X[i] >= 0 and X[i] != x:
X[i] = 2
return -1e7, 1e7, 2, 0
U[i] = min(U[i], u)
L[i] = max(L[i], l)
X[i] = x
for j in G[i]:
if searched[j]:
continue
nu, nl = dfs(U[i]+1, L[i]-1, (X[i]+1)%2, j)
U[i] = min(U[i], nu+1)
L[i] = max(L[i], nl-1)
return U[i], L[i]
dfs(U[v], L[v], X[v], v)
Q = [v]
searched = [0]*(N+1)
answer = [0]*(N+1)
answer[v] = U[v]
OK = True
while Q:
p = Q.pop()
for q in G[p]:
if searched[q]:
continue
searched[q] = True
Q.append(q)
if L[q] <= answer[p] + 1 <= U[q]:
answer[q] = answer[p] + 1
elif L[q] <= answer[p] - 1 <= U[q]:
answer[q] = answer[p] - 1
else:
OK = False
Q = []
break
if OK:
print("Yes")
print(*answer[1:], sep="\n")
else:
print("No")
|
s603171165 | p03949 | u924339359 | 1537388310 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1243 | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF=1000000010;
const ll MOD=1000000007;
int v[100010],p[100010],lb[100010],ub[100010];
vector<int> G[100010];
bool f=false;
int n;
void dfs(int i,int pre,int l,int r){//(頂点、前の頂点、ありうるmin、ありうるmax)
if(p[i]!=-1){
if(p[i]%2!=l%2||p[i]<l||p[i]>r){
f=true;
return;
}
l=p[i];
r=p[i];
}
lb[i]=l,ub[i]=r;
for(auto &e:G[i]){
if(e==pre)continue;
dfs(e,i,l-1,r+1);
lb[i]=max(lb[i],lb[e]-1);
ub[i]=min(ub[i],ub[e]+1);
}
for(auto &e:G[i]){
if(e==pre)continue;
dfs(e,i,lb[i]-1,ub[i]+1);
}
}
void dfs2(int i,int pre){
if(p[i]==-1&&pre!=-1){
if(lb[i]<=p[pre]+1&&p[pre]+1<=ub[i]){
p[i]=p[pre]+1;
}else if(lb[i]<=p[pre]-1&&p[pre]-1<=ub[i]){
p[i]=p[pre]-1;
}
}
for(auto &e:G[i]){
if(e==pre)continue;
dfs2(e,i);
}
}
int main(){
cin>>n;
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
int k;cin>>k;
fill(p,p+n+1,-1);
for(int i=0;i<k;i++){
cin>>v[i];
cin>>p[v[i]];
}
dfs(v[0],-1,p[v[0]],p[v[0]]);
if(f){
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
dfs2(v[0],-1);
for(int i=1;i<=n;i++){
cout<<p[i]<<endl;
}
}
|
s067850956 | p03949 | u226155577 | 1518387242 | Python | Python (3.4.3) | py | Runtime Error | 2107 | 37840 | 830 | N = int(input())
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)
M = {}
K = int(input())
for i in range(K):
V, P = map(int, input().split())
M[V-1] = P
memo = [0]*N
def dfs(v, p, x, y):
if v in M:
x = y = M[v]
x0 = x; y0 = y
for w in G[v]:
if p == w:
continue
s, t = dfs(w, v, x-1, y+1)
x0 = max(x0, s-1)
y0 = min(y0, t+1)
for w in G[v]:
if p == w:
continue
dfs(w, v, x0-1, y0+1)
memo[v] = x0, y0
return x0, y0
INF = 10**18
dfs(list(M.keys())[0], -1, -INF, INF)
ok = 1
for i in range(N):
x, y = memo[i]
if not x <= y:
ok = 0
if ok:
print('Yes')
print(*map(lambda x: x[1], memo), sep='\n')
else:
print('No')
|
s779218434 | p03949 | u280667879 | 1500255491 | Python | Python (2.7.6) | py | Runtime Error | 2110 | 63224 | 507 | from scipy.sparse import*
g=[]
n=int(raw_input())
for _ in xrange(n-1):
a,b=map(int,raw_input().split())
g+=[(a-1,b-1,1)]
z=[-1]*n
for _ in xrange(int(raw_input())):
a,b=map(int,raw_input().split())
g+=[(n,a-1,b)]
z[a-1]=b
a,b,c=zip(*g)
a=map(int,csgraph.dijkstra(csr_matrix((c,(a,b)),[n+1]*2),0,n))
for i in xrange(n):
if z[i]>=0 and z[i]!=a[i]:
print('No')
sys.exit()
for e in g:
if e[0]<e[1] and abs(a[e[0]]-a[e[1]])!=1:
print('No')
sys.exit()
print('Yes')
print("\n".join(map(str,a[:n]))) |
s316229081 | p03949 | u280667879 | 1478557428 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3068 | 604 | from heapq import*
R=range;I=lambda:map(int,input().split());n=int(input());g=[[]for _ in R(n+1)];z=[-1]*n;d=[1e9]*n+[0];q=[-1]*(n+1);r=;Q=[];heappush(Q,(0,-2,n))
for _ in R(n-1):a,b=I();a-=1;b-=1;g[a]+=[(1,a,b)];g[b]+=[(1,b,a)]
for _ in R(*I()):a,b=I();a-=1;g[n]+=[(b,n,a)];z[a]=b
while Q:
e=heappop(Q)
if q[e[2]]!=-1:continue
q[e[2]]=e[1]
for f in g[e[2]]:
if d[f[2]]>e[0]+f[0]:d[f[2]]=e[0]+f[0];heappush(Q,(e[0]+f[0],f[1],f[2]))
for _ in g:
if any(n!=e[1]and abs(d[e[1]]-d[e[2]])!=1 for e in _):r="No"
if any(~z[i]and z[i]!=d[i]for i in R(n)):r="No"
print(r or"Yes\n"+"\n".join(map(str,d[:n]))) |
s762679236 | p03949 | u280667879 | 1478555498 | Python | Python (3.4.3) | py | Runtime Error | 56 | 10332 | 887 | #!/usr/bin/python
def shortestPath(g,s,dist,prev):
n = len(g)-1
Q=[]
heapq.heappush(Q,(0,-2,s))
while Q:
e = heapq.heappop(Q)
if prev[e[2]]!=-1: continue
prev[e[2]] = e[1]
for f in g[e[2]]:
if dist[f[2]] > e[0] + f[0]:
dist[f[2]] = e[0] + f[0]
heapq.heappush(Q,(e[0]+f[0],f[1],f[2]))
import sys,heapq
if sys.version_info[0]>=3:raw_input=input
n=int(raw_input())
g=[[] for _ in range(n+1)]
for _ in xrange(n-1):
a,b=map(int,raw_input().split())
g[a-1]+=[(1,a-1,b-1)]
g[b-1]+=[(1,b-1,a-1)]
z=[-1]*n
for _ in xrange(int(raw_input())):
a,b=map(int,raw_input().split())
g[n]+=[(b,n,a-1)]
z[a-1]=b
a=[1e9]*n+[0]
shortestPath(g,n,a,[-1]*(n+1))
for i in xrange(n):
if z[i]>=0 and z[i]!=a[i]:
print('No')
sys.exit()
for _ in g:
for e in _:
if e[1]<e[2] and abs(a[e[1]]-a[e[2]])!=1:
print('No')
sys.exit()
print('Yes')
print("\n".join(map(str,a[:n])))
|
s730656804 | p03949 | u132291455 | 1478495988 | Python | PyPy2 (5.6.0) | py | Runtime Error | 343 | 54428 | 545 | import sys
import heapq
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n+1)]
for _ in range(n-1):a,b=o();e[a]+=[(b,1)];e[b]+=[(a,1)]
k=int(raw_input())
for _ in range(k):v,p=o();e[v]+=[(0,p)];e[0]+=[(v,p)]
vis=[False]*n
q=[(0,0)]
heapq.heapify(q)
while len(q):
c,v=heapq.heappop(q)
vis[v]=True
cost[v]=c
for (w,d) in e[v]:
if not vis[w]:q+=[(c+d,w)]
for i in range(n):
for w,d in e[i]:
if abs(cost[i]-cost[w])!=1:print 'No';sys.exit()
print 'Yes'
for i in range(n):print cost[i] |
s722927293 | p03949 | u132291455 | 1478495880 | Python | PyPy2 (5.6.0) | py | Runtime Error | 341 | 54428 | 603 | import sys
import heapq
sys.setrecursionlimit(200000)
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n+1)]
for _ in range(n-1):
a,b=o()
e[a]+=[(b,1)];e[b]+=[(a,1)]
k=int(raw_input())
for _ in range(k):
v,p=o()
e[v]+=[(0,p)];e[0]+=[(v,p)]
vis=[False]*n
q=[(0,0)]
heapq.heapify(q)
while len(q):
c,v=heapq.heappop(q)
vis[v]=True
cost[v]=c
for (w,d) in e[v]:
if not vis[w]:q+=[(c+d,w)]
for i in range(n):
for w,d in e[i]:
if abs(cost[i]-cost[w])!=1:print 'No';sys.exit()
print 'Yes'
for i in range(n):print cost[i]
|
s239992455 | p03949 | u132291455 | 1478495867 | Python | Python (2.7.6) | py | Runtime Error | 1005 | 58260 | 603 | import sys
import heapq
sys.setrecursionlimit(200000)
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n+1)]
for _ in range(n-1):
a,b=o()
e[a]+=[(b,1)];e[b]+=[(a,1)]
k=int(raw_input())
for _ in range(k):
v,p=o()
e[v]+=[(0,p)];e[0]+=[(v,p)]
vis=[False]*n
q=[(0,0)]
heapq.heapify(q)
while len(q):
c,v=heapq.heappop(q)
vis[v]=True
cost[v]=c
for (w,d) in e[v]:
if not vis[w]:q+=[(c+d,w)]
for i in range(n):
for w,d in e[i]:
if abs(cost[i]-cost[w])!=1:print 'No';sys.exit()
print 'Yes'
for i in range(n):print cost[i]
|
s884875268 | p03949 | u132291455 | 1478488441 | Python | PyPy2 (5.6.0) | py | Runtime Error | 36 | 8944 | 921 | import sys
sys.setrecursionlimit(200000)
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n)]
for _ in range(n-1):
a,b=o()
e[a-1]+=[b-1];e[b-1]+=[a-1]
k=int(raw_input())
INF=float('inf')
r=[(-INF,INF)for _ in range(n)]
for _ in range(k):
v,p=o()
r[v-1]=(p,p)
vis=[False]*n
def dfs(x):
vis[x]=True
r1,r2=r[x]
for w in e[x]:
if not vis[w]:
dfs(w)
w1,w2=r[w]
if w1==-INF or r1==-INF or (w1-r1)%2:r1=max(r1,w1-1);r2=min(r2,w2+1)
else: r1,r2=1,-1
if r1>r2:r1,r2=1,-1
return=(r1,r2)
dfs(0)
if r[0]==(1,-1):print 'No';sys.exit()
print 'Yes'
vis=[False]*n
q=[(0,r[0][0])]
ans=[0]*n
while len(q):
v,c=q.pop(0)
vis[v]=True
ans[v]=c
for w in e[v]:
if not vis[w]:
for x in (c+1,c-1):
if r[w][0]<=x<=r[w][1]:q+=[(w,x)];break
for i in range(n):print int(ans[i])
|
s474064392 | p03949 | u132291455 | 1478488352 | Python | PyPy2 (5.6.0) | py | Runtime Error | 37 | 9072 | 897 | import sys
sys.setrecursionlimit(200000)
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n)]
for _ in range(n-1):
a,b=o()
e[a-1]+=[b-1];e[b-1]+=[a-1]
k=int(raw_input())
INF=float('inf')
r=[(-INF,INF)for _ in range(n)]
for _ in range(k):
v,p=o()
r[v-1]=(p,p)
vis=[False]*n
def dfs(x):
vis[x]=True
r1,r2=r[x]
for w in e[x]:
if not vis[w]:
dfs(w)
w1,w2=r[w]
if w1==-INF or r1==-INF or (w1-r1)%2:r1=max(r1,w1-1);r2=min(r2,w2+1)
else: r1,r2=1,-1
return=(r1,r2)
dfs(0)
if r[0]==(1,-1):print 'No';sys.exit()
print 'Yes'
vis=[False]*n
q=[(0,r[0][0])]
ans=[0]*n
while len(q):
v,c=q.pop(0)
vis[v]=True
ans[v]=c
for w in e[v]:
if not vis[w]:
for x in (c+1,c-1):
if r[w][0]<=x<=r[w][1]:q+=[(w,x)];break
for i in range(n):print int(ans[i])
|
s568178122 | p03950 | u326569562 | 1478488815 | Python | Python (2.7.6) | py | Runtime Error | 17 | 2824 | 1685 | def main():
N = input()
edges = [raw_input() for _ in range(N-1)]
K = input()
VP = [raw_input() for _ in range(K)]
VP = [map(int, _.strip().split()) for _ in VP]
edges = [map(int, _.strip().split()) for _ in edges]
# print VP
# print edges
scores = {}
for n_idx, value in VP:
scores[n_idx] = [value]
pre_defined = scores.keys()
# print scores
def check(value, n1, n2):
if value == (n1 - n2) or value == (n2 - n1):
return True
return False
for idx in pre_defined:
for n1, n2 in [l for l in edges if idx in l]:
v = scores[idx][0]
n = n1 if idx == n2 else n2
scores[n] = [_ for _ in scores.get(n, []) if check(_, n1, n2)] + [v - 1, v+1]
for n1, n2 in edges:
# print n1, n2
if scores.get(n1) is None and scores.get(n2) is None:
pass
else:
if scores.get(n1) is None:
for v in scores.get(n2, []):
scores[n1] = [_ for _ in scores.get(n1, []) if check(_, n1, n2)] + [v - 1, v+1]
elif scores.get(n2) is None:
for v in scores.get(n1, []):
scores[n2] = [_ for _ in scores.get(n2, []) if check(_, n1, n2)] + [v - 1, v+1]
# print scores.get(n1), scores.get(n2)
# print "----------"
# decide step
adding = []
for n in range(1, N+1):
v = scores.get(n, [None])[0]
adding.append(v)
if all([_ is not None for _ in adding]):
print "Yes"
for a in adding:
print a
else:
print "No"
# print scores
if __name__ == '__main__':
main() |
s325994561 | p03951 | u306412379 | 1599692493 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9140 | 110 | n = int(input())
s = input()
t = input()
for i in range(n):
if t.startswith(s[i:]):
x = n + i
print(x) |
s078914067 | p03951 | u697690147 | 1596771764 | Python | Python (3.8.2) | py | Runtime Error | 20 | 8872 | 355 | if (n == len(s) and (s == t)):
print(n)
else:
ind = [0]
for i in range(1, len(s)):
if s[-i:] == t[:i]:
ind.append(i)
ind.reverse()
for i in ind:
if i == 0:
print(2*n)
else:
res = s[0:-i] + t
if len(res) >= n:
print(len(res))
break |
s874299402 | p03951 | u137228327 | 1596686392 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9128 | 133 | n=int(input())
s=input()
t=input()
for i in range(n,2*n-1):
if s[:2*n-i] == t[2*n-i]:
print(i)
exit()
print(2*n) |
s587706928 | p03951 | u167906550 | 1596472080 | Python | PyPy3 (7.3.0) | py | Runtime Error | 85 | 68772 | 117 | n=input()
s=raw_input()
t=raw_input()
for i in xrange(0, n + 1):
if s[i : n] == t[0 : n - i]:
print n + i
break
|
s645046340 | p03951 | u167906550 | 1596472051 | Python | Python (3.8.2) | py | Runtime Error | 25 | 8976 | 117 | n=input()
s=raw_input()
t=raw_input()
for i in xrange(0, n + 1):
if s[i : n] == t[0 : n - i]:
print n + i
break
|
s356735631 | p03951 | u933068010 | 1596195849 | Python | PyPy3 (7.3.0) | py | Runtime Error | 91 | 74636 | 9472 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lscan(x) scanf("%I64d", &x)
#define lprint(x) printf("%I64d", x)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, n) for (int i = n - 1; i >= 0; i--)
const int mod = 1000000007;
ll gcd(ll a, ll b)
{
ll c = a % b;
while (c != 0)
{
a = b;
b = c;
c = a % b;
}
return b;
}
long long extGCD(long long a, long long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
struct UnionFind
{
vector<ll> data;
UnionFind(int sz)
{
data.assign(sz, -1);
}
bool unite(int x, int y)
{
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k)
{
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
ll size(int k)
{
return (-data[find(k)]);
}
};
ll M = 1000000007;
vector<ll> fac(2000011); //n!(mod M)
vector<ll> ifac(2000011); //k!^{M-2} (mod M)
ll mpow(ll x, ll n)
{
ll ans = 1;
while (n != 0)
{
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
ll mpow2(ll x, ll n, ll mod)
{
ll ans = 1;
while (n != 0)
{
if (n & 1)
ans = ans * x % mod;
x = x * x % mod;
n = n >> 1;
}
return ans;
}
void setcomb()
{
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 2000010; i++)
{
fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
}
ifac[2000010] = mpow(fac[2000010], M - 2);
for (ll i = 2000010; i > 0; i--)
{
ifac[i - 1] = ifac[i] * i % M;
}
}
ll comb(ll a, ll b)
{
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % M;
return tmp * fac[a] % M;
}
ll perm(ll a, ll b)
{
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
return fac[a] * ifac[a - b] % M;
}
long long modinv(long long a)
{
long long b = M, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= M;
if (u < 0)
u += M;
return u;
}
ll modinv2(ll a, ll mod)
{
ll b = mod, u = 1, v = 0;
while (b)
{
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= mod;
if (u < 0)
u += mod;
return u;
}
template <int mod>
struct ModInt
{
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p)
{
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p)
{
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p)
{
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p)
{
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const
{
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0)
{
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const
{
ModInt ret(1), mul(x);
while (n > 0)
{
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p)
{
return os << p.x;
}
friend istream &operator>>(istream &is, ModInt &a)
{
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using mint = ModInt<mod>;
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n)
{
int i, j, k, t;
vector<vector<ll>> c(n);
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
t = 0;
for (k = 0; k < n; k++)
t = (t + a[i][k] * b[k][j] % M) % M;
c[i].push_back(t);
}
}
return c;
}
template <typename Monoid>
struct SegmentTree
{
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
{
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x)
{
seg[k + sz] = x;
}
void build()
{
for (int k = sz - 1; k > 0; k--)
{
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x)
{
k += sz;
seg[k] = x;
while (k >>= 1)
{
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b)
{
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
{
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const
{
return seg[k + sz];
}
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type)
{
while (a < sz)
{
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C>
int find_first(int a, const C &check)
{
Monoid L = M1;
if (a <= 0)
{
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
{
if (a & 1)
{
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C>
int find_last(int b, const C &check)
{
Monoid R = M1;
if (b >= sz)
{
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1)
{
if (b & 1)
{
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <unsigned mod>
struct RollingHash
{
vector<unsigned> hashed, power;
inline unsigned mul(unsigned a, unsigned b) const
{
unsigned long long x = (unsigned long long)a * b;
unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
asm("divl %4; \n\t"
: "=a"(d), "=d"(m)
: "d"(xh), "a"(xl), "r"(mod));
return m;
}
RollingHash(const string &s, unsigned base = 10007)
{
int sz = (int)s.size();
hashed.assign(sz + 1, 0);
power.assign(sz + 1, 0);
power[0] = 1;
for (int i = 0; i < sz; i++)
{
power[i + 1] = mul(power[i], base);
hashed[i + 1] = mul(hashed[i], base) + s[i];
if (hashed[i + 1] >= mod)
hashed[i + 1] -= mod;
}
}
unsigned get(int l, int r) const
{
unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
if (ret >= mod)
ret -= mod;
return ret;
}
unsigned connect(unsigned h1, int h2, int h2len) const
{
unsigned ret = mul(h1, power[h2len]) + h2;
if (ret >= mod)
ret -= mod;
return ret;
}
int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2)
{
int len = min(r1 - l1, r2 - l2);
int low = -1, high = len + 1;
while (high - low > 1)
{
int mid = (low + high) / 2;
if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
low = mid;
else
high = mid;
}
return (low);
}
};
using RH = RollingHash<1000000007>;
template <typename T>
struct edge
{
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x)
{
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;
template <typename G>
struct DoublingLowestCommonAncestor
{
const int LOG;
vector<int> dep;
const G &g;
vector<vector<int>> table;
DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size()))
{
table.assign(LOG, vector<int>(g.size(), -1));
}
void dfs(int idx, int par, int d)
{
table[0][idx] = par;
dep[idx] = d;
for (auto &to : g[idx])
{
if (to != par)
dfs(to, idx, d + 1);
}
}
void build()
{
dfs(0, -1, 0);
for (int k = 0; k + 1 < LOG; k++)
{
for (int i = 0; i < table[k].size(); i++)
{
if (table[k][i] == -1)
table[k + 1][i] = -1;
else
table[k + 1][i] = table[k][table[k][i]];
}
}
}
int query(int u, int v)
{
if (dep[u] > dep[v])
swap(u, v);
for (int i = LOG - 1; i >= 0; i--)
{
if (((dep[v] - dep[u]) >> i) & 1)
v = table[i][v];
}
if (u == v)
return u;
for (int i = LOG - 1; i >= 0; i--)
{
if (table[i][u] != table[i][v])
{
u = table[i][u];
v = table[i][v];
}
}
return table[0][u];
}
};
int main()
{
int n, i, j;
string s,t;
cin >> n >> s >> t;
int ans = 2 * n;
for (i = 0; i < n;i++){
int flag = 1;
for (j = i; j < n;j++)
if(s[j]!=t[j-i])
flag = 0;
if(flag){
ans = n + i;
break;
}
}
cout << ans << endl;
} |
s910446263 | p03951 | u766566560 | 1593916704 | Python | Python (3.8.2) | py | Runtime Error | 25 | 9084 | 142 | N = int(input())
s = input()
t = input()
if s[N-3] == t[0]:
print(len(s[:N-3] + t))
elif s == t:
print(len(s))
else:
print(len(s + t))
|
s235338515 | p03951 | u766566560 | 1593661672 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9136 | 201 | N = int(input())
s = input()
t = input()
if s[N-1] == t[0]:
if s[N-2] == t[1]:
print(len(s[:N-2] + t))
exit()
print(len(s[:N-1] + t))
elif s == t:
print(len(s))
else:
print(len(s + t)) |
s822592088 | p03951 | u350093546 | 1593658058 | Python | Python (3.8.2) | py | Runtime Error | 22 | 8940 | 103 | n=int(input())
s=input()
t=input()
while True:
if s==t:
break
s=s[1:]
t=[:-1]
n+=1
print(n) |
s618530352 | p03951 | u699089116 | 1593481145 | Python | PyPy3 (7.3.0) | py | Runtime Error | 87 | 74804 | 144 | n = int(input())
s = input()
t = input()
for i in range(n):
if s[i:] == t[:n-i]:
print(n + cnt)
exit()
else:
print(n*2) |
s256155000 | p03951 | u841021102 | 1593059600 | Python | Python (3.8.2) | py | Runtime Error | 27 | 8964 | 187 | n = int(input())
s = input()
t = input()
answer = n
for i in range (n + 1) :
if answer == n :
newstring = s[0:i] + t[:n]
if newstring[0:n] == s :
answer += i
print (answer)
|
s913441679 | p03951 | u841021102 | 1593059521 | Python | Python (3.8.2) | py | Runtime Error | 26 | 8892 | 185 | n = int(input())
s = input()
t = input()
answer = n
for i in range (n + 1) :
if answer == n :
newstring = s[0:i] + t[:n]
if newstring[0:n] == s :
answer += i
print (answer) |
s663098902 | p03951 | u841021102 | 1593052321 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9020 | 152 | s = input()
t = input()
s1 = []
t1 = []
for i in range(0 , n):
s1.append(s[i])
for i in range(0 , n):
t1.append(t[i])
a = set(s1 + t1)
print(len(a)) |
s043013257 | p03951 | u290187182 | 1592089343 | Python | PyPy3 (2.4.0) | py | Runtime Error | 259 | 62572 | 481 | import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *
import numpy as np
import math
if __name__ == '__main__':
n = int(input())
s =input()
t = input()
count = 2*n
for i in range(n):
if t[i] == s[n-i-1]:
count-=1
else:
break
if s == t:
print(n)
else:
print(count) |
s614806799 | p03951 | u391819434 | 1591645917 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 268 | N=int(input())
S=input()
T=input()
ans=S+T
while ans[-N:]==T:
recover=ans
if ans[N-1]==ans[N]:
ans=ans[:N]+ans[N+1:]
else:
recover=ans
break
if S in T:
print(len(T))
elif T in S:
print(len(S))
else:
print(len(recover)) |
s787783550 | p03951 | u408375121 | 1589487546 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 193 | n = int(input())
s = input()
t = input()
for i in range(n):
cnt = 0
for j in range(i, n):
if s[j] != t[j-i]:
break
cnt += 1
if cnt == n-i:
ans = n+i
break
print(ans) |
s585000632 | p03951 | u408375121 | 1589486965 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 119 | n = int(input())
s = input()
t = input()
for i in range(n):
if s[i:] == t[:n-i]:
ans = n + i
break
print(ans) |
s522220974 | p03951 | u335793707 | 1588371377 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 179 | n = int(input())
s = input()
t = input()
if s == t:
print(n)
return
r = 0
for i in range(0, n):
if s[-(i + 1)] != t[i]:
break
r += 1
print((n * 2) - r)
|
s504822576 | p03951 | u114641312 | 1587927628 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1012 | # from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)
# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb
# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
S = input()
T = input()
ans = 2*N
for i in range(N,-1,-1):
# ST = S[:i] + T
print(ST,ST[:i],ST[i:])
if ST[:N]==S and ST[-N:]==T:
ans = min(len(ST),ans)
print(ans)
# print(*ans) # unpackして出力。間にスペースが入る
# for row in board:
# print(*row,sep="") #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
|
s341832489 | p03951 | u797550216 | 1586919577 | Python | PyPy3 (2.4.0) | py | Runtime Error | 167 | 38256 | 129 | import sys
n = int(input())
s = input()
t = input()
for i in range(n):
if s[i:] == t[:n-i]:
print(n+i)
exit()
print(2*n) |
s752395277 | p03951 | u606523772 | 1586910483 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 202 | N = int(input())
s = list(input())
t = list(input())
cnt = 0
if s==t:
ans = N
elif N==1:
ans = N*2
else:
for i in range(N):
if s[i:]==t[:-i]:
ans = N*2 - (N-i)
print(ans) |
s757893287 | p03951 | u606523772 | 1586910163 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 177 | N = int(input())
s = list(input())
t = list(input())
cnt = 0
if s==t:
ans = N
else:
for i in range(N):
if s[i:]==t[:-i]:
ans = N*2 - (N-i)
print(ans) |
s251677703 | p03951 | u942123514 | 1581542743 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 96 | n=int(input())*2
s=input()
t=input()
a=0
b=-1
while s[b] == t[a]:
a=a+1
b=b-1
print(n-a) |
s427020087 | p03951 | u423585790 | 1578078643 | Python | PyPy3 (2.4.0) | py | Runtime Error | 180 | 38512 | 1137 | #!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
#solve
def solve():
n = II()
s = S()
t = S()
for i in range(n):
if s[i:] == t[: n - i]:
print(n + i)
return
primt(2 * n)
return
#main
if __name__ == '__main__':
solve()
|
s333311076 | p03951 | u102960641 | 1577347197 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 119 | n,x = map(int, input().split())
if n != x:
print("No")
else:
print("Yes")
for i in range(1, 2 * n):
print(i)
|
s063972639 | p03951 | u094191970 | 1576009079 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 101 | n=int(input())
s=input()
t=input()
for i in range(n):
if s[-i-1:]==t[:i+1]:
cnt=i+1
print(2*n-cnt) |
s039342403 | p03951 | u066455063 | 1575772904 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 249 | N = int(input())
s = input()
t = input()
ans = 0
if s == t:
print(N)
exit()
else:
s = input()[::-1]
for i in range(N):
if s[i] != t[i]:
ans += len(s)
ans += len(t[i:])
break
print(ans)
|
s961827445 | p03951 | u595893956 | 1575516782 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 172 | import sys
n=int(input())
s=input()
t=input()
if s == t:
print len(s)
sys.exit()
for i in range(1,n):
tmp=s+t[-1*i:]
if tmp[-n:] == t:
print n+i
sys.exit()
|
s937296848 | p03951 | u623687794 | 1573136931 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 270 | n,x=map(int,input().split())
if x==1 or x==2*n-1:print("No")
else:
print("Yes")
b=[0]*n
b[n//2]=x
b[n//2-1]=x-1
b[n//2+1]=x+1
tor=[i+1 for i in range(n)]
del tor[x-2:x+1]
for i in range(n):
if b[i]==0:
b[i]=tor.pop()
for i in b:
print(i)
|
s139094928 | p03951 | u623687794 | 1573136765 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 279 | n,x=map(int,input().split())
if x==1 or x==n:print("No")
else:
print("Yes")
b=[0]*n
b[n//2]=x
b[n//2-1]=x-1
b[n//2+1]=x+1
tor=[i+1 for i in range(n)]
del tor[x-2:x+1]
print(tor)
for i in range(n):
if b[i]==0:
b[i]=tor.pop()
for i in b:
print(i)
|
s395470752 | p03951 | u889344512 | 1565372625 | Python | PyPy3 (2.4.0) | py | Runtime Error | 178 | 38640 | 131 | n=int(input())
s=input()
t=input()
count=0
for i in range(n):
if s[n-1-i:n]==t[0:i+1]:
count+=i+1
break
print(2×n-count) |
s682025145 | p03951 | u889344512 | 1565371998 | Python | PyPy3 (2.4.0) | py | Runtime Error | 168 | 38256 | 131 | n=int(input())
s=input()
t=input()
count=0
for i in range(n):
if s[n-1-i]==t[i]:
count+=1
else:
break
print(2×n-count) |
s984575618 | p03951 | u539517139 | 1562073482 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 112 | n=int(input())
s=input()
t=input()
for i in range(n):
if s[i:]==t[:n-i]:
l=n+i
break
print(min(n*2,l)) |
s096524939 | p03951 | u196697332 | 1559860298 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 201 | N = int(input())
s = str(input())
t = str(input())
word = s + t
for i in range(N):
if word[len(s) - 1] == word[len(s)] and :
s = s[:N - 1]
word = s + t
print(len(word))
|
s380283806 | p03951 | u196697332 | 1559859993 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 323 | import sys
N = int(input())
s = str(input())
t = str(input())
word = s + t
for letter in s:
if letter not in letter_list:
letter_list.append(letter)
for letter in t:
if letter not in list(letter_dict.keys()):
letter_dict[letter] = 1
if s == t:
print(N)
sys.exit()
else:
print(len(letter_dict)) |
s780896686 | p03951 | u196697332 | 1559859950 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 316 | import sys
N = int(input())
s = str(input())
t = str(input())
word = s + t
if s == t:
print(N)
sys.exit()
for letter in s:
if letter not in letter_list:
letter_list.append(letter)
for letter in t:
if letter not in list(letter_dict.keys()):
letter_dict[letter] = 1
print(len(letter_dict)) |
s269342378 | p03951 | u196697332 | 1559859918 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 292 | N = int(input())
s = str(input())
t = str(input())
word = s + t
if s == t:
print(N)
for letter in s:
if letter not in letter_list:
letter_list.append(letter)
for letter in t:
if letter not in list(letter_dict.keys()):
letter_dict[letter] = 1
print(len(letter_dict)) |
s190946866 | p03951 | u513900925 | 1555132247 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 158 | N = input()
N =int(N)
s = input()
t = input()
for i in range(N):
q = s[-(i+1):]
r = t[:i+1]
if q == r :
x = q
y =i+1
print(N*2-y) |
s536441237 | p03951 | u565204025 | 1555132218 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3060 | 358 | # -*- coding: utf-8 -*-
n = int(input())
s = list(input())
t = list(input())
for i in range(n):
match = True
for j in range(n):
if i + j < n:
if s[i + j] != t[j]:
match = False
if match:
if i == 0:
print(n)
else:
print(n + i)
break
else:
print(len(n * 2))
|
s216014610 | p03951 | u513900925 | 1555131983 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 162 | N = input()
N =int(N)
s = input()
t = input()
for i in range(N):
q = s[-(i+1):]
r = t[:i+1]
if q == r :
x = q
y =i+1
print(s[:N-y]+t) |
s384583680 | p03951 | u367130284 | 1553724601 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 93 | input();s=input();t=input();print(2*len(s)-max([i for i in range(n+1)if s[-i:]==t[:i]]or[0])) |
s580729007 | p03951 | u887207211 | 1552534582 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 127 | N = int(input())
S = input()
T = input()
for i in range(N, 0, -1):
if(S[-i:] == T[:i]):
tmp = i
break
print(N*2-tmp) |
s508306252 | p03951 | u741397536 | 1552010819 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 208 | N = int(input())
s = input()
t = input()
count = 0
for i in range(len(s)):
if t[i] == s[-i-1]:
count += 1
else:
break
if s = t:
print(len(s))
else:
print(len(s)+len(t)-count) |
s167027693 | p03951 | u023229441 | 1550982711 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 153 | n=int(input())
A=input()
B=input()
s=0
ans=2*n
for i in range(n)
if A[-i-1:]!=B[:i+1]:
s=1
print(ans)
exit()
else:
ans-=1
print(ans) |
s585793907 | p03951 | u371467115 | 1546038123 | Python | Python (3.4.3) | py | Runtime Error | 2103 | 3060 | 154 | n=int(input())
s=[input() for i in range(n)]
t=[input() for j in range(n)]
s.reverse()
l=0
for k in range(n):
while s[k]==t[k]:
l+=1
print(l) |
s671527802 | p03951 | u853900545 | 1542822284 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 157 | n = int(input())
s = input()
t = input()
c == 1
for i in range(n):
if s[n-i:n] == t[0:i+1]:
print(i+1)
c = 0
break
if c == 1:
print(0) |
s950060498 | p03951 | u030726788 | 1521598018 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 117 | n=int(input())
s=input()
t=input()
for i in range(n):
if(t[i]==s[-(i+1)]):
t=t[1:]
else:break
print(n+len(t)) |
s357320048 | p03951 | u986399983 | 1490053349 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 139 | N = int(input())
s = input()
l = input()
for i in range(1,N):
if s[-i:]!=l[:i]:
a=2*N-i+1
break
print(a if s!=l else N) |
s874634704 | p03951 | u272496669 | 1477803427 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 83 | n = int(input())
s = str(input())
t = str(input())
i = 0
while t.find(s[i,n])>-1:
|
s206051932 | p03951 | u820351940 | 1477801483 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 273 | N, K = map(int, input().split())
m = 2 * N - 1
if 2 <= K < m:
mid = list((3, 2, 1) if K == 2 else (K - 1, K, K + 1, K - 2))
a = list(set(range(1, m + 1)) - set(mid))
print("Yes\n" + "\n".join(map(str, a[:m//2 - 1] + mid + a[m//2 - 1:])))
else:
print("No")
|
s273111243 | p03951 | u582243208 | 1477798868 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 257 | n=int(input())
s=input()
t=input()
if s==t:
print(n)
else:
ans=2*n
f=False
for i in range(n):
for j range(i+1):
if t[j]!=s[n-1-i+j]:
f=True
if not f:
break
ans-=1
print(ans) |
s236923514 | p03951 | u765237551 | 1477796684 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 411 | N, x = map(int, input().split())
if x==1 or x==2*N-1:
print('No')
else:
print('Yes')
if x <= 2*N:
y = list(i for i in range(2, 2*N-2) if i!=x)
l = len(y)//2
print("\n".join(map(str, y[:l] + [2*N-1, x, 1, 2*N-2] + y[l:])))
else:
y = list(i for i in range(3, 2*N-1) if i!=x)
l = len(y)//2
print("\n".join(map(str, y[:l] + [2*N-1, 1, x, 2] + y[l:]))) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.