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

using ll = long long;
const int MOD = 1000000007;
#ifdef LOCAL_ENV
    #define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
    #define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	int len = vv.size();
	for (int i = 0; i < len; ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


int main(){
    int n,m;
    cin >> n >> m;
	if(m<=n){
		p(0);
		return 0;
	}
	vector<int> a(m,0);
	rep(i,m){
		cin >> a[i];
	}
	sort(all(a));

	vector<int> b(m-1,0);
	rep(i,m-1){
		b[i]=a[i+1]-a[i];
	}
	sort(all(b),greater<int>());
	debug(b);
	int ans=accumulate(b.begin()+n-1, b.end(), 0);

  	p(ans);
  
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
S = input()

A = [0] * (N+1)
B = [0] * (N+1)

for i in range(N):
    A[i+1] = A[i]
    if S[i] == "#":
        A[i+1] += 1

for i in range(N,0,-1):
    B[i-1] = B[i]
    if S[i-1] == ".":
        B[i-1] += 1

ans = 10 ** 9
for i in range(N+1):
    ans = min(ans, A[i] + B[i])

print(ans)


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);


ll gcd(ll n, ll m){
    while(true){
        if(n<m) swap(n, m);
        if(!m) break;
        n %= m;
    }
    return n;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];
    vll B = A;

    vector<bool> prime(1000001, true);
    prime[0] = prime[1] = false;
    rep(i, 1000001){
        if(prime[i]){
            for(ll j=i+i; j<1000001; j+=i){
                prime[j] = false;
            }
        }
    }

    bool pc = true;
    REP(i, 2, 1002){
        if(!prime[i]) continue;
        bool flag = false;
        bool valid = true;
        rep(j, N){
            if(A[j]%i==0){
                while(A[j]%i==0) A[j] /= i;
                if(flag){
                    valid = false;
                    break;
                }
                else flag = true;
            }
        }
        if(!valid){
            pc = false;
            break;
        }
    }
    if(pc){
        vector<bool> appeared(1000001, false);
        rep(i, N){
            if(A[i]>=2 && appeared[A[i]]){
                pc = false;
                break;
            }
            appeared[A[i]] = true;
        }
    }

    if(pc) cout << "pairwise coprime" << endl;
    else{
        ll g = B[0];
        REP(i, 1, N) g = gcd(g, B[i]);
        if(g==1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}


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


struct priority_queue{
	size_t __nmemb;
	size_t __size;
	int (*__compar) (const void*, const void*);
	size_t length;
	void *heap;
	void *temp;
	int (*push)(struct priority_queue*, int);
	int (*pop)(struct priority_queue*);
	void (*clear)(struct priority_queue*);
	void (*dispose)(struct priority_queue*);
};

int priority_queue_push(struct priority_queue *p, int value){
	if(p->length == p->__nmemb){
		return -1;
	}
	void *heap = p->heap - p->__size;
	p->length++;
	memcpy(heap+(p->length*p->__size), (void*)&value, p->__size);

	size_t node;
	for(node=p->length; p->__compar(heap+node*p->__size, heap+(node/2)*p->__size)<0 && node != 1; node/=2){
		memcpy(p->temp, heap+node*p->__size, p->__size);
		memcpy(heap+node*p->__size, heap+(node/2)*p->__size, p->__size);
		memcpy(heap+(node/2)*p->__size, p->temp, p->__size);
	}
	return 0;
}

int priority_queue_pop(struct priority_queue *p){
	if(p->length == 0){
		return 0;
	}
	int ret;
	size_t node, downto;
	size_t left, right;
	char f;
	void *heap = p->heap - p->__size;
	
	ret = *((int*)(heap+p->__size));
	
	memcpy(heap+p->__size, heap+(p->length*p->__size), p->__size);
	p->length--;
	node = 1;
	while(1) {
		downto = node;
		left = node<<1;
		right = left+1;
		if (left<=p->length && p->__compar(heap+downto*p->__size, heap+left*p->__size)>0){
			downto=left;
		}
		if (right<=p->length && p->__compar(heap+downto*p->__size, heap+right*p->__size)>0){
			downto = right;
		}
		if(downto==node){
			break;
		}
		memcpy(p->temp, heap+node*p->__size, p->__size);
		memcpy(heap+node*p->__size, heap+downto*p->__size, p->__size);
		memcpy(heap+downto*p->__size, p->temp, p->__size);
		node = downto;
	}
    return ret;
}

void priority_queue_clear(struct priority_queue *p){;
	p->length = 0;
}

void priority_queue_dispose(struct priority_queue *p){
	free(p->heap);
}

int create_priority_queue(struct priority_queue *p, size_t __nmemb, /*size_t __size, */int (*__compar) (const void*, const void*)){
	size_t __size = sizeof(int);
	if((p->heap = malloc(__nmemb * __size)) == NULL){
		return -1;
	}
	if((p->temp = malloc(__size)) == NULL){
		free(p->heap);
		return -1;
	}
	p->__nmemb = __nmemb;
	p->__size = __size;
	p->__compar = __compar;
	p->length = 0;
	p->push = priority_queue_push;
	p->pop = priority_queue_pop;
	p->clear = priority_queue_clear;
	p->dispose = priority_queue_dispose;
	return 0;
}

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

struct priority_queue A;
int N, M, a, i;
long sum;

int main(void){
	scanf("%d%d", &N, &M);
	create_priority_queue(&A, N, compare_int);
	for(i=0; i<N; i++){
		scanf("%d", &a);
		sum += a;
		A.push(&A, a);
	}
	for(i=0; i<M; i++){
		a = A.pop(&A);
		sum -= (a+1)>>1;
		A.push(&A, a>>1);
	}
	printf("%ld\n", sum);
}



Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;

int main() {
  ll n, k; cin >> n >> k;
  cout << min(n % k, k - n % k) << endl;
  return 0;
}



Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

vector<int> graph[202020];
vector<int> score(202020);

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

  int n, q; cin >> n >> q;
  for (int i = 0; i < n - 1; ++i) {
    int a, b; cin >> a >> b;
    --a; --b;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }

  for (int i = 0; i < q; ++i) {
    int p, x; cin >> p >> x;
    --p;
    score[p] += x;
  }

  auto dfs = [&](const auto& dfs, int cur, int prev) -> void {
    for (int next : graph[cur]) {
      if (next == prev) continue;
      score[next] += score[cur];
      dfs(dfs, next, cur);
    }
  };

  dfs(dfs, 0, -1);

  for (int i = 0; i < n; ++i) {
    cout << score[i] << " ";
  }
  cout << '\n';

  return 0;
}


Measured memory_bytes: 20736
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    from collections import defaultdict
    ret = defaultdict(list)
    for i in range(self.n):
      ret[self.find(i)].append(i)
    return ret

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
P = list(map(int, input().split()))

uf = UnionFind(N)

for _ in range(M):
  x, y = map(lambda x: int(x)-1, input().split())
  uf.union(x, y)

D = uf.all_group_members()

ans = 0

for L in D.values():
  check = set(L)
  for i in L:
    if P[i]-1 in check:
      ans += 1 

print(ans)


Measured memory_bytes: 34212
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,p;
    cin>>n;
    p=n%10;
    if(p==3)
    cout<<"bon";
    else if(p==0||p==1||p==6||p==8)
    cout<<"pon";
    else
    cout<<"hon";
    return 0;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define FOR(i, x, y) for(int i = x; i < y; i++)
#define endll cout << "\n"
#define For(n) for(int i = 0; i < n; i++)
const ll maxn = 1000 + 100;
const int inf = 1e9;

bool isprime(int x)
{
    if(x <= 1)
        return false;
    for(int i = 2; i * i < x; i++)
        if(x % i == 0)
            return false;
    return true;
}
ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int res = 0;
    for(int i = 0; i < 1000; i++)
    {
        if(a <= i && i < b && c <= i && i < d)
            res ++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int c[300000];
vector<int>v[300000];
vector<int>t[300000];
ll dp[300000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d",&c[i]);c[i]--;
		v[c[i]].push_back(i);
	}
	rep(i,200000){
		if(v[i].size()<=1)continue;
		rep(j,v[i].size()-1){
			if(v[i][j+1]-v[i][j]>1)t[v[i][j]].push_back(v[i][j+1]);
		}
	}
	dp[0]=1;
	rep(i,n){
		(dp[i+1]+=dp[i])%=MOD;
		for(int j:t[i]){
			(dp[j]+=dp[i])%=MOD;
		}
	}
	cout<<dp[n]<<endl;
}

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

int G[101][101];

int main(){
  int n, u, k, v;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v;
      G[u][v] = 1;
    }
  }
  for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++)
      cout << G[i][j] << (j == n ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, ans{};
  string S;
  cin >> N >> S;
  vector<vector<int>> v(10);
  for (int i = 0; i != N; ++i)
    v[S[i]-'0'].push_back(i);
  for (int i = 0; i != 10; ++i) {
    if (v[i].empty()) continue;
    for (int k = 0; k != 10; ++k) {
      if (v[k].empty()) continue;
      for (int j = 0; j != 10; ++j) {
        auto it1 = upper_bound(begin(v[j]),end(v[j]),v[i].front());
        auto it2 = lower_bound(begin(v[j]),end(v[j]),v[k].back());
        if (it2 - it1 > 0) ++ans;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3884
/*
Problem

Category
全探索・全列挙

URL:
https://atcoder.jp/contests/abc095/tasks/arc096_a


考察:

Date: 2020/03/31
*/

#include <bits/stdc++.h>
// #include "../utils.cpp"
using namespace std;
// #define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int a, b, c, x, y;

/* ======================== */

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

void getInput() {
    cin>>a>>b>>c>>x>>y;
}

void solve() {
    c *=2;
    int nc = 0;
    // cout<<"a, b, c: "<<a<<", "<<b<<", "<<c<<endl;
    // cout<<"x, y: "<<x<<", "<<y<<endl;
    if (c < a) {
        nc += x;
        x = 0;
        y -= nc;
        if (y <= 0) {
            cout<<nc*c<<endl;
            return;
        }
    }
    if (c < b) {
        nc += y;
        x -= nc;
        y = 0;
        if (x <= 0) {
            cout<<nc*c<<endl;
            return;
        }
    }

    while(x > 0 and y > 0) {
        if (a + b < c) break;
        
        nc++;
        x--;
        y--;
    }
    cout<<x*a+y*b+nc*c<<endl;
    // cout<<"x, y, nc: "<<x<<", "<<y<<", "<<nc<<endl;
    


    // cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

void bfs(ll n, vector<vll> &nx, vll &ans) {
	queue<ll> task;
	vector<bool> seen(n, false);
	task.push(0);
	seen[0] = true;
	while (task.size()) {
		ll x = task.front();
		task.pop();
		for (ll i = 0; i < nx[x].size(); i++) {
			if (seen[nx[x][i]]) continue;
			ans[nx[x][i]] = x + 1;
			seen[nx[x][i]] = true;
			task.push(nx[x][i]);
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, m;
	cin >> n >> m;
	vector<vll> nx(n, vll(0));
	vll a(m), b(m);
	for (ll i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		nx[a[i]].push_back(b[i]);
		nx[b[i]].push_back(a[i]);
	}

	vll ans(n, -1);
	bfs(n, nx, ans);
	Yes();
	for (ll i = 1; i < n; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 16156
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
count=0
for i in range(n):
  for j in range(i+1,n):
    count+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
print(count*2/n)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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 long long INF = 1LL << 60;
char s[60][60];
int bomb[60][60];
int main()
{
	int N;
	cin >> N;
	long long res = 1;
	long long n = 1;
	for (long long i = 1;i <= N;i++) {
		n = i*n % (1000000000+7);
	}
	cout << n << endl;
}


Measured memory_bytes: 256
#最小全域木　プリム法
n = int(input())
x = []
for i in range(0,n):
    X,Y = [int(_x) for _x in input().split()]
    x.append((i,X,Y))
x = sorted(x, key=lambda x:x[1])
y = sorted(x, key=lambda x:x[2])

g = [[] for _ in range(n)]
for j in range(1, len(x)):
    _i, _xx, _yy = x[j-1]
    i, xx, yy = x[j]
    dis1 = abs(_xx - xx)
    dis2 = abs(_yy - yy)
    g[i].append((dis1, _i))
    g[i].append((dis2, _i))
    g[_i].append((dis1, i))
    g[_i].append((dis2, i))

for j in range(1, len(y)):
    _i, _xx, _yy = y[j-1]
    i, xx, yy = y[j]
    dis1 = abs(_xx - xx)
    dis2 = abs(_yy - yy)
    g[i].append((dis1, _i))
    g[i].append((dis2, _i))
    g[_i].append((dis1, i))
    g[_i].append((dis2, i))

import heapq
def prim_heap():
    used = [True] * n #True:不使用
    edgelist = []
    for e in edge[0]:
        heapq.heappush(edgelist,e)
    used[0] = False
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,e)
        res += minedge[0]
    return res

edge = g
print(prim_heap())

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

int main() {
	int n;
	cin >> n;
	set<string>st;
	for(int i=0;i<n;i++){
	    string ch;
	    cin >> ch;
	    st.insert(ch);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 19200
use std::io::Read;
use std::cmp::min;

const INF: isize = std::isize::MAX;

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

    let v: usize = iterator.next().unwrap().parse().unwrap();
    let e: usize = iterator.next().unwrap().parse().unwrap();

    let mut d: Vec<Vec<isize>> = vec![vec![INF; v]; v];
    for i in 0..v {
        d[i][i] = 0;
    }

    for _ in 0..e {
        let s: usize = iterator.next().unwrap().parse().unwrap();
        let t: usize = iterator.next().unwrap().parse().unwrap();
        let c: isize = iterator.next().unwrap().parse().unwrap();
        d[s][t] = c;
    }

    for k in 0..v {
        for i in 0..v {
            if d[i][k] == INF {
                continue;
            }
            for j in 0..v {
                if d[k][j] == INF {
                    continue;
                }
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    let mut has_negative = false;
    for i in 0..v {
        if d[i][i] < 0 {
            has_negative = true;
            break;
        }
    }

    if has_negative {
        return "NEGATIVE CYCLE".to_string();
    }

    let mut result = String::new();
    for i in 0..v {
        for j in 0..v {
            if d[i][j] == INF {
                result.push_str("INF ");
            } else {
                result.push_str(&format!("{} ", d[i][j]));
            }
        }
        result = result.trim().to_string();
        result.push_str("\n");
    }
    return result.trim().to_string();
}

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

    let answer = solve(&buf);

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



Measured memory_bytes: 5060
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-04-26 20:01:09
 * @LastEditTime: 2020-04-26 20:02:13
 * @FilePath: \VSC\C++\Practice\AC abc164 A.cpp
 */
#include<bits/stdc++.h>
using namespace std;

int x,y;
signed main(){
    scanf("%d%d",&x,&y);
    puts(x<=y?"unsafe":"safe");
    return 0;
}

Measured memory_bytes: 3764
N=int(input())
A=list(map(int,input().split()))
cnt=[0 for _ in range(100001)]
for i in range(N):
    cnt[A[i]]+=1
ans=sum(A)
Q=int(input())
for _ in range(Q):
    B,C=map(int,input().split())
    cnt[C]+=cnt[B]
    ans+=(C-B)*cnt[B]
    cnt[B]=0
    print(ans)


Measured memory_bytes: 20812
#include <iostream>

int main() {
    long long totalHeight=0;
    int arrSize;
    std::cin>>arrSize;
    int arr[arrSize];
    for(int i=0, x; i<arrSize; i++){
        std::cin>>x;
        arr[i]=x;
        if(i!=0){
            if(arr[i-1]>arr[i]){
                totalHeight+=arr[i-1]-arr[i];
                arr[i]=arr[i-1];
            }
        }
    }
    std::cout << totalHeight << std::endl;
    return 0;
}


Measured memory_bytes: 4412
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll ans=0;
ll n;
string s;
ll cnt=0;
vector<P> p;
ll sz;
int main()
{
	cin>>s;
	//p.reserve(1000001);
	n=s.length();
	rep(i,n){
		if(i==0){
			if(s[0]=='J') p.pb(P(1,0));
			else if(s[0]=='O') p.pb(P(1,1));
			else p.pb(P(1,2));
		}
		else{
			if(s[i]!=s[i-1]){
				if(s[i]=='J') p.pb(P(1,0));
				else if(s[i]=='O') p.pb(P(1,1));
				else p.pb(P(1,2));
			}
			else{
				p[p.size()-1].fr++;
			}
		}
	}
	for(ll i=0;i+2<p.size();i++){
		if(p[i].sc==0&&p[i+1].sc==1&&p[i+2].sc==2&&p[i].fr>=p[i+1].fr&&p[i+1].fr<=p[i+2].fr){
			ans = max(ans , p[i+1].fr );
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 20792
// Problem : C - 755
// Contest : AtCoder - AtCoder Beginner Contest 114
// URL : https://atcoder.jp/contests/abc114/tasks/abc114_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int cnt=0;
ll n;
void dfs(ll val)
{
	if(val>n)
	return;
	else
	{
		ll v;
		v=val;
		set<ll> s;
		while(val>0)
		{
			s.insert(val%10);
			val/=10;
		}
		if(sz(s)==3)
			cnt++;
		dfs(v*10+3);
      	dfs(v*10+5);
        dfs(v*10+7);
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	cin>>n;
	dfs(0);
	cout<<cnt<<nl;
}
// read the question correctly (ll vs int)
// template by bqi343

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

//using ll=long long;

const int MAX = 2200000;
const long long MOD = 1000000007;
long long INF = 90000000001000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;//0!,1!
    finv[0] = finv[1] = 1;//(0!)^(-1),(1!)^(-1)
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;//i! = i*(i-1)!
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;//1/i
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
COMinit();

int x,y,sum;cin >> x >> y;
int a,b;a = (2*y-x)/3;b=(2*x-y)/3;

if ((2*y-x)%3!=0||(2*x-y)%3!=0)
{
    cout << 0<<endl;
    return 0;
}



long long ans;
int mn = min(a,b);
sum = a + b;
ans = COM(sum,mn);

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




Measured memory_bytes: 51840
#include<stdio.h>
int main()
{
	int i,a,b,n,s,f;
	scanf("%d%d",&a,&b);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&s,&f);
		if(a<f&&b>s){
			printf("1\n");
			return 0;
		}
	}
	printf("0\n");
    return 0;
}

Measured memory_bytes: 2676
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define testcase int t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<long long int,long long int>
#define ub upper_bound // '>'
#define lb lower_bound // '>='
#define updiv(a,b) (ceil)((a)*(1.0)/(b))
typedef long long int ll;
typedef unsigned long long int ull;
#define M 1000000007
using namespace std;
int main()
{
    fast
ull a,b,c,res1,res2;
cin>>a>>b>>c;
res1=(a*a)+(b*b)+(c*c);
res2=2*(a*b+b*c+c*a);
if(res1>res2&&(c>(a+b)))
    cout<<"Yes";
else
    cout<<"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;
using ll = long long;

const int mod = pow(10,9) + 7;

int main()
{
  int n;
  cin >> n;
    
  ll a = 1, b = 1, d = 1;

  rep(i,n){
    a = (a*10) % mod;
    b = (b*9) % mod;
    d = (d*8) % mod;
  }

  ll ans = (a -2*b + d) % mod;
  
  if(ans < 0) ans += mod;
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define ll long long
#define mod (ll)1000000007

const ll INF = 1e11;

void solve(){

    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if(x / d >= k) cout << x - k*d << endl;
    else{
        k -= x / d;
        x %= d;
        if(k & 1) cout << abs(x - d) << endl;
        else cout << x << endl;
    }

    return;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



Measured memory_bytes: 3604
#include<stdio.h>
#include<string.h>
char s[10];
int i,p;
int main(){
    scanf("%s",s);
    p=0;
    for(i=1;s[i];i++) if(s[i-1]=='A' && s[i]=='C') p=1;
    if(p) printf("Yes\n"); else printf("No\n");
}


Measured memory_bytes: 128
n,m = map(int, input().split())
h = list(map(int, input().split()))
r = [0]*n
no = 1
for i in range(m):
    a,b = map(int, input().split())

    if(h[a-1] > h[b-1]):
        r[b-1] = 1
    elif(h[a-1] < h[b-1]):
        r[a-1] = 1
    elif(h[a-1] == h[b-1]):
        r[a-1] = 1
        r[b-1] = 1

count = 0
for i in range(n):
    if(r[i] == 0):
        count += 1

print(count)

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

#define all(x) begin(x), end(x)
#define cina(s, n, a) for(int quer = s; quer < n; quer++) cin >> a[quer]
#define mod(a, b) (abs(b) + (a % abs(b))) % abs(b)
#define setp(x) fixed << setprecision(x)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const int N = 100500; // are you sure?

void solve(){
    int n;
    cin >> n;
    vi a(n + 1), b(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    b = a;
    sort(all(a));
    int l = (n) / 2;
    for(int i = 1; i <= n; i++){
        if(b[i] > a[l]){
            cout << a[l] << '\n';
        }
        else cout << a[l + 1] << '\n';
    }
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, u, v;
vector<int> G[100005];

int ret = 0;

void dfs(int x, int px, int d, vector<int>& dist){
  if(dist[x] != -1) return;
  dist[x] = d;
  rep(i,G[x].size()){
    if(G[x][i] == px) continue;
    dfs(G[x][i], x, d+1, dist);
  }
}

void dfs2(int x, int px, int d, vector<int>& dist, vector<int>& dist2){
  if(dist2[x] != -1) return;
  
  if(dist[x] < d) return;
  if(dist[x] == d){
    ret = max(ret, d);
    return;
  }

  ret = max(ret, dist[x]-1);
  dist2[x] = d;
  rep(i,G[x].size()){
    if(G[x][i] == px) continue;
    dfs2(G[x][i], x, d+1, dist, dist2);
  }
}

int main(){
  cin >> N >> u >> v;
  u--;
  v--;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> taka(N,-1), ao(N,-1);
  dfs(v,-1,0,ao);
  dfs2(u,-1,0,ao,taka);

  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 12928
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n;
  cin >> n;
  
  ll dist[n][n];
  ll ans = 0;
  REP(i,n){
    REP(j,n){
      cin >> dist[i][j];
      ans += dist[i][j];
    }
  }
  
  
  
  REP(i,n){
    REP(j,n){
      bool f = true;
      REP(k,n){
        if(dist[i][j] > dist[i][k] + dist[k][j]){
          cout << -1 << endl;
          return 0;
        }
        if(k != j && i != k && dist[i][j] == dist[i][k] + dist[k][j] && f){
          ans -= dist[i][j];
          f = false;
        }
      }
    }
  }
  
  cout << ans/2 << endl;
  
 return 0;
}

Measured memory_bytes: 896
N,M = map(int,input().split())
maxL = 0
minR = 10**6
for i in range(M):
    L,R = map(int,input().split())
    if (maxL < L) :
        maxL = L
    if (minR > R) :
        minR = R

ans = minR - maxL + 1

if (ans < 0):
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
index = 0
if n % 2 == 0:
    for i in range(n - 1, -1, -2):
        ans[index] = a[i]
        index += 1
    for i in range(0, n, 2):
        ans[index] = a[i]
        index += 1
else:
    for i in range(n - 1, -1, -2):
        ans[index] = a[i]
        index += 1
    for i in range(1, n, 2):
        ans[index] = a[i]
        index += 1

print(" ".join(map(str, ans)))

Measured memory_bytes: 29764
import bisect
N = int(input())
S = input()
where = {str(s):[] for s in range(10)}
for i, s in enumerate(S):
    where[s].append(i)
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    #print(v)
    s = v[0]
    if len(where[s]) > 0:
        before_index = where[s][0]
        #print('\t', s, before_index)
        c = 1
        for j in range(1, 3):
            s = v[j]
            if len(where[s]) > 0:
                next_index = bisect.bisect_left(where[s], before_index+1)
                if next_index == len(where[s]):
                    break
                #print('\t', s, before_index, next_index)
                next_index = where[s][next_index]
                #print(s, before_index, next_index)
                if next_index > before_index:
                    before_index = next_index
                    c += 1
            else:
                break
        if c == 3:
            #print('\t ok')
            ans += 1
print(ans)

Measured memory_bytes: 4468
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

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

	int n;
	cin >> n;
	n--;
	vector<char> ans;
	while(n>=0){
		int x = n%26;
		ans.pb(char(x+'a'));
		n/=26;
		n--;
	}
	reverse(all(ans));
	for(auto it: ans)cout << it;
		cout << endl;

	return 0;
}  


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

const int N = 100;

int a[N];
int n, k;

int main(){
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++ i){
		scanf("%d", &a[i]);
	}
	std::sort(a, a + n);
	int ans = 0;
	for (int i = n - k; i < n; ++ i){
		ans += a[i];
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  vector<ll> sum(N+1);
  rep(i, N) sum[i+1] = sum[i]+A[i];
  int ans = 1;
  for (int i=N-1; i>0; i--) {
    if (sum[i]*2 >= A[i])
      ans++;
    else
      break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int MAXV =  3502;

int main() {
  ll N;
  cin >> N;
  rep(n, MAXV) rep(h, MAXV) {
    if (n == 0 || h == 0) continue;
    if((4 * h * n - h * N - n * N) == 0) continue;
    ll denominator = (h * n * N);
    ll numerator = (4 * h * n - h * N - n * N);
    ll w = denominator / numerator;
    if (w <= 0 || (denominator % numerator)) continue;
    cout << n << " " << h <<" " << w << endl;;
    return 0;
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<vector>
std::priority_queue<int, std::vector<int>, std::greater<int>> a;
int N, sum;
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		sum += tmp;
		a.push(tmp);
	}
	if (sum % 10 != 0) { 
		std::cout << sum << std::endl;
		return 0;
	}
	while (!a.empty()) {
		int tmp = a.top();
		a.pop();
		int ans = sum - tmp;
		if (ans % 10 != 0) {
			std::cout << ans << std::endl;
			return 0;
		}
	}
	std::cout << 0 << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MOD = 998244353;
const double PI = acos(-1.0);
const double EXP = 1e-8;
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
inline ll qpow(ll a, ll b)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
bool ok(string s, int l, int r)
{
    while (s[l] == s[r])
        ++l, --r;
    return l >= r;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    map<ll,ll>num;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        num[a[i]]++;
    }
    ll all=0;
    for(auto i:num)
    {
        all+=i.sec*(i.sec-1)/2;
    }
    for(int i=0;i<n;i++)
    {
          cout<<all-(num[a[i]]*(num[a[i]]-1)/2)+((num[a[i]]-1)*(num[a[i]]-2))/2<<'\n';
    }
}


Measured memory_bytes: 10368
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if(K > (N-1)*(N-2)/2) {
			System.out.println(-1);
			return;
		}
		System.out.println(N*(N-1)/2-K);
		for(int i = 2; i <= N; i++)
			System.out.println(1 + " " + i);
		int M = 0;
		for(int i = 2; i <= N; i++) {
			for(int j = i+1; j <= N; j++) {
				M++;
				if(M > (N-1)*(N-2)/2-K)
					break;
				System.out.println(i + " " + j);
			}
		}
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp    make_pair
#define pb    push_back
#define F     first
#define pi 	  3.14159265358979323846
#define S     second
#define ll    long long
#define ld    long double
#define sz(s) (ll)s.size() 
#define vl    vector < ll >
#define pll   pair < ll, ll >
#define ml    map < ll, ll >
#define mod   1000000007
#define MAXN  50005 
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define inv(i,a,b)  for(ll i=a;i>=b;i--)
#define all(a)  (a).begin(),(a).end()
using namespace std;
ll p[1000005]={0}; 
ll ans=0,i;
void solve(ll n){
	ll i;
	if(p[n]>1)return;
	if(n>1 && p[1])return;
	for(i=2;i*i<=n;i++)if(n%i==0 && (p[i] || p[n/i]) )return;
	ans++;
	return;
}
int main(){
	IOS;
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n)cin>>a[i],p[a[i]]++;
	rep(i,0,n){
		solve(a[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 12916
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int n, k;
  cin >> n >> k;
  vecint a(n);
  REP(i,n) cin >> a[i];
  sort(all(a));
  int sum = 0;
  REP(i,k){
    sum += a[n - 1 - i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

bool check(string &S) {
	rep(i, S.size() / 2 + 1) {
		if (S[i] != S[S.size() - i - 1]) return false;
	}
	return true;
}

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

	string T = "";
	rep(i, S.size()) {
		if (S[i] != 'x') {
			T += S[i];
		}
	}

	if (!check(T)) {
		cout << -1 << endl;
		return 0;
	}

	int ret = 0;
	int pt = 0;
	int pt2 = S.size() - 1;

	while (true) {
		int cnt1 = 0;
		int cnt2 = 0;
		while (pt < S.size() && S[pt] == 'x') {
			pt++;
			cnt1++;
		}
		while (pt2 >= 0 && S[pt2] == 'x') {
			pt2--;
			cnt2++;
		}
		if (pt > pt2) break;
		ret += abs(cnt1 - cnt2);
		pt++;
		pt2--;
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 640
def main():
    _ = input()
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    sum_prev = sum(A)

    for i in range(len(A)-1):
        b = B[i]
        b = max(0, b - A[i])
        A[i] = max(0, A[i] - B[i])
        A[i+1] = max(0, A[i+1] - b)

    print(sum_prev - sum(A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 18624
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll K) {
  ll res = 0;
  for (int b = K + 1; b <= N; ++b) {
    res += (N + 1) / b * (b - K);
    res += max(0LL, (N + 1) % b - K);
    if (K == 0) --res;
    // cout << b << " " << res << endl;
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll K;
	scanf("%lld", &N);
	scanf("%lld", &K);
	solve(N, K);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    ans = 1
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    if ans < grid[i][x] + count:
                        ans = grid[i][x] + count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i][x] + count:
                ans = grid[i][x] + count

    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)


Measured memory_bytes: 98008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int N = 2e5+5;
ll f[N][19],g[N][19];
int n;ll a[N],c[17];
int main(){
    ios::sync_with_stdio(false);
    memset(f,0x3f,sizeof(f));
    memset(g,0x3f,sizeof(g));
    cin>>n;c[0]=1;
    for(int i=1;i<=15;i++)
        c[i]=c[i-1]*4;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=0;i<=15;i++)
        f[1][i]=i;
    for(int i=2;i<=n;i++){
        for(int j=0;j<=15;j++){
            for(int k=15;k>=0;k--){
                if(a[i-1]*c[k]>=a[i]*c[j]) {
                    f[i][j] = min(f[i][j], f[i - 1][k] + j);
                }
            }
            if(f[i][j]==4557430888798830399LL) f[i][j]=f[i][j-1]+i;
        }
    }
    for(int i=0;i<=15;i++)
        g[n][i]=i;
    for(int i=n-1;i;i--){
        for(int j=0;j<=15;j++){
            for(int k=15;k>=0;k--){
                if(a[i+1]*c[k]>=a[i]*c[j]){
                    g[i][j]=min(g[i][j],g[i+1][k]+j);
                }
            }
            if(g[i][j]==4557430888798830399LL) g[i][j]=g[i][j-1]+(n-i+1);
        }
    }
    ll ans = INF;
    f[0][0]=g[0][0]=f[n+1][0]=g[n+1][0]=0;
    for(int i=0;i<=n;i++){
        ll n1=INF,n2=INF;
        for(int j=0;j<=15;j++){
            n1 = min(n1,f[i][j]);
            n2 = min(n2,g[i+1][j]);
        }
        ans = min(ans,n1*2+n2*2+i);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 61184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) list.add(sc.nextInt());
        Collections.sort(list);

        for (int i = 0; i < n-1; i++) {
            if (list.get(i).equals(list.get(i+1))) {
              System.out.println("NO"); 
              return;
            }
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 93568