Problem:


 JOIとIOI 

問題

与えられた文字列内の連続する3文字が，JOIまたはIOIという並びになっている個所がそれぞれ何個所あるのかを数え上げるプログラムを作成せよ．文字列はアルファベットの大文字だけからなる．例えば下図の「JOIOIOI」という文字列にはJOIが1個所，IOIが2個所に含まれている．

入力

入力は複数のデータセットからなる．各データセットは1行であり，10000文字以下のアルファベットの大文字からなる．入力は EOF で終了する.

データセットの数は 5 を超えない．

出力

データセットごとに,  1行目に見つかったJOIの個数，2行目に見つかったIOIの個数をそれぞれ出力せよ．

入出力例

入力例

JOIJOI
JOIOIOIOI
JOIOIJOINXNXJIOIOIOJ

出力例

2
0
1
3
2
3

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



Sample input:
JOIJOI
JOIOIOIOI
JOIOIJOINXNXJIOIOIOJ


Sample output:
2
0
1
3
2
3

Submission status: Wrong Answer

Solution code:
import string
s = raw_input()
def f(str):
    t = cnt = 0
    while 1:
        u = t
        t = string.find(s[t:],str)
        if t == -1: break
        cnt+=1; t+=u+1;
    print cnt
f("JOI")
f("IOI")

Submission status: Wrong Answer

Solution code:
s = input()
joi = 0
ioi = 0

for i in range(len(s) - 2):
    x = s[i] + s[i + 1] + s[i + 2]
    if (x == "JOI"):
        joi += 1
    elif (x == "IOI"):
        ioi += 1

print(joi)
print(ioi)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        s = input().strip()
    except:
        break
    i = 0
    cnt_joi, cnt_ioi = 0, 0
    while i < len(s) - 2:
        t = s[i:i + 3]
        if t == 'JOI':
            cnt_joi += 1
            i += 2
        elif t == 'IOI':
            cnt_ioi += 1
            i += 2
        elif t[2] == 'O':
            i += 1
        elif t[2] == 'I':
            i += 2
        else:
            i += 3
    print(cnt_joi)
    print(cnt_ioi)

Submission status: Wrong Answer

Solution code:
J = "JOI"; I = "IO"
while 1:
    try:
        s = raw_input()
        a=b=0; p=q=0;
        for i in xrange(len(s)):
            if s[i]==J[p]:
                p+=1
                if p==3:
                    a+=1; p=0;
            else:
                p=0
            if s[i]==I[q%2]:
                q+=1
                if q>1 and q%2==1:
                    b+=1
            else:
                q=0
        print "%d\n%d"%(a,b);
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
J = "JOI"; I = "IOI"
while 1:
    try:
        s = raw_input()
        a=b=0; p=q=0;
        for i in xrange(len(s)):
            if s[i]==J[p]:
                p+=1
                if p==3:
                    a+=1; p=0;
            else:
                p=0
            if s[i]==I[q]:
                q+=1
                if q==3:
                    b+=1; q=1;
            else:
                q= 0 if s[i]!=I[0] else 1
        print "%d\n%d"%(a,b);
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
while 1:
	try:
		a=raw_input()
		print a.count("JOI")
		print a.count("IOI")+a.count("IOIO")
	except:
		break

Submission status: Wrong Answer

Solution code:
def main():

    joi = 0
    ioi = 0

    text = input()

    for i in range(len(text)-2):

        if text[i+1] == 'O' and text[i+2] == 'I':
            if text[i] == 'J':
                joi += 1

            elif text[i] == 'I':
                ioi += 1


    print(joi)
    print(ioi)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

while True:
    try:
        s = input('')
    except:
        break

    cut_s_list = [s[i:i+3] for i in range(len(s[:-2]))]

    n_joi = 0
    n_ioi = 0
    for cut_s in cut_s_list:
        if cut_s == 'JOI':
            n_joi += 1
        if cut_s == 'IOI':
            n_ioi += 1

    print(n_joi)
    print(n_ioi)

Submission status: Accepted

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

