akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class BBattle {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (ceil((double)C / (double)B) > (ceil((double)A / (double)D))) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
};


signed main() {
  BBattle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3548
N = int(input())
m = [input() for _ in range(N)]
mt = list(map(''.join, zip(*m)))

ans = 0
for z in range(N): #ずらし
  for y in range(N):
    if m[y][y+1:] != mt[y][y+1:]:
      break
  else:
    ans += N
  m = [l[-1]+l[:-1] for l in m]
  mt = [mt[-1]] + mt[:-1]

print(ans)

Measured memory_bytes: 3444
import java.util.*;

class Main{
    //150a
    static final long DIV = 100000007L;
    static final int MAX = 2000000000;
    //static long[] fac = new long[MAX];
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        //String[] s = new String[40320];
        if(n*500>=k){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }

    static long modpow(long n){
        long ans =1;
        long a = 2;
        long m = n;
        while(m>0){
            if((m&1)==1)ans = ans*a % DIV;
            a = a * a % DIV;
            m >>= 1;
        }
        return ans;
    }

    static long modcomb(long n,long r){
        return 1;
    }
    
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int A, B;

void solve() {
	cin >> A >> B;
	string str;
	cin >> str;
	bool found = false;
	rep(i, 0, sz(str)) {
		if(i == A) {
			if(str[i] != '-') {
				found = true;
				break;
			}
		}
		else {
			if(str[i] < '0' || str[i] > '9') {
				found = true;
				break;
			}
		}
	}
	if(found) cout << "No\n";
	else cout << "Yes\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    string s ; 
    cin >> s ; 
    int n = (int) s.size() ; 
    vector<int> v(n) ; 
    int cnt = 0 ; 
    for(int i=0;i<n-1;i++){
    	if ( s[i] == 'R' && s[i+1] == 'L' ){
    		cnt++ ; 
    		v[i] += (cnt+1) / 2 ;
    		v[i+1] += cnt / 2 ;
    		cnt = 0 ; 
    	}
    	else if ( s[i] == 'R' ) cnt++;
    }
    cnt = 0 ;
    for(int i=n-1;i>0;i--){
    	if ( s[i] == 'L' && s[i-1] == 'R' ){
    		cnt++ ; 
    		v[i] += (cnt+1) / 2 ;
    		v[i-1] += cnt / 2 ;
    		cnt = 0 ;
    	}
    	else if ( s[i] == 'L' ) cnt++ ; 
    }
    debug() << imie(v) ; 
    for(int i=0;i<n;i++){
    	cout << v[i] << ' ' ; 
    }
    cout << endl;
    return 0 ;
}


Measured memory_bytes: 1104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
// typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int m;

string J(string s){
    s = s[m-1] + s.substr(0,m-1);
    return s;
}
string C(string s){
    s = s.substr(1) + s[0];
    return s;
}
string E(string s){
    if (m % 2 == 0){
        s = s.substr(m/2) + s.substr(0,m/2);
    }else{
        s = s.substr(m/2+1) + s[m/2] + s.substr(0,m/2);
    }
    return s;
}
string A(string s){
    reverse(s.begin(), s.end());
    return s;
}
string P(string s){
    REP(i,m){
        if (s[i] >= '1' && s[i] <= '9')
            s[i]--;
        else if (s[i] == '0')
            s[i] = '9';
    }
    return s;
}
string M(string s){
    REP(i,m){
        if (s[i] >= '0' && s[i] <= '8')
            s[i]++;
        else if (s[i] == '9')
            s[i] = '0';
    }
    return s;
}

int main() {
    int n;
    cin >> n;
    while (n--){
        string s, t;
        cin >> s >> t;
        m = t.length();
        reverse(s.begin(), s.end());
        REP(i,s.length()){
            if (s[i] == 'J')
                t = J(t);
            if (s[i] == 'C')
                t = C(t);
            if (s[i] == 'E')
                t = E(t);
            if (s[i] == 'A')
                t = A(t);
            if (s[i] == 'P')
                t = P(t);
            if (s[i] == 'M')
                t = M(t);
        }
        cout << t << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
N, L = map(int,input().split())
A=0
if L > 0:
  for i in range(1,N):
    A += L + i
elif L*(-1) >= N:
  for s in range(N-1):
    A += L + s
else:
  for w in range(N):
    A += L + w
print(A)

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

namespace Painting_problem
{
    class Program
    {
        static int height = 0;
        static int width = 0;
        static int[,] datas = new int[51, 51];
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            try
            {
                height = Int32.Parse(input.Split(' ')[0]);
                width = Int32.Parse(input.Split(' ')[1]);
            
                for (int i = 0; i < height; i++)
                {
                    input = Console.ReadLine();
                    for (int j = 0; j < width; j++)
                    {
                        if (input[j].Equals('#'))
                        {
                            datas[i, j] = 1;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("形式エラー");
                Console.ReadLine();
                return;
            }
            bool result = true;
            //Paint
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    PaintOut(i, j);
                }
            }
            //Check Result
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (datas[i,j] == 1)
                    {
                        result = false;
                        break;
                    }
                }
            }
            Console.WriteLine(result ? "Yes" : "No");
            Console.ReadLine();
        }

        static void PaintOut(int x, int y)
        {
            if (datas[x,y] == 1)
            {
                bool isSuccess = false;
                if (x > 0)
                {
                    isSuccess = isSuccess || datas[x - 1, y] != 0;
                }
                if (y > 0)
                {
                    isSuccess = isSuccess || datas[x, y - 1] != 0;
                }
                isSuccess = isSuccess || datas[x + 1, y] != 0;
                isSuccess = isSuccess || datas[x, y + 1] != 0;
                if (isSuccess)
                {
                    datas[x, y] = 2;
                }
            }
        }
    }
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	int n, m;
	cin >> n >> m;
	int sum = 0;
	VI a(n);
	REP(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	sort(ALL(a));
	reverse(ALL(a));

	REP(i, m) {
		if (a[i] * 4 * m < sum) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;



}

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

int main(){
	int h,i,m;
	;
	string A,B,S;

	for(;;){
	cin>>S;
	if(S == "-")
		break;

	cin>>m;
	for(i = 0;i < m;i++){
		cin>>h;

		A = S.substr(0,h);
		B = S.substr(h);
		S = B;
		S += A;
	}
	cout<<S<<endl;
}
return 0;
}

Measured memory_bytes: 1216
from collections import deque


def main():
    num_queues, num_queries = [int(x) for x in input().split(" ")]
    qs = [deque() for i in range(num_queues)]
    for i in range(num_queries):
        query = input()
        if (query[0] == '0'):
            cmd, q_idx, elem = [int(x) for x in query.split(" ")]
            qs[q_idx].appendleft(elem)
        elif (query[0] == '1'):
            cmd, q_idx = [int(x) for x in query.split(" ")]
            if qs[q_idx]:
                print(qs[q_idx][-1])
        elif (query[0] == '2'):
            cmd, q_idx = [int(x) for x in query.split(" ")]
            if qs[q_idx]:
                qs[q_idx].pop()


if __name__ == '__main__':
    main()



Measured memory_bytes: 14540
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		double x1 = scan.nextDouble();
		double y1 = scan.nextDouble();
		double x2 = scan.nextDouble();
		double y2 = scan.nextDouble();
		double dis = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
		System.out.printf("%f\n", dis);
	}
}

Measured memory_bytes: 28264
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
stack<ll>stk;
int main()
{
    ll n,open=0,close=0;
    scanf("%lld",&n);
    string s;
    cin>>s;
    for(ll i=0;i<n;i++)
    {
        if(s[i]==')')
        {
            if(stk.empty())
            {
                open++;
            }
            else stk.pop();
        }
        else
        {
            stk.push('(');
        }
    }
    while(!stk.empty())
    {
        close++;
        stk.pop();
    }
    for(ll i=0;i<open;i++)
    {
        cout<<"(";
    }
    cout<<s;
    for(ll i=0;i<close;i++)
    {
        cout<<")";
    }
    cout<<endl;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int N;
	std::vector<std::pair<int, int>> E;
	std::cin >> N;
	E.resize(N-1);
	for (auto& e : E) {
		std::cin >> e.first >> e.second;
		--e.first;
		--e.second;
	}

	std::vector<int> nneighs;
	std::vector<std::vector<std::pair<int /* neighbor node id */, int /* edge index */>>> neighs;
	nneighs.resize(N);
	neighs.resize(N);
	for (int i = 0; i < E.size(); ++i) {
		const auto& e = E[i];
		neighs[e.first].push_back({e.second, i});
		neighs[e.second].push_back({e.first, i});
		++nneighs[e.first];
		++nneighs[e.second];
	}
	int K = *std::max_element(nneighs.begin(), nneighs.end());

	std::unordered_set<int> arrived;
	std::vector<int> colors;
	colors.resize(N-1);
	std::queue<std::pair<int /* node id */, int /* incoming color id */>> q;
	q.push({0, 0});
	arrived.insert(0);

	while (!q.empty()) {
		int node = q.front().first;
		int incol = q.front().second;
		q.pop();
		int c = 1;
		for (const auto& neigh : neighs[node]) {
			int nextnode = neigh.first;
			int edgeidx = neigh.second;
			if (arrived.find(nextnode) != arrived.end())
				continue;
			if (c == incol)
				++c;
			colors[edgeidx] = c;
			q.push({nextnode, c});
			++c;
			arrived.insert(nextnode);
		}
	}

	std::cout << K << "\n";
	for (int c : colors) {
		std::cout << c << "\n";
	}
}


Measured memory_bytes: 12196
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();
        int x=0;
        if(a<=b){
             for(int i=a;i<=b; i++){
            if(c%i==0){
                x=x+1;
            }
            else{
                x=x;
            }
        }
        }
        else{
             for(int i=b;i<=a; i++){
            if(c%i==0){
                x=x+1;
            }
            else{
                x=x;
            }
        }
        }
        System.out.println(x);
    }
}

