akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
// #define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E,mn = 0,mx = 0;
int dp[NMAX] = {};
ll rnk = 0;
string S;
vec v;

string ans[2] = {};

void solve(){
  // main algorithm
  for(auto&& ch : S) {
    if(ch == '(') {
      rnk++;
      mx = max(mx,rnk);
    }
    else {
      rnk--;
      mn = min(rnk, mn);
    }
  }
  for (int i = 0; i < -mn; ++i)
  {
    ans[0] += "(";
  }
  for (int i = 0; i < rnk - mn; ++i)
  {
    ans[1] += ")";
  }
}
void debug(){
  // output debug information
  cout << mn << rnk << mx << endl;
  cout << ans[0] << " " << ans[1] << endl;
}
void answer(){
  // output answer
  cout << ans[0] << S << ans[1] << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N >> S;
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int A, B;
	cin >> A >> B;
	vector<vector<modulo> > ways(B + 1, vector<modulo>(A + 1));
	ways[0][0] = 1;
	for (int i = 0; i <= B; ++i) {
		for (int j = 0; j <= A; ++j) {
			if (i >= 1) ways[i][j] += ways[i - 1][j];
			if (j >= 1) ways[i][j] += ways[i][j - 1];
		}
	}
	vector<vector<modulo> > dp(B + 1, vector<modulo>(A + 1));
	for (int i = 0; i <= B; ++i) {
		modulo sum = 0;
		for (int j = 0; j <= A; ++j) {
			if (j < i) sum += ways[i - j - 1][j];
			dp[i][j] = sum + (j >= 1 ? dp[i][j - 1] : (i == 0 ? 1 : 0));
		}
	}
	modulo ans = 0;
	for (int i = 0; i <= A; ++i) {
		for (int j = 0; j < B && j <= i; ++j) {
			ans += ways[B - j - 1][j] * dp[j][i - j];
		}
	}
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a[100010];
ll mn[100010],mx[100010];

int main(){
    int n;
    cin>>n;
    rep(i,n+1)cin>>a[i];
    mn[n]=mx[n]=a[n];
    for(int i=n; i>0; --i){
        mn[i-1]=a[i-1]+(mn[i]+1)/2;
        mx[i-1]=a[i-1]+mx[i];
    }
    if(mn[0]!=1){cout<<-1<<endl; return 0;}
    ll ans=0,now=1;
    rep(i,n+1){
        ans+=now;
        now-=a[i];
        now=min(now*2,mx[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5596
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()

    L,R=-INF,INF
    for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
    print(R-L+1)



        





if __name__ == "__main__":
    main()

Measured memory_bytes: 69896
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    vvi vec(n,vi(3));
    vi ans(n);
    REP(i,n-1){
        REP(j,3){
            cin>>vec[i][j];
        }
    }
    REP(i,n-1){
        int now=0;
        FOR(j,i,n-1){
            int a=vec[j][0];
            int b=vec[j][1];
            int c=vec[j][2];
            if(i==j){
                now=a+b;
                continue;
            }
            int t=max(0,(now-b+c-1)/c);
            now=a+b+c*t;
        }
        ans[i]=now;
    }
    REP(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>


int main(void) {
	int n[100] = { 0 }, num, sum = 0,min_no10 = 100;
	scanf("%d", &num);
	for (int i = 0; i < num; i++) {
		scanf("%d", &n[i]);
		sum += n[i];
		if (n[i] % 10 != 0 && min_no10 > n[i])min_no10 = n[i];
	}
	if(sum % 10 != 0)printf("%d\n", sum);
	else if((sum - min_no10) % 10 != 0)printf("%d\n", sum - min_no10);
	else printf("0\n");

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  map<long long, int> pow5_number;
  for(long long i = -3981; i <= 3981; i++)
  {
    pow5_number[pow(i, 5)] = i;
  }
  long long X;
  cin >> X;
  for(long long i = -3981; i <= 3981; i++)
  {
    long long B5 = pow(i, 5);
    long long A5 = X + B5;
    if(pow5_number.find(A5) != pow5_number.end())
    {
      cout << pow5_number[A5] << " " << i << endl;
      return 0;
    } 
  }
  return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include<algorithm>
#include<string.h>
using namespace std;
int main() {
	//freopen("1.txt","r",stdin);
	//freopen("2.txt","w",stdout); 
   	int n;
   	cin>>n;
   	int a[100000];
   	int b[100000];
   	for(int i=0;i<n;i++)
   		cin>>a[i];
   	b[0]=0;
   	b[1]=abs(a[1]-a[0]);
   	for(int i=2;i<n;i++)
   	{
   		b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<b[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  ll wa = 0;
  vector<ll> a(n);
  ll res = 1000000000000000;
  for(int i = 0;i < n;i++)cin >> a[i],wa += a[i];
  ll now = 0;
  for(int i = 0;i < n;i++){
    now += a[i];
    res = min(res,abs(wa - now - now));
  }
  cout << res << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define gc getchar
#define pc putchar

#define fo0(i,a,b) for(int i=(a);i<(b);i++)
#define fo1(i,a,b) for(int i=(a);i<=(b);i++)
#define fd0(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define fd1(i,a,b) for(int i=(a);i>=(b);i--)
#define mset(a,b) memset(a,(b),sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

template<typename T> inline T gcd(T a, T b){T t;if(a>b){while(b){
t=b;b=a%b;a=t;}return a;}else{while(a){t=a;a=b%a;b=t;}return b;}}
template<typename T> inline T lcm(T a, T b){return a/gcd(a,b)*b;}

template<typename T> inline void QR(T &x){x=0;int fl=1;char ch=gc();while(ch<'0'||ch>'9')
{if(ch=='-')fl=-1;ch=gc();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=gc();}x*=fl;}
void Read(int &x){QR(x);} void Read(LL &x){QR(x);}
void Read(double &x){scanf("%lf", &x);} void Read(char &x){x=gc();}
template<typename T> void QW(T x){if(x<0){pc('-');x=-x;}if(x/10)QW(x/10);pc(x%10+'0');}
void Write(int &x){QW(x);} void Write(LL &x){QW(x);}
void Write(double &x){printf("%f", &x);} void Write(char &x){pc(x);}
void in(){} template<class T1,class...T2> void in(T1 &head,T2 &...tail){Read(head);in(tail...);}
void out(){} template<class T1,class...T2> void out(T1 head,T2 ...tail){Write(head);out(tail...);}

const int N = 1005;

double a, t, h, mn = 1e9;
int n, ans;

int main(){
	in(n, t, a);
	fo1(i, 1, n){
		in(h);
		double tmp = fabs(t - h * 0.006 - a);
		if(tmp < mn){
			mn = tmp;
			ans = i;
		}
	}
	out(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<P> p(n);
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
		if (p[i].first > p[i].second) swap(p[i].first, p[i].second);
	}
	sort(all(p));
	int idx = 0, check = 0;
	rep(i, n) if (chmax(check, p[i].second)) idx = i;
	ll mi = p[0].first; ll ma = p[idx].second;
	ll ans = INF;
	ll ma1 = 0; ll mi2 = inf;
	rep(i, n) {
		chmax(ma1, p[i].first);
		chmin(mi2, p[i].second);
	}
	chmin(ans, (ma1 - mi)*(ma - mi2));
	if (idx == 0) {
		cout << ans << '\n';
		return 0;
	}
	ll x = p[0].second; ll y = p[idx].first;
	if (x > y) swap(x, y);
	vector<P> a;
	rep(i, n) {
		if (i == 0 || i == idx) continue;
		P ap;
		if (p[i].second < p[i].first) swap(p[i].first, p[i].second);
		if (p[i].first < x&&p[i].second < x) {
			ap.first = x - p[i].second;
			ap.second = inf;
		}
		else if (p[i].first > y&&p[i].second > y) {
			ap.second = p[i].first - y;
			ap.first = inf;
		}
		else {
			ap.first = max(x - p[i].first, 0LL);
			ap.second = max(p[i].second - y, 0LL);
		}
		a.pb(ap);
	}
	sort(all(a));
	vector<ll> af(n - 2), as(n - 2);
	rep(i, n - 2) {
		if (i == 0) af[i] = a[i].first;
		else af[i] = max(af[i - 1], a[i].first);
	}
	for (int i = n - 3; i >= 0; i--) {
		if (i == n - 3) as[i] = a[i].second;
		else as[i] = max(as[i + 1], a[i].second);
	}
	ll v = inf;
	rep(i, n - 3) chmin(v, af[i] + as[i + 1]);
	if (n > 2) {
		chmin(v, af[n - 3]);
		chmin(v, as[0]);
	}
	v += y - x;
	chmin(ans, v*(ma - mi));
	cout << ans << '\n';
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s,t;
  cin >> s >> t;

  rep(i,t.size())cout << t[i];
  rep(i,s.size()) cout << s[i];
  cout << ""<<endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define mod 1000000007
string A, B, C; long long dp[70][3];
int main() {
	while (true) {
		cin >> A; if (A == "0")break;
		cin >> B >> C;
		for (int i = 0; i < 210; i++)dp[i / 3][i % 3] = 0;
		reverse(A.begin(), A.end()); int A1 = A.size();
		reverse(B.begin(), B.end()); int B1 = B.size();
		reverse(C.begin(), C.end()); int C1 = C.size();
		while (A.size() < 60)A = A + '0';
		while (B.size() < 60)B = B + '0';
		while (C.size() < 60)C = C + '0';
		dp[0][0] = 1;
		for (int i = 0; i < 60; i++) {
			for (int j = 0; j < 3; j++) {
				int a = 0, b = 0, c = 0;
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						int m = j + k + l;
						if ((k != (int)(A[i] - '0') && A[i] != '?') || (i == A1 - 1 && k == 0))continue;
						if ((l != (int)(B[i] - '0') && B[i] != '?') || (i == B1 - 1 && l == 0))continue;
						if ((m % 10 != (int)(C[i] - '0') && C[i] != '?') || (i == C1 - 1 && m % 10 == 0))continue;
						if (m >= 0 && m < 10)a++;
						if (m >= 10 && m < 20)b++;
						if (m >= 20 && m < 30)c++;
					}
				}
				dp[i + 1][0] += dp[i][j] * a; dp[i + 1][0] %= mod;
				dp[i + 1][1] += dp[i][j] * b; dp[i + 1][1] %= mod;
				dp[i + 1][2] += dp[i][j] * c; dp[i + 1][2] %= mod;
			}
		}
		cout << (dp[60][0] + dp[60][1] + dp[60][2]) % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int count_digit(ll n){
    int count = 0;
    while(true){
        if (n>0){
            count ++;
            n = n/10;
    }
    else break;
    }
    return count;
}

int main(){
    ll N,n;
    cin >> N;
    n=N;
    int ans = count_digit(N);

    for (ll A=1LL;A*A <=N;A++){

        if (N%A != 0) continue;

        const ll B=N/A;
        const int c=max(count_digit(A),count_digit(B));
        if (c < ans) ans = c;

    }
    cout << ans;

}

Measured memory_bytes: 256
#!/bin/ruby
loop = true

while loop
  line=STDIN.gets.chomp
  if line == '-'
    loop = false
    next
  end
  count=STDIN.gets.to_i
  count.times do
    pivot = STDIN.gets.to_i
    line = line[pivot..line.size-1] + line[0..pivot-1]
  end
  puts line
end

Measured memory_bytes: 8680
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N, total = 0;
vector<vector<int>> visited( 100 + 1, vector<int>( 10000 + 1, -1 ) );
vector<int> vc;
int dfs( int i, int sum )
{
    if( i == N )
    {
        if( total < sum && sum % 10 != 0 )
        {
            total = sum;
        }
        return 0;
    }
    if( visited[ i ][ sum ] >= 0 )
    {
        return visited[ i ][ sum ];
    }
    return visited[ i ][ sum ] = dfs( i + 1, sum + vc[ i ] ) || dfs( i + 1, sum );
    return visited[ i ][ sum ] = 0;
}
int main()
{
    cin >> N;
    vc.resize( N );
    for( auto &x : vc )
    {
        cin >> x;
    }
    dfs( 0, 0 );
    cout <<  total << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

const int nax = 1e5+10;
int n,m,u,v;
vvi adj(nax);
vi dp(nax,-1);

int dfs(int x){
    if(dp[x]!=-1) return dp[x];
    dp[x] = 0;
    for(auto ad: adj[x])
        max_self(dp[x], dfs(ad));

    ++dp[x];
    return dp[x];
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    forn(i,m){
        cin>>u>>v;
        adj[u].pb(v);
    }

    int maxLen = 0;
    fore(i,1,n+1){
        if(dp[i]==-1)
            dfs(i);
        max_self(maxLen, dp[i]);
    }

    cout<<maxLen-1<<endl;


    return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  // for (int i = 0;; i++) {
  //   if (i * (K - 1) + 1 >= N) {
  //     cout << i << endl;
  //     return 0;
  //   }
  // }
  // m >= (N-1)/(K-1)
  cout << (N + K - 3) / (K - 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int h;
  int w;
  char c = '#';
  do 
  {
  cin >> h >> w;
  
  for(int i = 0; i < h; i++)
  {
    for(int j = 0; j < w; j++)
    {
      cout << c;
    }
    cout << endl;
  }
    if (h != 0 && w != 0)
      cout << endl;
  }while(h != 0 && w != 0);
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0;
  set<ll> st;
  cin >> n >> k;
  vector<ll> l(k), r(k);
  ll dp[n + 1] = {}, sdp[n + 1] = {};
  dp[1] = sdp[1] = 1;
  rep(i, k) cin >> l[i] >> r[i];

  for (ll i = 2; i <= n; ++i) {
    rep(j, k) {
      ll li = i - r[j], ri = i - l[j];
      if (ri < 0) continue;
      li = max(1ll, li);
      (dp[i] += sdp[ri] - sdp[li - 1] + mod) %= mod;
    }
    (sdp[i] = sdp[i - 1] + dp[i]) %= mod;
  }

  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 6748
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string A, B;
  cin >> A >> B;
  stringstream ss;
  ss << A << B;
  string S = ss.str();
  ll a = atoi(S.c_str());
  REP(i, 1, 1001) {
    if (i * i == a) {
      cout << "Yes" <<endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		log.Fatal(err)
	}
	return i
}

func main() {

	sc.Split(bufio.ScanWords)
	n := nextInt()
	list := []int{}
	for i := 0; i < n; i++ {
		x := nextInt()
		list = append(list, x)
	}

	min := list[0]
	result := 0

	for _, i := range list {
		if min >= i {
			result++
			min = i
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define ll long long
#define ld long double
     
int main(){
  ll n;
  cin >> n;
  
  vector<string> v(n);
  rep(i,n) cin >> v[i];
  
  ll ac=0,wa=0,tle=0,re = 0;
  rep(i,n){
    if(v[i]=="AC") ac++;
    if(v[i]=="WA") wa++;
    if(v[i]=="TLE") tle++;
    if(v[i]=="RE") re++;
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6284
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  int count=1;
  for(int i=0;i<N-1;i++){
    if(d.at(i)<d.at(i+1)){
      count=count+1;
    }
    else{
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int main() {
	int N;
	cin >> N;
	

	cout << N/30 << " " << N%30*2 << endl;
	return 0;
}

Measured memory_bytes: 3112
#include <string>
#include <iostream>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  long long a(0);
  long long b(0);
  bool first = true;
  for (int i = 0; i < s.size(); ++i) {
    if (first && s[i] != ' ') {
      a *= 10;
      a += (s[i] - '0');
    }
  }
  for (int i = 0; i < t.size(); ++i) {
    if (t[i] != '.') {
      b *= 10;
      b += (t[i] - '0');
    }
  }
  cout << (a * b / 100) << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int h,w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a[i][j];
    queue<P> que;
    que.push(P(0,0)); a[0][0] = '.';
    int x[] = {1,0},y[] = {0,1};
    int cnt = 1;
    while(que.size()){
        P p = que.front();
        que.pop();
        for(int k = 0; k < 2; k++){
            int nx = p.first+x[k],ny = p.second+y[k];
            if(0 <= nx && nx < w && 0 <= ny && ny < h && a[ny][nx] == '#'){
                a[ny][nx] = '.';
                que.push(P(nx,ny));
                cnt++;
            }
        }
    }
    int flag = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            //cout << a[i][j];
            if(a[i][j] == '#') flag = 1;
        }
        //cout << endl;
    }
    cout << (flag || cnt != w+h-1 ? "Impossible" : "Possible") << endl;
    return 0;
}

Measured memory_bytes: 256
def checker(L1, L2):
    N = len(L1)
    for i in range(N):
        if L1[i] == L2[i] or L1[i] == "?":
            pass
        else:
            return False

    return True


def solve():
    while 1:
        try:
            S_prime = list(input())
            T = input()
            if len(T) > len(S_prime):
                print("UNRESTORABLE")
                raise EndLoop
            elif S_prime.count("?") == 0:
                if T in "".join(S_prime):
                    print("".join(S_prime))
                    raise EndLoop
                else:
                    print("UNRESTORABLE")
                    raise EndLoop
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                raise EndLoop

            possible_ans = []
            for i in range(len(S_prime) - len(T) + 1):
                tmp_str = list(S_prime[i:len(T) + i])
                if checker(tmp_str, T):
                    if i + len(T) == len(S_prime):
                        S = "".join(S_prime[:i]) + "".join(T)
                        possible_ans.append(S.replace("?", "a"))
                    else:
                        S = "".join(S_prime[:i]) + T + "".join(S_prime[i + len(T):])
                        possible_ans.append(S.replace("?", "a"))
                        
            if len(possible_ans) == 0:
                print("UNRESTORABLE")
            else:
                print(min(possible_ans))
            break
        except:
            break


solve()

Measured memory_bytes: 3192
#include <bits/stdc++.h>

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===


using Graph = std::vector<std::vector<int>>;
Graph g;
Vi checked;
Vi color;
map<pair<int, int>, int> edge_idx;


int dfs(int idx, int root)
{
	int chs = (int)g[idx].size();
	int tmp = 0;
	int c = 0, d = 0;
	for (const auto& to : g[idx]) {
		if (checked[to] == 1) continue;
		if (c == root) d = 1;
		int edge_a, edge_b;
		edge_a = min(idx, to);
		edge_b = max(idx, to);
		color[edge_idx[make_pair(edge_a, edge_b)]] = c + d;
		checked[to] = 1;
		tmp = max(tmp, dfs(to, c + d));
		++c;
	}

	int res;
	if (root == -1) res = max(tmp, chs);
	else res = max(tmp, chs + 1);
	return res;
}


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	g.resize(N);
	checked.resize(N);
	color.resize(N - 1, -1);
	

	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
		if (a > b) swap(a, b);
		edge_idx[make_pair(a, b)] = i;
	}

	checked[0] = 1;
	dfs(0, -1);

	int ans = 0;
	for (int i = 0; i < N - 1; ++i) {
		ans = max(ans, color[i] + 1);
	}

	cout << ans << endl;
	for (int i = 0; i < N - 1; ++i) {
		cout << color[i] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 14976
#include<cstdio>
#include<vector>


using namespace std;
using vi=vector<int>;


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		int ans=0;
		vi a(n);

		for(int i=0;i<n;i++)
		{
			scanf("%d", &a[i]);
		}

		for(int i=1;i<n;i++)
		{
			if(a[i]==a[i-1])
			{
				a[i]=0;
				ans++;
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int n,k;
int main(){
  cin>>n>>k;
  int ans=1;
  rep(i,n){
    ans=min(ans*2,ans+k);
  }
  prin(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  function <ll(int, int, ll, ll)> rec = [&] (int l, int r, ll c1, ll c2) {
    if (l > r) return 0LL;
    ll res = 1e18;
    for (int i = l; i <= r; ++i) {
      ll cur = (ll)a[i] * (c1 + c2) + rec(l, i - 1, c1, c1 + c2) + rec(i + 1, r, c1 + c2, c2);
      res = min(cur, res);
    } 
    return res;
  };
  cout << a[0] + a[n - 1] + rec(1, n - 2, 1, 1) << '\n';
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int resulta=0,resultb=0;
    string a;
    cin>>a;
    for(int i=0;i<a.length();i++){
        if(a[i]=='C')resulta=1;
        if(a[i]=='F' && resulta==1)resultb=1;
    }
    cout<<((resultb==1)?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;

const ll BIG = 1000000007;

ll sum(ll l, ll r){
    return (l+r)*(r-l+1)/2;
}

int main(){
    int n,k;
    cin >>n>>k;
    ll ans=0;
    for(int i=k; i<=n+1; i++){
        ll l = sum(0, i-1), r = sum(n-i+1, n);
        ans += (r-l+1);
        ans = ans%BIG;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n];

	/* (a1*a2*...*an) mod ai = 0
	   (a1*a2*...*an - 1) mod ai = ai - 1 */
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i] - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n+1),b(n);
  for(ll i = 0; i <= n; ++i) cin >> a[i];
  for(ll i = 0; i < n; ++i) cin >> b[i];
  ll ans = 0;
  ll k = min(a[0],b[0]);
  ll tmp = k,bi = b[0]-k;
  for(ll i = 1; i < n; ++i){
    tmp += min(bi+b[i],a[i]);
    ll ai = max(0ll,a[i]-bi);
    bi = max(0ll,b[i]-ai);
  }
  tmp += min(bi,a[n]);
  ans = max(ans,tmp);
  cout << ans;
  return 0;
}

Measured memory_bytes: 1792
import math
import sys
N = int(input())
S = int(input())

def tt(k, N):
    r = 0
    while N:
        N, m = divmod(N, k)
        r += m
#    print(k, r)
    return r

if N == S:
    print(N+1)
    sys.exit()

for i in range(2, math.floor(N**0.5) + 2):
    if tt(i, N) == S:
        print(i)
        sys.exit()

for k in range(math.floor(N**0.5), 0, -1):
    s = N//k
    f = N//(k+1) + 1
    si = k + N%k
    fi = si + (s-f)*k
    if N//(s**2) > 0:
        continue
#    print("aaa", k, si, fi, s, f)
    if si <= S <= fi and ((fi-S) % k == 0):
#        print(k)
#        print("cc", f, fi, S, f+(fi-S)//k)
        print(f+(fi-S)//k)
        sys.exit()
#    for i in range(f, s+1):
#        tt(i, N)
#        if ( i == f or i == s ) and S == tt(i, N):
#            print(i)
#            sys.exit()

print(-1)


Measured memory_bytes: 41820
import sys
N = int(sys.stdin.readline().rstrip())
s = []
if N == 0:
    print(0)
    exit()
base = 1
cur = 2
while N != 0:
    r = N % cur
    if r > 0:
        s.append("1")
        N -= base
    else:
        s.append("0")
    cur *= 2
    base *= -2
print("".join(s[::-1]))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, A, B, cou, sum, res, ans;
std::map<LL, LL>map, list;

void make_comb(std::vector<std::vector<LL>> &v)
{
	rep(i, v.size())
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); ++k)
	{
		for (int j = 1; j < k; ++j)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}

int main()
{
	in >> N >> A >> B;
	std::vector<LL>v(N);
	std::vector<std::vector<LL>>comb(N + 1, std::vector<LL>(N + 1, 0));
	rep(i, N) in >> v[i];
	rep(i, N) ++map[v[i]];
	std::sort(v.begin(), v.end(), std::greater<LL>());
	make_comb(comb);
	rep(i, A)
	{
		sum += v[i];
		++list[v[i]];
		++cou;
	}
	res = 1;
	for (auto i : list) res *= comb[map[i.first]][i.second];
	ans += res;
	rep(i, B - A)
	{
		if (v[i + A] == v[0])
		{
			sum += v[i];
			++list[v[i]];
			++cou;
			res = 1;
			for (auto i : list) res *= comb[map[i.first]][i.second];
			ans += res;
		}
		else break;
	}
	out << std::fixed << std::setprecision(6);
	out << (long double)sum / cou << std::endl << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int n,i,b,c,j;
  char a[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    int rui[5]={0},point=0,out=0;
    while(1){
      scanf("%s",&a);
      if(strcmp(a,"OUT")==0){
	out++;
	if(out==3)goto exit;
      }
      else if(strcmp(a,"HOMERUN")==0){
	point++;
	for(j=1;j<=4;j++){
	  if(rui[j]==1) point++;
	  rui[j]=0;
	}
      } else {
	for(j=3;j>0;j--){
	  if(rui[j]==1){
	    rui[j]=0,rui[j+1]=1;
	  }
	}
	if(rui[4]==1)point++,rui[4]=0;
	rui[1]=1;
      }
    }
  exit:
    printf("%d\n",point);
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
#define INF (1e18)
typedef long long ll;
using namespace std;

int main(){
  ll n;
  ll X;
  cin>>n>>X;

  ll x[n+1]={};
  ll s[n+1]={};
  for(int i=1;i<=n;i++){
    cin>>x[i];
    s[i]=s[i-1]+x[i];
  }

  ll sum=0;
  for(int i=1;i<=n;i++){
    sum+=x[i]*5+X;
  }
  ll ans=sum;
  for(int i=1;i<=n;i++){
    ll tmp=0;
    tmp+=5*(s[n]-s[n-i]);
    ll u=5;
    for(int j=n-i;j>0;j-=i){
      if(j-i<0) tmp+=u*(s[j]);
      else tmp+=u*(s[j]-s[j-i]);
      u+=2;
    }
    tmp+=i*X;
    if(tmp<0) continue;
    //cout<<tmp<<endl;
    ans=min(ans,tmp);
  }

  cout<<ans+n*X<<endl;



  return 0;
}


Measured memory_bytes: 3328
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
from math import floor
def main():
    n, c, k = map(int, input().split())
    times = defaultdict(int)
    for _ in range(n):
        times[int(input()) + k] += 1
    # ts:時間順に「時間ごとの出発したい人数」を並べたもの
    ts = dict(sorted(times.items()))

    r = 0
    busg = c # バスに乗せられる人数
    busstart = - k - 1
    for tse in ts:
        if busstart + k < tse: # 前のバスに間に合わない場合。バスを仕立てる
            r += floor(ts[tse] / c) # 満員になるバス台数を+する。
            nokori = ts[tse] % c
            if nokori: # 残りがいるならバスを仕立てる。
                r += 1
                busg = c - nokori
                busstart = tse
            else:
                busstart = -k - 1
        else:
            if busg >= ts[tse]: #バスに乗りきれる場合
                busg -= ts[tse]
            else:             # バスに乗り切れない場合。バスを仕立てる。
                r += floor(ts[tse] / c)
                nokori = ts[tse] % c
                if nokori:
                    r += 1
                    busg = c - nokori
                    busstart = tse
                else:
                    busstart = -k - 1
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 107372
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    let N = parseInt(input[0]);
    
    input.shift();
    
    let case_num = {
        "ac": 0,
        "wa": 0,
        "tle": 0,
        "re": 0
    };
    
    let S = input.forEach(value => {
        
        switch(value) {
            case "AC":
                case_num.ac++;
                break;
            case "WA":
                case_num.wa++;
                break;
            case "TLE":
                case_num.tle++;
                break;
            case "RE":
                case_num.re++;
                break;
        }
        
    });
    
    console.log("AC x " + case_num.ac);
    console.log("WA x " + case_num.wa);
    console.log("TLE x " + case_num.tle);
    console.log("RE x " + case_num.re);
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36492
#include <bits/stdc++.h>

using namespace std;

int n, maxi;
int chk[110];
int arr[110];

bool good() {
    int i;
    for (i=0;i<=maxi;i++) {
        if (chk[i]<0) return false;
    }
    for (i=0;i<=(maxi+1)/2;i++) if (chk[i]!=0) return false;
    return true;
}

int main() {
    int i;

    scanf("%d",&n);
    for (i=0;i<n;i++) {
        scanf("%d",&arr[i]);
        maxi = max(maxi,arr[i]);
        chk[arr[i]]++;
    }
    for (i=0;i<=maxi;i++) {
        chk[max(i,maxi-i)]--;
    }
    if (good()) printf("Possible\n");
    else printf("Impossible\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


ll N,X,M;
llvec v;
map<ll,int> mp;

void input() {
	cin>>N>>X>>M;
}

void solve() {
	v.pushb(0);
	v.pushb(X);
	mp[X]=1;
	for(int i=2; i<=N; i++) {
		ll A = (v[i-1]-v[i-2])*(v[i-1]-v[i-2])%M;
		if(A==0) {
			cout<<v[i-1]<<endl;
			return;
		}
		auto itr = mp.find(A);
		if(itr != mp.end()) {
			int pos = itr->second;
			cout<<v[i-1]+(N-i+1)/(i-pos)*(v[i-1]-v[pos-1])+(v[(N-i+1)%(i-pos)+pos-1]-v[pos-1])<<endl;
			return;
		}
		v.pushb(v[i-1]+A);
		mp[A]=i;
	}
	cout<<v[v.size()-1]<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 6696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    string s;
    cin >> s;
    stack<char> stk;
    rep (i, s.size()) {
        switch (s[i]) {
            case 'S':
                stk.push('S');
                break;
            case 'T':
                if (stk.empty() || stk.top() == 'T') {
                    stk.push('T');
                } else {
                    stk.pop();
                }
        }
    }
    cout << stk.size() << endl;
}

Measured memory_bytes: 644
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[101], p[101], des[202];
  scanf("%s %s", s, p);

  strcat(des, s);
  strcat(des, s);

  printf("%s\n", strstr(des, p)!=NULL ? "Yes": "No");
  return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            char op = sc.next().charAt(0);
            int b = sc.nextInt();
            if (op == '+'){
                System.out.println(a+b);
            }else if(op == '-'){
                System.out.println(a-b);
            }else if(op == '*'){
                System.out.println(a*b);
            }else if(op == '/'){
                System.out.println(a/b);
            }else{
                break;
            }
        }
    }
}


Measured memory_bytes: 26420
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    const i64 MOD=1000000007;
    modint(i64 a_=0){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a,MOD=_.MOD;
    while(b){
        if(b&1) (n*=A)%=MOD;
        (A*=A)%=MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

class FSmallProducts {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,m;
        in>>n>>k;
        m=(int)sqrt(n);
        vector<modint> c(2*m),s(2*m+1),ns(2*m+1);
        fr(i,m) c[i]=1,c[i+m]=n/(m-i)-n/(m-i+1);
        if(n/m==m) c[m]-=1;
        s[0]=1;
        fr(_,k){
            ifr(i,2*m) ns[i]=ns[i+1]+(s[0]-s[2*m-i])*c[i];
            s.swap(ns);
        }
        out<<s[0]<<endl;
    }
};

int main() {
    FSmallProducts solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
int main(){
    int n,d,x,a[100],ans=0;
    scanf("%d%d%d",&n,&d,&x);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j+=a[i]){
            ans++;
        }
    }
    printf("%d\n",ans+=x);
    return 0;
}

Measured memory_bytes: 128
from queue import Queue

n = int(input())
A = [[0 for i in range(n)] for j in range(n)]
d = [-1 for i in range(n)]

for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1

q = Queue()
q.put(0)
d[0] = 0

while not q.empty():
    u = q.get()
    # print('visited:', u)
    for v in range(n):
        # print(u, v)
        if A[u][v] == 1 and d[v] == -1:
            q.put(v)
            d[v] = d[u] + 1

# print('-========')
for i in range(n):
    print(i+1, d[i])


Measured memory_bytes: 6928
#include <iostream>
#include <stack>
using namespace std;
using ll=long long;
int main() {
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
    stack<ll>s;
    ll left[n],right[n];

    for(ll i=0;i<n;i++){
        while(!s.empty() && arr[s.top()]>arr[i]){
            s.pop();
        }
        if(s.empty()){
            left[i]=i+1;
        }
        else{
            left[i]=i-s.top();
        }
        s.push(i);
    }
    while(!s.empty())s.pop();
    for(ll i=n-1;i>=0;i--){    
        while(!s.empty() && arr[s.top()]>arr[i]){
            s.pop();
        }
        if(s.empty()){
            right[i]=n-i;
        }
        else{
            right[i]=s.top()-i;
        }
        s.push(i);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans+=(left[i]*right[i]*arr[i]);
    }
    cout<<ans;

}


Measured memory_bytes: 9940
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int debu(string a)
{
	cout<<a<<endl;
}
int debu()
{
	cout<<"ok"<<endl;
}
int debu(int a)
{
	cout<<a<<endl;
}




int main()
{
	int ans=0;
	int c;
	int a[6]={1,5,10,50,100,500};
	rep(i,6)
	{
		cin>>c;
		ans+=a[i]*c;
	}
	if(ans>=1000)
	{
		cout<<1<<endl;
	}
	else
	{
		cout<<0<<endl;
	}

}

Measured memory_bytes: 1160