while True:
    try:
        s = input('')
    except:
        break

    n_joi = 0
    n_ioi = 0
    for i in range(len(s[:-2])):
        cut_s = s[i:i+3]
        if cut_s == 'JOI':
            n_joi += 1
        if cut_s == 'IOI':
            n_ioi += 1

    print(n_joi)
    print(n_ioi)

Submission status: Accepted

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

while True:
    try:
        input_s = input()
    except:
        break

    s_list = [input_s[i:i+3] for i in range(len(input_s[:-2]))]

    n_joi = 0
    n_ioi = 0
    for s in s_list:
        if s == 'JOI':
            n_joi += 1
        if s == 'IOI':
            n_ioi += 1

    print(n_joi)
    print(n_ioi)

Submission status: Accepted

Solution code:
import string
def f(str):
    t = cnt = 0
    while 1:
        u = t
        t = string.find(s[t:],str)
        if t == -1: break
        cnt+=1; t+=u+1;
    print cnt
while 1:
    try:
        s = raw_input()
        f("JOI")
        f("IOI")
    except EOFError: break

Submission status: Accepted

Solution code:
while True:
    try:
        s = input()
    except:
        break
    joi = 0
    ioi = 0
    s_list = [s[i:i+3] for i in range(len(s) - 2)]
    for i in s_list:
        if i == "JOI":
            joi += 1
        if i == "IOI":
            ioi += 1
    print(joi)
    print(ioi)

Submission status: Accepted

Solution code:
while True:
    try:
        s = input()
    except:
        break
    joi = 0
    ioi = 0
    for i in range(len(s) - 2):
        x = s[i] + s[i + 1] + s[i + 2]
        if x == "JOI":
            joi += 1
        if x == "IOI":
            ioi += 1
    print(joi)
    print(ioi)

Submission status: Accepted

Solution code:
while True:
    try:
        s= input()
    except:
        break
    j=i=0
    j= sum(1 for k in range(len(s)-1) if s[k]=="J"and s[k+1]=="O"and s[k+2]=="I")
    i= sum(1 for k in range(len(s)-1) if s[k]=="I"and s[k+1]=="O"and s[k+2]=="I")
    print("\n".join(map(str, [j, i])))

Submission status: Accepted

Solution code:
while 1:
    try:a=input()
    except:break
    b=c=0
    for i in range(len(a)-2):
        if a[i:i+3]=='JOI':b+=1
        elif a[i:i+3]=='IOI':c+=1
    print(b)
    print(c)

Submission status: Accepted

Solution code:
while True:
    try:
        s = input().strip()
    except:
        break
    i = 0
    cnt_joi, cnt_ioi = 0, 0
    while i < len(s) - 2:
        t = s[i:i + 3]
        if t == 'JOI':
            cnt_joi += 1
            i += 2
        elif t == 'IOI':
            cnt_ioi += 1
            i += 2
        elif t[2] == 'O':
            i += 1
        elif t[2] == 'I' or t[2] == 'J':
            i += 2
        else:
            i += 3
    print(cnt_joi)
    print(cnt_ioi)

Submission status: Accepted

Solution code:
while True:
    try:
        s = input().strip()
    except:
        break
    i = 0
    cnt_joi, cnt_ioi = 0, 0
    while i < len(s) - 2:
        t = s[i:i + 3]
        if t == 'JOI':
            cnt_joi += 1
            i += 2
        elif t == 'IOI':
            cnt_ioi += 1
            i += 2
        elif t[2] == 'O':
            i += 1
        elif t[2] in 'IJ':
            i += 2
        else:
            i += 3
    print(cnt_joi)
    print(cnt_ioi)

Submission status: Accepted

Solution code:
while True:
    try:
        str = list(input())
        #0-4
        state = 0
        joi = 0
        ioi = 0

        for chara in str:
            if state == 0:
                if chara == "J":
                    state = 1
                elif chara == "I":
                    state = 3
                else:
                    state = 0
            elif state == 1:
                if chara == "J":
                    state = 1
                elif chara == "O":
                    state = 2
                elif chara == "I":
                    state = 3
                else:
                    state = 0
            elif state == 2:
                if chara == "J":
                    state = 1
                elif chara == "I":
                    state = 3
                    joi += 1
                else:
                    state = 0
            elif state == 3:
                if chara == "J":
                    state = 1
                elif chara == "O":
                    state = 4
                elif chara == "I":
                    state = 3
                else:
                    state = 0
            elif state == 4:
                if chara == "J":
                    state = 1
                elif chara == "I":
                    state = 3
                    ioi += 1
                else:
                    state = 0

        print(joi)
        print(ioi)

    except EOFError:
        break

