akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

struct Coord {
    Int x;
    Int y;
};
double CalcDist(Coord first, Coord second);
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId);
Int Factorial(Int n);

/*
// 引数に関数オブジェクトを渡さない場合
void PermutationLoop(Int n, vector<Coord>& coords) {
    vector<Int> v(n);
    for (Int i = 0; i < n; ++i) {
        v[i] = i;
    }

    //double (*const calcDistSum[])(vector<Coord>&, vector<Int>&) = {CalcDistSum}; // 関数ポインタ
    // 関数オブジェクト(ラムダ式使用) ver.1
    // auto calcDistSum = [&coords, &v]() {
    //     return CalcDistSum(coords, v);
    // };
    // 関数オブジェクト(ラムダ式使用) ver.2
    // auto calcDistSum = [&v](vector<Coord>& coords) {
    //     return CalcDistSum(coords, v);
    // };

    double sum = 0;
    do {
        //sum += calcDistSum[0](coords, v); // 関数ポインタ
        //sum += calcDistSum(); // 関数オブジェクト ver.1
        sum += calcDistSum(coords); // 関数オブジェクト ver.2
    } while (std::next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / (double)Factorial(n) << endl;
    return;
}

*/
// 引数に関数オブジェクトを渡す場合
template <typename Func>
void PermutationLoop(Int n, Func func) {
    vector<Int> v(n);
    for (Int i = 0; i < n; ++i) {
        v[i] = i;
    }
    double sum = 0;
    do {
        sum += func(v); // 関数オブジェクト ver.2
    } while (std::next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / (double)Factorial(n) << endl;
    return;
}


int main(void) {
    Int n;
    cin >> n;
    vector<Coord> coords(n);
    for (Int i = 0; i < n; ++i) {
        cin >> coords[i].x >> coords[i].y;
    }
    // 関数オブジェクト(ラムダ式使用) ver.3: 引数で渡す
    auto calcDistSum = [&coords](vector<Int>& v) {
        return CalcDistSum(coords, v);
    };

    PermutationLoop(n, calcDistSum);
    return 0;
}

double CalcDist(Coord first, Coord second) {
    return sqrt((first.x - second.x) * (first.x - second.x) + (first.y - second.y) * (first.y - second.y));
}
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId) {
    Int size = (Int)coordId.size();
    double ret = 0;
    for (Int i = 0; i < size - 1; ++i) {
        ret += CalcDist(coords[coordId[i]], coords[coordId[i + 1]]);
    }
    return ret;
}
Int Factorial(Int n) {
    if (n == 1) {
        return 1;
    } else {
        return n * Factorial(n - 1);
    }
}



Measured memory_bytes: 3784
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let hist = Array.make (n + 1) 0 in
    Array.iter (fun v -> hist.(v) <- hist.(v) + 1) a;
    let sum = Array.fold_left (fun acc v -> acc + v * (v - 1) / 2) 0 hist in
    for i = 0 to n - 1 do
        let k = hist.(a.(i)) in
        Printf.printf "%d\n" (sum - k + 1)
    done
)

Measured memory_bytes: 8704
# see: https://twitter.com/maspy_stars/status/1179226257982185472
import sys
input = sys.stdin.buffer.readline


class WeightedUnionFindTree:
    """Disjoint-Set Data Structure with weight

    complexity:
        - init: O(n)
        - find, unite, same: O(alpha(n))
    """

    def __init__(self, n_nodes):
        self.par = [i for i in range(n_nodes)]  # parent
        self.rank = [0] * n_nodes  # depth of tree
        self.weights = [0] * n_nodes

    def find(self, x):
        if self.par[x] == x:
            return x
        root = self.find(self.par[x])
        self.weights[x] += self.weights[self.par[x]]
        self.par[x] = root
        return root

    def unite(self, x, y, weight=0):
        root_x, root_y = self.find(x), self.find(y)
        if root_x == root_y:
            return
        if self.rank[root_x] < self.rank[root_y]:
            self.par[root_x] = root_y
            self.weights[root_x] = weight - self.weights[x] + self.weights[y]
        else:
            self.par[root_y] = root_x
            self.weights[root_y] = -weight - self.weights[y] + self.weights[x]
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weights[x] - self.weights[y]


