akhauriyash/Code-Regression huggingface dataset:
N,X = [int(x) for x in input().split()]
# num of Ps
B = [int((2**(n+1))-1) for n in range(N+1)]
# num of layers
C = [int((2**(n+2))-3) for n in range(N+1)]

def count(n,x):
    counter = 0
    center = int((C[n]+1)/2)
    if(n==0):
        return 1
    if(x==1):
        counter = 0
    elif(x==C[n]):
        counter = B[n]
    elif(x==center):
        counter = int((B[n]+1)/2)
    elif(x<center):
        counter = count(n-1,x-1)
    elif(x>center):
        counter = int((B[n]+1)/2) + count(n-1,x-center)
    return counter

print(count(N,X))   

Measured memory_bytes: 3064
class Heap
    attr_reader :size
    def initialize
        @heap = []
        @size = 0
    end

    def length
        @size
    end

    def push(x)
        i = @size
        @size += 1
        while i > 0 do
            p = (i - 1) / 2
            break if @heap[p] <= x
            @heap[i] = @heap[p]
            i = p
        end
        @heap[i] = x
        self
    end

    def pop
        return nil if @size == 0
        ret = @heap[0]
        @size -= 1
        x = @heap[@size]
        i = 0
        while i * 2 + 1 < @size do
            a = i * 2 + 1
            b = a + 1
            if b < @size && @heap[b] < @heap[a]
                a = b
            end
            break if @heap[a] >= x
            @heap[i] = @heap[a]
            i = a
        end
        @heap[i] = x
        @heap.pop
        return ret
    end
end


N = gets.to_i
as = gets.split.map(&:to_i)

max_f = Array.new(3*N)
sum = as[0...N].inject(:+)
max_f[N-1] = sum
heap = Heap.new
(0...N).each do |i|
    heap.push(as[i])
end

(N...(2*N)).each do |i|
    heap.push(as[i])
    sum += as[i]
    sum -= heap.pop
    max_f[i] = sum
end

as.reverse!
as.map!{|a| -a}
max_r = Array.new(3*N)
sum = as[0...N].inject(:+)
max_r[N-1] = sum
heap = Heap.new
(0...N).each do |i|
    heap.push(as[i])
end

(N...(2*N)).each do |i|
    heap.push(as[i])
    sum += as[i]
    sum -= heap.pop
    max_r[i] = sum
end

max_r.reverse!

ans = -Float::INFINITY
((N-1)...(2*N)).each do |i|
    sum = max_f[i] + max_r[i+1]
    ans = sum if ans < sum
end

puts ans

Measured memory_bytes: 31588
#include<cstdio>
#include<algorithm>
int main(){for(int a[5];~scanf("%d%d%d%d%d",a,a+1,a+2,a+3,a+4);printf("%d %d %d %d %d\n",a[4],a[3],a[2],a[1],a[0]))std::sort(a,a+5);}

Measured memory_bytes: 1040
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    cin>>x>>y;
    if(x%y){
        cout<<x<<"\n";
    }
    else{
        cout<<-1<<"\n";
    }
}


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

