rendered paste body#include <iostream>#include <vector>using namespace std;const int KOSZULKA = 0;const int SPAKOWANY = -1;long strony=0;vector <long> stos;//long stos[1000000];long licznik =0;long wynik=0;long error=1;long temp, temp2;long j,k;int main(void) { cin >> strony; stos.resize(strony*2); for(int i=0; i<(2*strony);i++) cin >> stos[i]; while (error > 0) { error=0; for(j=0;j<stos.size();j++) { if((stos[j] == KOSZULKA && stos[j+1] == KOSZULKA) || (stos[j] > KOSZULKA && stos[j+1] > KOSZULKA)) { error++; wynik++; temp = stos[j]; stos[j] = stos[j+1]; stos[j+1] =temp; } else { stos[j] = SPAKOWANY; stos[j+1] = SPAKOWANY; } if(stos[j] == SPAKOWANY && stos[j+1] == SPAKOWANY) { temp = stos[j]; temp2 = stos[j+1]; for(k=j+2; k<stos.size();k++) { stos[k-2]=stos[k]; stos[k-1]=stos[k+1]; stos.resize(stos.size()-2); } } } }/*while (error>0) { error=0; cout << "petla sie wykonala iles razy" << endl;for (j=0;j<licznik;j++) { if (((stos[j]==KOSZULKA && stos[j+1]==KOSZULKA)||(stos[j]>KOSZULKA && stos[j+1]>KOSZULKA))&&(stos[j]!=SPAKOWANY && stos[j+1]!=SPAKOWANY)) { error++; wynik++; temp = stos[j]; stos[j] = stos[j+1]; stos[j+1] =temp; } else{ stos[j] = SPAKOWANY; stos[j=1] = SPAKOWANY;} } } */cout << wynik <<endl;}