akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

typedef struct UnionFindTree{
  vector<int> par;
  vector<int> treerank;
  
  UnionFindTree(int n){
    par.resize(n); treerank.resize(n);
    rep(i, n) par[i] = i, treerank[i] = 0;
  }
  
  int find(int x){
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;
    if(treerank[x] < treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) treerank[x]++;
    par[y] = x;
    return;
  }
  
  bool same(int x, int y){
    return find(x) == find(y);
  }
}UF;

template<class T> struct edge{
    int from, to; T cost;
    edge(int f, int t, T c){
        from = f; to = t; cost = c;
    }
};

template<class T> struct Graph{
    vector<vector<edge<T>>> G;
    vector<edge<T>> E;
    int n;
    
    Graph(int n_){
        n = n_;
        G.resize(n);
    }
    
    void add_edge(int f, int t, T c){
        G[f].emplace_back(f, t, c);
        
    }
    
    vector<T> dijkstra(int s){
        using P = pair<T, int>;
        priority_queue<P, vector<P>, greater<P>> que;
        vector<T> d(n, numeric_limits<T>::max());
        d[s] = 0;
        que.push(P((T)0, s));
        while(!que.empty()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(edge<T> &e : G[v]){
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
        return d;
    }
    
    T kruskal(){
        rep(i, n)for(edge<T> &e : G[i]) E.push_back(e);
        sort(E.begin(), E.end(), [](const edge<T> &e1, const edge<T> &e2){return e1.cost < e2.cost;});
        UF uf(n);
        T res = 0;
        for(edge<T> &e : E){
            if(!uf.same(e.from, e.to)){
                uf.unite(e.from, e.to);
                res += e.cost;
            }
        }
        return res;
    }
};

int main(){
    int v, e; cin >> v >> e;
    Graph<int> g(v);
    rep(i, e){
        int s, t, w; cin >> s >> t >> w;
        g.add_edge(s, t, w);
    }
    cout << g.kruskal() << endl;
}


Measured memory_bytes: 6784
//By UditDesai
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define trav(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define nl cout<<'\n'
#define sp <<' '<<
#define sz(a) (int)(a.size())
#define check(x) cout << #x << " : " << (x) << endl
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl//By UditDesai
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int N=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;
 
 
int main()
{
	fastio;
	ll n,k,i,j,ans=1e18;
	cin>>n>>k;
	ll dp[n+1];
	ll h[n+1];
	h[0]=0;
	for(i=1;i<=n;i++) cin>>h[i];
	for(i=0;i<=n;i++)  dp[i] = 1e18;
	dp[1] = 0;
	for(i=2;i<=n;i++)
	{
		for(j=1;j<=k;j++)
		{
			if(i>j)
			{
				dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}

	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1792
S = list(input())

if S[0] == 'A':
    cnt = 0
    for i in range(2, len(S)-1):
        if S[i] == 'C':
            cnt += 1
    if cnt == 1:
        S.sort()
        for i in range(2, len(S)):
            if S[i].isupper():
                print('WA')
                exit()
        print('AC')
    else:
        print('WA')
else:
    print('WA')



Measured memory_bytes: 8932
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
    // Your code here!
    int n;cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    cout<<s.size()<<endl;
    
}

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

using namespace std;

int main ()

{
   vector <char> s;
   int i, hugs, y;

   while (1)
   {
       char x;
       scanf ("%c", &x);

       if (x == '\n')
        break;
       s.push_back(x);
    }

    if (s.size()%2 == 0)
        y = s.size() / 2;

    else y = s.size() / 2 +1;

   for(i=0, hugs=0; i<y; i++)
   {
       if (s[i] != s[s.size()-1-i])
        hugs++;
   }

   printf("%d", hugs);

   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a==c)cout<<1<<endl;
    else if(a==b&&a!=c)cout<<2<<endl;
    else if(a==c&&a!=b)cout<<2<<endl;
    else if(b==c&&c!=a)cout<<2<<endl;
    else cout<<3<<endl;
return 0;
}

Measured memory_bytes: 256
/**
 *      ///----- My Info -----///
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu
#include <debug/to_string.h>
#endif
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
    	///----- My Template -----///
///======================================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x); .order_of_key(x);
// using namespace __gnu_pbds;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define size(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Debug
#define _end cout << "\n"
#ifdef Ernest0_0Abreu
#define db(x) cerr << "[ "<< #x << " ]: " << to_string(x) << "\n"
#define dbrange(x,begin,end) cerr << "[ "<< #x << " ]: " << to_string(x,begin,end) << "\n"
#define dbname(x) cerr << to_string(x,#x) << "\n"
#define dbnamerange(x,begin,end) cerr << to_string(x,#x,begin,end) << "\n"
#define dbmat(x,begin_n,end_n,begin_m,end_m) cerr << to_string(x,#x,begin_n,end_n,begin_m,end_m) << "\n"
#define dbST(x,end) cerr << to_string(x,end) << "\n";
#define dbendl cerr << "\n";
#else 
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#define dbST(x,end) ;
#define dbendl ;
#endif
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 1e5+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, 1000000033;
///=======================================================================================================================================
#define int long long
		///----- My code -----///



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

	string s;
	cin >> s;
	if(s == "ABC") cout << "ARC";
	else cout << "ABC";

	return 0;
}


Measured memory_bytes: 3640
n, k = map(int, input().split())
x = list(map(int, input().split()))

for center in range(n):
    if x[center] >= 0:
        break

if center == n - 1:
    print(-1 * x[n - k])
    exit()
elif center == 0:
    print(x[k - 1])
    exit()

plus = [0] + x[center:]
minus = [0] + list(reversed(list(map(lambda i:i * -1, x[:center]))))

ans = 10 ** 10

for i in range(max(k - len(minus) + 1, 0), min(k + 1, len(plus))):
    ans = min(ans, plus[i] + minus[k - i] + min(plus[i], minus[k - i]))

print(ans)

Measured memory_bytes: 14568
#include <bits/stdc++.h>
using namespace std;
int count(int n)
{
    int c = 0;
    while (!(n % 2) && n > 0)
    {
        c++;
        n /= 2;
    }
    return c;
}

int main()
{
    int n;
    int ans = INT_MAX;
    cin >> n;
    for (int i = 0; i < n; i++){
        int curr;
        cin >> curr;
        ans = min(ans,count(curr));
    }
    cout << ans;
}

Measured memory_bytes: 3564
s;main(c){double*q=&s,b;for(;~scanf("%s%c",&s,&c);c&2&&printf("%f\n",*q))sscanf(&s,"%lf",q+1)-1?b=*q--,*q=s&1?s&2?s&4?*q/b:*q+b:*q-b:*q*b:*++q;}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	const int MAX = 101;
	int n;
	cin >> n;
	double x[MAX], y[MAX];
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n; i++)
		cin >> y[i];
	int P[4] = { 1,2,3,-1 };
	for (int k = 0; k < 4; k++)
	{
		int p = P[k];
		double dis = 0;
		if (p != -1)
		{
			for (int i = 0; i < n; i++)
				dis += pow(fabs(x[i] - y[i]), p);
			dis = pow(dis, 1 / (double)p);
			printf("%.6f\n", dis);
		}
		else
		{
			double d[MAX];
			for (int i = 0; i < n; i++)
				d[i] = fabs(x[i] - y[i]);
			double *max = max_element(d, d + n);
			printf("%.6f\n", *max);
		}
	}
}


Measured memory_bytes: 3376
n = int(input())
p = list(map(int, input().split()))
st = []
c = 0
for i in range(0,n):
    if (p[i] == i+1):
        st.append(1)
    else:
        st.append(0)
def cal(a):   
    global c    
    if (st[a]== 1 and  st[a+1]==1):
        c += 1
        return a+2
    return a+1
p=0           
while (p < n-1):
    p = cal(p)
    
y = st.count(1)
print(y-c)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main () {
#define int int_fast32_t
	io_optimized
	string x,y,s;
	int a,b;
	while(cin>>x>>y>>a>>b>>s)
	{
		if(x==s)
		{
			cout<<a-1<<" "<<b<<"\n";
		}
		else if(y==s)
		{
			cout<<a<<" "<<b-1<<"\n";
		}
	}

	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(1000000000)


a, b, k = map(int, input().split())

if a >= k:
    a = a - k
    print("{} {}".format(a, b))
elif k > a and a + b >= k:
    b = a + b - k
    print("{} {}".format(0, b))
else:
    print("{} {}".format(0, 0))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
/*<almost-copy-pasted-part>*/
#define ios ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0)
#define int long long
#define ccon continue
#define E exit(0)
#define B break
#define F first
#define S second

#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define ins insert
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define whole(x) x + 1, x + n + 1

#define TRUE

using namespace std;

const int MyIQ = 1e18 * 0 - 7;
const int E3 = 1e3 + 7;
const int E4 = 1e4 + 7;
const int E5 = 1e5 + 7;
const int E6 = 1e6 + 7;
const int E7 = 1e7 + 7;
const int E8 = 1e8 + 7;
const int E9 = 1e9 + 7;
const int E12 = 1e12 + 7;
const int INF = 1e18 + 7;

int n, a[2*E5];
vector<pair<int,int>>v;

template <typename TN>
class exlxtxbxdx {	
		public:
		void done() {
			cin >> n;
			for (int i = 1; i <= n; i++) {
				cin >> a[i];
				v.pb({a[i],i});
			}
			sort(all(v));
			for (int i = 1; i <= n; i++) {
				if (i != v[sz(v)-1].S) {
					cout << v[sz(v)-1].F << "\n";
					ccon; 
				}
				else {
					cout << v[sz(v)-2].F << "\n";
				}
			}
		}	
};		

main () {
#ifdef FALSE
	freopen (".in", "r", stdin);
	freopen (".out", "w", stdout);
#endif
	ios;
	exlxtxbxdx <int> well;
	well.done();
	return false;
}

Measured memory_bytes: 7408
N, A, B = map(int,input().split())

count = 0

for i in range(N+1):
    i10000 = i // 10000
    i1000 = (i-i10000*10000) // 1000
    i100 = (i-i10000*10000-i1000*1000) // 100
    i10 = (i-i10000*10000-i1000*1000-i100*100) // 10
    i1 = (i-i10000*10000-i1000*1000-i100*100-i10*10) // 1

    isum = i10000 + i1000 + i100 + i10 + i1

    if A <= isum <= B:
        count += i

print(count)


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define mp make_pair
int x[100005],y[100005];
int a[100005],b[1000005];
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<k;i++) scanf("%d%d",&x[i],&y[i]);
	for(int i=0;i<k;i++) a[i]=x[i],b[i]=y[i];
	sort(a,a+k); sort(b,b+k);
	ll ret=1e15; int rx,ry;
	for(int i=(k-1)/2;i<=(k+1)/2;i++)
	{
		for(int j=(k-1)/2;j<=(k+1)/2;j++)
		{
			ll sum=0LL,gen=0LL;
			for(int s=0;s<k;s++)
			{
				sum+=2LL*(abs(x[s]-a[i])+abs(y[s]-b[j]));
				gen=max(gen,1LL*(abs(x[s]-a[i])+abs(y[s]-b[j])));
			}
			if(sum-gen<ret){ rx=a[i]; ry=b[j]; ret=sum-gen;}
			else if(sum-gen==ret && mp(rx,ry)>mp(a[i],b[j])) rx=a[i],ry=b[j];
		}
	}
	printf("%lld\n%d %d\n",ret,rx,ry);
}

Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    string s;cin>>s;
    if(s[1]=='R')cout<<"ABC";
    else cout<<"ARC";
 
return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

int exp_mod(long long a, long long b, int m) {
	long long res = 1;
	while (b > 0) {
		if (b&1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}
	return (int)res;
}

int fact_mod(int n, int m) {
	long long res = 1;
	for (int i=n; i>0; --i)
		res = (res * i)%m;
	return (int)res;
}

int comb_mod(int n, int r) {
	long long res = 1;
	for (int i=0; i<r; ++i)
		res = (res * (n - i) )%MOD;
	return ( res * exp_mod(fact_mod(r, MOD), MOD-2, MOD) ) % MOD;
}

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

  long n, m;

  cin >> n >> m;

  cout << ((n*3)+m)/2 << endl;
  
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,n) for(ll i=0;i<n;i++)
#define nforn(i,n) for(ll i=n-1;i>=0;i--)
#define forne(i,n) for(ll i=1;i<=n;i++)
#define forse(i,s,e) for(ll i=s;i<e;i++)
#define all(v) v.begin(),v.end()
#define MOD 1000000007
#define d1(x) cerr <<"> "<<#x<<" = "<<x<<'\n'
#define d2(x, y) cerr <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<'\n'
#define d3(x, y, z) cerr <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<' '<<#z<<" = "<<z<<'\n'
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
	// cin>>t;
	while(t--){
		ll a,h;
		cin>>h>>a;
		cout<<(h+a-1)/a<<"\n";
	}
}

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

using namespace std;

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

const ll mod = 1000000007;

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

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

  x--;
  y--;

  vector<int> ans(n-1);
  for (int i = 0; i < n-1; i++) {
    vector<int> dist(n);
    vector<bool> visited(n);
    queue<Pii> que;
    que.emplace(i, 0);
    while (!que.empty()) {
      auto now = que.front();
      que.pop();
      if (visited[now.first]) continue;
      visited[now.first] = true;
      dist[now.first] = now.second;
      if (now.first > 0) {
        if (!visited[now.first-1]) que.emplace(now.first-1, now.second+1);
      }
      if (now.first < n-1) {
        if (!visited[now.first+1]) que.emplace(now.first+1, now.second+1);
      }
      if (now.first == x) {
        if (!visited[y]) que.emplace(y, now.second+1);
      }
      if (now.first == y) {
        if (!visited[x]) que.emplace(x, now.second+1);
      }
    }
    for (int j = i; j < n; j++) {
      if (dist[j] > 0) ans[dist[j]-1]++;
    }
  }

  for (auto &z: ans) cout << z << endl;

  return 0;
}


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

