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, *XL = map(int, open(0).read().split())
XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))
curr = -float("inf")
ans = 0
for right, left in XL:
if left >= curr:
curr = right
ans += 1
print(ans)
|
n = int(input())
x_list = []
for _ in range(n):
x, l = map(int, input().split())
x_list.append((x + l, x - l))
x_list.sort()
ans = 0
for i in range(n):
x_max, x_min = x_list[i]
if i == 0:
t = x_max
continue
if x_min < t:
ans += 1
continue
t = x_max
print(n - ans)
| 1 | 89,564,735,546,582 | null | 237 | 237 |
#初期定義
global result
global s_list
result = 0
#アルゴリズム:ソート
def merge(left, mid, right):
global result
n1 = mid - left
n2 = right - mid
inf = 10**9
L_list = s_list[left: mid] + [inf]
R_list = s_list[mid: right] + [inf]
i = 0
j = 0
for k in range(left, right):
result += 1
if L_list[i] <= R_list[j]:
s_list[k] = L_list[i]
i += 1
else:
s_list[k] = R_list[j]
j += 1
#アルゴリズム:マージソート
def mergeSort(left, right):
if (left + 1) < right:
mid = (left + right) // 2
mergeSort(left, mid)
mergeSort(mid, right)
merge(left, mid, right)
#初期値
n = int(input())
s_list = list(map(int, input().split()))
#処理の実行
mergeSort(0, n)
#結果の表示
print(" ".join(map(str, s_list)))
print(result)
|
import math
a,b,h,m=map(int,input().split())
hc=360/12*h+30/60*m #時針の角度
mc=360/60*m #分針の角度
hm=abs(hc-mc) #時針と分針の角度の差
if hm > 180:
hm=360-hm
mcos=math.cos(math.radians(hm))
c=a**2+b**2-(2*a*b*mcos) #余剰定理
print(math.sqrt(c))
| 0 | null | 10,098,926,421,942 | 26 | 144 |
h,n= map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
m = 10**4
dp = [0]*(h+m+1)
for i in range(m+1,h+m+1):
dp[i] = min(dp[i-a] + b for a,b in p)
print(dp[h+m])
|
N = int(input())
con = 1
set = 0
s = list(map(int, input().split()))
for i in s:
if con == i:
set += 1
con += 1
if set == 0:
print(-1)
else:
ans = len(s) - set
print(ans)
| 0 | null | 97,446,775,957,440 | 229 | 257 |
import sys
import math
import fractions
from collections import defaultdict
import bisect
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,M=nm()
A=nl()
A.sort()
S=[0]
S[0]=A[0]
for i in range(1,N):
S.append(S[i-1]+A[i])
def clc_shake(x):#x以上の和
tot=0
for i in range(N):
th=x-A[i]
inds=bisect.bisect_left(A,th)
tot+=(N-inds)
return tot
l=0
r=2*(10**6)
c=0
while (l+1<r):
c=(l+r)//2
if(clc_shake(c)<M):
r=c
else:
l=c
ans=0
for i in range(N):
th=r-A[i]
inds=bisect.bisect_left(A,th)
if(inds!=0):
ans+=((N-inds)*A[i]+(S[N-1]-S[inds-1]))
else:
ans+=((N-inds)*A[i]+(S[N-1]))
M2=M-clc_shake(r)
ans+=M2*(l)
print(ans)
|
from operator import itemgetter
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
sortA = sorted(AB, key=itemgetter(0))
sortB = sorted(AB, key=itemgetter(1))
if n%2==1:
print(sortB[n//2][1] - sortA[-n//2][0] + 1)
else:
print(int(((sortB[n//2][1]+sortB[n//2-1][1])/2 - (sortA[n//2][0]+sortA[n//2-1][0])/2) / (1/2) + 1))
| 0 | null | 63,005,267,689,238 | 252 | 137 |
def nCkpow(n,k):
if n<k:
return 0
y=1
for i in range(k):
y*=n-i
y//=i+1
y*=9
return y
def f(s,m,k):
#print(m,k)
if len(s)-m<k:
return 0
if k==0:
return 1
if s[m]=='0':
return f(s,m+1,k)
l=len(s)-m
y=nCkpow(l-1,k)
y+=(int(s[m])-1)*nCkpow(l-1,k-1)
return y+f(s,m+1,k-1)
N=input()
K=int(input())
print(f(N,0,K))
|
# 愚直に数え上げる方法
import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = list(map(int, input()))
K = int(input())
if K == 1:
ans = (len(N) - 1) * 9 + N[0]
elif K == 2:
if len(N) < 2:
print(0)
exit()
ans = (9 ** 2) * (len(N) - 1) * (len(N) - 2) // 2
ans += (N[0] - 1) * (len(N) - 1) * 9
for i in range(1, len(N)):
if N[i] != 0:
ans += N[i] + (len(N) - i - 1) * 9
break
elif K == 3:
if len(N) < 3:
print(0)
exit()
ans = (9 ** 3) * (len(N) - 1) * (len(N) - 2) * (len(N) - 3) // 6
ans += (N[0] - 1) * (9 ** 2) * (len(N) - 1) * (len(N) - 2) // 2
for i in range(1, len(N) - 1):
if N[i] != 0:
ans += (9 ** 2) * (len(N) - i - 1) * (len(N) - i - 2) // 2
ans += (N[i] - 1) * (len(N) - i - 1) * 9
for j in range(i + 1, len(N)):
if N[j] != 0:
ans += N[j] + (len(N) - j - 1) * 9
break
break
print(ans)
if __name__ == '__main__':
solve()
| 1 | 75,717,275,747,648 | null | 224 | 224 |
n=int(input())
a=[int(j) for j in input().split()]
p=[0]*n
d=[0]*n
for i in range(n):
p[i]=a[i]+p[i-2]
if (i&1):
d[i]=max(p[i-1],a[i]+d[i-2])
else:
d[i]=max(d[i-1],a[i]+d[i-2])
print(d[-1])
|
b = []
c = []
d = []
while True:
a = input().split()
a[0] = int(a[0])
a[1] = int(a[1])
if a[0] == 0 and a[1] == 0:
break
elif a[1]%2 == 0:
b.append("#."*(a[1]//2)+"#")
c.append((a[0],a[1]))
else:
b.append("#."*(a[1]//2)+"#.")
c.append((a[0],a[1]))
for i in range(len(c)):
if c[i][0]%2 == 0:
for j in range(c[i][0]//2):
print(b[i][0:-1])
print(b[i][1:])
else:
for j in range(c[i][0]//2):
print(b[i][0:-1])
print(b[i][1:])
print(b[i][0:-1])
print("\n",end="")
| 0 | null | 18,997,182,467,100 | 177 | 51 |
''' 1.降序排列,选出x个红苹果,y个绿苹果
2.使用c个无色苹果去更新这x+y个苹果中的小值,直到最小也比无色苹果的大为止'''
nums = [int(i) for i in input().split()]
x = nums[0]
y = nums[1]
a = nums[2]
b = nums[3]
c = nums[4]
redApples = [int(i) for i in input().split()]
greenApples = [int(i) for i in input().split()]
colorless = [int(i) for i in input().split()]
redApples.sort(reverse=True)
greenApples.sort(reverse=True)
colorless.sort(reverse=True)
redApples = redApples[:x]
greenApples = greenApples[:y]
res = redApples+greenApples
res.sort(reverse=True)
currIndex = len(res)-1
for i in range(len(colorless)):
if colorless[i] <= res[currIndex]:
break
res[currIndex] = colorless[i]
currIndex -= 1
if currIndex < 0:
break
print(sum(res))
|
N, M, L = map(int, raw_input().split())
nm = [map(int, raw_input().split()) for n in range(N)]
ml = [map(int, raw_input().split()) for m in range(M)]
for n in range(N):
col = [0] * L
for l in range(L):
for m in range(M):
col[l] += nm[n][m] * ml[m][l]
print ' '.join(map(str, col))
| 0 | null | 23,103,862,848,780 | 188 | 60 |
n = int(input())
a = list(map(int, input().split()))
for n in a:
if n % 2 == 0:
if not n % 3 == 0 and not n % 5 == 0:
print("DENIED")
break
else:
print("APPROVED")
|
N, K = [int(_) for _ in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(K, N + 2):
ans += i * (N - i + 1) + 1
ans %= mod
print(ans)
| 0 | null | 51,213,621,303,780 | 217 | 170 |
n, *a = map(int, open(0).read().split())
mita = [0] * -~n
mita[-1] = 3
mod = 10 ** 9 + 7
c = 1
for i in range(n):
c = c * (mita[a[i] - 1] - mita[a[i]]) % mod
mita[a[i]] += 1
print(c)
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import math
a, b, c = map(float, sys.stdin.readline().split())
degree = abs(180-abs(c))*math.pi / 180
height = abs(b * math.sin(degree))
pos_x = b * math.cos(degree) + a
edge_x = (height**2 + pos_x**2) ** 0.5
print(round(a * height / 2, 6))
print(round(a + b + edge_x, 6))
print(round(height, 6))
| 0 | null | 65,378,473,226,560 | 268 | 30 |
n=int(input())
a1=1
a=1
i=1
while i<n:
a1,a=a,a1+a
i+=1
print(a)
|
from scipy.sparse.csgraph import floyd_warshall
n, m, l = map(int, input().split())
inf = 10**12
d = [[inf for i in range(n)] for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
x,y,z = map(int,input().split())
d[x-1][y-1] = z
d[y-1][x-1] = z
for i in range(n):
d[i][i] = 0 #自身のところに行くコストは0
dd = floyd_warshall(d)
ddd = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
for j in range(n):
if dd[i][j] <= l:
ddd[i][j] = 1
dddd =floyd_warshall(ddd)
q = int(input())
for i in range(q):
s, t = map(int, input().split())
if dddd[s-1][t-1] == inf:
print(-1)
else:
print(int(dddd[s-1][t-1]-1))
| 0 | null | 86,557,138,394,720 | 7 | 295 |
dice = list(map(int, input().split()))
command = str(input())
for c in command:
if (c == 'S'): ##2651 --> 1265
dice[1],dice[5],dice[4],dice[0] = dice[0],dice[1],dice[5],dice[4]
elif(c == 'N'):
dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
elif (c == 'W'): ##4631 -- > 1463
dice[3], dice[5], dice[2],dice[0] = dice[0], dice[3], dice[5], dice[2]
else:
dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2],dice[0]
print(dice[0])
|
n = int(input())
S = list(map(int, input().split()))
c = 0
def merge(left, mid, right):
global c
L = S[left:mid] + [float('inf')]
R = S[mid:right] + [float('inf')]
i, j = 0, 0
for k in range(left, right):
if L[i] <= R[j]:
S[k] = L[i]
i += 1
else:
S[k] = R[j]
j += 1
c += right - left
def merge_sort(left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(left, mid)
merge_sort(mid, right)
merge(left, mid, right)
merge_sort(0, n)
print(*S)
print(c)
| 0 | null | 172,674,292,160 | 33 | 26 |
n=int(input())
A=0
B=0
for i in range(n):
a,b=map(str,input().split())
if a>b:
A+=3
elif a==b:
A+=1
B+=1
elif a<b:
B+=3
print(A,B)
|
# coding:utf-8
a, b, c = map(int, input().split())
k = int(input())
counter = 0
while a >= b:
counter += 1
b = b * 2
while b >= c:
counter += 1
c = c * 2
if counter <= k:
print('Yes')
else:
print('No')
| 0 | null | 4,444,451,775,230 | 67 | 101 |
from fractions import gcd
n, m = map(int, input().split())
lst = list(map(int, input().split()))
norm = 0
tmp = lst[0]
while tmp%2 == 0:
tmp = tmp//2
norm += 1
for i in range(n):
count = 0
tmp = lst[i]
while tmp%2 == 0:
tmp = tmp//2
count += 1
if norm != count:
print(0)
exit()
lst[i] = lst[i]//2
lst = sorted(list(set(lst)))
def lcm(a, b): # a, b の最大公約数を求める
return(a*b//gcd(a, b))
def lcms(List): # list[a[0], a[1], ... , a[n]]の最小公倍数を求める
if len(List) == 1:
return List[0]
ans = lcm(List[0], List[1])
for i in range(2, len(List)):
ans = lcm(ans, List[i])
return ans
lcm = lcms(lst)
ans = m//lcm
if ans%2 == 0:
ans = ans//2
else:
ans = ans//2 + 1
print(ans)
|
s=list(input())
ans=0
for i in range(len(s)//2):
if s[i]==s[len(s)-1-i]:
continue
ans+=1
print(ans)
| 0 | null | 111,067,993,864,780 | 247 | 261 |
def insection_sort(lst):
lens=len(lst)
ans=0
for i in xrange(lens):
mn=i
for j in xrange(i+1,lens):
if(lst[j]<lst[mn]):
mn=j
if(mn!=i):
tmp=lst[i]
lst[i]=lst[mn]
lst[mn]=tmp
ans+=1
return ans
num=int(raw_input().strip())
arr=map(int,raw_input().strip().split())
ans=insection_sort(arr)
print " ".join(str(pp) for pp in arr)
print ans
|
n, m = list(map(int, input().split()))
c = list(map(int, input().split()))
DP = [i for i in range(n + 1)]
for cost in c:
for i in range(cost, n + 1):
DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[n])
| 0 | null | 77,963,466,308 | 15 | 28 |
def main():
n = int(input())
S, T = [], []
for _ in range(n):
s, t = input().split()
S.append(s)
T.append(int(t))
x = input()
print(sum(T[S.index(x) + 1:]))
if __name__ == '__main__':
main()
|
# FizzBuzz Sum
N = int(input())
ans = ((1+N) * N)/2 - ((3 + 3*(N//3)) * (N//3))/2 - ((5 + 5*(N//5)) * (N//5))/2 + ((15 + 15*(N//15)) * (N//15))/2
print(int(ans))
| 0 | null | 66,125,225,673,012 | 243 | 173 |
# -*- coding: utf-8 -*-
n, m= [int(i) for i in input().split()]
for i in range(0,m):
if n-2*i-1>n/2 or n%2==1:
print(i+1,n-i)
else:
print(i+1,n-i-1)
|
import math
a, b, c, d = map(float, input().split())
s1 = (a - c) * (a - c)
s2 = (b - d) * (b - d)
print("%.6f"%math.sqrt(s1+s2))
| 0 | null | 14,400,616,125,632 | 162 | 29 |
max_n=10**5
mod=10**9+7
frac=[1]
for i in range(1,max_n+1):
frac.append((frac[-1]*i)%mod)
inv=[1,1]
inv_frac=[1,1]
for i in range(2,max_n):
inv.append((mod-inv[mod%i]*(mod//i))%mod)
inv_frac.append((inv_frac[-1]*inv[-1])%mod)
def perm(m,n):
if m<n:
return 0
if m==1:
return 1
return (frac[m]*inv_frac[m-n])%mod
def comb(m,n):
if m<n:
return 0
if m==1:
return 1
return (frac[m]*inv_frac[n]*inv_frac[m-n])%mod
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
for i in range(n-k+1):
s=(s+(a[n-i-1]-a[i])*comb(n-i-1,k-1))%mod
print(s)
|
#import numpy as np
#import math
#from decimal import *
#from numba import njit
#@njit
def main():
X = int(input())
a = 100
count = 0
while a < X:
a += a//100
count += 1
print(count)
main()
| 0 | null | 61,439,930,892,732 | 242 | 159 |
import math
N,K=map(int,input().split())
sum=0
for i in range(K,N+2):
# print(N*(N+1)//2-((N-i)*(N-i+1)//2),i*(i-1)//2)
sum+=(N*(N+1)//2)-((N-i)*(N-i+1)//2)-(i*(i-1)//2)+1
sum%=(10**9+7)
print(sum%(10**9+7))
|
import sys
def solve():
a, b = map(int, input().split())
ans = gcd(a, b)
print(ans)
def gcd(a, b):
return gcd(b, a % b) if b else a
if __name__ == '__main__':
solve()
| 0 | null | 16,710,915,380,800 | 170 | 11 |
#!/usr/bin/env python3
import sys
MOD = 1000000007 # type: int
def solve(N: int, K: int):
num_gcd = {}
for k in range(K, 0, -1):
num_select = K // k
num_gcd_k = pow(num_select, N, MOD)
for multiple in range(2, num_select+1):
num_gcd_k -= num_gcd[k * multiple]
num_gcd[k] = num_gcd_k
result = 0
for k in range(1, K+1):
result += (k * num_gcd[k]) % MOD
print(result % MOD)
return
# Generated by 1.1.6 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()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
solve(N, K)
if __name__ == '__main__':
main()
|
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
#print(l[0][0])
#print(l[0][1])
ans = n-2
ans1 = 0
for m in range(ans):
if l[m][0] == l[m][1] and l[m+1][0] == l[m+1][1] and l[m+2][0] == l[m+2][1]:
ans1 += 1
if ans1 >= 1:
print("Yes")
else:
print("No")
| 0 | null | 19,512,433,913,920 | 176 | 72 |
import math
n=int(input())
xs=list(map(float,input().split()))
ys=list(map(float,input().split()))
ds=[ abs(x - y) for (x,y) in zip(xs,ys) ]
print('{0:.6f}'.format(sum(ds)))
print('{0:.6f}'.format((sum(map(lambda x: x*x,ds)))**0.5))
print('{0:.6f}'.format((sum(map(lambda x: x*x*x,ds)))**(1./3.)))
print('{0:.6f}'.format(max(ds)))
|
from sys import stdin
n = int(stdin.readline().rstrip())
x = [float(x) for x in stdin.readline().rstrip().split()]
y = [float(x) for x in stdin.readline().rstrip().split()]
def minkowski_dist(x, y, p="INF"):
if p == "INF":
return max([abs(x[i]-y[i]) for i in range(n)])
elif isinstance(p, int):
return (sum([(abs(x[i]-y[i]))**p for i in range(n)]))**(1/p)
print(minkowski_dist(x, y, 1))
print(minkowski_dist(x, y, 2))
print(minkowski_dist(x, y, 3))
print(minkowski_dist(x, y))
| 1 | 211,605,621,562 | null | 32 | 32 |
# Common Raccoon vs Monster
H, N = map(int,input().split())
A = list(map(int, input().split()))
ans = ['No', 'Yes'][sum(A) >= H]
print(ans)
|
H, N = map(int, input().split())
As = list(map(int, input().split()))
sumA = sum(As)
if sumA >= H:
print('Yes')
else:
print('No')
| 1 | 77,654,770,504,288 | null | 226 | 226 |
# -*- coding: utf-8 -*-
# E
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
n = int(input())
d1 = [] * n
d2 = [] * n
for i in range(n):
x, y = map(int, input().split())
d1.append(x+y)
d2.append(x-y)
print(max(max(d1) - min(d1), max(d2)-min(d2)))
|
N = int(input())
*A, = map(int, input().split())
dic = {}
ans = 0
for i in range(N):
if A[i] + i in dic:
dic[A[i] + i] += 1
if A[i] + i not in dic:
dic[A[i] + i] = 1
if i - A[i] in dic:
ans += dic[i - A[i]]
print(ans)
| 0 | null | 14,771,164,766,254 | 80 | 157 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
alp = 'abcdefghijklmnopqrstuvwxyz'
number27 = []
cnt = 26
digit = 1
while N > 0:
if N <= cnt:
break
else:
N -= cnt
cnt *= 26
digit += 1
ans = list('a' * digit)
N -= 1
tmp = -1
while N > 0:
N, mod = divmod(N, 26)
ans[tmp] = alp[mod]
tmp -= 1
print(''.join(ans))
if __name__ == '__main__':
# S = input()
N = int(input())
# N, M = map(int, input().split())
# As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
solve(N)
# for i in range(1, 100):
# # print(i)
# solve(i)
|
N = int(input())
ans = ''
while(N > 0):
N -= 1
_i = N % 26
ans = chr(ord('a') + _i) + ans
N //= 26
print(ans)
| 1 | 11,994,710,851,928 | null | 121 | 121 |
n, m = input().split()
a = list(map(int, input().split()))
s = 0
for i in a:
s += int(i)
if int(s) <= int(n):
print(int(n) - int(s))
else:
print("-1")
|
from collections import Counter
n = int(input())
ans = 0
dp = []
cl = []
n1 = n
if n == 1:
ans = 0
else:
for i in range(2, int(n**0.5)+1):
if n%i == 0:
cl.append(i)
while n%i == 0:
n = n/i
dp.append(i)
if n == 1:
break
if n != 1:
ans = 1
c = Counter(dp)
for i in cl:
cnt = 1
while c[i] >= cnt:
c[i] -= cnt
ans += 1
cnt += 1
print(ans)
| 0 | null | 24,500,749,690,180 | 168 | 136 |
a, b, c = map(int, input().split())
a, b = b, a
a, c = c, a
print(f'{a} {b} {c}')
|
import math
n= int(input())
x=n+1
for i in range(2,int(math.sqrt(n)+1)):
if n%i==0:
x= i+ (n/i)
print(int(x)-2)
| 0 | null | 100,083,410,482,582 | 178 | 288 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ruiseki_A = [0]
ruiseki_B = [0]
for i in range(len(A)):
ruiseki_A.append(ruiseki_A[i]+A[i])
for i in range(len(B)):
ruiseki_B.append(ruiseki_B[i]+B[i])
#print(ruiseki_A)
ans = 0
for i in range(len(ruiseki_A)):
tmp = K - ruiseki_A[i]
if tmp < 0:
continue
r = len(ruiseki_B)
l = 0
while r-l > 1:
mid = (r + l) // 2
if ruiseki_B[mid] <= tmp:
l = mid
else:
r = mid
ans = max(ans, i+l)
print(ans)
|
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
h=int(input())
w=int(input())
n=int(input())
v=max(h,w)
cnt=0
while n>0:
n-=v
cnt+=1
print(cnt)
resolve()
| 0 | null | 49,881,380,700,580 | 117 | 236 |
def solve():
H1, M1, H2, M2, K = map(int, input().split())
print((H2*60 + M2) - (H1*60 + M1) - K)
if __name__ == '__main__':
solve()
|
h1,m1,h2,m2,k=map(int,input().split())
if h1>h2:
h2+=24
p=(h2-h1)*60+(m2-m1)
print(p-k)
| 1 | 18,042,289,288,362 | null | 139 | 139 |
A,B,C=map(int,input().split())
K=int(input())
i=0
while i<K:
if A>=B:
i+=1
B*=2
else:
break
while i<K:
if B>=C:
i+=1
C*=2
else:
break
print('YNeos'[(A>=B)or(B>=C)::2])
|
a,b,c=[int(x) for x in input().split(" ")]
k=int(input())
count=0
while b<=a:
count+=1
b*=2
while c<=b:
count+=1
c*=2
if count<=k:
print("Yes")
else:
print("No")
| 1 | 6,884,538,499,902 | null | 101 | 101 |
#!/usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, AS):
for _i in range(K):
d = [0] * (N + 1)
for i in range(N):
x = AS[i]
d[max(i - x, 0)] += 1
d[min(i + x + 1, N)] -= 1
cur = 0
ret = [0] * N
for i in range(N):
cur += d[i]
ret[i] = cur
AS = ret
if all(x == N for x in ret):
return ret
return ret
def main():
N, K = map(int, input().split())
AS = list(map(int, input().split()))
print(*solve(N, K, AS))
T1 = """
5 1
1 0 0 1 0
"""
def test_T1():
"""
>>> as_input(T1)
>>> main()
1 2 2 1 2
"""
T2 = """
5 2
1 0 0 1 0
"""
def test_T2():
"""
>>> as_input(T2)
>>> main()
3 3 4 4 3
"""
def _test():
import doctest
doctest.testmod()
def as_input(s):
"use in test, use given string as input file"
import io
global read, input
f = io.StringIO(s.strip())
def input():
return bytes(f.readline(), "ascii")
def read():
return bytes(f.read(), "ascii")
USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
print("compiling")
from numba.pycc import CC
cc = CC('my_module')
cc.export('solve', solve.__doc__.strip().split()[0])(solve)
cc.compile()
exit()
else:
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
# -p: pure python mode
# if not -p, import compiled module
from my_module import solve # pylint: disable=all
elif sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
# input given as file
input_as_file = open(sys.argv[1])
input = input_as_file.buffer.readline
read = input_as_file.buffer.read
main()
|
M1,D1 = map(int, input().split())
M2,D2 = map(int, input().split())
if M1==12 and M2==1 or M1+1==M2:
print(1)
else:
print(0)
| 0 | null | 70,188,267,028,748 | 132 | 264 |
from collections import Counter
MOD = 998244353
n = int(input())
d = list(map(int,input().split()))
d_count = Counter(d)
ans = 1
pre_count = 1
if d[0] > 0: ans = 0
for i,(dist,count) in enumerate(sorted(d_count.items())):
if i != dist or (i==0 and count > 1):
ans = 0
break
ans *= pow(pre_count,count,MOD)
ans %= MOD
pre_count = count
print(ans)
|
n,m,k = map(int,input().split())
A = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
A[a].append(b)
A[b].append(a)
C = [[] for i in range(n+1)]
for i in range(k):
c,d = map(int,input().split())
C[c].append(d)
C[d].append(c)
from collections import deque
reach = [0]*(n+1)
for i in range(1,n+1):
if reach[i] != 0:
pass
else:
reach[i] = i
q = deque([])
q.append(i)
while q:
x = q.popleft()
for s in A[x]:
if reach[s] == 0:
q.append(s)
reach[s] = i
dis_count = [0]*(n+1)
for i,C0 in enumerate(C):
for CC in C0:
if reach[CC] == reach[i]:
dis_count[i] += 1
import collections
D = collections.Counter(reach)
for i in range(1,n+1):
print(D[reach[i]]-len(A[i])-dis_count[i]-1,end="")
print(" ",end="")
print("")
| 0 | null | 108,029,833,320,380 | 284 | 209 |
# coding: utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
B = [[a, i + 1] for i, a in enumerate(A)]
B.sort()
for i, j in B:
if i == N:
print(j)
else:
print(j, "", end='')
if __name__ == "__main__":
main()
|
n,x,y=map(int,input().split())
a=[0]*n
for i in range(1,n+1):
for j in range(i,n+1):
b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i))
a[b]+=1
print(*a[1:],sep="\n")
| 0 | null | 112,244,896,170,310 | 299 | 187 |
S = input()
L = len(S)
cnt = 0
for i in range(L//2):
if S[i] == S[-1-i]:
continue
else:
cnt += 1
print(cnt)
|
s = list(input())
n = len(s)-1
count = 0
if s != s[::-1]:
for i in range(0,(n+1)//2):
if s[i] != s[n-i]:
count += 1
print(count)
| 1 | 120,039,934,202,682 | null | 261 | 261 |
s=input()
l=['SUN','MON','TUE','WED','THU','FRI','SAT']
d=[7,6,5,4,3,2,1]
print(d[l.index(s)])
|
def main():
lis = list(map(int, input().split()))
ans = lis[0] * lis[2]
a, b = lis[0:2], lis[2:4]
for i in a:
for j in b:
if i * j > ans:
ans = i * j
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 67,932,217,345,988 | 270 | 77 |
d=set()
for _ in[0]*int(input()):
c,g=input().split()
if'i'==c[0]:d|=set([g])
else:print(['no','yes'][g in d])
|
s = input()
print('x'*len(s))
| 0 | null | 36,706,904,577,980 | 23 | 221 |
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
"""def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)"""
"""def pw(a,b):
result=1
while(b>0):
if(b%2==1): result*=a
a*=a
b//=2
return result"""
def inpt():
return [int(k) for k in input().split()]
def check(mid,k,ar):
ct=k
for i in ar:
if(i<=mid):
continue
ct-=(i//mid)
return ct>=0
def main():
n,k=map(int,input().split())
ar=inpt()
i,j=1,100000000000
while(i<j):
mid=(i+j)//2
if(check(mid,k,ar)):
j=mid
else:
i=mid+1
print(i)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
|
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
mid = (ok+ng)//2
cur = 0
for i in range(n):
cur += L[i]//mid
if cur > k:
ok = mid
elif cur <= k:
ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
res = 0
if K[i] > 0:
for j in range(n):
res += (L[j]-1)//K[i]
if res <= k:
P.append(K[i])
print(min(P))
| 1 | 6,529,788,227,310 | null | 99 | 99 |
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos
MOD = 10 ** 9 + 7
INF = 10 ** 18
N = int(input())
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]
print(1 - N)
|
x=input()
if x=='0':
print('1')
if x=='1':
print('0')
| 1 | 2,879,287,559,830 | null | 76 | 76 |
n = str(input())
p = int(input())
keta = len(n)
Dp = [[[0 for _ in range(2)] for _ in range(keta+1)]for _ in range(keta+1)]
Dp[0][0][1] = 1
10
for i in range(keta):
for j in range(i+1):
for k in range(10):
if k == 0:
if k < int(n[i]):
Dp[i+1][j][0] += Dp[i][j][0]
Dp[i+1][j][0] += Dp[i][j][1]
elif k == int(n[i]):
Dp[i+1][j][1] += Dp[i][j][1]
Dp[i+1][j][0] += Dp[i][j][0]
else:
Dp[i+1][j][0] += Dp[i][j][0]
else:
if k < int(n[i]):
Dp[i+1][j+1][0] += Dp[i][j][0]
Dp[i+1][j+1][0] += Dp[i][j][1]
elif k == int(n[i]):
Dp[i+1][j+1][1] += Dp[i][j][1]
Dp[i+1][j+1][0] += Dp[i][j][0]
else:
Dp[i+1][j+1][0] += Dp[i][j][0]
if p > keta:
print(0)
else:
print(sum(Dp[-1][p]))
|
x = raw_input()
a = int (x)**3
print a
| 0 | null | 38,229,690,574,140 | 224 | 35 |
n=int(input())
mod=1000000007
import math
ab=[]
n0=0
for i in range(n):
a,b = map(int,input().split())
if a==0 and b==0:
n0+=1
continue
if b==0:
ab.append( (1,0) )
elif a==0:
ab.append( (0,1) )
else:
gc = math.gcd(a,b)*b//abs(b)
ab.append( (a//gc,b//gc) )
n_eff = n-n0
from collections import Counter
c=Counter(ab)
pairs =[]
for cc in c:
n_dual = c[(-cc[1],cc[0])]
if n_dual>0:
# print(cc)
pairs.append( (c[cc],n_dual) )
ans=1
for p in pairs:
ans = ans*(pow(2,p[0],mod)+pow(2,p[1],mod)-1 ) %mod
amari = n_eff - sum(sum(p) for p in pairs)
ans=ans * pow(2,amari,mod) %mod
ans=ans+n0-1
print(ans%mod)
|
mod = 10 ** 9 + 7
from math import gcd
N = int(input())
from collections import defaultdict
X = defaultdict(lambda: [0, 0])
x = 0
y = 0
z = 0
for i in range(N):
a, b = map(int, input().split())
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)][0] += 1
elif a * b < 0:
X[(abs(b) // g, abs(a) // g)][1] += 1
else:
if a:
x += 1
elif b:
y += 1
else:
z += 1
ans = 1
pow2 = [1]
for i in range(N):
pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
ans *= pow2[i[0]] + pow2[i[1]]- 1
ans %= mod
ans *= pow2[x] + pow2[y] - 1
ans += z - 1
ans %= mod
print(ans)
| 1 | 20,992,743,220,540 | null | 146 | 146 |
N, M = map(int, input().split())
adj = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
start = 0
queue = [start]
pre = [None]*N
pre[0] = 0
while queue:
v = queue.pop(0)
for i in adj[v]:
if pre[i] is None:
pre[i] = v
queue.append(i)
if None in pre:
print("No")
else:
print("Yes")
for p in pre[1:]:
print(p+1)
|
import sys
input = sys.stdin.readline
M1,D1 = map(int, input().split())
M2,D2 = map(int, input().split())
if(M1+1==M2):print(1)
else: print(0)
| 0 | null | 72,294,741,874,980 | 145 | 264 |
from itertools import starmap
(lambda *_: None)(
*map(print,
(lambda board, pairs: starmap(board, pairs))(
(lambda h, w:
(lambda rows: ''.join(map(lambda i: rows[i%2], range(h))))(
(lambda row: (row[:w]+'\n', row[1:w+1]+'\n'))(
'#.'*(w//2+1)))),
map(lambda t: map(int, t),
map(str.split, iter(input, '0 0'))))))
|
while True:
H,W = map(int,input().split())
if H == W == 0:
break
a = '#.'
b = '#'
c = '.#'
d = '.'
def bw(n):
if n % 2 == 0:
print((n//2)*a)
else:
print((n//2)*a + b)
def wb(n):
if n % 2 == 0:
print((n//2)*c)
else:
print((n//2)*c + d)
for i in range(1,H + 1):
if i % 2 == 0:
wb(W)
else:
bw(W)
print()
| 1 | 868,562,933,030 | null | 51 | 51 |
N,M = [int(i) for i in input().split()]
if N%2 == 1:
for i in range(1,M+1):
print(i, end=" ")
print(N+1-i)
exit()
L = min(M,N//4)
for i in range(1,L+1):
print(i,end=" ")
print(N+1-i)
if L < M:
for i in range(L+1,M+1):
print(i,end=" ")
print(N-i)
|
A,B,M=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
XC=[]
for i in range(M):
XC.append(list(map(int,input().split())))
ans=min(aa)+min(bb)
for i in range(M):
ans=min(ans,aa[XC[i][0]-1]+bb[XC[i][1]-1]-XC[i][2])
print(ans)
| 0 | null | 41,309,992,008,018 | 162 | 200 |
s = input()
if ord(s) >= 65 and ord(s) <= 90 :
print("A")
elif ord(s) >= 97 and ord(s) <= 122 :
print("a")
|
def main():
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
if s == u:
print(a-1, b)
else:
print(a, b-1)
if __name__ == "__main__":
main()
| 0 | null | 41,661,428,848,650 | 119 | 220 |
S = input()
T = input()
ans = 0
for n in range(len(S)):
if S[n] != T[n]:
ans += 1
print(ans)
|
first_string = input()
second_string = input()
count = 0
for x, y in zip(first_string, range(len(first_string))):
if(second_string[y] != x):
count += 1
print(count)
| 1 | 10,448,396,383,282 | null | 116 | 116 |
import sys
N = next(sys.stdin.buffer)
X = tuple(map(int, next(sys.stdin.buffer).split()))
min_x = min(X)
max_x = max(X)
stamina = min(sum((p - x) ** 2 for x in X) for p in range(min_x, max_x + 1))
print(stamina)
|
a=int(input())
d=0
for i in range(2,int(a**0.5)+1):
c=0
while a%i==0:
c+=1
a//=i
for i in range(1,60):
if c>=i:
c-=i
d+=1
else:
break
if a==1:
break
if a!=1:
d+=1
print(d)
| 0 | null | 41,258,144,554,880 | 213 | 136 |
x = int(input())
#import fractions
import math
from functools import reduce
def lcm_base(x, y):
#return (x * y) // fractions.gcd(x, y)
return (x * y) // math.gcd(x, y)
l = lcm_base(x, 360)
print(l//x)
|
from sys import stdin
from collections import deque
# 入力
n = int(input())
# command = [stdin.readline()[:-1] for a in range(n)]
command = stdin
# process
output = deque([])
for a in command:
if a[0] == 'i':
output.appendleft(int(a[7:]))
elif a[0:7] == 'delete ':
try:
output.remove(int(a[7:]))
except ValueError:
pass
elif a[6] == 'F':
output.popleft()
else:
output.pop()
# 出力
print(*list(output))
| 0 | null | 6,564,996,075,660 | 125 | 20 |
n = int(input())
if n % 2 == 0:
work = int(n / 2)
s = input()
a = s[:work]
b = s[work:]
if a == b:
print("Yes")
else:
print("No")
else:
print("No")
|
N = int(input())
S = input()
ans = "Yes"
if N % 2 != 0:
ans = "No"
else:
N = int(N/2)
for i in range(0, N):
if S[i] != S[i+N]:
ans = "No"
break
print(ans)
| 1 | 146,546,780,073,552 | null | 279 | 279 |
mod = 1000000007
n = int(input())
ans = pow(10,n,mod) - 2 * pow(9,n,mod) + pow(8,n,mod)
ans = (ans % mod + mod) % mod
print(ans)
|
s = input()
day = ['SAT','FRI','THU','WED','TUE','MON','SUN']
for i in range(7):
if s == day[i]:
print(i + 1)
exit()
| 0 | null | 68,350,177,589,440 | 78 | 270 |
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])
|
cin = open(0).read().strip().split('\n')
n = int(cin[0])
v = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]]
import queue
q = queue.Queue()
q.put(0)
dist = [-1]*n
dist[0] = 0
seen = [False]*n
while not q.empty():
num = q.get()
seen[num] = True
for a in v[num]:
if dist[a] != -1: continue
dist[a] = dist[num] + 1
q.put(a)
for idx, num in enumerate(dist):
print(idx+1, num)
| 1 | 4,574,565,530 | null | 9 | 9 |
import sys
from fractions import gcd
[print("{} {}".format(gcd(k[0], k[1]), (k[0] * k[1]) // gcd(k[0], k[1]))) for i in sys.stdin for k in [[int(j) for j in i.split()]]]
|
def GCD(a, b):
if b > a:
return GCD(b, a)
elif a % b == 0:
return b
return GCD(b, a % b)
def LCM(a, b):
return a * b // GCD(a, b)
import sys
L = sys.stdin.readlines()
for line in L:
x, y = list(map(int, line.split()))
print(GCD(x, y), LCM(x, y))
| 1 | 555,165,322 | null | 5 | 5 |
N = int(input())
A = [int(a) for a in input().split()]
cum_A = [0] * N
cum_A[0] = A[0]
for i in range(1, N):
cum_A[i] = cum_A[i - 1] + A[i]
ans = 0
for i in range(N - 1):
inner_sum = cum_A[-1] - cum_A[i]
ans += A[i] * inner_sum
print(ans % (10**9 + 7))
|
X, K, D = map(int, input().split())
value = abs(X)
if (value / D) >= K:
print(value - D * K)
else:
min_count = value // D
mod_value = K - min_count
if mod_value % 2 == 0:
print(value % D)
else:
print(abs(value % D - D))
| 0 | null | 4,508,869,336,020 | 83 | 92 |
n = list(input())
sList = list(map(int,input().split()))
q = list(input())
tList = list(map(int,input().split()))
tCount = 0
for tmp_t in tList:
if 0 < sList.count(tmp_t):
tCount += 1
print(tCount)
|
import sys
ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'
def main():
S = get_input1()
T = get_input2()
count = 0
for t in T:
for s in S:
if t == s:
count += 1
break
print(count)
def get_input1():
n = int(input())
if n > 10000:
print(ERROR_INPUT)
sys.exit(1)
li = []
for x in input().split(' '):
if int(x) < 0 or int(x) > 10 ** 9:
print(ERROR_INPUT)
sys.exit(1)
li.append(x)
return li
def get_input2():
n = int(input())
if n > 500:
print(ERROR_INPUT)
sys.exit(1)
li = []
for x in input().split(' '):
if int(x) < 0 or int(x) > 10 ** 9:
print(ERROR_INPUT)
sys.exit(1)
elif int(x) in li:
print(ERROR_INPUT_NOT_UNIQUE)
sys.exit(1)
li.append(x)
return li
main()
| 1 | 64,254,691,886 | null | 22 | 22 |
num_cnt = int(input().rstrip())
nums = list(map(int, input().rstrip().split(" ")))
for i in range(num_cnt):
tmpNum = nums[i]
j = i -1
while j >=0:
if nums[j] <= tmpNum:
break
nums[j+1] = nums[j]
j = j-1
nums[j+1] = tmpNum
print (" ".join(map(str,nums)))
|
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()
| 0 | null | 23,789,076,351,068 | 10 | 192 |
import numpy as np
from numba import jit
@jit('i4[:](i4,i4,i4[:])',cache = True)
def solve(n,k,A):
l,r=0,0
for i in range(k):
B=np.zeros(n+1,dtype=np.int64)
for x,y in enumerate(list(A)):
l=max(0,x-y)
r=min(n,x+y+1)
B[l]+=1
B[r]-=1
A=np.cumsum(B[:-1])
if A[A==n].size==n:
break
return A
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=np.array(a)
X=solve(n,k,A)
print(*X,sep=' ')
|
n = int(input())
fo_x = '0' + str(n) + 'b'
a = [None] * n
x = [None] * n
y = [None] * n
ans = 0
flag = 0
for i in range(n):
a[i] = int(input())
ax = [None] * a[i]
ay = [None] * a[i]
for j in range(a[i]):
ax[j],ay[j] = map(int,input().split())
x[i] = ax
y[i] = ay
for i in range(2 ** n):
b = format(i,fo_x)
for j in range(len(b)):
if b[j] == '0':
continue
for z in range(a[j]):
if str(y[j][z]) != b[x[j][z]-1]:
flag = 1
break
if flag == 1:
break
if flag == 0:
ans = max(ans,b.count('1'))
flag = 0
print(ans)
| 0 | null | 68,371,552,068,960 | 132 | 262 |
N = int(input())
N = N%10
if N == 2 or N == 4 or N == 5 or\
N == 7 or N == 9:
print('hon')
elif N == 0 or N == 1 or N == 6 or\
N == 8:
print('pon')
else:
print('bon')
|
n = int(input())
h = [2,4,5,7,9]
p = [0,1,6,8]
b = [3]
t = n%10
if t in h:
print("hon")
elif t in p:
print("pon")
else:
print("bon")
| 1 | 19,245,646,850,460 | null | 142 | 142 |
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 # (string,3) 3回
from collections import deque
from collections import defaultdict
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
def readInts():
return list(map(int,input().split()))
def main():
a,b = readInts()
print(a - b*2 if a - b*2 >= 0 else 0)
if __name__ == '__main__':
main()
|
a, b = map(int, input().split())
ans = a - b*2
print(ans if ans > 0 else 0)
| 1 | 166,363,665,417,790 | null | 291 | 291 |
N = int(input())
A = list(map(int,input().split()))
Adict = {}
for i in range(N):
Adict[A[i]] = (i+1)
ans = []
for i in range(1,N+1):
ans.append(str(Adict[i]))
print(" ".join(ans))
|
# ['表面', '南面', '東面', '西面', '北面', '裏面']
dice = input().split()
com = [c for c in input()]
rolling = {
'E': [3, 1, 0, 5, 4, 2],
'W': [2, 1, 5, 0, 4, 3],
'S': [4, 0, 2, 3, 5, 1],
'N': [1, 5, 2, 3, 0, 4]
}
for c in com:
dice = [dice[i] for i in rolling[c]]
print(dice[0])
| 0 | null | 90,855,848,235,712 | 299 | 33 |
from __future__ import print_function
import sys
from functools import reduce
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
return
def solve02():
n = int(input().strip())
L = []
Xmin, Ymin, Xmax, Ymax = (sys.maxsize, sys.maxsize, -100, -100)
for i in range(n):
a, b = map(int, input().strip().split())
L.append((a, b))
Xmin, Ymin, Xmax, Ymax = (min(Xmin, a), min(Ymin, b), max(Xmax, a), max(Ymax, b))
A, B, C, D = ((Xmin, Ymax), (Xmin, Ymin), (Xmax, Ymin), (Xmax, Ymax))
# 対角線ACについて
d_MinDistFromA = sys.maxsize # 点Aからの距離が最小であるような,その最小の距離の値を求める
d_MinDistFromC = sys.maxsize # 点Cからの距離が最小であるような,その最小の距離の値を求める
# 対角線BDについて
d_MinDistFromB = sys.maxsize # 点Bからの距離が最小であるような,その最小の距離の値を求める
d_MinDistFromD = sys.maxsize # 点Dからの距離が最小であるような,その最小の距離の値を求める
for a, b in L:
d_MinDistFromA = min(d_MinDistFromA, abs(a - Xmin) + abs(b - Ymax))
d_MinDistFromC = min(d_MinDistFromC, abs(a - Xmax) + abs(b - Ymin))
d_MinDistFromB = min(d_MinDistFromB, abs(a - Xmin) + abs(b - Ymin))
d_MinDistFromD = min(d_MinDistFromD, abs(a - Xmax) + abs(b - Ymax))
# 出力
ans1 = abs(A[0] - C[0]) + abs(A[1] - C[1]) - (d_MinDistFromA + d_MinDistFromC)
ans2 = abs(B[0] - D[0]) + abs(B[1] - D[1]) - (d_MinDistFromB + d_MinDistFromD)
print(max(ans1, ans2))
def main():
solve02()
if __name__ == '__main__':
main()
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
n,k = [int(x) for x in stdin.readline().rstrip().split()]
p = [(int(x)+1)/2 for x in stdin.readline().rstrip().split()]
m = sum(p[0:k])
maxm = m
for i in range(1,n-k+1):
m = m - p[i-1] + p[i+k-1]
maxm = max([maxm,m])
print(maxm)
| 0 | null | 39,332,872,769,920 | 80 | 223 |
def pcmod(n):
if n==0:
return 1
return 1+pcmod(n%bin(n).count('1'))
def main():
n = int(input())
x = list(map(int,list(input())))
m_1 = x.count(1)-1
m_0 = x.count(1)+1
baser_1 = 0
baser_0 = 0
if m_1!=0:
for i in range(n):
baser_1 += x[i] * pow(2,(n-1-i),m_1)
baser_1 %= m_1
for i in range(n):
baser_0 += x[i] * pow(2,(n-1-i),m_0)
baser_0 %= m_0
ans = [0]*n
for i in range(n):
a = 0
if x[i]==1:
if m_1==0:
ans[i] = 0
continue
t = (baser_1 - pow(2,(n-1-i),m_1))%m_1
a = pcmod(t)
if x[i]==0:
t = (baser_0 + pow(2,(n-1-i),m_0))%m_0
a = pcmod(t)
ans[i] = a
for a in ans:
print(a)
if __name__ == "__main__":
main()
|
str = input() *2
pattern = input()
if pattern in str:
print("Yes")
else:
print("No")
| 0 | null | 4,988,650,252,810 | 107 | 64 |
def makeRelation():
visited=[False]*(N+1)
g=0 # group
for n in range(1,N+1):
if visited[n]:
continue
q={n}
D.append(set())
while q:
j=q.pop()
for i in F[j]: # search for friend
if not visited[i]:
visited[i]=True
q.add(i)
D[g]|={i}
g+=1
def main():
makeRelation()
#print(D)
for g in D:
for d in g:
ans[d]=len(g) - len(F[d]) - len(g&B[d]) - 1
print(*ans[1:])
if __name__=='__main__':
N, M, K = map(int, input().split())
F=[set() for n in range(N+1)]
AB=[list(map(int, input().split())) for m in range(M)]
for a,b in AB:
F[a].add(b)
F[b].add(a)
B=[set() for n in range(N+1)]
CD=[list(map(int, input().split())) for k in range(K)]
for c,d in CD:
B[c].add(d)
B[d].add(c)
D=[]
#print(F)
#print(B)
ans=[0]*(N+1)
main()
|
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
ans = 1
if m1 == m2:
ans = 0
print(ans)
| 0 | null | 92,732,682,088,668 | 209 | 264 |
N=int(input())
X=sorted(list(map(int, input().split())))
ans =100000000000
tmp=0
cnt=0
for i in range(X[0],X[-1]+1):
for j in range(len(X)):
tmp += (X[j]-i)**2
if ans > tmp:
ans =tmp
tmp=0
print(ans)
|
n = int(input())
x = list(map(int, input().split()))
ans = 10**6
for i in range(1, 101):
str = 0
for j in x:
str += (j-i)**2
ans = min(ans, str)
print(ans)
| 1 | 65,517,754,286,642 | null | 213 | 213 |
a,b,c=input().split()
print(c,a,b)
|
n= int(input())
mod=10**9+7
a= [int(x ) for x in input().split()]
b= a[:]
s=0
for i in range(n-2,-1,-1):
b[i]=b[i+1]+b[i]
for i in range(n):
s += (b[i]-a[i])*a[i]
print(s%mod)
| 0 | null | 20,779,214,729,348 | 178 | 83 |
h, w, k = map(int, input().split())
s = [list(map(int, input())) for _ in range(h)]
ans = float("inf")
for sep in range(1 << (h-1)):
g_id = [0] * h
cur = 0
for i in range(h-1):
g_id[i] = cur
if sep >> i & 1: cur += 1
g_id[h-1] = cur
g_num = cur+1
ng = False
for i in range(w):
tmp = [0] * g_num
for j in range(h): tmp[g_id[j]] += s[j][i]
if any([x > k for x in tmp]): ng = True; break
if ng: continue
res = g_num-1
gs = [0] * g_num
for i in range(h):
gs[g_id[i]] += s[i][0]
for i in range(1, w):
tmp = gs[::]
for j in range(h):
tmp[g_id[j]] += s[j][i]
if any([x > k for x in tmp]):
res += 1
gs = [0] * g_num
for j in range(h): gs[g_id[j]] += s[j][i]
ans = min(ans, res)
print(ans)
|
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
def divide_choco(bit):
divrow_num = bin(bit).count("1") + 1 # 割った回数+1
choco_current = [[0] * w for _ in range(divrow_num)]
row_divided_cur = 0
for col, piece in enumerate(choco[0]):
choco_current[0][col] = piece
for row in range(h - 1):
if bit >> row & 1:
row_divided_cur += 1
for col, piece in enumerate(choco[row + 1]):
choco_current[row_divided_cur][col] += piece
return choco_current, divrow_num
h, w, k = list(map(int, readline().split()))
choco = []
for i in range(h):
choco_in = input()
choco_add = [int(c) for c in choco_in]
choco.append(choco_add)
ans = INF
for bit in range(1 << (h - 1)):
choco_current, divrow_num = divide_choco(bit)
choco_cursum = [0] * divrow_num
is_exceed = False # 超えてる場合True
ans_temp = bin(bit).count("1")
if divrow_num > 1:
for col in range(w):
choco_currow = [choco_current[dr][col] for dr in range(divrow_num)]
for drow, pieces in enumerate(choco_currow):
if pieces > k:
ans_temp += INF
elif choco_cursum[drow] + pieces > k:
is_exceed = True
if is_exceed:
choco_cursum = [cc for cc in choco_currow]
ans_temp += 1
is_exceed = False
else:
choco_cursum = [cc + cs for cc, cs in zip(choco_currow, choco_cursum)]
else:
choco_cursum = 0
for pieces in choco_current[0]:
if pieces > k:
ans_temp += INF
elif choco_cursum + pieces > k:
choco_cursum = pieces
ans_temp += 1
else:
choco_cursum = choco_cursum + pieces
ans = min(ans, ans_temp)
print(ans)
if __name__ == '__main__':
main()
| 1 | 48,549,175,742,352 | null | 193 | 193 |
n,x,y = map(int,input().split())
ans = [0] * (n-1)
l = list(range(1,n+1))
import itertools
for a,b in itertools.combinations(l, 2):
dis = min(b-a, abs(b-y)+abs(x-a)+1)
ans[dis-1] += 1
for i in ans:
print(i)
|
s = str(input())
if s.count('RRR') == 1:
print(3)
elif s.count('RR') == 1:
print(2)
elif 1 <= s.count('R'):
print(1)
else:
print(0)
| 0 | null | 24,333,613,516,700 | 187 | 90 |
#!/usr/bin/env python3
import sys
DEBUG = False
class SegmentTree:
# Use 1-based index internally
def __init__(self, n, merge_func, fillval=sys.maxsize):
self.n = 1
while self.n < n:
self.n *= 2
self.nodes = [fillval] * (self.n * 2 - 1 + 1) # +1 for 1-based index
self.merge_func = merge_func
self.fillval = fillval
def update(self, idx, val):
idx += 1 # for 1-based index
nodes = self.nodes
mergef = self.merge_func
idx += self.n - 1
nodes[idx] = val
while idx > 1: # > 1 for 1-based index
idx >>= 1 # parent(idx) = idx >> 1 for 1-based index segment tree
nodes[idx] = mergef(nodes[idx << 1], nodes[(idx << 1) + 1]) # child(idx) = idx << 1 and idx << 1 + 1
def query(self, l, r):
l += 1; r += 1 # for 1-based index
l += self.n - 1
r += self.n - 1
acc = self.fillval
while l < r:
if l & 1:
acc = self.merge_func(acc, self.nodes[l])
l += 1
if r & 1:
acc = self.merge_func(acc, self.nodes[r - 1])
r -= 1
l >>= 1
r >>= 1
return acc
def read(t = str):
return t(sys.stdin.readline().rstrip())
def read_list(t = str, sep = " "):
return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]
def dprint(*args, **kwargs):
if DEBUG:
print(*args, **kwargs)
return
def main():
read()
s = read()
a_ord = ord("a")
bit_offsets = {chr(c_ord): c_ord - a_ord for c_ord in range(ord("a"), ord("z") + 1)}
apps = SegmentTree(len(s), lambda x, y: x | y, 0)
i = 0
for c in s:
apps.update(i, 1 << bit_offsets[c])
i += 1
nr_q = read(int)
for i in range(0, nr_q):
q = read_list()
if q[0] == "1":
_, i, c = q # i_q in the question starts from 1, not 0
apps.update(int(i) - 1, 1 << bit_offsets[c])
else:
_, l, r = q # l_q and r_q in the question start from 1, not 0
print(bin(apps.query(int(l) - 1, int(r) - 1 + 1)).count("1")) # query in the question includes both edges
if __name__ == "__main__":
main()
|
n = int(input())
title = []
length = []
for i in range(n):
a, b = input().split()
title.append(a)
length.append(int(b))
i = title.index(input())
print(sum((length[i+1:])))
| 0 | null | 80,063,510,190,670 | 210 | 243 |
import collections
from math import factorial
def permutations_count(n, r):
''' 順列 '''
return factorial(n) // factorial(n - r)
def combinations_count(n, r):
''' 組み合わせ '''
return factorial(n) // (factorial(n - r) * factorial(r))
S = input()
lis = []
amari = 1
lis.append(int(S[-1]))
for i in range(2,len(S)+1):
amari = (amari * 10) % 2019
lis.append((int(S[-1*i]) * amari + lis[i-2]) % 2019)
c = collections.Counter(lis)
su = 0
for k in c:
if c[k] > 1:
su += combinations_count(c[k], 2)
su += c[0]
print(su)
|
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n,u,v=map(int,input().split())
node=[[]for _ in range(n)]
for _ in range(n-1):
a,b=map(int,input().split())
node[a-1].append(b-1)
node[b-1].append(a-1)
def dfs(i):
visited[i]=1
for x in node[i]:
if visited[x]==0:
dis[x]=dis[i]+1
dfs(x)
inf=10**9
dis=[inf]*n;dis[u-1]=0;visited=[0]*n
dfs(u-1)
dis2=[]
from copy import copy
dis_dash=copy(dis)
dis2.append(dis_dash)
dis[v-1]=0;visited=[0]*n
dfs(v-1)
dis2.append(dis)
cnt=0
for i in range(n):
if dis2[0][i]<dis2[1][i]:
cnt=max(cnt,dis2[1][i])
print(cnt-1)
| 0 | null | 74,304,830,459,860 | 166 | 259 |
(a,b,c) = input().rstrip().split()
a = int(a)
b = int(b)
c = int(c)
if a <= b <= c:
print(a,b,c)
elif a <= c <= b:
print(a,c,b)
elif b <= a <= c:
print(b,a,c)
elif b <= c <= a:
print(b,c,a)
elif c<= a <= b:
print(c,a,b)
else:
print(c,b,a)
|
l = map(int,raw_input().split())
l.sort()
print "%d %d %d" %(l[0] ,l[1], l[2])
| 1 | 424,274,904,480 | null | 40 | 40 |
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class Mod:
def __init__(self, m):
self.m = m
def add(self, a, b):
return (a + b) % self.m
def sub(self, a, b):
return (a - b) % self.m
def mul(self, a, b):
return ((a % self.m) * (b % self.m)) % self.m
def div(self, a, b):
return self.mul(a, pow(b, self.m-2, self.m))
def pow(self, a, b):
return pow(a, b, self.m)
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD
@mt
def slv(K, S):
M = 10**9+7
C = Combination(2*(10**6), M)
MOD = Mod(M)
ans = 0
S = len(S)
N = S + K
for k in range(K+1):
r = K -k
a = MOD.pow(26, r)
b = MOD.mul(MOD.pow(25, k), C(k+S-1, k))
ans = MOD.add(ans, MOD.mul(a, b))
return ans
def main():
K = read_int()
S = read_str()
print(slv(K, S))
if __name__ == '__main__':
main()
|
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
# nCk
## 0!~n!をmodしつつ求める
def fact_all(n,M=mod):
f = [1]*(n+1)
ans = 1
for i in range(1,n+1):
ans = (ans*i)%M
f[i] = ans
return f
## inv(0!)~inv(n!)をmodしつつ求める
def fact_inv_all(fact_all,M=mod):
N = len(fact_all)
finv = [0]*N
finv[-1] = pow(fact_all[-1],M-2,M)
for i in range(N-1)[::-1]:
finv[i] = finv[i+1]*(i+1)%M
return finv
## nCkをmodしつつ返す
def nCk(n,k,fact_list,inv_list,M=mod):
return (((fact_list[n]*inv_list[k])%M)*inv_list[n-k])%M
K = I()
S = list(input())
N = len(S)
fl = fact_all(N+K+1)
il = fact_inv_all(fl)
beki25 = [1]*(N+K+1)
for i in range(1,N+K+1):
beki25[i] = beki25[i-1]*25
beki25[i] %= mod
beki26 = [1]*(N+K+1)
for i in range(1,N+K+1):
beki26[i] = beki26[i-1]*26
beki26[i] %= mod
ans = 0
for i in range(N-1,N+K):
ans += nCk(i,N-1,fl,il)*beki25[i-N+1]*beki26[N+K-1-i]
ans %= mod
print(ans)
| 1 | 12,838,707,901,530 | null | 124 | 124 |
# ABC 147 D
N=int(input())
A=list(map(int,input().split()))
res=0
p=10**9+7
bits=[0]*71
for a in A:
j=0
while a>>j:
if (a>>j)&1:
bits[j]+=1
j+=1
t=0
n=70
while n>=0:
if bits[n]!=0:
break
n-=1
for a in A:
j=0
while j<=n:
if (a>>j)&1:
res+=((2**j)*(N-bits[j]))%p
else:
res+=((2**j)*bits[j])%p
j+=1
t=res
print((res*500000004)%p)
|
def main():
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
# Aの中でd桁目が0,1であるものの個数を求める(p,qとする)
# 全部のd桁目についてループして、ans+=(2**d)*(p*q)
ans = 0
for d in range(60):
p,q = 0,0
for i in range(N):
if A[i]%2==0: p+=1
else: q+=1
A[i] //= 2
ans += ((2**d)*p*q)%MOD
ans %= MOD
print(ans)
main()
| 1 | 122,997,950,258,272 | null | 263 | 263 |
chs = 'abcdefghijklmnopqrstuvwxyz'
s = input()
for i,c in enumerate(chs):
if s == c:
print(chs[i+1])
break
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
c = input()
c = chr(ord(c)+1)
print(c)
| 1 | 92,382,100,898,880 | null | 239 | 239 |
a=[1,2,3,4,5,6,7,8,9]
b=[1,2,3,4,5,6,7,8,9]
for i in a:
for j in b:
print(str(i)+"x"+str(j)+"="+str(i*j))
|
import math , sys
def fac(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append(cnt)
if temp!=1:
arr.append(1)
if arr==[]:
arr.append(1)
return arr
def sta ( x ):
return int( 0.5* (-1 + math.sqrt(1+8*x)))
N = int( input() )
if N == 1:
print(0)
sys.exit()
if N == 2 or N ==3:
print(1)
sys.exit()
Is = fac( N )
ans = sum( [ sta(j) for j in Is])
print(max(ans,1))
| 0 | null | 8,553,497,630,272 | 1 | 136 |
s = input()
p = input()
s = s * 2
for i in range(len(s) - len(p) + 1):
#print(s[i:i + len(p)])
if p == s[i:i + len(p)]:
print("Yes")
exit()
print("No")
|
s = input() * 2
p = input()
print("Yes" if s.find(p, 0, len(s) )>= 0 else "No")
| 1 | 1,748,951,874,000 | null | 64 | 64 |
import math
n = int(input())
a,b = 1,n
for i in range(1,int(math.sqrt(n)+1)):
if n%i == 0:
q = n//i
if abs(a-b) > abs(q-i):
a,b = i,q
print((a-1) + (b-1))
|
import sys
a,b,c = map(int,sys.stdin.readline().split())
counter = 0
for n in range(a,b+1):
if c % n == 0:
counter += 1
print(counter)
| 0 | null | 81,166,805,552,198 | 288 | 44 |
def f_sugoroku(INF=float('inf')):
from collections import deque
N, M = [int(i) for i in input().split()]
S = input()
dp = [INF] * (N + 1) # [v]: 頂点 v からゴール到達までに最低何回かかるか
dp[N] = 0
q = deque([0])
for i in range(N - 1, -1, -1):
while True:
if len(q) == 0:
return '-1'
if q[0] != INF and len(q) <= M:
break
q.popleft()
if S[i] == '0':
dp[i] = q[0] + 1
q.append(dp[i])
ans = []
current = 0
rest = dp[0] # ゴールまであと何回ルーレットを回すか
while current < N:
# dp の値が rest から 1 減るまでインデックスを進める
i = 1
rest -= 1 # ルーレットを回した
while dp[current + i] != rest:
i += 1
# ルーレットの出目を答えに追加し、現在位置を進める
ans.append(i)
current += i
return ' '.join(map(str, ans))
print(f_sugoroku())
|
import sys
while True:
cards = sys.stdin.readline().strip()
if cards == "-":
break
n = int(sys.stdin.readline())
for i in range(n):
h = int(sys.stdin.readline())
cards = cards[h:] + cards[:h]
print(cards)
| 0 | null | 70,300,076,799,172 | 274 | 66 |
N = int(input())
if N % 2 != 0:
print((N + 1) // 2 - 1)
else:
print(N//2 -1)
|
# D - Friend Suggestions
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def root(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.root(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.root(x)
y = self.root(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):
return self.root(x) == self.root(y)
def size(self, x):
return -self.parents[self.root(x)]
N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
x,y = map(int,input().split())
block[x] += 1
block[y] += 1
friend.union(x,y)
for _ in range(K):
x,y = map(int,input().split())
if friend.same(x,y):
block[x] += 1
block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans)
| 0 | null | 107,449,118,635,232 | 283 | 209 |
from collections import deque
def breadth_first_search(adj_matrix, n):
distance = [0] + [-1] * (n - 1)
searching = deque([0])
while len(searching) > 0:
start = searching.popleft()
for end in range(n):
if adj_matrix[start][end] and distance[end] == -1:
searching.append(end)
distance[end] = distance[start] + 1
return distance
def main():
n = int(input())
adj = [[False for _ in range(n)] for _ in range(n)]
for _ in range(n):
ukv = input().split()
id = int(ukv[0])
dim = int(ukv[1])
if dim > 0:
nodes = map(int, ukv[2:])
for node in nodes:
adj[id - 1][node - 1] = True
distance = breadth_first_search(adj, n)
for i in range(n):
print("{} {}".format(i + 1, distance[i]))
if __name__ == "__main__":
main()
|
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect
MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 8)
n = int(input())
dis = [-1] * n
info = [list(map(int, input().split())) for _ in range(n)]
stack = [[0, 0]]
ans = 0
while len(stack) > 0:
num = stack.pop(0)
if dis[num[0]] == -1:
dis[num[0]] = num[1]
for i in info[num[0]][2:]:
if dis[i-1] == -1:
stack.append([i - 1, num[1] + 1])
for i in range(n):
print(str(i+1) + " " + str(dis[i]))
| 1 | 4,055,610,618 | null | 9 | 9 |
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(N):
b = int(input())
for i in range(3):
for j in range(3):
if A[i][j]==b:
B[i][j] = 1
flag = 0
for i in range(3):
if sum(B[i])==3:
flag = 1
break
for j in range(3):
cnt = 0
for i in range(3):
cnt += B[i][j]
if cnt==3:
flag = 1
break
if B[0][0]+B[1][1]+B[2][2]==3:
flag = 1
if B[2][0]+B[1][1]+B[0][2]==3:
flag = 1
if flag==1:
print("Yes")
else:
print("No")
|
h, n = map(int, input().split())
a = list(map(int, input().split()))
if h <= sum(a): print("Yes")
else: print("No")
| 0 | null | 68,751,401,624,746 | 207 | 226 |
def selectionSort(A):
n = len(A)
cnt = 0
for i in range(n):
minj = i
for j in range(i,n):
if A[minj] > A[j]:
minj = j
if minj != i:
A[i], A[minj] = A[minj], A[i]
cnt += 1
print(*A)
print(cnt)
n = int(input())
A = list(map(int, input().split(" ")))
selectionSort(A)
|
N,K = map(int,input().split())
tmp = 1
for i in range(1,40):
if N >= K**i:
tmp = i+1
else:
print(tmp)
break
| 0 | null | 31,990,149,880,260 | 15 | 212 |
M=998244353
f=lambda:[*map(int,input().split())]
n,k=f()
lr=[f() for _ in range(k)]
dp=[0]*n
dp[0]=1
S=[0]
for i in range(1,n):
S+=[S[-1]+dp[i-1]]
for l,r in lr:
dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)]
dp[i]%=M
print(dp[-1])
|
a,b = input().split()
aaa = a * int(b)
bbb = b * int(a)
print(min(aaa, bbb))
| 0 | null | 43,509,443,743,360 | 74 | 232 |
a, b, c, d = map(int, input().split())
if c%b==0:
x = c//b
else:
x = c//b+1
if a%d==0:
y = a//d
else:
y = a//d+1
if x<=y:
print("Yes")
else:
print("No")
|
a, b, c, d = map(int, input().split())
taka = 0
aoki = 0
while a > 0:
a = a - d
taka += 1
while c > 0:
c = c - b
aoki += 1
if taka < aoki:
print("No")
else:
print("Yes")
| 1 | 29,688,627,781,670 | null | 164 | 164 |
import itertools
n = int(input())
p = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
p[i][0],p[i][1] = map(int,input().split())
#print(p)
def dis(a,b):
dis = (a[0]-b[0]) ** 2 + (a[1]-b[1]) **2
return dis ** (1/2)
perm = [i for i in range(n)]
total = 0
num = 0
for v in itertools.permutations(perm,n):
path = 0
for i in range(n-1):
path += dis(p[v[i]],p[v[i+1]])
num += 1
total += path
print(total/num)
|
import sys
input = sys.stdin.readline
n,d,a = map(int,input().split())
attack = [0 for _ in range(n)]
event = []
for i in range(n):
x,h = map(int,input().split())
h = (h-1)//a+1
event.append([x-d,0,h,i])
event.append([x+d,1,h,i])
event.sort()
#print(event)
ans = 0
now = 0
for j in range(2*n):
x,m,h,i = event[j]
if m == 0:
if h > now:
attack[i] += h-now
ans += h-now
now = h
else:
now -= attack[i]
print(ans)
| 0 | null | 115,029,157,946,186 | 280 | 230 |
def bubble_sort(numbers, n):
"""bubble sort method
Args:
numbers: a list of numbers to be sorted by bubble sort
n: len(list)
Returns:
sorted list
"""
flag = True
counter = 0
while flag:
flag = False
for index in range(n - 1, 0, -1):
if numbers[index] < numbers[index - 1]:
numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
flag = True
counter += 1
return numbers, counter
n = int(raw_input())
numbers = [int(x) for x in raw_input().split()]
numbers, swapped_numbers = bubble_sort(numbers, n)
print(" ".join([str(x) for x in numbers]))
print(swapped_numbers)
|
def bubble(A,N):
flag=1
cnt=0
while flag==1:
flag=0
for j in range(1,N):
if A[j]<A[j-1]:
k=A[j-1]
A[j-1]=A[j]
A[j]=k
flag=1
cnt+=1
return A,cnt
n=int(raw_input())
list=map(int,raw_input().split())
list,cnt=bubble(list,n)
for x in list:
print x,
print
print cnt,
| 1 | 16,711,875,960 | null | 14 | 14 |
import sys
N = int(input())
result = 0
for a in range(1, N):
if N % a == 0:
b_count = N // a - 1
else:
b_count = N // a
result += b_count
print(result)
|
import sys
input = sys.stdin.buffer.readline
N = int(input())
ans = 0
for a in range(1, N+1):
maxb = (N-1)//a
ans += maxb
print(ans)
| 1 | 2,602,204,984,548 | null | 73 | 73 |
def abc145c_average_length():
import itertools
import math
n = int(input())
x = []
y = []
for _ in range(n):
a, b = map(int, input().split())
x.append(a)
y.append(b)
result = 0
cnt = 0
for p in itertools.permutations(range(n)):
total = 0
for i in range(n-1):
total += math.sqrt(pow(x[p[i]]-x[p[i+1]], 2)+pow(y[p[i]]-y[p[i+1]], 2))
result += total
cnt += 1
print(result/cnt)
abc145c_average_length()
|
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, log
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 fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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 *
N = INT()
L = LIST()
L.sort()
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
idx = bisect_left(L, a+b) - 1
if j < idx:
ans += idx - j
print(ans)
| 0 | null | 159,968,477,371,692 | 280 | 294 |
n = int(input())
s = input()
rs = s.count('R')
oks = s[:rs].count('R')
print(rs - oks)
|
N = int(input())
c = input()
num_red = c.count('R')
print(num_red - c[:num_red].count('R'))
| 1 | 6,329,870,862,432 | null | 98 | 98 |
n = int(input())
ans = -1
for k in range(n, 0, -1):
if n == k * 108 // 100:
ans = k
break
if ans > 0: print(ans)
else: print(':(')
|
def resolve():
import math
n = int(input())
for i in range(1, n+1):
if math.floor(i * 1.08) == n:
print(i)
quit()
print(":(")
resolve()
| 1 | 125,852,128,252,900 | null | 265 | 265 |
while True:
x,y = [int(i) for i in input().split()]
if x == 0 and y == 0:
break
if x>y:
print(str(y) + " " + str(x))
else:
print(str(x) + " " + str(y))
|
i=0
while 1:
i+=1
x,y=map(int, raw_input().split())
if x==0 and y==0:
break
print min(x,y),max(x,y)
| 1 | 522,643,834,788 | null | 43 | 43 |
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log,gcd #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod-2,mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N=I()
A,B=[],[]
for i in range(N):
a,b = MI()
A.append(a)
B.append(b)
both_zero_cnt = 0
num_of_group = defaultdict(int) ##既約分数にしてあげて、(分子,分母)がkeyで、負なら分子が負になる他は正
for i in range(N):
a,b = A[i], B[i]
if(a==b==0):
both_zero_cnt+=1
continue
elif(a==0):
num_of_group[-inf,inf] += 1
num_of_group[inf,inf] += 0
elif(b==0):
num_of_group[inf,inf] += 1
else:
if(a*b<0):
a,b=abs(a),abs(b)
g = gcd(a,b)
a//=g
b//=g
num_of_group[(-b,a)] += 1
num_of_group[(b,a)] += 0
else:
a,b=abs(a),abs(b)
g = gcd(a,b)
a//=g
b//=g
num_of_group[(a,b)] += 1
# print(num_of_group.items())
if(both_zero_cnt==N):
print(N)
return
##solve
ans = ModInt(1)
# two_pow = [1]
# for i in range(N):
# two_pow.append((2*two_pow[-1])%mod)
# print(two_pow,"#######")
for (a,b),cnt1 in num_of_group.items():
if(a<0):
continue
tmp = ModInt(2)**cnt1
if (-a,b) in num_of_group:
cnt2 = num_of_group[-a,b]
tmp += ModInt(2)**cnt2
tmp-=1
if(tmp):
ans *= tmp
ans -= 1 ##全部選ばない
ans += both_zero_cnt
print(ans)
if __name__ == '__main__':
main()
|
import math
def caracal_vs_monster():
"""
2**0 個 5
/ \
2**1 個 2.5 2.5
/ \ / \
2**2 個 1.25 1.25 1.25 1.25
/ \ / \ / \ / \
2**3 個 0.625 0.625 ...
"""
# 入力
H = int(input())
# H / 2 の何回目で1になるか
count = int(math.log2(H))
# 攻撃回数
attack_count = 0
for i in range(count+1):
attack_count += 2 ** i
return attack_count
result = caracal_vs_monster()
print(result)
| 0 | null | 50,376,469,197,380 | 146 | 228 |
import math
r = float(input())
print('{0:.6f} {1:.6f}'.format(r * r * math.pi, (r + r) * math.pi))
|
import math
r=float(input())
string=str(r**2*math.pi)+" "+str(2*math.pi*r)
print(string)
| 1 | 636,811,849,560 | null | 46 | 46 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
X = [list(map(int, input().split())) for _ in range(Q)]
ctr = Counter(A)
ans = sum(A)
for b, c in X:
n = ctr[b]
ans += -b * n + c * n
ctr[b] = 0
ctr[c] += n
print(ans)
|
n = int(input())
if n%2 ==1:
print(0)
exit()
cnt = 0
i = 1
if n%2 == 0:
while n//(2*(5**i)) > 0:
cnt += n//(2*(5**i))
i +=1
print(cnt)
| 0 | null | 64,423,200,562,732 | 122 | 258 |
n=int(raw_input())
left=0
right=0
for i in range(n):
x,y=raw_input().strip().split()
if x==y:
left+=1
right+=1
elif x<y:
right+=3
elif x>y:
left+=3
print left,right
|
n = int(input())
x = 0
y = 0
for _ in range(n):
a,b=input().split()
if a < b:
y+=3
elif a ==b:
x+=1
y+=1
else:
x+=3
print (x,y)
| 1 | 1,984,874,031,580 | null | 67 | 67 |
a = []
while True:
d = list(map(int, input().split()))
if d == [0,0]:
break
d.sort()
a.append(d)
for x in a:
print('{} {}'.format(x[0],x[1]))
|
'''
ITP-1_3-C
2 ????????°?????????
???????????´??° x, y ?????????????????????????????????????°?????????????????????????????????°?????????????????????????????????
?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
???Input
??\???????????°????????????????????????????§?????????????????????????????????????????????????????????§??????????????????????????´??° x, y ?????????
?????????????§?????????????????????????
???Output
??????????????????????????¨??????x ??¨ y ????°????????????????????????????????????????????????????????????????x ??¨ y ????????????????????????????????\??????????????????
'''
# import
import sys
# input???????????????
for inputData in sys.stdin:
inputData = inputData.split(" ")
inputData01, inputData02 = int(inputData[0]), int(inputData[1])
# 0?????´??? ????????????
if inputData01 == 0:
if inputData02 == 0:
break
if inputData01 > inputData02:
outputData01 = inputData02
outputData02 = inputData01
else:
outputData01 = inputData01
outputData02 = inputData02
# ????????????
print((outputData01), (outputData02))
| 1 | 531,075,735,480 | null | 43 | 43 |
# import time
# p0 = time.time()
N = int(input())
A = list(map(int,input().split()))
# print(A)
A = [[A[i],i] for i in range(N)]
A.sort(reverse=True)
# print("A :",A)
dp = [[0]*(N+1) for _ in range(N+1)]
# print(dp)
#dp[x][y] : x人は Ai*(i-pi),y人は Ai*(pi-i)
# piは 0,1,2... piはN-1,N-2,N-3,,
# p1 = time.time()-p0
dp[0][0] = 0
# y = 0
for x in range(1,N+1):
dp[x][0] = dp[x-1][0]+A[x-1][0]*(A[x-1][1]-x+1)
# print(x,dp)
# x = 0
for y in range(1,N+1):
dp[0][y] = dp[0][y-1]+A[y-1][0]*(N-y - A[y-1][1])
# print(x,dp)
# p2 = time.time()-p0
for x in range(1,N):
for y in range(1,N+1-x):
A0 = A[x+y-1][0]
A1 = A[x+y-1][1]
dp[x][y] = max(dp[x-1][y] + A0*(A1+1 - x), dp[x][y-1] + A0*(N-y - A1))
# print(dp)
# p3 = time.time()-p0
c = 0
for i in range(N):
if c < dp[i][N-i]:
c = dp[i][N-i]
print(c)
# print(p1,p2,p3)
|
import statistics
N = int(input())
A = []
B = []
for _ in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if N % 2 == 1:
med_min = A[N // 2]
med_max = B[N // 2]
print(med_max - med_min + 1)
else:
med_min_db = A[N // 2] + A[N // 2 - 1]
med_max_db = B[N // 2] + B[N // 2 - 1]
print(med_max_db - med_min_db + 1)
| 0 | null | 25,499,994,283,920 | 171 | 137 |
n = int(input())
s = input().split()
q = int(input())
t = input().split()
c = 0
for i in t:
for j in s:
if i == j:
c += 1
break
print(c)
|
n = int(input())
a = set(input().split())
m = int(input())
b = set(input().split())
print(len(a&b))
| 1 | 66,370,035,104 | null | 22 | 22 |
a = int(input())
print(2*(22/7)*a)
|
r = int(input())
s = r * 2 * 3.14
print(s)
| 1 | 31,345,792,028,938 | null | 167 | 167 |
N = int(input())
S = ["*"]*(N+1)
S[1:] = list(input())
Q = int(input())
q1,q2,q3 = [0]*Q,[0]*Q,[0]*Q
for i in range(Q):
tmp = input().split()
q1[i],q2[i] = map(int,tmp[:2])
if q1[i] == 2:
q3[i] = int(tmp[2])
else:
q3[i] = tmp[2]
class BIT:
def __init__(self, n, init_list):
self.num = n + 1
self.tree = [0] * self.num
for i, e in enumerate(init_list):
self.update(i, e)
#a_kにxを加算
def update(self, k, x):
k = k + 1
while k < self.num:
self.tree[k] += x
k += (k & (-k))
return
def query1(self, r):
ret = 0
while r > 0:
ret += self.tree[r]
r -= r & (-r)
return ret
#通常のスライスと同じ。lは含み、rは含まない
def query2(self, l, r):
return self.query1(r) - self.query1(l)
s_pos = [BIT(N+1,[0]*(N+1)) for _ in range(26)]
for i in range(1,N+1):
s_pos[ord(S[i]) - ord("a")].update(i,1)
alphabets = [chr(ord("a") + i) for i in range(26)]
for i in range(Q):
if q1[i] == 1:
s_pos[ord(S[q2[i]]) - ord("a")].update(q2[i],-1)
S[q2[i]] = q3[i]
s_pos[ord(q3[i]) - ord("a")].update(q2[i],1)
else:
ans = 0
for c in alphabets:
if s_pos[ord(c) - ord("a")].query2(q2[i],q3[i]+1) > 0:
ans += 1
print(ans)
|
n = int(input())
s = input()
q = int(input())
class SegmentTree:
def __init__(self, a, func=max, one=-10 ** 18):
self.logn = (len(a) - 1).bit_length()
self.n = 1 << self.logn
self.func = func
self.one = one
self.b = [self.one] * (2 * self.n - 1)
for i, j in enumerate(a):
self.b[i + self.n - 1] = j
for i in reversed(range(self.n - 1)):
self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])
self.ll = []
self.rr = []
i = self.n
for _ in range(self.logn+1):
for j in range(0, self.n, i):
self.ll.append(j)
self.rr.append(j + i)
i //= 2
def get_item(self, i):
return self.b[i + self.n - 1]
def update(self, index, x):
i = index + self.n - 1
self.b[i] = x
while i != 0:
i = (i - 1) // 2
self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])
def update_func(self, index, x):
i = index + self.n - 1
self.b[i] = self.func(self.b[i], x)
while i != 0:
i = (i - 1) // 2
self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])
def get_segment(self, l, r, i=0):
ll = self.ll[i]
rr = self.rr[i]
if l <= ll and rr <= r:
return self.b[i]
elif rr <= l or r <= ll:
return self.one
else:
return self.func(self.get_segment(l, r, i * 2 + 1),
self.get_segment(l, r, i * 2 + 2))
def get_int(s):
abc = "abcdefghijklmnopqrstuvwxyz"
return 1 << abc.index(s)
seg = SegmentTree([get_int(i) for i in s], int.__or__, 0)
for _ in range(q):
q, i, j = input().split()
if q == "1":
seg.update(int(i) - 1, get_int(j))
else:
aa = seg.get_segment(int(i) - 1, int(j))
ans = 0
for i in range(26):
if (aa >> i) & 1 == 1:
ans += 1
print(ans)
| 1 | 62,125,573,556,380 | null | 210 | 210 |
from math import atan, degrees
def is_divisible(a):
return 'Yes' if any(int(a/x) == a/x and a/x <= 9 for x in range(1,10)) and a <= 81 else 'No'
print(is_divisible(int(input())))
|
import math;
in_put = input("");
cube=math.pow(float(in_put),3);
print(int(cube));
| 0 | null | 79,673,810,565,566 | 287 | 35 |
N=int(input())
s=[]
t=[]
for i in range(N):
x,y=input().split()
s.append(x)
t.append(int(y))
X=input()
begin_idx=s.index(X)+1
print(sum(t[begin_idx:]))
|
N = int(input())
ST = [list(input().split()) for _ in [0]*N]
X = input()
ans = 0
for i,st in enumerate(ST):
s,t = st
if X==s:
break
for s,t in ST[i+1:]:
ans += int(t)
print(ans)
| 1 | 97,118,466,758,148 | null | 243 | 243 |
N,M=map(int, input().split())
from collections import defaultdict
A=list(map(int, input().split()))
B=[]
import math
def lcm(x, y):
return (x * y) // math.gcd(x, y)
# a 偶数
twos=0
D=defaultdict(int)
for i in range(N):
B.append(A[i]//2)
a=A[i]
now=0
while a%2==0:
a//=2
now+=1
D[now]+=1
twos=max(twos, now)
if len(set(D.values()))!=1:
print(0)
exit()
now=1
for i in range(N):
now=lcm(now, B[i])
# 1.5 * 3 2*5
from math import ceil
ans=M//(now*pow(2,twos))+1
#res=now+now%(2**twos)
ans=ceil(M//now/2)
#if M-res>0:
# ans-=int((M-res)//now/(2**twos))
print(ans)
|
N = int(input())
a = list(map(int, input().split()))
x = 0
for r in a:
x ^= r
a = [str(x^r) for r in a]
a = ' '.join(a)
print(a)
| 0 | null | 57,203,143,303,162 | 247 | 123 |
N=int(input())
List = list(map(int, input().split()))
Row = int(input())
QList = []
for i in range (Row):
QList.append(list(map(int, input().split())))
dictA ={}
res = 0
for i in range (N):
dictA.setdefault(List[i],0)
dictA[List[i]] += 1
res += List[i]
num = 0
for i in range(Row):
if QList[i][0] not in dictA:
pass
else:
num = dictA[QList[i][0]]
res = res - dictA[QList[i][0]] * QList[i][0]
dictA[QList[i][0]] = 0
dictA.setdefault(QList[i][1],0)
dictA[QList[i][1]] += num
res += QList[i][1] * num
print(res)
|
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b,c=[],[]
for _ in range(q):
bi,ci=map(int,input().split())
b.append(bi)
c.append(ci)
number=[0 for i in range(10**5+1)]
for i in range(n):
number[a[i]]+=1
s=sum(a)
for i in range(q):
s+=(c[i]-b[i])*number[b[i]]
number[c[i]]+=number[b[i]]
number[b[i]]=0
print(s)
| 1 | 12,164,969,738,972 | null | 122 | 122 |
def main():
n = int(input())
dss = [list(map(int, input().split())) for _ in range(n)]
ans = "No"
Count = 0
for ds in dss:
if ds[0] == ds[1]:
Count += 1
else:
Count = 0
if Count == 3:
ans = "Yes"
print(ans)
if __name__ == "__main__":
main()
|
def resolve():
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
pass
else:
if N != 0:
ans += N*(N-1)/2
if M != 0:
ans += M*(M-1)/2
print(int(ans))
resolve()
| 0 | null | 23,994,537,408,618 | 72 | 189 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.