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
# -*- coding: utf-8 -*- from sys import stdin input = stdin.readline def main(): n = int(input().strip()) print('1' if n == 0 else '0') if __name__ == "__main__": main()
n=int(input()) a=[[[0 for _ in range(10)]for _ in range(3)]for _ in range(4)] for i in range(n): b,f,r,v=map(int, input().split()) a[b-1][f-1][r-1]+=v for bb in range(4): for ff in range(3): print(*[""]+a[bb][ff]) if bb==3: break else: print("#"*20)
0
null
2,014,429,007,076
76
55
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import itertools import math import sys INF = float('inf') def solve(x: "List[int]"): return x.index(0) + 1 def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() x = [int(next(tokens)) for _ in range(5)] # type: "List[int]" print(solve(x)) if __name__ == '__main__': main()
X=list(map(int,input().split())) for i in range(0,5): if X[i]==0: print(i+1) break
1
13,440,504,294,214
null
126
126
#get input n = input() S = map(lambda x: int(x), input().split(' ')) q = input() T = list(map(lambda x: int(x), input().split(' '))) #create T set T_set = set(T) #iterate S and counting count = 0 for i in S: if i in T_set: count += 1 T_set.remove(i) print(count)
n=int(input()) lista=[0 for i in range(n)] lista=input().split() n2=int(input()) listb=[0 for i in range(n2)] listb=input().split() cnt=0 for i in range(n2): x=0 for j in range(n): if listb[i]==lista[j] and x==0: x=1 cnt+=1 print(cnt)
1
67,068,098,240
null
22
22
import os import sys import math import heapq from decimal import * from io import BytesIO, IOBase from collections import defaultdict, deque def r(): return int(input()) def rm(): return map(int,input().split()) def rl(): return list(map(int,input().split())) n=r() a=rl() money=1000 s=0 for i in range(n): if i==n-1: money+=s*a[i] else: if a[i]<=a[i+1]: money+=s*a[i] s=money//a[i] money%=a[i] else: money+=s*a[i] s=0 print(money)
N = int(input()) A = list(map(int,input().split())) Money = 1000 Stock = 0 for i in range(N-1): if A[i] < A[i+1]: Stock = Stock + (Money//A[i]) Money = Money % A[i] elif A[i] > A[i+1]: Money = Money + Stock * A[i] Stock = 0 ans = Money + Stock * A[i+1] print(ans)
1
7,354,458,242,460
null
103
103
n = int(input()) A = list(map(int,input().split())) b = 1 B=[0]*(n+1) count = 0 t=len(A)-1 for i in range(t): B[i] = b if 2*(b - A[i]) < A[i+1]: count += 1 break b = 2*(b - A[i]) B[n] = b if n == 0 and A[0] > 1: count += 1 j = 0 while count == 0 and A[t] > B[j]: if j == n: break j += 1 total = 0 for i in range(j): total += B[i] s = A[t] for i in range(t-1,j-1,-1): total += min(B[i],s+A[i]) s+=A[i] if count==0: print(total+A[t]) else: print('-1')
N = int(input()) A = tuple(map(int, input().split())) S = [0] for a in reversed(A): S.append(S[-1] + a) S.reverse() lst = [0] * (N + 2) lst[0] = 1 for i, a in enumerate(A): if lst[i] < a: print(-1) break lst[i + 1] = min((lst[i] - a) * 2, S[i + 1]) else: print(sum(lst))
1
18,999,749,901,182
null
141
141
from sys import stdin input = stdin.readline().rstrip #x = input().rstrip() #n = int(input()) #a,b,c = input().split() #a,b,c = map(int, input().split()) D,T,S = map(int, input().split(" ")) if(T * S >= D): print("Yes") else: print("No")
input_data = list(map(int,input().split())) time = input_data[0] / input_data[2] if time > input_data[1]: print('No') else: print('Yes')
1
3,537,546,164,294
null
81
81
import sys input = sys.stdin.readline read = sys.stdin.read n, t = map(int, input().split()) m = map(int, read().split()) AB = sorted(zip(m, m)) A, B = zip(*AB) dp = [[0]*t for _ in range(n+1)] for i, a in enumerate(A[:-1]): for j in range(t): if j < a: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = max(dp[i][j-a]+B[i], dp[i][j]) ans = 0 maxB = [B[-1]]*n for i in range(n-2, 0, -1): maxB[i] = max(B[i], maxB[i+1]) for i in range(n-1): ans = max(ans, dp[i+1][-1] + maxB[i+1]) print(ans)
from sys import exit import math ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) n = li() N = [] N.append(n[0]) for i in range(1,3,1): if n[i] in N: continue N.append(n[i]) if len(N) == 2: print('Yes') else: print('No')
0
null
109,990,343,744,540
282
216
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) n, k, c = nm() s = ns() g = [0]*n f = [0]*n _h = 0 for i in reversed(range(n)): if i + c + 1 < n: if _h < g[i+c+1]: _h = g[i+c+1] if s[i] == 'o': g[i] = _h + 1 if max(g) == k: _h = 0 for i in range(n): if i > c: if _h < f[i-c-1]: _h = f[i-c-1] if s[i] == 'o': f[i] = _h + 1 # print(g) # print(f) a = [0]*(k+2) b = [0]*(k+2) for i in range(n): a[g[i]] = i for i in reversed(range(n)): b[k+1-f[i]] = i # print(a) # print(b) for i in range(k, 0, -1): if a[i] == b[i]: print(a[i] + 1)
N,K,C=map(int,input().split()) S=input() L=[0 for i in range(K)] R=[0 for i in range(K)] n=0 rc=0 lc=0 while True: if lc==K: break if S[n]=="o": L[lc]=n+1 n+=C+1 lc+=1 else: n+=1 n=N-1 while True: if rc==K: break if S[n]=="o": R[K-1-rc]=n+1 n-=C+1 rc+=1 else: n-=1 for i in range(K): if R[i]==L[i]: print(R[i])
1
40,592,371,585,740
null
182
182
n = int(input()) m = list(map(int, input().split())) count = 0 for i in range(n-1): minj =i for j in range(i+1, n): if m[j] < m[minj]: minj = j if m[i] != m[minj]: m[i], m[minj] = m[minj], m[i] count += 1 print(" ".join(str(x) for x in m)) print(count)
def main(): N, M = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) def helper(x): p = len(A) - 1 t = 0 for a in A: while p >= 0 and A[p] + a < x: p -= 1 t += p + 1 return t l, r = 0, A[0] * 2 + 1 while r - l > 1: m = (l + r) // 2 if helper(m) > M: l = m else: r = m k = sum(A) p = len(A) - 1 t = (M - helper(l)) * l for a in A: while p >= 0 and A[p] + a < l: k -= A[p] p -= 1 t += a * (p + 1) + k print(t) main()
0
null
54,083,963,093,920
15
252
import sys n=int(input()) if n%2: print(0) sys.exit() # 10->50->2500の個数 cnt=0 v=10 while 1: cnt+=n//v if n//v==0: break v*=5 print(cnt)
import math n = int(input()) cnt = 0 mod = 10 if n%2 == 1: print(0) exit() while mod<=n: cnt += n//mod mod*=5 print(cnt)
1
115,975,466,625,828
null
258
258
data = [] for i in xrange(4): tou = [] data.append(tou) for j in xrange(3): kai = [0 for k in xrange(10)] tou.append(kai) n = int(raw_input()) for i in xrange(n): b,f,r,v = map(int, raw_input().split(" ")) data[b-1][f-1][r-1] = max(0, data[b-1][f-1][r-1] + v) for tou in data: if not tou is data[0]: print "#" * 20 for kai in tou: print " " + " ".join(map(str, kai))
All = [[[0 for x in range(10)] for y in range(3)] for z in range(4)] N = int(input()) i = 0 while i < N: b, f, r, v = map(int,input().split()) All[b-1][f-1][r-1] += v i += 1 for x in range(4): for y in range(3): for z in range(10): print(" {}".format(All[x][y][z]), end = "") if z == 9: print("") if x != 3 and y == 2: for j in range(20): print("#", end = "") print("")
1
1,109,609,513,892
null
55
55
import collections n=int(input()) A=list(map(int,input().split())) c = collections.Counter(A) all_combi=0 for i in c: # print(c[i]) all_combi += c[i]*(c[i]-1)//2 count = [c[A[i]] for i in range(len(A))] for i in range(len(A)): n_same_i = count[i]-1 ans = all_combi - n_same_i print(ans)
N=int(input()) S,T=map(list,input().split()) lis=[] for i in range(0,N): lis.append(S[i]) lis.append(T[i]) print(''.join(lis))
0
null
79,813,062,379,882
192
255
n, m = map(int,input().split()) count = 0 l = [] for i in range(n): for i2 in range(i,n): if i != i2: l.append([i,i2]) for i in range(m): for i2 in range(i,m): if i != i2: l.append([i,i2]) print(len(l))
import math n, m = map(int, input().split()) def comb(n, r): if n == 0 or n == 1: return 0 return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) a = comb(n, 2) b = comb(m, 2) print(a+b)
1
45,487,349,250,770
null
189
189
def main(): k = int(input()) a, b = (int(i) for i in input().split()) for i in range(a, b+1): if i % k == 0: print('OK') return print('NG') main()
def gcd(a,b): if a < b: a,b = b,a while b != 0: a,b = b,a%b return a a,b = map(int,raw_input().split()) print gcd(a,b)
0
null
13,408,883,946,748
158
11
H, W = map(int,input().split()) S = [list(input()) for i in range(H)] N = [[10**9]*W]*H l = 0 u = 0 if S[0][0] == '#' : N[0][0] = 1 else : N[0][0] = 0 for i in range(H) : for j in range(W) : if i == 0 and j == 0 : continue #横移動 l = N[i][j-1] #縦移動 u = N[i-1][j] if S[i][j-1] == '.' and S[i][j] == '#' : l += 1 if S[i-1][j] == '.' and S[i][j] == '#' : u += 1 N[i][j] = min(l,u) print(N[-1][-1])
h, w = map(int, input().split()) maze = [list(input()) for i in range(h)] dp = [[0] * w for i in range(h)] for i in range(h): for j in range(w): if i == j == 0: if maze[i][j] == "#": dp[i][j] += 1 if i == 0 and j != 0: if maze[0][j] != maze[0][j - 1]: dp[0][j] = dp[0][j - 1] + 1 else: dp[0][j] = dp[0][j - 1] if j == 0 and i != 0: if maze[i][0] != maze[i - 1][0]: dp[i][0] = dp[i - 1][0] + 1 else: dp[i][0] = dp[i - 1][0] if i != 0 and j != 0: dp[i][j] = min(dp[i - 1][j] + (1 if maze[i][j] != maze[i - 1][j] else 0), dp[i][j - 1] + (1 if maze[i][j] != maze[i][j - 1] else 0)) if i == h - 1 and j == w - 1: if maze[i][j] == "#": dp[i][j] += 1 ans = dp[h - 1][w - 1] // 2 print(ans)
1
49,013,017,625,600
null
194
194
kuku = [i * j for i in range(1,10) for j in range(1,10)] N = int(input()) print('Yes' if N in kuku else 'No')
N,K = map(int, input().split()) L = [0]*N R = [0]*N DP = [0]*(N+10) DP[0] = 1 SDP = [0]*(N+10) SDP[1] = 1 MOD=998244353 for i in range(K): L[i],R[i] = map(int, input().split()) for i in range(1,N): for j in range(K): l = max(0,i-R[j]) r = max(0,i-L[j]+1) DP[i] += SDP[r] - SDP[l] SDP[i+1] = (SDP[i] + DP[i])%MOD print(DP[N-1]%MOD)
0
null
81,112,770,790,530
287
74
import sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり N,K = LI() A = LI() for i in range(N): A[i] -= 1 B = [0] # Aの累積和をKで割ったもの for i in range(N): B.append((B[-1]+A[i]) % K) from collections import defaultdict # 要素の個数がKを超えないことに注意 if N < K: d = defaultdict(int) for n in B: d[n] += 1 ans = 0 for n in d.keys(): m = d[n] ans += m*(m-1)//2 print(ans) else: d = defaultdict(int) ans = 0 for i in range(N): # A[i]から始まる部分列を考える if i == 0: for j in range(K): d[B[j]] += 1 ans += d[B[i]]-1 elif i <= N-K+1: d[B[K+i-1]] += 1 d[B[i-1]] -= 1 ans += d[B[i]]-1 else: d[B[i-1]] -= 1 ans += d[B[i]]-1 print(ans)
from collections import defaultdict N,K=map(int,input().split()) alist=list(map(int,input().split())) #print(alist) slist=[0] for i in range(N): slist.append(slist[-1]+alist[i]) #print(slist) sslist=[] for i in range(N+1): sslist.append((slist[i]-i)%K) #print(sslist) answer=0 si_dic=defaultdict(int) for i in range(N+1): if i-K>=0: si_dic[sslist[i-K]]-=1 answer+=si_dic[sslist[i]] si_dic[sslist[i]]+=1 print(answer)
1
137,394,363,396,448
null
273
273
N = input() nums = [] for num in N: nums.append(int(num)) s = sum(nums) if s % 9 == 0: print("Yes") else: print("No")
k = int(input()) queue = [1,2,3,4,5,6,7,8,9] cnt = 0 while cnt + len(queue) < k: cnt += 1 n = queue.pop(0) if n%10 != 0: queue.append(n*10+n%10-1) queue.append(n*10+n%10) if n%10 != 9: queue.append(n*10+n%10+1) print(queue[k-cnt-1])
0
null
22,106,006,949,150
87
181
class Dice: def __init__(self, hoge): self.num = hoge self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} def move(self, direct): previouse = {k: v for k, v in self.face.items()} if direct == 'E': self.face['U'] = previouse['W'] self.face['W'] = previouse['B'] self.face['E'] = previouse['U'] self.face['B'] = previouse['E'] elif direct == 'W': self.face['U'] = previouse['E'] self.face['W'] = previouse['U'] self.face['E'] = previouse['B'] self.face['B'] = previouse['W'] elif direct == 'N': self.face['U'] = previouse['S'] self.face['N'] = previouse['U'] self.face['S'] = previouse['B'] self.face['B'] = previouse['N'] elif direct == 'S': self.face['U'] = previouse['N'] self.face['N'] = previouse['B'] self.face['S'] = previouse['U'] self.face['B'] = previouse['S'] def get_upper(self): return self.num[self.face['U']] if __name__ == '__main__': dice = Dice([int(x) for x in input().split()]) for d in input(): dice.move(d) print (dice.get_upper())
a,b = map(int,input().split()) ans = "" k = min(a,b) l = max(a,b) for i in range(l): ans += str(k) print(ans)
0
null
42,209,032,204,800
33
232
N =int(input()) S, T = input().split() for i in range(N): print(S[i], end="") print(T[i], end="") print()
import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): N,K=mi() n = N//K ans = INF for m in [n-1,n,n+1]: ans = min(ans,abs(N-K*m)) print(ans) if __name__ == "__main__": main()
0
null
75,680,848,348,052
255
180
if __name__ == "__main__": s = int(input()) m = s // 60 h = str(m // 60) m = str(m % 60) s = str(s % 60) print(h + ":" + m + ":" + s)
S = int(input()) s = (S % 60) m = (S % 3600 // 60) h = (S // 3600) print(h, ':', m, ':', s, sep='')
1
322,437,581,690
null
37
37
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, T, *AB = map(int, read().split()) D = [(a, b) for a, b in zip(*[iter(AB)] * 2)] D.sort() dp = [[0] * T for _ in range(N + 1)] for i, (a, b) in enumerate(D): for t in range(T): if 0 <= t - a: dp[i + 1][t] = dp[i][t - a] + b if dp[i + 1][t] < dp[i][t]: dp[i + 1][t] = dp[i][t] ans = 0 for i in range(N - 1): if ans < dp[i + 1][T - 1] + D[i + 1][1]: ans = dp[i + 1][T - 1] + D[i + 1][1] print(ans) return if __name__ == '__main__': main()
D,T,S = map(int,input().split()) x = S*T if x >= D : print("Yes") else: print("No")
0
null
77,876,152,940,198
282
81
n = int(input()) def gcd(a,b): if b == 0: return a return gcd(b, a%b) print((360 * n // gcd(360, n)) // n)
def main(): X = int(input()) i = 1 while True: if i * X % 360 == 0: print(i) break i += 1 main()
1
13,103,675,773,552
null
125
125
while True: n = list(map(int,input())) if n[0] ==0: break else: print(sum(n))
while True: s = input() if s=="0": break print(sum(map(int,s)))
1
1,614,692,353,846
null
62
62
from collections import Counter abc = Counter(input().split()) if len(abc) == 2: print('Yes') else: print('No')
def main(): A, B, C = (int(x) for x in input().split()) K = int(input()) while not A < B < C and K > 0: if A >= B: B *= 2 else: C *= 2 K -= 1 # print(A, B, C, K) if A < B < C: print('Yes') else: print('No') if __name__ == '__main__': main()
0
null
37,489,994,938,720
216
101
n, k = map(int, input().split()) listn = list() for i in range(k): d = int(input()) a = list(map(int, input().split())) listn.extend(a) print(n - len(set(listn)))
N, K = map(int, input().split()) count = 0 num_people = [] num_people_snacks = [] for i in range(1, N + 1): num_people.append(i) while K > count: d = int(input()) A = list(map(int, input().split())) for k in A: num_people_snacks.append(k) count += 1 ans = 0 for j in range(N): if num_people[j] not in num_people_snacks: ans += 1 print(ans)
1
24,636,827,234,710
null
154
154
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) def enum_divisors(n): # 約数列挙 divisors = [] for i in range(1, int(n ** 0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors divs = enum_divisors(N) ans = INF for div1 in divs: div2 = N // div1 score = (div1 + div2 - 2) ans = min(score, ans) print(ans) if __name__ == '__main__': main()
from math import sqrt from math import floor n = int(input()) ans = 10 ** 12 m = floor(sqrt(n)) for i in range(1,m+1): if n % i == 0: j = n // i ans = min(ans,i+j-2) print(ans)
1
161,916,019,862,520
null
288
288
from itertools import product n = int(input()) data = {} for p in range(1, n+1): a = int(input()) # 人p=1~の証言 data[p] = [list(map(int, input().split())) for _ in range(a)] # パターン生成 ans = 0 for honest in product(range(2), repeat=n): for p,hk in enumerate(honest, 1): if hk == 1: # 証言の矛盾をチェック if not all([honest[x-1] == y for x,y in data[p]]): break else: ans = max(ans, sum(honest)) print(ans)
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(1000000) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, K, C, S): def f(S): r = 0 w = [] c = 0 for s in S: if r == 0 and s == 'o': w.append(1) r = C c += 1 else: w.append(0) r = max(0, r-1) return w lw = f(S) rw = list(reversed(f(reversed(S)))) if sum(lw) != K: return for i, (l, r) in enumerate(zip(lw, rw)): if l == r == 1: print(i+1) def main(): N, K, C = read_int_n() S = read_str() (slv(N, K, C, S)) if __name__ == '__main__': main()
0
null
81,276,971,991,962
262
182
import sys def input(): return sys.stdin.readline()[:-1] def main(): X = int(input()) if X >= 1800: print(1) elif X >= 1600: print(2) elif X >= 1400: print(3) elif X >= 1200: print(4) elif X >= 1000: print(5) elif X >= 800: print(6) elif X >= 600: print(7) else: print(8) if __name__ == "__main__": main()
import math shuu = input() num = int(shuu) ganpon = 100000 i = 1 while i <= num: ganpon *= 1.05 ganpon /= 1000 ganpon = math.ceil(ganpon) ganpon *= 1000 i += 1 pass #ganpon /= 1000 #ganpon = math.ceil(ganpon) #ganpon *= 100000 print(ganpon)
0
null
3,400,479,122,180
100
6
from collections import Counter n = int(input()) lst = list(map(int,input().split())) if lst[0] != 0: print(0) exit() mod = 998244353 c = dict(Counter(lst)) c = dict(sorted(c.items(), key=lambda x:x[0])) for e,(k,v) in enumerate(c.items()): if e==0: if k!=0 or v!=1: ans = 0 break else: pre_v = v ans = v elif e!=k or v==0: ans = 0 break else: ans = ans*pow(pre_v, v, mod)%mod pre_v = v print(ans%mod)
H,W,M=map(int,input().split()) L=[] bh=[0]*(H+1) bw=[0]*(W+1) for _ in range(M): h,w=map(int,input().split()) L.append((h,w)) bh[h]+=1 bw[w]+=1 p,q=max(bh),max(bw) num=len(list(filter(p.__eq__, bh)))*len(list(filter(q.__eq__,bw))) num-=len(list(filter(lambda x: bh[x[0]]==p and bw[x[1]]==q, L))) ans=p+q-1 if num>0: ans+=1 print(ans)
0
null
79,630,098,842,382
284
89
A,B,N=map(int,input().split()) f=lambda x:(A*x)//B-A*(x//B) print(f(B-1 if B-1<=N else N))
n = int(input()) a = list(map(int,input().split())) maxketa = max([len(bin(a[i])) for i in range(n)])-2 mod = 10**9+7 ans = 0 for i in range(maxketa): ones = 0 for j in range(n): if (a[j] >> i) & 1: ones += 1 ans = (ans + (n-ones)*ones*(2**i)) % mod print(ans)
0
null
75,413,349,415,952
161
263
n,m=map(int,input().split()) way=[[] for i in range(n)] H = list(map(int,input().split())) for i in range(m): a,b=map(int,input().split()) way[a-1].append(b-1) way[b-1].append(a-1) ans=0 for i in range(n): high=True for j in way[i]: if H[i]<=H[j]: high=0 break if high: ans+=1 print(ans)
from collections import deque def bfs(adj_mat, d): Q = deque() N = len(d) color = ["W" for n in range(N)] Q.append(0) d[0] = 0 while len(Q) != 0: u = Q.popleft() for i in range(N): if adj_mat[u][i] == 1 and color[i] == "W": color[i] = "G" d[i] = d[u] + 1 Q.append(i) color[u] = "B" for i in range(N): if color[i] != "B": d[i] = -1 def Main(): N = int(input()) adj_mat = [[0 for n in range(N)] for n in range(N)] d = [0] * N for n in range(N): u, k , *V = map(int, input().split()) if k > 0: for i in V: adj_mat[n][i - 1] = 1 bfs(adj_mat, d) for n in range(N): print("{} {}".format(n + 1, d[n])) Main()
0
null
12,666,466,563,840
155
9
import collections N = int(input()) A = sorted(list(map(int,input().split()))) cA = collections.Counter(A) li = [1]*(max(A)+1) for j in range(N): for i in range(A[j]*2,A[-1]+1,A[j]): li[i] = 0 for key,val in cA.items(): if val >1: li[key]=0 sA = sum([li[i] for i in A]) print(sA)
def sol(s, p): n = len(s) cnt = 0 if p == 2 or p == 5: for i in range(n): if (s[i] % p == 0): cnt += i + 1 else: pre = [0] * (n+2) pre[n+1] = 0 b = 1 for i in range(n, 0, -1): pre[i] = (pre[i+1] + s[i-1] * b) % p b = (b * 10) % p rec = [0] * p rec[0] = 1 for i in range(n, 0, -1): cnt += rec[pre[i]] rec[pre[i]] += 1 return cnt if __name__ == "__main__": n, p = map(int, input().split()) s = input() print (sol([int(i) for i in s], p))
0
null
36,234,443,779,164
129
205
n, m, k = map(int, input().split()) class UnionFind(): def __init__(self, n): self.n = n self.par = [-1 for i in range(self.n)] def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): p = self.find(x) q = self.find(y) if p == q: return None if p > q: p, q = q, p self.par[p] += self.par[q] self.par[q] = p def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] UF = UnionFind(n) f_or_b = [0] * n for i in range(m): a, b = map(int, input().split()) UF.unite(a - 1, b - 1) f_or_b[a - 1] += 1 f_or_b[b - 1] += 1 for i in range(k): c, d = map(int, input().split()) if UF.same(c - 1, d - 1): f_or_b[c - 1] += 1 f_or_b[d - 1] += 1 for i in range(n): print(UF.size(i) - f_or_b[i] - 1, end=" ")
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = 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 -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) n, m, k = map(int, input().split()) u = UnionFind(n + 1) already = [0] * (n + 1) for i in range(m): a, b = map(int, input().split()) u.union(a, b) already[a] += 1 already[b] += 1 for i in range(k): c, d = map(int, input().split()) if u.same(c, d): already[c] += 1 already[d] += 1 for i in range(1, n + 1): print(u.size(i) - already[i] - 1)
1
61,578,799,560,180
null
209
209
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() point = [0]*K flag = ["a"]*K k = -1 #K本のリストを用意する 剰余系の中で、同じ手が連続するとき、1、3、5、...は別の手に変える for i in range(N): k = (k+1)%K #mod if T[i] == "r": if flag[k] == "r": flag[k] = "a" else: flag[k] = "r" point[k] += P elif T[i] == "s": if flag[k] == "s": flag[k] = "a" else: flag[k] = "s" point[k] += R if T[i] == "p": if flag[k] == "p": flag[k] = "a" else: flag[k] = "p" point[k] += S print(sum(point))
n,k=map(int,input().split()) amari=n%k if amari>k: print(k) else: print(min(amari,abs(amari-k)))
0
null
73,481,377,394,348
251
180
N,A,B = map(int,input().split()) if (B-A) % 2 == 0: print((B-A)//2) elif A-1 <= N-B: print((A+B-1)//2) else: print(N+1-(B+A+1)//2)
import sys input = sys.stdin.readline MOD = 1000000007 N,A,B = map(int,input().split()) if abs(A-B)%2 == 0: print(abs(A-B)//2) else: if (A-1) < (N-B): print((A-1)+1+(B-A-1)//2) else: print((N-B)+1+(B-A-1)//2)
1
109,679,218,056,590
null
253
253
N, M = list(map(int, input().split())) ans = 0 ans += N * (N - 1) // 2 ans += M * (M - 1) // 2 print(ans)
N, M=map(int, input().split(" ")) print(int((N*(N-1))/2+(M*(M-1))/2))
1
45,470,349,224,202
null
189
189
def solve(n): arr = [i for i in range(1, n+1) if i % 3 != 0 and i % 5 != 0] print(sum(arr)) if __name__ == "__main__": n = int(input()) solve(n)
n = int(input()) output = 0 for i in range(n): if (i + 1) % 3 != 0 and (i + 1) % 5 != 0:output += i + 1 print(output)
1
34,806,371,763,932
null
173
173
x,n=map(int,input().split()) *p,=map(int,input().split()) q=[0]*(102) for pp in p: q[pp]=1 diff=1000 ans=-1 for i in range(0,102): if q[i]: continue cdiff=abs(i-x) if cdiff<diff: diff=cdiff ans=i print(ans)
mod = 10**9 + 7 N = int(input()) A = [int(i)%mod for i in input().split()][:N] wa = sum(A) total = 0 for n in range(N-1): wa -= A[n] total += A[n] * wa total %= mod print(total)
0
null
8,898,883,755,228
128
83
x = map(int, raw_input().split()) s = x[0] * x[1] n = 2 * (x[0] + x[1]) print '%d %d' % (s, n)
arr = map(int,raw_input().split()) arr.sort() arr = map(str,arr) print ' '.join(arr)
0
null
365,271,383,008
36
40
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N = int(readline()) if N % 2: print(0) return ans = 0 N //= 2 while N: N //= 5 ans += N print(ans) return if __name__ == '__main__': main()
N=int(input()) #m1,d1=map(int,input().split()) #hl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] S=list(input()) d=list('0123456789') ans=0 for d1 in d: for d2 in d: for d3 in d: v=d1+d2+d3 i=0 p=0 while i < N : if v[p]==S[i]: p+=1 if p == 3: break i+=1 if p==3 : ans+=1 print(ans)
0
null
122,075,731,645,150
258
267
X, Y = [int(arg) for arg in input().split()] def f(X, Y): for i in range(X + 1): for j in range(X + 1): kame = i tsuru = j if kame + tsuru == X and kame * 4 + tsuru * 2 == Y: return 'Yes' return 'No' print(f(X, Y))
n,k = map(int,input().split()) mod = 998244353 dp = [0]*(n+10) dpsum = [0]*(n+10) dp[1] = dpsum[1] = 1 L = [0]*k R = [0]*k for i in range(k): l,r = map(int,input().split()) L[i],R[i] = l,r for i in range(2,n+1): for j in range(k): li = i-R[j] ri = i-L[j] if ri < 0: continue li = max(li,1) dp[i] += dpsum[ri]-dpsum[li-1] dp[i] %= mod dpsum[i] = dpsum[i-1]+dp[i] dpsum[i] %= mod print(dp[n])
0
null
8,266,084,950,878
127
74
import math import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) mod = 10**9 + 7 sys.setrecursionlimit(1000010) N,M = nm() used = [0] * N start = 0 if N % 2 != 0: s = (N-1)//2 else: s = N//2 - 1 for i in range(1,M+1): q= (i+1)//2 if i % 2 !=0: print(q,N+1-q) else: print(s+1-q,s+1+q)
n, m = map(int, input().split()) if m%2 == 0: x = m//2 y = m//2 else: x = m//2 y = m//2+1 for i in range(x): print(i+1, 2*x+1-i) for i in range(y): print(i+2*x+2, 2*y+2*x+1-i)
1
28,859,321,638,928
null
162
162
#import numpy as np N = int(input()) a = list(map(int, input().split())) all_xor = 0 for _a in a: all_xor = all_xor ^ _a for _a in a: print(all_xor ^ _a)
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N = I() a = LI() xor = 0 for x in a: xor ^= x for x in a: print(xor^x,end=' ') print()
1
12,510,996,309,220
null
123
123
#!/usr/bin/python3 # main n = int(input()) - 1 fib = [1, 2] for i in range(2, n + 1): fib.append(fib[i - 1] + fib[i - 2]) print(fib[n])
for x in range(1, 10): for y in range(1, 10): print "{}x{}={}".format(x, y, x*y)
0
null
806,955,432
7
1
from collections import Counter import sys n, m, k = map(int, input().split()) F = [[] for _ in range(n)] B = [[0] for _ in range(n)] sys.setrecursionlimit(10**9) for _ in range(m): a, b = map(int, input().split()) F[a-1].append(b) F[b-1].append(a) rks = [0]*(n) def dfs(s,r): if rks[s] == 0: rks[s] = r for i in F[s]: if rks[i-1] != 0: continue dfs(i-1,r) r = 0 for i in range(n): if rks[i] == 0: r += 1 dfs(i,r) for _ in range(k): c, d = map(int, input().split()) if rks[c-1] == rks[d-1]: B[c-1][0] += 1 B[d-1][0] += 1 counter = Counter(rks) for i in range(n): print(counter[rks[i]] - len(F[i]) - (B[i][0]) - 1)
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): class UnionFind(object): def __init__(self, n=1): # 木の親要素を管理するリストparをつくります。 # par[x] == xの場合には、そのノードが根であることを示します。 # 初期状態では一切グループ化されていないので、すべてのノードが根になりますね。 self.par = [i for i in range(n)] # 木の高さを持っておき、あとで低い方を高い方につなげる。初期状態は0 self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): """ x が属するグループを探索: ある2つの要素が属する木の根が同じかどうかをチェックすればよい。 つまり、親の親の親の・・・と根にたどり着くまで走査すればよい。 再帰。 """ # 根ならその番号を返す 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 と y のグループを結合 """ # 根を探す x = self.find(x) y = self.find(y) # 小さい木に結合して経路圧縮 if x != y: if self.rank[x] < self.rank[y]: x, y = y, x # 同じ長さの場合rankが1増える if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 低い方の木の根を高い方の根とする self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): """ x と y が同じグループか否か """ return self.find(x) == self.find(y) def get_size(self, x): """ x が属するグループの要素数 """ x = self.find(x) return self.size[x] N,M,K=map(int,input().split()) uf = UnionFind(N) # ノード数Nでクラス継承 friends_cnt=[0]*N for i in range(M): # A,Bはノード A, B = map(int, input().split()) A-=1 B-=1 friends_cnt[A]+=1 friends_cnt[B]+=1 # 連結クエリ union uf.union(A, B) blocks=[[] * N for i in range(N)] for i in range(K): x, y = map(int, input().split()) x, y = x - 1, y - 1 blocks[x].append(y) blocks[y].append(x) # 有向ならコメントアウト for i in range(N): ans=uf.get_size(i)-friends_cnt[i]-1 for j in blocks[i]: if uf.is_same(i,j): ans-=1 print(ans,end=' ') print() resolve()
1
61,631,867,851,110
null
209
209
from collections import defaultdict from itertools import groupby, accumulate, product, permutations, combinations from math import gcd def reduction(x,y): g = gcd(x,y) return abs(x)//g,abs(y)//g def solve(): mod = 10**9+7 dplus = defaultdict(lambda: 0) dminus = defaultdict(lambda: 0) N = int(input()) x0,y0,xy0 = 0,0,0 for i in range(N): x,y = map(int, input().split()) if x==0 and y==0: xy0 += 1 elif x==0 and y!=0: x0 += 1 elif y==0: y0 += 1 elif x*y>0: dplus[reduction(x,y)] += 1 else: dminus[reduction(-y,x)] += 1 ans = pow(2,x0,mod)+pow(2,y0,mod)-1 other = N-x0-y0-xy0 for k,v in dplus.items(): ans *= pow(2,dminus[k],mod)+pow(2,v,mod)-1 other -= dminus[k]+v ans *= pow(2,other,mod) ans += xy0-1 ans %= mod return ans print(solve())
for ii in range(1,10): for jj in range(1,10): print("{}x{}={}".format(ii,jj,ii*jj))
0
null
10,552,456,958,558
146
1
N=input() K=int(input()) l=len(N) dp=[[[0]*(K+2) for _ in range(2)] for _ in range(l+1)] dp[0][1][0]=1 for i,c in enumerate(N): x=int(c) for j in range(2): for d in range(x+1 if j==1 else 10): for k in range(K+1): dp[i+1][x==d if j==1 else 0][k+1 if 0<d else k]+=dp[i][j][k] print(dp[l][0][K]+dp[l][1][K])
import sys sys.setrecursionlimit(10000) n = input() k = int(input()) m = {} def doit(n, k): if len(n) == 0: return k == 0 d = int(n[0]) if (n, k) not in m: ret = 0 for i in range(d + 1): if i == d: ret += doit(n[1:], k - 1 if i > 0 else k) else: ret += doit('9' * (len(n) - 1), k - 1 if i > 0 else k) m[(n, k)] = ret return m[(n, k)] print(doit(n, k))
1
76,256,346,977,120
null
224
224
import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().rstrip() def main(): x, k, d = map(int, input().split()) desired = abs(x) // d if k <= desired: if x < 0: x += k * d else: x -= k * d print(abs(x)) return if x < 0: x += desired * d else: x -= desired * d if (k - desired) % 2 == 0: print(abs(x)) return if x == 0: print(d) elif x > 0: x -= d print(abs(x)) elif x < 0: x += d print(abs(x)) if __name__ == '__main__': main()
n, m = map(int, input().split()) A = [] B = [] for line in range(n): A.append(list(map(int, input().split()))) for line in range(m): B.append(int(input())) #print(A,B) ret = [] for i in range(n): ret.append(sum(A[i][j] * B[j] for j in range(m))) print('\n'.join(map(str, ret)))
0
null
3,158,846,816,074
92
56
def readinput(): n,x,m=map(int,input().split()) return n,x,m def main(n,x,m): ans_list=[] hist=[0]*m val=x count=0 while hist[val]==0 and count<n: ans_list.append(val) hist[val]+=1 val=(val*val)%m if count==n: loop_start=0 loop_len=n else: i=0 while ans_list[i] != val: i+=1 loop_start=i loop_len=len(ans_list)-i # print(ans_list) # print(loop_start) # print(loop_len) ans=sum(ans_list[:loop_start]) ans+=sum(ans_list[loop_start:])*((n-loop_start)//loop_len) ans+=sum(ans_list[loop_start:loop_start+(n-loop_start)%loop_len]) # ans=sum(ans_list)*(n//loop_len) + sum(ans_list[:n%loop_len]) return ans if __name__=='__main__': n,x,m=readinput() ans=main(n,x,m) print(ans)
N,X,M = map(int,input().split()) i = X%M L = [i] S = set([i]) i = i**2 % M while not i in S: L.append(i) S.add(i) i = i**2 % M index = L.index(i) k = (N-index)//len(L[index:]) l = (N-index)%len(L[index:]) # これでうまくいくのたまたまだよ。本当はN<indexの場合分けがひつよう。なんで場合分けするよ if N<index: ans = sum(L[:N]) else: ans = sum(L[:index]) + (k*sum(L[index:])) + sum(L[index:index+l]) print(ans)
1
2,832,908,224,650
null
75
75
n=int(input()) a=list(map(int,input().split())) c=0 for i in range(n-1): for j in range(0,n-i-1): if a[j]>a[j+1]:a[j],a[j+1]=a[j+1],a[j];c+=1 print(*a) print(c)
n = int(input()) a = [int(x) for x in input().split()] c = 0 for i in range(n): for j in range(1, n): if a[j - 1] > a[j]: tmp = a[j - 1] a[j - 1] = a[j] a[j] = tmp c += 1 print(" ".join([str(x) for x in a])) print(c)
1
15,879,498,958
null
14
14
from sys import stdin from itertools import accumulate input = stdin.readline n = int(input()) a = list(map(int,input().split())) p = [0] + list(accumulate(a)) res = 0 for i in range(n-1,-1,-1): res += (a[i] * p[i])%(10**9 + 7) print(res % (10**9 + 7))
n=int(input()) d=list(map(int,input().split())) num=[0]*n num[0]=1 if d[0]!=0 or d.count(0)!=1: print(0) else: ans=1 for i in range(1,n): num[d[i]]+=1 for i in range(1,max(d)+1): ans*=num[i-1]**num[i] ans%=998244353 print(ans)
0
null
79,056,245,335,426
83
284
from decimal import * import math a, b = map(Decimal, input().split()) print(math.floor(a * b))
a, b = input().split() a = int(a) if '.' in b: i, f = b.split('.') b = int(i) * 100 + int(f) else: b = int(b) * 100 ans = a * b // 100 print(ans)
1
16,619,867,314,940
null
135
135
import math n=int(input()) m=100000 k=100000 for i in range(n): m=1.05*k m=m/1000 k=math.ceil(m)*1000 print(k)
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): H, A = map(int, input().split()) q, r = divmod(H, A) if r > 0: q = q + 1 print(q) if __name__ == '__main__': solve()
0
null
38,611,526,706,286
6
225
N, M = map(int, input().split()) task = [] for i in range(1, M + 1): task.append("A_" + str(i)) task = map(int, input().split()) task_total = sum(task) if task_total <= N: print(N - task_total) else: print(-1)
n=int(input()) a=list(map(int,input().split())) if n%2==0: dp=[[0 for i in range(2)] for j in range(n)] dp[0][0]=a[0] dp[1][1]=a[1] for i in range(2,n): if i==2: dp[i][0]=dp[i-2][0]+a[i] dp[i][1]=dp[i-2][1]+a[i] else: dp[i][0]=dp[i-2][0]+a[i] dp[i][1]=max(dp[i-2][1],dp[i-3][0])+a[i] print(max(dp[n-1][1],dp[n-2][0])) else: dp=[[0 for i in range(3)] for j in range(n)] dp[0][0]=a[0] dp[1][1]=a[1] dp[2][2]=a[2] for i in range(2,n): if i==2: dp[i][0]=dp[i-2][0]+a[i] dp[i][1]=dp[i-2][1]+a[i] else: dp[i][0]=dp[i-2][0]+a[i] dp[i][1]=max(dp[i-2][1],dp[i-3][0])+a[i] dp[i][2]=max(dp[i-2][2],dp[i-3][1],dp[i-4][0])+a[i] print(max(dp[n-1][2],dp[n-2][1],dp[n-3][0]))
0
null
34,848,930,676,768
168
177
while True: H,W = map(int,input().split()) if H==0 and W==0: break for i in range(H): for k in range(W): if (i+k)%2 == 0: print("#",end = "") else: print(".",end = "") print() print()
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time def I(): return int(input()) def S(): return input() def MI(): return map(int, input().split()) def MS(): return map(str, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def input(): return sys.stdin.readline().rstrip() def make4(initial, L, M, N, O): return [[[[initial for i in range(O)] for n in range(N)] for m in range(M)] for l in range(L)] def make3(initial, L, M, N): return [[[initial for n in range(N)] for m in range(M)] for l in range(L)] def debug(table, *args): ret = [] for name, val in table.items(): if val in args: ret.append('{}: {}'.format(name, val)) print(' | '.join(ret), file=sys.stderr) yn = {False: 'No', True: 'Yes'} YN = {False: 'NO', True: 'YES'} MOD = 10**9+7 inf = float('inf') IINF = 10**19 l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() sys.setrecursionlimit(10**6) nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] show_flg = False # show_flg = True def main(): N = I() A = LI() dp_use = [-IINF] * 3 dp_not_use = [-IINF] * 3 dp_not_use[0] = 0 for i in range(N): dp_use_next = [-IINF] * 3 dp_not_use_next = [-IINF] * 3 for j in range(3): if j - 1 >= 0: dp_not_use_next[j] = max(dp_use[j], dp_not_use[j-1]) else: dp_not_use_next[j] = dp_use[j] dp_use_next[j] = dp_not_use[j] + A[i] # print('dp_use ', *[a if a > -10**10 else '-IINF' for a in dp_use_next]) # print('dp_not_use', *[a if a > -10**10 else '-IINF' for a in dp_not_use_next]) dp_use = dp_use_next dp_not_use = dp_not_use_next if N % 2 == 0: print(max(dp_use[1], dp_not_use[0])) else: print(max(dp_use[2], dp_not_use[1])) if __name__ == '__main__': main()
0
null
19,162,770,816,420
51
177
s=input()*2 r=input() if(r in s): print('Yes') else: print('No')
#!/usr/bin/env python3 c = [[0] * 10 for _ in [0] * 10] for i in range(1, int(input()) + 1): c[int(str(i)[0])][int(str(i)[-1])] += 1 print(sum(c[i][j] * c[j][i] for i in range(10) for j in range(10)))
0
null
43,892,265,465,280
64
234
n,k = map(int,input().split()) if(n//k==0): a =0 else: a = 1 for i in range(100000000000): n = n//k a +=1 if(n<k): break print(a)
A, B = map(int, input().split()) n = 1 while True: A_ = A * n if A_ % B == 0: print(A_) exit() n += 1
0
null
88,925,992,438,780
212
256
import math N = int(input()) MOD_VALUE = math.pow(10, 9) + 7 def pow_mod(value, pow): ret = 1 for _ in range(pow): ret = ret * value % MOD_VALUE return ret result = pow_mod(10, N) - pow_mod(9, N) * 2 + pow_mod(8, N) print(int(result % MOD_VALUE))
n = int(input()) mod=10**9+7 if n==1: print(0) else: print(((10**n)-(9**n)-(9**n)+(8**n))%mod)
1
3,186,845,227,840
null
78
78
if int(input())==1:print(0) else:print(1)
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) x,y=t1*(a1-b1),t2*(a2-b2) if (x+y)==0: print("infinity") elif x*(x+y)>0: print(0) else: if x>0: x1,x2=x,x+y else: x1,x2=-x,-(x+y) if x1%x2==0: print(2*abs(x1//x2)) else: print(2*abs(x1//x2)-1)
0
null
67,545,045,715,236
76
269
h,n = map(int, input().split()) ab = [] amax = 10**5 for _ in range(n): ab.append(tuple(map(int,input().split()))) amax = max(a for a,b in ab) p = [0]*(h+amax+1) for i in range(1,h+amax): p[i] = min(p[i-a]+b for a,b in ab) print(p[h])
import math A, B, C, D = map(int, input().split()) if math.ceil(C/B) <= math.ceil(A/D): print('Yes') else: print('No')
0
null
55,261,497,173,280
229
164
def distance(x, y, p): """returns Minkowski's distance of vactor x and y if p > 0. if p == 0, returns Chebyshev distance >>> d = distance([1, 2, 3], [2, 0, 4], 1) >>> print('{:.6f}'.format(d)) 4.000000 >>> d = distance([1, 2, 3], [2, 0, 4], 2) >>> print('{:.6f}'.format(d)) 2.449490 >>> d = distance([1, 2, 3], [2, 0, 4], 3) >>> print('{:.6f}'.format(d)) 2.154435 >>> d = distance([1, 2, 3], [2, 0, 4], 0) >>> print('{:.6f}'.format(d)) 2.000000 """ if p == 0: return max([abs(a-b) for (a, b) in zip(x, y)]) else: return sum([abs(a-b) ** p for (a, b) in zip(x, y)]) ** (1/p) def run(): dim = int(input()) # flake8: noqa x = [int(i) for i in input().split()] y = [int(j) for j in input().split()] print(distance(x, y, 1)) print(distance(x, y, 2)) print(distance(x, y, 3)) print(distance(x, y, 0)) if __name__ == '__main__': run()
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p1 = p2 = p3 = pi = 0 for i in range(n): p1 += abs(a[i] - b[i]) p2 += (abs(a[i] - b[i]))**2 p3 += (abs(a[i] - b[i]))**3 if pi < abs(a[i] - b[i]): pi = abs(a[i] - b[i]) print("%f" % (p1)) print("%f" % (p2**(1/2))) print("%f" % (p3**(1/3))) print("%f" % (pi))
1
212,593,499,898
null
32
32
import sys from sys import stdin input = stdin.readline import math th = math.pi/3.000000000000000 n = int(input()) p1 = [0.0000000000000000,0.00000000000000000] p2 = [100.0000000000000,0.00000000000000000] def koch(n,p1,p2): if n == 0: return s =[0,0] t =[0,0] u =[0,0] s[0] = (2.0 * p1[0] +1.0 * p2[0]) / 3.0 s[1] = (2.0 * p1[1] +1.0 * p2[1]) / 3.0 t[0] = (1.0 * p1[0] +2.0 * p2[0]) / 3.0 t[1] = (1.0 * p1[1] +2.0 * p2[1]) / 3.0 u[0] = (t[0] - s[0]) * math.cos(th) - (t[1] - s[1]) * math.sin(th) + s[0] u[1] = (t[0] - s[0]) * math.sin(th) + (t[1] - s[1]) * math.cos(th) + s[1] # p1,p2からs,t,uの座標を計算 koch(n-1, p1, s) print(s[0],s[1]) koch(n-1, s, u) print(u[0],u[1]) koch(n-1, u, t) print(t[0],t[1]) koch(n-1, t, p2) print(0,0) koch(n,p1,p2) print(100,0)
import math class vec2d(object): def __init__(self, x, y) -> None: self.x = float(x) self.y = float(y) def rot(self, theta: float): newx = self.x * math.cos(theta) - self.y * math.sin(theta) newy = self.x * math.sin(theta) + self.y * math.cos(theta) return vec2d(newx, newy) def __str__(self): return ' '.join(map(str, [self.x, self.y])) def __format__(self, format_spec): return ' '.join(map(lambda x: format(x, format_spec), [self.x, self.y])) def __add__(self, other): return vec2d(self.x + other.x, self.y + other.y) def __sub__(self, other): return vec2d(self.x - other.x, self.y - other.y) def __mul__(self, k): return vec2d(self.x * k, self.y * k) def __truediv__(self, k): return self.__mul__(1 / k) def prod(self, other): return self.x * other.x + self.y * other.y def cochcurve(p1, p2, n): if n > 0: pd = (p2 - p1) / 3 ps = p1 + pd pu = ps + pd.rot(math.pi / 3) pt = ps + pd cochcurve(p1, ps, n-1) print(f'{ps:>12.6f}') cochcurve(ps, pu, n-1) print(f'{pu:>12.6f}') cochcurve(pu, pt, n-1) print(f'{pt:>12.6f}') cochcurve(pt, p2, n-1) n = int(input()) S = vec2d(0, 0) T = vec2d(100, 0) print(f'{S:>12.6f}') cochcurve(S, T, n) print(f'{T:>12.6f}')
1
126,236,478,382
null
27
27
# B - Product Max def main(): A, B, C, D = map(int, input().split()) res = max(A * C, A * D, B * C, B * D) print(res) if __name__ == "__main__": main()
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) h,a = map(int, input().split()) ans = h // a if (h % a != 0): ans += 1 print(ans)
0
null
39,974,090,178,528
77
225
h, w, k = map(int, input().split()) tbl = [input() for _ in range(h)] # ビット全探索で全パターンをチェック # n個のものからいくつか選ぶ組み合わせの数は 2**n # 例えば、3個の場合は 2**3 = 8通り # 0: 0b000 # 1: 0b001 # 2: 0b010 # 3: 0b011 # 4: 0b100 # 5: 0b101 # 6: 0b110 # 7: 0b111 # バイナリの 0 は選ばれている、1 は選ばれていない # https://drken1215.hatenablog.com/entry/2019/12/14/171657 ans = 0 for i in range(2**h): for j in range(2**w): ct = 0 for ii in range(h): for jj in range(w): # 塗りつぶされない黒をカウントする # カウントした結果が残った数と同じであれば、回答に+1 if (i>>ii)&1 == 0 and (j>>jj)&1 == 0: if tbl[ii][jj] == '#': ct += 1 if ct == k: ans += 1 print(ans)
sel='E' #A if sel=='A': N,M=map(int,input().split()) ans=0 ans+=M*(M-1)//2 ans+=N*(N-1)//2 print(ans) #B if sel=='B': def ispal(s): for i in range(len(s)//2+1): if s[i]!=s[-(i+1)]: return False return True S=input() N=len(S) if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]): print('Yes') else: print('No') #C if sel=='C': L=int(input()) print((L**3)/27) #D if sel=='D': N=int(input()) A=[int(i) for i in input().split()] kin=list(set(A)) cnt={} for k in kin: cnt[k]=0 for a in A: cnt[a]+=1 SUM=0 for k in kin: SUM+=cnt[k]*(cnt[k]-1)//2 for a in A: if cnt[a]>=2: print(SUM-cnt[a]+1) else: print(SUM) #E if sel=='E': def add(in1, in2): return [a + b for a, b in zip(in1, in2)] def split(ar, k, w): a = 0 if max(max(ar)) > k: return -1 tm = ar[0] for i in range(1, w): tm = add(tm, ar[i]) if max(tm) > k: a += 1 tm = ar[i] return a h, w, k = map(int, input().split()) s = [[int(i) for i in input()] for j in range(h)] ans = h*w for i in range(2**(h-1)): data = [] temp = s[0] sp = bin(i+2**h)[4:] for j in range(1, h): if sp[j-1] == "0": temp = add(temp, s[j]) else: data.append(temp) temp = s[j] data.append(temp) ans_ = split([list(x) for x in zip(*data)], k, w) if ans_ == -1: continue ans_ += sp.count("1") if ans > ans_: ans = ans_ print(ans) # #F # if sel=='F': # N,S=map(int,input().split()) # A=[int(i) for i in input().split()]
0
null
28,834,872,392,950
110
193
import numpy as np def main(): H, W, K = map(int, input().split()) S = [] for _ in range(H): S.append(list(map(int, list(input())))) S = np.array(S) if S.sum() <= K: print(0) exit(0) answer = float('INF') for i in range(0, 2 ** (H - 1)): horizons = list(map(int, list(bin(i)[2:].zfill(H - 1)))) result = greedy(W, S, K, horizons, answer) answer = min(answer, result) print(answer) # ex. horizons = [0, 0, 1, 0, 0, 1] def greedy(W, S, K, horizons, current_answer): answer = sum(horizons) # ex. # S = [[1, 1, 1, 0, 0], # [1, 0, 0, 0, 1], # [0, 0, 1, 1, 1]] # horizons = [0, 1]のとき, # S2 = [[2, 1, 1, 0, 0], # [0, 0, 1, 1, 1]] # となる top = 0 bottom = 0 S2 = [] for h in horizons: if h == 1: S2.append(S[:][top:(bottom + 1)].sum(axis=0).tolist()) top = bottom + 1 bottom += 1 S2.append(S[:][top:].sum(axis=0).tolist()) # ブロック毎の累積和を計算する h = len(S2) partial_sums = [0] * h for right in range(W): current = [0] * h for idx in range(h): current[idx] = S2[idx][right] partial_sums[idx] += S2[idx][right] # 1列に含むホワイトチョコの数がkより多い場合 if max(current) > K: return float('INF') # 無理な(ブロックの中のホワイトチョコの数をk以下にできない)場合 if max(partial_sums) > K: answer += 1 if answer >= current_answer: return float('INF') partial_sums = current return answer if __name__ == '__main__': main()
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): H, W, K = NMI() choco = [SI() for _ in range(H)] ans = 100000 for case in range(2**(H-1)): groups = [[0]] for i in range(H-1): if (case >> i) & 1: groups[-1].append(i+1) else: groups.append([i+1]) white = [0] * len(groups) is_badcase = False cut = len(groups) - 1 for w in range(W): diff = [0] * len(groups) for gi, group in enumerate(groups): for h in group: if choco[h][w] == "1": white[gi] += 1 diff[gi] += 1 if max(white) <= K: is_cont = True continue if max(diff) > K: is_badcase = True break cut += 1 white = diff[:] continue if not is_badcase: ans = min(ans, cut) print(ans) if __name__ == "__main__": main()
1
48,649,481,935,028
null
193
193
import sys input = lambda: sys.stdin.readline().rstrip() def main(): n = int(input()) a = [int(i) for i in input().split()] mark = 1 remain = 0 for i in range(n): if a[i] == mark: remain += 1 mark += 1 if remain == 0: print(-1) else: print(n-remain) if __name__ == '__main__': main()
n = int(input()) l = [] for i in range(1,n+1) : if i%3 != 0 and i%5 != 0 : l.append(i) print(sum(l))
0
null
75,005,193,910,108
257
173
def gcd(a, b): if b == 0: return a return gcd(b, a % b) import fileinput import math for line in fileinput.input(): a, b = map(int, line.split()) g = gcd(a, b) lcm = a * b // g print(g, lcm)
n = int(input()) ans = set() for _ in range(n): ans.add(input()) print(len(ans))
0
null
15,247,723,182,720
5
165
days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] S = input() for i in range(7): if S == days[i]: print(7 - i) exit()
x = int(input()) a = x // 100 b = x - a * 100 while b > 5: b = b - 5 a -= 1 if a>=1: print(1) else: print(0)
0
null
130,230,753,366,140
270
266
N = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(0, N, 2): if a[i] % 2 == 1: cnt += 1 print(cnt)
N = int(input()) lst = input().split() count = 0 for i in range(N): if (i + 1) % 2 == 1 and int(lst[i]) % 2 == 1: count += 1 print(count)
1
7,811,008,377,952
null
105
105
s=input() print("Yes" if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi" else "No")
def main(): h, w, m = map(int, input().split()) hp = [0]*h wp = [0]*w hw = set() for _ in range(m): h1, w1 = map(int, input().split()) hp[h1-1] += 1 wp[w1-1] += 1 hw.add((h1, w1)) h_max = max(hp) w_max = max(wp) hh = [i+1 for i, v in enumerate(hp) if v == h_max] ww = [i+1 for i, v in enumerate(wp) if v == w_max] ans = h_max + w_max for hb in hh: for wb in ww: if (hb, wb) not in hw: print(ans) exit() print(ans-1) if __name__ == '__main__': main()
0
null
29,060,625,043,242
199
89
import math a,b,x = map(int,input().split()) if x >= a**2*b/2: tan = 2*(b/a-x/(a**3)) y = math.atan(tan) else : tan = a*(b**2)/(2*x) y = math.atan(tan) print(math.degrees(y))
import numpy as np a, b, x = map(int,input().split()) th = a**2 * b / 2 if x <= th: ans = np.arctan(a*b**2/2/x) else: ans = np.arctan((2*b-2*x/a**2)/a) print(np.degrees(ans))
1
163,120,346,970,662
null
289
289
n = int(input()) x = input() original_pop_count = x.count('1') one_pop_count = original_pop_count - 1 # 0になりうる zero_pop_count = original_pop_count + 1 # X mod p(X) += 1 の前計算 one_mod = 0 zero_mod = 0 for b in x: if one_pop_count != 0: one_mod = (one_mod * 2 + int(b)) % one_pop_count zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count # f の前計算 f = [0] * 220000 pop_count = [0] * 220000 for i in range(1, 220000): # pop_count[i] = pop_count[i // 2] + i % 2 pop_count[i] = bin(i)[2:].count('1') f[i] = f[i % pop_count[i]] + 1 for i in range(n-1, -1, -1): if x[n-i-1] == '1': if one_pop_count != 0: nxt = one_mod nxt -= pow(2, i, one_pop_count) nxt %= one_pop_count print(f[nxt] + 1) else: print(0) elif x[n-i-1] == '0': nxt = zero_mod nxt += pow(2, i, zero_pop_count) nxt %= zero_pop_count print(f[nxt] + 1)
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし N = I() X = LI2() X.reverse() if N == 1 and len(X) == 1 and X[0] == 0: print(1) exit() def popcount(n): res = 0 m = n.bit_length() for i in range(m): res += (n >> i) & 1 return res # 1回の操作で 2*10**5 未満になることに注意 F = [0]*(2*10**5) # F[i] = f(i) for i in range(1,2*10**5): F[i] = 1 + F[i % popcount(i)] a = sum(X) b = a-1 c = a+1 if a == 1: C = [1] # 2冪をcで割った余り xc = 0 # Xをcで割った余り for i in range(N): if X[i] == 1: xc += C[-1] xc %= c C.append((2 * C[-1]) % c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(0) else: ANS.append(1 + F[(xc + C[i]) % c]) ANS.reverse() print(*ANS, sep='\n') exit() B,C = [1],[1] # 2冪をb,cで割った余り xb,xc = 0,0 # Xをb,cで割った余り for i in range(N): if X[i] == 1: xb += B[-1] xc += C[-1] xb %= b xc %= c B.append((2*B[-1])%b) C.append((2*C[-1])%c) ANS = [] for i in range(N): if X[i] == 1: ANS.append(1 + F[(xb-B[i]) % b]) else: ANS.append(1 + F[(xc+C[i]) % c]) ANS.reverse() print(*ANS,sep='\n')
1
8,202,775,560,932
null
107
107
n = int(input()) R = (int(input()) for _ in range(n)) ret = -(10 ** 9) mn = next(R) for r in R: ret = max(ret, r - mn) mn = min(mn, r) print(ret)
#-*- coding:utf-8 -*- def main(): n , data = input_data() vMax = float('-inf') vMin = data.pop(0) for Rj in data: if vMax < Rj - vMin: vMax = Rj - vMin if vMin > Rj: vMin = Rj print(vMax) def input_data(): n = int(input()) lst = [int(input()) for i in range(n)] return (n , lst) if __name__ == '__main__': main()
1
12,531,707,430
null
13
13
n = int(input()) S = input() ans = 0 def ok(i): pin = '{:0=3}'.format(i) j = 0 for s in S: if s == pin[j]: j += 1 if j == 3: return True else: return False for i in range(1000): ans += ok(i) print(ans)
N = int(input()) S = input() ans = 0 for i in range(10): for j in range(10): for k in range(10): a = [i, j, k] l = 0 for s in S: if l < 3 and a[l] == int(s): l += 1 if l == 3: ans += 1 print(ans)
1
128,880,931,079,380
null
267
267
#atcoder t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) d1=a1-b1 d2=a2-b2 if d1*d2>0: print(0) else: if d1>0 and d2<0: plus=d1*t1+d2*t2 if plus>0: print(0) elif plus==0: print("infinity") elif plus<0: d=-plus k=d1*t1 if k%d==0: print(2*k//d) else: print(2*(k//d)+1) else: d1=-d1 d2=-d2 plus=d1*t1+d2*t2 if plus>0: print(0) elif plus==0: print("infinity") elif plus<0: d=-plus k=d1*t1 if k%d==0: print(2*k//d) else: print(2*(k//d)+1)
def resolve(): INF = 1<<60 H, N = map(int, input().split()) A, B = [], [] for i in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) dp = [INF]*(H+1) dp[0] = 0 for h in range(H): for i in range(N): to = min(H, A[i]+h) dp[to] = min(dp[to], dp[h]+B[i]) print(dp[H]) if __name__ == "__main__": resolve()
0
null
106,660,958,414,470
269
229
import numpy n, m = [int(i) for i in input().split()] A = [int(i) for i in input().split()] sup_A = 10 ** 5 B = [0] * (1 << 18) for a in A: B[a] += 1 C = numpy.fft.fft(B) D = numpy.fft.ifft(C * C) ans = 0 cnt = 0 for i in range(2 * sup_A, -1, -1): d = int(D[i].real + 0.5) if cnt + d >= m: ans += (m - cnt) * i break cnt += d ans += i * d print(ans)
n, m = map(int, input().split(' ')) A = [] i = 0 while i < n: a = list(map(int, input().split(' '))) A.append(a) i += 1 x = [] j = 0 while j < m: x.append(int(input())) j += 1 ans = '' p = 0 while p < n: q = 0 a0 = 0 while q < m: a0 += A[p][q] * x[q] q += 1 ans += str(int(a0)) + '\n' p += 1 print(ans[:-1])
0
null
54,875,187,998,822
252
56
count = int(raw_input()) S = [] H = [] C = [] D = [] while count: arr = map(str, raw_input().split(" ")) if arr[0] == "S": S.append(int(arr[1])) elif arr[0] == "H": H.append(int(arr[1])) elif arr[0] == "C": C.append(int(arr[1])) else: D.append(int(arr[1])) count -= 1 S.sort() H.sort() C.sort() D.sort() ans_s = [] ans_h = [] ans_c = [] ans_d = [] for x in range(1, 14): if not x in S: ans_s.append(x) if not x in H: ans_h.append(x) if not x in C: ans_c.append(x) if not x in D: ans_d.append(x) def answer(arr, value): for x in arr: print "%s %s" % (value, str(x)) answer(ans_s, 'S') answer(ans_h, 'H') answer(ans_c, 'C') answer(ans_d, 'D')
n = int(input()) S = [False for i in range(13)] D = [False for i in range(13)] C = [False for i in range(13)] H = [False for i in range(13)] for i in range(n): a,b = input().split() b = int(b) if a == "S": S[b-1] = True elif a == "D": D[b-1] = True elif a == "C": C[b-1] = True elif a == "H": H[b-1] = True for i in range(13): if S[i] == False: print("S "+str(i+1)) for i in range(13): if H[i] == False: print("H "+str(i+1)) for i in range(13): if C[i] == False: print("C "+str(i+1)) for i in range(13): if D[i] == False: print("D "+str(i+1))
1
1,022,850,799,058
null
54
54
s,w = map(int,input().split()) print("unsafe" if w>=s else "safe")
def combination(n, r, m): res = 1 r = min(r, n - r) for i in range(r): res = res * (n - i) % m res = res * pow(i + 1, m - 2, m) % m return res mod = 10**9 + 7 n, a, b = map(int, input().split()) total = pow(2, n, mod) - 1 total -= (combination(n, a, mod) + combination(n, b, mod)) % mod print(total % mod)
0
null
47,616,138,322,292
163
214
import sys,math,collections from collections import defaultdict #from itertools import permutations,combinations def file(): sys.stdin = open('input.py', 'r') sys.stdout = open('output.py', 'w') def get_array(): l=list(map(int, input().split())) return l def get_2_ints(): a,b=map(int, input().split()) return a,b def get_3_ints(): a,b,c=map(int, input().split()) return a,b,c def sod(n): n,c=str(n),0 for i in n: c+=int(i) return c def getFloor(A, x): (left, right) = (0, len(A) - 1) floor = -1 while left <= right: mid = (left + right) // 2 if A[mid] == x: return A[mid] elif x < A[mid]: right = mid - 1 else: floor = A[mid] left = mid + 1 return floor #file() def main(): n=int(input()) l=get_array() c=0 for i in range(0,n,2): if(l[i]&1): c+=1 print(c) if __name__ == '__main__': main()
n=input() s=range(1,14) h=range(1,14) c=range(1,14) d=range(1,14) trump={'S':s,'C':c,'H':h,'D':d} for i in range(n): suit,num=raw_input().split() num=int(num) trump[suit].remove(num) count=0 for suit in ['S','H','C','D']: for num in trump[suit]: print('%s %d'%(suit,num))
0
null
4,373,248,471,520
105
54
# -*- utf-8 -*- while True: try: inp = raw_input() i = map(int, inp.split()) a = i[0] b = i[1] s = a + b except: break ans = 0 while s >= 1: s /= 10 ans += 1 print ans
import math import sys for num in sys.stdin: num = num.split() a = int(num[0]) b = int(num[1]) size = int (math.log10(a+b) + 1) print(size)
1
122,108,518
null
3
3
k = int(input()) s = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51' arr = [int(x) for x in s.split(', ')] print(arr[k - 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 from fractions import gcd def input(): return sys.stdin.readline().strip() def STR(): return input() 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 = sys.maxsize mod = 10 ** 9 + 7 arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] n = INT() print(arr[n - 1])
1
49,745,623,308,278
null
195
195
N = int(input()) A = list(map(int,input().split())) R, B, G = 0, 0, 0 ans = 1 for a in A: if R == a: if B == a and G == a: ans *= 3 elif B == a or G == a: ans *= 2 else: ans *= 1 R += 1 elif B == a: if G == a: ans *= 2 else: ans *= 1 B += 1 elif G == a: ans *= 1 G += 1 else: print(0) exit() ans %= 10**9+7 print(ans)
S = list(str(input())) T = list(str(input())) if S == T[:len(T)-1]: print('Yes') else: print('No')
0
null
75,802,949,326,556
268
147
h, w = map(int, input().split()) s = [list(map(str, input().rstrip())) for _ in range(h)] dp = [[10001] * w for _ in range(h)] if s[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 moves = [[1, 0], [0, 1]] for y in range(h): for x in range(w): for m in moves: ny, nx = y + m[0], x + m[1] if ny >= h or nx >= w: continue add = 0 # .から#に突入する時だけカウントが増える if s[y][x] == "." and s[ny][nx] == "#": add = 1 dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add) print(dp[-1][-1])
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) n = ini() print(n + n**2 + n**3)
0
null
29,569,637,269,230
194
115
N = int(input()) slist = [] tlist = [] from itertools import accumulate for _ in range(N): s, t = input().split() slist.append(s) tlist.append(int(t)) cum = list(accumulate(tlist)) print(cum[-1]-cum[slist.index(input())])
N = int(input()) S = [""] * N T = [0] * N for i in range(N): s, t = input().split() S[i] = s T[i] = int(t) X = input() t = 0 for i in range(N): t += T[i] if S[i] == X: break print(sum(T) - t)
1
96,911,267,051,482
null
243
243
n=int(input()) a=[0]+[int(x) for x in input().split()] ans=[0]*(n+1) for i in range(len(a)): ans[a[i]]=i ans.pop(0) print(*ans)
N = int(input()) A = list(map(int, input().split())) y = sorted([(i+1, A[i]) for i in range(N)], key=lambda x: x[1]) print(" ".join(map(str, [z[0] for z in y])))
1
180,910,719,226,148
null
299
299
N ,K = map(int, input().split()) lst = [i for i in range(N+1)] rlst = [i for i in range(N,-1,-1)] P = 10**9 + 7 rlt = 0 mini = sum(lst[:K-1]) maxi = sum(rlst[:K-1]) for i in range(N -K + 2): mini += lst[K+i-1] maxi += rlst[K+i-1] rlt += maxi -mini + 1 rlt %= P print(rlt)
N = int(input()) primes = {} for num in range(2, int(N**0.5)+1): while N%num == 0: if num in primes: primes[num] += 1 else: primes[num] = 1 N //= num ans = 0 for p in primes.values(): n = 1 while n*(n+1)//2 <= p: n += 1 ans += n-1 if N > 1: ans += 1 print(ans)
0
null
24,980,597,721,288
170
136
s = list(input()) if len(s) % 2 != 0: print("No") exit() while s: if s[0]=="h" and s[1] == "i": s.pop(0) s.pop(0) else: print("No") exit() print("Yes")
s = input() hitachi = "" for i in range(5): hitachi += "hi" if s==hitachi: print("Yes") exit(0) print("No")
1
53,071,185,693,358
null
199
199
import math X = int(input()) print(X * 2 * math.pi)
n = int(input()) lr1, lr2 = [], [] res = 0 for _ in range(n): s = input() m = len(s) l, r = 0, 0 tmp = 0 for i in range(m): if s[i] == ')': tmp += 1 else: tmp -= 1 l = max(l, tmp) tmp = 0 for i in range(m): if s[m-1-i] == '(': tmp += 1 else: tmp -= 1 r = max(r, tmp) res += r - l if r - l >= 0: lr1.append((l, r)) else: lr2.append((l, r)) if res != 0: print('No') exit() lr1.sort(key=lambda x: x[0]) lr2.sort(key=lambda x: x[1]) flg1, flg2 = True, True n1, n2 = len(lr1), len(lr2) tmp = 0 for i in range(n1): l, r = lr1[i] tmp -= l if tmp < 0: flg1 = False tmp += r tmp = 0 for i in range(n2): l, r = lr2[i] tmp -= r if tmp < 0: flg2 = False tmp += l if flg1 and flg2: print('Yes') else: print('No')
0
null
27,694,533,450,560
167
152
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline s = input().rstrip() n = len(s) t = s[0:(n-1)//2] q = s[(n+2)//2:n] if s == s[::-1] and t == t[::-1] and q == q[::-1]: print("Yes") else: print("No")
import math N = int(input()) X = list(map(int, input().split())) def average(a): return sum(a) / len(a) avg = average(X) res = 0 if avg - int(avg) >= 0.5: for i in X: res += (i - math.ceil(avg)) **2 else: for i in X: res += (i - math.floor(avg)) ** 2 print(res)
0
null
55,907,365,733,398
190
213
def main(): s = str(input()) dic = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1} print(dic.get(s)) main()
def divisor(x): table = [] i = 1 while i * i <= x: if x%i == 0: table.append(i) table.append(n//i) i +=1 table.sort() return table n = int(input()) l = divisor(n) c = len(l) ans = 100100100100100 for i in range(c): x = l[i] - 1 y = l[c-i-1] - 1 tot = x + y ans = min(ans,tot) print(ans)
0
null
147,151,503,913,960
270
288
while True: a, b = map(int, input().split()) if(a == 0 and b == 0): break for i in range(a): for j in range(b): if(0 < i < a-1 and 0 < j < b-1): print(".", end = "") else: print("#", end = "") print() print()
while True: h,w = map(int,input().split()) if h == 0 and w == 0: break for x in range(h): if x == range(h)[0] or x == range(h)[-1]: print(w*"#",end="") else: for y in range(w): if y == range(w)[0] or y == range(w)[-1]: print("#",end="") else: print(".",end="") print() print()
1
803,731,719,022
null
50
50
import math n = int(input()) a = n/2 print(math.ceil(a)-1)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import defaultdict from itertools import accumulate n, k = map(int, readline().split()) a = list(map(lambda x: int(x) - 1, readline().split())) cumsum = [0] + list(map(lambda x: int(x) % k, list(accumulate(a)))) dict = defaultdict(int) ans = 0 for i, v in enumerate(cumsum): ans += dict[v] dict[v] += 1 if i >= k - 1: dict[cumsum[i - k + 1]] -= 1 print(ans)
0
null
145,349,861,768,988
283
273
import fractions from functools import reduce def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) A,B=list(map(int,input().split())) print(lcm_list([A,B]))
a,b=map(int,input().split()) def factorization(n): arr = [] tmp = n for i in range(2, int(n**0.5//1)+1): if tmp%i==0: cnt = 0 while tmp%i==0: cnt+=1 tmp//=i arr.append([i,cnt]) if tmp!=1: arr.append([tmp,1]) if arr==[]: arr.append([n,1]) return arr a_arr = factorization(a) b_arr = factorization(b) a_map = {str(arr[0]):arr[1] for arr in a_arr} b_map = {str(arr[0]):arr[1] for arr in b_arr} factor = set(list(a_map.keys())+list(b_map.keys())) ans = 1 for i in factor: if str(i) in a_map.keys(): a_num = a_map[str(i)] else: a_num = 0 if str(i) in b_map.keys(): b_num = b_map[str(i)] else: b_num = 0 ans *= int(i)**(max(a_num,b_num)) print(ans)
1
113,543,015,218,010
null
256
256
n = int(input()) a = list(map(int, input().split())) target = 1 broken = 0 for i in a: if i == target: target += 1 else: broken += 1 if broken < n: print(broken) else: print(-1)
X, Y, A, B, C = [int(_) for _ in input().split()] P = [int(_) * 3 for _ in input().split()] Q = [int(_) * 3 + 1 for _ in input().split()] R = [int(_) * 3 + 2 for _ in input().split()] S = sorted(P + Q + R) cnt = [0, 0, 0] ans = [0, 0, 0] limit = [X, Y, 10**10] while S: s = S.pop() q, r = divmod(s, 3) if cnt[r] >= limit[r]: continue cnt[r] += 1 ans[r] += q if sum(cnt) == X + Y: print(sum(ans)) exit()
0
null
80,074,340,067,050
257
188
i = int(input()) print(i^1)
n = int(input()) print(n^1)
1
2,935,695,186,788
null
76
76
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, k = map(int, readline().split()) a = list(map(int, readline().split())) memo = [0] * (n + 1) for _ in range(k): flag = True for i, aa in enumerate(a): bf = (i - aa if i - aa >= 0 else 0) af = (i + aa + 1 if i + aa < n else n) memo[bf] += 1 memo[af] -= 1 for i in range(n): memo[i + 1] += memo[i] a[i] = memo[i] if a[i] != n: flag = False memo[i] = 0 if flag: break print(*a) if __name__ == '__main__': main()
n,m=map(int,input().split()) a=list(map(int,input().split())) def func(n): ret=0 n=n/2 while n.is_integer(): ret+=1 n=n/2 return ret b=func(a[0]) for i in range(1,n): if b==func(a[i]): continue else: print(0) exit(0) from fractions import gcd lcmn=a[0]//2 for i in range(1,n): lcmn=(lcmn*a[i]//2)//gcd(lcmn,a[i]//2) print((1+m//lcmn)//2)
0
null
58,532,279,518,268
132
247
s = input() ls = ['SUN','MON','TUE','WED','THU','FRI','SAT'] for i, x in enumerate(ls): if s == x: print(7-i)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) YES = "Yes" # type: str NO = "No" # type: str def solve(X: int): if X >= 30: ret = YES else: ret = NO print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int solve(X) if __name__ == '__main__': main()
0
null
69,476,442,947,168
270
95
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, t = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort() res = 0 dp = [[0] * (t + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = AB[i - 1] for j in range(1, t + 1): if j - a >= 0: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b) else: dp[i][j] = dp[i - 1][j] for k in range(i, n): _, b = AB[k] res = max(res, dp[i][j - 1] + b) print(res) if __name__ == '__main__': resolve()
if int(input()) >= 30:print('Yes') else:print('No')
0
null
78,685,579,783,502
282
95
score = input() scin = score.split() ans = int(scin[0]) * int(scin[1]) print(ans)
import sys def input(): return sys.stdin.readline().rstrip() N, X, M = map(int, input().split()) numlist = [-1] * M num = X ans = num roop_start = -1 for i in range(N-1): new_num = (num * num) % M if numlist[num] == -1: numlist[num] = new_num ans += new_num num = new_num else: roop_start = num break num = roop_start if roop_start == -1: print(ans) else: roop_sum = [num] for i in range(N-1): new_num = numlist[num] numlist[num] = -1 if numlist[new_num] == -1: break else: roop_sum.append(roop_sum[-1] + new_num) num = new_num if numlist[X] != -1: count = 0 ans = 0 for i in range(M): if numlist[i] != -1: ans += i count += 1 N -= count else: ans = 0 size = len(roop_sum) div = N // size rest = N % size ans += div * roop_sum[-1] if rest != 0: ans += roop_sum[rest-1] print(ans)
0
null
9,371,959,362,948
133
75