akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
#define int long long
signed main(){
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int ans=0;
  string s;
  cin>>s;
  for(int i=0; i<s.size(); i++){
    if(i%2==0 && s[i]=='L'){
      ans=1;
      break;
    }
    else if(i%2==1 && s[i]=='R'){
      ans=1;
      break;
    }
  }
  if(ans==0) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=998244353;

struct p{ll gb,cnt,rui;};
p dp[3005][3005];
void f(p &a,p b){
  a={(a.gb+a.rui*a.cnt+b.gb+b.rui*b.cnt)%MOD,0,(a.rui+b.rui)%MOD};
}
int g(p a){
  return a.gb+a.rui*a.cnt%MOD;
}
ll n,s,ans;

signed main(){
  cin>>n>>s;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n;i++){
    f(dp[i+1][v[i]],{0,1,i+1});
    for(int j=1;j<=s;j++){
      if(j+v[i]<=s)f(dp[i+1][j+v[i]],dp[i][j]);
      f(dp[i+1][j],dp[i][j]);
    }
    ans+=g(dp[i+1][s]);
  }
  cout<<ans%MOD<<endl;
}


Measured memory_bytes: 211584
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

// 最大公約数
long long gcd(long long a, long long b){
    if (a < b){
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}
// 最小公倍数
long long lcm(long long a, long long b){
    return a * b / gcd(a, b);
}

using llong = long long;
using namespace std;

int main(){
    llong a,b,c,d,c_count,d_count,dob_count;
    cin >> a >> b >> c >> d;
    c_count = b/c - a/c;
    d_count = b/d - a/d;
    dob_count = b/lcm(c,d) - a/lcm(c,d);
    if(a%c == 0) c_count++;
    if(a%d == 0) d_count++;
    if(a%lcm(c,d) == 0) dob_count++;
    cout << b-a+1 - c_count - d_count + dob_count << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  string w;
  int u=0;
  cin >> w;
  int size = w.length();
  int a[26];
  for(int i=0;i<26;i++){
    a[i]=0;
  }
  for(int i=0;i<size;i++){
    a[(int)w[i]-97] +=1;
  }
  
  for(int i=0;i<26;i++){
    if(a[i]%2==1) u=1;
  }
  if(u==1) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  
}

Measured memory_bytes: 256
n,m,x=gets.split.map &:to_i
arr=gets.split.map &:to_i
mid=n.to_f/2
a_l=arr.select{|i|i>x}
a_r=arr.select{|i|i<x}
b_a=a_l.size<a_r.size ?a_l:a_r
puts b_a.size

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

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

    rep(i, n) {
        ll a;
        cin >> a;
        if (a % 2 == 1) {
            cout << "first" << endl;
            ret();
        }
    }
    cout << "second" << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <int64_t MOD>
class Modint {
  using Self = Modint<MOD>;

  int64_t m_value;

 public:
  Modint(int64_t value) : m_value((value % MOD + MOD) % MOD) {}
  Self pow(int64_t e) const {
    if (e == 0) {
      return (Self)1;
    } else if (e % 2 == 0) {
      return ((*this) * (*this)).pow(e / 2);
    } else {
      return (*this).pow(e - 1) * (*this);
    }
  }
  Self inv() const { return pow(MOD - 2); }
  Self& operator=(const Self& rh) {
    m_value = rh.m_value;
    return *this;
  }
  Self operator-() const { return Self(-m_value); }
  Self operator+(const Self& other) const {
    return Self(m_value + other.m_value);
  }
  Self operator-(const Self& other) const {
    return Self(m_value - other.m_value);
  }
  Self operator*(const Self& other) const {
    return Self(m_value * other.m_value);
  }
  Self operator/(const Self& other) const { return (*this) * other.inv(); }
  Self& operator+=(const Self& rh) { return (*this) = (*this) + rh; }
  Self& operator-=(const Self& rh) { return (*this) = (*this) - rh; }
  Self& operator*=(const Self& rh) { return (*this) = (*this) * rh; }
  int64_t value() const { return m_value; }
};

int main() {
  int N, K;
  cin >> N >> K;

  using Mint = Modint<1'000'000'007>;
  vector<Mint> dp(K + 1, 0);
  Mint result = 0;
  for (int d = K; d >= 1; d--) {
    dp[d] = Mint(K / d).pow(N);
    for (int j = 2 * d; j <= K; j += d) {
      dp[d] -= dp[j];
    }
    result += dp[d] * d;
  }
  cout << result.value() << endl;

  return 0;
}

Measured memory_bytes: 3996
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<set>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#include<vector>
#include <type_traits>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef pair<ll, ll>P;
template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

ll par[100000], depth[100000];
static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}
#define yo 100001
typedef pair<double, double> dop;
//------------------変数-----------------------//
ll n, m, hoge[100000];
//-------------------関数----------------------//


