#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
  int D;
  cin >> D;
  rep(i,D) cout << ((i % 26)+1) << endl;
}

Problem Statement

AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.

The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.

Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.

If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).

Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0).
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.

Constraints

D = 365

Each c_i is an integer satisfying 0\leq c_i \leq 100.

Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.

Input

Input is given from Standard Input in the following format:

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}

Output

Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d.
Print D integers t_d to Standard Output in the following format:

t_1
t_2
\vdots
t_D

Any output that does not follow the above format may result in 0 pointsWA for that test case.

Input Generation

Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192

Sample Output 1

1
17
13
14
13

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.

Input generator, score calculator, and visualizer

Beginner's Guide

If you don't know what to do, proceed to problem B or C.


#include <bits/stdc++.h>
using namespace std;

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  vector<vector<int>> lastc(D+1,vector<int>(26,0));
  vector<int> t(D);

    srand(std::time(nullptr));

  for(int i=1; i<=D; i++){

    int cont; /*cin >> cont;
    cont--;*/ cont=rand()%26;
    t[i-1]=cont;

    //lastcの更新
    for(int j=0; j<26; j++){
      if(j==cont) lastc[i][j]=i;
      else lastc[i][j]=lastc[i-1][j];
    }
  }

  int M=1000000;//調整
  for(int i=0; i<M; i++){
    int d,q; /*cin >> d >> q; q--;
    */
    d=rand()%D+1;
    q=rand()%26;
    int qold=t[d-1];

    int sat=0;

    sat = sat - s[d-1][qold];
    sat = sat + s[d-1][q];

    int lastcold = lastc[d-1][qold];
    for(int j=d; j<=D; j++){
      if(j==d){
        sat-=c[qold]*(j-lastcold);
      }
      else if(lastc[j][qold]==j){
        break;
      }
      else{
        sat-=c[qold]*(lastc[j][qold]-lastcold);
      }
    }

    for(int j=d; j<=D; j++){
      if(lastc[j][q]==j){
        break;
      }
      else{
        sat+=c[q]*(d-lastc[j][q]);
      }
    }

    if(sat>0){
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][qold]=lastc[j-1][qold];
        }
        else if(lastc[j][qold]==j){
          break;
        }
        else{
          lastc[j][qold]=lastc[j-1][qold];
        }
      }

      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][q]=d;
        }
        else if(lastc[j][q]==j){
          break;
        }
        else{
          lastc[j][q]=lastc[j-1][q];
        }
      }

      t[d-1]=q;
    }
  }

  for(int i=0; i<D; i++){
    cout << t[i]+1 << endl;
  }
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


#include <bits/stdc++.h>
using namespace std;

int main() {
  int D;
  vector<pair<int, int>> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  vector<int> t(D);

  cin >> D;
  for(int i = 0; i < 26; i++){
    cin >> c.at(i).first;
    c.at(i).second = 0;
  }

  for(int i = 0; i < D; i++){
    for(int j = 0; j < 26; j++){
      cin >> s.at(i).at(j);
    }
  }

  for(int i = 0; i < D; i++){
    t.at(i) = rand() % 26+1;
  }

  int count = 0;
  int S = 0;
  vector<int> ans(D);
  while(count++ < 50000){

  t.at((rand() % D+1)-1) = rand() % 26+1;

  int Pl = 0;
  int Mi = 0;

    for(int i = 0; i < D; i++){
      Pl += s.at(i).at(t.at(i)-1);
      c.at(t.at(i)-1).second = i + 1;
      for(int j = 0; j < 26; j++){
        Mi += c.at(j).first*(i+1 - c.at(j).second);
      }
      Pl -= Mi;
      Mi = 0;
    }
  if(S < Pl){
    S = Pl;
    for(int i = 0; i < D; i++){
      ans.at(i) = t.at(i);
    }
  }
  else if(S >= Pl){
    continue;
  }
}
  for(int i = 0; i < D; i++){
    cout << ans.at(i) << endl;
  }
}


/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;
constexpr int64_t kMod1 = 1000000007LL;
constexpr int64_t kMod2 = 998244353LL;
constexpr int64_t kMod3 = 3571L;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  constexpr int64_t kN = 26;
  int64_t D;
  cin >> D;
  vector<int64_t> C(kN + 1, 0);
  for (int64_t c = 1; c <= kN; ++c) {
    cin >> C[c];
  }
  vector<vector<int64_t>> S(D + 1, vector<int64_t>(kN + 1));
  for (int64_t d = 1; d <= D; ++d) {
    for (int64_t c = 1; c <= kN; ++c) {
      cin >> S[d][c];
    }
  }
  vector<vector<int64_t>> last(D + 1, vector<int64_t>(kN + 1, 0));
  vector<int64_t> contests(D + 1);
  for (int64_t d = 1; d <= D; ++d) {
    cin >> contests[d];
  }

  auto Score = [&](const int64_t day) -> int64_t {
    int64_t score = 0;
    for (int64_t d = 1; d <= day; ++d) {
      last[d] = last[d - 1];
      last[d][contests[d]] = d;
      score += S[d][contests[d]];
      for (int64_t c = 1; c <= kN; ++c) {
        score -= C[c] * (d - last[d][c]);
      }
    }
    return score;
  };

  auto OutputResults = [&]() {
    for (int64_t d = 1; d <= D; ++d) {
      cout << contests[d] << endl;
    }
  };

  for (int64_t d = 1; d <= D; ++d) {
    int64_t best_score = INT64_MIN;
    int64_t best_conte = -1;
    for (int64_t c = 1; c <= kN; ++c) {
      contests[d] = c;
      int64_t temp_score = Score(d);
      if (temp_score > best_score) {
        best_score = temp_score;
        best_conte = c;
      }
    }
    contests[d] = best_conte;
  }

  int64_t day_index = 123;
  int64_t contest_index = 2034;
  int64_t ignore_index = 34234;
  int64_t prev_score = Score(D);
  constexpr int64_t kIgnoreBunbo = 5;
  constexpr int64_t kIgnoreBunshi = 0;
  constexpr int64_t kMaxConsecutiveWorse = 3;

  vector<int64_t> best_contests;
  int64_t best_score = INT64_MIN;
  int64_t consecutive_worse = 0;
  vector<int64_t> better_contests;
  for (int64_t i = 0; i < 50000; ++i) {
    const int64_t day_candidate = (day_index % D) + 1;
    const int64_t original_contest = contests[day_candidate];
    const int64_t contest_candidate = (contest_index % kN) + 1;
    contests[day_candidate] = contest_candidate;
    const int64_t temp_score = Score(D);
    if (temp_score > prev_score) {
      // KEEP
      consecutive_worse = 0;
      better_contests = contests;
      if (temp_score > best_score) {
        best_score = temp_score;
        best_contests = contests;
      }
    } else if (ignore_index <= kIgnoreBunshi && temp_score > prev_score * 0.97 &&
               consecutive_worse <= kMaxConsecutiveWorse) {
      // KEEP
      ++consecutive_worse;
    } else {
      contests[day_candidate] = original_contest;
    }
    if (temp_score < best_score * 0.9) {
      contests = better_contests;
    }
    if (temp_score < best_score * 0.5) {
      contests = best_contests;
    }
    day_index = day_candidate + kMod1;
    contest_index = contest_candidate + kMod2;
    ignore_index += kMod3;
    ignore_index %= kIgnoreBunbo;
  }

  contests = best_contests;
  OutputResults();
  return 0;
}


#include "bits/stdc++.h"
using namespace std;

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int D, c[27];
int s[366][27];

chrono::steady_clock::time_point program_begin;

double runtime() {
	chrono::steady_clock::time_point program_end = chrono::steady_clock::now();

	return chrono::duration_cast<chrono::microseconds>(program_end - program_begin).count() / 1000000.0;
}

int calc(vector<int> sc) {
	vector<int> last(27, 0);
	int val = 0;
	rep(d, 1, D + 1) {
		val += s[d][sc[d]];
		last[sc[d]] = d;
		rep(i, 1, 27)
			val -= c[i] * (d - last[i]);
	}
	return val;
}

int myrand(int a, int b) {
	return a + rand() % (b - a + 1);
}

