akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[] = {-1,0,1,0,-1,-1,1,1};
const int dy[] = {0,-1,0,1,1,-1,1,-1};

int main(){
  int n; cin>>n;
  cout<<n<<":";
  bool judge=false;
  rep(i,100000){
    if(i==0||i==1) continue;
    while(n%i==0){
      n/=i;
      cout<<" "<<i;
      judge=true;
    }
    if(n==1){
      cout<<endl;
      return 0;
    }
  }
  if(!judge) cout<<" "<<n<<endl;
}



Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(10) << num << endl;
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int s,w; cin >> s >> w;
    if(s<=w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
 
// ------------------------------------------------------------------------------------------
int a, b, c;
int main()
{
    scanf("%d/%d/%d", &a, &b, &c);
    if (a < 2019) {
        cout << "Heisei" << endl;
    } else if (a > 2019) {
        cout << "TBD" << endl;
    } else if (b < 4) {
        cout << "Heisei" << endl;
    } else if (b > 4) {
        cout << "TBD" << endl;
    } else if (c <= 30) {
        cout << "Heisei" << endl;
    } else {
      cout << "TBD" << endl;
    }
    return 0;
}

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

typedef struct{
	int t;
	long long d;
}data;

int main(void){
	int n,k,kaburitop=0;
	long long dif=0;
	long long max=0,pt;
	data sushi[100000];
	data kaburi[100000];
	bool f[100000];

	cin>>n>>k;
	for(int i=0;i<n;i++){cin>>sushi[i].t>>sushi[i].d;sushi[i].t--;}
	sort(sushi,sushi+n,[](data a,data b){return a.d>b.d?true:false;});
	for(int i=0;i<k;i++){
		max+=sushi[i].d;
		if(f[sushi[i].t]==false){
			f[sushi[i].t]=true;
			dif++;
			}
		else kaburi[kaburitop++]=sushi[i];
	}
	max+=dif*dif;
	pt=max;
	for(int i=k;kaburitop>0&&i<n;i++){
		if(f[sushi[i].t]==false){
			f[sushi[i].t]=true;
			pt-=kaburi[--kaburitop].d+dif*dif;
			dif++;
			pt+=dif*dif+sushi[i].d;
			if(max<pt)max=pt;
		}
	}
	cout<<max<<endl;
	
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
vector<pair<int, int> > vp;
int vis[maxn],low[maxn],dfn[maxn];
int ind ;
vector<int> g[maxn];
void tarjan(int u,int p)
{
    dfn[u]=low[u]=++ind;
    vis[u]=1;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(v==p) continue;
        if(!vis[v])
        {
            tarjan(v,u);
            low[u]=min(low[v],low[u]);
            if(dfn[u]<low[v]) {
                int a = u, b = v;
                if (a > b) swap(a, b);
                vp.push_back(make_pair(a, b));
            }
        }
        else low[u]=min(low[u],dfn[v]);
    }
}
int v,e;
int main()
{
    scanf("%d%d",&v,&e);
    for(int i=0;i<e;i++)
    {
        int s,t;
        scanf("%d%d",&s,&t);
        g[s].push_back(t);
        g[t].push_back(s);
    }
    tarjan(0,-1);
    sort(vp.begin(), vp.end());
    for (int i = 0; i < vp.size(); i++)
        printf("%d %d\n", vp[i].first, vp[i].second);
    return 0;
}

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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    if ('A' <= s[0] && s[0] <= 'Z')
        cout << "A\n";
    else
        cout << "a\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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 (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

bool g[51][51];
int n, m, a[51], b[51];
bool used[51];
int ans;

bool dfs(int v) {
  used[v] = true;
  bool all_visited = true;
  rep(i, 0, n) if (!used[i]) all_visited = false;
  if (all_visited) return true;

  bool res = false;
  rep(i, 0, n) {
    if (!used[i] && g[v][i]) {
      res = dfs(i);
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, 0, m) {
      cin >> a[i] >> b[i];
      a[i]--, b[i]--;
      g[b[i]][a[i]] = g[a[i]][b[i]] = true;
    }
    
    rep(i, 0, m) {
      rep(j, 0, n) used[j] = false;
      g[a[i]][b[i]] = g[b[i]][a[i]] = false;
      if (!dfs(0)) ans++;
      g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import math
N = int(input())

result = sum(range(1,N+1))
#3

N_3 = math.floor(N/3)
result_3 = sum(range(1, N_3+1))*3

N_5 = math.floor(N/5)
result_5 = sum(range(1, N_5+1))*5

N_15 = math.floor(N/15)
result_15 = sum(range(1, N_15+1))*15

# print(result)
# print(result_3)
# print(result_5)
# print(result_15)

print(result - result_3 -result_5 + result_15)

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

#define REP( i, n) for( int i = 0; i < (n); ++i)
#define FOR( i, a, b) for( int i = (a); i < (b); ++i)

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){

  ll ans = 0;
  int n;
  int l,r;
  
  cin >> n;
  REP( i, n){
    cin >> l >> r;
    ans += r-l+1;
  }
  cout << ans << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> road(N, 0);
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    road.at(a-1)++;
    road.at(b-1)++;
  }
  for (int i=0; i<N; i++) cout << road.at(i) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n;
    cin >> n;
    string s;
    cin >> s;
    map<char,LL> cnt;
    for(char c: s){
        cnt[c] += 1;
    }
    LL ans = cnt['R'] * cnt['G'] * cnt['B'];
    for(LL i = 0; i < n; ++i){
        for(LL j = i+1; j < n; ++j){
            LL k = j + (j-i);
            if(k >= n) break;
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) --ans;
        }
    }

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



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int n;
    cin>>n;

    ll k;
    cin>>k;
        
    vector<ll> A;
    
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        A.push_back(a);
    }
    
    sort(A.begin(),A.end());
    
    ll fail=(-1e18);
    ll pass=(1e18);
    pass++;
    fail--;
    
    while(pass-fail>1LL)
    {
        ll mid = ll((fail+pass)/2LL);
        //cout << pass << " " << fail << endl;
    
        //cout << "trying " << mid << endl;
     
        // do there exist at least k terms <= mid ?
        
        ll cur=0LL;
        
        for(auto a:A)
        {
            if(a*a<=mid)
            {
                //cout << "sneaky bugga" << endl;
                cur--;
            }
            
            if(a<0)
            {
                int works=n;
                int dont=-1;
                
                while(works-dont>1)
                {
                    int mid2=int((works+dont)/2);
                    if(A[mid2]*a <= mid) works=mid2;
                    else dont=mid2;
                }
                
                cur += n-works;
                //cout << n-works << " ";
            }
            
            if(a==0)
            {
                if(mid>=0) cur+=n;
                //if(mid>=0) cout << n << " ";
            }
            
            if(a>0)
            {
                int works=-1;
                int dont=n;
                
                while(dont-works>1)
                {
                    int mid2=int((works+dont)/2);
                    if(A[mid2]*a <= mid) works=mid2;
                    else dont=mid2;
                }
                
                cur+=works+1;
                //cout << a << " " << works+1 << " ";
            }
            //cout << endl;
        }
        
        cur/=2;
        
        if(cur>=k) pass=mid;
        else fail=mid;
        
        //cout << mid << " " << cur << endl;
        //if(cur>=k) cout << "...worked" << endl;
        //else cout << "...didnt" << endl;
    }
    
    cout << pass << endl;
    
    //while
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std ;
const int N = 1e7 + 4;
void FastInputOutput()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline ll LLD()
{
    ll ret;
    scanf("%lld", &ret);
    return ret;
}
inline int D()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
void bin( int x )
{
    if(!x)
        return;
    bin( x / 2 );
    cout << x % 2 ;
}
bool checkPrimeNumber(int n)
{
    bool flag = true;
    for(int j = 2 ; j <= n ; ++j)
    {
        if (n % j == 0)
        {
            flag = false;
            break;
        }
    }
    return flag;
}
bool cmp(string last, string first)
{
    if(last.size() < first.size())
        return 1;
    return 0;
}
int calculateDigit(int n)
{
    double temp = (double)(n);
    double a = 0.39908-(0.434294 * n);
    double b = log10( n ) ;
    double c = ( n + 0.5 ) * b ;
    double ans = c - abs( a ) ;
    return ceil(ans) ;
}
int findDigits(int n)
{
    double E = 2.71828182845904523536;
    double PI = 3.141592654;

    if (n < 0)
        return 0;
    if (n <= 1)
        return 1;

    double x = ((n * log10(n / E) +
                 log10(2.0 * PI * n) /
                 2.0));

    return floor(x) + 1;
}
ll fact(ll n)
{
    ll ans = 1 ;
    for(ll i = 1 ; i <= n ; ++i)
        ans *= i ;
    return ans ;
}
unsigned long long Factorial(int n)
{
    const unsigned int M = 1000000007;
    unsigned long long f = 1;
    for (int i = 1; i <= n; i++)
        f = (f*i) % M;

    return f;
}
int a[ N ], b[ N ];
int arr[ N ], cm[ N ] ;
int n, k ;
int ans, ansL, ansR ;
bool can(int x)
{
    for(int i = 1, j = x ; j <= n ; ++j, ++i)
    {
        if(cm[ j ] - cm[i - 1] + k >= x)
        {
            ansL = i, ansR = j ;
            return true ;
        }
    }
    return false ;
}
int BS(int n)
{
    int low = 0, high = n ;
    while(low < high)
    {
        int mid = (low + high + 1) >> 1 ;
        if(can(mid))
            low = mid ;
        else
            high = mid - 1 ;
    }
    return low ;
}
int main()
{
    FastInputOutput() ;
    int n ;
    cin >> n ;
    if(n <= 2)
        cout << 0 << endl ;
    else
        cout << n / 3 << endl ;


}


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

int main() {
    int N, K;
    cin >> N >> K;
    int index_one;
    for (int i = 1; i <= N; i++){
        int a;
        cin >> a;
        if(a == 1){
            index_one = i;
        }
    }
    int ans;
    if((index_one < K) || (index_one + K - 1 > N)){
        ans = (N - 1 + K - 2) / (K - 1);
    }else if((N - 1) % (K - 1) == 0){
        ans = (N - 1) / (K - 1);
    }else{
    ans = (index_one - 1 + K - 2) / (K - 1) + (N - index_one + K - 2) / (K - 1);
    }
    cout << ans;
}


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

#define int long long

signed main(){
  int n;cin>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  int ans=0;
  for(int i=n-1;i>=0;i--)ans+=(b[i]-(a[i]+ans+b[i])%b[i])%b[i];
  cout<<ans<<endl;
}


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

bool comp( pair<ll,ll> a , pair<ll,ll> b){
    return atan2((double)a.second,a.first) <atan2((double)b.second,b.first);    
}

int main(){
    ll n,a,b;cin>>n;
    vector<pair<ll,ll> >v;
    for(ll i=0;i<n;i++){
        cin>>a>>b;
        v.push_back({a,b});
    }
          
    sort(v.begin(),v.end(),comp); 
    ll sum=0,x,y,temp;
    
    for(ll i=0;i<n;i++){
      x=v[i].first;
      y=v[i].second;
      temp=x*x+y*y;
      sum= max(sum,temp);
      
      ll j=(i+1)%n;
    while(j!=i){
       x+= v[j].first;
       y+= v[j].second;
       temp=x*x+y*y;
       sum=max(sum,temp);
       j=(j+1)%n;
     }
    }
    
    double res=sqrtl(sum);
    cout<<fixed<<setprecision(13)<<res<<endl;
    return 0;
}

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

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

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll N    = 1e5 + 10;
const ll MOD  = 1e9 + 7;
const ll INF  = 1e18;

int n, mark[N];
vector<int> adj[N];

void DFS(int u, int p) {
    for (int v : adj[u]) if (v != p) {
        DFS(v, u);
        mark[u] += (mark[v] == 0);
    }
    if (mark[u] >= 2) {
        cout << "First" << endl;
        exit(0);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    DFS(1, 0);
    cout << (mark[1] ? "Second" : "First") << endl;
    return 0;
}


Measured memory_bytes: 9568
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

int main(void){
    int n, k;
    cin >> n >> k;

    v_ll h(n+1);
    
    irep2(i, 1, n) {
        cin >> h[i];    
    }

    v_ll cost(n+5, INF);
    cost[1] = 0;

    irep2(i, 1, n) {
        irep2(j, 1, k) {
            cost[i+j] = min(cost[i+j], cost[i] + abs(h[i] - h[i+j]));
        }
    }
    //for(auto c : cost) { cout << c << " "; } cout << endl;
    cout << cost[n] << endl;

	return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#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--)


void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}


int32_t main() {


	int n, k;
	cin >> n >> k;

	mk(p, n, int);
	for (int i = 0 ; i < n ; i++) {
		cin >> p[i];
	}
	sort(p, p + n);
	int cost = 0;
	for (int i = 0 ; i < k ; i++) {
		cost += p[i];
	}
	cout << cost;






	return 0;
}

Measured memory_bytes: 3640
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>
#include<cmath>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N ;
char str[26];
std::map<char,int> M ;
/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  int A,B,K ;
  cin >> A >> B >> K ;
  for(int i = A ; i <= B ; i++){
    if(i <= A+(K-1) || i >= B-(K-1) ){
      cout << i << endl;
    }

  }

  if (DEBUG){
    std::printf("******debug********\n");

    std::printf("******debug********\n");
  }
  return 0 ;
}

Measured memory_bytes: 256
# abc 153
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N, K = map(int, readline().split())
H = list(map(int, readline().split()))
H.sort()

if K == 0:
    answer = sum(H)
else:
    answer = sum(H[:-K])
print(answer)

Measured memory_bytes: 21988
#方針: 753数を全列挙
n = gets.to_i

list = ["7","5","3"]
ary = []

(3..9).each do |digit|
  (0..3**digit-1).each do |bit|
    tmp = ""
    (0..bit.to_s(3).rjust(digit,"0").length-1).each do |i|
      tmp += list[bit.to_s(3).rjust(digit,"0")[i].to_i]
    end
    ary << tmp
  end
end

ary.each_with_index do |num, i|
  f7=f5=f3 = false
  num.chars do |c|
    case c
    when "7"
      f7=true
    when "5"
      f5=true
    when "3"
      f3 = true
    end
    if f7&&f5&&f3
      ary[i]  = [num,true]
    else
      ary[i] = [num,false]
    end
  end
end

ans = 0
ary.each do |a|
  if a[0].to_i <= n && a[1] == true
    ans+=1
  end
end
p ans

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

int main()
{
    int A,B;
    cin>>A>>B;

    if(A<=5)
        cout<<0<<endl;
    else if(A>=13)
        cout<<B<<endl;
    else
       cout<<int(B/2)<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int tik[100099];
int cnt[100099];
int main()
{

    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        ++cnt[l];
        if(r<n)--cnt[r+1];
    }
    long long ti=0;
    for(int i=1;i<=n;i++)
    {
        ti+=cnt[i];
        tik[i]=ti;
    }
    long long ok=0;
    for(int i=1;i<=n;i++)
    {
        if(tik[i]==m)++ok;
    }
    printf("%lld\n",ok);
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define for_each(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    string s;
    cin >> s;
    bool ok = true;
    rep(i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] != 'h')
                ok = false;
        } else {
            if (s[i] != 'i')
                ok = false;
        }
    }
    if (s.back() != 'i')
        ok = false;
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
import copy