int main() {
	fill_all(hoge, -1);
	cin >> n;
	ll cnt = 0;
	REP(i, n) {
		ll a; cin >> a;
		if (hoge[a - 1] >= 0) { if (hoge[a - 1] == i+1) { cnt++; } }
		hoge[i] = a;
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 1024
a,b=map(int,input().split())
account=0
wacount=0
acbox=[0]*(a+1)
wabox=[0]*(a+1)
for i in range(b):
  p,q=input().split()
  p=int(p)
  if q=="WA":
    if acbox[p]==0:
      wabox[p]+=1
  else:
    if acbox[p]==0:
      account+=1
      wacount+=wabox[p]
      acbox[p]=+1
print(account,wacount)

Measured memory_bytes: 4724
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int a , b , c ;
        cin >> a >> b >> c ;
        vector<int> v;
        v.push_back(a);
        v.push_back(b);
        v.push_back(c);
        sort(v.begin(), v.end());
        if(v[0] == 5 && v[1] == 5 && v[2] == 7 ){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
        return 0;
    }

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

using namespace std;

typedef pair<long long, long long> ii;
int n, m;
long long inf = (1ll << 61);
long long tree[200005];

void update(int i, long long v){
	i += n;
	tree[i] = v;
	while(i > 1){
		i /= 2;
		tree[i] = min(tree[i<<1],tree[i<<1|1]);
	}
}

long long query(int l, int r){
	long long ans = inf;
	for(l += n, r += n;l < r;l>>=1,r>>=1){
		if(l&1){
			ans = min(ans,tree[l]);
			l++;
		}
		if(r&1){
			r--;
			ans = min(ans,tree[r]);
		}
	}
	return ans;
}
int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	
	vector<ii> stuff[n];
	
	for(int i = 0;i < m;i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		stuff[b].push_back(ii(a,c));
	}
	
	for(int i = 1;i < n;i++){
		update(i,inf);
	}
	
	update(0,0);
	
	for(int i = 0;i < n;i++){
		if(stuff[i].size() == 0) continue;
		long long ans = inf;
		for(ii x : stuff[i]){
			ans = min(ans, query(x.first, i) + x.second);
		}
		update(i,ans);
		//cout << i << " " << ans << "\n";
	}
	//cout << inf << "\n";
	long long ans = query(n-1,n);
	if(ans >= inf) cout << -1;
	else cout << ans;
	
}


Measured memory_bytes: 7168
X, N = map(int, input().split())
p = set()
if N != 0:
    p = set(map(int, input().split()))
pp = sorted(list({i for i in range(102)} - p))
ans = -100
for i in pp:
    if abs(X - ans) > abs(X - i):
        ans = i
print(ans)

Measured memory_bytes: 61912
#include<stdio.h>
int main(void)
{
	int x[10000];
	int i=0;
	for(i=0;i<10000;i++){
		scanf("%d",&x[i]);
		if(x[i]==0){
			break;
		}
		printf("Case %d: %d\n",i+1,x[i]);
	}
	return 0;
}

Measured memory_bytes: 2692
#include<iostream>
#include<algorithm>
#include<cmath>

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

int H, W, D;
P pos[90001];

ll cost[90001];

int getdis(P a, P b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

void calc_cost() {
	for (int i = 1; i <= H * W; i++) {
		if (i - D >= 1) {
			cost[i] = cost[i - D] + getdis(pos[i], pos[i - D]);
		}
		else {
			cost[i] = 0;
		}
	}
}

int main() {
	
	cin >> H >> W >> D;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++) {
			int a;
			cin >> a;
			pos[a] = P(i, j);
		}
	}

	calc_cost();

	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		if(l != r)
			cout << cost[r] - cost[l] << endl;
		else cout << 0 << endl;
	}

	return 0;
}

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

#define MAX 200000

int N;
long long T;
long long t[MAX];

