akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int H, W; 
    cin >> H >> W;
    int N; cin >> N;
    vector<vector<int>> grid(H, vector<int>(W));

    int h = 0, w = 0;
    bool down = true;

    rep(i, N) {
        int A; cin >> A;
        rep(j, A) {
            // DUMP2(h, w);
            grid[h][w] = i+1;
            h += (down ? 1 : -1);

            if (down && h == H) {
                w++;
                h = H - 1;
                down = false;
            }

            if (!down && h == -1) {
                w++;
                h = 0;
                down = true;
            }
        }
    }

    rep(i, H) {
        rep(j, W) {
            if (j > 0) cout << " ";
            cout << grid[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>
#include <utility>
 
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl
#define ROUNDED(N) fixed << setprecision(N)
#define SPACE " "
 
typedef long long ll;
using namespace std;
 
int nextInt() { int n; cin >> n; return n; }
double nextDouble() { double d; cin >> d; return d; }
string nextString() { string str; cin >> str; return str; }
 
int dx[6] = {1,1,0,-1,-1,0};
int dy[6] = {1,0,-1,-1,0,1};
struct points{int x,y,turn;};
const int def = 60;
int main() {
    cin.tie(0); //??????±?????????????????????
    ios::sync_with_stdio(false); //printf???¨???±??????????????????
 
    int t,n;
    while(cin>>t>>n,t||n){
        vector<vector<int>> mp(def*2+1,vector<int>(def*2+1,0));
	vector<vector<int>> memp(def*2+1,vector<int>(def*2+1,0));
        REP(i,n){
            int a = nextInt()+def;
            int b = nextInt()+def;
            mp[a][b] = 1;
        }
        queue<points> que;
        points start;
        start.x=nextInt()+def;start.y=nextInt()+def;start.turn=t;
        que.push(start);
        int ct = 0;
        while(que.size()){
            int x = que.front().x;
            int y = que.front().y;
            int nowturn = que.front().turn;
            que.pop();
	     
            if(mp[x][y]==0){
                ct++;
                mp[x][y] = 1;
            }
	    if(nowturn>memp[x][y])
	      memp[x][y] = nowturn;
	    else continue;
            if(nowturn==0)continue;
            REP(i,6){
                points ne;
                ne.x = x + dx[i];
                ne.y = y + dy[i];
                if(ne.x<0||ne.x>def*2||ne.y<0||ne.y>def*2)continue;
                if(mp[ne.x][ne.y]==0){//||ne.x*ne.x+ne.y*ne.y>900
                    ne.turn = nowturn - 1;
                    que.push(ne);
                }
            }
        }
        cout << ct << endl;
    }
    return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
	int H, W, ih, iw;

	while (1) {
		cin >> H >> W;

		if (H == 0 && W == 0)
			break;
		for (ih = 0; ih < H; ih++) {
			for (iw = 0; iw < W; iw++) {
				printf("#");
			}
			printf("\n");
		}

		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3084
#pragma GCC optimize("O3")
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pii pair<ll,int>
#define pip pair<int,pii>
#define ppi pair<pii,int> 
#define ppp pair<pii,pii>
#define pb push_back
#define ppb pop_back
#define pf push_fron
#define ppf pop_front
#define N 200003
#define inf (ll)(1e9+11)
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll mod=1e9+7;
int freq[N];

signed main()
{
    warmup
    
    int n;
    cin>>n;
    int a[n+1],i,j;
    for(i=1;i<=n;++i)
        cin>>a[i], ++freq[a[i]];
    ll ans=0;
    for(i=1;i<N-2;++i)
        if(freq[i])
            ans+=(freq[i]*1ll*(freq[i]-1))/2;
    
    for(i=1;i<=n;++i)
    {
        ans-=(freq[a[i]]*1ll*(freq[a[i]]-1))/2;
        --freq[a[i]];
        if(freq[a[i]])
            ans+=(freq[a[i]]*1ll*(freq[a[i]]-1))/2;
        
        cout<<ans<<'\n';
        
        if(freq[a[i]])
            ans-=(freq[a[i]]*1ll*(freq[a[i]]-1))/2;
        ++freq[a[i]];
        ans+=(freq[a[i]]*1ll*(freq[a[i]]-1))/2;
    }   
    
    return 0;
}


Measured memory_bytes: 3712
N, X = map(int, input().split())

size_table = [1] * 51
pate_table = [1] * 51

for i in range(1, 51):
    size_table[i] = size_table[i-1] * 2 + 3
    pate_table[i] = pate_table[i-1] * 2 + 1

def calc(N, X):
    if X <= 0:
        return 0
    if size_table[N] <= X:
        return pate_table[N]
    r = 0
    r += calc(N - 1, X - 1)
    if (size_table[N - 1] + 1) < X:
        r += 1
    r += calc(N - 1, X - size_table[N - 1] - 2);
    return r

print(calc(N, X))


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi array(n+1);
		array[0] = 0;
		reep(i, 1, n+1){
			scanf("%d", &array[i]);
			array[i] += array[i-1];
		}

		int ans = INT_MIN;
		rep(i, n){
			reep(j, i+1, n+1)
				ans = max(ans, array[j]-array[i]);
		}

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long N,K,p[1000];
	cin >> N >> K;

	string s;
	//cin >> s;

	//int A[5]

	for (long long i = 0; i < N; i++)
	{
		cin >> p[i] ;
	}

	sort(p, p + N);
	long long a = 0;
	for (long long i = 0; i < K; i++)
	{
		a += p[i];
	}
	if (true)
	{
		cout << a << endl;
	}

}

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

typedef long long ll;

int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15)cout<<'+'<<endl;
  else if(a*b==15)cout<<'*'<<endl;
  else cout<<'x'<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#define SIZE 20005

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

ll A[SIZE];
P pos[SIZE];
int n;

bool check(int x,int k)//x 桁目
{
	ll rt=1;
	for(int i=0;i<x;i++) rt*=10LL;
	int sz=0;
	pos[sz++]=P(rt*(ll) k,rt*(ll) (k+1)-1);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<sz;j++)
		{
			if(pos[j].first<=A[i]%(rt*10LL)&&A[i]%(rt*10LL)<=pos[j].second)
			{
				return true;
			}
		}
		int ns=sz;
		for(int j=0;j<sz;j++)
		{
			P p=pos[j];
			p.first-=A[i]%(rt*10LL);
			p.second-=A[i]%(rt*10LL);
			if(p.first<0) p.first+=rt*10LL;
			if(p.second<0) p.second+=rt*10LL;
			if(p.first<=p.second) pos[ns++]=p;
			else
			{
				pos[ns++]=P(p.first,rt*10LL-1);
				pos[ns++]=P(0,p.second);
			}
		}
		sort(pos,pos+ns);
		sz=0;
		for(int j=0;j<ns;)
		{
			P p=pos[j];
			for(;j<ns&&pos[j].first<=p.second;j++) p.second=max(p.second,pos[j].second);
			pos[sz++]=p;
		}
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	int ret=0;
	for(int i=0;i<17;i++)
	{
		int nm=0;
		for(int j=0;j<10;j++) if(check(i,j)) nm=j;
		ret+=nm;
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 384
//Keep working hard :)
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e5+5;
int a[N];

void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
     //   fileIO();
	int k,s,cnt(0);
	cin >> k >> s;
	for(int i = 0; i <= k; i++)
	{
		for(int j = 0;j <= k; j++)
		{
			int z = s - i - j;
			if(z >= 0 && z <= k)cnt++;
		}
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;
    string s;cin>>s;
    map<char, int> mm;
    rep(i, 4){
        mm[s[i]]++;
    }
    if(mm[s[0]]==2&&mm[s[1]]==2&&mm[s[2]]==2&&mm[s[3]]==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	if (a == b) {
		if (a == c) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	else if (a == c) {
		cout << "Yes" << endl;
	}
	else if (b == c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define MAX_N 11111111
using namespace std;
int prime[MAX_N];
bool is_prime[MAX_N];
int sieve(int n){
  int p = 0;
  for(int i=0;i<=n;i++)is_prime[i] = true; // 初期化
  is_prime[0] = is_prime[1] = false; // 例外処理
  for(int i=2;i<=n;i++){
    if(is_prime[i] == true){
      prime[p++] = i;
      for(int j=2*i;j<=n;j+=i)is_prime[j] = false;
    }
  }
  return p;
}
int main(){
  int n;
  while(cin >> n){
    cout << sieve( n ) << endl;
  }
}

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


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> ans(n);
    rep(i, n) ans[a[i]-1] = i+1;
    rep(i, n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 1664
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> minOf(vararg a: A) = a.reduce { acc, x -> min(acc, x) }

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val Q = sc.next().toLong()
        val H = sc.next().toLong()
        val S = sc.next().toLong()
        val D = sc.next().toLong()
        val N = sc.next().toLong()
        val q1 = minOf(4 * Q, 2 * H, S)
        val q2 = minOf(2 * q1, D)
        pw.println((N / 2) * q2 + (N % 2) * q1)
    }
}


Measured memory_bytes: 31264
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


struct UnionFind {
	vector<int> par;
  
  UnionFind(int N): par(N){
  	for(int i=0;i<N;i++) par[i] =i;
  }
  
  
};



int main(){
  ios::sync_with_stdio(false);
  
  ll N,A,B;
  cin>>N>>B>>A;
  
  ll now = (N/(A+B))*B;
  ll mo = N%(A+B);
  
  if(mo >= B){
  	cout<<now+B;
  }else{
  	cout<<now+mo;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
long long int C[12];
long long int A[12][12];
long long int N,M,X;
long long int mi = 12*10e+5+1000;
void calc(long long int now,long long int nowD,vector<long long int> AL){
	
	if(nowD >= N){
		//cout<<now<<" "<<nowD<<endl;
		long long int f = 0;
		for(long long int i = 0; i < M; i++){
			if(AL[i] >= X){
				
			}else{
				f=1;
				break;
			}
		}
		//cout<<now<<" "<<f<<" ";
		//for(long long int i = 0; i < M; i++)cout<<AL[i]<<" "<<endl;
		if(f == 0){
			
			mi = min(mi,now);
		}
		return;
	}

	
	calc(now,nowD+1,AL);
	for(long long int i = 0; i < M;i++){
		AL[i] += A[nowD][i];
	}
	calc(now+C[nowD],nowD+1,AL);
}


signed main(){
	
	cin>>N>>M>>X;
	
	for(long long int i = 0; i < N; i++){
		cin>>C[i];
		for(long long int k = 0 ; k < M; k++){
			cin>>A[i][k];
		}
	}
	
	
	vector<long long int>AL(12);
	for(long long int i = 0; i < M;i++){
		AL[i] = 0;
	}
	calc(0,0,AL);
	for(long long int i = 0; i < M;i++){
		AL[i] = A[0][i];
	}
	calc(C[0],1,AL);
	if(12*10e+5+1000 == mi){
		cout<<"-1"<<endl;
	}else{
		cout<<mi<<endl;
	}
}



Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;

int main() {
	ll n, m, k;
	while (cin >> n >> m >> k) {
		ll t;
		if (m < n) {
			t = m;
			m = n;
			n = t;
		}
		if (k >= n && k <= m) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	string S, T;
	cin >> S >> T;
	int A, B;
	cin >> A >> B;
	string U;
	cin >> U;
	if(S == U)
		A--;
	else
		B--;
	cout << A << " " << B << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char str[20],a[20];
    int i,len,j;
    scanf("%s",str);
    for(i=0;str[i]!='\0';i++);
    len=i;
    for(i=len-1,j=0;i>=0;i--,j++)
    {
        a[j]=str[i];
    }
      a[len]='\0';
      printf("%s\n",a);

    return 0;
}


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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<Edge>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
//使える数字のみからなるN以上の最小数を求める
void dfs(int N,int a,vector<int> &v,vector<int> &use){
  if(a >= N) return;

  int n = use.size();
  rep(i,n){
    if(a == 0 && use[i] == 0) continue;
    if(10*a + use[i] >= N) v.push_back(10*a + use[i]);
    dfs(N,10*a + use[i],v,use);
  }

}

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> D(K);
  rep(i,K){
    cin >> D[i];
  }
  set<int> s;
  rep(i,K){
    s.insert(D[i]);
  }
  vector<int> use;//使える数
  for(int i = 0;i<=9;i++){
    if(!s.count(i)) use.push_back(i);
  }
  /*rep(i,use.size()){
    cout << use[i] << endl;
  }*/
  vector<int> v;
  dfs(N,0,v,use);
  sort(v.begin(),v.end());
  cout << v[0] << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	set<ll> a;
	for (ll i = 0; i < n; i++)
	{
		ll q, x;
		cin >> q >> x;

		switch (q)
		{
			case 0:
				a.insert(x);
				println(a.size());
				break;

			case 1:
				if (a.count(x))
				{
					println(1);
				}
				else
				{
					println(0);
				}
				break;
		}
	}

}




Measured memory_bytes: 12472
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		int a=Integer.parseInt(scan.next());
    		int b=Integer.parseInt(scan.next());
    		
    		System.out.print(a+b>=10?"error":a+b);
    		
    	
  
    				
 
     
    }
    }

Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N, M, X; cin >> N >> M >> X;
	ll a = 0, b = 0;
	rep(i, 0, M) {
		ll A; cin >> A;
		if (X < A) {
			a++;
		}
		else {
			b++;
		}
	}
	cout << ((a > b) ? b : a) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll dp[2005][2005];
bool comp(p2 a,p2 b){
	return a.first>b.first;
}
void solve(){
	ll n;
	cin>>n;
	vector<p2> v(n);
	for(ll i=0;i<n;i++){
		cin>>v[i].first;
		v[i].second=i;
	}
	sort(v.begin(),v.end(),comp);
	for(ll i=0;i<n;i++){
		for(ll l=0;l<=i;l++){
			dp[l+1][i-l]=max(dp[l+1][i-l],dp[l][i-l]+v[i].first*abs(v[i].second-l));
			dp[l][i-l+1]=max(dp[l][i-l+1],dp[l][i-l]+v[i].first*abs(n-i+l-1-v[i].second));
		}
	}
	ll res=0;
	for(ll i=0;i<=n;i++)
	res=max(res,dp[i][n-i]);
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 26324
def candy():
    n = []
    n = input().split()
    N = int(n[0])
    x = int(n[1])
    alist = [int(i) for i in input().split()]

    s = 0
    for i in range(0, N - 1):
        c = int(alist[i])
        d = int(alist[i + 1])
        if int( alist[i] + alist[i + 1] ) > x:
            if int( alist[i] ) >= x:
                alist[i] = x
                alist[i + 1] = 0
            else :
                alist[i + 1] = int(x - alist[i] )
            s += c - int(alist[i]) + d - int(alist[i + 1])
        """
        if int(alist[i]) > x:
            s = s + int(alist[i+1])
            alist[i+1] = 0

        if int(alist[i+1]) + int(alist[i]) > x:
            s = s + (int(alist[i+1]) + int(alist[i]) - x)
            alist[i+1] = x - int(alist[i])
        """
    print(s)
candy()

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();
	int n;
	string s;
	cin >> n >> s;
	vector<int> preWhite(n+1), sufRed(n+1);
	preWhite[0] = 0; sufRed[n] = 0;
	for (int i = 0; i < n; ++i) {
		int adder = s[i]=='W';
		preWhite[i+1] = preWhite[i] + adder;
	}
	for (int i = n-1; i >= 0; --i) {
		int adder = s[i]=='R';
		sufRed[i] = sufRed[i+1] + adder;
	}
	int ans = n;
	for (int i = 0; i <= n; ++i)
	{
		int mx = max(preWhite[i],sufRed[i]), mn = min(preWhite[i], sufRed[i]);
		ans = min(ans, mx);
	}
	cout << ans << nl;
}

Measured memory_bytes: 5192
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e5+10;
int a[N],lis[N],sum[N];
int n,m;
namespace BIT{
	const int N=::N*2;
	ll c[N];
	int mx;
	void init(int _n){mx=_n;memset(c,0,sizeof(c));}
	void insert(int x,int delta){for (;x<=mx;x+=x&-x) c[x]+=delta;}
	ll query(int x){
		ll ret=0;
		for (;x;x-=x&-x) ret+=c[x];
		return ret;
	}
}
bool check(int val){
	ll cnt=0;
	sum[0]=0;
	for (int i=1;i<=n;++i) sum[i]=sum[i-1]+(a[i]>=val?1:-1);
	BIT::init(n*2+1);
	for (int i=0;i<=n;++i){
		cnt+=BIT::query(sum[i]+n+1);
		BIT::insert(sum[i]+n+1,1);
	}
	return cnt>=1LL*n*(n+1)/4;
}
int solve(){
	int l=1,r=lis[0],mid,ret=0;
	while (l<=r){
		mid=l+r>>1;
		if (check(lis[mid])) ret=lis[mid],l=mid+1;
		else r=mid-1;
	}
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	//freopen("a.in","r",stdin);
#endif
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i),lis[i]=a[i];
	sort(lis+1,lis+1+n);
	lis[0]=unique(lis+1,lis+1+n)-lis-1;
	printf("%d\n",solve());
}


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

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(int x, int y){
  if(x % y == 1) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(int x, int y){
  return x * y / gcd(x, y);
}
// n個の最大公約数
ll ngcd(vector<int> a){
  int res;
  res = a[0];
  for(int i=1; i<a.size() && res!=1; i++){
    res = gcd(res, a[i]);
  }
  return res;
}
// n個の最小公倍数
ll nlcm(vector<int> a){
  int res;
  res = a[0];
  REP(i, a.size()){
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(int x){
  int i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
int digsum(int x){
  int res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int a, b;
  cin >> a >> b;
  bool ans = false;
  REP(i,3){
    if(a*b*i % 2 != 0) ans = true;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}






Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
vll Ai;
vll Bi;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> N;
    cin >> M;
    cin >> K;
 
    ll sumA=0;
    A.push_back(0);
    rep(ni,N){
        cin >> ltmp;
        sumA+=ltmp;
        if(sumA<=K){
            //sumA+=ltmp;
            A.push_back(sumA);
        }
    }
    
    ll sumB=0;
    B.push_back(0);
    rep(ni,M){
        cin >> ltmp;
        //if(sumB+ltmp<=K){
        sumB+=ltmp;
        B.push_back(sumB);
        //}
    }

    ll bi = B.size()-1;
    ll cnt = 0;
    rep(ai,A.size()){
        if(A[ai]>K) break;
        while(A[ai]+B[bi]>K){
            bi--;
        }
        if(cnt<ai+bi) cnt = ai + bi;

    }

    cout << cnt << endl;




}

Measured memory_bytes: 7916
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	while(1){
		ll d,n,m;
		ll x[100010],y[10010];
		
		scanf("%lld",&d); if(d == 0)break;
		scanf("%lld%lld",&n,&m);
		rep1(i,n-1){
			scanf("%lld",&x[i]);
		}
		rep(i,m){
			scanf("%lld",&y[i]);
		}
		
		vector<ll> vec;
		rep1(i,n-1){
			vec.pb(x[i]);
		}
		vec.pb(0);
		vec.pb(d);
		sor(vec);
		
		ll ret = 0;
		rep(i,m){
			ret += min ( *ub(vec,y[i])-y[i] , y[i]-*--ub(vec,y[i]) );
		}
		
		printf("%lld\n",ret);
	}
}

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


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

    if( S[5] != '0' ) goto TBD;
    if( S[6] != '1' && S[6] != '2' && S[6] != '3' && S[6] != '4' ) goto TBD;

    cout << "Heisei" << endl;
    return 0;
TBD:
    cout << "TBD" << endl;
}



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


int main (){
    int dis ;
    vector<int> Vec(5);
    for(int i=0; i<5;i ++){
        cin>>Vec.at(i);
    }
    cin>>dis;
    cout<<(dis<Vec.at(4)-Vec.at(0)?":(":"Yay!")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
int a,b,c,d,n,m,h,w,sum,mi,ma;
typedef vector<int> VI;
typedef vector<pair<int,int> > VP;

int main(void){
    cin>>n;
    VP vp;
    rep(i,n){
        cin>>a>>b;
        vp.pb({b,a});
    }
    sort(all(vp));
    rep(i,n){
        d(vp[i].fi)d(vp[i].se)
        sum+=vp[i].se;
        if(sum>vp[i].fi){p("No");return 0;}
    }
    p("Yes");
    return 0;
}


Measured memory_bytes: 2420
n = int(input())
A =list(map(int,input().split()))
num4 = 0
num2 = 0
num1 = 0
for a in A:
    if a%4 == 0:
        num4 += 1
    elif a%2 == 0:
        num2 += 1
    else:
        num1 += 1

if num2 == 0:
    if num4 >= num1-1:
        print("Yes")
    else:
        print("No")
else:
    if num4 >= num1:
        print("Yes")
    else:
        print("No") 

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S seconnd
#define int ll
#define PB push_back


bool f(int n){
  int res=0;
  FOR(i,1,n+1){
    if(n%i==0) res++;
  }

  

  if(res==8) return true;

  return false;
}

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

  int ans=0;
  rep(i,n+1){
    if(i%2==0) continue;
    if(f(i))
      ans++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	string s;
	int i;
	cin>>s;
	for(i=0;i<s.length();i++)
		if(s[i]=='C')
			break;
	for(;i<s.length();i++)
		if(s[i]=='F')
		{
			cout<<"Yes";
			return 0;
		}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],cnt[2000000],cnt1[2000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,i,j,k,x,y,ans;
    cin>>n;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i];
    	cnt[arr[i]]++;
	}
	sort (arr,arr+n);
	ans=n;
	for (i=0;i<=1000000;i++)
	{
		if (cnt1[i]==1)
		{
			ans-=cnt[i];
		}
		else if (cnt[i]>1)
		{
			ans-=cnt[i];
		}
		if (cnt[i]>=1)
		{
			for (j=i*2;j<=1000000;j+=i)
			{
				cnt1[j]=1;
			}
		}
	}
	cout<<ans<<endl;
}

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

int ordena(void const *a, void const *b) {
    return ( *(int*)a - *(int*)b );
}

int main() {
    int n;
    scanf("%d", &n);
    int vetor[n];
    for (int i=0; i<n; ++i)
        scanf("%d", &vetor[i]);

    qsort(vetor, n, sizeof(vetor[0]), ordena);

    printf("%d\n", vetor[n-1]-vetor[0]);
    return 0;
}


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

using namespace std;

using ll = long long;

int w, h;
vector< vector<int> > c, island;

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

void dfs(int x, int y, int id) {

    island[y][x] = id;

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

        int nx = x + dx[i];
        int ny = y + dy[i];

        if(nx < 0 || nx >= w || ny < 0 || ny >= h)
            continue;

        if(c[ny][nx] == 1 && island[ny][nx] != id)
            dfs(nx, ny, id);

    }

}

int main(){

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

    int ans;

    while(cin >> w >> h && w) {

        c.assign(h, vector<int>(w));
        island.assign(h, vector<int>(w, -1));
        ans = 0;

        for(int y = 0; y < h; y++)
            for(int x = 0; x < w; x++)
                cin >> c[y][x];

        for(int x = 0; x < w; x++)
            for(int y = 0; y < h; y++)
                if(c[y][x] == 1 && island[y][x] == -1)
                    dfs(x, y, ans++);

        cout << ans << endl;

    }
}

Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  vector<ll> w(n);
  ll sum = 0;
  ll res = 100000000000LL;
  REP(i,n) {
    cin >> w[i];
    sum += w[i];
  }
  for (ll i = 0; i < n-1; i++) {
    ll tmp = 0;
    for (ll j = 0; j <= i; j++) {
      tmp += w[j];
    }
    res = min(abs(sum-tmp-tmp),res);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#グラフが連結かどうかをDFSで判定する
def dfs(g, v):
    visited[v] = True
    for v2 in range(N):
        if visited[v2] == False and g[v][v2] == 1:
            dfs(g,v2)

##入力
N, M = map(int,input().split())
#隣接行列を作る
graph = [[0 for i in range(N)] for j in range(N)]
edgelist = [] #辺のリスト
for e in range(M):
    ai, bi = map(int,input().split())
    graph[ai-1][bi-1] = 1
    graph[bi-1][ai-1] = 1
    edgelist.append([ai-1,bi-1])

bridges = 0 #橋の数
#辺を一本ずつ外して連結かどうか判定
for edge in edgelist:
    #辺を削除
    graph[edge[0]][edge[1]] = 0
    graph[edge[1]][edge[0]] = 0
    
    isbridge = False
    visited = [False for i in range(N)]
    dfs(graph, 0)
    
    for i in range(N):
        if visited[i] == False:
            isbridge = True
            break
    if isbridge == True:
        bridges += 1
    
    #削除した辺を戻す
    graph[edge[0]][edge[1]] = 1
    graph[edge[1]][edge[0]] = 1

print(bridges)

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

using namespace std;

int main(){
	long long int n;
	cin >> n;
	long long int ans = 0, val = 0, count = 0;
	for(int i=1;i<=1000000;++i){
		val = val*10 + 7;
		val = val%n;
		count++;
		if(val == 0){
			ans = 1;
			break;
		}
	}	
	(ans == 1)?cout << count:cout << -1;
}


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

int main() {
	int n;
	cin>>n;
	string p="1";
	int zo;
	char oz;
	if(n%2==0)p="0";
	while(n!=0&&n!=1){
	    if(n>0){
	        n=n/-2;
	        zo=-1*(n%-2);
	    }
	    else{
	        n=(n-1)/-2;
	        zo=n%-2;
	    }
	    if(zo==1)oz='1';
	    else oz='0';
	    p=oz+p;
	}
	cout<<p<<endl;
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const ll INF = 1LL << 60;
const double PI = 3.14159265358979;

void solve()
{
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a), t(b);
  for(int i = 0; i < a; ++i) cin >> s[i];
  for(int i = 0; i < b; ++i) cin >> t[i];

  ll x;
  for(int i = 0; i < q; ++i)
  {
    cin >> x;
    int ans = 0;
    auto s_it = lower_bound(s.begin(), s.end(), x);
    auto t_it = lower_bound(t.begin(), t.end(), x);

    int si = distance(s.begin(), s_it);
    int ti = distance(t.begin(), t_it);

    ll sr = INF, tr = INF, sl = -INF, tl = -INF;
    if (s_it != s.end()) sr = *s_it;
    if (t_it != t.end()) tr = *t_it;
    if (s_it != s.begin()) { s_it--; sl = *s_it; }
    if (t_it != t.begin()) { t_it--; tl = *t_it; }
    
    ll straight_dist = INF, turn_dist = INF;

    // min( 左直進, 右直進 )
    straight_dist  = abs( min( x - min(sl, tl), max(sr, tr) - x) );

    // t左->s右
    ll dist_tlsr = abs(x - tl + sr - tl);
    // s左->t右
    ll dist_sltr = abs(x - sl + tr - sl);
    // t右->s左
    ll dist_trsl = abs(tr - x + tr - sl);
    // s右->t左
    ll dist_srtl = abs(sr - x + sr - tl);

    turn_dist = min({dist_tlsr, dist_sltr, dist_trsl, dist_srtl});

    cout << min(straight_dist, turn_dist) << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
string s;
int main(){
  cin >> s;
  if(s[0] == 'S' && s[1] == 'U')cout << 7;
  if(s[0] == 'M')cout << 6;
  if(s[0] == 'T' && s[1] == 'U')cout << 5;
  if(s[0] == 'W')cout << 4;
  if(s[0] == 'T' && s[1] == 'H')cout << 3;
  if(s[0] == 'F')cout << 2;
  if(s[0] == 'S' && s[1] == 'A')cout << 1;
  cout << endl;
}


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

int main(){
    int n,tmp=0;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    int maxnum = -1,minnum =100;
    rep(i,n) maxnum = max(maxnum,x[i]);
    rep(i,n) minnum = min(minnum,x[i]);

    int minenr = 10000000;

    for(int i=minnum;i<=maxnum;i++){
        int pos = i ;
        for(int j=0; j<n;j++) {tmp += pow(x[j]-pos,2);}
        minenr = min(minenr,tmp);
        tmp=0;
    }
    cout << minenr << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;

void solve()
{
	int N, Z, W;
	cin >> N >> Z >> W;
	vector<long long int> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}
	long long int ans = abs(a[N - 1] - W);
	if (N >= 2)
	{
		ans = max(ans, abs(a[N - 2] - a[N - 1]));
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

char S[100005];
int n,m;
pi range[100005];
int ar[100005];

vector<int> R[100005];
void ng(){
  puts("NO");
  exit(0);
}
void ok(){
  puts("YES");
  exit(0);
}

int addval[100005];
int main(){
  scanf("%s",S);
  m=strlen(S);
  REP(i,m/2){
    ar[i]=(S[m-1-i]-(int)S[i]);
    ar[i]=(ar[i]+26)%26;
  }
  int M=m;
  m=m/2;
  if(m==0) ok();
  cin>>n;
  REP(i,n){
    int l,r;scanf("%d%d",&l,&r);
    --l;
    int l2=M-r,r2=M-l;
    chmin(r2,m);
    if(r<=m){
      range[i]={l,r};
    }else if(m<=l){
      range[i]={l2,r2};
    }else{
      range[i]={min(l,l2),max(l,l2)};
    }
  }
  REP(i,n){
    if(range[i].fr<range[i].sc){
      R[range[i].fr].pb(range[i].sc);
    }
  }
  REP(i,m){
    sort(ALL(R[i]));
    R[i].erase(unique(ALL(R[i])),R[i].end());
    int m2=R[i].size();
    REPN(j,m2,1){
      int l=R[i][j-1],r=R[i][j];
      R[l].pb(r);
    }
  }

  int cur=0;

  REP(i,m){
    cur=((cur-addval[i])%26+26)%26;
    if(cur!=ar[i]){
      if(R[i].empty()) ng();
      int r=R[i][0];
      int dif=(ar[i]-cur+26)%26;
      addval[r]+=dif;
      cur=ar[i];
    }
  }
  ok();
  return 0;
}





Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int L=1, R=1e9;
	while(L<R){
		int M=(L+R)/2, cuts=0;
		for(int i=1;i<=n;i++){
			int x=(a[i]+M-1)/M-1;
			cuts+=x;
		}
		if(cuts<=k) R=M;
		else L=M+1;
	}
	cout<<L;
}

Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define pi 3.141592653589793238

ll find(vector<ll> &v, ll a, ll b, ll c){
    if(b < a+c) return 1;
    else return 0;
}

void solve(){
    ll r; cin >> r;
    cout << 2*pi*r << endl;
}

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


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

int n ;
cin>>n;
if(n==1)
{
    cout<<1<<endl;
    return 0;
}
int ans = 1;
while(ans<=n)
{
    ans*=2;
}
cout<<ans/2<<endl;

 return 0;
}


Measured memory_bytes: 3596
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    l = list(map(int, sys.stdin.readline().split()))

    l.sort()

    length = len(l)
    if (length % 2 == 1):
        print(0)
        exit()

    pre = int(length / 2 - 1)
    post = int(length / 2)

    print(l[post] -l[pre])

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

cnt = 0
for i in reversed(range(N)):
  canDefeat = B[i]
  if (canDefeat <= A[i+1]): cnt += B[i]
  else:
    cnt += A[i+1]
    canDefeat -= A[i+1]
    if (canDefeat <= A[i]):
      cnt += canDefeat
      A[i] -= canDefeat
    else:
      cnt += A[i]
      A[i] = 0

print(cnt)


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

#define endl '\n'
using ll = long long int;

void solve(int &T)
{
    ll n;
    cin >> n;
    cout << (n >= 30 ? "Yes" : "No");
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t = 1;
    for(int i = 1; i <= t; i++) {
        solve(i);
    }
    return 0;
}

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

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

  vector<vector<bool>> b(n, vector<bool>(n, true));
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n-1; i++) {
      if (i == k) continue;
      for (int j = i+1; j < n; j++) {
        if (j == k) continue;
        if (a[i][j] > a[i][k] + a[k][j]) {
          cout << -1 << endl;
          return 0;
        }
        if (a[i][j] == a[i][k] + a[k][j]) b[i][j] = false;
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      if (b[i][j]) ans += a[i][j];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
def main():
    import sys
    N = int(input())
    input_2 = sys.stdin.readline
    P_list = list(map(int,input_2().split()))
    i_num = 0
    min_P = P_list[0]
    for p in P_list:
        if p <= min_P:
            min_P = p
            i_num += 1
    print(i_num)

if __name__ == "__main__":
    main()

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

int N;
string S;

void solve(){
    int ans = 0;
    int i = 0;
    while(i < N){
        if(S[i] == 'A'){
            if(i + 2 < N && S[i + 1] == 'B' && S[i + 2] == 'C'){
                ans++;
                i += 3;
                continue;
            }
        }
        i++;
    }
    cout << ans;
}
int main(){
    cin >> N;
    cin >> S;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int c[10005];
int main(){
	int i;
	int a, b, k;
	int n=0;
	
	scanf("%d %d %d", &a, &b, &k);
	for(i=a; i<=b and i-a<k; i++) c[++n]=i;
	for(i=b; i>=a and b-i<k; i--) c[++n]=i;
	sort(c+1, c+1+n);
	for(i=1; i<=n; i++) if(c[i]^c[i-1])
		printf("%d\n", c[i]);
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, ll> mp;
    rep(i, n) {
        ++mp[s[i]];
    }
    ll ans = mp['R'] * mp['G'] * mp['B'];
    for ( int i = 1; i <= n; ++i ) {
        for ( int j = 0; j < n; ++j ) {
            if ( j + 2 * i >= n ) break;
            if ( s[j] != s[j+i] && s[j+i] != s[j+2*i] && s[j+2*i] != s[j] ) {
                --ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int i,j,res,d,m = 0x3f3f3f3f;
    int min[10010];
    char str[13];
    gets(str);
    d=strlen(str);

    for(i=0; i<d-2; i++)
    {
        res=(str[i]-'0')*100+(str[i+1]-'0')*10+(str[i+2]-'0');

        min[i] = abs(753-res);

    }
    for (i=0; i<d-2; i++)
    {
        if(m > min[i])
            m = min[i];
    }

    printf("%d",m);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    double r; cin >> r;
    double pi = 3.141592653589793238;
    cout << setprecision(30)<< pi * r * 2 << endl;
    return 0;
}


Measured memory_bytes: 3800