Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

#include<bits/stdc++.h>
using namespace std;

int main()
{
	//char  str[1000];
	int k,count;
    string str;
	cin>>str;
	 cin>>k;

   int value=str.length();

  int cnt=0;
	for(int i=97;i<123;i++)
	{  count=0;
		for(int j=0;j<value;j++)
		{
			if(str[j]==i)
				count++;
		}
   if(count>0)
   	cnt++;
	}
  if(k>value)
	{
		cout<<"impossible";
	}
    else if(k<=cnt)
    {
       cout<<"0";
    }
	else
	{    k=k-cnt;
		 cout<<k;
	}
}

[{'input': 'yandex\r\n6\r\n', 'output': ['0\r\n']}, {'input': 'yahoo\r\n5\r\n', 'output': ['1\r\n']}, {'input': 'google\r\n7\r\n', 'output': ['impossible\r\n']}, {'input': 'a\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'z\r\n2\r\n', 'output': ['impossible\r\n']}, {'input': 'fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\r\n26\r\n', 'output': ['14\r\n']}, {'input': 'nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\r\n26\r\n', 'output': ['12\r\n']}, {'input': 'a\r\n3\r\n', 'output': ['impossible\r\n']}, {'input': 'smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\r\n4\r\n', 'output': ['1\r\n']}, {'input': 'fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\r\n20\r\n', 'output': ['18\r\n']}, {'input': 'swmkwaruyv\r\n5\r\n', 'output': ['0\r\n']}, {'input': 'tnbqpsuhkczmejirvyfdolxwga\r\n22\r\n', 'output': ['0\r\n']}, {'input': 'abcde\r\n3\r\n', 'output': ['0\r\n']}, {'input': 'abb\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'aaaa\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'abcde\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'yandex\r\n4\r\n', 'output': ['0\r\n']}, {'input': 'aaabbbccc\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'abcd\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'asdfgh\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'aab\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'mynameissako\r\n5\r\n', 'output': ['0\r\n']}, {'input': 'abcde\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'abcd\r\n3\r\n', 'output': ['0\r\n']}, {'input': 'abcdef\r\n2\r\n', 'output': ['0\r\n']}, {'input': 'abcdefg\r\n4\r\n', 'output': ['0\r\n']}, {'input': 'abc\r\n1\r\n', 'output': ['0\r\n']}, {'input': 'asdafjsgljdllgjdgkl\r\n5\r\n', 'output': ['0\r\n']}, {'input': 'yaay\r\n3\r\n', 'output': ['1\r\n']}, {'input': 'yaay\r\n4\r\n', 'output': ['2\r\n']}, {'input': 'zzzzzz\r\n2\r\n', 'output': ['1\r\n']}]


Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:  "+ ri" — the reader with registration number ri entered the room;  "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Print a single integer — the minimum possible capacity of the reading room.

NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define mem(m,v) memset(m,v,sizeof(m))
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define all(x) (x.begin() ,  x.end() )
#define sz(x) x.size();
template<class t> inline void checkmax(t &a,t &b)
{if(b>a)a = b;}
template<class t> inline void checkmin(t &a,t &b)
{if(b<a)a = b;}
#define inf (int)1e9
#define eps LD(1e-9)
#define dinf LD(1e50)

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef pair<int,int> pii;
typedef double ld;
typedef vector<pii> vpii;
string s[1005];
int a[1005];
map <int ,int> m;
map<int,int> :: iterator it;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>s[i]>>a[i];
    int curr=0;
    int ans = 0;

    for(int i=0;i<n;i++) {
        if(s[i][0] == '+') {
            m[a[i]]++;
            if(curr == ans)
            {
                ans++;
                curr++;
            }
            else
                curr++;
        }
        else {
            if(m[a[i]]==0)
                ans++;
            else
            {
                m[a[i]]--;
                curr--;
            }
        }
    }
    cout<<ans;
    return 0;
}


Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.

The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot. The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.

Print the only integer d — the minimal number of steps to get the finish position.

NoteIn the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.

#include<bits/stdc++.h>
using namespace std;
int main(){
    int x1,y1;
    cin>>x1>>y1;
    int x2,y2;
    cin>>x2>>y2;
    int a=abs(x2-x1);
    int b=abs(y2-y1);
    if(a>=b){
        cout<<b+a-b<<endl;
    }
    else{
        cout<<a+b-a<<endl;
    }

}


There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hallWe know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

The first line of the input contains three integers n, a and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

NoteIn the first sample there are many other possible solutions. For example, 3 20 1and 2 13 0The following assignment 3 21 0is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 110;
int mtr[MAXN][MAXN];
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int disp = A * B - N;
    if (disp < 0) {
        cout << "-1\n";
        return 0;
    }
    int x_ = 1, y_ = 1, imp = 1, p = 2, cnt = 1;
    int NN = N;
    while (N) {
       // cout << "imp " << y_ << " " << x_ << " " << mtr[y_ - 1][x_] << '\n';
        if (mtr[y_ - 1][x_] == 0) {
            mtr[y_][x_] = min(imp, p);
            if (imp < p) imp += 2;
            else p += 2;
            N--;
        } else if (mtr[y_ - 1][x_]  % 2) {
            if (p <= NN) {
                mtr[y_][x_] = p;
                p += 2;
                N--;
            } else mtr[y_][x_] = 0;
        } else {
            if (imp <= NN) {
                mtr[y_][x_] = imp;
                imp += 2;
                N--;
            } else mtr[y_][x_] = 0;
        }
        x_++;
        x_ %= (B + 1);
        if (!x_) x_ = 1;
        if (x_ == 1) y_++;
    }
    int mats = 0;
    for (int i = 1; i <= A; ++i)
        for (int j = 1; j <= B; ++j) mats = max(mats, mtr[i][j]);
    if (NN != mats) {
        cout << "-1\n";
        return 0;
    }
    for (int i = 1; i <= A; ++i) {
        for (int j = 1; j <= B; ++j) cout << mtr[i][j] << " ";
        cout << '\n';
    }
    return 0;
}


Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples.Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.

The first line contains integers n, a, b (1 ≤ n ≤ 100; 1 ≤ a, b ≤ n) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains a distinct integers — the numbers of the apples Arthur likes. The next line contains b distinct integers — the numbers of the apples Alexander likes. Assume that the apples are numbered from 1 to n. The input is such that the answer exists.

Print n characters, each of them equals either 1 or 2. If the i-h character equals 1, then the i-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.

#include <bits/stdc++.h>

using namespace std;
#define ull unsigned long long

int main()
{
   int n,a,b;
   cin>>n>>a>>b;
   vector<int> va(a),vb(b);
   for(int i=0;i<a;i++) cin>>va[i];
   for(int i=0;i<b;i++) cin>>vb[i];
   sort(va.begin(),va.end());
   sort(vb.begin(),vb.end());
   vector<int> ans(n+1,-1);
   for(int i=0;i<a;i++)
   {
    //   cout<<va[i]<<endl;
       ans[va[i]] = 1;
   }
//   cout<<ans[1]<<endl;
   for(int i=1;i<=n;i++)
   {
       if(ans[i]==-1) ans[i] = 2;
   }
   for(int i=1;i<=n;i++)
   {
       cout<<ans[i]<<" ";
   }
    return 0;
}


"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).

The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).

Print the only number — the minimum number of changes needed to get the permutation.

NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2.

#include <iostream>
#include <vector>
using namespace std;

int main(void)
{
    int n, a;
    cin >> n;
    vector<bool> v(n, false);
    for (int i = 0; i != n; ++i)
    {
        cin >> a;
        if (a <= n)
            v[a-1] = true;
    }
    a = 0;
    for (int i = 0; i != n; ++i)
        a += v[i];
    cout << v.size() - a;
    return 0;
}


