akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    VI P(N), Q(N); REP(i,N) cin >> P[i]; REP(i,N) cin >> Q[i];
    VI a(N); REP(i,N) a[i] = i+1;

    int j=1,aa;
    do{
        bool same = true;
        REP(i,N){
            if(a[i] != P[i]){
                same = false; break;
            }
        }
        if(same){aa = j; break;}
        j++;
    }while(next_permutation(a.begin(), a.end()));

    REP(i,N) a[i] = i+1;
    j=1;
    int bb;
    do{
        bool same = true;
        REP(i,N){
            if(a[i] != Q[i]){
                same = false; break;
            }
        }
        if(same){bb = j; break;}
        j++;
    }while(next_permutation(a.begin(), a.end()));

    cout << abs(aa-bb) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int N, M;
unordered_map<int, int> D;

int main() {
    cin >> N;
    for (int n = 0; n < N; n++) {
        int d; cin >> d;
        D[d]++;
    }

    cin >> M;
    for (int n = 0; n < M; n++) {
        int t; cin >> t;
        if (D.find(t) != D.end() && D[t] != 0) { D[t]--; }
        else { cout << "NO" << endl; return 0; }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 8564
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 1; i < n; ++i) {
        for (int j = i; j < n; j += i) {
            v[j]++;
        }
    }
    cout << accumulate(v.begin(),v.end(), 0LL) << "\n";
    return 0;
}

Measured memory_bytes: 7216
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383
#define pb push_back
#define all(s) s.begin(),s.end()


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

    for(int i=1;i<=n-1;i++){
        ans += ((n-1)/i);
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
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; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

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


Measured memory_bytes: 11592
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String coffee = scan.nextLine();
		
		if(coffee.charAt(4) == coffee.charAt(5) && coffee.charAt(2) == coffee.charAt(3)) {
			System.out.println("Yes");
			
		}else {
			System.out.println("No");
			
		}
		
		
	}
	
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        int sum = 0;
 
        for(int i =0 ; i< n; i++ ){
            a[i] = sc.nextInt();
        }
 
        for(int i = 0;i<n;i++){
            b[i] = sc.nextInt();
        }
 
        for(int i = 0;i<n-1;i++){
            c[i] = sc.nextInt();
        }
 
        for(int i = 0; i<n;i++){
            sum += b[a[i]-1];
            if(i>0 && a[i]==a[i-1]+1){
                sum+=c[a[i]-2];
            }
        }
 
        System.out.println(sum);
		
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include<string.h>
int main(void){
    char A[10],B[10],C[10];
    scanf("%s%s%s",A,B,C);
    if(A[strlen(A)-1]==B[0]&&B[strlen(B)-1]==C[0]){printf("YES");}
    else{printf("NO");}
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a % 500 <= b){
              System.out.println("Yes");
            } else {
              System.out.println("No");
            }
            }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


int main(void)
{
    IOS
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = 0;
    if (A <= B) {
        if (N == 1) {
            if (A == B) ans = 1;
        } else {
            ll n2 = N - 2;
            ans = B*n2 - A*n2+1;
        }
    }

    cout << ans << '\n';

    return 0;
}

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

#define fcout cout << fixed << setprecision(12) 

using std::cout;

void solve(int n, pair<double, double> x, pair<double, double> y) {
	if (n == 0) return;

	double sin60 = sqrt(3) / 2;

	double ax = (x.first * 2 + y.first) / 3;
	double ay = (x.second * 2 + y.second) / 3;
	double cx = (x.first + y.first * 2) / 3;
	double cy = (x.second + y.second * 2) / 3;

	pair<double, double> a{ax, ay};
	pair<double, double> c{cx, cy};
	pair<double, double> b{(cx - ax) / 2 - (cy - ay) * sin60 + ax, (cx - ax) * sin60 + (cy - ay) / 2 + ay};


	solve(n - 1, x, a);
	fcout << a.first << " " << a.second << endl;
	solve(n - 1, a, b);
	fcout << b.first << " " << b.second << endl;
	solve(n - 1, b, c);
	fcout << c.first << " " << c.second << endl;
	solve(n - 1, c, y);

}

int main() {
	int n; cin >> n;
	cout << "0 0" << endl;
	solve(n, {0, 0}, {100, 0});
	cout << "100 0" << endl;
}


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