void solve() {
	vector<int> ans(366), best_ans(366);
	int best_ans_val = -50000000;
	int cur_val = calc(ans);

	for (int i = 1; i <= 365; i++)
		ans[i] = i % 26 + 1;

	{
		int val = calc(ans);
		if (val > best_ans_val) {
			best_ans_val = val;
			best_ans = ans;
		}
	}

	double T1 = 0.4;
	double T2 = 1.8;

	auto rng = default_random_engine {};
	while (runtime() <= T1 / 2) {
		for (int i = 1; i + 25 <= 365; i += 26) {
			shuffle(ans.begin() + i, ans.begin() + i + 26, rng);
		}

		int val = calc(ans);
		if (val > best_ans_val) {
			best_ans_val = val;
			best_ans = ans;
		}
	}
	while (runtime() <= T1) {
		for (int i = 1; i <= 365; i++)
			ans[i] = myrand(1, 26);

		int val = calc(ans);
		if (val > best_ans_val) {
			best_ans_val = val;
			best_ans = ans;
		}
	}

	ans = best_ans;
	cur_val = best_ans_val;

	//cerr << "INIT:" << best_ans_val << endl;

	while (runtime() <= T2) {
		vector<int> new_ans = ans;
		int d = myrand(1, 365), n = myrand(1, 26);
		new_ans[d] = n;
		int new_val = calc(new_ans);

		double base_proc = exp(-50.0 * (runtime() - T1) / (T2 - T1));
		double rand_double = 1.0 * rand() / RAND_MAX;
		bool accept =
			rand_double < base_proc * (1.0 * new_val / best_ans_val);

		if (new_val > cur_val || accept) {
			ans = new_ans;
			cur_val = new_val;

			if (chmax(best_ans_val, cur_val)) {
				best_ans_val = cur_val;
				best_ans = ans;
			}
		}
	}

	rep(i, 1, D + 1)
		write(best_ans[i]);
}

void test() {}

int main(int argc, char *argv[]) {
	//cin.tie(0)->sync_with_stdio(0);
	//cin.exceptions(cin.failbit);

	srand(time(NULL));

	program_begin = chrono::steady_clock::now();

	read(D);
	rep(i, 1, 27) read(c[i]);
	rep(i, 1, D + 1) rep(j, 1, 27) read(s[i][j]);

	solve();
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// initial: random
// annealing: no
// 77477817

// initial: max s
// annealing: no
// 93907681

// initial: max s
// annealing:         if (diff >= 0 || (rng()%10 < 1 && diff > -1000)) {
// 98343220

// initial: max s
// annealing:         if (diff >= 0 || (rng()%10 < 1 && diff > -1000)) {
// choose bigger c[i]
// 98745730

// annealing: if (diff >= 0 || (rng()%10 < 1 && clock() - start < 1.8 * CLOCKS_PER_SEC)) {
// initial: max s
// choose bigger c[i]
// time 1.95

class AAtCoderContestScheduling {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;

      int d; cin >> d;
      vector<int> c(26);
      vector<int> prob;
      rep(i, 26) {
        cin >> c[i];
        rep(j, c[i]) {
          prob.push_back(i);
        }
      }
      int ps = prob.size();
      vector<vector<ll>> s(d, vector<ll>(26));
      rep(i, d) rep(j, 26) {
        cin >> s[i][j];
      }
      ll ret = 0;
      set<int> last[26];
      rep(i, 26) {
        last[i].insert(0);
        last[i].insert(d+1);
      }
      vector<ll> last2(26);
      vector<int> contests(d);
      rep(i, d) {
        ll ma = -1;
        int t = -1;
        rep(j, 26) {
          if (chmax(ma, s[i][j])) t = j;
        }

        contests[i] = t;
        ret += s[i][t];
        last[t].insert(i+1);
        last2[t] = i+1;
        rep(j, 26) {
          ret -= c[j]*(i+1-last2[j]);
        }
      }

      auto start = clock();

      while(clock() - start < 1.95 * CLOCKS_PER_SEC) {
        int day = rng()%d;
        int q = prob[rng()%ps];

        int before = contests[day];

        ll diff = 0;
        diff += s[day][q];
        diff -= s[day][before];

        day++;
        last[before].erase(day);
        auto it = last[before].upper_bound(day);
        int right = (*it);
        it--;
        int left = (*it);
        diff -= c[before]*(day-left)*(right-day);

        it = last[q].upper_bound(day);
        right = (*it);
        it--;
        left = (*it);
        diff += c[q]*(day-left)*(right-day);
        //debug(day, q, diff);

        if (diff >= 0 || (rng()%10 < 1 && clock() - start < 1.8 * CLOCKS_PER_SEC)) {
          last[q].insert(day);
          contests[day-1] = q;
          ret += diff;
        } else {
          last[before].insert(day);
        }
      }

      rep(i, d) {
        cout << contests[i]+1 << '\n';
      }
      debug(ret);
    }
};

signed main() {
  AAtCoderContestScheduling solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include<iostream>
using namespace std;
int main() {

	int d;
	cin >> d;
	int c[26];
	int i, j;
	for (i = 0; i < 26; i++) {
		cin >> c[i];
	}
	int s[365][26];
	for (i = 0; i < d; i++) {
		for (j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}
	int last[26];
	for (i = 0; i < 26; i++) {
		last[i] = 0;
	}
	int jmax, jindex;
	for (i = 1; i <= d; i++) {

		jmax = 0;
		jindex = -1;
		for (j = 0; j < 26; j++) {
			if (c[j] *(i - last[j]) > jmax) {
				jmax = c[j] *(i - last[j]);
				jindex = j;
			}
			else if (c[j] *(i - last[j]) == jmax) {
				if (s[i - 1][j] > s[i - 1][jindex]) {
					jindex = j;
				}
			}
		}
		for (j = 0; j < 26; j++) {
			if (s[i - 1][j] + 20 * c[j] * (i - last[j]) >= jmax) {
				jmax = s[i - 1][j] + 20 * c[j] * (i - last[j]);
				jindex = j;
			}
		}
		last[jindex] = i;
		cout << jindex + 1 << endl;

	}
	return 0;

}


#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int d, n;
  n = 26;
  cin >> d;
  vi c(n);
  rep(i, n) cin >> c[i];
  int ca = 0;
  rep(i, n) ca += c[i];
  dump(ca);
  vvi s(d, vi(n));
  rep(i, d) rep(j, n) cin >> s[i][j];
  ll sc = 0;
  vi l(n, -1);
  rep(i, d) {
    vl g(n);
    rep(j, n) {
      g[j] = s[i][j];
      rep(k, n) {
        if (j == k) {
        } else {
          g[j] -= (ll)c[k] * (i - l[k]);
        }
      }
    }
    int mi = 0;
    ll mx = g[0];
    rep(j, n) {
      if (mx < g[j]) {
        mx = g[j];
        mi = j;
      }
    }
    sc += mx;
    l[mi] = i;
    dump(g, mi, sc);
    cout << mi + 1 << endl;
  }
  dump(sc);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}


#include <bits/stdc++.h>
#include <random>

using namespace std;

int main() {

	int D;
	cin >> D;

	vector<int> c(27);
	for (int i = 1; i <= 26; i++) {
		cin >> c[i];
	}

	vector<vector<int>> sd(D + 1, vector<int>(27));

	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> sd[i][j];
		}
	}

	mt19937 mt{ std::random_device{}() };

	uniform_int_distribution<int> dist(1, 26);

	int resmax = 0;
	vector<int> maxcont(D + 1);

	for (int k = 0; k < 100000; k++) {

		int tmpres = 0;
		vector<int> cont(D + 1);
		vector<int> lastcont(27);

		for (int i = 1; i <= D; i++) {

			cont[i] = dist(mt);

			lastcont[cont[i]] = i;
			tmpres += sd[i][cont[i]];

			for (int j = 1; j <= 26; j++) {
				tmpres -= c[j] * (i - lastcont[j]);
			}

		}

		if (resmax < tmpres) {
			resmax = tmpres;
			maxcont = cont;
		}
	}

	for (int i = 1; i < D; i++) {
		cout << maxcont[i] << endl;
	}
	cout << maxcont[D];

	return 0;

}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

const int N=365, M=26;
int c[26], s[365][26];
int res[365];

int calc(){
    int ret=0;
    vector<int> last(26,-1);
    rep(i,N){
        ret+=s[i][res[i]];
        last[res[i]]=i;
        rep(j,26)ret-=c[j]*(i-last[j]);
    }
    return ret;
}
struct Xor128{
    unsigned x,y,z,w;

