akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

int main(void)
{
   int a=700, x, i;
   char s[11];

   scanf("%s",s);

   for(i=0;i<strlen(s)-2;i++){
      x=(s[i]-0x30)*100+(s[i+1]-0x30)*10+(s[i+2]-0x30);
      if(x>753){
         if(x-753<a)
            a=x-753;
      }
      else
         if(753-x<a)
            a=753-x;
   }

   printf("%d\n",a);
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll k, a, b; cin >> k >> a >> b;
    if(k == 1){
        cout << 2 << endl;
        return 0;
    }
    if(b - a <= 2){
        cout << k + 1 << endl;
        return 0;
    }
    if(a-1+2 > k){
        cout << k + 1 << endl;
        return 0;
    }
    ll rest = k - (a-1+2);
    cout << b + (rest/2)*(b-a) + (rest%2) << endl;
}


Measured memory_bytes: 3628
A, B, C, X, Y = map(int, input().split())
ret = A * X + B * Y
x = 0
y = 0
c = 0
while (X + Y) * 2 > c :
    c += 2
    x += 1
    y += 1
    tmp = A * max(0, X - x) + B * max(0, Y - y) + c * C
    ret = min(ret, tmp)
print(ret)

Measured memory_bytes: 9092
x = int(input())
if x >= 1800:
    print(1)
elif x >= 1600:
    print(2)
elif x >= 1400:
    print(3)
elif x >= 1200:
    print(4)
elif x >= 1000:
    print(5)
elif x >= 800:
    print(6)
elif x >= 600:
    print(7)
else:
    print(8)

Measured memory_bytes: 9112
N,A,B,C,D=map(int,input().split())
x = N // A
y = N // C
if N % A == 0:
    a = x * B
else:
    a = B * (x + 1)

if N % C == 0:
    c = y * D
else:
    c = D * (y + 1)
    
if a < c:
    print(a)
else:
    print(c)


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

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); }

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(r, seg[--b]);
        }
        return merge(l, r);
    }
};

int n;
int a[100010];

