Problem:


Score : 500 points

Problem Statement

There is a string s of length 3 or greater.
No two neighboring characters in s are equal.

Takahashi and Aoki will play a game against each other.
The two players alternately performs the following operation, Takahashi going first:

Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.

The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.

Constraints

3 ≤ |s| ≤ 10^5

s consists of lowercase English letters.

No two neighboring characters in s are equal.

Input

The input is given from Standard Input in the following format:

s

Output

If Takahashi will win, print First. If Aoki will win, print Second.

Sample Input 1

aba

Sample Output 1

Second

Takahashi, who goes first, cannot perform the operation, since removal of the b, which is the only character not at either ends of s, would result in s becoming aa, with two as neighboring.

Sample Input 2

abc

Sample Output 2

First

When Takahashi removes b from s, it becomes ac.
Then, Aoki cannot perform the operation, since there is no character in s, excluding both ends.

Sample Input 3

abcab

Sample Output 3

First



Sample input:
aba


Sample output:
Second

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

s = input()

def judge() :
    if len(s) == 3 :
        if s[0] == s[2] :
            return 'Second'
        else :
            return 'First'

    d = defaultdict(int)
    
    for s_ in s :
        d[s_] += 1
    
    if len(d) == 3 :
        one = []
        for k, v in d.items() :
            if v == 1 :
                one.append(k)
        
        if len(one) == 1 :
            for i in range(1, len(s) - 1) :
                if s[i] == one[0] :
                    if s[i-1] != s[i+1] :
                        return 'Fisrt'
                    else :
                        break

    if len(s) % 2 == 1 :
        return 'First'
    else :
        return 'Second'
        
print(judge())

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
if N%2==1:
    f=True
    i=0
    a=S[0]
    while(i<N):
        if S[i]!=a:
            f=False
            break
        i+=2
    if f:
        num=0
    else:
        num=N-2
