akhauriyash/Code-Regression huggingface dataset:
def main(p, swaps)
  forest = swaps.each_with_object({}) do |(x, y), f|
    root_x, root_y = root(x, f), root(y, f)
    next if root_x == root_y
    new_root, new_node = root_x < root_y ? [root_x, root_y] : [root_y, root_x]
    f[new_node] = new_root
  end

  groups = p.each_with_object({}) do |num, gs|
    r = root(num, forest)
    gs[r] ||= []
    gs[r].push num
  end.values

  match_nums = groups.flat_map do |indexes|
    nums = indexes.map { |i| p[i - 1] }
    indexes & nums
  end

  match_nums.size
end

def root(value, forest)
  v = value
  loop do
    next_v = forest[v]
    return v if next_v.nil? || v == next_v
    v = next_v
  end
end

_, m = gets.split(" ").map(&:to_i)
p = gets.split(" ").map(&:to_i)
swaps = m.times.map { gets.split(" ").map(&:to_i) }
puts main(p, swaps)

Measured memory_bytes: 30772
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cctype>
#include<vector>
#include<queue>
#include<map>
using namespace std;

int main() {
	int N, a, b, c;
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a >> b >> c;
		if (a*a == b*b + c*c || b*b == a*a + c*c || c*c == b*b + a*a)cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

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

typedef long long ll;
#define int ll

using namespace std;

const int N=2e5+10;

int inv[N];

signed main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int p;
        cin>>p;
        inv[p]=i;
    }
    int ans=n-1;
    for(int t=1,i=2;i<=n;i++)
        if(inv[i]>inv[i-1])
            t++,ans=min(ans,n-t);
        else
            t=1;
    cout<<ans;
}


Measured memory_bytes: 1792
#include<iostream>

int Check(int n, int x);

int main()
{
	while (true) {
		int n, x;

		int count = 0;
		std::cin >> n >> x;
		if (n == 0 && x == 0)
			return 0;

		std::cout << Check(n, x) << std::endl;
	}
}

int Check(int n, int x) {
	int count = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			for (int k = j + 1; k <= n; k++) {
				if (i + j + k == x)
					count++;
			}
		}
	}
	return count;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[25100000] = {};

