Pagini recente » Cod sursa (job #1766523) | Cod sursa (job #1055471) | Cod sursa (job #835132) | Cod sursa (job #681722) | Cod sursa (job #1709388)
#include <stdio.h>
#define MOD 19997
int n;
int a[1000024];
int count = 0;
int vizIdx = 0;
int wtf(int i)
{
count++;
if (count >= 19997) {
count -= 19997;
}
if (i == n - 1) {
return a[i];
}
int oldcnt = count;
int wtfi = wtf(i + 1);
int difcnt = (19997 + count - oldcnt) % 19997;
if (a[i] < wtfi) {
return a[i];
} else {
count += difcnt;
count %= 19997;
return wtfi;
}
}
int main()
{
FILE *fin = fopen("twoton.in", "r");
FILE *fout = fopen("twoton.out", "w");
fscanf(fin, "%d", &n);
for (int i = 0; i < n; ++i) {
fscanf(fin, "%d", &a[i]);
}
wtf(0);
fprintf(fout, "%d\n", count);
fclose(fin);
fclose(fout);
}