def ispal(s):
halfl = len(s) // 2
return s[:halfl] == ''.join(reversed(s[len(s) - halfl:]))
line = input()
l = len(line)
maxl = 1
for length in range(1, l + 1):
for start in range(l - length + 1):
substr = line[start:start + length]
if ispal(substr):
maxl = max(maxl, len(substr))
print(maxl)
# coding:utf-8
def string2time(s: str):
spl = s.split(':')
return int(spl[0]) * 60 + int(spl[1])
def inrush(t: int):
return (t >= 420 and t < 600) or (t >= 900 and t < 1140)
totalt = 0
apart = string2time(input())
while totalt < 120:
totalt += 5 if inrush(apart) else 10
apart = (apart + 10) % 1440
print(str(apart // 60).rjust(2, '0') + ':' + str(apart % 60).rjust(2, '0'))
# coding:utf-8
qtype = input()
n = int(input())
citya = list(map(int, input().split()))
cityb = list(map(int, input().split()))
total = sorted(citya + cityb, reverse=True)
if qtype == '1':
print(sum(total[::2]))
else:
print(sum(total[:len(total) // 2]))
from collections import Counter
#import sys
# INPUTFILE=sys.stdin #从键盘读
INPUTFILE = open('s1.in', 'r') # 从文件读
def input():
return INPUTFILE.readline().strip()
if __name__ == '__main__':
line1 = Counter(input())
line2 = Counter(input())
line2.pop('*', None)
line1.subtract(line2)
print('N' if any(i < 0 for i in line1.values()) else 'A')
2
5
202 177 189 589 102
17 78 1 496 540
#import sys
# INPUTFILE=sys.stdin #从键盘读
INPUTFILE = open('s2.in', 'r') # 从文件读
def input():
return INPUTFILE.readline().strip()
if __name__ == '__main__':
qtype = input()
n = int(input())
citya = list(map(int, input().split()))
cityb = list(map(int, input().split()))
total = sorted(citya + cityb, reverse=True)
if qtype == '1':
print(sum(total[::2]))
else:
print(sum(total[:len(total) // 2]))
8 2
5 2
0 1
0 2
2 3
4 3
6 1
1 5
7 3
# coding:utf-8
#import sys
# INPUTFILE=sys.stdin #从键盘读
INPUTFILE = open('s3.in', 'r') # 从文件读
def input():
return INPUTFILE.readline().strip()
class Graph(dict):
def addnode(self, node):
self[node] = set()
def addedge(self, node1, node2):
self[node1].add(node2)
self[node2].add(node1)
def findpath(self, start, end, path=[]):
""" *不包括* 终点的路径"""
if start in path:
return None
if start == end:
return path
path = path.copy()
path.append(start)
for adj in self[start]:
r = self.findpath(adj, end, path)
if r is not None:
return r
def solve(graph, current, plan, path=[]):
"""current: 现在位置, plan: 还没去的地方, path: 走过的路"""
global presult
if len(plan) == 0:
presult.append(path)
return
for p in plan:
newplan = plan.copy()
newplan.remove(p)
solve(graph, p, newplan, path + graph.findpath(current, p))
if __name__ == '__main__':
line1 = input().split()
n = int(line1[0]) # total restaurants
m = int(line1[1]) # num Pho restaurants
phos = set(map(int, input().split()))
waterloo = Graph()
for p in range(n):
waterloo.addnode(p)
for _ in range(n - 1):
line = input().split()
waterloo.addedge(int(line[0]), int(line[1]))
minpath = 100000
for p in phos:
newphos = phos.copy()
newphos.remove(p)
presult = list()
solve(waterloo, p, newphos)
minpath = min(minpath, min(map(len, presult)))
print(minpath)
#import sys
# INPUTFILE=sys.stdin #从键盘读
INPUTFILE = open('s4.in', 'r') # 从文件读
def input():
return INPUTFILE.readline().strip()
if __name__ == '__main__':
presult = list()
def combiner(row):
global presult
cancmb = False
for i in range(len(row) - 1):
if row[i] == row[i + 1]:
cancmb = True
newrow = row[:i] + [row[i] * 2] + row[i + 2:]
combiner(newrow)
for i in range(len(row) - 2):
if row[i] == row[i + 2]:
cancmb = True
newrow = row[:i] + [row[i] * 2 + row[i + 1]] + row[i + 3:]
combiner(newrow)
if not cancmb:
presult.append(row)
n = int(input())
rice = list(map(int, input().split()))
combiner(rice)
maxrice = 0
for result in presult:
maxrice = max(maxrice, max(result))
print(maxrice)
#import sys
# INPUTFILE=sys.stdin #从键盘读
INPUTFILE = open('s5.in', 'r') # 从文件读
def input():
return INPUTFILE.readline().strip()
if __name__ == '__main__':
line1 = input().split()
n = int(line1[0]) # num cells
t = int(line1[1]) # num generations
line2 = input()
cells = list(map(lambda x: bool(int(x)), line2))
for _ in range(t):
nextgen = list()
for i in range(n):
nextgen.append(True if cells[(i - 1) % n] != cells[(i + 1) % n] else False)
cells = nextgen
print(''.join(map(lambda x: '1' if x else '0', cells)))
评论