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
|
---|---|---|---|---|---|---|
a, b, c, d = map(int, input().split())
while a > 0 and c > 0:
a = a - d
c = c - b
if c <= 0:
print('Yes')
else:
print('No')
|
a, b, c, d = map(int,input().split())
t = c//b
if not c % b == 0:
t += 1
o = a//d
if not a % d == 0:
o += 1
if t <= o:
print('Yes')
else:
print('No')
| 1 | 29,923,004,447,324 | null | 164 | 164 |
import math
x = int(input())
for i in range(1,x+1):
if i%3==0:
print(f" {i}",end="")
continue
r=i
while True:
if r<=0:
break
if r%10==3:
print(f" {i}",end="")
break
r//=10
print("")
|
# -*- coding:utf-8 -*-
n = int(input())
for i in range(2,n+1):
a = i // 10
a = a % 10
b = i // 100
b = b % 10
if i % 3 == 0:
print(' ',i,sep='',end='')
elif i % 10 == 3:
print(' ',i,sep='',end='')
elif a == 3:
print(' ',i,sep='',end='')
elif i // 100 == 3:
print(' ',i,sep='',end='')
elif i // 1000 == 3:
print(' ',i,sep='',end='')
elif i // 10000 == 3:
print(' ',i,sep='',end='')
elif b == 3:
print(' ',i,sep='',end='')
print('')
| 1 | 927,192,564,370 | null | 52 | 52 |
# -*- coding:utf-8 -*-
x = int(input())
if x == False:
print("1")
else:
print("0")
|
import math
def main():
mod = 1000000007
N = int(input())
A = list(map(int, input().split()))
A_max = sorted(A)[-1]
if A_max == 0:
print(0)
exit()
bit_max = int(math.ceil(math.log2(A_max)))
i = 0
bit = 1
res = 0
while i <= bit_max:
c_zero = 0
c_one = 0
for j in range(N):
if A[j] & bit == 0:
c_zero += 1
else:
c_one += 1
m_bit = bit % mod
res += m_bit*c_zero*c_one
res %= mod
i += 1
bit<<=1
print(res)
if __name__ == "__main__":
main()
| 0 | null | 63,175,647,679,068 | 76 | 263 |
import sys
from functools import reduce
from operator import xor
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
s = reduce(xor, a)
print(' '.join([str(xor(s, i)) for i in a]))
|
def main():
N = int(input())
A = list(map(int, input().split()))
xor = 0
for a in A:
xor ^= a
ans = [xor ^ a for a in A]
print(*ans)
if __name__ == "__main__":
main()
| 1 | 12,518,054,601,636 | null | 123 | 123 |
n,k = map(int,input().split())
a = list(map(int,input().split()))#消化コスト
f = list(map(int,input().split()))#食べにくさ
a.sort(reverse = True)
f.sort()
top = 10**13
bot = -1
def ok(x):
res = 0
for i in range(n):
res += max(0,a[i] - (x//f[i]))
return res <=k
while top - bot > 1:
mid = (top + bot) //2
if ok(mid):top = mid
else:bot = mid
print(top)
|
data_num = int(input())
cnt = 0
deff_price = -999999999
min_price = 0
tmp_price = 0
for i in range(data_num):
price = int(input())
if i ==0:
min_price = price
elif price - min_price > deff_price:
deff_price = price - min_price
if price < min_price:
min_price = price
print(str(deff_price))
| 0 | null | 82,467,837,606,712 | 290 | 13 |
MOD = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
DP = [[0] * (1 + S) for _ in range(1 + N)] # DP[i][j] はi番目までみた時に総和がjと成る組み合わせの総和
# 初期化
DP[0][0] = 1
# 漸化式 DP[i][j] = DP[i-1][j]*2 + DP[i-1][j-A[i]]
for i in range(1, N + 1):
for j in range(S + 1):
if j >= A[i - 1]:
DP[i][j] = DP[i - 1][j] * 2 + DP[i - 1][j - A[i - 1]]
else:
DP[i][j] = DP[i - 1][j] * 2
DP[i][j] %= MOD
print(DP[N][S])
|
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=998244353
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
N,S=map(int,input().split())
A=tuple(map(int,input().split()))
dp=[[0]*3001 for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
for j in range(3001):
dp[i+1][j]+=dp[i][j]*2
dp[i+1][j]%=MOD
if j-A[i]>=0:
dp[i+1][j]+=dp[i][j-A[i]]
dp[i+1][j]%=MOD
print(dp[-1][S])
| 1 | 17,724,162,216,732 | null | 138 | 138 |
a = int(input())
c=0
for i in range(a + 1):
if bool(i%3!=0 and i % 5 != 0):
c += i
print(c)
|
N = int(input())
sum = 0
if (1 <= N and N <= 10 ** 6):
for i in range(1,N + 1):
if ( i % 3 == 0) and ( i % 5 == 0):
#if i % 15 ==0:
N = 'Fizz Buzz'
elif i % 3 == 0:
N = 'Fizz'
elif i % 5 == 0:
N = 'Buzz'
else:
sum += i
print(sum)
| 1 | 34,812,426,079,640 | null | 173 | 173 |
# -*- coding: utf-8 -*-
"""
Created on Thu May 7 00:03:02 2020
@author: shinba
"""
L = int(input())
L = L/3
print(L**3)
|
L=float(input())
print((L/3)**3)
| 1 | 47,235,346,941,380 | null | 191 | 191 |
s=input()
q=int(input())
mae=""
usr=""
flg=True
for i in range(q):
a=list(map(str,input().split()))
if a[0]=="1":
if flg:
flg=False
elif flg==False:
flg=True
if a[0]=="2":
if a[1]=="1":
if flg:
mae=a[2]+mae
else:
usr=usr+a[2]
if a[1]=="2":
if flg:
usr=usr+a[2]
else:
mae=a[2]+mae
if flg:
ans=mae+s+usr
else:
ans=usr[::-1]+s[::-1]+mae[::-1]
print(ans)
|
s = list(input())
q = int(input())
before = []
after = []
cnt = 0
for i in range(q):
t = list(input().split())
if t[0] == "1":
cnt += 1
else:
f = t[1]
c = t[2]
if f == "1":
if cnt%2 == 0:
before.append(c)
else:
after.append(c)
else:
if cnt%2 == 0:
after.append(c)
else:
before.append(c)
if cnt%2 == 1:
s.reverse()
after.reverse()
#before.reverse()
for i in after:
print(i,end = "")
for i in s:
print(i,end = "")
for i in before:
print(i,end = "")
else:
before.reverse()
before.extend(s)
before.extend(after)
for i in before:
print(i,end = "")
| 1 | 57,190,568,505,602 | null | 204 | 204 |
from collections import defaultdict
n = int(input())
dic = defaultdict(lambda: 0)
for _ in range(n):
com = input().split(' ')
if com[0]=='insert':
dic[com[1]] = 1
else:
if com[1] in dic:
print('yes')
else:
print('no')
|
n = int(input())
d = {}
for i in range(n):
order = input().split()
if order[0] == 'insert':
d[order[1]] = i
else:
if order[1] in d:
print("yes")
else:
print("no")
| 1 | 77,583,888,580 | null | 23 | 23 |
# -*- coding: utf-8 -*-
import sys
import os
import math
n = int(input())
p0 = (0, 0)
p1 = (100, 0)
def koch(depth, p0, p1):
if depth == 0:
return
# s = 2/3 p0 + 1/3 p1
sx = 2 / 3 * p0[0] + 1 / 3 * p1[0]
sy = 2 / 3 * p0[1] + 1 / 3 * p1[1]
s = (sx, sy)
tx = 1 / 3 * p0[0] + 2 / 3 * p1[0]
ty = 1 / 3 * p0[1] + 2 / 3 * p1[1]
t = (tx, ty)
theta = math.radians(60)
ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx
uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy
u = (ux, uy)
# ????????? s, u, t?????¨???
koch(depth - 1, p0, s)
print(*s)
koch(depth - 1, s, u)
print(*u)
koch(depth - 1, u, t)
print(*t)
koch(depth - 1, t, p1)
print(*p0)
koch(n, p0, p1)
print(*p1)
|
import math
import collections
N = int(input())
Point = collections.namedtuple('Point', ['x', 'y'])
def koch(d, p1, p2):
if d == 0:
return
th = math.pi * 60 / 180
s = Point(x=(2 * p1.x + p2.x) / 3, y=(2 * p1.y + p2.y) / 3)
t = Point(x=(p1.x + 2 * p2.x) / 3, y=(p1.y + 2 * p2.y) / 3)
u = Point(x=(t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x,
y=(t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y)
koch(d - 1, p1, s)
print('{:.8f} {:.8f}'.format(s.x, s.y))
koch(d - 1, s, u)
print('{:.8f} {:.8f}'.format(u.x, u.y))
koch(d - 1, u, t)
print('{:.8f} {:.8f}'.format(t.x, t.y))
koch(d - 1, t, p2)
p1 = Point(x=0, y=0)
p2 = Point(x=100, y=0)
print('{:.8f} {:.8f}'.format(p1.x, p1.y))
koch(N, p1, p2)
print('{:.8f} {:.8f}'.format(p2.x, p2.y))
| 1 | 130,470,222,868 | null | 27 | 27 |
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
else:
max_list = []
for _ in s:
max_list.append(ord(_))
for i in range(ord("a"),max(max_list) + 2):
s = s + chr(i)
dfs(s)
s = s[:len(s) - 1]
dfs("a")
|
def main():
from string import ascii_lowercase
dic = {i: s for i, s in enumerate(ascii_lowercase)}
N = int(input())
ans = []
def dfs(s, mx):
if len(s) == N:
ans.append(s)
return
else:
for i in range(mx+2):
mx = max(mx, i)
dfs(s + dic[i], mx)
dfs("a", 0)
print(*ans, sep="\n")
if __name__ == '__main__':
main()
| 1 | 52,335,318,283,250 | null | 198 | 198 |
import math
a, b, h, m = map(int, input().split())
ang = h * 30 - m * 5.5
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ang)))
print(ans)
|
import math
a, b, h, m = map(int, input().split())
rad_a = 2 * math.pi / 720 * (60 * h + m)
rad_b = 2 * math.pi / 60 * m
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(rad_a - rad_b))
print("{:.20f}".format(ans))
| 1 | 20,267,592,628,240 | null | 144 | 144 |
import sys
sys.setrecursionlimit(10 ** 9)
# 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 MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): 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, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
S = list(map(int, LS()))
S = S[::-1]
ln = len(S)
mod = 2019
times = 1
for i in range(ln):
S[i] = S[i] * times
times = times * 10 % mod
R = [0] * (ln+1)
memo = {0: 1}
ans = 0
for i in range(1, ln+1):
tmp = (R[i-1] + S[i-1]) % mod
R[i] = tmp
cnt = memo.get(tmp, 0)
ans = ans + cnt
memo[tmp] = cnt + 1
print(ans)
if __name__ == '__main__':
solve()
|
from collections import Counter
n=input()[::-1]
A=[0]
num,point=0,1
for i in n:
num +=int(i)*point
num %=2019
A.append(num)
point *=10
point %=2019
count=Counter(A)
ans=0
for i,j in count.items():
if j>=2:ans +=j*(j-1)//2
print(ans)
| 1 | 30,683,601,899,648 | null | 166 | 166 |
n, x, m = map(int, input().split())
ans = []
flag = False
for i in range(n):
if x in ans:
v = x
flag = True
break
ans.append(x)
x = x**2 % m
if flag:
p = ans.index(v)
l = len(ans) - p
d, e = divmod(n-p, l)
print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e]))
else:
print(sum(ans))
|
n, x, m = map(int, input().split())
X = [-1] * m
P = []
sum_p = 0
while X[x] == -1: # preset
X[x] = len(P) # pre length
P.append(sum_p) # pre sum_p
sum_p += x # now sum_p
x = x*x % m
P.append(sum_p) # full sum_p
p_len = len(P) - 1
if n <= p_len:
print(P[n]) # sum_p
exit()
cyc_times, nxt_len = divmod(n - X[x], p_len - X[x])
cyc = (sum_p - P[X[x]]) * cyc_times
remain = P[X[x] + nxt_len]
print(cyc + remain)
| 1 | 2,833,301,625,638 | null | 75 | 75 |
from sys import stdin
from itertools import permutations
n = int(stdin.readline().strip())
rank = dict([(val, i) for i, val in enumerate(sorted([int(''.join([str(v) for v in l])) for l in permutations(list(range(1, n+1)), n)])[::-1])])
p_rank = rank[int(''.join(stdin.readline().split()))]
q_rank = rank[int(''.join(stdin.readline().split()))]
print(abs(p_rank - q_rank))
|
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
l = []
for i in range(1,N+1):
l.append(i)
tmp = sorted(list(itertools.permutations(l)))
p = tmp.index(P)
q = tmp.index(Q)
print(abs(p-q))
| 1 | 100,164,474,260,230 | null | 246 | 246 |
h, a = list(map(int, input().split()))
b = h/a
if int(b) == b:
print(int(b))
else:
print(int(b)+1)
|
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
H,A = LI()
print(int(H/A) if H%A==0 else int(H/A+1))
main()
| 1 | 77,085,175,423,070 | null | 225 | 225 |
ri = lambda S: [int(v) for v in S.split()]
S = [ri(input()) for _ in range(3)]
N = int(input())
D = set()
O = set()
def mark(A, v):
for i in range(3):
for j in range(3):
if A[i][j] != 0 and A[i][j] == v:
A[i][j] = 0
if (i, j) in [(0, 0), (1, 1), (2,2)]:
D.add((i,j))
if (i, j) in [(0, 2), (1, 1), (2, 0)]:
O.add((i, j))
for _ in range(N):
b = int(input())
mark(S, b)
R = [sum(r) for r in S]
C = [sum(r) for r in zip(*S)]
check = len(D) == 3 or len(O) == 3 or any(v == 0 for v in R) or any(v == 0 for v in C)
print("Yes" if check else "No")
|
A=[]
for _ in range(3):
A+=map(int,input().split())
N=int(input())
for _ in range(N):
b=int(input())
if b in A:
A[A.index(b)]=0
for i,j,k in [
(0,1,2),(3,4,5),(6,7,8),
(0,3,6),(1,4,7),(2,5,8),
(0,4,8),(2,4,6),
]:
if A[i]==A[j]==A[k]:
print('Yes')
break
else:
print('No')
| 1 | 59,894,161,830,592 | null | 207 | 207 |
a = int(input())
print(1-a)
|
print(1 - (int(input())))
| 1 | 2,920,408,889,060 | null | 76 | 76 |
def factorization(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
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def f(n):
for i in range(50,-1,-1):
if n>=(i*(i+1)//2):
return i
break
n=int(input())
cnt=0
alist=factorization(n)
for i in range(len(alist)):
cnt+=f(alist[i][1])
if n==1:
cnt=0
print(cnt)
|
import math , sys
def fac(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
temp //= i
arr.append(cnt)
if temp!=1:
arr.append(1)
if arr==[]:
arr.append(1)
return arr
def sta ( x ):
return int( 0.5* (-1 + math.sqrt(1+8*x)))
N = int( input() )
if N == 1:
print(0)
sys.exit()
if N == 2 or N ==3:
print(1)
sys.exit()
Is = fac( N )
ans = sum( [ sta(j) for j in Is])
print(max(ans,1))
| 1 | 17,002,026,605,532 | null | 136 | 136 |
a,b=input().split();print([b*int(a),a*int(b)][a<b])
|
a,b = map(int,input().split())
word = ""
for i in range(max(a,b)):
word += str(min(a,b))
print(word)
| 1 | 84,590,439,583,090 | null | 232 | 232 |
import sys
# \n
def input():
return sys.stdin.readline().rstrip()
def train(X, Y, T): # O(N) ans: 回数
ans = 0
for i in range(len(X)):
ans += max(0, X[i] - T // Y[i])
return ans
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True) # 0(NlogN)
F.sort() # O(NlogN)
t =A[0]*(10**6)
if K>=t:
print(0)
exit()
ok = t+1 #時間
ng = -1
# O(Nlog(maxK)?)
while ok - ng > 1:
mid = (ok + ng) // 2 #時間
ans = train(A,F,mid) #kaisuu
if ans >K:
ng =mid
else:
ok =mid
print(ok)
if __name__ == "__main__":
main()
|
n = int(input())
x = [int(i) for i in input().split()]
hp = []
for p in range(min(x), max(x)+1):
sum = 0
for i in x:
sum = sum + (i-p)**2
hp.append(sum)
print(min(hp))
| 0 | null | 114,563,916,907,790 | 290 | 213 |
import sys
def value(w,n,P):
tmp_w = 0
k = 1
for i in range(n):
if tmp_w + w[i] <= P:
tmp_w += w[i]
else:
tmp_w = w[i]
k += 1
return k
def test():
inputs = list(map(int,sys.stdin.readline().split()))
n = inputs[0]
k = inputs[1]
w = []
max = 0
sum = 0
for i in range(n):
w.append(int(sys.stdin.readline()))
if w[i] > max:
max = w[i]
sum += w[i]
while max != sum:
mid = (max + sum) // 2
if value(w,n,mid) > k:
max = mid + 1
else:
sum = mid
print(max)
if __name__ == "__main__":
test()
|
import sys
from math import gcd
def input(): return sys.stdin.readline().strip()
def main():
N = int(input())
A =list(map(int, input().split()))
all_gcd = A[0]
max_num = A[0]
for a in A:
all_gcd = gcd(all_gcd, a)
max_num = max(max_num, a)
if all_gcd != 1:
print("not coprime")
return
# エラトステネスの篩でmin_prime[i] = (iを割り切る最小の素数)を記録する
min_prime = [i for i in range(max_num + 1)]
for p in range(2, int(max_num**0.5) + 1):
if min_prime[p] != p: continue
for i in range(2 * p, max_num + 1, p): min_prime[i] = p
# Aの要素で出てきた素因数をusedに記録
used = [0] * (max_num + 1)
for a in A:
while a > 1:
p = min_prime[a]
if used[p]:
print("setwise coprime")
return
while a % p == 0: a //= p
used[p] = 1
print("pairwise coprime")
if __name__ == "__main__":
main()
| 0 | null | 2,112,560,518,980 | 24 | 85 |
a=list(map(int,input().split()))
if a[0]>a[1]*2:
print(a[0]-a[1]*2)
else:
print('0')
|
n=int(input())
a=list(map(int,input().split()))
m=len(a)
a=set(a)
n=len(a)
if m==n:
print("YES")
else:
print("NO")
| 0 | null | 120,331,534,477,000 | 291 | 222 |
a,b,c= map(int,input().split())
if c>a+b and 4*a*b<(c-a-b)*(c-a-b):
print('Yes')
else:
print('No')
|
from decimal import Decimal
a,b,c = map(str,input().split()) # Decimalを使う場合,文字列で渡す
a_sq = Decimal(a).sqrt()
b_sq = Decimal(b).sqrt()
c_sq = Decimal(c).sqrt()
if a_sq + b_sq < c_sq:
print("Yes")
else:
print("No")
| 1 | 51,679,654,413,560 | null | 197 | 197 |
s = "#."
while True:
H,W= map(int, input().split())
if H==0 and W==0:
break
elif W%2==0 :
w1=s*(W//2)
w2="."+s*(W//2-1)+"#"
elif W%2==1:
w1=s*((W-1)//2)+"#"
w2="."+s*((W-1)//2)
for i in range(H):
if i%2==0:
print(w1)
elif i%2==1:
print(w2)
print("")
|
import sys
for i in sys.stdin.readlines():
nums = list(map(int,i.split()))
h = nums[0]
w = nums[1]
if h == 0 and w == 0:
break
for j in range(1,h+1):
if h == 1 and w == 1:
print("#")
elif j % 2 == 1:
if w % 2 == 1:
x = int((w-1)/2)
print("#."*x +"#")
else:
x = int(w/2)
print("#."*x)
elif j % 2 == 0:
if w % 2 == 1:
x = int((w-1)/2)
print(".#"*x +".")
else:
x = int(w/2)
print(".#"*x)
print("")
| 1 | 862,804,588,448 | null | 51 | 51 |
import sys
s = input()
if s[2] == s[3] and s[4] == s[5]:
print("Yes")
sys.exit()
print("No")
|
co ="coffee"
S = input()
if S[2]!=S[3]:
print("No")
elif S[4]!=S[5]:
print("No")
else:
print("Yes")
| 1 | 42,188,929,105,808 | null | 184 | 184 |
S = input()
n = len(S) + 1
A = []
mini = 0
for i in range(n-1):
if i==0:
if S[i]=="<":
A.append([1,0])
else:
A.append([0,1])
else:
if S[i]=="<" and S[i-1]==">":
A.append([1,0])
elif S[i]=="<":
A[-1][0] += 1
else:
A[-1][1] += 1
summ = 0
for x in A:
ma = max(x)
mi = min(x)
summ += (ma+1)*ma//2
summ += (mi-1)*mi//2
print(summ)
|
S = list(input())
T = list(input())
L = len(S)
i = 0
cn = 0
N = 200000
while i < L:
if S[i] != T[i]:
i = i + 1
cn = cn + 1
else:
i = i + 1
print(cn)
| 0 | null | 83,410,170,808,290 | 285 | 116 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
height, width = map(int, raw_input().split())
print("%d %d") % (height * width, (height + width) * 2)
|
# coding: utf-8
a, b = map(int, input().split(' '))
menseki = a * b
print(menseki, a*2 + b*2)
| 1 | 301,288,550,412 | null | 36 | 36 |
from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for i, bi in enumerate(BIT, 1):
if bi == 1:
LIST.append(tmp)
tmp = s[i]
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, s[i])]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
CNT, tmp = 0, [li[0] for li in LIST]
if any(num > k for num in tmp):
return h * w
for j in range(1, w):
cal = [t + li[j] for t, li in zip(tmp, LIST)]
if any(num > k for num in cal):
CNT += 1
tmp = [li[j] for li in LIST]
else:
tmp = cal
return CNT
h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
|
def solve():
N = int(input())
S, T = map(str, input().split())
ans = ""
for i in range(N): ans += S[i] + T[i]
print(ans)
if __name__ == "__main__":
solve()
| 0 | null | 80,253,423,782,148 | 193 | 255 |
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 % mod)
self.i.reverse()
def factorial(self, j):
return self.f[j]
def ifactorial(self, j):
return self.i[j]
def comb(self, n, k):
return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
N, K = map(int, input().split())
K = min(K, N - 1)
F = Factorial(N + 1, MOD)
ans = 0
for k in range(K + 1):
tmp = F.comb(N, k) * F.factorial(N - 1) * F.ifactorial(N - 1 - k) * F.ifactorial(k)
ans += (tmp % MOD)
ans %= MOD
print (ans)
|
import sys,math,collections,itertools
input = sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
xa=a[0]
for i in range(1,len(a)):
xa ^= a[i]
b = []
for ai in a:
b.append(xa^ai)
print(*b)
| 0 | null | 39,864,839,082,046 | 215 | 123 |
def comb(n, k, mod):
m = 1
for i in range(n, n - k, -1):
m = m * i % mod
n = 1
for i in range(1, k + 1):
n = n * i % mod
return (m * pow(n, mod - 2, mod) % mod)
def main():
mod = 1000000007
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)
ans = ans % mod
print(ans)
if __name__ == '__main__':
main()
|
k = int(input())
s = input()
lists = list(s)
news = list()
if len(lists) <= k:
print(s)
else:
for i in range(k):
news.append(lists[i])
result = "".join(news)
print(result + "...")
| 0 | null | 42,869,652,668,190 | 214 | 143 |
import math
a,b,c = [float(s) for s in input().split()]
r = c * math.pi / 180
h = math.sin(r) * b
s = a * h / 2
x1 = a
y1 = 0
if c == 90:
x2 = 0
else:
x2 = math.cos(r) * b
y2 = h
d = math.sqrt((math.fabs(x1 - x2) ** 2) + (math.fabs(y1 - y2) ** 2))
l = a + b + d
print(s)
print(l)
print(h)
|
import math
a, b, C = map(float, input().split())
S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + (math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))
h = b * math.sin(math.radians(C))
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 1 | 178,402,566,472 | null | 30 | 30 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n, m = map(int, input().split())
graph = [0] + [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
from collections import deque
def bfs(graph, queue, dist, prev):
while queue:
current = queue.popleft()
for _next in graph[current]:
if dist[_next] != -1:
continue
else:
dist[_next] = dist[current] + 1
prev[_next] = current
queue.append(_next)
queue = deque([1])
dist = [0] + [-1] * n
prev = [0] + [-1] * n
dist[1] = 0
bfs(graph, queue, dist, prev)
if -1 in dist:
print('No')
else:
print('Yes')
for v in prev[2:]:
print(v)
|
n, m = map(int, input().split())
route = [[] for _ in range(n+1)]
ans = [0]*n
for _ in range(m):
a, b = map(int, input().split())
route[a].append(b)
route[b].append(a)
q = [1]
l = set()
while True:
if len(q) == 0:
break
p = q.pop(0)
for i in route[p]:
if i not in l:
l.add(i)
ans[i-1] = p
q.append(i)
if ans.count(0) > 1:
print("No")
else:
print("Yes")
for i in range(1, n):
print(ans[i])
| 1 | 20,442,329,329,020 | null | 145 | 145 |
def solve():
N = int(input())
cnt = [[0]*10 for i in range(10)]
for i in range(1, N+1):
target_str = str(i)
cnt[int(target_str[0])][int(target_str[-1])] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += cnt[i][j] * cnt[j][i]
print(ans)
if __name__ == "__main__":
solve()
|
a = ""
while True:
try:
a += input().lower()
except:
break
for i in range(ord("a"), ord("z")+1):
print("{} : {}".format(chr(i), a.count(chr(i))))
| 0 | null | 43,896,703,053,258 | 234 | 63 |
X, Y = map(int, input().split())
temp = [0, 300000, 200000, 100000]
ans = 0
if X == Y == 1:
ans += 400000
if X <= 3:
ans += temp[X]
if Y <= 3:
ans += temp[Y]
print(ans)
|
x,y = map(int,input().split())
s = max(0,(4-x)*100000)+max(0,(4-y)*100000)
print(s if s!=600000 else s+400000)
| 1 | 140,834,249,542,402 | null | 275 | 275 |
def solve():
N, K, C = map(int, input().split())
S = input()
l_r,r_l = [0]*N,[0]*N
i,cnt = 0,0
while i<N and cnt<K:
if S[i]=='o':
l_r[i] = 1
cnt += 1
i += C
i += 1
j,cnt = N-1,0
while j>=0 and cnt<K:
if S[j]=='o':
r_l[j] = 1
cnt += 1
j -= C
j -= 1
ans = []
c_lr = 0
c_rl = 0
for i in range(1,N+1):
if l_r[i-1]:
c_lr += 1
if r_l[i-1]:
c_rl += 1
if l_r[i-1]*r_l[i-1]==1 and c_lr==c_rl:
ans.append(i)
return ans
print(*solve(),sep='\n')
|
def main():
cands = {'ABC', 'ARC'}
S = input()
cands.discard(S)
print(cands.pop())
if __name__ == '__main__':
main()
| 0 | null | 32,354,590,300,502 | 182 | 153 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,r = map(int, input().split())
if n >= 10:
ans = r
else:
ans = r + 100*(10-n)
print(ans)
|
n,m = map(int,input().split())
ans = 0
for i in range(n-1):
ans = ans + i+1
for b in range(m-1):
ans = ans + b+1
print(ans)
| 0 | null | 54,238,876,070,898 | 211 | 189 |
from collections import Counter
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if D[0] != 0 or cnt_D.get(0, 0) != 1:
print(0)
else:
prev = 1
ans = 1
for i in range(1, max(D) + 1):
v = cnt_D.get(i, 0)
ans *= pow(prev, v, MOD)
ans %= MOD
prev = v
print(ans)
|
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
print(0)
exit()
l[d[i]]+=1
mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
ans *= t**l[i]
t=l[i]
print(ans%998244353)
| 1 | 155,092,067,518,980 | null | 284 | 284 |
N, M = (int(x) for x in input().split())
print(int(N*(N-1)/2 + M*(M-1)/2))
|
n,m=map(int,input().split())
i=0
i+=n*(n-1)/2
i+=m*(m-1)/2
print(int(i))
| 1 | 45,448,364,931,708 | null | 189 | 189 |
n = int(input())
print(len(set([input() for i in range(n)])))
|
import math
print(int(math.ceil(int(input())/2)-1))
| 0 | null | 91,986,746,317,730 | 165 | 283 |
import math
T_1, T_2 = map(int, input().split())
A_1, A_2 = map(int, input().split())
B_1, B_2 = map(int, input().split())
ans = 0
if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2:
print("infinity")
else:
# 速いほうをAと仮定
if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2:
A_1, A_2, B_1, B_2 = B_1, B_2, A_1, A_2
if A_1 < B_1:
sa_12 = T_1 * A_1 + T_2 * A_2 - (T_1 * B_1 + T_2 * B_2) # 1サイクルでできる差
sa_1 = -T_1 * A_1 + T_1 * B_1 # T_1でできる差
if sa_1 % sa_12 == 0:
ans = int((sa_1 / sa_12)*2)
else:
kari = math.ceil(sa_1 / sa_12)
ans = (kari-1)*2+1
print(ans)
|
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")
D, T, S = map(int, input().split())
if D / S > T:
print("No")
else:
print("Yes")
| 0 | null | 67,334,399,177,792 | 269 | 81 |
class AlgUnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n #各要素の親要素の番号を格納するリスト 要素が根(ルート)の場合は-(そのグループの要素数)を格納する
def find(self, x): #要素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が属するグループと要素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): #要素xが属するグループのサイズ(要素数)を返す
return -self.parents[self.find(x)]
def same(self, x, y): #要素x, yが同じグループに属するかどうかを返す
return self.find(x) == self.find(y)
def members(self, x): #要素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): #print()での表示用 ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
if __name__ == "__main__":
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
for j in range(M):
A[j][0] -= 1
A[j][1] -= 1
uf = AlgUnionFind(N)
for i in range(M):
uf.union(A[i][0], A[i][1])
count = uf.group_count() - 1
print(count)
|
import sys
INF = 1 << 60
MOD = 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
ward = 96
n, s = map(int, input().split())
mask = int(('1' * 32 + '0' * 64) * (s + 1) , 2)
Mask = (1 << (s + 1) * ward) - 1
dp = 1
for a in map(int, input().split()):
dp = (dp * 2) + (dp << ward * a)
dp &= Mask
dp = (dp & (~mask)) + ((dp & mask) >> 64) * ((1 << 64) % MOD)
print(((dp >> s * ward) & ((1 << ward) - 1)) % MOD)
resolve()
| 0 | null | 9,971,642,114,698 | 70 | 138 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import deque
import bisect
from decimal import *
def main():
a, b, c, d = MI()
print(max(a * c, b * d, a * d, b * c))
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
a, b, c, d = list(map(int, input().split()))
return a, b, c, d
def main(a: int, b: int, c: int, d: int) -> None:
"""
メイン処理.
Args:\n
a (int): 整数(-10**9 <= a <= b <= 10**9)
b (int): 整数(-10**9 <= a <= b <= 10**9)
c (int): 整数(-10**9 <= c <= d <= 10**9)
d (int): 整数(-10**9 <= c <= d <= 10**9)
"""
# 求解処理
ans = max([a * c, a * d, b * c, b * d])
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
a, b, c, d = get_input()
# メイン処理
main(a, b, c, d)
| 1 | 3,069,608,864,070 | null | 77 | 77 |
from sys import stdin
X = [ 0 for i in range(100) ]
d = [ 0 for i in range(100) ]
f = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]
t = 0
def DFS(i) :
global t
t += 1
d[i] = t
for j in range(n) :
if G[i][j] != 0 and d[j] == 0 : DFS(j)
t += 1
f[i] = t
n = int(input())
for i in range(n) :
X[i] = stdin.readline().strip().split()
for i in range(n) :
for j in range(int(X[i][1])) :
G[int(X[i][0])-1][int(X[i][j+2])-1] = 1
for i in range(n) :
if d[i] == 0 : DFS(i)
for i in range(n) : print(i+1,d[i],f[i])
|
d = int(input())
c = list(map(int,input().split()))
s = [0]*d
for i in range(d):
s[i] = list(map(int,input().split()))
lis = [0]*26
sum_score = 0
for i in range(d): #d日全てに対して
ans = -float("Inf")
num = 0
for j in range(26): #i日目にj番目を選んだ時の得点を計算
score = 0
score += s[i][j]
for k in range(26):
if k != j:
score -= (lis[k]+1)*c[k]
if score > ans:
ans = score
num = j
sum_score += ans
#print(sum_score)
print(num+1)
for j in range(26):
if j != num:
lis[j] += 1
else:
lis[j] = 0
#print(lis)
| 0 | null | 4,841,007,512,192 | 8 | 113 |
import math
case_num = 0
N = int(input())
for num in range(N - 1):
num += 1
case_num += ( math.ceil(N / num) - 1 )
print(case_num)
|
from collections import Counter
n = int(input())
if n == 1:
print(0)
else:
lis = [i for i in range(n+1)]
for i in range(2, int(n**0.5) + 1):
if lis[i] == i:
lis[i] = i
for j in range(i**2, n+1, i):
if lis[j] == j:
lis[j] = i
#print(lis)
def bunkai(m):
ans = []
now = lis[m]
cnt = 1
for i in range(m):
m = m//lis[m]
if now == lis[m]:
cnt += 1
else:
ans.append(cnt)
cnt = 1
now = lis[m]
if m == 1:
break
return ans
ans = 1
for i in range(2,n):
tmp = 1
yaku = bunkai(i)
for i in yaku:
tmp *= (i +1)
ans += tmp
print(ans)
| 1 | 2,595,411,832,690 | null | 73 | 73 |
s,t = map(str,input().split())
ts = [t,s]
print("".join(ts))
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
from collections import Counter
def main():
n = int(input())
p = list(map(int, input().split()))
min = p[0]
cnt = 0
for i in p:
if i <= min:
cnt += 1
min = i
else:
pass
print(cnt)
if __name__=="__main__":
main()
| 0 | null | 94,409,463,965,908 | 248 | 233 |
n = int(input())
a = list(map(int, input().split()))
ans = 0
tmp = a[0]
for i in range(1,n):
tmp = max(a[i], tmp)
ans += tmp - a[i]
print(ans)
|
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
def main():
n, *a = map(int, read().split())
r = 0
maxtall = a[0]
for i1 in range(1, n):
if a[i1] > maxtall:
maxtall = a[i1]
else:
r += maxtall - a[i1]
print(r)
if __name__ == '__main__':
main()
| 1 | 4,596,920,854,962 | null | 88 | 88 |
a=input()
print(a+"e"*(a[-1]=='s')+'s')
|
# coding: utf-8
#Name: List of Top 3 Hills
#Level: 1
#Category: ????????????
#Note:
s = [int(raw_input()) for i in range(10)]
s.sort()
for i in range(3):
print s[9-i]
| 0 | null | 1,187,323,986,276 | 71 | 2 |
A = [[int(x) for x in input().split()] for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
Bingo = [[0, 0, 0] for _ in range(3)]
for i in range(3):
for j in range(3):
for l in range(N):
if(A[i][j] == b[l]):
Bingo[i][j] = 1
bingo = 0
for i in range(3):
if(Bingo[i][0]+Bingo[i][1]+Bingo[i][2])==3:
bingo += 1
elif(Bingo[0][i]+Bingo[1][i]+Bingo[2][i])==3:
bingo += 1
if(Bingo[0][0]+Bingo[1][1]+Bingo[2][2])==3:
bingo += 1
elif(Bingo[0][2]+Bingo[1][1]+Bingo[2][0])==3:
bingo += 1
if(bingo!=0):
print('Yes')
else:
print('No')
|
import numpy as np
A=[]
for i in range(3):
A.append(list(map(int,input().split())))
A=np.array(A)
n=int(input())
for i in range(n):
b=int(input())
if b in A:
A=np.where(A==b,0,A)
cross=0
if A[0][0]+A[1][1]+A[2][2]==0 or A[2][0]+A[1][1]+A[0][2]==0:
cross=1
print("NYoe s"[0 in np.sum(A,axis=0) or 0 in np.sum(A,axis=1) or cross ::2])
| 1 | 59,894,190,151,840 | null | 207 | 207 |
ABC = list(map(int,input().split()))
red = ABC[0]
green = ABC[1]
blue = ABC[2]
K = int(input())
for i in range(K):
if green <= red:
green *= 2
continue
elif blue <= green:
blue *= 2
if green > red and blue > green:
print('Yes')
else:
print('No')
|
a,b,c=map(int,input().split())
K=int(input())
flag=False
for i in range(10):
for j in range(10):
for k in range(10):
if i+j+k<=K and 2**i*a<2**j*b<2**k*c:
flag=True
if flag:
print("Yes")
else:
print("No")
| 1 | 6,829,964,544,062 | null | 101 | 101 |
N,K=map(int,input().split())
H=list(map(int,input().split()))
ans=0
for h in H:
if K<=h:
ans=ans+1
print(ans)
|
mem_num, over_height = map(int, input().split())
members_hgt = list(map(int, input().split()))
cnt = 0
for i in members_hgt:
if i >= over_height:
cnt += 1
print(cnt)
| 1 | 179,241,903,207,654 | null | 298 | 298 |
n = int(input())
d = []
for i in range(n):
a,b = map(int,input().split())
d.append([a,b])
cnt,ans = 0,0
for i in d:
if i[0] == i[1]:
cnt += 1
ans = max(ans,cnt)
else:
cnt = 0
if ans>2:
print("Yes")
else:
print("No")
|
N = int(input())
D = []
for _ in range(N):
D.append([int(x) for x in input().split()])
count = 0
for i in range(N):
if(D[i][0] == D[i][1]):
count +=1
if(count == 3):
break
else:
count = 0
if(count == 3):
print('Yes')
else:
print('No')
| 1 | 2,463,177,535,740 | null | 72 | 72 |
n = int(input())
MOD = 10**9+7
from math import gcd
zero = 0
cnt = {}
for i in range(n):
a,b = map(int,input().split())
if a ==0 and b==0:
zero += 1
continue
g = gcd(a,b)
a//=g
b//=g
if b<0:
a*=-1
b*=-1
if b==0 and a<0:
a *= -1
if a<=0:
a,b = b,-a
if (a,b) in cnt:
cnt[(a,b)][0] += 1
else:
cnt[(a,b)] = [1,0]
else:
if (a,b) in cnt:
cnt[(a,b)][1] += 1
else:
cnt[(a,b)] = [0,1]
ans = 1
for i,v in cnt.items():
ans *= 1 + pow(2,v[0],MOD)-1 + pow(2,v[1],MOD)-1
ans %= MOD
print((zero-1+ans)%MOD)
|
N = int(input())
A = N + N**2 + N**3
print(A)
| 0 | null | 15,538,898,271,104 | 146 | 115 |
x, k, d = map(int, input().split())
if abs(x) >= k * d:
print(abs(x) - k * d)
else:
a = abs(abs(x) - (abs(x) // d) * d)
k -= (abs(x) // d)
if k % 2 == 0:
print(a)
else:
print(abs(a - d))
|
k,n=map(int,input().split())
a=sorted(list(map(int, input().split())))
ans=k+a[0]-a[-1]
for i in range(1,n):
ans=max(ans,a[i]-a[i-1])
print(k-ans)
| 0 | null | 24,234,303,900,788 | 92 | 186 |
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
c=input('')
for a in range(25):
if l[a]==c:
print(l[a+1])
|
S,T=input().split()
print(T+S)
| 0 | null | 97,516,972,374,150 | 239 | 248 |
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
def solve():
N, X, M = it()
if N == 1: return X % M
cur = 0
cnt = 0
value = defaultdict(int)
history = defaultdict(int)
for i in range(N):
if X in history: break
value[X] = cur
history[X] = i
cnt += 1
cur += X
X = X * X % M
loop = cur - value[X]
period = i - history[X]
freq, rem = divmod(N - cnt, period)
cur += freq * loop
for i in range(rem):
cur += X
X = X * X % M
return cur
if __name__ == '__main__':
print(solve())
|
N, X, M = map(int, input().split())
id = [-1] * M
a = []
l = 0
tot = 0
while id[X] == -1:
a.append(X)
id[X] = l
l += 1
tot += X
X = X ** 2 % M
c = l - id[X]
s = 0
for i in range(id[X], l):
s += a[i]
ans = 0
if N <= l:
for i in range(N):
ans += a[i]
else:
ans += tot
N -= l
ans += s * (N // c)
N %= c
for i in range(N):
ans += a[id[X] + i]
print(ans)
| 1 | 2,817,087,648,102 | null | 75 | 75 |
import sys
A, B, K = map(int, input().split())
if A >= K:
A -= K
print(A, B)
sys.exit(0)
else:
K -= A
if B >= K:
B -= K
print(0, B)
sys.exit(0)
else:
print(0, 0)
|
A, B, K = map(int, input().split())
if A >= K:
a = A - K
b = B
else:
if K <= A + B:
a = 0
b = B - (K - A)
else:
a = 0
b = 0
print(a, b)
| 1 | 103,886,272,143,680 | null | 249 | 249 |
S = input()
ans = ''
for s in S:
ans += s.upper() if s.islower() else s.lower()
print(ans)
|
# -*- coding: utf-8 -*-
buf = str(raw_input())
char_list = list(buf)
res = ""
for i in char_list:
if i.isupper():
res += i.lower()
elif i.islower():
res += i.upper()
else:
res += i
print res
| 1 | 1,507,475,656,182 | null | 61 | 61 |
from collections import deque
n,m = map(int, input().split())
dis = [n+2]*(n)
dis[0] = 0
near = [[] for _ in range(n)]
mark = [-1]*(n)
mark[0] = 0
que = deque()
for _ in range(m):
a,b = map(int, input().split())
a -= 1
b -= 1
near[a].append(b)
near[b].append(a)
if a==0:
que.appendleft(b)
mark[b] = 0
dis[b] = 1
if b==0:
que.appendleft(a)
mark[a] = 0
dis[a] = 1
while que:
i = que.popleft()
for j in near[i]:
if dis[i]+1<dis[j]:
dis[j] = dis[i]+1
mark[j] = i
que.append(j)
if n+2 not in dis:
print('Yes')
for i in mark[1:]:
print(i+1)
else:
print('No')
|
MOD = 10 ** 9 + 7
# エラトステネスの篩(コピペ用)
table_len = 1010
prime_list = [] # 必要に応じて
isprime = [True] * (1010)
isprime[0] = isprime[1] = False
for i in range(table_len):
if isprime[i]:
for j in range(2*i, table_len, i):
isprime[j] = False
prime_list.append(i) # 必要に応じて
N = int(input())
As = list(map(int, input().split()))
factor_counts = [0] * len(prime_list)
big_factors = set() # 1000より大きな素数がAの素因数として含まれるとき、その素因数は一乗のみだから
for A in As:
for i, p in enumerate(prime_list):
count = 0
while A % p == 0:
A //= p
count += 1
factor_counts[i] = max(factor_counts[i], count)
if A == 1:
break
else:
big_factors.add(A)
A_lcm = 1
for p, count in zip(prime_list, factor_counts):
A_lcm *= pow(p, count, MOD)
A_lcm %= MOD
for p in big_factors:
A_lcm *= p
A_lcm %= MOD
ans = 0
for A in As:
ans += A_lcm * pow(A, MOD - 2, MOD) % MOD
ans %= MOD
print(ans)
| 0 | null | 53,877,416,110,592 | 145 | 235 |
from decimal import Decimal
a, b = [Decimal(i) for i in input().split()]
print(int(a * b))
|
def main():
A, B = input().split()
A = int(A)
B100 = int(B[0] + B[2:])
print(A*B100//100)
if __name__ == "__main__":
main()
| 1 | 16,680,269,274,538 | null | 135 | 135 |
N = int(input())
sum = N + N**2 + N**3
print(sum)
|
a = int(input())
reslut = pow(a,1) + pow(a,2) + pow(a,3)
print(reslut)
| 1 | 10,276,632,614,544 | null | 115 | 115 |
N, k = map(int, input().split())
dp = [0] * (N+1)
dp[1] = 1
S = []
for i in range(k):
S.append(list(map(int, input().split())))
for i in range(2, N+1):
for l, r in S:
dp[i] += (dp[max(i-l, 0)] - dp[max(i-r-1, 0)])
dp[i] += dp[i-1]
dp[i] %= 998244353
print((dp[N] - dp[N-1])%998244353)
|
while True:
a, b = map(int, input().split())
if(a == 0 and b == 0):
break
for i in range(a):
for j in range(b):
if(0 < i < a-1 and 0 < j < b-1):
print(".", end = "")
else:
print("#", end = "")
print()
print()
| 0 | null | 1,726,132,603,822 | 74 | 50 |
def main():
import sys
input = sys.stdin.readline
N = int(input())
S = input()
import re
num_li = [False]*1000
for i in range(10):
first_ = S.find(str(i),0,N-2)
if first_==-1:
continue
for j in range(10):
second_ = S.find(str(j),first_+1,N-1)
if second_==-1:
continue
for k in range(10):
third_ = S.find(str(k),second_+1,N)
if third_==-1:
continue
num_li[i*100+j*10+k]=True
print(sum(num_li))
if __name__=='__main__':
main()
|
from itertools import product
n = int(input())
s = input()
ans = 0
for a, b, c in product(map(str, range(10)), repeat=3):
ai = s.find(a)
bi = s.find(b, ai + 1)
ci = s.find(c, bi + 1)
if ai != -1 and bi != -1 and ci != -1:
ans += 1
print(ans)
| 1 | 128,547,999,678,202 | null | 267 | 267 |
# coding: UTF-8
from collections import deque
#入力値の整理
n = int(input())
adj={}
visited={}
d={}
f={}
t=0
visited=set()
for i in range(n):
raw=list(map(int,input().split()))
u = raw.pop(0)
k = raw.pop(0)
raw.sort()
q = deque(raw)
adj[u] = q
d[u] = -1
f[u] = -1
next = 1
v = next
d[next] = t + 1
stack = deque()
visited.add(v)
while True:
t = t+1
clear = True
while adj[v]:
cand = adj[v].popleft()
if cand not in visited:
next = cand
d[next] = t + 1
visited.add(next)
clear = False
break
if clear:
f[v] = t + 1
if stack:
next = stack.pop()
v = next
else:
end = True
for i in range(n):
if i+1 not in visited:
next = i+1
end = False
break
if end:
break
else:
t = t+1
v = next
d[next] = t + 1
visited.add(v)
else:
stack.append(v)
v = next
#print
i = 0
for j in range(n):
i += 1
print(str(i) + " " + str(d[i]) + " " + str(f[i]))
#return d,f
|
# -*- coding: utf-8 -*-
def DFS(adj, start):
n = len(adj)
d = [0] * n
f = [0] * n
flag = [0] * n
S = []
time = 1
S.append(start)
flag[start] = 1
d[start] = time
time = time + 1
while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§
if len(S) != 0:
u = S.pop()
v = [i for i, x in enumerate(adj[u]) if (x == 1) and (flag[i] == 0)] # v <= ??£??\???????????????????????¢?´¢??????????????????
if len(v) != 0:
S.append(u)
S.append(v[0])
flag[v[0]] = 1
d[v[0]] = time
time = time + 1
else:
#??£??\??????????????¨????¨??????????
flag[u] = 2
f[u] = time
time = time + 1
else:
u = flag.index(0)
S.append(u)
flag[u] = 1
d[u] = time
time = time + 1
return d, f
def main():
n = int(input())
adj = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
tmp = list(map(int, input().split()))
u = tmp[0]
u = u -1
k = tmp[1]
v = tmp[2:]
for j in range(k):
adj[u][v[j]-1] = 1
d, f = DFS(adj, 0)
for i in range(n):
print(i+1, d[i], f[i])
if __name__ == "__main__":
main()
| 1 | 2,531,704,980 | null | 8 | 8 |
MOD = 998244353
MAX = int(2e5 + 5)
fact = [0] * MAX
invFact = [0] * MAX
def mod_inverse(a):
return pow(a, MOD - 2, MOD)
def pre():
global fact, invFact
fact[0] = 1
for i in range(1, MAX):
fact[i] = (fact[i - 1] * i) % MOD
invFact[MAX - 1] = mod_inverse(fact[MAX - 1])
for i in range(MAX - 2, -1, -1):
invFact[i] = (invFact[i + 1] * (i + 1)) % MOD
def ncr(nn, rr):
if nn < 0 or nn < rr or rr < 0:
return 0
return (fact[nn] * invFact[rr] * invFact[nn - rr]) % MOD
pre()
n, m, k = map(int, input().split())
ans = 0
for i in range(k + 1):
ans = (ans + m * pow(m - 1, n - 1 - i, MOD) * ncr(n - 1, i) ) % MOD
print(ans)
|
A, B, M = map(int, input().split())
a = [int(a) for a in input().split()]
b = [int(b) for b in input().split()]
X = [0] * M
Y = [0] * M
C = [0] * M
for i in range(M):
X[i], Y[i], C[i] = map(int, input().split())
all_prices = []
for x, y, c in zip(X, Y, C):
all_prices.append(a[x-1] + b[y-1] - c)
prices = [min(a) + min(b), min(all_prices)]
print(min(prices))
| 0 | null | 38,784,761,680,772 | 151 | 200 |
count = 1
while True:
x = input().strip()
if x == '0':
break
else:
print('Case %s: %s' %(count, x))
count = count + 1
|
N = int(input())
ans = [0 for _ in range(N+1)]
for x in range(1, 101):
for y in range(x, 101):
for z in range(y, 101):
v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if v < N+1:
if x == y == z:
ans[v] += 1
elif x == y or x == z or z == y:
ans[v] += 3
else:
ans[v] += 6
for i in range(1,N+1):
print(ans[i])
| 0 | null | 4,210,211,090,782 | 42 | 106 |
import math
def main():
hp, attack = (int(i) for i in input().rstrip().split(' '))
print(str(math.ceil(hp / attack)))
if __name__ == '__main__':
main()
|
def main():
h,w,k=map(int,input().split())
grid=[input() for _ in [0]*h]
ans=[[0]*w for _ in [0]*h]
berry=0
for i in range(h):
if "#" in grid[i]:
cnt=0
berry+=1
for j in range(w):
if grid[i][j]=="#":
cnt+=1
if cnt>1:
berry+=1
ans[i][j]=berry
for i in range(1,h):
if ans[i][0]==0:
for j in range(w):
ans[i][j]=ans[i-1][j]
for i in range(h-2,-1,-1):
if ans[i][0]==0:
for j in range(w):
ans[i][j]=ans[i+1][j]
for i in ans:
print(*i)
main()
| 0 | null | 110,436,247,529,722 | 225 | 277 |
def main():
a, b, c = map(int, input().split())
ans = 0
for i in range(a, b + 1):
d = c % i
if d == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
def resolve():
N = int(input())
A = list(map(int, input().split()))
B = A[0]
for i in range(1, N):
B = B^A[i]
ans = []
for i in range(N):
ans.append(B^A[i])
print(*ans)
if __name__ == "__main__":
resolve()
| 0 | null | 6,480,797,573,510 | 44 | 123 |
from math import gcd
k=int(input())
ans=0
for i in range(1,k+1):
for j in range(1,k+1):
ans_=gcd(i,j)
for l in range(1,k+1):
ans+=gcd(ans_,l)
print(ans)
|
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if A > B:
x = A
A = B
B = x
if V <= W:
ans="NO"
elif T*V+A-B >= T*W:
ans="YES"
else:
ans="NO"
print(ans)
| 0 | null | 25,494,578,111,460 | 174 | 131 |
a, b = map(int, input().split())
print(a == b and "Yes" or "No")
|
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools, bisect
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
def main():
N = I()
A = LI()
def lcm(a, b): return a * b // math.gcd(a, b)
l = reduce(lcm, A, 1) % MOD
ans = 0
for ai in A:
ans = (ans + l * pow(ai, MOD - 2, MOD)) % MOD
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 85,472,118,111,038 | 231 | 235 |
n = input()
cards = []
for i in range(n):
cards.append(raw_input().split())
marks = ['S', 'H', 'C', 'D']
for i in marks:
for j in range(1, 14):
if [i, str(j)] not in cards:
print i, j
|
import sys
for x in sys.stdin:
a, op, b = x.split()
a = int(a)
b = int(b)
if op == '?':
break
elif op == '+':
print(a + b)
elif op == '-':
print(a - b)
elif op == '*':
print(a * b)
elif op == '/':
print(a // b)
| 0 | null | 855,699,334,110 | 54 | 47 |
# -*- coding: utf-8 -*-
r, c = map(int, raw_input().split())
cl= [0] * c
for i in xrange(r):
t = map(int, raw_input().split())
for i, a in enumerate(t): cl[i] += a
print ' '.join(map(str, t)), sum(t)
print ' '.join(map(str, cl)), sum(cl)
|
N,M,K = map(int,input().split())
MOD = 998244353
MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
fac[i] = fac[i-1] * i % MOD
inv[i] = -inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i-1] * inv[i] % MOD
def comb(n,r):
if n < r: return 0
if n < 0 or r < 0: return 0
return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD
ans = 0
for i in range(K+1):
if i==N: break
n = N-i
ans += M * pow(M-1,n-1,MOD) * comb(N-1,i)
ans %= MOD
print(ans)
| 0 | null | 12,333,423,877,888 | 59 | 151 |
H,N = map(int,input().split())
A = list(map(int,input().split()))
sum =0
for i in range(len(A)):
sum = sum + A[i]
if sum >= H:
print("Yes")
else:
print("No")
|
h,n=map(int,input().split())
l=list(map(int,input().split()))
a=0
for i in range(n):
a+=l[i]
if a>=h:
print("Yes")
else:
print("No")
| 1 | 77,764,853,781,212 | null | 226 | 226 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0;r=10**10
while r-l>1:
x=(l+r)//2
ct=0
for i in range(n):
ct+=(a[i]-1)//x
if ct<=k:
r=x
else:
l=x
print(r)
|
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
high = max(A)
else:
low = 0
high = 10**9
while high-low>1:
mid = (high+low)//2
cnt = 0
for i in range(N):
if A[i]%mid==0:
cnt += A[i]//mid-1
else:
cnt += A[i]//mid
if K>=cnt:
high = mid
else:
low = mid
print(high)
| 1 | 6,481,629,051,550 | null | 99 | 99 |
N = int(input())
z = []
w = []
for i in range(N):
x,y = map(int,input().split())
z.append(x+y)
w.append(x-y)
z_max = max(z)
z_min = min(z)
w_max = max(w)
w_min = min(w)
print(max(z_max-z_min,w_max-w_min))
|
N=int(input())
A=[]
B=[]
for _ in range(N):
x,y=map(int, input().split())
A.append(x+y)
B.append(x-y)
A=sorted(A)
B=sorted(B)
print(max(A[-1]-A[0],B[-1]-A[0],A[-1]-A[0],B[-1]-B[0]))
| 1 | 3,432,765,851,268 | null | 80 | 80 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
n,k = LI()
a = LI()
for kk in range(k):
r = [0] * (n+1)
for i in range(n):
c = a[i]
r[max(0, i - c)] += 1
r[min(n, i + c + 1)] -= 1
if r[0] == n and r[n] == -n:
a = [n] * n
break
t = 0
for i in range(n):
t += r[i]
a[i] = t
return JA(a, " ")
print(main())
|
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
b = [0] * (n + 1)
for i in range(n):
left_edge = max(0, i-a[i])
right_edge = min(i + a[i] + 1, n)
b[left_edge] += 1
b[right_edge] -= 1
for i in range(1, n+1):
b[i] = b[i] + b[i-1]
b.pop(n)
if a == b:
break
a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))
| 1 | 15,424,119,080,978 | null | 132 | 132 |
n=int(input())
a=list(map(int,input().split()))
num=[i for i in range(1,n+1)]
order=dict(zip(num,a))
order2=sorted(order.items(),key=lambda x:x[1])
ans=[]
for i in range(n):
ans.append(order2[i][0])
print(' '.join([str(n) for n in ans]))
|
N=int(input())
A=list(map(int, input().split()))
B=[0]*N
C=''
for i in range(N):
B[A[i]-1]=i+1
for i in range(N):
C+=str(B[i])+' '
print(C[0:-1])
| 1 | 179,993,445,336,004 | null | 299 | 299 |
def solve():
n = int(input())
s = set(map(int, input().split()))
print("YES" if len(s) == n else "NO")
solve()
|
N = int(input())
S, T = input().split()
A = ""
for i in range(N):
A += S[i] + T[i]
print(A)
| 0 | null | 93,164,884,818,080 | 222 | 255 |
# -*- coding: utf-8 -*-
import sys
'import math'
while(1):
n,m=input().split()
if n=='0' and m=='0':
sys.exit()
n=int(n)+1
m=int(m)
cnt=0
for a in range(1,n):
for b in range(a+1,n):
for c in range (b+1,n):
if a+b+c==m:
cnt+=1
print(cnt)
|
from sys import stdin
def main():
for l in stdin:
n, x = map(int, l.split(' '))
if 0 == n == x:
break
print(len(num_sets(n, x)))
def num_sets(n, x):
num_sets = []
for i in range(1, n-1):
for j in [m for m in range(i+1, n)]:
k = x - (i+j)
if n < k:
continue
if k <= j:
break
num_sets.append((i, j, k))
return num_sets
if __name__ == '__main__': main()
| 1 | 1,287,238,308,214 | null | 58 | 58 |
N = input()
A, a = 0, 0
for i in range(65, 91):
if i==ord(N):
A += 1
for i in range(97, 123):
if i==ord(N):
a += 1
if A==1:
print('A')
if a==1:
print('a')
|
x = input()
ans = 'A' if x in ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z') else 'a'
print(ans)
| 1 | 11,282,361,843,916 | null | 119 | 119 |
X = int(input())
def f(X):
for A in range(-118, 120):
for B in range(-119, 119):
if A**5-B**5 == X:
print(A, B)
exit()
f(X)
|
n = int(input())
for i in range(1000):
for j in range(-1000,1000):
if (i**5-j**5)==n:
print(i,j)
exit()
| 1 | 25,524,406,484,282 | null | 156 | 156 |
import math
A, B = map(int, input().split())
min1 = math.floor(A * 25/2)
max1 = math.ceil((A + 1) * 25/2)
ans_lis = []
ans1 = False
ans2 = False
for i in range(min1, max1):
if A == math.floor(i * 2/25):
ans1 = True
ans_lis.append(i)
for x in ans_lis:
if B == math.floor(x * 1/10):
ans2 = True
ans = x
break
if ans1 == True and ans2 == True:
print(x)
else:
print(-1)
|
N = int(input())
Ans = [0] * (N + 1)
def calc(a, b, c):
return a ** 2 + b ** 2 + c ** 2 + a * b + b * c + c * a
for i in range(1, N):
for j in range(1, N):
for k in range(1, N):
x = calc(i, j, k)
if x > N:
break
Ans[x] += 1
for a in Ans[1:]:
print(a)
| 0 | null | 32,325,153,425,030 | 203 | 106 |
n = int(input())
if n % 2 != 0:
print(n//2)
else:
print(n//2-1)
|
def solve(n):
return (n - 1) // 2
assert solve(4) == 1
assert solve(999999) == 499999
n = int(input())
print(solve(n))
| 1 | 153,504,180,941,110 | null | 283 | 283 |
import sys
sys.setrecursionlimit(10**7)
n,u,v=map(int, input().split())
u-=1
v-=1
graph = [[] for _ in range(n+1)]
for i in range(n-1):
a, b=map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
dist=[[-1, -1] for _ in range(n)]
dist[v][0]=0
dist[u][1]=0
def dfs(graph,v,k):
ver=graph[v]
for vers in ver:
if dist[vers][k]==-1:
dist[vers][k]=dist[v][k]+1
dfs(graph,vers,k)
dfs(graph,v,0)
dfs(graph,u,1)
dist.sort(reverse=True)
for i in range(10**6):
if dist[i][0]-dist[i][1]>=1:
print(dist[i][0]-1)
break
|
N = int(input())
S = input()
ans = 0
prev = -1
for s in S:
if prev != s:
ans+=1
prev=s
print(ans)
| 0 | null | 144,106,166,473,110 | 259 | 293 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
K = int(readline())
vec = list(range(1, 10))
for i in range(K):
tail = vec[i] % 10
n10 = vec[i] * 10
if tail == 0:
vec.append(n10 + tail)
vec.append(n10 + tail + 1)
elif tail == 9:
vec.append(n10 + tail - 1)
vec.append(n10 + tail)
else:
vec.append(n10 + tail - 1)
vec.append(n10 + tail)
vec.append(n10 + tail + 1)
print(vec[K - 1])
return
if __name__ == '__main__':
main()
|
import sys
sys.setrecursionlimit(10**9)
k=int(input())
def dfs(keta,num):
global ans
ans.append(int(''.join(num)))
if keta==10:
return
min_n=max(0,int(num[-1])-1)
max_n=min(9,int(num[-1])+1)
for i in range(min_n,max_n+1):
dfs(keta+1,num+[str(i)])
ans=[]
for i in range(1,10):
dfs(1,[str(i)])
ans.sort()
print(ans[k-1])
| 1 | 39,961,746,303,878 | null | 181 | 181 |
MAX = 10**6 * 3
MOD = 10**9+7
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
#前処理 逆元テーブルを作る
def COMinit():
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i-1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD//i)%MOD
finv[i] = finv[i-1] * inv[i] % MOD
#実行
def COM(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
k = int(input())
s = input()
n = len(s)
COMinit()
ans = 0
for i in range(k+1):
pls = pow(25, i, MOD)
pls *= pow(26,k-i, MOD)
pls %= MOD
pls *= COM(i+n-1, i)
ans += pls
ans %= MOD
print(ans%MOD)
|
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)
| 0 | null | 11,787,651,357,692 | 124 | 117 |
#coding:utf-8
from copy import deepcopy
n = int(input())
c = ["white" for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
S = []
class DFS:
def __init__(self, key, color="white",nex=None):
self.color = color
self.nex = nex
self.key = key
objListCopy = [DFS(i+1) for i in range(n)]
for i in range(n):
data = list(map(int,input().split()))
times = data[1]
obj = objListCopy[i]
for j in range(times):
index = data[2+j] - 1
nextobj = DFS(index+1)
obj.nex = nextobj
obj = obj.nex
time = 1
objList = objListCopy[:]
def check(first,time):
obj = objList[first]
c[first] = "gray"
d[first] = time
f[first] = time
S.append(first+1)
while S != []:
index = S[-1] - 1
u = objList[index]
v = u.nex
time += 1
if v != None:
if c[v.key - 1] == "white":
objList[index] = v
index = v.key - 1
v = objList[index]
c[v.key-1] = "gray"
d[index] = time
S.append(v.key)
else:
objList[index] = v
time -= 1
else:
S.pop()
c[u.key-1] = "black"
f[index] = time
return time
for i in range(n):
if f[i] == 0:
objList = deepcopy(objListCopy)
time = check(i,time) + 1
k = 1
for i,j in zip(d,f):
print(k,i,j)
k += 1
|
count = 0
def solve(i, a, ans):
global count
if ans[i][0] == 0:
count += 1
ans[i][0] = count
for x in range(a[i][1]):
if ans[a[i][2 + x] - 1][0] == 0:
solve(a[i][2 + x] - 1, a, ans)
if ans[i][1] == 0:
count += 1
ans[i][1] = count
N = int(input())
a = []
for _ in range(N):
a.append([int(x) for x in input().split()])
ans = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
if ans[i][0] == 0:
solve(i, a, ans)
for i, x in enumerate(ans):
print(i + 1, *x)
| 1 | 2,877,835,970 | null | 8 | 8 |
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
#print(a)
if a[0]==0 :
print(0)
exit()
res = 1
lim = 10**18
for i in(a):
res *= i
if res > lim :
print(-1)
exit()
print(res)
|
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
def count(x):
ret = 0
for a in A:
ret += N - bisect_left(A, x - a)
return ret
overEq = 0
less = 10**7
while less - overEq > 1:
mid = (less + overEq) // 2
if count(mid) >= M:
overEq = mid
else:
less = mid
ans = 0
cnt = [0] * N
for a in A:
i = (N - bisect_left(A, overEq - a))
ans += i * a
if i > 0:
cnt[-i] += 1
for i in range(1, N):
cnt[i] += cnt[i - 1]
for a, c in zip(A, cnt):
ans += a * c
ans -= overEq * (count(overEq) - M)
print(ans)
| 0 | null | 62,369,646,157,764 | 134 | 252 |
# -*- coding: utf-8 -*-
import io
import sys
import math
def solve(a,b):
# implement process
s = str(min(a,b))
n = max(a,b)
return s * n
def main():
# input
a,b = map(int, input().split())
# process
ans = str( solve(a,b) )
# output
print(ans)
return ans
### DEBUG I/O ###
_DEB = 0 # 1:ON / 0:OFF
_INPUT = """\
7 7
"""
_EXPECTED = """\
7777777
"""
def logd(str):
"""usage:
if _DEB: logd(f"{str}")
"""
if _DEB: print(f"[deb] {str}")
### MAIN ###
if __name__ == "__main__":
if _DEB:
sys.stdin = io.StringIO(_INPUT)
print("!! Debug Mode !!")
ans = main()
if _DEB:
print()
if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
|
def main():
a,b= list(map(int,input().split()))
a_str=""
b_str=""
for i in range(0,b):
a_str+=str(a)
for i in range(0,a):
b_str+=str(b)
if a_str<b_str:
print(a_str)
else:
print(b_str)
main()
| 1 | 84,608,510,563,160 | null | 232 | 232 |
n = int(input())
info = []
for _ in range(n):
temp = [int(x) for x in input().split( )]
info.append(temp)
state = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for a in info:
state[a[0]-1][a[1]-1][a[2]-1] += a[3]
for b in range(4):
for f in range(3):
string = ''
for k in range(10):
string += ' ' + str(state[b][f][k])
print(string)
if b < 3:
print('#'*20)
|
n=int(input())
data=[[int(num)for num in input().split(' ')] for i in range(n)]
state=[[[0 for i in range(10)]for j in range(3)]for k in range(4)]
for datum in data:
state[datum[0]-1][datum[1]-1][datum[2]-1]+=datum[3]
for i in range(4):
for j in range(3):
s=""
for k in range(10):
s+=' '+str(state[i][j][k])
print(s)
if i!=3:
print("####################")
| 1 | 1,126,097,867,520 | null | 55 | 55 |
N = int(input())
alist = list(map(int, input().split()))
blist = []
for i in range(N):
blist.append([alist[i],i+1])
blist.sort()
for i in range(N):
print(blist[i][1],end=" ")
|
n = int(input())
a = list(map(int, input().split()))
# a = np.array(a)
# ans = []
# while a.min() != 9999999:
# min_index = a.argmin()
# ans.append(min_index+1)
# a[min_index] = 9999999
# print(' '.join([str(_) for _ in ans]))
l = []
for i in range(n):
l.append([i+1, a[i]])
sl = sorted(l, key=lambda x: x[1])
sl0 = [r[0] for r in sl]
print(' '.join([str(_) for _ in sl0]))
| 1 | 180,911,139,391,868 | null | 299 | 299 |
N = int(input())
ans = 'No'
for i in range(1,10):
if N%i == 0:
tmp = str(int(N/i))
if len(tmp) >= 2:
continue
else:
ans = 'Yes'
break
else:
continue
print(ans)
|
n=int(input())
a=[]
for i in range(1,10):
for j in range(1,10):
a.append(i*j)
else:
if n in a:
print('Yes')
else:
print('No')
| 1 | 160,427,134,775,222 | null | 287 | 287 |
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
p=10**9+7
def fact(n,p):
a=[[] for _ in range(n+1)]
a[0]=1
for i in range(n):
a[i+1]=(a[i]*(i+1))%p
return a
f=fact(n,p)
g=[]
for i in range(n+1):
g.append(pow(f[i],-1,p))
def com(n,r):
return f[n]*g[r]*g[n-r]
ans=0
for i in range(n-k+1):
ans=ans+(a[-i-1]-a[i])*com(n-i-1,k-1)
print(ans%p)
|
MAX = 10 ** 6
MOD = 10 ** 9 + 7
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def COM(n, r):
if n < r or r < 0 or n < 0:
return 0
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD
def main():
COMinit()
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
i = 0
sum_max = 0
sum_min = 0
while n - i - 1 >= k - 1:
cnt = COM(n - i - 1, k - 1)
sum_max += a[i] * cnt
sum_min += a[n - i - 1] * cnt
i += 1
ans = (sum_max - sum_min) % MOD
print(ans)
if __name__ == '__main__':
main()
| 1 | 95,656,524,271,646 | null | 242 | 242 |
H1,M1,H2,M2,k = map(int,input().split())
h = ((H2-1)-H1)*60
m = (M2+60)-M1
print((h+m)-k)
|
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007
h1, m1, h2, m2, k = map(int, input().split())
minute = ((h2 * 60) + m2) - ((h1 * 60) + m1)
print(minute - k)
| 1 | 17,935,596,860,608 | null | 139 | 139 |
import sys
read = sys.stdin.buffer.read
def main():
N, K, *AF = map(int, read().split())
A = AF[:N]
F = AF[N:]
A.sort()
F.sort(reverse=True)
ok = pow(10, 12)
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
k = 0
for i in range(N):
if A[i] * F[i] > mid:
k += A[i] - mid // F[i]
if k <= K:
ok = mid
else:
ng = mid
print(ok)
return
if __name__ == '__main__':
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)
def isOk(T):
ret = 0
for a, f in zip(A, F):
ret += max(0, a - T // f)
return ret <= K
ok = max(a * f for a, f in zip(A, F))
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if isOk(mid):
ok = mid
else:
ng = mid
print(ok)
| 1 | 164,665,819,486,058 | null | 290 | 290 |
import math
a, b, n = map(int, input().split())
x = b - 1
if x > n:
x = n
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
|
H, W, K = map(int, input().split())
C = ["" for _ in range(H)]
for h in range(H):
C[h] = [s for s in input()]
cnt = 0
for h in range(1 << H):
for w in range(1 << W):
black = 0
for i in range(H):
if (h >> i & 1) == 1:
continue
for j in range(W):
if (w >> j & 1) == 1:
continue
if C[i][j] == "#":
black += 1
if black == K:
cnt += 1
print(cnt)
| 0 | null | 18,472,329,857,388 | 161 | 110 |
N = int(input())
if N % 10 in [2, 4, 5, 7, 9]:
print("hon")
elif N % 10 in [0, 1, 6, 8]:
print("pon")
else:
print("bon")
|
def gcd( x, y ):
if 1 < y < x:
return gcd( y, x%y )
else:
if y == 1:
return 1
return x
a, b = [ int( val ) for val in raw_input( ).split( " " ) ]
if a < b:
a, b = b, a
print( gcd( a, b ) )
| 0 | null | 9,600,987,251,632 | 142 | 11 |
from collections import deque
process_num, qms = map(int ,input().split())
que = deque({})
for i in range(process_num):
name, time = input().split()
time = int(time)
que.append({"name":name, "time":time})
if __name__ == '__main__':
total_time = 0
while len(que)>0:
atop = que.popleft()
spend = min(atop["time"], qms)
atop["time"] -= spend
total_time += spend
if(atop["time"] == 0):
print("{} {}".format(atop["name"], total_time))
else:
que.append(atop)
|
import itertools
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A_=[0]+list(itertools.accumulate(A))
B_=[0]+list(itertools.accumulate(B))
ans=0
j=M
for i in range(N+1):
a=A_[i]
K_a=K-a
while (j>=0 and B_[j]>K_a):
j-=1
if a+B_[j]<=K:
ans=max(ans,i+j)
print(ans)
| 0 | null | 5,421,860,538,108 | 19 | 117 |
a, b = (int(i) for i in input().split())
while a != 0 or b != 0:
count = 0
for i in range(1, a-1):
for j in range(i+1 , a):
for k in range(i+2, a+1):
if i + j + k == b and i < j < k:
count += 1
print("{0}".format(count))
a, b = (int(i) for i in input().split())
|
a,b,c = map(int,input().split())
if a + b + c >= 22:
print('bust')
if a + b + c <= 21:
print('win')
| 0 | null | 60,182,101,525,792 | 58 | 260 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.