Measured memory_bytes: 26228
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
set<int> st[N];
void solve(){
	int n;
	string s;
	cin >> n >> s;
	rep(i, n) {
		st[s[i] - '0'].insert(i);
	}
	int cnt = 0;
	rep(i, 10){
		rep(j, 10){
			rep(k, 10){
				vector<int> v = {i, j, k};
				int mx = -1;
				bool ok = 1;
				rep(t, sz(v)){
					auto it = st[v[t]].upper_bound(mx);
					if(it == st[v[t]].end()) ok = 0;
					else mx = *it;
				}
				cnt += ok;
			}
		}
	}
	cout << cnt;

}	

 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


Measured memory_bytes: 48640
s = input()
n = len(s)
for i in range(1, n):
    if ord(s[i]) < 97 and s[i] != "C":
        print("WA")
        exit()
cnt_c = 0
for i in range(2, n - 1):
    if s[i] == "C":
        cnt_c += 1
if cnt_c != 1:
    print("WA")
    exit()
print("AC" if s[0] == "A" else "WA")

Measured memory_bytes: 3060
s = list(input())
t = list(input())
x = len(s)
y = len(t)
ans = "Yes"
for i in range(x):
  if (s[i] == t[i]) and (x+1 == y):
    ans = "Yes"
    continue
  else:
    ans = "No"
    break
