Jupyter Notebook
AGC-n
Current Kernel Logo
Python 3 


1
#A
2
N=input()
3
A_list=list(map(int,input().split()))
4
n=0
5
for i in range(len(A_list)-1):
6
    if A_list[i]==A_list[i+1]:
7
        A_list[i+1]+=10000
8
        n+=1
9
print(n)
1
2 3 4 5
0

1
#B
2
import math
3
T=int(input())
4
for i in range(T):
5
    check=0
6
    A,B,C,D=map(int,input().split())
7
    A_list=[]
8
    if B>D:
9
        print('No')
10
        check=1
11
    while check==0:
12
        k=math.ceil((A-C)/B) if A>=C else 1
13
        A-=k*B
14
        if A<0:
15
            print('No')
16
            break
17
        elif A<=C:
18
            A+=D
19
            if (A in A_list or A==0):
20
                print('Yes')
21
                break
22
            A_list.append(A)
1
9 7 5 9
No

1
# B
2
import math
3
T=int(input())
4
abcd=list(map(int,input().split()))
5
for i in range(T):
6
    sugoi='no'
7
    A,B,C,D=abcd[4*i],abcd[4*i+1],abcd[4*i+2],abcd[4*i+3]
8
    A_list=[]
9
    if B>D:
10
        print('No')
11
        sugoi='yes'
12
    while sugoi=='no':
13
        k=math.ceil((A-C)/B) if A>=C else 1
14
        A-=k*B
15
        if A<0:
16
            print('No')
17
            break
18
        elif A<=C:
19
            A+=D
20
            if A in A_list:
21
                print('Yes')
22
                break
23
            A_list.append(A)

1
import random
2
moji=''
3
for i in range(96*4):
4
    k=random.randrange(10,100000)
5
    moji+=str(k)+' '
6
print(moji)
49577 38748 51545 14229 66123 10159 13594 6667 75070 86954 43840 53738 39847 89585 9933 10129 70224 43454 45481 51487 54133 32286 78378 6497 73223 12189 87999 65011 43165 32546 8432 49737 43518 87213 90515 92099 74897 55565 46842 11081 84008 30991 44856 10305 72212 79367 86422 23049 34681 16096 93431 10032 78460 20377 44252 84334 98591 30972 75860 61883 48522 6988 85488 44798 39847 51447 49578 24157 69296 30493 8039 86315 33193 24243 23835 60725 99843 15788 27649 78531 7473 45213 58255 19078 63934 67284 38890 39155 25554 68632 65336 41502 97236 2317 93279 31025 60928 37625 44284 90314 42272 998 13481 53773 89382 98693 89134 76034 66399 95908 83397 9050 1185 9287 13075 22268 32701 95365 39540 3229 98603 59523 94096 44043 57083 6753 46555 1918 42947 8303 64854 37648 61525 98387 86705 38499 91181 48418 50920 29372 58029 24455 90742 14303 9907 73692 25233 34412 44743 33412 92719 94350 35737 16182 49794 25665 53330 47138 92539 696 54581 93518 36745 80424 59149 22790 697 72606 34502 94277 218 20114 81501 41453 44708 75123 25623 6222 51387 2561 47426 416 92800 23639 15666 47122 73472 99766 44914 48566 56201 71348 18268 93876 46551 35164 72609 59316 90756 20705 40484 12132 24345 21801 95572 69432 55858 73229 79945 68822 32966 73732 69373 7177 10817 53863 30883 46980 73951 88471 27314 53286 60991 14070 5757 23970 42978 55057 77030 64451 94209 19825 98049 89573 99554 23004 91677 11626 73234 26402 83987 76501 48311 50527 27379 8455 38923 86818 20238 67077 34259 22630 20689 60414 25516 61921 62161 31533 26844 6818 15493 19052 66511 77893 29455 21509 85070 90188 67693 61281 24487 86300 19230 90598 94835 64004 18362 57697 60707 19909 84171 95392 34820 63054 22243 90465 35761 45148 71903 58818 78033 45587 73626 13049 61152 46111 75380 88825 87574 34409 37390 62366 4025 68652 64514 86326 7689 80484 69780 15598 9697 54332 37388 45287 73660 41083 75293 55400 86645 99173 40831 29754 2975 9435 66198 66581 19149 73914 41325 25900 66326 93100 26224 45245 51190 80973 69280 75152 84285 24035 97505 46366 43162 56726 20367 86063 98812 64109 33949 3112 52584 22431 87110 59764 81415 66427 14112 79314 59522 60695 30091 22120 51701 90949 33273 75703 88454 54028 42622 18003 27609 80241 95556 35884 61115 91784 97200 60096 86929 94001 84670 81425 85365 34807 