int main()
{
	cin >> N >> T;
	for( int i = 0; i < N; i++ ) {
		cin >> t[i];
	}

	long long ans = 0;
	long long tt = 0;
	for( int i = 0; i < N; i++ ) {
		if( i == 0 ) {
			ans += T;
			tt = t[i] + T;
		}
		else {
			if( t[i] < tt ) {
				ans += T - (tt - t[i]);
			}
			else {
				ans += T;
			}
			tt = t[i] + T;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int N = 0, a, b, c, d = 0;
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a >> b >> c;
		if (a < b){
			d = a;
			a = b;
			b = d;
			d = 0;
		}
		if (a < c){
				d = a;
				a = c;
				c = d;
				d = 0;
		}
		if (a*a == b*b + c*c){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main(){
    char S[101];
    long long int K, x=0;
    int i, len, s;

    scanf("%s", S);
    scanf("%lld", &K);

    len = strlen(S);

    for(i=0; i<len; i++){
        s = S[i] - '0';
        x += pow(s, 5000000000000000);
        if(K <= x || x < 0)
            break;
    }

    printf("%d\n", s);

    return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

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

#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v;}
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) {cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}

#define all(x)  (x).begin(),(x).end()
#define tr(c, it)   for(auto it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))
#define forn(i, n)   for(int i=0; i<n; i++)

const double eps = 1e-5;
const int INF = 0x3f3f3f3f;

int c0, c1;
int p, n;

LL fun(int n, int m)
{
    if(m == 0)  return 1;

    LL ret = 1;
    for(int i=1; i<=(n - m); i++)
    {
        ret = ret * (i + m) / i;
    }
    return ret;
}


int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif

    //scanf("%d",&T);


    while(cin >> n >> p)
    {
        c0 = c1 = 0;
        for(int i=1; i<=n; ++i)
        {
            int v;
            cin >> v;
            if(v % 2 == 0) c0++;
            else c1 ++;
        }

        LL ans = (1ll << c0);
        if(p == 0)
        {
            LL vv = 0;
            for(int i=0; i<=c1; i+=2)
            {
                LL v = fun(c1, i);
                vv += v;
            }
            //debug(vv);
            ans *= vv;
        }
        else
        {
            if(c1 == 0)
            {
                ans = 0;
            }
            else
            {

                LL vv = 0;
                for(int i=1; i<=c1; i+=2)
                {
                    LL v = fun(c1, i);
                    vv += v;
                }
                ans *= vv;
            }

        }

        cout << ans << endl;


    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
using namespace std;
int main(){
    int n,w;
    while(1){
        int v[100];
        cin>>n>>w;
        if(n+w==0)break;
        int ma=-1,ma1=-1;
        REP(i,n)cin>>v[i];
        REP(i,n)ma=max(v[i],ma);
        int wp=ma/w;
        int cnt[wp+1];
        REP(i,wp+1)cnt[i]=0;
        REP(i,n)cnt[v[i]/w]++;
        double ans=0.01;
        REP(i,wp+1)ma1=max(ma1,cnt[i]);
        REP(i,wp+1){
            ans+=(double)cnt[i]/(double)ma1*(double)(1.0-(double)i/(double)wp);
        }
        printf("%.10f\n",ans);
    }
}

Measured memory_bytes: 3164
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
 
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    int k=0;
    REP(i,h-k){
        int count = 0;
        cin >> a[i];
        REP(j,w){
            if(a[i][j] == '.'){
                count++;
            }
        }
        if(count == w){
            i--;
            k++;
        }
    }
    int t=0;
    REP(j,w-t){
        int count =0;
        REP(i,h-k){
            if(a[i][j]=='.'){
                count++;
            }
        }
        if(count == h-k){
            REP(i,h-k){
                a[i].erase(a[i].begin()+j);
            }
            j--;
            t++;
        }
    }
    REP(i,h-k){
            cout << a[i] << endl;
    }


    
    return 0;
}

Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
s = gets
f = (n%2 == 0)
(n/2).times do |i|
  f = false unless s[i] == s[i+n/2]
end
puts (f)? "Yes" : "No"

Measured memory_bytes: 1788
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        PriorityQueue<Task> queue = new PriorityQueue<>();
        
        for(int i = 0; i < N; i++){
            int requireTime = sc.nextInt();
            int deadLine = sc.nextInt();
            queue.add(new Task(requireTime, deadLine));
        }
        
        boolean isOK = true;
        int elapsedTime = 0;
        
        while(!queue.isEmpty()){
            Task task = queue.poll();
            
            if( elapsedTime <= task.deadLine - task.requireTime ){
                elapsedTime += task.requireTime;
            } else {
                isOK = false;
                break;
            }
        }
        
        System.out.println( isOK ? "Yes" : "No" );
        
    }
    
    static class Task implements Comparable<Task> {
        int requireTime;
        int deadLine;
        
        public Task(int requireTime, int deadLine){
            this.requireTime = requireTime;
            this.deadLine = deadLine;
        }
        
        public int compareTo(Task other){
            return this.deadLine - other.deadLine;
        }
    }
}


Measured memory_bytes: 104852
/**
 * @Author:      G_bg
 * @DateTime:    2019-09-28 20:09:19
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
int main(int argc, const char *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    int n,k;cin >> n >> k;
    int x,sum = 0;
    for(int i = 0;i < n;++i){
        cin >> x;
        if(x >= k) ++sum;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

N, M = map(int,stdin.readline().rstrip().split())
switchList=[]
for i in range (M):
  switchList.append(list(map(int, stdin.readline().rstrip().split())))
pList = list(map(int, stdin.readline().rstrip().split()))

methodCounter=0
for i in range(2**N):
  lightOnCounter=0
  for j in range (M):
    k = switchList[j][0]
    onCounter=0
    for l in range (1,k+1,1):
      switch=switchList[j][l]
      bit = 1 << switch-1
      if (i & bit) != 0:
        onCounter+=1
    if onCounter %2 == pList[j]:
      lightOnCounter+=1
  if lightOnCounter == M:
    methodCounter+=1
print(methodCounter)

Measured memory_bytes: 41584
#include<iostream>
using namespace std;
int main(){
  int x;
  int a;
  int min=1000000000;
  int max=0;
  cin>>x;
  for(int i=0;i<x;i++){
    cin>>a;
    if(a<min)
      min=a;
    if(a>max)
      max=a;
  }
  cout<<max-min<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
priority_queue<pint,vector<pint>,greater<pint> >q;
int n,L,l[MAXN],r[MAXN];ll lf[MAXN],rf[MAXN],f1[MAXN],f2[MAXN];
vector<int>S1,S2;
inline void add(int x,int y){r[l[y]=x]=y;}
inline ll Solve(int x){
	ll res=0,tmp=0;int len=S2.size(),lb=l[S2[0]],rb=r[S2[len-1]];
	for(int i=0;i<len;i++)(i-L+1>=0?tmp+=lf[S2[i-L+1]]:0),res+=rf[S2[i]]*tmp;
	for(int i=0;i<len;i++)f1[S2[i]]=lf[S2[i]],f2[S2[i]]=rf[S2[i]],lf[S2[i]]=rf[S2[i]]=0;
	int cnt=len/L;
	if(cnt){
		for(int i=L-1;i<len;i++){int t=(i+1)/L-1;rf[S2[t]]+=f2[S2[i]];}
		for(int i=len-L;i>=0;i--){int t=cnt-(len-i)/L;lf[S2[t]]+=f1[S2[i]];}
		for(int i=1;i<cnt;i++)add(S2[i-1],S2[i]);add(lb,S2[0]),add(S2[cnt-1],rb);
		for(int i=0;i<cnt;i++)q.push(mk(x+1,S2[i]));tmp=0;
		for(int i=0;i<cnt;i++)(i-L+1>=0?tmp+=lf[S2[i-L+1]]:0),res-=rf[S2[i]]*tmp;
	}else r[lb]=n+1,l[rb]=0;S2.clear();
	return res;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),L=read();
	Rep(i,1,n){int x=read();q.push(mk(x,i)),add(i,i+1),lf[i]=rf[i]=1;}
	add(0,1);ll ans=0;
	for(;!q.empty();){
		int x=q.top().fir;S1.clear();
		for(;!q.empty()&&q.top().fir==x;q.pop())S1.push_back(q.top().sec);
		S2.clear();S2.push_back(S1[0]);
		for(int i=1,len=S1.size();i<len;i++){if(r[S1[i-1]]!=S1[i])ans+=Solve(x);S2.push_back(S1[i]);}
		ans+=Solve(x);
	}cout<<ans+n<<'\n';
	return 0;
}




Measured memory_bytes: 13836
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 5000
#define MAXH 4
#define MAXM 4
#define INF 1LL << 62
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 1005;

int main(){
	int n;
	ll b,a;
	fast_io();
	cin >> n >> a >> b;
	a-=b;
	ll v[n];
	cu(i,0,n)cin >> v[i];
	ll l = 0, r = 1e9+1, m;
	ll ans = MOD;
	while(l <= r){
		m = l + (r-l)/2;
		ll cnt = 0;
		cu(i,0,n){
			cnt += max((v[i] - b * m + a - 1)/a, 0LL);	
		}
		if(cnt > m)l = m + 1;
		else{
			ans = m;
			r = m - 1;
		}
	}
	cout << ans << '\n';
}


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

int main(){
  int a;
  cin >> a;
  int b[a];
  for(int i = 0; i < a; i++){
    cin >> b[i];
  }
  int x = 0;
  for(int i = 0; i < a; i++){
  	for(int j = i + 1; j < a; j++){
    	x += b[i] * b[j];
    }
  }
  cout << x << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,a[110000];
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  int ans = 0;
  rep(i,n)ans ^= a[i];
  cout << (ans%2 ? "NO" : "YES") << endl;
}


Measured memory_bytes: 1024
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val n, m = Scanner.nextInt
	val h = Array.fill(n)(Scanner.nextInt)

	val path = Array.fill(n)(Nil: List[Int])

	loop(0, m) { _ =>
		val a, b = Scanner.nextInt - 1

		path(a) = b :: path(a)
		path(b) = a :: path(b)
	}

	pw.println( (0 until n).filter{ i => path(i) forall { j => h(j) < h(i) } }.size )
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 70604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

struct LowLink {
    vector<P> bridge;
    vector<int> ord,low;
    vector<bool> used;
    vector<vector<int>> g;
    int n, k = 0;
    LowLink(const vector<vector<int>> &g) : g(g) {
        n = g.size();
        ord.resize(n, -1);
        low.resize(n, -1);
        used.resize(n, false);
    }
    void dfs(int v, int pre) {
        used[v] = true;
        ord[v] = k++;
        low[v] = ord[v];
        for(auto &to : g[v]) if(to != pre) {
            if(!used[to]) {
                dfs(to, v);
                low[v] = min(low[v], low[to]);
                if(low[to]>ord[v]) {
                    bridge.emplace_back(min(v,to), max(v,to));
                }
            }
            else {
                low[v] = min(low[v], ord[to]);
            }
        }
    }
};

int main() {
    int n,m; cin >> n >> m;
    vector<vector<int>> g(n);
    REP(i,m) {
        int a,b; cin >> a >> b; a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    LowLink ans(g);
    ans.dfs(0,-1);
    cout << ans.bridge.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	string s,ans;
	int a=0;
	cin>>n>>s;
	ans=s;
	for(int i=0;i<n;i++){
		if(s[i]=='('){
			a--;
		}
		else{
			a++;
		}
		if(a>0){
			ans="("+ans;
			a--;
		}
	}
	
	for(int i=0;i<abs(a);i++){
		ans=ans+")";
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let list_of_string str = range 0 (String.length str) |> List.map (fun i -> str.[i])
let array_of_string str = Array.init (String.length str) (fun i -> str.[i])

let () =
  let arr = scanf "%d" (fun n -> Array.init n (fun _ -> scanf " %s" (fun s -> s.[0]))) in
  let ct = [|'M'; 'A'; 'R'; 'C'; 'H'|] |> Array.map (fun c ->
    arr |> Array.map (fun x -> if x = c then 1 else 0) |> Array.fold_left (+) 0) in
  for_iter 0 5 (fun x -> for_iter (x+1) 5 (fun y -> for_iter (y+1) 5 (fun z ->
    ct.(x) * ct.(y) * ct.(z)) |> List.fold_left (+) 0) |> List.fold_left (+) 0)
  |> List.fold_left (+) 0 |> printf "%d\n"


Measured memory_bytes: 7424
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double  D=sc.nextDouble();
    double  T=sc.nextDouble();
    double  S=sc.nextDouble();

if(D/S<=T){System.out.println("Yes");
}else{
  System.out.println("No");
}

}
}


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

#define ll long long
#define pb push_back
#define N 1000000007
#define nmax 200001
#define pll pair<ll,ll>
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

ll extended_gcd(ll a, ll b, ll &x, ll &y) {
	if(a==0) {
		x = 0;
		y = 1;
		return b;
	}

	ll x1,y1;
	ll gcd = extended_gcd(b%a,a,x1,y1);

	x = y1 - (b/a)*x1;
	y = x1;

	return gcd;
}

ll solve(vector<vector<ll>> &dp, vector<vector<ll>> &adj, ll idx, ll mask) {

	ll n = adj.size();
	if(mask==0)
		return 1;

	if(dp[idx][mask]!=-1)
		return dp[idx][mask];

	ll res = 0;

	for(ll i=0;i<n;i++) {
		if((mask & (1<<i)) != 0 && adj[idx][i]) {
			res = (res + solve(dp,adj,idx-1,mask^(1<<i)))%N;
		}
	}

	dp[idx][mask] = (res+N)%N;
	return dp[idx][mask];
}

int main() {
    
   	ll n; cin>>n;
   	vector<pair<ll,ll>> vec(n);
   	for(int i=0;i<n;i++) {
   		scanf("%lld",&vec[i].first);
   	}

   	for(int i=0;i<n;i++) {
   		scanf("%lld",&vec[i].second);
   	}

   	vector<ll> vals(n,0); 

   	ll base = 1;
   	while(base<n)
   		base*=2;

   	vector<ll> tree(2*base,0);
   	ll maxi = 0;
   	for(int i=0;i<n;i++) {
   		
   		ll a = vec[i].first;
   		ll b = vec[i].second;

   		ll best = 0, x = base+a-1;

   		while(x>1) {
   			if(x%2==1)
   				best = max(best, tree[x-1]);
   			x/=2;
   		}
   		
   		vals[a-1] = b+best;

		x = base+a-1;

   		while(x>=1) {
   			tree[x] = max(vals[a-1], tree[x]);
   			x/=2;
   		}	
   		
   		maxi = max(maxi, vals[a-1]);
   	}

   	cout<<maxi<<endl;

	return 0;
}


 

Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;

string s;
ll ans=0,x=1,y=1;
ll dp[2][202020]={0};

signed main(){
    cin>>s;
    
    dp[0][0]=1;
    for(int i=0;i<s.length();++i){
        if(s[i]=='1'){
            dp[0][i+1]+=2*dp[0][i];
            dp[0][i+1]%=MOD;
            dp[1][i+1]+=dp[0][i];
        }
        else{
            dp[0][i+1]+=dp[0][i];
            dp[0][i+1]%=MOD;
        }
        dp[1][i+1]+=dp[1][i]*3;
        dp[1][i+1]%=MOD;
    }


    cout<<(dp[0][s.length()]+dp[1][s.length()])%MOD<<endl;

    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  for( int i=A; i<(B+A); i+=(A-1)){
    
    if(B==1){
      cout << 0 << endl;
      break;
    }
    
    else if(i==B){
      cout << (B-1)/(A-1) << endl;
      break;
    }
    
    else if(i>B){
      cout << (i-1)/(A-1) << endl;
      break;
    }
  }
}
  
  

Measured memory_bytes: 256
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string.h>
#include<algorithm>

int main() {

	int a, b, c, d, e, k;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	scanf("%d", &e);
	scanf("%d", &k);

	if (e - d <= k && e - c <= k && e - b <= k && e - a<= k && d - c <= k && d - b <= k && d - a <= k && c - b <= k && c - a <= k && b - a <= k)puts("Yay!");
	else puts(":(");



	return(0);
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) {
    int xi; cin >> xi;
    x[i] = xi;
    y[i] = xi;
  }
  sort(y);

  int midi = (n - 1) / 2, right = y[midi + 1];
  rep(i, n) {
    if (x[i] > y[midi] || right == y[midi]) outl(y[midi]);
    else outl(right);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 3840
#include<iostream>
using namespace std;
int main(void){
  int n,a[3000],f=0,max=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    max+=a[i]-1;
  }
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>

class AABC333 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int a,b;
        std::cin >> a >> b;
        std::string ans;
        if( (a*b) % 2 == 0 ){
            ans = "No";
        } else{
            ans = "Yes";
        }
        std::cout << ans << std::endl;
	}
};


int main() {
	AABC333 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())

if a < b:
    position_A = a + (v * t)
    position_B = b + (w * t)
    if position_B <= position_A:
        print("YES")
    else:
        print("NO")
else:
    position_A = a + (-v * t)
    position_B = b + (-w * t)
    if position_B >= position_A:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
const int N=220000;
string s;
int l[N],r[N];
int n,k,c;
int main(){
	cin>>n>>k>>c>>s;int i=1,kk=1;
	while(kk<=k){
		if(s[i-1]=='o')l[kk++]=i,i+=c;
		++i; 	}	
	i=n,kk=k;
	while(kk){
		if(s[i-1]=='o')r[kk--]=i,i-=c;
		--i; 
	}
	
	for(i=1;i<=k;++i)if(l[i]==r[i])printf("%d\n",l[i]);
	
	return 0;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long 
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

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

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e5 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N+2];
vector< vector<int> > adj;
int dp[N][3];

int dfs(int id, int p, int pc)
{     
      int ans = 0, f = 0;
      int &mafia = dp[id][pc];
      if( mafia != -1 ) return mafia;
      
      int a1 = 1;
      for(auto i: adj[id])
      {
            if( i != p )
            {     
                  f++;
                  a1 *= dfs(i, id, 0);
                  a1 %= M;
            }
      }
      int a2 = 0;

      if(pc != 1)
      {     
            a2 = 1;
            for(auto i: adj[id])
            {     
                  if( i != p )
                  {
                        a2 *= dfs(i, id, 1);
                        a2 %= M;
                  }
            }
      }

      return mafia = (a1 + a2)%M;
      
}
void solve()
{
      cin >> n;
      adj.resize(n+1);
      memset(dp, -1, sizeof dp);
      lop(i,0,n-1)
      {
            int u, v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
      }

      cout << dfs(1,0,3) << endl;

      
}


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

      int t = 1;
      //cin >> t;
      while(t--) solve();

}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 20992
N=int(input())
#people
li = list(map(int, input().split()))
Ave1=sum(li)//N
Ave2=sum(li)//N+1
S1=0
S2=0
for i in range(N):
  S1=S1+(Ave1-li[i])**2
for i in range(N):
  S2=S2+(Ave2-li[i])**2

if S1>S2:
  print(S2)
else:
  print(S1)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

inline int read(){
  int x = 0, fh = 1; char ch;
  for(; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
  for(; isdigit(ch); ch = getchar()) x = (x<<1) + (x<<3) + (ch^'0');
  return x * fh;
}

int sum_2, sum_4;
int main(){
	int n = read();
	For (i, 1, n) {
		int val = read();
		if (val % 4 == 0) ++sum_4;
		else if (val % 2 == 0) ++sum_2;
	}
	int rest = n - sum_4 - sum_2 + (sum_2 != 0 ? 1 : 0);
	
	if (rest <= sum_4 + 1) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d;
    int p,q;
    cin>>l>>r>>d;
    int cnt =0;
    for(int i=l;i<=r;i++)
 {
     if(i%d==0)
        cnt++;
 }
    cout<<cnt<<endl;

}



Measured memory_bytes: 3616
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] != L[j] and L[j] != L[k] and L[i] + L[j] > L[k]:
                ans += 1
                
print(ans)


Measured memory_bytes: 9184
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x = iterator.next().unwrap().chars().next().unwrap();
    let y = iterator.next().unwrap().chars().next().unwrap();

    let a = vec!['A', 'B', 'C', 'D', 'E', 'F'];

    let xp = a.iter().position(|c| *c == x).unwrap();
    let yp = a.iter().position(|c| *c == y).unwrap();

    if xp < yp {
        "<".to_string()
    } else if xp > yp {
        ">".to_string()
    } else {
        "=".to_string()
    }
}


Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61)
typedef long long int ll;

int main() {
	int K;
	cin >> K;
	int e = K / 2;
	int o = K - e;
	cout << e * o << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define cnt first
#define sum second
using namespace std;
typedef long long ll;
const int N = 2e5+1;


int k,n,a[N],cnt[N];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),cnt[a[i]]--;
	sort(cnt,cnt+n+1);
	ll ans=0;
	for(int i=0;i<k;++i)ans-=cnt[i];
	cout<<n-ans;
}

Measured memory_bytes: 1920
hash = {3=> 100000, 2=> 200000, 1=>300000}
winner = 400000

X,Y = gets.chomp.split(' ').map{|n| n.to_i}

sum = 0
if X < 4 then
  sum = sum + hash[X]
end
if Y < 4 then 
  sum = sum + hash[Y]
end

if X == Y && X == 1 then
  sum += winner
end

puts sum

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] atgs){


		//??????????????°
		Scanner sc;
		int y;
		int a;
		int b;
		int c;

		sc = new Scanner(System.in);		//?????????????????§??\????????????

		y = sc.nextInt();		//???????????°

		for(int i = 0;i < y ; i++){
			a = sc.nextInt();		//??\???????????????????????°?????\??????
			b = sc.nextInt();
			c = sc.nextInt();

			a = a * a;
			b = b * b;
			c = c * c;

			if(c == a + b){
				System.out.println("YES");
			}else if(b == a + c){
				System.out.println("YES");
			}else if(a == b + c){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 33312
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x,y;
    cin>>x>>y;
    int ans=1; 
    for(int i=0;;i++){
      if(x*2<=y){
        ans++;
        x=x*2;
      }
      else{
        break;  
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
private static Scanner s = new Scanner(System.in);
static int[] color;
static int[] f;
static int[] d;
static int[][] list;
static int time;
public static void main(String[] args) {
	int n = s.nextInt();
	int u,k,v;
	d = new int[n];
	f = new int[n];
	color = new int[n];
	list = new int[n][n];

	for(int i = 0;i < n;i++) {
		u = s.nextInt();
		k = s.nextInt();
		while(k > 0) {
			v = s.nextInt();
			list[u-1][v-1] = 1;
			k--;
		}
	}
	dfs(n);
	for(int i = 0;i < n;i++) {
		System.out.println(i+1 + " " + d[i] + " " + f[i]);
	}

}

static void dfs(int n) {
	for(int i = 0;i < n;i++) {
		color[i] = 0;
	}
	time = 0;
	for(int i = 0;i < n;i++) {
		if(color[i] == 0) {
			visit(n,i);
		}
	}
}

static void visit(int n,int u) {
	color[u] = -1;
	d[u] = ++time;
	for(int i = 0;i < n;i++) {
		if(color[i] ==0 && list[u][i] ==1 ) {
			visit(n,i);
		}
	}
		color[u] = 1;
		f[u] = ++time;

}
}




Measured memory_bytes: 27992
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
for i in range(N):
  if i != 0 and i != (N-1):
  	A[i] = min(B[i-1], B[i])
  elif i == 0:
    A[i] = B[i]
  else:
    A[i] = B[i-1]
print(sum(A))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll dp[2][110000];
int main()
{
  ll i,w[110],v[110],j,W,N;
  cin>>N>>W;
  for(i=0;i<N;i++)
  {
    cin>>w[i]>>v[i];
}
   for(j=0;j<N;j++)
 {
 if (j%2)
        {
     for(i=0;i<=W;i++)
    {
    if(i<w[j])
     dp[1][i]=dp[0][i];
    else
  dp[1][i]=max(dp[0][i],dp[0][i-w[j]]+v[j]);
}}
  else
  {
   for(i=1;i<=W;i++)
    {
    if(i<w[j])
   dp[0][i]=dp[1][i];
    else
  dp[0][i]=max(dp[1][i],dp[1][i-w[j]]+v[j]);
}
}
  
}    
    if(N%2)
    {
     j=dp[0][0];
  for(i=1;i<=W;i++)
        {
     j=max(j,dp[0][i]);
}}
 else
 {
 j=dp[1][0];
  for(i=1;i<=W;i++)
        {
     j=max(j,dp[1][i]);
}
     
}
 cout<<j;       }

Measured memory_bytes: 1792
n = input()
s = range(1,14)
h = range(1,14)
c = range(1,14)
d = range(1,14)


for i in range(n):
    a = raw_input().split()
    num = int(a[1])
    if a[0] == "S":
        s.remove(num)
    elif a[0] == "H":
        h.remove(num)
    elif a[0] == "C":
        c.remove(num)
    elif a[0] == "D":
        d.remove(num)


for i in range(len(s)):
    print "S",s[i]
for i in range(len(h)):
    print "H",h[i]
for i in range(len(c)):
    print "C",c[i]
for i in range(len(d)):
    print "D",d[i]

Measured memory_bytes: 6496
import math
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a, b = map(int, input().split())
print(math.ceil((a+b)/2))


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

int main(){
    int N;
    int C[22],V[22],S[22];
    int i;
    int ans = 0;
    cin >> N;
    for(i=0;i<=N-1;i++)
        cin >> V[i];
    for(i=0;i<=N-1;i++)
        cin >> C[i];
    for(i=0;i<=N-1;i++)
        S[i] = V[i] - C[i];
    for(i=0;i<=N-1;i++)
        if(S[i] > 0) ans += S[i];
    cout << ans << endl;
}


Measured memory_bytes: 256
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)

Measured memory_bytes: 122808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n);
    rep(i,n) cin>>A[i];
    int ans=0;
    rep(i,n) if((i+1)%2==1&&A[i]%2==1) ans++;
    cout<<ans;
}

Measured memory_bytes: 3620