else:
    s=S[0]+S[-1]
    if S==s*(N//2):
        num=0
    else:
        num=N-2
if num%2==1:
    print("First")
else:
    print("Second")

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


def main():
    s = input()
    n = len(s)
    if s[0] == s[n - 1] and n % 2 == 1:
        print("Second")
    else:
        print("First")


main()

Submission status: Wrong Answer

Solution code:
import collections
S = input()
N = len(S)
count = collections.defaultdict(int)
if S[0] == S[-1]:
    for i in range(1, N - 1):
        count[S[i]] += 1
    m = -1
    if (N - max(v for v in count.values())) % 2:
        print('First')
    else:
        print('Second')
elif (N - count[S[0]] - count[S[-1]]) % 2:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
s = input()
if s[0] == s[-1]:
  print('Second')
else:
  print('First')

Submission status: Wrong Answer

Solution code:
s = raw_input()

if s[0] == s[-1]:
	if len(s) % 2 == 0: print "Second"
	else: print "First"
else:
	if len(s) % 2 == 0: print "First"
	else: print "Second"

Submission status: Wrong Answer

Solution code:
import sys

def check(S):
    even = set()
    odd = set()
    for i in range(len(S)):
        if i % 2 == 0:
            odd.add(S[i])
        else:
            even.add(S[i])

    return len(even) == len(odd) == 1


def can_checkmate(S):
    chrs = set(S)
    if len(chrs) != 3:
        return False

    for c in chrs:
        S_ = S
        S_.remove(c)
        if check(S_):
            return True

    return False


def main():
    input = sys.stdin.readline
    S = [c for c in input().strip()]

    if check(S):
        return 'Second'

    if S[0] == S[-1]:
        if len(S) % 2 == 0 or can_checkmate(S):
            return 'First'

        else:
            return 'Second'
    else:
        if len(S) % 2 == 1:
            return 'First'

        elif can_checkmate(S):
            return 'First'

        else:
            return 'Second'


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
s = input()
leng = len(s)

a = s[0]
b = s[1]
flag = True

for i in s:
  if i != a and i != b:
    flag = False
    break
if flag:
  print('Second')
  exit()

if (leng - 2) % 2 == 0:
  print('Second')
else:
  print('First')

Submission status: Wrong Answer

Solution code:
a = input()
if a[0] != a[-1]:
  print("First")
else:
  print("Second")

Submission status: Wrong Answer

Solution code:
a = input()
if a[0] == a[-1]:
  print("First")
else:
  print("Second")

Submission status: Wrong Answer

Solution code:
Ls=input()
ls=[]
result=0
for i in Ls:
     if i not in ls:
          result+=1
          ls.append(i)
LEN=len(ls)
if LEN%2==0:
     print('Second')
else:
     print('First')

Submission status: Wrong Answer

Solution code:
Ls=input()
ls=[]
result=0
def fun():
     print('11111')
     print('22222')
for i in Ls:
     if i not in ls:
          result+=1
          ls.append(i)
LEN=len(ls)
if LEN%2==0:
     print('Second')
else:
     print('First')

Submission status: Wrong Answer

Solution code:
Ls=input()
ls=[]
result=0
def fun():
     print('11111')
     print('22222')
     print('3')
     print('4')
for i in Ls:
     if i not in ls:
          result+=1
          ls.append(i)
LEN=len(ls)
if LEN%2==0:
     print('Second')
else:
     print('First')

Submission status: Wrong Answer

Solution code:
s=input()
def check(s):
    for i in range(len(s)):
        if s[i]!=s[i%2]:return False
    return True
if check(s):print('Second')
else:
    if len(s)%2==1:print('First')
    else:print('Second')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import deque, Counter, defaultdict
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, product, combinations, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial

def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

l,r = 0,1
mx = 0
# 外ループで左を動かす
while l < N:
    # 内ループは条件を満たす限り右を動かす
    while r < N and S[l] != S[r]:
        r += 1
    # 同じ文字までの間隔が最大の所を探す
    if r < N:
        mx = max(r - l - 1, mx)
    if l == r:
        # 左が右に追いついたら、右も左に合わせて+1する
        r += 1
    l += 1

if mx == 0:
    if N % 2 == 0:
        print('Second')
    else:
        print('First')
else:
    if mx % 2 == 0:
        print('First')
    else:
        print('Second')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8

s = input()

if (s[0] == s[-1]) ^ (len(s) % 2 == 0):
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
s = list(input())
fir, sec = 0, 0

x, i = 0, 1
while len(s)-1 != i:
    if s[i-1] == s[i+1]:
        i += 1
        x += 1
    else:
        s.remove(s[i])
        if x % 2 == 0:
            fir += 1
        else:
            sec += 1
        x += 1

if fir <= sec:
    print('Second')
else:
    print('First')

Submission status: Wrong Answer

Solution code:
s=input()
eo=len(s)
if eo%2==0 and s[0]==s[-1]:
    print("Second")
elif eo%2==0 and s[0]!=s[-1]:
    print("First")
elif eo%2!=0 and s[0]==s[-1]:
    print("Second")
elif eo%2!=0 and s[0]!=s[-1]:
    print("First")

Submission status: Wrong Answer

Solution code:
s = input()
if s[0] == s[-1]:
  if len(s) % 2 == 1:
    print("Second")
  else:
    print("First")
else:
  if len(s) % 2 == 0:
    print("First")
  else:
    print("Second")

Submission status: Wrong Answer

Solution code:

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(S):
    even = len(S) % 2 == 0
    hte = S[0] == S[1]

    if even != hte:
        return 'Second'
    return 'First'


def main():
    S = read_str()

    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 13 15:44:15 2018
ABC048D
@author: maezawa
"""
import collections

s = input()

c = collections.Counter(s)
n = len(s)
n0 = s.count(s[0])
n1 = s.count(s[-1])

if s[0] == s[-1]:
    if (n-n0+1)%2 != 0:
        print('First')
    else:
        print('Second')
elif (n-2*min(n0,n1))%2 != 0:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
import collections

s = input()

c = collections.Counter(s)
n = len(s)
n0 = s.count(s[0])
n1 = s.count(s[-1])

if s[0] == s[-1]:
    if (n-n0+1)%2 != 0:
        print('First')
    else:
        print('Second')
elif (n-min(n0,n1))%2 != 0:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 13 15:44:15 2018
ABC048D
@author: maezawa
"""
import collections

s = input()

c = collections.Counter(s)
n = len(s)
n0 = s.count(s[0])
n1 = s.count(s[-1])

if s[0] == s[-1]:
    if (n-n0+1)%2 != 0:
        print('First')
    else:
        print('Second')
elif (n-n0-n1)%2 != 0:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
S = input()
print('First' if (len(S) % 2 == 2) == (S[0] == S[-1]) else 'Second')

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

s = stdin.readline().rstrip().split()[0]

if len(s) % 2 == 1 and s[0] == s[len(s)-1]:
    print('Second')
elif len(s) % 2 == 1 and s[0] != s[len(s)-1]:
    print('First')
elif len(s) % 2 == 0 and s[0] != s[len(s)-1]:
    print('First')
elif len(s) % 2 == 0 and s[0] == s[len(s)-1]:
    print('Second')

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

s = stdin.readline().rstrip().split()[0]

if len(s) % 2 == 1 and s[0] == s[len(s)-1]:
    print('Second')
elif len(s) % 2 == 1 and s[0] != s[len(s)-1]:
    print('First')
elif len(s) % 2 == 0 and s[0] != s[len(s)-1]:
    print('First')
else:
    print('Second')

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)

