akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int N = 210000;
VI g[N];
string s;

bool vis[N];
int possum[N]; // 2: indeterminate
bool dfs(int v) {
  if (vis[v]) return possum[v] != 0;
  int a = 0;
  int b = 0;
  vis[v] = true;
  possum[v] = 2;
  for (int w: g[v]) {
    if (dfs(w)) {
      if (s[w] == 'A') a = 1;
      else b = 1;
    }
    if (a == 1 && b == 1) {
      possum[v] = 1;
      return true;
    }
  }
  possum[v] = 0;
  return false;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m >> s;
  REP(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  VI ac(n), bc(n); // count of adjacent vertices
  REP(i, 0, n) {
    for (int w: g[i]) {
      if (s[w] == 'A') ac[i]++;
      else bc[i]++;
    }
  }
  queue<int> que;
  vector<bool> alive(n, true);
  REP(i, 0, n) {
    if (ac[i] == 0 || bc[i] == 0) que.push(i);
  }
  while (not que.empty()) {
    int v = que.front(); que.pop();
    if (not alive[v]) continue;
    // eliminate v
    alive[v] = false;
    for (int w: g[v]) {
      if (s[v] == 'A') ac[w]--;
      else bc[w]--;
      if (ac[w] == 0 || bc[w] == 0) {
	que.push(w);
      }
    }
  }
  bool ok = false;
  REP(i, 0, n) ok |= alive[i];
  cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 12624
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    if (n%2 == 0) {
      System.out.println(n/2);
    } else {
      System.out.println(n/2+1);
    }
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    size_t n;
    cin >> n;
    vector<int> v(n);
    for (size_t i = 0; i < n; ++i) {
        int a;
        cin >> a;
        v[i] = a;
    }
    auto p1 = partition(v.begin(), v.end(), [](int x) { return x % 2 == 1; });
    auto p4 = partition(p1, v.end(), [](int x) { return x % 4 == 0; });

    auto b1 = distance(v.begin(), p1);
    auto b4 = distance(p1, p4);
    auto b2 = distance(v.begin(), v.end()) - b1 - b4;

    if (b2 == 0) {
        cout << (b1 <= b4 + 1 ? "Yes" : "No") << endl;
    } else {
        cout << (b1 <= b4 ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#define Max 50
using namespace std;

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

    char b = a.back();
    if(b == 's'){
        a = a + "es";
    }else{
        a = a + "s";
    };
    cout << a << endl;
}


Measured memory_bytes: 3096
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int[10];
        for (int i = 0; i < 5; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        //var input = int.Parse(Console.ReadLine());



        if ((spliti[2] + spliti[4]) <= spliti[0] && (spliti[3] + spliti[4]) <= spliti[1])
        {
            if ((spliti[2] - spliti[4]) >= 0 && (spliti[3] - spliti[4]) >= 0)
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");
        }
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 8940
#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 ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    1-indexed であることに注意 !!
*/
template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= (i & (-i))) res += dat[i];
        return res;
    }

    T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    void add(int k, T x) {
        if (k == 0) return;
        for (int i = k; i <= n; i += (i & (-i))) dat[i] += x;
    }

    /*
        a[0] + a[1] + ... + a[res] >= x
    */
    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, k = 1;
        while (k < n) k <<= 1;
        for (; k > 0; k >>= 1) {
            if (res + k <= n && dat[res + k] < x) {
                x -= dat[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

signed main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    auto isOK = [&](ll x) {
        int sum[n + 1] = {};
        rep(i, n) {
            if (a[i] >= x)
                sum[i] = 1;
            else
                sum[i] = -1;
        }
        rep(i, n) {
            sum[i + 1] += sum[i];
        }
        ll cnt = 0;
        BIT<int> bit(2 * n);
        bit.add(n + 0, 1);
        rep(i, n) {
            cnt += bit.sum(n + sum[i]);
            bit.add(n + sum[i], 1);
        }
        return cnt >= ((ll)n * (n + 1) / 2 + 1) / 2;
    };
    ll ok = 0, ng = INF + 1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

inline int read(){
	char ch=getchar();int x=0,op=0;
	while(!isdigit(ch))op|=(ch=='-'),ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return op?-x:x;
}

const int N=100005,M=N*15;
const ll inf=1e18;
namespace G{
	struct edge{
		int u,v,f,c;ll w;int id;
	}e[M];
	ll f[N],d[N];
	int n,m,s,t,flag;
	vi g[N];
	inline void init(int _n,int _s,int _t,int _flag=1){
		n=_n,m=0,s=_s,t=_t,flag=_flag;
		rep(i,1,n)f[i]=0;
	}
	inline void add(int u,int v,int c,ll w){
		g[u].pb(m),w*=flag;
		e[m++]=(edge){u,v,0,c,w,(int)g[v].size()};
		g[v].pb(m);
		e[m++]=(edge){v,u,0,0,-w,(int)g[u].size()-1};
	}
	struct node{
		int u;ll d;
		inline friend bool operator < (node a,node b){
			return a.d>b.d;
		}
	};
	priority_queue<node> Q;
	int dij(){
		rep(i,1,n)d[i]=inf;
		d[s]=0,Q.push((node){s,0});
		while(!Q.empty()){
			node t=Q.top();Q.pop();
			if(d[t.u]!=t.d)continue;
			int u=t.u;
			for(auto k:g[u]){
				int v=e[k].v;
				if(e[k].f<e[k].c&&d[u]+e[k].w+f[u]-f[v]<d[v]){
					d[v]=d[u]+e[k].w+f[u]-f[v];
					Q.push((node){v,d[v]});
				}
			}
		}
		return d[t]<inf;
	}
	int in[N],r[N];
	int dfs(int u,int a){
		if(u==t)return a;
		ll res=0;in[u]=1;
		for(int &p=r[u];p<g[u].size();p++){
			int k=g[u][p],v=e[k].v;
			if(e[k].f<e[k].c&&d[u]+e[k].w+f[u]-f[v]==d[v]&&!in[v]){
				int tmp=dfs(v,min(a,e[k].c-e[k].f));
				res+=tmp,a-=tmp;
				e[k].f+=tmp,
				e[g[e[k].v][e[k].id]].f-=tmp;
			}
			if(!a)break;
		}
		return in[u]=0,res;
	}
	void mcmf(ll &flow,ll &cost){
		while(dij()){
			rep(i,1,n)r[i]=0;
			ll owo=dfs(s,2e9);
			flow+=owo,cost+=owo*(d[t]+f[t]);
			rep(i,1,n)f[i]=min(f[i]+d[i],inf);
		}
	}
}

int n,x,y,c,p0,p1,p2,p3,s,t,bas;

int main(){
	scanf("%d",&n);
	G::init(n*2+6,s=1,t=2,-1);
	p0=3,p1=4,p2=5,p3=6,bas=6;
	rep(i,1,n){
		scanf("%d%d%d",&x,&y,&c);
		G::add(s,bas+i,c,0);
		G::add(bas+i,p0,c,+x+y);
		G::add(bas+i,p1,c,+x-y);
		G::add(bas+i,p2,c,-x+y);
		G::add(bas+i,p3,c,-x-y);
	}
	bas+=n;
	rep(i,1,n){
		scanf("%d%d%d",&x,&y,&c);
		G::add(bas+i,t,c,0);
		G::add(p3,bas+i,c,+x+y);
		G::add(p2,bas+i,c,+x-y);
		G::add(p1,bas+i,c,-x+y);
		G::add(p0,bas+i,c,-x-y);
	}
	ll flow=0,cost=0;
	G::mcmf(flow,cost);
	cout<<-cost<<endl;

	return 0;
}

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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for(int i = 0;i < N;++i) cin >> t[i+1] >> x[i+1] >> y[i+1];
  bool can = true;
  for(int i = 0;i < N;++i) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if(dt < dist) can = false;
    if(dist % 2 != dt % 2) can = false;
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	int num;
	if (b < 10) num = a * 10 + b;
	else if (b < 100) num = a * 100 + b;
	else num = a * 1000 + b;
	bool f = false;
	for (int i = 4; i < 320; i++) {
		if (i * i == num) {
			f = true;
			break;
		}
	}
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 384
# coding: utf-8
# Your code here!
a,b,k=map(int,input().split())
ans=[]
if b-a+1>=2*k:
    for i in range(a,a+k):
        ans.append(i)
    for i in range(b,b-k,-1):
        ans.append(i)
else:
    for i in range(a,b+1):
        ans.append(i)
ans.sort()
ans2=map(str,ans)
print(" ".join(ans2))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int H,W;
  cin>>H>>W;
  vector<string> A(H);
  rep(i,H) cin>>A[i];
  int sum=0;
  rep(i,H) rep(j,W) if(A[i][j]=='#') sum++;
  if(sum==H+W-1) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n, m;
    cin >> n >> m;

    string s;
    cin >> s;

    ll dp[n+2];
    rep(i, n+2)dp[i] = INF;
    dp[0] = 0;
    rep(i, n+1){
        if(s[i] == '1')continue;
        for(ll j = 1; j <= min(i, m); ++j)dp[i] = min(dp[i], dp[i-j]+1);
    }

    if(dp[n] >= INF){
        cout << -1 << endl;
        return 0;
    }

    vector<ll> ans;
    ll p = n;
    while(p > 0){
        ll mv;
        for(ll i = 1; i <= min(p, m); ++i){
            if(dp[p-i] == dp[p]-1)mv = i;
        }
        ans.insert(ans.begin(), mv);
        p -= mv;
    }

    for(ll i : ans)cout << i << " ";
}

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

void Main()
{
	int N,X,T;
	cin>>N>>X>>T;
	cout<<((N+X-1)/X)*T<<_n;
}


void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3632
H,W = map(int,input().split())
grid = [input() for _ in range(H)]
inf = float('inf')
dp = [[inf]*W for _ in range(H)]
if grid[0][0] == '.':
    dp[0][0] = 0
else:
    dp[0][0] = 1

for i in range(H):
    for j in range(W):


        if i != 0:
            if grid[i][j] == grid[i-1][j] or grid[i][j] == '.':
                dp[i][j] = min(dp[i][j],dp[i-1][j])
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j]+1)

        if j != 0:
            if grid[i][j] == grid[i][j-1] or grid[i][j] == '.':
                dp[i][j] = min(dp[i][j],dp[i][j-1])
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1]+1)


