akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>

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

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//library----------------------------------------------

//素数判定
bool IsPrime(int x){
    if(x<2) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
    CIN(X);
    int num = X;
    while (!IsPrime(num))num++;
    printf("%d\n",num);    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int N = sc.nextInt();
      int K = sc.nextInt();
      String S = sc.next();
      String output = "";
      for(int i = 0; i < N; i++){
        if(i + 1 == K){
          output += S.substring(i , i + 1).toLowerCase();
        }else{
          output += S.substring(i , i + 1);
        }
      }
      System.out.println(output);
	}
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI b(n-1);
  rep(i,n-1){
    cin >> b[i];
  }

  reverse(all(b));
  int ans = b[0];

  rep(i,n-2){    
    ans += min(b[i],b[i+1]);
  }
  ans += b.back();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int size = sc.nextInt();
			BigDecimal divisor = BigDecimal.ZERO;
			for (int i = 0; i < size; i++) {
				BigDecimal bd = BigDecimal.ONE.setScale(15).divide(new BigDecimal(sc.nextInt()),
						BigDecimal.ROUND_HALF_UP);
				divisor = divisor.add(bd);
			}
			BigDecimal ans = BigDecimal.ONE.setScale(10).divide(divisor, BigDecimal.ROUND_HALF_UP);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21972
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            int[][] a = in.nextIntArrayArray(h, w);

            List<String> answers = new ArrayList<>();
            for (int i = 0; i < h * w - 1; i++) {
                int y = i / w;
                int x = i % w;

                if (y % 2 != 0) x = w - 1 - x;
                if (a[y][x] % 2 == 0) continue;

                if ((i + 1) % w == 0) {
                    answers.add((y + 1) + " " + (x + 1) + " " + (y + 2) + " " + (x + 1));
                    a[y + 1][x]++;
                } else if (y % 2 == 0) {
                    answers.add((y + 1) + " " + (x + 1) + " " + (y + 1) + " " + (x + 2));
                    a[y][x + 1]++;
                } else {
                    answers.add((y + 1) + " " + (x + 1) + " " + (y + 1) + " " + x);
                    a[y][x - 1]++;
                }
            }

            out.println(answers.size());
            for (String s : answers) {
                out.println(s);
            }
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public int[][] nextIntArrayArray(int n, int m) {
            int[][] res = new int[n][m];
            for (int i = 0; i < n; i++) {
                res[i] = nextIntArray(m);
            }
            return res;
        }

    }
}



Measured memory_bytes: 53464
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end();
int main() {
  vi ans(201,0);
  ans.at(105) = 1;
  ans.at(165) = 1;
  ans.at(195) = 1;
  ans.at(135) = 1;
  ans.at(189) = 1;
  int a;
  cin >> a;
  a++;
  int sum = 0;
  for(int i = 0;i<a;i++){
    sum += ans.at(i);
  }
  cout << sum;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, s) for (int i = s; i < (int)(n); i++)
#define twopo(k)  1 << k

typedef vector<int> ivec1;
typedef vector<vector<int>> ivec2;
typedef vector<vector<char>> cvec2;
typedef pair<int, int> pair;

