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
|
---|---|---|---|---|---|---|
n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0
if p == 2 or p == 5:
for i, x in enumerate(s):
if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)):
ans += i+1
print(ans)
exit()
s.reverse()
cum = [0] * (n+1)
for i in range(n):
cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1
for x in t:
ans += x * (x-1) // 2
print(ans)
|
from collections import defaultdict
def main():
N, P = map(int, input().split())
S = list(map(int,list(input())))
S_mod = [0] * N
if P == 2:
for i in range(N-1,-1,-1):
if S[i] % 2 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
if P == 5:
for i in range(N-1,-1,-1):
if S[i] % 5 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
ten = 1
for i in range(N-1,-1,-1):
S_mod[i] = (S[i] * ten) % P
ten *= 10
ten %= P
S_mod.reverse()
S_acc = [0] * (N+1)
for i in range(N):
S_acc[i+1] = (S_acc[i] + S_mod[i]) % P
d = defaultdict(int)
for i in range(N+1):
d[S_acc[i]] += 1
ans = 0
for i, j in d.items():
if j >= 2:
ans += (j * (j-1)) // 2
print(ans)
if __name__ == "__main__":
main()
| 1 | 58,263,193,983,102 | null | 205 | 205 |
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=" ")
|
from functools import reduce
from operator import xor
# via https://drken1215.hatenablog.com/entry/2020/06/22/122500
N, *A = map(int, open(0).read().split())
B = reduce(xor, A)
print(*map(lambda a: B^a, A))
| 1 | 12,524,284,366,848 | null | 123 | 123 |
s=raw_input().strip()
print s+('es' if s[-1]=='s' else 's')
|
S = input()
print(S + 's') if S[-1] != 's' else print(S + 'es')
| 1 | 2,355,517,032,722 | null | 71 | 71 |
K = int(input())
A, B = map(int, input().split())
for n in range(A, B+1):
if n%K ==0:
print("OK")
exit()
print("NG")
|
k = int(input())
a, b = map(int,input().split())
flg = False
for i in range(a, b+1):
if i % k == 0:
flg = True
break
print('OK') if flg else print('NG')
| 1 | 26,644,595,001,408 | null | 158 | 158 |
import sys
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
sys.exit()
a_b_dist = abs(a-b)
v_w_dist = abs(v-w)
if v_w_dist * t < a_b_dist:
print('NO')
sys.exit()
print('YES')
|
a,v,b,w,t=map(int,open(0).read().split())
print('YNEOS'[abs(b-a)>(v-w)*t::2])
| 1 | 15,263,984,196,604 | null | 131 | 131 |
def arg(operator):
try:
return elements.index(operator)
except:
return 100000000000000
elements = [elem if elem in ['+', '-', '*']
else int(elem) for elem in input().split()]
while len(elements) != 1:
if arg('+') or arg('-') or arg('*'):
i = arg('+')
i = min(i, arg('-'))
i = min(i, arg('*'))
if elements[i] == '+': r = elements[i-2] + elements[i-1]
elif elements[i] == '-': r = elements[i-2] - elements[i-1]
elif elements[i] == '*': r = elements[i-2] * elements[i-1]
# i, i-1, i-2 -> one element
elements = elements[:i-2] + [r] + elements[i+1:]
else:
break
print(elements[0])
|
def push(S, top, x):
S.append(x)
top = top + 1
def pop(S, top):
t = int(S[top-1])
del S[top-1]
top = top -1
return t
if __name__ == "__main__":
top = 0
inpt = (input()).split()
n = len(inpt)
S = []
for i in range(0,n):
if inpt[i] == "+":
b = pop(S, top)
a = pop(S, top)
c = a + b
push(S, top, c)
elif inpt[i] == "-":
b = pop(S, top)
a = pop(S, top)
c = a - b
push(S, top, c)
elif inpt[i] == "*":
b = pop(S, top)
a = pop(S, top)
c = a * b
push(S, top, c)
else :
push(S, top, int(inpt[i]))
print(S[top-1])
| 1 | 35,215,725,050 | null | 18 | 18 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8[:],i8[:],i8[:],i8[:]), cache=True)
def main(lis_h,lis_w,bomb_h,bomb_w):
bomb = {}
for h,w in zip(bomb_h,bomb_w):
bomb[(h,w)] = 1
m_h = max(lis_h)
m_w = max(lis_w)
m_h_lis = []
m_w_lis = []
for i,l in enumerate(lis_h):
if l==m_h:
m_h_lis.append(i)
for i,l in enumerate(lis_w):
if l==m_w:
m_w_lis.append(i)
ans = m_h+m_w
for h in m_h_lis:
for w in m_w_lis:
if (h,w) not in bomb:
return ans
return ans-1
H, W, M = map(int, input().split())
bombh = np.zeros(M, np.int64)
bombw = np.zeros(M, np.int64)
lis_h = np.zeros(H, np.int64)
lis_w = np.zeros(W, np.int64)
for i in range(M):
h,w = map(int, input().split())
h -= 1
w -= 1
bombh[i], bombw[i] = h,w
lis_h[h] += 1
lis_w[w] += 1
print(main(lis_h,lis_w,bombh,bombw))
|
from collections import defaultdict
h, w, m = map(int, input().split())
target = []
point = defaultdict(int)
count_target_of_y = defaultdict(int)
count_target_of_x = defaultdict(int)
for i in range(m):
x, y = map(int, input().split())
count_target_of_y[y] += 1
count_target_of_x[x] += 1
point[(x,y)] += 1
max_x_count = max(list(count_target_of_x.items()), key=lambda x:x[1])[1]
max_y_count = max(list(count_target_of_y.items()), key=lambda x:x[1])[1]
max_x_count_list = [i for i in count_target_of_x.items() if i[1] == max_x_count]
max_y_count_list = [i for i in count_target_of_y.items() if i[1] == max_y_count]
for x in max_x_count_list:
for y in max_y_count_list:
if point[(x[0], y[0])] == 0:
print(max_x_count + max_y_count)
exit()
print(max_x_count + max_y_count - 1)
| 1 | 4,735,783,029,448 | null | 89 | 89 |
#!/usr/bin/env python3
s = input()
k = int(input())
n = len(s)
b = [0] * n
c = [0] * n
c[0] = 1
for i in range(n):
if s[i - 1] == s[i] and not c[i - 1]:
c[i] = 1
if i and s[i - 1] == s[i] and not b[i - 1]:
b[i] = 1
s1 = sum(b)
s2 = sum(c)
if s[-1] != s[0] or b[-1]:
print(s1 * k)
else:
if c[-1]:
print((s1 + s2) * (k // 2) + s1 * (k % 2))
else:
print(s1 + (k - 1) * s2)
|
S = list(input())
K = int(input())
def solve(S, K):
T = S * K
ans = 0
for i in range(len(T) - 1):
if T[i] == T[i + 1]:
ans += 1
T[i + 1] = "*"
return ans
A = [solve(S, i) for i in range(6)]
if K <= 5:
print(A[K])
else:
if K % 2 == 1:
d = A[5] - A[3]
print(A[5] + (K - 5) // 2 * d)
else:
d = A[4] - A[2]
print(A[4] + (K - 4) // 2 * d)
| 1 | 175,205,120,654,300 | null | 296 | 296 |
while True:
x, y = map(int, input().split())
if x == 0 and y == 0:
break
if x > y:
z = x
x = y
y = z
print(x, y)
|
x = 1
y = 1
while x != 0 or y != 0:
n = map(int,raw_input().split())
x = n[0]
y = n[1]
if x == 0 and y == 0:
break
elif x <= y:
print x,y
elif x > y:
print y,x
| 1 | 512,239,611,052 | null | 43 | 43 |
n = int(input())
list01 = input().split()
x = 0
for i in list01:
if int(i) % 2 != 0:
pass
elif int(i) % 3 == 0:
pass
elif int(i) % 5 == 0:
pass
else:
x += 1
break
if x == 1:
print('DENIED')
else:
print('APPROVED')
|
import copy
n = int(input())
l = list(input().split())
C1 = []
for v in l:
s = v[0]
m = int(v[1])
C1.append((s, m))
C2 = copy.deepcopy(C1)
for i in range(n):
for j in range(n-1, i, -1):
if C1[j][1] < C1[j-1][1]:
C1[j], C1[j-1] = C1[j-1], C1[j]
for i in range(n):
minj = i
for j in range(i,n):
if C2[j][1] < C2[minj][1]:
minj = j
C2[i], C2[minj] = C2[minj], C2[i]
result1 = [t[0]+str(t[1]) for t in C1]
result2 = [t[0]+str(t[1]) for t in C2]
print(" ".join(result1))
print("Stable")
print(" ".join(result2))
if result1 == result2:
print("Stable")
else:
print("Not stable")
| 0 | null | 34,632,266,134,132 | 217 | 16 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n = int(input())
if n == 1:
print(1)
sys.exit()
r = 0
for i1 in range(1, n + 1):
y = n // i1
r += y * (y + 1) // 2 * i1
print(r)
if __name__ == '__main__':
main()
|
import numpy as np
n = int(input())
cnt = 0
for k in range(1,n+1):
d = n//k
if d == 1:
cnt += (k+n)*(n-k+1)//2
break
cnt += k*d*(d+1)//2
print(cnt)
| 1 | 11,107,423,006,482 | null | 118 | 118 |
W, H, x, y, r = list(map(int, input().split()))
x_right = x + r
x_left = x - r
y_up = y + r
y_down = y - r
if x_right <= W and x_left >= 0 and y_up <= H and y_down >= 0:
print("Yes")
else:
print("No")
|
def main():
h,w,m = map(int,input().split())
X = [0]*w
Y = [0]*h
g = set([])
for _ in range(m):
a,b = map(int,input().split())
a-=1
b-=1
X[b]+=1
Y[a]+=1
g.add((a,b))
xmax = max(X)
ymax = max(Y)
xlist = []
for i,x in enumerate(X):
if x==xmax:
xlist.append(i)
ylist = []
for i,y in enumerate(Y):
if y==ymax:
ylist.append(i)
ans = xmax+ymax
flag = True
for x in xlist:
for y in ylist:
if (y,x) not in g:
flag = False
break
if not flag:
break
if flag:
ans-=1
print(ans)
main()
| 0 | null | 2,619,592,146,170 | 41 | 89 |
def gcd(x, y):
if x == 0:
return y
return gcd(y % x, x)
def lcm(x, y):
return x // gcd(x, y) * y
n, m = map(int, input().split())
a = list(map(int, input().split()))
aa = [e // 2 for e in a]
for i, e in enumerate(aa):
if i == 0:
base = 0
while e % 2 == 0:
e //= 2
base += 1
else:
cnt = 0
while e % 2 == 0:
e //= 2
cnt += 1
if cnt != base:
print(0)
exit()
c = 1
for e in aa:
c = lcm(c, e)
ans = (m - c) // (2 * c) + 1
print(ans)
|
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)
from heapq import heapify, heappush, heappop, heappushpop, heapreplace
from bisect import bisect_left, bisect_right
from math import atan, degrees
n, m = map(int, input().split())
a = [int(x) // 2 for x in input().split()]
t = 0
while a[0] % 2 == 0:
a[0] //= 2
t += 1
for i in range(1, n):
t2 = 0
while a[i] % 2 == 0:
a[i] //= 2
t2 += 1
if t2 != t:
print(0)
exit()
def gcd(x, y):
return gcd(y, x%y) if y else x
def lcm(x, y):
return x // gcd(x, y) * y
m >>= t
l = 1
for i in a:
l = lcm(l, i)
if l > m:
print(0)
exit()
print((m // l + 1) // 2)
| 1 | 101,894,783,769,542 | null | 247 | 247 |
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
counter = Counter(S)
for k in ["AC", "WA", "TLE", "RE"]:
print(k, "x", counter[k])
|
#!/usr/bin/env python3
hight = []
for i in range(10):
hight.append(int(input()))
hight = sorted(hight, reverse=True)
for i in range(3):
print(hight[i])
| 0 | null | 4,312,463,902,400 | 109 | 2 |
s=input()
k=int(input())
cnt=1
temp=[]
for i in range(len(s)-1):
if s[i]==s[i+1]: cnt+=1
else:
temp.append([s[i],cnt])
cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
print(k*len(s)//2)
exit()
ans=0
if temp[0][0]!=temp[-1][0]:
for pair in temp:
if pair[1]!=1: ans+=pair[1]//2
print(ans*k)
else:
for pair in temp[1:-1]:
if pair[1]!=1: ans+=pair[1]//2
ans*=k
ans+=(k-1)*((temp[0][1]+temp[-1][1])//2)
ans+=temp[0][1]//2+temp[-1][1]//2
print(ans)
|
s = input()
k = int(input())
if len(set(s)) == 1:
print(len(s)*k//2)
exit()
l = head = 0
now = s[0]
for i in range(len(s)):
if s[i] == now:
head += 1
else:
l = i
break
r = tail = 0
now = s[-1]
for i in range(len(s))[::-1]:
if s[i] == now:
tail += 1
else:
r = i+1
break
ans = 0
cnt = 0
now = s[l]
for i in range(l,r):
if s[i] == now:
cnt += 1
else:
ans += cnt//2
cnt = 1
now = s[i]
ans += cnt//2
ans *= k
if s[0] == s[-1]:
ans += (head+tail)//2*(k-1)
ans += head//2+tail//2
else:
ans += (head//2+tail//2)*k
print(ans)
| 1 | 175,803,273,191,292 | null | 296 | 296 |
import sys
def main():
n, x, y = map(int, sys.stdin.buffer.readline().split())
L = [0] * n
for i in range(1, n):
for j in range(i + 1, n + 1):
d = j - i
if i <= x and y <= j:
d -= y - x - 1
elif i <= x and x < j < y:
d = min(d, x - i + y - j + 1)
elif x < i < y and y <= j:
d = min(d, i - x + j - y + 1)
elif x < i and j < y:
d = min(d, i - x + y - j + 1)
L[d] += 1
for a in L[1:]:
print(a)
main()
|
# 解説AC
mod = 10 ** 9 + 7
n, k = map(int, input().split())
dp = [-1] * (k + 1)
ans = 0
for i in range(k, 0, -1):
dp[i] = pow(k // i, n, mod)
t = 0
t += 2 * i
while t <= k:
dp[i] -= dp[t]
dp[i] %= mod
t += i
ans += i * dp[i]
ans %= mod
print(ans)
| 0 | null | 40,389,844,614,638 | 187 | 176 |
import math
N, K = (int(a) for a in input().split())
A = [int(a) for a in input().split()]
def isOK(X):
cutcount = 0
for i in range(N):
cutcount += math.ceil(A[i] / X) - 1
if cutcount <= K:
return True
else:
return False
def binary_search():
left = 0
right = max(A) + 1
while (right - left) > 1:
mid = left + (right - left) // 2
if (isOK(mid)):
right = mid;
else:
left = mid;
return right
print(binary_search())
|
N = input()
K = int(input())
dp = [[[0 for _ in range(5)] for _ in range(2)] for _ in range(len(N)+1)]
dp[0][0][0] = 1
for i in range(len(N)):
dgt = int(N[i])
for k in range(K+1):
dp[i+1][1][k+1] += dp[i][1][k] * 9
dp[i+1][1][k] += dp[i][1][k]
if dgt > 0:
dp[i+1][1][k+1] += dp[i][0][k] * (dgt-1)
dp[i+1][1][k] += dp[i][0][k]
dp[i+1][0][k+1] = dp[i][0][k]
else:
dp[i+1][0][k] = dp[i][0][k]
print(dp[len(N)][0][K] + dp[len(N)][1][K])
| 0 | null | 40,959,083,376,298 | 99 | 224 |
n,m = map(int,input().split())
mat=[]
v=[]
for i in range(n):
a=list(map(int,input().split()))
mat.append(a)
for j in range(m):
v.append(int(input()))
for i in range(n):
w = 0
for j in range(m):
w += mat[i][j]*v[j]
print(w)
|
#coding: UTF-8
import statistics as st
while True:
N = int(input())
if N == 0:
break
buf = list(map(float, input().split()))
sd = st.pstdev(buf)
print("%.8f"%sd)
| 0 | null | 673,265,702,160 | 56 | 31 |
sum = 0
num = [0] * (10 ** 5 + 1)
N = int(input())
A = [int(a) for a in input().split()]
for i in range(0, N):
sum += A[i]
num[A[i]] += 1
Q = int(input())
for i in range(0, Q):
B, C = (int(x) for x in input().split())
sum += (C - B) * num[B]
num[C] += num[B]
num[B] = 0
print(sum)
|
n = int(input())
dic = {"AC":0, "WA":0, "TLE":0, "RE":0}
for i in range(n):
s = input()
dic[s] += 1
print("AC x " + str(dic["AC"]))
print("WA x " + str(dic["WA"]))
print("TLE x " + str(dic["TLE"]))
print("RE x " + str(dic["RE"]))
| 0 | null | 10,392,849,372,958 | 122 | 109 |
a = list(map(int, input().split()))
c = 0
for b in a:
c = c + 1
if b == 0:
print(c)
|
n = int( input() )
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(1,4):
s=0
m=0
for j in range(n):
s+=(abs(x[j]-y[j]))**i
if (abs(x[j]-y[j])) > m:
m=(abs(x[j]-y[j]))
print(s**(1/i))
print(m)
| 0 | null | 6,892,530,250,912 | 126 | 32 |
N=int(input())
S=input()
if N%2==0 and S[:int(N/2)]==S[int(N/2):]:
print("Yes")
else:
print("No")
|
x=int(input())
t=0
for i in range(1,x+1):
if i%3!=0 and i%5!=0:
t+=i
print(t)
| 0 | null | 91,346,970,231,360 | 279 | 173 |
def gacha():
# 入力
N = int(input())
S = [input() for _ in range(N)]
# 重複排除
freebie_tuple = set(S)
# 景品の種類
return len(freebie_tuple)
result = gacha()
print(result)
|
n = int(input())
g = [[] for _ in range(n)]
for i in range(n):
a = int(input())
for j in range(a):
x, y = map(int, input().split())
x -= 1
g[i].append((x, y))
ans = 0
for i in range(2**n):
temp = [-1]*n
for j in range(n):
if (i >> j) & 1:
temp[j] = 1
else:
temp[j] = 0
flag = True
for j in range(n):
if temp[j] == 1:
for x, y in g[j]:
if temp[x] != y:
flag = False
if flag:
ans = max(ans, sum(temp))
print(ans)
| 0 | null | 75,763,783,190,552 | 165 | 262 |
# -*- coding: utf-8 -*-
def selection_sort(A, N):
change = 0
for i in xrange(N):
minj = i
for j in xrange(i, N, 1):
if A[j] < A[minj]:
minj = j
if minj != i:
temp = A[minj]
A[minj] = A[i]
A[i] = temp
change += 1
return (A, change)
if __name__ == "__main__":
N = input()
A = map(int, raw_input().split())
result, change = selection_sort(A, N)
print ' '.join(map(str, result))
print change
|
count = 0
input()
num = [int(n) for n in input().split()]
for i in range(len(num)):
minj = i
for j in range(i, len(num)):
if num[j] < num[minj]:
minj = j
if minj != i:
num[i], num[minj] = num[minj], num[i]
count += 1
print(*num)
print(count)
| 1 | 21,711,586,572 | null | 15 | 15 |
n=int(input())
a=n*n
print(int(a))
|
n = int(input())
my_result = n * n
print(int(my_result))
| 1 | 145,295,058,372,908 | null | 278 | 278 |
a, b = (int(x) for x in input().split())
ans=0
if a==b:
for i in range(a):
ans+=a*pow(10,i)
elif a>b:
for i in range(a):
ans+=b*pow(10,i)
else:
for i in range(b):
ans+=a*pow(10,i)
print(ans)
|
num = int(input())
array = list(map(int,input().split()))
for i in range(num):
v = array[i]
j = i-1
while j >=0 and array[j]>v:
array[j+1] = array[j]
j -= 1
array[j+1] = v
print(" ".join(map(str,array)))
| 0 | null | 42,063,901,069,862 | 232 | 10 |
def swap(a, b):
a = a ^ b
b = a ^ b
a = a ^ b
def gcd(x, y):
if(x < y):
swap(x, y)
mod = x % y
if mod == 0:
return y
else:
return gcd(y, mod)
def lcm(x, y):
return x * y / gcd(x, y)
while True:
try:
(a, b) = map(int ,raw_input().split())
except EOFError:
break
print gcd(a, b), lcm(a, b)
|
import sys
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b / gcd(a, b)
for s in sys.stdin:
a, b = map(int, s.split())
print "%d %d"%(gcd(a, b), lcm(a, b))
| 1 | 702,887,780 | null | 5 | 5 |
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
def distance(i, j):
xi, yi = xy[i]
xj, yj = xy[j]
return (xi-xj)**2 + (yi-yj)**2
visited = [False] * n
ans = 0
def dfs(route, length):
global ans
if len(route)==n:
ans += length
return
else:
for i in range(n):
if visited[i]: continue
next_distance = distance(route[-1], i)**0.5
visited[i] = True
dfs(route+[i], length+next_distance)
visited[i] = False
cnt = 1
for i in range(n):
cnt*=i+1
visited[i] = True
dfs([i], 0)
visited[i] = False
print(ans/cnt)
|
h, n = map(int,input().split())
a = list(map(int,input().split()))
atack = sum(a)
can = h <= atack
print("Yes" if can else "No")
| 0 | null | 113,416,108,387,340 | 280 | 226 |
from fractions import gcd
n,m = map(int,input().split())
a = list(map(lambda x: int(x)//2,input().split()))
def lcm(x,y):
return x*y//gcd(x,y)
def f(x):
cnt = 0
while x%2 == 0:
x //= 2
cnt += 1
return cnt
r = set([f(i) for i in a])
if len(r) != 1:
print(0)
exit()
T = 1
for i in range(n):
T = lcm(T,a[i])
ans=-(-(m//T)//2)
c=T
print(ans)
|
import sys
from functools import reduce
def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)
n, m, *a = map(int, sys.stdin.read().split())
def main():
for i in range(n):
a[i] //= 2
b = set()
for x in a:
cnt = 0
while x % 2 == 0:
x //= 2
cnt += 1
b.add(cnt)
if len(b) == 2: print(0); return
l = reduce(lcm, a, 1)
res = (m // l + 1) // 2
print(res)
if __name__ == '__main__':
main()
| 1 | 101,606,106,986,382 | null | 247 | 247 |
#(63)距離
import math
x1,y1,x2,y2=map(float,input().split())
a=abs(x2-x1)
b=abs(y2-y1)
c=math.sqrt(a**2+b**2)
print('{:.8f}'.format(c))
|
import math
n=int(input())
a=100000
for i in range(n):
a=a+a*0.05
if a%1000==0:
a=a
else:
a=(math.floor(a/1000))
a=a*1000+1000
print(a)
| 0 | null | 83,337,753,094 | 29 | 6 |
N = int(input())
S = list(input())
check = 0
for i in range(N-1):
if S[i] != "*":
if S[i:i+3] == ["A","B","C"]:
check += 1
S[i:i+3] = ["*"]*3
print(check)
|
import re
n = int(input())
s = input()
a = []
ans = 0
for i in range(n):
if s[i] == 'A':
a.append(i)
for i in a:
if s[i:i+3] == 'ABC':
ans += 1
print(ans)
| 1 | 98,865,768,174,720 | null | 245 | 245 |
import math
def prime(x):
p = {}
last = math.floor(x ** 0.5)
if x % 2 == 0:
cnt = 1
x //= 2
while x & 1 == 0:
x //= 2
cnt += 1
p[2] = cnt
for i in range(3, last + 1, 2):
if x % i == 0:
x //= i
cnt = 1
while x % i == 0:
cnt += 1
x //= i
p[i] = cnt
if x != 1:
p[x] = 1
return p
N = int(input())
P = prime(N - 1)
if N == 2:
print(1)
exit()
ans = 1
for i in P.keys():
ans *= P[i] + 1
ans -= 1
P = prime(N)
D = [1]
for i in P.keys():
L = len(D)
n = i
for j in range(P[i]):
for k in range(L):
D.append(D[k] * n)
n *= i
for i in D:
if i == 1: continue
t = N
while (t / i == t // i):
t //= i
t -= 1
if t / i == t // i:
ans += 1
print(ans)
|
a1, a2, a3 = [int(n) for n in input().split()]
print('bust' if a1+a2+a3 >= 22 else 'win')
| 0 | null | 79,906,210,245,640 | 183 | 260 |
a, b, c, = map(int, input().split())
if 4*a*b < a*a + b*b + c*c + 2*a*b - 2*c*b - 2*c*a and 0 < c - (a + b):
print("Yes")
else:
print("No")
|
N = int(input())
A = list(map(int, input().split()))
X = 10**18
ans = 1
if 0 in A:
ans = 0
else:
for i in range(N):
ans = ans * A[i]
if ans > X:
ans = -1
break
print(ans)
| 0 | null | 34,110,154,123,640 | 197 | 134 |
n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
a[i], b[i], c[i], d[i] = map(int, input().split())
score = []
# 数列Aの全探索
import copy
def dfs(A):
if len(A) == n+1:
# score計算
tmp = 0
#print(A)
for i in range(q):
if A[b[i]] - A[a[i]] == c[i]:
tmp += d[i]
score.append(tmp)
return
else:
tmp = A[-1]
arr = copy.copy(A)
arr.append(tmp)
while(arr[-1] <= m):
dfs(arr)
arr[-1] += 1
dfs([1])
print(max(score))
|
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
s_l = []
for i in range(q):
s = list(map(int, input().split()))
s_l.append(s)
A = []
for v in combinations_with_replacement(range(1,m+1), n):
A.append(v)
ans = 0
for a in A:
cnt = 0
for i in range(q):
if a[s_l[i][1] - 1] - a[s_l[i][0] - 1] == s_l[i][2]:
cnt += s_l[i][3]
ans = max(ans, cnt)
print(ans)
| 1 | 27,606,550,075,872 | null | 160 | 160 |
import sys
def gcd(a,b):
while a%b :
a,b=b,a%b
return b
def lcm(a,b) :
return a*b/gcd(a,b)
for ab in sys.stdin:
a,b = map(int,ab.split())
a,b = max(a,b),min(a,b)
print "%d" % gcd(a,b),
print "%d" % lcm(a,b)
|
import sys
sys.setrecursionlimit(10**7)
import fileinput
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
for line in sys.stdin:
x, y = map(int, line.split())
print(gcd(x,y),lcm(x,y))
| 1 | 494,580,440 | null | 5 | 5 |
S = list(input())
countA = 0
countB = 0
for i in range(0, len(S)):
if S[i] == "A":
countA += 1
elif S[i] == "B":
countB += 1
if countA == 3 or countB == 3:
print("No")
else:
print("Yes")
|
h,n=map(int,input().split())
a=list(map(int,input().split()))
sum=0
for i in a:
sum += i
if sum<h:
print("No")
else:
print("Yes")
| 0 | null | 66,633,528,842,650 | 201 | 226 |
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
s=input()
if s[-1]=="s":
print(s+"es")
else:
print(s+"s")
|
A = str(input())
if A[-1] == "s":
print(A + "es");
else:
print(A + "s")
| 1 | 2,376,347,577,792 | null | 71 | 71 |
h, n = map(int, input().split())
print('No' if sum(list(map(int, input().split())))<h else 'Yes')
|
n,x,t = map(int,input().split())
ans = int((n+x-1)/x)
ans *= t
print(ans)
| 0 | null | 41,351,668,692,052 | 226 | 86 |
X = int(input())
if X >= 400 and X < 600:
print('8')
elif X >= 600 and X < 800:
print('7')
elif X >= 800 and X < 1000:
print('6')
elif X >= 1000 and X < 1200:
print('5')
elif X >= 1200 and X < 1400:
print('4')
elif X >= 1400 and X < 1600:
print('3')
elif X >= 1600 and X < 1800:
print('2')
elif X >= 1800 and X < 2000:
print('1')
|
def main():
x = int(input())
print((2199 - x) // 200)
if __name__ == '__main__':
main()
| 1 | 6,704,247,452,588 | null | 100 | 100 |
N=int(input())
n= str(N)
total=0
for i in range(len(n)):
k = n[i]
k = int(k)
total += k
if total%9==0:
print("Yes")
else:
print("No")
|
# -*- coding: utf-8 -*-
def qq(limit=9):
qq_str = ''
for i in range(1, limit+1):
for j in range(1, limit+1):
qq_str += str(i) + 'x' + str(j) + '=' + str(i*j)
if i != limit or j != limit:
qq_str += '\n'
return qq_str
def main():
print(qq())
if __name__ == '__main__':
main()
| 0 | null | 2,173,762,440,120 | 87 | 1 |
n = int(input())
tarou = 0
hanako = 0
for i in range(n):
w1, w2 = input().split()
if w1 == w2:
tarou += 1
hanako += 1
elif w1 > w2:
tarou += 3
else:
hanako += 3
print(tarou, hanako)
|
import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
N, M = MI()
p = ["0"]*(M)
S = ["0"]*(M)
for i in range(M):
p[i], S[i] = map(str,input().split())
ans = [0]*(N+1)
error = [0]*(N+1)
e = [0]*(N+1)
for i in range(M):
if ans[int(p[i])] == 0:
if S[i] == "WA":
error[int(p[i])] += 1
elif S[i] == "AC":
ans[int(p[i])] = 1
sum_ans = sum(ans)
sum_error = 0
for i in range(N+1):
if ans[i] == 1:
sum_error += error[i]
print(sum_ans, sum_error)
if __name__ == "__main__":
main()
| 0 | null | 47,909,267,541,918 | 67 | 240 |
#!/usr/bin/env python
class PrimeFactor():
def __init__(self, n):
'''
Note:
make the table of Eratosthenes' sieve
and minFactor[] for fast_factorization.
'''
self.n = n
self.table = [True for _ in range(n+1)]
self.table[0] = self.table[1] = False
self.minFactor = [-1 for _ in range(n+1)]
for i in range(2, n+1):
if not self.table[i]: continue
self.minFactor[i] = i
for j in range(i*i, n+1, i):
self.table[j] = False
self.minFactor[j] = i
def fast_factorization(self, n):
'''
Note:
factorization
return the form of {factor: num}.
'''
data = {}
while n > 1:
if self.minFactor[n] not in data:
data[self.minFactor[n]] = 1
else:
data[self.minFactor[n]] += 1
n //= self.minFactor[n]
return data
def count_divisors(self, n):
'''
Note:
return the number of divisors of n.
'''
ret = 1
for v in self.fast_factorization(n).values():
ret *= (v+1)
return ret
n = int(input())
ans = 0
a = PrimeFactor(n)
for i in range(1, n):
ans += a.count_divisors(i)
print(ans)
|
n = int( input() )
A = []
B = []
for i in range(n):
a, b = map( int, input().split() )
A.append( a )
B.append( b )
A = sorted( A )
B = sorted( B )
ret = 0
if n % 2 == 0:
i = n // 2 - 1
ret = B[ i + 1 ] + B[ i ] - ( A[ i + 1 ] + A[ i ] ) + 1
else:
i = ( n + 1 ) // 2 - 1
ret = B[ i ] - A[ i ] + 1
print( ret )
| 0 | null | 9,828,555,247,488 | 73 | 137 |
def selsort(array):
counter = 0
for i in range(len(array)):
minnum = i
for c in range(i,len(array)):
if array[c] < array[minnum]:
minnum = c
if minnum != i:
x = array[i]
array[i] = array[minnum]
array[minnum] = x
counter = counter + 1
array.append(counter)
N = int(input())
arr = [int(i) for i in input().split()]
selsort(arr)
print(' '.join([str(i) for i in arr[:-1]]))
print(arr[-1])
|
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(N!=0):
for a in lst:
fl.append(int(a))
for a in range(101):
if(X-a not in fl):
print(X-a)
break
if(X+a not in fl):
print(X+a)
break
| 0 | null | 7,090,218,376,960 | 15 | 128 |
import sys
N, M = map(int, input().split())
S = input()[::-1]
ans = ''
i = 0
while i < N - M:
found = False
for j in range(M, 0, -1):
if S[i + j] == '0':
ans += str(j) + ' '
i += j
found = True
break
if not found:
print(-1)
sys.exit()
ans += str(N-i)
print(' '.join(ans.split()[::-1]))
|
import sys
def log(s):
# print("| " + str(s), file=sys.stderr)
pass
def output(x):
print(x, flush=True)
def input_ints():
return list(map(int, input().split()))
def main():
f = input_ints()
print(f[0] * f[1])
main()
| 0 | null | 77,249,575,096,494 | 274 | 133 |
N, K = map(int, input().split())
ans = 0
for h in list(map(int, input().split())):
ans += (h >= K)
print(ans)
|
import bisect
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
a = bisect.bisect(l, k-1)
print(n-a)
| 1 | 178,731,192,267,748 | null | 298 | 298 |
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=[]
for i in range(N):
score=[]
B=[]
count=1
nex=P[i]-1
point=C[nex]
B.append(C[nex])
score.append(point)
while count<=K:
if nex==i:
break
nex=P[nex]-1
point+=C[nex]
score.append(point)
B.append(C[nex])
count+=1
if count==K:
ans.append(max(score))
else:
if point<=0:
ans.append(max(score))
else:
a=K//count
b=K%count
maxpoint=point*(a-1)
for j in range(b):
maxpoint+=B[j]
c=maxpoint
for j in range(count):
if b+j<count:
c+=B[b+j]
else:
c+=B[b+j-count]
maxpoint=max(maxpoint,c)
ans.append(maxpoint)
print(max(ans))
|
class Union_Find():
def __init__(self, N):
self.N = N
self.par = [n for n in range(N)]
self.rank = [0] * N
def root(self, x):
if self.par[x] == x:
return x
else:
return self.root(self.par[x])
def same(self, x, y):
if self.root(x) == self.root(y):
return True
else:
return False
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if (x==y): return
if (self.rank[x] < self.rank[y]):
self.par[x] = y
self.rank[y] += self.rank[x] + 1
else:
self.par[y] = x
self.rank[x] += self.rank[y] + 1
N, M = map(int, input().split())
UF = Union_Find(N)
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
UF.unite(a, b)
ans = -1
for n in range(N):
ans = max(ans, UF.rank[n])
print(ans+1)
| 0 | null | 4,620,824,229,980 | 93 | 84 |
string = input()
if string[-1] == 's':
out = string + "es"
else:
out = string + "s"
print(out)
|
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
# MOD = int(1e09) + 7
MOD = 998244353
INF = int(1e15)
def divisor(N):
res = []
i = 2
while i * i <= N:
if N % i == 0:
res.append(i)
if i != N // i:
res.append(N // i)
i += 1
if N != 1:
res.append(N)
return res
def solve():
N = Scanner.int()
d0 = divisor(N - 1)
ans = len(d0)
d1 = divisor(N)
for d in d1:
X = N
while X % d == 0:
X //= d
if X % d == 1:
ans += 1
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| 0 | null | 21,909,990,341,988 | 71 | 183 |
N,M = map(int,input().split())
S = input()
c = 0
flag = 0
for i in S:
if i == '0':
if c >= M:
flag = 1
break
c = 0
else:
c += 1
if flag == 1:
print(-1)
else:
T = S[::-1]
now = 0
ans = []
while now != N:
delta = 0
for i in range(1,M+1):
if now + i == N:
delta = i
break
if T[now+i] == '0':
delta = i
ans.append(delta)
now += delta
Answer = ans[::-1]
print(*Answer)
|
from bisect import *
n,m = map(int,input().split())
S = input()
ok = []
for i,s in enumerate(S[::-1]):
if s == '0':
ok.append(i)
now = 0
ans = []
while now != n:
nxt = ok[bisect_right(ok, now + m) - 1]
if nxt == now:
ans = [str(-1)]
break
else:
ans.append(str(nxt - now))
now = nxt
print(' '.join(ans[::-1]))
| 1 | 139,472,385,348,634 | null | 274 | 274 |
import fileinput
a, b = map(int, input().split())
if a > 9 or b > 9:
print("-1")
else:
print(a * b)
|
n = int(input())
playlist = []
duration = []
for i in range(n):
s, t = input().split()
playlist.append(s)
duration.append(int(t))
index = playlist.index(input())
durations = sum(duration[index + 1: ])
print(durations)
| 0 | null | 127,704,171,978,080 | 286 | 243 |
class UnionFind():
#https://note.nkmk.me/python-union-find/
#note.nkmk.me 2019-08-18
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
#初期入力、集合とユニオンファインド
import sys
input = sys.stdin.readline
N,M,K = (int(x) for x in input().split())
#接続(友好関係、ブロック関係)
uf =UnionFind(N+1)
conn_fri ={i:set() for i in range(1,N+1)}
conn_blo ={i:set() for i in range(1,N+1)}
for i in range(M):
a,b = (int(x) for x in input().split())
uf.union(a,b)
conn_fri[a].add(b)
conn_fri[b].add(a)
for i in range(K):
c,d = (int(x) for x in input().split())
conn_blo[c].add(d)
conn_blo[d].add(c)
#友達候補の数=同じグループにいる、友達関係でない、ブロック関係でない
ans ={i:0 for i in range(1,N+1)}
for i in range(1,N+1):
root =uf.find(i)
all =uf.size(root)
same_groop_block =0
for j in conn_blo[i]:
if uf.same(i,j): #同じグループにいるけどブロック関係
same_groop_block +=1
ans[i] =all -len(conn_fri[i]) -same_groop_block -1 #-1 自分を引く
#出力
print(*ans.values())
#print(all)
|
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split()) #高橋君
B1,B2 = map(int,input().split()) #青木君
# 時間配列
T = [T1]
f = 1
for i in range(3):
if f:
Tn = T2
f = 0
else:
Tn = T1
f = 1
T.append(T[-1]+Tn)
# print(T)
class runner():
def __init__(self,v1,v2):
self.v1 = v1
self.v2 = v2
def distance(self,t):
d = t//(T1+T2)*(self.v1*T1 + self.v2*T2)
tm = t % (T1+T2)
# print("d",d,"tm",tm)
if tm < T1:
d += self.v1 * tm
else:
d += self.v2*(tm-T1) + self.v1*T1
return d
dif = runner(A1-B1,A2-B2)
c = -1
D = 0
DL = [0]
for t in T:
pD = D
D = dif.distance(t)
DL.append(D)
# print(D)
if pD*D <= 0:
c += 1
# print(c)
# print(DL)
if DL[1]*DL[2] > 0:
print(0)
else:
if DL[2] == 0:
print("infinity")
else:
a = DL[2]
if a>0:
if -DL[1]%a == 0:
print(-DL[1]//a*2)
else:
print(-DL[1]//a*2+1)
else:
if -DL[1]%a == 0:
print(-DL[1]//a*2)
else:
print(-DL[1]//a*2+1)
| 0 | null | 96,243,023,216,718 | 209 | 269 |
import math
N =int(input())
s = N / 1000
if s == 0 :
print(0)
else :
a = math.ceil(s) * 1000 - N
print(int(a))
|
a=["SUN","MON","TUE","WED","THU","FRI","SAT"]
s=input()
k=-1
for i in range(7):
if(a[i]==s):k=i
k=(7-k)
print(k)
| 0 | null | 70,963,706,920,860 | 108 | 270 |
"""
Hが少ないので、縦で割るパターンは全探索して見る。
dpとか使わずに、貪欲的に割っていけばよい。
"""
H,W,K = map(int,input().split())
choco = [list(input()) for _ in range(H)]
accum = [[0]*W for _ in range(H)]
for i in range(H):
for j in range(W):
accum[i][j] = accum[i][j-1] + int(choco[i][j])
ans = float("INF")
for i in range(2**H):
"""
i を2進数表記したときに1になっているインデックスに該当する行数で分割する。
例えば00100なら3行目と4行目の間で分割する。
"""
binI = format(i,"0"+str(H)+"b")
group = {}
groupNum = 0
for j in range(H):
group[j] = groupNum
if binI[j] == "1":
groupNum += 1
breakCnt = groupNum
tmp = [0]*(groupNum+1)
for j in range(W):
tmp2 = [0]*(groupNum+1)
for k in range(H):
groupNum = group[k]
if choco[k][j] == "1":
tmp2[groupNum] += 1
if max(tmp2) > K:
break
else:
for l in range(groupNum+1):
tmp[l] += tmp2[l]
if max(tmp) > K:
breakCnt += 1
tmp = tmp2
else:
ans = min(ans,breakCnt)
print(ans)
|
H,W,K = map(int,input().split())
C = [[int(i) for i in input()] for _ in range(H)]
ans = float("inf")
for i in range(1<<(H-1)):
start = [0]
end = []
for j in range(H-1):
if i & (1 << j):
j += 1
start.append(j)
end.append(j)
end.append(H)
L = len(end)
cnt = [0]*L
dcnt = L-1
fail = False
for w in range(W):
div = False
idx = 0
tmp = [0]*L
for s,e in zip(start,end):
for h in range(s,e): tmp[idx] += C[h][w]
if tmp[idx] > K:
fail = True
break
if cnt[idx] + tmp[idx] > K:
div = True
cnt = tmp[:]
else:
cnt[idx] += tmp[idx]
idx += 1
if fail: break
if div: dcnt += 1
if fail: continue
ans = min(dcnt,ans)
print(ans)
| 1 | 48,277,662,848,832 | null | 193 | 193 |
N=input()
dp0=[0]*(len(N)+1)
dp1=[0]*(len(N)+1)
dp1[0]=1
for i in range(len(N)):
n=int(N[i])
dp0[i+1]=min(dp0[i]+n, dp1[i]+(10-n))
n+=1
dp1[i+1]=min(dp0[i]+n, dp1[i]+(10-n))
#print(dp0)
#print(dp1)
print(dp0[-1])
|
n = int(input())
s = str(input())
ans = n
for i in range(1,n):
if s[i-1] == s[i]:
ans -= 1
print(ans)
| 0 | null | 120,749,734,420,184 | 219 | 293 |
N = int(input())
def cnt(n):
c = 0
for i in range(1, N+1):
n = N // i
j = i * n
c += (i + j) * n // 2
return c
print(cnt(N))
|
N=int(input())
A=[0]*N
ans=0
for i in range(1,N+1):
ii=i
while N>=ii:
A[ii-1]+=1
ii+=i
ans+=A[i-1]*i
print(ans)
| 1 | 10,918,428,225,472 | null | 118 | 118 |
a = [0, 0, 0, 0]
for t in range(10):
a[3] = input()
for i in range(2, -1, -1):
if (a[i] < a[i+1]):
a[i], a[i+1] = a[i+1], a[i]
for i in range(0, 3):
print a[i]
|
M = [0 for i in xrange(10)]
for i in xrange(10):
M[i] = int(raw_input())
M.sort()
M.reverse()
for i in xrange(3):
print M[i]
| 1 | 29,726,122 | null | 2 | 2 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h, w, m = map(int, input().split())
bom_set = set()
h_dict = {}
w_dict = {}
for i in range(m):
hh, ww = map(int, input().split())
bom_set.add(tuple([hh, ww]))
if hh in h_dict:
h_dict[hh] += 1
else:
h_dict[hh] = 1
if ww in w_dict:
w_dict[ww] += 1
else:
w_dict[ww] = 1
h_max_count = max(h_dict.values())
w_max_count = max(w_dict.values())
hh_dict = {}
ww_dict = {}
for hh in h_dict:
if h_dict[hh] == h_max_count:
hh_dict[hh] = h_max_count
for ww in w_dict:
if w_dict[ww] == w_max_count:
ww_dict[ww] = w_max_count
flag = 0
for hh in hh_dict:
for ww in ww_dict:
if tuple([hh, ww]) not in bom_set:
flag = 1
break
if flag == 1:
break
if flag == 1:
print(h_max_count + w_max_count)
else:
print(h_max_count + w_max_count - 1)
|
import collections
h, w, m = map(int, input().split())
h = [None]*m
w = [None]*m
for i in range(m):
u, v = map(int, input().split())
h[i] = u
w[i] = v
hc = collections.Counter(h)
wc = collections.Counter(w)
hm = hc.most_common()[0][1]
hs = set([])
for hi, ci in hc.most_common():
if ci == hm:
hs.add(hi)
else:
break
wm = wc.most_common()[0][1]
ws = set([])
for wi, ci in wc.most_common():
if ci == wm:
ws.add(wi)
else:
break
cnt = 0
for i in range(m):
if h[i] in hs and w[i] in ws:
cnt += 1
if cnt == len(hs)*len(ws):
print(hm + wm -1)
else:
print(hm + wm)
| 1 | 4,771,964,260,400 | null | 89 | 89 |
S,T,A,B,U = open(0).read().split()
if S==U:
print(int(A)-1,B)
else:
print(A,int(B)-1)
|
n=int(input())
a=list(map(int,input().split()))
if n==0:
if a[0]==1:
print(1)
exit()
else:
print(-1)
exit()
if a[0]>0:
print(-1)
exit()
ans=1
pre_no_ha=1
all_ha=sum(a)
for ai in a[1:]:
if pre_no_ha<=0:
print(-1)
exit()
if ai>pre_no_ha*2:
print(-1)
exit()
pre_no_ha*=2
pre_no_ha-=ai
all_ha-=ai
pre_no_ha=min(pre_no_ha,all_ha)
ans+=pre_no_ha+ai
print(ans)
| 0 | null | 45,629,939,196,956 | 220 | 141 |
N = int(input())
A = list(map(int, input().split()))
x = 0
for a in A:
x ^= a
ans = []
for a in A:
ans.append(a ^ x)
print(" ".join(map(str, ans)))
|
from collections import deque
n = int(input())
data = deque(list(input() for _ in range(n)))
ans = deque([])
co = 0
for i in data:
if i[6] == ' ':
if i[0] == 'i':
ans.insert(0, i[7:])
co += 1
else:
try:
ans.remove(i[7:])
co -= 1
except:
pass
else:
if i[6] == 'F':
del ans[0]
co -= 1
else:
del ans[-1]
co -= 1
for i in range(0, co-1):
print(ans[i], end=' ')
print(ans[co-1])
| 0 | null | 6,308,053,059,880 | 123 | 20 |
N, K = list(map(int, input().split()))
table = [0] * N
for _ in range(K):
num = int(input())
have_list = list(map(int, input().split()))
for child in have_list:
table[child-1] += 1
print(str(table.count(0)))
|
N,K = map(int,input().split())
n_lis = [0]*N
for i in range(K):
d = int(input())
*A, = map(int,input().split())
for j in range(d):
a = A[j]
n_lis[a-1] = 1
print(n_lis.count(0))
| 1 | 24,593,783,261,320 | null | 154 | 154 |
# coding: utf-8
# Your code here!
N=int(input())
count=-1
for i in range(N//2+1):
count+=1
if N%2==0:
print(count-1)
else:
print(count)
|
N = int(input())
A = [int(temp) for temp in input().split()]
cou = 0
for mak in range(1,N) :
for j in range(mak,N)[ : : -1] :
if A[j] < A[j - 1] :
tem = int(A[j])
A[j] = int(A[j - 1])
A[j - 1] = int(tem)
cou = cou + 1
A = [str(temp) for temp in A]
print(' '.join(A))
print(cou)
| 0 | null | 76,487,556,595,460 | 283 | 14 |
a=b=1
for _ in range(int(input())):a,b=b,a+b
print(a)
|
X = int(input())
for i in range(-120,120):
for j in range(-120,120):
if i**5 - j**5 == X:
print(i,j)
exit()
| 0 | null | 12,758,207,758,110 | 7 | 156 |
#!/usr/bin/env python3
import sys
def cube(x):
if not isinstance(x,int):
x = int(x)
return x*x*x
if __name__ == '__main__':
i = sys.stdin.readline()
print('{}'.format( cube( int(i) ) ))
|
n=int(input())
d=list(map(int,input().split()))
s=0
for i in d:
s+=i**2
print(int(((sum(d))**2)/2-(s/2)))
| 0 | null | 84,133,833,994,780 | 35 | 292 |
N = int(raw_input())
count = 0
A_str = raw_input().split()
A = map(int, A_str)
def merge(left, right):
global count
sorted_list = []
l_index = 0
r_index = 0
while l_index < len(left) and r_index < len(right):
count += 1
if left[l_index] <= right[r_index]:
sorted_list.append(left[l_index])
l_index += 1
else:
sorted_list.append(right[r_index])
r_index += 1
if len(left) != l_index:
sorted_list.extend(left[l_index:])
count += len(left[l_index:])
if len(right) != r_index:
sorted_list.extend(right[r_index:])
count += len(right[r_index:])
return sorted_list
def mergeSort(A):
if len(A) <= 1:
return A
mid = len(A) // 2
left = A[:mid]
right = A[mid:]
left = mergeSort(left)
right = mergeSort(right)
return list(merge(left, right))
print ' '.join(map(str, mergeSort(A)))
print count
|
def merge(a, l, m, r):
global count
Left = a[l:m]
Left.append(1e10)
Right = a[m:r]
Right.append(1e10)
i, j = 0, 0
for k in range(l, r):
count += 1
if Left[i] <= Right[j]:
a[k] = Left[i]
i += 1
else:
a[k] = Right[j]
j += 1
def sort(a, l, r):
if r-l > 1:
m = (l+r)//2
sort(a, l, m)
sort(a, m, r)
merge(a, l, m, r)
count=0
n=int(input())
a=[int(i) for i in input().split()]
sort(a, 0, n)
print(*a)
print(count)
| 1 | 116,113,319,168 | null | 26 | 26 |
from __future__ import absolute_import, print_function, unicode_literals
for a in xrange(1, 10):
for b in xrange(1, 10):
print('{}x{}={}'.format(a, b, a * b))
|
h, n = map(int, input().split())
inf = 10 ** 9
dp = [inf for _ in range(h + 1)]
dp[0] = 0
for _ in range(n):
a, b = map(int, input().split())
for i in range(h + 1):
if i < a:
dp[i] = min(dp[i], b)
else:
dp[i] = min(dp[i], dp[i - a] + b)
print(dp[-1])
| 0 | null | 40,601,174,692,808 | 1 | 229 |
a, b = map(int, input().split())
A=''
B=''
for i in range(b):
A+=str(a)
for i in range(a):
B+=str(b)
if A<=B:
print(A)
else:
print(B)
|
N = int(input())
n = input().split()
a = []
for i in range(N):
a.append(int(n[i]))
a = sorted(a)
print('{0} {1} {2}'.format(a[0], a[-1], sum(a)))
| 0 | null | 42,551,624,493,600 | 232 | 48 |
def reverse_polish_notation(A):
ops = {'+': lambda a, b: b + a,
'-': lambda a, b: b - a,
'*': lambda a, b: b * a}
stack = []
for i in A:
if i in ops:
stack.append(ops[i](stack.pop(), stack.pop()))
else:
stack.append(int(i))
return stack[0]
if __name__ == '__main__':
A = list(input().split())
print(reverse_polish_notation(A))
|
import math
x1,y1,x2,y2 = input().split( )
x = float(x1)-float(x2)
y = float(y1)-float(y2)
print(math.sqrt(x**2+y**2))
| 0 | null | 93,014,089,030 | 18 | 29 |
class Dice:
def __init__(self, state):
self.state = state
def vertical(self, direction):
s = self.state
state = [s[1], s[5], s[0], s[4]]
if direction < 0:
s[0], s[1], s[4], s[5] = state
elif 0 < direction:
s[0], s[1], s[4], s[5] = reversed(state)
return self
def lateral(self, direction):
s = self.state
state = [s[2], s[5], s[0], s[3]]
if direction < 0:
s[0], s[2], s[3], s[5] = state
elif 0 < direction:
s[0], s[2], s[3], s[5] = reversed(state)
return self
def north(self):
self.vertical(-1)
return self
def south(self):
self.vertical(1)
return self
def east(self):
self.lateral(1)
return self
def west(self):
self.lateral(-1)
return self
init_state = input().split()
for i in range(int(input())):
dice = Dice(init_state)
up, front = input().split()
if up == dice.state[0] \
and front == dice.state[1]:
print(dice.state[2])
else:
for c in list('NNNNWNNNWNNNENNNENNNWNNN'):
if c == 'N':
dice.north()
elif c == 'S':
dice.south()
elif c == 'W':
dice.west()
elif c == 'E':
dice.east()
if up == dice.state[0] \
and front == dice.state[1]:
print(dice.state[2])
break
|
N,M = map(int,input().split())
S = input()
ans = []
right = N
while right > 0:
left = right
for i in range(M):
if S[right-i-1] == '0':
left = right-i-1
if left == 0:
break
if left == right:
print(-1)
break
ans.append(right-left)
right = left
else:
print(*reversed(ans))
| 0 | null | 69,913,819,627,832 | 34 | 274 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
graph = {"r":P,"s":R,"p":S,"*":0}
for i,t in enumerate(T):
if len(T)-i-K > 0:
if t == T[i+K]:
T[i+K] = "*"
ans = 0
for t in T:
ans += graph[t]
print(ans)
|
n,k = list(map(int,input().split()))
point = list(map(int,input().split()))
rsp = ['r', 's', 'p']
t = input()
m = [rsp[rsp.index(i)-1] for i in t]
ans = 0
for i in range(n):
if i<k :
ans += point[rsp.index(m[i])]
else:
if m[i]!=m[i-k]:
ans += point[rsp.index(m[i])]
else:
try:
m[i] = rsp[rsp.index(m[i+k])-1]
except:
pass
# print(ans)
print(ans)
| 1 | 106,922,985,600,452 | null | 251 | 251 |
firstLine = input()
numOfPoints, limitDisatnce = list(map(int,firstLine.split(' ')))[0], list(map(int,firstLine.split(' ')))[1]
points = []
for i in range(0, numOfPoints):
cordinate = list(map(int,input().split(' ')))
points.append(cordinate)
count = 0
for i in range(0, len(points)):
distance = (points[i][0] ** 2) + (points[i][1] ** 2)
if (limitDisatnce ** 2) >= distance:
count = count + 1
print(count)
|
import sys
x = int(raw_input())
print(x*x*x)
| 0 | null | 3,142,832,592,452 | 96 | 35 |
def resolve():
N, K = map(int, input().split())
D = []
A = []
for _ in range(K):
d = int(input())
a = list(map(int, input().split()))
D.append(d)
A.append(a)
ans = 0
for i in range(N):
flag = 0
for j in range(K):
if i+1 in A[j]:
flag = 1
if flag == 0:
ans += 1
print(ans)
resolve()
|
x, y = map(int, input().split())
for i in range(x+1):
for j in range(x+1):
if i+j == x:
if 2*i + 4*j == y:
print('Yes')
exit()
print('No')
| 0 | null | 19,248,202,491,820 | 154 | 127 |
a = input()
t = list(a)
if t[len(t)-1] == "?":
t[len(t)-1] = "D"
if t[0] == "?":
if t[1] == "D" or t[1] == "?":
t[0] = "P"
else:
t[0] = "D"
for i in range(1, len(t)-1):
if t[i] == "?" and t[i-1] == "P":
t[i] = "D"
elif t[i] == "?" and t[i+1] == "D":
t[i] = "P"
elif t[i] == "?" and t[i+1] == "?":
t[i] = "P"
elif t[i] == "?":
t[i] = "D"
answer = "".join(t)
print(answer)
|
input = input()
print(input.replace('?','D'))
| 1 | 18,481,277,964,988 | null | 140 | 140 |
import math
def f_gcd(a, b):
return math.gcd(a, b)
k = int(input())
ans = 0
for a in range(1, k+1):
for b in range(1, k+1):
for c in range(1, k+1):
ans += f_gcd(math.gcd(a, b), c)
print(ans)
|
from math import gcd
K = int(input())
ans = 0
r = range(1, K+1)
for i in r:
for j in r:
for k in r:
ans += gcd(gcd(i, j), k)
print(ans)
| 1 | 35,492,282,318,964 | null | 174 | 174 |
def selection_Sort(A,N):
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
count += 1
return (count)
if __name__ == '__main__':
n = int(input())
data = [int(i) for i in input().split()]
result = selection_Sort(data,n)
print(" ".join(map(str,data)))
print(result)
|
from typing import List
def selection_sort(A: List[int]) -> int:
cnt = 0
for i in range(len(A)):
min_j = i
for j in range(i, len(A)):
if A[j] < A[min_j]:
min_j = j
if min_j != i:
cnt += 1
A[i], A[min_j] = A[min_j], A[i]
return cnt
N = int(input())
A = [int(i) for i in input().split()]
cnt = selection_sort(A)
print(' '.join(map(str, A)))
print(cnt)
| 1 | 21,114,464,294 | null | 15 | 15 |
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
for i in range(m):
x,y,c=map(int,input().split())
l.append(a[x-1]+b[y-1]-c)
l.append(min(a)+min(b))
print(min(l))
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, L = lr()
INF = 10 ** 19
dis = [[INF for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
a, b, c = lr()
if c > L:
continue
dis[a][b] = c
dis[b][a] = c
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
x = dis[i][k] + dis[k][j]
if x < dis[i][j]:
dis[i][j] = dis[j][i] = x
supply = [[INF] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(i+1, N+1):
if dis[i][j] <= L:
supply[i][j] = supply[j][i] = 1
for k in range(N+1): # kが中継地点
for i in range(N+1):
for j in range(i+1, N+1):
y = supply[i][k] + supply[k][j]
if y < supply[i][j]:
supply[i][j] = supply[j][i] = y
Q = ir()
for _ in range(Q):
s, t = lr()
if supply[s][t] == INF:
print(-1)
else:
print(supply[s][t] - 1)
# 59
| 0 | null | 114,085,016,552,370 | 200 | 295 |
import sys
import math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
a,b,x = map(int, input().split())
s = a * b
theta = 0
if a * a * b / 2 < x:
theta = math.atan(2 * (a**2 * b - x) / a**3)
else:
theta = math.atan((a * b**2) / (2 * x))
deg = math.degrees(theta)
print('{:.10f}'.format(deg))
|
N = int(input())
A = [int(s) for s in input().split()]
print(' '.join([str(item) for item in A]))
for i in range(1, N):
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j = j - 1
A[j+1] = key
print(' '.join([str(item) for item in A]))
| 0 | null | 81,535,123,273,320 | 289 | 10 |
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
cheby.append(l)
xmax = -10**10
xmin = 10**10
ymax = -10**10
ymin = 10**10
for i in range(n):
if cheby[i][0] > xmax :
xmax = cheby[i][0]
xa = i
if cheby[i][0] < xmin :
xmin = cheby[i][0]
xi = i
if cheby[i][1] > ymax :
ymax = cheby[i][1]
ya = i
if cheby[i][1] < ymin :
ymin = cheby[i][1]
yi = i
if abs(xmax-xmin) > abs(ymax-ymin):
print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))
|
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
lst = [None, ]
for _ in range(n):
x, y = LI()
lst.append((x,y))
per = itertools.permutations(range(1,n+1))
sm = 0
oc = math.factorial(n)
for p in per:
dist = 0
before = p[0]
for place in p[1:]:
dist += math.sqrt((lst[place][0]-lst[before][0])**2 + (lst[place][1]-lst[before][1])**2)
before = place
sm += dist
ans = sm/oc
print(ans)
main()
| 0 | null | 76,084,332,388,512 | 80 | 280 |
a,b,c= map(int,input().split())
if c>a+b and 4*a*b<(c-a-b)*(c-a-b):
print('Yes')
else:
print('No')
|
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
N = int(input())
N_div = make_divisors(N)[1:]
N1_div = make_divisors(N-1)[1:]
ans = len(N1_div)
for i in N_div:
n = N
while n % i == 0:
n //= i
if n % i == 1:
ans += 1
print(ans)
| 0 | null | 46,467,805,279,990 | 197 | 183 |
n,x,t = map(int,input().split())
c = n//x
if n%x>0:
c+=1
print(t*c)
|
line = input().split()
total = int(line[0])
lim = int(line[1])
time = int(line[2])
ans = total//lim
amari = total%lim
if amari == 0:
ans2 = ans*time
else:
ans2 = (ans + 1)*time
print(ans2)
| 1 | 4,264,987,073,772 | null | 86 | 86 |
data = input().split()
n = data[0]
m = data[1]
if n == m:
print("Yes")
else:
print("No")
|
S=input()
if S.count('A')==1 or S.count('A')==2:
print('Yes')
else:
print('No')
| 0 | null | 69,183,126,295,812 | 231 | 201 |
S = list(input())
K = int(input())
N = len(S)
left = 1
while left < N and S[0] == S[left]:
left += 1
right = 0
while N - 1 - right and S[0] == S[N - 1 - right]:
right += 1
S += S
cnt = 0
for i in range(len(S) - 1):
if S[i + 1] == S[i]:
S[i + 1] = 'A'
cnt += 1
if left + right < N and left % 2 != 0 and right % 2 != 0:
print(max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1))
else:
print(cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0))
|
s = input()
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
ss = s + s
shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
if s[i] == prev:
cnt += 1
else:
shoko += cnt // 2
cnt = 1
prev = s[i]
shoko += cnt // 2
kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
if ss[i] == prev:
cnt += 1
else:
kosa += cnt // 2
cnt = 1
prev = ss[i]
kosa += cnt // 2
kosa -= shoko
print(shoko + (k-1)*kosa)
| 1 | 174,796,830,855,428 | null | 296 | 296 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
k = II()
sevens = 7%k
for i in range(1, k+1):
if sevens % k == 0:
print(i)
return
sevens = (10*sevens + 7)%k
print(-1)
if __name__ == '__main__':
main()
|
K = int(input())
ai_1 = 0
for i in range(K):
ai = (10*ai_1 + 7)%K
if ai==0:
print(i+1)
exit()
ai_1 = ai
print("-1")
| 1 | 6,166,261,060,410 | null | 97 | 97 |
X = int(input())
def define_rate(X):
if X >= 1800:
return 1
elif X >= 1600:
return 2
elif X >= 1400:
return 3
elif X >= 1200:
return 4
elif X >= 1000:
return 5
elif X >= 800:
return 6
elif X >= 600:
return 7
elif X >= 400:
return 8
print(define_rate(X))
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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
X = INT()
l = [400, 600, 800, 1000, 1200, 1400, 1600, 1800]
print(9-bisect(l, X))
| 1 | 6,748,697,726,822 | null | 100 | 100 |
import sys
for x in sys.stdin:
a, op, b = x.split()
a = int(a)
b = int(b)
if op == '?':
break
elif op == '+':
print(a + b)
elif op == '-':
print(a - b)
elif op == '*':
print(a * b)
elif op == '/':
print(a // b)
|
ans = []
while True:
arr = map(str, raw_input().split())
if arr[1] is '?':
break
val = eval(arr[0] + arr[1] + arr[2])
ans.append(val)
print("\n".join(map(str, ans)))
| 1 | 681,155,087,012 | null | 47 | 47 |
N = int(input())
A = list(map(int,input().split()))
odds_or_even = N%2+2
inf = -float("inf")
dp = [[inf for _ in range(N+1)] for _ in range(odds_or_even)]
dp[0][0] = 0
for i in range(N):
dp[0][i+1] = dp[0][i]+A[i]*((i+1)%2)
for j in range(1,odds_or_even):
for i in range(N):
dp[j][i+1] = max(dp[j-1][i],dp[j][i]+A[i]*((i+j+1)%2))
print(dp[odds_or_even-1][N])
|
n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
if stone[l]=='W':
if stone[r]=='R':
ans += 1
l += 1
r -= 1
else:
r -= 1
else:
l += 1
if stone[r]=='W':
r -= 1
print(ans)
| 0 | null | 21,843,953,522,552 | 177 | 98 |
import math
a, b, C = map(int, input().split())
print('%f' % (0.5 * a * b * math.sin(math.radians(C))))
c = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(C)))
print('%f' % (a + b + c))
print('%f' % (b * math.sin(math.radians(C))))
|
import math
a,b,C = map(int, input().split())
r = C*math.pi/180
h = b*math.sin(r)
print('{0:f}'.format(a*h/2))
print('{0:f}'.format(a+b+(math.sqrt(a**2+b**2-2*a*b*math.cos(r)))))
print('{0:f}'.format(h))
| 1 | 171,085,191,488 | null | 30 | 30 |
rg = raw_input()
rg = rg.split()
if rg[0] < rg[1] < rg[2]:
print "Yes"
else:
print "No"
|
word = input()
num = int(input())
for index in range(num):
code = input().split()
instruction = code[0]
start, end = int(code[1]), int(code[2])
if instruction == "replace":
word = word[:start] + code[3] + word[end+1:]
elif instruction == "reverse":
reversed_ch = "".join(reversed(word[start:end+1]))
word = word[:start] + reversed_ch + word[end+1:]
else:
print(word[start:end+1])
| 0 | null | 1,218,533,362,160 | 39 | 68 |
a,b=[i for i in input().split()]
a=int(a)
b=round(float(b)*100)
print(a*b//100)
|
import sys
from collections import deque
d = deque()
n = int(input())
lines = sys.stdin.readlines()
for i in range(n):
ins = lines[i].split()
command = ins[0]
if command == "insert":
d.appendleft(ins[1])
elif command == "delete":
try:
d.remove(ins[1])
except:
pass
elif command == "deleteFirst":
d.popleft()
elif command == "deleteLast":
d.pop()
print(" ".join(d))
| 0 | null | 8,371,293,253,340 | 135 | 20 |
import math
n = int(input())
a = list(map(int,input().split()))
def generate_D(maxA):
seq = [i for i in range(maxA+1)]
p = 2
while p*p <= maxA:
if seq[p]==p:
for q in range(p*2,maxA+1,p):
if seq[q]==q:
seq[q] = p
p += 1
return seq
cur = a[0]
for v in a[1:]:
cur = math.gcd(cur,v)
if cur > 1:
print('not coprime')
else:
d = generate_D(max(a))
primes = set([])
tf = 1
for v in a:
tmp = set([])
while v > 1:
tmp.add(d[v])
v //= d[v]
for k in tmp:
if k in primes:
tf = 0
else:
primes.add(k)
if tf:
print('pairwise coprime')
else:
print('setwise coprime')
|
#!/usr/bin/env python3
S = input()
print(len(S) * 'x')
| 0 | null | 38,527,137,812,990 | 85 | 221 |
N,M,K=map(int,input().split())
*A,=map(int,input().split())
*B,=map(int,input().split())
def binary_search(func, array, left=0, right=-1):
if right==-1:right=len(array)-1
y_left, y_right = func(array[left]), func(array[right])
while True:
middle = (left+right)//2
y_middle = func(array[middle])
if y_left==y_middle: left=middle
else: right=middle
if right-left==1:break
return left
cumA = [0]
for i in range(N):
cumA.append(cumA[-1]+A[i])
cumB = [0]
for i in range(M):
cumB.append(cumB[-1]+B[i])
cumB.append(10**20)
if cumA[-1]+cumB[-1]<=K:
print(N+M)
exit()
if A[0] > K and B[0] > K:
print(0)
exit()
ans = 0
for i in range(N+1):
if K-cumA[i]<0:break
idx = binary_search(lambda x:x<=K-cumA[i],cumB)
res = max(0,i+idx)
ans = max(ans, res)
print(ans)
|
from itertools import accumulate
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
cumA = [0] + list(accumulate(deskA))
cumB = [0] + list(accumulate(deskB))
ans = 0
j = m
for i in range(n+1):
if cumA[i] > k:
continue
while cumA[i] + cumB[j] > k:
j -= 1
ans = max(i+j,ans)
print(ans)
| 1 | 10,790,680,118,332 | null | 117 | 117 |
N = int(input())
A = [int(i) for i in input().split()]
A = sorted(A, reverse=True)
A += A[1:]
A = sorted(A, reverse=True)
print(sum(A[:N-1]))
|
def main():
h, w, m = map(int, input().split())
hp = [0]*h
wp = [0]*w
hw = set()
for _ in range(m):
h1, w1 = map(int, input().split())
hp[h1-1] += 1
wp[w1-1] += 1
hw.add((h1, w1))
h_max = max(hp)
w_max = max(wp)
hh = [i+1 for i, v in enumerate(hp) if v == h_max]
ww = [i+1 for i, v in enumerate(wp) if v == w_max]
ans = h_max + w_max
for hb in hh:
for wb in ww:
if (hb, wb) not in hw:
print(ans)
exit()
print(ans-1)
if __name__ == '__main__':
main()
| 0 | null | 6,886,699,124,272 | 111 | 89 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
a, b = inm()
print(a * b)
|
s = input()
l = s.split(" ")
a,b = int(l[0]), int(l[1])
print(a*b)
| 1 | 15,832,589,267,140 | null | 133 | 133 |
from collections import deque
n,d,a = map(int, input().split())
ls = [list(map(int, input().split())) for i in range(n)]
ls.sort(key=lambda x:x[0])
q=deque()
ans=0
tot=0
for i in range(n):
x=ls[i][0]
h=ls[i][1]
while q and q[0][0]<x:
tot-=q[0][1]
q.popleft()
h-=tot
if h>0:
num = (h+a-1)//a
ans+=num
tot+=num*a
q.append([x+2*d,num*a])
print(ans)
|
import bisect
import math
N, D, A = map(int, input().split())
cusum = [0] * (N+1)
X = []
XH =[]
for i in range(N):
xi, hi = map(int, input().split())
X += [xi]
XH += [(xi, hi)]
X = sorted(X)
XH = sorted(XH)
cusumD = 0
ans = 0
for i, (xi, hi) in enumerate(XH):
cusumD -= cusum[i]
hi = max(0, hi-cusumD)
r = bisect.bisect_right(X, xi+2*D)
b = int(math.ceil(hi/A))
d = b * A
ans += b
cusumD += d
cusum[r] += d
print(ans)
| 1 | 82,334,587,578,122 | null | 230 | 230 |
from itertools import accumulate
N, K = map(int, input().split())
P = tuple(accumulate(map(int, input().split())))
ans = P[K - 1]
for i in range(N - K):
ans = max(P[i + K] - P[i], ans)
print((ans + K) / 2)
|
def solve():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
res = 0
for i in range(N):
if int(S[i]) % P == 0:
res += i + 1
print(res)
else:
res = 0
count = [0] * P
r = 0
for i in range(N-1, -1, -1):
r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P
if r == 0: res += 1
res += count[r]
count[r] += 1
print(res)
if __name__ == '__main__':
solve()
| 0 | null | 66,586,496,123,380 | 223 | 205 |
nums = list(input().split())
for i, j in enumerate(nums):
if j == '0':
print(i+1)
|
a=int(input())
cnt=0
t=100
while t<a:
t=(t*101)//100
cnt+=1
print(cnt)
| 0 | null | 20,350,134,299,738 | 126 | 159 |
def Judgement(x,y,z):
if z-x-y>0 and (z-x-y)**2-4*x*y>0:
return 0
else:
return 1
a,b,c=map(int,input().split())
ans=Judgement(a,b,c)
if ans==0:
print("Yes")
else:
print("No")
|
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#main code here!
x,y=MI()
ans=0
if x<=3:
ans+=(4-x)*(10**5)
if y<=3:
ans+=(4-y)*(10**5)
if x==1 and y==1:
ans+=4*10**5
print(ans)
if __name__=="__main__":
main()
| 0 | null | 96,190,315,696,258 | 197 | 275 |
a = [int(input()) for i in range(2)]
if a[0] == 1:
if a[1] == 2:
my_result = 3
else:
my_result = 2
elif a[0] == 2:
if a[1] == 1:
my_result = 3
else:
my_result = 1
else:
if a[1] == 1:
my_result = 2
else:
my_result = 1
print(my_result)
|
N = int(input())
clips = [input().split() for _ in range(N)]
X = input()
ans = 0
for i,title in enumerate(clips):
if X in title:
for j in range(i+1, N):
ans += int(clips[j][1])
break
print(ans)
| 0 | null | 103,663,890,528,630 | 254 | 243 |
import collections
def breadth_first_search(g,check,length):
q = collections.deque()
q.append(1)
check[1] = 1
length[1] = 0
while len(q) != 0:
v = q.popleft()
for u in g[v]:
if check[u] == 0:
check[u] = 1
length[u] = length[v]+1
q.append(u)
return length
def main():
N = int(input())
g = []
g.append([])
for i in range(N):
tmp = input().split()
tmp_ls = []
for i in range(int(tmp[1])):
tmp_ls.append(int(tmp[i+2]))
g.append(tmp_ls)
check = [0]*(N+1)
length = [0]*(N+1)
ans = breadth_first_search(g,check,length)
for i in range(N):
node_num = i+1
if ans[node_num] == 0 and i != 0:
ans[node_num] = -1
print(node_num,ans[node_num])
main()
|
n = int(input())
S = []
H = []
C = []
D = []
for x in range(0,n):
L = raw_input().split()
if L[0] == "S": S.append(int(L[1]))
elif L[0] == "H": H.append(int(L[1]))
elif L[0] == "C": C.append(int(L[1]))
else: D.append(int(L[1]))
for x in range(1,14):
if not x in S: print "S {}".format(x)
for x in range(1,14):
if not x in H: print "H {}".format(x)
for x in range(1,14):
if not x in C: print "C {}".format(x)
for x in range(1,14):
if not x in D: print "D {}".format(x)
| 0 | null | 537,141,481,348 | 9 | 54 |
import random
name = str(input())
a = len(name)
if 3<= a <= 20:
b = random.randint(0,a-3)
ada_1 = name[b]
ada_2 = name[b+1]
ada_3 = name[b+2]
print(ada_1+ada_2+ada_3)
else:
None
|
n=int(input())
print(1-(n//2)/n)
| 0 | null | 95,523,212,730,442 | 130 | 297 |
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
ai = list(map(int, input().split()))
a.append(ai)
for i in range(m):
bi = int(input())
b.append(bi)
for i in range(n):
ci = 0
for j in range(m):
ci += a[i][j] * b[j]
print(ci)
|
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]
| 1 | 1,185,197,369,938 | null | 56 | 56 |
r,c = map(int, raw_input().split())
col_sum = [0] * (c+1)
for i in range(r):
row = map(int, raw_input().split())
row.append(sum(row))
col_sum = [a + b for a, b in zip(row, col_sum)]
print " ".join(map(str, row))
print " ".join(map(str, col_sum))
|
#ABC 175 C
x, k, d = map(int, input().split())
x = abs(x)
syou = x // d
amari = x % d
if k <= syou:
ans = x - (d * k)
else:
if (k - syou) % 2 == 0: #残りの動ける数が偶数
ans = amari
else:#残りの動ける数が奇数
ans = abs(amari - d)
print(ans)
| 0 | null | 3,309,585,163,390 | 59 | 92 |
#!python3
import sys
iim = lambda: map(int, input().rstrip().split())
def popcnt2(n):
a = (
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
)
ans = 0
while n:
ans += a[n&0xff]
n >>= 8
return ans
def resolve():
N = int(input())
S = list(input())
Q = int(input())
ln = N.bit_length() + 1
c0 = ord('a')
smap = [1<<(i-c0) for i in range(c0, ord('z')+1)]
T = [None] * ln
T[0] = [smap[ord(S[i])-c0] for i in range(N)]
if N&1:
T[0].append(0)
N += 1
t0, n2 = T[0], N
for i in range(1, ln):
n1 = n2 = n2 >> 1
if n2 & 1:
n2 += 1
ti = T[i] = [0] * n2
for j in range(n1):
j2 = j << 1
d1, d2 = t0[j2], t0[j2+1]
ti[j] = d1 | d2
t0 = ti
#for ti in T:
# print(len(ti), ti)
ans = []
for cmd, i, j in (line.split() for line in sys.stdin):
i = int(i) - 1
if cmd == "1":
if S[i] == j:
continue
S[i] = j
t0 = T[0]
t0[i] = smap[ord(j)-c0]
for i1 in range(1, ln):
ti = T[i1]
j1 = i >> 1
ti[j1] = t0[i] | t0[i^1]
i, t0 = j1, ti
#for ti in T:
# print(len(ti), ti)
elif cmd == "2":
j = int(j) - 1
d1 = 0
for i1 in range(ln):
ti = T[i1]
if not i < j :
if i == j:
d1 |= ti[i]
break
if i & 1:
d1 |= ti[i]
i += 1
if j & 1 == 0:
d1 |= ti[j]
j -= 1
i >>= 1; j >>=1
ans.append(popcnt2(d1))
print(*ans, sep="\n")
if __name__ == "__main__":
resolve()
|
def main():
import sys
n,s,_,*t=sys.stdin.buffer.read().split()
n=int(n)
d=[0]*n+[1<<c-97for c in s]
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
r=[]
for q,a,b in zip(*[iter(t)]*3):
i,s=int(a)+n-1,0
if q<b'2':
d[i]=1<<b[0]-97
while i:
i//=2
d[i]=d[i+i]|d[i-~i]
continue
j=int(b)+n
while i<j:
if i&1:
s|=d[i]
i+=1
if j&1:
j-=1
s|=d[j]
i//=2
j//=2
r+=bin(s).count('1'),
print(' '.join(map(str,r)))
main()
| 1 | 62,366,116,089,802 | null | 210 | 210 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.