text:
Unique is Cheap
Write a function or program that determines the cost of a given string, where

the cost of each character equals the number of how many times the character has occurred up to this point in the string, and
the cost of the string is the sum of its characters' costs.

Example
For an input of abaacab, the cost is computed as follows:
a b a a c a b
1   2 3   4    occurrence of a
  1         2  occurrence of b
        1      occurrence of c
1+1+2+3+1+4+2 = 14

Thus the cost for the string abaacab is 14.
Rules

The score of your submission is the cost of your code as defined above, that is your submission run on its own source code, with a lower score being better.
Your submission should work on strings containing printable ASCII-characters, plus all characters used in your submission.
Characters are case-sensitive, that is a and A are different characters.

Testcases
input -> output
"abaacab" -> 14
"Programming Puzzles & Code Golf" -> 47
"" -> 0
"       " -> 28
"abcdefg" -> 7
"aA" -> 2

Leaderboard

var QUESTION_ID=127261,OVERRIDE_USER=56433;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px} /* font fix */ body {font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;} /* #language-list x-pos fix */ #answer-list {margin-right: 200px;}
 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Score

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

How do program flags such as -n for Perl count towards the score? It traditionally counts as 1 byte because the edit distance between the standard perl -e and perl -ne is 1, but for this challenge, will the n count for the purposes of counting duplicates?

@ValueInk Yes, I think counting the n is the fairest option.

I really wish there was a brainfuck solution to this challenge.

+1 for The score of your submission is the cost of your code

Is the input as char-array allowed instead of String?

@KevinCruijssen Sure.

@Peter1807, wish granted!

cost of a character is defined as how often this character has already occurred in the string, i'd probably changing to how many times the character has occurred up to this point to make it clearer that the first use costs 1, not 0

@undergroundmonorail Thanks, I added your suggested wording.

Is the leaderboard supposed to be unsorted?

@ØrjanJohansen Do you mean the language names in the winners-by- language section? I wouldn't mind if they were sorted, though I don't really know how the snippet works as I just copied it from an other challenge. Feel free to fix it if you know how.

Alas, I have no idea, except that e.g. the golf you a quine leaderboard is sorted.

MATL, score 4
&=Rz

Try it online!
Explanation
Consider input 'ABBA' as an example.
&=   % Implicit input. Matrix of all equality comparisons
     % STACK: [1 0 0 1;
               0 1 1 0;
               0 1 1 0;
               1 0 0 1]
R    % Upper triangular part
     % STACK: [1 0 0 1;
               0 1 1 0;
               0 0 1 0;
               0 0 0 1]
z    % Number of nonzeros. Implicitly display
     % STACK: 6

Are you a linear algebra professor?

@carusocomputing Actually a mobile communications professor. My tendency to use matrices comes from years of programming in Matlab

Neat! Is Matlab big in that area? I've never really looked into GSM or anything like it.

I joined this community just to commend you on this brilliant solution!

@Wboy Thanks, I feel honored :-) And welcome to PPCG!

@carusocomputing Matlab is a very common tool/language in engineering in general. It's good at numerical computation: linear algebra, signal processing, and the like. And being an interpreted language it's very easy to use

Python, score 49
lambda S:sum(1+S.count(C)for[C]in	S)/2

Try it online!
There's a tab after in.
Score breakdown:

+27 for 27 unique chars
+16 for 8 double chars: ()Camnou
+6 for 1 tripled char: S

Use a tab instead of a space to save a byte.

@mbomb007 Just had the same idea :-)

@mbomb007 Hah, that's a genius trick :-)

@mbomb007 that's just tabs vs. spaces war inside golfed code

Wouldn't it be +5 for S three times? i.e. +2 for the second, and +3 for the third.

@BrianJ I mean +3 over the raw character count, which counts 3 bytes for the 3 copies while the score counts 6.

@xnor Ah, of course. I understand the math now.

I was going to suggest using a form feed (which is also permitted whitespace in Python syntax), but you don't have any more whitespace to replace.

Clearly form feeds are the best characters to use for indenting code.

T-SQL, score 775 579! 580
declaRe @ char(876),@x int,@v int=0Select @=q+CHAR(9)from z X:seleCT @x=len(@),@=REPLACE(@,LEFT(@,1),''),@v+=(@x-LEN(@))*(@x-LEN(@)+1)/2IF LEN(@)>0GOTO X prINT @v-1

EDIT: Dropped a couple of variables, compacted a bit. Down to 16 @ symbols instead of 22, that by itself reduces my score by a whopping 117 points!
Nice contest, I like the requirement to optimize for something besides total character count.
Input is via varchar field q in pre-existing table z, per our IO rules. The database containing this input table must be set to a case-sensitive collation.
Formatted:
declaRe @ char(876), @x int, @v int=0
Select @=q+CHAR(9)from z
X:
    seleCT @x=len(@)
          ,@=REPLACE(@,LEFT(@,1),'')
          ,@v+=(@x-LEN(@))*(@x-LEN(@)+1)/2
IF LEN(@)>0 GOTO X
prINT @v-1

SQL keywords aren't case sensitive, so I used mixed case to minimize the count of duplicate letters (aaAA generates a better/lower score than aaaa).
The main loop compares the length before and after stripping all instances of the first character out. That difference n*(n+1)/2 is added to a running total.
The SQL LEN() function annoyingly ignores trailing spaces, so I had to append a control character and subtract 1 at the end.
EDIT: Fixed a miscalculation of my own score by 2 points (issue with quoting quotes), reduced by 1 by changing casing of one R. Also working on a completely different strategy, I'll be posting that as its own answer.

At first I thought your score was 579! ≈ 8.22 x 10^1349

C (gcc), score:  113   103   100   96  91
Thanks to @ugoren, @CalculatorFeline, @gastropner, @l4m2, and @JS1 for their tips.
g(char*s){int y[238]={};while(*s)*y-=--y[*s++];*y/=1;}

Initializes an array of zeros, then uses the ASCII values of the characters in the string as indices to that array to keep track of the number of instances of each character in the string.
Try it online!

Suggestion: Use variable names that aren't used in keywords, like z,x,c.

@CalculatorFeline char includes c...

Oh right...well, you get the point.

Also, you only need a 127 element array (\x7f is not printable) and please add an explanation.

You need return z. Replacing it with z=z might work on some platforms and without optimization.

z-=- saves 2 points.

Better - z+=--y and return -z.

@ugoren It says C (gcc) for a reason. If it fails on your system, please post specs.

Also, can confirm that this does not work on OSX fake gcc.

Also, it seems that on my machine, you can drop the z= part. Confirmed on TIO as well.

@CalculatorFeline Which z= do you mean? Dropping the latter instance of it doesn't work on TIO (at least for me), and dropping the former instance works but then the function can only be called once.

Forgot about the "must be callable multiple times" rule. Ignore.

Late to the party, but this should be 96: z;g(char*s){int y[238]={z=0};while(*s)z+=--y[*s++];z/=~0;}

@gastropner Thanks!

g(char*s){int y[238]={};while(*s)*y+=--y[*s++];*y/=~0;}

g(char*s){int y[238]={};while(*s)*y-=--y[*s++];*y/=1;}

Jelly, score 6
;\ċ"⁸S

Try it online!

JavaScript (ES6), score 81 78
Saved 3 points thanks to @Arnauld
s=>s.replace(d=/./g,z=>q+=d[z]=-~d[z],q=0)&&q

My original score-81 recursive solution:
f=([c,...s],d={})=>c?(d[c]=-~d[c])+f(s,d):0

Haskell, score 42
f l=sum[1|c<-l,d<-c:l,d==c]/2

Try it online!
Anonymizing \l-> gives the same score.

