akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int n;
  while(cin>>n && n){
    string stc[100000];
    cin.ignore();
    REP(i, n) getline(cin, stc[i]);
    char c; cin>>c;
    map<string, int> cnt;
    REP(i, n){
      stringstream ss(stc[i]);
      string word;
      while(ss>>word){
        if(word[0] == c) cnt[word] ++;
      }
    }
    vector<pair<int, string> > v;
    FORIT(it, cnt) v.push_back(make_pair(it->second * -1, it->first));
    sort(v.begin(), v.end());
    REP(i, min(5, (int)v.size())){
      if(i != 0) cout<<" ";
      cout<<v[i].second;
    }
    if(v.empty()) cout<<"NA";
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 1344
import math 

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

    H.sort(reverse=True)
    H = H[K:]

    count = 0
    for h in H:
        count += h
    
    print(count)

if __name__ == "__main__":
    main()


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

constexpr int MAX = 3030;

int main() {
    string s, t;
    cin >> s >> t;
    const int n = s.length();
    const int m = t.length();
    
    int dp[MAX][MAX] = {};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            if (s[i] == t[j]) {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            }
        }
    }
    
    string ans = "";
    int i = n, j = m;
    while (i > 0 and j > 0) {
        if (dp[i-1][j] == dp[i][j]) {
            i--;
        } else if (dp[i][j-1] == dp[i][j]) {
            j--;
        } else {
            i--;
            j--;
            ans += s[i];
        }
    }
    
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 36096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;


int main() {

int N,M; cin >> N >> M ;

vector<int> H(N);
rep(i,N) cin>>H[i];

vector<vector<int>> R(N);

rep(i,M){
  int A,B; cin>>A>>B; A--; B--;
  R[A].push_back(B);
  R[B].push_back(A);  
}
//input

ll ans=0;

rep(i,N){
  bool can=true;
  rep(j,R[i].size()){
    if(H[i]<=H[R[i][j]]) can=false;
  }

  if(can) ans++;

}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 8804
from collections import Counter

def max_earn(blue_cards, red_cards):
    blue_dict = Counter(blue_cards)
    red_dict = Counter(red_cards)
    maximum = 0
    for (k, v) in blue_dict.items():
        if k in red_dict:
            maximum = max(maximum, v - red_dict[k])
        else:
            maximum = max(maximum, v)
    return maximum


if __name__ == '__main__':
    blue_cards = [raw_input() for _ in xrange(int(raw_input()))]
    red_cards = [raw_input() for _ in xrange(int(raw_input()))]
    print max_earn(blue_cards, red_cards)

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

public static partial class Program
{
    public static void Main()
    {
        var s = CRL();
        var t = CRL();

        var cnts = new int[alphabet.Length];
        var cntt = new int[alphabet.Length];
        for (int i = 0; i < s.Length; i++)
        {
            cnts[s[i] - 'a']++;
            cntt[t[i] - 'a']++;
        }

        var lim = cnts.Max();
        for (int i = 0; i < lim; i++)
        {
            if (cnts.Count(x => x == i) != cntt.Count(x => x == i))
            {
                CWL("No");
                return;
            }
        }

        CWL("Yes");
    }
}

public static partial class Program
{
    //テンプレここから
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static string RL() => ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static void WL(object obj) => WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] {0, -1, 0, 1};
    public static long[] dy = new long[] {-1, 0, 1, 0};
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    //テンプレここまで
}

Measured memory_bytes: 16736
#include <stdio.h>

#define inf 10000
#define NIL -2
#define WHITE -3
#define BLACK -4
#define MAX 2000

int d[MAX], pi[MAX], color[MAX],w[100][100];

void prim(int n){
  int u,v,i,mincost,cost=0;
  for( u = 0; u < n; u++){
    d[u] = inf;
    pi[u] = NIL;
    color[u] = WHITE;
  }
  d[0] = 0;

  while(1){
    mincost = inf;
    for(i = 0; i < n; i++){
      if((color[i] != BLACK) && (d[i] < mincost)){
	mincost = d[i];
	u = i;
	//	printf("%d %d\n",i+1,d[i]);
	
      }

      //      printf("%d %d\n",i+1,d[i]);
    }
     

    if(mincost == inf) break;

    color[u] = BLACK;

    for( v = 0; v < n; v++){
      if((color[v] != BLACK)&&(w[u][v] < d[v])){
	pi[v] = u;
	d[v] = w[u][v];
	//	printf("%d\n",d[v]);
      }
    }
  }

  for( i = 0; i < n; i++){
    cost = cost + d[i];
    //    printf("d[%d]:%d\n",i+1,d[i]);
  }

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

  
}

