akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long int ll;
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	map<int,int> even,odd;
	for(int i = 0; i < n; i++){
		if(i%2==0) odd[v[i]]++;
		else even[v[i]]++;
	}

	int even_1=0,even_2=0,odd_1=0,odd_2=0;
	int e1=0,e2=0,o1=0,o2=0;
	int cnt = 0;
   
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;//「->」はポインタからクラスのメンバ変数にアクセスするための演算子
			even_1 = itr->first;
		}
	}
	e1 = cnt;
	cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt && itr->first != even_1){
			cnt = itr->second;
			even_2 = itr->first;
		}
	}
	e2 = cnt;

	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			odd_1 = itr->first;
		}
	}
	o1= cnt;
	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt && itr->first != odd_1){
			cnt = itr->second;
			odd_2 = itr->first;
		}
	}
	o2=cnt;

	if(even_1 == odd_1){
		cout << min(n-e1-o2, n-e2-o1) << endl;
	}else{
		cout << n-e1-o1 << endl;
	}

	return 0;
}


Measured memory_bytes: 5376
S = input()
N = len(S)
flag = True
if S != S[::-1]: flag = False
S1 = S[0:(N-1)//2]
if S1 != S1[::-1]: flag = False
S2 = S[(N+3)//2-1:N]
if S2 != S2[::-1]: flag = False

if flag is True:
  print("Yes")
else:
  print("No")

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

int ss[30005];

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans=0;
    for(int j=0;j<n;j++){
        ss[j]=s[j]-'0';
    }
    for(int i=0;i<1000;i++){
        int d[3]={i/100,(i%100)/10,i%10};
        int pos=0;
        for(int j=0;j<n;j++){
            if(ss[j]==d[pos]) pos++;
            if(pos>2){ans++;break;}
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    rep(i, k+1) {
        rep(j, k+1) {
            int rem = s-i-j;
            if (rem < 0) break;
            if (i+j+rem == s && rem <= k) ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

/*
    SegmentTree<int> seg(f, def) のように宣言する
    RMQ の場合 : 
    auto f = [](int a, int b){return min(a, b);};
    int def = INF;
*/
template <typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;
    int n;
    vector<Monoid> dat;
    F f;
    Monoid def;

    SegmentTree(F f, Monoid def) : f(f), def(def) {}

    void build(const vector<Monoid> & vec){
        int siz = vec.size();
        n = 1;
        while(n < siz) n *= 2;
        dat.assign(2 * n - 1, def);
        for(int i = 0; i < siz; i++) dat[n - 1 + i] = vec[i];
        for(int i = n - 2; i >= 0; i--) dat[i] = f(dat[2 * i + 1], dat[2 * i + 2]);
    }

    void update(int k, Monoid x){
        k += (n - 1);
        dat[k] = x;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    Monoid query(int a, int b){
        return query(a, b, 0, 0, n);
    }

private:
    Monoid query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return def;
        if(a <= l && r <= b) return dat[k];
        Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
};

signed main(){
    int n;
    ll c;
    cin >> n >> c;
    vector<P> v(n + 1);
    v[0].first = 0;
    v[0].second = 0;
    REP(i,n){
        cin >> v[i + 1].first >> v[i + 1].second;
    }
    vector<ll> rmn(n + 1), rmx(n + 1);
    ll lsum = 0;
    rmn[0] = 0;
    rmx[0] = 0;
    for(int i = 1; i <= n; i++){
        ll t = c - v[n + 1 - i].first;
        lsum += v[n + 1 - i].second;
        rmn[i] = lsum - t;
        rmx[i] = lsum - 2 * t;
    }
    auto f = [](ll a, ll b){return max(a, b);};
    SegmentTree<ll> segmn(f, -LINF), segmx(f, -LINF);
    segmn.build(rmn);
    segmx.build(rmx);
    ll ans = 0;
    ll rsum = 0;
    for(int i = 0; i <= n; i++){
        rsum += v[i].second;
        ans = max(ans, rsum - v[i].first + segmx.query(0, n + 1 - i));
        ans = max(ans, rsum - 2 * v[i].first + segmn.query(0, n + 1 - i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7424
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '(L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

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

    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }






}


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


struct edge{ int from, to, cost, ind; };
int bad[2525];
edge E[5050];

int d[2525];
int vis[2525];
int N,M;
const int INF=1e9;

void bellman_ford(int s){
  for(int i=0;i<N;i++) d[i]=INF;
  d[s]=0;
  while(1){
    bool update=0;
    for(edge e:E){
      if(bad[e.to]) continue;
      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }
    if(!update) break;
  }
}


bool find_negative_loop(){
  memset(d,0,sizeof(d));
  for(int i=0;i<N;i++){
    for(edge e:E){
      if(bad[e.to]) continue;
      if(d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        if(i==N-1) return 1;
      }
    }
  }
  return 0;
}

int P;
vector<vector<vector<int>>> V(2);

void dfs(int v,int x){
  vis[v]=1;
  for(int u:V[x][v]){
    if(vis[u]==0) dfs(u,x);
  }
}

int main(){
  cin>>N>>M>>P;
  V[0].resize(N);
  V[1].resize(N);
  rep(i,M){
    int A,B,C; cin>>A>>B>>C;
    E[i]={A-1,B-1,P-C};
    V[0][A-1].push_back(B-1);
    V[1][B-1].push_back(A-1);
  }
  dfs(0,0);
  rep(i,N) if(vis[i]==0) bad[i]=1;
  rep(i,N) vis[i]=0;
  dfs(N-1,1);
  rep(i,N) if(vis[i]==0) bad[i]=1;
  if(find_negative_loop()) cout<<"-1\n";
  else{
    bellman_ford(0);
    cout<<max(0,-d[N-1])<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long int A, B, C, D, lcm = 0;
	cin >> A >> B >> C >> D;
	lcm = (C*D) / __gcd(C,D);
	A--;
	cout << B - A - (B / C + B / D - B / lcm) + (A / C + A / D - A / lcm) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
#define vecP vector<P>
// cout << setprecision(15) << std::fixed;

int main() {
    ll n, cou = 0;
    cin >> n;
    vec A(n);
    priority_queue<int> ans;
    for (int i = 0;i < n;i++) {
        cin >> A[i];
    }
    for (int a = 0;a < n;a++) {
        cou = 0;
        for (int b = a;b < n;b++) {
            if (b + 1 == n || A[b] < A[b+1]) {
                ans.push(cou);
                if (ans.top() == n - 1 || ans.top() >= n - a) {
                    cout << ans.top();
                    exit(0);
                }
                break;
            }
            cou++;
        }
    }
    cout << ans.top();
}


Measured memory_bytes: 1276
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	ll n; cin>>n;

	ll ans[n+1] = {0};

	forsn(i,1,n+1){
		ll calc = 0;
		ll x = i;
		while(x){
			calc += x%2;
			x /= 2;
		}
		ans[i] = 1+ans[i%calc];
	}

	string s; cin>>s;
	reverse(s.begin(),s.end());

	int tot = 0;
	
	forn(i,s.length()){
		if(s[i] == '1') tot++;
	}

	ll p1 = tot+1, p2 = tot-1;

	ll val[2][n+1];
	ll mul[2][n+1];

	forn(i,2) forn(j,n+1) val[i][j] = 0;

	mul[0][0] = 1;
	mul[1][0] = 1;
	
	forsn(i,1,n+1){
		mul[0][i] = (mul[0][i-1] * 2) % p1;
		if(p2 != 0) mul[1][i] = (mul[1][i-1] * 2) % p2;
	}

	ll pref[2] = {0};

	forn(i,n){
		forn(j,2){
			val[j][i] += pref[j];
		}
		if(s[i] == '1'){
			forn(j,2) pref[j] += mul[j][i];
		}
	}

	ll suff[2] = {0};

	rforn(i,n-1){
		forn(j,2){
			val[j][i] += suff[j];
		}
		if(s[i] == '1'){
			forn(j,2) suff[j] += mul[j][i];
		}
	}

	rforn(i,n-1){
		if(s[i] == '0'){
			ll an = 0;
			an = val[0][i]%p1;
			an += mul[0][i];
			an %= p1;
			cout<<1+ans[an]<<ln;
		}
		else{
			ll an = 0;
			if(p2 == 0) cout<<0<<ln;
			else{
				an = val[1][i]%p2;
				cout<<1+ans[an]<<ln;
			}
		}
	}

	return 0;
}

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

int selectionSort(int A[], int N) {
    int sw = 0;
    for (int i = 0; i < N-1; i++) {
        int minj = i;
        for (int j = i; j < N; j ++) {
            if (A[j] < A[minj]) minj = j;
        }
        swap(A[i], A[minj]);
        if (i != minj) sw++;
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    
    sw = selectionSort(A, N);
    
    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}



Measured memory_bytes: 3068
S = list(str(input()))
result_position = [0] * len(S)
count = [0] * len(S)

# 最も左の計算
current = 0
for j in range(0, pow(10, 100)):
  if S[current + 1] == "L":
    if j % 2 == 1:
      current += 1
    break
  else:
    current += 1
result_position[0] = current
count[current] += 1

for i in range(1, len(S)):
  if (S[i - 1] == "R") or (S[i - 1] == "L" and S[i] == "L"):
    if S[result_position[i - 1]] == "R":
      result_position[i] = result_position[i - 1] + 1
    else:
      result_position[i] = result_position[i - 1] - 1
    count[result_position[i]] += 1
  else:
    current = i
    for j in range(0, pow(10, 100)):
      if S[current+1] == "L":
        if j % 2 == 1:
          current += 1
        break
      else:
        current += 1
    result_position[i] = current
    count[current] += 1
  
result = " ".join(map(str, count))

print(result)

Measured memory_bytes: 57484
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
 
int main() {
    int n, sum = 0, a = 0;
    cin >> n;
    vector<int>as(n + 2);
    vector<int>bs(n + 2);
    for (int i = 1; i < n + 1; i++){
        cin >> as[i];
    }
    for (int i = 1; i < n + 2; i++){
        bs[i] = bs[i - 1] + abs(as[i] - as[i - 1]);
    }
    for (int i = 0; i < n; i++){
        cout << abs (as[i + 2] - as[i]) + bs[i] + bs[n + 1] - bs[i + 2] << endl;
    }
}

Measured memory_bytes: 2048
import sys

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip()


n = int(input())
Arr = get_array()

child = [0] * (n)

for index, value in enumerate(Arr, 2):
    child[value - 1] += 1

for i in child:
    print(i)

Measured memory_bytes: 92284
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(){
    int K;
    string str;
    cin>>K;
    cin>>str;
    int len;
    len= str.length();
    if(len<=K)
        cout<<str<<endl;
    else
    { for(int i=0;i<K;i++)
        {
            cout<<str[i];
        }
    cout<<"..."<<endl;
    
    }
return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	int y[4]={10,50,100,500};
	int f=0;
	while(cin>>n,n!=0){
		if(f!=0)
		cout<<endl;
		int s=0;
		int x[4]={0};
		for(int i=0;i<4;i++){
			cin>>x[i];
			s+=x[i]*y[i];
		}
		s-=n;
		int k=3;
		int z[4]={0};
		while(s>0){
			if(s-y[k]>=0){
				z[k]++;
				s-=y[k];
			}
			else
				k--;
		}
		for(int i=0;i<4;i++){
			if(x[i]>z[i])
			cout<<y[i]<<" "<<x[i]-z[i]<<endl;
		}
		f=1;
	}
	
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a;
	while(scanf("%d",&a),a){
		int M=0;int m=9999;
		int sum=0;
		for(int i=0;i<a;i++){
			int b;scanf("%d",&b);M=max(M,b);m=min(m,b);sum+=b;
		}
		printf("%d\n",(sum-M-m)/(a-2));
	}
}

Measured memory_bytes: 1028
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

c = Counter(A)
d_1 = {k:v*(v-1)//2 for k,v in c.items()}
d_2 = {k:(v-1)*(v-2)//2 for k,v in c.items()}
d_value_sum = sum([i for i in d_1.values()])

for i in range(n):
  x = A[i]
  v_1 = d_1[x]
  v_2 = d_2[x]
  print(d_value_sum-v_1+v_2)

Measured memory_bytes: 38292
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.Primitive
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Sequence as Sq
import qualified Data.Map as M
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

readIntBS = fst . fromJust . BS.readInt

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  s <- BS.getLine
  t <- BS.getLine

  let
    l = lcm n m

    solve [] _ = True
    solve _ [] = True
    solve ((x,cx):xs) ((y,cy):ys)
      | x == y = if cx == cy then solve xs ys else False
      | x < y = solve xs ((y,cy):ys)
      | x > y = solve ((x,cx):xs) ys
      
      
    ans =  solve [(j, s `BS.index` i) | i<-[0..n-1], let j=i*l`div`n] [(j, t `BS.index` i) | i<-[0..m-1], let j=i*l`div`m]
  

  print $ if ans then l else -1
  


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
const ll M=1000000007;
//------------------------------------------//

int main(){
    int N;cin>>N;
    ll cnt=0;
    int B,C;
    for(int i=1;i<=1000000;i++){
        B=N/i;
        if(B!=0){
            for(int j=1;j<=B;j++){
                if(N-i*j>0){
                    cnt++;
                }
            }            
        } 
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3632
fun main(args: Array<String>) {
    abc129d()
}

fun abc129d() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val wall = Array(h) { BooleanArray(w) }
    repeat(h) { i ->
        wall[i] = readLine()!!.map { it == '#' }.toBooleanArray()
    }

    // down,up,right,left
    val cSumD = Array(h) { IntArray(w) }
    val cSumU = Array(h) { IntArray(w) }
    val cSumR = Array(h) { IntArray(w) }
    val cSumL = Array(h) { IntArray(w) }

    for (x in 0 until w) {
        for (y in 0 until h) {
            cSumD[y][x] = if (wall[y][x]) 0 else if (y == 0) 1 else cSumD[y - 1][x] + 1
            cSumR[y][x] = if (wall[y][x]) 0 else if (x == 0) 1 else cSumR[y][x - 1] + 1
        }
    }
    for (x in w - 1 downTo 0) {
        for (y in h - 1 downTo 0) {
            cSumU[y][x] = if (wall[y][x]) 0 else if (y == h - 1) 1 else cSumU[y + 1][x] + 1
            cSumL[y][x] = if (wall[y][x]) 0 else if (x == w - 1) 1 else cSumL[y][x + 1] + 1
        }
    }

    var answer = 0

    for (y in 0 until h) {
        for (x in 0 until w) {
            val curr = cSumD[y][x] + cSumU[y][x] + cSumR[y][x] + cSumL[y][x] - 3
            if (curr > answer) answer = curr
        }
    }

    println(answer)
}


Measured memory_bytes: 112508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> que;
    vector<int> dist(N, -1);
    vector<int> par(N);
    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        
        for (auto nv : G[v]) {
            if (dist[nv] != -1) continue;

            dist[nv] = dist[v] + 1;
            par[nv] = v + 1;
            que.push(nv);
        }
    }

    bool flag = true;
    for (int i = 0; i < N; i++) {
        if (dist[i] == -1) flag = false;
    }

    if (flag) {
        cout << "Yes" << endl;
        for (int i = 1; i < N; i++) {
            printf("%d\n", par[i]);
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 10740
#include <iostream>
#include <valarray>
#include <cmath>
#include <algorithm>

using namespace std;

typedef valarray<int> array_t;
int M, N, D;

int solve(valarray<array_t>& A){
	int p = 0, r, k;
	for(int i = 0; i < M*N; i++){
		for(k = p; k < M*N; k++){
			if(A[k][i] != 0){
				r = k;
				break;
			}
		}
		if(k == M*N) continue;
		swap(A[p],A[r]);
		for(int j = p + 1; j < M*N; j++){
			if(A[j][i]){
				A[j] += A[p];
				A[j] %= 2;
			}
		}
		p++;
	}
	for(int r = 0; r < M*N; r++){
		if(A[r][M*N] != 0){
			int flag = 0;
			for(int i = 0; i < M*N;i++) flag += A[r][i];
			if(flag == 0) return 0;
		}
	}
	return 1;
}

int main(){
	while(cin >> M >> N >> D && M){
		valarray<array_t> A(array_t(0, M*N+1), M*N);
		for(int i = 0; i < M*N; i++){
			cin >> A[i][M*N];
			for(int j = 0; j < M*N; j++){
				int x0 = i % M, y0 = i / M, x1 = j % M, y1 = j / M;
				int d = abs(x0-x1) + abs(y0-y1);
				if (d == 0 || d == D) A[i][j] = 1;
			}
		}
		cout << solve(A) << endl;
	}
	return 0;
}

Measured memory_bytes: 2640
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int w, a, b;
  scanf("%d %d %d", &w, &a, &b);
  if (abs(a+w-b) < abs(b+w-a)) {
    if (a+w < b) {
      printf("%d\n", b-(a+w));
    } else {
      printf("0\n");
    }
  } else {
    if (b+w < a) {
      printf("%d\n", a-(b+w));
    } else {
      printf("0\n");
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
using namespace std;
const int mod=998244353;
int n;
int a[405];
int b[405];
int fac[405];
int inv[405];
int fac_inv[405];
int f[405][405];
void upd(int &a,int b)
{
	a-=b;
	if(a<0) a+=mod;
}
void init(int n)
{
	inv[1]=1;
	for(int i=2;i<=n;++i)
	{
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	}
	fac[0]=1;
	for(int i=1;i<=n;++i)
	{
		fac[i]=1ll*fac[i-1]*i%mod;
	}
	fac_inv[0]=1;
	for(int i=1;i<=n;++i)
	{
		fac_inv[i]=1ll*fac_inv[i-1]*inv[i]%mod;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	init(400);
	f[0][0]=mod-1;
	int suma=0,sumb=0;
	for(int i=1;i<=n;++i)
	{
		for(int j=suma;j>=0;--j)
		{
			for(int k=0;k<=sumb;++k) if(f[j][k])
			{
				int d=1;
				for(int l=0;l<b[i];++l)
				{
					upd(f[j+a[i]][k+l],1ll*f[j][k]*d%mod*fac_inv[l]%mod);
					d=1ll*d*a[i]%mod;
				}
			}
		}
		suma+=a[i];
		sumb+=b[i];
	}
	int an=0;
	for(int j=1;j<=suma;++j)
	{
		int d=1;
		for(int k=0;k<=sumb;++k)
		{
			d=1ll*d*inv[j]%mod; 
			an=(an+1ll*f[j][k]*d%mod*fac[k])%mod;
		}
	}
	an=1ll*an*suma%mod;
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 896
# include <bits/stdc++.h>
using namespace std;
int a, b, c, d = 3;
int main()
{
    cin >> a >> b >> c;

    if(a == b)
        d--;

    if(b == c)
        d--;

    if(a == c)
        d--;

    if(d == 0)
    cout << 1;

    else
    cout << d;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define inf INT_MAX;
template<typename T>
T GCD(T a, T b) {
	if (a > b)swap(a, b);
	if (b%a == 0)return a;
	return GCD(b%a, a);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
int n, k, a[100010], MAX, gcd;
int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
		MAX = max(MAX, a[i]);
	}
	gcd = a[0];
	for (int i = 1; i < n; i++) {
		gcd = GCD(a[i], gcd);
	}
	if (MAX < k)cout << "IMPOSSIBLE" << endl;
	else if ((MAX - k) % gcd == 0)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    keys=[0]*m
    cost=[0]*m
    for i in range(m):
        a,b=map(int,input().split())
        cost[i]=a
        key=0
        for c in map(int,input().split()):
            key+=(1<<c-1)
        keys[i]=key
    N=2**n
    dp=[INF]*N
    dp[0]=0
    for k in range(N):
        for i in range(m):
            dp[k|keys[i]]=min(dp[k|keys[i]],dp[k]+cost[i])
    print(dp[N-1] if dp[N-1]!=INF else -1)
resolve()

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

int main() {
  long a,b,c,d,ac,ad,bc,bd,max1,max2,max3;
  cin>>a>>b>>c>>d;
  
  ac=a*c;
  ad=a*d;
  bc=b*c;
  bd=b*d;
  max1= max(ac,ad);
  max2= max(bc,bd);
  max3= max(max1,max2);
  
  
  cout<<max3<<endl;
  
 
}


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

ll n, ans = 1, mod = 1e9 + 7;
vector<vector<ll>> g(200100);
vector<ll> inv(200100), sbs(200100, -1);

ll modpow(ll x, ll n, ll mod) {
    ll r = 1;
    while (n > 0) {
        if (n & 1)
            r = r * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return r;
}

ll dfs(ll v, ll p) {
    if (sbs[v] != -1)
        return sbs[v];
    sbs[v] = 1;
    for (auto u : g[v])
        if (u != p) {
            sbs[v] += dfs(u, v);
            ans += (mod + 1 - modpow(inv[2], sbs[u], mod)) *
                   (mod + 1 - modpow(inv[2], n - sbs[u], mod)) % mod;
        }
    return sbs[v];
}

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

    cin >> n;
    inv[1] = 1;
    rep(i, 2, 200000) inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    rep(i, 1, n) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs(0, -1);

    ans = (ans + mod - modpow(inv[2], n, mod)) % mod;
    ans = (ans + mod - n * inv[2] % mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23552
def partition(A, p, r):
    x = A[-1]
    i = p - 1
    for j in range(p, r-1):
        if A[j] <= x:
            i = i + 1
            A[i],A[j]=A[j], A[i]
    A[i+1], A[-1]=A[-1], A[i+1]
    return i+1

    
    
if __name__ == "__main__":
    num = int(raw_input())
    num_list = raw_input().strip().split()
    num_list = map(int, num_list)
    i = partition(num_list, 0, len(num_list))
    num_list = map(str, num_list)
    data = ""
    for j in range(len(num_list)):
        if j == i:
            data += "[" + num_list[j] + "] "
        else:
            data += num_list[j] + " "
    print data[:-1]

    

Measured memory_bytes: 17912
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<long long, bool>> a(N+1);
  for(int i=0;i<N+1;i++) a.at(i).second = true;
  for(int i=0;i<M;i++){
    int b;cin >>b;
    a.at(b).second = false;
  }
  a.at(0).first = 1;
  
  if(a.at(1).second == false){
    a.at(1).first = 0;
  }
  else a.at(1).first = 1;
  
  for(int i=2;i<N+1;i++){
    if(!a.at(i).second) a.at(i).first = 0;
    else a.at(i).first = a.at(i-1).first + a.at(i-2).first;
    a.at(i).first %= 1000000007;
  }
  cout << a.at(N).first <<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp std::make_pair

std::vector<int> G[100001];
bool vis[100001];
std::pair<int, int> memo[100001];

std::pair<int, int> dfs_visit(int s)
{
	if(vis[s])
	return memo[s];
	int g = 0, h1 = 0;
	for(auto u : G[s])
	{
		std::pair<int, int> px = dfs_visit(u);
		g = std::max(g, px.first);
		if(px.second > h1)
		h1 = px.second;
	}	
	vis[s] = 1;
	g = std::max(g, h1);
	memo[s] = mp(g, h1 + 1);
	return memo[s];
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	int n,m;
	std::cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int s,d;
		std::cin>>s>>d;
		G[s].pb(d);
	}
	for(int i=1;i<=n;i++)
	memo[i] = mp(0, 0);
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		ans = std::max(ans, dfs_visit(i).first);
	}
	std::cout<<ans<<"\n";
	return 0;	
}

Measured memory_bytes: 9344
// Gaurav Nuti
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define ar array
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define INF 1e9 

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

bool comparep(pair<ll, ll> i1, pair<ll, ll> i2){
	return (i1.S < i2.S);
} 

ll modInverse(ll a)
{
    return power(a , mod - 2);
}

vector<vector<ll>> graph;
vector<bool> visited;
vector<ll> dist;
map<ll,ll> mymap;
ll max_dist = 1;

void bfs(int u1){
    visited[u1] = 1;
    dist[u1] = 1;
    mymap[1] = u1;
    queue<ll> q;
    q.push({u1});
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(auto i=graph[u].begin();i!=graph[u].end();i++){
            if(!visited[*i]){
                dist[*i] = dist[u] + 1;
                visited[*i] = 1;
                max_dist = max(dist[*i],max_dist);
                mymap[dist[*i]] = *i;
                q.push({*i});
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
	
    ll t;
    // cin>>t;
    t = 1;
    for(ll z=0;z<t;z++){
        ll n,k;
        cin>>n>>k;
        set<ll> peeps;
        for(ll i = 0;i<k;i++){
            ll d;
            cin>>d;
            for(ll i=0;i<d;i++){
                ll x;
                cin>>x;
                peeps.insert(x);
            }
        }
        cout<<n - peeps.size();
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N;
  string S;
  cin >> N >>  S;
  ll nr=0;
  ll ng=0;
  ll nb = 0;
  for(auto c : S){
    if (c == 'R') {
      //R.push_back(i);
      nr++;
    }else if(c == 'G'){
      //G.push_back(i);
      ng++;
    }else if(c == 'B'){
      //B.push_back(i);
      nb++;
    }
  }
  ll ans = nr * nb * ng;
  for(int i = 0; i < N-2; i++){
    for(int j = i+1; (2*j - i )< N; j++){
      int k = 2 * j - i;
      if(k < N){
        if((S[i] != S[k] )&& (S[j] != S[k]) && (S[i] != S[j])) ans--;
      }
    }
  }


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var mf = new MaxFlow_Dinic();
		int NN = 2 * N + 2;
		int src = 2 * N;
		int sinc = src + 1;
		mf.Init(NN);
		for(int i=0;i<N;i++){
			mf.AddEdge(src, i, (int) 1);
		}
		for(int i=0;i<N;i++){
			mf.AddEdge(i + N, sinc, (int) 1);
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(A[i] < C[j] && B[i] < D[j]) mf.AddEdge(i, j + N, 1);
			}
		}
		
		Console.WriteLine(mf.MaxFlow(src, sinc));
	}
	int N;
	int[] A,B,C,D;
	public Sol(){
		N = ri();
		A = new int[N]; B = new int[N];
		C = new int[N]; D = new int[N];
		for(int i=0;i<N;i++){
			var d = ria();
			A[i] = d[0]; B[i] = d[1];
		}
		for(int i=0;i<N;i++){
			var d = ria();
			C[i] = d[0]; D[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


class MaxFlow_Dinic{
	// arihon is god
	class Edge {
		public int To,Cap,Rev;
		public Edge(int to = 0,int cap = 0,int rev = 0){
			To = to;
			Cap = cap;
			Rev = rev;
		}
	}
	
	List<Edge>[] G;
	int[] Level;
	int[] Iter;
	
	static int Inf = (int) 1e9;
	public int N;
	public void Init(int n){
		N = n;
		G = new List<Edge>[N];
		for(int i=0;i<N;i++) G[i] = new List<Edge>();
		Level = new int[N];
		Iter = new int[N];
	}
	
	
	public void AddEdge(int from, int to, int cap){
		G[from].Add(new Edge(to,cap,G[to].Count));
		G[to].Add(new Edge(from,0,G[from].Count-1));
	}
	
	void bfs(int s){
		for(int j=0;j<G.Length;j++)Level[j] = -1;
		var Q = new Queue<int>();
		Level[s] = 0;
		Q.Enqueue(s);
		
		while(Q.Count>0){
			var v = Q.Dequeue();
			foreach(var e in G[v]){
				if(e.Cap > 0 && Level[e.To] < 0){
					Level[e.To] = Level[v] + 1;
					Q.Enqueue(e.To);
				}
			}
		}
	}
	
	int dfs(int v, int t, int f){
		if(v == t) return f;
		for(;Iter[v] < G[v].Count; Iter[v]++){
			var e = G[v][Iter[v]];
			if(e.Cap > 0 && Level[v] < Level[e.To]){
				int d = dfs(e.To, t, Math.Min(f,e.Cap));
				if(d > 0){
					e.Cap -= d;
					G[e.To][e.Rev].Cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	public int MaxFlow(int s,int t){
		int flow = 0;
		while(true){
			bfs(s);
			if(Level[t] < 0) return flow;
			Iter = new int[N];
			
			int f;
			while( ( f = dfs(s,t,Inf)) > 0){
				flow += f;
			}
		}
	}
	
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  }
}


Measured memory_bytes: 51056
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//AtCoder Beginner Contest 117
//C	Streamline
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		if (N >= M) {
			System.out.println(0);
			sc.close();
			return;
		}

		List<Integer> inList = new ArrayList<>();
		for (int i = 0; i < M; i++) {
			inList.add(sc.nextInt());
		}
		sc.close();


		Collections.sort(inList);

		List<Integer> diffList = new ArrayList<>();
		if (inList.size() > 1) {
			for (int i = 0; i < inList.size(); i++) {
				diffList.add(inList.get(i + 1) - inList.get(i));
				if (i == inList.size() - 2) {
					break;
				}
			}
		}

		Collections.sort(diffList);

		for (int i = 0; i < N - 1; i++) {
			if (diffList.size() < 2) {
				break;
			}
			diffList.remove(diffList.size() - 1);
		}

		int sum = 0;
		for (Integer d : diffList) {
			sum += d;
		}

		System.out.println(sum);

	}
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

vs create_ss(const vector<char> &cl) {
    vs ret;
    set<str> st;
    REP(i, cl.size()) {
        REP(j, cl.size()) {
            REP(k, cl.size()) {
                str s = to_string(cl[i] - '0') + to_string(cl[j] - '0') + to_string(cl[k] - '0');
                if(st.count(s) == 0) {
                    ret.push_back(s);
                    st.insert(s);
                }
            }
        }
    }
    return ret;
}

bool judge(const str &ss, const str &s) {
    int idx = 0;
    // DBG(ss);
    REP(i, s.size()) {
        if(idx == 3) return true;
        else if(idx < 3 && ss[idx] == s[i]) {
            // DBG(idx);
            // DBG(i);
            idx++;
            if(idx == 3) return true;
        }
    }
    return false;
}

int main() {
    int n;
    str s;
    cin >> n >> s;
    set<char> st;
    vector<char> clist;
    REP(i, n) {
        if(st.count(s[i]) == 0) {
            clist.push_back(s[i]);
            st.insert(s[i]);
        }
    }
    vs sl = create_ss(clist);
    ll ans = 0;
    REP(i, sl.size()) {
        if(judge(sl[i], s)) {
            // DBG("OK");
            ans++;
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>
#define ABS(a) ((a>0) ? a : (-a))


int main(void) {
  int N;
  scanf("%d", &N);

  int W[100];
  for(int i = 0; i < N; i++) {
    scanf("%d", &W[i]);
  }

  int minS = 100000;
  for(int T = 1; T < N; T++) {
    int lp = 0;
    int left = 0;
    int right = 0;
    while((lp <= T) && (lp < N)) {
      left += W[lp++];
    }
    while(lp < N) {
      right += W[lp++];
    }
    //printf("T=%d left=%d right=%d\n", T, left, right);
    int S = ABS((left - right));
    if(minS > S)
      minS = S;
  }
  printf("%d\n", minS);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
    int n,m,i;
    scanf("%d",&n);
    scanf("%d",&m);
    int a;
    int sum=0;
    for(i=0;i<m;i++){
        scanf("%d",&a);
        sum+=a;
    }
    if(n < sum){
        printf("%d",-1);
        return 0;
    }
    if(n >= sum){
        printf("%d",n-sum);
        return 0;
    }
}


Measured memory_bytes: 1732
n = input()
A = raw_input()
B = raw_input()
C = raw_input()
a = list(A)
b = list(B)
c = list(C)
count = 0
for i in range(0,n):
	if(a[i] == b[i]):
		if(a[i] == c[i]):
			pass
		else:
			c[i] = a[i]
			count+=1
	elif(a[i] == c[i]):
		b[i] = a[i]	
		count+=1
	elif(b[i] == c[i]):
		a[i] = b[i]
		count += 1
	else:
		b[i] = a[i]
		c[i] = a[i]
		count += 2
print(count)

Measured memory_bytes: 2696
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    vector<int> v[100001];
    int visited[100001];
    void dfs(int i)
    {
        visited[i]=1;
        for(int j=0;j<v[i].size();++j)
        {
            if(visited[v[i][j]]==0)
            {
                dfs(v[i][j]);
            }
        }
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,m,i,j,a,b,ans=0;
            cin>>n>>m;
            for(i=1;i<=m;++i)
            {
                cin>>a>>b;
                v[a].pb(b);
                v[b].pb(a);
            }
            for(i=1;i<=n;++i)
            {
                if(visited[i]==0)
                {
                    ++ans;
                    dfs(i);
                }
            }
            cout<<ans-1<<endl;
        }
        return 0;
    }


Measured memory_bytes: 9936
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int N = in.nextInt();
			int[] x1 = new int[N];
			int[] x2 = new int[N];

			for (int i = 0; i < N; i++) {
				int a = in.nextInt();
				x1[i] = a;
				x2[i] = a;
			}
			Arrays.sort(x2);

			int len = x1.length;
			int n1 = x2[len/2];
			int n2 = x2[len/2-1];

			double half = (N-1) / 2.0;


			for (int i = 0; i < N; i++) {
				int tar = x1[i];
				int index = lowerBound(x2, tar);

				if (index < half) {
					out.println(n1);
				} else {
					out.println(n2);
				}

			}
		}
		public static int lowerBound(int[] a, int obj) {
			int l = 0,r = a.length - 1;
			while (r - l >= 0) {
				int c = (l + r) / 2;
				if (obj <= a[c]) {
					r = c - 1;
				} else {
					l = c + 1;
				}
			}
			return l;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 53908
var n,i:longint;
    k:int64;
begin
  readln(n);
  i:=0;
  while k<n do 
    begin  
      i:=i+1;
      k:=i*i;
    end;
  if k=n
  then writeln(i*i)
  else writeln((i-1)*(i-1));
end.

Measured memory_bytes: 128