int main()
{
  int N, x;
  cin>>N ;
  int elm[N] ;
  for(int m=0; m<N; m++)
  { cin>>elm[m] ;
  }
  sort(elm, elm+N) ;
  for(int i=0; i<N; i++)
    { x=elm[i]-elm[i+1] ;
      if(x==0)
      { cout<<"NO" ;
        goto abc ;
      }
      else
      {continue ;
      }
  }
  cout<<"YES" ;
  abc: 
  return 0 ;
}


Measured memory_bytes: 1024
field = [[int(i) for i in input().split()] for j in range(3)]
N = int(input())
b_list = [int(input()) for n in range(N)]
bingo = False

for dan, row in enumerate(field):
    for suji, masu in enumerate(row):
        for b in b_list:
            if b == masu:
                field[dan][suji] = 0

for dan in field:
    if dan == [0, 0, 0]:
        bingo = True

hantei_list = []
i = 0
for dan in field:
    hantei_list.append(dan[i])
    i += 1
if hantei_list == [0, 0, 0]:
    bingo = True

hantei_list = []
i = 2
for dan in field:
    hantei_list.append(dan[i])
    i -= 1
if hantei_list == [0, 0, 0]:
    bingo = True

hantei_list = []
for dan in field:
    hantei_list.append(dan[0])