bool isOK(int num){
    int b[100010] = {};
    map<int, int> mp;
    vector<int> vec;
    vec.push_back(0);
    for(int i = 0;i < n;i++){
        b[i+1] += b[i];
        if(a[i] >= num){
            b[i+1]++;
            vec.push_back(b[i+1]);
        }else{
            b[i+1]--;
            vec.push_back(b[i+1]);
        }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    for(int i = 0;i < vec.size();i++){
        mp[vec[i]] = i;
    }

    long long ans = 0;
    SegmentTree<int> seg(n, 0, [](int a, int b){ return a + b;});
    seg.update(mp[0], 1);

    for(int i = 1;i <= n;i++){
        ans += seg.get(0, mp[b[i]]+1);
        seg.add(mp[b[i]], 1);
    }

    return ans >= ((((long long)n * (long long)(n+1)) / 2)+1) / 2;
}

signed main(){
    cin >> n;

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

    int l = 1, r = 1000000001;

    while(r-l > 1){
        int mid = (r+l)/2;

        if(isOK(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }

    cout << l << endl;
    return 0;
}


Measured memory_bytes: 7184
s = input()

if s == "SAT":
    print(1)
elif s == "FRI":
    print(2)
elif s == "THU":
    print(3)
elif s == "WED":
    print(4)
elif s == "TUE":
    print(5)
elif s == "MON":
    print(6)
else:
    print(7)


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

int main(){

    int c[3];

    int ca = 0, cb = 0;

    for(int i = 0; i < 3; ++i){

        cin >> c[i];
        if(c[i] == 5)++ca;
        if(c[i] == 7)++cb;

    }

    if(ca == 2 && cb == 1)cout << "YES\n";
    else cout << "NO\n";

    return 0;

}

Measured memory_bytes: 256
fun main(arr: Array<String>) {
    println(solve())
}

fun solve():Int {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    var next = 1
    var ans = 0
    for(i in a) {
        if(i == next) {
            next++
        } else {
            ans++
        }
    }
    if(ans == n) {
        return  - 1
    }
    return ans
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A, B, Q;
ll S[100005];
ll T[100005];

ll solve(ll x)
{
    //! x以上の神社の最大index
    int s = A, us = -1;
    while (abs(us - s) > 1)
    {
        int mid = (s + us) / 2;
        if (S[mid] >= x)
            s = mid;
        else
            us = mid;
    }

    //! x以上の寺の最大index
    int t = B, ut = -1;
    while (abs(ut - t) > 1)
    {
        int mid = (t + ut) / 2;
        if (T[mid] >= x)
            t = mid;
        else
            ut = mid;
    }

    ll min = INF;
    //! t,t-1,s,s-1を訪れる組み合わせで一番距離が短いもの
    for (int i = 0; i <= 1; ++i)
    {
        for (int j = 0; j <= 1; ++j)
        {
            //! 神社index
            int si = std::min(std::max(0, s - i), (int)A - 1);
            int ti = std::min(std::max(0, t - j), (int)B - 1);
            //! 寺→神社の順番
            ll sum0 = abs(S[si] - x) + abs(T[ti] - S[si]);
            ll sum1 = abs(T[ti] - x) + abs(S[si] - T[ti]);
            min = std::min(min, std::min(sum0, sum1));
        }
    }
    return min;
}

int main()
{
    cin >> A >> B >> Q;
    REP(i, A)
    {
        cin >> S[i];
    }
    S[A] = INF;
    REP(i, B)
    {
        cin >> T[i];
    }
    T[B] = INF;
    REP(i, Q)
    {
        ll x;
        cin >> x;
        cout << solve(x) << endl;
    }
    return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        scan.close();

        if(n % 2 == 0) System.out.println(n/2);
        else System.out.println((n/2) + 1);
    }
}

Measured memory_bytes: 21716
N, M = map(int, input().split())
X = list(map(int, input().split()))

X = sorted(X)
diff = []
for i in range(M-1):
    diff.append(X[i+1] - X[i])
diff = sorted(diff)[::-1]
print(X[-1] - X[0] - sum(diff[:N-1]))

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e5 + 5;

unsigned long long a[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	if(a[1]==0) {cout<<0<<'\n';return 0;}
	unsigned long long res=1;
	unsigned long long j;
	for(int i=1;i<=n;i++){
		res=res*a[i];
		if(res>1000000000000000000 || (i>1 && res<j)) {cout<<"-1\n";return 0;}
		j=res;
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 4440
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i,n) for(int i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int)v.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

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

    ll N;
    cin >> N;

    ll ans = 0;
    REP(i,N){
        ans += (i + 1) * (N - i);
    }

    REP(i,N - 1){

       int u,v;cin >> u >> v;
       if(u > v)swap(u,v);

       ans -= u * (N + 1 - v);

    }

    cout << ans << '\n';

}


Measured memory_bytes: 3640
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph2 {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph2() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		for(i = 0; i < totalVertex; i ++) {
			for(j = 0; j < totalVertex; j ++) {
				int t = in.nextInt();
				if(t != -1) {
					adjMatrix[i][j] = 1;
					adjWeight[i][j] = t;
				}
				
			}
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	
	public int[] Prim(int s) {
		LinkedList<Integer> linker = new LinkedList<Integer>();
		for(int i = 0; i < totalVertex; i ++) linker.add(i);
			int[] distance = new int[totalVertex];
		for(int i = 0; i < totalVertex; i ++) 
			distance[i] = Integer.MAX_VALUE;
		distance[s] = 0;
		while(linker.isEmpty() == false) {
			int j = getUnsettledNearest(distance);
			if(distance[j] == Integer.MAX_VALUE) 
				break;
			linker.remove(linker.indexOf(j));
			ifSettled[j] = true;
			Iterator<Integer> iter = 
					getUnsettledNeighbors(j).iterator();
			while(iter.hasNext()) {
				int m = iter.next();
				int k = getWeight(j, m); 
				if(k < distance[m]) distance[m] = k;
			}
		}
		return distance;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph2 g = new Graph2();
		g.loadAdjMatrix();
		int[] dist = g.Prim(0);
		int cost = 0;
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			cost += dist[i];
		}
		System.out.println(cost);
	}
}


Measured memory_bytes: 41284
#include<bits/stdc++.h>
using namespace std;
int a[2000][2000]={};
int main(){
  int n,f;
  //int a[2000][2000]={};
  map<string,int> M;
  map<int,string> MD;
  set<string> S;
  int c=0;
  int count=0;
  cin>>n>>f;
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    vector<string> st;
    for(int t=0;t<m;t++){
      string s;
      cin>>s;
      st.push_back(s);
      if(S.find(s)==S.end()){S.insert(s); MD[count]=s; M[s]=count; count++;}
      for(int h=0;h<st.size()-1;h++){
	a[M[s]][M[st[h]]]++;
	a[M[st[h]]][M[s]]++;
	if(a[M[st[h]]][M[s]]==f){c++;}
      }
    }
  }
  cout<<c<<endl;
  for(set<string>::iterator i=S.begin();i!=S.end();i++){
    for(set<string>::iterator t=i;t!=S.end();t++){
      if(a[M[(*i)]][M[(*t)]]>=f){
	  cout<<(*i)<<" "<<(*t)<<endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 7312
n = int(input())
v = []
f = []
for i in range(n):
	x = int(input())
	v.append(x)
	f.append(x)
f.sort()
for i in range(n):
	if v[i] == f[n-1]:
		print(str(f[n-2]) + ' ', end='')
	else:
		print(str(f[n-1]) + ' ', end='')	

Measured memory_bytes: 14120
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll mod=998244353;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int k;cin >> k;
    for (int i = 0; i < k; i++) {
        cout << "ACL";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <functional>
#include <sstream>
#include <fstream>
#include <valarray>
#include <complex>
#include <queue>
#include <cassert>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define debug_flag 1
#else
	#define debug_flag 0
#endif

template <class T1, class T2 >
std::ostream& operator << (std::ostream& os, const pair<T1, T2> &p) 
{
	os << "[" << p.first << ", " << p.second << "]";
	return os;
}

template <class T >
std::ostream& operator << (std::ostream& os, const std::vector<T>& v) 
{
	os << "[";
	bool first = true;
	for (typename std::vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
	{
		if (!first)
			os << ", ";
		first = false;
		os << *it;
	}
	os << "]";
	return os;
}

#define dbg(args...) { if (debug_flag) { _print(_split(#args, ',').begin(), args); cerr << endl; } else { void(0);} }

vector<string> _split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return v;
}

void _print(vector<string>::iterator) {}
template<typename T, typename... Args>
void _print(vector<string>::iterator it, T a, Args... args) {
    string name = it -> substr((*it)[0] == ' ', it -> length());
    if (isalpha(name[0]))
	    cerr << name  << " = " << a << " ";
	else
	    cerr << name << " ";
	_print(++it, args...);
}

typedef long long int int64;

const int N = 205;

int n, m;
char mx[N][N];
int cnt[N];

int main()
{
#ifdef LOCAL
	freopen ("input.txt", "r", stdin);
#endif

  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", mx[i]);
  }
  int c1, c2, c4;
  c1 = c2 = c4 = 0;
  if (n % 2 == 0 && m % 2 == 0) {
    c4 = n * m / 4;
  } else if (n % 2 == 1 && m % 2 == 0) {
    c2 = m / 2;
    c4 = (n * m - c2 * 2) / 4;
  } else if (n % 2 == 0 && m % 2 == 1) {
    c2 = n / 2;
    c4 = (n * m - c2 * 2) / 4;
  } else {
    c1 = 1;
    c2 = (n - 1) / 2 + (m - 1) / 2;
    c4 = (n * m - 2 * c2 - c1) / 4;
  }

  int k1 = 0;
  int k2 = 0;
  int k4 = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int c = mx[i][j] - 'a';
      cnt[c]++;
    }
  }

  for (int i = 0; i < N; i++) {
    if (cnt[i] == 0) {
      continue;
    }
    if (cnt[i] % 4 == 0) {
      k4++;
    } else if (cnt[i] % 2 == 0) {
      k2++;
    } else {
      k1++;
    }
  }

  if (k1 > c1 || k2 > c2) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }

	return 0;
}


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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

long long POW(long long a, long long n) {
	long long x = 1LL;
	for (; n > 0; n >>= 1, a *= a)
		x *= ((n & 1) == 1) ? a : 1;
	return x;
}

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	vi P(N);
	cin >> P;

	sortall(P);

	int a, b, c;
	a = b = c = 0;
	for (int i = 0; i < N; i++)
		if (P[i] <= A)
			a++;
		else if (P[i] <= B)
			b++;
		else
			c++;

	cout << min({ a, b, c }) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	int N,a[200000],flag=1;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	scanf("%d",&a[i]);
	sort(a,a+N);
	for(int i=N-1;i>0;i--)
	{
		if(a[i]==a[i-1])
		{
			flag=0;
			break;
		}
	}
	if(flag==1)	printf("YES\n");
	else	printf("NO\n");
}


Measured memory_bytes: 1024
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def dfs(v, p):
        for u in edge_extend[p][v]:
            next_p = 0 if p == 2 else p + 1
            if dist[next_p][u] <= dist[p][v] + 1:
                continue
            else:
                dist[next_p][u] = dist[p][v] + 1
                dfs(u, next_p)

    n, m = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, input().split())
        edge[u - 1].append(v - 1)
    s, t = map(int, input().split())

    edge_extend = []
    for _ in range(3):
        edge_extend.append(edge)

    dist = [[f_inf] * n for _ in range(3)]
    dist[0][s - 1] = 0
    que = deque([[0, s - 1]])
    while que:
        p, v = que.popleft()
        next_p = 0 if p == 2 else p + 1
        for u in edge_extend[p][v]:
            if dist[next_p][u] > dist[p][v] + 1:
                dist[next_p][u] = dist[p][v] + 1
                que.append([next_p, u])

    print(dist[0][t - 1] // 3 if dist[0][t - 1] != f_inf else -1)


if __name__ == '__main__':
    resolve()


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
int a[100010];

int msb(int x){
	int num=0;
	while(x>0) x/=2,num++;
	return num;
}

set<int> s;

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];

	int xsum=0;
	rep(i,n) xsum^=a[i];

	rep(i,n) s.insert((a[i]^(a[i]-1)));

	int ans=0;
	for(auto it=rbegin(s);it!=rend(s);++it){
		if(msb(xsum)==msb(*it))
			xsum^=*it,ans++;
	}
	
	if(xsum==0)	
		cout << ans << endl;
	else
		cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def add_temp_to_T(p, temp, T ):
    if p % 2 == 0:
        T[p-1] += temp[1]
        T[p] += temp[0]
    else:
        T[p-1] += temp[0]
        T[p] += temp[1]
    return 0


def main():
    S = input().strip()
    n = len(S)

    i = 0
    T=[0 for _ in range(n)]
    while i<n:
        temp = [0, 0]
        while i<n and S[i] == 'R':
            temp[i % 2] += 1
            i += 1
        p = i
        while i<n and S[i] == 'L':
            temp[i % 2] += 1
            i += 1
        add_temp_to_T(p, temp, T)
    del i
    print(" ".join(map(str,T)))

if __name__ == '__main__':
    main()


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

typedef long long int Int;

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

int main()
{
    faster();
    
    Int n,k;
    cin>>n>>k;
    Int a[n];
    Int i,j;
    for(i=0; i<n; i++) cin>>a[i];
    
    Int c[n];
    for(i=0; i<n; i++) c[i] = 0;
    
    Int min = -1;
    Int temp;
    
    
    for(i=1; i<n; i++)
    {
        min = -1;
        for(j = i-1; j>=0 && j >= i - k; j-- )
        {
            temp = abs(a[i] - a[j]) + c[j];
            if (min == -1) min = temp;
            else
            {
                if ( temp < min) min = temp;
            }
        }
        c[i] = min;
    }
    cout<<c[n-1]<<'\n';
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<map>
#include<vector>
#include<math.h>
#define ll long long
using namespace std;

int dp[1001][1001];


main()
{
	int h,w;
	cin>>h>>w;
	
	int i,j,k;
	char a[h][w];
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		cin>>a[i][j];
	}
	
	dp[0][0] = 1;
	
	bool flag = true;
	for(i=1;i<h;i++)
	{
		if(a[i][0] == '#')
		flag = false;
		
		if(flag)
		dp[i][0] = 1;
		else
		dp[i][0] = 0;
	}
	
	flag = true;
	for(j=1;j<w;j++)
	{
		if(a[0][j] == '#')
		flag = false;
		
		if(flag)
		dp[0][j] = 1;
		else
		dp[0][j] = 0;
	}
	
	for(i=1;i<h;i++)
	{
		for(j=1;j<w;j++)
		{
			if(a[i][j] == '.')
			dp[i][j] = dp[i-1][j] + dp[i][j-1];
			else
			dp[i][j] = 0;
			
			dp[i][j] %= 1000000007;
		}
	}
	
	cout<<dp[h-1][w-1];
	
	
}

Measured memory_bytes: 5120
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		// ??????????????£??????????´?
		int num[] = { scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt() };

		// ?????°?????????
		int x = scan.nextInt();
		for (int count = 0; count < x; count++) {
			// ?????¢????????????????????§????????????????????????
			int top = scan.nextInt();
			int front = scan.nextInt();
			// ?????????????????¶?????????????????£??????bot??????????????¨?????????
			int result[] = check(num, top, front);
			sb.append(result[2]);
			sb.append("\n");
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(new String(sb));

	}

	// ?????????????????????????????¢??¨?????¢?????????????????????
	private static int[] check(int num[], int chk,int chk2) {
		int top = num[0];
		int front = num[1];
		int left = num[2];
		int right = num[3];
		int back = num[4];
		int bot = num[5];

		for (int count2 = 0; count2 < 2; count2++) {

			// ??????????????????????????????????????????
			for (int count = 0; count < 4; count++) {

				// num[0]???chk????????£??????top????±????
				if (chk == num[0]) {
					break;
				}

				// ?????????num1??????????¶???????????????£??????????????£??\????????¨?????´??°?????????????????????????????????????????????????????£?????????
				int x1 = num[1];
				num[1] = num[0];
				num[0] = num[4];
				num[4] = num[5];
				num[5] = x1;
			}
			//???????¨??????¢?????????
			int x2 = num[1];
			num[1] = num[3];
			num[3] = num[4];
			num[4] = num[2];
			num[2] = x2;
		}
		
		//????????§?????¢????¢??????????
		for(int count3=0;count3<4;count3++){
			
			if (chk2 == num[1]) {
				break;
			}
			
			//???????¨??????¢?????????
			int x2 = num[1];
			num[1] = num[3];
			num[3] = num[4];
			num[4] = num[2];
			num[2] = x2;
			
			
		}
		
		
		
		

		int result[] = { num[0], num[1], num[2], num[3], num[4], num[5] };

		return result;
	}
}

