//c stands for char/d for integer/lf for double/f for float/s for string/v for vector
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cctype>   //isalnum,isalpha,isdigit,tolower,toupper
#include <cmath>    //accept d,lf and return lf : exp,log(ln),log10,fabs,fmod,modf, fracpart = modf(x,&intpart), frexp : breaks x into r*2^n => r=frexp(x,&n)
#include <cstdlib>  // dynamic memory,random,bsearch : atoi,atol,atof,strtod,strtol , ver quando usa estes e quando sprintf e sscanf
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string> //begin,end,size,resize,clear,empty,append,push_back
#include <vector>
#include <stack> // push,pop,empty,size,top
#include <queue> // push,pop,empty,size,front,back
#include <map> // bst, key->value

#include <deque>
/*
#include <multimap> // map(bst) with key not unique
#include <bitset>
#include <list> // linked list
#include <set>	// map (bst) element is the key
#include <complex>
#include <valarray>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <functional>
#include <utility>

cin.tie(0);
cout.unsetf(ios::floatfield);            // floatfield not set
cout.setf(ios::fixed,ios::floatfield);   // floatfield set to fixed

*/

using namespace std;
const long double PI = 3.1415926535897932384626433832795;
const int INF = (1 << 30) - 1;
typedef long long LL;
typedef long double LD;
typedef double DB;
typedef pair<int,int> II;
typedef vector<int> VII;

#define CIRCULARUP(a,max) a = (a + 1) % max // 0 <= a < max
#define CIRCULARDOWN(a,max) a = (a + max - 1) % max // 0 <= a < max
#define ROUNDNEAR(a) a = (int) ((double)a + 0.5)
#define SORT(V) sort((V).begin(),(V).end())
#define DEBUG(X) cout << "debug : " << #X << " = " << X << '\n'; //int,char,char[]
#define DEBUGC(X,Y)  for( int VAR = 0; VAR < Y; VAR++) cout << "debugc : " << #X <<'[' << VAR << "]  = " << *(X+VAR) << '\n'; // int[], char[] c
#define DEBUGSTL(X)  for( int VAR = 0; VAR < X.size(); VAR++) cout << "debugstl : "<< #X << '[' << VAR << "] = " << X[VAR] << '\n';// stl vector,string
#define FOR(X,Y) for ((X) = 0;(X) < (Y);(X)++)
#define gc getchar
int getint(){ unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }

int con[16][16];

// code :
int main (){
	ios_base::sync_with_stdio(false);
	int n, m, i, j, k;
	map <string, int> ID;
	string a, b;
	cin >> n >> m;
	string name[16];

	for (i = 0; i < n; i++) cin >> name[i];
	sort(name, name+n);
	for (i = 0; i < n; i++) ID[name[i]] = i;

	for (i = 0; i < m; i++){
		cin >> a >> b;
	        con[ID[a]][ID[b]] = 1;
		con[ID[b]][ID[a]] = 1;
	}
	int ans = 0, idd;
	for (i = 0; i < (1 << n); i++){
		bool flag = 1;
		int cnt = 0;
		for (j = 0; j < n; j++){
			if (0 == ((1 << j) & i) ) continue;
			cnt++;
			for (k = j+1; k < n; k++){
				if (0 == ((1 << k)& i)) continue;
				if (con[j][k]) {flag = 0; break;}
			}
			if (!flag) break;
		}

		if (flag && cnt > ans){
			ans = cnt;
			idd = i;
		}

	}
	cout << ans << endl;
	for (i = 0; i < n; i++){
		if ((1 << i) & idd) cout << name[i] << endl;
	}

	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct node
{
    string str1,str2;
}limit[1000];
vector<string> per;
int fun(int);
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    string temp;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        per.push_back(temp);
    }
    for(int i=0;i<m;i++)
    {
        cin>>limit[i].str1>>limit[i].str2;
    }
    sort(per.begin(),per.end());

    int max=0,ans;
    for(int i=0;i<(1<<n);i++)
    {
        int temp=fun(i);
        if(temp>max)
        {
            max=temp;
            ans=i;
        }
    }
    cout<<max<<endl;
    for(int i=0;i<n;i++)
    {
        if(ans&(1<<i)) cout<<per[i]<<endl;
    }
    return 0;
}
int fun(int a)
{
    vector<string> temp;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(a&(1<<i))
        {
            temp.push_back(per[i]);
            cnt++;
        }
    }
    bool find1=false,find2=false;
    for(int i=0;i<m;i++)
    {
        find1=false;find2=false;
        for(int j=0;j<temp.size();j++)
        {
            if(temp[j]==limit[i].str1) find1=true;
            if(temp[j]==limit[i].str2) find2=true;
        }
        if(find1&&find2) return 0;
    }
    if(find1&&find2) return 0;
    return cnt;
}

When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.