    Xor128(unsigned w_=88675123):x(123456789),y(362436069),z(521288629),w(w_){};

    inline unsigned xor128(){
        unsigned t;
        t = x^(x<<11);
        x = y;
        y = z;
        z = w;
        return w = (w^(w>>19))^(t^(t>>8));
    }

    int nextInt(int x,int y){
		if(x>y)swap(x,y);
        return xor128()%(y-x)+x;
    }

    double nextDouble(double a,double b){
        return (double)(xor128()&0xffff)/0xffff*(b-a)+a;
    }

};
int main(){
    int _;cin>>_;
    rep(i,M)cin>>c[i];
    rep(i,N)rep(j,M)cin>>s[i][j];
    auto rnd=Xor128();
    rep(i,N)res[i]=rnd.nextInt(0, M);
    int cur = calc();
    rep(_,100000){
        int i=rnd.nextInt(0, N), j=rnd.nextInt(0,M);
        int tmp=res[i];
        res[i]=j;
        int nc = calc();
        if(nc>cur){
            cur=nc;
        }
        else {
            res[i]=tmp;
        }
    }
    rep(i,N)cout<<res[i]+1<<endl;
    cerr << cur << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  for(int i = 0;i < 26;i++)cout << 1 << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 2e5 + 10;
int n,m,k;
int a[N],b[N];
int main(){
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];
    int i = 1 , j = 1;
    bool check = true;
    while (check == true){
        check = false;
        if (a[i] < b[j] && k >= a[i] && i <= n){
            k = k - a[i];
            i++;
            check = true;
        }
        else
        if (k >= b[j] && j <= m){
            k = k - b[j];
            j++;
            check = true;
        }
        else
        if (a[i] == b[j] && k >= a[i]){
            if (i <= n) k = k - a[i] , check = true , i++;
            else
            if (j <= m) k = k - b[j] , check = true , j++;
        }
        //cout << k << "\n";
    }
    cout << i + j - 2;
    return 0;
}

Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.


