akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u)
{
    rep(v, nt[u], n)
    {
        nt[u] = v + 1;
        if (M[u][v])
        {
            return v;
        }
    }
    return -1;
}

void dfs_visit(int r)
{
    rep(i, 0, n)
    {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while (!S.empty())
    {
        int u = S.top();
        int v = next(u);
        if (v != -1)
        {
            if (color[v] == WHITE)
            {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs()
{
    rep(i, 0, n)
    {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    rep(u, 0, n)
    {
        if (color[u] == WHITE)
        {
            dfs_visit(u);
        }
    }

    rep(i, 0, n)
    {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main()
{
    int u, k, v;
    cin >> n;

    rep(i, 0, n)
    {
        rep(j, 0, n)
        {
            M[i][j] = 0;
        }
    }

    rep(i, 0, n)
    {
        cin >> u >> k;
        u--;
        rep(j, 0, k)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
}


Measured memory_bytes: 3196
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] D = new int[N + 1];
            D[0] = 0;
            for (int i = 0; i < N; i++) {
                D[i + 1] = sc.nextInt();
            }

            Arrays.sort(D);

            int minmax = (int) 1e9;
            int[] isClockWise = new int[N + 1];
            for (int i = 1; i < N + 1; i++) {
                int max = 0;
                int maxK = -1;
                for (int k = 0; k < 2; k++) {
                    int di = k == 0 ? D[i] : (24 - D[i]);
                    int min = (int) 1e9;
                    for (int j = 0; j < i; j++) {
                        int dj = isClockWise[j] == 0 ? D[j] : (24 - D[j]);
                        int diff = Math.abs(di - dj);
                        diff = Math.min(diff, 24 - diff);
                        min = Math.min(min, diff);
                    }
                    if (min > max) {
                        max = min;
                        maxK = k;
                    }
                }
                isClockWise[i] = maxK;
                minmax = Math.min(minmax, max);
            }
            System.out.println(minmax);
        }
    }
}


Measured memory_bytes: 24020
#include <iostream>
using namespace std;

const int N = 100;
char result[N][N];
bool visited[N][N] = {0};

int dy[] = {0,  0, 1, -1};
int dx[] = {1, -1, 0, 0};

void dfs(int n, int y, int x){
  if (visited[y][x])return;
  visited[y][x] = true;
  for(int i = 0;i < 4;i++){
    int ney = y + dy[i], nex = x + dx[i];
    if (0 <= ney && ney < n && 0 <= nex && nex < n &&
	result[ney][nex] == result[y][x]){
      dfs(n, ney, nex);
    }
  }
}

bool check(int n, const int w, const int b){
  int w_cnt = 0, b_cnt = 0;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if (!visited[i][j]){
	if (result[i][j] == '#')b_cnt++;
	if (result[i][j] == '.')w_cnt++;
	dfs(n, i, j);
      }
    }
  }
  return w == w_cnt && b == b_cnt;
}

void solve(const int w_cnt, const int b_cnt){
  const int n = 100;
  for(int i = 0;i < n/2;i++){
    for(int j = 0;j < n;j++){
      result[i][j] = '#';
    }
  }
  for(int i = n/2;i < n;i++){
    for(int j = 0;j < n;j++){
      result[i][j] = '.';
    }
  }


  {
    int w_tmp = w_cnt-1;
    int nowy = 0;
    int nowx = 0;
    while(w_tmp){
      result[nowy][nowx] = '.';
      nowx += 2;
      if (nowx == n){
	nowy += 2;
	nowx = 0;
      }
      w_tmp--;
    }
  }
  {
    int b_tmp = b_cnt-1;
    int nowy = n/2+1;
    int nowx = 0;
    while(b_tmp){
      result[nowy][nowx] = '#';
      nowx += 2;
      if (nowx == n){
	nowy += 2;
	nowx = 0;
      }
      b_tmp--;
    }
  }

  /*
  bool isok = check(n, w_cnt, b_cnt);
  cout << isok << endl;
  */

  cout << n <<" " << n << endl;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      cout << result[i][j];
    }
    cout << endl;
  }
}


int main(){
  int w, b;
  cin >> w >> b;
  solve(w, b);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
    
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        
        int minv = Integer.parseInt(scanner.nextLine());
        int maxv = Integer.MIN_VALUE;
        for(int j = 0; j < n-1; j++){
            int r = Integer.parseInt(scanner.nextLine());
            if(maxv <= r - minv){
                maxv = r -minv;
            }
            if(minv > r){
                minv = r;
            }
        }
        
        System.out.println(maxv);
    }
}



