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,K=map(int,input().split())
ans=0
while N>=K**ans:
ans+=1
print(ans) | S = input()
for i in range(1, 6):
if S == 'hi' * i:
print('Yes')
exit()
print('No') | 0 | null | 58,798,848,701,438 | 212 | 199 |
import sys
input = sys.stdin.readline
n = int(input())
s, t = list(map(list, input().split()))
a = ""
for i in range(n):
a += s[i]
a += t[i]
print(a)
| h1 , m1 , h2 , m2 , k = map(int,input().split())
if m2 >= m1:
time = (h2 - h1)*60 + m2 - m1
elif m2 < m1:
time = (h2 - h1 - 1) * 60 + m2 + 60 - m1
print(time-k) | 0 | null | 65,313,707,822,886 | 255 | 139 |
n = int(input())
strList = []
timeList = []
for x in range(n):
s, t = map(str, input().split())
strList.append(s)
timeList.append(int(t))
x = input()
id = strList.index(x)
if timeList.count == id: print(0)
else: print(sum(timeList[id + 1:])) | n = int(input())
S = []
T = []
for _ in range(n):
s, t = input().split()
S.append(s)
T.append(int(t))
x = input()
index = S.index(x)
if index == n - 1:
print(0)
else:
print(sum(T[index+1:]))
| 1 | 97,194,488,987,090 | null | 243 | 243 |
# AtCoder Beginner Contest 148
# D - Brick Break
N=int(input())
a=list(map(int,input().split()))
targetnum=1
breaknum=0
for i in range(N):
if a[i]==targetnum:
targetnum+=1
else:breaknum+=1
if breaknum==N:
print(-1)
else:
print(breaknum)
| n=int(input())
a=list(map(int,input().split()))
ct=0
for i in range(n):
if a[i]==(ct+1):
ct+=1
if ct==0:
print('-1')
else:
print(n-ct) | 1 | 114,806,286,693,768 | null | 257 | 257 |
n, m, l = map(int, input().split())
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [list(map(int, input().split())) for i in range(m)]
mul_matrix_a_b = [[sum([matrix_a[i][k] * matrix_b[k][j] for k in range(m)]) for j in range(l)] for i in range(n)]
for result in mul_matrix_a_b:
print(*result) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k, *a = map(int, read().split())
def isOK(x):
kaisu = 0
for ae in a:
kaisu += ceil(ae / x) - 1
if kaisu <= k:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| 0 | null | 3,942,336,867,424 | 60 | 99 |
#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) | import sys
args = input()
print(args[:3]) | 0 | null | 55,603,000,613,600 | 243 | 130 |
n = int(input())
stocks = [int(x) for x in input().split()]
mymoney = 1000
mystock = 0
for i in range(0,len(stocks)-1): # コメントアウト部分はデバッグ用コード
#print(stocks[i],stocks[i+1],end=":")
if stocks[i] < stocks[i+1]: # 明日の方が株価が高くなる場合は、今日のうちに株を買えるだけ買う
#print("buying",end=" ")
mystock += mymoney//stocks[i]
mymoney = mymoney%stocks[i]
elif stocks[i] >= stocks[i+1]: # 明日の方が株価が安くなる場合には、今日のうちに手持ちの株を売却
#print("selling",end=" ")
mymoney += mystock*stocks[i]
mystock = 0
#print(mymoney,mystock)
i += 1
mymoney += mystock * stocks[i] # 最終日に手持ちの株をすべて売却して現金化
mystock = 0
print(mymoney) | print(*sorted(input().split())) | 0 | null | 3,860,422,329,660 | 103 | 40 |
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def bisearch_max(mn, mx, func):
""" 条件を満たす最大値を見つける二分探索 """
ok = mn
ng = mx
while ok+1 < ng:
mid = (ok+ng) // 2
if func(mid):
# 上を探しに行く
ok = mid
else:
# 下を探しに行く
ng = mid
return ok
T1, T2 = MAP()
A1, A2 = MAP()
B1, B2 = MAP()
# a,bの状態からT1,T2の操作を行った後のa,bと、この操作での交差回数を返す
def calc(a, b):
cnt = 0
a1 = a + T1 * A1
b1 = b + T1 * B1
if a > b and a1 <= b1 or a < b and a1 >= b1:
cnt += 1
a2 = a1 + T2 * A2
b2 = b1 + T2 * B2
if a1 > b1 and a2 <= b2 or a1 < b1 and a2 >= b2:
cnt += 1
return a2, b2, cnt
# x+1回目の操作でまだ交差するか
def check(x):
a = (T1 * A1 + T2 * A2) * x
b = (T1 * B1 + T2 * B2) * x
_, _, cnt = calc(a, b)
return cnt >= 1
# 初回で同値に飛んだらその先もずっと繰り返す
a, b, cnt = calc(0, 0)
if a == b:
print('infinity')
exit()
# 最後に交差する直前までの操作回数を調べる
res = bisearch_max(-1, 10**18, check)
# 初回でも交差しなければ0
if res == -1:
print(0)
exit()
# 直前までの操作では、初回は1回、以降は2回ずつ交差する
ans = max(0, res * 2 - 1)
# 最後に交差する直前までa,bを移動させる
a = (T1 * A1 + T2 * A2) * res
b = (T1 * B1 + T2 * B2) * res
# 最後が1回か2回か確認
_, _, cnt = calc(a, b)
ans += cnt
print(ans)
| T1,T2= map(int, input().split())
A1,A2= map(int, input().split())
B1,B2= map(int, input().split())
if A1>B1 and A2>B2:
print(0)
elif A1<B1 and A2<B2:
print(0)
elif T1*A1+T2*A2==T1*B1+T2*B2:
print('infinity')
elif A1>B1 and A2<B2:
if T1*A1+T2*A2>T1*B1+T2*B2:
print(0)
else:
se=abs(T1*A1+T2*A2-(T1*B1+T2*B2))
ad=T1*A1-T1*B1
d=-(-ad//se)
ans=2*d-1
if ad%se==0:
ans+=1
print(ans)
elif A1<B1 and A2>B2:
if T1*A1+T2*A2<T1*B1+T2*B2:
print(0)
else:
se=abs(T1*A1+T2*A2-(T1*B1+T2*B2))
ad=T1*B1-T1*A1
d=-(-ad//se)
ans=2*d-1
if ad%se==0:
ans+=1
print(ans)
| 1 | 131,991,313,084,770 | null | 269 | 269 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A
import sys
nums_len = int(sys.stdin.readline())
nums_str = sys.stdin.readline().split(' ')
nums = map(int, nums_str)
print ' '.join(map(str, nums))
for i in range(1, nums_len):
for j in reversed(range(1, i + 1)):
if nums[j] < nums[j - 1]:
v = nums[j]
nums[j] = nums[j - 1]
nums[j - 1] = v
print ' '.join(map(str, nums)) | N,K = map(int,input().split())
RST = list(map(int,input().split()))
#r:0 s:1 p:2
# a mod K != b mod Kならばaとbは独立に選ぶことができる。
# よってN個の手をmod KによるK個のグループに分け、各グループにおける最大値を求め、最終的にK個のグループの和が答え
T = [0 if i=="r" else 1 if i=="s" else 2 for i in input()]
dp = [[0]*3 for i in range(N)]
#直後の手を見て決める
for i in range(N):
if i<K:
for j in range(3):
# j:1,2,0
# j==0 -> RST[0]
#初期値は勝つ手を出し続ける
if (j+1)%3==T[i]:
dp[i][j]=RST[j]
else:
#現在の出す手
for j in range(3):
#K回前に出した手
for l in range(3):
if j!=l:
if (j+1)%3 == T[i]:
dp[i][j] = max(dp[i][j],RST[j]+dp[i-K][l])
else:
dp[i][j] = max(dp[i][j],dp[i-K][l])
ans = 0
for i in range(N-K,N):
ans += max(dp[i])
print(ans) | 0 | null | 53,198,253,924,818 | 10 | 251 |
import math
A, B, H, M = map(int, input().split())
X, Y = A*math.cos(math.pi*(60*H+M)/360), -A*math.sin(math.pi*(60*H+M)/360)
x, y = B*math.cos(math.pi*M/30), -B*math.sin(math.pi*M/30)
print(math.sqrt((X-x)**2+(Y-y)**2)) | N = int(input())
r, mod = divmod(N, 2)
print(r - 1 + mod) | 0 | null | 86,464,876,807,710 | 144 | 283 |
import sys
input = sys.stdin.readline
def main():
N, M = map(int, input().split())
c = list(map(int, input().split()))
dp = [i+100 for i in range(N+1)]
dp[0] = 0
for i in range(1, N+1):
for t in c:
if i - t >= 0:
dp[i] = min(dp[i], dp[i-t] + 1)
# print(dp)
print(dp[N])
if __name__ == "__main__":
main()
| n = int(input())
line = []
for _ in range(n):
x, l = map(int, input().split())
s, g = x-l, x+l
line.append([g, s])
line.sort()
ans = 1
now_g = line[0][0]
for g, s in line[1:]:
if now_g <= s:
ans += 1
now_g = g
print(ans)
| 0 | null | 44,820,816,868,800 | 28 | 237 |
from functools import reduce
n,a,b=map(int,input().split())
mod=10**9+7
def nCk(n,k):
c=reduce(lambda x,y: x*y%mod, range(n,n-k,-1))
m=reduce(lambda x,y: x*y%mod, range(1,k+1))
return c*pow(m,mod-2,mod)%mod
all=pow(2,n,mod)
nCa=nCk(n,a)
nCb=nCk(n,b)
print((all-nCa-nCb-1)%mod) | n, a, b = map(int, input().split())
mod = 10**9 + 7
ans = pow(2, n, mod)
ans -= 1
aa = 1
for i in range(1, a+1):
aa = (aa * (n - i + 1) * pow(i, -1, mod)) % mod
bb = 1
for i in range(1, b+1):
bb = (bb * (n - i + 1) * pow(i, -1, mod)) % mod
ans = (ans - aa - bb) % mod
print(ans) | 1 | 66,124,585,822,962 | null | 214 | 214 |
# coding: utf-8
def main():
_ = int(input())
A = list(map(int, input().split()))
ans = 0
tmp = 0
total = sum(A)
for a in A:
tmp += a
if tmp >= total // 2:
ans = min(2 * tmp - total, total - 2 * (tmp - a))
break
print(ans)
if __name__ == "__main__":
main()
| # -*- coding: utf-8 -*-
import sys
import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque
#input = stdin.readline
j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"
#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
print(number_list[i-1])#
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
x=[]
y=[]
for i in range(N):
x1, y1=[int(i) for i in input().split()]
x.append(x1)
y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''
'''
mixlist=[]
for i in range(N):
a,b=input().split()
mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ,今回はリスト一つで処理している"
'''
'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''
#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]
print(type(N))
print(N)
print(type(M))
print(M)
print(type(table))
print(table)
'''
#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値.桁ごとに分割したい.入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''
'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''
'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''
#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"
#a,b=map(int, input().split()) #int style 複数数値入力 「A B」みたいなスペース空いた入力のとき
#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成
##############################################################################################
##############################################################################################
#under this line explains example calculation
'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''
#nCr combination
'''
def cmb(n,r):
#When n < r , this function isn't valid
r= min(n-r,r)
#print(n,r)
if r == 0: return 1
over = reduce(mul, range(n, n-r, -1))
#flochart mul(n,n-1)=x
#next mul(x,n-2)........(n-r+1,n-r)
#mul read a,b and returns a*b
under = reduce(mul, range(1, r+1))
#print(over, under)
#reduce is applied mul(1,2)=2
#next mul(2,3)=6
#next mul(6,4)=4.........last(r!,r+1)=r+1!
return over // under
#// is integer divide
#calc example 5C2
#over=5*4*3
#under=3*2*1
a = cmb(n, r)
#print(a)
'''
'''
import itertools
from itertools import combinations_with_replacement
combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし
combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり
使用例 出力
combinations('ABCD', 2) AB AC AD BC BD CD
combinations_with_replacement('ABCD', 2) AA AB AC AD BB BC BD CC CD DD
'''
'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位n個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
#(1, 6)
#(3, 3)
#(4, 1)
'''
#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''
'''
素数の判定
'''
def is_prime(n):
if n == 1: return False
for k in range(2, int(np.sqrt(n)) + 1):
#sqrt(n)+1以上は考えて約数はないので却下
if n % k == 0:
return False
#割り切れたらFalse
return True
'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります.[1, -2, 3]と0の4つの数字のうち,最も大きい値を出力します.
一方で,[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります.
その時は,numpyのmaximum関数を用います.
xs = np.array([1, -2, 3])
np.maximum(xs, 0) # [1, 0, 3]
'''
########################################################################
########################################################################
#b2=a[:] #1次元のときはコピーはこれで良い
#print(b2)
#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a) #2次元配列はこうコピーする
#print(b3)
def main():
w=1
j=0
k=0
dlen=0
dsum=0
ota=0
n=int(input())
al=list(map(int, input().split(" ")))
dlen=sum(al)
for i in range(n):
dsum=dsum+al[i]
if dsum*2 > dlen:
ota=dsum-al[i]
break
#if dlen//2==0:#2で割り切れる時
# print(abs(dsum-dlen/2))
# sys.exit()
#print(2*dsum,2*ota,dlen)
print(min(abs(2*dsum-dlen),abs(2*ota-dlen)))
#r=int(input())
#dp= [[0]*3 for i in range(5)]#列 行
#dp用の0の入ったやつ
#dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
#print(dp)#初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
exdp=np.zeros((3,4)) # 3×4の2次元配列を生成。2次元ならこう
#dtypeは指定しないとfloatになる
#for i in range(n):#ちょっとした入力に便利
# a, b = map(int, input().split())
#dp[i][0] += [a]
#これだとintとlistをつなぐことになって不適
# dp[i] += [a]
# dp[i] += [b]
#これはうまくいく
#やり方はいろいろあるということ
#print(dp)
"1行1つの整数を入力を取得し、整数と取得する"
#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"
#brray=[list(map(int, input().split(" ")))for i in range(N)
#print(brray)
#s=input()
#a=[int(i) for i in s]#int取るとstrでも行ける
#print(a)
'''
入力
1234
出力
[1, 2, 3, 4]
'''
pin_l=["x" for i in range(10)]#内包表記に慣れろ
#print(pin_l)
ls = ["a", "b", "c", "d", "e"]
#print(ls[2:5])
#スライスでの取得
#print(ls[:-3])
#一番左端から右から3番目より左まで取得
#print(ls[:4:2])
#スライスで1個飛ばしで取得
#ないときは左端スタート
#始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
#print(ls[::2])
'''
lsというリストの場合に、1つ飛びの値を取得したい場合には
ls[::2]
のようにします。こうすると、
["a", "c", "d"]と出力される
'''
if __name__ == "__main__":
main()
| 1 | 141,833,714,365,408 | null | 276 | 276 |
# M-SOLUTIONS プロコンオープン 2020: B – Magic 2
A, B, C = [int(i) for i in input().split()]
K = int(input())
is_success = 'No'
for i in range(K + 1):
for j in range(K + 1):
for k in range(K + 1):
if i + j + k <= K and A * 2 ** i < B * 2 ** j < C * 2 ** k:
is_success = 'Yes'
print(is_success) | # -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())
k = int(input())
count = 0
while a >= b:
b *= 2
count += 1
while b >= c:
c *= 2
count += 1
if count <= k:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 1 | 6,896,855,572,968 | null | 101 | 101 |
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
is_prime = [True] * (n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if not is_prime[i]: continue
for j in range(i * 2, n+1, i): is_prime[j] = False
return is_prime
H,W = imn()
s = [input() for _ in range(H)]
dp = [[INF for _ in range(W)] for _ in range(H)]
dp[0][0] = 0
if s[0][0] == '#': dp[0][0] = 1
for i in range(H):
for j in range(W):
if i+1 < H:
cnt = dp[i][j]
if s[i][j] == "." and s[i+1][j] == "#":
cnt += 1
dp[i+1][j] = min(dp[i+1][j], cnt)
if j+1 < W:
cnt = dp[i][j]
if s[i][j] == "." and s[i][j+1] == "#":
cnt += 1
dp[i][j+1] = min(dp[i][j+1], cnt)
print(dp[-1][-1]) | # -*- coding:utf-8 -*-
A_Bingo = []
for i in range(3):
A_Bingo.append(list(map(int,input().split())))
card =[]
n = int(input())
for k in range(n):
card.append(int(input()))
r_cnt =[0,0,0]
c_cnt =[0,0,0]
rc_result = [[0,0,0],[0,0,0],[0,0,0]]
for row in range(3):
for column in range(3):
if A_Bingo[row][column] in card:
r_cnt[row] += 1
c_cnt[column] += 1
rc_result[row][column] = 1
if 3 in r_cnt:
print("Yes")
elif 3 in c_cnt:
print("Yes")
elif rc_result[0][0]*rc_result[1][1]*rc_result[2][2] == 1:
print("Yes")
elif rc_result[0][2]*rc_result[1][1]*rc_result[2][0] == 1:
print("Yes")
else:
print("No")
| 0 | null | 54,346,314,050,048 | 194 | 207 |
N=int(input())
st=[]
a=0
b=0
for i in range(N):
st.append(list(map(str,input().split())))
X=str(input())
for i in range(N):
if st[i][0]==X:
a=i
for i in range(a+1,N):
b+=int(st[i][1])
print(b) | x, y = map(int, input().split())
msg = 'No'
for a in range(1, x+1):
if 2*a + 4*(x-a) == y or 4*a + 2*(x-a) == y:
msg = 'Yes'
print(msg) | 0 | null | 55,467,959,135,364 | 243 | 127 |
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
N, K = map(int, input().split())
cnt = [0]*N
for _ in range(K):
d = int(input())
for a in list(map(int, input().split())):
a -= 1
cnt[a] += 1
ans = 0
for c in cnt:
ans += c == 0
print(ans)
| 1 | 24,603,227,315,902 | null | 154 | 154 |
H1, M1, H2, M2, K = list(map(int,input().split()))
a = 60*H1 + M1
b = 60*H2 + M2
print(b - a - K) | m = []
while True:
try:
m.append(int(raw_input()))
except EOFError:
break
m.sort()
m.reverse()
for h in m[0:3]:
print h | 0 | null | 9,125,417,544,270 | 139 | 2 |
s=str(input())
t=str(input())
n=len(s)
ans=0
for i in range(n):
if s[i]==t[i]:
ans+=1
print(n-ans) | s=input()
t=input()
l=len(s)
ans=0
for i in range(l):
if s[i]==t[i]:
ans+=1
print(l-ans) | 1 | 10,472,611,242,340 | null | 116 | 116 |
import sys
from decimal import Decimal as D, ROUND_FLOOR
def resolve(in_):
x = D(next(in_))
year = 0
deposit = D('100')
rate = D('1.01')
a = D('1.')
while deposit < x:
year += 1
deposit *= rate
deposit = deposit.quantize(a, rounding=ROUND_FLOOR)
return year
def main():
answer = resolve(sys.stdin)
print(answer)
if __name__ == '__main__':
main() | while True:
i,e,r = map(int,raw_input().split())
if i == e == r == -1:
break
if i == -1 or e == -1 :
print 'F'
elif i+e >= 80 :
print 'A'
elif i+e >= 65 :
print 'B'
elif i+e >= 50 :
print 'C'
elif i+e >= 30 :
if r >= 50 :
print 'C'
else :
print 'D'
else :
print 'F' | 0 | null | 14,045,594,707,618 | 159 | 57 |
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
C = list(input().strip())
counter = Counter(C)
if len(counter) == 1:
print(0)
else:
red_n = counter["R"]
ans = 0
for i in range(N):
if red_n <= i:
break
if C[i] == "W":
ans += 1
print(ans) | n = int(input())
c = input()
count = 0
i, j = 0, n - 1
if c.count('W') == 0:
count=0
elif c.count('R') == 0:
count = 0
else:
white_cnt = []
red_cnt = []
for i in range(n):
if c[i] == 'W':
white_cnt.append(i)
else:
red_cnt.append(i)
while 1:
white_num = white_cnt.pop(0)
red_num = red_cnt.pop()
if white_num < red_num:
count += 1
if len(white_cnt) == 0:
break
if len(red_cnt) == 0:
break
print(count)
| 1 | 6,315,065,131,778 | null | 98 | 98 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n = ri()
L = [0] * (n + 1)
for i in rl():
L[i] += 1
for i in range(1, n + 1):
print (L[i])
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| n, k = map(int, input().split())
lst = [int(i) for i in input().split()]
tele_lst = []
town_set = set()
town = 1
while True:
if town not in town_set:
tele_lst.append(town)
town_set.add(town)
else:
break
town = lst[town - 1]
ind = tele_lst.index(town)
length = len(town_set)
circle = length - ind
#print(ind, length)
#print(tele_lst)
if k < ind:
town = tele_lst[k]
print(town)
else:
k -= ind
k %= circle
#print(k)
town = tele_lst[ind + k]
print(town) | 0 | null | 27,508,695,377,058 | 169 | 150 |
#入力
n, u, v = map(int, input().split())
mapdata = [list(map(int,input().split())) for _ in range(n-1)]
#グラフ作成
graph = [[] for _ in range(n+1)]
for i, j in mapdata:
graph[i].append(j)
graph[j].append(i)
#探索
def dfs(v):
dist = [-1] * (n + 1)
stack = [v]
dist[v] = 0
while stack:
v = stack.pop()
dw = dist[v] + 1
for w in graph[v]:
if dist[w] >= 0:
continue
dist[w] = dw
stack.append(w)
return dist
du, dv = dfs(u), dfs(v)
ans = 0
for u, v in zip(du[1:], dv[1:]):
if u < v:
x = v-1
if ans < x:
ans = x
print(ans) | from collections import deque
N,u,v = map(int,input().split())
root = [[] for i in range(N)]
for _ in range(N-1):
a, b = (int(x) for x in input().split())
root[b-1].append(a-1)
root[a-1].append(b-1)
def search(p):
stack=deque([p])
check = [-1]*N
check[p] = 0
while len(stack)>0:
v = stack.popleft()
for i in root[v]:
if check[i] == -1:
check[i]=check[v]+1
stack.append(i)
return check
taka = search(u-1)
aoki = search(v-1)
ans = 0
for i in range(N):
if taka[i] < aoki[i]:
ans = max(ans, aoki[i]-1)
print(ans) | 1 | 117,637,238,556,820 | null | 259 | 259 |
H=int(input())
def n_attack(h):
if h==1:return(1)
else:return 1+2*n_attack(h//2)
print(n_attack(H)) | H = int(input())
cnt = 0
while H != 0:
H //= 2
cnt += 1
print(2**cnt-1) | 1 | 79,978,834,659,412 | null | 228 | 228 |
#!/usr/bin/env python3
import math
x = int(input())
while True:
key=1
for k in range(2, int(math.sqrt(x)) + 1):
if x % k == 0:
key=0
if key==1:
print(x)
exit()
else:
x += 1
print(x) | import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
a,b=map(str,input().split())
print(int(a*int(b)) if int(a)<=int(b) else int(b*int(a))) | 0 | null | 95,043,832,068,448 | 250 | 232 |
S = input()
if str.islower(S):
print('a')
else:
print('A')
exit()
| pictures = ['S','H','C','D']
card_li = []
for i in range(4):
for j in range(1,14):
card_li.append(pictures[i] + ' ' + str(j))
n = int(input())
for i in range(n): del card_li[card_li.index(input())]
for i in card_li:
print(i) | 0 | null | 6,258,157,852,620 | 119 | 54 |
import io
import sys
import math
def solve():
A, B, H, M = list(map(int, input().split()))
C_sq = A**2 + B**2 - 2*A*B*math.cos((H - 11/60 * M)*math.pi/6)
C = math.sqrt(C_sq)
print(C)
if __name__ == "__main__":
solve() | import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
@lru_cache(maxsize=None)
def f(x):
if x < 0:
return False
if (x%100==0) or (x%101==0) or (x%102==0) \
or (x%103==0) or (x%104==0) or (x%105==0):
return True
return f(x-100) or f(x-101) or f(x-102) \
or f(x-103) or f(x-104) or f(x-105)
def main():
X = ii()
print(1 if f(X) else 0)
if __name__ == '__main__':
main() | 0 | null | 73,891,137,612,226 | 144 | 266 |
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter
if D[0] != 0:
print(0)
exit(0)
cd = Counter(D)
if cd[0] != 1:
print(0)
exit(0)
tmp = sorted(cd.items(), key=lambda x: x[0])
ans = 1
for kx in range(1, max(D)+1):
ans *= pow(cd[kx-1], cd[kx],M)
ans %= M
print(ans)
| # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
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")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def solve(h, w, k, board):
ans = 0
for row in range(1 << h):
for col in range(1 << w):
count = 0
for i in range(h):
for j in range(w):
if (row >> i) & 1 == 0:
continue
if (col >> j) & 1 == 0:
continue
if board[i][j] == '#':
count += 1
if count == k:
ans += 1
return ans
h, w, k = map(int, input().split())
board = []
for i in range(h):
board += [list(input())]
print(solve(h, w, k, board))
| 0 | null | 82,077,366,795,958 | 284 | 110 |
from collections import defaultdict
H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]
d1 = defaultdict(int)
d2 = defaultdict(int)
b = defaultdict(int)
for h, w in hw:
d1[h] += 1
d2[w] += 1
b[(h, w)] = 1
m1 = max(d1.values())
m2 = max(d2.values())
e1 = [k for k in d1.keys() if d1[k] == m1]
e2 = [k for k in d2.keys() if d2[k] == m2]
flag = True
for x in e1:
for y in e2:
if b[(x, y)] == 1:
pass
else:
flag = False
break
if not flag:
break
if flag:
print(m1+m2-1)
else:
print(m1+m2) | H = int(input())
W = int(input())
N = int(input())
a = max(H, W)
print(N // a + min(1, N % a))
| 0 | null | 46,694,857,457,868 | 89 | 236 |
a,b = input().split()
a = int(a)
b = int(b)
if a >= 10 or b >=10:
print ('-1')
else:
print (a * b) | i = 1
while True:
a = raw_input()
if a == '0':
break
print "Case %d: %s" % (i,a)
i = i + 1 | 0 | null | 79,539,370,894,330 | 286 | 42 |
H,N=map(int,input().split())
print("NYoe s"[H<=sum(map(int,input().split()))::2]) | H, N = map(int,input().split())
special_move = list(map(int,input().split()))
if H <= sum(special_move):
result = 'Yes'
else:
result = 'No'
print(result) | 1 | 78,427,807,032,896 | null | 226 | 226 |
S = input()
kuri = False
ans = 0
for i in range(len(S)-1, -1, -1):
K = int(S[i])
if kuri:
K += 1
kuri = False
if K < 5:
ans += K
elif K > 5:
ans += (10-K)
kuri = True
elif K == 5:
if i > 0:
M = int(S[i-1])
if i != 0 and M >= 5:
kuri = True
ans += 5
if i == 0 and kuri:
ans += 1
print(ans)
| import sys
num = int(sys.stdin.readline())
print(num**3) | 0 | null | 35,408,468,428,122 | 219 | 35 |
import math
A, B, H, M = map(int,input().split())
h = 30*H + (0.5)*M
m = 6*M
C = abs(h-m)
X = math.sqrt(A**2 + B**2 -(2*A*B*(math.cos(math.radians(C)))))
print(X) | N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
dp=[0]*N
data={'r':P,'s':R,'p':S}
ans=0
for i in range(N):
if 0<=i-K:
if T[i-K]==T[i]:
if dp[i-K]==0:
ans+=data[T[i]]
dp[i]=1
else:
ans+=data[T[i]]
dp[i]=1
else:
dp[i]=1
ans+=data[T[i]]
print(ans) | 0 | null | 63,285,442,793,772 | 144 | 251 |
s, t = input().split()
a, b = map(int,input().split())
u = input()
if s == u:
print(a - 1, b)
elif t == u:
print(a, b - 1)
| s,t,a,b,u=open(0).read().split()
if s==u:
print(int(a)-1,b)
elif t==u:
print(a,int(b)-1) | 1 | 71,710,976,383,100 | null | 220 | 220 |
import itertools
from typing import List
def main():
h, w, k = map(int, input().split())
c = []
for _ in range(h):
c.append(list(input()))
print(hv(c, h, w, k))
def hv(c: List[List[str]], h: int, w: int, k: int) -> int:
ret = 0
for comb_h in itertools.product((False, True), repeat=h):
for comb_w in itertools.product((False, True), repeat=w):
cnt = 0
for i in range(h):
for j in range(w):
if comb_h[i] and comb_w[j] and c[i][j] == '#':
cnt += 1
if cnt == k:
ret += 1
return ret
if __name__ == '__main__':
main()
| # import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal
from functools import reduce
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
H, W, k = input_list()
maze = [list(input()) for _ in range(H)]
ans = 0
for row_bit in itertools.product(range(2), repeat=H):
for col_bit in itertools.product(range(2), repeat=W):
cnt = 0
for row in range(H):
for col in range(W):
if maze[row][col] == "#" and (row_bit[row] and col_bit[col]):
cnt += 1
if cnt == k:
ans += 1
print(ans)
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
def bfs(H, W, black_cells, dist):
d = 0
while black_cells:
h, w = black_cells.popleft()
d = dist[h][w]
for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
new_h = h + dy
new_w = w + dx
if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
continue
if dist[new_h][new_w] == -1:
dist[new_h][new_w] = d + 1
black_cells.append((new_h, new_w))
return d
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 1 | 8,933,055,027,918 | null | 110 | 110 |
A,B,N=map(int,input().split())
def func(t):
return int(t)
#NはBより大きいかもしれないし小さいかもしれない
#B-1が最高だが、NがB-1より小さいとどうしようもない
x=min(B-1,N)
print(func(A*x/B)-A*func(x/B)) | n,t = map(int,input().split())
l = []
for i in range(n):
a,b = map(int,input().split())
l.append([a,b])
l.sort(key=lambda x:x[0])
dp = [[0 for i in range(t)] for i in range(n+1)]
al = []
for i in range(n):
a,b = l[i]
for j in range(t):
if dp[i][j] == 0:
if j == 0:
if j + a < t:
dp[i+1][j+a] = max(dp[i][j+a],b)
else:
al.append(b)
else:
if j + a < t:
dp[i+1][j+a] = max(dp[i][j+a],dp[i][j]+b)
else:
al.append(dp[i][j]+b)
dp[i+1][j] = max(dp[i+1][j],dp[i][j])
if len(al) > 0:
print(max(max(dp[n]),max(al)))
else:
print(max(dp[n])) | 0 | null | 89,571,816,532,572 | 161 | 282 |
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k):
B = [0]*n
for j in range(n):
l = max(0, j-A[j])
r = j + A[j] + 1
B[l] += 1
if r <= n-1: B[r] -= 1
is_same = True
for j in range(n-1):
B[j+1] = B[j+1] + B[j]
if B[j+1] != n: is_same = False
if is_same: break
A = B
print(*B,sep=' ')
|
import numpy as np
from numba import njit
import math
n,k = map(int,input().split())
a = np.array(input().split(),np.int64)
@njit
def solve(n,k,a):
for i in range(k):
new = np.zeros_like(a)
for j in range(n):
distance = j - a[j]
if distance < 0:
distance = 0
last = j + a[j]
if last > n-1:
last = n-1
new[distance]+=1
if last+1 < n:
new[last+1]-=1
a = np.cumsum(new)
if np.all(a==n):
break
return a
a = solve(n,k,a)
print(" ".join(a.astype(str))) | 1 | 15,479,380,685,922 | null | 132 | 132 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
d=[0 for i in range(pow(10,5)+1)]
s=sum(a)
for i in range(n):
d[a[i]]+=1
for i in range(q):
s+=(bc[i][1]-bc[i][0])*d[bc[i][0]]
print(s)
d[bc[i][1]]+=d[bc[i][0]]
d[bc[i][0]]=0
| n = int(input())
al = list(map(int, input().split()))
num_cnt = {}
c_sum = 0
for a in al:
num_cnt.setdefault(a,0)
num_cnt[a] += 1
c_sum += a
ans = []
q = int(input())
for _ in range(q):
b,c = map(int, input().split())
num_cnt.setdefault(b,0)
num_cnt.setdefault(c,0)
diff = num_cnt[b]*c - num_cnt[b]*b
num_cnt[c] += num_cnt[b]
num_cnt[b] = 0
c_sum += diff
ans.append(c_sum)
for a in ans:
print(a) | 1 | 12,184,016,251,840 | null | 122 | 122 |
def judge(k, N, A):
p = N - 1
t = 0
for i in A:
while p >= 0 and A[p] + i < k:
p -= 1
t += (p + 1)
return t
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
t = A[0] * 2
b = 0
X = None
while t - b > 1:
m = (t + b)//2
i = judge(m, N, A)
if i == M:
X = m
break
if i > M:
ip = judge(m + 1, N, A)
if ip == M:
X = m + 1
break
if ip < M:
X = m
break
b = m + 1
if i < M:
im = judge(m - 1, N, A)
if im >= M:
X = m - 1
break
t = m - 1
if X is None:
X = b
r = 0
p = N - 1
k = sum(A)
for i in A:
while p >= 0 and A[p] + i < X :
k -= A[p]
p -= 1
r += i * (p + 1) + k
return r - (judge(X, N, A) - M) * X
print(main())
| n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
s = [0]
for ai in a:
s.append(ai + s[-1])
def count(x, accum=False):
ret = 0
for ai in a:
lo, hi = -1, n
while hi - lo > 1:
mid = (lo + hi) // 2
if ai + a[mid] >= x:
lo = mid
else:
hi = mid
ret += ai * hi + s[hi] if accum else hi
return ret
lo, hi = 0, 1000000000
while hi - lo > 1:
mid = (lo + hi) // 2
if count(mid) >= m:
lo = mid
else:
hi = mid
print(count(lo, accum=True) - (count(lo) - m) * lo)
| 1 | 108,046,615,190,478 | null | 252 | 252 |
import math
A, B, H, M = map(int, input().split())
a = math.pi/360 * (H*60 + M)
b = math.pi/30 * M
# if abs(a - b) > math.pi:
# theta = 2 * math.pi - abs(a-b)
# else:
theta = abs(a-b)
L = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(L) | import sys
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
minimum = sys.maxint
maximum = -sys.maxint - 1
for x in R:
p = x - minimum
if maximum < p:
maximum = p
if minimum > x:
minimum = x
print maximum | 0 | null | 9,962,890,136,618 | 144 | 13 |
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[0] * w for _ in range(h)]
start = 0
x = 1
cnt = 0
def sol(ans, s, x):
cnt = 0
start = 0
for i in range(len(s)):
if s[i].count("#") != 0:
y = i
break
for i in range(w):
if s[y][i] == "#":
cnt += 1
if i == w - 1 or (cnt == 1 and s[y][i + 1] == "#"):
for a in range(len(s)):
for b in range(start, i + 1):
ans[a][b] = x
start = i + 1
x += 1
cnt = 0
return x
for i in range(h):
if s[i].count("#") >= 1:
cnt += 1
if i == h - 1 or cnt == 1 and s[i + 1].count("#") >= 1:
x = sol(ans[start: i + 1], s[start: i + 1], x)
start = i + 1
cnt = 0
for i in range(h):
for j in range(w):
print(ans[i][j], end = " ")
print() | n = int(input())
MOD = int(1e9 + 7)
a, b, c = 1, 1, 1
for i in range(n):
a *= 10;
b *= 9;
c *= 8;
a %= MOD;
b %= MOD;
c %= MOD;
print((a - 2 * b + c) % MOD); | 0 | null | 73,202,447,693,188 | 277 | 78 |
N = int(input())
words = list(input())
ct_R = words.count('R')
ct_W = words.count('W')
a = words[0:ct_R]
W_in_a_count = a.count('W')
print(W_in_a_count)
| n = int(input())
ccc = input()
cnt_r = ccc.count('R')
ans = 0
for i in range(cnt_r):
if ccc[i] == 'W':
ans += 1
print(ans) | 1 | 6,321,341,658,772 | null | 98 | 98 |
sen = input()
n = int(input())
for i in range(n):
cmd = input().split()
sta = int(cmd[1])
end = int(cmd[2])
if cmd[0] == 'replace':
sen = sen[0:sta] + cmd[3] + sen[end+1:]
elif cmd[0] == 'reverse':
rev = sen[sta:end+1]
rev = rev[::-1]
# print(rev)
sen = sen[0:sta] + rev +sen[end+1:]
elif cmd[0] == 'print':
print(sen[sta:end+1])
# print('sen : '+sen) | import math
import fractions
import collections
import itertools
from collections import deque
S=input()
N=len(S)
cnt=0
l=[]
"""
cnt=0
p=10**9+7
for i in range(K,N+2):
cnt=(cnt+((N-i+1)*i)+1)%p
#print(((N-i+1)*i)+1)
print(cnt)
"""
amari=[0]*(N+1)
num=0
for i in range(N):
num=num+pow(10,i,2019)*int(S[N-1-i])
amari[i+1]=num%2019
#print(amari)
c=collections.Counter(amari)
values=list(c.values()) #aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys()) #先のvalue値に相当する要素のリスト(要素1,要素2,…)
#for i in range(len(key)):
# l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt) | 0 | null | 16,346,648,737,920 | 68 | 166 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
mod = 998244353
N, M, K = mapint()
pos = {}
neg = {}
pos[0] = 1
neg[0] = 1
for i in range(1, N+1):
pos[i] = i*pos[i-1]%mod
neg[i] = pow(pos[i], mod-2, mod)
ans = 0
for i in range(K+1):
ans += M*pow((M-1), (N-i-1), mod)*pos[N-1]*neg[i]*neg[N-i-1]
ans %= mod
print(ans) | n=int(input())
s=100000
for i in range(n):
s*=1.05
p=s%1000
if p!=0:
s+=1000-p
print(int(s))
| 0 | null | 11,628,208,052,850 | 151 | 6 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for j in range(W):
print('#', end='')
print()
for i in range(H-2):
print('#', end='')
for j in range(W-2):
print('.', end='')
print('#')
for j in range(W):
print('#', end='')
print('\n') | n=int(input())
x=100000
for i in range(n):
x*=1.05
if x%1000>0:
x=x-(x%1000)+1000
else:
pass
print(int(x))
| 0 | null | 411,272,476,176 | 50 | 6 |
W, H, x, y, r = map(int, input().split())
if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:
print("Yes")
else:
print("No")
| W,H,x,y,r=map(int,raw_input().split())
print'Yes' if((0+r)<=x and (W-r)>=x) and ((0+r)<=y and (H-r)>=y) else'No' | 1 | 453,632,921,884 | null | 41 | 41 |
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]
for s in range(n):
aa.append(aa[s] + a[s])
for s in range(m):
bb.append(bb[s] + b[s])
ans = 0
j = m
for i in range(n+1):
if aa[i] > k:
break
while bb[j] > k - aa[i]:
j -= 1
ans = max(ans, i+j)
print(ans) | number = int(input())
list1,list2 = input().split(" ")
str=""
for i in range(number):
str=str+list1[i]+list2[i]
print(str) | 0 | null | 61,464,437,760,036 | 117 | 255 |
import math
n,k = map(int,input().split())
s = n//k
if n-k*s>abs(n-k*s-k):
print(abs(n-k*s-k))
else:
print(n-k*s) | n,k=map(int,input().split())
ans=n%k
if ans>k//2:
print(abs(ans-k))
elif ans<=k//2:
print(ans) | 1 | 39,410,129,642,260 | null | 180 | 180 |
def selection_sort(A):
count = 0
for i in range(len(A)):
min_value = A[i]
min_value_index = i
# print('- i:', i, 'A[i]', A[i], '-')
for j in range(i, len(A)):
# print('j:', j, 'A[j]:', A[j])
if A[j] < min_value:
min_value = A[j]
min_value_index = j
# print('min_value', min_value, 'min_value_index', min_value_index)
if i != min_value_index:
count += 1
A[i], A[min_value_index] = A[min_value_index], A[i]
# print('swap!', A)
return count
n = int(input())
A = list(map(int, input().split()))
count = selection_sort(A)
print(*A)
print(count)
| # -*- coding: utf-8 -*-
def selection_sort(a, n):
count = 0
for i in range(n):
minj = i
for j in range(i+1, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if a[i] != a[minj]:
count += 1
return a, count
def main():
input_num = int(input())
input_list = [int(i) for i in input().split()]
ans_list, count = selection_sort(input_list, input_num)
for i in range(input_num):
if i != 0:
print(" ", end="")
print(ans_list[i], end='')
print()
print(count)
if __name__ == '__main__':
main() | 1 | 19,633,321,124 | null | 15 | 15 |
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
s=input()
lns=len(s)
lst=[0]*(lns+1)
start=[]
if s[0]=="<":
start.append(0)
for i in range(lns-1):
if s[i]==">" and s[i+1]=="<":
start.append(i+1)
if s[lns-1]==">":
start.append(lns)
for i in start:
d=deque([[i,0],[i,1]])
while d:
now,lr=d.popleft()
# print(now)
if now-1>=0 and lr==0 and s[now-1]==">":
lst[now-1]=max(lst[now-1],lst[now]+1)
d.append([now-1,0])
if now+1<=lns and lr==1 and s[now]=="<":
lst[now+1]=max(lst[now+1],lst[now]+1)
d.append([now+1,1])
# print(lst)
# print(start)
# print(lst)
print(sum(lst)) | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
s=input()
ls=len(s)
a=[0]*(ls+1)
for i in range(ls):
if s[i]=='<':
a[i+1]=a[i]+1
for j in reversed(range(ls)):
if s[j]=='>':
a[j]=max(a[j+1]+1,a[j])
print(sum(a))
resolve() | 1 | 156,174,368,527,290 | null | 285 | 285 |
A1, A2, A3 = [int(s) for s in input().split(' ')]
print('win' if A1+A2+A3 < 22 else 'bust')
| a,b,c=map(int,input().split())
if a+b+c>21:print('bust')
else:print('win') | 1 | 118,989,993,228,328 | null | 260 | 260 |
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
for i in range(60):
cou = 0
bit = 1 << i
for j in a:
if j & bit:
cou += 1
num1 = cou
num0 = n - num1
ans += ((num1*num0) * bit )%mod
print(ans%mod) | import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 10**9 + 7
cnt_one = [0] * 60
cnt_zero = [0] * 60
def count_bin(a):
base = 1
for i in range(60):
if a % (base * 2) > 0:
cnt_one[i] += 1
a -= base
else:
cnt_zero[i] += 1
base *= 2
for a in A:
count_bin(a)
base = 1
ans = 0
for one, zero in zip(cnt_one, cnt_zero):
ans += one * zero * base
ans %= mod
base *= 2
base %= mod
print(ans) | 1 | 123,423,698,772,330 | null | 263 | 263 |
a=map(int, raw_input().split())
if (min(a)<a[0]<max(a)):
print min(a),a[0],max(a)
elif (min(a)<a[1]<max(a)):
print min(a),a[1],max(a)
else:
print min(a),a[2],max(a) | s=input()
ans="No"
if len(s)%2==0:
if s=="hi"*(len(s)//2):
ans="Yes"
print(ans) | 0 | null | 26,852,269,235,792 | 40 | 199 |
#!/usr/bin/env python3
from networkx.utils import UnionFind
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n,m=map(int, input().split())
uf = UnionFind()
for i in range(1,n+1):
_=uf[i]
for _ in range(m):
a,b=map(int, input().split())
uf.union(a, b) # aとbをマージ
print(len(list(uf.to_sets()))-1)
#for group in uf.to_sets(): # すべてのグループのリストを返す
#print(group)
if __name__ == '__main__':
main()
| n,a,b = map(int,input().split())
if a == 0:
print(0)
elif a+b <= n and n%(a+b) < a:
print((n//(a+b))*a + n%(a+b))
elif a+b <= n and n%(a+b) >= a:
print((n//(a+b))*a + a)
elif n < a+b and n < a:
print(n)
elif n < a+b and a <= n:
print(a)
| 0 | null | 29,121,260,089,438 | 70 | 202 |
N=int(input())
ans=[0]*(N+1)
rN=int(N**(1/2))
for x in range(1,rN+1):
for y in range(1,rN+1):
for z in range(1,rN+1):
n=x**2+y**2+z**2+x*y+y*z+z*x
if n<=N:
ans[n]+=1
for i in range(1,N+1):
print(ans[i]) | x,y = map(int,input().split())
z = x * y
m = x * 2 + y * 2
print('{0} {1}'.format(z,m))
| 0 | null | 4,190,695,992,030 | 106 | 36 |
N,M = map(int,input().split())
ans = []
s = 1
e = M+1
while e>s:
ans.append([s,e])
s += 1
e -= 1
s = M+2
e = 2*M+1
while e>s:
ans.append([s,e])
s += 1
e -= 1
for s,e in ans:
print(s,e)
| color = input()
kosuu = input()
trashc = input()
_ = 0
color = color.split()
kosuu = kosuu.split()
trashc = trashc.split()
while True:
if(trashc[0] == color[_]):
kosuu[_] = int(kosuu[_]) -1
break
_= _+1
print(" ".join(map(str, kosuu)))
| 0 | null | 50,420,140,972,948 | 162 | 220 |
turn=int(input())
duel=[input().split(" ")for i in range(turn)]
point=[0,0]
for i in duel:
if i[0]==i[1]:
point[0],point[1]=point[0]+1,point[1]+1
if i[0]>i[1]:
point[0]+=3
if i[0]<i[1]:
point[1]+=3
print(" ".join(map(str,point)))
| def solve():
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))
As.sort()
Fs.sort(reverse=True)
def isOK(score):
d = 0
for A, F in zip(As, Fs):
if A*F > score:
d += -(-(A*F-score) // F)
return d <= K
ng, ok = -1, 10**12
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
solve()
| 0 | null | 83,238,772,698,368 | 67 | 290 |
XYZ = list(map(int, input().split()))
ABC = [0]*3
for i in range(3):
ABC[i] = XYZ[(i+2)%3]
print(" ".join(map(str,ABC))) | from collections import Counter
n,p = map(int,input().split())
S = input()
dp = [0]
mod = p
if p==2:
ans =0
for i in reversed(range(n)):
if int(S[i])%2==0:
ans += i+1
print(ans);exit()
elif p==5:
ans =0
for i in reversed(range(n)):
if int(S[i])%5==0:
ans += i+1
print(ans);exit()
for i in reversed(range(n)):
dp.append(dp[-1]%mod + pow(10,n-1-i,mod)*int(S[i]))
dp[-1]%=mod
count = Counter(dp)
ans = 0
for key,val in count.items():
if val>=2:
ans += val*(val-1)//2
print(ans) | 0 | null | 48,213,210,017,500 | 178 | 205 |
from math import gcd
from functools import reduce
import sys
input = sys.stdin.readline
def lcm(a, b):
return a*b // gcd(a, b)
def count_factor_2(num):
count = 0
while num % 2 == 0:
num //= 2
count += 1
return count
def main():
n, m = map(int, input().split())
A = list(map(lambda x: x//2, set(map(int, input().split()))))
check = len(set(map(count_factor_2, A)))
if check != 1:
print(0)
return
lcm_a = reduce(lcm, A)
step = lcm_a * 2
ans = (m + lcm_a) // step
print(ans)
if __name__ == "__main__":
main()
| # C Traveling Salesman around Lake
K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
before = A[0]
for i in range(1, len(A)):
ans = max(ans, A[i] - before)
before = A[i]
ans = max(ans, A[0] + K - A[N-1])
print(K - ans) | 0 | null | 73,048,767,925,870 | 247 | 186 |
# AC: 753 msec(Python3)
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.size = [1] * (n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.find(self.par[x])
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.size[x] < self.size[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_size(self, x):
return self.size[self.find(x)]
def main():
N,M,K,*uv = map(int, read().split())
ab, cd = uv[:2*M], uv[2*M:]
uf = UnionFind(N)
friend = [[] for _ in range(N+1)]
for a, b in zip(*[iter(ab)]*2):
uf.unite(a, b)
friend[a].append(b)
friend[b].append(a)
ans = [uf.get_size(i) - 1 - len(friend[i]) for i in range(N+1)]
for c, d in zip(*[iter(cd)]*2):
if uf.is_same(c, d):
ans[c] -= 1
ans[d] -= 1
print(*ans[1:])
if __name__ == "__main__":
main()
| def rec(num, string, total, xy_list, n):
x, y = xy_list[num]
if string:
pre_one = int(string[-1])
pre_x, pre_y = xy_list[pre_one]
distance = ((x - pre_x)**2 + (y - pre_y)**2)**0.5
total+=distance
string+=str(num)
if len(string)==n:
return total
all_total = 0
ret_list = [i for i in range(n) if str(i) not in string]
for one in ret_list:
all_total+=rec(one, string, total, xy_list, n)
return all_total
def main():
n = int(input())
xy_list = []
k = 1
for i in range(n):
x, y = list(map(int, input().split(" ")))
xy_list.append((x, y))
k*=(i+1)
all_total = 0
for i in range(n):
all_total+=rec(i, "", 0, xy_list, n)
print(all_total/k)
if __name__=="__main__":
main()
| 0 | null | 104,787,502,883,550 | 209 | 280 |
k = int(input())
a,b = map(int,input().split())
x = (b // k) * k
if a <= x <= b :
print('OK')
else :
print('NG') | K = int(input())
A, B = map(int,input().split())
C = A % K
if B - A >= K - 1:
print('OK')
elif C == 0:
print('OK')
elif C + B - A >= K:
print('OK')
else:
print('NG') | 1 | 26,531,988,105,730 | null | 158 | 158 |
X = int(input())
if X >= 400 and X < 600:
print('8')
elif X >= 600 and X < 800:
print('7')
elif X >= 800 and X < 1000:
print('6')
elif X >= 1000 and X < 1200:
print('5')
elif X >= 1200 and X < 1400:
print('4')
elif X >= 1400 and X < 1600:
print('3')
elif X >= 1600 and X < 1800:
print('2')
elif X >= 1800 and X < 2000:
print('1') | N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0]*N
for i in range(M):
A,B=map(int,input().split())
L[A-1]=max(L[A-1],H[B-1])
L[B-1]=max(L[B-1],H[A-1])
ans=0
for j in range(N):
if H[j]>L[j]:
ans+=1
print(ans)
| 0 | null | 15,832,584,322,658 | 100 | 155 |
a, b, m = map(int, input().split())
a_s = list(map(int, input().split()))
b_s = list(map(int, input().split()))
m_s =[]
for _ in range(m):
m_s.append(list(map(int, input().split())))
mini = min(a_s) + min(b_s)
for am, bm, sale in m_s:
mini = min(mini, a_s[am-1]+b_s[bm-1]-sale)
print(mini) | a,b,m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list) + min(b_list)
for i in range(m):
x,y,c = map(int, input().split())
if ans > a_list[x-1] + b_list[y-1] - c:
ans = a_list[x-1] + b_list[y-1] - c
print(ans) | 1 | 54,000,505,680,000 | null | 200 | 200 |
D = dict()
D['SUN'] = 7
D['MON'] = 6
D['TUE'] = 5
D['WED'] = 4
D['THU'] = 3
D['FRI'] = 2
D['SAT'] = 1
print(D[input()]) | # -*- coding: utf-8 -*-
"""
A - Can't Wait for Holiday
https://atcoder.jp/contests/abc146/tasks/abc146_a
"""
import sys
def solve(S):
return {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}[S]
def main(args):
S = input()
ans = solve(S)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 1 | 132,496,455,886,628 | null | 270 | 270 |
X = int(input())
if 400 <= X < 600:
print(8)
elif 600 <= X < 800:
print(7)
elif 800 <= X < 1000:
print(6)
elif 1000 <= X < 1200:
print(5)
elif 1200 <= X < 1400:
print(4)
elif 1400 <= X < 1600:
print(3)
elif 1600 <= X < 1800:
print(2)
else:
print(1)
| from sys import stdin
input = stdin.readline
def solve():
X = int(input())
check = (X - 400)//200
print(8 - check)
if __name__ == '__main__':
solve()
| 1 | 6,642,583,957,840 | null | 100 | 100 |
data = list(map(int, input().split()))
a,b = max(data), min(data)
r = a % b
while r != 0:
a = b
b = r
r = a % b
print(b) | from sys import stdin, setrecursionlimit
def gcd(x, y):
if x % y == 0:
return y
return gcd(y, x % y)
def main():
input = stdin.buffer.readline
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [a[i] // 2 for i in range(n)]
a = list(set(a))
n = len(a)
lcm = 1
for i in range(n):
lcm = lcm * a[i] // gcd(lcm, a[i])
for i in range(n):
if (lcm // a[i] % 2) == 0:
print(0)
exit()
ans = m // lcm
print(ans - ans // 2)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0 | null | 50,821,102,856,398 | 11 | 247 |
N, M = map(int, input().split())
A = list(set(map(int, input().split(" "))))
G = A.copy()
while not any(x % 2 for x in G):
G = [i // 2 for i in G]
if not all(x % 2 for x in G):
print(0)
exit(0)
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
total = 1
for x in A:
total = lcm(total, x // 2)
print((M // total + 1) // 2)
| kazu = ['pon','pon','hon','bon','hon','hon','pon','hon','pon','hon']
n = int(input())
print(kazu[n%10])
| 0 | null | 60,845,188,403,048 | 247 | 142 |
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
apple = p[:x] + q[:y] + r
apple = list(reversed(sorted(apple)))
print(sum(apple[:x+y])) | s=input()
if s[-4]==s[-3] and s[-2]==s[-1]:
print('Yes')
else:
print('No') | 0 | null | 43,500,274,174,488 | 188 | 184 |
#!/usr/bin/env python3
def solve(xs: "List[int]"):
for idx, x in zip(range(1, 6), xs):
if x == 0:
return idx
def main():
x = list(map(int, input().split()))
answer = solve(x)
print(answer)
if __name__ == "__main__":
main()
| X = input().split()
for i in range(len(X)):
if X[i] == '0' :
print(i+1)
exit() | 1 | 13,385,182,351,940 | null | 126 | 126 |
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors[1:]
n = int(input())
a = make_divisors(n-1)
b = make_divisors(n)
count = 0
for kk in b:
mom = n
while mom % kk == 0:
mom //= kk
if mom % kk == 1:
count +=1
print(len(a) + count)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from copy import deepcopy
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
n = int(readline())
ans = len(make_divisors(n - 1))
for check in make_divisors(n):
if check == 1:
continue
nn = deepcopy(n)
while nn % check == 0:
nn //= check
if nn % check == 1:
ans += 1
print(ans - 1)
| 1 | 41,254,375,367,300 | null | 183 | 183 |
from collections import deque
h,w = map(int,input().split())
maze = []
for _ in range(h):
maze.append(input())
ans = 0
move = [[1,0],[-1,0],[0,1],[0,-1]]
for i in range(h):
for j in range(w):
if(maze[i][j]=="."):
dist = [ [99999999]*w for _ in range(h) ]
dq = deque()
y=i
x=j
d=0
dist[y][x]=0
dq.append((y,x,d))
while(len(dq)):
y,x,d = dq.popleft()
for m in move:
if((0<=x+m[0]<w) and (0<=y+m[1]<h) and
(dist[y+m[1]][x+m[0]] > d+1) and
(maze[y+m[1]][x+m[0]] == ".")):
dist[y+m[1]][x+m[0]]=d+1
dq.append((y+m[1],x+m[0],d+1))
ans = max(ans,d)
# print(d,i,j)
print(ans) | from collections import deque
import itertools
h, w = map(int, input().split())
g = [input() for _ in range(h)]
# x,yはスタートの座標
def bfs(x, y):
# 最初は全て未訪問なので-1で初期化
d = [[-1] * w for _ in range(h)]
# スタート地点への距離は0
d[x][y] = 0
q = deque([(x, y)])
while q:
tx, ty = q.popleft()
# 右、上、左、下
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
nx, ny = tx + dx, ty + dy
# グリッドの範囲(縦方向, 横方向)内、通路(壁ではない)、未訪問(== -1)の場合
if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == '.' and d[nx][ny] < 0:
d[nx][ny] = d[tx][ty] + 1
q.append((nx, ny))
# 最終的なdを平坦化して最大値を返す
return max(list(itertools.chain.from_iterable(d)))
# 全てのマスについて
max_count = 0
for x in range(h):
for y in range(w):
# スタートが通路であるかチェックする必要がある
if g[x][y] == ".":
max_count = max(max_count, bfs(x, y))
print(max_count)
| 1 | 94,354,165,557,600 | null | 241 | 241 |
def insertion_sort(arr):
print(" ".join(map(str, arr)))
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
print(" ".join(map(str, arr)))
n = int(input())
arr = list(map(int, input().split()))
insertion_sort(arr) | def insertionSort(a, n):
trace(a, n)
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
trace(a, n)
def trace(a, n):
output = ''
for i in a:
if i == a[n-1]:
output += str(i)
else:
output += str(i) + ' '
print(output)
n = int(input())
a = list(map(int, input().split()))
insertionSort(a, n)
| 1 | 5,214,569,408 | null | 10 | 10 |
a = int(input())
result = a + a**2 + a**3
print(result) | a = int(input())
print(f'{a+a**2+a**3}') | 1 | 10,247,180,590,728 | null | 115 | 115 |
# AOJ ITP1_8_B
def numinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def main():
while True:
n = int(input())
if n == 0: break
sum = 0
while n > 0:
sum += n % 10
n = n // 10
print(sum)
if __name__ == "__main__":
main()
| import math
a,b,h,m=map(int,input().split())
arg=min(abs(30*h-5.5*m), 360-abs(30*h-5.5*m))
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(arg))))
| 0 | null | 10,907,605,444,450 | 62 | 144 |
a, b, c, k = map(int, input().split())
print(max(min(k, a) ,0) - max(min(k - (a + b), c), 0)) | a,b,c,k = map(int,input().split())
s=0
s += k if a > k else a
s -= (k-a-b) if k > a+b else 0
print(s) | 1 | 21,960,553,881,892 | null | 148 | 148 |
import sys
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, sys.stdin.readline().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
ars = [0] * N
todo = deque([0])
done = {0}
while todo:
p = todo.popleft()
for np in G[p]:
if np in done:
continue
todo.append(np)
ars[np] = p + 1
done.add(np)
if len(done) == N:
print("Yes")
for i in range(1, N):
print(ars[i])
else:
print("No") | N = int(input())
A = [int(x) for x in input().split()]
cnt = [0 for x in range(N)]
for i in range(len(A)) :
cnt[A[i]-1] += 1
for i in range(N) :
print(cnt[i]) | 0 | null | 26,381,409,813,050 | 145 | 169 |
N = int(input())
A = {int(x): key for key, x in enumerate(input().split(), 1)}
sort_a = sorted(A.items(), key=lambda x: x[0])
print(' '.join([str(key) for x, key in sort_a]))
| n,k=map(int,input().split())
L=[1]*n
for i in range(k):
d=int(input())
A=list(map(int,input().split()))
for a in A:
L[a-1] = 0
print(sum(L)) | 0 | null | 102,207,799,766,772 | 299 | 154 |
while True:
try:
a, b = map(int, input().rstrip().split())
print(len(str(a + b)))
except Exception:
break
| import sys
for jk in sys.stdin:
L=jk.split(" ")
sum = int(L[0])+int(L[1])
digit = 1
while sum>=10:
sum = sum/10
digit = digit + 1
print digit | 1 | 83,245,932 | null | 3 | 3 |
S=str(input())
ans=''
for i in range(3):
ans+=S[i]
print(ans) | line = list(input())
print(''.join(line[:3])) | 1 | 14,691,051,231,332 | null | 130 | 130 |
h1, m1, h2, m2, k = list(map(int, input().split()))
if m2 < m1:
while m2 < m1:
h2 -= 1
m2 += 60
tm = m2 - m1
th = h2 - h1
if k > (th*60 + tm):
print (0)
else:
print(th*60 + tm - k) | N = int(input())
stocks = list(map(int, input().split()))
curr = 1000
for i in range(N - 1):
cnt = 0
if stocks[i] < stocks[i + 1]:
cnt = curr // stocks[i]
curr += cnt * (stocks[i + 1] - stocks[i])
print(curr)
| 0 | null | 12,632,470,303,558 | 139 | 103 |
def dfs(c,lst):
n=len(lst)
ans=[0]*n
stack = [c-1]
check = [0]*n #チェック済みリスト
while stack != [] :
d=stack.pop()
if check[d]==0:
check[d]=1
for i in lst[d]:
if check[i]==0:
stack.append(i)
ans[i]=ans[d]+1
return(ans)
import sys
input = sys.stdin.readline
N,u,v=map(int,input().split())
ki=[[] for f in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
ki[a-1].append(b-1)
ki[b-1].append(a-1)
U=dfs(u,ki)
V=dfs(v,ki)
ans=0
for i in range(N):
if V[i]>U[i]:
ans=max(ans,V[i]-1)
print(ans)
| import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
n,u,v = LI()
ab = [LI() for _ in range(n-1)]
e = collections.defaultdict(list)
for a,b in ab:
e[a].append(b)
e[b].append(a)
def search(s, ea):
d = collections.defaultdict(lambda: inf)
d[s] = 0
q = []
heapq.heappush(q, (0, s))
v = collections.defaultdict(bool)
for u in ea:
v[u] = True
while len(q):
k, u = heapq.heappop(q)
if v[u]:
continue
v[u] = True
for uv in e[u]:
if v[uv]:
continue
vd = k + 1
if d[uv] > vd:
d[uv] = vd
heapq.heappush(q, (vd, uv))
return d
du = search(u, [])
dv = search(v, [])
r = 0
for i in range(n):
if du[v] - du[u] < 3:
break
r += 1
for c in e[u]:
if dv[u] > dv[c]:
u = c
break
for c in e[v]:
if du[v] > du[c]:
v = c
break
ea = []
t = dv[u]
for c in range(1, n+1):
if dv[c] < t:
ea.append(c)
d = search(u, ea)
m = max(d.values())
r += m
s = t - dv[v]
if s > 1:
r += 1
return r
print(main())
| 1 | 117,337,789,505,482 | null | 259 | 259 |
N = int(input())
cc = list(map(int,input().split()))
num = [0]*N
for i in cc:
num[i-1] += 1
for i in num:
print(i) | Flag = True
data = []
while Flag:
H, W = map(int, input().split())
if H == 0 and W == 0:
Flag = False
else:
data.append((H, W))
#print(type(W))
for (H, W) in data:
for i in range(H):
if i == 0 or i == H-1:
print('#' * W)
else:
print('#' + '.' * (W-2) + '#')
print('\n', end="")
| 0 | null | 16,779,342,296,508 | 169 | 50 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
A, B, C = map(int, input().split())
if A == B and B != C:
print("Yes")
elif B == C and B != A:
print("Yes")
elif C == A and C != B:
print("Yes")
else:
print("No") | a, b, c = map(int, input().split())
if a == b and a != c:
print('Yes')
elif b == c and b != a:
print('Yes')
elif c == a and c != b:
print('Yes')
else:
print('No')
| 1 | 68,361,977,801,248 | null | 216 | 216 |
import itertools
H,W,K = map(int,input().split())
S = []
for i in range(H):
s= map(int,input())
S.append(list(s))
l = list(itertools.product([0,1], repeat=H-1))
l = [list(li) for li in l]
for i in range(len(l)):
l[i] = [j+1 for j in range(len(l[i])) if l[i][j] > 0]
S_t = [list(x) for x in zip(*S)]
for i in range(W):
for j in range(1,H):
S_t[i][j] += S_t[i][j-1]
flag = False
min_cnt = H*W
for i in range(len(l)):
cnt = 0
bh = [0]+[li for li in l[i] if li > 0]+[H]
white = [0]*(len(bh)-2+1)
j = 0
while j < W:
if flag == True:
white = [0]*(len(bh)-2+1)
cnt += 1
flag = False
for k in range(len(bh)-1):
if bh[k] == 0:
su = S_t[j][bh[k+1]-1]
else:
su = S_t[j][bh[k+1]-1]-S_t[j][max(0,bh[k]-1)]
if white[k] + su > K:
if su > K:
j = W
cnt = H*W+1
flag = False
else:
flag = True
break
white[k] += su
if flag == False:
j += 1
min_cnt = min(cnt+len(bh)-2,min_cnt)
print(min_cnt)
| N = int(input())
print(-(N%-1000)) | 0 | null | 28,539,114,810,374 | 193 | 108 |
from bisect import bisect_left, bisect_right, insort_left
import sys
readlines = sys.stdin.readline
def main():
n = int(input())
s = list(input())
q = int(input())
d = {}
flag = {}
for i in list('abcdefghijklmnopqrstuvwxyz'):
d.setdefault(i, []).append(-1)
flag.setdefault(i, []).append(-1)
for i in range(n):
d.setdefault(s[i], []).append(i)
for i in range(q):
q1,q2,q3 = map(str,input().split())
if q1 == '1':
q2 = int(q2) - 1
if s[q2] != q3:
insort_left(flag[s[q2]],q2)
insort_left(d[q3],q2)
s[q2] = q3
else:
ans = 0
q2 = int(q2) - 1
q3 = int(q3) - 1
if q2 == q3:
print(1)
continue
for string,l in d.items():
res = 0
if d[string] != [-1]:
left = bisect_left(l,q2)
right = bisect_right(l,q3)
else:
left = 0
right = 0
if string in flag:
left2 = bisect_left(flag[string],q2)
right2 = bisect_right(flag[string],q3)
else:
left2 = 0
right2 = 0
if left != right:
if right - left > right2 - left2:
res = 1
ans += res
#print(string,l,res)
print(ans)
if __name__ == '__main__':
main() | l,r,d = [int(x) for x in input().split()]
nums = [int(x) for x in range(l,r+1)]
ans = []
for i in range(len(nums)):
if nums[i]%d == 0:
ans.append(nums[i])
print(len(ans)) | 0 | null | 35,250,697,835,620 | 210 | 104 |
A = []
B = []
C = []
n, m, l = map(int, input().strip().split())
[A.append(list(map(int, input().strip().split()))) for x in range(n)]
[B.append(list(map(int, input().strip().split()))) for y in range(m)]
[C.append([0 for zz in range(l)]) for z in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += A[i][k]*B[k][j]
if j == l - 1:
print(C[i][j])
else:
print(C[i][j],end=' ') | from collections import *
import copy
N,K=map(int,input().split())
A=list(map(int,input().split()))
lst=[0]
for i in range(0,N):
lst.append((A[i]%K+lst[i])%K)
for i in range(len(lst)):
lst[i]-=i
lst[i]%=K
dic={}
count=0
for i in range(0,len(lst)):
if lst[i] in dic:
count+=dic[lst[i]]
dic[lst[i]]+=1
else:
dic.update({lst[i]:1})
a=i-K+1
if a>=0:
dic[lst[a]]-=1
print(count)
| 0 | null | 69,120,050,332,860 | 60 | 273 |
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(0,N,2):
if A[i]%2 != 0:
count += 1
print(count) | #!/usr/bin/env python
#-*- coding:utf-8 -*-
def selectionSort(arr, N):
counter = 0
for i in range(N):
minj = i
for j in range(i,N):
if arr[minj] > arr[j]:
minj = j
if minj != i: counter += 1
arr[i], arr[minj] = arr[minj],arr[i]
return counter,arr
def main():
N = int(raw_input())
A = map(int, raw_input().split())
counter,sortedA = selectionSort(A, N)
print ' '.join(map(str,sortedA))
print counter
#def test():
if __name__ == '__main__':
main() | 0 | null | 3,912,109,139,080 | 105 | 15 |
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n = ii()
def get_head(x):
while x:
b = x%10
x //= 10
return b
dp = [[0] * 10 for i in range(10)]
for i in range(1,n+1):
h = get_head(i)
t = i%10
dp[h][t] += 1
for i in range(10):
dp[0][i] = 0
dp[i][0] = 0
ans = 0
for i in range(1,n+1):
h = get_head(i)
t = i%10
ans += dp[t][h]
print(ans)
| n = int(input())
aaa = [[0 for i in range(10)] for j in range(10)]
for i in range(1, n+1):
aaa[int(str(i)[0])][i%10] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += aaa[i][j]*aaa[j][i]
print(ans) | 1 | 86,775,773,782,542 | null | 234 | 234 |
for i in range(1, 10):
for j in range(1, 10):
print (u"%dx%d=%d"%(i,j,i*j)) | for i in range(9):
i=i+1
for j in range(9):
j=j+1
print(str(i)+'x'+str(j)+'='+str(i*j)) | 1 | 3,124,810 | null | 1 | 1 |
n, k, c = map(int, input().split())
s = list(str(input()))
def getpos(s):
l = []
i = 0
while i <= n-1 and len(l) < k:
if s[i] == 'o':
l.append(i)
i += c+1
else:
i += 1
return l
l = getpos(s)
s.reverse()
r = getpos(s)
for i in range(len(r)):
r[i] = n-1-r[i]
#print(l)
#print(r)
lastl = [-1]*(n+1)
lastr = [-1]*(n+1)
for i in range(k):
lastl[l[i]+1] = i
for i in range(n):
if lastl[i+1] == -1:
lastl[i+1] = lastl[i]
for i in range(k):
lastr[r[i]] = i
for i in reversed(range(n)):
if lastr[i] == -1:
lastr[i] = lastr[i+1]
#print(lastl)
#print(lastr)
ans = []
s.reverse()
for i in range(n):
if s[i] != 'o':
continue
cnt = 0
cnt += lastl[i]+1
cnt += lastr[i+1]+1
if lastl[i] != -1 and lastr[i+1] != -1 and r[lastr[i+1]] - l[lastl[i]] <= c:
cnt -= 1
if cnt < k:
ans.append(i+1)
for i in range(len(ans)):
print(ans[i]) | import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
#a = int(input())
n, k, c_yutori = tin()
if n == 1:
return 1
s = input()
can_work = [0]*n
can_work[0] = 1 if s[0]=='o' else 0
yn = c_yutori if s[0]=='o' else 0
for i, c in enumerate( list(s)[1:],1):
if yn == 0 and c == 'o':
can_work[i] = can_work[i-1]+1
yn = c_yutori
else:
can_work[i] = can_work[i-1]
yn = max(0, yn - 1)
need_to_work = [k]*n
if s[-1]=='o':
need_to_work[-1] = k-1
yn = c_yutori
else:
need_to_work[-1]=k
yn=0
for i, c in enumerate(list(s)[-2::-1],1):
pos = n-i-1
if yn == 0 and c == 'o':
need_to_work[pos] = need_to_work[pos+1]-1
yn = c_yutori
else:
need_to_work[pos]=need_to_work[pos+1]
yn = max(0, yn-1)
#pa(can_work)
#pa(need_to_work)
if need_to_work[1] == 1:
print(1)
for i in range(1, n-1):
if can_work[i-1] < need_to_work[i+1]:
print(i+1)
if can_work[-2]==k-1:
print(n)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | 1 | 40,679,915,749,290 | null | 182 | 182 |
if __name__ == "__main__":
h1, m1, h2, m2, k = map(int, input().split())
print((h2-h1)*60+m2-m1-k) | #float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
h,m,H,M,k=MI()
l=(M-m)+60*(H-h)
print(l-k) | 1 | 18,164,541,612,800 | null | 139 | 139 |
A, B, N = map(int, input().split())
if B < N:
Max = int(A*(B-1)/B)
X = int(N/B)
fx = int(A*(B*X-1)/B) - A * int((B*X-1)/B)
# Max = max(fx,Max)
# for x in range(1,X):
# fx = int(A*x/B) - A * int(x/B)
# Max = max(Max,fx)
elif B == N:
Max = int(A*(B-1)/B)
else:
Max = int(A*N/B)
print(Max)
| n, m = map(int, input().split())
def solve(n):
if n == 0:
return 1
return n * solve(n - 1)
if n <= 1:
n_ans = 0
else:
n_ans = solve(n) // (solve(n - 2) * 2)
if m <= 1:
m_ans = 0
else:
m_ans = solve(m) // (solve(m - 2) * 2)
ans = n_ans + m_ans
print(ans)
| 0 | null | 36,893,082,208,460 | 161 | 189 |
n,a,b = map(int,input().split())
if (a - b) % 2 == 0:
print(min(abs(a-b) // 2, max(a-1, b-1), max(n-a, n-b)))
else:
print(min(max(a-1, b-1), max(n-a, n-b), (a+b-1)//2, (2 * n - a - b + 1)//2))
| n, a, b = [int(i) for i in input().split()]
a,b=max(a,b),min(a,b)
if (a - b) % 2 == 0:
print((a - b) // 2)
else:
c = b + (a -1- b) // 2
d = n - a + 1 + (n - (n - a + 1) - b) // 2
print(min(c,d))
| 1 | 109,199,455,140,362 | null | 253 | 253 |
n, k = map(int, input().split())
t = n // k
re = n - t * k
if abs(re - k) < re:
re = abs(re - k)
i = True
print(re)
| K = int(input())
A,B = map(int, input().split())
target = 0
target = B - B % K
if A <= target:
print('OK')
else:
print('NG') | 0 | null | 33,175,675,808,550 | 180 | 158 |
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
left = 0
right = max(A)
while right - left > 1:
mid = (left + right) // 2
jk = 0
for i in range(N):
jk += A[i] // mid - 1
if A[i] % mid != 0: jk += 1
if jk <= K:
right = mid
else:
left = mid
print(right) | # https://atcoder.jp/contests/abc174/tasks/abc174_e
from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0
while i<100:
i +=1
for num in A:
cnt += ceil(num/ans)-1
if cnt <=K:
R = ans
elif cnt>=K:
L = ans
else:
#print("fin",i-1,cnt,ans)
break
ans = (R+L)/2
cnt=0
print(ceil(ans)) | 1 | 6,498,052,838,940 | null | 99 | 99 |
W = raw_input().lower()
c = 0
while True:
T = raw_input()
if T == "END_OF_TEXT":
break
Ti = T.lower().split()
for i in Ti:
if i == W:
c += 1
print("%d" % (c, )) | N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]
l = [0] * 10**6
tot = 0
for i in range(N) :
l[A[i]]+=1
tot += A[i]
for i in range(Q):
s0 = S[i][0]
s1 = S[i][1]
tot += s1 * (l[s0] + l[s1]) - (s0 * l[s0] + s1*l[s1])
l[s1] += l[s0]
l[s0] = 0
print(tot) | 0 | null | 7,033,116,961,120 | 65 | 122 |
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
tf = [True] * a[-1]
dup = [False] * a[-1]
for i in range(n):
if tf[a[i]-1] == True:
#print(a[i])
if dup[a[i]-1] == True:
tf[a[i]-1] = False
else:
dup[a[i]-1] = True
for j in range(a[i]*2, a[-1]+1, a[i]):
tf[j-1] = False
c = 0
#print(tf)
for x in a:
if tf[x-1]:
c += 1
print(c)
| n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
x=[0]+[True]*10**6
for i in range(len(a)):
cnt=a[i]
if x[a[i]]==True and (i==0 or a[i]!=a[i-1]) and (i==(n-1) or a[i]!=a[i+1]):
ans+=1
while cnt<=10**6:
x[cnt]=False
cnt+=a[i]
elif x[a[i]]==True and ((i!=0 and a[i]==a[i-1]) or (i!=(n-1) and a[i]==a[i+1])):
while cnt<=10**6:
x[cnt]=False
cnt+=a[i]
print(ans)
| 1 | 14,447,834,326,718 | null | 129 | 129 |
# -*- coding: utf-8 -*-
def main():
n = int(input())
keihin_set = set()
for i in range(n):
s = input()
if not s in keihin_set:
keihin_set.add(s)
print(len(keihin_set))
if __name__ == "__main__":
main() | import sys
import itertools
def resolve(in_):
return len(set(s.strip() for s in itertools.islice(in_, 1, None)))
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main() | 1 | 30,047,026,475,550 | null | 165 | 165 |
mod = 10**9 + 7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
print(0)
exit()
a = (2*Y-X)//3
b = (2*X-Y)//3
if a < 0 or b < 0:
print(0)
exit()
m = min(a, b)
ifact = 1
for i in range(2, m+1):
ifact = (ifact * i) % mod
ifact = pow(ifact, mod-2, mod)
fact = 1
for i in range(a+b, a+b-m, -1):
fact = (fact * i) % mod
print(fact*ifact % mod)
| X,Y=map(int,input().split())
mod=10**9+7
if (X+Y)%3!=0:
print(0)
else:
N=int((2*Y-X)/3)
M=int((2*X-Y)/3)
if N<0 or M<0:
print(0)
if N==0 or M==0:
print(1)
if N>0 and M>0:
List=[0 for i in range(N+M)]
List[0]=1
for i in range(N+M-1):
List[i+1]=List[i]*(i+2)%mod
print(List[N+M-1]*pow(List[N-1],mod-2,mod)*pow(List[M-1],mod-2,mod)%mod) | 1 | 150,463,230,940,790 | null | 281 | 281 |
for i in range(1,10001):
n = int(input())
if n:
print(f'Case {i}: {n}')
| list =[]
i=0
index=1
while(index != 0):
index=int(input())
list.append(index)
i +=1
for i in range(0,i):
if list[i] == 0:
break
print("Case",i+1,end='')
print(":",list[i])
| 1 | 485,108,529,848 | null | 42 | 42 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.