Harryxun/stf_run huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    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)]


N, M=map(int,input().split())
UF=UnionFind(N)

for _ in range(M):
  A,B=map(int,input().split())
  UF.union(A,B)

ans=0

for i in range(N):
  ans = max(ans, UF.size(i));
 
 print(ans)

### FIXED CODE ###

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)]


N, M = map(int, input().split())
UF = UnionFind(N)

for _ in range(M):
    A, B = map(int, input().split())
    UF.union(A - 1, B - 1)

ans = 0

for i in range(N):
    ans = max(ans, UF.size(i))

print(ans)
def main():
    s = list(input())
    s_uniq = list(set(s))

    a = s.count(s_uniq[0])
    b = s.count(s_uniq[1])

    if a == 2 and b == 2:
        print("Yes")
    else:
        print("No")

main()

### FIXED CODE ###

def main():
    s = list(input())
    s_unq = list(set(s))

    if len(s_unq) == 2:
        if s.count(s_unq[0]) == 2 and s.count(s_unq[1]):
            print("Yes")
    else:
        print("No")

main()
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
ans=chk=0
w=[1]
x=set([1])
for i in range(k):
    t=a[w[-1]-1]
    if t in x: break
    x.add(t)
    w.append(t)
    if i==k-1:
        print(t)
        exit()
mae=max(0,w.index(t)-1)
k-=mae
loop=len(w)-mae-1
print(w[k%loop+mae])


### FIXED CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=[0]
w=set([0])
x=0
for i in range(n):
    if a[x]-1 not in w:
        d.append(a[x]-1)
        w.add(a[x]-1)
        x=a[x]-1
    else:
        f=a[x]-1
        break

#print(d)
if k<len(d):
    print(d[k]+1)
else:
    x=k-len(d)
    y=d.index(f)
    z=len(d)-y
    #print(d,f,x,y,z)
    #exit()
    print(d[y+x%z]+1)
N, Q = [int(_) for _ in input().split()]
S = input()
l_r_list = [[int(_) for _ in input().split()] for _ in range(Q)]

AC_accumulation = [0]

for i in range(1, N):
    if S[i] == "C":
        if S[i - 1] == "A":
            AC_accumulation.append(AC_accumulation[-1] + 1)
    else:
        AC_accumulation.append(AC_accumulation[-1])


ans = []
for l, r in l_r_list:
    ans.append(str(AC_accumulation[r - 1] - AC_accumulation[l - 1]))

print("\n".join(ans))


### FIXED CODE ###

N, Q = [int(_) for _ in input().split()]
S = input()
l_r_list = [[int(_) for _ in input().split()] for _ in range(Q)]

AC_accumulation = [0]

for i in range(1, N):
    if S[i] == "C" and S[i - 1] == "A":
        AC_accumulation.append(AC_accumulation[-1] + 1)
    else:
        AC_accumulation.append(AC_accumulation[-1])


ans = []
for l, r in l_r_list:
    ans.append(str(AC_accumulation[r - 1] - AC_accumulation[l - 1]))

print("\n".join(ans))
N = str(N)
identify = N[-1]
answer = 'hon'
pon_list = ['0','1', '6', '8']
bon_list = ['3']
if identify in pon_list:
  answer = 'pon'
elif identify in bon_list:
  answer = 'bon'
print(answer)

### FIXED CODE ###

N = str(input())
identify = N[-1]
answer = ''
pon_list = ['0','1', '6', '8']
bon_list = ['3']
if identify in pon_list:
  answer = 'pon'
elif identify in bon_list:
  answer = 'bon'
else:
  answer = 'hon'
print(answer)
ABK = input()
A = int(ABK[0])
B = int(ABK[1])
K = int(ABK[2])

if (K >= A):
  print(str(K-A) + " " + str(K-A-B))
else:
  print(str(K-A) + " " + str(B))

### FIXED CODE ###

ABK = input().split()
A = int(ABK[0])
B = int(ABK[1])
K = int(ABK[2])

if (K >= A):
    K -= A
    B -= K
    A = 0

    if (B <= 0):
        B = 0
else:
    A -= K

print(str(A) + " " + str(B))
import fractions 

N = int(input())
for i in range(N):#1000
  t, a = map(int, input().split())
  if i == 0:
    taka, aoki = t, a
  else:
    now = [10 ** 10, -1, -1]
    for i in range(1001):
      if ((taka + i) * (a / t)) % 1 == 0:
        a2 = int((taka + i) * (a / t))
        if (now[0] >= a2 + taka + i) and (a2 >= aoki):
          now = [taka + i + a2, taka + i, a2]
      if ((aoki + i) * (t / a)) % 1 == 0:
        b2 = int((aoki + i) * (t / a))
        if (now[0] >= b2 + aoki + i) and (b2 >= taka):
          now = [aoki + i + b2, b2, aoki + i]
    taka = now[1]
    aoki = now[2]
    #print(now)
