akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#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 <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  rep(i,h) {
    rep(j,w) {
      if(grid[i][j] == '.') continue;

      bool flag = false;
      rep(dir, 4) {
        int ni = i + dy[dir];
        int nj = j + dx[dir];

        if(ni < 0) continue;
        if(nj < 0) continue;
        if(ni >= h) continue;
        if(nj >= w) continue;
        if(grid[ni][nj] == '#') flag = true;
      }
      if(!flag) { cout << "No" << endl; return 0; }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
int n;
string s;
vector<int> pos;
// Fills Z array for given string str[]
void getZarr(string str, int Z[])
{
    int n = str.length();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}
// prints all occurrences of pattern in text using Z algo
void Searchz(string pattern)
{
    // Create concatenated string "P$T"
    string text=s;
    string concat = pattern + "$" + text;
    int l = concat.length();

    // Construct Z array
    int Z[l];
    getZarr(concat, Z);

    // now looping through Z array for matching condition
    for (int i = 0; i < l; ++i)
    {
        // if Z[i] (matched region) is equal to pattern
        // length we got the pattern
        if (Z[i] == pattern.length())
            pos.push_back(i - pattern.length() -1);
    }
}

bool check(int k)
{
    if(k==0) return 1;
    for(int i=0;i<n-k+1;i++)
    {
        pos.clear();
        Searchz(s.substr(i,k));
        if(pos.size()>=2 && pos[0]+k<=pos[pos.size()-1]) return 1;
    }
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    cin>>s;
    int l=0,r=n/2,mi;
    while(l!=r)
    {
        mi=(l+r+1)/2;
        if(check(mi)) l=mi; else r=mi-1;
    }
    cout<<l;
    return 0;
}


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

using namespace std;

#define X first
#define Y second

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].X;
        a[i].Y = i + 1;
    }
    sort(a.begin(), a.end());
    
    set<int> ms;
    ms.insert(0);
    ms.insert(n + 1);
    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int l = *prev(ms.lower_bound(a[i].Y));
        int r = *ms.upper_bound(a[i].Y);
        ans += (ll)a[i].X * (a[i].Y - l) * (r - a[i].Y);
        ms.insert(a[i].Y);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 11264
