akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long


using namespace std;
const int N = 500077;
int n, m, d, t;
char a[N];
int s1 = 0, s2 = 0;

int binpow (int a, int n, int k) {
	if (n == 0)
		return 1 % k;
	if (n % 2 == 1)
		return binpow (a, n - 1, k) * a % k;
	else {
		int b = binpow (a, n / 2, k) % k;
		return b * b % k;
	}
}

int make(int x){
    int cnt = 0;
    while (x > 0){
        if (x % 2 == 1){
            cnt++;
        }
        x /= 2;
    }
    return cnt;
}

void check(int x){
    int cnt = 1;
    while (x > 0){
        cnt++;
        x %= make(x);
    }
    cout << cnt << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (a[i] == '1'){
            cnt++;
        }
    }
    if (cnt == 0){
        for (int i = 1; i <= n; i++){
            cout << 1 << endl;
        }
        return 0;
    }
    if (cnt == 1){
        for (int i = 1; i <= n; i++){
            if (a[i] == '1'){
                s1 = binpow(2, n - i, 2);
            }
        }
        for (int i = 1; i <= n; i++){
            if (a[i] == '1'){
                cout << 0 << endl;
            }
            else {
                int s2 = binpow(2, n - i, 2) + s1;
                s2 %= 2;
                check(s2);
            }
        }
        return 0;
    }

    for (int i = 1; i <= n; i++){
        if (a[i] == '1'){
            s1 += (binpow(2, n - i, cnt - 1) % (cnt - 1));
            s2 += (binpow(2, n - i, cnt + 1) % (cnt + 1));
        }
    }


    for (int i = 1; i <= n; i++){
        int sum = 0;
        if (a[i] == '1'){
            sum = s1;
            sum -= binpow(2, n - i, cnt - 1);
            sum %= (cnt - 1);
            sum += (cnt - 1);
            sum %= (cnt - 1);
            check(sum);
        }
        else{
            sum = s2;
            sum += binpow(2, n - i, cnt + 1) % (cnt + 1);
            sum %= (cnt + 1);
            sum += (cnt + 1);
            sum %= (cnt + 1);
            check(sum);
        }
    }

}


Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())



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



// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }




int main() {

  int a,b;
  cin >> a >> b;
  int ans = 0;

  if(a==b){
    cout << a+b << endl;
  }else if(a>b){
    cout << a+a-1 << endl;

  }else{
    cout << b+b-1 << endl;

  }



  // cout <<  << endl;

}

















//


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>


#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}

static void A_task();

int main()
{
	A_task();
	
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int N;
	scanf(" %d", &N);

	auto height = new int[N + 1];
	height[0] = 0;

	for (int i = 0; i < N; i++) {
		scanf(" %d", &height[i]);
	}

	auto dp = new int[N + 1];
	memset(dp, 0, sizeof(int) * (N + 1));
  	dp[1] = tp_abs<int>(height[1] - height[0]);
  
	for (int i = 2; i < N; i++) {
		dp[i] = std::min(dp[i - 1] + tp_abs<int>(height[i] - height[i - 1]), dp[i - 2] + tp_abs<int>(height[i] - height[i - 2]));
	}

	printf("%d\n", dp[N - 1]);

	delete[] height;
	delete[] dp;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b){
    return *(int*)a-*(int*)b;
}

int main(void)
{
    int i, n, a[200001];
    scanf("%d", &n);

    for( i = 0; i < n; i++ ){
        scanf("%d", &a[i]);
    }

    qsort(a, n, sizeof(int), comp);

    for( i = 0; i < n-1; i++ ){
        if( a[i] == a[i+1] ){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 1660
N, A = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)

dp = Array.new(N+1).map{Array.new(N+1).map{Array.new(50*N+1, 0)}}


# i = 0でjが1以上のものはないのでほかは0で良い
dp[0][0][0] = 1

1.upto(N) do |i|
  dp[i][0][0] = 1
  # 最大でi個までしか選ばない
  1.upto(i) do |j|
    1.upto(50*N) do |k|
      if k >= x[i-1]
        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]]
      else
        dp[i][j][k] = dp[i-1][j][k]
      end
    end
  end
end

# ans = 0
# 1.upto(N) do |j|
#   1.upto(N*50) do |k|
#     if j * A == k
#       # p "j:#{j} k:#{k} dp:#{dp[N][j][k]}"
#       ans += dp[N][j][k]
#     end
#   end
# end
# puts ans

