akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

int main()
{
	int N, M, P;
	while (scanf("%d %d %d", &N, &M, &P) != EOF) {
		if (N == 0 && M == 0 && P == 0)
			break;
		
		int sum = 0, m = 0, t;
		for (int i = 0; i < N; ++i) {
			scanf("%d", &t);
			sum += t;
			if (i == (M-1))
				m = t;
		}

		sum *= 100 * ((100 - P) / 100.0);
		if (m == 0)
			printf("0\n");
		else
			printf("%d\n", sum/m);
	}
	return 0;
}

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

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int X = in.nextInt();
            if (A > X || A + B < X) {
                out.println("NO");
            } else {
                out.println("YES");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

Measured memory_bytes: 21460
import java.util.*;
import java.io.*;
 
public class Main {
 
  public static void main(String[] args)throws IOException {
	  BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	  String S = br.readLine();
	  int temp = 0;
	  int counter = 0;
	  for(int i =0; i<S.length(); i++) {
		  if(S.charAt(i) == 'A' || S.charAt(i) == 'C' || S.charAt(i) == 'G' || S.charAt(i) == 'T' ) {
			  counter++;
		  } else {
			 temp = Math.max(temp, counter++);
			 counter = 0;
		  }
	  }
	  temp = Math.max(temp, counter);
	  System.out.println(temp);
  }
}

Measured memory_bytes: 32336
package main

import (
	"fmt"
//	"sort"
	"math"
//	"regexp"
)

var X,t, ans int
func main(){
	fmt.Scan(&X,&t)
	fmt.Println(max(X-t,0))
}

func max(x,y int) int{
	return int(math.Max(float64(x),float64(y)))
}

Measured memory_bytes: 512
// A. 

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int n, a;
	cin >> n >> a;
	bool ans = a >= (n % 500);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	lint r, g, b, n;
	cin >> r >> g >> b >> n;
	lint ans = 0;
	REP(i, 3030) REP(j, 3030) {
		lint rem = n - (r * i + g * j);
		if(rem >= 0 && rem % b == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */


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

using namespace std;
#define _overload3(_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(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll MOD = 1e9+7;

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

  int N;
  cin >> N;
  int K;
  cin >> K;

  ll ans = 0;
  vector<ll> cnt(K+1);

  for(ll i = K; i >= 1; i--){

    ll m = K/i;
    ll cnt_;

    cnt_ = modpow(m, N, MOD);

    ll sub_cnt_ = 0;
    for(ll j = 2; j * i <= K; j++){
      sub_cnt_ = (sub_cnt_ + cnt[j*i]) % MOD;
    }

    cnt[i] = (cnt_ + MOD - sub_cnt_) % MOD;
    
    ans = (ans + (i * cnt[i]) % MOD) % MOD;

  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3988
n, m = map(int, input().split())
num_list = [list(map(int, input().strip().split())) for i in range(m)]

out = -1
for j in range(0 if n == 1 else 10**(n - 1), 10**n):
    flg = 1
    s_list = [int(s) for s in list(str(j))]
    for k in num_list:
        if s_list[k[0] - 1] != k[1]:
            flg = 0
    if flg == 1:
        out = j
        break

print(out)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int A1 = stdIn.nextInt();
		int A2 = stdIn.nextInt();
		int A3 = stdIn.nextInt();
		int sum = 0;
		sum = A1 + A2 + A3;
		if(sum > 21){
			System.out.println("bust");
		}
		else{
			System.out.println("win");
		}
		stdIn.close();
	}
}


Measured memory_bytes: 35708
n,t = map(int, input().split())
list_ct = []
c_min = 10000000
for i in range(n):
    list_ct.append(list(map(int, input().split())))
for i in range(n):
    if list_ct[i][1] <= t:
        if c_min > list_ct[i][0]:
            c_min = list_ct[i][0]

if c_min == 10000000:
    print("TLE")
else:
    print(c_min)


Measured memory_bytes: 3060
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

bb = inputs[0][0]
pd bb
# body
if $debugFlag
end

if bb == "A"
  ret = "T"
elsif bb == "T"
  ret = "A"
elsif bb == "G"
  ret = "C"
else
  ret = "G"
end

puts ret


Measured memory_bytes: 1788
import bisect

A, B, Q = map(int, input().split())
s = [-float('inf')] + [int(input()) for _ in range(A)] + [float('inf')]
t = [-float('inf')] + [int(input()) for _ in range(B)] + [float('inf')]
X = [int(input()) for _ in range(Q)]

for x in X:
    sp = bisect.bisect_left(s, x)
    tp = bisect.bisect_left(t, x) 
    res = float('inf')
    for S in [s[sp-1], s[sp]]:
        for T in [t[tp-1], t[tp]]:
            d1, d2 = abs(S-x) + abs(T-S), abs(T-x)+abs(S-T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 16188
#include <stdio.h>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stdlib.h>

#include <vector>
#include <list>
#include <string>

using namespace std;


int main() {
  string S;
  long long K;

  cin >> S;
  scanf("%lld", &K);

  int ans = 1;
  int count = 0;

  for(char c: S){
    int digit = c - '0';
    if(digit == 1){
      count++;
    }else{
      break;
    }
  }

  if(K <= count){
    ans = 1;
    printf("%d\n", ans);
    return 0;
  }

  for(char c: S){
    int digit = c - '0';
    if(digit != 1){
      ans = digit;
      break;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[count];
        int[] values = new int[count];
        for (int i = 0; i < count; i++) {
            arr[i] = sc.nextInt();
            values[i] = Integer.MAX_VALUE;
        }
        values[0] = 0;

        for (int i = 1; i < count; i++) {
            for (int j = 0; j < Math.min(k, i); j++) {
                values[i] = Math.min(values[i], values[i - 1 - j] + Math.abs(arr[i] - arr[i - 1 - j]));
            }
        }
        System.out.println(values[count - 1]);
    }
}

Measured memory_bytes: 61220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,k;
    cin >>n >>k;
    vector<int> v(n);
    rep(i,n) cin >>v[i];

    int ans = 0;
    rep(i,n+1)for(int j=i; j<=n; ++j){
        int rem = k;
        vector<int> h;
        rep(x,i){
            h.pb(v[x]);
            --rem;
        }
        for(int x=j; x<n; ++x){
            h.pb(v[x]);
            --rem;
        }

        if(rem<0) continue;
        sort(all(h));

        int H = h.size();
        int idx = 0;
        while(idx<H && h[idx]<0 && rem>0){
            ++idx;
            --rem;
        }

        int s = 0;
        for(int x=idx; x<H; ++x) s += h[x];
        ans = max(ans, s);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
S = list(ST())
Q = I()
bits=[[0]*(N+1) for _ in range(26)]

def ctoi(c): #アルファベットを0-25の数字に変換
    return ord(c)-97

def query(pos): #各文字について1-pos番目までの文字数をカウント
    ret = [0]*26
    for i in range(26):
        tmp = 0
        p = pos
        while p>0:
            tmp += bits[i][p]
            bit_len = p&(-p) #p&(-p)は1のたつ最小桁であり、今の区間の長さをあらわす
            p -= bit_len #つぎに足すべき塊の番号は、今の値から区間の長さを引くとでる
        ret[i] = tmp #アルファベットiの1-posまでの出現回数
    return ret

def update(pos, a, x): #a番目のアルファベットについてpos番目の要素の値を更新
    while pos <= N:
        bits[a][pos] += x
        pos += pos&(-pos)

for i in range(N):
    update(i+1, ctoi(S[i]),1)
for _ in range(Q):
    q = LST()
    if q[0]=='1':
        i = int(q[1])
        c = q[2]
        if S[i-1]==c:
            continue
        update(i, ctoi(S[i-1]), -1) #S[i-1]のi番目に1が立っているが、これを下ろして削除を表現
        #O(logN)で削除が完了
        update(i, ctoi(c), 1)
        S[i-1] = c
    else:
        ans = 0
        l = int(q[1])
        r = int(q[2])
        r_sum = query(r)
        l_sum = query(l-1)
        for i in range(26):
            if r_sum[i]-l_sum[i] > 0:
                ans += 1
        print(ans)


Measured memory_bytes: 172668
T = int(input())

import heapq

def calc(camels):
	camels.sort()
	camels.reverse()
	count = len(camels)
	
	score = 0
	queue = []
	i = 0
	for k in range(count, 0, -1):
		while i < count and camels[i][0] >= k:
			K, L, R = camels[i]
			heapq.heappush(queue, (-(L - R), L, R))
			i += 1
		if len(queue) > 0:
			D, L, R = heapq.heappop(queue)
			score += L
	while len(queue) > 0:
		D, L, R = heapq.heappop(queue)
		score += R
	while i < count:
		K, L, R = camels[i]
		score += R
		i += 1
	return score

for t in range(T):
	N = int(input())
	
	camels_l = []
	camels_r = []
	
	count_r = 0
	for _ in range(N):
		K, L, R = map(int, input().split())
		if L - R >= 0:
			camels_l.append((K, L, R))
		else:
			camels_r.append((N - K, R, L))
	
	print(calc(camels_l) + calc(camels_r))


Measured memory_bytes: 49304
import itertools
n=int(input())
l=sorted([int(i) for i in input().split()])
ans=0

for i in range(n-2):
    A=list(itertools.combinations(l[:i+2],2))
    for a in A:
        if a[0]!=a[1]!=l[i+2] and sum(a)>l[i+2] :
            
            ans+=1
print(ans)

Measured memory_bytes: 69648
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n) cin >> w[i];
    int Min = INF;

    REP(t, 1, n) {
        int s1 = accumulate(w.begin(), w.begin() + t, 0);
        int s2 = accumulate(w.begin() + t, w.end(), 0);
        Min = min(Min, abs(s1 - s2));
    }
    cout << Min << endl;
    return 0;
}



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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

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

#define MAX_N 1010

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

int N;
int T[MAX_N],A[MAX_N];

int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N) cin >> T[i] >> A[i];
    ll now_T = 0, now_A = 0;
    REP(i,N) {
        if (now_T==0&&now_A==0) {
            now_T = T[i];
            now_A = A[i];
        }
        else {
            //ll Tbai = 0, Abai = 0;
            ll Tbai = now_T%T[i]==0 ? now_T/T[i] : now_T/T[i]+1;
            ll Abai = now_A%A[i]==0 ? now_A/A[i] : now_A/A[i]+1;
            if (Tbai > Abai) {
                now_T = Tbai * T[i];
                now_A = Tbai * A[i];
            }
            else {
                now_T = Abai * T[i];
                now_A = Abai * A[i];
            }
        }
        
    }
    
    cout << now_T + now_A << endl;
    
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
N,M=list(map(int,input().split()))
root = defaultdict(list)

for _ in range(M):
    A,B=list(map(int,input().split()))    
    root[A].append(B)
    root[B].append(A)

visited = [-1]*(N+1)
queue = deque([1])
visited[1] = 0
while queue:
    x = queue.popleft()
    for nex in root[x]:
        if visited[nex] == -1:
            visited[nex] = x
            queue.append(nex)

for i in range(2,N+1):
    if visited[i]==-1:
        print('No')
        exit()
print('Yes')
for i in range(2,N+1):
    print(visited[i])

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[222222];
bool f[222222];

bool C(int x){
    deque<pint>d;
    rep(i,N)f[i]=A[i]>=x;

    int l=N/2,r=N/2;
    while(l>0&&f[l-1]!=f[l])l--;
    while(r+1<N&&f[r+1]!=f[r])r++;
    if(l==0&&r==N-1){
        int tmp=f[N/2]+N/2;
        return tmp&1;
    }
    if(N/2-l<=r-N/2)return f[l];
    return f[r];
}

signed main(){
    cin>>N;
    N=N*2-1;
    rep(i,N)cin>>A[i];



    int lb=1,ub=N;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))lb=mid;
        else ub=mid;
    }
    cout<<lb<<endl;

    return 0;
}