def aoj():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_B
    N, Q = map(int, input().split())
    uft = WeightedUnionFindTree(N)
    ans = []
    for _ in range(Q):
        type_, u, v, *weight = map(int, input().split())
        if type_ == 0:
            uft.unite(u, v, weight[0])
        else:
            ans.append(uft.diff(u, v) if uft.is_same(u, v) else '?')
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    aoj()



Measured memory_bytes: 22104
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int n, a[100], mode = 0;
    rep(i, 100) {
        a[i] = 0;
    }
    while (cin >> n)
        a[n]++;
    
    rep(i,100) {
        if (mode < a[n]) {
            mode = a[n];
        }
    }
    
    rep(i,100) {
        if (a[i] == mode) {
            cout << i << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

/**
   ceil(0, 2) == 0
   ceil(1, 2) == 1
   ceil(2, 2) == 1
   ceil(3, 2) == 2
   ceil(4, 2) == 2
*/
template<class T>
T ceil(T dividend, T divisor)
{
    return (dividend + (divisor - 1)) / divisor;
}

int main()
{
    int64_t N, K;
    std::cin >> N >> K;

    int64_t P = 0;

    for (decltype(N) i = 1; i <= N; ++i) {
        int64_t t;
        std::cin >> t;

        if (t == 1) {
            P = t;
            break;
        }
    }

    if (N == K) {
        std::cout << 1 << std::endl;
    }
    else {
        std::cout << ceil(P-1, K-1) + ceil(N-P, K-1) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
const int MAX = 2e5+2;
int size[MAX], n;


int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
ll  k, q;
cin >> n >> k >> q;
unordered_map<ll, ll> map1;
size[0] = 0;
for(int i=1; i<=n; i++){
	size[i] = k;
}
for(int i=0; i<q; i++){
	ll a;
	cin >> a;
	map1[a]++;

}
for(int i=1; i<=n; i++){
	//cout << size[i] << endl;
	size[i] = size[i]-(q-map1[i]);
	if(size[i]>0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}
return 0;
}



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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    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>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;

    long double ans=0;
    rep(i,0,N){
        long double xi;
        string ui;
        cin >> xi >> ui;
        if(ui=="JPY") ans+=xi;
        else ans+=xi*380000;
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=10e5+5;
int arr[N];
int main()
{

int n;
cin>>n;
int sum;
int mini=10e7;
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
for(int i=1;i<=100;i++){
    sum=0;
    for(int j=0;j<n;j++){
        sum+=pow(arr[j]-i,2);

    }
    mini=min(mini,sum);

}
cout<<mini;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <deque>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v) sort(v.begin(), v.end())
#define SORTFUNC(v, func) sort(v.begin(), v.end(), func)
#define PRINT(v) REP(i, v.size()) printf("%d ", v[i]); cout << endl
#define SCI(n) int (n); scanf("%d", &(n))
#define SCL(n) ll (n); scanf("%I64d", &(n))
#define IN(n) scanf("%d", &(n))

int main(){
  int m;
  cin >> m;
  cout << 24 + (24-m) << endl;
  return 0;
}
























// I'd like to scroll past the end of document using Atom but I seemigly have to use these blank lines instead


Measured memory_bytes: 256
Q = int(input())
X = [list(map(int, input().split())) for _ in range(Q)]

n = 10 ** 5 + 2
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False

for i in range(2, n + 1):
    if not is_prime[i]:
        continue

    for j in range(2 * i, n + 1, i):
        is_prime[j] = False

like = [False] * (n + 1)
for i in range(n):
    like[i] = is_prime[i] and is_prime[(i + 1) // 2]

cumsum = [0] * (n + 1)
for i in range(n):
    cumsum[i + 1] = cumsum[i] + like[i]

for l, r in X:
    print(cumsum[r + 1] - cumsum[l])


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

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

  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
  else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  else cout << "bon" << endl;
}

Measured memory_bytes: 3672
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)*}
    };
}

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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input! {
        c:chars,
    }
    let c = c[0];
    if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' {
        println!("vowel");
    } else {
        println!("consonant");
    }
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, m;
  std::cin >> n >> m;

  if (n == m) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