Submission status: Accepted

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

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


def find_pattern(txt, p):
    count = 0
    i = txt.find(p, 0)
    while i != -1:
        count += 1
        i = txt.find(p, i+1)
    return count


def main(args):
    for line in sys.stdin:
        print(find_pattern(line, 'JOI'))
        print(find_pattern(line, 'IOI'))


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

Submission status: Accepted

Solution code:
while True:
    s=""
    try:s=input()
    except EOFError:break
    c_joi=0
    c_ioi=0
    for i in range(len(s)-2):
        if s[i:i+3]=="JOI":c_joi+=1
        elif s[i:i+3]=="IOI":c_ioi+=1
    print(c_joi)
    print(c_ioi)

Submission status: Accepted

Solution code:
import sys


def input_data():
    a = []
    for line in sys.stdin:
        a.append(str(line))

    return a


def how_in(string, pattern):
    match_num = 0
    for i in range(len(string) - 2):
        if pattern == string[i:i + 3]:
            match_num += 1

    return match_num


yeah = input_data()
for pattern in yeah:
    print(how_in(pattern, 'JOI'))
    print(how_in(pattern, 'IOI'))

Submission status: Accepted

Solution code:
while True:
  try:
    ss = input()
    ans1 = ans2 = 0
    for i in range(len(ss) - 2):
      if ss[i] == 'J' and ss[i + 1] == 'O' and ss[i + 2] == "I":
        ans1 += 1
      elif ss[i] == 'I' and ss[i + 1] == 'O' and ss[i + 2] == "I":
        ans2 += 1
    print(ans1)
    print(ans2)
  except EOFError:
    break

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 s=[e[i:i+3]for i in range(len(e)-3)]
 print(s.count('JOI'))
 print(s.count('IOI'))

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 s=sum((e[i:i+3]=='JOI')+1j*(e[i:i+3]=='IOI')for i in range(len(e)-3))
 print(int(s.real))
 print(int(s.imag))

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 s=[e[i:i+3]for i in range(len(e)-3)]
 for w in['JOI','IOI']:print(s.count(w))

Submission status: Accepted

Solution code:
# AOJ 0522: JOI and IOI
# Python3 2018.6.30 bal4u

import re

match = re.findall(r'[0-9]+', 'xxxx1aaaa22cc333ssss')
while True:
	try: s = input()
	except: break
	joi = ioi = 0
	for i in range(len(s)-2):
		if s[i+1] == 'O' and s[i+2] == 'I':
			if s[i] == 'J': joi += 1
			if s[i] == 'I': ioi += 1
	print(joi, ioi, sep='\n')

Submission status: Accepted

Solution code:
# AOJ 0522: JOI and IOI
# Python3 2018.6.30 bal4u

while True:
	try: s = input()
	except: break
	c = [s[i:i+3] for i in range(len(s)-2)]
	print(*[c.count(a) for a in ["JOI", "IOI"]], sep='\n')

Submission status: Accepted

Solution code:
while True:
 try:
  a=raw_input()
  a+="  "
  ans,ans2=0,0
  for i in range(len(a)-4):
    if a[i:i+3] == 'JOI': ans+=1
    elif a[i:i+3] == 'IOI': ans2+=1
  else:
    print "%d\n%d"%(ans,ans2)
 except EOFError: break

Submission status: Accepted

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

while 1:
    try:
        cntJ = 0
        cntI = 0
        s = raw_input()
        for i in xrange(len(s)-2):
            neko = "".join([s[i], s[i+1], s[i+2]])
            #print neko
            if neko == 'JOI': cntJ += 1
            elif neko == 'IOI': cntI += 1
        print cntJ
        print cntI
    except EOFError:
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        s=raw_input()
        joi=0
        ioi=0
        for i in range(len(s)-2):
            if(s[i+1]=="O" and s[i+2]=="I"):
                if(s[i]=="J"):
                    joi+=1
                if(s[i]=="I"):
                    ioi+=1
        print joi
        print ioi
    except EOFError:
        break