Measured memory_bytes: 2048
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var c = cin.ReadInt;
            var ans = 0;
            if((a - b) <= c)
            {
                ans = c - (a - b);
            }
            
            System.Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11220
import java.io.IOException;
import java.lang.System;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);

        while (s.hasNext()) {
            int a[] = new int[4];
            for (int i = 0; i < 4; i++) {
                a[i] = s.nextInt();
            }

            int b[] = new int[4];
            for (int i = 0; i < 4; i++) {
                b[i] = s.nextInt();
            }

            int hit = 0;
            int blow = 0;
            for(int i = 0; i < 4; i++){
                for(int j = 0; j < 4; j++){
                    if(a[i] == b[j] && i == j) {
                        hit++;
                    }
                    else if(a[i] == b[j]) {
                        blow++;
                    }
                }
            }

            System.out.println(hit + " " + blow);
        }
    }
}

Measured memory_bytes: 18084
#include <stdio.h>

int main()
{
	int n, i, j, temp, minj, count;
	int a[1000];

	count = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);

	for (i = 0; i < n; i++)
	{
		minj = i;
		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[minj])
				minj = j;
		}

		if (minj != i)
			count++;

		temp = a[i];
		a[i] = a[minj];
		a[minj] = temp;
	}

	for (i = 0; i < n; i++)
	{
		printf("%d", a[i]);
		if (i != n - 1)
			putchar(' ');
	}
	putchar('\n');

	printf("%d\n", count);

	return 0;
}