#include<iostream>
#include<stack>
#include<queue>
using namespace std;
const int MAX = 1e9+7;
int main()
{
    queue<int> a,b;
    int n,m,k,books=0;
    cin>>n>>m>>k;
    for(int i=0;i<n;i++)
    {
        int rp;
        cin>>rp;
        a.push(rp);
    }
    a.push(MAX);
    for(int i=0;i<m;i++)
    {
        int rp;
        cin>>rp;
        b.push(rp);
    }
    b.push(MAX);
    while(k>=a.front()||k>=b.front())
    {
        if(a.front()>b.front()&&b.front()<=k)
        {
            k=k-b.front();
            b.pop();
            books++;
        }
        else if(a.front()<=b.front()&&a.front()<=k)
        {
            k=k-a.front();
            a.pop();
            books++;
        }
    }
    cout<<books<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,m;
ll k;
ll a[200010],b[200010];
vector<ll> S;

void solve(){
    cin >> n >> m >> k;
    rep(i,n) cin >> a[i];
    S.resize(m+1);
    rep(i,m) {
        cin >> b[i];
        S[i+1]=S[i]+b[i];
    }
    int ans=0;
    ll A=0;
    int num_=upper_bound(S.begin(),S.end(),k-A)-S.begin()-1;
    ans=max(ans,num_);
    rep(i,n){
        A+=a[i];
        int num=upper_bound(S.begin(),S.end(),k-A)-S.begin()-1;
        if(num<0) continue;
        ans=max(ans,i+1+num);
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

const int MAXM = 200001;

ll A[MAXM],B[MAXM];

int main(){
    ll N,M,K;cin >> N >> M >> K;

    rep(i,N)cin >> A[i];
    rep(i,M)cin >> B[i];
    ll count = 0;
    ll a=0,b=0;
    bool a_ok = true, b_ok = true;
    while(1) {
        if((A[a] > B[b] || !a_ok) && b_ok){
            K-=B[b];
            b++;
            if(b>=M)b_ok = false;
        }else if(a_ok){
            K-=A[a];
            a++;
            if(a>=N)a_ok = false;
        }
        if(!a_ok && !b_ok){
            count++;
            break;
        }
        if(K<0){
            break;
        }
        count++;
    }
    cout << count << endl;

    return 0;
}


#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n, m, k;
	cin >> n>>m>>k;
	stack<int> s1, s2;
	int A[n], B[m];
	for (int i = 0; i < n; i++)
		cin >> A[i];
	for (int i = 0; i < m; i++)
		cin >> B[i];
	for (int i = n- 1; i >=0; i--)
		s1.push(A[i]);
	for (int i = m - 1; i >= 0; i--)
		s2.push(B[i]);
	unsigned long long int count = 0;
	while (k > 0) {
		if (!s1.empty() && !s2.empty()) {
			if (s1.top() <= s2.top()) {
				k = k - s1.top();
				//cout << s1.top() << " " << k << "\n";
				s1.pop();
				count++;
			}
			else {
				k = k - s2.top();
				//cout << s2.top() << " " << k << "\n";
				s2.pop();
				count++;
			}
		}
		else {
			if (!s1.empty()) {
				k = k - s1.top();
				//cout << s1.top() << " " << k << "\n";
				s1.pop();
				count++;

			}
			else if (!s2.empty())
			{
				k = k - s2.top();
				//cout << s2.top() << " " << k << "\n";
				s2.pop();
				count++;

			}
			if (s1.empty() && s2.empty() && k > 0)
				k = 0;
		}

	}
	if (k < 0)
		count--;
	cout << count;
}


#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n, m,count = 0, c = 0;
    long long int k;
    cin >> n >> m >> k;
    vector<long long int> a(n);
    vector<long long int> b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    int i = 0, j = 0;
    while (i!=n||j!=m) {
        if (i == n) {
            if (b[j] + c > k) {
                break;
            }
            else {
                count++;
                c += b[j];
                j++;
            }
        }
        else if (j == m) {
            if (a[i] + c > k) {
                break;
            }
            else {
                count++;
                c += a[i];
                i++;
            }
        }
        else if ((c + a[i]) > k && (c + b[j]) > k) {
            break;
        }
        else if (a[i] < b[j]) {
            c += a[i];
            i++;
            count++;
        }
        else {
            c += b[j];
            j++;
            count++;
        }
    }
    cout << count << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define MOD 1000000007

int main(){

  int N;
  int M;
  int K;
  int ans = 0;
  int buf = 0;

  int index_A = 0;
  int index_B = 0;
  cin >> N;
  cin >> M;
  cin >> K;

  vector<int> A(N+1,0);
  vector<int> B(M+1,0);

  for(int i=1;i<=N;i++){
    cin >> buf;
    if ( A[i-1] + buf <= K) {
      A[i] = A[i-1] + buf;
      index_A = i;
    } else {
      break;
    }
  }

  for(int i=1;i<=M;i++){
    cin >> buf;
    if ( B[i-1] + buf <= K) {
      B[i] = B[i-1] + buf;
      index_B = i;
    } else {
      break;
    }
  }

  ans = max(index_A, index_B);

  for (int i = 0; i <= index_A; i++) {
    while (A[i] + B[index_B] > K) {
      index_B--;
    }
    ans = max(i + index_B, ans);
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  vector<ll> aSum(n + 1, 0);
  vector<ll> bSum(m + 1, 0);
  rep(i, n) {
    cin >> a.at(i);
    aSum.at(i + 1) = (ll) a.at(i) + aSum.at(i);
  }
  rep(i, m) {
    cin >> b.at(i);
    bSum.at(i + 1) = (ll) b.at(i) + bSum.at(i);
  }
  int res = 0;
  for (int ac = 0; ac <= n; ac++) {
    ll xSumV = aSum.at(ac);
    if (xSumV > k) {
      continue;
    }
    auto itB = upper_bound(bSum.begin(), bSum.end(), (ll) k - xSumV);
    int bc = (ll) distance(bSum.begin() + 1, itB);
    res = max(res, ac + bc);
  }
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a(n);
	vector<int> b(m);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < m; i++)
		cin >> b[i];
	int i = 0;
	int j = 0;
	int count = 0;
	while(i < n && j < m){
		if(a[i] < b[j]){
			if(k >= a[i]){
				k -= a[i];
				i++;
				count++;
			}
			else{
				cout << count;
				return 0;
			}
		}
		else{
			if(k >= b[j]){
				k -= b[j];
				j++;
				count++;
			}
			else{
				cout << count;
				return 0;
			}
		}
	}
	while(i < n){
		if(k >= a[i]){
			i++;
			k -= a[i];
			count++;
		}
		else{
			cout << count;
			return 0;
		}
	}
	while(j < m){
		if(k >= b[i]){
			j++;
			k -= b[j];
			count++;
		}
		else{
			cout << count;
			return 0;
		}
	}
	cout << count;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    long long int k,i,count=0;
    bool flag1=1,flag2=1;
    cin>>n>>m>>k;
    long long int A[n],B[m];
    for(i=0;i<n;i++)
        cin>>A[i];
    for(i=0;i<m;i++)
        cin>>B[i];
    i=0;
    while(k>0&&((i<m)||(i<n)))
    {
        if(i<n)
        {
        if((k>=A[i])&&(flag1==1))
        {
            k-=A[i];
            count++;
        }
        else
            flag1=0;
        }
        if(i<m)
        {
        if((k>=B[i])&&(flag2==1))
        {
            k-=B[i];
            count++;
        }
        else
            flag2=0;
        }
        i++;
    }
    cout<<count<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int64_t N,M,K;
  cin >> N >> M >> K;
  vector<int64_t> A(N),B(M);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<M;i++){
    cin >> B.at(i);
  }
  int64_t sum=0;
  int64_t na=0;
  int64_t nb=0;
  int64_t ans=0;
  while((na<N)&&(nb<M)){
    if(sum>K){
      ans--;
      cout << ans << endl;
      return 0;
    }
    if(A.at(na)<=B.at(nb)){
      sum+=A.at(na);
      na++;
      ans++;
    }else{
      sum+=B.at(nb);
      nb++;
      ans++;
    }
  }
  while(na<N){
    if(sum>K){
      ans--;
      cout << ans << endl;
      return 0;
    }
    sum+=A.at(na);
    na++;
    ans++;
  }
  while(nb<M){
    if(sum>K){
      ans--;
      cout << ans << endl;
      return 0;
    }
    sum+=B.at(nb);
    nb++;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x
#define pb push_back
#define mp make_pair

vi a(200005), b(200005);

int32_t main()
{
    fast;
    int n, m, k, c = 0; cin >> n >> m >> k;
    For(i, 0, n) cin >> a[i];
    For(i, 0, m) cin >> b[i];
    For(i, 0, n) {
        if(k - a[i] >= 0) {
            k -= a[i];
            c++;
        }
    }

    For(i, 0, m) {
        if(k - b[i] >= 0) {
            k -= b[i];
            c++;
        }
    }

    cout << c;

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   ";
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N), B(M);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++) cin >> B[i];

    vector<ll> wa_a(N+1), wa_b(M+1);
    wa_a[0] = 0; wa_b[0] = 0;
    for(int i=1; i<=N; i++) wa_a[i] = wa_a[i-1] + A[i-1];
    for(int i=1; i<=M; i++) wa_b[i] = wa_b[i-1] + B[i-1];
    wa_a.push_back(3e16);
    wa_b.push_back(3e16);
    // cout << "  wa_a:  "; print_vec(wa_a);
    // cout << "  wa_b:  "; print_vec(wa_b);

    //O(NlogN)解法  累積和 + 2分探索
    ll ans = 0;
    for(int num_a=0; num_a<=N; num_a++){
      ll time = K - wa_a[num_a];
      auto iter = upper_bound(wa_b.begin(), wa_b.end(), time);
      auto index = iter - wa_b.begin();
      //cout << "  num_a: " << num_a << " num_b: " << index-1 << endl;
      if(index-1<0) continue;
      ans = max(ans, num_a + (ll)index-1);
    }
    cout << ans << endl;

    // O(N+M)解法  累積和 + 尺取り法 (2pointers)
    // ll ans = 0;
    // ll num_a = N;// Aから読む冊数
    // for(int num_b=0; num_b<=M; num_b++){
    //   if(wa_b[num_b] > K) break;
    //   while(wa_a[num_a] + wa_b[num_b] > K){
    //     num_a--;
    //   }

    //   ans = max(ans, num_a + num_b);
    // }

    // cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    ll a[n+10];
    ll b[m+10];
    ll suma[n+10];
    ll sumb[m+10];
    rep(i,n){
        ll temp;
        cin >> temp;
        a[i] = temp;
        if(i == 0) {
            suma[i] = temp;
        }
        else{
            suma[i] = suma[i-1]+temp;
        }
    }
    rep(i,m){
        ll temp;
        cin >> temp;
        b[i] = temp;
        if(i == 0) {
            sumb[i] = temp;
        }
        else{
            sumb[i] = sumb[i-1]+temp;
        }
    }
    ll upper = m-1;
    bool ok = false;
    ll ans = -1;
    rep(i,n){
        if(suma[i] >= k) upper = 0;
        while(sumb[upper] > k-suma[i] && upper > 0){
            upper--;
        }
        //ans = max(ans,upper+i+2);
        if(suma[i]+sumb[upper] <= k){
            ok = true;
            ll temp = upper+i+2;
            if(ans < upper+i+2){
                ans = temp;
            }
        }
    }
    if(ok) cout << ans << endl;
    else cout << 0 << endl;
}


#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,m,k;cin >> n >> m >> k;
    int a[n],b[m];
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    vector<int> sa(n+1),sb(m+1);
    rep(i,n)sa[i+1] = sa[i] + a[i];
    rep(i,m)sb[i+1] = sb[i] + b[i];
    int bot = 0;
    int top = 440000;
    auto ok = [&](int c){
        //cことる
        int res = 1001001001;
        rep(na,c+1){
            int ret = 0;
            int nb = c - na;
            if(nb < 0|| nb > m||na < 0 || na > n)continue;
            ret += sa[na];
            ret += sb[nb];
            //trace(c,na,nb,ret);
            res = min(res,ret);

        }
        //trace(res,c);
        return res <= k;

    };
    while(top - bot > 1){
        int mid = (top + bot)/2;
        if(ok(mid))bot = mid;
        else top = mid;
    }
    cout << bot << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M,K;
    cin >> N >> M >> K;
    vector<int>A1(N);
    vector<int>B1(M);
    vector<int>A;
    vector<int>B;
    int cnt1 = N;
    for(int i = 0; i < N; i++) {
        cin >> A1[i];
    }
    for(int i = 0; i < M; i++) {
        cin >> B1[i];
    }
    A.push_back(0);
    B.push_back(0);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cnt = cnt+A1[i];
        if(cnt > K) {
            cnt1 = i;
        }
        A.push_back(cnt);
    }
    cnt = 0;
    for(int i = 0; i < M; i++) {
        cnt = cnt+B1[i];
        B.push_back(cnt);
    }
    int ans = 0;
    for(int i = 0; i <= cnt1; i++) {
        auto it = upper_bound(B.begin(),B.end(),K-A[i]);
        if(it == B.end()) {
            ans = max(ans,i+M);
        }
        int X = it-B.begin()-1;
        if(X > 0) {
            ans = max(ans,i+X);
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <string>
using namespace std;

int main(){
    int N, M, K;
    cin >> N >> M >> K;

    int A[N], B[M];
    int tmpA[N], tmpB[M];
    int time[K];
    int i;

    // input A and B
    for(i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (i = 0; i < M; ++i)
    {
        cin >> B[i];
    }

    for (i = 0; i < N+M; ++i){

    }

    return 0;
}


#include<bits/stdc++.h>
#define ll   long long int
using namespace std;
int main()
{
  ll n,m,k;
  cin>>n>>m>>k;
  ll arr1[n];
  ll arr2[m];
  stack<ll> s1,s2;
  for(ll i=0;i<n;i++)
  {
    cin>>arr1[i];

  }
  for(ll i=n-1;i>=0;i--)
    s1.push(arr1[i]);
  for(ll i=0;i<m;i++)
    cin>>arr2[i];
  for(ll i=m-1;i>=0;i--)
    s2.push(arr2[i]);
  vector<ll> v;
  ll a,b;
  while(!s1.empty() || !s2.empty())
  {
    a=s1.top();
    b=s2.top();
    if(a>=b)
    {
      s2.pop();
      v.push_back(b);

    }
    else
    {
      s1.pop();
      v.push_back(a);
    }

  }
  if(!s1.empty())
  {
    while(!s1.empty())
    {
      v.push_back(s1.top());
      s1.pop();

    }

  }
  if(!s2.empty())
  {
    while(!s2.empty())
    {
      v.push_back(s2.top());
      s2.pop();

    }

  }
  ll count=0;
  for(ll i=0;i<v.size();i++)
  {
    if(k>=v[i])
    {
      count++;
      k=k-v[i];

    }
    else
      break;

  }
  cout<<count<<endl;

  }


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int n,m,k;
long long int all=0;
vector<long long int> a,b;
int main(void){
  cin>>n>>m>>k;
  a.resize(n+1);
  b.resize(m+1);
  a.at(0)=0;
  b.at(0)=0;
  for(long long int i=0; i<n; i++){
    long long int hoge;
    cin>>hoge;
    a.at(i+1)=a.at(i)+hoge;
  }
  for(long long int i=0; i<m; i++){
    long long int hoge;
    cin>>hoge;
    b.at(i+1)=b.at(i)+hoge;
  }
  all=a.at(n)+b.at(m);
  if(all<=k){
    cout<<n+m<<endl;
  }else{
    long long int ans=0;
    for(long long int i=0; i<=n; i++){
      long long int pre=i;
      long long int high=m;
      long long int low=0;
      long long int mid;
      long long int hoge;
      while(high>=low){
        mid=(high+low)/2;
        hoge=a.at(i)+b.at(mid);
        if(hoge==k){
          break;
        }else if(hoge>k){
          high=mid-1;
        }else{
          low=mid+1;
        }
      }
      if(hoge>k){
        if(mid!=0&&a.at(i)+b.at(mid-1)<=k){
          ans=max(ans,i+mid-1);
        }
      }else{
        if(mid!=m&&a.at(i)+b.at(mid+1)<=k){
          ans=max(ans,i+mid+1);
        }else{
          ans=max(ans,i+mid);
        }
      }
    }
    cout<<ans<<endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
int n, m, i, j, k, s, ans, x=1, y=1, a[200005], b[200005];
int main()
{
	memset (a, 9, sizeof(a));
	memset (b, 9, sizeof(b));
	scanf ("%d%d%d", &n, &m, &k);
	for (i=1; i<=n; i++)	scanf ("%d", &a[i]);
	for (i=1; i<=m; i++)	scanf ("%d", &b[i]);
	while (s<=k)
	{
		if (x > n && y > m)
			break;
		if (s + a[x] > k && s + b[y] > k)
			break;
		if (a[x] < b[y])
		{
			s += a[x];
			x++;
			ans++;
		}
		else
		{
			s += b[y];
			y++;
			ans++;
		}
	}
	printf ("%d", ans);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N);
    vector<int> B(M);

    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }

    int count = 0;
    unsigned long long int cost = 0;
    bool flag = true;
    if (*A.begin() > K && *B.begin() > K){
        cout << 0 << endl;
        return 0;
    }

    while (flag) {
        if (A.size() > 0 && A.begin() <= B.begin()) {
            // cout << "A, " << count << endl;
            cost += *A.begin();
            A.erase(A.begin());
            count++;
        }else{
            // cout << "B, " << count << endl;
            if(B.size() < 1) break;
            cost += *B.begin();
            B.erase(B.begin());
            count++;
        }
        if(cost > K){
            flag = false;
        }else{
            if(A.size() > 0 && cost + *A.begin() > K && B.size() > 0 && cost + *B.begin() > K) flag = false;
            // if (A.size() < 1 && B.size() < 1) break;
        }
    }
    cout << count << endl;
}


#include<cstdio>
#include<algorithm>
using namespace std;
#define int long long
const int maxn=2e5+5;
const int INF=0x3f3f3f3f3f3f3f3f;
int a[maxn],b[maxn],f_a[maxn],f_b[maxn];
signed main()
{
    int n,m,k;
    scanf("%lld%lld%lld",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
        f_a[i]=f_a[i-1]+a[i];
    for(int i=1;i<=m;i++)
        scanf("%lld",&b[i]);
    for(int i=1;i<=m;i++)
        f_b[i]=f_b[i-1]+b[i];
    f_b[m+1]=INF;
    int ans=0;
    for(int i=0;i<=n;i++)
    {
        if(f_a[i]>k) break;
        int left=k-f_a[i];
        int pos=(int)(upper_bound(f_b,f_b+m+2,left)-f_b);
        pos--;
        ans=max(ans,pos+i);
    }
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M,K;
    cin >> N >> M >> K;
    vector<int>A(N+2);
    vector<int>B(M+2);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < M; i++) {
        cin >> B[i];
    }
    A[N] = INF;
    B[M] = INF;
    A[N+1] = INF;
    B[M+1] = INF;
    int ans = 0;
    int cnt = 0;
    int cnt1 = 0;
    int cnt2 = 0;
    while(cnt <= K) {
        if(cnt+A[cnt1] > K && cnt+B[cnt2] > K) {
            goto age;
        }
        if(cnt+A[cnt1]+A[cnt1+1] > K && cnt+A[cnt1]+B[cnt2] > K &&
           cnt+B[cnt2]+B[cnt2+1] > K) {
            ans++;
            goto age;
        }
        else if(A[cnt1]+A[cnt1+1] < B[cnt2]+B[cnt2+1]) {
            cnt+=A[cnt1];
            cnt1++;
            ans++;
        }
        else {
            cnt+=B[cnt2];
            cnt2++;
            ans++;
        }
    }
    age:;
    cout << ans << endl;
}


/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
using   ld =          long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;
vi aa(N,0);

int main()
{
    _SAD()
    int n,m,k;
  cin>>n>>m>>k;
  int a[n],b[m];
  for(int i=0;i<n;i++)
    {
     cin>>a[i];
    }
  for(int i=0;i<m;i++)
    { cin>>b[i];
     }
  sort(a,a+n);
  sort(b,b+m);
  ll cnt=0,ans=0;
  int i=0,j=0;
  while(cnt<k)
    {
    if((min(a[i],b[j])+cnt<=k)&&i<n&&j<m)
      { ans++;
      cnt+=min(a[i],b[j]);
        if(a[i]<=b[j])i++;
        else j++;
       // cout<<min(a[i],b[j])<<" mm ";
       }
     else if(cnt+a[i]<=k&&i<n)
       {
         cnt+=a[i];ans++;//cout<<a[i]<<" aa ";
        i++;
       }
      else if(cnt+b[j]<=k&&j<m)
        {
         cnt+=b[j];ans++;//cout<<b[j]<<" bb ";
         j++;
         }
     else break;
    }
   cout <<ans<<nl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	long long n, m, k;
	cin >> n >> m >> k;
	long long a[n], b[m];
	long long c[n+1], d[m+1];
	c[0] = 0;
	d[0] = 0;
	int max_c = 0, max_d = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		c[i+1] = c[i] + a[i];
		if (c[i+1] <= k)
			max_c = i+1;
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		d[i+1] = d[i] + b[i];
		if (d[i+1] <= k)
			max_d = i+1;
	}
	int max = 0;
	for (int i = 0; i <= max_c; i++) {
		for (int j = 0; j <= max_d; j++) {
			if (c[i]+d[j] <= k && max < i+j) {
				max = i+j;
			}
		}
	}
	cout << max << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m, ans=0;
    long long k;
    cin >> n >> m >> k;
    vector<long long>  a(n), b(m), sa(n+1), sb(m+1);
    sa[0]=0;
    sb[0]=0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        if(sa[i]>=1000000000) sa[i+1]=1000000001;
        else{
            sa[i+1]=sa[i]+a[i];
        }

    }
    for(int i=0; i<m; i++) {
        cin >> b[i];
        if(sb[i]>=1000000000) sb[i+1]=1000000001;
        else{
            sb[i+1]=sb[i]+b[i];
        }
    }

    for(int i=0; i<n+1; i++){
        int left=0, right=m+1;

        while(left<right){
            int mid=(left+right)/2;
            if(sa[i]+sb[mid]==k){
                ans=max(i+mid, ans);
                break;
            }
            else if(sa[i]+sb[mid]<k){
                ans=max(i+mid, ans);
                left=mid+1;
            }
            else{
                right=mid;
            }
        }
    }
    cout << ans;
}


#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

int main(void) {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll>a(n);
	vector<ll>b(m);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, m) {
		cin >> b[i];
	}
	ll ans = 0;
	ll t = 0;
	ll a_ = 0, b_ = 0;
    while (t < k) {
        if (a_ == n) {
            if (b_ == m)break;
            ++ans;
            t += b[b_];
            ++b_;
            continue;
        }
        if (b_ == m) {
            ++ans;
            t += a[a_];
            ++a_;
            continue;
        }
        if (a[a_] > b[b_]) {
            ++ans;
            t += b[b_];
            ++b_;
        }
        else {
            ++ans;
            t += a[a_];
            ++a_;
        }
    }
    if (t > k) {
        --ans;
    }
    cout << ans;
}