print(ans)

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

int main(){
    int x,y,z;
    string s1, s2;
    char s;

    cin >> x >> y;
    
    if (x < 10 && y < 10 ){
        cout << x*y << endl;
    }else{
        cout << -1 << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
const int N=1e6+5;
const int mod=1e9+7;
struct node{
    int u,v,nxt;
};
struct Graph{
    node edge[N*2];
    int head[N];
    int mcnt;
    Graph(){memset(head,0,sizeof head);mcnt=0;}
    void add_edge(int u,int v){
        mcnt++;
        edge[mcnt].u=u;
        edge[mcnt].v=v;
        edge[mcnt].nxt=head[u];
        head[u]=mcnt;
    }
}G1,G2,G;
int n;
int f1[N],f2[N],a1[N],a2[N];
int rt1,rt2;
int s[N],top;
void dfs(Graph *g,int u){
    for(int i=g->head[u];i;i=g->edge[i].nxt){
        int v=g->edge[i].v;
        dfs(g,v);
    }
    if(a1[u])
        s[++top]=u;
    while(top>=2){
        G.add_edge(s[top],s[top-1]);
        G.add_edge(s[top-1],s[top]);
        top-=2;
    }
}
int color[N];
void dfs(int u,int c){
    color[u]=c;
    for(int i=G.head[u];i;i=G.edge[i].nxt){
        int v=G.edge[i].v;
        if(color[v]==0)
            dfs(v,-c);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        a1[i]=a2[i]=1;
    for(int i=1;i<=n;i++){
        scanf("%d",&f1[i]);
        if(f1[i]==-1)
            rt1=i;
        else{
            G1.add_edge(f1[i],i);
            a1[f1[i]]^=1;
        }
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&f2[i]);
        if(f2[i]==-1)
            rt2=i;
        else{
            G2.add_edge(f2[i],i);
            a2[f2[i]]^=1;
        }
    }
    for(int i=1;i<=n;i++)
        if(a1[i]!=a2[i]){
            puts("IMPOSSIBLE");
            return 0;
        }
    puts("POSSIBLE");
    top=0;
    dfs(&G1,rt1);
    top=0;
    dfs(&G2,rt2);
    for(int i=1;i<=n;i++)
        if(color[i]==0)
            dfs(i,1);
    for(int i=1;i<=n;i++)
        if(!a1[i])
            printf("0 ");
        else
            printf("%d ",color[i]);
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define BOARD_MAX 20

int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
int w, h;

int dfs(int count, int board[BOARD_MAX][BOARD_MAX], int sx, int sy)
{
	if (count == 10) return -1;

	int next_board[BOARD_MAX][BOARD_MAX];
	int ans = 100;

	rep(i, 0, 4)
	{
		rep(y, 0, h) rep(x, 0, w) next_board[y][x] = board[y][x];
		
		int xx = sx;
		int yy = sy;
		bool abort = false;
		bool init = true;
		
		while (1)
		{
			xx += dx[i];
			yy += dy[i];
			if (xx < 0 || w <= xx)
			{
				abort = true;
				break;
			}
			if (yy < 0 || h <= yy)
			{
				abort = true;
				break;
			}

			if (next_board[yy][xx] == 1)
			{
				if(init)
				{
					abort = true;
					break;
				}
				next_board[yy][xx] = 0;
				xx -= dx[i];
				yy -= dy[i];
				break;
			}
			else if (next_board[yy][xx] == 3)
			{
				return count + 1;
			}

			init = false;
		}

		if (abort) continue;
		int ret = dfs(count + 1, next_board, xx, yy);
		if (ret > 0) ans = min(ans, ret);
	}

	if (ans == 100)
		return -1;
	else
		return ans;
}

int main()
{
	while (1)
	{
		cin >> w >> h;
		if (w == 0) return 0;

		int board[BOARD_MAX][BOARD_MAX];
		int sx, sy;
		rep(y, 0, h) rep(x, 0, w)
		{
			cin >> board[y][x];
			if (board[y][x] == 2)
			{
				sx = x;
				sy = y;
				board[y][x] = 0;
			}
		}

		cout << dfs(0, board, sx, sy) << endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];  
    sort(a.begin(),a.end()); 
    vector<int> b;
    for(int i = 1; i < n; i++) {
        if(a[i]==a[i-1]) {
            b.push_back(a[i]);
            a[i]=-1;
        }
    }
    if(b.size()<2){
        cout << 0 << endl;
        return 0;
    }

    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    ll p=b[0],q=b[1];
    cout << p*q << endl;
    

    return 0;
}

Measured memory_bytes: 3960
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  bool used[n];
  for(int i = 0; i < n; ++i) used[i] = false;
  vector<int> V;
  int e[m];
  for(int i = 0; i < m; ++i)
    cin >> e[i];

  for(int i = m-1; i >= 0; --i){
    if(!used[e[i]-1]){
      V.push_back(e[i]-1);
      used[e[i]-1] = true;
    }
  }

  for(int i = 0; i < n; ++i)
    if(!used[i]) V.push_back(i);

  for(int i = 0; i < n; ++i) cout << V[i]+1 << endl;
  return 0;
}

Measured memory_bytes: 4496
// Problem : B - Popular Vote
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second

int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
vector<vec> ans(1e6 + 5);
//vec val1;
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int n,m;
   cin>>n>>m;
   vec v(n);
   fo(i,n)
   cin>>v[i];
   so(v);
   int s=0;
   fo(i, n)
       s += v[i];
   int val = ceil((s * 1.0) / (4 * m));
   for (int i = n - 1; i >= n - m;i--){
       if(v[i]<val){
           cout<<"No";
           return 0;
       }
   }
   cout << "Yes";
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl
ll bits(ll x){
	ll ans = 0;
	while(x){
		x/=2;
		ans++;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N);
	vector<ll> se;
	FOR(i,0,N)cin>>a[i];
	FOR(i,0,N){
		ll wa = 0;
		FOR(j,i,N){
			wa += a[j];
			se.push_back(wa);
		}
	}
	ll maxbit=0,ans=0;
	SORT(se);
	REV(se);
	for(ll x:se)maxbit=max(maxbit,bits(x));//
	maxbit = 63;
	//maxbit--;
	for(ll bit=maxbit;bit>0;bit--){
		vector<ll> vp;
		FOR(j,0,se.size()){
			if(se[j]&(1ll<<bit))vp.push_back(se[j]);
		}
		if(vp.size()>=K)se = vp;
		//for(auto x:se)cout << x<< " ";
		//cout << endl;
		if(se.size()==K)break;
	}
	ans = se[0];
	FOR(i,0,K)ans &= se[i];
	cout << ans << endl;
}


Measured memory_bytes: 6384
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

def num_of_elem(array)
  h = Hash.new{0}
  array.each do |key|
    h[key] += 1
  end
  h
end

num = num_of_elem(a)

ans = 1

(a.max+2).times do |i|
  ans = [num[i] + num[i-1] + num[i+1], ans].max
end

p ans


Measured memory_bytes: 15364
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const A = BigInt(lines[0]);
    const B = BigInt(lines[1]);
    console.log(A>B?"GREATER":A<B?"LESS":"EQUAL");
    
});


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