if hantei_list == [0, 0, 0]:
    bingo = True

hantei_list = []
for dan in field:
    hantei_list.append(dan[1])
if hantei_list == [0, 0, 0]:
    bingo = True

hantei_list = []
for dan in field:
    hantei_list.append(dan[2])
if hantei_list == [0, 0, 0]:
    bingo = True

if bingo == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N, M, Q = map(int, input().split())
ABCD = [[int(x) for x in input().split()] for _ in range(Q)]


def dfs(A):
    if len(A)==N:
        return calc(A)
    
    res = 0
    s = A[-1] if len(A)>0 else 1
    for i in range(s, M+1):
        A.append(i)
        res = max(res, dfs(A))
        A.pop()
    return res
        
    
def calc(A):
    score = 0
    for a,b,c,d in ABCD:
        if A[b-1] - A[a-1] == c:
            score += d
    return score


ans = dfs([])
print(ans)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  while (cin >> s) {
    if (s == "-")
      break;
    int n;
    cin >> n;
    int h;
    rep(i, 0, n) {
      cin >> h;
      s = s.substr(h) + s.substr(0, h);
    }
    cout << s << endl;
  }
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}

int p[N];
int get(int v){
	return v == p[v] ? v : p[v] = get(p[v]);
}
void solve()
{
	int n;
	cin >> n;
	vector<pii> x(n), y(n);
	set<pair<int, pii> > px, py;
	rep(i, n) p[i] = i;
	rep(i, n){
		cin >> x[i].F >> y[i].F;
		x[i].S = y[i].S = i;
	}
	sort(all(x));
	sort(all(y));
	rep(i, n){
		if(i){
			px.insert({x[i].F - x[i - 1].F, {x[i].S, x[i - 1].S}});
			py.insert({y[i].F - y[i - 1].F, {y[i].S, y[i - 1].S}});
		}
	}
	ll res = 0;
	while(!px.empty() && !py.empty()){
		pair<int, pii> u = *px.begin();
		pair<int, pii> v = *py.begin();
		if(u.F <= v.F){
			res += 1ll * u.F;
			int x = get(u.S.F), y = get(u.S.S);
			p[y] = x;
			px.erase(px.begin());
		}
		else{
			res += 1ll * v.F;
			int x = get(v.S.F), y = get(v.S.S);
			p[y] = x;
			py.erase(py.begin());	
		}
		while(!px.empty()){
			pair<int, pii> x = *px.begin();
			if(get(x.S.F) == get(x.S.S)) px.erase(px.begin());
			else break;
		}
		while(!py.empty()){
			pair<int, pii> x = *py.begin();
			if(get(x.S.F) == get(x.S.S)) py.erase(py.begin());
			else break;
		}
	}
	cout << res;


}	 

 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 19252
