akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N;  cin>>N;
    int A[N];  for(int i=0; i<N; i++)cin>>A[i];
    int B[N];  for(int i=0; i<N; i++)cin>>B[i];
    int C[N];  for(int i=0; i<N; i++)cin>>C[i];
    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);

    long long ans=0;
    for(int i=0; i<N; i++){
        ans += ( lower_bound(A,A+N, B[i]) - A ) * ( C+N - upper_bound(C,C+N, B[i]) );
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> button(n);
  int idx = 0;
  int ans = 1;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    button.at(i) = a;
  }
  
  while (button.at(idx) != 2) {
    idx = button.at(idx) - 1;
    ans++;
    if (ans > n) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>


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

using namespace std;
using ll = long long;

#define M (1'000'000'007)

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    if (n >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3028
N,M = map(int,input().split())
imos = [0]*(N+1)
for i in range(M):
    l,r = map(int,input().split())
    imos[l-1] += 1
    imos[r] -= 1
from itertools import accumulate
imos = list(accumulate(imos))
res = 0
for a in imos:
    if a == M:
        res += 1
print(res)

Measured memory_bytes: 8092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                            \
    chrono::system_clock::time_point start, end; \
    start = chrono::system_clock::now();
#define timer_wrap()                                                       \
    end = chrono::system_clock::now();                                     \
    double time = static_cast<double>(                                     \
        chrono::duration_cast<chrono::microseconds>(end - start).count() / \
        1000.0);                                                           \
    printf("%lf[ms]\n", time);                                             \
    start = end;
#define optimize_cin() \
    cin.tie(0);        \
    ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000    // 10^9
#define INFINF LLONG_MAX  // 2^63-1
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
// ########## template end ##########

#ifdef DEBUG_ON
void test_all();
#endif

void resolve() {
    ll N;
    cin >> N;
    if (N % 2 == 1) {
        cout << 0 << endl;
        return;
    }
    ll ans = N / 10;
    for (ll i = 50; i <= N; i *= 5) {
        ans += N / i;
    }
    cout << ans << endl;
}

int main() {
#ifdef DEBUG_ON
    test_all();
#else
    resolve();
#endif
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		//List<Integer> DQ=new ArrayList<>();
		MyDQ DQ=new MyDQ();
		int q=in.nextInt();
		
		for(int i=0;i<q;i++) {
			int query=Integer.parseInt(in.next());
			
			switch(query) {
			case 0:
				int d=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
				DQ.push(d, x);
				break;
				
			case 1:
				int p=Integer.parseInt(in.next());
				out.println(DQ.get(p));
				break;
				
			case 2:
				int e=Integer.parseInt(in.next());
				DQ.pop(e);
				break;
			}
		}
		out.flush();
	}

}

class MyDQ{
	int DQ[];
	int size,top,btm;
	
	MyDQ(){
		DQ=new int[1000000];
		size=0;
		top=500000; btm=499999;
	}
	
	void push(int d,int x) {
		if(d==0) {
			top--;
			DQ[top]=x;
		}
		else {
			btm++;
			DQ[btm]=x;
		}
		size++;
	}
	
	void pop(int d) {
		if(d==0) top++;
		else btm--;
		size--;
	}
	
	int get(int i) {
		return DQ[top+i];
	}
}



Measured memory_bytes: 182196
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int n=in();
	if(n==0||n==2)
		puts("1");
	else if(n==1)
		puts("2");
	else
		puts("0");
	return 0;
}

Measured memory_bytes: 1776
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

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

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) {
        if (flg[i] == '0') continue;
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    }
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] == '1') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*----------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll a, b;
    std::cin >> a >> b;

    auto func = [](ll n) -> ll {
        ll res = 0;
        for (ll i = 2; i * i <= n; i++) {
            if (n % i != 0) continue;
            res++;
            while (n % i == 0) n /= i;
        }

        return res += n > 1;
    };

    std::cout << func(gcd(a, b)) + 1 << '\n';
}


Measured memory_bytes: 3604
#include<iostream>
#include<string.h>

using namespace std;