# Postal Code
# input
A, B = map(int, input().split())
S = input()

# solution
res = 'Yes'
for i in range(len(S)):
    if i == A:
        if S[i] != '-':
            res = 'No'
            break
    else:
        if S[i] not in '0123456789':
            res = 'No'
            break

# output
print(res)



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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s; cin >> s;
    string a = "RUD", b = "LUD";
    for(int i = 0; i < s.size(); i+=2){
        int f = 1;
        REP(l, 0, 3){
            if(s[i] == a[l]){
                f = 0;
            }
        }
        if(f){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 1; i < s.size(); i+=2){
        int f = 1;
        REP(l, 0, 3){
            if(s[i] == b[l]){
                f = 0;
            }
        }
        if(f){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3548
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int n;

int main()
{
	int k;
	cin >> k;
	long long int a[100001];
	for(int i = 0; i < k; i++){
		cin >> a[i];
	}
	if(a[k - 1] != 2){
		cout << -1 << endl;
		return 0;
	}
	long long int minans = 2, maxans = 3;
	for(int i = k - 2; i >= 0; i--){
		if(minans % a[i] != 0) minans += a[i] - (minans % a[i]);
		if(maxans % a[i] != 0) maxans -= maxans % a[i];
		maxans += a[i] - 1;
		if(minans > maxans){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << minans << " " << maxans << endl;
}

Measured memory_bytes: 1024
import collections
def main():

    H, W, N = map(int, input().split())
    checked = collections.defaultdict(set)
    black = collections.defaultdict(set)
    refs = []
    for _ in range(N):
        a, b = map(int, input().split())
        black[a].add(b)
        refs.append([a, b])

    ans = [0 for _ in range(10)]
    for a, b in refs:
        for da in [-1, 0, 1]:
            for db in [-1, 0, 1]:
                c, d = a+da, b+db
                if d not in checked[c]:
                    checked[c].add(d)
                    if all(1<=c+dc<=H and 1<=d+dd<=W for dc in [-1,0,1] for dd in[-1, 0, 1]):
                        count = 0
                        for dc in [-1, 0, 1]:
                            for dd in [-1, 0, 1]:
                                if d+dd in black[c+dc]:
                                    count += 1
                        ans[count] += 1
    ans[0] = (H-2)*(W-2) - sum(ans[1:]) 
    for i in range(10):
        print(ans[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 195960
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>

using namespace std;

class Node {
public:
	int pos, chg, cost;
	Node(int pos, int chg, int cost) : pos(pos), chg(chg), cost(cost) {}
	bool operator < (const Node &nd) const { return cost > nd.cost; }
};

int main(){
	int n, m, c;
	static int len[100][100];
	while(cin >> n >> m >> c, n){
		vector< vector< pair<int,int> > > g(n);
		for(int i=0;i<m;i++){
			int f, t, c; cin >> f >> t >> c;
			g[f-1].push_back(make_pair(t-1, c));
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) len[i][j] = 1000000000;
		priority_queue<Node> qu; qu.push(Node(0, 0, 0));
		len[0][0] = 0;
		while(!qu.empty()){
			Node nd = qu.top(); qu.pop();
			int pos = nd.pos, chg = nd.chg, cost = nd.cost;
			if(len[pos][chg] < cost) continue;
			for(int i=0;i<g[pos].size();i++){
				int next = g[pos][i].first;
				if(len[next][chg] > len[pos][chg]+g[pos][i].second){
					len[next][chg] = len[pos][chg]+g[pos][i].second;
					qu.push(Node(next, chg, len[next][chg]));
				}
				if(chg+1 < n && len[next][chg+1] > len[pos][chg]){
					len[next][chg+1] = len[pos][chg];
					qu.push(Node(next, chg+1, len[next][chg+1]));
				}
			}
		}
		for(int i=1;i<n;i++){
			if(len[n-1][i] <= c){
				cout << i << endl;
				break;
			}
		}
	}
}

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

int main() {
	string s;
  	cin >> s;
  	int ns = 0, ew = 0;
  	for(int i = 0; i< s.size(); i++) {
    	if(ew == 3 &&ns==3)
          	break;
      	if(ns == 1 && s[i] == 'S')
      		ns = 3;
      	if(ns == 2 && s[i] == 'N')
      		ns = 3;
      	if(ew == 1 && s[i] == 'W')
      		ew = 3;
      	if(ew == 2 && s[i] == 'E')
      		ew = 3;
      	
      	if(ns == 0)
           	if(s[i] == 'N') { 
            	ns = 1;
            } else if(s[i] == 'S') {
         		ns = 2;
            }
         if(ew == 0)
           	if(s[i] == 'E') { 
            	ew = 1;
            } else if(s[i] == 'W') {
         		ew = 2;
            }
    }
  	if(ns == 3)ns=0;
  	if(ew == 3)ew=0;
  	if(ns == 0 && ew == 0)
      	cout << "Yes\n";
  	else
      	cout << "No\n";
}

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

int main() {
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  vector<long long> vec(4);
  vec.at(0)=a*c;
  vec.at(1)=a*d;
  vec.at(2)=b*c;
  vec.at(3)=b*d;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  cout<<vec.at(0)<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

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

	int n, q;
	int c = 0;

	Scanner sc = new Scanner(System.in);
      
        n = sc.nextInt();

	int[] s = new int[n];

        for(int i = 0; i < n; i++){
	    s[i] = sc.nextInt();
	}

	q = sc.nextInt();

	for(int i = 0; i < q; i++){
	    int t = sc.nextInt(); 	
	    int pos = -1;
	    int lower = 0; 
	    int upper = n - 1;
	    while (lower <= upper) {
		int mid = (lower + upper) / 2;
		if (s[mid] == t) {
		    pos = mid;
		    c++;
		    break;
		} else if (s[mid] < t) {
		    lower = mid + 1;
		} else {
		    upper = mid - 1;
		}
	    }
	}

	System.out.println(c);
    }
}



Measured memory_bytes: 80584
#include<cstdio>
#define reg register

const int MAXN=100000+5;

int n;
int a[MAXN];

int main(void){
	reg int i;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		static int x;
		scanf("%d",&x);
		a[x]=i;
	}
	for(i=1;i<n;++i)
		printf("%d ",a[i]);
	printf("%d\n",a[n]);
	return 0;
}

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

const int N=1e5;
int n;
int a[N+87];

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    a[n]=1e9+87;
    sort(a,a+n+1);
    int now=0;
    int ans=0;
    for(int i=0;i<=n;i++){
        if(a[i]!=a[now]){
            int tmp=i-now;
            if(tmp>=a[now])ans+=tmp-a[now];
            else ans+=tmp;
            now=i;
        }
    }

    printf("%d\n",ans);
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n,W;
int weight[110],value[110];
int dp[110][10010];
int main()
{
    cin >>n>>W;
    for(int i;i<n;++i) cin>>value[i]>>weight[i];

    for (int w =0 ; w<= W;++w) dp[0][w]=0;

    //DP
    for (int i=0; i<n; ++i){
        for (int w=0; w<= W;++w){
            if(w>= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]]+value[i],dp[i][w]);
            else dp[i+1][w]=dp[i][w];
        }
    }

    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7044
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n,m,x;
  scanf("%d%d%d",&n,&m,&x);

  int C[n];
  int A[n][m];
  for(int i=0;i<n;i++){
    scanf("%d",&C[i]);
    for(int j=0;j<m;j++){
      scanf("%d",&A[i][j]);
    }
  }


  int ans=10000000;
  
  //000000
  //000001
  //000010
  //000011
  //000100
  //000101
  //...
  //111111=2^7-1

  for(int bit=0;bit<(1<<n);bit++){
    int price=0;//今いくら分参考書を買ったか
    int B[m];//どれくらい経験値が貯まったか
    for(int i=0;i<m;i++){
      B[i]=0;
    }

    for(int i=0;i<n;i++){
      if(bit & (1<<i)){//その本を買う
        price+=C[i];//値段を追加
        for(int j=0;j<m;j++){
          B[j]+=A[i][j];
        }
      }
    }

    int can=1;
    for(int i=0;i<m;i++){
      if(B[i]<x){
        can=0;
      }
    }

    if(can==1){
      chmin(&ans,price);
    }
  }

  if(ans!=10000000){
    printf("%d\n",ans);
  }
  else{
    printf("-1\n");
  }

  return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 200005;
const int MM = 924844033;
const int L = 1<<19, HL = 1<<18;

typedef vector<int> poly;

bool dir;

ll w[L+1];
ll primitive_root = 116636802; // 5 ** ((MM-1) / 2**19) % MM

void priproc()
{
	w[0] = 1;
	for(int i = 1; i <= L; i++) w[i] = primitive_root * w[i-1] % MM;
}

void DFT(poly &p, int n) {
	if (n == 1) return;
	int Hn = n>>1;
	poly p0(Hn), p1(Hn);
	for (int k = 0; k < Hn; k++) {
		p0[k] = p[k<<1];
		p1[k] = p[(k<<1)|1];
	}

	DFT(p0, Hn);
	DFT(p1, Hn);
	int dif = L/n;
	if( dir ){
		for (int i = 0, j = Hn, k = 0; k < HL; k += dif, i++, j++) {
			p[i] = (p0[i] + w[k] * p1[i]) % MM;
			p[j] = (p0[i] + MM - w[k] * p1[i]%MM) % MM;
		}
	}
	else{
		for (int i = 0, j = Hn, k = L; k > HL; k -= dif, i++, j++) {
			p[i] = (p0[i] + w[k] * p1[i]) % MM;
			p[j] = (p0[i] + MM - w[k] * p1[i]%MM) % MM;
		}
	}
}

void poly_multi(poly X, poly Y, poly &Z)
{
	dir = true; DFT(X, L); DFT(Y, L);
	for(int i = 0; i < L; i++)
		Z[i] = (ll)X[i] * Y[i] % MM;
	dir = false; DFT(Z, L);
	for(int i = 0; i < L; i++) Z[i] = Z[i] * 924842269ll % MM;
}

int cnt[MX];
ll I[MX];
vector<int> T[MX];

void dfs(int x, int p = -1){
	cnt[x]++;
	for(int c : T[x]){
		if( c == p ) continue;
		dfs(c, x);
		cnt[x] += cnt[c];
	}
}

int main()
{
	int N, K;
	scanf("%d", &N);
	
	I[1] = 1;
	for(int i = 2; i <= N; i++) I[i] = (MM - MM/i) * I[MM%i] % MM;

	for(int i = 1; i < N; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		T[a].push_back(b);
		T[b].push_back(a);
	}
	dfs(1);
	poly F(2*L, 0);
	poly G(2*L, 0), H(2*L, 0);

	G[0] = 1;
	for(int i = 1; i <= N; i++) G[i] = G[i-1] * I[i] % MM;

	F[0] += N;
	for(int c : T[1]){
		F[N-cnt[c]] -= 1;
	}
	for(int i = 2; i <= N; i++){
		int mx = 0;
		for(int c : T[i]) mx = max(mx, cnt[c]);
		for(int c : T[i]){
			if( cnt[c] != mx ){
				F[N-cnt[c]] -= 1;
			}
		}
		F[cnt[i]] -= 1;
	}

	ll mul = 1;
	for(int i = 0; i <= N; i++){
		F[N-i] = mul * (MM+F[N-i]) % MM;
		mul = mul * (i+1) % MM;
	}
//	for(int i = 0; i <= N; i++) printf("%d ", F[i]); printf("\n");
//	for(int i = 0; i <= N; i++) printf("%d ", G[i]); printf("\n");

	priproc();
	poly_multi(F, G, H);
	for(int i = N-1; i >= 0; i--) printf("%lld\n", (ll)H[i] * G[N-i] % MM);
}


Measured memory_bytes: 52864
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let n = s.trim().parse::<usize>().unwrap();
    let mut a = String::new();
    io::stdin().read_line(&mut a).unwrap();
    let mut v = a.trim().split_whitespace().flat_map(str::parse::<i64>).collect::<Vec<_>>();
    for i in 0..n { v[i] -= i as i64 + 1; }
    v.sort();
    let b = v[n / 2];
    let r = v.iter().map(|&x| (x - b).abs()).fold(0, |r, x| r + x);    
    println!("{}", r);
}

Measured memory_bytes: 10492
import math

a,b,h,m = map(int,input().split())

r = abs(h*30-m*6+m/60*30)

if r >= 180:
    r = 360 - r

ans = a**2 + b**2 -2*a*b*math.cos(math.radians(r))

print(math.sqrt(ans))


Measured memory_bytes: 9464
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    s = input()
    k = 'keyence'
    if s.startswith(k) or s.endswith(k):
        print("YES")
        return

    for i in range(len(k)):
        start = k[:i]
        end = k[i:]
        if s.startswith(start) and s.endswith(end):
            print("YES")
            return
    print("NO")

if __name__=="__main__":
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int size=s.size();
	int ans=0;
	for(int i=1;i<size;i++){
		if(s[i]!=s[i-1]){
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define vi vector<int>
#define mod 1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl '\n'

vector<vector<int>> dp(100001, vector<int>(4,-1));
int a[100005],b[100005],c[100005];
int n;

int vacation(int ind, int fl){
	if(ind == n){
		return 0;
	}

	if(dp[ind][fl] != -1){
		return dp[ind][fl];
	}

	if(fl == 0){
		return dp[ind][fl] = max(a[ind] + vacation(ind+1,1),max(b[ind] + vacation(ind+1,2),c[ind] + vacation(ind+1,3)));
	}else if(fl == 1){
		return dp[ind][fl] = max(b[ind] + vacation(ind+1,2),c[ind] + vacation(ind+1,3));
	}else if(fl == 2){
		return dp[ind][fl] = max(a[ind] + vacation(ind+1,1), c[ind] + vacation(ind+1,3));
	}else if(fl == 3){
		return dp[ind][fl] = max(a[ind] + vacation(ind+1,1) , b[ind] + vacation(ind+1,2));
	}

	return dp[ind][fl];
}

signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	cin >> n;

	for(int i =0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	cout << vacation(0,0) << endl;
	return 0;
}

Measured memory_bytes: 20328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	private static void solve(FastScanner fr) {
		int n = fr.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = fr.nextInt();			

		if(n<2) {
			sout(0);
			return;
		}
		if(n==2) {
			sout((int)Math.abs(arr[1] - arr[0]));
			return;
		}
		
		int pp = 0;
		int p = Math.abs(arr[1] - arr[0]);
		for(int i = 2; i < n; i++) {
			int cur = Math.min(pp + Math.abs(arr[i] - arr[i-2]), p + Math.abs(arr[i] - arr[i-1]));
			// sout(i + " " + cur);
			pp = p;
			p = cur;
		}

		sout(p);
	}
    public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int n = 1;
		// int n = fs.nextInt();
		while (n-- > 0)	{
			solve(fs);
        }
    }

    private static void sout()          { System.out.println();  }
    private static void sout(String s)  { System.out.println(s); }
    private static void sout(int s)     { System.out.println(s); }
    private static void sout(long s)    { System.out.println(s); }
    private static void sout(double s)  { System.out.println(s); }
    
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); }
			return st.nextToken();
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		int nextInt() {	return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


Measured memory_bytes: 36464
from sys import stdin
n,k = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
for i in range(n):
    a[i] -= 1
d = {}
d[0] = k
cur = 0
while k > 0:
    cur = a[cur]
    k -= 1
    if cur in d:
        looplen = d[cur] - k
        k %= looplen
    else:
        d[cur] = k
print(cur + 1)


Measured memory_bytes: 110748
A, B, K = map(int, input().split())

def sousa(x,y):
  if x%2 == 0:
    x=int(x-x/2)
    y=int(y+x)
  else:
    x = int(x-1-(x-1)/2)
    y = int(y+x)
  return x,y

X = A
Y = B
for i in range(K):
  Number = sousa(X,Y)
  X = Number[1]
  Y = Number[0]
if K%2 == 0:
  output = (X,Y)
else:
  output = (Y,X)

print(output[0],output[1])

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

int main(){
  int a1, a2, a3;
  
  cin >> a1 >> a2 >> a3;
  
  if( a1 + a2 + a3 > 21 ){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    if n == 1 and m == 1:
        print(1)
    elif n == 1 or m == 1:
        print(n * m - 2)
    elif n == 2 or m == 2:
        print(0)
    else:
        print(n * m - 2 * n - 2 * m + 4)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

N, K = inpl()
ans = 0
X = 17

for i in range(1, N+1):
    while X and i * 2**(X-1) >= K:
        X -= 1
    ans += .5 ** X

print(ans/N)

Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int n = 100 * r + 10 * g + b;
    if(n % 4 == 0) cout << "YES";
    else cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    char s[n+1];
    for(int i = 0; i < n+1; i++) scanf("%c", &s[i]);
    int counter = 0;
    if(n%2 == 0){
        for(int i = 1; i< n/2+1; i++) {
            if(s[i] == s[n/2+i]) counter++;  
        }
    }
    if(n==1) printf("No");
    else{
        if(counter == n/2) printf("Yes");
        else printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
template<typename T> void cmin(T &a, T b) {a = min(a, b);}
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
vector<int> dp(1e6+1,INF),DP(1e6+1,INF);
signed main(){
  vector<int> a,odd;
  loop(i,1,1e6+1){
    int tmp=i*(i+1)*(i+2)/6;
    if(1e6<tmp)break;
    a.push_back(tmp);
    if(tmp%2)odd.push_back(tmp);
  }
  dp[0]=DP[0]=0;
  rep(i,1e6+1){
    rep(j,a.size())if(i+a[j]<=1e6)cmin(dp[i+a[j]],dp[i]+1);
    rep(j,odd.size())if(i+odd[j]<=1e6)cmin(DP[i+odd[j]],DP[i]+1);
  }

  int n;
  while(cin>>n,n){
    cout<<dp[n]<<' '<<DP[n]<<endl;
  }
  return 0;
}



Measured memory_bytes: 18212
use std::cmp;
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(a: u32, b: u32, c: u32, d: u32) -> u32 {
    let (l, r) = (cmp::max(a, c), cmp::min(b, d));
    if l < r { r - l } else { 0 }
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next(), sc.next(), sc.next(), sc.next()));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_foreach<T: Display>(answer: &[T]) {
    for x in answer {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_yn(answer: bool, yes: &str, no: &str) {
    println!("{}", if answer { yes } else { no });
}


#[allow(dead_code)]
fn print_or<T: Display>(answer: &Option<T>, or: &T) {
    match *answer {
        Some(ref x) => println!("{}", x),
        None => println!("{}", or),
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main()
{
  int n[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (auto &n1 : n)
    for (auto &n2 : n)
      cout << n1 << "x" << n2 << "=" << n1 * n2 << endl;
  return 0;
}

Measured memory_bytes: 3100
def isp(s): 
    rev = ''.join(reversed(s)) 
    if (s == rev): 
        return True
    return False
x=input()
y=len(x)
a=(len(x)-1)//2
b=(len(x)+3)//2
if(isp(x) and isp(x[:a]) and isp(x[b-1:])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
import java.util.*;
import java.io.*;
import java.util.Arrays; 
import java.util.ArrayList; 
import java.util.Collections; 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try (PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            Scanner in = new Scanner(System.in);  
            BigInteger n = in.nextBigInteger();  

            /*
            BigInteger sum = BigInteger.ZERO;
            while ((n.compareTo(new BigInteger("0"))) == 1) {
                BigInteger mod = n.mod(new BigInteger("10")); 
                sum = sum.add(mod);
                n = n.divide(new BigInteger("10"));
            }
            //out.println(sum);
            //out.println(sum.mod(new BigInteger("9")));

            if((sum.mod(new BigInteger("9"))).equals(new BigInteger("0"))) {
                out.println("Yes");
            } else {
                out.println("No");
            }*/

            if((n.mod(new BigInteger("9"))).equals(new BigInteger("0"))) {
                out.println("Yes");
            } else {
                out.println("No");
            }








        } finally {
            //out.close();
        }
        
           
    }
}




class FastScanner {
   private final BufferedReader br;
   private StringTokenizer st;
 
    FastScanner(InputStream InputStream) {
        br = new BufferedReader(new InputStreamReader(InputStream));
    }
    
    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
    
    int nextInt() {
        return Integer.parseInt(next());
    }
    
    long nextLong() {
        return Long.parseLong(next());
    }
    
    double nextDouble() {
        return Double.parseDouble(next());
    }


    
    ArrayList<Integer> nextIntList(int count) {
        ArrayList<Integer> array = new ArrayList<>();
        for (int n = 0; n < count; n++) {
            int number = nextInt();
            array.add(number);
        }
        return array;
    }
    
    int[] nextIntArray(int count) {
        int[] array = new int[count];
        for (int n = 0; n < count; n++) {
            array[n] = nextInt();
        }
        return array;
    }
}


Measured memory_bytes: 42332
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ll n,w;
	cin>>n>>w;
	ll w1[n+1]={0},v1[n+1]={0};
	for(ll i=1;i<=n;i++){
		cin>>w1[i]>>v1[i];
	}
	ll dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=w;j++){
			dp[i][j]=max(dp[i-1][j],(j>=w1[i]) ? dp[i-1][j-w1[i]]+v1[i] : 0);
		}
	}
	cout<<dp[n][w]<<endl;

	return 0;
}


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

int main(){
    int r;
    cin>>r;
    string tmp;
    if(r<1200) tmp="ABC";
    else if(1200<=r&&r<2800) tmp="ARC";
    else tmp="AGC";
    cout<<tmp<<endl;
}

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


void solve()
{
    ll X,K,D;
    cin>>X>>K>>D;
    X = max(X,-X);
    ll z=min(X/D,K);
    K-=z;
    X-=D*z;
    if(K%2)
    {
        X=abs(X-D);
    }
    cout<<X<<endl;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        solve();
 
		
	return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a[10000000],b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n;
       rep(i,n)cin>>a[i];
       rep(i,n){
         pos=i+1;
         if(a[i]==pos){
             if(i==n-1){
                 ans++;
             }
             else{
             cmp=a[i];
             a[i]=a[i+1];
             a[i+1]=cmp;
             ans++;
             }
         }
       }
     Cout(ans);
return 0;
}


Measured memory_bytes: 1024
ans = 0
def solve(n):
    global ans
    for i in range(1,n+1,2):
        div_list=[]
        for j in range(1,int((i+1)**0.5)+1):
            if i % j == 0:
                if (i//j)!=j:
                    div_list.append(i//j)
                    div_list.append(j)
                else:
                    div_list.append(j)
        if len(div_list) == 8:
            ans+=1

def main():
    n=int(input())
    solve(n)
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)
 
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;
 
 
int32_t main()
{
    fast_io;
    int n;
    cin >> n;
    vi a(n+1);
    vi cost(n+1);
    cost[0] = INT_MAX;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        cost[i] = min(abs(a[i] - a[i-1]) + cost[i-1], abs(a[i] - a[i-2]) + cost[i-2]);
    }
    cout << cost[n];

    return 0;
}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            long hp = cin.ReadLong;
            long many = 1;
            List<long> damageCount = new List<long>();
            while(hp > 0)
            {
                damageCount.Add(many);
                many *= 2;
                if (hp == 1)
                {
                    break;
                }
                hp /= 2;
            }
            Console.WriteLine(damageCount.Sum());
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		if(s=="#"){
			break;
		}
		int v=0;
		int ans=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='y' || s[i]=='u' || s[i]=='i' || s[i]=='o' || s[i]=='p' || s[i]=='h' || s[i]=='j' || s[i]=='k' || s[i]=='l' || s[i]=='n' || s[i]=='m'){
				if(v==2){
					ans++;
				}
				v=1;
			}
			else{
				if(v==1){
					ans++; 
				}
				v=2;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(i == 0) ans += A[i];
        else{
            if(A[i - 1] >= A[i]) continue;
            
            ans += A[i] - A[i - 1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256