#include <stdio.h>

void trace(int A[], int N) {
    int i;
    for(i = 0; i < N; i++ ){
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N) {
    int j,i,v;
    for (i = 1; i < N; i++) {
        v = A[i];
        j = i -1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
    }
}

int main() {
    int N, i, j;
    int A[100];

    scanf("%d", &N);
    for (i = 0; i < N; i++) scanf("%d", &A[i]);

    trace(A,N);
    insertionSort(A,N);

    return 0;
}


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

int main(void){
    int N;
    cin >> N;
    std::vector<string> v;
    string s;
    rep(i,N){
        cin>>s;
        v.push_back(s);
    }
    std::sort(v.begin(),v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());
    cout<<v.size();
    return 0;
}

Measured memory_bytes: 11664
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    char b;
    cin >> b;
    if(b == 'A') {
        cout << 'T';
    } else if (b == 'T') {
        cout << 'A';
    } else if (b == 'C') {
        cout << 'G';
    } else if (b == 'G') {
        cout << 'C';
    }
    return 0;
}

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

int n;

typedef long long ll;

struct matrix{
    ll mat[55][55];
};

matrix jedan;

const ll MOD = 1000000007;

ll add(ll a, ll b){
    return (a+b)%MOD;
}

ll mul(ll a, ll b){
    return ((ll)a*b)%MOD;
}

