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
|
---|---|---|---|---|---|---|
def update(i,x):
i += d-1
bit = ord(x)-97
seg[i] = 0 | (1<<bit)
while i > 0:
i = (i-1)//2
seg[i] = seg[i*2+1]|seg[i*2+2]
def find(a,b,k,l,r):
if r <= a or b <= l:
return 0
if a <= l and r <= b:
return seg[k]
c1 = find(a,b,2*k+1,l,(l+r)//2)
c2 = find(a,b,2*k+2,(l+r)//2,r)
return c1|c2
n = int(input())
s = input()
q = int(input())
d = 1
while d < n:
d *= 2
seg = [0]*(2*d-1)
for i in range(n):
update(i,s[i])
for i in range(q):
type,a,b = input().split()
if type == "1":
update(int(a)-1,b)
else:
part = find(int(a)-1,int(b),0,0,d)
print(bin(part).count("1"))
| import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
N0 = 2**(N.bit_length())
st = [0] * (N0*2)
def gindex(l, r):
L = l + N0; R = r + N0
lm = (L // (L & -L)) // 2
rm = (R // (R & -R)) // 2
while L < R:
if R <= rm:
yield R - 1
if L <= lm:
yield L - 1
L //= 2; R //= 2
while L > 0:
yield L - 1
L //= 2
def update(i,s):
x = 2 ** (ord(s) - ord('a'))
i += N0-1
st[i] = x
while i > 0:
i = (i-1) // 2
st[i] = st[i*2+1] | st[i*2+2]
def query(l,r):
l += N0
r += N0
ret = 0
while l < r:
if l % 2:
ret |= st[l-1]
l += 1
if r % 2:
r -= 1
ret |= st[r-1]
l //= 2 ; r //= 2
return ret
for i,s in enumerate(sys.stdin.readline().rstrip()):
update(i+1,s)
Q = NI()
for _ in range(Q):
c,a,b = sys.stdin.readline().split()
if c == '1':
update(int(a),b)
else:
ret = query(int(a),int(b)+1)
cnt = 0
b = 1
for i in range(26):
cnt += (b & ret) > 0
b <<= 1
print(cnt)
if __name__ == '__main__':
main() | 1 | 62,645,803,347,060 | null | 210 | 210 |
import sys
input = sys.stdin.readline
def main():
T = list(input().rstrip())
ans = ["D" if c == "?" else c for c in T]
print("".join(ans))
if __name__ == "__main__":
main() | x,n=map(int,input().split())
if n==0:
print(x)
exit()
p=list(map(int,input().split()))
p.sort()
t=0
while True:
if x-t in p and x+t in p:
t+=1
elif x-t in p and x+t not in p:
print(x+t)
exit()
elif x-t not in p:
print(x-t)
exit() | 0 | null | 16,351,237,054,932 | 140 | 128 |
N, R = map(int, input().split())
print("{}".format(R if N >= 10 else R + 100 * (10 - N))) | n = int(input())
Robo = []
for i in range(n):
x, l = map(int, input().split())
Robo.append([x-l, x+l])
Robo.sort(key=lambda x: x[1])
#print(Robo)
biggest_right = 2 * -10**9 - 1
counter = 0
for left, right in Robo:
if biggest_right <= left:
counter += 1
biggest_right = max(right, biggest_right)
print(counter) | 0 | null | 76,742,056,607,538 | 211 | 237 |
import math
class Point(object):
def __init__(self, x,y):
self.x = x*1.0
self.y = y*1.0
def Koch(n,p1,p2):
s=Point((2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3)
t=Point((p1.x+2*p2.x)/3,(p1.y+2*p2.y)/3)
u=Point((t.x-s.x)*math.cos(math.radians(60))-(t.y-s.y)*math.sin(math.radians(60))+s.x,(t.x-s.x)*math.sin(math.radians(60))+(t.y-s.y)*math.cos(math.radians(60))+s.y)
if n==0:
return
Koch(n-1,p1,s)
print s.x,s.y
Koch(n-1,s,u)
print u.x,u.y
Koch(n-1,u,t)
print t.x,t.y
Koch(n-1,t,p2)
n=input()
p1=Point(0,0)
p2=Point(100,0)
print p1.x,p1.y
Koch(n,p1,p2)
print p2.x,p2.y
| import math
def curve(inp):
ret = []
n = len(inp)
cos60 = math.cos(math.radians(60))
sin60 = math.sin(math.radians(60))
for i in range(n - 1):
p1x, p1y = inp[i]
p2x, p2y = inp[i+1]
diffx = (p2x - p1x) / 3
diffy = (p2y - p1y) / 3
sx, sy = p1x + diffx, p1y + diffy
ux = sx + diffx * cos60 - diffy * sin60
uy = sy + diffx * sin60 + diffy * cos60
tx, ty = p2x - diffx, p2y - diffy
ret.extend([(p1x, p1y), (sx, sy), (ux, uy), (tx, ty)])
ret.append(inp[-1])
return ret
if __name__=="__main__":
inp = [(0.0, 0.0), (100.0, 0.0)]
N = int(input())
for i in range(N):
inp = curve(inp)
for i in inp:
print(*i)
| 1 | 120,935,318,050 | null | 27 | 27 |
#!usr/bin/env python3
import sys
import copy
def main():
n = int(sys.stdin.readline())
separator = '####################'
room, floor = 10, 3;
building1 = [[0 for col in range(room)] for row in range(floor)]
building2 = copy.deepcopy(building1)
building3 = copy.deepcopy(building1)
building4 = copy.deepcopy(building1)
buildings = {1 : building1,
2 : building2,
3 : building3,
4 : building4
}
for i in range(n):
lst = [int(num) for num in sys.stdin.readline().split()]
buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3]
for idx, (key, value) in enumerate(buildings.items()):
for floor in value:
print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor))
if idx < 3:
print(separator)
if __name__ == '__main__':
main() | I=input
r=range
a=[[[0 for i in r(10)]for j in r(3)]for k in r(4)]
for i in r(int(I())):b,f,r,v=map(int,I().split());a[b-1][f-1][r-1]+=v
f=0
for i in a:
if f:print('#'*20)
else:f=1
for j in i:print('',*j) | 1 | 1,115,094,477,600 | null | 55 | 55 |
s1 = input()
s2 = input()
cnt = 0
for c1, c2 in zip(s1, s2) :
if c1 != c2 :
cnt += 1
print(cnt) | #ABC172-B
S = str(input())
T = str(input())
L = int(len(T))
for i in range(L):
if S[i] == T[i]:
L -= 1
print(L) | 1 | 10,547,110,000,800 | null | 116 | 116 |
s,t=input().split()
print(t+s,end='') | S, T = input().split()
print(T + S) | 1 | 103,527,531,840,130 | null | 248 | 248 |
n, k = map(int, input().split())
H = list(map(int, input().split()))
L = [h for h in H if h >= k]
print(len(L)) | # -*- coding: utf-8 -*-
n, k = map(int, input().split())
cnt = 0
h = list(map(int, input().split()))
for high in h:
if high >= k:
cnt += 1
print(cnt)
| 1 | 178,882,438,521,564 | null | 298 | 298 |
while True:
x,y=sorted([int(x) for x in input().split()])
if (x,y)==(0,0): break
print(x,y)
| N = int(input())
ans = 0
for i in range(1, N+1):
if i % 3 == 0:
continue
if i % 5 == 0:
continue
ans += i
print(ans)
| 0 | null | 17,576,474,411,862 | 43 | 173 |
def main():
a, b, c, d = map(int, input().split())
if a*b > 0 and c*d > 0 and a*c < 0:
print(max(a*d, b*c))
else:
print(max(a*c, b*d, 0))
if __name__ == "__main__":
main() | def LI():
return list(map(int, input().split()))
X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)
| 0 | null | 22,705,459,239,232 | 77 | 185 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
K = int(readline())
vec = list(range(1, 10))
for i in range(K):
tail = vec[i] % 10
if tail == 0:
vec.append(vec[i] * 10 + tail)
vec.append(vec[i] * 10 + tail + 1)
elif tail == 9:
vec.append(vec[i] * 10 + tail - 1)
vec.append(vec[i] * 10 + tail)
else:
vec.append(vec[i] * 10 + tail - 1)
vec.append(vec[i] * 10 + tail)
vec.append(vec[i] * 10 + tail + 1)
if len(vec) == K:
break
print(vec[K - 1])
return
if __name__ == '__main__':
main()
| a, b, c, k = map(int, input().split())
if(k <= a):
print(k)
elif(k <= a+b):
print(a)
else:
if(a <= k-a-b):
print(-1*(k-a-b-a))
elif(a > k-a-b):
print(a-(k-a-b)) | 0 | null | 30,867,626,827,600 | 181 | 148 |
A,B,C,D= map(int, input().split())
while (True):
C = C - B
if ( C <= 0 ):
result = "Yes"
break
A = A - D
if ( A <= 0 ) :
result = "No"
break
print ( result )
| res_list = [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]
n = int(input())
for i in range(n):
io_rec = list(map(int, input().split(" ")))
bld_num = io_rec[0] - 1
floor_num = io_rec[1] - 1
room_num = io_rec[2] - 1
io_headcnt = io_rec[3]
res_list[bld_num][floor_num][room_num] += io_headcnt
for i in range(4):
if i:
print("#" * 20)
bld = res_list[i]
for j in bld:
floor_str = map(str, j)
print(" " + " ".join(floor_str)) | 0 | null | 15,554,179,056,780 | 164 | 55 |
import math
n=int(input())
ans=0
num=int(math.sqrt(n)+1)
for i in range(1,num)[::-1]:
if n%i==0:
ans=i+(n//i)-2
break
print(ans) | import math
N = int(input())
start_digit = math.ceil(math.sqrt(N))
for i in range(start_digit, 0, -1):
q, r = divmod(N, i)
if r == 0:
output = i+q-2
break
print(output) | 1 | 161,842,969,940,158 | null | 288 | 288 |
N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l=-1
r=10**12+10
while l+1<r:
mid=(l+r)//2
s=0
for i in range(N):
s+=max(0, A[i]-mid//F[i])
if s<=K:
r=mid
else:
l=mid
print(r)
| a,b,c,k=[int(x) for x in input().split()]
ans=0
if a<=k:
ans+=a
k-=a
elif k>0:
ans+=k
k=0
if b<=k:
k-=b
elif k>0:
k=0
if k>0:
ans-=k
print(ans) | 0 | null | 93,225,271,905,920 | 290 | 148 |
a,b = map(int, raw_input().split())
A = [map(int, raw_input().split()) for _ in xrange(a)]
B = [input() for _ in xrange(b)]
C = [sum([A[i][j] * B[j] for j in xrange(b)]) for i in xrange(a)]
for x in C:
print x | import sys
(row, column) = sys.stdin.readline().rstrip('\r\n').split(' ')
row = int(row)
column = int(column)
a = []
b = []
c = []
for ii in range(row):
a.append([int(x) for x in input().rstrip('\r\n').split(' ')])
for ii in range(column):
b.append(int(input().rstrip('\r\n')))
for ii in range(len(a)):
work = 0
for jj in range(len(a[ii])):
work += a[ii][jj] * b[jj]
c.append(work)
for cc in c:
print(cc)
| 1 | 1,147,366,362,002 | null | 56 | 56 |
Row = int(input())
List = []
for i in range (Row):
List.append(input())
s_l = set(List)
print(len(s_l)) | def readinput():
n=int(input())
sList=[]
for _ in range(n):
sList.append(input())
return n,sList
def main(n,sList):
keihin={}
for s in sList:
if s in keihin:
keihin[s]+=1
else:
keihin[s]=1
return len(keihin)
if __name__=='__main__':
n,sList=readinput()
ans=main(n,sList)
print(ans)
| 1 | 30,386,219,087,590 | null | 165 | 165 |
N, A, B = [int(x) for x in input().split()]
if (B-A) % 2 == 0:
print((B-A) // 2)
else:
print(min(A-1, N-B) + 1 + (B - A - 1) // 2)
| n, a, b = map(int,input().split())
if a % 2 == b % 2:
print((b-a)//2)
else:
ans = min(n-b, a-1) + 1 + (b-a-1)//2
print(ans) | 1 | 109,479,960,628,782 | null | 253 | 253 |
import sys
import numpy as np
input = sys.stdin.readline
def main():
H, W, K = map(int, input().split())
s = np.zeros(shape=(H, W), dtype=np.bool)
for i in range(H):
s[i] = tuple(map(lambda x: True if x == "#" else False, input().rstrip()))
ans = np.zeros(shape=(H, W), dtype=np.int64)
h_keep = 0
k = 1
for h in range(H):
if s[h].sum() > 0:
indices = np.where(s[h])[0]
ans[h_keep:h + 1] = k
k += 1
for idx in reversed(indices[:-1]):
ans[h_keep:h + 1, :idx + 1] = k
k += 1
h_keep = h + 1
else:
h_keep = min(h_keep, h)
if h_keep < H:
h_base = h_keep - 1
for h in range(h_keep, H):
ans[h] = ans[h_base]
for h in range(H):
print(" ".join(map(str, ans[h])))
if __name__ == "__main__":
main()
| n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i] and l[k]-l[j]<l[i]:
cnt +=1
print(cnt) | 0 | null | 74,286,317,179,066 | 277 | 91 |
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) | N = int(input())
S = int(N**(1/2))
for i in range(S,0,-1):
if N%i == 0:
A = N//i
B = i
break
print(A+B-2) | 1 | 160,963,455,572,150 | null | 288 | 288 |
import numpy as np
def main(A, B, V, W, T):
if abs(B-A) <= T*(V-W):
return "YES"
return "NO"
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
print(main(A, B, V, W, T))
| a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a < b:
print('YES' if b+w*t <= a+v*t else 'NO')
else:
print('YES' if b-w*t >= a-v*t else 'NO')
| 1 | 15,045,434,614,756 | null | 131 | 131 |
n, m, l = map(int, input().split())
a = []
b = []
for i in range(n):
a.append(list(map(int, input().split())))
for k in range(m):
b.append(list(map(int, input().split())))
for i in range(n):
for s in range(l):
c = 0
for k in range(m):
c = c + a[i][k] * b[k][s]
if (s == l-1):
print('{}'.format(c), end = '')
else:
print('{}'.format(c), end = ' ')
print()
| a = input().split()
x = []
y = []
z = []
a[0] = int(a[0])
a[1] = int(a[1])
a[2] = int(a[2])
for i in range(a[0]):
b = input().split()
x.append(b)
z.append([])
for i in range(a[1]):
b = input().split()
y.append(b)
for i in range(a[0]):
for j in range(a[2]):
z[i].append(0)
for i in range(a[0]):
for j in range(a[2]):
for k in range(a[1]):
z[i][j] += int(x[i][k])*int(y[k][j])
for i in range(len(z)):
for j in range(a[2]):
z[i][j] = str(z[i][j])
for i in z:
gam = " ".join(i)
print(gam)
| 1 | 1,435,689,069,180 | null | 60 | 60 |
x=input().split()
a,b,c=int(x[0]),int(x[1]),int(x[2])
if a<b<c:
print("Yes")
else:
print("No")
| a, b, c = tuple([int(x) for x in input().split()])
if a < b and b < c:
print("Yes")
else:
print("No") | 1 | 375,284,352,700 | null | 39 | 39 |
#!/usr/bin/env python3
print(int(input())**3 / 27)
| L = int(input())
x = L/3
y = L/3
z = L/3
V = x * y * z
print(V) | 1 | 47,025,821,748,180 | null | 191 | 191 |
def main():
N, X, Y = map(int, input().split())
count_list = [0] * N
for i in range(1, N):
for j in range(i + 1, N + 1):
distance = min(j-i, abs(j-Y) + abs(i-X) + 1)
count_list[distance] += 1
for i in range(1, N):
print(count_list[i])
if __name__ == '__main__':
main() | import math
import numpy as np
N = int(input())
tb = [[0]*10]*10
tb = np.array(tb)
for i in range(1,N+1):
s = str(i)
tb[int(s[0])][int(s[-1])] =tb[int(s[0])][int(s[-1])] +1
point =0
for i in range(0,10):
for j in range(0,10):
point += tb[i][j] * tb[j][i]
print(point) | 0 | null | 65,267,848,902,432 | 187 | 234 |
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
for i in range(m):
x,y,c=map(int,input().split())
l.append(a[x-1]+b[y-1]-c)
l.append(min(a)+min(b))
print(min(l)) | a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# cheapest price without using discount ticket
min_price = min(a) + min(b)
for i in range(m):
arr = list(map(int, input().split()))
discounted_price = a[arr[0] - 1] + b[arr[1] - 1] - arr[2]
min_price = min(min_price, discounted_price)
print(min_price) | 1 | 53,921,799,474,098 | null | 200 | 200 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
X, Y, Z = lr()
print(Z, X, Y)
| A, B, C = map(int, input().split())
print(C, A, B) | 1 | 38,040,767,509,930 | null | 178 | 178 |
K = int(input())
def gcd(a,b):
if a % b == 0:
return b
return gcd(b, a%b)
dec = {}
for a in range(1,K+1):
for b in range(1, K+1):
if gcd(a,b) not in dec:
dec[gcd(a,b)] = 1
else:
dec[gcd(a,b)] += 1
ans = 0
for c in range(1, K+1):
for key in dec.keys():
ans += gcd(c, key)*dec[key]
print(ans)
| import collections
def U1(a,b):
if b > a:
b, a = a, b
while a%b != 0:
r = a%b
a = b
b = r
return b
K = int(input())
c = 0
arr = []
for i in range(1,K+1):
for j in range(1,K+1):
arr.append(U1(i,j))
arr=collections.Counter(arr)
for key,value in arr.items():
for k in range(1,K+1):
c += U1(k,key)*value
print(c) | 1 | 35,449,209,408,042 | null | 174 | 174 |
S = input()
K = int(input())
if len(set(S)) == 1:
print(len(S)*K//2)
else:
i, count1 = 1, 0
while i < len(S):
if S[i] == S[i-1]:
count1 += 1
i += 2
else:
i += 1
ss = S*2
i, count2 = 1, 0
while i < len(ss):
if ss[i] == ss[i-1]:
count2 += 1
i += 2
else:
i += 1
print(count1+(count2-count1)*(K-1))
| from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i]//2 for i in range(n)]
lcm_a = 1
for i in range(n):
lcm_a = (lcm_a * b[i]) // gcd(lcm_a, b[i])
for i in range(n):
if (lcm_a//b[i]) % 2 == 0:
print(0)
exit()
if m < lcm_a:
print(0)
else:
m -= lcm_a
print(1 + m // (lcm_a*2)) | 0 | null | 139,046,068,364,152 | 296 | 247 |
n,nWorks,nSp = map(int,input().split())
s = input()
leftList = [0]*n
rightList = [0]*n
num = 0
count = 0
while num < n:
if s[num] == "o":
leftList[num] = 1
count +=1
num += 1 + nSp
else:
num +=1
if count > nWorks:
exit()
num = n-1
count = 0
while num >= 0:
if s[num] == "o":
rightList[num] = 1
count +=1
num -= (1 + nSp)
else:
num -=1
for kk in range(n):
if leftList[kk] and rightList[kk]:
print(kk+1) | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, K, C, S):
def f(S):
r = 0
w = []
c = 0
for s in S:
if r == 0 and s == 'o':
w.append(1)
r = C
c += 1
else:
w.append(0)
r = max(0, r-1)
return w
lw = f(S)
rw = list(reversed(f(reversed(S))))
if sum(lw) != K:
return
for i, (l, r) in enumerate(zip(lw, rw)):
if l == r == 1:
print(i+1)
def main():
N, K, C = read_int_n()
S = read_str()
(slv(N, K, C, S))
if __name__ == '__main__':
main()
| 1 | 40,809,357,619,004 | null | 182 | 182 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
''' ?????¢??¢?´¢ '''
# n??????????´??????????????????????q????????¢?´¢????????£?????´???
# ?¨??????????O(qn)
def linear_search(S, T):
count = 0
for t in T:
if t in S:
count += 1
return count
if __name__ == '__main__':
NS = int(input())
S = list(map(int, input().split()))
NT = int(input())
T = list(map(int, input().split()))
print(linear_search(S, T)) | n, d = map(int, input().split())
d_t = d**2
r = 0
for i in range(n):
a, b = map(int, input().split())
if d_t >= a**2 + b**2:
r += 1
print(r) | 0 | null | 2,997,720,326,638 | 22 | 96 |
b=int(input())
a=list(map(int,input().split()))
ans=""
total=0
for i in a:
total^=i
for i in a:
ans+=str(total^i)+" "
print(ans) | import sys
import math
N = int(input())
A = map(int, input().split())
s = [0] * N
for a in A:
s[a-1] += 1
for i in range(N):
print(s[i])
| 0 | null | 22,324,905,450,610 | 123 | 169 |
import math
r = float(input())
#r = (float(x) for x in input().split())
d = r * r * math.pi
R = 2 * r * math.pi
print ("{0:.6f} {1:.6f}".format(d,R))
| from math import pi
r = float(input())
print("{:.6f} {:.6f}".format(pi * r ** 2, 2 * pi * r))
| 1 | 653,331,425,828 | null | 46 | 46 |
MOD = 1000000007
n, k = map(int, input().split())
rsw = [0]*(n+2)
for i in range(1,n+2):
rsw[i] = (rsw[i-1]+i-1)%MOD
rsw_e = [0]*(n+2)
for i in range(1,n+2):
rsw_e[i] = (rsw_e[i-1]+n-(i-1))%MOD
res = 0
for i in range(k,n+2):
start = rsw[i]
end = rsw_e[i]
res += (end-start+1)%MOD
print(res%MOD) | N, K = map(int, input().split())
A = [0]*(N+2)
for i in range(N+1):
A[i+1] += A[i] + i
ans = 0
for i in range(K, N+2):
minv = A[i]
maxv = A[N+1]-A[N-i+1]
ans += maxv-minv+1
ans %= 10**9+7
print(ans)
| 1 | 33,145,472,706,540 | null | 170 | 170 |
W=input()
count=0
while True:
text=input()
if text == 'END_OF_TEXT':
break
else:
ls = list(map(str, text.split()))
for s in ls:
if s.lower() == W.lower():
count += 1
print(count) | W, c = input(), 0
for line in iter(input, 'END_OF_TEXT'):
for Ti in line.lower().split():
if W == Ti:
c +=1
print(c) | 1 | 1,837,110,500,228 | null | 65 | 65 |
import itertools
def main():
N = int(input())
n_x_y = {}
for n in range(N):
A = int(input())
x_y = {}
for _ in range(A):
x, y = map(int, input().split())
x_y[x-1] = y
n_x_y[n] = x_y
ans = 0
for flags in itertools.product([1, 0], repeat=N):
sat = True
for n, flag in enumerate(flags):
if flag == 0:
continue
for x, y in n_x_y[n].items():
if (y == 1 and flags[x] == 0) or (y == 0 and flags[x] == 1):
sat = False
break
if sat is False:
break
if sat is True and sum(flags) > ans:
ans = sum(flags)
print(ans)
if __name__ == '__main__':
main()
| n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for j in range(m)]
ans = []
for a in A:
multi_list = [x * y for (x, y) in zip(a, b)] # 書き方:リストの要素同士の積
arg = 0
for k in multi_list:
arg += k
print(arg)
| 0 | null | 61,098,646,127,860 | 262 | 56 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
def main():
N = in_n()
D = in_nl()
mod = 998244353
if D[0] != 0:
print(0)
exit()
for i in range(1, N):
if D[i] == 0:
print(0)
exit()
count = [0] * N
for i in range(N):
count[D[i]] += 1
zero = N + 1
non_zero = -1
for i in range(N):
if count[i] == 0:
zero = min(zero, i)
else:
non_zero = max(non_zero, i)
if zero < non_zero:
print(0)
exit()
ans = 1
for i in range(1, N):
if count[i] == 0:
break
else:
ans *= count[i - 1] ** count[i]
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| A, B, M = map(int, input().split())
lis_a = list(map(int, input().split()))
lis_b = list(map(int, input().split()))
lis_price = []
lis_price.append(min(lis_a) + min(lis_b))
for i in range(M):
x, y, c = map(int,input().split())
lis_price.append(lis_a[x-1] + lis_b[y-1] - c)
print(min(lis_price))
| 0 | null | 104,013,703,392,548 | 284 | 200 |
n,k = map(int,input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
ans = 0
#con = cmb(n,k,mod)
#print(con)
for i in range(min(k+1,n+1)):
ans += cmb(n,i,mod)*cmb(n-1,i,mod)
ans %= mod
print(ans) | while True:
n, x = map(int, raw_input().split())
if n == x == 0:
break;
cnt = 0
for i in range(1, n):
for j in range(i + 1, n):
tmp = x - i - j
if tmp > j and tmp <= n:
cnt += 1
print cnt | 0 | null | 34,145,570,526,342 | 215 | 58 |
A, B = map(int, input().split())
print('0') if A <= 2*B else print(A - 2*B)
| A, B = map(int, input().split())
print(max([0, A-2*B])) | 1 | 167,038,733,046,192 | null | 291 | 291 |
xyz = input().split()
print(xyz[2]+ " " + xyz[0] + " " + xyz[1]) | a,b=[int(x) for x in input().split()]
if a < b :
print('a < b')
elif a > b :
print('a > b')
else:
print('a == b')
| 0 | null | 19,207,886,018,650 | 178 | 38 |
W, H, x, y, r = [int(i) for i in input().split()]
if r <= y <= H - r and r <= x <= W - r:
print('Yes')
else:
print('No') | h, a = map(int, input().split())
if h % a > 0:
number_of_times = h // a + 1
print(number_of_times)
else:
print(h // a) | 0 | null | 38,547,309,387,090 | 41 | 225 |
N, K, C = map(int, input().split())
S = input()
length = len(S)
INF = float('inf')
Ls = [-INF]
n = 0
for i, c in enumerate(S):
if c == 'o' and i - Ls[-1] > C:
Ls.append(i)
n += 1
if n >= K: break
Rs = [INF]
n = 0
for i, c in enumerate(reversed(S)):
if c == 'o' and Rs[-1] - (length-1-i) > C:
Rs.append(length-1-i)
n += 1
if n >= K: break
Rs.reverse()
for l, r in zip(Ls[1:], Rs[:-1]):
if l == r:
print(l+1)
| c, d = map(int, input().split())
if c < 10: print(d + 100 * (10-c))
else: print(d) | 0 | null | 52,223,993,570,432 | 182 | 211 |
N, M, X = map(int,input().split())
C = []
A = []
for i in range(N):
ca = list(map(int,input().split()))
C.append(ca[0])
A.append(ca[1:])
INF = 10**18
ans = INF
for mask in range(1<<N):
skill = [0 for i in range(M)]
cost = 0
for i in range(N):
if mask&(1<<i):
cost += C[i]
for j in range(M):
skill[j] += A[i][j]
if min(skill) >= X:
ans = min(ans,cost)
print(-1 if ans==INF else ans) | N = int(input())
lists= []
for i in range(N):
a,b = [x for x in input().split()]
lists.append([a,int(b)])
X = input()
add_time = False
add = 0
for i in range(N):
if add_time == True:
add += lists[i][1]
if X == lists[i][0]:
add_time = True
print(add) | 0 | null | 59,234,674,615,962 | 149 | 243 |
n = int(input())
list_ = [0]*n
joshi_list = list(map(int, input().split()))[::-1]
for i,num in enumerate(joshi_list):
list_[num-1]+=1
for num in list_:
print(num) | import itertools
n = int(input())
l = list(map(int, input().split()))
c = list(itertools.combinations(l, 3))
ans = 0
for i in c:
j = sorted(i)
if j[0] != j[1] != j[2] != j[0]:
if j[2] < j[0]+j[1]:
ans += 1
print(ans)
| 0 | null | 18,879,281,832,950 | 169 | 91 |
inputted = input().split()
S = inputted[0]
T = inputted[1]
answer = T + S
print(answer)
| l = input().split()
ans = l[1] + l[0]
print(ans) | 1 | 103,207,176,071,040 | null | 248 | 248 |
n, m = map(int, raw_input().split())
a, b, result = list(), list(), list()
for _ in range(n):
a.append(map(int, raw_input().split()))
for _ in range(m):
b.append(int(raw_input()))
for i in range(n):
temp = 0
for j in range(m):
temp += a[i][j] * b[j]
result.append(temp)
for i in result:
print(i) | n, m = [int(i) for i in input().split()]
vec = []
for i in range(n):
vec.append([int(j) for j in input().split()])
c = []
for i in range(m):
c.append(int(input()))
for i in range(n):
sum = 0
for j in range(m):
sum += vec[i][j]*c[j]
print(sum) | 1 | 1,166,758,677,800 | null | 56 | 56 |
s, t = input().split()
print('{}{}'.format(t, s))
| import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
s, t = input().split()
print(t, end="")
print(s)
main()
| 1 | 103,148,856,453,092 | null | 248 | 248 |
while True:
a, b, c = map(int, input().split())
if a == -1 and b == -1 and c == -1:
break
if a == -1 or b == -1 or a + b < 30:
print("F")
elif a + b >= 80:
print("A")
elif a + b >= 65:
print("B")
elif a + b >= 50 or c >= 50:
print("C")
else:
print("D")
| while True:
m,f,r=map(int,raw_input().split())
if m==f==r==-1: break
if m+f<30 or m==-1 or f==-1: print 'F'
elif m+f>=80: print 'A'
elif 65<=m+f: print 'B'
elif 50<=m+f: print 'C'
elif r>=50: print 'C'
else: print 'D' | 1 | 1,220,575,949,728 | null | 57 | 57 |
import sys
import numpy as np
from collections import Counter
# 全探索なら、 2**6 * 2**6 (4000)
# > 4000 * (6**2)
# bit全探索でOK
# ------------------------------------------
h, w, num = map(int, input().split())
data = []
for _ in range(h):
# 一文字ずつListへ格納
temp = list(input())
data.append(temp)
#data = [input() for _ in range(h)]
# print(data)
'''
count = Counter(data)
most = count.most_common()
print(most)
'''
ans = 0
# 縦の全Loop
for i in range(2 ** h):
for j in range(2 ** w):
#print(i, j)
*temp, = data
temp = np.array(temp)
for k in range(h):
if (i >> k & 1):
temp[k, :] = 'aa'
for l in range(w):
if (j >> l & 1):
temp[:, l] = 'aa'
count = np.where(temp == '#')[0]
#print(count, len(count))
if (len(count) == num):
# print('add')
ans += 1
else:
pass
print(ans)
| h, w, k = map(int, input().split())
c = []
for _ in range(h):
c.append([c for c in input()])
ans = 0
for i in range(1 << h):
for j in range(1 << w):
cnt = 0
for n in range(h):
for m in range(w):
if i >> n & 1:
continue
if j >> m & 1:
continue
if c[n][m] == '#':
cnt += 1
if cnt == k:
ans += 1
print(ans) | 1 | 9,033,352,220,640 | null | 110 | 110 |
i = 1
a = input()
while a != 0:
print "Case %d: %d" % (i, a)
i = i + 1
a = input() | import sys
s = sys.stdin
cnt = 1
for i in s:
if int(i)== 0:
break
print("Case {0}: {1}".format(cnt,i),end="")
cnt += 1 | 1 | 474,942,432,230 | null | 42 | 42 |
N = int(input())
testimony = [[-1]*N for i in range(N)]
count = 0
for i in range(N):
A = int(input())
for j in range(A):
x,y = map(int,input().split())
testimony[i][x-1]=y
for i in range(2**N):
honest = [0]*N
for j in range(N):
if(i>>j)&1:
honest[j]=1
flag=True
for j in range(N):
if honest[j]==1:
for k in range(N):
if testimony[j][k]==-1:
continue
if testimony[j][k]!=honest[k]:
flag=False
if flag==True:
count=max(count,honest.count(1))
print(count) | N = int(input())
A = ''.join(list(map(lambda x: format(int(x), '060b'), input().split(' '))))
mod = 10 ** 9 + 7
ans = 0
for n in range(60):
one = A[59-n::60].count('1')
ans = (ans + 2**n *one*(N-one))%mod
print(ans) | 0 | null | 122,284,293,686,818 | 262 | 263 |
a, b, c, k = map(int, input().split())
if k <= a:
print(k)
if a < k <= a+b:
print(a)
if a+b < k <= a+b+c:
print(a+(-1)*(k-a-b))
| h, w = map(int, input().split())
g = [[0] * w for _ in range(h)]#白が1、黒が0
for i in range(h):
s = list(input())
for j in range(w):
if s[j] == '.':
g[i][j] = 1
INF = 10**9
dp = [[INF] * w for _ in range(h)]
if g[0][0] == 0:
dp[0][0] = 1
else:
dp[0][0] = 0
for i in range(h):
for j in range(w):
for dx, dy in ((1, 0), (0, 1)):
nx = j + dx
ny = i + dy
if ny >= h or nx >= w:
continue
add = 0
if g[ny][nx] == 0 and g[i][j] == 1:
add = 1
dp[ny][nx] = min(dp[ny][nx], dp[i][j] + add)
print(dp[h-1][w-1])
| 0 | null | 35,451,765,009,540 | 148 | 194 |
N = int(input())
total = 0
for n in range(1, N+1):
if (n % 3 > 0) and (n % 5 > 0):
# print(n)
total += n
print(total) | # coding: UTF-8
n = input()
for n in range(n):
inputs = map(int,raw_input().split())
if inputs[0]**2 == inputs[1]**2 + inputs[2]**2 or\
inputs[1]**2 == inputs[0]**2 + inputs[2]**2 or\
inputs[2]**2 == inputs[0]**2 + inputs[1]**2:
print "YES"
else:
print "NO" | 0 | null | 17,305,848,450,352 | 173 | 4 |
n = int(input())
tp = 0
hp = 0
for i in range(n):
tarou, hanako = map(str,input().split())
if(tarou > hanako):
tp += 3
elif(tarou < hanako):
hp += 3
else:
tp += 1
hp += 1
print("%d %d" %(tp,hp))
| #coding: UTF-8
l = raw_input()
a = int(l)
x = 1
while a != 0:
print "Case %d: %d" %(x,a)
x += 1
l = raw_input()
a = int(l)
if l == 0:
print "end" | 0 | null | 1,224,294,182,330 | 67 | 42 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
a = [int(i) for i in input().split()]
mark = 1
remain = 0
for i in range(n):
if a[i] == mark:
remain += 1
mark += 1
if remain == 0:
print(-1)
else:
print(n-remain)
if __name__ == '__main__':
main() | N = int(input())
A = tuple(map(int, input().split()))
x = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
x[a].append(i)
maxcount = 0
todo = [(1, i) for i in x[1]]
while todo:
a, i = todo.pop()
maxcount = max(maxcount, a)
if a == N:
continue
na = a + 1
for ni in x[na]:
if ni < i:
continue
todo.append((na, ni))
if maxcount > 0:
print(N - maxcount)
else:
print(-1) | 1 | 115,306,749,078,602 | null | 257 | 257 |
n = int(input())
d = list(map(int, input().split()))
m = 1
num = 0
for s in range(0,n-1):
for t in range(m,n):
num += (d[s]*d[t])
m += 1
print(num) | N = int(input())
d_s = list(map(int, input().split()))
answer = 0
for i in range(N-1):
for j in range(i+1, N):
answer += d_s[i] * d_s[j]
print(answer) | 1 | 167,934,682,183,698 | null | 292 | 292 |
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
N,M=map(int,input().split())
ans = 0
if N >= 2:
ans += len(list(itertools.combinations(range(N), 2)))
if M >= 2:
ans += len(list(itertools.combinations(range(M), 2)))
print(ans)
| n,m=map(int,input().split())
a=n*(n-1)//2
b=m*(m-1)//2
print(a+b)
| 1 | 45,824,710,972,740 | null | 189 | 189 |
n=int(input())
if n<3:
print(0)
else:
L=[int(i) for i in input().split()]
x=0
for i in range(0,n-2):
for j in range(i+1,n-1):
for k in range(j+1,n):
if L[i]==L[j] or L[j]==L[k] or L[k]==L[i]:
pass
elif L[i]+L[j]>L[k] and L[i]+L[k]>L[j] and L[j]+L[k]>L[i]:
x+=1
else:
pass
print(x) | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=2019
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def main():
N,P=map(int,input().split())
A=list(map(int,list(input())[::-1]))
ans=0
if P==2 or P==5:
if P==2:
s=set([i*2 for i in range(5)])
else:
s=set([i*5 for i in range(2)])
for i,x in enumerate(A[::-1],1):
if x in s:
ans+=i
else:
S=[0]*(N+1)
for i in range(N):
S[i+1]=(S[i]+A[i]*pow(10,i,P))%P
l=[0]*P
for i in range(N+1):
ans+=l[S[i]]
l[S[i]]+=1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 31,386,680,619,968 | 91 | 205 |
x,y = list(input().split())
x = int(x)
y = int(y[0]+y[2]+y[3])
print(x*y//100) | a,b = input().split()
#print(a,b)
A = int(a)
x,y = b.split('.')
B = int(x)*100+int(y)
print(int(A*B)//100) | 1 | 16,539,158,359,232 | null | 135 | 135 |
a1, a2, a3 = map(int, input().split(" "))
tmp = a1 + a2 + a3
if tmp >= 22:
print("bust")
else:
print("win") | a=input()
if '7' in a:
print('Yes')
else:
print('No')
| 0 | null | 76,561,384,197,548 | 260 | 172 |
from collections import deque
N = int(input())
A = deque(list(map(int, input().split())))
ans = 0
cnt = 1
while A:
a = A.popleft()
if cnt == a:
cnt += 1
continue
else:
ans += 1
if ans == N:
print(-1)
else:
print(ans) | n = int(input())
a = list(map(int, input().split()))
t = 1
ans = 0
for i in range(n):
if t != a[i]:
ans += 1
a[i] = -1
else:
t += 1
if all([i == -1 for i in a]):
print(-1)
else:
print(ans) | 1 | 114,783,888,801,572 | null | 257 | 257 |
hp, dmg = map(int, input().split())
if hp % dmg == 0: print(int(hp//dmg))
else: print(int(hp//dmg) + 1) | n = int(input())
S = input()
rs = [s=="R" for s in S]
gs = [s=="G" for s in S]
bs = [s=="B" for s in S]
ind_r = [i for i,s in enumerate(rs) if s == 1]
ind_g = [i for i,s in enumerate(gs) if s == 1]
ind_b = [i for i,s in enumerate(bs) if s == 1]
ans = 0
ng = sum(gs)
for i in ind_r:
for j in ind_b:
# print(i,j)
kM = max(i,j) + abs(i-j)
km = min(i,j) - abs(i-j)
ans += ng
if (max(i,j) - min(i,j))%2==0:
# print("aaa",(max(i,j)+min(i,j))//2)
ans -= gs[(max(i,j)+min(i,j))//2]
if kM < n:
ans -= gs[kM]
if 0 <= km:
ans -= gs[km]
print(ans) | 0 | null | 56,540,880,898,564 | 225 | 175 |
import itertools
N = int(input())
dots = [tuple(map(int, input().split())) for _ in range(N)]
total_distance = 0
total_count = 0
for route in itertools.permutations(dots):
for i in range(len(route)-1):
x1, y1 = route[i]
x2, y2 = route[i+1]
total_distance += ((x2 - x1)**2 + (y2 - y1)**2)**0.5
total_count += 1
ans = total_distance / total_count
print(ans)
| def abc145c_average_length():
import itertools
import math
n = int(input())
x = []
y = []
for _ in range(n):
a, b = map(int, input().split())
x.append(a)
y.append(b)
result = 0
cnt = 0
for p in itertools.permutations(range(n)):
total = 0
for i in range(n-1):
total += math.sqrt(pow(x[p[i]]-x[p[i+1]], 2)+pow(y[p[i]]-y[p[i+1]], 2))
result += total
cnt += 1
print(result/cnt)
abc145c_average_length() | 1 | 148,319,230,055,358 | null | 280 | 280 |
N,M=map(int, input().split())
A=list(map(int, input().split()))
A = sorted(A, reverse=True)
s = sum(A)
th = s * 1/(4*M)
if A[M-1] < th: print('No')
else: print('Yes') | import sys
input = sys.stdin.readline
def main():
X = int(input())
for A in range(-119, 120 + 1):
for B in range(-119, 120 + 1):
if A ** 5 - B ** 5 == X:
print(A, B)
exit()
if __name__ == "__main__":
main()
| 0 | null | 31,994,480,005,752 | 179 | 156 |
if __name__ == '__main__':
k = int(input())
s = list(input())
if len(s) <= k:
print(''.join(s))
else:
print(''.join(s[:k]) + '...') | k=int(input())
s=list(input())
num_list=[]
if k<len(s):
for x in range(k):
num_list+=s[x]
x+=1
t=''.join(num_list)+'...'
else:
t=''.join(s)
print(t) | 1 | 19,578,829,696,160 | null | 143 | 143 |
# 二通りのやり方で解いてみよう。
# Aそれぞれに対してBを二分探索→M(累積和構成) + NlogM
# Aを昇順、Bを降順に動かす→O(N+M) このコードはこっち★
n, m, k = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
time_sum = sum(bb)
a_idx = 0
b_idx = m-1
ans = 0
# 最初はA無し、B全部からスタート
book_num = m
while True:
if time_sum > k:
if b_idx < 0:
break
time_sum -= bb[b_idx]
b_idx -= 1
book_num -= 1
else:
# 実行可能な読み方
ans = max(ans, book_num)
if a_idx > n-1:
break
time_sum += aa[a_idx]
a_idx += 1
book_num += 1
print(ans)
| N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
answer = 0
b_ind = 0
for x in range(N-1):
A[x+1] += A[x]
if A[x+1] > K:
A = A[:x+1]
break
for y in range(M-1):
B[y+1] += B[y]
if B[y+1] > K:
B = B[:y+1]
break
A = [0] + A
B = [0] + B
na = len(A)
nb = len(B)
if A[-1] + B[-1] <= K:
answer = len(A) + len(B) - 2
print(answer)
else:
for i in range(na):
for j in range(nb-b_ind-1, -1, -1):
if A[i] + B[j] <= K:
if answer < i+j:
answer = i+j
b_ind = nb-j-1
break
print(answer) | 1 | 10,684,877,404,640 | null | 117 | 117 |
a, b, c = map(int, raw_input().split())
n = a
count = 0
while True:
x = c % n
if x == 0:
count += 1
if n == b:
break
else:
n += 1
print count | [a,b,c]=raw_input().split()
x=int(a)
y=int(b)
z=int(c)
ans=[]
for n in range(x,y+1):
if z%n==0:
ans.append(n)
print len(ans) | 1 | 564,255,195,764 | null | 44 | 44 |
import math
N = int(input())
A = sorted(list(map(int, input().split())),reverse=True)
s = A[0]
for i in range(1,N-1):
s += A[math.ceil(i/2)]
print(s) | N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
ans = A[0] + sum(A[1:N//2])*2
if N % 2 == 1:
ans += A[N//2]
# print(A[1:N//2])
# スコアを獲得できるのはN-1回
print(ans)
| 1 | 9,187,716,688,280 | null | 111 | 111 |
A,B = map(int, input().split())
C,D = map(int, input().split())
if D == 1:
print("1")
else:
print("0") | dates = [list(map(int, input().split())) for _ in range(2)]
print("{}".format("1" if dates[0][0] < dates[1][0] or (dates[0][0] == 12 and dates[0][1] == 1) else "0")) | 1 | 124,387,214,090,720 | null | 264 | 264 |
from collections import Counter
def mpow(a,b,mod):
ret=1
while b>0:
if b&1:
ret=(ret*a)%mod
a=(a*a)%mod
b>>=1
return ret
n,p=map(int,input().split())
s=[int(i) for i in input()]
if p==2 or p==5:
ans=0
for i in range(n):
if s[i]%p==0:
ans+=i+1
print(ans)
else:
ans=0
d=Counter()
d[0]+=1
num=0
for i in range(n-1,-1,-1):
num=(num+s[i]*mpow(10,n-1-i,p))%p
ans+=d[num]
d[num]+=1
print(ans)
| import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
val = [0] * P
cur = 0
tenfactor = 1
val[cur] += 1
for i in range(N):
cur = (cur + int(S[N - i - 1]) * tenfactor) % P
tenfactor *= 10
tenfactor %= P
val[cur] += 1
ans = 0
for v in val:
ans += v * (v - 1) // 2
print(ans)
if __name__ == "__main__":
main()
| 1 | 58,351,022,688,410 | null | 205 | 205 |
N, K = [int(_) for _ in input().split()]
MOD = 10 ** 9 + 7
ans = 0
class ModFactorial:
"""
階乗, 組み合わせ, 順列の計算
"""
def __init__(self, n, MOD=10 ** 9 + 7):
"""
:param n: 最大の要素数.
:param MOD:
"""
kaijo = [0] * (n + 10)
gyaku = [0] * (n + 10)
kaijo[0] = 1
kaijo[1] = 1
for i in range(2, len(kaijo)):
kaijo[i] = (i * kaijo[i - 1]) % MOD
gyaku[0] = 1
gyaku[1] = 1
for i in range(2, len(gyaku)):
gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
self.kaijo = kaijo
self.gyaku = gyaku
self.MOD = MOD
def nCm(self, n, m):
return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD
def nPm(self, n, m):
return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD
def factorial(self, n):
return self.kaijo[n]
mf = ModFactorial(N, MOD)
for i in range(1, N + 1):
if N - i > K: continue
p = N - i
# print(i, p, mf.nCm(p + i - 1, i - 1))
ans += mf.nCm(p + i - 1, i - 1) * mf.nCm(N, i)
ans %= MOD
print(ans)
| class FastModComb:
def __init__(self, n, mod=10 ** 9 + 7):
f, self.mod = [1], mod
for i in range(1, n + 1):
f.append(f[-1] * i % mod)
rf = [self.modpow(f[-1], mod - 2)]
for i in range(1, n + 1):
rf.append(rf[-1] * (n - i + 1) % mod)
self.f, self.rf = f, list(reversed(rf))
def modpow(self, a, b):
ret = 1
while b > 0:
if b % 2 == 1:
ret = ret * a % self.mod
a = a * a % self.mod
b //= 2
return ret
def modcomb(self, n, c):
return self.f[n] * self.rf[c] * self.rf[n - c] % self.mod
n, k = map(int, input().split())
mod, mc = 10 ** 9 + 7, FastModComb(n)
print(sum([mc.modcomb(n, m) * mc.modcomb(n - 1, n - m - 1) % mod
for m in range(min(n - 1, k) + 1)]) % mod)
| 1 | 67,162,066,675,850 | null | 215 | 215 |
x=list(input())
print('Yes' if '7' in x else 'No') | N = input()
if '7' in N:
print('Yes')
else:
print('No') | 1 | 34,283,422,289,600 | null | 172 | 172 |
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
ave_a = t1 * a1 + t2 * a2
ave_b = t1 * b1 + t2 * b2
if ave_a == ave_b:
print('infinity')
exit()
half, all = t1 * (b1 - a1), ave_a - ave_b
ans = half // all * 2 + (half % all != 0)
print(max(0, ans))
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1*(A1-B1)
d2 = T2*(A2-B2)
if d1>d2:
d1 *= -1
d2 *= -1
if (d1>0 and d1+d2>0) or (d1<0 and d1+d2<0):
print(0)
elif d1+d2==0:
print("infinity")
else:
v = (abs(d1)//(d1+d2))
ans = v*2
pos = d1+v*(d1+d2)
if pos<0 and pos+d2>=0:
ans += 1
print(ans) | 1 | 131,360,550,011,262 | null | 269 | 269 |
import math
x = raw_input()
x = float(x)
S = x*x*math.pi
l = 2*x*math.pi
print("%.6f %.6f" %(S, l)) | s,t=[str(i)for i in input().split()]
print(t+s) | 0 | null | 51,990,418,492,090 | 46 | 248 |
ring = input() * 2
s = input()
if s in ring:
print('Yes')
else:
print('No') | def check(s, p):
for i in range(len(s)):
count = 0
for j in range(len(p)):
if s[(i+j) % len(s)] != p[j]:
break
count += 1
if count == len(p):
return True
return False
s = raw_input()
p = raw_input()
flag = check(s, p)
if flag:
print("Yes")
else:
print("No") | 1 | 1,729,696,435,840 | null | 64 | 64 |
import math
pi = math.pi
th = pi * 60.0 / 180.0
cos = math.cos(th)
sin = math.sin(th)
class Point():
def __init__(self):
self.x = 0.0
self.y = 0.0
def koch(n, p1, p2):
if n == 0:
return None
s = Point()
t = Point()
u = Point()
s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0
s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0
t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0
t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0
u.x = (t.x - s.x) * cos - (t.y - s.y) * sin + s.x
u.y = (t.x - s.x) * sin + (t.y - s.y) * cos + s.y
koch(n-1, p1, s)
print(s.x, s.y)
koch(n-1, s, u)
print(u.x, u.y)
koch(n-1, u, t)
print(t.x, t.y)
koch(n-1, t, p2)
def main():
p1 = Point()
p2 = Point()
n = int(input())
p2.x = 100
print(p1.x, p1.y)
koch(n, p1, p2)
print(p2.x, p2.y)
return 0
if __name__ == '__main__':
main()
| def koch(n, ax, ay, bx, by):
if n == 0:
return
th = math.pi * 60.0 / 180.0
xx = (2.0 * ax + bx)/3.0
xy = (2.0 * ay + by)/3.0
zx = (ax + 2.0 * bx)/3.0
zy = (ay + 2.0 * by)/3.0
yx = (zx - xx)*math.cos(th) - (zy - xy)*math.sin(th) + xx
yy = (zx - xx)*math.sin(th) + (zy - xy)*math.cos(th) + xy
koch(n-1, ax, ay, xx, xy)
print xx,xy
koch(n-1, xx, xy, yx, yy)
print yx,yy
koch(n-1, yx, yy, zx, zy)
print zx,zy
koch(n-1, zx, zy, bx, by)
import math
n = int(raw_input())
ax = 0.0
ay = 0.0
bx = 100.0
by = 0.0
print ax,ay
koch(n, ax, ay, bx, by)
print bx,by | 1 | 125,994,352,628 | null | 27 | 27 |
N = int(input())
for i in range(N):
triangle = sorted([int(n) for n in input().split()])
if triangle[0]**2 + triangle[1]**2 == triangle[2]**2:
print('YES')
else:
print('NO')
| n, m = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort(reverse=True)
ss = sum(nums)
if nums[m-1] * (4 * m) < ss:
print('No')
else:
print('Yes')
| 0 | null | 19,432,655,856,460 | 4 | 179 |
D, T , S = map(int,input().split())
move = T * S
if move >= D:
print('Yes')
else:
print('No')
| from collections import deque
N,u,v=map(int,input().split())
u-=1;v-=1
G=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a-=1;b-=1
G[a].append(b)
G[b].append(a)
if len(G[u])==1 and G[u][0]==v:
print(0)
exit()
distu=[-1 for i in range(N)]
q=deque([])
q.append(u)
while(len(q)>0):
r=q.pop()
for p in G[r]:
if distu[p]!=-1:
continue
distu[p]=distu[r]+1
q.append(p)
distv=[-1 for i in range(N)]
q=deque([])
q.append(v)
while(len(q)>0):
r=q.pop()
for p in G[r]:
if distv[p]!=-1:
continue
distv[p]=distv[r]+1
q.append(p)
dist=[distv[i] if distu[i]<=distv[i] else 0 for i in range(N)]
print(max(dist))
| 0 | null | 60,240,361,817,960 | 81 | 259 |
L=float(input())
print((L/3)**3) | N = int(input())
ans = 0
for i in range(1, N + 1):
n = N // i # 項数n
cnt = (n * (2 * i + (n - 1) * i)) // 2 # 初項i, 項数n の等差数列の和の公式
ans += cnt
print(ans) | 0 | null | 29,145,829,375,532 | 191 | 118 |
x, N = map(int, input().split())
p = list(map(int, input().split()))
min =10000
temp = 0
num = 10000
for i in range(-1000, 1000):
temp = abs(x- i)
if temp < min and i not in p:
min = temp
num = i
print(num)
| def main():
x, n = map(int, input().split())
if n == 0:
print(x)
return
p_tuple = tuple(map(int, input().split()))
radius = 0
for i in range(100):
if x-radius not in p_tuple:
print(x-radius)
return
elif x+radius not in p_tuple:
print(x+radius)
return
else:
radius += 1
if __name__ == '__main__':
main()
| 1 | 14,145,827,423,262 | null | 128 | 128 |
import numpy as np
def cumsum(x):
return list(np.cumsum(x))
def cumsum_number(N,K,x):
ans=[0]*(N-K+1)
number_cumsum = cumsum(x)
number_cumsum.insert(0,0)
for i in range(N-K+1):
ans[i]=number_cumsum[i+K]-number_cumsum[i]
return ans
"""
int #整数
float #小数
#for
for name in fruits: #fruitの頭から操作
print(name)
#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split())) # 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加 最後に()内が足される
list.insert(3,10) #リストの追加 任意の位置(追加したい位置,追加したい値)
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可)内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True) #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3, ,3]) #リストの合計
abs(a) #aの絶対値
max(a,b) min(a,b) #最大値 最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)
exit(0) #強制終了
cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N=int(input())
ans=0
for j in range(N):
if (j+1)%3!=0 and (j+1)%5!=0:
ans += j+1
print(ans)
| def main():
N = int(input())
comb_count = [[0 for i in range(10)] for j in range(10)]
res = 0
for i in range(1, N + 1):
s = str(i)
max, min = int(s[0]), int(s[-1])
comb_count[max][min] += 1
for l in range(1, 10):
for r in range(1, 10):
res += comb_count[l][r] * comb_count[r][l]
print(res)
if __name__ == '__main__':
main() | 0 | null | 60,661,256,694,090 | 173 | 234 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
a = list(map(int, input().split()))
aa = [(num,i) for i,num in enumerate(a)]
aa.sort()
write(" ".join(map(str, [item[1]+1 for item in aa]))) | from collections import Counter
S = input()
L = len(list(S))
dp = [0] * L
dp[0] = 1
T = [0] * L
T[0] = int(S[-1])
for i in range(1, L):
dp[i] = dp[i - 1] * 10
dp[i] %= 2019
T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1]
T[i] %= 2019
ans = 0
for k, v in Counter(T).items():
if k == 0:
ans += v
ans += v * (v - 1) // 2
else:
ans += v * (v - 1) // 2
print(ans)
| 0 | null | 106,031,082,983,680 | 299 | 166 |
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')
| a,b,c=map(int,input().split())
if c<a+b:
print("No")
exit()
if 4*a*b<(c-a-b)*(c-a-b):
print("Yes")
else:
print("No")
| 1 | 51,535,660,431,696 | null | 197 | 197 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n = ini()
ans = 0
tmp = 1
while n > 0:
n //= 2
ans += tmp
tmp *= 2
print(ans) | H = int(input())
i = 1
cnt = 0
while H > 0:
H //= 2
cnt += i
i *= 2
print(cnt) | 1 | 80,168,599,674,568 | null | 228 | 228 |
while True:
a, b = map(int, input().split())
if(a == 0 and b == 0):
break
for i in range(a):
for j in range(b):
if(0 < i < a-1 and 0 < j < b-1):
print(".", end = "")
else:
print("#", end = "")
print()
print()
| H, W = list(map(int, input().split()))
while H != 0 or W != 0 :
print('#' * W)
for i in range(H-2) :
print('#', end = '')
print('.' * (W - 2), end = '')
print('#')
print('#' * W)
print()
H, W = list(map(int, input().split())) | 1 | 804,713,673,010 | null | 50 | 50 |
n = int(input())
ans = 0
for i in range(1, n):
for j in range(1, n):
if i*j>=n:
break
ans += 1
print(ans) | import collections
MAXN = 10**6+10
sieve = [i for i in range(MAXN+1)]
p = 2
while p*p <= MAXN:
if sieve[p] == p:
for q in range(2*p,MAXN+1,p):
if sieve[q] == q:
sieve[q] = p
p += 1
def prime(a):
tmp = []
while a > 1:
tmp.append(sieve[a])
a //= sieve[a]
return collections.Counter(tmp)
def main():
N = int(input())
ans = 0
for c in range(1, N):
p = prime(N - c)
tmp = 1
for v in p.values():
tmp *= (v + 1)
ans += tmp
return ans
if __name__ == '__main__':
print(main()) | 1 | 2,628,767,209,600 | null | 73 | 73 |
from math import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [a//2 for a in A]
LCM = 1
for i in range(N):
LCM = LCM * B[i] // gcd(LCM, B[i])
for i in range(N):
if LCM // B[i] % 2 == 0:
print(0)
exit()
print((M//LCM + 1)//2) | from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
def lcm(a, b):
return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
if len(a) == 1: lcm_all = a[0]//2
else: lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
lcm_all = lcm(lcm_all, a[i]//2)
amax = max(amax, a[i]//2)
f = True
if lcm_all > m:
f = False
for i in range(n):
if n == 1: break
if (lcm_all//(a[i]//2))%2 == 0:
# akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない
f = False
if f:
# amaxの奇数倍でmを超えないもの
ans = (m // lcm_all + 1)//2
print(ans)
else:
print(0) | 1 | 101,622,817,646,450 | null | 247 | 247 |
K = int(input())
S = input()
S_len = len(S)
if len(S)<=K:
print(S)
else:
print(S[0:K]+'...') | D = int(input())
c = list(map(int, input().split()))
s = []
t = []
for _ in range(D):
s.append(list(map(int, input().split())))
for _ in range(D):
t.append(int(input()))
ans = 0
last_date = [0]*26
for day in range(D):
contest = t[day]-1
ans += s[day][contest]
last_date[contest] = day+1
for j in range(26):
ans -= c[j] * (day+1 - last_date[j])
print(ans)
| 0 | null | 14,917,259,045,850 | 143 | 114 |
s = input()
t = s[::-1]
n = len(s)
resid = [0] * 2019
resid[0] = 1
csum = 0
powoften = 1
for i in range(n):
csum = (csum + int(t[i]) * powoften) % 2019
powoften = (10 * powoften) % 2019
resid[csum] += 1
ans = 0
for i in range(2019):
ans += resid[i] * (resid[i] - 1) // 2
print(ans) | n = float(input())
even_num = n // 2;
num = n - even_num
print(num/n)
| 0 | null | 104,200,605,974,620 | 166 | 297 |
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
N = int(input())
S = input()
return N, S
def main(N: int, S: str) -> None:
"""
メイン処理.
Args:\n
N (int): 桁数
S (str): ラッキーナンバー
"""
# 求解処理
ans = 0
x_bit = [False for n in range(10)]
for x in range(N):
S_x = int(S[x])
if x_bit[S_x]:
continue
x_bit[S_x] = True
y_bit = [False for n in range(10)]
for y in range(x + 1, N):
S_y = int(S[y])
if y_bit[S_y]:
continue
y_bit[S_y] = True
z_bit = [False for n in range(10)]
for z in range(y + 1, N):
S_z = int(S[z])
if z_bit[S_z]:
continue
z_bit[S_z] = True
ans += 1
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, S = get_input()
# メイン処理
main(N, S)
|
l=raw_input()
k=l.split()
k.sort()
f=0
#
while f==0:
a=int(k[0])
b=int(k[1])
if a==b==0:
break
else:
if a<b:
print a,b
else:
print b,a
l=raw_input()
k=l.split()
k.sort() | 0 | null | 64,623,694,776,280 | 267 | 43 |
N ,M= input().split()
a=[]
N=int(N)
M=int(M)
for i in range(N):
a.append(list(map(int,input().split())))
b=[int(input()) for i in range(M)]
x=[0 for i in range(N)]
for i in range(N):
for j in range(M):
x[i]+=a[i][j]*b[j]
print("\n".join(map(str,x))) | n,m = map(int,input().split())
mat=[]
v=[]
for i in range(n):
a=list(map(int,input().split()))
mat.append(a)
for j in range(m):
v.append(int(input()))
for i in range(n):
w = 0
for j in range(m):
w += mat[i][j]*v[j]
print(w)
| 1 | 1,149,176,767,700 | null | 56 | 56 |
def resolve():
a,b = map(int,input().split())
print(0 if a<b*2 else a-b*2)
resolve() | 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()
| 1 | 166,843,895,887,150 | null | 291 | 291 |
import sys
from itertools import product
input = lambda:sys.stdin.buffer.readline().rstrip()
m, n, k = map(int, input().split())
grid = [[0] * n for _ in range(m)]
for _ in range(k):
i, j, v = map(int, input().split())
i -= 1; j -= 1
grid[i][j] = v
dp = [[0] * 4 for _ in range(n)]
for i in range(m):
ndp = [[0] * 4 for _ in range(n)]
for j, k in product(range(n), range(4)):
# from top
ndp[j][0] = max(ndp[j][0], dp[j][k])
ndp[j][1] = max(ndp[j][1], dp[j][k] + grid[i][j])
# from left
if j > 0:
ndp[j][k] = max(ndp[j][k], ndp[j - 1][k])
if k > 0:
ndp[j][k] = max(ndp[j][k], ndp[j - 1][k - 1] + grid[i][j])
dp = ndp
print(max(dp[-1])) | n, k = map(int, input().split())
lst = [int(i) for i in input().split()]
tele_lst = []
town_set = set()
town = 1
while True:
if town not in town_set:
tele_lst.append(town)
town_set.add(town)
else:
break
town = lst[town - 1]
ind = tele_lst.index(town)
length = len(town_set)
circle = length - ind
#print(ind, length)
#print(tele_lst)
if k < ind:
town = tele_lst[k]
print(town)
else:
k -= ind
k %= circle
#print(k)
town = tele_lst[ind + k]
print(town) | 0 | null | 14,085,596,771,248 | 94 | 150 |
n = int(input())
lst = list(map(int, input().split()))
lst = sorted(lst, reverse = True)
summ = lst[0] + 2 * sum(lst[1:n//2])
if n % 2:
summ += lst[n//2]
print(summ)
| ## coding: UTF-8
#import random
import math
N = int(input())
A = list(map(int,input().split()))
#N = 9
#A = [1, 2, 3, 40, 50, 60, 100, 200, 300]
A = sorted(A, reverse = True)
#print(N, A)
score = 0
for i in range(1, N):
index = math.floor(i/2)
score += A[index]
#print(i, index, A[index], score)
print(score) | 1 | 9,137,914,140,278 | null | 111 | 111 |
score = list(map(int,input().split()))
if score[0] == 1:
evennum = 0
else:
evennum = score[0]*(score[0]-1)/2
if score[1] == 1:
oddnum = 0
else:
oddnum = score[1]*(score[1]-1)/2
print(int(evennum+oddnum)) | import math
def count(n, r):
return math.factorial(n) // math.factorial(n - r)
def main():
N, M = map(int, input().split())
if (N == 0 and M == 0) or (N == 1 and M == 1):
ans = 0
elif N == 0 or N == 1:
y = count(M, 2)
ans = y
elif M == 0 or M == 1:
x = count(N, 2)
ans = x
else:
x = count(N, 2)
y = count(M, 2)
ans = x + y
print(int(ans/2))
main()
| 1 | 45,648,277,613,068 | null | 189 | 189 |
N = int(input())
ans = 10**100
for i in range(1,int(N**(0.5))+1):
if N % i == 0:
tmp = (i-1) + (N//i -1)
ans = min(ans,tmp)
print(ans)
| n,m = map(int,input().split())
p=[0]*m
s=[0]*m
for i in range(m):
p[i],s[i]=map(str,input().split())
cor=[0]*n
fal=[0]*n
for i in range(m):
x=int(p[i])
if cor[x-1]==0:
if s[i]=='AC':
cor[x-1]=1
else:
fal[x-1]+=1
ans_cor=0
ans_fal=0
for i in range(n):
if cor[i]==1:
ans_cor+=1
ans_fal+=fal[i]
print(ans_cor,ans_fal) | 0 | null | 127,796,132,128,768 | 288 | 240 |
n = list(map(int,input().split()))
m = []
for i in range(2):
m.append(n[0])
n.pop(0)
n.append(m[0])
n.append(m[1])
print(*n) | [N, R] = [int(i) for i in input().split()]
print(R + 100*max(10-N, 0)) | 0 | null | 50,686,018,127,932 | 178 | 211 |
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
if N<=0:
return [[]]*num
elif num==1:
return [I() for _ in range(N)]
else:
read_all = [tuple(II()) for _ in range(N)]
return map(list, zip(*read_all))
#################
from bisect import bisect_left
#Binary Indexed Tree(区間加算)
#1-indexed
class Range_BIT():
def __init__(self, N):
self.size = N
self.data0 = [0]*(N+1)
self.data1 = [0]*(N+1)
def _add(self, data, k, x):
while k <= self.size:
data[k] += x
k += k & -k
# 区間[l,r)にxを加算
def add(self, l, r, x):
self._add(self.data0, l, -x*(l-1))
self._add(self.data0, r, x*(r-1))
self._add(self.data1, l, x)
self._add(self.data1, r, -x)
def _get(self, data, k):
s = 0
while k:
s += data[k]
k -= k & -k
return s
# 区間[l,r)の和を求める
def query(self, l, r):
return self._get(self.data1, r-1)*(r-1)+self._get(self.data0, r-1)\
-self._get(self.data1, l-1)*(l-1)-self._get(self.data0, l-1)
N,M = II()
A = III()
A.sort()
def is_ok(x):
num = 0
for a in A:
p = bisect_left(A,x-a)
num += N-p
if num>=M:
return True
else:
return False
#l:その値以上の幸福度の握手がM通り以上ある最大値
l = 0
r = 2*10**5 + 1
while abs(r-l)>1:
mid = (l+r)//2
if is_ok(mid):
l = mid
else:
r = mid
#値l以上の握手で用いるA[i]の個数を調べる
bit = Range_BIT(N)
for i in range(1,N+1):
p = bisect_left(A,l-A[i-1])
if p!=N:
bit.add(p+1,N+1,1)
bit.add(i,i+1,N-p)
x = [0]*N
for i in range(N):
x[i] = bit.query(i+1,i+2)
ans = 0
for i in range(N):
ans += A[i]*x[i]
#握手の回数がM回になるように調整
ans -= l*((sum(x)-2*M)//2)
print(ans) | import sys
input = sys.stdin.readline
mm = 10**10
k = mm.bit_length()
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(200001)]]
n,m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0]*100001
for i in a:
b[i] += 1
c = li(st(nu(b)*nu(b)))
ans = 0
for i in range(200001)[::-1]:
if c[i] > 0:
p = min(m,c[i])
m -= p
ans += i*p
if m == 0:
break
print(ans) | 1 | 108,634,437,136,360 | null | 252 | 252 |
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
if a[m-1] < (sum(a) / (4*m)):
print('No')
else:
print('Yes') | # 161 B
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
list.sort(A, reverse=True)
print('Yes') if A[M-1] >= (sum(A)/(4*M)) else print('No') | 1 | 38,668,234,607,598 | null | 179 | 179 |
import math
from copy import copy
di = {}
di[0] = 0
for i in range(1, 2*(10**5)+1):
di[i] = 0
for i in range(1, 2*(10**5)+1):
count = 0
for j in range(int(math.log2(i))+4):
if (i>>j)&1:
count += 1
di[i] = di[i%count] + 1
n = int(input())
x = list(input())
x.reverse()
count = 0
for i in x:
if i =='1':
count += 1
mod_p = count + 1
mod_m = count - 1
di_p = {}
di_m = {}
for i in range(n):
di_p[i] = pow(2, i, mod_p)
if mod_m >= 1:
di_m[i] = pow(2, i, mod_m)
s_p = 0
s_m = 0
for i in range(n):
if x[i] == '1':
s_p += di_p[i]
if mod_m >= 1:
s_m += di_m[i]
else:
continue
for i in range(n-1, -1, -1):
sm = copy(s_m)
sp = copy(s_p)
if x[i] == '1' and (mod_m == 0 or mod_m == -1):
print(0)
elif x[i] == '1':
sm -= di_m[i]
sm %= mod_m
print(di[sm]+1)
else:
sp += di_p[i]
sp %= mod_p
print(di[sp]+1)
| def goes_to_zero(n):
cnt = 0
while(n > 0):
n %= bin(n).count('1')
cnt += 1
return cnt
N = int(input())
X = input()
XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0
for i in range(N):
if X[i] == "0":
print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
else:
if XCM == 0:
print(0)
else:
print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1) | 1 | 8,191,234,959,908 | null | 107 | 107 |
s = input()
flag = 0
sr = s[-1::-1]
if sr == s:
flag+=1
s1 = s[:(len(s)-1)//2]
s1r = s1[-1::-1]
if s1 == s1r:
flag += 1
s2 = s[(len(s)+3)//2-1:]
s2r = s2[-1::-1]
if s2 == s2r:
flag+=1
print('Yes' if flag == 3 else 'No')
| n, k = map(int, input().split())
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
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
def com(n, r, mod):
r = min(r, n - r)
if r == 0:
return 1
res = ilist[n] * iinvlist[n-r] * iinvlist[r] % mod
return res
mod = 10**9+7
ilist = [0]
iinvlist = [1]
tmp = 1
for i in range(1, n+1):
tmp *= i
tmp %= mod
ilist.append(tmp)
iinvlist.append(modinv(tmp, mod))
ans = 0
k = min(n-1, k)
for i in range(k+1):
tmp = com(n, i, mod)
tmp *= com(n-1, i, mod)
ans += tmp
ans %= mod
print(ans) | 0 | null | 57,058,536,500,470 | 190 | 215 |