ll N, A, B, K;
vector<ll> kaijo;
vector<ll> kaijoRev;

template <typename T>
T power(T x, T n, T mod)
{
    T ans = 1;
    while (n > 0)
    {
        if (n & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}


inline ll nCr(ll r)
{
    return (kaijo[N] * kaijoRev[r] % MOD) * kaijoRev[N - r] % MOD;
}

int main()
{
    cin >> N >> A >> B >> K;
    kaijo.resize(N + 1);
    kaijoRev.resize(N + 1);
    kaijo[0] = 1;
    kaijoRev[0] = 1;
    for (int i = 1; i <= N; i++) 
    {
        kaijo[i] = kaijo[i-1] * i % MOD;
        kaijoRev[i] = power(kaijo[i], MOD - 2, MOD);
    }

    ll ans = 0;
    for (ll x = 0; x <= N; x++)
    {
        ll y = (K - x * A) / B;
        if (x * A + y * B != K) continue;
        if (y > N || y < 0) continue;
        // cout << x << " " << y << endl;
        ans = (ans + nCr(x) * nCr(y)) % MOD;
        // cout << ans << endl;
    }
    // cout << kaijo[0] << " " << kaijo[1] << " " << nCr(0) << " " << nCr(1) << endl;
    cout << ans << endl;
    return 0;
}

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


int main () {
    int n ;
    cin >> n ;
    vector<int> d(n);
    rep(i, n){
        cin >> d[i];
    }
    int tot = 0;
    rep(i , n){
        rep(j , n){
            if (i == j){
                continue ;
            }
            else {
                tot += d[i] * d[j];
            }
        }
    }
    cout << tot / 2 << endl;

}


Measured memory_bytes: 256
N = int(input())
S = [int(input()) for _ in range(N)]

r = []
ans = 0
for i in range(N):
    ans += S[i]
    if S[i]%10!=0:
        r.append(S[i])

r.sort()
if ans%10==0:
    if len(r)>0:
        ans -= r[0]
    else:
        ans = 0

print(ans)



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[10000];
int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i, s.size()){
    if(s[i] == '+')ans++;
    else ans--;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m=0,max=0,a,b;
	cin>>n;
	for(int i=1;i<=n;i++){
		int j=n/i;
		if(i*j<n){
			m=m+j;
		}
		else m=m+j-1;
	}
	cout<<m<<endl;
	return 0;
} 

Measured memory_bytes: 3596
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

constexpr int MAX_N = 6, MAX_M = 10;

int n, x, m;
int l[MAX_M], r[MAX_M], s[MAX_M];
vector<int> lion;
vector<int> ans;
int mx = -1;

void dfs(int idx) {
	if(idx == n) {
		const int sum = accumulate(lion.begin(), lion.end(), 0);
		if(sum < mx) return;

		for(int i = 0; i < m; ++i) {
			if(accumulate(lion.begin() + l[i], lion.begin() + r[i], 0) != s[i]) {
				return;
			}
		}

		ans = vector<int>(lion);
		mx = sum;

		return;
	}

	for(int i = x; i >= 0; --i) {
		lion.push_back(i);
		dfs(idx + 1);
		lion.pop_back();
	}
}

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

	cin >> n >> x >> m;

	for(int i = 0; i < m; ++i) {
		cin >> l[i] >> r[i] >> s[i];
		--l[i];
	}

	dfs(0);
	if(mx >= 0) {
		for(int i = 0; i < n; ++i) {
			cout << ans[i] << (i == n - 1 ? "\n" : " ");
		}
	}
	else {
		cout << -1 << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
m,n = map(int,input().split())
a = 1000000007

def keisan(x, y):
    if y == 1:
        return x % a
    elif y % 2 == 0:
        return keisan(x, y/2)**2 % a
    else:
        return keisan(x, int(y/2))**2 * x % a

if n < 5:
    print(m**n)
else:
    ans = keisan(m, n)
    print(ans)


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

long long gcd(long long a, long long b) {
    if (a < b) {
        return gcd(b, a);
    }
    return b == 0 ? a : gcd(b, a%b);
}

bool solve(long long a, long long b, long long c, long long d) {
    if (a < b || d < b) {
        return false;
    }
    if (c >= b) {
        return true;
    }
    auto dv = gcd(d, b);
    long long mx = b + a%dv - dv;
    return mx <= c;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        long long a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << (solve(a, b, c, d) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  bool ok = false;
  for(int i=1; i<=100; i++) {
    if(a*i%b == c) ok = true;
  }
  cout << (ok ? "YES" : "NO") << "\n";
  return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for(int i = 0; i < N; i++){
    cin >> card.at(i);
  }
  int s = 0;
  for(int j = 0; j < N/2 + 1; j++){
    int x = 0;
    int y = 0;
    for(int i = 0; i < N; i++){
    	if(card.at(i) > x)x = card.at(i);
    }
  	for(int i = 0; i < N; i++){
    	if(card.at(i) == x){
      	card.at(i) = 0;
      	break;
    	}
  	}
  	for(int i = 0; i < N; i++){
    	if(card.at(i) > y)y = card.at(i);
  	}
  	for(int i = 0; i < N; i++){
    	if(card.at(i) == y){
      	card.at(i) = 0;
      	break;
    	}
  	}
    s+=(x-y);
  }
  cout << s << endl;
}
    
  
    
    

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 500005


int main(){
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(v<=w)
        cout<<"NO";
    else{
        if(a>b)
            a=a-b;
        else
            a=b-a;
        if((v-w)*t>=a)
            cout<<"YES";
        else
            cout<<"NO";
    }
    
    
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

string S;
int N;
vector<int> L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> S;
  N = S.size();
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') {
      R.push_back(i);
    } else {
      L.push_back(i);
    }
  }

  vector<int> ans(N, 0);
  // Rについて
  int l_idx = 0;
  for (int i = 0; i < R.size(); i++) {
    int r_pos = R[i];
    int l_pos = L[l_idx];
    while (r_pos > l_pos) {
      l_idx++;
      l_pos = L[l_idx];
    }

    if ((l_pos - r_pos) % 2 == 0) {
      ans[l_pos]++;
    } else {
      ans[l_pos - 1]++;
    }
  }

  // Lについて
  int r_idx = R.size() - 1;
  for (int i = L.size() - 1; i >= 0; i--) {
    int l_pos = L[i];
    int r_pos = R[r_idx];
    while (r_pos > l_pos) {
      r_idx--;
      r_pos = R[r_idx];
    }

    if ((l_pos - r_pos) % 2 == 0) {
      ans[r_pos]++;
    } else {
      ans[r_pos + 1]++;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1612
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

void solve(){
  int x;
  cin >> x;
  cout << 1-x << "\n";
}


signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}





Measured memory_bytes: 3608
import sys

def main():
    sys.stdin.readline()
    xs = sys.stdin.readline().strip().split(" ")
    n = 0
    m = 0
    l = 0

    for i in xs:
        if (int(i) % 2 == 1):
            m = m + 1
        elif (int(i) % 4 == 0):
            n = n + 1
        elif (int(i) % 4 == 2):
            l = l + 1

    if (l > 0 and n >= m):
        print("Yes")
    elif (l == 0 and n >= m - 1):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 11100
#include<bits/stdc++.h>
#define pb push_back
#define ll long long int
using namespace std;


int main(){
  
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin>>s>>t;
	ll cnt=0;
	for(int i=0; i<3; i++){
		if(s[i]==t[i])cnt++;
	}
	cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const* argv[])
{

    int n,k;
    char s[1024];

    char searchchar;
    int cnter = 0;
    cin >> n >> s >> k;
    
    searchchar = s[k-1];

    while(s[cnter]){
        if(s[cnter] != searchchar){
            s[cnter] = '*';
        }
        cnter++;
    }

    
    cout << s << endl;
    return 0;

}

//Yesterday,allmytroublesseemedsofaraway

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	public static class Conp{
		int start_pos, end_pos;
		boolean inv;

		public Conp(int s, int e) {
			super();
			this.start_pos = s;
			this.end_pos = e;
			inv = false;
		}
		
		public Conp(int s, int e, boolean inv) {
			super();
			this.start_pos = s;
			this.end_pos = e;
			this.inv = inv;
		}
		
		public int connect(int[] array){
			return Integer.parseInt(array[start_pos] + "" + array[end_pos]);
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		int[] array = new int[n];
		
		for(int i = 0; i < n; i++){
			array[i] = sc.nextInt();
		}
		
		Arrays.sort(array);
		
		PriorityQueue<Integer> p_queue = new PriorityQueue<Integer>();
		
		Queue<Conp> queue = new LinkedList<Conp>();
		queue.add(new Conp(0, 1));
		
		int count = 0;
		while(!queue.isEmpty()){
			Conp conp = queue.poll();
			
			if(count > 1000){
				break;
			}else{
				count++;
			}
			
			p_queue.add(conp.connect(array));
			if(!conp.inv){
				if(conp.end_pos < array.length - 1 && conp.end_pos + 1 != conp.start_pos){
					queue.add(new Conp(conp.start_pos, conp.end_pos + 1));
				}
				if(conp.start_pos < array.length - 1 && conp.start_pos + 1 != conp.end_pos){
					queue.add(new Conp(conp.start_pos + 1, conp.end_pos));
				}
			
				queue.add(new Conp(conp.end_pos, conp.start_pos, true));
			}
		}
		
		//System.out.println(p_queue);
		
		p_queue.poll();
		p_queue.poll();
		System.out.println(p_queue.poll());
		
	}

}

Measured memory_bytes: 29980
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    int coin=0;
    cin>>a>>b;
    for(int i=0;i<2;i++){
        if(a>=b){
            coin+=a;
            a--;
        }
        else {
            coin+=b;
            b--;
        }
    }
    cout<<coin;
}


Measured memory_bytes: 256
#![allow(dead_code, unused_variables)]
use proconio::{fastout, input};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
    }
    let mut a = Vec::new();
    let mut b = Vec::new();
    let mut c = Vec::new();
    for i in 0..n{
        input!{x:i32,y:i32,z:i32}
        a.push(x);
        b.push(y);
        c.push(z);
    }

    let mut dp = vec![vec![0;3];n+10];
    
    for i in 0..n{
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i];
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + b[i];
        dp[i+1][2] = max(dp[i][1], dp[i][0]) + c[i];
    }

    let mut ans = 0;
    for i in 0..3{
        ans = max(ans,dp[n][i]);
    }
    
    println!("{}",ans);
}