int main(){
  int n,u,v,i;

  scanf("%d",&n);
  for(u = 0; u < n; u++){
    for(v = 0; v < n; v++){
      scanf("%d",&w[u][v]);
      if(w[u][v] == -1){
	w[u][v] = inf;
      }
    }
  }
  prim(n);

 
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N;
	cin >> N;
	vector<int> a(N), b(N), c(N);
	for(int i = 0; i < N; i++) cin >> a[i];
	for(int i = 0; i < N; i++) cin >> b[i];
	for(int i = 0; i < N; i++) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	ll ans = 0;
	for(int i = 0; i < N; i++) {
		ll tmp = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		ll tmp2 = c.end() - lower_bound(c.begin(), c.end(), b[i] + 1);
		ans += tmp * tmp2;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4588
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const LL LINF=4557430888798830399;
const ld eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

inline int Read()
{
	int x=0,w=0;char ch=0;while(!isdigit(ch)){w|=ch=='-';ch=getchar();}while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
inline void Write(int x){if(x<0)putchar('-'),x=-x;if(x>9)Write(x/10);putchar(x%10+'0');}
inline LL powmod(LL a,LL b){LL res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res%MOD;}
inline LL gcdll(LL a,LL b){return b?gcdll(b,a%b):a;}

const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={1,0,-1,0,-1,-1,1,1};
/************************************************************BEGIN************************************************************/
const int maxn=200010;

string s,t;
int ans;

int main()
{
	cin>>s>>t;
	rep(i,SZ(s)) if(s[i]!=t[i]) ans++;
	cout<<ans;

	return 0;
}
/*************************************************************END**************************************************************/

Measured memory_bytes: 3896
#include<stdio.h>
#include<string.h>
int main()
{
	int n,x,y,z,c,i,j,k,qq,s;
	while(scanf("%d",&x)!=EOF){
		qq=0;
		scanf("%d%d",&y,&z);
		int a[y],b[y];
		memset(a,0,sizeof(a));
		for(k=0;k<y;k++){
			scanf("%d",&a[k]);
		}
		for(i=0;i<x;i++){
			s=0;
			memset(b,0,sizeof(b));
			for(j=0;j<y;j++){
				scanf("%d",&b[j]);
				s=s+b[j]*a[j];
			}
			if(s+z>0)qq++;
			
		}
		printf("%d\n",qq);
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main{
 public static void main(String args[]){
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  try{
   String str=null;
   while((str=br.readLine())!=null){
    StringTokenizer st=new StringTokenizer(str);
    int i=Integer.parseInt(st.nextToken());
    int j=Integer.parseInt(st.nextToken());
    System.out.println(String.valueOf(i+j).length());
   }
   br.close();
  }catch(Exception ex){
  System.exit(0);
  }
 }
}

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

int w, h;
bool state[51][51];

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

bool isRegion(int x, int y){
    return x >= 0 && x < w && y >= 0 && y < h;
}

void dfs(int x, int y){
    state[x][y] = 0;
    
    for(int i = 0; i < 8; i++){
        int nx = x + dx[i], ny = y + dy[i];
        if(isRegion(nx, ny) && state[nx][ny]){
            dfs(nx, ny);
        }
    }
}

int main(int argc, const char * argv[]) {
    while(1){
        cin >> w >> h;
        if(!w && !h) break;
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                cin >> state[x][y];
            }
        }
        
        int cnt = 0;
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                if(state[x][y]){
                    dfs(x, y);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
const int INF = 1e9;

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

	ll n;
	ll ans = 0;

	cin >> n;

	vector<ll> p(n);

	rep(i, n) cin >> p[i];

	ll val;
	rep2(i, 1, n-1) {
		if (p[i - 1] <= p[i] && p[i] <= p[i + 1] ||
			p[i + 1] <= p[i] && p[i] <= p[i - 1]) {
			if (p[i - 1] != p[i] && p[i] != p[i + 1]) {
				ans++;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(X: int, Y: int):
    return X + Y // 2


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    result = solve(X, Y)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5140
import math

def count(n, target):
    c = 0
    check_list = [i + 1 for i in range(n)] # [1, 2, 3]
    index = n
    for item in target: # [1, 3, 2]
        check_list.remove(item)
        c = c + len([i for i in check_list if i < item]) * math.factorial(index - 1)
        index = index - 1
    return c + 1


if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))

    n_list = [i + 1 for i in range(n)]

    p_count = count(n, p)
    q_count = count(n, q)

    print(abs(p_count - q_count))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
lli mat[101][101];
lli h,w;
lli dp[101][101][2];
lli rec(lli i,lli j,lli cc){
	if(i>=h || j>=w)return INT_MAX;
	if(i==h-1 && j==w-1){
		if(mat[i][j]==0 && cc==1)return 1;
		return 0;
	}
	if(dp[i][j][cc]!=-1)return dp[i][j][cc];
	lli c=0;
	if(mat[i][j]==0 && cc==1)c++;
	if(mat[i][j]==1) return dp[i][j][cc]=min(rec(i+1,j,1),rec(i,j+1,1));
	return  dp[i][j][cc]=(cc+ min(rec(i+1,j,0),rec(i,j+1,0)));
}



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //lli h,w;
    cin>>h>>w;
    loop(i,0,101)loop(j,0,101)loop(k,0,2)dp[i][j][k]=-1;
    for(lli i=0;i<h;i++){
    	string s;
    	cin>>s;
    	for(lli j=0;j<w;j++){
    		if(s[j]=='.')mat[i][j]=1;
		}
	}
	cout<<rec(0,0,1);
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 512
n, k = [ int(v) for v in input().split() ]
kmax, kmin = (n-1)*(n-2)//2, 0

if k > kmax:
    print(-1)
else:
    anslist = [ (i+1,j+1) for i in range(n) for j in range(n) if i < j ]
    m = len(anslist)
    print(m-k)
    for i in range(m-k):
        print(*anslist[i])


Measured memory_bytes: 43888
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		long[][] dp = new long[n][3];
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];
		
		for (int i = 1; i < n; i++) {
			dp[i][0] = a[i] + Math.max(dp[i - 1][1], dp[i - 1][2]);
			dp[i][1] = b[i] + Math.max(dp[i - 1][0], dp[i - 1][2]);
			dp[i][2] = c[i] + Math.max(dp[i - 1][0], dp[i - 1][1]);
		}
		
		long max = -1;
		for (int i = 0; i < 3; i++) {
			max = Math.max(max, dp[n - 1][i]);
		}
		
//		for (int i = 0; i < n; i++)
//			System.out.println(Arrays.toString(dp[i]));
		
		System.out.println(max);
 		
		sc.close();
	}
}



Measured memory_bytes: 51572
import fractions
N = int(input())
a = list(map(int,input().split()))
lcm = a[0]
for i in range(1,N):
	lcm = lcm*a[i]//fractions.gcd(lcm,a[i])

b = [0]*N

ans = 0
for i in range(N):
	ans += lcm//a[i]
print(int(ans%(10**9+7)))



Measured memory_bytes: 6200
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
int main()
{
	int x,y,z,m,k,l,i=0;
	while(cin>>x>>y>>z)
	{
		m=y+z;
		k=x/m;
		l=x%m;
		if(l<z)
			cout<<k-1<<endl;
		else
			cout<<k<<endl;
	}
}

Measured memory_bytes: 256
N, M = map(int,input().split())
A = sorted([int(i) for i in input().split()])
BC = [list(map(int,input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])[::-1]
ind = 0
for b, c in BC:
  for i in range(b):
    if A[ind] < c:
      A[ind] = c
      ind += 1
      if ind == N:
        print(sum(A))
        exit()
    else:
      break
print(sum(A))

Measured memory_bytes: 33604
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int i =0;
    int[] b = new int[32];
    if (N == 0) {
      System.out.print(0);
      return;
    }
    while (N != 0) {
      if (N % 2 != 0) {
        b[i] = 1;               
        N--;
      } else {
        b[i] = 0;
      }
      N /= -2;
      i++;
    } 
    i--;
    for (; i >=0; i--) {
      System.out.print(b[i]);
    }
  }
}

Measured memory_bytes: 35844
from collections import *
n,*a=map(int,open(0).read().split())
s=set(a)
c=Counter(a)
sm=0
for i in s:
  sm+=c[i]*(c[i]-1)//2
for i in a:
  print(sm-(c[i]*(c[i]-1)//2)+((c[i]-1)*(c[i]-2)//2))

Measured memory_bytes: 29720
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define print(x) (cout << x << endl)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

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

  int a, p;
  cin >> a >> p;

  cout << ( p + a * 3 ) / 2 << endl;
    
    
  
  
  // cout << "Case #" << C++ << ": " << cur_max << endl;  


}



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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;

    int index = (N % 2 == 1) ? 0 : 1;
    vector<pair<int, int>> ans;
    for(int i = N; i > 0; i--) {
        for(int j = 1; j <= i; j++) {
            if(j == i || j == index) continue;
            ans.emplace_back(i, j);
        }
        index++;
    }

    std::cout << ans.size() << "\n";
    for_each(ALL(ans), [](auto& p) {std::cout << p.first << " " << p.second << "\n";});

    return 0;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/abc110/tasks/abc110_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, m, x, y;

  cin >> n >> m >> x >> y;

  int xx = x, yy = y, t;

  REP(i, n)
  {
    cin >> t;
    xx = max(xx, t);
  }

  REP(i, m)
  {
    cin >> t;
    yy = min(yy, t);
  }

  string r = xx < yy ? "No War" : "War";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const double PI=3.14159265358979323846;
    double a,b,x;
    cin >> a >> b >> x;
    double s = x / a;
    //cerr << s << endl;
    double ans = 0;
    double la = 0;

    if (s >= b * a / 2) {
        double ub = 2 * s / a - b;
        //cerr << "ub:" <<ub << endl;
        s -= a * ub;
        b -= ub;
        la = a;
    } else {
        la = 2 * s / b;
    }
    //cerr<<la << endl;
    auto r = atan2(b,la);
    //cerr << r << endl;
    ans = r * (180.0 / PI); 

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;



	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		int Q = scanner.nextInt();

		long table[] = new long[N];

		for(int i = 0; i < N; i++){

			table[i] = scanner.nextLong();
		}

		StringBuilder ANS = new StringBuilder();

		for(int i = 0; i < Q; i++){

			long base_num = scanner.nextLong();
			Long ans = 0L;
			int left = 0;

			long tmp_sum = table[left];
			int right = left;

			while(true){
				while(tmp_sum <= base_num){
					ans += right-left+1;
					right++;
					if(right == N)break;
					tmp_sum += table[right];
				}

				if(right == N)break;

				while(tmp_sum > base_num){
					tmp_sum -= table[left];
					left++;
					if(left > right){
						break;
					}
				}

				if(left > right){
					while(left < N && table[left] > base_num){

						left++;
					}
					if(left == N)break;

					tmp_sum = table[left];
					right = left;
				}
			}
			ANS.append(Long.toString(ans)).append("\n");
		}
		System.out.print(ANS.toString());
	}
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 331700
// https://atcoder.jp/contests/abc111/tasks/abc111_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  string n;

  cin >> n;

  for (size_t i = 0; i < 3; i++)
  {
    if (n[i] == '1')
      n[i] = '9';
    else
      n[i] = '1';
  }

  cout << n << '\n';

  return 0;
}


Measured memory_bytes: 256
// Problem : A - Round One
// Contest : AtCoder Beginner Contest 148
// URL : https://atcoder.jp/contests/abc148/tasks/abc148_a
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;
  
  int n = 3;
  vector<int> a(n);

  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    
    a[t - 1]++;
  }
  
  for (int i = 0; i < n; ++i) {
    if (a[i] == 0) {
      cout << i + 1;
      
      return 0;
    }
  }
}


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

