code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
def solve():
N, K = map(int, input().split())
mod = 10**9+7
ans = 0
for k in range(K,N+2):
ans += (N+N-k+1)*k//2-k*(k-1)//2+1
ans %= mod
return ans
print(solve()) | import itertools
n = int(input())
lst = []
for _ in range(n):
m = int(input())
lst_s = []
for _ in range(m):
evi = list(map(int, input().split()))
lst_s.append(evi)
lst.append(lst_s)
#print(lst)
truth = [0, 1]
all_lists = list(itertools.product(truth, repeat=n))
#print(all_lists)
max_count = 0
for each in all_lists:
flag = True
count = 0
#print(each)
for i in range(n):
trust = each[i]
#print(trust)
evis = lst[i]
for evid in evis:
#print(evid)
person_ind = evid[0] - 1
person_trust = evid[1]
if trust == 1:
if person_trust != each[person_ind]:
flag = False
break
if not flag:
break
if trust == 1:
count += 1
if (count > max_count) and flag:
max_count = count
print(max_count) | 0 | null | 77,486,102,825,792 | 170 | 262 |
n=int(input())
s=[]
t=[]
flag=0
ans=0
for i in range(n):
ss,tt=map(str,input().split())
s.append(ss)
t.append(int(tt))
x=input()
for i in range(n):
if s[i]==x:
flag=1
continue
if flag == 1:
ans+=t[i]
print(ans) | #!/usr/bin/python3
# -*- coding:utf-8 -*-
import numpy
MAX = 10 ** 9 + 7
def prod_mod(la, mod):
x = 1
for a in la:
x *= a
x %= mod
return x
def main():
n, k = map(int, input().strip().split())
la = numpy.array(list(map(int, input().strip().split())))
la.sort()
if n == k:
print(prod_mod(la, MAX))
else:
if k % 2 == 1 and (la >= 0).sum() == 0:
print(prod_mod(la[-k:], MAX))
else:
il, ir = 0, n-1
cnt = 0
l = []
if k % 2 == 1:
l.append(la[ir])
ir -= 1
cnt += 1
while k - (cnt + 2) >= 0:
if la[il] * la[il+1] > la[ir-1] * la[ir]:
l.extend([la[il], la[il+1]])
il += 2
else:
l.extend([la[ir-1], la[ir]])
ir -= 2
cnt += 2
print(prod_mod(l, MAX))
if __name__=='__main__':
main()
| 0 | null | 53,445,489,455,420 | 243 | 112 |
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1e9)+7
INF = float('inf')
def solve():
n, m = [int(x) for x in input().split()]
a = []
starts = []
for i in range(n):
a.append(input())
for j in range(m):
if a[i][j] == '.':
starts.append((i, j))
def bfs(v):
q = deque([(v, 0)])
mx = 0
mv = v
w = defaultdict(int)
w[v] = 1
while q:
v, d = q.popleft()
if d > mx:
mv = v
mx = d
i, j = v
for x, y in ((0, 1), (0, -1), (1, 0), (-1, 0)):
if 0 <= i + x < n and 0 <= j + y < m and not w[(i+x,j+y)] and a[i+x][j+y] == '.':
w[(i+x,j+y)] = 1
q.append(((i+x, j+y), d + 1))
return mx, mv
ans = 0
for start in starts:
_, start = bfs(start)
cur, start = bfs(start)
ans = max(ans, cur)
print(ans)
t = 1
# t = int(input())
for case in range(1,t+1):
ans = solve()
"""
1
4
-1 1 1 -1
"""
| import queue
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
# print(maze)
def bfs(dist, i, j):
q = queue.Queue()
q.put((i, j, 0))
while not q.empty():
i, j, c = q.get()
# print(i, j, c, dist)
if i != 0 and dist[i-1][j] == 0:
dist[i-1][j] = c+1
q.put((i-1, j, c+1))
if j != 0 and dist[i][j-1] == 0:
dist[i][j-1] = c+1
q.put((i, j-1, c+1))
if i != h-1 and dist[i+1][j] == 0:
dist[i+1][j] = c+1
q.put((i+1, j, c+1))
if j != w-1 and dist[i][j+1] == 0:
dist[i][j+1] = c+1
q.put((i, j+1, c+1))
return dist, c
ans = 0
for i in range(h):
for j in range(w):
if maze[i][j] == '.':
dist = [[(maze[y][x] == '#')*-1 for x in range(w)] for y in range(h)]
dist[i][j] = -10
dist, c = bfs(dist, i, j)
tmp_ans = c
if tmp_ans > ans:
ans = tmp_ans
print(ans)
| 1 | 95,041,104,044,258 | null | 241 | 241 |
#coding:utf-8
#1_5_B 2015.4.1
while True:
length,width = map(int,input().split())
if (length,width) == (0,0):
break
for i in range(length):
for j in range(width):
if j == width - 1:
print('#')
elif i == 0 or i == length - 1 or j == 0:
print('#', end='')
else:
print('.', end='')
print() | N,D = map(int, input().split())
XY = [map(int, input().split()) for _ in range(N)]
X,Y = [list(i) for i in zip(*XY)]
s=0
for i in range (N):
if X[i]*X[i]+Y[i]*Y[i]<=D*D:
s=s+1
print(s) | 0 | null | 3,412,553,289,060 | 50 | 96 |
from math import sqrt
def solve(n):
s = list(map(float,input().split()))
m = sum(s)/n
a = sqrt(sum([(si-m)**2 for si in s])/n)
print('{0:.6f}'.format(a))
while True:
n = int(input())
if n==0:break
solve(n)
| import statistics
while True:
n=int(input())
if n==0:
break
stdnt=list(map(int,input().split()))
std=statistics.pstdev(stdnt)
print(std) | 1 | 197,414,766,900 | null | 31 | 31 |
def ra(a): #圧縮された要素を非保持
ll,l=[],1
for i in range(len(a)-1):
if a[i]==a[i+1]:
l+=1
else:
ll.append(l)
l=1
ll.append(l)
return ll
n=input()
print(len(ra(input()))) | # cook your dish here
import sys
def file():
sys.stdin = open('input.py', 'r')
sys.stdout = open('output.py', 'w')
def main(N, arr):
#initialising with positive infinity value
maxi=float("inf")
#initialising the answer variable
ans=0
#iterating linesrly
for i in range(N):
#finding minimum at each step
maxi=min(maxi,arr[i])
#increasing the final ans
ans+=maxi
print("dhh")
#returning the answer
return ans
#file()
if __name__ == '__main__':
#length of the array
'''N = 4
#Maximum size of each individual bucket
Arr = [4,3,2,1]
#passing the values to the main function
answer = main(N,Arr)
#printing the result
print(answer)'''
n=int(input())
s=input()
#l=list(map(int, input().split()))
ans=0
for i in range(1,n):
if(s[i]!=s[i-1]):
ans+=1
print(ans+1)
| 1 | 169,956,194,265,088 | null | 293 | 293 |
X=int(input())
sen=X//500
X=X%500
go=X//5
print(1000*sen + 5*go) | n = int(input())
s = input()
pw, pw1, pw2 = [0] * n, [0] * n, [0] * n
pw[0], pw1[0], pw2[0] = 1, 1, 1
v, mod1, mod2 = 0, 0, 0
for i in range(n):
if s[i] == '1':
v += 1
for i in range(1, n):
pw1[i] = int(pw1[i - 1] * 2) % (v + 1)
if v >= 2:
pw2[i] = int(pw2[i - 1] * 2) % (v - 1)
for i in range(n):
if s[i] == '1':
mod1 = (mod1 + pw1[n - i - 1]) % (v + 1)
if v >= 2:
mod2 = (mod2 + pw2[n - i - 1]) % (v - 1)
for i in range(n):
copy, x, cnt = 0, v, 1
if s[i] == '0':
x += 1
copy = (mod1 + pw1[n - i - 1]) % x
else:
x -= 1
if x >= 1:
copy = (mod2 - pw2[n - i - 1]) % x
else:
copy = -1
if copy == -1:
print(0)
else:
x = bin(copy).count('1')
while copy > 0:
copy %= x
x = bin(copy).count('1')
cnt += 1
print(cnt)
| 0 | null | 25,254,158,090,500 | 185 | 107 |
N = int(input())
from math import sin, cos, pi
th = pi/3
def koch(d, p1, p2):
if d == 0:
return
s = [0, 0]
t = [0, 0]
u = [0, 0]
s[0] = (2 * p1[0] + p2[0])/3
s[1] = (2 * p1[1] + p2[1])/3
t[0] = (2 * p2[0] + p1[0])/3
t[1] = (2 * p2[1] + p1[1])/3
u[0] = (t[0] - s[0]) * cos(th) - (t[1] - s[1]) * sin(th) + s[0]
u[1] = (t[0] - s[0]) * sin(th) + (t[1] - s[1]) * cos(th) + s[1]
koch(d-1, p1, s)
print(*s)
koch(d-1, s, u)
print(*u)
koch(d-1, u, t)
print(*t)
koch(d-1, t, p2)
p_start = [0.0, 0.0]
p_end = [100.0, 0.0]
print(*p_start)
koch(N, p_start, p_end)
print(*p_end)
| import copy
N = int(input())
list1 = list(map(int, input().split()))
list2 = copy.copy(list1)
list3 = set(list1)
x=len(list2)
y=len(list3)
if x==y:
print('YES')
else:
print('NO') | 0 | null | 37,093,644,609,542 | 27 | 222 |
N = int(input())
if N % 2 == 0:
print("0.5")
else:
a = N // 2 + 1
print(a/N) | #!/usr/bin/env python3
r, c, k = map(int, input().split())
items = [[0] * (c+1) for _ in range(r+1)]
for _ in range(k):
R, C, V = map(int, input().split())
items[R][C] = V
dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]
for i in range(1, r+1):
for j in range(1, c+1):
v = items[i][j]
dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + v, dp2[i-1][j] + v, dp3[i-1][j] + v)
dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + v)
dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + v)
ans = max(dp1[r][c], dp2[r][c], dp3[r][c])
print(ans) | 0 | null | 91,240,773,988,240 | 297 | 94 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
A = LI()
c = 0
d = collections.Counter()
d[0] = 1
ans = 0
r = [0] * (N+1)
for i,x in enumerate(A):
if i >= K-1:
d[r[i-(K-1)]] -= 1
c = (c + x - 1) % K
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans)
if __name__ == '__main__':
main() | n,k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
s = [0]
for i in range(len(a)):
s.append(s[-1]+a[i])
for i in range(len(s)):
s[i] = (s[i] - i) % k
# print(s)
d = {0:1}
ans = 0
for j in range(1,n+1):
if s[j] in d:
d[s[j]] += 1
else:
d[s[j]] = 1
if j >= k:
d[s[j-k]] -= 1
ans += d[s[j]] - 1
# print(d)
# print(ans)
print(ans) | 1 | 137,333,443,950,298 | null | 273 | 273 |
N = int(input())
An = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(N-1):
if An[i+1] > An[i]:
stock = money // An[i]
money += (An[i+1] - An[i]) * stock
print(money)
| n = int(input())
a=list(map(int,input().split()))
kane=1000
kabu =0
for i in range(n-1):
if a[i]<=a[i+1]:
kabu+=kane//a[i]
kane=kane%a[i]
else:
kane+=kabu*a[i]
kabu=0
print(kane+kabu*a[n-1]) | 1 | 7,269,118,390,500 | null | 103 | 103 |
# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())
S = input()
# 求解処理
ans = 0
x_bit = [False for n in range(10)]
for x in range(N):
S_x = int(S[x])
if x_bit[S_x]:
continue
x_bit[S_x] = True
y_bit = [False for n in range(10)]
for y in range(x + 1, N):
S_y = int(S[y])
if y_bit[S_y]:
continue
y_bit[S_y] = True
z_bit = [False for n in range(10)]
for z in range(y + 1, N):
S_z = int(S[z])
if z_bit[S_z]:
continue
z_bit[S_z] = True
ans += 1
# 結果出力
print(ans)
| n=int(input())
s=input()
ans=0
for i in range(1000):
cs=str(i).zfill(3)
p=0
for c in cs:
p=s.find(c,p)
if p==-1:
break
p+=1
else:
ans+=1
print(ans) | 1 | 128,712,390,537,792 | null | 267 | 267 |
n = int(input())
*li, = map(int, input().split())
input()
*Q, = map(int, input().split())
bits = 1
for i in li:
# print(f"{i=}")
# print(f"{bin(bits)=}")
bits |= bits << i
# print(f"{bin(bits)=}")
# print()
# print()
for q in Q:
# print(f"{bin(bits)=}")
print("yes"*((bits >> q) & 1) or "no")
# print()
| # -*- coding: utf-8 -*-
import random
import sys
import os
import pprint
#fd = os.open('ALDS1_5_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())
n = int(input())
A = list(map(int, input().split()))
# memo table T[i][m]
row_num = len(A)
column_num = 2000
T = [[None for i in range(column_num)] for j in range(row_num)]
#pprint.pprint(T)
def solve(i, m):
# out of index
if i >= len(A):
return False
if m < 0:
return False
if T[i][m] is not None:
return T[i][m]
if m == 0:
T[i][m] = True
elif m == A[i]:
T[i][m] = True
#elif i >= len(A):
# T[i][m] = False
elif solve(i+1, m):
T[i][m] = True
elif solve(i+1, m - A[i]):
T[i][m] = True
else:
T[i][m] = False
return T[i][m]
test_num = int(input())
test_values = map(int, input().split())
for v in test_values:
result = solve(0, v)
if result is True:
print('yes')
else:
print('no') | 1 | 97,503,026,660 | null | 25 | 25 |
# D - Road to Millionaire
def million(n, a):
wallet = 1000
i = 0
while i < n - 1:
highest_price = a[i]
cheapest_price = a[i]
# 直近の最高値と最安値を取得する
for j in range(i + 1, n):
if highest_price > a[j]:
break
if highest_price < a[j]:
highest_price = a[j]
if cheapest_price > a[j]:
cheapest_price = a[j]
if highest_price > cheapest_price:
# 取引する
stock = wallet // cheapest_price
wallet = wallet - stock * cheapest_price
wallet = wallet + stock * highest_price
i = j
else:
i += 1
return wallet
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
print(million(n, a))
| n=int(input())
A=list(map(int,input().split()))
g=1000
for s1,s2 in zip(A[:-1],A[1:]):
if s1<s2:
stockNum=g//s1
g+=stockNum*(s2-s1)
print(g)
| 1 | 7,371,005,975,062 | null | 103 | 103 |
import itertools
def main():
N, M, Q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(Q):
ai, bi, ci, di = list(map(int, input().split()))
a.append(ai)
b.append(bi)
c.append(ci)
d.append(di)
ans = 0
for A in list(itertools.combinations_with_replacement(range(1, M+1), N)):
# print(A)
score = 0
for i in range(Q):
if A[b[i]-1] - A[a[i]-1] == c[i]:
score += d[i]
if ans < score:
ans = score
print(ans)
if __name__ == "__main__":
main()
| n,m,q=map(int,input().split())
e=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i in range(1<<(m+n)):
a=[1]
for j in range(m+n):
if (i>>j)&1:a[-1]+=1
else:a+=[a[-1]]
if a[-1]>m:
flag=0
break
if len(a)>n:
flag=1
break
else:flag=1
if flag==0 or len(a)<n:continue
cnt=0
for s,t,u,v in e:
if a[t-1]-a[s-1]==u:cnt+=v
ans=max(ans,cnt)
print(ans) | 1 | 27,515,170,352,942 | null | 160 | 160 |
mod = 998244353
N, M, K = map(int, input().split())
list_size = 2*10**5 + 4
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size-1):
f_list[i+1] = (f_list[i] * (i+1)) % mod
f_r_list[-1] = pow(f_list[-1], mod - 2, mod)
for i in range(list_size-2, -1, -1):
f_r_list[i] = (f_r_list[i+1] * (i+1)) % mod
def comb(n, r, mod):
if n < r or r < 0:
return 0
elif n == 0 or r == 0 or n == r:
return 1
else:
return (f_list[n] * f_r_list[n-r] * f_r_list[r]) % mod
ans = 0
for k in range(K+1):
ans += (comb(N-1, k, mod) * M *pow(M-1, N-k-1, mod))%mod
ans %= mod
print(ans) | import sys
N, K = (int(x) for x in input().split())
H = list(map(int, input().split()))
ans=0
if K>=N:
print(0)
sys.exit(0)
H.sort(reverse=True)
del H[0:K]
for i in range(len(H)):
ans+=H[i]
print(ans) | 0 | null | 50,925,885,729,110 | 151 | 227 |
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
c = [0]*n
a = [0]*n
for i in range(n):
c[i],a[i] = ca[i][0],ca[i][1:]
INF = 10**9
ans = INF
for i in range(1<<n):
understanding = [0]*m
cost = 0
for j in range(n):
if ((i>>j)&1):
cost += c[j]
for k in range(m):
understanding[k] += a[j][k]
ok = True
for s in range(m):
if understanding[s] < x:
ok = False
if ok:
ans = min(ans, cost)
if ans == INF:
ans = -1
print(ans)
| n,m,x = map(int,input().split())
array = [list(map(int,input().split())) for _ in range(n)]
# print(array)
# print(n)
ans = 10 ** 8
for i in range(2**n):
skill = [0] * m
price = 0
count = 0
for k in range(n):
if (i >> k) & 1:
price += array[k][0]
for j in range(m):
skill[j] += array[k][j+1]
for l in range(m):
if skill[l] < x:
break
else:
count += 1
if count == m:
ans = min(ans, price)
if ans == 10**8:
print(-1)
else:
print(ans)
| 1 | 22,180,845,418,422 | null | 149 | 149 |
A,B,K = list(map(int,input().split()))
if A>= K:
print(str(A-K) + ' ' + str(B))
elif A < K :
print(str(0) + ' ' + str(max(B+A-K,0)))
| import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
A,B,K = LI()
A_ans = A-K if A>=K else 0
B_ans = B-(K-A) if K>A else B
B_ans = B_ans if B_ans>=0 else 0
print(A_ans,B_ans)
main()
| 1 | 103,723,472,070,560 | null | 249 | 249 |
# -*- coding: utf-8 -*-
# import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import math
def zz():
return list(map(int, sys.stdin.readline().split()))
def z():
return int(sys.stdin.readline())
def S():
return sys.stdin.readline()
def C(line):
return [sys.stdin.readline() for _ in range(line)]
def primes(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 [i for i in range(n + 1) if is_prime[i]]
N = z()
yakusu_nums = [0]*(N+1)
for i in range(1, N+1):
for j in range(i, N+1, i):
yakusu_nums[j] += 1
ans = 0
for i, yakusu_num in enumerate(yakusu_nums):
# print(i, yakusu_num)
ans += i*yakusu_num
print(ans)
| def solve():
N = int(input())
ans = 0
for i in range(1, N+1):
d = N//i
ans += i * d * (d + 1) / 2
print(int(ans))
solve() | 1 | 11,120,589,904,840 | null | 118 | 118 |
import sys,math,collections,itertools
input = sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
xa=a[0]
for i in range(1,len(a)):
xa ^= a[i]
b = []
for ai in a:
b.append(xa^ai)
print(*b)
| n = int(input())
a = list(map(int, input().split()))
x = 0
for ai in a:
x ^= ai
for ai in a:
print(x ^ ai, end=' ') | 1 | 12,594,582,973,986 | null | 123 | 123 |
from sys import stdin
n = int(stdin.readline().strip())
a_lst = [int(x) for x in stdin.readline().strip().split()]
pos = len(a_lst) // 2
min_diff = 10000000000000000000
while(True):
left = sum(a_lst[:pos])
right = sum(a_lst[pos:])
diff = right - left
if min_diff > abs(diff): min_diff = abs(diff)
else: break
if diff > 0: pos += 1
elif diff < 0: pos -= 1
print(min_diff) | N = int(input())
A = list(map(int,input().split()))
c = sum(A)/2
S = [0] * (N+1)
S[0] = 0
for i in range(N):
S[i+1] = A[i] + S[i]
m = float("INF")
j = -1
for i in range(1, N+1):
if abs(c - S[i]) < m:
m = abs(c - S[i])
j = i
print(abs((S[N] - S[j]) - S[j])) | 1 | 142,147,868,748,480 | null | 276 | 276 |
N,S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0]*(S+1) for _ in range(N)]
dp[0][0] = 2
if A[0] <= S:
dp[0][A[0]] = 1
for i in range(1,N):
for j in range(S+1):
if j-A[i] >= 0:
dp[i][j] = dp[i-1][j-A[i]] + 2*dp[i-1][j]
else:
dp[i][j] = 2*dp[i-1][j]
dp[i][j] %= mod
#print(dp)
print(dp[N-1][S]) | N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [0 for j in range(S + 1)]
dp[0] = 1
for i in range(N) :
for j in range(S, -1, -1) :
if j + A[i] <= S :
dp[j + A[i]] += dp[j]
dp[j + A[i]] %= mod
dp[j] *= 2
dp[j] %= mod
print(dp[S])
| 1 | 17,735,769,284,190 | null | 138 | 138 |
s = input()
small = 'abcdefghijklmnopqrstuvwxyz'
large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ''
for i in s:
q = 0
while q < 26:
if i == small[q]:
ans += large[q]
break
elif i == large[q]:
ans += small[q]
break
q += 1
if q == 26:
ans += i
print(ans)
| i = map(str, raw_input())
def check(x):
if x.islower():
return x.upper()
else:
return x.lower()
ret = []
for x in i:
ret += [check(x)]
print ''.join(ret) | 1 | 1,499,604,033,290 | null | 61 | 61 |
#!/usr/bin/python
# -*- coding: utf-8 -*-
# def
def int_mtx(N):
x = []
for _ in range(N):
x.append(list(map(int,input().split())))
return np.array(x)
def str_mtx(N):
x = []
for _ in range(N):
x.append(list(input()))
return np.array(x)
def int_map():
return map(int,input().split())
def int_list():
return list(map(int,input().split()))
def print_space(l):
return print(" ".join([str(x) for x in l]))
# import
import numpy as np
import collections as col
N = int(input())
ans = 0
for i in range(1,N):
if N%i != 0:
ans += N//i
else:
ans += N//i -1
print(ans)
| a, b = map(int, raw_input().split(" "))
if (a == b) :
print "a == b"
elif (a > b) :
print "a > b"
elif (a < b) :
print "a < b" | 0 | null | 1,467,478,660,000 | 73 | 38 |
def solve():
N, K, C = map(int, input().split())
S = input()
l_r,r_l = [0]*N,[0]*N
i,cnt = 0,0
while i<N and cnt<K:
if S[i]=='o':
l_r[i] = 1
cnt += 1
i += C
i += 1
j,cnt = N-1,0
while j>=0 and cnt<K:
if S[j]=='o':
r_l[j] = 1
cnt += 1
j -= C
j -= 1
ans = []
c_lr = 0
c_rl = 0
for i in range(1,N+1):
if l_r[i-1]:
c_lr += 1
if r_l[i-1]:
c_rl += 1
if l_r[i-1]*r_l[i-1]==1 and c_lr==c_rl:
ans.append(i)
return ans
print(*solve(),sep='\n') | #!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def calc(p, P):
ans = 0
for i in range(1, len(p)):
x1, y1 = P[p[i - 1]]
x2, y2 = P[p[i]]
ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
return ans
def solve():
N = int(input())
P = []
for _ in range(N):
X, Y = map(int, input().split())
P.append((X, Y))
ans = 0
num = 0
for p in permutations(range(N)):
ans += calc(p, P)
num += 1
print(ans / num)
def main():
solve()
if __name__ == '__main__':
main()
| 0 | null | 94,489,751,741,330 | 182 | 280 |
N = int(input())
dp = [[0] * 9 for _ in range(9)]
for i in range(1, N+1):
if i % 10 != 0:
si = str(i)
start = int(si[0])
fin = int(si[-1])
dp[start-2][fin-2] += 1
ans = 0
for i in range(9):
for j in range(9):
ans += dp[i][j] * dp[j][i]
print(ans)
| import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N,S=map(int,input().split())
A=list(map(int,input().split()))
# https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E9%A1%9E%E9%A1%8C-3
INF = 10**10 # INF+INFを計算してもオーバーフローしない範囲で大きく
MOD=998244353
I, J =N,S
# dpテーブル dp[i][j]:=i番目以下で選ばれしa_kの和がjになる通り数
dp = [[0]*(J+1) for _ in range(I+1)]
# 初期条件
dp[0][0] = 1
# ループ
for i in range(I):
for j in range(J+1):
dp[i+1][j]+=2*dp[i][j]
dp[i+1][j]%=MOD
if j+A[i]<=S:
dp[i+1][j+A[i]]+=dp[i][j]
dp[i+1][j+A[i]]%=MOD
print(dp[I][J])
resolve() | 0 | null | 52,208,265,317,690 | 234 | 138 |
N = int(input())
minP = N
count = 0
for pi in map(int, input().split()):
minP = min(minP, pi)
if pi <= minP:
count += 1
print(count) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
ans = 0
for x in range(1, n+1):
y = n // x
ans += y * (y + 1) * x // 2
print(ans) | 0 | null | 48,279,905,446,680 | 233 | 118 |
class UnionFind:
def __init__(self, num):
self.parent = [-1] * num
def find(self, node):
if self.parent[node] < 0:
return node
self.parent[node] = self.find(self.parent[node])
return self.parent[node]
def union(self, node1, node2):
node1 = self.find(node1)
node2 = self.find(node2)
if node1 == node2:
return
if self.parent[node1] > self.parent[node2]:
node1, node2 = node2, node1
self.parent[node1] += self.parent[node2]
self.parent[node2] = node1
return
def same(self, node1, node2):
return self.find(node1) == self.find(node2)
def size(self, x):
return -self.parent[self.find(x)]
def roots(self):
return [i for i, x in enumerate(self.parent) if x < 0]
def group_count(self):
return len(self.roots())
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
print(uf.group_count() - 1)
| class UnionFind():
def __init__(self,n):
self.n = n
self.parents = [-1] * (n+1)
def find(self, x):
if self.parents[x] < 0:
return x
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x,y = y,x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -1 * self.parents[x]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots()) - 1
N,M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
a,b = map(int, input().split())
uf.union(a,b)
ans = uf.group_count() - 1
print(ans)
| 1 | 2,272,527,162,460 | null | 70 | 70 |
from collections import deque
def solve(A, K):
a = deque() # 繰り返し部分
seen = [False for _ in range(len(A))] # 一度見たかどうか
cur = 0
while True:
# 一度通った頂点を見つけたときの処理
if seen[cur]:
while a[0] != cur:
# 最初の余計な数手分を除去する
K -= 1
a.popleft()
# K が限界になったらリターン
if K == 0:
return a[0] + 1
break
# 最初は愚直にシミュレーションしつつ、履歴をメモしていく
a.append(cur)
seen[cur] = True
cur = A[cur]
return a[K % len(a)] + 1
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [v - 1 for v in A]
print(solve(A, K)) | import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)
s = set([0])
# 再帰関数
def rec(visited,next):
if next in s:
# print(visited)
return visited,visited.index(next)
else:
s.add(next)
visited.append(next)
return rec(visited,a[next])
visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0])
# print(visited,loopStart)
if k < len(visited):
townIndex = visited[k]
else:
visitedLoop = visited[loopStart:]
# print(visitedLoop)
# 残り回数を循環配列の長さで割った余り
index = (k-(loopStart))%len(visitedLoop)
# print(index)
townIndex = visitedLoop[index]
print(townIndex+1) | 1 | 22,676,620,974,042 | null | 150 | 150 |
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M2 == M1 + 1 and D2 == 1 else 0) | import math , sys
from decimal import Decimal
A , B = list( map( Decimal , input().split()))
print( int(A * B ) ) | 0 | null | 70,374,022,573,922 | 264 | 135 |
input()
S=input()
print(1+sum(S[i]!=S[i+1]for i in range(len(S)-1))) | def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))
N = ri()
a = rls()
bubble = a[:]
flag = True
while(flag):
flag = False
for i in range(1, N):
if(bubble[-i][1] < bubble[-i-1][1]):
hold = bubble[-i]
bubble[-i] = bubble[-i-1]
bubble[-i-1] = hold
flag = True
pl(bubble)
print("Stable") # ?????????Stable
selection = a[:]
for i in range(N):
minj = i
for j in range(i, N):
if(selection[j][1] < selection[minj][1]):
minj = j
hold = selection[i]
selection[i] = selection[minj]
selection[minj] = hold
pl(selection)
print("Stable" if bubble == selection else "Not stable") | 0 | null | 84,731,916,882,702 | 293 | 16 |
#!/usr/bin/env python3
def main():
import sys
input = sys.stdin.readline
X = int(input())
for a in range(-150, 151):
for b in range(-150, 151):
if a ** 5 - b ** 5 == X:
print(a, b, sep=' ')
return
if __name__ == '__main__':
main()
| (a,b) = map(int,raw_input().split())
if a<b : print "a < b"
elif a>b : print "a > b"
else : print "a == b" | 0 | null | 13,034,556,631,426 | 156 | 38 |
a,b=input().split()
a=int(a)
b=int(b)
if a>=10:
print(b)
if a<10:
print(b+(100*(10-a))) | n = int(input())
A = list(map(int, input().split()))
total = 0
min_ = A[0]
for i in range(n):
if A[i] > min_:
min_ = A[i]
else:
total += (min_ - A[i])
print(total) | 0 | null | 33,999,912,293,668 | 211 | 88 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,K = LI()
f = [1]
r = [1]
s = 1
for i in range(1,N+2):
s = (s * i) % MOD
f.append(s)
r.append(pow(s,MOD-2,MOD))
def comb(a,b):
return f[a] * r[b] * r[a-b]
ans = 0
for k in range(min(K,N-1)+1):
ans = (ans + comb(N,k) * comb(N-1,k)) % MOD
print(ans)
if __name__ == '__main__':
main() | LARGE = 10 ** 9 + 7
def solve(n, k):
# singular cases
if k == 0:
return 1
elif k == 1:
return n * (n - 1)
# pow
pow_mod = [1] * (n + 1)
for i in range(n):
pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
pow_mod_inv = [1] * (n + 1)
pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
for i in range(n - 1, 0, -1):
pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE
res = 0
for i in range(min(k, n - 1) + 1):
# find where to set 0
pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
# how to assign ones
assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
res += pick_zeros * assign_ones
res %= LARGE
return res
def main():
n, k = map(int, input().split())
res = solve(n, k)
print(res)
def test():
assert solve(3, 2) == 10
assert solve(200000, 1000000000) == 607923868
assert solve(15, 6) == 22583772
if __name__ == "__main__":
test()
main()
| 1 | 66,784,971,570,048 | null | 215 | 215 |
n = int(input())
p = list(map(int, input().split()))
ret = 1
minp = p[0]
for i in range(1, n):
if p[i] <= minp:
ret += 1
minp = min(minp, p[i])
print(ret)
| n=int(input())
p=[int(x) for x in input().split()]
a=1
b=p[0]
for i in range(1,n):
if p[i-1]<b:
b=p[i-1]
if p[i]<=b:
a+=1
print(a) | 1 | 85,724,286,514,020 | null | 233 | 233 |
n, k = [int(i) for i in input().split()]
h = sorted([int(i) for i in input().split()])
if k > len(h):
print(0)
elif k == 0:
print(sum(h))
else:
print(sum(h[0:-k])) | n,k=map(int,input().split())
h=list(map(int,input().split()))
sum=0
h.sort()
h=h[:n-k]
if n <= k:
print(0)
exit()
else:
for i in h:
sum += i
print(sum) | 1 | 78,795,466,759,870 | null | 227 | 227 |
n=int(input())
r=list(map(int,input().split()))
s=0
for u in r: s^=u
t=[x ^ s for x in r]
print(*t) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
# あるbit列に対するコストの計算
def count(zerone):
one = 0
cnt = 0
for i in range(N):
flag = True
if zerone[i] == 1:
one += 1
for j in range(len(A[i])):
if A[i][j][1] != zerone[A[i][j][0]-1]:
flag = False
break
if flag:
cnt += 1
if cnt == N:
return one
else:
return 0
# bit列の列挙
def dfs(bits):
if len(bits) == N:
return count(bits)
res = 0
for i in range(2):
bits.append(i)
res = max(res, dfs(bits))
bits.pop()
return res
# main
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
a = int(input())
for _ in range(a):
A[i].append([int(x) for x in input().split()])
ans = dfs([])
print(ans) | 0 | null | 67,346,196,333,348 | 123 | 262 |
while True:
m, t, f = map( int, raw_input().split())
if m == -1 and t == -1 and f == -1:
break
if m == -1 or t == -1:
r = "F"
elif (m + t) >= 80:
r = "A"
elif (m + t) >= 65:
r = "B"
elif (m + t) >= 50:
r = "C"
elif (m + t) >= 30:
if f >= 50:
r = "C"
else:
r = "D"
else:
r = "F"
print r | import sys, math
from functools import lru_cache
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)]
def main():
N = ii()
s, t = [list(i) for i in zip(*[input().split() for i in range(N)])]
t = list(map(int, t))
k = s.index(input())
print(sum(int(t[i]) for i in range(k+1, N)))
if __name__ == '__main__':
main() | 0 | null | 49,190,690,908,160 | 57 | 243 |
def main():
N, X, T = map(int, input().split())
if N % X != 0:
print((N // X + 1) * T)
else:
print((N // X) * T)
main() | line = input()
N, X, T = (int(x) for x in line.split(" "))
print((N + X - 1) // X * T) | 1 | 4,309,398,317,128 | null | 86 | 86 |
a_1,a_2,a_3=map(int,input().split())
if a_1+a_2+a_3<=21:
print('win')
else:
print('bust') | def main():
A = map(int, input().split())
print('bust' if sum(A) >= 22 else 'win')
if __name__ == '__main__':
main()
| 1 | 118,748,474,809,248 | null | 260 | 260 |
S = list(input().split())
a = []
kazu = []
for i in range(1+10**6):
kazu.append(str(i))
for i in range(len(S)):
if S[i] in kazu:
a.append(int(S[i]))
elif S[i] == "+":
x = a.pop()
y = a.pop()
a.append(x+y)
elif S[i] == "-":
x = a.pop()
y = a.pop()
a.append(y-x)
elif S[i] == "*":
x = a.pop()
y = a.pop()
a.append(x*y)
print(a[0])
| S,T = map(int,input().split())
if S == T:
print('Yes')
else:
print('No') | 0 | null | 41,572,136,929,080 | 18 | 231 |
def inc3(i):
if i - (i // 10)*10 == 3:
return(True)
elif i//10==0:
return(False)
else:
return(inc3(i//10))
n = int(input())
for i in range(1,n+1):
if i%3==0 or inc3(i):
print(" " + str(i),end="")
print() | import sys
import bisect
N = int(input())
a = list(map(int,input().split()))
numdic = {}
for i, num in enumerate(a):
if num not in numdic:
numdic[num] = [i+1]
else:
numdic[num].append(i+1)
if 1 not in numdic:
print(-1)
sys.exit()
nowplace = 0
count = 0
for i in range(1,N+1):
if i not in numdic:
break
else:
place = bisect.bisect_right(numdic[i], nowplace)
if place >= len(numdic[i]):
break
else:
nowplace = numdic[i][place]
count += 1
print(N-count) | 0 | null | 58,061,290,147,040 | 52 | 257 |
h, w, k = map(int, input().split())
A =[]
for i in range(h):
a = input()
A.append([a[i] == "#" for i in range(w)])
ans = 0
for bit in range(1 << h):
for tib in range(1 << w):
now = 0
for i in range(h):
for j in range(w):
if(bit >> i) & 1 == 0 and (tib >> j) & 1 == 0 and A[i][j] == True: now += 1
if now == k: ans += 1
print(ans) | n,m,k = map(int,input().split())
ans = 0
g = [[i for i in input()] for i in range(n)]
for maskY in range(1 << n):
ng = [[0]*m for i in range(n)]
for bit in range(n):
if maskY & (1 << bit):
for i in range(m):
ng[bit][i] = 1
for maskX in range(1 << m):
ngg = [[i for i in j] for j in ng]
# print(ngg)
for bit in range(m):
if maskX & (1 << bit):
for i in range(n):
ngg[i][bit] = 1
cnt = 0
for y in range(n):
for x in range(m):
if g[y][x]=="#" and ngg[y][x]==0:
cnt += 1
# print(cnt)
if cnt == k:
ans += 1
print(ans) | 1 | 8,874,556,589,220 | null | 110 | 110 |
n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 16
a_1 = 0
a_2 = sum(a)
for i in range(n - 1):
a_1 += a[i]
a_2 -= a[i]
ans = min(ans, abs(a_1 - a_2))
print(ans) | N = int(input())
A = [int(i) for i in input().split()]
l = sum(A)
ans = float("inf")
t = 0
for i in range(N-1):
t += A[i]
ans = min(ans,abs(l-2*t))
#print("t,ans",t,ans)
print(ans)
| 1 | 142,364,051,521,944 | null | 276 | 276 |
r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
ri, ci, vi = map(int, input().split())
v[ri - 1][ci - 1] = vi
dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
for j in range(c):
dpj = dp[j][:]
if j == 0:
dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
else:
dp[j][0] = max(max(dpj), dp[j - 1][0])
dp[j][1] = dp[j - 1][1]
dp[j][2] = dp[j - 1][2]
dp[j][3] = dp[j - 1][3]
if v[i][j] > 0:
dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])
print(max(dp[c - 1]))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
if __file__=="test.py":
f = open("./in_out/input.txt", "r", encoding="utf-8")
read = f.read
readline = f.readline
def main():
R, C, K = map(int, readline().split())
L_INF = int(1e17)
dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K):
x, y, c = map(int, readline().split())
cell[x-1][y-1] = c
dp[0][0][1] = dp[0][1][0] = 0
for i in range(1, R + 1):
for j in range(1, C + 1):
for k in range(4):
if k > 0:
dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
if k > 0:
dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + cell[i-1][j-1])
if k == 1:
dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
print(dp[3][R][C])
if __name__ == "__main__":
main()
| 1 | 5,576,088,386,418 | null | 94 | 94 |
class Dice:
def __init__(self, labels):
self._top = labels[0]
self._front = labels[1]
self._right = labels[2]
self._left = labels[3]
self._back = labels[4]
self._bottom = labels[5]
def top(self):
return self._top
def front(self):
return self._front
def right(self):
return self._right
def left(self):
return self._left
def back(self):
return self._back
def bottom(self):
return self._bottom
def role(self, directions):
for d in directions:
self._role1(d)
def _role1(self, d):
if d == "N":
self._top, self._front, self._bottom, self._back = \
self._front, self._bottom, self._back, self._top
elif d == "E":
self._top, self._left, self._bottom, self._right = \
self._left, self._bottom, self._right, self._top
elif d == "S":
self._top, self._back, self._bottom, self._front = \
self._back, self._bottom, self._front, self._top
else:
self._top, self._right, self._bottom, self._left = \
self._right, self._bottom, self._left, self._top
xs = list(map(int, input().split()))
directions = input()
dice = Dice(xs)
dice.role(directions)
print(dice.top())
| class Dice(object):
"""docstring for Dice"""
def __init__(self, numeric_column):
self.numeric_column=numeric_column
def roll_to_S_direction(self):
self.numeric_column=[self.numeric_column[4],self.numeric_column[0],self.numeric_column[2],self.numeric_column[3],self.numeric_column[5],self.numeric_column[1]]
def roll_to_N_direction(self):
self.numeric_column=[self.numeric_column[1],self.numeric_column[5],self.numeric_column[2],self.numeric_column[3],self.numeric_column[0],self.numeric_column[4]]
def roll_to_E_direction(self):
self.numeric_column=[self.numeric_column[3],self.numeric_column[1],self.numeric_column[0],self.numeric_column[5],self.numeric_column[4],self.numeric_column[2]]
def roll_to_W_direction(self):
self.numeric_column=[self.numeric_column[2],self.numeric_column[1],self.numeric_column[5],self.numeric_column[0],self.numeric_column[4],self.numeric_column[3]]
dice=Dice(map(int,raw_input().split()))
direction=raw_input()
for i in direction:
if i=='S': dice.roll_to_S_direction()
elif i=='N': dice.roll_to_N_direction()
elif i=='E': dice.roll_to_E_direction()
else: dice.roll_to_W_direction()
print dice.numeric_column[0] | 1 | 243,826,898,920 | null | 33 | 33 |
from collections import Counter
def prime_factorize(n):
res = []
while n % 2 == 0:
res.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
res.append(f)
n //= f
else:
f += 2
if n != 1:
res.append(n)
return res
n = int(input())
prime_numbers = prime_factorize(n)
prime_counter = Counter(prime_numbers)
ans = 0
for v in prime_counter.values():
i = 1
while v >= i:
ans += 1
v -= i
i += 1
print(ans) | while True:
n, x = map(int, input().split())
if n == 0 and x == 0:
break
else:
counter = 0
for a in range(1,(x // 3)):
for c in range ((x//3)+1,n+1):
b = x - a - c
if a < b < c:
counter += 1
print(counter) | 0 | null | 9,152,691,007,152 | 136 | 58 |
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a = np.array(a, dtype='int64')
MOD = 10**9+7
ans = 0
for i in range(60):
ca = a >> i & 1
c1 = int(ca.sum())
c0 = n - c1
c0c1 = (c0 * c1) % MOD
c0c1pow = (c0c1 * 2**i) % MOD
ans = (ans + c0c1pow) % MOD
print(ans) | from collections import deque
N = int(input())
A = deque(map(int, input().split()))
mod = 10**9 + 7
M = len(bin(max(A))) - 2
ans = 0
bitlist = [1]
for k in range(M):
bitlist.append(bitlist[-1]*2%mod)
counter = [0 for _ in range(M)]
for k in range(N):
a = A.pop()
c = 0
while c < M:
b = a & 1
if b == 0:
ans += counter[-c-1]*bitlist[c]%mod
ans %= mod
else:
ans += (k-counter[-c-1])*bitlist[c]%mod
ans %= mod
counter[-c-1] += 1
c += 1
a >>= 1
print(ans)
| 1 | 122,900,311,478,620 | null | 263 | 263 |
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
S = str(input())
if S[2] == S[3] and S[4] == S[5]:
ans = "Yes"
else:
ans = "No"
print(ans) | N, M = (int(x) for x in input().split())
if N==M:
print("Yes")
else:
print("No") | 0 | null | 62,632,233,188,420 | 184 | 231 |
# A - November 30
def main():
M1, _, M2, _ = map(int, open(0).read().split())
print(int(M1 != M2))
if __name__ == "__main__":
main()
| import heapq
x,y,a,b,c = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
x_tmp = P[:x]
y_tmp = Q[:y]
tmp_li = x_tmp+y_tmp
heapq.heapify(tmp_li)
for i in range(c):
if R[i]>tmp_li[0]:
heapq.heapreplace(tmp_li,R[i])
print(sum(tmp_li)) | 0 | null | 84,687,623,748,168 | 264 | 188 |
n,a,b= map(int,input().split())
loop = n//(a+b)
r = n%(a+b)
before_count = loop * a
after_count = min(r,a)
ans = before_count + after_count
print(ans) | n,a,b = map(int,input().split())
cnt = n//(a+b)
rem = n-cnt*(a+b)
ans = cnt*a
if(rem > a):
ans += a
else:
ans += rem
print(ans)
| 1 | 55,694,779,440,432 | null | 202 | 202 |
W = input().rstrip().lower()
ans = 0
while True:
line = input().rstrip()
if line == 'END_OF_TEXT': break
line = line.lower().split(' ')
for word in line:
if word == W: ans += 1
print(ans)
| w = input().casefold()
c = 0
while True:
_ = input()
if(_ == "END_OF_TEXT"):
break
t = _.casefold().split()
c += t.count(w)
print(c) | 1 | 1,839,068,614,240 | null | 65 | 65 |
def binary_search(border, b):
ok = b
ng = n
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if L[mid] < border:
ok = mid
else:
ng = mid
return ok
n = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(0,n-1):
for b in range(a+1, n):
a_b = L[a] + L[b]
ans += binary_search(a_b, b) - b
print(ans) | n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(0,n-2):
for j in range(i+1,n-1):
left = j
right = n
while right-left>1:
mid = (left + right)//2
if l[i]+l[j]>l[mid] and l[i]+l[mid]>l[j] and l[mid]+l[j]>l[i]:
left = mid
else:
right = mid
#print(i,j,left)
ans+=(left-j)
print(ans) | 1 | 171,258,184,853,366 | null | 294 | 294 |
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7
def main():
n, x, t = rli()
q, r = divmod(n, x)
ans = q*t
if r > 0:
ans += t
print(ans)
stdout.close()
if __name__ == "__main__":
main() | n, x, t = [int(n) for n in input().split(' ')]
a = n // x * t
if n % x != 0:
a += t
print(a)
| 1 | 4,291,437,831,232 | null | 86 | 86 |
n = int(input())
ans = (n//2) + (n%2)
print (ans) | # input
n,a,b = list(map(int,input().split()))
p=10**9+7
#全体の組み合わせの数:All
all_ = pow(2,n,p)
#n本からi本選ぶ組み合わせの数:C[i],i:0~b
C_=[1]*(b+10)
for i in range(1,b+1):
C_[i] = (C_[i-1] * (n-i+1)%p * pow(i,p-2,p))%p
# C_
ans = (all_-C_[a]-C_[b])%p
print(ans-1) | 0 | null | 62,836,057,937,686 | 206 | 214 |
def main():
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i, a in enumerate(A):
if i % 2 == 0 and a % 2 == 1:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| s = list(input())
q = int(input())
for i in range(q):
cmd = list(input().split())
m = int(cmd[1])
n = int(cmd[2])
if cmd[0] == "print":
for i in range(m, n + 1):
print(s[i], end="")
print()
if cmd[0] == "reverse":
half = int((n - m) / 2)
while m <= half\
or m < n:
t = s[m]
s[m] = s[n]
s[n] = t
m += 1
n -= 1
if cmd[0] == "replace":
r = cmd[3]
j = 0
for i in range(m, n + 1):
s[i] = r[j]
j += 1 | 0 | null | 4,908,909,847,442 | 105 | 68 |
n = int(input())
s = []
t = []
for _ in range(n):
name,time = map(str,input().split())
s.append(name)
t.append(int(time))
target = input()
start = s.index(target)
ans = 0
for i in range(start+1,n):
ans += t[i]
print(ans) | n=int(input())
s=[""]*n
t=[0]*n
for i in range(n):
s[i],t[i]=input().split()
t[i]=int(t[i])
x=input()
c=0
for i in range(n):
if s[i]==x:
c=i
break
ans=0
for i in range(c+1,n):
ans+=t[i]
print(ans) | 1 | 97,070,783,505,570 | null | 243 | 243 |
n = float(input())
print(n * n * n / 27) | n=int(input())
print((n/3)*(n/3)*(n/3)) | 1 | 46,745,639,758,860 | null | 191 | 191 |
import math
N=int(input())
A=[int(x) for x in input().split()]
ans=0
A=sorted(A)
ans+=A[N-1]
for i in range(1,N-1):
ans+=A[N-1-math.ceil(i/2)]
print(ans) | def chess(h,w):
o = ""
for i in range(h):
if i%2:
if w%2: o+= ".#"*(w/2)+".\n"
else: o+= ".#"*(w/2)+"\n"
else:
if w%2: o+= "#."*(w/2)+"#\n"
else: o+= "#."*(w/2)+"\n"
print o
while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
chess(h,w) | 0 | null | 5,066,515,110,830 | 111 | 51 |
import sys
import math
import bisect
def main():
n = int(input())
ans = ((n+1)//2) / n
print('%.10f' % ans)
if __name__ == "__main__":
main()
| #142-A
N = int(input())
D = []
for i in range(1,N+1):
D.append(i)
#print(D)
cnt = 0
for j in D:
if j % 2 != 0:
cnt += 1
#print(cnt)
print(cnt / len(D))
| 1 | 177,642,218,304,360 | null | 297 | 297 |
x = input()
for i in range(int(input())):
o = input().split()
a,b = map(int,o[1:3])
b+=1
t = o[0][2]
if t == 'i':
print(x[a:b])
elif t =='p':
x = x[:a] + o[3] + x[b:]
else:
x = x[:a] + x[a:b][::-1] + x[b:]
| s = input()
for _ in range(int(input())):
c = input().split()
a = int(c[1])
b = int(c[2])
if c[0] == "replace":
s = s[:a] + c[3] + s[b+1:]
elif c[0] == "reverse":
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
else:
print(s[a:b+1])
| 1 | 2,086,800,875,080 | null | 68 | 68 |
from sys import stdin
from copy import deepcopy
import queue
class Dice:
def __init__(self, nums):
self.labels = [None] + [ nums[i] for i in range(6) ]
self.pos = {
"E" : 3,
"W" : 4,
"S" : 2,
"N" : 5,
"T" : 1,
"B" : 6
}
def rolled(dice, queries):
d = deepcopy(dice)
for q in queries:
if q == "E":
d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
elif q == "W":
d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
elif q == "S":
d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
elif q == "N":
d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
else:
return d
nums = [int(x) for x in stdin.readline().rstrip().split()]
q = int(stdin.readline().rstrip())
dice = Dice(nums)
# TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする
memo = [[False] * 7 for i in range(7)]
memo[dice.pos["T"]][dice.pos["S"]] = ""
# クエリとさいころの東面を記憶
res = { "" : dice.labels[dice.pos["E"]] }
# BFSで探索, 解を求めたらreturn Trueで抜け出す
# diceの中身をいじってはならない
def solve(T, S):
if isinstance(memo[T][S], str):
return memo[T][S]
que = queue.Queue()
que.put(dice)
sol_q = ["E", "N", "S", "W"]
while not que.empty():
d = que.get()
if d.pos["T"] == T and d.pos["S"] == S:
break
else:
for i in sol_q:
d_next = Dice.rolled(d, i)
if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
que.put(d_next)
memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next.labels[d_next.pos["E"]]
else:
return memo[T][S]
for i in range(q):
ts = [int(x) for x in stdin.readline().rstrip().split()]
T = dice.labels.index(ts[0])
S = dice.labels.index(ts[1])
if solve(T, S) != False:
print(res[memo[T][S]])
| class Dice:
def make_dice(self, value):
self.face = value
def move(self, direc):
if direc == "N":
self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
return self.face
elif direc == "E":
self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
return self.face
elif direc == "S":
self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
return self.face
elif direc == "W":
self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
return self.face
def get_face(self, top):
if top == self.face[0]:
return self.face
elif top == self.face[1]:
return dice.move("N")
elif top == self.face[2]:
return dice.move("W")
elif top == self.face[3]:
return dice.move("E")
elif top == self.face[4]:
return dice.move("S")
elif top == self.face[5]:
dice.move("N")
return dice.move("N")
def right_face(self, face1, face2):
if face2 == self.face[1]:
return self.face[2]
elif face2 == self.face[2]:
return self.face[4]
elif face2 == self.face[4]:
return self.face[3]
elif face2 == self.face[3]:
return self.face[1]
num = list(map(int, input().split()))
q = int(input())
dice = Dice()
for i in range(q):
dice.make_dice(num)
f1, f2 = map(int,input().split())
dice.get_face(f1)
print(dice.right_face(f1,f2))
| 1 | 253,362,762,540 | null | 34 | 34 |
N = int(input())
S = input()
d = {
'R': {},
'G': {},
'B': {}
}
for i, s in enumerate(S):
d[s][i] = True
answer = len(d['R']) * len(d['G']) * len(d['B'])
for r in d['R'].keys():
for g in d['G'].keys():
if 2 * r - g in d['B']:
answer -= 1
if 2 * g - r in d['B']:
answer -= 1
if ((r + g) % 2 == 0 and ((r + g) // 2) in d['B']):
answer -= 1
print(answer) | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
l = LI()
l.sort()
ans = 0
for i in range(n):
for j in range(i):
mini = l[i] - l[j]
if mini < l[j]:
ans += n-bisect.bisect_right(l, mini) - (n-j)
print(ans)
main()
| 0 | null | 103,812,342,591,712 | 175 | 294 |
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
N = int(input())
fac = factorization(N)
result = 0
for div in fac:
if div[0] == 1:
continue
i = 1
count = 1
while i <= div[1]:
result += 1
count += 1
i += count
print(result)
| from math import sqrt
def eratosthenes(x):
prime = []
for i in range(2, int(sqrt(x)) + 1):
if x % i == 0:
prime.append(i)
while x % i == 0:
x //= i
return prime
N = int(input())
prime = eratosthenes(N)
ans = 0
for x in prime:
i = 1
while N % x**i == 0:
ans += 1
N //= x**i
i += 1
while N % x == 0:
N //= x
if N > 1:
ans += 1
print(ans) | 1 | 16,869,726,077,344 | null | 136 | 136 |
N,X,T = map(int,input().split())
quo,mod = divmod(N,X)
if mod == 0:
print(T*quo)
else:
print(T*(quo+1)) | line = input()
N, X, T = (int(x) for x in line.split(" "))
print((N + X - 1) // X * T) | 1 | 4,307,402,635,316 | null | 86 | 86 |
# coding: utf-8
from itertools import count
def merge(A, left, mid, right):
global counter
n1, n2 = mid - left, right - mid
L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
counter += right - left
def mergeSort(A, left, right):
if left+1 < right:
mid = (left + right)//2;
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter) | n = int(input())
taro = 0
hana = 0
for _ in range(n):
taro_c, hana_c = input().split()
if taro_c > hana_c:
taro += 3
elif hana_c > taro_c:
hana += 3
else:
taro += 1
hana += 1
print(taro, hana) | 0 | null | 1,033,328,465,018 | 26 | 67 |
N = int(input())
print(N//2 if N%2 else N//2-1) | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
S = "abcdefghijk"
# q = [("", -1)]
ans = 0
def dfs(a, mx):
# q = [(cur, mx)]
# while q:
# a, mx = q.pop()
if len(a) == N:
print(a)
return
for c in range(len(S[:mx+2])):
t = a
t += S[:mx+2][c]
dfs(t, max(c, mx))
dfs("", -1)
| 0 | null | 102,625,681,857,700 | 283 | 198 |
def dfs(G,n):
global ptr
#探索済
seen[n] = True
#行き
F[n] = ptr
ptr += 1
for i in G[n]:
#次に行けるかを判定
if seen[i] == True :
continue
dfs(G,i)
#帰り
L[n] = ptr
ptr += 1
if __name__ == '__main__':
n = int(input())
G = [[] for _ in range(n+1)]
F = [0 for _ in range(n+1)]
L = [0 for _ in range(n+1)]
#深さ優先探索
#探索済配列
seen = [False for _ in range(n+1)]
for i in range(n):
cmd = list(map(int,input().split()))
m = cmd[1]
if m != 0:
for j in range(m):
G[i+1].append(cmd[j+2])
ptr = 1
for i in range(1,n):
if seen[i] == False :
dfs(G,i)
for i in range(1,n+1):
print(i,F[i],L[i])
| print(sum(s!=t for s,t in zip(input(),input()))) | 0 | null | 5,255,820,254,692 | 8 | 116 |
from sys import exit
n, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
done = [-1 for _ in range(n)]
tmp = 0
done[0] = 0
for k in range(1, K + 1):
tmp = A[tmp]
if done[tmp] >= 0:
for i in range((K - done[tmp]) % (k - done[tmp])):
tmp = A[tmp]
print(tmp + 1)
exit()
else:
done[tmp] = k
print(tmp + 1)
| n,k = map(int,input().split())
b = [bi-1 for bi in list(map(int,input().split()))]
a = 0
f = [0]*n
c = 1
for i in range(k):
if f[a]:
k %= c-f[a]
for i in range(k):
a = b[a]
print(a+1)
break
f[a] = c
k -= 1
c += 1
a = b[a]
else:
print(a+1) | 1 | 22,854,281,890,296 | null | 150 | 150 |
while True:
m, f, r = (int(x) for x in input().split())
if (m, f, r) == (-1, -1, -1):
break
sum_score = m + f
if m == -1 or f == -1:
print("F")
elif sum_score >= 80:
print("A")
elif 65 <= sum_score < 80:
print("B")
elif 50 <= sum_score < 65:
print("C")
elif 30 <= sum_score < 50:
print("C") if r >= 50 else print("D")
else:
print("F") | while True:
m, f, r = map(int, input().split())
score = ""
if all([x < 0 for x in [m, f, r]]):
break
if any([x < 0 for x in [m, f]]):
score = "F"
elif 80 <= m+f:
score = "A"
elif 65 <= m+f:
score = "B"
elif 50 <= m+f or (30 <= m+f and 50 <= r):
score = "C"
elif 30 <= m+f:
score = "D"
else:
score = "F"
print(score)
| 1 | 1,240,069,552,822 | null | 57 | 57 |
n,a,b=map(int,input().split())
res=n//(a+b)*a
if n%(a+b)>=a:
res+=a
else:
res+=n%(a+b)
print(res) | import sys
a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
cnt = 0
i = a
while i <= b:
if ( c % i ) == 0:
cnt += 1
i += 1
print( "{}".format( cnt ) ) | 0 | null | 27,902,849,145,470 | 202 | 44 |
n = int(input())
S = input()
a = ord('A')
z = ord('Z')
ans = ''
for s in S:
if ord(s) + n <= 90:
ans += chr(ord(s) + n)
else:
ans += chr(a + ord(s) + n - z - 1)
print(ans)
| N = int(input())
S = list(input())
l = []
for i in S:
if ord(i)+N > 90:
l.append(chr(64+(ord(i)+N)%90))
else:
l.append(chr(ord(i)+N))
print("".join(l)) | 1 | 134,510,772,128,942 | null | 271 | 271 |
A, B, N = map(int,input().split())
x = min(B-1, N)
print((A * x) // B - A * int(x // B))
| N, K = map(int, input().split())
result = 1
for i in range(K, N+1):
tmp_min = (i - 1) * i // 2
tmp_max = (N * (N + 1) - (N - i) * (N - i + 1)) // 2
result += tmp_max - tmp_min + 1
result %= 10 ** 9 + 7
print(result)
| 0 | null | 30,821,220,853,124 | 161 | 170 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
SI = lambda : sys.stdin.readline().rstrip()
N,D,A = LI()
X = []; XH = []
for _ in range(N):
x,h = LI()
X.append(x); XH.append((x,h))
XH.sort()
X.sort()
down = [0] * (N+1)
p = 0
ans = 0
for i in range(N):
if p < XH[i][1]:
b = -(-(XH[i][1]-p)//A)
ans += b
p += b * A
down[bisect.bisect(X,X[i]+2*D)-1] += b*A
p -= down[i]
print(ans)
if __name__ == '__main__':
main() | import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, d, a = map(int, input().split())
XH = sorted([list(map(int, input().split())) for _ in range(n)])
res = 0
tt_dmg = 0
que = deque()
for x, h in XH:
while que and que[0][1] < x:
dmg, rng = que.popleft()
tt_dmg -= dmg
if tt_dmg < h:
h -= tt_dmg
cnt = (h + a - 1) // a
res += cnt
dmg = cnt * a
tt_dmg += dmg
que.append((dmg, x + d * 2))
print(res)
if __name__ == '__main__':
resolve()
| 1 | 82,373,916,046,422 | null | 230 | 230 |
import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)
def main():
m, d = na()
n, s = na()
if s == 1:
print(1)
else:
print(0)
if __name__ == '__main__':
main() | a=input().split()
b=input().split()
if a[0] != b[0]:
print("1")
else:
print("0")
| 1 | 124,377,232,938,430 | null | 264 | 264 |
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:x]
q = q[:y]
l = p + q + r
l.sort(reverse = True)
print(sum(l[:x+y])) | def main():
N = int(input())
S = str(input())
ans = 0
for i in range(N - 2):
if S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C':
ans += 1
print(ans)
main() | 0 | null | 71,648,940,305,342 | 188 | 245 |
import sys
from io import StringIO
import unittest
import os
from collections import deque
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 h, w = map(int, input().split())
# 1行N項目 x = list(map(int, input().split()))
# N行1項目 x = [int(input()) for i in range(n)]
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
# 文字取得サンプル
# 1行1項目 x = input()
# 1行1項目(1文字ずつリストに入れる場合) x = list(input())
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
start_list = []
for i_len, i in enumerate(range(h)):
for j_len, j in enumerate(range(w)):
route = 4
# 自分が壁なら対象外
if maze[i][j] == "#":
continue
# 上下端なら-1
route -= 1 if i_len == 0 else 0
route -= 1 if i_len + 1 == h else 0
# 上下が壁なら-1
route -= 1 if not i_len == 0 and maze[i - 1][j] == "#" else 0
route -= 1 if not i_len + 1 == h and maze[i + 1][j] == "#" else 0
# 左右端なら-1
route -= 1 if j_len == 0 else 0
route -= 1 if j_len + 1 == w else 0
# 左右が壁なら-1
route -= 1 if not j_len == 0 and maze[i][j - 1] == "#" else 0
route -= 1 if not j_len + 1 == w and maze[i][j + 1] == "#" else 0
if route <= 2:
start_list.append((i, j))
ans = 0
que = deque()
for start in start_list:
que.appendleft(start)
ed_list = [[-1 for i in range(w)] for j in range(h)]
ed_list[start[0]][start[1]] = 0
# BFS開始
while len(que) is not 0:
now = que.pop()
# 各方向に移動
for i, j in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
# 処理対象の座標
target = [now[0] + i, now[1] + j]
# 処理対象のチェック
# 外なら何もしない
if not 0 <= target[0] < h or not 0 <= target[1] < w:
continue
# 距離が設定されているなら何もしない
if ed_list[target[0]][target[1]] != -1:
continue
# 壁なら何もしない
if maze[target[0]][target[1]] == "#":
continue
# 処理対象に対する処理
# キューに追加(先頭に追加するのでappendleft())
que.appendleft(target)
# 距離を設定(現在の距離+1)
ed_list[target[0]][target[1]] = ed_list[now[0]][now[1]] + 1
ans = max(ans, ed_list[target[0]][target[1]])
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 = """4"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """3 5
...#.
.#.#.
.#..."""
output = """10"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def test_1original_1(self):
test_input = """1 2
.."""
output = """1"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| h,w=[int(x) for x in input().rstrip().split()]
l=[list(input()) for i in range(h)]
move=[[1,0],[-1,0],[0,-1],[0,1]]
def bfs(x,y):
stack=[[x,y]]
done=[[False]*w for i in range(h)]
dist=[[0]*w for i in range(h)]
max_val=0
while(stack):
nx,ny=stack.pop(0)
done[ny][nx]=True
for dx,dy in move:
mx=nx+dx
my=ny+dy
if not(0<=mx<=w-1) or not(0<=my<=h-1) or done[my][mx]==True or l[my][mx]=="#":
continue
done[my][mx]=True
dist[my][mx]=dist[ny][nx]+1
max_val=max(max_val,dist[my][mx])
stack.append([mx,my])
return max_val
ans=0
for i in range(w):
for j in range(h):
if l[j][i]!="#":
now=bfs(i,j)
ans=max(ans,now)
print(ans) | 1 | 94,997,779,671,088 | null | 241 | 241 |
import math
def main():
x1, y1, x2, y2 = map(float, input().split())
ans = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print(ans)
if __name__ == "__main__":
main() | a, b, c, d = [float(temp) for temp in input().split()]
from math import sqrt
dis = sqrt((c - a) ** 2 + (d - b) ** 2)
print('%0.5f'%dis) | 1 | 156,312,211,592 | null | 29 | 29 |
k = int(input())
hp = [i for i in range(k+4)]
r, w = 1, 10
while w <= k:
n = hp[r]
r += 1
nm = n % 10
val = n * 10 + nm
if nm != 0:
hp[w] = val - 1
w += 1
hp[w] = val
w += 1
if nm != 9:
hp[w] = val + 1
w += 1
print(hp[k]) | def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
from math import gcd
mod = int(1e9+7)
n = ii()
cnd = {}
azero = 0
bzero = 0
allzero = 0
for _ in range(n):
a,b = iim()
if a*b == 0:
if a == 0 and b != 0:
azero += 1
elif a != 0 and b == 0:
bzero += 1
else:
allzero += 1
else:
g = gcd(a,b)
a //= g
b //= g
if a<0:
a *= -1
b *= -1
before = cnd.get((a,b),False)
if b > 0:
check = cnd.get((b,-a),False)
else:
check = cnd.get((-b,a),False)
if before:
cnd[(a,b)] = [before[0]+1,before[1]]
elif check:
if b > 0:
cnd[(b,-a)] = [check[0],check[1]+1]
else:
cnd[(-b,a)] = [check[0],check[1]+1]
else:
cnd[(a,b)] = [1,0]
cnd[0] = [azero,bzero]
noreg = 0
ans = 1
#print(cnd)
for item in cnd.values():
if item[0] == 0 or item[1] == 0:
noreg += max(item[0],item[1])
else:
ans *= (2**item[0]+2**item[1]-1)
ans %= mod
print((ans*((2**noreg)%mod)-1+allzero)%mod) | 0 | null | 30,311,064,933,672 | 181 | 146 |
import itertools
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 9)
M = 1000000007
N = int(sys.stdin.readline())
left = list(map(int, sys.stdin.read().split()))
counter = Counter(left)
def dp(t, ns):
cached = t.get(ns)
if cached is not None:
return cached
remaining = sum(ns)
assert remaining > 0
last_cnt = left[remaining - 1] + 1
n1, n2, n3 = ns
res = 0
if last_cnt == n1:
res += dp(t, tuple(sorted([n1 - 1, n2, n3])))
res %= M
if last_cnt == n2:
res += dp(t, tuple(sorted([n1, n2 - 1, n3])))
res %= M
if last_cnt == n3:
res += dp(t, tuple(sorted([n1, n2, n3 - 1])))
res %= M
# print(f"{remaining}: ({n1},{n2},{n3}) => {res}")
t[ns] = res
return res
def solve():
h = [0, 0, 0]
for i in range(N):
k = counter[i]
if k == 3:
h[0] = h[1] = h[2] = i + 1
elif k == 2:
h[0] = h[1] = i + 1
elif k == 1:
h[0] = i + 1
else:
break
if sum(h) != N:
return 0
t = dict()
t[0, 0, 0] = 1
res = dp(t, tuple(sorted(h)))
return (res * len(set(itertools.permutations(h)))) % M
print(solve())
| t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
d1=t1*a1+t2*a2
d2=t1*b1+t2*b2
import sys
if d1>d2:
dif=d1-d2
gap=(b1-a1)*t1
elif d1<d2:
dif=d2-d1
gap=(a1-b1)*t1
else:
print('infinity')
sys.exit()
if (b1-a1)*(b2-a2)>0 or (b1-a1)*(d2-d1)>0:
print(0)
sys.exit()
if gap%dif!=0:
print(gap//dif*2+1)
else:
print(gap//dif*2) | 0 | null | 130,839,096,547,640 | 268 | 269 |
import sys
sys.setrecursionlimit(10**9)
n,m = list(map(int,input().split()))
d = {}
for i in range(m):
fr, to = list(map(int,input().split()))
d[fr] = d.get(fr, []) + [to]
d[to] = d.get(to, []) + [fr]
visited = [0 for i in range(n+1)]
def connect(node, i):
visited[node] = i
if node in d:
for neig in d[node]:
if visited[neig] == 0:
connect(neig, i)
ans = 1
for key in range(1,n+1):
if visited[key] == 0:
connect(key, ans)
ans += 1
print(max(visited)-1)
| class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
n,m = map(int,input().split())
u = UnionFind(n)
for _ in range(m):
ai,bi = map(int,input().split())
u.union(ai,bi)
s = [0 for _ in range(n+1)]
for i in range(1,n+1):
s[u.find(i)] = 1
print(sum(s)-1) | 1 | 2,309,015,656,738 | null | 70 | 70 |
from collections import defaultdict
from math import gcd
def main():
N = int(input())
MOD = 10 ** 9 + 7
zero = 0
d = defaultdict(lambda: defaultdict(int))
for i in range(N):
A, B = map(int, input().split())
if A == 0 and B == 0:
zero += 1
continue
if B < 0:
A = -A
B = -B
flag = False
if A <= 0:
A, B = B, -A
flag = True
g = gcd(A,B)
A //= g
B //= g
if flag:
d[(A,B)]['first'] += 1
else:
d[(A,B)]['second'] += 1
ans = 1
for i, j in d.items():
now = 1
now += pow(2,j['first'],MOD) - 1
now += pow(2,j['second'],MOD) - 1
ans *= now
ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | strargs = input()
n, a, b = map(lambda x: int(x), strargs.split())
if (b - a) % 2 == 0:
print((b - a)//2)
elif a - 1 < n - b:
newB = b - a
mid = (newB - 1)//2 + 1
print(a + mid - 1)
else:
newA = (a + (n - b + 1))
mid = newA + (n - newA)//2
print((n - b + 1) + (n - newA)//2) | 0 | null | 65,095,842,004,960 | 146 | 253 |
DE = 10**9 + 7
N, K = list(map(lambda x: int(x), input().split(' ')))
A = list(map(lambda x: int(x), input().split(' ')))
def main():
A_posi = []
A_nega = []
for a in A:
if a > 0:
A_posi.append(a)
elif a < 0:
A_nega.append(-a)
len_posi = len(A_posi)
len_nega = len(A_nega)
if len_posi + len_nega < K:
return 0
if (len_nega % 2 == 1 and K == len_posi + len_nega) or (K % 2 == 1 and len_posi == 0):
if len_posi + len_nega == N:
A_posi.sort()
A_nega.sort()
answer = 1
k = 0
for a in A_nega:
answer *= (- a) % DE
answer %= DE
k += 1
if k >= K:
break
else:
for a in A_posi:
answer *= a % DE
answer %= DE
k += 1
if k >= K:
break
return answer
else:
return 0
A_posi.sort(reverse=True)
A_nega.sort(reverse=True)
posi = 0
nega = 0
answer = 1
if K % 2 == 1:
answer = A_posi[0] % DE
posi = 1
while posi + nega + 2 <= K:
p = A_posi[posi] * A_posi[posi + 1] if posi + 1 < len_posi else 0
n = A_nega[nega] * A_nega[nega + 1] if nega + 1 < len_nega else 0
if p > n:
answer *= p % DE
answer %= DE
posi += 2
else:
answer *= n % DE
answer %= DE
nega += 2
return answer
print(main()) | list1 = input().split(" ")
if int(list1[0]) <= int(list1[1]) * int(list1[2]):
print("Yes")
else:
print("No") | 0 | null | 6,538,473,790,212 | 112 | 81 |
t="qwertyuioplkjhgfdsazxcvbnm"
T="QWERTYUIOPLKJHGFDSAZXCVBNM"
a=str(input())
if a in t:
print('a')
else:
print('A') | # uppercase = A, lowercase = a
n = input()
if n.isupper():
print('A')
else:
print('a')
| 1 | 11,225,469,983,410 | null | 119 | 119 |
import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
k = int(input())
ans = 0
for a in range(1, k+1):
for b in range(a, k+1):
for c in range(b, k+1):
t = len({a,b,c})
if t == 3:
ans += gcd(a,b,c) * 6
elif t == 2:
ans += gcd(a,b,c) * 3
else:
ans += gcd(a,b,c)
print(ans) | n=int(input())
x=n%100
y=n//100
if(y*5>=x):
print("1")
else:
print(0) | 0 | null | 81,716,148,427,560 | 174 | 266 |
import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
cnt = 0
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) ) | cnt = 0
def insert_sort(g):
global cnt
i = g
for _ in range(n):
v = nums[i]
j = i - g
while j >= 0 and nums[j] > v:
nums[j + g] = nums[j]
j -= g
cnt += 1
nums[j + g] = v
i += 1
if i >= n:
break
def shell_sort():
i = 0
for _ in range(m):
insert_sort(g[i])
i += 1
n = int(input())
nums = []
for _ in range(n):
nums.append(int(input()))
g = []
g_val = n
for _ in range(n):
g_val = g_val // 2
g.append(g_val)
if g_val == 1:
break
m = len(g)
shell_sort()
print(m)
g_cnt = 0
s = ''
for _ in range(m):
s += str(g[g_cnt]) + ' '
g_cnt += 1
print(s.rstrip())
print(cnt)
nums_cnt = 0
for _ in range(n):
print(nums[nums_cnt])
nums_cnt += 1
| 1 | 28,811,303,772 | null | 17 | 17 |
N,M=map(int, input().split())
peaks=list(map(int, input().split()))
flag=[1]*N
a=0
b=0
for i in range(M):
a,b=map(int,input().split())
a-=1
b-=1
if peaks[a]<=peaks[b]:
flag[a]=0
if peaks[a]>=peaks[b]:
flag[b]=0
ans=0
for i in flag:
ans+=i
print(ans) | print((int(input())**2)) | 0 | null | 85,252,150,963,066 | 155 | 278 |
while 1:
x,y = map(int, raw_input().split())
if x == 0 and y == 0:
break
if y >= x:
print '%s %s' % (x, y)
else:
print '%s %s' % (y, x) | while True:
a=input()
b=a.split()
c=list()
for d in b:
c.append(int(d))
if c[0]==0 and c[1]==0:
break
else:
d=sorted(c)
print(d[0],d[1])
| 1 | 523,592,978,612 | null | 43 | 43 |
#template
def inputlist(): return [int(j) for j in input().split()]
#template
"""
H,W = inputlist()
st = inputlist()
gl = inputlist()
maze = ['0']*H
for i in range(H):
maze[i] = list(input())
table = [[10**9+7]*W for _ in range(H)]
"""
D,T,S = inputlist()
time = D//S + int(D%S != 0)
if time <= T:
print("Yes")
else:
print("No")
| from collections import deque,defaultdict
import bisect
N = int(input())
S = [input() for i in range(N)]
def bend(s):
res = 0
k = 0
for th in s:
if th == '(':
k += 1
else:
k -= 1
res = min(k,res)
return res
species = [(bend(s),s.count('(')-s.count(')')) for s in S]
ups = [(b,u) for b,u in species if u > 0]
flats = [(b,u) for b,u in species if u == 0]
downs = [(b,u) for b,u in species if u < 0]
ups.sort()
high = 0
for b,u in ups[::-1] + flats:
if high + b < 0:
print('No')
exit()
high += u
rdowns = [(b-u,-u) for b,u in downs]
rdowns.sort()
high2 = 0
for b,u in rdowns[::-1]:
if high2 + b < 0:
print('No')
exit()
high2 += u
if high == high2:
print('Yes')
else:
print('No')
| 0 | null | 13,651,369,395,158 | 81 | 152 |
#!/usr/bin/env python3
def main():
k = int(input())
num = 0
soeji = 0
ar = [0 for _ in range(k)]
while True:
# print(soeji)
if ar[soeji] > 0:
break
ar[soeji] = num
soeji = (soeji * 10 + 7) % k
num += 1
print(-1 if ar[0] == 0 else ar[0])
if __name__ == '__main__':
main()
| n = int(input().rstrip())
def calc(target):
result = 0
count = 0
if target % 2 == 0:
print(-1)
return
for i in range(n):
result = (result * 10 + 7) % target
count += 1
if result == 0:
print(count)
return
print(-1)
calc(n) | 1 | 6,112,409,267,680 | null | 97 | 97 |
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans=float("inf")
counter=[[999]*W for _ in range(H)]
def search(i,j,count):
global ans
if counter[i][j]!=999:
ans=min(ans,count+counter[i][j])
return(counter[i][j])
dist=999
if i==H-1 and j==W-1:
ans=min(ans,count)
return 0
countj=count
counti=count
if j<W-1:
if S[i][j]=="." and S[i][j+1]=="#":
countj+=1
dist=search(i,j+1,countj) + (S[i][j]=="." and S[i][j+1]=="#")
if i<H-1:
if S[i][j]=="." and S[i+1][j]=="#":
counti+=1
dist=min(dist,search(i+1,j,counti)+(S[i][j]=="." and S[i+1][j]=="#"))
counter[i][j]=dist
return dist
search(0,0,(S[0][0]=="#")*1)
print(ans) | def LI():
return list(map(int,input().split()))
h,n=LI()
a=[]
b=[]
for _ in range(n):
x,y=LI()
a.append(x)
b.append(y)
INF=10**15
dp=[INF]*(h+max(a)+10)
dp[0]=0
for i in range(0,h+1):
for j,k in zip(a,b):
dp[i+j]=min(dp[i+j],dp[i]+k)
ans=INF
for i in dp[h:]:
ans=min(ans,i)
print(ans) | 0 | null | 65,277,685,378,280 | 194 | 229 |
class card:
def __init__(self, types, value):
self.types = types
self.value = value
def bubbleSort(A, N):
for i in range(0, N):
for j in range(N - 1, i, -1):
if A[j].value < A[j - 1].value:
exchange(A, j - 1, j)
printCards(A)
print "Stable"
def selectionSort(A, N):
origin = A[:]
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j].value < A[minj].value:
minj = j
if i != minj:
exchange(A, i, minj)
printCards(A)
if checkStable(origin, A, N):
print "Stable"
else:
print "Not stable"
def exchange(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
def printCards(cards):
print " ".join(t.types + str(t.value) for t in cards)
def checkStable(origin, sorted, N):
for i in range(0, N - 1):
if sorted[i].value == sorted[i + 1].value:
if origin.index(sorted[i]) > origin.index(sorted[i + 1]):
return False
return True
if __name__ == "__main__":
N = input()
A = [card(c[0], int(c[1])) for c in raw_input().split()]
bubbleSort(A[:], N)
selectionSort(A[:], N) | import sys
def bubble_sort(C, N):
for i in range(N):
for j in range(N - 1, i, -1):
if C[j][1] < C[j - 1][1]:
C[j], C[j - 1] = C[j - 1], C[j]
return C
def selection_sort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j][1] < C[minj][1]:
minj = j
C[i], C[minj] = C[minj], C[i]
return C
#fin = open("test.txt", "r")
fin = sys.stdin
N = int(fin.readline())
A = fin.readline().split()
B = A[:]
A = bubble_sort(A, N)
B = selection_sort(B, N)
print(" ".join(A))
print("Stable")
print(" ".join(B))
if A == B:
print("Stable")
else:
print("Not stable") | 1 | 26,178,264,240 | null | 16 | 16 |
class Dice:
def __init__(self, men):
self.men = men
def throw(self, direction):
if direction == "E":
pmen = men[:]
men[0] = pmen[3]
men[1] = pmen[1]
men[2] = pmen[0]
men[3] = pmen[5]
men[4] = pmen[4]
men[5] = pmen[2]
elif direction == "W":
pmen = men[:]
men[0] = pmen[2]
men[1] = pmen[1]
men[2] = pmen[5]
men[3] = pmen[0]
men[4] = pmen[4]
men[5] = pmen[3]
elif direction == "S":
pmen = men[:]
men[0] = pmen[4]
men[1] = pmen[0]
men[2] = pmen[2]
men[3] = pmen[3]
men[4] = pmen[5]
men[5] = pmen[1]
elif direction == "N":
pmen = men[:]
men[0] = pmen[1]
men[1] = pmen[5]
men[2] = pmen[2]
men[3] = pmen[3]
men[4] = pmen[0]
men[5] = pmen[4]
def printUe(self):
print (self.men)[0]
def printMen(self):
print self.men
men = map(int, (raw_input()).split(" "))
d = Dice(men)
S = raw_input()
for s in S:
d.throw(s)
d.printUe() | class Dice:
def __init__(self, faces):
self.faces = tuple(faces)
def roll_north(self):
self.faces = (self.faces[1], self.faces[5], self.faces[2],
self.faces[3], self.faces[0], self.faces[4])
def roll_south(self):
self.faces = (self.faces[4], self.faces[0], self.faces[2],
self.faces[3], self.faces[5], self.faces[1])
def roll_west(self):
self.faces = (self.faces[2], self.faces[1], self.faces[5],
self.faces[0], self.faces[4], self.faces[3])
def roll_east(self):
self.faces = (self.faces[3], self.faces[1], self.faces[0],
self.faces[5], self.faces[4], self.faces[2])
def number(self, face_id):
return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
commands = input()
for c in commands:
if c == "N":
dice.roll_north()
elif c == "S":
dice.roll_south()
elif c == "W":
dice.roll_west()
elif c == "E":
dice.roll_east()
print(dice.number(1)) | 1 | 227,181,856,132 | null | 33 | 33 |
n=int(input())
p=[[0,0]]
r3=1.7320508
def unit_koch(p1,p2,d):
if d>=n:
return
s=[(p1[0]*2+p2[0])/3,(p1[1]*2+p2[1])/3]
t=[(p1[0]+p2[0]*2)/3,(p1[1]+p2[1]*2)/3]
v_s_t=[t[0]-s[0],t[1]-s[1]]
v_s_u=[v_s_t[0]/2-v_s_t[1]*r3/2,v_s_t[1]/2+v_s_t[0]*r3/2]
u=[s[0]+v_s_u[0],s[1]+v_s_u[1]]
unit_koch(p1,s,d+1)
p.append(s)
unit_koch(s,u,d+1)
p.append(u)
unit_koch(u,t,d+1)
p.append(t)
unit_koch(t,p2,d+1)
unit_koch([0,0],[100,0],0)
p.append([100,0])
for i in p:
print(str(i[0])+' '+str(i[1]))
| #coding:UTF-8
import math
def KC(n,p1,p2):
if n==0:
return
s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
u=[(t[0]-s[0])*math.cos(math.pi/3)-(t[1]-s[1])*math.sin(math.pi/3)+s[0],(t[0]-s[0])*math.sin(math.pi/3)+(t[1]-s[1])*math.cos(math.pi/3)+s[1]]
KC(n-1,p1,s)
print(str(format(s[0],'.8f'))+" "+str(format(s[1],'.8f')))
KC(n-1,s,u)
print(str(format(u[0],'.8f'))+" "+str(format(u[1],'.8f')))
KC(n-1,u,t)
print(str(format(t[0],'.8f'))+" "+str(format(t[1],'.8f')))
KC(n-1,t,p2)
if __name__=="__main__":
n=int(input())
p1=[0,0]
p2=[100,0]
print(str(format(p1[0],'.8f'))+" "+str(format(p1[1],'.8f')))
KC(n,p1,p2)
print(str(format(p2[0],'.8f'))+" "+str(format(p2[1],'.8f'))) | 1 | 127,042,501,740 | null | 27 | 27 |
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array
# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
# 再帰の制限設定
sys.setrecursionlimit(10000000)
def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
for _ in range(n)]
def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
for _ in range(n)]
def lcm(x, y): return (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
D = [il() for _ in range(N)]
for i in range(N - 2):
for j in range(i, i + 3):
if D[j][0] != D[j][1]:
break
else:
print('Yes')
exit()
else:
print('No')
if __name__ == '__main__':
main()
| n, m = input().split()
a = list(map(int, input().split()))
s = 0
for i in a:
s += int(i)
if int(s) <= int(n):
print(int(n) - int(s))
else:
print("-1") | 0 | null | 17,183,039,541,008 | 72 | 168 |
while True:
n=input()
if n=='-':
break
else:
m=int(input())
for i in range(m):
h=int(input())
n=n[h:len(n)]+n[:h]
print(n)
| # -*- coding: utf-8 -*-
import math
x = int(input())
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return True
return False
while is_prime(x):
x += 1
print(x)
| 0 | null | 53,706,833,588,772 | 66 | 250 |
from collections import deque
from sys import stdin
n = int(input())
ddl = deque()
for i in stdin:
inp = i.split()
if len(inp) == 2:
op, data = inp
data = int(data)
else: op, data = inp[0], None
if op == 'insert':
ddl.appendleft(data,)
elif op == 'delete':
try:
ddl.remove(data)
except ValueError:
pass
elif op == 'deleteFirst':
ddl.popleft()
elif op == 'deleteLast':
ddl.pop()
print(' '.join([str(item) for item in ddl])) | from collections import deque
n = int(input())
q = deque()
for i in range(n):
c = input()
if c[0] == 'i':
q.appendleft(c[7:])
elif c[6] == ' ':
try:
q.remove(c[7:])
except:
pass
elif c[6] == 'F':
q.popleft()
else:
q.pop()
print(*q) | 1 | 49,961,564,572 | null | 20 | 20 |
n, k = [int(_) for _ in input().split()]
ary = [int(input()) for _ in range(n)]
def search_v(p):
v = 0
w = 0
tmp_k = 1
ind = 0
while True:
if tmp_k > k:
return v
if ind == n:
return n
tmp = ary[ind]
if w + tmp <= p:
w += tmp
v += 1
ind += 1
else:
w = 0
tmp_k += 1
max_p = n * 10000
ps = range(max_p + 1)
left = 0
right = max_p
while left + 1 < right:
mid = (left + right) // 2
v = search_v(ps[mid])
if v >= n:
right = mid
else:
left = mid
print(ps[right])
| n, k = map(int, input().split())
W = [int(input()) for i in range(n)]
left = max(W)-1; right = sum(W)
while left+1 < right:
mid = (left + right) // 2
cnt = 1; cur = 0
for w in W:
if mid < cur + w:
cur = w
cnt += 1
else:
cur += w
if cnt <= k:
right = mid
else:
left = mid
print(right) | 1 | 88,282,712,640 | null | 24 | 24 |
def my_eval(ar,str):
res = True
n = len(str)
# print(n)
# print("start")
for i in range(n):
# print(i)
if(ar[str[i][0]] == 1):
# print(str[i][0])
# print(str[i][1])
# print(str[i][2])
# print(ar[str[i][1]-1])
# print(ar[str[i][1]-1] == str[i][2])
# print(ar)
# print()
if(ar[str[i][1]] != str[i][2]):
res = False
# print("end")
# print()
return res
if __name__ == "__main__":
# 全探索
n = int(input())
str = []
for i in range(n):
a = int(input())
for j in range(a):
x = list(map(int,input().split()))
x.insert(0,i+1)
str.append(x)
ar = [0] * (n+1)
res = 0
# print(str)
count = 0
for i in range(2**n):
count = 0
for j in range(n):
if(i >> j & 1 == 1):
ar[j+1] = 1
count += 1
else:
ar[j+1] = 0
# print(ar)
if(my_eval(ar,str)):
res = max(res,count)
print(res)
| a = int(input())
sum = a + (a*a) + (a*a*a)
print(sum) | 0 | null | 65,927,735,108,960 | 262 | 115 |
r=float(input())
pi=3.141592653589793238
print(pi*r**2,2*pi*r)
| r=float(raw_input())
p=float(3.14159265358979323846264338327950288)
s=p*r**2.0
l=2.0*p*r
print"%.5f %.5f"%(float(s),float(l)) | 1 | 648,112,676,538 | null | 46 | 46 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.