Measured memory_bytes: 10304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> c; //1の個数,0の個数,1の個数,...
    int idx = 0, now = S[0] - '0', cnt = 0;
    if (now == 0)
    {
        c.push_back(0);
    }
    while (idx <= N)
    {
        if (idx == N)
        {
            c.push_back(cnt);
            cnt = 1;
        }
        else if (S[idx] - '0' == now)
        {
            cnt++;
        }
        else
        {
            c.push_back(cnt);
            now = S[idx] - '0';
            cnt = 1;
        }
        idx++;
    }
    int n = c.size();
    vint s(n + 1);
    s[0] = 0;
    rep(i, n)
    {
        s[i + 1] = s[i] + c[i];
    }
    int M = c[0];
    n++;
    for (int left = 0; left < n; left += 2)
    {
        int right = left + 2 * K + 1;
        if (right >= n)
        {
            right = n - 1;
        }
        chmax(M, s[right] - s[left]);
    }
    cout << M;
    return 0;
}

Measured memory_bytes: 1272
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(n); 
    bool is1 = false;
    ll tmp = 1;
    REP(i, n) {
        cin >> a[i];
        if (a[i] == 1) is1 = true;
        if (a[i] == tmp) tmp++;
    }

    if (!is1) cout << -1 << '\n';
    else cout << n - tmp + 1 << '\n';
    return 0;
}



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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int d[1123][1123];
int col[1123];
int N, M;
int solve() {
	for (int i : range(N))for (int j : range(N))d[i][j] = 0;
	for (int i : range(N)) {
		col[i] = -1;
		d[i][i] = 1;
	}
	for (int i : range(M)) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		d[a][b] = d[b][a] = 1;
	}
	vector<pair<int, int>> c;
	stack<int> s;
	for (int i : range(N)) {
		if (col[i] != -1)continue;
		s.push(i);
		col[i] = 0;
		int cnt[2] = { 1,0 };
		while (s.size()) {
			int v = s.top(); s.pop();
			for (int u : range(N)) {
				if (d[v][u] == 0) {
					if (col[u] == -1) {
						col[u] = 1 - col[v];
						cnt[col[u]]++;
						s.push(u);
					}
					else {
						if (col[v] == col[u])return -1;
					}
				}
			}
		}
		c.push_back({ cnt[0],cnt[1] });
	}
	int ret = 1e9;
	vector<int> dp(N+1, 0);
	dp[0] = 1;
	for (auto &it:c) {
		vector<int> nxt(N + 1, 0);
		for (int i : range(N+1)) {
			if (dp[i] == 0)continue;
			nxt[i + it.first] = 1;
			nxt[i + it.second] = 1;
		}
		swap(dp, nxt);
	}
	for (int i : range(N + 1)) {
		if (dp[i]) {
			int a = i;
			int b = N - i;
			chmin(ret, a*(a - 1) / 2 + b * (b - 1) / 2);
		}
	}
	return ret;
}
int main() {
	while (cin >> N >> M)cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	
	
		public static void main(String[] args) {
			Scanner scan=new Scanner(System.in);
			boolean hai=false,tya=false,midori=false,
					mizi=false,ao=false,ki=false,dai=false,
					aka=false;
			int a=scan.nextInt();
			int b[]=new int[a];
			for(int i=0;i<a;i++)b[i]=scan.nextInt();
			Arrays.sort(b);
			int nount=0;
			for(int i=0;i<a;i++) {
				int c=b[i];
				if(c>=3200) {
					nount++;
				}
				if(c<400) hai=true;
				else if(c<800)tya=true;
				else if(c<1200)midori=true;
				else if(c<1600)mizi=true;
				else if(c<2000)ao=true;
				else if(c<2400)ki=true;
				else if(c<2800)dai=true;
				else if(c<3200)aka=true;
			}
			int cnt=0;
			if(hai)cnt++;
			if(tya)cnt++;
			if(midori)cnt++;
			if(mizi)cnt++;
			if(ao)cnt++;
			if(ki)cnt++;
			if(dai)cnt++;
			if(aka)cnt++;
			int max=cnt+nount;
			if(!hai&&!tya&&!midori&&!mizi&&!ao&&!ki&&!dai&&!aka) {
				cnt++;
			}
			System.out.print(cnt+" ");
			System.out.println(max);
		}
}

