code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
x = int(input())
ans = 0
while True:
ans += 1
if ans*x % 360 == 0:
break
print(ans)
|
x = int(input())
a = 360
for _ in range(360):
if a%x == 0:
print(a//x)
break
else:
a += 360
| 1 | 13,117,307,239,248 | null | 125 | 125 |
n = int(input())
A = list(map(int,input().split()))
UA = set(A)
print('YES' if len(A) == len(UA) else 'NO')
|
n=int(input())
a=[int(i) for i in input().split()]
cnt={}
for i in range(n):
cnt[a[i]]=0
ok=1
for i in range(n):
cnt[a[i]]+=1
if cnt[a[i]]==2:
print("NO")
ok=0
break
if ok==1:
print("YES")
| 1 | 73,918,640,239,660 | null | 222 | 222 |
n,*aa = map(int, open(0).read().split())
from collections import Counter
c = Counter(aa)
for i in range(1,n+1):
print(c[i])
|
n = int(input())
dp = [1, 1]
for i in range(2, n + 1):
dp = [dp[-1], dp[-2] + dp[-1]]
print(dp[-1])
| 0 | null | 16,156,690,867,228 | 169 | 7 |
## coding: UTF-8
mod = 998244353
N, S = map(int,input().split())
A = list(map(int,input().split()))
dp = []
for i in range(N+1):
#dp.append([0]*3010)
dp.append([0]*(S+1))
#print(dp)
dp[0][0] = 1
#print(dp)
#print('dpstart')
for i in range(N):
for j in range(S+1):
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= mod
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= mod
if(j >= A[i]):
dp[i+1][j] += dp[i][j-A[i]]
dp[i+1][j] %= mod
#print(dp)
print(dp[N][S])
|
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(s+1):
dp[i+1][j] = dp[i+1][j] + dp[i][j] * 2
dp[i+1][j] = dp[i+1][j] % MOD
if j + a[i] <= s:
dp[i+1][j+a[i]] = dp[i+1][j+a[i]] + dp[i][j]
dp[i+1][j+a[i]] = dp[i+1][j+a[i]] % MOD
print(dp[n][s])
| 1 | 17,698,383,284,792 | null | 138 | 138 |
n = int(input())
n %= 10
if n == 3:
print("bon")
elif n == 0 or n == 1 or n == 6 or n == 8:
print("pon")
else:
print("hon")
|
# -*- using:utf-8 -*-
class main:
def function(x, k, d):
if x >= k * d:
ans = x - k * d
else:
r = x // d
n = k - r
if n % 2 == 0:
ans = x % d
else:
ans = abs(x % d - d)
return ans
if __name__ == "__main__":
x, k, d = map(int, input().split())
x = abs(x)
ans = main.function(x, k, d)
print(ans)
| 0 | null | 12,207,328,377,050 | 142 | 92 |
from scipy.sparse.csgraph import floyd_warshall
N,M,L,*X = map(int, open(0).read().split())
ls = X[:3*M]
Els = [[0]*N for i in range(N)]
Q = X[3*M]
query = X[3*M+1:]
for a,b,c in zip(*[iter(ls)]*3):
if c<=L:
Els[a-1][b-1] = c
Els[b-1][a-1] = c
dist = floyd_warshall(Els)
Els2 = [[0]*N for i in range(N)]
for i in range(N):
for j in range(N):
if dist[i][j]<=L:
Els2[i][j] = 1
ans = floyd_warshall(Els2)
for s,t in zip(*[iter(query)]*2):
if ans[s-1][t-1]==float('inf'):
print(-1)
continue
print(int(ans[s-1][t-1])-1)
|
N, M, L = map(int, input().split())
INF = float('inf')
d1 = [[INF]*N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
d1[a][b] = c
d1[b][a] = c
for i in range(N):
d1[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
d1[i][j] = min(d1[i][k] + d1[k][j], d1[i][j])
d2 = [[INF]*N for _ in range(N)]
for i in range(N):
for j in range(N):
if i == j:
d2[i][j] = 0
if d1[i][j] <= L and i != j:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
s -= 1
t -= 1
if d2[s][t] == INF:
print(-1)
else:
print(d2[s][t]-1)
| 1 | 173,118,551,624,072 | null | 295 | 295 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
for line in sys.stdin:
a,b = line.split(' ')
value = int(a) + int(b)
print( len('{}'.format(value)) )
|
import sys
for e in sys.stdin.readlines():
print(len(str(eval('+'.join(e.split())))))
| 1 | 76,887,900 | null | 3 | 3 |
x=input()
if x[-1]==("s"):
print(x+"es")
elif x[-1]!=("s"):
print(x+"s")
|
S = input()
if S[-1] == "s":
S = S + "es"
print(S)
else:
S = S + "s"
print(S)
| 1 | 2,385,809,037,800 | null | 71 | 71 |
A, B = map(int, input().split())
ans = A*B
if A > 9 or B > 9:
ans = -1
print(ans)
|
import fileinput
a, b = map(int, input().split())
if a > 9 or b > 9:
print("-1")
else:
print(a * b)
| 1 | 157,614,875,679,020 | null | 286 | 286 |
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
Ai = [(i + 1) - a for i, a in enumerate(A)]
Aj = [(j + 1) + a for j, a in enumerate(A)]
cntAi = defaultdict(lambda: 0)
for ai in Ai:
cntAi[ai] += 1
ans = 0
for ai, aj in zip(Ai, Aj):
cntAi[ai] -= 1
ans += cntAi[aj]
print(ans)
|
N = int(input())
Alist = list(map(int,input().split()))
Aplu = []
Amin = dict()
for i in range(N):
A = Alist[i]
Aplu.append(A+(i+1))
if (i+1)-A not in Amin:
Amin[(i+1)-A] = 1
else:
Amin[(i+1)-A] += 1
Answer = 0
for k in Aplu:
if k in Amin:
Answer += Amin[k]
print(Answer)
| 1 | 25,959,072,712,388 | null | 157 | 157 |
import math
n,d=map(int,input().split())
c=0
for _ in range(n):
x,y=map(int,input().split())
k=math.sqrt(x**2+y**2)
if k<=d:
c+=1
print(c)
|
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
pS = [f[i*2:i*2+2] for i in range(M)]
accepted = [0] * (N+1)
wrong = [0] * (N+1)
penalty = [0] * (N+1)
for p,S in pS:
i = int(p)
if accepted[i] == 0:
if S == 'AC':
penalty[i] = wrong[i]
accepted[i] = 1
else:
wrong[i] += 1
print(sum(accepted),sum(penalty))
| 0 | null | 49,900,140,562,272 | 96 | 240 |
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array
# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
# 再帰の制限設定
sys.setrecursionlimit(10000000)
def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
for _ in range(n)]
def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
for _ in range(n)]
def lcm(x, y): return (x * y) // math.gcd(x, y)
# MOD = 10 ** 9 + 7
MOD = 998244353
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N, K = il()
D = [il() for _ in range(K)]
dp = [0] * (N)
dp[0] = 1
acc = 0
for i in range(1, N):
for l, r in D:
if i - l >= 0:
acc += dp[i-l]
acc %= MOD
if i - r - 1 >= 0:
acc -= dp[i-r-1]
acc %= MOD
dp[i] = acc
print(dp[-1])
if __name__ == '__main__':
main()
|
(A, B, M), aa, bb, *xyc = [list(map(int, s.split())) for s in open(0)]
ans = min(aa)+min(bb)
for x, y, c in xyc:
ans = min(ans, aa[x-1]+bb[y-1]-c)
print(ans)
| 0 | null | 28,507,924,173,380 | 74 | 200 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007
from fractions import *
def inverse(f):
# return Fraction(f.denominator,f.numerator)
return 1 / f
def combmod(n, k, mod=MOD):
ret = 1
for i in range(n - k + 1, n + 1):
ret *= i
ret %= mod
for i in range(1, k + 1):
ret *= pow(i, mod - 2, mod)
ret %= mod
return ret
def bunsu(n):
ret = []
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
tmp = 0
while (True):
if n % i == 0:
tmp += 1
n //= i
else:
break
ret.append((i, tmp))
ret.append((n, 1))
return ret
MOD = 998244353
def solve():
n, k = getList()
nums = getList()
dp = [0 for i in range(k+1)]
dp[0] = 1
for i, num in enumerate(nums):
new = [0 for i in range(k+1)]
for j, d in enumerate(dp):
new[j] += d * 2
if (j + num) <= k:
new[j+num] += d
dp = [ne%MOD for ne in new]
print(dp[-1])
def main():
# n = getN()
# for _ in range(n):
solve()
if __name__ == "__main__":
solve()
|
import numpy as np
mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
for num, a in enumerate(A):
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP[a] += pow(2, num, mod)
DP %= mod
print(DP[s])
| 1 | 17,621,747,637,020 | null | 138 | 138 |
# 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')
|
import sys
input = sys.stdin.readline
def main():
N, R = map(int, input().split())
print(R+100*(10-N)) if N < 10 else print(R)
if __name__ == '__main__':
main()
| 0 | null | 51,248,106,439,518 | 179 | 211 |
n = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
#divisors.sort()
return divisors
d1 = make_divisors(n)
d2 = make_divisors(n-1)
ans = 0
for k in d1:
if k == 1:
continue
temp = n
while temp%k == 0:
temp //= k
if temp%k == 1:
ans += 1
ans += len(d2)-1
print(ans)
|
def divisor(n):
ret=[]
for i in range(1,int(n**0.5)+1):
if n%i==0:
a,b=i,n//i
if a!=b:
ret+=a,
ret+=b,
else:
ret+=a,
return sorted(ret)
def f(n):
return divisor(n)[1:]
def solve(n):
ans=f(n-1)
for k in f(n):
N=n
while N>=k:
if N%k==0:N=N//k
else:N=N%k
if N==1:ans+=k,
print(len(ans))
return 0
solve(int(input()))
| 1 | 41,085,367,765,400 | null | 183 | 183 |
x, y, z = map(int, input().split())
if x + y + z <= 21:
print("win")
else:
print("bust")
|
print(['bust', 'win'][sum(map(int, input().split()))<=21])
| 1 | 118,971,424,096,646 | null | 260 | 260 |
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから!!___________
n, m, k = map(int, input().split())
A = list(accumulate(map(int, input().split())))
B = list(accumulate(map(int, input().split())))
A=[0]+A
B=[0]+B
ans = []
for i in range(n+1):
c = bisect_right(B, k-A[i])-1
if c!=-1:
ans.append(c+i)
print(max(ans))
|
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB
A.insert(0, 0)
for i in range(1,len(A)):
A[i] += A[i-1]
for i in range(1, len(B)):
B[i] += B[i-1]
ans = 0
for i in range(len(A)):
rest_time = k - A[i]
if rest_time >= 0:
numb = bisect_right(B, rest_time)
anstmp = i + numb
ans = max(ans, anstmp)
print(ans)
| 1 | 10,710,489,315,790 | null | 117 | 117 |
a,b,x,y,r = map(int,input().split())
if (x+r)>a or (y+r)>b or (x-r)<0 or (y-r)<0:
print('No')
else:
print('Yes')
|
a, b, k = map(int,input().split())
if a <= k:
k -= a
a = 0
if b <= k:
b =0
else:
b -= k
else:
a -= k
print(a, b)
| 0 | null | 52,416,720,600,100 | 41 | 249 |
import sys
sys.setrecursionlimit(10 ** 9)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
uf = UnionFind(N)
FG = [0] * N
BG = [0] * N
for _ in range(M):
a, b = map(int, input().split())
a, b = a-1, b-1
uf.union(a, b)
FG[a] += 1
FG[b] += 1
for _ in range(K):
c, d = map(int, input().split())
c, d = c-1, d-1
if uf.same(c, d):
BG[c] += 1
BG[d] += 1
ans = []
for i in range(N):
ans.append(uf.size(i) - FG[i] - BG[i] - 1)
print(*ans)
|
a,b,c = map(int,input().split())
tmp = a
a = b
b = tmp
tmp = a
a = c
c = tmp
print(a,b,c)
| 0 | null | 49,730,272,242,550 | 209 | 178 |
while True:
a = map(int, raw_input().split(" "))
if len([x for x in a if x <> 0]) <= 0:
break
else:
a.sort()
print " ".join(map(str, a))
|
list1=input().split()
S=list1[0]
T=list1[1]
A,B=map(int,input().split())
U=input()
if U==S:
a=A-1
print(f"{a} {B}")
if U==T:
b=B-1
print(f"{A} {b}")
| 0 | null | 36,108,312,035,004 | 43 | 220 |
import itertools
n = int(input())
l = list(map(int,input().split()))
li = [i for i in range(n)]
a = []
for i in range(n):
a.append([l[i],i])
a.sort(reverse = True)
dp = [[-1]*(n+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(i+1):
le = j
ri = i-le
dp[le+1][ri] = max(dp[le+1][ri],dp[le][ri]+a[i][0]*abs(a[i][1]-le))
dp[le][ri+1] = max(dp[le][ri+1],dp[le][ri]+a[i][0]*abs(n-1-a[i][1]-ri))
ans = 0
for i in range(n+1):
j = n-i
ans = max(ans,dp[i][j])
print(ans)
|
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N = I()
A = []
xy = []
for _ in range(N):
A.append(I())
xy.append([LI() for _ in range(A[-1])])
ans = 0
for i in range(2 ** N):
# まず正直者を仮定し、正直者の証言に矛盾がないか判定
is_ok = True
num = 0
for j in range(N):
if i >> j & 1:
num += 1
for k in xy[j]:
x, y = k
x -= 1
if i >> x & 1 != y:
is_ok = False
if is_ok:
ans = max(num, ans)
print(ans)
if __name__ == '__main__':
resolve()
| 0 | null | 77,794,568,842,002 | 171 | 262 |
(A, V) = map(lambda a: float(a), input().split())
(B, W) = map(lambda a: float(a), input().split())
T = float(input())
D = abs(A - B)
X = V - W
if (X*T >= D):
print("YES")
else:
print("NO")
|
# -*- coding: utf-8 -*-
a, v = map(int,input().split())
b, w = map(int,input().split())
t = int(input())
if a == b:
print("YES")
exit()
if v <= w:
print("NO")
exit()
#print(b-a, w-v, t*(w-v))
if a < b:
if (b - a) <= t * (v - w): #(b - a) // (w - v) <= t
print("YES")
else:
print("NO")
elif a > b:
if (a - b) <= t * (v - w): #(a - b) // (v - w) <= t
print("YES")
else:
print("NO")
| 1 | 15,077,520,305,472 | null | 131 | 131 |
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
mod = 998244353
n,k = readints()
s = [readints() for i in range(k)]
a = [0] * (n+1)
a[1] = 1
b = [0] * k
for i in range(2,n+1):
for j in range(k):
l,r = s[j]
if i-l>0:
b[j] += a[i-l]
if i-r-1>0:
b[j] -= a[i-r-1]
a[i] += b[j]
a[i] %= mod
print(a[-1])
|
n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0
for i in range(q):
for j in range(n):
if s[j]==t[i]:
cnt+=1
break
print(cnt)
| 0 | null | 1,402,945,092,800 | 74 | 22 |
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():
N, *D = map(int, read().split())
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += D[i] * D[j]
print(ans)
return
if __name__ == '__main__':
main()
|
n = int(input())
a = [int(x) for x in input().split()]
res = 0
for i in range(n):
for j in range(i+1,n):
res += a[i] * a[j]
print(res)
| 1 | 168,620,101,903,396 | null | 292 | 292 |
#coding: utf-8
import math
n = int(input())
x = [int(i) for i in input().split(" ")]
y = [int(i) for i in input().split(" ")]
d1 = d2 = d3 = di = 0
for i in range(n):
d1 += abs(x[i] - y[i])
d2 += abs(x[i] - y[i])**2
d3 += abs(x[i] - y[i])**3
if di < abs(x[i] - y[i]):
di = abs(x[i] - y[i])
print(d1)
print(math.pow(d2, 1.0/2.0))
print(math.pow(d3, 1.0/3.0))
print(di)
|
N ,D = map(int , input().split())
sum = 0
for i in range(N):
a,b = map(int , input().split())
if(((a ** 2 + b ** 2)**(1/2)) <= D):
sum += 1
print(sum)
| 0 | null | 3,045,533,430,330 | 32 | 96 |
import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
a,b,x = i_map()
if a*a*b<x*2:
water_y = x/a**2
left_y = b-water_y
half_x = a/2
d = math.degrees(math.atan(left_y/half_x))
print(d)
else:
c = (x*2)/(a*b)
c = math.degrees(math.atan(b/c))
print(c)
if __name__=="__main__":
main()
|
a, b, x = map(int, input().split())
import math
if a**2 * b < 2 * x:
tangent = (2 * (a**2 * b - x)) / a ** 3
theta = math.degrees(math.atan(tangent))
print(theta)
else:
tangent = (a * b**2) / (2 * x)
theta = math.degrees(math.atan(tangent))
print(theta)
| 1 | 163,244,680,120,228 | null | 289 | 289 |
input_n = input()
n = str(input_n)
listN = list(n)
#listN = n.split(' ')
if listN[len(listN) - 1] == "s":
listN.append("e")
listN.append("s")
else:
listN.append("s")
for i in range(len(listN)):
print(listN[i], end = "")
|
word = input()
if word[-1] == 's':
word += "e"
print(word + "s")
| 1 | 2,374,332,203,880 | null | 71 | 71 |
a,b=map(int,input().split())
print('unsafe' if b>=a else 'safe')
|
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for k in range(D)]
t = [int(input()) for k in range(D)]
ret = 0
last = [0]*26
for k in range(D):
last[t[k]-1] = k+1
ret += s[k][t[k]-1]
for i in range(26):
ret -= c[i]*(k+1-last[i])
print(ret)
| 0 | null | 19,575,146,119,780 | 163 | 114 |
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
return int(input())
def rm():
return map(int,input().split())
def rl():
return list(map(int,input().split()))
'''D Anything Goes to zero'''
twoPowM1=[0]*(300000)
twoPowM2=[0]*(300000)
stepsSmall=[0]*(300000)
n=r()
s=input()
bitcount=0
for i in range(n):
if s[i]=='1':
bitcount+=1
mod=bitcount-1
if mod>0:
twoPowM1[0]=1
for i in range(1,len(twoPowM1)):
twoPowM1[i]=(twoPowM1[i-1]+twoPowM1[i-1])%mod
mod=bitcount+1
twoPowM2[0]=1
for i in range(1,len(twoPowM2)):
twoPowM2[i]=(twoPowM2[i-1]+twoPowM2[i-1])%mod
for i in range(1,len(stepsSmall)):
stepsSmall[i]=1+stepsSmall[i%bin(i).count('1')]
valM1=0;valM2=0
for i in range(n):
mod=bitcount-1
if mod>0:
valM1=((valM1*2)%mod+int(s[i]))%mod
mod=bitcount+1
valM2=((valM2*2)%mod+int(s[i]))%mod
for i in range(n):
pow=n-1-i
if s[i]=='0':
mod=bitcount+1
newVal=(valM2+twoPowM2[pow])%mod
print(stepsSmall[newVal]+1)
else:
mod=bitcount-1
if mod==0:
print(0)
else:
newVal=(valM1-twoPowM1[pow])%mod
print(stepsSmall[newVal]+1)
|
def pc(x):
return format(x, 'b').count('1')
N = int(input())
X = input()
Xo = int(X, 2)
count = 0
ans = 0
ori = pc(Xo)
X = list(X)
Xp = Xo%(ori + 1)
if ori == 1:
Xm = 0
else:
Xm = Xo % (ori - 1)
# for i in range(N-1, -1, -1):
for i in range(N):
if ori == 1 and X[i] == '1':
print(0)
continue
else:
if X[i] == '1':
# ans = Xm - pow(2, i, ori - 1)
ans = Xm - pow(2, N-1-i, ori - 1)
ans %= ori - 1
else:
# ans = Xp - pow(2, i, ori + 1)
ans = Xp + pow(2, N-1-i, ori + 1)
ans %= ori + 1
count = 1
while ans > 0:
# count += 1
# if ans == 1:
# break
ans %= pc(ans)
count += 1
print(count)
count = 1
| 1 | 8,142,188,285,190 | null | 107 | 107 |
print("".join(reversed(input().split())))
|
# coding=utf-8
from collections import deque
n, q = map(int, input().split())
queue = deque()
total_time = 0
for i in range(n):
name, time = input().split()
queue.append([name, int(time)])
while queue:
poped = queue.popleft()
if poped[1] > q:
queue.append([poped[0], poped[1] - q])
total_time += q
else:
total_time += poped[1]
print(poped[0], total_time)
| 0 | null | 51,345,696,261,990 | 248 | 19 |
for i in range(1, 10):
for j in range(1, 10):
print(f"{i}x{j}={i * j}")
|
for i in range(1, 10):
for j in range(1, 10):
print(i,'x',j,'=',i*j,sep='')
| 1 | 710,272 | null | 1 | 1 |
s = input()
l1 = len(s)
res = 0
for i in range(l1//2):
if s[i]!=s[-i-1]:res +=1
print(res)
|
S = input()
ans = 0
for i in range(0,len(S)//2):
if S[i] != S[len(S)-1-i]:
ans += 1
print(ans)
| 1 | 120,256,192,548,712 | null | 261 | 261 |
n, m = map(int, input().split())
S = list(input())
"""
9 3
0001000100
0010001000
3 2 3 1
"""
S_r = S[::-1] + ["0"] #スタートのぶん付け足し
ans = []
now = 0
while now < n:
flg = True
for i in range(m,0,-1):
if now + i <= n and S_r[now+i] == "0":
ans.append(i)
now += i
flg = False
break
if flg:
print(-1)
exit()
print(*ans[::-1])
|
a, b = int(input()), int(input())
if 1 not in [a, b]:
print(1)
elif 2 not in [a, b]:
print(2)
else:
print(3)
| 0 | null | 125,062,415,708,288 | 274 | 254 |
def main():
L, R, d = map(int, input().split(' '))
X = 0
if L % d == 0:
X = int(L / d) - 1
else:
X = int(L / d)
print(int(R / d) - X)
main()
|
import sys
input = sys.stdin.buffer.readline
def gcd(a: int, b: int) -> int:
"""a, bの最大公約数(greatest common divisor: GCD)を求める
計算量: O(log(min(a, b)))
"""
while b:
a, b = b, a % b
return a
def multi_gcd(array: list) -> int:
"""arrayのGCDを求める"""
n = len(array)
ans = array[0]
for i in range(1, n):
ans = gcd(ans, array[i])
return ans
def make_mindiv_table(n):
mindiv = [i for i in range(n + 1)]
for i in range(2, int(n ** 0.5) + 1):
if mindiv[i] != i:
continue
for j in range(2 * i, n + 1, i):
mindiv[j] = min(mindiv[j], i)
return mindiv
def get_prime_factors(num):
res = []
while mindiv[num] != 1:
res.append(mindiv[num])
num //= mindiv[num]
return res
n = int(input())
a = list(map(int, input().split()))
mindiv = make_mindiv_table(10 ** 6)
set_primes = set()
flag = True
for val in a:
set_ = set(get_prime_factors(val))
for v in set_:
if v in set_primes:
flag = False
set_primes.add(v)
if not flag:
break
else:
print("pairwise coprime")
exit()
gcd_ = multi_gcd(a)
if gcd_ == 1:
print("setwise coprime")
exit()
print("not coprime")
| 0 | null | 5,794,656,788,232 | 104 | 85 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
ans = 0
for i in range(1,N+1):
if i % 3 == 0 or i % 5 == 0:
continue
ans += i
print(ans)
|
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
cnt = 0
for i in range(1,N + 1):
if i % 3 != 0 and i % 5 != 0:
cnt += i
print(cnt)
| 1 | 34,947,864,250,972 | null | 173 | 173 |
n, k, s = map(int, input().split())
L = [0] * n
for i in range(n):
if i < k:
L[i] = s
else:
if s != 10 ** 9:
L[i] = s + 1
else:
L[i] = s - 1
print(*L)
|
n, k, s = map(int, input().split())
# 1. 全部10**9
# 2. s=10**9の時, 他は1でok
if s == 10 ** 9:
a = [5] * n
else:
a = [10 ** 9] * n
for i in range(k):
a[i] = s
print(*a)
| 1 | 91,087,418,198,590 | null | 238 | 238 |
N = int(input())
A = list(map(int, input().split(' ')))
const = 1000000007
ans = 0
total = sum(A)
for i in range(N):
total -= A[i]
ans += A[i] * total
print(ans%const)
|
n = int(input())
arr_a = list(map(int, input().split()))
mod = 10**9 + 7
memo = {}
for i in range(n):
if i == 0:
memo[n-i-1] = 0
else:
memo[n-i-1] = (memo[n-i] + arr_a[n-i]) % mod
ans = 0
for i in range(n):
ans += arr_a[i] * memo[i]
ans = ans % mod
print(ans)
| 1 | 3,828,954,248,292 | null | 83 | 83 |
import sys
R, C, K = map(int, sys.stdin.readline().split())
grid = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
r, c, v = map(int, sys.stdin.readline().split())
grid[r-1][c-1] = v
# r行目、c列目にいるときに、その行でアイテムをi個取得している場合の最大価値
dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)]
# print(dp)
for r in range(R):
for c in range(C):
# 取らない
dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
dp3[r][c+1] = max(dp3[r][c], dp3[r][c])
if grid[r][c] == 0:
continue
# 取る
dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])
dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])
# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])))
print(dp0[R][C-1])
|
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
a,b = map(lambda z:int(z)-1,input().split())
graph[a].append(b)
graph[b].append(a)
size = [0 for i in range(n)]
check = [True for i in range(n)]
for i in range(n):
if check[i]:
tmp = 1
stack = [i]
check[i] = False
while stack:
now = stack.pop()
size[now] = tmp
tmp+=1
for to in graph[now]:
if check[to]:
check[to] = False
stack.append(to)
print(max(size))
| 0 | null | 4,769,568,227,140 | 94 | 84 |
n = int(input())
i = 100
total=0
while i<n:
i = i*101//100
total +=1
print(total)
|
x = int(input())
ans = 0
m = 100
while m < x:
m += m // 100
ans += 1
print(ans)
| 1 | 26,916,707,302,540 | null | 159 | 159 |
n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
n_vote = sum(l)
if l[m-1] >= n_vote/(4*m):
print('Yes')
else:
print('No')
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
cnt = 0
for _a in a:
if _a * 4 * m >= total:
cnt += 1
if cnt >= m:
print("Yes")
else:
print("No")
| 1 | 38,521,371,200,018 | null | 179 | 179 |
all = [x for x in range(1,53)]
N = int(input())
i = 1
while i <= N:
M, num = input().split()
num = int(num)
if M == 'S':
all.remove(num)
elif M == 'H':
all.remove(num+13)
elif M == 'C':
all.remove(num+26)
elif M == 'D':
all.remove(num+39)
i += 1
sN = 52 - N
for j in range(sN):
if all[j] // 13 == 0 or (all[j] // 13 == 1 and all[j] % 13 == 0):
print("S {}".format(all[j]))
elif all[j] // 13 == 1 or (all[j] // 13 == 2 and all[j] % 13 == 0):
print("H {}".format(all[j]-13))
elif all[j] // 13 == 2 or (all[j] // 13 == 3 and all[j] % 13 == 0):
print("C {}".format(all[j]-26))
else:
print("D {}".format(all[j]-39))
|
n = int(input())
full_set=set([1,2,3,4,5,6,7,8,9,10,11,12,13])
S=[]
H=[]
C=[]
D=[]
for i in range(n):
suit,num = input().split()
if suit=="S": S.append(int(num))
elif suit=="H": H.append(int(num))
elif suit=="C": C.append(int(num))
elif suit=="D": D.append(int(num))
S_set=set(S)
H_set=set(H)
C_set=set(C)
D_set=set(D)
for (suit,suit_set) in zip(["S","H","C","D"],[S_set,H_set,C_set,D_set]):
for num in sorted(list(full_set - suit_set)): print(suit,num)
| 1 | 1,041,731,179,090 | null | 54 | 54 |
import sys
input = sys.stdin.readline
I=lambda:int(input())
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
from collections import deque
res=0
INF=10**9
N,u,v=MI()
G=[[] for _ in [0]*(N+1)]
for i in range(N-1):
a,b=MI()
G[a].append(b)
G[b].append(a)
def bfs(a):
q=deque()
q.append(a)
d=[INF]*(N+1)
d[a]=0
res=0
while q:
r=q.popleft()
for nr in G[r]:
if d[nr]==INF:
q.append(nr)
d[nr]=d[r]+1
res+=1
return d
aoki=bfs(v)
taka=bfs(u)
m=0
for i in range(1,N+1):
if taka[i]<aoki[i]:
m=max(aoki[i],m)
print(m-1)
|
N=str(input())
if '7' in N:
print("Yes")
else:
print("No")
| 0 | null | 76,082,601,596,260 | 259 | 172 |
N, M = map(int, input().split())
c = list(map(int, input().split()))
dp = [0] + [float('inf')] * N
for m in range(M):
ci = c[m]
for n in range(N + 1):
if n - ci >= 0:
dp[n] = min(dp[n], dp[n - ci] + 1)
print(dp[N])
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
A, B = mapint()
if 1<=A<=9 and 1<=B<=9:
print(A*B)
else:
print(-1)
| 0 | null | 79,541,421,869,338 | 28 | 286 |
N=input()
N=list(N)
N=map(lambda x: int(x),N)
if sum(N)%9==0:
print("Yes")
else:
print("No")
|
N = int(input())
x = 0
for i in range(1,N+1):
if i%3 == 0:
print(" %d"%i,end = "");
else:
x = i
while (x):
if x%10 == 3:
print(" %d"%i,end = "")
break
x //= 10
print()
| 0 | null | 2,628,843,128,288 | 87 | 52 |
n = int(input())
i = 100
total=0
while i<n:
i = i*101//100
total +=1
print(total)
|
x = int(input())
r = 100
ans = 0
while r < x:
r = int(r * 101)//100
ans += 1
print(ans)
| 1 | 26,882,755,163,880 | null | 159 | 159 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return input().split()
def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
def solve():
n = II()
A = LI()
memo = {}
ans = 0
for i in range(n):
mae = (i+1) + A[i]
ima = (i+1) - A[i]
ans += memo.get(ima, 0)
memo[mae] = memo.get(mae, 0) + 1
# print(memo)
print(ans)
if __name__ == '__main__':
solve()
|
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [-1 for _ in range(N)]
R = [-1 for _ in range(N)]
for i in range(N):
L[i] = A[i] - i-1
R[i] = A[i] + i+1
# L = -R となる物のうち、i>jになりゃいいんだけど、最後にいくつかで破れば良い気がす
# i > 0 なので、自分自身を2回選んでL=Rみたいにはならない・・・?
LC = Counter(L)
RC = Counter(R)
ans = 0
for k,v in LC.items():
if (-1) * k in RC:
ans += v * RC[(-1)*k]
#print(k,v,(-1)*k,RC[(-1)*k], ans)
print(ans)
| 1 | 26,203,399,428,932 | null | 157 | 157 |
from sys import stdin
def isPrime(x):
if x == 2: return 1
elif x % 2 == 0: return 0
return pow(2, x - 1, x) == 1
n = int(stdin.readline())
print(sum([isPrime(int(stdin.readline())) for _ in range(n)]))
|
import math
def prime(num):
judge = True
for i in range(2, int(math.sqrt(num)+1)):
if num % i == 0:
judge = False
return judge
n = int(input())
cnt = 0
ns=[]
for i in range(n):
num = int(input())
if prime(num):
cnt += 1
print(cnt)
| 1 | 11,134,230,872 | null | 12 | 12 |
k=int(input())
a,b=map(int,input().split())
if b//k-(a-1)//k==0 : print("NG")
else : print("OK")
|
k = int(input())
a,b = map(int,input().split())
n = range(k,1001,k)
if any(a <= i and i <= b for i in n):
print('OK')
else:
print('NG')
| 1 | 26,609,112,518,172 | null | 158 | 158 |
num,money=map(int,input().split())
if num*500>=money:
print("Yes")
else:
print("No")
|
S = input()
Q = int(input())
rev = False
l, r = "", ""
for _ in range(Q):
query = input()
if query[0] == "1":
rev = not rev
else:
T, F, C = query.split()
if F == "1":
if rev:
r += C
else:
l = C + l
else:
if rev:
l = C + l
else:
r += C
res = l + S + r
if rev:
res = res[::-1]
print(res)
| 0 | null | 77,445,823,435,140 | 244 | 204 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
class UnionFind:
def __init__(self, N: int):
"""
N:要素数
root:各要素の親要素の番号を格納するリスト.
ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
rank:ランク
"""
self.N = N
self.root = [-1] * N
self.rank = [0] * N
def __repr__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def find(self, x: int):
"""頂点xの根を見つける"""
if self.root[x] < 0:
return x
else:
while self.root[x] >= 0:
x = self.root[x]
return x
def union(self, x: int, y: int):
"""x,yが属する木をunion"""
# 根を比較する
# すでに同じ木に属していた場合は何もしない.
# 違う木に属していた場合はrankを見てくっつける方を決める.
# rankが同じ時はrankを1増やす
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] > self.rank[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def same(self, x: int, y: int):
"""xとyが同じグループに属するかどうか"""
return self.find(x) == self.find(y)
def count(self, x):
"""頂点xが属する木のサイズを返す"""
return - self.root[self.find(x)]
def members(self, x):
"""xが属する木の要素を列挙"""
_root = self.find(x)
return [i for i in range(self.N) if self.find == _root]
def roots(self):
"""森の根を列挙"""
return [i for i, x in enumerate(self.root) if x < 0]
def group_count(self):
"""連結成分の数"""
return len(self.roots())
def all_group_members(self):
"""{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
return {r: self.members(r) for r in self.roots()}
N,M=MI()
uf=UnionFind(N)
for _ in range(M):
a,b=MI()
a-=1
b-=1
uf.union(a,b)
cnt=uf.group_count()
print(cnt-1)
main()
|
a, b, c, d = map(int, input().split())
for i in range(max(a, b, c, d)):
if b >= c:
print('Yes')
exit()
else:
c -= b
if a <= d:
print('No')
exit()
else:
a -= d
continue
| 0 | null | 15,892,361,881,802 | 70 | 164 |
n = input()
a = map(int, raw_input().split())
for i in range(n):
key = a[i]
j = i - 1
while j >= 0 and a[j] > key:
a[j + 1] = a[j]
j -= 1
a[j + 1] = key
print(" ".join(map(str, a)))
|
import sys
ERROR_INPUT = 'input is invalid'
def main():
n = get_length()
arr = get_array(length=n)
print(*arr)
insetionSort(li=arr, length=n)
return 0
def get_length():
n = int(input())
if n < 0 or n > 100:
print(ERROR_INPUT)
sys.exit(1)
else:
return n
def get_array(length):
nums = input().split(' ')
return [str2int(string=n) for n in nums]
def str2int(string):
n = int(string)
if n < 0 or n > 1000:
print(ERROR_INPUT)
sys.exit(1)
else:
return n
def insetionSort(li, length):
for i in range(1, length):
v = li[i]
j = i - 1
while j >= 0 and li[j] > v:
li[j + 1] = li[j]
j -= 1
li[j + 1] = v
print(*li)
main()
| 1 | 5,812,721,822 | null | 10 | 10 |
def gcd(a, b):
while b:
a, b = b, a%b
return a
def lcm(a, b):
return a*b//gcd(a, b)
X = int(input())
print(lcm(360, X)//X)
|
def gcd(a, b):
if a==0:
return b
else:
return gcd(b%a, a)
X = int(input())
LCM = X*360/gcd(360, X)
print(int(LCM/X))
#a, b = map(int, input().split())
#print(gcd(a, b))
| 1 | 13,153,031,749,928 | null | 125 | 125 |
def main():
d, t, s = map(int, input().split())
print('Yes' if t*s >= d else 'No')
if __name__ == '__main__':
main()
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
def is_lessthanK(X):
ans=0
for A,F in zip(a,f):
if A*F>X:
ans+=A-X//F
if ans > k:
return False
return True
ng=-1
ok=a[-1]*f[0]
while ok-ng>1:
mid=(ok+ng)//2
if is_lessthanK(mid):
ok=mid
else:
ng=mid
print(ok)
| 0 | null | 84,495,769,694,572 | 81 | 290 |
def insertionSort(a, n):
print " ".join(map(str, a))
for i in xrange(1, n):
v = a[i]
j = i - 1
# print "i = " + str(i) + ", j = " + str(j)
while j >= 0 and v < a[j]:
a[j + 1] = a[j]
j -= 1
a[j + 1] = v
print " ".join(map(str, a))
n = int(raw_input())
a = map(int, raw_input().split(" "))
insertionSort(a, n)
|
n = int(input())
xlist = list(map(int,input().split()))
sum = 0
for i in range(n):
for j in range(i+1,n):
sum+=xlist[i]*xlist[j]
print(sum)
| 0 | null | 84,277,993,452,700 | 10 | 292 |
import sys
i=1
while True:
x=sys.stdin.readline().strip()
if x=="0":
break;
print("Case %d: %s"%(i,x))
i+=1
|
case = 0
while 1:
case += 1
n = int(input())
if n == 0: break
print("Case {}: {}".format(case, n))
| 1 | 487,917,966,272 | null | 42 | 42 |
x=int(input())
for i in range(1,361):
if (x*i)%360==0:
print(i)
break
|
N,M,L = (int(i) for i in input().split())
A = [[int(i) for i in input().split()] for i in range(N)]
B = [[int(i)for i in input().split()] for i in range(M)]
C = []
for i in range(N):
for i2 in range(L):
ans = 0
for i3 in range(M):
ans += A[i][i3]*B[i3][i2]
if i2 == L-1:
print(ans)
else:
print(ans,end=" ")
| 0 | null | 7,335,520,729,672 | 125 | 60 |
import math
in_line = raw_input().split()
a = float(in_line[0])
b = float(in_line[1])
c = float(in_line[2])
print 0.5*a*b*math.sin(math.radians(c))
print a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(c)))
print b*math.sin(math.radians(c))
|
import math
a, b, c = [float(i) for i in input().split()]
print(a * b * math.sin(math.radians(c)) / 2)
print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c))))
print(b * math.sin(math.radians(c)))
| 1 | 180,740,380,900 | null | 30 | 30 |
n = int(input())
al = list(map(int, input().split()))
ail = []
for i,a in enumerate(al):
ail.append((a,i+1))
ail.sort()
ans = []
for i,a in ail:
ans.append(a)
print(*ans)
|
a,b=map(int,input().split())
#a,bの最大公約数
def gcd(a, b):
while b:
a, b = b, a % b
return a
#a,bの最小公倍数
def lcm(a, b):
return a * b // gcd (a, b)
print(lcm(a,b))
| 0 | null | 147,141,953,083,300 | 299 | 256 |
import sys
import math
import bisect
def main():
n = int(input())
s = ['ACL'] * n
print(''.join(s))
if __name__ == "__main__":
main()
|
a = int(input())
if a == 1:
print("ACL")
elif a == 2:
print("ACLACL")
elif a == 3:
print("ACLACLACL")
elif a == 4:
print("ACLACLACLACL")
else:
print("ACLACLACLACLACL")
| 1 | 2,202,718,470,118 | null | 69 | 69 |
N=int(input())
if N>=400 and 599>=N:
print('8')
if N>=600 and 799>=N:
print('7')
if N>=800 and 999>=N:
print('6')
if N>=1000 and 1199>=N:
print('5')
if N>=1200 and 1399>=N:
print('4')
if N>=1400 and 1599>=N:
print('3')
if N>=1600 and 1799>=N:
print('2')
if N>=1800 and 1999>=N:
print('1')
|
from collections import defaultdict
n,k = map(int,input().split())
a = list(map(int,input().split()))
ruisekiwa = [0 for _ in range(n+1)]
for i in range(n):
ruisekiwa[i+1] = (ruisekiwa[i] + a[i] - 1) % k
dp = defaultdict(lambda: 0)
ans = 0
tmp = 0
for i in range(n+1):
tmp += 1
if tmp > k:
dp[ruisekiwa[i-k]] -= 1
ans += dp[ruisekiwa[i]]
dp[ruisekiwa[i]] += 1
print(ans)
| 0 | null | 72,397,910,219,958 | 100 | 273 |
n = int(input())
L = [list(map(int,input().split())) for _ in range(n)]
L.sort(key=lambda x:x[0]+x[1])
seen=-10**10
cnt=0
for i in range(n):
if seen<=L[i][0]-L[i][1]:
seen=L[i][0]+L[i][1]
cnt+=1
print(cnt)
|
import string
n = int(input())
s = ''
lowCase = string.ascii_lowercase
while n > 0:
n -= 1
s += lowCase[int(n % 26)]
n //= 26
print(s[::-1])
| 0 | null | 51,034,282,954,732 | 237 | 121 |
N = int(input())
hash = {}
end = int(N ** (1/2))
for i in range(2, end + 1):
while N % i == 0:
hash[i] = hash.get(i, 0) + 1
N = N // i
if N != 1:
hash[i] = hash.get(i, 0) + 1
count = 0
trans = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
res = 0
for i in hash.values():
for j in range(len(trans)):
if i > trans[j]:
continue
elif i == trans[j]:
res += (j + 1)
break
else:
res += j
break
print(res)
|
N=int(input())
K=set(input().split())
i=len(K)
if i==N:
print('YES')
else:
print('NO')
| 0 | null | 45,304,592,780,822 | 136 | 222 |
#!/usr/bin/env python
# coding: utf-8
# In[86]:
# ans = [0]*(len(S)+1)
# for i in range(len(S)):
# count_left = 0
# count_right = 0
# for j in range(i):
# if S[i-j-1] == "<":
# count_left += 1
# else:
# j -= 1
# break
# for k in range(i,len(S)):
# if S[k] == ">":
# count_right += 1
# else:
# k -= 1
# break
# ans[i] = max(count_left, count_right)
# # print(count_left, count_right)
# # print(S[i-j-1:i], S[i:k+1])
# # print(ans)
# print(sum(ans))
# In[87]:
from collections import deque
S = input()
left = deque([0])
right = deque([0])
cnt = 0
for s in S:
if s == '<':
cnt += 1
else:
cnt = 0
left.append(cnt)
cnt = 0
for s in S[::-1]:
if s == '>':
cnt += 1
else:
cnt = 0
right.appendleft(cnt)
ans = 0
for l, r in zip(left, right):
ans += max(l, r)
print(ans)
# In[ ]:
|
x = list(map(int, input().split()))
print(x[2], x[0], x[1])
| 0 | null | 97,223,356,338,836 | 285 | 178 |
N = int(input())
u = []
v = []
for _ in range(N):
x,y = map(int,input().split())
u.append(x+y)
v.append(x-y)
umax = max(u)
umin = min(u)
vmax = max(v)
vmin = min(v)
print(max(umax-umin,vmax-vmin))
|
l=[list(map(int,input().split())) for _ in range(int(input()))]
f=sorted([x+y for x,y in l])
g=sorted([x-y for x,y in l])
print(max(f[-1]-f[0],g[-1]-g[0]))
| 1 | 3,386,998,681,628 | null | 80 | 80 |
n, m = map(int, input().split())
C = sorted([int(x) for x in input().split()])
dp = [int(x) for x in range(n + 1)]
for c in C[1:]:
for i in range(n + 1):
anc = i - c
if anc < 0:
continue
dp[i] = min(dp[i], dp[anc] + 1)
print(dp[n])
|
from fractions import gcd
from functools import reduce, lru_cache
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
def lcm(x, y):
return int(x*y)//int(gcd(x, y))
B = [1 for i in range(N)]
global_lcm = reduce(lcm, A) % MOD
ans = 0
for i in range(N):
ans += (global_lcm*pow(A[i], MOD-2, MOD)) % MOD
ans %= MOD
print(ans)
| 0 | null | 43,957,491,020,630 | 28 | 235 |
print("YES") if int(input()) == len(list(set(input().split(" ")))) else print("NO")
|
N = int(input())
A_list = list(map(int,input().split()))
A_set = set(A_list)
if len(A_list) == len(A_set):
print("YES")
else:
print("NO")
| 1 | 73,938,736,374,748 | null | 222 | 222 |
import sys
cnt = {}
for line in sys.stdin:
for c in line:
if c.isalpha():
cl = c.lower()
cnt[cl] = cnt.get(cl, 0) + 1
for i in range(97, 97 + 26):
c = chr(i)
print("{0} : {1}".format(c, cnt.get(c, 0)))
|
text = ''
while True:
try:
s = input().lower()
except EOFError:
break
if s == '':
break
text += s
for i in 'abcdefghijklmnopqrstuvwxyz':
print(i+' : '+str(text.count(i)))
#print("{0} : {1}".format(i, text.count(i)))
| 1 | 1,681,734,261,128 | null | 63 | 63 |
d=int(input()) #365
c=list(map(int,input().split()))
s=[]
for i in range(d):
s.append(list(map(int,input().split())))
ll=[0 for i in range(26)]
l=[]
ans=[]
for i in range(d):
for j in range(26):
ll[j]+=1
m=-(10**10)
for j in range(26):
t=s[i][j]+ll[j]*c[j]
if m<t:
m=t
tt=j
l.append(ll[tt])
ans.append(tt)
ll[tt]=0
print("\n".join(map(lambda x:str(x+1),ans)))
|
import heapq
import sys
input = sys.stdin.readline
def dijkstra_heap(s,edge,n):
#始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a,b in edge[s]:
heapq.heappush(edgelist,a*(10**6)+b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge%(10**6)]:
continue
v = minedge%(10**6)
d[v] = minedge//(10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
return d
def main():
N, u, v = map(int, input().split())
u -= 1
v -= 1
edge = [[] for i in range(N)]
for _ in range(N-1):
A, B = map(int, input().split())
A -= 1
B -= 1
edge[A].append([1,B])
edge[B].append([1,A])
d1 = dijkstra_heap(u,edge, N)
d2 = dijkstra_heap(v,edge, N)
ans = 0
for i in range(N):
if d1[i] < d2[i]:
ans = max(ans, d2[i]-1)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 63,629,467,745,230 | 113 | 259 |
# -*- coding: utf-8 -*-
n = int(raw_input())
#print n
while True:
try:
a = map(int, raw_input().split())
#print a
a.sort(reverse=True)
#print a
b, c, d = a
if (b * b) == ((c * c) + (d * d)):
print 'YES'
else:
print 'NO'
except EOFError:
break;
|
print "\n".join(s for s in map(lambda x:x[0]+x[1]==x[2] and 'YES' or 'NO', [sorted(int(x)**2 for x in raw_input().split(' ')) for i in range(int(raw_input()))]))
| 1 | 244,442,042 | null | 4 | 4 |
n=int(raw_input())
i = 1
print "",
while(i<=n):
x=i
if x%3 is 0:
print i,
else:
for j in xrange(0,4):
if (x/10**j)%10 is 3:
print i,
break
i = i+1
|
def check(st):
for d in range(len(st)):
if st[d]=="3":
return True
return False
num = int(input())
str=""
for d in range(3,num+1):
s = "%d"%(d)
if d%3==0 or check(s):
str+=" %d"%(d)
print(str)
| 1 | 950,199,603,678 | null | 52 | 52 |
X=int(input())
i=0
t=100
while(t<X):
t *= 101
t = int(t//100)
i += 1
print(i)
|
# 1%
import math
N = int(input())
x = 100
ans = 0
while x < N:
x += x // 100
ans += 1
print(ans)
| 1 | 27,307,277,067,090 | null | 159 | 159 |
#!/usr/bin/env python3
def next_line():
return input()
def next_int():
return int(input())
def next_int_array_one_line():
return list(map(int, input().split()))
def next_int_array_multi_lines(size):
return [int(input()) for _ in range(size)]
def next_str_array(size):
return [input() for _ in range(size)]
def main():
n = next_int()
ar = list(reversed(sorted(next_int_array_one_line())))
# print(ar)
res = ar[0]
n -= 2
use = 1
while n > 0:
if n >= 2:
res += ar[use] * 2
n -= 2
use += 1
else:
res += ar[use]
n -= 1
print(res)
if __name__ == '__main__':
main()
|
n = int(input())
a = sorted(map(int,input().split()))[::-1]
ans = 2 * sum(a[:(n-1)//2+1]) - a[0]
if n % 2 == 1:
ans -= a[(n-1)//2]
print(ans)
| 1 | 9,109,808,591,766 | null | 111 | 111 |
mod = 1000000007
N = int(input())
A = list(map(int, input().split()))
S = [0] # 累積和のリスト
ans = 0
for i in range(N):
S.append(A[i] + S[i] % mod)
for i in range(N):
sum = S[N] - S[i + 1]
if sum < 0:
sum += mod
ans += A[i] * sum
print(ans % mod)
|
n = int( input().rstrip())
numbers = list( map(int, input().rstrip().split(" ")) )
total = sum(numbers)
m = 10 ** 9 + 7
result = 0
for number in numbers[:-1]:
total -= number
result += (total * number)
result %= m
print(result)
| 1 | 3,867,938,761,092 | null | 83 | 83 |
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = map(int,input().split())
mod = 10 ** 9 + 7
ans = 0
for i in range(K, N + 1 + 1):
mi = int((i - 1) * i / 2) #ma、miは i * (10 **100)を無視した上限下限
ma = i * N - mi
ans += ma - mi + 1
print(ans % mod)
if __name__ == "__main__":
main()
|
n, k = map(int, input().split())
mo = 10 ** 9 + 7
ans = 0
def calc(t):
u = (0 + t - 1) * t // 2
v = (n + n - t + 1) * t // 2
return v - u + 1
for i in range(k, n + 2):
ans = (ans + calc(i)) % mo
print(ans)
| 1 | 32,933,174,482,858 | null | 170 | 170 |
x, y = map(int, input().split())
if x > y:
x, y = y, x
while x:
x, y = y % x, x
print(y)
|
import re
def bubble_sort(C, N):
for i in range(N):
for j in reversed(range(1, N)):
if C[j][1] < C[j-1][1]:
# 1???????????????????°????????????°??????
C[j], C[j-1] = C[j-1], C[j]
return C
def selection_sort(C, N):
for i in range(N):
# i ?????????????????¨????????????
minj = i
for j in range(i, N):
# ?????????????????¨??????????°???????????????????
if C[j][1] < C[minj][1]:
minj = j
# ??????????????¨??????????°????????????????????????\????????????
C[i], C[minj] = C[minj], C[i]
return C
def is_stable(C, sorted):
# ????????°???????????????????¨???????????????????????´???????????????????
c_container = []
s_container = []
for i in range(len(C)):
# C ??§ i ????????\?????????????????§????????°????????????????????¢???
for j in range(len(C)):
# ????????°???????????????????????£?????´???
if C[i][1] == C[j][1]:
# C ????????????????¨?????????????
c_container.append(C[j][0])
# ????????°???????????????????????¨????????´???
if len(c_container) >= 2:
# C ??§ i ???????????????????????°?????¨????????°????????????????????¢???
for k in range(len(sorted)):
# ????±??????????????????°?????¨????????°???????¨?????????????????????????????????????????????????????´?
if sorted[k][1] == C[i][1]:
s_container.append(sorted[k][0])
# ??????????????´?????????????????£?????´???
if c_container != s_container:
# Not Stable
return False
# ?????????????????????
c_container = []
s_container = []
return True
if __name__ == '__main__':
N = int(input())
# ??????????????????????????????????????¨?????¨??°?????¨?????????????????????????´?
cards = input().split()
C = [[] for i in range(N)]
for i in range(N):
# ??????????¨??????¨??°????????????
symbol_and_num = re.findall(r'(\d+|\D+)', cards[i])
C[i] = [symbol_and_num[0], int(symbol_and_num[1])]
# ??????????????????????????????
bubble_sorted = bubble_sort(C.copy(), N)
# ?¨??????¨???????????????
bubble_sorted_cards = [val[0] + str(val[1]) for val in bubble_sorted]
# ?????????????????????
print(' '.join(bubble_sorted_cards))
# stable or not stable
print('Stable' if is_stable(C, bubble_sorted) else 'Not stable')
# ?????????????????????
selection_sorted = selection_sort(C.copy(), N)
# ?¨??????¨???????????????
selection_sorted_cards = [val[0] + str(val[1]) for val in selection_sorted]
# ?????????????????????
print(' '.join(selection_sorted_cards))
# stable or not stable
print('Stable' if is_stable(C, selection_sorted) else 'Not stable')
| 0 | null | 14,984,513,478 | 11 | 16 |
#In[]:
x = int(input())
money = 100
year = 0
while True:
money += money//100
year += 1
if money >= x:
print(year)
break
|
from decimal import Decimal
X=int(input())
c =Decimal(100)
C=0
while c<X:
c=Decimal(c)*(Decimal(101))//Decimal(100)
C+=1
print(C)
| 1 | 27,059,672,336,374 | null | 159 | 159 |
N = int(input())
A = list(map(int,input().split()))
R, B, G = 0, 0, 0
ans = 1
for a in A:
if R == a:
if B == a and G == a:
ans *= 3
elif B == a or G == a:
ans *= 2
else:
ans *= 1
R += 1
elif B == a:
if G == a:
ans *= 2
else:
ans *= 1
B += 1
elif G == a:
ans *= 1
G += 1
else:
print(0)
exit()
ans %= 10**9+7
print(ans)
|
def root(x, root_ls):
if root_ls[x] < 0:
return x
else:
root_ls[x] = root(root_ls[x], root_ls)
return root_ls[x]
def unite(a, b, root_ls):
a = root(a, root_ls)
b = root(b, root_ls)
if a != b:
root_ls[a] += root_ls[b]
root_ls[b] = a
n, m = list(map(int, input().rstrip().split(" ")))
members = [-1 for i in range(n)]
max_idx = 0
for mm in range(m):
a, b = list(map(int, input().rstrip().split(" ")))
unite(a-1, b-1, members)
print(max([-m for m in members]))
| 0 | null | 67,087,363,496,260 | 268 | 84 |
input()
*l,=map(int,input().split())
print((pow(sum(l),2)-sum([pow(x,2) for x in l]))//2)
|
N = int(input())
S = input()
ans = ''
for i in S:
num = (ord(i) + N)
if num > 90:
num = 64 + num % 90
ans += chr(num)
print(ans)
| 0 | null | 150,886,783,127,340 | 292 | 271 |
import math
a,b,c=map(float,input().split())
if c<90:
e=c*math.pi/180
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b*math.sin(e)
print(S)
print(L)
print(h)
if c==90:
e=c*math.pi/180
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b
print(S)
print(L)
print(h)
if c>90:
e=c*math.pi/180
d=180*math.pi/180
f=d-e
S=a*b*1/2*math.sin(e)
t=a**2+b**2-2*a*b*math.cos(e)
r=math.sqrt(t)
L=a+b+r
h=b*math.sin(f)
print(S)
print(L)
print(h)
|
import numpy as np
n = int(input())
a = []
b = []
for i in range(n):
ae, be = map(int, input().split())
a.append(ae)
b.append(be)
a_med = np.median(a)
b_med = np.median(b)
if n % 2 == 0:
print(int(2*b_med - 2*a_med + 1))
else:
print(int(b_med - a_med + 1))
| 0 | null | 8,801,045,983,300 | 30 | 137 |
L, R, d = map(int, input().split())
lst = list()
for x in range(R+1):
y = d * x
if y>=L and y<=R:
lst.append(y)
print(len(lst))
|
l,r,d = map(int, input().split())
if l%d == 0:
print(r//d - l//d + 1)
else:
print(r//d - l//d)
| 1 | 7,549,112,911,860 | null | 104 | 104 |
A,B,K=map(int, input().split())
if A >= K:
print(f'{A-K} {B}')
elif (A+B) >= K:
print(f'0 {B-(K-A)}')
else:
print('0 0')
|
p = 10**9+7
def pow(x,m):
if m==0:
return 1
if m==1:
return x
if m%2==0:
return (pow(x,m//2)**2)%p
else:
return (x*(pow(x,(m-1)//2)**2)%p)%p
A = [1 for _ in range(10001)]
for i in range(2,10001):
A[i] = (i*A[i-1])%p
B = [1 for _ in range(10001)]
B[10000] = pow(A[10000],p-2)
for i in range(9999,1,-1):
B[i] = ((i+1)*B[i+1])%p
def f(n,k):
if k>n:
return 0
return (A[n]*B[k]*B[n-k])%p
S = int(input())
n = S//3
ans = 0
for i in range(n,0,-1):
k = S-3*i
ans = (ans+f(k+i-1,i-1))%p
print(ans)
| 0 | null | 53,968,435,420,328 | 249 | 79 |
import numpy as np
n = int(input())
li_a = list(map(int, input().split()))
A = [0]*(10**5)
s = sum(li_a)
li_a = list(map(lambda x: x-1, li_a))
for a in li_a:
A[a] += 1
q = int(input())
for i in range(q):
b, c = map(int, input().split())
if A[b-1]>0:
A[c-1] += A[b-1]
s -= b * A[b-1]
s += c * A[b-1]
A[b-1] = 0
print(s)
else:
print(s)
|
import sys
input = sys.stdin.readline
import collections
def main():
N = int(input())
A = list(map(int, input().split()))
v_freq = collections.Counter(A)
v_sum = 0
for v, freq in v_freq.items():
v_sum += v * freq
Q = int(input())
for _ in range(Q):
B, C = map(int, input().split())
if B in v_freq:
v_sum -= (B - C) * v_freq[B]
if C in v_freq:
v_freq[C] += v_freq[B]
else:
v_freq[C] = v_freq[B]
del v_freq[B]
print(v_sum)
else:
print(v_sum)
if __name__ == '__main__':
main()
| 1 | 12,159,808,909,210 | null | 122 | 122 |
import sys
i = input().split()
a,b,c = int(i[0]),int(i[1]),int(i[2])
if a >= b:
print('No')
sys.exit()
elif b < c:
print('Yes')
sys.exit()
else:
print('No')
|
N, K, C = map(int, input().split())
S = list(input())
# 左詰めの働くリスト
l_list = [-1 for i in range(N)]
i = 0
cnt = 0
while(i < N and cnt < K):
if(S[i] == "o"):
l_list[i] = cnt
cnt += 1
i += C
i += 1
# 右詰めの働くリスト
r_list = [-1 for i in range(N)]
i = N - 1
cnt = 0
while(i >= 0 and cnt < K):
if(S[i] == "o"):
r_list[i] = K-1-cnt
cnt += 1
i -= C
i -= 1
# 両方のリストで一致するマス(日)を出力
for i in range(N):
if(l_list[i] == -1 or r_list[i] == -1):
continue
if(l_list[i] == r_list[i]):
print(i+1)
| 0 | null | 20,682,087,213,602 | 39 | 182 |
x = int(input())
for i in range(1, 100000):
if x * i % 360 == 0:
print(i)
exit()
|
# https://atcoder.jp/contests/abc154/tasks/abc154_e
# 桁DPっぽいよなぁ => O
"""
memo
dp0[i][j]
上からi桁目まで決めて,0でない桁がj個あり
Nより小さいことが確定している (less)
dp1[i][j]
上からi桁目まで決めて,0でない桁がj個あり
Nより小さいことが確定していない (i桁目まで同じ)
通常の再帰
rec
"""
S = input()
K = int(input())
N = len(S)
def com(N, R):
if R < 0 or R > N:
return 0
if R == 1:
return N
elif R == 2:
return N * (N - 1) // 2
elif R == 3:
return N * (N - 1) * (N - 2) // 6
else:
raise NotImplementedError("NIE")
# 再帰呼出し
def rec(i, k, smaller):
if i == N:
return 1 if k == 0 else 0
if k == 0:
return 1
if smaller:
# 残っている桁数からk個を選び,それぞれ9^kのパターンがある
return com(N - i, k) * pow(9, k)
else:
if S[i] == '0':
return rec(i + 1, k , False)
else:
zero = rec(i + 1, k, True)
aida = rec(i + 1, k - 1, True) * (int(S[i]) - 1)
ichi = rec(i + 1, k - 1, False)
return zero + aida + ichi
ans = rec(0, K, False)
print(ans)
| 0 | null | 44,718,361,309,440 | 125 | 224 |
# パナソニック2020D
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
s, m = q.pop()
if len(s)==n:
print(s)
elif len(s)>=n+1:
break
for o in range(ord("a"), ord(m)+2):
if ord(m)<o:
m = chr(o)
q.appendleft((s + chr(o), m))
|
N = int(input())
a_num = 97
def dfs(s, n): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値
if n == 0:
print(s)
return
for i in range(ord("a"), ord(max(s))+2):
dfs(s+chr(i), n-1)
dfs("a", N-1)
| 1 | 52,465,340,212,570 | null | 198 | 198 |
n = int(input())
lst = []
for i in range(n):
x, l = map(int, input().split())
left = x - l
right = x + l
lst.append([left, right])
lst = sorted(lst, key=lambda x: x[1])
ans = 1
limit = lst[0][1]
for i in range(n):
if lst[i][0] >= limit:
ans += 1
limit = lst[i][1]
print(ans)
|
n = int(input())
stack = [["",0] for i in range(10**6*4)]
stack[0] = ["a",1]
pos = 0
while(pos>=0):
if(len(stack[pos][0]) == n):
print(stack[pos][0])
pos-=1
else:
nowstr = stack[pos][0]
nowlen = stack[pos][1]
#print(nowlen)
pos-=1
for ii in range(nowlen+1):
i = nowlen-ii
pos+=1
stack[pos][0] = nowstr+chr(ord('a')+i)
if(i == nowlen):
stack[pos][1] = nowlen+1
else:
stack[pos][1] = nowlen
| 0 | null | 71,056,984,087,012 | 237 | 198 |
l =int(input())
s =input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
A = r * g * b
B = 0
gapmax = (l - 3) // 2
for _ in range(gapmax+1):
for i in range(l-2-2*_):
c1, c2, c3 = s[i], s[i+1+_],s[i+2+2*_]
if not (c1 == c2) and not (c1 == c3) and not (c2 ==c3):
B += 1
print(A-B)
|
#!/usr/bin/env python3
from functools import reduce
from itertools import combinations
from math import gcd
K = int(input())
sum = K * (K + 1) // 2
for i in combinations(range(1, K + 1), 2):
sum += 6 * reduce(gcd, i)
for i in combinations(range(1, K + 1), 3):
sum += 6 * reduce(gcd, i)
print(sum)
| 0 | null | 35,970,120,222,400 | 175 | 174 |
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, M = LI()
if N == M:
print("Yes")
else:
print("No")
|
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import floyd_warshall
n,m,l = map(int,input().split())
edge = [[0]*n for _ in range(n)]
for i in range(m):
a,b,c = map(int,input().split())
edge[a-1][b-1] = c
edge[b-1][a-1] = c
edge = floyd_warshall(edge)
for i in range(n):
for j in range(n):
if edge[i][j]<=l:
edge[i][j] = 1
else:
edge[i][j] = 0
edge = floyd_warshall(edge)
q = int(input())
for i in range(q):
s,t = map(int,input().split())
if edge[s-1][t-1] == float("inf"):
print(-1)
else:
print(int(edge[s-1][t-1] - 1))
| 0 | null | 128,649,029,963,232 | 231 | 295 |
A = list(map(int, input().split()))
N=A[0]
R=A[1]
if N>=10:
print(R)
else:
print(100*(10-N)+R)
|
N,R = map(int,input().split(" "))
if N>10:
print(R)
else:
print(R+100*(10-N))
| 1 | 63,508,286,237,436 | null | 211 | 211 |
def main():
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = []
for i in range(k,n):
ans.append("Yes" if a[i] > a[i-k] else "No")
print("\n".join(ans))
if __name__ == '__main__':
main()
|
N,K=map(int,input().split())
a=list(map(int,input().split()))
for v in range(N-K):
if a[v]>=a[K+v]:
print("No")
else:
print("Yes")
| 1 | 7,123,975,900,352 | null | 102 | 102 |
a, b = list(map(int, input().split(' ')))
def gcd(l, r):
return l if r == 0 else gcd(r, l % r)
print(int(a * b / gcd(a, b)))
|
A, B = [int(_) for _ in input().split()]
print(A * B)
| 0 | null | 64,757,295,534,360 | 256 | 133 |
K = int(input())
S = input()
print(S[:K]+"..." if len(S) > K else S)
|
S = input()
T = input()
ans = 1001
for i in range(len(S)-len(T)+1):
ans = min(ans, sum(S[i+j] != T[j] for j in range(len(T))))
print(ans)
| 0 | null | 11,748,859,082,168 | 143 | 82 |
#!/usr/bin/env python3
def main():
N = int(input())
A = list(map(int, input().split()))
p = 10**9 + 7
digit_0 = [0] * 60
digit_1 = [0] * 60
for i in range(N):
for j in range(60):
if (A[i] >> j) & 1:
digit_1[j] += 1
else:
digit_0[j] += 1
ans = 0
for j in range(60):
ans += ((digit_0[j] * digit_1[j] % p) * pow(2,j,p) % p)
ans %= p
print(ans)
if __name__ == "__main__":
main()
|
N, *A = map(int, open(0).read().split())
mod = 10**9 + 7
ans = 0
for i in range(60):
mask = 1 << i
cnt = 0
for a in A:
if a & mask:
cnt += 1
x = cnt * (N-cnt)
x *= mask % mod
ans += x
ans %= mod
print(ans)
| 1 | 123,157,303,605,660 | null | 263 | 263 |
S=input()
N=len(S)
K=int(input())
s="".join((S,S))
cnt1=0
cnt2=0
buf=0
piv=""
if len(set(S))!=1:
for i in range(N):
if S[i]==piv:
buf=buf+1
else:
piv=S[i]
cnt1=cnt1+(buf+1)//2
buf=0
cnt1=cnt1+(buf+1)//2
buf=0
piv=""
for i in range(2*N):
if s[i]==piv:
buf=buf+1
else:
piv=s[i]
cnt2=cnt2+(buf+1)//2
buf=0
#print(buf)
cnt2 = cnt2 + (buf + 1) // 2
x = cnt2 - cnt1
print(cnt1 + (K - 1) * x)
else:
print((len(S)*K)//2)
|
from collections import defaultdict
dd = defaultdict(int)
n,p=map(int, input().split())
S = list(input().rstrip())
tmp = 0
r=1
su=0
dd[0]=1
if p==2 or p==5:
c=n
for s in S[::-1]:
if int(s)%p==0:
su+=c
c-=1
print(su)
else:
for s in S[::-1]:
tmp+=int(s)*r
tmp%=p
dd[tmp]+=1
r*=10
r%=p
for i in dd.values():
su += (i*(i-1))//2
print(su)
| 0 | null | 116,884,306,820,398 | 296 | 205 |
H, W, K = map(int, input().split())
Ss = [list(map(int, input().replace("\n", ""))) for _ in range(H)]
cut_yoko_patterns = ["0","1"]
options = ["0","1"]
import copy
for i in range(H-2):
cut_yoko_patterns = [cut_yoko_patterns[i] + options[j] for i in range(len(cut_yoko_patterns)) for j in range(len(options))]
answer = int(1e+5)
for cut_yoko_pattern in cut_yoko_patterns:
yoko_cut_num = cut_yoko_pattern.count("1")
boxs = [0 for _ in range(yoko_cut_num+1)]
box_num = [0 for _ in range(H)]
for i in range(H-1):
if cut_yoko_pattern[i] == "1":
box_num[i+1] = box_num[i] + 1
else:
box_num[i+1] = box_num[i]
tate_cut_num = 0
for j in range(W):
temp_boxs = [0 for _ in range(yoko_cut_num+1)]
for i in range(H):
if Ss[i][j] == 1:
temp_boxs[box_num[i]] += 1
Impossible = False
Should_cut = False
for i in range(yoko_cut_num+1):
if temp_boxs[i] > K:
Impossible = True
elif boxs[i] + temp_boxs[i] > K:
Should_cut = True
if Impossible == True:
break
elif Should_cut ==True:
boxs = copy.deepcopy(temp_boxs)
tate_cut_num += 1
else:
for i in range(yoko_cut_num+1):
boxs[i] += temp_boxs[i]
else:
if tate_cut_num+yoko_cut_num < answer:
answer = tate_cut_num + yoko_cut_num
print(answer)
|
import math
H, W, K = map(int, input().split())
S = [list(map(lambda x: int(x=='1'), input())) for _ in range(H)]
def cal_min_vert_div(hs):
cnt = 0
n_h_div = len(hs)
n_white = [0]*n_h_div
for i in range(W):
for j in range(n_h_div):
n_white[j] += hs[j][i]
if n_white[j] > K:
n_white = [hs[k][i] for k in range(n_h_div)]
cnt += 1
if max(n_white)>K:
return math.inf
break
return cnt
ans = math.inf
for mask in range(2**(H-1)):
hs = []
tmp = S[0]
for i in range(H-1):
if mask>>i & 1:
hs.append(tmp)
tmp = S[i+1]
else:
tmp = [tmp[w]+S[i+1][w] for w in range(W)]
hs.append(tmp)
tmp = cal_min_vert_div(hs)+sum(map(int, bin(mask)[2:]))
ans = min(ans, tmp)
print(ans)
| 1 | 48,450,957,330,870 | null | 193 | 193 |
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
DP = [i for i in range(n + 1)]
for cost in c:
for i in range(cost, n + 1):
DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[n])
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, *a = map(int, read().split())
a.sort()
a = tuple(a)
TorF = [0] * (a[-1] + 1)
for ae in a:
TorF[ae] = 1
for i1 in range(n - 1):
a1 = a[i1]
if TorF[a1]:
m = a[-1] // a1 + 1
for i2 in range(2, m):
TorF[a1 * i2] = 0
if a[i1 + 1] == a[i1]:
TorF[a[i1]] = 0
r = sum(TorF)
print(r)
if __name__ == '__main__':
main()
| 0 | null | 7,213,931,456,900 | 28 | 129 |
n = int(input())
a = int(n//1.08)
for x in range(a, a+2):
if x < (n + 1)/1.08 and x >= n/1.08:
print(x)
exit()
print(':(')
|
import sys
input = sys.stdin.readline
from collections import *
def bfs(s):
q = deque([s])
dist = [-1]*N
dist[s] = 0
leaf = set()
while q:
v = q.popleft()
flag = True
for nv in G[v]:
if dist[nv]==-1:
dist[nv] = dist[v]+1
q.append(nv)
flag = False
if flag:
leaf.add(v)
return dist, leaf
N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
A, B = map(int, input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
d1, _ = bfs(u-1)
d2, leaf = bfs(v-1)
ans = 0
for i in range(N):
if i not in leaf and d1[i]<=d2[i]:
ans = max(ans, d2[i])
print(ans)
| 0 | null | 121,280,710,604,448 | 265 | 259 |
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 00:38:11 2020
@author: liang
"""
"""
<D - Multiple of 2019>
【方針】
a = b(mod2019) => a - b は 2019の倍数
余りが等しいグループの組み合わせの総数が解になる。
既に2019の倍数であるものは単体で成立するため、[0]のカウントを一つあげておく
<累積和>
【計算量削減】
大きな数を使わない ⇒ mod を使う
tmp += 7 * 100000000 => 7 * ( 2019*N + α) => 7 * α と同じ
⇒ 累乗(10**N) に mod をかけると良い
100000000 + γ => (2019*N + β) + γ => β + γ と同じ
⇒ 累積和 に mod をかけると良い
for文で1文字ずつ足し算していくことで実装可能
reversed() : 逆順に並べ替え
reversed(input()) : 入力を逆順に取り出す
"""
S = input()
MOD = 2019
counter = [0] * 2019
counter[0] = 1
t = 1
tmp = 0
for i in reversed(S):
tmp += int(i)*t
tmp %= MOD #累積和を効率化
t *= 10
t %= MOD #累乗を効率化
#print(tmp)
counter[tmp] += 1
ans = sum( i*(i-1)//2 for i in counter)
print(ans)
|
x = int(input())
count_500 = 0
count_5 = 0
count_500 = x // 500
x -= 500 * count_500
count_5 = x // 5
x -= 5 * count_5
print(1000 * count_500 + 5 * count_5)
| 0 | null | 36,804,576,736,992 | 166 | 185 |
n=input()
print(' '.join(map(str,map(int,raw_input().split())[::-1])))
|
n = int(input())
s = input()
ans = n
if n == 1:
print("1")
else:
for i in range(n-1):
if s[i] == s[i+1]:
ans -= 1
print(ans)
| 0 | null | 85,759,590,115,540 | 53 | 293 |
while True:
H,W = map(int, raw_input().split(" "))
if H == 0 and W == 0:
break
else:
for h in xrange(H):
print "#" * W
print ""
|
while True:
x = [int(z) for z in input().split(" ")]
if x[0] == 0 and x[1] == 0: break
for h in range(0,x[0]):
for w in range(0,x[1]):
print("#", end="")
print("\n", end="")
print("")
| 1 | 793,010,331,526 | null | 49 | 49 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.