puts (1..N).map {|j| dp[N][j][j * A] }.inject(0,&:+)




Measured memory_bytes: 54652
def chmin(a, b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf")] * N

for i in range(N):
    if i == 0:
        dp[0] = 0
        continue
    for j in range(1, K + 1):
        if i - j < 0:
            break
        dp[i] = chmin(dp[i], abs(h[i] - h[i - j]) + dp[i - j])
print(dp[N - 1])


Measured memory_bytes: 55264
N = int(input())
L = list(map(int, input().split()))
if N == 1 or N == 2:
  print(1)
else:
  pre = L[0]
  greater = False
  less = False
  ans = 1
  for l in L[1:]:
    if greater:
      if pre > l:
        ans += 1
        greater = False
    elif less:
      if pre < l:
        ans += 1
        less = False
    else:
      if pre < l:
        greater = True
      elif pre > l:
        less = True
    pre = l
    
  print(ans)
      

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

int main() 
{   
  

 
long long int n;
scanf("%lld",&n);

double p[n];
    for(long long int i = 0; i <n; i++){
   
   
   scanf("%lf",&p[i]);
}

double dp[n+1][n+1];
memset(dp, 0.0, sizeof(dp)); 
  
    
    dp[0][0] = 1.0; 
dp[1][1]=p[0];
dp[0][1]=1.0-p[0];

for(long long int i=1;i<=n;i++)
{
for(long long int j=0;j<=i;j++)
{
if(j==0)
dp[0][i]=dp[0][i-1]*(1.0-p[i-1]);
else

dp[j][i]=dp[j-1][i-1]*p[i-1]+dp[j][i-1]*(1.0-p[i-1]);

}


}
double sum=0.0;
for(long long int i=(n+1)/2;i<=n;i++)
{

sum=sum+dp[i][n];




}

printf("%0.15lf",sum);



}

  
 


Measured memory_bytes: 70528
using System;
using System.Linq;

namespace ABC147
{
    class A
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (22 <= input.Sum()) Console.WriteLine("bust");
            else Console.WriteLine("win");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;

int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ya=min(a+b,2*c);
  if(x>y)
  cout << min(2*x*c,y*ya+(x-y)*a) << endl;
  else
  cout << min(2*y*c,x*ya+(y-x)*b) << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;
//#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int i = n; i >= 0; i--)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}



int main() {
	vector<int> a, b;
	int n;
	a.resize(9);
	rep(i, 9) {
		cin >> a[i];
	};
	cin >> n;
	b.resize(9);
	string ans = "No";

	rep(i, 9) {
		b[i] = 0;
	};


	rep(i, n) {
		int com;
		cin >> com;
		rep(i, 9) {
			if (b[i] == 0) {
				if (a[i] == com) b[i] = 1;
			}
		}
	};


	rep(i, 3) {
		
		if (b[3*i] == 1 && b[3*i + 1] == 1 && b[3*i + 2] == 1) {
			ans = "Yes";
		};

		if (b[i] == 1 && b[i + 3] == 1 && b[i + 6] == 1) {
			ans = "Yes";
		};
	};

	
		if (b[0] == 1 && b[4] == 1 && b[8] == 1) {
			ans = "Yes";
		};


	
		if (b[2] == 1 && b[4] == 1 && b[6] == 1) {
			ans = "Yes";
		};
	
		cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int x;
    cin >> x;
    bool ans = x >= 30;
    cout << (ans? "Yes" : "No") << endl;

}

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

long long nCr(int n, int r) {
    if (r > n) {
        return 0;
    }
    if (r > n / 2) {
        r = n - r;
    }
    if (r == 0) {
        return 1;
    }
    long long choose = n;
    for (int i = 2; i <= r; i++) {
        choose *= n - i + 1;
        choose /= i;
    }
    return choose;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end(), greater<long long>());
    
    map<int,int> freq;
    for (int i = 0; i < n; i++) {
        freq[nums[i]]++;
    }
    
    long double mean = 0;
    long long amt = 0, prev = -1;
    for (int i = 0; i < a; i++) {
        mean += nums[i];
        if (nums[i] != prev) {
            prev = nums[i];
            amt = 1;
        }
        else {
            amt++;
        }
    }
    mean /= a;

    long long ways = 0;
    if (prev == nums[0]) {
        for (int i = a; i <= b; i++) {
            ways += nCr(freq[prev], i);
        }
    }
    else {
        ways = nCr(freq[prev], amt);
    }
    
    printf("%.20Lf\n%lld", mean, ways);
    return 0;
}

Measured memory_bytes: 3776
def main():
    h, w = map(int, input().split())
    a = [0]*26
    for i in range(h):
        s = input().rstrip()
        for c in s:
            a[ord(c) - ord("a")] += 1
    f = True
    for i in range(h//2):
        for j in range(w//2):
            sf = True
            for k in range(26):
                if a[k] >= 4:
                    a[k] -= 4
                    sf = False
                    break
            if sf:
                f = False
    if h%2 == 1:
        for j in range(w//2):
            sf = True
            for k in range(26):
                if a[k] >= 2:
                    a[k] -= 2
                    sf = False
                    break
            if sf:
                f = False
    if w%2 == 1:
        for i in range(h//2):
            sf = True
            for k in range(26):
                if a[k] >= 2:
                    a[k] -= 2
                    sf = False
                    break
            if sf:
                f = False
    if h%2 == 1 and w&2 == 1:
        sf = True
        for k in range(26):
            if a[k] >= 1:
                a[k] -= 1
                sf = False
                break
        if sf:
            f = False
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    str = (input().rstrip())
    cnt = 0
    for s in str:
        if(s == '2'):
            cnt += 1
    
    print(cnt)
        
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3940
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S := ReadString()
	v := make([]int, len(S)+1)

	for i := 0; i < len(S); i++ {
		if S[i] == '<' {
			v[i+1] = v[i] + 1
		}
	}
	for i := len(S) - 1; i >= 0; i-- {
		if S[i] == '>' {
			v[i] = Max(v[i], v[i+1]+1)
		}
	}

	ans := 0
	for _, a := range v {
		ans += a
	}
	fmt.Println(ans)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 9420
#include<stdio.h>
int main(void)
{
while(1){
 int m,a,b,p=0,c=0,d,l=0,h[4],temp,s,x;

 
  scanf("%d",&m);
  if (m==0) break;

  for (;;){

   if(m==6174) break;

   a=m/1000;
   b=(m%1000)/100;
   c=(m-(a*1000+b*100))/10;
   d=(m-(a*1000+b*100))%10;
if(a==b&&b==c&&c==d){
break;
}
   h[0]=a;
   h[1]=b;
   h[2]=c;
   h[3]=d;

   for (x=0;x<4;x++){
	for (s=x+1;s<4;s++){
	if (h[x]<h[s]){
	    temp=h[x];
	    h[x]=h[s];
	    h[s]=temp;
	    }
       }
    }

    
    s=0;
    a=h[0];
    b=h[1];
    c=h[2];
    d=h[3];

    l=a*1000+b*100+c*10+d;
    s=d*1000+c*100+b*10+a;

    c=l-s;

    p++;
    m=c;
    }
if(a==b&&b==c&&c==d)
printf("NA\n");
else 
printf("%d\n",p);
  
}
return 0;
}

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

int main(){
  long long N, T, S = 0;
  cin >> N >> T;
  
  vector<int> t(N);
  cin >> t.at(0);
  for (int i = 1; i < N; i++){
    cin >> t.at(i);
    if (t.at(i) - t.at(i-1) >= T){
      S += T;
    }
    else{
      S += t.at(i) - t.at(i-1);
    }
  }
  cout << S + T << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val, class Cmp, long long Inv>
struct StarrySkyTree {
    StarrySkyTree() {}
    StarrySkyTree(int n_) {
        for (n = 1; n < n_; n <<= 1);
        data = datb = vector<Val>(n << 1);
    }
    void add(int L, int R, Val x, int l, int r, int k) {
        if (L <= l && r <= R) {
            data[k] += x;
        } else if (l < R && L < r) {
            int mid = (l + r) >> 1;
            add(L, R, x, l, mid, (k << 1) + 1);
            add(L, R, x, mid, r, (k << 1) + 2);
            Val a = data[(k << 1) + 1] + datb[(k << 1) + 1];
            Val b = data[(k << 1) + 2] + datb[(k << 1) + 2];
            datb[k] = cmp(a, b) ? a : b;
        }
    }
    void add(int L, int R, Val x) {
        add(L, R, x, 0, n, 0);
    }
    Val query(int L, int R, int l, int r, int k) {
        if (L <= l && r <= R) {
            return data[k] + datb[k];
        } else if (l < R && L < r) {
            int mid = (l + r) >> 1;
            Val a = query(L, R, l, mid, (k << 1) + 1);
            Val b = query(L, R, mid, r, (k << 1) + 2);
            Val res = (cmp(a, b) ? a : b) + data[k];
            return res;
        } else {
            return Inv;
        }
    }
    Val query(int L, int R) {
        return query(L, R, 0, n, 0);
    }
    int n;
    vector<Val> data, datb;
    Cmp cmp;
};
using SSTMin32 = StarrySkyTree<int, less_equal<int>, INT_MAX / 3>;
using SSTMax32 = StarrySkyTree<int, greater_equal<int>, INT_MIN / 3>;
using SSTMin64 = StarrySkyTree<long long, less_equal<long long>, LLONG_MAX / 3>;
using SSTMax64 = StarrySkyTree<long long, greater_equal<long long>, LLONG_MIN / 3>;


void solve() {
    int N, M;
    cin >> N >> M;
    
    const int NN = 200005;
    static vector<pii> I[NN], O[NN];
    rep(i, M) {
        int l, r, a;
        cin >> l >> r >> a;
        I[l].emplace_back(r, a);
        O[r].emplace_back(l, a);
    }

    ll ans = 0;
    SSTMax64 sst(N + 1);
    for (int i = 1; i <= N; ++i) {
        each(p, I[i]) {
            sst.add(0, i, p.second);
        }

        ll x = sst.query(0, i);
        smax(ans, x);
        sst.add(i, i + 1, x);

        each(p, O[i]) {
            sst.add(0, p.first, -p.second);
        }
    }

    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 30336
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

auto input() {
    return InputType();
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

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

int main() {
    ll a = input();
    ll b = input();
    auto c = ll(ceil(double(a) / 0.08) + 0.0001);
    auto d = 10 * b;
    auto e = min(c, d);
    auto f = max(c, d);
    for (auto i = e; i <= f; ++i) {
        auto g = ll(0.08 * double(i)) == a;
        auto h = i / 10 == b;
        if (g && h) {
            cout << i << endl;
            return 0;
        }


    }
    cout << -1 << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int a[101],n,AS=0,BS=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=n-1;i>=0;i-=2){
        AS+=a[i];
    }
    for(int j=n-2;j>=0;j-=2){
        BS+=a[j];
    }
    cout<<AS-BS;

    return 0;
}


Measured memory_bytes: 3632
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n = ni()
a = na()
b = na()

p = 0
q = 0

for i in range(n):
    if a[i] < b[i]:
        m = b[i] - a[i]
        if m % 2 == 1:
            m -= 1
        p += m
    else:
        q += a[i] - b[i]

p //= 2

if p >= q:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

std::string N;
uint64_t D;

int dp(int d, uint64_t p, bool f, bool z, std::bitset<3> deg)
{
  if (d == D) {
    return deg.all() ? 1 : 0;
  }
  
  uint64_t X = f ? N[d] - '0' : 9, S = 0;
  for (uint64_t x = 0; x <= X; ++x) {
    if (z && x == 0) {
      bool g = f && (x == X);
      S += dp(d + 1, p, g, true, deg);
    } else if (x == 3 || x == 5 || x == 7) {
      std::bitset<3> new_deg(deg);
      if (x == 3) new_deg.set(0);
      if (x == 5) new_deg.set(1);
      if (x == 7) new_deg.set(2);
      
      uint64_t q = 0;
      if (x == 3) q = p * 10 + x;
      if (x == 5) q = p * 10 + x;
      if (x == 7) q = p * 10 + x;
      
      bool g = f && (x == X);
      S += dp(d + 1, q, g, false, new_deg);
    }
  }
  
  return S;
}

int main(int argc, char **argv)
{
  std::cin >> N;
  
  D = N.size();
  
  uint64_t S = dp(0, 0, true, true, std::bitset<3>(0));
  
  std::cout << S << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, K; cin >> N >> K;
    vector<int> T(N);
    for(int i=0; i<N; i++) {
        cin >> T[i];
    }

    int sum = N;
    vector<int> U;
    for(int i=0; i<N-1; i++) {
        U.push_back(T[i+1] - T[i] - 1);
    }

    sort(U.begin(), U.end());
    int take = N - K;
    for(int i=0; i<take; i++) sum += U[i];
    cout << sum << endl;
    return 0;
}



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

#ifdef _LOCAL
    #include <utils/debug.hpp>
    #include <utils/random_generate.hpp>
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 42
    #define generate_string(...) 42
    #define generate_array(...) 42
    #define generate_unique_array(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void scan(){}
template <class Head, class... Tail>
void scan(Head&& head, Tail&&... tail) {
    cin >> head;
    scan(forward<Tail>(tail)...);
}

void print(){}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
    for (auto v: vs){
        cout << v;
        if (&v != &vs.back()) cout << " ";
    }
    cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

void solve(){
    string s;
    scan(s);
    ll n = ll(s.length());
    if (s[n - 1] == 's') (s += 'e') += 's';
    else s += 's';
    println(s);
}

void test(ll num = 0, bool verbose = false){
    rep(i, max(1LL, num)){
        ll t = clock();
        if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
        solve();
        if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    #ifdef _LOCAL
        test(6, true);
    #else
        ll t = 0;
        if (multiple_queries) cin >> t;
        test(t, false);
    #endif
    return 0;
}

Measured memory_bytes: 3688
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var c = input[N].split(" ").map(i => parseInt(i));
  c.sort(function(a,b){return b-a});
  input.splice(N,input.length-N);
  input.shift();
  var e = input.map(i => i.split(" ").map(i => parseInt(i)));
  stem=1;
  var anssub=new Array(N).fill(-1);
  anssub[stem-1]=0;
  var queue=[stem];
  var num=1;
  while(queue.length!=0){
    for(var i=0;i<N-1;i++){
      if(e[i][0]==queue[0]){
        if(anssub[e[i][1]-1]==-1){
          anssub[e[i][1]-1]=num;
          num++;
          queue.push(e[i][1]);
        }
      }else if(e[i][1]==queue[0]){
        if(anssub[e[i][0]-1]==-1){
          anssub[e[i][0]-1]=num;
          num++;
          queue.push(e[i][0]);
        }
      }
    }
    queue.shift();
  }
  var anssub2=new Array();
  for(var i=0;i<N;i++){
    anssub2[i]=c[anssub[i]];
  }
  var ans2=[0];
  for(var i=0;i<N-1;i++){
    ans2[0]+=Math.min(anssub2[e[i][0]-1],anssub2[e[i][1]-1]);
  }
  var ans3=anssub2.join(" ");
  ans2.push(ans3);
  var ans=ans2.join("\n");

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17768
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
vector<int> ans;
vector<int> a1,a2;
int co;
int dep[100005];
bool st[100005];
int wuf;
int k;
void dfs(int i,int j,vector<int> gra[],int d)
{
	if(dep[i]==0)
	{
		st[i]=1;
		dep[i]=d;
		FOR(k,0,gra[i].size())
		{
			if(gra[i][k]!=j)
			dfs(gra[i][k],i,gra,d+1);
			if(wuf!=0)
			{
				if(wuf<d)
				ans.pb(i);
				break;
			}
		}
		st[i]=0;
	}
	else
	{
//		cout<<i<<' '<<d<<' '<<dep[i]<<' '<<k<<'\n';
		if((d-dep[i])<=k && st[i]==1)
		{
			wuf=dep[i];
			ans.pb(i);
		}
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int a,b=0;
		FOR(i,0,5)
		{
			cin>>a;
			b+=a;
		}
		cout<<15-b;
	}
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  //2倍無駄に検索しているのが気になる・・・
  //iがs.size()の半分でbreak?
  int count = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] != s[s.size()-i-1]) count++;
  }
  cout << count/2 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	m := make(map[rune]bool)
	for _, r := range s {
		m[r] = true
	}

	if ((m['S'] && m['N']) || (!m['S'] && !m['N'])) &&
		((m['W'] && m['E']) || (!m['W'] && !m['E'])) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
int a,b,c,d,e,f;
scanf("%d\n%d\n%d\n%d\n%d",&a,&b,&c,&d,&e);
if(a<0){
a=0-a;
f=a*c+d;
f=f+b*e;
}
else{
a=b-a;
f=e*a;
}
printf("%d\n",f);
return 0;
}



Measured memory_bytes: 2108
def isOK(index, key, a):
    if a[index] >= key:
        return True
    else:
        return False

def binary_search(key, a, N):
    ng = -1
    ok = N

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid, key, a):
            ok = mid
        else:
            ng = mid

    return ok

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
C.sort()

# C > B > Aの組み合わせを見つける
# C > B と　B > A の組み合わせの数をカウントしてその積をたす
ans = 0
for i in range(N):
    key = B[i]
    A_index = binary_search(key, A, N)
    C_index = binary_search(key + 1, C, N)
    # print('key: ',key)
    # print('A: ', A[A_index],'   ',A_index)
    # print('C: ', C[C_index],'   ',C_index)

    count_A = A_index
    count_C = N - C_index
    
    ans += count_A * abs(N-C_index)


print(ans)


Measured memory_bytes: 105572
#include <bits/stdc++.h>
#define forn(i,n) for(int i = 0 ; i < (int)n ; ++i)
#define fi first
#define se second
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)
#define __USE_MINGW_ANSI_STDIO 0
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

//const ll INF = LONG_LONG_MAX;
const double PI = acos(-1);
const int MAXN = 1e5+200;
const double EPS= 1e-10;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,W;
    cin>>n>>W;
    int v[n+1],w[W+1];
    ll dp[n+1][W+1];
    forn(i,n){
        cin>>w[i+1]>>v[i+1];
    }

    forn(i,n+1){
        forn(j,W+1){
            if(i==0 || j==0) dp[i][j] = 0;
            else if(j>=w[i]){
                dp[i][j] = max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];
}


Measured memory_bytes: 79232
X = int(input())
ans = ""
if    400 <= X <= 599: ans = "8"
elif  600 <= X <= 799: ans = "7"
elif  800 <= X <= 999: ans = "6"
elif 1000 <= X <= 1199:ans = "5"
elif 1200 <= X <= 1399:ans = "4"
elif 1400 <= X <= 1599:ans = "3"
elif 1600 <= X <= 1799:ans = "2"
elif 1800 <= X <= 1999:ans = "1"
print(ans)

Measured memory_bytes: 9160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int N = in.nextInt();
            int max = Math.max(H, W);
            out.println(N / max + ((N % max) > 0 ? 1 : 0));
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21588
N,K=map(int,input().split())

ablist=[]
for _ in range(N):
  a,b=map(int,input().split())
  ablist.append((a,b))
ablist.sort()
  
aslist=[]
s=0
for a,b in ablist:
  s+=b
  aslist.append((a,s))
#print(aslist)

for a,s in aslist:
  if s>=K:
    print(a)
    break

Measured memory_bytes: 27840
#define _GLIBCXX_DEBUG
#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 all(v) v.begin(), v.end()
#define sz(v) v.size()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int64_t A, B;
  cin >> A >> B;
  rep2(i, 1, B+1){
    if((A*i) % B == 0){
      cout << A*i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
const long long MOD = 1000000007;
typedef long long ll;

int n,k,q,f;
string s,t;
char c; bool r=0;

int main() {
  cin >> s >> q;
  deque<char> d;
  for(auto c : s) d.push_back(c);
  rep(i,q){
    cin >> n;
    if(n==1) r^=1;
    else{
      cin >> f >> c; 
      if(f==1) r ? d.push_back(c) : d.push_front(c);
      else r ? d.push_front(c) : d.push_back(c);
    }
  }
  if(r) reverse(all(d));
  for(auto c : d) cout << c;  
  cout << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <utility>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;

int main () {
    string S;
    cin >> S;
    lli N = S.size();
    lli ans = N * (N - 1) / 2 + 1;
    vector<int> c(26, 0);
    for (int i = N - 1; i >= 0; i--) {
        int pos = S[i] - 'a';
        ans -= (c[pos]);
        c[pos]++;
    }
    cout << ans << endl;

    /*
    map<string,vector<pii>> m;
    m[S].push_back({0, N - 1});
    REP (i, 0, N) {
        REP (j, i + 2, N + 1) {
            string C = S;
            reverse(C.begin() + i, C.begin() + j);
            m[C].push_back({i, j});
        }
    }
    cout << m.size() << endl;
    for (auto &s : m) {
        cout << s.first << " : ";
        for (auto &p : s.second) {
            cout << '{' << p.first << ' ' << p.second << "},";
        }
        cout << endl;
    }
    */
    return 0;
}


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

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); }

int big(int a, int b) {
  return a > b? a:b;
}

int main() {
  ioinit();
  int out, max = 1,N;
  vector<int> A;
  cin >> N;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    A.push_back(a);
  }

  vector<int> div;
  for(int i = 1 ; i*i <= big(A[0], A[1]); i++) {
    if(A[0] % i == 0) {
      div.push_back(i);
      if(i*i != A[0]) div.push_back(A[0]/i);
    }
    if(A[1] % i == 0) {
      div.push_back(i);
      if((i*i) != A[1]) div.push_back(A[1]/i);
    }
  }

  for(int i; i < div.size(); i++){
    if(A[0] % div[i] == 0 || A[1] % div[i] == 0){
      out = 0;
      for(int j = 0; j < N; j++){
        if(A[j] % div[i] != 0 && ++out == 2) break;
      }
      if(out < 2){
        if(max < div[i]) max = div[i];
      }
    }
  }
  
  cout << max << endl;
}


Measured memory_bytes: 892
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <tuple>
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }
using ll = long long;
constexpr int MOD = 1e9 + 7;
inline int quick_pow(int a, int n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = (ll)res * a % MOD;
		a = (ll)a * a % MOD;
		n >>= 1;
	}
	return res;
}
int fa[100005], sz[100005];
int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); }
std::pair<int, int> seq[100005];
int main()
{
	// freopen("AGC038-D.in", "r", stdin);
	int n, q, fix = 0, cnt = 0, rem = 0, comp = 0;
	ll m;
	scanf("%d%lld%d", &n, &m, &q);
	for (int i = 0; i < n; i++)
	{
		fa[i] = i;
		sz[i] = 1;
	}
	for (int i = 0; i < q; i++)
	{
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		if (!c)
		{
			u = getfa(u);
			v = getfa(v);
			if (u == v)
				continue;
			fa[u] = v;
			sz[v] += sz[u];
		}
		else
			seq[cnt++] = {u, v};
	}
	for (int i = 0; i < n; i++)
	{
		if (i == fa[i])
		{
			rem += sz[i] == 1;
			comp++;
			fix += sz[i] - 1;
		}
	}
	for (int i = 0; i < cnt; i++)
	{
		if (getfa(seq[i].first) == getfa(seq[i].second) ||
				(comp == 2 && !rem))
		{
			puts("No");
			return 0;
		}
	}
	puts(m < fix + comp - !cnt ||
		 m > fix + (ll)comp * (comp - 1) / 2 ?
		 "No" : "Yes");
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

int n;
vector <int> a;
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int x; cin >> x;
		a.pb(x);
	}
	sort(all(a));
	cout << a[n-1]-a[0];
}

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