unittest
{
	assert( [ "5 3", "10", "15", "11", "14", "12" ].parse.expand.solve == 2 );
	assert( [ "5 3", "5", "7", "5", "7", "7" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	auto hs = new long[ nk[ 0 ] ];
	foreach( ref h; hs )
	{
		input.popFront;
		h = input.front.strip.to!( long );
	}
	return tuple( nk[ 1 ], hs );
}

auto solve( long k, long[] hs )
{
	hs.sort!( ( a, b ) => b < a );
	
	auto d = long.max;
	for( auto i = 0; i + k <= hs.length; i++ )
	{
		d = min( d, hs[ i ] - hs[ i + k - 1 ] );
	}
	return d;
}


Measured memory_bytes: 3708
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input) {


	Array.prototype.max = function() { return Math.max.apply(null, this) }
	Array.prototype.min = function() { return Math.min.apply(null, this) }
	num = (val) => Array.isArray(val) ? val.map( (v)=>Number(v) ) : Number(val)
	print = console.log

	var line = input.split("\n")
	var n = num( line[0] )
	var a = num( line[1].split(" ") )

	print( a.max() - a.min() )

}

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef pair<int,string> P;

string str, s;
vector<string> x;

int main(){
	cin >> str;
	for(int i = 1; i < str.size(); i++){
		if(str[i] == '.'){
			x.push_back(s);
			s.clear();
			continue;
		}
		s.push_back(str[i]);
	}
	x.push_back(s);
	vector<P> y;
	while(getline(cin,s)){
		int cnt = 0;
		rep(i,s.size()){
			if(s[i] != ' '){
				break;
			}
			cnt++;
		}
		while(y.size() > 0){
			if(y[y.size()-1].first < cnt) break;
			y.pop_back();
		}
		string tmp;
		for(int i = cnt; i < s.size(); i++){
			if(s[i] == ':') break;
			tmp.push_back(s[i]);
		}
		y.push_back(P(cnt,tmp));
		if(y.size() != x.size()) continue;
		bool ok = true;
		rep(i,x.size()) if(y[i].second != x[i]) ok = false;
		if(ok){
			if(s[s.size()-1] != ':'){
				string tmpp;
				for(int i = cnt+tmp.size()+2; i < s.size(); i++) tmpp.push_back(s[i]);
				printf("string \"");
				cout << tmpp;
				printf("\"\n");
			} else{
				cout << "object" << endl;
			}
			return 0;
		}
	}
	cout << "no such property" << endl;
}

Measured memory_bytes: 1332
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int N, D, X;
int P[11][11];
int dp[121111];

void solve() {

  int ans = X;
  dp[X] = X;
  rep(i, D - 1) {
    rep(j, N) {
      for(int x = 111111; x>=P[i][j]; x--) if(dp[x]) {
        dp[x - P[i][j]] = max(dp[x - P[i][j]], dp[x] - P[i][j] + P[i+1][j]);
        ans = max(ans, dp[x - P[i][j]]);
      }
    }
    rep(x, 111111) {
      dp[dp[x]] = max(dp[dp[x]], dp[x]);
    }
  }

  cout << ans << endl;
}

int main() {

  cin >> N >> D >> X;

  rep(i, D) rep(j, N)
    cin >> P[i][j];

  solve();
  
  return 0;
}

Measured memory_bytes: 3368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    vector<vector<int>> vec(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> vec[i][j];

    int n; cin >> n;
    rep(b, n) {
        int x; cin >> x;
        rep(i, 3) rep(j, 3) if (x==vec[i][j]) vec[i][j]=0;
    }

    rep(i, 3) {
        if ((vec[i][0]==0) && (vec[i][1]==0) && (vec[i][2]==0)) {
            puts("Yes");
            return 0;
        }
    }
    rep(j, 3) {
        if ((vec[0][j]==0) && (vec[1][j]==0) && (vec[2][j]==0)) {
            puts("Yes");
            return 0;
        }
    }
    if ((vec[0][0]==0) && (vec[1][1]==0) && (vec[2][2]==0)) {
        puts("Yes");
        return 0;
    }
    if ((vec[0][2]==0) && (vec[1][1]==0) && (vec[2][0]==0)) {
        puts("Yes");
        return 0;
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

int main(){
    ll x,y;
    cin >> x >> y;
    ll ans = 1;
    while(x*2<=y){
        x*=2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>

#define ll long long
using namespace std;

double dist(pair<int,int> a,pair<int,int> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,k=0;
    double sum=0;
    cin>>n;
    vector<pair<ll,ll>>xy(n);
    for(ll i=0;i<n;i++){
        cin>>xy[i].first>>xy[i].second;
    }
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        a[i]=i;
    }
    do{
        for(ll i=0;i<n-1;i++){
            sum+=dist(xy[a[i]],xy[a[i+1]]);
        }
        k++;

    }while(next_permutation(a.begin(),a.end()));
    double ans=sum/k;
    cout<<ans<<endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,,] rooms = new int[4, 3, 10];
            int n= int.Parse(Console.ReadLine());
            for(int i=0; i<n; i++)
            {
                int[] values = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                int b = values[0];
                int f = values[1];
                int r = values[2];
                int v = values[3];

                rooms[b - 1, f - 1, r - 1] += v;
            }

            for (int b = 0; b < 4; b++)
            {
                for (int f = 0; f < 3; f++)
                {
                    for (int r = 0; r < 10; r++)
                    {
                        Console.Write(" {0}", rooms[b, f, r]);
                    }
                    Console.WriteLine();
                }

                if(b < 3)
                {
                    Console.WriteLine("####################");
                }
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9664
using System;

public class hello
{
    public static void Main()
    {
        var aa = 0; var bb = 0; var oo = 0; var ab = 0;
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            string[] s = line.Trim().Split(',');
            switch (s[1])
            {
                case "A":
                    aa++;
                    break;
                case "B":
                    bb++;
                    break;
                case "O":
                    oo++;
                    break;
                case "AB":
                    ab++;
                    break;
            }
        }
        Console.WriteLine(aa);
        Console.WriteLine(bb);
        Console.WriteLine(ab);
        Console.WriteLine(oo);
    }
}

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

int main() {
	vector<int> v; int q, n, x, p; cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> n;
		switch (n) {
		case 0:
			cin >> x; v.push_back(x); break;
		case 1:
			cin >> p; cout << v[p] << endl; break;
		case 2:
			v.pop_back(); break;
		}
	}
	return 0;
}


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

int main() {
  ll N, L;
  cin >> N >> L;
  ll ans = N * L + N * (N - 1) / 2;
  if (L * (L + N - 1) < 0) {
  } else if (L < 0) {
    ans -= N + L - 1;
  } else {
    ans -= L;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int Lx,Ly,Lw,Lh;
	int Rx,Ry,Rw,Rh;

	scanf("%d %d %d %d",&Lx,&Ly,&Lw,&Lh);
	scanf("%d %d %d %d",&Rx,&Ry,&Rw,&Rh);

	if(Rx < Lx){
		swap(Lx,Rx);
		swap(Ly,Ry);
		swap(Lw,Rw);
		swap(Lh,Rh);
	}

	int all = Lw*Lh+Rw*Rh;

	int minus = 0;

	if(Lx+Lw <= Rx || Ry >= Ly+Lh || Ly >= Ry+Rh){

			//Do nothing

	}else{
		minus = (min(Ly+Lh,Ry+Rh)-max(Ly,Ry))*(Lx+Lw-(Rx));
	}

	printf("%d\n",all-2*minus);

	return 0;
}



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

bool hasCycle = false;

void search(int curr, int &n, vector<vector<int>> &v, vector<int> &visited, int count) {
    if (hasCycle) return;
    visited[curr] = count;
    for (auto &to: v[curr]) {
        if (visited[to] != -1) {
            if (count - visited[to] + 1 != n) hasCycle = true;
            continue;
        }
        search(to, n, v, visited, count+1);
    }
}

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; c[i] = a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i]; d[i] = b[i];
    }
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    for (int i = 0; i < n; i++) {
        if (c[i] > d[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        int ci = upper_bound(c.begin(), c.end(), d[i]) - c.begin();
        if (ci-i > 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    map<int, int> cm, dm;
    for (int i = 0; i < n; i++) {
        cm[c[i]] = i; dm[d[i]] = i;
    }
    vector<vector<int>> v(n);
    vector<int> visited(n, -1);
    for (int i = 0; i < n; i++) {
        v[cm[a[i]]].emplace_back(dm[b[i]]);
        if (cm[a[i]] == dm[b[i]]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (visited[i] == -1) search(i, n, v, visited, 0);
    }
    if (hasCycle) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 24832
def main():
    N = int(input())
    h_lst = list(map(int, input().split()))
    while h_lst[0] == 0:
        del h_lst[0]
        if h_lst == []:
            break
    ans = 0
    while len(h_lst) > 0:
        r = len(h_lst) - 1
        for i in range(len(h_lst) - 1):
            if h_lst[i + 1] == 0:
                r = i
                break

        block_min = min(h_lst[:r + 1])
        for i in range(r + 1):
            h_lst[i] -= block_min
        ans += block_min

        while h_lst[0] == 0:
            del h_lst[0]
            if h_lst == []:
                break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <int>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
const ll mod=1e9+7;
bool is_prime(int n)
{
    if(n==2)
        return true;
    if(n%2==0||n<2)
        return false;
    for(int i=3; i<=sqrt(n); i+=2)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
long long power(ll n, ll k){
    if(k==0) return 1;
    ll sq=(power(n,k/2))%mod;
    sq=(sq*sq)%mod;
    if(k%2==1)
        sq=(sq*n)%mod;
    return sq%mod;
}
long long gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
// lcm = (a*b)/gcd(a,b)
//freopen("input.txt" ,"r",stdin );
//freopen("output.txt","w",stdout);
double memo[3005][3005];
int n;
vector<double>a;
double fun(int idx,int rem)
{
    if(idx==n)
    {
        if(rem>n-rem)return 1;
        else return 0;
    }
	double &ret=memo[idx][rem];
	if(ret!=-1)return ret;
    return ret=fun(idx+1,rem+1)*a[idx]+fun(idx+1,rem)*(1-a[idx]);
}

void fast();
int main()
{
    fast();
    cin>>n;
    a.resize(n);
    loop(n)
    {
        cin>>a[i];
    }
    loop(n)
    {
        for(int j=0;j<3000;j++)memo[i][j]=-1;
    }
    cout<<fixed<<setprecision(12)<<fun(0,0);
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


Measured memory_bytes: 70912
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
a.each do |i|
    hash[i] += 1
end
hash_2 = Hash.new(0)
arr = Array.new(n+1,0)
count = 0
hash.each do |i|
    ans =  (i[1] * (i[1] - 1)) / 2
    hash_2[i[0]] = ans
    count += ans
end
a.each do |j|
    point = hash_2[j]
    sa_1 = (hash[j] * (hash[j] - 1)) / 2
    sa_2 = [((hash[j]-1) * (hash[j] - 2)) / 2,0].max
    count = count - sa_1 + sa_2
    puts count
    count = count + (sa_1 - sa_2)
end

Measured memory_bytes: 43928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll Stoi(string s){
  ll res=0;
  for(ll i=0;i<(int)s.size();i++)res=res*10+s[i]-'0';
  return res;
}

ll Pow(ll a,ll b){
  ll res=1;
  while(b--)res*=a;
  return res;
}

string n;
ll dp[20][2][10][10][10];
ll dfs(ll id,ll f,ll a,ll b,ll c){
  if(dp[id][f][a][b][c]!=-1)return dp[id][f][a][b][c];
  if(id==(int)n.size())return 0;
  ll r=9,res=0;
  if(!f)r=n[id]-'0';
  for(ll d=0;d<=r;d++){
    ll nf=f;
    if(d<r)nf=1;
    if(a==5&&b==1&&d==3)
      if(nf) res+=Pow(10,n.size()-id-1);
      else res+=Stoi(n.substr(id+1))+1;
    else res+=dfs(id+1,nf,b,c,d);
  }
  return dp[id][f][a][b][c]=res;
}

int main(){
  cin>>n;
  memset(dp,-1,sizeof(dp));
  cout<<dfs(0,0,0,0,0)<<endl;
  return 0;
}


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

#define true 1
#define false 0

int main(){
  int n,i,x,not=0,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    if(isPrime(x)==true)
      count++;
  }
  printf("%d\n",count);

  return 0;
}

isPrime(x){
  int i;
  if(x==2)
    return true;
  if(x<2 || x%2==0)
    return false;
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0)
      return false;
    i=i+2;
  }
  return true;
}



Measured memory_bytes: 2108
(* Vicfred
 * https://atcoder.jp/contests/abc147/tasks/abc147_b
 * string manipulation
 * *)
let s, ans = read_line(), ref 0
let main =
    String.(iteri (fun i c -> if s.[length s - i - 1] <> c then incr ans) s);
    Printf.printf "%d\n" @@ !ans / 2



Measured memory_bytes: 3676
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        int[] uf = new int[N];
        Arrays.fill(uf,-1);

        for (int i = 0; i < M; i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            int z = sc.nextInt();

            connect(x,y,uf);

        }

        int count =0;
        for(int leader : uf) if(leader==-1) count++;
        System.out.println(count);
    }

    static    private int findLeader(int i ,int[] uf){
        if (uf[i] ==-1) return i;
        int leader = findLeader(uf[i], uf);
        uf[i] = leader;
        return leader;
    }
    static  private void connect(int i ,int j, int[] uf){
        int leader1 = findLeader(i,uf);
        int leader2 = findLeader(j,uf);
        if(leader1 == leader2) return;

        if(leader1 < leader2){
            uf[leader2] = leader1;
        }else{
            uf[leader1] = leader2;
        }


    }

}

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

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

	long long n, x, y;
	cin >> n >> x >> y;

	// first calculate distance as though it has been normal
	long long dist[n + 1][n + 1];
	long long INF = 1e4;
	memset(dist, INF, sizeof(dist));

	for (long long i = 1; i <= n; ++i) {
		for (long long j = 1; j <= n; ++j) {
			dist[i][j] = abs(j - i);
		}
	}

	for (long long i = 1; i <= n; ++i) {
		for (long long j = 1; j <= n; ++j) {
			dist[i][j] = min(dist[i][j], dist[i][x] + 1 + dist[y][j]);}
	}

	long long res[n];
	memset(res, 0, sizeof(res));

	for (long long i = 1; i <= n; ++i)
		for (long long j = 1 + i; j <= n; ++j) {
			if (dist[i][j] < n && dist[i][j] >= 0)
				res[dist[i][j]]++;
		}

	for (long long i = 1; i < n; ++i)
		cout << res[i]<< endl;

	return 0;
}



Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
  cin >>n >>m;
  int x[m];
  for(int i=0;i<m;i++)cin >>x[i];
  if (n>=m)cout << 0 <<endl;
  else {
  	sort(x,x+m);
    int xsub[m-1],ans=0;
    for(int i=0;i<m-1;i++){
      xsub[i]=x[i+1]-x[i];
    }
    sort(xsub,xsub+m-1);
    for(int i=0;i<m-n;i++){
      ans+=xsub[i];
    }
    cout << ans <<endl;
  }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,max1=0,max2=0;
    cin>>n;
    Vi a(n);
    REP(i,0,n){
        cin>>a[i];
        if(a[i]>=max1){
            max2=max1;
            max1=a[i];
        }else if(a[i]>=max2){
            max2=a[i];
        }
    }
    
    REP(i,0,n){
        if(a[i]==max1) cout<<max2<<endl;
        else cout<<max1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdlib>
 
using namespace std;
 
char ToUpper(char cX) { return toupper(cX); }
 
int main()
{
    string str;
 
    while (getline(cin, str, '\n')) {
        transform(str.begin(), str.end(), str.begin(), ToUpper);
        cout << str << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int n=0,m=0;
  if(c%b != 0){
    n = c/b + 1;
  }else{
    n = c/b;
  }
  if(a%d != 0){
    m = a/d + 1;
  }else{
    m = a/d;
  }
  if(m < n){
    cout << "No" << endl;
    return 0;
  }else{
    cout << "Yes" << endl;
    return 0;
  }
}

Measured memory_bytes: 3592
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i, m, n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int main() {
    // input
    int n, z, w; scanf("%d%d%d", &n, &z, &w);
    vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
    // solve
    vector<map<int, int> > memo_fst(n);
    vector<map<int, int> > memo_snd(n);
    function<int (bool, int, int, int)> go = [&](bool is_first, int i, int z, int w) {
        if (i == n) {
            return abs(z - w);
        }
        if (is_first) {
            if (memo_fst[i].count(w)) return memo_fst[i][w];
            int acc = INT_MIN;
            repeat_from (j, i, n) {
                setmax(acc, go(false, j + 1, a[j], w));
            }
            return memo_fst[i][w] = acc;
        } else {
            if (memo_snd[i].count(z)) return memo_snd[i][z];
            int acc = INT_MAX;
            repeat_from (j, i, n) {
                setmin(acc, go(true, j + 1, z, a[j]));
            }
            return memo_snd[i][z] = acc;
        }
    };
    int result = go(true, 0, z, w);
    // output
    printf("%d\n", result);
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int n , k;
string s;

int main()
{   

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



      cin >> n >> k;
      cin >> s;
      s[k-1] = tolower(s[k-1]);
      cout << s << "\n";


      return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
using ld = long double;

template <std::uint_fast64_t Mod>
class ModInt {
  using u64 = std::uint_fast64_t;

 public:
  u64 val;

  constexpr ModInt(const u64 x = 0) noexcept : val(x % Mod) {}
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    val += rhs.val;
    if (val >= Mod) {
      val -= Mod;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (val < rhs.val) {
      val += Mod;
    }
    val -= rhs.a;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    val = val * rhs.val % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 exp = Mod - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

const ll MOD = 1000000007;
using mint = ModInt<MOD>;

void solve(ll n, ll k) {
  auto lim = min(n,k+1);
  vector<mint> nCk(lim);
  nCk[0] = 1;

  mint ans = 1;
  for (auto i = 1; i != lim; ++i) {
    nCk[i] = nCk[i-1] * (n-i+1) / i;
    ans += nCk[i] * nCk[i] * (n-i) / n;
  }
  
  cout << ans.val << endl;
}

int main() {
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  solve(n, k);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int a[1001],n,m;
int main()
{
	int i,j,k,ans=0;
	char c;
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=0;i<m;i++)
		ans+=a[i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3144
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int h[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &h[i]);
	int ans = 0, c = 0;
	for (i = 1; i < n; i++)
	{
		if (h[i] > h[i - 1])
			c = 0;
		else
			c++;
		if (ans < c)
			ans = c;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        n: usize, m: usize, c: i64,
        b: [i64; m],
        a: [[i64; m]; n],
    }

    let mut ret = 0;
    for i in 0..n {
        let ai = &a[i];
        let mut total = 0;
        for j in 0..m {
            total += ai[j] * b[j];
        }
        total += c;
        if total > 0 {
            ret += 1;
        }
    }
    println!("{}", ret);
}


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

int main()
{
    char c;
    cin >> c;

    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
use strict;
use warnings;
package FenwickTree;
sub new{
	return bless[(0)x$_[1]],$_[0];
}
sub add{
	my$self=shift;
	my$p=1+shift;
	my$x=shift;
	while($p<=@{$self}){
		$self->[$p-1]+=$x;
		$p+=$p&-$p;
	}
}
sub sum{
	my$self=shift;
	return$self->prefixsum($_[1])-$self->prefixsum($_[0]);
}
sub prefixsum{
	my$self=shift;
	my$r=shift;
	my$s=0;
	while($r>0){
		$s+=$self->[$r-1];
		$r-=$r&-$r;
	}
	return$s;
}
package main;
my($N,$Q)=split$",<>;
my$fenwicktree=FenwickTree->new($N);
my@a=split$",<>;
for(0..$#a){
	$fenwicktree->add($_,$a[$_]);
}
for(1..$Q){
	my($t,$a,$b)=split$",<>;
	if($t==0){
		$fenwicktree->add($a,$b);
	}
	else{
		print$fenwicktree->sum($a,$b),$/;
	}
}


Measured memory_bytes: 69060
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> a(N), b(N);
	for (int i = 0; i < N; i++) {
		cin >> a.at(i) >> b.at(i);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int cnt = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (b.at(i) <= a.at(N - 1)) break;

		if (H <= 0) {
			cout << cnt << endl;
			return 0;
		}
		else {
			cnt++;
			H -= b.at(i);
		}
	}

	if (H <= 0) {
		cout << cnt << endl;
	}
	else {
		int n= H / a.at(N - 1);
		if (a.at(N - 1) * n == H) {
			cnt += n;
		}
		else {
			cnt += n + 1;
		}

		cout << cnt << endl;
	}
}

Measured memory_bytes: 4052
s = input()
pre = int(s[:2])
post = int(s[2:])

a = 1 <= pre and pre <= 12
b = 1 <= post and post <= 12

if a and b:
    print("AMBIGUOUS")
elif a:
    print("MMYY")
elif b:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 10**9

int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> A(n),B(m),C(n+1),D(m+1);
    rep(i,n){
        cin >> A.at(i);
    }
    rep(i,m){
        cin >> B.at(i);
    }
    C.at(0) = 0;
    D.at(0) = 0;
    rep(i,n){
        C.at(i+1)=C.at(i)+A.at(i);
    }
    rep(i,m){
        D.at(i+1)=D.at(i)+B.at(i);
    }
    ll j=m;
    ll ans = 0;
    rep(i,n+1){
        if (C.at(i) > k){
            break;
        }
        while (D.at(j) > k-C.at(i)){
            j--;
        }
        ans = max(ans,i+j);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9592
import sys
from heapq import heappush, heappop


class Dijkstra:
    class Edge:
        def __init__(self, end, cost):
            self.to = end
            self.cost = cost

    def __init__(self, node_size, inf):
        self._node = node_size
        self._graph = [[] for _ in range(self._node)]
        self.inf = inf
        self.dist = [self.inf for _ in range(self._node)]

    def add_edge(self, st, ed, cs):
        self._graph[st].append(self.Edge(ed, cs))

    def solve(self, start):
        que = []
        self.dist[start] = 0
        heappush(que, (0, start))
        while que:
            cur_cost, cur_vertex = heappop(que)
            if self.dist[cur_vertex] < cur_cost:
                continue
            for e in self._graph[cur_vertex]:
                if self.dist[e.to] > cur_cost + e.cost:
                    self.dist[e.to] = cur_cost + e.cost
                    heappush(que, (self.dist[e.to], e.to))


if __name__ == '__main__':
    V, E, r = map(int, sys.stdin.readline().split())
    dk = Dijkstra(V, 10 ** 10)
    for i in range(E):
        s, t, d = map(int, sys.stdin.readline().split())
        dk.add_edge(s, t, d)
    dk.solve(r)
    for value in dk.dist:
        if value == dk.inf:
            sys.stdout.write("INF\n")
        else:
            sys.stdout.write("%s\n" % value)


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

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

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

  int n, a, b;

  cin >> n >> a >> b;
  cout << min(b, (a * n)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int AX = 1e2+6;
map<int,int >mpa;
map<int,int >mpb;
struct  Node
{
	int x , y;
}a[AX],b[AX];
bool cmp( const Node &a , const Node &b ){
	if( a.y == b.y ){
		return a.x < b.x;
	}else{
		return a.y < b.y;
	}
}
bool cmp2( const Node &a , const Node &b ){
	if( a.x == b.x ){
		return a.y < b.y;
	}else{
		return a.x < b.x;
	}
}
int main(){
	int n ;
	cin >> n ;
	for( int i = 0 ; i < n ; i++ ){
		cin >> a[i].x >> a[i].y;
	}
	for( int i = 0 ; i < n ; i++ ){
		cin >> b[i].x >> b[i].y;
	}
	int res = 0;
	sort( a , a + n , cmp );
	sort( b , b + n , cmp );
	for( int i = n -1 ; i >= 0 ; i-- ){
		for( int j = 0 ; j < n ; j++ ){
			if( mpb[j] ) continue;
			if( mpa[i] ) continue;
			if( a[i].x < b[j].x && a[i].y < b[j].y ){
				res ++ ;
				mpa[i] = 1;
				mpb[j] = 1;
			}
		}
	}
	int ibest = res ;
	res = 0;
	sort( a , a + n , cmp2 );
	mpa.clear();
	mpb.clear();
	for( int i = n - 1 ; i >= 0 ; i-- ){
		for( int j = 0 ; j < n ; j++ ){
			if( mpb[j] ) continue;
			if( mpa[i] ) continue;
			if( a[i].x < b[j].x && a[i].y < b[j].y ){
				res ++ ;
				mpa[i] = 1;
				mpb[j] = 1;
			}
		}
	}
	ibest = max( res , ibest );
	cout << ibest << endl;
	return 0 ;
}

Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n,m;
    cin>>n>>m;

    vl v(n);
    ll sum = 0;

    forn(i,0,n)
    {
        cin>>v[i];
        sum += v[i];
    }

    ll x = ceil((1.0*sum)/(4.0*m));

    forn(i,0,n)
    {
        if(v[i] >= x)
        {
            m--;
        }
    }

    string ans = (m <= 0 ? "Yes" : "No");

    cout<<ans;





    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
"""AtCoder Beginner Contest 088: B - Card Game for Two
https://atcoder.jp/contests/abc086/tasks/abc088_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def main():
    N = int(input())
    an = list(map(int, input().split()))

    answer = 0
    an.sort(reverse=True)
    for i in range(N):
        if i % 2 == 0:
            answer += an[i]
        else:
            answer -= an[i]

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/*author : Yashvardhan
Tuesday, April 07, 2020
8:45 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

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

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

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

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin >> n;

	vi arr(n);
	vi counti(n+1,0);
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		counti[arr[i]]++;
	}

	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(!counti[i]) continue;
		ans += (counti[i] * (counti[i] - 1))/2;
	}

	for(int i = 0; i <= n - 1; i++){
		int val = counti[arr[i]];
		int contri = (val * (val - 1))/2;
		val--;
		int ncontri = (val*(val - 1))/2;
		int diff = contri - ncontri;
		cout << ans - diff << endl;
	}

	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> list(3);
  for (int i=0; i<3; i++) {
    int a;
    cin >> a;
    list.at(i) = a;
  }
  sort(list.begin(),list.end());
  cout << list.at(0)+list.at(1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(W>=x+r && H>=y+r && x-r>=0 && y-r>=0){
		printf("Yes\n");
	}
	else 
	printf("No\n");
	
	return 0;
}

Measured memory_bytes: 584
import sys

sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
# readlines = sys.stdin.buffer.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

n = ni()
l = [input() for _ in range(n)]
print(len(set(l)))


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

int main(int argc, const char * argv[]) {
    int a , b , c , d ;
    int start , end , time ;
    
    cin >> a >> b >> c >> d ;
    if(a >= 0 && a <= b && b <= 100 && c >= 0 && c <= d && d <=100){
        if(a <= c)
            start = c ;
        else
            start = a ;
        if(b <= d)
                end = b ;
        else
            end = d ;
        time = end - start ;
        if(time <= 0)
            cout << "0" << endl ;
        else
            cout << time << endl ;
        
    }
    else
        cout << "Wrong input!" << endl ;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int max = 0;
  int result = 0;
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    if (max <= h) {
      result++;
      max = h;
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef long long ll;

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;


int main(){
    ll n;
    cin >> n;
    map<ll, ll> primes;
    for (ll p = 2; p * p <= n; p++) {
        int k = 0;
        while (n % p == 0) {
            n /= p;
            k++;
        }
        if (k > 0) {
            primes[p] = k;
        }
    }
    if (n > 1) {
        primes[n] = 1;
    }
    /*
    for(auto& prime : primes){
        cout << prime.first << " " << prime.second << endl;
    }
    */
    int ans = 0;
    for(auto prime : primes) {
        int i = 1;
        while(1){
            if(((i+2)*(i+1))>2*prime.second){
                break;
            }
            i++;
        }
        //cout << i << endl;
        ans += i;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>

using namespace std;





int main()
{
	int w;
	int fee;	//水道料金
	
	while (cin >> w)
	{
		if (w == -1) break;
		fee = 0;
		if (w > 30)
		{
			fee += 160 * (w - 30);
			w = 30;
		}
		if (w > 20)
		{
			fee += 140 * (w - 20);
			w = 20;
		}
		if (w > 10)
		{
			fee += 125 * (w - 10);
			w = 10;
		}
		if (w <= 10)
		{
			fee += 1150;
		}
		cout << 4280 - fee << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160