Submission status: Accepted

Solution code:
#coding:utf-8
ans = []
while True:
    JOI=0
    IOI=0
    try:
        string=raw_input()
    except EOFError:
        break
    length=len(string)
    for i in xrange(length-2):
        if string[i] == 'J':
            if (string[i+1] == 'O' and string[i+2] == 'I'):
                JOI += 1
        if string[i] == 'I':
            if (string[i+1] == 'O' and string[i+2] == 'I'):
                IOI += 1
    ans.append(JOI)
    ans.append(IOI)
for i in ans:
    print i

Submission status: Accepted

Solution code:
while 1:
    try:
        s = raw_input()
        ws = [s[i:i + 3] for i in range(len(s) - 2)]
        print ws.count('JOI')
        print ws.count('IOI')
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        s=raw_input()
    except EOFError:
	break
    cj,ci=0,0
    for i in range(len(s)):
        if s[i:i+3]=="JOI":
	    cj+=1
        elif s[i:i+3]=="IOI":
	    ci+=1
    print cj
    print ci

Submission status: Accepted

Solution code:
from sys import stdin
graph = [{"J":1,"O":0,"I":4},
         {"J":1,"O":2,"I":4},
         {"J":1,"O":0,"I":3},
         {"J":1,"O":5,"I":4},
         {"J":1,"O":5,"I":4},
         {"J":1,"O":0,"I":6},
         {"J":1,"O":5,"I":4}]
for line in stdin.readlines():
    cur,JOI,IOI = 0,0,0
    for c in line.strip():
        if not c in "JOI":
            cur = 0
        else:
            cur = graph[cur][c]
            if cur == 3:
                JOI += 1
            if cur == 6:
                IOI += 1
    print JOI
    print IOI

Submission status: Accepted

Solution code:
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

while True:
    n = fp.readline()[:-1]
    if not n:
        break

    c_joi = 0
    c_ioi = 0
    for i in xrange(len(n)-2):
        if n[i:i+3] == "JOI":
            c_joi += 1
        if n[i:i+3] == "IOI":
            c_ioi += 1
    print c_joi
    print c_ioi

Submission status: Accepted

Solution code:
while True:
    try:
        joi, ioi = 0, 0
        s = raw_input()
        for i in range(0, len(s)-2):
            if s[i:i+3] == 'JOI':
                joi += 1
            elif s[i:i+3] == 'IOI':
                ioi += 1
        print joi
        print ioi
    except EOFError:
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        s = raw_input()
        a = b = 0
        for i in xrange(len(s)-2):
            if s[i:i+3]=="JOI": a+=1
            if s[i:i+3]=="IOI": b+=1
        print "%d\n%d"%(a,b)
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys

for s in sys.stdin:
	joi=0
	ioi=0

	for i in range(0,len(s)-2):
		subs=s[i:i+3]
		if subs=="JOI":
			joi+=1
		elif subs=="IOI":
			ioi+=1

	print joi
	print ioi

Submission status: Accepted

Solution code:
while 1:
	try:
		a=raw_input()
		cjoi=cioi=0
		for i in range(len(a)-2):
			if a[i:i+3]=="JOI":
				cjoi+=1
			if a[i:i+3]=="IOI":
				cioi+=1
		print cjoi
		print cioi
	except:
		break

Submission status: Accepted

Solution code:
while 1:
	try:
		a=raw_input()
		cjoi=cioi=0
		for i in range(len(a)-2):
			if   a[i]=="J" and a[i+1]=="O" and a[i+2]=="I":cjoi+=1
			elif a[i]=="I" and a[i+1]=="O" and a[i+2]=="I":cioi+=1
		print cjoi
		print cioi
	except:
		break

Submission status: Accepted

Solution code:
while 1:
	try:
		a=raw_input()
		cjoi=cioi=0
		for i in range(len(a)-2):
			if a[i+1]=="O" and a[i+2]=="I":
				if   a[i]=="J":cjoi+=1
				elif a[i]=="I":cioi+=1
		print cjoi
		print cioi
	except:
		break