def bubble(N, A):
    for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp

def select(N, A):
    for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp

def st(B, S):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True

N = int(input())
#カード入力
S = [i for i in input().split()]
B = copy.deepcopy(S)

bubble(N, B)
select(N, S)

print(" ".join(B))
print("Stable")
print(" ".join(S))
if st(B, S) == True:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 6348
import queue

k = int(input())
q = queue.Queue()
for i in range(1,10):
  q.put(i)

n = 0
while True:
  val = q.get()
  n += 1
  if n == k:
    print(val)
    break

  if val % 10 != 0:
    q.put(10 * val + (val % 10) - 1)
  q.put(10 * val + (val % 10))
  if val % 10 != 9:
    q.put(10 * val + (val % 10) + 1)
  
  

Measured memory_bytes: 12452
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)


int main(){
    ll MOD = pow(10, 9) + 7;
    int n, m;
    cin>>n>>m;
    ll x[n], y[m];
    FOR(i, 0, n) cin>>x[i];
    FOR(i, 0, m) cin>>y[i];
    ll x_times = 0, y_times = 0;
    FOR(i, 1, n+1){
        x_times += (i-1)*x[i-1] - (n-i)*x[i-1];
        x_times %= MOD;
    }
    FOR(i, 1, m+1){
        y_times += (i-1)*y[i-1] - (m-i)*y[i-1];
        y_times %= MOD;
    }
    ll ans = (x_times * y_times) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 1792
def gcd(a,b):

    c=max(a,b)
    d=min(a,b)
    while True:
        if c%d==0:
            break
        else:
            temp=c
            c=d
            d=temp%d
    return d

def two_gcd(x):
    if len(x)==2:
        return gcd(x[0],x[1])
    elif len(x)==1:
        return x[0]
    else:
        i=len(x)//2
        return gcd(two_gcd(x[:i]),two_gcd(x[i:]))

N,X=list(map(int,input().split()))

x=list(map(int,input().split()))

x1 = []

for i in range(N):
    x1.append(abs(x[i]-X))
    
print(two_gcd(x1))

Measured memory_bytes: 14480
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int L;
    int R;
    int d;
    int Y;
    int X;
    int pan;
    scanf("%d",&L);
    scanf("%d",&R);
    scanf("%d",&d);
    pan = L%d;
    X = L/d;
    Y = R/d;
    if (pan==0)
        printf("%d",Y-X+1);
    else printf("%d",Y-X);
    return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean firsr_win = false;
		for(int i=0;i<n;i++) {
			if(in.nextInt()%2==1) {
				firsr_win = true;
			}
		}
		System.out.println(firsr_win?"first":"second");
		in.close();
	}

}


