akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int mm[5005];
int pre[5005];
int vis[5005];
vector<int>lol;
int p[5005];
int col[5005];

void dfs(int ver)
{
    lol.push_back(col[ver]);
    vis[ver]=1;
    if(!vis[p[ver]])
        dfs(p[ver]);
}

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>col[i];
    }

    int mx=-1e17;
    
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            lol.clear();
            int ans=0;
            dfs(i);
            int sz=lol.size();

            for(int j=0;j<sz;j++)
                pre[j+1]=pre[j]+lol[j];


            for(int j=1;j<=sz;j++)
            {
                for(int l=1;l<=sz;l++)
                {
                    ans=0;
                    if(l>=j)
                    {
                        if(l-j+1<=k)
                        {
                            ans+=pre[l]-pre[j-1];
                            if(pre[sz]>0)
                            {
                                ans+=((k-(l-j+1))/sz)*pre[sz];
                            }
                            mx=max(mx,ans);
                        }
                    }
                    else
                    {
                        if(l-j+1+sz<=k)
                        {
                            ans+=pre[sz]-pre[j-1]+pre[l];
                            if(pre[sz]>0)
                            {
                                ans+=((k-(l-j+1+sz))/sz)*pre[sz];
                            }
                            mx=max(mx,ans);
                        }
                        
                    }
                    
                }
            }
        }
    }
    cout<<mx;

    

}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
#include<map>
#include<tr1/unordered_map>
using namespace std;
typedef long long LL;
//map<int,int> mp;
tr1::unordered_map<int,int> mp;
int a[100005]; int prime[100005]; bool vis[100005]; int cnt; int sz; int fac[1005][2];
void initial(const int n=1e5)
{
	cnt=0;
	for(int i=2;i<=n;i++)
	{
		if(vis[i]==false) prime[++cnt]=i;
		for(int j=1;j<=cnt&&i*prime[j]<=n;j++)
		{
			vis[i*prime[j]]=true;
			if(i%prime[j]==0) break;
		}
	}
}
void work(int x)
{
	sz=0;
	for(int i=1;i<=cnt&&1ll*prime[i]*prime[i]<=x;i++)
	{
		if(x%prime[i]) continue;
		int t=0;
		while(x%prime[i]==0) x/=prime[i],t++;
		fac[++sz][0]=prime[i]; fac[sz][1]=t;	
	}	
	if(x!=1) fac[++sz][0]=x,fac[sz][1]=1;
} 
void dfs(int pos,int num)
{
	if(pos==sz+1)
	{
		mp[num]++;
		return ;
	}
	int x=1;
	for(int i=0;i<=fac[pos][1];i++)
	{
		dfs(pos+1,num*x);
		x=x*fac[pos][0];
	}
}
int main(void)
{
	initial();
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		work(a[i]); dfs(1,1);
	}
	int res=0;
	for(auto P:mp)
	{
		if(P.second>=n-1) res=max(res,P.first);
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    a.push_back(INF);
    int cnt = 1, ans = 0;
    rep(i, n)
    {
        if (a[i] == a[i + 1])
        {
            cnt++;
        }
        else
        {
            if (cnt != a[i])
            {
                if (cnt < a[i])
                    ans += cnt;
                else
                    ans += cnt - a[i];
            }
            cnt = 1;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int isPrime(int k){
    int lim = sqrt(k);
    for(int i = 2; i <= lim; i++){
        if(k % i == 0){
            return 0;
            break;
        }
    }
    return 1;
}

int main(){
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int k;
        scanf("%d", &k);
        int a = isPrime(k);
        if(a == 1){
            cnt++;
        }
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3176
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

vector<string> a;

bool solve(string &s, string &t,int num) {
	if (s.size() < t.size())return false;
	REP(i,t.size() - num, t.size())if (s[i] != t[i])return false;
	if (t.size() == s.size())return true;

	rep(i, a.size()) {
		t += a[i];
		bool res = solve(s, t, a[i].size());
		rep(j,a[i].size())t.erase(--t.end());
		if (res)return true;
	}
	return false;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	a = { "dreamer","dream","eraser","erase" };
	string S;
	cin >> S;
	string T = "";
	cout << (solve(S, T, 0) ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 1616
#include <stdio.h>
int main()
{
	int n, a, b;
	while(scanf("%d %d %d", &n, &a, &b)!=EOF)
	{
		if(n * a < b)
		{
			printf("%d\n",n * a);
		}
		else
		{
			printf("%d\n",b);
		}
	}
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,W;
    cin>>n>>W;
    ll dp[100005];
for(int i=0;i<100005;i++){
dp[i]=1e9+9;
}
dp[0]=0;

ll sum=0;
for(int i=0;i<n;i++){
ll w,v;
cin>>w>>v;
sum=sum+v;
//cout<<sum<<"  ";
// dp[i] represents minimum weight with value exactly i
for(int j=(sum-v);j>=0;j--){
dp[j+v]=min(dp[j+v],dp[j]+w);
}

}

ll ans=0;
for(int i=sum;i>=0;i--)
{ if(W>=dp[i])
{ //cout<<dp[i];
ans=i;
break;
}

}
cout<<ans;

    return 0;}


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

int main()
{
	string str;
	cin >> str;
	
	for(int i=0;i<3;i++)
	{
		if(str[i]=='1')str[i]='9';
		else if(str[i]=='9')str[i]='1';
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := newScanner()
	var n = sc.readInt()

	var cnt = 0
	for i := 1; i < n+1; i++ {
		cnt += (n - 1) / i
	}
	fmt.Println(cnt)
}

//////////////////
//////////////////
//////////////////

func abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func reverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func reverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type scanner struct {
	bufScanner *bufio.Scanner
}

func newScanner() *scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &scanner{bufSc}
}

func (sc *scanner) readString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *scanner) readInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *scanner) readInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...) std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v)
{
  for (auto & x : v) is >> x;
  return is;
}

template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v)
{
  auto n = v.size();
  os << "{";
  for (size_t i = 0; i < n; i++)
    os << (i > 0 ? "," : "") << v[i];
  return os << "}";
}

int main()
{
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int h, w; std::cin >> h >> w;
  auto print = [&] (auto&& v) {
    rep(i, 0, h) {
      rep(j, 0, w) {
        std::cout
          << (at(v, i, j) ? '#' : '.');
      }
      std::cout << std::endl;
    }
  };
  auto a = make_vector<2, int>(h, w);
  rep(i, 0, h) rep(j, 0, w)
  {
    char c; std::cin >> c;
    at(a, i, j) = c == '#';
  }
  auto b = make_vector<2, int>(h, w, false);
  auto c = make_vector<2, int>(h, w, false);
  rep(i, 0, h) rep(j, 0, w)
  {
    ((j == 0 || ((j < w - 1) && (i % 2 == 0)))
      ? at(b, i, j)
      : at(c, i, j))
      = true;
    if (at(a, i, j))
      at(b, i, j) = at(c, i, j) = true;
  }
  print(b);
  std::cout << std::endl;
  print(c);
  return 0;
}

Measured memory_bytes: 3712
N=int(input())
A=[int(input()) for i in range(N)]
if (sum(A)%10)!=0:
  print(sum(A))
else:
  B=[]
  C=[]
  for i in A:
    if i%10!=0:
      B.append(i)

  if len(B)==0:
    print(0)
  else:
    C=sorted(B)
    print(sum(A)-C[0])

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long int n,k,ans=0;
    cin >> n >> k;
    long long int h[n];
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    sort(h,h+n);
    
    for(int i=0; i<n-k; i++){
        ans += h[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=105;
const int MOD=1e9+7;


int wall[N][N];

int main()
{
    int h, w, n;
    cin>>w>>h>>n;
    int a, b, c;

    for(int i = 0; i < n; i++)
    {
        cin>>a>>b>>c;
        if(c == 1)
        {
            for(int i = 1; i <= h; i++)
                for(int k = 1; k <= a; k++)
                    wall[i][k] = 1;
        }
        else if(c == 2)
        {
            for(int i = 1; i <= h; i++)
                for(int k = a + 1; k <= w; k++)
                    wall[i][k] = 1;
        }
        else if(c == 3)
        {
            for(int i = 1; i <= w; i++)
                for(int k = b; k >= 0; k--)
                    wall[k][i] = 1;
        }
        else
        {
            for(int i = 1; i <= w; i++)
                for(int k = b + 1; k <= h; k++)
                    wall[k][i] = 1;
        }
    }

    int ans = 0;

    for(int i = 1; i <= h; i++)
        for(int k = 1; k <= w; k++)
            ans += 1 - wall[i][k];

    cout<<ans;


    return 0;
}





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

using ll = long long;

int main(void)
{
    ll n;
    cin >> n;
    n%=10;
    //cout << n << endl;
    if(n== 0 || n== 1 || n== 6 || n== 8)
    {
        cout << "pon" << endl;
    }
    else if(n== 3)
    {
        cout << "bon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,d[55],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>d[i];
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=d[i]*d[j];
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x == 3 )
    {
        cout<<"YES\n";
    }
    else if(x == 5)
    {
        cout<<"YES\n";
    }
    else if(x == 7)
    {
        cout<<"YES\n";
    }
    else cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
l=list()#empty list

for i in range(1,N+1):
    tempS,tempP = input().split()
    l.append([tempS,-int(tempP),i])

sortedList = sorted(l,key=lambda item:(item[0],item[1]))

for i in range(1,N+1):
    print(sortedList[i-1][2])


Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if ((x, y > 0) && (x - r >= 0) && (y - r >= 0) && (x + r <= W) && (y + r <= H))
	{
		printf("Yes\n");

	}
	else
	{
		printf("No\n");
	}
	return 0;
}


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

int main(){
  int n,a,c;
  int minn;

  int *b;
  
  while(true){
    cin >> n;
    if(n == 0) break;

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

    minn = abs(b[0] - b[1]);
    for(int i=0;i<n-1;++i){
      for(int k=i+1;k<n;++k){
	minn = min(minn,abs(b[i] - b[k]));
      }
    }

    delete[] b;
  cout << minn << endl;
  }

  /*
  while(true){
    cin >> n;
    if(n == 0) break;

    minn = 1000000;

    cin >> a;
    c = a;
    for(int i=1;i<n-1;++i){
      cin >> a;
      minn = min(minn, )
    }
  }
  */
  return 0;
}



Measured memory_bytes: 2996
#include<iostream>
#define N 105000
#define P 1000000007
using namespace std;
int   n,m,x[N],y[N],h[N],w[N],t,tl;
long long sum,ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    cin>>tl;
    for(int i=1;i<n;i++)
    {
        cin>>t;
        w[i]=t-tl;
        x[i]=1LL*i*(n-i)%P;
        tl=t;
    }
    cin>>tl;
    for(int j=1;j<m;j++)
    {
        cin>>t;
        h[j]=t-tl;
        y[j]=1LL*j*(m-j)%P;
        tl=t;
    }
    for(int j=1;j<m;j++)
        sum=(sum+1LL*y[j]*h[j]%P)%P;
    for(int i=1;i<n;i++)
        ans=(ans+1LL*x[i]*w[i]%P*sum)%P;
    ans=(ans+P)%P;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = long.Parse(Console.ReadLine());
            long i = X / 500;
            long j = (X % 500) / 5;
            Console.WriteLine(1000 * i + 5 * j);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
 
#define fir first
#define sec second
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define All(s) (s).begin(), (s).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define vi vector<int> 
#define vvi vector<vector<int> >
using namespace std;
 
typedef unsigned long long int ll;
const int Mod = 1e9 + 7;
const int max_n = 3 * 1e5 + 1;
const ll INF = 10241024;
long double INFD = 100100100;
 
//_________template______________
inline void IN(void){
  return;
}
 
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}
 
inline void OUT(void){
  cout << "\n";
  return;
}
 
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
 
//_____________________　following sorce code_________________________//
string s;
void input(){
  IN(s);
}
 
void solve(){
  input();
  if(s == "SUN")cout << 7;
  else if(s == "MON") cout << 6;
  else if(s == "TUE") cout << 5;
  else if(s == "WED") cout << 4;
  else if(s == "THU") cout << 3;
  else if(s == "FRI") cout << 2;
  else if(s == "SAT") cout << 1;
 
  cout << endl;
 
}
 
int main () {
    solve();
    return 0;
}
 

Measured memory_bytes: 256
x, y = map(int, input().split())

result = 0
if x == 1:
  result += 300000
if x == 2:
  result += 200000
if x == 3:
  result += 100000
if y == 1:
  result += 300000
if y == 2:
  result += 200000
if y == 3:
  result += 100000
if x == 1 and y == 1:
  result += 400000
print(result)

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

using namespace std;

int main()
{
    string s;
    int a[10000] = {};
    int n; cin >> n;
    for(int i =0; i < n; i++)
    {
       cin >> s;
       a[s[0]]++;
    }
   cout << "AC x " << a['A'] << endl;
   cout << "WA x " << a['W'] << endl;
   cout << "TLE x " << a['T'] << endl;
   cout << "RE x " << a['R'] << endl;
}


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

bool searchKey(int A[], int size, int x) {
  A[size] = x;
  int i = 0;
  while (A[i] != x) {
    i++;
  }
  return i != size;
}

int n, q, S[10000 + 1];

void solve() {
  scanf("%d", &n);
  rep(i,0,n)
  {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  int sum = 0, key;
  rep(i,0,q)
  {
    scanf("%d", &key);
    if (searchKey(S, n, key)) {
      sum++;
    }
  }
  printf("%d\n", sum);
}
int main() {
  solve();
  return 0;
}



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

const int h=19;
const int w=15;
const int INF=30;

int dh[]={0,-1,-1,-1, 0, 1,1,1};
int dw[]={1, 1, 0,-1,-1,-1,0,1};
bool isRange(int i,int j){
    return 0<=i && i<h && 0<=j && j<w;
}
int dfs(int nh,int nw,vector<string> &f){
    if(nh>=h || isRange(nh,nw) && nh==h-1) return 0;
    if(!isRange(nh,nw)) return INF;
    int res=INF;
    for(int i=0;i<8;i++){
        int toh=nh+dh[i];
        int tow=nw+dw[i];
        if(isRange(toh,tow) && f[toh][tow]=='X'){
            stack<pair<int,int>> st;
            while(isRange(toh,tow) && f[toh][tow]=='X'){
                f[toh][tow]='.';
                st.push({toh,tow});
                toh+=dh[i];
                tow+=dw[i];
            }
            res=min(res,dfs(toh,tow,f)+1);
            while(!st.empty()){
                auto ret=st.top(); st.pop();
                f[ret.first][ret.second]='X';
            }
        }
    }
    return res;
}
int main(){
    vector<string> f(h);
    for(int i=0;i<h;i++) cin>>f[i];
    int inih=-1,iniw=-1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(f[i][j]=='O'){
                inih=i,iniw=j;
                f[i][j]='.';
            }
        }
    }
    
    int res=dfs(inih,iniw,f);
    cout<<(res>=INF ? -1 : res)<<endl;
    return 0;
}


Measured memory_bytes: 3236
A, B = map(int, input().split())
A -= 1
B -= 1
G = []
for h in range(50):
    G.append(["#"]*100)
for h in range(50):
    G.append(["."]*100)
i, j = 0, 0
for _ in range(A):
    G[i][j] = "."
    j += 2
    if j>=100:
        i += 2
        j = 0
i, j = 99, 0
for _ in range(B):
    G[i][j] = "#"
    j += 2
    if j>=100:
        i -= 2
        j = 0
print(100,100)
for i in range(100):
    print("".join(G[i]))

Measured memory_bytes: 62572
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int n,m;
    while(cin>>n>>m,n){
        vi d(101,0);
        int mx=-1;
        rep(i,n){
            int p,q; cin>>p;
            rep(j,p){
                cin>>q; d[q]++;
                mx=max(mx,d[q]);
            }
        }
        cout<<(mx<m?0:(find(all(d),mx)-d.begin()))<<endl;
    }
}