Submission status: Accepted

Solution code:
while 1:
	try:
		a=raw_input()
		c=0
		for i in range(len(a)-2):
			if a[i:i+3]=="IOI":c+=1
		print a.count("JOI")
		print c
	except:
		break

Submission status: Accepted

Solution code:
while True:
    try:
        s = input()
    except:
        break
    c = [s[i:i+3] for i in range(len(s)-2)]
    print(*[c.count(a) for a in ["JOI","IOI"]], sep="\n")

Submission status: Accepted

Solution code:
while True:
    try:
        n=input()
        a=0
        b=0
        
        for i in range(len(n)-2):
            if n[i:i+3]=="JOI":
                a+=1
            elif n[i:i+3]=="IOI":
                b+=1
        print(a)
        print(b)
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        s=str(input())
        JOI=0
        IOI=0
        for i in range(len(s)-2):
            if s[i]=="J" and s[i+1]=="O" and s[i+2]=="I":
                JOI+= 1
            elif s[i] =="I" and s[i+1]=="O" and s[i+2]=="I":
                IOI+= 1
        print(JOI)
        print(IOI)
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        t=str(input())
    except EOFError:
        break
    p="JOI"
    for i in range(2):
        if i==1:
            p="IOI"
        a=int(0)
        for i in range(len(t)):
            f=t[i:i+len(p)]
            if f.find(p)!=-1:
                a+=1
        print(a)

Submission status: Accepted

Solution code:
while True:
    try:
        m = str(input());
        if m == "EOF":
            break;
    except EOFError:
        break;
    j = "JOI";
    i = "IOI";
    J = 0;
    I = 0;
    l = "";

    for a in range(0,len(m)-2):
        l = m[a:a+3]

        if l == j:
            J += 1;
        if l == i:
            I += 1;

    print(J);
    print(I);

Submission status: Accepted

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

while True:
   try:
      s = input()
      
      Jc = 0
      Ic = 0
      for i in range(len(s) - 2):
         if s[i] == "J" and s[i + 1] == "O" and s[i + 2] == "I":
            Jc += 1
         if s[i] == "I" and s[i + 1] == "O" and s[i + 2] == "I":
            Ic += 1
      print(Jc)
      print(Ic)

   except EOFError:
      break

Submission status: Accepted

Solution code:
while True:
    try:
        a = input()
        b = 0
        c = 0
        for i in range(len(a)-2):
            if a[i]=='J':
                if a[i+1]=='O':
                    if a[i+2]=='I':
                        b+=1
            if a[i]=='I':
                if a[i+1]=='O':
                    if a[i+2]=='I':
                        c+=1
        print(b)
        print(c)
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        s=input()
        
        joi=0
        ioi=0
        
        for i in range(len(s)-2):
            if(s[i:i+3]=="JOI"):
                joi+=1
            if(s[i:i+3]=="IOI"):
                ioi+=1
                
        print(joi)
        print(ioi)
    
    
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        x=input()
        if x=="EOF":
            break
        else:
            x=x.replace("I","II")
            s=x.count("JOI")
            print(s)
            t=x.count("IOI")
            print(t)
    except EOFError:
        break

Submission status: Accepted

Solution code:
m=str('JOI')
w=str('IOI')

while True:
    x=0
    y=0
    try:
        n=str(input())
    except EOFError:
        break
    a=len(n)
    N=list(n)
    for i in range(a-2):
        C=[]
        for j in range(3):
            C.append(N[j])
        B=''.join(C)
        c=N[0]
        if B==m:
            x=x+1
        if B==w:
            y=y+1
        N.remove(c)
        N.append(c)
    print(x)
    print(y)

Submission status: Accepted

Solution code:
while True:
    try:
        li=list(input())
        JOI=0
        IOI=0
        for i in range(len(li)-2):
            if li[i]=='J' and li[i+1]=='O' and li[i+2]=='I':
                JOI+=1
            if li[i]=='I' and li[i+1]=='O' and li[i+2]=='I':
                IOI+=1
        print(JOI)
        print(IOI)
        
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        s=list(str(input()))
        j=0
        i=0
        for n in range(len(s)-2):
            if s[n]=='J' and s[n+1]=='O' and s[n+2]=='I':
                j+=1
            if s[n]=='I' and s[n+1]=='O' and s[n+2]=='I':
                i+=1
        print(j)
        print(i)
    except:
        break