Measured memory_bytes: 2140
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(input())
A = [int(input()) for i in range(N-1)]

wins = [[] for _ in range(N)]
for i,a in enumerate(A,start=1):
    wins[a-1].append(i)

def depth(v):
    if len(wins[v])==0: return 0
    ds = []
    for to in wins[v]:
        ds.append(depth(to))
    ds.sort(reverse=True)
    ret = 0
    for i,d in enumerate(ds):
        ret = max(ret, i+d)
    return ret+1

print(depth(0))

Measured memory_bytes: 121496
n,m,q=list(map(int,input().split()))
abcd=[]
for _ in range(q):
    abcd.append(list(map(int,input().split())))

max_score=0

num=[0]*n
while True:
    score=0
    for lis in abcd:
        if num[lis[1]-1]-num[lis[0]-1]==lis[2]:
            score+=lis[3]
    if score>=max_score:
        max_score=score
    num[-1]+=1
    #繰り上がる場合を考える
    if num[-1]==m:
        check=-1
        for j in range(n-1):
            if num[j]!=m-1:
                check=j
        if check==-1:
            break
        else:
            num[check]+=1
            for k in range(check+1,n):
                num[k]=num[check]
print(max_score)




Measured memory_bytes: 9160
import java.util.*;

public class Main{
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int K = scan.nextInt();
    int []p = new int[N];
    for(int i=0;i<N;i++) {
        p[i] = scan.nextInt();
    }
    scan.close();