x = S[0]
y = S[1]
for i in range(2, N):
    if i % 2 == 0:
        if S[i] != x:
            break
    else:
        if S[i] != y:
            break
else:
    print("Second")
    exit()

if N % 2 == 0 and S[0]==S[-1]:
    print("First")
elif N % 2 == 1 and S[0]==S[-1]:
    print("Second")
elif N % 2 == 0:
    print("First")
else:
    print("Second")

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)

x = S[0]
y = S[1]
for i in range(2, N):
    if i % 2 == 0:
        if S[i] != x:
            break
    else:
        if S[i] != y:
            break
else:
    print("Second")
    exit()

if N % 2 == 0 and S[0]==S[-1]:
    print("First")
elif N % 2 == 0:
    print("Second")
else:
    print("First")

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)

x = S[0]
y = S[1]
for i in range(2, N):
    if i % 2 == 0:
        if S[i] != x:
            break
    else:
        if S[i] != y:
            break
else:
    print("Second")
    exit()

if N % 2 == 0:
    print("Second")
else:
    print("First")

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
op = 0
i = 0
while i < l-2:
    if not s[i-op]==s[i+2-op]:
        s = s[:i+1-op]+s[i+1-op:]
        op += 1
    i += 1
print('First' if op%2==1 else 'Second')

Submission status: Wrong Answer

Solution code:
x=str(input())
if x[0]==x[-1] or len(x)%2==0:
 print('Second')
else:
 print('First')

Submission status: Wrong Answer

Solution code:
s = input()
print("Second") if(s[0] == s[-1]) else print("First")

Submission status: Wrong Answer

Solution code:
s = input()
print("Second") if(len(s)%2 and s[0] == s[-1]) else print("First")

Submission status: Wrong Answer

Solution code:
s = input()

b1 = bool(len(s)%2)
b2 = ( s[0] == s[len(s)-1] )

if b1 ^ b2:
    print("Second")
else:
    print("First")

Submission status: Wrong Answer

Solution code:
def check_duplicate(s):
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            return True
    return False

def find_status(i):
    if i % 2 == 1:
        return "First"
    else:
        return "Second"