Submission status: Accepted

Solution code:
try:
    while True:
        n = input() 
        J=0
        I=0
        n = list(n)
        for i in range(len(n)):
            m = n[i:i+3]
            m =''.join(m)
            if m=='JOI':
                J+=1
            elif m=='IOI':
                I+=1
            
        print(J)
        print(I)
except EOFError:
    pass

Submission status: Accepted

Solution code:
while 1:
    try:
        A = input()
        a = len(A)
        C='JOI'
        D='IOI'
        c=len(C)
        d=len(D)
        s=0
        for i in range(a-c+1):
            if C == A[i:i+c]:    #a[i:j]→[a[i], a[i+1], a[i+2], ..., a[j-1]]
                s+=1
        print(s)
        t=0
        for i in range(a-d+1):
            if D == A[i:i+d]:    #a[i:j]→[a[i], a[i+1], a[i+2], ..., a[j-1]]
                t+=1
        print(t)
    except EOFError:break

Submission status: Accepted

Solution code:
while True:
  try:
    ss = input()
    ans1 = ans2 = 0
    for i in range(len(ss) - 2):
      if ss[i] == 'J' and ss[i + 1] == 'O' and ss[i + 2] == "I":
        ans1 += 1
      elif ss[i] == 'I' and ss[i + 1] == 'O' and ss[i + 2] == "I":
        ans2 += 1
    print(ans1)
    print(ans2)
  except EOFError:
    break

Submission status: Accepted

Solution code:
while True:
   try:
      j = input()
      p=0
      q=0
      for i in range(len(j)-2):
         if j[i:i+3] == 'JOI':
            p += 1
         elif j[i:i+3] == 'IOI':
            q += 1
         else:
            pass
      print(p)
      print(q)
   except EOFError:
      break

Submission status: Accepted

Solution code:
while 1:
    try:A=input()
    except:break
    B=C=0
    for i in range(len(A)-2):
        if A[i:i+3]=='JOI':B+=1
        elif A[i:i+3]=='IOI':C+=1
    print(B)
    print(C)

Submission status: Accepted

Solution code:
# coding: utf-8
# 90

while True:
    try:
        m = input()
        print(m.count('JOI'))
        print(m.count('IOI')+m.count('IOIOI'))
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        n=input()
    except:
        break
    c=[n[i:i+3] for i in range(len(n)-2)]
    print(*[c.count(a) for a in ["JOI","IOI"]],sep="\n")

Submission status: Accepted

Solution code:

while True:
    try: tmp = input()
    except: break

    joi,ioi = 0,0

    for i in range(len(tmp)):
        if tmp[i:i+3]=="JOI":
            joi += 1
        elif tmp[i:i+3]=="IOI":
            ioi += 1
        
    print(joi,ioi,sep="\n")

Submission status: Accepted

Solution code:
while True:
    try:
        a=input()
    except EOFError:
        break
    b=0
    c=0
    for i in range(len(a)):
        if a[i:i+3]=='JOI':
            b+=1
        elif a[i:i+3]=='IOI':
            c+=1
        else:
            pass
    print(b)
    print(c)

Submission status: Accepted

Solution code:
while True:
    try:
        x=input()
        a=b=0
        for i in range(len(x)-2):
            if x[i]=="J" and x[i+1]=="O" and x[i+2]=="I":
                a+=1
            if x[i]=="I" and x[i+1]=="O" and x[i+2]=="I":
                b+=1
        print(a)
        print(b)
    except EOFError: break

Submission status: Accepted

Solution code:
try:
    while True:
        A=0
        B=0
        
        a=list(str(input()))
        b=len(a)
        for i in range(b-2):
            c=a[i]+a[i+1]+a[i+2]
            if c=="JOI":
                A+=1
            if c=="IOI":
                B+=1
                
        print(A)
        print(B)
        
except EOFError:
    pass

Submission status: Accepted