Measured memory_bytes: 3020
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	x1,x2,x3,x4,x5 = inputMap()

	if x1 == 0:
		print(1)
	elif x2 == 0:
		print(2)
	elif x3 == 0:
		print(3)
	elif x4 == 0:
		print(4)
	else:
		print(5)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 70916
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ans = 0
for i in range(N + 1):
    s = list(str(i))

    cnt = 0
    for x in s:
        cnt += int(x)

    if A <= cnt <= B:
        ans += i

print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double lxd;
#define INF 1000000007
#define mem(dp,a) memset(dp,a,sizeof dp)
#define flash ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define f(i,n) for (ll i=0;i<n;i++)
#define fo(i,x,n) for (ll i=x;i<=n;i++)
#define pb(x) push_back(x)
#define tr(c,it) for(((c).begin())it=(c).begin();it!=(c).end();it++)
#define test ll t; cin>>t;
#define fls fflush(stdout) ;
int main()
{
  ll n,k;cin>>n>>k;
  ll height[n],dp[n];
  for(ll i=0;i<n;i++)cin>>height[i];
  dp[0]=0;
  dp[1]=abs(height[1]-height[0]);
  ll mn;
  for(ll i=2;i<k+1&&i<n;i++)
  {     mn=INT_MAX;
      for(ll j=i-1;j>=0;j--)
    {
       mn=min(mn,dp[j]+abs(height[j]-height[i]));
       dp[i]=mn;
    }
  }
  for(ll i=k+1;i<n;i++)
  {   mn=INT_MAX;
      for(ll j=i-1;j>=i-k;j--)
    {
         mn=min(mn,dp[j]+abs(height[j]-height[i]));
         dp[i]=mn;
    }
  }
  // for(ll i=0;i<n;i++)cout<<dp[i]<<" ";cout<<endl;
   cout<<dp[n-1]<<endl;
   return 0; 
}



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

