akhauriyash/Code-Regression huggingface dataset:
#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>;

const int INF = 1001001001;
vector<int> to[100005];

int main() {
  int R;
  cin >> R;
  
  double PI = acos(-1);
  double ans = 2.0 * PI * (double) R;
  
  cout << fixed << setprecision(12);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6156
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int h, w;
	cin >> h >> w;

	char table[h][w];
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
			cin >> table[i][j];
	}

	vector<bool> row(h, true);
	for (int i = 0; i < h; i++)
	{
		bool f = false;
		for (int j = 0; j < w; j++)
		{
			if (table[i][j] == '#')
				f = true;
		}
		if (!f)
			row[i] = false;
	}

	vector<bool> column(w, true);
	for (int j = 0; j < w; j++)
	{
		bool f = false;
		for (int i = 0; i < h; i++)
		{
			if (table[i][j] == '#')
				f = true;
		}
		if (!f)
			column[j] = false;
	}

	for (int i = 0; i < h; i++)
	{
		bool f = false;
		for (int j = 0; j < w; j++)
		{
			if (row[i] && column[j])
			{
				cout << table[i][j];
				f = true;
			}
		}
		if (f)
			cout << endl;
	}
}



Measured memory_bytes: 256
import sys
import bisect
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,t = map(int,read().split())
    li = list(map(int,read().split()))
    now = -1e18
    ans = 0
    for ti in li:
        if now < 0:
            now = ti
        else:
            ans += min(t,ti-now)
            now = ti
        
    print(ans+t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25744
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod = 1e9 + 7;
signed main()
{
	int n,m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	for(int i = 0;i < n; ++i) cin >> a[i];
	for(int j = 0;j < m; ++j) cin >> b[j];
	
	vector<vector<int>> dp(n+1,vector<int>(m+1,0));
	
	for(int i=1;i <= n; ++i)
	{
		for(int j=1; j<= m; ++j)
		{
			dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + mod)%mod;
			if(a[i-1] == b[j-1])
			{
				dp[i][j] += (1 + dp[i-1][j-1])%mod;
			}
		}
	}
	
	cout << dp[n][m]%mod + 1;
}


Measured memory_bytes: 31616
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>

#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include<atcoder/all>

using namespace std;

using namespace atcoder;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << endl
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
void Yes(bool cond) { cout << (cond ? "Yes" : "No") << '\n'; }
void YES(bool cond) { cout << (cond ? "YES" : "NO") << '\n'; }

ll op(ll a, ll b) { return max(a, b); }
ll e() { return -INF; }
ll target;
bool f(ll v) { return v < target; }


void solve() {
	int N, Q; cin >> N >> Q;
	vector<ll>A(N);
	REP(i, N)cin >> A[i];
	segtree<ll,op,e>seg(A);
	REP(_, Q) {
		int t; cin >> t;
		if (t == 1) {
			int x, v; cin >> x >> v;
			x--;
			seg.set(x, v);
		}
		else if(t==2){
			int l, r; cin >> l >> r;
			print(seg.prod(l - 1, r));
		}
		else {
			int x, v; cin >> x >> v;
			x--;
			target = v;
			print(seg.max_right<f>(x) + 1);
		}
	}
}



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

	//int q;
	//cin >> q;
	//while (q--)
	solve();

}