s = raw_input()
i = 1
while (True):
    status = "First"
    flag = "NO"
    if len(s) == 2:
        print "only 2 left, stoppng... loser:", find_status(i), "winner:", find_status(i+1)
    for x in range(1, len(s)-1):
        tmp = s[:x] + s[x+1:]
        if check_duplicate(tmp) == False:
            flag = "OK"
            print "round", i, "remove_char=", s[x],". Go to the next round."
            s = tmp
            i += 1
            break
        else:
            print "round", i, "failed to remove_char=", s[x]," on", i, "of", s
            continue
    if flag == "NO":
        print "Failed to step forward for the round", i, 
        print "loser:", find_status(i), 
        print "winner:", find_status(i+1)
        break

Submission status: Wrong Answer

Solution code:
def check_duplicate(s):
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            return True
    return False

def find_status(i):
    if i % 2 == 1:
        return "First"
    else:
        return "Second"

s = raw_input()
i = 1
while (True):
    status = "First"
    flag = "NO"
    if len(s) == 2:
        print "only 2 left, stoppng... loser:", find_status(i), "winner:", find_status(i+1)
    for x in range(1, len(s)-1):
        tmp = s[:x] + s[x+1:]
        if check_duplicate(tmp) == False:
            flag = "OK"
            print "round", i, "remove_char=", s[x],". Go to the next round."
            s = tmp
            i += 1
            break
        else:
            print "round", i, "failed to remove_char=", s[x]," on", i, "of", s
            continue
    if flag == "NO":
        print "Failed to step forward for the round", i, 
        print "loser:", find_status(i), 
        print "winner:", find_status(i+1)
        break
    if i > 1000:
        break

Submission status: Wrong Answer

Solution code:
def main():
	s  = len(input())
	if (s-2)%2==0:
		print("First")
	else:
		print("Second")	
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import random 
def main():
	s  = list(input())
	count = 0
	while True:
		idx = count
		if s[idx] == s[idx+1] or s[idx] == s[idx-1]:
			break
		count += 1

	if count%2==0:
		print("First")
	else:
		print("Second")	
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import random 
def main():
	s  = list(input())
	count = 0
	while True:
		idx = random.randint(0,len(s))
		if s[idx] == s[idx+1] or s[idx] == s[idx-1]:
			break
		count += 1
	if count%2==0:
		print("First")
	else:
		print("Second")	
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
a = raw_input()
s_size = len(a)
a_list=[]
n = 0
p = 0
for b in range(0,len(a)):
    a_list.append(a[b])
w = 0
fi = 0
k = 1

while w == 0:
    print a_list
    s_size = len(a_list)
    #print s_size
    p = 0
    fi = fi + 1
    for n in range(1,s_size - 1):
        #print a_list[n - 1] + a_list[n] + a_list[n + 1]
        #print "fas"
        #print a_list[n]
        if s_size == 3:
            w = 1
            if fi == 1:
                k = k + 1
            
            continue
        
        if a_list[n - 1] != a_list[n + 1]:
            #print "if_BUN"
            a_list.pop(n)
            k = k + 1
            p = 1
            break

    if p == 0:
        w = 1



if k%2==0:
    print "Second"
else:
    print "First"

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
n -= 1

if s[0] == s[n-1]:
    print("First" if (n % 2 == 0) else "Second")
else:
    print("First" if (n % 2 == 1) else "Second")

Submission status: Wrong Answer

Solution code:
s=raw_input()
ls=list(s)

def candelete(n):
    if ls[n-1]==ls[n+1]:
        return False
    else:
        return True
count=0
for i in range(1,len(ls)-1):
    if candelete(i):
        count+=1
if count %2==0:
    print "Second"
else:
    print "First"

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
n -= 1

print(n)
if s[0] == s[n-1]:
    print("First" if (n % 2 == 0) else "Second")
else:
    print("First" if (n % 2 == 1) else "Second")

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==3 and s[0]==s[2]:
 print("Second")
else:
 print("First")

Submission status: Wrong Answer

