A. Repeating Cipher

Polycarp loves ciphers. He has invented his own cipher called repeating.

Repeating cipher is used for strings. To encrypt the string s=s1s2…sm (1≤m≤10), Polycarp uses the following algorithm:

he writes down s1 ones,
he writes down s2 twice,
he writes down s3 three times,

he writes down sm m times.
For example, if s=“bab” the process is: “b” → “baa” → “baabbb”. So the encrypted s=“bab” is “baabbb”.

Given string t — the result of encryption of some string s. Your task is to decrypt it, i. e. find the string s.

Input
The first line contains integer n (1≤n≤55) — the length of the encrypted string. The second line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is exactly n.

It is guaranteed that the answer to the test exists.

Output
Print such string s that after encryption it equals t.

Examples
input
6
baabbb
output
bab
input
10
ooopppssss
output
oops
input
1
z
output
z

题意:
给你一段加密的字符串,加密是如果未加密的是s=“bab” 则加密过程是: “b” → “baa” → “baabbb”. 给你baabbb 让你求出是bab;

解题思路:

“b” → “baa” → “baabbb”.
规律是 第一次 a 复制一次 第二次 b复制两次 则 k次 复制k次;
简单模拟一下即可

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
const int MM=1e5+5;
int n;
char s[MM];
int a[MM];
int main()
{
    int t;
    scanf("%d",&t);
    scanf("%s",s);
    int k=0;
    for(int i=0;i<t;)//
    {
        k++;//用来输出我们需要的字符
        cout<<s[i];
        i+=k;//删去第i次复制了i次的字符;
    }
    cout<<endl;
    return 0;
}

B. Array Stabilization
You are given an array a consisting of n integer numbers.

Let instability of the array be the following value: maxi=1nai−mini=1nai.

You have to remove exactly one element from this array to minimize instability of the resulting (n−1)-elements array. Your task is to calculate the minimum possible instability.

Input
The first line of the input contains one integer n (2≤n≤105) — the number of elements in the array a.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤105) — elements of the array a.

Output
Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array a.

Examples
input
4
1 3 3 7
output
2
input
2
1 100000
output
0
Note
In the first example you can remove 7 then instability of the remaining array will be 3−1=2.

In the second example you can remove either 1 or 100000 then instability of the remaining array will be 100000−100000=0 and 1−1=0 correspondingly.

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
const int MM=1e5+5;
int n;
int a[MM<<1];
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d",&a[i]);
    }
    if(t>2){
    sort(a,a+t);
    int sum=a[t-2]-a[0];
    int minn=a[t-1]-a[1];
    cout<<min(sum,minn);
    }
    else
        cout<<"0"<<endl;
    return 0;
}