akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        //dummy=0,A=1,G=2,C=3,T=4
        var dp = new long[N+1,5,5,5];
        dp[0, 0, 0, 0] = 1;
        for (int n = 0; n < N; ++n)
        {
            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 5; ++j)
                {
                    for (int k = 0; k < 5; ++k)
                    {
                        for (int l = 1; l < 5; ++l)
                        {
                            //AGC GAC ACG A?GC AG?C (i,j,k,l)
                            if (j == 1 && k == 2 && l == 3
                            || j == 2 && k == 1 && l == 3
                            || j == 1 && k == 3 && l == 2
                            || i == 1 && k == 2 && l == 3
                            || i == 1 && j == 2 && l == 3)
                            {
                                continue;
                            }
                            dp[n + 1, j, k, l] = (dp[n + 1, j, k, l] + dp[n, i, j, k]) % 1000000007;
                        }
                    }
                }
            }
        }
        var ans = 0L;
        for (int i = 1; i < 5; ++i)
        {
            for (int j = 1; j < 5; ++j)
            {
                for (int k = 1; k < 5; ++k)
                {
                    ans = (ans + dp[N, i, j, k]) % 1000000007;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


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

#define int long long

int n, m;
int g[105][105];
int ans;
set<vector<bool>> memo;

void dfs(vector<bool> used){
	if(not (memo.emplace(used)).second) return;
	//for(auto i : used){ cout << i << ' ' ; } cout << endl;

	vector<int> to;
	rep(i,n){
		if(used[i]) continue;
		bool f = true;
		rep(j,n){
			if(not used[j]) continue;
			if(i == j || g[j][i] == 0){
				f = false;
				break;
			}
		}
		if(f) to.emplace_back(i);
	}

	for(auto i : to){
		used[i] = true;
		dfs(used);
		used[i] = false;
	}

	int sum = 0;
	rep(i,n){
		if(not used[i]) continue;
		int mini = INF;
		rep(j,n){
			if(not used[j]) continue;
			if(g[i][j] == 0) continue;
			mini = min(mini, g[i][j]);
		}
		if(mini == INF) continue;
		sum += mini;
	}
	ans = max(ans, sum);
}

signed main(){
	cin >> n >> m;

	vector<int> v;
	rep(i,m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a][b] = g[b][a] = c;
	}

	rep(i,n){
		vector<bool> tmp(n,0);
		tmp[i] = true;
		dfs(tmp);
	}
	cout << ans << endl;

	//for(auto i : memo){ for(auto j : i){ cout << j << ' '; } cout << endl; }
}

Measured memory_bytes: 5004
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math
import itertools


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    LArray = LI()
    ans = 0
    if N < 3:
        print(ans)
        return

    for v in list(itertools.combinations(LArray, 3)):
        v = list(v)
        v.sort()

        if v[0] == v[1] or v[2] == v[1] or v[0] == v[2]:
            continue
        elif v[0]+v[1] <= v[2]:
            continue
        else:
            ans += 1
        
    print(ans)


if __name__ == '__main__':
    main()


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

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

	ll ans = 0;
	rep1(i, n+1)
		if (i % 3 != 0 && i % 5 != 0) ans += i;

	cout << ans << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int data[n];
	int i,j;
	for(i=0;i<n;i++){
		scanf("%d",&data[i]);
	}
	int swap=0,temp;
	for(i=0;i<n;i++){
		for(j=1;j<n;j++){
			if(data[j-1]>data[j]){
				temp=data[j];
				data[j]=data[j-1];
				data[j-1]=temp;
				swap++;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d",data[i]);
		if(i+1!=n){
			printf(" ");
		}
	}
	printf("\n");
	printf("%d\n",swap);
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;

ll N;
vector<ll> A;

void solve(){
    map<ll, ll> mp;
    for(ll a : A){
        mp[a]++;
    }

    ll res = 0;
    for(auto it = mp.begin(); it != mp.end(); it++){
        ll a = it->first, n = it->second;
        res += n * (n - 1) / 2;
    }

    for(ll a : A){
        ll n = mp[a];
        cout<<res - (n-1)*n/2 + (n-1-1)*(n-1)/2<<endl;
    }
}

int main(){
    //freopen("d.in", "r", stdin);
    cin>>N;
    A = vector<ll>(N, 0);
    for(ll i=0; i<N; i++){
        cin>>A[i];
    }

    solve();
    return 0;
}



Measured memory_bytes: 11008
def main():
    k = int(input())
    tbl = {}
    v = int(0)
    cnt = 0
    while True:
        cnt += 1
        v = 10 * v + 7
        v = v % k

        if v == 0:
            print(cnt)
            break
        elif v in tbl.keys():
            print('-1')
            break
        else:
            tbl[v] = 0


if __name__ == '__main__':
    main()


Measured memory_bytes: 92760
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

// -----------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------

let main() =
    let [| n; a; b |] = reada int64
    let ab = a + b
    let ans = (n / ab) * a
    let rem = n % ab
    let ans = ans + min a rem
    puts ans
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


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

using namespace std;

int main(void) {
	int n; cin >> n;
	vector < tuple<string, int, int>> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> get<0>(v[i]) >> get<1>(v[i]);
		get<1>(v[i]) *= -1;
		get<2>(v[i]) = i + 1;
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; ++i)cout << get<2>(v[i]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
int dp[3010][3010];
int fr[3010][3010];
void ct(int x,int y){
	switch(fr[x][y]){
		case 0:
			return;
		case 1:
			ct(x-1,y-1);
			cout<<s[x-1];
			break;
		case 2:
			ct(x,y-1);
			break;
		case 3:
			ct(x-1,y);
			break;
	}
}
int main()
{
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		for(int j=0;j<t.size();j++){
			if(s[i]==t[j])
				fr[i+1][j+1]=1,dp[i+1][j+1]=dp[i][j]+1;
			else{
				if(dp[i][j+1]<=dp[i+1][j])
					dp[i+1][j+1]=dp[i+1][j],fr[i+1][j+1]=2;
				else dp[i+1][j+1]=dp[i][j+1],fr[i+1][j+1]=3;
			}
		}
	ct(s.size(),t.size());
	return 0;
}

Measured memory_bytes: 71040
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 2019;

map<long long, long long> inv_fact;
long long inv_factorial(long long x){
    if (inv_fact.count(x)){
        return inv_fact[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv_fact[x]=ret;
    return ret;
}

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    string S;
    cin >> S;
    int N=S.size();
    vector<ll> vec((int)S.size()+1,0);

    ll tmp=1;
    for(int i=N; i>0; i--){
        vec[i-1]=(ll)((S[i-1]-'0')*tmp+vec[i])%2019;
        tmp*=10;
        tmp%=2019;
    }
    
    vector<ll> cnt(2019,0);
    for(auto x:vec){
        cnt[x]++;
    }

    ll ans=0;
    for(auto x:cnt){
        ans+=x*(x-1)/2;
    }
    //cout_vec(vec);

    cout << ans << endl;
}

Measured memory_bytes: 5240
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename T> class segtree {
private:
    int n,sz,h;
    vector<T> node, lazy;
    void eval(int k) {
        if(lazy[k]){
            node[k] += lazy[k];
            if(k < n) {
                lazy[k*2] += lazy[k] / 2, lazy[k*2+1] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

public:
    segtree(vector<T>& v) : sz((int)v.size()), h(0) {
        n = 1;
        while(n < sz) n *= 2, h++;
        node.resize(2*n, 0), lazy.resize(2*n, 0);
        for(int i = 0; i < sz; i++) node[i+n] = v[i];
        for(int i = n-1; i >= 1; i--) node[i] = node[2*i] + node[2*i+1];
    }
    void range(int a, int b, T x) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        int ta = a, tb = b++, length = 1;
        while(a < b){
            if(a & 1) lazy[a++] += length * x;
            if(b & 1) lazy[--b] += length * x;
            a >>= 1, b >>= 1, length <<= 1;
        }
        while(ta >>= 1, tb >>= 1, ta){
            if(!lazy[ta]){
                eval(2*ta), eval(2*ta+1), node[ta] = node[2*ta] + node[2*ta+1];
            }
            if(!lazy[tb]){
                eval(2*tb), eval(2*tb+1), node[tb] = node[2*tb] + node[2*tb+1];
            }
        }
    }
    T query(int a, int b) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        b++;
        T res1 = 0, res2 = 0;
        while(a < b) {
            if(a & 1) eval(a), res1 += node[a++];
            if(b & 1) eval(--b), res2 += node[b];
            a >>= 1, b >>= 1;
        }
        return res1 + res2;
    }
    void print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;}
};

int main(){
	int n,m;
	cin >> n >> m;
	vector< vector<pair<int,int> > >  v(m+1);
	rep(i,n){
		int a,b;
		cin >> a >> b;
		v[b-a].push_back(MP(a,b));
	}
	vector<int> r(m+1);
	segtree<int> sg(r);
	rep(d,m){
		if(d!=0){
			for(auto &x:v[d-1]){
				sg.range(x.first,x.second+1,1);
			}
			n-=v[d-1].size();
		}
		int sm = 0;
		int id = 0;
		while(id<=m){
			sm += sg.query(id,id+1);
			id += d+1;
		}
		cout << n+sm << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int a[2][100];
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < n;j++) {
			cin >> a[i][j];
		}
	}
	int sum_max = 0;
	for (int i = 0;i < n;i++) {
		int sum = 0;
		for (int j = 0;j < n;j++) {
			if (j < i) {
				sum += a[0][j];
			}
			else if (j == i) {
				sum += a[0][j] + a[1][j];
			}
			else {
				sum += a[1][j];
			}
		}
		sum_max = max(sum, sum_max);
	}
	cout << sum_max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    string w;
    cin>>w;
    
    int alpha[26]={};
    REP(i,w.size())alpha[w[i]-'a']++;
    
    REP(i,26){
        if(alpha[i]%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    cout<<"Yes"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
   ll n,i;
   cin>>n;
   ll arr[n];
   for(i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   ll dp[n];
   memset(dp,0,sizeof(dp));
   dp[1]=abs(arr[1]-arr[0]);
   for(i=2;i<n;i++)
   {
       dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
   }


//   for(i=0;i<n;i++)
//   {
//       cout<<dp[i]<<" ";
//   }
   cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String topping[] = line.split("");
        int price = 700;
        for(int i = 0; i<3; i++){
            if(topping[i].equals("o")){
                price += 100;
            }
        }
        System.out.println(price);
    }
}


Measured memory_bytes: 23764
#include<cstdio>
int main(){
	long long int ans=1,sum=1;
	int n,m;
	while(scanf("%d %d",&n,&m)==2){
		sum=1,ans=1;
		if(n-m>1||m-n>1){
			ans=0;
		}
		else{
			if(n==m){
				for(int i=n;i>0;i--){
					sum*=i;
					sum%=1000000007;
				}
				for(int j=m;j>0;j--){
					sum*=j;
					sum%=1000000007;
				}
				ans=sum*2;
				ans%=1000000007;
			}
			else{
				for(int i=n;i>0;i--){
					sum*=i;
					sum%=1000000007;
				}
				for(int j=m;j>0;j--){
					sum*=j;
					sum%=1000000007;
				}
				ans=sum;
				ans%=1000000007;
				}
			}
		printf("%lld\n",ans%1000000007);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(ll)(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
#define MOD 1000000007

vl facdp;
ll fac(ll x){
  if(x < sz(facdp)){
    return facdp[x];
  }
  facdp.pb((x*fac(x-1)) % MOD);
  return facdp[x];
}

ll modExp(ll a, ll x, ll m=MOD) {
  if (x == 0) return 1;
  ll res = modExp(a, x/2, m);
  res = (res * res) % m;
  return (x % 2) ? (res * a) % m : res;
}

vl moifa;
ll modInv(ll a, ll p=MOD) {
  return modExp(a, p-2, p);
}

ll pos_dir(ll dx, ll dy){
  ll res = (fac(dx+dy) * moifa[dx]) % MOD;
  res *= moifa[dy];
  res %= MOD;
  return res;
}

vector<pll> walls;
vl dp;

ll f(ll i){
  if(dp[i] != -1) return dp[i];
  pll& we = walls[i];
  ll base = pos_dir(we.xx,we.yy);
  FOR(j,0,i){
    pll& other = walls[j];
    if(other.yy > we.yy) continue;
    base -= (f(j) * pos_dir(we.xx-other.xx, we.yy - other.yy)) % MOD;
    base += MOD;
    base %= MOD;
  }
  dp[i] = base;
  return base;
}

int main(){
  facdp.pb(1);
  FOR(i,0,200000){
    facdp.pb((i+1) * facdp[i] % MOD);
    moifa.pb(modInv(fac(i)));
  }
  ll H,W;
  cin >> H >> W;
  ll N;
  cin >> N;
  FOR(i,0,N){
    ll a,b;
    cin >> a >> b;
    walls.pb(mp(a-1,b-1));
  }
  walls.pb(mp(H-1,W-1));
  sort(all(walls));
  dp.resize(N+1,-1);

  cout << f(N) << endl;

} //cin.tie(0) bei schnellem Wechseln


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= (j);i--)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 55555;
int A[maxn];

vector<int> prime;
vector<int> good;

void init(){
    _for(i,2,maxn){
        if(A[i]) continue;
        if(i <= maxn && (i % 5 == 1)) good.PB(i);
        for(int j = i*2; j < maxn; j+=i ){
            A[j] = 1;
        }
    }
}

int main()
{
    init();
    int N;cin >> N;
    _for(i,0,N){
        if(i) printf(" ");
        printf("%d",good[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vli vector<li>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pi pair<int,int>
#define FOR(i,s,n) for(auto i=s;i<n;++i)
#define FORN(i,s,n) for(auto i=s;i<=n;++i)
#define FORR(i,s,n) for(auto i=s;i>=n;--i)
#define FORE(i,a) for(auto i : a)
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ops = 0;
    FOR(i,0,s.size()) {
        if(s[i]=='R')
            ops++;
    }
    int idx = ops;
    FOR(i,0,idx) {
        if(s[i]=='R') {
            ops--;
        }
    }
    cout << ops << endl;
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int l=0,r=s.size()-1,ans=0;
    while(l<r){
        if(s[l]==s[r]){
            l++;
            r--;
            continue;
        }
        if(s[l]=='x'){
            l++;
            ans++;
            continue;
        }
        if(s[r]=='x'){
            r--;
            ans++;
            continue;
        }
        if(s[l]!=s[r]){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc081/tasks/arc086_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, K, A, m[200000] = {0}, r = 0, s = 0;
  vector<int> c;

  cin >> N >> K;

  REP(i, N)
  {
    cin >> A;
    m[A - 1]++;
  }
  REP(i, 200000)
  {
    if (m[i] != 0)
    {
      c.push_back(m[i]);
      s++;
    }
  }

  sort(ALL(c));

  REP(i, max(0, s - K))
  {
    r += c[i];
  }

  cout << r << '\n';

  return 0;
}


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

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb push_back
#define vll vector<ll> 
#define f(i,x,y)  for(i=x;i<y;i++)
#define INF     LLONG_MAX
#define fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define p2(n,x)    cout << fixed << setprecision(x) <<n<<endl; 
#define pll    pair<ll,ll> 
#define ff first
#define ss second
#define blt(x)   __builtin_popcount(x)
ll fun(string a,string b)
{
    ll i;
    ll ans=0;
    f(i,0,(int)a.size())
    {
        if(a[i]!=b[i])
            ans++;
    }
    return ans;
}
void solve()
{
    string a,b;
    cin>>a>>b;
    ll i,j;
    ll ans=INF;
    for(i=0;i<(int)a.size()-b.size()+1;i++)
    {
        string s=a.substr(i,(int)b.size());
        ans=min(ans,fun(s,b));
        //cout<<s<<endl;
    }
    cout<<ans;

}

int main()
{
    
    fast
    ll t = 1;

    

    while(t--)
    solve();
    
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int b=0;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=1;i+1<n;i++)
	{
		int maxv=max(a[i],max(a[i-1],a[i+1]));
		int minv=min(a[i],min(a[i-1],a[i+1]));
		if(a[i]!=maxv&&a[i]!=minv)
			b++;
	}	
	cout<<b;
	return 0;
}

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

using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	if (a!=2 && b!=2) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
// kyopro.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int main(){
	string S;
	cin >> S;
	int flag = 1;
	if (S[2] != S[3])
		flag = 0;
	if (S[5] != S[4])
		flag = 0;
	Yn(flag);
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] p = new int[n+1];
		StringTokenizer st;
		for (int i = 0; i < n-1; i++) {
			st = new StringTokenizer(reader.readLine());
			int p1 = Integer.parseInt(st.nextToken());
			p[i] = p1;
		}
		st = new StringTokenizer(reader.readLine());
		p[n-1] = Integer.parseInt(st.nextToken());
		p[n] = Integer.parseInt(st.nextToken());
		reader.close();
		System.out.println(mcm(p,n));
	}
	private int mcm(int[] p, int n) {
		int[][] m = new int[n+1][n+1];
		for (int s = 0; s < n; s++) {
			for (int i=1,j=s+2;j<=n;i++,j++) {
				m[i][j] = 1 << 30;
				for (int k = i; k < j; k++) {
					m[i][j]=Math.min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
				}
			}
		}
		return m[1][n];
	}
}



Measured memory_bytes: 24720
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int result[3010][3010] = {};

int main() {
	string s, t;
	cin >> s >> t;

	for (int i = 1; i <= s.length(); i++) {
		for (int j = 1; j <= t.length(); j++) {
			result[i][j] = max(result[i - 1][j], result[i][j - 1]);
			if (s[i - 1] == t[j - 1])
				result[i][j] = max(result[i][j], result[i - 1][j - 1] + 1);
		}
	}

	vector<char> ans;
	int i = s.length();
	int j = t.length();
	while (i > 0 && j > 0) {
		if (s[i - 1] == t[j - 1] && result[i - 1][j - 1] + 1 == result[i][j]) {
			ans.push_back(s[i - 1]);
			i--;
			j--;
		} else if (result[i - 1][j] == result[i][j]) {
			i--;
		} else {
			j--;
		}
	}
	// cout << i << " " << j << endl;
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 35584
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (ll)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll n,k,t,zeroCnt; 
vector<ll> pos,neg;
ll numLessPos(vector<ll> &a,ll val){
	ll ans=0,i=0,j=sz(a)-1;
	while(i<j){
		while(i<j&&a[i]*a[j]>val)j--;
		ans+=j-i;
		i++;
	}
	return ans;
}
ll numLessNeg(ll val){
	int j=sz(neg)-1;
	ll ans=sz(neg)*sz(pos);
	for(auto x:pos){
		while(j>=0&&neg[j]*x>=val)j--;
		ans-=(j+1);
	}
	return ans;
}
ll numLess(ll val){
	if(val>0){
		return numLessPos(pos,val)+numLessPos(neg,val)+sz(pos)*sz(neg)+(sz(pos)+sz(neg))*zeroCnt+(zeroCnt-1)*zeroCnt/2;
	}else if(val==0)return sz(pos)*sz(neg)+(n-zeroCnt)*zeroCnt+(zeroCnt-1)*zeroCnt/2;
	else return numLessNeg(-val);
}
void solve(){
	cin>>n>>k;
	rep(i,0,n){
		cin>>t;
		if(t>0){
			pos.pb(t); 
		}else if(t<0){
			neg.pb(-t);
		}else{
			zeroCnt++;
		}
	}
	sort(all(pos));
	sort(all(neg));
	ll low=-1e18,high = 1e18,ans = high;
	while(low<=high){
		ll mid = (low+high)/2;
		if(numLess(mid)>=k){
			ans = mid;
			high = mid-1;
		}else{
			low = mid+1;
		}
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 2420
A,B,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

mmA = min(A)
mmB = min(B)

ans = mmA+mmB

for i in range(M):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    mm = A[x]+B[y]-c
    ans = min(ans,mm)

print(ans)

Measured memory_bytes: 18608
/*
....................
....................
*/
#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;


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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll A[n],i,j,k;
    for(i=0;i<n;i++)
    {
    	cin>>A[i];
    }
    ll dp[n]={0};
    dp[0]=0;
    dp[1]=abs(A[1]-A[0]);
    for(i=2;i<n;i++)
    {
    	dp[i]=min(dp[i-2]+abs(A[i]-A[i-2]),dp[i-1]+abs(A[i]-A[i-1]));
    }
    cout<<dp[n-1]<<endl;
	
	return 0;
}

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

int main()
{
    string s[200050];
    int n;
    cin>>n;
    map<string,int>mp;
    set<string>q;
    int most=0;
    for(int i=0;i<n;i++){
            cin>>s[i];
            mp[s[i]]++;
            most=max(mp[s[i]],most);//首先找出最大次数
    }
    for(int i=0;i<n;i++){
        if(most==mp[s[i]])
            q.insert(s[i]);//set集合元素唯一且有序
    }
    for(set<string>::iterator i=q.begin();i!=q.end();i++)
        cout<<*i<<endl;
        
    return 0;
}


Measured memory_bytes: 36096
void main()
{
    long n = readln.chomp.to!long;
    long[] x = readln.split.to!(long[]);

    long[] y = x.dup;
    y.sort!"a < b";
    long l = y[n/2-1], r = y[n/2];

    foreach (a; x)
    {
        if (a <= l) r.writeln;
        else l.writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
    int n, q; string s;
    cin >> n >> q >> s;

    int iac[n+1];
    iac[0] = 0;
    rep(i, n) {
        iac[i+1] = iac[i];
        if (s[i] == 'A' && s[i+1] == 'C') iac[i+1] += 1;
    }

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << iac[r] - iac[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
int main()
{
    int R;
    while(cin >> R)
    {
    	if(R<1200)
    	printf("ABC\n");
    	else if(R<2800)
    	printf("ARC\n");
    	else
    	printf("AGC\n");
	}
	return 0;
}


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

#define ll long long

using namespace std;



int main(){
    vector<int> a(3);
    for(int i = 0; i < 3; i++){
        cin >> a[i];
    }
    if(a[0]+a[1]+a[2] > 21) cout << "bust" << endl;
    else cout << "win" << endl;
}

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

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


void init()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 1e6+6;
const int MOD = 1e9+7;

ll f[N];

void calcfact(){
	f[0] = f[1] = 1;
	lpi(i, 2, N-2){
		f[i] = (f[i-1] * i) % MOD;
	}
}
long long power(long long a , long long b){
    long long x = 1 , y = a;
    while(b > 0){
        if(b & 1){
            x = (x * y);
            if(x > MOD)
                x %= MOD;
        }

        y = y*y;
        if(y > MOD)
            y %= MOD;

        b >>= 1;
    }
    return x;
}
long long nCr(long long n , long long r){
    return (f[n] * power(f[r] * f[n-r] %MOD , MOD - 2))% MOD;
}

int main()
{
	init();
	calcfact();
	int x, y;
	cin >> x >> y;
	int xtwos = -1, xones = -1;
	lp(i, x + 1){
		if((x-i) % 2 == 1)
			continue;
		if(i*2 + (x-i)/2 == y){
			xtwos = (x-i)/2;
			xones = i;
			break;
		}
	}
	if(xones == -1){
		cout << 0;
		return 0;
	}

	cout << nCr(xtwos+xones, xones);
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N,P;
    string S;
    cin >> N >> P;
    cin >> S;
    vector<int> T;
    REP(i,N){
        T.push_back(S[i]-'0');
    }
    if(P==2 || P==5){
        int ans=0;
        REP(i,N){
            if(T[i]%P==0){
                ans+=(i+1);
            }
        }
        cout << ans << endl;
        return 0;
    }
    int k=1;
    RREP(i,N){
        T[i]=(T[i]*k)%P;
        k=(k*10)%P;
    }
    vector<int> U=T;
    
    U[N-1]%=P;
    RREP(i,N-1){
        U[i]=(U[i]+U[i+1])%P;
    }

    int F[114514]={};
    int Ans=0;
    //REP(i,N){cout << U[i] << " ";}cout << endl;
    REP(i,N){
        F[U[i]]++;
    }
    F[0]++;
    REP(i,P){
        Ans+=(F[i]*(F[i]-1))/2;
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 4596
def h(A, n):
    if A == -1:
        return 0
    return A // (2 * n) * n + max(A % (2 * n) - (n - 1), 0)


def g(A):
    result = 0
    for i in range(48):
        t = 1 << i
        if h(A, t) % 2 == 1:
            result += t
    return result


def f(A, B):
    return g(A - 1) ^ g(B)


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

print(f(A, B))


Measured memory_bytes: 3060
'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(x=> x*1);
  // 高橋モンスターの倒れるまでの回数
  let AdevD = Math.ceil(inp[0]/inp[3]);
  // 青木モンスターの倒れるまでの回数
  let CdevB = Math.ceil(inp[2]/inp[1]);
  if(AdevD >= CdevB){
  	console.log("Yes")
  } else {
    console.log("No")
  }

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29628
//package abc176;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		
		int ans = 0;
		
		for(char c : str.toCharArray()) {
			ans = ( ans + c-'0')%9; 
		}
		
		if(ans == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	
}


Measured memory_bytes: 36592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	int N; cin >> N;
	vector<vector<char>> s(N,vector<char>(N));
	rep(i,N)rep(j,N) cin >> s[i][j];
	int ans = 0;
	rep(i,N){
		bool ok = true;
		rep(j,N)rep(k,N){
			if(s[j][(k+i)%N] != s[k][(j+i)%N]) ok = false;
		}
		if(ok) ans++;
	}
	ans *= N;
	cout << ans << endl;
}



Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;

int main(void){
  int n,x,i;
  int ki,gu;
  cin>>n;
  ki=gu=0;
  for(i=0;i<n;i++){
    cin>>x;
    if(x%2==1) ki++;
    else gu++;
    if(ki==2) {
      ki=0;
      gu++;
    }
    if(gu==2) gu--;
  }
  if(ki+gu==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(void){
    int H,W;
    
    while(1){
        scanf("%d %d",&H,&W);
        
        for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
                if((i % 2 == 0 && j % 2 == 0)||(i % 2 == 1 && j % 2 == 1))
                    printf("#");
                else
                    printf(".");
            }
            printf("\n");
        }
        if(H == 0 && W == 0)
            break;
        printf("\n");
    }
    
    return 0;
}



Measured memory_bytes: 3140
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	char c;
	scan(c);
	char ans=c+1;
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define mk make_pair
#define pi pair <int,int>
#define pl pair <ll,ll>
#define rep(i,a,n) for(int i=a;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define rep_(i,a,n) for(int i=(n-1);i>=a;i--)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int curr=0;
    vi v;
    v.pb(1);
    rep(i,1,s.size())
    {
    	if(s[i-1]!=s[i])
    	{
    		v.pb(1);
		}
		else
		{
			v[v.size()-1]++;
		}
	}
	int b[s.size()+1]={0};
	for(int i=0;i<v.size();i+=2)
	{
		int ind=curr+v[i];
		b[ind+1]+=v[i]/2;
		b[ind+1]+=(v[i+1]-v[i+1]/2);
		b[ind]+=(v[i+1]/2);
		b[ind]+=(v[i]-v[i]/2);
		curr+=(v[i]+v[i+1]);
	}
	rep(i,1,s.size()+1)
		cout<<b[i]<<" ";
	cout<<endl;
}

Measured memory_bytes: 1480
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int n=0,sum=0;
	char c;
	while((c=getchar())!=EOF)
	{
		if(c>='0'&&c<='9')
		{
			n*=10;
			n+=(c-('0'));
		}
		else
		{
			sum+=n;
			n=0;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
vector<int> v;
long long sum = 1000000;
int n;
long long cal(int k) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += pow(k - v[i], 2);
  }
  return sum;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a = 0;
    cin >> a;
    v.push_back(a);
  }
  int max_v = *max_element(v.begin(), v.end());
  int min_v = *min_element(v.begin(), v.end());
  for (int i = min_v; i <= max_v; ++i) {
    sum = min(sum, cal(i));
  }
  cout << sum << endl;
  return 0;
}


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

void dfs(int start, int n, int& time, std::vector<std::vector<int> >& G, std::vector<int>& D, std::vector<int>& F)
{
	D.at(start) = ++time;
	if (G.at(start).size() == 0)
	{
		F.at(start) = ++time;
		return;
	}
	for (int i = 0; i < G.at(start).size(); i++)
	{
		if (D.at(G.at(start).at(i)) == 0)
			dfs(G.at(start).at(i), n, time, G, D, F);
	}
	F.at(start) = ++time;
}


int main()
{	
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > G;
	for (int i = 0; i < n; i++)
	{
		int nl;
		int m;
		std::vector<int> V;
		std::cin >> nl >>  m;
		for (int j = 0; j < m; j++)
		{
			int v;
			std::cin >> v;
			v--;
			V.push_back(v);
		}
		G.push_back(V);
	}
	std::vector<int> D(n, 0);
	std::vector<int> F(n, 0);
	int time = 0;
	for (int i = 0; i < n; i++)
	{
		if (D.at(i) == 0)
			dfs(i, n, time, G, D, F);	
	}
	
	for (int i = 0; i < n; i++)
	{
		std::cout << i + 1 << ' ' << D.at(i) << ' ' << F.at(i) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef pair<char ,char> P;
const ll MAX_N=1500,MOD=998244353;
ll N;
ll ans;
char A[MAX_N-1][MAX_N-1];
ll G[MAX_N+1][MAX_N+1];
ll V;
bool flg[MAX_N+1];
void dans(){
	ans*=2;
	ans%=MOD;
}
ll ondeg,ver,qedge;
void dfs(ll v){
	flg[v]=true;
	ver++;
	REP(i,V){
		if(i==v)continue;
		if(G[v][i]==1){
			ondeg++;
		}
		if(G[v][i]==0){
			qedge++;
			if(!flg[i]){
				dfs(i);
			}
		}
	}
}
		
int main(){
	cin>>N;
	REP(i,N-1)cin>>A[i];
	ans=1;
	REP(i,N-1){
		REP(j,i){
			char c1=A[j][i],c2=A[i][j];
			if(c1>c2){
				swap(c1,c2);
			}
			P p(c1,c2);
			if(p==P('?','o')||p==P('?','x')){
				A[j][i]=A[i][j]=c2;
			}else if(p==P('o','x')){
				ans=0;
			}
			
		}
	}
	REP(i,N-1){
		REP(j,i){
			char c1=A[N-j-2][i],c2=A[N-i-2][j];
			if(c1>c2){
				swap(c1,c2);
			}
			P p(c1,c2);
			if(p==P('?','o')||p==P('?','x')){
				A[N-j-2][i]=A[N-i-2][j]=c2;
			}else if(p==P('o','x')){
				ans=0;
			}
		
		}
	}
	/*
	REP(v,N-1){
		REP(w,N-1){
			printf("%c ",A[v][w]);
		}
		printf("\n");
	}
	*/
	REP(t,2){
		ll n;
		ll cc,cr;
		if(N%2==0){
			if(t==0){
				n=N/2;
				cc=cr=N/2-1;
			}else{
				n=N/2-1;
				cc=N/2-1;
				cr=N/2;
			}
		}else{
			n=N/2;
			if(t==0){
				cc=N/2-1;
				cr=N/2;
			}else{
				cc=N/2;
				cr=N/2;
			}
		}
		V=n+1;
		REP(a,n){
			REP(b,n-a){
				char c=A[cr+a+b][cc-a+b];
				ll v,w;
				if(b==0){
					v=n;	//root
					w=a;
				}else{
					v=a;
					w=n-b;
				}
				ll val;
				if(c=='?'){
					val=0;
				}else if(c=='o'){
					val=1;
				}else{
					val=-1;
				}
				G[v][w]=G[w][v]=val;
			}
		}
		if(V%2==0){
			REP(v,V){
				FOR(u,v+1,V){
					if(G[v][u]==0){
						dans();
					}
				}
			}
		}else{
			memset(flg,false,sizeof(flg));
			REP(v,V){
				if(!flg[v]){
					ondeg=0;
					ver=0;
					qedge=0;
					dfs(v);
					if(ondeg%2==1){
		//				cout<<"ondeg"<<endl;
						ans=0;
					}
					qedge/=2;
					REP(i,qedge-ver+1){
						dans();
					}
				}
			}
		}
		/*
		REP(v,V){
			REP(w,V){
				printf("%2lld ",G[v][w]);
			}
			printf("\n");
		}
		*/
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 13216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=310,mod=1e9+7;
int n,a[N<<1],t[N<<1],c[N<<1],cnt,CNT;
void pls(int &x,int y){x+=y;x>=mod?x-=mod:0;}
int dp[N<<1][N][N];
int main()
{
//	freopen("f7.in","r",stdin);
//	freopen("f7.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=2*n;i++)scanf("%d",&a[i]);
	
	for (int i=1;i<=2*n;i+=2) 
	if (a[i]!=-1&&a[i+1]!=-1) t[a[i]]=t[a[i+1]]=2;
	else if (a[i]!=-1) t[a[i]]=1;
	else if (a[i+1]!=-1)t[a[i+1]]=1;
	else CNT++;
	for (int i=1;i<=2*n;i++) 
	if (t[i]==1) c[++cnt]=1;else if (!t[i]) c[++cnt]=0;
	dp[cnt][0][0]=1;
	for (int i=cnt;i;i--) 
		for (int j=0;j<=cnt&&j<=n;j++)
			for (int k=0;k<=cnt&&k<=n;k++) 
			if (c[i]==1)
			{
				pls(dp[i-1][j+1][k],dp[i][j][k]);
				if (k)pls(dp[i-1][j][k-1],dp[i][j][k]);
			} else
			{
				pls(dp[i-1][j][k+1],dp[i][j][k]);
				if (k)pls(dp[i-1][j][k-1],dp[i][j][k]);
				if (j)pls(dp[i-1][j-1][k],(ll)dp[i][j][k]*j%mod);
			}
	ll ans=dp[0][0][0];
	for (int i=1;i<=CNT;i++) ans=ans*i%mod;
	cout<<ans;
}

Measured memory_bytes: 225536
#include <iostream>
#include <string>

using namespace std;

int main(){
	int N, K;
	cin >> N >> K;
	long long int A[200000] = {0};

	for (int i = 1; i <= N; i++) {
		cin >> A[i]; 			
	}

	for (int i = K+1; i <= N; i++) {
		if (A[i] - A[i - K] > 0) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
	return 0;
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
    N: i32,
    Y: i32
    }

    for i in (0..N+1) {
        for j in (0..N+1-i) {
            if 10000 * i + 5000 * j + 1000 * (N-i-j)  == Y {
                println!("{} {} {}", i, j, N-i-j);
                return;
            }
        }
    }
    println!("{} {} {}", -1, -1, -1)
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = a*ll(n/(a+b)) + min(a, n%(a+b));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

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

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    ll a, b, c, d, p, q, r, s;
    cin >> a >> b >> c >> d;

    p = a * c;
    q = a * d;
    r = b * c;
    s = b * d;

    cout << max(p, max(q, max(r, s))) << endl;

}

Measured memory_bytes: 3628