matrix komb(matrix a, matrix b){
    matrix res;
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=n; j++){
            for(ll k=1; k<=n; k++){
                res.mat[i][j] = add(res.mat[i][j], mul(a.mat[i][k], b.mat[k][j]));
            }
        }
    }
    return res;
}

matrix pwmat(matrix a, ll b){
    if(b == 1) return a;
    matrix res = pwmat(a, b/2);
    res = komb(res, res);
    if(b%2) res = komb(res, jedan);
    return res;
}

int main(){

    cin >> n;
    ll k;
    cin >> k;
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=n; j++){
            cin >> jedan.mat[i][j];
        }
    }
    matrix res = pwmat(jedan, k);
    ll sum = 0;
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=n; j++){
            sum = add(sum, res.mat[i][j]);
        }
    }
    cout << sum;
    return 0;
}


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

int64_t gcd(int64_t a, int64_t b){
    if (a < b){
        int tmp = a;
        a = b;
        b = tmp;
    }

    int r = a % b;
    while (r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int64_t lcm(int64_t a, int64_t b){
    return a * b / gcd(a, b);
}

int main() {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int64_t num_c, num_cl, num_ch;
    int64_t num_d, num_dl, num_dh;
    int64_t num_cd,num_cdl,num_cdh;

    num_cl = (a + c - 1) / c;
    num_ch = b / c;
    num_c = num_ch - num_cl + 1;

    num_dl = (a + d - 1) / d;
    num_dh = b / d;
    num_d = num_dh - num_dl + 1;

    int64_t cd = lcm(c, d);
    num_cdl = (a + cd - 1) / cd;
    num_cdh = b / cd;
    num_cd = num_cdh - num_cdl + 1;

	cout << b - a + 1 - num_c - num_d + num_cd << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H,W = map(int,input().split())
N = int(input())
a = [int(i) for i in input().split()]

grid = [list([None for i in range(W)]) for i in range(H)]

x = 0
y = 0
i = 0

d = 1
while i<N:
    grid[y][x] = i+1
    a[i]-=1
    if a[i]==0:
        i+=1

    x+=d
    
    if x==W:
        x-=1
        y+=1
        d= -1
        
    if x==-1:
        x+=1
        y+=1
        d = 1

for r in grid:
    print(" ".join([str(i) for i in r]))


Measured memory_bytes: 3572
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur//=j

def num(m):
    return len(list(filter(lambda x: x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 38512
#define DigLim  1000000000
#include<stdio.h>

int main(){
    short A[100][100] = {0}, B[100][100] = {0};
    int c[2]={0};
    int n, m, l, i, j, k, t, s;
    scanf("%d %d %d", &n, &m, &l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d", &(A[i][j]));
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d", &(B[i][j]));
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            c[1] = c[0] = 0;
            for(k=0;k<m;k++){
                t = A[i][k]*B[k][j];
                if(c[0]+t>=DigLim){
                    c[0] += t - DigLim;
                    c[1]++;
                }
                else c[0]+=t;
            }
            if(c[1]>0){
                printf("%d", c[1]);
                t=c[0];
                for(s=1;t/10>0;s++)t/=10;
                for(t=0;t<9-s;t++)putchar('0');
            }
            printf("%d", c[0]);
            putchar((j<l-1)?' ':'\n');
        }
        //printf("\n");
    }
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if((s[0] == s[1] && s[2] == s[3]) && (s[1] != s[2])) cout << "Yes" << endl;
  else cout << "No" << 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 n, k, x[], ans = 0;
		n = sc.nextInt();
		k = sc.nextInt();
		x = new int[n];
		for(int i = 0; i < n; ++i) {
			x[i] = sc.nextInt();
			int tmp = Math.abs(k - x[i]);
			ans += 2 * Math.min(x[i],  tmp);
		}
		sc.close();
		System.out.println(ans);
	}

}


Measured memory_bytes: 22484
import Data.List
import qualified Data.Map as M

main :: IO ()
main = do
    _ <- getLine
    ss <- lines <$> getContents
    putStrLn . solve $ ss

count :: String -> M.Map Char Int
count = foldl' (\acc cs -> M.insert (head cs) (length cs) acc) base
        . group . sort
    where
        base = M.fromList $ zip ['a'..'z'] (repeat 0)

render :: M.Map Char Int -> String
render = M.foldrWithKey (\k v a -> (replicate v k) ++ a) "" 

solve :: [String] -> String
solve = render . M.unionsWith min . map count


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
    IOS;
    int n,m;
    cin >> n >> m;
    rep(i,0,m){
        int x;
        cin >> x;
        n-=x;
    }
    if(n>=0) cout << n << "\n";
    else cout << "-1\n";
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> railway(n);
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    railway[l].push_back(r);
  }
  for (auto& v : railway)
    sort(begin(v), end(v));
  for (int i = 0; i < q; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    int total = 0;
    for (int j = p; j <= q; j++)
      total += upper_bound(begin(railway[j]), end(railway[j]), q) - begin(railway[j]);
    cout << total << endl;
  }
}


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

int INF = 1001001001;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    vector<int> Y(100, INF);
    vector<int> T(100);


    int ycnt = 0;
    int tcnt = 0;
    rep(i, N){
        if(i == N-1){
            if(A[i] > Y[ycnt]){
                T[tcnt] = A[i];
            }
            continue;
        }

        if(A[i] < A[i+1]){
            Y[ycnt] = min(Y[ycnt], A[i]);
        } else if(A[i] > A[i+1] && A[i] > Y[ycnt]){
            T[tcnt] = A[i];
            ycnt++;
            tcnt++;
        }
    }



    ll now = 1000;
    ll kabu = 0;
    int yn = 0;
    int tn = 0;
    while(T[tn] != 0 && Y[yn] != INF){
        ll kau = now / Y[yn];
        kabu += kau;
        now -= Y[yn] * kau;

        now += T[tn] * kabu;
        kabu = 0;
        tn++;
        yn++;
    }

    /*rep(i, 10){
        cout << i << " " << Y[i] << " " << T[i] << endl;
    }*/

    cout << now << endl;


    return 0;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> d(n);
	rep(i,k){
		int m;
		cin >> m;
		rep(j,m){
			int a;
			cin >> a;
			d[a-1] = 1;
		}
	}
	int ans = 0;
	rep(i,n)if(d[i] == 0)ans++;
	cout << ans << endl;
	return 0;
}





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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  
  long int answer = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H.at(i) >= H.at(i + 1)) {
      answer += H.at(i) - H.at(i + 1);
      H.at(i + 1) = H.at(i);
    }
    else if (H.at(i) < H.at(i + 1)) {
      continue;
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 3996
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int k;
  const int a[32]={1, 1, 1, 2, 1, 
                   2, 1, 5, 2, 2, 
                   1, 5, 1, 2, 1, 
                   14, 1, 5, 1, 5, 
                   2, 2, 1, 15, 2, 
                   2, 5, 4, 1, 4, 
                   1, 51};
  
  cin >> k;
  
  cout << a[k-1] << endl;
  
  return 0;
}