Measured memory_bytes: 48160
import itertools


N = int(input())

P = "".join(input().split())
Q = "".join(input().split())

p_index = -1
q_index = -1
permutation_list = list(itertools.permutations([x + 1 for x in range(N)]))
for i in range(len(permutation_list)):
    param = "".join(map(str, permutation_list[i]))
    if P == param:
        p_index = i
    if Q == param:
        q_index = i
    if p_index != -1 and q_index != -1:
        print(abs(p_index - q_index))
        exit(0)


Measured memory_bytes: 46700
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
struct fk{int id,val;}stk[N<<1],p[N<<1];
int n,m,q,top;
bool on(int x,int y){return (x==n||y==m||x==0||y==0);}
int get(int x,int y){
    if(!x)return y;
    if(y==m)return m+x;
    if(x==n)return m+n+m-y;
    if(!y)return 2*m+2*n-x;
    return 0;
}
bool cmp(fk a,fk b){return a.val<b.val;}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1,x,y,xx,yy;i<=q;i++){
        scanf("%d%d%d%d",&x,&y,&xx,&yy);
        if(!on(x,y)||!on(xx,yy)){--i;--q;continue;}
        p[(i<<1)-1]=(fk){i,get(x,y)};
        p[(i<<1)]=(fk){i,get(xx,yy)};
    }
    sort(p+1,p+2*q+1,cmp);
    for(int i=1;i<=2*q;i++)
        if(!top||p[i].id!=stk[top].id)stk[++top]=p[i];
        else --top;
    puts(top?"NO":"YES");
}

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

