code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,629B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
def main():
K = int(input())
A,B = map(int,input().split())
for i in range(A,B+1):
if i%K == 0:
return('OK')
return('NG')
print(main())
| K = int(input())
A,B = map(int,input().split())
if (B//K *K)>=A:
print("OK")
else:
print("NG") | 1 | 26,482,856,851,092 | null | 158 | 158 |
container = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
unser = int(input())
print(container[unser - 1]) | #!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np
# A = input()
A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(li[A-1]) | 1 | 49,937,620,287,008 | null | 195 | 195 |
S = input()
N = len(S)
one = S[:(N-1) // 2]
two = S[(N+3) // 2 - 1:]
if S == S[::-1]:
if one == one[::-1]:
if two == two[::-1]:
print('Yes')
exit()
print('No')
| from itertools import *
from collections import *
from functools import *
def isqrt(n):
if n > 0:
x = 1 << (n.bit_length() + 1 >> 1)
while True:
y = (x + n // x) >> 1
if y >= x:
return x
x = y
elif n == 0:
return 0
else:
raise ValueError
def qrime():
yield from [2, 3, 5, 7]
q = [i for i in range(1, 210, 2) if 0 not in (i%3, i%5, i%7)]
yield from q[1:]
for i in count(210, 210):
for j in q:
yield i + j
def factor(n):
p = Counter()
limit = isqrt(n)
for q in qrime():
if q > limit:
break
while n % q ==0:
p[q] += 1
n //= q
if q in p:
limit = isqrt(n)
if n != 1:
p[n] += 1
return p
def divisor(n):
p, m = zip(*factor(n).items())
for c in product(*map(lambda x:range(x+1), m)):
yield reduce(int.__mul__, (x**y for x, y in zip(p, c) if y), 1)
N = int(input())
ans = reduce(int.__mul__, (c+1 for c in factor(N-1).values()), 1) - 1
for d in divisor(N):
if d == 1:
continue
n = N
while n % d == 0:
n //= d
if n % d == 1:
ans += 1
print(ans)
| 0 | null | 43,556,100,185,660 | 190 | 183 |
n = int(input())
g = [[]for i in range(n)]
for i in range(n):
v = list(map(int,input().split()))
u = v[0]-1
k = v[1]
for j in range(k):
g[u].append(v[j+2]-1)
time = 1
ans = []
d = [0]*n
f = [0] *n
visited = [0]*n
def dfs(now,last = -1):
global time
visited[now] = 1
d[now] = time
time += 1
for next in g[now]:
if visited[next]:continue
dfs(next,now)
f[now] = time
time +=1
for i in range(n):
if not visited[i]:dfs(i)
for i in range(n):
print(i+1,d[i],f[i])
| # N=4
# G=[[2],[4],[],[3]]
import sys
sys.setrecursionlimit(1000000)
N=int(input())
G=[list(map(int, input().split()))[2:] for _ in range(N)]
v=[False]*N
d=[0]*N
f=[0]*N
timecount=1
def dfs(i):
global timecount
if v[i] : return
v[i] = True
d[i] = timecount
# print("D",i+1,timecount)
timecount += 1
for p in G[i]:
dfs(p-1)
# print("F",i+1,timecount)
f[i] = timecount
timecount += 1
return
for i in range(N):
if v[i]==0: dfs(i)
for i in range(N):
print(i+1, d[i], f[i])
| 1 | 2,912,289,370 | null | 8 | 8 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
N,K = map(int, read().split())
k = int(math.log(N, 10))
s = N // (10 ** k)
tmp1, tmp2, div = 1, 1, 1
for i in range(K-1):
tmp1 *= k-i
div *= i+1
tmp2 *= 9
ret = tmp1//div * tmp2
ret *= s-1
tmp1 *= k - (K-1)
tmp2 *= 9
div *= K
ret += tmp1 * tmp2 // div
lis = range(k)
nums = range(1,10)
base = s * 10 ** k
for A in combinations(lis, K-1):
for X in product(nums, repeat = K-1):
tmp = base
for a,x in zip(A,X):
tmp += 10 ** a * x
if tmp <= N:
ret += 1
print(ret)
if __name__ == "__main__":
run() | n = input()
for e in n:
if e == '7':
print('Yes')
break
else:
print('No')
| 0 | null | 54,947,309,307,320 | 224 | 172 |
# 貪欲+山登り(日付をランダムに2つ選んで更新)
import time
import random
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = []
L = [-1 for j in range(26)]
for i in range(d):
max_diff = -10**7
arg_max = 0
for j in range(26):
memo = L[j]
L[j] = i
diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
if diff > max_diff:
max_diff = diff
arg_max = j
L[j] = memo
T.append(arg_max)
L[arg_max] = i
def calc_score(T):
L = [-1 for j in range(26)]
X = [0 for j in range(26)]
score = 0
for i in range(d):
score += S[i][T[i]]
X[T[i]] += (d - i) * (i - L[T[i]])
L[T[i]] = i
for j in range(26):
score -= C[j] * (dd - X[j])
return score
score = calc_score(T)
start = time.time()
cnt = 0
while True:
now = time.time()
if now - start > 1.8:
break
i0, i1 = tuple(random.sample(range(d), 2))
arg_max = (0, 0)
max_diff = 0
for j0 in range(26):
for j1 in range(26):
memo = (T[i0], T[i1])
T[i0], T[i1] = j0, j1
new_score = calc_score(T)
if new_score - score > max_diff:
max_diff = new_score - score
arg_max = (j0, j1)
T[i0], T[i1] = memo
if max_diff > 0:
T[i0], T[i1] = arg_max
score += max_diff
cnt += 1
for t in T:
print(t + 1)
| #-------------------------------------------------------------------------------
#関数定義
def f(a,d,T):
try:
return T[d+1:].index(a)+(d+1)
except ValueError:
return len(T)
def g(a,d,T):
try:
return (d-1)-T[d-1::-1].index(a)
except ValueError:
return 0
#-------------------------------------------------------------------------------
#インポート
from math import inf,exp
from random import random,randint
import time
from copy import copy
#-------------------------------------------------------------------------------
#定数
TIME_LIMIT=1.864 #ループの時間制限
A=26 #アルファベットの数
START=time.time()
ALPHA=15
ep=10**(-6) #アニーリングの微小温度
#-------------------------------------------------------------------------------
#読み込み部
D=int(input())
C=[True]+list(map(int,input().split())) #減る満足度のベース
S=[True]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度
for i in range(1,D+1):
S[i]=[0]+list(map(int,input().split()))
#-------------------------------------------------------------------------------
#貪欲部
L=[0]*(A+1)
T=[0]
for d in range(1,D+1):
Y=-inf
E=0
for a in range(1,A+1):
X=S[d][a]
for s in range(1,A+1):
if a!=s:
X-=C[s]*(d-L[s])
if X>Y:
Y=X
E=a
L[E]=d
T.append(E)
#-------------------------------------------------------------------------------
#調節部
t=time.time()-START
while t<TIME_LIMIT:
d=randint(1,D)
p=T[d]
q=randint(1,A)
Delta=(S[d][q]-S[d][p])+(d-g(q,d,T))*(f(q,d,T)-d)*C[q]-(d-g(p,d,T))*(f(p,d,T)-d)*C[p]
if (Delta>=0) or (Delta<0 and random()<exp(Delta/(ALPHA*(TIME_LIMIT-t)+ep))):
T[d]=q
t=time.time()-START
for i in range(1,D+1):
print(T[i])
| 1 | 9,709,495,987,490 | null | 113 | 113 |
while(1):
str = raw_input()
if str == "-":
break
else:
m = int(raw_input())
for i in range(m):
h = int(raw_input())
str = str[h:len(str)] + str[0:h]
print str | N=int(input())
arms=[list(map(int,input().split())) for _ in range(N)]
points=[]
for i in range(N):
points.append([arms[i][0]-arms[i][1],arms[i][0]+arms[i][1]])
#print(points)
points.sort(key=lambda x:x[1])
#print(points)
nowr=-float("inf")
cnt=0
for i in points:
l,r=i
if nowr<=l:
nowr=r
cnt=cnt+1
print(cnt)
| 0 | null | 46,095,614,371,590 | 66 | 237 |
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] - sum(b) >= 0:
print(a[0] - sum(b))
else:
print(-1)
| a,b = map(float, raw_input().split())
d = int(a / b)
e = int(a % b)
r = a / b
print "%d %d %f" %(d,e,r) | 0 | null | 16,145,929,754,948 | 168 | 45 |
n,a,b = map(int,input().split())
t = n // (a+b)
ans = t*a
s = n % (a+b)
if s <= a:
ans += s
else:
ans += a
print(ans) | import math
N=int(input())
ans=0
for i in range(1,N+1):
for j in range(i,N+1):
for k in range(j,N+1):
if i==j and j==k:
ans+=i
elif i<j and j<k:
ans+=6*math.gcd(i,math.gcd(j,k))
else:
ans+=3*math.gcd(i,math.gcd(j,k))
print(ans)
| 0 | null | 45,384,689,873,962 | 202 | 174 |
N=int(input());M=N//500;M*=1000;X=500*(N//500);N-=X;M+=(N//5)*5;print(M) | n=int(input())
res=0
for i in range(1,n+1):
if int(i*1.08)==n:
res=i
if res != 0:
print(res)
else:
print(":(") | 0 | null | 84,532,495,005,042 | 185 | 265 |
k=int(input())
k+=1
o=''
a='ACL'
if k==1:
print('')
exit()
else:
for i in range(1,k):
o=o+a
print(o) | def i():
return int(input())
def i2():
return map(int,input().split())
def s():
return str(input())
def l():
return list(input())
def intl():
return list(int(k) for k in input().split())
n = i()
d = intl()
ans = 0
for i in range(n):
for j in range(i+1,n):
ans += d[i]*d[j]
print(ans) | 0 | null | 84,978,505,835,146 | 69 | 292 |
data = input().split(' ')
a = int(data[0])
b = int(data[1])
if a > b:
print("a > b")
else:
if a < b:
print("a < b")
else:
print("a == b") | n = input().split()
a = int(n[0])
b = int(n[1])
if a < b:
print("a < b")
elif a > b:
print("a > b")
elif a == b:
print("a == b") | 1 | 362,455,602,278 | null | 38 | 38 |
g = input()
l = []
q = []
n = 0
for x in range(len(g)):
if g[x] == '\\':
if n:
l.append(n)
n = 0
if q:
q.append(-1)
q.append(x)
elif g[x] == '/':
if q:
while True:
p = q.pop()
if p == -1:
n += l.pop()
else:
break
n += x-p
else:
pass
if n:
l.append(n)
for j in range(l.count(0)):
l.remove(0)
print(sum(l))
print(len(l), *l) | import math
import sys
import itertools
from collections import deque
# import numpy as np
def main():
S = sys.stdin.readline()
len_S = len(S)
index = 0 # 操作しているSのインデックス
DOWN = [] # 下り文字をスタック
POOL = [] # 水たまりごとの面積
area = 0 # 総面積
for s in S:
if s == '\\':
DOWN.append(index)
elif s == '/' and len(DOWN) > 0:
pool_start = DOWN.pop()
pool_end = index
tmp_area = pool_end - pool_start
area += tmp_area
while True:
if len(POOL) == 0:
break
if POOL[-1]['start'] > pool_start and POOL[-1]['end'] < pool_end:
tmp_area += POOL[-1]['area']
POOL.pop()
else:
break
POOL.append({'start': pool_start, 'end': pool_end, 'area': tmp_area})
index += 1
print(area)
if len(POOL) > 0:
print(len(POOL), end=" ")
for i in range(len(POOL)-1):
print(POOL[i]['area'], end=" ")
print(POOL[-1]['area'])
else:
print(0)
if __name__ == '__main__':
main()
| 1 | 58,393,813,852 | null | 21 | 21 |
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
def __init__(self):
# ????????¶???
self.dice = (2, 5), (3, 4), (1, 6) # x, y, z
self.ax = [[0, False], [1, False], [2, False]]
self.axmap = [0, 1, 2]
self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}
def rotate(self, dir):
def rot(k, r):
t = self.axmap[r]
self.axmap[k], self.axmap[r] = t, self.axmap[k]
self.ax[t][1] = not self.ax[t][1]
rot(*self.mm[dir])
def front(self): return self.value(0, True)
def rear(self): return self.value(0, False)
def right(self): return self.value(1, True)
def left(self): return self.value(1, False)
def top(self): return self.value(2, True)
def bottom(self): return self.value(2, False)
def value(self, ax, d):
a = self.ax[self.axmap[ax]]
return self.dice[a[0]][a[1] if d else not a[1]]
if __name__=="__main__":
dice = Dice()
labels = input().split()
q = int(input())
def tf(p, f, d):
for _ in range(4):
if p==f(): break
dice.rotate(d)
for _ in range(q):
a, b = input().split()
p = labels.index(a) + 1
f = dice.top
tf(p, f, "N")
tf(p, f, "E")
p = labels.index(b) + 1
f = dice.front
tf(p, f, "R")
print(labels[dice.right()-1]) | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
n = readint()
ans = 0
for a in range(1,n):
b = n//a
if a*b==n:
ans += b-1
else:
ans += b
print(ans)
| 0 | null | 1,402,518,735,332 | 34 | 73 |
x1,x2,x3,x4,x5=(int(i) for i in input().split())
if x1==0:
print(1)
elif x2==0:
print(2)
elif x3==0:
print(3)
elif x4==0:
print(4)
else:
print(5) | import sys
R, C, K = list(map(int, input().split()))
d = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)]
t = [[0] * (C+1) for _ in range(R+1)]
for i in range(K):
r,c,v = list(map(int, input().split()))
t[r][c] = v
for i in range(R+1):
for j in range(C+1):
for k in range(4):
if i!=0:
d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])
if j!=0:
d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
if k != 0:
d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j])
a = 0
for i in range(4):
a = max(a, d[i][-1][-1])
print(a)
| 0 | null | 9,551,599,069,822 | 126 | 94 |
from time import time
import random
start = time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
def cal_score(t):
S = 0
last = [-1] * 26
score = 0
for d in range(D):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
return score
def main():
t = [random.randint(0, 25) for _ in range(D)]
score = cal_score(t)
while time()-start + 0.2 < 2:
d = random.randint(0, D-1)
q = random.randint(0, 25)
old = t[d]
t[d] = q
new_score = cal_score(t)
if new_score < score:
t[d] = old
else:
score = new_score
return t
if __name__ == "__main__":
ans = main()
for t in ans:
print(t+1) | def do_calc(data):
from collections import deque
s = deque() # ??????????????¨??????????????????
while data:
elem = data[0]
data = data[1:]
if elem == '+' or elem == '-' or elem == '*':
a = s.pop()
b = s.pop()
if elem == '+':
s.append(b + a)
elif elem == '-':
s.append(b - a)
elif elem == '*':
s.append(b * a)
else:
s.append(int(elem))
return s.pop()
if __name__ == '__main__':
# ??????????????\???
data = [x for x in input().split(' ')]
# data = ['1', '2', '+', '3', '4', '-', '*']
# ???????????????
result = do_calc(data)
# ???????????????
print(result) | 0 | null | 4,856,608,171,870 | 113 | 18 |
class Dice:
def __init__(self,d1,d2,d3,d4,d5,d6):
self.dice = [d1,d2,d3,d4,d5,d6]
def turn(self,dir):
if dir == 'S':
self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
if dir == 'N':
self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
if dir == 'W':
self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
if dir == 'E':
self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]
def check(m):
for b in range(4):
m.turn('N')
if m.dice[0] == a[0] and m.dice[1] == a[1]:
return(m.dice[2])
dice_num = input().split()
q = int(input())
conditions = []
for a in range(q):
temp = input().split()
conditions.append(temp)
init_Dice = Dice(dice_num[0],dice_num[1],dice_num[2],dice_num[3],dice_num[4],dice_num[5])
kaitou = []
for a in conditions:
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('W')
init_Dice.turn('N')
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
init_Dice.turn('E')
if check(init_Dice):
print(check(init_Dice))
continue
| # D - Moving Piece
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
assert len(p) == len(c) == n
visited = [False] * n
scc = []
for i in range(n):
if not visited[i]:
scc.append([])
j = i
while not visited[j]:
visited[j] = True
scc[-1].append(j)
j = p[j] - 1
n_scc = len(scc)
subsum = [[0] for i in range(n_scc)]
for i in range(n_scc):
for j in scc[i]:
subsum[i].append(subsum[i][-1] + c[j])
for j in scc[i]:
subsum[i].append(subsum[i][-1] + c[j])
def lister(k):
for i in range(n_scc):
l = len(scc[i])
loop_score = max(0, subsum[i][l])
for kk in range(1, min(k, l) + 1):
base = loop_score * ((k - kk) // l)
for j in range(kk, l + kk + 1):
yield base + subsum[i][j] - subsum[i][j - kk]
print(max(lister(k)))
| 0 | null | 2,786,282,392,740 | 34 | 93 |
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
def add(x):
if x == 'r':
return p
elif x == 's':
return r
else:
return s
nk =[0]*k
for i in range(n):
key = i%k
if nk[key]==0:
nk[key] = [t[i]]
else:
nk[key].append(t[i])
ans = 0
for j in nk:
if j ==0:
continue
ans += add(j[0])
for k in range(1, len(j)):
if j[k]== j[k-1]:
j[k]='q'
else:
ans += add(j[k])
print(ans) | N, K = [int(i) for i in input().split()]
R, S, P = [int(i) for i in input().split()]
d = {'r': P, 's': R, 'p': S}
T = input()
checked = [False for i in range(N)]
# 勝てるだけ勝てばいい
for i in range(N-K):
if T[i] == T[i+K]:
if checked[i] == False:
checked[i+K] = True
result = 0
for i in range(N):
if checked[i] == False:
result += d[T[i]]
print(result) | 1 | 107,246,304,603,388 | null | 251 | 251 |
n,k=map(int,input().split())
mod=10**9+7
ans=0
for x in range(k,n+2):
min_a=(0+x-1)*x//2
max_a=(n-x+1+n)*x//2
aa=max_a-min_a+1
ans+=aa
print(ans%mod) | #!usr/bin/env python3
import sys
def int_fetcher():
num = int(sys.stdin.readline())
return num
def call(num):
res = ''
for i in range(1, num+1):
x = i
if x % 3 == 0 or x % 10 == 3:
res += ' ' + str(i)
continue
while x:
if x % 10 == 3:
res += ' ' + str(i)
break
x //= 10
return res
def main():
print(call(int_fetcher()))
if __name__ == '__main__':
main() | 0 | null | 16,976,409,907,548 | 170 | 52 |
class Dice():
def __init__(self, a, b, c, d, e, f):
"""面の数字とindexを一致させるために0を挿入"""
self.s = [0, a, b, c, d, e, f]
def rotate(self, dir):
if dir == "N":
self.s[0] = self.s[1] #s[0]に一時的にs[1]を保持
self.s[1] = self.s[2]
self.s[2] = self.s[6]
self.s[6] = self.s[5]
self.s[5] = self.s[0]
return
elif dir == "W":
self.s[0] = self.s[1]
self.s[1] = self.s[3]
self.s[3] = self.s[6]
self.s[6] = self.s[4]
self.s[4] = self.s[0]
return
elif dir == "S":
self.s[0] = self.s[1]
self.s[1] = self.s[5]
self.s[5] = self.s[6]
self.s[6] = self.s[2]
self.s[2] = self.s[0]
return
elif dir == "E":
self.s[0] = self.s[1]
self.s[1] = self.s[4]
self.s[4] = self.s[6]
self.s[6] = self.s[3]
self.s[3] = self.s[0]
return
elif dir == "R":
self.s[0] = self.s[2]
self.s[2] = self.s[3]
self.s[3] = self.s[5]
self.s[5] = self.s[4]
self.s[4] = self.s[0]
return
elif dir == "L":
self.s[0] = self.s[2]
self.s[2] = self.s[4]
self.s[4] = self.s[5]
self.s[5] = self.s[3]
self.s[3] = self.s[0]
return
else:
return
dice = Dice(*list(map(int, input().split())))
for _ in range(int(input())):
t, s = map(int, input().split())
while dice.s[1] != t:
dice.rotate("S")
if dice.s[1] != t:
dice.rotate("E")
while dice.s[2] != s:
dice.rotate("R")
print(dice.s[3])
| def lotate(dic, dire):
if dire == 'N':
x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
elif dire == 'S':
x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
elif dire == 'W':
x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
elif dire == 'E':
x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
return dic
a,b,c,d,e,f = map(int, input().split())
n = int(input())
for _ in range(n):
dic = {'up': a, 'front': b, 'right': c, 'left': d, 'back': e, 'bottom': f}
x, y = map(int, input().split())
s = 'EEENEEENEEESEEESEEENEEEN'
for i in s:
if dic['up'] == x and dic['front'] == y:
print(dic['right'])
break
dic = lotate(dic, i)
| 1 | 250,325,370,112 | null | 34 | 34 |
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
if n<=3:
print(max(a))
exit()
lacc = [0]*n
racc = [0]*n
lacc[0] = a[0]
lacc[1] = a[1]
racc[n-1] = a[n-1]
racc[n-2] = a[n-2]
for i in range(2,n):
if i%2==0:
lacc[i] = lacc[i-2]+a[i]
else:
lacc[i] = max(lacc[i-3],lacc[i-2])+a[i]
if n%2==0:
print(max(lacc[n-2],lacc[n-1]))
exit()
for i in range(n-3,-1,-1):
if (n-1-i)%2==0:
racc[i] = racc[i+2]+a[i]
else:
racc[i] = max(racc[i+3],racc[i+2])+a[i]
mx = max(racc[2],lacc[n-3])
for i in range(1,n-2):
if i%2==0:
mx = max(mx, max(lacc[i-2],lacc[i-1])+racc[i+2])
else:
mx = max(mx, max(racc[i+2],racc[i+3])+lacc[i-1])
print(mx)
| #!/usr/bin/env python3
# coding: utf-8
import collections
def debug(arg):
if __debug__:
pass
else:
import sys
print(arg, file=sys.stderr)
def main():
pass
N, *A = map(int, open(0).read().split())
a = dict(enumerate(A, 1))
dp = collections.defaultdict(lambda: -float("inf"))
dp[0, 0] = 0
dp[1, 0] = 0
dp[1, 1] = a[1]
for i in range(2, N + 1):
jj = range(max(i // 2 - 1, 1), (i + 1) // 2 + 1)
for j in jj:
x = dp[i - 2, j - 1] + a[i]
y = dp[i - 1, j]
dp[i, j] = max(x, y)
print(dp[N, N // 2])
if __name__ == "__main__":
main() | 1 | 37,493,845,941,090 | null | 177 | 177 |
def main():
N,M,K=map(int,input().split())
MOD=998244353
E=0
n_=1
for i in range(1,N):
n_=(n_*i)%MOD
nr_ = 1
nr_array=[]
for i in range(1,N-1):
nr_ = (nr_ * i) % MOD
nr_array.append(nr_)
m=1
Mk_array=[1]
for i in range(1,N):
m=(m*(M-1))%MOD
Mk_array.append(m)
r_=1
for i in range(0,K+1):
if i!=0 and i!=N-1:
r_ = (r_ * i) % MOD
nr_=nr_array.pop()
power_r=pow(r_,MOD-2,MOD)
power_nr=pow(nr_,MOD-2,MOD)
Mk=Mk_array.pop()
if i!=0 and i!=N-1:
E+=(n_*power_r*power_nr*Mk)%MOD
else:
E+=Mk%MOD
res=(M*E)%MOD
print(res)
if __name__=="__main__":
main()
| import math
def rot60_on_complex_plane(start: complex, end: complex) -> complex:
v = end - start
arg = 1 / 2 + complex(0, (math.sqrt(3) / 2))
return v * arg + start
def print_real_coordinate(z: complex) -> None:
x = z.real
y = z.imag
print(f"{x:.8f} {y:.8f}")
def create_koch_points(p1: complex, p2: complex, n: int) -> None:
if n == 0:
return
# Get s, t, u coordinates on the complex plane.
s = (p2 - p1) * (1 / 3) + p1
t = (p2 - p1) * (2 / 3) + p1
u = rot60_on_complex_plane(s, t)
# Call the function recursively by the case of n == 0.
create_koch_points(p1, s, n - 1)
print_real_coordinate(s)
create_koch_points(s, u, n - 1)
print_real_coordinate(u)
create_koch_points(u, t, n - 1)
print_real_coordinate(t)
create_koch_points(t, p2, n - 1)
if __name__ == "__main__":
n = int(input())
start_point = (0 + 0j)
end_point = (100 + 0j)
print_real_coordinate(start_point)
create_koch_points(start_point, end_point, n)
print_real_coordinate(end_point)
| 0 | null | 11,704,037,846,082 | 151 | 27 |
from collections import deque
N,M=map(int,input().strip().split())
l=[]
dp=[[] for _ in range(N)]
for _ in range(M):
a,b=map(int,input().strip().split())
l.append((a,b))
dp[a-1].append(b)
dp[b-1].append(a)
d=deque([1])
visited=[0 for _ in range(N)]
visited[0]=1
cnt=1
while d:
tmp=d.popleft()
for e in dp[tmp-1]:
if visited[e-1]==0:
visited[e-1]=tmp
cnt+=1
d.append(e)
if cnt!=len(visited):
print("No")
else:
print("Yes")
for n in range(1,N):
print(visited[n]) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
N, K, S = MAP()
if S == 10**9:
tmp = 1
else:
tmp = 10**9
ans = [S]*K + [tmp]*(N-K)
print(*ans) | 0 | null | 56,062,469,960,330 | 145 | 238 |
import sys
input = sys.stdin.readline
def main():
N, M = map(int, input().split())
P = [0] * M
S = [""] * M
for i in range(M):
PS = input().split()
P[i], S[i] = int(PS[0]), PS[1]
AC = [False] * (N + 1)
WA = [0] * (N + 1)
n_AC = 0
n_WA = 0
for p, s in zip(P, S):
if AC[p]:
continue
if s == "AC":
n_AC += 1
AC[p] = True
n_WA += WA[p]
else:
WA[p] += 1
print(n_AC, n_WA)
if __name__ == "__main__":
main()
| n,m=map(int,input().split())
l=[0]*(n+1)
miss=[0]*(n+1)
for _ in range(m):
p,s=input().split()
p=int(p)
if l[p]==0:
if s=='AC':
l[p]+=1
else:
miss[p]+=1
for i in range(1,n+1):
if l[i]==0 and miss[i]!=0:
miss[i]=0
a=l.count(1)
b=sum(miss)
print(a,b) | 1 | 93,370,997,695,470 | null | 240 | 240 |
S = input()
T = input()
ans = 0
for i,y in zip(S,T):
if i != y:
ans += 1
print(ans) | s = input()
t = input()
l = len(s)
x = 0
for i in range(l):
if s[i] != t[i]:
x += 1
print(x) | 1 | 10,520,870,497,592 | null | 116 | 116 |
n,a,b = map(int,input().split())
mod = 10**9 + 7
all = pow(2, n, mod)
if all == 0:
all = 10**9 + 6
else:
all -= 1
a = min(n-a,a)
b = min(n-b,b)
a_fact = 1
a_inv = 1
for i in range(1,a+1):
a_fact *= (n-i+1)%mod
a_inv *= pow(i,mod-2,mod)
a_fact %= mod
a_inv %= mod
nca = a_fact * a_inv
nca %= mod
b_fact = 1
b_inv = 1
for i in range(1,b+1):
b_fact *= (n-i+1)%mod
b_inv *= pow(i,mod-2,mod)
b_fact %= mod
b_inv %= mod
ncb = b_fact * b_inv
ncb %= mod
ans = all - nca - ncb
while ans < 0:
ans += mod
if ans >= mod:
ans -= mod
print(ans) | import sys
import math
import bisect
import heapq
from collections import Counter
def input():
return sys.stdin.readline().rstrip()
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
AS = [0]
it = 0
for i in range(0, N):
it += A[i]
it %= K
sj = (it - i - 1) % K
AS.append(sj)
# 最初だけ作る
C = dict()
C[0] = 1
current = 0
for j in range(1, N + 1):
if j > K-1:
C[AS[j - K]] -= 1
if AS[j] in C:
current += C[AS[j]]
C[AS[j]] += 1
else:
C[AS[j]] = 1
print(current)
if __name__ == "__main__":
main()
| 0 | null | 101,431,916,715,752 | 214 | 273 |
import sys
sys.setrecursionlimit(10**5)
n, u, v = map(int, input().split())
u -= 1
v -= 1
m_mat = [[] for i in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
m_mat[a].append(b)
m_mat[b].append(a)
u_map = [-1]*n
v_map = [-1]*n
u_map[u] = 0
v_map[v] = 0
def dfs(current, depth, ma):
for nex in m_mat[current]:
if ma[nex] > -1:
continue
ma[nex] = depth
dfs(nex, depth+1, ma)
dfs(u, 1, u_map)
dfs(v, 1, v_map)
ans = -1
for i in range(n):
if u_map[i] < v_map[i] and v_map[i] > ans:
ans = v_map[i]
print(ans-1)
| def dfs(c,lst):
n=len(lst)
ans=[0]*n
stack = [c-1]
check = [0]*n #チェック済みリスト
while stack != [] :
d=stack.pop()
if check[d]==0:
check[d]=1
for i in lst[d]:
if check[i]==0:
stack.append(i)
ans[i]=ans[d]+1
return(ans)
import sys
input = sys.stdin.readline
N,u,v=map(int,input().split())
ki=[[] for f in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
ki[a-1].append(b-1)
ki[b-1].append(a-1)
U=dfs(u,ki)
V=dfs(v,ki)
ans=0
for i in range(N):
if V[i]>U[i]:
ans=max(ans,V[i]-1)
print(ans)
| 1 | 117,030,141,197,382 | null | 259 | 259 |
tmp = input()
line = input().split(" ")
for i in range(len(line)):
line[i] = int(line[i])
line.sort()
count = 0
for i in range(0, len(line) - 2):
for j in range(1, len(line) - 1):
if i > j or i == j:
continue
for k in range(2, len(line)):
if j > k or j == k:
continue
if int(line[i]) != int(line[j]) and int(line[j]) != int(line[k]):
if int(line[i]) + int(line[j]) > int(line[k]):
count += 1
print(count) | import sys
sys.setrecursionlimit(300000)
from itertools import combinations
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N = I()
L = LMI()
ans = 0
for a, b, c in combinations(L, 3):
if a == b or b == c or c == a:
continue
if a + b > c and b + c > a and c + a > b:
ans += 1
print(ans)
| 1 | 5,053,753,806,848 | null | 91 | 91 |
import numpy as np
D = int(input())
C = np.array(list(map(int, input().split())))
S = []
for i in range(D):
s = list(map(int, input().split()))
S.append(s)
S = np.array(S)
T = [int(input()) for _ in range(D)]
last = np.zeros(26, dtype=np.int64)
def decrease(d, last):
res = np.sum(C * (d - last))
# print(d, res, C * (d - last))
return res
manzoku = 0
# kaisai = dict()
# print(S, T, C)
for day, t in enumerate(T):
t -= 1
manzoku += S[day, t] # d 日目にタイプi のコンテストを開催した場合、満足度が S[d,i]増加することが予め分かっています。
last[t] = day + 1
manzoku -= decrease(day + 1, last)
print(manzoku)
| d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) - 1 for _ in range(d)]
def scoring(d, c, s, t):
v = []
memo = [0 for _ in range(26)]
for i in range(d):
if i == 0:
score = 0
else:
score = v[-1]
score += s[i][t[i]]
memo[t[i]] = i + 1
for j in range(26):
score -= c[j] * (i+1 - memo[j])
v.append(score)
return v
v = scoring(d, c, s, t)
print(*v, sep='\n') | 1 | 9,894,659,689,462 | null | 114 | 114 |
n = int(input())
lis = list(map(int, input().split()))
m = 0
for a in lis:
m = m ^ a
for a in lis:
print(m ^ a, end=" ")
| import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N = I()
a = LI()
b = 0
for i in range(N):
b ^= a[i]
print(*[b^a[i] for i in range(N)])
| 1 | 12,454,947,524,588 | null | 123 | 123 |
import sys
input()
numbers = map(int, input().split())
evens = [number for number in numbers if number % 2 == 0]
if len(evens) == 0:
print('APPROVED')
sys.exit()
for even in evens:
if even % 3 != 0 and even % 5 != 0:
print('DENIED')
sys.exit()
print('APPROVED')
| mod = 10 ** 9 + 7
N = int(input())
result = 0
ten = pow(10, N, mod)
nine = pow(9, N, mod)
eight = pow(8, N, mod)
result = (ten - 2 * nine + eight) % mod
print(result) | 0 | null | 36,219,952,805,230 | 217 | 78 |
x,y=map(int,input().split())
for i in range(0,x+1):
if(2*i+4*(x-i)==y):
print("Yes")
exit()
print("No") | x,y = map(int,input().split())
for i in range(x+1):
if 2*i+4*(x-i) == y:
print('Yes')
exit()
print('No')
| 1 | 13,723,584,749,270 | null | 127 | 127 |
nm = input().split()
n = int(nm[0])
m = int(nm[1])
ans = 0
n1 = n*(n-1)/2
n2 = m*(m-1)/2
ans = int(n1 + n2)
print(ans) | import math
def count(n, r):
return math.factorial(n) // math.factorial(n - r)
def main():
N, M = map(int, input().split())
if (N == 0 and M == 0) or (N == 1 and M == 1):
ans = 0
elif N == 0 or N == 1:
y = count(M, 2)
ans = y
elif M == 0 or M == 1:
x = count(N, 2)
ans = x
else:
x = count(N, 2)
y = count(M, 2)
ans = x + y
print(int(ans/2))
main()
| 1 | 45,446,224,909,096 | null | 189 | 189 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list(map(int, input().split()))
s = set()
def check(i, m):
if i == n:
s.add(m)
return
check(i+1, m+A[i])
check(i+1, m)
check(0,0)
for i in B:
if i in s:
print('yes')
else:
print('no')
| n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
memory = [[-1 for i in range(max(m)+1)]for j in range(n)]
def f(i, m):
if m == 0:
return 1
elif i >= n:
return 0
elif memory[i][m] != -1:
return memory[i][m]
elif m - a[i] >= 0:
res0 = f(i+1, m)
res1 = f(i+1, m-a[i])
if res0 or res1:
memory[i][m] = 1
return 1
else:
memory[i][m] = 0
return 0
else:
res = f(i+1, m)
memory[i][m] = res
return res
for k in m:
print('yes' if f(0, k) else 'no')
| 1 | 103,384,231,100 | null | 25 | 25 |
h1,m1,h2,m2,k =(int(x) for x in input().split())
hrtom= (h2-h1)
if (m2-m1 < 0) and (h2-h1 >=0) :
min = (h2-h1)*60 + (m2-m1) - k
print(min)
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
min = (h2-h1)*60 + (m2-m1) - k
print(min)
else:
print('0') | h1, m1, h2, m2, k = map(int, input().split())
h = h2 - h1
m = m2 - m1
m += 60 * h
print(m - k)
| 1 | 18,000,695,702,858 | null | 139 | 139 |
while True:
a = raw_input()
if a == '-':
break
m = input()
b = [input() for _ in range(m)]
for i in b:
a = a[i:]+a[0:i]
print a | while True:
d = input()
if d == '-':
break
h = int(input())
rotate = 0
for i in range(h):
rotate += int(input())
move = rotate % len(d)
print(d[move:] + d[:move])
| 1 | 1,930,911,918,870 | null | 66 | 66 |
n = int(input())
a = list(map(int,input().split()))
if a == [1]*n:
print("pairwise coprime")
quit()
m = max(a)
l = [-1]*(m+3)
for i in range(2,m+1):
if l[i] != -1:
continue
l[i] = i
j = 2
while i*j <= m:
if l[i*j] == -1:
l[i*j] = i
j += 1
def fastfact(i,lst):
if l[i] == -1:
return lst
while i > 1:
lst.append(l[i])
i //= l[i]
return lst
check = [0]*(m+1)
for i in range(n):
if a[i] == 1:
continue
s = set(fastfact(a[i],[]))
for j in s:
check[j] += 1
M = max(check)
if M == 1:
print("pairwise coprime")
elif M == n:
print("not coprime")
else:
print("setwise coprime") | from math import gcd
def setwise_coprime_check_fun(A_list, N):
gcd_all = A_list[0]
for i in range(N - 1):
gcd_all = gcd(gcd_all, A_list[i + 1])
if gcd_all == 1:
break
return gcd_all
def preprocess_fun(A_max):
p_flg = [True] * (A_max + 1)
D = [0] * (A_max + 1)
p_flg[0] = False
p_flg[1] = False
for i in range(2, A_max + 1, 1):
if p_flg[i]:
for j in range(i, A_max + 1, i):
p_flg[j] = False
D[j] = i
return D
def pairwise_coprime_check(A_list, D, A_max):
p_count = [0] * (A_max + 1)
for A in A_list:
temp = A
d = 0
while temp != 1:
if p_count[D[temp]] == 1 and d != D[temp]:
return 0
p_count[D[temp]] = 1
d = D[temp]
temp = temp // D[temp]
return 1
## 標準入力
N = int(input())
A_list = list(map(int, input().split(" ")))
# 整数の最大値を取得
A_max = max(A_list)
# 本体
if(setwise_coprime_check_fun(A_list, N) != 1):
print("not coprime")
else:
D = preprocess_fun(A_max)
if pairwise_coprime_check(A_list, D, A_max) == 1:
print("pairwise coprime")
else:
print("setwise coprime") | 1 | 4,111,784,786,760 | null | 85 | 85 |
h1, m1, h2, m2, k = map(int, input().split(' '))
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2
print(t2 - t1 - k) | a, b, c = tuple([int(x) for x in input().split()])
if a < b and b < c:
print("Yes")
else:
print("No") | 0 | null | 9,190,133,556,520 | 139 | 39 |
def main():
N = int(input())
d = dict()
for i in range(1, N+1):
u = int(str(i)[0])
v = int(str(i)[-1])
d[(u, v)] = d.get((u, v), 0) + 1
ans = 0
for u, v in d:
if (v, u) in d:
ans += d[(u, v)] * d[(v, u)]
return ans
if __name__ == '__main__':
print(main())
| from collections import defaultdict
N = int(input())
d = defaultdict(int)
for i in range(1, N+1):
s = str(i)
top = int(s[0])
end = int(s[-1])
d[(top, end)] += 1
counter = 0
for i in range(1, N+1):
s = str(i)
top = int(s[0])
end = int(s[-1])
if (end, top) in d:
counter += d[(end, top)]
print(counter) | 1 | 86,686,843,153,878 | null | 234 | 234 |
n, k = map(int, input().split())
cnt = 0
while n >= 1:
n = n//k
cnt +=1
print(cnt) | def main():
n, k = map(int, input().split())
a = 1
b = 0
while True:
a *= k
if a > n:
break
b += 1
ans = b + 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 64,169,494,364,928 | null | 212 | 212 |
import math
h = int(input())
w = int(input())
n = int(input())
ans = math.ceil(n/max(h,w))
print(ans) | h = int(input())
w = int(input())
n = int(input())
ans = n // max(h,w) if n % max(h,w) == 0 else n // max(h,w) + 1
print(ans) | 1 | 88,415,818,012,822 | null | 236 | 236 |
# coding: utf-8
# Your code here!
# coding: utf-8
# 自分の得意な言語で
# Let's チャレンジ!!
S=input()
if "7" in S:
print("Yes")
else:
print("No") | class Dice:
dice = {'N':2, 'E':4, 'S':5, 'W':3}
currTop = 1
def top(self):
return self.currTop
def rot(self, direction):
newTop = self.dice[direction]
currTop = self.currTop
self.currTop = newTop
if direction == 'N':
self.dice['N'] = 7 - currTop
self.dice['S'] = currTop
elif direction == 'S':
self.dice['N'] = currTop
self.dice['S'] = 7 - currTop
elif direction == 'E':
self.dice['E'] = 7 - currTop
self.dice['W'] = currTop
elif direction == 'W':
self.dice['E'] = currTop
self.dice['W'] = 7 - currTop
def yaw(self, direction):
newDice = {}
if direction == 'E':
newDice['N'] = self.dice['E']
newDice['E'] = self.dice['S']
newDice['S'] = self.dice['W']
newDice['W'] = self.dice['N']
if direction == 'W':
newDice['N'] = self.dice['W']
newDice['E'] = self.dice['N']
newDice['S'] = self.dice['E']
newDice['W'] = self.dice['S']
self.dice = newDice
faces = list(map(int, input().split()))
q = int(input())
d = Dice()
for i in range(q):
top, front = list(map(int, input().split()))
topIdx = faces.index(top) + 1
frontIdx = faces.index(front) + 1
if d.top() != topIdx:
# search topIdx and rotate to make topIdx top.
key = [k for k,v in d.dice.items() if topIdx == v]
if len(key) == 0:
d.rot('N')
key = [k for k,v in d.dice.items() if topIdx == v]
d.rot(key[0])
# rotate(yaw) to make frontIdx front.
while True:
if d.dice['N'] == frontIdx:
break
d.yaw('E')
print(faces[d.dice['W']-1]) | 0 | null | 17,238,974,303,838 | 172 | 34 |
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
for i, ai in enumerate(a):
cnt = 0
for j, bj in enumerate(b):
cnt += ai[j] * bj
print(cnt)
| n=int(input())
a=list(map(int,input().split()))
thing={}
ans=0
for i in range(n):
if i-a[i] in thing:
ans+=thing[i-a[i]]
if i+a[i] in thing:
thing[i+a[i]]+=1
else:
thing[i+a[i]]=1
print(ans) | 0 | null | 13,524,210,988,600 | 56 | 157 |
N = int(input())
ptn = [[0 for _ in range(10)] for __ in range(10)]
for num in range(1, N+1):
str_num = str(num)
if str_num[-1] != 0:
ptn[int(str_num[0])][int(str_num[-1])] += 1
answer = 0
for i in range(10):
for j in range(i, 10):
if i == j:
answer += ptn[i][j]**2
else:
answer += ptn[i][j]*ptn[j][i]*2
print(answer) | # !/usr/bin/python3
"""
https://atcoder.jp/contests/abc152/tasks/abc152_d
Low Elements.
"""
def solve(n):
res = 0
for num in range(n+1):
start = int(str(num)[0])
end = int(str(num)[-1])
for i in range(1, 10):
for j in range(1, 10):
if i == start and j == end: dp[i][j] += 1
for i in range(1, 10):
for j in range(1, 10):
res += dp[i][j]*dp[j][i]
# for each in dp: print(each)
return res
if __name__ == "__main__":
n = int(input())
dp = [[0 for _ in range(10)] for _ in range(10)]
print(solve(n))
| 1 | 86,757,340,977,020 | null | 234 | 234 |
n, k = [int(z) for z in input().strip().split()]
p = [int(z) - 1 for z in input().strip().split()]
c = [int(z) for z in input().strip().split()]
visited = [False for _ in range(n)]
cycle = []
for start in range(n):
if visited[start]:
continue
now = start
route = []
while not visited[now]:
visited[now] = True
route.append(now)
now = p[now]
cycle.append(route)
min_c = min(c)
max_value = min_c
for route in cycle:
full_value = sum([c[i] for i in route])
double_route = route + route
v = [c[i] for i in double_route]
max_sum_step = []
for step in range(1, len(route)):
s = sum(v[:step])
max_sum = max(s, min_c)
for idx in range(step, step + len(route) - 1):
s += v[idx]
if idx >= step:
s -= v[idx - step]
max_sum = max(s, max_sum)
max_sum_step.append(max_sum)
addition = k % len(route)
if full_value > 0:
addition_value = 0 if addition == 0 else max(max_sum_step[:addition])
value1 = int(k / len(route)) * full_value + addition_value
value2 = (int(k / len(route)) - 1) * full_value + max(max_sum_step)
value = max(value1, value2)
else:
value = max(max_sum_step[:min(k, len(max_sum_step))])
max_value = max(max_value, value)
print(max_value) | #!/usr/bin/env python3
def main():
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
res = [False for _ in range(N)]
for _ in range(K):
_ = int(input())
A = [int(x) for x in input().split()]
for i in A:
res[i - 1] = True
print(res.count(False))
if __name__ == '__main__':
main()
| 0 | null | 14,889,769,979,008 | 93 | 154 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,K,S = MI()
if S == 10**9:
ANS = [10**9]*K + [1]*(N-K)
else:
ANS = [S]*K + [10**9]*(N-K)
print(*ANS)
| import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int
nl = lambda: list(map(int, readline().split())) # input multiple int to list
n, k, s = nm()
ans_h = [str(s) for _ in range(k)]
if s==10**9 :
ans_t = ['1' for _ in range(n-k)]
else:
ans_t = [str(s+1) for _ in range(n-k)]
print(' '.join(ans_h + ans_t)) | 1 | 90,677,793,147,732 | null | 238 | 238 |
a,b=map(int,raw_input().split())
print a/b,a%b,'%.8f'%(a/(b+0.0)) | def insertion_sort(numbers, n, g):
"""insertion sort method
(only elements whose distance is larger than g are the target)
Args:
numbers: list of elements to be sorted
n: len(numbers)
g: distance
Returns:
partially sorted list, counter
"""
counter = 0
copied_instance = []
for data in numbers:
copied_instance.append(data)
for i in range(g, n):
target = copied_instance[i]
j = i - g
while j >= 0 and target < copied_instance[j]:
copied_instance[j + g] = copied_instance[j]
j -= g
counter += 1
copied_instance[j + g] = target
return copied_instance, counter
def shell_sort(numbers, n, key=lambda x: x):
"""shell sort method
Args:
numbers: list of elements to be sorted
n: len(numbers)
Returns:
sorted numbers, used G, swapped number
"""
counter = 0
copied_instance = []
for data in numbers:
copied_instance.append(data)
G = [1]
g = 4
while g < len(numbers):
G.append(g)
g = g * 3 + 1
G = G[::-1]
for g in G:
copied_instance, num = insertion_sort(copied_instance, n, g)
counter += num
return copied_instance, G, counter
length = int(raw_input())
numbers = []
counter = 0
while counter < length:
numbers.append(int(raw_input()))
counter += 1
numbers, G, counter = shell_sort(numbers, length)
print(len(G))
print(" ".join([str(x) for x in G]))
print(counter)
for n in numbers:
print(str(n)) | 0 | null | 322,133,846,940 | 45 | 17 |
n,d = map(int,input().split())
su = 0
for i in range(n):
x,y = map(int,input().split())
#print("i=",i,"x,y=",x,y)
if d**2 >= x**2 +y**2:
su +=1
else:
continue
print(su) | N,D=map(int, input().split())
A = 0
for i in range(N):
X,Y=map(int, input().split())
if (D*D) >= (X*X)+(Y*Y):
A +=1
print(A) | 1 | 5,942,793,677,900 | null | 96 | 96 |
import sys
h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
num_in_h[t_h] += 1
num_in_w[t_w] += 1
targets.add((t_h, t_w))
max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1
flag = False
for i in max_h_set:
for j in max_w_set:
if (i, j) not in targets:
flag = True
break
if flag: break
print(ans+1 if flag else ans)
| def divide(a, b):
if a < b:
return divide(b, a)
if b == 0:
return a
return divide(b, a%b)
nums=list(map(int,input().split()))
ans = divide(nums[0], nums[1])
print(ans)
| 0 | null | 2,356,039,086,868 | 89 | 11 |
n,b,r = map(int, input().split())
t = n % (b+r)
q = n // (b+r) * b
if t > b:
t = b
print(q+t)
| from collections import defaultdict
N, M = map(int, input().split())
heights = list(map(int, input().split()))
d = defaultdict(list)
for i in range(M):
A, B = map(int, input().split())
d[A].append(B)
d[B].append(A)
ans_cnt = 0
for i in range(1, N + 1):
if d[i] == []:
ans_cnt += 1
else:
my_height = heights[i - 1]
flag = True
for j in d[i]:
if heights[j - 1] >= my_height:
flag = False
break
if flag:
ans_cnt += 1
print(ans_cnt)
| 0 | null | 40,190,608,249,470 | 202 | 155 |
k=int(input())
a,b = map(int,input().split())
while b>=a:
if b%k==0:
print('OK')
break
b-=1
if b<a:
print('NG') | import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
num = [i for i in range(1,n+1)]
lst = list(itertools.permutations(num))
pos_p = 0
pos_q = 0
for i in range(len(lst)):
temp = list(lst[i])
if temp == p:
pos_p = i
if temp == q:
pos_q = i
print(abs(pos_p - pos_q))
| 0 | null | 63,557,704,750,852 | 158 | 246 |
a,b=(int(x) for x in input().split())
print(a*b) | list = input().split(" ")
a = int(list[0])
b = int(list[1])
print(a * b) | 1 | 15,876,784,136,070 | null | 133 | 133 |
n = int(input())
nums = [0]*n
a = int(n**0.5)+1
for x in range(1,a):
for y in range(1,a):
if x**2 + y**2 + x*y > n: break
for z in range(1,a):
s = x**2 + y**2 + z**2 + x*y + y*z + z*x
if s <= n: nums[s-1] += 1
print(*nums, sep="\n") | import math
N = int(input())
ans = [0] * N
n = int(math.sqrt(N))
for x in range(1, n+1):
for y in range(1, x+1):
for z in range(1, y+1):
i = x**2 + y**2 + z**2 + x*y + y*z + z*x
if i <= N:
if x == y == z:
ans[i-1] += 1
elif x == y or y == z:
ans[i-1] += 3
else:
ans[i-1] += 6
for j in range(N):
print(ans[j]) | 1 | 7,988,922,692,530 | null | 106 | 106 |
while True :
x,op,y = input().split()
x=int(x)
y=int(y)
if op == '?' :
break
elif op == '+' :
print(x+y)
elif op == '-' :
print(x-y)
elif op == '*' :
print(x*y)
else :
print(x//y)
| n = int(input())
ikeru = [[] for _ in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
ikeru[a-1].append((b-1, i))
settansaku = set([])
setmada = {0}
listmada = [(0, None)] #left: Vertex, right: Color
kouho = 1
num = [0 for _ in range(n-1)]
while kouho != 0:
for i, cnt in listmada[:]:
colors = {cnt}
settansaku.add(i)
setmada.remove(i)
listmada.remove((i, cnt))
kouho -= 1
c = 0
for k, j in ikeru[i]:
if not k in setmada:
if not k in settansaku:
setmada.add(k)
while True:
if c not in colors:
listmada.append((k, c))
colors.add(c)
num[j] = c
break
c += 1
kouho += 1
print(max(num)+1)
print("\n".join([str(i+1) for i in num])) | 0 | null | 68,285,376,275,250 | 47 | 272 |
import sys
for line in sys.stdin:
n,x = map(int,line.split())
if n==0 and x==0:
break
_range = list(range(1,n+1))
conb = []
for i in _range[::-1]:
d = x - i
if i - 1 <= 0:
continue
for j in _range[:i-1][::-1]:
d2 = d - j
if j - 1 <= 0:
continue
for k in _range[:j-1][::-1]:
if d2 - k == 0:
conb.append((i,j,k))
print(len(conb)) | n = int(input())
s = [input() for _ in range(n)]
print(len(list(set(s)))) | 0 | null | 15,803,747,125,500 | 58 | 165 |
def main():
H = int(input())
W = int(input())
N = int(input())
print((N-1)//max(H,W) + 1)
if __name__ == '__main__':
main() | H = int(input())
W = int(input())
N = int(input())
ans = N // max(H, W)
if N % max(H, W) > 0:
ans += 1
print(ans) | 1 | 88,543,769,765,088 | null | 236 | 236 |
(a,b) = map(int,raw_input().split())
print str(a*b)+ ' ' + str((a+b)*2) | w,h = map(int, raw_input().split())
print(str(w*h) + ' ' + str((w+h)*2))
| 1 | 306,437,151,068 | null | 36 | 36 |
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
x=sum(a)%mod
y=0
for i in range(n):
y+=a[i]**2
y%=mod
z=pow(2,mod-2,mod)
print(((x**2-y)*z)%mod) | a, b = map(int, input().split(" "))
if 0 < a < 10 and 0 < b < 10:
print(a * b)
else:
print(-1) | 0 | null | 81,179,034,118,170 | 83 | 286 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
#階乗#
lim = 10**5 #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
if n < r:
return 0
else:
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
N, K = MAP()
A = LIST()
A.sort()
A_cnt = Counter(A)
P = list(A_cnt.keys())
p = list(A_cnt.values())
#print("P={}".format(P))
#print("p={}".format(p))
p_acc = list(accumulate(p))
p_acc_rev = list(accumulate(p[::-1]))
#print("p_acc={}".format(p_acc))
#print("p_acc_rev={}".format(p_acc_rev))
n = len(p)
T = [[0]*4 for _ in range(n)]
for i in range(n):
T[i][0] = p_acc[i]
for i in range(1, n):
T[i][1] = p_acc[i-1]
for i in range(n):
T[(-i-1)][3] = p_acc_rev[i]
for i in range(1, n):
T[(-i-1)][2] = p_acc_rev[i-1]
#for i in range(n):
# print(T[i])
t = [0]*n
for idx, x in enumerate(T):
t[idx] = (C(x[0], K) - C(x[1], K) + C(x[2], K) - C(x[3], K))%mod
ans = 0
for i in range(n):
ans = (ans + P[i]*t[i]%mod)%mod
print(ans)
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()
if T1*A1+T2*A2 == T1*B1+T2*B2:
print("infinity")
exit()
if (A1 < B1 and A2 < B2) or (B1 < A1 and B2 < A2):
print(0)
exit()
if A1 > B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1*T1+A2*T2 < B1*T1+B2*T2:
print(0)
exit()
F = A1*T1-B1*T1
L = A2*T2-B2*T2
S, T = divmod(-F, F+L)
if T == 0:
print(2*S)
else:
print(2*S+1)
| 0 | null | 113,648,505,766,400 | 242 | 269 |
from math import sqrt, ceil
def divisors(n):
out = []
nn = ceil(sqrt(n))
for i in range(1, nn):
if n % i == 0:
out.append(i)
out.append(n//i)
if nn ** 2 == n:
out.append(nn)
out.sort()
return out
n = int(input())
a = len(divisors(n-1)[1:])
d = divisors(n)
for dd in d[1:]:
nn = n
while nn % dd == 0:
nn = nn // dd
if nn % dd == 1:
a += 1
print(a)
| h,w,n = int(input()),int(input()),int(input())
ans = 0
s = 0
while s < n:
s += max(h,w)
ans += 1
print(ans) | 0 | null | 65,230,285,848,182 | 183 | 236 |
# coding: utf-8
def solve(*args: str) -> str:
n = int(args[0])
A = list(map(int, args[1].split()))
rem = sum(A)
cur = 1
ret = 0
for a in A:
cur = min(rem, cur)
rem -= a
ret += cur
cur = 2*(cur-a)
if cur < 0:
ret = -1
break
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
|
D = int(input())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for _ in range(D)]
last_open = [0] * 26
res = 0
res_list = []
for i in range(D):
t = int(input())
res += s_list[i][t-1]
bad = 0
last_open[t-1] = i+1
for ci in range(26):
bad += c_list[ci]*(i+1 - last_open[ci])
res -= bad
print(res)
res_list.append(res)
| 0 | null | 14,340,196,623,422 | 141 | 114 |
import sys
write=sys.stdout.write
while True:
h,w=map(int,raw_input().split())
if h==w==0: break
for i in xrange(h):
l=[('#' if i%2==j%2==0 else ('.' if (i%2==1 and j%2==0) or (i%2==0 and j%2==1) else '#')) for j in xrange(w)]
for i in l:
write(i)
print ""
print "" | def print_it(l, n):
print(''.join([l[x % 2] for x in range(n)]))
matrix = []
while True:
values = input()
if '0 0' == values:
break
matrix.append([int(x) for x in values.split()])
sc = ['#', '.']
cs = ['.', '#']
for height, width in matrix:
for i in range(height):
if 0 == i % 2:
print_it(sc, width)
else:
print_it(cs, width)
print() | 1 | 884,759,394,232 | null | 51 | 51 |
n = int(input())
dp = [1] * (n+1)
for j in range(n-1):
dp[j+2] = dp[j+1] + dp[j]
print(dp[n])
| N = int(input())
memolist = [-1]*(N+1)
def fib(x):
if memolist[x] == -1:
if x == 0 or x == 1:
memolist[x] = 1
else:
memolist[x] = fib(x - 1) + fib(x - 2)
return memolist[x]
print(fib(N))
| 1 | 2,092,917,820 | null | 7 | 7 |
n=int(input())
l0=[[] for _ in range(n)]
l1=[[] for _ in range(n)]
for i in range(n):
a=int(input())
for j in range(a):
x,y=map(int,input().split())
if y==0:
l0[i].append(x)
else:
l1[i].append(x)
ans=0
for i in range(2**n):
s0=set()
s1=set()
num=0
num1=[]
num0=[]
for j in range(n):
if (i>>j) & 1:
num1.append(j+1)
for k in range(len(l0[j])):
s0.add(l0[j][k])
for k in range(len(l1[j])):
s1.add(l1[j][k])
else:
num0.append(j+1)
for j in range(len(s1)):
if s1.pop() in num0:
num=1
break
if num==0:
for j in range(len(s0)):
if s0.pop() in num1:
num=1
break
if num==0:
ans=max(ans,len(num1))
print(ans)
| n = int(input())
ans = [0] * 10010
def get_ans(n):
cnt = 0
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
k = x**2 + y**2 + z**2 + x*y + y*z + z*x
if(k <= 10000):
ans[k] += 1
return ans
ans = get_ans(n)
for i in range(1, n+1):
print(ans[i]) | 0 | null | 64,436,748,748,060 | 262 | 106 |
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(len(a)):
if i%2==0 and a[i]%2==1:
cnt+=1
print(cnt) | n = int(input())
a = list(map(int, input().split()))
ans = 0
for num in range(1, n+1, 2):
if a[num-1] % 2 != 0:
ans += 1
print(ans) | 1 | 7,740,525,736,908 | null | 105 | 105 |
from collections import deque
N, D, A = map(int, input().split())
mons = []
for _ in range(N):
X, H = map(int, input().split())
mons.append((X, (H + A - 1) // A))
mons.sort()
ans = 0
q = deque([])
tot = 0
for x, h in mons:
while q:
x0, h0 = next(iter(q))
if x - 2 * D <= x0:
break
tot -= h0
q.popleft()
h = max(0, h - tot)
ans += h
tot += h
q.append((x, h))
print(ans)
| import bisect
n,d,a = map(int,input().split())
lst = []
x = []
for i in range(n):
xi,hi = map(int,input().split())
lst.append([xi,hi,0])
x.append(xi)
lst.sort()
x.sort()
count = 0
cur = 0
for i in range(n):
if lst[i][1]-cur > 0:
num = -(-(lst[i][1]-cur)//a)
count += num
damage = a * num
cur += damage
index = bisect.bisect(x,x[i]+2*d)
if index != n:
lst[index-1][2] += damage
cur -= lst[i][2]
print(count) | 1 | 82,224,533,052,060 | null | 230 | 230 |
ABC = list(map(int,input().split()))
red = ABC[0]
green = ABC[1]
blue = ABC[2]
K = int(input())
for i in range(K):
if green <= red:
green *= 2
continue
elif blue <= green:
blue *= 2
if green > red and blue > green:
print('Yes')
else:
print('No') | N, K = map(int, input().split())
SC = list(map(int, input().split()))
T = input()
Q = []
for i in range(len(T)):
if T[i] == "r":
Q.append(0)
elif T[i] == "s":
Q.append(1)
else:
Q.append(2)
my = [0 for i in range(N)]
ans = 0
for i in range(N):
if i < K:
my[i] = (Q[i] - 1) % 3
ans += SC[my[i]]
else:
n = (Q[i] - 1) % 3
if my[i - K] != n:
my[i] = n
ans += SC[my[i]]
else:
if i + K < N:
my[i] = Q[i+K]
print(ans) | 0 | null | 56,889,048,270,222 | 101 | 251 |
n = input()
str_n = list(n)
if str_n[-1] == "3":
print("bon")
elif str_n[-1] == "0" or str_n[-1] == "1" or str_n[-1] == "6" or str_n[-1] == "8":
print("pon")
else:
print("hon") | N = list(input())
l = len(N)
if N[l-1] == '2' or N[l-1] == '4' or N[l-1] == '5' or N[l-1] == '7' or N[l-1] == '9':
print('hon')
elif N[l-1] == '0' or N[l-1] == '1' or N[l-1] == '6' or N[l-1] == '8':
print('pon')
elif N[l-1] == '3':
print('bon') | 1 | 19,305,443,497,048 | null | 142 | 142 |
x = int(input())
money = 100
year = 0
while True:
money = money + money*100//10000
year += 1
if money >= x:
print(year)
exit() | x=int(input())
cost=100
for i in range(1,10000000000):
cost+=cost//100
if cost>=x:
print(i)
break | 1 | 27,273,041,018,300 | null | 159 | 159 |
X, Y, A, B, C = map(int, input().split())
Ap = list(map(int, input().split()))
Bq = list(map(int, input().split()))
Cr = list(map(int, input().split()))
Ap.sort()
Bq.sort()
print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[C:])) | x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:x]
q = q[:y]
r = r[:x+y]
all = p + q + r
all.sort(reverse = True)
print(sum(all[:x+y])) | 1 | 44,706,365,650,378 | null | 188 | 188 |
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N,K=mi()
P=list(mi())
C=list(mi())
ans = -INF
for i in range(N):
start = i + 1
stack = [start]
score_his = [0]
scores = 0
depth = 1
seen = {}
while stack:
if depth > K: break
current = stack.pop()
if current in seen:
loop_start_depth = seen[current]
loop_end_depth = depth - 1
loop_scores = score_his[-1] - score_his[loop_start_depth-1]
loop_len = loop_end_depth - loop_start_depth + 1
if loop_scores < 0: break
# print(start,score_his)
# print(loop_start_depth,loop_end_depth,loop_scores,loop_len)
rest_count = K - depth + 1
available_loop_count = rest_count // loop_len
res1 = (available_loop_count-1) * loop_scores + scores
# print("a",rest_count,available_loop_count,res1)
res2 = res1
rest_loop_len = rest_count % loop_len + loop_len
# print("b",rest_loop_len)
ress = [res1,res2]
for j in range(rest_loop_len):
score = C[P[current-1]-1]
res2 += score
ress.append(res2)
current = P[current-1]
# print("ress",ress)
score_his.append(max(ress))
break
score = C[P[current-1]-1]
scores += score
score_his.append(scores)
seen[current] = depth
stack.append(P[current-1])
depth += 1
ans = max(ans,max(score_his[1:]))
print(ans)
if __name__ == "__main__":
main() | from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
Ques = [ list(map(int, input().split())) for _ in range(Q) ]
Nums = [ i for i in range(M) ]
ans = -1
for v in combinations_with_replacement(Nums, N):
cnt = 0
for que in Ques:
if v[que[1]-1]-v[que[0]-1] == que[2]: cnt += que[3]
ans = max(ans, cnt)
print(ans) | 0 | null | 16,382,209,517,728 | 93 | 160 |
n = list(input())
for i in range(0, len(n)):
print("x", end = "") | # B - I miss you...
# S
S = input()
answer = '0'
for i in range(0, len(S)):
answer += 'x'
print(answer[1:len(S) + 1])
| 1 | 72,901,723,075,220 | null | 221 | 221 |
import sys
for i in sys.stdin.readlines():
a,b = map(int,i.split())
print len(str(a+b)) | import sys
import math
for n in [int(math.log10(float(int(line.split()[0])+int(line.split()[1]))))+1 for line in sys.stdin]:
print n | 1 | 116,377,092 | null | 3 | 3 |
def main():
s = input()
n = len(s)
for i in range(n//2):
if s[i] != s[n-1-i]:
print("No")
return
s1 = s[:(n-1)//2]
s2 = s[(n+3)//2-1:]
n1 = len(s1)
for i in range(n//4):
if s1[i] != s[n1-1-i]:
print("No")
return
if s2[i] != s[n1-1-i]:
print("No")
return
print("Yes")
if __name__ == "__main__":
main() | # coding: utf-8
import sys
from collections import deque
readline = sys.stdin.readline
sr = lambda: readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 左からgreedyに
N, D, A = lr()
monsters = []
for _ in range(N):
x, h = lr()
monsters.append((x, h))
monsters.sort()
bomb = deque()
answer = 0
attack = 0
for x, h in monsters:
while bomb:
if bomb[0][0] + D < x:
attack -= bomb[0][1]
bomb.popleft()
else:
break
h -= attack
if h > 0:
t = -(-h//A)
answer += t
bomb.append((x + D, A * t))
attack += A * t
print(answer)
| 0 | null | 64,101,290,761,452 | 190 | 230 |
table = [[ 0 for i in range(13)] for j in range(4)]
n = int(input())
i = 0
while i < n:
s,num = input().split()
num = int(num)
if s == "S":
table[0][num-1] = 1
elif s == "H":
table[1][num-1] = 1
elif s == "C":
table[2][num-1] = 1
else: # D
table[3][num-1] = 1
i += 1
for i,elem_i in enumerate(table):
for j,elem_j in enumerate(elem_i):
if elem_j ==1:
continue
if i == 0:
s_str='S'
elif i == 1:
s_str='H'
elif i == 2:
s_str='C'
else:
s_str='D'
print (s_str + " " + str(j+1))
| l=[]
for mark in ["S","H","C","D"]:
for i in range(1,14):
l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
l.remove(input())
for i in l:
print(i) | 1 | 1,036,584,871,560 | null | 54 | 54 |
S=str(input())
S=S.replace('?', 'D')
print(S)
| import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
#from math import *
from itertools import permutations ,product
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def inc(d,c):
d[c]=d[c]+1 if c in d else 1
def bo(i):
return ord(i)-ord('A')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j):
return 0<=i<n and 0<=j<n
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=1
def find(a,i):
if i==a[i]:
return a[i]
a[i]=find(a,a[i])
return a[i]
def union(a,x,y):
xs=find(a,x)
ys=find(a,y)
if xs!=ys:
if rank[xs]<rank[ys]:
xs,ys=ys,xs
a[ys]=xs
rank[xs]+=1
while t>0:
t-=1
n,m=mi()
a=[i for i in range(n+1)]
rank=[0]*(n+1)
for i in range(m):
x,y=mi()
union(a,x,y)
d=[0]*(n+1)
for i in range(1,n+1):
a[i]=find(a,i)
d[a[i]]+=1
print(max(d))
| 0 | null | 11,191,155,083,740 | 140 | 84 |
import sys
class Card:
def __init__(self, card):
self.card = card
self.mark = card[0]
self.value = card[1]
def equals(self, other):
if self.mark != other.mark: return False
if self.value != other.value: return False
return True
def __str__(self):
return self.card
def print_cards(cards, cards_):
n = len(cards)
same = True
for i in range(n):
if cards_ != None and cards[i].equals(cards_[i]) == False:
same = False
sys.stdout.write(str(cards[i]))
if i != n - 1:
sys.stdout.write(' ')
print()
return same
def swap(cards, i, j):
temp = cards[i]
cards[i] = cards[j]
cards[j] = temp
def bubble_sort(cards):
n = len(cards)
for i in range(n):
for j in range(n - 1, i, -1):
if cards[j].value < cards[j - 1].value:
swap(cards, j, j - 1)
def selection_sort(cards):
n = len(cards)
for i in range(n):
mini = i
for j in range(i, n):
if cards[j].value < cards[mini].value:
mini = j
if mini != i:
swap(cards, i, mini)
n = int(input())
input_list = list(map(str, input().split()))
cards1 = [None] * n
cards2 = [None] * n
for i in range(n):
cards1[i] = Card(input_list[i])
cards2[i] = Card(input_list[i])
bubble_sort(cards1)
selection_sort(cards2)
print_cards(cards1, None)
print('Stable')
stable = print_cards(cards2, cards1)
if stable == True:
print('Stable')
else:
print('Not stable')
| def selection_sort(numbers, n, key=lambda x: x):
"""selection sort method
Args:
numbers: a list of numbers to be sorted
n: len(numbers)
key: sort key
Returns:
sorted numberd, number of swapped times
"""
x = []
for data in numbers:
x.append(data)
counter = 0
for i in range(0, n):
min_j = i
for j in range(i, n):
if key(x[j]) < key(x[min_j]):
min_j = j
if min_j != i:
x[min_j], x[i] = x[i], x[min_j]
counter += 1
return x, counter
def bubble_sort(numbers, n, key=lambda x: x):
"""bubble sort method
Args:
numbers: a list of numbers to be sorted by bubble sort
n: len(list)
key: sort key
Returns:
sorted list
"""
x = []
for data in numbers:
x.append(data)
flag = True
counter = 0
while flag:
flag = False
for index in range(n - 1, 0, -1):
if key(x[index]) < key(x[index - 1]):
x[index], x[index - 1] = x[index - 1], x[index]
flag = True
counter += 1
return x, counter
def insertion_sort(numbers, n, key=lambda x: x):
"""insertion sort method
Args:
numbers: a list of numbers to be sorted
n: len(numbers)
Returns:
sorted list
"""
for i in range(1, n):
target = numbers[i]
index = i - 1
while index >= 0 and target < numbers[index]:
numbers[index + 1] = numbers[index]
index -= 1
numbers[index + 1] = target
return numbers
def is_stable(list1, list2):
"""check stablity of sorting method used in list2
Args:
list1: sorted list(bubble sort)
list2: sorted list(some sort)
Returns:
bool
"""
flag = True
for index, data in enumerate(list1):
if list2[index] != data:
flag = False
break
return flag
length = int(raw_input())
cards = raw_input().split()
bubble_sorted_card, bubble_swapped = bubble_sort(numbers=cards, n=length, key=lambda x: int(x[1]))
selection_sorted_card, selection_swapped = selection_sort(numbers=cards, n=length, key=lambda x: int(x[1]))
print(" ".join(bubble_sorted_card))
print("Stable")
print(" ".join(selection_sorted_card))
if is_stable(bubble_sorted_card, selection_sorted_card):
print("Stable")
else:
print("Not stable") | 1 | 27,167,497,060 | null | 16 | 16 |
S = int(input())
f = 10**9 + 7
dp = [0]*(S+1)
dp[0] = 1
for i in range(1,S+1):
if i==1 or i==2: dp[i] = 0
else:
for j in range(0,i-2):
dp[i] += dp[j]
dp[i] %= f
print(dp[-1]%f) | W,H,x,y,r = map(int, input().split())
if W < (x+r) or H < (y + r) or 0 > (x-r) or 0 > (y-r) :
print("No")
else :
print("Yes")
| 0 | null | 1,876,920,893,760 | 79 | 41 |
def gcd (a, b):
while b != 0:
a, b = b, a%b
return a
def lcm(a, b,mod):
return a*b//gcd(a,b)
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
b = 1
for i in range(N):
a = A[i]
b = lcm(a,b,mod)
ans = 0
for a in A:
ans += b//a
print(ans%mod) | # 幅優先探索
from collections import deque
N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]
links = [[] for _ in range(N + 1)]
for a, b in AB:
links[a].append(b)
links[b].append(a)
result = [-1] * (N + 1)
q = deque([1])
while q:
i = q.popleft()
for j in links[i]:
if result[j] == -1:
result[j] = i
q.append(j)
print('Yes')
print(*result[2:], sep='\n')
| 0 | null | 54,132,982,972,422 | 235 | 145 |
def main():
import sys
input = sys.stdin.readline
n, d, a = [int(i) for i in input().split()]
chk = []
for i in range(n):
x, h = [int(i) for i in input().split()]
chk.append((x, 0, h))
from heapq import heapify, heappop, heappush
heapify(chk)
atk_cnt = 0; ans = 0
while chk:
x, t, h = heappop(chk)
if t == 0:
if atk_cnt * a >= h:
continue
remain = h - atk_cnt * a
new_atk = (remain - 1) // a + 1
heappush(chk, (x + 2 * d, 1, new_atk))
ans += new_atk
atk_cnt += new_atk
else:
atk_cnt -= h
print(ans)
if __name__ == '__main__':
main()
| K = int(input())
S = input()
l = list(S)
if len(l) <= K: print(S)
else:
ans = ''
for i in range(K):
ans += l[i]
ans += '...'
print(ans) | 0 | null | 50,651,117,851,220 | 230 | 143 |
t,h=0,0
n=int(input())
for i in range(n):
a,b=input().split()
if a > b:
t+=3
elif a < b:
h+=3
else:
t+=1
h+=1
print(t, h) | n = int(input())
s = input().split()
arr = [int(s[i]) for i in range(n)]
arr.sort()
sum = 0
for i in range(len(arr)):
sum += arr[i]
print(arr[0], arr[len(arr)-1], sum) | 0 | null | 1,373,295,244,860 | 67 | 48 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
A = LI()
c = 0
d = collections.Counter()
d[0] = 1
ans = 0
r = [0] * (N+1)
for i,x in enumerate(A):
if i >= K-1:
d[r[i-(K-1)]] -= 1
c = (c + x - 1) % K
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans)
if __name__ == '__main__':
main() | import bisect
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
cuml=[0]*(N+1)
cuml[0]=A[0]
l=[]
cuml2=[]
l2=[]
buf=[]
ans=0
for i in range(N):
cuml[i+1]=cuml[i]+A[i+1]
#print(cuml)
for i in range(N+1):
cuml2.append([(cuml[i]-i)%K,i])
cuml[i]=(cuml[i]-i)%K
#print(cuml2,cuml)
cuml2.sort(key=lambda x:x[0])
piv=cuml2[0][0]
buf=[]
for i in range(N+1):
if piv!=cuml2[i][0]:
l2.append(buf)
piv=cuml2[i][0]
buf=[]
buf.append(cuml2[i][1])
l2.append(buf)
#print(l2)
cnt=0
for i in range(len(l2)):
for j in range(len(l2[i])):
num=l2[i][j]
id=bisect.bisect_left(l2[i], num + K)
#print(j,id)
cnt=cnt+(id-j-1)
print(cnt)
| 1 | 137,091,958,168,858 | null | 273 | 273 |
from itertools import permutations
if __name__ == "__main__":
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
arr = [i for i in range(1,N+1)]
pattern_arr = list(permutations(arr))
a,b = -1,-1
for i,pattern in enumerate(pattern_arr):
if pattern == P:
a = i
if pattern == Q:
b = i
print(abs(a-b)) | import itertools
N = int(input())
l = []
for i in itertools.permutations(list(range(1,N+1))):
l.append(i)
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
a = 1
b = 1
for i in l:
if i < P:
a += 1
for i in l:
if i < Q:
b += 1
print(abs(a-b)) | 1 | 100,670,903,103,330 | null | 246 | 246 |
N,K,*A=map(int,open(0).read().split())
for _ in range(K):
B=[0]*(N+1)
for i,j in enumerate(A):
B[max(0,i-j)]+=1
B[min(N,i+j+1)]-=1
for i in range(N):B[i+1]+=B[i]
if A==B:break
A=B
print(*A[:-1]) | N, K = map(int, input().split())
As = list(map(int, input().split()))
for i in range(K):
if min(As) == N:
break
dBs = [0]*(N+1)
for i in range(N):
A = As[i]
dBs[max(0, i-A)] += 1
dBs[min(N, i+A+1)] -= 1
#print(dBs)
Bs = [dBs[0]]
for i in range(1, N):
B = Bs[i-1]+dBs[i]
Bs.append(B)
As = Bs
print(" ".join(map(str, As)))
| 1 | 15,587,242,577,890 | null | 132 | 132 |
def popcount(x):
return bin(x).count("1")
def solve(n):
if n == 0:
return 0
return 1+solve(n % popcount(n))
N = int(input())
X = input()
num_x = int(X, 2)
p_cnt = X.count('1')
if p_cnt == 1:
for i in range(N):
if X[i] == '1':
print(0)
elif i == N-1:
print(2)
else:
print(1)
exit()
r0_p = num_x % (p_cnt+1)
r0_m = num_x % (p_cnt-1)
for i in range(N):
if X[i] == '0':
c_p_cnt = p_cnt+1
r = (r0_p + pow(2, (N - 1 - i), c_p_cnt)) % c_p_cnt
else:
c_p_cnt = p_cnt-1
if c_p_cnt == 0:
print(0)
continue
r = (r0_m- pow(2, (N - 1 - i), c_p_cnt)) % c_p_cnt
print(1 + solve(r % c_p_cnt))
| from functools import lru_cache
def popcnt(x):
return bin(x).count("1")
@lru_cache(maxsize=None)
def rec(n):
if n == 0:
return 0
else:
return rec(n % popcnt(n)) + 1
n = int(input())
arr = input()
ALL_ARR = int(arr, 2)
# ALL_ARR mod popcnt±1を予め計算しておく
cnt = popcnt(int(arr, 2))
init_big = ALL_ARR % (cnt + 1)
if cnt == 1:
init_small = 0
else:
init_small = ALL_ARR % (cnt - 1)
# 変更部分だけ調整して剰余を再計算する
# 調整部分だけでも数が大きいためpowの引数modで高速化
li = [0] * n
for i in range(n):
if arr[i] == "0":
li[i] = (init_big + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)
# 0除算回避のためにフラグを立てておく
elif ALL_ARR - (1 << (n - i - 1)) == 0 or cnt - 1 == 0:
li[i] = "flg"
else:
li[i] = (init_small - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)
ans = []
for x in li:
if x == "flg":
ans.append(0)
else:
ans.append(rec(x) + 1)
print(*ans, sep="\n") | 1 | 8,229,839,698,818 | null | 107 | 107 |
while True:
c = str(input())
if c == "-":
break
n = int(input())
for i in range(n):
a = int(input())
c = c[a:] + c[:a]
print(c)
|
while True:
line = input()
if line=='-':
break
loop = int(input())
for i in range(loop):
x = int(input())
line = line[x:] + line[:x]
print(line)
| 1 | 1,896,253,570,496 | null | 66 | 66 |
N = int(input())
alist = list(map(int, input().split()))
k = 1
if 0 in alist:
print(0)
else:
for i in range(0,N):
k = k*alist[i]
if k > 1000000000000000000:
k= -1
break
print(k) |
def main():
n = int(input())
As = list(map(int, input().split()))
ans = 1
if 0 in As:
print(0)
return
for a in As:
ans *= a
if ans > 10**18:
print(-1)
return
print(ans)
if __name__ == '__main__':
main()
| 1 | 16,204,869,353,010 | null | 134 | 134 |
# coding: utf-8
"""
import codecs
import sys
sys.stdout = codecs.getwriter("shift_jis")(sys.stdout) # ??????
sys.stdin = codecs.getreader("shift_jis")(sys.stdin) # ??\???
# ??\??¬?????????print??????????????´?????? print(u'?????????') ??¨??????
# ??\??¬?????????input??? input(u'?????????') ??§OK
# ??°?¢???????????????????????????´??????6,7???????????????????????¢??????
"""
s = raw_input()
p = raw_input()
#s = "abaabbaabbaaaaaabbaabba"
#p = "aabbaabaabb"
cnt = s.count(p[0]) #????§?????£?????????°
flag = 0
if cnt == -1: #p???????????????????????¨?????????
print("No")
else: #????§?????£?????????¨??????
start_search = 0 #????´¢?????????????§???????
while cnt > 0:
index = s.find(p[0], start_search) #????§????????????????
ans = 1
for i in range(len(p)):
if index + i >= len(s): #????°?????????????????????´??????????????????????????????????????????
j = i - len(s)
else:
j = i
if s[index + j] != p[i]: #1????????§????????£????????????????????§??¢?´¢??????
ans = 0
break
if ans == 1:
print("Yes")
flag = 1
break
start_search = index + 1
#print(start_search)
cnt -= 1
if flag == 0:
print("No") | import itertools
N, M, Q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(Q):
ai, bi, ci, di = list(map(int, input().split()))
a.append(ai)
b.append(bi)
c.append(ci)
d.append(di)
ans = 0
for A in list(itertools.combinations_with_replacement(range(1, M+1), N)):
# print(A)
score = 0
for i in range(Q):
if A[b[i]-1] - A[a[i]-1] == c[i]:
score += d[i]
if ans < score:
ans = score
# print(A, score)
print(ans)
| 0 | null | 14,541,913,051,820 | 64 | 160 |
import sys
def main():
for line in sys.stdin:
a, b = map(int, line.split())
print(len(str(a + b)))
if __name__ == "__main__":
main() | import math
n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
p1 = 0
p2 = 0
p3 = 0
p4 = []
for i in range(n):
p1 += math.pow(abs(x[i]-y[i]),1)
for i in range(n):
p2 += math.pow(abs(x[i]-y[i]),2)
for i in range(n):
p3 += math.pow(abs(x[i]-y[i]),3)
for i in range(n):
p4.append(abs(x[i]-y[i]))
print(p1)
print(math.sqrt(p2))
print(math.pow((p3),1/3))
print(max(p4))
| 0 | null | 109,391,808,890 | 3 | 32 |
s = [i for i in input()]
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
| c=str(input())
print('Yes' if c[2]==c[3] and c[4]==c[5] else'No') | 1 | 41,907,624,438,812 | null | 184 | 184 |
x = int(input())
cnt = x//100
if x < 100 :
print("0")
else :
for i in range(cnt) :
if 100*cnt <= x <= 105*cnt :
print("1")
break
else :
print("0")
| def so(x):
xx = int(x ** 0.5) + 1
for i in range(2, xx):
if x % i == 0:
return True
return False
x = int(input())
while(so(x)):
x += 1
print(x)
| 0 | null | 116,838,987,229,220 | 266 | 250 |
def main():
arg = input().rstrip()
ans = 'ABC' if arg == 'ARC' else 'ARC'
print(ans)
if __name__ == '__main__':
main()
| s=input()
if s=="ABC":
print("ARC")
else:
print("ABC") | 1 | 24,221,502,692,452 | null | 153 | 153 |
n=input()
fn_first=1
fn_second=1
if n >= 2:
for x in xrange(n-1):
tmp = fn_first
fn_first = fn_first + fn_second
fn_second = tmp
print fn_first | import itertools
n = int(input())
l = list(map(int, input().split()))
count = 0
c_list = list(itertools.combinations(l, 3))
for c in c_list:
if (c[0]+c[1])>c[2] and (c[1]+c[2])>c[0] and (c[2]+c[0])>c[1]:
if len(set(c)) == 3:
count += 1
print(count) | 0 | null | 2,515,774,898,170 | 7 | 91 |
h,a = map(int,input().split())
print(-1*(h//(-1*a))) | def resolve():
n = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
divisors = make_divisors(n)
min_pair = 10**19
for i in divisors:
pair_i = n//i
min_pair = min(min_pair, ((i-1)+(pair_i-1)))
print(min_pair)
resolve() | 0 | null | 119,460,509,325,220 | 225 | 288 |
S = int(input())
h = S // 3600
m = (S // 60) % 60
s = S % 60
print("%d:%d:%d" % (h, m, s))
| S = int(raw_input())
M, s = S / 60, S % 60
h, m = M / 60, M % 60
print '%d:%d:%d' % (h, m, s) | 1 | 338,081,950,986 | null | 37 | 37 |
#!/usr/bin/env python3
def main():
A, B, C, D = map(int, input().split())
print('Yes' if - (-A // D) >= -(-C // B) else 'No')
if __name__ == '__main__':
main()
| A,B,C,D=map(int,input().split())
while A>0 and C>0:
C-=B
A-=D
if C<=0:
print("Yes")
break
elif A<=0:
print("No")
| 1 | 29,634,427,002,962 | null | 164 | 164 |
i = 1
while True:
a = int(input())
if(a == 0):
break
else :
print(f'Case {i}: {a}')
i += 1
| n = int(raw_input())
tp = 0; hp = 0
for i in range(n):
tw,hw = raw_input().split()
if tw == hw:
tp += 1
hp += 1
elif tw > hw:
tp += 3
elif tw < hw:
hp += 3
print '%s %s' % (tp,hp) | 0 | null | 1,259,363,222,108 | 42 | 67 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, u, v = mapint()
query = [[] for _ in range(N)]
for _ in range(N-1):
a, b = mapint()
query[a-1].append(b-1)
query[b-1].append(a-1)
from collections import deque
def dfs(start):
Q = deque([start])
dist = [10**18]*N
dist[start] = 0
while Q:
now = Q.pop()
for nx in query[now]:
if dist[nx]>=10**18:
dist[nx] = dist[now] + 1
Q.append(nx)
return dist
taka = dfs(u-1)
aoki = dfs(v-1)
ans = 0
for i in range(N):
t, a = taka[i], aoki[i]
if t<=a:
ans = max(ans, a-1)
print(ans) | n = int(input())
s = str(input())
s += "A"
q = s[0]
ans = 0
for i in range(n+1):
if(q==s[i]):
None
else:
ans += 1
q = s[i]
print(ans)
| 0 | null | 143,218,394,881,132 | 259 | 293 |
def divide(a, b):
if a < b:
return divide(b, a)
if b == 0:
return a
return divide(b, a%b)
nums=list(map(int,input().split()))
ans = divide(nums[0], nums[1])
print(ans)
| def gcd(a,b):
if(b):
return gcd(b,a%b)
return a
l = raw_input().split()
if(int(l[0]) > int(l[1])):
print gcd(int(l[0]),int(l[1]))
else:
print gcd(int(l[1]),int(l[0]))
| 1 | 7,902,372,670 | null | 11 | 11 |
n = int(input()[-1])
if n == 3:
print("bon")
elif n in [0, 1, 6, 8]:
print("pon")
else:
print("hon") | m=input()
l=len(m)
if m[l-1]=="0" or m[l-1]=="1" or m[l-1]=="6" or m[l-1]=="8":
print("pon")
elif m[l-1]=="3":
print("bon")
else:
print("hon") | 1 | 19,345,135,256,060 | null | 142 | 142 |