[{'input': '3 1\nPetya\nVasya\nMasha\nPetya Vasya\n', 'output': ['2\nMasha\nPetya\n']}, {'input': '3 0\nPasha\nLesha\nVanya\n', 'output': ['3\nLesha\nPasha\nVanya\n']}, {'input': '7 12\nPasha\nLesha\nVanya\nTaras\nNikita\nSergey\nAndrey\nPasha Taras\nPasha Nikita\nPasha Andrey\nPasha Sergey\nLesha Taras\nLesha Nikita\nLesha Andrey\nLesha Sergey\nVanya Taras\nVanya Nikita\nVanya Andrey\nVanya Sergey\n', 'output': ['4\nAndrey\nNikita\nSergey\nTaras\n']}, {'input': '2 0\nAndrey\nTaras\n', 'output': ['2\nAndrey\nTaras\n']}, {'input': '16 0\nTaras\nNikita\nSergey\nAndrey\nRomka\nAlexey\nUra\nDenis\nEgor\nVadim\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\n', 'output': ['16\nAlena\nAlexey\nAlice\nAndrey\nBrus\nDenis\nEgor\nJohn\nNikita\nOlya\nRomka\nSergey\nTaras\nUra\nVadim\nVanya\n']}, {'input': '6 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n', 'output': ['4\nAlena\nBrus\nOlya\nVanya\n']}, {'input': '7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n', 'output': ['5\nAlena\nBrus\nMariana\nOlya\nVanya\n']}, {'input': '1 0\nPetr\n', 'output': ['1\nPetr\n']}, {'input': '2 0\nNgzlPJgFgz\nQfpagVpWz\n', 'output': ['2\nNgzlPJgFgz\nQfpagVpWz\n']}, {'input': '2 1\ncLWdg\nGoWegdDRp\nGoWegdDRp cLWdg\n', 'output': ['1\nGoWegdDRp\n']}, {'input': '3 0\nr\nyVwqs\nsdTDerOyhp\n', 'output': ['3\nr\nsdTDerOyhp\nyVwqs\n']}, {'input': '3 3\nvRVatwL\nWmkUGiYEn\nuvvsXKXcJ\nWmkUGiYEn vRVatwL\nuvvsXKXcJ vRVatwL\nuvvsXKXcJ WmkUGiYEn\n', 'output': ['1\nWmkUGiYEn\n']}, {'input': '16 11\njA\nkyRNTE\neY\nToLcqN\nbnenhMxiK\nzlkOe\nXCKZ\neaQrds\nqUdInpi\nKgPQA\nmQIl\ninOCWEZHxy\nyA\nPIZRMOu\nXtueKFM\nfRNwNn\ninOCWEZHxy qUdInpi\nKgPQA zlkOe\ninOCWEZHxy KgPQA\nfRNwNn XCKZ\ninOCWEZHxy eY\nyA mQIl\ninOCWEZHxy ToLcqN\nyA KgPQA\nqUdInpi ToLcqN\nqUdInpi eaQrds\nPIZRMOu eY\n', 'output': ['10\nKgPQA\nPIZRMOu\nToLcqN\nXCKZ\nXtueKFM\nbnenhMxiK\neaQrds\njA\nkyRNTE\nmQIl\n']}, {'input': '12 12\njWuGgOjV\nWs\njTZQMyH\nULp\nUfsnPRt\nk\nbPKrnP\nW\nJOaQdgglDG\nAodc\ncpRjAUyYIW\nMrjB\nbPKrnP ULp\nk Ws\ncpRjAUyYIW k\nULp jTZQMyH\nbPKrnP jWuGgOjV\ncpRjAUyYIW jTZQMyH\nW ULp\nk jTZQMyH\nk ULp\nMrjB ULp\ncpRjAUyYIW Aodc\nW k\n', 'output': ['8\nAodc\nJOaQdgglDG\nMrjB\nUfsnPRt\nW\nWs\nbPKrnP\njTZQMyH\n']}, {'input': '11 17\njFTNgFBO\ntZDgmdF\nIjeDjoj\nBEMAaYkNb\nRZRQl\ntK\nlNHWt\nIdG\nLAbVLYiY\notOBsWqJuo\nUoTy\ntK BEMAaYkNb\nBEMAaYkNb jFTNgFBO\nIjeDjoj tZDgmdF\nRZRQl jFTNgFBO\nlNHWt tZDgmdF\nRZRQl tZDgmdF\nUoTy LAbVLYiY\nBEMAaYkNb IjeDjoj\nIdG BEMAaYkNb\nLAbVLYiY tK\nLAbVLYiY jFTNgFBO\nUoTy IjeDjoj\nlNHWt jFTNgFBO\nlNHWt BEMAaYkNb\ntK IjeDjoj\nUoTy RZRQl\nBEMAaYkNb tZDgmdF\n', 'output': ['6\nIdG\nIjeDjoj\nLAbVLYiY\nRZRQl\nlNHWt\notOBsWqJuo\n']}, {'input': '11 13\ncZAMfd\nSWQnweM\nKlQW\nWRsnNZT\nix\nUC\nLWqsVHcWec\nfeb\ncBy\ntvk\nRXDlX\nfeb SWQnweM\ncBy WRsnNZT\nLWqsVHcWec KlQW\nRXDlX feb\nLWqsVHcWec cZAMfd\ncBy UC\nWRsnNZT SWQnweM\nRXDlX cBy\ntvk UC\ncBy SWQnweM\nUC KlQW\nRXDlX KlQW\nUC WRsnNZT\n', 'output': ['6\nKlQW\nWRsnNZT\ncZAMfd\nfeb\nix\ntvk\n']}, {'input': '4 2\nadQx\nrJGeodBycK\ntgPYZk\ncz\ncz tgPYZk\nrJGeodBycK adQx\n', 'output': ['2\nadQx\ncz\n']}, {'input': '4 2\noVemoZhjW\nHspFEry\nhFO\njxt\nhFO HspFEry\njxt oVemoZhjW\n', 'output': ['2\nHspFEry\njxt\n']}, {'input': '5 2\niBrgNFlNXd\nlnGPIV\nnb\nB\nVgqRcEOG\nlnGPIV iBrgNFlNXd\nB iBrgNFlNXd\n', 'output': ['4\nB\nVgqRcEOG\nlnGPIV\nnb\n']}, {'input': '5 1\nWEYUdpYmZp\nfhNmMpjr\nydARivBg\ncilTtE\nyeXxkhPzB\nyeXxkhPzB cilTtE\n', 'output': ['4\nWEYUdpYmZp\ncilTtE\nfhNmMpjr\nydARivBg\n']}, {'input': '6 9\noySkmhCD\nUIKWj\nmHolKkBx\nQBikssqz\nZ\nzoFUJYa\nZ UIKWj\nQBikssqz oySkmhCD\nQBikssqz UIKWj\nZ oySkmhCD\nzoFUJYa UIKWj\nzoFUJYa Z\nzoFUJYa mHolKkBx\nzoFUJYa QBikssqz\nQBikssqz mHolKkBx\n', 'output': ['3\nUIKWj\nmHolKkBx\noySkmhCD\n']}, {'input': '6 1\nuPVIuLBuYM\nVejWyKCtbN\nqqjgF\nulBD\nDRNzxJU\nCOzbXWOt\nulBD qqjgF\n', 'output': ['5\nCOzbXWOt\nDRNzxJU\nVejWyKCtbN\nqqjgF\nuPVIuLBuYM\n']}, {'input': '7 14\nFXCT\nn\no\nS\nMdFuonu\nmszv\nbqScOCw\nS o\nbqScOCw FXCT\nMdFuonu o\no n\nbqScOCw n\nmszv S\nbqScOCw MdFuonu\nmszv n\nS FXCT\nbqScOCw o\no FXCT\nmszv MdFuonu\nmszv FXCT\nbqScOCw mszv\n', 'output': ['3\nFXCT\nMdFuonu\nn\n']}, {'input': '7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZNeTyY\nm j\n', 'output': ['5\nUj\nZ\na\nm\nsuaaSiKcK\n']}, {'input': '8 6\nU\nC\nPEElYwaxf\nVubTXNI\nJ\nIxZUHV\nhLNFnzmqFE\nDPPvwuWvmA\nhLNFnzmqFE IxZUHV\nIxZUHV C\nJ PEElYwaxf\nIxZUHV PEElYwaxf\nPEElYwaxf C\nJ VubTXNI\n', 'output': ['5\nC\nDPPvwuWvmA\nJ\nU\nhLNFnzmqFE\n']}, {'input': '8 12\nBkgxqAF\nKhq\nNpIfk\nkheqUyDVG\niRBkHlRpp\nZDaQY\nNG\nqN\nqN BkgxqAF\nNpIfk BkgxqAF\niRBkHlRpp BkgxqAF\niRBkHlRpp NpIfk\nNG Khq\niRBkHlRpp Khq\nNG ZDaQY\nNG iRBkHlRpp\nNG NpIfk\nqN Khq\nZDaQY kheqUyDVG\nNpIfk Khq\n', 'output': ['3\nBkgxqAF\nKhq\nZDaQY\n']}, {'input': '9 5\nRFiow\naxgvtiBGbx\ngGBVZtI\nVWAxrqx\nmnASVEQI\ntZHzWGAvXc\nBeaCYhIRLy\nhTdUL\nFJd\nhTdUL RFiow\nhTdUL gGBVZtI\nFJd axgvtiBGbx\nFJd BeaCYhIRLy\nhTdUL axgvtiBGbx\n', 'output': ['7\nBeaCYhIRLy\nRFiow\nVWAxrqx\naxgvtiBGbx\ngGBVZtI\nmnASVEQI\ntZHzWGAvXc\n']}, {'input': '9 13\nYiUXqlBUx\nQNgYuX\ndPtyZ\nITtwRJCv\nLJ\nrAG\nOgxNq\nsitechE\nvVAAz\nOgxNq QNgYuX\nOgxNq dPtyZ\nsitechE rAG\nLJ QNgYuX\nQNgYuX YiUXqlBUx\nOgxNq LJ\nvVAAz OgxNq\nrAG dPtyZ\nvVAAz LJ\nvVAAz ITtwRJCv\nsitechE LJ\nrAG YiUXqlBUx\nsitechE QNgYuX\n', 'output': ['4\nITtwRJCv\nLJ\nYiUXqlBUx\ndPtyZ\n']}, {'input': '9 6\nfLfek\nEQPcotnrp\nCaAlbwoIL\nVG\nNAZKIBiKT\noFy\njFluh\nKqHXRNya\nQSwgobA\noFy EQPcotnrp\nKqHXRNya jFluh\noFy NAZKIBiKT\njFluh oFy\njFluh fLfek\noFy fLfek\n', 'output': ['7\nCaAlbwoIL\nEQPcotnrp\nKqHXRNya\nNAZKIBiKT\nQSwgobA\nVG\nfLfek\n']}, {'input': '9 14\nmoRNeufngu\nBSKI\nzXl\ngwmIDluW\nYFn\nHvasEgl\nXcAC\neVP\nAiOm\neVP BSKI\neVP YFn\nHvasEgl YFn\neVP XcAC\nAiOm HvasEgl\nXcAC YFn\nzXl moRNeufngu\neVP zXl\nHvasEgl BSKI\nXcAC gwmIDluW\nXcAC HvasEgl\nYFn moRNeufngu\nzXl BSKI\nHvasEgl gwmIDluW\n', 'output': ['4\nAiOm\nBSKI\nYFn\ngwmIDluW\n']}, {'input': '15 8\ncXeOANpvBF\nbkeDfi\nnsEUAKNxQI\noSIb\naU\nXYXYVo\nduZQ\naPkr\nPVrHpL\nmVgmv\nhHhukllwbf\nGkNPGYVxjY\nbgBjA\nslNKCLIlOv\nmPILXy\nbgBjA cXeOANpvBF\nGkNPGYVxjY cXeOANpvBF\nslNKCLIlOv GkNPGYVxjY\nGkNPGYVxjY mVgmv\nXYXYVo cXeOANpvBF\nslNKCLIlOv bkeDfi\nmVgmv aPkr\nslNKCLIlOv nsEUAKNxQI\n', 'output': ['12\nGkNPGYVxjY\nPVrHpL\nXYXYVo\naPkr\naU\nbgBjA\nbkeDfi\nduZQ\nhHhukllwbf\nmPILXy\nnsEUAKNxQI\noSIb\n']}, {'input': '15 3\na\nYclKFJoaIA\nhalYcB\nbLOlPzAeQ\ntckjt\noDFijpx\nb\npz\nVDLb\nlCEHPibt\noF\npzJD\nMC\nqklsX\nTAU\npzJD tckjt\nqklsX oF\nMC pzJD\n', 'output': ['13\nMC\nTAU\nVDLb\nYclKFJoaIA\na\nb\nbLOlPzAeQ\nhalYcB\nlCEHPibt\noDFijpx\noF\npz\ntckjt\n']}, {'input': '16 8\nJIo\nINanHVnP\nKaxyCBWt\nkVfnsz\nRAwFYCrSvI\nF\nvIEWWIvh\nTGF\nFeuhJJwJ\nTngcmS\nSqI\nRmcaVngp\neGwhme\nlwaFfXzM\noabGmpvVH\nTMT\nFeuhJJwJ F\neGwhme FeuhJJwJ\nRmcaVngp SqI\nINanHVnP JIo\nSqI FeuhJJwJ\nF kVfnsz\nTGF F\nTMT TGF\n', 'output': ['11\nF\nINanHVnP\nKaxyCBWt\nRAwFYCrSvI\nRmcaVngp\nTMT\nTngcmS\neGwhme\nlwaFfXzM\noabGmpvVH\nvIEWWIvh\n']}, {'input': '16 25\nbBZ\nEr\nZ\nrYJmfZLgmx\nPaJNrF\naHtRqSxOO\nD\nhsagsG\nMDuBOXrmWH\nSgjMQZ\nYXgWq\nxDwpppG\nSDY\nJwZWx\ncOzrgrBaE\nFJYX\nYXgWq SgjMQZ\nSDY PaJNrF\nFJYX rYJmfZLgmx\nhsagsG Er\nxDwpppG rYJmfZLgmx\naHtRqSxOO rYJmfZLgmx\nhsagsG bBZ\nJwZWx hsagsG\nFJYX cOzrgrBaE\nSDY YXgWq\nFJYX Z\nJwZWx rYJmfZLgmx\nD rYJmfZLgmx\nYXgWq Z\nrYJmfZLgmx Z\naHtRqSxOO bBZ\nSDY rYJmfZLgmx\ncOzrgrBaE D\nYXgWq hsagsG\nSDY aHtRqSxOO\ncOzrgrBaE xDwpppG\nSDY bBZ\nSDY Er\nJwZWx xDwpppG\nFJYX JwZWx\n', 'output': ['8\nD\nEr\nJwZWx\nMDuBOXrmWH\nPaJNrF\nSgjMQZ\nZ\naHtRqSxOO\n']}, {'input': '16 37\ntIWi\nq\nIEAYCq\nXozwkum\nCC\niPwfd\nS\nXEf\nWqEiwkH\nWX\ne\nltmruh\nKGx\nauTUYZRC\nmeJa\nM\nmeJa q\nKGx e\nXEf Xozwkum\ne q\nauTUYZRC KGx\ne CC\nM CC\nM meJa\nWX CC\nWqEiwkH IEAYCq\nauTUYZRC WqEiwkH\nKGx WX\nmeJa KGx\nXEf q\nauTUYZRC XEf\nauTUYZRC IEAYCq\nWX XEf\nM XEf\nWqEiwkH q\nM KGx\nKGx CC\nM e\nWqEiwkH Xozwkum\nCC q\nS Xozwkum\nKGx tIWi\nWX q\nXEf S\nauTUYZRC S\nCC IEAYCq\nKGx IEAYCq\ne WqEiwkH\nM S\nauTUYZRC q\nS tIWi\nM ltmruh\nM iPwfd\n', 'output': ['8\nIEAYCq\nWX\nXozwkum\ne\niPwfd\nltmruh\nmeJa\ntIWi\n']}, {'input': '16 11\ntulhZxeKgo\nbrAXY\nyQUkaihDAg\nmwjlDVaktK\nweVtBIP\nzRwb\nds\nhXPfJrL\nAdIfP\nazQeXn\nB\nJlmscIUOxO\nZuxr\nV\nOfyLIUO\nuaMl\nhXPfJrL yQUkaihDAg\nweVtBIP yQUkaihDAg\nazQeXn hXPfJrL\nV tulhZxeKgo\nzRwb yQUkaihDAg\nds mwjlDVaktK\nzRwb brAXY\nyQUkaihDAg brAXY\nB yQUkaihDAg\nAdIfP mwjlDVaktK\nbrAXY tulhZxeKgo\n', 'output': ['11\nAdIfP\nB\nJlmscIUOxO\nOfyLIUO\nV\nZuxr\nazQeXn\nbrAXY\nds\nuaMl\nweVtBIP\n']}, {'input': '5 10\nTaras\nNikita\nSergey\nAndrey\nRomka\nTaras Romka\nTaras Nikita\nTaras Sergey\nTaras Andrey\nRomka Nikita\nRomka Sergey\nRomka Andrey\nNikita Sergey\nNikita Andrey\nSergey Andrey\n', 'output': ['1\nAndrey\n']}]


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define MAXN 110
#define TOT 0xff

int N;

struct Node {
    int id;
    Node *next[52];
} node[MAXN*MAXN], *root;
int n_tot;

int mark[MAXN];

int main_ ()
{
    scanf ("%d\n", &N);
    int l0, l1;
//-4: (; -3: ); -2: inputing token; -1: null; 0: c; 1~4: +,-,*,/
    root = node; n_tot = 1;
    memset (node, 0, sizeof(node));
    char ch[MAXN];
    for (int i = 1; i <= N+1; i++)
    {
        l0 = l1 = -1;
        if (i <= N)
        {
            memset (ch, 0, sizeof(ch));
            scanf ("%*[ #]%*[define] %s ", ch);
//          cerr << '_' << ch << endl;
        }
        mark[i] = TOT;
        char c;
        Node *x = 0;
        int cnt = 0, t;
        while (1)
        {
            scanf ("%c", &c);
//          cerr << c;
            if (c == '\n')
            {
                if (l0 == -2 && x && x->id && !mark[x->id]) mark[i] = 0;
                if (l1 == -1 && l0 == -2 && x && x->id) mark[i] &= mark[x->id]|0xf0;
                if (l0 == -2 && x && x->id && l1 != -1 && !(mark[x->id]&(1<<(l1-1))))
                    mark[i] = 0;
                if (l0 == -2 && x && x->id) mark[i] &= mark[x->id]|0xf;
                break;
            }
            if (c == ' ') continue;
            if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
            {
                t = c- (c>='a'? 'a': 'A'-26);
                if (l0 != -2) {l1 = l0; l0 = -2; x = root;}
                if (x) x = x->next[t];
            }
            else if ('0' <= c && c <= '9')
            {
                if (l0) {l1 = l0; l0 = 0;}
            }
            else if (c == '(')
            {
                cnt++;
                l1 = l0; l0 = -4;
            }
            else if (c == ')')
            {
                if (l0 == -2 && x && x->id && !mark[x->id]) {mark[i] = 0; break;}
                if (l0 == -2 && x && x->id && l1 != -4 && !(mark[x->id]&(1<<(l1-1))))
                {
                    mark[i] = 0;
                    break;
                }
                l1 = l0; l0 = -3;
                cnt--;
            }
            else
            {
                if (l0 == -2 && x && x->id && !mark[x->id]) {mark[i] = 0; break;}
                if (l1 == -1 && l0 == -2 && x && x->id) mark[i] &= mark[x->id]|0xf0;
                t = c=='+'? 1: c=='-'? 2: c=='*'? 3: 4;
                if (!cnt)
                {
                    if (t <= 2) mark[i] &= 0x1|0x10|0x20;
                    else mark[i] &= TOT-0x8;
                }
                if (l0 == -2)
                {
                    if (x && x->id &&
                            ((l1 != -4 && l1 != -1 && !(mark[x->id]&(1<<(l1-1))))
                        || !(mark[x->id]&(1<<(t+3)))))
                        mark[i] = 0;
                }
                l1 = l0; l0 = t;
            }
        }
        while (c != '\n') scanf ("%c", &c);
        int pos = 0;
        x = root;
        while (ch[pos])
        {
            int t = ch[pos]- (ch[pos]>='a'? 'a': 'A'-26);
            if (!x->next[t]) x->next[t] = &node[n_tot++];
            x = x->next[t];
            pos++;
        }
        x->id = i;
    }
    printf ("%s\n", mark[N+1]? "OK": "Suspicious");

    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j < 8; j++)
            cerr << !!(mark[i]&(1<<j)) << ' ';
        cerr << endl;
    }

    return 0;
}

int main ()
{
    int T;
//  scanf ("%d", &T);
    T = 1;
    while (T--) main_ ();
    return 0;
}

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include <sstream>
#include <numeric>
#include <climits>
#include <cctype>
#include <ctime>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;

enum Token {
	addend, multiplier, expression, suspicious
};

map<string, Token> def;

bool check(const string &str, int l, int r) {
	int cnt = 0;
	for (int i = l; i < r; ++i) {
		if (str[i] == '(')
			cnt++;
		else if (str[i] == ')')
			cnt--;
		if (cnt < 0)
			return false;
	}
	return cnt == 0;
}

int level(char x) {
	return x == '+' || x == '-' ? 0 : x == '/' || x == '*' ? 1 : 2;
}