Measured memory_bytes: 26316
#include <iostream>
#include <cstdio>

using namespace std;

void solve(void){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0, min(b, d) - max(a, c)) << endl;;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    int ans = N % 1000;
    if (ans) {
        ans = 1000 - ans;
    }

    cout << ans << endl;

    return 0;
}


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

int main(void) {
    int A[1<<18];
    int N;
    int ans = 0;
    int m,s1,s2;
    cin >> N;
    m = 1<<N;
    for(int i=0; i<m; i++) cin >> A[i];
    for(int i=1; i<m; i++) {
        s1=A[0],s2=0;
        for(int j=i; j; j=(j-1)&i) {
            if(A[j]>s1) s2=s1, s1=A[j];
            else if (A[j]>s2) s2=A[j];
        }
        ans = max(ans, s1+s2);
        cout << ans << endl;
    }
    return 0;
}


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

using namespace std;

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

bool used[100];
long long c[101][101], R;
int n;

long long solve(int k, long long res) {
  if (res <= 0) return 1e15;
  vector<pair<int, int> > next;
  rep (i, n) if (!used[i]) next.push_back(make_pair(c[k][i], i));
  if (next.size() == 0u) return 0;
  sort(next.begin(), next.end());
  rep (i, next.size()) {
    used[next[i].second] = true;
    res = min(solve(next[i].second, res - next[i].first) + next[i].first, res);
    used[next[i].second] = false;
  }
  return res;
}