int main() {
    long ans = LONG_MAX, h, w, o;
    cin >> h >> w >> o;
    vector<vector<char>> field(h, vector<char>(w));
    rep(i, h) {
        string t;
        cin >> t;
        rep(j, w) field.at(i).at(j) = t.at(j);
    }
    rep(i, pow(2, h - 1)) {
        vector<int> temp;
        rep(j, h - 1) {
            if(1 & (i >> j)) temp.push_back(j);
        }
        long s = temp.size();
        temp.push_back(h - 1);
        vector<vector<int>> st(temp.size(), vector<int>(w, 0));
        rep(j, w) {
            int l = 0;
            rep(k, temp.size()) {
                for(; l <= temp.at(k); l++) st.at(k).at(j) += field.at(l).at(j) - '0';
            }
        }
        bool flag = true;
        rep(j, w) {
            rep(k, temp.size()) {
                if(st.at(k).at(j) > o) flag = false;
            }
        }
        if(!flag) continue;
        rep(j, w - 1) {
            bool ttt = true;
            rep(k, temp.size()) {
                if(st.at(k).at(j) + st.at(k).at(j + 1) > o) ttt = false;
            }
            if(ttt) {
                rep(k, temp.size()) {
                    st.at(k).at(j + 1) += st.at(k).at(j);
                }
            } else {
                s++;
            }
        }
        ans = min(ans, s);
    }
    cout << ans << endl;
}

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