«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?

Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).

NoteIn the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int  k, l, m, n, d;
    cin >> k >> l >> m >> n >> d;
    int ans = d;

    for (int i = 1; i <= d; i++) {
        if (i%k != 0 && i%l != 0 && i%m != 0 && i%n != 0) ans--;
    }

    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("T.INP", "r")) {
        freopen("T.INP", "r", stdin);
        freopen("T.OUT", "w", stdout);
    }

    int tt = 1;
    // cin >> tt;
    while (tt--) solve();

}


An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int g[n][255]={0},g2[m][255]={0};
    char gc[n][m];
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {
        cin>>gc[i][j];
        g[i][gc[i][j]]++;
        g2[j][gc[i][j]]++;

    }
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {

        if(!(g[i][gc[i][j]]+g2[j][gc[i][j]]>2))
        cout<<gc[i][j];

    }
    return 0;
}

[{'input': '3 3\r\ncba\r\nbcd\r\ncbc\r\n', 'output': ['abcd']}, {'input': '5 5\r\nfcofd\r\nooedo\r\nafaoa\r\nrdcdf\r\neofsf\r\n', 'output': ['codeforces']}, {'input': '4 4\r\nusah\r\nusha\r\nhasu\r\nsuha\r\n', 'output': ['ahhasusu']}, {'input': '7 5\r\naabcd\r\neffgh\r\niijkk\r\nlmnoo\r\npqqrs\r\nttuvw\r\nxxyyz\r\n', 'output': ['bcdeghjlmnprsuvwz']}, {'input': '10 10\r\naaaaaaaaaa\r\nbccceeeeee\r\ncdfffffffe\r\ncdfiiiiile\r\ncdfjjjjile\r\ndddddddile\r\nedfkkkkile\r\nedddddddde\r\ngggggggggg\r\nhhhhhhhhhe\r\n', 'output': ['b']}, {'input': '15 3\r\njhg\r\njkn\r\njui\r\nfth\r\noij\r\nyuf\r\nyfb\r\nugd\r\nhgd\r\noih\r\nhvc\r\nugg\r\nyvv\r\ntdg\r\nhgf\r\n', 'output': ['hkniftjfbctd']}, {'input': '17 19\r\nbmzbmweyydiadtlcoue\r\ngmdbyfwurpwbpuvhifn\r\nuapwyndmhtqvkgkbhty\r\ntszotwflegsjzzszfwt\r\nzfpnscguemwrczqxyci\r\nvdqnkypnxnnpmuduhzn\r\noaquudhavrncwfwujpc\r\nmiggjmcmkkbnjfeodxk\r\ngjgwxtrxingiqquhuwq\r\nhdswxxrxuzzfhkplwun\r\nfagppcoildagktgdarv\r\neusjuqfistulgbglwmf\r\ngzrnyxryetwzhlnfewc\r\nzmnoozlqatugmdjwgzc\r\nfabbkoxyjxkatjmpprs\r\nwkdkobdagwdwxsufees\r\nrvncbszcepigpbzuzoo\r\n', 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': '1 1\r\na\r\n', 'output': ['a']}, {'input': '2 2\r\nzx\r\nxz\r\n', 'output': ['zxxz']}, {'input': '1 2\r\nfg\r\n', 'output': ['fg']}, {'input': '2 1\r\nh\r\nj\r\n', 'output': ['hj']}, {'input': '1 3\r\niji\r\n', 'output': ['j']}, {'input': '3 1\r\nk\r\np\r\nk\r\n', 'output': ['p']}, {'input': '2 3\r\nmhw\r\nbfq\r\n', 'output': ['mhwbfq']}, {'input': '3 2\r\nxe\r\ner\r\nwb\r\n', 'output': ['xeerwb']}, {'input': '3 7\r\nnutuvjg\r\ntgqutfn\r\nyfjeiot\r\n', 'output': ['ntvjggqfnyfjeiot']}, {'input': '5 4\r\nuzvs\r\namfz\r\nwypl\r\nxizp\r\nfhmf\r\n', 'output': ['uzvsamfzwyplxizphm']}, {'input': '8 9\r\ntjqrtgrem\r\nrwjcfuoey\r\nywrjgpzca\r\nwabzggojv\r\najqmmcclh\r\nozilebskd\r\nqmgnbmtcq\r\nwakptzkjr\r\n', 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': '9 3\r\njel\r\njws\r\ntab\r\nvyo\r\nkgm\r\npls\r\nabq\r\nbjx\r\nljt\r\n', 'output': ['elwtabvyokgmplabqbxlt']}, {'input': '7 6\r\neklgxi\r\nxmpzgf\r\nxvwcmr\r\nrqssed\r\nouiqpt\r\ndueiok\r\nbbuorv\r\n', 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': '14 27\r\npzoshpvvjdpmwfoeojapmkxjrnk\r\nitoojpcorxjdxrwyewtmmlhjxhx\r\ndoyopbwusgsmephixzcilxpskxh\r\nygpvepeuxjbnezdrnjfwdhjwjka\r\nrfjlbypoalbtjwrpjxzenmeipfg\r\nkhjhrtktcnajrnbefhpavxxfnlx\r\nvwlwumqpfegjgvoezevqsolaqhh\r\npdrvrtzqsoujqfeitkqgtxwckrl\r\nxtepjflcxcrfomhqimhimnzfxzg\r\nwhkfkfvvjwkmwhfgeovwowshyhw\r\nolchgmhiehumivswgtfyhqfagbp\r\ntdudrkttpkryvaiepsijuejqvmq\r\nmuratfqqdbfpefmhjzercortroh\r\nwxkebkzchupxumfizftgqvuwgau\r\n', 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': '1 100\r\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\r\n', 'output': ['g']}, {'input': '2 100\r\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\r\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\r\n', 'output': ['rbe']}, {'input': '3 100\r\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\r\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\r\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\r\n', 'output': ['blkck']}, {'input': '100 1\r\na\r\nm\r\nn\r\nh\r\na\r\nx\r\nt\r\na\r\no\r\np\r\nj\r\nz\r\nr\r\nk\r\nq\r\nl\r\nb\r\nr\r\no\r\ni\r\ny\r\ni\r\np\r\ni\r\nt\r\nn\r\nd\r\nc\r\nz\r\np\r\nu\r\nn\r\nw\r\ny\r\ng\r\ns\r\nt\r\nm\r\nz\r\ne\r\nv\r\ng\r\ny\r\nj\r\nd\r\nz\r\ny\r\na\r\nn\r\nx\r\nk\r\nd\r\nq\r\nn\r\nv\r\ng\r\nk\r\ni\r\nk\r\nf\r\na\r\nb\r\nw\r\no\r\nu\r\nw\r\nk\r\nk\r\nb\r\nz\r\nu\r\ni\r\nu\r\nv\r\ng\r\nv\r\nx\r\ng\r\np\r\ni\r\nz\r\ns\r\nv\r\nq\r\ns\r\nb\r\nw\r\ne\r\np\r\nk\r\nt\r\np\r\nd\r\nr\r\ng\r\nd\r\nk\r\nm\r\nf\r\nd\r\n', 'output': ['hlc']}, {'input': '100 2\r\nhd\r\ngx\r\nmz\r\nbq\r\nof\r\nst\r\nzc\r\ndg\r\nth\r\nba\r\new\r\nbw\r\noc\r\now\r\nvh\r\nqp\r\nin\r\neh\r\npj\r\nat\r\nnn\r\nbr\r\nij\r\nco\r\nlv\r\nsa\r\ntb\r\nbl\r\nsr\r\nxa\r\nbz\r\nrp\r\nsz\r\noi\r\nec\r\npw\r\nhf\r\njm\r\nwu\r\nhq\r\nra\r\npv\r\ntc\r\ngv\r\nik\r\nux\r\ntz\r\nbf\r\nty\r\ndk\r\nwo\r\nor\r\nza\r\nkv\r\nqt\r\nfa\r\njy\r\nbk\r\nuv\r\ngk\r\ncz\r\nds\r\nie\r\noq\r\nmf\r\nxn\r\nql\r\nxs\r\nfb\r\niv\r\ncj\r\nkn\r\nns\r\nlg\r\nji\r\nha\r\naj\r\ndg\r\nfj\r\nut\r\nsg\r\nju\r\noc\r\nov\r\nhe\r\nnw\r\nbl\r\nlp\r\nbx\r\nnm\r\nyq\r\ncw\r\nov\r\nxk\r\npg\r\noh\r\npl\r\nuo\r\ngf\r\nul\r\n', 'output': ['dvy']}, {'input': '100 3\r\nruy\r\nmye\r\njgp\r\nscn\r\nktq\r\nalx\r\nmvk\r\nlpm\r\nkry\r\norb\r\nmpu\r\nzcv\r\nlge\r\nkft\r\ndzp\r\ntfb\r\nhqz\r\nuur\r\nhry\r\nzjx\r\ncuo\r\nqqc\r\ntih\r\nenj\r\nvnp\r\nbwi\r\nzzh\r\nhkc\r\nwdr\r\nldh\r\nvel\r\nizj\r\nfhb\r\nqrn\r\nqpp\r\nvzs\r\nlhg\r\nkee\r\nlbq\r\nzhy\r\nwcl\r\nyaa\r\nton\r\nfly\r\nkyw\r\nept\r\ngwq\r\ncoe\r\nopd\r\neez\r\nnmx\r\nnjg\r\nwhy\r\nvel\r\nafq\r\nnbq\r\nulx\r\noxs\r\nbbo\r\nyhx\r\nfmz\r\nnrg\r\nnfm\r\njek\r\nbeu\r\ntya\r\nxgs\r\nsgg\r\nnkq\r\nbbv\r\nwkd\r\ntns\r\nfdt\r\neox\r\nobc\r\neab\r\nkkj\r\noub\r\ngji\r\nrht\r\nozv\r\nysk\r\nsbt\r\nflf\r\npbu\r\nlxb\r\npzs\r\nrzh\r\ncea\r\nkmi\r\nuea\r\nncc\r\nzng\r\nvkn\r\njhn\r\njqw\r\nlqc\r\nmbt\r\nlov\r\ngam\r\n', 'output': ['tvdiixs']}]


