code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import sys
# import re
# import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
# import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
MOD2 = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n = ni()
d = na()
c = collections.Counter(d)
lim = max(c)
flg = False
if d[0] != 0:
flg = True
if c[0] != 1:
flg = True
for i in range(lim + 1):
if i not in c.keys():
flg = True
break
if flg:
print(0)
exit(0)
ans = 1
for i in range(2, lim + 1):
ans *= pow(c[i - 1], c[i], MOD2)
ans %= MOD2
print(ans)
if __name__ == '__main__':
main()
|
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
N = int(sysread())
D = list(map(int, sysread().split()))
mod = 998244353
dict = defaultdict(lambda:[])
max_depth = 0
for node, d in enumerate(D, 1):
dict[d].append(node)
max_depth = max(max_depth, d)
if dict[0] != [1]:
print(0)
return None
ans = 1
for i in range(1, max_depth+1):
pre = len(dict[i-1])
current = len(dict[i])
val =pow(pre, current, mod)
ans *= val
ans %= mod
print(ans)
return None
#print(factorials)
if __name__ == "__main__":
run()
| 1 | 154,563,250,871,470 | null | 284 | 284 |
h,n = map(int,input().split())
M = []
max_val = 0
for _ in range(n):
a,b = map(int,input().split())
max_val = max(max_val,a)
M.append((a,b))
dp = [float('inf')]*(h+1+max_val)
dp[0] = 0
for i in range(1,h+1+max_val):
for j in range(n):
dp[i] = min(dp[i-M[j][0]] + M[j][1],dp[i])
print(min(dp[h:-1]))
|
#-*-coding:utf-8-*-
from decimal import Decimal
import math
def main():
x1,y1,x2,y2 = map(Decimal,input().split())
print("{:.8f}".format(math.sqrt((x2-x1)**2+(y2-y1)**2)))
if __name__=="__main__":
main()
| 0 | null | 40,833,584,358,120 | 229 | 29 |
S = int(input())
if S == 1:
print(0)
exit()
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0
cumsum = 1
for i in range(3, len(A)):
A[i] = (A[i - 1] + A[i - 3]) % MOD
print(A[-1])
|
def main():
n = input()
A = map(int,raw_input().split())
c = mergeSort(A,0,n)
for i in range(n-1):
print A[i],
print A[-1]
print c
def merge(A,left,mid,right):
n1 = mid - left
n2 = right - mid
L = [A[left+i] for i in range(n1)]
L += [float("inf")]
R = [A[mid+i] for i in range(n2)]
R += [float("inf")]
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return i+j
def mergeSort(A,left,right):
if left+1 < right:
mid = (left+right)/2
k1 = mergeSort(A,left,mid)
k2 = mergeSort(A,mid,right)
k3 = merge(A,left,mid,right)
return k1+k2+k3
else:
return 0
if __name__ == "__main__":
main()
| 0 | null | 1,674,056,039,620 | 79 | 26 |
import itertools
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
Psort = sorted(P)
Pp = list(itertools.permutations(Psort))
a = Pp.index(P)
b = Pp.index(Q)
print(abs(a-b))
|
x = input().split()
a,b,c=[int(x) for x in x]
ans=0
for x in range(a,b+1):
if c%x==0:ans+=1
print(ans)
| 0 | null | 50,852,813,060,772 | 246 | 44 |
import sys
import numpy as np
mod=10**9+7
n=int(sys.stdin.buffer.readline())
a=np.fromstring(sys.stdin.buffer.readline(),dtype=np.int64,sep=' ')
ans=0
b=1
for i in range(60):
s=int((a&1).sum())
ans=(ans+s*(n-s)*b)%mod
a>>=1
b=b*2%mod
print(ans)
|
ret = [3,14,39,84,155,258,399,584,819,1110]
s = int(input())
print(ret[s-1])
| 0 | null | 66,589,606,786,978 | 263 | 115 |
num,money=map(int,input().split())
if num*500>=money:
print("Yes")
else:
print("No")
|
import numpy as np
#n = int(input())
a = list(map(int, input().rstrip().split()))
out=0
for i in a:
if i > 1:
out += i*(i-1)//2
print(out)
| 0 | null | 71,432,335,510,080 | 244 | 189 |
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
result=1
max=10**18
for a in A:
result *= a
if result>max:
print(-1)
break
else:
print(result)
|
import math
import statistics
a=int(input())
#b=int(input())
# c=[]
# for i in b:
# c.append(i)
# e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]
# h = []
# for i in range(e1):
# h.append(list(map(int,input().split())))
ans=0
count=0
for i in range(a):
if ans+1 == f[i]:
ans=f[i]
count+=1
if count>0:
print(len(f)-count)
else:
print(-1)
| 0 | null | 65,291,239,477,608 | 134 | 257 |
n = int(input())
a = list(map(int, input().split()))
x = []
flag = True
for i in reversed(range(n)):
if i == 0:
if not flag:
x.append(a[i])
break
flag2 = flag
if flag:
if a[i - 1] < a[i]:
x.append(a[i])
flag2 = not flag2
else:
if a[i - 1] > a[i]:
x.append(a[i])
flag2 = not flag2
flag = flag2
x = x[::-1]
m = len(x)
if m % 2 == 1:
x = x[1:]
# print("x =", x)
cur_money = 1000
cur_stock = 0
for i in range(m):
if i % 2 == 0:
cur_stock += cur_money // x[i]
cur_money %= x[i]
else:
cur_money += x[i] * cur_stock
cur_stock = 0
print(cur_money)
|
N = int(input())
A = list(map(int, input().split()))
A.append(0)
okane = 1000
kabu = 0
for i in range(N):
if A[i] <= A[i+1]:
buy = okane//A[i]
okane -= buy*A[i]
kabu += buy
if A[i] > A[i+1]:
okane += kabu*A[i]
kabu = 0
print(okane)
| 1 | 7,349,448,225,406 | null | 103 | 103 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
S = input()
if S[-1] == 's':
print(S+'es')
else:
print(S+'s')
if __name__ == '__main__':
main()
|
s = input()
s_list = list(s)
if s_list[-1] == 's':
output = s + 'es'
else:
output = s + 's'
print(output)
| 1 | 2,345,817,649,120 | null | 71 | 71 |
s = sorted([int(input()), int(input())])
print(3 if s == [1, 2] else (2 if s == [1, 3] else 1))
|
A = int(input())
B = int(input())
anss = set([1, 2, 3])
anss.remove(A)
anss.remove(B)
for i in anss:
print(i)
| 1 | 110,277,729,096,140 | null | 254 | 254 |
a = input().lower()
cnt = 0
while 1:
c = input()
if c == 'END_OF_TEXT':
break
cnt += c.lower().split().count(a)
print(cnt)
|
s=input().lower()
cnt=0
while True:
l=input().split()
if l[0]=='END_OF_TEXT': break
for i in range(len(l)):
lg=len(l[i])-1
if not l[i][lg].isalpha(): l[i]=l[i][:lg]
cnt+=(s==l[i].lower())
print(cnt)
| 1 | 1,818,867,912,228 | null | 65 | 65 |
#!/usr/bin/env python
# coding: utf-8
# In[14]:
from collections import deque
# In[21]:
S = deque(input())
Q = int(input())
rev_cnt = 0
for _ in range(Q):
q = input().split()
if len(q) == 1:
rev_cnt += 1
else:
if (rev_cnt+int(q[1]))%2 == 0:
S.append(q[2])
else:
S.appendleft(q[2])
if rev_cnt%2 == 0:
print("".join(S))
else:
print("".join(list(reversed(S))))
# In[ ]:
|
import sys
from collections import defaultdict
#+++++
def main():
n, k = map(int, input().split())
aal = list(map(int, input().split()))
sss = [0]*(n+1)
si=0
for i, a in enumerate(aal):
si+=a-1
sss[i+1]=si%k
count=0
mkl_dict=defaultdict(lambda :0)
for j in range(n+1):
sj=sss[j]
if j-k >= 0:
mkl_dict[sss[j-k]]-=1
count += mkl_dict[sj]
mkl_dict[sj] += 1
print(count)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
if __name__ == "__main__":
if sys.platform =='ios':
sys.stdin=open('inputFile.txt')
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| 0 | null | 97,463,742,292,412 | 204 | 273 |
A,B,C = map(int, input().split())
print('{} {} {}'.format(C,A,B))
|
N = int(input())
As = list(map(int, input().split()))
tmp = []
for i in range(1, len(As)):
if As[i]-As[i-1]>0:
tmp.append(1)
elif As[i]-As[i-1]<0:
tmp.append(-1)
else:
tmp.append(0)
seq = False
money = 1000
stock = 0
for i, pm in enumerate(tmp, 1):
if pm==1:
if seq == False:
stock = As[i-1]
seq = True
if pm==-1:
if stock:
stock_num = money//stock
money-=stock*stock_num
max_ = As[i-1]
money+=max_*stock_num
seq = False
stock = 0
if len(tmp) == i:
if stock<As[i] and stock!=0:
stock_num = money//stock
money-=stock*stock_num
max_ = As[i]
money+=max_*stock_num
print(money)
| 0 | null | 22,579,053,106,864 | 178 | 103 |
W, H, x, y, r = map(int, input().split())
flg = False
for X in [x - r, x + r]:
for Y in [y - r, y + r]:
if not 0 <= X <= W:
flg = True
if not 0 <= Y <= H:
flg = True
print(["Yes", "No"][flg])
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a = LI()
s = sum(a)
if s >= 22:
print('bust')
else:
print('win')
| 0 | null | 59,721,222,618,900 | 41 | 260 |
n=int(input())
s=list(input())
if n%2==1:
print("No")
elif s[:n//2]==s[n//2:n]:
print("Yes")
else:
print("No")
|
N = int(input())
S = list(input())
ans = 'No'
if N%2 == 0:
num = int(N/2)
pre = S[:num]
suf = S[num:]
if pre == suf: ans = "Yes"
print(ans)
| 1 | 147,131,015,025,468 | null | 279 | 279 |
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
def cal(x):
s = 0
for aa in a:
s += math.ceil(aa / x) - 1
if s <= K: return True
else: return False
l = 0
r = max(a)
while r - l > 1:
mid = (l + r) // 2
if cal(mid):
r = mid
else:
l = mid
print(r)
|
a = int(input())
reslut = pow(a,1) + pow(a,2) + pow(a,3)
print(reslut)
| 0 | null | 8,443,224,346,212 | 99 | 115 |
n = int(raw_input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
g = [0 for i in range(n)]
def dfs_visit(s):
st[s] = 1
time[0] += 1
d[s] = time[0]
for k in range(n):
if a[s][k] == 1 and st[k] == 0:
dfs_visit(k)
st[s] ==2
time[0] += 1
f[s] = time[0]
def main():
for s in range(n):
if st[s] == 0:
dfs_visit(s)
for s in range(n):
print '%d %d %d' %(s+1, d[s], f[s])
for i in range(n):
g = map(int, raw_input().split())
for j in range(g[1]):
a[g[0]-1][g[2+j]-1] = 1
main()
|
import sys
def gcd(m, n):
if n != 0:
return gcd(n, m % n)
else:
return m
for line in sys.stdin.readlines():
m, n = map(int, line.split())
g = gcd(m, n)
l = m * n // g # LCM
print(g, l)
| 0 | null | 1,521,428,610 | 8 | 5 |
N = int(input())
L = [x * y for x in range(1, 10) for y in range(1, 10)]
if L.count(N) != 0:
print("Yes")
else:
print("No")
|
a = int(input())
f = False
for i in range(1,10):
if a % i == 0 and a/i < 10:
f = True
break
if f:
print("Yes")
else:
print("No")
| 1 | 159,197,144,628,952 | null | 287 | 287 |
n, m = (int(x) for x in input().split())
list_a = [int(x) for x in input().split()]
for i in range(0, m):
n -= list_a[i]
if n < 0:
print('-1')
exit()
print(n)
|
# https://atcoder.jp/contests/abc163/tasks/abc163_b
n, m = map(int, input().split())
a = list(map(int, input().split()))
day = sum(a)
if day <= n:
print(n-day)
else:
print('-1')
| 1 | 31,943,347,846,014 | null | 168 | 168 |
a1, a2, a3 = map(int, input().split())
x = a1 + a2 + a3
print('win' if x <= 21 else 'bust')
|
t1, t2 = map(int,input().split())
a1, a2 = map(int,input().split())
b1, b2 = map(int,input().split())
a1 = t1*a1
a2 = t2*a2
b1 = t1*b1
b2 = t2*b2
if (a1 + a2) == (b1 + b2):
print('infinity')
exit(0)
elif (a1 + a2) > (b1 + b2):
a1, b1 = b1, a1
a2, b2 = b2, a2
if b1 > a1:
print(0)
exit(0)
tmp00 = a1 - b1
tmp01 = b1 + b2 - a1 - a2
ans = tmp00 // tmp01 * 2 + 1
if tmp00 % tmp01 == 0:
ans -= 1
print(ans)
| 0 | null | 124,832,032,247,100 | 260 | 269 |
(r, c) = [int(i) for i in input().split()]
table = [[0 for j in range(c + 1)]for i in range(r + 1)]
for i in range(r):
tmp = [int(x) for x in input().split()]
for j in range(c + 1):
if not j == c:
table[i][j] = tmp[j]
table[i][c] += table[i][j]
table[r][j] += table[i][j]
for i in range(r + 1):
for j in range(c + 1):
if j == c:
print(table[i][j], end='')
else:
print(table[i][j], '', end='')
print()
|
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=A[0]
if N%2==1:
n=int((N-1)/2)
ans+=A[n]
for i in range(1,n):
ans+=2*A[i]
elif N==2:
ans+=0
elif N%2==0 and N>2:
n=int((N-2)/2)
for i in range(1,n+1):
ans+=2*A[i]
print(ans)
| 0 | null | 5,240,694,092,092 | 59 | 111 |
a,b,c,k = map(int,input().split())
print(k if k<a else a if a+b>k else a-(k-a-b))
|
import math
r = float(input())
a = r * r * math.pi
b = r * 2 * math.pi
print('{0:f} {1:f}'.format(a, b))
| 0 | null | 11,269,363,672,760 | 148 | 46 |
def nearest_int(f):
if f - int(f) < 0.5:
return int(f)
else:
return int(f) + 1
N = int(input())
X = list(map(lambda x: int(x), input().split(" ")))
ave = sum(X) / N
avei = nearest_int(ave)
print(sum([(x - avei) ** 2 for x in X]))
|
inp = list(map(int, input().split()))
a, b = inp[0], inp[1]
if a > b*2: print(a-b*2)
else: print(0)
| 0 | null | 115,933,749,016,160 | 213 | 291 |
import sys
sys.setrecursionlimit(10**9)
n,m = list(map(int,input().split()))
d = {}
for i in range(m):
fr, to = list(map(int,input().split()))
d[fr] = d.get(fr, []) + [to]
d[to] = d.get(to, []) + [fr]
visited = [0 for i in range(n+1)]
def connect(node, i):
visited[node] = i
if node in d:
for neig in d[node]:
if visited[neig] == 0:
connect(neig, i)
ans = 1
for key in range(1,n+1):
if visited[key] == 0:
connect(key, ans)
ans += 1
print(max(visited)-1)
|
#0926
class UnionFind(): # 0インデックス
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 test(self):
return self.parents
def test2(self):
return sum(z <0 for z in self.parents)
N, M = map(int, input().split()) # N人、M個の関係
uf = UnionFind(N)
for _ in range(M):
A, B = map(int, input().split())
A -= 1
B -= 1
uf.union(A, B)
print(uf.test2()-1)
| 1 | 2,310,675,554,978 | null | 70 | 70 |
import time as ti
class MyQueue(object):
"""
My Queue class
Attributes:
queue: queue
head
tail
"""
def __init__(self):
"""Constructor
"""
self.length = 50010
self.queue = [0] * self.length
# counter = 0
# while counter < self.length:
# self.queue.append(Process())
# counter += 1
self.head = 0
self.tail = 0
# def enqueue(self, name, time):
def enqueue(self, process):
"""enqueue method
Args:
name: enqueued process name
time: enqueued process time
Returns:
None
"""
self.queue[self.tail] = process
# self.queue[self.tail].name = name
# self.queue[self.tail].time = time
self.tail = (self.tail + 1) % self.length
def dequeue(self):
"""dequeue method
Returns:
None
"""
# self.queue[self.head].name = ""
# self.queue[self.head].time = 0
self.queue[self.head] = 0
self.head = (self.head + 1) % self.length
def is_empty(self):
"""check queue is empty or not
Returns:
Bool
"""
if self.head == self.tail:
return True
else:
return False
def is_full(self):
"""chech whether queue is full or not"""
if self.tail - self.head >= len(self.queue):
return True
else:
return False
class Process(object):
"""process class
"""
def __init__(self, name="", time=0):
"""constructor
Args:
name: name
time: time
"""
self.name = name
self.time = time
def forward_time(self, time):
"""time forward method
Args:
time: forward time interval
Returns:
remain time
"""
self.time -= time
return self.time
def time_forward(my_queue, interval, current_time,):
"""
Args:
my_queue: queue
interval: time step interval
current_time: current time
"""
value = my_queue.queue[my_queue.head].forward_time(interval)
if value <= 0:
current_time += (interval + value)
print my_queue.queue[my_queue.head].name, current_time
my_queue.dequeue()
elif value > 0:
current_time += interval
name, time = my_queue.queue[my_queue.head].name, \
my_queue.queue[my_queue.head].time
my_queue.enqueue(my_queue.queue[my_queue.head])
my_queue.dequeue()
return current_time
my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
name, time = raw_input().split()
my_queue.enqueue(Process(name, int(time)))
counter += 1
# end_time_list = []
current_time = 0
while not my_queue.is_empty():
current_time = time_forward(my_queue, q, current_time)
|
s = input()
p = input()
s2 = s + s
if s2.find(p) != -1:
print('Yes')
else:
print('No')
| 0 | null | 876,659,391,268 | 19 | 64 |
import bisect
X, N = map(int, input().split())
P = set(map(int, input().split()))
A = {i for i in range(102)}
S = list(A - P)
T = bisect.bisect_left(S, X)
if T == 0:
print(S[0])
elif X - S[T-1] > S[T] - X:
print(S[T])
else:
print(S[T-1])
|
N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
tmp = input().split()
node_id = tmp[0]
node_ls.append(node_id)
is_visited[node_id] = False
adj_num = int(tmp[1])#各頂点の次元が入っている
if adj_num != 0:
DG[node_id] = tmp[2:]
else:
DG[node_id] = []
d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1
def dfs(node):
global t
#終了条件
if is_visited[node]:
return
is_visited[node] = True
d[node] = t
t += 1
for no in DG[node]:
dfs(no)
f[node] = t
t += 1
for node in node_ls:
dfs(node)
#print(d,f)
for node in node_ls:
print(node, d[node], f[node])
| 0 | null | 7,058,607,104,654 | 128 | 8 |
S = input()
print('ARC' if S[1]=='B' else 'ABC')
|
from operator import itemgetter
from itertools import chain
N = int(input())
L = []
R = []
for i in range(N):
S = input()
low = 0
var = 0
for s in S:
if s == '(':
var += 1
else:
var -= 1
low = min(low, var)
if var >= 0:
L.append((low, var))
else:
R.append((low, var))
L.sort(key=itemgetter(0), reverse=True)
R.sort(key=lambda x: x[0] - x[1])
pos = 0
for i, (low, var) in enumerate(chain(L, R)):
if pos + low < 0:
ans = 'No'
break
pos += var
else:
ans = 'Yes' if pos == 0 else 'No'
print(ans)
| 0 | null | 23,847,528,303,140 | 153 | 152 |
A, B = map(int, input().split())
N = 1000
p1 = 0.08
p2 = 0.1
for i in range(1, N + 1):
if int(i * p1) == A and int(i * p2) == B:
print(i)
exit()
print("-1")
|
import sys
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0 or D.count(0) != 1:
print(0)
sys.exit()
D = Counter(D)
L = sorted(D.items())
pk = 0
pv = 1
ans = 1
for i,j in L:
if i == 0:
continue
if i != pk+1:
print(0)
break
ans *= pv**j
ans %= 998244353
pk = i
pv = j
else:
print(ans)
| 0 | null | 105,508,427,726,390 | 203 | 284 |
N = int(input())
ansAC = 0
ansWA = 0
ansTLE = 0
ansRE = 0
for i in range(N):
S = input()
if S == "AC":
ansAC += 1
elif S == "TLE":
ansTLE += 1
elif S == "WA":
ansWA += 1
elif S == "RE":
ansRE += 1
print("AC x " + str(ansAC))
print("WA x " + str(ansWA))
print("TLE x " + str(ansTLE))
print("RE x " + str(ansRE))
|
N = int(input())
S = [input() for _ in range(N)]
C0 = 0
C1 = 0
C2 = 0
C3 = 0
for i in range(N):
if S[i] == "AC": C0 += 1
elif S[i] == "WA": C1 += 1
elif S[i] == "TLE": C2 += 1
else: C3 += 1
print("AC x "+ str(C0))
print("WA x "+ str(C1))
print("TLE x "+ str(C2))
print("RE x "+ str(C3))
| 1 | 8,763,146,856,804 | null | 109 | 109 |
n, d, a = map(int, input().split())
xh = []
for _ in range(n):
x, h = map(int, input().split())
xh.append((x, h))
xh.sort(key=lambda x:x[0])
def bisect(x):
ok = n
ng = -1
while abs(ok-ng)>1:
mid = (ok+ng)//2
if xh[mid][0]>x:
ok = mid
else:
ng = mid
return ok
out = [0]*(n+1)
ans = 0
accu = 0
for ind, (x, h) in enumerate(xh):
accu -= out[ind]
h -= accu
if h<=0:
continue
ans += (h+a-1)//a
accu += ((h+a-1)//a)*a
out[bisect(x+2*d)] += ((h+a-1)//a)*a
print(ans)
|
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
logs_S = [0, ]
ans = 0
for i, enemy in enumerate(enemies):
X, hp = enemy
start_i = b_left(logs, X-2*D)
count = logs_S[-1] - logs_S[start_i]
hp -= count * A
if hp > 0:
attack_num = (hp + A-1) // A
logs.append(X)
logs_S.append(logs_S[-1]+attack_num)
ans += attack_num
print(ans)
| 1 | 82,342,100,962,560 | null | 230 | 230 |
N = int(input())
dic = {}
for _ in range(N):
s = input()
if s in dic:
dic[s] += 1
else:
dic[s] = 1
num = 0
for key in dic:
num = max(num, dic[key])
ans = []
for key in dic:
if dic[key] == num:
ans.append(key)
ans.sort()
for a in ans:
print(a)
|
n = int(input())
s = []
for i in range(n):
s.append(input())
s.sort()
# print(s)
m = 1
cnt = [1]
ans = []
for i in range(1,n):
if s[i] == s[i-1]:
cnt[-1] += 1
else:
if cnt[-1] > m:
ans = [s[i-1]]
elif cnt[-1] == m:
ans.append(s[i-1])
m = max(m, cnt[-1])
cnt.append(1)
if i == n-1 and cnt[-1] > m:
ans = [s[i]]
elif i == n-1 and cnt[-1] == m:
ans.append(s[i])
print('\n'.join(ans))
| 1 | 70,108,246,743,080 | null | 218 | 218 |
n, q = map(int, input().split(' '))
L = []
i = 0
while i < n:
name, time = map(str, input().split(' '))
L.append([name, int(time)])
i += 1
t = 0
fin = []
while len(L) != 0:
if L[0][1] > q:
t += q
name = L[0][0]
time = L[0][1] - q
L.append([name, time])
L.pop(0)
else:
t += L[0][1]
name = L[0][0]
time = t
fin.append([name, time])
L.pop(0)
ans = ''
for f in fin:
ans += f[0] + ' ' + str(f[1]) + '\n'
print(ans[:-1])
|
process_num, qms = map(int, input().split())
raw_procs = [input() for i in range(process_num)]
if __name__ == '__main__':
procs = []
for row in raw_procs:
name, time = row.split()
procs.append({
"name": name,
"time": int(time),
})
total_time = 0
current_proc = 0
while len(procs) > 0:
if procs[current_proc]["time"] > qms:
procs[current_proc]["time"] = procs[current_proc]["time"] - qms
total_time += qms
if current_proc == len(procs)-1:
current_proc = 0
else:
current_proc += 1
else:
total_time += procs[current_proc]["time"]
print("{} {}".format(procs[current_proc]["name"], total_time))
del procs[current_proc]
if current_proc == len(procs):
current_proc = 0
| 1 | 43,798,973,162 | null | 19 | 19 |
from collections import deque
import sys
flg1 = 1
s = input()
ll = deque()
lr = deque()
for _ in range(int(input())):
q = sys.stdin.readline().rstrip()
if q == "1":
flg1 *= -1
else:
q = list(q.split())
flg2 = 1 if q[1] == "1" else -1
if flg1 * flg2 == 1:
ll.appendleft(q[2])
else:
lr.append(q[2])
ans = "".join(ll) + s + "".join(lr)
print((ans[::-1], ans)[flg1 == 1])
|
import math
import itertools
import sys
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
h.sort(reverse=True)
ans = 0
for i in range(len(h)):
if(h[i] < k):
ans = i
print(ans)
sys.exit()
print(len(h))
| 0 | null | 118,507,548,655,750 | 204 | 298 |
n,k,s=map(int,input().split())
sMax=10**9
if k==0:
if s==sMax:
print("1 "*n)
else:
print((str(sMax)+" ")*n)
else:
if s==sMax:
print((str(s)+" ")*k+"1 "*(n-k))
else:
print((str(s)+" ")*k+(str(sMax)+" ")*(n-k))
|
n, k, s = map(int, input().split())
if s != 10**9:
ans = [s]*k + [10**9]*(n-k)
else:
ans = [s]*k + [1]*(n-k)
print(*ans)
| 1 | 91,014,482,529,728 | null | 238 | 238 |
import math
import sys
import bisect
import array
m=10**9 + 7
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split()))
# print(N,K,A)
B = list( map(lambda x: x % K, A))
C = [0]
x = 0
i = 0
for b in B:
x = (x + b ) % K
C.append((x-i-1) % K)
i += 1
# print(B,C)
E={}
ans=0
for i in range(N+1):
if C[i] in E:
ans += E[C[i]]
E[C[i]] = E[C[i]] + 1
else:
E[C[i]] = 1
if i >= K-1:
E[C[i-K+1]] = E[C[i-K+1]] - 1
if E[C[i-K+1]] == 0:
E.pop(C[i-K+1])
print(ans)
exit(0)
|
S = list(input())
ans = "No"
if (S[2] == S[3]) and (S[4] == S[5]):
ans = "Yes"
print(ans)
| 0 | null | 89,403,931,223,530 | 273 | 184 |
n = int(input())
ans = 0
for a in range(1, n+1):
cnt = (n-1)//a
ans += cnt
print(ans)
|
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
ans = 1
for a in range(1, N-1):
num_b = (N-1) // a
ans += num_b
print(ans)
main()
| 1 | 2,566,963,792,890 | null | 73 | 73 |
N,A,B=map(int,input().split())
if N == (N//(A+B))*(A+B):
print(N-(N//(A+B))*(B))
elif (N//(A+B))*(A+B)<N <= (N//(A+B))*(A+B)+A:
print(N-(N//(A+B))*(B))
else:
print((N//(A+B)+1)*(A))
|
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
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 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
n,m = inm()
h = inl()
p = [True] * n
for i in range(m):
a,b = inm()
a -= 1
b -= 1
if h[a] >= h[b]:
p[b] = False
if h[b] >= h[a]:
p[a] = False
ans = sum(p)
print(ans)
| 0 | null | 40,224,817,399,140 | 202 | 155 |
A = input()
B = input()
print('Yes' if A == B[:-1] else 'No')
|
S = list(input())
T = list(input())
T.pop()
if S==T:
print("Yes")
else:
print("No")
| 1 | 21,193,076,976,138 | null | 147 | 147 |
from functools import reduce
from math import gcd
n = int(input())
A = list(map(int, input().split()))
def furui(x):
memo = [0]*(x+1)
primes = []
for i in range(2, x+1):
if memo[i]: continue
primes.append(i)
memo[i] = i
for j in range(i*i, x+1, i):
if memo[j]: continue
memo[j] = i
return memo, primes
memo, primes = furui(10**6+5)
pr = [True]*(10**6+5)
for a in A:
if a == 1: continue
while a != 1:
w = memo[a]
if not pr[w]:
break
pr[w] = False
while a%w == 0:
a = a // w
else:
continue
break
else:
print('pairwise coprime')
exit()
if reduce(gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
|
import math
from functools import reduce
def gcd_list(numbers):
return reduce(math.gcd, numbers)
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
N = int(input())
A = list(map(int, input().split()))
if gcd_list(A) != 1:
print('not coprime')
exit()
primes = set()
for a in A:
len_primes = len(primes)
divs = set(prime_factorize(a))
primes |= divs
if len(primes) != len_primes + len(divs):
print('setwise coprime')
exit()
print('pairwise coprime')
| 1 | 4,097,291,997,558 | null | 85 | 85 |
N=int(input())
L=list(map(int, input().split()))
count=0
for i in range(N-2):
for j in range(i+1,N-1):
for k in range(j+1,N):
if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
if max(L[i],L[j],L[k])<L[i]+L[j]+L[k]-max(L[i],L[j],L[k]):
count += 1
else:
pass
print(count)
|
import numpy as np
import scipy as sp
import math
a, b, c = map(int, input().split())
d = a + b + c
if(d<22):
print("win")
else:
print("bust")
| 0 | null | 62,234,611,697,060 | 91 | 260 |
N = int(input())
S = input()
ans = ""
for i in range(len(S)):
ord_c = ord(S[i])
# print(chr((ord_c + N - 65) % 26 + 65))
ans += chr((ord_c + N - 65) % 26 + 65)
print(ans)
|
N = int(input())
S = input()
ans = ""
for i in range(len(S)):
ans += chr(int(ord("A"))+(int(ord(S[i])+N)-int(ord("A")))%26)
print(ans)
| 1 | 134,570,183,210,762 | null | 271 | 271 |
s = input()
partition = s.replace('><','>|<').split('|')
ans=0
for sub in partition:
left = sub.count('<')
right = sub.count('>')
ans += sum(range(1, max(left, right) + 1))
ans += sum(range(1, min(left, right)))
print(ans)
|
str_search = input().upper()
int_cnt = 0
len_search = len(str_search)
while True:
str_line = input()
if str_line == "END_OF_TEXT":
break
str_line = str_line.upper()
int_cnt = int_cnt + str_line.split().count(str_search)
print(str(int_cnt))
| 0 | null | 79,230,072,386,626 | 285 | 65 |
import string
count = {x: 0 for x in string.ascii_lowercase}
lines = ""
while True:
try:
lines += input().lower()
except EOFError:
break
for c in lines:
if 'a' <= c <= 'z':
count[c] += 1
for key in string.ascii_lowercase:
print("{0} : {1}".format(key, count[key]))
|
A,B,C = map(int,input().split())
ans = A+B+C
if ans <= 21:
print('win')
else:
print('bust')
| 0 | null | 60,238,791,457,530 | 63 | 260 |
#
# author sidratul Muntaher
# date: Aug 19 2020
#
n = int(input())
from math import pi
print(pi* (n*2))
|
r = int(input())
print(r * 3.14159265 * 2);
| 1 | 31,605,736,187,992 | null | 167 | 167 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
A = LI()
c = 0
d = collections.Counter()
d[0] = 1
ans = 0
r = [0] * (N+1)
for i,x in enumerate(A):
if i >= K-1:
d[r[i-(K-1)]] -= 1
c = (c + x - 1) % K
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans)
if __name__ == '__main__':
main()
|
from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = S[i] + A[i]
d = defaultdict(int)
ans = 0
for j in range(N + 1):
v = (S[j] - j) % K
ans += d[v]
d[v] += 1
if j >= K - 1:
d[(S[j - K + 1] - (j - K + 1)) % K] -= 1
print(ans)
| 1 | 137,414,065,053,210 | null | 273 | 273 |
cnt = 0
def insertion_sort(seq, n, g):
global cnt
for i in range(g, n):
v = seq[i]
j = i - g
while j >= 0 and seq[j] > v:
seq[j + g] = seq[j]
j = j - g
cnt = cnt + 1
seq[j + g] = v
def shell_sort(seq, n):
g = 1
G = []
while g <= n:
G.append(g)
g = 3 * g + 1
print(len(G))
print(' '.join(map(str, reversed(G))))
for g in reversed(G):
insertion_sort(seq, n, g)
return seq
n = int(input())
a = [int(input()) for _ in range(n)]
ans = shell_sort(a, n)
print(cnt)
print('\n'.join(map(str, ans)))
|
def main():
a,b,c = map(int, input().split())
ab = [i for i in range(a, b + 1)]
cnt = 0 #count
for x in range(len(ab)):
if c % ab[x] == 0:
cnt += 1
else:
pass
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 299,253,548,580 | 17 | 44 |
MOD = 10**9 + 7
N, K = map(int, input().split())
As = list(map(int, input().split()))
def getInvs(n, MOD):
invs = [1] * (n+1)
for x in range(2, n+1):
invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
return invs
invs = getInvs(N, MOD)
def getCombKs(n, k, invs, MOD):
combKs = [0] * (n+1)
combKs[k] = 1
for x in range(k+1, n+1):
combKs[x] = (combKs[x-1] * x * invs[x-k]) % MOD
return combKs
combKs = getCombKs(N, K-1, invs, MOD)
As.sort()
ans = 0
for i, A in enumerate(As):
if i >= K-1:
ans += combKs[i] * A
if N-1-i >= K-1:
ans -= combKs[N-1-i] * A
ans %= MOD
print(ans)
|
def factorials(n,mod=10**9+7):
# 0~n!のリスト
f = [1,1]
for i in range(2,n+1):
f.append(f[-1]*i%mod)
# 0~n!の逆元のリスト
g = [1]
for i in range(n):
g.append(pow(f[i+1],mod-2,mod))
return f,g
def combination_mod(f,g,n,r,mod=10**9+7):
# nCr mod modを求める
nCr = f[n] * g[n-r] * g[r]
nCr %= mod
return nCr
def permutation_mod(f,g,n,r,mod=10**9+7):
# nPr mod modを求める
nPr = f[n] * g[n-r]
nPr %= mod
return nPr
n,k = map(int, input().split())
a = list(map(int, input().split()))
m = 10**9+7
a.sort()
f,g = factorials(n)
ans = 0
for i in range(k-1,n):
ans += combination_mod(f,g,i,k-1)*a[i]
for i in range(n-k+1):
ans -= combination_mod(f,g,n-i-1,k-1)*a[i]
while ans < 0:
ans += m
print(ans%m)
| 1 | 96,000,738,317,990 | null | 242 | 242 |
def is_stable(oline, line):
for i in range(N):
for j in range(i+1, N):
for a in range(N):
for b in range(a+1, N):
if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
return False
return True
N = int(input())
line = input().split()
oline = line.copy()
#BubbleSort
for i in range(N):
for j in range(N-1, i, -1):
if int(line[j][1]) < int(line[j-1][1]):
tmp = line[j]
line[j] = line[j-1]
line[j-1] = tmp
print(' '.join(line))
print(('Not stable', 'Stable')[is_stable(oline, line)])
#SelectionSort
line = oline.copy()
for i in range(N):
minj = i
for j in range(i+1, N):
if int(line[minj][1]) > int(line[j][1]):
minj = j
tmp = line[i]
line[i] = line[minj]
line[minj] = tmp
print(' '.join(line))
print(('Not stable', 'Stable')[is_stable(oline, line)])
|
def bubblesort(N, A):
C, flag = [] + A, True
while flag:
flag = False
for j in range(N-1, 0, -1):
if int(C[j][1]) < int(C[j-1][1]):
C[j], C[j-1] = C[j- 1], C[j]
flag = True
return C
def selectionSort(N, A):
C = [] + A
for i in range(N):
minj = i
for j in range(i,N):
if int(C[j][1]) < int(C[minj][1]):
minj = j
C[i], C[minj] = C[minj], C[i]
return C
N, A= int(input()), input().split()
Ab = bubblesort(N, A)
print(*Ab)
print('Stable')
As = selectionSort(N, A)
print(*As)
if Ab != As:
print('Not stable')
else:
print('Stable')
| 1 | 24,210,364,864 | null | 16 | 16 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
n = int(input())
A = list(map(int, input().split()))
ans = 1
mod = 10 ** 9 + 7
for i in range(n):
A[i] += 1
cnt = [0] * (n + 1) # cnt[i]は、Aのなかでこれまでに何個iが登場したか。つまりiの候補数。
cnt[0] = 3
for j in range(n):
i = A[j]
ans *= cnt[i - 1]
cnt[i - 1] -= 1
cnt[i] += 1
if cnt[i] > 3:
ans = 0
if cnt[i - 1] < 0:
ans = 0
print(ans % mod)
resolve()
|
N = int(input())
A = list(map(int, input().split()))
f = 0
if 0 in A:
print("0")
f = 1
else:
ans = A[0]
for i in range(1, N):
ans = ans * A[i]
if ans > 10**18:
print("-1")
f = 1
break
if f == 0:
print(ans)
| 0 | null | 73,288,789,241,350 | 268 | 134 |
import sys
r = int(sys.stdin.readline().rstrip())
def main():
print(r ** 2)
if __name__ == '__main__':
main()
|
n = int(input())
i,j=1,1
count=0
x = i*j
cc = n-x
while cc>=1:
cnt=0
while 1:
p = i*j
c = n - p
if c>=1:
#print(i,":",j,":",c)
j=j+1
cnt+=1
else:
j=i
break
count=count+((cnt*2)-1)
i=i+1
j=j+1
x = i*j
cc = n-x
print(count)
| 0 | null | 73,785,398,655,558 | 278 | 73 |
from itertools import accumulate, repeat, takewhile
(lambda n:
(lambda include3:
print('',
*filter(None,
map(lambda i: i if i % 3 == 0 else include3(i),
range(1, n+1)))))(
(lambda x:
next(map(lambda _: x,
filter(lambda d: d % 10 == 3,
takewhile(bool,
accumulate(repeat(x),
lambda a, _: a // 10)))),
None))))(int(input()))
|
def nabeatsu(n):
if(n % 3 == 0):
return True
temp = n
while(temp > 0):
if(temp % 10 == 3):
return True
temp = temp // 10
return False
x = int(input())
for i in range(x):
if(nabeatsu(i + 1)):
print(' ', end = '')
print(i + 1, end = '')
print()
| 1 | 925,761,557,268 | null | 52 | 52 |
n, a, b = map(int, input().split())
N = n//(a+b)
m = n%(a+b)
print(N*a+min(m,a))
|
n,x,y = map(int,input().split())
d = [0]*(n)
for i in range(1,n):
for j in range(i+1,n+1):
c = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
d[c] += 1
for i in range(1,n):
print(d[i])
| 0 | null | 49,952,972,817,728 | 202 | 187 |
def Judgement(x,y,z):
if z-x-y>0 and (z-x-y)**2-4*x*y>0:
return 0
else:
return 1
a,b,c=map(int,input().split())
ans=Judgement(a,b,c)
if ans==0:
print("Yes")
else:
print("No")
|
#!/usr/bin/env python
from sys import stdin, stderr
def main():
a, b, c = map(int, stdin.readline().split())
print('Yes' if c-a-b >= 0 and 4*a*b < (c-a-b)**2 else 'No')
return 0
if __name__ == '__main__': main()
| 1 | 51,666,791,657,746 | null | 197 | 197 |
import math
A, B, H, M = map(int, input().split())
deg_H = 360*(H+M/60)/12
deg_M = 360*M/60
theta = math.radians(abs(deg_H - deg_M))
ans = B**2 + A**2 - 2*A*B*math.cos(theta)
print(ans**0.5)
|
import math
def modcomb(n, k, mod, fac, ifac):
x = fac[n]
y = ifac[n-k] * ifac[k] % mod
#print(x * y % mod)
return x * y % mod
def makeTables(n, mod):
fac = [1, 1]
ifac = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
fac.append(i * fac[i-1] % mod)
inv.append(-inv[mod % i] * (mod // i) % mod)
ifac.append(inv[i] * ifac[i-1] % mod)
return fac, ifac
def answer(n, k, mod, fac, ifac):
if k >= n:
k = n - 1
ans = 0
for i in range(k+1):
c = modcomb(n, i, mod, fac, ifac) * modcomb(n-1, i, mod, fac, ifac) % mod
ans = (ans + c) % mod
return ans
n, k = map(int, input().split())
mod = 1000000007
fac, ifac = makeTables(n, mod)
print(answer(n, k, mod, fac, ifac))
| 0 | null | 43,455,448,220,292 | 144 | 215 |
N=int(input())
A=list(map(int,input().split()))
import itertools
ACU=itertools.accumulate(A)
B=list(ACU)
MAX=B[-1]
tmp=10**10
for i in B:
tmp=min(tmp,abs(2*i-MAX))
print(tmp)
|
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
N = k()
A = l()
S = sum(A)
minx = S
sum = 0
for x in A:
sum += x
minx = min(minx, abs(sum-(S-sum)))
print(minx)
| 1 | 142,456,607,777,670 | null | 276 | 276 |
from sys import exit
from math import gcd
n, m = map(int, input().split())
A = list(map(int, input().split()))
Count = [0] * n
div_A = [a // 2 for a in A]
def lcm(x, y):
return (x * y) // gcd(x, y)
for i, a in enumerate(div_A):
while a % 2 == 0:
Count[i] += 1
a //= 2
if len(set(Count)) != 1:
print(0)
exit()
lcm_num = 1
for div_a in div_A:
lcm_num = lcm(div_a, lcm_num)
if lcm_num > m:
print(0)
exit()
else:
print((m + lcm_num) // (2 * lcm_num))
|
def main():
from fractions import gcd
from math import ceil
n, m, *a = map(int, open(0).read().split())
b = [0 for _ in range(n)]
a.sort()
for i, j in enumerate(a):
c = 0
while j % 2 == 0:
c += 1
j = j // 2
a[i] = j
b[i] = c
if len(set(b)) > 1:
print(0)
exit()
lcm = 1
for i in a:
lcm = (lcm * i) // gcd(lcm, i)
k = b[0] - 1
ans = ceil(m // 2 ** k // lcm / 2)
print(ans)
if __name__ == "__main__":
main()
| 1 | 101,993,562,759,308 | null | 247 | 247 |
l=input().split()
n=int(l[0])
m=int(l[1])
#receive vecter a(n*m)
i=0
A=[]
while i<n:
a=input().split()
for p in a:
A.append(int(p))
i+=1
#receive vecter b(m*1)
I=0
B=[]
while I<m:
b=int(input())
B.append(b)
I+=1
#Ci=ai1b1+ai2b2+...+aimbm
#C[i]=a[m*(i)+1]*b[1]+a[m*(i)+2]*b[2]+...a[m*(i)+m]*b[m]
q=0
C=[]
while q<n:
Q=0
cq=0
while Q<m:
cq+=A[m*q+Q]*B[Q]
Q+=1
C.append(cq)
q+=1
for x in C:
print(x)
|
# -*- coding: utf-8 -*-
while True:
deck = str(raw_input())
if deck == '-':
break
m = int(raw_input())
for i in range(m):
h = int(raw_input())
deck = deck[h:] + deck[0:h]
print deck
| 0 | null | 1,505,989,246,258 | 56 | 66 |
import math
a,b = map(int,input().split())
c = math.ceil
min8, max8 = c(a*12.5), c((a+1)*12.5)
min10, max10 = c(b*10), c((b+1)*10)
l8, l10 = list(range(min8, max8)), list(range(min10, max10))
s8, s10 = set(l8), set(l10)
ss = s8 & s10
#print(min8, max8, min10, max10)
print(min(ss) if len(ss) >0 else -1)
#print(238*0.08)
|
import math
a,b=map(int,input().split())
ast=math.ceil(a*12.5)
aend=math.ceil((a+1)*12.5)-1
bst=b*10
bend=(b+1)*10-1
flag=0
for i in range(bst,bend+1):
if ast<=i<=aend:
print(i)
flag=1
break
if flag==0:
print(-1)
| 1 | 56,653,210,656,488 | null | 203 | 203 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
def solve(X: int, Y: int, Z: int):
return f"{Z} {X} {Y}"
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
Z = int(next(tokens)) # type: int
print(f'{solve(X, Y, Z)}')
if __name__ == '__main__':
main()
|
XYZ = list(map(int, input().split()))
ABC = [0]*3
for i in range(3):
ABC[i] = XYZ[(i+2)%3]
print(" ".join(map(str,ABC)))
| 1 | 38,269,728,121,982 | null | 178 | 178 |
n=input()
ans=0
for i in n:
ans+=int(i)
ans%=9
if ans==0:
print('Yes')
else:
print('No')
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [0] * (N + 1)
for k in range(K):
sta = [max(i-A[i], 0) for i in range(N)]
end = [min(i+A[i]+1, N) for i in range(N)]
for s in sta:
dp[s] += 1
for e in end:
dp[e] -= 1
for i in range(1, len(dp)-1):
dp[i] += dp[i-1]
B = dp[:-1]
if A == B:
break
A = B
dp = [0] * (N + 1)
print(' '.join(map(str, A)))
| 0 | null | 9,891,780,246,482 | 87 | 132 |
from bisect import bisect
import math
n,k=map(int,input().split())
A=list(map(int,input().split()))
l,r = 0,max(A)
while l < r - 1:
mid = (l+r)//2
cnt = 0
for a in A:
cnt += math.ceil(a/mid) - 1
#print(l,r,mid,cnt,k)
if cnt <= k:
r = mid
else:
l = mid
print(r)
|
###2分探索
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
p = 0###無理(そこまで小さくできない)
q = max(A)###可能
if K == 0:
print(q)
sys.exit(0)
while q-p > 1:
r = (p+q)//2
count = 0
for i in range(N):
if A[i]/r == A[i]//r:
count += A[i]//r - 1
else:
count += A[i]//r
if count > K:
p = r
else:
q = r
#print(p,q)
print(q)
| 1 | 6,556,851,719,902 | null | 99 | 99 |
import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
print(len(c))
|
import sys
from collections import Counter
N = int(input())
S = [str(s) for s in sys.stdin.read().split()]
items = list(dict.fromkeys(S))
print(len(items))
| 1 | 30,290,710,368,842 | null | 165 | 165 |
from collections import deque
n, q = map(int, input().split())
procs = deque([])
for i in range(n):
name, time = input().split()
time = int(time)
procs.append([name, time])
total = 0
while procs:
procs[0][1] -= q
if procs[0][1] > 0:
total += q
procs.append(procs.popleft())
else:
total += q + procs[0][1]
print(procs[0][0], total)
procs.popleft()
|
# coding: utf-8
import sys
import collections
def main():
n, quantum = map(int, raw_input().split())
processes = [x.split() for x in sys.stdin.readlines()]
for p in processes:
p[1] = int(p[1])
queue = collections.deque(processes)
elapsed = 0
while queue:
# print elapsed, queue
head = queue.popleft()
if head[1] > quantum:
head[1] -= quantum
queue.append(head)
elapsed += quantum
else:
elapsed += head[1]
print head[0], elapsed
if __name__ == '__main__':
main()
| 1 | 42,877,502,148 | null | 19 | 19 |
N = int(input())
X = str(input())
count = X.count("1")
num, nump, numm = 0, 0, 0
now, nowp, nowm = 1, 1, 1
if count == 0:
for i in range(N):
print(1)
quit()
elif count == 1:
if X[-1] == "1":
for i in range(N):
if i != N - 1:
print(2)
else:
print(0)
else:
for i in range(N):
if i!= N - 1:
if X[i] == "1":
print(0)
else:
print(1)
else:
print(2)
quit()
xx = [0] * N
x_plus = [0] * N
x_minus = [0] * N
for i in range(1, N + 1):
if i != 1:
now *= 2
nowp *= 2
now %= count
nowp %= (count + 1)
nowm *= 2
nowm %= (count - 1)
else:
now %= count
nowp %= (count + 1)
nowm %= (count - 1)
xx[i - 1] = now
x_plus[i - 1] = nowp
x_minus[i - 1] = nowm
if X[-i] == "1":
num += now
num %= count
nump += nowp
nump %= count + 1
numm += nowm
numm %= count - 1
#print(num, xx, x_plus, x_minus)
nextn = [0] * N
#ans = [1] * N
for i in range(N):
if X[i] == "0":
a = nump + x_plus[N - 1 - i]
b = count + 1
#print(a, b)
nextn[i] = a % b
else:
#if count == 2:
# nextn[i] = 0
#else:
a = numm - x_minus[N - 1 - i]
b = count - 1
nextn[i] = a % b
#print(nextn)
for i in range(N):
if nextn[i] == 0:
print("1")
else:
nownow = nextn[i]
ans = 1
while nownow != 0:
alpha = bin(nownow)[2:]
beta = str(alpha).count("1")
nownow %= beta
ans += 1
print(ans)
|
if __name__ == "__main__":
h1, m1, h2, m2, k = map(int, input().split())
print((h2-h1)*60+m2-m1-k)
| 0 | null | 13,183,903,443,480 | 107 | 139 |
number = int(input())
score = list(map(int,input().split()))
score.sort()
cancel = 0
for i in range(number-1):
if score[i] == score[i+1]:
cancel = 1
break
if cancel == 1:
print('NO')
else:
print('YES')
|
import sys
def main():
lines = sys.stdin.readlines()
A = []
B = []
C = []
n = 0
m = 0
for i, line in enumerate(lines):
# print(line)
# rm '\n' from string of a line
line = line.strip('\n')
elems = line.split(" ")
if i == 0:
n = int(elems[0])
m = int(elems[1])
elif 0 < i and i < n + 1:
A.append([int(e) for e in elems])
elif n < i:
B.append([int(elems[0])])
c = []
for i in range(0, n):
num = 0
for index, e in enumerate(A[i]):
num += e * B[index][0]
c.append(num)
for i in range(0, n):
print c[i]
if __name__ == "__main__":
main()
| 0 | null | 37,377,786,029,188 | 222 | 56 |
n=int(input())
lfb=[]
l=[]
for i in range(1,n+1):
if i%3==0:
lfb.append(i)
elif i%5==0:
lfb.append(i)
elif i%15==0:
lfb.append(i)
else:
l.append(i)
print(sum(l))
|
n, m = [int(i) for i in input().split()]
matrix = []
for ni in range(n):
matrix.append([int(a) for a in input().split()])
vector = []
for mi in range(m):
vector.append(int(input()))
b = []
for ni in range(n):
sum = 0
for mi in range(m):
sum += matrix[ni][mi] * vector[mi]
print(sum)
| 0 | null | 17,978,721,880,448 | 173 | 56 |
n = int(input())
data = list(map(int, input().split()))
ans = 0
money = 1000
for idx in range(n-1):
today = data[idx]
tmr = data[idx+1]
if tmr > today:
money += (tmr-today) * (money//today)
print(money)
|
n, x, t = map(int, input().split())
i = 0
while True:
i += 1
if i*x >= n :
break
print(i*t)
| 0 | null | 5,823,389,783,970 | 103 | 86 |
N = int(input())
s = [input().split() for _ in range(N)]
X = input()
for i in range(N):
if X == s[i][0]:
break
ans = 0
for j in range(i+1, N):
ans += int(s[j][1])
print(ans)
|
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(input())
s = [0] * n
t = [0] * n
for i in range(n):
s[i], t[i] = input().split()
t[i] = int(t[i])
x = input()
idx = s.index(x)
ans = 0
for i in range(idx+1, n):
ans += t[i]
print(ans)
if __name__ == '__main__':
main()
| 1 | 97,074,798,751,820 | null | 243 | 243 |
n,m = map(int,input().split())
print('Yes' if n<=m else 'No')
|
a, b, c, d = map(int,input().split(" "))
Ns = [a*c, a*d, b*c, b*d]
print(sorted(Ns)[-1])
| 0 | null | 43,255,731,496,338 | 231 | 77 |
import math
while True:
try:
a,b=list(map(int,input().split()))
x=math.gcd(a,b)
y=int(a*b/x)
print("%d %d"%(x,y))
except:
break
|
import math
H, W = map(int, raw_input().split())
while H > 0 or W > 0 :
print "#" * W
for i in xrange(H-2) :
print "#" + "." * (W-2) + "#"
print "#" * W
print
H, W = map(int, raw_input().split())
| 0 | null | 418,575,334,840 | 5 | 50 |
N=int(input())
f=[0]*(N+1)
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
temp=x**2+y**2+z**2+x*y+y*z+z*x
if temp<=N:
f[temp]+=1
for i in range(1,N+1):
print(f[i])
|
n = int(input())
ans = [0 for _ in range(10001)]
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 100):
v = x**2 + y**2 + z**2 + x*y + y*z + z*x
if v < 10001:
ans[v] += 1
for i in range(n):
print(ans[i+1])
| 1 | 7,994,696,512,742 | null | 106 | 106 |
import math
i = input().split()
n = int(i[0])
D = int(i[1])
num_list = []
count = 0
for i in range(n):
num_list.append(list(map(int,input().split())))
for j in num_list:
x = j[0]
y = j[1]
dist = math.sqrt(x ** 2 + y ** 2)
if dist <= D:
count += 1
print(count)
|
n,d=map(int, input().split())
xy=[]
ans = 0
for i in range(n):
x,y = map(int, input().split())
xy.append([x,y])
if d**2>=x**2+y**2:
ans += 1
print(ans)
| 1 | 5,984,468,071,780 | null | 96 | 96 |
from itertools import product
n = int(input())
info = {}
for p in range(n):
a = int(input())
L = []
for _ in range(a):
x,y = list(map(int, input().split()))
x,y = x-1, y
L.append((x,y))
info[p] = L
ans = 0
for bit_pattern in product(range(2), repeat=n):
for p,bit in enumerate(bit_pattern):
if bit:
if not all([bit_pattern[x] == y for x,y in info[p]]):
break
else:
ans = max(ans, sum(bit_pattern))
print(ans)
|
def main():
N = int(input())
shougen = []
for _ in range(N):
A = int(input())
shougen.append([list(map(int, input().split())) for _ in range(A)])
ans = 0
for i in range(2**N):
state = [1]*N
for j in range(N):
if (i >> j) & 1:
state[j] = 0
flag = True
for k in range(N):
if not flag:
break
if state[k] == 1:
for ele in shougen[k]:
if state[ele[0]-1] != ele[1]:
flag = False
break
if flag:
ans = max(ans, sum(state))
print(ans)
if __name__ == '__main__':
main()
| 1 | 121,554,718,608,242 | null | 262 | 262 |
alpha = input()
if ord(alpha) <= 90:
print('A')
else:
print('a')
|
A=input()
if str.isupper(A):
print('A')
else:
print('a')
| 1 | 11,320,489,967,952 | null | 119 | 119 |
A,B=map(int, input().split())
if A-B*2<0:
print('0')
else:
print(A-B*2)
|
A = input().split()
B = int(A[0]) - 2 * int(A[1])
print(0 if B < 0 else B)
| 1 | 167,038,757,174,940 | null | 291 | 291 |
X, K, D = map(int, input().split())
ans = abs(abs(X) - D*K)
a = abs(X)//D
b = abs(X)%D
if (K - a)%2 == 1 and a < K:
ans = D - b
elif (K - a)%2 == 0 and a < K:
ans = b
print(ans)
|
x,k,d=list(map(int,input().split()))
if k>=abs(x)//d:
y=abs(x)//d
ans=abs(abs(x)-y*d)
ans=abs(ans-((k-y)%2)*d)
else:
ans=abs(abs(x)-k*d)
print(ans)
| 1 | 5,229,340,188,332 | null | 92 | 92 |
h,n = map(int,input().split())
lst = list(map(int,input().split()))
if sum(lst) < h:
print('No')
else:
print('Yes')
|
def main():
H, N = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
if H > s:
print('No')
else:
print('Yes')
main()
| 1 | 78,310,210,601,700 | null | 226 | 226 |
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
if i % 2 == 0 and A[i] % 2 == 1:
ans += 1
print(ans)
|
mod = 10**9 + 7
def C():
N = int(input())
ans = 10**N - 2*9**N + 8**N
print(ans%mod)
def A():
N = int(input())
if( N == 0):
print(1)
else:
print(0)
A()
| 0 | null | 5,369,725,332,312 | 105 | 76 |
import math
def abc158c_tax_increase():
a, b = map(int, input().split())
for i in range(1001):
if math.floor(i*0.08) == a and math.floor(i*0.1) == b:
print(i)
return
print('-1')
abc158c_tax_increase()
|
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 21:57:22 2020
"""
import sys
#import numpy as np
sys.setrecursionlimit(10 ** 9)
#def input():
# return sys.stdin.readline()[:-1]
mod = 10**9+7
S = input()
if S[2] == S[3] and S[4] == S[5]:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| 0 | null | 49,207,048,825,642 | 203 | 184 |
def solve(n,x):
count = 0
for i in range(1,n+1):
for j in range(1,n+1):
if i == j :
continue
for k in range(1,n+1):
if j == k or i == k:
continue
if i+j+k == x:
count += 1
return count//6
while True:
n,x = map(int,input().split())
if n == x == 0:
break;
print(solve(n,x))
|
N = int(input())
for i in range(N):
sides = list(map(int, input().split()))
longestSide = max(sides)
sides.remove(longestSide)
if (longestSide ** 2) == (sides[0] ** 2 + sides[1] ** 2):
print('YES')
else:
print('NO')
| 0 | null | 660,241,814,368 | 58 | 4 |
n = int(input())
p = list(map(int, input().split()))
min = p[0]
count = 1
for i in range(1,n):
if p[i] <= min:
count += 1
min = p[i]
print(count)
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
n, *a = map(int, read().split())
p = np.array(a)
minp = np.minimum.accumulate(p)
r = 0
for i1, ae in enumerate(a):
r += minp[i1] >= ae
print(r)
if __name__ == '__main__':
main()
| 1 | 85,380,006,284,008 | null | 233 | 233 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
counter = Counter(A)
counter_sum = sum(k*v for k, v in counter.items())
for b, c in BC:
counter[c] += counter[b]
counter_sum -= b * counter[b]
counter_sum += c * counter[b]
counter[b] = 0
print(counter_sum)
|
def main():
_, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
if K == 0:
print(max(A))
return
def is_ok(x):
need = 0
for a in A:
if a % x == 0:
need += a//x - 1
else:
need += a//x
if need <= K:
return True
else:
return False
def binary_search():
ng = 0
ok = 10**9
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(binary_search())
if __name__ == '__main__':
main()
| 0 | null | 9,435,559,452,442 | 122 | 99 |
def bingo():
# 初期処理
A = list()
b = list()
comb_list = list()
is_bingo = False
# 入力
for _ in range(3):
dummy = list(map(int, input().split()))
A.append(dummy)
N = int(input())
for _ in range(N):
dummy = int(input())
b.append(dummy)
# ビンゴになる組み合わせ
for i in range(3):
# 横
comb_list.append([A[i][0], A[i][1], A[i][2]])
# 縦
comb_list.append([A[0][i], A[1][i], A[2][i]])
# 斜め
comb_list.append([A[0][0], A[1][1], A[2][2]])
comb_list.append([A[0][2], A[1][1], A[2][0]])
# 集計(出現した数字をnullに置き換え)
for i in b:
for j in range(8):
for k in range(3):
if i == comb_list[j][k]:
comb_list[j][k] = 'null'
# すべてnullのリストの存否
for i in comb_list:
for j in i:
if 'null' != j:
is_bingo = False
break
else:
is_bingo = True
# 一組でもbingoがあれば即座に関数を抜ける
if is_bingo == True:
return 'Yes'
# すべてのリストを確認後
if is_bingo == False:
return 'No'
result = bingo()
print(result)
|
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(A: "List[List[int]]", N: int, b: "List[int]"):
for i in b:
A = [[(a if a != i else 0) for a in l] for l in A]
return [NO, YES][any([not any(l) for l in [*A, *[[A[i][j] for i in range(3)] for j in range(3)], [A[0][0], A[1][1], A[2][2]], [A[2][0], A[1][1], A[0][2]]]])]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = [[int(next(tokens)) for _ in range(3)]
for _ in range(3)] # type: "List[List[int]]"
N = int(next(tokens)) # type: int
b = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(A, N, b)}')
if __name__ == '__main__':
main()
| 1 | 59,639,681,640,980 | null | 207 | 207 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
import math
from functools import reduce
n = int(readline())
a = list(map(int,readline().split()))
def lcm(x, y):
return (x * y) // math.gcd(x, y)
x = reduce(lcm, a)
ans = 0
for i in range(n):
ans += x // a[i]
print(ans%1000000007)
|
import collections
import math
n = int(input())
ai = [int(i) for i in input().split()]
mod = 10**9+7
if n == 1:
print(1)
exit()
# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
factor = {}
tmp = int(math.sqrt(n)) + 1
for num in range(2, tmp):
while n % num == 0:
n //= num
if not num in factor.keys():
factor[num] = 1
else:
factor[num] += 1
if num > n:
break
if n != 1:
if not n in factor.keys():
factor[n] = 1
else:
factor[n] += 1
return factor
dic = {}
for a in ai:
pr = prime(a)
for num, count in pr.items():
if not num in dic.keys():
dic[num] = count
else:
if dic[num] < count:
dic[num] = count
kari = 1
for num,count in dic.items():
kari *= pow(num,count,mod)
kari %= mod
kari_old = kari
ans = 0
for i in range(n):
kari = kari_old
#com_ab_new = copy.deepcopy(com_ab)
#print(com_ab,com_ab_new)
#kari = 1
#for j in range(kosu):
#kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
kari *= pow(ai[i],mod-2,mod)
ans += kari
ans %= mod
#print(ans)
#print(ans)
print(ans)
| 1 | 87,410,705,053,668 | null | 235 | 235 |
from math import *
def modpow(a,n,m):
res=1
while n>0:
if n&1:res=res*a%m
a=a*a%m
n//=2
return res
n,a,b=map(int,input().split())
mod=10**9+7
ans=modpow(2,n,mod)-1
na=1
nb=1
for i in range(a):
na*=(n-i)%mod
na%=mod
fa=1
for i in range(1,a+1):
fa*=i
fa%=mod
na*=modpow(fa,mod-2,mod)
for i in range(b):
nb*=(n-i)%mod
nb%=mod
fb=1
for i in range(1,b+1):
fb*=i
fb%=mod
nb*=modpow(fb,mod-2,mod)
print((ans-nb-na)%mod)
|
from collections import defaultdict
N, P = map(int, input().split())
S = input()
"""
S = "s0 s1 ... s(N-1)"に対して"sl s(l+1) ... s(r-1)"が素数Pで割り切れるかを考える。
これはa_i := int("si s(i+1) ... s(N-1)")と定めることで、
(a_l - a_r) / 10^{N-r} ¥cong 0 (mod P)
と定式化できる。
(整数関連の区間の問題は後ろからの累積和が相性良さそう。頭からの累積を考えたのが敗因な気がする)
Pが2でも5でもない場合は、上式は
a_l - a_r ¥cong 0 (mod P)
に同値であるから、各a_iのmod Pでの値を辞書にまとめておけば良さそう。
Pが2, 5のいずれかの場合は偶然チェックが簡単なので解ける。
"""
ans = 0
if P == 2:
for i in range(N):
a = int(S[i])
if a % 2 == 0:
ans += i + 1
elif P == 5:
for i in range(N):
a = int(S[i])
if a == 0 or a == 5:
ans += i + 1
else:
S += "0" # 上の定式化の都合上、r = Nのケースが必要なので
d = defaultdict(int)
r = 0
d[0] += 1
for i in range(N - 1, -1, -1):
"""
ここでS[i:]を毎回Pで割るとTLEする(桁の大きい演算はやはり負担が大きいのか?)
(a_i % P)をi = N, N-1,...の降順に求めていくことを考えれば、
前の計算結果が使える、特に繰り返し二乗法が使えるのでだいぶ早くなるみたい。
"""
r += int(S[i]) * pow(10, N - i - 1, P)
r %= P
d[r] += 1
for num in d.values():
ans += num * (num - 1) // 2
print(ans)
| 0 | null | 62,192,410,204,760 | 214 | 205 |
C =input()
L =[]
for i in range(97, 123):
L.append(chr(i))
print(L[ord(C)-96])
|
C = input()
C = ord(C)
C = C+1
print(chr(C))
| 1 | 92,579,095,802,718 | null | 239 | 239 |
N = input()
sum_n = 0
for n in N:
num = int(n)
sum_n += num
if(sum_n % 9 == 0):
print("Yes")
else:
print("No")
|
N=int(input())
if N%9==0:print("Yes")
else:print("No")
| 1 | 4,392,588,876,334 | null | 87 | 87 |
# -*- coding: utf-8 -*-
import sys
point = '.'
sharp = '#'
while True:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for h in xrange(H):
for w in xrange(W):
if h % 2 == 0:
if w % 2 == 0:
sys.stdout.write(sharp),
else:
sys.stdout.write(point),
else:
if w % 2 == 0:
sys.stdout.write(point)
else:
sys.stdout.write(sharp)
print
print
|
#!/usr/bin/python
ar = []
while True:
tmp = [int(i) for i in input().split()]
if tmp == [0,0]:
break
else:
ar.append(tmp)
for i in range(len(ar)):
for j in range(ar[i][0]):
for k in range(ar[i][1]):
if ( j + k ) % 2 == 0:
print('#' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n')
else:
print('.' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n')
| 1 | 899,086,808,658 | null | 51 | 51 |
n, k = map(int, input().split())
p_list = list(map(lambda x: int(x) - 1, input().split()))
c_list = list(map(int, input().split()))
max_score = -(1 << 64)
cycles = []
cycled = [False] * n
for i in range(n):
if cycled[i]:
continue
cycle = [i]
cycled[i] = True
while p_list[cycle[-1]] != cycle[0]:
cycle.append(p_list[cycle[-1]])
cycled[cycle[-1]] = True
cycles.append(cycle)
for cycle in cycles:
cycle_len = len(cycle)
accum = [0]
for i in range(cycle_len * 2):
accum.append(accum[-1] + c_list[cycle[i % cycle_len]])
cycle_score = accum[cycle_len]
max_series_sums = [max([accum[i + length] - accum[i]
for i in range(cycle_len)])
for length in range(cycle_len + 1)]
if cycle_len >= k:
score = max(max_series_sums[1:k + 1])
elif cycle_score <= 0:
score = max(max_series_sums[1:])
else:
max_cycle_num, cycle_rem = divmod(k, cycle_len)
score = max(cycle_score * (max_cycle_num - 1) + max(max_series_sums),
cycle_score * max_cycle_num + max(max_series_sums[:cycle_rem + 1]))
max_score = max(max_score, score)
print(max_score)
|
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()
def main():
n, k = map(int, input().split())
p = tuple(map(int, input().split()))
c = tuple(map(int, input().split()))
ans = -10**18
for i in range(n):
start, count = i, 1
val = c[start]
while p[start]-1 != i:
start = p[start]-1
count += 1
val += c[start]
start = i
if val > 0:
a = (k//count-1)*val
ans = max(a, ans)
num = count + k % count
else:
a = 0
num = min(k, count)
for _ in range(num):
a += c[start]
start = p[start] - 1
ans = max(a, ans)
print(ans)
if __name__ == '__main__':
main()
| 1 | 5,344,044,967,140 | null | 93 | 93 |
a,b=input().split()
a=int(a)
b=int(b)
e=a
d=b
c=1
if a>b:
for i in range(1,e):
if a%(e-i)==0 and b%(e-i)==0:
a=a/(e-i)
b=b/(e-i)
c=c*(e-i)
print(int(a*b*c))
if a<b:
for i in range(1,d):
if a%(d-i)==0 and b%(d-i)==0:
a=a/(d-i)
b=b/(d-i)
c=c*(d-i)
print(int(a*b*c))
|
# coding: utf-8
# Here your code !
ret = []
for i in range(10):
ret.append(int(input()))
ret.sort()
print(ret[-1])
print(ret[-2])
print(ret[-3])
| 0 | null | 56,477,271,164,640 | 256 | 2 |
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
N=I()
A=LI()
from collections import defaultdict
dd = defaultdict(int)
for i in range(N):
dd[A[i]]+=1
ans=0
for k,v in dd.items():
ans+=(v*(v-1))//2
for i in range(N):
a=A[i]
v=dd[A[i]]
temp=ans
temp-=(v*(v-1))//2
temp+=((v-1)*(v-2))//2
print(temp)
main()
|
N = int(input())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
from operator import mul
from functools import reduce
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, range(n, n - r, -1), 1)
denom = reduce(mul, range(1, r + 1), 1)
return numer // denom
ans = 0
for i in a:
if a[i] > 1:
ans += combinations_count(a[i],2)
for i in A:
n = a[i]
if n > 2:
print(ans+combinations_count(n-1,2)-combinations_count(n,2))
elif n == 2:
print(ans-1)
else:
print(ans)
| 1 | 47,596,813,187,616 | null | 192 | 192 |
while True:
h = input()
h_list = list(h)
if h == '-':
break
count = int(input())
for j in range(count):
count1 = int(input())
for i in range(0,count1):
h_list.append(h_list[0])
h_list.remove(h_list[0])
length = int(len(h_list))
for i in range(length):
print("{}".format(h_list[i]),end="")
print("")
|
print("bust") if sum(list(map(int,input().split()))) > 21 else print("win")
| 0 | null | 60,662,286,885,578 | 66 | 260 |
input_nums = map(int,raw_input().split())
men = input_nums[0] * input_nums[1]
syu = (input_nums[0] * 2) + (input_nums[1] * 2)
print "{0} {1}".format(men,syu)
|
a,b = raw_input().split(" ")
x = int(a)*2+int(b)*2
y = int(a)*int(b)
print "%d %d"%(y,x)
| 1 | 298,269,112,262 | null | 36 | 36 |
i = 0
while True :
x = int(input())
if(x == 0) :
break
else :
i += 1
print("Case ", i, ": ", x, sep = "")
|
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
def inverse(a, p):
"""逆元"""
a_, p_ = a, p
x, y = 1, 0
while p_:
t = a_ // p_
a_ -= t * p_
a_, p_ = p_, a_
x -= t * y
x, y = y, x
x %= p
return x
# from decorator import stop_watch
#
#
# @stop_watch
def solve(n, k):
mod = 10 ** 9 + 7
ans = 0
p_mod = [1, 1]
for i in range(2, n + 1):
p_mod.append((p_mod[-1] * i) % mod)
for i in range(min(n, k + 1)):
if i == 0:
ans += 1
elif i == 1:
ans += n * (n - 1)
else:
nCi = p_mod[n] * inverse(p_mod[n - i], mod) % mod * inverse(p_mod[i], mod) % mod
nmHi = (p_mod[n - 1] * inverse(p_mod[n - i - 1], mod) % mod) * inverse(p_mod[i], mod) % mod
# ans += cmb2(n, i, mod) * cmb2(n - 1, i, mod)
ans += nCi * nmHi % mod
ans %= mod
print(ans)
if __name__ == '__main__':
# S = input()
# N = int(input())
n, k = map(int, input().split())
# Ai = [int(i) for i in input().split()]
# Bi = [int(i) for i in input().split()]
# ABi = [[int(i) for i in input().split()] for _ in range(N)]
solve(n, k)
# # test
# from random import randint
# from func import random_str
# solve()
| 0 | null | 33,737,362,193,040 | 42 | 215 |
word = input()
n = int(input())
for _ in range(n):
meirei = input().split()
if meirei[0] == "print":
print(word[int(meirei[1]):int(meirei[2])+1])
elif meirei[0] == "reverse":
word = word[:int(meirei[1])] + word[int(meirei[1]):int(meirei[2])+1][::-1] + word[int(meirei[2])+1:]
elif meirei[0] == "replace":
word = word[:int(meirei[1])] + meirei[3] + word[int(meirei[2])+1:]
|
import sys
import math
def str_input():
S = raw_input()
if S[len(S)-1] == "\r":
return S[:len(S)-1]
return S
W = str_input()
cnt = 0
while 1:
S = str_input()
if (S == "END_OF_TEXT"):
break
S = S.lower().split()
cnt += S.count(W)
print cnt
| 0 | null | 1,944,490,914,028 | 68 | 65 |
from collections import deque
d = deque()
n = int(input())
for i in range(n):
s = input()
if s == "deleteFirst":
d.popleft()
elif s == "deleteLast":
d.pop()
elif s[:6] == "insert":
d.appendleft(int(s[7:]))
else:
delkey = int(s[7:])
if delkey in d:
d.remove(delkey)
print(" ".join(map(str,d)))
|
import collections,sys
def s():
d=collections.deque()
input()
for e in sys.stdin:
if'i'==e[0]:d.appendleft(e[7:-1])
else:
if' '==e[6]:
m=e[7:-1]
if m in d:d.remove(m)
elif len(e)%2:d.pop()
else:d.popleft()
print(*d)
s()
| 1 | 47,651,446,040 | null | 20 | 20 |
from queue import Queue
def isSafe(row, col):
return row >= 0 and col >= 0 and row<h and col<w and mat[row][col] != '#'
def bfs(row, col):
visited = [[False]*w for _ in range(h)]
que = Queue()
dst = 0
que.put([row, col, 0])
visited[row][col] = True
moves = [[-1, 0],[1, 0], [0, -1], [0, 1]]
while not que.empty():
root = que.get()
row, col, dst = root
for nrow, ncol in moves:
row2 = row + nrow
col2 = col + ncol
if isSafe(row2, col2) is True and visited[row2][col2] is False:
visited[row2][col2] = True
que.put([row2, col2, dst+1])
return dst
h, w = map(int, input().split())
mat = [input() for _ in range(h)]
ans = 0
for row in range(h):
for col in range(w):
if mat[row][col] == '.':
ans = max(ans, bfs(row, col))
print(ans)
|
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')
def main():
n = ri()
x = rs()
k = int(x, 2)
d = x.count('1')
if d > 1:
k0 = k % (d-1)
k1 = k % (d+1)
f = [0] * (n + 1)
for i in range(1, n+1):
f[i] = f[i % bin(i).count('1')] + 1
for i in range(n):
cnt = 0
if x[i] == '1' and d - 1 > 0:
cnt += f[(k0 - pow(2, n - i - 1, d - 1)) % (d - 1)] + 1
elif x[i] == '0':
cnt += f[(k1 + pow(2, n - i - 1, d + 1)) % (d + 1)] + 1
wi(cnt)
if __name__ == '__main__':
main()
| 0 | null | 51,252,986,518,262 | 241 | 107 |
N = int(input())
S = input()
A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
result = ''
for i in S:
ind = A.index(i)
ind += N
if ind > 25:
ind -= 26
result += A[ind]
print(result)
|
n = int(input())
s = input()
sl = list(s)
answer = ""
for i in s:
t = ord(i)+n
if t <= 90:
answer += chr(t)
else :
answer += chr(ord("A") + abs(t-90)-1)
print(answer)
| 1 | 134,352,336,312,220 | null | 271 | 271 |
def main():
l = []
for _ in range(10):
l.append(int(input()))
l = sorted(l, reverse=True)
for i in range(3):
print(l[i])
return None
if __name__ == '__main__':
main()
|
heights = []
for _ in range(10):
heights.append(int(input()))
heights.sort()
print(heights[9])
print(heights[8])
print(heights[7])
| 1 | 18,580,100 | null | 2 | 2 |
while True:
a = input()
if a == '-':
break
m = int(input())
for i in range(m):
h = int(input())
a = a[h:]+a[:h]
print(a)
|
def shuffle():
h = int(input())
for i in range(h):
s.append(s[0])
del s[0]
while True:
s = list(input())
if s == ['-']:
break
m = int(input())
for i in range(m):
shuffle()
print(''.join(s))
| 1 | 1,908,318,758,388 | null | 66 | 66 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.