Token calc(string str) {
	bool brackets = false;
	while (int(str.size()) >= 2 && str[0] == '(' && str[int(str.size()) - 1] == ')' && check(str, 1, int(str.size()) - 1)) {
		str.erase(0, 1);
		str.erase(int(str.size()) - 1, 1);
		brackets = true;
	}

	char op = 'o';
	int cnt = 0, index;
	for (int i = 0; i < (int)str.size(); ++i) {
		if (str[i] == '(')
			cnt++;
		else if (str[i] == ')')
			cnt--;
		else if (level(str[i]) <= level(op)) {
			index = i;
			op = str[i];
		}
	}
	if (level(op) == 2) {
		if (def.count(str))
			return def[str] == suspicious ? suspicious : brackets ? expression : def[str];
		else
			return expression;
	}

	Token part[2] = {calc(str.substr(0, index)), calc(str.substr(index + 1, (int)str.size()))};
	if (part[0] == suspicious || part[1] == suspicious)
		return suspicious;
	if (op == '+' || op == '-') {
		if (op == '-' && part[1] == addend)
			return suspicious;
		return brackets ? expression : addend;
	} else if (op == '/' || op == '*') {
		if (part[0] == addend || part[1] == addend)
			return suspicious;
		if (op == '/' && part[1] == multiplier)
			return suspicious;
		return brackets ? expression : multiplier;
	}
	return suspicious;
}

Token parse() {
	string str;
	getline(cin, str);
	string buf;
	for (int i = 0; i < (int)str.size(); ++i)
		if (str[i] != ' ')
			buf.push_back(str[i]);
	str = buf;
	return calc(str);
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		scanf(" #%*sdefine");
		string a, b;
		cin >> a;
		def[a] = parse();
	}
	scanf(" ");
	cout << (parse() == suspicious ? "Suspicious" : "OK") << endl;
}

Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use.In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. The generic syntax for declaring a macro is the following:#define macro_name macro_valueAfter the macro has been declared, "macro_name" is replaced with "macro_value" each time it is met in the program (only the whole tokens can be replaced; i.e. "macro_name" is replaced only when it is surrounded by spaces or other non-alphabetic symbol). A "macro_value" within our model can only be an arithmetic expression consisting of variables, four arithmetic operations, brackets, and also the names of previously declared macros (in this case replacement is performed sequentially). The process of replacing macros with their values is called substitution.One of the main problems arising while using macros — the situation when as a result of substitution we get an arithmetic expression with the changed order of calculation because of different priorities of the operations.Let's consider the following example. Say, we declared such a #define construction:#define sum x + yand further in the program the expression "2 * sum" is calculated. After macro substitution is performed we get "2 * x + y", instead of intuitively expected "2 * (x + y)".Let's call the situation "suspicious", if after the macro substitution the order of calculation changes, falling outside the bounds of some macro. Thus, your task is to find out by the given set of #define definitions and the given expression if this expression is suspicious or not.Let's speak more formally. We should perform an ordinary macros substitution in the given expression. Moreover, we should perform a "safe" macros substitution in the expression, putting in brackets each macro value; after this, guided by arithmetic rules of brackets expansion, we can omit some of the brackets. If there exist a way to get an expression, absolutely coinciding with the expression that is the result of an ordinary substitution (character-by-character, but ignoring spaces), then this expression and the macros system are called correct, otherwise — suspicious.Note that we consider the "/" operation as the usual mathematical division, not the integer division like in C/C++. That's why, for example, in the expression "a*(b/c)" we can omit brackets to get the expression "a*b/c".

[{'input': '1\n#define sum x + y\n1 * sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum  (x + y)\nsum - sum\n', 'output': ['OK\n']}, {'input': '4\n#define sum  x + y\n#define mul  a * b\n#define div  a / b\n#define expr sum + mul * div * mul\nexpr\n', 'output': ['OK\n']}, {'input': '3\n#define SumSafe   (a+b)\n#define DivUnsafe  a/b\n#define DenominatorUnsafe  a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/DenominatorUnsafe)\n', 'output': ['Suspicious\n']}, {'input': '0\naa + b - c * (ddd * eee / fff * a / b * c + d - b + c - (a + b)) - d\n', 'output': ['OK\n']}, {'input': '2\n#define a b\n#define c d\na + b + c + d + 1234567 -10*(2-2+1000*1000*1000*1000*1000)\n', 'output': ['OK\n']}, {'input': '2\n  #  define  macros    (  x  +  y  ) \n # define  Macros (x+y)\nmacros/Macros\n', 'output': ['OK\n']}, {'input': '2\n#define A v\n#define a v/v/v\nv/A\n', 'output': ['OK\n']}, {'input': '2\n#define A v\n#define a v/v/v\nv/a\n', 'output': ['Suspicious\n']}, {'input': '2\n#define A v\n#define a v/v/v\nv/(a)\n', 'output': ['OK\n']}, {'input': '1\n#define a x*y\nc/a\n', 'output': ['Suspicious\n']}, {'input': '1\n#define a b*c\na/a*a\n', 'output': ['Suspicious\n']}, {'input': '3\n#define mul  x*y\n#define bad  x/mul\n#define good x/(mul)\ngood\n', 'output': ['OK\n']}, {'input': '4\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define mult   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nsum+difference+(sum)*(difference)-mult+mult*division+division*mult+division/(mult+sum-(difference))\n', 'output': ['OK\n']}, {'input': '4\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define multiplication   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(difference/division)+sum\n', 'output': ['Suspicious\n']}, {'input': '4\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define multiplication   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(difference)*sum\n', 'output': ['Suspicious\n']}, {'input': '4\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define multiplication   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(sum)/multiplication\n', 'output': ['Suspicious\n']}, {'input': '4\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define multiplication   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nsum/(multiplication)\n', 'output': ['Suspicious\n']}, {'input': '5\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define multiplication   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n#define res (0-difference)\nsum+res*multiplication\n', 'output': ['Suspicious\n']}, {'input': '4\n#define sum   xx+yy\n#define difference  aaaa-bbbBBBB\n#define multiplication   a*b\n#define division  aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ndivision/(multiplication/(division)/DIVISION/(sum-division-multiplication-(difference)))\n', 'output': ['OK\n']}, {'input': '3\n#define sum  x + y\n#define SomeBad  (2 * sum)\n#define SomePossiblyGood  0 * SomeBad + (x + x - 2*x) * SomeBad\nSomePossiblyGood\n', 'output': ['Suspicious\n']}, {'input': '2\n#define a  0\n#define b  (a-a)*(x/x-1)\nb-b/b*b\n', 'output': ['Suspicious\n']}, {'input': '2\n#define fkdsjfslkjfsdk x/0\n#define fkdsjfslkjfsdksdds 0/(0-0)\nfkdsjfslkjfsdk + fkdsjfslkjfsdks + fkdsjfslkjfsdkssds\n', 'output': ['OK\n']}, {'input': '3\n#define null x/0\n#define some x/x\n#define bad 1/x\nbad/0+0/bad+0/0*bad\n', 'output': ['Suspicious\n']}, {'input': '3\n#define MWjGY x+x*53 *x\n#define ovqZ 2/926+x/A\n#define uU 55-qRj*A*2\nx*A/x-A\n', 'output': ['OK\n']}, {'input': '4\n#define zz 5+7/x*x*9\n#define mlTL 6+x/7+x/x\n#define DUO 7*7-x+zz\n#define IH 6*4-x+x\n67/(5)-IH\n', 'output': ['Suspicious\n']}, {'input': '5\n#define Oc 9/51+65+vN\n#define gga 53/ 94/x/x\n#define ArB x/x/9-77-8\n#define j 76-6/93+vN\n#define cALNN Oc+60499\n8*6-66/x*x\n', 'output': ['OK\n']}, {'input': '3\n#define fSdvwOj (W)*W+73\n#define NAZjc 7695*55-x\n#define AHGGglVwch (6-a-W)\n((5))+W+W\n', 'output': ['OK\n']}, {'input': '4\n#define m bJJD +x \n#define yYkQNzjR (x*19)-892\n#define MNvfxqfbq (x-6*x/8)\n#define nJZdvO 8/4 *m/m\n 9+m/x+x\n', 'output': ['Suspicious\n']}, {'input': '5\n#define Sl x*7-(x)/O\n#define srAOHccTln 3+x*2*O\n#define OFAZk 239751817\n#define JYWrOEgazV (x-O/4)-x\n#define XsOZvalgOh 89905879/7\nx/Sl-(Sl)\n', 'output': ['Suspicious\n']}, {'input': '3\n#define uYdw ((9-x-3) )\n#define fy (((x+21)))\n#define nY ((2+x)-46)\n141141432\n', 'output': ['OK\n']}, {'input': '4\n#define GCvqH (58 )-(x)\n#define g ((x/x+x))\n#define spst hQTJ\n#define i GCvqH\n(((x+6)))\n', 'output': ['OK\n']}, {'input': '5\n#define rg (67)+((x))\n#define ya x-(6/x)*rg\n#define anTxe 10*ya*(x)\n#define xcmo ((x)*(vT))\n#define eg ((vT)) -ya\n((x*(Ii)))\n', 'output': ['OK\n']}, {'input': '3\n#define T ((b/1 +1))\n#define pm (s)-43-(s)\n#define jkNBpvDZl ((x ))/65\n(((58*7)))\n', 'output': ['OK\n']}, {'input': '4\n#define cJitUt 21/(4)+4+4\n#define zHwBOLIvF 4*((41/x))\n#define GbtYVo (E)+(x+3)\n#define zTcZBaby (58)+x-x+x\n(E+E)/8 *4\n', 'output': ['OK\n']}, {'input': '5\n#define mBURKdeKvy 266693986\n#define nWi ( ((x))-4)\n#define iYreeOt ((7/x+42))\n#define laLzP ((aB/35)) \n#define dXjRJ (((B*hX)))\n(1*2+(67))\n', 'output': ['OK\n']}, {'input': '3\n#define UVMQLGvEqOxaAgRkvJH tBd\n#define QoAsBMaUcJzXai x/x-hm/83+8*8/5/hm /x/hm\n#define QtxtzEHCmidm 75 +491928441\n((x)/VUpYoEdDUtLFanGyqfQR  )\n', 'output': ['OK\n']}, {'input': '4\n#define efemx 2/1*3*69+81+10/690445104\n#define AyjrEzAjMKZpRPfCOaO 21*9+( j*40+3*4)*ND+w-j*j+x*55\n#define YkJkHcNhXcci 85*3215/40/365819568\n#define MUzvOZSXJujI 9-4/j*j-7-w*23*5+j+9-9*ND*2/37\nND/j*28 -1* ND+22889023/j/j/j\n', 'output': ['OK\n']}, {'input': '5\n#define QNUkjqPcGWF 6*4/908975666-7/10-x*7\n#define xqwhNWiiMaZOcmgiXYY 3936*(e*5*H+2)-TsA+(e)/1-25\n#define tRsSqfqJt ((uT*82/e)+e/(23+(45)-9)+(50))\n#define DtIOWRkYe (8*3/9)*e*x *60041512*2-(e)\n#define qgPgxja (4/x+e/uT*16358009- 6/13*5)\ne+x*e/84/x+uT*H\n', 'output': ['OK\n']}, {'input': '3\n#define lTCUUO JQmj\n#define oUeQMB (12*x+x+x)-75-(79/1)-(7)*1/mr\n#define LAQu xwvBtky\n8654 *1*5-mr-3*J/oUeQMB/x/6/9\n', 'output': ['Suspicious\n']}, {'input': '4\n#define VLuQIO 1-x/33+ Fk+wS/35-wS-(x*iz )\n#define BCIsIR 5*(wS)/x/iz/1+x-x-4-x/68/x/8*x\n#define QPUpmTiB 21-x/895912506+2\n#define wcZLUIqJS 7/65-x*61-(24+iz)+x+315670+x/x\nBCIsIR/VLuQIO\n', 'output': ['Suspicious\n']}, {'input': '5\n#define FDmMYOENCOKmYwYlOl 6-(L)/((((ud/x))/ud-26*8-5))\n#define QkopKBjKdJxhc (6)*4/7-L/781844832  \n#define UjgTieUBXTSTbiLFAhkV 3*1*(52)/6-6*65/x+((L-56))+x+x\n#define yWVYDuqliezpKLwnI 8/4+1+88+97946+(1)-((68))-L/L\n#define AvvED 719901121+95/2/78/1-10+37\n(1*x+ 528176190+17/ud)\n', 'output': ['OK\n']}, {'input': '3\n#define e x *R/5+(x)+4/18/x*R/x-8+1+R\n#define GgGqGYjXoJjIezAVu (( 491563947*R))*9-e-3/4\n#define XgznGUWMxQwh (8/R+4*(e)+10/4*x+24*R+21)-224\n (82493582)\n', 'output': ['OK\n']}, {'input': '4\n#define MrKSTrKhPLeJqOcEPvv (x+x/x)/Qdf-x-x-(2/23)+9442-x\n#define zPHUgmIYE 10- 7*x/x+VwRUuIRezDR*80\n#define OsfThxasHeFZCEZTfD 271456028-(x*x)-8+2*x*x*x+(x)\n#define zVYasB x/x -x-(51)-x*x*((x))  /x \n(x/64-x*( (5+x+x)-(37)/3*22))\n', 'output': ['OK\n']}, {'input': '5\n#define WREol (fcdGZaLzhiFpVQmhHO)\n#define lDTNxcMqPPP 3+(57)/x/91540-x*71-x*6-((1))\n#define afFJVBkr ((12*x-8+9 *lDlx+7+lDlx))\n#define mYEizEWrNtRSQNCcDQrn 732480960+9+x-78-x/1+12*x\n#define IZTmjheAahbNSNFa ((x-x*7+407643063 ))\nXQvMxLNpQnhpimNhAkfX\n', 'output': ['OK\n']}, {'input': '3\n#define Mc x+x*55231- x/x/x+35/x*(5*(x)) -5*x*(1-2-(29/1))\n#define afSVLCdjvylSu bgqv/6+4*x*((Mc/1318/x-8-4)-Mc/Mc/(9))\n#define ZOSV (1+2/x+6* 174806683)-x/x*Mc+52*x-x\nbgqv-x-6*x/72/(x )/afSVLCdjvylSu\n', 'output': ['Suspicious\n']}, {'input': '4\n#define RJIiiGQqn dmpWFcrqQeM+V-o* 55/9*o-o/V*V*o\n#define ElDZlrtzDkeKgsX 498718105* 3/(y)/(4)-(5*x)*1\n#define qwKl jHqPHX\n#define qXzAZkCuchBYR  (qy*qwKl-6+5*1+2)-7-3+(38)-o*4/4-1-V*x/6+1*x/o\no*((V))-o+2+((((2*V)/V-o*V/4)))/o*33+y/7  -x+x \n', 'output': ['OK\n']}, {'input': '5\n#define WTovyGexUNjGMRJv (MQG*18-6)/x/x*x/x-x*akNyw*x+x-x/2/x*20\n#define hpextyhVCa 70*x/67-x*87931-(497612505-7*x-MQG)-x\n#define MRkKnCXFt x-5-21962-x/sOmThNSS/x/6-4+(65+57+x+x+7-7+x/x)\n#define ajsczBLLklBSqqh nGj-38*9 *x/47/8*5/5-72/x*x-x*x*31  /7-44-3+64\n#define jgqfv WTovyGexUNjGMRJv\n  4+338/x*x+13 -795*3-74*2/4+563-x/76401438/83025\n', 'output': ['OK\n']}, {'input': '3\n#define G u+13-35348/2-(u/u)-u/u*u*(OC)-OC -u-u/u*u/9 \n#define RNRQ G*G*u+G/755750/G/G +((u-6*G+6)*2)- 5*96+5/u*275-u\n#define Zg 94363/u*u-41+Gm*G-81/5-1-G*G*x-(5517*5/4)*21 +75\n406690013/WM*G+(u+u)*Zg+2\n', 'output': ['Suspicious\n']}, {'input': '4\n#define RMWAZhIp x*x+12+94*12*5*1-x-141915293\n#define EeguG 9-55+x/29+x+x/E*8*81/x-x*75-4*17-81/x/6+619978*x*x\n#define HvUYEvQTyYmBGvqHSb 454574730/644135926*x/23+E-sy/14\n#define BqMGcT x/(43)+819897061-x*(7/x)-(x)+sy-E-x*79-E+(x)/6/63\n76+3/x/8*x+E-76+sy-sy+9*6/66/sy-77+x-x*sy+E/50/64\n', 'output': ['OK\n']}, {'input': '5\n#define cbt ((((d))+9-3+ (d)/d/6*SDDNqj*50/d+d-m+8/d/1)) \n#define gLrUE 18+ 70*d/3-d*d-d/35 +33-5/9+d-d*387+d-1\n#define AvjmK 9-d-8+(d+m+5/2/x*d+1)/x/d-5-2*(m)+d+17/d+ 4/52/8\n#define SjrJ 90/7/5/d+ 254877982+(m) *x-19\n#define PlykoqfDbwxR  540304590 +d*x/11-(m+d-d-4)*(d-3-1)/d\nd-2+1+46-29620+9-(9*3 /d)*6*m/d+9+(1670)/cbt/d+d\n', 'output': ['OK\n']}, {'input': '3\n#define BuAiJLgAlkj x-3+419032556/409023036-(17*84)+x+8+A\n#define wU 516506880\n#define HeyDGlnaGxBaHjzelvF iRSPqHfgHw/4-(99)*(I)+A+I-9*46*x\nI/CRklg-HeyDGlnaGxBaHjzelvF/3+5 \n', 'output': ['Suspicious\n']}, {'input': '4\n#define SOlTohcPGckDyF ((D)/G-83+KHGSuJFLHqD/5)\n#define KEUXeOYpg 9+x-8-8/x/9-65-6+4+55*x-58/x+84+D*2-7+D/x-x*G/4-2\n#define YZl (1/67*x*6/2*G)-D/1595107*D+6/x*1+D+3/9/x/26-6+9 \n#define gCatFsZn uBBqilYclMhpVfKKTkGK\n(28682537+ YZl*(4*52)  )*x/8- gCatFsZn*x/54/7\n', 'output': ['Suspicious\n']}, {'input': '5\n#define iiXEqDYeyVmIYsOaO fj/x-9-6/x*x+ 1/ 7*2-x -x+9+235*23*Ww+x-2*K+2-x/70\n#define XVgLzhoTUxoBr ( x+x/x/x*6-x)* x+K/24206-2 /5/8-x-7/Ww/K-x+6 \n#define QdfRBaJk 470551685-(  54-x)-30\n#define gEJcAGnF x+x-x+(x/x+9)/x-41-1/fj/1157561+x/x -x/26/x+K*x\n#define lO 7-1*(x*58 )-K*fj  /722113691/x/K+2\n2+4*85/86/x*27 /49252-x*x/6-83-7/x+x+K-lO+8-K-x\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x+y\nr-sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x+y\nr+sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x+y\nr*sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x+y\nr/sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x-y\nr+sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x-y\nr-sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x-y\nr*sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x-y\nr/sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x*y\nr+sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x*y\nr-sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x*y\nr*sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x*y\nr/sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x/y\nr+sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nr-sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nr*sum\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nr/sum\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x+y\nsum+r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x+y\nsum-r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x+y\nsum*r\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x+y\nsum/r\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x-y\nsum+r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x-y\nsum-r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x-y\nsum*r\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x-y\nsum/r\n', 'output': ['Suspicious\n']}, {'input': '1\n#define sum x*y\nsum+r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x*y\nsum-r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x*y\nsum*r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x*y\nsum/r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nsum+r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nsum-r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nsum*r\n', 'output': ['OK\n']}, {'input': '1\n#define sum x/y\nsum/r\n', 'output': ['OK\n']}, {'input': '1\n#define x 3/2\n2*x\n', 'output': ['OK\n']}, {'input': '2\n   #    define     sum     1000000000   +   1000000000       +     1000000000      \n    #    define      a    b     +      45    *   sum    \n       a       \n', 'output': ['Suspicious\n']}]