Measured memory_bytes: 256
// AOJ 1208: Rational Irrationals
// 2017.10.14 bal4u@uu

#include <stdio.h>

int n, p;
long long x, y, u, v;

void SternBrocot(long long pl, long long ql, long long pr, long long qr)
{
	long long pm, qm;

	pm = pl + pr, qm = ql + qr;
    if (pm > n || qm > n) return;
    if (p * qm * qm < pm * pm) {
        x = pm, y = qm;
        SternBrocot(pl, ql, pm, qm);
    } else if (p * qm * qm > pm * pm) {
        u = pm, v = qm;
        SternBrocot(pm, qm, pr, qr);
    } else x = u = pm, y = v = qm;
}

int main()
{
	while (scanf("%d%d", &p, &n) && p > 0) {
        SternBrocot(0, 1, 1, 0);
        printf("%lld/%lld %lld/%lld\n", x, y, u, v);
    }
    return 0;
}

Measured memory_bytes: 1712
from heapq import heapify, heappop, heappush
N,M = map(int, input().split())
AB = []
for i in range(N):
    a,b = map(int, input().split())
    if a<=M:
        AB.append((a,-b))
    else:
        N-=1
AB.sort()

Q = []
heapify(Q)
ans = 0
i = 0

for day in range(M):
    while i<N and AB[i][0] == day+1:
        heappush(Q, AB[i][1])
        i+=1
    if Q:
        ans -= heappop(Q)
print(ans)

Measured memory_bytes: 17664
#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;

#define MIN(a,b) ((a)<(b)?(a):(b))


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> res(n,0);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		res[a-1]++;
		res[b-1]++;
	}
	for (auto& i : res) {
		cout << i << endl;
	}
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int p, q;
        cin >> p >> q;
        char res = 'P';
        for (int m = 0; m < 200; ++m) {
            for (int n = 0; n < 200; ++n) {
                int den = m * m + n * n;
                if (den <= 1 || (n * q + m * p) % den != 0 || (m * q - n * p) % den != 0) continue;
                int x = (n * q + m * p) / den;
                int y = (m * q - n * p) / den;
                if (x * x + y * y <= 1) continue;
                res = 'C';
                break;
            }
            if (res == 'C') break;
        }
        cout << res << endl;
    }
    return 0;
}


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


typedef struct Node{
  int key;
 struct Node *next,*prev;
}Node;

Node *nil;