A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

NoteIn the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

#include <iostream>
#include <fstream>
#include <cstdio>
#include <math.h>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <vector>
using namespace std;
#define fname ""
#define ull unsigned long long
#define ll long long
#define INF 1000*1000*1000

int n, x, y, m, i, a[1001], j, mn = INF;
bool was[1001][1001];

int main () {
  #ifndef ONLINE_JUDGE
    freopen ("a.in", "r", stdin);
    freopen ("a.out", "w", stdout);
    #endif
    cin >> n >> m;;
    for (i = 1; i <= n; i++)
        cin >> a[i];

    for (i = 1; i <= m; i++) {
        cin >> x >> y;
        was[x][y] = true;
        was[y][x] = true;
    }
    for (i =1; i < n-1; i++)
        for (j = i+1; j < n; j++)
            for (int k = j+1; k <= n; k++) {
                if (was[i][j] && was[j][k] && was[k][i])
                    mn = min(mn, a[i]+a[j]+a[k]);
            }
    if (mn == INF)
        cout << -1;
    else
        cout << mn;
    return 0;
}


Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: a12 + a22 + ... + an2 ≥ x a1 + a2 + ... + an ≤ y

The first line contains three space-separated integers n, x and y (1 ≤ n ≤ 105, 1 ≤ x ≤ 1012, 1 ≤ y ≤ 106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.

Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.

#include <iostream>

using namespace std;

int main(){
    long long n, x, y;

    cin >> n >> x >> y;

    long long a1 = y - n + 1;

    if (a1 > 0 && a1 * a1 >= x - n + 1){
        cout << a1 << " ";
        for (int i = 1; i < n; i++){
            cout << 1 << " ";
        }
    }
    else cout << -1;

}


Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya was delivered a string s, containing only digits. He needs to find a string that represents a lucky number without leading zeroes, is not empty, is contained in s as a substring the maximum number of times.Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.

The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.

In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).

NoteThe lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".In the second sample s has no substrings which are lucky numbers.In the third sample the three conditions are only fulfilled for string "7".

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int cnt=0;
    int cnt1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='4'){
            cnt++;
        }
        else if(s[i]=='7'){
            cnt1++;
        }
    }
    if(cnt==0 && cnt1==0){
        cout<<"-1"<<endl;
    }
    else if(cnt==cnt1 || cnt>cnt1){
        cout<<"4"<<endl;
    }
    else{
        cout<<"7"<<endl;
    }
}


One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as  lines, drinks another cup of tea, then he writes  lines and so on: , , , ...The expression  is regarded as the integral part from dividing number a by number b.The moment the current value  equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.

The input consists of two integers n and k, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ n ≤ 109, 2 ≤ k ≤ 10.

Print the only integer — the minimum value of v that lets Vasya write the program in one night.

NoteIn the first sample the answer is v = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.In the second sample the answer is v = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than n = 59.

#include <iostream>
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<n; i++)
#define repc(i, a, b) for(int i = a; i<b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define fast_io std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define sortv(v) sort(v.begin(), v.end())
#define reversev(v) sort(v.begin(), v.end())
#define all(v) (v.begin(), v.end())

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<bool> vb;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mi;
typedef pair<int, int> pi;
typedef map<ll, ll> mll;
typedef pair<ll, ll> pll;
bool func(int mid,int k,int n){
    int total = mid;
    while(mid/k!=0){
        mid = mid/k;
        total += mid;
    }
    if(total>=n) return true;
    return false;
}
int main() {
    fast_io;
    int n,k;
    cin>>n>>k;
    int lo =0;
    int hi = n;
    int mid;
    int ans ;
    while(lo<=hi){
        mid = (lo+hi)>>1;
        if(func(mid,k,n)){
            ans = mid;
            hi = mid-1;
        }
        else{
            lo= mid+1;
        }
    }
    cout<<ans<<endl;
}


A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:   there were b milliliters poured in total. That is, the bottle need to be emptied;  after the process is over, the volumes of the drink in the mugs should be equal.

The first line contains a pair of integers n, b (2 ≤ n ≤ 100, 1 ≤ b ≤ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the current volume of drink in the i-th mug.

Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.

#include <cstdio>
#include <iostream>

#include <vector>
#include <list>
#include <string>

#include <algorithm>
#include <functional>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

const int MAXN = 100 + 10;

int n, b;
int as[MAXN];
int cs[MAXN];

int main()
{
    scanf("%d%d", &n, &b);
    int mx = 0;
    for(int i = 0; i < n; ++i) {
        scanf("%d", &as[i]);
        mx = max(mx, as[i]);
    }

    for(int i = 0; b >= 0 && i < n; ++i) {
        cs[i] = mx - as[i];
        b -= cs[i];
    }

    if(b < 0) {
        cout << "-1" << endl;
        return 0;
    }

    double r = static_cast<double>(b) / n;

    for(int i = 0; i < n; ++i) {
        printf("%.6f\n", cs[i] + r);
    }

    return 0;
}


Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:   After the cutting each ribbon piece should have length a, b or c.  After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.

The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.

Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.

NoteIn the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    int res=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++ ){
            int k=(n-(i*a)-(j*b))/c;
            if(k<0){k=0;}
            if((i*a)+(j*b)+(c*k)==n){
                res=max(res,i+j+k);
            }
        }
    }
    cout <<res;
    return 0;
}


Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value .Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.In the problem, fraction  denotes division in real numbers, that is, no rounding is performed.