// =========================================================
//
//       Filename:  prob6D.cpp
//
//    Description:
//
//        Version:  1.0
//        Created:  07/18/2011 09:15:04 AM
//       Revision:  none
//       Compiler:  g++
//
//         Author:  LI YAN (lyan), lyan@cs.ucr.edu
//        Company:  U of California Riverside
//      Copyright:  Copyright (c) 07/18/2011, LI YAN
//
// =========================================================

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
#include <set>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;

#define INF (1<<29)
#define fort(i,a) for(typeof a.begin() i=a.begin(); i!=a.end(); ++i)
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define MP make_pair
#define sz(x) int(x.size())

template<class T>
void chmax(T &a, T b) { a = a>=b ? a:b; }

template<class T>
void chmin(T &a, T b) { a = a<=b ? a:b; }

int n,a,b;
//map<VI,int> memo;
//map<VI,PII> prev;
#define LAST 200
#define DIM 2*LAST+1
int memo[DIM][DIM][15]; // h[p-1], p
int best[DIM][DIM][15];

int calc(VI conf, int p)
{
    if (p>=sz(conf)-1) {
        if (conf[sz(conf)-2]<0 && conf[sz(conf)-1]<0) return 0;
        else return 100;
    }

    if (memo[conf[p-1]+LAST][conf[p]+LAST][p]>=0)
        return memo[conf[p-1]+LAST][conf[p]+LAST][p];

    int ans=100;
    {
        int kmax=0,kmin=0;
        if (conf[p-1]>=0) kmin=conf[p-1]/b+1;
        if (conf[p]>=0) kmax=conf[p]/a+1;
        if (conf[p-1]>=0) chmax(kmax, conf[p-1]/b+1);
        if (conf[p+1]>=0) chmax(kmax, conf[p+1]/b+1);
        assert(kmin<=kmax); //cout << p << ' ' << kmin << ' ' << kmax << endl;

        for(int j=kmin; j<=kmax; ++j) {
            int p1=conf[p-1], p2=conf[p];
        conf[p]-=a*j; conf[p-1]-=b*j; conf[p+1]-=b*j;
        int curr = j+calc(conf,p+1);
        if (curr<ans) { ans=curr; best[p1+LAST][p2+LAST][p]=j; }
        conf[p]+=a*j; conf[p-1]+=b*j; conf[p+1]+=b*j;
        }
    }
    return memo[conf[p-1]+LAST][conf[p]+LAST][p]=ans;
}

void solve()
{
    memset(memo,-1,sizeof memo);
    memset(best,0,sizeof best);
    cin >> n >> a >> b;
    VI h(n); for(int i=0; i<n; ++i) cin >> h[i];

    int kans=calc(h,1); cout << kans << endl;
    VI ans;

    int p1,p2;
    for(p1=0; p1<2*LAST; ++p1) for(p2=0; p2<2*LAST; ++p2)
    if (memo[p1][p2][1]==kans) goto done;
    done:
    int k=best[p1][p2][1];
    for(int i=0; i<k; ++i) ans.PB(2);
    h[0]-=b*k; h[1]-=a*k; h[2]-=b*k;

    for(int i=2; i<n-1; ++i) {
        k = best[h[i-1]+LAST][h[i]+LAST][i]; h[i-1]-=b*k; h[i]-=a*k; h[i+1]-=b*k;
        for(int j=0; j<k; ++j) ans.PB(i+1);
        kans -= k;
    }
    for(int i=0; i<sz(ans); ++i) {
        if (i) cout << ' ';
        cout << ans[i];
    }
    cout << endl;
}

int main()
{
    solve();
}

/*
dfs+最优性剪枝/dp
题意：你是火系法师，对面有一排敌人，每个敌人都有HP，你要向他们扔火球，火球对目标 i 有一个主伤害a，对i+1和i -1有一个溅射伤害b。
法师只能攻击到2号到n-1号，且对于第i个敌人，只有其前面的都死了你才能攻击到那个位置。问你至少要扔多少个火球才能杀死所有敌人，并依次输出每个火球的攻击目标。
*/
#include <bits/stdc++.h>
using namespace std;

int hp[12];
vector<int> cur;
vector<int> best;
int ans=0x3f3f3f3f;
int n,a,b;

void dfs(int x, int times){
    if (times>=ans) return;
    if (x==n){
        if (hp[x]<0){
            best=cur;
            ans=times;
        }
        return;
    }
    for (int i=0; i<=max(hp[x-1]/b+1,max(hp[x]/a+1,hp[x+1]/b+1)); i++){
        if (hp[x-1]-b*i<0){
            hp[x-1]-=b*i;
            hp[x]-=a*i;
            hp[x+1]-=b*i;
            for (int j=0; j<i; j++) cur.push_back(x);
            dfs(x+1,times+i);
            for (int j=0; j<i; j++) cur.pop_back();
            hp[x-1]+=b*i;
            hp[x]+=a*i;
            hp[x+1]+=b*i;
        }
    }

}

int main(){

    cin>>n>>a>>b;
    for (int i=1; i<=n; i++){
        cin>>hp[i];
    }
    dfs(2,0);
    cout<<ans<<endl;
    for (int i=0; i<best.size(); i++) cout<<best[i]<<" ";

    return 0;
}

This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1≤b<a≤10) health points each.As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?Polycarp can throw his fire ball into an archer if the latter is already killed.


#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <bitset>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define li       	long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define pb       	push_back
#define sz(v)    	((li)v.size())
#define bit(n)   	(1ll<<(li)(n))

#define MAX 1005
li n,base[MAX],a[MAX];

li solve(li num,bool flag){
	li res=0;
	rep(i,MAX) a[i]=base[i];
	rep(i,MAX)if(n<=i+num && a[i]) a[i]--;
	for(li i=0;i<n;i++){
		while(a[i]){
			li pos=i;
			while(a[pos]){
				a[pos++]--;
				if(flag) cout<<"AR";
				res+=2;
			}
			if(flag){ cout<<"A"; rep(j,pos-i) cout<<"L"; cout<<"A"; }
			res+=pos-i+2;
		}
		if(flag) cout<<"AR";
		res+=2;
	}
	if(flag){ cout<<"A"; rep(i,num) cout<<"L"; cout<<"A"; cout<<endl;}
	res+=2+num;
	return res;
}

int main(){
	li best=bit(55),best_num=-1;
	cin>>n;
	rep(i,n) cin>>base[i];
	while(n && base[n-1]==0) n--;
	for(li i=0;i<=n;i++){
		li tmp=solve(i,false);
		if(tmp<best){
			best=tmp;
			best_num=i;
		}
	}
	solve(best_num,true);
}

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1005;
int n, p[N], pos;
string ans;

void goRight(int l = 1) {
	for (int i = 0; i < l; ++i) {
		ans += 'A';
		ans += 'R';
		++pos;
	}
}

void goLeft(int l = 1) {
	for (int i = 0; i < l; ++i) {
		ans += 'L';
		--pos;
	}
}