Node* listSearch(int key){
  Node *c = nil->next;
  while(c->key!=key){
    if(c==nil) break;
    c = c->next;
  }
  return c;
}

void printList(){
 struct Node *c = nil->next;
  int isf =1;
  while(1){
    if(c==nil) break;
    if(isf==0) printf(" ");
    printf("%d",c->key);
    c = c->next;
    isf =0;
  }
  printf("\n");
}

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev =nil;
}

void deleteNode(struct Node *t){
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  struct Node *t = nil->next;
  if(t==nil) return;
  deleteNode(t);
}

void deleteLast(){
  struct Node *t = nil->prev;
  if(t==nil) return;
  deleteNode(t);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x;
x = malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int i,n,key;
  int size =0;
  char A[20];
  int np =0,nd =0;
    scanf("%d",&n);
    init();
    for(i=0;i<n;i++){
      scanf("%s%d",A,&key);
      if(A[0]=='i'){
	insert(key);
	np++;
	size++;
      }
      else if(A[0]=='d'){
	if(strlen(A)>6){
       if(A[6]=='F') deleteFirst();
       else if(A[6]=='L') deleteLast();
	}
	else{
	  deleteKey(key);
	  nd++;
	}
	size--;
      }
    }

    printList();

    return 0;
}

Measured memory_bytes: 31788
#include <bits/stdc++.h>
#define MAX 11000
#define ll long int
using namespace std;
 
 
int main() {
 
	map<string,int> mp;
	string s ;
	ll i,j,n,count=0,sum=0;
	
	cin >> n;
	
	for(i=0;i<n;i++)
	{
		cin >> s;
		sort(s.rbegin(), s.rend(), greater<char>());
		count += mp[s]++;
	
	}
	
	cout << count;


	
 
}

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

int main() {
  
  long long A;
  string str;
  cin >> A >> str;
  long long B = 0;
  for(char ch : str){
    if(ch != '.'){
      B += (ch - '0');
      B *= 10;
    }
   }
   B /= 10;
      
  long long ans = A*B / 100;
  printf("%lld\n",ans);
  return 0;

}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
  
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
  
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
 
typedef long long int64;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;

int get_dist(int x1, int y1, int x2, int y2){ //(x1, y1)の方が(x2, y2)より大きいこと
  return max(x1 - x2, y1 - y2);
}
int main()
{
  int N;
  scanf("%d", &N);
  vector< int > x(N), y(N);

  // (x1,y1) と(x2,y2)のマンハッタン距離
  // |x1 - x2| + |y1 - y2|

  // 以下の中の最大値
  // -(x1 - y1) - (x2 + y2)
  // -(x1 + y1) + (x2 + y2)
  // (x1 + y1) - (x2 + y2)
  // (x1 - y1) + (x2 + y2)

  // (x - y) と (x + y)

  for(int i = 0; i < N; i++){
    int a, b;
    scanf("%d %d", &a, &b);
    x[i] = a - b, y[i] = a + b;
  }
  int xlow = *min_element(ALL(x)), xhigh = *max_element(ALL(x));
  int ylow = *min_element(ALL(y)), yhigh = *max_element(ALL(y));
  int ret = 0, res = 0;
  for(int i = 0; i < N; i++){
    ret = max( ret, min( get_dist( x[i], y[i], xlow, ylow), get_dist( xhigh, yhigh, x[i], y[i])));
  }
  for(int i = 0; i < N; i++){
    res = max( res, min( get_dist( x[i], yhigh, xlow, y[i]), get_dist( xhigh, y[i], x[i], ylow)));
  }
  printf("%d\n", min(ret, res));
}

Measured memory_bytes: 1792
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<i32> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0] as usize;
    let a = line[1];
    let mut xs: Vec<i32> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    for i in 0..n {
        xs[i] -= a;
    }

    let mut memo = HashMap::new();
    memo.insert(0, 1u64);

    for i in 0..n {
        let tmp = memo.clone();
        for (&key, &val) in tmp.iter() {
            let y = memo.get(&(key + xs[i])).unwrap_or(&0) + val;
            memo.insert(key + xs[i], y);
        }

    }

    println!("{}", memo.get(&0).unwrap() - 1);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>

#define MAX 1000000

int main(void)
{
  int n;
  int b[MAX] = {0};
  int count;
  int i, j;

  // ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
  b[0] = 1;
  b[1] = 1;
  for(i=4; i<=MAX; i+=2)
    {
      b[i] = 1;
    }
  for(i=3; i<=sqrt(MAX); i+=2)
    {
      for(j=i+i; j<=MAX; j+=i)
	{
	  b[j] = 1;
	}
    }

  while(scanf("%d", &n)!=EOF)
    {
      count = 0;
      for(i=2; i<=n; i++)
	{
	  if(b[i]==0)
	      count ++;
	}
      printf("%d\n", count);
    }

  return 0;
}