print(now[0])
        
        

### FIXED CODE ###

N = int(input())
takahashi = 1
aoki = 1
for i in range(N):
  T, A = map(int,input().split())
  n = max((takahashi + T - 1) // T, (aoki + A - 1) // A)
  takahashi = n*T
  aoki = n*A
print(takahashi+aoki)
n = int(input())
a = [int(i) for i in input().split]
print(min(a), max(a), sum(a))



### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
print(min(a), max(a), sum(a))
def min_disc(points):
    from random import sample
    N = len(points)
    if N == 1:
        return points[0], 0
    points = sample(points, N)
    def cross(a, b):
        return a.real * b.imag - a.imag * b.real
    def make_circle_3(a, b, c):
        A, B, C = abs(b-c), abs(c-a), abs(a-b)
        S = cross(b-a, c-a)
        p = A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c / (4*S*S)
        r2 = abs(p-a)
        return p, r2
    def make_circle_2(a, b):
        c = (a+b) / 2
        r2 = abs(a-c)
        return c, r2
    def in_circle(point, circle):
        return abs(point-circle[0]) <= circle[1]+1e-7
    p0 = points[0]
    circle = make_circle_2(p0, points[1])
    for i, p_i in enumerate(points[2:], 2):
        if not in_circle(p_i, circle):
            circle = make_circle_2(p0, p_i)
            for j, p_j in enumerate(points[1:i], 1):
                if not in_circle(p_j, circle):
                    circle = make_circle_2(p_i, p_j)
                    for p_k in points[:j]:
                        if not in_circle(p_k, circle):
                            circle = make_circle_3(p_i, p_j, p_k)
    return circle

N = int(input())
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append(x + y*1j)
center, rad = min_disc(XY)
print(rad)


### FIXED CODE ###

def min_disc(points):
    from random import sample
    N = len(points)
    if N == 1:
        return points[0], 0
    points = sample(points, N)
    def cross(a, b):
        return a.real * b.imag - a.imag * b.real
    def norm2(a):
        return a.real * a.real + a.imag * a.imag
    def make_circle_3(a, b, c):
        A, B, C = norm2(b-c), norm2(c-a), norm2(a-b)
        S = cross(b-a, c-a)
        p = (A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c) / (4*S*S)
        radius = abs(p-a)
        return p, radius
    def make_circle_2(a, b):
        c = (a+b) / 2
        radius = abs(a-c)
        return c, radius
    def in_circle(point, circle):
        return abs(point-circle[0]) <= circle[1]+1e-7
    p0 = points[0]
    circle = make_circle_2(p0, points[1])
    for i, p_i in enumerate(points[2:], 2):
        if not in_circle(p_i, circle):
            circle = make_circle_2(p0, p_i)
            for j, p_j in enumerate(points[1:i], 1):
                if not in_circle(p_j, circle):
                    circle = make_circle_2(p_i, p_j)
                    for p_k in points[:j]:
                        if not in_circle(p_k, circle):
                            circle = make_circle_3(p_i, p_j, p_k)
    return circle

N = int(input())
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append(x + y*1j)
center, rad = min_disc(XY)
print(rad)
a=list(input().split())
b=int(a[0])
c=int(a[1])
if a%b==0:
  print(b+c)
else:
  print(c-b)

### FIXED CODE ###

a=list(input().split())
b=int(a[0])
c=int(a[1])
if c%b==0:
  print(b+c)
else:
  print(c-b)
import sympy

n = int(input())
arr = list(map(int, input().split()))

x = sympy.Symbol("x")

ex = [0] * n
ex[0] = x

for i in range(n - 1):
    ex[i + 1] = 2 * arr[i] - ex[i]

ans = sympy.solve(ex[0] + ex[-1] - 2 * arr[-1])[0]
ans = [y.subs(x, ans) for y in ex]

print(*ans)

### FIXED CODE ###

import numpy as np
n = int(input())
arr = np.array(list(map(int, input().split())))

ans = np.zeros(n + 1, dtype=int)
for i, x in enumerate(arr):
    tmp = x * 2 - ans[i]
    ans[i + 1] += tmp

x = ans[-1] // 2
ans = ans[:-1]
ans[0::2] += x
ans[1::2] -= x

print(*ans)
import sympy
x=int(input())
ans=sympy.nextprime(x)
print(ans)

### FIXED CODE ###

x=int(input())
i=2
cond="notyet"
while cond=="notyet":
    count=0
    for i in range(2,x):
        ex=x%i
        if  ex!=0:
            count+=1
    if count==x-2:
        ans=x
        cond="discovered"
    else:
        x=x+1
print(ans)
n,a,b = map(int,input().split())
count_list = [0]*n

cnt = 0
for i in range(1,n):
  for k in range(i+1,n+1):
    a0 = k-i
    a1 = abs(a-i)+ abs(b-k) + 1
    count_list[cnt] = min(a0,a1)
    #print(i,"@",k,"@",a0,"@",a1,"@",count_list,cnt)
    cnt += 1
    
    

for result in range(1,n+1):
  print(count_list.count(result))

### FIXED CODE ###

a = list(input())
 
if a[2] == a[3] and a[4] == a[5]:
    print("Yes")
else:
    print("No")
n = int(input())
S = [input() for i in range(n)]
cnt = 0
a = 0
b = 0
ba = 0
for i in range(n):
    cnt += S[i].count("AB")
    if S[i].startswith("B") and S[i].endswith("A")
        ba += 1
    elif S[i].startswith("B"):
        a += 1
    elif S[i].endswith("A"):
        b += 1
if ba >= 1:
    cnt += ba - 1
if a >= 1:
    cnt += 1
if b >= 1:
    cnt += 1
print(cnt)


### FIXED CODE ###

n = int(input())
S = [input() for i in range(n)]
cnt = 0
a = 0
b = 0
ba = 0
for i in range(n):
    cnt += S[i].count("AB")
    if S[i].startswith("B") and S[i].endswith("A"):
        ba += 1
    elif S[i].startswith("B"):
        b += 1
    elif S[i].endswith("A"):
        a += 1
if ba >= 1:
    cnt += ba - 1
    if a >= 1:
        cnt += 1
        a -= 1
    if b >= 1:
        cnt += 1
        b -= 1
    cnt += min(a, b)
elif a >= 1 and b >= 1:
    cnt += min(a, b)
print(cnt)
s = list(input())

i = 0
abc = list("ABC")

def roop(n): #n:現在地
  if n >= len(s)-2:
    return 0
  elif s[n:n+3] == abc:
    s[n] = "B"
    s[n+1] = "C"
    s[n+2] = "A"
    if n == 0: return roop(n+2)+1 
    return roop(n-1)+1
    # return roop(n-1)+1
  else:
    return roop(n+1)


print(roop(0))

### FIXED CODE ###

s = list(input())

i = 0
bc = list("BC")

a_cnt = 0
res = 0
i = 0
while i <= len(s)-1:
  if s[i] == "A":
    a_cnt += 1
  elif s[i:i+2] == bc:
    res += a_cnt
    i += 1
  else:
    a_cnt = 0
  i += 1

print(res)
N,Q=list(map(int,input().split()))
cnt=[0]*N
dic={}
for _ in range(N-1):
    temp=list(map(int,input().split()))
    dic.setdefault(temp[0],[]).append(temp[1])
p=[]
X=[]
for _ in range(Q):
    temp2=list(map(int,input().split()))
    p.append(temp2[0])
    X.append(temp2[1])
k=dic.keys()

def tree(o):
    for y in dic[o]:
        cnt[y-1]+=add
        if y in k:
            tree(y)

for x in range(Q):
    add=X[x]
    cnt[p[x]-1]+=add
    if p[x] in k:
        tree(p[x])

print(*cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
read N, D as int
ans = 0
for i = 1, ..., N:
	read X, Y as int
	if X * X + Y * Y <= D * D:
		ans += 1
 write ans


### FIXED CODE ###

N, D = map(int,input().split())
ans = 0
i = 1
while i <= N:
  i += 1
  X, Y = map(int,input().split())
  
  if X * X + Y * Y <= D * D:
    ans += 1
print(ans)
N, S = input().split()

hN = int(int(N)/2)

S1 = S[:hN]
S2 = S[hN:]

if(S1 == S2):
    print('Yes')
else:
    print('No')


### FIXED CODE ###


N = int(input())
S = input()

hN = int(int(N)/2)

S1 = S[:hN]
S2 = S[hN:]

if(S1 == S2):
    print('Yes')
else:
    print('No')
s = input()
from collections import deque
dq = deque()
for i in range(len(s)):
    if s[i] == "B":
        dq.pop()
        continue
    dq.append(s[i])
print("".join(dq))


### FIXED CODE ###

s = input()
from collections import deque
dq = deque()
for i in range(len(s)):
    if s[i] == "B":
        if len(dq) == 0:
            continue
        dq.pop()
        continue
    dq.append(s[i])
print("".join(dq))
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int n,m,k;
int main(){
	fast
	cin>>n>>m>>k;
	int sx,sy,ex,ey;
	cin>>sx>>sy>>ex>>ey;
	pii came[n][m];
	sx--;sy--;ex--;ey--;
	char a[n][m];
	FOR0(n){
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	int vis[n][m];
	mem(vis,-1);
	queue<pair<int,int> >q;
	vis[sx][sy]=0;
	q.push({sx,sy});
	mem(came,-1);
	came[sx][sy]={-1,-1};
	while(!q.empty()){
		pii f=q.front();
		q.pop();
		int x=f.ff,y=f.ss;
		for(int i=1;i<=k;i++){
			int yy=y+i;
			if(yy>=m) break;
			if(a[x][yy]=='@') break;
			else if(vis[x][yy]==-1){
				vis[x][yy]=vis[x][y]+1;
				q.push({x,yy});
				came[x][yy]={x,y};
			}
			else if(came[x][yy]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int yy=y-i;
			if(yy<0) break;
			if(a[x][yy]=='@') break;
			else if(vis[x][yy]==-1){
				vis[x][yy]=vis[x][y]+1;
				q.push({x,yy});
				came[x][yy]={x,y};
			}
			else if(came[x][yy]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int xx=x+i;
			if(xx>=n) break;
			if(a[xx][y]=='@') break;
			else if(vis[xx][y]==-1){
				vis[xx][y]=vis[x][y]+1;
				q.push({xx,y});
				came[xx][y]={x,y};
			}
			else if(came[xx][y]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int xx=x-i;
			if(xx<0) break;
			if(a[xx][y]=='@') break;
			else if(vis[xx][y]==-1){
				vis[xx][y]=vis[x][y]+1;
				q.push({xx,y});
				came[xx][y]={x,y};
			}
			else if(came[xx][y]==came[x][y]) break;
		}
	}
	cout<<vis[ex][ey];
}

### FIXED CODE ###

#getting input from user
#cranes and turtle already give the information
#condition yes or no 
X,Y= map(int,input().split())
cranes= 2 # assign 2 to cranes
turtles= 4 # assign 4 to turtle
ans="No"
for i in range(X+1): 
    b=X-i
    if cranes*i + turtles*b == Y:
        ans = "Yes"
print(ans)

# Time complixity O(X)
# D - Integer Cards
# https://atcoder.jp/contests/abc127/tasks/abc127_d

import sys

n, m = list(map(int, sys.stdin.readline().split()))
cards = list(map(int, sys.stdin.readline().split()))
cards.sort()

set = [list(map(int, sys.stdin.readline().split())) for _ in range(m)]

# combinations.sort(key = lambda x: x[1], reverse = True)
combinations = []
for b, c in set:
    combinations.extend([c] * b)

combinations.sort(reverse = True)

for i in range(len(combinations)):
    if i > len(cards) or combinations[i] <= cards[i]:
        break
    else:
        cards[i] = combinations[i]

print(sum(cards))

### FIXED CODE ###

a, b = list(map(int, input().split()))

if a <= 5:
    print(0)
elif a <= 12:
    print(b//2)
else:
    print(b)
a = []
while True:
    n = input()
    if n == -1:
        break
    a.append(n)
for i in range(len(a)):
    if(a[i]==0):
        break
    else:
        print(a[i])

### FIXED CODE ###

i=1
while(1):
    n=input()
    if(int(n)==0):
        break
    else:
        print('Case '+str(i)+': '+n)
        i+=1
import sys,array
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split( )))
a = array.array("i",a)
ans = 0
mod = 10**9+7
Bit = [[0]*2 for j in range(60)]# for i in range(n+1)

for i in range(1,n):##1から
    for j in range(60):
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j][0] += 1
        else:#ｊビット目1
            Bit[j][1] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j][0]<<j
            ans %=mod
        else:
            ans += Bit[j][1]<<j
            ans %= mod
    #print(Bit[:6])
"""
for i in range(1,n):##1から
    for j in range(60):

    #ans += a[i]
    #ans %=mod
    #自身の分
        #print(ans)
"""
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split( )))
ans = 0
mod = 10**9+7
Bit = [0 for j in range(60)]# for i in range(n+1)
for j in range(60):#ループ交換
    for i in range(1,n):##1から
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j]<<j
            ans %=mod
        else:
            ans += (i-Bit[j])<<j
            ans %= mod
    