The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing. The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing. It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.

Print the number of "integer" gears with the maximum ratio among all "integer" gears.

NoteIn the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.

#include<algorithm>
#include <iostream>
using namespace std;

int main() {

    int n,m , a[51] ,b[51];
    cin>>n;
    for(int i=0 ;i<n ;i++){
        cin>>a[i];
    }

    cin>>m;
    for(int i=0 ;i<m ;i++){
        cin>>b[i];
    }

    int num[100]={0};
    int l=0;
    for(int i=0 ;i<m ;i++){
        for(int j=0 ;j<n ;j++){
            if(b[i]%a[j]==0){
            num[l]=b[i]/a[j];
            l++;
            }
        }

    }
     int max1;
    max1=max(l,m);
    sort(num,num+max1);
    int c=0;

    for(int i=0 ;i<max1 ;i++){
    //  cout<<num[i];
        if(num[i]==num[max1-1])
        c++;

    }

    cout<<c;
    return 0;
}


Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.

The first line contains four space-separated integers s1, s2, s3, s4 (1 ≤ s1, s2, s3, s4 ≤ 109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.

Print a single integer — the minimum number of horseshoes Valera needs to buy.

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    map<int , int > color;
    int num ;
    for(int i=0;i<4;i++)
    {
        cin>>num;
        color[num]=num;
    }
    cout<<4-color.size()<<endl;

    return 0 ;

}


One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.

NoteFor example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

int main()
{
  	ll n; cin >> n;

  	if (n % 2 != 0 || n == 2) cout << "NO";
	else cout << "YES";

    return 0;
}


A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.As before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.

The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).

Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.

WWWBWWBW
BBBBBBBB
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW

WWWWWWWW
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
#define pb(a) push_back(a)
#define pbr(a,b) pb(make_pair(a,b))
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define F first
#define S second

ll M = 1e9 + 7;                 //998244353;
const int N = 100001;

ll binpow(ll a, ll b){    ll ans = 1;    while(b > 0){        if(b&1)     ans = (ans * a) % M;        a = (a*a) % M;        b >>= 1;    }    return ans;     }
bool sS(pi p1, pi p2){    return (p1.S < p2.S);     }
bool sF(pi p1, pi p2){    return (p1.F < p2.F);     }

void solve()
{
    string s[8];
    fr(i, 0, 7)
        cin >> s[i];
    int res{}, f;
    fr(i, 0, 7){
        f = 1;
        fr(j, 0, 7)
            if(s[i][j] == 'W'){
                f = 0;
                break;
            }
        if(f)
            res++;
    }
    fr(j, 0, 7){
        f = 1;
        fr(i, 0, 7)
            if(s[i][j] == 'W'){
                f = 0;
                break;
            }
        if(f)
            res++;
    }
    if(res == 16)
        res = 8;
    cout << res << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);

    int t=1;
    // cin >> t;
    for(int i = 1; i <= t; i++)
    {
        // cout << "t: " << t << "\n";
        solve();
    }
    return 0;
}

