Problem:


Score : 100 points

Problem Statement

There are N students in a school.

We will divide these students into some groups, and in each group they will discuss some themes.

You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.

Divide the students so that the number of groups consisting of three or more students is maximized.

Constraints

1 \leq N \leq 1000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N

Output

If you can form at most x groups consisting of three or more students, print x.

Sample Input 1

8

Sample Output 1

2

For example, you can form a group of three students and another of five students.

Sample Input 2

2

Sample Output 2

0

Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.

Sample Input 3

9

Sample Output 3

3



Sample input:
8


Sample output:
2

Submission status: Runtime Error

Solution code:
n = int(input())
ans(n//3)

Submission status: Runtime Error

Solution code:
def main():
def main():
    N = int(input())
    print(N // 3)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
ptint(int(input())//3)

Submission status: Runtime Error

Solution code:
print('{}'.fotmat(int(input())//3))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
while True:
    N = int(input())
    if N >= 1 and N <= 1000:
        continue
    if N < 3:
        print(0)
    else:
        if N/3 > 3.0:
            print(int(N/3)+1)
        else:
            print(int(N/3))

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input().split())

if 'Y' in S:
    print('Four')
else:
    print('Three')

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(str, input().split(' ')))
#print(s)

si = [print('Four')if 'Y' in s else print('Three') ]

Submission status: Runtime Error

Solution code:
N = (int, input())
print(N//3)

Submission status: Runtime Error

Solution code:
N = (int, input())
N//3

Submission status: Runtime Error

Solution code:
import numpy as np

#### 入力フェーズ開始 ####
HWD = input().split()
H = int(HWD[0])
W = int(HWD[1])
D = int(HWD[2])

A = []
for i in range(H):
    Ai = []
    Ai_raw = input().split()
    for j in range(W):
        Ai.append(int(Ai_raw[j]))
    A.extend(Ai)

Q = int(input())
L = []
R = []
for i in range(Q):
    LRi_raw = input().split()
    L.append(int(LRi_raw[0]))
    R.append(int(LRi_raw[1]))

#### 入力フェーズここまで ####
#### 計算フェーズここから ####

# 各移動で踏むA_ijとそのx,yの値にindexベースで参照できるように
# A_ijの値でindexをソートしておく
x_ = np.arange(W)
x = np.tile(x_, H)
y_ = np.arange(H)
y = np.repeat(y_, W)
# A_ijの値でsortした時のindexの順番を取得
B = np.argsort(A)

for q in range(Q):
    # 各実技試験につき
    score = 0
    Li = L[q]
    Ri = R[q]
    M = int((Ri - Li) / D) # 何回移動が必要か
    m_vec = [Li + D * m for m in range(M+1)] # 通るA_ijの値

    for m in range(M):
        # 各移動につき
        id_from = B[m_vec[m] - 1]
        id_to = B[m_vec[m+1]- 1]
        score += np.abs(x[id_from] - x[id_to]) + np.abs(y[id_from] - y[id_to])

    print(score)

Submission status: Runtime Error

Solution code:
N = input()

return int( N / 3 )

Submission status: Runtime Error

Solution code:
N = input()

def groupMaker(N):
    if N < 0 or N > 100:
        print('invalid input')
        return -1
    m = N / 3
    return int(m)

return groupMaker(N)

Submission status: Runtime Error

Solution code:
s = input()$
return int(s)//3$

Submission status: Runtime Error

Solution code:
n = int(input())
l = input().split()
l = set(l)
length = len(l)

if length == 4:
    print("Four")
else:
    print("Three")

Submission status: Runtime Error

Solution code:
# --*-- encoding:utf-8 --*--
 
n = input()
list = input().split(" ")
result = []
 
for i in list:
  if i not in result:
    result.append(i)
 
print(len(result))

Submission status: Runtime Error

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

print(input() / 3)

Submission status: Runtime Error

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

n = input()
list = input().split(" ")
result = []

for i in list:
  for x not in list:
    result.append(x)

print(len(result))

Submission status: Runtime Error

Solution code:
print(int(input() // 3)

Submission status: Runtime Error

Solution code:
N=int(input())
a=[]
for i in range(N):
    a.append(input())

import numpy as np
s=np.zeros(5)

for i in a:
    if i[0]=="M":
        s[0]+=1
    elif i[0]=="A":
        s[1]+=1
    elif i[0]=="R":
        s[2]+=1
    elif i[0]=="C":
        s[3]+=1
    elif i[0]=="H":
        s[4]+=1
    else:
        continue
b=np.unique(s)
c=0
if len(b)<3:
    print(0)
else:
    for i in range(0,3):
        for j in range(i+1,4):
            for k in range(j+1,5):
                c+=s[i]*s[j]*s[k]
    print(c)

Submission status: Runtime Error

Solution code:
N = int(input())

ball_list = map(str, input().split())
type_num = len(list(set(ball_list)))

if type_num == 3:
    print('Three')
else:
    print('Four')

Submission status: Runtime Error

Solution code:
N = int(input())

ball_list = []

for i in range(N):
    ball_list.append(int(input()))

print(len(list(set(ball_list))))

Submission status: Runtime Error

Solution code:
ips = []
ips.append(input())
while True:
    try:
        ips.append(input())
    except (EOFError):
        break
num = int(ips[0])
hina = ips[1]
v = []
for i in range(num):
    if hina[i] not in v:
        v.append(hina[i])
if len(v) == 3:
    print("three")
elif len(v) == 4:
    print("four")

Submission status: Runtime Error

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


N = int(input())
S = []
for i in range(N):
    S.append(input())

m = sum([name[0] == 'M' for name in S])
a = sum([name[0] == 'A' for name in S])
r = sum([name[0] == 'R' for name in S])
c = sum([name[0] == 'C' for name in S])
h = sum([name[0] == 'H' for name in S])

print(m * (a * (r + c + h) + r * (c + h) + c * h) + a * (r * c + c * h) + r * c * h)

Submission status: Runtime Error

Solution code:
a = input()
b = a / 3
print(b)

Submission status: Runtime Error

Solution code:
a = input()
print(a/3)

Submission status: Runtime Error

Solution code:
n = int(input())
items = set(input().split())
results = {3: 'Three', 4: 'Four'}
if len(items) in results:
    print(results[len(items)])

Submission status: Runtime Error

Solution code:
N=int(input())
NCount = 0
while N =>0:
    NCount+= 1
    N -=3
print(NCount-1)

Submission status: Runtime Error

Solution code:
H,W,D = map(int,input().split())
A = []

for i in range(H):
    AH = map(int,input().split())
    A.append(list(AH))
Q = int(input())

for l in range(Q):
    s=0
    L,R = map(int,input().split())
    
    while L != R:
        for m in A:
            if L in m:
                i=A.index(m)
                j=m.index(L)
            if L+D in m:
                x=A.index(m)
                y=m.index(L+D)
                
        L +=D
        s += abs(x-i)+abs(y-j)
            
    print(s)

Submission status: Runtime Error

Solution code:
H,W,D = list(map(int, input().split()))
X = [[0,0] for i in range(H*W+1)]

for i in range(1, H+1):
	A = list(map(int, input().split()))
	for idx, a in enumerate(A):
		X[a] = [i, idx+1]

Q = int(input())
L = []
R = []
S = [0]*(H*W+1)

for i in range(Q):
	l,r = list(map(int, input().split()))
	L.append(l)
	R.append(r)

for i in range(D+1, H*W+1):
	S[i] = S[i-D] + abs(X[i][0]-X[i-D][0])+abs(X[i][1]-X[i-D][1])

for i in range(Q):
	print(S[R[i]] - S[L[i]])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
print int(N/3)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = input()
print (N/3)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = input()
print N/3

Submission status: Runtime Error

Solution code:
N = int(input())
name_list = [input() for name in range(N)]
char_list = ['M', 'A', 'R', 'C', 'H']
count_list = [0 for _ in range(N)]

for name in name_list:
    if name[0] in char_list:
        count_list[char_list.index(name[0])] += 1
score=0
for x in range(5):
    for y in range(x+1,5):
        for z in range(y+1,5):
            score+=count_list[x]*count_list[y]*count_list[z]

print(score)

Submission status: Runtime Error

Solution code:
<?php
$n = intval(trim(fgets(STDIN)));
$ans = floor($n/3);
print "$ans\n";
?>

Submission status: Runtime Error

Solution code:
N = int(input())
num = [0,0,0,0,0]
answer = 0
for i in range(N):
	a = input()
	if a[0]=='M':
		num[0] += 1
	if a[0]=='A':
		num[1] += 1
	if a[0]=='R':
		num[2] += 1
	if a[0]=='C':
		num[3] += 1
	if a[0]=='H':
		num[4] += 1

for i in range(3):
  for j in range(i+1, 4):
	for k in range(j+1, 5):
		answer += num[i]*num[j]*num[k]

print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(str, input().split()))
if 'Y' in S:
    print('Four')
else:
    print('Three')

Submission status: Runtime Error

Solution code:
import itertools as it
# -*- coding: utf-8 -*-
# 個数の入力
N = int(input())
# 改行区切りの名前の入力
S = []
for i in range(N):
    S.append(input())
# データの加工
for i in range(N):
	S[i] = S[i][0]

# 文字列カウント
count = [S.count('M'), S.count('A'), S.count('R'), S.count('C'), S.count('H')]

# 数え上げ
answer = count[0]*count[1]*count[2]
answer = count[0]*count[1]*count[3] + answer
answer = count[0]*count[1]*count[4] + answer
answer = count[0]*count[2]*count[3] + answer
answer = count[0]*count[2]*count[4] + answer
answer = count[0]*count[3]*count[4] + answer
answer = count[1]*count[2]*count[3] + answer
answer = count[1]*count[2]*count[4] + answer
answer = count[1]*count[3]*count[4] + answer
answer = count[2]*count[3]*count[4] + answer

# 出力
print(answer)

Submission status: Runtime Error

Solution code:
n = input()
chars=input().split()
myset=set()
for char in chars:
    myset.add(char)

print(len(myset))

Submission status: Runtime Error

Solution code:
N = int(input())
S ="MARCH"
S2 = [0]*len(S)
n=0

for i in range(N):
    s = input()
    for k, j in enumerate(S2):
        if s[0] == j:
            S2[k]+=1
            
for i in range(len(S2)):
    for j in range(i+1,len(S2)):
        for k in range(j+1,len(S2)):
            n +=S2[i]*S2[j]*S2[k]
    
print(n)

Submission status: Runtime Error

Solution code:
# https://abc089.contest.atcoder.jp/tasks/abc089_c

import copy

n = int(input())
s = [input().replace("\n", "") for i in range(n)]
march_num_list = [0, 0, 0, 0, 0]

for name in s:
    for i, head in enumerate(("M", "A", "R", "C", "H")):
        if name[0] == head:
            march_num_list[i] += 1

pattern_num = 0

for i in range(len(march_num_list)):
    two_list = copy.copy(march_num_list)
    two_list.pop(i)
    for j in range(len(two_list)):
        three_list = copy.copy(two_list)
        three_list.pop(j)
        for k in range(len(three_list)):
            pattern_num += 1

print(pattern_num)

Submission status: Runtime Error

Solution code:
tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dict = {}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dict[tmp[d]] = str(i)+' '+str(d)
result ={}
cost ={}

def calcost(L,R,D):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        posi1 = dict[R].split()
        posi2 = dict[str(int(R)-D)].split()
        costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))
        if str(int(R)-D) in cost:
            cost[R] = costs + cost[str(int(R)-D)]
            return cost[R]
        else:
            cost[R] = costs + calcost(L,str(int(R)-D),D)
            return cost[R]

for n in range(D+1,H*W+1):
    calcost(str(1),str(n),D)

Q = int(input())
for j in range(Q):
    tmpx = input()
    if tmpx in result:
        print(result[tmpx])
    else:
        tmp = tmpx.split()
        result[tmpx] = cost[tmp[1]]-cost[tmp[0]]
        print(result[tmpx])

Submission status: Runtime Error

Solution code:
int x
raw_input(x)
int y = x%3
print(y)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
Names = []
n_M, n_A, n_R, n_C, n_H = 0,0,0,0,0
for i in range(N):
	Name = raw_input()
	if Name[0] == "M":
		n_M += 1
	if Name[0] == "A":
		n_A += 1
	if Name[0] == "R":
		n_R += 1
	if Name[0] == "C":
		n_C += 1
	if Name[0] == "H":
		n_H += 1

C = (n_M * n_A * n_R + 
	n_M * n_A * n_C +
	n_M * n_A * n_H +
	n_M * n_R * n_C +
	n_M * n_R * n_H +
	n_M * n_C * n_H +
	n_A * n_R * n_C +
	n_A * n_R * n_H +
	n_A * n_C * n_H +
	n_R * n_C * n_H
	)

print C

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = set(input().split(' '))

    if len(S) == 3:
        print('Three')
    else:
        print('Four')

Submission status: Runtime Error

Solution code:
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        System.out.println(N / 3);
    }

}

Submission status: Runtime Error

Solution code:
print((int)input()/3)

Submission status: Runtime Error

Solution code:
a = int(imput())
m = int(a / 3)
print(m)

Submission status: Runtime Error

Solution code:
ip = input()

ans = ip / 3
print(int(ans))

Submission status: Runtime Error

Solution code:
def main():
    N = input()
    S = input().strip().split()

    if len(set(S)) == 3:
        return 'Three'
    else:
        return 'Four'
    
if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
n = int(print())
group = 0
if n%3==0:
    group = n/3
elif n%3==1:
    group = (n-1)/3
else:
    group = (n-2)/3
print(int(group))

Submission status: Runtime Error

Solution code:
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

dp = {}

def dp_search(L, R, D, num_dic):
    global dp
    if (L, R) in dp:
        return dp[(L, R)]
    if L== R:
        return 0

    if L + D == R:
        now_pos = num_dic[L]
        next_pos = num_dic[R]
        dp[(L, R)] =  abs(next_pos[0] - now_pos[0]) + abs(next_pos[1] - now_pos[1])
        return dp[(L, R)]

    dp[(L, R)] = dp_search(L , R - D, D , num_dic) + dp_search(L + D , R, D , num_dic)

    return dp[(L, R)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W, D] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    num_dic= {}
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            num_dic[int(input_raw[j])] = (i, j)
    input_raw = read_func().strip().split()
    [Q] = [int(input_raw[0])]
    test_list = []
    for i in range(Q):
        input_raw = read_func().strip().split()
        test_list.append((int(input_raw[0]), int(input_raw[1])))

    dp = [[] for i in range(D)]

    for i in range(0, H * W):
        A = i + 1
        if len(dp[A % (D)]) == 0:
            dp[A % (D)].append((A, 0))
        else:
            (prev_point, prev_cost)= dp[A % D][len(dp[A % D]) - 1]
            prev_pos = num_dic[prev_point]
            now_pos = num_dic[A]
            dp[A % (D)].append((A, prev_cost +abs(prev_pos[0] - now_pos[0]) + abs(prev_pos[1] - now_pos[1])))

    for test in test_list:
        L = test[0]
        R = test[1]
        if L==R:
            print 0
        else:
            print (dp[L % (D)] [R/(D) - 1 + (1 if R % D != 0 else 0)][1] -
                    (dp[L % (D)] [L/(D) - 1 + (1 if L % D != 0 else 0)][1] ))




if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
h, w, d = map(int, input().split())

a = [list(map(int, input().split())) for i in range(h)]

dic = [0] * (h * w)

for i in range(h):
    for j in range(w):
        dic[a[i][j] - 1] = i, j

s = [[0] * (h * w // d + 1) for i in range(d)]

for i in range(d):
    for j in range(1, h * w // d + 1):
        b = i + d * (j - 1)
        c = i + d * j

        if c >= len(dic):
            break
        
        y, x = dic[b]
        ny, nx = dic[c]
        s[i][j] = s[i][j - 1] + abs(ny - y) + abs(nx - x)

q = int(input())

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    print(s[l % d][r // d] - s[l % d][l // d])

Submission status: Runtime Error

Solution code:
n = int(input())
 
M = 0
A = 0
R = 0
C = 0
H = 0
 
res = 0
 
for i in range(n):
    char = input()[0]
    if char == "M":
        M += 1
    elif char == "A":
        A += 1
    elif char == "R":
        R += 1
    elif char == "C":
        C += 1
    elif char == "H":
        H += 1
 
res += M * A * R;
res += M * A * C;
res += M * A * H;
res += M * R * C;
res += M * R * H;
res += M * C * H;
 
res += A * R * C;
res += A * R * H;
res += A * C * H;
 
res += R * C * H;
 
print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
if("Y" in s):
      print("Four")
else:
      print("Three")

Submission status: Runtime Error

Solution code:
h,w,d=map(int,input().split())

board=[0 for _ in range(h*w)]

for i in range(h):
    for j,a in enumerate(input().split()):
        board[i*w+j]=int(a)

q=int(input())


distances=[0 for _ in range(h*w)]

for i in range(d,h*w):
    a=h*w-i
    tmp=board.index(a)
    i=tmp//w
    j=tmp%w
    tmp=board.index(a+d)
    x=tmp//w
    y=tmp%w
    distances[a-1]=distances[a+d-1]+abs(i-x)+abs(j-y)

for _ in range(q):
    l,r=map(int,input().split())
    print(distances[l-1]-distances[r-1])

Submission status: Runtime Error

Solution code:
N = input()
a = []
for i in range(N):
    a.append(input())
b = list(set(a))
If length(b) ==3 :
  print(3)
elso :
  print(4)

Submission status: Runtime Error

Solution code:
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

dp = {}

def dp_search(L, R, D, num_dic):
    global dp
    if (L, R) in dp:
        return dp[(L, R)]
    if L== R:
        return 0

    if L + D == R:
        now_pos = num_dic[L]
        next_pos = num_dic[R]
        dp[(L, R)] =  abs(next_pos[0] - now_pos[0]) + abs(next_pos[1] - now_pos[1])
        return dp[(L, R)]

    dp[(L, R)] = dp_search(L , R - D, D , num_dic) + dp_search(L + D , R, D , num_dic)

    return dp[(L, R)]


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W, D] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    num_dic= {}
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            num_dic[int(input_raw[j])] = (i, j)
    input_raw = read_func().strip().split()
    [Q] = [int(input_raw[0])]
    test_list = []
    for i in range(Q):
        input_raw = read_func().strip().split()
        test_list.append((int(input_raw[0]), int(input_raw[1])))

    dp = [[0 for i in range(H)] for j in range(W)]
    for test in test_list:
        L = test[0]
        R = test[1]
        print dp_search(L,R,D,num_dic)




if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
Q = I()

m = [[0]*H*W for i in range(H*W)] 
def calc(l,r):
    if m[l][r] != 0:
        return m[l][r]
    else:
        maho = 0
        for k in range(l,r,D):
            maho += abs(d[k+D][0] - d[k][0]) + abs(d[k+D][1] - d[k][1])
        m[l][r] = maho
        return maho
    
for q in range(Q):
    l,r = Is()
    maho = calc(l,r)
    print(maho)

Submission status: Runtime Error

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


def filter_name(n):
    return n.startswith("M") or n.startswith("A") or n.startswith("R") or n.startswith("C") or n.startswith("H")


def filter_ok(l):
    dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for i in l:
        dic[i[0:1]] += 1
    for num in dic.values():
        if num >= 2:
            return False
    return True


n = input()
a = []
for i in range(n):
    a.append(raw_input())

r = filter(filter_name, a)
c = list(itertools.combinations(r, 3))
r = filter(filter_ok, c)
print len(r)

Submission status: Runtime Error

Solution code:
H, W, D = map(int,input().split())
dist = [[float("inf") for i in range(H*W+1)] for j in range(H*W+1)]
for i in range(H*W+1):
  dist[i][i] = 0
#dist[i][j]は隣接行列
pos = [[0,0] for i in range(H*W+1)]
for i in range(H):
  A = list(map(int,input().split()))
  for j in range(W):
    pos[A[j]] = [i+1, j+1]
for i in range(H*W+1-D):
  dist[i][i+D] = abs(pos[i][0]-pos[i+D][0])+abs(pos[i][1]-pos[i+D][1])
distances = [[] for i in range(D)]#あまりがiの距離
for i in range(1,H*W+1-D):
  d = dist[i][i+D]
  distances[i%D]+=[d]
distances2 = [[0] for i in range(D)]#累積和に直す
for i in range(D):
  K = len(distances[i])
  for j in range(K):
    distances2[i]+=[distances2[i][-1]+distances[i][j]]
Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  q = L%D
  l, r = (L-1)//D, (R-1)//D
  print(distances2[q][r]-distances2[q][l])

Submission status: Runtime Error

Solution code:
import sys
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
Q = I()
for q in range(Q):
    l,r = Is()
    maho = 0
    for k in range(l,r,D):
        maho += abs(d[k+D][0] - d[k][0]) + abs(d[k+D][1] - d[k][1])
    print(maho)

Submission status: Runtime Error

Solution code:
H, W, D = map(int, input().split())

A = [list(map(int, input().split())) for i in range(H)]
rA = [[0 for j in range(2)] for i in range(H * W + 1)]
S = [0 for i in range(H * W + 1)]
for i in range(H):
	for j in range(W):
		rA[A[i][j]][0] = i
		rA[A[i][j]][1] = j

Q = int(input())
for i in range(Q):
	L, R = map(int, input().split())
	ans = 0
	for j in range(H * W + 1) [L::D]:
		if j == R:
			break
		if S[j]:
			ans += S[j]
			break
		S[j] -= ans
		ans += abs(rA[j + D][1] - rA[j][1]) + abs(rA[j + D][0] - rA[j][0])
	for j in range(H * W + 1)[L::D]:
		if S[j] > 0:
			break
		S[j] += ans
	print (ans)

Submission status: Runtime Error

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
Q = I()
for q in range(Q):
    l,r = Is()
    maho = 0
    for k in range(l,r,D):
        maho += abs(d[k+D][0] - d[k][0]) + abs(d[k+D][1] - d[k][1])
    print(maho)

Submission status: Runtime Error

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
import itertools
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
Q = I()
for q in range(Q):
    l,r = Is()
    maho = 0
    for k in range(l,r,D):
        maho += abs(d[k+D][0] - d[k][0]) + abs(d[k+D][1] - d[k][1])
    print(maho)

Submission status: Runtime Error

Solution code:
import itertools
import math

N = int(input())
S_list = []
for i in range(N):
    S_list.append(input())

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
a = sum(count)

x = a*(a-1)*(a-2)/math.factorial(3)

for c in count:
    if c > 2:
        x -= c*(c-1)*(c-2)/math.factorial(3)
    elif c == 2:
        x -= (a-2)

print(int(x))

Submission status: Runtime Error

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

def comb1(n, r):
    if n == 0 or r == 0: return 1
    return comb1(n, r-1) * (n-r+1) / r

a = int(input())
# スペース区切りの整数の入力
m_members = []
a_members = []
r_members = []
c_members = []
h_members = []

for i in range(a):
    member = input()
    if(member[0:1] == 'M'):
        m_members.append(member)
    elif(member[0:1] == 'A'):
        a_members.append(member)
    elif(member[0:1] == 'R'):
        r_members.append(member)
    elif(member[0:1] == 'C'):
        c_members.append(member)
    elif(member[0:1] == 'H'):
        h_members.append(member)

member_info = []
count = 0
result = 0

if(len(m_members) != 0):
    member_info.append(len(m_members))
    count += 1
if(len(a_members) != 0):
    member_info.append(len(a_members))
    count += 1
if(len(r_members) != 0):
    member_info.append(len(r_members))
    count += 1
if(len(c_members) != 0):
    member_info.append(len(c_members))
    count += 1
if(len(h_members) != 0):
    member_info.append(len(h_members))
    count += 1

if(count >= 3):
    for i in (list(itertools.combinations(member_info, 3))):
        result += i[0] * i[1] * i[2]
    print(result)
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
print(N/3)

Submission status: Runtime Error

Solution code:
pink = 0
green = 0
white = 0
yellow = 0

n = input()
l = raw_input().split()
 
for i in range(n):
   
    if(l[i] == 'P'):
        pink = 1

    if(l[i]== 'G'):
        green = 1

    if(l[i] == 'W'):
        white = 1

    if(l[i] == 'Y'):
        yellow = 1

if(pink + white + green + yellow) == 4:
    print u"Four"
else:
    print u"Three"

Submission status: Runtime Error

Solution code:
def ACBC_089_C():
    _num = int(input())
    _namelist = []
    _countM = 0
    _countA = 0
    _countR = 0
    _countC = 0
    _countH = 0

    for i in range(0, _num):
        _name = str(input())
        _namelist.append(_name)
        if _name[0] == "M":
            _countM += 1
        elif _name[0] == "A":
            _countA += 1
        elif _name[0] == "R":
            _countR += 1
        elif _name[0] == "C":
            _countC += 1
        elif _name[0] == "H":
            _countH += 1
    print(_countM * _countA * _countR + \
          _countM * _countA * _countC + \
          _countM * _countA * _countH + \
          _countM * _countR * _countC + \
          _countM * _countR * _countH + \
          _countM * _countC * _countH + \
          _countA * _countR * _countC + \
          _countA * _countR * _countH + \
          _countA * _countC * _countH + \
          _countR * _countC * _countH + \
          )

ACBC_089_C()

Submission status: Runtime Error

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

N = input()
m,a,r,c,h = 0
for i in range(N):
	S = raw_input()
	if S[:1] == "M":
		m += 1
	elif S[:1] == "A":
		a += 1
	elif S[:1] == "R":
		r += 1
	elif S[:1] == "C":
		c += 1
	elif S[:1] == "H":
		h += 1
print m*a*r+m*a*c+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h

Submission status: Runtime Error

Solution code:
pink = 0
green = 0
white = 0
yellow = 0

n = input()
l = raw_input().split()
 
for i in range(n):
   
    if(l[i] == 'P'):
        pink = 1

    if(l[i]== 'G'):
        green = 1

    if(l[i] == 'W'):
        white = 1

    if(l[i] == 'Y'):
        yellow = 1

if(pink + white + green + yellow) == 4:
    print('Four')
else:
    print('Three')

Submission status: Runtime Error

Solution code:
pink = 0
green = 0
white = 0
yellow = 0

n = input()
l = raw_input().split()
 
for i in range(n):
   
    if(l[i] == 'P'):
        pink = 1

    if(l[i]== 'G'):
        green = 1

    if(l[i] == 'W'):
        white = 1

    if(l[i] == 'Y'):
        yellow = 1

if(pink + white + green + yellow) == 4:
    print('Four')

if(pink + white + green + yellow) == 3:
    print('Three')

Submission status: Runtime Error

Solution code:
 N= int(input())
ans =0
if N<=2:
    print('0')
else:
    ans=N//3
    print(ans)

Submission status: Runtime Error

Solution code:
n= int(input())
print( n//3)

Submission status: Runtime Error

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

N = input()
S = raw_input.split()
for i in range(N):
	if S[i] == 'Y':
		print('Four')
		N = -1
		break
if N = -1:print('Three')

Submission status: Runtime Error

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

if 'Y' in s:
    print('Four')
else:
    print('Three')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
# スペース区切りの整数の入力
members = input().split()
a = []
count = 0

for member in members:
    if(member not in a):
        a.append(member)
        count += 1
if(count == 3):
    print("Three")
elif(count == 4):
    print("Four")

Submission status: Runtime Error

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

a = int(input())

if a < 2:
    print(0)
elif a%3 == 0:
    print(int(a/3))
elif a%3 == 1:
    print(int(a/3) - 1)
else:
    print(int(a/3)

Submission status: Runtime Error

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

X = raw_input()
print X/3

Submission status: Runtime Error

Solution code:
n = int(input())

s = input().split()
color = "Three"

for i in s:
    if i == "Y":
        color = "Four"
        break
print(color)

Submission status: Runtime Error

Solution code:
X = raw_input()
print X//3

Submission status: Runtime Error

Solution code:
import sys

N=sys.argv[0]
print(int(N/3)

Submission status: Runtime Error

Solution code:
n=int(input()
print(int(n//3))

Submission status: Runtime Error

Solution code:
print(int(int(input())num / 3))

Submission status: Runtime Error

Solution code:
print(input()/3)