1
#C
2
from itertools import permutations
3
N=int(input())
4
S=input()
5
S0=S
6
ways=-1
7
"""moji='abcdefghijklmnopqrstuvwxyz'
8
for i in range(len(moji)):
9
    print(S,S.count(moji[i]))
10
    if S.count(moji[i])%2==1:
11
        ways=0
12
        break
13
print('check ok')"""
14
if ways!=0:
15
    ways=0
16
    nums=[0,]*(N-1)+[1,]*N
17
    color=list(set(permutations(nums,2*N-1)))
18
    color.sort()
19
    for j in range(len(color)):
20
        S=S0
21
        s1,s2='',''
22
        j_color=(0,)+color[j]
23
        for i in range(2*N):
24
            if j_color[i]==0:
25
                s1+=S[i]
26
                S=S[:i]+'0'+S[i+1:]
27
        s2=(S.replace('0',''))[::-1]
28
        print(j_color,s1,s2,s1==s2)
29
        if s1==s2:ways+=1
30
print(2*ways)
11
mippiisssisssiipsspiim

1
moji='abcdefg'
2
i=3
3
moji=moji[:i]+'0'+moji[i+1:]
4
moji
'abc0efg'

1
#027A
2
N,x=map(int,input().split())
3
children=list(map(int,input().split()))
4
children.sort()
5
fun=0 if x!=sum(children) else N
6
if fun==0:
7
    for i in range(N):
8
        x-=children[i]
9
        if x>=0:fun+=1
10
        else: break
11
    if fun==N:fun-=1
12
print(fun)
2 10
20 20
0

1
#027B
2
N,X=map(int,input().split())
3
gomi=list(map(int,input().split()))
4
​

-1
1
N,M=map(int,input().split())
2
S=input()
3
T=input()
4
​
5
def gcd(a,b):
6
    if a<b:a,b=b,a
7
    c=a%b
8
    while c>0:
9
        a,b=b,c
10
        c=a%b
11
    return b
12
​
13
def enstr(A):
14
    S=''
15
    for i in A:
16
        S+=i
17
    return S
18
    
19
if S[0]==T[0]:
20
    gcd=gcd(N,M)
21
    if N<M:
22
        N,M=M,N
23
        S,T=T,S
24
    if gcd==M:
25
        if S==T*(N//M):
26
            print(N)
27
        else:
28
            print('-1')
29
    else:
30
        gcm=N*M//gcd
31
        print(gcm)
32
print(-1)
3 2
a
c
-1

15 9
1
15 9


### FIXED CODE ###

N,M=map(int,input().split())
S=input()
T=input()

def gcd(a,b):
    if a<b:a,b=b,a
    c=a%b
    while c>0:
        a,b=b,c
        c=a%b
    return b

def enstr(A,g):
    m=''
    for i in range(len(A)//g):
        m+=A[g*i]
    return m
    
if S[0]==T[0]:
    gcd=gcd(N,M)
    n,m=N//gcd,M//gcd
    s,t=enstr(S,n),enstr(T,m)
    if s==t:
        print(N*M//gcd)
    else:
        print(-1)
else:
    print(-1)