struct UnionFind {
  vector<int> ps, rs;

  UnionFind(){};

  UnionFind(int n) {
    ps.resize(n, 0);
    rs.resize(n, 0);
    for (int i = 0; i < n; ++i)
      ps[i] = i;
  }

  int find(int x) {
    if (ps[x] != x)
      ps[x] = find(ps[x]);
    return ps[x];
  }

  void unite(int x, int y) {
    int x_root = find(x);
    int y_root = find(y);
    if (x_root == y_root)
      return;
    if (rs[x_root] < rs[y_root])
      swap(x_root, y_root);
    ps[y_root] = x_root;
    if (x_root == y_root)
      rs[x_root] += 1;
  }
};

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

  UnionFind u(n);
  vector<int> fs(n), gs(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    u.unite(a, b);
    fs[a]++;
    fs[b]++;
  }
  for (int i = 0; i < n; ++i) {
    gs[u.find(i)] += 1;
  }

  vector<vector<int>> cd(n);
  for (int i = 0; i < k; ++i) {
    int c, d;
    cin >> c >> d;
    --c, --d;
    cd[c].push_back(d);
    cd[d].push_back(c);
  }

  for (int i = 0; i < n; ++i) {
    int ans = gs[u.find(i)] - fs[i] - 1;
    for (int x : cd[i]) {
      if (u.find(x) == u.find(i))
        ans -= 1;
    }
    if (i != 0)
      cout << " ";
    cout << ans;
  }
  cout << endl;
}