Measured memory_bytes: 9000
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    if b == 1 {
        println!("{}", 0);
    } else {
        let mut count = 1;
        while (a - 1) * (count - 1) + a < b {
            count += 1;
        }
        println!("{}", count);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define f first
#define s second
typedef long long ll;
typedef std::pair<ll, ll> pll;
ll g(ll a,ll b){
	if(a==0)return b;
	ll x;
	while(1){
		x=a%b;
		if(x==0)return b;
		else{
			a=b;
			b=x;
		}
	}
}
int main(){
	ll N,X,D;
	std::cin>>N>>X>>D;
	if(D<0){
		X*=-1;
		D*=-1;
	}
	ll a=0;
	if (D==0){
		if(X==0)a=1;
		else a=N+1;
	}
	else{
		std::vector<pll> S(N+1);
		rep(i,N+1){
			S[i].f=X*i+D*i*(i-1)/2;
			S[i].s=S[i].f+D*i*(N-i);
			if(S[i].f>S[i].s)
				std::swap(S[i].f,S[i].s);
			a+=(S[i].s-S[i].f)/D+1;
			int p=i-D/g(abs(X),D);
			if(p>=0){
				pll E=S[p];
				E.f=std::max(E.f,S[i].f);
				E.s=std::min(E.s,S[i].s);
				if(E.f<=E.s)
					a-=(E.s-E.f)/D+1;
			}
		}
	}
	std::cout<<a<<std::endl;
	return 0;
}

Measured memory_bytes: 3328
# a = 1,2,3,4,5,2,1,1
# s = {0}
# for j in a:s |= {x+i for x in s} という手もある
#set()は重複を許さずソート→探索がO(1)

n = int(input())
A = list(map(int,input().split()))
q = int(input())
p = set()

for i in range(2**n):
    sum = 0
    for j in range(n):
        if i>>j & 1:
            sum += A[j]
    p.add(sum)

M = list(map(int,input().split()))

for i in range(q):
    m =  M[i]
    if m in p:
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5660
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i*m+j*n-2*i*j==k)
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

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

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 100005;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}
int n;
vector<pii>adj[mx];
bool rong[mx];
void dfs(int u,int pa,int col)
{
    rong[u]=col;
    for(pii p:adj[u])
    {
        int v=p.ff;
        int c=p.ss;
        if(v!=pa)
        {
            dfs(v,u,(col+c)%2);
        }
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        adj[u].pb({v,w});
        adj[v].pb({u,w});
    }
    dfs(1,-1,0);
    for(int i=1;i<=n;i++)cout<<rong[i]<<endl;
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define pqll priority_queue<ll>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) ll a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define qll queue<ll>
#define sll set<ll>
#define inf LLONG_MAX


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

	int n;
	cin>>n;
	map<int,int> m;
	for(int x=1;x*x<=n;x++)
	{
		for(int y=1;y*y<=n;++y)
		{
			for(int z=1;z*z<=n;z++)
			{
				int t=x*x+y*y+z*z+x*y+x*z+y*z;
				m[t]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
		cout<<m[i]<<'\n';
	return 0;
}


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

using namespace std;

#define x first
#define y second
typedef long long ll;

const int MOD = 1000000007;
const int oo = 1e9;
typedef pair<int,int> pii;

const int N = 1e6+10;


int n,k;
ll a[1001];
vector<ll> all;

int main(){
  cin >> n >> k;
  for (int i = 0; i < n; ++i)scanf("%lld",&a[i]);
  for (int i = 0 ; i < n ; ++i){
    ll sum = 0;
    for(int j = i ; j < n ; ++j){
      sum += a[j];
      all.push_back(sum);
    }
  }
  ll pre = 0,ans = 0;
  for(ll bit = 60 ; bit >= 0 ; --bit){
    ll nw = pre | (1ll<<bit);
    int cnt = 0;
    for(auto v : all)
      if((v&nw)==nw)cnt++;
    if(cnt >= k){
      pre |= (1ll<<bit);
      ans += (1ll<<bit);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N,W; cin>>N>>W;
    vector<ll> w(N),v(N);
    rep(i,N) cin>>w[i]>>v[i];

    vector<ll> val[4];
    rep(i,N) val[w[i]-w[0]].pb(v[i]);

    rep(i,4) sort(all(val[i]));
    rep(i,4) reverse(all(val[i]));

    vector<vector<ll>> cs(4,vector<ll>(N+10,0));
    for(int i=0;i<4;i++){
        if(val[i].size()==0) continue;
        for(int j=0;j<sz(val[i]);j++){
            cs[i][j+1] = cs[i][j] + val[i][j];
        }
    }

    ll ans = 0;
    for(int i=0;i<=sz(val[0]);i++){
        for(int j=0;j<=sz(val[1]);j++){
            for(int k=0;k<=sz(val[2]);k++){
                for(int l=0;l<=sz(val[3]);l++){
                    if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3)>W) break;
                    ll sum = cs[0][i] + cs[1][j] + cs[2][k] + cs[3][l];
                    ans = max(ans,sum);
                }
            }
        }
    }
    cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String tmp = null;
		int cup = 0;
		String[] rrr;
		
		while(true){
			
			try {
				tmp = br.readLine();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			
			if(tmp == null){
				break;
			}
			if(tmp.equals("")){
				break;
			}
			
			rrr = tmp.split(",");
			
			if(rrr[0].equals("A") && cup == 0){
				if(rrr[1].equals("B")){
					cup = 1;
				}else if(rrr[1].equals("C")){
					cup = 2;
				}
			}else if(rrr[0].equals("B") && cup == 1){
				if(rrr[1].equals("A")){
					cup = 0;
				}else if(rrr[1].equals("C")){
					cup = 2;
				}
			}else if(rrr[0].equals("C") && cup == 2){
				if(rrr[1].equals("A")){
					cup = 0;
				}else if(rrr[1].equals("B")){
					cup = 1;
				}
			}else if(rrr[1].equals("A") && cup == 0){
				if(rrr[0].equals("B")){
					cup = 1;
				}else if(rrr[0].equals("C")){
					cup = 2;
				}
			}else if(rrr[1].equals("B") && cup == 1){
				if(rrr[0].equals("A")){
					cup = 0;
				}else if(rrr[0].equals("C")){
					cup = 2;
				}
			}else if(rrr[1].equals("C") && cup == 2){
				if(rrr[0].equals("A")){
					cup = 0;
				}else if(rrr[0].equals("B")){
					cup = 1;
				}
			}
			
		}
		
		if(cup == 0){
			System.out.println("A");
		}else if(cup == 1){
			System.out.println("B");
		}else if(cup == 2){
			System.out.println("C");
		}
		
		
		
		
	}

}

Measured memory_bytes: 16908
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//ll INF = 1000000000000000000;
ll gcd(ll n, ll m){
  if(n==0) return m;
  else return gcd(m%n,n);
}
ll lcm(ll n, ll m){
  ll tmp = m/gcd(n,m);
  return n*tmp;
}
int main(){
  int N;
  cin >> N;

  int d[3];
  d[0] = 0;
  d[1] = 0;
  d[2] = 0;

  for(int i=0;i<N;i++){
    ll a;
    cin >> a;
    if(a%4==0){
      d[2]++;
    }else if(a%2==0){
      d[1]++;
    }else{
      d[0]++;
    }
  }

  if(d[0]<=d[2]){
    cout << "Yes" <<endl;
  }else if(d[0]<=d[2]+1 && d[1]==0){
      cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  
  return 0;
}







Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long

int main(void) {
    int n,c,k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for (int i = 0; i<n; i++) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());
    int tt = t[0], cc = 1, ans = 0;
    for (int i = 1; i<n; i++) {
        cc += 1;
        if (cc>c || t[i] - tt>k) {
            ans += 1;
            cc = 1;
            tt = t[i];
        }
    }
    cout << ans + (cc ? 1 : 0) << endl;
    return 0;
    
}

Measured memory_bytes: 768
$n=<>;
@a=map{
	($a,$b)=glob<>;
	$a==$b?1:0
}0..$n-1;
for$i(0..$n-3){
	if($a[$i]&&$a[$i+1]&&$a[$i+2]){
		print "Yes";
		exit;
	}
}
print "No";

Measured memory_bytes: 5368
#include <stdio.h>

int main(void)
{
	int a, b, c, d, who = 0;

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

	while (1)
	{
		++who;

		if (who % 2)
			c -= b;
		else
			a -= d;

		if (a <= 0)
		{
			puts("No");
			return 0;
		}
		else if (c <= 0)
		{
			puts("Yes");
			return 0;
		}
	}
}

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

int main(){
    int n, ai, i = 0;
    cin >> n;
    int *A = (int*) malloc(sizeof(int)*n);

    memset (A, 0, sizeof(int)*n/sizeof(char));

    while(i++ < n-1) {
        cin >> ai;
        A[ai-1] += 1;
    }

    for(i = 0; i < n; ++i) {
        cout << A[i] << endl;
    }
    return 0;
}


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

int fib(int n){
	int ans[45] = {1,1},i;
	for(i=2;i<=n;i++){
		ans[i] = ans[i-1]+ans[i-2];
	}
	return ans[n];
}

int main() {
	int n;
	cin >> n;
	cout << fib(n) << endl;
	return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int read(){
	int ans=0,w=1;char c=getchar();
	while(!isdigit(c)&&c!='-')c=getchar();
	if(c=='-')c=getchar(),w=-1;
	while(isdigit(c))ans=ans*10+c-'0',c=getchar();
	return ans*w;
}
#define N 1000010
int a[N],n,k;
int main(){
	n=read();k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	int ans=0;
	for(int i=1;i<n;i=i+k-1)ans++;
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 640
# ABC 086 C  
import numpy as np

N = int(input())
it = [[0,0,0]]
for i in range(N):
    it.append(list(map(int, input().split())))
it = np.array(it)

ans = 'Yes'
for i in range(1,N+1):
    x_delta = abs(it[i,1] - it[i-1, 1])
    y_delta = abs(it[i,2] - it[i-1, 2])
    t_delta = it[i,0] - it[i-1,0]
    if t_delta - x_delta - y_delta >= 0:
      if (t_delta - x_delta - y_delta )%2 != 0:
        ans = 'No'
        break
    else:
      ans = 'No'
      break

print(ans)


Measured memory_bytes: 38632
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

int A[1000010];
int cnt[1000010];
int gcd(int a, int b)
{
	if (a < b) return gcd(b, a);
	if (b == 0) return a;
	else return gcd(b, a % b);
}
bool isPrime[1000010];
void set_prime() {
	for (int i = 1; i <= 1000000; i++) {
		isPrime[i] = true;
	}
	isPrime[0] = false; isPrime[1] = false;
	for (int i = 2; i * i <= 1000000; i++) {
		int j = 2;
		while (i * j <= 1000000) {
			isPrime[i * j] = false;
			j++;
		}
	}
}
int main()
{
	set_prime();
	vector<int> V;
	for (int i = 0; i < 1000010; i++) {
		if (isPrime[i]) V.push_back(i);
	}
	int N;
	//N = 10000000;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int> B;
	for (int i = 0; i < N; i++) {
		if (A[i] != 1) B.push_back(A[i]);
	}
	bool pc = true;
	if (B.size() <= V.size()) {
		for (int i = 0; i < B.size(); i++) {
			int tmp = B[i];
			for (int j : V) {
				if (j * j > B[i]) break;
				bool first = true;
				while (tmp % j == 0) {
					if (first && cnt[j] >= 1) pc = false;
					cnt[j]++;
					first = false;
					tmp /= j;
				}
			}
			if (tmp > 1) {
				if (cnt[tmp] >= 1) pc = false;
			}
			cnt[tmp]++;
		}
	}
	else pc = false;
	if (pc) {
		cout << "pairwise coprime" << endl;
		return 0;
	}
	int GCD = A[0];
	for (int i = 1; i < N; i++) {
		GCD = gcd(GCD, A[i]);
	}
	if (GCD == 1) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
	
}

Measured memory_bytes: 12648
#include<cstdio>
using namespace std;
int main(){
  int n,g[300][300]={},g2[300][300]={},mina,flag=0,x,y;
  long a[300][300],ans=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      scanf("%ld",&a[i][j]);
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        if(a[i][k]+a[k][j]<a[i][j]||a[i][j]!=a[j][i]){
          printf("-1\n");
          return 0;
        }
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      g2[i][j]=1;
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
        if(i!=k&&j!=k&&a[i][j]==a[i][k]+a[k][j])
          g2[i][j]=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(g2[i][j])
        ans+=a[i][j];
  printf("%ld\n",ans);
}

Measured memory_bytes: 1280
import collections
n,k=map(int, input().split())
a=list(map(int, input().split()))

c= collections.Counter(a)
b=c.most_common()[::-1]
d=len(set(a))
ans=0
if d-k<=0:
    print(ans)
    exit()
    
for i in range(d-k):
    ans+=b[i][1]
print(ans)

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int test(ll X, ll Y) {
  for(int i = 1; X - 2 * i >= 0; ++i) {
    if(test(X - 2 * i, Y + i) == 0) return 1;
  }
  for(int i = 1; Y - 2 * i >= 0; ++i) {
    if(test(X + i, Y - 2 * i) == 0) return 1;
  }
  return 0;
}

int main(){
  /*
  for(int X = 0; X <= 10; ++X) {
    for(int Y = 0; Y <= 10; ++Y) {
      cout << " " << test(X, Y);
    }
    cout << endl;
  }
  */
  ll X, Y;
  cin >> X >> Y;
  if(abs(X - Y) <= 1) cout << "Brown" << endl;
  else cout << "Alice" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
int n,m,q,i,j,a[2005][2005],b[2005][2005],c[2005][2005],dian,bian,u,v,x,y;
char s[2005][2005];
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();m=read();q=read();
   	for(i=1;i<=n;i++)
   		scanf("%s",s[i]+1);
   	for(i=1;i<=n;i++)
   		for(j=1;j<=m;j++){
			if(s[i][j]=='1')
				a[i][j]=1;
			if(s[i][j]=='1'&&s[i-1][j]=='1')
				b[i][j]=1;
			if(s[i][j]=='1'&&s[i][j-1]=='1')
				c[i][j]=1;
			a[i][j]=a[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			b[i][j]=b[i][j]+b[i-1][j]+b[i][j-1]-b[i-1][j-1];
			c[i][j]=c[i][j]+c[i-1][j]+c[i][j-1]-c[i-1][j-1];
		}
	while(q--){
		u=read();v=read();x=read();y=read();
		dian=a[x][y]-a[x][v-1]-a[u-1][y]+a[u-1][v-1];
		bian=b[x][y]-b[x][v-1]-b[u][y]+b[u][v-1]+c[x][y]-c[x][v]-c[u-1][y]+c[u-1][v];
		pus(dian-bian,2);
	}
    return 0;
}

Measured memory_bytes: 52864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define F first
#define S second
#define um map <ll,ll>
#define rep(i,z,n)  for(int i=z;i<n;i++)
#define repi(i,z,n) for(int i=z;i<=n;i++)
#define repn(i,z,n) for(int i=n-1;i>=z;i--)
#define vec vector<ll>
#define vecp vector<pair<ll,ll>>
#define pi (double)3.14159265358979323846
#define ld long double
#define all(z) z.begin(),z.end()

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; if (a == 0) return 0; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }
ll modInverse(ll a, ll m) {return power(a, m - 2, m);}
ll binpow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll binlog2(ll n) {ll logValue = -1; while (n) {logValue++; n >>= 1;} return logValue;}
ll ceil(ll t1, ll t2) {ll ans = (t1 + t2 - 1) / t2; return ans;}
void print(vec a) {rep(i, 0, a.size())cout << a[i] << " "; cout << endl;}
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
const ll inf = 2e18;


void solve() {
    ll n;
    cin >> n;
    vec ans(n + 5, 1);
    repi(i, 2, n - 1) {
        for (int j = i; j <= n; j += i) {
            ans[j]++;
        }
    }

    ll fans = 0;
    repi(i, 1, n - 1) {
        fans += ans[i];
    }
    cout << fans << endl;
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    speed;
    int test = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case #" << t1 << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 11100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 * 
 * @author daltao
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            TaskD solver = new TaskD();
            solver.solve(1, in, out);
            out.close();
        }
    }
    static class TaskD {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.readInt();
            int[] seq = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                seq[i] = in.readInt();
            }

            long totalSell = 0;
            int atLeast = 1;
            for (int i = 1; i <= n; i++) {
                if (seq[i] == atLeast) {
                    atLeast++;
                    continue;
                }
                int sell = (seq[i] - 1) / atLeast;
                totalSell += sell;
                if (i == 1) {
                    atLeast = 2;
                }
            }

            out.println(totalSell);
        }

    }
    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}



