solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
n=int(input())
l=[int(i) for i in input().split()]
ans=0
f=0
#l.insert0(10000000000000,0)
for i in range(n-1,0,-1):
if l[i]<l[i-1]:
print(i)
f=1
break
if not f:
print(f) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res) n -= n & (-n);
return res;
}
template <class T>
void chmax(T& a, const T& b) {
a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
a = min(a, b);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < (n); i++) cin >> a[i];
long long int len = n - 1;
while (len > 0 && a[len - 1] < a[len]) {
len--;
}
cout << len << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100000];
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d", &a[i]);
}
int index, flag;
for (int i = t - 2; i >= 0; i--) {
if (a[i] > a[i + 1]) {
index = i;
printf("%d\n", (index + 1));
flag = 0;
break;
} else {
flag = 1;
index = i;
}
}
if (flag == 1) printf("%d\n", 0);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
bool visit[n + 1];
for (int i = 0; i < n + 1; i++) {
visit[i] = false;
}
long long int i = 0;
long long int no_new = 0;
long long int msg = 0;
long long int k = 1;
while (i < n) {
if (a[i] != k) {
msg += no_new + 1;
no_new = 0;
visit[a[i]] = true;
i++;
} else {
visit[k] = true;
no_new++;
i++;
while (visit[k] == true) {
k++;
}
}
}
cout << msg;
}
| 8 | CPP |
#include <bits/stdc++.h>
long m[100001];
int main() {
long n, p, a, i;
scanf("%ld", &n);
p = 0;
for (i = 1; i <= n; i++) scanf("%ld", &m[i]);
p = 0;
for (i = n; i > 1; i--) {
if (m[i - 1] > m[i]) {
p = i - 1;
break;
}
}
printf("%ld", p);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int rez, i, j, n, a[100000];
cin >> n;
j = -1;
for (i = 0; i < n; i++) cin >> a[i];
i = n - 1;
j = n;
rez = 0;
while (rez == 0 and i >= 0) {
if (a[i] < j) j = a[i];
if (a[i] > j) rez = i + 1;
i--;
}
cout << rez;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int num[n];
for (int i = 0; i < n; i++) cin >> num[i];
int mi = 100000000;
for (int i = n - 1; i >= 0; i--) {
if (num[i] >= mi) {
cout << i + 1 << endl;
return 0;
} else {
mi = min(mi, num[i]);
}
}
cout << 0 << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k;
int a[100000];
int ans = 0;
for (int k = 0; k < n; k++) {
cin >> a[k];
if (k > 0 && a[k] < a[k - 1]) ans = k;
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ls = 0;
bool first = 0, f = 0;
cin >> n;
int Arr[n];
long long int cnt = 0;
for (int i = 0; i < n; i++) cin >> Arr[i];
for (int i = 1; i < n; i++)
if (Arr[i] < Arr[i - 1]) cnt = i;
cout << cnt;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int count = 0;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
int min_validated = n + 1;
for (int i = n - 1; i > 0; --i) {
if (v[i] <= v[i - 1]) {
cout << i << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
int a[maxn];
int c[maxn];
int main() {
int ans = 0;
int i, j, x;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int id = 0;
for (i = 2; i <= n; i++) {
if (a[i] < a[i - 1]) id = i - 1;
}
printf("%d\n", id);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200000];
int c[200000];
int lowbit(int y) { return y & (y ^ (y - 1)); }
int sum(int x) {
int ans = 0;
while (x > 0) {
ans += c[x];
x -= lowbit(x);
}
return ans;
}
void insert(int pos, int val) {
while (pos <= n) {
c[pos] += val;
pos += lowbit(pos);
}
}
int main() {
while (cin >> n) {
memset(c, 0, sizeof(c));
for (int i = 0; i < n; ++i) cin >> a[i];
int ans;
for (ans = n - 1; ans >= 0; --ans) {
int num = sum(a[ans] - 1);
if (num > 0) break;
insert(a[ans], 1);
}
cout << ans + 1 << endl;
}
}
| 8 | CPP |
if __name__ == '__main__':
n = int(input())
x = [int(i) for i in input().split(' ')]
i = n - 1
while i > 0:
if x[i] < x[i - 1]:
break
i -= 1
print(i)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int testnum;
vector<long long> nums;
int cnt;
void preprocess() {}
void solve() {
int N, i, a[100004];
scanf("%d", &N);
for (i = 0; i < N; ++i) scanf("%d", &a[i]);
for (i = N - 1; i > 0; --i) {
if (a[i] < a[i - 1]) break;
}
printf("%d\n", i);
}
bool input() { return true; }
int main() {
preprocess();
int T = 1;
for (testnum = 1; testnum <= T; testnum++) {
if (!input()) break;
solve();
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
;
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < (n); i++) cin >> a[i];
int i = 0;
for (i = n - 1; i > 0; i--)
if (a[i] < a[i - 1]) break;
cout << i;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int sum = 1;
for (int i = n - 1; i > 0; i--) {
if (a[i] > a[i + 1]) break;
sum++;
}
printf("%d\n", n - sum);
return 0;
}
| 8 | CPP |
n = int(input())
s = input().split()
a = 0
b = 0
for i in range(n-1):
if int(s[i]) < int(s[i+1]):
a = a+1
else:
b = b+1+a
a = 0
print(b)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, o, f = 0;
cin >> a;
const int b = a;
int A[b];
for (int i = 0; i < b; i++) {
cin >> A[i];
}
o = a - 1;
for (int i = a - 1; i >= 0; i--) {
if (A[i] > A[i - 1]) {
o--;
} else {
goto loop1;
}
}
loop1:
cout << o;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16000000")
using namespace std;
const double eps = 1e-10;
int sqr(int a) { return a * a; }
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
v.push_back(x);
}
int mn = v[v.size() - 1];
for (int i = n - 2; i >= 0; --i) {
if (v[i] > mn) {
cout << i + 1 << endl;
return 0;
}
mn = std::min(mn, v[i]);
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e16;
const long long _inf = -1e16;
long long dx[] = {1, -1, 0, 0};
long long dy[] = {0, 0, 1, -1};
long long addmod(long long& a, long long b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
}
long long submod(long long& a, long long b) {
a -= b;
if (a < 0) a += 1000000007;
}
long long a[100010];
long long b[100010];
int main() {
long long n, i, cnt = 0, idx = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
b[n] = a[n];
for (i = 1; i < n; i++) {
if (a[i] > a[i + 1]) idx = i;
}
cout << idx << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, mn, mx, l, t, n, x = 1, sm, cnt, fg, a[1000010];
char ch[1000010];
int gcd(int a, int b) {
while (b > 0) {
a %= b;
a ^= b;
b ^= a;
a ^= b;
}
return a;
}
int main() {
while (~scanf("%d", &n)) {
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = n - 1; i >= 1; i--) {
if (a[i] > a[i + 1]) break;
}
printf("%d\n", i);
}
return 0;
}
| 8 | CPP |
def ordem_crescente(lista,n, i, crescente):
while i < n-1:
if int(lista[i]) > int(lista[i+1]):
crescente[0] = i - 1
return False
i += 1
return True
n = int(input())
fim = input().split(' ')
count = 0
i = 0
crescente = [-1]
while i < n:
if i >= crescente[0]:
num = int(fim[i])
if (i+1) < num:
count += 1
elif (i+1) == num:
if not ordem_crescente(fim, n, i, crescente):
count += 1
else:
break
else:
if not ordem_crescente(fim, n, i, crescente):
count += 1
else:
break
else:
count += 1
i += 1
print(count)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, a[1000009], b[1000009], p[1000009], ans, cn, t, x, y, z;
char c[1000009], d[1000009], ch;
int main() {
while (scanf("%d", &n) != EOF) {
ans = 1;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
x = a[n - 1];
for (i = n - 2; i >= 0; i--) {
if (x > a[i]) {
x = a[i];
ans++;
} else {
break;
}
}
printf("%d\n", n - ans);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 17;
int a[MAXN];
int main() {
int i, n, t;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; ++i) scanf("%d", a + i);
for (i = n - 1; i > 0 && a[i - 1] < a[i]; --i)
;
printf("%d\n", i);
}
return 0;
}
| 8 | CPP |
n = int(input())
t = [int(i) for i in input().split()]
last_new = -1
for i in range(len(t)):
if i == len(t) - 1:
break
if t[i] > t[i+1]:
last_new = i
print(last_new + 1)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e6;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
int main() {
int length, index = -1;
cin >> length;
int arr[length];
for (int i = 0; i < length; i++) cin >> arr[i];
for (int i = length - 1; i >= 1; i--) {
if (arr[i] < arr[i - 1]) {
index = i;
break;
}
}
if (index == -1)
cout << 0;
else
cout << index;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[100005];
cin >> n;
int fa = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] != i) {
fa = 0;
}
}
if (fa == 1) {
cout << "0";
} else {
int ji = n - 1;
while (a[ji] < a[ji + 1]) {
ji--;
}
cout << ji;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int j = n - 1; j > 0; j--) {
if (ar[j] - ar[j - 1] < 0) {
count = j;
break;
}
}
cout << count;
return 0;
}
| 8 | CPP |
R=input
I=lambda:map(int,R().split())
n=int(R())
a=list(I())[::-1]+[999999]
for i in range(n):
if a[i+1]>a[i]:print(n-i-1);break | 8 | PYTHON3 |
if __name__ == '__main__':
n = int(input())
q = (list(map(int, input().split())))
index = 0
for i in range(n-1, 0, -1):
if(q[i-1] > q[i]):
index = i
break
print(index)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a_vec(n);
for (int i = 0; i < n; i++) cin >> a_vec[i];
vector<int> min_vec(n);
min_vec[n - 1] = a_vec[n - 1];
for (int i = n - 2; i >= 0; i--) min_vec[i] = min(min_vec[i + 1], a_vec[i]);
for (int i = n - 2; i >= 0; i--) {
if (a_vec[i] > min_vec[i + 1]) {
cout << i + 1 << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int mn = a[n], c = 0;
int i = n - 1;
for (; i > 0; i--) {
if (a[i] > mn) break;
mn = min(mn, a[i]);
}
cout << i << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
bool vis[1000005];
int main() {
int n, i, ans = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", a + i);
for (i = n - 1; i > 0; i--)
if (a[i] < a[i - 1]) break;
ans = i;
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int a[100001], fl[100001];
using namespace std;
int main() {
int i, j, k, n, m, t, co = 0, pr = 0, pos, cur;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = n - 1; i > 0; i--) {
if (a[i] < a[i - 1]) {
pos = i;
break;
}
}
if (i == 0) pos = 0;
cout << pos;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = n - 1; i > 0; i--) {
if (a[i - 1] > a[i]) {
cout << i << endl;
exit(0);
}
}
cout << 0 << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int a[t];
for (int i = 0; i < t; i++) cin >> a[i];
for (int i = t - 1; i > 0; i--) {
if (a[i] < a[i - 1]) {
cout << i << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, arr[111111];
int main() {
cin >> n;
arr[0] = 0x3f3f3f3f;
for (int i = 1; i <= n; ++i) cin >> arr[i];
int ans = 0;
for (int i = 0; i < n; ++i) {
int ii = n - i;
if (arr[ii] < arr[ii - 1]) {
ans = i;
break;
}
}
ans = n - ans - 1;
cout << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int main() {
int s[100001], m, n, t[100001], min, ans = 0;
scanf("%d", &n);
for (m = 0; m < n; m++) {
scanf("%d", &s[m]);
}
for (m = n - 1; m > 0; m--) {
if (s[m - 1] > s[m]) break;
}
printf("%d\n", m);
}
| 8 | CPP |
n=int(input())
pos = (list(map(int, input().split())))
last=-1
for i in range(n-1):
if(pos[i]>pos[i+1]):
last=i
print(last+1)
| 8 | PYTHON3 |
n = int(input())
a = (str(input())).split(' ')
ma=0
output = 0
for i in range(n-1):
if int(a[i])<int(a[i+1]):
ma+=1
else:
output+=1+ma
ma=0
print(output)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int i;
int n;
int th[100010];
th[0] = 9000000;
scanf("%d", &n);
n++;
for (i = 1; i < n; i++) {
scanf("%d", &th[i]);
}
for (i = n - 2; th[i] < th[i + 1]; i--) {
}
printf("%d\n", i);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 1, x, ans = 0;
cin >> n;
int a[n + 1];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = n - 1; i >= 0; i--) {
x = a[i] - a[i - 1];
if (x > 0)
count++;
else
break;
}
ans = n - count;
cout << ans << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int counter = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
counter++;
if (a[i] == 1 || a[i] < a[i - 1]) break;
}
cout << n - counter;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> myvec;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
myvec.push_back(a);
}
int tedad = 0;
int minimum = myvec.back();
for (int i = myvec.size() - 1; i >= 0; i--) {
if (myvec[i] > minimum) {
cout << i + 1 << endl;
return 0;
}
if (myvec[i] < minimum) minimum = myvec[i];
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
num = int(input())
arr = list(map(int,input().split()))
i = num-1
while arr[i] > arr[i-1]:
i -= 1
print(i)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100010];
if (0) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
};
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int dem = 1;
int i = n;
while (i > 1 && a[i] > a[i - 1]) {
dem++;
i--;
}
printf("%d", n - dem);
return 0;
}
| 8 | CPP |
def main():
n = int(input())
aa = list(map(int, input().split()))
m = aa[-1]
for i in range(n - 2, -2, -1):
a = aa[i]
if m < a:
break
m = a
print(i + 1)
if __name__ == '__main__':
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> a(n), v(n);
for (long long int i = 0; i <= n - 1; i++) {
cin >> a[i];
}
if (n == 1) {
cout << 0 << endl;
return;
}
long long int i = n - 1;
while (i - 1 >= 0) {
if (a[i - 1] <= a[i])
i--;
else
break;
}
cout << i << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1, test = 0;
while (t--) {
solve();
}
}
| 8 | CPP |
import sys
import itertools as it
import math as mt
import collections as cc
I=lambda:list(map(int,input().split()))
n,=I()
l=I()
i=n-1
while i>0 and l[i]>l[i-1]:
i-=1
print(i) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int i = n - 1;
while (i > 0 && a[i - 1] < a[i]) {
i--;
}
cout << i << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gin[100010], g_s[100010];
void update(int p) {
while (p < 100010) {
g_s[p]++;
p += ((p) & (-(p)));
}
}
int getsum(int p) {
int ret = 0;
while (p) {
ret += g_s[p];
p -= ((p) & (-(p)));
}
return ret;
}
int main() {
int a, n, ans = 0, i, j, mark;
cin >> n;
mark = -1;
for (i = 0; i < n; i++) {
cin >> a;
if (getsum(a) < a - 1) {
mark = i;
}
update(a);
}
cout << mark + 1;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXVAL = 2e9 + 5;
int arr[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", arr + i);
arr[n] = MAXVAL;
int i;
for (i = n - 1; i >= 0; --i)
if (arr[i] > arr[i + 1]) break;
printf("%d\n", i + 1);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i), b[a[i]] = i;
int ans = 0, cnt = 0;
for (int i = n; i > 0; i--) {
if (b[i] - i < ans) ans++;
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int a[n], i;
for (i = 0; i < n; i++) cin >> a[i];
set<long long int> st;
long long int ans = 0;
st.insert(a[0]);
int ind = -1;
for (i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) ind = i;
}
if (ind == -1)
cout << 0;
else
cout << ind + 1;
}
| 8 | CPP |
n = int(input())
a = list(map(int, input().split()))
i = n-1
while i and a[i]>a[i-1]:
i= i-1
print(i)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int i;
vector<long long int> v(n + 1, 0);
for (i = 1; i <= n; i++) cin >> v[i];
long long int minn = 1000000007, index = 0;
for (long long int i = n; i >= 1; i--) {
if (v[i] > minn) {
index = i;
break;
}
minn = min(minn, v[i]);
}
cout << index << "\n";
return 0;
}
| 8 | CPP |
# from debug import *
import sys; input = sys.stdin.readline
from collections import deque, defaultdict
from math import log10, ceil, factorial as F
I = lambda : int(input())
L = lambda : list(map(int, input().split()))
T = lambda : map(int, input().split())
n = I()
lis = L()
i = n-1
while i>0 and lis[i-1] < lis[i]: i-=1
print(i)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int a[], int n, long long x) {
if (x < a[1]) return 0;
if (x >= a[n]) return n;
int i = 1, j = n, mid = 0;
while (j - i > 1) {
mid = (i + j) / 2;
if (a[mid] > x)
j = mid;
else
i = mid;
}
return (a[j] > x ? i : j);
}
long long combination(int c, int i) {
if (i == 0)
return 1;
else if (i == 1)
return c;
else
return ((c - i + 1) * combination(c, i - 1)) / i;
}
int main() {
int n;
cin >> n;
int x = n;
vector<int> number;
while (x--) {
int t;
cin >> t;
number.push_back(t);
}
for (int i = n - 1; i > 0; --i) {
int temp = number[i];
if (temp < number[i - 1]) {
cout << i << endl;
return 0;
}
}
cout << "0" << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = a.size() - 1; i > 0; i--) {
if (a[i - 1] > a[i]) {
cout << i << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
# -*- coding: utf-8 -*-
# Baqir Khan
# Software Engineer (Backend)
from sys import stdin
inp = stdin.readline
n = int(inp())
a = list(map(int, inp().split()))
ans = 0
cur_max = a[0]
for i in range(n - 1, 0, -1):
if a[i] < a[i - 1]:
print(i)
exit()
print(0)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i, j, count = 1;
int a[100001];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = n - 2; i >= 0; i--) {
if (a[i] > a[i + 1])
break;
else
count++;
}
count = n - count;
printf("%d\n", count);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int ar[100010], n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> ar[i];
for (int i = n - 2; i >= 0; i--)
if (ar[i] > ar[i + 1]) cout << i + 1, exit(0);
cout << 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
const int INF = 1000 * 1000 * 1000 + 7;
const long double EPS = 1e-9, pi = 3.1415926535897932384626433832795;
int n;
vector<int> a;
void solve() {
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int ans = 0;
for (int i = n - 2; i >= 0; i--) {
if (a[i] > a[i + 1]) {
printf("%d", i + 1);
exit(0);
}
}
printf("%d", ans);
}
int main() {
solve();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
int main() {
int a[N], n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int p = n;
while ((p > 1) && (a[p - 1] < a[p])) {
p--;
}
cout << p - 1;
}
| 8 | CPP |
n = int(input())
old_pos = list(map(int, input().split()))
# Transforming multithread position in the real order
real_pos = list(reversed(old_pos))
flag = True
for i in range(1,n):
if real_pos[i] > real_pos[i-1]:
print(n - i)
flag = False
break
if(flag == True):
print(0)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n, i, j, k;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
k = 100001;
j = 0;
for (i = n - 1; i >= 0; i--) {
if (a[i] < k) {
k = a[i];
j = j + 1;
} else {
break;
}
}
printf("%d\n", n - j);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a(100500);
long long n;
int main() {
long long i;
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
for (i = 1; i <= n; i++) cin >> a[i];
long long ans = 0;
for (i = 2; i <= n; i++)
if (a[i] < a[i - 1]) ans = i - 1;
cout << ans;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n;
long long a[N];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i];
long long ans = n - 1;
for (long long i = n - 1; i >= 1; i--) {
if (a[i] < a[i + 1])
ans--;
else
break;
}
cout << ans;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a;
vector<int> ind(n + 1);
for (long long i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
a.push_back(tmp);
ind[tmp] = i;
}
int offset = 0;
for (int i = n; i >= 1; i--) {
if (ind[i] < a[ind[i]] - 1 + offset) offset++;
}
cout << offset << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
cin >> n;
vector<int> v(n + 1);
for ((i) = 0; (i) < (n); (i)++) cin >> v[i + 1];
for (i = n - 1; i >= 1; i--) {
if (v[i] < v[i + 1])
continue;
else
break;
}
cout << i << "\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16777216")
class str {
public:
long a1;
long a2;
};
struct myclass {
bool operator()(int i, int j) { return (i < j); }
} mycomp;
int main() {
long n;
cin >> n;
vector<long> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
;
for (int i = n - 1; i >= 0; i--) {
if (i == 0) {
cout << '0';
return 0;
}
if (arr[i - 1] > arr[i]) {
cout << i;
return 0;
}
}
}
| 8 | CPP |
n=int(input())
temp=0
c=0
a=list(map(int,input().split()))
for i in range(0,n):
if(temp-a[i]>0):
c=i+1
temp=a[i]
if(c!=0):
print (c-1)
else:
print(0)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
int n[100005];
bool vis[100005];
int cur;
void next() {
cur++;
while (vis[cur]) cur++;
}
int main() {
int i, t, res;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &n[i]);
}
next();
res = 0;
for (i = 0; i < t; i++) {
if (n[i] != cur) {
res = i + 1;
vis[n[i]] = true;
} else
next();
}
printf("%d", res);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int Mess[100001];
int Counter = 0;
for (int i = 0; i < n; i++) {
cin >> Mess[i];
}
for (int i = n - 1; i >= 0; i--) {
if (i == 0) {
cout << i << endl;
break;
}
if (Mess[i] < Mess[i - 1]) {
if (i == n - 1) {
Counter = n - 1;
cout << i << endl;
break;
}
if (i != n - 1) {
Counter = n - (i + 1);
cout << i << endl;
break;
}
}
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct pole {
int x, y;
const bool operator<(pole a) const { return y < a.y; }
};
int main() {
int n, m, k, i, j, l;
cin >> n;
int niza[100005];
for (k = 0; k < n; k++) cin >> niza[k];
m = 0;
l = niza[n - 1];
for (k = n - 2; k >= 0; k--) {
if (niza[k] > l) {
cout << k + 1 << endl;
return 0;
}
l = min(l, niza[k]);
}
cout << m << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, i, a[100005];
while (cin >> n) {
for (i = 1; i <= n; i++) cin >> a[i];
for (i = n; i >= 1; i--) {
if (a[i - 1] > a[i]) break;
}
i--;
if (i < 0) i = 0;
cout << i << endl;
}
return 0;
}
| 8 | CPP |
n=input()
arr=input().split(" ")
asc=1
x=int(arr[0])
for i in range(1,int(n)):
if int(arr[i])>x:
asc+=1
else:
asc=1
x=int(arr[i])
print(int(n)-asc)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int ar[1000006];
int main() {
int a, b, d, e, x, y, z;
cin >> z;
for (a = 1; a <= z; a++) cin >> ar[a];
x = 0;
for (a = z; a > 1; a--) {
if (ar[a] > ar[a - 1])
x++;
else
break;
}
cout << z - x - 1 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double eps = 1e-9;
int main() {
int i, n, arr[100005], ret = 1;
cin >> n;
for ((i) = 0; (i) < (n); (i)++) cin >> arr[i];
for (i = n - 2; i >= 0; i--)
if (arr[i] < arr[i + 1])
ret++;
else
break;
cout << n - ret << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], m[100005], cnt;
int main() {
int i, mmin = 555555;
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (i = n - 1; i >= 0; --i) {
m[i] = mmin;
mmin = min(mmin, a[i]);
}
for (i = n - 1; i >= 0; --i)
if (a[i] > m[i]) {
cnt = i + 1;
break;
}
printf("%d", cnt);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int v[100010];
int n;
int main() {
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
int resp = n;
bool c = true;
for (int i = n - 1; i >= 0; i--) {
if (v[i] > resp) {
resp = i + 1;
c = false;
break;
} else
resp = v[i];
}
if (c) resp = 0;
printf("%d\n", resp);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
int n, a[MAXN], c = -1;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n - 1; ++i) {
if (a[i] > a[i + 1]) c = i;
}
cout << c + 1 << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.1415926536;
const int oo = (int)1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int di[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> myvec(n);
int mn = oo;
for (int i = 0; i < n; i++) {
cin >> myvec[i];
}
int counter = 0, ans = 0;
for (int i = 0; i < n - 1; i++) {
if (myvec[i] > myvec[i + 1]) {
ans += counter;
ans++;
counter = 0;
} else
counter++;
}
cout << ans;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[100100];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int c = 1;
for (int i = n - 1; i > 0; i--) {
if (a[i] < a[i + 1])
c++;
else
break;
}
cout << (n - c) << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long in() {
int32_t x;
scanf("%d", &x);
return x;
}
const long long maxn = 1e5 + 10;
long long res;
long long a[maxn];
int32_t main() {
long long n = in();
for (long long i = 0; i < n; i++) {
a[i] = in() - 1;
}
long long mini = 1e9;
for (long long i = n - 1; i >= 0; i--) {
res += mini < a[i] || bool(res);
mini = min(mini, a[i]);
}
cout << res << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
int i;
for (i = 0; i < rep; i++) p[i] = val;
}
int GETi() {
int i;
scanf("%d", &i);
return i;
}
template <class T>
T sqr(T val) {
return val * val;
}
int N;
int A[100001];
void solve() {
int f, r, i, j, k, l;
N = GETi();
for (i = 0; i < N; i++) A[i] = GETi() - 1;
j = 0;
for (i = N - 1; i >= 1; i--) {
if (A[i - 1] < A[i])
j++;
else
break;
}
printf("%d\n", N - 1 - j);
return;
}
int main(int argc, char** argv) {
if (argc > 1) freopen(argv[1], "r", stdin);
solve();
return 0;
}
| 8 | CPP |
n = int(input())
t = list(map(int, input().split()))
i = n - 1
while t[i] > t[i - 1]: i -= 1
print(i)
# Made By Mostafa_Khaled | 8 | PYTHON3 |
n = int(input())
t = list(map(int , input().split()))
i=n-1
while t[i] > t[i-1] : i=i-1
print (i) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long mm, mmm, k, cas, t, i, j, d[100005], tmp[100005];
while (scanf("%ld", &cas) == 1) {
j = 0;
for (t = 0; t < cas; t++) {
scanf("%ld", &d[t]);
tmp[t] = d[t];
}
sort(tmp, tmp + cas);
mmm = d[cas - 1];
for (i = cas - 1; i > 0; i--) {
mmm = min(mmm, d[i - 1]);
if (d[i - 1] > mmm) {
j = i;
break;
}
}
cout << j << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
long nnn;
cin >> nnn;
long *arr = new long[nnn];
for (long i = 0; i < nnn; ++i) cin >> arr[i];
long nn = 0;
for (long i = nnn - 2; i >= 0; --i)
if (arr[i] < arr[i + 1])
++nn;
else
break;
++nn;
cout << nnn - nn << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
int count = 1;
for (int i = n - 1; i > 0 && a[i] < a[i + 1]; i--) count++;
cout << n - count << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
vector<int> A;
int n;
scanf("%d", &n);
int a, b, res = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
A.push_back(a);
}
int i;
for (i = A.size() - 1; i >= 1; i--) {
if (A[i] < A[i - 1]) break;
}
cout << i << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int main() {
int n, left = -1, right, pos = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &right);
if (left > right) pos = i;
left = right;
}
printf("%d\n", pos);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int(i) = (0); (i) < (n); (i)++) cin >> arr[i];
int j = 1;
int ret = 0;
bool taken[n + 1];
memset(taken, 0, sizeof taken);
for (int(i) = (0); (i) < (n); (i)++) {
if (taken[j])
j++, i--;
else if (arr[i] == j)
j++;
else
ret = i + 1, taken[arr[i]] = 1;
}
cout << ret << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int i = n - 1;
while (i > 0 && a[i - 1] < a[i]) {
i--;
}
cout << i;
}
| 8 | CPP |
def main():
n = int(input())
threads = [int(i) for i in input().split()]
i = len(threads) -1
while i > 0:
if threads[i] < threads[i - 1]:
print(i)
return
i -= 1
print(0)
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int t[100010];
int main() {
int n, ans;
while (scanf("%d", &n) > 0) {
ans = 0;
for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
for (int i = n - 1; i >= 1; i--) {
if (t[i] > t[i + 1]) {
ans = i;
break;
}
}
printf("%d\n", ans);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
int n;
set<int> st;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int cur = n, ans = 0;
for (int i = n; i > 0; i--) {
if (st.find(a[i]) != st.end()) {
ans = i;
break;
}
while (a[i] != cur) st.insert(cur), cur--;
cur--;
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))[::-1]
ans = 0
acc = n
pre = 9999999999999
for i in range(n):
if l[i] < pre:
ans += 1
pre = l[i]
else:
break
print(n-ans) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
while (cin >> n) {
long flag = 0, count = 0, a[100005] = {0}, i;
for (i = 0; i < n; i++) cin >> a[i];
for (i = n - 1; i > 0; i--) {
if (a[i - 1] > a[i])
break;
else
count++;
}
cout << n - count - 1 << endl;
}
return 0;
}
| 8 | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.