int N;
int C[500], S[500], F[500];

void solve(int i) {
  int t = S[i];
  while (i < N-1) {
    t += C[i];
    if (++i == N-1) break;
    int k = max(0, (t+F[i]-1 - S[i]) / F[i]);
    t = S[i] + k*F[i];
  }
  cout << t << endl;
}

int main() {
  cin >> N;
  rep(i, N-1) cin >> C[i] >> S[i] >> F[i];
  rep(i, N) solve(i);
  return 0;
}

Measured memory_bytes: 256
// AtCoder ABC128: B - Guidebook
// 2019.9.8 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int i, p; char *s; } T;
T t[105];

int cmp(const void *u, const void *v) {
	int t;
	if (t = strcmp(((T *)u)->s, ((T *)v)->s)) return t;
	return ((T *)v)->p - ((T *)u)->p;
}
	
char S[105][15];

int main()
{
	int i, N;
	
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%s%d", S[i], &t[i].p);
		t[i].s = S[i], t[i].i = i;
	}
	qsort(t, N, sizeof(T), cmp);
	for (i = 0; i < N; i++) printf("%d\n", t[i].i+1);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int h[100005];

int abse(int n)
{
    if(n<0) return -n;
    return n;
}
int solve(int i,int n,int dp[])
{
    if(i==n-2)return dp[i]= abse(h[n-2]-h[n-1]);
    if(i>n-2)  return dp[i]= 0;
    if(dp[i]!=-1) return dp[i];
    return dp[i]=min(abse(h[i+1]-h[i])+solve(i+1,n,dp),abse(h[i+2]-h[i])+solve(i+2,n,dp)) ;

}
int main(void)
{
    int n,i;
    cin>>n;
    int dp[n+5];
    memset(dp,-1,sizeof dp);
    for(i=0;i<n;i++)
        cin>>h[i];
    cout<<solve(0,n,dp);
}