Measured memory_bytes: 25812
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

vi d, f;
vector<bool> r;
int t;

void dfs(vvi &g, int u) {	
	r[u] = true;
	d[u] = t++;
	for (int v : g[u]) {
		if (r[v]) continue;
		dfs(g, v);
	}
	f[u] = t++;
}

int main() {
	int n; cin >> n;
	vvi g(n + 1);
	rep(j, n) {
		int u, k; cin >> u >> k;
		rep(j, k) {
			int vj; cin >> vj;
			g[u].push_back(vj);
		}
	}

	r.assign(n + 1, false);
	d.assign(n + 1, 0); f.assign(n + 1, 0);
	t = 1;
	rep2(i, 1, n + 1) if (!r[i]) dfs(g, i);
	/*
	dbvv(g);
	dbv(d);
	dbv(f);
	*/
	rep2(i, 1, n + 1) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

int main() {
    int n, m;
    cin >> n >> m;
    ll s[n], t[m];

    rep(i, n) { cin >> s[i]; }
    rep(j, m) { cin >> t[j]; }

    ll dp[n + 1][m + 1];

    rep(i, n + 1) { dp[i][0] = 1; }

    for (int i = 0; i <= m; i++) {
        dp[0][i] = 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
            } else {
                dp[i + 1][j + 1] =
                    (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + mod) % mod;
            }
        }
    }
    cout << dp[n][m] << endl;
}


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