Solution code:
while True:
    try:
        d = input()
        D = list(d)
        J = 0
        I = 0
        for i in range(len(D)-2):
            if D[i] == 'J' and D[i+1] == 'O' and D[i+2] == 'I':
                J += 1
            if D[i] == 'I' and D[i+1] == 'O' and D[i+2] == 'I':
                I += 1
        print(J)
        print(I)

    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
import math

for x in sys.stdin:
    n = len(x)
    J = 0
    I = 0
    for j in range(n-2):

        if x[j:j+3] == "JOI":
            J += 1
        elif  x[j:j+3] == "IOI":
            I += 1
    print(J)
    print(I)

Submission status: Accepted

Solution code:
#0522
def count(text,part):
    return sum(text.startswith(part,i) for i in range(len(text)))

while True:
    try:
        y = str(input())
    except:
        break
    x = count(y,'JOI')
    z = count(y,'IOI')
    print(x)
    print(z)

Submission status: Accepted

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

while True:
   try:
      s = input()
      
      Jc = 0
      Ic = 0
      for i in range(len(s) - 2):
         if s[i] == "J" and s[i + 1] == "O" and s[i + 2] == "I":
            Jc += 1
         if s[i] == "I" and s[i + 1] == "O" and s[i + 2] == "I":
            Ic += 1
      print(Jc)
      print(Ic)

   except EOFError:
      break

Submission status: Accepted

Solution code:
while True:
    try:
        s=input()
        J=0
        I=0
        for i in range(len(s)-2):
            m=s[i]+s[i+1]+s[i+2]
            if m=="JOI":
                J+=1
            elif m=="IOI":
                I+=1
        print(J)
        print(I)
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        a=input()
        cj=0
        ci=0
        for i in range(len(a)-2):
            if a[i+1]=="O" and a[i+2]=="I":
                if a[i]=="J":
                    cj+=1
                elif a[i]=="I":
                    ci+=1
        print(cj)
        print(ci)
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        a = input()
    except:
        break

    ans1 = 0
    ans2 = 0

    for i in range(len(a)-2):
        if a[i:i+3] == 'JOI':
            ans1 += 1
        elif a[i:i+3] == 'IOI':
            ans2 += 1
            
    print(ans1)
    print(ans2)

Submission status: Accepted

Solution code:
def JOIOI(l) :
    count_j = 0
    count_i = 0
    for i in range(len(l)-2) :
        if l[i] == "J" and l[i+1] == "O" and l[i+2] == "I" :
            count_j += 1
        if l[i] == "I" and l[i+1] == "O" and l[i+2] == "I" :
            count_i += 1
    return count_j, count_i

while True :
    try :
        l = input()
    except EOFError :
        break
    
    j, i = JOIOI(l)
    print(j)
    print(i)

Submission status: Accepted

Solution code:
while True:
    try:
        s=input()
    except:
        break
    (a,b)=(0,0)
    for i in range(len(s)-2):
        if (s[i],s[i+1],s[i+2])==("J","O","I"):
            a+=1
        if (s[i],s[i+1],s[i+2])==("I","O","I"):
            b+=1
    print(a)
    print(b)

Submission status: Accepted

Solution code:
def countDuplicate(S, s):
	# S:文字列、s:検索対象文字列
	cnt = 0
	for i in range(0, len(S) - 2):
		if S.startswith(s, i):
			cnt = cnt + 1

	return cnt


while True:
	try:
		S = str(input().strip())
	except:
		break
	print(countDuplicate(S, 'JOI'))
	print(countDuplicate(S, 'IOI'))

Submission status: Accepted

Solution code:
while True:
    try:
        text = input()
    except:
        break
    
    joi = 0
    ioi = 0
   
    while len(text)>2:
        textlist = list(text)
        judgetext = ''.join(textlist[0:3])
        x = judgetext.find('JOI')
        y = judgetext.find('IOI')
        
        if x==-1 and y==-1:
            pass
        if x==0:
            joi += 1
        if y==0:
            ioi += 1
        
        del(textlist[0])
        text = ''.join(textlist)
    
    print(joi)
    print(ioi)

Submission status: Accepted