Measured memory_bytes: 4096
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Usize1},
};

fn yes_no(f: bool) -> &'static str {
    if f {
        "Yes"
    } else {
        "No"
    }
}

#[fastout]
fn main() {
    input! {
        d: u32,
        t: u32,
        s: u32,
    }
    println!("{}", yes_no(d <= s * t));
}


Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main(void)
{
    
    long N, M, sum;
    long A[100000];
    sum = 0;
    
    cin >> N >> M;
    
    for(long i = 0; i < M; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    
    N -= sum;
    
    if(N < -1)
    {
        cout << -1;
    }
    else
    {
        cout << N;
    }
    
}

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

int main(void) {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());
	int res = 0;
	for (int i = 0; i < n; i++) res += a[i] * (i & 1 ? -1 : 1);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 1000000007
#define MAX 100005
ll fast_(ll n,ll k){
	ll base=1;
	while(k){
		if(k&1){
			base=(base*n)%mod;
		}
		n=(n%mod * n%mod)%mod;
		k/=2;
	}
	return base;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,j,sum=0,ch,ans,exclude;
    cin>>n>>k;
     vll ways(k+2,0);
    // no extra counting for k
    for(i=k;i>=1;--i){
    	ch=k/i;
    	ans=fast_(ch,n)%mod;
    	ways[i]=ans%mod;
    	exclude=0;
    	for(j=i*2;j<=k;j+=i){
    		exclude=(exclude+ways[j])%mod;
		}
		ways[i]=(ways[i]-exclude+mod)%mod;
    }
	for(i=1;i<=k;++i){
		ans=(ways[i]%mod * i%mod)%mod;
		sum=(sum+ans)%mod;
	}
	cout<<sum;
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long 
#define f(j) for(ll i=0;i<j;i++)
#define pb(i) push_back(i)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;    
typedef vector<vector<long long> > matrix; 
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	int n,x,t;
	cin>>n>>x>>t;
	int ans;
	ans = n/x;
	if(n%x)
		ans++;
	ans*=t;
	cout<<ans<<"\n";
return 0;	
}

Measured memory_bytes: 3628
<?php
define("MOD", 10**9+7);
list($n, $a, $b) = ints();
$nn = powerm(2,$n);
echo subm(subm(subm($nn,1), nCm($n, $a)), nCm($n, $b)) ;

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}