namespace ConsoleApp5
{
    class Program 
        {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



Measured memory_bytes: 15944
n = int(input())
a = list(map(int, input().split()))

cnt_4, cnt_2 = 0, 0
for num in a:
    if num % 4 == 0:
        cnt_4 += 1
    elif num % 2 == 0:
        cnt_2 += 1

if n//2 <= cnt_4 + cnt_2//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 19924
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;
const long long int MOD=1e9+7;

int main(){
  long long int n, d[59], ans = 0;
  cin >> n;
  for(int i=0;i<n;i++)cin >> d[i];
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            while (a[i] % 2 == 0) {
                a[i] /= 2;
                ans++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 47948
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
S = getlist()
T = getlist()

L = [[1 for i in range(N + 1)] for j in range(M + 1)]
for i in range(1, N + 1):
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007

print(L[M][N] % 1000000007)

Measured memory_bytes: 74332
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long double ld;

int i, j, k;

int main() {

    int N, K;
    cin >> N >> K;

    double p_sum = 0;

    for(i = 1; i <= N; i++) {
        if(i >= K) {
            p_sum = p_sum + (ld)1 / (ld)N;
        } else {
            int num = (int)ceil(log2((ld)K / (ld)i));
            ld p = (ld)1 / (ld)pow(2, num);
            p_sum = p_sum + p / (ld)N;
        }
    }

    printf("%.12lf\n", p_sum);
}

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

int main() {
  int N;
  int l,r,seat_n;
  
  cin >> N;
  
  seat_n = 0;
  
  for(int i =0; i<N; i++){
    cin >> l >> r;
    
    seat_n += r -l +1;
  }
  
  cout << seat_n << endl;

  
}


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

using namespace std;

int main(){
	long long N, D;
	cin >> N >> D;
	int ans = 0;

	long long DD = D * D;

	for (int i = 0; i < N; i++)
	{
		long long X, Y;
		cin >> X >> Y;
		if (X * X + Y * Y <= DD) {
			ans++;
		}
	}
	cout << ans << endl;

	cin >> N;
}

Measured memory_bytes: 3640
// abc169_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<P> AB(N);
    REP(i, N) cin >> AB[i].first >> AB[i].second;

    ll ans;
    if (N % 2 == 0){
        sort(ALL(AB));
        ll mn = AB[N/2-1].first;
        ll mn2 = AB[N/2].first;

        sort(ALL(AB), [](P& a, P& b){
            return a.second > b.second;
        });
        ll mx = AB[N/2-1].second;
        ll mx2 = AB[N/2].second;

        ans = ((mx+mx2) - (mn+mn2) + 1);
    } else {

        sort(ALL(AB));
        ll mn = AB[N/2].first;

        sort(ALL(AB), [](P& a, P& b){
            return a.second > b.second;
        });
        ll mx = AB[N/2].second;

        ans = (mx - mn + 1);

    }

    print(ans);


    return 0;
}


Measured memory_bytes: 4792
#include<stdio.h>
int a[200000];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int minl=a[1];
int maxl=-1000000000;

for(int i=2;i<=n;i++)
{
if((a[i]-minl)>maxl)
{
maxl=a[i]-minl;
}
if(a[i]<minl)
{
 minl=a[i];
}
}
printf("%d\n",maxl);

return 0;
}

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


int main(){
    char x,y;
    cin>>x>>y;

    if(x>y) cout<<'>'<<endl;
    else if(x<y) cout<<'<'<<endl;
    else cout<<'='<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int a[n+1],b[n],sum=0;
    for(int i=0;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];

    }
    for(int i=0;i<n;i++)
    {
        if(a[i]>=b[i])
            sum+=b[i];
        else
        {
            sum+=a[i];
            b[i]=b[i]-a[i];
            if(b[i]>=a[i+1])
            {
                sum+=a[i+1];
                a[i+1]=0;
            }
            else
            {
                sum+=b[i];
                a[i+1]=a[i+1]-b[i];
            }
        }
    }

