akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
//------------------------????????????????????£?¨?
struct CARDS{
	char mark;
	int number;
	int value;
};
void BubbleSort(vector<CARDS> C, int N);
void SelectionSort(vector<CARDS> C, int N);
bool checkStable();
void outputResult(bool result);
void outputVector(vector<CARDS> C);

//-------------------------???????????¢??°
int main(){
	//??\???
	int N ;
	cin >> N;
	vector<CARDS> card;
	card.resize(N);
	for(int i=0; i< N; i++){
		cin >> card[i].mark;//S,H,C,D???0~3
		cin >> card[i].number;
	}
//   	outputVector(card);
	//??????????????????
	BubbleSort(card, N);
	//???????????????
	SelectionSort(card, N);
	return 0;
}
//------------------------
bool checkStable(vector<CARDS> CARD, vector<CARDS> Result, int N){
    for(int i=0; i< N ; i++){
        for(int j=i+1; j< N ; j++){
            for(int k=0; k< N ; k++){//????????????????????¨?????????
                for(int m=k+1; m< N ; m++){//????????????????????¨?????????
                    if( (CARD[i].number == CARD[j].number) &&
                        (CARD[i].mark   == Result[m].mark) &&
                        (CARD[i].number == Result[m].number) &&
                        (CARD[j].mark   == Result[k].mark) &&
                        (CARD[j].number == Result[k].number)){
                            return false;
                    }
                }
            }
        }
	}
	return true;
}
//------------------------
void BubbleSort(vector<CARDS> C, int N){
	
	vector<CARDS> P = C;
	for(int i =0; i<N; i++){
		for(int j=(N-1);  j>=(i+1) ; --j){
			if( C[j].number < C[j-1].number){
				CARDS temp  = C[j];
				C[j]        = C[j-1];
				C[j-1]      = temp;
			}
		}
	}
	outputVector(C);
	//??????
    bool result = false;
    result = checkStable(P, C, N);
	outputResult(result);

	return ;
}
//------------------------
void SelectionSort(vector<CARDS> C, int N){
	vector<CARDS> P = C;
	for(int i=0; i<N; i++ ){
		int minj = i;
		for(int j=i; j<=(N-1) ;j++){
			if( C[j].number < C[minj].number){
				minj = j;
			}
		}
		CARDS temp  = C[i];
		C[i]        = C[minj];
		C[minj]     = temp;
	}
	outputVector(C);
	//??????
    bool result = false;
    result = checkStable(P, C, N);
	outputResult(result);

	return ;
}
//------------------------
void outputResult(bool result){
	if(result){
		cout << "Stable" << endl;
	}else{
		cout << "Not stable" << endl;
	}

}
//----------------------
void outputVector(vector<CARDS> C){
	for(int i =0; i< C.size(); i++){
		cout << C[i].mark;
		cout << C[i].number;
		if(C.size()-i-1){
			cout << " " ;
		}
	}
	cout << endl ;
}

Measured memory_bytes: 3152
#include <iostream>
#include <cstdio>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;



int n,k;

int const MAXN = 510000;


long long fac[MAXN], finv[MAXN], inv[MAXN];
long long A[MAXN];