Measured memory_bytes: 8320
n=int(input())
lst=[]

tup = tuple(map(int,input().split()))




m=int(input())

for i in range(m):
    prev,nxt=input().split()
    prev=int(prev)
    nxt=int(nxt)
    lst=list(tup)
    res = 0
    lst[prev-1]=nxt
    for i in range(n):
        res=res+lst[i]
    print(res)




Measured memory_bytes: 9164
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var list = new List<Tuple<String, int>>();
            for (int i = 0; i < n; i++)
            {
                list.Add(Tuple.Create(cin.next(), cin.nextInt()));
            }
            var x = cin.next();

            var flag = false;
            var ans = 0;
            for (int i = 0; i < n; i++)
            {
                if (flag)
                {
                    ans += list[i].Item2;
                }
                if (x.Equals(list[i].Item1))
                {
                    flag = true;
                }                
            }

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	string s[10] = { "pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon" };
	int n; cin >> n;
	cout << s[n % 10] << endl;
	return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    char x, y;
    cin >> x >> y;
    cout << (x == y ? "=" : (x < y ? "<" : ">")) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

bool am[50][50];
bool node[50];
int n, m;

void dfs(int x) {
  node[x] = true;
  for (int i = 0; i < n; i++) {
    if (am[x][i] == true && node[i] == false) dfs(i);
  }
}