void perform(int l, int r) {
	goRight(r - pos);
	ans += 'A';
	goLeft(pos - l + 1);
	ans += 'A';
	for (int i = l; i <= r; ++i) {
		--p[i];
	}
}

void solve(int l, int r) {
	while (p[l] <= 1 && l <= r) {
		++l;
	}
	if (l > r) {
		return;
	}
	while (p[l] > 1) {
		int cos = l;
		while (p[cos + 1] > 1) {
			++cos;
		}
		perform(l, cos);
	}
	solve(l + 1, r);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", p + i);
	}
	while (!p[n - 1]) {
		--n;
	}
	ans = "";
	pos = -1;
	for (int i = 0; i < n; ++i) {
		goRight();
		if (p[i]) {
			break;
		}
	}
	int lef = pos;
	for (int i = pos; i < n; ++i) {
		while (!p[i]) {
			++i;
		}
		int j = i;
		while (j + 1 < n && p[j + 1]) {
			++j;
		}
		solve(i, j);
		//cleared to 1 = lef - j
		if (lef == -1) {
			lef = i;
		}
		if (j != n - 1) {
			int empty = 0;
			while (p[j + empty + 1] == 0) {
				++empty;
			}
			if (empty > (j - lef + 1) + 3) {
				perform(lef, j);
				lef = -1;
			}
		} else {
			perform(lef, n - 1);
		}
		i = j;
	}
	printf("%s\n", ans.c_str());
	return 0;
}

The Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment n in length not far from the city walls. And only the frost magician Solomon can save the Frost Kingdom. The n-long segment is located at a distance equal exactly to 1 from the castle walls. It can be imaginarily divided into unit segments. On some of the unit segments fire demons are located — no more than one demon per position. Each demon is characterised by his strength - by some positive integer. We can regard the fire demons being idle.Initially Solomon is positioned on the fortress wall. He can perform the following actions several times in a row:  "L" — Solomon shifts one unit to the left. This movement cannot be performed on the castle wall. "R" — Solomon shifts one unit to the left. This movement cannot be performed if there's no ice block to the right. "A" — If there's nothing to the right of Solomon, then Solomon creates an ice block that immediately freezes to the block that Solomon is currently standing on. If there already is an ice block, then Solomon destroys it. At that the ice blocks to the right of the destroyed one can remain but they are left unsupported. Those ice blocks fall down.Solomon spends exactly a second on each of these actions.As the result of Solomon's actions, ice blocks' segments fall down. When an ice block falls on a fire demon, the block evaporates and the demon's strength is reduced by 1. When the demons' strength is equal to 0, the fire demon vanishes. The picture below shows how it happens. The ice block that falls on the position with no demon, breaks into lots of tiny pieces and vanishes without hurting anybody. Help Solomon destroy all the Fire Lord's army in minimum time.

[{'input': '3\n1 0 1\n', 'output': ['ARARARALLLA']}, {'input': '3\n0 2 0\n', 'output': ['ARARALAARALA']}, {'input': '5\n3 1 2 2 4\n', 'output': ['ARALAARALAARARARARARALLLAARARARALAARALAARALLLLLA']}, {'input': '4\n2 2 2 2\n', 'output': ['ARARARARALLLLAARARARARALLLLA']}, {'input': '7\n5 3 3 4 2 1 0\n', 'output': ['ARARARARARALLLLLAARARARARALLLLAARALAARALAARARARARALAARARARALLLLLLA']}, {'input': '10\n0 0 0 0 0 0 0 1 1 0\n', 'output': ['ARARARARARARARARARALLA']}, {'input': '17\n5 10 6 7 3 1 1 1 5 9 2 2 2 2 2 2 2\n', 'output': ['ARARARARARALLLLLAARARARARARALLLLLAARARARARALLLLAARARARARALLLLAARARARARALLLAARALAARALAARALAARALAARARARALAARARARARARARARARARARARARARARALLLLLLLLLAARARALLAARARALLAARARALLAARARALAARALAARALAARALAARARARARARARARARALLLLLLLLLLLLLLLLLA']}, {'input': '1\n1\n', 'output': ['ARALA']}, {'input': '1\n52\n', 'output': ['ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA']}, {'input': '1\n100\n', 'output': ['ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA']}, {'input': '2\n0 1\n', 'output': ['ARARALA']}, {'input': '2\n1 0\n', 'output': ['ARALA']}, {'input': '2\n1 1\n', 'output': ['ARARALLA']}, {'input': '2\n0 100\n', 'output': ['ARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA']}, {'input': '2\n100 0\n', 'output': ['ARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALA']}, {'input': '3\n1 0 100\n', 'output': ['ARARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALLLA']}, {'input': '3\n0 100 1\n', 'output': ['ARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARARALLA']}, {'input': '3\n1 100 1\n', 'output': ['ARARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARALAARARALLLA']}, {'input': '9\n3 0 1 0 0 2 1 3 2\n', 'output': ['ARALAARALAARARARARARARALAARARARARALLAARALAARARALLLLLLLLLA']}, {'input': '10\n1 1 1 6 5 9 9 9 5 2\n', 'output': ['ARARARARARARARARARARALLLLLLLAARARARARARARALLLLLLAARARARARARARALLLLLLAARARARARARARALLLLLLAARALAARARARARARALLLAARARARALLLAARARARALLLAARARARALLLAARARARARARALLLLLLLLLLA']}, {'input': '2\n2 2\n', 'output': ['ARARALLAARARALLA']}, {'input': '2\n1 2\n', 'output': ['ARARALAARALLA']}, {'input': '2\n2 1\n', 'output': ['ARALAARARALLA']}, {'input': '3\n1 2 1\n', 'output': ['ARARALAARARALLLA']}, {'input': '7\n1 1 1 0 1 1 1\n', 'output': ['ARARARARARARARALLLLLLLA']}, {'input': '8\n1 0 0 0 0 0 0 1\n', 'output': ['ARALAARARARARARARARARALA']}, {'input': '10\n1 0 0 0 0 0 0 1 0 1\n', 'output': ['ARALAARARARARARARARARARARALLLA']}, {'input': '20\n2 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1\n', 'output': ['ARALAARALAARARARARARARARARALAARARARARARARARARARARARARARALLLLLLLA']}, {'input': '20\n10 9 8 7 6 5 4 3 0 0 0 1 0 0 0 0 0 0 0 1\n', 'output': ['ARARARARARARARARALLLLLLLLAARARARARARARARARALLLLLLLLAARARARARARARARALLLLLLLAARARARARARARALLLLLLAARARARARARALLLLLAARARARARALLLLAARARARALLLAARARALLAARALAARARARARARARARARARARARARARARARARARARARARALLLLLLLLLLLLLLLLLLLLA']}]


#include <iostream>
#include <string.h>

using namespace std;

int main(int argc, char const *argv[]){
	char word[1005];
	int k, mud = 0;

	bool v[30];
	for(int i = 0; i < 30; i++){
		v[i] = false;
	}

	cin >> word >> k;

	int tam = strlen(word);
	if(tam < k){
		cout << "impossible" << endl;
	}

	else{
		int dif = 0;

		for(int c1 = 0; word[c1] != '\0'; c1++){

			int index = word[c1];
			if(v[index - 97] == false){
				v[index - 97] = true;
				dif++;
			}
		}

		if(k - dif >= 0)
			cout << k - dif << endl;
		else
			cout << 0 << endl;
	}

	return 0;
}
// 1505925283123

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char a[1100];
int num,k[27];
int main(){
//	freopen("2.txt","r",stdin);
	cin>>a;
	int len=strlen(a);
	cin>>num;
	memset(k,0,sizeof(k));
	if(len<num)
	cout<<"impossible";
	else{
		for(int i=0;i<len;i++){
			k[a[i]-'a']++;
		}
		int ans=0;
		for(int i=0;i<26;i++)
		if(k[i])
		ans++;
		if(num>=ans)
		cout<<num-ans;
		else{
			cout<<0;
		}
	}
	return 0;
}

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.

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


#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
//#define ls l,mid,rt<<1
//#define rs mid+1,r,rt<<1|1
#define SIZE 1000100
//#define inf
#define mod 1000000007
//#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double PI = acos(-1.0);
const double eps = 1e-8;

char str[SIZE];
ll dp[SIZE][5];

int main()
{
    scanf("%s",str+1);
    int len = (int)strlen(str+1);
    if(len == 1)
    {
        if(str[1] == '?')puts("2");
        else if(str[1] == '0' || str[1] == '*')puts("1");
        else puts("0");
        return 0;
    }
    memset(dp,0,sizeof(dp));
    if(str[1] == '0') dp[1][0] = 1;
    else if(str[1] == '1') dp[1][1] = 1;
    else if(str[1] == '*') dp[1][4] = 1;
    else if(str[1] == '?') dp[1][0] = dp[1][1] = dp[1][4] = 1;
    for(int i=2; i<=len; i++)
    {
        if(str[i] == '0')
        {
            dp[i][0] = (dp[i][0] + dp[i-1][0])%mod;
            dp[i][0] = (dp[i][0] + dp[i-1][2])%mod;
        }
        else if(str[i] == '1')
        {
            dp[i][1] = (dp[i][1] + dp[i-1][0])%mod;
            dp[i][2] = (dp[i][2] + dp[i-1][4])%mod;
            dp[i][1] = (dp[i][1] + dp[i-1][2])%mod;
        }
        else if(str[i] == '2')
        {
            dp[i][3] = (dp[i][3] + dp[i-1][4])%mod;
        }
        else if(str[i] == '*')
        {
            dp[i][4] = (dp[i][4] + dp[i-1][3])%mod;
            dp[i][4] = (dp[i][4] + dp[i-1][1])%mod;
            dp[i][4] = (dp[i][4] + dp[i-1][4])%mod;
        }
        else
        {
            dp[i][0] = (dp[i][0] + dp[i-1][0])%mod;
            dp[i][0] = (dp[i][0] + dp[i-1][2])%mod;
            dp[i][1] = (dp[i][1] + dp[i-1][0])%mod;
            dp[i][2] = (dp[i][2] + dp[i-1][4])%mod;
            dp[i][1] = (dp[i][1] + dp[i-1][2])%mod;
            dp[i][3] = (dp[i][3] + dp[i-1][4])%mod;
            dp[i][4] = (dp[i][4] + dp[i-1][3])%mod;
            dp[i][4] = (dp[i][4] + dp[i-1][1])%mod;
            dp[i][4] = (dp[i][4] + dp[i-1][4])%mod;
        }
    }
    ll ans = 0;
    for(int i=0; i<5; i++)
        ans = (ans + dp[len][i])%mod;
    ans -= (dp[len][3] + dp[len][1]);
    ans %= mod;
    if(ans < 0)
        ans += mod;
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
#define mod 1000000007LL
i64 dp[7][7][1000006];
string inp;
int len;
i64 solve(int pre,int adj,int pos)
{
    if(pos==len)
    {
        return !((adj==1 && pre!=3)||adj==2);
    }
   i64 &ret=dp[pre][adj][pos];
   if(ret!=-1)return ret;
   ret=0;
   if(inp[pos]=='?')
   {
      if(adj==5){
        ret=(ret+solve(adj,0,pos+1))%mod;
          ret=(ret+solve(adj,1,pos+1))%mod;
           ret=(ret+solve(adj,3,pos+1))%mod;
          }

       if(adj==0)ret=(ret+solve(adj,0,pos+1)+solve(adj,1,pos+1))%mod;
       if(adj==1 && pre==3)ret=(ret+solve(adj,0,pos+1)+solve(adj,1,pos+1))%mod;
       if(adj==1 && pre!=3)ret=(ret+solve(adj,3,pos+1))%mod;
       if(adj==3)ret=(ret+(solve(adj,1,pos+1))+solve(adj,2,pos+1)+solve(adj,3,pos+1))%mod;
       if(adj==2 && pre==3)ret=(ret+solve(adj,3,pos+1))%mod;
   }
   else
   {
       int t=(inp[pos]=='*'?3:(inp[pos]-'0'));
      if(adj==5 && t!=2)
         ret=(ret+solve(adj,t,pos+1))%mod;
      if(adj==2 && t==3 && pre==3)ret=(ret+solve(adj,t,pos+1))%mod;
      if(adj==1 && pre==3 && t<2)ret=(ret+solve(adj,t,pos+1))%mod;
      if(adj==1 && pre!=3 && t==3)ret=(ret+solve(adj,t,pos+1))%mod;
      if(adj==3 && t!=0 )ret=(ret+solve(adj,t,pos+1))%mod;
      if(adj==0 && t<2 )ret=(ret+solve(adj,t,pos+1))%mod;

   }
   return ret;

}
int main()
{
  memset(dp,-1,sizeof dp);
  cin>>inp;
  len=inp.size();
  cout<<solve(5,5,0);
  return 0;
}

Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares.For example, the correct field to play looks like that: 001*2***101*. The cells that are marked with "*" contain bombs. Note that on the correct field the numbers represent the number of bombs in adjacent cells. For example, field 2* is not correct, because cell with value 2 must have two adjacent cells with bombs.Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of n cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end.


#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define li		long long
#define rep(i,to)	for(li i=0;i<((li)to);i++)
#define pb		push_back
#define sz(v)		((li)v.size())

#define MAX 200005
#define LEFT 0
#define RIGHT 1
li n;
vector<pair<li,li> > E[MAX];
vector<pair<li,li> > L;
li used[MAX],comp[MAX],cnt[MAX],ans[MAX],sum[MAX],dis[MAX*3];
li find_loop(li pos,li parent=-1){
	if(used[pos]) return pos;
	used[pos]=true;
	rep(i,sz(E[pos]))if(E[pos][i].first!=parent){
		li tmp=find_loop(E[pos][i].first,pos);
		if(tmp!=-1){
			comp[pos]=true;
			L.pb(make_pair(pos,E[pos][i].second));
			return (tmp==pos)?-1:tmp;
		}
	}
	return -1;
}

li dfs(li pos,li parent=-1){
	cnt[pos]=1,sum[pos]=0;
	rep(i,sz(E[pos]))if(E[pos][i].first!=parent && !comp[E[pos][i].first]){
		cnt[pos]+=dfs(E[pos][i].first,pos);
		sum[pos]+=sum[E[pos][i].first];
		sum[pos]+=E[pos][i].second*cnt[E[pos][i].first];
	}
	return cnt[pos];
}

void cal(li pos,li parent=-1){
	rep(i,sz(E[pos]))if(E[pos][i].first!=parent && !comp[E[pos][i].first]){
		ans[E[pos][i].first]=ans[pos];
		ans[E[pos][i].first]+=(n-cnt[E[pos][i].first])*E[pos][i].second;
		ans[E[pos][i].first]-=cnt[E[pos][i].first]*E[pos][i].second;
		cal(E[pos][i].first,pos);
	}
}

int main(){
	li a,b,c;
	cin>>n;
	rep(i,n){
		cin>>a>>b>>c;
		E[a-1].pb(make_pair(b-1,c));
		E[b-1].pb(make_pair(a-1,c));
	}
	rep(i,MAX) used[i]=comp[i]=false;
	find_loop(0);
	rep(i,sz(L)) dfs(L[i].first);
	dis[0]=0;
	rep(i,sz(L)*3)if(i) dis[i]=dis[i-1]+L[i%sz(L)].second;
	ans[L[0].first]=0;
	rep(i,sz(L)){
		ans[L[0].first]+=sum[L[i].first]+min(dis[i],dis[sz(L)]-dis[i])*cnt[L[i].first];
	}
	li num[2]={n,0},mid=0;
	while(dis[mid+1]<dis[sz(L)]-dis[mid+1]){
		mid++;
		num[LEFT]-=cnt[L[mid].first];
		num[RIGHT]+=cnt[L[mid].first];
	}
	rep(i,sz(L))if(i){
#define ANS(var) ans[L[var].first]
		ANS(i)=ANS(i-1)+num[LEFT]*(dis[i]-dis[i-1])-num[RIGHT]*(dis[i]-dis[i-1]);
		num[LEFT]+=cnt[L[i].first];
		num[RIGHT]-=cnt[L[i].first];
		while(dis[mid+1]-dis[i]<dis[sz(L)+i]-dis[mid+1]){
			mid++;
			num[LEFT]-=cnt[L[mid%sz(L)].first];
			num[RIGHT]+=cnt[L[mid%sz(L)].first];
			ANS(i)-=(dis[sz(L)+i]-dis[mid])*cnt[L[mid%sz(L)].first];
			ANS(i)+=(dis[mid]-dis[i])*cnt[L[mid%sz(L)].first];
		}
	}
	rep(i,sz(L)) cal(L[i].first);
	rep(i,n) cout<<ans[i]<<" "; cout<<endl;
}

#include <iostream>
#include <vector>

using namespace std;

typedef long long int ll;

const int limite=1000000;

int n;
vector<pair<int,int> > g[limite];
ll numnodos[limite];
ll precomputo[limite];

int nc=0,lenc=0;
int c[limite];
ll d[limite];

int cc[limite];
int dd[limite];
int visto[limite];

bool buscaciclo(int u,int p,int prof)
{
  if (visto[u]) {
    int icc=prof-1;
    while (cc[icc]!=u) icc--;
    for (int i=icc;i<prof;i++) {
      c[i-icc]=cc[i];
      d[i-icc]=dd[i];
      nc++;
      lenc+=dd[i];
    }
    return true;
  }
  visto[u]=1;
  cc[prof]=u;
  vector<pair<int,int> > &ar=g[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    dd[prof]=ar[i].second;
    if (v!=p and buscaciclo(v,u,prof+1))
      return true;
  }
  return false;
}

void eliminaadyacente(int u,int elim)
{
  vector<pair<int,int> > &ar=g[u];
  vector<pair<int,int> > nextar;
  for (int i=0;i<int(ar.size());i++)
    if (elim!=ar[i].first)
      nextar.push_back(ar[i]);
  ar=nextar;
}

void quitapadre(int u,int p)
{
  vector<pair<int,int> > &ar=g[u];
  vector<pair<int,int> > nextar;
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    if (v!=p) {
      nextar.push_back(ar[i]);
      quitapadre(v,u);
    }
  }
  ar=nextar;
}