    cout<<sum<<endl;

}


Measured memory_bytes: 5124
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_13_B
// Heuristic Search - 8 Puzzle
// status:
// tag: [bfs]

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int N = 3;
const int N2 = 9;

struct puzzle {
    int p[N2];
    string path;
    int space;

    bool is_complete() {
        // complete pattern is:
        // 1 2 3
        // 4 5 6
        // 7 8 9
        for (int i = 0; i < N2; ++i) {
            if (p[i] != i + 1) return false;
        }

        return true;
    }

    bool operator<(const puzzle& other) const {
        for (int i = 0; i < N2; ++i) {
            if (p[i] == other.p[i]) continue;
            return other.p[i] < p[i];
        }

        // equal
        return false;
    }
};

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const char direction[] = {'l', 'd', 'r', 'u'};

int to_index(int x, int y) { return y * N + x; }
int to_x(int index) { return index % N; }
int to_y(int index) { return index / N; }

queue<puzzle> pq;

string bfs() {
    map<puzzle, bool> puzzle_memory;

    while (!pq.empty()) {
        auto curr_puzzle = pq.front();
        pq.pop();

        int curr_x = to_x(curr_puzzle.space), curr_y = to_y(curr_puzzle.space);
        for (int r = 0; r < 4; ++r) {
            int next_x = curr_x + dx[r], next_y = curr_y + dy[r];
            if (next_x < 0 || N <= next_x || next_y < 0 || N <= next_y) continue;

            auto next_puzzle = curr_puzzle;
            next_puzzle.space = to_index(next_x, next_y);
            swap(next_puzzle.p[curr_puzzle.space], next_puzzle.p[next_puzzle.space]);
            // 既に出現した盤面ならcontinue
            if (puzzle_memory[next_puzzle]) continue;

            next_puzzle.path += direction[r];
            if (next_puzzle.is_complete()) return next_puzzle.path;

            puzzle_memory[next_puzzle] = true;
            pq.push(next_puzzle);
        }
    }

    // fail
    return "";
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(1 3 0
4 2 5
7 8 6
)";
    stringstream stream(program_input_str);
#endif
    puzzle start_puzzle;
    start_puzzle.path = "";

    int value;
    for (int y = 0; y < N; ++y) {
        for (int x = 0; x < N; ++x) {
            auto index = to_index(x, y);
            stream >> value;
            start_puzzle.p[index] = value;
            if (value == 0) {
                start_puzzle.p[index] = N2;
                start_puzzle.space = index;
            }
        }
    }

    if (start_puzzle.is_complete()) {
        cout << "0" << endl;
    }
    else {
        pq.push(start_puzzle);
        auto ans = bfs();
        cout << ans.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 33576
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }

long long dp[510000][5];

long long cost(int i, int s, const vector<long long> &A) {
    if (s == 0) return A[i];
    else if (s == 4) return A[i];
    else if (s == 1 || s == 3) {
        if (A[i] % 2 == 0 && A[i] > 0) return 0;
        else if (A[i] > 0) return 1;
        else return 2;
    }
    else {
        if (A[i] % 2 == 0) return 1;
        else return 0;
    }
}

int main() {
    int L; cin >> L;
    vector<long long> A(L);
    for (int i = 0; i < L; ++i) cin >> A[i];

    for (int i = 0; i < 510000; ++i) for (int j = 0; j < 5; ++j) dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 0; i < L; ++i) {
        for (int j = 0; j < 5; ++j) {
            for (int k = j; k < 5; ++k) {
                chmin(dp[i+1][k], dp[i][j] + cost(i, k, A));
            }
        }
    }
    long long res = INF;
    for (int j = 0; j < 5; ++j) chmin(res, dp[L][j]);
    cout << res << endl;
}


Measured memory_bytes: 21760
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

const int N = 200003;
int n, k;
string s;


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

