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, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = M-1
m = sum(B)
an = M
ans = 0
for a in [0] + A:
m += a
while idx_B >= 0 and m > K:
m -= B[idx_B]
idx_B -= 1
an -= 1
if m > K:
break
if an > ans:
ans = an
an += 1
print(ans)
| import bisect
from itertools import accumulate
N, M, K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
A_cumsum = list(accumulate(A))
B_cumsum = list(accumulate(B))
max_books = 0
for a, A_sum in enumerate([0] + A_cumsum):
if A_sum > K:
break
else:
b = bisect.bisect(B_cumsum, K - A_sum)
max_books = max(a + b, max_books)
print(max_books)
| 1 | 10,791,520,517,778 | null | 117 | 117 |
for c in input():
if c.isupper():
print(c.lower(), end='')
elif c.islower():
print(c.upper(), end='')
else:
print(c, end='')
print() | import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
X = int(input())
ans = min(8, 10-X//200)
print(ans) | 0 | null | 4,123,960,993,912 | 61 | 100 |
x = int(input())
flag = 0
for a in range(x):
b5 = a**5 - x
for b in range(120):
if abs(b5) == int(b**5):
if b5 < 0:
b = -b
flag = 1
break
if flag:
break
print(a, int(b))
| from sys import stdin,stdout
# n,e=list(map(int,stdin.readline().split()))
n=int(stdin.readline())
for a in range(-400,400):
for b in range(-400,400):
if abs(a**5-b**5)==n:
print(max(a,b),min(a,b))
exit(0) | 1 | 25,560,749,673,760 | null | 156 | 156 |
n,q = map(int,input().split())
queue = []
for i in range(n):
p,t = map(str,(input().split()))
t = int(t)
queue.append([p,t])
total_time = 0
while len(queue) > 0:
x = queue.pop(0)
if x[1] > q :
total_time += q
x[1] -= q
queue.append(x)
else:
total_time += x[1]
print(x[0],total_time) | n, q = map(int, raw_input().split())
A = [[0, 0] for i in range(n)]
for i in range(n):
temp = raw_input().split()
A[i][0] = temp[0]
A[i][1] = int(temp[1])
time = 0
while A != []:
if A[0][1] - q > 0:
A[0][1] = A[0][1] - q
time = time + q
A.append(A.pop(0))
else:
print A[0][0],
print time + A[0][1]
time = time + A[0][1]
A.pop(0) | 1 | 42,996,597,560 | null | 19 | 19 |
H,N = map(int,input().split())
A = list(map(int,input().split()))
All = sum(A)
if H - All > 0:
print("No")
else:
print("Yes") | # 問題文誤読して30分経過してた
# ソートしたとき「自分より小さいいずれの値も自分の素因数に含まれない」
# これはなんか実装しにくいので、A<10^6を利用して、調和級数的なノリでやってみる
n = int(input())
a = sorted(list(map(int, input().split())))
t = {}
for av in a:
if av not in t:
t[av] = 1
else:
t[av] += 1
limit = a[-1]
d = [True] * (limit + 1)
for av in a:
start = av
# 複数あった場合は自分自身も粛清の対象になる
if t[av] == 1:
start *= 2
for i in range(start, limit + 1, av):
d[i] = False
ans = 0
for av in a:
if d[av]:
ans += 1
print(ans) | 0 | null | 46,013,916,228,758 | 226 | 129 |
s = input()
l = len(s)
ans = 'x' * l
print(ans) | n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
def make_sumlist(book_list):
sumnum=0
container=[0]
for i in book_list:
container.append(sumnum+i)
sumnum+=i
return container
total_a=make_sumlist(a)
total_b=make_sumlist(b)
# print(n,m,k)
# print(total_a)
# print(total_b)
#r個読めるか
def readable(r):
#全部読んでも無理
if r>n+m:
return False
if r==0:
return True
max_book=100000000000
for a_n in range(max(0,r-m),min(n,r)+1):
b_n=r-a_n
# print(a_n,b_n)
book_sum=total_a[a_n]+total_b[b_n]
# print(book_sum)
max_book=min(max_book,book_sum)
if max_book<=k:
return True
return False
def nibuntansaku(start,end):
if start==end:
return start
middle=(start+end)//2+1
if readable(middle):
start=middle
else:
end=middle-1
return nibuntansaku(start,end)
print(nibuntansaku(0,k))
| 0 | null | 41,866,778,466,858 | 221 | 117 |
import math
r = float(input())
print("{0:.6f} {1:.6f}".format(math.pi*r**2, 2*math.pi*r))
| import math
r = input()
l = math.pi*r*2.0
s = r*r*math.pi
print "%f %f" %(s, l) | 1 | 638,103,435,818 | null | 46 | 46 |
n = int(input())
lst = []
while n % 2 == 0:
lst.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
lst.append(f)
n //= f
else:
f += 2
if n != 1:
lst.append(n)
#print(lst)
count = 0
while lst:
s = 0
i = 1
num = lst[0]
for ele in lst:
if ele == num:
s += 1
for j in range(s):
lst.remove(num)
while s > 0:
s -= i
i += 1
if s >= 0:
count += 1
#print(lst)
print(count) | def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
n = int(input())
cnt = 0
lis = list(set(prime_factorize(n)))
for i in range(len(lis)):
for j in range(1, 10**9):
if n % lis[i]**j == 0:
n /= lis[i]**j
cnt+=1
else:
break
print(cnt)
| 1 | 16,761,780,587,500 | null | 136 | 136 |
N = int(input())
A = list(int(input()) for _ in range(N))
def ins_sort(a, n, g):
count = 0
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
count += 1
a[j+g] = v
return count
def shell_sort(a, n):
cnt = 0
*g, = []
h = 0
for i in range(0, n):
h = h * 3 + 1
if h > n:
break
g.insert(0, h)
m = len(g)
for i in range(0, m):
cnt += ins_sort(a, n, g[i])
print(m)
print(*g)
print(cnt)
for i in range(len(a)):
print(a[i])
shell_sort(A, N)
| n = int(input())
A = [None] * n
for i in range(n):
A[i] = int(input())
def insertionSort(A, n, g):
cnt = 0
for i in range(g, n, 1):
# Insertion Sort
# e.g. if g == 4 and i == 8: [4] 6 2 1 [10] 8 9 5 [3] 7
j = i - g # e.g. j = 4
k = i # e.g. k = 8
while j >= 0 and A[j] > A[k]:
#print("i:{} j:{} k:{} A:{}".format(i, j, k, A))
A[j], A[k] = A[k], A[j]
k = j # e.g. k = 4
j = k - g # e.g. j = 4 - 0 = 0
cnt += 1
#print("j reduced to {}, k reduced to {}".format(j, k))
return(cnt)
def shellSort(A, n):
g = [0]
m = 0
sum = 0
while True:
if (3*m + 1 <= n):
g.insert(0, 3*m + 1)
m = 3*m + 1
else:
break
for i in range(len(g)):
cnt = insertionSort(A, n, g[i])
sum += cnt
print(len(g))
print(str(g).replace('[', '').replace(']', '').replace(',', ''))
print(sum)
for i in range(n):
print(A[i])
def main():
shellSort(A, n)
main()
| 1 | 31,198,379,734 | null | 17 | 17 |
n = int(input())
cum = 0
d = dict()
for _ in range(n):
a, b = input().split()
b = int(b)
cum += b
d[a] = cum
c = input()
print(cum - d[c]) | r = int(input())
print((r * 2) * 3.141592) | 0 | null | 63,813,512,275,780 | 243 | 167 |
def main2():
N = int(input())
mod = 10**9 + 7
ans = 10**N - 9**N - 9**N + 8**N
print(ans % mod)
if __name__ == "__main__":
main2() | import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
N = I()
X = LI2()
X.reverse()
if N == 1 and len(X) == 1 and X[0] == 0:
print(1)
exit()
def popcount(n):
res = 0
m = n.bit_length()
for i in range(m):
res += (n >> i) & 1
return res
# 1回の操作で 2*10**5 未満になることに注意
F = [0]*(2*10**5) # F[i] = f(i)
for i in range(1,2*10**5):
F[i] = 1 + F[i % popcount(i)]
a = sum(X)
b = a-1
c = a+1
if a == 1:
C = [1] # 2冪をcで割った余り
xc = 0 # Xをcで割った余り
for i in range(N):
if X[i] == 1:
xc += C[-1]
xc %= c
C.append((2 * C[-1]) % c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(0)
else:
ANS.append(1 + F[(xc + C[i]) % c])
ANS.reverse()
print(*ANS, sep='\n')
exit()
B,C = [1],[1] # 2冪をb,cで割った余り
xb,xc = 0,0 # Xをb,cで割った余り
for i in range(N):
if X[i] == 1:
xb += B[-1]
xc += C[-1]
xb %= b
xc %= c
B.append((2*B[-1])%b)
C.append((2*C[-1])%c)
ANS = []
for i in range(N):
if X[i] == 1:
ANS.append(1 + F[(xb-B[i]) % b])
else:
ANS.append(1 + F[(xc+C[i]) % c])
ANS.reverse()
print(*ANS,sep='\n')
| 0 | null | 5,675,872,670,432 | 78 | 107 |
# coding: utf-8
def solve(*args: str) -> str:
n = int(args[0])
A = list(map(int, args[1].split()))
rem = sum(A)
cur = 1
ret = 0
for a in A:
cur = min(rem, cur)
rem -= a
ret += cur
cur = 2*(cur-a)
if cur < 0:
ret = -1
break
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
| N = int(input())
A = tuple(map(int, input().split()))
S = [0]
for a in reversed(A):
S.append(S[-1] + a)
S.reverse()
lst = [0] * (N + 2)
lst[0] = 1
for i, a in enumerate(A):
if lst[i] < a:
print(-1)
break
lst[i + 1] = min((lst[i] - a) * 2, S[i + 1])
else:
print(sum(lst))
| 1 | 18,935,445,028,430 | null | 141 | 141 |
import sys
sys.setrecursionlimit(10**8)
def find(x):
if par[x]==x:
return x
else:
par[x]=find(par[x])
return par[x]
def union(a,b):
a=find(a)
b=find(b)
if a==b:
return
if rank[a]<rank[b]:
par[a]=b
rank[b]+=rank[a]
rank[a]=rank[b]
else:
par[b]=a
rank[a]+=rank[b]
rank[b]=rank[a]
return
def chk(a,b):
if par[a]==par[b]:
print('Yes')
else:
print('No')
return
N,M=map(int, input().split())
par=(list(range(N+1)))
rank=[1]*(N+1)
for _ in range(M):
A,B=map(int, input().split())
union(A,B)
print(max(rank)) | i = 1
while True:
num = int(input())
if num == 0:
break
print('Case {}: {}'.format(i, num))
i+=1
| 0 | null | 2,193,634,837,120 | 84 | 42 |
import fractions
def is_lcm(X, Y):
return X*Y // fractions.gcd(X, Y)
N, M = map(int, input().split())
print(is_lcm(N, M)) | MOD = 10 ** 9 + 7
n, k = map(int, input().split())
ans = 0
for x in range(k, n + 2):
p = x * (x - 1) // 2
q = x * (x - 1) // 2 + (n - x + 1) * x
ans += q - p + 1
print(ans % MOD)
| 0 | null | 72,905,854,349,692 | 256 | 170 |
n=int(input())
z_max,z_min=-10**10,10**10
w_max,w_min=-10**10,10**10
for i in range(n):
a,b=map(int,input().split())
z=a+b
w=a-b
z_max=max(z_max,z)
z_min=min(z_min,z)
w_max=max(w_max,w)
w_min=min(w_min,w)
print(max(z_max-z_min,w_max-w_min)) | N = int(input())
taro_p = hana_p = 0
for n in range(N):
tw,hw = input().split()
if tw == hw:
taro_p += 1
hana_p += 1
elif tw < hw:
hana_p += 3
else :
taro_p += 3
print(taro_p,hana_p) | 0 | null | 2,719,844,158,748 | 80 | 67 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
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())
from collections import defaultdict
from collections import Counter
import bisect
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
N = S()
K = I()
dig = len(N)
if dig < K:
print(0)
exit()
ans = 0
for i in range(dig):
if K == 0:
ans += 1
break
if int(N[i]) == 0:
continue
if dig - i - 1 >= K:
ans += combinations_count(dig - i - 1, K) * pow(9, K)
if dig - i - 1 >= K - 1:
ans += (int(N[i]) - 1) * combinations_count(dig - i - 1, K - 1) * pow(9, K - 1)
if i == dig - 1:
ans += 1
K -= 1
print(ans)
if __name__ == "__main__":
main()
| i = range(1,10)
for i in ['%dx%d=%d' % (x,y,x*y) for x in i for y in i]:
print i | 0 | null | 37,716,709,453,160 | 224 | 1 |
"""ABC174E diff: 1158
"""
N,K=map(int,input().split())
A=list(map(int, input().split()))
if K == 0:
print(max(A))
exit()
def f(x):
"""
K回以内のカットで全ての丸太の長さをX以下にできるか?
X: int
Return: bool
"""
cnt = 0
for a in A:
if a % x == 0:
cnt += a//x - 1
else:
cnt += a//x
if cnt <= K:
return True
else:
return False
left = 0
right = max(A) + 10
while right - left > 1:
mid = (left+right) // 2
if f(mid):
right = mid
else:
left = mid
print(right) | def main():
log_no, cut_max = [int(x) for x in input().split()]
logs = [int(x) for x in input().split()]
bin_l, bin_r = 0, 10 ** 9
while bin_r - bin_l > 1:
bin_mid = (bin_l + bin_r) // 2
cut_count = sum((log - 1) // bin_mid for log in logs)
if cut_count <= cut_max:
bin_r = bin_mid
else:
bin_l = bin_mid
print(bin_r)
if __name__ == '__main__':
main()
| 1 | 6,484,937,521,850 | null | 99 | 99 |
n=int(input())
r=[int(input()) for i in range(n)]
maxv=r[1]-r[0]
minv=r[0]
for i in range(1,n):
maxv=max(maxv,r[i]-minv)
minv=min(minv,r[i])
print(maxv)
| n = input()
Max = -4300000000
Min = input()
for i in range(n - 1):
IN_NOW = input()
Max = max(Max, (IN_NOW - Min))
Min = min(Min, IN_NOW)
print Max | 1 | 12,986,260,378 | null | 13 | 13 |
a, b, c = map(int, input().split())
divisitor = []
for i in range(a, b+1):
if a < 0 or b < 0 or c < 0:
break
elif a > 10001 or b > 10001 or c > 10001:
break
elif a > b:
break
elif c % i == 0:
divisitor.append(int(c/i))
print((len(divisitor))) | a,b,c = [int(i) for i in input().split()]
i=0
for num in range(a,b+1,1):
if c % num == 0:
i = i+1
else:
pass
print(i)
| 1 | 555,256,313,520 | null | 44 | 44 |
n = int(raw_input())
num = map(int, raw_input().split())
num.reverse()
print " ".join(map(str, num))
|
def main():
a, b = map(int, input().split())
print(a*b)
if __name__ == '__main__':
main()
| 0 | null | 8,392,106,424,220 | 53 | 133 |
import numpy as np
n=int(input())
d_i = list(map(int, input().split()))
d=np.array(d_i)
out=0
for i in range(1,n):
a=d_i.pop(0)
d_i.append(a)
out+=np.dot(d,np.array(d_i))
print(int(out/2)) | N=int(input())
d=list(map(int,input().split()))
l=len(d)
s=0
for i in range(l):
for j in range(i+1,l):
s+=d[i]*d[j]
print(s) | 1 | 168,020,890,476,738 | null | 292 | 292 |
N, M = map(int, input().split())
A = input().split()
work_days = 0
for i in range(M):
work_days += int(A[i])
if work_days > N:
print(-1)
else:
print(N - work_days) | a, b = list(map(int, input().split()))
if a < b:
a, b = b, a
while True:
if b == 0:
break
tmp = a % b
a = b
b = tmp
print(a)
| 0 | null | 15,942,318,270,052 | 168 | 11 |
import sys
import math
for n in [int(math.log10(float(int(line.split()[0])+int(line.split()[1]))))+1 for line in sys.stdin]:
print n | import sys
import math
for line in sys.stdin:
try:
a, b = [int(i) for i in line.split()]
print(int(math.log10(a + b) + 1))
except:
break | 1 | 142,884,782 | null | 3 | 3 |
inp = [int(a) for a in input().split()]
X = inp[0]
N = inp[1]
if N == 0:
print(X)
else:
P = [int(b) for b in input().split()]
found = 0
num = 0
answer = X
while(found == 0):
if not (X - num in P):
found = 1
answer = X - num
elif not (X + num in P):
found = 1
answer = X + num
num += 1
print(answer) | import sys
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
if p[i] == 0:
print(0)
sys.exit()
product = 1
for i in range(N):
product = product * p[i]
if product > 10 ** 18:
print(-1)
sys.exit()
break
print(product) | 0 | null | 15,000,755,536,130 | 128 | 134 |
def merge(A, left, mid, right):
L = A[left:mid] + [int(1e9)]
R = A[mid:right] + [int(1e9)]
i,j = 0,0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
global count
count += (right - left)
def merge_sort(A, left, right):
if left+1 < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
if __name__=='__main__':
n = int(input())
A = list(map(int, input().strip().split()))
count = 0
merge_sort(A, 0, n)
print(" ".join(map(str, A)))
print(count) | def merge(a,left,mid,right):
count=0
L=a[left:mid]+[float("inf")]
R=a[mid:right]+[float("inf")]
i,j=0,0
for k in range(left,right):
count+=1
if L[i]<=R[j]:
a[k]=L[i]
i+=1
else:
a[k]=R[j]
j+=1
return count
def mergeSort(a,left,right):
if left+1<right:
mid=(left+right)//2
countl=mergeSort(a,left,mid)
countr=mergeSort(a,mid,right)
return merge(a,left,mid,right)+countl+countr
return 0
n=int(input())
a=list(map(int,input().split()))
ans=mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(ans)
| 1 | 111,444,813,006 | null | 26 | 26 |
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (10**6 + 1)
for i in range(N):
cnt[A[i]] += 1
flag = True
for i in range(2, 10**6 + 1):
multiple = 0
for j in range(i, 10**6 + 1, i):
multiple += cnt[j]
if multiple == N:
print("not coprime")
exit()
if multiple >= 2:
flag = False
print("pairwise coprime" if flag else "setwise coprime")
| import sys
t = input()
answerCount = 0
stringList = []
while True:
line = input()
if line == "END_OF_TEXT":
break
for i in range(len(str(line).lower().split())):
stringList.append(str(line).lower().split()[i])
if str(line).lower().split()[i] == t:
answerCount += 1
print(answerCount)
| 0 | null | 2,976,332,194,540 | 85 | 65 |
N = int(input())
X = list(map(int, input().split()))
MAX = 10 ** 6 + 1
prime = [True] * MAX
counted = set()
for v in X:
if v in counted:
prime[v] = False
continue
for j in range(2 * v, MAX, v):
prime[j] = False
counted.add(v)
ans = 0
for v in X:
ans += int(prime[v])
print(ans)
| def main():
s = str(input())
dic = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}
print(dic.get(s))
main() | 0 | null | 73,812,221,223,200 | 129 | 270 |
cards = int(input())
i = 0
cardlist = []
while(i < cards):
cardlist.append(list(map(str,input().split())))
i += 1
SP = [False] * 13
HR = [False] * 13
CL = [False] * 13
DY = [False] * 13
for i in cardlist:
num = int(i[1])-1
if (i[0] == "S"):
SP[num] = True
elif(i[0] == "H"):
HR[num] = True
elif(i[0] == "C"):
CL[num] = True
elif(i[0] == "D"):
DY[num] = True
c = 0
for i in SP:
c += 1
if i == False:
print("S %d" %c)
c = 0
for i in HR:
c += 1
if i == False:
print("H %d" %c)
c = 0
for i in CL:
c += 1
if i == False:
print("C %d" %c)
c = 0
for i in DY:
c += 1
if i == False:
print("D %d" %c)
| n = int(raw_input())
C = {'S':range(13), 'H':range(13), 'C':range(13), 'D':range(13)}
for i in range(n):
suit, num = raw_input().split()
num = int(num)
C[suit][num-1] = 14
for i in ['S', 'H', 'C', 'D']:
for j in range(13):
if C[i][j] != 14:
print "%s %d" %(i, j+1) | 1 | 1,032,950,627,548 | null | 54 | 54 |
class UnionFind():
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()}
n, m, k = map(int, input().split())
fr = UnionFind(n)
bl = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
bl[a-1].append(b-1)
bl[b-1].append(a-1)
fr.union(a-1, b-1)
for _ in range(k):
c, d = map(int, input().split())
if fr.same(c-1, d-1):
bl[c-1].append(d-1)
bl[d-1].append(c-1)
ans = []
for i in range(n):
s = fr.size(i) - len(bl[i]) - 1
ans.append(s)
print(*ans) | op = "$"
while op != "?":
a, op, c = map(str, raw_input().split())
a = int(a)
c = int(c)
if op == "+":
print u"%d" % (a+c)
elif op == "-":
print u"%d" % (a-c)
elif op == "*":
print u"%d" % (a*c)
elif op == "/":
print u"%d" % (a/c)
else:
break | 0 | null | 30,973,661,260,502 | 209 | 47 |
S=input()
Sa=len(S)
a="x"*Sa
print(a) | S = input()
result = ''
for _ in S:
result += 'x'
print(result) | 1 | 72,881,672,706,824 | null | 221 | 221 |
# -*- coding: utf-8 -*-
import sys
import numpy as np
N,S, *A = map(int, sys.stdin.buffer.read().split())
mod = 998244353
answer = np.zeros(S+1).astype(np.int64)
answer[0] = 1
for a in A:
if a<=S:
answer[a:] = (2*answer[a:]+answer[:-a])%mod
answer[:a] = (2*answer[:a])%mod
else:
answer = (2*answer)%mod
print(answer[S]) | while True:
try:
a, b = list(map(int, input().split()))
print(len(str(a + b)))
except EOFError:
break
except ValueError:
break
| 0 | null | 8,771,179,401,390 | 138 | 3 |
#初期定義
global result
global s_list
result = 0
#アルゴリズム:ソート
def merge(left, mid, right):
global result
n1 = mid - left
n2 = right - mid
inf = 10**9
L_list = s_list[left: mid] + [inf]
R_list = s_list[mid: right] + [inf]
i = 0
j = 0
for k in range(left, right):
result += 1
if L_list[i] <= R_list[j]:
s_list[k] = L_list[i]
i += 1
else:
s_list[k] = R_list[j]
j += 1
#アルゴリズム:マージソート
def mergeSort(left, right):
if (left + 1) < right:
mid = (left + right) // 2
mergeSort(left, mid)
mergeSort(mid, right)
merge(left, mid, right)
#初期値
n = int(input())
s_list = list(map(int, input().split()))
#処理の実行
mergeSort(0, n)
#結果の表示
print(" ".join(map(str, s_list)))
print(result)
| comp = 0
def m(L, R):
global comp
j = 0
for l in L:
while j < len(R) and R[j] < l:
yield R[j]
j += 1
yield l
while j < len(R):
yield R[j]
j += 1
comp += len(L) + len(R)
def merge(A):
global comp
if len(A) == 1:
return A
if len(A) == 2:
comp += 2
a, b = A
return A if a < b else (b, a)
mid = len(A) // 2
A[:] = m(merge(A[:mid]), merge(A[mid:]))
return A
n, *A = map(int, open(0).read().split())
B = merge(A)
print(*B)
print(comp) | 1 | 113,241,660,112 | null | 26 | 26 |
class Dice:
def __init__(self):
self.faces=[]
def rotate(self, direction):
tmp = self.faces.copy()
if direction =="N":
self.faces[5-1] = tmp[1-1]
self.faces[1-1] = tmp[2-1]
self.faces[2-1] = tmp[6-1]
self.faces[6-1] = tmp[5-1]
if direction =="S":
self.faces[5-1] = tmp[6-1]
self.faces[1-1] = tmp[5-1]
self.faces[2-1] = tmp[1-1]
self.faces[6-1] = tmp[2-1]
if direction =="W":
self.faces[4-1] = tmp[1-1]
self.faces[1-1] = tmp[3-1]
self.faces[3-1] = tmp[6-1]
self.faces[6-1] = tmp[4-1]
if direction =="E":
self.faces[3-1] = tmp[1-1]
self.faces[1-1] = tmp[4-1]
self.faces[4-1] = tmp[6-1]
self.faces[6-1] = tmp[3-1]
return 0
def spin(self):
self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\
self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]
return 0
d1 = Dice()
d1.faces=[int(x) for x in input().split(" ")]
lines = int(input())
for i in range(lines):
up, front = map(int, input().split(" "))
#set up side
for _ in range(3):
if d1.faces[0] == up:
break
d1.rotate("N")
for _ in range(3):
if d1.faces[0] == up:
break
d1.rotate("W")
#set front side
for _ in range(3):
if d1.faces[1] == front:
break
d1.spin()
print(d1.faces[2]) | # -*- coding: utf-8 -*-
from sys import stdin
class Dice:
def __init__(self,dicelist):
self.dice_list = dicelist
def roll(self, direction):
work = list(self.dice_list)
if (direction == 'N'):
self.dice_list[0] = work[1]
self.dice_list[1] = work[5]
self.dice_list[2] = work[2]
self.dice_list[3] = work[3]
self.dice_list[4] = work[0]
self.dice_list[5] = work[4]
elif (direction == 'E'):
self.dice_list[0] = work[3]
self.dice_list[1] = work[1]
self.dice_list[2] = work[0]
self.dice_list[3] = work[5]
self.dice_list[4] = work[4]
self.dice_list[5] = work[2]
elif (direction == 'S'):
self.dice_list[0] = work[4]
self.dice_list[1] = work[0]
self.dice_list[2] = work[2]
self.dice_list[3] = work[3]
self.dice_list[4] = work[5]
self.dice_list[5] = work[1]
elif (direction == 'W'):
self.dice_list[0] = work[2]
self.dice_list[1] = work[1]
self.dice_list[2] = work[5]
self.dice_list[3] = work[0]
self.dice_list[4] = work[4]
self.dice_list[5] = work[3]
def roll_until_index0top(self,num0):
if self.dice_list[0] == num0:
return
commands = ['E', 'E', 'E', 'N', 'N', 'N']
for c in commands:
self.roll(c)
if self.dice_list[0] == num0:
return
else:
print('error')
def get_index_by_number(self, num):
for i in range(len((self.dice_list))):
if self.dice_list[i] == num:
return i
else:
return -1
def get_index2_number(self, num1):
index1 = self.get_index_by_number(num1)
if index1 == 1:
return self.dice_list[2]
elif (index1 == 2):
return self.dice_list[4]
elif (index1 == 3):
return self.dice_list[1]
elif (index1 == 4):
return self.dice_list[3]
else:
print('error 2')
def getTop(self):
return self.dice_list[0]
dice_list = list(map(int, stdin.readline().rstrip().split()))
q = int(stdin.readline().rstrip())
dice = Dice(dice_list)
for i in range(q):
num0_num1 = list(map(int, stdin.readline().rstrip().split()))
dice.roll_until_index0top(num0_num1[0])
print(dice.get_index2_number(num0_num1[1]))
| 1 | 258,293,362,880 | null | 34 | 34 |
# FizzBuzz Sum
N = int(input())
ans = ((1+N) * N)/2 - ((3 + 3*(N//3)) * (N//3))/2 - ((5 + 5*(N//5)) * (N//5))/2 + ((15 + 15*(N//15)) * (N//15))/2
print(int(ans)) | import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
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())
N = I()
cnt = 0
for i in range(1,N + 1):
if i % 3 != 0 and i % 5 != 0:
cnt += i
print(cnt) | 1 | 34,955,918,944,560 | null | 173 | 173 |
from collections import defaultdict
N, X, Y = map(int, input().split())
ctr = defaultdict(int)
for u in range(1, N):
for v in range(u + 1, N + 1):
d = min(v - u, abs(u - X) + 1 + abs(Y - v))
ctr[d] += 1
for n in range(1, N):
print(ctr[n])
| def stringconcant(S,T):
a=S
b=T
c=a+b
return c
S,T = input().split()
a = stringconcant(T,S)
print(a) | 0 | null | 73,229,586,533,052 | 187 | 248 |
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = [int(s) for s in input().split()]
print(sum([t in S for t in T])) | n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
ans = 0
for i in T:
if i in S:
ans += 1
print ans | 1 | 68,316,374,438 | null | 22 | 22 |
num_cnt = int(input().rstrip())
nums = list(map(int, input().rstrip().split(" ")))
for i in range(num_cnt):
tmpNum = nums[i]
j = i -1
while j >=0:
if nums[j] <= tmpNum:
break
nums[j+1] = nums[j]
j = j-1
nums[j+1] = tmpNum
print (" ".join(map(str,nums))) | import sys
A,B = map(int,input().split())
if not ( 1 <= A <= 20 ): sys.exit()
if not ( 1 <= B <= 20 ): sys.exit()
if not (isinstance(A,int) and isinstance(B,int)): sys.exit()
print(A*B) if A <= 9 and B <= 9 else print(-1) | 0 | null | 79,078,198,677,200 | 10 | 286 |
from functools import reduce
rpn = lambda s: int(reduce(
lambda x, y: (
x[:-2] + [str(eval(x[-2]+y[0]+x[-1]))] if y in '+-*'
else x + [y]
), s.split(), []
)[0])
print(rpn(input()))
| W,H,x,y,r=map(int,input().split())
if x-r<0 or y-r<0 or x+r>W or y+r>H :
print("No")
else:
print("Yes")
| 0 | null | 250,719,793,886 | 18 | 41 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
# 区間スケジューリング問題
# 区間の集合の中から、重ならないように最大で何個選べるかを問う問題である。
# 区間を「終端が早い順」にソートして、とれる順にとる Greedy で解くことができる。
# XL<-区間の集合
def main():
N = int(input())
XL = [None] * N
for n in range(N):
X, L = map(int,input().split())
XL[n] = (X-L,X+L)
XL.sort(key=lambda x:x[1])
ret = 0
TMP = XL[0][0]
for x in XL:
if TMP <= x[0]:
TMP = x[1]
ret += 1
print(ret)
if __name__ == '__main__':
main() | x1,x2,x3,x4,x5 = map(int,input().split())
P=[x1,x2,x3,x4,x5]
for i in range(5):
if P[i]==0:
print(str(i+1))
else:
continue | 0 | null | 51,840,940,231,290 | 237 | 126 |
import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *D = map(int, read().split())
csum = accumulate(D)
ans = sum(s * d for s, d in zip(csum, D[1:]))
print(ans)
return
if __name__ == '__main__':
main()
| import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
d,t,s = map(int, input().split())
if d <= t*s:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 0 | null | 86,173,285,178,968 | 292 | 81 |
n,m = map(int,raw_input().split())
A = [[0 for i in range(m)] for i in range(n)]
B = [ 0 for i in range(m)]
for i in range(n):
A[i] = map(int,raw_input().split())
for i in range(m):
B[i] = input()
for i in range(n):
sum = 0
for j in range(m):
sum += A[i][j] * B[j]
print sum | n, m = list(map(int, input().split()))
mat = [list(map(int, input().split())) for _ in range(n)]
vec = [int(input()) for _ in range(m)]
for v in mat:
print(sum(a * b for a, b in zip(v, vec))) | 1 | 1,156,111,503,680 | null | 56 | 56 |
from math import atan, degrees
a,b,x= map(int,input().split())
yoseki = a**2*b
if x <= yoseki/2:
# b*y*a/2==x
y= 2*x/b/a
# 90からシータを引けば良い
print(90-degrees(atan(y/b)))
else:
# a*y*a/2==yoseki-x
y = 2*(yoseki-x)/a**2
print(degrees(atan(y/a)))
|
[a,b,x] = list(map(int,input().split()))
import math
S = x/a
if S > (a*b)/2:
c = (2*S)/a - b
out = math.degrees(math.atan((b-c)/a))
else:
c = (2*S)/b
out = math.degrees(math.atan(b/c))
print(out)
| 1 | 163,194,449,750,230 | null | 289 | 289 |
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)
| N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]
win_point = {
'r': r,
's': s,
'p': p,
}
next_hands = {
'r': ['s', 'p'],
's': ['r', 'p'],
'p': ['r', 's'],
}
enemy_hands = input()
def can_win(enemy_hand, my_hands):
# 勝てる場合にはTrueと勝てる手を教えてくれる
if enemy_hand == 'r' and 'p' in my_hands:
return True, 'p'
if enemy_hand == 's' and 'r' in my_hands:
return True, 'r'
if enemy_hand == 'p' and 's' in my_hands:
return True, 's'
# 勝てる手がない場合
return False, None
point = 0
for index in range(K):
now_hands = ['r', 'p', 's']
for i in range(index, N, K):
win, hand = can_win(enemy_hands[i], now_hands)
if win:
point += win_point[hand]
now_hands = next_hands[hand]
else:
# 勝てない場合次似邪魔しない手を選ぶ
# 勝てない回の次は必ず勝てるため全手出せる前提とする
now_hands = ['r', 'p', 's']
print(point)
| 1 | 107,263,469,596,260 | null | 251 | 251 |
A,B = input().split()
from decimal import Decimal
A = Decimal(A)
B = Decimal(B)
ans = A*B
ans = str(ans)
n = len(ans)
s = ''
for i in range(n):
if ans[i] == '.':
break
s += ans[i]
print(s) | def main():
n=int(input())
s,t= list(map(str,input().split()))
ans=""
for i in range(0,n):
ans+=s[i]+t[i]
print(ans)
main() | 0 | null | 64,346,919,545,680 | 135 | 255 |
sum = 0
while 1:
x = int(raw_input())
sum = sum + 1
if x == 0:
break
print 'Case %s: %s' %(sum, x) | i = 0
while True:
t = int(input())
if t == 0:
break
else:
i += 1
print('Case '+str(i)+': '+str(t)) | 1 | 488,876,352,888 | null | 42 | 42 |
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n):
ans[a[i]-1] = i+1
ans = [str(x) for x in ans]
print(" ".join(ans)) | from decimal import Decimal
def main():
a, b = input().split(" ")
a = int(a)
b = Decimal(b)
print(int(a*b))
if __name__ == "__main__":
main() | 0 | null | 99,122,892,933,190 | 299 | 135 |
#!/usr/bin/env python3
import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy # to copy multi-dimentional matrix without reference
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float('inf') # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def mi_0(): return map(lambda x: int(x)-1, input().split())
def lmi(): return list(map(int, input().split()))
def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
def li(): return list(input())
n = ii()
l_p_only = []
r_p_only = []
r_p_l_p = []
for _ in range(n):
s = input()
left_cnt = 0
right_cnt = 0
for char in s:
if char == ')':
if left_cnt > 0:
left_cnt -= 1
else:
right_cnt += 1
else:
left_cnt += 1
if left_cnt == 0 and right_cnt == 0:
pass
elif right_cnt == 0:
l_p_only.append(left_cnt)
elif left_cnt == 0:
r_p_only.append(- right_cnt)
else:
r_p_l_p.append([- right_cnt, left_cnt])
# print(l_p_only)
# print(r_p_l_p)
# print(r_p_only)
current_left = sum(l_p_only)
pos = []
neg = []
for elm in r_p_l_p:
if elm[0] + elm[1] >= 0:
pos.append(elm)
else:
neg.append(elm)
pos.sort(key=lambda x: x[0], reverse=True) # 負の値が大きい順、0 に近い順
for elm in pos:
current_left += elm[0]
if current_left >= 0:
current_left += elm[1]
else:
print('No')
exit()
neg.sort(key=lambda x: x[0]) # 負の値が小さい順、- に大きい順に最初のうちにやっておく
for elm in neg:
current_left += elm[0]
if current_left >= 0:
current_left += elm[1]
else:
print('No')
exit()
if current_left >= 0 and current_left == - sum(r_p_only):
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| n = int(input())
ara = [input() for _ in range(n)]
pref = []
suff = []
for s in ara:
pos = neg = 0
for ch in s:
if ch == '(':
pos += 1
elif pos == 0:
neg += 1
else:
pos -= 1
if pos >= neg:
pref.append([pos, neg])
else:
suff.append([pos, neg])
pref.sort(key=lambda x: x[1])
suff.sort(key=lambda x: x[0], reverse=True)
totPos = 0
ara = pref + suff
for pos, neg in ara:
if neg > totPos:
print("No")
exit(0)
totPos -= neg
totPos += pos
if totPos != 0:
print("No")
else:
print("Yes")
| 1 | 23,740,726,908,730 | null | 152 | 152 |
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
c = [n]*61
for i in range(n):
b = str(bin(a[i]))[2:]
b = b[::-1]
for j, x in enumerate(b):
if x == "1":
c[j] -= 1
ans = 0
for i in range(60):
ans += c[i]*(n-c[i])*pow(2,i,mod)
ans %= mod
print(ans)
| from collections import deque
from collections import defaultdict
n, m = map(int, input().split())
g = defaultdict(list)
s = set(list(range(1, n+1)))
ans = 0
for i in range(m):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
while s:
root = s.pop()
q = deque()
q.append(root)
done = set()
done.add(root)
while q:
node = q.popleft()
for adj in g[node]:
if adj not in done:
done.add(adj)
q.append(adj)
s.remove(adj)
ans += 1
print(ans - 1) | 0 | null | 62,474,774,123,552 | 263 | 70 |
N = int(input())
X = list(map(int, input().split()))
p = 0
s = sum(X)
for n in range(N):
s -= X[n]
s = s % (10**9 + 7)
p += s * X[n]
p = p % (10**9 + 7)
print(p) | N,K=map(int,input().split())
result=0
for i in range(10**9):
if (N<K**i):
result+=i
break
print(result) | 0 | null | 33,940,923,148,842 | 83 | 212 |
n = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
for k in range(j+1,n):
if L[i]!=L[j] and L[i]!=L[k] and L[j]!=L[k] and abs(L[j]-L[k])<L[i]<L[j]+L[k]:
ans += 1
print(ans) | def abc152c_low_elements():
n = int(input())
p = list(map(int, input().split()))
cnt = 1
min_val = p[0]
for i in range(1, n):
if min_val > p[i]:
cnt += 1
min_val = min(min_val, p[i])
print(cnt)
abc152c_low_elements() | 0 | null | 45,180,056,888,600 | 91 | 233 |
while True:
inVal = input().split()
if inVal[1] == "?":
break
if inVal[1] == "+":
print(int(inVal[0]) + int(inVal[2]))
elif inVal[1] == "-":
print(int(inVal[0]) - int(inVal[2]))
elif inVal[1] == "*":
print(int(inVal[0]) * int(inVal[2]))
elif inVal[1] == "/":
print(int(inVal[0]) // int(inVal[2]))
| import sys
n=input()
house=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
for i in range(4):
for j in range(3):
for k in range(10):
house[i][j].append(0)
for i in range(n):
b,f,r,v=map(int,raw_input().split())
house[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for k in range(10):
sys.stdout.write(' %d'%house[i][j][k])
print('')
if i!=3:
print('#'*20) | 0 | null | 877,527,118,546 | 47 | 55 |
n = int(input())
s, t = map(str, input().split())
ans = ''
for a, b in zip(s, t):
ans += a+b
print(ans) | number = int(input())
list1,list2 = input().split(" ")
str=""
for i in range(number):
str=str+list1[i]+list2[i]
print(str) | 1 | 111,915,870,371,396 | null | 255 | 255 |
def therefore():
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
N = input()
n = int(N[-1])
if n in hon:
print("hon")
elif n in pon:
print("pon")
elif n in bon:
print("bon")
therefore() | from math import log2, ceil
class SegTree:
#####単位元######
ide_ele = 0
def __init__(self, init_val):
n = len(init_val)
self.num = 2**ceil(log2(n))
self.seg = [self.ide_ele] * (2 * self.num - 1)
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
# built
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
#####segfunc######
def segfunc(self, x, y):
return x|y
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, a, b, k, l, r):
if r <= a or b <= l:
return self.ide_ele
if a <= l and r <= b:
return self.seg[k]
else:
vl = self.query(a, b, k*2+1, l, (l+r)//2)
vr = self.query(a, b, k*2+2, (l+r)//2, r)
return self.segfunc(vl, vr)
N = int(input())
S = input()
Q = int(input())
li = [1 << (ord(s) - ord('a')) for s in S]
seg_tree = SegTree(li)
ans = []
for _ in range(Q):
i, l, r = input().split()
i = int(i)
l = int(l)
if i == 1:
seg_tree.update(l-1, 1 << (ord(r) - ord('a')))
else:
r = int(r)
num = seg_tree.query(l-1, r, 0, 0, seg_tree.num)
ans.append(bin(num).count('1'))
for a in ans:
print(a)
| 0 | null | 41,136,658,312,988 | 142 | 210 |
def main():
N = int(input())
# 桁数を求める
n_digit = 0
idx = 0
while True:
n_digit += 1
n_str = 26 ** n_digit
if idx + 1 <= N <= idx + n_str:
idx += 1
break
else:
idx += n_str
k = N - idx
ans = ''
for i in range(n_digit):
ans += chr(ord('a') + k % 26)
k //= 26
print(ans[::-1])
if __name__ == '__main__':
main()
| d = {chr(i):i-96 for i in range(97,123)}
D = {val:key for key,val in d.items()}
N = int(input())
x = ""
while N>0:
a = N%26
if a!=0:
x += D[a]
N = N//26
else:
x += "z"
N = N//26
N -= 1
print(x[::-1]) | 1 | 11,931,608,699,760 | null | 121 | 121 |
import math
a, b, deg = map(int, input().split())
rad = math.radians(deg)
S = a * b * math.sin(rad) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)) ** (1 / 2)
L = a + b + c
h = S * 2 / a
print(S,L,h)
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
N = i()
S = s()
if N % 2 != 0:
print("No")
else:
a = N // 2
if S[:a] == S[a:N]:
print("Yes")
else:
print("No")
| 0 | null | 73,432,095,409,466 | 30 | 279 |
write = open(1, 'w').write
for i in range(1, int(open(0).read())+1):
if i % 3:
if "3" in str(i):
write(" %d" % i)
else:
write(" %d" % i)
write("\n")
| def call(n):
ans = []
for i, x in enumerate(range(1, n + 1), 1):
if x % 3 == 0:
ans.append(i)
continue
while x:
if x % 10 == 3:
ans.append(i)
break
x //= 10
print(" " + " ".join(map(str, ans)))
if __name__ == '__main__':
from sys import stdin
n = int(stdin.readline().rstrip())
call(n)
| 1 | 908,272,505,360 | null | 52 | 52 |
values = input()
a, b = [int(x) for x in values.split()]
print('{0} {1} {2:.5f}'.format(a // b, a % b, a / b)) | def sol(s, p):
n = len(s)
cnt = 0
if p == 2 or p == 5:
for i in range(n):
if (s[i] % p == 0):
cnt += i + 1
else:
pre = [0] * (n+2)
pre[n+1] = 0
b = 1
for i in range(n, 0, -1):
pre[i] = (pre[i+1] + s[i-1] * b) % p
b = (b * 10) % p
rec = [0] * p
rec[0] = 1
for i in range(n, 0, -1):
cnt += rec[pre[i]]
rec[pre[i]] += 1
return cnt
if __name__ == "__main__":
n, p = map(int, input().split())
s = input()
print (sol([int(i) for i in s], p)) | 0 | null | 29,294,488,882,880 | 45 | 205 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
a, b, c = map(int, readline().split())
if a + b < c and (c - b - a) ** 2 > 4 * a * b:
print('Yes')
else:
print('No')
| def main():
a, b, c = map(int, input().split())
if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 1 | 51,423,112,567,870 | null | 197 | 197 |
def solve():
dp = [0] * N
for i in range(N):
dp[A[i]-1] = i+1
for i in range(N):
print(dp[i], end=" ")
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
solve()
| X = int(input())
d = {}
for i in range(0, 26):
d[i+1] = chr(97+i)
a = []
while X > 0:
if X%26 != 0:
a.append(d[(X % 26)])
X -= X % 26
else:
a.append(d[26])
X -= 26
X //= 26
for i in a[::-1]:
print(i, end='')
print() | 0 | null | 96,355,649,678,588 | 299 | 121 |
S,T=map(str,input().split())
ans = T+S
print(ans)
| # -*- coding: utf-8 -*-
import sys
import os
s = input().strip()
N = int(input())
for i in range(N):
lst = input().split()
command = lst[0]
if command == 'replace':
a = int(lst[1])
b = int(lst[2])
p = lst[3]
s = s[:a] + p + s[b+1:]
elif command == 'reverse':
a = int(lst[1])
b = int(lst[2])
part = s[a:b+1]
part = part[::-1]
s = s[:a] + part + s[b+1:]
elif command == 'print':
a = int(lst[1])
b = int(lst[2])
print(s[a:b+1])
else:
print('error')
#print('s', s) | 0 | null | 52,684,871,882,700 | 248 | 68 |
import sys
import math
def main():
r = float(sys.stdin.readline())
print(math.pi * r**2, 2 * math.pi * r)
return
if __name__ == '__main__':
main()
| a,b=map(int,input().split())
print("%d %d %0.5f"%(a/b,a%b,a/b))
| 0 | null | 605,298,021,820 | 46 | 45 |
N, u, v = map(int, input().split())
target = u-1
v -= 1
edge = [[] for _ in range(N)]
for i in range(N-1):
a,b = map(int, input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
from collections import deque
def bfs(s):
lis = [-1]*N
d = deque([s])
lis[s]=0
while len(d)>0:
v = d.popleft()
for w in edge[v]:
if lis[w]<0:
lis[w]=lis[v]+1
d.append(w)
return lis
lis1 = bfs(target)
lis2 = bfs(v)
ans = 0
for i in range(N):
if lis1[i]<lis2[i]:
ans = max(ans, lis2[i]-1)
print(ans) | r, c = map(int, input().split())
matrix = []
for _ in range(r):
L = list(map(int, input().split()))
matrix.append(L + [sum(L)])
matrix.append([sum(column) for column in zip(*matrix)])
for row in matrix:
print(' '.join(map(str, row))) | 0 | null | 59,520,325,254,060 | 259 | 59 |
N = int(input())
S = list(input())
i = 1
count = 0
while i * 2 < N:
n = 0
while n + i * 2 < N:
if (S[n] != S[n+i]) and (S[n+i] != S[n+2*i]) and (S[n] != S[n+i*2]):
count += 1
#print(S[n], S[n+i], S[n+2*i])
n += 1
i += 1
print(S.count('G') * S.count('R') * S.count('B') - count) | N = int(input())
S = input()
R = []
G = []
B = []
for i in range(N):
if S[i] == 'R':
R.append(i+1)
elif S[i] == 'G':
G.append(i+1)
elif S[i] == 'B':
B.append(i+1)
lenb = len(B)
cnt = 0
for r in R:
for g in G:
up = max(r, g)
down = min(r, g)
diff = up - down
chk = 0
if up + diff <= N:
if S[up+diff-1] == 'B':
chk += 1
if down-diff >= 1:
if S[down-diff-1] == 'B':
chk += 1
if diff%2 == 0:
if S[int(up-diff/2-1)] == 'B':
chk += 1
cnt += lenb - chk
print(cnt)
| 1 | 36,136,752,322,528 | null | 175 | 175 |
a, b, m = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
coupon = []
for _ in range(m):
coupon.append(list(map(int, input().split())))
a_copy = a_price.copy()
a_copy.sort()
b_copy = b_price.copy()
b_copy.sort()
a_min = a_copy[0]
b_min = b_copy[0]
min = a_min + b_min
totals = [min]
for list in coupon:
tmp = a_price[list[0] - 1] + b_price[list[1] - 1] - list[2]
totals.append(tmp)
totals.sort()
ans = totals[0]
print(ans)
| n = int(input())
s = input()
if n % 2 != 0:
print('No')
else:
if s[:int((n/2))] == s[int((n/2)):]:
print('Yes')
else:
print('No')
| 0 | null | 100,787,136,696,162 | 200 | 279 |
import math
X = int(input())
count = 0
s = 100
while s < X:
#s = math.floor(s*1.01)
s += s//100
count += 1
print(count) | # 142 A
n = int(input())
odd = 0
for i in range(1, n+1):
if i % 2 != 0:
odd += 1
x = odd/n
print('%.10f' % x) | 0 | null | 102,304,542,678,660 | 159 | 297 |
n = int(input())
a = list(map(int, input().split()))
ans = [None]*n
all = 0
for i in range(n):
all = all^a[i]
for i in range(n):
ans[i]=str(all^a[i])
print(' '.join(ans)) | N=int(input())
a=list(map(int,input().split()))
a_all=0
for i in range(N):
a_all^=a[i]
ans=[]
for j in range(N):
ans.append(a_all^a[j])
print(*ans) | 1 | 12,474,589,645,870 | null | 123 | 123 |
S = input()
for i in range(len(S)):
tmp = S[i]
S = S.replace(tmp,"x")
print(S) | class Dice(object):
def __init__(self, top, south, east, west, north, bottom):
self.top = top
self.south = south
self.east = east
self.west = west
self.north = north
self.bottom = bottom
def get_top(self):
return self.top
def rotate(self, directions):
for direction in directions:
if direction == 'S':
self.prev_top = self.top
self.top = self.north
self.north = self.bottom
self.bottom = self.south
self.south = self.prev_top
elif direction == 'E':
self.prev_top = self.top
self.top = self.west
self.west = self.bottom
self.bottom = self.east
self.east = self.prev_top
elif direction == 'W':
self.prev_top = self.top
self.top = self.east
self.east = self.bottom
self.bottom = self.west
self.west = self.prev_top
elif direction == 'N':
self.prev_top = self.top
self.top = self.south
self.south = self.bottom
self.bottom = self.north
self.north = self.prev_top
dice = Dice(*map(int, input().split()))
dice.rotate(input())
print(dice.get_top()) | 0 | null | 36,584,785,178,942 | 221 | 33 |
import random
class Dice:
def __init__(self, list = map(str, range(1, 7))):
self.top = list[0]
self.front = list[1]
self.right = list[2]
self.left = list[3]
self.back = list[4]
self.bottom = list[5]
def print_all(self):
print "top = " + self.top
print "front = " + self.front
print "right = " + self.right
print "left = " + self.left
print "back = " + self.back
print "bottom = " + self.bottom
def roll_N(self):
temp = self.top
self.top = self.front
self.front = self.bottom
self.bottom = self.back
self.back = temp
def roll_S(self):
temp = self.top
self.top = self.back
self.back = self.bottom
self.bottom = self.front
self.front = temp
def roll_W(self):
temp = self.top
self.top = self.right
self.right = self.bottom
self.bottom = self.left
self.left = temp
def roll_E(self):
temp = self.top
self.top = self.left
self.left = self.bottom
self.bottom = self.right
self.right = temp
def random_roll(self):
ram = random.randint(1, 4)
if ram == 1:
self.roll_E()
elif ram == 2:
self.roll_N()
elif ram == 3:
self.roll_S()
else:
self.roll_W()
my_dice = Dice(raw_input().split(" "))
q = int(raw_input())
for i in xrange(q):
input_dice = raw_input().split(" ")
while True:
if my_dice.top == input_dice[0] and my_dice.front == input_dice[1]:
break
else:
my_dice.random_roll()
print my_dice.right | #!/usr/bin/env python
# -*- coding: utf-8 -*-
POSITIONS = ["top", "south", "east", "west", "north", "bottom"]
class Dice(object):
def __init__(self, initial_faces):
self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
self.store_previous_faces()
def store_previous_faces(self):
self.previous_faces = self.faces.copy()
def change_face(self, after, before):
self.faces[after] = self.previous_faces[before]
def change_faces(self, rotation):
self.change_face(rotation[0], rotation[1])
self.change_face(rotation[1], rotation[2])
self.change_face(rotation[2], rotation[3])
self.change_face(rotation[3], rotation[0])
def roll(self, direction):
self.store_previous_faces()
if direction == "E":
self.change_faces(["top", "west", "bottom", "east"])
elif direction == "N":
self.change_faces(["top", "south", "bottom", "north"])
elif direction == "S":
self.change_faces(["top", "north", "bottom", "south"])
elif direction == "W":
self.change_faces(["top", "east", "bottom", "west"])
def rolls(self, directions):
for d in directions:
self.roll(d)
def main():
dice = Dice(input().split())
q = int(input())
for x in range(q):
[qtop, qsouth] = input().split()
if qsouth == dice.faces["west"]:
dice.roll("E")
elif qsouth == dice.faces["east"]:
dice.roll("W")
while qsouth != dice.faces["south"]:
dice.roll("N")
while qtop != dice.faces["top"]:
dice.roll("W")
print(dice.faces["east"])
if __name__ == "__main__":
main() | 1 | 264,289,836,958 | null | 34 | 34 |
n=int(input())
dept=100000
for i in range(n):
dept*=1.05
if dept%1000!=0:
dept=dept-dept%1000+1000
print(int(dept)) | # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
#import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
from collections import deque
# from decimal import Decimal
# from numba import jit
INF = 1 << 50
EPS = 1e-8
mod = 998244353
def intread():
return int(sysread())
def mapline(t=int):
return map(t, sysread().split())
def mapread(t=int):
return map(t, read().split())
def run():
K = intread()
print('ACL' * K)
if __name__ == "__main__":
run()
| 0 | null | 1,084,927,618,476 | 6 | 69 |
n, p = map(int, input().split())
s = [int(i) for i in input()]
p_cnt = 0
if p == 2 or p == 5:
for i in range(n):
if s[i] % p == 0:
p_cnt += i+1
else:
s = s[::-1]
div_dic = dict(zip(range(p), [0] * p))
tmp = 0
for i in range(n):
tmp += s[i] * pow(10, i, p)
tmp %= p
div_dic[tmp] += 1
for v in div_dic.values():
p_cnt += v * (v - 1)
p_cnt //= 2
p_cnt += div_dic.get(0)
print(p_cnt) | S = input()
# 辞書型を使うとスッキリ書ける!
dic = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}
print(dic[S]) | 0 | null | 95,665,905,995,670 | 205 | 270 |
def solve(n,s):
cnt = 0
for i in range(len(s)-2):
if "ABC" == s[i:i+3]:
cnt+=1
return cnt
n = int(input())
s = input()
ans = solve(n,s)
print(ans) | n,s = [input() for _ in range(2)]
print(s.count("ABC")) | 1 | 99,485,301,248,970 | null | 245 | 245 |
import math
N=int(input())
ans=int(math.ceil(N/2.0)-1)
print(ans)
| n = int(input())
print(max(0,((n-1)//2)))
| 1 | 153,531,511,205,000 | null | 283 | 283 |
x = input().strip()
if x[-1] == 's':
x += "es"
else:
x += 's'
print(x) | s=input()
l=len(s)
list_s=list(s)
ans=""
if(s[l-1]!="s"):
list_s.append("s")
elif(s[l-1]=="s"):
list_s.append("es")
for i in range(0,len(list_s)):
ans+=list_s[i]
print(ans) | 1 | 2,349,826,315,072 | null | 71 | 71 |
H,W,M=map(int,input().split())
h,w=map(list,zip(*[list(map(int,input().split())) for i in range(M)]))
from collections import Counter
hc,wc=Counter(h),Counter(w)
hx,wx=hc.most_common()[0][1],wc.most_common()[0][1]
hl,wl=set([k for k,v in hc.items() if v==hx]),set([k for k,v in wc.items() if v==wx])
x=sum([1 for i in range(M) if h[i] in hl and w[i] in wl])
print(hx+wx if len(hl)*len(wl)-x else hx+wx-1) | def pre_combi1(n, p):
fact = [1]*(n+1) # fact[n] = (n! mod p)
factinv = [1]*(n+1) # factinv[n] = ((n!)^(-1) mod p)
inv = [0]*(n+1) # factinv 計算用
inv[1] = 1
# 前処理
for i in range(2, n + 1):
fact[i]= fact[i-1] * i % p
inv[i]= -inv[p % i] * (p // i) % p
factinv[i]= factinv[i-1] * inv[i] % p
return fact, factinv
def combi1(n, r, p, fact, factinv):
if r < 0 or n < r:
return 0
r = min(r, n-r)
return fact[n] * factinv[r] * factinv[n-r] % p
import sys
x,y=map(int,input().split())
if (x+y)%3 > 0:
print(0)
sys.exit()
n=(x+y)//3
r=x-n
f,inv=pre_combi1(n,1000000007)
print(combi1(n,r,1000000007,f,inv)) | 0 | null | 77,049,808,385,760 | 89 | 281 |
N=int(input())
S=list(input())
if N%2==1:
print("No")
else:
n=int(N/2)
if S[0:n]==S[n:N]:
print("Yes")
else:
print("No")
| s = input()
t = input()
ls = len(s)
lt = len(t)
ret = lt
for i in range(ls+1 - lt):
diff = 0
for j in range(lt):
diff += (t[j] != s[i+j])
if diff == 0:
ret = diff
break
if diff < ret:
ret = diff
print(ret) | 0 | null | 75,351,809,561,600 | 279 | 82 |
n = int(input())
i = 1
while i <= n:
x = i
if x % 3 == 0:
print(" {:d}".format(i),end="")
else:
while x:
if x % 10 == 3:
print(" {:d}".format(i),end="")
break
x = x // 10
i += 1
print("")
| n = input()
ans = ""
for i in range(1, n + 1) :
if (i % 3 == 0 or str(i).count('3')) :
ans += (" " + str(i))
print("%s" % ans) | 1 | 915,615,106,350 | null | 52 | 52 |
import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
X, K, D = MI()
if abs(X) >= K * D:
print(abs(X) - K * D)
else:
a = abs(abs(X) - (abs(X) // D) * D)
K -= (abs(X) // D)
if K % 2 == 0:
print(a)
else:
print(abs(a - D)) | # ABC172 C - Walking Takahashi
X,K,D=map(int,input().split())
q=abs(X)//D
if q>K:
print(abs(X)-K*D)
else:
if (K-q)%2==0:
print(abs(X)-q*D)
else:
print(abs(abs(X)-(q+1)*D)) | 1 | 5,225,389,512,738 | null | 92 | 92 |
n=input()
r='No'
for i in range(len(n)):
if n[i]=='7': r='Yes'
print(r)
| n = int(input());
print(n*"ACL"); | 0 | null | 18,397,830,905,252 | 172 | 69 |
N = int(input())
P = list(map(int,input().split()))
n = float("INF")
count = 0
for i in P:
if n >= i:
n = i
count += 1
print(count) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, *a = map(int, read().split())
r = 0
minp = a[0]
for i1 in range(n):
if minp >= a[i1]:
r += 1
minp = a[i1]
print(r)
if __name__ == '__main__':
main()
| 1 | 85,632,841,934,272 | null | 233 | 233 |
def report(k, r):
print('{} x {}'.format(k, r[k]))
ans = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
N = int(input().rstrip())
for i in range(N):
S = input().rstrip()
ans[S] += 1
report('AC', ans)
report('WA', ans)
report('TLE', ans)
report('RE', ans)
| n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0] * t for _ in range(n)]
ans = 0
a.sort()
for i in range(n-1):
for j in range(t):
if j - a[i][0] < 0:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i][0]] + a[i][1])
ans = max(ans, dp[i + 1][-1] + a[i+1][1])
print(ans) | 0 | null | 80,173,767,513,922 | 109 | 282 |
import sys
readline = sys.stdin.readline
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
MAX_VAL = 10 ** 5 + 1
hand = [0] * MAX_VAL
for a in A:
hand[a] += 1
import numpy as np
def convolve(f, g):
fft_len = 1
while 2 * fft_len < len(f) + len(g) - 1:
fft_len *= 2
fft_len *= 2
Ff = np.fft.rfft(f, fft_len)
Fg = np.fft.rfft(g, fft_len)
Fh = Ff * Fg
h = np.fft.irfft(Fh, fft_len)
h = np.rint(h).astype(np.int64)
return h[:len(f) + len(g) - 1]
right_hand = np.array(hand, dtype = int)
left_hand = np.array(hand, dtype = int)
H = convolve(left_hand, right_hand)
# Hを大きいほうから見ていくと、
# 幸福度iの握手をH[i]種類できることが分かる
# 上から順に足していって、最後H[i]種類の握手を足せないときは、残りの握手回数だけ足す
ans = 0
for i in range(len(H) - 1, -1, -1):
if H[i] == 0:
continue
if H[i] <= M: # H[i]回の握手ができる
ans += i * H[i]
M -= H[i]
else: # H[i]回の握手ができないので、残った回数だけ握手する
ans += M * i
break
print(ans) | import sys
from bisect import bisect_right, bisect_left
from itertools import accumulate
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
def meguru_bisect(ok, ng):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
def is_ok(x):
cnt = 0
for a in A:
t = x - a
idx = bisect_right(A, t)
cnt += n - idx
return cnt < m
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ng, ok = 0, 10 ** 15 + 1
mth = meguru_bisect(ok, ng)
R = [0] + list(accumulate(A))
res = 0
cnt = 0
for a in A:
s = mth - a
left = bisect_left(A, s)
res += (n - left) * a + R[-1] - R[left]
cnt += n - left
print(res - mth * (cnt - m))
if __name__ == '__main__':
resolve()
| 1 | 108,003,170,015,392 | null | 252 | 252 |
N, H = map(int, input().split())
print('Yes' if N == H else 'No') | N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(len(A)):
if A[i]%2==0:
if A[i]%3==0 or A[i]%5==0:
count+=1
else:
count+=1
if count==len(A):
print("APPROVED")
else:
print("DENIED") | 0 | null | 76,073,547,933,472 | 231 | 217 |
n = int(input())
A = list(map(int, input().split()))
ans = 1
A = sorted(A)
for i in range(n):
ans *= A[i]
if ans > 10**(18):
print('-1')
exit()
print(ans) | N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
al = []
bl = []
for a,b in ab:
al.append(a)
bl.append(b)
al.sort()
bl.sort()
if N%2 == 0:
ans = (bl[N//2] + bl[N//2 -1]) - (al[N//2] + al[N//2 -1]) +1
else:
ans = bl[N//2] - al[N//2] +1
print(ans) | 0 | null | 16,750,186,797,878 | 134 | 137 |
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') | from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
Ones = A.count(1)
R = max(A)
nums = [0]*(R+1)
# 素因数テーブルの作成
D = [0]*(R+1)
for i in range(2, R+1):
if D[i]:
continue
n = i
while n < R+1:
if D[n] == 0:
D[n] = i
n += i
# 素因子をカウント
for a in A:
tmp = a
while tmp > 1:
prime_factor = D[tmp]
nums[prime_factor] += 1
while tmp%prime_factor == 0:
tmp //= prime_factor
y = max(nums)
if y < 2:
print('pairwise coprime')
elif y-Ones < N:
print('setwise coprime')
else:
print('not coprime') | 1 | 4,107,429,616,470 | null | 85 | 85 |
def solve(n):
ret = []
while n > 26:
if n % 26 == 0:
ret = [26] + ret
n = (n - 26) // 26
else:
ret = [n % 26] + ret
n = n // 26
ret = [n] + ret
return ret
n = int(input())
ans = ''.join([chr(ord('a') + i - 1) for i in solve(n)])
print(ans) | #N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
i = 0
ans = []
#26^{i}がNを越えるまで以下の操作を繰り返す
while N != 0:
s = N%26
if s == 0:
s = 26
N -= s
N //= 26
ans.append(chr(s + 96))
print(''.join(list(reversed(ans)))) | 1 | 12,026,364,827,202 | null | 121 | 121 |
n=int(raw_input())
print (n-1)/2 | a = int(input())
if a % 2 is 0:
print(a // 2 - 1)
else:
print(a // 2) | 1 | 153,033,295,291,840 | null | 283 | 283 |
count = int(input())
lists = []
for i in range(count):
new = input()
lists.append(new)
ac_count = lists.count('AC')
wa_count = lists.count('WA')
tle_count = lists.count('TLE')
re_count = lists.count('RE')
print("AC x " + str(ac_count))
print("WA x " + str(wa_count))
print("TLE x " + str(tle_count))
print("RE x " + str(re_count))
| from collections import defaultdict
N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
A_accsum = [0] * (N+1)
for i, a in enumerate(A):
A_accsum[i+1] = (A_accsum[i]+a) % K
count = defaultdict(lambda: 0)
piv = A_accsum[0]
count[piv] += 1
ans = 0
for i in range(1, min(K, N+1)):
a = A_accsum[i]
count[a] += 1
for i in range(K, N + 1):
a = A_accsum[i]
piv = A_accsum[i-K]
count[piv] -= 1
ans += count[piv]
count[a] += 1
for i in range(max(0, N - K+1), N+1):
piv = A_accsum[i]
count[piv] -= 1
ans += count[piv]
print(ans)
| 0 | null | 72,885,061,008,890 | 109 | 273 |
s,t=input().split()
S,T=map(int,input().split())
dis=input()
if s==dis:
print(S-1,T)
else:
print(S,T-1) | def main():
n = int(input())
A = [int(x) for x in input().split()]
ans = 0
mod = 10 ** 9 + 7
for d in range(60):
# d桁目ごとに考える
x = 0
for a in A:
if (a >> d) & 1:
x += 1
ans += x * (n-x) * 2**d
ans %= mod
print(ans)
if __name__ == '__main__':
main() | 0 | null | 97,399,094,920,722 | 220 | 263 |
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
if A[0]==1:
if N==0:
pass
else:
print(-1)
exit()
elif A[0]>1:
print(-1)
exit()
limit=[1]
for a in A[1:]:
limit.append(limit[-1]*2-a)
A=A[::-1]
limit=limit[::-1]
ans=A[0]
temp=A[0]
for i in range(len(limit)-1):
a=limit[i+1]
b=temp
x=b-a
y=a-x
if x<0:
x=0
y=temp
elif y<0:
print(-1)
exit()
temp=x+y+A[i+1]
ans+=temp
print(ans) | n,k=map(int,input().split(' '))
l=list(map(int, input().split(' ')))
l=sorted(l)
print(sum(l[:max(n-k,0)])) | 0 | null | 49,085,172,271,260 | 141 | 227 |
x=list(map(int, input().split()))
L=x[0]
R=x[1]
d=x[2]
res=0
while L<=R:
if L%d==0:
res+=1
L+=1
print(res) | """
f(n) , f(n+1)の値を求める
f(3456)を求める時
f(0) = 0, f(1) = 1 とする
f(3) = min
(
f(0) + 3
f(1) + 7
)
f(4) = min
(
f(0) + 4
f(1) + 6
)
f(34) = min
(
f(3) + 4
f(4) + 6
)
f(35) = min
(
f(3) + 5
f(4) + 5
)
f(345) = min
(
f(34) + 5
f(35) + 5
)
f(346) = min
(
f(34) + 4
f(35) + 6
)
f(3456) = min
(
f(345) + 6
f(346) + 4
)
"""
N = input()
n = [int(i) for i in N]
f0 = 0
f1 = 1
dp = f0, f1
# 桁DP
for i in n:
# 支払い枚数を考える
fn_0 = min(dp[0] + i, dp[1] + 10 - i)
fn_1 = min(dp[0] + (i+1), dp[1] + 10 - (i+1))
dp = fn_0, fn_1
print(dp[0])
| 0 | null | 39,174,329,383,260 | 104 | 219 |
import sys #インタプリタや実行環境に関する情報を扱うためのライブラリ
import os #フォルダやファイルを操作
import math
#標準入力
n = int(input())
#inputはstr(string)で入力されるのでstrの場合は指定不要
S=input()
#inputが改行されている場合は別途入力でよい
print(S.count("ABC")) | def column_check(grp, grp_count, choco, h, j, k):
""" 0:成功(更新も反映) 1:失敗(区切った結果を返す) 2:不可能 """
# この行のグループ毎のカウント
curr_count = [0] * len(grp_count)
# 数える
for i in range(h):
if choco[i][j] == '0':
continue
curr_count[grp[i]] += 1
# この行だけでk越えてたら現在の横の切り方では不可能
for cc in curr_count:
if cc > k:
return 2
# ここまでの行と合わせてkを越えないかチェック
for i, cc in enumerate(curr_count):
grp_count[i] += cc
# 越えてたら、grp_countを現在の行に上書き
if grp_count[i] > k:
grp_count[:] = curr_count
return 1
return 0
def solve(h, w, k, choco):
ans = 10 ** 9
grp = [0] * h
for bit in range(1 << (h - 1)):
g = 0
for i in range(h):
grp[i] = g
if (bit >> i) & 1:
g += 1
grp_count = [0] * (g + 1)
tmp = 0
possible = True
for j in range(w):
result = column_check(grp, grp_count, choco, h, j, k)
if result == 2:
possible = False
break
if result == 1:
tmp += 1
if not possible:
continue
ans = min(ans, tmp + bin(bit).count('1'))
return ans
h, w, k = map(int, input().split())
choco = [input() for _ in range(h)]
print(solve(h, w, k, choco))
| 0 | null | 74,310,964,822,560 | 245 | 193 |
n = int(input())
L = []
ans = 0
for i in range(n):
a = int(input())
for j in range(a):
x, y = map(int, input().split())
L.append((i, x-1, y))
for i in range(1<<n):
flg = True
for j, x, y in L:
if i>>j & 1 and i>>x & 1 != y:
flg = False
break
if flg:
ans = max(ans, sum(i>>j & 1 for j in range(n)))
print(ans)
| n = int(input())
s = [ i for i in input().split()]
cnt = 0
for i in range(n-1):
minj = i
for j in range(i+1,n):
if int(s[j]) < int(s[minj]):
minj = j
if i != minj:
cnt += 1
s[i],s[minj] = s[minj],s[i]
print(' '.join(s))
print(cnt)
| 0 | null | 60,695,018,045,760 | 262 | 15 |
def main():
K = int(input())
ans = False
if K % 2 == 0:
print(-1)
exit()
cnt = 7 % K
for i in range(1, K+1):
if cnt == 0:
ans = True
print(i)
exit()
cnt = (10 * cnt + 7) % K
if ans == False:
print(-1)
exit()
main() | k=int(input())
if k%2==0 or k%5==0:
print(-1)
else:
i=1
t=7
while t%k!=0:
i+=1
t=(t*10+7)%k
print(i) | 1 | 6,120,309,357,568 | null | 97 | 97 |
from collections import deque
import sys
INFTY=sys.maxsize
WHITE=0
GRAY=1
BLACK=2
color=[]
d=[]
Q=deque([])
n=0
L=[]
def readinput():
global n
global L
n=int(input())
for i in range(n+1):
L.append([])
for i in range(n):
inp=list(map(int,input().split()))
L[inp[0]]=inp[2:]
def bfs(s):
global color
global d
global Q
for i in range(n+1):
color=[WHITE]*(n+1)
d=[-1]*(n+1)
color[s]=GRAY
d[s]=0
Q.append(s)
while(len(Q)>0):
u = Q.popleft()
for l in L[u]:
if(color[l]==WHITE):
color[l]=GRAY
d[l]=d[u]+1
Q.append(l)
color[u]=BLACK
if __name__=='__main__':
readinput()
bfs(1)
for i in range(1,n+1):
print('{} {}'.format(i, d[i]))
| import sys
from collections import deque
n = int(sys.stdin.readline().strip())
edges = [[] for _ in range(n)]
for _ in range(n):
tmp = list(map(int, sys.stdin.readline().strip().split(" ")))
for node in tmp[2:]:
edges[tmp[0] - 1].append(node-1)
# print(edges)
distance = [0] * n
q = deque()
q.append((0, 0))
visited = set()
while q:
node, d = q.popleft()
# print(node, d)
if node in visited:
continue
distance[node] = d
visited.add(node)
for next in edges[node]:
# print("next", next)
q.append((next, d + 1))
for i, d in enumerate(distance):
if i == 0:
print(1, 0)
else:
print(i + 1, d if d > 0 else -1)
| 1 | 4,193,846,460 | null | 9 | 9 |
X = int(input())
print("YNeos"[not(X>=30)::2]) | def insertionSort(A, n, g):
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 = j - g
global cnt
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
G =[]
g = 0
for h in range(100):
g = 3*g + 1
if g <= n:
G.insert(0,g)
m = len(G)
for i in range(m):
insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt)
print(*A,sep="\n")
n = int(input())
A = [int(input()) for i in range(n)]
shellSort(A, n)
| 0 | null | 2,855,760,202,862 | 95 | 17 |
import math
A = []
N = int(input())
count = 0
for n in range(N):
x = int(input())
if x == 2:
A.append(x)
count += 1
elif x % 2 == 0:
pass
elif x > 2:
for i in range(3, int(math.sqrt(x))+2, 2):
if x % i == 0:
break
else:
count += 1
A.append(x)
print(count) | #E
N,T=map(int,input().split())
A=[0 for i in range(N+1)]
B=[0 for i in range(N+1)]
for i in range(1,N+1):
A[i],B[i]=map(int,input().split())
dp1=[[0 for i in range(6001)] for j in range(N+1)]
dp2=[[0 for i in range(6001)] for j in range(N+2)]
for i in range(1,N+1):
for j in range(T+1):
if j>=A[i]:
dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-A[i]]+B[i])
else:
dp1[i][j]=dp1[i-1][j]
for i in range(N,0,-1):
for j in range(T+1):
if j>=A[i]:
dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-A[i]]+B[i])
else:
dp2[i][j]=dp2[i+1][j]
ans=0
for i in range(1,N+1):
for j in range(T):
ans=max(ans,dp1[i-1][j]+dp2[i+1][T-1-j]+B[i])
print(ans) | 0 | null | 75,477,525,938,210 | 12 | 282 |
def solve():
ans = 0
N, T = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
dp = [[0]*(T+A[-1][0]) for _ in range(N+1)]
for i in range(1,N+1):
for t in range(1,T+A[-1][0]):
if t<A[i-1][0] or t>=T+A[i-1][0]:
dp[i][t] = max(dp[i-1][t],dp[i][t-1])
else:
dp[i][t] = max([dp[i-1][t],dp[i][t-1],dp[i-1][t-A[i-1][0]]+A[i-1][1]])
ans = max(dp[-1])
return ans
print(solve()) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, T = mapint()
AB = [list(mapint()) for _ in range(N)]
AB.sort()
maxtime = AB[-1][0]
Bs = [b for a, b in AB]
dp = [0]*(T)
ans = 0
for n in range(N-1):
a, b = AB[n]
newdp = [0]*(T)
for i in range(T):
if a<=i and i-a<T:
newdp[i] = max(dp[i], dp[i-a]+b)
dp = newdp
ans = max(ans, max(dp)+max(Bs[n+1:]))
print(ans) | 1 | 151,685,486,325,002 | null | 282 | 282 |
import sys
az = [0 for i in range(26)]
s = sys.stdin.read().lower()
l = [ord(i) for i in s]
for i in range(len(l)):
c = l[i] - 97
if(c >= 0 and c <= 26):
az[c] += 1
for i in range(26):
print('{} : {}'.format(chr(i + 97),az[i])) | import sys
import string
s = sys.stdin.read().lower()
for c in string.ascii_lowercase:
print(c, ":", s.count(c)) | 1 | 1,645,580,492,040 | null | 63 | 63 |
n = int(input())
digit = 1
while n > 26 ** digit:
n -= 26 ** digit
digit += 1
ans = []
n -= 1
char = 'abcdefghijklmnopqrstuvwxyz'
for i in list(range(digit)):
ans.append(char[n % 26])
n -= n%26
n = int(n/26)
print(''.join(reversed(ans))) | n = int(input())
ans = ''
while n:
n -= 1
ans += chr(ord('a') + n % 26)
n //= 26
print(ans[::-1]) | 1 | 11,935,508,466,950 | null | 121 | 121 |
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
memory = [[-1 for i in range(max(m)+1)]for j in range(n)]
def f(i, m):
if m == 0:
return 1
elif i >= n:
return 0
elif memory[i][m] != -1:
return memory[i][m]
elif m - a[i] >= 0:
res0 = f(i+1, m)
res1 = f(i+1, m-a[i])
if res0 or res1:
memory[i][m] = 1
return 1
else:
memory[i][m] = 0
return 0
else:
res = f(i+1, m)
memory[i][m] = res
return res
for k in m:
print('yes' if f(0, k) else 'no')
| def main():
r = int(input())
print(r**2)
return 0
if __name__ == '__main__':
main() | 0 | null | 72,611,281,123,008 | 25 | 278 |