Measured memory_bytes: 169076
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

#define mod 1000000007
#define ll long long

int MIN(int n, int m){
    if(n <= m)return n;
    else return m;
}

int main(){

    ll int N,M;
    cin >> N >> M;

    if(N*2 >= M){
        cout << M / 2 << endl;
        return 0;
    }

    else{
        M -= 2*N;
        cout << N + M / 4 << endl;
        return 0;    
    }

}


Measured memory_bytes: 256
#include <stdio.h>

long max(long a, long b) {
  if (a >= b) {
    return a;
  } else {
    return b;
  }
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long dp0[n/2][2],dp1[n/2][2];
  dp0[0][0] = 0;
  dp0[0][1] = a[0];
  dp1[0][0] = -10000000000;
  dp1[0][1] = a[1];
  for (long i = 1; i < n/2; i++) {
    dp0[i][0] = dp0[i-1][0]+a[i*2];
    dp0[i][0] = max(dp0[i][0],max(dp0[i-1][1],dp1[i-1][1]));
    dp0[i][1] = dp0[i-1][1]+a[i*2];
    dp1[i][0] = max(dp0[i-1][0],dp1[i-1][0])+a[i*2+1];
    dp1[i][1] = max(dp0[i-1][1],dp1[i-1][1])+a[i*2+1];
  }
  long ans;
  if (n%2 == 0) {
    ans = max(dp0[n/2-1][1],dp1[n/2-1][1]);
  } else {
    ans = dp0[n/2-1][0]+a[n-1];
    ans = max(ans,max(dp0[n/2-1][1],dp1[n/2-1][1]));
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 6372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#define MOD_P 1000000007
#define ll long long
using namespace std;


int main()
{
	int x, y;
	cin >> x >> y;

	printf("%s", x > y ? "safe" : "unsafe");

	return 0;
}

Measured memory_bytes: 3684
n, k = map(int, input().split())
trees = [0 for _ in range(n)]
for i in range(n):
    trees[i] = int(input())
trees = sorted(trees)

ans_list = []
for index, tree in enumerate(trees):
    if  k-1 <= index:
        ans_list.append(tree-trees[index-(k-1)])
print(min(ans_list))


Measured memory_bytes: 51616
#include<stdio.h>
 
int main() {
    long long  h, w;
    scanf("%lld %lld", &h, &w);

    if (h == 1 || w == 1) {
        puts("1");
        return 0;
    }
 
    printf("%lld\n", (h * w + 1) / 2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  unordered_map<int, int> a;
  rep(i, n) a[i] = 0;
  rep(i, q){
    int idx;
    cin >> idx;
    ++a[idx-1];
  }
  
  vector<int> score(n);
  rep(i, n) {
    score[i] = k - q + a[i];
    if ( score[i] > 0 ) puts("Yes");
    else puts("No");
  }
  return 0;
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
int dx[] = {1, 0, -1, 0}; // {down , right , up , left}
int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
//int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

int n;
vector<int> adj[100];
string col = "RGB";

char getCur(char frst , char sec){
  for (int i = 0; i < 3; ++i)
    if(frst != col[i] && sec != col[i])
      return col[i];
  return 'R';
}

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  string s;
  cin >> n;
  cin >> s;
  int len = SZ(s);
  for (int i = 0; i < len; ++i)
    adj[s[i]].push_back(i);

  ll cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j){
      if(s[i] == s[j])
        continue;
      char curChar = getCur(s[i], s[j]);
      int sz = SZ(adj[curChar]);
      int idx = lower_bound(adj[curChar].begin(), adj[curChar].end(), j + (j - i)) - adj[curChar].begin();
      cnt += (sz - (lower_bound(adj[curChar].begin(), adj[curChar].end(), j + 1) - adj[curChar].begin()));
      if(idx < sz && adj[curChar][idx] == j + (j - i))
        cnt--;
    }
  }
  cout << cnt << "\n";

  return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2010;
int N, M;
int S[MAXN], T[MAXN];

const int MOD = 1e9 + 7;
int tr[MAXN];

void add(int k, int a) {
	for (k++; k <= M; k += (k & -k)) {
		tr[k] += a;
		if (tr[k] >= MOD) tr[k] -= MOD;
	}
}

int sum(int k) { // exclusive
	int res = 0;
	for (; k; k -= (k & -k)) {
		res += tr[k];
		if (res >= MOD) res -= MOD;
	}
	return res;
}

int main() {
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) scanf("%d", &S[i]);
	for (int i = 0; i < M; i++) scanf("%d", &T[i]);

	int ans = 1;
	for (int i = 0; i < N; i++) {
		for (int j = M - 1; j >= 0; j--) {
			if (S[i] != T[j]) continue;
			int num = sum(j) + 1;
			ans += num;
			if (ans >= MOD) ans -= MOD;
			add(j, num);
		}
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N,K;
	scanf("%d\n%d", &N,&K);
	int start = 1;
	for(int i=0; i<N; i++){
		int A= start*2;
		int B= start+K;
		start = A>B?B:A;
	}
	printf("%d\n",start);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

vector<int> E[1000005];
int indegree[1000005];
bool finish[1000];

int main() {
    int n; cin >> n;
    int a[n][n-1];
    rep(i,n) rep(j,n-1) {
        cin >> a[i][j];
        a[i][j]--;
    }
    int v1,v2;
    rep(i,n) {
        rep(j,n-2) {
            if (i < a[i][j]) v1 = i*1000+a[i][j];
            else v1 = a[i][j]*1000+i;
            if (i < a[i][j+1]) v2 = i*1000+a[i][j+1];
            else v2 = a[i][j+1]*1000+i;
            E[v1].push_back(v2);
            indegree[v2]++;
        }
    }
    vector<int> topo;
    queue<int> que;
    rep(i,n) {
        for (int j = i+1; j < n; j++) {
            if (indegree[1000*i+j] == 0) {
                que.push(1000*i+j);
            }
        }
    }

    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for(int nx : E[v]) {
            indegree[nx]--;
            if (indegree[nx] == 0) que.push(nx);
        }
        topo.push_back(v);
    }
    if (topo.size() != n*(n-1)/2) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 1;
    rep(i,n) finish[i] = true;
    for (int battle : topo) {
        int one = battle / 1000;
        int two = battle % 1000;
        if (finish[one] && finish[two]) {
            finish[one] = false;
            finish[two] = false;
        } else {
            rep(i,n) finish[i] = true;
            ans++;
            finish[one] = false;
            finish[two] = false;
        }
    }

    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 52136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;

int main(){
    int n,m;
    cin >> n >> m;
    Graph G(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(n,-1);
    queue<int> que;
    
    dist[0] = 0;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(int nv:G[v]){
            if(dist[nv] != -1) continue;

            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    if(dist[n-1] == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 13168
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int h, n;
  cin >> h >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i ++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  for (int i = 0; i < n; i ++)
  {
    h -= a.at(i);
    if (h <= 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

const int MOD = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  set<int> S;
  REP(i, M) {
    int x;
    cin >> x;
    S.insert(x);
  }
  // dp[i] := i段目にたどりつく移動方法
  vector<int> dp(N + 1, 0);
  dp[0] = 1;
  if(S.count(1) && S.count(2)) {
    cout << 0 << endl;
    return 0;
  } else if(S.count(1)) {
    dp[1] = 0;
  } else {
    dp[1] = 1;
  }
  REP(i, N - 1) {
    if(S.count(i + 2)) {
      dp[i + 2] = 0;
    } else {
      dp[i + 2] = (dp[i + 1] + dp[i]) % MOD;
    }
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>

using namespace std;

int n,m,q;
const int MAXN = 5e2 + 4;
long long a[MAXN],b[MAXN],d[MAXN],c[MAXN];
vector<long long> sub;
bool vis[MAXN];
long long ans = 0;
void solve(int i)
{
    if(i >= n)
        {
        
            long long tmp = 0;
            for(int j = 0 ; j < q;  j++)
             {
                 if((sub[b[j] - 1] - sub[a[j] - 1]) == c[j])
                      tmp+=d[j];
             }
             ans = max(ans , tmp);
             return;
        }
        long long j = 1;
        if(!sub.empty())
             j = sub.back();
        
        for(j ; j <= m ; j++)
        {
            sub.push_back(j);
            solve(i + 1);
            vis[j] = 0;
            sub.pop_back();
        }
        return;
}


int main()
{
    cin >> n >> m >> q;
    for(int i = 0 ; i < q ; i++)
      cin >> a[i] >> b[i] >> c[i] >> d[i];

    solve(0);
    cout << ans ;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int N = 52;
const int B = N * N;
int n, k, dp[N][N][2 * N * N + 5];
void upd(int &x, const int &y) {
	(x += y) >= mo ? x -= mo : 0;
}
int main() {
	scanf("%d%d", &n, &k);
	dp[0][0][B] = 1;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j <= i; j ++) {
			for(int k = - n * n; k <= n * n; k ++) if(dp[i][j][B + k]) {
				upd(dp[i + 1][j][B + k], (2 * j + 1ll) * dp[i][j][B + k] % mo);
				upd(dp[i + 1][j - 1][B + k + 2 * (i + 1)], 1ll * j * j * dp[i][j][B + k] % mo);
				upd(dp[i + 1][j + 1][B + k - 2 * (i + 1)], dp[i][j][B + k]);
			}
		}
	}
	printf("%d\n", dp[n][0][B + k]);
	return 0;
}

Measured memory_bytes: 53760
def examC():
    N, M = LI()
    A = [I() for _ in range(M)]
    A.append(N+1)
    fib = [1]*(N+2)
    for i in range(1,N):
        fib[i+2] = fib[i+1] + fib[i]
    fib[0] = 0
#    print(fib)
    ans = fib[A[0]]%mod
    for i in range(M):
        ans *= fib[A[i+1]-A[i]-1]
        ans %=mod
    print(ans)
    return

def examD():
    H, W = LI()
    S = [SI() for _ in range(H)]
    width = [[0]*W for _ in range(H)]
    height = [[0]*W for _ in range(H)]
    for i in range(H):
        cur = 0; keep = []
        for j in range(W):
            if S[i][j]==".":
                cur +=1
                keep.append(j)
            else:
                for k in keep:
                    width[i][k] = cur
                cur = 0; keep = []
        if keep:
            for k in keep:
                width[i][k] = cur
    for j in range(W):
        cur = 0; keep = []
        for i in range(H):
            if S[i][j]==".":
                cur +=1
                keep.append(i)
            else:
                for k in keep:
                    height[k][j] = cur
                cur = 0; keep = []
        if keep:
            for k in keep:
                height[k][j] = cur
    ans = 0
    for i in range(H):
        for j in range(W):
            cur = width[i][j] + height[i][j]
            if ans<cur:
                ans = cur
    print(ans-1)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()


Measured memory_bytes: 120540
import sys
import bisect

MAX = 1299710
prime = [-1] * MAX
prime_list = []
i = 2
while MAX > i:
	if prime[i - 1] == -1:
		prime[i - 1] = 0
		temp = i * 2
		prime_list.append(i)
		while temp < MAX:
			prime[temp - 1] = 1
			temp += i
	if i == 2:
		i += 1
	else:
		i += 2

while True:
    n = int(sys.stdin.readline())
    
    if n == 0:
        break
    
    start = bisect.bisect_left(prime_list, n)
    end = bisect.bisect_right(prime_list, n)
    if prime_list[start] == n:
        print 0
    else:
        print prime_list[end] - prime_list[start - 1]

Measured memory_bytes: 17636
#include <bits/stdc++.h>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin >>h[i];
  }
  int height =0;
  int ans=0;
  for(int i=0;i<n;i++){
    if(height<=h[i]){
      ans++;
      height=h[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    bool ok = true;
    rep(i, N) if(A[i] % 2 == 1) ok = false;
    if(ok) output("second");
    else output("first");
    
    
    
    return 0;
}


Measured memory_bytes: 640
import itertools

n,m,x=map(int,input().split())
book=[]

for i in range(n):
  ca=list(map(int,input().split()))
  book.append(ca)


ans=1000000000
for bit in itertools.product([0,1],repeat=n):
  b=[0]*m
  cost=0
  for i in range(n):
    if bit[i]:
      cost+=book[i][0]
      for j in range(1,m+1):
        b[j-1]+=book[i][j]
  k=1
  for i in range(m):
    if b[i]<x:
      k=0
      break
  if k:
    ans=min(ans,cost)
    
if ans==1000000000:
  print(-1)
else:
  print(ans)
  

Measured memory_bytes: 9228
import sys
input=sys.stdin.readline

N,A,B=map(int,input().split())
P=list(map(int,input().split()))

data=[0]*(N+1)
flag=[0]*(N+1)
for i in range(N):
    p=P[i]
    flag[p]=1
    cnt=0
    for j in range(p+1,N+1):
        if flag[j]==0:
            data[j]=data[j-1]
        else:
            cnt+=1
            data[j]=min(cnt*A+data[p-1],data[j]+B)

print(data[-1])

Measured memory_bytes: 43900
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        static final char A = 'A';
        static final char C = 'C';

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), q = in.nextInt();

            char[] s = (in.next()).toCharArray();

            int[] count = new int[n];
            for (int i = 0; i < n; i++) {
                count[i] = i > 0 ? count[i - 1] : 0;
                if (i > 0 && s[i - 1] == A && s[i] == C) {
                    count[i]++;
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1, r = in.nextInt() - 1;

                int answer = count[r] - count[l];

                out.println(answer);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 39464
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
int dig(int x) {
    int cnt = 0;
    while(x) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int main() {fio; // remove during scanf
    int N;
    cin >> N;
    int ans = 128912;
    for(int a = 1; a < N; a++) {
        ans = min(dig(a) + dig(N - a), ans);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
M = []
q = []
for i in range(h):
    line = input().strip()
    M.append(list(line))
    for j in range(w):
        if line[j] == "#":
            M[i][j] = 0
            q.append((j, i))

dir = [[1, 0], [-1, 0], [0, 1], [0, -1]]
cnt = 0
while q:
    next_q = []
    cnt += 1
    for x, y in q:
        for dx,dy in dir:
            next_x, next_y = x + dx, y + dy
            if 0 <= next_y <= h - 1 and 0 <= next_x <= w - 1:
                if M[next_y][next_x] == ".":
                    M[next_y][next_x] = M[y][x] + 1
                    q.append((next_x, next_y))
    q = next_q

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, M[i][j])
print(ans)


Measured memory_bytes: 170712
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      mut a: i64,
      mut b: i64,
    }
    if a < b {
        std::mem::swap(&mut a, &mut b);
    }

    if (a+b)%2 == 1 {
        puts!("{}\n", "IMPOSSIBLE");
    } else {
        let k = (a+b)/2;
        puts!("{}\n", k);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
typedef pair<ii, ii> pii;
const int MAX = 5e5+5;
vector<int> tree[4*MAX];
int a[MAX];

void build(int no, int i, int j) {
	if(i == j) { tree[no].pb(a[i]); return; }
	build(no*2, i, (i+j)/2); build(no*2+1, (i+j)/2+1, j);
	merge(all(tree[no*2]), all(tree[no*2+1]), back_inserter(tree[no]));
}

int query(int no, int i, int j, int l, int r) {
	if(i > r || j < l) return 0;
	if(i >= l && j <= r) return (lower_bound(all(tree[no]), l)-tree[no].begin());
	return query(no*2, i, (i+j)/2, l, r) + query(no*2+1, (i+j)/2+1, j, l, r);
}

int main(int argc, char** argv) {
	map<int, int> mp;
	int N, Q, l, r, x;
	scanf("%d%d", &N, &Q);
	REP(i, 1, N) {
		scanf("%d", &x);
		a[i] = mp[x];
		mp[x] = i;
	}
	build(1, 1, N);
	rep(q, 0, Q) {
		scanf("%d%d", &l, &r);
		printf("%d\n", query(1, 1, N, l, r));
	}
	return 0;
}


Measured memory_bytes: 140940
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
int rd(int s, int e) { return rand()%(e-s+1) + s; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }

const int MAXN = 2005;

int B[MAXN][MAXN];
int A[MAXN*2];

ll Ans = INFLL;
int N, X;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> X;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		A[i+N] = A[i];
	}
	for(int i = 1; i <= N; i++) {
		B[i][1] = A[i];
		for(int j = 2; j <= N; j++)
			B[i][j] = min(B[i][j-1], A[i+N+1-j]);
	}

	for(int t = 1; t <= N; t++) {
		ll ret = 0;
		for(int i = 1; i <= N; i++)
			ret += B[i][t];
		ret += ll(X) * (t-1);
		upmin(Ans, ret);
	}

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 16000
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    
    ll ans = a[0];
    
    for (int i = 2; i < n; i++) {
        ans += a[i/2];
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 4776
n = int(input())
t_1 ,x_1 ,y_1 = 0,0,0
f = 1

for i in range(n):
    t_2 ,x_2 ,y_2 = map(int,input().split())
    x = ((t_2 - t_1) - abs(x_1 - x_2) - abs(y_1 - y_2))
    if  x % 2 == 0 and x >= 0:
        t_1 ,x_1 ,y_1 = t_2 ,x_2 ,y_2
    else:
        f = 0
        print("No")
        break
if f:
    print("Yes")

Measured memory_bytes: 3064
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

ll floor_sum(ll n,ll m,ll a,ll b){
  ll ans=0;
  ans+=(n-1)*n*(a/m)/2+n*(b/m);
  a%=m;
  b%=m;

  ll y=(a*n+b)/m;
  if(y==0) return ans;
  ll x=(m*y-b+a-1)/a;
  ans+=(n-x)*y+floor_sum(y,a,m,a*x-m*y+b);
  return ans;
}

int main(){
  int t;
  cin>>t;
  
  rep(i,t){
    int n,m,a,b;
    cin>>n>>m>>a>>b;
  
    cout<<floor_sum(n,m,a,b)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;

long long gcd(long long a, long long b) {
  long long d;
  while (b > 0) {
    d = a % b;
    a = b;
    b = d;
  }
  return a;
}

int main() {
  long long a, b, c, ans;
  cin >> a >> b;
  if (a > b){
    c = gcd(a, b);}
  else{
    c = gcd(b, a);}
  ans = a * b / c;
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
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;}



signed main(){
	string s;
	cin >> s;
	int flg = 1;
	vector<int>dp(1<<26,333333);
	dp[0] = 0;
	int now = 0;
	REP(i,s.size()){
		now ^= 1 << (s[i] - 'a');
		REP(j,26){
			CHMIN(dp[now],dp[now^(1<<j)]+1);
		}
	}
	if(now)cout << dp[now] << endl;
	else cout << 1 << endl;
}

Measured memory_bytes: 262788
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B;
    }else if (A>5)
    {
        cout << B/2;
    }else{
        cout << 0;
    }
    
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;

void solve(int N, vector<int> A)
{
    sort(A.begin(), A.end());

    int res = 0;
    vector<bool> checked((int)1e6 + 1);
    for (int i = 0; i < N; i++)
    {
        if (checked.at(A.at(i)))
            continue;
        if (i + 1 == N || A.at(i) != A.at(i + 1))
            res++;
        for (int x = A.at(i); x <= 1e6; x += A.at(i))
            checked.at(x) = true;
    }
    cout << res << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0 ; i < N ; i++){
        cin >> A.at(i);
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0;i < n; i++)
using namespace std;

int main() {
    int k;
    int pt = 0;
    long double n, prob = 1, possivility = 0;
    cin >> n >> k;
    rep(i,n){
        pt = i+1;
        if(pt >= k){
            possivility += (double)(1/n);
            continue;
        }
        while(1){
            pt *= 2;
            prob *= 2;
            if(pt >= k){
                possivility += (double)((1 / (prob * n)));
                prob = 1;
                break;
            }
        }
    }
    cout << setprecision(10) << possivility << endl;
}


Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJCGL_1B().doIt();
	}

	class AOJCGL_1B{
		void doIt(){
			Point2D p0 = new Point2D.Double(in.nextDouble(), in.nextDouble());
			Point2D p1 = new Point2D.Double(in.nextDouble(), in.nextDouble());
			int q = in.nextInt();
			for(int i=0;i<q;i++){
				Point2D p2 = new Point2D.Double(in.nextDouble(),in.nextDouble());
				Point2D result = getVerticalPoint(p0,p1,p2);
				double dx = result.getX()-p2.getX();
				double dy = result.getY()-p2.getY();
//				System.out.println(dx+" "+dy);
//				System.out.println(result.getX()+" "+result.getY());
				double tx = dx+result.getX();
				double ty = dy+result.getY();
				System.out.printf("%.9f %.9f\n",tx,ty);
			}
		}
		
		//p0-p1の直線があるときに直線p2から直線らしたときp0-p1上の垂直な点を求める。
		private Point2D getVerticalPoint(Point2D p0,Point2D p1,Point2D p2){
			double kyori = p0.distance(p1);
			double angle = angle(p0, p1, p2);
			double t = p0.distance(p2) * Math.cos(angle);
			Point2D result = new Point2D.Double(p0.getX()+(p1.getX()-p0.getX())*t/kyori,
					p0.getY()+(p1.getY()-p0.getY())*t/kyori);
			return result;
		}

		private double angle(Point2D p0, Point2D p1, Point2D p2){
			return Math.atan2(p2.getY()-p0.getY(),p2.getX()-p0.getX())-
					Math.atan2(p1.getY()-p0.getY(),p1.getX()-p0.getX());
		}

	}
}

Measured memory_bytes: 39456
#pragma warning(disable:4996)
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAX 1010

char str[MAX];

int main()
{
	scanf("%s", str);
	for (int i = 0; str[i] != '\0'; i++)
	{
		if (str[i + 1] == '\0')
		{
			if (str[i] == 's')
				strcat(str, "es");
			else
				strcat(str, "s");
			break;
		}
	}
	printf("%s", str);
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;

#define int long long
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; }

string dfs(int n, int cnt){
	if(cnt == 0) return "";

	string tmp;
	tmp.push_back('a'+n%26);
	return dfs(n/26, cnt-1)+tmp;
}

signed main(){
	int n;
	cin >> n;
	n--;

	int l = 0;
	int r = 26;
	int cnt = 1;
	while(1){
		if(l <= n && n < r){
			cout << dfs(n-l, cnt) << endl;
			return 0;
		}
		cnt++;
		n-=r;
		r *= 26;
	}

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> vec(n);
  ll sum = 0;
  rep(i,n){
    cin >> vec[i];
    sum += vec[i];
  }
  ll ans = 0;
  rep(i,n){
    if(vec[i] * 4 * m >= sum){
      ans++;
    }
  }
  if(ans >= m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
S=input()

N=len(S)
RLs=[]
Rs=[]
Ls=[]

rlen=0
llen=0
for i in range(N):

    if S[i]=='R':
        rlen+=1
        if S[i:i+2] == 'RL':
            RLs.append(i)
            Rs.append(rlen)
            rlen=0
    elif S[i]=='L':
        llen+=1
        if i==N-1 or S[i:i+2] == 'LR':
            Ls.append(llen)
            llen=0

ans = [0]*N
for i,rlpos in enumerate(RLs):
    rr=-(-Rs[i]//2)
    rl=Rs[i]//2

    lr=Ls[i]//2
    ll=-(-Ls[i]//2)

    ans[rlpos]+=rr+lr
    ans[rlpos+1]+=rl+ll

for a in ans:
    print(str(a)+' ',end='')
print()

Measured memory_bytes: 7704
isPrime :: Int -> Bool
isPrime num = null(filter (\x -> num `mod` x == 0) [2..floor(sqrt(fromIntegral num))])

findFirstPrime :: Int -> Int
findFirstPrime num = head(filter isPrime [num..])

main = do
    x <- readLn :: IO Int
    let ans = findFirstPrime x
    putStrLn $ show ans


Measured memory_bytes: 508
/**
*    author:  yuya1234
*    created: 30.06.2020 10:57:25
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    int n,m,k;
    cin>>n>>m>>k;

    ll a[200001],b[200001];
    ll aMax=1,bMax=1,tmp,sum=0;
    a[0]=b[0]=0;
    FOR(i,1,n)
    {
        cin>>tmp;
        sum+=tmp;
        a[i]=sum;
        if(sum<=k)
        {
            aMax=i+1;
        }
    }
    
    sum=0;
    FOR(i,1,m)
    {
        cin>>tmp;
        sum+=tmp;
        b[i]=sum;
        if(sum<=k)
        {
            bMax=i+1;
        }
    }

    ll ans=0;

    REP(i,aMax)
    {
        REPD(j,bMax)
        {
            if(k>=a[i]+b[j])
            {
                ans=max(ans,i+j);
                bMax=j+1;
                break;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6772
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n;x>=1;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001
ll dp[N][3],a[N][3];

ll fun(ll n,ll i)
{
	// cout<<n<<" "<<i<<endl;
	if(n==0)
		return dp[n][i];
	if(dp[n][i]!=-1)
		return dp[n][i];
	dp[n][0]=max((dp[n-1][1]!=-1?dp[n-1][1]:fun(n-1,1))+a[n][0],
				 (dp[n-1][2]!=-1?dp[n-1][2]:fun(n-1,2))+a[n][0]);
	dp[n][1]=max((dp[n-1][0]!=-1?dp[n-1][0]:fun(n-1,0))+a[n][1],
				 (dp[n-1][2]!=-1?dp[n-1][2]:fun(n-1,2))+a[n][1]);
	dp[n][2]=max((dp[n-1][1]!=-1?dp[n-1][1]:fun(n-1,1))+a[n][2],
				 (dp[n-1][0]!=-1?dp[n-1][0]:fun(n-1,0))+a[n][2]);
	return dp[n][i];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n,i,j;
    cin>>n;
	ifr(i,n)
		ifr(j,3) cin>>a[i][j],dp[i][j]=-1;
	dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
	fun(n-1,2);
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<cmath>
using namespace std;

int main(){
	int n, y;
	while(1){
		cin >> n;
		if(n == 0) break;
		cin >> y;
		double max = -1.0;
		int maxIdx;
		for(int i = 0;i < n;i++){
			int b, t, r;
			cin >> b >> r >> t;
			double sum;
			if(t == 1){
				sum = 1.0 + y * r / 100.0;
			}
			else{
				sum = pow(1.0 + r / 100.0, y);
			}
			if(sum > max){
				max = sum;
				maxIdx = b;
			}
		}
		cout << maxIdx << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

typedef struct{
    int u;
    int k;
    int a[100];
}rist;
int main(){
    int i,j,n,x=0;
    rist A[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&A[i].u,&A[i].k);
        for(j=0;j<A[i].k;j++){
            scanf("%d",&A[i].a[j]);
        }
    }
    
    for(i=0;i<n;i++){
        for(j=1;j<=n;j++){
            if(j==n){
                if(A[i].a[x]!=j) printf("0");
                else {
                    printf("1");
                    x++;
                }
            }
            else{
                if(A[i].a[x]!=j) printf("0 ");
                else {
                    printf("1 ");
                    x++;
                }
            }
        }
        x=0;
        printf("\n");
    }
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll x;
int main(){
	cin >> x;

	ll y = x / 11;

	ll z = 0;

	if(x % 11 == 0) {
		;
	}else if(x % 11 <= 6) {
		z++;
	}else {
		z += 2;
	}

	cout << y * 2 + z << endl;;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll x,y; cin >> x >> y;
    cout << x + y / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);
//or-> ||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

int N;
string ans;
string S;
signed main(){
	IO_STREAM;
	cin>>N>>S;

	int cnt=0;
	rep(i,0,N){
		if(S[i]==')'){
			cnt++;
		}
		else{
			if(cnt<=0) cnt--;
			else break;
		}
	}
	rep(i,0,cnt){
		S='('+S;
		N++;
	}
	
	cnt=0;
	for(int i=N-1;i>=0;i--){
		if(S[i]=='('){
			cnt++;
		}
		else{
			if(cnt<=0) cnt--;
			else break;
		}
	}
	rep(i,0,cnt){
		S=S+')';
		N++;
	}

	DBG("S",S,N,"");
	int L=0,R=0;
	rep(i,0,N){
		if(S[i]=='(')	L++;
		else			R++;
	}
	if(R>L){
		rep(i,0,(R-L)){
			ans.pb('(');
		}
		ans=ans+S;
	}
	else if(L>R){
		ans=S;
		rep(i,0,(L-R)){
			ans.pb(')');
		}
	}
	else{
		ans=S;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] strs = Console.ReadLine().Split(' ');
        int n = int.Parse(strs[0]);
        int d = int.Parse(strs[1]);

        string[][] x = new string[n][];
        for (int i = 0; i < n; i++)
        {
             x[i] = Console.ReadLine().Split(' ');
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                int sum = 0;
                for (int k = 0; k < d; k++)
                {
                    int tmp = int.Parse(x[i][k]) - int.Parse(x[j][k]);
                    sum += tmp * tmp;
                }
                double sqrt = Math.Sqrt(sum);
                if (isInt(sqrt)) count++;
            }
        }

        Console.Write(count);
    }

    static bool isInt(double val)
    {
        return val - Math.Floor(val) == 0;
    }
}


Measured memory_bytes: 11220