Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.

Sonya has drawn nn numbers in a row, aiai is located in the ii-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.

Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.

For example, if the numbers [1,5,4,1,3][1,5,4,1,3] are written, and Sonya gives the number 11 to the first robot and the number 44 to the second one, the first robot will stop in the 11-st position while the second one in the 33-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 44 to the first robot and the number 55 to the second one, they will meet since the first robot will stop in the 33-rd position while the second one is in the 22-nd position.

Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.

Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (pp, qq), where she will give pp to the first robot and qq to the second one. Pairs (pipi, qiqi) and (pjpj, qjqj) are different if pi≠pjpi≠pj or qi≠qjqi≠qj.

Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of numbers in a row.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105) — the numbers in a row.

Output

Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.

Examples

Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7

Note

In the first example, Sonya can give pairs (11, 11), (11, 33), (11, 44), (11, 55), (44, 11), (44, 33), (55, 11), (55, 33), and (55, 44).

In the second example, Sonya can give pairs (11, 11), (11, 22), (11, 33), (22, 11), (22, 22), (22, 33), and (33, 22).

  一般的暴力思想是两重循环,从序列中的第一个数开始,判度这个数之后有几个不重复的数。这样会超时。

  利用 STL 中的 set 来简化暴力,首先将从计算第一个数可以和哪些数进行匹配,改为从最后一个数开始计算。

  表达能力有限,解释不清楚,还是看代码吧。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; LL con[];
LL init[];
LL check[];
set< LL > qq;
int main()
{
LL n,i,p,j;
LL ans=;
scanf("%lld",&n);
for(i=;i<=n;i++)
{
scanf("%lld",&init[i]);
con[init[i]]=qq.size();
qq.insert(init[i]);
}
for(i=;i<=n;i++)
{
//printf("%d ",con[init[i]]);
if(check[init[i]]!=-)
{
ans+=con[init[i]];
check[init[i]]=-;
}
else
;
}
printf("%lld\n",ans);
return ;
}

CodeForces - 1004C的更多相关文章

  1. Sonya and Robots(CodeForces 1004C)

    Since Sonya is interested in robotics too, she decided to construct robots that will read and recogn ...

  2. Sonya and Robots CodeForces - 1004C (思维题)

    Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input: standard in ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. [BinaryTree] 二叉树常考知识点

    1.二叉树第i层至多有2^(i-1)个结点(i>=1). 2.深度为k的二叉树上,至多含2^k-1个结点(k>=1) 3.n0 = n2 + 1(度) 4.满二叉树:深度为k且含有2^k- ...

  2. python3判断字典、列表、元组为空以及字典是否存在某个key的方法

    #!/usr/bin/python3 #False,0,'',[],{},()都可以视为假 m1=[] m2={} m3=() m4={"name":1,"age&quo ...

  3. [LeetCode] PathSum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  4. 【Linux笔记】CentOS yum 安装 vsftpd

    vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用,下面直接上干货. 一.安装vsftp 以管理员的身份使用yum命令安装vsftp: [root@localh ...

  5. HDU4055_Number String

    题目告诉你在一个排列中,相邻两个数的大小关系.问你排列可能有多少种情况. DP. f[i][j]表示将i个数按照前面i-1个大小关系排列且最后一个数位j的排列数有多少个. 这样对于新加入的一个数i+1 ...

  6. jquery 集合注意点

  7. noip模拟题《序》sort

    [问题背景]      zhx 给他的妹子们排序.[问题描述]      zhx有N个妹子,他对第i个妹子的好感度为ai, 且所有ai两两不相等.现在N个妹子随意站成一 排,他要将她们根据好感度从小到 ...

  8. MySQL复制 -- 应用场景

    本文行文路径如下: 什么是复制?复制是怎么工作的?复制有哪几种表现形式?复制能解决那些问题?业界有哪些数据同步解决方案? 什么是复制? 官方解释道:Replication enables data f ...

  9. wp开发(三)--赚取收益篇

    App开发完毕了,是否有赚取收益的想法呢?下面很浅显地介绍两种常用赚取收益的方法. 一. 收费 在发布应用时,可以对应用进行定价,发布到商城之后,用户付费才可以下载,当然也可以提供试用版.收益状况可以 ...

  10. 【BZOJ3437】小P的牧场(动态规划,斜率优化)

    [BZOJ3437]小P的牧场(动态规划,斜率优化) 题面 BZOJ 题解 考虑暴力\(dp\),设\(f[i]\)表示强制在\(i\)处建立控制站的并控制\([1..i]\)的最小代价. 很显然,枚 ...