Problem:


指輪 (Ring)

問題

あなたは N 個の指輪を持っている．どの指輪にも，アルファベットの大文字 10 文字からなる文字列が刻印されている．指輪には文字列の最初と最後がつながった形で文字が刻印されている．指輪に刻印された文字列を逆順に読む心配はない．

探したい文字列が与えられたとき，その文字列を含む指輪が何個あるかを求めるプログラムを作成せよ． 

入力

入力は 2+N 行からなる．

1 行目には，1 文字以上 10 文字以下のアルファベットの大文字からなる探したい文字列が書かれている．

2 行目には，指輪の個数 N ( 1 ≦ N ≦ 100 )が書かれている．

2+i 行目(1 ≤ i ≤ N )には， i 個目の指輪に刻印されている 10 文字からなる文字列が書かれている． 

出力

探したい文字列を含む指輪の個数を表す整数を 1 行で出力せよ．

入出力例

入力例 1
  

ABCD
3
ABCDXXXXXX
YYYYABCDXX
DCBAZZZZZZ

出力例 1

2

入力例 2
  

XYZ
1
ZAAAAAAAXY

出力例 2

1

入力例 2 の指輪には「XYZ」という文字列が 1 つ含まれている．これは、指輪の文字列の最初と最後がつながっているためである．

入力例 3
  

PQR
3
PQRAAAAPQR
BBPQRBBBBB
CCCCCCCCCC

出力例 3

2

入力例 3 の 1 個目の指輪には「PQR」という文字列が 2 つ含まれており， 2 個目の指輪には「PQR」という文字列が 1 個含まれており， 3 個目の指輪には「PQR」という文字列が含まれていない．そのため「PQR」という文字列が含まれている指輪の数は 2 個となる．

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
ABCD
3
ABCDXXXXXX
YYYYABCDXX
DCBAZZZZZZ


Sample output:
2

Submission status: Wrong Answer

Solution code:
s = raw_input()
n = input()
ans = 0
for i in xrange(n):
    t = raw_input()
    t2 = t+t
    for j in xrange(len(t)):
        if s==t[j:j+len(s)]:
            ans += 1
            break
print ans

Submission status: Wrong Answer

Solution code:
_find=str(input())
n=int(input())

count=0

for i in range(n):
    s=str(input())
    if _find in s:
        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
s=input()
print(sum(len(2*input().split(s))>1 for _ in range(int(input()))))

Submission status: Wrong Answer

Solution code:
import sys
R = lambda:map(int,raw_input().split())

s = raw_input()
l = len(s)
#print s, l
n = int(raw_input())
neko = 0
for i in xrange(n):
    ring = raw_input()
    #print ring
    rings = ring + ring
    #print rings
    for i in xrange(len(ring)):
        cc = []
        for j in xrange(l):
            cc.append(rings[i+j])
        zgok = "".join(cc)
        #print zgok
        if zgok == s:
            neko += 1
print neko

Submission status: Wrong Answer

Solution code:
letter=raw_input()
N=input()
ans=0
rings=[]
for i in xrange(N):
    rings.append(raw_input())
for ring in rings:
    if ring.find(letter):
        ans+=1
        break
    else:
        failFlag=1
        for i in xrange(len(ring)):
            aring=list(ring)
            aring.append(aring.pop())
            ring=str(aring)
            if ring.find(letter):
                ans+=1
                failFlag=0
                break
            
print ans

Submission status: Accepted

Solution code:
s = input()
n = int(input())
ans = 0
for _ in range(n):
    t = input()
    t += t[:len(s)]
    if s in t:
        ans += 1
else:
    print(ans)

Submission status: Accepted

Solution code:
s = raw_input()
n = input()
ans = 0
for i in xrange(n):
    t = raw_input()
    t2 = t+t
    for j in xrange(len(t)):
        if s==t2[j:j+len(s)]:
            ans += 1
            break
print ans

Submission status: Accepted

Solution code:
s = raw_input()
n = input()
ans = 0
for i in range(n):
    t = raw_input()
    t += t[:n]
    if s in t: ans+=1
print ans

Submission status: Accepted

Solution code:


keyword = raw_input()
N = int(raw_input())

count = 0