print(dp[H-1][W-1])

# for i in range(H):
#     print(dp[i])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#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=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool ok[125252];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, k, r, s, p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  int ans=0;
  REP(i, n){
    bool f=false;
    if(i<k){
      f=true;
    }
    else{
      if(t[i]==t[i-k]){
        if(ok[i-k]){
          f=true;
        }
        else{
          ok[i]=true;
        }
      }
      else{
        f=true;
      }
    }
    if(f){
      if(t[i]=='r'){
        ans+=p;
      }
      if(t[i]=='s'){
        ans+=r;
      }
      if(t[i]=='p'){
        ans+=s;
      }
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 592
n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
done = [False] * n
s = []
cnt = 0
for i in range(n):
    if not done[i]:
        s.append(i)
        while not s == []:
            v = s.pop()
            done[v] = True
            for nxt in edge[v]:
                if not done[nxt]:
                    s.append(nxt)
        cnt += 1
print(cnt - 1)

Measured memory_bytes: 26344
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
int a,b,c;

int main() {
	read(a);read(b);read(c);
	cout<<b+min(c,a+b+1);
	return 0;
}

Measured memory_bytes: 256
import sys
N,M = map(int,sys.stdin.readline().rstrip().split())
A = list(map(int,sys.stdin.readline().rstrip().split()))

from collections import defaultdict

d = defaultdict(int)  # d[i] = (Aの中でi本用いて表せる最大の数)
for i in range(M):
    if A[i] == 1:
        d[2] = 1
    elif A[i] == 7:
        d[3] = 7
    elif A[i] == 4:
        d[4] = 4
    elif A[i] in [2,3,5]:
        d[5] = max(d[5],A[i])
    elif A[i] in [6,9]:
        d[6] = max(d[6],A[i])
    else:
        d[7] = 8

B = list(d.keys())
B.sort()

a = B[0]
B[0] = 0

if N % a == 0:
    print(''.join([str(d[a])]*(N//a)))
    exit()

from itertools import combinations_with_replacement

C = []

for i in range(N//a,max(-1,N//a-7),-1):  # aをi回用いる
    x = N-a*i
    for u in list(combinations_with_replacement(B,5)):
        if sum(u) == x:
            s = []
            for j in range(5):
                if u[j] != 0:
                    s.append(u[j])
            C.append((i,s))

D = []
for i,j in C:
    if i + len(j) == C[0][0] + len(C[0][1]):
        D.append((i,j))

m = min(D[i][0] for i in range(len(D)))

q,r,s = 0,0,0
for i,j in D:
    X = [d[a]]*(i-m) + [d[k] for k in j]
    X.sort(reverse=True)
    M = ''
    for k in X:
        M += str(k)
    M = int(M)
    if q < M:
        q,r,s = M,i,j

E = [d[a]]*r + [d[i] for i in s]
E.sort(reverse=True)

ans = ''
for i in E:
    ans += str(i)
print(ans)

Measured memory_bytes: 9508
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	long long ans = 0;
	for1(i, n){
		if(i % 3 == 0 || i % 5 == 0)continue;
		else ans += i;
		//deb(ans);
	}
	cout << ans;
	return 0;
}




Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int a, b, x;
double pi = 4.0 * atan(1.0);
bool f(double t){
    double val;
    if(t / 180 * pi >= atan((double)b / (double)a)){
        val = a * b * b * tan(pi/2 - t / 180 * pi) / 2.0;
    }
    else{
        val = a * a * b - a * a * a * tan(t / 180 * pi) / 2.0;
    }

    if(val < x){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    cin >> a >> b >> x;
    double ng = 0;
    double ok = 90;
    double mid;
    while(ok - ng > ok / 100000000){
        mid = (ok + ng) / 2.0;
        if(f(mid)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    printf("%28.12f\n", ok);


}

Measured memory_bytes: 4296
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

vector<Int> s;//累積和
Int N;

bool isOK_R(Int x, Int i) {//x回の攻撃で全滅するかどうか

	if (s[x] - s[i] < s[N] - s[x]) {
		return true;
	}
	else {
		return false;
	}
}

Int binary_search_R(Int i) {
	Int ng = N;
	Int ok = i+1; 

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		Int mid = (ok + ng) / 2;

		if (isOK_R(mid, i)) ok = mid;
		else ng = mid;
	}
	return ok;
}

bool isOK_L(Int x,Int i) {//x回の攻撃で全滅するかどうか

	if (s[x]-s[0]<s[i]-s[x]) {
		return true;
	}
	else {
		return false;
	}
}

Int binary_search_L(Int i) {
	Int ng = i; // 0が条件を満たすこともあるので、初期値は -1
	Int ok = 1; // 考えられる答えの上限

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		Int mid = (ok + ng) / 2;

		if (isOK_L(mid,i)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	cin >> N;

	vector<Int> A(N);
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}

	s.resize(N + 1);
	for (Int i = 0; i < N; i++) {
		s[i + 1] = s[i] + A[i];
	}

	Int ans = INF;
	Int tempL, tempR;
	Int mx, mn;
	for (Int i = 2; i <= N - 2; i++) {//真ん中の切れ目
		//左半分の最適化
		tempL = binary_search_L(i);
		if (abs(s[tempL] - (s[i] - s[tempL])) > abs(s[tempL + 1] - (s[i] - s[tempL + 1]))) {
			tempL++;
			if (tempL==i) {
				tempL--;
			}
		}

		//右半分の最適化
		tempR = binary_search_R(i);
		if (abs((s[N]-s[tempR]) - (s[tempR] - s[i])) > abs((s[N]-s[tempR+1]) - (s[tempR+1] - s[i]))) {
			tempR++;
			if (tempR==N) {
				tempR--;
			}
		}

		mx = max({ s[tempL],s[i] - s[tempL],s[tempR] - s[i],s[N] - s[tempR] });
		mn = min({ s[tempL],s[i] - s[tempL],s[tempR] - s[i],s[N] - s[tempR] });

		ans = min(ans, mx - mn);

	}

	cout << ans << "\n";

}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

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

  int pointer = 0;
  while (pointer < s.length()) {
    if(s.substr(pointer, 7) == "dreamer") {
      if (s[pointer+7] == 'a') {
        pointer += 5; 
        continue;
      } else {
        pointer += 7; 
        continue;
      }
    } else if(s.substr(pointer, 6) == "eraser") {
      pointer += 6; 
      continue;
    } else if(s.substr(pointer, 5) == "dream") {
      pointer += 5; 
      continue;
    } else if(s.substr(pointer, 5) == "erase") {
      pointer += 5; 
      continue;
    } else {
      cout << "NO\n";
      return 0;
    }
  }

  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
using namespace std;

int main()
{
	int n,tmp=0,sum=0;
	string s;
	cin >> n;
	s = to_string(n);
	tmp = n;
	for (int i = 0; i < s.length(); i++) {
		sum += n % 10;
		n /= 10;
	}
	cout << (tmp % sum == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		while(true) {
			int N=in.nextInt(),M=in.nextInt();
			if(N==0)break;
			int maxv[]=new int[M+1];
			for(int i=0;i<N;i++) {
				int d=Integer.parseInt(in.next()),v=Integer.parseInt(in.next());
				maxv[d]=Math.max(maxv[d], v);
			}
			int sum=0;
			for(int i=1;i<=M;i++)sum+=maxv[i];
			System.out.println(sum);
		}
	}
}



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

class M {
  static void Main(string[] __) {
    new M();
  }
  
  M() {
    var tmp = Console.ReadLine().Split(' ');
    int a = int.Parse(tmp[0]);
    int b = int.Parse(tmp[1]);
    int c = a * b;
    if ( c % 2 == 0 ) {
      Console.Write("Even");
    } else {
      Console.Write("Odd");
    }
  }
  
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long M=0,A=0,R=0,C=0,H=0;
    string ss;
    for(int i=0;i<n;i++)
    {
        cin >> ss;
        if(ss[0]=='M')
            M++;
        else if(ss[0]=='A')
            A++;
        else if(ss[0]=='R')
            R++;
        else if(ss[0]=='C')
            C++;
        else if(ss[0]=='H')
            H++;
    }
    long long ch=0;
    ch+=M*A*R;
    ch+=M*A*C;
    ch+=M*A*H;
    ch+=M*R*C;
    ch+=M*R*H;
    ch+=M*C*H;
    ch+=A*R*C;
    ch+=A*R*H;
    ch+=A*C*H;
    ch+=R*C*H;
    cout << ch << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define long long LL     
#define MAXN=1e4+10    


int main(){
	int a,b,c;
	int ans=0;
	cin>>a>>b>>c;
	if(a+b==c || a+c==b || b+c==a){
		ans=1;
	}
	if(ans==1){
		cout<<"Yes"<<endl;
	}else if(ans==0){
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		a = scanner.nextInt();
		b = scanner.nextInt();
		slove(0, 0, "");
	}

	private void slove(int x, int y, String s) {
		if (x == a && y == b) {
			System.out.println(s);
			return;
		}
		if ((x == 5 && y < 4) || (y == 5 && x < 4))
			return;
		if (x > a || y > b)
			return;

		slove(x + 1, y, s + "A");
		slove(x, y + 1, s + "B");
	}

	int a, b;
}

Measured memory_bytes: 17388
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<=A) cout << K << endl;
    else if(K<=A+B) cout << A << endl;
    else cout << A-(K-A-B) << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

const ll mod = 1000000007;
struct Mod
{
	ll num;
	Mod() : num(0) { ; }
	Mod(ll n) : num(n % mod) { ; }
	operator ll() { return num; }
};


Mod operator+(Mod a, Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator-(Mod a, Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator*(Mod a, Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator+=(Mod &a, Mod b) { return a = a + b; }
Mod operator-=(Mod &a, Mod b) { return a = a - b; }
Mod operator^(Mod a, ll n)
{
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod inv(Mod a) { return a ^ (mod - 2); }
Mod operator/(Mod a, Mod b) { return a * inv(b); }

Mod fact(Mod n)
{
	if (n < 0) assert(false);
	if (n == 0 || n == 1) return 1;
	else return n*fact(n - (Mod)1);
}

Mod nPk(Mod n, Mod k)
{
	if (n < 0 || k < 0 || n < k) assert(false);
	return fact(n) / fact(k);
}

Mod nCk(Mod n, Mod k)
{
	if (n < 0 || k < 0 || n < k) assert(false);
	return nPk(n, k) / fact(n - k);
}

Mod nHk(Mod n, Mod k)
{
	if (n < 0 || k < 0 || n < k) assert(false);
	return nCk(n + k - (Mod)1, k);
}


ll n, d, x;
Mod dp[2222][2222];
int main()
{
	while (cin >> n >> d >> x, n)
	{
		REP(i, 2222)REP(j, 2222) dp[i][j] = 0;
		Mod N(n), D(d);
		dp[0][0] = 1;
		FOR(i, 1, n + 1)FOR(j, 1, n + 1)
		{
			dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1];
			if (j >= x) dp[i][j] -= dp[i - 1][j - x];
		}
		Mod ans = 0;
		FOR(i, 1, min(d + 1, n + 1))
		{
			Mod tmp = (Mod)dp[i][n];
			REP(j, i)
			{
				tmp = (Mod)(d - j + mod)*tmp;
				tmp = tmp*inv(Mod(i - j + mod));
			}
			ans += tmp;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 41652
N=int(input())
A=list(map(int,input().split()))
from itertools import accumulate
C=[0]+list(accumulate(A))
l,r=1,3
x=10**16
for m in range(2,N-1):
    a,b,c,d=C[l],C[m]-C[l],C[r]-C[m],C[N]-C[r]
    while l<m-1 and abs(C[m]-C[l+1]*2)<abs(a-b):
        l+=1
        a,b=C[l],C[m]-C[l]
    while r<N-1 and abs(C[N]-C[r+1]*2+C[m])<abs(c-d):
        r+=1
        c,d=C[r]-C[m],C[N]-C[r]
    x=min(x,max(a,b,c,d)-min(a,b,c,d))
print(x)

Measured memory_bytes: 25676
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	char s[4];
	scanf("%s",s);
	if((s[0]=='a' || s[1]=='a' || s[2]=='a')	&&
	(s[0]=='b' || s[1]=='b' || s[2]=='b')	&&
	(s[0]=='c' || s[1]=='c' || s[2]=='c'))	{
		printf("Yes\n");
	}
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> H >> W;
    auto c1 = make_vec<char>(H, W, char('.'));
    auto c2 = make_vec<char>(2 * H, W, char('.'));
    REP(i, H)
    REP(j, W)
    cin >> c1[i][j];
    REP(i, 2 * H)
    REP(j, W)
    c2[i][j] = c1[i / 2][j];
    REP(i, 2 * H) {
        REP(j, W)
        cout << c2[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,i,sw;
  sw=0;
  scanf("%d",&n);
long long int a[n],sum[n],ans,temp;
  scanf("%lld",&a[0]);
  sum[0]=a[0];
  for(i=1;i<n;++i)
  {
  scanf("%lld",&a[i]);
  sum[i]=sum[i-1]+a[i];
  }
  int cc=0;
  
  ans=llabs(sum[n-1]-sum[0]*2);
    for(i=1;i<n-1;++i)
    {
    temp=llabs(sum[n-1]-sum[i]*2);
    if(temp<ans) ans=temp;
    }
  printf("%lld",ans);
return 0;}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main() {
   ll n,c=0,mi=INT_MAX;
   cin>>n;
   ll arr[n];
   for(int i=0;i<n;i++)
    cin>>arr[i];
   for(int i=-100;i<=100;i++){
       for(int o=0;o<n;o++){
        c=pow(abs(i-arr[o]),2)+c;
    }
    mi=min(c,mi);
    c=0;
   }
   cout<<mi;
   return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int N;
string X;

int m0_list[200001];
int m1_list[200001];

int cnt_list[200001];

int mod(string s, int n)
{
	int cur = 0;
	for (int i = 0; i < s.length(); i++)
	{
		cur = cur << 1;
		if (s[i] == '1')
		{
			cur += 1;
		}
		cur %= n;
	}
	return cur;
}

void make(int list[200001], int n)
{
	int cur = 1;
	for (int i = 1; i <= 200000; i++)
	{
		cur = cur % n;
		list[i] = cur;
		cur <<= 1;
	}
}

int get_cnt(int n)
{
	int cur = n;
	int cnt = 0;
	while (cur > 0)
	{
		if ((cur & 1LL) != 0)
		{
			cnt++;
		}
		cur >>= 1;
	}
	if (cnt == 0) return 0;
	int a = n % cnt;
	return 1 + get_cnt(a);
}

signed main()
{
	cin >> N;
	cin >> X;

	int cnt = 0;
	for (int i = 0; i < X.length(); i++)
	{
		if (X[i] == '1') cnt++;
	}


	for (int i = 1; i <= 200000; i++)
	{
		cnt_list[i] = get_cnt(i);
	}

	make(m0_list, cnt + 1);
	if (cnt - 1 > 0)
	{
		make(m1_list, cnt - 1);
	}

	int m0 = mod(X, cnt + 1);
	int m1 = cnt == 1 ? 0 : mod(X, cnt - 1);

	for (int i = 0; i < X.length(); i++)
	{
		int keta = (X.length() - i);
		if (X[i] == '0')
		{
			int m = (m0 + m0_list[keta]) % (cnt + 1);
			int a = cnt_list[m];
			cout << (a + 1) << endl;
		}
		else
		{
			if (cnt - 1 == 0)
			{
				cout << 0 << endl;
			}
			else
			{
				int m = (m1 - m1_list[keta]) % (cnt - 1);
				if (m < 0) m += (cnt - 1);
				int a = cnt_list[m];
				cout << (a + 1) << endl;
			}
		}
	}

}



Measured memory_bytes: 8080
import sys
sys.setrecursionlimit(10**7)
n,A,B,C = map(int,input().split())
L_ls = [int(input()) for _ in range(n)]

# dfs(i,a,b,c) := i番目の竹のまえの時点で、A用の長さがa, B用の長さがb, C用の長さがcだった時の、それ以降の分岐での最初コスト
def dfs(i,a,b,c):
    if i == n:
        if a==0 or b == 0 or c == 0:
            return float('inf')
        else:
            return abs(a-A) + abs(b-B) + abs(c-C)
    
    Min = dfs(i+1,a,b,c)

    if a == 0:
        Min = min(Min,dfs(i+1,a+L_ls[i],b,c))
    else:
        Min = min(Min,dfs(i+1,a+L_ls[i],b,c)+10)
    
    if b == 0:
        Min = min(Min,dfs(i+1,a,b+L_ls[i],c))
    else:
        Min = min(Min,dfs(i+1,a,b+L_ls[i],c)+10)
    
    if c == 0:
        Min = min(Min,dfs(i+1,a,b,c+L_ls[i]))
    else:
        Min = min(Min,dfs(i+1,a,b,c+L_ls[i])+10)
    
    return Min
print(dfs(0,0,0,0))

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int N;
int A[20];
int x[20][20];
int y[20][20];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int ans;ans=0;
    int a;
    bool flg;flg=true;
    REP1(i,N){
        cin>>a;
        if(a==i){
            if(flg){
                ans++;
                flg=false;
            }else{
                flg=true;
            }
        }else{
            flg=true;
        }  
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;



signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n];
        f(i,0,n-1)
        {
            cin>>a[i];
            if(a[i]==0)
            {
                cout<<0<<endl;
                return 0;
            }
        }
        ll ans=1;
        f(i,0,n-1)
        {
            if(ans==0)
            {
                break;
            }
            if(ans*a[i] > llinf or a[i]>llinf/ans)
            {
                ans=-1;
                break;
            }
            ans=(ans * a[i] * 1LL);
            if(ans>(ll)1e18)
            {
                ans=-1;
                break;
            }
        }
        cout<< ans <<endl;
    }
    return 0;
}

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

const int N = 2500 + 10;
const int INF = (1 << 30) - 1;

std::vector<std::pair<int, int>> neighbors[N];
bool in_queue[N];
int dist[N], times[N];
int n, m, p;

int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < m; ++ i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    neighbors[u].push_back(std::make_pair(v, w - p));
  }

  for (int i = 1; i <= n; ++ i) {
    dist[i] = -INF;
  }
  dist[1] = 0;

  std::queue<int> queue;
  queue.push(1);
  while (!queue.empty()) {
    int u = queue.front();
    queue.pop();
    in_queue[u] = false;
    for (auto x : neighbors[u]) {
      int v = x.first;
      int w = x.second;
      if (dist[u] + w > dist[v]) {
        dist[v] = dist[u] + w;
        if (!in_queue[v]) {
          queue.push(v);
          in_queue[v] = true;
          times[v] ++;
          if (times[n] > n) {
            puts("-1");
            return 0;
          }
        }
      }
    }
  }
  if (dist[n] >= INF) {
    puts("-1");
  } else {
    printf("%d\n", std::max(0, dist[n]));
  }
  return 0;
}


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

int main() {
  int a, b; cin >> a >> b;
  int p = a + b;
  int mi = a - b;
  int mu = a*b;
  int an = max (p, mi);
  int ans = max (an, mu);
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
from fractions import gcd
import functools
l=[(hoge.append(gcd(hoge[i-1],a[i])),hoge)[1] for hoge in [[a[0]]] for i in range(1, n)][0]
r=[(hoge.append(gcd(hoge[i-1],a[n-1-i])),hoge)[1] for hoge in [[a[n-1]]] for i in range(1, n)][0][::-1]
print(functools.reduce(lambda x,y:max(x,y),[gcd(l[i-1]if 0<i else r[i+1],r[i+1]if i<n-1 else l[i-1])for i in range(n)]))

Measured memory_bytes: 14400
(defun solve (n)
  (declaim (optimize (speed 3) (debug 0) (safety 0)))
  (let ((tmp 0))
    (loop for i from 1 to n
          do (setq tmp (+ tmp i))
          when (<= n tmp)
          return (loop for j from 1 to i
                   unless (= (- tmp n) j)
                   collect j))))

(format t "~{~A~%~}" (solve (read)))

Measured memory_bytes: 10984
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;

struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};
In in;

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

template <typename T>
T gcd(T x,T y){
    if (y == 0) return x;
    return gcd(y,x%y);
}

template <typename T>
T lcm(T x,T y){
    return x*y/gcd(x,y);
}

int main(){
    ll n=in,n2=n;
    string ans="";
    char al;
    int t;
    while (n2!=0){
        t=n2%26;
        n2/=26;
        if (t==0) {
            t=26;
            n2--;
        }
        al=(char)('a'+t-1);
        ans+=al;
    }
    reverse(ans.begin(),ans.end());
    out(ans);
}

Measured memory_bytes: 3632
n,k=map(int,input().split( ))

m=(n-2)*(n-1)//2

if m<k:
    print(-1)
else:
    l=m-k
    line=[]
    for i in range(n-1):
        line.append((1,i+2))
    
    counter=0
    for j in range(2,n):
        if counter==l:
            break
        for i in range(j+1,n+1):
            line.append((j,i))
            counter+=1
            if counter==l:
                break
        if counter==l:
            break
    print(len(line))
    for i in range(len(line)):
        print(str(line[i][0])+' '+str(line[i][1]))


Measured memory_bytes: 41968
#include <stdio.h>

int main(){
  int N;
  int arr[100000];
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&arr[i]);
  }
  int cnt=0;
  for(int pointer=0;pointer!=1;pointer=arr[pointer]-1){
    cnt++;
    if(cnt>100005) {cnt=-1; break;}
  }
  printf("%d",cnt);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    int r, D, init_x;
    cin >> r >> D >> init_x;
    int now = init_x;
    RANGE(i, 10){
        now = r*now - D;
        cout << now <<endl;
    }
}


Measured memory_bytes: 256
use std::io;
use std::f64::consts::PI;
fn main(){
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let a: f64 = s.trim().parse().unwrap();
    
    println!("{:.6} {:.6}", a * a * PI, 2f64 * PI * a);
}


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

int main()
{
    int n,l;
    cin >> n >> l;
   vector<string> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    for(int i = 0; i < n; i++){
        cout << a.at(i);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <regex>
#include <stack>
#include <queue>
#include <vector>
#define MAX_N 100
#define INF 10000000

using namespace std;
int n;
pair<int,int> r[MAX_N];
pair<int,int> b[MAX_N];

void solve() {
	int ans = 0;
	sort(r, r + n);
	sort(b, b + n);
	for (int i = 0; i < n; i++) {
		int N = n;
		while (N > 0) {
			if (b[i].first > r[N - 1].second&& b[i].second > r[N - 1].first) {
				ans++;
				r[N - 1].first = INF;
				r[N - 1].second = INF;
				break;
			}
			else N--;
		}
	}
	cout << ans << endl;
}
int main() {
	cin >> n;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		r[i].second = a;
		cin >> a;
		r[i].first = a;
	}
	for (int i = 0; i < n; i++) {
		cin >> a;
		b[i].first = a;
		cin >> a;
		b[i].second = a;
	}
	solve();
	return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Fijk = new long[N][];
            for (var i = 0; i < N; ++i)
                Fijk[i] = Sarray();
            var Pij = new long[N][];
            for (var i = 0; i < N; ++i)
                Pij[i] = Sarray();
            var lst = 1 << 10;
            var ans = long.MinValue;
            // 時間帯に対する開店を全通り試す
            for (var i = 1; i < lst; ++i)
            {
                var open = new long[N];
                var mask = 1;
                for (var j = 0; j < 10; ++j)
                {
                    if (0 != (mask & i))
                    {
                        // 時間帯jに開いている店を確認
                        for (var m = 0; m < N; ++m)
                        {
                            if (Fijk[m][j] != 0)
                                ++open[m];
                        }
                    }
                    mask <<= 1;
                }
                var prf = 0L;
                // 同時に開いている店の数
                for (var j = 0; j < N; ++j)
                    prf += Pij[j][open[j]];
                ans = Max(ans, prf);
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396