Solution code:
line = list(input())
count = 0
for i, s in enumerate(line[0:-2]):
  if line[i] != line[i+2]:
    count+=1
 
if count % 2 == 0:
  print("Second")
else:
  print("First")

Submission status: Wrong Answer

Solution code:
line = list(input())
count = 0
for i, s in enumerate(line[0:-2]):
  if line[i] == line[i+2]:
    count+=1

if count % 2 == 0:
  print("Second")
else:
  print("First")

Submission status: Wrong Answer

Solution code:
s=input()
if s[0]!=s[-1]:
 print("First")
else:
 print("Second")

Submission status: Wrong Answer

Solution code:
from collections import Counter
s=list(raw_input())
c=Counter(s)
d=c.values()
k=0
for i in d:
    e=int(i/2)
    k=k+e
if(k%2==0):
    print 'First'
else:
    print 'Second'

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def neb(str):
    for i in range(len(str)-1):
        if(str[i] == str[i+1]):
            # print(str[i], i)
            # print("neb:False")
            return False
    # print("neb:True")
    return True


l = input()
win = False
loop = True
while(loop):
    win = not(win)
    # print(l, len(l))
    for i in range(len(l)-1):
        if(len(l) <= 2):
            # print("main: else")
            print("Second" if win else "First")
            quit()
        if((not i == 0) and (not i == len(l)-1)):
            # print(tmp.replace(l[i], ""))
            tmp = l.replace(l[i], "")
            if(neb(tmp)):
                l = l.replace(l[i], "")
                break
            else:
                loop = False


print("Second" if win else "First")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys

def main():
    s = sys.stdin.readline().rstrip()
    if s[0] == s[-1]:
        print "Second"
    else:
        print "First"

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
turn = 1
k = -1
while 1:
    for i in range(len(s)-2):
        if s[i] != s[i+2]:
            k = i
            if i < len(s) - 3:
                if s[i+1] == s[i+3]:
                    s = s[:i+1] + s[i+2:]
                    turn += 1
                    break
            if i > 0:
                if s[i+1] == s[i-1]:
                    s = s[:i+1] + s[i+2:]
                    turn += 1
                    break
    else:
        if k != -1:
            s = s[:k+1] + s[k+2:]
            turn += 1
            k = -1
        else:
            break
if turn%2 == 0:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    s=list(sys.stdin.readline().strip())
    t=0
    while len(s)>2:
        ps,cs,f=s[0],s[1],False
        for i,ns in enumerate(s[2:],1):
            if ps!=ns:
                s.pop(i)
                f,t=True,t^1
                break
            ps,cs=cs,ns
        if f is False:
            break
    print('First') if t==1 else print('Second')
if __name__=='__main__':main()

Submission status: Time Limit Exceeded

Solution code:
# 入力値
s = input()

# 手番管理
# 先行: 1, 後攻: -1
turn = 1

# 終了条件は、残り2文字になった時
while len(s) != 2:
    # 両サイド以外のどの文字が抜けるか調べる
    success = False
    for i in range(1,len(s)-1):
        if s[i-1] != s[i+1]:
            #print(s, s[i])
            s = s[0:i]+s[i+1:]
            #print(s)
            turn *= -1
            success = True
            break
    if success == False:
        break
    
# 手番の人が負け
if turn == 1:
    print("Second")
else:
    print("First")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict, deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()

memo = defaultdict(str)
def rec(S):
    if memo[S] != '':
        return memo[S]
    N = len(S)
    res = True
    S = list(S)
    S1 = list(S[0])
    S2 = deque(S[1:])
    for i in range(N-2):
        cur = S2.popleft()
        if S1[-1] != S2[0]:
            res &= rec(''.join(S1+list(S2)))
        S1.append(cur)
    if res:
        memo[''.join(S)] = False
        return False
    else:
        memo[''.join(S)] = True
        return True

if rec(S):
    print('First')
else:
    print('Second')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()