int main() {
  cin >> n;
  rep (i, n) rep (j, n) cin >> c[i][j];
  long long res = 0;
  rep (i, n) rep (j, i) {
    long long m = min(c[i][j], c[j][i]);
    res += m;
    c[i][j] -= m;
    c[j][i] -= m;
  }
  cout << solve(100, 1e15) + res << endl;
  return 0;
}

Measured memory_bytes: 1344
package main

import (
	"fmt"
	"log"
	"math"
)

func main() {
	log.SetFlags(log.Lshortfile)
	var N int
	fmt.Scan(&N)
	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&d[i])
	}
	var ans int
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			ans += d[i] * d[j]
		}
	}
	fmt.Println(ans)
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;

int Set[200200];

int Find(int a) {
    if (Set[a] == a) return a;
    return Set[a] = Find(Set[a]);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n,m; cin>>n>>m;
    for (int i=1; i<=n; i++) Set[i] = i;
    while (m--) {
        int a,b; cin>>a>>b;
        a=Find(a), b=Find(b);
        if (a!=b) Set[a] = b;
    }
    map <int, int> mp;
    int res = ++mp[Find(1)];
    for (int i=2; i<=n; i++) res = max(res, ++mp[Find(i)]);
    cout << res;
    return 0;
}

Measured memory_bytes: 17668
#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;


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}


