Codeforces Round #525 (Div. 2) C

 

 

                                                                         C. Ehab and a 2-operation task

You're given an array aa of length nn. You can perform the following operations on it:

  • choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xx to all the elements in the prefix ending at ii.
  • choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.

Can you make the array strictly increasing in no more than n+1n+1 operations?

Input

The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.

The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.

Output

On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.

To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.

Examples

input

3
1 2 3

output

0

input

3
7 6 3

output

2
1 1 1
2 2 4

Note

In the first sample, the array is already increasing so we don't need any operations.

In the second sample:

In the first step: the array becomes [8,6,3][8,6,3].

In the second step: the array becomes [0,2,3][0,2,3].

 

题意:给定一个数组,要求只进行两种操作,[1, x, v]就是把元素下标小于等于x的都加上v,[2, x, v]把所有元素下标小于等于x的都对v取余。只需把原来无序的数组中所有的元素构造成  i + (n + 1),最后让所有元素对(n+1)取余即可。设 a_{i} 为原数组的值,x_{i}为该元素要加的值,则有 x_{i} = i + n + 1 - (a_{i} + cnt) mod (n + 1),cnt为每次i元素累加的值

 

#include<iostream>
#include<memory.h> 
#include<algorithm>
using namespace std;
const int maxn = 1e5+5;
int n; 
long long a[maxn];
int main()
{
	scanf("%d", &n);
	for(int i = 1;i <= n;i ++)
		scanf("%lld", &a[i]);
	long long cnt = 0;                //累计每次加的数值
	printf("%d\n", n + 1);
	for(int i = n;i >= 1;i --)
	{
		int x = i - ((a[i] + cnt) % (n + 1)) + n + 1;
		printf("1 %d %d\n", i, x);
		cnt += x;
	}
	printf("2 %d %d\n", n, n + 1);
	return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值