void precomputa(int u)
{
  vector<pair<int,int > > &ar=g[u];
  numnodos[u]=1;
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    ll t=ar[i].second;
    precomputa(v);
    numnodos[u]+=numnodos[v];
    precomputo[u]+=precomputo[v]+numnodos[v]*t;
  }
}

ll precomputodebajo(int ic)
{
  int u=c[ic];
  vector<pair<int,int> > &ar=g[u];
  ll pre=0;
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    ll t=ar[i].second;
    if (v!=c[(ic+1)%nc] and v!=c[(ic-1+nc)%nc])
      pre+=precomputo[v]+numnodos[v]*t;
  }
  return pre;
}

ll numnodosdebajo(int ic)
{
  int u=c[ic];
  vector<pair<int,int> > &ar=g[u];
  ll num=0;
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    if (v!=c[(ic+1)%nc] and v!=c[(ic-1+nc)%nc])
      num+=numnodos[v];
  }
  return num;
}

ll sol[limite];

void calcula(int u,ll computoabove)
{
  //cout<<"calculamos "<<u<<endl;
  vector<pair<int,int> > &ar=g[u];
  sol[u]=computoabove+precomputo[u];
  for (int i=0;i<int(ar.size());i++) {
    int v=ar[i].first;
    ll t=ar[i].second;
    calcula(v,sol[u]-(precomputo[v]+numnodos[v]*t)+(n-numnodos[v])*t);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
  for (int i=0;i<n;i++) {
    int u,v,t;
    cin>>u>>v>>t;
    g[u].push_back(pair<int,int> (v,t));
    g[v].push_back(pair<int,int> (u,t));
  }
  buscaciclo(1,0,0);
  eliminaadyacente(c[0],c[1]);
  eliminaadyacente(c[1],c[0]);
  quitapadre(c[0],0);
  precomputa(c[0]);
  int ri=0;
  int lenri=0;
  ll nodri=numnodosdebajo(0)+1;
  ll computori=precomputodebajo(0);
  ll computole=precomputo[c[0]]-computori;
  //cout<<"inicio "<<nodri<<" "<<computori<<" "<<computole<<endl;
  for (int i=0;i<nc;i++) {
    int u=c[i];
    //cout<<"ciclo "<<i<<" "<<u<<" "<<ri<<" "<<nodri<<" "<<computori<<" "<<computole<<endl;
    while (2*(lenri+d[ri])<=lenc) {
      lenri+=d[ri];
      ri=(ri+1)%nc;
      ll comp=precomputodebajo(ri);
      ll numn=numnodosdebajo(ri);
      nodri+=numn+1;
      computori+=comp+(numn+1)*lenri;
      computole-=comp+(numn+1)*(lenc-lenri);
    }
    //cout<<"despues "<<ri<<" "<<c[ri]<<" "<<nodri<<" "<<computori<<" "<<computole<<endl;
    sol[u]=computori+computole;
    vector<pair<int,int> > &ar=g[u];
    for (int j=0;j<int(ar.size());j++) {
      int v=ar[j].first;
      ll t=ar[j].second;
      if (v!=c[(i+1)%nc] and v!=c[(i-1+nc)%nc])
	calcula(v,computori+computole-(precomputo[v]+numnodos[v]*t)+(n-numnodos[v])*t);
    }
    ll comp=precomputodebajo(i);
    ll numn=numnodosdebajo(i);
    //cout<<"debajo "<<comp<<" "<<numn<<" "<<d[i]<<endl;
    computori-=comp;
    nodri-=numn+1;
    computori-=nodri*d[i];
    computole+=comp+(n-nodri)*d[i];
    lenri-=d[i];
  }
  for (int u=1;u<=n;u++) {
    if (u>1) cout<<" ";
    cout<<sol[u];
  }
  cout<<endl;
}

In a far away galaxy there are n inhabited planets numbered with numbers from 1 to n. One day the presidents of all the n planets independently from each other came up with an idea of creating the Galaxy Union. Now they need to share this wonderful idea with their galaxymates, that’s why each president is busy working out a project of negotiating with the other presidents.For negotiations between some pairs of the planets there are bidirectional communication channels, each of which is characterized with "dial duration" ti which, as a rule, takes several hours and exceeds the call duration greatly. Overall the galaxy has n communication channels and they unite all the planets into a uniform network. That means that it is possible to phone to any planet v from any planet u, perhaps, using some transitional planets v1, v2, ..., vm via the existing channels between u and v1, v1 and v2, ..., vm-1 and vm, vm and v. At that the dial duration from u to v will be equal to the sum of dial durations of the used channels.So, every president has to talk one by one to the presidents of all the rest n-1 planets. At that the negotiations take place strictly consecutively, and until the negotiations with a planet stop, the dial to another one does not begin. As the matter is urgent, from the different ways to call the needed planet every time the quickest one is chosen. Little time is needed to assure another president on the importance of the Galaxy Union, that’s why the duration of the negotiations with each planet can be considered equal to the dial duration time for those planets. As the presidents know nothing about each other’s plans, they do not take into consideration the possibility that, for example, the sought president may call himself or already know about the founding of the Galaxy Union from other sources.The governments of all the n planets asked you to work out the negotiation plans. First you are to find out for every president how much time his supposed negotiations will take.


#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){
	char a[1000000], b[1000000], c[1000000], t[1000000], t1[1000000];
	bool forward=0, backward=0, both=0;
	string s, s1;
	cin >> a ;
	cin >> b >> c ;
	int len = 0;
	while (b[len] != '\0')
		len++;
	int i = len ;
	if (strstr(a, b))
		s = strstr(a,b);
	for (int j = 0 ; j <= s.length() ; j ++, i++)
		t[j] = s[i];
	if (strstr(t, c))
		forward = 1;
	i = 0 ;//first reversing the string a :D
	while (a[i] != '\0')
		i++;
	int x = i - 1 ;
	for (int j = 0 ; j < i ; ++ j,x-- )
		t1[j] = a[x];
	if (strstr(t1, b))
		s1 = strstr(t1,b);
	x = len;
	for (int j = 0 ; j <= s1.length() ; j++, x++ )
		t1[j] = s1[x];
	if (strstr(t1, c))
		backward = 1 ;
	if (forward && backward)
		cout << "both";
	if (forward == 0 && backward == 1)
		cout << "backward";
	if (forward == 1 && backward == 0)
		cout << "forward" ;
	if (forward == 0 && backward == 0)
		cout << "fantasy" ;
	return 0;
}

#include<cstdio>
#include<cstring>
#define maxn 100005
char s1[maxn],s2[maxn],s[maxn],ss[maxn];
int next1[maxn],next2[maxn],len,len1,len2;
int kmp(char *des,char *s,int *next)
{
    int i,j=-1;
    for(i=0;des[i];i++)
    {
        while(s[j+1]!=des[i]&&j>=0) j=next[j];
        if(s[j+1]==des[i]) j++;
        if(s[j+1]==0) return i;
    }
    return -1;
}
void getnext(char *s,int *next)
{
    int i,j=-1;
    next[0]=-1;
    for(i=1;s[i];i++)
    {
        while(j>=0&&s[j+1]!=s[i]) j=next[j];
        if(s[j+1]==s[i]) j++;
        next[i]=j;
    }
}
int main()
{
    scanf("%s%s%s",s,s1,s2);
    len1=strlen(s1);
    len2=strlen(s2);
    len=strlen(s);
    getnext(s1,next1);
    getnext(s2,next2);
    bool f1=0,f2=0;
    int x1=kmp(s,s1,next1),x2;
    if(x1>=0)
    {
        x2=kmp(s+x1+1,s2,next2);
        if(x2>=0) f1=1;
    }
    for(int i=0;i<len;i++) ss[i]=s[len-1-i];
    x1=kmp(ss,s1,next1);
    if(x1>=0)
    {
        x2=kmp(ss+x1+1,s2,next2);
        if(x2>=0) f2=1;
    }
    if(f1==0&&f2==0) puts("fantasy");
    else if(f1==0) puts("backward");
    else if(f2==0) puts("forward");
    else puts("both");
    return 0;
}

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.

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


///________________In THE NAME OF ALLAH________________\\\