//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}

//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}

//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}

//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}

//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}

//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}

//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 61944
<?php
/*プログラムのイメージ
--入力-----
5
3 8 7 5 5
-----------
2*3=a+b
2*8=b+c
2*7=c+d
2*5=d+e
2*5=e+a
 
2*3=a+(2*8-c)
2*3=a+(2*8-(2*7-d))
2*3=a+(2*8-(2*7-(2*5-e)))
2*3=a+(2*8-(2*7-(2*5-(2*5-a))))
a+a=(2*3)-(2*8-(2*7-(2*5-(2*5))))
2a=(2*3)-(2*8)+(2*7)-(2*5)+(2*5)
a=3-8+7-5+5
a=2
 
e=(2*5)-a
e=8
 
d=(2*5)-e
d=2
 
c=(2*7)-d
c=12
 
b=(2*8)-c
b=4
*/
fscanf(STDIN,"%d",$N);
$lowA = fgets(STDIN);
$arrayA = explode(" ",$lowA);
$result = [];
 
//初期値設定
for($i=0;$i<$N;$i++){
  ${"mount".$i} = 0;
}
 
//1つ目の山に降った水計算
for($i=0;$i<$N;$i++){
  if($i%2===0){
    $mount0 += $arrayA[$i];
  }else{
    $mount0 -= $arrayA[$i];
  }
}
//最後の山に降った水計算
${"mount".($N-1)} = 2*$arrayA[$N-1]-$mount0;
//上記以外の山に降った水計算
for($i=$N-2;$i>0;$i--){
  ${"mount".($i)} = 2*$arrayA[$i]-${"mount".($i+1)};
}
 
