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 |
|---|---|---|---|---|---|---|
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
for i in range(1001):
i=str(i)
if len(i)!=n:
continue
f=1
for s,c in l:
c=str(c)
if len(i)<s:
f=0
break
if not i[s-1]==c:
f=0
break
if f:
... | n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
ans=str(i)
if len(ans)==n and all(ans[s-1]==str(c) for s,c in sc):
print(ans)
exit()
print(-1) | 1 | 60,929,748,488,192 | null | 208 | 208 |
N = int(input())
A = []
for _ in range(N):
a = int(input())
b = []
for _ in range(a):
b.append(list(map(int, input().split())))
A.append(b)
# 証言リスト A[i人目][j個目の証言] -> [誰が, bit(1は正、0は誤)]
# bitが1であれば正しい証言、0であれば間違った証言とする
# 正しい証言だけ確認して、[i, 1]と証言した i も1かどうか、[j,0]と証言したjが0かどうか
def F(i):
cnt = 0
... | import itertools
n = int(input())
lst = []
for _ in range(n):
m = int(input())
lst_s = []
for _ in range(m):
evi = list(map(int, input().split()))
lst_s.append(evi)
lst.append(lst_s)
#print(lst)
truth = [0, 1]
all_lists = list(itertools.product(truth, repeat=n))
#print(all_lists)
max_count = 0
for eac... | 1 | 121,647,634,125,348 | null | 262 | 262 |
import sys
N = int(sys.stdin.readline().strip())
X = sys.stdin.readline().strip()
def popcount(n):
cnt = 0
while n > 0:
cnt += n & 1
n //= 2
return cnt
def f(n):
cnt = 0
while n != 0:
n = n % popcount(n)
cnt += 1
return cnt
#nX = int(X, 2)
pcnt = X.count('1')
... | import sys
def popcount(x):
'''xの立っているビット数をカウントする関数
(xは64bit整数)'''
# 2bitごとの組に分け、立っているビット数を2bitで表現する
x = x - ((x >> 1) & 0x5555555555555555)
# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitご... | 1 | 8,239,826,175,494 | null | 107 | 107 |
import sys
N = input()
for i in range ( len ( N )):
if '7' == N[i] :
print("Yes")
sys.exit()
print("No") | str = input()
if '7' in str:
print("Yes")
else:
print("No") | 1 | 34,245,476,650,968 | null | 172 | 172 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
bl = N == M
print('Yes' if bl else 'No')
| print("Yes" if len(set(map(int,input().split())))==1 else "No") | 1 | 83,279,894,565,630 | null | 231 | 231 |
N = int(input())
a = N // 100
if 0 <= N - 100 * a <= 5 * a:
print(1)
else:
print(0) | dp = [True] # i円の買い物ができるか
x = int(input())
for i in range(99):
dp.append(False)
for i in range(100, x + 1):
if(i < 106):
dp.append(True)
else:
if(dp[i - 100] or dp[i - 101] or dp[i - 102] or dp[i - 103] or dp[i - 104] or dp[i - 105]):
dp.append(True)
else:
dp... | 1 | 127,124,148,149,014 | null | 266 | 266 |
S = list(input())
K = int(input())
S.extend(S)
prev = ''
cnt = 0
for s in S:
if s == prev:
cnt += 1
prev = ''
else:
prev = s
b = 0
if K % 2 == 0:
b += 1
if K > 2 and S[0] == S[-1]:
mae = 1
while mae < len(S) and S[mae] == S[0]:
mae += 1
if mae % 2 == 1 and mae !... | import math
def main():
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
sumA = t1 * a1 + t2 * a2
sumB = t1 * b1 + t2 * b2
if sumA == sumB:
return 'infinity'
if sumA < sumB:
sumA, sumB = sumB, sumA
a1, b1 = b1, a1
a2, b2 = b2, a2
... | 0 | null | 154,134,834,566,540 | 296 | 269 |
import math
from collections import defaultdict
n = int(input())
p = defaultdict(int)
mod = 10 ** 9 + 7
ori = 0
for _ in range(n):
a,b = map(int,input().split())
if a == b == 0:
ori += 1
continue
elif b < 0:
a *= -1
b *= -1
elif b == 0 and a < 0:
a *= -1
if a ... | import math
x = float(input())
print("%.6f %.6f"%(x*x*math.pi, x*2*math.pi))
| 0 | null | 10,834,980,560,544 | 146 | 46 |
R,C,K= map(int,input().split(" "))
original=[[0]*(C+1) for i in range(R+1)]
for _ in range(K):
r,c,v= map(int,input().split(" "))
original[r][c]=v
d1=[[0]*(C+1) for i in range(R+1)]
d2=[[0]*(C+1) for i in range(R+1)]
d3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
for j in range(1,C+1):
cu... | n = int(input())
min_price = int(input())
max_diff = -1e9
for _ in range(n - 1):
p = int(input())
max_diff = max(p - min_price, max_diff)
min_price = min(p, min_price)
print(max_diff) | 0 | null | 2,819,735,033,060 | 94 | 13 |
a,b,k = map(int, input().split())
if k > a and k >= a+b:
print( 0 , 0 )
elif k < a :
print(a-k , b)
elif k == a:
print(0 , b)
elif k>a and k < a+b:
print(0 , b-(k-a))
| a, b, k = map(int, input().split())
ac, k = min(a, k), k - min(a, k)
bc = min(b, k)
print(a-ac, b-bc) | 1 | 104,141,352,609,568 | null | 249 | 249 |
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
for i in range(1,N+1):
print(C[i]) | def bSort(A):
flag = 1
i = 0
count = 0
while flag:
flag = 0
for j in range(len(A)-1, i, -1):
if int(A[j][1]) < int(A[j-1][1]):
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag = 1
count += 1
i +... | 0 | null | 16,299,339,567,578 | 169 | 16 |
n,k = map(int, input().split())
h = [int(x) for x in input().split()]
if n<=k:
print(0)
exit()
h.sort()
print(sum(h[:n-k])) | n = int(input())
x = list(map(int,input().split()))
ans = 100**2 * n
for i in range(1,101):
energy = 0
for j in x:
energy += (i-j)**2
ans = min(ans, energy)
print(ans) | 0 | null | 71,806,011,424,382 | 227 | 213 |
a, b, c = [int(i) for i in raw_input().split()]
if a < b< c:
print "Yes"
else:
print "No" | MOD = 10 ** 9 + 7
class Factorial:
def __init__(self, n, mod):
self.f = [1]
self.mod = mod
for j in range(1, n + 1):
self.f.append(self.f[-1] * j % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for j in range(n, 0, -1):
self.i.append(self.i[-1] * j % ... | 0 | null | 33,761,905,740,668 | 39 | 215 |
from functools import reduce
n = input()
a = list(map(int, input().split()))
s = int(reduce(lambda i,j: i^j, a))
print(' '.join(list(map(lambda x: str(x^s), a)))) | def main():
cands = {'ABC', 'ARC'}
S = input()
cands.discard(S)
print(cands.pop())
if __name__ == '__main__':
main()
| 0 | null | 18,226,504,712,352 | 123 | 153 |
A,B,C,D=map(int,input().split())
x=(A-1)//D+1
y=(C-1)//B+1
if x<y:
print("No")
else:
print("Yes")
| n, x, m = map(int, input().split())
dic = {}
tmp = []
a = x
sum_a = x
for i in range(n - 1):
if a in dic:
tmp.append(sum_a)
idx0 = dic[a] - 1
idx1 = i - 1
period = idx1 - idx0
times = (n - 1 - idx0) // period
res = (n - 1 - idx0) % period
before = tmp[idx0]
... | 0 | null | 16,245,164,081,230 | 164 | 75 |
N, M = map(int, input().split())
flgs = [0] * N
penas = [0] * N
ac = 0
pena = 0
for _ in range(M):
p, s = input().split()
p = int(p)
s = (s=='AC')
if flgs[p - 1]:
continue
elif s:
ac += 1
flgs[p - 1] = 1
pena += penas[p-1]
else:
penas[p - 1] += 1
print(ac... | #coding:utf-8
def seki(a, b):
c = []
gou = 0
d = []
for i in range(len(a)):
for j in range(len(b[0])):
for k in range(len(b)):
gou += a[i][k] * b[k][j]
d.append(gou)
gou = 0
c.append(d)
d=[]
return c
n, m, l = [int(i) for... | 0 | null | 47,420,264,295,558 | 240 | 60 |
def make_array_for_comb(N, mod=10**9+7):
fact = [1,1]
fact_inv = [1,1]
inv = [0,1]
for i in range(2, N+1):
fact.append((fact[-1]*i) % mod)
# モジュラ逆数の性質
inv.append((-inv[mod%i] * (mod//i)) % mod)
fact_inv.append((fact_inv[-1]*inv[i]) % mod)
return fact, fact_inv
def co... | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
s = input().rstrip()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
else:
print("No")
| 0 | null | 68,670,337,985,470 | 242 | 184 |
n = int(input())
s = []
for i in range(n):
s.append(input())
s.sort()
# print(s)
m = 1
cnt = [1]
ans = []
for i in range(1,n):
if s[i] == s[i-1]:
cnt[-1] += 1
else:
if cnt[-1] > m:
ans = [s[i-1]]
elif cnt[-1] == m:
ans.append(s[i-1])
m = max(m, cnt[-1]... | from sys import stdin
input = stdin.readline
def main():
N, K = list(map(int, input().split()))
surp = N % K
print(min(surp, abs(surp-K)))
if(__name__ == '__main__'):
main()
| 0 | null | 54,954,117,058,312 | 218 | 180 |
n = int(input())
a = list(map(int, input().split()))
l = sum(a)
accu = 0
for i in a:
accu += i
if accu>l/2:
if abs(l/2-accu)<abs(l/2-accu+i):
print(accu*2-l)
else:
print(l-(accu-i)*2)
break | n = int(input())
a = list(map(int, input().split()))
first_half = 0
latter_half = sum(a)
min_diff = latter_half
for i in range(n):
first_half += a[i]
latter_half -= a[i]
diff = abs(first_half - latter_half)
min_diff = min(min_diff, diff)
print(min_diff)
| 1 | 141,587,110,707,568 | null | 276 | 276 |
n, x, m = map(int, input().split())
ans = []
c = [0]*m
flag = False
for i in range(n):
if c[x] == 1:
flag = True
break
ans.append(x)
c[x] = 1
x = x**2 % m
if flag:
p = ans.index(x)
l = len(ans) - p
d, e = divmod(n-p, l)
print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e... | import math
from decimal import Decimal, ROUND_HALF_UP
def resolve():
a, b, C = map(int, input().split())
x = math.radians(C)
h = b * math.sin(x)
S = Decimal((a * h) / 2).quantize(Decimal('0.00000001'), rounding=ROUND_HALF_UP)
c = Decimal(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(x))).quan... | 0 | null | 1,520,771,920,590 | 75 | 30 |
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
while True:
N,X = map(int,input().split())
if N == 0 and X == 0:
break
ans = 0
for a in range(1,N+1):
for b in range(1,N+1):
if b <= a:
continue
c = X-(a+b)
if c > b and c <=... | n, m, k = [int(i) for i in input().split()]
subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
x = []
for j in range(n):
if i&(1<<j):
x.append(j)
subsets.append(x)
n+=1
A = []
for i in range(n):
A.append([int(j) for j in input()])
ans = n*m
for subset in sub... | 0 | null | 24,826,058,562,758 | 58 | 193 |
import math
n, d = [int(n) for n in input().split(' ')]
cnt = 0
for i in range(n):
x, y = [int(n) for n in input().split(' ')]
if math.sqrt(x*x + y*y) <= d:
cnt += 1
print(cnt)
| n , d = map(int, input().split())
x = []
y = []
for i in range(n):
a = list(map(int, (input().split())))
x.append(a[0])
y.append(a[1])
ans = 0
for i in range(n):
if (x[i] ** 2 + y[i] ** 2) ** (0.5) <= d:
ans += 1
print(ans) | 1 | 5,950,900,605,988 | null | 96 | 96 |
import sys
r, c = map(int, raw_input().split())
c_sum = 0
sum_vector = [0 for i in xrange(c+1)]
for i in xrange(r):
temp = map(int, raw_input().split())
temp.append(sum(temp))
for j in xrange(c):
sum_vector[j] += temp[j]
sys.stdout.write(str(temp[j])+" ")
else:
sum_vector[c] += temp[c]
print temp[c]
for... | r,c = map(int,input().split())
num=[]
r_sum =[]
for i in range(r):
num.append([int(i) for i in input().split()])
for i in range(r):
line_sum = 0
for j in range(c):
line_sum += num[i][j]
num[i].append(line_sum)
for i in range(c+1):
row_sum = 0
for j in range(r):
row_sum += num[j][... | 1 | 1,367,688,944,660 | null | 59 | 59 |
def find(x):
if parent[x]<0:
return x
else:
parent[x]=find(parent[x])
return parent[x]
def same(x,y):
return find(x)==find(y)
def union(x,y):
root_x=find(x)
root_y=find(y)
if root_x==root_y:
return
if parent[root_x]>parent[root_y]:
root_x,root_y=root... | 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):
... | 1 | 2,284,223,582,870 | null | 70 | 70 |
def main():
n, m, k = map(int, input().split())
mod = 998244353
comb = 1
c = 0
for i in range(k + 1):
if i > 0:
comb = comb * (n - i) * pow(i, mod - 2, mod) % mod
c = (c + m * comb * pow(m - 1, n - 1 - i, mod)) % mod
print(c)
if __name__ == '__main__':
main() | height,width=map(int,input().split())
A=[]
for i in range(height):
A.append([int(j) for j in input().split()])
for i in range(height):
print(' '.join(map(str,A[i])),str(sum(A[i])))
B=[]
C=[0 for _ in range(width)]
for i in range(width):
for j in range(height):
s=0
s+=A[j][i]
B.append(s)
C[i]=sum(B)
B=[]
p... | 0 | null | 12,165,743,439,850 | 151 | 59 |
import sys
input=sys.stdin.readline
import numpy as np
from numpy.fft import rfft,irfft
n,m=[int(j) for j in input().split()]
l=np.array([int(j) for j in input().split()])
a=np.bincount(l)
fft_len=1<<18
fft = np.fft.rfft
ifft = np.fft.irfft
Ff = fft(a,fft_len)
x=np.rint(ifft(Ff * Ff,fft_len)).astype(np.int64)
p=x.cu... | n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):a[i]*=-1
a.sort()
from bisect import bisect_left,bisect_right
def check(mid):
mm=0
for i in range(n):
if -(a[i]+a[0])<mid:break
mm+=bisect_right(a,-(mid+a[i]))
return mm
ok=0
ng=10**10+7
while ng!=ok+1:
mid=(ok+ng)//2
if c... | 1 | 108,277,799,547,840 | null | 252 | 252 |
from math import sqrt
x1, y1, x2, y2 = map(float, input().split())
r = sqrt((x1 - x2)**2 + (y1 - y2)**2 )
print('{0:.5f}'.format(r))
| import math
a,b,c,d=map(float,input().split())
x=math.sqrt((a-c)**2 + (b-d)**2)
print(round(x,8))
#round(f,6)でfを小数点以下6桁にまとめる。
| 1 | 152,635,586,062 | null | 29 | 29 |
from collections import deque
n,m = map(int,input().split())
h=list(map(int,input().split()))
g = [[] for _ in range(n)]
for _ in range(m):
a,b = map(int,input().split())
a-=1
b-=1
g[a].append(b)
g[b].append(a)
ans=0
for j in range(n):
for i in g[j]:
if h[j]<=h[i]:
break
... | n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[0 for i in range(m)]
b=[0 for i in range(m)]
for i in range(m):
a[i],b[i]=map(int,input().split())
count=0
c=[[] for i in range(n)]
for i in range(m):
c[a[i]-1].append(b[i]-1)
c[b[i]-1].append(a[i]-1)
for i in range(n):
max_h=0
for j in rang... | 1 | 25,183,466,699,020 | null | 155 | 155 |
print(2*3.14159*int(input())) | import sys
import math
import itertools
import collections
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N = NI()
xy = [NLI() for _ in r... | 0 | null | 90,159,053,129,728 | 167 | 280 |
# -*- coding: utf-8 -*-
import io
import sys
import math
def solve():
# implement process
pass
def main():
# input
s,t= input().split()
# process
ans = t+s
# output
print(ans)
return ans
### DEBUG I/O ###
_DEB = 0 # 1:ON / 0:OFF
_INPUT = """\
humu humu
"""
_E... | s, t = map(str, input().split())
print(str(t)+str(s)) | 1 | 103,057,837,142,232 | null | 248 | 248 |
k=int(input())
k *= 9
amari = 63
for i in range(1, 10 ** 6 + 1):
amari %= k
if amari == 0:
print(i)
break
else:
amari = amari * 10 + 63
else:
print(-1) | r, c = map(int, input().split())
lis = [[] for a in range(r+1)]
for x in range(r):
lis[x] = list(map(int, input().split()))
lis[x].append(sum(lis[x]))
lis[r] = [0 for a in range(c+1)]
for y in range(c+1):
for z in range(r):
lis[r][y] += lis[z][y]
for x in lis:
for z,y in enumerate(x):
if... | 0 | null | 3,702,361,021,820 | 97 | 59 |
import sys
S = input()
if S == "ABC":
print("ARC")
sys.exit()
else:
print("ABC")
sys.exit()
| S = input()
if S[1] == 'B':
print('ARC')
else:
print('ABC') | 1 | 24,003,897,622,198 | null | 153 | 153 |
import numpy as np
from numpy.fft import rfft, irfft
import sys
input=sys.stdin.readline
N, M = map(int, input().split())
fft_len = 1<<18
MAX = 2*10**5
A = np.zeros(fft_len)
for a in [int(x) for x in input().split()]:
A[a] += 1
F = rfft(A, fft_len)
f = np.rint(irfft(F*F))
n, ans = 0, 0
for i, c in enumerate(f[:MAX... | def resolve():
A, B, C, K = map(int, input().split())
if K < A:
ans = K
elif (A + B) >= K:
ans = A
else:
ans = A - (K - A - B)
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 65,030,551,593,670 | 252 | 148 |
C = input()
tmp = ord(C)
print(chr(tmp + 1))
| al = "abcdefghijklmnopqrstuvwxyz"
C = input()
print(al[al.index(C)+1]) | 1 | 91,965,849,081,204 | null | 239 | 239 |
import math
r = float(input())
print('{0:.6f} {1:.6f}'.format(r * r * math.pi, (r + r) * math.pi)) | pi = 3.14159265359
r = float(input())
a,d = r*r*pi,2*r*pi
print(a,d,sep=' ') | 1 | 630,027,334,440 | null | 46 | 46 |
n, k, c = map(int, input().split())
s = input()
l = []
r = []
res = []
def fun(string, pos):
counter = 0
consec_counter = c + 1
res = []
while pos < n:
# print(pos)
if counter == k:
break
if consec_counter >= c and string[pos] == 'o':
counter += 1
... | def main():
N, K, C = map(int, input().split())
S = input()
L, R = [-C], [N + C]
i, k = 0, 0
while i < N and k < K:
if S[i] == 'o':
L.append(i)
k += 1
i += C
i += 1
L.append(N)
i, k = N - 1, 0
while 0 <= i and k < K:
if S[i] == ... | 1 | 40,471,998,852,858 | null | 182 | 182 |
N, K = map(int, input().split())
portals = [0] + list(map(int, input().split()))
visitTowns = list()
visitTimes = [0 for _ in range(N + 1)]
curTown = 1
timeBackTo = 0
curTime = 0
while True:
if visitTimes[curTown] > 0:
timeBackTo = visitTimes[curTown]
break
visitTowns.append(curTown)
vis... | def main():
x, y = map(int, input().split())
mul_xy = x * y
while True:
x, y = y, x % y
if not y:
break
print(int(mul_xy / x))
if __name__ == '__main__':
main()
| 0 | null | 67,721,600,689,480 | 150 | 256 |
'''
def main():
S = input()
cnt = 0
ans = 0
f = 1
for i in range(3):
if S[i] == 'R':
cnt += 1
else:
cnt = 0
ans = max(ans, cnt)
print(ans)
'''
def main():
S = input()
p = S[0] == 'R'
q = S[1] == 'R'
r = S[2] == 'R'
if p and q a... | s = input()
t = input()
ans = 0
for c, d in zip(s, t):
if c != d:
ans += 1
print(ans) | 0 | null | 7,674,881,153,108 | 90 | 116 |
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi
MOD = 10 ** 9 + 7
INF = 10 ** 18
N, K, C = map(in... | n, k, c = map(int, input().split())
s = input()
left = []
i = 0
while len(left) < k:
if s[i] == 'o':
left.append(i)
i += c + 1
else:
i += 1
right = []
i = n - 1
while len(right) < k:
if s[i] == 'o':
right.append(i)
i -= c + 1
else:
i -= 1
right = right[::-1]
for i in range(k):
if l... | 1 | 40,894,395,708,570 | null | 182 | 182 |
N, M, K = map(int, input().split())
chess = [input() for i in range(N)]
ans = [[0 for i in range(M)] for j in range(N)]
index = 0
def ok(r, h, t):
for i in range(h, t+1):
if ans[r][i] or chess[r][i] == '#':
return False
return True
def color(r, h, t):
for i in range(h, t+1):
... | def main():
H, N = map(int, input().split(' '))
A = input().split(' ')
total = 0
for i in A:
total += int(i)
if total >= H:
print('Yes')
else:
print('No')
main()
| 0 | null | 110,923,214,979,402 | 277 | 226 |
i = 1
while True:
n = input()
if n != 0:
print 'Case %s: %s' % (str(i), str(n))
i = i + 1
else:
break | import sys
for i, x in enumerate(iter(sys.stdin.readline, '0\n'), 1):
print(f'Case {i}: {x[:-1]}')
| 1 | 475,061,338,972 | null | 42 | 42 |
import math
while True:
n = input()
if(n == 0):
break
s = map(int, raw_input().split())
average = 0.0
for i in s:
average += i
average /= len(s)
alpha_pow = 0.0
for i in range(len(s)):
alpha_pow += (s[i] - average) * (s[i] - average)
alpha_pow /= n
print(m... | while True:
n = int(input())
if n==0:
break
score = list(map(int, input().split()))
ave = sum(score) / n
print((sum([(i-ave)**2 for i in score])/n)**0.5)
| 1 | 187,401,766,332 | null | 31 | 31 |
import sys
import numpy as np
mod=10**9+7
n=int(sys.stdin.buffer.readline())
a=np.fromstring(sys.stdin.buffer.readline(),dtype=np.int64,sep=' ')
ans=0
b=1
for i in range(60):
s=int((a&1).sum())
ans=(ans+s*(n-s)*b)%mod
a>>=1
b=b*2%mod
print(ans) | def main():
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
# Aの中でd桁目が0,1であるものの個数を求める(p,qとする)
# 全部のd桁目についてループして、ans+=(2**d)*(p*q)
ans = 0
for d in range(60):
p,q = 0,0
for i in range(N):
if A[i]%2==0: p+=1
else: q+=1
A[i]... | 1 | 123,119,409,563,330 | null | 263 | 263 |
import sys
import numpy as np
import math
import collections
from collections import deque
from functools import reduce
# input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
axor = 0
for ai in a:
axor ^= ai
ans = []
for ni in range(n):
ans.append(str(axor ^ a[ni]))
print(" ".join(... | N = int(input())
alp = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10}
alp2 = "abcdefghij"
def solve(N):
ans = []
if N == 1:
ans.append("a")
else:
pre = solve(N-1)
for i in range(len(pre)):
tmp = sorted(pre[i])
num = alp[tmp[len(tmp)-... | 0 | null | 32,400,099,152,750 | 123 | 198 |
#coding:utf-8
#1_4_A
def isFound(array, x):
""" linear search """
array.append(x)
i = 0
while array[i] != x:
i += 1
if i == len(array)-1:
return False
return True
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
... | from collections import deque
import sys
input = sys.stdin.readline
_ = int(input())
S = [int(i) for i in input().strip().split()]
_ = int(input())
T = [int(i) for i in input().strip().split()]
ans = 0
for t in T:
if t in S:
ans += 1
print(ans)
| 1 | 68,246,548,370 | null | 22 | 22 |
import copy
def bubble(N, A):
for i in range(N - 1):
for j in reversed(range(1, N)):
if A[j - 1][1] > A[j][1]:
tmp = A[j]
A[j] = A[j - 1]
A[j - 1] = tmp
def select(N, A):
for i in range(N):
min = i
for j in range(i, N):
... | # -*- coding: utf-8 -*-
def input_int():
return int(input())
def answer():
n = input_int()
count = 0
for a in range(1, n):
b = (n - 1) // a
if b >= a:
count += (b - a) * 2
count += 1
else:
continue
print(count)
answer() | 0 | null | 1,325,942,305,540 | 16 | 73 |
def main():
n, k = map(int, input().split(" "))
h = list(map(int, input().split(" ")))
h.sort(reverse = True)
print(sum(h[k:]))
if __name__ == "__main__":
main() | n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
print(sum(H[:max(n-k, 0)])) | 1 | 79,380,464,681,980 | null | 227 | 227 |
inputa = input()
print(inputa.swapcase()) | n=int(input())
r=int(n**0.5+1)
ans=0
for i in range(2,r):
e=0
while n%i==0:
n//=i
e+=1
k=1
while e>=k:
e-=k
ans+=1
k+=1
if n!=1:
ans+=1
print(ans)
| 0 | null | 9,209,693,778,658 | 61 | 136 |
n = int(input())
a = list(map(int,input().split()))
ans = 0
m = a[0]
for i in range(1,n):
if a[i] <= m:
ans += -a[i]+m
else:
m = a[i]
print(ans)
| N = int(input())
A = list(map(int, list(input().split())))
total = 0
for i in range(1, N):
step = A[i-1] - A[i]
if step > 0 :
total = total + step
A[i] = A[i] + step
print(total) | 1 | 4,499,275,565,942 | null | 88 | 88 |
N = int(input())
ans = [0]*(1+N)
for x in range(1, 10**2+1):
for y in range(1, 10**2+1):
for z in range(1, 10**2+1):
v = x*x+y*y+z*z+x*y+y*z+z*x
if v<=N:
ans[v] += 1
for i in range(1, N+1):
print(ans[i]) | s=input()
a=[0]*(len(s)+1)
for i in range(len(s)):
if s[i]=="<":
a[i+1]=a[i]+1
for i in range(len(s)-1,-1,-1):
if s[i]==">":
a[i]=max(a[i],a[i+1]+1)
print(sum(a)) | 0 | null | 82,141,467,490,040 | 106 | 285 |
N, M, L = map(int, input().split())
dist = [[10**12] * N for _ in range(N)]
for i in range(N):
dist[i][i] = 0
for _ in range(M):
a, b, c = map(int, input().split())
if c <= L:
dist[a-1][b-1] = dist[b-1][a-1] = c
for k in range(N):
for i in range(N):
for j in range(N):
dist... | #!/usr/bin/env python3
import sys
from itertools import chain
# import numpy as np
# from itertools import combinations as comb
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
def solve(N: int, P: "List[int]"):
min_p = P[0]
count = 0
for p in P:... | 0 | null | 129,609,746,055,828 | 295 | 233 |
def f(n):
res = 0
s = 0
for i in range(1,n+1):
s += i
if s <=n:
res = i
else:
break
return res
n = int(input())
p =2
ans = 0
while p*p <= n:
e = 0
while n%p == 0:
e += 1
n//=p
ans += f(e)
p +=1
if n >1:
ans += 1
print(an... | H,W,K = map(int,input().split())
S = [[int(i) for i in input()] for l in range(H)]
posibility = set()
for i in range(1<<H-1):
SW = []
tmp = S[0]
counter = 0
for k in range(H-1):
if i>>k & 1:
SW.append(tmp)
tmp = S[k+1]
else:
tmp = [tmp[l]+S[k+1][... | 0 | null | 32,839,357,882,200 | 136 | 193 |
h = int(input())
num = 0
t = 0
while h != 1:
h = h//2
num += 2**t
t += 1
num += 2**t
print(num) | N=int(input())
A=list(map(int,input().split()))
mlt=0
for a in A:
mlt^=a
for i in range(N):
print(mlt^A[i],end=" ") | 0 | null | 46,498,615,748,330 | 228 | 123 |
import math
while True:
n=int(input())
if n==0:
break
else:
score=list(map(int,input().split()))
dev=math.sqrt(sum((x-sum(score)/len(score))**2 for x in score)/len(score))
print("{:.8f}".format(dev))
| import statistics
while True:
n = int(input())
if n == 0:
break
scores = list((int(x) for x in input().split()))
std = statistics.pstdev(scores)
print("{0:.8f}" . format(round(std,8)))
| 1 | 193,525,399,262 | null | 31 | 31 |
x = input()
if x == "1": print(0)
else: print(1)
| import math
import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
n = input_int()
_x = []
_y = []
for _ in range(n):
x, y = in... | 0 | null | 3,128,739,328,458 | 76 | 80 |
a, b, c, d = map(int, input().split())
if -(-c//b) > -(-a//d):
print('No')
exit()
print('Yes')
| def main():
n = int(input())
a_list = list(map(int, input().split()))
all_xor = 0
for a in a_list:
all_xor ^= a
x_list = [a ^ all_xor for a in a_list]
print(*x_list, sep=" ")
if __name__ == "__main__":
main()
| 0 | null | 21,081,291,531,580 | 164 | 123 |
import math
a, b, n = list(map(int, input().split()))
x = min(n, b - 1)
ans = math.floor((a * x) / b) - a * math.floor(x / b)
print(ans)
| #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
def solve(A: int, B: int, C: int, K: int):
return min(K, A) - max(K-A-B, 0)
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_token... | 0 | null | 24,753,946,177,702 | 161 | 148 |
a, b = input().split()
print(a * int(b) if a < b else b * int(a)) | import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
a... | 1 | 84,335,793,081,440 | null | 232 | 232 |
import math
n = int(input())
a = list(map(int, input().split()))
f = [0]*10**7
def fctr_d(n):
c = 0
r = int(n**0.5)
for i in range(2, r+2):
while n % i == 0:
c += 1
n = n//i
if c != 0:
if f[i] != 0:
return False
else:
... | import math
def GCD(a):
gcd = a[0]
N = len(a)
for i in range(1, N):
gcd = math.gcd(gcd, a[i])
return gcd
# 素因数分解
def fact(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
... | 1 | 4,115,876,294,050 | null | 85 | 85 |
import sys
n,k=map(int,input().split())
A=[]
mod=10**9+7
zero=0
a=list(map(int,input().split()))
for i in range(n):
if a[i]>0:
A.append([a[i],0])
elif a[i]<0:
A.append([-a[i],1])
else:
zero+=1
if k>n-zero:
print(0)
sys.exit()
A=list(reversed(sorted(A)))
cnt=0
for i ... | n, k = map(int, input().split())
a = list(map(int, input().split()))
a_pos = sorted([i for i in a if i >= 0])
a_neg = sorted([i for i in a if i < 0], reverse=True)
mod = 10 ** 9 + 7
ans = 1
if len(a_pos) == 0 and k % 2:
for i in a_neg[:k]:
ans = ans * i % mod
print(ans)
exit()
while k > 0:
i... | 1 | 9,400,600,527,878 | null | 112 | 112 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
for i in range(int(N**.5),0,-1):
if N % i == 0:
print(i+(N//i)-2)
exit()
| # coding: utf-8
# Your code here!
import sys
import math
n=int(input())
ans=n
for i in range(1,int(math.sqrt(n))+1):
if n%i==0:
a=i
b=int(n/i)
if a+b-2<ans:
ans=a+b-2
print(ans)
| 1 | 161,815,129,356,270 | null | 288 | 288 |
s = []
while True:
hoge = input()
if hoge == '-':
break
num = int(input())
for i in range(num):
h = int(input())
hoge = hoge.replace(hoge,hoge[h:] + hoge[:h])
s += [hoge]
for i in s: print(i) | n = int(input())
playlists = []
for _ in range(n):
title, playtime = input().split()
playlists.append([title, int(playtime)])
titles, playtimes = list(zip(*playlists))
lastmusic = input()
lastmusic_timing = titles.index(lastmusic)
print(sum(playtimes[lastmusic_timing + 1:])) | 0 | null | 49,493,103,663,548 | 66 | 243 |
import sys
def gcd(a,b):
r= b % a
while r != 0:
a,b = r,a
r = b % a
return a
def lcm(a,b):
return int(a*b/gcd(a,b))
for line in sys.stdin:
a,b = sorted(map(int, line.rstrip().split(' ')))
print("{} {}".format(gcd(a,b),lcm(a,b))) | import sys
nums = []
for line in sys.stdin:
nums.append(line)
for i in range(len(nums)):
input_line = nums[i].split(" ")
a = int(input_line[0])
b = int(input_line[1])
if a > b:
num_bigger = a
num_smaller = b
else:
num_bigger = b
num_smaller = a
r = ... | 1 | 770,314,830 | null | 5 | 5 |
# coding: utf-8
# Here your code !
def func():
try:
word=input().rstrip().lower()
words=[]
while(True):
line=input().rstrip()
if(line == "END_OF_TEXT"):
break
else:
words.extend(line.lower().split(" "))
except:
... | data = [
[[0 for k in range(10)] for j in range(3)] for i in range(4)
]
count = int(input())
for x in range(count):
(b,f,r,v) = [int(i) for i in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
print(' ',end='')
for r in range(10):
... | 0 | null | 1,444,049,830,080 | 65 | 55 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
r, c, k = map(int, input().split())
itm = [[0]*(c) for _ in range(r)]
for i in range(k):
ri, ci, vi = map(int, input().split())
itm[ri-1][ci-1] = vi
dp0 = [[0]*4 for c_ in range(3005)]
dp1 = [[0]*4 for c_ in range(3005)]
for i in range(r):
for j in range(c):
... | import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int(): return int(read())
def ints(... | 1 | 5,598,720,952,990 | null | 94 | 94 |
N = int(input())
S, T = map(str, input().split())
result = []
for i in range(N):
result.append(S[i])
result.append(T[i])
print(''.join(result)) | N=int(input())
S,T=input().split()
list=[]
i=0
while i<N:
list.append(S[i])
list.append(T[i])
i=i+1
print(*list, sep='') | 1 | 112,065,143,302,240 | null | 255 | 255 |
from collections import defaultdict
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
print(ans)
else:
d=defaultdict(int)
a=0
for i in range(N):
a+=int(S[N-i-1])*pow(10,i,P)
a%=P
d[a]+=1
... | from collections import defaultdict
N, P = map(int, input().split())
S = input().strip()[::-1]
if P in [2, 5]:
ans = 0
for r in range(N):
if int(S[r]) % P == 0:
ans += N - r
print(ans)
exit()
cum = [0] * (N + 1)
for i in range(N):
now = int(S[i]) * pow(10, i, P)
cum[i + 1]... | 1 | 58,027,523,891,648 | null | 205 | 205 |
def main():
h,w,k=map(int,input().split())
s=[list(input()) for _ in range(h)]
ans=[[0]*w for _ in range(h)]
for idx in range(h):
if '#' in s[idx]:
i=idx
break
start,j,cnt,first=i,0,1,True
while i<h:
if j==w:
if first:
... | H, W, K = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]
L = []
u = 0
M = []
for i in range(H):
s = 0
for j in range(W):
if S[i][j] == '#':
s += 1
u += 1
C[i][j] = u
if s == 0:
L.append(i)
else:
M.append(i)
d = 0
for i in ra... | 1 | 143,593,881,252,500 | null | 277 | 277 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
Ans = "YES"
List = []
before_n = 0
for e in A:
if e == before_n:
Ans = "NO"
break
else:
before_n=e
print(Ans) | n,k=map(int,input().split());print(min(n%k,k-n%k)) | 0 | null | 56,670,110,576,168 | 222 | 180 |
n = int(input())
dic_A = set()
dic_C = set()
dic_G = set()
dic_T = set()
for i in range(n) :
p, string = input().split()
if p == 'insert' :
if string[0] == 'A' :
dic_A.add(string)
elif string[0] == 'C' :
dic_C.add(string)
elif string[0] == 'G' :
dic_G.... | M = 1046527
POW = [pow(4, i) for i in range(13)]
def insert(dic, string):
# i = 0
# while dic[(hash1(string) + i*hash2(string)) % M]:
# i += 1
# dic[(hash1(string) + i*hash2(string)) % M] = string
dic[get_key(string)] = string
def find(dic, string):
# i = 0
# while dic[(hash1(string)... | 1 | 77,420,581,260 | null | 23 | 23 |
N = int(input())
dp = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
if i%10==0: continue
strI = str(i)
f,l = strI[-1], strI[0]
dp[int(f)][int(l)] += 1
res = 0
for i in range(1,10):
for j in range(1,10):
res += dp[i][j] * dp[j][i]
print(res) | from _collections import deque
k = int(input())
l = [str(i) for i in range(1,10)]
que = deque(l)
while len(l) < k:
seq = que.popleft()
a = int(seq[-1])
if a != 0:
aa = seq + str(a-1)
que.append(aa)
l.append(aa)
aa = seq + str(a)
que.append(aa)
l.append(aa)
if a !=... | 0 | null | 63,243,485,882,808 | 234 | 181 |
N = int(input())
*A, = map(int, input().split())
ans = 0
for i, a in enumerate(A):
if (i + 1) & 1 and a & 1:
ans += 1
print(ans)
| N = input()
A = list(map(int,input().strip().split()))
ans = 0
for i in range(len(A)):
if i%2==0 and A[i]%2==1:
ans += 1
print(ans) | 1 | 7,768,962,279,262 | null | 105 | 105 |
t = input()
n = int(input())
for i in range(n):
orders = input().split()
order = orders[0]
a = int(orders[1])
b = int(orders[2])
if order == "replace":
word = orders[3]
t = t[:a] + word + t[b+1:]
if order == "print":
print(t[a:b+1])
if order == "reverse":
t =... | import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
left=1
right=10**9
while left<right:
cnt=0
mid=(left+right)//2
for i in range(n):
cnt+=math.ceil(a[i]/mid)-1
if cnt<=k:
right=mid
else:
left=mid+1
print(left) | 0 | null | 4,284,999,808,230 | 68 | 99 |
import bisect
n = int(input())
A = tuple(map(int,input().split()))
q = int(input())
Q = tuple(map(int, input().split()))
dp = [0]*(2**n)
for i in range(n):
for j in range(1<<i):
dp[j+(1<<i)] = dp[j] + A[i]
dp.sort()
for n in Q:
i = bisect.bisect(dp, n)
print("yes" if i>0 and n==dp[i-1] else "no") | N = int(input().rstrip())
A = [int(_) for _ in input().rstrip().split(" ")]
Q = int(input().rstrip())
M = [int(_) for _ in input().rstrip().split(" ")]
import itertools
from functools import lru_cache
@lru_cache(maxsize=2**12)
def solve(i, m):
if m == 0:
return True
elif i >= N:
return False
... | 1 | 96,273,814,350 | null | 25 | 25 |
s = raw_input()
ans = ""
for i in range(len(s)):
if('A' <= s[i] and s[i] <= 'Z'):
ans += s[i].lower()
elif('a' <= s[i] and s[i] <= 'z'):
ans += s[i].upper()
else:
ans += s[i]
print(ans) | text = raw_input()
t = list(text)
for i in range(len(t)):
if t[i].isupper():
t[i] = t[i].lower()
elif t[i].islower():
t[i] = t[i].upper()
print "".join(t) | 1 | 1,496,357,823,072 | null | 61 | 61 |
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
print(sum(((xi-xj)**2 + (yi-yj)**2) **0.5 for xi,yi in xy for xj,yj in xy) / N)
| def main():
N, M = map(int, input().split())
H = list(map(int, input().split()))
connected = dict()
for _ in range(M):
A, B = map(int, input().split())
if A not in connected:
connected[A] = H[B-1]
else:
connected[A] = max(connected[A], H[B-1])
if ... | 0 | null | 86,535,997,755,516 | 280 | 155 |
import sys
n, a, b = map(int, input().split())
mod = 10**9 + 7
sys.setrecursionlimit(10**9)
def f(x):
if x == 0:
return 1
elif x % 2 == 0:
return (f(x // 2) ** 2) % mod
else:
return (f(x - 1) * 2) % mod
def comb(n,k,p):
"""power_funcを用いて(nCk) mod p を求める"""
from math import f... |
mod = (10 ** 9 + 7)
def comb(n, r):
p, q = 1, 1
for i in range(r):
p = p *(n-i)%mod
q = q *(i+1)%mod
return p * pow(q, mod-2, mod) % mod
n, a, b = list(map(int, input().split()))
s = pow(2, n, mod) - 1
print((s - comb(n, a) - comb(n, b)) % mod) | 1 | 66,449,547,455,328 | null | 214 | 214 |
import collections
import sys
input = sys.stdin.readline
def main():
N = int(input())
S = [input().rstrip() for _ in range(N)]
c = collections.Counter(S).most_common()
max_freq = None
max_S = []
for s, freq in c:
if max_freq is None:
max_freq = freq
max_S.append... | import sys
input = sys.stdin.buffer.readline
import numpy as np
def main():
N,K = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
if sum(a) <= K:
print(0)
else:
a = np.array(a)
f = np.array... | 0 | null | 117,744,735,196,854 | 218 | 290 |
from itertools import combinations as combi
N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]
#/##//####
# M-1+N C N
max_num = 0
for l in combi(range(M-1+N), N):
x = [t-s for t, s in zip(l, range(N))]
# print(x)
score = sum(d for a, b, c, d in ABCD if x[b-1]-x[... | s = list(map(int, input().split()))
N = s[0]
A = s[1]
B = s[2]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1,N - B) + 1 + (B - A - 1) // 2) | 0 | null | 68,642,263,652,858 | 160 | 253 |
n = int(input())
ans = ""
while n:
n -= 1
ans += chr(ord('a') + (n % 26))
n //= 26
print(ans[::-1])
| N = int(input().strip())
ans = ''
while N > 0:
ans = chr(ord('a') + (N-1) % 26) + ans
N = (N -1) // 26
print(ans)
| 1 | 11,867,374,221,680 | null | 121 | 121 |
from collections import Counter
s=input()
n=len(s)
M=[0]
mod=2019
for i in range(n):
m=(M[-1]+int(s[n-1-i])%mod*pow(10,i,mod))%mod
M.append(m)
MC=Counter(M)
r=0
for v in MC.values():
if v>1:
r+=v*(v-1)//2
print(r) | def main():
def modpow(x, n, mod):
res = 1
while n:
if n % 2:
res *= x % mod
x *= x % mod
n >>= 1
return res
s = input()
s = s[::-1]
s_len = len(s)
mod = 2019
d = [0] * mod
d[0] = 1
rev_num = 0
# 2以上なら共通するmo... | 1 | 30,672,439,520,690 | null | 166 | 166 |
def main():
n = int(input())
As = list(map(int, input().split()))
ans = 1
if 0 in As:
print(0)
return
for a in As:
ans *= a
if ans > 10**18:
print(-1)
return
print(ans)
if __name__ == '__main__':
main()
| N = int(input())
A = list(map(int, input().split(' ')))
uniqu_a = list(set(A))
if N == len(uniqu_a):
print('YES')
else:
print('NO') | 0 | null | 45,245,418,707,468 | 134 | 222 |
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
tmp=min(a)+min(b)
for i in range(m):
x,y,c=map(int,input().split())
if a[x-1]+b[y-1]-c<tmp:
tmp=a[x-1]+b[y-1]-c
print(tmp) | n, m = map(int, input().split())
account, wacount = 0, 0
acdic = [0] * (n + 10)
for _ in range(m):
p, s = input().split()
p = int(p)
if s == "AC" and acdic[p] <= 0:
account += 1
wacount += abs(acdic[p])
acdic[p] = 1
elif s == "WA" and acdic[p] <= 0:
acdic[p] -= 1
print(ac... | 0 | null | 73,343,567,178,378 | 200 | 240 |
N = int(input())
says = []
for _ in range(N):
A = int(input())
say = [list(map(int, input().split())) for _ in range(A)]
says.append(say)
# print(says)
max_upright_count = 0
for i in range(1 << N):
integrate = True
upright_count = 0
declares = [-1 for _ in range(N)]
for j in range(N):
... | n = input()
sum_of_digits = 0
for d in n:
sum_of_digits += int(d)
print('Yes' if sum_of_digits%9 == 0 else 'No') | 0 | null | 63,320,670,035,066 | 262 | 87 |
n,m,l = map(int, input().split())
wf=[[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
a,b,c = list(map(int,input().split()))
wf[a-1][b-1] = c
wf[b-1][a-1] = c
q = int(input())
st=[list(map(int,input().split())) for i in range(q)]
from scipy.sparse.csgraph import floyd_warshall
for i ... | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m,l = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
a,b,c = map(int, input().split())
a-=1
b-=1
... | 1 | 173,771,273,435,708 | null | 295 | 295 |
#coding = utf-8
import math
a, b, c = map(float, raw_input().split())
h = b * math.sin(math.pi*c/180)
s = a * h / 2
x = math.sqrt(h**2 + (a-b*math.sin(math.pi*(90-c)/180))**2)
l = a + b + x
#print "%.8f, %.8f, %.8f" % (s, l, h)
print "\n".join([str(s), str(l), str(h)])
#print "%.1f, %.1f, %.1f" % (s, l, h) | A, B, K = map(int, input().split())
a = max(0, A - K)
b = B
if K - A > 0:
b = max(0, B - K + A)
print(a, b)
| 0 | null | 52,375,380,579,350 | 30 | 249 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
class UnionFind(object):
def __init__(self, n, recursion = False):
self._par = list(range(n))
self._size = [1] * n
self._recursion = recursion
def root(se... | a,b,c=map(int, input().split())
#たこ焼きが余るかの場合分け
if a%b==0:
Q=a//b
#ちょうど焼ききる
else:
Q=a//b+1
#余る
print(Q*c)#回数×時間
#完了
| 0 | null | 3,278,049,555,810 | 70 | 86 |
terms = '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'.split(', ')
print(terms[int(input()) - 1]) | mlist = list([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])
b = int(input())
print(mlist[b-1]) | 1 | 49,973,919,472,860 | null | 195 | 195 |
A = list(map(int , input().split()))
B = list(map(int , input().split()))
print(sum(sorted(B)[:A[1]])) | a = input()
if a[2] != a[3]:
print("No")
elif a[4] != a[5]:
print("No")
else:
print("Yes") | 0 | null | 26,809,981,690,490 | 120 | 184 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
#DP[i] = i までの魔法でモンスターの体力を減らすため消耗する魔力の最小値
dp = [0] * 20001
for i in range(h):
dp[i] = min(dp[i-a] + b for a, b in ab)
print(dp[h-1])
| def main():
a,b,c=map(int,input().split())
if a<b<c:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| 0 | null | 40,538,748,440,672 | 229 | 39 |
from math import sqrt
N = int(input())
X = []
Y = []
for i in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
ans = 0
for i in range(0, N-1):
for j in range(i+1, N):
ans += sqrt((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2)
print(ans * 2.0 / N) | a, b = map(int, input().split())
aa = ""
for i in range(b):
aa += str(a)
bb = ""
for i in range(a):
bb += str(b)
if a <= b :
print(aa)
else :
print(bb) | 0 | null | 115,834,963,814,368 | 280 | 232 |
i = 1
while True:
x = int(raw_input())
if x == 0:
break
else:
print "Case %d: %d" % (i, x)
i += 1 | x = []
while True:
if 0 in x:
break
x.append(int(input()))
x.pop()
for i, v in enumerate(x):
print(('Case %d: %d') % (i+1, v)) | 1 | 500,689,608,340 | null | 42 | 42 |
from itertools import permutations
import math
n = int(input())
x,y = [],[]
for _ in range(n):
x_, y_ =map(int,input().split())
x.append(x_)
y.append(y_)
c = list(permutations([i for i in range(1,n+1)],n))
g = [[-1]*(n+1) for _ in range(n+1)]
sum = 0
for ci in (c):
tmp = 0
for i in range(len(ci)-1... | import numpy as np
import math
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
a=np.array(a, dtype=object)
ans=0
for i in range(n):
for j in range(n):
if i==j:
continue
else:
x= (a[i]-a[j])**2
hei=math.sqrt(sum(x))
ans+= hei/n
print(ans)
| 1 | 148,790,729,286,868 | null | 280 | 280 |
n = int(input())
x = input()
a = x.count('1')
b = int(x,2)
# print (b)
ary = [None for i in range(200010)]
ary[0] = 0
def f(n):
if ary[n] is not None:
return ary[n]
b = bin(n).count('1')
r = 1 + f(n%b)
ary[n] = r
return ary[n]
a1 = a + 1
a0 = a - 1
for i in range(200010):
f(i)
one = [1] * 200010
z... | def main():
print(input().swapcase())
if __name__ == '__main__':
main()
| 0 | null | 4,878,852,050,022 | 107 | 61 |
s=input()
a,b,c,d=0,0,0,0
for i in range(len(s)):
if s[i]==">":
c=0;b+=1
if b<=d:a+=b-1
else:a+=b
else:b=0;c+=1;a+=c;d=c
print(a) | from itertools import groupby
S=input()
T=groupby(S)
s=0
total=0
keys=[]
groups=[]
for key,group in T:
keys.append(key)
groups.append(len(list(group)))
if keys[0]==">":
total+=sum([i for i in range(groups[0]+1)])
if keys[-1]=="<":
total+=sum([i for i in range(groups[-1]+1)])
for i in range(len(keys)-1)... | 1 | 156,305,946,359,772 | null | 285 | 285 |
num = list(map(int,input().split()))
print(num[2],num[0],num[1]) | import math
import itertools
def gcd(lst):
return math.gcd(math.gcd(lst[0],lst[1]), lst[2])
k = int(input())
lst = [i for i in range(1,k+1)]
itr = itertools.combinations_with_replacement(lst, 3)
ans = 0
for i in itr:
st = set(i)
num = len(st)
if num == 1:
ans += i[0]
elif num == 2:
a,b = st
ans ... | 0 | null | 36,988,110,791,062 | 178 | 174 |
a = int(input())
b = list(map(int, input().split()))
b = sorted(b)
c = b[0]
if c == 0:
print(c)
exit()
else:
for i in range(a-1):
c *= b[i+1]
if c > 1000000000000000000:
break
if c > 1000000000000000000:
print(-1)
else:
print(c) | class Dice:
__slots__ = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6']
def __init__(self, n_tup):
self.n1 = n_tup[0]
self.n2 = n_tup[1]
self.n3 = n_tup[2]
self.n4 = n_tup[3]
self.n5 = n_tup[4]
self.n6 = n_tup[5]
def roll(self, direction):
if direction == "N":... | 0 | null | 8,190,488,325,140 | 134 | 33 |
n,x,mod = map(int,input().split())
num = []
ans = cnt = 0
ch = x
while True:
if ch not in num:
num.append(ch)
else:
st = ch
break
ch *= ch
ch %= mod
index = num.index(st)
if (len(num)-index) != 0:
rest = (n-index)%(len(num)-index)
qu = (n-index)//(len(num)-index)
else:
... | N,X,M=map(int,input().split())
table=[X]
visited=[-1]*M
visited[X]=1
ans=X
for i in range(N-1):
nx=table[i]**2
nx%=M
if visited[nx]>0:
first=table.index(nx)
oneloop=i+1-first
rest=N-i-1
loops=rest//oneloop
totalofoneloop=sum(table[first:])
ans+=totalofoneloo... | 1 | 2,769,415,790,164 | null | 75 | 75 |
X=sorted(map(int,input().split()));print(X[0],X[1],X[2]) | list = []
a, b, c = map(list.append, raw_input().split())
list = sorted(list)
for i in range(3):
print list[i], | 1 | 430,706,206,656 | null | 40 | 40 |
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
print(0)
exit()
prod = 1
for a in A:
prod *= a
if prod > 1e18:
print(-1)
exit()
print(prod) | a,b,c=map(int,input().split(' '))
a,b,c=c,a,b
print(str(a)+" "+str(b)+" "+str(c))
| 0 | null | 27,098,412,024,512 | 134 | 178 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.