code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
|---|---|---|---|---|---|---|
intl=map(int, raw_input().split())
a=intl[0]
b=intl[1]
if a==b:
print "a == b"
elif a>b:
print "a > b"
else:
print "a < b"
|
m,n=map(int,raw_input().split())
if m>n:print'a > b'
elif m<n:print'a < b'
else:print'a == b'
| 1 | 353,980,211,208 | null | 38 | 38 |
n,m=[int(x) for x in input().split()]
A=[[0 for i in range(m)] for i in range(n)]
vector=[0 for i in range(m)]
result=[0 for i in range(n)]
for i in range(n):
A[i]=[int(x) for x in input().split()]
for i in range(m):
vector[i]=int(input())
for i in range(n):
for j in range(m):
result[i] += A[i][j]*vector[j]
for _ in result:
print(_)
|
N = int(input())
A = [0]*(N)
for i in input().split():
A[int(i)-1] = A[int(i)-1]+1
for i in A:
print(i)
| 0 | null | 16,827,728,995,088 | 56 | 169 |
r=int(input())
ans=2*r*3.141592
print(ans)
|
R = int(input())
enn = R * 2 * 3.14
print(enn)
| 1 | 31,410,271,239,480 | null | 167 | 167 |
len_s = int(input())
s = [int(i) for i in input().split()]
len_t = int(input())
t = [int(i) for i in input().split()]
cnt = 0
for f in t:
i = 0
while i < len(s) and s[i] != f:
i += 1
if i < len(s):
cnt +=1
print(cnt)
|
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
cnt = 0
for T in T:
if T in S:
cnt += 1
print(cnt)
| 1 | 68,232,285,438 | null | 22 | 22 |
while True:
n = int(input())
if n == 0:
break
else:
score = [int(x) for x in input().split()]
a = 0
m = sum(score)/n
for s in score:
a += (s-m)**2
a = (a/n)**0.5
print('{:.8f}'.format(a))
|
import numpy as np
#基本入力
D = int(input())
c =list(map(int,input().split()))
s = []
for i in range(D):
s.append(list(map(int,input().split())))
t = []
for i in range(D):
t.append(int(input()))
#基本入力完了
#得点計算
c = np.array(c)
last_day = np.array([0]*26)
day_pulse = np.array([1]*26)
s = np.array(s)
t = np.array(t)
manzoku = 0
for day in range(1,D+1):
contest_number = t[day-1] #開催するコンテスト種類
manzoku += s[day-1,contest_number-1] #開催したコンテストによる満足度上昇
last_day += day_pulse #経過日数の計算
last_day[contest_number -1 ] = 0 #開催したコンテスト種類の経過日数を0に
manzoku -= sum(c*last_day) #開催していないコンテストによる満足度の減少
print(manzoku)
| 0 | null | 5,029,195,142,368 | 31 | 114 |
def main(h: int, w: int, n: int):
m = max(h, w)
if n % m == 0:
print(n // m)
else:
print((n // m) + 1)
if __name__ == "__main__":
h = int(input())
w = int(input())
n = int(input())
main(h, w, n)
|
row = int(input())
colmun = int(input())
top = int(input())
low, high = 0,0
if row <= colmun:
low, high = row, colmun
else:
low, high = colmun, row
for n in range(low):
if (n + 1) * high >= top:
print(n + 1)
break
| 1 | 88,622,609,071,992 | null | 236 | 236 |
N = int(input())
A = input().split()
num_list = [0] * 10**5
ans = 0
for i in range(N):
num_list[int(A[i])-1] += 1
for i in range(10**5):
ans += (i+1) * num_list[i]
Q = int(input())
for i in range(Q):
B, C = map(int, input().split())
ans = ans + C * num_list[B-1] - B * num_list[B-1]
num_list[C-1] += num_list[B-1]
num_list[B-1] = 0
print(ans)
|
# coding: utf-8
a , b = map(int,input().split())
c , d = map(int,input().split())
if a + 1 == c:
print(1)
else:
print(0)
| 0 | null | 68,313,667,397,140 | 122 | 264 |
import math
def solve():
N = int(input())
A = list(map(int, input().split()))
if(N == 0 and A[0] == 1):
print(1)
return
leaf_list = [0] * (N+1)
for d in range(N, -1 , -1):
if(d == N):
leaf_list[d] = (A[d],A[d])
else:
Min = math.ceil(leaf_list[d+1][0]/2) + A[d]
Max = leaf_list[d+1][1] + A[d]
leaf_list[d] = (Min,Max)
if(not(leaf_list[0][0] <= 1 and leaf_list[0][1] >= 1)):
print(-1)
return
node_list = [0] * (N+1)
node_list[0] = 1
for d in range(1, N+1):
node_list[d] = min((node_list[d-1] - A[d-1]) * 2, leaf_list[d][1])
print(sum(node_list))
solve()
|
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
low = [0]*(N+1)
high = [0]*(N+1)
low[N] = A[N]
high[N] = A[N]
for i in range(N-1, -1, -1):
low[i] = (low[i+1]+1)//2+A[i]
high[i] = high[i+1]+A[i]
if not low[0]<=1<=high[0]:
print(-1)
exit()
ans = 1
now = 1
for i in range(N):
now = min(2*(now-A[i]), high[i+1])
ans += now
print(ans)
| 1 | 19,009,103,818,420 | null | 141 | 141 |
import sys
import math
input = sys.stdin.readline
a, b = list(map(int, input().split()))
print(a * b // math.gcd(a, b))
|
import sys
readline = sys.stdin.readline
S = readline().rstrip()
from collections import deque
S = deque(S)
Q = int(readline())
turn = False
for i in range(Q):
query = readline().split()
if query[0] == "1":
turn ^= True
elif query[0] == "2":
if query[1] == "1":
if turn:
S.append(query[2])
else:
S.appendleft(query[2])
elif query[1] == "2":
if turn:
S.appendleft(query[2])
else:
S.append(query[2])
S = "".join(S)
if turn:
S = S[::-1]
print(S)
| 0 | null | 85,288,992,145,830 | 256 | 204 |
# coding: utf-8
from math import sqrt
from itertools import permutations
def main():
N = int(input())
ans = 0.0
P = [i for i in range(N)]
C = [list(map(int, input().split())) for _ in range(N)]
for p in permutations(P):
for i in range(N - 1):
ans += sqrt(((C[p[i + 1]][0] - C[p[i]][0]) ** 2) + ((C[p[i + 1]][1] - C[p[i]][1]) ** 2))
for i in range(2, N + 1):
ans /= i
print(ans)
if __name__ == "__main__":
main()
|
from itertools import permutations
import math
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
sum_roots = 0
for points in permutations(XY):
for point_idx in range(1, N):
before_x = points[point_idx-1][0]
before_y = points[point_idx-1][1]
x = points[point_idx][0]
y = points[point_idx][1]
sum_roots += math.sqrt((x-before_x) ** 2 + (y-before_y)**2)
print(sum_roots/math.factorial(N))
| 1 | 148,473,130,691,032 | null | 280 | 280 |
X, K, D = map(int, input().split())
ans = abs(abs(X) - D*K)
a = abs(X)//D
b = abs(X)%D
if (K - a)%2 == 1 and a < K:
ans = D - b
elif (K - a)%2 == 0 and a < K:
ans = b
print(ans)
|
x,k,d = list(map(int, input().split()))
amari = abs(x) % d
shou = abs(x) // d
amari_ = abs(amari - d)
if k < shou:
print(abs(x) - d * k)
else:
if (k - shou) % 2 == 0:
print(amari)
else:
print(amari_)
| 1 | 5,239,039,261,980 | null | 92 | 92 |
a=[]
for i in range(10):
inp=input()
a.append(inp)
if i>=3:
a.sort()
del a[0]
print a[2]
print a[1]
print a[0]
|
import math
while True:
try:
n=input()
x=100000
for i in xrange(n):
x=math.ceil(x*1.05/1000)*1000
print(int(x))
except EOFError: break
| 0 | null | 466,843,680 | 2 | 6 |
n, k, c = map(int, input().split())
s = input()
l = [0 for i in range(k+1)]
r = [0 for i in range(k+1)]
cnt = 0
kaime = 1
for i in range(n):
if kaime > k: break
if cnt > 0:
cnt -= 1
else:
if s[i] == 'o':
l[kaime] = i
kaime += 1
cnt = c
cnt = 0
kaime = k
for j in range(n):
i = n-1 - j
if kaime < 1: break
if cnt > 0:
cnt -= 1
else:
if s[i] == 'o':
r[kaime] = i
kaime -= 1
cnt = c
for i in range(1, k+1):
if l[i] == r[i]:
print(l[i]+1)
|
n, k, c = map(int, input().split())
s = input()
l = [0] * k
r = [0] * k
p = 0
# for i in range(n):
i = 0
while i < n:
if s[i] == "o":
l[p] = i
p += 1
if (p >= k):
break
i += c
i += 1
p = k-1
# for i in range(n - 1, -1, -1):
i = n - 1
while i >= 0:
if s[i] == "o":
r[p] = i
p -= 1
if (p < 0):
break
i -= c
i -= 1
#print(l, r)
for i in range(k):
if l[i] == r[i]:
print(l[i]+1)
| 1 | 40,695,424,148,588 | null | 182 | 182 |
N = input()
if N.find('7') > -1:
print('Yes')
else:
print('No')
|
N = list(input())
if '7' in N:
print("Yes")
else:
print("No")
| 1 | 34,311,894,232,188 | null | 172 | 172 |
S = str(input())
if S[0] == S[1] == S[2]:
print('No')
else:
print('Yes')
|
# n, k = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
# b = list(map(int, input().split()))
# print(r + max(0, 100*(10-n)))
# print("Yes" if 500*n >= k else "No")
# s = input()
# a = int(input())
# b = int(input())
# c = int(input())
s = input()
print("Yes" if ('A' in s and 'B' in s) else "No")
| 1 | 55,043,647,010,688 | null | 201 | 201 |
from collections import defaultdict
N, X, M = map(int, input().split())
A = [X]
visited = set()
visited.add(X)
idx = defaultdict()
idx[X] = 0
iii = -1
for i in range(1, M):
tmp = (A[-1]**2) % M
if tmp not in visited:
A.append(tmp)
visited.add(tmp)
idx[tmp] = i
else:
iii = idx[tmp]
ans = 0
if iii == -1:
ans = sum(A[:N])
print(ans)
exit()
else:
# ループの頭の直前まで
ans += sum(A[:iii])
N -= iii
if N > 0:
# ループの長さ
l = len(A) - iii
ans += (N // l) * sum(A[iii:])
N -= N // l * l
if N > 0:
# ループに満たないN
ans += sum(A[iii:iii + N])
print(ans)
|
N, X, M = map(int, input().split())
pt = [[0] * (M+100) for i in range(70)]
to = [[0] * (M+100) for i in range(70)]
for i in range(M+1):
to[0][i] = (i*i) % M
pt[0][i] = i
for i in range(65):
for j in range(M+1):
to[i+1][j] = to[i][to[i][j]]
pt[i+1][j] = pt[i][j] + pt[i][to[i][j]]
ans = 0
for i in range(60):
if (N>>i)&1:
ans += pt[i][X]
X = to[i][X]
print(ans)
| 1 | 2,804,745,566,532 | null | 75 | 75 |
import sys
size = int(sys.stdin.readline())
for i in range(size):
line = sys.stdin.readline()
line = line.split(" ")
inp = []
for j in line:
inp.append(int(j))
inp.sort()
if (inp[0]**2+inp[1]**2==inp[2]**2):
print("YES")
else:
print("NO")
|
N = int(raw_input())
for i in range(N):
a = range(3)
a[0],a[1],a[2] = map(int, raw_input().split())
a.sort()
if a[0]**2 + a[1]**2 == a[2]**2:
print "YES"
else:
print "NO"
| 1 | 351,236,402 | null | 4 | 4 |
from sys import stdin
input = stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
order = sorted(range(1, N+1), key=lambda i: A[i-1])
print(*order, sep=' ')
if(__name__ == '__main__'):
main()
|
N = int(input())
A = list(map(int, input().split()))
dct = dict(enumerate(A))
ad = sorted(dct.items(), key=lambda x:x[1])
ans = []
for i in ad:
j = i[0] + 1
ans.append(j)
a = map(str, ans)
b = ' '.join(a)
print(b)
| 1 | 180,548,468,032,982 | null | 299 | 299 |
# ABC145D
import sys
input=sys.stdin.readline
MOD=10**9+7
factorial=[1]*(2*10**6+1)
for i in range(1,2*10**6+1):
factorial[i]=factorial[i-1]*i
factorial[i]%=MOD
def modinv(x):
return pow(x,MOD-2,MOD)
def comb(n,r):
return (factorial[n]*modinv(factorial[n-r])*modinv(factorial[r]))%MOD
def main():
X,Y=map(int,input().split())
a=(2*Y-X)
b=(2*X-Y)
A=a//3
B=b//3
ans=0
if a%3==0 and b%3==0 and a>=0 and b>=0:
ans=comb(A+B,A)
print(ans)
if __name__=="__main__":
main()
|
from math import gcd
import itertools
k = int(input())
lst = [int(i) for i in range(1, k+1)]
all_array = list(itertools.combinations_with_replacement(lst, 3))
num = 0
for element in all_array:
a = element[0]
b = element[1]
c = element[2]
d = gcd(gcd(a, b), c)
if a != b and b != c:
num += d * 6
elif a == b and b != c:
num += d * 3
elif a != b and b == c:
num += d * 3
elif a == b and b == c:
num += d
print(num)
| 0 | null | 92,521,360,710,710 | 281 | 174 |
n = list(input())
if '7' in n:
print('Yes')
else:
print('No')
|
if any(x == '7' for x in input()):
print('Yes')
else:
print('No')
| 1 | 34,263,326,219,460 | null | 172 | 172 |
n = int(input())
A = list(input().split())
def insertion_sort(l):
for i in range(0, len(l) - 1):
x = i + 1
while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
temp = l[x]
l[x] = l[x - 1]
l[x - 1] = temp
x -= 1
return l
def babble_sort(l):
for i in range(0, len(l)):
for j in reversed(range(i+1, len(l))):
b = int(l[j][1])
a = int(l[j - 1][1])
if b < a:
t = l[j]
l[j] = l[j-1]
l[j-1] = t
return l
def is_stable(a, l):
for i in range(0, len(a)):
if a[i] != l[i]:
return False
return True
def print_with_space(l):
print(' '.join(str(x) for x in l))
B = insertion_sort(A[:])
babbled = babble_sort(A[:])
print_with_space(babbled)
if is_stable(B, babbled):
print('Stable')
else:
print('Not stable')
def selection_sort(l):
for i in range(0, len(l)):
minj = i
for j in range(i, len(l)):
if int(l[j][1]) < int(l[minj][1]):
minj = j
t = l[i]
l[i] = l[minj]
l[minj] = t
return l
selected = selection_sort(A[:])
print_with_space(selected)
if is_stable(B, selected):
print('Stable')
else:
print('Not stable')
|
# -*- coding:utf-8 -*-
def Selection_Sort(A,n):
for i in range(n):
mini = i
for j in range(i,n): #i以上の要素において最小のAをminiに格納
if int(A[j][1]) < int(A[mini][1]):
mini = j
if A[i] != A[mini]:
A[i], A[mini] = A[mini], A[i]
return A
def Bubble_Sort(A, n):
for i in range(n):
for j in range(n-1,i,-1):
if int(A[j][1]) < int(A[j-1][1]):
A[j], A[j-1] = A[j-1], A[j]
return A
n = int(input())
A = input().strip().split()
B = A[:]
A = Bubble_Sort(A,n)
print (' '.join(A))
print ("Stable")
B =Selection_Sort(B,n)
print (' '.join(B))
if A == B:
print ("Stable")
else:
print ("Not stable")
| 1 | 26,161,605,722 | null | 16 | 16 |
MOD = 2019
def solve(S):
N = len(S)
dp = [0 for _ in range(MOD)]
tmp = 0
ret = 0
for i in range(N - 1, -1, -1):
m = (tmp + int(S[i]) * pow(10, N - i - 1, MOD)) % MOD
ret += dp[m]
dp[m] += 1
tmp = m
ret += dp[0]
return ret
if __name__ == "__main__":
S = input()
print(solve(S))
|
from collections import Counter
MOD = 2019
S = input()[::-1]
X = [0]
for i in range(len(S)):
X.append((X[-1]+int(S[i])*pow(10, i, MOD))%MOD)
C = Counter(X)
ans = 0
for v in C.values():
ans += v*(v-1)//2
print(ans)
| 1 | 30,884,177,826,620 | null | 166 | 166 |
import sys
for i in sys.stdin.readlines():
x = i.split(" ")
print len(str(int(x[0]) + int(x[1])))
|
# -*- coding: utf-8 -*-
import sys
import os
for s in sys.stdin:
a, b = list(map(int, s.split()))
c = a + b
if c == 1:
print(1)
continue
for i in range(7):
left = 10 ** i
right = 10 ** (i + 1)
if left <= c < right:
print(i + 1)
break
| 1 | 72,735,148 | null | 3 | 3 |
n, m = map(int, raw_input().split())
a, b = [], []
c = [0 for _ in range (n)]
for _ in range(n):
a.append(map(int, raw_input().split()))
for _ in range(m):
b.append(int(raw_input()))
for i in range(n):
c[i] = 0
for j in range(m):
c[i] += a[i][j]*b[j]
print c[i]
|
row, col = map(int,input().split())
mat = [[0 for i2 in range(col)] for i1 in range(row)]
for i in range(row):
mat[i] = list(map(float,input().split()))
vec = [0 for i in range(col)]
for i in range(col):
vec[i] = float(input())
result = [0 for i in range(row)]
for i in range(row):
for j in range(col):
result[i] += mat[i][j]*vec[j]
for i in range(len(result)):
print(int(result[i]))
| 1 | 1,187,950,193,388 | null | 56 | 56 |
N,X,Y=map(int,input().split())
ANS=[0 for i in range(N-1)]
for i in range(N-1):
for k in range(i+1,N):
d=min(k-i,abs(X-i-1)+abs(Y-k-1)+1)
ANS[d-1]+=1
for i in ANS:
print(i)
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
N = I()
s = 'abcdefghijklmnopqrstuvwxyz'
assert len(s) == 26
cur = []
while N > 0:
amari = N % 26
if amari == 0:
amari += 26
cur.append(s[amari-1])
N -= amari
N //= 26
print(''.join(cur[::-1]))
main()
| 0 | null | 28,075,853,910,780 | 187 | 121 |
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
Q.append(input().split())
t=0
res=[]
while Q!=[]:
if int(Q[0][1])<=q:
res.append([Q[0][0],int(Q[0][1])+t])
t+=int(Q[0][1])
else:
Q.append([Q[0][0],int(Q[0][1])-q])
t+=q
del Q[0]
for i in res:
print(i[0]+" "+str(i[1]))
|
n,r=map(int,input().split())
if n<10:
ans=r+(100*(10-n))
else:
ans=r
print(ans)
| 0 | null | 31,877,177,395,638 | 19 | 211 |
from collections import deque
n, x, y = map(int, input().split())
graph = [[i-1,i+1] for i in range(n+1)]
graph[1]=[2]
graph[n]=[n-1]
graph[0]=[0]
graph[x].append(y)
graph[y].append(x)
def bfs(start,graph2):
dist = [-1] * (n+1)
dist[0] = 0
dist[start] = 0
d = deque()
d.append(start)
while d:
v = d.popleft()
for i in graph2[v]:
if dist[i] != -1:
continue
dist[i] = dist[v] + 1
d.append(i)
dist = dist[start+1:]
return dist
ans=[0 for _ in range(n-1)]
for i in range(1,n+1):
for j in bfs(i,graph):
ans[j-1] +=1
for i in ans:
print(i)
|
R,C,K = map(int,input().split()) #行、列、個数
G = [[0]*C for _ in range(R)] #G[i][j]でi行目のj番目にある価値
for i in range(K):
a,b,v = map(int,input().split())
a-=1;b-=1 #0index
G[a][b] = v
#print(G)
dp = [[0]*4 for _ in range(C+1)]
#dp[j][k]ある行において、j個目まで見て、その行でk個拾っている
for i in range(R):
p = [[0]*4 for _ in range(C+1)] #pが前の行、dpが今の行
p,dp = dp,p
for j in range(C):
#print(j+1,dp)
for k in range(4):
if k == 0: #その行で一個も取っていなければ上の行から来るだけ
dp[j+1][k] = max(p[j+1])
elif k == 1: #一個目をとるということは横からきて取るか、上から来て取るか
if G[i][j] == 0: #そこにない場合は横から
dp[j+1][k] = dp[j][k]
else: #ある場合は横からくるか上から来て一個取るか
dp[j+1][k] = max(dp[j][k],max(p[j+1])+G[i][j])
else: #二個以上の場合には上からは来れない。
if G[i][j] == 0: #そこになければ横からくるだけ
dp[j+1][k] = dp[j][k]
else: #あればとったほうがよいか比較
dp[j+1][k] = max(dp[j][k],dp[j][k-1]+G[i][j])
#print(p,dp)
ans = max(dp[C])
print(ans)
| 0 | null | 24,736,610,730,678 | 187 | 94 |
S = input()
for i in range(1, 6):
if S == 'hi' * i:
print('Yes')
exit()
print('No')
|
s=input()
cnt=s.count("hi")
if cnt*2==len(s):
print("Yes")
else:
print("No")
| 1 | 53,098,217,424,912 | null | 199 | 199 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
As = list(mapint())
plus = [i+a for i, a in enumerate(As)]
minus = [i-a for i, a in enumerate(As)]
from collections import Counter
pc = Counter(plus)
mc = Counter(minus)
ans = 0
for p, cnt in pc.most_common():
ans += cnt*mc[p]
print(ans)
|
k=int(input())
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
for l in range(1,k+1):
ans+=gcd(gcd(i,j),l)
print(ans)
| 0 | null | 30,757,395,558,240 | 157 | 174 |
W, H, x, y ,r = [int(i) for i in input().split()]
if x <= 0 or y <= 0:
print("No")
elif W - x >= r and H - y >= r:
print("Yes")
else:
print("No")
|
from decimal import Decimal
X=int(input())
c =Decimal(100)
C=0
while c<X:
c=Decimal(c)*(Decimal(101))//Decimal(100)
C+=1
print(C)
| 0 | null | 13,805,873,817,792 | 41 | 159 |
def readInt():
return list(map(int, input().split()))
h, w = readInt()
if h == 1 or w == 1:
print(1)
elif h*w%2 == 0:
print(h*w//2)
else:
print(h*w//2+1)
|
import math
h, w = map(int, input().split())
ans = math.ceil(h * w / 2)
if h == 1 or w == 1:
ans = 1
print(ans)
| 1 | 51,073,711,975,872 | null | 196 | 196 |
S = input()
K = int(input())
if len(set(S)) == 1:
print(len(S)*K//2)
exit()
b = [1]
for i in range(len(S)-1):
if S[i] == S[i+1]:
b[-1] += 1
else:
b.append(1)
ans = 0
for i in b:
ans += i//2
ans *= K
if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
ans += K - 1
print(ans)
|
s=str(input())
k=int(input())
ans=0
count=1
c1=0
c2=0
if len(set(s))==1:
print(len(s)*k//2)
exit()
if s[0]==s[-1]:
for i in range(len(s)-1):
if s[i]==s[i+1]:
count+=1
else:
if 2<=count:
ans+=count//2
count=1
ans+=count//2
i=0
while s[i]==s[0]:
c1+=1
i+=1
i=len(s)-1
while s[i]==s[-1]:
c2+=1
i-=1
#print(c1,c2)
ans*=k
if c1%2==1 and c2%2==1:
ans+=k-1
print(ans)
else:
for i in range(len(s)-1):
if s[i]==s[i+1]:
count+=1
else:
if 2<=count:
ans+=count//2
count=1
ans+=count//2
print(ans*k)
| 1 | 175,868,311,808,518 | null | 296 | 296 |
s="ACL"*int(input())
print(s)
|
def main():
K: int = int(input())
S: str = 'ACL'
print(S*K)
if __name__ == "__main__":
main()
| 1 | 2,179,485,955,922 | null | 69 | 69 |
def magic(a,b,c,k):
for i in range(k):
if(a>=b):
b*=2
elif(b>=c):
c*=2
if(a < b and b < c):
print("Yes")
else:
print("No")
d,e,f = map(int,input().split())
j = int(input())
magic(d,e,f,j)
|
A, B, C = map(int, input().split())
K = int(input())
cnt = 0
while A>=B:
cnt+=1
B*=2
while B>=C:
cnt+=1
C*=2
print("Yes" if cnt<=K else "No")
| 1 | 6,916,856,865,370 | null | 101 | 101 |
import sys
def readint():
for line in sys.stdin:
yield map(int,line.split())
def gcd(x,y):
[x,y] = [max(x,y),min(x,y)]
while 1:
z = x % y
if z == 0:
break
[x,y] = [y,z]
return y
for [x,y] in readint():
GCD = gcd(x,y)
mx = x/GCD
print GCD,mx*y
|
def gcd(a, b):
if a > b:
a, b = b, a
if a == 0:
return b
else:
return gcd(b % a, a)
try:
while 1:
a,b = list(map(int,input().split()))
c = gcd(a, b)
print('{} {}'.format(c,int(c * (a/c) * (b/c))))
except Exception:
pass
| 1 | 604,503,620 | null | 5 | 5 |
N = int(input())
def cnt(s):
r = [0] * (len(s)+1)
for i, v in enumerate(s):
if v == '(':
r[i+1] = r[i] + 1
else:
r[i+1] = r[i] - 1
return r[0], r[-1], min(r)
# S1 := 始点 < 終点
S1 = []
# S2 := 始点 => 終点
S2 = []
for i in range(N):
s = input()
t = tuple(cnt(s))
if t[1] > 0:
S1.append(t)
else:
S2.append(t)
def main():
# Sの終点を合計して0じゃなかったら、終わり
if sum([s[1] for s in S1]) + sum([s[1] for s in S2]) != 0:
print("No")
return
# S1の中で、最小値が大きい順に並べる
X1 = sorted(S1, key=lambda x: x[2], reverse=True)
# S2の中で、最小値が小さい順に並べる
X2 = sorted(S2, key=lambda x: x[2]-x[1])
T = 0
# X1を並べきった後に、X2を並べて実現可能か調べる、終点を合計して0になることは確認済み
for s, t, mi in X1:
if T + mi < 0:
print("No")
return
T += t
for s, t, mi in X2:
if T + mi < 0:
print("No")
return
T += t
print("Yes")
main()
|
import sys
from collections import deque
H,W=map(int,input().split())
S=list(sys.stdin)
ans=0
for i in range(H):
for j in range(W):
if S[i][j]=='#':
continue
dist=[[-1]*W for _ in range(H)]
dist[i][j]=0
que=deque()
que.append((i,j))
while que:
i,j=que.popleft()
ans=max(ans,dist[i][j])
for ni,nj in (i-1,j),(i,j+1),(i+1,j),(i,j-1):
if not (0<=ni<H and 0<=nj<W):
continue
if S[ni][nj]=='#' or dist[ni][nj]!=-1:
continue
dist[ni][nj]=dist[i][j]+1
que.append((ni,nj))
print(ans)
| 0 | null | 58,976,493,614,570 | 152 | 241 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
st=set()
for i in range(1<<n):
sm=0
for j in range(n):
if (i & (1<<j)):
sm+=a[j]
st.add(sm)
Q=list(map(int,input().split()))
for i in Q:
if i in st:
print("yes")
else:
print("no")
|
def main():
input()
array_a = list(map(int, input().split()))
input()
array_q = map(int, input().split())
def can_construct_q (q, i, sum_sofar):
if sum_sofar == q or sum_sofar + array_a[i] == q:
return True
elif sum_sofar > q or i >= len (array_a) - 1:
return False
if can_construct_q(q, i + 1, sum_sofar + array_a[i]):
return True
if can_construct_q(q, i + 1, sum_sofar):
return True
sum_array_a = sum(array_a)
for q in array_q:
#print(q)
if sum_array_a < q:
print('no')
elif can_construct_q(q, 0, 0):
print('yes')
else:
print('no')
return
main()
| 1 | 102,903,614,300 | null | 25 | 25 |
x=int(input())
i=0
ans=0
while(True):
i+=x
ans+=1
if(i%360==0):
print(ans)
break
|
n, k = map(int, input().split())
m = 0
while True:
m += 1
if k**m > n:
print(m)
break
| 0 | null | 38,902,788,056,748 | 125 | 212 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
A = list(map(int, input().split()))
res = 0
for i in range(60):
cnt = 0
for a in A:
cnt += (a >> i) & 1
res += (cnt * (n - cnt) % mod) * (1 << i) % mod
res %= mod
print(res)
if __name__ == '__main__':
resolve()
|
def main():
S=input()
Q=int(input())
Left=[]
Right=[]
reverse_flag=0
for i in range(Q):
query=input().split()
if query[0]=="1":
if reverse_flag==1:
reverse_flag=0
else:
reverse_flag=1
else:
if query[1]=="1":
if reverse_flag==0:
Left.append(query[2])
else:
Right.append(query[2])
else:
if reverse_flag==0:
Right.append(query[2])
else:
Left.append(query[2])
res=""
if reverse_flag==0:
Left.reverse()
res+="".join(Left)
res+=S
res+="".join(Right)
else:
Right.reverse()
res+="".join(Right)
S=list(S)
S.reverse()
res+="".join(S)
res+="".join(Left)
print(res)
if __name__=="__main__":
main()
| 0 | null | 90,276,285,439,704 | 263 | 204 |
def main():
S, W = map(int, input().split(' '))
if S > W:
print('safe')
else:
print('unsafe')
main()
|
def main():
n = int(input())
while True:
try:
num_list = [int(i) for i in input().split()]
num_list = sorted(num_list)
a,b,c = num_list[0],num_list[1],num_list[2]
if (a**2 + b**2) == c**2:
print("YES")
else:
print("NO")
except EOFError:
break
return None
if __name__ == '__main__':
main()
| 0 | null | 14,478,821,735,940 | 163 | 4 |
n, k = map(int, input().split())
l = list(map(int, input().split()))
for i in range(1, n - k + 1):
print("Yes" if l[i - 1] < l[i + k - 1] else "No")
|
# 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 | 6,260,783,608,362 | 102 | 93 |
from collections import defaultdict
from sys import stdin
input = stdin.readline
def main():
N, X, Y = list(map(int, input().split()))
dic = defaultdict(int)
for l in range(1, N):
for r in range(l+1, N+1):
spath = r - l
if l <= X and Y <= r:
spath -= (Y-X-1)
elif l <= X and X < r <= Y:
spath = min(spath, X-l+1+Y-r)
elif X <= l < Y and Y <= r:
spath = min(spath, l-X+1+r-Y)
elif X < l < Y and X < r < Y:
spath = min(spath, l-X+1+Y-r)
dic[spath] += 1
for k in range(1, N):
print(dic[k])
if(__name__ == '__main__'):
main()
|
def main():
n, x, y = map(int, input().split())
distances = [0 for _ in range(n)]
for i in range(1, n+1):
for j in range(i+1, n+1):
distances[min(j-i, min(abs(i-x)+abs(j-y), abs(j-x)+abs(i-y))+1)] += 1
for v in distances[1:]:
print(v)
if __name__ == '__main__':
main()
| 1 | 44,392,665,973,798 | null | 187 | 187 |
MOD = 10**9+7
n,k = map(int,input().split())
L = [0]*(k+1)
for i in range(k,0,-1):
L[i] = pow(k//i,n,MOD)
for j in range(2,k//i+1):
L[i] -= L[i*j]
ans = 0
for i in range(1,k+1):
ans = (ans + i*L[i]) % MOD
print(ans)
|
import sys
sys.setrecursionlimit(10**6)
def dfs(GF,group,gn,i):
size = 1
group[i]=gn
for node in GF[i]:
if group[node]==-1:
group[node]=gn
size+=dfs(GF,group,gn,node)
return size
def main():
from sys import stdin
n,m,k = map(int,stdin.readline().rstrip().split())
F=[]
for _ in range(m):
F.append(list(map(int,stdin.readline().rstrip().split())))
GF = [[] for _ in range(n+1)]
for a,b in F:
GF[a].append(b)
GF[b].append(a)
B=[]
for _ in range(k):
B.append(list(map(int,stdin.readline().rstrip().split())))
GB = [[] for _ in range(n+1)]
for a,b in B:
GB[a].append(b)
GB[b].append(a)
U = []
group= [-1]*(n+1)
gn = 0
for i in range(1,n+1):
if group[i] == -1:
sz = dfs(GF,group,gn,i)
gn+=1
U.append(sz)
for i in range(1,n+1):
g = group[i]
ans = U[g]-1-len(GF[i])
for b in GB[i]:
if group[b]==g:
ans-=1
print(ans,end=" ")
main()
| 0 | null | 48,945,577,471,692 | 176 | 209 |
#axino's copy
def move(up, bottom, right, left, front, back, direction):
if direction == 'N':
return(front, back, right, left, bottom, up)
elif direction == 'S':
return(back, front, right, left, up, bottom)
elif direction == 'E':
return(left, right, up, bottom, front, back)
elif direction == 'W':
return(right, left, bottom, up, front, back)
def check(up, bottom, right, left, front, back, up_current, front_current):
if front_current == front and up_current == up:
print(right)
elif front_current == front:
if left == up_current:
print(up)
elif bottom == up_current:
print(left)
elif right == up_current:
print(bottom)
elif up_current == up:
if right == front_current:
print(back)
elif back == front_current:
print(left)
elif left == front_current:
print(front)
else:
up, bottom, right, left, front, back = move(up, bottom, right, left, front, back, 'S')
check(up, bottom, right, left, front, back, up_current, front_current)
up, front, right, left, back, bottom = input().split()
times = int(input())
for i in range(times):
up_current, front_current = input().split()
check(up, bottom, right, left, front, back, up_current, front_current)
|
H,W,N = map(int, open(0).read().split())
ans = 0
while N > 0:
A = max(H, W)
tmp = N // A
N = N % A
if tmp == 0 and N:
N = 0
ans += 1
break
if H == A:
W -= tmp
else:
H -= tmp
ans += tmp
print(ans)
| 0 | null | 44,676,785,617,322 | 34 | 236 |
def resolve():
N = int(input())
import math
print(math.ceil(N/2))
if '__main__' == __name__:
resolve()
|
n = int(input())
ans = n // 2
ans += 1 if n % 2 != 0 else 0
print(ans)
| 1 | 58,984,427,338,880 | null | 206 | 206 |
import sys
alpha = 'abcdefghijklmnopqrstuvwxyz'
dic = {c:0 for c in alpha}
t = sys.stdin.read()
for s in t:
s = s.lower()
if s in alpha:
dic[s] += 1
for i in sorted(dic):
print("{} : {}".format(i,dic[i]))
|
A,B=map(int,input().split())
if 10>A>0 and 10>B>0:
print(A*B)
else:
print(-1)
| 0 | null | 79,880,881,016,650 | 63 | 286 |
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
if N == 1:
print("a")
else:
S = list("abcdefghij")
Q = deque([("a",1)]) #文字列、種類
while len(Q) != 0:
s,kind = Q.popleft()
for i in range(kind+1):
news = s+S[i]
if len(news) == N+1:
break
if len(news) == N:
print(news)
if i == kind:
Q.append((news,kind+1))
else:
Q.append((news,kind))
|
def DFS(word,N):
if len(word)==n:print(word)
else:
for i in range(N+1):
DFS(word+chr(97+i),N+1 if i==N else N)
n=int(input())
DFS("",0)
| 1 | 52,695,743,833,822 | null | 198 | 198 |
from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for i, bi in enumerate(BIT, 1):
if bi == 1:
LIST.append(tmp)
tmp = s[i]
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, s[i])]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
CNT, tmp = 0, [li[0] for li in LIST]
if any(num > k for num in tmp):
return h * w
for j in range(1, w):
cal = [t + li[j] for t, li in zip(tmp, LIST)]
if any(num > k for num in cal):
CNT += 1
tmp = [li[j] for li in LIST]
else:
tmp = cal
return CNT
h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
|
from collections import defaultdict
H,W,K = map(int,input().split())
S = [0] * H
for i in range(H):
S[i] = input()
INF = H + W - 2
def bi(x):
global H
o = [0]*(H-1)
i = 0
while x != 0:
o[i] = x % 2
i += 1
x //= 2
return o
def hoge(n):
global K
b = bi(n)
d = defaultdict(set)
j = 0
for i in range(H):
d[j].add(i)
if i == H - 1:
break
if b[i]:
j += 1
dlen = len(d)
T = [0]*dlen
for k,V in d.items():
T[k] = [0]*W
for i in range(W):
for v in V:
T[k][i] += int(S[v][i])
if T[k][i] > K:
return INF
ans = dlen - 1
U = [T[x][0] for x in range(dlen)]
for i in range(1,W):
flag = 0
for k in range(dlen):
U[k] += T[k][i]
if U[k] > K:
flag = 1
if flag == 1:
ans += 1
for k in range(dlen):
U[k] = T[k][i]
return ans
ANS = INF
for i in range(2**(H-1)):
ANS = min(ANS,hoge(i))
print(ANS)
| 1 | 48,571,423,789,476 | null | 193 | 193 |
import math
k = int(input())
ans = "NG"
pi = math.pi
print(2*k*pi)
|
N,K=input().split()
N=int(N)
K=int(K)
ls=[int(s) for s in input().split()]
count=0
for i in range(N):
if ls[i]>=K:
count=count+1
print(count)
| 0 | null | 105,143,236,697,800 | 167 | 298 |
str_num = input()
num_list = str_num.split()
answer = int(num_list[0]) * int(num_list[1])
print(answer)
|
N, D = map(int,input().split())
cnt = 0
for i in range(N):
X,Y = map(int,input().split())
S = (X**2+Y**2)**0.5
if S <= D:
cnt += 1
else:
continue
print(cnt)
| 0 | null | 10,948,096,268,088 | 133 | 96 |
A, B, C = list(map(int, input().split()))
K = int(input())
while(B <= A):
B *= 2
K -= 1
while(C <= B):
C *= 2
K -= 1
if(K >= 0): print("Yes")
else: print("No")
|
from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
g=reduce(gcd,a)
if g!=1:
print("not coprime")
exit()
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n // g): return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i*i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += 1 + i % 2
if i == 101 and n >= 2 ** 20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
return ret
def primes(x):
ret=[]
for i in range(1,int(x**0.5)+1):
if x%i==0:
ret.append(i)
if x//i!=i:
ret.append(x//i)
ret.sort()
return ret[1:]
d=defaultdict(int)
for q in a:
#p=primeFactor(q)
p=primes(q)
for j in p:
if d[j]==1:
print("setwise coprime")
exit()
d[j]+=1
print("pairwise coprime")
| 0 | null | 5,577,842,130,788 | 101 | 85 |
def gcd(x,y):
if x%y!=0:
return gcd(y,x%y)
else:
return y
def GCD(x,y,z):
return gcd(gcd(x,y),z)
ans=0
K=int(input())
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
ans+=GCD(a,b,c)
print(ans)
|
N,K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
ans = 0
for i in range(N):
if K <= H[i]:
ans += 1
print(ans)
| 0 | null | 106,781,048,912,484 | 174 | 298 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
lis = list(range(1,n+1))
a,b = None,None
P = readInts()
Q = readInts()
i = 0
for A in permutations(lis,n):
if list(A) == P == Q:
a,b = i,i
elif list(A) == Q:
b = i
elif list(A) == P:
a = i
i += 1
print(abs(a-b))
|
from itertools import permutations as p
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
j = 0
for i in p(range(1, N + 1)):
j += 1
if i == P: a = j
if i == Q: b = j
if a - b >= 0: print(a - b)
else: print(b - a)
| 1 | 100,335,887,953,972 | null | 246 | 246 |
def digitsum(n):
res = 0
for i in n:
#print(ni)
ni = int(i)
res += ni
return res
s = input()
r = digitsum(s)
if r % 9 == 0:
print("Yes")
else:
print("No")
|
m = input("")
s = m.split(".")
sum = 0
if len(s) == 1 and int(m)>=0 and int(m)<10**200000:
for i in m :
sum = sum+int(i)
if sum % 9 == 0:
print("Yes")
else:
print("No")
| 1 | 4,389,438,624,802 | null | 87 | 87 |
import sys
input = sys.stdin.readline
K, X = map(int, input().split())
print('Yes' if X <= 500 * K else 'No')
|
import sys
import os
MOD = 10 ** 9 + 7
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
K, X = list(map(int, sys.stdin.buffer.readline().split()))
print('Yes' if K*500 >= X else 'No')
if __name__ == '__main__':
main()
| 1 | 98,116,113,674,610 | null | 244 | 244 |
def insertionSort(n, A, g):
global cnt
for i in range(g, n):
temp = A[i]
j = i - g
while j >= 0 and A[j] > temp:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = temp
return A
def shellSort(A, n):
global m
global G
h = 1
while True:
if h > n:
break
G.append(h)
h = 3 * h + 1
G.reverse()
m =len(G)
for i in range(m):
insertionSort(n, A, G[i])
if __name__ == "__main__":
n = int(input())
A = [int(input()) for i in range(n)]
G = []
m = 0
cnt = 0
shellSort(A, n)
print(m)
print(*G)
print(cnt)
for i in range(n):
print(A[i])
|
cnt = 0
def insertionsort(A,n,g):
global cnt
for i in range(g,n):
v = A[i]
j = i-g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
def shellsort(A,n):
h = 1
G = []
while h <= len(A):
G.append(h)
h = h*3+1
G.reverse()
m = len(G)
for i in range(m):
insertionsort(A,n,G[i])
return m,G
def main():
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
m,G = shellsort(A,n)
##print("-----------")
print(m)
print(*G)
print(cnt)
for i in A:
print(i)
if __name__ == "__main__":
main()
| 1 | 31,366,980,262 | null | 17 | 17 |
H, N = map(int, input().split())
As = list(map(int, input().split()))
sumA = sum(As)
if sumA >= H:
print('Yes')
else:
print('No')
|
import sys
def main():
sec = int(sys.stdin.readline())
hour = int(sec / 3600)
sec = sec % 3600
minute = int(sec / 60)
sec = sec % 60
print("{0}:{1}:{2}".format(hour,minute,sec))
return
if __name__ == '__main__':
main()
| 0 | null | 39,054,334,640,508 | 226 | 37 |
print('No' if input().replace('hi', '') else 'Yes')
|
n = input()
print("Yes" if n == "hi" * (len(n)// 2) else "No")
| 1 | 53,271,602,124,142 | null | 199 | 199 |
from collections import deque
que = deque()
n = int(input())
for _ in range(n):
command = input()
if command == 'deleteFirst':
que.popleft()
elif command == 'deleteLast':
que.pop()
else:
x, y = command.split()
if x == 'insert':
que.appendleft(int(y))
elif int(y) in que:
que.remove(int(y))
print(' '.join(map(str, que)))
|
from collections import deque
n = int(input())
dq = deque()
for _ in range(n):
query = input()
if query == "deleteFirst":
dq.popleft()
elif query == "deleteLast":
dq.pop()
else:
op, arg = query.split()
if op == "insert":
dq.appendleft(arg)
else:
tmp = deque()
while dq:
item = dq.popleft()
if item == arg:
break
else:
tmp.append(item)
while tmp:
dq.appendleft(tmp.pop())
print(*dq)
| 1 | 51,298,946,130 | null | 20 | 20 |
n = int(input())
a = list(map(int, input().split()))
tmp = 0
sum = 0
for i in a:
if tmp > i:
dif = tmp - i
sum += dif
else:
tmp = i
print(sum)
|
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
now = A[0]
for a in A:
if now > a:
ans += now -a
if now < a:
now = a
print(ans)
| 1 | 4,548,075,121,900 | null | 88 | 88 |
x=int(input())
y=str(input())
if len(y) > x:
print(y[:x] + '...')
else:
print(y)
|
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
print(k)
exit()
ans += a
k -= a
if b >= k:
print(ans)
exit()
k -= b
ans -= k
print(ans)
| 0 | null | 20,774,976,135,250 | 143 | 148 |
X, Y = map(int, input().split())
MOD = 10**9+7
def mod_pow(n, m):
res = 1
while m > 0:
if m & 1:
res = (res*n)%MOD
n = (n*n)%MOD
m >>= 1
return res
if (2*Y-X)%3 != 0 or (2*X-Y)%3 != 0 or 2*Y < X or 2*X < Y:
print(0)
else:
A = (2*X-Y)//3
B = (2*Y-X)//3
m = 1
n = 1
for i in range(A):
m = (m*(A+B-i))%MOD
n = (n*(A-i))%MOD
inverse_n = mod_pow(n, MOD-2)
print((m*inverse_n)%MOD)
|
import math
x = math.pi
r = float(input())
ans = r*2*x
print(ans)
| 0 | null | 91,104,011,975,680 | 281 | 167 |
n=int(input())
l=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
a=int(input())
for j in range(a):
x,y = map(int,input().split())
l[i][x-1]=y
ans=0
for i in range(2**n):
d=[0 for x in range(n)]
for j in range(n):
if i>>j & 1:
d[j]=1
flag=1
for j in range(n):
for s in range(n):
if d[j]==1:
if l[j][s]==-1:
continue
if l[j][s]!=d[s]:
flag=0
break
if flag:
ans=max(ans,sum(d))
print(ans)
|
N=int(input())
D=[{} for _ in range(N+1)]
for i in range(1,N+1):
A=int(input())
for k in range(A):
p,x=map(int,input().split())
D[i][p]=x
Max=0
for x in range(2**N):
y=x
B=["*"]*(N+1)
for i in range(N):
B[i+1]=y%2
y>>=1
Flag=True
for i in range(1,N+1):
if B[i]==1:
for k in D[i]:
Flag&=(B[k]==D[i][k])
if Flag:
Max=max(Max,B.count(1))
print(Max)
| 1 | 121,137,865,869,008 | null | 262 | 262 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, ABs):
tree_top = [[] for _ in range(N + 1)]
for i in range(N - 1):
tree_top[ABs[i][0]].append(i)
tree_top[ABs[i][1]].append(i)
max_color = 0
for tt in tree_top:
max_color = max(max_color, len(tt))
ans = [0 for _ in range(N - 1)]
for tt in tree_top:
colored = []
for i in tt:
if ans[i] != 0:
colored.append(ans[i])
colored.sort()
now_color = 1
colored_point = 0
for i in tt:
if ans[i] != 0:
continue
if colored_point < len(colored) \
and now_color == colored[colored_point]:
now_color += 1
colored_point += 1
ans[i] = now_color
now_color += 1
print(max_color)
for a in ans:
print(a)
if __name__ == '__main__':
# S = input()
N = int(input())
# N, M = map(int, input().split())
# As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
ABs = [[int(i) for i in input().split()] for _ in range(N - 1)]
solve(N, ABs)
|
import collections
n = int(input())
adj_list = []
for _ in range(n):
adj = list(map(int, input().split(" ")))
adj_list.append([c - 1 for c in adj[2:]])
distances = [-1 for _ in range(n)]
queue = collections.deque()
queue.append(0)
distances[0] = 0
while queue:
p = queue.popleft()
for next_p in adj_list[p]:
if distances[next_p] == -1:
distances[next_p] = distances[p] + 1
queue.append(next_p)
for i in range(n):
print(i+1, distances[i])
| 0 | null | 68,249,185,216,392 | 272 | 9 |
import math
import sys
import bisect
import array
m=10**9 + 7
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split()))
# print(N,K,A)
B = list( map(lambda x: x % K, A))
C = [0]
x = 0
i = 0
for b in B:
x = (x + b ) % K
C.append((x-i-1) % K)
i += 1
# print(B,C)
E={}
ans=0
for i in range(N+1):
if C[i] in E:
ans += E[C[i]]
E[C[i]] = E[C[i]] + 1
else:
E[C[i]] = 1
if i >= K-1:
E[C[i-K+1]] = E[C[i-K+1]] - 1
if E[C[i-K+1]] == 0:
E.pop(C[i-K+1])
print(ans)
exit(0)
|
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
q = deque()
for i in acc_a:
if i not in count:
count[i] = 0
ans += count[i]
count[i] += 1
q.append(i)
if len(q) == k:
count[q.popleft()] -= 1
print(ans)
| 1 | 137,565,375,743,070 | null | 273 | 273 |
h = -1
w = -1
while (h != 0) and (w != 0):
input = map(int, raw_input().split(" "))
h = input[0]
w = input[1]
if (h == 0 and w == 0):
break
i = 0
j = 0
line = ""
while j < w:
line += "#"
j += 1
while i < h:
print line
i += 1
print ""
|
while 1:
H , W = map(int, raw_input().split())
if H == 0 and W == 0:
break
for l in range(0,H):
print '#' * W
print
| 1 | 761,214,879,140 | null | 49 | 49 |
N = list(input())
for i in N:
if i == "7":
print("Yes")
exit()
print("No")
|
N = input ()
if N.count ('7') != 0:
print ('Yes')
else:
print ('No')
| 1 | 34,349,174,613,578 | null | 172 | 172 |
#!/usr/bin/env python3
import sys
def main():
input = sys.stdin.readline
d, t, s = map(int, input().split())
if d / s <= t:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
|
N = int(input())
A = list(map(int, input().split()))
print("APPROVED" if all(a&1 or (a%3==0 or a%5==0) for a in A) else "DENIED")
| 0 | null | 36,247,294,625,148 | 81 | 217 |
# E - Colorful Hats 2
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
count = [0]*N+[3]
used = [0]*(N+1)
ans = 1
for x in A:
ans = (ans*(count[x-1]-used[x-1]))%MOD
count[x] += 1
used[x-1] += 1
print(ans)
|
A, B, C = map(int, input().split())
K = int(input())
k = 0
while True:
if A < B < C:
print("Yes")
break
else:
if k == K:
print("No")
break
if B <= A:
B *= 2
elif C <= B:
C *= 2
k += 1
| 0 | null | 68,368,636,376,920 | 268 | 101 |
# Sheep and Wolves
S, W = map(int, input().split())
print(['safe', 'unsafe'][W >= S])
|
def main():
S, W = map(int, input().split())
un = "un" if W >= S else ""
print(un + "safe")
if __name__ == "__main__":
main()
| 1 | 29,342,092,874,732 | null | 163 | 163 |
from functools import reduce
from math import gcd
N=int(input())
A=list(map(int, input().split()))
c=max(A)+1
D=[0]*c
div=[0]*c
P=[]
for i in range(2,c):
if D[i]==0:
P.append(i)
D[i]=i
for j in P:
if i*j>=c or j>D[i] :
break
D[i*j]=j
f=0
for i in A:
if i==1:
continue
temp=i
while temp!=1:
if div[D[temp]]==1:
f=1
break
div[D[temp]]+=1
temp2=D[temp]
while temp%temp2==0 and temp>=temp2:
temp=temp//temp2
if f==1:
break
if max(div)<=1 and f==0:
print('pairwise coprime')
elif reduce(gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
|
from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
if reduce(gcd,a)!=1:
print("not coprime")
exit()
def primes(x):
ret=[]
for i in range(1,int(x**0.5)+1):
if x%i==0:
ret.append(i)
if x//i!=i:
ret.append(x//i)
ret.sort()
return ret[1:]
s=set()
for q in a:
p=primes(q)
for j in p:
if j in s:
print("setwise coprime")
exit()
s.add(j)
print("pairwise coprime")
| 1 | 4,149,737,745,582 | null | 85 | 85 |
l = input().split()
q = []
for e in l:
if e == '+':
q.append(q.pop() + q.pop())
elif e == '-':
q.append(-q.pop() + q.pop())
elif e == '*':
q.append(q.pop() * q.pop())
else:
q.append(int(e))
print(q[0])
|
n = int(input())
dp = [0 for _ in range(46)]
dp[0] = 1
dp[1] = 1
for i in range(2, 46):
dp[i] = dp[i-1] + dp[i-2]
print(dp[n])
| 0 | null | 19,409,833,640 | 18 | 7 |
num_freebies = int(input())
freebies = []
for _ in range(num_freebies):
freebies.append(input())
print(len(set(freebies)))
|
n = int(input())
s = [input() for _ in range(n)]
uniq = set(s)
print(len(uniq))
| 1 | 30,297,960,172,678 | null | 165 | 165 |
N = int(input())
ST = [list(input().split()) for _ in [0]*N]
X = input()
ans = 0
for i,st in enumerate(ST):
s,t = st
if X==s:
break
for s,t in ST[i+1:]:
ans += int(t)
print(ans)
|
n = int(input())
d = {}
t = [0]*n
for i in range(n):
S,T = input().split()
d[S] = i
t[i] = int(T)
x = input()
idx = d[x]
print(sum(t[idx+1:]))
| 1 | 97,302,236,699,360 | null | 243 | 243 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = [a%K for a in A]
cs = [0]
for b in B:
c = (cs[-1] + b-1) % K
cs.append(c)
from collections import deque
from collections import defaultdict
qs = defaultdict(lambda: deque())
ans = 0
for i,c in enumerate(cs):
while qs[c] and qs[c][0] + K <= i:
qs[c].popleft()
ans += len(qs[c])
qs[c].append(i)
print(ans)
|
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions import gcd
#input=sys.stdin.readline
#import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
def lcm(a,b):
g=math.gcd(a,b)
return b*(a//g)
l=a[0]//2
for i in range(n):
r=a[i]//2
l=lcm(l,r)
for i in range(n):
if (l//(a[i]//2))%2==0:
print(0)
exit()
res=m//l
print((res+1)//2)
| 0 | null | 119,610,972,069,738 | 273 | 247 |
# !/usr/bin/python3
"""
https://atcoder.jp/contests/abc151/tasks/abc151_c
Welcome at atcoder
"""
if __name__ == "__main__":
n, m = list(map(int, input().split()))
accepted = [False for _ in range(n+5)]
wrong = [0 for _ in range(n+5)]
ac = wa = 0
for _ in range(m):
p, s = input().split()
p = int(p)
if accepted[p]: continue
elif s == "WA": wrong[p] += 1
elif s == "AC":
ac += 1
wa += wrong[p]
accepted[p] = True
print(f"{ac} {wa}")
|
n,m=map(int,input().split())
ps=[list(input().split()) for _ in range(m)]
wa=[0]*n
w=0
ac=0
d=[0]*n
for p,s in ps:
if s=='WA':
if d[int(p)-1]==0:
wa[int(p)-1]+=1
else:
if d[int(p)-1]==0:
ac+=1
d[int(p)-1]=1
w+=wa[int(p)-1]
print(ac,w)
| 1 | 93,312,207,648,000 | null | 240 | 240 |
if __name__ == '__main__':
n = input().split()
c = input().split()
dp = [50000] * (int(n[0]) + 1)
for i in range(int(n[1])):
if int(c[i]) > int(n[0]):
continue
dp[int(c[i])] = 1
for j in range(int(n[0])):
if int(c[i])+j > int(n[0]):
break;
if dp[j] != 50000:
dp[int(c[i])+j] = min(dp[int(c[i])+j], dp[j]+1)
print (dp[int(n[0])])
|
n,m = map(int,input().split())
C = list(map(int,input().split()))
INF = 50010
dp = [[INF]*(n+1) for _ in range(m+1)]
for i in range(m):
dp[i+1][0] = 0
for j in range(1,n+1):
if j-C[i] >= 0:
dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j])
else:
dp[i+1][j] = dp[i][j]
print(dp[m][n])
| 1 | 143,666,679,210 | null | 28 | 28 |
s = input()
t = s[::-1]
n = len(s)
resid = [0] * 2019
resid[0] = 1
csum = 0
powoften = 1
for i in range(n):
csum = (csum + int(t[i]) * powoften) % 2019
powoften = (10 * powoften) % 2019
resid[csum] += 1
ans = 0
for i in range(2019):
ans += resid[i] * (resid[i] - 1) // 2
print(ans)
|
from collections import Counter
S = input()
L = len(list(S))
dp = [0] * L
dp[0] = 1
T = [0] * L
T[0] = int(S[-1])
for i in range(1, L):
dp[i] = dp[i - 1] * 10
dp[i] %= 2019
T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1]
T[i] %= 2019
ans = 0
for k, v in Counter(T).items():
if k == 0:
ans += v
ans += v * (v - 1) // 2
else:
ans += v * (v - 1) // 2
print(ans)
| 1 | 30,936,057,413,920 | null | 166 | 166 |
for i in range(1, 10):
for j in range(1, 10):
print(f"{i}x{j}={i * j}")
|
a = 1
while a<10:
b=1
while b<10:
print(str(a)+'x'+str(b)+'='+str(a*b))
b=b+1
a=a+1
| 1 | 1,441,872 | null | 1 | 1 |
h = int(input())
cnt = 1
if h == 1:
print(1)
exit()
while(True):
cnt += 1
h = int(h / 2)
if h == 1:
break
print(2 ** cnt - 1)
|
n = int(input())
al = list(map(int, input().split()))
num_cnt = {}
c_sum = 0
for a in al:
num_cnt.setdefault(a,0)
num_cnt[a] += 1
c_sum += a
ans = []
q = int(input())
for _ in range(q):
b,c = map(int, input().split())
num_cnt.setdefault(b,0)
num_cnt.setdefault(c,0)
diff = num_cnt[b]*c - num_cnt[b]*b
num_cnt[c] += num_cnt[b]
num_cnt[b] = 0
c_sum += diff
ans.append(c_sum)
for a in ans:
print(a)
| 0 | null | 46,164,794,711,260 | 228 | 122 |
import math
N, K = map(int, input().split())
if N != 1:
res = math.log(N, K)
else:
res = 1
print(math.ceil(res))
|
N, K = map(int, input().split(' '))
cnt = 0
while N:
N //= K
cnt += 1
print(cnt)
| 1 | 64,506,188,550,606 | null | 212 | 212 |
n=int(input())
if n<3:
print(0)
elif n%2==0:
print(int((n/2)-1))
else:
print(int(n//2))
|
f=lambda:[*map(int,input().split())]
n,k=f()
p,c=f(),f()
p=[i-1 for i in p]
a=-10**9
for i in range(n):
x,l,s,t=i,[],0,0
while 1:
x=p[x]
l+=[c[x]]
s+=c[x]
if x==i: break
m=len(l)
for j in range(m):
if j+1>k: break
t+=l[j]
a=max(a,t+(k-j-1)//m*s*(s>0))
print(a)
| 0 | null | 79,008,166,053,040 | 283 | 93 |
# Python 3
if __name__ == "__main__":
a, b, c = input().split()
a, b, c = int(a), int(b), int(c)
count = 0
for i in range(a, b + 1):
if c % i == 0:
count += 1
print(count)
|
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
d={'r':p,'s':r,'p':s}
d_={'r':'p','s':'r','p':'s'}
s=0
for i in range(k):
a=0
z='0'
t_=t[i::k]
for a in range(len(t_)):
if a==0:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
else:
if z==d_[t_[a]]:
z='0'
a+=1
else:
s+=d[t_[a]]
z=d_[t_[a]]
a+=1
print(s)
| 0 | null | 53,820,759,691,830 | 44 | 251 |
s = input()
t = len(s)
x = []
y = 0
while 10 ** y % 2019 not in x:
x.append(10 ** y % 2019)
y += 1
z = len(x)
m = [0 for i in range(2019)]
m[0] = 1
a = 0
for i in reversed(range(0, t)):
a += x[(t-i-1) % z] * (int(s[i]) % 2019)
a = a % 2019
m[a] += 1
def triangle(n):
if n > 1:
return n * (n-1) // 2
else:
return 0
p = list(map(triangle, m))
# print(p)
print(sum(p))
|
import sys
input=lambda: sys.stdin.readline().rstrip()
S=input()
n=len(S)
D=[0]*2019
T=[0]*(n+1)
T[0]=1
for i in range(n):
T[i+1]=(T[i]*10)%2019
cur=0
keta=0
ans=0
D[0]+=1
for s in S[::-1]:
cur=(cur+int(s)*T[keta])%2019
ans+=D[cur]
D[cur]+=1
keta+=1
print(ans)
| 1 | 30,800,793,134,960 | null | 166 | 166 |
import math
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
x = int(input())
lcm = lcm_base(360, x)
print(lcm//x)
|
def main():
s = input()
ans = 'x' * len(s)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 42,975,919,327,018 | 125 | 221 |
a = int(input())
b = int(input())
d = {}
d[a] = True
d[b] = True
for i in range(1, 4):
if i not in d:
print(i)
|
n=int(input())
a=list(map(int,input().split()))
ans=[x for x in range(n)]
for i in range(n):
ans[(a[i] - 1)] = i + 1
for aaa in ans:
print(aaa)
| 0 | null | 145,469,860,001,930 | 254 | 299 |
import itertools
n = int(input())
d = list(map(int, input().split()))
lst = list(itertools.combinations(d, 2))
ans = 0
for i in lst:
a = i[0] * i[1]
ans += a
print(ans)
|
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(input())
s = [0] * n
t = [0] * n
for i in range(n):
s[i], t[i] = input().split()
t[i] = int(t[i])
x = input()
idx = s.index(x)
ans = 0
for i in range(idx+1, n):
ans += t[i]
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 132,446,306,270,076 | 292 | 243 |
from collections import deque
n = int(input())
answer = deque()
for i in range(n):
command = input()
if " " in command:
command, key = command.split()
if command == "insert":
answer.appendleft(key)
elif command == "delete":
if key in answer:
answer.remove(key)
elif command == "deleteFirst":
answer.popleft()
elif command == "deleteLast":
answer.pop()
print(*answer)
|
n,k=map(int,input().split())
mod=10**9+7
ans=1
#Combination 1 O()
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
comb=Combination(10**6)
if n-1<=k:
print(comb(2*n-1,n)%mod)
else:
for i in range(1,k+1):
ans+=(comb(n,i)*comb(n-1,i))
ans%=mod
print(ans%mod)
| 0 | null | 33,362,755,474,708 | 20 | 215 |
L,R,d=map(int,input().split())
ans=0
for i in range(L,R+1):
if i%d==0:
ans+=1
print(ans)
|
a = list(map(int, input().rstrip().split()))
resto=a[0]%a[-1]
if resto >0:
o = a[0]+a[-1]- resto
else:
o= a[0]
print((a[1]-o)//a[-1]+1)
| 1 | 7,536,065,384,484 | null | 104 | 104 |
n,k=map(int,input().split());n,c=set(range(1,n+1)),set()
for i in range(k):
input();c|=set(map(int,input().split()))
print(len(n^c))
|
N = input()
s1 = []
s2 = []
res = []
ans = []
cnt = 0
for i in range(len(N)):
if N[i] == "\\":
s1.append(i)
elif N[i] == "/" and s1:
idx = s1.pop()
tmp = i - idx
cnt += tmp
while s2 and idx < s2[-1][0]:
tmp += s2.pop()[1]
s2.append((idx, tmp))
res.append(len(s2))
for i in range(len(s2)):
ans.append(s2[i][1])
res.extend(ans)
print(cnt)
print(" ".join(map(str, res)))
| 0 | null | 12,390,880,006,274 | 154 | 21 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def solve():
N, X, M = map(int, input().split())
if N == 1:
print(X)
return
A = X
steps = [0] * M
sms = [0] * M
steps[A] = 1
sms[A] = A
sm = A
ans = A
rest = 0
for i in range(2, N+1):
A = (A*A) % M
sm += A
ans += A
if steps[A] != 0:
P = i - steps[A]
v = sm - sms[A]
rest = N - i
ans += v * (rest//P)
rest %= P
break
steps[A] = i
sms[A] = sm
for i in range(rest):
A = (A*A) % M
ans += A
print(ans)
solve()
|
# -*- coding: utf-8 -*-
N, X, M = map(int, input().split())
mod_check_list = [False for _ in range(M)]
mod_list = [(X ** 2) % M]
counter = 1
mod_sum = (X ** 2) % M
last_mod = 0
for i in range(M):
now_mod = (mod_list[-1] ** 2) % M
if mod_check_list[now_mod]:
last_mod = now_mod
break
mod_check_list[now_mod] = True
mod_list.append(now_mod)
counter += 1
mod_sum += now_mod
loop_start_idx = 0
for i in range(counter):
if last_mod == mod_list[i]:
loop_start_idx = i
break
loop_list = mod_list[loop_start_idx:]
loop_num = counter - loop_start_idx
ans = 0
if (N - 1) <= counter:
ans = X + sum(mod_list[:N - 1])
else:
ans += X + mod_sum
N -= (counter + 1)
ans += sum(loop_list) * (N // loop_num) + sum(loop_list[:N % loop_num])
print(ans)
| 1 | 2,790,401,427,452 | null | 75 | 75 |
import math
n = int(input())
xlist = list(map(float, input().split()))
ylist = list(map(float, input().split()))
#x, y = [list(map(int, input().split())) for _ in range(2)] 로 한방에 가능
print(sum(abs(xlist[i] - ylist[i]) for i in range(n)))
print(pow(sum(abs(xlist[i] - ylist[i]) ** 2 for i in range(n)),0.5))
print(pow(sum(abs(xlist[i] - ylist[i]) ** 3 for i in range(n)),1/3))
print(max(abs(xlist[i] - ylist[i])for i in range(n)))
|
n = int(input())
a = [(_a, i) for i, _a in enumerate(map(int, input().split()))]
a.sort(reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
for i, (v, p) in enumerate(a):
# 前にj人いる
dp[i+1][0] = dp[i][0] + v*abs((n-1 - i) - p)
for j in range(1, i+1):
dp[i+1][j] = max(dp[i][j] + v*abs((n-1 - (i-j)) - p),
dp[i][j-1] + v*abs((j-1) - p))
dp[i+1][i+1] = dp[i][i] + v*abs(i - p)
print(max(dp[n]))
| 0 | null | 16,820,016,488,472 | 32 | 171 |
while True:
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
kei = 0
for p in s:
kei += p
m = kei / n
a = 0
for p in s:
a += ((p - m)**2) / n
import math
h = math.sqrt(a)
print(h)
|
import math
while True:
n = int(input())
if n == 0: break
s = list(map(int,input().split()))
dis = 0
mean = sum(s)
mean /= n
for s in s:
dis += (s-mean)**2
print('{0:.5f}'.format(math.sqrt(dis/n)))
| 1 | 194,761,681,600 | null | 31 | 31 |
n,t = map(int,input().split())
L = []
for i in range(n):
a,b = map(int,input().split())
L.append([a,b])
dp1 = [[0 for i in range(t)] for i in range(n+1)]
dp2 = [[0 for i in range(t)] for i in range(n+1)]
for i in range(n):
a = L[i][0]
b = L[i][1]
for j in range(t):
if j-a >= 0:
dp1[i+1][j] = max(dp1[i][j], dp1[i][j-a]+b, dp1[i+1][j])
else:
dp1[i+1][j] = max(dp1[i][j],dp1[i+1][j])
for i in range(n):
a = L[n-i-1][0]
b = L[n-i-1][1]
if i == 0:
for j in range(a, t):
dp2[n-i-1][j] = b
else:
for j in range(t):
if j-a >= 0:
dp2[n-i-1][j] = max(dp2[n-i][j], dp2[n-i][j-a]+b,dp2[n-i-1][j])
else:
dp2[n-i-1][j] = max(dp2[n-i-1][j], dp2[n-i][j])
ans = 0
for i in range(1,n+1):
for j in range(t):
ans = max(ans, dp1[i-1][j]+dp2[i][t-1-j]+L[i-1][1])
print(ans)
|
N,M=map(int,input().split())
par=[i for i in range(N)]
size=[1 for i in range(N)]
def find(x):
if par[x]==x:
return x
else:
par[x]=find(par[x])
return par[x]
def union(a,b):
x=find(a)
y=find(b)
if x!=y:
if size[x]<size[y]:
par[x]=par[y]
size[y]+=size[x]
else:
par[y]=par[x]
size[x]+=size[y]
else:
return
for i in range(M):
a,b=map(int,input().split())
union(a-1,b-1)
print(max(size))
| 0 | null | 77,796,461,944,092 | 282 | 84 |
N = int(input())
S = input()
if S == S[:N//2]*2:
print("Yes")
else:
print("No")
|
def main():
""""ここに今までのコード"""
H = int(input())
Count, atk = 1,1
while H > atk * 2 - 1:
atk = atk * 2
Count = Count * 2 + 1
print(Count)
if __name__ == '__main__':
main()
| 0 | null | 113,543,316,732,230 | 279 | 228 |
n = [int(i) for i in input().split()]
print(max(n[0] - 2*n[1], 0))
|
A,B = (int(a) for a in input().split())
ans = A - B * 2
print(max(0,ans))
| 1 | 165,980,522,521,406 | null | 291 | 291 |
# encoding:utf-8
import math as ma
# math.pi
x = float(input())
pi = (x * x) * ma.pi
# Circumference
pi_line = (x + x) * ma.pi
print("{0} {1}".format(pi,pi_line))
|
r=float(input())
pi=3.141592653589793238
print(pi*r**2,2*pi*r)
| 1 | 635,828,165,700 | null | 46 | 46 |
n=int(input())
T,H=0,0
for i in range(n):
t_card,h_card=input().split()
if t_card>h_card:
T+=3
elif t_card<h_card:
H+=3
else:
T+=1
H+=1
print(str(T)+" "+str(H))
|
X, N = map(int, input().split())
P = list(map(int, input().split()))
st = set(P)
ans = 111
for i in range(111):
if i in st:
continue
if abs(ans - X) > abs(i - X):
ans = i
print(ans)
| 0 | null | 8,108,989,980,260 | 67 | 128 |
N = int(input())
B = input().split()
S = B[:]
for i in range(N):
for j in range(N-1, i, -1):
if B[j][1] < B[j-1][1]:
B[j], B[j-1] = B[j-1], B[j]
m = i
for j in range(i, N):
if S[m][1] > S[j][1]:
m = j
S[m], S[i] = S[i], S[m]
print(*B)
print('Stable')
print(*S)
print(['Not s', 'S'][B==S] + 'table')
|
import math
x = int(input())
a = 100
cnt = 0
while(1):
cnt += 1
a += a//100
if a >= x:
break
print(cnt)
| 0 | null | 13,529,917,478,752 | 16 | 159 |
from collections import deque
N, D, A = map(int, input().split())
monsters = []
for _ in range(N):
monsters.append(list(map(int, input().split())))
monsters.sort()
d = deque()
ans = 0
damage = 0
for x, h in monsters:
while d:
if d[0][0] >= x - D:
break
_, power = d.popleft()
damage -= power
h -= damage
if h <= 0:
continue
attack = (h - 1) // A + 1
ans += attack
d.append((x + D, attack * A))
damage += attack * A
print(ans)
|
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
logs_S = [0, ]
ans = 0
for i, enemy in enumerate(enemies):
X, hp = enemy
start_i = b_left(logs, X-2*D)
count = logs_S[-1] - logs_S[start_i]
hp -= count * A
if hp > 0:
attack_num = (hp + A-1) // A
logs.append(X)
logs_S.append(logs_S[-1]+attack_num)
ans += attack_num
print(ans)
| 1 | 82,642,513,770,528 | null | 230 | 230 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.