File tree 6 files changed +98
-0
lines changed
6 files changed +98
-0
lines changed Original file line number Diff line number Diff line change
1
+ a , b = map (int , input ().split ())
2
+
3
+ for i in range (- 100 , 101 ):
4
+ for j in range (- 100 , 101 ):
5
+ if i + j == a and i - j == b :
6
+ print (i , j )
7
+ exit ()
Original file line number Diff line number Diff line change
1
+ #AC with PyPy3
2
+ from collections import Counter
3
+ n , s = input ().split ()
4
+ n = int (n )
5
+
6
+ count_org = Counter (s )
7
+ count = 0
8
+
9
+ for i in range (1 , n + 1 )[::- 1 ]:
10
+ count_t = count_org .copy ()
11
+ for j in range (i ):
12
+
13
+ if count_t ['A' ] == count_t ['T' ] and count_t ['C' ] == count_t ['G' ]:
14
+ count += 1
15
+
16
+ count_t [s [j ]] -= 1
17
+ count_org [s [i - 1 ]] -= 1
18
+
19
+ print (count )
Original file line number Diff line number Diff line change
1
+ from itertools import combinations
2
+
3
+ abcd = list (map (int , input ().split ()))
4
+ total = sum (abcd )
5
+
6
+ for i in range (1 , 5 ):
7
+ comb = list (combinations (abcd , i ))
8
+
9
+ for j in comb :
10
+ choose = sum ([j for j in list (j )])
11
+
12
+ if choose == total - choose :
13
+ print ('Yes' )
14
+ exit ()
15
+
16
+ print ('No' )
17
+
Original file line number Diff line number Diff line change
1
+ from functools import reduce
2
+ import math
3
+
4
+ def my_gcd (numbers ):
5
+ return reduce (math .gcd , numbers )
6
+
7
+ n = int (input ())
8
+ a = list (map (int , input ().split ()))
9
+ print (my_gcd (a ))
Original file line number Diff line number Diff line change
1
+ n = int (input ())
2
+
3
+ for a in range (1 , 38 ):
4
+ for b in range (1 , 27 ):
5
+ if 3 ** a + 5 ** b == n :
6
+ print (a , b )
7
+ exit ()
8
+ print (- 1 )
Original file line number Diff line number Diff line change
1
+ from collections import deque
2
+
3
+ n , m = map (int , input ().split ())
4
+ a = list (map (int , input ().split ()))
5
+ b = list (map (int , input ().split ()))
6
+ visited = [False ]* n
7
+ graph = [[] for i in range (n )]
8
+
9
+ for i in range (m ):
10
+ c , d = map (int , input ().split ())
11
+ graph [c - 1 ].append (d - 1 )
12
+ graph [d - 1 ].append (c - 1 )
13
+
14
+ def bfs (start ):
15
+ q = deque ([start ])
16
+ visited [start ] = True
17
+ ans = []
18
+ while q :
19
+ now = q .popleft ()
20
+ ans .append (now )
21
+ for i in graph [now ]:
22
+ if visited [i ] == False :
23
+ visited [i ] = True
24
+ q .append (i )
25
+
26
+ return ans
27
+
28
+ for v in range (n ):
29
+
30
+ if visited [v ] == False :
31
+ nodes = bfs (v )
32
+
33
+ if sum (a [idx ] for idx in nodes ) != sum (b [idx ] for idx in nodes ):
34
+ print ('No' )
35
+ exit ()
36
+
37
+ print ('Yes' )
38
+
You can’t perform that action at this time.
0 commit comments