    Arrays.sort(p);

    int sum = 0;
    for(int i=0;i<K;i++) {
        sum += p[i];
    }

    System.out.println(sum);
}
}


Measured memory_bytes: 38944
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		int sum = 0;
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			sum += A[i];
		}

		int ans = 1;
		for (int i = sum; i >= 2; --i) {
			if (sum % i != 0)
				continue;
			int[] B = new int[N];
			for (int j = 0; j < N; ++j)
				B[j] = A[j] % i;
			Arrays.sort(B);
			int s = 0;
			while (s < B.length && B[s] == 0)
				++s;
			if (s == B.length) {
				ans = Math.max(ans, i);
				break;
			}
			int t = B.length - 1;
			int cnt = 0;
			while (s < t && cnt <= K) {
				int sub = Math.min(i - B[t], B[s]);
				B[t] += sub;
				B[s] -= sub;
				cnt += sub;
				while (B[t] >= i)
					B[t] -= i;
				while (B[s] >= i)
					B[s] -= i;
				if (B[t] == 0)
					--t;
				if (B[s] == 0)
					++s;
			}
			if (cnt <= K) {
				ans = Math.max(ans, i);
				break;
			}
		}
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(ans);
		pw.close();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 26028
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


//const int mod=1000000007;
const int mod=998244353;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,l,r;
    cin >> n >> k;
    vll v(n);
    vll dp(n,1e18);
    dp[n-1]=0;
    for(int i=0; i<n; i++)
        cin >> v[i];
    for(int i=n-2; i>=0; i--){
        for(int j=1; j<=k; j++){
            if(i+j<n)
                dp[i]=min(dp[i],dp[i+j]+abs(v[i]-v[i+j]));
        }
    }
    cout << dp[0] << el;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define ALL(a) begin(a), end(a)