ivec1 vecplus(const ivec1 &first, const ivec1 &second){
  int len = first.size();
  ivec1 answer(len);
  rep(i,len){
    answer.at(i) = first.at(i) + second.at(i);
  }
  return answer;
}

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  int ans = -1;
  
  ivec2 list;
  rep(i,N){
    vector<int> v(M + 1);
    rep(j, M + 1){
      cin >> v.at(j);
    }
    list.push_back(v);
  }
  
  for (int tmp = 0; tmp < twopo(N); tmp++){
    bitset<12> s(tmp);
    vector<int> judge(M+1);
    rep(i,N){
      if(s.test(i)){
        judge = vecplus(judge, list.at(i));
      }
    }   
    
    bool go = true;
    for (int i = 1; i < M+1; i++){
      if (judge.at(i) < X){
        go = false;
        break;
      }
    }
    if(go){
      if(ans == -1){
        ans = judge.at(0);
      }else if(judge.at(0) < ans){
        ans = judge.at(0);
      }
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3620
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    l=sort(parseMap(split(readline())))
    println(ifelse(l[n]-sum(l[1:n-1])<0,"Yes","No"))
end
main()

Measured memory_bytes: 166440
#include <stdio.h>

int main()
{
    char string[6];
    scanf("%s",string);
    if(string[2]==string[3])
    {
        if(string[4]==string[5])
        {
            printf("Yes");
        }
        else
        {
            printf("No");
        }
    }
    else
    {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 128
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

max_a = 0
min_b = -1
for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    if a > max_a:
        max_a = a
        min_b = b
print(max_a + min_b)


Measured memory_bytes: 27380
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
#define INF (2e9)
typedef long long int ll;

using namespace std;

char s[3001], t[3001];
int sn, tn;
int dp[3001][3001];
int main(void){
    scanf("%s", s+1); for(int i=1;s[i];i++) sn++;
    scanf("%s", t+1); for(int i=1;t[i];i++) tn++;

    for(int i=1;i<=sn;i++) for(int j=1;j<=tn;j++){
        if(s[i]==t[j]) {
            dp[i][j] = dp[i-1][j-1] + 1;
        }else{
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }

    string str = "";
    while(true){
        if(sn < 1 or tn < 1) break;
        if(s[sn] == t[tn]){
            str = s[sn]+str;
            sn--; tn--;
        }else{
            if(dp[sn][tn]==dp[sn-1][tn]) sn--;
            else tn--;
        }
    }
    cout << str << endl;

    return 0;
}



Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/


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

	if(n%2==1) cout<<0<<endl;
	else{
		n/=10;
		int ans=n;

		FOR(i,1,30){
			int z=pow(5,i);
			if(n<z) break;

			ans+=(n/z);
		}
		

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



Measured memory_bytes: 4140
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int a,b;
    cin>>a>>b;
    if(a<10&&b<10){
        cout<<a*b;
    }else{
        cout<<-1;
    }
    return 0;
}


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

typedef long long ll;

int main() {
  ll N; cin >> N;
  vector<ll> a(N*3);
  for(ll i=0; i<N*3; i++) cin >> a[i];

  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  ll sum=0, cnt=0;
  for(ll i=0; i<3*N; i++){
    if(i%2==1){
      if(cnt==N) break;
      cnt++;
      sum += a[i];
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1 << 30)

class Edge {
	public:
	    int t, w;
	    Edge() {}
	    Edge(int t, int w) :t(t), w(w){}
};

vector<Edge> G[MAX];
int n, d[MAX];
int cnt;

void bfs(int s) {
	for(int i = 0; i < n; i++) d[i] = INFTY;
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;
	while(!Q.empty()) {
		u = Q.front();
		Q.pop();
		for(int i = 0; i < G[u].size(); i++) {
			Edge e = G[u][i];
			if(d[e.t] == INFTY) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

 
void solve() {
	bfs(0);
	int maxv = 0, tgt = 0;
	for(int i = 0; i < n; i++) {
		if(d[i] == INFTY) continue;
		if(maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}  
	}
	
	bfs(tgt);
	maxv = 0;
	for(int i = 0; i < n; i++) {
		if(d[i] == INFTY) continue;
		if(maxv < d[i]) {
			maxv = d[i];
		}
	}
	
	cout << maxv << endl;
}

main() {
	int s, t, w;
	cin >> n;
	
	for(int i = 0; i < n - 1; i++) {
		cin >> s >> t >> w;
		
		G[s].push_back(Edge(t, w));
		G[t].push_back(Edge(s, w)); 
	}
	
	solve();
}

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

typedef long long lint;
typedef long double louble;

const char lf = '\n';

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

int n,xl[_],xr[_];

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();
	for(int i=1;i<=n;i++)xl[i]=ty(),xr[i]=ty();
	sort(xl+1,xl+n+1,greater<int>()),sort(xr+1,xr+n+1);

	lint now=0,ans=0;
	for(int i=1;i<=n;i++)ans=max(ans,now+=xl[i]),ans=max(ans,now-=xr[i]);
	now=0;
	for(int i=1;i<=n;i++)ans=max(ans,now-=xr[i]),ans=max(ans,now+=xl[i]);
	cout<<ans+ans<<lf;

	return 0;
}


Measured memory_bytes: 1024
#include <cstdlib>
#include <iostream>

int main(int argc, char *argv[]) {
  int n, x, t;
  std::cin >> n >> x >> t;

  auto dv = std::div(n, x);
  int res = dv.quot * t;
  if (dv.rem) {
    res += t;
  }

  std::cout << res << std::endl;
  return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(long i=0;i<(n);i++)
#define For1(i,n) for(long i=1;i<(n);i++)
long gcd(long a,long b){
    return b?gcd(b,a%b):a;
}
int main(){
    int n;cin>>n;
    vector<long> p(n);
    For(i,n){
        long x;
        cin>>x;
        p.at(i)=x;
    }
    int ans=0;
    For1(i,n-1){
        if(max(p.at(i-1),max(p.at(i),p.at(i+1)))!=p.at(i)&&min(p.at(i-1),min(p.at(i),p.at(i+1)))!=p.at(i)){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		class IndexData
		{
			String word;
			//String page;
			List<Integer> page = new ArrayList<>();
		};
		List<IndexData> list = new ArrayList<>();
		
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext(); )
		{
			String word = scanner.next();
			int page = scanner.nextInt();
			
			boolean is_equals = false;
			for(int i=0; i<list.size(); i++)
			{
				IndexData index = list.get(i);
				if(word.equals(index.word))
				{
					is_equals = true;
					index.page.add(page);
					list.set(i, index);
					break;
				}
			}
			if(!is_equals)
			{
				IndexData index = new IndexData();
				index.word = word;
				index.page.add(page);
				list.add(index);
			}
		}
		
        Collections.sort(
                list,
                new Comparator<IndexData>()
                {
                    @Override
                    public int compare(IndexData obj0, IndexData obj1)
                    {
                        return obj0.word.compareTo(obj1.word);
                    }
                });
        
		for(int i=0; i<list.size(); i++)
		{
			IndexData index = list.get(i);
			System.out.println(index.word);
			
	        Collections.sort(
	                index.page,
	                new Comparator<Integer>()
	                {
	                    @Override
	                    public int compare(Integer obj0, Integer obj1)
	                    {
	                        return (obj0 > obj1) ? 1 : -1;
	                    }
	                });
	        
			for(int j=0; j<index.page.size(); j++)
			{
				System.out.print((j>0?" ":"") + index.page.get(j));
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 26392
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	cin>>n;
	vi v(n);
	rep(i, n) cin>>v[i];
	sort(all(v));
	double ans = 0.0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			int c = v[j], d = v[i];
			int a, b;
			for(int k = n - 1; k >= 0; k--) if(v[k] != c && v[k] != d){
				a = v[k];
				break;
			}
			for(int k = n - 1; k >= 0; k--) if(v[k] != c && v[k] != d && v[k] != a){
				b = v[k];
				break;
			}
			ans = max(ans, (double)(a+b)/(c-d));
		}
	}
	printf("%.15lf\n", ans);
}

Measured memory_bytes: 3256
#include<iostream>
#include<algorithm>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
P matrix[102][102];
bool used[102][102];
int imap[102][102];
int index,cnt;
static const int dx[4] = {0,1,0,-1};
static const int dy[4] = {1,0,-1,0};

void rec(int x,int y){
  used[y][x] = true;
  imap[y][x] = index;
  P p = matrix[y][x];
  if(used[p.S][p.F]){
    if(imap[p.S][p.F]==index || imap[p.S][p.F] == 0)cnt++;
    return;
  }
  rec(p.F,p.S);  
}

int main(){
  int N;
  while(true){
    cin >> N;
    if(N == 0)break;
    index = 1;
    cnt = 0;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	int x,y;
	used[i][j] = false;
	imap[i][j] = 0;
	cin >> x >> y;
	matrix[i][j] = P(x,y);
      }
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	if(!used[i][j]){
	  rec(j,i);
	  index++;
	}
      }
    }

    cout << cnt << endl;

  }
  return 0;
}

Measured memory_bytes: 1292
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        System.out.println(6 - (A+B));


    }
}


Measured memory_bytes: 21716
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>

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

int N, M;
int P[112345];
int c[23][112345];
int n[23];

int count(int p, int s, int e) {
	return c[p][e - 1] - ((s == 0) ? 0 : c[p][s - 1]);
}

int memo[1 << 21];

int dp(int i, int j, int b) {
	if (memo[i] != -1) return memo[i];
	if (b == 1) return memo[i] = count(log2(i), 0, j);
	int a = 0;
	rep(p, M) {
		if (i & 1 << p) a = max(a, dp(i ^ (1 << p), j - n[p], b - 1) + count(p, j - n[p], j));
	}
	return memo[i] = a;
}

int main() {

	memset(memo, 0xFF, sizeof(memo));

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

	rep(i, M) n[i] = 0;

	rep(i, N) {
		scanf("%d", &P[i]);
		n[P[i] - 1]++;
	}

	rep(i, M) {
		int t = 0;
		rep(j, N) {
			if (P[j] == i + 1) t++;
			c[i][j] = t;
			c[i][j + 1] = t;
		}
	}
	printf("%d\n", N - dp((1 << M) - 1, N, M));

	return 0;
}

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

int main(){
    string  S; cin>>S;
    if(S == "Sunny")
        cout<<"Cloudy"<<endl;
    if(S == "Cloudy")
        cout<<"Rainy"<<endl;
    if(S == "Rainy")
        cout<<"Sunny"<<endl;
    return 0;
}


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

template<int MOD>
class mod_int {
	unsigned x;
public:
	mod_int() : x(0) { }
	mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }

	mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
	mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
	mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
	mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }

	bool operator==(const mod_int& that) const { return x == that.x; }

	mod_int inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		return mod_int(u);
	}
};

template<int MOD>
istream& operator >> (istream& is, mod_int<MOD>& val) {
	long long x;
	is >> x; val = x;
	return is;
}

template<int MOD>
ostream& operator << (ostream& os, const mod_int<MOD>& val) {
	os << val.get();
	return os;
}

const int mod = 1e6 + 3;
using mint = mod_int<mod>;

mint fac[mod + 1];

mint power(mint x, int n) {
	mint res = 1;
	while (n) {
		if (n & 1) res *= x;
		n >>= 1;
		x *= x;
	}
	return res;
}

int main()
{
	fac[0] = 1;
	for (int i = 0; i < mod; i++) {
		fac[i + 1] = fac[i] * (i + 1);
	}
	int Q;
	cin >> Q;
	while (Q--) {
		mint x, d;
		int n;
		cin >> x >> d >> n;
		assert(1 <= n && n <= 1e9);
		if (x == 0) {
			puts("0");
			continue;
		}
		if (d == 0) {
			printf("%d\n", power(x, n).get());
			continue;
		}
		if (((mint(0) - x) / d).get() < n) {
			puts("0");
			continue;
		}
		int off = (x / d).get() - 1;
		assert(0 <= off && off < mod && off + n < mod);
		mint v = fac[off + n] / fac[off];
		printf("%d\n", (v * power(d, n)).get());
	}
	return 0;
}


Measured memory_bytes: 4736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int X;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		X = Integer.parseInt(strArr[1]);
		// System.out.println(N);
		M = new int[N];
		MinM = Integer.MAX_VALUE;
	}

	public boolean hasNext() {
		return cnt < N;
	}

	int[] M;
	int MinM;

	public void readBody(String str) {
		// System.out.println(str);
		M[cnt] = Integer.parseInt(str);
		if (M[cnt] < MinM)
			MinM = M[cnt];
		cnt++;
	}

	public void solve() {
		int x = X;
		for (int i = 0; i < N; i++)
			x -= M[i];
		int ans = N + x / MinM;
		System.out.println(ans);
	}
}


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

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

  vector<pair<int,int>> vec;

  if(k>(n - 2)*(n - 1)/2){
    cout << -1 << endl;
    return 0;
  }

  for (int i = 1; i < n; i++) vec.emplace_back(i,n);

  vector<pair<int,int>> edge;
  for (int i = 1; i < n; i++)
  {
    for (int j = i+1; j < n; j++) edge.emplace_back(i,j);
  }

  int cnt = (n-2)*(n-1)/2 - k;
  for (int i = 0; i < cnt; i++) vec.push_back(edge[i]);

  
  cout << vec.size() << endl;
  for(auto ans:vec){
    cout << ans.first << " " << ans.second << endl;
  }
  
}

Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
#define INF 1e9