print(ans)
S = int(input())
h = s / / 3600
m = (s // 60) % 60
s = S % 60
print(h,";",m,":",s,sep="")

### FIXED CODE ###

S = int(input())
h = S // 3600
m = (S // 60) % 60
s = S % 60
print(h,":",m,":",s,sep="")
inp = input().split(" ")
N = int(inp[0])
K = int(inp[1])

arr = []
indicies = [0]

for i in range(N):
	inp = input().split(" ")
	a = int(inp[0])
	b = int(inp[1])
	if len(arr) == 0 or a >= arr[-1]:
		arr += [a] * b
		indicies.append(len(arr))
	elif a <= arr[0]:
		arr = ([a] * b) + arr
	else:
		for i in indicies:
			if a > arr[i-1] and a < arr[i]:
				arr = arr[0:i] + ([a] * b) + arr[i:]
	print(arr)

print(arr[K])


### FIXED CODE ###

nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])

arr = []

for i in range(0, n):
	ab = input().split(' ')
	arr.append((int(ab[0]), int(ab[1])))

arr = sorted(arr)

pos = 0
while True:
	if k > arr[pos][1]:
		k -= arr[pos][1]
	else:
		print(arr[pos][0])
		break
	pos += 1
N = input()
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A + B)

### FIXED CODE ###

