code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
n=int(input())
A=list(map(int,input().split()))
r = [-1]*n
for i,a in enumerate(A):
r[a-1]=i+1
for r2 in r:
print(r2) | import sys
import numpy as np
import numba
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@jit
def main(n, a):
ans = np.zeros(n)
for i, j in enumerate(a):
ans[j-1] = i+1
for i in ans:
print(int(i), end=' ')
n = int(readline())
a = np.array(readline().split(), np.int64)
main(n,a) | 1 | 180,953,207,218,450 | null | 299 | 299 |
import sys
s = sys.stdin.readline().rstrip("\n")
print(s[:3]) | import random
name = list(input())
i = random.randint(0,len(name)-3)
print(name[i],end="")
print(name[i+1],end="")
print(name[i+2]) | 1 | 14,770,916,829,760 | null | 130 | 130 |
N = int(input())
for i in range(1, 50000):
pay = int(i*1.08)
if pay == N:
print(i)
break
elif pay > N:
print(':(')
break | import sys
n = int(input())
ans = n*100/108
for i in [int(ans), int(ans)+1]:
if int(i*1.08) == n:
print(i)
sys.exit()
print(":(")
| 1 | 125,520,497,945,720 | null | 265 | 265 |
from collections import defaultdict
import math
def main():
n = int(input())
mod = 1000000007
zeroes = 0
counter = defaultdict(lambda: defaultdict(int))
for _ in range(n):
x, y = [int(x) for x in input().split()]
if x == y == 0:
zeroes += 1
continue
denominator = math.gcd(x, y)
x, y = x // denominator, y // denominator
if y < 0:
# quadrant III, IV -> I, II
x, y = -x, -y
if x <= 0:
# round 90° from quadrant II to I
x, y = y, -x
counter[(x, y)][1] += 1
else:
counter[(x, y)][0] += 1
ans = 1
for v in counter.values():
now = 1
now += pow(2, v[0], mod) - 1
now += pow(2, v[1], mod) - 1
ans = ans * now % mod
ans += zeroes
ans -= 1 # choose no fish
return ans % mod
if __name__ == '__main__':
print(main())
| import sys
input=sys.stdin.buffer.readline
mod=10**9+7
n=int(input())
d={}
z=0
from math import gcd
for i in range(n):
x,y=map(int,input().split())
if x==y==0:z+=1
else:
f=gcd(x,y)
x//=f;y//=f
if x<0:x*=-1;y*=-1
if x==0 and y<0:y=-y
if (x,y)not in d:d[(x,y)]=1
else:d[(x,y)]+=1
ans=1
for (a,s) in d:
if d[(a,s)]==0:continue
ng=0
if (s,-a)in d:ng+=d[(s,-a)];d[(s,-a)]=0
if (-s,a)in d:ng+=d[(-s,a)];d[(-s,a)]=0
ans*=(pow(2,d[(a,s)],mod)-1 + pow(2,ng,mod)-1 +1)%mod
ans%=mod
d[(a,s)]=0
print((ans+z-1)%mod) | 1 | 21,031,393,202,500 | null | 146 | 146 |
N = int(input())
X = input()
n1 = X.count("1")
Xn = int(X, 2)
Xms = (Xn % (n1 - 1)) if n1 > 1 else 0
Xml = Xn % (n1 + 1)
def f(n):
if n == 0:
return 0
return f(n % bin(n).count("1")) + 1
dp = [0] * ((10 ** 5) * 2 + 1)
for i in range(1, len(dp)):
dp[i] = f(i)
for i in range(N):
cnt = 0
Xim = 0
if X[i] == "1" and n1 == 1:
print(cnt)
elif X[i] == "1":
print(dp[(Xms - pow(2, N - i - 1, n1 - 1)) % (n1 - 1)] + 1)
else:
print(dp[(Xml + pow(2, N - i - 1, n1 + 1)) % (n1 + 1)] + 1)
| import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
X = input()
pc = X.count("1")
if pc == 1:
if X[-1] == "0":
for i, s in enumerate(X):
if i == N - 1:
print(2)
elif s == "0":
print(1)
else:
print(0)
else:
ans = [2] * (N - 1) + [0]
print(*ans, sep="\n")
exit()
m01 = 0
m10 = 0
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
if s == "1":
m01 += b01
m01 %= pc + 1
m10 += b10
m10 %= pc - 1
b01 *= 2
b01 %= pc + 1
b10 *= 2
b10 %= pc - 1
def pop_count(T):
T = (T & 0x55555555) + ((T >> 1) & 0x55555555)
T = (T & 0x33333333) + ((T >> 2) & 0x33333333)
T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F)
T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF)
T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF)
return T
memo = [0] * (N + 10)
for i in range(1, N + 10):
p = pop_count(i)
memo[i] = memo[i % p] + 1
ans = [0] * N
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
if s == "0":
m = m01
m += b01
m %= pc + 1
else:
m = m10
m -= b10
m %= pc - 1
ans[i] = memo[m] + 1
b01 *= 2
b01 %= pc + 1
b10 *= 2
b10 %= pc - 1
print(*ans[::-1], sep="\n") | 1 | 8,266,081,255,552 | null | 107 | 107 |
H, M = map(int, input().split())
A = list(map(int, input().split()))
a = (sum(A))
if a >= H:
ans = "Yes"
else:
ans = "No"
print(ans)
| def get_depth(graph,tmp_depth,vertex_list,depth_list):
new_vertex_list=[]
for vertex in vertex_list:
for j in range(len(depth_list)):
if(graph[vertex][j]!=0 and depth_list[j]==-1):
depth_list[j]=tmp_depth + 1
new_vertex_list.append(j)
if(len(new_vertex_list)!=0):
get_depth(graph,tmp_depth+1,new_vertex_list,depth_list)
#グラフの作成
n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
tmp_ope=list(map(int,input().split()))
for j in range(tmp_ope[1]):
graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1
depth_list=[-1]*n
depth_list[0]=0
vertex_list=[0]
get_depth(graph,0,vertex_list,depth_list)
for i in range(n):
print(f"{i+1} {depth_list[i]}")
| 0 | null | 38,846,969,455,392 | 226 | 9 |
import random as random
s=input()
s_=s[:-2]
s1=random.choice(s_)
l=s_.index(s1)
s2=s[l+1]
s3=s[l+2]
s4=s1+s2+s3
print(s4) | ns = list(map(int, input().split()))
x = 0
for i in ns:
for j in range(3):
if ns[j] == i:
x += 1
o = 'Yes' if x == 5 else 'No'
print(o) | 0 | null | 41,287,020,273,184 | 130 | 216 |
A, B, N = map(int, input().split())
if B < N:
Max = int(A*(B-1)/B)
X = int(N/B)
fx = int(A*(B*X-1)/B) - A * int((B*X-1)/B)
# Max = max(fx,Max)
# for x in range(1,X):
# fx = int(A*x/B) - A * int(x/B)
# Max = max(Max,fx)
elif B == N:
Max = int(A*(B-1)/B)
else:
Max = int(A*N/B)
print(Max)
| import sys
input = sys.stdin.readline
def main():
a,b,n = map(int,input().split())
if n < b:
print((a*n)//b)
exit()
num = n//b
ans = (a*(b-1))//b
print(max(ans,(a*n)//b - a * (n//b)))
if __name__ == '__main__':
main()
| 1 | 28,163,010,927,880 | null | 161 | 161 |
K = int(input())
if K % 2 == 0:
print(-1)
exit()
num = 0
for i in range(1, K+1):
num = (num*10+7) % K
if num == 0:
print(i)
exit()
print(-1) | k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
mod = ((mod * 10) % k + 7) % k
if mod not in mod_map:
mod_map.add(mod)
else:
counter = -1
break
counter += 1
if mod == 0:
break
print(counter)
| 1 | 6,105,721,557,192 | null | 97 | 97 |
N = int(input())
for X in range(1, N+1):
if X*108//100==N:
print(X)
break
else:
print(':(') |
def main():
n = set(map(int, input().split()))
if len(n) == 2:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 0 | null | 97,381,239,000,160 | 265 | 216 |
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
leaf = sum(A)
ans = 0
node = 1
for i in range(N+1):
if A[i] > node or leaf == 0:
ans = -1
break
ans += node
leaf -= A[i]
node = min(2*(node-A[i]), leaf)
print(ans)
| n = int(input())
s = input()
a = s[:n//2]
b = s[n//2:]
if a == b:
print('Yes')
else:
print('No') | 0 | null | 82,871,253,641,988 | 141 | 279 |
N = int(input())
for i in range(1, 10):
if N % i == 0 and 1 <= N / i <= 9:
print('Yes')
exit()
print('No') | import sys
n = int(input())
for i in range(1,10):
mod,ret = divmod(n,i)
if ret == 0 and mod <= 9:
print('Yes')
sys.exit()
print('No') | 1 | 159,887,237,637,618 | null | 287 | 287 |
n, k = map(int, raw_input().split())
w = []
max = 0
sum = 0
for i in xrange(n):
w_i = int(raw_input())
if w_i > max:
max = w_i
sum += w_i
w.append(w_i)
def can_put(w, p, k):
weight = 0
cnt = 1
for w_i in w:
if weight + w_i <= p:
weight += w_i
else:
cnt += 1
if cnt > k:
return 0
else:
weight = w_i
return 1
low = max
high = sum
while low < high:
mid = (low + high) / 2
#print high, mid, low
if can_put(w, mid, k) == 1:
#print("*1")
high = mid
else:
#print("*0")
low = mid + 1
#print high, mid, low
print high | # -*- config: utf-8 -*-
if __name__ == '__main__':
while 1:
try:
nums = map(int,raw_input().split())
s = sum(nums)
print len(str(s))
except:
break | 0 | null | 41,864,715,942 | 24 | 3 |
n = input()
n2 = n * 2
x = input()
if x in n2:
print('Yes')
else: print('No')
| [print(i) for i in (sorted([int(input()) for _ in range(10)])[:6:-1])] | 0 | null | 877,864,182,272 | 64 | 2 |
x = int(input())
print("Yes" if x >= 30 else "No")
| X = int(input())
if X >= 30 :
print ('Yes')
else :
print ("No")
| 1 | 5,721,141,160,372 | null | 95 | 95 |
MOD = 10**9 + 7
N, K = map(int, input().split())
def getFacts(n, MOD):
facts = [1] * (n+1)
for x in range(2, n+1):
facts[x] = (facts[x-1] * x) % MOD
return facts
facts = getFacts(2*N, MOD)
def getInvFacts(n, MOD):
invFacts = [0] * (n+1)
invFacts[n] = pow(facts[n], MOD-2, MOD)
for x in reversed(range(n)):
invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
return invFacts
invFacts = getInvFacts(2*N, MOD)
def getComb(n, k, MOD):
if n < k:
return 0
return facts[n] * invFacts[k] * invFacts[n-k] % MOD
ans = 0
for x in range(min(K, N-1)+1):
ans += getComb(N, x, MOD) * getComb(N-1, x, MOD)
ans %= MOD
print(ans)
| from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))
a_count = Counter(a_input)
score_dic={}
exclude_dic={}
for k,v in a_count.items():
score_dic[k]=v*(v-1)//2
exclude_dic[k]=(v-1)*(v-2)//2
score_sum = sum(score_dic.values())
for i in range(n):
print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])
| 0 | null | 57,367,692,971,972 | 215 | 192 |
# coding: utf-8
"""this is python work script"""
def solver(trip_records):
"""solve this problem"""
answer = True
return answer
def main():
"""main function"""
name = input().rstrip()
print(name[:3])
if __name__ == '__main__':
main()
| n = int(input())
for i in range(1,10):
if (n%i==0) and ((n//i) in range(1,10)):
print("Yes")
break
else:
print("No") | 0 | null | 87,538,329,916,542 | 130 | 287 |
H,W = list(map(int,input().split()))
N=H*W
#壁のノード
wall=[]
for h in range(H):
for w_idx,w in enumerate(list(input())):
if w == '#':
wall.append(W*h+w_idx+1)
#道のノード
path=[_ for _ in range(1,N+1) if _ not in wall]
#隣接リスト
ad = {}
for n in range(N):
ad[n+1]=[]
for n in range(N):
n=n+1
if n not in wall:
up = n-W
if up > 0 and up not in wall:
ad[n].append(up)
down = n+W
if down <= N and down not in wall:
ad[n].append(down)
left = n-1
if n % W != 1 and left not in wall and left > 0:
ad[n].append(left)
right = n+1
if n % W != 0 and right not in wall:
ad[n].append(right)
from collections import deque
def BFS(start):
que = deque([start])
visit = deque([])
color = {}
for n in range(N):
color[n+1] = -1
color[start] = 0
depth = {}
for n in range(N):
depth[n+1] = -1
depth[start] = 0
while len(que) > 0:
start = que[0]
for v in ad[start]:
if color[v] == -1:
que.append(v)
color[v] = 0
depth[v] = depth[start]+1
color[start] = 1
visit.append(que.popleft())
return depth[start]
ans=-1
for start in path:
ans_=BFS(start)
if ans < BFS(start):
ans = ans_
# print(start,ans_)
print(ans) | n,k = map(int,input().split())
A = list(map(int,input().split()))
c = 0
from collections import Counter
d = 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#ここで範囲kからはみ出たものの数を減らす
c = (c+x-1)%k
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans) | 0 | null | 115,854,316,346,080 | 241 | 273 |
MAX = 600000
MOD = 10 ** 9 + 7
fac = [0] * MAX
ifac = [0] * MAX
fac[0] = 1
for i in range(1,MAX):
fac[i] = (fac[i-1] * i) % MOD
ifac[MAX-1] = pow(fac[MAX-1],MOD-2,MOD)
for i in reversed(range(1,MAX)):
ifac[i-1] = (ifac[i] * i) % MOD
def combinations(n, k):
if k < 0 or n < k:
return 0
else:
return (fac[n] * ifac[k] * ifac[n-k]) % MOD
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
com = [0]
for i in range(N):
com.append(A[i] + com[-1])
#print(com)
ans = 0
for i in range(K-2,N-1):
ans += combinations(i,K-2) * (-(com[N-i-1]) + (com[N]-com[i+1]))
#print(N-i-1,N,i+1)
ans %= MOD
#print(combinations(i,K-2) * (-(com[N-i-1]) + (com[N]-com[i+1])))
print(ans)
| from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
res = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
dist = [[-1] * w for _ in range(h)]
dist[i][j] = 0
d = deque()
d.append([i, j])
while d:
pos_x, pos_y = d.popleft()
dist_max = dist[pos_x][pos_y]
for k in range(4):
x, y = pos_x + dx[k], pos_y + dy[k]
if 0 <= x < h and 0 <= y < w and s[x][y] == "." and dist[x][y] == -1:
dist[x][y] = dist[pos_x][pos_y] + 1
d.append([x, y])
res = max(res, dist_max)
print(res) | 0 | null | 95,377,912,176,820 | 242 | 241 |
x = int(input())
x500 = x // 500
y = x - x500*500
y5 = y // 5
z = y - y5*5
print(x500*1000+y5*5) | import sys
x = int(sys.stdin.read())
c500, x = divmod(x, 500)
c5 = x // 5
print(c500 * 1000 + c5 * 5) | 1 | 42,854,088,273,700 | null | 185 | 185 |
class Dic:
def __init__(self):
self.end = False
self.a = self.c = self.g = self.t = 0
def insert(self, s):
node = self
index = 0
while index < len(s):
c = s[index]
child = 0
if c == 'A':
if not node.a:
node.a = Dic()
child = node.a
elif c == 'C':
if not node.c:
node.c = Dic()
child = node.c
elif c == 'G':
if not node.g:
node.g = Dic()
child = node.g
elif c == 'T':
if not node.t:
node.t = Dic()
child = node.t
else:
return
node = child
index += 1
node.end = True
def find(self, s):
node = self
index = 0
while index < len(s):
c = s[index]
child = 0
if c == 'A':
child = node.a
elif c == 'C':
child = node.c
elif c == 'G':
child = node.g
elif c == 'T':
child = node.t
if child == 0:
return False
node = child
index += 1
return node.end
dic = Dic()
n = int(input())
for _ in range(n):
cmd = list(input().split())
if cmd[0] == 'insert':
dic.insert(cmd[1])
elif cmd[0] == 'find':
print('yes' if dic.find(cmd[1]) else 'no')
| n=int(input())
m=100
y=0
while m < n:
m += m//100
y += 1
print(y) | 0 | null | 13,702,064,884,034 | 23 | 159 |
n = int(input())
a = []
b = []
for i in range(n):
a_1, b_1 = input().split()
a.append(int(a_1))
b.append(int(b_1))
a.sort()
b.sort()
is_odds = n % 2 == 0
if n % 2 == 0:
print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)
else:
print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1) | import statistics
def main():
n = int(input())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
a[i], b[i] = map(int, input().split())
amed = statistics.median(a)
bmed = statistics.median(b)
if n % 2:
print(int(bmed - amed + 1))
else:
print(int((bmed - amed) * 2 + 1))
if __name__ == '__main__':
main()
| 1 | 17,216,418,989,172 | null | 137 | 137 |
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
ruiseki = [0]
d = defaultdict(int)
d[0]=1
for i in range(n):
if i - k + 1>= 0:
d[ruiseki[i - k+1]]-=1
ruiseki.append((ruiseki[i] + a[i] - 1)%k)
ans += d[ruiseki[i+1]]
d[ruiseki[i + 1]] += 1
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
n,k = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9 + 7
# from random import randint
# n = 10
# k = 4
# A = []
# for i in range(10):
# A.append(randint(-20,20))
# anss=0
# for i in range(n):
# for j in range(i+1,n):
# for ii in range(j+1,n):
# for jj in range(ii+1,n):
# anss = max(anss, A[i]*A[j]*A[ii]*A[jj])
# print(anss)
# print(A)
B = [[], []]
for i in range(n):
if A[i] >= 0:
B[0].append(A[i])
else:
B[1].append(A[i])
B[0].sort(reverse=True)
B[1].sort()
if k % 2 == 1 and len(B[0]) == 0:
ans = 1
ind = len(B[1])-1
for i in range(k):
ans = (ans * B[1][ind]) % mod
ind -= 1
print(ans)
elif k == n and len(B[1]) % 2 == 1:
ans = 1
for i in range(n):
ans = (ans * A[i]) % mod
print(ans)
else:
k0 = min(len(B[0]), k)
k1 = k-k0
if k1%2==1:
k0 -= 1
k1 += 1
# print(B,k0,k1)
while k1+1 < len(B[1]) and k0-2 >= 0 and B[1][k1]*B[1][k1+1] > B[0][k0-1]*B[0][k0-2]:
k1 += 2
k0 -= 2
# print(k0,k1)
# print(k1+1 < len(B[1]),B[1][k1]*B[1][k1+1] , B[0][k0-1]*B[0][k0-2])
ans = 1
for i in range(k0):
ans = (ans * B[0][i]) % mod
for i in range(k1):
ans = (ans * B[1][i]) % mod
print(ans)
| 0 | null | 73,299,647,159,008 | 273 | 112 |
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
S = input().strip()
counter = Counter(S)
if len(counter) < 3:
print(0)
sys.exit()
exclude = 0
max_w = N // 2
for w in range(1, max_w+1):
for i in range(N):
if N <= i + 2*w:
continue
if S[i] != S[i+w] and S[i] != S[i+2*w] and S[i+w] != S[i+2*w]:
exclude += 1
# print(exclude)
print(counter["R"] * counter["G"] * counter["B"] - exclude) | n = int(input())
s = input()
rs = [0]*n
gs = [0]*n
bs = [0]*n
for i in reversed(range(n)):
if s[i] == 'R':
rs[i] += 1
elif s[i] == 'G':
gs[i] += 1
else:
bs[i] += 1
for i in reversed(range(n-1)):
rs[i] += rs[i+1]
gs[i] += gs[i+1]
bs[i] += bs[i+1]
res = 0
for i in range(n):
for j in range(i+1,n-1):
if s[i] == s[j]:
continue
if s[i]!='B' and s[j]!='B':
res += bs[j+1]
if j-i+j < n:
if s[j-i+j] == 'B':
res -=1
elif s[i]!='G' and s[j]!='G':
res += gs[j+1]
if j - i + j < n:
if s[j-i+j] == 'G':
res -=1
else:
res += rs[j+1]
if j - i + j < n:
if s[j-i+j] == 'R':
res -= 1
print(res) | 1 | 36,239,910,826,460 | null | 175 | 175 |
from enum import Enum
from queue import Queue
import numpy as np
import collections
import bisect
import sys
import math
from scipy.sparse.csgraph import floyd_warshall
BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001
def warshall_floyd(d,n):
#d[i][j]:iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
N,M,L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
a,b,c = map(int,input().split())
d[a-1][b-1] = c
d[b-1][a-1] = c
for i in range(N):
d[i][i] = 0
d = floyd_warshall(d)
for i in range(N):
for j in range(i,N):
if d[i][j] <= L:
d[i][j] = 1
d[j][i] = 1
else:
d[i][j] = float("inf")
d[j][i] = float("inf")
d[i][i] = 1
d = floyd_warshall(d)
Q = int(input())
for q in range(Q):
s,t = map(int,input().split())
if d[s-1][t-1] == float("inf"):
print(-1)
else:
print(int(d[s-1][t-1])-1)
| import sys
from copy import deepcopy
def main():
INF = 10**18
input = sys.stdin.readline
N, M, L = [int(x) for x in input().split()]
d = [set() for _ in range(N+1)]
ds = [[INF] * (N+1) for _ in range(N+1)]
bs = [[INF] * (N+1) for _ in range(N+1)]
for _ in range(M):
A, B, C = [int(x) for x in input().split()]
A, B = sorted([A, B])
d[A].add(B)
if L >= C:
ds[A][B] = C
nes = set()
for k in range(1, N+1):
for i in range(1, N+1):
for j in range(i+1, N+1):
ds[i][j] = min(ds[i][j], ds[min(i, k)][max(i, k)] + ds[min(k, j)][max(k, j)])
if ds[i][j] <= L:
bs[i][j] = 1
for k in range(1, N+1):
for i in range(1, N+1):
for j in range(i+1, N+1):
bs[i][j] = min(bs[i][j], bs[min(i, k)][max(i, k)] + bs[min(k, j)][max(k, j)])
Q, = [int(x) for x in input().split()]
for _ in range(Q):
s, t = sorted(int(x) for x in input().split())
print(bs[s][t]-1 if bs[s][t] < INF else -1)
if __name__ == '__main__':
main()
| 1 | 174,283,189,976,378 | null | 295 | 295 |
a, b, n = [int(x) for x in input().split()]
n = min(n,b-1)
x = max(0,n-a-a-a-a)
s = -a
for i in range(x,n+1):
s = max(s,(a*i//b)-a*(i//b))
print(s)
| A,B,N=map(int,input().split())
if B>N:
print((A*N)//B-A*(N//B))
else:
print((A*(B-1)//B-A*((B-1)//B))) | 1 | 28,259,061,163,302 | null | 161 | 161 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
A, B = input().split()
B = int(''.join(B.split('.')))
print(int(A)*B//100) | import decimal
a,b = map(decimal.Decimal,input().split())
ans = a*b//1
print(ans)
| 1 | 16,416,360,418,272 | null | 135 | 135 |
import math
n=int(input())
s=0
for i in range(n):
a=int(input())
#b=int(a**0.5)
b=math.ceil(a**0.5)
#print(str(b), '??O')
if a==2:
s+=1
# print(str(a),'!!!!')
elif a%2==0 or a < 2:
continue
else:
j=3
c=0
while j <= b:
if a%j==0:
c+=1
break
j+=2
if c==0:
s+=1
"""
for j in range(3,b+1,2):
if a%j==0:
break
if j==b:
s+=1
print(str(a),'!!!!')
"""
print(s) | n = int(input())
a = list(map(int, input().split()))
def buy(money, stock, p):
amount = money // p
return (money - amount * p), amount
def sell(money, stock, p):
return (money + stock * p), 0
money = 1000
stock = 0
for i, (p, q) in enumerate(zip(a[:-1], a[1:])):
if stock == 0 and p < q:
money, stock = buy(money, stock, p)
elif stock and p > q:
money, stock = sell(money, stock, p)
if stock:
money += stock * a[-1]
print(money)
| 0 | null | 3,659,056,335,900 | 12 | 103 |
N, M = [int(x) for x in input().split()]
result = N * (N - 1) // 2 + M * (M - 1) // 2
print(result)
|
#atcoder
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
d1=a1-b1
d2=a2-b2
if d1*d2>0:
print(0)
else:
if d1>0 and d2<0:
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
d=-plus
k=d1*t1
if k%d==0:
print(2*k//d)
else:
print(2*(k//d)+1)
else:
d1=-d1
d2=-d2
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
d=-plus
k=d1*t1
if k%d==0:
print(2*k//d)
else:
print(2*(k//d)+1)
| 0 | null | 88,644,667,587,050 | 189 | 269 |
from collections import deque
n = int(input())
adj = [[]]
for i in range(n):
adj.append(list(map(int, input().split()))[2:])
ans = [-1]*(n+1)
ans[1] = 0
q = deque([1])
visited = [False] * (n+1)
visited[1] = True
while q:
x = q.popleft()
for y in adj[x]:
if visited[y] == False:
q.append(y)
ans[y] = ans[x]+1
visited[y] = True
for j in range(1, n+1):
print(j, ans[j])
| list=[0 for i in range(10**4+1)]
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
var=x**2 +y**2 +z**2 +x*y +y*z +z*x
if var<=10**4:
list[var]+=1
n=int(input())
for i in range(1,n+1):
print(list[i]) | 0 | null | 3,951,794,590,170 | 9 | 106 |
import math
X = int(input())
ans = 0
while ans == 0:
factor = 0
if X % 2 == 0 and X != 2:
X +=1
continue
for divisor in range(2, X // 2):
if X % divisor == 0:
factor += 1
if factor == 0:
ans =X
X +=1
print(ans) | pi = 3.141592653589793
r = float(input())
print('{0:f} {1:f}'.format(r*r*pi, 2 * r * pi)) | 0 | null | 53,079,047,211,838 | 250 | 46 |
s=list(input())
a=list(set(s))
print('Yes') if 'A' in a and 'B' in a else print('No') | a = input()
if a == 'AAA' or a == 'BBB' :
print('No')
else :
print('Yes') | 1 | 54,909,597,640,480 | null | 201 | 201 |
in_sec = int(raw_input())
sec = in_sec%60
in_sec = (in_sec-sec)/60
min = in_sec%60
h = (in_sec-min)/60
print str(h) + ":" + str(min) + ":" + str(sec) | print("YNeos"["".join(input().split("hi"))!=""::2]) | 0 | null | 26,702,182,398,368 | 37 | 199 |
n = int(input())
s = list(str(n))
r = list(reversed(s))
if r[0] in ["2","4","5","7","9"]:
print("hon")
elif r[0] in ["0","1","6","8"]:
print("pon")
else:
print("bon") | n, m, k = map(int, input().split())
friendships = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
friendships[a-1].append(b-1)
friendships[b-1].append(a-1)
blockships = [[] for _ in range(n)]
for _ in range(k):
c, d = map(int, input().split())
blockships[c-1].append(d-1)
blockships[d-1].append(c-1)
# assign users (id) for connected component, according to friendships
# also increment a counter for size of each component
component_id = [-1]*n
component_size = dict()
stack_to_visit = [(node, node) for node in range(n)]
while stack_to_visit:
node, parent_id = stack_to_visit.pop()
if component_id[node] != -1:
continue
component_id[node] = parent_id
component_size[parent_id] = component_size.get(parent_id, 0) + 1
for other in friendships[node]:
stack_to_visit.append((other, parent_id))
# calculate number of suggestions for each node
for node in range(n):
suggestions = 0
current_id = component_id[node]
suggestions += component_size[current_id] - 1
suggestions -= len(friendships[node])
suggestions -= sum(int(component_id[other] == current_id) for other in blockships[node])
print(suggestions, end=" ") | 0 | null | 40,355,457,614,310 | 142 | 209 |
H, W, K = map(int, input().split())
C = [[(c=="#") for c in input()] for _ in range(H)]
cnt0 = sum(sum(c) for c in C)
ans = 0
for sy in range(1<<H):
for sx in range(1<<W):
D = [c.copy() for c in C]
cnt = cnt0
for y in range(H):
for x in range(W):
if sy>>y&1 | sx>>x&1:
cnt -= D[y][x]
D[y][x] = False
if cnt == K:
ans += 1
print(ans)
| n = int(input())
MOD = 10 ** 9 + 7
ans = (pow(10, n, MOD) - 2 * pow(9, n, MOD) + pow(8, n, MOD))%MOD
print(ans) | 0 | null | 6,048,839,413,132 | 110 | 78 |
n = int(input())
taro = 0
hana = 0
for _ in range(n):
taro_c, hana_c = input().split()
if taro_c > hana_c:
taro += 3
elif hana_c > taro_c:
hana += 3
else:
taro += 1
hana += 1
print(taro, hana) | n = int(input())
a = 0
b = 0
for i in range(n):
t1,t2 = input().split()
if t1>t2:
a+=3
elif t1==t2:
a+=1
b+=1
else:
b+=3
print(a,b)
| 1 | 1,992,102,226,480 | null | 67 | 67 |
# ????????? str ?????????????????????????????????????????????????????????????????°??????
# ?????\????±??????????str????¨??????\???????????????
str = list(input())
str = "".join(str)
# ?????\???????????°p????¨??????\???????????????
p = int(input())
# p??????????????????????????????????????????
orderList = [0 for i in range(p)]
for i in range(0, p):
orderList[i] = list(input())
orderList[i] = "".join(orderList[i]).split()
if orderList[i][0] == "print":
print("{0}".format(str[int(orderList[i][1]):int(orderList[i][2]) + 1]))
elif orderList[i][0] == "reverse":
str = str[0:int(orderList[i][1])] + str[-len(str) + int(orderList[i][2]):-len(str) + int(orderList[i][1]) - 1:-1] + str[int(orderList[i][2]) + 1:]
elif orderList[i][0] == "replace":
str = str[:int(orderList[i][1])] + orderList[i][3] + str[int(orderList[i][2]) + 1:] | x, y = map(int, input().split())
if y > x * 4:
print("No")
else:
for i in range(x + 1):
if 2 * i + 4 * (x - i) == y:
str = 'Yes'
break
else:
str = 'No'
print(str)
| 0 | null | 7,833,618,951,964 | 68 | 127 |
n, m = map(int, input().split())
if n % 2 == 1:
for i in range(m):
print(i + 1, n - i)
else:
for i in range(m):
if 2 * (i + 1) <= m + 1:
print(i + 1, n - i)
else:
print(i + 1, n - i - 1) | n, m = map(int, input().split())
if n % 2 or m < n//4:
for i in range(m):
print(i+1, n-i)
else:
for i in range(n//4):
print(i+1, n-i)
for i in range(n//4, m):
print(i+1, n-i-1) | 1 | 28,615,241,428,502 | null | 162 | 162 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s=input()
if len(s)%2==1:
print("No")
sys.exit()
for i in range(len(s)//2):
if s[2*i:2*i+2]!="hi":
print("No")
break
else:print("Yes")
if __name__=='__main__':
main() | while True:
H, W = [int(x) for x in input().split(" ")]
if H == 0 and W == 0: exit()
for i in (range(H)):
print("#"*W)
print("") | 0 | null | 26,944,808,986,744 | 199 | 49 |
K=int(input())
A=0
for i in range(K):
A=(A*10+7)%K
if A%K==0:
print(i+1)
break
if i==K-1:print(-1) | H, W, M = map(int, input().split())
hallline = [0 for i in range(H)]
wallline = [0 for i in range(W)]
b = {}
for i in range(M):
tmp = list(map(lambda x: int(x) - 1, input().split()))
hallline[tmp[0]] += 1
wallline[tmp[1]] += 1
b[(tmp[0], tmp[1])] = True
t = max(hallline)
s = max(wallline)
a = [i for i in range(H) if hallline[i] == t]
c = [i for i in range(W) if wallline[i] == s]
tmp = False
for i in a:
for j in c:
if (i, j) not in b.keys():
print(t + s)
tmp = True
break
if tmp:
break
if not tmp:
print(t + s - 1)
| 0 | null | 5,467,949,755,758 | 97 | 89 |
X,Y = map(int,input().split())
for i in range(X+1):
a = i*2 + (X-i)*4
if a == Y:
print("Yes")
break
if a != Y:
print("No")
| M,N = map(int,input().rstrip().split(" "))
ans=False
for a in range(M + 1):
b=M-a
if 2 * a + 4 * b == N:
ans=True
if ans:
print("Yes")
else:
print("No") | 1 | 13,816,986,041,658 | null | 127 | 127 |
N = int(input())
S = list(input())
ans = 'No'
n = int(N / 2)
if S[:n] == S[n:]:
ans = 'Yes'
print(ans) | N = int(input())
S = input()
print('Yes' if (N % 2 == 0) and (S[:N // 2] == S[N // 2:]) else 'No')
| 1 | 146,394,512,131,910 | null | 279 | 279 |
N=int(input())
A=list(map(int,input().split()))
ans=0
tree=1
node=sum(A)
flag=0
for i in A:
ans+=i
node-=i
if i>tree:
ans=-1
break
tree-=i
if tree<node:
ans+=tree
else:
ans+=node
tree=2*tree
print(ans) | n = int(input())
a = list(map(int, input().split()))
node_max = [1]
for i in range(1, n+1):
node_max.append(min(10**18, node_max[i-1]*2-a[i]))
a.reverse()
node_max.reverse()
node_max2 = [a[0]]
node_min2 = [a[0]]
for i in range(n):
node_max2.append(node_max2[-1]+a[i+1])
node_min2.append((node_min2[-1]+1)//2+a[i+1])
if node_min2[-1] != 1:
print(-1)
else:
ans = 0
for i in range(n+1):
ans += min(node_max[i]+a[i], node_max2[i])
print(ans)
| 1 | 18,894,915,257,120 | null | 141 | 141 |
def main():
a = list(map(int, input().split()))
if sum(a[:]) >= 22:
print('bust')
else:
print('win')
if __name__ == "__main__":
main()
| print('win' if sum(map(int, input().split())) < 22 else 'bust') | 1 | 118,606,111,138,492 | null | 260 | 260 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
dp = [False] * 100001
dp[0] = True
food = [100,101,102,103,104,105]
for i in range(1,100001):
for j in range(len(food)):
if i - food[j] >= 0:
dp[i] |= dp[i - food[j]]
X = I()
print('1' if dp[X] else '0')
|
X = int(input())
c = X // 100
if c * 100 <= X <= c * 105:
print(1)
else:
print(0)
| 1 | 127,477,644,975,548 | null | 266 | 266 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for i in range(H):
print('#', end='')
for j in range(W-2):
if i > 0 and i < H - 1:
print('.', end='')
else:
print('#', end='')
print('#')
print() | while True:
H,W = map(int,raw_input().split())
if (H,W) == (0,0):
break
for k in range(H):
if k==0 or k==H-1:
print "#"*W
else:
print "#" + "." * (W-2) + "#"
print "" | 1 | 819,848,987,618 | null | 50 | 50 |
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) | s1 = input()
s2 = input()
ans = 0
for i in range(len(s1)):
if s1[i] != s2[i]:
ans += 1
print(ans) | 1 | 10,518,813,934,528 | null | 116 | 116 |
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(m)]
C = []
B_T = list(zip(*B))
for a_row in A:
C.append([sum(a * b for a, b, in zip(a_row, b_column)) for b_column in B_T])
for row in C:
print(' '.join(map(str, row))) | N, X, M = map(int, input().split())
if X <= 1:
print(X*N)
exit()
check = [0]*(M+1)
check[X] += 1
A = X
last_count = 0
while True:
A = (A**2)%M
if check[A] != 0:
last_count = sum(check)
target_value = A
break
check[A] += 1
A2 = X
first_count = 0
while A2 != target_value:
first_count += 1
A2 = (A2**2)%M
roop_count = last_count-first_count
A3 = target_value
mass = A3
for i in range(roop_count-1):
A3 = (A3**2)%M
mass += A3
if roop_count == 0:
print(N*X)
exit()
if first_count != 0:
ans = X
A = X
for i in range(min(N,first_count)-1):
A = (A**2)%M
ans += A
else:
ans = 0
if N > first_count:
ans += ((N-first_count)//roop_count)*mass
A4 = target_value
if (N-first_count)%roop_count >= 1:
ans += A4
for i in range(((N-first_count)%roop_count)-1):
A4 = (A4**2)%M
ans += A4
print(ans) | 0 | null | 2,146,118,249,382 | 60 | 75 |
N=int(input())
a = list(map(int,input().split()))
s = a[0]
for i in range(1,len(a)):
s ^= a[i]
#print(a[i])
#print(s)
for i in range(len(a)):
#print(s,a[i])
ans = s^a[i]
print(ans,end=" ")
| #coding:utf-8
class Combination:
def __init__(self,N,P=10**9+7):
if N > 10**7:
self.fact = lambda x: x * self.fact(x-1) % P if x > 2 else 2
self.perm = lambda x, r: x * self.perm(x-1,r-1) % P if r > 0 else 1
self.cmb = lambda n,r: (self.perm(n,min(n-r,r)) * pow(self.fact(min(n-r,r)) ,P-2 ,P) % P) if r > 0 else 1
else:
self.__fact = [1] * (N+1)
self.__inv = [1] * (N+1)
self.__inv_fact = [1] * (N+1)
for i in range(2,N+1):
self.__fact[i] = self.__fact[i-1] * i % P
self.__inv[i] = - self.__inv[P%i] * (P//i) % P
self.__inv_fact[i] = self.__inv_fact[i-1] * self.__inv[i] % P
self.fact = lambda n: self.__fact[n]
self.perm = lambda n,r: self.__fact[n] * self.__inv_fact[n-r] % P
self.cmb = lambda n,r: (self.__fact[n] * self.__inv_fact[n-r] * self.__inv_fact[r] % P) if r > 0 else 1
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
from collections import deque
n,k = LMIIS()
cmb = Combination(2*n)
ans = 1
for i in range(1,min(n,k+1)):
ans = (ans + cmb.cmb(n,i) * cmb.cmb(n-1,i)) % MOD
print(ans)
if __name__ == '__main__':
main() | 0 | null | 39,962,794,656,052 | 123 | 215 |
a, b, c , d = map(int, input().split())
M = b * d;
if M < a * c:
M = a*c;
if M < b * c:
M = b*c;
if M < a * d:
M = a * d;
print (M); | #!/usr/bin/env python3
import sys
import math
def solve(H: int, W: int):
if W == 1 or H == 1:
# coner case
print(1)
else:
print(math.ceil(W * H / 2))
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
H = int(next(tokens)) # type: int
W = int(next(tokens)) # type: int
solve(H, W)
if __name__ == "__main__":
main()
| 0 | null | 26,838,745,037,510 | 77 | 196 |
ans = list(map(int,input().split()))
print(ans[2],ans[0],ans[1])
| a,b,c=list(map(int,input().split()))
print(c,a,b) | 1 | 37,886,902,245,610 | null | 178 | 178 |
a=int(input())
b=int(input())
ab={a,b}
s={1,2,3}
ss=s-ab
print(list(ss)[0]) | N = int(input())
S = input()
ans = 0
for i in range(10):
for j in range(10):
for k in range(10):
a = [i, j, k]
l = 0
for s in S:
if l < 3 and a[l] == int(s):
l += 1
if l == 3:
ans += 1
print(ans)
| 0 | null | 120,202,156,193,940 | 254 | 267 |
x = int(input())
yen_500 = 0
yen_5 = 0
amari = 0
happy = 0
if x>= 500:
yen_500 = x//500
amari = x - 500 * yen_500
yen_5 = amari//5
happy = 1000 * yen_500 + 5 * yen_5
print(happy)
else:
yen_5 = x//5
happy = 5 * yen_5
print(happy)
| x = int(input())
n_500 = int(x / 500)
h = 1000 * n_500
x -= 500 * n_500
n_5 = int(x / 5)
h += 5 * n_5
print(int(h))
| 1 | 42,849,791,191,296 | null | 185 | 185 |
n=int(input())
A=list(map(int,input().split()) )
A.sort()
furui = [0] * (max(A) + 1)
for i in A:
if furui[i] >= 2:
continue
for j in range(i,len(furui),i):
furui[j] += 1
ans=0
for i in A:
if furui[i]==1:
ans+=1
print(ans) | #import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
S = set(A)
maxA = A[-1]
chk = [0] * (maxA+1)
for s in S:
for i in range(s, maxA+1, s):
chk[i] += 1
res = [s for s in S if chk[s] == 1 and C[s] == 1]
# print(res)
print(len(res)) | 1 | 14,473,616,112,840 | null | 129 | 129 |
x = int(input())
answer = 0
answer = (x//500)*1000
x = x%500
answer += (x//5)*5
print(answer) | #!/usr/bin/env python3
N = int(input().split()[0])
xlt_list = []
for _ in range(N):
x, l = list(map(int, input().split()))
xlt_list.append((x, l, x + l))
xlt_list = sorted(xlt_list, key=lambda x: x[2])
count = 0
before_t = -float("inf")
for i, xlt in enumerate(xlt_list):
x, l, t = xlt
if x - l >= before_t:
count += 1
before_t = t
ans = count
print(ans)
| 0 | null | 66,327,318,922,660 | 185 | 237 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
s,t = input().split()
a,b = map(int, input().split())
u = input()
if s==u:
a -= 1
else:
b -= 1
print(" ".join(map(str, (a,b)))) | S,T,A,B,U = open(0).read().split()
if S==U:
print(int(A)-1,B)
else:
print(A,int(B)-1) | 1 | 72,125,935,972,288 | null | 220 | 220 |
while 1:
S = raw_input()
if (S == '-'):
break
N = input()
for i in range(N):
h = input()
S = S[h : len(S)] + S[0 : h]
print S
| import sys
def input(): return sys.stdin.readline().rstrip()
S = input()
if S == "ABC":
print("ARC")
else:
print("ABC") | 0 | null | 13,082,116,843,168 | 66 | 153 |
from collections import deque
N = int(input())
K = 0
Ans = [0] * (N-1)
Edge = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
a -= 1
b -= 1
Edge[a].append((b, _))
Edge[b].append((a, _))
Q = deque()
Q.append((0, 0))
P = [-1] * N
while Q:
now, color = Q.popleft()
cnt = 1
for nex, num in Edge[now]:
if cnt == color:
cnt += 1
if nex == P[now]:
continue
if Ans[num] != 0:
continue
Q.append((nex, cnt))
Ans[num] = cnt
K = max(cnt, K)
cnt += 1
print(K)
for a in Ans:
print(a) | import sys
import numpy as np
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(input())
edge = [[] for _ in range(N)]
ab = [tuple() for _ in range(N - 1)]
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
edge[a].append(b)
edge[b].append(a)
ab[i] = (a, b)
# print(ab)
# print(edge)
max_v = 0
max_v_dim = 0
for i, e in enumerate(edge):
if max_v_dim < len(e):
max_v_dim = len(e)
max_v = i
# print(max_v)
# print(max_v_dim)
# bfs
q = deque()
q.append(max_v)
ec = np.full(N, -1, dtype='i8')
ec[max_v] = max_v_dim + 10
vc = dict()
# vc = np.full((N, N), -1, dtype='i8')
while q:
nv = q.popleft()
nc = ec[nv]
tc = 1
for v in edge[nv]:
v1, v2 = min(nv, v), max(nv, v)
if not ((v1, v2) in vc):
if nc == tc:
tc += 1
ec[v] = tc
vc[(v1, v2)] = tc
tc += 1
q.append(v)
print(max_v_dim)
for v1, v2 in ab:
print(vc[(v1, v2)])
if __name__ == '__main__':
solve()
| 1 | 135,535,279,842,720 | null | 272 | 272 |
import math
def koch(n, p1_x, p1_y, p2_x, p2_y):
if n == 0:
print(f"{p1_x:.8f} {p1_y:.8f}")
return
# p1, p2からs, t, uを計算
# 与えられた線分(p1, p2) を3等分点s、tを求める
s_x = (2 * p1_x + 1 * p2_x) / 3
s_y = (2 * p1_y + 1 * p2_y) / 3
t_x = (p1_x + 2 * p2_x) / 3
t_y = (p1_y + 2 * p2_y) / 3
# 線分を3等分する2点 s,t を頂点とする正三角形 (s,u,t) を作成する
u_x = (
(t_x - s_x) * math.cos(math.pi / 3) - (t_y - s_y) * math.sin(math.pi / 3) + s_x
)
u_y = (
(t_x - s_x) * math.sin(math.pi / 3) + (t_y - s_y) * math.cos(math.pi / 3) + s_y
)
# 線分 (p1,s)、線分 (s,u)、線分 (u,t)、線分 (t,p2)に対して再帰的に同じ操作を繰り返す
koch(n - 1, p1_x, p1_y, s_x, s_y)
koch(n - 1, s_x, s_y, u_x, u_y)
koch(n - 1, u_x, u_y, t_x, t_y)
koch(n - 1, t_x, t_y, p2_x, p2_y)
n = int(input())
koch(n, 0, 0, 100, 0)
print("100.00000000 0.00000000")
| from functools import reduce
MOD = 10**9 + 7
n, a, b = map(int, input().split())
def combination2(n, r, MOD=10**9+7):
if not 0 <= r <= n: return 0
r = min(r, n - r)
numerator = reduce(lambda x, y: x * y % MOD, range(n, n - r, -1), 1)
denominator = reduce(lambda x, y: x * y % MOD, range(1, r + 1), 1)
return numerator * pow(denominator, MOD - 2, MOD) % MOD
print((pow(2,n,MOD) - combination2(n,a) - combination2(n,b)-1)%MOD) | 0 | null | 33,096,550,877,500 | 27 | 214 |
a, b = map(int, input().split())
ans = '-1'
if a < 10 and b < 10:
ans = a*b
print(ans) | A,B=map(int,input().split())
print(A*B if 1<=A<=9 and 0<B<10 else -1) | 1 | 157,979,346,540,470 | null | 286 | 286 |
s = input()
res = 0
if s == "SUN":
res = 7
elif s == "MON":
res = 6
elif s == "TUE":
res = 5
elif s == "WED":
res = 4
elif s == "THU":
res = 3
elif s == "FRI":
res = 2
elif s == "SAT":
res = 1
print(res) | class Combination():
def __init__(self, N:int, P:int):
self.N = N
self.P = P
self.fact = [1, 1]
self.factinv = [1, 1]
self.inv = [0, 1]
for i in range(2, N+1):
self.fact.append((self.fact[-1] * i) % P)
self.inv.append((-self.inv[P % i] * (P // i)) % P)
self.factinv.append((self.factinv[-1] * self.inv[-1]) % P)
def getComb(self, n:int, k:int):
if (k < 0) or (n < k):
return 0
k = min(k, n - k)
return self.fact[n] * self.factinv[k] % self.P * self.factinv[n-k] % self.P
def main():
n,k = map(int,input().split())
MOD = 10**9 +7
COMB = Combination(n,MOD)
ans = 0
for i in range(min(n, k+1)):
ans += COMB.getComb(n,i) * COMB.getComb(n-1,i)
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 0 | null | 100,018,240,258,008 | 270 | 215 |
n = int(input())
a = list(map(int,input().split()))
l = [0] * n
for i in range(n):
l[a[i]-1] = i+1
for i in range(n):
print(l[i],end = ' ')
| def gotoS(org, n):
res = [0] * n
for i in range(1, n+1):
res[org[i-1]-1] = i
return res
n = int(input())
org = list(map(int, input().split()))
print(*gotoS(org, n)) | 1 | 181,231,459,254,120 | null | 299 | 299 |
import sys
import numpy as np
import heapq
def input():
return sys.stdin.readline()[:-1]
def solve():
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(a[K-1])
if __name__ == "__main__":
solve()
| K = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
ans = K.split(", ")
num = int(input())
print(ans[num-1])
| 1 | 49,868,393,675,870 | null | 195 | 195 |
def havec(x_list, y):
x_list[y-1] = 1
def printc(x_list, s):
for i in range(13):
if x_list[i] == 0:
print("%s %d" %(s, i+1))
n = input()
Sp = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Ha = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Cl = [0,0,0,0,0,0,0,0,0,0,0,0,0]
Di = [0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(n):
incard = raw_input()
a, b = incard.split(" ")
b = int(b)
if a == "S":
havec(Sp, b)
elif a == "H":
havec(Ha, b)
elif a == "C":
havec(Cl, b)
else:
havec(Di, b)
printc(Sp, "S")
printc(Ha, "H")
printc(Cl, "C")
printc(Di, "D") | n,m = map(int, input().split())
neighbors = {key:[] for key in range(1, n+1)}
answers = {key:0 for key in range(1, n+1)}
answers[1] = 1
for i in range(m):
a,b = map(int, input().split())
neighbors[a].append(b)
neighbors[b].append(a)
def register(hs):
newhs = []
for h in hs:
for i in neighbors[h]:
if answers[i] == 0:
answers[i] = h
newhs.append(i)
return newhs
hosts = [1]
while True:
hosts = register(hosts)
if len(hosts) == 0:
break
flag = 0
for key, item in answers.items():
if item == 0:
flag = 1
if flag == 0:
print("Yes")
for key, item in answers.items():
if key != 1:
print(item)
else:
print("No") | 0 | null | 10,742,298,744,360 | 54 | 145 |
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 is_ok(x):
c = 0
for a, f in zip(A, F):
c += max(0, a-x//f)
if c <= k:
return True
else:
return False
ng = -1
ok = 10**18
while ng+1 < ok:
c = (ng+ok)//2
if is_ok(c):
ok = c
else:
ng = c
print(ok)
| from collections import Counter
N=int(input())
if N==1:
print(0)
exit()
def factorize(n):
out=[]
i = 2
while 1:
if n%i==0:
out.append(i)
n //= i
else:
i += 1
if n == 1:break
if i > int(n**.5+3):
out.append(n)
break
return out
c = Counter(factorize(N))
def n_unique(n):
out = 0
while 1:
if out*(out+1)//2 > n:
return out-1
out += 1
ans = 0
for k in c.keys():
ans += n_unique(c[k])
print(ans) | 0 | null | 90,917,807,806,000 | 290 | 136 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
def main():
N,*A = map(int, read().split())
cnt = [0] * N
ans = 1
for a in A:
if a == 0:
cnt[0] += 1
continue
ans *= cnt[a - 1] - cnt[a]
ans %= MOD
cnt[a] += 1
if cnt[0] == 1:
ans *= 3
elif cnt[0] <= 3:
ans *= 6
else:
ans = 0
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
ans = 1
cnt = [0, 0, 0]
for i in range(N):
ans = ans * cnt.count(A[i]) % mod
if A[i] in cnt:
cnt[cnt.index(A[i])] += 1
else:
print(0)
exit()
print(ans) | 1 | 130,177,770,501,492 | null | 268 | 268 |
x = int(input())
cnt_500 = 0
cnt_5 = 0
while x > 4:
if x >= 500:
x -= 500
cnt_500 += 1
else:
x -= 5
cnt_5 += 1
print(1000*cnt_500+5*cnt_5)
| s = list(input())
t = list(input())
ans = 1000
sub = 0
flag = False
for i in range(len(s)):
if s[i] != t[sub]:
sub = 0
continue
else:
if sub == len(t) - 1:
print(0)
flag = True
break
sub += 1
if not flag:
for i in range(len(s) - len(t) + 1):
sub = 0
an = 0
for j in range(len(t)):
if s[i + j] != t[sub]:
an += 1
sub += 1
ans = min(an, ans)
print(ans) | 0 | null | 23,151,575,231,350 | 185 | 82 |
import itertools
n,k=map(int,input().split())
d=[]
a=[]
for i in range(k):
d.append(int(input()))
a.append(list(map(int,input().split())))
a_1=itertools.chain.from_iterable(a)
print(n-len(list(set(a_1)))) | import sys
import itertools
input = sys.stdin.readline
def SI(): return str(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
H, W, K = MI()
grid = [SI().rstrip('\n') for _ in range(H)]
n = H + W
ans = 0
for i in itertools.product(range(2),repeat = H):
for j in itertools.product(range(2),repeat = W):
count = 0
for k in range(H):
if i[k] == 1:
continue
for l in range(W):
if j[l] == 1:
continue
if grid[k][l] == "#":
count += 1
if count == K:
ans +=1
print(ans)
main() | 0 | null | 16,762,426,044,558 | 154 | 110 |
N = int(input())
c = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
end = i%10
head = int(str(i)[0])
c[head][end] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += c[i][j]*c[j][i]
print(ans)
| d = ["ABC", "ARC"]
s = input()
print(d[1 - d.index(s)])
| 0 | null | 55,522,602,648,890 | 234 | 153 |
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]
class UnionFind:
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 same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
return self.find(x) == self.find(y)
def size(self, x): # 要素xが属するグループのサイズ(要素数)を返す
return -self.parents[self.find(x)]
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): # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
for i in range(M):
uf.union(AB[i][0] - 1, AB[i][1] - 1)
l = []
for i in range(N):
l.append(uf.size(i))
print(max(l))
| x = int(input())
ans, r = divmod(x, 500)
ans *= 1000
ans += (r//5)*5
print(ans)
| 0 | null | 23,281,107,106,328 | 84 | 185 |
import sys
input = sys.stdin.buffer.readline
def main():
N = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
print(0)
else:
MOD = 998244353
use = [0 for _ in range(max(d)+1)]
for num in d:
use[num] += 1
if use[0] != 1:
print(0)
else:
ans,pa = 1,1
for num in use:
ans *= pow(pa,num,MOD)
ans %= MOD
pa = num
print(ans)
if __name__ == "__main__":
main()
| from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
p = defaultdict(int)
for d in D:
p[d] += 1
if p[0] == 1 and D[0] == 0:
ans = 1
for i in range(max(D)):
ans *= pow(p[i], p[i + 1], MOD)
ans %= MOD
if ans == 0:
break
print(ans)
else:
print(0)
| 1 | 154,900,828,489,028 | null | 284 | 284 |
S = input()
ans = ''.join(['x' for ch in S])
print(ans)
| n, k = map(int,input().split())
w_in = list()
for i in range(n):
w_in.append(int(input()))
def alloc(p):
load = 0
track = 1
for w in w_in:
if w > p:
return False
if load + w <= p:
load += w
else:
load = w
track += 1
if track > k:
return False
return True
def binsearch():
upper = sum(w_in)
lower = max(w_in)
while(upper != lower):
mid = int((upper + lower) / 2)
if alloc(mid):
upper = mid
else:
lower = mid + 1
return upper
print(binsearch()) | 0 | null | 36,697,535,480,970 | 221 | 24 |
n = input()
h = [2,4,5,7,9]
p = [0,1,6,8]
if int(n[-1]) in h:
print('hon')
elif int(n[-1]) in p:
print('pon')
else:
print('bon') | n = input()
c = n[-1]
if c in "24579":
print("hon")
elif c in "0168":
print("pon")
else:
print("bon") | 1 | 19,317,857,518,480 | null | 142 | 142 |
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
routes = [[] for _ in range(len(h) + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
routes[a].append(b)
routes[b].append(a)
good = 0
for i in range(1, len(routes)):
if len(routes[i]) == 0:
good += 1
continue
if h[i - 1] > max([h[j - 1] for j in routes[i]]):
good += 1
print(good) | n = int(input())
ans, tmp = 0, 5
if n % 2 == 0:
n //= 2
while tmp <= n:
ans += n // tmp
tmp *= 5
print(ans)
| 0 | null | 70,407,452,914,140 | 155 | 258 |
def pows(a, n, mod):
# [a**0, a**1, ..., a**n] % mod
ret = [1] * (n + 1)
for i in range(1, n + 1):
ret[i] = ret[i - 1] * a % mod
return ret
def ext_euc(a, b):
if b == 0:
return 1, 0, a
y, x, v = ext_euc(b, a % b)
y -= (a // b) * x
return x, y, v
def mod_inv(a, mod):
x, _, _ = ext_euc(a, mod)
return x % mod
def main():
MOD = 10**9 + 7
K = int(input())
S = input()
N = len(S)
ans = 0
pw25 = pows(25, K, MOD)
pw26 = pows(26, K, MOD)
comb = 1 # (k+N-1)_C_k
for k in range(K + 1):
ans += pw25[k] * comb * pw26[K - k]
ans %= MOD
comb *= k + N
comb *= mod_inv(k + 1, MOD)
comb %= MOD
print(ans)
if __name__ == '__main__':
main() | MAXN = 2*10**6+2
p = 10**9 + 7
fact = [1] * MAXN
invfact = [1] * MAXN
for i in range(1, MAXN):
fact[i] = fact[i-1] * i % p
invfact[MAXN-1] = pow(fact[MAXN-1], p-2, p)
for i in range(MAXN-1, 0, -1):
invfact[i-1] = invfact[i] * i % p
def nCk(n, k):
return fact[n] * invfact[n-k] * invfact[k] % p
K = int(input())
N = len(input())
ans = 0
for i in range(N, N+K+1):
ans += pow(25, i-N, p) * nCk(i-1, N-1) * pow(26, N+K-i, p) % p
ans %= p
print(ans)
| 1 | 12,761,282,571,180 | null | 124 | 124 |
def pows(a, n, mod):
# [a**0, a**1, ..., a**n] % mod
ret = [1] * (n + 1)
for i in range(1, n + 1):
ret[i] = ret[i - 1] * a % mod
return ret
def ext_euc(a, b):
if b == 0:
return 1, 0, a
y, x, v = ext_euc(b, a % b)
y -= (a // b) * x
return x, y, v
def mod_inv(a, mod):
x, _, _ = ext_euc(a, mod)
return x % mod
def main():
MOD = 10**9 + 7
K = int(input())
S = input()
N = len(S)
ans = 0
pw25 = pows(25, K, MOD)
pw26 = pows(26, K, MOD)
comb = 1 # (k+N-1)_C_k
for k in range(K + 1):
ans += pw25[k] * comb * pw26[K - k]
ans %= MOD
comb *= k + N
comb *= mod_inv(k + 1, MOD)
comb %= MOD
print(ans)
if __name__ == '__main__':
main() | k=int(input())
s=list(input())
n=len(s)
def cmb(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
def p(n,r,mod):
return fact[n]*factinv[n-r] % mod
mod = 10 ** 9 + 7
maxi = 2*10 ** 6 + 1 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, maxi + 1):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
array_5=[1]
array_6=[1]
for i in range(k):
array_5.append(25*array_5[-1]%mod)
array_6.append(26*array_6[-1]%mod)
ans=0
for i in range(n,n+k+1): #iはS_Nの固定した位置を表す。
x=cmb(i-1,n-1,mod)
y=array_5[i-n]*array_6[n+k-i]
ans += x*y%mod
ans %=mod
print(ans) | 1 | 12,673,522,088,740 | null | 124 | 124 |
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
cheak = [0] * (2*(10**5) + 1)
point = 1
dev = [1]
flag = 0
for i in range(1, k + 1):
if cheak[point]:
loop = i -cheak[point]
pre_loop = cheak[point]
flag = 1
break
else:
cheak[point] = i
point = a[point]
#dev.append(point)
if flag:
rest = (k + 1- pre_loop) % loop
for j in range(rest):
point = a[point]
#dev.append(point)
print(point) | kMod = 1000000007
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
print(0)
exit()
offset = (X+Y)//3
X, Y = X-offset, Y-offset
if X < 0 or Y < 0:
print(0)
exit()
X, Y = max(X, Y), min(X, Y)
ans = 1
for i in range(X+1, X+Y+1):
ans *= i
ans %= kMod
for i in range(2, Y+1):
ans *= pow(i, kMod-2, kMod)
ans %= kMod
print(ans) | 0 | null | 86,768,279,057,306 | 150 | 281 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
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())
n = I()
ans = 'No'
cnt = 0
for i in range(n):
a, b = M()
if a == b:
cnt += 1
if cnt == 3:
ans = 'Yes'
break
else:
cnt = 0
print(ans) | import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
k=int(input())
if k%2==0:
print("-1")
sys.exit()
flg=False
cnt=0
a=7
for i in range(k):
cnt+=1
a%=k
if a%k==0:
print(cnt)
sys.exit()
a*=10
a+=7
if not flg:
print(-1) | 0 | null | 4,278,777,146,018 | 72 | 97 |
import math
m=10**2
for i in range(input()):
m*=1.05
m=math.ceil(m)
print int(m*(10**3)) | N = int(input())
A = sorted(map(lambda x: (int(x[1]), x[0]),
enumerate(input().split())), reverse=True)
V = [0]
for i in range(N-1):
a, p = A[i]
s = i+1
V2 = [None]*(s+1)
for t in range(s+1):
v = 0
if t > 0:
v = V[t-1] + a*abs(p-(t-1))
if t < s:
v = max(V[t] + a*abs(p-(N-s+t)), v)
V2[t] = v
V = V2
a, p = A[-1]
for i in range(N):
V[i] += a*abs(p-i)
print(max(V))
| 0 | null | 16,801,322,507,210 | 6 | 171 |
n = int(input())
cnt = 0
for i in range(1, 10):
if len(str(n//i)) == 1 and n%i == 0:
cnt +=1
if cnt >= 1:
print('Yes')
else :
print('No')
| N=int(input())
for i in range(1,10):
for j in range(1,10):
if i*j==N:
print("Yes")
break
else:
continue
break
else:
print("No")
| 1 | 159,764,817,165,730 | null | 287 | 287 |
x, y = map(int, input().split())
result = x * y
print(result)
| if __name__ == "__main__":
a,b = map(int, input().split(" "))
print(a*b) | 1 | 15,843,520,301,002 | null | 133 | 133 |
lx = [int(w) for w in input().split()]
for i, x in enumerate(lx):
if x == 0:
print(i+1)
exit()
| N_List = list(map(int,input().split()))
print(N_List.index(0)+1) | 1 | 13,336,054,541,052 | null | 126 | 126 |
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
# 10進数表記でnのk進数を求めてlength分0埋め
def ternary (n, k, length):
if n == 0:
nums = ['0' for i in range(length)]
nums = ''.join(nums)
return nums
nums = ''
while n:
n, r = divmod(n, k)
nums += str(r)
nums = nums[::-1]
nums = nums.zfill(length)
return nums
def main():
num = int(input())
data = list(map(int, input().split()))
mod = 10 ** 9 + 7
max_length = len(bin(max(data))) - 2
bit_count = [0 for i in range(max_length)]
for i in range(num):
now_bin = bin(data[i])[2:]
now_bin = now_bin.zfill(max_length)
for j in range(max_length):
if now_bin[j] == "1":
bit_count[j] += 1
flg_data = [0 for i in range(max_length)]
for i in range(max_length):
flg_data[i] += bit_count[i] * (num - bit_count[i])
ans = 0
for j in range(max_length):
pow_num = max_length - 1 - j
bbb = pow(2, pow_num, mod)
ans += bbb * flg_data[j]
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| def solve():
MOD = 10**9 + 7
N = int(input())
As = list(map(int, input().split()))
ans = 0
for d in range(60):
mask = 1<<d
num1 = len([1 for A in As if A & mask])
ans += num1 * (N-num1) * mask
ans %= MOD
print(ans)
solve()
| 1 | 122,759,644,738,012 | null | 263 | 263 |
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
work1=sorted([x[0] for x in l])
work2=sorted([x[1] for x in l])
if n%2==1 :
mmin=work1[n//2]
mmax=work2[n//2]
else:
mmin=work1[n//2]+work1[n//2-1]
mmax=work2[n//2]+work2[n//2-1]
print(mmax-mmin+1) | from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
a[i], b[i] = map(int, input().split())
a.sort()
b.sort()
if n%2!=0 :
l = a[int(n/2)]
u = b[int(n/2)]
ans = u - l + 1
else:
l = a[int(n/2-1)] + a[int(n/2)]
u = b[int(n/2-1)] + b[int(n/2)]
ans = u - l +1
print(ans)
| 1 | 17,323,785,005,252 | null | 137 | 137 |
n = int(input())
bricks = list(map(int, input().split()))
cnt = 0
num = 1
for i in range(n):
if bricks[i] == num: num += 1
else: cnt += 1
else:
if num != 1: print(cnt)
else: print(-1) | n = int(input())
a = list(map(int,input().split()))
if 1 not in a:
print(-1)
exit()
x = 1
cnt = 0
for i in range(n):
if a[i] == x:
x += 1
else:
cnt += 1
print(cnt) | 1 | 115,069,718,816,290 | null | 257 | 257 |
S=str(input())
def kinshi(S:str):
len_count=len(S)
return("x"*len_count)
print(kinshi(S))
| string = input()
replaced_string = ''
while len(replaced_string) < len(string):
replaced_string += 'x'
print(replaced_string) | 1 | 73,159,099,173,602 | null | 221 | 221 |
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
A[i] = [i+1, A[i]]
A.sort(key=lambda x:x[1])
ans=[]
for i in range(N):
ans.append(A[i][0])
ans = map(str, ans)
print(' '.join(ans))
| a = int(input())
print(a+(a**2)+(a**3)) | 0 | null | 95,502,063,941,520 | 299 | 115 |
# 解説を見た。
# https://at274.hatenablog.com/entry/2020/01/24/060000
def main():
num = int(input())
counter = [[0] * 10 for _ in range(10)]
for x in range(1, num + 1):
x = str(x)
head = int(x[0])
tail = int(x[-1])
counter[head][tail] += 1
gen = (counter[head][tail] * counter[tail][head]
for head in range(1, 10)
for tail in range(1, 10))
print(sum(gen))
if __name__ == '__main__':
main()
| N,K = map(int,input().split())
count =0
for i in range(K,N+2):
if i ==N+1:
count+=1
else:
a = (i-1)
a = a/2
a = a*i
b = (N+N-(i-1))/2
b = b*i
count +=b-a+1
#print(i,count,a,b)
print(int(count%(10**9+7))) | 0 | null | 59,694,200,570,328 | 234 | 170 |
n = int(input())
d = {}
m = 0
for i in range(n):
s = input()
d[s] = d.get(s, 0) + 1
if m <= d[s]:
m = d[s]
c = []
for i in d:
if d[i]==m:
c.append(i)
c.sort()
for x in c:
print(x) | import collections
n=int(input())
data=[""]*n
for i in range(n):
data[i]=input()
data=sorted(data)
count=collections.Counter(data)
num=max(count.values())
for v,k in count.items():
if k==num:
print(v) | 1 | 69,768,127,970,802 | null | 218 | 218 |
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]
for s in range(n):
aa.append(aa[s] + a[s])
for s in range(m):
bb.append(bb[s] + b[s])
ans = 0
j = m
for i in range(n+1):
if aa[i] > k:
break
while bb[j] > k - aa[i]:
j -= 1
ans = max(ans, i+j)
print(ans) | import bisect
n, m, k = list(map(int, input().split()))
book_a = list(map(int, input().split()))
book_b = list(map(int, input().split()))
a_time_sum = [0]
b_time_sum = []
for i in range(n):
if i == 0:
a_time_sum.append(book_a[0])
else:
a_time_sum.append(a_time_sum[i]+book_a[i])
for i in range(m):
if i == 0:
b_time_sum.append(book_b[0])
else:
b_time_sum.append(b_time_sum[i-1]+book_b[i])
ans = 0
# Aから何冊か読む
for i in range(n+1):
read = i
a_time = a_time_sum[i]
time_remain = k - a_time
if time_remain < 0:
break
# このときBから何冊よめる?
b_read = bisect.bisect_right(b_time_sum, time_remain)
read += b_read
ans = max(ans, read)
print(ans)
| 1 | 10,726,230,369,536 | null | 117 | 117 |
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
X=ii()
i = 1
yen = 100
while yen < X:
r = yen // 100
yen += r
i += 1
print(i-1)
if __name__ == "__main__":
main() | s=input()
d_in={'/':1,'\\':-1,'_':0}
stack_h=[]
pairs_x=[]
for i in range(len(s)):
if d_in[s[i]]==-1:
stack_h.append(i)
elif d_in[s[i]]==1:
if len(stack_h)!=0:
pairs_x.append([stack_h.pop(),i+1])
stack_ans=[]
for i in range(len(pairs_x)):
pair_i=pairs_x.pop()
if len(stack_ans)==0:
stack_ans.append(pair_i)
elif pair_i[1]<=stack_ans[-1][0]:
stack_ans.append(pair_i)
area=[0]*len(stack_ans)
sum_area=0
for i in range(len(stack_ans)):
p=stack_ans.pop()
h=0
for j in range(p[0],p[1]):
area[i]+=h
h-=d_in[s[j]]
sum_area+=area[i]
print(sum_area)
if len(area)==0:
print(0)
else:
print(len(area),end=' ')
print(' '.join(map(str,area)))
| 0 | null | 13,487,231,982,100 | 159 | 21 |
def main():
""""ここに今までのコード"""
N, K = map(int, input().split())
dice_list = list(map(int, input().split()))
max, s = 0, 0
for i in range(K):
s += (dice_list[i] + 1) / 2
max = s
for i in range(N-K):
s -= (dice_list[i] + 1) / 2
s += (dice_list[i+K] + 1) / 2
if s > max:
max = s
print(max)
if __name__ == '__main__':
main() | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
while True:
try:
num = eval(input().replace(" ","+"))
except:
return
else:
print(len(str(num)))
if __name__ == '__main__':
main() | 0 | null | 37,266,454,861,220 | 223 | 3 |
n = int(input())
s = input()
ans = 0
for i in range(10):
for j in range(10):
for k in range(10):
fi = False
fj = False
for ss in s:
ss = int(ss)
if not fi and ss == i:
fi = True
continue
if fi and not fj and ss == j:
fj = True
continue
if fj and ss == k:
ans += 1
break
print(ans)
| X = int(input())
if (X < 30):
print('No')
else:
print('Yes') | 0 | null | 66,981,463,209,080 | 267 | 95 |
import re
def main():
S , T =map(str, input().split())
print (T+S)
if __name__ == '__main__':
main()
| #---Strings
S, T = map(str, input().split(" "))
print(T, S, sep="")
| 1 | 102,949,420,264,070 | null | 248 | 248 |
# https://atcoder.jp/contests/abc145/tasks/abc145_d
X, Y = list(map(int, input().split()))
MOD = int(1e9 + 7)
def combination(n, r, mod=MOD):
def modinv(a, mod=MOD):
return pow(a, mod-2, mod)
# nCr with MOD
r = min(r, n - r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
# 1回の移動で3増えるので,X+Yは3の倍数 (0, 0) start
if (X + Y) % 3 != 0:
ans = 0
print(0)
else:
# X+Yは3の倍数
# (+1, +2)をn回,(+2, +1)をm回実行
# n + 2m = X
# 2n + m = Y
# 3 m = 2 X - Y
# m = (2 X - Y) // 3
# n = X - 2 * m
m = (2 * X - Y) // 3
n = X - 2 * m
if m < 0 or n < 0:
print(0)
else:
print(combination(m + n, m, MOD))
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
v = N//K
print(min(N-v*K, K-(N-v*K))) | 0 | null | 94,547,175,641,530 | 281 | 180 |
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) | N=int(input())
n=N
ans=0
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)
return divisors
l=make_divisors(N-1)
r=make_divisors(N)
ans=len(l)-1
for i in range(len(r)):
N=n
K=r[i]
if K==1:
continue
while(N%K==0):
N=N//K
if N%K==1:
#print(K)
ans+=1
print(ans) | 0 | null | 69,181,767,270,532 | 243 | 183 |
N = int(input())
if N == 1:
print(0)
else:
print(1) | x = int(input())
print((x == 0) * 1 + (x == 1) * 0) | 1 | 2,939,000,849,402 | null | 76 | 76 |
H, A = map(int, input().split())
print(H//A + 1 if H%A else H//A) | import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
t=''
for c in e[1:n]:
for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '
t=t[:-1]+'\n'
print(t[:-1])
| 0 | null | 39,006,158,700,782 | 225 | 60 |
n = int(input())
p = list(map(int,input().split()))
p2 = [0]*n
for x in p:
p2[x-1] = p2[x-1] + 1
for x in p2:
print(x) | N = int(input())
p = [list(map(int,input().split())) for _ in range(N)]
z = []
w = []
for i in range(N):
z.append(p[i][0] + p[i][1])
w.append(p[i][0] - p[i][1])
print(max(max(z)-min(z),max(w)-min(w))) | 0 | null | 17,900,729,190,080 | 169 | 80 |
n = input()
digit1 = int(n[-1])
ans = ''
if digit1 in {2, 4, 5, 7, 9}:
ans = 'hon'
elif digit1 in {0, 1, 6, 8}:
ans = 'pon'
elif digit1 in {3}:
ans = 'bon'
print(ans)
| a = [2, 4, 5, 7, 9]
b = [0, 1, 6, 8]
n = input()
if int(n[-1]) in a:
print("hon")
elif int(n[-1]) in b:
print("pon")
else:
print("bon") | 1 | 19,135,982,154,210 | null | 142 | 142 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.