	int cnt = 0, res = 0;
	for(int i = 0; i < n; ++i)
		if(s[i] == 'R')
			++cnt;
	for(int i = 0; i < cnt; ++i)
		if(s[i] == 'W')
			++res;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);                    
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    ll cnt[100002]={0};
    ll sum=0;
    for(int i=0;i<n;i++) cin>>arr[i],sum+=arr[i],cnt[arr[i]]++;
    ll q,a,b;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>b>>a;
		sum+=(a-b)*cnt[b];
		cnt[a]+=cnt[b];
		cnt[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  ll ans=1000;//所持金
  ll kabu=0;//株数
  for(int i=0;i<n-1;i++){
    if(a[i]<a[i+1]){
      kabu+=ans/a[i];
      ans=ans%a[i];
    }else if(a[i]>a[i+1]){
      ans+=kabu*a[i];
      kabu=0;
    }
    
  }
  ans+=a[n-1]*kabu;
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3620
use std::io::*;
// XORとは繰り上がりがない和であるため、
// l ~ rのXORが和に等しいという条件には単調性がある。
// なぜなら、l ~ rまでで条件を充せてなかったらl ~ r + 1も充せないので。

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans: usize = 0;
    let mut d: usize = 0;
    let mut r: usize = 0;
    for l in 0..n {
        while r < n && d & a[r] == 0 {
            d |= a[r];
            r += 1;
        }
        ans += r - l;
        d ^= a[l];
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int dp[100010],x[100000];
bool bo[100100];
signed main(){
	int n,m;
	cin>>n>>m;
	f(i,m){
		cin>>x[i];
		bo[x[i]]=true;
	}
	dp[0]=1;
	f(i,n){
		dp[i]%=mod;
		if(!bo[i+1]){
			dp[i+1]+=dp[i];
		}
		if(!bo[i+2])dp[i+2]+=dp[i];
	}
	cout<<dp[n]%mod<<endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int M = 1000000007;

int main(){
    string s[3];
    while(cin >> s[0], s[0][0] != '0'){
        rep(i,2) cin >> s[i + 1];
        rep(i,3) reverse(all(s[i]));

        int n = s[0].size();
        long long dp[55][2] = {{0}};
        dp[0][0] = 1;
        rep(i,n){
            vector<int> a[3];
            rep(j,3){
                if(s[j][i] == '?'){
                    if(i == n - 1){
                        a[j] = vector<int>(9);
                        iota(all(a[j]), 1);
                    } else {
                        a[j] = vector<int>(10);
                        iota(all(a[j]), 0);
                    }
                }else{
                    a[j].emplace_back(s[j][i] - '0');
                }
            }
            for(auto j:a[0]){
                for(auto k:a[1]){
                    for(auto l:a[2]){
                        if((j + k) % 10 == l) (dp[i + 1][(j + k) / 10] += dp[i][0]) %= M;
                        if((j + k + 1) % 10 == l) (dp[i + 1][(j + k + 1) / 10] += dp[i][1]) %= M;
                    }
                }
            }
        }
        cout << dp[n][0] << endl;
    }
}

Measured memory_bytes: 3192
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    ll h, a;
    cin >> h >> a;
    ll cnt = 0;
    while (h > 0) {
        h -= a;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256