Solution code:
while True :
    try :
        n = input()
        J = 0
        I = 0
        
        for i in range(len(n) - 2) :
            if n[i : i + 3] == "JOI" :
                J += 1
            elif n[i : i + 3] == "IOI" :
                I += 1
        
        print(J)
        print(I)
        
    except :
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        a=input()
    except:
        break
    b = 0
    c = 0
    for i in range(len(a)-2):
        if a[i:i+3]=='JOI':
            b+=1
        elif a[i:i+3]=='IOI':
            c+=1
        else:
            pass
    print(b)
    print(c)

Submission status: Accepted

Solution code:
while True:
    try:
        n=input()
    except:
        break
    c=[n[i:i+3] for i in range(len(n)-2) ]
    print(c.count('JOI'))
    print(c.count('IOI'))

Submission status: Accepted

Solution code:
def f(x):
  J=0
  I=0
  for i in range(len(x)-2):
    if x[i:i+3]=='JOI':
      J=J+1
    if x[i:i+3]=='IOI':
      I=I+1
  print(J)
  print(I)

while True:
  try:
    f(input())
  except:
    break

Submission status: Accepted

Solution code:
while True:
    try:
        a = list(input())
    except:
        break
    joi = 0
    ioi = 0
    for i in range(len(a)-2):
        if a[i:i+3] == ["J","O","I"]:
            joi += 1
        elif a[i:i+3] == ["I","O","I"]:
            ioi += 1
    print(joi)
    print(ioi)

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
    cnt_j = 0
    cnt_i = 0
    for i in range(len(e)-2):
        if e[i:i+3] == 'JOI':
            cnt_j += 1
        elif e[i:i+3] == 'IOI':
            cnt_i += 1
    print(cnt_j)
    print(cnt_i)

Submission status: Accepted

Solution code:
while 1:
    try:
        S=input()
        JOI,IOI=0,0
        for i in range(len(S)-2):
            r=S[i]+S[i+1]+S[i+2]
            if r=="JOI":
                JOI+=1
            elif r=="IOI":
                IOI+=1
        print(JOI)
        print(IOI)
    except:
        break

Submission status: Accepted

Solution code:
import sys
counter=0
A=[]
for e in sys.stdin:
    str=e.replace("\n", "")
    A.append(0)
    A.append(0)
    for i in range(len(str)-2):
        if str[i:i+3]=="JOI":
            A[counter]+=1
        elif str[i:i+3]=="IOI":
            A[counter+1]+=1
    counter+=2
for k in range(len(A)):
    print(A[k])

Submission status: Accepted

Solution code:
def aa(s):
    joi = 0
    ioi = 0
    for i in range(len(s)-2):
        if s[i:i+3] == "JOI":
            joi += 1
        if s[i:i+3] == "IOI":
            ioi += 1
    print(joi)
    print(ioi)
    
n = []
while True:
    try:
        n.append(input())
    except EOFError:
        break
for i in n:
    aa(i)

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
  data = e.replace('\n', '')
  countJOI = 0
  countIOI = 0

  for i in range(len(data) - 2):
    c = data[i:i+3]
    if (c == 'JOI'):
      countJOI += 1
    elif(c == 'IOI'):
      countIOI += 1
  print(countJOI)
  print(countIOI)

Submission status: Accepted

Solution code:
while True:
	try:
		s=input()
	except:
		exit()
	a=b=0
	for i in range(len(s)-2):
		if s[i]=="J" and s[i+1]=="O" and s[i+2]=="I":
			a+=1
		elif s[i]=="I" and s[i+1]=="O" and s[i+2]=="I":
			b+=1
	print(a)
	print(b)

Submission status: Accepted

Solution code:
while 1:
    try:
        s = input()
    except:
        break
    sz = len(s)
    joi,ioi = 0,0
    for i in range(sz - 2):
        t = s[i : i + 3]
        if t == "JOI":
            joi += 1
        elif t == "IOI":
            ioi += 1
    print(joi)
    print(ioi)

Submission status: Accepted

Solution code:
def f(x):
    joi = 0
    ioi = 0
    for i in range(len(x)):
        
        if x[i:i+3] == "JOI":
            joi += 1
        elif x[i:i+3] == "IOI":
            ioi += 1
    print(joi)
    print(ioi)

while True:
    try:
        s = input()
        f(s)
    except:
        exit()