for _ in xrange(N):
  s = raw_input()
  if keyword in (s+s):
    count += 1

print count

Submission status: Accepted

Solution code:
_find=str(input())
n=int(input())

count=0

for i in range(n):
    s=str(input())
    l=list(s)

    for j in range(len(_find)-1):
        l.append(s[j])

    ss="".join(l)

    if _find in ss:
        count=count+1

print(count)

Submission status: Accepted

Solution code:
a=input()
n=int(input())
c=0
while n:
    n-=1
    b=input()
    b=b*2
    if a in b: c+=1
print(c)

Submission status: Accepted

Solution code:
I=input;s=I();print(sum(s in I()*2for _ in[0]*int(I())))

Submission status: Accepted

Solution code:
s=input()
print(sum(1 for _ in range(int(input()))if s in 2*input()))

Submission status: Accepted

Solution code:
s=input()
print(sum(s in 2*input()for _ in range(int(input()))))

Submission status: Accepted

Solution code:
s=input()
print(sum(s in 2*input()for _ in[0]*int(input())))

Submission status: Accepted

Solution code:
s=input()
print(sum(len((2*input()).split(s))>1 for _ in range(int(input()))))

Submission status: Accepted

Solution code:
import sys

key = sys.stdin.readline().strip()
n = int(sys.stdin.readline())
find = 0

for i in range(0, n):
    line = sys.stdin.readline().strip()
    ring = line+line
    if ring.count(key) != 0:
        find += 1

print(find)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0555

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    search_word = input().strip()
    N = int(input())

    found = 0
    for _ in range(N):
        data = input().strip()
        data = data + data
        data = data[:-1]
        if search_word in data:
            found += 1
    print(found)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
s=input()
n=int(input())
rng=[input()for i in range(n)]
contain=[False for i in range(n)]
l=len(s)
for i in range(len(rng)):
    t=rng[i]+rng[i][:l]
    for j in range(len(rng[i])):
        if s==t[j:j+l]:
            contain[i]=True
            break
print(contain.count(True))

Submission status: Accepted

Solution code:
t=input()
print(sum(t in input()*2 for _ in[0]*int(input())))

Submission status: Accepted

Solution code:
t=input()
print(sum(t in 2*input()for _ in[0]*int(input())))

Submission status: Accepted

Solution code:
s = input()
print(sum([s in input() * 2 for _ in range(int(input()))]))

Submission status: Accepted

Solution code:
# AOJ 0555: Ring
# Python3 2018.6.30 bal4u

p = input().strip()
ans = 0
for i in range(int(input())):
	s = input().strip()
	s = s+s
	if s.find(p) >= 0: ans += 1
print(ans)

Submission status: Accepted

Solution code:
t = raw_input()
count = int(input())
g,e,r = 0,0,1
for i in range(count):
  r,e =1,0
  y = raw_input()
  y *=2
  for j in range(len(y)):
    if t == y[e:e+len(t)]:
      g+=1
      break
    e+=1
print g

Submission status: Accepted

Solution code:
import sys
R = lambda:map(int,raw_input().split())

s = raw_input()
l = len(s)
#print s, l
n = int(raw_input())
neko = 0
for i in xrange(n):
    ring = raw_input()
    #print ring
    rings = ring + ring
    #print rings
    for i in xrange(len(ring)):
        cc = []
        for j in xrange(l):
            cc.append(rings[i+j])
        zgok = "".join(cc)
        #print zgok
        if zgok == s:
            neko += 1
            break
print neko

Submission status: Accepted

Solution code:
s=raw_input()
n=input()
ans=0
for i in range(n):
    r=raw_input()
    for j in range(len(r)):
        flag=True
        for k in range(len(s)):
            ri=(j+k)%len(r)
            if r[ri]!=s[k]:
                flag=False
        if flag:
            ans+=1
            break
print ans

Submission status: Accepted

Solution code:
letter=raw_input()
N=input()
ans=0
rings=[]
for i in xrange(N):
    rings.append(raw_input())
for ring in rings:
    if not ring.find(letter) == -1:
        ans+=1
    else:
        failFlag=1
        aring=list(ring)
        for i in xrange(len(ring)):
            l=aring.pop(0)
            aring.append(l)
            ring=''.join(aring)
            if not ring.find(letter) == -1:
                ans+=1
                failFlag=0
                break
            