/*/* Dear online judge:
* I've read the problem, and tried to solve it.
* Even if you don't accept my solution, you should respect my effort.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.     /               ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <string>
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define rep(i,m)        for(int i=0;i<m;i++)
#define REP(i,k,m)      for(int i=k;i<m;i++)
#define repd(i,m)        for(int i=m;i>=0;i--)
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
#define mem(a,b)        memset(a,b,sizeof(a))
#define mp              make_pair
#define pb              push_back
#define SORT(ptr , k )  sort ( ptr , ptr + k );
#define OO ((ll)1e12)
#define ooo -100000000
#define small  INT_MIN;
#define big  INT_MAX;
// #undef to remove macro
using namespace std;
typedef long long ll;
typedef double db;
typedef long double   	  ld;
typedef vector<int>       vi;
typedef vector<bool>       vb;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
typedef bitset<20> MASK;
typedef  pair < int  , string > point ;
#define mo 1000000009
#define INF 10000
#define sz(v)          ((int)((v).size()))
//std::ios_base::sync_with_stdio(false); means  i will not deal with c lang that will speed
const int oo = (int) 1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-7;
#define pi 1000000007
#define black 0;
#define white 1;
const int MAXN=1e5+10;
int dx[] = {1 , 0 , 0 , -1 , -1 , -1 , 1 , 1};
int dy[] = {0 , 1 , -1 , 0 , 1 , -1 , 1 , -1};
int setbit(int num , int idx , int val  )
{
    return (val ) ? (num |(1 << idx )) : (num & ~(1 << idx ));
}
int getbit( int num , int idx )
{
    return ((num >> idx )& 1) == 1 ;
}
int countbit( int num )
{
    int cnt = 0 ;    // __builtin_popcount(mask);
    while ( num )
    {
        num &= (num -1);
        cnt++;
    }
}
// __gcd(10 , 45)

int main()
{
#ifdef AHMED_RAMADAN
    /// freopen("a.txt", "rt", stdin);
    /// freopen("b.txt", "wt", stdout);
#endif
    std::ios_base::sync_with_stdio(false);
    cin.tie();
int n , a ;
pair < int , int >  arr[100002];
cin >> n ;
rep( i , n ) cin >> a , arr[i].first = a , arr[i].second = i + 1 ;
SORT(arr, n );
vi first ;
vi second ;
int sum1 = 0 , sum2 = 0 ;
rep( i , n )
if ( i & 1 ){ first.pb(arr[i].second); sum1+= arr[i].first;}
else {second.pb(arr[i].second); sum2+= arr[i].first ; }
cout << sz(second ) <<endl;
rep(i , sz(second))
cout << second[i] << " ";
cout << endl << sz(first) <<endl;
rep( i , sz(first))
cout << first[i] <<" ";
}

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <utility>
#include <set>
#define pb push_back
#define mp make_pair

#define MAXN 100007
#define MAXM 10007

using namespace std;

	typedef vector<int> VI;
	typedef pair<int,int> PII;

	const int INF = 2123456789;
	int a,b,c;
	int n,m,k;
	int x,y;
	string s;
	pair<int,int> t[MAXN];

int main() {
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> t[i].first;
		t[i].second = i+1;
	}
	sort(t,t+n);
	cout << n/2 + (n % 2) << endl;
	for(int i=0;i<n;i++)
		if(i % 2 == 0) cout << t[i].second << " ";
	cout << endl << n/2 << endl;
	for(int i=0;i<n;i++)
		if(i % 2 == 1) cout << t[i].second << " ";

	return 0;
}

Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:  Each boy plays for exactly one team (x+y=n).  The sizes of teams differ in no more than one (|x-y|≤1).  The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.


#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
const double eps=1e-8;
struct P
{
    double x,y;
    P(){}
    P(double _x,double _y):x(_x),y(_y){}
    double abs(){return sqrt(x*x+y*y);}
    P operator + (const P&a) const {return P(x+a.x,y+a.y);}
    P operator - (const P&a) const {return P(x-a.x,y-a.y);}
    P operator * (const double&a) const {return P(x*a,y*a);}
    P operator / (const double&a) const {return P(x/a,y/a);}
    bool operator < (const P&a) const {return x<a.x-eps||fabs(x-a.x)<eps&&y<a.y;}
    bool operator == (const P&a) const {return (*this-a).abs()<eps;}
    P rot(){return P(y,-x);}
    void get(){scanf("%lf%lf",&x,&y);}
};
struct T
{
    P a[3];double b[3];
    void get()
    {
        for(int i=0;i<3;i++)a[i].get();
        for(int i=0;i<3;i++)b[i]=(a[i]-a[(i+1)%3]).abs();
    }
}a[4];
bool equ(double a,double b){return fabs(a-b)<eps;}
bool tri(double a,double b,double c){return a+b>c-eps&&b+c>a-eps&&c+a>b-eps;}
void geti(P a,P b,double la,double lb,vector<P>&e)
{
    double d=(a-b).abs();
    if(!tri(la,lb,d))return;
    if(la+lb<d+eps)e.pb(a+(b-a)*la/d);else
    {
        double co=(d*d+la*la-lb*lb)/(2*d*la),si=sqrt(max(0.0,1.0-co*co));
        e.pb(a+(b-a)*la*co/d+(b-a).rot()*la*si/d),
        e.pb(a+(b-a)*la*co/d-(b-a).rot()*la*si/d);
    }
    sort(e.begin(),e.end()),
    e.erase(unique(e.begin(),e.end()),e.end());
}
int S=9;
void ff(vector<P> a,vector<T> b)
{
    S=min(S,(int)a.size()+(int)b.size()*2);
    if((int)a.size()>=S)return;
    if(b.empty()){S=min(S,(int)a.size());return;}
    for(int i=0;i<(int)a.size();i++)
        for(int j=i+1;j<(int)a.size();j++)
        {
            double d=(a[i]-a[j]).abs();
            for(int k=0;k<(int)b.size();k++)
            {
                vector<P> e;
                for(int l=0;l<3;l++)
                    if(equ(b[k].b[l],d))
                        geti(a[i],a[j],b[k].b[(l+1)%3],b[k].b[(l+2)%3],e),
                        geti(a[i],a[j],b[k].b[(l+2)%3],b[k].b[(l+1)%3],e);
                for(int l=0;l<(int)e.size();l++)
                {
                    vector<P> a0=a;a0.pb(e[l]);
                    sort(a0.begin(),a0.end()),
                    a0.erase(unique(a0.begin(),a0.end()),a0.end());
                    vector<T> b0=b;b0.erase(b0.begin()+k);
                    ff(a0,b0);
                }
            }
        }
}
int main()
{
    for(int i=0;i<4;i++)a[i].get();
    for(int k=0;k<81;k++)
    {
        double e[4];
        for(int i=0,j=k;i<4;j/=3,i++)e[i]=a[i].b[j%3];
        if(e[0]+e[1]+e[2]+e[3]>2* *max_element(e,e+4)-eps)S=min(S,8);
    }
    for(int i=0;i<4;i++)
    {
        vector<P> a0;
        for(int j=0;j<3;j++)a0.pb(a[i].a[j]);
        sort(a0.begin(),a0.end()),
        a0.erase(unique(a0.begin(),a0.end()),a0.end());
        vector<T> b0;
        for(int j=0;j<4;j++)if(i!=j)b0.pb(a[j]);
        ff(a0,b0);
    }
    for(int i=0;i<4;i++)
    {
        vector<int> p;
        for(int j=0;j<4;j++)if(j!=i)p.pb(j);
        for(int k=0;k<27;k++)
        {
            vector<P> a0;
            vector<double> l;
            for(int i=0,j=k;i<3;j/=3,i++)l.pb(a[p[i]].b[j%3]);
            vector<P> e;
            a0.pb(P(0,0)),a0.pb(P(0,l[0]));geti(P(0,0),P(0,l[0]),l[2],l[1],e);
            if(e.empty())continue;a0.pb(e[0]);
            for(int o=0;o<64;o++)
            {
                vector<P> a1=a0;
                for(int i=0,j=k;i<3;j/=3,i++)
                {
                    e.clear();
                    if((o>>i*2)&1)geti(a0[i],a0[(i+1)%3],a[p[i]].b[(j%3+1)%3],a[p[i]].b[(j%3+2)%3],e);
                    else geti(a0[i],a0[(i+1)%3],a[p[i]].b[(j%3+2)%3],a[p[i]].b[(j%3+1)%3],e);
                    if(e.empty())goto end;
                    if((int)e.size()==1)a1.pb(e[0]);else
                    if(((o>>i*2)&3)/2)a1.pb(e[0]);else a1.pb(e[1]);
                }
                sort(a1.begin(),a1.end()),
                a1.erase(unique(a1.begin(),a1.end()),a1.end());
                ff(a1,vector<T>(1,a[i]));
                end:;
            }
        }
    }
    for(int w=0;w<81;w++)
        for(int i=0;i<4;i++)
            for(int j=i+1;j<4;j++)
            {
                if(!equ(a[i].b[w%3],a[j].b[w/3%3]))continue;
                vector<P> e,f;
                geti(P(0,0),P(0,a[i].b[w%3]),a[i].b[(w%3+1)%3],a[i].b[(w%3+2)%3],e),
                geti(P(0,0),P(0,a[i].b[w%3]),a[i].b[(w%3+2)%3],a[i].b[(w%3+1)%3],e),
                geti(P(0,0),P(0,a[j].b[w/3%3]),a[j].b[(w/3%3+1)%3],a[j].b[(w/3%3+2)%3],f),
                geti(P(0,0),P(0,a[j].b[w/3%3]),a[j].b[(w/3%3+2)%3],a[j].b[(w/3%3+1)%3],f);
                vector<double> d;
                for(int i=0;i<(int)e.size();i++)
                    for(int j=0;j<(int)f.size();j++)
                        d.pb((e[i]-f[j]).abs());
                sort(d.begin(),d.end()),
                d.erase(unique(d.begin(),d.end(),equ),d.end());
                for(int k=0;k<4;k++)if(k!=i&&k!=j)
                    for(int l=k+1;l<4;l++)if(l!=i&&l!=j)
                    {
                        if(tri(a[k].b[w/9%3],a[l].b[w/27%3],a[i].b[w%3]-eps))S=min(S,7);
                        if(equ(a[k].b[w/9%3],a[l].b[w/27%3]))
                        {
                            e.clear(),f.clear();
                            geti(P(0,0),P(0,a[k].b[w/9%3]),a[k].b[(w/9%3+1)%3],a[k].b[(w/9%3+2)%3],e),
                            geti(P(0,0),P(0,a[k].b[w/9%3]),a[k].b[(w/9%3+2)%3],a[k].b[(w/9%3+1)%3],e),
                            geti(P(0,0),P(0,a[l].b[w/27%3]),a[l].b[(w/27%3+1)%3],a[l].b[(w/27%3+2)%3],f),
                            geti(P(0,0),P(0,a[l].b[w/27%3]),a[l].b[(w/27%3+2)%3],a[l].b[(w/27%3+1)%3],f);
                            for(int k=0;k<(int)e.size();k++)
                                for(int l=0;l<(int)f.size();l++)
                                    for(int w=0;w<(int)d.size();w++)
                                        if(equ((e[k]-f[l]).abs(),d[w]))S=min(S,6);
                        }
                    }
            }
    printf("%d\n",S);
    return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>

using namespace std;

const double eps=1e-9;

struct Point
{
	double x,y;
	Point(double _x=0,double _y=0) { x=_x; y=_y; }
};

int result;
Point p[4][3],e[4][3],pts[12];
double dst[12][12];
int permutation[4];

void rotate(Point &p,double d)
{
	double cosd=cos(d);
	double sind=sin(d);
	double x=p.x*cosd-p.y*sind;
	double y=p.x*sind+p.y*cosd;
	p.x=x;
	p.y=y;
}
double ppDistance(const Point &a,const Point &b)
{
	double dx=a.x-b.x;
	double dy=a.y-b.y;
	return sqrt(dx*dx+dy*dy);
}
double sqr(double x)
{
	return x*x;
}
int getIntersect(double X1,double Y1,double R1,double X2,double Y2,double R2,Point &P,Point &Q)
{
	double dst=ppDistance(Point(X1,Y1),Point(X2,Y2));
	if (dst>R1+R2+eps || dst<fabs(R1-R2)-eps) return 0;
	if (dst<=eps) return 0;
	//(x-X1)^2+(y-Y1)^2=sqr(R1)=x^2-2*X1*x+X1^2+y^2-2*Y1*y+Y1^2 (1)
	//(x-X2)^2+(y-Y2)^2=sqr(R2)=x^2-2*X2*x+X2^2+y^2-2*Y2*y+Y2^2 (2)
	//(2)-(1):  sqr(R2)-sqr(R1)=2*(X1-X2)*x+2*(Y1-Y2)*y+sqr(X2)-sqr(X1)+sqr(Y2)-sqr(Y1)
	//	 :  (X1-X2)*x+(Y1-Y2)*y-(sqr(X1)-sqr(X2)+sqr(Y1)-sqr(Y2)-sqr(R1)+sqr(R2))/2.0;
	double a=X1-X2;
	double b=Y1-Y2;
	double c=-(a*(X1+X2)+b*(Y1+Y2)-sqr(R1)+sqr(R2))/2.0;
	double CX=X1,CY=Y1;
	//ax+by+c=0
	//(+by+c+aCX)^2+(ay-aCY)^2=(aR)^2
	double x1,y1,x2,y2;
	if (fabs(a)>fabs(b))
	{
		double A=sqr(a)+sqr(b);
		double B=2.0*b*(c+a*CX)-2.0*sqr(a)*CY;
		double C=sqr(c+a*CX)+sqr(a)*(sqr(CY)-sqr(R1));
		double delta=sqr(B)-4*A*C;
		if (delta<-eps) return 0;
		if (delta<0) delta=0;
		delta=sqrt(delta);
		y1=(-B+delta)/(2*A);x1=(-c-b*y1)/a;
		y2=(-B-delta)/(2*A);x2=(-c-b*y2)/a;
		P.x=x1;P.y=y1;
		Q.x=x2;Q.y=y2;
	}
	else
	{
		swap(a,b);swap(CX,CY);
		double A=sqr(a)+sqr(b);
		double B=2.0*b*(c+a*CX)-2.0*sqr(a)*CY;
		double C=sqr(c+a*CX)+sqr(a)*(sqr(CY)-sqr(R1));
		double delta=sqr(B)-4*A*C;
		if (delta<-eps) return 0;
		if (delta<0) delta=0;
		delta=sqrt(delta);
		y1=(-B+delta)/(2*A);x1=(-c-b*y1)/a;
		y2=(-B-delta)/(2*A);x2=(-c-b*y2)/a;
		swap(x1,y1);swap(x2,y2);
		swap(a,b);swap(CX,CY);
		P.x=x1;P.y=y1;
		Q.x=x2;Q.y=y2;
	}
	return 2;
}
void DFS(int d)
{
	if (d==3)
	{
		int m=0;
		for (int i=0;i<d;i++) for (int j=0;j<3;j++)
		{
			bool is_exists=false;
			for (int k=0;!is_exists && k<m;k++) if (fabs(e[i][j].x-pts[k].x)<=eps && fabs(e[i][j].y-pts[k].y)<=eps) is_exists=true;
			if (!is_exists) pts[m++]=e[i][j];
		}
		if (m>=result) return;
		if (m+2<result)
		{
			result=m+2;
			//printf("res = %d\n",result);
		}
		double l1=ppDistance(p[d][0],p[d][1]);
		double l2=ppDistance(p[d][0],p[d][2]);
		double l3=ppDistance(p[d][1],p[d][2]);
		for (int i=0;i<m;i++) for (int j=0;j<m;j++) dst[i][j]=(i==j)?0:((i>j)?dst[j][i]:ppDistance(pts[i],pts[j]));
		for (int i=0;i<m;i++) for (int j=i+1;j<m;j++) if (fabs(dst[i][j]-l1)<=eps) for (int k=0;k<m;k++)
			if (fabs(dst[i][k]-l2)<=eps && fabs(dst[j][k]-l3)<=eps || fabs(dst[i][k]-l3)<=eps && fabs(dst[j][k]-l2)<=eps)
			{
				result=m;
				//printf("res = %d\n",result);
				return;
			}
		if (m+1>=result) return;
		for (int i=0;i<m;i++) for (int j=i+1;j<m;j++) if (fabs(dst[i][j]-l1)<=eps || fabs(dst[i][j]-l2)<=eps || fabs(dst[i][j]-l3)<=eps)
		{
			result=m+1;
			//printf("res = %d\n",result);
			return;
		}
		return;
	}
	bool dup[12];
	memset(dup,false,sizeof(dup));
	for (int i=0;i<d*3;i++) for (int j=i+1;j<d*3;j++)
	{
		Point p1=e[i/3][i%3];
		Point p2=e[j/3][j%3];
		if (fabs(p1.x-p2.x)<=eps && fabs(p1.y-p2.y)<=eps) dup[j]=true;
	}
	for (int i=0;i<d*3;i++) if (!dup[i]) for (int j=0;j<d*3;j++) if (!dup[j])
	{
		if (i==j) continue;
		Point p1=e[i/3][i%3];
		Point p2=e[j/3][j%3];
		if (fabs(p1.x-p2.x)<=eps && fabs(p1.y-p2.y)<=eps) continue;
		Point g1=Point(p[d][1].x-p[d][0].x,p[d][1].y-p[d][0].y);
		Point g2=Point(p[d][2].x-p[d][0].x,p[d][2].y-p[d][0].y);
		double rot=atan2(p2.y-p1.y,p2.x-p1.x)-atan2(g1.y,g1.x);
		rotate(g1,rot);
		rotate(g2,rot);
		e[d][0]=p1;
		e[d][1]=Point(p1.x+g1.x,p1.y+g1.y);
		e[d][2]=Point(p1.x+g2.x,p1.y+g2.y);
		DFS(d+1);
	}
	if (d==1 && permutation[1]<permutation[2])
		for (int i=0;i<d*3;i++) if (!dup[i]) for (int j=0;j<d*3;j++) if (!dup[j])
		{
			if (i==j) continue;
			Point p1=e[i/3][i%3];
			Point p2=e[j/3][j%3];
			if (fabs(p1.x-p2.x)<=eps && fabs(p1.y-p2.y)<=eps) continue;
			double l1=ppDistance(p[d][0],p[d][1]);
			double l2=ppDistance(p[d+1][0],p[d+1][1]);
			Point h[2];
			int c=getIntersect(p1.x,p1.y,l1,p2.x,p2.y,l2,h[0],h[1]);
			for (int k=0;k<c;k++)
			{
				Point g1=Point(p[d][1].x-p[d][0].x,p[d][1].y-p[d][0].y);
				Point g2=Point(p[d][2].x-p[d][0].x,p[d][2].y-p[d][0].y);
				double rot=atan2(h[k].y-p1.y,h[k].x-p1.x)-atan2(g1.y,g1.x);
				rotate(g1,rot);
				rotate(g2,rot);
				e[d][0]=p1;
				e[d][1]=Point(p1.x+g1.x,p1.y+g1.y);
				e[d][2]=Point(p1.x+g2.x,p1.y+g2.y);
				DFS(d+1);
			}
		}
	if (d==2 && permutation[2]<permutation[3])
	{
		int m=0;
		for (int i=0;i<d;i++) for (int j=0;j<3;j++)
		{
			bool is_exists=false;
			for (int k=0;!is_exists && k<m;k++) if (fabs(e[i][j].x-pts[k].x)<=eps && fabs(e[i][j].y-pts[k].y)<=eps) is_exists=true;
			if (!is_exists) pts[m++]=e[i][j];
		}
		for (int i=0;i<m;i++) for (int j=0;j<m;j++) if (i!=j) for (int k=0;k<3;k++)
		{
			Point p1=pts[i];
			Point p2=pts[j];
			if (fabs(p1.x-p2.x)<=eps && fabs(p1.y-p2.y)<=eps) continue;
			double l1=ppDistance(p[d][0],p[d][1]);
			double l2=ppDistance(p[d+1][k],p[d+1][(k+1)%3]);
			Point h[2];
			int c=getIntersect(p1.x,p1.y,l1,p2.x,p2.y,l2,h[0],h[1]);
			for (int u=0;u<c;u++)
			{
				Point g1=Point(p[d][1].x-p[d][0].x,p[d][1].y-p[d][0].y);
				Point g2=Point(p[d][2].x-p[d][0].x,p[d][2].y-p[d][0].y);
				double rot=atan2(h[u].y-p1.y,h[u].x-p1.x)-atan2(g1.y,g1.x);
				rotate(g1,rot);
				rotate(g2,rot);
				e[d][0]=p1;
				e[d][1]=Point(p1.x+g1.x,p1.y+g1.y);
				e[d][2]=Point(p1.x+g2.x,p1.y+g2.y);
				DFS(d+1);
			}
		}
	}
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	Point a[4][3];
	for (int i=0;i<4;i++) for (int j=0;j<3;j++)
	{
		double x,y;
		scanf("%lf%lf",&x,&y);
		a[i][j]=Point(x,y);
	}
	result=12;
	for (int i=0;i<4;i++) permutation[i]=i;
	do{
		for (int mset=0;mset<(1<<3);mset+=2) for (int set=0;set<(1<<3);set+=2) for (int rot=0;rot<27;rot+=3)
		{
			for (int i=0;i<4;i++) for (int j=0;j<3;j++) p[i][j]=a[permutation[i]][j];
			for (int i=0;i<4;i++) if (mset&(1<<i)) for (int j=0;j<3;j++) p[i][j].x=-p[i][j].x;
			for (int state=rot,i=0;i<4;i++,state/=3) for (int j=0;j<state%3;j++)
			{
				Point t=p[i][0];
				p[i][0]=p[i][1];
				p[i][1]=p[i][2];
				p[i][2]=t;
			}
			for (int i=0;i<4;i++) if (set&(1<<i)) swap(p[i][1],p[i][2]);
			for (int j=0;j<3;j++) e[0][j]=p[0][j];
			DFS(1);
		}
	}while (next_permutation(permutation+1,permutation+4)!=0);
	printf("%d\n",result);
	return 0;
}

Little Petya is preparing for the first contact with aliens. He knows that alien spaceships have shapes of non-degenerate triangles and there will be exactly 4 ships. Landing platform for a ship can be made of 3 special columns located at some points of a Cartesian plane such that these 3 points form a triangle equal to the ship with respect to rotations, translations (parallel shifts along some vector) and reflections (symmetries along the edges). The ships can overlap after the landing.Each column can be used to land more than one ship, for example, if there are two equal ships, we don't need to build 6 columns to land both ships, 3 will be enough. Petya wants to know what minimum number of columns will be enough to land all ships.


#pragma comment(linker, "/stack:64000000")
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <algorithm>
#include <iostream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define debug(x) cerr << #x << " = " << x << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair((a), (b))
#define X first
#define Y second
#define ft first
#define sc second

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long double ld;
typedef pair<ld, ld> ptd;
typedef pair <int, int> pt;
typedef long long li;
typedef unsigned char byte;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;

const int N = 150 + 13;

int n;
int a[N];
char s[N];
int p[N][N];
int z[N][N][N];
int d[N][N];

int calcZ (int, int, int);

int calcD (int lf, int rg)
{
    int& ans = d[lf][rg];
    if (ans != -1) return ans;

    ans = -2;

    for (int mid = lf; mid < rg; mid++)
    {
        int t1 = calcD(lf, mid), t2 = calcD(mid + 1, rg);
        if (t1 != -2 && t2 != -2)
            ans = max(ans, t1 + t2);
    }

    if (s[lf] == s[rg])
    {
        for (int len = 1; len <= rg - lf + 1; len++)
        {
            if (a[len] == -1) continue;

            int t = calcZ(lf + 1, rg - 1, len - 1 - (lf != rg));
            if (t == -2) continue;

            ans = max(ans, t + a[len]);
        }
    }

    return ans;
}

int calcZ (int lf, int rg, int len)
{
    int& ans = z[lf][rg][len];
    if (ans != -1) return ans;

    if (lf > rg)
        return ans = (len == 0 ? 0 : -2);

    if (len == 0)
        return ans = calcD(lf, rg);

    ans = -2;

    for (int mid = lf; mid <= rg; mid++)
    {
        if (mid != rg)
        {
            int t1 = calcZ(lf, mid, len);
            int t2 = calcD(mid + 1, rg);
            if (t1 != -2 && t2 != -2)
                ans = max(ans, t1 + t2);
        }

        if (mid != lf)
        {
            int t1 = calcD(lf, mid - 1);
            int t2 = calcZ(mid, rg, len);
            if (t1 != -2 && t2 != -2)
                ans = max(ans, t1 + t2);
        }
    }

    if (s[lf] == s[rg])
        ans = max(ans, calcZ(lf + 1, rg - 1, len - 1 - (lf != rg)));

    return ans;
}

int calcP (int lf, int rg)
{
    int& ans = p[lf][rg];
    if (ans != -1) return ans;

    ans = 0;

    for (int i = lf; i < rg; i++)
        ans = max(ans, calcP(lf, i) + calcP(i + 1, rg));

    if (s[lf] == s[rg])
    {
        for (int len = 1; len <= rg - lf + 1; len++)
        {
            if (a[len] == -1) continue;

            int t = calcZ(lf + 1, rg - 1, len - 1 - (lf != rg));

            if (t == -2) continue;

            ans = max(ans, t + a[len]);
        }
    }

    return ans;
}

int main()
{
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    cin >> n;

    for1(i, n)
        scanf("%d", &a[i]);

    scanf("%s", s);

    memset(p, -1, sizeof(p));
    memset(z, -1, sizeof(z));
    memset(d, -1, sizeof(d));

    cout << calcP(0, n - 1) << endl;

    return 0;
}

Market stalls now have the long-awaited game The Colder Scrools V: Nvodsk. The game turned out to be difficult as hell and most students can't complete the last quest ("We don't go to Nvodsk..."). That threatened winter exams. The rector already started to wonder whether he should postpone the winter exams till April (in fact, he wanted to complete the quest himself). But all of a sudden a stranger appeared at the door of his office. "Good afternoon. My name is Chuck and I solve any problems" — he said.And here they are sitting side by side but still they can't complete the mission. The thing is, to kill the final boss one should prove one's perfect skills in the art of managing letters. One should be a real magician to do that. And can you imagine what happens when magicians start competing... But let's put it more formally: you are given a string and a set of integers ai. You are allowed to choose any substring that is a palindrome and delete it. At that we receive some number of points equal to ak, where k is the length of the deleted palindrome. For some k, ak=-1, which means that deleting palindrome strings of such length is forbidden. After a substring is deleted, the remaining part "shifts together", that is, at no moment of time the string has gaps. The process is repeated while the string has at least one palindrome substring that can be deleted. All gained points are summed up.Determine what maximum number of points can be earned."Oh" — said Chuck, raising from the chair, — "I used to love deleting palindromes, just like you, but one day I took an arrow in the Knee".