Measured memory_bytes: 0
import numpy as np
n,l=map(int,input().split())
a=list(map(int,input().split()))
flag=False;idx=0
for i in range(n-1):
  if a[i]+a[i+1]>=l:
    flag=True
    idx=i
if not flag:
  print("Impossible")
  exit(0)
print("Possible")
for x in range(idx):
  print(x+1)
for x in reversed(range(idx,n-1)):
  print(x+1)


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

using namespace std;

typedef long long ll;
typedef double db;

#define dbg(x) cout<<#x<<" is "<<x<<endl

const int maxn = 5e5 + 9;

int ql[maxn], qr[maxn];
int ord[maxn];
int aaa[maxn];
int c[maxn];
int arr[maxn];
int n, q;

inline int cmp(int a, int b) {
    if (qr[a] != qr[b])return qr[a] < qr[b];
    return ql[a] < ql[b];
}

inline int lowbit(int x) {
    return (-x) & x;
}

inline void add(int p, int a) {
    for (int i = p; i <= n; i += lowbit(i)) {
        arr[i] += a;
    }
}

inline int sum(int p) {
    int ans = 0;
    for (int i = p; i > 0; i -= lowbit(i)) {
        ans += arr[i];
    }
    return ans;
}

inline int read() {
    int x = 0, f = 1;
    char ch;
    while (ch < '0' || ch > '9') {
        if (ch == '-')f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return f * x;
}

inline void init() {
//    scanf("%d%d", &n, &q);
    n = read();
    q = read();
    for (int i = 1; i <= n; i++) {
//        scanf("%d", c + i);
        c[i] = read();
    }
    for (int i = 0; i < q; i++) {
        ord[i] = i;
        ql[i] = read();
        qr[i] = read();
//        scanf("%d%d", ql + i, qr + i);
    }
    sort(ord, ord + q, cmp);
}

int pre[maxn];

int main() {
    init();
//    pt2();
    int nr = 0;
    memset(pre, -1, sizeof(pre));
    for (int i = 0; i < q; i++) {
        int t = ord[i];
        for (int j = nr + 1; j <= qr[t]; j++) {
            if (pre[c[j]] != -1) {
                add(pre[c[j]], -1);
            }
            pre[c[j]] = j;
            add(j, 1);
        }
        nr = qr[t];
//        dbg(i);
//        dbg(t);
//        pt();
        int tmp = sum(qr[t]);
        if (ql[t] != 1) {
            tmp -= sum(ql[t] - 1);
        }
        aaa[t] = tmp;
    }
    for (int i = 0; i < q; i++) {
        printf("%d\n", aaa[i]);
    }
    return 0;
}

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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n,k;
int a[110];

int cache[N];

int dp(int cur){
    int &ans=cache[cur];
    if(ans!=-1) return ans;
    ans=0;
    for(int i=1; i<=n; i++){
        if(cur-a[i]<0) break;
        ans|=(dp(cur-a[i])==0);
    }
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    rep(i,1,n+1) cin >> a[i];
    mst(cache,-1);
    if(dp(k)) cout << "First";
    else cout << "Second";
    return 0;
}


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

int read()
{
	int ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10+ch-'0';
	if(flag)ans=-ans;
	return ans;
}

long long rell()
{
	long long ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10ll+(long long)(ch-'0');
	if(flag)ans=-ans;
	return ans;
}

void writ(int n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}

void writ(long long n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}
const int N=1<<20;
int f[N];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	memset(f,0,sizeof(f));
	f[1]=1;f[n]=2;
	bool flag=false;
	for(int i=0;i<m;i++)
	{
		int u=read(),v=read();
		if(u>v)swap(u,v);
		if(u==1)f[v]|=1;
		if(v==n)f[u]|=2;
		if(f[v]==3 || f[u]==3)flag=true;
	}
	if(flag)puts("POSSIBLE");else puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 4352
n = int(input())
abc = [chr(i) for i in range(97, 97 + n)]
def dfs(s, idx):
    if len(s) == n:
        print(s)
    else:
        for i in range(idx + 1):
            if idx == i:
                dfs(s + abc[i], idx + 1)
            else:
                dfs(s + abc[i], idx)
dfs("", 0)


Measured memory_bytes: 4412
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *

H, W = MAP()
A = [input() for _ in range(H)]
check = [[-1]*W for _ in range(H)]
q = deque()

for y in range(H):
    for x in range(W):
        if A[y][x] == "#":
            check[y][x] = 0
            q.append((y, x, 0))

dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]

while q:
    y, x, cnt = q.popleft()
    for i in range(4):
        ny = y + dy[i]
        nx = x + dx[i]
        if 0 <= ny < H and 0 <= nx < W:
            if check[ny][nx] == -1 or cnt+1 < check[ny][nx]:
                check[ny][nx] = cnt + 1
                q.append((ny, nx, cnt+1))


print(max([max(c) for c in check]))

Measured memory_bytes: 189004