struct UnionFind{
  Int num;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int n):num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    num--;
  }
  Int size(Int x){
    return r[find(x)];
  }
  Int count() const{
    return num;
  }
};


//INSERT ABOVE HERE
signed main(){
  Int n,m,q;
  cin>>n>>m>>q;

  vector<Int> as(q),bs(q),cs(q);
  for(Int i=0;i<q;i++) cin>>as[i]>>bs[i]>>cs[i];

  if(m==n-1){
    if(*max_element(cs.begin(),cs.end())==1) drop("No");
    drop("Yes");
  }

  UnionFind uf(n);
  for(Int i=0;i<q;i++){
    if(cs[i]!=0) continue;
    uf.unite(as[i],bs[i]);
  }

  for(Int i=0;i<q;i++){
    if(cs[i]!=1) continue;
    if(uf.same(as[i],bs[i])) drop("No");
  }

  Int k=uf.count();
  if(m<=n+k*(k-3)/2) drop("Yes");
  drop("No");
  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    string s;
    ll a = 0;
    cin >> s;
    rep(i,s.size()){
        a += s[i] - '0';
    }
    //cout << a << endl;
    if(a%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3720
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   int n;
   cin>>n;
   int cnt=0;
   for(int i=1;i<=n; ++i){
   	int temp;cin>>temp;
   	if(i&1 && temp&1) cnt++;
   }
   cout<<cnt;
   


}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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 modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  cout << N * (N+1) / 2 << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    ll a, b, x; scll(a), scll(b), scll(x);
    ll cnt = b/x - a/x;
    if (a % x == 0) cnt += 1;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
   int  n,l;
   int a[200];
   int main()
   {
   while(scanf("%d%d",&n,&l)!=EOF)
      {
      for(int i=0;i<n;i++)
	     {
	     a[i]=i+l;	
		 }
	  sort(a,a+n);
	  int t=0,b=0;
	  for(int i=0;i<n;i++)
	     {
	     if(a[i]==0)
	     t++;
	     else if(a[i]>0)
	     b++;
	     }
	  int sum=0;   
	  for(int i=0;i<n;i++)
	      sum+=a[i];   
	  if(t>0)
	     sum-=0;
	  else if(b==0)
	       sum-=a[n-1];   
	  else if(b==n)
	        sum-=a[0];
	  else if(b<n)
	        {
	        if(n%2!=0)
			sum-=a[n/2];
			else if(a[n/2]>0&&a[n/2+1]>0)
			     sum-=a[n/2];
			else if(a[n/2]<0&&a[n/2+1]>0)
			     {
			     if(a[n/2]*a[n/2]>a[n/2+1]*a[n/2+1])
				 sum-=a[n/2+1];
				 else
				 sum-=a[n/2];	
			     }
            else if(a[n/2]<0&&a[n/2+1]<0)
	             sum-=a[n/2+1];
			}
	  printf("%d\n",sum);      
	  }    
   }
	    	
   

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define N 4003 
#include<set>
#define ll long long
using namespace std;
ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar(); 
	}
	return f*x; 
}
int n,B[N][N>>1],W[N][N>>1],reb[N],rew[N],sum;
struct node{
	int x;
	char s[2];
}a[N];
int f[N>>1][N>>1];
struct TREE{
	int tr[N];
	void add(int x)
	{
		while(x<=n)
		{
			tr[x]++;
			x+=x&-x;
		}
	}
	int query(int x)
	{
		int ans=0;
		while(x)
		{
			ans+=tr[x];
			x-=x&-x;
		}
		return ans;
	}
}b,w;
int main()
{
//	freopen("magolor.in","r",stdin);
//	freopen("magolor.out","w",stdout);
	n=read();
	for(int i=1;i<=n*2;++i)
	{
		scanf("%s",a[i].s);a[i].x=read();
		if(a[i].s[0]=='W') rew[a[i].x]=i;
		else reb[a[i].x]=i;
		for(int j=1;j<=n;++j)
		{
			B[i][j]=B[i-1][j]+(a[i].s[0]=='B'&&a[i].x>=j);
			W[i][j]=W[i-1][j]+(a[i].s[0]=='W'&&a[i].x>=j);
		}
		if(a[i].x==1)
		{
			if(a[i].s[0]=='B')
			{
				f[0][1]=W[i][1];
			//	cout<<f[0][1]<<"*"<<endl;
			}
			else
			{
				f[1][0]=B[i][1];
			//	cout<<f[1][0]<<endl;
			}
		}
	}
	for(int i=2*n;i>=1;--i)
	{
		if(a[i].s[0]=='W')
		{
			sum+=w.query(a[i].x);
			w.add(a[i].x);
		}
		else 
		{
			sum+=b.query(a[i].x);
			b.add(a[i].x);
		}
	}
	for(int i=2;i<=n;++i)
	{
		f[i][0]=f[i-1][0]+B[rew[i]][1];
		f[0][i]=f[0][i-1]+W[reb[i]][1];
	}
	for(int i=1;i<=n;++i)	
		for(int j=1;j<=n;++j)
		{
			f[i][j]=1e9;
			f[i][j]=min(f[i][j],f[i-1][j]+B[rew[i]][j+1]);
			f[i][j]=min(f[i][j],f[i][j-1]+W[reb[j]][i+1]);
		//	cout<<i<<" "<<j<<" "<<f[i][j]<<endl;
		}
	printf("%d",f[n][n]+sum);
	return 0;
}

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