/*

*/


#include <bits/stdc++.h>
using namespace std;

int main(){
  int n, m;
  int64_t k;
  cin >> n >> m >> k;
  queue<int64_t> a;
  queue<int64_t> b;

  int i =0;
  while (i < n) {
    int64_t tmp;
    cin >> tmp;
    a.push(tmp);
    i++;
  }

  int j =0;
  while (j < m) {
    int64_t tmp;
    cin >> tmp;
    b.push(tmp);
    j++;
  }

  int64_t sum = 0;
  int count = 0;
  while (sum < k+1){
    if (a.front() <= b.front()){
      sum += a.front();
      count += 1;
      a.pop();
    }
    else {
      sum += b.front();
      count += 1;
      b.pop();
    }
    if (count == n+m) {
      count++;
      break;
    }
  }

  cout << count -1 << endl;

}


#include<iostream>
#include<vector>
using namespace std;
int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N);
    vector<int> B(M);
    int count = 0;
    int i = 0;
    int j = 0;
    for (int a = 0; a < N; a++) {
        cin >> A[a];
    }
    for (int b = 0; b < M; b++) {
        cin >> B[b];
    }
    while (K > 0) {
        if (i < N && j < M) {
            if (A[i] <= B[j]) {
                K -= A[i];
                i++;
                count++;
            }
            else {
                K -= B[j];
                j++;
                count++;
            }
        }
        else if (i == N && j < M) {
            K -= B[j];
            j++;
            count++;
        }
        else if (i < N && j == M) {
            K -= A[i];
            i++;
            count++;
        }
        else {
            break;
        }
    }
    cout << count << endl;
}