Measured memory_bytes: 23892
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
        int m=sc.nextInt();
        int[] arr=new int[n];
        
        int sum=0;
        for(int i=0; i<n; i++){
        	arr[i]=sc.nextInt();
        	sum+=arr[i];
        }
        // System.out.println(sum);
        float check=(float)sum/(4*m);

        int count=0;
        for(int i=0; i<n; i++){
        	if(arr[i]>=check)
        		count++;	
        }
        // System.out.println(check);
        // System.out.println(count);
        if(count>=m)
        	System.out.println("Yes");
        else
        	System.out.println("No");

		sc.close();
	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int a,b;
    cin >> a >> b;
    cout << a/b << ' ' << a%b << ' ' << fixed << setprecision(5) << (double)a/b << endl;
    return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n, m;
int k;

const int maxn = 2e5 + 5;
vector<int> G[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    cin >> k; 
    for(int i = 1;i <= k;i++){
        int x, y;
        cin >> x >> y;
        G[y].push_back(x);
    }
    int cnt = 0;
    int ans = 1e9;
    for(int i = 1;i <= m;i++){
        sort(G[i].begin(), G[i].end());
        int val = n + 1;
        for(auto v : G[i]){
            if(v < cnt + i){
                continue;
            }else if(v == cnt + i){
                cnt++;
            }else{
                val = v;
                break;
            }
        }
        ans = min(ans, val - 1);
    }
    cout << ans << endl;
    return 0;
}


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