N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A + B)
N, X, M = [int(v) for v in input().split()]

def f(a):
    return a * a % M


a = X

map = {}
ary = [a]
map[a] = 1

sub = [0, a]
last_sub = a

def naive(a):
    total = a
    ary = [a]
    for i in range(1, N):
        a = f(a)
        ary.append(a)
    return ary
    
#n_ary = naive(X)
#print(n_ary)
#print(sum(n_ary))

count = 1
for i in range(1, N):
    a = f(a)
    if a == 0:
        break
    if a in map:
        break
    else:
        map[a] = i
    count += 1
    last_sub += a
    sub.append(last_sub)

if a == 0:
    print(sub[-1])
    exit()

j = map[a]

#print(sub)
#print(j)
unit = sub[-1] - sub[j]
#print(unit)

l = count
i = (N - j) % (l - j)
d = (N - j) // (l - j)

#i = N % l
#d = N // l

#print(len(sub), i, j)
print(unit * d + sub[i + j])

#print(sub[-1] * (d + 1) * d // 2 + sub[i])


### FIXED CODE ###

N, X, M = [int(v) for v in input().split()]

def f(a):
    return a * a % M

a = X

map = {}
ary = [a]
map[a] = 0

sub = [0, a]
last_sub = a

count = 1
for i in range(1, N):
    a = f(a)
    if a == 0:
        break
    if a in map:
        break
    else:
        map[a] = i
    count += 1
    last_sub += a
    sub.append(last_sub)