bool node_check() {
  for (int i = 0; i < n; i++) {
    if (node[i] == false) return true;
  }
  return false;
}

int main() {
  cin >> n >> m;
  REP(i, n) { 
    REP(j, n) { 
      am[i][j] = false;
    }
  }
  pi tmp;
  REP(i, m) {
    cin >> tmp.first >> tmp.second;
    am[tmp.first-1][tmp.second-1] = true;
    am[tmp.second-1][tmp.first-1] = true;
    node[i] = false;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      if (am[i][j] == true) {
	am[i][j] = am[j][i] = false;
	dfs(0);
	if (node_check()) cnt++;
	am[i][j] = am[j][i] = true;
	for (int k = 0; k < n; k++) node[k] = false;
      }
    }
  }
  dump(cnt);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n;cin>>n;
  int sum=0;
  vector<int>a(n),b(n),c(n-1);
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n-1)cin >> c[i];
  rep(i,n)a[i]--;

  rep(i,n){
    sum+=b[i];
  }
  rep(i,n-1){
  if(a[i]+1==a[i+1]){
      sum += c[a[i]];
    }
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 256
n, m, l = map(int, input().split())
A = [(list(map(int, input().split()))) for i in range(n)]
B = [(list(map(int, input().split()))) for i in range(m)]
C = [[0] * l for _ in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for line in C:
    print(*line)


Measured memory_bytes: 7044
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main(){
    int a,b;
    cin >> a >> b;
    REP(i,100000){
        double tmp=i+1;
        int an=tmp*0.08;
        int bn=tmp*0.1;
        if ( an== a && bn == b){
            cout << tmp << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

int main(){
    int n,d;
    cin >> n >> d;
    int ans=1;
    while((2*d+1)*ans < n){
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 998244353 
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000005
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define PI M_PI
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}


void solve()
{  
   string s1,s2;
   cin >> s1 >> s2;
   int n=s1.size(),ans=0;
   for(int i=0;i<n;i++)
   {
       if(s1[i]!=s2[i])ans++;
   }
   cout << ans;
}

signed main()
{ 
    boost
    int test=0,t;
    //cin >> t ;
    t=1;
   while(test++ <t){
	  //cout<<"Case #"<<test<<": ";
	   solve();}
  
}

Measured memory_bytes: 3888
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)

N = int(input())
S =[input() for i in range(N)]

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)


Measured memory_bytes: 60760
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // not prime num
            return false;
        }
    }
    // prime num
    return true;
}

vector<int> G[100010];
vector<int> d_White(100010,INFint), d_Black(100010,INFint);
void dfs(int start, int d, vector<int>& v){
    for(int i=0; i<G[start].size(); i++){
        int to=G[start][i];
        if(v[to]==INFint) {
            v[to] = d + 1;
            dfs(to, d + 1, v);
        }
    }
}

int main() {
    int N;
    cin >> N;
    int snuke=0, fennec=0;

    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    d_Black[1]=0;
    dfs(1,0,d_Black);

    d_White[N]=0;
    dfs(N,0,d_White);

    for(int i=1; i<=N; i++){
        if(d_White[i]>=d_Black[i]){
            fennec++;
        }else{
            snuke++;
        }
    }
    string ans=(fennec>snuke) ? "Fennec" : "Snuke";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1000000007
#define oo 1000006
int f[100005];
int n,m;
vector<int> a[100005];
int x,y,res;
int tinh(int i)
{
    if(f[i]!=-1) return f[i];
    f[i]=0;
    for(int j=0;j<a[i].size();j++)
        f[i]=max(f[i],tinh(a[i][j])+1);
    return f[i];
}
main()
{
    cin>>n>>m;
    F(i,1,m){cin>>x>>y;a[y].pb(x);}
    reset(f,-1);
    F(i,1,n)
    {
        f[i]=0;
        F(j,0,a[i].size()-1)MAX(f[i],tinh(a[i][j])+1);
    }
    F(i,1,n)MAX(res,f[i]);
    cout<<res;

}


Measured memory_bytes: 10624
# coding: utf-8
def solve(n,m)
  # まずSをあまらせないように消費する
  if m < n * 2
    # Cが足りない
    s_s = m / 2
    puts s_s
    return
    # s_c = s_s * 2
  end
  c_rest = m - (n * 2)
  scc_c = c_rest / 4
  puts (n + scc_c)
end

def main
  n,m = gets.split.map(&:to_i)
  solve(n,m)
end

main


Measured memory_bytes: 1788
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

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

using namespace std;
typedef long long int ll;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  sort(all(a));
  vector<ll> v= a;
  v.erase(unique(all(v)),v.end());

  vector<ll> va, vaa;
  va.push_back(-1);
  rep(i, v.size()) va.push_back(distance(a.begin(), upper_bound(all(a),v.at(i))) - 1);
  rep(i, va.size()-1) vaa.push_back(va.at(i+1)-va.at(i));

  sort(all(vaa));

  ll sum =0;
  rep(i, v.size()-k) sum+= vaa.at(i);
  cout << sum << endl;


  return 0;
}

Measured memory_bytes: 8048
<?php
$n = intval(fgets(STDIN));
for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%d%d", $a[], $b[]);
}
$num = 1;
$sum = 0;
for($i = $n-1; $i >= 0; $i--){
  $num2 = ceil(($a[$i]+$sum) / $b[$i]) * $b[$i];
  $diff = $num2 - $a[$i] - $sum;
  $sum+=$diff;
  $num = $num2;
}
echo $sum;

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