int main() {
	int c[3][3];
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}
	int a[3], b[3];
	bool can = true;;
	for (int i = 0; i < 3; ++i) {
		a[i] = c[i][0] - b[0];
	}
	for (int i = 0; i < 3; ++i) {
		b[i] = c[0][i] - a[0];
	}
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			if (c[i][j] != a[i] + b[j])
				can = false;
		}
	}
	if (can)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int num(int a, int b) {
  int i;
  for(i = 0; i < b; ++i) a /= 10;
  return a ? a % 10 : 10;
}

int main(void) {
  int i, j, n, k, d;
  scanf("%d%d", &n, &k);
  bool flg[11];
  for(i = 0; i < 11; ++i) flg[i] = false;
  for(i = 0; i < k; ++i) scanf("%d", &d), flg[d] = true;
  for(i = n; ;++i) {
    bool b = false;
    for(j = 0; j < 7; ++j) if(flg[num(i, j)]) b = true;
    if(b) continue;
    printf("%d", i);
    return 0;
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;                     
using namespace __gnu_pbds;
// assert(a[i]<n ) // if we want to check for special cond , used for debug
// make less_equal in order to make a multiset pbds
const ll Mod = 998244353;
ll CaseN=1;
ll fast_power(ll a,ll b,ll mod){
	ll ans=1;
	while(b>0){
	if(b&1){
	ans=(a*ans)%mod;
	}
	b=b>>1;
	a=(a*a)%mod;
	}
	return ans;
	}


ll nCr(ll n ,ll r)
{
ll p= n;
r = min(r,n-r);
ll a =1;
ll b=1;	
while(r)
{
	a = a*p;
	b = b*r;
	
	ll g = __gcd(a,b);
	
	a = a/g;
	b = b/g;
	
	p--;
	r--;	
}	
return a;
	
}

ll tst(ll n ,ll *a)
{
 ll ans=0;
 
 return ans;
}


void solve()
{
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	ll p[n+2];
	
	for(ll i=1;i<=n;i++)
	{
	cin>>p[i];	
	}
	sort(p+1,p+1+n);
	for(ll i=1;i<=k;i++)
	{
	ans+=p[i];	
	}
	cout<<ans<<endl;
	//cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;

return ;
}


signed main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{	
	solve();	
	
	}
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

ll N, X;
vector<ll> nums(55, 1), paties(55, 1);

ll f(ll n, ll x) {
    if(n == 0) {
        return 1;
    }
    if(x <= 1)
        return 0;
    else if(x > 1 && x < nums[n] / 2 + 1)
        return f(n - 1, x - 1);
    else if(x == nums[n] / 2 + 1)
        return paties[n - 1] + 1;
    else if(x > nums[n] / 2 + 1 && x < nums[n])
        return paties[n - 1] + 1 + f(n - 1, x - (nums[n] / 2 + 1));
    else if(x >= nums[n])
        return paties[n];
}

int main() {
    cin >> N >> X;
    for(int i = 0; i < N; i++) {
        nums[i + 1] = 2 * nums[i] + 3;
        paties[i + 1] = 2 * paties[i] + 1;
    }
    cout << f(N, X) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int tmp,ary[5],i,j;
	for(i=0;i<5;i++){
		scanf("%d",&ary[i]);
	}
	for(j=0;j<4;j++){
		for(i=3;i>=j;i--){
			if(ary[i]<ary[i+1]){
				tmp=ary[i+1];
				ary[i+1]=ary[i];
				ary[i]=tmp;
			}
		}
	}
	for(i=0;i<5;i++){	
		printf("%d",ary[i]);
		if(i<4){
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<map>
#include<cmath>
#define ll long long
#define N 100100
#define MZ 1300
using namespace std;

ll n,a[N],b[N],zs[N],zz,ans;
bool P[N];
map<ll,ll>cnt;
map<ll,bool>vis;

inline void get()
{
	ll i,j;
	for(i=2;i<=100000;i++)
	{
		if(!P[i]) zs[++zz]=i;
		for(j=1;j<=zz&&zs[j]*i<=100000;j++) P[zs[j]*i]=1;
	}
}

int main()
{
//	freopen("2.txt","r",stdin);
	ll i,j,k,p,q,t,tmp;
	get();
//	cout<<zs[1300];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n;i++)
	{
		t=a[i];
		b[i]=q=1;
		for(j=1;j<=MZ&&t!=1;j++)
		{
			p=0;
			for(;t%zs[j]==0;t/=zs[j]) p++;
			p%=3;
			if(!p) continue;
			for(k=1;k<=p;k++) q*=zs[j];
			for(k=p+1;k<=3;k++) b[i]*=zs[j];
		}
		if(t)
		{
			tmp=sqrt(t);
			if(tmp*tmp==t)
			{
				q*=t;
				b[i]*=tmp;
			}
			else
			{
				q*=t;
				b[i]*=t*t;
			}
		}
		a[i]=q;
		cnt[a[i]]++;
//		if(i%1000==0) cout<<i<<endl;
	}
//	return 0;
//	for(i=1;i<=n;i++) cout<<a[i]<<" ";puts("");
//	for(i=1;i<=n;i++) cout<<b[i]<<" ";puts("");
	for(i=1;i<=n;i++)
	{
		if(vis[a[i]] || vis[b[i]] || a[i]==1) continue;
		vis[a[i]]=1;
		ans+=max(cnt[a[i]],cnt[b[i]]);
	}
	cout<<ans+(!!cnt[1]);
}

Measured memory_bytes: 27008
import java.util.*;

public class Main {

    static char[][] map;

    static boolean next_permutation(int[] p) {
      for (int a = p.length - 2; a >= 0; --a)
        if (p[a] < p[a + 1])
          for (int b = p.length - 1;; --b)
            if (p[b] > p[a]) {
              int t = p[a];
              p[a] = p[b];
              p[b] = t;
              for (++a, b = p.length - 1; a < b; ++a, --b) {
                t = p[a];
                p[a] = p[b];
                p[b] = t;
              }
              return true;
            }
      return false;
    }

    static boolean search(int i, int j) {
        boolean flg = true;
        for (int r=0;r<8;r++){
            if (r==i) continue;
            if (map[r][j]=='Q') {
                flg = false;
            }
        }
        for (int c=0;c<8;c++) {
            if (c==j) continue;
            if (map[i][c]=='Q') {
                flg = false;
            }
        }
        for (int k=-Math.min(i, j);k<=Math.min(7-i, 7-j);k++) {
            if (k==0) continue;
            if (map[i+k][j+k]=='Q') {
                flg = false;
            }
        }
        for (int k=-Math.min(i, 7-j);k<=Math.min(7-i, j);k++) {
            if (k==0) continue;
            if (map[i+k][j-k]=='Q') {
                flg = false;
            }
        }
        return flg;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int[] r = new int[k];
        int[] c = new int[k];
        for (int i=0;i<k;i++) {
            r[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        int[] arr = new int[8];
        for (int i=0;i<8;i++) {
            arr[i] = i;
        }
        do {
            boolean flag = true;
            map = new char[8][8];
            for (int i=0;i<8;i++) {
                for (int j=0;j<8;j++) {
                    map[i][j] = '.';
                }
            }
            for (int i=0;i<k;i++) {
                map[r[i]][c[i]] = 'Q';
            }
            for (int i=0;i<8;i++) {
                map[i][arr[i]] = 'Q';
            }

            loop:for (int i=0;i<8;i++) {
                for (int j=0;j<8;j++) {
                    if (map[i][j]=='Q') {
                        if (!search(i, j)) {
                            flag = false;
                            break loop;
                        }
                    }
                }
            }

            if (flag) {
                for (int i=0;i<8;i++) {
                    for (int j=0;j<8;j++) {
                        if (j!=7) System.out.print(map[i][j]);
                        else System.out.println(map[i][j]);
                    }
                }
                break;
            }
        } while (next_permutation(arr));
    }
}


Measured memory_bytes: 41880
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  string S;
  cin >> S;
  int N = S.size();
  rep(i,(N/2)){
    if(S[i] != S[N-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  int n = (N/2)+1;
  rep(i,(n/2)){
    if(S[i] != S[n-i-2]){
      cout << "No" << endl;
      return 0;
    }
  }
  int M = (N+3)/2;
  rep(i,(N/2)-1){
    if(S[M-1+i] != S[N-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
N = int(input())
 
F = []
 
for _ in range(N):
    f = list(input().strip().split())
    F.append(int("".join(f), 2))

P = [list(map(int, input().split())) for _ in range(N)]

ans = -10**10-7

for i in range(1,2**10):
    candi = 0
    for j in range(N):
        tmp = i & F[j]
        p = format(tmp, 'b').count("1")
        candi += P[j][p]
    ans = max(ans,candi) 
    
print(ans)

Measured memory_bytes: 3064
f=lambda:map(int,input().split())
n,m=f()
g=[[] for _ in range(n)]
for _ in range(m):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
p=[0]*n
from collections import*
q=deque([0])
while q:
  v=q.popleft()
  for c in g[v]:
    if p[c]<1: p[c]=v+1; q.append(c)
print('Yes',*p[1:],sep='\n')

Measured memory_bytes: 39112
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 99999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n;
    cin >> n;
    cout << n*n*n << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace atcoder_csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Util.ReadInt();
            var result = 1/Util.ReadInts().Select(a => 1/(double)a).Sum();
            Console.WriteLine(result);
        }
  
    }

    class Util {
        private const bool debug = false;

        public static string ReadStr() {
            return debug ? ReadDebugLine() : Console.ReadLine();
        }

        public static List<string> ReadStrs() {
            return ReadStr().Split(' ').ToList();
        }

        public static int ReadInt() {
            return int.Parse(ReadStr());
        }     

        public static List<int> ReadInts() {
            return ReadStrs().Select(s => int.Parse(s)).ToList();
        } 

        private static List<string> _lines;
        private static int _lineIndex = 0;
        private static string ReadDebugLine() {
            if(_lines == null) {
                _lines = System.IO.File.ReadAllLines("debug.txt").ToList();
            }
            return _lines[_lineIndex++];
        }

    }
}


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

int main(){
    int n,x,ans=1,sum=0;
    cin >> n >> x ;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l.at(i);
        sum+=l.at(i);
        if(sum<=x){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn pop_count(x: usize) -> usize {
    let mut n = 0;
    for i in 0..32 {
        if (x & (1 << i)) != 0 {
            n += 1;
        }
    }
    n
}

fn main() {
    let N = read!(usize);
    let mut T = vec![vec![]; N];

    for i in 0..N {
        let A = read!(usize);
        for (x, y) in read![usize, i64; A] {
            T[i].push((x - 1, y != 0));
        }
    }

    let mut m = 0;

    's: for s in 1..1 << N {
        let k = pop_count(s);
        if k < m {
            continue;
        }

        for i in 0..N {
            if (s & (1 << i)) == 0 {
                // 不親切な人の主張は何であれ矛盾しない。
                continue;
            }

            for &(x, y) in &T[i] {
                // x は正直者？
                let honest = (s & (1 << x)) != 0;

                if (honest && !y) || (!honest && y) {
                    // 矛盾
                    continue 's;
                }
            }
        }

        m = k;
    }

    println!("{}", m)
}


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


int main() {
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int l = 0;
    A.push_back(A[0]+K);
    rep(i,N) l = max(l,A[i+1]-A[i]);
    cout << K-l << endl;

    return 0;
}

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

#define fo(i, x, y) for (int i = x; i <= y; ++i)
#define fd(i, x, y) for (int i = x; i >= y; --i)

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

int main()
{
	int d, t, s;
	d = getint(); t = getint(); s = getint();
	printf((double)d / s <= t? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3768
n, h = map(int, input().split())
v = []
for _ in range(n):
  a, b = map(int, input().split())
  v.append([a, b])
v.append([-1, -1])
v.sort(key=lambda x:x[0])
k = v[-1]
v.sort(key=lambda x:x[1], reverse=True)
cnt = 0
t = v[-1]
for i in v:
  if i[1] >= k[0]:
    h -= i[1]
    cnt += 1
  if h <= 0:
    print(cnt)
    break;
if h > 0:
  cnt += (h - 1) // k[0] + 1
  print(cnt)

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

int main(){
    int s;cin >> s;
    int arr[1000000];
    int ex;
    int cnt = 0;
    bool isEnd = false;
    for(int i=1;i<=1000000;i++){
        if(i==1){
            ex = s;
        }else if(ex%2==0){
            ex = ex/2;
        }else{
            ex = 3*ex+1;
        }
        //cout << ex << endl;
        for(int j=0;j<cnt;j++){
            
            if(arr[j] == ex){
                //printf("-------------------------\n");
                cout << cnt+1 << endl;
                isEnd = true;
                break;
            }
        }
        arr[cnt] = ex;
        cnt++;
        if(isEnd) break;

    }



}

Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif // suiyuan2009
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  int ret=0;
  for(int i=1;i<=n;i++){
    if(a[i]!=i)continue;
    int j=i;
    while(j+1<=n&&a[j+1]==j+1)j++;
    ret+=(j-i+2)/2;
    i=j;
  }
  cout<<ret<<endl;
  return 0;
}



Measured memory_bytes: 640
import math
from bisect import bisect_left, bisect_right

N = int(input())
X = list(map(int, input().split()))
L = int(input())
Q = int(input())
Y = [list(map(int, input().split())) for _ in range(Q)]

LOGN = int(math.log(N) / math.log(2)) + 1
parent = [[-1] * N for _ in range(LOGN + 1)]

# Update for k
for k in range(LOGN + 1):
    for i in range(N):
        if k == 0:
            parent[k][i] = bisect_right(X, X[i] + L) - 1
        else:
            parent[k][i] = parent[k - 1][parent[k - 1][i]]

def find(a, b):
    num = 0
    u = a
    while True:
        k = 0
        for i in range(LOGN + 1):
            if parent[i][u] >= b:
                k = i
                break
                
        if k == 0:
            num += 1
            break
        num += pow(2, k - 1)
        u = parent[k - 1][u]
        
    return num

for a, b in Y:
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    print(find(a, b))


Measured memory_bytes: 102936
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).ToArray();
            Console.WriteLine((inputs[0] * 3 + inputs[1]) / 2);
		}
	}
}


Measured memory_bytes: 13268
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		int[] mountHill = new int[10];

		for (int i = 0; i < 10; i++) {
			mountHill[i] = sc.nextInt();

			if (mountHill[i] > 10000 || mountHill[i] < 0) {
				System.out.println("error");
			}
		}
		Arrays.sort(mountHill);

		System.out.println(mountHill[9] + "\n" + mountHill[8] + "\n"
				+ mountHill[7]);
	}

}

Measured memory_bytes: 17172
#include <iostream>  
#include <stdio.h>  
#include <string.h>  
using namespace std;  
int sum,n,m;  
int k;  
char map[105][105];  
int dx[10]={-1,1,0,0};  
int dy[10]={0,0,-1,1};  
void dfs1(int x,int y)  
{  
    if(x<0||x>=n||y<0||y>=m) return ;  
    if(map[x][y]=='#')  
    {  
        map[x][y]=' ';  
        for(int i=0;i<4;i++)  
        {  
            dfs1(x+dx[i],y+dy[i]);  

        }  
    }  
}  
void dfs2(int x,int y)  
{  
    if(x<0||x>=n||y<0||y>=m) return ;  
    if(map[x][y]=='@')  
    {  
        map[x][y]=' ';  
        for(int i=0;i<4;i++)  
        {  
            dfs2(x+dx[i],y+dy[i]);  

        }  
    }  
}  
void dfs3(int x,int y)  
{  
    if(x<0||x>=n||y<0||y>=m) return ;  
    if(map[x][y]=='*')  
    {  
        map[x][y]=' ';  
        for(int i=0;i<4;i++)  
        {  
            dfs3(x+dx[i],y+dy[i]);  

        }  
    }  
}  
int main()  
{  
    while(scanf("%d%d",&n,&m)!=EOF)  
    {  getchar();
        if(m==0||n==0) break;  
        for(int i=0;i<n;i++)  
        {  
            for(int j=0;j<m;j++)  
            {  
              scanf("%c",&map[i][j]) ;
            }  
            getchar();
        }
        sum=0;  
        for(int i=0;i<n;i++)  
        {  
            for(int j=0;j<m;j++)  
            {  
                if(map[i][j]=='#')  
                {  
                    sum++;  
                    dfs1(i,j);  
                }  
                  if(map[i][j]=='@')  
                {  
                    sum++;  
                    dfs2(i,j);  
                }  
                  if(map[i][j]=='*')  
                {  
                    sum++;  
                    dfs3(i,j);  
                }  
            }  
        }  
        printf("%d\n",sum);  
    }  
    return 0;  
}  


Measured memory_bytes: 3404
a,b,c,d=map(int,input().split())
ans=-10**18
if a>=0:
    if c>=0:
        print(b*d)
    elif c<0 and d>=0:
        print(b*d)
    else:
        print(a*d)
elif a<0 and b>=0:
    if c>=0:
        print(b*d)
    elif c<0 and d>=0:
        print(max(a*c,b*d))
    else:
        print(a*c)
else:
    if c>=0:
        print(b*c)
    elif c<0 and d>=0:
        print(a*c)
    else:
        print(a*c)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int main ()
{
     signed long long x,a,q,y,z,n,t;
    cin>>n;
    cin>>q;
    getchar();
    stack<int>S[n];
    stack<int>S2[n];
     for(int i=1; i<=q; i++)
    {
        cin>>a;
        if(a==0)
        {
            cin>>t;
            cin>>x;
            S[t].push(x);
        }
        else if(a==1)
        {
            cin>>t;
            //cout<<"S[t] = ";
            if(!S[t].empty())
            {
          cout<<S[t].top()<<endl;
            S2[t].push(S[t].top());
            S2[t].pop();
            }
        }
        else if(a==2)
        {
            cin>>t;
            if(!S[t].empty())
            {
                S[t].pop();
            }
        }
    }
    return 0;
}




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

#define for_(i,a,b) for(int i=a;i<b;++i)

typedef long long lint;

int H, W, dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
lint L;
string grid[110], dir = "NESW";

int visit[110][110][4], px[41000], py[41000], pd[41000];

bool able(int x, int y) {
	if (x < 0 || x >= W || y < 0 || y >= H) return false;
	return grid[y][x] == '.';
}

int main() {
	std::ios::sync_with_stdio(false);
	while (cin >> H >> W >> L, H) {
		int x = 0, y = 0, d = 0;
		
		for_(i,0,H) {
			cin >> grid[i];
			for_(j,0,W) if (grid[i][j] != '.' && grid[i][j] != '#') {
				x = j; y = i;
				d = dir.find(grid[i][j]);
				grid[i][j] = '.';		
			}
		}
		
		memset(visit, -1, sizeof(visit));
		
		lint s = 0;
		while (visit[y][x][d] < 0) {
			visit[y][x][d] = s;
			px[s] = x; py[s] = y; pd[s] = d;
			while (!able(x + dx[d], y + dy[d])) d = (d + 1) % 4;
			x += dx[d]; y += dy[d];
			++s;
		}
		
		lint t = visit[y][x][d], id = L;
		if (s < L) id = t + (L - t) % (s - t);
		
		cout << py[id] + 1 << " " << px[id] + 1 << " " << dir[pd[id]] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1516
s = input()

a = int(s[0]+s[1])
b = int(s[2]+s[3])

# YYMM
if((0 <= a <= 99) & (1 <= b <= 12)):
    if((0 <= b <= 99) & (1 <= a <= 12)):
        print("AMBIGUOUS")
    else:
        print("YYMM")
else:
    if((0 <= b <= 99) & (1 <= a <= 12)):
        print("MMYY")
    else:
        print("NA")


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		if(t.substring(0, t.length()-1).equals(s)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35644