//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
using namespace std;
int solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> g;
	int a[n];
	int b[m];
	for(int i=0;i<n;i++)	cin>>a[i];
	for(int i=0;i<m;i++)	cin>>b[i];
	int i=0,j=0;
	int cnt=0;
	while(k>0){
		if(i<n && j<m && a[i]<b[j] && k>=a[i])
		{
			k-=a[i];
			i++;
			cnt++;
		}
		else if(i<n && j<m && a[i]>b[j] && k>=b[j])
		{
			k-=b[j];
			j++;
			cnt++;
		}
		else if(i<n && k>=a[i])
			k-=a[i], i++, cnt++;
		else if(j<m && k>=b[j])
			k-=b[j], j++, cnt++;
		else
			break;
	}
	cout<<cnt<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n + 1);
    vector<int> b(m + 1);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    a[n] = 1000000000000000000;
    b[m] = 1000000000000000000;
    int time = 0;
    int cnt = 0;
    int ai = 0;
    int bi = 0;
    while (time <= k) {
        if (a[ai] <= b[bi]) {
            time += a[ai];
            ai++;
            cnt++;
        }
        else if (bi != m) {
            time += b[bi];
            bi++;
            cnt++;
        }
        else {
            if (time <= k)
                cnt++;
            break;
        }
    }
    cnt--;
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,M,K;
  cin >> N >> M >> K;
  vector<int> A(N+M);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=N;i<N+M;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  long long time=0,count=0;
  for(int i=0;i<N+M;i++){
    time+=A.at(i);
    if(time<=K){
      count++;
    }
    else{
      break;
    }
  }
  cout << count << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,K,i,ans=0,a=0,b=0;
  cin>>N>>M>>K;ll A[N+1],B[M+1];
  A[0]=0;B[0]=0;
  REP(i,N){
    cin>>A[i+1];A[i+1]+=A[i];
  }
  REP(i,M){
    cin>>B[i+1];B[i+1]+=B[i];
  }
  REP(i,N+1){
    if(K<A[i])break;
    ans=max((long)ans,i+upper_bound(B,B+M+1,K-A[i])-B-1);
  }
  cout<<min(ans,M+N)<<endl;
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>

#define ll long long

using namespace std;

void solve() {
    int n, m, t;
    cin >> n >> m >> t;
    vector<ll> a(n), b(m);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i > 0) {
            a[i] += a[i - 1];
        }
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
        if(i > 0) {
            b[i] += b[i - 1];
        }
    }

    int res = upper_bound(b.begin(), b.end(), t) - b.begin();
    for(int i = 0; i < n; i++) {
        if(t < a[i]) {
            break;
        }
        if(b[0] > t - a[i]) {
            res = max(res, i + 1);
            continue;
        }
        // cout << t - a[i] << endl;
        int c = upper_bound(b.begin(), b.end(), t - a[i]) - b.begin();
        res = max(res, c + i + 1);
    }

    cout << res <<endl;
}

int main() {

    // int T;
    // cin >> T;
    // while(T--) {
        // solve();
    // }
    solve();

    return 0;
};


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    Factorial[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

//modの値の確認をすること
int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vl a(n + 2,0),b(m + 2,0);
    rep1(i, n){
        cin >> a[i];
        a[i] += a[i - 1];
    }
    rep1(i, m){
        cin >> b[i];
        b[i] += b[i - 1];
    }
    a[n + 1] = INF;
    b[m + 1] = INF;
    ll ans = 0;
    rep0(i, n)if(a[i] < k)chmax(ans, ll(i + (lower_bound(all(b), k - a[i]) - b.begin()) - 1));
    pf(ans);
    return 0;
}


#define _GLIBCXX_DEBUG

#include"bits/stdc++.h"
using namespace std;

//loops
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

template<typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n)
{
    auto first = v.cbegin() + m;
    auto last = v.cbegin() + n + 1;

    std::vector<T> vec(first, last);
    return vec;
}

//v need to be sorted
#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//comparision
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//pair
#define fir first
#define sec second
#define mp make_pair

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
#define intP pair<int, int>

//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()
#define gll get<ll>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)
#define gllm(n) getv<ll>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << std::fixed << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 1000000007;
const vec<string> alphabets = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }

////////////////////

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

string capitalize(string s){ // function prototype
    string newS = "";
    for (char c: s) {
        newS += toupper(c);
    }
    return newS;
}

void Main() {
    //code here

    int n = gi, m = gi, k = gi;
    vec<int> as = gim(n);
    vec<int> bs = gim(m);

    reverse(ALL(as));
    reverse(ALL(bs));

    int count = 0;
    while(true) {
         if(as.size() == 0 && bs.size() == 0) {
             break;
         } else if (as.size() == 0) {
             if (k - *bs.rbegin() >= 0) {
                 k -= *bs.rbegin();
                 bs.pop_back();
             } else {
                 break;
             }
         } else if (bs.size() == 0) {
             if (k - *as.rbegin() >= 0) {
                 k -= *as.rbegin();
                 as.pop_back();
             } else {
                 break;
             }
         } else if (*as.rbegin() < *bs.rbegin()) {
             if (k - *as.rbegin() >= 0) {
                 k -= *as.rbegin();
                 as.pop_back();
             } else {
                 break;
             }
        } else {
             if (k - *bs.rbegin() >= 0) {
                 k -= *bs.rbegin();
                 bs.pop_back();
             } else {
                 break;
             }
        }
         //print(as);
         //print(bs);
        count++;
    }

    print(count);

}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}