Retina, score 34
s(O`.
M&!`^|(?<=(.))\1*
.

Try it online!
Explanation
s(O`.

We start by sorting all the characters in the input so that identical characters are grouped together into a single run. The s( activates singleline mode for all stages (i.e. makes . match linefeeds).
M&!s`^|(?<=(.))\1*

The goal is to turn a run of n characters into Tn characters (the nth triangular number) because that's the score of the occurrences of this character. To do so, we find overlapping matches. In particular, for each i in [1,n], we're going to include i-1 characters in the match. We get all those matches due to the overlapping flag &. That gives us n*(n-1)/2 = Tn-1 = Tn - n characters just from the matches. But the match stage will join these with linefeeds, which are n linefeeds for n matches. There's only one problem. There won't be a linefeed after the last match, so the overall number of characters in the output is one less than we need. We fix this by also matching the beginning of the input, which gives us a single leading linefeed if there is at least one other match.
.

Finally, we just count how many characters there are in the string.

Haskell, score 52 51
f(a:b)=1+sum[1|c<-b,c==a]+f b;f _=0

There's a tab between f and _.
Try it online!
The value of the empty string is 0. The value of the string s, where a is the first char and b the rest of the string is 1 plus the occurrences of a in b plus a recursive call with b.

J, score 16
1#.,@(*+/\"1)&=

Try it online!
Explanation
1#.,@(*+/\"1)&=
              =  Self-classify: bit matrix of equality between input
                 and its unique elements.
     (      )&   Apply verb in parentheses to it:
       +/\         running sums
          "1       of each row
      *            multiplied with original matrix.
                 This causes the i'th 1 on each row to be replaced by i.
   ,@            Flatten the resulting matrix
1#.              and interpret as a base-1 number, computing its sum.

Using 1#. instead of +/@ for the sum saved a few points, and & could be used instead of @ in a monadic context to save one more.
The repeated 1 costs me one extra point, but I haven't been able to get rid of it.

"later" waits a quarterday

@CalculatorFeline 10 hours later is still later. :P

Let's make it a sesquisemiday now.

I personally use this format for TIO answers in order to reflect an accurate byte count in the code section, maybe you would want to use it

R, score: 67 83 95 128
-61 thanks to top tips from Giuseppe

function(x,y=table(utf8ToInt(x)))y%*%{y+1}/2

Try it online!
The string is split using utf8ToInt and each ascii value is counted table.  The the result is calculated using doing a matrix multiplication %*% over that at itself + 1 and finally halfed.

use table instead of rle; you can get rid of the sort as well (and you don't have to index [[1]] into the result of strsplit)

@Giuseppe Thanks a lot.  I didn't even think of table, will incorporate soon.

I think you can save a few more bytes by using a different variable name instead of n (since it's in function twice) and also changing (n+1) to {n+1}

score:67. Some variation on this might make it possible to reduce the score further.

@Giuseppe ... I should have re read it .  whoops

Jelly, score 5
ĠJ€ẎS

Try it online!
Thanks to Leaky Nun for -2 (previously on his answer)

Ahhh I didn't notice this question fast enough.

@LeakyNun p.s. you're not always a ninja, nor anyone is

Really? I don't think so.

Score 5: ĠJ€ẎS

@LeakyNun As promised...yeah, the credit is there :)

05AB1E, score 6
{γ€gLO

Try it online!

Pyth, score 6
1 byte thanks to isaacg.
+F/V._

Test suite.
How it works
+F/V._
+F/V._QQ  implicit input
  /V      vectorize count: for each element in the first argument,
                           count the number of occurrences of the
                           second argument:
    ._Q       all prefixes of input
       Q      input
+F        fold (reduce) on +, base case 0.

s+0 is the same as +F.

Good!  The best I could do is usaShHGrScQ1 8Z for 16.  Can you add an explanation?

@DigitalTrauma I've added an explanation.

s/LQ is score 4, does this use features that postdates the challenge?

J, score: 14 12 11
$+/@,2!1#.=

Try it online!

Clever use of $.

Nice.  Slight 11 byte variation: 1#.2!1+1#.=

@Jonah Reusing glyphs results in a penalty

ah, missed that part.

Jelly, score of 7
ċÐ€QRFS

Explanation:
   Q    get unique letters
ċÐ€     count the occurences of each letter in the original string
    R   [1..n] for n in list of frequencies
     F  flatten list
      S sum
        (implicit output)

Try it online!

Welcome to PPCG!

C, 60 bytes, score 108 95
g(char*s){int y[256]={},z=0;while(*s)z-=--y[*s++];return z;}

Try it online!
Usually pre- and post-increment operators are great for code golf, but they really hurt on this challenge!
EDIT: By subtracting negative counts instead of adding positive ones, I saved a whole bunch of score. Replacing for() with while() eliminated a semicolon as well.

C# (.NET Core), score ∞ (I mean, 209)
b=>b.Distinct().Select(z=>{var w=b.Count(p=>p==z);return w*(w+1)/2;}).Sum()

Try it online!
The score includes the following:
using System.Linq;

I know it's been a while, but you can change return w*(w+1)/2 to return-~w*w/2 (score 196). EDIT: You can create a port of my Java 8 answer for a score of 149: using System.Linq;b=>{int[]x=new int[256];return\nb.Select(z=>++x[z]).Sum();} Try it online.

@KevinCruijssen: I got your solution down to a score of 111: b=>{var x=new int[256];return\nb.Sum(z=>++x[z]);}

@raznagul (half year old response incoming) 109 if you change the second space to a tab. ;) Try it online.

@KevinCruijssen (another half year old response incoming) 49 with the interactive compiler, and I think it won't ever get below 48. I find it odd how the more golfed C# answers get, the more readable they always seem to become. Try it online!

PowerShell, score 64
$z=@{}
$ARGS|% getE*|%{$u+=($Z.$_+=1)};$U

(Score is based on a single linefeed newline, which isn't Windows standard but does work in PS).
PS C:\> D:\unique-is-cheap.ps1 (gc D:\unique-is-cheap.ps1 -raw)
64

Hashtable counter @{}
Iterate through the letters; $args is an array of parameters - in this case the input string makes it a single item array; |% does a foreach loop over the items, and uses the getE* shortcut to match the GetEnumerator() string method and call it to turn the string into a character stream.
|% loop over the characters and increment their hashtable entry, add it to a running total. The ($x+=1) form with parens both modifies the variable and outputs the new value for use.
Output the running total.

(When I first wrote it, it was $c=@{};$t=0;[char[]]"$args"|%{$c[$_]++;$t+=$c[$_]};$t with a score of 128, and felt like it wouldn't go much lower. Halving it to 64 is quite pleasing).

61 pts/ 38 bytes by messing with the increment

59 pts/36 bytes

Perl 6, score  61 56 53 46  44
(1 X..*.comb.Bag.values).flat.sum

Try it
{sum flat 1 X.. .comb.Bag.values}

Try it
{sum flat 1 X.. values(.comb.Bag)}

Try it
{[+] flat	1	X.. values(.comb.Bag)}

Try it
{[+] flat	1	X.. values(bag
.comb)}

Try it

Java 10, score: 149 138 137 134 133 130 103 102 101 100
(Bytes: 72 73 74 75 64 62 61) Bytes go up, but score goes down. :D
x->{int j=0,q[]=new int[256];for(var    C:x)j+=++q[C];return
j;}

-28 score (and -11 bytes) thanks to @Nevay.
-1 score (and -2 bytes) thanks to @OlivierGrégoire.
-1 score (and -1 byte) by converting Java 8 to Java 10.
Explanation:
Try it here.
x->{                     // Method with character-array parameter and integer return-type
  int j=0,               //  Result-integer, starting at 0
      q[]=new int[256];  //  Integer-array with 256 times 0
  for(var   C:x)         //  Loop over the characters of the input array
    j+=++q[C];           //   Raise the value in the array by 1,
                         //   and then add it to the result-integer
  return                 //  Return
  j;}                    //         the result

You can remove the ~ if you use j=0 and return-j; (133).

103: x->{int[]q=new int[256];return\nx.chars().map(v->++q[v]).sum();}

@Nevay 103 actually, when I use j instead of u (return contains u) and a new-line and tab instead of the spaces. EDIT: Hehe, you've edited right when I made this comment. :)

Julia 0.6, 45 bytes, Score: 77

Inspired by the MATL solution:
f(w)=sum(UpperTriangular([z==j for z=w,j=w]))

Try it online!
A less pretty solution, using counts:
Julia 0.6, score: 82
F(w)=sum(l->[l+1]l/2,count(x->x==i,w)for i=Set(w))

Try it online!
Thanks to Guiseppe for pointing out the scoring and for tips.
These comments helped me loads.

The score of your submission is the cost of your code, which I think is 135.

I don't know Julia very well but I think you can reduce the score to 110 by switching some variable names and removing a set of parentheses. If returning a single-element vector is allowed, then you can replace (x+1) with [x+1] to further reduce the score.

You can save a score by changing the second space to a tab or  new-line: score 104. And @Giuseppe tip of using [x+1] instead of (x+1) lowers it to a score of 98.

The second approach doesn't accept the empty string. It could be reduced to 63 points in Julia 0.7.

Adding a special case for the empty string brings the score to 83.

F#, score 120 118
let j z=Seq.countBy id z|>Seq.sumBy(fun x->List.sum[0..snd x])

-2 thanks to Kevin Cruijssen!
Try it online!
Takes a string as an input. Seq.countBy pairs each distinct character with its count (id is the identity function) so you end up with a collection like 'a' = 4, 'b' = 2 etc.
The Seq.sumBy takes the count for every letter and sums all the numbers from 0 to the count for that letter. So if 'a' = 4 the collection would be 0, 1, 2, 3, 4 which summed together is 10. Then Seq.sumBy sums all those totals.

You can lower your score by 2 by changing let q to let j, since the q is already used in both Seq.

BQN, Score: 4
≠+´⊒

Run online!
The occurrence count builtin ⊒ calculates the cost of each character decremented by 1. To adjust for that we can either add 1 to each cost or add the length ≠ to the sum. The latter turns out to be a byte shorter.

Common Lisp, score 286 232 222
(loop with w =(fill(make-list 128)0)as z across(read)sum(incf(elt w(char-code z))))

High-valued score due to the wordy syntax of builtin operators of Common Lisp.
Try it online!
The ungolfed code:
(loop with w = (fill (make-list 128) 0)  ; create a list to count characters
   as z across (read)                   ; for each character of input
   sum (incf (elt w (char-code z))))     ; increase count in list and sum

PHP, 45 bytes, Score 78
WHILE($x=ORD($argn[$v++]))$y+=$$x-=-1;echo$y;

Try it online!
PHP, 46 bytes, Score 79 Bytes
WHILE(~$xy=$argn[$vz++])$su-=-$$xy+=1;echo$su;

Try it online!
PHP, 56 bytes, Score 92
FOREAch(COUNT_CHARS($argn)as$z)WHILE($z)$y+=$z--;echo$y;

Try it online!

Perl 5 score 91 83
Uses the -p flag which adds 2 because of the p in split.
$x=$_;$b+=++$a{$_}for(split//,$x);$_=$b

Welcome to PPCG!

Using your answer as a base and applying some techniques from the tips page, I managed to get your score down to 31: Try it online!. $\ is automatically printed after each call so we can use that to store the score and /./g returns a list of all chars in $_, which is cheaper than split//.

I know this is an old challenge, but you can cut the score even further: Try it online!

Octave, 39 bytes, Score 69
@(a)sum((b=hist(a,unique(1*a))).^2+b)/2

Try it online!
While there is another Octave answer, this one is entirely my own and a different approach, plus it scores less :).
The approach boils down to first finding the count (b) of each unique character, which is achieved using the histogram function. Then for each element we calculate the sum of 1 to b which is done using the formula (b*(b+1))/2. Then the individual sums are all summed into the final score.
In testing it seems brackets are really costly in the scoring because many are needed. I've optimised down from an initial score of about 88 by rearranging the questions to minimise the number of open/close brackets - hence we now do the /2 on the final total rather than individually, and also I've modified the formula to (b^2+b)/2 as that requires fewer brackets.

Unfortunately this appears to fail on the empty string: error: hist: subscript indices must be either positive integers less than 2^31 or logicals

APL (Dyalog), score 27 18 11 10
Reduced score by 7 thanks to @Adám by using a tradfn and using 1⊥ to sum the frequencies
Reduced score by 1 thanks to @rabbitgrowth by using a function instead
1⊥{+/⍳≢⍵}⌸

Try it online!

Same method, score 11: 1⊥{+/⍳≢⍵}⌸⍞

@Adám Thanks, the 1⊥ trick is really neat

Can't the ⍞ be omitted? It turns into a function, and it still works.

@rabbitgrowth Thanks!

Octave , score 77 31 bytes
*same as @LuisMendo 's MATL answer.
@(a)nnz(triu(a==a'))

Try it online!
Previous answer:
@(d,g=accumarray(+d',1)-(0:254))sum(g(g>0));

Try it online!

You could probably save a point by ditching the semicolon. Couldn't test it as it doesn't seem to work with TIO.

@TomCarpenter Without ; doesn't work. however such a lambda cab be used in arrayfun.

APL (Dyalog), score 15
+/1 1⍉+\∘.=⍨⍞

Try it online!
⍞ get text input
∘.=⍨ equality table with self
+\ cumulative sum across
1 1⍉ diagonal (lit. collapse both dimensions into dimension one)
+/ sum

Retina, score 68 45 43
s`(.)(?<=((\1)|.)+)
$#3$*
1

Try it online! Link shows score. Edit: Thanks to @MartinEnder who saved 20 bytes by using overlapping matches instead of lookaheads and a further three bytes by grouping the stages so that the s flag only needs to be applied once. Saved a further two bytes by calculating the triangular number differently, avoiding the need for a sort.

Mathematica, score 42
Total[#^2+#].5&@*CharacterCounts

input

["abcdefg"]

thanks to hftf
thanks to att

Total[#(#+1)/2&@Counts@Characters@#]& scores 54.

42: Total[#^2+#].5&@*CharacterCounts

brainfuck, score 897
,[<<[[->+>-<<]>>[<]<[<]<[<]<[+<<]>>>>[>]>[->+>+<<]>[-<+>]<<<]<+[->>+<<]>>>[->+<]>[>]>,]<<[<]<

Try it online!
Ends on the cell with the correct value. Assumes a cell size larger than the score of the string, otherwise it'll wrap (got a little suspicious when the interpreter said the score was 188).

You might be able to change this to use one of the many binary-encoded brainfuck dialects that exist to lower your score...

CompressedFuck looks promising.

@EsolangingFruit That's like saying switching to Jelly may save some bytes on your Java answer... :P

@ConorO'Brien I'd argue that it's more akin to switching from a version of Jelly which must begin with the header module Main where: import Jelly.Types; import Jelly.Builtins. The problem being solved is the same, it's just more competitive. But I do see your point - switching languages is essentially switching competitions, so it's not really fair to ask someone to do that.

Japt -x, 9 7 6 points
ü mÊcõ

Try it

Not that hard to optimise for score when you can solve it using entirely unique characters, huh :P

SNOBOL4 (CSNOBOL4), score: 681
	s	=iNPUT
	Y	_table()
d	S	LEN(1) . x REM . S	:F(b)
	Y<X>	=y<X> + 1	:(D)
b	Z	_convert(Y,'aRrAy')
N	j	=J + 1
	G	_z[j,2]	:f(q)
	o	=o + g * G + g	:(N)
q	OUtpuT	_O / 2
end

Try it online!
looks a bit scary, but SNOBOL matches identifiers case-insensitively, which dropped the score by around 100 points. Note that it requires a single line of input, so I've replaced \n with ; in the input field (which is still valid SNOBOL).
The SNOBOL4 implementation on TIO allows for an additional 16 point golf, as = and _ are both allowable as the assignment operator. How neat!

Rust, 265 255 bytes. Score: 1459 1161
fn main(){let mut z=String::new();std::io::stdin().read_line(&mut z);let Z=z.trim_right_matches(|x|x=='\r'||x=='\n');let mut q:Vec<u8>=Z.bytes().collect();q.sort();let(mut k,mut W,mut j)=(0,0u8,0);for Y in&q{if*Y==W{j+=1}else{j=1;W=*Y}k+=j}print!("{}",k)}

Ungolfed
fn main() {
    let mut input_string = String::new();
    std::io::stdin().read_line(&mut input_string);
    let trimmed = input_string
        .trim_right_matches(|c| c == '\r' || c == '\n');
    let mut chars: Vec<u8> = trimmed.bytes().collect();
    chars.sort();
    let (mut total_score, mut last_char, mut last_score) = (0, 0u8, 0);
    for letter in &chars {
        if *letter == last_char {
            last_score += 1;
        } else {
            last_score = 1;
            last_char = *letter;
        }
        total_score += last_score;
    }
    print!("{}", total_score);
}

Edit: improved answer by renaming variables and altering code

Welcome to PPCG! In this challenge the score of your submission is the cost of your code, which I think is 1459.

Edited. Thanks for pointing that out

This also means you can improve your score quite a bit by choosing characters as variable names which are not already contained in other keywords.

You're still using a lot of variable names that are characters used elsewhere. jkqvxz and most capitals are unused and would improve the score.

Husk, Score 9
½§+L(Σ´×=

Try it online!
Explanation:
This calculates the score as sum_i (n_i^2 + n_i)/2, where i is indexed arbitrarily across unique character types and n_i is the number of characters of type i in the input. But since sum_i n_i is the length of the input, this reduces to (1/2) * (L + sum_i n_i^2)
Code breakdown:
o ½ (§ + L (o Σ (´ (× =)))        --With parentheses and two implicit compositions
                   (× =)          --1 or 0 for each equality check between elements of its first and second arguments
                (´ (× =))         --argdup, 1 or 0 for each equality check between elements of its only argument
           (o Σ (´ (× =))         --# of equalities between pairs (this will give sum_i n_i^2)
         L                        --length
    (§ + L (o Σ (´ (× =)))        --length + sum_i n_i^2
o ½ (§ + L (o Σ (´ (× =)))        --1/2 * (length + sum_i n_i^2)

You can do Ṡṁ# instead of (Σ´×= for a score of 7.

Python 2. Score:142 115
def     f(a):
        x=0
        for y in set(a):z=a.count(y);x+=.5*z*-~z
        print x

EDIT:-27 thanks to @Kevin Cruijssen

By changing the indentations and the space between def f(a) to tabs you lower your score to 126. In addition, you can change (z+1) to -~z to lower it more to 117. And you can remove the 0 in 0.5 to lower it to 115. Try it online.

@KevinCruijssen Thanks, Changed!

Try it online! link

Husk, 5 bytes, score 5
ΣṁŀgO

Try it online!
Different and (so far) shorter strategy to Natte's or Sophia Lechner's Husk answers.
    O   # sort the input
   g    # and group equal adjacent values;
 ṁ      # now, for each group
  ŀ     # make a range 1..length of the group
 ṁ      # and flatten all the ranges into one list;
Σ       # then output the sum

J, score 23
$-:@+[:+/,/@(=/~)

Try it online!

Clojure, score 96
#(apply +(for[[k j](frequencies %)](*(inc j)j 0.5)))

Five spaces and pairs of brackets...

Actually, score 12
;╗╔⌠╜cRΣ⌡MΣ

Try it online!
Explanation:
;╗╔⌠╜cRΣ⌡MΣ  (implicit input: S)
;╗           save a copy of S in register 0
  ╔          uniquify S (call it A)
   ⌠╜cRΣ⌡M   for each unique character in A:
    ╜c         count the number of occurrences in S
      R        range(1, count+1)
       Σ       sum
          Σ  sum

Repeating the Σ is two points less than using an alternative formulation with no repeated characters (i`+Y).

F#, score:12641110
-154 points, thanks to @Laikoni
let x(y:bool)=System.Convert.ToInt32(y)
let rec p(k:string)q=
 let j=k.Length
 if(j=1)then(x(k.[0]=q))else p k.[0..(j-2)] q+x(k.[j-1]=q)
let rec d(a:string)=
 let z=a.Length
 if(z<2)then z else d a.[0..(z-2)]+p a (a.[z-1])

You need to call the d function. In a more readable form:
let x (y:bool)=
    System.Convert.ToInt32(y)
let rec e (c:string) b=
    let j=c.Length
    if(j=1)then
        (x(c.[0]=b))
    else
        e c.[0..(j-2)] b+x (c.[j-1]=b)
let rec d (a:string)=
    let h=a.Length
    if(h<2)then
        h
    else
        d a.[0..(h-2)]+e a (a.[h-1])

Explanation
It is a recursive algorithm, the base case is, if the length of the string is less than 2 (0 or 1), the score will be the length of the string. This is because, if the length is 0 (empty string), we have no characters, so the score is 0, and if the length is 1, that means, that the string consists of only 1 character, so the score is 1.
Otherwise it trims the last character of the string, and to the score of the truncated string adds the count of the last character in the untruncated string.
The counting algorithm is also recursive. Its base case is, when the length of the string is one, then the count is 1, if the string matches with the character, and 0 otherwise. This can also be done, if we convert the bool to an int, and this results in a lower score.
Otherwise it trims the last character of the string, calculates the count of that string, and if the last character matches the character, we are calculating the count of, adds one to the count. This is again, better, if we convert that boolean to an int.

I think you can remove some white space, e.g. around the parentheses in let rec e (c:string) b=. Also using some character as variable which does not appear in keywords will improve your score, e.g. y instead of e.

FIREBIRD, score 3577
Version to calculte the score:
SELECT COALESCE(SUM(C),0)FROM(WITH RECURSIVE T AS(SELECT 1 AS I,SUBSTRING(CAST(:V AS BLOB)FROM 1 FOR 1)AS S FROM RDB$DATABASE UNION ALL SELECT I+1,SUBSTRING(CAST(:V AS BLOB)FROM I+1 FOR 1)FROM T WHERE I < CHAR_LENGTH(CAST(:V AS BLOB)))SELECT T.*,(SELECT COUNT(T2.I) FROM T T2 WHERE T2.S=T.S AND T2.I<=T.I)AS C FROM T WHERE CAST(:V AS BLOB) <> '')

Below is the idented version of the code, in case anyone want to now. I'm sorry for any mistakes, first time here actually posting!
SELECT COALESCE(SUM(C), 0)
FROM (
  WITH RECURSIVE T AS (
    SELECT 1 AS I, SUBSTRING(CAST(:V AS BLOB) FROM 1 FOR 1) AS S
    FROM RDB$DATABASE

    UNION ALL

    SELECT I+1, SUBSTRING(CAST(:V AS BLOB) FROM I+1 FOR 1)
    FROM T
    WHERE I < CHAR_LENGTH(CAST(:V AS BLOB))
  )
  SELECT T.*, (SELECT COUNT(T2.I) FROM T T2 WHERE T2.S = T.S AND T2.I <= T.I) AS C
  FROM T
  WHERE CAST(:V AS BLOB) <> ''
)

Explanation
I start my select in a system table SELECT 1 AS I, SUBSTRING(CAST(:V AS BLOB) FROM 1 FOR 1) AS S FROM RDB$DATABASE, which always has only one row. Using that only one row, I return 1 as a column I, and the character that exists in the input in the I value.
Let's say I've passed 'abaacab' as input:

╔═══╦═══╗
║ I ║ S ║
╠═══╬═══╣
║ 1 ║ a ║
╚═══╩═══╝

In the UNION ALL part, I start to increment the index from the first select, until it reaches the end of the input. So, in the example I would get this:

╔═══╦═══╗
║ I ║ S ║
╠═══╬═══╣
║ 1 ║ a ║
║ 2 ║ b ║
║ 3 ║ a ║
║ 4 ║ a ║
║ 5 ║ c ║
║ 6 ║ a ║
║ 7 ║ b ║
╚═══╩═══╝

After that, I also select the count of ocurrences from the value on S, that has already appeared in indexes below the I. So, in a column C I now have the 'cost' of that character, which I only need to SUM after to get the value.

╔═══╦═══╦═══╗
║ I ║ S ║ C ║
╠═══╬═══╬═══╣
║ 1 ║ a ║ 1 ║
║ 2 ║ b ║ 1 ║
║ 3 ║ a ║ 2 ║
║ 4 ║ a ║ 3 ║
║ 5 ║ c ║ 1 ║
║ 6 ║ a ║ 4 ║
║ 7 ║ b ║ 2 ║
╚═══╩═══╩═══╝

I used BLOB as the type from the input, to not get limited by size.

Welcome to PPCG!

@Laikoni Thanks! I forgot to add a short explanation, my bad. I will do it later, in case anyone is interested.

I'm always interested in explanations. :) Have you checked for each space wether it can be removed or not? Some of them look unnecessary, e.g. (SUM(C), 0) or AS (SELECT, thought I don't know firebird.

Thanks @Laikoni, with your advice I saved some points. I've just add my explanation. If its too bad just let me know so I can try to make a better one.

AWK, 39 bytes, Score 54
BEGIN{RS="(.)"}{M+=++s[RT]}END{print M}

Try it online!

Changing S to some unused character reduces the score by two.

Python 3, score 89 85
lambda	y:sum(y[:x+1].count(v)for	x,v in enumerate(y))

Try it online!

Python 2, score 83
lambda z:sum((2*z.count(x)+1)**2/8for x in set(z))

Try it online
1/8 (1 + 2 n)^2 -1/8 is the same as n (n+1) / 2. Floor division removes the need to subtract 1/8.

K/Kona, score 19
+/,/1+!:'(#:)'=

Works as:
              = (implicitly take arg as input), group -> make dictionary of characters to their occurring indices
         (#:)'= count each of these
    1+!:'(#:)'= get a list from 0->n-1 for each of these counts, add one to each
+/,/1+!:'(#:)'= finally, reduce to single list, sum reduce this list

Example:
k)+/,/1+!:'(#:)'="+/,/1+!:'(#:)'="
19
k)+/,/1+!:'(#:)'="abaacab"
14

Legible q equivalent:
(sum/)raze 1+til count each group

Jelly, 10 9 bytes; Score 10 9
ṢŒrzẆṪRẎS

Try it online!
This is the first time I use Jelly, and I didn't want to check other people's answers because I wanted to try it myself. I probably reinvented the wheel a couple times there. Suggestions and feedback are greatly appreciated.
EDIT: -1 byte for removing ɠ and taking the input as an argument.
Explanation:
ṢŒrzẆṪRẎS           #Main Link; input abaacab
Ṣ                   #sorts input; aaaabbc
 Œr                 #run-length encode, or the number of times a character appears; a4b2c1
   z                #zip; ['abc', [4, 2, 1]]
    Ẇ               #takes every contiguous sublists
     Ṫ              #Pops the last element; [4, 2, 1]
      R             #Takes the range of every element; [[1,2,3,4],[1,2],1]
       Ẏ            #Collapses every element into a single array; [1,2,3,4,1,2,1]
        S           #Sum and implicitly print; 14.

(no idea why, but the code doesn't work without Ẇ,
 although it gives the exact same output as z)

8 bytes, score of 8

Pyke, score 7
cemSss

Try it here!
c      -    count_occurrences(input)
 e     -   values(^)
  mS   -  [range(1,i+1) for i in ^]
    ss - sum(sum(i)for i in ^)

Japt, score 12 (+2 for -x) = 14
¬n ó¥ ËÊõÃc

Explanation
¬n ó¥ ËÊõÃc                                             "abaacab"
¬            // Split the input into an array of chars  ["a","b","a","a","c","a","b"]
 n           // Sort                                    ["a","a","a","a","b","b","c"]
   ó¥        // Partition matching items                [["a","a","a","a"],["b","b"],["c"]]
      Ë      // map; For each array:
       Ê     //   Get the length x                      [4,2,1]
        õ    //   Create a range [1...x]                [[1,2,3,4],[1,2],[1]]
         Ã   // }
          c  // Flatten                                 [1,2,3,4,1,2,1]
-x           // Sum                                     14

Try it online!

J, score 14
1#.2!1+#/.~

Try it online!
Outgolfed by the other J solution, but figured I'd post this anyways since it uses a slightly different method.

Attache, score 36
Sum@Map&:(Count#Last)@Prefixes

Try it online!
Explanation
Sum@Map&:(Count#Last)@Prefixes

This is a composition of 3 functions:

Prefixes - this simply obtains the prefixes of the input
Map&:(Count#Last) - This is a mapped fork. This is equivalent to arr.map { e -> e.count(e.last) } So, for each character, this counts the occurrences of that character so far.
Sum - this sums all of these numbers.

JavaScript, 112 95 58 points
A=>A.map(C=>N+=A[C]=-~A[C],N=0)|N

7 points saved thanks to ETHProductions

Try it online!

MS-SQL, score 308
I'm using a completely different technique from my other answer, with additional restrictions, so I'm submitting them separately:
SelEcT SUm(k)FROM(SELECT k=couNt(*)*(CoUNT(*)+1)/2froM spt_values,z WHERE type='P'AND number<len(q)GROUP BY sUBstring(q,number+1,1))L

Caveats: this must be run from the master database of a MS-SQL server set to a case-sensitive collation (mine is set to SQL_Latin1_General_CP850_BIN2).
Input is via varchar field q in pre-existing table z, per our IO rules. Formatted:
SelEcT SUm(k)
FROM
    (SELECT k=couNt(*)*(CoUNT(*)+1)/2
     froM spt_values,z
     WHERE type='P'
     AND number<len(q)
     GROUP BY sUBstring(q,number+1,1)
    )L

The trick here is to use a "number table"  to join with the input table, which allows me to separate each character into its own row, then group by matching characters, count them up, calculate the score of each, and sum them all together. All the rest is minimizing score by playing with character case, since SQL keywords are not case sensitive.
MS-SQL has a system table in the master database called spt_values with a lot of junk in it, but I restrict it to type='P', I get a nice number table with 0 through 2047.

K4, score 15
Solution:
+/,/{1+!#x}'=

Example:
q)k)+/,/{1+!#x}'="Programming Puzzles & Code Golf"
47

Explanation:
+/,/{1+!#x}'= / the solution
            = / group
    {     }'  / apply lambda to each (')
         x    / implicit lambda input
        #     / count length
       !      / range 0..n
     1+       / add one
  ,/          / flatten list
+/            / sum up

Notes:
In Q this could be written as:
q)sum raze { 1 + til count x } each group "Programming Puzzles & Code Golf"
47

Standard ML, 66 bytes, score 113
fun$(a::z)=1+length(List.filter(fn y=>y=a)z)+	$z|
$_=0;$o explode;

This code defines an anonymous function which is bound to the implicit result identifier it. Try it online!
Explanation
The ungolfed code looks like this:
fun f (a::z) = 1 + length (List.filter (fn y => y=a) z) + f z
  | f  _     = 0
val g = f o explode

The function g takes a string as input, converts it to a list of characters with explode, and passes it on to the function f which recurses over the list, with a being the current character and z being the remaining list. For each a the number of occurrences of a in z is computed by filtering z to contain only chars equivalent to a and taking the length of the resulting list. The result is incremented by one to account for the current occurrence of a and added to result of the recursive call of f on z.

Stax, 8 6
ç╕┌α▒'

Run and debug online!
Saved 2 points by using runs per comment by @recursive.
Explanation
Uses the unpacked version to explain.
o:GF:T+
o          Sort array
 :G        Run lengths
   F       For each run length `n`
    :T     The nth triangular number
      +    Add to accumulator
           Implicit output

run-length is good here.  6

PHP, 44 bytes, score 78:
While($C=ORD($argn[$p++]))$s-=++$$C;EcHo-$s;

Almost Jörg´s solution, but one byte shorter.

PHP, 51 bytes, score 80
ForEach(COUNT_CHARS($argn)As$p)$z-=~$p*$p/2;echo$z;

Run as pipe with -nR or try them online

Perl6/Rakudo, 45 bytes, score 66
Run with perl -ne:
say [+] bag(.comb).values.map({($_+1)*$_/2});

Uses the essential nature of a Bag (like a set with a count per member).
Step by step:
.say;                      # abaacab
say .comb;                 # (a b a a c a b)
say bag(.comb);            # Bag(a(4), b(2), c)
say bag(.comb).values;     # (2 4 1)
say bag(.comb).values.map({($_+1)*$_/2});        # (3 10 1)
say [+] bag(.comb).values.map({($_+1)*$_/2});  #14

Also note that each character's score can be calculated from its occurrences as (n+1)*n/2.
Edited because I cannot evidently read.

In this challenge, the score of your submission is the cost of your code which I think is 75.

><>, score 33
0vAB;n*
i:0(?^:ag1+:}r-@a

Try it online!
28 bytes, with 2 occurrences each of a and 0, and 3 occurrences of :. AB can be replaced by any two characters which don't appear anywhere else in the code.
Works by storing the current character count in the code grid on row 10. The sum is actually a negative sum to start with, and the -1 from reaching the end of STDIN is multiplied with this to turn it back into a positive number.

SHELL ( 67 bytes)
Last Solution : ( 68 bytes)
 f(){ bc<<<`echo -n "$1"|od -bAn|sed "s/\([^ ]\+\)/s+=++v\1;/g"`s;}

Old solutions :
Old Solution 1 : by creating function f (83 bytes ) :
f(){ bc<<<`echo "$1"|sed "s/./ss+=++&;/g"|sed "s/[A-Z]/\L&_/g"|sed "s/ /bb/g"`ss;}

Old Solution 2 : by creating alias f ( 81 bytes )
alias f='bc<<<`cat -|sed "s/./ss+=++&;/g"|sed "s/[A-Z]/\L&_/g"|sed "s/ /bb/g"`ss'

Explanations :
I used  ( sed "s/./ss+=++&;/g" ) to replace any char a by  ( ss+=++a; ); where ss is the sum to calculate, then concatenate with ss, and calculate all expression by the command bc :
echo "a" | sed "s/./ss+=++&;/g"
ss+=++a;

for a string in input :
echo "aab" | sed "s/./ss+=++&;/g"
ss+=++a;ss+=++a;ss+=++b;

step by step :
ss+=++a;    // a=1  -->  ss=1
ss+=++a;    // a=2  -->  ss=3
ss+=++b;    // b=1  -->  ss=4

for lowercase only input, the simpler function need only ( 47 bytes ) to define :
f(){ bc<<<`echo "$1"|sed "s/./ss+=++&;/g"`ss;}

to take uppercase in consideration, Without spaces ( 68 bytes) :
f(){ bc<<<`echo "$1"|sed "s/./ss+=++&;/g"|sed "s/[A-Z]/\L&_/g"`ss;}

Complete Solution ( 83 bytes):
f(){ bc<<<`echo "$1"|sed "s/./ss+=++&;/g"|sed "s/[A-Z]/\L&_/g"|sed "s/ /bb/g"`ss;}

fuction tests :
f "abaacab"
14

f "abcdefg"
7

f "       "
28

f "Aa"
2

using an alias instead the function, we can reduce code size to ( 68 bytes )
alias f='bc<<<`cat -|sed "s/./ss+=++&;/g"|sed "s/[A-Z]/\L&_/g"|sed "s/ /bb/g"`ss'

alias tests :
echo "       " | f
28

echo "Ab" | f
2

The score of your submission is the cost of your code, that is 241 for the 84-byte version and 232 for the 81 byte version.

Since this challenge is not scored by length, you should list the scores instead of byte counts.

Ruby, score: 38
->z{z.sum{|k|z.count(k)+1}/2}

Try it online!

R, 349
Here is my R solution bit of tidy
s=function(x) {c=0
for (i in unique(strsplit(x,"")[[1]])) {
c=c(c,sum(1:sum(charToRaw(x)==charToRaw(i))))}
sum(c)
}

Welcome to PPCG! The point of this challenge is to make the score (the output of running your code on your code) as small as possible. This would have quite a large score! I would be more than happy to help you reduce the score.

Thanks @Giuseppe will work to improve it! Cheers

This answer still has a lot of unnecessary whitespace and long variable names it. Also, in order to be a valid solution, you'll need to provide the current byte count. (which is currently 174)

While in the counting part you use charToRaw(), better use it instead strsplit() too. Score 195

@manatwork thanks for your advice but it is not quite clear when you would use strsplit()

Uhm… Never. Both functions decomposes the string into vectors of unique values per character, so I suggested to work exclusively with raws. BTW, the code I linked has the score of 195. Your currently posted code's score is 456. ☹

@manatwork just amended thanks working on cut it short now!

jq, score 60
(40 characters code + 3 characters command line option)
[./""|group_by(.)[]|range(length+1)]|add

Sample run:
bash-4.4$ jq -R '[./""|group_by(.)[]|range(length+1)]|add' <<< 'Programming Puzzles & Code Golf'
47

Try it online!
jq, score 63
[./""|group_by(.)[]|range(length+1)]|add+0

In case the result for empty string must be numeric 0. There are a few other solutions that use alternative representation of nothing.

Kotlin, score 93
{it.foldIndexed(0){z,q,v->q+it.take(z+1).count{it==v}}}

Try it online!

Reticular, score 56
iSd:A=>ddV@c~dc$:A=+:A`L0EQ6jj+1*37_$O;

Try it online!

Perl 6, Score: 34
{sum [\+](^∞)[.comb.Bag{*}]}

Try it online!
Takes advantage of the unicode operator ∞ to save on characters.
Explanation
{                          }  # Anonymous code block
              .comb           # Split the input string into characters
                   .Bag{*}    # Get the count of each character
             [            ]   # And inded each into
         (^∞)                 # The infinite list of integers
     [\+]                     # Triangularly summed (0,0+1,0+1+2...)
 sum                          # And return the sum total

C++ (gcc), Score: 209 196 193
98 96 bytes
-3 thanx to l4m2
#include<map>
long	F(std::string	S,int I=0){for(auto&C:S){++I;for(char&D:S)I+=C==D;}return I/2;}

C++-specific tricks:

#include<map> instead of #include<string>
Returning long instead of int to use more different characters
Using auto instead of char in one of the loops has the same effect
References (&) inside range-for save whitespace

Common tricks:

Evenly use both tabs and blanks
Upper case variables to be distinct from keyword characters

Try it online!

193

Your code is  still 196

JavaScript, 150 141 133
f=(g,i=[])=>g?(i[j=g.charCodeAt()]=(i[j]|0)+1)+f(g.substr(1),i):0

Ungolfed:
f=(g,i=[])=>                                                       //function declaration, a is list of appearance of characters so far.
            g?                                                     //check if string is empty
              (i[j=g.charCodeAt()]=                                //update appearance list
                                    (i[j]|0)+1)+                   //handle undefined, then increment
                                                f(g.substr(1),i)   //next character
                                                                :0 //base case for the empty string

150->141 - -6 for renaming variables to unique characters (thanks to Ørjan Johansen), and -3 for removing implicit 0 in charCodeAt.
141->133 - -8 for using actual unique variable names(thanks again to Ørjan Johansen).

The variable names s,a,c give you a higher score than necessary because they're used as characters in charCodeAt and subStr.

@Ørjan Johansen Hmm, then let's see if I can do better

b and d are still not unique. I think i and j are the first vacant ones.

@Ørjan Johansen Oh yeah true

Zsh, 36 bytes, score 52
for	p (${(s..)1})$[j+=++a[#p]]
<<<$j

Try it online!
One tab, one space, one newline. This will fill up the debug log with "command not found". If that must be avoided, 38 bytes, score 55.

05AB1E (legacy), score: 4 (4 bytes)
Ù¢LO

Input as a list of characters.
Try it online or verify all test cases.
Explanation:
Ù     # Get all unique characters of the (implicit) input-list
 ¢    # For each, count the amount of times it occurs in the (implicit) input-list
  L   # Create a list of each of these counts
      # (which implicitly flattens in the legacy version of 05AB1E)
   O  # Take the sum of all those integers
      # (which is output implicitly as result)

Haskell, 150 133 points
(79 75 bytes)
import Data.List
c=foldr(\x->	\y->y+(x*(x+1)`div`2))0.map length.group.sort

Try it online!

-17 points by removing some parentheses (thanks to @Laikoni)

You can drop the parenthesis around the foldr expression and just write map length instead of (map$length) for a score of 133.

Gaia, score: 11 10
$uC¦ₔ┅¦_Σ

Try it online!
For some reason, _ is necessary else this spits out garbage answers. But the language is defined by its implementation, so what are ya gonna do. Without the _, one of the sublists generated by ┅¦is [1 2] which is converted to 12 by Σ.
$		| split into characters
 		|
  u		| get unique
   C¦ₔ		| implicitly copy original input; get counts of uniques into original
      ┅¦	| sequence: 1..count
        _Σ	| flatten and sum

JavaScript, 87 score
A=([B,...C],Z=0)=>B?C.map(D=>D!=B||Z++)^A(C)-~Z:0

Try it online!
C.map(D=>D!=B||Z++) is either empty, 0, true or something with a ,, making it never show value to ^

Vyxal d, 3 bytes
Ċɾ⌊

Try it Online!
Ċ   # Counts of each element within itself
 ɾ  # Convert each value to 1...n
  ⌊ # Parse each to integer, zeroes element values
    # (d flag) take the deep sum

Pyth, 8 bytes, Score: 9
ssSM/LQ{

Test suite
Explanation
ssSM/LQ{  | Full code
ssSM/LQ{Q | with implicit variables filled
----------+-------------------------------
     L {Q | Map over deduplicated input:
    /LQ   |  count in input
  SM      | Map: to [1...N]
 s        | Flatten
s         | Sum

ss can be replaced with s.n for an identical score with no repeat bytes, at the cost of being one byte longer.

Husk, Score: 6
ṁoΣ#¹u

Try it online!
Explanation
ṁoΣ#¹u   translates to ṁoΣ#⁰u⁰
ṁ    u⁰  map following function on unique input and then sum
 o       composed function
   #⁰    count occurrences in input
  Σ      triangular number

Excel, Score: 206
G4 =MID(B3,SEQUENCE(LEN(B3)),1)
C3 =IF(B3<>"",SUM(EXACT(G4#,TRANSPOSE(G4#))/2)+ROWS(G4#)/2,)

Link to Spreadsheet

Excel VBA Immediate Window, Score 159 141
-18 byte thank to @TaylorRaine
FOR I=1TO[len(b3)]:for J=1to i:Y=Y-(MID([B3],i,1)=mid([B3],j,1)):NEXT:next:?y

The mixed case reduces the score by 30.

Answers are not required to be self resetting, so you can drop the y=0:, and just note that y needs to be cleared before being run - you can also get rid of one of the spaces by using TO[len(b3)]:

Something that I hadn't noticed earlier is that you can replace NEXT:next with NEXT j,i to drop a single character - not sure if that will help to lower the score, but it is an option

JavaScript (Firefox 30+), score 68
S=>[for(C of(T=0,S))T+=S.split(C).length]&&T/2

This uses array comprehensions which were originally planned for ES7, but were dropped late in the process. Firefox had implemented them anyway.

I thought those were ES6...?

@CalculatorFeline No, they didn't make it in favour of map/filter with arrow functios

*planned for ES6

QBIC, score: 128
dim x(126)[_l;||i=asc(_sA,a,1|)┘x(i)=x(i)+1][126|[x(b)|p=p+c}?p

Nice round score of 128.
Explanation
dim x(126)      Create an array of 126 elements (one for each ASCII element)
[_l;||          Read cmd line input, loop over its length
i=asc(_sA,a,1|) Read the next char's ascii value
┘               (Syntactic linebreak)
x(i)=x(i)+1     Raise the count of this ASCII char by 1
]               NEXT
[126|           Loop over the ASCII array again
[x(b)|          Read the count and start a loop that runs from 1 to that count
p=p+c           Add to running total p the loop counter
}               Close both loops
?p              PRINT p

Ruby, score 63 60
Uses the -n flag which ends up adding 2 points due to the presence of another n within the code.
-3 points from Alexis Anderson.
i=x=0
gsub(/./){x+=$_[0,i+=1].count$&};p x

Try it online!

why not use a different variable than s since s is in gsub. It would save you 3 points, I believe.

@AlexisAndersen wow I can't believe I missed that

><> (Fish), score 133
!<01-0&i:2(:?&:?n?;&1+&:}}:3(00@@?.~~:{=&+&{$}8e+0.>.!06}~{

This code reads the input per character, adds a point and loops through all the read characters, adding an extra point for every equal character.
You can try it out here
Explanation
!<01-0&         // Initialize (put -1 on the stack and 0 in the register)
i:2(:?$:?n?;    // Read the next input. If it's -1, print the register and end the program.
&1+&            // Add one to the register
:}}:            // Duplicate both the input and the check value
3(00@@?.~~      // If the check value is -1, jump the instruction pointer to 0,0 (line 0)
:{=&+&          // Compare the input to the check value and add the result to the register
{$}8e+0.        // Move the checked value to the bottom of the stack and jump to 22,0 (line 4)
>.!06}~{        // Clean up the stack and jump to 0,6 (line 2)

CJam, score 18
q_,{)W$<}%.e=0+:+

Try it online!
Explanation
q                  e# Read the input.
 _,                e# Copy it, get its length.
   {               e# Map over the range from 0 .. length-1:
    )              e#  Increment the current number.
     W$            e#  Push the input.
       <           e#  Get the first <current number> characters of it.
        }%         e# (end map)
          .e=      e# Count the occurrences of each character in the corresponding slice.
             0+    e# Append a 0 to the result (because you can't reduce and empty list).
               :+  e# Reduce by addition (sum).

You can replace 0+:+ with 1b (convert from base 1, which handles empty list and doesn't have the duplicated character), which gets you a score of 15.

Swift 3, 153 bytes, score = 637
var u:(String)->Int={var d = Dictionary<Character,Int>()
for c in $0.characters{d[c] = (d[c] ?? 0) + 1}
return d.values.reduce(0,{$0 + $1 * ($1 + 1) / 2})}

Legible version plus explanation
func unique(_ string: String) -> Int {
    var dict = Dictionary<Character, Int>()
    for char in string.characters { dict[char] = (dict[char] ?? 0) + 1 }
    return dict.values.reduce(0, { $0 + $1 * ($1 + 1) / 2 })
}

My solution takes the string, iterates over the characters and tracks each unique character in a dictionary, counting the occurrences per character. Once that's done, it reduces the dictionary's values using the triangle number formula ( n(n+1) / 2 ) and returns the result.
Comments
Swift obviously isn't the best language for golfing, but it was fun to see where I could save bytes despite its rigid syntax. This is my first Swift submission - be gentle!

Python 2, score 108
lambda S:sum(S.count(Q)*(S.count(Q)+1)/2for Q in set(S))

Still golfing :)

I think you missed the scoring system.

@LeakyNun Oh shoot you're right –– and that was fast

S.count(Q)*(S.count(Q)+1)/2for Q in set(S) should be the same as (S.count(Q)+1)/2for Q in S

Factor, 2435
(o god my score)
"" over [ 2dup swap in? [ drop ] [ suffix ] if ] each { } swap swapd [ dupd 0 swap swapd swap [ over = swap [ [ 1 + ] [ ] if ] dip ] each drop swap [ suffix ] dip ] each drop [ dup 1 + * 2 / ] map sum
(wrong formatting on purpose for multi-line span)
Wow, Factor is hard. Or I'm just bad. Probably a little bit of both.

Could you tell me what needs to be added in order to test this code on Try it online?

@Laikoni add the string to the beginning of the code. So, for abaacab, the code will read "abaacab" "" over [ 2dup ...

@Laikoni Come to think of it, you'd have to add USING: kernel sequences sets math ; to the beginning, too, (they're libraries). Also, it's working on my local machine but not on TIO, and IDK why. Never used Factor on TIO.

 JavaScript, 49 bytes, score 88
b={};s=0;for(j in a=prompt())s+=b[a[j]]=-~b[a[j]]

The score of each submission is not the byte count, but the cost of the submission, that is the program run on its own source code. This means your score is 88 instead of 49.

Pyt, 6 bytes
ĐỤ⇹ɔ△Ʃ

Explanation:
              Implicit input
Đ             Duplicate top of stack
 Ụ            Get unique characters
  ⇹           Swap top two items on stack
   ɔ          Count number of times each unique character occurs in the input
    △         Calculates the total score for each character
     Ʃ        Sum count
              Implicit output

Try it online!

Factor + grouping.extras math.unicode, score: 104
[ head-clump
[ dup
last '[
_ =
] count
] map
Σ ]

Try it online!
The whitespace is a killer. In order to lessen its impact, I alternate between spaces and newlines. Tabs aren't allowed in TIO's build of Factor or I would have used them too.


text:
Convert a TIO answer to a CMC answer
Let's for once do something useful.
Given the text from a Try It Online codegolf submission, produce the equivalent Chat Mini Challenge submission, which is of the form
Language, N bytes: [`code`](URL)

or (if submission is a single byte – TIO will add a trailing s on the first line only if needed)
Language, 1 byte: [`code`](URL)

You may assume that the submission

has only one line
does not contain backticks (`)
has no leading whitespace
has a regular format like in the examples below; the code line is indented with four spaces ( ), not with HTML tags (
…
), i.e. no trailing whitespace.

Note that the submission may have a syntax highlighting tag. See last example.
You may optionally include the title text, i.e. …url "Language - Try It Online".
Examples
Given
# [05AB1E], 1 byte

    Ô

[Try it online!][TIO-j3v72bss]

[05AB1E]: https://github.com/Adriandmen/05AB1E
[TIO-j3v72bss]: https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA "05AB1E – Try It Online"

return
05AB1E, 1 byte: [`Ô`](https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA)

or
05AB1E, 1 byte: [`Ô`](https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA "05AB1E – Try It Online")

Given
# [Brachylog], 4 bytes

    ḅhᵐc

[Try it online!][TIO-j3v75978]

[Brachylog]: https://github.com/JCumin/Brachylog
[TIO-j3v75978]: https://tio.run/##SypKTM6ozMlPN/r//@GO1oyHWyck//@vlJGampOTDwZK/6MA "Brachylog – Try It Online"

return
Brachylog, 4 bytes: [`ḅhᵐc`](https://tio.run/##SypKTM6ozMlPN/r//@GO1oyHWyck//@vlJGampOTDwZK/6MA)

Given
# [APL (Dyalog Unicode)], 15 bytes

    ⍴⍨¨⍳

[Try it online!][TIO-j44jgrps]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-j44jgrps]: https://tio.run/##AScA2P9hcGwtZHlhbG9n//9m4oaQ4o204o2owqjijbP//zcxNjDijLZmIDQ "APL (Dyalog Unicode) – Try It Online"

return
APL (Dyalog Unicode), 15 bytes: [`⍴⍨¨⍳`](https://tio.run/##AScA2P9hcGwtZHlhbG9n//9m4oaQ4o204o2owqjijbP//zcxNjDijLZmIDQ)

Can we assume the language name does not contain a ]?

No language name on TIO has ] though.

True, I guess. May we assume the answer does not have any leading whitespace?

@ETHproductions Yes, because otherwise the backticks won't work. I'll edit.

@ais523 I think the 4th assumption already listed covers the secondary output format.

@ais523 the first issues is dealt with as ETHproductions notes. The syntax highlighting, hm, I guess it should.

Code golf is useful ಠ_ಠ

@Adám I somehow missed that

V, 37, 35 bytes
ç^</dj
H3xf]x3Ji[`A`]Jd2/:
xr(A)

Try it online!

I tried using the surround plugin that's sort of bundled with V, but it kept trimming whitespace off the end, which I think disqualifies it.

Can I bother you to add support for the syntax highlighting tag?

@nmjcman101 Umm, I think you can assume trailing whitespace doesn't exist.

@Adám Well, that kinda seems like pointlessly changing the spec in the middle, but I guess I can support it.

@DJMcMayhem Well, it was in sandbox for a while. And no-one thought of that. I wouldn't have made the change if it wasn't for the actual use value of these submissions. Sorry about that. Have some ice cream:

@DJMcMayhem I just did ds[ for the language brackets and then tried ys$[ for the actual code oneliner.  I think that ys$] will skip adding extra whitespace, and you should be able to do `ys$`` to surround with backticks also

@nmjcman101 Yeah, I did know about the difference between ys$[ and ys$], but since we're surrounding it with backticks and brackets, it's actually shorter to just put them in manually.

Could you use d/    instead of ç^</dj for both 2 bytes and back to Vim compatibility? Try it online!

Python 3, 113 103 98 91 bytes
-1 byte thanks to Value Ink.
If you can, I could totally use some help with the regex. ><
lambda s:re.sub('(?s)# .(.*)](.*?)\n.* {4}(.*?)\n.+: (.*)',r'\1\2: [`\3`](\4)',s)
import re

Try it online!

Can I bother you to add support for the syntax highlighting tag?

Great, thanks. Sorry about that.

No need to use \s to match the code block part; replace it with a literal space character. Also the expected output doesn't have the "Language - Try It Online" segment, so you need to change your last group to (\S*) to match correctly, so the byte count comes out around the same.

Actually, it turns out you can keep that Try It Online part. In that case, changing \s to a space will save 1 byte.

Yup, I was the one who asked that question. ;)

This is late, but you can do <sp><sp>+ in place of <sp>{4} (-1 byte). Also, with Python 3.6, you can use (?s:...) to apply dot-all to only part of the regex (-2 bytes). Try it online!

Actually, even better: ditch the flag entirely and use [^\t] (with \t representing a literal tab character) when you need to match all characters including newlines: 86 bytes

Retina, 54 48 52 57 48 bytes
Saved 1 byte thanks to @MartinEnder, 1 byte thanks to @Riley
...(.+)[^@]+    (.+)[^@]+:
$1: [`$2`](
1`]

$
)

Try it online! This assumes there won't be an @ in the language name, which should be fine...

you could just replace ^# \[ with ^... I think

@MartinEnder Thanks, I think that works...

Can you skip the ^ and $? It should always match the whole string anyway.

@Riley That would fail if... oh shoot, mine does too...

This doesn't work if the code contains <space>", but I don't know if you need to handle that. I'm guessing you just noticed that to.

@Riley Yeah, fixed now. The ^ can be removed though AFAICT.

Can I bother you to add support for the syntax highlighting tag?

@Adám Ah sorry, fixed.

05AB1E, 50 bytes
']¡J¦¦¦|J|`‚ʒнðQ}`ðÛ|D`θ'"Êi\|ë\}θ#1èr"ÿ: [`ÿ`](ÿ)

Try it online!
Now supports syntax highlighting too!
н is replaced by 0è and θ is replaced by ®è since those aren't pulled to TIO yet.
I just wonder how to shorten ¦¦¦...

JavaScript (ES6), 73 bytes

f=
s=>s.replace(/...(.*)](.*)[^]+    (.*)[^]+: (.*) ".*/,"$1$2: [`$3`]($4)")
<textarea rows=8 cols=75 oninput=o.textContent=this.value==f(this.value)?``:f(this.value)></textarea>

The answer I was waiting for. Can this be made into a bookmarklet? Otherwise I'll just bookmark it.

@Adám alert(prompt().replace(...)) might work, if the prompt will let you paste multiple lines in some way (the regexp doesn't actually need the newlines to be present).

Hm, I get the unmodified post as result. Maybe we can inject your code into TIO…

I was also working on a similar solution, but I didn't know about [^] to match anything. I have learnt something new from your solution. Thanks!

MATLAB/Octave, 120 126 bytes
@(a)strjoin(regexprep(strsplit(a,'\n'),{'\[.+\]: (.+) ".+','^[\[<].+','# \[(.+)\](.+)','^ +'},{'`]($1)','','$1$2: [`',''}),'')

This should work. For MATLAB it won't work with Unicode characters though I don't think, mostly because MATLAB sucks when it comes to odd characters. However it will work with Unicode for Octave, or at least TIO seems to be able to cope.
It should also handle submissions both with and without the <-- --> syntax highlighting.
Updates:

Added 4 bytes as I missed the @(a) when copying over
Added 2 bytes to add back ticks around the code in the output

Try it online!

Can this be run on TIO Octave?

@Adám it does indeed. I've updated the answer with TIO link.

Ruby, 85 bytes
->s{s[/.*/].gsub(/# .|\]/){}+": [`#{s[/(?<=  )\S.*/]}`](#{s=~/TIO-\w+.: (\S+)/;$1})"}

Try it online!

Python 2, 101 bytes
a=input().split('\n')
print'%s%s: [`%s`](%s)'%tuple(a[0][3:].split(']')+[a[-6][4:],a[-1].split()[1]])

Try it online! or Try all test cases

PHP, 92 bytes
<?=preg_filter("<...(.+)\](, \d+ \w+).* {4}(\S+).*: (\S+).*>s","$1$2: [`$3`]($4)",$_GET[0]);

Try it online!

Pip, 43 39 38 bytes
[a@>3DC']": [`"g@-6|>s"`]("(g@v^s1)')]

Try it online!
Takes the lines as separate command-line arguments. An example invocation could look like:
> pip.py -f convert.pip "# [05AB1E], 1 byte" "" "    Ô" "" "[Try it online!][TIO-j3v72bss]" "" "[05AB1E]: https://github.com/Adriandmen/05AB1E" "[TIO-j3v72bss]: https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA \"05AB1E – Try It Online\""

though actually this doesn't work for me because Windows cmd complains about the Ô... [inarticulate muttering]
--At any rate, it works on TIO. Or, use the -r flag and take input from lines of stdin instead.
Assumes that the language name will not contain ] (which would break the markdown anyway).
Explanation
                                        g is list of cmdline args; a is 1st arg;
                                        s is space; v is -1 (implicit)
[                                    ]  Build a list with these elements:
 a@>3                                    1st line, sans first three characters,
     DC']                                 with the ] character deleted
         ": [`"                          This string
               g@-6                      6th line from the end (the code)
                   |>s                    with leading spaces stripped
                      "`]("              This string
                            g@v          Last line (containing the URL)
                               ^s         split on spaces
                           (     1)       get element at index 1
                                   ')    This character
                                        By default, the list is concatenated and printed

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
All non-ordered pairs between the elements of an array
Task:
Return an array with all possible pairs between the elements of an array.
Example
From a=["a", "b", "c", "d"]; return b=[["a","b"],["a","c"],["a","d"],["b","c"],["b","d"],["c","d"]].
Pairs can be in any order as long as all possible combinations are included and obviously ["b","d"] is the same to ["d","b"].
Input
Array of unique string elements composed of chars from the class [a-z].
Output
2d array containing all the possible pairs of input array's elements.
Test Cases
input=["a","b","c"];
//output=[["a","b"],["a","c"],["b","c"]]

input=["a","b","c","d","e"];
//output=[["a","b"],["a","c"],["a","d"],["a","e"],["b","c"],["b","d"],["b","e"],["c","d"],["c","e"],["d","e"]]

Note: I could not find a duplicate to this challenge. If there is one, alert me with a comment to drop question.

I'm not clear on what happens when input values repeat or are not in sorted order. Some more general test cases would help there.

@Adám Not a dupe, that involves having 2 lists.

This problem excludes pairing an element with itself, soeven more nonduplicate.

@xnor havent thought about repeating values because my original problem at work had to do with a unique set of individuals. I guess I should add uniqueness as a condition?

@alexandros84 Uniqueness would be fine. What should ["c","b","a"] return?

@xnor, the same (or not) with ["a","b","c"], in that order of pairs does not matter. This is why I included the wording "non-ordered" in title (this is not legit lingo but impro from my part).

Edited input for uniqueness. Looks much better now.

Jelly, 2 bytes
Œc

Try it online!

You ninja'd me - pretty print the output using something like ÇK€Y in the footer.

@JonathanAllan Oh, thanks!

Haskell, 29 bytes
f(a:b)=map((,)a)b++f b
f _=[]

Try it online! Example usage: f ["a","b","c"] yields [("a","b"),("a","c"),("b","c")].

With the flag -XTupleSections this can be shortened to 27 bytes, however the flag would need to be counted:
f(a:b)=map(a,)b++f b
f _=[]

Try it online!

I think you can save one byte by modifying the be case to f l=l.

@Kritzefitz I'm afraid this won't work as the two empty lists have a different type, so Haskell's type checker will complain.

Good point. I Didn't think of that.

Mathematica, 14 bytes
#~Subsets~{2}&

input

[{"a", "b", "c"}]

I was going to do that :(

Haskell, 25 bytes
f l=[(x,y)|x<-l,y<-l,x<y]

Try it online!
Outer (x) and inner (y) loop through the input list and keep the pair (x,y) only if x < y.

vim, 50 48
AX<esc>qqYplX@qq@qqrYpllDkxh@rq:g/./norm@r<cr>:g/X/d<cr>dG

Takes input in the form
abcd

and outputs as
ad
ac
ab
bd
bc
cd

Explanation
First, AX<esc> appends an X to the input in order to handle 2-length input, which is necessary for reasons that will become clear shortly.
Then comes the first recursive macro, of the form qq...@qq@q. (Record macro q, run itself again at the end, end the recording, then run itself once.) In the body of the macro, Yp duplicates the current line, l breaks out of the macro if the line is now one character long, and X deletes the first character in the line. This has the end result of producing
abcdX
abcX
abX
aX
X
X

Ignoring the Xs for now, all we have to do is turn abcdX, for example, into ab / ac / ad / aX. This is achieved with the second recursive macro, qr...@rq.
In this macro, we first duplicate the line (Yp), then delete everything but the first two characters by moving right two (ll) and deleting to the end of the line (D). Since the cursor is now on the second charcater of the line, kx will delete the second character from the previous line, which happens to be the one that was just paired with the first character on the line. This process is then repeated starting again from the beginning of the line (h) as many times as necessary due to the recursive nature of the macro.
It's now just a matter of running the macro on every line, which can be achieved with :g/./norm@r (I'm not sure why this behaves differently than :%norm@r, but suffice to say, the latter does not work as intended.) Lines with X are deleted with :g/X/d, and the blank lines at the end left as a result of the construction of the r macro are cleaned up with dG.

Great answer. Will take time for me to go through it.

Brachylog, 5 bytes
{⊇Ċ}ᶠ

Try it online!
How it works
{⊇Ċ}ᶠ
    ᶠ   find all the possible outputs of the following predicate
 ⊇          the output is an ordered subset of the input
  Ċ         the output is a list with two elements

05AB1E, 3 bytes
Code:
æ2ù

Uses the 05AB1E encoding. Try it online!
Explanation:
æ      # Powerset of the input
 2ù    # Keep the items of length two

Octave, 23 bytes
@(s)[nchoosek(+s,2) '']

Try it online!

Python 3, 44 bytes
f=lambda k,*s:[*s]and[[k,x]for x in s]+f(*s)

Try it online!
Takes input as individual function parameters.

Octave, 49 48 bytes
@(x)[imag(y=(y=triu(x+j*x',1))(~~y)) real(y) '']

Anonymous function that avoids the built-in (nchoosek).
Try it online!
Explanation
x+j*x' uses broadcasting to build a matrix of complex numbers where the real and imaginary parts are all pairs of code points from the input x.
y=triu(...,1) keeps the upper triangular part excluding the diagonal, making the rest of elements zero. The result is assigned to variable y.
y=(...)(~~y) retains the nonzero elements in the form of a column vector, which is assigned to variable y.
imag(...) and real(...) extract the real and imaginary parts.
[... ... ''] converts back to char to build the output.

Nice! The whole challenge is really interesting. It took me about one hour and a half to come up with my es5 code (featured below). I am happy it generated so many interesting answers..

Python, 53 bytes
2 bytes saved thanks to @CalculatorFeline
lambda a:[(x,y)for i,x in enumerate(a)for y in a[:i]]

Try it online!

a[i+1:] can be a[:i]

Having a long username makes short comments easy by simply mentioning the aforementioned user.

R, 18 bytes
combn(scan(,''),2)

reads the list from stdin, returns a matrix where the columns are pairs.
Try it online!

Perl 6, 17 bytes
*.combinations(2)

Whew, that's a long method name.

Pari/GP, 34 bytes
a->concat([[[x,y]|y<-a,x<y]|x<-a])

Try it online!

Octave, 38 bytes
@(s)s([[x y]=find(s|s'),y](y<x,[2 1]))

Another answer to avoid nchoosek built-in.
Try it online!

Arturo, 18 bytes
$=>[combine.by:2&]

Try it

Python ≥ 2.7, 55 bytes
lambda l:list(combinations(l,2))
from itertools import*

repl.it!

Javascript (ES 5), from 108 to 78 bytes
I post my answer today but I obviously promise to not accept my own answer:
x=input;
a=[];

for(n=0;n<(x.length-1);n++){for(i=n+1;i<(x.length);i++){a.push([x[n],x[i]]);}}

Welcome to PPCG; we expect submissions to be golfed, including removing unnecessary whitespace

Ty. I was wondering also this: should I have included the x=input; a=[]; in my answer or not? I ll edit tomorrow.

You can either just submit a function or do a full program. Since you use a, you need to define it, but you can make a function of x.

much better now @HyperNeutrino.

I think you can exclude some semicolons and the empty line to save some space. I also think you can change for(i=n+1;i<(x.length);i++) to for(i=n;++i<x.length;). Likewise, you can change n<(x.length-1);n++ to n++<x.length-1

Pyth, 7 4 bytes
 -3 bytes thanks to Leaky Nun!
.cQ2

Try it online!

.cQ2?

@LeakyNun I could have sworn there was a function that did exactly what this challenge needed, but I only saw .C when looking through the list. Nice catch!

Scala, 17 bytes
_.combinations(2)

Python, 74 bytes
f=lambda a:[(c,d) for i,c in enumerate(a) for j,d in enumerate(a) if i<j]

Welcome to PPCG! You can golf this: 1) replace 2-char variable names with 1-char 2) remove unnecessary whitespace 3) this is a snippet, you need to make it into a lambda, function or full program

Golfing off 10 bytes: 64 bytes

Japt, 2 bytes
à2

Test it (-Q flag for visualisation purposes only)

Python, 64 bytes
f=lambda a:sum((list(zip(a, a[i:]))for i in range(1,len(a))),[])

Ruby, 38 34 24 bytes
->x{[*x.combination(2)]}

Thanks Seims for the idea that saved 10 bytes.
Try it online!

->x{x.combination(2).to_a} saves some bytes :)

Clojure, 42 bytes
#(set(for[i % j(remove #{i}%)](set[i j])))

Returns a set of sets :)

J, 17 bytes
({~$#:I.@,)#\</#\

Try it online!
Explanation
({~$#:I.@,)#\</#\  Input: string S
               #\  Get the length of each prefix of S
           #\      Get the length of each prefix of S again
             </    Test using greater than (<) between each
         ,         Flatten
      I.@          Find the indices where the value is 1
   $               Shape of that table
    #:             Convert the indices to the base represented by the shape
 {~                Index into S at those values

Pip, -p 4 bytes
aCB2

CB is the operator for combinations, not much explanation needed
Try It Online!

Go, 132 bytes
func f[T any](S[]T)(O[][]T){if len(S)<3{O=append(O,S)}else{for a,i:=range(S){for _,j:=range(S[a+1:]){O=append(O,[]T{i,j})}}}
return}

Attempt This Online!
A generic function that takes in a slice of type T and outputs a slice of slices of type T.
A solution that does only []string -> [][]string is 8 bytes longer.
Explanation
func f[T any](S[]T)(O[][]T){  // boilerplate
if len(S)<3{                  // if the input length < 3,
  O=append(O,S)               // just return the input
}else{                        // otherwise,
  for a,i:=range(S){          // for each 1st element,
    for _,j:=range(S[a+1:]){  // and each 2nd element,
      O=append(O,[]T{i,j})}}} // add the pair
return}                       // return the result

JavaScript ES6, 52 bytes
a=>a.map((x,i)=>a.slice(0,i).map(y=>[x,y])).slice(1)

If there was like a flatMap that would save a lot of bytes.

Hey nice answer! check out my es5 answer while I study yours if u want. any feedback will be appreciated (positive/constructive haha)

Firefox 30's array comprehensions can simulate a flat map, e.g. a=>[for(x of[...a])for(y of(a.shift(),a))[x,y]].

@Neil, some really advanced syntax there... I d have to google at least three things to start understanding your expression. Namely the spread operator, what is array comprehensions and what is the [x,y] in the end (still havent found answer to that).

@alexandros84 The [x,y] at the end is the easy bit, it's just an array literal.

Also the spread operator is only there to copy the array, since I'm mutating it inside the loop.

@Neil it took me like one hour and a half to find my solution to my own challenge (earlier today for a problem at work-- my code is the last answer here). Still have lots to learn about js, especially now that es6 is becoming widespread.

The output seems to be wrapped inside an extra layer of [ ]?

@Neil I ve entered your expression inside babeljs.io online tool and for some reason I get unexpected token. I ve learned a lot from your contribution and I am really grateful for it, but why is this happening? Hey wait... I think I found out why: (from mdn on array comprehensions) "Specifications: Was initially in the ECMAScript 2015 draft, but got removed in revision 27 (August 2014). Please see older revisions of ES2015 for specification semantics."

Python, 55 bytes
f=lambda s:[(s[0],j)for j in s[1:]]+f(s[1:])if s else[]

Try it online!
Longer than other Python answers, but it uses a different technique so I think it's worth posting.

Dont have time to check, I hope is really different technique cause I ve upvoted.

I think this is a very similar approach to @ovs's Python 3 answer.

Nibbles, 1.5 bytes
`_~

Attempt This Online!

Thunno, \$ 3 \log_{256}(96) \approx \$ 2.47 bytes
2zQ

Attempt This Online!
Almost a built-in. zQ is "combinations of b with length a".

Vyxal, 2 bytes
2ḋ

Try it Online!
Almost a built-in. ḋ is the built-in for "combinations of a with length b"

Curry (PAKCS), 20 bytes
f(_++x:_++y:_)=[x,y]

Attempt This Online!

I learning Curry now and like it very much. But is there some prime numbers built in, can you help me?

@lesobrod There isn't such built-in in Prelude or the base library. I can't even find any package for number theory in the CPM Repository.

@lesobrod By the way, you can claim this bounty for your first Curry answer.

Thank you! I'll try. And may be will try to make some primes generator in Smap

Thunno 2, 2 bytes
2ċ

Try it online!
ċ = "all combinations of b with length a"

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/