const int N = 2e5 + 87;
int a[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vector<int> ans;
    for (int i = n; i >= 1; --i) {
        int s = 0;
        for (int j = i * 2; j <= n; j += i)
            s ^= a[j];
        a[i] ^= s;
        if (a[i])
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); ++i)
        cout << ans[i] << " \n"[i + 1 == ans.size()];
}


Measured memory_bytes: 2424
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;

int order[4000];
map<int, ll> sums;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		int optr = 0;
		sums.clear();
		while(n--){
			int a;
			ll b, c;
			cin >> a >> b >> c;
			map<int, ll>::iterator it = sums.find(a);
			if(it == sums.end()){
				order[optr++] = a;
				sums.insert(pair<int, ll>(a, b * c));
			}else{
				(*it).second += b * c;
			}
		}
		bool isNA = true;
		for(int i = 0; i < optr; ++i){
			if(sums[order[i]] >= 1000000){
				cout << order[i] << endl;
				isNA = false;
			}
		}
		if(isNA){ cout << "NA" << endl; }
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int a;
    char s[11];

    cin >> a >> s;

    cout << (a >= 3200 ? s : "red") << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

long long int memo[250][250];

long long int gcd(long long int a, long long int b) {

	if (memo[a][b] > 0) { return memo[a][b]; }
	if (b == 0) { return a; }
	
	return memo[a][b]=gcd(b, a%b);
}

long long int GCD(long long int a, long long int b, long long int c) {
	
	return gcd(gcd(a, b), c);

}

long long int K;

int main(void) {
	cin >> K;
	long long int ans = 0;

	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			for (int c = 1; c <= K; c++) {
				ans += GCD(a, b, c);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4028
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	int h, w, k;
	cin >> h >> w >> k;

	vector<string> v(h);
	for (auto& i : v) {
		cin >> i;
	}

	int ht = 0;
	int wt = 0;
	int lh = 1 << h;
	int lw = 1 << w;

	int ret = 0;
	vector<string> vt;
	for (int i = 0; i < lh; ++i) {
		for (int j = 0; j < lw; ++j) {

			vt = v;

			int it = i;
			int ci = 0;
			while (it != 0) {
				if (it & 1) {
					for (int j2 = 0; j2 < w; ++j2) {
						vt[ci][j2] = '_';
					}
				}
				it >>= 1;
				++ci;
			}


			int jt = j;
			int cj = 0;
			while (jt != 0) {
				if (jt & 1) {
					for (int i2 = 0; i2 < h; ++i2) {
						vt[i2][cj] = '_';
					}
				}
				jt >>= 1;
				++cj;
			}

			int count = 0;
			for (int i2 = 0; i2 < h; ++i2) {
				for (int j2 = 0; j2 < w; ++j2) {
					if (vt[i2][j2] == '#') {
						++count;
					}
				}
			}

			if (count == k) {
				++ret;
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
using namespace std;
const int mod = 1e9 + 7;

class Matrix
{
  public:
  Matrix(vector<vector<int> >& vec) {
     vec_ = vec;
     n = vec.size();
  }

  Matrix(int n)
  {
    vec_.resize(n);
    this->n = n;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
          vec_[i].push_back(0);
  }

  int& operator()(int x, int y)
  {
    return vec_[x][y];
  }
  friend Matrix operator*(Matrix& a, Matrix& b)
  {
    Matrix res(a.size());
    // square matrix
    int n = a.size();
    for (int i = 0; i < a.size(); ++i)
    {
      for (int j = 0; j < b.size(); ++j)
      {
        long long int c = 0;
        for(int k = 0; k < n; ++k) {
           c += (long long) a(i,k) * b(k,j);
           c %= mod;
           res(i,j) = c;
        }
      }
    }
    return res;
  }

  friend Matrix operator^(Matrix& a, long long int n)
  {
    int x = a.size();
    Matrix ret(x);
    for (int i = 0; i < x; ++i)
      ret(i,i) = 1;
    while(n)
    {
      if (n & 1)
        ret = ret * a;
      a = a * a;
      n /= 2;
    }
    return ret;
  }



  int size() { return n;}

  private:
  vector<vector<int> > vec_;
  int n;

};




int main()
{
  int n;
  long long  k;
  cin >> n >> k;
  vector<vector<int>> a(n,vector<int>(n));
  for (int i = 0; i < n; ++i)
   for(int j = 0; j < n; ++j)
    cin >> a[i][j];
  Matrix mat(a);

  mat = mat ^ (k);
  int ret = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n ; ++j)
      ret = (ret + mat(i, j)) % mod;
  cout << ret << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  int k = in();
  vector<int> ans;
  rep(i,bit(n)){
    if(__builtin_popcount(i)==k)ans.emplace_back(i);
  }
  foreach(i,ans){
    cout << i << ":";
    rep(j,n){
      if(bit(j)&i){
        cout << " " << j;
      }
    }
    cout << endl;
  }
}



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

#define ll long long
#define UN unsigned
#define pb push_back
#define mod 1000000007
#define mt make_tuple
typedef tuple<int, int> tii;
typedef pair<int, int> pii;

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

    vector<int> a(n);
    for(auto& x: a)
        cin >> x;
    
    int dp[100005];
    fill(dp, dp+n+1, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(a[0]-a[1]);
    for(int i = 2; i < n; i++){
        int h = k;
        for(int j=i-1; j >= 0 && h > 0; h--, j--){
            dp[i] = min(dp[j]+abs(a[i]-a[j]), dp[i]);
        }
    }

    cout << dp[n-1];
}

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, unsigned long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

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

  ll h,w,k;
  std::cin>>h>>w>>k;

  ll sx,sy,gx,gy;
  std::cin>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;

  std::vector<std::string> grid(h);
  rep(i,0,h)std::cin>>grid[i];

  constexpr ll INF=1e10;

  std::vector<std::vector<ll>> d(h,std::vector<ll>(w,INF));
  std::vector<std::vector<std::bitset<4>>> used(h,std::vector<std::bitset<4>>(w));

  using P=std::pair<ll,ll>;

  std::queue<P> que;

  d[sx][sy]=0;
  que.emplace(sx,sy);

  while(!que.empty()){
    auto [nx,ny]=que.front();
    que.pop();
    rep(i,0,4){
      ll tx=nx,ty=ny;
      rep(j,0,k){
        tx+=dx[i];
        ty+=dy[i];
        if(tx<0||tx>=h||ty<0||ty>=w)break;
        if(grid[tx][ty]=='@')break;
        if(d[tx][ty]<d[nx][ny]+1)break;
        if(used[tx][ty][i])break;
        used[tx][ty][i]=true;
        d[tx][ty]=d[nx][ny]+1;
        que.emplace(tx,ty);
      }
    }
  }

  if(d[gx][gy]==INF)std::cout<<-1<<"\n";
  else std::cout<<d[gx][gy]<<"\n";

  return 0;
}

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

using namespace std;

int main()
{
    int n, H;
    int sum = 0;
    cin >> H >> n;
    while (n--)
    {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum >= H) cout << "Yes";
    else cout << "No";
    return 0;
}


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

int main(void){
  int n, q;
  cin >> n >> q;

  int v, w;
  for(int i = 0; i < q; i++){
    cin >> v >> w;
    --v;
    --w;  

    if(n == 1){
      if(v > w)
        v = w;
    }
    else{
      while(v != w){
        if(v > w){
          --v;
          v /= n;
        }
        else{
          --w;
          w /= n;
        }
      }
    }
    
    cout << (v + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define N 1000005
typedef long long int ll;
// int n,m;
// vector<int> adj[mx];

//---dfs--
// bool visited[mx];
// vector<int> val(n,0);

// void dfs(int s, int & cnt_vert, int & cnt_edge){
// 	assert(!visited[s]);
// 	visited[s]=true;
// 	++cnt_vert;
// 	cnt_edge+=adj[s].size();
// 	for(int b:adj[s]){
// 		if(!visited[b]){
// 			dfs(b,cnt_vert,cnt_edge);
// 		}
// 	}
// }
//---dfs---

//---primes---
// vector<bool> prime(N,true);
// int spf[N];

// void calc(){
// 	for(int i=2;i<1e4;i++){
// 		if(!prime[i]) continue;
// 		spf[i]=i;
// 		for(int j=i*i;j<N;j+=i){
// 			prime[j]=false;
// 			spf[j]=i;
// 		}
// 	}
// 	for(int i=2;i<N;i++){
// 		if(!spf[i]) spf[i]=i;
// 	}
// }

// vector<pair<int,int>> getp(int x){
// 	int curr=x;
// 	vector<pair<int,int>> ans;
// 	while(curr>1){
// 		int a=spf[curr];
// 		int count=0;
// 		while(curr%a==0){ curr/=a; count++;}
// 		ans.push_back(make_pair(a,count));
// 	}
// 	return ans;
// }

// bool ispr(int n) {
//     for (int i=2;i*i<=n;++i){
//         if(n%i==0){
//             return false;
//         }
//     }
//     return true;
// }
//---primes---

//---segment_tree---
// int upd(int t,int val,int l,int r,int y, int z){
// 	if(y<l||y>r) return tr[val];
// 	if(l==r) return tr[val]=z;
// 	int s=(l+r)/2;
// 	upd(t^1,2*val+1,l,s,y,z);
// 	upd(t^1,2*val+2,s+1,r,y,z);
// 	if(t) tr[val]=tr[2*val+1]|tr[2*val+2];
// 	else tr[val]=tr[2*val+1]^tr[2*val+2];
// 	return tr[val];
// }
//int query(){}
//---segment_tree---

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int t=1;
	//cin>>t;
	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		int a[n+1],b[m+1];
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=m;i++){
			cin>>b[i];
		}
		vector<ll> prefa(n+1),prefb(m+1);
		prefa[0]=0;
		prefb[0]=0;
		for(int i=1;i<=n;i++){
			prefa[i]=prefa[i-1]+a[i];
		}
		for(int i=1;i<=m;i++){
			prefb[i]=prefb[i-1]+b[i];
		}
		int ans=0;
		int j=m;
		for(int x=0;x<=n;x++){
			if(prefa[x]>k) break;
			while(prefb[j]>k-prefa[x]) j-=1;
			ans=max(ans,x+j); 
		}
		cout<<ans<<"\n";
	}
}


Measured memory_bytes: 7908
require 'prime'

def common_divisors(n)
  return [1] if n == 1

  tmp = n.prime_division.map do |e|
    (0..e[1]).to_a.map do |i|
      e[0]**i
    end
  end
    
  tmp.reduce{|p,q| p.product(q)}.map do |a|
    [a].flatten.reduce(&:*)
  end.sort
end

n = gets.to_i

div1 = common_divisors(n)
div2 = div1.reverse

ans = Float::INFINITY
div1.size.times do |i|
  digits1 = div1[i].to_s.length
  digits2 = div2[i].to_s.length
  f = [digits1, digits2].max
  ans = [ans, f].min
end

puts ans


Measured memory_bytes: 2684
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 998244353


def main():
    N, K, *LR = map(int, read().split())
    interval = [(l, r) for l, r in zip(*[iter(LR)] * 2)]

    dp = [0] * (N + 1)
    dp[1] = 1
    dp[2] = -1

    for i in range(1, N + 1):
        dp[i] = (dp[i] + dp[i - 1]) % MOD
        for l, r in interval:
            if i + l <= N:
                dp[i + l] += dp[i]
                if i + r + 1 <= N:
                    dp[i + r + 1] -= dp[i]

    print(dp[N])
    return


if __name__ == '__main__':
    main()


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

#define ubuntu ios_base::sync_with_stdio, cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()

const long long MXN = 3e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef long double ldub;
typedef unsigned long long ullong;

using namespace std;

set <int> s;
llong n , a[MXN];

int main(){
    ubuntu;
    ///freopen("in.in", "r", stdin);
    ///freopen("out.out", "w", stdout);
    cin >> n;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
        s.insert(a[i]);
    }cout << s.size();
    return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())

abc = [a,b,c]
abc.sort()

if abc[0] == abc[1] and abc[1] != abc[2]:
    print('Yes')
    exit()

if abc[1] == abc[2] and abc[0] != abc[1]:
    print('Yes')
    exit()


print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(n,i) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;


int main()
{
   FAST/**/
   
   ll n,a,b;
   cin>>n>>a>>b;
   ll ans = LLONG_MAX;
   if(b%2 == a%2)
   {
       cout<<(b-a)/2;
       return 0;
   }
   
   ll d1 = n-b;
   ll a1 = a+d1;
   ll b1 = n;
   
   ll ans1 = min(n-a,b-1);
   if(n%2 == a1%2)
       ans1 = min(d1 + (b1-a1)/2,ans1);
   else ans1 = min(ans1, d1 + (b1-a1-1)/2 + 1);
   
   d1 = a-1;
   a1 = 1;
   b1 = b-d1;
   
   if(1 == b1%2)
        ans1 = min(ans1, d1 + (b1-a1)/2);
   else ans1 = min(ans1, d1 + (b1-1-a1)/2 + 1);
   
   cout<<ans1;
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int m,f,r;
    for(;scanf("%d %d %d",&m,&f,&r);){
        if(m==-1&&f==-1&&r==-1)break;
        else if(m==-1||f==-1||m+f<30)
        printf("F\n");
        else if(m+f>=80)
        printf("A\n");
        else if(m+f>=65&&m+f<80)
        printf("B\n");
        else if(m+f>=50&&m+f<65)
        printf("C\n");
        else if(m+f>=30&&m+f<50&&r>=50)
        printf("C\n");
        else if(m+f>=30&&m+f<50)
        printf("D\n");
        }
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define N 111116
 
int n,q;
vector<long long> a;
long long t[N],ans[N];
 
long long read(){
	long long x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();q=read();a.push_back(n);
	for (int i=1;i<=q;i++){
		long long x=read();
		while (a.size()&&a.back()>=x) a.pop_back();
		a.push_back(x);
	}
	q=a.size();t[q-1]=1;
	for (int i=q-1;i>=0;i--){
		long long x=a[i],y=i-1;
		while (y>=0){
			t[y]+=x/a[y]*t[i];x%=a[y];
			for (int k=1<<16;k;k/=2)
				if (y-k+1>=0&&a[y-k+1]>=x) y-=k;
		}
		ans[1]+=t[i];ans[x+1]-=t[i];
	}
	for (int i=1;i<=n;i++)
		printf("%lld\n",ans[i]+=ans[i-1]);
	return 0;
}

Measured memory_bytes: 4212
#include <iostream>
#include <queue>
using namespace std;
static const int N = 1000;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	for (int i = 0; i < n; ++i) d[i] = INFTY;
	d[s] = 0;
	int u;
	while (!q.empty()) {
		u = q.front(); q.pop();
		for (int v = 0; v < n; ++v) {
			if (!M[u][v]) continue;
			if (d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
	}
}

int main() {
	int u, k, v;

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

	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; ++j) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	bfs(0);
}


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

int main(){
	#ifndef ONLINE_JUDGE
	    freopen("in.txt" , "r" , stdin);
	    freopen("out.txt" , "w" , stdout);
	#endif
	    ll t , u;
	    cin>>t>>u;
	    ll mul = t*u;
	    cout<<mul<<'\n';
	    

	}


Measured memory_bytes: 3636
S = input()

S = list(S)

for i in range(len(S)):	
	if not (S[i] == 'A' or S[i] == 'T' or S[i] == 'C' or S[i] == 'G'):
		S[i] = ","
		
S = ("".join(S)).split(",")
print(max([len(s) for s in S]))

Measured memory_bytes: 3064