memo = defaultdict(str)
def rec(S):
    if memo[S] != '':
        return memo[S]
    N = len(S)
    res = True
    S = list(S)
    for i in range(1, N-1):
        if S[i-1] != S[i+1]:
            tmp = S.pop(i)
            res &= rec(''.join(S))
            S.insert(i, tmp)
    if res:
        memo[''.join(S)] = False
        return False
    else:
        memo[''.join(S)] = True
        return True

if rec(S):
    print('First')
else:
    print('Second')

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
length = len(s)

while not (length == 2 or (length == 3 and s[0] == s[2])):
    index = 1
    left = s[0]
    right = s[2]
    while True:
        if left != right:
            s = s[:index] + s[index + 1:]
            try:
                right = s[index + 1]
            except BaseException:
                count += 1
                length = len(s)
                break
            count += 1
        else:
            if index == length - 1:
                length = len(s)
                break
            else:
                left = s[index]
                index += 1
                try:
                    right = s[index + 1]
                except BaseException:
                    length = len(s)
                    break

if count % 2:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

while not (len(s) == 2 or (len(s) == 3 and s[0] == s[2])):
    index = 1
    left = s[0]
    right = s[2]
    while True:
        if left != right:
            s = s[:index] + s[index + 1:]
            try:
                right = s[index + 1]
            except BaseException:
                count += 1
                break
            count += 1
        else:
            if index == len(s) - 1:
                break
            else:
                left = s[index]
                index += 1
                try:
                    right = s[index + 1]
                except BaseException:
                    break

if count % 2:
    print("First")
else:
    print("Second")

Submission status: Time Limit Exceeded

Solution code:
s=input()
branch={}

def check(s):
    if len(s)==2:return []
    ans=[]
    for i in range(2,len(s)):
        if s[i-2]!=s[i]:ans.append(i-1)
    return ans
def result(limit):
    if limit%2==1:return 'Second'
    if limit%2==0:return 'First'
branch[1]=check(s)
past=(s,)
now=1
limit=1000000
def go(s,now,limit,past,prev):
    if prev==0:branch[now]=check(s)
    if branch[now]==[]:
        if now==1 and prev!=0:print(result(limit))
        elif now==1 and prev==0:print('Second')
        elif now==2:print('First')
        else:go(past[now-2],now-2,now,past[:-2],1)
    else:
        if now+1==limit:go(past[now-1],now-1,limit,past[:-1],1)
        else:
            x=branch[now].pop()
            s=s[:x]+s[x+1:]
            past+=(s,)
            go(s,now+1,limit,past,0)
go(s,now,limit,past,0)

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
t = 0
while True:
    N = len(s)
    ok = False
    for i in range(1, N-1):
        if s[i-1] != s[i+1]:
            ok = True
            s = s[:i] + s[i+1:]
            break
    if not ok:
        print "First" if (t % 2 == 1) else "Second"
        break
    t += 1

Submission status: Time Limit Exceeded

Solution code:
def check_duplicate(s):
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            return True
    return False

def find_status(i):
    if i % 2 == 1:
        return "First"
    else:
        return "Second"

s = raw_input()
i = 1
while (True):
    status = "First"
    flag = "NO"
#     if len(s) == 2:
#         #print "only 2 left, stoppng... loser:", find_status(i), "winner:", find_status(i+1)
#         print 
    for x in range(1, len(s)-1):
        tmp = s[:x] + s[x+1:]
        if check_duplicate(tmp) == False:
            flag = "OK"
            #print "[Try] Round", i, "remove_char=", s[x],". Go to the next round."
            s = tmp
            i += 1
            break
        else:
            #print "round", i, "failed to remove_char=", s[x]," on", i, "of", s
            continue
    if flag == "NO":
        #print "Failed to step forward for the round", i, 
        #print "loser:", find_status(i), 
        #print "winner:", find_status(i+1)
        print find_status(i+1)
        break

Submission status: Time Limit Exceeded