int cnt2d(int n){
    int cnt = 0;
    while(n%2==0){
        ++cnt;
        n /= 2;
    }
    return cnt;
}

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

    int n;
    cin >> n;

    int res = 0;
    rep(i, n){
        int a;
        cin >> a;
        res += cnt2d(a);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
from bisect import bisect_left
def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    h,w,m = get_nums_l()
    targets = []
    H = []
    W = []
    HW = []
    for i in range(m):
        hi, wi = get_nums_l()
        HW.append((hi-1, wi-1))
        H.append(hi-1)
        W.append(wi-1)

    HW.sort()
    
    rows = [0] * h
    cols = [0] * w

    for i in range(m):
        rows[H[i]] += 1
        cols[W[i]] += 1

    rmax = 0
    rmaxi = []
    for i,x in enumerate(rows):
        if x > rmax:
            rmax = x
            rmaxi = [i]
        elif x == rmax:
            rmaxi.append(i)
    cmax = 0
    cmaxi = []
    for i,x in enumerate(cols):
        if x > cmax:
            cmax = x
            cmaxi = [i]
        elif x == cmax:
            cmaxi.append(i)

    # log(rmax,cmax)
    # log(rmaxi, cmaxi)

    for rmi in rmaxi:
        for cmi in cmaxi:
            ok = True
            i = bisect_left(HW, (rmi, cmi))
            if i<m and HW[i] == (rmi, cmi):
                ok = False
            # for i in range(m):
            #     if H[i] == rmi and W[i] == cmi:
            #         ok = False
            #         break
            if ok:
                print(rmax + cmax)
                return

    print(rmax + cmax - 1)

main()

Measured memory_bytes: 167568
N,K = gets.split(" ").map { |e| e.to_i }
data = []
for i in 0..N-1 do
  hi = gets.to_i
  data << hi
end

data.sort!
res = []
for i in 0..N-K do
  res << data[i+K-1] - data[i]
end

puts res.min


Measured memory_bytes: 4328
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
const int INF = 1e9;

ll N, X;
vl a(51), p(51);

ll eat(ll n, ll x)
{
    if(n == 0)
    {
        if(x <= 0) return 0;
        return 1;
    }
    else if(x <= 1 + a[n-1]) return eat(n-1, x-1);
    else return p[n-1]+1+eat(n-1, x-2-a[n-1]);
}

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

    cin >> N >> X;
    a[0] = 1; p[0] = 1;
    REPS(i, 50)
    {
        a[i] = 2*a[i-1]+3;
        p[i] = 2*p[i-1]+1;
    }
    cout << eat(N, X) << endl;
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

int main(){
	int n,a;
	cin>>n>>a;
	cout<<n*n-a<<endl;
	return 0;
}


Measured memory_bytes: 256
s = input()
string = list()
for letter in s:
	string.append(letter)
# print(string)
counter = 0
length = int(len(s) / 2)
i = 0
for i in range(length):
	if string[i] != string[len(s) - i - 1]:
		counter += 1
print(counter)

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

int main(){
    string S;
    long K;
    cin >> S >> K;

    int count = 0;
    for (int i = 0; i < S.size(); ++i){
        if (S.at(i) == '1'){
            ++count;
        }
        else {
            break;
        }
    }
    if (S.at(0) == '1'){
        if (K <= count){
            cout << 1;
        }
        else {
            cout << S.at(count);
        }
    }
    else {
        cout << S.at(0);
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll K,A,B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; ++i) {
        if(i % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
  int a,b,c,tmp;
  scanf("%d %d",&a,&b);
  if(a<b){//a%bをする際のために
    tmp=a;
    a=b;
    b=tmp;
  }
  c=a%b;
  while(c!=0){
    a=b;//最大公約数は小さいほうが最大
    b=c;//公約数
    c=a%b;//0になるまで計算する
  }
  printf("%d\n",b);
    
  return 0;
}


Measured memory_bytes: 2080
object Main {
  def main(args: Array[String]):Unit = {
      val w = io.StdIn.readLine
      val isBeauty = w.sorted.groupBy(c => c).forall{
        case (k, s) => s.length % 2 == 0
      }

      val answer = if(isBeauty) "Yes" else "No"
      println(answer)
  }
}


Measured memory_bytes: 21564
N=int(input())
p=list(map(int,input().split()))
point=[]
swap=[0,0]
cnt=0
"""
for i in range(N):
    if (p[i]==i+1):
        if swap[0]==0:
            swap[0]=i+1
        else:
            swap[1]=i+1
            #print(swap)
            cnt=cnt+min(2,swap[1]-swap[0])
            swap=[0,0]
if (swap[0]!=0)and(swap[1]==0):
    cnt=cnt+1
"""
for i in range(N):
    if p[i]==i+1:
        point.append(i+1)
#print(point)
cnt=len(point)
i=0
while i<len(point)-1:
    #print(i)
    if point[i+1]==point[i]+1:
        cnt=cnt-1
        i=i+1
    i=i+1
print(cnt)


Measured memory_bytes: 56044
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

void main() {
    int n;
    R(n);
    vector<PII> e;
    int t=(n%2==0?n+1:n);
    REP1(i,1,n) REP1(j,i+1,n) if ( i+j!=t ) e.PB({i,j});
    W(SZ(e));
    for ( auto i:e ) W(i.first,i.second);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 768
import heapq
x,y,a,b,c = map(int,input().split())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [-int(i) for i in input().split()]
P.sort(reverse=True)
P = P[:x]
Q.sort(reverse=True)
Q = Q[:y]
heapq.heapify(P)
heapq.heapify(Q)
heapq.heapify(R)
while R:
    if P[0] >= Q[0]:
        if Q[0] < -R[0]:
            heapq.heapreplace(Q, -heapq.heappop(R))
        else:
            break
    else:
        if P[0] < -R[0]:
            heapq.heapreplace(P,-heapq.heappop(R))
        else:
            break
print(sum(P)+sum(Q))

Measured memory_bytes: 114384
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, M; cin >> N >> M;
    vector<int> V(N,1);
    set<int> Red;
    Red.insert(0);
    rep(i,M) {
        int x, y; cin >> x >> y;
        x--,y--;
        if (Red.count(x) > 0) {
            if (V[x] == 1) {
                Red.erase(x);
                Red.insert(y);
            } else {
                Red.insert(y);
            }
        }
        V[x]--;
        V[y]++;
    }
    cout << Red.size() << endl;
}


Measured memory_bytes: 8108
#include <iostream>
#include <cmath>
#include <complex>
#include <vector>
using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}





//線分x線分交差判定
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

//線分x点交差判定
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}


//点の直線への射影
P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

//線分と点の距離
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

//線分と線分の距離
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

int i,j,t;

main(){
	int N,i,j;
	while(cin>>N, N){
		double x1,y1,x2,y2,h,Min = 1e6;
		P S,E;
		cin >> x1>>y1>>x2>>y2;
		S = P(x1, y1);
		E = P(x2, y2);
		for(i=0;i<N;i++){
			cin >> x1>>y1>>x2>>y2>>h;
			P p1 = P(x1,y1);
			P p2 = P(x1,y2);
			P p3 = P(x2,y1);
			P p4 = P(x2,y2);
			double l = distanceSS(L(p1, p2), L(S, E));
			if(distanceSS(L(p2, p4), L(S, E)) < l) l = distanceSS(L(p2, p4), L(S, E));
			if(distanceSS(L(p3, p4), L(S, E)) < l) l = distanceSS(L(p3, p4), L(S, E));
			if(distanceSS(L(p1, p3), L(S, E)) < l) l = distanceSS(L(p1, p3), L(S, E));
			double a;
			if(l < h) a = l;
			else{
				a = (h*h+l*l)/(2*h);
			}
			if(x1 < real(S) && y1 < imag(S) && real(S) < x2 && imag(S) < y2) a = 0;
			Min = min(Min, a);
		}
		printf("%.4lf\n", Min);
	}
}	

Measured memory_bytes: 1004
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    scanf("%d",&m);
    return m ;
}
inline ll lD()
{
    ll m ;
    scanf("%lld",&m);
    return m ;
}
inline double dD()
{
    double m ;
    scanf("%llf",&m);
    return m ;
}
ll LCM(ll a, ll b)
{
    return a / __gcd(a, b) * b;
}
ll power(ll a, ll b, ll m)
{
    if(!b)  return 1;
    ll t = power(a, b>>1, m)%m;
    return ((t*t)%m * (b&1 ? a : 1)%m)%m;
}

int main()
{
    fast();
    string s="";
 char c[3][3];
 for(int i=0;i<3;++i){
    for(int j=0;j<3;++j){
        cin>>c[i][j];
        if(i==j)
            s+=c[i][j];
    }
 }
 cout<<s<<endl;
}


Measured memory_bytes: 256