using namespace std;

int main () {
  int N;
  vector<double> v;

  cin >> N;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    v.push_back((double)a);
  }

  sort(v.begin(),v.end());

  for (int i=0; i<N-1; i++) {
    v[i+1] = (v[i] + v[i+1])/2.0;
  }

  cout << v[N-1] << endl;
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

inline int addmod(lli x,lli y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
    return (x%mod * y%mod)%mod;
}


inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
 //  freopen("input.txt","r",stdin);
    FastIO;

    lli a[7];

    while(cin>>a[0])
    {
        for(int i=1; i<7; i++) cin>>a[i];
        swap(a[0],a[1]);
        lli ans = 0;

        if((a[1]%2 + a[4]%2 + a[3]%2) >= 2 && (a[1]>0 && a[3]>0 && a[4]>0)){
            for(int k : {1,3,4}) a[k]--;
            ans += 6;
        }

        ans += a[0]*2 + (a[1]/2)*4 + (a[3]/2)*4 + (a[4]/2)*4;

        cout<<ans/2<<endl;
    }

    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 256
N,A = map(int,input().split())
X = list(map(int,input().split()))

Xp = [0]
Xm = [0]
Xz = 0
for x in X:
    if x-A > 0:
        Xp.append(x-A)
    elif x-A < 0:
        Xm.append(x-A)
    else:
        Xz += 1