[{'input': 'WWWBWWBW\r\nBBBBBBBB\r\nWWWBWWBW\r\nWWWBWWBW\r\nWWWBWWBW\r\nWWWBWWBW\r\nWWWBWWBW\r\nWWWBWWBW\r\n', 'output': ['3']}, {'input': 'WWWWWWWW\r\nBBBBBBBB\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n', 'output': ['1']}, {'input': 'WWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n', 'output': ['0']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['8']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBW\r\n', 'output': ['14']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nBBBBBBWB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['14']}, {'input': 'BBBBBBBB\r\nWBBBWBBW\r\nBBBBBBBB\r\nWBBBWBBW\r\nWBBBWBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBBBWBBW\r\n', 'output': ['9']}, {'input': 'BBBBBBBB\r\nWBBWWWBB\r\nBBBBBBBB\r\nWBBWWWBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBBWWWBB\r\nBBBBBBBB\r\n', 'output': ['9']}, {'input': 'BBBBBWWB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBWWB\r\nBBBBBWWB\r\nBBBBBWWB\r\nBBBBBWWB\r\nBBBBBWWB\r\n', 'output': ['8']}, {'input': 'WWWWBBBB\r\nWWWWBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWWWBBBB\r\nWWWWBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['8']}, {'input': 'BBBBBBBB\r\nWBWWBBBW\r\nBBBBBBBB\r\nWBWWBBBW\r\nWBWWBBBW\r\nWBWWBBBW\r\nWBWWBBBW\r\nBBBBBBBB\r\n', 'output': ['7']}, {'input': 'WBWWBBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBWWBBBW\r\nWBWWBBBW\r\n', 'output': ['9']}, {'input': 'BBWWBBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBWWBBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['11']}, {'input': 'WWBWBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWBWBBBB\r\nBBBBBBBB\r\nWWBWBBBB\r\nBBBBBBBB\r\n', 'output': ['10']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWBWBBBB\r\nWWBWBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWBWBBBB\r\n', 'output': ['10']}, {'input': 'WBBWBBBW\r\nWBBWBBBW\r\nWBBWBBBW\r\nWBBWBBBW\r\nWBBWBBBW\r\nBBBBBBBB\r\nWBBWBBBW\r\nWBBWBBBW\r\n', 'output': ['6']}, {'input': 'BBBWBBBW\r\nBBBWBBBW\r\nBBBWBBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBWBBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['10']}, {'input': 'BBBBBBBB\r\nBBBWBBBB\r\nBBBWBBBB\r\nBBBWBBBB\r\nBBBBBBBB\r\nBBBWBBBB\r\nBBBWBBBB\r\nBBBWBBBB\r\n', 'output': ['9']}, {'input': 'BBBBBBBB\r\nWWWBBBBB\r\nWWWBBBBB\r\nBBBBBBBB\r\nWWWBBBBB\r\nWWWBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['9']}, {'input': 'WBBBBBWB\r\nBBBBBBBB\r\nWBBBBBWB\r\nWBBBBBWB\r\nWBBBBBWB\r\nWBBBBBWB\r\nWBBBBBWB\r\nBBBBBBBB\r\n', 'output': ['8']}, {'input': 'WBBBWWBW\r\nWBBBWWBW\r\nBBBBBBBB\r\nWBBBWWBW\r\nBBBBBBBB\r\nWBBBWWBW\r\nWBBBWWBW\r\nWBBBWWBW\r\n', 'output': ['6']}, {'input': 'WBBBBWBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBBBBWBB\r\nWBBBBWBB\r\nBBBBBBBB\r\nWBBBBWBB\r\nBBBBBBBB\r\n', 'output': ['10']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBBBWBBW\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBBBWBBW\r\nBBBBBBBB\r\n', 'output': ['11']}, {'input': 'BBBBBBBB\r\nBWBBBBBW\r\nBWBBBBBW\r\nBBBBBBBB\r\nBWBBBBBW\r\nBWBBBBBW\r\nBBBBBBBB\r\nBWBBBBBW\r\n', 'output': ['9']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nWBBBWWWW\r\nBBBBBBBB\r\nBBBBBBBB\r\nWBBBWWWW\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['9']}, {'input': 'BWBBBWWB\r\nBWBBBWWB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBWBBBWWB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\n', 'output': ['10']}, {'input': 'BBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBWBBWBWB\r\n', 'output': ['12']}, {'input': 'BWBBBBWW\r\nBWBBBBWW\r\nBWBBBBWW\r\nBWBBBBWW\r\nBBBBBBBB\r\nBWBBBBWW\r\nBWBBBBWW\r\nBBBBBBBB\r\n', 'output': ['7']}, {'input': 'WWBBWWBB\r\nBBBBBBBB\r\nWWBBWWBB\r\nWWBBWWBB\r\nWWBBWWBB\r\nBBBBBBBB\r\nWWBBWWBB\r\nWWBBWWBB\r\n', 'output': ['6']}, {'input': 'BWBBWWWW\r\nBWBBWWWW\r\nBWBBWWWW\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nBWBBWWWW\r\nBBBBBBBB\r\n', 'output': ['7']}]


Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.  The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.

Output one of the four words without inverted commas:    «forward» — if Peter could see such sequences only on the way from A to B;  «backward» — if Peter could see such sequences on the way from B to A;  «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;  «fantasy» — if Peter could not see such sequences.

NoteIt is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

#include <bits/stdc++.h>
using namespace std;

#define MAXN 100000
#define MAXS 100

char flags[MAXN+10];
char a[MAXS+10], b[MAXS+10];
int faila[MAXS], failb[MAXS];

void kmpinit(char *s, int len, int *fail) {
	fail[0] = -1;
	for (int i=1, pos = -1; i<len; ++i) {
		while (pos != -1 && s[pos+1] != s[i]) { pos = fail[pos]; }
		if (s[pos+1] == s[i]) { ++pos; }
		fail[i] = pos;
	}
}

bool possible(char *s, int lens, int lena, int lenb) {
	int matcha = lens;
	for (int i=0, pos=-1; i<lens; ++i) {
		while (pos != -1 && a[pos+1] != s[i]) { pos = faila[pos]; }
		if (a[pos+1] == s[i]) { ++pos; }
		if (pos == lena - 1) {
			matcha = i;
			break;
		}
	}

	if (matcha >= lens) { return false; }

	for (int i=0, pos=-1; i<lens; ++i) {
		while (pos != -1 && b[pos+1] != s[i]) { pos = failb[pos]; }
		if (b[pos+1] == s[i]) { ++pos; }
		if (pos == lenb - 1) {
			if (i-lenb >= matcha) { return true; }
			pos = failb[pos];
		}
	}

	return false;
}

int main() {
	scanf("%s", flags);
	scanf("%s", a);
	scanf("%s", b);

	int lena = strlen(a), lenb= strlen(b);
	int lenf = strlen(flags);

	kmpinit(a, lena, faila);
	kmpinit(b, lenb, failb);

	bool forward = possible(flags, lenf, lena, lenb);
	reverse(flags, flags+lenf);
	bool backward = possible(flags, lenf, lena, lenb);

	if (forward) {
		printf("%s\n", backward ? "both" : "forward");
	} else {
		printf("%s\n", backward ? "backward" : "fantasy");
	}

	return 0;

}

[{'input': 'atob\r\na\r\nb\r\n', 'output': ['forward\r\n']}, {'input': 'aaacaaa\r\naca\r\naa\r\n', 'output': ['both\r\n']}, {'input': 'aaa\r\naa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'astalavista\r\nastla\r\nlavista\r\n', 'output': ['fantasy\r\n']}, {'input': 'abacabadabacaba\r\nabacaba\r\nabacaba\r\n', 'output': ['both\r\n']}, {'input': 'a\r\na\r\na\r\n', 'output': ['fantasy\r\n']}, {'input': 'ab\r\nb\r\na\r\n', 'output': ['backward\r\n']}, {'input': 'aaa\r\naaaa\r\naaaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'bbabbbbababbaabaabaa\r\nabb\r\nbaab\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['backward\r\n']}, {'input': 'aaaa\r\naaa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzzzz\r\nzzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzz\r\n', 'output': ['both\r\n']}, {'input': 'aabaa\r\naab\r\nbaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'aabaab\r\naba\r\nab\r\n', 'output': ['forward\r\n']}, {'input': 'aab\r\nb\r\naa\r\n', 'output': ['backward\r\n']}, {'input': 'abacaba\r\naca\r\nba\r\n', 'output': ['both\r\n']}]


And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following:   during one run the minibus makes n stops, the i-th stop is in point (xi, 0)  coordinates of all the stops are different  the minibus drives at a constant speed, equal to vb  it can be assumed the passengers get on and off the minibus at a bus stop momentarily  Student can get off the minibus only at a bus stop  Student will have to get off the minibus at a terminal stop, if he does not get off earlier  the University, where the exam will be held, is in point (xu, yu)  Student can run from a bus stop to the University at a constant speed vs as long as needed  a distance between two points can be calculated according to the following formula:   Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.

The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.

In the only line output the answer to the problem — index of the optimum bus stop.

NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.

///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 1e6+10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
using ld=long double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
dl ttime[1000];
dl atime[1000];
ll vb,vs,vx,vy;
ld dis(ll k)
{
    ld x=(vx-aarray[k]);
    ld y=vy;
    return sqrt(x*x+y*y);
}
ld calc(ll n)
{
    ld t1=(ld)(aarray[n])/vb;
    ld t2=(ld)dis(n)/vs;
    return t1+t2;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll i,j,n,m,k=0;
    cin>>n>>vb>>vs;
    for(i=1; i<=n; i++)
    {
        cin>>aarray[i];
    }
    cin>>vx>>vy;
    ll ans=2;
    for(i=3; i<=n; i++)
    {
        if(calc(i)-calc(ans)<1e-14)
        {
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.—No problem! — said Bob and immediately gave her an answer.Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.

The first line contains one integer n (0 ≤ n ≤ 109) without leading zeroes. The second lines contains one integer m (0 ≤ m ≤ 109) — Bob's answer, possibly with leading zeroes.

Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define MAX 1000100
#define MD 1e9 + 7
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

signed main(){
    // fast;
    string s1, s2;

    cin >> s1 >> s2;

    if (s1 == "0" && s2 == "0") {
        cout << "OK";
        return 0;
    }

    string ans, s3 = "";

    int zeros = 0;

    for (int i = 0; i < s1.length(); i++) {
         if (s1[i] == '0') zeros++;
         else s3 += s1[i];
    }

    sort(s3.begin(), s3.end());

    if (s1.length() > 1)
        for (int i = 0; i < zeros; i++)
            s3.insert(1, 1, '0');

    if (s3 == s2) cout << "OK";
    else cout << "WRONG_ANSWER";
}


Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

string MakeLine(string str)
{
    string s = "";
    if(str.size() < 4)
    {
        return str;
    }
    if(str.size()%2 == 0)
    {
        for(int i = 1; i <= str.size(); i++)
        {
            s += str[i-1];
            if(i%2 == 0 && i != str.size())
                s += "-";
        }
    }
    else
    {
        s += str[0];
        s += str[1];
        s += str[2];
        s += "-";
        for(int i = 1; i <= str.size() - 3; i++)
        {
            s += str[i+2];
            if(i%2 == 0 && i != str.size() - 3)
                s += "-";
        }
    }
    return s;
}

int main()
{
    int n;
    string str;
    cin >> n >> str;
    cout << MakeLine(str);
    return 0;
}


Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.

The first line contains integer n (3 ≤ n ≤ 100) — amount of worm's forms. The second line contains n space-separated integers ai (1 ≤ ai ≤ 1000) — lengths of worms of each form.

Output 3 distinct integers i j k (1 ≤ i, j, k ≤ n) — such indexes of worm's forms that ai = aj + ak. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that aj = ak.

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <list>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int *a = new int[n];
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < j; k++) {
				if (a[i] == a[j]+a[k] && i != j && i != k && j != k) {
					printf("%d %d %d\n",i+1,j+1,k+1);
					return 0;
				}
			}
		}
	}
	printf("-1\n");
	return 0;
}


Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.

The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.

Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long

const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;

signed main() {
    ios::sync_with_stdio(false); cin.tie(NULL);

    string s; int upper = 0, lower = 0;
    cin>>s;
    for(int i = 0; i<s.size(); i++){
        if(((int)s[i])>=97 && ((int)s[i])<=122) lower++;
        else upper++;
    }

    if(lower>=upper){
        for(int i = 0; i<s.size(); i++){
            s[i] = tolower(s[i]);
        }
    }
    else if(upper>lower){
        for(int i = 0; i<s.size(); i++){
            s[i] = toupper(s[i]);
        }
    }

    cout<<s<<endl;
}

[{'input': 'HoUse\r\n', 'output': ['house']}, {'input': 'ViP\r\n', 'output': ['VIP']}, {'input': 'maTRIx\r\n', 'output': ['matrix']}, {'input': 'BNHWpnpawg\r\n', 'output': ['bnhwpnpawg']}, {'input': 'VTYGP\r\n', 'output': ['VTYGP']}, {'input': 'CHNenu\r\n', 'output': ['chnenu']}, {'input': 'ERPZGrodyu\r\n', 'output': ['erpzgrodyu']}, {'input': 'KSXBXWpebh\r\n', 'output': ['KSXBXWPEBH']}, {'input': 'qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv\r\n', 'output': ['qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv']}, {'input': 'Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd\r\n', 'output': ['amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd']}, {'input': 'ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv\r\n', 'output': ['isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv']}, {'input': 'XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg\r\n', 'output': ['xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg']}, {'input': 'RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak\r\n', 'output': ['RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK']}, {'input': 'DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw\r\n', 'output': ['DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW']}, {'input': 'NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB\r\n', 'output': ['NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB']}, {'input': 'igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge\r\n', 'output': ['igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge']}, {'input': 'Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw\r\n', 'output': ['ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw']}, {'input': 'YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks\r\n', 'output': ['yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks']}, {'input': 'CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz\r\n', 'output': ['CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ']}, {'input': 'WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg\r\n', 'output': ['WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG']}, {'input': 'VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO\r\n', 'output': ['VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO']}, {'input': 'EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd\r\n', 'output': ['EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD']}, {'input': 'EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas\r\n', 'output': ['ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas']}, {'input': 'AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm\r\n', 'output': ['AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM']}, {'input': 'DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn\r\n', 'output': ['dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn']}, {'input': 't\r\n', 'output': ['t']}, {'input': 'N\r\n', 'output': ['N']}, {'input': 'kv\r\n', 'output': ['kv']}, {'input': 'Ur\r\n', 'output': ['ur']}, {'input': 'CN\r\n', 'output': ['CN']}]


Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Write one line — the corresponding answer. Do not omit the leading 0s.

#include <iostream>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#define ll long long
using namespace std;

int main()
{
    string x,y;
    cin>>x>>y;
    for(int i=0;i<x.size();i++){
        if(x[i]==y[i]){
            cout<<0;
        }
        else{
            cout<<1;
        }
    }
    return 0;
}


n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
int n,i,diff,x,y,ar[1000000];
int main()
{
    while(cin>>n)
    {
        for(i=0;i<n;i++)
            cin>>ar[i];
        ar[n] = ar[0];
        diff = 99999999;
        for(i=0;i<n;i++)
        {
            if(abs(ar[i]-ar[i+1])<diff)
            {
                diff = abs(ar[i]-ar[i+1]);
                x = i;
                y = i+1;
              //  cout<<x<<" "<<y<<endl;;
            }
        }
        if(y==n)y=0;
        cout<<x+1<<" "<<y+1;
    }
    return 0;
}


After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation.The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1.Find the tree that will be the last to start burning. If there are several such trees, output any.

The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning.  The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide.

Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any.

#include <bits/stdc++.h>
using namespace std;

//#define DEBUG
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define what_is(x) cout << #x << " = " << x << endl
#define IO_SPEED_UP ios::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

const int PINF = numeric_limits<int>::max();
const int NINF = numeric_limits<int>::min();
const ll MOD = 1E9 + 7;

void print_vector(vector<int> &v) {
	for (int i = 0; i < (int) v.size(); ++i) {
		cout << v[i] << endl;
	}
}

int dirx[] = { -1, 1, 0, 0 };
int diry[] = { 0, 0, -1, 1 };

int main() {
	//IO_SPEED_UP;
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	int rows, cols;
	cin >> rows >> cols;
	int k;
	cin >> k;
	vii start(k);
	vvi g(rows, vi(cols, PINF));
	for (int i = 0; i < k; ++i) {
		int x, y;
		cin >> x >> y;
		g[--x][--y] = 0;
		start[i] = ii(x, y);
	}
	vector<vb> visited(rows, vb(cols, false));
	queue<ii> q;
	for (int i = 0; i < k; ++i) {
		ii s = start[i];
		q.push(s);
		visited[s.F][s.S] = true;
	}
	while (!q.empty()) {
		ii u = q.front();
		q.pop();
		for (int j = 0; j < 4; ++j) {
			ii child(u.F + dirx[j], u.S + diry[j]);
			if (child.F >= 0 && child.F < rows && child.S >= 0
					&& child.S < cols) {
				if (visited[child.F][child.S] == false) {
					q.push(child);
					g[child.F][child.S] = g[u.F][u.S] + 1;
					visited[child.F][child.S] = true;
				}
			}
		}
	}

	ii last_point;
	int mx = -1;
	for (int i = 0; i < rows; ++i) {
		for (int j = 0; j < cols; ++j) {
			if (mx < g[i][j]) {
				mx = g[i][j];
				last_point = ii(i, j);
			}
		}
	}
	cout << ++last_point.F << " " << ++last_point.S;
	return 0;
}


Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too?

The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3.

In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.

#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<ll,ll> int2;
typedef tuple<ll,ll,ll> int3;
typedef tuple<ll,ll,ll,ll> int4;

#define all(v) (v).begin(), (v).end()
#define est(v,e) (find(all(v), (e)) != (v).end())
#define pb push_back
#define eb emplace_back
#define SZ(a) ((ll)((a).size()))
#define For(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) For(i,0,n)
#define tag(i,v) rep(i,SZ(v))
#define trace(x)  cerr << #x << " = " << (x) << endl
#define tracev(x) cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl
#define initv(typ, v, n) vector<typ> v; rep(i,n) { typ tmp; cin >> tmp; x.pb(tmp); }
#define fst get<0>
#define snd get<1>
#define thd get<2>

const ll inf = 1LL << 60;
int toInt(string s) {int res;stringstream ss;ss<<s;ss>>res;return res;}

int main(void) {

  #define int long long

  #ifdef ONLINE_JUDGE
  ifstream ifile("input.txt");
  if(ifile) freopen("input.txt", "rt", stdin);
  if(ifile) freopen("output.txt", "wt", stdout);
  #endif

  int n;
  cin >> n;

  rep(i,3){

    int x,y;
    cin >> x >> y;

    if(x==n)n=y;
    else if(y==n)n=x;

  }

  cout << (n) << endl;

  return 0;

}


Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?

The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.

In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<fstream>
#include<vector>
#include<set>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<cmath>

#define PB push_back
#define MP make_pair
#define F first
#define S second

using namespace std;
ifstream fin("I.12");
ifstream fout("O.12");
FILE *inn=fopen("","r"),*outt;
//inn=fopen("","r");
//outt=fopen("","w");
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1e6+5,MAXM=1e3+5,inf=2e9+1,MOD=1e9+7;
const ll C=701;

int N,M,ans;
ll h1[MAXN],h2[MAXN],p[MAXN];
string str1,str2;
vector <int> res;

bool cmpstr(int st1,int en1,int st2,int en2);

int main(){
	ios::sync_with_stdio(0);
	cin >> str1 >> str2;
	N=str1.size();
	M=str2.size();
	h1[0]=str1[0];h2[0]=str2[0];p[0]=1;
	for(int i=1;i<N;i++){
		h1[i]=h1[i-1]*C+str1[i];
		p[i]=p[i-1]*C;
	}
	for(int i=1;i<M;i++) h2[i]=h2[i-1]*C+str2[i];
	for(int i=0;i<N;i++){
		if(cmpstr(0,i-1,0,i-1) && cmpstr(i+1,N-1,i,M-1)){
			ans++;
			res.PB(i+1);
		}
	}
	cout << ans << endl;
	for(int i=0;i<res.size();i++){
		cout << res[i] << " ";
	}
	cout << endl;
	return 0;
}

bool cmpstr(int st1,int en1,int st2,int en2){
	if(en1<st1 || en2<st2){
		if(en1<st1 && en2<st2)return 1;
		return 0;
	}
	if(h1[en1]-h1[st1-1]*p[en1-st1+1]==h2[en2]-h2[st2-1]*p[en2-st2+1])return 1;
	return 0;
}

[{'input': 'abdrakadabra\r\nabrakadabra\r\n', 'output': ['1\r\n3 ']}, {'input': 'aa\r\na\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'competition\r\ncodeforces\r\n', 'output': ['0\r\n']}, {'input': 'ab\r\na\r\n', 'output': ['1\r\n2 ']}, {'input': 'bb\r\nb\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'aab\r\nab\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'aabb\r\nabb\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'babaacaacaa\r\nbbaacaacaa\r\n', 'output': ['1\r\n2 ']}, {'input': 'bccaabbcccc\r\nbccaabcccc\r\n', 'output': ['2\r\n6 7 ']}, {'input': 'ababcaabaaa\r\nabacaabaaa\r\n', 'output': ['1\r\n4 ']}, {'input': 'cccacaccacb\r\ncccacaccac\r\n', 'output': ['1\r\n11 ']}, {'input': 'aaaaaaaaaaa\r\naaaaaaaaaa\r\n', 'output': ['11\r\n1 2 3 4 5 6 7 8 9 10 11 ']}, {'input': 'lcaaxcbcjca\r\nccaaacccca\r\n', 'output': ['0\r\n']}, {'input': 'babbbtaamba\r\nbabbbaabba\r\n', 'output': ['0\r\n']}, {'input': 'xdfxmcnzpch\r\nazvotghvtk\r\n', 'output': ['0\r\n']}, {'input': 'ki\r\nb\r\n', 'output': ['0\r\n']}, {'input': 'vct\r\nie\r\n', 'output': ['0\r\n']}, {'input': 'feee\r\nsnl\r\n', 'output': ['0\r\n']}, {'input': 'cbxxxxzvks\r\ncbxxxzvks\r\n', 'output': ['4\r\n3 4 5 6 ']}, {'input': 'qybldcgfhdhhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\r\nqybldcgfhdhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\r\n', 'output': ['10\r\n11 12 13 14 15 16 17 18 19 20 ']}]


A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>

#define sz(a)    int(a.size())
#define FOR(i,n) for(int (i)=1;(i)<=(n);++(i))
#define  ll long long

using namespace std;

int main ()
{
    int n; scanf("%d", &n);
    for (int i = 1; i <= n-1; i++)
        printf("%d ", (i*(i+1)/2) % n + 1);
    return 0;
}


The only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includes $$$n$$$ pictures.When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The $$$i$$$-th picture has a non-negative weight $$$w_i$$$, and the probability of the $$$i$$$-th picture being displayed is $$$\frac{w_i}{\sum_{j=1}^nw_j}$$$. That is to say, the probability of a picture to be displayed is proportional to its weight.However, Nauuo discovered that some pictures she does not like were displayed too often. To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add $$$1$$$ to its weight; otherwise, she would subtract $$$1$$$ from its weight.Nauuo will visit the website $$$m$$$ times. She wants to know the expected weight of each picture after all the $$$m$$$ visits modulo $$$998244353$$$. Can you help her?The expected weight of the $$$i$$$-th picture can be denoted by $$$\frac {q_i} {p_i}$$$ where $$$\gcd(p_i,q_i)=1$$$, you need to print an integer $$$r_i$$$ satisfying $$$0\le r_i<998244353$$$ and $$$r_i\cdot p_i\equiv q_i\pmod{998244353}$$$. It can be proved that such $$$r_i$$$ exists and is unique.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 2\cdot 10^5$$$, $$$1\le m\le 3000$$$) — the number of pictures and the number of visits to the website. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$a_i$$$ is either $$$0$$$ or $$$1$$$) — if $$$a_i=0$$$ , Nauuo does not like the $$$i$$$-th picture; otherwise Nauuo likes the $$$i$$$-th picture. It is guaranteed that there is at least one picture which Nauuo likes. The third line contains $$$n$$$ positive integers $$$w_1,w_2,\ldots,w_n$$$ ($$$w_i \geq 1$$$) — the initial weights of the pictures. It is guaranteed that the sum of all the initial weights does not exceed $$$998244352-m$$$.

