akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

int main(){
    int n;
    cin >> n;
    vector<long> a(n);
    rep(i,n) cin >> a[i];
    
    long suma = a[0], sumb = 0;
    for(int i=1; i<n; i++) sumb += a[i];

    long ans = abs(suma - sumb);

    for(int i=1; i<n-1; i++){
        suma += a[i];
        sumb -= a[i];
        if(abs(suma - sumb) < ans) ans=abs(suma - sumb);
    }

    cout << ans << endl;
}


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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> A(n), F(n);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<int>());
    auto f = [&](ll c) {
        ll a = 0;
        rep(i, n) {
            ll b = ll(A[i])*F[i] - c;
            if (b>0) {
                a += (b-1)/F[i] + 1;
            }
        }
        return a <= k;
    };
    ll l = -1, r = 1e13;
    while (r-l > 1) {
        ll m = (l+r) / 2;
        if (f(m)) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func max(a []int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func min(a []int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}

func main() {
	// sc.Split(bufio.ScanWords)
	s := nextLine()

	mp := make(map[rune]bool, 26)
	for _, v := range s {
		if mp[v] {
			fmt.Println("no")
			return
		}
		mp[v] = true
	}
	fmt.Println("yes")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ans=max(max(1ll*a*c,1ll*a*d),max(1ll*b*c,1ll*b*d));
	cout<<ans<<endl;
} 

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

using namespace std;

typedef vector<int> vi;
#define all(c) (c).begin(), (c).end()
#define rep(i,b) for(int i=0; i<(int)(b); i++)
int main(){
    int n;
    while(cin>>n){
        vi v(n);
        rep(i,n) cin>>v[i];
        sort(all(v));
        int ans = 0;
        rep(i,n) ans+= (n-i)*v[i];
        cout << ans << endl;
    }
}

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

#define BUF 12

int main(void) {
  char strs[BUF], strt[BUF];
  scanf("%s %s", strs, strt);
  if (!strncmp(strs, strt, strlen(strs)) && (strlen(strt) - strlen(strs) == 1)) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int X,max=1,tmp;
    cin >> X;

    for(int i=1;i<=100;i++){
        tmp=i;
        for(int j=1;j<=100;j++){
            tmp=tmp*i;
            if(tmp>max&&tmp<=X){
            max=tmp;
            }
            if(tmp>X)break;
        }
    }

    cout << max <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a,b;

int main(){
	cin>>a>>b;
  	if(a==1){
		a+=15;
    }
  	if(b==1){
      	b+=15;
    }
  	if(a>b){
		cout<<"Alice"<<endl;
    }else if(a<b){
		cout<<"Bob"<<endl;
    }else{
		cout<<"Draw"<<endl;
    }
  	return 0;
}

Measured memory_bytes: 256
N = int(input())
tmp = list(map(int, input().split()))

h = [0]
h.extend(tmp)

res = 0

while 1 == 1:
    if max(h) <= 0:
        break
    for i in range(1,len(h)):
        if h[i] > 0 and h[i-1] <= 0:
            res = res + 1
    h = list(map(lambda x:x - 1,h))

print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define N 200009
#define inf 1e18
int mod=998244353;


int a[N];
int n;
map<pair<int,int>,int>dp;
int fun(int idx,int pick){
    if(pick>n/2 or pick+(n-idx+1)/2 <n/2)return -inf;
    if(idx>=n)return 0;
    if(dp.count({idx,pick}))return dp[{idx,pick}];
    int x=fun(idx+1,pick);
    int y=fun(idx+2,pick+1)+a[idx];
    dp[{idx,pick}]=max(x,y);
    return max(x,y);
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    cout<<fun(0,0)<<"\n";
    return 0;
}

Measured memory_bytes: 33324
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int D,G;
  cin >> D>>G;
  vec<vec<int>>a(D,vec<int>(2,0));
  REP(i,D){
    cin>>a[i][0]>>a[i][1];
  }
  int minans=INF;
  REPB(i,D){
   int score=0,ans=0;
   REP(j,D){
     if (i & BIT(j)){
       score+=(j+1)*100*a[j][0]+a[j][1];
       ans+=a[j][0];
     }
   }
   bool flg = score>=G;
    if (!flg){
    REPR(j,D-1){
      if (!(i & BIT(j))){
        int scoreadd = (j+1)*100*(a[j][0]-1);
         if (score+scoreadd>=G){
          ans+=ceil(1.0*(G-score)/((j+1)*100));
          flg = true;
          break;
        }else{
          score+=scoreadd;
          ans+=a[j][0]-1;
        }
      }
    }
   }
    if (flg){
     minans = min(ans,minans);
   }
 }
  print(minans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>

using namespace std;

int main()
{
  int r1, r2;
  char r3;
  string str, fm;
  bool f;

  while(cin>>fm){
    r1 = r2 = 0;
    r3 = ' ';
    f = true;
    str = "";
    for(int i = 0; f && i < fm.size(); ++i){
      if(isdigit(fm[i])){
	str += fm[i];
      } else {
	r2 = atoi(str.c_str());
	str = "";

	if(r3 == ' ') r1 = r2;
	else if(r3 == '+') r1 += r2;
	else if(r3 == '-') r1 -= r2;
	else if(r3 == '*') r1 *= r2;
	else if(r3 == '=') break;
	
	if(r1 < 0 || r2 < 0 || r2 >= 10000 || r1 >= 10000) f = false;
	r3 = fm[i];
      }
    }

      if(!f) cout << "E" << endl;
      else cout << r1 << endl;
  }

  return 0;
}

Measured memory_bytes: 0
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

alias sread = () => readln.chomp();
enum MOD = 10 ^^ 9 + 7;

void main()
{
    long N, K;
    scan(N, K);
    double ans = 0.0;
    foreach (n; 1 .. N + 1)
    {
        long tmp = n;
        long cnt = 0;
        while (tmp < K)
        {
            cnt++;
            tmp *= 2;
        }
        // writeln(cnt);
        ans += (1.0 / N) * (1.0 / (2 ^^ cnt));
    }
    writefln("%.10f", ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n,k,a;
const ll mod=1e9;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	cin>>n>>k;
//	while(k<=n){
//		sum1=0,sum2=0;
//		for(ll i=0;i<k;i++)sum1+=i,sum1%=mod;
//		for(ll i=0;i<k;i++)sum2+=(n-i),sum2%=mod;
//		ans+=((sum2+mod-sum1+1)%mod);ans%=mod;
//		k++;
//	}
//	cout<<ans;
	cin>>n>>k;
  	for(int i=k;i<n+2;i++)a=(a+i*(n-i+1)+1)%1000000007;
  	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 3652
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}


enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

bool isPrime(int N) {
    if (N <= 1) return false;
    for (int i = 2; i*i <= N; i++) {
        if (N % i == 0) return false;
    }
    return true;
}

enum lim = 10^^5 + 1;

void main() {
    int Q;
    scan(Q);

    auto b = new bool[](lim);
    foreach (i ; 1 .. lim) {
        b[i] = (i % 2) && isPrime(i) && isPrime((i + 1) / 2);
    }
    auto c = new int[](lim + 1);
    foreach (i ; 1 .. lim + 1) {
        c[i] = c[i - 1] + b[i - 1];
    }

    foreach (_ ; 0 .. Q) {
        int li, ri;
        scan(li, ri);
        auto ans = c[ri + 1] - c[li - 1];
        writeln(ans);
    }
}


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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 1e5 + 10;

int n;
int val[N], cnt[16];
int dis[1 << 16];

queue<int> q;

void relax(int o, int d){
	if(dis[o] > d) dis[o] = d, q.push(o);
}

int SPFA(int S){
	memset(dis, 0x3f, sizeof dis);
	dis[S] = 0;
	q.push(S);
	while(!q.empty()){
		int o = q.front(); q.pop();
		if(!o) return dis[o];
		For(i, 0, 14) if(o & (1 << i)) relax(o ^ (1 << i), dis[o] + 1);
		For(i, 0, 14) if(o & (1 << i)) For(j, i + 1, 14) if(o & (1 << j))
			For(k, 1, 15){
				int u = (i + 1) ^ k, v = (j + 1) ^ k;
				int st = o ^ (1 << i) ^ (1 << j), w = dis[o] + 1;
				
				if(u){
					if(o & (1 << (u - 1))) ++w;
					st ^= 1 << (u - 1);
				}
				if(v){
					if(o & (1 << (v - 1))) ++w;
					st ^= 1 << (v - 1);
				}

				relax(st, w);
			}
	}
	assert(false);
}

int main(){

	scanf("%d", &n);
	For(i, 2, n){
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		++u, ++v;
		val[u] ^= w, val[v] ^= w;
	}
	For(i, 2, n) cnt[val[i]]++;

	int ans = 0;
	For(i, 1, 15) ans += cnt[i] / 2, cnt[i] &= 1;
	
	int st = 0;
	For(i, 1, 15) st |= cnt[i] << (i - 1);
	printf("%d\n", ans + SPFA(st));

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	map<int, int> mm;
	REP(i, N) {
		int A;
		scanf("%d", &A);
		++mm[A];
	}
	
	int ans = 0;
	for (auto it : mm) ans += it.second & 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
N = int(input())
s = str(input())
count = 0
score = []
for i in range(1,N):
    if s[i] == "E":
        count += 1
score.append(count)
for i in range(1,N):
    if s[i-1] == "W":
        count += 1
    if s[i] == "E":
        count -= 1
    score.append(count)
print(min(score))

Measured memory_bytes: 15520
N=int(input())
a,b,c,d,red,blue=[],[],[],[],[],[]
for i in range(N):
    ai,bi=list(map(int,input().split()))
    a.append(ai)
    b.append(bi)
for i in range(N):
    ci,di=list(map(int,input().split()))
    c.append(ci)
    d.append(di)
for i in range(N):
    red.append([a[i],b[i]])
    blue.append([c[i],d[i]])

cxy = []
for i in range(N):
    cxy.append(["r",red[i][0],red[i][1],0])
    cxy.append(["b",blue[i][0],blue[i][1],0])

cxy_sort = sorted(cxy, key=lambda x: x[1])

cnt=0
for i in range(N*2):
    counter = -1
    max=0
    for j in range(0,i):
        if cxy_sort[i][0] == "b" and cxy_sort[j][0] == "r" and cxy_sort[j][3] == 0 and cxy_sort[i][2] - cxy_sort[j][2] >0:
            if cxy_sort[j][2] >= max:
                max = cxy_sort[j][2]
                counter = j
    if counter != -1:
        cxy_sort[counter][3] = 1
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll n;
string s;
int main(){
    cin >> s;
    n = s.size();
    ll num = n*(n-1)/2;
    ll cnt[26] = {};
    for(ll i = 0; i < n; i++) cnt[s[i]-'a']++;
    for(ll i = 0; i < 26; i++){
        num -= cnt[i]*(cnt[i]-1)/2;
    }
    cout << num+1 << endl;
}

 

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

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

typedef long long ll;

using namespace std;

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

  int result = 0;

  while (H > 0) {
    result++;
    H -= A;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}



Measured memory_bytes: 11688
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long int
#define mp  std::make_pair
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << v << endl;

int main(int argc, const char * argv[]) {
	int K,N;
	cin >> N >> K;
	int h[N];
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
	}
	sort(h,h+N);
	int ret = 1000000000;
	for (int i = 0; i <= N-K; ++i) {
		int diff = h[i+K-1]-h[i];
		if(diff< ret) ret=diff;
	}
	cout <<ret<< endl;
}


Measured memory_bytes: 640
#include <cstdio>

template<int N, typename T, T M>
struct factorial_mod
{
	T mod[N + 1];
	T inv_mod[N + 1];

	constexpr factorial_mod() : mod(), inv_mod()
	{
		mod[0] = 1;
		for (int i = 0; i < N; ++i)
		{
			mod[i + 1] = (mod[i] * (i + 1)) % M;
		}
		inv_mod[N] = power(mod[N], M - 2);
		for (int i = N - 1; i >= 0; --i)
		{
			inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
		}
	}

	constexpr T power(T a, T b)
	{
		T r = 1;
		while (b > 0)
		{
			if ((b & 1) != 0) r = (r * a) % M;
			a = (a * a) % M;
			b >>= 1;
		}
		return r;
	}

	constexpr T comb(T n, T r)
	{
		return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
	}
};


factorial_mod<200000, long long, 1000000007> facmod;

int main()
{
	long long h, w, a, b;
	scanf("%lld %lld %lld %lld", &h, &w, &a, &b);
	long long ans = 0;

	long long c1 = h - 1 - a + b;
	long long c2 = w - 1 - b + a;
	while (a < h && b < w)
	{
		ans = (ans + ((facmod.comb(c1, b) * facmod.comb(c2, a)) % 1000000007)) % 1000000007;
		++a; ++b;
	}
	printf("%lld\n", ans);
}

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

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

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

    int res = 0;
    int max = 0;
    for (int i = 0; i < N; i++)
    {
        if (i == 0)
        {
            res++;
            max = H.at(i);
        }
        else
        {
            if (max < H.at(i))
            {
                max = H.at(i);
            }
            if (max <= H.at(i) && H.at(i - 1) <= H.at(i))
            {
                res++;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int i;
  map<long,long>m;
  for(i=0;i<n;i++){
    cin>>a[i];
    m[a[i]]++;
  }
  long all = 0;
  for(i=1;i<=n;i++){
    all += m[i]*(m[i]-1)/2;
  }
  for(i=0;i<n;i++){
    cout<<all-(m[a[i]]-1)<<endl;
  }

}


Measured memory_bytes: 15872
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int[] b = new int[a];
		int[] c = new int[a];
		// 文字列の入力
		
		int[] d = new int[a];
		int[] e = new int[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
			e[i] = sc.nextInt();
			b[i] = d[i] + e[i];
			c[i] = d[i] - e[i];
		}
		int intMax = b[0]; 
		for(int i = 1; i < a; i++) {// 要素0番目のは代入済みのため1番目から開始する
          
			if(intMax < b[i]) {
				intMax = b[i];
			}
		}
		int intMin = b[0]; 
		for(int i = 1; i < a; i++) {// 要素0番目のは代入済みのため1番目から開始する

			if(intMin > b[i]) {
				intMin = b[i];
			}
		}
		int f = intMax - intMin; 
		int intMaxc = c[0]; 
		for(int i = 1; i < a; i++) {// 要素0番目のは代入済みのため1番目から開始する

			if(intMaxc < c[i]) {
				intMaxc = c[i];
			}
		}
		int intMinc = c[0]; 
		for(int i = 1; i < a; i++) {// 要素0番目のは代入済みのため1番目から開始する

			if(intMinc > c[i]) {
				intMinc = c[i];
			}
		}
		int g = intMaxc - intMinc;
		System.out.println(Math.max(f, g));
		
		
	}
}

Measured memory_bytes: 62424
// 2012/01/06 Tazoe

#include <iostream>
using namespace std;

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

	int S[100001];
	S[1] = 0;
	for(int i=2; i<=n; i++){
		int s;
		cin >> s;

		S[i] = (S[i-1]+s)%100000;
	}

	int sum = 0;
	int x = 1;
	for(int i=0; i<m; i++){
		int a;
		cin >> a;

		if(a>0){
			sum += (S[x+a]+100000-S[x]);
			x += a;
		}
		else{
			a = -a;
			x -= a;
			sum += (S[x+a]+100000-S[x]);
		}

		sum %= 100000;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<bitset>

using namespace std;



int main(){
  string s; cin>>s;
  string ss=s;
  int n = s.length();
  reverse(s.begin(),s.end());
  int ans=0;
  for(int i=0; i<n/2;i++)
  if(s[i]!=ss[i]) ans++;
  cout<<ans<<endl;
}


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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;

    /*
    for (int i = 1; i < N-1; i++){
	string sub1 = s.substr(0, i);
	string sub2 = s.substr(i, N-i);
	set<char> sx;
	set<char> sy;
	for (int j = 0; j < sub1.size(); j++){
	    sx.insert(sub1[i]);
	}
    }
    */


    map<char, int> m;
    for (int i = 0; i < s.size(); i++){
	m[s[i]]++;
    }

    int res = 0;
    for (int i = 1; i < s.size(); i++){
	map<char, int> x;
	string sub = s.substr(0, i);
	for (int j = 0; j < sub.size(); j++){
	    x[sub[j]]++;
	}

	int cnt = 0;
	for (auto itr = x.begin(); itr != x.end(); itr++){
	    int y = itr->second;
	    int z = m[itr->first];
	    if (z-y != 0){
		cnt++;
	    }
	}

	res = max(res, cnt);
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

template<typename F> double bsearch(double ok, double ng, ll loop, F f) {
	REP(i, loop) {
		double middle = (ok + ng) / 2;
		(f(middle) ? ok : ng) = middle;
	}
	return ok;
}


int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vvl path(n);
	REP(i, n - 1) {
		ll u, v; cin >> u >> v;
		u--,v--;
		path[u].push_back(v);
		path[v].push_back(u);
	}
	vl leafs;
	REP(i, n) if (path[i].size() == 1) leafs.push_back(i);

	vl deg(n); REP(i, n) deg[i] = path[i].size();
	vb used(n, 0);
	while (!leafs.empty()) {
		ll id = leafs.back();
		leafs.pop_back();
		if (used[id]) continue;

		// 葉の親を探す
		ll next = [&] {
			for (auto node : path[id]) if (!used[node]) return node;
			assert(false);
		}();

		// 葉が孤独頂点だった場合
		used[id] = 1;
		used[next] = 1;
		for (auto node : path[next]) if(!used[node]) {
			deg[node]--;
			if (deg[node] == 1) leafs.push_back(node);
			if (deg[node] == 0) {
				cout << "First" << endl;
				return 0;
			}
		}
	}
	cout << "Second" << endl;


	return 0;
}


Measured memory_bytes: 7676
n = int(input())
a, b = map(int, input().split())
ls = list(map(int, input().split()))

cnt1 = 0
cnt2 = 0
cnt3 = 0

for i in range(n):
    if ls[i] <= a:
        cnt1 += 1
    elif a + 1 <= ls[i] <= b:
        cnt2 += 1
    elif ls[i] >= b + 1:
        cnt3 += 1

print(min(cnt1, cnt2, cnt3))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
#define TIME ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
    const ll N = 1e5 + 7;///

int main(){
    TIME
    ld a , b , c;
    cin >> a >> b >> c;
    if(2 * sqrt(a) * sqrt(b) + a + b < c){
        cout << "Yes";
    }
    else
        cout << "No";
}
///...


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N;cin>>N;
  for(int a=1;a<=3500;a++)for(int b=a;b<=3500;b++)if(4*a*b>N*(a+b)&&N*a*b%(4*a*b-N*a-N*b)==0){
    cout<<a<<" "<<b<<" "<<N*a*b/(4*a*b-N*a-N*b)<<endl;
    return 0;
  }
  return 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define PB push_back
#define MP make_pair
#define SZ size()
#define Fr first
#define Sc second
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%I64d", &a)
#define sd(a) scanf("%lf", &a)
#define ss(a) scanf("%s", a)
#define debug(x) cout << #x << ": " << x << endl
#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)

typedef long long Long;
typedef pair <int, int> Pii;
///<-------------------------------------------------END OF TEMPLATE-------------------------------------------------->

int main() {
   int N;
   deque <int> deq;
   si(N);
   for(int i = 0; i < N; i++) {
      int a;
      si(a);
      if(i & 1) deq.PB(a);
      else deq.push_front(a);
   }
   bool sp = false;
   while(!deq.empty()) {
      int x;
      if(N & 1) {
         x = deq.front();
         deq.pop_front();
      } else {
         x = deq.back();
         deq.pop_back();
      }
      if(sp) printf(" ");
      printf("%d", x);
      sp = true;
   }
   puts("");
}


Measured memory_bytes: 2944
from pprint import pprint
def main():
    D,G = map(int, input().split())
    p,c = [0]*D,[0]*D
    for i in range(D):
        p[i],c[i] = map(int, input().split())
    qnum = sum(p)
    # dp[i][j] := i問目まででj個解いたときの最大得点
    dp = [[0]*(qnum+1) for _ in range(D+1)]
    dp[0] = [0]*(qnum+1)
    ans = qnum
    for i in range(1,D+1):
        # i問目までを見る
        for j in range(qnum+1):
            # 全部でj回解く
            for k in range(min(p[i-1]+1, j+1)):
                # i問目をk個解く
                if k<p[i-1]:
                    dp[i][j] = max(dp[i][j], dp[i-1][j-k]+100*i*k)
                else:
                    dp[i][j] = max(dp[i][j], dp[i-1][j-k]+100*i*k+c[i-1])
                if dp[i][j]>=G:
                    ans = min(ans, j)
    pprint(ans)

main()


Measured memory_bytes: 4084
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll L, R; cin >> L >> R;
    const ll mod = 2019;
    if(R-L > mod){
        cout << 0 << endl;
        return 0;
    }
    ll ans = LINF;
    FOR(i, L, R) FOR(j, i+1, R+1){
        ll t =i*j%mod;
        ans = min(t, ans);
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace D___Gathering_Children
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var result = new int[S.Length];
            var countR = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'R') countR++;
                if (S[i] == 'L')
                {
                    result[i] += countR / 2;
                    result[i - 1] += countR / 2;
                    if ((countR % 2) == 1) result[i - 1] += 1;
                    countR = 0;
                }
            }
            var countL = 0;
            for (int i = S.Length - 1; i >= 0; i--)
            {
                if (S[i] == 'L') countL++;
                if (S[i] == 'R')
                {
                    result[i] += countL / 2;
                    result[i + 1] += countL / 2;
                    if ((countL % 2) == 1) result[i + 1] += 1;
                    countL = 0;
                }
            }
            Console.WriteLine(string.Join(" ", result));

        }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string S;
int ans;

int main()
{
	in >> S;
	ans = S.length();
	rep(i, S.length() - 1)
	{
		if (S[i] != S[i + 1]) ans = std::min(ans, std::max<int>(i + 1, S.length() - (i + 1)));
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef long long int int64;
typedef unsigned long long int uint64;
typedef float float32;
typedef double float64;
typedef long double float128;


int main(){
    int A[3];
    REP(i,3){
        cin >> A[i];
    }
    int K;
    cin >> K;
    sort(A,A+3);
    cout << A[0]+A[1]+A[2]*pow(2,K);
}

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

bool Check(int n) {
	string s = to_string(n), sarch = "357";

	bool ret = true;
	for (auto c : sarch) {
		if (count(s.begin(), s.end(), c) == 0)ret = false;
	}
	return ret;
}

vector<int> Number753;
void dfs(int n) {
	if (Check(n))Number753.push_back(n);

	if (n <= 100000000) {
		dfs(n * 10 + 3);
		dfs(n * 10 + 5);
		dfs(n * 10 + 7);
	}
}

int main() {
	int N; cin >> N;
	dfs(0);

	int ans = 0;
	for (auto n : Number753) {
		if (n <= N)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define INF 123456789012345678

int main()
{
  int n,m;cin>>n>>m;
  vector<long long> a(m);
  vector<long long> b(m);
  vector<long long> c(m);
  int i;
  for(i=0;i<m;i++)cin>>a.at(i)>>b.at(i)>>c.at(i);
  vector<vector<long long>> edge(n,vector<long long>(n,INF));
  for(i=0;i<m;i++)
  {
    a.at(i)--;
    b.at(i)--;
    c.at(i)*=(-1);
    edge.at(a.at(i)).at(b.at(i))=c.at(i);
  }
  for(i=0;i<n;i++)edge.at(i).at(i)=0;
  vector<long long> d(n,INF);
  d.at(0)=0;
  int count=0;
  while(true)
  {
    for(i=0;i<m;i++)
    {
      if(d.at(a.at(i))!=INF&&d.at(b.at(i))>d.at(a.at(i))+edge.at(a.at(i)).at(b.at(i)))
      {
        d.at(b.at(i))=d.at(a.at(i))+edge.at(a.at(i)).at(b.at(i));
      }
    }
    count++;
    if(count==n-1)break;
  }
  vector<bool> negative(n,false);
  while(true)
  {
    for(i=0;i<m;i++)
    {
      if(d.at(a.at(i))!=INF&&d.at(b.at(i))>d.at(a.at(i))+edge.at(a.at(i)).at(b.at(i)))
      {
        d.at(b.at(i))=d.at(a.at(i))+edge.at(a.at(i)).at(b.at(i));
        negative.at(a.at(i))=true;
        negative.at(b.at(i))=true;
      }
    }
    count++;
    if(count==n)break;
  }
  if(negative.at(n-1))cout<<"inf"<<endl;
  else cout<<-d.at(n-1)<<endl;
}


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

string solve() {
    string S;
    cin >> S;
    bool ok = false;
    for ( int i = 0; i < 26; i++ ) {
        if ( S[i] != 'z' - i ) {
            ok = true;
            break;
        }
    }
    if ( !ok ) return "-1";
    set<char> cs;
    for ( int i = 0; i < 26; i++ ) {
        cs.insert('a'+i);
    }
    for ( int i = 0; i < S.size()-1; i++ ) {
        cs.erase(S[i]);
    }
    string ans(S);
    if ( cs.size() > 1 ) {
        char c = *S.rbegin();
        cs.erase(c);
        ans.push_back(*cs.begin());
    } else {
        for(;;) {
            char c = *ans.rbegin();
            cs.insert(c);
            ans.pop_back();
            auto p = next(cs.find(c));
            if ( p != cs.end() ) {
                ans.push_back(*p);
                break;
            }
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
use proconio::{input,fastout};
use proconio::marker::Usize1;

#[fastout]
fn main() {
  input!{n: usize, k: usize, a: [Usize1;n]}; // 64bitで耐えてる
  let mut path: Vec<usize> = Vec::new();
  // path内の値(x)からインデックス(index_of(path[x]))を得るためのVec
  // Someなら訪問済みということ
  let mut path_rev: Vec<Option<usize>> = vec![None;n];
  let mut i = 0;
  loop {
    path.push(i);
    path_rev[i] = Some(path.len() - 1);
    if let Some(j) = path_rev[a[i]] {
      let (path_to_cycle, cycle) = path.split_at(j);

      println!("{}", if k < path_to_cycle.len() {
        path_to_cycle[k] + 1
      } else {
		cycle[(k - path_to_cycle.len()) % cycle.len()] + 1
	  });
      break;
    } else {
      i = a[i];
    }
  }
}

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

int main(){
    int n, m;
    double a[100];
    cin >> n >> m;
    int cnt = 0;
    double total = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
	total += a[i];
    }
    
    for(int i = 0; i< n; i++){
        if(a[i] < (total*(1/(4*(double)m)))) cnt++;
    }
    
    if(n-m-cnt >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}   


Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;

long long memo[10][101][1001];

long long dp(int now, int x, int sum)
{
	if (sum == 0 && now == 0)return 1;
	if (now < 0 || x < 0 || sum < 0)return 0;
	if (memo[now][x][sum] != -1)return memo[now][x][sum];
	long long ans = 0;
	ans = dp(now - 1, x - 1, sum - x) + dp(now, x - 1, sum);
	return memo[now][x][sum] = ans;
}



int main()
{
	memset(memo, -1, sizeof memo);
	int n, s;
	while (cin >> n >> s&&n)
		cout << dp(n, 100, s) << endl;
}

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

int main() {
	int S, h, m, c;
	cin >> S;
	h = S / 3600;
	m = (S % 3600) / 60;
	c = (S % 3600) % 60;
	cout << h << ":" << m << ":" << c << endl;
	return 0;
}

Measured memory_bytes: 1164
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
using System.IO;

namespace ConsoleApp2
{
    class Program {
        static decimal C(int a,int b) {
            decimal res = 1;
            for (int i = 0; i < b; i++) {
                res *= (a - i);
                res /= (i + 1);
            }
            return res;
        }
        static void Main(string[] Args) {
            Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));

            var l = new List<string>(ReadLine().Split(' ')).Select(int.Parse).ToList();
            int N = l[0];
            int A = l[1];
            int B = l[2];

            var Value = new List<string>(ReadLine().Split(' ')).Select(long.Parse).GroupBy(i => i).OrderBy(x => -x.Key).ToList();

            /*
            foreach (var e in Value) {
                WriteLine(e.Key + ":" + e.Count());
            }
            */            

            decimal res = 0;
            decimal ave = 0; /* 合計の意味もある */

            if (A <= Value[0].Count()) {
                for (int i = A; i <= B; i++) {
                    //WriteLine(String.Format("{0}C{1} = {2}", A, Value[0].Count(), C(Value[0].Count(), i)));
                    res += C(Value[0].Count(), i);
                }
                ave = Value[0].Key;
            } else {
                int i;
                int A_ = A;
                for (i = 0; A >= Value[i].Count(); i++) {
                    A -= Value[i].Count(); /* 選んだ */
                    ave += Value[i].Key * Value[i].Count();
                }
                res = C(Value[i].Count(), A);
                ave += Value[i].Key * A;
                ave /= A_;
            }
            WriteLine(ave);
            WriteLine(res);

            ReadLine();
        }
    }
}


Measured memory_bytes: 13536
import sys
input = sys.stdin.readline

def main():
    N, K = input().split()
    N = int(N)
    K = int(K)
    monster = list(map(int, input().split()))
    monster = sorted(monster, reverse=True)
    print(sum(monster[K:]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 26740
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	ll n;
	cin >> n;
	vector<pair<ll, ll>> v;
	map<pair<ll, ll>, ll> m;
	for (ll i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		v.push_back(make_pair(x, y));
	}
	for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			ll x = v[i].first - v[j].first;
			ll y = v[i].second - v[j].second;
			m[make_pair(x, y)]++;
			m[make_pair(-x, -y)]++;
		}
	}
	ll maxm = 0;
	for (auto itr = m.begin(); itr != m.end(); itr++) {
		if (maxm < itr->second) {
			maxm = itr->second;
		}
	}
	cout << n - maxm << endl;
}


Measured memory_bytes: 3720
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	long long a,b,x;
	cin>>a>>b>>x;
	long long s=0;

	if (a==b){
		if (a%x==0){
			cout<<1<<endl;
		}else{
			cout<<0<<endl;
		}
		return 0;
	}
	if (a==0){
		s=1;
		a=1;
	}
	if (x>b){
		cout<<s<<endl;
		return 0;
	}
	if (x>a){
		a=x;
	}else{
		if (a%x!=0){
			a=(a/x+1)*x;
		}
	}
	if (b%x!=0){
		b=b/x*x;
	}
	s+=(b-a)/x+1;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x;
    cin >> x;

    int L = 100, R = 105;
    int mn = (x + R - 1) / R;
    int mx = x / L;

    bool res = false;
    for (int n = mn; n <= mx; ++n) {
        int rem = x - n * L;
        if (rem >= 0 && rem <= 5 * n) {
            res = true;
        }
    }

    if (res) {
        cout << 1 << '\n';
    } else {
        cout << 0 << '\n';
    }

    return 0;
}

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

using namespace std;

const int maxn = 1e5 + 5;
const int INF = 1e9 + 9;

struct SegmentTree {
      int minval, minpos;
      SegmentTree(int minval = INF, int minpos = INF)
            : minval(minval), minpos(minpos) {}

      void assignLeaf(int num, int pos) {
            minval = num;
            minpos = pos;
      }
      void marge(const SegmentTree lchild, const SegmentTree rchild) {
            if (lchild.minval <= rchild.minval) {
                  minval = lchild.minval;
                  minpos = lchild.minpos;
            }
            else {
                  minval = rchild.minval;
                  minpos = rchild.minpos;
            }
      }
} Tree[maxn * 4];

void update(int node, int a, int b, int pos, int num, int minpos) {
      if (a > pos or b < pos) {
            return;
      }
      if (a >= pos and b <= pos) {
            Tree[node].assignLeaf(num, minpos);
            return;
      }
      int lchild = node * 2;
      int rchild = lchild + 1;
      int mid = (a + b) / 2;
      update(lchild, a, mid, pos, num, minpos);
      update(rchild, mid + 1, b, pos, num, minpos);
      Tree[node].marge(Tree[lchild], Tree[rchild]);
}

SegmentTree query(int node, int a, int b, int i, int j) {
      if (a > j or b < i) {
            return SegmentTree();
      }
      if (a >= i and b <= j) {
            return Tree[node];
      }
      int lchild = node * 2;
      int rchild = lchild + 1;
      int mid = (a + b) / 2;
      SegmentTree p = query(lchild, a, mid, i, j);
      SegmentTree q = query(rchild, mid + 1, b, i, j);
      SegmentTree res;
      res.marge(p, q);
      return res;
}

void Task() {
      int n, m;
      cin >> n >> m;
      string s;
      cin >> s;
      vector <int> dp(n + 1, -1);
      vector <int> par(n + 1, 0);
      update(1, 0, n, 0, 0, 0);
      dp[0] = 0;
      par[0] = 0;
      for (int i = 1; i <= n; i++) {
            if (s[i] == '1') {
                  continue;
            }
            int l = max(0, i - m);
            int r = i;
            SegmentTree seg = query(1, 0, n, l, r);
            if (seg.minpos == INF) {
                  break;
            }
            dp[i] = seg.minval + 1;
            par[i] = seg.minpos;
            update(1, 0, n, i, dp[i], i);
      }
      if (dp[n] == -1) {
            cout << -1 << endl;
            return;
      }
      cerr << dp[n] << endl;
      vector <int> path;
      int node = n;
      do {
            path.push_back(node);
            node = par[node];
      } while (node != 0);
      reverse(path.begin(), path.end());
      int pre = 0;
      for (int x : path) {
            cout << x - pre << " ";
            pre = x;
      }
}

signed main() {
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr); cout.tie(nullptr);

      if (fopen("in.txt", "r")) {
            freopen("in.txt", "r", stdin);
      }

      int tc = 1;
      while (tc--) {
            Task();
      }
}


Measured memory_bytes: 7868
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

int main(){
    long int n,h;
    cin >> n >> h;
    long int amax = -1,b[100000] = {};

    for(long int i = 0; i < n; ++i){
        long int a;
        cin >> a >> b[i];
        if(amax < a) amax = a;
    }

    sort(b,b+n,greater<int>());
    long int i = 0;

    while(i < n && h > 0){
        if(amax < b[i]){
            h -= b[i];
        }else{
            break;
        }

        ++i;
    }

    if(h > 0)i += ceil(h / (double)amax);

    cout << i << endl;

}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, K;
    cin >> N >> K;
    const auto& modpow = [](unsigned long a, unsigned long n, unsigned long b = 1) -> unsigned long {
        unsigned long r{b % MOD};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    const auto& totient = [](unsigned long n) -> unsigned long {
        unsigned long v{n}, k{n};
        for(unsigned long j{2}; j * j <= k; ++j)if(k % j == 0){
            v = v / j * (j - 1);
            while(k % j == 0)k /= j;
        }
        if(k > 1)v = v / k * (k - 1);
        return v;
    };
    unsigned long ans{0};
    for(unsigned long i{1}; i <= K; ++i)ans += modpow(K / i, N, totient(i));
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 3636