DPp = [[0 for j in range(2501)] for i in range(len(Xp))]
DPm = [[0 for j in range(2501)] for i in range(len(Xm))]

DPp[0][0] = 1
DPm[0][0] = 1

for i in range(1,len(DPp)):
    x = Xp[i]
    for j in range(2501):
        if j >= x:
            DPp[i][j] = DPp[i-1][j] + DPp[i-1][j-x]
        else:
            DPp[i][j] = DPp[i-1][j]

for i in range(1,len(DPm)):
    x = -Xm[i]
    for j in range(2501):
        if j >= x:
            DPm[i][j] = DPm[i-1][j] + DPm[i-1][j-x]
        else:
            DPm[i][j] = DPm[i-1][j]

ans = 1

for j in range(1,2501):
    ans += DPp[len(DPp)-1][j]*DPm[len(DPm)-1][j]
ans = ans*pow(2,Xz) - 1
print(ans)


Measured memory_bytes: 4340
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

istream& operator>> (istream& a, pii& b) {
    cin >> b.first >> b.second;
    return a;
}

ostream& operator<< (ostream& a, const pii& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = b * 10; i <= b * 10 + 9; i++) {
        if (i * 8 / 100 == a) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
}
/*

*/  

Measured memory_bytes: 256
from collections import deque
import copy
H, W = map(int, input().split())
 
start = set()
for y in range(H):
  for x, w in enumerate(input()):
    if w == '.':
      start.add((x,y))

score = 0
ssize = [(-1,0),(0,-1),(1,0),(0,1)]
for xy in start:
  d = deque()
  d.append((xy+(0,)))
  step = 0
  can = copy.deepcopy(start)
  can.remove(xy)
  while len(d) > 0:
    now = d.popleft()
    step = now[2]
    for xs, ys in ssize:
      nxt = (now[0]+xs, now[1]+ys)
      if nxt in can:
        d.append(nxt+(step+1,))
        can.remove(nxt)
  score = max(step, score)
  
print(score)

Measured memory_bytes: 59484