The output contains $$$n$$$ integers $$$r_1,r_2,\ldots,r_n$$$ — the expected weights modulo $$$998244353$$$.

NoteIn the first example, if the only visit shows the first picture with a probability of $$$\frac 2 3$$$, the final weights are $$$(1,1)$$$; if the only visit shows the second picture with a probability of $$$\frac1 3$$$, the final weights are $$$(2,2)$$$.So, both expected weights are $$$\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3$$$ .Because $$$332748119\cdot 3\equiv 4\pmod{998244353}$$$, you need to print $$$332748119$$$ instead of $$$\frac4 3$$$ or $$$1.3333333333$$$.In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $$$w_1$$$ will be increased by $$$1$$$.So, the expected weight is $$$1+2=3$$$.Nauuo is very naughty so she didn't give you any hint of the third example.

#include <bits/stdc++.h>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define CLEAR(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define REP(i, l, r) for (int i = (l); i <= (r); ++i)
using namespace std;

typedef long long li;
typedef unsigned long long lu;
typedef pair<int, int> pii;

const int mod = 998244353;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (lu)x * y % mod; }
inline int Mul(int x, int y, int z) { return Mul(Mul(x, y), z); }

inline void Max(int &x, int y) { if (y > x) x = y; }
inline void Min(int &x, int y) { if (y < x) x = y; }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

