code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
x = 1
ans = 0
for i in range(60):
ones = 0
zeros = 0
for a in A:
if a & (1 << i) > 0:
ones += 1
else:
zeros += 1
ans += (ones * zeros * x) % MOD
x *= 2
print(ans % MOD)
|
X = int(input())
K = 0
while ((X * K) % 360 != 0) or (K == 0):
K += 1
print(K)
| 0 | null | 68,295,499,559,518 | 263 | 125 |
n,m = [int(i) for i in input().split()]
s = input()
p = n
q = []
while p!=0:
frag = True
for i in range(max(p-m,0),p):
if s[i]=='0':
q.append(p-i)
p=i
frag = False
break
if frag:
q=[]
print(-1)
break
for i in reversed(q):
print(i)
|
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
s = input()
inf=float("inf")
#i番目のマスに行くための最小手数と、なんマス移動してきたか
dp = [(0,0)] + [(inf,None) for _ in range(n)]
for i in range(1,n+1):
if s[i]=="0":
for j in range(min(m,i),0,-1):
if dp[i-j][0]<inf:
dp[i]=(dp[i-j][0]+1,j)
break
if dp[-1][1]:
i = n
ret = []
ra = ret.append
while dp[i][1]:
ra(dp[i][1])
i-=dp[i][1]
print(" ".join(map(str,ret[::-1])))
else:
print(-1)
| 1 | 139,411,623,260,590 | null | 274 | 274 |
#!/usr/bin/python3
def countpars(s):
lc = 0
rc = 0
for ch in s:
if ch == '(':
lc += 1
else:
if lc > 0:
lc -= 1
else:
rc += 1
return (lc, rc)
n = int(input())
ssl = []
ssr = []
for i in range(n):
(clc, crc) = countpars(input())
if clc >= crc:
ssl.append((clc, crc))
else:
ssr.append((clc, crc))
ssl.sort(key=lambda x: x[1])
ssr.sort(reverse=True)
lc = 0
rc = 0
for (clc, crc) in ssl:
lc -= crc
if lc < 0:
print('No')
exit()
lc += clc
for (clc, crc) in ssr:
lc -= crc
if lc < 0:
print('No')
exit()
lc += clc
if lc == 0:
print('Yes')
else:
print('No')
|
import sys
heights = sorted([int(h) for h in sys.stdin], reverse=True)
print(heights[0])
print(heights[1])
print(heights[2])
| 0 | null | 11,891,408,723,082 | 152 | 2 |
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
cnt, a, b = 0, 0, 0
for i in itertools.permutations(range(1, N+1)):
if P == i:
a = cnt
if b != 0:
break
if Q == i:
b = cnt
if a != 0:
break
cnt += 1
print(abs(a-b))
|
n,m = map(int,input().split())
*hl, = map(int,input().split())
ansl = [1]*n
for _ in [0]*m:
a,b = map(int,input().split())
if hl[a-1] > hl[b-1]:
ansl[b-1] = 0
elif hl[a-1] < hl[b-1]:
ansl[a-1] = 0
else:
ansl[a-1] = 0
ansl[b-1] = 0
print(sum(ansl))
| 0 | null | 62,865,386,777,970 | 246 | 155 |
while True:
y,x = [int(i) for i in input().split()]
if x==0 and y==0:
break
for i in range(y):
if i%2:
for j in range(x):
if j%2:
print('#' ,end='')
else:
print('.' ,end='')
print()
else:
for j in range(x):
if j%2:
print('.' ,end='')
else:
print('#' ,end='')
print()
print()
|
h= []
w= []
while True:
a,b= map(int,input().split())
if(not (a==0 or b==0)):
h.append(a)
w.append(b)
elif(a==b==0):
break
n= 0
for e in h:
c= 0
for f in range(e):
if(w[n]%2==0):
if(c== 0):
print('#.'*(w[n]//2))
c= 1
else:
print('.#'*(w[n]//2))
c= 0
else:
if(c== 0):
print('#.'*(w[n]//2)+'#')
c= 1
else:
print('.#'*(w[n]//2)+'.')
c= 0
print()
n+= 1
| 1 | 877,377,651,968 | null | 51 | 51 |
#!/usr/bin/env python3
S = input()
total = 0
for i in range(len(S)):
if "R" * (i + 1) in S:
total = i + 1
ans = total
print(ans)
|
S = input()
if S == 'RRR':
print(3)
elif S == 'SSS':
print(0)
elif S=='RSS' or S == 'SRS' or S=='SSR' or S=='RSR':
print(1)
else:
print(2)
| 1 | 4,893,158,549,838 | null | 90 | 90 |
in_str = input().rstrip()
print(in_str.swapcase())
|
import sys
for e in iter(sys.stdin.readline, '0 0\n'):
print(*sorted(map(int, e.split())))
| 0 | null | 1,037,530,778,882 | 61 | 43 |
l = int(input())
ans = 0
edge = l/3
ans = edge**3
print(ans)
|
import math
r=float(input())
S=r*r*math.pi
L=2*r*math.pi
print('%.5f %.5f'%(S,L))
| 0 | null | 23,852,480,232,112 | 191 | 46 |
n = int(input())
a = list(map(int, input().split(" ")))
for lil_a in a[-1:0:-1]:
print("%d "%lil_a, end="")
print("%d"%a[0])
|
n = int(input())
count = 0
for i in range(n):
a,b = map(int,input().split())
if count >2 :
break
elif a==b:
count += 1
else:
count = 0
print('Yes' if count > 2 else 'No')
| 0 | null | 1,764,320,399,104 | 53 | 72 |
N = int(input())
cnt = 0
for a in range(1,N):
for b in range(1,N):
if a * b >= N:
break
else:
cnt +=1
print(cnt)
|
number=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
masu=[]
for i in range(H):
tmp=list(str(input()))
masu.append(tmp)
count=0
ans=0
for cowmask in range(1<<H):
for rowmask in range(1<<W):
count=0
for x in range(H):
for y in range(W):
if (cowmask>>x)&1==0 and (rowmask>>y)&1==0 and masu[x][y]=="#":
count+=1
if count==K:
ans+=1
print(ans)
| 0 | null | 5,697,792,423,410 | 73 | 110 |
n = int(input())
ans = ""
check = "abcdefghijklmnopqrstuvwxyz"
while n != 0:
n -= 1
ans += check[n % 26]
n //= 26
print(ans[::-1])
|
n = int(input())
ans = ''
while n > 0:
n -= 1
ans += chr(n % 26 + ord('a'))
n = n // 26
print(ans[::-1])
| 1 | 11,826,124,967,228 | null | 121 | 121 |
X, Y = map(int, input().split())
print(400000*(X==1)*(Y==1) + max(0, 400000-100000*X) + max(0, 400000-100000*Y))
|
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
a, b = map(int, input().split())
print(max(0, a - 2 * b))
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0 | null | 153,538,976,251,140 | 275 | 291 |
#26
N,A,B = map(int,input().split())
num = int(N/(A+B))
blue = 0
blue = num*A
if (N-num*(A+B)) <= A:
blue += (N-num*(A+B))
else:
blue += A
print(blue)
|
import sys
import bisect
input = sys.stdin.readline
n, d, a = map(int, input().split())
xh = sorted([tuple(map(int, input().split()))for _ in range(n)])
x_list = [x for x, h in xh]
damage = [0]*(n+1)
ans = 0
for i in range(n):
x, h = xh[i]
h -= damage[i]
if h <= 0:
damage[i+1] += damage[i]
continue
cnt = -(-h//a)
ans += cnt
damage[i] += cnt*a
end_idx = bisect.bisect_right(x_list, x+2*d)
damage[end_idx] -= cnt*a
damage[i+1] += damage[i]
print(ans)
| 0 | null | 68,827,527,780,802 | 202 | 230 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
x_list = []
while True:
x = int(raw_input())
if x == 0:
break
else:
x_list.append(x)
for i, x in enumerate(x_list, 1):
print("Case %d: %d") % (i, x)
|
N, M = map(int, input().split())
to = [[] for i in range(100010)]
for i in range(M):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
dist = [0] * (N+1)
q = [1]
dist[0] = -1
#print(to[:4])
dist = [0] * N
pre = [0] * N
while len(q) != 0:
a = q.pop(0)
for i in to[a]:
if dist[i-1] == 0:
dist[i-1] = dist[a-1] + 1
pre[i-1] = a
q.append(i)
#print(q)
print("Yes")
for i in range(1, N):
print(pre[i])
| 0 | null | 10,531,115,714,212 | 42 | 145 |
s1 = str(input())
s2 = str(input())
n = len(s1)
if s1 == s2[:n]:
print('Yes')
else:
print('No')
|
s = input()
t = input()
print(['No','Yes'][s == t[:-1]])
| 1 | 21,462,201,982,858 | null | 147 | 147 |
a,b,c=list(map(int,raw_input().split()))
if 4*a*b < (c-(a+b))*(c-(a+b)) and c > (a+b):
print("Yes")
exit(0)
print("No")
|
from decimal import Decimal
a, b, c = [Decimal(x) for x in input().split()]
result = a.sqrt() + b.sqrt() < c.sqrt()
print('Yes' if result else 'No')
| 1 | 51,745,375,693,870 | null | 197 | 197 |
# -*- coding:utf-8 -*-
def solve():
N = int(input())
"""
■ 解法
N = p^{e1} * p^{e2} * p^{e3} ...
と因数分解できるとき、
z = p_i^{1}, p_i^{2}, ...
としていくのが最適なので、それを数えていく
(例) N = 2^2 * 3^2 * 5 * 7
のとき、
2,3,5,7の4回割れる。(6で割る必要はない)
■ 計算量
素因数分解するのに、O(√N)
割れる回数を計算するのはたかだか素因数分解するより少ないはずなので、
全体としてはO(√N+α)くらいでしょ(適当)
"""
def prime_factor(n):
"""素因数分解する"""
i = 2
ans = {}
while i*i <= n:
while n%i == 0:
if not i in ans:
ans[i] = 0
ans[i] += 1
n //= i
i += 1
if n != 1:
ans[n] = 1
return ans
pf = prime_factor(N)
ans = 0
for key, value in pf.items():
i = 1
while value-i >= 0:
value -= i
ans += 1
i += 1
print(ans)
if __name__ == "__main__":
solve()
|
N = int(input())
n = min(N, 10**6)
is_Prime = [True] * (n + 1)
is_Prime[0] = False
is_Prime[1] = False
for i in range(2, int(n**(1/2)+1)):
for j in range(2*i, n+1, i):
if j % i == 0:
is_Prime[j] = False
P = [i for i in range(n+1) if is_Prime[i]]
count = 0
for p in P:
count_p = 0
while N % p == 0:
count_p += 1
N /= p
count += int((-1+(1+8*count_p)**(1/2))/2)
if p == P[-1] and N != 1:
count += 1
print(count)
| 1 | 17,040,588,120,728 | null | 136 | 136 |
n,m,x = map(int,input().split())
array = [list(map(int,input().split())) for _ in range(n)]
# print(array)
# print(n)
ans = 10 ** 8
for i in range(2**n):
skill = [0] * m
price = 0
count = 0
for k in range(n):
if (i >> k) & 1:
price += array[k][0]
for j in range(m):
skill[j] += array[k][j+1]
for l in range(m):
if skill[l] < x:
break
else:
count += 1
if count == m:
ans = min(ans, price)
if ans == 10**8:
print(-1)
else:
print(ans)
|
from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
ans = float("inf")
for i in range(1,n+1):
for j in combinations(ca,i):
l = [0]*(m+1)
for k in j:
for i2 in range(m+1):
l[i2] += k[i2]
if all(l[num] >= x for num in range(1,m+1)):
ans = min(ans, l[0])
if ans == float("inf"): print(-1)
else: print(ans)
| 1 | 22,313,675,617,060 | null | 149 | 149 |
if __name__ == '__main__':
from sys import stdin
from itertools import combinations
while True:
n, x = (int(n) for n in stdin.readline().rstrip().split())
if n == x == 0:
break
a = range(1, n + 1)
l = tuple(filter(lambda _: sum(_) == x, combinations(a, 3)))
print(len(l))
|
import math
a,b,c=[int(i) for i in input().split()]
e=math.ceil(a/c)
if(e<=b):
print('Yes')
else:
print('No')
| 0 | null | 2,425,479,931,190 | 58 | 81 |
while True:
a ,b = map(int, input().split())
if a > b :
print('{} {}'.format(b,a))
elif a == 0 and b == 0 :
break
else:
print('{} {}'.format(a,b))
|
N,M=input().split()
N=int(N)
M=int(M)
if N==M:
print("Yes")
else:
print("No")
| 0 | null | 41,804,977,243,190 | 43 | 231 |
N=int(input())
d=list(map(int, input().split()))
ans=0
for i in range(N):
for j in range(N):
if i == j:
continue
elif i < j:
ans += d[i]*d[j]
print(ans)
|
N = int(input())
d_list = list(map(int,input().split()))
ans = 0
for i in range(N-1):
for j in range(i+1,N):
ans += d_list[i] * d_list[j]
print(ans)
| 1 | 167,888,558,171,972 | null | 292 | 292 |
s = input()
ans = 0
a = []
for i in s:
if i == 'R':
ans += 1
else :
ans = 0
a.append(ans)
print(max(a))
|
#coding:utf-8
#1_6_D 2015.4.5
n,m = map(int,input().split())
matrix = [list(map(int,input().split())) for i in range(n)]
vector = [int(input()) for i in range(m)]
for i in range(n):
print(sum([matrix[i][j] * vector[j] for j in range(m)]))
| 0 | null | 2,989,833,958,660 | 90 | 56 |
word = input()
n = int(input())
for _ in range(n):
meirei = input().split()
if meirei[0] == "print":
print(word[int(meirei[1]):int(meirei[2])+1])
elif meirei[0] == "reverse":
word = word[:int(meirei[1])] + word[int(meirei[1]):int(meirei[2])+1][::-1] + word[int(meirei[2])+1:]
elif meirei[0] == "replace":
word = word[:int(meirei[1])] + meirei[3] + word[int(meirei[2])+1:]
|
n = int(input())
memo = [0 for _ in range(45)]
def fib_memo(n):
if memo[n] != 0:
return memo[n]
elif (n == 0) or (n == 1):
return 1
else:
memo[n] = fib_memo(n-1) + fib_memo(n-2)
return memo[n]
print(fib_memo(n))
| 0 | null | 1,051,455,879,840 | 68 | 7 |
a, b = map(int, input().split())
print('{:d} {:d} {:.10f}'.format(a//b, a%b, a/b))
|
a,b = map(int,input().split())
print("{} {} {:.8f}".format(a//b,a%b,a/b))
| 1 | 609,785,696,058 | null | 45 | 45 |
n=int(input())
a=[[[0 for _ in range(10)]for _ in range(3)]for _ in range(4)]
for i in range(n):
b,f,r,v=map(int, input().split())
a[b-1][f-1][r-1]+=v
for bb in range(4):
for ff in range(3):
print(*[""]+a[bb][ff])
if bb==3:
break
else:
print("#"*20)
|
arr = [[[0 for i1 in range(10)] for i2 in range(3)] for i3 in range(4)]
count=input()
for l in range(int(count)):
b,f,r,v=input().split()
arr[int(b)-1][int(f)-1][int(r)-1]+=int(v)
first_b = arr[0]
second_b = arr[1]
third_b = arr[2]
fourth_b= arr[3]
for m in range(3):
for n in range(10):
print(" "+str(first_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(second_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(third_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(fourth_b[m][n]),end="")
print()
| 1 | 1,093,190,132,608 | null | 55 | 55 |
def main():
s = input()
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
main()
|
def ABC_160_A():
S = input()
if S[2] == S[3] and S[4] == S[5]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
ABC_160_A()
| 1 | 42,236,834,140,868 | null | 184 | 184 |
w=input()
a=0
while True:
t=input().split()
l=[]
for T in t:
l.append(T.lower())
a+=l.count(w)
if t[0]=="END_OF_TEXT":
break
print(a)
|
import re
W = input()
T = []
count = 0
while(1):
line = input()
if (line == "END_OF_TEXT"):
break
words = list(line.split())
for word in words:
T.append(word)
for word in T:
matchOB = re.fullmatch(W, word.lower())
if matchOB:
count += 1
print(count)
| 1 | 1,804,016,619,452 | null | 65 | 65 |
#同値なものはリストでまとめる
n = int(input())
c = [[[] for i in range(9)] for i in range(9)]
for i in range(1,n+1):
s = str(i)
if s[-1] == '0':
continue
c[int(s[0])-1][int(s[-1])-1].append(i)
ans = 0
for i in range(9):
for j in range(9):
ans += len(c[i][j])*len(c[j][i])
print(ans)
|
h,w,k= map(int, input().split())
s = [[int(i) for i in input()] for i in range(h)]
for i in range(h):
for j in range(1,w):
s[i][j]+=s[i][j-1]
for i in range(w):
for j in range(1,h):
s[j][i]+=s[j-1][i]
# 1行目、一列目をゼロにする。
s=[[0]*w]+s
for i in range(h+1):
s[i]=[0]+s[i]
ans=float('inf')
#bit 全探索
for i in range(2**(h-1)):
line=[]
for j in range(h-1):
if (i>>j)&1:
line.append(j+1)
cnt=len(line)
line=[0]+line+[h]
x=0
flag=True
for k1 in range(1,w+1):
v=0
for l in range(len(line)-1):
# どう分割してもダメな奴に✖︎のフラグ立てる
if s[line[l+1]][k1]-s[line[l+1]][k1-1]-s[line[l]][k1]>k:
flag=False
v=max(s[line[l+1]][k1]-s[line[l+1]][x]-s[line[l]][k1]+s[line[l]][x],v)
if v>k:
cnt+=1
x=k1-1
if flag:
ans=min(cnt,ans)
print(ans)
| 0 | null | 67,505,084,079,040 | 234 | 193 |
import numpy as np
from numba import njit
@njit
def myfunc(n, k, A):
for _ in range(k):
l = np.zeros((n + 1,), dtype=np.int64)
for i, a in enumerate(A[:-1]):
l[max(0, i - a)] += 1
l[min(n, i + a + 1)] -= 1
A = np.cumsum(l)
if np.all(A[:-1] == n):
break
return A
def main():
n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)
A = np.append(A, 0)
print(*myfunc(n, k, A)[:-1])
if __name__ == "__main__":
main()
|
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K):
TEMP = [0]*(N+1)
for j in range(N):
TEMP[max(0,j-A[j])] +=1
TEMP[min(N,j+A[j]+1)] -=1
A = list(itertools.accumulate(TEMP))
if A[0] == N and A[N-1] == N:
break
A.pop()
print(*A)
| 1 | 15,309,386,182,168 | null | 132 | 132 |
n=int(input())
a=list(map(int,input().split()))
ans=0
t=10**6
for i in range(n):
if a[i]<t:
ans+=1
t=a[i]
print(ans)
|
def sum_part(N, k):
return k*(2*N-k+1)/2-k*(k-1)/2+1
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2):
ans += sum_part(N, k)
ans = ans % (10**9 + 7)
print(int(ans))
| 0 | null | 59,511,711,576,800 | 233 | 170 |
X = int(input())
# 500円硬貨 1枚につき 1000、5円硬貨 1枚につき 5 の 嬉しさ を得ます。
# X円を持っています。嬉しさの最大値を出力せよ。
s = X // 500
a = X % 500
t = a // 5
print(s*1000 + t*5)
|
x = int(input())
a = x // 500
b = x % 500 // 5
print(a*1000 + b*5)
| 1 | 42,715,511,094,010 | null | 185 | 185 |
while True:
n=input()
if n=='-':break
x=int(input())
for _ in range(x):
h=int(input())
n=n[h:]+n[:h]
print(n)
|
[N, M, X] = map(int, list(input().split(' ')))
A = []
C = []
for i in range(N):
c, *a = map(int, input().split(' '))
C.append(c)
A.append(a)
#print(C)
#print(A)
INF = 10**10
min_cost = INF
for b in range(2**N):
# これがバイナリーベースの全探索となる。今回のキモ part 1
# 一つのループが本の購入セットに対応している
# 各ビットがそれぞれの本を購入するかどうか表している
# 因みに b は bit を表しているつもり
cost = 0 # この購入セットで使う金額
algo_level = [0] * M # 各アルゴリズムトピックの理解度
for i in range(N):
# これが各本のコストと理解度取得のためのループ
# i 番目の本に対してループを回していく
if(b >> i & 1): # この行が今回のキモ part 2。
# i 番目の本の購入有無を判定するために、ビットシフトした値に対して '1 = 0b1' (つまり単なる (2進数の) 1) との論理積を求めている
# この if 文が True であるということは、i 番目の本を買ったということ
cost += C[i]
for a in range(M): # (各本にある) 各アルゴリズムに対するループ
algo_level[a] += A[i][a]
if(min(algo_level) >= X): # 全てのアルゴリズムトピックが X 以上の理解度である場合…
min_cost = min(cost, min_cost)
if(min_cost < INF):
print(min_cost)
else:
print('-1')
| 0 | null | 12,026,964,150,078 | 66 | 149 |
from functools import reduce
from operator import xor
N = int(input())
A = list(map(int, input().split()))
XorA = reduce(xor, A)
B = []
for a in A:
B.append(XorA ^ a)
print(*B)
|
N = int(input())
ans = 0
for a in range(1, 10 ** 6 + 1):
for b in range(1, 10 ** 6 + 1):
if a * b >= N:
break
ans += 1
print(ans)
| 0 | null | 7,475,373,404,448 | 123 | 73 |
from fractions import gcd
def count(x):
ans = 0
while x % 2 == 0:
ans += 1
x = x // 2
return ans
N, M = map(int, input().split(' '))
a = list(map(lambda x: int(x) // 2, input().split(' ')))
lcm, div2 = a[0], count(a[0])
flag = True
for i in range(1, N):
lcm = lcm // gcd(lcm, a[i]) * a[i]
if count(a[i]) != div2:
flag = False
if flag:
print((M // lcm + 1) // 2)
else:
print(0)
|
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 k(): 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 = k()
A = l()
S = sum(A)
minx = S
sum = 0
for x in A:
sum += x
minx = min(minx, abs(sum-(S-sum)))
print(minx)
| 0 | null | 122,191,601,750,034 | 247 | 276 |
print("\n".join(map(str,sorted([int(input())for _ in[0]*10])[:-4:-1])))
|
n = int(input())
p_list = input().split()
p_list = map(int,p_list)
p_list = sorted(p_list,reverse=True)
ans_list = []
ans = 0
for i in range(0,len(p_list)):
if i!=0:
ans_list.append(p_list[i])
ans_list.append(p_list[i])
else:
ans_list.append(p_list[i])
for i in range(0,n-1):
ans += int(ans_list[i])
print(ans)
| 0 | null | 4,622,425,351,700 | 2 | 111 |
import sys
for index, line in enumerate(sys.stdin):
value = int(line.strip())
if value == 0:
break
print("Case {0}: {1}".format(index+1, value))
|
n = 0
while True:
x = input()
if x==0:
break
n+=1
print 'Case %d: %d' %(n, x)
| 1 | 477,157,965,088 | null | 42 | 42 |
N = int(input())
word = [str(input()) for i in range(N)]
dic = {}
for i in word:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
max_num = max(dic.values())
can_word = []
for i,j in dic.items():
if j == max_num:
can_word.append(i)
can_word.sort()
for i in can_word:
print(i)
|
from collections import Counter
def main():
n = int(input())
s = (input() for i in range(n))
d = Counter(s)
num = d.most_common(1)[0][1]
ans = sorted(j[0] for j in d.items() if j[1] == num)
for i in ans:
print(i)
main()
| 1 | 70,076,118,959,070 | null | 218 | 218 |
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=[]
ans=0
for i in range(a):
s=ii()
h=[list(mi()) for _ in range(s)]
l.append(h)
for k in range(2**a):
lst=[]
for p in range(a):
if k>>p & 1:
lst.append(p)
t=True
for aa in lst:
for m in l[aa]:
if m[1]==0:
if m[0]-1 in lst:
t=False
break
else:
if not m[0]-1 in lst:
t=False
break
if t:
ans=max(ans,len(lst))
print(ans)
|
x = input()
for i in xrange(x):
inp = map(int ,raw_input().split())
inp.sort()
if inp[2]**2 == inp[0]**2 + inp[1]**2:
print "YES"
else:
print "NO"
| 0 | null | 61,032,850,326,392 | 262 | 4 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
a, b, c = map(int, sys.stdin.readline().split())
num_div = 0
for x in range(a, b+1):
if c % x == 0:
num_div += 1
print(num_div)
|
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return
for i in range(ord("a"), ord(max(s))+2):
dfs(s+chr(i))
dfs("a")
| 0 | null | 26,582,490,921,180 | 44 | 198 |
poland = input().split()
num = []
for p in poland:
if p.isdigit():
num.append(int(p))
else:
b = num.pop()
a = num.pop()
if p == '*':
num.append(a * b)
elif p == '/':
num.append(a / b)
elif p == '+':
num.append(a + b)
elif p == '-':
num.append(a - b)
print(num.pop())
|
inputEnzan=input().split()
def keisan(inputEnzan):
while True:
stockFornumber=[]
index=0
length=len(inputEnzan)
if length==1:
break
while index<length:
if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
if len(stockFornumber)==2:
if inputEnzan[index]=="+":
inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
elif inputEnzan[index]=="-":
inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
else:
inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
else:
stockFornumber=[]
pass
else:
if len(stockFornumber)==2:
del stockFornumber[0]
stockFornumber.append(int(inputEnzan[index]))
index+=1
while "null" in inputEnzan:
inputEnzan.remove("null")
print(inputEnzan[0])
keisan(inputEnzan)
| 1 | 36,449,718,798 | null | 18 | 18 |
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
import math
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, As):
ans = max(As)
l, r = 1, ans
for _ in range(30):
m = (l + r) // 2
cnt = 0
for A in As:
cnt += math.ceil(A / m) - 1
if cnt <= K:
ans = min(ans, m)
r = m - 1
else:
l = m + 1
if l > r:
break
print(ans)
if __name__ == '__main__':
# S = input()
# N = int(input())
N, K = map(int, input().split())
As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
solve(N, K, As)
|
N = int(input())
A = list(map(int, input().split()))
ct = 0
for n in range(N + 1):
if n % 2:
if A[n - 1] % 2:
ct +=1
print(ct)
| 0 | null | 7,100,041,166,582 | 99 | 105 |
import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
can_make = [False] * 2001
for bit in range(2 ** n):
total = 0
for i in range(n):
if bit & 1 << i > 0:
total += A[i]
if total <= 2000:
can_make[total] = True
for m in M:
if can_make[m]:
print("yes")
else:
print("no")
|
A = []
A += map(int, input().split())
A += map(int, input().split())
A += map(int, input().split())
N = int(input())
for _ in range(N):
b = int(input())
try:
A[A.index(b)] = 0
except ValueError:
pass
res = (
(A[0]+A[1]+A[2])*(A[3]+A[4]+A[5])*(A[6]+A[7]+A[8])*
(A[0]+A[3]+A[6])*(A[1]+A[4]+A[7])*(A[2]+A[5]+A[8])*
(A[0]+A[4]+A[8])*(A[2]+A[4]+A[6])
)
print("Yes" if res == 0 else "No")
| 0 | null | 29,999,785,739,282 | 25 | 207 |
x = int(input())
a = 100
i = 0
while a < x:
i += 1
a += a // 100
print(i)
|
import string
n = int(input())
alphabet = list(string.ascii_lowercase)
ans = ''
while n > 0:
ans = alphabet[(n-1) % 26] + ans
n = (n-1) // 26
print(ans)
| 0 | null | 19,538,958,562,888 | 159 | 121 |
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 L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7
N,M = I()
a = l()
num1 = format(a[0],'b')[::-1].find('1')
num2 = 1
for i in range(N):
num2 = lcm(num2,a[i])
if num1 != format(a[i],'b')[::-1].find('1'):
print(0)
exit()
num2 = num2//2
print(math.ceil(M//num2/2))
|
class UnionFind():
def __init__(self, n):
self.parents = list(range(n))
self.rank = [0] * n
def find(self, x):
if self.parents[x] == x:
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.rank[x] < self.rank[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
x, y = map(int, input().split())
x, y = x-1, y-1
uf.union(x, y)
for i in range(n):
uf.find(i)
print(len(set(uf.parents))-1)
| 0 | null | 51,887,212,365,980 | 247 | 70 |
n=int(input())
s=input()
ans=0
for i in range(10):
for j in range(10):
for k in range(10):
tar=str(i)+str(j)+str(k)
now=0
for l in range(n):
if tar[0+now]==s[l]:now+=1
if now==3:
ans+=1
break
print(ans)
|
N = int(input())
N_ri = round(pow(N, 1/2))
for i in range(N_ri, 0, -1):
if N % i == 0:
j = N // i
break
print(i + j - 2)
| 0 | null | 145,064,332,027,922 | 267 | 288 |
print("Yes" if "7" in list(input()) else "No")
|
n = int(input())
statements = []
for i in range(n):
a = int(input())
astates = [list(map(int, input().split())) for _ in range(a)]
statements.append(astates)
cnt = 0
for i in range(2**n):
state = format(i, "0"+str(n)+"b")
pos = True
for j in range(n):
if state[j] == "1":
for x, y in statements[j]:
if not (state[x-1] == str(y)):
pos = False
break
if not pos:
break
if pos:
cnt = max(cnt, state.count("1"))
print(cnt)
| 0 | null | 78,124,500,871,900 | 172 | 262 |
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush
from decimal import *
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除&その最小値を出力
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
##### 累乗 #####
# pow(x, y, z) -> x**y % z
##### 割り算の切り上げ #####
# tmp = -(-4 // 3)
##### dict の for文 #####
# for k, v in d.items():
# print(k, v)
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]
inf = float('inf')
mod = 1000000007
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
N = inputInt()
pazuru_nobori = []
pazuru_kudari = []
for i in range(N):
S = inputStr()
tmp = 0
min_tmp = 0
for s in S:
if s == "(":
tmp += 1
else:
tmp -= 1
if min_tmp > tmp:
min_tmp = tmp
if tmp >= 0:
pazuru_nobori.append((min_tmp,tmp))
else:
pazuru_kudari.append((min_tmp,tmp))
pazuru_nobori.sort()
pazuru_nobori = pazuru_nobori[::-1]
score = 0
for i,val in enumerate(pazuru_nobori):
min_tmp,tmp = val
if score + min_tmp < 0:
print("No")
sys.exit()
score += tmp
pazuru_kudari_non = []
for i,val in enumerate(pazuru_kudari):
min_tmp,tmp = val
min_tmp_2 = min_tmp - tmp
tmp_2 = -1 * tmp
pazuru_kudari_non.append((min_tmp_2,tmp_2))
pazuru_kudari_non.sort()
pazuru_kudari_non = pazuru_kudari_non[::-1]
score2 = 0
for i,val in enumerate(pazuru_kudari_non):
min_tmp,tmp = val
if score2 + min_tmp < 0:
print("No")
sys.exit()
score2 += tmp
if score2 == score:
print("Yes")
else:
print("No")
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
if N < K or K-1 < 0:
return 0
else:
return combination(N-1, K-1, mod)
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
# comb = Combination(n+r-1, mod)
# return comb(n+r-1, r)
return combination(n+r-1, r, mod)
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
stk = []
stk.append(edge)
while len(stk) > 0:
p = stk.pop()
for e in graph[p]:
if parent[p] == e:
continue
else:
parent[e] = p
counter[e] += counter[p]
stk.append(e)
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
main()
|
n = int(input())
buf = [0]*n
def solv(idx,char):
aida = n - idx
if idx == n:
print("".join(buf))
return
for i in range(char + 1):
buf[idx] = chr(ord('a') + i)
solv(idx+1,max(i + 1,char))
solv(0,0)
| 0 | null | 37,933,402,829,076 | 152 | 198 |
N = int(input())
S = input()
if N % 2 !=0:
print('No')
else:
n = int(N/2)
s1 = S[:n]
s2 = S[n:]
if s1 == s2:
print('Yes')
else:
print('No')
|
n = int(input())
s = list(input())
m = n//2
if n%2 != 0:
ans = "No"
else:
for i in range(m):
if s[i] != s[m+i]:
ans = "No"
break
ans = "Yes"
print(ans)
| 1 | 146,857,066,588,750 | null | 279 | 279 |
N, K = map(int, input().split())
INF = 998244353
LR = []
for i in range(K):
LR.append(list(map(int, input().split())))
dp = [0] * N
dp[0] = 1
a_sum = [0] * N
a_sum[0] = 1
for i in range(1, N):
for lr in LR:
if i - lr[0] >= 0:
if i - lr[1]-1 >= 0:
# print(i, lr, dp[i], i-lr[0], i-lr[1]-1, a_sum[i-lr[0]], a_sum[i-lr[1]-1])
dp[i] = dp[i] + a_sum[i-lr[0]] - a_sum[i-lr[1]-1]
else:
dp[i] = dp[i] + a_sum[i-lr[0]]
dp[i] %= INF
a_sum[i] = a_sum[i-1] + dp[i]
a_sum[i] %= INF
# print(i, dp, a_sum)
print(dp[-1])
|
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8
@njit(i8(i8,i8,i8,i8[:,:],i8[:],i8,i8))
def give_dp(N,K,mod,LR,dp,l,r):
for i in range(N):
if i > 0:
dp[i] += dp[i-1]
dp[i] %= mod
for k in range(K):
l = LR[k][0]
r = LR[k][1]
if i + l < N:
dp[i+l] += dp[i]
dp[i+1] %= mod
if i + r < N:
dp[i+r+1] -= dp[i]
dp[i+1] %= mod
return dp[-1]
def main():
N,K = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(K)]
LR = np.array(LR)
mod = 998244353
dp = [0 for i in range(N)]
dp[0] = 1
dp[1] = -1
dp = np.array(dp)
res = give_dp(N,K,mod,LR,dp,0,0)
res %= mod
print(res)
main()
| 1 | 2,662,752,490,404 | null | 74 | 74 |
a = input()
if a >= 'a' and a <= 'z':
print('a')
elif a >= 'A' and a <= 'Z':
print('A')
|
MOD = 998244353
class mint:
def __init__(self, x):
if isinstance(x, int):
self.x = x % MOD
elif isinstance(x, mint):
self.x = x.x
else:
self.x = int(x) % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __iadd__(self, other):
self.x += other.x if isinstance(other, mint) else other
self.x -= MOD if self.x >= MOD else 0
return self
def __isub__(self, other):
self.x += MOD-other.x if isinstance(other, mint) else MOD-other
self.x -= MOD if self.x >= MOD else 0
return self
def __imul__(self, other):
self.x *= other.x if isinstance(other, mint) else other
self.x %= MOD
return self
def __add__(self, other):
return (
mint(self.x + other.x) if isinstance(other, mint) else
mint(self.x + other)
)
def __sub__(self, other):
return (
mint(self.x - other.x) if isinstance(other, mint) else
mint(self.x - other)
)
def __mul__(self, other):
return (
mint(self.x * other.x) if isinstance(other, mint) else
mint(self.x * other)
)
def __floordiv__(self, other):
return (
mint(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, mint) else
mint(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
mint(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
mint(other.x - self.x) if isinstance(other, mint) else
mint(other - self.x)
)
__rmul__ = __mul__
def __rfloordiv__(self, other):
return (
mint(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, mint) else
mint(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
mint(pow(other, self.x, MOD))
)
n,s = map(int, input().split())
a = list(map(int, input().split()))
import copy
dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
dp[0][0]=pow(2,n,MOD)
div=pow(2,MOD-2,MOD)
for i in range(n):
for j in range(s+1):
dp[i+1][j]=dp[i][j]
if j-a[i]>=0:
dp[i+1][j]+=dp[i][j-a[i]]*div
dp[i+1][j]%=MOD
print(dp[n][s])
| 0 | null | 14,541,438,640,122 | 119 | 138 |
number = list(map(int,input().split()))
score = list(map(int,input().split()))
score.sort()
answer = 0
if number[1] > number [0]:
number[1] = number[0]
for i in range(number[1]):
score[number[0]-1-i] = 0
for j in range(number[0]):
answer += score[j]
print(answer)
|
import sys
import time
import math
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N = int(input())
d = inpl()
ans = 0
for i in range(N-1):
for j in range(i+1, N):
ans += d[i] * d[j]
print(ans)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 0 | null | 124,176,415,181,642 | 227 | 292 |
def main():
n = int(input())
_list = list(range(1,n+1))
for x in _list:
if x % 3 == 0 or any(list(map(lambda x: x == 3, list(map(int,list(str(x))))))):
print(' %d' % x, end = '')
print()
main()
|
n = int(input())
for i in range(1,n+1):
x = i
if x % 3 == 0:
print(' {}'.format(i), end='')
else:
while x:
if x % 10 == 3:
print(' {}'.format(i), end='')
break
else:
x //= 10
print('')
| 1 | 928,677,366,494 | null | 52 | 52 |
n, m = map(int, input().split())
temp = list(['?'] * n)
# print(temp)
if (m == 0):
if (n == 1):
ans = 0
else:
ans = '1' + '0' * (n - 1)
else:
for _ in range(m):
s, c = map(int, input().split())
if (s == 1 and c == 0 and n >= 2):
print(-1)
exit()
else:
pass
if (temp[s-1] == '?'):
temp[s - 1] = str(c)
elif (temp[s - 1] == str(c)):
pass
else:
print(-1)
exit()
if (temp[0] == '?'):
temp[0] = '1'
ans01 = ''.join(temp)
ans = ans01.replace('?', '0')
print(ans)
|
import math
n, x, t = [int(x) for x in input().split()]
print(math.ceil(n/x)*t)
| 0 | null | 32,342,200,128,408 | 208 | 86 |
n, a, b = map(int, input().split())
MOD = 10**9+7
def comb(n, k, MOD):
x = 1
for i in range(k):
x *= (n-i)
x *= pow(i+1, MOD-2, MOD)
x %= MOD
return x
ans = pow(2, n, MOD) - 1 - comb(n, a, MOD) - comb(n, b, MOD)
ans += MOD
ans %= MOD
print(ans)
|
"""
s=1817181712114 なら
4
10
100
2000
10000
700000
1000000
80000000
100000000
7000000000
10000000000
800000000000
1000000000000
の数列とみて, 各々%Pを取ってzero sum range
P=2,5がコーナー
"""
from collections import Counter
def make_modlist(Len,mod):
modlist=[0]*Len
modlist[0]=1
for i in range(1,Len):
modlist[i]=10*modlist[i-1]%mod
return modlist
n,p=map(int,input().split())
a=list(map(int,input()))
ans=0
a.reverse()
if p==2 or p==5:
for i in range(n):
if a[i]%p==0:
ans+=n-i
else:
d=make_modlist(n,p)
b=[0]*(n+1)
for i in range(n):
b[i+1]=a[i]*d[i]%p
for i in range(1,n+1):
b[i]+=b[i-1]
b[i]%=p
for i in Counter(b).values():
ans+=i*(i-1)//2
print(ans)
| 0 | null | 62,121,764,947,268 | 214 | 205 |
dice = {v: k for k, v in enumerate(list(map(int, input().split())))}
adjacent = {k: v for k, v in enumerate(sorted(dice.keys()))}
q = int(input())
p = [(-1,2,4,1,3,-1),(3,-1,0,5,-1,2),(1,5,-1,-1,0,4),(4,0,-1,-1,5,1),(2,-1,5,0,-1,3),(-1,3,1,4,2,-1)]
for _ in range(q):
top, front = map(int, input().split())
x = dice[top]
y = dice[front]
print(adjacent[p[x][y]])
|
import sys
input = sys.stdin.readline
H,W,K =list(map(int,input().split()))
s = [input().rstrip() for _ in range(H)]
cut = [[0]*W for _ in range(H)]
cnt =0
for ih in range(H):
if s[ih].count('#')==0:
continue
else:
for iw in range(W):
if s[ih][iw] == '#':
cnt +=1
cut[ih][iw]= cnt
for ih in range(H):
for iw in range(W-1):
if cut[ih][iw+1] ==0:
cut[ih][iw+1]= cut[ih][iw]
for iw in range(W-1,0,-1):
if cut[ih][iw-1] ==0:
cut[ih][iw-1]= cut[ih][iw]
for ih in range(H-1):
if cut[ih+1][0]==0:
for iw in range(W):
cut[ih+1][iw] = cut[ih][iw]
for ih in range(H-1,0,-1):
if cut[ih-1][0]==0:
for iw in range(W):
cut[ih-1][iw] = cut[ih][iw]
for i in range(H):
print(*cut[i])
| 0 | null | 71,851,844,838,698 | 34 | 277 |
import math
a, b, C = map(int, input().split())
C = math.radians(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
S = a * b * math.sin(C) / 2
print(f"{S:0.9f}")
print(f"{a+b+c:0.9f}")
print(f"{S*2/a:0.9f}")
|
# -*- coding: utf-8 -*-
import math
a, b, C = map(int, raw_input().split())
radC = math.radians(C)
c = math.sqrt(a*a+b*b-2*a*b*math.cos(radC))
S = a*b/2*math.sin(radC)
print S
print a+b+c
print 2*S/a
| 1 | 181,768,325,408 | null | 30 | 30 |
N, M = map(int, input().split())
H = list(map(int, input().split()))
table = []
for i in range(N):
table.append(set())
for i in range(M):
Ai, Bi = map(lambda x: x - 1, map(int, input().split()))
table[Ai].add(Bi)
table[Bi].add(Ai)
answer = 0
for i, h in enumerate(H):
highest = True
for path in table[i]:
if h <= H[path]:
highest = False
if highest:
answer += 1
print(answer)
|
N,M=map(int, input().split())
peaks=list(map(int, input().split()))
flag=[1]*N
a=0
b=0
for i in range(M):
a,b=map(int,input().split())
a-=1
b-=1
if peaks[a]<=peaks[b]:
flag[a]=0
if peaks[a]>=peaks[b]:
flag[b]=0
ans=0
for i in flag:
ans+=i
print(ans)
| 1 | 25,152,457,028,540 | null | 155 | 155 |
def resolve():
S = str(input())
if S =='ABC':
print('ARC')
else:
print('ABC')
return
resolve()
|
S=input()
if S=="ABC":
print("ARC")
else:print("ABC")
| 1 | 24,262,664,846,420 | null | 153 | 153 |
N = int(input())
S = list(map(int,input().split()))
def marge(l,r):
count = 0
conq = []
i = 0
j = 0
k = len(l) + len(r)
l.append(float('inf'))
r.append(float('inf'))
for o in range(k):
if l[i] <= r[j]:
conq.append(l[i])
i += 1
else:
conq.append(r[j])
j += 1
count += 1
return conq,count
def margeSort(s):
n = len(s)
if n == 1:
return s,0
else:
L, cnt_L = margeSort(s[:n//2])
R,cnt_R = margeSort(s[n//2:])
s,cnt = marge(L,R)
return s,cnt+cnt_R+cnt_L
S,count = margeSort(S)
print(*S)
print(count)
|
WHxyr = input().split()
W = int(WHxyr[0])
H = int(WHxyr[1])
x = int(WHxyr[2])
y = int(WHxyr[3])
r = int(WHxyr[4])
if x-r<0 or x+r>W or y-r<0 or y+r>H:
print("No")
else:
print("Yes")
| 0 | null | 286,508,609,942 | 26 | 41 |
s = input()
if(s[2] == s[3] and s[4] == s[5]):
print("Yes")
else:
print("No")
|
s = list(input())
print(['No', 'Yes'][s[2] == s[3] and s[4] == s[5]])
| 1 | 41,884,854,369,312 | null | 184 | 184 |
a,b = map(str, input().split())
a2 = a*int(b)
b2 = b*int(a)
print(a2) if a2 < b2 else print(b2)
|
A, B = map(str, input().split())
A_ans=''
B_ans=''
if min(A,B) == A:
for a in range(int(B)):
A_ans += A
print(A_ans)
else:
for b in range(int(A)):
B_ans += B
print(B_ans)
| 1 | 84,878,321,346,588 | null | 232 | 232 |
K = int(input())
S = input()
if len(S) >K:
S = S[:K] + '...'
print(S)
|
# S の長さが K 以下であれば、S をそのまま出力してください。
# S の長さが K を上回っているならば、
# 先頭 K 文字だけを切り出し、末尾に ... を付加して出力してください。
# K は 1 以上 100 以下の整数
# S は英小文字からなる文字列
# S の長さは 1 以上 100 以下
K = int(input())
S = str(input())
if K >= len(S):
print(S)
else:
print((S[0:K] + '...'))
| 1 | 19,770,163,996,612 | null | 143 | 143 |
while 1 :
a,op,b=raw_input().split()
ai=int(a)
bi=int(b)
if op=='?':break
elif op=='+':print ai+bi
elif op=='-':print ai-bi
elif op=='*':print ai*bi
elif op=='/':print ai/bi
|
from collections import deque
N = int(input())
C = input()
r = deque()
lr = 0
for i in range(N):
if C[i] == 'R':
lr += 1
r.append(i)
ans = 0
for i in range(N):
if lr == 0:
break
if C[i] == 'W':
if i < r[-1]:
ans += 1
r.pop()
lr -= 1
else:
break
print(ans)
| 0 | null | 3,453,943,389,700 | 47 | 98 |
#coding: UTF-8
N=int(input())
p=[int(input()) for i in range(0,N)]
maxv=p[1]-p[0]
buy=p[0]
for i in range(1,N):
if p[i]-buy>maxv:
maxv=p[i]-buy
if p[i]<buy:
buy=p[i]
print(maxv)
|
from collections import Counter
N,*A = map(int, open(0).read().split())
ac = Counter(A)
if len(ac) == N:
print('YES')
else:
print('NO')
| 0 | null | 37,013,326,754,888 | 13 | 222 |
A = int(input())
B = int(input())
AB = [A,B]
Ans = [x for x in range(1,4) if x not in AB]
print(Ans[0])
|
s = input()
n = len(s)
sd = s[::-1]
a = s[:int((n-1)/2)]
ad = a[::-1]
b = s[int((n+3)/2-1):]
bd = b[::-1]
if s == sd and a == ad and b == bd:
print('Yes')
else:
print('No')
| 0 | null | 78,210,387,391,390 | 254 | 190 |
import sys
array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(array[int(sys.stdin.readline()) - 1])
|
def main():
ary = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(ary[K - 1])
main()
| 1 | 49,917,381,372,352 | null | 195 | 195 |
N,A,B = map(int, input().split())
div, mod = divmod(N, A+B)
print(div*A + min(mod,A))
|
n,a,b = map(int,input().split())
if a == 0:
print(0)
elif a+b <= n and n%(a+b) < a:
print((n//(a+b))*a + n%(a+b))
elif a+b <= n and n%(a+b) >= a:
print((n//(a+b))*a + a)
elif n < a+b and n < a:
print(n)
elif n < a+b and a <= n:
print(a)
| 1 | 55,626,029,576,308 | null | 202 | 202 |
num = list(map(int,input()))
if num[-1] == 3:
print("bon")
elif num[-1] in (0, 1, 6, 8):
print("pon")
else:
print("hon")
|
n=input()
hon="24579"
pon="0168"
x=n[len(n)-1]
if x in hon:
print("hon")
elif x in pon:
print("pon")
else:
print("bon")
| 1 | 19,315,030,084,752 | null | 142 | 142 |
n=int(input())
d=list(map(int,input().split()))
if d[0] != 0:
print(0)
exit()
d.sort()
if d[1] == 0:
print(0)
exit()
cnt = 1
pre = 1
ans =1
i = 1
mod = 998244353
while i < n:
if d[i]-1 != d[i-1]:
ans = 0
while i!=n-1 and d[i+1] == d[i]:
i+=1
cnt+=1
ans *= pow(pre,cnt,mod)
ans %= mod
pre =cnt
cnt = 1
i+=1
print(ans)
|
import collections
N=int(input())
D=list(map(int,input().split()))
mod=998244353
if D[0]!=0:
print(0);exit()
D=collections.Counter(D)
if D[0]!=1:
print(0);exit()
ans=1
for i in range(1,len(D)):
ans*=pow(D[i-1],D[i],mod)
ans%=mod
print(ans)
| 1 | 154,345,540,974,950 | null | 284 | 284 |
a = int(input())
b = a ** 2
print(b)
|
import sys
input = sys.stdin.readline
n, (s, t) = int(input()), input()[:-1].split()
print(''.join(s[i] + t[i] for i in range(n)))
| 0 | null | 128,710,184,393,342 | 278 | 255 |
X = int(input())
for i in range(1, 100001):
if 100*i <= X <= 105*i:
print(1)
exit(0)
print(0)
|
S, T = map(str, input().split())
print(T+S)
| 0 | null | 115,077,751,812,140 | 266 | 248 |
import sys
while True:
try:
word = input()
if word == "-":
break
word_len = len(word)
words_shuffle = []
for i in range(word_len):
words_shuffle.append(word[i])
n = int(input())
for i in range(n):
h = int(input())
words_shuffle = words_shuffle[h:] + words_shuffle[:h]
for i in range(word_len-1):
print(words_shuffle[i], end="")
print(words_shuffle[-1])
except EOFError:
break
|
import sys
def input():
return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
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()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(N+1)
for i in range(M):
a,b=map(int, input().split())
uf.union(a,b)
print(uf.group_count()-2)
| 0 | null | 2,110,494,588,162 | 66 | 70 |
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x) if isinstance(other, ModInt) else
ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x) if isinstance(other, ModInt) else
ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x) if isinstance(other, ModInt) else
ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(self.power_func(self.x, other.x, MOD)) if isinstance(other, ModInt) else
ModInt(self.power_func(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
ModInt(other.x - self.x) if isinstance(other, ModInt) else
ModInt(other - self.x)
)
__rmul__ = __mul__
def __rtruediv__(self, other):
return (
ModInt(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(other, self.x, MOD))
)
def power_func(self,a,n,p):
bi=str(format(n,"b"))#2進表現に
res=1
for i in range(len(bi)):
res=(res*res) %p
if bi[i]=="1":
res=(res*a) %p
return res
#グローバル変数MODを決めてあげてください
#グローバル変数MODを決めてあげてください
MOD = 10**9 + 7
N,K=[int(hoge) for hoge in input().split()]
Kazus = [0]*(K+1)
for x in range(K,0,-1):
Dmax = K//x
MoDmax = ModInt(Dmax)
kazu = MoDmax ** N
for d in range(Dmax,1,-1):
kazu -= Kazus[d*x]
Kazus[x] = kazu
print(sum([x*k for x,k in enumerate(Kazus) ]))
|
if __name__ == '__main__':
from sys import stdin
r, c = (int(n) for n in stdin.readline().split())
table = []
for _ in range(r):
row = [int(n) for n in stdin.readline().split()]
row.append(sum(row))
print(" ".join(map(str, row)))
table.append(row)
sum_column = (sum(column) for column in zip(*table))
print(" ".join(map(str, sum_column)))
| 0 | null | 18,980,810,812,082 | 176 | 59 |
import sys
n = int(input())
for i in range(1,10):
for j in range(1,10):
if i * j == n :
print('Yes')
sys.exit()
print('No')
|
if __name__ == '__main__':
n, m, l = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]
B = [[int(i) for i in input().split()] for j in range(m)]
B = list(map(list, zip(*B))) # trace
C = [[sum(map(lambda x,y: x*y, A[i], B[j])) for j in range(l)] for i in range(n)]
for i in C:
print(' '.join([str(x) for x in i]))
| 0 | null | 80,253,339,120,580 | 287 | 60 |
x, y = [int(n) for n in input().split()]
while True:
tmp = x % y
if tmp == 0:
break
x, y = y, tmp
print(y)
|
#coding:UTF-8
def GCD(x,y):
d=0
if x < y:
d=y
y=x
x=d
if y==0:
print(x)
else:
GCD(y,x%y)
if __name__=="__main__":
a=input()
x=int(a.split(" ")[0])
y=int(a.split(" ")[1])
GCD(x,y)
| 1 | 8,187,977,368 | null | 11 | 11 |
n = int(input())
answer = 0 # 和の格納用
for i in range(1, n + 1):
if i % 3 == 0 or i % 5 == 0:
continue
else:
answer += i
print(answer)
|
N,R=[int(x) for x in input().rstrip().split()]
if 10<=N:
print(R)
else:
print(R+100*(10-N))
| 0 | null | 49,070,364,606,958 | 173 | 211 |
i = [i for i in input().split()]
op = ['+', '*', '-']
stack = []
for j in i:
if j in op:
r = stack.pop()
l = stack.pop()
stack.append(str(eval(l + j + r)))
else:
stack.append(j)
print (stack[0])
|
import sys
K=input()
if int(K)%2==0:
print(-1)
sys.exit()
S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
if S%K==0:
print(ans)
break
else:
S=(S*10)%K+7
ans+=1
else:
print(-1)
| 0 | null | 3,036,611,225,920 | 18 | 97 |
a=input()
print("a") if a.islower() else print("A")
|
import math
N, K = map(int,input().split())
A = list(map(int, input().split()))
l, r = 0, max(A)
while r - l > 1:
x = (l + r) // 2
cnt = 0
for a in A:
n = math.ceil(a / x)
# n = (a + x - 1) // x
cnt += n - 1
if cnt > K:
l = x
else:
r = x
print(r)
| 0 | null | 8,935,078,421,630 | 119 | 99 |
from sys import stdin,stdout
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
mod=1000000007
INF=float('inf')
for _ in range(1):
s=st()
if s[-1]=='s':
print(''.join(s)+'es')
else:
print(''.join(s)+'s')
|
from sys import stdin
def ans():
_in = [_.rstrip() for _ in stdin.readlines()]
S = _in[0] # type:str
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if S[-1] == 's':
S += 'es'
else:
S += 's'
ans = S
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
S = list(_in[0]) # type:str
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ans = 0
if S[-1] == 's':
S[-1] += 'es'
else:
S[-1] += 's'
ans = ''.join(S)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
#main()
ans()
| 1 | 2,396,665,637,490 | null | 71 | 71 |
import sys
printf = sys.stdout.write
mat = []
new_map = []
r,c = map(int, raw_input().split())
for i in range(r):
mat = map(int, raw_input().split())
new_map.append(mat)
for i in range(r):
new_map[i].append(sum(new_map[i][:]))
for j in range(c):
print new_map[i][j],
printf(" " + str(new_map[i][j + 1]) + "\n")
for j in range(c + 1):
a = 0
for i in range(r):
a += new_map[i][j]
if j == c:
printf(" " + str(a) + "\n")
break
else:
print a,
|
ans = ''
r, c = map(int, input().split(' '))
i = 0
L = [0] * (c + 1)
while i < r:
a = list(map(int, input().split(' ')))
atot = 0
j = 0
while j < c:
atot += a[j]
L[j] += a[j]
j += 1
ans += ' '.join(map(str, a)) + ' ' + str(atot) + '\n'
L[c] += atot
i += 1
if ans != '':
ans += ' '.join(map(str, L))
print(ans)
| 1 | 1,344,453,071,280 | null | 59 | 59 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K, C = mapint()
S = list(input())
r_S = S[::-1]
pos = [0]*N
neg = [0]*N
ok = 0
cnt = 0
for i in range(N):
if S[i]=='o':
if ok<=i:
pos[i] = cnt + 1
cnt += 1
ok = i + C + 1
if cnt==K:
break
else:
pass
ok = 0
cnt = 0
for i in range(N):
if r_S[i]=='o':
if ok<=i:
neg[i] = cnt + 1
cnt += 1
ok = i + C + 1
if cnt==K:
break
else:
pass
ans = []
neg = neg[::-1]
for i in range(N):
if pos[i]+neg[i]-1==K:
ans.append(i)
for a in ans:
print(a+1)
|
n, k, c = map(int, input().split())
s = input()
work = [1]*n
rest = 0
for i in range(n):
if rest:
rest -= 1
work[i] = 0
continue
if s[i] == 'x':
work[i] = 0
elif s[i] == 'o':
rest = c
rest = 0
for i in reversed(range(n)):
if rest:
rest -= 1
work[i] = 0
continue
if s[i] == 'o':
rest = c
if k < sum(work):
print()
else:
for idx, bl in enumerate(work):
if bl:
print(idx+1)
| 1 | 40,391,762,833,590 | null | 182 | 182 |
v,w,x,y=map(float,input().split())
print(float((abs(v-x)**2)+abs(w-y)**2)**(1/2))
|
from math import *
x1, y1, x2, y2 = map(float, raw_input().split())
distance = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
print distance
| 1 | 158,681,833,252 | null | 29 | 29 |
import sys, math
from itertools import permutations, combinations, accumulate
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))
N = int(input())
G = [list(map(int, input().split())) for _ in range(N)]
c = [0]*N # 0:not found, 1:found, 2:finished
res = [[0]*2 for _ in range(N)]
time = 1
def dfs(index):
# print('index:', index)
global time
if c[index]==0:
c[index]=1
res[index][0] = time # found
time += 1
elif c[index]==1:
return
elif c[index]==2:
return
u, k, *v = G[index]
for node in v:
dfs(node-1) # 1-index -> 0-index
c[index] = 2
res[index][1] = time # finished
time += 1
return
for i in range(N):
dfs(i)
res = [[val1]+val2 for val1, val2 in zip(list(range(1, N+1)), res)]
for val in res:
print(*val)
|
n = int(input())
memo = [0 for _ in range(45)]
def fib_memo(n):
if memo[n] != 0:
return memo[n]
elif (n == 0) or (n == 1):
return 1
else:
memo[n] = fib_memo(n-1) + fib_memo(n-2)
return memo[n]
print(fib_memo(n))
| 0 | null | 2,604,507,040 | 8 | 7 |
N=int(input())
S=input()
cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B')
ans=cntR*cntG*cntB
for i in range(N-2):
for j in range(i+1,N-1):
if S[i]!=S[j]:
k=2*j-i
if k<N and S[k]!=S[i] and S[k]!=S[j]:
ans-=1
print(ans)
|
from itertools import permutations
n = int(input())
s = input()
out = 0
ans = s.count("R")*s.count("G")*s.count("B")
combi = list(permutations(["R","G","B"],3))
for i in range(1,n):
for j in range(n-i*2):
if (s[j], s[j+i], s[j+i*2]) in combi:
ans -= 1
print(ans)
| 1 | 36,089,406,721,410 | null | 175 | 175 |
import sys
read = sys.stdin.buffer.read
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
import math
def main():
k=II()
ans=0
li=[[0]*(k+1) for i in range(k+1)]
for a in range(1,k+1):
for b in range(1,k+1):
li[a][b]=math.gcd(a,b)
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
ans+=math.gcd(li[a][b],c)
print(ans)
if __name__ == "__main__":
main()
|
import sys
import itertools
from math import gcd
n = int(sys.stdin.read())
print(sum(gcd(gcd(abc[0], abc[1]), abc[2]) for abc in itertools.product(range(1, n + 1), repeat=3)))
| 1 | 35,739,340,134,656 | null | 174 | 174 |
import math
A, B = [i for i in input().split()]
A = int(A)
tmp = B.split('.')
B = 100 * int(tmp[0]) + int(tmp[1])
print((A*B)//100)
|
a,b = input().split()
a = int(a)
b_list = list(b)
b_list.pop(1)
b_list = [int(s) for s in b_list]
p_100 = a*b_list[0]*100 + a*b_list[1]*10 + a*b_list[2]
p = p_100//100
print(p)
| 1 | 16,496,006,050,360 | null | 135 | 135 |
N = int(input())
A = [int(i) for i in input().split()]
temp = 0
for i in A:
temp ^= i
for i in A:
print(temp ^ i)
|
N = int(input())
S = input()
ans = 0
pre = ''
for i in range(N):
if pre != S[i:i+1]: ans += 1
pre = S[i:i+1]
print(ans)
| 0 | null | 90,968,701,179,460 | 123 | 293 |
n, m = map(int, input().split())
conditions = [tuple(map(int, input().split())) for j in range(m)]
exist = False
for i in range(1000):
if len(str(i)) == n and all(str(i)[s - 1] == str(c) for s, c in conditions):
ans = i
exist = True
break
print(ans if exist else -1)
|
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
N,M=MI()
st=pow(10,N-1)
en=pow(10,N)
if N==1:
st=0
s=[0]*M
c=[0]*M
for i in range(M):
s[i],c[i]=MI()
s[i]-=1
ans=-1
for i in range(st,en):
flag=1
i2=str(i)
for j in range(M):
aaa=int(i2[s[j]])
if aaa!=c[j]:
flag=0
break
if flag:
ans=i
break
print(ans)
main()
| 1 | 60,853,727,471,422 | null | 208 | 208 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
def solve(K: int):
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
solve(K)
if __name__ == '__main__':
main()
|
import sys
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
a, b, c = map(int, input().split())
a, b, = a - 1, b -1
G[a][b] = c
G[b][a] = c
#全点間最短距離を計算
G = floyd_warshall(G)
#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
for j in range(N):
if G[i][j] <= L:
E[i][j] = 1
#全点間最短距離を計算
E = floyd_warshall(E)
#クエリに答えていく
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
s, t = s - 1, t-1
print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1)
| 0 | null | 111,815,597,192,530 | 195 | 295 |
s = input()
ans = 0
if s[0] == "R":
ans += 1
if s[1] == "R":
ans += 1
if s[2] == "R":
ans += 1
elif s[1] == "R":
ans += 1
if s[2] == "R":
ans += 1
elif s[2] == "R":
ans += 1
print(ans)
|
s = input()
if s in ["RRR"]:
print(3)
if s in ["RRS", "SRR"]:
print(2)
if s in ["RSR", "RSS", "SRS", "SSR"]:
print(1)
if s == "SSS":
print(0)
| 1 | 4,894,134,018,682 | null | 90 | 90 |
h,n = map(int,input().split())
Mag = []
for i in range(n):
AB = list(map(int,input().split()))
Mag.append(AB)
dp = [[float("inf")]*(h+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(h+1):
dp[i+1][j] = min(dp[i+1][j],dp[i][j])
dp[i+1][min(j+Mag[i][0],h)] = min(dp[i+1][min(j+Mag[i][0],h)],dp[i+1][j]+Mag[i][1])
print(dp[n][h])
|
while True:
Input = raw_input().split()
a = int(Input[0])
op = Input[1]
b = int(Input[2])
if op == "+":
ans = a + b
print ans
elif op == "-":
ans = a - b
print ans
elif op == "/":
ans = a / b
print ans
elif op == "*":
ans = a * b
print ans
elif op == "?":
break
| 0 | null | 40,635,444,876,420 | 229 | 47 |
x1,y1,x2,y2 = map(float,input().split())
an = (x1 - x2)**2 + (y1 - y2)**2
dis = an/2
v = an/4
while abs(dis**2 - an) > 0.0001:
if dis**2 > an:
dis -= v
else:
dis += v
v = v/2
print(dis)
|
import math
a = float(input())
print(str("{0:.6f}".format((a * a) * math.pi)) + " " + str("{0:.5f}".format((a + a) * math.pi)))
| 0 | null | 397,341,000,842 | 29 | 46 |
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
A_temp=[0]*(N+1)
for i in range(N):
A_temp[max(0,i-A[i])]+=1
if i+A[i]+1<=N-1:
A_temp[i+A[i]+1]-=1
A[0]=A_temp[0]
for j in range(1,N):
A_temp[j]+=A_temp[j-1]
A[j]=A_temp[j]
for ai in A:
if ai != N:
break
else:
break
print(' '.join([str(a) for a in A]))
if __name__ == "__main__":
main()
|
from os.path import split
def main():
X, Y, Z = map(int, input().split())
print(Z, X, Y)
if __name__ == '__main__':
main()
| 0 | null | 26,885,457,372,448 | 132 | 178 |
# C - Replacing Integer
n,k = map(int,input().split())
m = n % k
l = map(abs,[m-k,m,m+k])
print(min(l))
|
K = int(input())
s = 7
flg = False
cnt = 0
for i in range(K+1):
cnt += 1
if s % K == 0:
flg = True
break
s *= 10
s %= K
s += 7
if flg:
print(cnt)
else:
print(-1)
| 0 | null | 22,751,307,023,236 | 180 | 97 |
n,k = map(int,input().split())
class Combination(): # nCr mod MOD など
"""
O(n+log(mod))の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
C = Combination(10**6)
print(C.combi_mod(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7): # O(n+log(mod))
self.mod = mod
self.fac, self.facinv = self.prepare(n_max)
#self.modinv = self.make_modinv_list(n_max) ##なくても問題ないので、必要な時のみ使う
def prepare(self,n): # O(n+log(mod))
# 前処理(コンストラクタで自動的に実行)
# 1! ~ n! の計算
factorials = [1] # 0!の分
for m in range(1, n+1):
factorials.append(factorials[m-1]*m%self.mod)
# n!^-1 ~ 1!^-1 の計算
invs = [1] * (n+1)
invs[n] = pow(factorials[n], self.mod-2, self.mod)
for m in range(n, 1, -1):
invs[m-1] = invs[m]*m%self.mod
return factorials, invs # list
def make_modinv_list(self, n): # O(n)
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
# 整数aのMを法とした時の逆元a^-1は、(0<=a<=M-1)
# a == qM+rであるとき(qは商,rは余り)、
# a^-1 == -qr^-1 % M で与えられる。
modinv[i] = (self.mod - self.mod//i)*modinv[self.mod%i] % self.mod
return modinv
def perm_mod(self,n,r): # nPr % self.mod
if n < r:
return 0
if (n < 0 or r < 0):
return 0
return (self.fac[n] * self.facinv[n-r]) % self.mod
def combi_mod(self,n,r): # nCr % self.mod
if n < r:
return 0
if (n < 0 or r < 0):
return 0
return (((self.fac[n] * self.facinv[r]) % self.mod) * self.facinv[n-r]) % self.mod
def repeated_permutation(self,n,deno): # 重複順列
# n!/(deno[0]!*deno[1]!*...*deno[len(deno)-1]) % MOD
## n:int(分子),deno:分母のlist
if n < max(deno):
return 0
if (n < 0 or min(deno) < 0):
return 0
D = 1
for i in range(len(deno)):
D = D*self.facinv[deno[i]] % self.mod
return self.fac*D % self.mod # int ## == n!/(deno[0]!*deno[1]!*...*deno[len(deno)-1]) % MOD
def H(self,n,r): # 重複組合せ nHr % self.mod
now_n = len(self.fac)
if now_n < n+r-1: # もしself.facの長さが足りなかったら追加
for i in range(now_n+1, n+r-1+1):
self.fac.append(self.fac[i-1]*i%self.mod)
return self.combi_mod(n+r-1,r)
mod = 10**9+7
C = Combination(n,mod)
ans = 0
for i in range(min(k+1,n+1)):
ans += C.combi_mod(n,i)*C.H(n-i,i)
ans %= mod
print(ans)
|
def nCr_frL(n,r,mod):
ret=[1,n%mod]
for i in range(2,r+1):
inv=pow(i,mod-2,mod)
ret.append((ret[-1]*(n-i+1)*inv)%mod)
return ret
N,K=map(int,input().split())
MOD=10**9+7
com1=nCr_frL(N,N,MOD) # nCi
com2=nCr_frL(N-1,N-1,MOD) # n-1Ci
if K>N-1:
K=N-1
ans=0
for m in range(K+1):
ans+=(com1[m]*com2[N-m-1])%MOD
print(ans%MOD)
| 1 | 67,377,768,990,788 | null | 215 | 215 |
N = int(input())
ans = 0
for n in range(1, N+1):
if n % 3 == 0 and n % 5 == 0:
pass
elif n % 3 == 0:
pass
elif n % 5 == 0:
pass
else:
ans += n % (10**9+7)
print(ans)
|
print(sum([i for i in range(int(input()) + 1) if (i % 3 != 0 and i % 5 != 0)]))
| 1 | 34,877,026,193,568 | null | 173 | 173 |
def gcd(a,b):
x = max(a,b)
y = min(a,b)
while True:
n = x%y
if n == 0:
print(y)
break
else:
x = y
y = n
a,b = map(int,input().split())
gcd(a,b)
|
n,r=map(int,input().split())
def rate(n,r):
if n>=10:
return r
else:
return r+100*(10-n)
print(rate(n,r))
| 0 | null | 31,696,345,758,612 | 11 | 211 |
dice = list(map(int, input().split()))
cmd = input()
for i in range(len(cmd)):
if cmd[i] == 'N':
dice[0], dice[1] = dice[1], dice[0]
dice[1], dice[5] = dice[5], dice[1]
dice[5], dice[4] = dice[4], dice[5]
elif cmd[i] == 'E':
dice[0], dice[3] = dice[3], dice[0]
dice[3], dice[5] = dice[5], dice[3]
dice[5], dice[2] = dice[2], dice[5]
elif cmd[i] == 'W':
dice[0], dice[2] = dice[2], dice[0]
dice[2], dice[5] = dice[5], dice[2]
dice[5], dice[3] = dice[3], dice[5]
else:
dice[0], dice[4] = dice[4], dice[0]
dice[4], dice[5] = dice[5], dice[4]
dice[5], dice[1] = dice[1], dice[5]
print(dice[0])
|
class Dice:
def __init__(self):
self.top = 1
self.front = 2
self.left = 4
@property
def bottom(self):
return 7 - self.top
@property
def back(self):
return 7 - self.front
@property
def right(self):
return 7 - self.left
def move(self, direction):
if direction == 'N':
bottom = self.bottom
self.top = self.front
self.front = bottom
elif direction == 'W':
right = self.right
self.left = self.top
self.top = right
elif direction == 'E':
bottom = self.bottom
self.top = self.left
self.left = bottom
elif direction == 'S':
back = self.back
self.front = self.top
self.top = back
def __repr__(self):
print(self.__dict__)
dice = Dice()
numbers = input().split()
for cmd in input():
dice.move(cmd)
print(numbers[dice.top - 1])
| 1 | 224,872,909,450 | null | 33 | 33 |
def main():
n = input()
res = 0
for ni in n:
res = (res + int(ni)) % 9
print(('Yes', 'No')[res != 0])
if __name__ == '__main__':
main()
|
N = list(map(int, input().split()))
if sum(N) % 9: print('No')
else: print('Yes')
| 1 | 4,385,988,508,160 | null | 87 | 87 |
a,b,c,d = map(int,input().split())
t_deth=(a+d-1)//d
a_deth=(c+b-1)//b
if t_deth>=a_deth:
print('Yes')
else:
print('No')
|
import sys
from time import time
from random import randrange, random
input = lambda: sys.stdin.buffer.readline()
DEBUG_MODE = False
st = time()
def get_time():
return time() - st
L = 26
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
ans = [randrange(L) for _ in range(D)]
class BinaryIndexedTree:
def __init__(self, n):
self.n = n
self.data = [0] * (self.n+1)
def sum(self, i):
res = 0
while i > 0:
res += self.data[i]
i -= i & -i
return res
def add(self, i, x):
if i <= 0: raise IndexError
while i <= self.n:
self.data[i] += x
i += i & -i
def lower_bound(self, x):
if x <= 0: return 0
cur, s, k = 0, 0, 1 << (self.n.bit_length()-1)
while k:
nxt = cur + k
if nxt <= self.n and s + self.data[nxt] < x:
s += self.data[nxt]
cur = nxt
k >>= 1
return cur + 1
def rsum(x):
return x*(x+1)//2
b = [BinaryIndexedTree(D) for _ in range(L)]
score = 0
for d, cont in enumerate(ans):
b[cont].add(d+1, 1)
score += S[d][cont]
for i in range(L):
m = b[i].sum(D)
tmp = 0
s = [0]
for j in range(1, m+1):
s.append(b[i].lower_bound(j))
s.append(D+1)
for j in range(len(s)-1):
x = s[j+1] - s[j] - 1
tmp += rsum(x)
score -= tmp*C[i]
def chg(d, p, q):
diff = 0
d += 1
o = b[p].sum(d)
d1 = b[p].lower_bound(o-1)
d2 = b[p].lower_bound(o+1)
diff += rsum(d-d1) * C[p]
diff += rsum(d2-d) * C[p]
diff -= rsum(d2-d1) * C[p]
o = b[q].sum(d)
d1 = b[q].lower_bound(o)
d2 = b[q].lower_bound(o+1)
diff += rsum(d2-d1) * C[q]
diff -= rsum(d-d1) * C[q]
diff -= rsum(d2-d) * C[q]
d -= 1
diff -= S[d][p]
diff += S[d][q]
ans[d] = q
b[p].add(d+1, -1)
b[q].add(d+1, 1)
return diff
while True:
if random() >= 0.8:
d, q = randrange(D), randrange(L)
p = ans[d]
diff = chg(d, p, q)
if diff > 0:
score += diff
else:
chg(d, q, p)
else:
d1 = randrange(D-1)
d2 = randrange(d1+1, min(d1+3, D))
p, q = ans[d1], ans[d2]
diff = chg(d1, p, q)
diff += chg(d2, q, p)
if diff > 0:
score += diff
else:
chg(d1, q, p)
chg(d2, p, q)
if DEBUG_MODE: print(score)
if get_time() >= 1.7: break
if DEBUG_MODE: print(score)
else:
for x in ans: print(x+1)
| 0 | null | 19,635,557,372,526 | 164 | 113 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.