#define REP(A, H) for(int A = 0; A < H; A++)
#define REP1(A, H) for(int A = 1; A < H; A++)
#define ALL(c) c.begin(), c.end()
#define SHOWL(c) std::cout << c << std::endl
#define SHOW(c) std::cout << c
#define CIN std::cin 

typedef long long ll;

int main(void) {
  int H, W, h, w;
  CIN >> H >> W >> h >> w;
  SHOWL(H * W - W * h - H * w + h * w);
  return 0;
}

Measured memory_bytes: 256
from collections import deque

R=lambda: map(int, input().split())

n, m = R()
g = [[] for _ in range(n)]
for _ in range(m):
  u, v = R()
  g[u - 1].append(v - 1)
  g[v - 1].append(u - 1)

r = ['Yes'] + [None] * (n - 1)
V = [True] + [False] * (n - 1)
q = deque([0])
while q:
  u = q.popleft()
  for v in g[u]:
    if not V[v]:
      V[v] = True
      r[v] = u + 1
      q.append(v)

print(*(['No'], r)[all(r)], sep='\n')


Measured memory_bytes: 39992
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	cin >> H >> W;
	vector<vector<int>>v(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> v[i][j];
		}
	}
	int ans = MOD;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int box = 0;
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < W; l++) {
					box += min(abs(k - i), abs(l - j))*v[k][l];
				}
			}
			ans = min(ans, box);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3212