int N,K;
int A[200010];
int sum[200020] = {0};

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    for(int i = 0; i < N; i++)sum[A[i] - 1]++;
    sort(sum,sum + N);
    int ans = N;
    for(int i = 0; i < K; i++)
    {
        ans -= sum[N - i - 1];
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cctype>

int main() {
    int num{};
    std::string w{}, s{};
    std::cin >> w;
    for(auto& c : w) { c = tolower(c); }
    while(std::cin >> s) {
        if(s=="END_OF_TEXT") break;
        for(auto& c : s) { c = tolower(c); }
        num += (s==w) ? 1 : 0;
    }
    std::cout << num << std::endl;
}



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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fa(x,y) for(auto x:y)
#define endl '\n'
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fr(i,x,n) for(i=x;i>=n;--i)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vi adl[100010];
int cc[100010];
int cur;

void dfs(int node){
    cc[node]=cur;
    for(auto x:adl[node]){
        if(cc[x]) continue;
        dfs(x);
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    int a[100010];
    f(n){
        cin>>a[i+1];
    }
    f(m){
        int x,y;
        cin>>x>>y;
        adl[x].pb(y);
        adl[y].pb(x);
    }
    cur=1;
    f(n){
        if(cc[i+1]) continue;
        dfs(i+1);
        ++cur;
    }
    int ans=0;
    f(n){
        if(cc[i+1]==cc[a[i+1]]) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w;cin>>h>>w;
  ll num=llINF,num2=llINF;
  if(h<=2||w<=2){
    if(h==1||w==1){
      if(h%3==0|w%3==0)
	cout<<0<<endl;
      else
	cout<<1<<endl;
    }else{
      if(h==2){
	for(ll i=1;i<w;i++){
	  num=min(num,max(h/2*i,h*(w-i))
		  -min(h/2*i,h*(w-i)));
	}
	cout<<min(2LL,num)<<endl;
      }else{
	for(ll i=1;i<h;i++){
	  num2=min(num2,max(w/2*i,w*(h-i))-min(w/2*i,w*(h-i)));
	}
	cout<<min(2LL,num2)<<endl;
      }
    }
  }else if(h%2&&w%2){
    for(ll i=1;i<w;i++){
      num=min(num,max(max(h/2*i,(h/2+1)*i),h*(w-i))
	      -min(min(h/2*i,(h/2+1)*i),h*(w-i)));
    }
    for(ll i=1;i<h;i++){
      num2=min(num2,max(max(w/2*i,(w/2+1)*i),w*(h-i))
	      -min(min(w/2*i,(w/2+1)*i),w*(h-i)));
    }
    cout<<min(min((h%3!=0)*w,(w%3!=0)*h),min(num,num2))<<endl;
  }else if(h%2){
    for(ll i=1;i<w;i++){
      num=min(num,max(max(h/2*i,(h/2+1)*i),h*(w-i))
	      -min(min(h/2*i,(h/2+1)*i),h*(w-i)));
    }
    for(ll i=1;i<h;i++){
      num2=min(num2,max(w/2*i,w*(h-i))-min(w/2*i,w*(h-i)));
    }
    cout<<min(min((h%3!=0)*w,(w%3!=0)*h),
	      min(num,num2))<<endl;
  }else if(w%2){
    for(ll i=1;i<w;i++){
      num=min(num,max(h/2*i,h*(w-i))
	      -min(h/2*i,h*(w-i)));
    }
    for(ll i=1;i<h;i++){
      num2=min(num2,max(max(w/2*i,(w/2+1)*i),w*(h-i))
	      -min(min(w/2*i,(w/2+1)*i),w*(h-i)));
    }
    cout<<min(min((h%3!=0)*w,(w%3!=0)*h),
	      min(num,num2))<<endl;
  }else{
    for(ll i=1;i<w;i++){
      num=min(num,max(h/2*i-h*(w-i),-h/2*i+h*(w-i)));
    }
    for(ll i=1;i<h;i++){
      num2=min(num2,max(w/2*i-w*(h-1),-w/2*i+w*(h-1)));
    }
    cout<<min(min((h%3!=0)*w,(w%3!=0)*h),min(num,num2))<<endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < k; i++) ans += p[i];
    cout << ans << "\n";
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

		int i;
		double s = 0;
		for(i = 0; i < n; i++) {
			s += (double)1/in.nextInt();
		}

		System.out.println((double)1 / s);
	}
}

Measured memory_bytes: 21844
# pragma GCC optimize("Ofast")
# pragma GCC target("avx,avx2,fma")
# pragma GCC optimization ("unroll-loops")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int gcd(int a, int b)
{
    if(b) return gcd(b,a%b);
    return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,dp[3005][3005];

const int mod = 1e9 + 7;

int32_t main(){_
    //freopen("in","r",stdin);
	cin >> n;
	string s;
	cin >> s;
	dp[1][1] = 1;
	for(int i = 2;i <= n;i++)
	{
		for(int j = 1;j <= i;j++)
		{
			if(s[i - 2] == '<')
			{
				dp[i][j] = dp[i - 1][j - 1];
			}
			else dp[i][j] = (dp[i - 1][i - 1] - dp[i - 1][j - 1] + mod) % mod;
			dp[i][j] += dp[i][j - 1];
			dp[i][j] %= mod;
		}
	}
	rc(dp[n][n]);
}

Measured memory_bytes: 69120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;

int main(){
	string s;
	in >> s;
	REP(i, s.size()) {
		int a =s[i]-65+26;
		a = (a - 3) % 26 +65;
		s[i]=a;
	}
	out << s << endl;
	int a; in >> a;
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    int p[n];
    rep(i, 0, n) cin >> p[i];
    int sum[n + 1] = {};
    rep(i, 1, n + 1) {
        sum[i] = sum[i - 1] + p[i - 1];
    }
    int mx = 0;
    int mxi = 0;
    rep(i, 0, n - k + 1) {
        int tmp = sum[i + k] - sum[i];
        if (mx < tmp) {
            mx = tmp;
            mxi = i;
        }
    }
    double ans = 0;
    rep(i, mxi, mxi + k) {
        ans += p[i] * (p[i] + 1) / 2.0 / (double)p[i];
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}


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

int main()
{
	unordered_set<int> S;
	int C = 0;

	auto f = [](auto g) {
		int n, x;
		cin >> n;
		while (n--) {
			cin >> x;
			g(x);
		}
	};

	f([&](int x){S.emplace(x);});

	f([&](int x){if(S.find(x) != S.end()) C++;});

	cout << C << endl;
}


Measured memory_bytes: 6888
#include <stdio.h>

int n, A[50];

int solve(int i, int m) {
    if (m == 0) return 1;
    if (i == n || m < 0) return 0;

    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q, M, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}

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

int main() {
  int L, R, d, count=0;
  cin >> L >> R >> d;
  for (int i=L; i<=R; i++) {
      if(i%d==0) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3640