print ans

Submission status: Accepted

Solution code:
s = raw_input()
score = 0
for u in xrange(input()):
    ss = raw_input()
    if len((ss+ss).split(s)) > 1:
        score += 1
print score

Submission status: Accepted

Solution code:
s = raw_input()
score = 0
for u in xrange(input()):
    ss = raw_input()
    if s in ss*2:
        score += 1
print score

Submission status: Accepted

Solution code:
s=raw_input()
n=input()
cnt=0
for i in range(n):
    a=raw_input()
    if s in a+a[:-1]:
        cnt+=1
print cnt

Submission status: Accepted

Solution code:
s = raw_input()
c = 0
n = int(raw_input())
for _ in range(n):
    r = raw_input()
    if s in (r + r):
        c += 1
print c

Submission status: Accepted

Solution code:
str = raw_input()
cnt = 0
while True:
	try:
		if (raw_input() * 2).count(str) != 0:
			cnt = cnt + 1
	except:
		print cnt
		break

Submission status: Accepted

Solution code:
count = 0
target = raw_input()
for i in range(int(raw_input())):
    s = raw_input()
    s += s[:-1]
    if target in s:
        count += 1
print count

Submission status: Accepted

Solution code:
a = raw_input()
ans = 0
for i in range(input()):
	r = raw_input()
	if a in r + r[:len(a)]:
		ans += 1
print ans

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
m=input()
n=int(input())
x=[input()for i in range(n)]

c=0

for i in range(n):
    x[i]=x[i]+x[i][:11]
    if m in x[i]:
        c+=1
print(c)

Submission status: Accepted

Solution code:
k = input()
n = int(input())
l = [input() for i in range(n)]
c = 0

for i in range(n):
    l[i] = l[i]+l[i][:11]
    if k in l[i]:
        c += 1

print(c)

Submission status: Accepted

Solution code:
s = input()
c = 0
for i in range(int(input())):
    x = input()
    if s in x*2:
        c += 1
print(c)

Submission status: Accepted

Solution code:
a = input()
b = int(input())
c = 0
for _ in range(b):
	d = input()
	d = d+d
	if d.count(a)!=0: c += 1

print(c)

Submission status: Accepted

Solution code:
x = input()
n = int(input())
ans = 0
for i in range(n) :
    y = list(input())
    for j in range(len(x)-1) :
        y.append(y[j])
    y = "".join(y)
    if x in y :
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
str1 = input()
num2 = 0
num = int(input())
for num1 in range(num):
    str2 = input()
    str2 += str2
    i = str1 in str2
    if i == True:
        num2 += 1
        continue
    elif i == False:
        continue
print(num2)

Submission status: Accepted

Solution code:
x = input()
n = int(input())
cnt = 0
for _ in range(n):
    t = input() * 2
    if t.count(x) > 0:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
word = input()
num = int(input())
ans = 0
for i in range(num):
    ring = input()
    ring *= 2
    if word in ring:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = int(input())

count = 0
for i in range(n):
    a = input()
    a += a
    if a.count(s) >= 1:
        count += 1
print(count)

Submission status: Accepted

Solution code:
s=input()
n=int(input())
st=[input() for _ in range(n)]
for i in range(n):
    st[i]=st[i]+st[i][:len(st[i])-1]
cnt=0
for i in range(n):
    if s in st[i]:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
S = input()
n = int(input())
cnt = 0

for i in range(n) :
    R = input()
    R *= 2
    if(S in R) :
        cnt += 1
    else :
        pass

print(cnt)

Submission status: Accepted

Solution code:
pat = input()
N = int(input())
cnt = 0
for i in range(N):
    s = input()
    s = s * 2
    if pat in s:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
word=input()
n=int(input())
count=0
for i in range(n):
    s=input()*2
    if word in s:count+=1
print(count)

Submission status: Accepted

Solution code:
target = input()
n = int(input())

cnt = 0
for _ in range(n):
    dst = input()
    dst *= 2
    if target in dst:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
S = str(input())
N = int(input())
rings = [0]*N
ans = 0
for i in range(N):
    rings[i] = str(input()) * 3
    if S in rings[i]:
        ans+=1
print(ans)