http://codeforces.com/problemset/problem/1144/D

You are given an array aa consisting of nn integers. You can perform the following operations arbitrary number of times (possibly, zero):

  1. Choose a pair of indices (i,j)(i,j) such that |i−j|=1|i−j|=1 (indices ii and jj are adjacent) and set ai:=ai+|ai−aj|ai:=ai+|ai−aj| ;
  2. Choose a pair of indices (i,j)(i,j) such that |i−j|=1|i−j|=1 (indices ii and jj are adjacent) and set ai:=ai−|ai−aj|ai:=ai−|ai−aj| .

The value |x||x| means the absolute value of xx . For example, |4|=4|4|=4 , |−3|=3|−3|=3 .

Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it.

It is guaranteed that you always can obtain the array of equal elements using such operations.

Note that after each operation each element of the current array should not exceed 10181018 by absolute value.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105 ) — the number of elements in aa .

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤2⋅1050≤ai≤2⋅105 ), where aiai is the ii -th element of aa .

Output

In the first line print one integer kk — the minimum number of operations required to obtain the array of equal elements.

In the next kk lines print operations itself. The pp -th operation should be printed as a triple of integers (tp,ip,jp)(tp,ip,jp) , where tptp is either 11 or 22 (11 means that you perform the operation of the first type, and 22 means that you perform the operation of the second type), and ipip and jpjp are indices of adjacent elements of the array such that 1≤ip,jp≤n1≤ip,jp≤n , |ip−jp|=1|ip−jp|=1 . See the examples for better understanding.

Note that after each operation each element of the current array should not exceed 10181018 by absolute value.

If there are many possible answers, you can print any.

Examples

Input

5
2 4 6 6 6

Output

2
1 2 3
1 1 2

Input

3
2 8 10

Output

2
2 2 1
2 3 2

Input

4
1 1 1 1

Output

0

题目大意:给一个序列,通过两种操作,最后使得序列的所有数都相等,求最少的操作次数。

思路: 两种操作分ai>aj和ai<aj两种情况进行化简,就会发现两种操作可以让一个数与其相邻的数相等。(看ai 和aj的大小 决定使用哪种操作)那么问题就简单了,手边遍历一遍求出众数,并存储其位置,然后扫描一遍就行了。(利用存储的位置 向左或向右扫描)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;int a[200005];
int vis[200005];
vector<int> vec;
int MAX=0;
int n;int main()
{int v;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(++vis[a[i]]>MAX){MAX=vis[a[i]];v=a[i];}}if(MAX==n)printf("0\n");else{printf("%d\n",n-MAX);for(int i=1;i<=n;i++)if(a[i]==v)vec.push_back(i);int b=vec[0]-1;while(b>=1){if(a[b]>v)printf("2 %d %d\n",b,b+1);elseprintf("1 %d %d\n",b,b+1);--b;}for(int i=1;i<vec.size();i++){for(int j=vec[i]-1;j>vec[i-1];j--){if(a[j]>v)printf("2 %d %d\n",j,j+1);elseprintf("1 %d %d\n",j,j+1);}}b=vec[vec.size()-1]+1;while(b<=n){if(a[b]>v)printf("2 %d %d\n",b,b-1);elseprintf("1 %d %d\n",b,b-1);++b;}}return 0;
}

Codeforces 1144 D相关推荐

  1. 【CodeForces Round #550】A-F | 模拟 | 贪心 | 高精 | BFS | 二分图 | E

    今年怎么没有愚人节比赛了   CF你看看人家洛谷   唉鸭原来那边还没到愚人节呢- 愚人节比赛还是有的,在今晚 qwq [CodeForces 1144   A-F] Tags:模拟 贪心 BFS 高 ...

  2. Codeforces Contest 1144 E Median String —— 水题

    This way 题意: 给你两个字符串,问你字典序在这两个字符串正中间的字符串是什么 题解: 好几个星期没做题目了,连1900都想了一段时间,一开始想着用2进制来做,但是想着想着发现直接用2进制做不 ...

  3. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  4. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  5. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  6. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  7. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  8. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  9. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

最新文章

  1. TCMalloc(Thread-Caching malloc) 基本设计原理
  2. 三步走——带你打造一份完美的数据科学家简历|(附件有PPT福利)
  3. C# WINFORM的自动更新程序
  4. RabbitMQ系列教程之三:发布\/订阅(Publish\/Subscribe)
  5. cad转dxf格式文件太大_想知道DWG、DWT、DWS和DXF是什么吗?从了解4种CAD图形格式开始吧...
  6. SQL语言入坑—1.数据的检索、排序、过滤、分组
  7. 一种基于复制粘贴的cam350邮票孔拼版教程(一)
  8. JS基础-DOM增删改-尚硅谷视频p103
  9. iPhone 开发常用工具
  10. 你还没掌握超表「视图」, 难怪觉得数据繁杂得要命!
  11. 2022年春招美团二面总结 凉经
  12. C语言中三个数比较大小详解——三种方法
  13. 【经验分享】58个硬件工程师基础知识面试题
  14. linux魔兽世界黑屏,在UBUNTU下玩魔兽世界并不轻松。许多问题无法自己解决,请有兴趣的...
  15. 计算机属性显示缩略图 桌面样式变了,Win7任务栏缩略图预览变成列表预览怎么解决?...
  16. hive行转列的高级用法later view explode
  17. Node.js躬行记(18)——半吊子的可视化搭建系统
  18. 华清远见上海中心22071班 9.30作业
  19. 各大银行ATM跨行取款收费一览表 程序员的切身利益 不得不看啊
  20. 机器学习储备(12):二项分布的例子解析

热门文章

  1. 告诉你猪身上最香的部位是什么?五花肉不是最香
  2. 金龄会为中老年群体搭建展现风采的舞台
  3. 学习记录——微信小程序查询的两种方法
  4. 金蝶K3 BOM独立控制跳层开关开发
  5. 《英雄联盟》源代码被黑客窃取!起价100万美元,拳头公司拒付赎金!
  6. 切换页面导致计时器停止,JS暂停!
  7. z390 黑苹果启动盘_黑苹果从入门到精通:K39小钢炮黑苹果实践
  8. git commit后回退方法
  9. Python:tkinter Canvas 删除/清理元素方法
  10. C++中的sort函数排序(快速排序)