akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  vi v(n);
  fi(0, n)
    cin >> v[i];

  sort(all(v));
  while(m--) {
    int n = v.size();
    int x = v[n - 1] / 2;
    v.erase(v.begin() + n - 1);
    v.insert(lower_bound(all(v), x), x);
  }
  ans = sum(v);
  cout << ans << endl;
  return 0;
}



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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
typedef pair<double,pi> edge;

inline double dist(int x1, int y1, int x2, int y2)
{
    return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}

struct UF{
    int n;
    //??£?????£????????????????????????,????????£???????????§??£?????????????????°
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

int main()
{
    int n,m;
    scanf(" %d %d", &n, &m);

    vector<int> x(n),y(n);
    rep(i,n) scanf(" %d %d", &x[i], &y[i]);

    vector<edge> e(m);
    double sum=0;
    rep(i,m)
    {
        int p,q;
        scanf(" %d %d", &p, &q);
        --p;
        --q;

        e[i] = edge(dist(x[p],y[p],x[q],y[q]), pi(p,q));
        sum += e[i].fi;
    }

    sort(all(e),greater<edge>());

    UF uf(n);
    double mst_max_cost=0;
    rep(i,m)
    {
        int p=e[i].se.fi, q=e[i].se.se;
        if(!uf.same(p,q))
        {
            uf.unite(p,q);
            mst_max_cost += e[i].fi;
        }
    }

    printf("%.10f\n", sum - mst_max_cost);
    return 0;
}

Measured memory_bytes: 3320
#include<iostream>
using namespace std;
int main(){
int a,b;
std::string op;
while(1){
cin >>a>>op>>b;
if(op=="?")break;
if(op=="+"){
cout<<a+b<<endl;
}else if(op=="-"){
cout<<a-b<<endl;
}else if(op=="*"){
cout<<a*b<<endl;
}else if(op=="/"){
cout<<a/b<<endl;
}
}
return 0;
}




Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
int main(){
    int ans=100000000;
    int A,B; //A:1000mLボトルの価格、B:500mLボトルの価格
    int X; //最低でも何mL買いたいのか        
    cin >> A >> B >> X;               // 1000*x本+500*y本>=Xml
    int loop=X/500+1; //ループ回数  
    int a=0;
    for (int i=0; i<=loop; i++){
        for(int j=0; j<=loop; j++){
            if(1000*i+500*j>=X){
                a=A*i+B*j;
                ans=min(ans,a);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3112
class Node2:
    def __init__(self):
        self.parent = -1
        self.left = -1
        self.right = -1
    
def getSibling(u):
    if Nodes[u].parent == -1:
        return -1
    p = Nodes[u].parent
    if Nodes[p].left == u:
        return Nodes[p].right
    else:
        return Nodes[p].left

def getDepth(u):
    depth = 0
    while Nodes[u].parent != -1:
        depth += 1
        u = Nodes[u].parent
        
    return depth

def getDegree(u):
    if Nodes[i].left != -1 and Nodes[i].right != -1:
        return 2
    elif Nodes[i].left == -1 and Nodes[i].right == -1:
        return 0
    else:
        return 1

def getHeight(u):
    a = 0
    b = 0
    if Nodes[u].left != -1:
        a = getHeight(Nodes[u].left) + 1
    if Nodes[u].right != -1:
        b = getHeight(Nodes[u].right) + 1
    return max(a, b)

def getType(u):
    if Nodes[u].parent == -1:
        return "root"
    elif Nodes[u].right != -1 or Nodes[u].left != -1:
        return "internal node"
    else:
        return "leaf"
    
def printNode(u):
    print_str = "node " + str(u) + ": parent = " + str(Nodes[u].parent) + ", "
    print_str = print_str + "sibling = " + str(getSibling(u)) + ", "
    print_str = print_str + "degree = " + str(getDegree(u)) + ", "
    print_str = print_str + "depth = " + str(getDepth(u)) + ", "
    print_str = print_str + "height = " + str(getHeight(u)) + ", " + getType(u)
    print(print_str)
    
        

    
# 入力
n = int(input())

Nodes = []
for i in range(n):
    tmp_obj = Node2()
    Nodes.append(tmp_obj)

# 登録作業
for i in range(n):
    num, left, right = map(int, input().split())
    Nodes[num].left = left
    Nodes[num].right = right
    if left != -1:
        Nodes[left].parent = num
    if right != -1:
        Nodes[right].parent = num
    
# 出力
for i in range(n):
    printNode(i)


Measured memory_bytes: 5616
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,a[210];cin>>n;
	for(int i=0;i<n*2;i++)cin>>a[i];
	sort(a,a+n*2);
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=a[i*2];
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };



int main() {
	char S[120],T[120];
	scanf("%s%s", &S,&T);

	bool can = false;

	int lenS = strlen(S);
	int lenT = strlen(T);

	if (lenS == lenT) {
		for (int i = 0; i < lenS; i++) {
			for (int j = 0; j < lenS; j++) {
				if (S[(i + j)%lenS] != T[j])break;
				
				if (j == lenS - 1) {
					can = true;
					i = c_INF;
				}
			}
		}
	}
	
	if (can)printf("Yes");
	else printf("No");

}





/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
N, M = [int(i) for i in input().split()]
conditions = [[int(i) for i in input().split()] for j in range(M)] 
num = -1
for i in range(10**N):
    flag = True
    for j in range(M):
        s = conditions[j][0]
        c = conditions[j][1]
        if len(str(i)) < s:
            flag = False
            break
        else :
            if int(str(i)[s-1]) == c:
                pass
            else:
                flag = False
                break
    if flag:
        if len(str(i)) == N:
            num = i
            break
        else :
            pass

print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	ll N;
	vector<ll>V;
	cin >> N;
	V.push_back(2);
	V.push_back(1);
	for(int i=1;i<N;i++){
			ll t;
			t=V[i-1]+V[i];
			V.push_back(t);
	}
	cout << *(V.end()-1) << endl;

}


Measured memory_bytes: 256
a = 0
A, B = map(int, input().split())
c = (B + 1 - A) // 2
d = (B + 1 - A) % 2
if d == 0 and A % 2 == 0:
    if c % 2 == 0:
        a = 0
    else:
        a = 1
elif d == 0 and A % 2 != 0:
    if (c-1) % 2 == 0:
        a = A ^ B
    else:
        a = 1 ^ A ^ B
elif d == 1 and A % 2 == 0:
    if c % 2 == 0:
        a = B
    else:
        a = 1 ^ B
elif d == 1 and A % 2 != 0:
    if c % 2 == 0:
        a = A
    else:
        a = 1 ^ A
print(a)

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

int a[6];

void count(double h) {
  int x = (h - 160.0) * 0.2;
  if(x < 1) a[0]++;
  else if(1 <= x && x < 2) a[x]++;
  else if(2 <= x && x < 3) a[x]++;
  else if(3 <= x && x < 4) a[x]++;
  else if(4 <= x && x < 5) a[x]++;
  else a[5]++;
}

int main() {
  int n;
  cin >> n;
  
  double h;
  for(int i = 0; i < n; ++i) {
	cin >> h;
	count(h);
  }

  
  for(int i = 0; i < 6; ++i) {
	cout << i + 1 << ":";
	for(int j = 0; j < a[i]; ++j) {
	  cout << "*";
	}
	cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3228
N = int(input())

d = {}

m = 0
for i in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
    if d[S] > m: m = d[S]

ans_l = []

for k, v in d.items():
    if v==m: ans_l.append(k)

ans_l = sorted(ans_l)

for ans in ans_l:
    print(ans)


Measured memory_bytes: 32988
let () = Scanf.scanf "%s" @@ fun s ->
  let n = String.length s in
  let easy = ref true in
  for i = 0 to n - 1 do
    if i mod 2 = 0 && s.[i] = 'L' then easy := false
    else if i mod 2 = 1 && s.[i] = 'R' then easy := false
  done;
  Printf.printf "%s\n" @@
  if !easy then "Yes" else "No"

Measured memory_bytes: 3744
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn];

int main()
{
	int n=read(); n*=2;
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<=n;i+=2) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc117/tasks/abc117_d
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(int argc, char const *argv[]) {
  long N,K;
  long x =0;
  cin >> N >> K;
  long A[100100];
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=39;i>=0;i--){
    int count =0;
    for(int j=0;j<N;j++) count +=(A[j]>>i )&1;
    if(2*count<N && (x|(1L<<i))<=K) x|=(1L<<i);
  }
  long ans = 0;
  for(int i=0;i<N;i++) ans+= x^A[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;


template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

using P=pair<ll,pair<ll,ll>>;
void solve(){
	ll n;
	cin>>n;
	vector<P>p(n);
	rep(i,n){
		cin>>p[i].second.first>>p[i].second.second;
		p[i].first=p[i].second.second-p[i].second.first;
	}
	sort(all(p));
	ll ans=0;
	vector<ll>val(n+1),rval(n+1);
	ll left=0,right=1e9;
	rep(i,n){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		val[i+1]=right-left+1;
	}
	left=0,right=1e9;
	for(int i=n-1;i>=0;--i){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		rval[i]=right-left+1;
	}
	REP(i,1,n){
		//cout<<val[i]<<" "<<rval[i]<<"\n";
		chmax(ans,max(val[i],0LL)+max(rval[i],0LL));
	}
	rep(i,n)p[i].first=0;
	sort(all(p));
	left=0,right=1e9;
	rep(i,n){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		val[i+1]=right-left+1;
	}
	left=0,right=1e9;
	for(int i=n-1;i>=0;--i){
		chmax(left,p[i].second.first);
		chmin(right,p[i].second.second);
		rval[i]=right-left+1;
	}
	REP(i,1,n){
		//cout<<val[i]<<" "<<rval[i]<<"\n";
		chmax(ans,max(val[i],0LL)+max(rval[i],0LL));
	}
	cout<<ans<<"\n";
}

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


Measured memory_bytes: 7180
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	int z = sc.nextInt();
	int ans = x/(z+y);
	if(ans*(z+y)+z<=x) System.out.println(ans);
	else System.out.println(ans-1);
    }
}

Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
ll fact_[5000000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 5000000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int dp[63][4];
signed main() {
	cin >> n;
	dp[61][0] = 1;
	for (int i = 61; i > 0; i--) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k <= 2; k++) {
				int r = ((n >> (i - 1)) & 1) - k + 2 * j;
				if (r < 0) continue;
				else if (r < 2) (dp[i - 1][r] += dp[i][j]) %= Mod;
				else (dp[i - 1][2] += dp[i][j]) %= Mod;
			}//この桁のa+bの値が0, 1, 2
		}
	}
	cout << (dp[0][0] + dp[0][1] + dp[0][2]) % Mod << endl;
}

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

int main(){

	int a;
	int b;
	int c;
	
	int i;
	int j=0;
	
	cin >> a >> b >> c;
	
	for(i=a ; i<=b ; i++){
		if(c%i==0){
			j++;
		}
	}
	cout << j <<endl;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int mod = 2019;

int main(void){
    int L, R;
    cin >> L >> R;
    
    if(R - L + 1 >= 2019){
        cout << 0 << endl;
        return 0;
    }
    for(int i = L; i <= R; ++i){
        if(i % mod == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    int ans = 2020;
    for(int i = L; i < R; ++i){
        for(int j = i + 1; j <= R; ++j){
            ll temp = ((ll)i * j) % mod;
            ans = min(ans, (int)temp);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

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

		while(true) {
			boolean judge = true;
			for(int i = 2; i < Math.sqrt(x); i++) {
				if(x%i==0) {
					judge = false;
					x++;
					break;
				}
			}
			if(judge) {
				break;
			}
		}
		System.out.println(x);
	}

}

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

int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a==0)
        cout << 1;
    else if (b == 0)
        cout << 2;
    else if (c== 0)
        cout << 3;
    else if (d==0)
        cout << 4;
    else
        cout << 5;
    cout << '\n';
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,k;
	cin >> n >>k;
	vector<ll> h(n);
	rep(i,n) cin >>h[i];
	sort(all(h));
	ll ans = 1LL<<55;
	rep(i, n+1-k){
		ll w = abs(h[i] - h[i+k-1]);
		ans = min(ans, w);
	}
	cout << ans <<"\n";
	return 0;
}


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

long long _C[51][51];

long long C(int m, int n)
{
	if(_C[m][n]==0)
	{
		if(m==0||m==n)
		{
			return _C[m][n] = 1;
		}else
		{
			return _C[m][n] = C(m-1,n-1) + C(m,n-1);
		}
	}
	else
	{
		return _C[m][n];
	}
}

int main()
{
    std::ios::sync_with_stdio(false);	

	int N,P;
	cin>>N>>P;
	
	vector<int> bis_n(N);
	int bis_n_odd = 0, bis_n_even = 0;
	for(int i = 0 ; i < N ; i++)
	{
		cin>>bis_n[i];
		if( bis_n[i]%2 == 1 )
		{
			bis_n_odd++;
		}
		else
		{
			bis_n_even++;
		}
	}
	
	
	_C[0][1] = 1;
	_C[1][1] = 1;
	_C[0][2] = 1;
	_C[1][2] = 2;
	_C[2][2] = 1;
	
	for(int n = 1 ; n <= N ; n++)
	{
		for(int m = 0 ; m <= n ; m++)
		{
			C(m,n);
		}
	}
	
	long long ans;
	
	if(P==1)
	{
		ans = 0;
		for(int i = 1 ; i <= bis_n_odd ; i+=2)
		{
			ans += C(i,bis_n_odd); 
		}
		if(ans>0)
		{
			ans *= (long long)pow(2,bis_n_even);
		}
	}
	else
	{
		ans = (long long)pow(2,bis_n_even);
		long long ans2 = 0;
		for(int i = 0 ; i <= bis_n_odd ; i+=2)
		{
			ans2 += C(i,bis_n_odd);
		}
		ans *= ans2;
	}
	cout<<ans;
	
    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    ll n; cin >> n;
    vll a(5);
    rep(i, 5) cin >> a[i];

    ll mine = *min_element(a.begin(), a.end());
    ll ans = (n + mine - 1) / mine + 4;

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

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

string n;
int m = 0, w = 0, t = 0;

int main()
{
	cin >> n;
	
	int j = n.size();

	for (int i = j - 1; i >= 0; i--) {

		int k = n[i] - '0' + w;

		if (k < 6) {
			m += k - t;

			if (k == 5 && t == 0) {
				w = 1;
				t = 1;
			}
			else {
				w = 0;
				t = 0;
			}
		}
		else {
			m += 10 - k;
			w = 1;
			t = 0;
		}
	}

	if (t == 1)
		w = 0;

	cout << m + w << endl;

	return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if( abs( c - a ) <= d || ( abs( b - a ) <= d && abs( c - b ) <= d ) )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

using namespace std;

vector<int> erase_equal(vector<int> v) {
	vector<int> result;
	map<int, bool> mp;
	for (int i = 0; i < v.size(); i++) {
		auto itr = mp.find(v[i]);
		if (itr == mp.end()) {
			mp[v[i]] = true;
			result.push_back(v[i]);
		}
	}
	return result;
}

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}

		map<int, long long> sales;
		vector<int> ids(n);
		for (int i = 0; i < n; i++) {
			int id;
			int sale_val;
			int sale_num;
			cin >> id;
			cin >> sale_val;
			cin >> sale_num;

			ids.push_back(id);
			auto itr = sales.find(id);
			if (itr != sales.end()) {
				sales[id] += (long long)sale_val * (long long)sale_num;
			} else {
				sales[id] = (long long)sale_val * (long long)sale_num;
			}
		}

		vector<int> v = erase_equal(ids);
		bool na_flag = true;
		for (int i = 0; i < v.size(); i++) {
			if (sales[v[i]] >= 1000000) {
				cout << v[i] << endl;
				na_flag = false;
			}
		}
		if (na_flag) {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
ll n,x,a[100010],ans=0;

void s(ll i){
  if(a[i]+a[i+1]<=x) return;
  ans+=a[i]+a[i+1]-x;
  if(a[i]<=x) a[i+1]=x-a[i];
  else a[i+1]=0;
  return;
}

int main(){
  cin>>n>>x;
  fr(i,n) cin>>a[i];
  fr(i,n-1) s(i);
  cout<<ans<<endl;
}

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

using namespace std;
const int N = 2e5+5;
int n,m;
int pre[N],sum[N];

void init(){
	for(int i=1;i<=n;i++) pre[i]=i,sum[i]=1;
}

int find(int x){
	if(x==pre[x]) return x;
	else return pre[x]=find(pre[x]);
}

void join(int u,int v){
	int fx=find(u),fy=find(v);
	if(fx!=fy){
		pre[fy]=fx;
		sum[fx]+=sum[fy];
	}
}

int main(){
	cin>>n>>m;
	init();
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		join(u,v);
	}
	cout<<*max_element(sum+1,sum+n+1)<<'\n';
	
	return 0;
} 

Measured memory_bytes: 5144
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 200009
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;

ll a[N],b[N],f[N];
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n;
  ll i=0;
  cin>>n;
  while(i<n)
    {
      cin>>a[i];
      f[a[i]]++;
      i++;
    }
  i=0;
  while(i<n)
  {
    cin>>b[i];
    f[b[i]]++;
    i++;
  }
  i=0;
  while(i<N)
  {
    if(f[i]>n)
    {
      No
      return 0;
    }
    i++;
  }
  Yes
  reverse(b,b+n);
  i=0;
  while(i<n&&a[i]!=b[i])
    i++;
  ll j=i;
  while(j<n&&a[j]==b[j])
    j++;
  j--;
  ll k=0;
  ll t=i;
  while(k<t&&i<=j)
  {
    if(a[k]!=a[i]&&b[k]!=b[i])
    {
      swap(b[k],b[i]);
      i++;
    }
    k++;
  }
  k=j+1;
  while(k<n&&i<=j)
  {
    if(a[k]!=a[i]&&b[k]!=b[i])
    {
      swap(b[k],b[i]);
      i++;
    }
    k++;
  }
  i=0;
  while(i<n)
  {
    cout<<b[i]<<" ";
    i++;
  }
}

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

public class Main {
	private static void solve(){
	//Implement solution here.
		int n = ni();
		int m = ni();
		int[] ary = new int[m];
		int i0 = 1;
		while(i0 <= n){
			int k = ni();
			for(int j = 0; j < k; j++){
				ary[ni() - 1]++;
			}
			i0++;
		}
		
		int result = 0;
		for(int i1 = 0; i1 < m; i1++){
			if(ary[i1] == n)result++;
		}
		
		System.out.println(result);
	}

    //Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
                scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

int main()
{
    string s;
    cin >> s;
    int counter = 0;

    if(s[0] == 'o') ++counter;
    if(s[1] == 'o') ++counter;
    if(s[2] == 'o') ++counter;

    int a = 700 + counter*100;

    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> v(4);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end());
    if(v[0] == v[1] && v[2] == v[3]) puts("yes");
    else puts("no");
    return 0;
}


Measured memory_bytes: 3168
n=int(input())
a=list(map(int,input().split()))

ans=0
while True:
    repeat=True
    for i in range(n):
        if a[i]%2==0:
            a[i]//=2
        else:
            repeat=False
            break
    if repeat==True:
        ans+=1
    else:
        break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,st,dp[N],tot,d[N],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
void dfs(int u,int p)
{
    bool flag=true;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        dfs(v,u);
        dp[u]+=dp[v];
        if(!dp[v])
        {
            if(flag) flag=false;
            else dp[u]++;
        }
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);u++;v++;
        add(u,v);add(v,u);
        d[u]++;d[v]++;
    }
    for(int i=1;i<=n;i++)
        if(d[i]>=3) st=i;
    if(!st){printf("1\n");return 0;}
    dfs(st,0);
    printf("%d\n",dp[st]);
}


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

using namespace std;

typedef long long ll;
typedef long double K;
typedef pair<int, int> pii;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const int inf = 2000000000;

main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
#define Puts(b) cout<<(b? "Yes":"No")<<endl
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  cin >> n;
  rep(i, n, 1000) {
    string s = to_string(i);
    if(s[0] == s[1] && s[1] == s[2]) return cout << s << endl, 0;
  }
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n, a;
  cin >> n >> a;