// テーブルを作る前処理
void init_fac(ll MOD){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
    for (int i = 2; i < MAXN; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll modcomb( int n, int k, ll MOD ){
	if( n < k )	return 0;
	if( n < 0 || k < 0 )	return 0;
	return fac[n] * ( finv[k] * finv[n-k] % MOD ) % MOD;
}

bool cmp_reverse( int a, int b ){
	return a > b;
}



int main(){
	ll const MOD = 1000000007L;
	init_fac(MOD);

	std::cin >> n >> k;

	for( int i = 1; i <= n; i++ )
		std::cin >> A[i];

	

	ll maxsum = 0;
	ll minsum = 0;

	std::sort( A+1, A+1+n );
	for( int i = k; i <= n; i++ ){
		// maxsum = ( maxsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
		maxsum = maxsum + ( A[i] * modcomb(i-1,k-1,MOD) ) % MOD;
		maxsum %= MOD;
		// printf("maxsum = %lld\n", maxsum);
	}

	std::sort( A+1, A+1+n, cmp_reverse );
	for( int i = k; i <= n; i++ ){
		// minsum = ( minsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
		minsum = minsum + ( A[i] * modcomb(i-1,k-1,MOD) ) % MOD;
		minsum %= MOD;
	}
	
	// printf("maxsum = %lld, minsum = %lld\n", maxsum, minsum );
	std::cout << (maxsum - minsum + MOD) % MOD << std::endl;
}


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

int main(){
    string s;
    cin >> s;
    int a=0,b=0;

    for(int i = 0;i < s.size();i ++){
        if(i % 2 == 0 && s.at(i) == '0'){
            a ++;
        }else if(i % 2 == 1 && s.at(i) == '1'){
            a ++;
        }else if(i % 2 == 0 && s.at(i) == '1'){
            b ++;
        }else{
            b ++;
        }
    }

    cout << min(a,b) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e6+9; 
vector<int> dp(N,N);
void solve(){
    dp[1]=1;
    for(int i=2;i<N;i++){
        if(dp[i]<i) continue;
        for(int j=i;j<N;j+=i) dp[j]=min(dp[j],i);
    }
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	solve();
	int n;
	cin>>n;
	int a[n];
	int gcd,flag=1;
	map<int,int> mp1,mp2;
	for(int i=0;i<n;i++) cin>>a[i],mp1[a[i]]++;
	gcd=__gcd(a[0],a[1]);
	for(int i=2;i<n;i++) gcd=__gcd(a[i],gcd);
	for(int i=0;i<n;i++){
	    int k=a[i];
	    if(mp1[k]>1&&k!=1) flag=0;
	    //bitset<1000007> vis;
	    while(k>1){
	        if(mp2[dp[k]]) flag=0;
	        mp2[dp[k]]++;
	        int x=dp[k];
	        //cout<<dp[k]<<"\n";
	        k/=x;
	        while(k%x==0&&k>1) k/=x;
	    }
	    if(!flag) break;
	}
	if(flag) cout<<"pairwise coprime";
	else if(gcd==1) cout<<"setwise coprime";
	else cout<<"not coprime";
	return 0; 
	
}


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

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

    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int ans = 0;
    vector<bool> changed(N, false);
    for (int i = 1; i < N; i++) {
        if (a[i] == a[i - 1] and !changed[i - 1]) {
            ans++;
            changed[i] = true;
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;

namespace Nikkei2019_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine();
            var B = Console.ReadLine();
            var C = Console.ReadLine();

            var cnt = 0;
            for (int i = 0; i < N; i++)
            {
                if (A[i] == B[i] && A[i] == C[i]) continue;
                if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) cnt++;
                else cnt += 2;
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 11092
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

from collections import Counter
def main():
  ss = Counter(input() for _ in range(GI()))
  ts = Counter(input() for _ in range(GI()))

  for k in ss:
    if k in ts:
      ss[k] -= ts[k]

  print(max(max(ss.values()), 0))

main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define ll long long
using namespace std;
int dp[102][100003],n,mw,w[102],ar[102],ans ;
int fun(int id , int val)
{
    if(val==0) return 0 ;
    if(id==n) return 1000000009 ;
    if(dp[id][val]!=-1) return dp[id][val] ;
    int a=1000000009,b=1000000009;
    if(val-ar[id]>=0) a=w[id]+fun(id+1,val-ar[id]) ;
    b=fun(id+1,val) ;
    return dp[id][val]=min(a,b) ;
}
int main()
{
    memset(dp,-1,sizeof(dp)) ;
    cin>>n>>mw ;
    for(int i = 0 ; i < n ; i++) cin>>w[i]>>ar[i] ;
    for(int i = 1 ; i <= 100003 ; i++)
    {
        int x=fun(0,i) ;
     //   if(i==100003) cout<<x<<" "<<i<<endl ;
        if(x<=mw) ans=i ;
    }
    cout<<ans<<endl ;
}


Measured memory_bytes: 40064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];

    ll two = 1;
    while (a[0] % (two << 1) == 0)two <<= 1;

    bool same = true;
    for (int i = 1; i < n; i++) {
        if (!(a[i] % two == 0 && (a[i] / 2) % two != 0))same = false;
    }
    if (!same) {
        cout << 0 << endl;
        return 0;
    }

    ll lcm = a[0] / 2;
    for (int i = 1; i < n; i++) {
        ll gcd = __gcd(lcm, a[i] / 2);
        lcm /= gcd, lcm *= a[i] / 2;

        if (lcm > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (m - lcm) / (lcm * 2) + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
  int parent; 
  int left;
  int right;
}node_list;

void Preorder(node_list *,int);

void Inorder(node_list *,int);

void Postorder(node_list *,int);

int main(){
  int i,j,n,L,R,id;
  node_list *A;

  scanf("%d",&n);

  A = malloc(sizeof(node_list)*n);
  for(i=0;i<n;i++)A[i].parent = -1;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&L,&R);
    A[id].left = L;
    A[id].right = R;
    if(L != -1)A[L].parent = id;
    if(R != -1)A[R].parent = id;
  }
  for(i=0;i<n;i++)if(A[i].parent == -1)break;

  printf("Preorder\n");
  Preorder(A,i);
  printf("\n");
  
  printf("Inorder\n");
  Inorder(A,i);
  printf("\n");
  
  printf("Postorder\n");
  Postorder(A,i);
  printf("\n");
  free(A);
  return 0;
}
    
void Preorder(node_list *A,int i){
  printf(" %d",i);
  if(A[i].left != -1) Preorder(A,A[i].left);
  if(A[i].right != -1) Preorder(A,A[i].right);
}      
void Inorder(node_list *A,int i){
  if(A[i].left != -1) Inorder(A,A[i].left);
  printf(" %d",i);
  if(A[i].right != -1) Inorder(A,A[i].right);
}
void Postorder(node_list *A,int i){
  if(A[i].left != -1) Postorder(A,A[i].left);
  if(A[i].right != -1) Postorder(A,A[i].right);
  printf(" %d",i);
}
  
      



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

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

using namespace std;

int main() {
  int n;
  string s, t;
  std::cin >> n >> s >> t;

  int length = 0;
  rep(i, n) {
    if (s.substr(i) == t.substr(0, n - i)) {
      length = n + i;
      break;
    }
    length = n * 2;
  }

  std::cout << length << std::endl;

  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 100005
 
#define PI   3.14159265358979323846264338327950

#define PB push_back 
#define F first
#define S second
 
#define ll 	 long long int

#define mod  1000000007




int main()
{
	FAST;
	ll a, b;
	cin >> a >> b;
	if(a % 2 == 0 || b % 2 == 0){
		cout << "Even";
		return 0;
	}
	cout << "Odd";
	return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    if(n % 2 == 1){
        int c = n, t = 1;
        for(int i = 0; i < m; i++){
            cout << t << " " << c<< endl;
            t++;
            c--;
        }
    }else{
        int c = n, t = 1, u = m / 2;
        if(m % 2 == 0){
            u--;
        }
        for(int i = 0; i < m; i++){
            cout << t << " " << c<< endl;
            t++;
            c--;
            if(i == u){
                c--;
            }
        }
    }
}


Measured memory_bytes: 3600
N=int(input())
S=[str(input())for i in range(N)]
AC=0
WA=0
TLE=0
RE=0
for j in S:
    if j =='AC':
        AC+=1
    elif j=='WA':
        WA+=1
    elif j=='TLE':
        TLE+=1
    else:
        RE+=1
print('AC x',AC)
print('WA x',WA)
print('TLE x',TLE)
print('RE x',RE)

Measured memory_bytes: 16328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
#define MAXN 1000000007
 
 
int main() {
	ll b,h,m,s;
	cin>>b;
	m=b/60;
	s=b%60;
	h=m/60;
	m=m%60;
	cout<<h<<":"<<m<<":"<<s<<endl;
}
	



Measured memory_bytes: 3092
#include<stdio.h>

int main(void){
    long int l,r,i,j,temp,flag;
    flag=1;
    temp=2018;
    scanf("%ld%ld",&l,&r);

    if (r-l < 2019){
        for(i=l; i<r; i++){
            for(j=l+1; j<=r; j++){
                 if( i*j % 2019 < temp )
                 temp = i*j % 2019;
            }
        }

        printf("%ld\n",temp);
    }

    if( r-l >= 2019){
        for(i=l; i<r; i++){
            for(j=l+1; j<=r; j++){
                if( i*j % 2019 == 0){
                    temp=0,flag=0;
                    break;
                }
                else if( i*j % 2019 < temp )
                 temp = i*j % 2019;
            }
            if(flag==0)
            break;
        }
        printf("%ld\n",temp);
    }

    return 0;

}

Measured memory_bytes: 128
v = $<.read.split.map(&:to_i)
N, k = v.shift(2)
K = [N*2, k].min
res = 0
u = v+v

1.upto(K < N ? K : N) do |n|
	0.upto(K-n < n ? K-n : n) do |m|
		next if n == m
		0.upto(n) do|l|
#			p [n,m,t=u[N-l...N+n-l],t.max(n-m)]
			t = u[N-l...N+n-l].max(n-m).inject(:+)
			res = t if res < t
		end
	end
end
p res



Measured memory_bytes: 2640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    long long int n,i,j,k,c=0;

    //while(1)
    {
        c=0;
        cin>>n>>k;

        for(i=0;i<n;i++)
        {
            cin>>j;

            c=c+min(2*j,(k-j)*2);
        }

        cout<<c<<endl;

    }
return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if(a==b&&b!=c)
    printf("Yes");
  else if(a!=b&&b==c)
    printf("Yes");
  else if(a!=b&&c==a)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1728
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    char c; cin >> c;
    if ('A' <= c && c <= 'Z')print('A');
    else print('a');

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const ll MOD = 1e9 + 7;

ll frac(ll n)
{
    if (n == 0)
        return 1;
    return (n * frac(n - 1)) % MOD;
}

int main(int argc, char const *argv[])
{

    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    vector<vector<ll>> dp(256, vector<ll>(n + 1, 0));
    dp[0][0] = 1;
    rep(i, n)
    {
        auto next = dp;
        rep(j, 256)
        {
            int to = j ^ v[i];
            rep(j2, n)
            {
                next[to][j2 + 1] += dp[j][j2];
                next[to][j2 + 1] %= MOD;
            }
        }
        dp = next;
    }
    ll ans = 0;
    rep(i, n + 1)
    {
        ans += frac(i) * dp[k][i];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
int n,k,cnt[1000010];
ll ans;
int f(int i) {
	return cnt[i%k];
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(k);
	for (int i=1;i<=n;i++)
		cnt[i%k]++;
	for (int i=0;i<k;i++) {
		if ((2*(k-i))%k==0)
			ans+=(ll)f(i)*f(k-i)*f(k-i);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ss              second
#define ar              array
#define int             long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("ip1.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);
#endif
}

bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int32_t main()
{
  k_007();
  string s;
  string t;
  cin >> s;
  cin >> t;
  int cnt = 0;
  f(i, 3)
  {
    if (s[i] == t[i]) cnt++;
  }

  cout << cnt << endl;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
  return (a.second < b.second);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int prime(int n) {
  int flag = 1;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {flag = 0; break;}
  }
  return flag;
}
int power(int x, int y)
{
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
  else
    return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 100001
struct rect {
  long long int height;
  long long int pos;
};
long long int table[MAX];
long long int large_histogram(long long int w);
int main(void)
{
  long long int i, j, w, temp, max = 0;
  scanf("%lld", &w);
  for (i = 0; i < w; i++) scanf("%lld", &table[i]);
  temp = large_histogram(w);
  if (max < temp) max = temp;
  printf("%lld\n", max);
}
long long int large_histogram(long long int w)
{
  long long int i, sp = 0, max = 0;
  struct rect stack[MAX];
  table[w] = 0;
  for (i = 0; i <= w; i++) {
    struct rect r;
    r.height = table[i];
    r.pos = i;
    if (!sp || stack[sp-1].height < r.height) stack[sp++] = r;
    else if (stack[sp-1].height > r.height){
      long long int target = i;
      while (sp && stack[sp-1].height >= r.height) {
        struct rect pre = stack[--sp];
        long long int area = pre.height * (i - pre.pos);
        if (max < area) max = area;
        target = pre.pos;
      }
      r.pos = target;
      stack[sp++] = r;
    }
  }
  return max;
}


Measured memory_bytes: 4196
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n+1);
    long i;
    for(i=1; i<=n; i++) {
        scanf("%ld", &a[i]);
    }

    long curr=1;
    for(i=1; i<=n; i++) {
        if(curr==2) {
            printf("%ld\n", i-1); return 0;
        }
        curr=a[curr];
    }
    printf("-1\n");

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String b = sc.next();
		sc.close();

		if ("A".equals(b)) {
			System.out.println("T");

		} else if ("T".equals(b)) {
			System.out.println("A");

		} else if ("C".equals(b)) {
			System.out.println("G");

		} else if ("G".equals(b)) {
			System.out.println("C");
		}
	}
}


Measured memory_bytes: 21716
# include "iostream"
# include "cstdio"
# include "cstring" 

using namespace std;
 
const int maxm=100+10; 

bool  
    f[maxm],   //f[i]表示切割在j位置时1~j是否存在i字符 
    q[maxm];   //q[i]表示切割在j位置时j+1~n是否存在i字符 

int main(){
    int n, //字符串长度 
        now,  //当前不同字符数 
        ans;  //已知最大不同字符数(初始值为0) 
    register int i,j;
    char s[maxm]; 
    scanf("%d",&n);    //读入字符串的长度 
    scanf("%s",s);     //读入的字符串 
    for(i=0;i<n;i++){  //枚举切割点 
        f[s[i]-'a']=true;     
        //当前i位置的字符在f中标记为存在 
        memset(q,false,sizeof(q));    //初始化q数组 
        for(j=i+1;j<n;j++){   
            //当前j位置的字符在q中标记为存在 
            q[s[j]-'a']=true;  
        }
        now=0;    //初始化now 
        for(j=0;j<26;j++){
            if(f[j] && q[j]){    
                //如果两串中拥有相同字符那么记入到now中 
                now++; 
            } 
        } 
        ans=max(ans,now); 
        //若当前不同字符数大于已知不同字符则更新答案 
    }
    printf("%d",ans);  //打印答案 
    return 0; 
}

Measured memory_bytes: 256
n,m = map(int, input().split())
ab = []
for i in range(m):
    point = list(map(int, input().split()))
    ab.append(point)
ab.sort(key=lambda x:x[0], reverse=True)
ans = 0
right = 1e7
left = 0
for i in range(m):
    left = max(left, ab[i][0])
    right = min(right, ab[i][1])
    if left>=right:
        left=ab[i][0]
        ans +=1

    if i==m-1 and left<right:
        ans+=1
print(ans)



Measured memory_bytes: 29132
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 0;

	for (int i = 1; i <= n; i+=2) {
		int yaku = 0;
		for (int j = 1; j <= i; j++)
			if (i%j == 0)
				yaku++;
		if (yaku == 8)
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
li_a = list(map(int, input().split()))
li_d = list()
for idx, a in enumerate(li_a):
    if idx == (n - 1):
        li_d.append(abs(k - li_a[idx] + li_a[0]))
    else:
        li_d.append(abs(li_a[idx] - li_a[idx + 1]))
print(sum(li_d) - max(li_d))


Measured memory_bytes: 26420
using System;
class Program
{
    static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());

        var keta = x.ToString().Length;

        int ans = 0;
        
        if (keta == 2)
        {
            ans = 9;
        }
        else if (keta == 4)
        {
            ans = 900 + 9;
        }
        else if (keta == 6)
        {
            ans = 90000 + 900 + 9;
        }
        else if (keta == 1)
        {
            ans = x;
        }
        else if (keta == 3)
        {
            ans = x - 99 + 9;
        }
        else if (keta == 5)
        {
            ans = x - 9999 + 900 + 9;
        }
        Console.Write(ans.ToString());
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	string s1,s2;
	while(cin>>n){
		int ans1=0,ans2=0;
		for(int i=0;i<n;i++){
			cin>>s1>>s2;
			if(s1>s2)
				ans1+=3;
			else if(s1==s2){
				ans1++;
				ans2++;
			}else
				ans2+=3;
		}
		cout<<ans1<<" "<<ans2<<endl; 
	}
	return 0;
}


Measured memory_bytes: 3152
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>




int main() {
	
	int a, b, c;

	std::cin >> a >> b >> c;

	if (a < b && b < c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	//system("pause");
	return 0;
}


Measured memory_bytes: 3024
#include <iostream>

using namespace std;

int main()
{
	int i, j, k, N;
	cin >> N;

	for (i = 0; i * 4 <= N; i++) {
		for (j = 0; j * 7 <= N; j++) {
			if ((i * 4 + j * 7) == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef vector<int> vi;

int main(void) {
	ll L, N;
	cin >> L >> N;
	vector<ll> X(N, 0);
	REP(i, N) cin >> X[i];
	vector<ll> tl(N+10, 0L);
	vector<ll> tr(N+10, 0L);
	REP(i, N) tl[i+1] = X[i];
	REP(i, N) tr[i] = (L - X[i]);
	REP(i, N+1) tl[i+1] += tl[i];
	tr[0] = (L - X[0]);
	for(int i = N; i > 0; i--) tr[i-1] += tr[i];

	ll ans = 0L;
	REP(i, N) {
		int left = i, right = N - 1;
		ll res = 0L;
		int med = (right - left + 1) / 2;
		ll x = (tl[left + med] - tl[left]) * 2;
		res += x;
		ll y = (tr[right - med + 1] - tr[right+1]) * 2;
		res += y;
		left += med; right -= med; 
		if(left == right) res += X[left];
		else res -= (L - X[right+1]);
		ans = max(ans, res);
	}
	RREP(i, N) {
		int left = 0, right = i;
		ll res = 0L;
		int med = (right - left + 1) / 2;
		res += (tl[left + med] - tl[left]) * 2;
		res += (tr[right - med + 1] - tr[right+1]) * 2;
		left += med; right -= med;
		if(left == right) res += (L - X[right]);
		else res -= X[left-1];
		ans = max(ans, res);
	}
	cout << ans << endl;
}


Measured memory_bytes: 5504
import math

def distance(x1, y1, x2, y2):
    dx = x1 - x2
    dy = y1 - y2
    return (dx**2 + dy**2)**0.5

lh, lm, h, m = map(int, input().split())

PI = math.pi

hx = math.cos(PI * 2 * (60 * h + m) / 720) * lh
hy = math.sin(PI * 2 * (60 * h + m) / 720) * lh
mx = math.cos(PI * 2 * m / 60) * lm
my = math.sin(PI * 2 * m / 60) * lm

print("%.20f"%(distance(hx, hy, mx, my)))





Measured memory_bytes: 9520
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
mans = set()
b = 0
for b in range(2**n):
    ans = 0
    for i in range(n):
        if 1&(b>>i):
            ans += A[i]
    mans.add(ans)
for m in M:
    if m in mans:
        print("yes")
    else:
        print("no")


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

using namespace std;

#define f first
#define s second
#define pub push_back
#define pob pop_back

typedef vector<int> vi;
typedef vector<vi> graf;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> wgraf;

typedef vector<double> vd;
typedef pair<double,double> dd;
typedef vector<dd> vdd;

typedef uint64_t ui64;

vi a, b, c;

int main(){

	int n;
	cin >> n;

	a.resize(n);
	b.resize(n);
	c.resize(n-1);

	for(auto &x: a){
		cin >> x;
		x--;
	}

	for(auto &x: b)
		cin >> x;
	for(auto &x: c)
		cin >> x;
	c.push_back(0);

	int satisfaction = 0;

	for(int i = 0; i < n; i++){

		satisfaction += b[a[i]];

		if(i > 0 && a[i] == a[i-1]+1){
			satisfaction += c[a[i-1]];
		}

	}

	cout << satisfaction << endl;
			

	return 0;
}


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

int main(){
  int n; cin >> n;
  map<int, int> mp;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto p: mp){
    int k = p.first;
    int tmp = p.second;
    if(k < tmp) ans += tmp-k;
    else if(k > tmp) ans += tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4736
using System;
 
namespace _135C
{
    class Program
    {
        static void Main(string[] args){
            var n = long.Parse(Console.ReadLine());
            var sqrt = (int)Math.Ceiling(Math.Sqrt(n));
            long min = long.MaxValue;
            for (int i = 1; i <= sqrt; i++)
            {
                if (n % i == 0) min = Math.Min(min, i + n / i - 2);
            }
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define mp make_pair
#define pb push_back
#define fro(i,a,b)for(int i(a);i<(b);i++)
#define rep(i,n)fro(i,0,n)
const long long INF=1e9;
int a,b,ans;
int main(){
	cin>>a>>b;
	rep(i,2){
		if(!i)ans=a+b;
		else if(i)ans=a*b;
		if(ans==15){
			if(!i)cout<<"+"<<endl;
			else cout<<"*"<<endl;
			return 0;
		}
	}
	cout<<"x"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/* 選択ソート */
int selectionSort(int A[], int N){
    int i, j, minj, t, sw = 0;
    for(i = 0; i < N-1; i++){
        minj = i;
        for(j = i; j < N; j++){
            if(A[j] < A[minj]) minj=j;
        }
        t = A[i];
        A[i] = A[minj];
        A[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
}


int main(){
    int A[100], N, sw, i;
    scanf("%d", &N);
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
    sw = selectionSort(A, N);
    for(i = 0; i < N; i++){
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    return 0;

    scanf("%d", &N);
}


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

struct Point
{
	double x, y;
	Point () {}
	Point (double x, double y) : x(x), y(y) {}

	Point operator + ( const Point &d ) const
	{
		return ( Point(x + d.x, y + d.y) );
	}

	Point operator - () const 
	{
		return ( Point(-x, -y) );
	}

	Point operator - ( const Point &d ) const
	{
		return ( *this + -d );
	}

	Point operator * ( double r ) const
	{
		return ( Point(r * x, r * y) );
	}

	Point operator / ( double r ) const
	{
		return ( Point(x / r, y / r) );
	}
	
	Point rotate(double angle)
	{
		return ( Point(cos(angle) * x - sin(angle) * y, sin(angle) * x + cos(angle) * y) );
	}

	void output()
	{
		printf("%.8f %.8f", x, y);
	}

	void outputln()
	{
		output();
		putchar('\n');
	}
};

void KochCurve(Point a, Point b, int n)
{
	if ( n > 0 ) {
		Point s = a + (b - a) / 3.0;
		Point t = a + (b - a) / 3.0 * 2.0;
		Point u = s + (t - s).rotate(M_PI / 3.0);

		KochCurve(a, s, n - 1);
		s.outputln();
		KochCurve(s, u, n - 1);
		u.outputln();
		KochCurve(u, t, n - 1);
		t.outputln();
		KochCurve(t, b, n - 1);
	}
}
int main()
{
	int n;

	cin >> n;

	Point(0, 0).outputln();
	KochCurve(Point(0, 0), Point(100, 0), n);
	Point(100, 0).outputln();

	return ( 0 );
}



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

int main() {

  int a,i,p,x,y;
	cin >>  a;
  vector<int> vec(a);
  for (i = 0; i < a; i++) {
    cin >> vec.at(i);
  }

	p=0;
	for(i = 0; i < a; i++) {
   	x=vec.at(i)%2;
	y=i%2;
	if(x==1 && y==0){
	p=p+1;
	}
  }
	cout << p << endl;

}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
//桁
int kt(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b;
  cin>>a>>b;
  int c=a-2*b;
  if(c<0)
  cout<<0;
  else
    cout<<c;
}

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

using namespace std;

void bye(int x) {
  //cout << x + 1 << " ";
  puts("No");
  exit(0);
}

bool odd(char x) {
  return x != 'R';
}

bool even(char x) {
  return x != 'L';
}

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      if (!even(s[i])) bye(i);
    } else {
      if (!odd(s[i])) bye(i);
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B
 */
/**
 * Result: AC
 * TC: O(N^2)
 * SC: O(N)
 */
import java.util.Scanner;

public class Main {

    int capacity;
    int n;
    int[] cost;
    int[] value;
    int[] rowCurr;
    Scanner in = new Scanner(System.in);

    boolean readCase() {
        while (in.hasNext()) {
            n = in.nextInt();
            capacity = in.nextInt();
            cost = new int[n];
            value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = in.nextInt();
                cost[i] = in.nextInt();
            }
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Main main = new Main();
        while (main.readCase()) {
            main.solve();
        }
    }

    void solve() {
        rowCurr = new int[capacity + 1];
        for (int numOfItems = 1; numOfItems <= n; numOfItems++) {
            for (int weight = capacity; weight >= cost[numOfItems - 1]; weight--) {
                if (weight >= cost[numOfItems - 1]) {
                    rowCurr[weight] = Math.max(
                            rowCurr[weight - cost[numOfItems - 1]] + value[numOfItems - 1],
                            rowCurr[weight]);
                }
            }
        }
        System.out.println(rowCurr[capacity]);
    }
}

Measured memory_bytes: 27080
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
const int inf = 1e9;
const int limit = 1e5;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b){
    return make_pair(a.first +b.first, a.second +b.second);
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        
        vector<int> p(n);
        for(int i=0; i<n; i++) cin >> p[i];

        vector<pair<int, int> > dp(limit, make_pair(-1,-1));
        dp[0] = make_pair(0,0);
        for(int i=0; i<n; i++){
            vector<pair<int, int> > ndp(limit, make_pair(-1,-1));
            for(int j=0; j<limit; j++){
                if(dp[j].first == -1) continue;
                ndp[j] = max(ndp[j], dp[j]);
                int ch = (1000 -(p[i]%1000)) %1000;
                ndp[j+ch%500] = max(ndp[j+ch%500], dp[j] +make_pair(ch/500, -p[i]));
                if(ch < 500 && ch +j >= 500){
                    ndp[j-(500-ch)] = max(ndp[j-(500-ch)], dp[j] +make_pair(1, -p[i]));
                }
            }
            dp = ndp;
        }

        int ansn=0, ansp=0;
        for(int i=0; i<limit; i++){
            if(dp[i].first >= ansn){
                if(dp[i].first != ansn){
                    ansp = -dp[i].second;
                }else{
                    ansp = min(ansp, -dp[i].second);
                }
                ansn = dp[i].first;
            }
        }
        cout << ansn << " " << ansp << endl;
    }
    return 0;
}


Measured memory_bytes: 4496
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

int main() {
    

    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long int N, M;
    cin >> N >> M;
    
    if(N>1 && M>1) {
        cout << (N-2)*(M-2) << endl;
    } else if(N>1) {
        cout << N-2 << endl;
    } else if(M>1) {
        cout << M-2 << endl;
    } else {
        cout << 1 << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){

  int x;
  cin>>x;
  int mx=1;
  rep(i,1,x+1){
    rep(j,2,10){
      int z=pow(i,j);
      if(z<=x) mx=max(mx,z);
    }
  }
  cout<<mx<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 4152
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-06-08 14:13:26
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

int n , m , par[MAXN] , sz[MAXN] , dist[MAXN * 3];
vector<pii> E[MAXN];
vector<int> comp[MAXN] , adj[MAXN * 3];

int Find(int v){
    return (par[v] == -1 ? v : par[v] = Find(par[v]));
}

void Union(int v , int u){
    v = Find(v) ; u = Find(u);
    if(v == u)  return;
    if(sz[v] < sz[u])   swap(v , u);
    par[u] = v ; sz[v] += sz[u];
    for(int i : comp[u])    comp[v].push_back(i);
    comp[u] = {};
    comp[u].shrink_to_fit();
}

void BFS(int v){
    fill(dist , dist + MAXN * 3 , MOD);
    queue<int> Q; dist[1] = 0; Q.push(1);
    while(!Q.empty()){
        int v = Q.front() ; Q.pop();
        for(int u : adj[v]){
            if(dist[u] == MOD){
                dist[u] = dist[v] + 1;
                Q.push(u);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    fill(par , par + MAXN , -1);
    fill(sz , sz + MAXN , 1);

    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)   comp[i].push_back(i);
    for(int i = 0 , v , u , c ; i < m ; i++){
        cin >> v >> u >> c;
        E[c].push_back({v , u});
    }
    int cur = n + 1;
    for(int i = 0 ; i < MAXN ; i++){
        vector<int> vec;
        for(pii j : E[i]){
            int v = j.X , u = j.Y;
            Union(v , u);
            vec.push_back(v); vec.push_back(u);
        }
        sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
        for(int j : vec){
            if(Find(j) == j){
                for(int k : comp[j]){
                    adj[cur].push_back(k);
                    adj[k].push_back(cur);
                }
                cur++;
            }
        }
        for(int j : vec)    par[j] = -1 , sz[j] = 1 , comp[j] = {j} , comp[j].shrink_to_fit();
    }

    BFS(1);
    if(dist[n] == MOD)  return cout << -1 << endl , 0;
    cout << dist[n] / 2 << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 156160
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, p, q;
    cin >> n;
    vector<int> p1(n), p2(n);
    for(auto& i : p1) cin >> i;
    for(auto& i : p2) cin >> i;

    vector<int> a;
    for(int i = 1; i <= n; i++) a.push_back(i);
    int i = 0;
    do {
        i++;
        bool flg = true;
        for(int i = 0; i < n; i++) {
            flg &= (p1[i] == a[i]);
        }
        if( flg ) p = i;
        flg = true;
        for(int i = 0; i < n; i++) {
            flg &= (p2[i] == a[i]);
        }
        if( flg ) q = i;
    } while( next_permutation(a.begin(), a.end()) );
    cout << abs(p - q) << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	char S[27];
	int i,j;
	scanf("%s",S);
	for(i=0;i<27;i++){
		if(S[i]=='\0'){
			printf("yes\n");
			break;
		}
		for(j=i+1;j<27;j++){
			if(S[i]==S[j]){
				printf("no\n");
				return 0;			
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{int a;int b;cin>>a>>b;
if(a!=1&&b!=1){
if(a>b)
{cout<<"Alice";}
if(b>a)
{cout<<"Bob";}
if(b==a)
{cout<<"Draw";}
}
if(a==1||b==1)
{if(b==1&&a!=1)
{cout<<"Bob";}
if(a==1&&b!=1)
{cout<<"Alice";}
if(a==b)
{cout<<"Draw";}}
return 0;
}

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

int main()
{
    long long int n , a, b;
    
    cin>>n>>a>>b;
    long long int cnt=0;
    
        long long int x=n/(a+b);
        
        cnt = x*a + min(n%(a+b) , a);
        
    cout<<cnt<<endl;
  
    return 0;
}


Measured memory_bytes: 256
q,w,e=input,range,int
n,m=map(e,q().split())
V=n+m
par,sizes=[i for i in w(V)],[1]*V


def f(x):
    if x == par[x]:
        return x
    par[x] = f(par[x])
    return par[x]


def u(x, y):
    x, y = f(x), f(y)
    if x == y:
        return
    if sizes[x] < sizes[y]:
        x, y = y, x
    par[y] = x
    sizes[x] += sizes[y]


[u(i,l-1+n)for i in w(n)for l in [e(k)for k in q().split()][1:]]
print("NO"if len([i for i in w(n)if f(i)!=f(0)])>0 else"YES")


Measured memory_bytes: 12684
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 998244353;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int main() {
  int a, b, n, m;
  cin >> a >> b >> n >> m;
  // trace(n, m);
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  for (int i = a; i <= n; ++i) {
    for (int j = b; j <= m; ++j) {
      if (i == a && j == b) {
        dp[i][j] = 1;
        continue;
      }
      if (i - 1 >= a) {
        add(dp[i][j], 1LL * dp[i - 1][j] * j % MOD);
      }
      if (j - 1 >= b) {
        add(dp[i][j], 1LL * dp[i][j - 1] * i % MOD);
      }
      if (i - 1 >= a && j - 1 >= b) {
        add(dp[i][j], MOD - 1LL * dp[i - 1][j - 1] * (i - 1) % MOD * (j - 1) % MOD);
      }
      // trace(i, j, dp[i][j]);
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}


Measured memory_bytes: 38292