int main () {
	int n;
	cin >> n;
	long long L[n];
	for (int i = 0; i <= n; i++) {
		L[i] = 0;
	}
	L[0] = 2;
	L[1] = 1;
	for (int i = 2; i <= n; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	cout << L[n] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=200010;

signed main(){
    ll n;cin>>n;
    ll ans=0;
    REP(i,1,n){
        ans+=(n-1)/i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#!/usr/bin/perl

my ($n,$x) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = sort { $a <=> $b} map {$_ - 0} split(/\s+/o,<STDIN>);

my $ans = 0;
my $tot = 0;
for(my $i=0;$i<$n;$i++){
  last if $x < $a[$i];
  $tot += $a[$i];
  $ans ++;
  $x -= $a[$i];
  if( $i == $n - 1 and $x > 0 ){
    $ans --;
    last;
  }
}

print "$ans\n";


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 100001
using namespace std;
int A[N];
vector<int> win[N];

int dfs(int pos,int dep){
  if(win[pos].size()==0) return 0;
  vector<int> res;
  for(int i=0;i<win[pos].size();i++)
    res.push_back(dfs(win[pos][i],dep+1)); 
  
  sort(res.begin(),res.end(),greater<int>());
  int mx=0;
  for(int i=0;i<res.size();i++){
    mx=max(mx,1+i+res[i]);
  }
    return mx;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n-1;i++)cin>>A[i],win[--A[i]].push_back(i+1);
  
  cout<<dfs(0,0)<<endl;
  return 0;
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll n, r;

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

inline void work(){
	n = read(), r = read();
	if (n < 10) r += (10 - n) * 100;
	printf("%lld\n", r);
}

int main(){
	work();
	return 0;
}

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

using namespace std;
typedef long long ll;

int n;
ll a[100];

inline void chkmin(ll &x, ll y) { x = x < y ? x : y; }

ll dfs(int l, int r, int x, int y) {
	if (l + 2 > r) return 0;
	ll res = LLONG_MAX;
	for (int i = l + 1; i < r; ++i)
		chkmin(res, dfs(l, i, x, x + y) + dfs(i, r, x + y, y) + a[i] * (x + y));
	return res;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	cout << dfs(1, n, 1, 1) + a[1] + a[n] << endl;
	return 0;
}

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

int main(){
  int n, ret=0;
  cin >> n;
  for(int i=1; i<=n; i++){
    if((1<=i&&i<=9) || (100<=i&&i<=999) || (10000<=i&&i<=99999))ret++;
  }
  cout << ret;
  return 0;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i < b;++i) cout << ary[i] << (b-1 == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int n;
ll sums[410];
vector<vector<ll>> dp(410,vector<ll>(410,0));

int main() {
    cin >> n;
    for (int i = 0;i < n;++i) {
        cin >> sums[i+1];
        sums[i+1] += sums[i];
    }
    for (int i = 1;i < n;++i) for (int j = 0;j < n-i;++j) {
        ll res = INT64_MAX;
        for (int k = j;k < j+i;++k) {
            ll temp = dp[j][k]+dp[k+1][j+i];
            res = min(res,temp);
        }
        dp[j][j+i] = res+sums[j+i+1]-sums[j];
    }
    cout << dp[0][n-1] << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    ll n,i,j,p,r,l,sum=0,k;
    vector<vector<int> >v(10,vector<int>(10));
    cin>>n;
    for(i=1;i<=n;i++){
    p=i;
    r=p%10;
    while(p!=0)
    {
        l=p%10;
        p=p/10;
    }
    k=l;
    v[k][r]++;
    }
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
            sum+=v[i][j]*v[j][i];
    }
    cout<<sum;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#define R second.second
using namespace std;
typedef vector<pair<int,pair<int,int> > >vpp;

int main(){
	int W,Q,d,w,i;
	char s[2];
	for(;scanf("%d%d",&W,&Q),W;){ //some case Q==0.
		vpp v;
		v.push_back(make_pair(-2,make_pair(0,0)));
		v.push_back(make_pair(-1,make_pair(W,0)));
		for(;Q;Q--){
			scanf("%s",s);
			if(*s=='w'){
				scanf("%d",&d);
				for(i=0;i<v.size();i++)if(v[i].first==d){v.erase(v.begin()+i);break;}
			}else{
				scanf("%d%d",&d,&w);
				for(i=0;~v[i].first;i++){
					if(v[i+1].second.first-v[i].R>=w){
						v.insert(v.begin()+i+1,make_pair(d,make_pair(v[i].R,v[i].R+w)));
						printf("%d\n",v[i].R);break;
					}
				}
				if(v[i].first==-1)puts("impossible");
			}
		}
		puts("END");
	}
}

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

typedef vector<int>  vi;
typedef set<char> setchar;
typedef set<int> sett;
typedef deque <int> dq;
typedef long long ll;
#define mx 100005
#define vec(a)  a.begin(),a.end()
#define pb     push_back
#define pf     push_front
#define mem(a,b) memset(a,b,sizeof(a));
#define inI(a)  scanf("%d",&a);
#define inL(a)  scanf("%lld",&a);
#define uff ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
//int fx[]={+0,-1,-1,-1,+0,+1,+1,+1};
//int fy[]={-1,-1,+0,+1,+1,+1,+0,-1};
int fx[]= {0,-1,0,+1};
int fy[]= {-1,0,+1,0};
int dp[mx],arr[mx],n;
int solve()
{   dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
        if(i>2)
        {
            dp[i]=min(dp[i],dp[i-2]+abs(arr[i]-arr[i-2]));
        }
    }
    return dp[n];
}
int main()
{
    uff
    //freopen("input.txt","r",stdin);
     cin>>n;
     for(int i=1;i<=n;i++)
     {
         cin>>arr[i];
     }
     cout<<solve()<<endl;




    return 0;

}






Measured memory_bytes: 1024
#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 main(){
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  rep(i,n){
    cout << s[i];
    cout << t[i];
  }
  cout << endl;
}

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

int main(){
	static const double pi = 3.141592653589793;
	long double a,b,h,m;
	cin >> a >> b >> h >> m;
	
	long double dist;

	
	long double handm = h * 60 + m;
	long double hx,hy,mx,my;
	long double radh = 2*pi/(12*60);
	long double radm = 2*pi/60;
	
	hx = a * sinl(radh*handm);
	hy = a * cosl(radh*handm);
	mx = b * sinl(radm*m);
	my = b * cosl(radm*m);
	
	dist = sqrtl( powl( hx-mx,2)+powl( hy-my,2));
	

	printf("%.12Lf\n",dist);

/*	int i;
	for(i=0;i<n;i++){
		
	}
*/	

}

Measured memory_bytes: 4168
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

  int n, d, x; cin >> n >> d >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = x;
  rep(i, n) {
    int day = 1;
    int cnt = 1;
    while(day <= d) {
      day += a[i];
      ++cnt;
    }
    ans += --cnt;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
ret4 x1 y1 x2 y2 =
    (x1 - (y2 - y1), y1 + (x2 - x1))

ret3 x1 y1 x2 y2 =
    (x2 + (y1 - y2), y2 - (x1 - x2))


main = do
    input <- getLine
    let [x1, y1, x2, y2] = map read $ words input
    let (x3, y3) = ret3 x1 y1 x2 y2
        (x4, y4) = ret4 x1 y1 x2 y2
    putStr $ (show x3) ++ " "
    putStr $ (show y3) ++ " "
    putStr $ (show x4) ++ " "
    putStrLn $ (show y4)

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {

    int N;
    cin >> N;
    string S;
    cin >> S;

    string word = "ABC";

    int count = 0;
    for(string::size_type pos = S.find(word); pos != string::npos; pos = S.find(word, pos + string(word).length())) count++;

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
namespace IO{
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc(){
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread(){}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls){
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do{
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    inline void flush(){
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x){
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite(){}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls){
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    struct Flusher_{~Flusher_(){flush();}}io_flusher;
}
using namespace IO;
int main(){
    char ch;
    cin >> ch;
    if(ch >= 'a' && ch <= 'z'){
        puts("a");
    } else {
        puts("A");
    }
    return 0;
}

Measured memory_bytes: 3592
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct cake{
	int turn,w,h;
	cake(int turn,int w,int h):turn(turn),w(w),h(h){}
	cake(){}
	bool operator< (const cake &other)const{
		if(turn==other.turn){
			return w*h<other.w*other.h;
		}else{
			return turn<other.turn;
		}
	}
	pair<cake,cake> cut(int ss,int t){
		int s=ss;
		s%=(2*w+2*h);
		if(s<w){
			return make_pair(cake(t,s,h),cake(t,w-s,h));
		}
		s-=w;
		if(s<h){
			return make_pair(cake(t,w,s),cake(t,w,h-s));
		}
		s-=h;
		if(s<w){
			return make_pair(cake(t,s,h),cake(t,w-s,h));
		}
		s-=w;
		if(s<h){
			return make_pair(cake(t,w,s),cake(t,w,h-s));
		}
		assert(0);
	}
};
int main(){
	int n,w,d;
	while(cin>>n>>w>>d,n|w|d){
		vector<cake> cakes;
		cakes.push_back(cake(0,w,d));
		REP(i,n){
			int p,s;
			cin>>p>>s;
			pair<cake,cake> new_cakes;
			new_cakes=cakes[p-1].cut(s,i+1);
			cakes.erase(cakes.begin()+p-1,cakes.begin()+p);
			cakes.push_back(new_cakes.first);
			cakes.push_back(new_cakes.second);
			sort(ALL(cakes));
		}
		vi sizes;
		REP(i,cakes.size()){
			sizes.push_back(cakes[i].w*cakes[i].h);
		}
		sort(ALL(sizes));
		REP(i,cakes.size()){
			cout<<sizes[i]<<(i==cakes.size()-1?"":" ");
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
// g++ -std=c++14 -O3 -fsyntax-only -o main main.cpp

using ll = long long int;

const int MOD = 1e9 + 7;

#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

template <class T>
class my_array{
  private:
    int n;
    vector<T> A;
  public:
    my_array(int k){n = k; A.resize(n);}
    ~my_array(void){};
    // input a_0, a_1, ..., a_(n-1)
    void get(void){
      for(int i = 0; i < n; i++) cin >> A.at(i);
    }
    // sort A
    void sorted(bool flag = true){
      if(flag) sort(A.begin(), A.end());
      else sort(A.begin(), A.end(), greater<T>());
    }
    // print : a_0, a_1, ... a_(n-1)
    void show(void){
      for(int i = 0; i < n - 1; i++) cout << A.at(i) << " ";
      cout << A.at(n - 1) << "\n";
    }
    tuple<int, int> solve(){
      vector<int> came(9, 0);
      for(int x : A) came.at(MIN(8, x / 400))++;
      int mx, mn, k = 0;
      for(int i = 0; i < 8; i++) if(came.at(i) > 0) k++;
      mn = MAX(1, k);
      mx = k + came.at(8);
      return forward_as_tuple(mn, mx);
    }
};

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

int main(void){
  int n; cin >> n;
  my_array<int> a(n);
  a.get();
  int p, q;
  tie(p, q) = a.solve();
  cout << p << " "<< q << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int map[101][101];
int main()
{
	int n,i,j,k,a,b;
	for(i=0;i<100;i++)
	{
		map[0][i]=1;
	}
	for(i=1;i<100;i+=2)
	{
		for(j=1;j<99;j++)
		{
			map[j][i]=1;
		}
	}
	scanf("%d%d",&a,&b);
	for(i=1;i<99;i+=2)
	{
		for(j=97;j>1;j=j-2)
		{
			if(b==1)
			{
				goto ssa; 
			}
			map[j][i]=0;
			b--;
		}
	}
	ssa:
	for(i=98;i>=0;i=i-2)
	{
		for(j=2;j<97;j+=2)
		{
			if(a==1)
			{
				goto ssb;
			}
			map[j][i]=1;
			a--;
		}
	}
	ssb:
	printf("100 100\n");
	for(i=0;i<100;i++)
	{
		for(j=0;j<100;j++)
		{
			if(map[i][j]==0)
			{
				printf(".");
			}
			else printf("#");
		}
		printf("\n");
	}
	return 0;
}

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 = sc.nextInt();
        char[] c = sc.next().toCharArray();

        int[] west = new int[n];
        int[] east = new int[n];

        if(c[0] == 'W') {
            west[0] = 1;
        } else {
            east[0] = 1;
        }
        for(int i=1; i<n; i++) {
            if(c[i] == 'W') {
                west[i] = west[i-1] + 1;
                east[i] = east[i-1];
            } else {
                west[i] = west[i-1];
                east[i] = east[i-1] + 1;
            }
        }

        int res = east[n-1] + east[0];
        for(int i=1; i<n; i++) {
            int t = east[n-1]-east[i] + west[i-1];
            res = Math.min(t, res);
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 31108
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    string s; cin >> s;
    map<char,int> mp;
    for(int i = 0; i < s.size(); i++){
        mp[s[i]]++;
    }
    bool check = false;
    if(mp['N']>0 && mp['S']>0 && mp['W']>0 && mp['E']>0) check = true;
    if(mp['N']>0 && mp['S']>0 && mp['W']==0 && mp['E']==0) check = true;
    if(mp['N']==0 && mp['S']==0 && mp['W']>0 && mp['E']>0) check = true;

    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int ans;
string s;
int main(){
 cin >> s;
 if(s[0]==s[1]) ans++;
 if(s[1]==s[2]) ans++;
 if(s[2]==s[3]) ans++;
 if (ans == 0) {
		cout << "Good";
	}
	else {
		cout << "Bad"; // 1が表示される
	}
  return 0;
  
  
}

Measured memory_bytes: 888
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")


N = input()
 
n = int(N[-1])
if n in [2,4,5,7,9]:
    print("hon")
elif n in [0,1,6,8]:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 65608
#include <stdio.h>
#include <string.h>
int main(void){
	int a,b,i,j,k,n,A[101][101]={0};
	char str[100000],*line;

	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d %d",&a,&b);
	for(i=0;i<a;i++){
		fgets(str,sizeof(str),stdin);
		line = strtok(str," ");
		sscanf(line,"%d",&n);
		A[i][0]+=n; A[a][0]+=n; A[i][b]+=n; A[a][b]+=n;
		for(j=1;j<b;j++){
			line = strtok(NULL," ");
			sscanf(line,"%d",&n);
			A[i][j]+=n; A[a][j]+=n; A[i][b]+=n; A[a][b]+=n;
		}
	}
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			if(j) printf(" ");
			printf("%d",A[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 668
n = int(input())
cnt, hit, out = 0, 0, 0
while n != 0:
    s = input()
    if s == 'HIT':
        hit += 1
        if hit == 4:
            cnt += 1
            hit -= 1
    elif s == 'HOMERUN':
        cnt += hit + 1
        hit = 0
    else:
        out += 1
    if out == 3:
        print(cnt)
        cnt, hit, out = 0, 0, 0
        n -= 1



Measured memory_bytes: 5600
#include<cstdio>
#include<algorithm>
using namespace std;

int n,m;
int a[300][300];

bool C(int x){
	bool used[300];
	int now[300];
	fill(now,now+n,0);
	fill(used,used+m,false);
	for(int i=0;i<m;i++){
		int cnt[300];
		bool flag = true;
		fill(cnt,cnt+m,0);
		for(int j=0;j<n;j++){
			while(now[j]!=m&&used[a[j][now[j]]]){
				now[j]++;
			}
			if(now[j]==m) return false;
			cnt[a[j][now[j]]]++;
		}
		for(int j=0;j<m;j++){
			if(cnt[j]>x){
				used[j] = true;
				flag = false;
			}
		}
		if(flag) return true;
	}
	return false;
}


int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]--;
	int l = -1;
	int r = n;
	while(r-l>1){
		int mid = (l + r) / 2;
		if(C(mid)) r = mid;
		else l = mid;
	}
	printf("%d\n",r);
}


Measured memory_bytes: 512
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int k;

int main(){
    scanf("%d%d" , &n , &k);
    int xr = 0;
    for(int i = 1; i < (1 << n); i++){
        if(i == k)
            continue;
        xr ^= i;
    }
    if(k == 0){
        for(int i = 0; i < (1 << n); i++){
            printf("%d %d " , i , i);
        }
        return 0;
    } else if(n >= 2 && xr == k){
        printf("%d " , k);
        for(int i = (1 << n) - 1; i >= 0; i--){
            if(i == k)
                continue;
            printf("%d " , i);
        }
        printf("%d " , k);
        for(int i = 0; i < (1 << n); i++){
            if(i == k)
                continue;
            printf("%d " , i);
        }
        puts("");
        return 0;
    }
    puts("-1");
}

Measured memory_bytes: 1792
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	vpii a(n);
	rep(i,0,n) cin>>a[i].F,a[i].S = i;
	sort(a.begin(), a.end());
	rep(i,0,n) cout<<a[i].S+1<<" ";
	
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n];
    for(int i=1;i<n;i++)
        dp[i]=1000000007;
    dp[0]=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<=i+k && j<n;j++)
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
    cout<<dp[n-1];
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll N, M;
	cin >> N >> M;

	vector<ll> dp(N + 1, 0);
	vector<bool> safe(N + 1, true);
	REP(i, M) {
		int tmp;
		cin >> tmp;
		safe[tmp] = false;
	}

	dp[0] = 1;
	FOR(i, 1, N + 1)if (safe[i]) {
		if (i != 1)(dp[i] += dp[i - 2]) %= MOD;
		(dp[i] += dp[i - 1]) %= MOD;
	}
	cout << dp.back() << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define maxn 100005
#define LL long long
#define mod 1000000007
#define INF (LL)4e18
using namespace std;
int n,f[maxn],s[maxn];
LL a,b,x[maxn];
int Get(int l,int r)
{
	if(l>r) return 0;
	if(!l) return s[r];
	else return (s[r]-s[l-1]+mod)%mod;
}
int main()
{
	scanf("%d%lld%lld",&n,&a,&b);
	if(a<b) swap(a,b);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	x[0]=-INF,x[n+1]=INF;
	f[0]=s[0]=1;
	int l=0,r=0;
	for(int i=1;i<=n+1;i++)
	{
		while(r+1<i&&x[i]-x[r+1]>=a) r++;
		if(i>=2&&x[i-1]-x[i-2]<b) l=i-2;
		if(x[i]-x[i-1]>=a) f[i]=f[i-1];
		f[i]=(f[i]+Get(l,min(i-2,r)))%mod;
		s[i]=s[i-1];
		if(x[i+1]-x[i-1]>=b) s[i]=(s[i]+f[i])%mod;
	}
	printf("%d\n",f[n+1]);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<b;i++)
#define f(i,n) for(int i=0;i<n;i++)
typedef unsigned long long ull;
typedef long long ll;
#define vint vector<int>
#define pb(a) push_back(a);
#define bug(x) cout<<#x<<" = "<<x<<"\n";
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)

template <typename t>
void printarr(t *a,int n){
	f(i,n){
		cout<<a[i]<<" ";
	}
	cout<<"\n";
}

template <typename t>
void printvec(vector<t> a){
	for(int i=0;i<a.size();i++){
		cout<<a[i]<<" ";
	}
	cout<<"\n";
	return;
}

int pow(int n,int p){
    if(p==0){return 1;}
    if(p==1){return n;}
    else{
        int temp = pow(n,p/2);
        if(p%2==0){return temp*temp;}
        else{
            return n*temp*temp;
        }
    }
}

int main(){
	fastio;
	int h,w,k;
	cin>>h>>w>>k;
    char a[h][w];
    f(i,h){
        f(j,w){
            cin>>a[i][j];
        }
    }
    int maxh=pow(2,h),maxw=pow(2,w);
    int ans=0;
    f(i,maxh){
        f(j,maxw){
            int count=0;
            f(row,h){
                f(col,w){
                    if(((i>>row)&1)==0 && ((j>>col)&1)==0 && a[row][col]=='#'){
                        count+=1;
                    }
                }
            }
            if(count==k)    ans+=1;
        }
    }
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3616
N,P = map(int, input().split())
bs = list(map(int, input().split()))
even = 0
for i in range(N):
    if bs[i]%2 == 0: even += 1
odd = N-even

f = [1]
for n in range(1, N+2):
    f.append(f[-1] * n)

def ncr(n,r):
    return f[n] // f[n-r] // f[r]

oddc = 0
for i in range(odd+1):
    if i%2 != P : continue
    oddc += ncr(odd,i)

print (pow(2,even) * oddc)


Measured memory_bytes: 3188
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = (1e9) + 7 ;
const LD EPS = 0.0000001 ;

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

   int n; cin >> n;
   LL arr[n];
   for (int i = 0; i < n; i++){
   		cin >> arr[i];
   }
   int ans = 1;
   LL mx = arr[0];
   for (int i = 1; i < n; i++){
   		if (arr[i] >= mx){
   			ans++;
   		}
   		mx = max (mx, arr[i]);
   }
   cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{   
    long long b,x,g,cnt=0,i,n,sum=0;
    cin>>n>>x;
    long long a[n];
    for(i=0;i<n;i++){cin>>a[i];sum+=a[i];}
    for(i=0;i<n-1;i++){
        g=(a[i]+a[i+1]-x);
        if(a[i+1]>=g&&g>0){a[i+1]-=g;cnt+=g;}
        else if(g>0){a[i+1]=0;cnt+=g;}
    }
    if(cnt>0){cout<<cnt;}
    else{cout<<0;}
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
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__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int M, D, t = 0;
    cin >> M >> D;
    rep(i, 1, M + 1)
        rep(j, 22, D + 1) if((j / 10) * (j % 10) == i && (j % 10) > 1) t++;
    cout << t << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

// ?????¢???top, ?????¢???fr?????¨????????¢??????????????????
// fr????????????y????????????????????¨??????
// ?????????????????????????????§??????????????????
VI getDir(int top, int fr){
  VI res;
  int n;
  if(top == 1 || top == 6) n = 5;
  else n = 6;
  if(fr == n) res.PB(0);
  else if(7 - fr == n) res.PB(2);
  else if(top%2){
	if(fr <= 3) res.PB(1);
	else res.PB(3);
  }
  else{
	if(fr <= 3) res.PB(3);
	else res.PB(1);
  }

  if(top == 3 || top == 4) n = 5; else n = 4;
  if(fr == n) res.PB(0);
  else if(7 - fr == n) res.PB(2);
  else if(top%2){
	if(fr <= 3) res.PB(3);
	else res.PB(1);
  }
  else{
	if(fr <= 3) res.PB(1);
	else res.PB(3);
  }

  return res;
}

void rotate(int& top, int& fr, int dir){
  int ot = top, ofr = fr;
  switch(dir){
  case 0:
	top = 7 - ofr;
	fr = ot;
	break;
  case 2:
	top = ofr;
	fr = 7 - ot;
	break;
  default:
	fr = ofr;
	top = 6 - min(ot, 7 - ot) - min(ofr, 7-ofr);
	break;
  }
}

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

  int N;
  while(cin>>N,N){
	//(y,x)??§????????????????????????
	int hs[200][200];
	//????????????????????¢
	int top[200][200];
	fill((int*)hs, (int*)hs+200*200, 0);
	fill((int*)top, (int*)top+200*200, 0);

	REP(i,N){
	  int t, f, h; cin >> t >> f;
	  int x = 100, y = 100;
	  h = hs[y][x];
	  while(true){
		VI dirs = getDir(t,f);
		int j;
		for(j=0;j<SZ(dirs);++j){
		  int d = dirs[j];
		  int tx = x + dx[d], ty = y + dy[d];
		  if(hs[ty][tx] >= hs[y][x]) continue;
		  x = tx, y = ty;
		  rotate(t, f, d);
		  break;
		}
		//??¢????????´??????????????£??????
		if(j == SZ(dirs))
		  break;
		h = hs[y][x];
	  }
	  ++hs[y][x];
	  top[y][x] = t;
	}

	VI cnt(7,0);
	REP(y,200) REP(x,200)
	  cnt[top[y][x]]++;

	cout << cnt[1];
	FOR(i,2,7) cout << " " << cnt[i];
	cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1524
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
import math
if c-a-b>0 and 4*a*b<(c-a-b)**2:
    print('Yes')
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}

int main(){
    ll n;
    cin >> n;
    while(!is_prime(n)){
        ++n;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.InputMismatchException;

public class Main {
	int n, m;
	double[] a, b, c;
	double max;

	void bt(int k, boolean[] use, int cnt) {
		if (m < cnt) {
			return;
		}
		if (k == n) {
			if (cnt < m) return;
			max = Math.max(max, calc(use));
		} else {
			use[k] = true;
			bt(k + 1, use, cnt + 1);
			use[k] = false;
			bt(k + 1, use, cnt);
		}
	}

	double calc(boolean[] use) {
		double sum = 0;
		for (int i = 0; i < n; i++) {
			if (!use[i]) continue;
			for (int j = i + 1; j < n; j++) {
				if (!use[j]) continue;
				sum += dist(i, j);
			}
		}
		return sum;
	}

	double dist(int i, int j) {
		double res = 0;
		res += (a[i] - a[j]) * (a[i] - a[j]);
		res += (b[i] - b[j]) * (b[i] - b[j]);
		res += (c[i] - c[j]) * (c[i] - c[j]);
		return res;
	}

	void run() {
		MyScanner sc = new MyScanner();

		n = sc.nextInt();
		m = sc.nextInt();
		a = new double[n];
		b = new double[n];
		c = new double[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextDouble();
			b[i] = sc.nextDouble();
			c[i] = sc.nextDouble();
		}

		max = 0;
		bt(0, new boolean[n], 0);
		System.out.println(max);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

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

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}

Measured memory_bytes: 27796
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n = I()
X = LI()
ans = INF
for i in range(100):
    ret = 0
    for x in X:
        ret += (i - x) ** 2
    ans = min(ans, ret)


print(ans)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < S.size() / 2; i++) {
    if (S[i] != S[S.size() - 1 - i]) {
      ans++;
    }
  }

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

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 3e3 + 5; 
int dp[N][N]; 

void solve(int test) {
	int n; cin >> n ;
	int a[n+1]; rep(i,1,n+1) cin >> a[i] ;

	for(int i = n ; i > 0 ; --i ) {
		for(int j = i ; j <= n ; ++j ) {
			if(i == j ) dp[i][j] = a[i] ;
			else dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]) ;
		}
	}

	cout << dp[1][n] ; 
}

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

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

string s;
char a,b;

int main(){
    cin >> s;
    ll cou1 = 0, cou2 = 0;
    a = s[0];
    ++cou1;
    for(int i = 1; i < s.length(); i++){
        if(s[i] != a){
            if(cou2 == 0){
                b = s[i];
                ++cou2;
            }
            else{
                if(s[i] == b)   ++cou2;
                else{
                    cout << "No\n";
                    return 0;
                }
            }
        }
        else    ++cou1;
    }

    if(cou1 == cou2){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
def main():
    # -*- coding: utf-8 -*-
    # 整数の入力
    # a = int(input())
    # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # b, c = map(int, input())

    # # 文字列の入力
    a = input()
    # 出力
    # print("{} {}".format(a+b+c, s))

    # mul = a

    if '7' in a:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    # main('123')
    main()


Measured memory_bytes: 9024
h, w = gets.split.map(&:to_i)
a = (1..h).map { gets.chomp.split("") }
pos = {}
a.each.with_index do |row, i|
  row.each.with_index do |c, j|
    if c =~ /\w/
      (pos[c] ||= []) << i
      pos[c] << j
    end
  end
end

def paths(y1, x1, y2, x2)
  return [Range.new(*[y1, y2].sort).map {|y| [y, x1] }] if x1 == x2
  return [Range.new(*[x1, x2].sort).map {|x| [y1, x] }] if y1 == y2
  return [
    (Range.new(*[x1, x2].sort).map {|x| [y1, x] } + Range.new(*[y1, y2].sort).map {|y| [y, x2] }),
    (Range.new(*[y1, y2].sort).map {|y| [y, x1] } + Range.new(*[x1, x2].sort).map {|x| [y2, x] })
  ]
end

answer = pos.size * 2
loop do
  erase = false

  pos.each do |c, coor|
    y1, x1, y2, x2 = coor
    paths = paths(y1, x1, y2, x2)
    if paths.any? {|path| (path - [[y1, x1], [y2, x2]]).size > 0 && path.all? {|y, x| [y, x] == [y1, x1] || [y, x] == [y2, x2] || a[y][x] == ?. } }
      erase = true
      pos.delete(c)
      a[y1][x1] = ?.
      a[y2][x2] = ?.
      break
    end
  end
  break if !erase
end
answer -= pos.size * 2
p answer



Measured memory_bytes: 24824
#include <stdio.h>
int main(void){
    int n , a[100] ;
    int i , j , t , l = 0 ;
    int flag ;
    
    scanf("%d" , &n) ;
    
    for(i = 0 ; i < n ; i++){
        scanf("%d" , &a[i]) ;
    }
    
    for(i = 0 ; i < n ; i++){
        for(j = n - 1 ; j > i ; j--){
            if(a[j] < a[j - 1]){
                t = a[j - 1] ;
                a[j - 1] = a[j] ;
                a[j] = t ;
                l++ ;
            }
        }
    }
    
    for(i = 0 ; i < n ; i++){
        printf("%d" , a[i]) ;
        if(i == n - 1)continue ;
        printf(" ") ;
    }
    printf("\n") ;
    printf("%d\n" , l) ;
    return 0 ;
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,A;cin >> N >> A;
  YesNo(A>=N%500);
  return 0;
}


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

int main(){
  long long k;
  long long count=0;
  long long x=0;

  cin >> k;

  while(count<=k){
    x=((x*10)+7)%k;
    count++;
    if(x==0){
      break;
    }
  }

  if(count>k){
    cout << -1 << endl;
  }else{
    cout << count << endl;

  }


  return(0);
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

ll n;
ll A, B, C;
vll l;

ll dfs(ll cur, ll a, ll b, ll c)
{
	if (cur==n){
		if (a!=0 && b!=0 && c!= 0){
			return abs(A-a)+abs(B-b)+abs(C-c)-30;
		}else{
			return 3000;
		}
	}
	ll ret=LONG_LONG_MAX;
	ret = min(ret, 10+dfs(cur+1, a+l[cur], b, c));
	ret = min(ret, 10+dfs(cur+1, a, b+l[cur], c));
	ret = min(ret, 10+dfs(cur+1, a, b, c+l[cur]));
	ret = min(ret, dfs(cur+1, a, b, c));
	return ret;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	cin >> A >> B >> C;
	l.resize(n);
	rep(i, n) cin >> l[i];
	cout << dfs(0, 0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256