#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  ll k;
  cin >> k;
  vll a(n);
  rep(i, n) cin >> a[i];
  vll b(m);
  rep(i, m) cin >> b[i];
  ll i=0;
  ll j=0;
  ll count=0;
  ll time=0;
  while(true){
    if(i==n&&j==m)break;
    if((i!=n&&a[i]<=b[j])||j==m){
      count++;
      time+=a[i];
      i++;
      if(time>k){
        count--;break;
      }
    }else{
      count++;
      time+=b[j];
      j++;
      if(time>k){
        count--;break;
      }
    }
  }
  cout<<count<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  int n, m, k;
  cin >> n >> m >>k;
  vector <int> a(n);
  vector <int> b(m);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  int counter_a = 0, counter_b = 0;
  while (k > 0) {
    int d;
    if (counter_a < n || counter_b < m) {
      if (counter_a > n) {
        d = b[counter_b];
      } else if (counter_b > m) {
        d = a[counter_a];
      } else {
        d = min(a[counter_a], b[counter_b]);
      }
      if ((k - d) > 0 ) {
        if (a[counter_a] < b[counter_b]) {
          counter_a = counter_a + 1;
          // cout << "a read" << endl;
        } else {
          counter_b = counter_b + 1;
          // cout << "a read" << endl;
        }
        k = k - d;
        ans = ans + 1;
      } else {
        k  = 0;
      }
    } else {
      k = 0;
    }
  }
  cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	//input
	int64_t N, M, K;
	cin >> N >> M >> K;

	vector<int64_t> A(N), B(M);
	for (int64_t i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int64_t i = 0; i < M; i++) {
		cin >> B[i];
	}

	//calculation
	int64_t output = 0;
	int64_t sum = 0;
	int64_t n = 0;
	int64_t m = 0;
	for (int64_t i = 0; i < M + N; i++) {
		if (n == N) {
			sum += B[m];
			m++;
		} else if (m == M) {
			sum += A[n];
			n++;
		} else if (A[n] < B[m]) {
			sum += A[n];
			n++;
		} else {
			sum += B[m];
			m++;
		}

		if (sum > K) {
			break;
		}
		output++;
	}

	//output
	cout << output << endl;

	return 0;
}