  vll x(n);
  rep(i, n) {
    cin >> x[i];
    x[i] -= a;
  }

  vvll dp(n + 1, vll(5010));
  const ll offset = 2500;
  dp[0][offset] = 1;
  rep(i, n) {
    rep(j, 5001) {
      dp[i + 1][j] += dp[i][j];
      if (j + x[i] >= 0 && j + x[i] <= 5000) {
        dp[i + 1][j + x[i]] += dp[i][j];
      }
    }
  }

  cout << dp[n][offset] - 1 << endl;

  return 0;
}


Measured memory_bytes: 5304
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int x, y;
  cin >> x >> y;

  cout << x + y / 2 << "\n";
  return 0;
}



Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,len(p)-1):
    l=[]
    l.append(p[i-1])
    l.append(p[i])
    l.append(p[i+1])
    l.sort()
    if l[1]==p[i]:
        count=count+1
print(count)

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

typedef long long ll;

const int mod = 998244353;

int main() {
    ll N;
    cin >> N;
    map<ll, ll>mp;
    vector<ll>D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i];
        mp[D[i]]++;
    }
    if (D[0] != 0) {
        cout << 0 << endl;
    } else {
        ll ans = 1;
        sort(D.begin(), D.end(), greater<ll>());
        for (int i = 0; i < N-1; i++) {
            ans *= mp[D[i]-1]; 
            ans %= mod;
        }
        cout << ans % mod << endl;
    }
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
vector<int> upr, sz, ssz, dp, prt;
void dfs (int crr = 0, int prt = 0) {
  upr[crr] = max(upr[prt], prt);
  sz[crr] = 1;
  if (upr[upr[crr]] > crr) {
    ssz[crr] = 1;
  } else {
    ssz[crr] = 0;
  }
  for (int nxt : grh[crr]) if (nxt != prt) {
    dfs(nxt, crr);
    if (upr[crr] > nxt) {
      if (upr[crr] > crr) {
        sz[crr] += sz[nxt];
      } else {
        sz[crr] += ssz[nxt];
      }
    }
    if (upr[upr[crr]] > crr && upr[upr[crr]] > nxt) {
      ssz[crr] += ssz[nxt];
    }
  }
}
void efs (int crr = 0, int prt = 0) {
  dp[crr] = dp[prt];
  if (upr[prt] > prt && upr[prt] < crr) {
    dp[crr] += sz[crr];
  }
  if (upr[prt] < prt) {
    dp[crr] += sz[crr] - ssz[crr];
  }
  for (int nxt : grh[crr]) if (nxt != prt) {
    efs(nxt, crr);
  }
}
int main() {
  int n;
  cin >> n;
  grh.resize(n);
  upr.resize(n, 0);
  sz.resize(n, 0);
  ssz.resize(n, 0);
  dp.resize(n, 1);
  prt.resize(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    grh[--a].push_back(--b);
    grh[b].push_back(a);
  }
  dfs();
  efs();
  for (int i = 1; i < n; i++) {
    cout << dp[i];
    if (i < n - 1) {
      cout << ' ';
    } else {
      cout << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 32128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int cmp(const void *a, const void *b){
    return strcmp((const char *)a, (const char *)b);
}

int main(void){
    int n, max = 0;
    scanf("%d", &n);
    char str[n][11];
    int count[n];
    for(int i = 0; i < n; i++){
        scanf("%s", str[i]);
        count[i] = 0;
    }
    qsort(str, n, 11, cmp);
    for(int i = 0; i < n - 1; i++){
        if(strcmp(str[i], str[i + 1]) == 0){
            count[i] ++;
            count[i + 1] = count[i] + 1;
        }
    }
    for(int i = 0; i < n; i++){
        if(count[i] > max){
            max = count[i];
        }
    }
    
    for(int i = 0; i < n; i++){
        if(max == count[i]){
            printf("%s\n", str[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 5244
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

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

    vector<int> p(n);
    for(int i = 0;i < n;++i)    cin >> p[i];
    vector<int> p_sum(n-k+1, 0);
    for(int i = 0;i < k;++i){
        p_sum[0] += p[i];
    }
    for(int i = 1;i < p_sum.size();++i){
        p_sum[i] = p_sum[i-1] - p[i-1] + p[i+k-1];
    }

    int max_p_sum_i = 0;
    int max_p_sum = -1;
    for(int i = 0;i < p_sum.size();++i){
        if(max_p_sum < p_sum[i]){
            max_p_sum = p_sum[i];
            max_p_sum_i = i;
        }
    }

    double ans = 0.0;
    for(int i = 0;i < k;++i){
        ans += (double)(p[max_p_sum_i+i]*(p[max_p_sum_i+i]+1)/2) / (double)(p[max_p_sum_i+i]);
    }

    printf("%.13lf\n", ans);

    

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod = 1000000007;
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n; 
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int bits[64];
    memset(bits,0,sizeof(bits));

    for(int i=0;i<60;i++)
    {
        for(int j=0;j<n;j++)
        {
            bits[i] += (arr[j]>>i)&1; 
        }
    }
    int ans = 0;
    for(int i=0;i<60;i++)
    {
        int val = (bits[i]*(n-bits[i]))%mod;
        int po = (1ll<<i)%mod;
        ans = (ans+(val*po)%mod)%mod;
    }
    cout<<ans<<"\n";
    return 0;

}

Measured memory_bytes: 2560
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if x in a:
  if y in a:
    print("Yes")
  else:
    print("No")
if x in b:
  if y in b:
    print("Yes")
  else:
    print("No")
if x in c:
  if y in c:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll bo[510][510];

bool used[510][510];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll M = N * N;
    ll P[M];
    REP(i, 0, M) {
        cin >> P[i];
        P[i]--;
    }
    // cout << "aaa" << endl;
    ll ans = 0;
    REP(i, 0, N) {
        REP(j, 0, N) {
            bo[i + 1][j + 1] = min(min(i, N - 1 - i), min(j, N - 1 - j));
        }
    }
    REP(i, 0, M) {
        // REP(j, 0, N) {
        //     REP(k, 0, N) {
        //         cout << bo[j + 1][k + 1] << " ";
        //     }
        //     cout << endl;
        // }
        ll q = P[i];
        ll x = q % N + 1;
        ll y = q / N + 1;
        // cout << x << " " << y << endl;
        ans += bo[x][y];
        // cout << bo[x][y] << endl;
        used[x][y] = true;
        queue<plglg> que;
        que.push(plglg(x, y));
        while (!que.empty()) {
            plglg p = que.front();
            que.pop();
            ll px = p.first;
            ll py = p.second;
            ll val = bo[px][py];
            if (!used[px][py]) {
                val++;
            }
            REP(j, 0, 4) {
                ll newx = px + dx[j];
                ll newy = py + dy[j];
                if (val < bo[newx][newy]) {
                    bo[newx][newy] = val;
                    que.push(plglg(newx, newy));
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7872
#include<iostream>
#include<cstdio>
#include<algorithm>

int main(){
    int R;
    scanf("%d",&R);
    if(R<1200)std::cout<<"ABC"<<"\n";
    else if(R>=2800)std::cout<<"AGC\n";
    else std::cout<<"ARC\n";

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		String a=scan.next();
		int ans=0;
		for(int i=0;i<a.length();i++) {
			for(int j=i+1;j<a.length()+1;j++) {
				String str=a.substring(i,j);
				int count=0;
				for(int k=0;k<str.length();k++) {
					char ch=str.charAt(k);
					if(ch=='A'||ch=='C'||ch=='G'||ch=='T') {
						count++;
					}
					else {
						break;
					}
				}
				ans=Math.max(ans,count);
			}
		}
		System.out.println(ans);
	}
	}

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

int main(){
  int n;
  cin >> n;
  vector<tuple<string, int, int>> a;//string:市,int:点数,int:番号となっている
  for (int i=1;i<=n;++i){
    string s;
    int p;
    cin >> s >> p;
    p=-p;
    a.push_back(tie(s,p,i));
  }
  
  sort(a.begin(),a.end());
  for (int i=0;i<n;++i){
    cout << get<2>(a[i]) << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/python
import sys,math
if sys.version_info[0]>=3: raw_input=input
while True:
	a,b=[int(e) for e in raw_input().split()]
	if not a: break
	print(min(abs(b-math.hypot(i,a-i)) for i in range(a//2+1)))

Measured memory_bytes: 6384
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int A[101];
	int count = 0;
	for (int i=0; i < n; i++) {
		scanf("%d", &A[i]);
	};
	int flag = 0;
	for (int i=0; i < n; i++) {
		int minj = i;
		for (int j=i+1; j < n; j++) {
			if (A[j] < A[minj]) {
				minj = j;
				flag = 1;
			}
		}
		if (flag) {
			if (A[i] != A[minj]) {
				swap(A[i], A[minj]);
				count++;
			}
		}
	}	
	for (int i=0; i < n; i++) {
		if (i == n-1) {
			printf("%d", A[i]);
		} else {
			printf("%d ", A[i]);
		}
	}
    printf("\n%d\n", count);
}


Measured memory_bytes: 2708
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
# 2次元累積和
acum = [[0]*(w+1) for _ in range(h+1)]
for i in range(h):
    for j in range(w):
        acum[i+1][j+1] = acum[i][j+1] + acum[i+1][j] - acum[i][j] + int(s[i][j])
#print(acum)


def white_choco_count(x1, y1, x2, y2):
    return acum[y2][x2] - acum[y2][x1] - acum[y1][x2] + acum[y1][x1]


ans = float("inf")
for rows in range(2**(h-1)):
    count = 0
    hlist = []
    for i in range(h-1):
        if rows >> i & 1 == 1:
            count += 1  # 横線の数カウントしておく
            hlist.append(i+1)
    hlist.append(h)
    #print(hlist)
    x1 = 0
    for x2 in range(w):
        y1 = 0
        for y2 in hlist:
            if white_choco_count(x1, y1, x2, y2) > k:
                count += float("inf")
            # kを超えてはいけないが、一個右で縦に割るとｋを超える必要がある（貪欲にやるので）
            elif white_choco_count(x1, y1, x2, y2) <= k < white_choco_count(x1, y1, x2+1, y2):
                count += 1
                # 次のブロックにいくのでx1更新(ただしy1の更新はx2がｗまでおわったあとにしたいのでbreak使うとうまくいく）
                x1 = x2
                break
            y1 = y2
    # ここまでで、x2=0, 1, ..., w-1 までみたが、x2 = wのとき（ブロックの右端）を見てない
    y1 = 0
    for y2 in hlist:
        if white_choco_count(x1, y1, w, y2) > k:
            count += float("inf")
        y1 = y2
    #print(count)
    ans = min(ans, count)
print(ans)



Measured memory_bytes: 46940
# -*- coding: utf-8 -*-

S, T = input(), input()
nS = len(S)

dS, dT = {}, {}
for i in range(nS):
    if not S[i] in dS:
        dS[S[i]] = T[i]
    elif not dS[S[i]] == T[i]:
        print("No")
        exit()

    if not T[i] in dT:
        dT[T[i]] = S[i]
    elif not dT[T[i]] == S[i]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    int T,N;
    scanf("%d %d",&N,&T);
    int t[N],c[N];
    int i;
    for(i=0;i<N;i++)scanf("%d %d",&c[i],&t[i]);
    int max=c[0];
    int x;
    for(i=0;i<N;i++){
        if(t[i]<=T)if(max>c[i]){
            max=c[i];
            x=i;
        }
    }
    if(t[x]>T)printf("TLE");
    else printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string.h>
using namespace std;

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

  bool card[52];
  for(int t=0;t<52;t++){
    card[t] = false;
  }

  char c;
  int x;
  for(int i=0;i<n;i++){
    cin >> c >> x;
    int j;
    if(strcmp(&c,"S")==0) j=0;
    else if(strcmp(&c,"H")==0) j=1;
    else if(strcmp(&c,"C")==0) j=2;
    else j=3;
    card[j*13+x-1] = true;
  }

  for(int s=0;s<52;s++){
    if(card[s] == false){
      switch(s/13){
        case 0:
          cout << "S " << s+1 << endl;
          break;
        case 1:
          cout << "H " << s%13+1 << endl;
          break;
        case 2:
          cout << "C " << s%13+1 << endl;
          break;
        case 3:
          cout << "D " << s%13+1 << endl;
          break;
        default:
          break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<cmath>
#include <numeric>
#include<climits>
#include<cfloat>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

int INF = 1e9 + 1;

using namespace std;
typedef pair<int,bool> Pair;

int main(){

	int N;
	int d[8];
	double x[8], y[8];
	double total = 0;
	double sum = 0;

	cin >> N;

	for (int i = 0; i < N; ++i){
		
		cin >> x[i] >> y[i];
		d[i] = i;
	}

	do{

		for (int i = 1; i < N;++i)	sum += sqrt((x[d[i]] - x[d[i - 1]])*(x[d[i]] - x[d[i - 1]]) + (y[d[i]] - y[d[i - 1]])*(y[d[i]] - y[d[i - 1]]));
		++total;

	} while (next_permutation(d, d + N));

	cout << setprecision(8) << sum/total << endl;

	return 0;

}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010, mod = 1e9 + 7;

int n;
map<int, int> h;

int main()
{
    cin >> n;
    for(int i = 2; i <= n; i++)
    {
        int t = i;
        for(int j = 2; j <= t / j; j++)
        {
            int cnt = 0;
            if(t % j == 0)
                while(t % j == 0)
                {
                    t /= j;
                    cnt++;
                }
            h[j] += cnt;
        }
        if(t > 1) h[t]++;
    }

    int res = 1;
    for(auto it = h.begin(); it != h.end(); it++)
    {
        int t = it->second;
        res = (LL)res * (t + 1) % mod;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
int a[200005] = {};
int b[200005];
int main() {
	int n;
	cin >> n;
	
	for (int i = 0; i < n-1; i++) {
		cin >> b[i];
		a[b[i] - 1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5160