// ----------------------------------------

const int maxn = 2e5, maxm = 3000;

int n, m;
int type[maxn], wei[maxn];
// int n1, w1[maxn], s1;
// int n0, w0[maxn], s0;
int s0, s1;
int pro[maxm + 2][maxm + 2];

int _inv[4 * maxm + 1], *inv = _inv + 2 * maxm;

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", type + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", wei + i);
  }
  for (int i = 0; i < n; ++i) {
    if (type[i] == 0) {
      // w0[n0++] = wei[i];
      Add(s0, wei[i]);
    } else {
      // w1[n1++] = wei[i];
      Add(s1, wei[i]);
    }
  }

  for (int i = -2 * m; i <= 2 * m; ++i) {
    int x = Sub(Add(Add(s0 + s1) + i));
    inv[i] = Pow(x, mod - 2);
  }

  int ans0 = 0, ans1 = 0;

  pro[0][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; i + j < m; ++j) {
      int p = pro[i][j];
      // printf("pro[%d][%d] = %d\n", i, j, p);
      if (p == 0) continue;
      int ss0 = s0 - i;
      int ss1 = s1 + j;
      int pp0 = Mul(ss0, inv[j - i]);
      int pp1 = Mul(ss1, inv[j - i]);
      int p0 = Mul(p, pp0);
      int p1 = Mul(p, pp1);
      Add(pro[i + 1][j], p0);
      Add(pro[i][j + 1], p1);
      Add(ans0, p0);
      Add(ans1, p1);
    }
  }

  ans0 = Mul(ans0, Pow(s0, mod - 2));
  ans1 = Mul(ans1, Pow(s1, mod - 2));
  for (int i = 0; i < n; ++i) {
    int w = wei[i];
    if (type[i] == 0) {
      Sub(w, Mul(ans0, w));
    } else {
      Add(w, Mul(ans1, w));
    }
    printf("%d\n", w);
  }
}


Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common divisor of a and b, and LCM(a, b) denotes the least common multiple of a and b.You are given two integers x and y. You are to find the number of good pairs of integers (a, b) such that l ≤ a, b ≤ r. Note that pairs (a, b) and (b, a) are considered different if a ≠ b.

