code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
square = input() down = [] edge = [] pool = [] for i, strings in enumerate(square): if strings == "\\": down.append(i) elif down and strings == "/": left = down.pop() area = i - left while edge: if edge[-1] < left: break edge.pop() area += pool.pop() edge.append(left) pool.append(area) print(sum(pool)) print(len(pool), *pool)
N = int(input()) A = [int(a) for a in input().split()] if A.count(0): print(0) exit(0) ans=1 for a in A: ans *= a if ans > 10**18: print(-1) break else: print(ans)
0
null
8,154,441,137,288
21
134
list = map(int,raw_input().split()) list.sort() print'%d %d %d' %(list[0],list[1],list[2])
x = input().split() a = int(x[0]) b = int(x[1]) c = int(x[2]) if a <= b <= c: print(a,b,c) elif a <= c <= b: print(a,c,b) elif b <= a <= c: print(b,a,c) elif b <= c <= a: print(b,c,a) elif c <= a <= b: print( c,a,b) else: print(c,b,a)
1
419,094,351,088
null
40
40
a=int(input()) x=(a-2)/2 if int(x) ==x: print(int(x)) else: print(int(x+1))
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) P = [None] + P C = [None] + C all_max = C[1] for st in range(1, N + 1): p = P[st] scores = [C[p]] while p != st and len(scores) < K: p = P[p] scores.append(C[p]) num_elem = len(scores) all_sum = sum(scores) q, r = divmod(K, num_elem) max_ = scores[0] temp = scores[0] max_r = scores[0] temp_r = scores[0] for x in range(1, num_elem): if x < r: temp_r += scores[x] max_r = max(max_r, temp_r) temp += scores[x] max_ = max(max_, temp) temp_max = scores[0] if all_sum > 0 and q > 0: if r > 0: temp_max = max(all_sum * (q - 1) + max_, all_sum * q + max_r) else: temp_max = all_sum * (q - 1) + max_ else: temp_max = max_ all_max = max(all_max, temp_max) print(all_max)
0
null
79,656,852,978,144
283
93
n, m = [int(i) for i in input().split()] C = [int(i) for i in input().split()] dp = [100000] * (n + 1) dp[0] = 0 for k in C: for j in range(k, n + 1): if dp[j] > dp[j - k] + 1: dp[j] = dp[j - k] + 1 print(dp[n])
n = int(input()) s = [int(i) for i in input().split()] s.sort() flag = False for i in range (0,n-1): if s[i] == s[i+1]: flag = True break if flag == True: print("NO") else: print("YES")
0
null
36,823,102,055,970
28
222
n = int(input()) hon = [2, 4, 5, 7, 9] bon = [3] pon = [1, 6, 0] if int(str(n)[-1]) in hon: print("hon") elif int(str(n)[-1]) in bon: print("bon") else: print("pon")
import math a=100 n=int(input()) for i in range(n): a=a*1.05 a=math.ceil(a) print(a*1000)
0
null
9,702,310,489,362
142
6
n = int(input()) tbl = [[0 for i in range(n)] for j in range(5)] for i in range(2): a = list(map(int,input().split())) for j in range(n): tbl[i][j] = a[j] D_1 = 0 d_2 = 0 d_3 = 0 for k in range(n): tbl[2][k] = abs(tbl[0][k]-tbl[1][k]) tbl[3][k] = (abs(tbl[0][k]-tbl[1][k]))**2 tbl[4][k] = (abs(tbl[0][k]-tbl[1][k]))**3 D_1 += tbl[2][k] d_2 += tbl[3][k] d_3 += tbl[4][k] M = max(tbl[2]) print(f'{D_1:.6f}') print(f'{(d_2)**(1/2):.6f}') print(f'{(d_3)**(1/3):.6f}') print(f'{M:.6f}')
from math import pow,fabs N = int(input()) X = list(map(float,input().split())) Y = list(map(float,input().split())) def distance(length,x,y,n): D = 0 for i in range(length): D += fabs(x[i]-y[i]) ** n return pow(D,1.0/n) def che_distance(length,x,y): D = 0 for i in range(length): if D < fabs(x[i]-y[i]): D = fabs(x[i]-y[i]) return D p1 = distance(N,X,Y,1) p2 = distance(N,X,Y,2) p3 = distance(N,X,Y,3) pinf = che_distance(N,X,Y) print("{}\n{}\n{}\n{}".format(p1,p2,p3,pinf))
1
215,194,018,600
null
32
32
n = int(input()) p = list(map(int, input().split())) mini = p[0] ans = 0 for i in p: if i <= mini: ans += 1 mini = min(mini,i) print(ans)
n=int(input()) a=list(map(int,input().split())) if n==1: print(1) else: min1=a[0] ans=1 for x in range(1,n): if min1>=a[x]: ans+=1 min1=min(min1,a[x]) print(ans)
1
85,313,796,768,760
null
233
233
from collections import defaultdict n = int(input()) A = list(map(int, input().split())) cnt = defaultdict(int) ans = 0 for i, a in enumerate(A): ans += cnt[i+1 - a] cnt[i+1 + a] += 1 print(ans)
N,K = map(int,input().split()) A = list(map(int,input().split())) def check(m): n = 0 for a in A: if a%m == 0: n += a//m - 1 else: n += a//m return n <= K l = 0 r = 10**9+10 while r-l > 1: m = (r+l) // 2 if check(m): r = m else: l = m print(r)
0
null
16,209,510,078,552
157
99
import sys from collections import deque sys.setrecursionlimit(10**7) input = sys.stdin.readline n,x,y = map(int, input().split()) g = [[] for _ in range(n)] for i in range(1, n): a = i - 1 b = i g[a].append(b) g[b].append(a) x -= 1 y -= 1 g[x].append(y) g[y].append(x) ans = [0] * n for i in range(n): stack = deque() dis = [0] * n seen = [False] * n stack = deque() stack.append(i) seen[i] = True while stack: v = stack.popleft() for nv in g[v]: if seen[nv]: continue dis[nv] = dis[v] + 1 seen[nv] = True stack.append(nv) for j in range(n): ans[dis[j]] += 1 for i in range(1, n): print(ans[i] // 2)
H, N = map(int, input().split()) As = list(map(int, input().split())) sumA = sum(As) if sumA >= H: print('Yes') else: print('No')
0
null
60,901,428,928,028
187
226
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) lr = [None]*n for i in range(n): x,l = map(int, input().split()) lr[i] = (x-l, x+l) lr.sort(key=lambda x: x[1]) ans = 0 c = -10**10 for l,r in lr: if c<=l: ans += 1 c = r print(ans)
N=int(input()) LR=[] for i in range(N): X,L=map(int,input().split()) LR.append([X-L,X+L]) LR.sort(key=lambda x:x[1]) nin=LR[0][1] ans=1 for i in range(1,N): if nin<=LR[i][0]: nin=LR[i][1] ans+=1 print(ans)
1
89,860,388,661,218
null
237
237
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b n = int(input()) a = list(map(int, input().split())) l = 1 for i in a: l = lcm(l, i) ans = 0 for i in a: ans += l // i print(ans % 1000000007)
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) Ad = A1 * T1 + A2 * T2 Bd = B1 * T1 + B2 * T2 if Ad == Bd: print('infinity') else: if Bd > Ad: Ad, Bd = Bd, Ad A1, B1 = B1, A1 if A1 > B1: print(0) else: num = (B1 - A1) * T1 // (Ad - Bd) if (B1 - A1) * T1 % (Ad - Bd) == 0: print(num * 2) else: print(num * 2 + 1)
0
null
109,471,299,672,322
235
269
N,M = (int(x) for x in input().split()) A = [int(x) for x in input().split()] A = sorted(A,reverse=True) if A[M-1] * 4 * M >= sum(A): print("Yes") else: print("No")
n, m = (int(x) for x in input().split()) list_a = sorted([int(x) for x in input().split()], reverse=True) for i in range(0, m): if list_a[i] < sum(list_a) / (4 * m): print('No') exit() print('Yes')
1
38,679,604,002,052
null
179
179
#!/usr/bin/env python3 T = list(input()) cnt = 0 for i in range(len(T)): if T[i] == '?': T[i] = 'D' print(''.join(T))
def main() -> None: t = input() print(t.replace('?','D')) return if __name__ == '__main__': main()
1
18,490,633,388,568
null
140
140
import math n = int(input()) a = list(map(int,input().split())) def generate_D(maxA): seq = [i for i in range(maxA+1)] p = 2 while p*p <= maxA: if seq[p]==p: for q in range(p*2,maxA+1,p): if seq[q]==q: seq[q] = p p += 1 return seq cur = a[0] for v in a[1:]: cur = math.gcd(cur,v) if cur > 1: print('not coprime') else: d = generate_D(max(a)) primes = set([]) tf = 1 for v in a: tmp = set([]) while v > 1: tmp.add(d[v]) v //= d[v] for k in tmp: if k in primes: tf = 0 else: primes.add(k) if tf: print('pairwise coprime') else: print('setwise coprime')
import math from functools import reduce def getD(num): input_list = [2 if i % 2 == 0 else i for i in range(num+1)] input_list[0] = 0 bool_list = [False if i % 2 == 0 else True for i in range(num+1)] sqrt = int(math.sqrt(num)) for serial in range(3, sqrt + 1, 2): if bool_list[serial]: for s in range(serial ** 2, num+1, serial): if bool_list[s]: input_list[s] = serial bool_list[s] = False return input_list N = int(input()) A = list(map(int, input().split())) D = getD(max(A)) pairwise_coprime = True use_divnum = set() for i in range(N): k = A[i] while k != 1: if D[k] in use_divnum: pairwise_coprime = False break else: use_divnum.add(D[k]) div = D[k] while k % div == 0 and k > 1: k = k // div if pairwise_coprime: print("pairwise coprime") exit() from math import gcd gcd_of_a = A[0] for i in range(N): gcd_of_a = gcd(gcd_of_a, A[i]) if gcd_of_a == 1: print("setwise coprime") else: print("not coprime")
1
4,120,567,251,198
null
85
85
def main(): l = int(input()) print((l / 3) ** 3) if __name__ == "__main__": main()
import math import sys from collections import Counter readline = sys.stdin.readline def main(): l = int(readline().rstrip()) print((l/3)**3) if __name__ == '__main__': main()
1
47,161,377,132,008
null
191
191
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() yn = {False: 'No', True: 'Yes'} YN = {False: 'NO', True: 'YES'} MOD = 10**9+7 inf = float('inf') IINF = 10**10 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 = [0] * N dp[1] = max(a[0], a[1]) c = a[0] for i in range(2, N): if i % 2 == 0: c += a[i] dp[i] = max(dp[i-2] + a[i], dp[i-1]) else: dp[i] = max(dp[i-2] + a[i], c) print(dp[-1]) if __name__ == '__main__': main()
import math n = int(input()) K = int(input()) def calk1(n): if n == 0: return 0 m = int(math.log10(n)) num = m * 9 num += n//(10**m) return num def calk2(n): m = int(math.log10(n)) num = m * (m - 1) // 2 * 9**2 num += (n//(10**m)-1) * m * 9 num += calk1(n - (n//(10**m)*10**m)) return num def calk3(n): m = int(math.log10(n)) num = m * (m - 1) * (m - 2) // 6 * 9**3 num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2) num += calk2(n - (n//(10**m)*10**m)) return num if n < 10 ** (K - 1): print(0) else: if K == 1: print(calk1(n)) elif K == 2: print(calk2(n)) else: print(calk3(n))
0
null
56,596,778,677,536
177
224
n = int(input()) st = list(map(int,input().split())) st.sort(reverse = True) count = 0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if (st[i] != st[j] != st[k]) and (st[i] < st[j] + st[k]): count += 1 print(count)
import math while True: n = int(raw_input()) if n==0: break nums = [int(x) for x in raw_input().split(" ")] average = sum(nums) / float(n) a2 = sum([math.pow(x-average, 2.0) for x in nums]) / n print math.sqrt(a2)
0
null
2,645,215,787,492
91
31
import copy def main(): N = int(input()) A = list(map(int, input().split())) A.sort() A_max = A[N-1] div_count = [0] * (A_max + 1) for a in A: for n in range(a, A_max+1, a): div_count[n] += 1 exists = [False] * (A_max + 1) for a in A: exists[a] = True result = 0 for i, d in enumerate(div_count): if d == 1 and exists[i]: result += 1 print(result) main()
n = int(input()) A = sorted(list(map(int, input().split()))) from collections import Counter c = Counter(A) MAX = 10 ** 6 + 1000 dp = [True] * MAX for k, v in c.items(): if dp[k] == False: continue if v > 1: dp[k] = False for x in range(k + k, MAX, k): dp[x] = False res = 0 for x in range(n): if dp[A[x]]: res += 1 print(res)
1
14,422,096,469,758
null
129
129
x = int(input()) k = 1 while(True): if k * x % 360 == 0: print(k) break else: k += 1
x = int(input()) y = x while y % 360: y += x print(y//x)
1
13,108,060,696,452
null
125
125
N=int(input()) S=input() res=0 R=[] G=[] B=[] r,g,b=0,0,0 for i in range(N): if S[i]=='R': r+=1 elif S[i]=='G': g+=1 else: b+=1 R.append(r) G.append(g) B.append(b) for i in range(N): for j in range(N): if not i<j: continue k=S[2*j-i] if 2*j-i<N else 'A' if set([S[i],S[j]])==set(['R','G']): res+=B[-1]-B[j]-(k=='B') elif set([S[i],S[j]])==set(['B','G']): res+=R[-1]-R[j]-(k=='R') elif set([S[i],S[j]])==set(['R','B']): res+=G[-1]-G[j]-(k=='G') print(res)
k = int(input()) def test_case(k): ans,cnt = 7,1 if k % 2 == 0 or k % 5 == 0: return -1 if k == 1 or k == 7: return 1 while (1): ans = (ans * 10 + 7) % k cnt += 1 if ans == 0: return cnt print(test_case(k))
0
null
21,302,141,506,490
175
97
X=input().split(" ") print(int(X[0])*int(X[1]))
n = int(input()) a = list(map(int, input().split())) lists = [0] * n for i in range(n): lists[a[i] - 1] = i + 1 for i in lists: print(i , end =' ')
0
null
98,040,917,932,288
133
299
n = int(input()) dic = {} for i in range(1,50000): dic[int(i * 1.08)] = i if n in dic: print(dic[n]) else: print(':(')
number_list=[int(i) for i in input().split()] counter=0 for r in range(number_list[0],number_list[1]+1): if number_list[2]%r==0: counter+=1 print(counter)
0
null
63,137,259,907,008
265
44
N = map( int , raw_input().split() ) N.sort() print "%d %d %d" %( N[0] , N[1] , N[2] )
import sys input = sys.stdin.readline from collections import deque def main(): n = int(input().strip()) v = [[] for _ in range(n)] for i in range(n): v[i] = list(map(int, input().strip().split())) l = [-1] * (n+1) q = deque() q.append((1, 0)) while len(q) != 0: id, d = q.popleft() # print("id", id) if l[id] != -1: # print("b") continue l[id] = d # l[id] = min(d, l[id]) # print(id, d) for i in range(v[id-1][1]): q.append((v[id-1][2+i], d+1)) # if id == 8: # print("##", id, v[id-1][2+i]) # print(repr(q)) for i in range(1, n+1): print(i, l[i]) if __name__ == '__main__': main()
0
null
219,115,709,440
40
9
N = int(input()) C_0 = 0 C_1 = 0 C_2 = 0 C_3 = 0 for _ in range(N): S = input() if S == 'AC': C_0 += 1 elif S == 'WA': C_1 += 1 elif S == 'TLE': C_2 += 1 else: C_3 += 1 print('AC x {}'.format(C_0)) print('WA x {}'.format(C_1)) print('TLE x {}'.format(C_2)) print('RE x {}'.format(C_3))
import math a,b,c=map(int,input().split()) s=0.5*a*b*math.sin(math.radians(c)) l=a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(c))) h=b*math.sin(math.radians(c)) print("%.6f %.6f %.6f"%(s,l,h))
0
null
4,416,888,306,628
109
30
#nの約数を列挙する関数 import math def n_div(n): div_list = [] import math for i in range(1, math.ceil(math.sqrt(n))+1): if n % i ==0: div_list.append(i) if i*i ==n: continue div_list.append(n//i) div_list.sort() return div_list n = int(input()) lr = n_div(n) #print(lr) if len(lr) % 2==0: a = len(lr)/2 a = int(a) ans = lr[a]+lr[a-1]-2 else: a = math.floor(len(lr)/2) #print(a) ans = lr[a]*2 -2 print(ans)
import sys sys.setrecursionlimit(10 ** 7) N = int(input()) infants = [] for i, A in enumerate(map(int, input().split(' '))): infants.append((-A, i + 1)) infants.sort() dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)] def search(i, l): # i番目の幼児を見ていて左にl人配置している if i == N: return 0 if dp[i][l] != -1: return dp[i][l] (act_val, pos) = infants[i] act_val = -act_val ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val, search(i + 1, l) + abs(N - i + l - pos) * act_val) dp[i][l] = ans return ans print(search(0, 0))
0
null
97,827,636,974,926
288
171
import sys stdin=sys.stdin ip=lambda: int(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() a,b=lp() print(max(0,a-2*b))
import sys, math from functools import lru_cache from collections import deque sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def main(): S = input() for i in range(1, 6): if S == 'hi'*i: print('Yes') return print('No') if __name__ == '__main__': main()
0
null
109,714,931,211,478
291
199
n,m = map(int,raw_input().split()) a = [[0 for i in range (m)]for j in range(n)] b = [0 for i in range(m)] c = [0 for i in range(n)] for i in range(n): x = map(int,raw_input().split()) for j in range(m): a[i][j] = x[j] for i in range(m): b[i] = int(raw_input()) for i in range(n): for j in range(m): c[i] += a[i][j] * b[j] print c[i]
a,b=map(int,input().split()) c=0 for i in range (0,a+1): for j in range (0,a+1): if (i+j)==a and (i*2 + j *4) == b: c+=1 if c== 0: print('No') else: print('Yes')
0
null
7,474,348,440,336
56
127
N = int(input()) for i in range(N): a, b, c = map(int, input().split()) if(a > c): a, c = c, a if(b > c): b, c = c, b if(c**2 == a**2 + b**2): print("YES") else: print("NO")
from collections import defaultdict n = int(input()) a = [int(i) for i in input().split()] mapping = defaultdict(int) for _a, i in zip(range(2, n + 1), a): mapping[i] += 1 for i in range(1, n + 1): print(mapping[i])
0
null
16,333,097,588,922
4
169
# coding:utf-8 import sys n = input() array = [] for i in range(n): array.append(map(int, raw_input().split())) array.sort() result = [[0 for i in range(4)] for j in range(n)] index = 0 result[index] = array[0][0:4] for i in range(1,n): if result[index][0:3] == array[i][0:3]: result[index][3] += array[i][3] elif result[index][0:3] != array[i][0:3]: index += 1 result[index] = array[i][0:] index = 0 for i in range(4): for j in range(3): for k in range(10): sys.stdout.write(' ') if(i == result[index][0] - 1 and j == result[index][1] - 1 and k == result[index][2] - 1): print result[index][3], if index != len(result) - 1: index += 1 else: print 0, else: print else: if(i != 3): print "####################"
N = int(input()) A = list(map(int,input().split())) mod = 10**9+7 a,s = 0,0 for i in range(N): a += s*A[i] s += A[i] a %= mod print(a)
0
null
2,479,010,786,640
55
83
n, m = [int(x) for x in input().split()] a = [[int(x) for x in input().split()] for y in range(n)] b = [int(input()) for x in range(m)] c = [] for i in range(n): c.append(sum([a[i][x] * b[x] for x in range(m)])) for i in c: print(i)
n, m = map(int, input().split()) a = [] b = [] for i in range(n): ai = list(map(int, input().split())) a.append(ai) for i in range(m): bi = int(input()) b.append(bi) for i in range(n): ci = 0 for j in range(m): ci += a[i][j] * b[j] print(ci)
1
1,177,812,354,048
null
56
56
import sys sys.setrecursionlimit(10**7) def MI(): return map(int,sys.stdin.readline().rstrip().split()) class UnionFind: def __init__(self,n): self.par = [i for i in range(n+1)] # 親のノード番号 self.rank = [0]*(n+1) def find(self,x): # xの根のノード番号 if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self,x,y): # x,yが同じグループか否か return self.find(x) == self.find(y) def unite(self,x,y): # x,yの属するグループの併合 x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: x,y = y,x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x N,M = MI() UF = UnionFind(N) for _ in range(M): a,b = MI() UF.unite(a,b) A = UF.par A = [UF.find(A[i]) for i in range(1,N+1)] print(len(set(A))-1)
li =list(map(int,input().split())) n =li[0] m =li[1] k =li[2] count =0 for i in range(n,m+1): if i%k ==0: count +=1 print(count)
0
null
4,936,559,845,338
70
104
X = int(input()) if X>=30:print("Yes") else:print("No")
a = int(input()) print("Yes") if a >= 30 else print("No")
1
5,755,263,452,888
null
95
95
s = raw_input() s = s.lower().strip() cnt = 0 while True: text = raw_input() if 'END_OF_TEXT' == text.strip(): break text = text.lower() for item in text.split(): if item == s: cnt += 1 print cnt
W = input() count = 0 while True: line = input() if line == 'END_OF_TEXT': break for s in line.lower().split(): if s == W: count += 1 print(count)
1
1,807,917,916,002
null
65
65
n = int(input()) cnt=0 for _ in range(n): a,b=map(int,input().split()) if a==b: cnt+=1 if cnt>=3: break else: cnt=0 if cnt>=3: print("Yes") else: print("No")
n = int(input()) t = 0 for _ in range(n): d1,d2 = map(int, input().split()) if d1 != d2: t = 0 else: t += 1 if t == 3: print("Yes") exit() print("No")
1
2,494,330,202,520
null
72
72
inData = int(input()) seqData = list(range(1,inData+1,1)) outData = [0] * inData for thisData in seqData: if thisData == inData: if thisData%3 == 0 or thisData%10==3: print(" "+str(thisData)) else: for i in range(5): i=i+1 over = 10 ** i tmp = thisData/over if int(tmp % 10) == 3: print(" "+str(thisData)) break else: pass print("") else: if thisData%3 == 0 or thisData%10==3: print(" "+str(thisData), end = "") else: for i in range(5): i=i+1 over = 10 ** i tmp = thisData/over if int(tmp % 10) == 3: print(" "+str(thisData), end = "") break else: pass
t = input() ans = t tem = '' if '?' in t : if len(t) == 1 : ans = 'D' elif len(t) == 2 : if t[0] == '?' and t[1] == '?' : ans = 'PD' elif t[0] == '?' and t[1] == 'D': ans = 'PD' elif t[0] == '?' and t[1] == 'P': ans ='DP' elif t[1] == '?' and t[0] == 'P': ans = 'PD' elif t[1] == '?' and t[0] == 'D': ans = 'DD' else: for i in range(0,len(t)): if i == 0 : if t[i] == '?' and t[i+1] == 'P': ans = 'D' elif t[i] == '?' : ans = 'P' else : ans = t[i] elif i == len(t)-1 : if t[i] == '?' : ans += 'D' else: ans += t[i] else: if t[i] == '?': if ans[i-1] == 'P': ans += 'D' elif t[i+1] == 'D' or t[i+1] == '?': ans += 'P' else: ans += 'D' else: ans += t[i] print(ans)
0
null
9,712,736,318,500
52
140
import collections N=int(input()) s=[str(input()) for i in range(N)] c=collections.Counter(s) maximum =max(c.values()) max_c_list = sorted(key for key,value in c.items() if value == maximum) for s in max_c_list: print(s)
from collections import Counter n = int(input()) s = [input() for _ in range(n)] c = Counter(s) m = c.most_common()[0][1] k = list(c.keys()) v = list(c.values()) l = [] for i in range(len(c)): if v[i] == m: l.append(k[i]) l.sort() print(*l,sep="\n")
1
69,903,020,981,022
null
218
218
text = [] try: while True: text.append(input()) except: for s in [chr(k) for k in range(97,97+26)]: count = 0 for i in text: count += i.lower().count(s) print(s,":",count)
count_al = list(0 for i in range(26)) while True : try : a = str(input()) b = a.lower() for i in range(len(b)) : c = ord(b[i]) if c > 96 and c < 123 : count_al[c - 97] += 1 except EOFError : break for i in range(97, 123) : print(chr(i), ":", count_al[i-97])
1
1,646,897,530,642
null
63
63
from collections import deque n = int(input()) adj = [[]] for i in range(n): adj.append(list(map(int, input().split()))[2:]) ans = [-1]*(n+1) ans[1] = 0 q = deque([1]) visited = [False] * (n+1) visited[1] = True while q: x = q.popleft() for y in adj[x]: if visited[y] == False: q.append(y) ans[y] = ans[x]+1 visited[y] = True for j in range(1, n+1): print(j, ans[j])
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) XY = [list(mapint()) for _ in range(N)] XY.sort(key=lambda x:x[0]+x[1]) ans_1 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1]) XY.sort(key=lambda x:x[0]-x[1]) ans_2 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1]) print(max(ans_1, ans_2))
0
null
1,685,698,074,452
9
80
S = input() Q = int(input()) reverse = 0 left = "" right = "" for _ in range(Q): q = input().split() if q[0]=="1": reverse += 1 left, right = right, left if q[0]=="2" and q[1]=="1": if reverse%2==0: left = q[2]+left else: left = left+q[2] if q[0]=="2" and q[1]=="2": if reverse%2==0: right = right+q[2] else: right = q[2]+right if reverse%2==1: left = left[::-1] right = right[::-1] S = S[::-1] print(left+S+right)
def main(): N = int(input()) ans = 0 for x in range(1, int(N ** 0.5) + 1): # x(1+2+3+...+e) e = N // x ans += x * (e * e + e - x * x) print(ans) if __name__ == '__main__': main()
0
null
34,184,745,866,272
204
118
a, b = map(int,input().split()) if a > b: a, b = b, a print(str(a) * b)
n = int(input()) table = [0] * (n + 1) for i in range(1, n+1): for j in range(i, n+1, i): table[j] += 1 ans = 0 for i in range(n+1): ans += table[i] * i print(ans)
0
null
47,428,625,731,776
232
118
for i in range(9): i=i+1 for j in range(9): j=j+1 print(str(i)+'x'+str(j)+'='+str(i*j))
s = list(input()) c = 0 x = s[::-1] for i in range(len(s)): if s[i] != x[i]: x[i] = s[i] c += 1 s[::-1] = x print(c)
0
null
60,254,732,286,626
1
261
#!/usr/bin/env python3 import math import sys def calculate_area(side_a, side_b, angle_c): return (side_a*side_b*math.sin(math.radians(angle_c))) / 2 def calculate_perimeter(side_a, side_b, angle_c): side_c = math.sqrt(side_a**2 + side_b**2 - 2*side_a*side_b*math.cos(math.radians(angle_c))) return side_a + side_b + side_c def calculate_height_from_side_a(side_a, area): return (area*2)/side_a def main(): nums = [float(num) for num in sys.stdin.readline().split()] area = calculate_area(nums[0], nums[1], nums[2]) perimeter = calculate_perimeter(nums[0], nums[1], nums[2]) height_from_side_a = calculate_height_from_side_a(nums[0], area) print(area) print(perimeter) print(height_from_side_a) if __name__ == '__main__': main()
def main(): s = int(input()) mod = 10**9+7 dp = [0] * (s+1) dp[0] = 1 x = 0 for i in range(1, s+1): if i-3 >= 0: x += dp[i-3] x %= mod dp[i] = x print(dp[s]) if __name__ == "__main__": main()
0
null
1,740,419,546,372
30
79
input() numbers = input().split() numbers.reverse() print(" ".join(numbers))
input() print(*reversed([int(e) for e in input().split()]))
1
976,749,133,500
null
53
53
N = int(input()) A = list(map(int, input().split())) A_MAX = 10 ** 5 idx = [0] * (A_MAX + 1) sum = 0 for i in A: idx[i] += 1 sum += i Q = int(input()) for i in range(Q): B, C = list(map(int, input().split())) sub = C - B num = idx[B] idx[B] = 0 idx[C] += num sum += (sub * num) print(sum)
def resolve(): N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [list(map(int, input().split())) for _ in range(Q)] a = [0] * 100001 for i in A: a[i] += i ans = sum(a) for b, c in BC: if a[b] == 0: print(ans) continue move = a[b] // b a[b] = 0 a[c] += c * move ans += (c - b) * move print(ans) if __name__ == "__main__": resolve()
1
12,201,801,524,230
null
122
122
import sys import math import heapq sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, m=DVSR): return pow(x, m - 2, m) def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def FLIST(n): res = [1] for i in range(1, n+1): res.append(res[i-1]*i%DVSR) return res N=II() AS=LI() SM=sum(AS) B=1 res=0 M = 1 m = 1 for a in AS: B = M-a if B < 0: print(-1) exit(0) res += a res += B SM -= a M = min(B*2, SM) m = B print(res)
N, P = map(int, input().split()) S = input() if P == 2: ans = 0 for i, d in enumerate(map(int, S)): if d % 2 == 0: ans += i+1 print(ans) elif P == 5: ans = 0 for i, d in enumerate(map(int, S)): if d % 5 == 0: ans += i+1 print(ans) else: mods = [0] * P mods[0] = 1 cur_mod = 0 for i, digit in enumerate(map(int, S)): cur_mod += pow(10, N-i-1, P) * digit cur_mod %= P mods[cur_mod] += 1 ans = 0 for count in mods: ans += count * (count - 1) // 2 print(ans)
0
null
38,689,088,452,594
141
205
# -*-coding:utf-8 #import fileinput import math def main(): n = int(input()) for i in range(1, n+1): x = i if (x%3 == 0): print(' %d' % i, end='') else: while(x): if (x%10 == 3): print(' %d' % i, end='') break else: x = int(x/10) print('') if __name__ == '__main__': main()
s=int(input()) A=[0,0,1] for i in range(3,s): A+=[A[i-1]+A[i-3]] print(A[s-1]%(10**9+7))
0
null
2,111,612,288,544
52
79
a,b = map(int, raw_input().split()) print a/b,a%b,"%.5f" % (a/float(b))
line = list(map(int,input().split())) print(line[0]//line[1],line[0]%line[1],'%0.05f'%(1.0*line[0]/line[1]))
1
600,799,723,690
null
45
45
import itertools import math import fractions import functools s, w = map(int, input().split()) if w >= s :print("unsafe") else: print("safe")
def main(): s = input() n = int(input()) for i in range(n): cmds = input().split(' ') if 'reverse' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 s = s[:a]+''.join(reversed(s[a:b]))+s[b:] if 'replace' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 res = cmds[3] s = s[:a]+res+s[b:] if 'print' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 print(s[a:b]) if __name__ == '__main__': main()
0
null
15,528,202,243,598
163
68
N = int(input()) if N == 2: print(1) exit() S = set([N-1]) lst = [N] i = 2 while i*i <= N-1: if (N-1) % i == 0: S.add(i) S.add((N-1)//i) i += 1 i = 2 while i*i < N: if N % i == 0: lst.append(i) lst.append(N//i) i += 1 if i*i == N: lst.append(i) lst.sort() for l in lst: if l in S: continue _N = N while _N % l == 0: _N //= l if _N % l == 1: S.add(l) print(len(S))
a, b = [int(i) for i in input().split(" ")] num1 = a // b num2 = a % b num3 = "{:.8f}".format(a / b) print(num1, num2, num3)
0
null
20,913,313,708,638
183
45
import sys K, X = map(int, sys.stdin.readline().strip().split()) if K * 500 >= X: print('Yes') else: print('No')
def main(): K, X = map(int, input().split()) m = K * 500 if m >= X: print('Yes') else: print('No') main()
1
98,245,374,141,370
null
244
244
A,V = map(int,input().split()) B,W = map(int,input().split()) T = int(input()) if W >= V: print('NO') else: if (V-W)*T >= abs(A-B): print('YES') else: print('NO')
# from collections import defaultdict import math def comb(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(input()) K = int(input()) keta = len(str(N)) dp = [[0]*(keta) for i in range(4)] ans = 0 for k in range(1, 4): for i in range(1, keta): if i<k: continue else: dp[k][i] = comb(i-1, i-k)*(9**k) #print(dp) # dp[k][i]: i桁で、k個の0でない数 ans += sum(dp[K]) # (N の桁)-1 までの累積和 count = 0 for j in range(keta): t = int(str(N)[j]) if j==0: count+=1 ans += sum(dp[K-count])*(t-1) if count == K: # K==1 ans+=t break continue elif j==keta-1: if t!=0: count+=1 if count==K: ans+=t break if t !=0: count+=1 if count==K: ans+=sum(dp[K-count+1][:keta-j]) #0のとき ans+=t break ans += sum(dp[K-count][:keta-j])*(t-1) #0より大きいとき ans += sum(dp[K-count+1][:keta-j]) #0のとき print(ans)
0
null
45,685,301,827,750
131
224
def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) ans=0 N,D=MI() D2=D*D for i in range(N): x,y=MI() if x*x+y*y<=D2: ans+=1 print(ans)
n = int(input()) a = list(map(int,input().split())) b = a[0] x = 0 for i in range(1,n): if a[i] > b: b = a[i] else: x += b-a[i] print(x)
0
null
5,292,102,019,618
96
88
N=input() total=0 for i in N: total += int(i) print('Yes' if total % 9 == 0 else 'No')
N=list(map(int,input().split())) temp = sum(N) if temp%9 == 0:print("Yes") else:print("No")
1
4,438,311,745,000
null
87
87
import math a,b,x = map(int,input().split()) if x <= b*a*a*1/2: dum = 2*x/(a*b) ans = 90-(math.degrees(math.atan(dum/b))) else: x -= b*a*a*1/2 dum = b-(x*2/(a*a)) ans = math.degrees(math.atan(dum / a)) print(ans)
import math a, b, x = map(int,input().split()) v = a*a*b if x > v/2: y = 2*(b-(x/(a*a))) naname = math.sqrt((y*y) + (a*a)) cosine = a/naname print(math.degrees(math.acos(cosine))) elif x < v/2: y = 2*x/(b*a) naname = math.sqrt((y*y)+(b*b)) cosine = b / naname print(90-math.degrees(math.acos(cosine))) else: naname = math.sqrt((a*a)+(b*b)) cosine = a/naname print(math.degrees(math.acos(cosine)))
1
163,521,268,387,740
null
289
289
N = int(input()) l = [1] * N i = 0 d = {1:0,2:0,3:0} for s in input(): n = 1 if s == "G": n = 2 elif s == "B": n = 3 l[i] = n d[n] += 1 i += 1 cnt = d[1] * d[2] * d[3] for j in range(1,(N - 1) // 2 + 1): for k in range(N - (2 * j)): if l[k] * l[k+j] * l[k+j+j] == 6: cnt -= 1 print(cnt)
N = int(input()) S = input() r = S.count('R') g = S.count('G') b = S.count('B') ans = r*g*b for i in range(N): for d in range(N): j = i+d k = i+2*d if k > N-1: break if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: ans -= 1 print(ans)
1
36,304,124,993,578
null
175
175
while True: inputs = input().split(' ') a = int(inputs[0]) op = inputs[1] b = int(inputs[2]) if op == "?": break elif op == "+": # (和) print(a + b) elif op == "-": # (差) print(a - b) elif op == "*": #(積) print(a * b) else: # "/"(商) print(a // b)
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N, P = map(int, readline().split()) S = [int(i) for i in readline().strip()[::-1]] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S): if s % P == 0: ans += N - i print(ans) exit() a = {} a[0] = 1 t = 0 x = 1 for s in S: t += s * x t %= P if t in a: a[t] += 1 else: a[t] = 1 x *= 10 x %= P ans = 0 for v in a.values(): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
0
null
29,556,805,353,504
47
205
s = input() s = s[::-1] n = len(s) m = [0] * 2019 m[0] = 1 a = 0 d = 1 for i in range(n): a = (a + int(s[i]) * d) % 2019 d = (d * 10) % 2019 m[a] += 1 print(sum([int(x * (x - 1) / 2) for x in m if x > 1]))
from sys import stdin, stdout s = input() n = len(s) if len(s) <= 3: print(0) exit() suffix_rems = [-1]*n suffix_rems[-1] = int(s[-1]) suffix_rems[-2] = int(s[-2:]) suffix_rems[-3] = int(s[-3:]) rems_d = dict() rems_d[0] = 1 rems_d[int(s[-1])] = 1 rems_d[int(s[-2:])] = 1 rems_d[int(s[-3:])] = 1 special_keys = set() for i in range(n-3)[::-1]: rem = (pow(10, n-i-1, 2019) * int(s[i]) + suffix_rems[i + 1])%2019 if rem in rems_d: rems_d[rem] += 1 special_keys.add(rem) else: rems_d[rem] = 1 suffix_rems[i] = rem ans = 0 for key in special_keys: t = rems_d[key] ans += (t*(t-1))//2 print(ans)
1
30,696,489,000,742
null
166
166
class stack(): def __init__(self): self.S = [] def push(self, x): self.S.append(x) def pop(self): return self.S.pop() def isEmpty(self): if len(self.S) == 0: return True else: return False areas = input() S1 = stack() S2 = stack() for i, info in enumerate(areas): if info == '/': if S1.isEmpty(): continue left = S1.pop() menseki = i - left while True: if S2.isEmpty(): S2.push([menseki, left]) break if S2.S[-1][1] < left: S2.push([menseki, left]) break menseki += S2.pop()[0] elif info == '\\': S1.push(i) ans = [m[0] for m in S2.S] print(sum(ans)) if len(ans) == 0: print(len(ans)) else: print(len(ans), ' '.join(list(map(str, ans))))
S = input() l1 = [] l2 = [] total_area = 0 for i, j in enumerate(S): if j == '\\': l1.append(i) elif j == '/' and l1: i_p = l1.pop() v = i -i_p total_area += v while l2 and l2[-1][0] > i_p: v += l2.pop()[1] l2.append([i_p, v]) ans = [str(len(l2))] + [str(k[1]) for k in l2] print(total_area) print(' '.join(ans))
1
57,546,804,016
null
21
21
def pascal(xdata): for x in xrange(3): for y in xrange(3): for z in xrange(3): if xdata[x]**2 + xdata[y]**2 == xdata[z]**2: return True return False N = input() data = [map(int, raw_input().split()) for x in range(N)] for x in data: if pascal(x): print "YES" else: print "NO"
count = int(input()) for i in range(count): a = map(int,raw_input().split()) a.sort() if a[0]**2+a[1]**2 == a[2]**2: print "YES" else: print "NO"
1
344,834,402
null
4
4
def main(): n = int(input()) a_list = list(map(int, input().split())) a_set = set(a_list) if len(a_set) == n: print("YES") else: print("NO") if __name__ == "__main__": main()
n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n-1): if a[i]==a[i+1]: print("NO") exit() print("YES")
1
74,062,164,623,562
null
222
222
n=int(input()) a=list(map(int,input().split())) b=[] for i in range(n): tmp=[i+1,a[i]] b.append(tmp) b=sorted(b,key=lambda x:x[1]) ans=[] for j in b: ans.append(j[0]) print(*ans)
N=int(input()) A=list(map(int,input().split())) for i in range(N): A[i] = [i+1, A[i]] A.sort(key=lambda x:x[1]) ans=[] for i in range(N): ans.append(A[i][0]) ans = map(str, ans) print(' '.join(ans))
1
180,433,764,513,600
null
299
299
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] n = int(input()) p = list(map(int, input().split())) ans = 1 minVal = p[0] for i in range(1, n): if minVal > p[i]: ans += 1 minVal = p[i] print(ans)
N = int(input()) P = list(map(int, input().split())) dp = [0] * N dp[0] = P[0] for i in range(1, N): dp[i] = min(dp[i - 1], P[i]) res = 0 for i in range(N): if dp[i] >= P[i]: res += 1 print(res)
1
85,394,155,177,512
null
233
233
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() wins = {"p":"s", "r":"p", "s":"r"} points = {"p":S, "r":P, "s":R} hands = [] ans = 0 for i in range(N): if i - K < 0: hands.append(wins[T[i]]) ans += points[T[i]] else: if hands[i-K] == wins[T[i]]: #あいこにするしか無い時 hands.append("-") else: #勝てる時 hands.append(wins[T[i]]) ans += points[T[i]] print(ans)
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B x = int(input()) y = list(map(int,input().split())) z = 0 for i in range(x): minj = i for j in range(i,x): if y[j] < y[minj]: minj = j if not i == minj: y[i], y[minj] = y[minj], y[i] z += 1 print(" ".join(list(map(str,y)))) print(z)
0
null
53,477,092,167,040
251
15
N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() divided_T = [[] for _ in range(K)] for i in range(N): divided_T[i%K].append(T[i]) ans = 0 for target in divided_T: dp = [[0]*3 for _ in range(len(target))] dp[0][0] = R if target[0] == 's' else 0 dp[0][1] = P if target[0] == 'r' else 0 dp[0][2] = S if target[0] == 'p' else 0 for i in range(1,len(target)): dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + (R if target[i] == 's' else 0) dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + (P if target[i] == 'r' else 0) dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + (S if target[i] == 'p' else 0) ans += max(dp[-1]) print(ans)
N=int(input()) print(sum([((N-1)//1)//i for i in range(1, N)]))
0
null
54,640,078,827,972
251
73
import sys from collections import deque def main(): N, p, q, *AB = map(int, sys.stdin.buffer.read().split()) p -= 1 q -= 1 G = [[] for _ in range(N)] for a, b in zip(*[iter(AB)] * 2): G[a - 1].append(b - 1) G[b - 1].append(a - 1) if len(G[p]) == 1 and G[p][0] == q: print(0) return dist1 = [-1] * N dist1[p] = 0 queue = deque([p]) while queue: v = queue.popleft() for nv in G[v]: if dist1[nv] == -1: dist1[nv] = dist1[v] + 1 queue.append(nv) dist2 = [-1] * N dist2[q] = 0 queue = deque([q]) while queue: v = queue.popleft() for nv in G[v]: if dist2[nv] == -1: dist2[nv] = dist2[v] + 1 queue.append(nv) max_d = 0 for d1, d2 in zip(dist1, dist2): if d1 < d2 and max_d < d2: max_d = d2 print(max_d - 1) return if __name__ == '__main__': main()
#a(n) = 2^ceiling(log_2(n+1))-1 import math print(2**(math.ceil(math.log2(int(input())+1)))-1)
0
null
98,444,642,248,270
259
228
n, x, m = map(int, input().split()) mn = min(n, m) S = set() A = [] sum_9 = 0 # sum of pre + cycle for _ in range(mn): if x in S: break S.add(x) A.append(x) sum_9 += x x = x*x % m if len(A) >= mn: print(sum_9) exit() pre_len = A.index(x) cyc_len = len(A) - pre_len nxt_len = (n - pre_len) % cyc_len cyc_num = (n - pre_len) // cyc_len pre = sum(A[:pre_len]) cyc = sum_9 - pre nxt = sum(A[pre_len: pre_len + nxt_len]) print(pre + cyc * cyc_num + nxt)
K=int(input()) S=input() if len(S)<=K: print(S) else: for i in range(K): print(S[i],end="") print("...")
0
null
11,306,696,749,898
75
143
while 1: x, y = map(int, raw_input().split()) if x == y == 0: break else: if x < y: print "%d %d" % (x, y) else: print "%d %d" % (y, x)
# coding: utf-8 x,y=map(int,input().split()) while not(x==0 and y==0): if x>y: x,y=y,x print(str(x)+" "+str(y)) x,y=map(int,input().split())
1
532,340,937,920
null
43
43
N = int(input()) S = input() ans = 0 pre = '' for i in range(N): if pre != S[i:i+1]: ans += 1 pre = S[i:i+1] print(ans)
def remove_slimes(ls): l = [ls[0]] for i in range(1, len(ls)): if ls[i-1] != ls[i]: l.append(ls[i]) return len(l) n = int(input()) s = input() cnt = 1 if len(s) != 1: cnt = remove_slimes(list(s)) print(cnt)
1
169,776,692,396,996
null
293
293
D = int(input()) c = list(map(int, input().split())) last = [0] * 26 S = [] for d in range(1, D+1): sd = list(map(int, input().split())) S += [sd] score = 0 for d in range(1, D+1): td = int(input()) - 1 cumsump = 0 for i in range(26): if td != i: tmp = -c[i] * (d - last[i]) cumsump += tmp last[td] = d score += S[d-1][td]+cumsump print(score)
D = int(input()) C = list(map(int, input().split())) s = list() for i in range(D): s1 = list(map(int, input().split())) s.append(s1) t = list() for i in range(D): N = int(input()) t.append(N-1) done = [0] * 26 ans = 0 for d in range(1, D+1): td = t[d-1] done[td] = d ans += s[d-1][td] for i in range(26): ans -= C[i]*(d-done[i]) print(ans)
1
10,022,446,467,350
null
114
114
#!/usr/bin/env python3 import sys from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10) def main(): mod = 1000000007 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79e+308 # inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) a, b, c = mi() if c - (a + b) <= 0: print('No') else: print('Yes') if 4 * a * b < (c - (a + b)) ** 2 else print('No') if __name__ == "__main__": main()
# coding: utf-8 n = int(input()) A = list(map(int, input().split())) print(" ".join(map(str,A))) for i in range(1,n): v = A[i] j = i -1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(" ".join(map(str,A)))
0
null
25,914,021,564,940
197
10
n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() price = 0 for i in range(k) : price += l[i] print(price)
A, B, C = map(int, input().split()) K = int(input()) num = 0 while B <= A: B *= 2 num += 1 while C <= B: C *= 2 num += 1 if num > K: print("No") else: print("Yes")
0
null
9,342,200,039,688
120
101
# ALDS1_11_C.py import queue def printNode(): for i, node in enumerate(glaph): print(i, node) N = int(input()) glaph = [[] for i in range(N+1)] for i in range(1, N+1): glaph[i] = list(map(int, input().split()))[2:] # printNode() step = [-1]*(N+1) step[1] = 0 q = queue.Queue() q.put(1) while not q.empty(): now = q.get() next_node = glaph[now] # print("now is ", now, ", next is", next_node) for i in next_node: if step[i] != -1: continue q.put(i) step[i] = step[now] + 1 for i, v in enumerate(step): if i != 0: print(i, v)
n=int(input()) ne=[[] for _ in range(n+1)] for _ in range(n): u,k,*v=map(int,input().split()) ne[u]=v dis=[-1]*(n+1) dis[1]=0 q=[1] while q: p=q.pop(0) for e in ne[p]: if dis[e]==-1: dis[e]=dis[p]+1 q.append(e) for i in range(1,n+1): print(i,dis[i])
1
4,280,525,850
null
9
9
N = int(input()) Alist = list(map(int,input().split())) Aplu = [] Amin = dict() for i in range(N): A = Alist[i] Aplu.append(A+(i+1)) if (i+1)-A not in Amin: Amin[(i+1)-A] = 1 else: Amin[(i+1)-A] += 1 Answer = 0 for k in Aplu: if k in Amin: Answer += Amin[k] print(Answer)
n = int(input()) a = list(map(int,input().split())) import collections p = [] q = [] d = collections.defaultdict(int) e = collections.defaultdict(int) for i in range(n): p.append(a[i]+i+1) for i in range(n): q.append(-a[i]+i+1) ans = 0 for i in range(n): d[p[i]] += 1 e[q[i]] += 1 for i in d.keys(): ans += d[i]*e[i] print(ans)
1
26,093,652,471,536
null
157
157
D = int(input()) # with open("sample1.in") as f: last = [0 for i in range(26)] s = [[0 for j in range(26)] for i in range(D)] c = list(map(int, input().split(" "))) result = [] total = 0 # opened = [] #開催したやつを保存 for i in range(D): a = list(map(int, input().split(" "))) for j, k in enumerate(a): #print(i, j, k) s[i][j] = int(k) # スコア計算 score_max = 0 score_index = 0 for j in range(26): if j == 0: score_max = s[i][j] # - (i - last[j]) * c[j] for k in range(26): if j != k: score_max -= (i + 1 - last[k]) * c[k] score_index = 0 else: score = s[i][j] for k in range(26): if j != k: score -= (i + 1 - last[k]) * c[k] if score_max < score: score_max = score score_index = j #print(i, j, score) result.append(score_index) #print(score_index, score) last[score_index] = i + 1 total += score # print(a.index(max(a))) # print(total) for i in range(D): # print(s.index(max(s[i]))) print(result[i]+1)
n,m = map(int, raw_input().split()) A = [] B = [] for i in range(n): A.append(map(int, raw_input().split())) for i in range(m): B.append(input()) for i in range(n): answer = 0 for j in range(m): answer += A[i][j] * B[j] print answer
0
null
5,468,885,991,180
113
56
x=input() x=x*x*x print(x)
x = int(raw_input()) print (x**3)
1
270,967,810,080
null
35
35
N,K =map(int,input().split()) count=0 while 1: if N//(K**count)==0: break count +=1 print(count)
def resolve(): N = int(input()) S = input() cnt = 0 for i in range(len(S)-2): if S[i:i+3] == "ABC": cnt += 1 print(cnt) if '__main__' == __name__: resolve()
0
null
81,704,805,147,040
212
245
H,W,k = map(int, input().split()) # アイテムが何処に何個あるか fs = [[0]*(W+1) for i in range(H+1)] for i in range(k): h, w, v = map(int, input().split()) h -= 1 w -= 1 fs[h][w] = v mvs = [(0,1),(1,0)] dp = [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)] # dp[n][i][j] n個取ったときの、i,jにおけるアイテム価値の最大値 from collections import deque q = deque([]) q.append((0,0)) dp[0][0][0] = 0 dp[1][0][0] = fs[0][0] for h in range(H): for w in range(W): dp[0][h][w+1] = max(dp[0][h][w+1], dp[0][h][w]) dp[1][h][w+1] = max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1]) dp[2][h][w+1] = max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1]) dp[3][h][w+1] = max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1]) for w in range(W): mx = 0 for i in range(4): # print("fe",i,h,w,"dp",dp[i][h][w]) mx = max(mx,dp[i][h][w]) dp[0][h+1][w] = mx dp[1][h+1][w] = mx + fs[h+1][w] H -= 1 W -= 1 ans0 = dp[0][H][W] ans1 = dp[1][H][W] ans2 = dp[2][H][W] ans3 = dp[3][H][W] # print(fs) # for i in range(3): # d = dp[i] # for r in d: # print(*r) # print("----------") print(max(ans1,ans2,ans3))
# -*- coding: utf-8 -*- n, m= [int(i) for i in input().split()] for i in range(0,m): if n-2*i-1>n/2 or n%2==1: print(i+1,n-i) else: print(i+1,n-i-1)
0
null
17,128,002,642,580
94
162
N = int(input()) s = 0 for i in range(1,N+1): if i%2 != 0: s += 1 print(s/N)
#QQ for i in range(1,10): for n in range(1, 10): print("%dx%d=%d" % (i, n, i * n))
0
null
88,364,920,276,992
297
1
from collections import deque def round_robin_scheduling(n, q, A): sum = 0 while A: head = A.popleft() if head[1] <= q: sum += head[1] print(head[0], sum) else: sum += q head[1] -= q A.append(head) if __name__ == '__main__': n, q = map(int, input().split()) A = deque() for i in range(n): name, time = input().split() A.append([name, int(time)]) round_robin_scheduling(n, q, A)
def do_round_robin(process, tq): from collections import deque q = deque() elapsed_time = 0 # ??????????????????????§?????????????????????? finished_process = [] # ????????????????????????????????????????????¨??????????????????????????§????????? # ?????\????????????????????????????????? for process_name, remaining_time in process: q.append([process_name, int(remaining_time)]) while True: try: process_name, remaining_time = q.pop() except IndexError: # ??????????????£???????????????????????????????????£??? break else: elapsed_time += min(remaining_time, tq) remaining_time -= tq if remaining_time > 0: q.appendleft([process_name, remaining_time]) else: finished_process.append((process_name, elapsed_time)) return finished_process if __name__ == '__main__': # ??????????????\??? # ????????????????????????????????????????????????????°??????????????????????????????¨ data = [int(x) for x in input().split(' ')] num_of_process = data[0] time_quantum = data[1] process = [] for i in range(num_of_process): process.insert(0, [x for x in input().split(' ')]) # ?????? results = do_round_robin(process, time_quantum) # ??????????????? for i in results: print('{0} {1}'.format(i[0], i[1]))
1
41,813,651,558
null
19
19
n = int(input()) ans = 0 d = 10 if n%2==1: print(0) import sys sys.exit() while True: ans += n//d d *= 5 if d>n: break print(ans)
import numpy as np N, X, Y = [int(_) for _ in input().split()] X -= 1 Y -= 1 cnt = np.zeros(N, dtype=int) for i in range(0, (X + Y) // 2): #t-i<=abs(i-X)+1+Y-t #2*t<=abs(i-X)+1+Y+i #t<= tmax = 0 - - (abs(i-X)+1+Y+i)//2 #tmin=abs(i-X)+1 tmin = abs(i - X) + 1 tmax = 0 - -(abs(i - X) + 1 + Y + i) // 2 cnt[1:tmax - i] += 1 cnt[tmin:tmin + Y - tmax + 1] += 1 cnt[tmin + 1:tmin + N - Y] += 1 for i in range((X + Y) // 2, N): cnt[1:N - i] += 1 print(*cnt[1:], sep='\n')
0
null
80,355,769,851,708
258
187
import bisect n = int(input()) l_li = list(map(int,input().split())) l_li.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect.bisect_left(l_li,l_li[i]+l_li[j]) num = ind-1 - j ans += num 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(100000) 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 def f(n): r = 2 ret = 1 for i in range(n, n-r, -1): ret *= i for i in range(1, r+1): ret //= i return ret * 2 + n class Bisect: def __init__(self, func): self.__func = func def bisect_left(self, x, lo, hi): while lo < hi: mid = (lo+hi)//2 if self.__func(mid) < x: lo = mid+1 else: hi = mid return lo def bisect_right(self, x, lo, hi): while lo < hi: mid = (lo+hi)//2 if x < self.__func(mid): hi = mid else: lo = mid+1 return lo @mt def slv(N, M, A): A.sort(reverse=True) print(A) b = Bisect(f) i = b.bisect_left(M, 1, N) if f(i) != M: i -= 1 l = f(i) ans = 0 for j in range(i): ans += A[j] * 2 ans += A[j] * (i-1) rem = M - l print(i, l, rem) j = 0 while rem != 0: ans += A[j] + A[i] rem -= 1 if rem == 0: break ans += A[j] + A[i] rem -= 1 if rem == 0: break j += 1 return ans import numpy as np @mt def slv2(N, M, A): C = Counter(A) L = 1 << (max(A).bit_length() + 1) B = [C[i] for i in range(L)] D = np.fft.rfft(B) D *= D E = list(map(int, np.round(np.fft.irfft(D)))) ans = 0 c = 0 i = L - 1 while c != M: n = E[i] if c + n > M: n = M-c c += n ans += i * n i -= 1 return ans def main(): N, M = read_int_n() A = read_int_n() print(slv2(N, M,A)) # N = 10**5 # M = random.randint(1, N**2) # A = [random.randint(1, 10**5) for _ in range(N)] # print(slv(N, M, A)) if __name__ == '__main__': main()
0
null
139,440,556,556,148
294
252
n = input() print("No" if n.count("A") == 3 or n.count("B") == 3 else "Yes")
# region header import sys import math from bisect import bisect_left, bisect_right, insort_left, insort_right from collections import defaultdict, deque, Counter from copy import deepcopy from fractions import gcd from functools import lru_cache, reduce from heapq import heappop, heappush from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement from math import ceil, floor, factorial, log, sqrt, sin, cos from operator import itemgetter from string import ascii_lowercase, ascii_uppercase, digits sys.setrecursionlimit(10**6) INF = float('inf') MOD = 10 ** 9 + 7 def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rf(): return float(rs()) def rs_(): return [_ for _ in rs().split()] def ri_(): return [int(_) for _ in rs().split()] def rf_(): return [float(_) for _ in rs().split()] def divisors(n, sortedresult=True): div = [] for i in range(1, int(n**0.5)+1): if n % i == 0: div.append(i) if i != n // i: div.append(n//i) if sortedresult: div.sort() return div # endregion S = list(rs()) ans = 0 tmp = 0 cnt = 0 f = 1 for i in range(len(S)): if S[i] == '<': if f: cnt += 1 else: ans += cnt * (cnt - 1) // 2 ans += max(tmp, cnt) cnt = 1 f = 1 else: if f: ans += cnt * (cnt - 1) // 2 tmp = cnt cnt = 1 f = 0 else: cnt += 1 ans += cnt * (cnt - 1) // 2 if f: ans += cnt else: ans += max(tmp, cnt) print(ans)
0
null
105,800,183,826,338
201
285
a, b = map(int, input().split()) alpha = str(b) beta = str(a) if a >= b: for k in range(a - 1): alpha = alpha + str(b) print(int(alpha)) else: for k in range(b - 1): beta = beta + str(a) print(beta)
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): _a, _b = input().split() a = _a * int(_b) b = _b * int(_a) print(a if a < b else b) main()
1
84,772,513,035,992
null
232
232
list=list() for i in range(10): t=input() list.append(int(t)) list.sort(reverse=True) for i in range(3): print(list[i])
list = [] for i in range(0, 10): t = int(raw_input()) list.append(t) list.sort(reverse=True) for i in range(0, 3): print list[i]
1
25,907,010
null
2
2
n1 = int(input()) r1 = n1 * n1 print(r1)
n, m= map(int, input().split()) ans = [10] * (n + 1) #s-digit: ans = [dummy, 1st-d, 2nd-d, ...] for i in range(m): s, c = map(int, input().split()) if ans[s] == 10 and not (n!=1 and s==1 and c==0): ans[s] = c elif ans[s] == c: pass elif ans[s] != c or (n!=1 and s==1 and c==0): print(-1) exit() for i in range(1, n+1): if ans[i] == 10: ans[i] = 0 if i == 1 and n != 1: ans[i] += 1 print(''.join([str(x) for x in ans[1:]]))
0
null
102,883,482,974,140
278
208
from collections import defaultdict from operator import mul from functools import reduce def main(): n = int(input()) p = [1] * (n + 1) for i in range(2, n + 1): if p[i] != 1: continue for j in range(i, n + 1, i): if p[j] == 1: p[j] = i ans = 1 for i in range(2, n): m = i k = defaultdict(int) while m > p[m]: k[p[m]] += 1 m //= p[m] k[m] += 1 ans += reduce(mul, [e + 1 for e in k.values()]) print(ans) if __name__ == '__main__': main()
N =int(input()) c = 0 for i in range(N): c += (N-1)//(i+1) print(c)
1
2,583,695,214,958
null
73
73
n, k = map(int, input().split()) a = list(map(int, input().split())) def is_ok(l): cnt = 0 for L in a: cnt += L // l - 1 if L % l != 0: cnt += 1 return cnt <= k def meguru_bisect(ng, ok): while abs(ok - ng) > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(meguru_bisect(0, max(a)))
n, k = map(int, input().split()) a = list(map(int, input().split())) # binary search left = 1 right = 10 ** 9 while left < right: center = (left + right) // 2 total = 0 for i in a: if i % center == 0: i -= 1 total += i//center if total > k: left = center + 1 else: right = center print(left)
1
6,506,080,157,148
null
99
99
Dict = set() n = int(input()) for i in range(n): C = input().split() if C[0] =="insert": Dict.add(C[1]) else: if C[1] in Dict: print("yes") else: print("no")
n = input() dic = set([]) for i in xrange(n): order = raw_input().split() if order[0][0] == 'i': dic.add(order[1]) else: print "yes" if order[1] in dic else "no"
1
78,277,047,798
null
23
23
N, M = map(int,input().split()) ans = "Yes" if N == M else "No" print(ans)
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n, m = list(map(int, readline().split())) print("Yes" if n == m else "No") if __name__ == '__main__': solve()
1
83,203,791,293,700
null
231
231
import math def get_int_list(): return list(map(int, input().split())) n, x, t = get_int_list() ans = math.ceil(n / x) * t print(ans)
n, x, t = map(int, input().split()) if n % x == 0: res = int((n / x) * t) else: res = int(((n // x) + 1) * t) print(res)
1
4,253,322,318,540
null
86
86
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) h, w = map(int, input().split()) if h == 1 or w == 1: print(1) sys.exit(0) # a/bの切り上げ: (a + b - 1)//b print(((h * w) + 2 - 1) // 2)
N,K=list(map(int,input().split())) l=[0]*(K+1) ans=0 mod=10**9+7 for x in range(K,0,-1): l[x]=pow((K//x),N,mod) for y in range(2*x,K+1,x): l[x]-=l[y] l[x]=pow(l[x],1,mod) ans+=l[x]*x ans=pow(ans,1,mod) print(ans)
0
null
43,646,599,872,290
196
176
import math N = int(input()) ans = 0 if N == 0 or N % 2 == 1: ans = 0 else: # means N >= 2 and even digN = round( math.log(N , 5) ) i = 1 while i <= digN: ans += ( N //( 5 ** i * 2 ) ) i += 1 print(ans)
N = int(input()) def solve_function(N): if N % 2 == 1: return 0 it_can_be_divisible = 10 ans = 0 while True: if it_can_be_divisible > N: break ans += N//it_can_be_divisible it_can_be_divisible *= 5 return ans if solve_function(N): print(solve_function(N)) else: print(0)
1
115,921,635,415,200
null
258
258
n,m,l=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] b=[list(map(int,input().split())) for i in range(m)] ans=[[0]* l for i in range(n)] for i in range(n): for j in range(l): for k in range(m): ans[i][j]+=b[k][j]*a[i][k] print(*ans[i])
n,m,l=map(int,input().split()) a=[list(map(int,input().split(" "))) for i in range(n)] b=[list(map(int,input().split(" "))) for i in range(m)] c=[[0]*l for i in range(n)] for i in range(n): for j in range(l): for k in range(m): c[i][j]=c[i][j]+a[i][k]*b[k][j] for d in range(n): print(c[d][0],end="") for e in range(1,l): print(" %d"%c[d][e],end="") print()
1
1,412,134,201,610
null
60
60
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools as fts import itertools as its import math import sys INF = float('inf') def solve(S: str, T: str): return len(T) - max(sum(s == t for s, t in zip(S[i:], T)) for i in range(len(S) - len(T) + 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() S = next(tokens) # type: str T = next(tokens) # type: str print(f'{solve(S, T)}') if __name__ == '__main__': main()
# coding: utf-8 import math import numpy as np #N = int(input()) #A = list(map(int,input().split())) x = int(input()) #x, y = map(int,input().split()) for i in range(1,10**5): if (i*x)%360==0: print(i) break
0
null
8,497,694,714,432
82
125
# C gacha N = int(input()) goods = set() cnt = 0 for i in range(N): S = input() if S not in goods: goods.add(S) cnt += 1 print(cnt)
n = int(input()) a = set([input() for i in range(n)]) print(len(a))
1
30,156,753,047,580
null
165
165
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] MOD = 2019 # INF = int(1e15) def solve(): S = Scanner.string() S = S[::-1] cnt = [0 for _ in range(MOD)] tmp = 0 ans = 0 x = 1 for s in S: cnt[tmp] += 1 tmp += int(s) * x tmp %= MOD x *= 10 x %= MOD ans += cnt[tmp] print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
n = int(input()) s,t = input().split() ans = [] for i in range(n): ans.append(s[i]) ans.append(t[i]) print("".join(ans))
0
null
71,257,659,820,098
166
255
x, y = map(int,input().split()) money = 0 def yy(money): if y == 1: money += 300000 elif y ==2: money += 200000 elif y==3: money += 100000 else: money +=0 print(money) if x==1 and y==1: print(300000*2+400000) else: if x == 1: money += 300000 yy(money) elif x ==2: money += 200000 yy(money) elif x ==3: money += 100000 yy(money) else: money +=0 yy(money)
n = input() a = list(map(int, input().split())) b = sum(a) sum = 0 for i in range(len(a)): b -= a[i] sum += a[i]*b print(sum%(10**9+7))
0
null
72,415,059,125,372
275
83
# 2020-05-22 def main(): n, m, k = [int(x) for x in input().split()] friends = [set() for _ in range(n)] blocks = [set() for _ in range(n)] for _ in range(m): a, b = [int(x) - 1 for x in input().split()] friends[a].add(b) friends[b].add(a) for _ in range(k): a, b = [int(x) - 1 for x in input().split()] blocks[a].add(b) blocks[b].add(a) networks = {} # The dict of networks as sets. Keys are leaders. net_leaders = [-1] * n # The leaders of the networks that the ones joined. visited = [False] * n for person in range(n): if visited[person]: continue network = set() stack = [person] while stack: new = stack.pop() visited[new] = True net_leaders[new] = person network.add(new) for adj in friends[new]: if visited[adj]: continue stack.append(adj) networks[person] = network answers = [] for person in range(n): net = networks[net_leaders[person]] ans = len(net) - len(friends[person]) - 1 for block in blocks[person]: if block in net: ans -= 1 answers.append(ans) print(*answers) return if __name__ == '__main__': main()
n = int(input()) ans = 0 for i in range(1,n): ans += n//i if n%i == 0: ans -= 1 print(ans)
0
null
32,100,907,569,780
209
73
def getList(): return list(map(int, input().split())) a, b = getList() if a > 9 or b > 9: print(-1) else: print(a*b)
from collections import Counter S=input() K=int(input()) S_double = S*2 n = 0 if len(set(list(S)))==1: print(len(S)*K//2) exit() while n< len(S_double)-1: if S_double[n] ==S_double[n+1]: S_double = S_double[:n+1]+' '+S_double[n+2:] n += 1 ans = Counter(S_double[:len(S)])[' '] + Counter(S_double[len(S):])[' ']*(K-1) print(ans)
0
null
166,828,961,697,244
286
296
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n = ni() s = input() def wid(w): return ord(w)-ord("A") def ws(wid): return chr(wid+ord("A")) ans = "" for i in range(len(s)): id = (wid(s[i])+n)%26 ans+=ws(id) print(ans)
N = int(input()) S = input() print(''.join([chr((ord(s) - ord('A') + N) % 26 + ord('A')) for s in S]))
1
134,247,885,734,062
null
271
271