int main(){
  string b[3];
  string ans;

  for(;;){
    cin >> b[0];
    if(b[0] == "0")break;

    cin >> b[1] >> b[2];

    ans = "NA";
    for(int i=0;i<3;i++){
      if(b[0][i] == b[1][i] && b[1][i] == b[2][i]){
	if(b[0][i] == 'b')ans = "b";
	if(b[0][i] == 'w')ans = "w";
      }
      if(b[i][0] == b[i][1] && b[i][1] == b[i][2]){
	if(b[i][0] == 'b')ans = "b";
	if(b[i][0] == 'w')ans = "w";
      }
    }
    if(b[0][0] == b[1][1] && b[1][1] == b[2][2]){
      if(b[1][1] == 'b')ans = "b";
      if(b[1][1] == 'w')ans = "w";
    }
    if(b[0][2] == b[1][1] && b[1][1] == b[2][0]){
      if(b[1][1] == 'b')ans = "b";
      if(b[1][1] == 'w')ans = "w";
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		long[] ws = new long[N+1];
		long[] vs = new long[N+1];
		long[] dp = new long[W+1];
		int INF = Integer.MAX_VALUE;
		long max = 0;

		ws[0] = 0;
		vs[0] = 0;
		for (int i = 1; i <= N; ++i) {
			ws[i] = sc.nextLong();
			vs[i] = sc.nextLong();
		}
		Arrays.fill(dp, INF);
		dp[0] = 0;

		for (int i = 1; i <= N; ++i) {
			for (int j = W; j >= 0; --j) {
				if (dp[j] != INF && j + ws[i] <= W) {
					if (dp[j] + vs[i] > dp[(int)(j+ws[i])] || dp[(int)(j+ws[i])] == INF) {
						dp[(int)(j+ws[i])] = dp[j] + vs[i];
						if (dp[(int)(j+ws[i])] > max)max = dp[(int)(j+ws[i])];
					}
				}
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22736
// Aizu Vol0 0053: Sum of Prime Numbers
// 2017.7.30

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);

#define MAX  104729  // 10000th prime
#define SQRT 323     // sqrt(MAX)

char table[MAX + 5];
int sum[MAX];

int main()
{
	int i, j, n;
	char buf[100];

	for (i = 2; i <= SQRT; i++) {
		if (!table[i]) {
			for (j = i + i; j <= MAX; j = j + i) table[j] = 1;
		}
	}
	j = 2, sum[1] = 2;
	for (i = 3; i <= MAX; i += 2) {
		if (!table[i]) sum[j] = sum[j - 1] + i, j++;
	}

	while (1) {
		gets(buf);
		n = atoi(buf);
		if (n == 0) break;
		printf("%d\n", sum[n]);
	}
	return 0;
}

Measured memory_bytes: 660
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    while keta < 10**7:
        if mod==0:
            print(keta)
            break
        keta += 1
        mod = (mod*10 + 7)%k
    else:
        print(-1)


if __name__=='__main__':
    main()

Measured memory_bytes: 62744
def S(dice):
    a_0=dice[0]
    a_1=dice[1]
    a_4=dice[4]
    a_5=dice[5]
    dice[1]=a_0
    dice[5]=a_1
    dice[4]=a_5
    dice[0]=a_4

def N(dice):
    a_0=dice[0]
    a_1=dice[1]
    a_4=dice[4]
    a_5=dice[5]
    dice[1]=a_5
    dice[5]=a_4
    dice[4]=a_0
    dice[0]=a_1

def W(dice):
    a_0=dice[0]
    a_3=dice[3]
    a_5=dice[5]
    a_2=dice[2]
    dice[0]=a_2
    dice[3]=a_0
    dice[5]=a_3
    dice[2]=a_5

def E(dice):
    a_0=dice[0]
    a_3=dice[3]
    a_5=dice[5]
    a_2=dice[2]
    dice[0]=a_3
    dice[3]=a_5
    dice[5]=a_2
    dice[2]=a_0

dice=list(map(int,input().split()))
command=str(input())

for i in command:
    if i=='S':
        S(dice)
    elif i=='N':
        N(dice)
    elif i=='W':
        W(dice)
    elif i=='E':
        E(dice)
print(dice[0])


Measured memory_bytes: 5608
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n;
double x[2005], y[2005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
main() {
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf %lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.16lf ", sqrt(d));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define be(x) (x).begin(),(x).end()
bool is_prime(ll n){
    if(n==2)return true;
    else if(n<2||n%2==0)return false;
    ll i=3;
    while(i<=sqrt(n)){
        if(n%i==0)return false;
        i+=2;
    }
    return true;
}
void solve(){
    int n;
    cin>>n;
    ll i=n;
    while(1){
        if(is_prime(i)){
            cout<<i<<endl;
            break;
        }
    i++;
    }
}

int main(){
    cout<<std::fixed<<std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>

typedef long long ll;
using namespace std;

int main(){
  ll n,k,i,j,mbit=0;
  cin >> n >> k;
  ll a[n],x,bit[45]={};
  for(i=0;i<n;i++){
    cin >> x;
    a[i] = x;
    ll cnt = 0;
    while(x){
      if(x%2==1)bit[cnt]++;
      x>>=1;
      cnt++;
    }
    mbit=max(mbit,cnt);
  }
  ll t = k,ch=0ll;
  while(t){
    ch++;
    t>>=1;
  }
  ll b = max(ch-1,mbit-1);
  ll ret = 0ll;
  while(b>=0){
    ll p = 1ll<<b;
    //cout << p << endl;
    if(p<=k && 2*bit[b]<n){
      ret += (n-bit[b])*p;
      k-=p;
    }else{
      ret += bit[b]*p;
    }
    b--;
  }
  //cout << mbit << endl;
  cout << ret << endl;
  //for(i=0;i<mbit;i++)cout << bit[i] << endl;
  return 0;
}


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

//#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int MB = 31;

void solve() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) cout << 'x';
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for (int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
template <typename T> bool chkmax(T &a, const T &b) { return a < b ? a = b, true : false; }
template <typename T> bool chkmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template <typename T> T sgn(const T&a) { return (a > T(0)) - (a < T(0)); }
typedef long long LL;
typedef long double LD;
const int BUF_SIZE = (int)2e7 + 10;
struct fastIO {
    char buf[BUF_SIZE], buf1[BUF_SIZE];
    int cur, cur1; FILE *in, *out;
    fastIO() { cur = BUF_SIZE, in = stdin, out = stdout; cur1 = 0; __builtin_prefetch(buf);__builtin_prefetch(buf1);}
    inline char getchar() { if(cur == BUF_SIZE) fread(buf, BUF_SIZE, 1, in), cur = 0; return *(buf + (cur++)); }
    inline void putchar(char ch) { *(buf1 + (cur1++)) = ch; if (cur1 == BUF_SIZE) fwrite(buf1, BUF_SIZE, 1, out), cur1 = 0; }
    inline int flush() { if (cur1 > 0) fwrite(buf1, cur1, 1, out); return cur1 = 0; }
}IO;
#define getchar IO.getchar
LL read() {
	LL x = 0, flag = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	return x * flag;
}
void write(LL x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) write(x / 10);
	putchar(x % 10 + '0');
} 

const int Maxn = 1e5 + 9;
struct edge {
	int to, nxt;
}g[Maxn << 1];
int n, head[Maxn];
void add(int u, int v) { 
	static int e = 0;
	g[++e] = (edge){v, head[u]}, head[u] = e; 
}

int ans = 0;
static int bit[Maxn];

void dfs(int u, int pa) {
	int same = 0;
	for (int i = head[u]; ~i; i = g[i].nxt) {
		int v = g[i].to;
		if (v != pa) {
			dfs(v, u);
			same |= bit[u] & bit[v];
			bit[u] |= bit[v];
		}
	}
	int mx = same ? 32 - __builtin_clz(same) : 0;
	while (bit[u] & (1 << mx)) ++mx;
	bit[u] |= (1 << mx);
	chkmax(ans, mx), bit[u] = bit[u] >> mx << mx;
}

int main() {

	clar(head, -1);
	n = read();
	rep (i, 1, n - 1) {
		int u = read(), v = read();
		add(u, v), add(v, u);
	}
	dfs(1, 0);
	cout << ans << endl;

#ifdef Qrsikno
	debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 9216
#include<cstdio>
const int MAXN = 500;
int A[MAXN + 5][MAXN + 5];
void solve(int l, int r, int k) {
	if( l == r ) return ;
	int mid = (l + r) >> 1;
	solve(l, mid, k + 1), solve(mid + 1, r, k + 1);
	for(int i=l;i<=mid;i++)
		for(int j=mid+1;j<=r;j++)
			A[i][j] = A[j][i] = k;
}
int main() {
	int N; scanf("%d", &N);
	solve(1, N, 1);
	for(int i=1;i<N;i++)
		for(int j=i+1;j<=N;j++)
			printf("%d%c", A[i][j], (j == N) ? '\n' : ' ');
}

Measured memory_bytes: 1408
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	r := ""
	for n > 0 {
		w := n / 26
		a := n % 26
		if a == 0 {
			r = "z" + r
			w--
		} else {
			r = itos(a) + r
		}

		n = w
	}
	fmt.Println(r)
}

const abc = "abcdefghijklmnopqrstuvwxyz"

func itos(i int) string {
	return abc[i-1 : i]
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

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;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	map<ll,ll> mp;
	rep(i,n)mp[v[i]]++;
	for(auto x:mp){
		ans+=x.sc*(x.sc-1)/2;
	}
	rep(i,n){
		puta(ans-(mp[v[i]]-1));
	}
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    map<string,int> m;
    int now = 1;
    rep(i,n) {
        if(m.count(s[i])) {
            m[s[i]]++;
            now = max(now,m[s[i]]);
        } else {
            m.insert({s[i],1});
        }
    }
    vector<string> ans;
    for(auto p : m) {
        if(p.second == now) ans.push_back(p.first);
    }
    sort(ans.begin(),ans.end());
    for(string s : ans) {
        cout << s << endl;
    }
}

Measured memory_bytes: 28404
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n;
	string s;
	cin >> n >> s;

	REP(i, s.size()) {
		int j = s[i] - 'A';
		if (j + n >= 26) {
			s[i] = 'A' + j + n - 26;
		}
		else {
			s[i] += n;
		}
	}
	
	col(s);
	return 0;
}

Measured memory_bytes: 3624
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:23/03/2020
'''


from math import ceil
def main():
    
    
    
    n,m=map(int,input().split())
    
    a=list(map(int,input().split()))
    a.sort()
    ans=0
    for i in range(n-m):
        ans+=a[i]
    print(ans)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ =="__main__":
    main()

Measured memory_bytes: 27300
#include<iostream>
#include<string>
#include <cmath>
#include<iomanip>

using namespace std;

int n;
double x[100],y[100];

double distance(double p){
  double sum=0;
  for(int i=0;i<n;i++){
    double w=abs(x[i]-y[i]);
    sum += pow(w,p);
  }
  return pow(sum,1.0/p);
}

int main(){
  cout<<fixed<<setprecision(12);

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin>>y[i];
  }
  
  cout<< distance(1) <<endl;
  cout<< distance(2) <<endl;
  cout<< distance(3) <<endl;

  double mx=0;
  for(int i=0;i<n;i++){
    mx=max(mx, abs(x[i]-y[i]) );
  }
  cout<< mx <<endl;
  
  return 0;
}




Measured memory_bytes: 3472
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[1] - a[0] + a[2] - a[1] << endl;
}

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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) cin >> v[i];
  Int ans = T;
  for (int i = 0; i < N - 1; ++i) ans += min(T, v[i + 1] - v[i]);
  cout << ans << endl;
}

Measured memory_bytes: 1024
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    a=sorted([random.randint(0,5) for _ in range(n)])[::-1]
    return n,a

show_flg=False
show_flg=True
a,b,c=LI()
if a+b+c>21:
    ans='bust'
else:
    ans='win'
print(ans)


Measured memory_bytes: 38764
object Main extends App {
  import scala.io.StdIn._
  val Array(n,k) = readLine().split(" ").map(_.toInt)
  var a :Array[Int] = Array()
  for (i <- 1 to k) {
    readInt()
    a = a ++ readLine().split(" ").map(_.toInt)
  }
  val aSet = a.toSet
  println((1 to n).count( x => !aSet.contains(x)))
}

Measured memory_bytes: 56368
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(' ').map(String::toInt)
    val cakes = (1..N).map { readLine()!!.split(' ').map(String::toLong) }
    val r = (0..7).map {
        val x = if (it % 2 == 0) 1 else -1
        val y = if ((it shr 1) % 2 == 0) 1 else -1
        val z = if ((it shr 2) % 2 == 0) 1 else -1

        cakes
                .map {
                    (it[0] * x) + (it[1] * y) + (it[2] * z)
                }
                .sortedDescending()
                .take(M)
                .sum()
    }.max()
    println(r)
}

Measured memory_bytes: 40696