# https://atcoder.jp/contests/abc137/tasks/abc137_e

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(1000000)

def main():
    n, m, p = map(int, input().split())
    edges = []
    graph = defaultdict(list)
    rev_graph = defaultdict(list)

    for _ in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        c = -(c - p)
        edges.append((a, b, c))
        graph[a].append(b)
        rev_graph[b].append(a)

    # pick up nodes on goal path
    reachable_from_start = [False] * n

    # print(edges)
    def dfs(node):
        if reachable_from_start[node]:
            return
        reachable_from_start[node] = True
        for next_node in graph[node]:
            dfs(next_node)

    reachable_to_end = [False] * n

    def rdfs(node):
        if reachable_to_end[node]:
            return
        reachable_to_end[node] = True
        for next_node in rev_graph[node]:
            rdfs(next_node)

    dfs(0)
    rdfs(n-1)

    valid = [False] * n
    for i in range(n):
        valid[i] = reachable_from_start[i] and reachable_to_end[i]

    inf = 10**10
    scores = [inf] * n
    scores[0] = 0
    loop = 0

    # bellman-ford
    updated = True
    while updated:
        updated = False
        for i in range(m):
            a, b, c = edges[i]
            if not valid[a]:
                continue
            if not valid[b]:
                continue

            new_cost = scores[a] + c
            if new_cost < scores[b]:
                updated = True
                scores[b] = new_cost

        loop += 1
        if loop > n:
            print(-1)
            return

    print(max(0, -scores[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 66520
import collections
N, M = map(int, input().split(" "))
A = dict(collections.Counter([k for k in input().split(" ")]))

for m in range(M):
    b, c = input().split(" ")
    b, c = int(b), str(c)
    try:
        A[c] = A[c] + b
    except:
        A[c] = b

A = [(int(k), v) for k, v in zip(list(map(int, (A.keys()))), list(map(int, (A.values()))))]
A =dict(A)

A = sorted(A.items(), key=lambda x:x[0])

ans = 0
cards_num = 0
while True:
    if cards_num == N:
        break
    cards = A.pop()
    if cards_num + cards[1] > N:
        n = N - cards_num
        ans += int(cards[0])*n
        cards_num += n
    else:
        ans += int(cards[0])*cards[1]
        cards_num += cards[1]

print(ans)




Measured memory_bytes: 60376
num = int(input())
result =list()
illusts = ['S','H','C','D']

while True:
    try:
        a,b = input().split(' ')
        b = int(b)
        if a == 'S': result.append(b)
        elif a == 'H':result.append(b + 13)
        elif a == 'C': result.append(b + 26)
        else : result.append(b + 39)
    except EOFError:
        break

box = 0
for illust in illusts:
    for i in range(1,14):
        if i + box not in result:
            print(illust, i)
    box += 13


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll a[125252], b[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%lld%lld",a+i,b+i);
  ll ans = 1ll<<60;
  CHMIN(ans, accumulate(a,a+n,0ll));
  CHMIN(ans, accumulate(b,b+n,0ll));
  multiset<ll> S, T;
  REP(i,n){
    S.insert(a[i]);
    S.insert(b[i]);
  }
  while(S.size()>n-2){
    ll x = *S.rbegin(); S.erase(S.find(x));
    T.insert(x);
  }
  ll sm = 0;
  for(ll x : S){
    sm += x;
  }
  REP(i,n){
    ll tmp = sm + a[i] + b[i];
    bool ta = T.count(a[i])>0;
    if(ta){
      T.erase(T.find(a[i]));
    }else{
      tmp -= a[i];
    }
    bool tb = T.count(b[i])>0;
    if(tb){
      T.erase(T.find(b[i]));
    }else{
      tmp -= b[i];
    }
    int cnt = 2 - ta - tb;
    for(ll x : T){
      if(cnt==0)break;
      tmp += x; cnt--;
    }
    CHMIN(ans, tmp);
    if(tb)T.insert(b[i]);
    if(ta)T.insert(a[i]);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 11136