The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).

In the only line print the only integer — the answer for the problem.

NoteIn the first example there are two suitable good pairs of integers (a, b): (1, 2) and (2, 1).In the second example there are four suitable good pairs of integers (a, b): (1, 12), (12, 1), (3, 4) and (4, 3).In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition l ≤ a, b ≤ r.

/*
 ID: osama2
 LANG: C++
 PROG: beads
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define imfaast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<typename T>using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind);
int dx[]= {0,0,-1,1,1,-1,1,-1};
int dy[]= {1,-1,0,0,1,-1,-1,1};
#define f first
#define s second
int oo=1e3;
const int mod=1e9+7;
const int N=1;
const int N2=105;
#define endl '\n'
#define mem memset(dp,-1,sizeof(dp));
int gcd(int a,int b)
{
    // O(log(a*b)) GCD calculater
    if(b>a)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}
void doswaps(int& a,int&b,int q)
{
    int n=a-q*b;
    a=b;
    b=n;
}
int egcd(int a,int b,int& x0,int& y0)
{
    int x1,y1;
    x1=y0=0;
    x0=y1=1;
    int r0=a,r1=b;
    while(r1!=0)
    {
        int q=r0/r1;
        doswaps(x0,x1,q);
        doswaps(y0,y1,q);
        doswaps(r0,r1,q);
    }
    return r0;
}

ll fpow(int b,int p)// fast power
{
    if(p==1)return b;
    ll ret= fpow(b,p/2);
    ret*=ret;
    ret%=mod;
    if(p%2)ret= ret * b % mod;
    return ret%mod;
}
ll fact[N];
void pre(int n)
{
    fact[0]=1;
    for(int i=1; i<n; i++)
    {
        fact[i]= ( fact[i-1] * i);
    }
}
ll ncr(int n,int r)
{
    // n! / (n-r)! * r!
    if(r>n)return 0;
    ll ret= fact[n];
    ll d= fact[n-r];
    d*=fact[r];
    d%=mod;
    return (ret*fpow(d,mod-2))%mod;
}

signed main()
{
    imfaast
//      freopen("input.txt","r",stdin);
//      freopen("billboard.out","w",stdout);
    int l,r,x,y;cin>>l>>r>>x>>y;
    if(y%x)
    {
        cout << 0<<endl;return 0;
    }
    int ans=0;
    int z=y/x;
    for(int i=1;i*i<=z;i++)
    {
        if(z%i==0)
        {
            int j= z/i;
            if(i*x>=l&&i*x<=r&&j*x>=l&&j*x<=r&&gcd(i,j)==1)
            {
                ans++;
                if(i!=j)ans++;
            }
        }
    }
    cout << ans;

}


In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns.

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

NoteIn the first sample, the train can take the route  and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.


Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list. The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

In the first line, print a single integer k — the size of the subset. In the second line, print k integers — the elements of the subset in any order. If there are multiple optimal subsets, print any.

NoteIn the first case, the optimal subset is , which has mean 5, median 2, and simple skewness of 5 - 2 = 3.In the second case, the optimal subset is . Note that repetition is allowed.In the last case, any subset has the same median and mean, so all have simple skewness of 0.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 200010
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int n,len;
int a[maxn];
LL sum[maxn];
int main()
{
	scanf("%d",&n);

	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	if(n==2)
	{
		printf("2\n");
		printf("%d %d",a[1],a[2]);
		return 0;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	int res,ans1=1,len=0;
	double ans=-INF;
	for(int i=1;i<=n;i++)
	{
		int l=1,r=min(i-1,n-i);
		res=0;
		while(l<=r)
		{
			int mid=(l+r)/2;
			double res1=1.0*(sum[i]-sum[i-mid-1]+sum[n]-sum[n-mid])/(2*mid+1);
			double res2=1.0*(sum[i]-sum[i-mid]+sum[n]-sum[n-mid+1])/(2*mid-1);
			if(res1>res2)
				{res=mid;l=mid+1;}
			else
				r=mid-1;

		}
		double tmp=1.0*(sum[i]-sum[i-res-1]+sum[n]-sum[n-res])/(2*res+1)-a[i];
		//printf("%.3lf %.3lf\n", tmp, ans);
		if(tmp>ans)
			{ans=tmp;ans1=i;len=res;}
	}
	printf("%d\n",2*len+1);
	for(int i=ans1-len;i<=ans1;i++)
	{
		printf("%d ",a[i]);
	}
	for(int i=n-len+1;i<=n;i++)
	{
		printf("%d",a[i]);
		if(i!=n)
		printf(" ");
	}
}


There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum ai in the group minus the minimum ai in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k?Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.

The first line contains two space-separated integers n and k (1 ≤ n ≤ 200, 0 ≤ k ≤ 1000) — the number of students and the maximum total imbalance allowed, respectively. The second line contains n space-separated integers ai (1 ≤ ai ≤ 500) — the time it takes the i-th student to complete his/her independent piece of work.

Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7.

NoteIn the first sample, we have three options:   The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2.  The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1.  All three students form their own groups. Total imbalance is 0. In the third sample, the total imbalance must be 0, so each student must work individually.

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,k,now,a[205];
long long f[2][205][1010],ans;
int read()
{
	int res=0,fl=0;
	char a=getchar();
	while(a<'0'||a>'9') {if(a=='-') fl=1;a=getchar();}
	while(a>='0'&&a<='9') res=res*10+a-'0',a=getchar();
	return fl? -res:res;
}
int main()
{
//	freopen("group.in","r",stdin);
//	freopen("group.out","w",stdout);
	int i,j,li;
	n=read(),k=read();
	for(i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1),f[0][0][0]=1;
	for(i=0;i<n;i++)
	{
		for(j=0;j<=n;j++)
			for(li=0;li<=k;li++)
			{
				int t=(a[i+1]-a[i])*j;
				if(li+t>k) continue;
				(f[now^1][j][li+t]+=f[now][j][li]*(j+1)%mod)%=mod;
				(f[now^1][j+1][li+t]+=f[now][j][li])%=mod;
				if(j) (f[now^1][j-1][li+t]+=f[now][j][li]*j%mod)%=mod;
			}
		memset(f[now],0,sizeof(f[now])),now^=1;
	}
	for(i=0;i<=k;i++) (ans+=f[now][0][i])%=mod;
	cout<<ans;
	return 0;
}