int main(){
    int N;
    cin >> N;
    long long int g1, s1, b1, g2, s2, b2;
    cin >> g1 >> s1 >> b1;
    cin >> g2 >> s2 >> b2;
    long long int S1 = N;
    for(int i = 0; i <= 5000; i++){
        for(int j = 0; j <= 5000; j++){
            if(i * g1 + j * s1 > N){
                continue;
            }
            long long int rem = N - i * g1 - j * s1;
            S1 = max(S1, i * g2 + j * s2 + rem);

            long long int k = (N - i * g1 - j * s1) / b1;
            rem = N - i * g1 - j * s1 - k * b1;
            S1 = max(S1, i * g2 + j * s2 + k * b2 + rem);
        }
    }
    for(int i = 0; i <= S1; i++){
        DP[i] = i;
    }
    for(int i = 0; i <= S1; i++){
        DP[i + s2] = max(DP[i + s2], DP[i] + s1);
        DP[i + b2] = max(DP[i + b2], DP[i] + b1);
    }
    long long int ans = 0;
    for(int i = 0; i * g2 <= S1; i++){
        ans = max(ans, i * g1 + DP[S1 - i * g2]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 195584
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cctype>
#include <cmath>
#include <fstream>

using namespace std;

typedef long long ll;
#define REP(i,k) for(int (i)=0;(i)<(k);(i)++)
#define INF ~(1<<31)
#define CLR(a) memset((a),0,sizeof((a)))
#define EPS 1e-9
#define DBG 1
#define D(s,v) if(DBG) cout<<(s)<<": "<<(v)<<endl;
#define DVEC(s,v) if(DBG) {cout<<(s)<<": "; for(int i=0;i<(v).size();i++) cout<<(v)[i]<<" "; cout<<endl;}
#define DARR(s,v,n) if(DBG) {cout<<(s)<<": "; for(int i=0;i<n;i++) cout<<(v)[i]<<" "; cout<<endl;}

int main(){
    ios_base::sync_with_stdio(0);

    ll N,H;

    while(cin>>N>>H){
        vector<ll> a,b;
        for(int i=0;i<N;i++){
            ll aa, bb;
            cin>>aa>>bb;
            a.push_back(aa);
            b.push_back(bb);
        }

        sort(a.begin(),a.end());
        reverse(a.begin(),a.end());
        sort(b.begin(),b.end());
        reverse(b.begin(),b.end());

        ll sum[b.size()+1];
        CLR(sum);
        ll cur = 0;
        for(int i=1;i<=b.size();i++){
            cur += b[i-1];
            sum[i] = cur;
        }

        ll res = 1e9+10;
        for(int t=0;t<=N;t++){
            ll rem = H - sum[t];
            ll w = 0;
            if(rem>=0){
                w = rem / a[0];
                if(rem%a[0]!=0) w++;
            }
            res = min(res, t+w);
        }

        cout<<res<<endl;
    }
}

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

struct edge{
	int to,color,num;
};
using graph=vector<vector<edge>>;
signed main(){
	int N; cin>>N;
	vector<bool> start(N,true);
	graph G(N);
	for(int i=0;i<N-1;i++){
		int a,b; cin>>a>>b; a--; b--;
		edge tmp; tmp.to=b; tmp.color=0; tmp.num=i;
		G[a].push_back(tmp);
		start[b]=false;
	}
	int S;
	for(int i=0;i<N;i++){
		if(start[i]){S=i; break;}
	}
	vector<set<int>> col(N);
	vector<int> ans(N-1);
	queue<int> que;
	que.push(S);
	int col_num=0;
	while(!que.empty()){
		int v=que.front();
		que.pop();
		int tmp_col=1;
		for(auto i:G[v]){
			first:
			if(!col[v].count(tmp_col)){
				i.color=tmp_col;
				col[v].insert(tmp_col);
				col[i.to].insert(tmp_col);
				ans[i.num]=tmp_col;
			}
			else{
				tmp_col++;
				goto first;
			}
			que.push(i.to);
			col_num=max(col_num,tmp_col);
		}
	}
	cout<<col_num<<endl;
	for(int i=0;i<N-1;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 20864
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}

signed main(){
  int sum[100000+1]={};
  for(int i=1;i<=100000;i++){
    int a;
    if(isPrime(i) && isPrime((i+1)/2)) a=1;
    else a=0;
    sum[i]=sum[i-1]+a;
  }
  int Q;
  cin >> Q;
  //rep(i,8) cout << sum[i] << endl;
  rep(i,Q){
    int l,r;
    cin >> l >> r;
    cout << sum[r]-sum[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    
    int i , j , k , n;
    string str;

    cin>>str;
    int len = str.size();

    for ( i = 0 ; i <len ; i ++)
    {
        if (str[i]=='B')
        {
            int temp = i;
            str[i] = 'x';
            while (temp!=-1)
            {

                temp--;
                if (str[temp]=='0'||str[temp]=='1')
                    {

                        str[temp] = 'x';
                        break;
                    }

            }
        }
    }
    for ( i = 0 ; i <len ; i ++)
    {
        if (str[i]=='1'||str[i]=='0')
        printf("%c",str[i]);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+20;
int n,w,h,Max[N<<2],tag[N<<2];
pair<int,int> p[N],sta1[N],sta2[N];
#define lc x<<1
#define rc x<<1|1
void init(int x,int l,int r){
    tag[x]=0;
    if (l==r) return void(Max[x]=-p[l].first);
    int mid=(l+r)>>1;
    init(lc,l,mid);init(rc,mid+1,r);
    Max[x]=max(Max[lc],Max[rc]);
}
void add(int x,int d){Max[x]+=d;tag[x]+=d;}
void add(int x,int l,int r,int L,int R,int d){
    if (l>=L&&r<=R) return add(x,d);
    if (tag[x]) add(lc,tag[x]),add(rc,tag[x]),tag[x]=0;
    int mid=(l+r)>>1;
    if (L<=mid) add(lc,l,mid,L,R,d);
    if (R>mid) add(rc,mid+1,r,L,R,d);
    Max[x]=max(Max[lc],Max[rc]);
}
int ans,top1,top2;
void push1(int x,int y){
    while (top1&&sta1[top1].second<y)
        add(1,0,n,sta1[top1-1].first,sta1[top1].first-1,sta1[top1].second),top1--;
    sta1[++top1]=make_pair(x,y);
    add(1,0,n,sta1[top1-1].first,x-1,-y);
}
void push2(int x,int y){
    while (top2&&sta2[top2].second>y)
        add(1,0,n,sta2[top2-1].first,sta2[top2].first-1,-sta2[top2].second),top2--;
    sta2[++top2]=make_pair(x,y);
    add(1,0,n,sta2[top2-1].first,x-1,y);
}
void solve(){
    sort(p+1,p+n+1);
    init(1,0,n);
    int mid=h>>1;top1=top2=0;
    for (int i=1;i<=n;i++){
        ans=max(ans,p[i].first+Max[1]);
        ans=max(ans,p[i].first-p[i-1].first+h);
        if (p[i].second>mid) push1(i,0),push2(i,p[i].second);
            else push1(i,p[i].second),push2(i,h);
    }
    ans=max(ans,w+Max[1]);
}
int main()
{
    scanf("%d%d%d",&w,&h,&n);
    for (int i=1;i<=n;i++) scanf("%d%d",&p[i].first,&p[i].second);
    p[++n]=make_pair(0,0);
    p[++n]=make_pair(0,h);
    p[++n]=make_pair(w,0);
    p[++n]=make_pair(w,h);
    solve();
    for (int i=1;i<=n;i++) swap(p[i].first,p[i].second);swap(w,h);
    solve();
    printf("%d\n",ans<<1);
    return 0;
}


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

using namespace std;

using int64 = long long;

struct INFTY {
  const int64 infll = (1LL << 62) - 1;
  const int inf = (1 << 30) - 1;

  operator int64() { return infll; }

  operator int() { return inf; }
} inf;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

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

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, H[5000], P[5000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> H[i] >> P[i];
  }
  vector< int > ord(N);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int a, int b) {
    return H[a] + P[a] < H[b] + P[b];
  });
  int64 lim = inf;
  vector< int64 > dp(N + 1, lim);
  dp[0] = 0;
  for(int i : ord) {
    for(int j = N - 1; j >= 0; j--) {
      if(dp[j] <= H[i]) chmin(dp[j + 1], dp[j] + P[i]);
    }
  }
  for(int i = N; i >= 0; i--) {
    if(dp[i] != lim) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 384
#include  <iostream>
#include <vector>

using namespace std;

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

int main(void)
{
	string s;
	cin >> s;
	rep(i, s.length() - 8) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

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

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

const int MOD = 1e9 + 7;

int ar[1005];

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int num = i;
        for (int j = 2; j <= num; j++) {
            while (num % j == 0) {
                ar[j]++;
                num /= j;
            }
        }
    }
    int ans = 1;
    for (int i = 0; i < 1005; i++)
        ans = (ans * 1LL * (ar[i] + 1)) % MOD;
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mx 100000
#define pb push_back
#define siz(v) v.size()
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;

int main()
{
 	ios_base::sync_with_stdio(0);
 	cin.tie(0); cin.tie(0);
	// freopen("input.txt","r",stdin);
	ll a;
	cin >> a;
	cout << a*a + a*a*a + a <<"\n";






 return 0;
 }


Measured memory_bytes: 3612
import kotlin.math.max

fun popcount(x:Int):Int{
    var x = x
    var res = 0
    while(x>0) {
        if(x%2==1) res++
        x/=2
    }
    return res
}

fun calcF(n:Int):MutableList<Int> {
    var res = MutableList<Int>(n+1,{_->0})
    for(i in 1..n){
        res[i] = res[i%popcount(i)]+1;
    }
    return res
}

fun calcSum(x:List<Int>,p:Int):Int{
    var base = 1
    var sum = 0
    for(i in x.indices.reversed()){
        sum+=x[i]*base
        sum%=p
        base=base*2%p
    }
    return sum
}
fun main() {
    val n = readLine()!!.toInt()
    val x = readLine()!!.map({c -> c-'0'})
    
    val cntx = x.sum()
    val f = calcF(n)

    val pFor1 = max(cntx-1,1)
    val pFor0 = cntx+1
    val sumFor1 = calcSum(x,pFor1)
    val sumFor0 = calcSum(x,pFor0)

    var base0 = 1
    var base1 = 1
    var res = MutableList<Int>(n,{_->0})
    for(i in n-1 downTo 0){
        if(cntx==1 && x[i]==1){
            res[i] = 0
        }
        else{
            var tar:Int
            if(x[i]==0){
                tar = sumFor0+base0
                tar = (tar%pFor0+pFor0)%pFor0
            }
            else{
                tar = sumFor1-base1
                tar = (tar%pFor1+pFor1)%pFor1
            }
            res[i] = f[tar]+1
        }
        base0=base0*2%pFor0
        base1=base1*2%pFor1
    }
    for(i in 0 until n){
        println(res[i])
    }
}


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

void comb_array(long long n, vector<long long> *pnC)
{ // nCk mod MODNUMBER
	(*pnC)[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		(*pnC)[i] = (*pnC)[i - 1] * (n - i + 1) / i;
	}
	if ((*pnC)[n] != 1)
	{
		printf("error");
	}

	return;
}

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

	long long N, P;
	scanf("%lld %lld", &N, &P);

	long long A;
	long long even = 0, odd = 0;
	for (long long i = 0; i < N; i++)
	{
		cin >> A;
		if (A % 2 == 0)
		{
			even++;
		}
		else
		{
			odd++;
		}
	}
	// cout << even << " " << odd << "\n";

	long long result;
	vector<long long> combination(odd + 1);
	comb_array(odd, &combination);

	if (P == 0)
	{
		result = 0;
		for (int i = 0; i <= odd; i = i + 2)
		{
			result += combination[i];
		}
	}
	else
	{
		result = 0;
		for (int i = 1; i <= odd; i = i + 2)
		{
			result += combination[i];
		}
	}
	// cout << result << "\n";
	for (int i = 1; i <= even; i++)
	{
		result = result * 2;
	}

	cout << result;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main( void )
{
	char s[10+1];
	scanf("%s", s ) ;
	int T = 0, t = 0 ;
	for( char * p = s ; *p ; p++ ) {
		switch(*p) {
		case 'A' : case 'C' : case 'G' : case 'T' : t++ ; break ;
		default :
			if( t > T ) T = t ;
			t = 0 ;
			break ;
		}
	}
	printf("%d\n", t > T ? t : T ) ;
	return 0 ;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;

const int maxn = 1111;
const int mod = 1e9 + 7;
long long dp[maxn][maxn];

int main() {
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 1; i <= h; ++i) {
        string str;
        cin >> str;
        for (int j = 0; j < str.length(); ++j) {
            int x = i;
            int y = j + 1;
            if (str[j] == '#') {
                continue;
            }
            if (x == 1 && y == 1) {
                dp[x][y] = 1;
            } else {
                dp[x][y] = dp[x - 1][y] + dp[x][y - 1];
                // cout << x << " " << y << " " << dp[x][y] << endl;
                dp[x][y] %= mod;
            }
        }
    }
    printf("%lld\n", dp[h][w]);
}

Measured memory_bytes: 8960
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
 
int main(){
    int n,a[220000],b[220000];
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
     scanf("%d",&a[i]);
     b[i]=a[i];
  }
   sort(b+1,b+n+1);
   int l=b[n/2],r=b[n/2+1];
   for(int i=1;i<=n;i++){
      int ans=a[i]<=l?r:l;
      printf("%d\n",ans);
    }
    return 0;
}

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

ll fx(ll h){
  if(h==1)
    return 1;
  ll p=h/2;
  if(mp[p]!=0)
    return 1+2*mp[p];
  return 1+2*fx(p);
}



int main()
{
  mp[1]=1;
  mp[0]=0;
  ll h;
  cin>>h;
  ll res=fx(h);
  cout<<res;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> v;

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

  int res = 0;
  for (int i = 0; i < n - 2; i++)
  {
    if ((v[i] < v[i + 1] && v[i + 1] < v[i + 2]) || (v[i + 2] < v[i + 1] && v[i + 1] < v[i]))
    {
      res++;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
ope1,ope2,ope3,ope4,concent,capacity = map(int,input().split())
ope1 *= 100
ope2 *= 100
noudo = -1
check = 0
check_capacity = 0
result =""

for i in range(int(capacity / ope1)+1):
    for x in range(int( (capacity -(i*ope1)) /ope2 )+1):
        if i+x == 0:
            continue
        for y in range(int( (capacity -(i*ope1 +x*ope2)) /ope3)+1):
            for z in range( int( (capacity -(i*ope1 +x*ope2 +y*ope3) ) /ope4)+1):
                if y+z ==0:
                    if noudo < 0:
                        noudo = 0
                        result = (str(i * ope1 + x * ope2 + y * ope3 + z * ope4) + " " + str(y * ope3 + z * ope4))
                    continue
                check = (100 *(y*ope3 + z*ope4)) / ( i*ope1 + x*ope2 + y*ope3 + z*ope4)

                if check > noudo and ((i*ope1+x*ope2)/100)*concent>= y*ope3+z*ope4:
                    noudo = check
                    result = (str(i*ope1+x*ope2+y*ope3+z*ope4)+" "+str(y*ope3+z*ope4))
print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;         
long long n,m,d[405][405],cnt,x,y;
char b[405][405];
void go(int i, int j)
{
    if(b[i][j]=='#') 
	{
		++x;
	}
    else 
	{
		++y;
	}
    d[i][j]=cnt;
    if(i>0 && d[i-1][j]==-1 && b[i-1][j]!=b[i][j])
	{
        go(i-1,j);
    }
    if(j>0 && d[i][j-1]==-1 && b[i][j-1]!=b[i][j])
	{
        go(i,j-1);
    }
    if(i<n-1 && d[i+1][j]==-1 && b[i+1][j]!=b[i][j])
	{
        go(i+1,j);
    }
    if(j<m-1 && d[i][j+1]==-1 && b[i][j+1]!=b[i][j])
	{
        go(i,j+1);
    }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>b[i][j];
		}
	}
    memset(d,-1,sizeof d);
    long long ans=0;
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		if(d[i][j]==-1)
			{
				x=0;
				y=0;
            	go(i,j);
            	cnt++;
            	ans+=x*y;
        	}
		}
	}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16640
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	while(cin>>a>>b>>c,a!=-1||b!=-1||c!=-1){
	int now=a*3600+b*60+c;
	int ans=7200-now;
	cout<<"0"<<ans/3600<<":";
	if(ans%3600/60<10)cout<<"0";
	cout<<ans%3600/60<<":";if(ans%60<10)cout<<"0";cout<<ans%60<<endl;
	ans=(7200-now)*3;
	cout<<"0"<<ans/3600<<":";
	if(ans%3600/60<10)cout<<"0";
	cout<<ans%3600/60<<":";if(ans%60<10)cout<<"0";cout<<ans%60<<endl;
	}
	
	return 0;
}

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

int arr[102];

int main() {
    int x,n,a,sol=0,diff=INT_MAX;
    cin >> x >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        arr[a]=1;
    }
    for (int i=0;i<=101;i++) {
        if (arr[i]==1) {continue;}
        if (abs(x-i)<diff) {
            sol=i;
            diff=abs(x-i);
        }
    }
    cout << sol << endl;

}


Measured memory_bytes: 3672
#include<cstdio>
#include<cmath>
#include<algorithm>>
#include<cstring>
using namespace std;
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	printf("%d %d",min(a,b),max(0,a+b-n));
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;


int main()
{
    int n;
    cin >> n;
    int a[8] = {0};
    int r = 0;
    for(int i = 0; i < n; i++){
        int c;
        cin >> c;
        if(c < 3200){
            a[c/400]++;
        }else{
            r++;
        }
    }
    int ans1 = 0,ans2 = 0;
    int none = 0;
    for(int i = 0; i < 8; i++){
        if(a[i] > 0){
            ans1++;
        }
        if(a[i] == 0){
            none++;
        }
    }
    if(ans1 + none <= 8){
        ans2 = ans1 + r;
    }else {
        ans2 = 8;
    }
    if(ans1 == 0){
        ans1 = 1;
    } 
    cout << ans1 << ' ' << ans2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 1000006

using namespace std;

int n;
int a[N], b[N];

bool check(int);

int main(){
	scanf("%d", &n);n = n * 2 - 1;
	int l = 999999999, r = 0, ans;
	for(int i = 1; i <= n; ++i)
		scanf("%d",a + i), l = min(l, a[i]), r = max(r, a[i]);
	while(l <= r){
		int mid = l + r >> 1;
		if(check(mid)) l = mid + 1, ans = mid;
		else r = mid - 1;	
	//	cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

bool check(int x){
	int cnt1 = 0, cnt2 = 0;
	for(int i = 1; i <= n; ++i)
		if(a[i] >= x) b[i] = 1, ++cnt1;
		else b[i] = 0, ++cnt2;
	b[0] = -1;b[n + 1] = -1;
	int pos = n / 2 + 1, tmp1 = 0, tmp2 = 0;
	while(b[pos + tmp1 + 1] != b[pos + tmp1] && pos + tmp1 <= n) ++tmp1;
	while(b[pos - tmp2 - 1] != b[pos - tmp2] && pos - tmp2 >= 1) ++tmp2;
//	cout << x << endl;for(int i = 1; i <= n; ++i) cout << b[i] << ' ';cout << endl;cout << tmp1 << ' ' << tmp2 << endl;
	if(tmp1 == tmp2){
		if(pos - tmp2 == 0)
			return cnt1 > cnt2;	
		else return b[pos - tmp1];
	}
	else{
		if(tmp1 < tmp2) return b[pos + tmp1];
		else return b[pos - tmp2];
	}
}

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

#define int long long

template <typename T> 
struct WeightedUnionFind{	
  int n;
  T d;
  vector<int> r,p;
  vector<T> ws;
  WeightedUnionFind(){}
  WeightedUnionFind(int sz,T d_):
    n(sz),d(d_),r(n,1),p(n),ws(n,d){iota(p.begin(),p.end(),0);}
  int find(int x){
    if(x==p[x]){
      return x;
    }else{
      int t=find(p[x]);
      ws[x]+=ws[p[x]];
      return p[x]=t;
    }
  }
  T weight(int x){
    find(x);
    return ws[x];
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y,T w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y),w=-w;
    r[x]+=r[y];
    p[y]=x;
    ws[y]=w;
  }
  T diff(int x,int y){
    return weight(y)-weight(x);
  }
};

signed main() {
	int n, m;
	while ( cin >> n >> m, n ) {
	
		WeightedUnionFind<int> uf(n, 0);
		for ( int i = 0; i < m; i++ ) {
			char c;
			cin >> c;
			int a, b;
			cin >> a >> b;
			a--; b--;
			if ( c == '!' ) {
				int c;
				cin >> c;
				uf.unite(a, b, c);
			} else {
				if ( !uf.same(a, b) ) cout << "UNKNOWN" << endl;
				else cout << uf.diff(a, b) << endl;			
			}
		}
	}
	
}

						



Measured memory_bytes: 5220
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
//________
#define pb        emplace_back
#define fi        first
#define se        second
#define ALL(x)    x.begin(),x.end()
#define err(...)  fprintf(stderr, __VA_ARGS__ )
#define show(x)   cerr << #x << ':' << (x) << endl
#define outl(x)   cout << (x) << '\n'
#define FAST()    cin.tie(0), ios::sync_with_stdio(false)
#define rep(i,n)     for(int i=0; i<(n); ++i)
#define reps(i,f,n)  for(int i=(f); i<=(n); ++i)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
constexpr int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
typedef long long ll;
typedef pair<int,int> pii;
#define let const auto
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

bool f(const char*s)
{
   int len = strlen(s);
   int i = 0; 
   int  j = len -1;
   while (i < j) {
      if (s[i]  != s[j]) {
         return (false);
      }
      ++i, --j;
   }
   return (true);
}

signed main()
{
   FAST();
   int a, b;
   char s[20];
   int cnt = 0;
   cin >> a >> b;
   reps(i, a, b) {
      sprintf(s, "%d", i);
      if (f(s)) {
         ++cnt;
      }
   }
   outl(cnt);
}



Measured memory_bytes: 256
n,q = map(int,input().split())
s = list(input())
c = 0
t = [0]
for i in range(1,n):
        if s[i] == "C" and s[i-1] == "A":
                c = c + 1
        t.append(c)

for i in range(q):
        t1,t2=map(int,input().split())
        print(t[t2-1]-t[t1-1])

Measured memory_bytes: 55032
import math
import os
import sys
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, S = [int(sys.stdin.readline()) for _ in range(2)]


@lru_cache(maxsize=None)
def f(b, n):
    if n < b:
        return n
    return f(b, int(n // b)) + n % b


if S > N:
    print(-1)
    exit()
if S == N:
    print(N + 1)
    exit()

# #########
# b = 2
# ans = -1
# prev = 0
# while b <= N:
#     if f(b, N) > prev:
#         print(b, N, f(b, N))
#     prev = f(b, N)
#     b += 1
# ##########

b = 2
ans = -1
while b <= math.sqrt(N) + 1:
    if f(b, N) == S:
        ans = b
        break
    b += 1
if ans >= 0:
    print(ans)
    exit()

ans = INF
# b > sqrt(N) のとき 2 桁になるので上位桁を全探索する
for d2 in range(1, int(math.sqrt(N)) + 1):
    if (N - S) % d2 == 0:
        b = int(1 + (N - S) // d2)
        if b >= 2 and f(b, N) == S:
            ans = min(ans, b)
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 156908
# 以下の 2 つの条件の両方を満たすマスはいくつありますか？
# マスの番号は奇数
# マスに書かれた整数は奇数
n = int(input())
a = list(map(int, input().split()))
# 2 つの条件の両方を満たすマス
ans = 0
for i in range(n):
    # マスの番号は奇数
    # マスに書かれた整数は奇数
    if (i+1) % 2 == 1 and a[i] % 2 == 1:
        ans += 1
print(ans)


Measured memory_bytes: 9028
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define INF 1000000007
using namespace std;
int main(){
  int K,S;
  scanf("%d %d",&K,&S);
  int cnt=0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      int z=S-i-j;
      if(0<=z&&z<=K) cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
int main(){
    int n,w; cin>>n>>w;
    vector<pair<int,int>>data(n);
    int dp[101][10001]={};
    for(int i=0;i<n;++i) cin>>data[i].first>>data[i].second;
    for(int i=n-1;i>=0;--i){
	for(int j=1;j<=w;++j){
	    if(j<data[i].second) dp[i][j]=dp[i+1][j];
	    else dp[i][j]=max(dp[i+1][j],dp[i+1][j-data[i].second]+data[i].first);
	}
    }
    cout<<dp[0][w]<<endl;
    return 0;
}


Measured memory_bytes: 7028
from itertools import permutations
from math import hypot, factorial
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
 
total = 0
for p in permutations(a):
    for i in range(N-1):
        total += hypot(p[i][0]-p[i+1][0], p[i][1]-p[i+1][1])
    
print(total / factorial(N))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    string input;
    string output = "";
    int i;
    cin >> input;

    for(i = 0; i < input.length(); i+=2) {
        output += input[i];
    }

    cout << output << endl;
       
    return 0;
}

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

const int MAXN = 100005;

int n, a[MAXN], b[MAXN];
pair <int, int> v[MAXN];

int main(){
	scanf("%d", &n);
	
	int l = 0, r = 1 << 30;
	for(int i = 0; i < n; i++){
		scanf("%d %d", &v[i].first, &v[i].second);

		l = max(l, v[i].first);
		r = min(r, v[i].second);
		
		a[i] = l;
		b[i] = r;
	}
	
	int res = 0;
	
	l = 0, r = 1 << 30;
	for(int i = n - 1; i >= 0; i--){
		int cl = l;
		if(i > 0)cl = max(cl, a[i - 1]);
		
		int cr = r;
		if(i > 0)cr = min(cr, b[i - 1]);
		
		res = max(res, (v[i].second - v[i].first + 1) + max(0, cr - cl + 1));
		
		l = max(l, v[i].first);
		r = min(r, v[i].second);
	}
	
	sort(v, v + n);
	
	int m = 0;
	for(int i = 0; i < n; i++){
		if(m == 0)v[m++] = v[i];
		else if(v[m - 1].first == v[i].first)continue;
		else{
			while(m > 0 && v[m - 1].second >= v[i].second)m--;
			v[m++] = v[i];
		}
	}
	
	l = 0, r = 1 << 30;
	for(int i = 0; i < m; i++){
		l = max(l, v[i].first);
		r = min(r, v[i].second);
		
		a[i] = max(0, r - l + 1);
	}
	
	l = 0, r = 1 << 30;
	for(int i = m - 1; i >= 1; i--){
		l = max(l, v[i].first);
		r = min(r, v[i].second);
		
		res = max(res, a[i - 1] + max(0, r - l + 1));
	}
	
	printf("%d\n", res);
	
	return 0;
}


Measured memory_bytes: 1792
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}


struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll freq[1000005]={0};
    ll mm[1000005]={0};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
    vc<ll> v(n);
    generate(all(v),nxt);

    rep(a,0,n)
        freq[v[a]]++;
    ll ans=0;

    for(ll a=1;a<1000001;a++)
    {
        if(freq[a]==1 and mm[a]==0)
            ans++;
        if(freq[a]==0)
            continue;
        for(ll b=2*a;b<1000001;b+=a)
            mm[b]=1;
    }
    cout<<ans<<endl;
	printclock;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3)){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}


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

using namespace std;

typedef long long LL;
#define TIMES(i_, n_) for(int i_ = 0; i_ < n_; ++i_)

template <class T>
struct BinaryIndexedTree/*{{{*/
{
  vector<T> tree;
  const int size;
  BinaryIndexedTree(int s) : tree(s), size(s) {}
  // i 番目までの要素の累積和
  T read(int i) const
  {
    T sum = 0;
    while (i > 0) {
      sum += tree[i];
      i -= i & -i;
    }
    return sum;
  }

  // i 番目の要素
  T read_single(int i) const
  {
    T sum = tree[i];
    if (i > 0) {
      const int z = i - (i & -i);
      --i;
      while (i != z) {
        sum -= tree[i];
        i -= (i & -i);
      }
    }
    return sum;
  }

  void add(int i, T v)
  {
    while (i <= size) {
      tree[i] += v;
      i += (i & -i);
    }
  }

  int search(T v) {
      int left = 0, right = size;
      while(left+1 < right) {
          const int center = (left+right) / 2;
          if(read(center) < v) {
              left = center;
          } else {
              right = center;
          }
      }
      if(right == size || read(right) != v) return -1;
      return right;
  }
};/*}}}*/

struct Bug {
    LL a, b;
};

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<Bug> bugs(N);
    TIMES(i, N) {
        cin >> bugs[i].a >> bugs[i].b;
    }
    sort(bugs.begin(), bugs.end(), [](const Bug a, const Bug b) {
            return a.a < b.a;
            });
    int ans = 0;
    int left = 0, right = N+1;
    while(left+1 < right) {
        const int k = (left + right) / 2;
        BinaryIndexedTree<LL> bit(100002);
        BinaryIndexedTree<int> bit_cnt(100002);
        for(const auto &bug : bugs) {
            const int idx = 100001 - int(bug.b);
            bit.add(idx, bug.a);
            bit_cnt.add(idx, 1);
            const auto lim = bit_cnt.search(k);
            //cout << k << ' ' << (100001 - lim) << ' ' << bit.read(lim) << ' ' << bit_cnt.read(lim) << endl;
            if(lim != -1 && bit.read(lim) <= (LL)k * (100001 - lim)) {
                ans = k;
                break;
            }
        }
        if(ans == k) {
            left = k;
        } else {
            right = k;
        }
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 7000
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
n,k=l()
A=l()
d={}
for i in range(n):
    if(A[i] not in d):
        d[A[i]]=0
    d[A[i]]+=1
x=[]
for ks in d:
    x.append([d[ks],ks])
x.sort()
if(len(x)<=k):
    print(0)
else:
    s=0
    for i in range(len(x)-k):
        s+=x[i][0]
    print(s)



Measured memory_bytes: 46648
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp

if s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi"
  puts 'Yes'
else
  puts 'No'
end


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

enum Sauce{ NOT_DETERMINED = 0, Tomato = 1, Cream = 2, Basil = 3 };
enum Seq{ SAME, DIFF };

const int divisor = 10000;

class Pasta{
public:
	Pasta(int _N);
	~Pasta();

	Sauce* sauceary;
	int schedule(int i, Sauce yesterday, Seq seq);

private:
	int N;
	int*** memo;
};

Pasta::Pasta(int _N){
	N = _N;
	sauceary = new Sauce[N + 1];
	memo = new int**[N + 1];

	for (int i = 0; i <= N; i++) sauceary[i] = NOT_DETERMINED;

	for (int i = 0; i <= N; i++){
		memo[i] = new int*[4];
		for (int j = 0; j < 4; j++){
			memo[i][j] = new int[2];
			memo[i][j][SAME] = -1;
			memo[i][j][DIFF] = -1;
		}
	}
}

Pasta::~Pasta(){
	delete[] sauceary;
	delete[] memo;
}

int Pasta::schedule(int i, Sauce yesterday, Seq seq){
	if (i == N + 1) return 1;
	if (memo[i][yesterday][seq] >= 0) return memo[i][yesterday][seq];

	if (seq == SAME && yesterday == sauceary[i]){
		memo[i][yesterday][SAME] = 0;
		return 0;
	}

	if (sauceary[i] == NOT_DETERMINED){
		int tmpmemo = 0;

		for (int si = 1; si <= 3; si++){
			if ((Sauce)si == yesterday && seq == SAME) continue;
			else if ((Sauce)si == yesterday && seq == DIFF) tmpmemo += schedule(i + 1, (Sauce)si, SAME) % divisor;
			else tmpmemo += schedule(i + 1, (Sauce)si, DIFF) % divisor;
		}

		memo[i][yesterday][seq] = tmpmemo % divisor;
		return memo[i][yesterday][seq];
	}
	else {
		if (yesterday == sauceary[i]) memo[i][yesterday][seq] = schedule(i + 1, sauceary[i], SAME) % divisor;
		else memo[i][yesterday][seq] = schedule(i + 1, sauceary[i], DIFF) % divisor;
			
		return memo[i][yesterday][seq];
	}
}

int main(){
	int N, K;
	cin >> N >> K;

	Pasta* pasta = new Pasta(N);

	for (int i = 0; i < K; i++){
		int A, B;
		cin >> A >> B;
		pasta->sauceary[A] = (Sauce)B;
	}

	cout << pasta->schedule(1, NOT_DETERMINED, DIFF) << endl;

	delete pasta;
	return 0;
}

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

typedef long long ll;

int main() {
	int n,k;
	cin >> n >> k;
	vector< int > a(n);
	for (auto& e:a)cin >> e;
	// bool y = 1;
	for (int i=0;i+k<n;i++) {
		cout << (a[i+k] > a[i] ? "Yes" : "No") << '\n';
	}
	return 0;
}


Measured memory_bytes: 4048
#include<stdio.h>
int main(void){
	int N,M,i;
	scanf("%d %d\n",&N,&M);
	int A[M];
	for(i=0;i<M;i++)
		scanf("%d",&A[i]);
	for(i=0;i<M;i++)
		N=N-A[i];
	if(N<0)
		N=-1;
	printf("%d\n",N);
	return 0;
}

Measured memory_bytes: 1768
#include<bits/stdc++.h>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
    return (a.second > b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
ll sumofdigit(ll n)
{
    ll c=0,d=0,sum=0,i;
    while(n>0)
    {
        c=n%10;
        sum+=c;
        n/=10;
    }
    return sum;
}

int main()
{
     fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
        ll  k,i,j,c=0,d=0,sum=0,e=0,f=0,g=0,h=0,n,maxi=0;
        cin>>n>>k;
        if(k>=n)
        {
            cout<<"unsafe";
        }
        else
            cout<<"safe";



     }

}


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

int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    cout.precision(18);
    cout << (a * a * b > x + x ? atan(a * b * b / 2. / x) : atan((a * a * b - x) * 2. / a / a / a)) * 45 / atan(1) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>

using namespace std;

int main(void){
    long long n, m, a[100],b[100], ans[100];
    cin >> n >> m;
    for(int i=0;i<n;i++){
        ans[i] = 0;
    }
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        for(int j=0;j<n;j++){
            if(j+1 == a[i]){
                ans[j]++;
            }
            if(j+1 == b[i]){
                ans[j]++;
            }
        }
    }

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

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,K,A[202020],F[202020];
ll i, j, k;
ll ans;

bool bs(ll a){
    //printf("\n%lld:\n", a);
    ll k = K;
    ll i;
    fornum(i,0,N){
        ll b = (A[i] * F[i] - a);
        k -= max( b/ F[i]+(b%F[i]>0), 0ll);
        //printf("%lld ", k);
        if(k<0)
            return false;
    }
    return true;
}

int main(){
    scanf("%lld%lld",&N,&K);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    sort(A, A + N);
    fornum(i,0,N){
        scanf("%lld", &F[i]);
    }
    sort(F, F + N,greater<ll>());
    ll l = 0, r = 1e15;
    while(l<r){
        ll c = (l + r)/2;
        if(bs(c)){
            r = c;
        }else{
            l = c + 1;
        }
    }
    printf("%lld", r);

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;

int main(){
	fast_io();
	int n,k;
	cin >> n >> k;
	ll res = n/k;
	ll ans = 0;
	ans += res * res * res;
	if((k&1) == 0){
		res = (n + k/2)/k;
		ans += res * res * res;
	}
	cout << ans << '\n';
}



Measured memory_bytes: 256
import math
N = int(input())
L = [input() for i in range(N)]
L = sorted(list(map("".join, list(map(sorted, list(map(list, L)))))))
c = 0
ans = 0
for j in range(1,N):
    if not L[j] == L[j - 1]:
        ans += (j - c)*(j - c - 1)/2
        c = j
    elif j + 1 == N:
        ans += (j + 1 - c)*(j - c)/2
print(int(ans))

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

ll A, B;
bool dp[100][100];

bool read() {
    if (!(cin >> A >> B))
        return false;

    return true;
}

void solve() {
    cout << ((abs(A - B) > 1) ? "Alice" : "Brown") << endl;
}

int32_t main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 256
x,k,d=map(int,input().split())
x=abs(x)
if x-k*d>=0:
    print(x-k*d)
else:
    m=x//d
    x=x-m*d
    k=k-m
    if k%2==0:
        print(x)
    else:
        print(abs(x-d))
    


Measured memory_bytes: 9172
n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.append(0)
s=0
for i in range(1,n+2):
  s += abs(a[i]-a[i-1])
for i in range(1,n+1):
  if a[i-1] <= a[i] <= a[i+1] or a[i-1] >= a[i] >= a[i+1]:
    print(s)
  else:
    print(s-2*min(abs(a[i-1]-a[i]),abs(a[i]-a[i+1])))

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

int main() {
	char s;
	bool a = false;
	bool b = false;
	
	for(int i=0; i<3; ++i){
		scanf("%c", &s);
		
		if(s == 'A')
			a = true;
		else if(s == 'B')
			b = true;
	}	
	
	if(a && b)
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll N;
vector<string> ans;
void solve(ll n, string S){
    ll nn=S.size();
    if(nn==N) {
        ans.emplace_back(S);
        return;
    }
    rep(i,n){
        char c='a'+i;
        string buf=S;
        buf+=c;
        solve(n,buf);
    }
    S+='a'+n;
    n+=1;
    solve(n,S);
}
//--MAIN-----------------------------------
void Main() {
    cin>>N;
    solve(0,"");
    SORT(ans);
    for(auto x: ans){
        cout<< x <<"\n";
    }
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 7796