Solution code:
def can_do(s):
	list=[]
	if len(s) < 3:
		return list
	else:
		for i in range(1,len(s)-1):
			if s[i-1] != s[i+1]:
				list.append(s[:i]+s[i+1:])
	#print(list)
	return list
		
def check_list(list, cnt):
	bFlag = False
	for s in list:
		res = can_do(s)
		if len(res) > 0:
			return check_list(res, cnt+1)
			bFlag = True
	if bFlag == False:
		return cnt

		
s = input()

list = can_do(s)
cnt = 0
if len(list) > 0:
	cnt = check_list(list, 1)
#print(cnt)
if cnt%2 == 0:
	print("Second")
else:
	print("First")

Submission status: Time Limit Exceeded

Solution code:
def can_remove(s, idx):
    return s[idx - 1] != s[idx + 1]

def can_first_win(teban, cand_lst):
    if len(cand_lst) <= 0:
        return (teban % 2 == 0)

    next_cand_lst = []
    for s in cand_lst:
        for i in range(1, len(s) - 1):
            if can_remove(s, i):
                next_cand_lst.append(s[0:i] + s[i + 1:])

        return can_first_win((teban + 1) % 2, next_cand_lst)

s = input()
ans = can_first_win(0, [s])
print('First' if ans else 'Second')

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
n = 0

while (len(s) > 2):
    for i in xrange(1, len(s)-1):
        if s[i-1] != s[i+1]:
            s = s[0:i] + s[i+1:len(s)]
            n += 1
            break
    if len(s) == 3 and s[0] == s[2]:
        break

if n % 2 == 1:
    print "First"
else:
    print "Second"

Submission status: Accepted

Solution code:
s = input()
if len(s) %2 == 0 and s[0] == s[-1] or s[0] != s[-1] and len(s) %2 != 0:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
# from functools import lru_cache

# @lru_cache
# def grundy(s):
#     if len(s) == 2:
#         return 0
#     gs = set()
#     for i in range(1, len(s) - 1):
#         if s[i - 1] == s[i + 1]:
#             continue
#         gs.add(grundy(s[:i] + s[i + 1:]))
#     for i in range(100):
#         if i not in gs:
#             return not (i == 0)

def win_first(s):
    return ((s[0] == s[-1]) + len(s)) % 2

# def test():
#     for i in range(1000000):
#         s = str(i)
#         for c1, c2 in zip(s[:-1], s[1:]):
#             if c1 == c2:
#                 break
#         else:
#             assert win_first(s) == grundy(s)

def main():
    print("First" if win_first(input()) else "Second")

main()

Submission status: Accepted

Solution code:
s=input()
N=len(s)
if s[0]==s[-1]:
  if N%2:
    print('Second')
  else:
    print('First')
else:
  if N%2:
    print('First')
  else:
    print('Second')

Submission status: Accepted

Solution code:
string=list(input())
if string[0]==string[-1]:
	subtractor=-1
else:
	subtractor=0
if (len(string)+subtractor)%2==0:
	print('Second')
else:
	print('First')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

S = list(input())
leng = len(S)
if S[0]==S[-1]:
    leng -= 3
else:
    leng -= 2
if (leng-3)%2==0:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
s = input().strip()
N = len(s)
if N%2==0:
    if s[0]==s[-1]:
        print("First")
    else:
        print("Second")
else:
    if s[0]==s[-1]:
        print("Second")
    else:
        print("First")

Submission status: Accepted

Solution code:
s = str(input())
if len(s)%2 == 0:
  if s[0] == s[-1]:
    print("First")
  else:
    print("Second")
else:
  if s[0] != s[-1]:
    print("First")
  else:
    print("Second")

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
n=n-2
if s[0]==s[-1]:
    n-=1
if n%2==0:
    print("Second")
else:
    print("First")

Submission status: Accepted

Solution code:
S = input()
if (len(S)%2)^(S[0]==S[-1]):
  print("First")
else:
  print("Second")