1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char** argv) 
{
	int friends = 0;
	int periods = 0;
	string WP = "";
	
	cin>>friends;
	
	int money[100000];
	
	for(int i = 0; i<friends; ++i)
	{
		cin>>money[i];
	}
	
	cin>>periods;
	
	cin>>WP;
	
	vector<int> wins;
	
	string games = "";
	
	vector<int> elements;
	
	int c = 0;
	int hm = 0;
	bool CzyZero = false;
	
	while(CzyZero == false)
	{
		
		if(periods >= 500000)
		{
			while(games.length()<100000000)
			{
				games.append(WP);
			}
		}
		else
		{
			for(int pp = 0; pp<friends; ++pp)
			{
				if(games.length()>=10000000)
				{
					break;
				}
				
				games.append(WP);
			}	
		}
		
		for(int ww = 0; ww<friends; ++ww)
		{
			if(games[c] == 'W')
			{
				elements.push_back(money[ww]+1);
				money[ww] = money[ww]+1;
				c++;
			}
			else 
			{
				elements.push_back(money[ww]-1);
				money[ww] = money[ww]-1;
				if(money[ww] == 0)
				{
					CzyZero = true;
				}
				c++;
			}		
		}
		
		
		if(periods <= 500000)
		{
			if(elements.size()>10000000)
			{
				cout<<"-1"<<endl;
				return 0;
			}
		}
		else
		if(elements.size()>1000000000000)
		{
			cout<<"-1"<<endl;
			return 0;
		}
		
	}	

	for(int g = 0; g<elements.size(); ++g)
	{

		if(elements[g] == 0)
		{
			cout<<g+1<<endl;
			return 0;
						
		}
		
	}
	
	return 0;
}