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
|
---|---|---|---|---|---|---|
S=list(input())
T=S.copy()
T.reverse()
count=0
for i in range(len(S)):
if S[i]!=T[i]:count+=1
print(count//2) | d, t, s = map(int, input().split())
if s * t >= d:
print("Yes")
else:
print("No") | 0 | null | 62,164,637,488,028 | 261 | 81 |
#import sys
#input = sys.stdin.buffer.readline
#input = sys.stdin.readline
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
def main():
n=int(input())
s=[]
t=[]
for i in range(n):
a,b=input().split()
s.append(a)
t.append(int(b))
x=input()
for i in range(n):
if x==s[i]:
ans=sum(t[i+1:])
print(ans)
exit(0)
if __name__ == "__main__":
main()
| X = int(input())
x1 = X//500
x2 = (X%500)//5
print(x1*1000+x2*5) | 0 | null | 69,792,175,522,190 | 243 | 185 |
n = int(input())
s = "abcdefghij"
def func(a):
if len(a) == n:
print(a)
else:
for i in range(len(set(a))+1):
func(a+s[i])
func("a") | N = int(input())
# 最後の数字+1以下じゃないとだめ
# abc -> 次はa,b,c,d
dic = ["a","b","c","d","e","f","g","h","i","j"]
strs = ["a"]
cnt = 1
while cnt < N:
tmps = []
for s in strs:
for i,d in enumerate(dic[::-1]):
if d in s:
ind = len(dic)-i-1
break
# print(s,ind,dic[i])
for i in range(ind+2):
tmps.append(s+dic[i])
cnt += 1
strs = tmps[:]
for s in strs:
print(s) | 1 | 52,502,239,520,960 | null | 198 | 198 |
A = input()
B = input()
KAI = "123"
KAI1 = KAI.replace(A,"")
KAI2 = KAI1.replace(B,"")
print(KAI2) | # C - Go to School TLE
N = int(input())
A = list(map(int, input().split()))
attend = [i for i in range(1,N+1)]
for j in range(1,N+1):
attend[A[j-1] - 1] = j
print(*attend) | 0 | null | 145,852,622,894,876 | 254 | 299 |
N = int(input())
alist = list(map(int, input().split()))
cnt = 1
ans = 0
for a in alist:
if a != cnt:
ans += 1
else:
cnt += 1
if ans==N:
print(-1)
else:
print(ans)
|
from sys import exit
def main():
N = int(input())
a = list(map(int,input().split()))
index = -1
num = 1
for i in range(index+1, N):
if a[i] != num:
continue
elif a[i] == num:
index = i
num += 1
if index != -1:
print(N-(num-1))
exit()
#indexに更新がなければ-1のまま
print(index)
main() | 1 | 114,908,762,347,342 | null | 257 | 257 |
import sys
official_house = {}
for b in range(1, 5):
for f in range(1, 4):
for r in range(1, 11):
official_house[(b, f, r)] = 0
n = int(sys.stdin.readline())
for line in sys.stdin:
(b, f, r, v) = [int(i) for i in line.split()]
official_house[(b, f, r)] += v
for b in range(1, 5):
if b != 1:
print("####################")
for f in range(1, 4):
for r in range(1, 11):
print(" %d" % official_house[(b, f, r)], end="")
print() | # (c) midandfeed
q = []
for i in range(4):
b = []
for j in range(3):
a = [0 for x in range(10)]
b.append(a)
q.append(b)
t = int(input())
for _ in range(t):
b, f, r, v = [int(x) for x in input().split()]
q[b-1][f-1][r-1] += v
a = 0
for x in q:
a += 1
for y in x:
for z in range(len(y)):
print(" {}".format(y[z]), end='')
if (z==(len(y))-1):
print()
if (a!=4):
print("#"*20) | 1 | 1,086,301,237,412 | null | 55 | 55 |
n = int(input())
d = {}
ans = []
for i in range(n):
order = list(map(str, input().split()))
if order[0] == 'insert':
d[order[1]] = i
else:
if d.__contains__(order[1]):
ans.append('yes')
else:
ans.append('no')
print(*ans, sep='\n')
| n = int(input())
s = input()
sr = []
sg = []
sb = [0] * n
kcnt = 0
for i in range(n):
if s[i] == 'R':
sr.append(i)
elif s[i] == 'G':
sg.append(i)
else:
sb[i] = 1
kcnt += 1
ans = 0
for i in sr:
for j in sg:
nki = j*2 - i
nkj = i*2 - j
nkk = (j+i)
ans += kcnt
if 0<= nki < n and sb[nki] == 1:
ans -= 1
if 0<= nkj < n and sb[nkj] == 1:
ans -= 1
if nkk%2 == 0 and 0<= (nkk//2) < n and sb[nkk//2] == 1:
ans -= 1
print(ans) | 0 | null | 18,192,508,759,492 | 23 | 175 |
import sys
a = ""
l = []
for input in sys.stdin:
a += input
l = a.split()
b = int(l[0])
l = l[1:]
for i in range(0,b):
key = int(l[i])
j = i - 1
while(j >= 0 and int(l[j]) > key):
l[j+1] = l[j]
j = j - 1
l[j+1] = key
if(b > 0):
for data in l:
print int(data),
print
b = b-1
| w,h,x,y,r = map(int,input().split())
if (x + r)> w or (y + r) > h or x <= 0 or y <=0 or (x-r)<0 or (y-r)<0 :
print('No')
else:
print('Yes')
| 0 | null | 221,588,373,288 | 10 | 41 |
i = int(input())
print('Yes' if i >= 30 else 'No') | X = int(input())
if X < 30:
print('No')
else:
print('Yes') | 1 | 5,747,966,801,060 | null | 95 | 95 |
ss=str(input())
a=int(ss.count("R"))
if ss=="RSR":
a=1
print(a)
| S = input()
a = S[0] == 'S'
b = S[1] == 'S'
c = S[2] == 'S'
if (a and b and c ):
print(0)
elif ( b or(a and c)):
print(1)
elif(a or c):
print(2)
else:
print(3) | 1 | 4,850,053,217,860 | null | 90 | 90 |
a = [input().split() for l in range(3)]
n = int(input())
b = list(input() for i in range(n))
c = [[0] * 3 for i in range(3)]
for i in range(n):
for j in range(3):
for k in range(3):
if b[i] == a[j][k]:
c[j][k] = 1
if (c[0][0] == 1 and c[0][1] == 1 and c[0][2] == 1) or(c[1][0] == 1 and c[1][1] == 1 and c[1][2] == 1) or(c[2][0] == 1 and c[2][1] == 1 and c[2][2] == 1) or(c[0][0] == 1 and c[1][0] == 1 and c[2][0] == 1) or(c[0][1] == 1 and c[1][1] == 1 and c[2][1] == 1) or(c[0][2] == 1 and c[1][2] == 1 and c[2][2] == 1) or(c[0][0] == 1 and c[1][1] == 1 and c[2][2] == 1) or (c[0][2] == 1 and c[1][1] == 1 and c[2][0] == 1):
print("Yes")
else:
print("No")
| a1=input("").split(" ")
a2=input("").split(" ")
a3=input("").split(" ")
lista=[]
listmp=[]
for k in range(3):
listmp+=[int(a1[k])]
lista+=[listmp]
listmp=[]
for k in range(3):
listmp+=[int(a2[k])]
lista+=[listmp]
listmp=[]
for k in range(3):
listmp+=[int(a3[k])]
lista+=[listmp]
n=int(input(""))
listn=[]
for i in range(n):
t=int(input(""))
listn+=[t]
for i in range(3):
for k in range(3):
if(lista[i][k] in listn):
lista[i][k]=0
p=0
for i in range(3):
s=0
for k in range(3):
s+=lista[i][k]
if(s==0):
p=1
for i in range(3):
s=0
for k in range(3):
s+=lista[k][i]
if(s==0):
p=1
s=0
for i in range(3):
s+=lista[i][i]
if(s==0):
p=1
s=0
for i in range(3):
s+=lista[i][2-i]
if(s==0):
p=1
if(p==1):
print("Yes")
else:
print("No")
| 1 | 59,845,465,945,890 | null | 207 | 207 |
import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def prepare_simple(n, mod=pow(10, 9) + 7):
# n! の計算
f = 1
for m in range(1, n + 1):
f *= m
f %= mod
fn = f
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return fn, invs
def prepare(n, mod=pow(10, 9) + 7):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= mod
factorials.append(f)
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return factorials, invs
# 実装を行う関数
def resolve(test_def_name=""):
x, y = map(int, input().split())
all_move_count = (x + y) // 3
x_move_count = all_move_count
y_move_count = 0
x_now = all_move_count * 2
y_now = all_move_count
canMake= False
for i in range(all_move_count+1):
if x_now == x and y_now == y:
canMake = True
break
x_move_count -= 1
y_move_count += 1
x_now -= 1
y_now += 1
if not canMake:
print(0)
return
fns, invs = prepare(all_move_count)
ans = (fns[all_move_count] * invs[x_move_count] * invs[all_move_count - x_move_count]) % (pow(10, 9) + 7)
print(ans)
# fn, invs = prepareSimple(10)
# ans = (fn * invs[3] * invs[10 - 3]) % (pow(10, 9) + 7)
# print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 3"""
output = """2"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """2 2"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """999999 999999"""
output = """151840682"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| n = int(input())
s = 0
a = 1
b = 1
while a*b < n:
while a*b < n and b <= a:
if a == b:
s += 1
else:
s += 2
b += 1
a += 1
b = 1
print(s)
| 0 | null | 76,335,873,181,250 | 281 | 73 |
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
ans = 1
for a in range(1, N-1):
num_b = (N-1) // a
ans += num_b
print(ans)
main()
| def resolve():
N = int(input())
count = 0
for A in range(1, N):
count += ((N-1)//A)
print(count)
if __name__ == "__main__":
resolve() | 1 | 2,599,785,638,554 | null | 73 | 73 |
n = int(input())
a = list(map(int, input().split()))
left = a[0]
right = a[-1]
center = 0
sum_a = sum(a)
flg = False
for i in range(1, n-1):
if left + a[i] > sum_a/2 and flg is False:
flg = True
center = a[i]
right -= a[i]
elif left + a[i] == sum_a / 2:
print(0)
exit()
if flg is False:
left += a[i]
else:
right += a[i]
print(abs(min(left+center-right, right+center-left)))
| N,M=map(int, input().split())
S=input()
now=S[N-1]
dp=[float("INF")]*(N+1)
dp[N]=0
nowmin=0
right=N
for left in range(N-1,-1,-1):
while right-left>M or S[right]=="1":
right-=1
nowmin=dp[right]
if right<=left:
print(-1)
exit()
if S[left]=="1":
continue
else:
dp[left]=1+nowmin
#print(dp)
#print(dp[0])
now=dp[0]
nowi=0
"""
if now==float("INF"):
print(-1)
exit()
"""
for i in range(1,N+1):
if now>dp[i]:
print(i-nowi, end=" ")
now=dp[i]
nowi=i
| 0 | null | 140,605,379,685,232 | 276 | 274 |
def is_prime(num):
""" ??°???????´???°????????????????????????
http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_C
:param num: ?????????????????°???
:return: num????´???°??§????????°True
"""
if num == 2:
return True
if num < 2 or num % 2 == 0:
return False
i = 3
while i <= num**0.5:
if num % i == 0:
return False
i += 2
return True
if __name__ == '__main__':
# ??????????????\???
data = []
num = int(input())
for i in range(num):
data.append(int(input()))
# data = [6, 2, 3, 4, 5, 6, 7]
# ?´???°????????°?????????
num_of_prime = 0
for d in data:
if is_prime(d):
num_of_prime += 1
# ???????????????
print('{0}'.format(num_of_prime)) | def IsPrime(x):
if x == 1:
return False
p = int(pow(x, 0.5)) + 1
i = 2
while i <= p and i < x:
if x % i == 0:
return False
else:
i += 1
return True
n = int(input())
c = 0
i = 0
while i < n:
x = int(input())
if IsPrime(x) == True:
c += 1
i += 1
print(c)
| 1 | 9,873,171,542 | null | 12 | 12 |
# -*- coding: utf-8 -*-
## Library
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
## input
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split())
# P = [list(map(int,input().split())) for i in range(M)]
# S = []
# for _ in range(N):
# S.append(list(input()))
N=int(input())
print(N+N**2+N**3) | inp = input()
out = int(inp) + int(inp)**2 + int(inp)**3
print(out) | 1 | 10,165,401,861,008 | null | 115 | 115 |
list_len = int(input().rstrip())
num_list = list(map(int, input().rstrip().split()))
for i in range(list_len):
v = num_list[i]
j = i - 1
while j >= 0 and num_list[j] > v:
num_list[j + 1] = num_list[j]
j -= 1
num_list[j+1] = v
output_str = ' '.join(map(str, num_list))
print(output_str) | n = int(input())
S = input()
ans = 0
def ok(i):
pin = '{:0=3}'.format(i)
j = 0
for s in S:
if s == pin[j]:
j += 1
if j == 3:
return True
else:
return False
for i in range(1000):
ans += ok(i)
print(ans) | 0 | null | 64,219,361,667,812 | 10 | 267 |
n, m = map(int,input().split())
a = list(map(int,input().split()))
if n - sum(a) >= 0:
print(n - sum(a))
else:
print('-1') | # 問題文
# 高橋君の夏休みはN日間です。
# 夏休みの宿題が M個出されており、i番目の宿題をやるにはAi日間かかります。
# 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
# 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか?
# ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。
# n(夏休みの日数),m(宿題の数):標準入力
# リストの中のA(宿題日):リストを作成し、標準入力
n, m = map(int, input().split())
A = list(map(int, input(). split()))
# 最大で n −合計(A1+. . .+AM)日間遊ぶことができる
if n < sum(A): # 夏休みの日数より宿題日が多い場合:宿題をやる日数が足りない→終わらせることができない
print(-1)
else:
print(n-sum(A)) # その他→宿題は終わる→夏休みの日数-宿題日
# NameError: name 'N' is not defined | 1 | 31,829,280,755,424 | null | 168 | 168 |
def main():
N = int(input())
NN = [[0]*10 for _ in range(11)]
for i in range(11,100):
As = str(i)[0]
Ae = str(i)[-1]
cnt = 0
for j in range(1,N+1):
if str(j)[-1]== As and str(j)[0] == Ae:
cnt +=1
NN[int(As)][int(Ae)] = cnt
ans = 0
for i in range(1,N+1):
ans += NN[int(str(i)[0])][int(str(i)[-1])]
print(ans)
if __name__ == '__main__':
main()
| N = int(input())
A = list(map(int, input().split()))
print(' '.join(map(str, A)))
for i in range(1, N):
v = A[i]
j = i - 1
while j >=0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(' '.join(map(str, A)))
| 0 | null | 43,009,923,976,922 | 234 | 10 |
def prime_factorize(n):
'''
素因数分解のリストを返す。n == 1のとき[]になるので注意。
:param n:int
素因数分解する自然数
:return: list
素因数分解した結果。
例
n : 10
primes : [[2, 1], [5, 1]]
'''
primes = []
for i in range(2, int(n ** (1 / 2)) + 1):
if n % i != 0:
continue
num = 0
while n % i == 0:
num += 1
n //= i
primes.append([i, num])
if n != 1:
primes.append([n, 1])
return primes
N = int(input())
prime_list = prime_factorize(N)
ans = 0
for _, e in prime_list:
now = 1
work = e
while work >= now:
work -= now
now += 1
ans += 1
print(ans) | data = input().split()
print(int(data[0])*int(data[1])) | 0 | null | 16,315,962,409,880 | 136 | 133 |
n,k = map(int, input().split())
ans=n % k
if abs(ans-k)<ans:
print(abs(ans-k))
else:
print(ans)
| # -*- coding:utf-8 -*-
def main():
List=[]
for i in range(10):
a=int(input())
List.append(a)
List.sort(reverse=True)
print(List[0])
print(List[1])
print(List[2])
if __name__ == '__main__':
main() | 0 | null | 19,770,617,571,838 | 180 | 2 |
from itertools import accumulate
from collections import defaultdict, deque
def resolve():
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = accumulate([a % K for a in A])
A = [0] + list(A)
# 区間 [i,j] の和(累積和): dj+1−di
# 区間 [i,j] の要素の数(0_indの為 +1): j−i+1
# 上記を一般化: dr−dl=r−l となるものの個数を求める
# r−l<K の時、mod K において式変形が成り立つ, dr−r=dl−l
# rを固定し辞書で管理すれば、dl−lと同じ値なので個数を求められる。
cnt = defaultdict(int)
q = deque()
ans = 0
for r in range(N + 1):
t = (A[r] - r) % K
ans += cnt[t]
cnt[t] += 1
q.append(t)
if len(q) == K:
left = q.popleft()
cnt[left] -= 1
print(ans)
if __name__ == "__main__":
resolve()
| import collections
def primes(n): #試し割り法で各素因数とその指数を求める
cnt=collections.defaultdict(int)
for i in range(2,int(n**0.5)+1):
if n%i==0:
while n%i==0:
cnt[i]+=1
n//=i
if n!=1:
cnt[n]+=1
return cnt
n=int(input())
cnt=primes(n)
ans=0
for key in cnt.keys():
val=cnt[key]
for i in range(100): #各素因数の指数について、k(k+1)//2<=(指数)を満たす最大のkを求める
if (i*(i+1))//2>val:
ans+=i-1
break
print(ans) | 0 | null | 77,007,279,802,402 | 273 | 136 |
X = int(input())
if X >= 2100:
print(1)
exit()
for a in range(21):
for b in range(21-a):
for c in range(21-a-b):
for d in range(21-a-b-c):
for e in range(21-a-b-c-d):
for f in range(21-a-b-c-d-e):
if 100*a +101*b +102*c +103*d +104*e + 105*f == X:
print(1)
exit()
print(0) | from sys import exit
from itertools import accumulate,chain
n,*s=open(0).read().split()
t=[2*i.count("(")-len(i) for i in s]
if sum(t)!=0:
print("No");exit()
st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),t_] for s_,t_ in zip(s,t)]
now=0
for c in chain(sorted([x for x in st if x[1]>=0])[::-1],sorted([x for x in st if x[1]<0],key=lambda z:z[1]-z[0])[::-1]):
if now+c[0]<0:
print("No");exit()
now+=c[1]
print("Yes") | 0 | null | 75,075,304,322,276 | 266 | 152 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(15000)
n = int(sys.stdin.readline())
ret = []
inp = sys.stdin.readlines()
G = [None]*(n+1)
depths = [-1]*(n+1)
for i in range(1,n+1):
v = list(map(int,inp[i-1].split()))
G[v[0]] = list(map(int,v[2:]))
#print(G)
nodes = [1]
depth = 0
while nodes:
new = []
for i in nodes:
if depths[i] == -1:
depths[i] = depth
new += G[i]
#print(i,nodes,depth,depths)
depth += 1
nodes = new
for i in range(1,n+1):
print(i,depths[i])
| INFTY = 10 ** 10
import queue
def bfs(s):
q = queue.Queue()
q.put(s)
d = [INFTY] * n
d[s] = 0
while not q.empty():
u = q.get()
for v in range(n):
if M[u][v] == 0:
continue
if d[v] != INFTY:
continue
d[v] = d[u] + 1
q.put(v)
for i in range(n):
if d[i] == INFTY:
print(i+1, -1)
else:
print(i+1, d[i])
n = int(input())
M = [[0] * n for _ in range(n)]
for i in range(n):
nums = list(map(int, input().split()))
u = nums[0] - 1
k = nums[1]
for j in range(k):
v = nums[j+2] - 1
M[u][v] = 1
bfs(0)
| 1 | 4,284,267,654 | null | 9 | 9 |
n = int(input())
ans = 100000
# ans += (n*(100000*0.05))
for i in range(n):
ans *= 1.05
if ans % 1000 > 0:
ans = ans // 1000 * 1000 + 1000
print(int(ans))
| N = input()
money = 100000
for i in range(N):
money = int(money *1.05)
if money % 1000 != 0:
money = (money // 1000 + 1) * 1000
print money | 1 | 1,017,549,088 | null | 6 | 6 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1*(A1-B1)
d2 = T2*(A2-B2)
if d1>d2:
d1 *= -1
d2 *= -1
if (d1>0 and d1+d2>0) or (d1<0 and d1+d2<0):
print(0)
elif d1+d2==0:
print("infinity")
else:
v = (abs(d1)//(d1+d2))
ans = v*2
pos = d1+v*(d1+d2)
if pos<0 and pos+d2>=0:
ans += 1
print(ans) | T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
len1 = T1 * A1 + T2 * A2
len2 = T1 * B1 + T2 * B2
if len1 == len2:
print("infinity")
quit()
ans = 0
subs = 0
sub1 = T1 * (A1 - B1)
sub2 = T2 * (A2 - B2)
if sub1 > 0:
if len1 - len2 > 0:
ans = 0
else:
S = (-1 * sub1) // (sub1 + sub2)
T = (-1 * sub1) % (sub1 + sub2)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
else:
if len1 - len2 < 0:
ans = 0
else:
S = (-1 * sub1) // (sub1 + sub2)
T = (-1 * sub1) % (sub1 + sub2)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
print(ans) | 1 | 132,010,960,599,404 | null | 269 | 269 |
cards = [[0 for i in range(13)] for j in range(4)]
s2n = {'S': 0, 'H': 1, 'C': 2, 'D': 3}
n2s = 'SHCD'
n = int(input())
for i in range(n):
card = list(input().split())
card[1] = int(card[1])
cards[s2n[card[0]]][card[1]-1] = 1
for i in range(4):
for j in range(13):
if not(cards[i][j]):
print(n2s[i], j+1) | n = int(input())
list_s = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_h = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_c = [1,2,3,4,5,6,7,8,9,10,11,12,13]
list_d = [1,2,3,4,5,6,7,8,9,10,11,12,13]
for i in range(n):
zugara, num = input().split()
#print(zugara)
#print(num)
#print(list_s)
if zugara == 'S':
list_s.remove(int(num))
elif zugara == 'H':
list_h.remove(int(num))
elif zugara == 'C':
list_c.remove(int(num))
else:
list_d.remove(int(num))
for i in list_s:
print('S', i)
for i in list_h:
print('H', i)
for i in list_c:
print('C', i)
for i in list_d:
print('D', i)
| 1 | 1,019,212,795,800 | null | 54 | 54 |
def dice_expectation(p):
return ((1 + p) * p / 2) * (1/p)
n, k = map(int, input().split())
pp = [0] * (n+1)
for i, p in enumerate(map(int, input().split())):
pp[i+1] = pp[i] + dice_expectation(p)
max = -1
for i in range(k, n+1, 1):
max = pp[i] - pp[i-k] if pp[i] - pp[i-k] > max else max
print(max)
| # -*- coding: utf-8 -*-
## Library
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
## input
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split())
# P = [list(map(int,input().split())) for i in range(M)]
# S = []
# for _ in range(N):
# S.append(list(input()))
N,K=map(int, input().split())
P = list(map(int, input().split()))
S = []
for i in range(N):
S.append((P[i]+1)/2)
tmp = sum(S[:K])
ans = tmp
for i in range(N-K):
tmp = tmp - S[i] + S[i+K]
ans = max(ans, tmp)
print(ans)
| 1 | 75,089,973,604,220 | null | 223 | 223 |
n,*A=map(int,open(0).read().split());m=1000
for x,y in zip(A,A[1:]):
if x<y:m=m//x*y+m%x
print(m) | import math
X = int(input())
ans = 0
money = 100 #初期金額
while money < X:
money += money//100
ans += 1
print(ans)
| 0 | null | 17,322,622,613,440 | 103 | 159 |
s_l = list(input())
t_l = list(input())
count_difference = 0
for s, t in zip(s_l, t_l):
if s != t:
count_difference += 1
print(count_difference)
| def main():
S = input()
T = input()
cnt = 0
for a, b in zip(S, T):
cnt += a != b
print(cnt)
if __name__ == '__main__':
main()
| 1 | 10,491,914,608,912 | null | 116 | 116 |
import sys
s = input().lower()
t = sys.stdin.read().lower().split()
print(t.count(s))
| W = raw_input()
S = []
while True:
tmp = map(str, raw_input().split())
if tmp[0] == "END_OF_TEXT":
break
else:
S.append(tmp)
cnt = 0
for i in range(len(S)):
for j in range(len(S[i])):
if W == S[i][j].lower():
cnt += 1
print cnt | 1 | 1,806,781,595,332 | null | 65 | 65 |
from collections import deque
import sys
input = sys.stdin.readline
def main():
N,X,Y = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(N):
if i == 0:
edge[i].append(i+1)
elif i == N-1:
edge[i].append(i-1)
else:
edge[i].append(i-1)
edge[i].append(i+1)
edge[X-1].append(Y-1)
edge[Y-1].append(X-1)
ans = [0]*(N-1)
for i in range(N):
visited = [0]*N
dist = [0]*N
q = deque([i])#i番目のノードを根とする探索
visited[i] = 1
while q:
now = q.popleft()
for connection in edge[now]:
if visited[connection]:
dist[connection] = min(dist[connection],dist[now]+1)
else:
visited[connection] = 1
dist[connection] = dist[now] + 1
q.append(connection)
for d in dist:
if d == 0:
continue
ans[d-1] += 1
ans = list(map(lambda x: x//2,ans))
print(*ans,sep="\n")
if __name__ == '__main__':
main() | a,b,c=map(int,input().split())
K=int(input())
isCheck = None
for i in range(K+1):
for j in range(K+1):
for k in range(K+1):
x = a*2**(i)
y = b*2**(j)
z = c*2**(k)
if i+j+k <= K and x < y and y < z:
isCheck = True
if isCheck:
print("Yes")
else:
print("No")
| 0 | null | 25,472,430,875,582 | 187 | 101 |
#!/usr/bin/env python
n = int(input())
if n%2 == 1:
print(0)
exit()
mp = tmp = 0
while True:
if 5**tmp > n:
break
mp = tmp
tmp += 1
ans = 0
for i in range(1, mp+1):
ans += n//(2*(5**i))
print(ans)
| n=int(input())
if n%2!=0:
print(0)
exit(0)
n//=10
def Base_10_to_n(X, n):
X_dumy = X
out = ''
while X_dumy>0:
out = str(X_dumy%n)+out
X_dumy = X_dumy//n
return out
n=Base_10_to_n(n,5)
n=reversed(list(n))
tmp=1
ans=0
for i in n:
ans+=int(i)*tmp
tmp=tmp*5+1
print(ans)
| 1 | 116,263,081,975,712 | null | 258 | 258 |
import sys
for i in sys.stdin.readlines()[:-1]:
h,w = map(int,i.strip().split())
for i in range(h):
for j in range(w):
if (i+j) % 2 == 0:
print('#',end='')
else:
print('.',end='')
print()
print() | import math;
in_put = input("");
cube=math.pow(float(in_put),3);
print(int(cube)); | 0 | null | 593,371,822,570 | 51 | 35 |
s = input()
if len(s) >= 3:
print(s[0:3]) | a=input().split()
print(a[1]+a[0]) | 0 | null | 58,872,708,573,618 | 130 | 248 |
#!/usr/bin/python3
import sys
from collections import Counter
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = [int(x) for x in input().split()]
c = Counter(a)
def c2(n):
return n * (n - 1) // 2
ans = sum(c2(v) for v in c.values())
def add(x):
global ans
ans -= c2(c[x])
c[x] += 1
ans += c2(c[x])
def remove(x):
global ans
ans -= c2(c[x])
c[x] -= 1
ans += c2(c[x])
for x in a:
remove(x)
print(ans)
add(x) | import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
#全体の数列について答えを求めるnC2=n(n-1)/2
ALL=0
for i in c.values():
if i>1:
ALL += i*(i-1)//2
#各要素が影響する分を求める
for i in A:
if c[i]>2:
print(ALL-c[i]+1)
elif c[i]==2:
print(ALL-1)
else:
print(ALL) | 1 | 47,810,851,898,182 | null | 192 | 192 |
a = input()
print('Yes' if input() in a+a else 'No') | import sys
input = sys.stdin.readline
def inp():
return(int(input()))
print("Yes" if inp() >=30 else "No") | 0 | null | 3,716,683,233,540 | 64 | 95 |
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
lis = ['0']*N
time = [0]*N
for i in range(N):
lis[i],time[i] = input().split()
sing = input()
index = -1
for i in range(N):
if lis[i] == sing:
index = i
break
ans = 0
for i in range(index+1,N):
ans += int(time[i])
print(ans) | # -*- coding: utf-8 -*-
import sys
def gcd(a, b):
if a < b:
a, b = b, a
while b!=0:
c = b
b = a % b
a = c
return a
def lcm(a, b, g):
return a * b / g
def main():
for line in sys.stdin:
a, b = map(int, line.split())
ng = gcd(a, b)
nl = lcm(a, b, ng)
print('{0:d} {1:d}'.format(int(ng), int(nl)))
if __name__ == '__main__':
main() | 0 | null | 48,248,786,693,120 | 243 | 5 |
num=int(input())
print(3.14159265359*num*2) | r = int(input())
print(r * 6.28) | 1 | 31,513,322,378,060 | null | 167 | 167 |
from bisect import bisect_left
from itertools import accumulate
n, m = map(int, input().split())
hands = [int(x) for x in input().split()]
increasing = sorted(hands)
hands = list(reversed(increasing))
xs = [0] + list(accumulate(hands))
max_x = 2 * 10**5 + 1
min_x = 0
def canGet(x):
count = 0
for hand in increasing:
idx = bisect_left(increasing, x-hand)
count += n - idx
return count >= m
while max_x - min_x > 1:
# left
mid = (max_x + min_x) // 2
if canGet(mid):
min_x = mid
else:
max_x = mid
ans = 0
count = 0
for Ai in hands:
idx = bisect_left(increasing, min_x-Ai)
ans += Ai*(n-idx) + xs[n-idx]
count += n-idx
print(ans-(count-m)*min_x)
| # 上からm番目がx
# x以上のヒトがm人以上、x+1以上のヒトがm-1人以下
# x以上のヒトがm人以上となる最大のx
from bisect import bisect_left
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ok = 0
ng = 3 * (10 ** 5)
B = [0] + A[::-1]
C = list(accumulate(B))
while ng - ok > 1:
mid = (ok + ng) // 2
cnt = 0
for i in range(n):
gendo = mid - A[i]
position = bisect_left(A, gendo)
if position == n:
continue
kosuu = n - position
cnt += kosuu
if cnt >= m:
ok = mid
else:
ng = mid
ans = 0
cnt = m
for i in range(n):
gendo = ok - A[i]
position = bisect_left(A, gendo)
if position == n:
continue
kosuu = n - position
ans += C[kosuu] + kosuu * A[i]
cnt -= kosuu
ans += cnt * ok
print(ans)
| 1 | 108,436,870,099,034 | null | 252 | 252 |
def gcd(a,b):
if b == 1:
return 1
elif b == 0:
return a
else:
return gcd(b,a%b)
a,b = map(int, raw_input().split(' '))
if a > b:
print gcd(a,b)
else:
print gcd(b,a) | def swap(x, y):
tmp = x
x = y
y = tmp
def gcm(x, y):
if x < y:
swap(x, y)
while y > 0:
r = x % y
x = y
y = r
return x
if __name__ == '__main__':
x, y = list(map(int, input().split()))
n = gcm(x, y)
print(n) | 1 | 8,055,178,082 | null | 11 | 11 |
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()
prev = {}
ans = 0
for i in range(k):
if t[i] == 'r':
ans += P
prev[i] = 'p'
elif t[i] == 's':
ans += R
prev[i] = 'r'
elif t[i] == 'p':
ans += S
prev[i] = 's'
for i in range(k, n):
a = i % k
if t[i] == 'r':
if prev[a] != 'p':
ans += P
prev[a] = 'p'
else:
if i + k < n and t[i + k] != 's':
prev[a] = 'r'
else:
prev[a] = 's'
elif t[i] == 's':
if prev[a] != 'r':
ans += R
prev[a] = 'r'
else:
if i + k < n and t[i + k] != 'p':
prev[a] = 's'
else:
prev[a] = 'p'
elif t[i] == 'p':
if prev[a] != 's':
prev[a] = 's'
ans += S
else:
if i + k < n and t[i + k] != 'r':
prev[a] = 'p'
else:
prev[a] = 'r'
print(ans) | n, k = map(int, input().split())
s, p, r = map(int, input().split())
dic = {"p":p, "r":r, "s":s}
t = input()
ans = 0
for i in range(k):
bef = "a"
for j in range(i, n, k):
if bef == t[j]:
bef = "a"
else:
ans += dic[t[j]]
bef = t[j]
print(ans) | 1 | 106,769,988,223,310 | null | 251 | 251 |
a, b, c = list(map(int, input().split()))
k = int(input())
for i in range(k+1) :
if a >= b :
b *= 2
elif b >= c :
c *= 2
else :
print("Yes")
exit()
print("No")
| import bisect
n=int(input())
a=list(map(int,input().split()))
suma=[]
sumans=0
for i in range(n):
sumans += a[i]
suma.append(sumans)
u=bisect.bisect_right(suma, sumans//2)
print(min(abs(2*suma[u-1]-sumans), abs(2*suma[u]-sumans))) | 0 | null | 74,572,546,996,680 | 101 | 276 |
#import time
from itertools import dropwhile, takewhile
def main():
N, M = list(map(int, input().split()))
lis = [list(map(int, input().split())) for _ in range(M)]
#print(lis)
edge = [[] for _ in range(N+1)]
#print(edge)
for a,b in lis:
edge[a].append(b)
edge[b].append(a)
#print(edge)
ans = [0] * (N+1)
visited = {0}
stack = [1]
for i in stack:
for j in edge[i]:
if j in visited:
continue
stack.append(j)
#print(stack)
visited.add(j)
#print(visited)
ans[j]=i
print("Yes")
for k in ans[2:]:
print(k)
if __name__ == '__main__':
#start = time.time()
main()
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]") | from collections import*
(n,m),*c = [[*map(int,i.split())]for i in open(0)]
g = [[]for _ in range(n+1)]
for a,b in c:
g[a]+=[b]
g[b]+=[a]
q=deque([1])
r=[0]*(n+1)
while q:
v=q.popleft()
for i in g[v]:
if r[i]==0:
r[i]=v
q.append(i)
print("Yes",*r[2:],sep="\n")
| 1 | 20,548,654,886,412 | null | 145 | 145 |
import copy
class Dice:
def __init__(self, numbers):
self.dd = dict(zip(['U', 'S', 'E', 'W', 'N', 'B'], numbers))
def next(self, o):
old = copy.deepcopy(self.dd)
if o == 'E':
self.dd['B'] = old['E']
self.dd['U'] = old['W']
self.dd['E'] = old['U']
self.dd['W'] = old['B']
elif o == 'S':
self.dd['B'] = old['S']
self.dd['U'] = old['N']
self.dd['S'] = old['U']
self.dd['N'] = old['B']
elif o == 'W':
self.dd['B'] = old['W']
self.dd['U'] = old['E']
self.dd['E'] = old['B']
self.dd['W'] = old['U']
elif o == 'N':
self.dd['B'] = old['N']
self.dd['U'] = old['S']
self.dd['S'] = old['B']
self.dd['N'] = old['U']
dn = [int(n) for n in input().split()]
op = input()
ad = Dice(dn)
for o in op:
ad.next(o)
print(ad.dd['U']) | import copy
class Dice:
def __init__(self, eyes: [int]):
self.__eyes = eyes
def top(self):
return self.__eyes[0]
def roll_s(self):
tmp = copy.copy(self.__eyes)
tmp[0] = self.__eyes[4]
tmp[1] = self.__eyes[0]
tmp[2] = self.__eyes[2]
tmp[3] = self.__eyes[3]
tmp[4] = self.__eyes[5]
tmp[5] = self.__eyes[1]
self.__eyes = tmp
def roll_e(self):
tmp = copy.copy(self.__eyes)
tmp[0] = self.__eyes[3]
tmp[1] = self.__eyes[1]
tmp[2] = self.__eyes[0]
tmp[3] = self.__eyes[5]
tmp[4] = self.__eyes[4]
tmp[5] = self.__eyes[2]
self.__eyes = tmp
def roll_n(self):
tmp = copy.copy(self.__eyes)
tmp[0] = self.__eyes[1]
tmp[1] = self.__eyes[5]
tmp[2] = self.__eyes[2]
tmp[3] = self.__eyes[3]
tmp[4] = self.__eyes[0]
tmp[5] = self.__eyes[4]
self.__eyes = tmp
def roll_w(self):
tmp = copy.copy(self.__eyes)
tmp[0] = self.__eyes[2]
tmp[1] = self.__eyes[1]
tmp[2] = self.__eyes[5]
tmp[3] = self.__eyes[0]
tmp[4] = self.__eyes[4]
tmp[5] = self.__eyes[3]
self.__eyes = tmp
def roll(self, direction: str):
if direction == 'N':
self.roll_n()
if direction == 'E':
self.roll_e()
if direction == 'S':
self.roll_s()
if direction == 'W':
self.roll_w()
def resolve():
eyes = list(map(int, input().split()))
directions = list(input())
dice = Dice(eyes)
for direction in directions:
dice.roll(direction)
print(dice.top())
resolve()
| 1 | 235,077,717,332 | null | 33 | 33 |
from collections import deque
n,x,y=map(int,input().split())
l=[[1]]
for i in range(1,n-1):
l.append([i-1,i+1])
l.append([n-2])
x,y=x-1,y-1
l[x].append(y)
l[y].append(x)
#print(l)
p=[0 for i in range(n)]
for j in range(n):
s=[-1 for i in range(n)]
s[j]=0
q=deque([j])
while len(q)>0:
a=q.popleft()
for i in l[a]:
if s[i]==-1:
s[i]=s[a]+1
q.append(i)
for i in s:
if i!=0:
p[i]+=1
print(*map(lambda x:x//2,p[1:]),sep='\n') | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, X, Y = mapint()
X, Y = X-1, Y-1
dist = [0]*(N-1)
for i in range(N-1):
for j in range(i+1, N):
d = min(j-i, abs(i-X)+abs(j-Y)+1, abs(i-Y)+abs(j-X)+1)
dist[d-1] += 1
for k in range(N-1):
print(dist[k]) | 1 | 44,106,615,825,668 | null | 187 | 187 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
a = [1+(i-1)/2 for i in p]
l = sum(a[:k])
ans = l
for i in range(1, n-k+1):
l = l-a[i-1]+a[k+i-1]
ans = max(ans, l)
print(ans) | n, k = map(int, input().split())
p = list(map(int, input().split()))
e = [(p[i]+1)/2 for i in range(n)]
tmp = sum(e[:k])
ans = tmp
for i in range(n-k):
tmp += (e[i+k]-e[i])
ans = max(ans, tmp)
print(ans) | 1 | 74,683,714,699,122 | null | 223 | 223 |
a = input()
if a[-1] == 's':
print(a + 'es')
else:
print(a + 's') | n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
journey = [1]
for i in range(n):
journey.append(a[journey[i]])
if k <= n:
print(journey[k])
exit()
cycle_end = n
cycle_start = n - 1
while journey[cycle_start] != journey[cycle_end]:
cycle_start -= 1
cycle_range = cycle_end - cycle_start
cycle_cnt = (k - n) // cycle_range
extra = (k - n) - (cycle_range * cycle_cnt)
for i in range(extra):
journey.append(a[journey[i + n]])
print(journey[-1]) | 0 | null | 12,573,983,207,620 | 71 | 150 |
N = int(input())
ans = []
for n in range(1, int(N ** 0.5) + 1):
if (N - 1) % n == 0:
ans.append(n)
ans.append((N - 1) // n)
for k in range(2, int(N ** 0.5) + 1):
if N % k != 0:
continue
x = N
while x % k == 0:
x //= k
if x % k == 1:
ans.append(k)
print(len(set(ans)))
| n = int(input())
def yakusu(x):
xx = 2
y = []
while xx**2 < x:
if x%xx == 0:
y.append(xx)
y.append(x//xx)
xx += 1
if xx**2 == x:
y.append(xx)
y.append(x)
return y
if n == 2:
ans = 0
else:
ans = len(yakusu(n-1))
for i in yakusu(n):
nn = n
while True:
if nn%i == 0:
nn = nn//i
else:
break
if nn%i == 1:
ans += 1
print(ans)
| 1 | 41,069,637,053,760 | null | 183 | 183 |
K=int(input())
if K==4 :
print(2)
elif K==6 :
print(2)
elif K==8 :
print(5)
elif K==9 :
print(2)
elif K==10 :
print(2)
elif K==12 :
print(5)
elif K==14 :
print(2)
elif K==16 :
print(14)
elif K==18 :
print(5)
elif K==20 :
print(5)
elif K==21 :
print(2)
elif K==22 :
print(2)
elif K==24 :
print(15)
elif K==25 :
print(2)
elif K==26 :
print(2)
elif K==27 :
print(5)
elif K==28 :
print(4)
elif K==30 :
print(4)
elif K==32 :
print(51)
else :
print(1) | a = input()
for i in xrange(10000) :
print "Case " + str(i+1) + ": " + str(a)
a = input()
if (a == 0) :
break | 0 | null | 25,137,680,262,980 | 195 | 42 |
N,M,K=list(map(int,input().split()))
MAXN = 2*(10**5)+10
p = 998244353
MOD = p
f = [1]
for i in range(MAXN):
f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod
def power_func(a,n,p):
bi=str(format(n,"b"))#2進表現に
res=1
for i in range(len(bi)):
res=(res*res) %p
if bi[i]=="1":
res=(res*a) %p
return res
out = 0
for i in range(K+1):
out += M*nCr(N-1,i,p)*power_func(M-1,N-1-i,p)
out = out % p
print(out) | n = int(input())
acl = "ACL" * n
print(acl)
| 0 | null | 12,618,672,961,960 | 151 | 69 |
n = input()
a = map(int,raw_input().split())
for i in xrange(len(a)):
v = a[i]
j = i - 1
while j >= 0 and a[j] > v :
a[j+1] = a[j]
j = j - 1
a[j+1] = v
print " ".join(map(str,a)) | s = input()
count = 1; memo = 0; x = 0
for i in range(1, len(s)):
if s[i-1] == "<" and s[i] == ">":
x += count*(count-1)//2
memo = count
count = 1
elif s[i-1] == ">" and s[i] == "<":
x += count*(count-1)//2+max(count, memo)
memo = 0
count = 1
else:
count += 1
else:
if s[-1] == "<":
x += count*(count+1)//2
else:
x += count*(count-1)//2+max(count, memo)
print(x) | 0 | null | 77,967,206,451,330 | 10 | 285 |
X,K,D = map(int,input().split())
ans = 0
if X == 0:
if K % 2 == 0:
ans = 0
else:
ans = D
if X > 0:
if K*D <= X:
ans = X - K*D
else:
n = X // D
if X % D != 0:
n += 1
if (K - n) % 2 == 0:
ans = abs(X-D*n)
else:
ans = abs(X-D*(n-1))
if X < 0:
if K*D + X <= 0:
ans = abs(K*D+X)
else:
n = -X // D
if -X % D != 0:
n += 1
if (K-n) % 2 == 0:
ans = abs(X+n*D)
else:
ans = abs(X+(n-1)*D)
print(ans) | # bit全探索 典型といえば典型(問題文の意味がよくわからんので読解力コンテスト)
n = int(input())
syogen = []
for i in range(n):
syogen.append([])
for _ in range(int(input())):
syogen[i].append(list(map(int, input().split())))
ans = 0
for bit in range(1 << n):
p = ["不親切"] * n
ng = False
# bitの立っているのを正直者と仮定
for i in range(n):
if bit >> i & 1 == 1:
# 上位bit = 小さいインデックス、になる(ように実装してしまった わかりづらい
p[n - i - 1] = "正直者"
for i in range(n):
if p[i] == "不親切":
# まあ不親切な人間のことなんて聞かなくていい
continue
for s in syogen[i]:
if p[s[0] - 1] == "正直者" and s[1] == 1:
# 証言と一致する
continue
elif p[s[0] - 1] == "不親切" and s[1] == 0:
# 証言と一致する
continue
else:
# 証言と一致しない
ng = True
break
if not ng:
ans = max(ans, p.count("正直者"))
print(ans)
| 0 | null | 63,321,115,385,692 | 92 | 262 |
C = input()
ans = chr(ord(C) + 1)
print(ans)
| # a^n mod p
def exp_by_sq(a, n, p):
if n == 0:
exp = 1
elif n == 1:
exp = a % p
elif n % 2 == 0:
exp = exp_by_sq(a * a % p, n // 2, p)
else:
exp = a * exp_by_sq(a * a % p, (n - 1) // 2, p) % p
return exp % p
# 入力
n, k = [int(x) for x in input().split()]
p = 10 ** 9 + 7
# Find n * sum_{j = 0..m}{(n choose j)^2 * (n - j)}
m = min(n, k)
# 最初の2項
binom = n # n choose 1 mod p
ans = n * ((n * n - n + 1) % p) % p # (n choose 0)^2 * (n - 0) + (n choose 1)^2 * (n - 1)
inv = [0, 1]
inv_n = exp_by_sq(n, p - 2, p) # n^(-1) mod p
for i in range(2, m + 1):
inv_i = ( inv[p % i] * (p - p//i) ) % p # inverse of i
inv.append(inv_i)
binom = (binom * (n - i + 1) % p) * inv_i % p
ans = (ans + (binom * binom % p) * (n - i)) % p
ans = ans * inv_n % p
print(ans)
| 0 | null | 79,725,678,102,510 | 239 | 215 |
x, y = map(int, input(). split())
while True:
if x % y == 0:
break
tmp = x % y
x = y
y = tmp
print(y) | n = int(input())
a = [int(x) for x in input().split()]
sm_e = []
sm_o = []
e = 0
o = 0
for i in range(n):
if i % 2 == 0:
e += a[i]
sm_e.append(e)
else:
o += a[i]
sm_o.append(o)
tot_e = sm_e[-1]
tot_o = sm_o[-1]
m = len(sm_o)
if n % 2 == 0:
ans = max(tot_e, tot_o)
for i in range(m):
ans = max(ans, sm_e[i] + tot_o - sm_o[i])
# for i in range(m-1):
# ans = max(ans, sm_o[i] + tot_e - sm_e[i+1])
print(ans)
exit()
ans = tot_o
for i in range(m):
ans = max(ans, sm_e[i]+tot_o-sm_o[i])
l = [0]*m
for i in range(m):
l[i] = sm_e[i]-sm_o[i]
val = l[0]
tmp = 0
for i in range(m-1):
ans = max(ans, sm_o[i] + tot_e - sm_e[i+1])
if i != 0:
if val < l[i]:
val = l[i]
ans = max(ans, sm_o[i] + tot_e - sm_e[i+1] + val)
for i in range(n):
if i % 2 == 0:
ans = max(ans, tot_e - a[i])
print(ans)
| 0 | null | 18,826,758,393,750 | 11 | 177 |
s, t = input("").split(" ")
res = t + s
print(res) | a, b, c, d = map(int,input().split())
flag = True
while a > 0 and c > 0:
c -= b
if c <= 0:
flag = True
break
a -= d
if a <= 0:
flag = False
break
if flag:
print('Yes')
else:
print('No') | 0 | null | 66,326,412,336,428 | 248 | 164 |
from collections import deque
import copy
H, W = map(int, input().split())
route = []
for _ in range(H):
route.append(input())
wall = set()
start = set()
for y, r in enumerate(route):
for x, w in enumerate(r):
if w == '.':
start.add((x, y))
score = -1
ssize = [(-1,0),(0,-1),(1,0),(0,1)]
for xy in start:
d = deque()
d.append((xy+(0,)))
step = 0
can = copy.deepcopy(start)
can.remove(xy)
while len(d) > 0:
now = d.popleft()
step = now[2]
for xs, ys in ssize:
nxt = (now[0]+xs, now[1]+ys)
if nxt in can:
d.append(nxt+(step+1,))
can.remove(nxt)
score = max(step, score)
print(score) | from collections import deque
H,W = map(int,input().split())
field = [list(input()) for _ in range(H)]
dist = [[-1]*W for _ in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
mx = 0
for h in range(H):
for w in range(W):
if field[h][w] == "#":
continue
dist = [[-1]*W for _ in range(H)]
dist[h][w] = 0
que = deque([])
que.append([h,w])
while que != deque([]):
u,v = que.popleft()
for dir in range(4):
nu = u + dx[dir]
nv = v + dy[dir]
if (nu < 0) or (nu >= H) or (nv < 0) or (nv >= W):
continue
if field[nu][nv] == "#":
continue
if dist[nu][nv] != -1:
continue
que.append([nu,nv])
dist[nu][nv] = dist[u][v] + 1
for i in range(H):
for j in range(W):
if mx < dist[i][j]:
mx = dist[i][j]
print(mx) | 1 | 94,546,013,608,640 | null | 241 | 241 |
import math
a,b,H,M=map(int,input().split())
theta_a = math.pi/6 * (H+M/60)
theta_b = math.pi*2*M/60
ans = math.sqrt((b*math.cos(theta_b) - a*math.cos(theta_a))**2 + (b*math.sin(theta_b) - a*math.sin(theta_a))**2)
print(ans) | nn, kk = list(map(int,input().split()))
sum = 0
for i in range(kk, nn+2):
min = (0+i-1)*i/2
max = (nn+nn-i+1)*i/2
sum += (max-min)+1
sum = sum % (10**9+7)
print(int(sum)) | 0 | null | 26,697,218,600,120 | 144 | 170 |
N,M,K=map(int,input().split())
*A,=map(int,input().split())
*B,=map(int,input().split())
def binary_search(func, array, left=0, right=-1):
if right==-1:right=len(array)-1
y_left, y_right = func(array[left]), func(array[right])
while True:
middle = (left+right)//2
y_middle = func(array[middle])
if y_left==y_middle: left=middle
else: right=middle
if right-left==1:break
return left
cumA = [0]
for i in range(N):
cumA.append(cumA[-1]+A[i])
cumB = [0]
for i in range(M):
cumB.append(cumB[-1]+B[i])
cumB.append(10**20)
if cumA[-1]+cumB[-1]<=K:
print(N+M)
exit()
if A[0] > K and B[0] > K:
print(0)
exit()
ans = 0
for i in range(N+1):
if K-cumA[i]<0:break
idx = binary_search(lambda x:x<=K-cumA[i],cumB)
res = max(0,i+idx)
ans = max(ans, res)
print(ans) | n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
asum.append(asum[-1]+a[i])
for i in range(m):
bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
if asum[i]>k:
break
while asum[i]+bsum[m]>k and m>0:
m-=1
ans=max(ans,i+m)
print(ans) | 1 | 10,738,056,650,608 | null | 117 | 117 |
N,P = map(int,input().split())
S = list(map(int,list(input())))
if P==2:
cnt = 0
for i in range(N):
if S[i]%2==0:
cnt += i+1
elif P==5:
cnt = 0
for i in range(N):
if S[i]==0 or S[i]==5:
cnt += i+1
else:
A = [0 for _ in range(N)]
a = 0
b = 1
for i in range(N-1,-1,-1):
a = (a+b*S[i])%P
A[i] = a
b = (b*10)%P
C = {i:0 for i in range(P)}
for i in range(N):
C[A[i]] += 1
cnt = 0
for i in range(P):
cnt += (C[i]*(C[i]-1))//2
cnt += C[0]
print(cnt) | ary = list(filter(lambda x: int(x) % 3 != 0 and int(x) % 5 != 0, list(range(int(input()) + 1))))
print(sum(ary)) | 0 | null | 46,630,154,917,220 | 205 | 173 |
def bubbleSort(a,n):
flag = 1
count = 0
while flag:
flag = 0
for j in range(n-1,0,-1):
if a[j] < a[j-1]:
count += 1
w = a[j]
a[j] = a[j-1]
a[j-1] = w
flag = 1
print(' '.join(map(str, a)))
print(count)
n = int(input())
a = list(map(int, input().split()))
bubbleSort(a,n)
| from collections import deque
n = int(input())
data = deque(list(input() for _ in range(n)))
ans = deque([])
co = 0
for i in data:
if i[6] == ' ':
if i[0] == 'i':
ans.insert(0, i[7:])
co += 1
else:
try:
ans.remove(i[7:])
co -= 1
except:
pass
else:
if i[6] == 'F':
del ans[0]
co -= 1
else:
del ans[-1]
co -= 1
for i in range(0, co-1):
print(ans[i], end=' ')
print(ans[co-1])
| 0 | null | 31,601,352,892 | 14 | 20 |
x = 0
while x == 0:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
print "#" * m[1]
for i in xrange(m[0]-2):
print "#" + "." * (m[1]-2) + "#"
print "#" * m[1]
print "" | while True:
line = list(map(int,input().split()))
if line==[0,0]: break
for i in range(line[0]):
if i==0 or i==line[0]-1: print('#'*line[1])
else: print('#'+'.'*(line[1]-2)+'#')
print() | 1 | 815,802,493,680 | null | 50 | 50 |
from sys import stdin
import math
def GCD(a,b):
if(a%b==0):
return b
else:
c = a%b
return GCD(b,c)
def LCM(a,b):
gcd = GCD(a,b)
return int(a*b/gcd)
for line in stdin:
a,b = line.split(" ")
a = int(a)
b = int(b)
gcd = GCD(a,b)
lcm = LCM(a,b)
print(str(gcd)+" "+str(lcm))
| # coding=utf-8
def solve_gcd(number1: int, number2: int) -> int:
two_list = [number1, number2]
two_list.sort()
if two_list[1] % two_list[0] == 0:
return two_list[0]
r = two_list[1] % two_list[0]
return solve_gcd(two_list[0], r)
def solve_lcm(number1: int, number2: int, number3: int) -> int:
return number1*number2//number3
if __name__ == '__main__':
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
gcd = solve_gcd(a, b)
lcm = solve_lcm(a, b, gcd)
print(gcd, lcm) | 1 | 552,158,840 | null | 5 | 5 |
l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
s = input()
if s in l:
print(7-l.index(s))
else:
pass | Day = ['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
print(Day.index(input())) | 1 | 133,180,735,013,470 | null | 270 | 270 |
l, r, d = map(int, input().split())
result=0
for i in range(r-l+1):
if (l+i) % d == 0:
result+=1
print(result)
| n="0"+input()
k=int(input())
dp=[[[0]*(k+1) for i in range(len(n))] for _ in range(2)]
dp[0][0][0]=1
dp[1][1][0]=1
for i in range(1,len(n)):
x=int(n[i])
dp[1][i][0]+=dp[1][i-1][0]
for j in range(1,k+1):
if x==0:
dp[0][i][j]+=dp[0][i-1][j]
dp[1][i][j]+=dp[1][i-1][j]+dp[1][i-1][j-1]*9
else:
dp[0][i][j]+=dp[0][i-1][j-1]
dp[1][i][j]+=dp[1][i-1][j]+dp[1][i-1][j-1]*9+dp[0][i-1][j-1]*(x-1)+dp[0][i-1][j]
print(dp[1][-1][-1]+dp[0][-1][-1]) | 0 | null | 41,985,782,559,360 | 104 | 224 |
M1, D1 = [int(_) for _ in input().split(" ")]
M2, D2 = [int(_) for _ in input().split(" ")]
if M1 == M2:
print (0)
else:
print (1)
| s = input()
q = []
for i in s:
q.append(int(i))
if sum(q)%9 == 0:
print('Yes')
else:print('No') | 0 | null | 64,369,151,305,312 | 264 | 87 |
def selection(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i], A[minj] = A[minj], A[i]
count += 1
return A, count
if __name__ == "__main__":
N = int(input())
A = [int(i) for i in input().split()]
A, count = selection(A, N)
print (*A)
print (count) | length = int(input())
targ = [int(n) for n in input().split(' ')]
ans = 0
for l in range(length):
value = l
for init in range(l + 1,length):
if targ[value] > targ[init]:
value = init
if value != l:
disp = targ[l]
targ[l] = targ[value]
targ[value] = disp
ans += 1
print(' '.join([str(n) for n in targ]))
print(ans) | 1 | 22,109,710,590 | null | 15 | 15 |
def abc159d_banned_k():
def cmb(n, r):
""" nCrの組み合わせ数を返す """
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
n = int(input())
a = list(map(int, input().split()))
dict_a = {}
for item in a:
if item in dict_a.keys():
dict_a[item] += 1
else:
dict_a[item] = 1
cnt = 0
for k in dict_a:
if dict_a[k] > 1:
cnt += cmb(dict_a[k],2)
for item in a:
if dict_a[item] > 2:
print(cnt - cmb(dict_a[item],2) + cmb(dict_a[item]-1,2))
elif dict_a[item] == 2:
print(cnt - 1)
else:
print(cnt)
abc159d_banned_k() | n = int(input())
lst = [ int(i) for i in input().split() ]
visited = {}
for d in lst:
if d in visited.keys():
visited[d] += 1
else:
visited[d] = 1
count = 0
for d in visited.keys():
count += int(visited[d]*(visited[d]-1)/2)
for d in lst:
v = visited[d] - 1
ans = count - v
print(ans) | 1 | 47,686,228,975,008 | null | 192 | 192 |
def main():
import sys
K=int(sys.stdin.readline())
print('ACL'*K)
main() | def main():
n = int(input())
X = [int(x) for x in input().split()]
ave_x = int(sum(X) / len(X))
error_1 = 0
error_2 = 0
for x in X:
error_1 += (x-ave_x) ** 2
error_2 += (x-(ave_x+1)) ** 2
min_e = min(error_1, error_2)
print(min_e)
if __name__ == '__main__':
main() | 0 | null | 33,477,217,094,880 | 69 | 213 |
N = int(input())
A = [int(x) for x in input().split()]
S = [0] * (N+1) #累積和用のリスト
s = 0
CONST = 10**9+7
#前準備として累積和を計算
for i in range(N):
S[i+1] = S[i] + A[i]
#積の総和を計算
for i in range(N-1):
s += A[i] * ((S[N] - S[i+1]) % CONST)
s %= CONST
print(s) | from sys import stdin
from itertools import accumulate
input = stdin.readline
n = int(input())
a = list(map(int,input().split()))
p = [0] + list(accumulate(a))
res = 0
for i in range(n-1,-1,-1):
res += (a[i] * p[i])%(10**9 + 7)
print(res % (10**9 + 7)) | 1 | 3,825,121,000,800 | null | 83 | 83 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
ML = 50
r = min(ML,k)
for l in range(r):
imos = [0]*(n+1)
for i in range(n):
left = max(0,i-a[i])
right = min(n,i+a[i]+1)
imos[left] += 1
imos[right] -= 1
c = 0
for i in range(n):
c += imos[i]
a[i] = c
print(*a) | import sys
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
@njit(cache=True)
def solve(n, k, a):
if k == 0:
return a
b = [0]*n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i-a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n-1):
b[i+1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a)) | 1 | 15,416,977,377,536 | null | 132 | 132 |
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, M, L = inpl()
road = [[] for _ in range(N)]
ABC = []
for i in range(M):
A, B, C = inpl()
if C <= L:
road[A-1].append((B-1,C))
road[B-1].append((A-1,C))
ABC.append((A-1,B-1,C))
INF = 10**12
cur1 = [[INF]*N for _ in range(N)]
for a, b, c in ABC:
cur1[a][b] = cur1[b][a] = c
for k in range(N):
prev1 = cur1
cur1 = [[INF]*N for _ in range(N)]
for j in range(N):
for i in range(N):
cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k])
cur2 = [[INF]*N for j in range(N)]
for j in range(N):
for i in range(N):
if cur1[j][i] <= L:
cur2[j][i] = 1
for k in range(N):
prev2 = cur2
cur2 = [[INF]*N for _ in range(N)]
for j in range(N):
for i in range(N):
cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k])
Q = int(input())
ST = [inpl() for _ in range(Q)]
for s,t in ST:
if cur2[s-1][t-1] >= INF:
print(-1)
else:
print(cur2[s-1][t-1]-1) | while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
for height in range(H):
for wide in range(W):
if height == 0 or height == H-1 or wide == 0 or wide == W-1:
print('#', end='')
else:
print('.', end='')
print('')
print('') | 0 | null | 87,153,614,578,004 | 295 | 50 |
from decimal import Decimal
a, b = map(float, input().split())
a = Decimal(str(a))
b = Decimal(str(b))
print(int(a * b))
| def main():
data = input().split()
print( int(data[0]) * int(data[1]))
if __name__ == '__main__':
main()
| 1 | 15,869,559,766,242 | null | 133 | 133 |
K = int(input())
s = ""
for i in range(K):
s += 'ACL'
print(s) | k=int(input())
l=['ACL']*k
print(*l,sep='')
| 1 | 2,203,083,739,890 | null | 69 | 69 |
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
d= [abs(x[i] - y[i]) for i in range(n)]
for i in range(1, 4):
a = 0
for j in d:
a += j**i
print("{:.6f}".format(a**(1/i)))
print("{:.6f}".format(max(d)))
| N = int(input())
x = input().split()
y = input().split()
x = [int(j) for j in x]
y = [int(z) for z in y]
d1 = 0
d2 = 0
d4 = []
d3 = 0
for i in range(N):
d1 += abs(x[i]- y[i])
d2 += (x[i]-y[i])**2
d3 += abs(x[i]-y[i])**3
d4.append(abs(x[i]- y[i]))
d2_root = d2**0.5
d3_root = d3**(1/3)
print('{:.08f}'.format(d1))
print('{:.08f}'.format(d2_root))
print('{:.08f}'.format(d3_root))
print('{:.08f}'.format(max(d4)))
| 1 | 217,440,235,210 | null | 32 | 32 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
S = input()
cnt = 0
mx = 0
for i in range(len(S)):
if (S[i] == 'R'):
cnt += 1
else:
cnt = 0
mx = max(mx, cnt)
print(mx)
if __name__ == '__main__':
main()
| from numba import njit
@njit(fastmath=True)
def fact(x):
i = 1
while i * i <= x:
if x % i == 0:
yield i
yield x // i
i += 1
def main():
n = int(input())
a = tuple(map(int, input().split()))
c = [0] * (max(a) + 1)
for e in a:
c[e] += 1
ans = n
for e in a:
c[e] -= 1
for fct in fact(e):
if c[fct]:
ans -= 1
break
c[e] += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 9,678,380,985,020 | 90 | 129 |
n, a, b = [int(x) for x in input().split()]
if (b - a) % 2 == 0:
print((b - a) // 2)
else:
print(min(a, n - b + 1) + (b - a - 1) // 2) | N,A,B=map(int,input().split())
if (A+B)%2==0:
P=(B-A)//2
else:
P=float("inf")
if (A+B)%2==1:
Q=A
Q+=(B-Q-(B-Q+1)//2)
else:
Q=float("inf")
if (A+B)%2==1:
R=N-B+1
B=N
A+=R
R+=B-(A+B)//2
else:
R=float("inf")
print(min(P,Q,R)) | 1 | 109,700,768,072,910 | null | 253 | 253 |
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
divisible = [False for _ in range(int(1e6+1))]
cnt = defaultdict(int)
for a in A:
cnt[a] += 1
if divisible[a] == False and cnt[a] <= 1:
for i in range(a+a, len(divisible), a):
divisible[i] = True
ans = 0
for a in A:
if divisible[a] is False and cnt[a] <= 1:
ans += 1
print(ans)
| N, K = [int(_) for _ in input().split()]
MOD = 10 ** 9 + 7
ans = 0
class ModFactorial:
"""
階乗, 組み合わせ, 順列の計算
"""
def __init__(self, n, MOD=10 ** 9 + 7):
"""
:param n: 最大の要素数.
:param MOD:
"""
kaijo = [0] * (n + 10)
gyaku = [0] * (n + 10)
kaijo[0] = 1
kaijo[1] = 1
for i in range(2, len(kaijo)):
kaijo[i] = (i * kaijo[i - 1]) % MOD
gyaku[0] = 1
gyaku[1] = 1
for i in range(2, len(gyaku)):
gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
self.kaijo = kaijo
self.gyaku = gyaku
self.MOD = MOD
def nCm(self, n, m):
return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD
def nPm(self, n, m):
return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD
def factorial(self, n):
return self.kaijo[n]
mf = ModFactorial(N, MOD)
for i in range(1, N + 1):
if N - i > K: continue
p = N - i
# print(i, p, mf.nCm(p + i - 1, i - 1))
ans += mf.nCm(p + i - 1, i - 1) * mf.nCm(N, i)
ans %= MOD
print(ans)
| 0 | null | 40,850,669,036,594 | 129 | 215 |
import numpy as np
from numpy.fft import rfft, irfft
N, M = map(int, input().split())
*A, = map(int, input().split())
B = np.zeros(5*10**5)
for a in A:
B[a] += 1
L = 5*10**5
FB = rfft(B, L)
C = np.rint(irfft(FB*FB)).astype(int)
ans = 0
for i in range(2*10**5, -1, -1):
c = C[i]
if not c:
continue
if M - c > 0:
ans += i*c
M -= c
else:
ans += i*M
break
print(ans)
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
a = sorted(inpl())
ng = 10**9+1
ok = -1
def sol(x):
cnt = 0
for i,t in enumerate(a):
tmp = x - t
c = bisect.bisect_left(a,tmp)
cnt += n-c
return True if cnt >= m else False
while ng-ok > 1:
mid = (ng+ok)//2
if sol(mid):
ok = mid
else: ng = mid
# print(ok,ng)
# print(ok)
res = 0
cnt = 0
revc = [0]
for i in range(n)[::-1]:
revc.append(revc[-1] + a[i])
# print(revc)
for i in range(n):
j = n-bisect.bisect_left(a,ok-a[i])
res += j*a[i] + revc[j]
cnt += j
res -= (cnt-m) * ok
print(res) | 1 | 108,385,193,477,840 | null | 252 | 252 |
N = int(input())
A = list(map(int, input().split()))
res = 0
for i in range(1, N + 1):
if i % 2 == 1 and A[i-1] % 2 == 1:
res += 1
print(res)
| n = list(map(int,input().split()))
ans = n[1] * n[3]
ans = max(n[0]*n[2],ans)
ans = max(n[0]*n[3],ans)
ans = max(n[1]*n[2],ans)
ans = max(n[1]*n[3],ans)
print(ans) | 0 | null | 5,392,107,644,516 | 105 | 77 |
n = int(input())
a = [0]+list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
if i%2 == 1 and a[i]%2==1:
ans += 1
print(ans) | N, A, B = map(int, input().split())
A, B = min(A, B), max(A, B)
d = B - A
if d % 2 == 0:
print(d // 2)
else:
if (A - 1 <= N - B):
A, B = A - 1, B - 1
else:
A, B = N - B, N - A
ans = min(B, A + 1 + (B - A - 1) // 2)
print(ans)
| 0 | null | 58,424,554,153,472 | 105 | 253 |
class SegTree:
def __init__(self, init_val, ide_ele, segfunc):
self.n = len(init_val)
self.num =2**(self.n-1).bit_length()
self.ide_ele = ide_ele
self.seg = [self.ide_ele]*2*self.num
self.segfunc = segfunc
#set_val
for i in range(self.n):
self.seg[i+self.num-1] = init_val[i]
#built
for i in range(self.num-2,-1,-1) :
self.seg[i] = segfunc(self.seg[2*i+1], self.seg[2*i+2])
def update(self, k, x):
k += self.num-1
self.seg[k] = x
while k+1:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
def query(self, p, q):
if q<=p:
return self.ide_ele
p += self.num-1
q += self.num-2
res = self.ide_ele
while q-p>1:
if p&1 == 0:
res = self.segfunc(res, self.seg[p])
if q&1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
import sys
input = sys.stdin.readline
N = int(input())
S = input()
L = [-1]*N
for i in range(N):
L[i] = 2**(ord(S[i]) - ord('a'))
def segfunc(a,b):
return a | b
Seg = SegTree(L,0,segfunc)
Q = int(input())
for _ in range(Q):
q,a,b = input().split()
if q == '1':
i = int(a)-1
c = 2**(ord(b) - ord('a'))
Seg.update(i,c)
elif q=='2':
l = int(a)-1
r = int(b)-1
X = Seg.query(l,r+1)
tmp = 0
for j in range(30):
if X%2==1:
tmp += 1
X//=2
print(tmp) | import itertools
def main():
N = int(input())
BIT = list(itertools.product([True,False], repeat=N))
P = [[(0,0)]]
for i in range(1,N+1):
A = int(input())
L = []
for _ in range(A):
x,y = map(int,input().split())
L.append((x,y))
P.append(L)
ans = 0
for b in BIT:
cnt = 0
flag = True
HU = [-1]*(N+1)
for i in range(1,N+1):
if b[i-1]:
cnt += 1
for hu in P[i]:
if b[hu[0]-1] != (hu[1]==1):
flag = False
break
if flag:
ans = max(ans,cnt)
print(ans)
if __name__ == '__main__':
main() | 0 | null | 91,783,152,283,660 | 210 | 262 |
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
X,Y=MI()
N3=X+Y
if N3%3!=0:
print(0)
exit()
N=N3//3
a=0
b=0
for i in range(N+1):
if 2*i + (N-i) == X:
a=i
b=N-i
break
if a==0 and b==0:
print(0)
exit()
fact=[1,1]
factinv=[1,1]
inv=[0,1]
for i in range(2, N + 5):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
ans=fact[N]*factinv[a]*factinv[b]
print(ans%mod)
main()
| X,Y=map(int,input().split())
if 2*Y<X or 2*X<Y:
print(0)
exit()
if not((X%3==0 and Y%3==0) or (X%3==1 and Y%3==2) or (X%3==2 and Y%3==1)):
print(0)
exit()
P=10**9+7
A=(2*Y-X)//3
B=(2*X-Y)//3
num = 1
for i in range(A+1, A+B+1):
num=num*i%P
den = 1
for j in range(1, B+1):
den = den*j%P
den = pow(den,P-2,P)
print((num*den)%P) | 1 | 149,956,051,524,430 | null | 281 | 281 |
n, m = map(int, input().split())
ans = []
if n % 2 == 1:
for i in range(m):
ans.append((i+1, n-i))
else:
for i in range(m):
if i <= (m+1)//2-1:
ans.append((i+1, n-i))
else:
ans.append((i+1, n-i-1))
for a, b in ans:
print(a, b)
| import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, m = map(int, readline().split())
if m % 2 == 0:
rem = m
for i in range(m // 2):
print(i + 1, m + 1 - i)
rem -= 1
if rem == 0:
return
for i in range(n):
print(m + 2 + i, 2 * m + 1 - i)
rem -= 1
if rem == 0:
return
else:
rem = m
for i in range((m - 1) // 2):
print(i + 1, m - i)
rem -= 1
if rem == 0:
return
for i in range(n):
print(m + 1 + i, 2 * m + 1 - i)
rem -= 1
if rem == 0:
return
if __name__ == '__main__':
main()
| 1 | 28,478,748,976,588 | null | 162 | 162 |
xyz = list(map(int,input().split()))
print("{} {} {}".format(xyz[2],xyz[0],xyz[1])) | row, col = map(int,input().split())
mat = [[0 for i2 in range(col)] for i1 in range(row)]
for i in range(row):
mat[i] = list(map(float,input().split()))
vec = [0 for i in range(col)]
for i in range(col):
vec[i] = float(input())
result = [0 for i in range(row)]
for i in range(row):
for j in range(col):
result[i] += mat[i][j]*vec[j]
for i in range(len(result)):
print(int(result[i])) | 0 | null | 19,609,320,545,782 | 178 | 56 |
n, k = map(int, input().split())
sunuke = []
for s in range(n):
sunuke.append(str(s+1))
for t in range(k):
d = int(input())
hito = input().split(" ")
for u in range(d):
for v in range(n):
if hito[u] == sunuke[v]:
sunuke[v] = 0
else:
pass
m = sunuke.count(0)
print(n-m) | import sys
input=sys.stdin.readline
LEN=2*10**5+10
moves=[0]*LEN
for i in range(1,LEN): #1~Nまでのすべての数について、0になるまでの操作回数を求める
tmp=i
cnt=0
while tmp!=0:
popcount=0
for j in range(20):
if tmp&(1<<j):
popcount+=1
tmp%=popcount
cnt+=1
moves[i]=cnt
n=int(input())
x=input()
k=x.count('1')
if k==0:
for i in range(n):
print(1)
elif k==1:
pos=x.index('1')
for i in range(n):
if i==pos:
print(0)
else:
if pos==n-1:
print(2)
else:
if i==n-1:
print(2)
else:
print(1)
else:
sum1=0
sum2=0
tmp1=1
tmp2=1
for i in range(n-1,-1,-1):
if x[i]=='1':
sum1+=tmp1
sum1%=k+1
sum2+=tmp2
sum2%=k-1
tmp1*=2
tmp1%=k+1
tmp2*=2
tmp2%=k-1
for i in range(n):
if x[i]=='0':
tmp=sum1+pow(2,n-i-1,k+1)
tmp%=k+1
print(moves[tmp]+1)
else:
tmp=sum2-pow(2,n-i-1,k-1)
tmp%=k-1
print(moves[tmp]+1) | 0 | null | 16,430,656,458,110 | 154 | 107 |
N,A,B = map(int,input().split())
if N % (A+B) > A:
C = A
elif N % (A+B) <= A:
C = N % (A+B)
print((N//(A+B))*A + C)
| N, A, B = map(int, input().split())
q, r = divmod(N, A + B)
print(q * A + min(A, r))
| 1 | 55,347,618,620,580 | null | 202 | 202 |
def main():
n, k = map(int, input().split())
results = tuple(map(int, input().split()))
for i in range(n-k):
print('Yes' if results[i] < results[i+k] else 'No')
if __name__ == '__main__':
main()
| #!/usr/bin/python
s=raw_input()
p=raw_input()
s+=s
print "Yes" if p in s else "No" | 0 | null | 4,406,804,804,490 | 102 | 64 |
import math
r = [float(x) for x in input().split()]
print("{0:f} {1:f}".format(r[0] * r[0] * math.pi, r[0] * 2 * math.pi)) | if __name__ == "__main__":
from decimal import Decimal
r = Decimal(raw_input())
pi = Decimal("3.14159265358979")
print "{0:.6f} {1:.6f}".format( r * r * pi, 2 * r * pi) | 1 | 630,261,420,610 | null | 46 | 46 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, AS):
for i in range(K, N):
# debug("i: i,AS[i-K],AS[K]", i, AS[i-K], AS[K])
if AS[i - K] < AS[i]:
print("Yes")
else:
print("No")
def main():
# parse input
N, K = map(int, input().split())
AS = list(map(int, input().split()))
solve(N, K, AS)
# tests
T1 = """
5 3
96 98 95 100 20
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
Yes
No
"""
T3 = """
15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
Yes
Yes
No
Yes
Yes
No
Yes
Yes
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
| n, k = map(int, input().split())
l = list(map(int, input().split()))
start = k
c = 0
for i in range(n-k):
if l[start]>l[c]:
print("Yes")
else:
print("No")
start+=1
c+=1 | 1 | 7,116,915,192,702 | null | 102 | 102 |
import itertools
n,k = map(int, input().split())
di = [0] * k
Ai_di = []
for i in range(k):
di[i] = int(input())
Ai_di.append(list(map(int, input().split())))
ans_set = set(list(itertools.chain.from_iterable(Ai_di)))
print(n - len(ans_set)) | def resolve():
N, K = list(map(int, input().split()))
snacks = [0 for _ in range(N)]
for i in range(K):
d = int(input())
A = list(map(int, input().split()))
for a in A:
snacks[a-1] += 1
cnt = 0
for s in snacks:
if s == 0:
cnt += 1
print(cnt)
if '__main__' == __name__:
resolve() | 1 | 24,544,285,592,948 | null | 154 | 154 |
n = int(input())
s, t = input().split()
ans = ''
for si, ti in zip(s, t):
ans += si + ti
print(ans) | n = int(input())
s,t = input().split(" ")
res = ""
for i in range(n):
res = res + s[i] + t[i]
print(res) | 1 | 112,061,447,366,960 | null | 255 | 255 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
A = [(A[i], i) for i in range(N)]
A_sort = sorted(A,reverse = True)
dp = [-float('inf')]*(N+1)
dp[0] = 0
for i in range(N):
dp_new = [-float('inf')]*(N+1)
pi = A_sort[i][1] #もともといた場所
for l in range(i+1):
r = i - l #右を選んだ回数
dp_new[l+1] = max(dp_new[l+1],dp[l] + A_sort[i][0] * (pi-l))
dp_new[l] = max(dp_new[l],dp[l] + A_sort[i][0] * ((N-r-1)-pi))
dp = dp_new
print(max(dp)) | import sys
input = sys.stdin.readline
N = int(input())
A = list(zip(list(map(int, input().split())), range(N)))
A.sort(reverse=True)
dp = [[0] * (N+1) for _ in range(N+1)]
for i in range(1, N+1):
a, k = A[i-1]
dp[i][0] = dp[i-1][0] + a * abs(N-i-k)
for j in range(1, i):
dp[i][j] = max(dp[i-1][j] + a * abs(N-(i-j)-k), dp[i-1][j-1] + a * abs(j-1-k))
dp[i][i] = dp[i-1][i-1] + a * abs(i-1-k)
print(max(dp[N])) | 1 | 33,666,914,392,330 | null | 171 | 171 |
a, b, c = map(int, input().split())
k = int(input())
ans = 0
for i in range(10**5):
if a < b*(2**i):
b = b*(2**i)
break
ans += 1
for i in range(10**5):
if b < c*(2**i):
break
ans += 1
if ans <= k:
print('Yes')
else:
print('No') | # ABC159
# String Palindrome
S = input()
n = len(S)
n
m = int(((n - 1)/2)-1)
l = int(((n + 3)/2)-1)
if S[::1] == S[::-1]:
if S[:m+1:] == S[m::-1]:
if S[l::] == S[:l-1:-1]:
print('Yes')
exit()
print('No') | 0 | null | 26,586,219,464,792 | 101 | 190 |
import math
def resolve():
H, W = [int(i) for i in input().split()]
if H==1 or W==1:
print(1)
else:
print(math.ceil(H*W/2))
resolve() | def main():
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = sum(a)
ans = 0
for i in range(n):
s -= a[i]
ans = (ans + a[i] * s) % mod
print(ans)
main() | 0 | null | 27,470,247,796,908 | 196 | 83 |
n = int(input())
cnt = 0
mx = -1
ps = []
for _ in range(n):
d1,d2 = map(int, input().split())
ps.append((d1,d2))
ps.append((1,2))
for d1,d2 in ps:
if d1 != d2:
mx = max(mx,cnt)
cnt = 0
else:
cnt += 1
print("Yes" if mx>=3 else "No")
| from math import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def div3(a,b):
c1=(2*a+b)/3
c2=(a+2*b)/3
return [c1,c2]
def main():
n=int(input())
xy=[[0,0],[100,0]]
#aa=list(map(int, input().split()))
for _ in range(n):
nxy=[[0,0]]
for [x0,y0],[x4,y4] in zip(xy,xy[1:]):
x1,x3=div3(x0,x4)
y1,y3=div3(y0,y4)
a=((x3-x1)**2+(y3-y1)**2)**0.5
rad=atan2(y3-y1,x3-x1)
x2=x1+a*cos(rad+pi/3)
y2=y1+a*sin(rad+pi/3)
nxy+=[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
xy=nxy
for x,y in xy:
print(x,y)
main()
| 0 | null | 1,302,903,479,020 | 72 | 27 |
# coding: utf-8
x,y=map(int,input().split())
while not(x==0 and y==0):
if x>y:
x,y=y,x
print(str(x)+" "+str(y))
x,y=map(int,input().split()) | import sys
sys.setrecursionlimit(700000)
def s_in():
return input()
def n_in():
return int(input())
def l_in():
return list(map(int, input().split()))
def print_l(l):
print(' '.join(map(str, l)))
class Interval():
def __init__(self, li):
self.li = li
self.n = len(li)
self.sum_li = [li[0]]
for i in range(1, self.n):
self.sum_li.append(self.sum_li[i-1] + li[i])
def sum(self, a, b=None):
if b is None:
return self.sum(0, a)
res = self.sum_li[min(self.n-1, b-1)]
if a > 0:
res -= self.sum_li[a-1]
return res
n = s_in()
k = n_in()
res = 0
d = len(n)
def comb(a,b):
if b == 0:
return 1
if b == 1:
return a
if b == 2:
return a*(a-1)//2
if b == 3:
return (a)*(a-1)*(a-2)//6
return 0
# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数
def calc(i, l):
m = int(n[i])
if i == d-1:
if l == 0:
if m == 0:
return 1
else:
return 0
elif l == 1:
if m == 0:
return 0
else:
return m
else:
return 0
if m == 0:
return calc(i+1, l)
else:
tmp = calc(i+1, l-1) # i桁めがmの場合
tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
tmp += comb(d-i-1,l)*int(9**l)
return tmp
print(calc(0,k))
| 0 | null | 38,019,794,119,252 | 43 | 224 |
n,k = map(int,input().split())
count=0
l= list(map(int,input().split()))
for i in range(len(l)):
if l[i]>=k:
count=count+1
print(count) | n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort(reverse=1)
ans=0
for i in h:
if i>=k:ans+=1
print(ans)
| 1 | 178,635,364,403,288 | null | 298 | 298 |
x,y=map(int,input().split())
while x%y!=0:
tmp=y
y=x%y
x=tmp
print(y)
| 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
K,N=MI()
A=LI()
S=sum(A)
L=[]
for i in range(N-1):
temp=A[i+1]-A[i]
L.append(temp)
L.append(A[0]+K-A[-1])
M=max(L)
print(K-M)
main()
| 0 | null | 21,747,691,391,712 | 11 | 186 |
import math
import numpy as np
N = int(input())
N_half = math.floor(N/2)
counts = 0
for i in np.arange(1, N):
j = N-i
if(i != j ):
counts += 1
print(int(counts/2)) | import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
S = SS()
len_S = len(S)
ans = 0
for i in range(len_S // 2):
if S[i] != S[len_S-1-i]:
ans += 1
print(ans)
if __name__ == '__main__':
resolve()
| 0 | null | 136,617,616,507,090 | 283 | 261 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.