if a == 0:
    print(sub[-1])
    exit()


def naive(a):
    total = a
    ary = [a]
    for i in range(1, N):
        a = f(a)
        ary.append(a)
    return ary
    
#n_ary = naive(X)
#print(n_ary)
#print(sum(n_ary))

j = map[a]

#print(sub)
#print(j)

unit = sub[-1] - sub[j]
#print(unit)

l = count
i = (N - j) % (l - j)
d = (N - j) // (l - j)

#i = N % l
#d = N // l

#print(len(sub), i, j)
print(unit * d + sub[i + j])

#print(sub[-1] * (d + 1) * d // 2 + sub[i])
S = input()
K = int(input())
s = len(str(S))
l = [str(x) for x in S]
i = 0
while i <= s - 1:
  if l[i] == '1':
    i = i + 1
  else:
    break

if i == 100:
  print(1)
if K < 99:
  print(l[K-1])
else:
  print(l[i-1])

### FIXED CODE ###

S = input()
K = int(input())
s = len(str(S))
i=0

while i < s-1:
  if S[i] == '1':
    i = i + 1
  else:
    break

if K > i:
  print(S[i])
else:
  print(1)
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)


### FIXED CODE ###

import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(11):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N , M)
x = [""] * L
for i in range(N):
    idx = i * (L // N)
    # x[idx] = S[i]
for i in range(M):
    idx = i * (L // M)
    if x[idx] != "" and x[idx] != T[i]:
        print(-1)
        exit()
print(L)


### FIXED CODE ###

import math

N = int(input())
a_li = []
b_li = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    a_li.append(a)
    b_li.append(b)
for i in reversed(range(N)):
    a, b = a_li[i], b_li[i]
    a += ans
    div = math.ceil(a / b)
    ans += b * div - a
print(ans)
import math

R = int(input())
return 2 * math.pi * R

### FIXED CODE ###

import math

R = int(input())
print(2 * math.pi * R)
n=int(input())
a=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')
         
      		


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(n):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    print('YES')
else:
    print('NO')