int solve(std::string S)
{
    for (int i = 0; i < 3; i++)
    {
        if (S[i] == S[i + 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    puts("Good");
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int N, W; cin >> N >> W;
    int v[110], w[110];
    rep(i,0,N) cin >> v[i] >> w[i];

    // i ???????????§????????£????????? j ????????????????????????????°????
    int dp[110][10010] = {};
    repq(i,0,N) rep(j,0,10010) dp[i][j] = 3*(int)1e9;
    dp[0][0] = 0;
    if(w[0] <= W) dp[0][v[0]] = w[0];
    rep(i,1,N) {
        rep(j,0,10010) {
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if(j - v[i] >= 0 && dp[i-1][j-v[i]] + w[i] <= W)
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
            // if(dp[i][j] != 3*(int)1e9) printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
        }
    }
    int ans = 0;
    rep(j,0,10010) if(dp[N-1][j] < 3*(int)1e9) ans = j;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11696
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	vector<int> v;
	for(int i = 1; i <= 3; i++)
	{
		int x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	int ans = v[0] + v[1];
	cout << ans;
	return 0;
}

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

int main(){
	
	int i,n;
	int a[100];


	scanf("%d", &n);

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

Measured memory_bytes: 596
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <regex>
#include <sstream>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr int INF = 1e9 + 10;
constexpr ll INFL = 1e18 + 10;

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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

struct edge
{
public:
    int to;
    int cost;
};

// O(|E|(log|V|))
void dijkstra(std::vector<int> &dist, const std::vector<std::vector<edge>> &graph, int s)
{
    typedef std::pair<int, int> P;
    std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
    for (auto &e : dist)
    {
        e = INF;
    }

    dist[s] = 0;
    // P(distance from start, vertex index)
    pq.push(P(0, s));
    while (!pq.empty())
    {
        P cur = pq.top();
        pq.pop();
        int v = cur.second;
        int cost = cur.first;
        if (dist[v] < cost)
        {
            continue;
        }
        for (const auto &next : graph[v])
        {
            if (dist[next.to] > next.cost + dist[v])
            {
                dist[next.to] = next.cost + dist[v];
                pq.push(P(dist[next.to], next.to));
            }
        }
    }
}

void restorePath(
    std::vector<int> &path,
    const std::vector<int> &dist,
    const std::vector<std::vector<edge>> &graph,
    int e)
{
    int cur = e;
    path.push_back(e);
    while (dist[cur] != 0)
    {
        for (const auto &n : graph[cur])
        {
            if (dist[n.to] + n.cost == dist[cur])
            {
                path.push_back(n.to);
                cur = n.to;
                break;
            }
        }
    }
    std::reverse(path.begin(), path.end());
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

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

    string s;
    cin >> s;
    vector<int> count(26, 0);
    for (char c : s)
    {
        count[c - 'a']++;
    }
    for(int e : count){
        if (e % 2 == 1){
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes"
         << "\n";
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
#define N 200005
int n;
int a[N], b[N];

inline bool check(int x) {
    rep (i, 1, n * 2 - 1) b[i] = (a[i] >= x ? 1 : 0);
    if (b[n] == b[n - 1] || b[n]== b[n + 1]) return b[n];
    for (int l = n, r = n; l >= 1 && r <= 2 * n - 1; --l, ++r) {
        if (b[l] == b[l + 1]) return b[l];
        if (b[r] == b[r - 1]) return b[r];
    }
    return b[n] ^ (n % 2 == 0);
}

int main() {
    scanf ("%d", &n);
    rep (i, 1, n * 2 - 1) scanf ("%d", &a[i]);
    int l = 1, r = (n << 1) - 1, mid, ans;
    while (l <= r) {
        mid = l + r >> 1;
        if (check(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>

int main(){
    std::string str1, str2;
    std::cin >> str1 >> str2;

    std::string str3 = str1 + str1;

//    std::cout << str3.find(str2) << std::endl;

    if(str3.end() == std::search(str3.begin(), str3.end(), str2.begin(), str2.end())){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3212
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;

    vector<int> x(2*n);
    map<int, bool> y;
    rep(i, n){
        cin >> x[i];
        y[x[i]] = false;
    }
    rep(i, n){
        cin >> x[n+i];
        y[x[n+i]] = true;
    }
    sort(x.begin(), x.end());

    stack<int> a, b;
    int ans = 1;
    rep(i, 2*n){
        if(y[x[i]]){
            if(not a.empty()){
                ans *= a.size();
                ans %= MOD;
                a.pop();
                continue;
            }
            b.push(x[i]);
        }else{
            if(not b.empty()){
                ans *= b.size();
                ans %= MOD;
                b.pop();
                continue;
            }
            a.push(x[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15104
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    char buf[1<<10];
    size_t q;
    scanf("%s %zu", buf, &q);
    string str(buf);

    for (size_t i=0; i<q; ++i) {
        size_t a, b;
        scanf("%s %zu %zu", buf, &a, &b);
        string instr(buf);

        if (instr == "print") {
            printf("%s\n", str.substr(a, b-a+1).c_str());
        } else if (instr == "reverse") {
            reverse(str.begin()+a, str.begin()+b+1);
        } else if (instr == "replace") {
            scanf("%s", buf);
            string p(buf);
            str.replace(a, b-a+1, p);
        }
    }

    return 0;
}

Measured memory_bytes: 2816
import numpy as np

import copy
import math


def DFS(i, li, D, reached, mv, summ):
    if reached[i]:
        return

    for j in li:
        reached[i] = True

        if all(reached):
            reached[i] = False
            summ[0] += mv
            return

        li0 = copy.deepcopy(li)
        li0.remove(j)
        mv += D[i, j]
        DFS(j, li0, D, reached, mv, summ)
        mv -= D[i, j]
        reached[i] = False



def main():
    N = int(input())
    xy = np.zeros([N, 2])
    for i in range(N):
        xy[i, :] = list(map(int, input().split()))

    D = np.zeros([N, N])

    for i in range(N):
        for j in range(N):
            D[i, j] = np.sqrt((xy[i, 0] - xy[j, 0])**2 + (xy[i, 1] - xy[j, 1])**2) 

    reached = [False] * N

    li = list(range(N))

    summ = [0, 0]
    for i in range(N):
        s = i
        mv = 0
        DFS(s, li, D, reached, mv, summ)

    print(summ[0]/math.factorial(N))

        

main()


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

int main() {
  int N, K, ans;
  cin >> N >> K;
  std::map<int, int> m;
  int num, have;
  for (int i = 0; i < K; i++){
    cin >> num;
    for (int j = 0; j < num; j++){
      cin >> have;
      m[have] = 1;
    }
  }   
  cout << N - m.size() << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Range Set Counter
//-------------------------------------------------
template<typename T>
class RangeSet
{
private:
    ::std::vector<int> v;
    ::std::unordered_map<T, int> Map;
    ::std::vector<::std::vector<int> > data;
    int kind;
public:
    RangeSet(const ::std::vector<T> &v_):v(v_.size()){
        int sz = v_.size(); kind = 0;
        for(int i=0;i<sz;i++){
            T t = v_[i];
            if (Map.count(t)){
                data[Map[t]].push_back(i);
            }else{
                Map[t] = kind++;
                data.push_back(::std::vector<int>());
                data.back().push_back(i);
            }
            v[i] = Map[t];
        }
    }
    //query for all elements
    int query(T x){
        if (!Map.count(x)) return 0;
        return data[Map[x]].size();
    }
    //query for [a, b]
    int query(int a, int b, T x){
        if (a>b) return 0;
        if (!Map.count(x)) return 0;
        int xi = Map[x];
        auto right = ::std::upper_bound(data[xi].begin(),data[xi].end(),b);
        auto left  = ::std::lower_bound(data[xi].begin(),data[xi].end(),a);
        return right-left;
    }
    //search x for [k, tail]
    int find(int k, T x){
        if (!Map.count(x)) return -1;
        int xi = Map[x];
        auto itr = ::std::lower_bound(data[xi].begin(),data[xi].end(),k);
        if (itr!=data[xi].end()){
            return *itr;
        }else{
            return -1;
        }
    }
};

const int MOD = 2019;

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n = s.size();
    vi dp(n+1);
    int m=1;
    RFOR(i,n-1,0){
        int c=s[i]-'0';
        dp[i]=(dp[i+1]+c*m)%MOD;
        m=(m*10)%MOD;
    }

    RangeSet<int> rs(dp);
    ll ans=0;
    rep(i,n) ans+=rs.query(i+1,n,dp[i]);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 6432
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans;
    if (k % 2 == 0) {
        ans = a - b;
    } else {
        ans = b - a;
    }
    
    cout << ans << endl;
    
    return 0;
}



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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

ll n , k;

int main()
{
    _FastIO;
    cin >> n;
    ll x = 1;
    string s = "";
    while(n){
       if(n % abs(2 * x)){
            n -= x;
            s += '1';
       }
        else
            s += '0';
        x *= (-2);
    }
    reverse(s.begin() , s.end());
    if(s.empty()){
        cout << "0" << endl;
        return 0;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3664
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n: usize,
        ass: [usize;n],
    }
    let mut lights:Vec<usize> = vec![0;n];
    let mut ans = 0;
    let mut i = 0;
    loop{
        ans += 1;
        let a = ass[i];
        if ass[i] == 2 {
            println!("{}",ans);
            return;
        }    
        if lights[a - 1] == 1 {
            println!("-1");
            return;
        } 
        lights[a - 1] = 1;
        i = a - 1;
    }
    println!("-1");

}    


Measured memory_bytes: 6396
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vector<int> A(N), B(N), C(N), dpA(N), dpB(N), dpC(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i] >> C[i];
    }

    dpA[0] = A[0];
    dpB[0] = B[0];
    dpC[0] = C[0];
    for (int i = 1; i < N; i++) {
        dpA[i] = A[i] + max(dpC[i - 1], dpB[i - 1]);
        dpB[i] = B[i] + max(dpA[i - 1], dpC[i - 1]);
        dpC[i] = C[i] + max(dpB[i - 1], dpA[i - 1]);
    }

    int ans = max(dpA[N - 1], max(dpB[N - 1], dpC[N - 1]));

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


Measured memory_bytes: 2560
/*
 * ver0.1
 * どうすればいいねん
 * わからん
 */#include<stdio.h>
int main(void)
{
	int a,b,c,d,n,i;
	while(scanf("%d",&n)!=EOF){
		for(a=0;a<10;a++){
		for(b=0;b<10;b++){
		for(c=0;c<10;c++){
		for(d=0;d<10;d++){
			if(n==a+b+c+d)
				i++;
		}
		}
		}
		}
		printf("%d\n",i);
		i=0;
	}
	return 0;
}

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

using namespace std;

const int N = 100 + 7;
int n, b[N], a[N];


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

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        a[i] = (int) 1e9;
    }
    for (int i = 1; i < n; i++)
    {
        cin >> b[i];
        a[i] = min(a[i], b[i]);
        a[i + 1] = min(a[i + 1], b[i]);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans += a[i];
    }
    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		boolean ontToOne = true;
		Scanner sc = new Scanner(System.in);
		// 文字列の標準入力
		String s = sc.next();
		String t = sc.next();
		// 英小文字置換表の作成
		int[][] swap = new int[26][26];
		for(int i = 0; i < s.length(); i++) {
			swap[s.charAt(i) - 'a'][t.charAt(i) - 'a'] = 1;
		}
		// 2文字列間で英小文字が1対1で対応しているか
		for(int i = 0; i < 26; i++) {
			int sToT = 0;
			int tToS = 0;
			for(int j = 0; j < 26; j++) {
				// 文字列sから文字列tの置換パターンが存在するか
				if(swap[i][j] == 1) {
					sToT++;
				}
				// 文字列tから文字列sの置換パターンが存在するか
				if(swap[j][i] == 1) {
					tToS++;
				}
				// 置換パターンが1対1よりも存在するか
				if(sToT >= 2 || tToS >= 2) {
					ontToOne = false;
				}
			}
		}
		// 結果出力
		if(ontToOne) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 27924
N = int(input())
L = list(map(int, input().split()))

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            x = max(L[i], L[j], L[k])
            y = L[i] + L[j] + L[k]
            if x < y - x and (L[i] != L[j] and L[i] != L[k] and L[j] != L[k]):
                count += 1

print(count)


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

int main()
{
    string s;
    cin>>s;
    
    int l=s.length();
    if(s[l-1]=='s'){
    	cout<<s<<"es"<<endl;
	}else{
		cout<<s<<"s"<<endl;
	}
    
    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=100050;
int G[N],to[N<<1],nxt[N<<1],sz=-1,out[N],p[N];
bool f[N<<1],vis[N];
queue<int> Q,q;
inline void add(int u,int v){
	to[++sz]=v;nxt[sz]=G[u];G[u]=sz;
	to[++sz]=u;nxt[sz]=G[v];G[v]=sz;
}
inline void work(int u){
	int i,h,v;
	bool ok=0;
	memset(vis,0,sizeof(vis));
	while(!q.empty())q.pop();
	q.push(u);
	vis[u]=1;
	while(!q.empty()&&!ok){
		h=q.front();q.pop();
		for(i=G[h];i!=-1;i=nxt[i])if(!vis[v=to[i]]){
			vis[v]=1;
			p[v]=i;
			q.push(v);
			if(out[v]&1){ok=1;break;}
		}
	}
	while(v!=u){
		f[p[v]]^=1;f[p[v]^1]^=1;
		--out[to[p[v]^1]];++out[to[p[v]]];
		v=to[p[v]^1];
	}
}
int main(){
	int n,m,i,u,v;
	scanf("%d%d",&n,&m);
	if(m&1){
		puts("-1");
		return 0;
	}
	memset(G,-1,sizeof(G));
	for(i=0;i<m;++i){
		scanf("%d%d",&u,&v);
		add(u,v);++out[u];
	}
	for(i=1;i<=n;++i)if(out[i]&1)Q.push(i);
	if(Q.size()&1){
		puts("-1");
		return 0;
	}
	while(!Q.empty()){
		u=Q.front();Q.pop();
		if(out[u]&1)work(u);
	}
	for(i=0;i<m;++i)printf("%d %d\n",to[(i<<1)^1^f[i<<1]],to[(i<<1)^f[i<<1]]);
	return 0;
}

Measured memory_bytes: 4608