for($i=0;$i<$N;$i++){
  $result[] = ${"mount".($i)};
}
 
echo implode(" ",$result);


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    
    int K, A, B;
    cin >> K >> A >> B;
    
    bool ok = false;
    for (int i = A; i <= B; ++i) {
        if (i % K == 0) {
            ok = true;
            break;
        }
    }
    
    cout << (ok ? "OK" : "NG") << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(long double,q,h,s,d,n);

  q *= 4.0;
  h *= 2.0;
  d /= 2.0;

  int ans = 0;
  if((int)n%2==0) {
    ans = n * min(q,min(h,min(s,d)));
  } else {
    ans = ((int)n/2)*2 * min(q,min(h,min(s,d)));
    //debug(ans);
    ans += min(q,min(h,s));
  }

  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			StringTokenizer tokenizer = new StringTokenizer(line, ",");
			int sum = 0;
			int[] nums = new int[10];
			for (int i = 0; i < 10; i++) {
				sum += Integer.parseInt(tokenizer.nextToken());
				nums[i] = sum;
			}
			double a = Double.parseDouble(tokenizer.nextToken());
			double b = Double.parseDouble(tokenizer.nextToken());

			double c = sum / (a + b) * a;

			for (int i = 0; i < 10; i++) {
				if (nums[i] >= c) {
					System.out.println(i + 1);
					break;
				}

			}
		}
	}
}

Measured memory_bytes: 16908
#include<cstdio>
int main(){
    bool is[30];
    for(int i=0;i<30;i++){
        is[i]=true;
    }
    int ins;
    for(int i=0;i<28;i++){
        scanf("%d",&ins);
        is[ins-1]=false;
    }
    for(int i=0;i<30;i++){
        if(is[i])printf("%d\n",i+1);
    }
}

Measured memory_bytes: 0
#define loop(i,j,k) for(long long i = j;i < k;i++)

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int n,p[100001];
    cin>>n;
    loop(i,0,n)cin>>p[i];
    int prev = 0;
    int res = 0;
    p[n] = -1;
    loop(i,0,n+1) {
        if(p[i] == i+1) {
            prev++;
        }
        else if(prev != 0) {
            res += (prev +1)/2;
            prev = 0;
        }
    }
    cout << res << endl;
}


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

using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define pb			    push_back

typedef long long ll;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int h, w, n;
	cin >> h >> w >> n;
	int grid[h][w];
	int color[n+1];
	clr(color, 0);
	for (int i = 1; i <= n; ++i)
		cin >> color[i];
	int c = 0;
	for (int i = 0; i < h; ++i) {
		if (i & 1) {
			for (int j = w - 1; j >= 0; --j) {
				while (color[c] == 0)
					c++;
				grid[i][j] = c;
				color[c]--;
			}
		} else {
			for (int j = 0; j < w; ++j) {
				while (color[c]== 0)
					c++;
				grid[i][j] = c;
				color[c]--;
			}
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cout << grid[i][j] << " ";
		}
		cout << endl;

	}

	return 0;
}

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

//#define int long long
//#define ll int long long
#define REP(i,n) for(int i=0;i<n;i++)
//#define ALL(vec) (vec).begin(),(vec).end()
//#define vint vector<int>
//#define pint pair<int,int>
//#define vpint vector<pint>
/*
int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
*/

string s;
int w;

signed main(){
    cin>>s>>w;
    for(int i=0;i<s.size();i+=w)cout<<s[i];
    cout<<endl;
}


Measured memory_bytes: 256
//By Zank100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define din(t) long long t;cin>>t;
#define in(t) cin>>t;

int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	din(n);
	ll a[n],dp[n]={0};
	for(ll i=0;i<n;i++)
	{
	    in(a[i]);
	}
	for(ll i=1;i<n;i++)
	{
	    if(a[i-1]>=a[i])
	    {
	        dp[i-1]++;
	    }
	}
	for(ll i=n-1;i>=0;i--)
	{
	    if(dp[i-1]!=0)
	    {
	        dp[i-1]+=dp[i];
	    }
	}
	sort(dp,dp+n);
	ll ans;
	ans=dp[n-1];
	
	if(ans<0) ans=0;
	
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#define inf 0x3f3f3f3f3f3f3f
typedef long long ll;
using namespace std;
int k,n,x;
int a[2010];
int query(int l,int r)
{
	int ans=inf;
	if(l>=1)
	{
		for(int i=l;i<=r;i++)
		ans=min(ans,a[i]);
	}
	else
	{
		for(int i=1;i<=r;i++)
		 	ans=min(ans,a[i]);
		l=l+n;
		for(int i=l;i<=n;i++)
			ans=min(ans,a[i]);
	}
	return ans;
}
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	ll ans=inf,sum;
	for(k=0;k<=n-1;k++)
	{
		sum=0;
		for(int i=1;i<=n;i++)
		{
			sum+=query(i-k,i);
		}
		sum+=x*k;
		ans=min(ans,sum);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 888
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;


int main(void) {
  string S;
  cin >> S;

  ll ans = 0;
  vector<int> v(S.length()+1, 0);
  rep(i, S.length()) {
    if (S[i] == '<') {
      v[i + 1] = v[i] + 1;
    }
  }
  for (int i = S.length() - 1; i >= 0; --i) {
    if (S[i] =='>') {
      if (v[i] <= v[i + 1]) {
        v[i] = v[i + 1] + 1;
      }
    }
  }

  rep(i, v.size()) {
    ans += v[i];
  }

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

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

int main() {
    i64 N; cin >> N;
    string X; cin >> X;
    reverse(X.begin(), X.end());

    i64 pc0 = 0;
    REP(i, N) {
        if (X[i] == '1') pc0++;
    }

    auto rem0 = [&](i64 mod, vector<i64> &pow2) {
        if (mod == 0) {
            return 1L;
        }
        i64 res = 0;
        pow2[0] = 1 % mod;
        REP(i, N) {
            if (X[i] == '1') {
                res += pow2[i] % mod;
            }
            pow2[i + 1] = pow2[i] * 2;
            pow2[i + 1] %= mod;
        }
        res %= mod;
        return res;
    };

    vector<i64> pow2p1(N + 1), pow2m1(N + 1);
    i64 rem0p1 = rem0(pc0 + 1, pow2p1);
    i64 rem0m1 = rem0(pc0 - 1, pow2m1);

    vector<i64> ans(N);
    REP(i, N) {
        if (pc0 == 1 && X[i] == '1') {
            ans[i] = 0;
            continue;
        }

        i64 cnt = 1;

        i64 x;
        if (X[i] == '1') {
            x = rem0m1 - pow2m1[i];
            x %= pc0 - 1;
            if (x < 0) x += pc0 - 1;
        } else {
            x = rem0p1 + pow2p1[i];
            x %= pc0 + 1;
            if (x < 0) x += pc0 + 1;
        }

        while (x > 0) {
            x %= __builtin_popcount(x);
            cnt++;
        }

        ans[i] = cnt;
    }

    ALL(reverse, ans);
    REP(i, N) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 8340
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int k;
  cin >> k;
  int count = 1;
  int b = (10%(9*k/7));
  if (k%7 == 0){
    while (true){
      if ((9*k/7)%2 == 0 or (9*k/7)%5 == 0){
        cout << "-1" << endl;
        break;
      }
      if (b%(9*k/7) == 1){
        cout << count << endl;
        break;
      }
      b = b%(9*k/7);
      count = count+1;
      b = 10*b;
    }
  }else{
    int b = (10%(9*k));
    while (true){
      if ((9*k)%2 == 0 or (9*k)%5 == 0){
        cout << "-1" << endl;
        break;
      }
      if (b%(9*k) == 1){
        cout << count << endl;
        break;
      }
      b = b%(9*k);
      count = count+1;
      b = 10*b;
    }
  }
  return 0;
}

Measured memory_bytes: 3644
// finish date: 2018/05/05
#include <bits/stdc++.h>


using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    if (A < B) swap(A, B);
    if (A < C) swap(A, C);
    cout << (A << K) + B + C << endl;


    return 0;
}

Measured memory_bytes: 256