akhauriyash/Code-Regression huggingface dataset:
# abc153_a.py
# https://atcoder.jp/contests/abc153/tasks/abc153_a

# A - Serval vs Monster /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# サーバルはモンスターと戦っています。
# モンスターの体力は Hです。
# サーバルが攻撃を 1回行うとモンスターの体力を A減らすことができます。 
# 攻撃以外の方法でモンスターの体力を減らすことはできません。
# モンスターの体力を 0以下にすればサーバルの勝ちです。
# サーバルがモンスターに勝つために必要な攻撃の回数を求めてください。

# 制約
#     1≤H≤104
#     1≤A≤104
#     入力中のすべての値は整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# H A

# 出力
# サーバルがモンスターに勝つために必要な攻撃の回数を出力せよ。

# 入力例 1
# 10 4

# 出力例 1
# 3
#     1回目の攻撃の後のモンスターの体力は 6です。
#     2回目の攻撃の後のモンスターの体力は 2です。
#     3回目の攻撃の後のモンスターの体力は −2です。

# よって 3回の攻撃でモンスターに勝つことができます。

# 入力例 2
# 1 10000

# 出力例 2
# 1

# 入力例 3
# 10000 1

# 出力例 3
# 10000


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    H, A = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = -(H//(-A))

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['10 4']
        lines_export = [3]
    if pattern == 2:
        lines_input = ['1 10000']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['10000 1']
        lines_export = [10000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int ap[1000000+20],n,a[200000+20];
int main(){
	fastio;
	cin>>n;
	rb(i,1,n) {
		cin>>a[i];
		
	}
	sort(a+1,a+1+n);
	rb(i,1,n){
		if(a[i]==a[i-1]){
			ap[a[i]]=1;
		}
	}
	int res=0;
	rb(i,1,n){
		if(!ap[a[i]])
			res++;
		if(a[i]!=a[i-1]){
			for(int j=2*a[i];j<=1000000;j+=a[i]){
				ap[j]=1;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    bool ok=true;
    if(s.length()%2 == 0)
    {
        for (int i = 0; i < s.length(); i+=2)
        {
            if(s[i]!='h' || s[i+1] != 'i')
            {
                ok = false;
            }
        }
        
    }
    else
    {
        ok=false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c,x;
  while(cin>>n>>a>>b>>c>>x, n){
    int y[n];
    for(int i=0;i<n;++i) cin>>y[i];
    int ans=-1, cnt=0;
    for(int i=0, j=0;i<10001;++i){
      if(x==y[j]){
        cnt++, j++;
        if(cnt==n) ans=i;
      }
      x = (a*x+b)%c;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

vector<int> g[401];
int in[401], out[401];
bool vis[401];

bool go(int v){
	if (g[v].empty())return true;
	vis[v] = true;
	bool ok = in[v] != out[v];
	f(i, 0, g[v].size())if (!vis[g[v][i]])ok |= go(g[v][i]);
	return ok;
}

int main(){
	int n, h;
	scanf("%d%d", &n, &h);
	f(i, 0, n){
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x, y;
		if (c == 0)x = a; else x = c + 200;
		if (d == 0)y = b + 200; else y = d;
		++in[y];
		++out[x];
		g[x].push_back(y);
		g[y].push_back(x);
	}
	bool ok = true;
	f(i, 0, h + 1)if (in[i] > out[i])ok = false;
	f(i, 201, h + 201)if (out[i] > in[i])ok = false;
	f(i, 0, 401)if (!vis[i])ok &= go(i);
	printf("%s\n", ok ? "YES" : "NO");
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long size = sc.nextInt();
		long max = 0;
		long total = 0;

		for(long i=0; i<size; i++) {
			long sci = sc.nextInt();
			if(max < sci) max = sci;
			else if(max > sci) total += max - sci;
		}
		
		System.out.println(total);
	}
}


Measured memory_bytes: 58772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int A, B;
	cin >> A >> B;
	int money = 0;
	while(money <= 100000) {
		money++;
		if((int)(money * 0.08) == A && (int)(money * 0.1) == B) {
			cout << money << "\n";
			return 0;
		}
	}
	cout << -1 << "\n";
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int inf=1e18;
int32_t main()
{
	int A=in();int B=in();int q=in();int x;
	vector<int> s(A+2),t(B+2);
	s[0]=t[0]=-inf;
	for(int i=1;i<=A;i++)s[i]=in();
	for(int i=1;i<=B;i++)t[i]=in();
	s[A+1]=inf;t[B+1]=inf;
	
	while(q--)
	{
		x=in();
		int s1=*lower_bound(all(s),x);
		int t1=*lower_bound(all(t),x);
		auto i=upper_bound(all(s),x);i--;
		int s2=*i;
		i=upper_bound(all(t),x);i--;int t2=*i;
		//cout<<s1<<" "<<s2<<" "<<t1<<" "<<t2<<"\n";
		//s1t1 or t1s1
		int s1t1=abs(t1-s1)+min(abs(x-s1),abs(x-t1));
		//s1t2 or t2s1
		int s1t2=abs(t2-s1)+min(abs(x-t2),abs(x-s1));
		//s2t1 or t1s2
		int s2t1=abs(s2-t1)+min(abs(x-t1),abs(x-s2));
		//s2t2
		int s2t2=abs(s2-t2)+min(abs(s2-x),abs(t2-x));
		
		cout<<min({s1t1,s1t2,s2t1,s2t2})<<"\n";
		
	}
	
	
}

Measured memory_bytes: 4832
import itertools as it
H,W,N=map(int,input().split())
c=[list(input()) for t in range(H)]
ans=0
for con in it.product(range(2),repeat=H):
  for row in it.product(range(2),repeat=W):
    count=0
    for h in range(H):
      for w in range(W):
        if c[h][w]=='#' and con[h]==1 and row[w]==1 :
          count+=1
    if count==N:
      ans+=1
print(ans)
      

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


void solve(long long M, long long D) {
	int res = 0;
	reps(j, 1, M+1) {
		reps(i, 1, D+1) {
			res += (i / 10 >= 2) && (i % 10 >= 2) && ((i / 10) * (i % 10) == j);
		}
	}
	cout << res << endl;
}

signed main() {
	long long M;
	scanf("%lld",&M);
	long long D;
	scanf("%lld",&D);
	solve(M, D);
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC_173_A_C_sharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int s = 0;
            for (int i = 1; i <= 10; i++)
            {
                N %= (i * 1000);
                if (N % 1000 == 0)
                {
                    break;
                }
                s = 1000 - N;
            }
            //N = (1000 - N % 1000) % 1000;
            Console.WriteLine(s.ToString());
            Console.ReadKey();
        }
    }
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int count = 0;
  vector<int> A(3);
  A[0] = a;
  A[1] = b;
  A[2] = c;
  sort(A.begin(),A.end());
  //cout << A[0] << A[1] << A[2] << endl;
  while(A[0] < A[2]-1){
    A[0] += 2;
    ++count;
  }
  while(A[1] < A[2]-1){
    A[1] += 2;
    ++count;
  }
  //cout << A[0] << A[1] << A[2] << endl;
  if (A[0] == A[1] && A[1] == A[2]){
    cout << count << endl;
  }
  else if(A[0] == A[1]){
    cout << count+1 << endl;
  }
  else {
    cout << count+2 << endl;
  }
  return 0;
}


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

using namespace std;

using ll = long long;

using T = tuple<int, int, int>;

const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};

const int INF = 1000000000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    int ans = 0;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
        for (int j = 0; j < W; j++) {
            ans += (s[i][j] == '.');
        }
    }

    vector< vector<int> > d(H, vector<int>(W, INF));
    queue<T> q;
    q.emplace(0, 0, 0);
    while (!q.empty()) {
        int x, h, w;
        tie(x, h, w) = q.front();
        q.pop();
        if (d[h][w] <= x) continue;
        d[h][w] = x;
        if (h + 1 == H && w + 1 == W) {
            break;
        }
        for (int i = 0; i < 4; i++) {
            int nh = h + dh[i], nw = w + dw[i];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (d[nh][nw] <= x + 1) continue;
            if (s[nh][nw] == '#') continue;
            q.emplace(x + 1, nh, nw);
        }
    }
    if (d[H - 1][W - 1] == INF) cout << -1 << endl;
    else cout << ans - d[H - 1][W - 1] - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (2147483647)
#define MOD (int)(998244353) 

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    vector<int> arr(n);
    for(int &i : arr) cin >> i;
    sort(arr.begin(), arr.end(), greater<int>());
    for(int i = 0; i < n; ++i) sum += arr[i];
    double step = 1.0/(4.0 * (double) m);
    for(int i = 0; i < m; ++i) {
        if((double)arr[i] < (step * (double) sum)) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

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

int main() {
    string s;
    cin>>s;
    if(s[s.length()-1]=='s') cout<<s<<"es"<<endl;
    else cout<<s<<"s"<<endl;
}

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

typedef long long LL;

using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef tuple<string,int> P;
template<typename T>
istream &operator>>(istream& is,vector<T>& v){
    for(auto &it:v)is>>it;
    return is;
}
vector<int> getid(string s,string t){
    int n=s.size();
    int m=t.size();
    vector<int> res;
    for(int i=0;i<n;i++){
        bool f=true;
        if(i+m>n)continue;
        for(int j=0;j<m;j++)
            if(s[i+j]!=t[j])f=false;
        if(f){
            res.push_back(i);
            i=i+m-1;
        }
    }
    reverse(res.begin(),res.end());
    return res;
}
int main(){
    for(int n;cin>>n,n;){
        vector<string> a(n),b(n);
        for(int i=0;i<n;i++)cin>>a[i]>>b[i];
        set<string> memo;
        queue<P>que;
        string s,t;
        cin>>s>>t;
        memo.insert(s);
        que.push(P(s,0));
        int res=-1;
        while(que.size()){
            string now;int cost;
            tie(now,cost)=que.front();que.pop();
            //cout<<now<<endl;
            for(int i=0;i<n;i++){
                string x,y,z;
                auto id=getid(now,a[i]);
                z=now;
                for(auto&it:id){
                    //cout<<it;
                    x=z.substr(0,it);
                    y=z.substr(it+a[i].size(),z.size()-it-a[i].size());
                    z=x+b[i]+y;
                }
                if(z.size()>10)continue;
                if(z==t){
                    res=cost+1;
                    break;
                }
                if(memo.count(z)==0){
                    que.push(P(z,cost+1));
                    memo.insert(z);
                }
                //  cout<<endl;
            }
            
            if(res!=-1)break;
        }
        cout<<res<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3228
#include<iostream>

using namespace std;

static const int MAX = 25;
static const int nil = -1;

struct Node { int l, p, r; };

int n;
Node A[MAX];

void Pre(int tmp) {
	if (tmp == nil) {
		return;
	}
	cout << " " << tmp;
	Pre(A[tmp].l);
	Pre(A[tmp].r);
}

void In(int tmp) {
	if (tmp == nil) {
		return;
	}
	In(A[tmp].l);
	cout << " " << tmp;
	In(A[tmp].r);
}

void Post(int tmp) {
	if (tmp == nil) {
		return;
	}
	Post(A[tmp].l);
	Post(A[tmp].r);
	cout << " " << tmp;
}

int main() {
	int l, r, id;
	cin >> n;
	for (int i = 0; i < n; i++) {			//初期化
		A[i].l = nil;
		A[i].p = nil;
		A[i].r = nil;
	}

	for (int i = 0; i < n; i++) {			//データを繋げる
		cin >> id >> l >> r;
		A[id].l = l;
		A[id].r = r;
		if (A[id].l != nil) {
			A[l].p = id;
		}
		if (A[id].r != nil) {
			A[r].p = id;
		}
	}

	for (int i = 0; i < n; i++) {
		if (A[i].p == nil) {
			cout << "Preorder" << endl;
			Pre(i);
			cout << endl;
			cout << "Inorder" << endl;
			In(i);
			cout << endl;
			cout << "Postorder" << endl;
			Post(i);
			cout << endl;

		}
	}
	return 0;
}


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

int main()
{
    int n;int b=-1;
    int i;string s;
    cin>>n;
    map<string,int>x;

    for(i=0;i<n;i++)
    {
        cin>>s;
        x[s]++;

       b=max(b,x[s]);
    }
    map<string,int>::iterator itr;
    for(itr=x.begin();itr!=x.end();itr++)
    {
        if(itr ->second == b)
        {
            cout<<itr->first<<endl;
        }
    }
}

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

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

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

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


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

bool dp[100010];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    VLL a(n);
    rep(i,n) cin >> a[i];
    FOR(i,1,k+1){
        bool flag = false;
        rep(j,n){
            if(a[j] <= i && dp[i-a[j]] == false){
                flag = true;
                break;
            }
        }
        dp[i] = flag;
    }
    cout << (dp[k]?"First":"Second") << endl;;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const int BITSIZE = 100010;


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n, q; cin >> n >> q;
    vector<vector<ll> > v(n);
    REP(i, q){
        int a, b, c; cin >> a;
        if(a==0){
            cin >> b >> c;
            v[b].push_back(c);
        }
        if(a==1){
            cin >> b;
            for(int i=0; i<v[b].size(); ++i){
                if(i) cout << " ";
                cout << v[b][i];
            }
            cout << endl;
        }
        if(a==2){
            cin >> b;
            v[b].clear();
        }
    }
	return 0;
}


Measured memory_bytes: 9016
def resolve():
    n, k = map(int, input().split())
    flag = [1 for i in range(n)]
    for i in range(k):
        d = int(input())
        Sunukes = list(map(int, input().split()))
        for sunuke in Sunukes:
            flag[sunuke-1] = 0
    print(sum(flag))
resolve()

Measured memory_bytes: 67848
#include<iostream>
#include<vector>
#include<map>

using namespace std;

struct Memo
{

  int count;
  bool flag;

  Memo()
  {
    count = 0;
    flag = false;
  }

};

Memo memo[31][4];

int ProgressNumberOfYears(int step_num, int step_kind)
{

  int kind_count = 0;

  if(step_num == 0) return 1;
  else if(memo[step_num][step_kind].count) return memo[step_num][step_kind].count;

  for(int i = 1; i < 4; ++i) if(step_num - i >= 0) kind_count = kind_count + ProgressNumberOfYears(step_num - i,i);

  memo[step_num][step_kind].count = kind_count;

  return kind_count;

}

int main()
{

  int step_num;

  while(cin >> step_num && step_num != 0) cout << ProgressNumberOfYears(step_num,0)/10/365 + 1<< endl;

  return 0;

}

Measured memory_bytes: 1160
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return (this- 1)>>1; };
    Number.prototype.leftIdx = function() { return (this<<1) + 1; };
    Number.prototype.rightIdx = function() { return (this<<1) + 2; };
  }

  insert(key) { this.heapIncrease(this.keys.push(key) - 1); }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx()) {
      keys[p] = [keys[i], keys[i] = keys[p]][0];
    }
  }

  extract() {
    const res = this.keys[0];
    this.keys[0] = this.keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys, n = keys.length;
    const innerMaxHeapify = (i) => {
      let left, right, largest = i;
      left = i.leftIdx();
      right = i.rightIdx();
      if (left < n && keys[left] > keys[largest]) largest = left;
      if (right < n && keys[right] > keys[largest]) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n').slice(0, -1);
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()}\n`; break;
    }
  });
  process.stdout.write(str);
})();




Measured memory_bytes: 204000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const long long mod = 1000000007;


// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

void solve(long long K, std::string S){
    ll N = S.size();
    /*
    まずは|S|+Kの長さの文字列Uが何通りあるか計算
    そこから余事象としてSが含まれないものの通り数を引いていく。
    Sが含まれないとは、丁度n文字目まで含まれ、n+1文字目が含まれないという条件でMECEに分割可能
    例えば、S= "abc"だっととして、Uの部分文字列にaがありbが現れない場合、abがありcが現れない場合....
    例えばabまで現れる場合を考える。最初にその出現位置を決めると、
    文字列は(xxxx,a,yyyy,b,zzzz)となるが、xにaが含まれないこと、yにbが含まれないこと、zにcが含まれないことが
    条件となる。
    これを一般化させるとk文字目まで含まれる部分文字列の候補はcombination(|S|,k)*pow(25,部分文字列以外の部分の長さ)
    となる。
    */
    mint ans = mint(26).pow(N+K);
    combination com = combination(int(1e6)*2+5);
    //
    for(ll i=0;i<N;i++){
        ans -=com(K+N,i)*(mint(25).pow(K+N-i));
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 36612
#include<stdio.h>
int main(void){

int a,b;

 scanf("%d %d",&a,&b);

 if(a<b){
   printf("a < b\n");
 }else if(a>b){
   printf("a > b\n");
 }else{
   printf("a == b\n");
 };
 

 return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
long long a, b, c, d;
long long num(long long e)
{
	long long tempa = (a % e == 0) ? (long long)a / e - 1 : (long long)a / e;
	long long tempb = (long long)b / e;
	return (long long) tempb - tempa;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	cin >> a >> b >> c >> d;
	long long ans = b - a + 1;
	long long lcm = __gcd(c, d);
	lcm = (long long)c * d / lcm;
	long long three = num(lcm);
	long long one = num(c);
	long long two = num(d);
//	cout << one << ' ' << two << ' ' << three << '\n';
	ans -= (long long)one + two - three;
	cout << ans << '\n';
	return 0;
} 

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

using int64 = long long;

int main() {
  int64 n, k;
  cin >> n >> k;
  vector<int64> a(n);
  for (int64 i = 0; i < n; ++i)
    cin >> a[i];

  int64 x = 0;
  for (int64 b = 1LL << 50; b; b >>= 1) {
    if ((b | x) > k)
      continue;
    int64 s0 = 0, s1 = 0;
    for (int64 aa : a) {
      s0 += (b & aa);
      s1 += (b & aa) ^ b;
    }
    if (s1 > s0)
      x += b;
  }

  int64 sum = 0;
  for (int64 aa : a)
    sum += x ^ aa;
  cout << sum << "\n";

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        Sort(a);
        int sum = 0;
        for(int i = 0; i < n[1]; i++)
            sum += a[i];
        WriteLine(sum);
    }
}


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

int main(){

  int A,B,T;

  cin>>A>>B>>T;

  long long cnt=0;
  
  for(int i=A;i<=T;i+=A){
	cnt+=B;
  }

  cout<<cnt<<endl;
  
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=input().split()
l=[None]*n
b=[None]*n
for i in range(n):
    l[i]=int(a[i])
s=0
while 1:
    for i in range(n):
        b[i]=l[i]%2
    if 1 in b:
        break
    for j in range(n):
        l[j]=l[j]/2
    s+=1
print(s)

Measured memory_bytes: 3060
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.begin(),v.end(),greater<int>());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
using namespace std;
int main()
{
    rj
    ll a,b,i,k;
    cin>>k>>a>>b;
    for(i=a ; i<=b ; i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }

    }
    cout<<"NG"<<endl;



    return 0;
}


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

int main(){
  int map[2020] = {};
  int n,m;
  cin >> n;
  int koma[n+1] = {};
  for(int i=1; i<=n; ++i){
    int tmp;
    cin >> tmp;
    map[tmp] = 1;
    koma[i] = tmp; 
  }
  cin >> m;
  for(int i=0; i<m; ++i){
    int tmp;
    cin >> tmp;
    //cout << koma[tmp] << endl; 
    if(map[koma[tmp]+1] != 1 && koma[tmp] != 2019){
      map[koma[tmp]] = 0;
      map[koma[tmp]+1] = 1;
      ++koma[tmp];
    }
  }
  for(int i=1; i<=2019; ++i){
    if(map[i] == 1){
      cout << i << endl;
    }
  }
}


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

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***スニペット***
ifelse, isprime, torad, todeg, lcm, bfs
****************/

//隣接リスト
vector<int> to[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    double ans=0.0,A;
    rep(i,0,n){
        cin >> A;
        ans+=1.0/A;
    }
    cout << fixed << setprecision(20);
    cout << (long double)1.0/ans ENDL;
    
    return 0;
}

Measured memory_bytes: 6148
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

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

struct Edge {
	int s;
	int t;
	int cost;
	Edge() {}
	Edge(int s, int t, int cost) : s(s), t(t), cost(cost) {}
};
bool operator < (const Edge& e, const Edge& f) { return e.cost < f.cost; }

int root(int* par, int x)
{
	if (x==par[x]) return x;
	else return par[x] = root(par, par[x]);
}

void unite(int* par, int x, int y)
{
	par[root(par, x)] = root(par, y);
}

bool isSame(int* par, int x, int y)
{
	return root(par, x) == root(par, y);
}

int main()
{
	int n, m;
	while (true) {
		std::cin >> n >> m;
		if (n == 0) break;
		std::vector<Edge> edge_list;
		for (int i=0; i<m; i++) {
			int s, t, cost;
			std::cin >> s >> t >> cost;
			edge_list.push_back( Edge(s, t, cost) );
		}
		std::sort(edge_list.begin(), edge_list.end());
		int* par = new int[n];
		for (int i=0; i<n; i++) par[i] = i;
		int res = 0;
		int count = 0;
		for (int i=0; i<edge_list.size(); i++) {
			if (isSame(par, edge_list[i].s, edge_list[i].t)) continue;
			unite(par, edge_list[i].s, edge_list[i].t);
			res += edge_list[i].cost;
			count++;
			if (count == n-1) break;
		}
		std::cout << res << std::endl;
		delete[] par;
	}
	return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")

using namespace std;

#define inp "TestCode.inp"
#define out "TestCode.out"
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileInOut freopen(inp,"r",stdin);freopen(out,"w",stdout);
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pi acos(-1)
#define pii pair<int,int>
#define ppiii pair< pair <int,int> ,int>
#define INF 1000000
#define endl '\n'
#define ll long long
#define pq priority_queue
const int mod=1e9+7;
int test=1;
/*-----------------------------------------------*/
void nathan_on_osu()
{
    FAST
    #ifndef ONLINE_JUDGE
    //FileInOut
    #endif // ONLINE_JUDGE
}
/*-----------------------------------------------*/

string s;

int main()
{
    nathan_on_osu();
    cin>>s;
    for(int i=0;i<=2;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N, K;
    cin >> N >> K;
    vector<long long> h;
    rep(i, 0, N) {
        long long high;
        cin >> high;
        h.push_back(high);
    }
    sort(h.begin(), h.end());
    long long min = INF;
    rep(i, 0, N - K + 1) { chmin(min, h[i + K - 1] - h[i]); }

    cout << min << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    vector<int> A(N);
    double mul = 1;
    
    for(int i=0; i<N; i++){
        cin >> A[i];
        mul *= A[i];
    }
    
    double c = 0;
    for(int i=0; i<N; i++){
        c += mul/A[i];
    }
    
    cout << fixed << setprecision(20) << (double)mul/c << endl;
    
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
using namespace std;
const int SIZE=5*1e5;
const int INF=1<<30;
int main(){
	string s;
	int H,W;
	cin >> H >> W;
	REP(i,H) REP(j,W){
		cin >> s;
		if(s=="snuke") cout << char('A'+j) << i+1 << endl;
	}
	return 0;
}

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

int main(){
    string sa, sb, sc;

    cin >> sa >> sb >> sc;


    char turn = 'a';
    //sa.erase(0, 1);
    char vic;
    while(1){
        if(turn == 'a'){
            if(sa.size() == 0){
                vic = 'a';
                break;
            }
            turn = sa[0];
            //printf("turn a discard %c\n", turn);
            sa.erase(0, 1);
        }
        else if(turn == 'b'){
            if(sb.size() == 0){
                vic = 'b';
                break;
            }
            turn = sb[0];
            //printf("turn b discard %c\n", turn);
            sb.erase(0, 1);
        }
        else if(turn == 'c'){
            if(sc.size() == 0){
                vic = 'c';
                break;
            }
            turn = sc[0];
            //printf("turn c discard %c\n", turn);
            sc.erase(0, 1);
        }
    }

    if(vic == 'a'){
        printf("A\n");
    }
    else if(vic == 'b'){
        printf("B\n");
    }
    else if(vic == 'c'){
        printf("C\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
int main() {
  
  string s;
  cin>>s;
  int length=(int)(s.length()+0.5);
  
  
  int wc=0;
  for(int i=0;i<length/2;i++){
  	char a=s[i];
    char b=s[length-i-1];
    //cout<<a<<","<<b<<endl;
    a==b? :wc++;
  }

  cout<<wc<<endl;
  return 0;
}

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


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

    int ans = 0;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum = 0;
        if (i%2 == 1) {
            for (int j = 1; j < i/2; j++) {
                if (i%j == 0) sum++;
            }
        }
        if (sum == 7) ans++;
    }

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

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<deque>
#include<tuple>
#include<stdio.h>
#include<iomanip>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n;
	cin>>n;
	if(n%1000>0)
		cout<<1000-n%1000<<endl;
	else
		cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;


  for(int i=1;i<=n;i++){
    int cnt = 0;
    for(int x=1;x<=100;x++){
      for(int y=1;y<=100;y++){
        int a = (x+y)*(x+y) - 4*(x*x+y*y+x*y-i);
        if(a < 0) continue;
        int ra = sqrt(a);
        if(ra*ra!=a) continue;
        int z = (-x-y+ra)/2;
        if(z > 0){
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }

}

Measured memory_bytes: 3636
using System;

class aoj1041{
	public static void Main(){
		while(true){
			int n = int.Parse(Console.ReadLine());
			if(n == 0) return;
			n = n / 4;
			int answer = 0;
			for(int i = 0; i < n; i++){
				answer += int.Parse(Console.ReadLine());
			}
			Console.WriteLine(answer);
		}
	}
}

Measured memory_bytes: 5596
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			Long[] h = new Long[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextLong();
			}

			if (n <= k) {
				System.out.println(0);
				return;
			}

			Arrays.sort(h, Collections.reverseOrder());

			long sum = 0;
			for (long v : Arrays.copyOfRange(h, k, n)) {
				sum += v;
			}
			System.out.println(sum);
		}
	}
}


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

int main(){
	ll n,a,b; scanf("%lld%lld%lld",&n,&a,&b);
	if (n==1 && b-a+1>1){ puts("0"); return 0; }
	if (a>b){ puts("0"); return 0; }
	printf("%lld\n",b*(n-1)+a-(a*(n-1)+b)+1); return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Array
import Data.Maybe
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt
 
solve :: Int -> [Int] -> Int
solve k = sum . drop k . sortBy (flip compare) . change . sort

change :: [Int] -> [Int]
change [] = []
change (x:xs) = go xs x 1
    where go [] n c = [c]
          go (x:xs) n c
            | n == x = go xs n (c+1)
            | otherwise = c : go xs x 1 
 
main :: IO ()
main = do
    [n, k] <- getInts
    ls <- getInts
    print (solve k ls)

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

#define endl '\n'

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

    int a, b; cin >> a >> b;
    for (int i = 1; i<= 100000; i++){
        if (i*2/25 == a && i/10 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1\n";
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim().split(" ");
    var N = parseInt(input[0],10);
    var K = parseInt(input[1],10);

    if (K == 1) {
        console.log(0);
    }
    else {
        console.log(N - K);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
int N; cin >> N; int cnt = 0;
  for(int i = 0; i < N; i++){ int a; cin >> a; if(a%2){ cnt++;}}
  
  if(cnt%2){ cout << "NO" << endl;} else{ cout << "YES" << endl;}
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int n,ans=0,cnt=0,a[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]==i){
			cnt++;
		}
		else{
			ans+=(cnt+1)/2;
			cnt=0;
		}
	}
	ans+=(cnt+1)/2;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 640
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

readInt :: B.ByteString -> Maybe (Int,B.ByteString)
readInt xs = do
    (x,ys) <- B.readInt xs
    return (x,B.tail ys)

main :: IO ()
main = do
    (a,b,c) <- (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) . VU.unfoldrN 3 readInt <$> B.getLine
    putStrLn $ if c-a-b>0 && 4*a*b < (c-a-b)^2 then "Yes" else "No"

Measured memory_bytes: 380
#include <iostream>
#include <math.h>

using namespace std;

void f(long int H, long int &ans, int level){
  
  if(H <= 1){
  	ans = ans + pow(2,level);
    return;
  }
  else{ 
  	ans  = ans + pow(2,level);
    f(H/2,ans,level+1);
  }
}

int main(){
	  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long int  H;
  cin>>H;
  
  long int ans = 0;
  
  f(H,ans,0);
  
  cout<< ans <<endl;
  
  return 0;
}


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

string s;

void print () {
    int start, end;
    cin >> start >> end;
    cout << s.substr(start, end-start+1) << endl;
}

void replace () {
    int start, end;
    string re;
    cin >> start >> end >> re;
    int j = 0;
    for (int i = start; i <= end; i++) {
        s[i] = re[j];
        j++;
    }
    // cout << s << endl;
}

void reverse () {
    int start, end;
    cin >> start >> end;
    string rev;
    rev = s.substr(start, end-start+1);
    // cout << rev << endl;
    int j = rev.size() - 1;
    for (int i = start; i <= end; i++) {
        s[i] = rev[j];
        j--;
    }
    // cout << s << endl;
}

int main () {
    cin >> s;
    int n;
    cin >> n;
    string func;
    for (int i = 0; i < n; i++) {
        cin >> func;
        if (func == "print") print();
        else if (func == "replace") replace();
        else if (func == "reverse") reverse();
    }
}


Measured memory_bytes: 3200
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	}

	vector<int> dp(n, inf);
	dp.at(0) = 0;

	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i - j >= 0)
			{
				dp.at(i) = min(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j)));
			}
		}
	}

	cout << dp.at(n - 1) << endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.math.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static BigInteger value = new BigInteger("0");
	static BigInteger average = new BigInteger("0");
	static BigInteger number = new BigInteger("0");
	
	public static void main(String[] args) {
		read();
		solve();
	}
	static boolean read(){
		number = sc.nextBigInteger();
		if(number.intValue() == 0)return false;
		for(int i = 0; i < number.intValue(); i++)
			value = value.add(sc.nextBigInteger());
		return false;
	}
	static void solve(){
		average = value.divide(number);
		System.out.println(average);
	}
	
}

Measured memory_bytes: 13000
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

vector<int>v = { 1,5,10,50,100,500 };
int getpay(int money,const vector<int>&ns) {
	int ans = 0;
	for (int i = 5; i>=0;--i) {
		if (money) {
			const int use = min(ns[i], money / v[i]);
			money -= use*v[i];
			ans += use;
		}
	}
	if (money)return 1e8;
	else return ans;
}

int main() {
	while (1) {
		int P; cin >> P;
		if (!P)break;
		vector<int>ns(6);
		vector<int>clerks(6, 10000);
		for (int i = 0; i < 6; ++i)cin >> ns[i];
		int sum = 0;
		for (int i = 0; i < 6; ++i)sum += ns[i] * v[i];
		int ans = 1e8;
		for (int pay = P; pay <= sum; ++pay) {
			ans = min(ans, getpay(pay, ns) + getpay(pay-P, clerks));
		}
		cout << ans << endl;

	}
	return 0;
}

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



namespace CSharpSample01
{

    
    class Program
    {

        static int Solve(char[,] grid)
        {
            int H = grid.GetLength(0);
            int W = grid.GetLength(1);

            //L[i, j] := (i, j)マスに明りを置いたときに照らすことができる左側のマス数
            //R[i, j] := (i, j)マスに明りを置いたときに照らすことができる右側のマス数
            //D[i, j] := (i, j)マスに明りを置いたときに照らすことができる下側のマス数
            //U[i, j] := (i, j)マスに明りを置いたときに照らすことができる上側のマス数
            //それぞれ(i, j)を含んだマス数
            int[,] L = new int[H, W];
            int[,] R = new int[H, W];
            int[,] D = new int[H, W];
            int[,] U = new int[H, W];

            //L, R, D, U を求める
            //L
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    if (grid[i, j] == '#') L[i, j] = 0;
                    else if (j == 0) L[i, j] = 1;
                    else L[i, j] = L[i, j - 1] + 1;
                }
            }
            //R
            for(int i = 0; i < H; i++)
            {
                for(int j = W - 1; j >= 0; j--)
                {
                    if (grid[i, j] == '#') R[i, j] = 0;
                    else if (j == W - 1) R[i, j] = 1;
                    else R[i, j] = R[i, j + 1] + 1;
                }
            }
            //U
            for (int j = 0; j < W; j++)
            {
                for (int i = 0; i < H; i++)
                {
                    if (grid[i, j] == '#') U[i, j] = 0;
                    else if (i == 0) U[i, j] = 1;
                    else U[i, j] = U[i - 1, j] + 1;
                }
            }
            //D
            for (int j = 0; j < W; j++)
            {
                for(int i = H - 1; i >= 0; i--)
                {
                    if (grid[i, j] == '#') D[i, j] = 0;
                    else if (i == H - 1) D[i, j] = 1;
                    else D[i, j] = D[i + 1, j] + 1;
                }
            }

            //照らすことが出来るマスの最大数
            int ans = 0;

            //L, R, U, D を使ってansを更新
            //(i, j)に明りをおいたときの照らすことが出来るマス数は
            //R[i, j] + L[i, j] + U[i, j] + D[i, j] - 3
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    ans = Math.Max(ans, R[i, j] + L[i, j] + U[i, j] + D[i, j] - 3);
                }
            }

            return ans;

        }
        
        static void Main(string[] args)
        {
            //入力1(H, W)
            string[] input = Console.ReadLine().Split(' ');
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);

            //grid[i, j] := (i, j)マスの状態
            char[,] grid = new char[H, W];

            //入力2(grid)
            for(int i = 0; i < H; i++)
            {
                string str_row = Console.ReadLine();
                for(int j = 0; j < W; j++)
                {
                    grid[i, j] = str_row[j];
                }
            }

            Console.WriteLine(Solve(grid));
            
        }
    }

}

Measured memory_bytes: 85448
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N=input()
A=map(int, sys.stdin.readline().split())

S=defaultdict(lambda: 0) 
S[0]=3  #初期化

mod=10**9+7
ans=1
for x in A:
    ans*=S[x]
    ans%=mod
    S[x+1]+=1
    S[x]-=1

print ans%mod


Measured memory_bytes: 52064