int main()
{
    char s[4];
    int count = 0;
    cin.getline(s, 4);

    for(int i=0; s[i]!='\0'; ++i)
    {
        if(s[i] == 'R')
        {
            count++;
        }

        else if(s[0] == 'S' && s[1] == 'R' && s[2] == 'R')
        {
            count = 0;
        }
        else if(s[0] == 'S' && s[1] == 'R' && s[2] == 'S')
        {
            count = 1;
        }
        else if(s[0] == 'S' && s[1] == 'S' && s[2] == 'R')
        {
            count = 0;
        }
        else
        {
            count = count;
            break;
        }
    }

    cout << count << endl;




}


Measured memory_bytes: 3528
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, w;
vector<ll> ww[4];
int main() {
	cin>>n>>w;
	ll w1;
	for (int i = 1; i <= n; ++i) {
		ll tw, v;
		cin>>tw>>v;
		if (i == 1) w1 = tw;
		ww[tw-w1].push_back(v);
	}
	for (int i = 0; i < 4; ++i) {
	//	cout<<"i="<<i<<endl;
		sort(ww[i].begin(), ww[i].end());
		reverse(ww[i].begin(), ww[i].end());
		for (int j = 1; j < ww[i].size(); ++j) {
			ww[i][j] += ww[i][j-1];
		}
	//	cout<<"i1="<<i<<endl;
	}
	ll ans = 0;
	for (int a = 0; a <= ww[0].size(); ++a) {
		for (int b = 0; b <= ww[1].size(); ++b) {
			for (int c = 0; c <= ww[2].size(); ++c) {
				ll totw = (ll)a * (w1+0) + (ll)b*(w1+1) + (ll)c*(w1+2);
				//cout<<a<<" "<<b<<" "<<c<<endl;
				if (totw <= w) {
				//	cout<<"???"<<endl;
					int d = (w - totw) / (w1+3);
					ll totv = (a == 0 ? 0 : ww[0][a-1]) + (b == 0 ? 0 : ww[1][b-1])
					+ (c == 0 ? 0 : ww[2][c-1]);
					if (d > 0) {
						if (d <= ww[3].size()) totv += ww[3][d-1];
						else {
							if (!ww[3].empty()) {
								totv += ww[3].back();
							}
						}
					}
					//if (totv == 12) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
					ans = max(ans, totv);
				}
			//	cout<<"!!!"<<endl;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	ll int n,m,T,res;

	ll int maxi=-mx,mini=mx,count=0;

	ll int i,j,k;

	bool flag,pole1,pole2;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n>>m;

    (abs(n-m)>1)?cout<<"Alice"<<endl:cout<<"Brown"<<endl;


}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#define INF 500
using namespace std;
int N,M;
int X1[101],Y1[101];
int X2[101],Z2[101];

double width(int* X,int* Y,int n,double x){
	double lb=INF,ub=-INF;
	for(int i=0;i<n;i++){
		double x1=X[i],y1=Y[i],x2=X[(i+1)%n],y2=Y[(i+1)%n];
		if((x1-x)*(x2-x)<=0 && x1!=x2){
			double y=y1+(y2-y1)*(x-x1)/(x2-x1);
			lb=min(lb,y);
			ub=max(ub,y);
		}
	}
	return max(0.0,ub-lb);
}

void solve(){
	int min1=*min_element(X1,X1+M),max1=*max_element(X1,X1+M);
	int min2=*min_element(X2,X2+N),max2=*max_element(X2,X2+N);
	vector<int> xs;
	for(int i=0;i<M;i++){
		xs.push_back(X1[i]);
	}
	for(int i=0;i<N;i++){
		xs.push_back(X2[i]);
	}
	sort(xs.begin(),xs.end());
	double res=0;
	for(int i=0;i+1<xs.size();i++){
		double a=xs[i],b=xs[i+1],c=(a+b)/2;
		if(min1<=c && c<=max1 && min2<=c && c<=max2){
			double fa=width(X1,Y1,M,a)*width(X2,Z2,N,a);
			double fb=width(X1,Y1,M,b)*width(X2,Z2,N,b);
			double fc=width(X1,Y1,M,c)*width(X2,Z2,N,c);
			res+=(b-a)/6*(fa+4*fc+fb);
		}
	}
	printf("%.10f\n",res);
}

int main(void){
	while(1){
		scanf("%d %d",&M,&N);
		if(M+N==0)break;
		for(int i=0;i<M;i++){
			scanf("%d %d",&X1[i],&Y1[i]);
		}
		for(int i=0;i<N;i++){
			scanf("%d %d",&X2[i],&Z2[i]);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1092
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

int MOD;

template<typename T>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T>
ostream& operator<<(ostream &os,Mint<T> m){os<<m.v;return os;}

//INSERT ABOVE HERE

const int MAX = 5050;

using M = Mint<int>;
M dp[MAX]={};

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

  dp[n]=M(1);
  for(int k=0;k<=(n-1)/2;k++)
    for(int j=n;j>=k+1;j--)
      dp[j-(k+1)]+=dp[j];

  for(int k=1;k<=n/2-1;k++)
    for(int j=n;j>=k+1;j--)
      dp[j-(k+1)]+=dp[j];

  M ans{0};
  for(int k=1;k<=n;k++) ans+=dp[k]*M(k);

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <functional>

std::vector<intmax_t> ancestors(intmax_t v, intmax_t n,
				const std::vector<intmax_t> &min_sibls) {
  std::vector<intmax_t> res;
  while (v > 1) {
    res.push_back(v);
    auto w=std::upper_bound(min_sibls.begin(), min_sibls.end(), v)-1;
    v = w[-1] + (v-*w)/n;
  }
  res.push_back(1);
  return res;
}

int lca(int v, int w, intmax_t n, const std::vector<intmax_t> &min_sibls) {
  std::vector<intmax_t> pv=ancestors(v, n, min_sibls);
  std::vector<intmax_t> pw=ancestors(w, n, min_sibls);
  size_t i=0, j=0;
  while (pv[i] != pw[j]) {
    if (pv[i] < pw[j]) {
      ++j;
    } else {
      ++i;
    }
  }
  return pv[i];
}

int main() {
  intmax_t N, Q;
  scanf("%jd %jd", &N, &Q);

  if (N == 1) {
    for (int i=0; i<Q; ++i) {
      int v;
      scanf("%d %*d", &v);
      printf("%d\n", v);
    }
    return 0;
  }

  std::vector<intmax_t> min_sibls{1};
  for (intmax_t i=2, m=1; i<=2e12; i+=m) {
    min_sibls.push_back(i);
    m *= N;
  }

  for (int i=0; i<Q; ++i) {
    int v, w;
    scanf("%d %d", &v, &w);
    printf("%d\n", lca(v, w, N, min_sibls));
  }
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

template<class T>
void chmax(T& a,T b){
	a=max(a,b);
}

template<class T>
void chmin(T& a,T b){
	a=min(a,b);
}

template<class T>
void ResetVector(vector<T>& v,int n,const T& t){
	v.clear();
	v.resize(n,t);
}

int main(){
	string s;
	cin>>s;
	string t=s.substr(0,4),u=s.substr(4,8);
	cout<<t<<" "<<u<<endl;
}


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

int main() {
	// your code goes here
	int n, ac=0, wa=0, tle=0, ra=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string str;
		cin>>str;
		if(str=="AC"){ac++;}
		if(str=="WA"){wa++;}
		if(str=="TLE"){tle++;}
		if(str=="RE"){ra++;}
		
	}
	cout<<"AC"<<" x "<<ac<<endl<<"WA"<<" x "<<wa<<endl<<"TLE"<<" x "<<tle<<endl<<"RE"<<" x "<<ra<<endl;
};

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N, a[220000];
int x[220000];
vint ans;
signed main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    for(int i=N;i>0;i--){
        int cur=0;
        for(int j=i*2;j<=N;j+=i)cur^=x[j];
        x[i]=cur^a[i];
        if(x[i])ans.push_back(i);
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second

ll N,C;
ll D[35][35];
ll c[505][505];
ll X1[35],X2[35],X3[35];
ll ans=mod;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>C;

rep(i,C){
	rep(j,C){
		cin>>D[i][j];
	}
}

rep(i,N){
	rep(j,N){
		cin>>c[i][j];
		c[i][j]--;
	}
}

rep(k,C){
rep(i,N){
	rep(j,N){
		if((i+j)%3==0){
			X1[k]+=D[c[i][j]][k];
		}
		else if((i+j)%3==1){
			X2[k]+=D[c[i][j]][k];
		}
		else if((i+j)%3==2){
			X3[k]+=D[c[i][j]][k];
		}

	}
}
}

rep(i,C){
	rep(j,C){
		rep(k,C){
			if(i!=j&&j!=k&&i!=k){
				ans=min(ans,X1[i]+X2[j]+X3[k]);
			}
		}
	}
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef double r32;

int n, d, x;

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

	r32 l = (d + d + (n * 2.0 - 1.0) * x) * n;
	r32 v = 0;
	for (int i = 1; i <= n; ++i)
		v = (1.0 - 1.0 / i / i) * v + 0.5 / i;

	printf("%.16f\n", v * l);

	return 0;
}

Measured memory_bytes: 256
// atcoder/abc165/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  lli a, b, n;
  while (cin >> a >> b >> n) {
    auto fn = [&] (lli x) {
      return ((a * x) / b) - a * (x / b);
    };
    // for (int i = 1; i <= n; ++i) {
    //   cout << i << ' ' << fn(i) << endl;
    // }
    cout << fn(min(b - 1, n)) << endl;
  }

  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  cin >> n;

  int cnt = 0;
  for(int i = 1; i < n+1; i += 2) {
    int c = 0;
    fo(j, 1, n+1) {
      if(i % j == 0) c++;
    }
    if(c == 8) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll x[100010], y[100010], c[100010];
ll a[100010], b[100010];
ll an[100010], bn[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,M;
    cin >> A >> B >> M;
    rep(i,0,A) cin >> a[i];
    rep(i,0,B) cin >> b[i];
    rep(i,0,A) an[i] = a[i];
    rep(i,0,B) bn[i] = b[i];


    rep(i,0,M){
        cin >> x[i] >> y[i] >> c[i];
        x[i]--; y[i]--;
    }
    sort(an, an+A);
    sort(bn, bn+B);
    ll ans = an[0] + bn[0];
    rep(i,0,M){
        ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
    }
    print(ans);

    

}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>

using namespace std;

int n, ans = INT_MAX;
vector<int> a;

int get(int x)
{
    int cur = 0;

    for (int i = 0; i < n; i++)
        cur += (a[i] - x) * (a[i] - x);

    return cur;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    a.resize(n);

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

    for (int x = 1; x <= 100; x++)
        ans = min(ans, get(x));

    cout << ans << "\n";

    return 0;
}


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

using namespace std;

template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}

int main() 
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    
    long long int i,j,ans=0,c,n,a[200005],q,h,s,d,temp,mn;
    
    cin>>q>>h>>s>>d>>n;
    
    q=4*q;
    h=2*h;

    mn=min(q,h);
    mn=min(mn,s);
    
    if((2*mn)<=d)
    {
        ans=mn*n;
    }
    else
    {
        temp=n/2;
        ans=d*temp;
        if(n%2==1)
        {
            ans+=mn;
        }
    }
    
    //ans=100000000000000000;
    
    cout<<ans<<endl;
    
    
	return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
queue = [input() for i in range(n)]
cnt = 0
while len(queue) != 0:
    name, time = queue.pop(0).split()
    if int(time) <= q:
        cnt+=int(time)
        print(name,str(cnt))
    else:
        cnt+=q
        time = str(int(time) - q)
        queue.append(name+" "+time)


Measured memory_bytes: 9544
#include <stdio.h>
 
int main(){
	int n, p[20], i, c=0;
 
	scanf("%d", &n);
 
	for(i=0; i<n; i++)
		scanf("%d", &p[i]);
 
	for(i=2; i<n; i++){
		if((p[i-2] < p[i-1] && p[i-1] < p[i]) || (p[i] < p[i-1] && p[i-1] < p[i-2]))
			c++;
	}
 
	printf("%d\n",c);
 
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int sheet = scan.nextInt();
		int c = 0;

		int[][] card = new int[4][13];

		for(int i=1; i<=sheet; i++){
			String mark = scan.next();
			int nums = scan.nextInt();

			if(mark.equals("S")){
				card[0][nums-1] = i;
			}else if(mark.equals("H")){
				card[1][nums-1] = i;
			}else if(mark.equals("C")){
				card[2][nums-1] = i;
			}else if(mark.equals("D")){
				card[3][nums-1] = i;
			}
		}
		scan.close();
		for(int i=0; i<4; i++){
			for(int s=0; s<13; s++){
				c = s+1;
				if(card[i][s] == 0){
					if(i == 0){
						System.out.println("S " + c);
					}else if(i == 1){
						System.out.println("H " + c);
					}else if(i == 2){
						System.out.println("C " + c);
					}else if(i == 3){
						System.out.println("D " + c);
					}
				}
			}
		}
	}
}

Measured memory_bytes: 18076
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
 
	if(A<=5){
      System.out.println("0");
    }else if(A>=6 && A<13){
     System.out.println(B/2);
    }else{
      System.out.println(B);
     }
}
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<int, pair<double, double>>> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].second.first >> A[i].second.second;
        A[i].first = i;
    }

    vector<double> dist;
    sort(A.begin(), A.end());

    while(true) {
        double dis = 0;
        for (int i = 0; i < N-1; i++) {
            dis += sqrt((A[i].second.first-A[i+1].second.first)*(A[i].second.first-A[i+1].second.first) + (A[i].second.second-A[i+1].second.second) * (A[i].second.second-A[i+1].second.second));
        }
        dist.push_back(dis);
        if (!next_permutation(A.begin(), A.end())) break;
    }

    int n = 1;
    for (int i = 2; i <= N; i++) {
        n *= i;
    }

    double sum = 0.0;
    for (int i = 0; i < dist.size(); i++) {
        sum += dist[i];
    }

    double ans = sum / n;
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 892
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
ll x[1000005],xx[1000005],w[1000005],l,r,s,t,n,m,c;
int main()
{
    scanf("%lld%lld%lld",&n,&l,&t);
    for(reg int i=1;i<=n;i++)scanf("%lld%lld",&x[i],&w[i]);
    for(reg int i=1;i<=n;i++)
    {
        if(w[i]==2)w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0)(c+=r/l)%=n;
        else if(r<0)(c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    sort(xx+1,xx+n+1);
    c=(c+n)%n;
    for(reg int i=c+1;i<=n;i++)printf("%lld\n",xx[i]);
    for(reg int i=1;i<=c;i++)printf("%lld\n",xx[i]);
    return 0;
}

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

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

using namespace std;

int main(){
  ll n,c,k;cin>>n>>c>>k;
  vector<ll> t(n);
  rep(i,n)cin>>t[i];
  sort(t.begin(), t.end());

  ll result=0, people_count=0, time_limit=0;
  time_limit=t[0]+k;
  rep(i, n){
    if(t[i]<=time_limit && people_count<c){
      people_count++;
    }else{
      result++;
      people_count=1;
      time_limit=t[i]+k;
    }
//cout<<time_limit<<' '<<people_count<<' '<<t[i]<<' '<<result<<endl;
  }

//cout<<people_count<<' '<<result<<endl;

  if(people_count)result++;
  cout<<result;

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (b % a == 0) {
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }
    }
}

Measured memory_bytes: 21972
// AOJ DPL_5_A Balls and Boxes 1
// 2019.3.10 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MOD 1000000007

int myPow(int x, int n)  // x^n
{
	long long ans = 1;
	long long xx = x;

	while (n > 0) {
		if (n & 1) ans = (ans * xx) % MOD, n--;
		else xx = (xx * xx) % MOD, n >>= 1;
	}
	return (int)ans;
}

int main()
{
	int n, k;

	scanf("%d%d", &n, &k);
	printf("%d\n", myPow(k, n));
	return 0;
}


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

int main() {
    int A, B, K; cin >> A >> B >> K;
    int num=0, i=0;

    i = __gcd(A, B) + 1;

    while (num!=K){
        i--;
        if ((A%i==0)&&(B%i==0)) num++;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
//        Int X;
//        cin >> X;
//        Int tapu = X / 500;
//        Int neri = tapu * 1000;
//        X %= 500;
//        Int tapi = X / 5;
//        neri += tapi * 5;
//        cout << neri << endl;

        Int K, N;
        cin >> K >> N;
        vector<Int> A(N);
        rep(i, 0, N) cin >> A[i];
        Int ans = INFl;
        for (int i = 0; i < N; ++i) {
            Int tmp = K - ((-A[i] + A[(i + 1) % N]) % K + K) % K;
            chmin(ans, tmp);
        }
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n;
    cin>>k>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int x=k-(a[n-1]-a[0]);
    for(int i=1;i<n;i++){
        x=max(x,a[i]-a[i-1]);
    }
    cout<<k-x<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main() {
	int a, b, n, ans;
	cin >> n >> a >> b;
	ans = 0;
	for (int i = 1; i <= n; i++) {
		int x = i;
		int temp = 0;
		while (x > 0) {
			temp += x % 10;
			x /= 10;
		}
		if (temp >= a && temp <= b) ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define all(L) L.begin(),L.end()
using ll=long long;
#define RO 1
#define SI 2
#define PA 3

int main(){
    int n;cin>>n;
    vector<pair<int,int> > T(n);
    rep(i,0,n){
        int a,b;cin>>a>>b;
        T[i]=make_pair(b,a);
    }

    sort(all(T));

    string ans="Yes";
    ll cntt=0;
    rep(i,0,n){
        cntt+=T[i].second;
        if(cntt>T[i].first){
            ans="No";
            break;
        }
    }

    cout<<ans<<endl;
}    


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

int main(){
    bool hasSeven=false;
    
    int n;cin>>n;
    while(n){
        int d=n%10;
        if(d==7){
            hasSeven=true;
            break;
        }
        n/=10;
    }
    
    if(hasSeven) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3588
using System;

class test{
    static void Main(){
        string[] str;
        str=Console.ReadLine().Split(' ');
        
        int[] num={int.Parse(str[0]),int.Parse(str[1])};
        while (num[0]!=0||num[1]!=0)
        {
            Array.Sort(num);
            if(num[0]==0&&num[1]==0)break;
            Console.WriteLine("{0} {1}",num[0],num[1]);
            str=Console.ReadLine().Split(' ');
            for(int i=0;i<str.Length;i++){
                num[i]=int.Parse(str[i]);
            }
        }
    }
}



Measured memory_bytes: 9516
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[200001];
	rep1(i, N) A[getint()] = i;

	int dai[200002], shou[200002];
	rep1(i, N) dai[i + 1] = i;
	rep1(i, N) shou[i - 1] = i;

	ll kotae = 0;
	for (int i = N; i > 0; i--) {
		int a = A[i];
		int l = shou[a - 1];
		int r = dai[a + 1];
		kotae += (ll)(a - l + 1) * (r - a + 1) * i;
		dai[l] = r;
		shou[r] = l;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2688
import sys
a=[]
for i in sys.stdin.readlines():
    a.append(i.rstrip())
    
b=''.join(a)
x=str.lower(b)

for i in "abcdefghijklmnopqrstuvwxyz":
    countable=x.count(i)
    print(f'{i} : {countable}')


Measured memory_bytes: 5572
#include <stdio.h>

int main(){      //?????????????´??????????
    int train[100] = {0};
    int num;
    int stock = 0;
    int data[100] = {0};
    int cnt = 0;
    int i = 0;
    while(scanf("%d",&num) != EOF){
        if(num == 0){
            data[cnt] = train[stock - 1];
            printf("%d\n",data[cnt]);
            // printf("???????????????????????????%d????????????%d",cnt,train[stock - 1]);
            train[stock - 1] = 0;
            stock--;     //??????
            
            cnt++;
        }else{
            train[stock] = num;
            stock++;    //??¶??????????????????
        }
    }
    return 0;
}

Measured memory_bytes: 600
N, M, X = list(map(int, input().split()))
CA = [list(map(int, input().split())) for _ in range(N)]

n = 1<<(N)
min_cost = 100000000
for one in range(n):
    tmp = [0]*M
    cost = 0
    for i in range(N):
        if (one>>i & 1)==1:
            cost+=CA[i][0]
            for j in range(M):
                tmp[j]+=CA[i][j+1]
    flag = True
    for i in range(M):
        if tmp[i]<X:
            flag=False
            break
    if flag:
        min_cost = min(min_cost, cost)
    
if min_cost == 100000000:
    print(-1)
else:
    print(min_cost)

Measured memory_bytes: 68620
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

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

  int ans = 0;
  int outlet = 1;

  while(outlet < b) {
    outlet += (a - 1);
    ans += 1;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 768
import math
n,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
p=0
for i in range(0,n-1):
  for j in range(i+1,n):
    q=0
    for k in range(0,d):
      q+=(a[i][k]-a[j][k])**2
    if int(math.sqrt(q))==math.sqrt(q):
      p+=1
print(p)

Measured memory_bytes: 3060
import java.io.*;
import java.math.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws Exception {
		new Main().solve();
	}
	void solve() throws Exception {
		FastScanner in = new FastScanner(System.in);

		int N = in.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = in.nextInt();
		}

		int updown = 0;
		int last = a[0];
		int ret = 0;
		for (int i = 1; i < N; i++) {
			if (updown > 0 && a[i] >= last) {
				//
			} else if (updown < 0 && a[i] <= last) {
				//
			} else if (updown == 0) {
				updown = a[i] - last;
				//
			} else {
				// ng
				updown = 0;
				ret++;
			}
			last = a[i];
		}

		System.out.println(ret + 1);
	}
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	class FastScanner {

		private InputStream _stream;
		private byte[] _buf = new byte[1024];
		private int _curChar;
		private int _numChars;
		private StringBuilder _sb = new StringBuilder();

		FastScanner(InputStream stream) {
			this._stream = stream;
		}

		public int read() {
			if (_numChars == -1) throw new InputMismatchException();
			if (_curChar >= _numChars) {
				_curChar = 0;
				try {
					_numChars = _stream.read(_buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (_numChars <= 0) return -1;
			}
			return _buf[_curChar++];
		}

		public String next() {
			int c = read();
			while (isWhitespace(c)) {
				c = read();
			}
			_sb.setLength(0);
			do {
				_sb.appendCodePoint(c);
				c = read();
			} while (!isWhitespace(c));
			return _sb.toString();
		}

		public int nextInt() {
			return (int) nextLong();
		}
		public long nextLong() {
			int c = read();
			while (isWhitespace(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isWhitespace(c));
			return res * sgn;
		}

		public boolean isWhitespace(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


Measured memory_bytes: 21812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

 
int main(int argc, char const *argv[]) {
  int N;cin>>N;
  vector<int>v(N); for(int i=0;i<N;++i){
  cin>>v[i]; }
  sort(v.begin(),v.end());
  int answer=v[v.size()/2]-v[v.size()/2-1];
  cout<<answer<<endl;

  return 0;
}


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

ll powmod(ll x, ll y){
    ll res = 1;
    for(ll i=0; i<y; i++){
        res = res*x%mod;
    }
    return res;
}
int main()
{
    ll n;
    cin >> n;
    ll ans = powmod(10, n) - powmod(9, n) - powmod(9,n) + powmod(8, n);
    ans %= mod;
    ans = (ans+mod)%mod;
    cout << ans << endl;
  
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    if(Math.abs(a-c) <= d){
      System.out.println("Yes");
    }else if((Math.abs(a-b) <= d) && (Math.abs(b-c) <= d)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

ll d;
vector<vl> s;
vl c(26);
vector<set<ll>> st(26, {-1});
ll score;

void add(ll i, ll k) {  // i日目(0-index)、テストk（0-index）
  st[k].insert(i);
  auto pi = st[k].lower_bound(i);
  pi--;
  ll prev, next;
  if(pi == st[k].begin())
    prev = -1;
  else
    prev = *pi;
  auto ni = st[k].upper_bound(i);
  if(ni == st[k].end())
    next = d;
  else
    next = *ni;
  score += c[k] * (i - prev) * (next - i) + s[i][k];
}

void rm(ll i, ll k) {
  auto pi = st[k].lower_bound(i);
  pi--;
  ll prev, next;
  if(pi == st[k].begin())
    prev = -1;
  else
    prev = *pi;
  auto ni = st[k].upper_bound(i);
  if(ni == st[k].end())
    next = d;
  else
    next = *ni;
  score -= c[k] * (i - prev) * (next - i) + s[i][k];
  st[k].erase(i);
}

void eval(vl &t) {
  rep(i, d) {
    ll k = t[i];
    add(i, k);
  }
}

int main() {
  // 入力をもらう
  cin >> d;
  rep(i, 26) cin >> c[i];
  s.resize(d, vl(26));
  rep(i, d) rep(j, 26) cin >> s[i][j];

  //// 入力を作るデバッグ用
  // d = 365;
  // s.resize(d, vl(26));
  // rep(i, 26) c[i] = rand() % 101;
  // rep(i, d) rep(j, 26) s[i][j] = rand() % 20001;

  // 初期解をランダムに作って評価、scoreに反映
  score = -accumulate(all(c), 0LL) * d * (d + 1) / 2;
  vl t(d);
  rep(i, d) t[i] = rand() % 26;
  eval(t);

  double limit = double(clock()) / double(CLOCKS_PER_SEC) + 1.8;
  while(double(clock()) / double(CLOCKS_PER_SEC) < limit) {
    ll xd = rand() % d;
    ll xt = rand() % 26;
    ll old_score = score;
    ll old_test = t[xd];
    if(xt == t[xd]) xt = (xt + 1) % 26;
    rm(xd, t[xd]);
    add(xd, xt);
    if(score < old_score) {
      rm(xd, xt);
      add(xd, old_test);
    } else
      t[xd] = xt;
  }
  rep(i, d) cout << t[i] + 1 << '\n';
}

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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n;
    cin >> n;

    ll a[n], b[n], suma = 0, sumb = 0;
    vector <pll > e(n);

    for (ll i = 0; i < n; i++)
        cin >> a[i], suma += a[i];
    
    for (ll i = 0; i < n; i++) {
        cin >> b[i], sumb += b[i];
        e[i] = {a[i] - b[i], i};
    }

    if (suma < sumb) {
        cout << -1 << '\n';
    } else {
        sort(all(e));
        vector <int> mark(n, 0);

        ll j = n - 1, i = 0, cnt = 0;
        while (i < j) {
            if (e[i].first >= 0) {
                break;
            } else {
                if (e[j].first >= -e[i].first) {
                    e[j].first += e[i].first;
                    mark[e[i].second] = mark[e[j].second] = 1;
                    i++;
                } else {
                    e[i].first += e[j].first;
                    mark[e[i].second] = mark[e[j].second] = 1;
                    j--;
                }
            }
        }

        for (auto x : mark) cnt += (x);
        cout << cnt << '\n';
    }
    return 0;
}


Measured memory_bytes: 3712
# https://atcoder.jp/contests/abc065/tasks/abc065_b
# B - Trained?
n = int(input().split()[0])

index2number_dict = {}
number2index_dict = {}
button_list = []

for _ in range(n):
    number = int(input().split()[0])
    button_list.append(number)
    

# ボタンが光っているときに押すと、
# 今のボタンの光が消える
# 次のボタンが光る
# ボタン2が光っている状態でやめたい
# print(index2number_dict)

start_index = 1
# print(start_number)
# print(start_index)

step = 0
lighting_index = start_index # 1 - n
status_list = ''
can_stop = False

while True:
    status_list += str(lighting_index)

    lighting_number = button_list[lighting_index - 1]
    lighting_index = lighting_number  # 次のインデックス
    step += 1


    if lighting_index == 2:
        can_stop = True
        break

    if step >= len(button_list):
        break
    # print('i = {}, ai = {}'.format(lighting_index, lighting_number))
    

    # print('Next -> i = {}, a_i = {} '.format(lighting_index, lighting_number))
    

if not can_stop:
    step = -1

# print('===========')
# print(status_list)
print(step)

Measured memory_bytes: 7604
import java.util.HashMap;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum = 0;
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

    for (int i = 0; i < n; i++) {
      int tmp = sc.nextInt();
      if (map.containsKey(tmp)) {
        int v = map.get(tmp);
        map.put(tmp, v + 1);
      } else {
        map.put(tmp, 1);
      }
    }

    for (int key : map.keySet()) {
      sum += key * map.get(key);
    }

    int q = sc.nextInt();

    for (int i = 0; i < q; i++) {
      int b = sc.nextInt();
      int c = sc.nextInt();
      if (map.containsKey(b)) {
        int v = map.get(b);
        int gap = (c - b) * v;
        sum += gap;
        map.remove(b);
        if (map.containsKey(c)) {
          int tmp = map.get(c);
          map.put(c, tmp + v);
        } else {
          map.put(c, v);
        }
      }
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 68000
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
A = 0
rsp = {
    "r":P,
    "s":R,
    "p":S,
}
A += T.count("r")*P
A += T.count("s")*R
A += T.count("p")*S
a = []
for i in range(N):
    if i-K >= 0 and T[i] == a[i-K]:
        A -= rsp[T[i]]
        a.append("")
    else:
        a.append(T[i])
print(A)

Measured memory_bytes: 4792