/*Bismillahir Rahmanir Rahim
->>Code by Ashraful Islam Paran
->>CUET,CSE
*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef unsigned long long ull;
typedef vector<int> vi;
const int MX=2e5+5;
#define f(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,m ,k,l,s{0},c{0};
    cin>>n>>m>>k;
    vi v;
    f(i,0,n+m)
    {
        cin>>l;
        v.pb(l);
    }
    sort(v.begin(),v.end());

    f(i,0,n+m)
    {
        s+=v[i];

        if(s>k)
        {
            break;
        }
        c++;
    }
    //cout<<s<<endl;
    cout<<c<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> v, w;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }
  rep(i,M){
    ll a;
    cin >> a;
    w.push_back(a);
  }

  ll ret = 0;

  vector<ll> sum;
  sum.push_back(0);
  ll base = 0;
  rep(i,w.size()){
    base += w[i];
    if(base <= K) ret = max(ret, (ll)(i+1));
    sum.push_back(base);
  }

  base = 0;
  rep(i,v.size()){
    base += v[i];
    ll rem = K-base;
    if(rem < 0) continue;

    ll lb = 0, ub = sum.size();
    while(ub-lb>1){
      int m = (lb+ub)/2;
      if(sum[m] <= rem) lb = m;
      else ub = m;
    }

    ret = max(ret, i+1 + lb);
  }

  cout << ret << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mxN =150000;
int32_t main(){
  ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);

        int n,m,k; cin>>n>>m>>k;
        queue<int> a,b;
        for(int i=0;i<n;i++){
        	int x; cin>>x;
        	a.push(x);
		}
		for(int i=0;i<m;i++){
        	int x; cin>>x;
        	b.push(x);
		}
		int res=0;
		while(k)
		{
			 int y;
			 if(!a.empty())
			 y=a.front();
			 if(!b.empty())
			 y=min(y,b.front());

			 if(k<y)
			 break;
			 else
			 {
			 	 k-=y;
			 	 res++;
			 	 if(a.size() and y==a.front())
			 	 a.pop();
			 	 else if(b.size() and y==b.front())
			 	 b.pop();

			 }

		}
		 cout<<res<<endl;

 return 0;}


/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> prime_pow;
void sieveOfEratosthenes(ll N, ll s[]){
    vector <bool> prime(N+1, false);
    for (ll i=2; i<=N; i+=2)
        s[i] = 2;
    for (ll i=3; i<=N; i+=2) {
        if (prime[i] == false) {
            s[i] = i;
            for (ll j=i; j*i<=N; j+=2) {
                if (prime[i*j] == false) {
                    prime[i*j] = true;
                    s[i*j] = i;
                }
            }
        }
    }
}
void primefactor(ll N){
    ll s[N+1];
    sieveOfEratosthenes(N, s);
    ll curr = s[N], cnt = 1;
    while (N > 1){
        N /= s[N];
        if (curr == s[N]) {
            cnt++;
            continue;
        }
        prime_pow.push_back({curr,cnt});
        curr = s[N], cnt = 1;
    }
}

void virus(){
    ll a,b,k;
    cin>>a>>b>>k;
    vector<ll> arr(a+b);
    for(auto &i:arr) cin>>i;
    sort(arr.begin(),arr.end());
    vector<ll> pre(a+b);
    partial_sum(arr.begin(),arr.end(),pre.begin());
    cout<<lower_bound(pre.begin(),pre.end(),k) - pre.begin();
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}


/**
 *    Author  : Ador
 *    Created : 24.07.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
        //freopen("input.txt", "r", stdin) ;
        //freopen("output.txt", "w", stdout) ;
    ll n , i , sum = 0 ; cin >> n ;
    for(i = 1 ; i <= n ; ++i)
    {
        ll x = (n / i) ;
        sum += i * ((x * (x + 1)) / 2) ;
    }
    cout << sum << "\n" ;
    return 0 ;
}

Score : 400 points

Problem Statement

For a positive integer X, let f(X) be the number of positive divisors of X.

Given a positive integer N, find \sum_{K=1}^N K\times f(K).

Constraints

1 \leq N \leq 10^7

Input

Input is given from Standard Input in the following format:

N

Output

Print the value \sum_{K=1}^N K\times f(K).

Sample Input 1

4

Sample Output 1

23

We have f(1)=1, f(2)=2, f(3)=2, and f(4)=3, so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23.

Sample Input 2

100

Sample Output 2

26879

Sample Input 3

10000000

Sample Output 3

838627288460105

Watch out for overflows.


#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18

const int RT = 31644;

vector<int>prime;
vector<int>factor;
bitset<31666> status;

void sieve()
{
    int rt = 3164;
    for(int i = 4; i <= rt; i+=2) status[i]=true;
    for(int i = 3; i <= rt; i+=2)
        if(!status[i])
            for(int j = i*i; j < RT; j+=(i<<1))
                status[j] = true;

    prime.push_back(2);
    status[2]=false;

    for(int i = 3; i <= RT; i+=2)
        if(!status[i])
            prime.push_back(i);
}

lll primefac(int n)
{
    int pf_idx=0,pf=prime[pf_idx],SIZE=prime.size();
    lll ans=1,lol=0;
    while(pf*pf<=n&&pf<SIZE)
    {
        if(n%pf==0)
        {
            lol=0;
            while(n%pf==0) {n/=pf; lol++; }
            ans*=(lol+1);
            //cout<<ans<<endl;
        }
        pf=prime[++pf_idx];
    }
    if(n!=1) ans*=(1+1);
    return ans;
}
void solve()
{
   sieve();
   int n;
   cin>>n;
   lll num=1;
   for(int i=2;i<=n;i++)
   {
      num+=(primefac(i)*i);
   }
   cout<<num<<endl;
}

int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //int t; cin>>t; while(t--) solve();
    solve();

}


#include<bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll z=1000000000+7;
ll f[10000001]={0};
void nod(ll n)
{
  for(ll i=1;i<=n;i++)
  {
    f[i]=2;
  }
  f[1]=1;
  for(ll i=2;i<=n;i++)
  {
    for(ll j=2*i;j<=n;j+=i)
    {
      f[j]=f[j]+1;
    }
  }
}

int main()
{
  IOS;
  ll t=1;
  //cin>>t;
  while(t--)
  {
    ll i,n,k,sum=0,x,p=0,l,r,ans=0,cnt=0,m,j;
    cin>>n;
    nod(n);
    ans=0;
    for(i=1;i<=n;i++)
    {
      ans+=i*f[i];
    }
    cout<<ans;
  }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=1e7+1;
int f[N];
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j*i<=n;j++)
		{
			f[i*j]+=1;
		}
	}
	for(int i=1;i<=n;i++)
		sum+=f[i]*i;
	cout<<sum<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;

  ll ans = 0;
  rep3(i, 1, n + 1) {
    // ans に i の倍数が足される
    int l = n / i * i; // 末項
    int n_ = (l - i) / i + 1;
    // cerr << i << " " << l << " " << n_ << endl;
    ans += (i + l) * 1LL * n_ / 2; // 初項 i, 末項 l, 項数 n_ の等差数列の和
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...)
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int n;
  cin >> n;
  vector<ll> cnt(n+1);
  rep2(i, 1, n+1) {
    for (int j = i; j <= n; j += i) cnt[j]++;
  }
  ll ans = 0;
  rep2(i, 1, n+1) {
    ans += cnt[i] * i;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#include <unordered_set>
#include <unordered_map>

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
typedef set<LL> SLL;
typedef unordered_set<LL> USLL;
typedef string STR;

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;

std::pair<LL, LL> find_rest(LL n, LL dev) {
  LL degree = 0;
  while (n % dev == 0) {
    n /= dev;
    ++degree;
  }
  return {n, degree};
}

int main() {
  LL n;
  R(n);
  std::vector<LL> devs(n + 1, -1);
  devs[1] = 1;
  for (LL i = 2; i <= n; ++i) {
    if (devs[i] != -1) {
      continue;
    }

    for (LL j = i; j <= n; j += i) {
      devs[j] = i;
    }
  }

  std::vector<LL> f(n + 1);

  f[1] = 1;
  for (LL i = 2; i <= n; ++i) {
    if (devs[i] == i) {
      f[i] = 2;
    } else {
      auto [rest, degree] = find_rest(i, devs[i]);

      f[i] = f[rest] * (degree + 1);
    }
  }

  LL res = 0;

  for (LL i = 1; i <= n; ++i) {
    res += i * f[i];
  }

  W(res);

  return 0;
}


#include <iostream>

long long A[200001];

int main() {
    long long N;
    std::cin >> N;
    for (long long i=1; i<=N; i++) {
        std::cin >> A[i];
    }
    qsort(A+1, N, sizeof(long long), [](void const* a, void const* b) {
        return *(int*)a - *(int*)b;
        });

    long long count = 0;
    for (long long i=1; i<=N; i++) {
        if (A[i] < 0)
            continue;
        for (int j=i+1; j<=N; j++) {
            if (A[j] > 0 && A[j]%A[i] == 0)
                A[j] *= -1;
        }
        if (A[i] != -A[i+1]) {
            count++;
        }
    }
    std::cout << count << std::endl;
}

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define rept(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    FAST;
    ll n;
    cin>>n;
    ll a[n];
    ll ans=0;
    bool x=true;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
         rep(j,n){
            if(i!=j&&a[i]%a[j]==0){
                x=false;
                break;
            }
        }
        if(x){
            ans+=1;
        }
        x=true;
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

int main(){
    int n; cin>>n;
    vector<int> p;
    map<int,int> mp;
    rep(i,n){
        int a; cin>>a;
        mp[a]++;
    }
    for(auto& v: mp){
        if(v.second>=1) p.push_back(v.first);
    }
    sort(btoe(p));
    n=p.size();
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    vector<int> an(p[n-1]+5);
    rep(i,n){
        if(an[p[i]]<=1){
            for(int j=p[i]; j<=p[n-1]; j+=p[i]){
                an[j]++;
            }
        }
    }
    int ans=0;
    rep(i,n) if(an[p[i]]==1) ans++;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    vector <int> l(n);
    for (int i=0;i<n;i++) {
        scanf("%d",&l[i]);
    }
    sort(l.begin(),l.end());
    int count=0;
    int b=0;
    for (int i =0;i<n;i++){
        count++;
        for (int j=b;j<i;j++){
            if(l[i] % l[j]==0){
                swap(l[i],l[b]);
                b++;
                break;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}


#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	long long N;
	cin >> N;
	long long A[200000];

	long long i,j;
	long long C = 0;
	long long z=0;
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (i = 0; i < N; i++) {
		C = 0;
		for (j = 0; j < N; j++) {
			if (i != j) {
				if (A[i] % A[j] == 0)break;
				else C++;
			}
			if (C == N - 1)z++;
		}
	}
	cout << z << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e6 + 1;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int found[mxN];
int a[mxN];

int main() {
	fast();
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		found[a[i]]++;
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		bool success = true;
		if (found[a[i]] > 1) continue;
		if (a[i] > 1 && found[1] > 0) continue;
		for (int j = 2; j*j <= a[i]; ++j)
		{
			if (a[i] % j == 0) {
				if (found[j] || found[a[i]/j]) {
					success= false;
					break;
				}
			}
		}
		if (success) {
			++ans;
		}
	}
	cout << ans << nl;
}


/*
CODED BY
**************
DARSHAN JAIN
darshanjain31
**************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
int main()
{
	fast;
	ll n;
	cin>>n;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ll dp[1000005]={0};

	ll count=0;
	for (int i = 0; i < n; ++i)
	{
		//cout<<a[i]<<endl;
		if(dp[a[i]]==0)
		{
			count++;
			for (int j = a[i]; j < sqrt(1000002); j+=a[i])
			{
				dp[j]=1;
			}
		}
	}
	cout<<count<<endl;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n, a[200010];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        bool isCounted = true;
        for (int j = 0; j < n; ++j) {
            if (i == j) continue;
            else if (a[i] < a[j]) break;
            else if (a[i] % a[j] == 0) {
                isCounted = false;
                break;
            }
        }
        if (isCounted) ++ans;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int solve() {
    int n;
    map<int, int> M;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        M[a]++;
    }
    // cout << "M:  " << M << endl;
    int m = 1e6 + 1;
    int ans = 0;
    vector<int> B(m, 1);
    for (auto &p: M) {
        int a = p.first;
        if (B[a]) {
            if (p.second == 1)
                ans++;
            for (int i = a ; i < m; i += a) {
                B[i] = 0;
            }
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << solve() << endl;
    return 0;
}


#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n;
  vector<int> a;

  cin >> n;
  a.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> a[ii];
  }

  bool flg=true;
  int cnt=0;

  sort(a.begin(),a.end());
  int start;
  for(ii=0;ii<n;ii++){
    flg=true;
    if(ii != n-1){
      start = ii+1;
    }
    else{
      start = ii;
    }

    for(jj=start;jj>=0;jj--){
      //cout << "ii:" << ii << "jj:" << jj << endl;
      if(ii!=jj){
        if(a[ii] % a[jj] == 0){
          flg = false;
        }
      }
    }

    if(flg){
      //cout << a[ii] << endl;
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VB=vector<bool>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}

void Main()
{
	ll n,m,l; ll res=0;
	string s,t,u; string sres="No or NO";

	cin>>n;
	VI a(n),b(n);
	VI counter(2e6,0);
	rep(i, n){
		ll num=0;
		cin>>num;
		//for(ll i=2;i*i<=2e6;i++){
		//	while(num%i==0){
		//		n/=i;
		//	}
		//}
		if(counter[num]==0) {
			a[i]=num;
		}
		counter[num]++;
	}
	rep(i,n){
		bool divisile=false;
		rep(j,n){
			if(i==j) continue;
			if(a[i]%a[j]==0) {
				divisile = true;
				break;
			}
		}
		if(!divisile) res++;
	}

	cout << res << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >

int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
vector<bool>mark(1000010,0);
vll freq(1000010,0);
void solve(){
    int n;
    cin>>n;
    vll vec(n);
    rep(i,n){
        cin>>vec[i];
        mark[vec[i]]=1;
        freq[vec[i]]++;
    }
    ll ans=0;
    rep(i,n){
        ll val=vec[i];
        vll divs;
        ll lim=sqrt(val);
        rep1(j,1,lim){
            if(val%j==0){
                divs.pb(j);
                if(val/j!=j) divs.pb(val/j);
            }
        }
        bool ok=0;
        forch(it,divs){

            if(it==val and freq[it]>1){
                ok=1;
                break;

            }

            if(it!=val and mark[it]) {ok=1;break;}
            //cout<<it<<" "<<mark[it]<<endl;
        }
        if(!ok) ans++;
    }
    cout<<ans<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah