akhauriyash/Code-Regression huggingface dataset:
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize, h: [i64; n]);
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        parse!(it, a: usize, b: usize);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }
    let mut ok = vec![false; n];
    for i in 0..n {
        let a = g[i].iter().all(|&v| h[i] > h[v]) || (g[i].len() == 0);
        ok[i] = a;
    }
    println!("{}", ok.into_iter().filter(|&x| x == true).count());
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 10980
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long long,long long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long long,long long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long long,long long>>> lvvii;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

long long mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

long long mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll h,w,k;
	cin>>h>>w>>k;
	string s[6];
	for (int i = 0; i < h; ++i)
	{
		cin>>s[i];
	}
	ll ans=0;
	for(int rows=0;rows<(1<<h);rows++)
	{
		for(int cols=0;cols<(1<<w);cols++)
		{
			vi r,c;
			for(int i=0;i<h;i++)
			{
				if(((1<<i)&rows)==0) r.pb(i);
			}
			for(int i=0;i<w;i++)
			{
				if(((1<<i)&cols)==0) c.pb(i);
			}
			ll k1=0;
			for(auto r1:r)
			{
				for(auto c1:c)
				{
					k1+=((s[r1][c1]=='#')?1:0);
				}
			}
			if(k1==k) ans++;
		}	
	}
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  ll a, b,n;
  cin >> a >> b >> n;

  if(b<=n)cout << (a*(b-1)/b) << endl;
  else cout << (a*n)/b << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;



int main(){
    vector<string> S(3);
    int count[3];
    rep(i,3){
        cin >> S[i];
        count[i] = S[i].size();
    }
    int Now = 0;
    while(true){
        if(count[Now] == 0){
            char ans = 'A'+Now;
            cout << ans << endl;
            return 0;
        }
        int temp = Now;
        Now = S[Now][S[Now].size()-count[Now]] - 'a';
        count[temp]--;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

const ll INF = 5e15;

V<ll> winv(2001), binv(2001);
VV<ll> bpre(2001, V<ll>(2002));
VV<ll> wpre(2001, V<ll>(2002));
VV<ll> costs(2001, V<ll>(2001, INF));

int main() {
    costs[0][0] = 0;
    ll N;
    cin >> N;
    V<ll> widxv(N + 1), bidxv(N + 1);
    V<pair<ll, bool>> balls;
    for(ll i = 0; i < 2 * N; i++) {
        char c;
        ll a;
        cin >> c >> a;
        (c == 'W' ? widxv : bidxv)[a] = i;
        balls.emplace_back(a, c == 'W');
    }

    for(ll i = 0; i < 2 * N; i++) {
        ll num;
        bool color;
        tie(num, color) = balls[i];
        auto &inv = (color ? winv : binv)[num];
        auto &pre = (color ? wpre : bpre)[num];
        for(ll j = 0; j < i; j++) {
            ll nnow;
            bool cnow;
            tie(nnow, cnow) = balls[j];
            if(color == cnow && num < nnow) inv++;
            if(color != cnow) pre[nnow]++;
        }
        for(ll j = 2000; j > 0; j--) {
            pre[j - 1] += pre[j];
        }
    }

    for(ll i = 0; i < 2 * N; i++) {
        for(ll w = 0; w <= min(i, N); w++) {
            ll b = i - w;
            if(w < N) chmin(costs[w + 1][b], costs[w][b] + winv[w] + bpre[w + 1][b + 1]);
            if(b < N) chmin(costs[w][b + 1], costs[w][b] + binv[b] + wpre[b + 1][w + 1]);
        }
    }
    cout << costs[N][N] << endl;
    return 0;
}


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

int main()
{
    long N;
    cin >> N;
    vector<string> al = {
        "z",
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
    };

    int n = 0;
    string s = "";
    while (N > 0)
    {
        n = N % 26;
        s = al.at(n) + s;
        N = N / 26;

        if (n == 0 && N == 0)
        {
            break;
        }
        else if (n == 0)
        {
            N--;
        }
    }

    cout << s << endl;
    return 0;
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define MAX 1000000001



int main(){
    string s;
    cin>>s;

    int j=0;
    int ju=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='h'){
            j=1;
            if(i==s.size()-1){
                ju=1;
                break;
            }
        }else if(s.at(i)=='i'){
            if(j==0){
                ju=1;
                break;
            }
            j=0;
            continue;
        }else{
            ju=1;
            break;
        }
    }
    if(ju==1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int p=1;
  for(int i=0;i<N;i++){
    if(p>K){p=p+K;}
    else{p=p*2;}
  }
  cout << p << endl;
}


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

using namespace std;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writerLn(int x) { writer(x, '\n'); }
#define rep(i,n)for(int i=0;i<n;i++)
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
char b[200000], ok[100000]{ 1 };
deque<int>que;

void bfs(int u, int t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!~d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)writerLn(ans[i]);
}

Measured memory_bytes: 13580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    vector<vector<ll>> dp(N, vector<ll>(N, 0));
    for (int i = 0; i < N; i++) {
        if (N%2 == 1) dp[i][i] = A[i];
        else dp[i][i] -= A[i];
    }
    
    for (int l = 2; l <= N; l++) {
        for (int i = 0; i+l-1 <= N-1; i++) {
            if ((N-l)%2 == 0) dp[i][i+l-1] = max(dp[i+1][i+l-1]+A[i], dp[i][i+l-2]+A[i+l-1]);
            else dp[i][i+l-1] = min(dp[i+1][i+l-1]-A[i], dp[i][i+l-2]-A[i+l-1]);
        }
    }
    
    cout << dp[0][N-1] << endl;
    return 0;
}

Measured memory_bytes: 73628
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

int n, T, L, B;
bool lose[110], back[110];
double dp[110][110];

int nxt(int x, int i){
    x += i;
    return x <= n ? x : 2*n-x;
}

double dfs(int x, int t){
    if(t < 0) return 0;
    if(dp[x][t] >= 0) return dp[x][t];
    double ret = 0;
    For(i, 1, 7){
        int m = nxt(x, i);
        if(lose[m]) ret += dfs(m, t-2) / 6.0;
        else if(back[m]) ret += dfs(0, t-1) / 6.0;
        else ret += dfs(m, t-1) / 6.0;
    }
    return dp[x][t] = ret;
}

int main(){
    while(scanf("%d%d%d%d", &n, &T, &L, &B) && n){
        rep(i, n+1) lose[i] = back[i] = false;
        rep(_, L){
            int i;
            scanf("%d", &i);
            lose[i] = true;
        }
        rep(_, B){
            int i;
            scanf("%d", &i);
            back[i] = true;
        }
        rep(i, n+1)rep(j, T+1) dp[i][j] = -1;
        rep(i, n) dp[i][0] = 0;
        dp[n][0] = 1;
        For(j, 1, T+1) dp[n][j] = 0;
        double ans = 0;
        rep(t, T+1) ans += dfs(0, t);
        printf("%.20lf\n", ans);
    }
}


Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#define ll long long
using namespace std;

#define MOD 1000000007

class Solve
{
private:
	string s;
public:
	Solve(){
		cin >> s;

	}

	void exec(){
		if(s.size() < 4){
			cout << "No" << endl;
			return;
		}
		string tmp = "YAKI";
		for (int i = 0; i < 4; ++i)
		{
			if(s[i] != tmp[i]) {
				cout << "No" << endl;
				return;
			}
		}
		cout << "Yes" << endl;

	}
};

int main(){
	Solve solver = Solve();
	solver.exec();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
inline __int128 read(){
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void print(__int128 x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

signed main()
{
	__int128 n=read();
	__int128 sum1=0,sum2=0;
	while (n--){
		int a;
		cin>>a;
		sum1+=a;
		sum2+=a*a;
	}
	sum1=sum1*sum1-sum2;
	sum1/=2;
	sum1%=(__int128)(1e9+7);
	print(sum1);
	re 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;


#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull testcase;cin>>testcase;while(testcase--)
#define pb push_back
#define mkp make_pair
#define nl cout<<"\n"
#define prime 1000000007
#define debug(x) cout<<(#x)<<" : "<<x,nl
#define debug2(x,y) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y,nl
#define debug3(x,y,z) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y<<" "<<(#z)<<" : "<<z,nl
#define f first
#define s second
#define oa(a,n) loop(i,0,n)cout<<a[i]<<" ";nl;
#define ov(a) loop(i,0,a.size()) cout<<a[i]<<" ";nl;
#define MOD(a) (((a%prime)+prime)%prime)



int main()
{


    ll n,x,y,w,z;
    string s;
    cin >> n;

    x = n/1000;
    y = (n/100) - x*10;
    w  = (n/10) - x*100 - y*10;
    z = (n) - x*1000 - y*100 - w*10;
    // cout << x << y << w << z << endl;
    // cout << x*10+y << " " << w*10+z << " ";

    if(((x*10 + y) > 12|| (x*10+y)==0) && (w*10+z) <= 12 && (w*10+z) >= 1)
    {
    	cout << "YYMM";
    }
    else if((x*10 + y) <= 12 && ((w*10+z) > 12 || (w*10+z)==0) && (x*10+y)>=1)
    {
    	cout << "MMYY";
    }
    else if((x*10 + y) <= 12 && (w*10+z) <= 12 && (w*10+z) >=1 && (x*10 + y)>=1 )
    {
    	cout << "AMBIGUOUS";
    }
    else
    {
    	cout << "NA";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
const int N = 10000;
int main()
{
	int a[N] = {0}, n ,maxn=-1000000,minn=1000000;
	long long sum = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
    	scanf("%d", &a[i]);
    	if(a[i] > maxn)
        {
    	    maxn = a[i];
	    }
	    if(a[i] < minn)
	    {
		    minn = a[i];
	    }
	    sum += a[i];
	}
    printf("%d %d %lld\n", minn, maxn, sum);
	return 0;
 } 


Measured memory_bytes: 2796
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
from collections import defaultdict, Counter

H, W, N = inpl()
ddic = defaultdict(int)

for _ in range(N):
    A, B = inpl()
    for a in range(max(3, A), min(H, A+2)+1):
        for b in range(max(3, B), min(W, B+2)+1):
            ddic[(a, b)] += 1

C = Counter(ddic.values())

print((H-2)*(W-2) - sum(C.values()))

for i in range(1, 10):
    print(C[i])

Measured memory_bytes: 152020
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,a[100010],b[100010],ans=0,now=0;;
    cin>>n>>m;
    vector<pll> ab(n);
    multiset<ll> st;
    rep(i,n){
        cin>>a[i]>>b[i];
        ab[i]=(pll(a[i],b[i]));
    }
    sort(all(ab));
    rep2(i,1,m+1){
        ll M=0;
        rep2(j,now,n){
            if(ab[j].first==i){
                st.insert(ab[j].second);
                M=max(M,ab[j].second);
            }
            else{
                now=j;
                break;
            }
        }
        if(!st.empty()){
            M =max(M,*(--st.end()));
        }
        if(M>0){
            st.erase(st.find(M));
        }
        if(M==0 && !st.empty()){
            ll a=*(--st.end());
            st.erase(--st.end());
            ans+=a;
        }
        ans+=M;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 8064
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef	pair<int,int>	pii;

int main(){
	for(int n,m,a;scanf("%d%d%d",&n,&m,&a),n;){
		a--;
		int amida[100];
		rep(i,n)	amida[i]=i;

		static pair<int,pii> bar[1000];
		rep(i,m){
			int h,p,q;	scanf("%d%d%d",&h,&p,&q);
			p--,q--;
			bar[i]=mp(h,mp(p,q));
		}
		sort(bar,bar+m);
		rep(i,m){
			int p=bar[i].second.first,q=bar[i].second.second;
			swap(amida[p],amida[q]);
		}

		printf("%d\n",amida[a]+1);
	}

	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	cout << a[0] + a[1] << endl;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
edge_list = [[] for i in range(n)]
prev_list = [1]
ans = [0] * n

for i in range(m):
    a, b =  map(int, input().split())
    edge_list[a - 1].append(b)
    edge_list[b - 1].append(a)

while len(prev_list) > 0:
    next = []
    for prev in prev_list:
        for edge in edge_list[prev - 1]:
            if ans[edge - 1] == 0:
                next.append(edge)
                ans[edge - 1] = prev
    prev_list = next

print('Yes')
for i in range(1, len(ans)):
    print(ans[i])


Measured memory_bytes: 33964
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
import std.numeric;
void main()
{
    auto
        buf = readln.chomp.split.to!(int[]),
        b = readln.chomp.split.to!(int[]);
    size_t answer;
    foreach (i; 0..buf[0])
        if (-buf[2] < readln.chomp.split.to!(int[]).dotProduct(b))
            answer += 1;
    answer.writeln;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char st[1000];
int main(){
	scanf("%s",st);
	int len=strlen(st);
	len-=8;
	for(register int i=0;i<len;++i){
		printf("%c",st[i]);
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		LinkedList<String> input = new LinkedList<String>();
		while(sc.hasNext()){
			input.addLast(sc.next());
		}
		LinkedList<String> rest = new LinkedList<String>();
		
		while(!input.isEmpty()){
			//System.out.println(input + " " + rest);
			final int a = Integer.parseInt(input.poll());
			if(input.isEmpty()){
				System.out.println(a);
				break;
			}
			
			final int b = Integer.parseInt(input.poll());
			final String ops = input.poll();
			
			if("+".equals(ops)){
				input.addFirst((a + b) + "");
				while(!rest.isEmpty()){
					input.addFirst(rest.poll());
				}
			}else if("-".equals(ops)){
				input.addFirst((a - b) + "");
				while(!rest.isEmpty()){
					input.addFirst(rest.poll());
				}
			}else if("*".equals(ops)){
				input.addFirst((a * b) + "");
				while(!rest.isEmpty()){
					input.addFirst(rest.poll());
				}
			}else if("/".equals(ops)){
				input.addFirst((a / b) + "");
				while(!rest.isEmpty()){
					input.addFirst(rest.poll());
				}
			}else{
				rest.addFirst(a + "");
				input.addFirst(ops);
				input.addFirst(b + "");
			}
		}
		
	}
}

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

bool judge(string S) {
    int i = 0;
    while (i < S.length()) {
        if (S[i] == 'd') {
            if (i + 5 >= S.length()) {
                return S.substr(i, 5).compare("dream") == 0;
            }
            else if (S[i + 5] == 'd') {
                if (S.substr(i, 5).compare("dream"))
                    return false;
                i += 5; continue;
            }
            else if (S[i + 5] == 'e') {
                if (S[i + 7] == 'a') {
                    if (S.substr(i, 5).compare("dream"))
                        return false;
                    i += 5; continue;
                } else {
                    if (S.substr(i, 7).compare("dreamer"))
                        return false;
                    i += 7; continue;
                }
            } else {
                return false;
            }
        } else if (S[i] == 'e') {
            if (i + 5 >= S.length()) {
                return S.substr(i, 5).compare("erase") == 0;
            }
            if (S[i + 5] == 'r') {
                if (S.substr(i, 6).compare("eraser"))
                    return false;
                i += 6; continue;
            } else {
                if (S.substr(i, 5).compare("erase"))
                    return false;
                i += 5; continue;
            }
        } else {
            return false;
        }
    }    
    return true;
}

int main() {
    string S;
    cin>>S;
    cout<<(judge(S)?"YES":"NO")<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long int
// #include"Template.cpp"

void solve() {
    string s; cin >> s;
    int sum = 0;
    for(auto i : s) {
        int d = i - '0';
        sum += d;
    }
    if((sum%9) == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}

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

int main(){
  int n,m;
  int cnt=0,flg=0;
  string u[260]={},t[260]={};
  
  cin >> n;
  for(int i=0;i < n;i++)
    {
      cin >> u[i];
    }
  
  cin >> m;
  for(int j=0;j < m;j++)
    {
      cin >> t[j];
    }

  for(int j=0;j < m;j++)
    {
      flg=0;
      for(int i=0;i < n;i++)
	{
	  if(t[j]==u[i] && cnt ==0)
	    {
	      cnt++;
	      flg = 1;
	      cout << "Opened by " << t[j] << endl;
	    }
	  else if(t[j]==u[i] && cnt ==1)
	    {
	      cnt--;
	      flg = 1;
	      cout << "Closed by " << t[j] << endl;
	    }
	}
      if(flg==0)
	{
	  cout << "Unknown " << t[j] << endl;
	}
    }
}


Measured memory_bytes: 3236
// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = 1000003;

int n, m;
int a[N];
int ton[M];

int main()
{
    //File("");
    n = gi();
    for (int i = 1; i <= n; i+=1) a[i] = gi(), ++ton[a[i]];
    LL ans = 0;
    for (int i = 1; i <= n; i+=1)
    {
    	bool ok = true;
    	for (int j = 1; j * j <= a[i]; j+=1)
    		if (a[i] % j == 0)
    		{
    			if (j != a[i] && ton[j]) {ok = false; break;}
    			if (j == a[i] && ton[j] > 1) {ok = false; break;}
    			if (a[i] / j != a[i] && ton[a[i] / j]) {ok = false; break;}
    			if (a[i] / j == a[i] && ton[a[i] / j] > 1) {ok = false; break;}
    		}
    	if (ok) ++ans;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 8340
#include <bits/stdc++.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using T = tuple<int, int, int>;
constexpr int INF = 1e9+7;
list<T> ls;
int H, W, h, w, d, eh, ew, ds[1005][1005], dhw[][2] = {{0,1},{0,-1},{1,0},{-1,0}};
char s[1005];
int main(){
	scanf("%d%d%d%d%d%d", &H, &W, &h, &w, &eh, &ew);
	h++; w++; eh++; ew++;
	fill(ds[0], ds[1004], -1);
	rep(i,H){
		scanf("\n%s", s);
		rep(j,W) if(s[j] == '.') ds[i+2][j+2] = INF;
	}
	ls.emplace_front(h,w,0);
	while(!ls.empty()){
		tie(h,w,d) = ls.front(); ls.pop_front();
		if(ds[h][w] <= d) continue;
		ds[h][w] = d;
		for(auto [dh, dw]: dhw) ls.emplace_front(h+dh, w+dw, d);
		rep(i,5) rep(j,5) ls.emplace_back(h+i-2,w+j-2,d+1);
	}
	printf("%d\n", ds[eh][ew] == INF ? -1 : ds[eh][ew]);
}

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

int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(10, vector<int>(10));
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int begin = s[0] - '0';
        int end = s[s.size()-1] - '0';
        a[begin][end]++;
    } 
    int ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            ans += a[i][j] * a[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef struct {
    long long x, y, z;
} cake;

int main (void) {
    int N, M;
    cake cake[1000];
    char sign;
    long long result, tmp, tmpResult;
    long long sum[1000];

    scanf("%d%d", &N, &M);
    int i;
    for (i = 0; i < N; i++){
        scanf("%lld%lld%lld", &(cake[i].x), &(cake[i].y), &(cake[i].z));
    }

    result = 0;
    for (sign = 0; sign < 8; sign++) {
        for (i = 0; i < N; i++) {
            sum[i] = ((sign & 0b100)? cake[i].x: -cake[i].x)
                    + ((sign & 0b010)? cake[i].y: -cake[i].y)
                    + ((sign & 0b001)? cake[i].z: -cake[i].z);
        }
        for (;;) {
            for (i = 0; (i < N - 1) && (sum[i] >= sum[i + 1]); i++);
            if (i == N - 1) {
                break;
            }
            tmp = sum[i]; sum[i] = sum[i + 1]; sum[i + 1] = tmp;
        }
        tmpResult = 0;
        for (i = 0; i < M; i++){
            tmpResult += sum[i];
        }
        result = (result < tmpResult)? tmpResult: result;
    }
   
    printf ("%lld", result);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

#define ll long long
const ll N = 1000000000000000;

void solve() {

}

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }

    cout << "NG";
    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).OrderBy(i=>i).ToArray();
            Console.WriteLine(abc[0]+abc[1]);
        }
    }
}


Measured memory_bytes: 11604
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  ll a,b,c,k;
  cin >> a >> b >> c >> k;

  ll ans = (k % 2) ? b - a: a - b;

  if(abs(ans) > 1000000000000000000)
  {
    cout << "Unfair" << endl;
  }
  else
  {
    cout << ans << endl;
  }  

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

template<class T, int SZ> struct Seg {
    T seg[2*SZ], MN = MOD;
    
    Seg() {
        memset(seg,0,sizeof seg);
    }
    
    T comb(T a, T b) { return min(a,b); } // easily change this to min or max
    
    void upd(int p, T value) {  // set value at position p
        for (seg[p += SZ] = value; p > 1; p >>= 1) seg[p>>1] = comb(seg[p],seg[p^1]);
    }
    
    void build() {
        F0Rd(i,SZ) seg[i] = comb(seg[2*i],seg[2*i+1]);
    }
    
    T query(int l, int r) {  // sum on interval [l, r]
        T res = MN; r++;
        for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
            if (l&1) res = comb(res,seg[l++]);
            if (r&1) res = comb(res,seg[--r]);
        }
        return res;
    }
};

Seg<int,1<<18> s;

int N,Q, b[200001], cost[200001], tmp;
vi v[200001];

void solve() {
	F0R(i,1<<18) s.upd(i,MOD);
	s.upd(0,0);
	FOR(i,1,N+1) {
	    sort(v[i].rbegin(),v[i].rend());
	    for (int j: v[i]) s.upd(j,s.query(i-1,j));
	    
	    int t = s.query(i-1,i-1)+cost[i];
	    if (t < s.query(i,i)) s.upd(i,t);
	}
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N;
	FOR(i,1,N+1) {
	    cin >> b[i]; 
	    if (b[i] == 1) {
	        cost[i] = 1;
	    } else {
	        cost[i] = -1;
	        tmp ++;
	    }
	}
	cin >> Q;
	F0R(i,Q) {
	    int l,r; cin >> l >> r;
	    v[l].pb(r);
	}
	solve();
	cout << tmp+s.query(N,N);
}

// read!
// ll vs. int!

Measured memory_bytes: 12544
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
  int K;
  cin>>K;
  string s;
  cin>>s;
  if(s.size()<=K){
    cout<<s<<endl;
    return 0;
  }
  string tmp=s.substr(0,K);
  cout<<tmp<<"..."<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005,INF=1<<30;

string S;

ll s[MAX][2];
ll ruru[MAX][2];
vector<ll> base={37,43};

void make(){
    int N=S.size();
    
    for(int q=0;q<2;q++){
        s[0][q]=0;
        
        ruru[0][q]=1;
        
        for(int i=1;i<=N;i++){
            s[i][q]=s[i-1][q]*base[q]+ll(S[i-1]-'A');
            s[i][q]%=mod;
            
            ruru[i][q]=ruru[i-1][q]*base[q]%mod;
        }
    }
}

pair<ll,ll> hashh(int a,int b){
    pair<ll,ll> res;
    res.fi=(s[b][0]-s[a][0]*ruru[b-a][0]%mod+mod)%mod;
    res.se=(s[b][1]-s[a][1]*ruru[b-a][1]%mod+mod)%mod;
    
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Q;cin>>N>>Q;
    cin>>S;
    make();
    
    set<pair<ll,ll>> SE;
    int l=0,r=0;
    
    while(Q--){
        string S;cin>>S;
        if(S=="L++") l++;
        if(S=="L--") l--;
        if(S=="R++") r++;
        if(S=="R--") r--;
        
        SE.insert(hashh(l,r+1));
    }
    
    cout<<SE.size()<<endl;
}





Measured memory_bytes: 31340
#include <iostream>
#include <vector>
#include <numeric>
#include <utility>
#include <cmath>
#include <algorithm>
#include <queue>

using ll = long long;

template <class T>
using vec = std::vector<T>;

template <class T>
constexpr T nil = static_cast<T>(-1);

template <class T>
constexpr T inf = std::numeric_limits<T>::max() / 2;


constexpr int NIL = nil<int>;

void solve()
{
    using namespace std;

    int n, m;
    cin >> n >> m;

    vec<vec<int>> edges(n);
    vec<int> degIn(n, 0);

    for (int i = 0, from, to; i < m; ++i)
    {
        cin >> from >> to;
        edges[from].push_back(to);
        ++degIn[to];
    }

    vec<int> sortedV;
    queue<int> q;

    for (int i = 0; i < n; ++i)
        if (degIn[i] == 0)
            q.push(i);
    
    while (!q.empty())
    {
        auto v = q.front(); q.pop();

        sortedV.push_back(v);

        for (int e : edges[v])
            if (--degIn[e] == 0)
                q.push(e);
    }

    for (int v : sortedV)
        cout << v << endl;

}

int main()
{
    solve();
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<ll, ll> pll;

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(), (c).end()
#define MOD 1000000007
#define MAX 110

int main(){
#ifdef HOME
    freopen("kek.in", "r", stdin);
    freopen("kek.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vi arr(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] == i + 1 && i < n - 1)
            swap(arr[i], arr[i + 1]), ans++;
        else if(arr[i] == i + 1 && i == n - 1)
            swap(arr[i], arr[i - 1]), ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String t = sc.next();
        
        ArrayList<String> ary = new ArrayList<>();
        String tmp = s;
        //ary.add(tmp);
        for(int i=0;i<s.length();i++){
            String a = tmp.substring(0, s.length()-1);
            a = tmp.substring(s.length()-1) + a;
            //System.out.println(a);
            ary.add(a);
            tmp = a;
        }
        
        for(String ss : ary){
            if (ss.equals(t)==true){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
    
}


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

vector<int> v[256];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t; cin >> s >> t;
	for (int i = 0; i < s.length(); i++) 
		v[s[i]].push_back(i + 1);
	long long ans = 0;
	int p = 0;
	for (int i = 0; i < t.length(); i++) {
		if (v[t[i]].empty()) {
			cout << -1 << '\n';
			return 0;
		}
		if (v[t[i]].back() <= p) {
			ans += (int)s.length();
			p = 0;
		}
		p = (*upper_bound(v[t[i]].begin(), v[t[i]].end(), p));
	}
	ans += p;
	cout << ans << '\n';
	return 0;
}	

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

bool prime(int p){

  if (p <= 0)
  {
    return false;
  }
  
  for (int i = 2; i < p; i++)
  {
    if (p % i == 0)
    {
      return false;
    }
    
  }
  return true;
}

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

  while (!prime(X))
  {
    X++;
  }
  
  cout << X;

  return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

for i in range(n-1):
    j = i + 1
    if j < n and a[i]+a[j] > x:
        d = min(a[j], (a[i]+a[j]) - x)
        a[j] -= d
        ans += d
    if a[i]+a[j] > x:
        d = min(a[i], (a[i]+a[j]) - x)
        a[i] -= d
        ans += d
print(ans)


Measured memory_bytes: 14052
#include <iostream>
#include <map>

using namespace std;

int ifkaibun(string& s){
    
    string str = s;
    unsigned long long i,j;
    unsigned long long size = str.size();
    if(size < 2) return 1;
    
    for(i = 0,j = size-1; i < j; i++,j--) {
        if(str[i] != str[j]) return 0;
    }
    return 1;
}

int solve(){

    string str;
    
    cin >> str;
    
    unsigned long long num = str.size();
    
    string tar;
    
    for (unsigned long long i = 0; i < num; i++){
        
        string sym(1, str[i]);
        string temp = sym.c_str();
        
        if (temp != "x")
            tar = tar + temp;
        
    }
    
    if (ifkaibun(tar)) {
        
        
        
        unsigned long long i = 0,j,result = 0; j = str.size() - 1;
        unsigned long long k = 0;
        unsigned long long size_tar = tar.size() / 2;
        
        if (tar.size()==0) {
            
            cout << 0 << endl;
            return 0;
        }
        
        while(k <= size_tar){
            
            unsigned long long count1 = 0,count2 = 0;
            
            while(str[i] == 'x'){
                count1++;
                i++;
            }
            
            while(str[j] == 'x'){
                count2++;
                j--;
            }
            
            result += (count1 > count2)? count1-count2:count2-count1;
            i++;j--;
            k++;
            
        }
        
        cout << result << endl;
    }else{
        cout << -1 << endl;
    }
    
    
    return 0;
}



int main() {
    // insert code here...
    //cout << "Hello, World!\n";
    
    solve();
    
    
    //return 0;
}


Measured memory_bytes: 696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

int H, W;
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
int grid[50][50], visited[50][50];

int main()
{
    while (cin >> W >> H)
    {
        if (H == 0 && W == 0)
            return 0;

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                cin >> grid[i][j];
                visited[i][j] = 0;
            }
        }

        int ans = 0, cnt = 0;
        queue<pair<int, int>> que;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (grid[i][j] == 1 && visited[i][j] == 0)
                {
                    que.push({i, j});

                    while (!que.empty())
                    {
                        auto p = que.front();
                        que.pop();
                        visited[p.first][p.second] = 1;
                        for (int k = 0; k < 8; k++)
                        {
                            int nx = p.first + dx[k], ny = p.second + dy[k];
                            if (nx < 0 || nx >= H)
                                continue;
                            if (ny < 0 || ny >= W)
                                continue;
                            if (visited[nx][ny])
                                continue;

                            visited[nx][ny] = 1;
                            if (grid[nx][ny] == 1)
                                que.push({nx, ny});
                        }
                    }
                    ans++;
                }
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3108