akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
using namespace std;

int a[100005];

int main(){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    sort(a, a+n);
    // all same
    int valid = 1;
    for(int i=1; i<n; i++) if(a[i] != a[i-1]) valid = 0;
    if(valid){
        if(n-1 == a[0] || n/2 >= a[0]) printf("Yes");
        else printf("No");
        return 0;
    }
    // not same
    if(a[n-1] != a[0]+1){ printf("No"); return 0; }
    int cnt = 0;
    for(int i=0; i<n; i++) if(a[i] == a[0]) cnt++;
    if(a[0]-cnt+1 <= 0) printf("No");
    else if(2*(a[0]-cnt+1) <= n-cnt) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (true) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			if (N == 0) break;
			int min = N;
			for (int i = 0; i < M; ++i) {
				min = Math.min(min, sc.nextInt());
			}
			System.out.printf("%.5f\n", min == 1 ? 0.0 : N / 2.0);
		}
	}

}

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

int main() {

    string s;

    cin >> s;

    if(s.size() == 2){
        if(s[0] == s[1]){
            cout << "1 2" << endl;
        }
        else {
            cout << "-1 -1" << endl;
        }
        return 0;
    }

    for(int i=0; i<s.size()-1; i++){
        if(s[i] == s[i+1]){
            if(i!=0){
                cout << i+1-1 << " " << i+1+1 << endl;
                return 0;
            }
            else{//(i+1 < s.size())
                cout << i+1 << " " << i+2+1 << endl;
                return 0;
            }
        }
        else if(i+2 < s.size() && s[i] == s[i+2]){
            cout << i+1 << " " << i+2+1 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;

    return 0;
}

Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	x = readline() |> split |> parseMap
	z = maximum(x)
	np = zeros(Int,m)
	p = zeros(Int,m)
	ct = zeros(Int,z)
	for i in 1:n
		if ct[x[i]]==1
			np[x[i]%m+1]-=1
			p[x[i]%m+1]+=2
			ct[x[i]]=0
		else
			np[x[i]%m+1]+=1
			ct[x[i]]=1
		end
	end
	ans = 0
	ans += np[1]>>1+p[1]>>1
	for i in 2:(m+1)>>1
		j = m+2-i
		if np[i]>np[j]
			if np[i]>np[j]+p[j]
				ans += np[j]+p[j]
				ans += p[i]>>1
			elseif np[i]+p[i]>np[j]+p[j]
				ans += np[j]+p[j]
				ans += (p[i]-(np[j]+p[j]-np[i]))>>1
			else
				ans += np[i]+p[i]
				ans += (p[j]-(np[i]+p[i]-np[j]))>>1
			end
		else
			if np[j]>np[i]+p[i]
				ans += np[i]+p[i]
				ans += p[j]>>1
			elseif np[i]+p[i]>np[j]+p[j]
				ans += np[j]+p[j]
				ans += (p[i]-(np[j]+p[j]-np[i]))>>1
			else
				ans += np[i]+p[i]
				ans += (p[j]-(np[i]+p[i]-np[j]))>>1
			end
		end	
	end
	if m%2==0
		ans += np[m>>1+1]>>1+p[m>>1+1]>>1
	end
	println(ans)
end

main()

Measured memory_bytes: 121776
#include <iostream>
#include <vector>
#include <queue>

struct N {
    N(int i, int c) : i(i), c(c) {}
    int i;
    int c;
};

using vi = std::vector<int>;
using vvi = std::vector<vi>;

using qN = std::queue<N>;

int main() {
    int n; std::cin >> n;
    vvi g(n + 1);
    int a, b;
    for (int i = 0; i < n - 1; i++) {
        scanf("%d %d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vi marked(n + 1);
    vi c(2);
    qN q;
    q.emplace(1, 0);
    q.emplace(n, 1);

    while (!q.empty()) {
        auto e = q.front();
        q.pop();
        if (marked[e.i]) continue;
        marked[e.i] = 1;
        c[e.c]++;
        for (auto a : g[e.i]) {
            if (!marked[a]) q.emplace(a, e.c);
        }
    }

    printf("%s\n", (c[0] > c[1] ? "Fennec" : "Snuke"));
}


Measured memory_bytes: 6272
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(true){
			int m = scan.nextInt();
			if(m == 0){
				break;
			}
			int d = scan.nextInt();
			
			int[] day = new int[12];
			day[0] = 3;
			day[1] = 6;
			day[2] = 0;
			day[3] = 3;
			day[4] = 5;
			day[5] = 1;
			day[6] = 3;
			day[7] = 6;
			day[8] = 2;
			day[9] = 4;
			day[10] = 0;
			day[11] = 2;
			String[] month = new String[7];
			month[0] = "Monday";
			month[1] = "Tuesday";
			month[2] = "Wednesday";
			month[3] = "Thursday";
			month[4] = "Friday";
			month[5] = "Saturday";
			month[6] = "Sunday";
			System.out.println(month[(d-1+day[m-1])%7]);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
map<string,int>ma;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	rep(i,1,n+1){
		string s;
		cin >> s;
		ma[s]++;
	}
	cout<<ma.size()<<endl;
	return 0;
}



Measured memory_bytes: 19284
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;

vi weights,vals;
int main(){
	int n,w;
	cin>>n>>w;
	weights.resize(n+1);
	vals.resize(n+1);
	for(int i=1;i<=n;i++){
		cin>>weights[i]>>vals[i];

	}
	vector<vector<ll> > dp;
	dp.resize(n+1);
	for(int i=0;i<=n;i++){
		dp[i].resize(w+1);
	}
	for(int item=1;item<=n;item++){
		for(int wei=0;wei<=w;wei++){
			if(wei>=weights[item]){
				dp[item][wei]=max(vals[item]+dp[item-1][wei-weights[item]],dp[item-1][wei]);
			}else{
				dp[item][wei]=dp[item-1][wei];
			}
		}
	}
	cout<<dp[n][w];
	

	return 0;
}

Measured memory_bytes: 79488
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=10007;
const ll INF=1000000000;
const int MAX=100001;
const double EPS=0.00001;
typedef pair<int,int> P;
ll f(ll b,ll n){
    if(n<b){
        return n;
    }else{
        return f(b,n/b)+(n%b);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,s;
    cin>>n>>s;
    if(n<s){
        cout<<-1<<endl;
        return 0;
    }
    if(n==s){
        cout<<n+1<<endl;
        return 0;
    }
    for(ll i=2;i<=sqrt(n);i++){
        if(f(i,n)==s){
            cout<<i<<endl;
            return 0;
        }
    }
    for(ll i=sqrt(n);i>=1;i--){
        if(n-s<i||(n-s)%i!=0){
            continue;
        }
        ll b=(n-s)/i+1LL;
        if(f(b,n)==s){
            cout<<b<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

                           


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	int a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f){
		cout.precision(3);
		double y = (double)(a*f-c*d)/(double)(a*e-b*d);
		double x = (double)(c-b*y)/(double)a;
		cout << std::fixed << x;
		cout << ' ' << std::fixed << y << endl;
	}
}

Measured memory_bytes: 1236
#include<stdio.h>
#define MAXN 200005
int t[MAXN];
int u[MAXN];
int r[MAXN];
int main(){
	int a[MAXN],n,cnt = 0, p,m,total = 0;
	long long k;
	scanf("%d %lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	p = 1;
	u[1] = 1;
	t[0] = 1;
	do{
		cnt++;
		p = a[p];
		t[cnt] = p;
		if(u[p] == 0){
			u[p] = 1;
		}else break;
	}while(true);
	for(int i = 0; i < cnt; i++){
		if(t[i] == p){
			m = i;
			break;
		}
	}
	if(k < m){
		printf("%d\n",t[k]);
	}else{
	k = k - m;
	for(int i = m; i < cnt; i++){
		r[total++] = t[i];
	}
	k = k % total;
	printf("%d",r[k]);
	}
	return 0;
}

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

typedef long long ll;


int main() {
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<ll> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a.begin(),a.end());
        reverse(a.begin(),a.end());
        ll sum=0;
        for(int i=0;i<n/2;i++){
            sum+=a[i]*2;
        }
        sum-=a[0];
        if(n%2==1)
            sum+=a[n/2];
        cout<<sum;
    }
	return 0;
}

Measured memory_bytes: 4808
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

  int64_t N, M;
  cin >> N >> M;

  vector<string> A(N);
  vector<string> B(M);

  for (int64_t i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int64_t i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  cout << endl; 

  for (int64_t i = 0; i < N - M + 1; i++) {
    vector<size_t> positions;

    size_t pos = A.at(i).find(B.at(0), 0);
    while (pos != string::npos) {
      positions.push_back(pos);
      pos = A.at(i).find(B.at(0), pos + 1);
    }

    for (size_t p : positions) {
      bool flag = true;
      for (int64_t j = 1; j < M; j++) {
        auto A_sub = A.at(i + j).substr(p, M);
        if (A_sub.compare(B.at(j)) != 0) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << "Yes"; 
        return 0; 
      }
    }
  }

  cout << "No"; 

  return 0;
}


Measured memory_bytes: 3568
n = gets.to_i
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i

#全部一番輸送力が低い量だけ運べば良い
m = [a,b,c,d,e].min
time_to2 = (n + m - 1) / m

puts time_to2 + 4

Measured memory_bytes: 1788
#include <bits/stdc++.h>
        using namespace std;
       // #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
           int h,w;
           cin>>h>>w;
           string s[h];
           for(int i=0;i<h;i++)cin>>s[i];
           int dp[h][w];
           if(s[0][0]=='.')dp[0][0]=0;
           else dp[0][0]=1;
           for(int i=1;i<w;i++){
                   if(s[0][i]==s[0][i-1])dp[0][i]=dp[0][i-1];
                   else dp[0][i]=1+dp[0][i-1];
           }
           for(int i=1;i<h;i++){
                   if(s[i][0]==s[i-1][0])dp[i][0]=dp[i-1][0];
                   else dp[i][0]=dp[i-1][0]+1;
                   for(int j=1;j<w;j++){
                             if(s[i][j]==s[i-1][j])dp[i][j]=dp[i-1][j];
                   else dp[i][j]=dp[i-1][j]+1;
                   if(s[i][j]==s[i][j-1])dp[i][j]=min(dp[i][j],dp[i][j-1]);
                   else dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
                   }
           }
           cout<<(dp[h-1][w-1]+1)/2<<endl;
         
}

        


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <limits.h>
#define N 200000
int main() {
  int n,i,min,max,R[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&R[i]);
  min=R[0];
  max=-1000000000;
  for(i=1;i<n;i++){
    if(max<R[i]-min)max=R[i]-min;
    if(min>R[i])min=R[i];
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2636
h1, a1, h2, a2 = map(int, input().split())

n1 = h1//a2 + (h1%a2 != 0)
n2 = h2//a1 + (h2%a1 != 0)

if n2 <= n1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61896
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long n,x,y,z,s=0,i,l,m,b[100000]={0};
    cin>>n;
    for(x=1;x<=sqrt(n);x++)
    {
        for(y=1;y<=sqrt(n);y++)
        {
            for(z=1;z<=sqrt(n);z++)
            {
                l=(x*x)+(y*y)+(z*z)+(z*x)+(x*y)+(y*z);
                b[l]=b[l]+1;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        cout<<b[i]<<endl;
    }  
    return 0;
}

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

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

    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

int main(){
  int m;
  while(cin >> m,m){
    int c=0;
    m=1000-m;
	while(m-500>=0){
	  m=m-500;
	  c++;
	}
	while(m-100>=0){
	  m=m-100;
	  c++;
	}
	while(m-50>=0){
	  m=m-50;
	  c++;
	}
	while(m-10>=0){
	  m=m-10;
	  c++;
	}
	while(m-5>=0){
	  m=m-5;
	  c++;
	}
	while(m-1>=0){
	  m=m-1;
	  c++;
	}
	cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())


a = []
for _ in range(N):
    n = int(input())
    a.append(n)

sorted = sorted(a)

max1 = sorted[-1]
max2 = sorted[-2]

for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 14080
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

const double PI = acos(-1.0);

int main() {
	while (1) {
		int a, b;
		char op;
		cin >> a >> op >> b;
		switch (op) {
			case '+':
				cout << a + b << endl;
				break;
			case '-':
				cout << a - b << endl;
				break;
			case '*':
				cout << a * b << endl;
				break;
			case '/':
				cout << a / b << endl;
				break;
			default:
				return 0;
		}
	}

	return 0;
}



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

int main() {
	
	int N, K, soma = 0;
	cin >> N >> K;
	int Vetor[N];
	
	
	for(int i=0; i<N; i++) {
		cin >> Vetor[i];
	}
	
	sort(Vetor, Vetor+N);
	
	for(int i=N-1; i>=N-K; i--)
		soma += Vetor[i];
	
	
	cout << soma << endl;
	return 0;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> cnt(3,0);
  rep(i,N){
    int a;
    cin >> a;
    if(a%4==0)  cnt.at(2)++;
    else if(a%2==0) cnt.at(1)++;
    else  cnt.at(0)++;
  }

  if(cnt.at(1)==0){
    if(cnt.at(0)-1<=cnt.at(2))  cout << "Yes" << endl;
    else  cout << "No" << endl;
  }
  else{
    if(cnt.at(0)<=cnt.at(2))  cout << "Yes" << endl;
    else  cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3660
using System;
using System.Collections.Generic;

namespace ABC116_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = int.Parse(Console.ReadLine());
            var ls = new List<int>();

            ls.Add(s);
            var cnt = 1;
            while (true)
            {
                if (s % 2 == 0)
                {
                    s /= 2;
                }
                else
                {
                    s = 3 * s + 1;
                }

                cnt++;
                if (ls.Contains(s))
                {
                    break;
                }
                ls.Add(s);
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13148
use input::Input;

fn main() {
    let mut input = Input::default();

    let h = input.parse::<usize>();
    let w = input.parse::<usize>();
    let k = input.parse::<u32>();
    let c = (0..h)
        .map(|_| input.parse::<String>().chars().collect::<Vec<char>>())
        .collect::<Vec<_>>();

    let mut ans = 0u32;
    for i in 0..(1 << h) {
        for j in 0..(1 << w) {
            let mut cnt = 0u32;
            for row in 0..h {
                for col in 0..w {
                    let red = i >> row & 1 == 1 || j >> col & 1 == 1;
                    if c[row][col] == '#' && !red {
                        cnt += 1;
                    }
                }
            }
            if cnt == k {
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


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

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const string S4[4] = {"abcc", "abdd", "ccab", "ddab"};
const string S5[5] = {"abbcc", "ad..a", "bd..a", "b.eez", "oorrz"};
const string S6[6] = {"oorrzz", ".a.b.c", ".a.b.c", "d.e.f.", "d.e.f.", "oorrzz"};
const string S7[7] = {".oorrzz", "oabb...", "oa.c...", "rddc...", "r...abb", "z...a.c", "z...ddc"};

char s[1010][1010];

inline void solve(int&n, int x) {
	if(x == 4)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S4[i][j];
	if(x == 5)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S5[i][j];
	if(x == 6)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S6[i][j];
	if(x == 7)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S7[i][j];
	n += x;
}

int main() {
	int n = ri;
	if(n <= 2) return puts("-1"), 0;
	if(n == 3) {
		puts("a..");
		puts("a..");
		puts(".bb");
		return 0;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			s[i][j] = '.';
	int x = n % 4, N = 1;
	if(x == 0) solve(N, 4);
	if(x == 1) solve(N, 5);
	if(x == 2) solve(N, 6);
	if(x == 3) solve(N, 7);
	while(N <= n) solve(N, 4);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			putchar(s[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

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

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();

		// 計算
		int min = Integer.MAX_VALUE;
		for (int A = 1; A < N; A++) {
			int B = N - A;
			int sumA = sumDigitsNumber(A);
			int sumB = sumDigitsNumber(B);
			if (sumA + sumB < min) {
				min = sumA + sumB;
			}
		}

		// 出力
		System.out.println(min);

		return;
	}


	private int sumDigitsNumber(int x) {
		int sum = 0;
		while(x > 0) {
			sum += x % 10;
			x /= 10;
		}
		return sum;
	}
}


Measured memory_bytes: 23252
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int x = 0,y=B;
		if((0<=A&&A<=100)&&(0<=B&&B<=100)&&(0<=C&&C<=100)) {
	while(y>=A && x<C) {
		y=y-A;
		x++;
	}
	System.out.println(x);
		}
	}
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int N, K; cin >> N >> K;
    vector<ll> p(N), sums(N+1);
    rep(i, N) {
        cin >> p[i];
        sums[i+1] = sums[i] + p[i];
    }
    ll sum = 0;
    double ans = 0;
    int i = 0;
    int ind = 0;
    ll tmp = 0;
    while (i <= N - K) {
        ll x = sums[i+K] - sums[i];
        if (tmp <= x) {
            ind = i;
            tmp = x;
        }
        i++;
    }
    
    for (int j = ind; j < ind + K; j++) {
        sum = (p[j] * (p[j] + 1)) / 2;
        ans += (double)(sum) / p[j];
    }
    printf("%.12lf\n", ans);
}

Measured memory_bytes: 3456
#include <iostream>
#define N_MAX 1000000000
using namespace std;
int func(long long n){
    static int cnt = 0;
    if(cnt++ > 64)return -1;
    char ans;
    cout << "? " << n << endl;
    cin >> ans;
    if(ans == 'Y')return 1;
    return 0;
}
int main(void){
    long long left = (long long)N_MAX*10-1, right = (long long)N_MAX*100;
    while(left + 1 < right){
        long long mid = (left + right) / 2;
        if(func(mid)){
            right = mid;
        }else{
            left = mid;
        }
    }

    while(right%10 == 0)right /= 10;

    if(right == 1){
        while(func(right*2) == 0){
            right *= 10;
        }
        cout << "! " << right << endl;
    }else{
        left = 10;
        right--;
        while(func(right*left) == 1){
            left *= 10;
        }
        left /= 10;
        right++;
        cout << "! " << right*left << endl;
    }

}


Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};



typedef struct _state{
  int from,vis;
  double cost;
  _state(double ic,int ifr,int iv):cost(ic),from(ifr),vis(iv){
  };
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

typedef struct _edge{
  int to,cost;
  _edge(int ito,int icost):to(ito),cost(icost){
  };
}edge;

main(){
  int n,m,p,a,b;
  while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n){
    --a,--b;
    int ti[n];
    vector<edge> V[m];
    rep(i,n)scanf("%d",ti+i);

    rep(i,p){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      --x,--y;
      V[x].pb(edge(y,z));
      V[y].pb(edge(x,z));
    }

    priority_queue<state> Q;
    Q.push(state(0,a,0));

    bool cost[1<<n][m];
    memset(cost,0,sizeof(cost));
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().from,cti=Q.top().vis;
      double ccost=Q.top().cost;
      Q.pop();
      if(cost[cti][from])continue;
      cost[cti][from]=true;
      if(from==b){
        ans=ccost;
        break;
      }

      rep(i,n){
        if(cti>>i&1)continue;
        rep(j,V[from].size()){
          int to=V[from][j].to;
          int cc=V[from][j].cost;
          if(cost[cti|1<<i][to])continue;
          double ncost=ccost+1.0*cc/ti[i];
          Q.push(state(ncost,to,cti|1<<i));
        }
      }
    }
    if(ans<0)puts("Impossible");
    else printf("%f\n",ans);
  }
}

Measured memory_bytes: 7772
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class ABulletinBoard {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt(), h = in.nextInt() - 1, w = in.nextInt() - 1;
            int mat[][] = new int[n][n];
            int ro = 0, co = 0;
            for (int i = 0; i + h < n; i++) {
                ro++;
            }
            for (int i = 0; i + w < n; i++) {
                co++;
            }
            out.println(ro * co);
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21076
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL n,x,y;
    cin>>n>>x>>y;
    LL a=y-x+1;
    LL ans[n+1];
    for(int i=0;i<=n;i++){ans[i]=0;}
    //接合と接合
    for(int i=1;i<=n-y+x;i++){
        ans[i]=ans[i]+(n-y+x-i+1);
    }
    if((a%2)==1){
        LL b=(a-1)/2;
        //ループ内
        for(int i=1;i<=b;i++){
            ans[i]=ans[i]+a;
        }
        ans[1]--;
        //ループと接合a
        if(x!=1){
        LL c=x-1;
        if(c<b){
            for(int i=2;i<=c+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=c+2;i<=b+1;i++){ans[i]=ans[i]+c*2;}
            for(int i=b+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        else{
            for(int i=2;i<=b+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=b+2;i<=c+1;i++){ans[i]=ans[i]+b*2;}
            for(int i=c+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        }
        //ループと接合b
        if(y!=n){
        LL c=n-y;
        if(c<b){
            for(int i=2;i<=c+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=c+2;i<=b+1;i++){ans[i]=ans[i]+c*2;}
            for(int i=b+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        else{
            for(int i=2;i<=b+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=b+2;i<=c+1;i++){ans[i]=ans[i]+b*2;}
            for(int i=c+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        }
        for(int i=1;i<=x-1;i++){ans[i+1]--;}
        for(int i=1;i<=n-y;i++){ans[i+1]--;}
    }
    else if(a!=2){
        LL b=a/2;
        //ループ内
        for(int i=1;i<=b-1;i++){
            ans[i]=ans[i]+a;
        }
        ans[1]--;
        ans[b]=ans[b]+b;
        //ループと接合a
        if(x!=1){
        LL c=x-1;
        if(c<b){
            for(int i=2;i<=c+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=c+2;i<=b+1;i++){ans[i]=ans[i]+c*2;}
            for(int i=b+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        else{
            for(int i=2;i<=b+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=b+2;i<=c+1;i++){ans[i]=ans[i]+b*2;}
            for(int i=c+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        }
        //ループと接合b
        if(y!=n){
        LL c=n-y;
        if(c<b){
            for(int i=2;i<=c+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=c+2;i<=b+1;i++){ans[i]=ans[i]+c*2;}
            for(int i=b+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        else{
            for(int i=2;i<=b+1;i++){ans[i]=ans[i]+(i-1)*2;}
            for(int i=b+2;i<=c+1;i++){ans[i]=ans[i]+b*2;}
            for(int i=c+2;i<=b+c;i++){ans[i]=ans[i]+(b+c-i+1)*2;}
        }
        }
        for(int i=1;i<=x-1;i++){ans[b+i]--;}
        for(int i=1;i<=n-y;i++){ans[b+i]--;}
        for(int i=1;i<=x-1;i++){ans[i+1]--;}
        for(int i=1;i<=n-y;i++){ans[i+1]--;}

    }
    for(int i=1;i<n;i++){cout<<ans[i]<<endl;}
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x_y = [abs(x[i]-y[i]) for i in range(n)]
p1 = sum(x_y)
p2 = sum([x**2 for x in x_y]) ** (1/2)
p3 = sum([x**3 for x in x_y]) ** (1/3)
pn = max(x_y)
print(p1)
print(p2)
print(p3)
print(pn)


Measured memory_bytes: 5644
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
using std::swap;

int N;
std::vector<int> A;
int ans = 1000000000;
int x = 1000000000;

int che(int s) {
	int m = 0;
	for (int i = 0; i < N; ++i) {
		int t;
		if (s >= A[i]) {
			if (ans > A[i])ans = A[i];
			continue;
		}
		A[i] = (A[i] % s != 0) ? A[i] % s : s;
		if (A[i] < ans) { 
			ans = A[i];
			m = 1;
		}
	}
	if (m == 0)return ans;
	else che(ans);
}

int main()
{	
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		if (A[i] < x)x = A[i];
	}
	cout << che(x) << "\n";
	return 0;
}

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

int main() {
  const string c[] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
  const int t[][3] = { {0, 0, 0}, { 0, 0, 255}, {0, 255, 0}, {0, 255, 255}, {255 ,0, 0},
                       {255, 0, 255}, {255, 255, 0}, {255, 255, 255} };
  string s;
  while (cin >> s, s != "0") {
    int r = stoi(s.substr(1, 2), nullptr, 16);
    int g = stoi(s.substr(3, 2), nullptr, 16);
    int b = stoi(s.substr(5, 2), nullptr, 16);
    double mind = 500.0;
    int idx = -1;
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(t[i][0] - r, 2) + pow(t[i][1] - g, 2) + pow(t[i][2] - b, 2));
      if (d < mind) {
        mind = d;
        idx = i;
      }
    }
    cout << c[idx] << "\n";
  }
}


Measured memory_bytes: 3124
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

bool query(int a, int b) {
	cout << "? " << a << ' ' << b << endl;
	string result;
	cin >> result;
	return result == "Y";
}

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

	int A, B;
	cin >> A >> B;

	if (A <= B) {
		cout << "Impossible" << endl;
		return 0;
	}

	int N = A + B;
	vector<int> chain = { 0 };

	for (int i = 1; i < N; i++)
		if (chain.empty() || query(chain.back(), i))
			chain.push_back(i);
		else
			chain.pop_back();

	int honest = chain.back();
	string answer(N, '1');

	for (int i = 0; i < N; i++)
		if (i != honest)
			answer[i] = query(honest, i) ? '1' : '0';

	cout << "! " << answer << endl;
}

Measured memory_bytes: 724
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

const int INF=1e18;

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

    int N,W; cin>>N>>W;
    vector<int> w(N),v(N);
    for(int i=0;i<N;i++) cin>>w[i]>>v[i];

    int V=accumulate(v.begin(),v.end(),0LL);
    vector<vector<int>> dp(N+1,vector<int>(V+1,INF));
    dp[0][0]=0;
    for(int i=0;i<N;i++) for(int j=0;j<=V;j++) if(dp[i][j]!=INF){
        assert(j+v[i]<=V);
        chmin(dp[i+1][j],dp[i][j]);
        chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
    }
    int ans;
    for(int j=0;j<=V;j++) if(dp[N][j]<=W) ans=j;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        cout << "a > b" << '\n';
    } else if (a < b) {
        cout << "a < b" << '\n';
    } else {
        cout << "a == b" << '\n';
    }
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    REP(i,0,s.size()){
        if(s[i]=='a') a++;
        if(s[i]=='b') b++;
        if(s[i]=='c') c++;
    }
    YESNO(max({a,b,c})-min({a,b,c})<=1);
    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = []
for i in range(n):
    sc = input().split()
    if sc[0] == 'S':
        a.append(int(sc[1]) - 1)
    if sc[0] == 'H':
        a.append(12 + int(sc[1]))
    if sc[0] == 'C':
        a.append(25 + int(sc[1]))
    if sc[0] == 'D':
        a.append(38 + int(sc[1]))
a.sort()

for i in range(52):
    if not i in a:
        if i // 13 == 0:
            print('S', i % 13 + 1)
        if i // 13 == 1:
            print('H', i % 13 + 1)
        if i // 13 == 2:
            print('C', i % 13 + 1)
        if i // 13 == 3:
            print('D', i % 13 + 1)


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

int main(void){
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set> 
#include<cmath>
using namespace std;
long long p  = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)
#define upper(h,val) upper_bound(h.begin(),h.end(),val)
#define mint modint<998244353>
#define end_s(a) cout <<a<<endl;return 0
template <std::uint_fast64_t Modulus> class modint {
	using u64 = std::uint_fast64_t;

public:
	u64 a;

	constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
	constexpr u64 &value() noexcept { return a; }
	constexpr const u64 &value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint &operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint &operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint &operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint &operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
signed main() {
	int n; cin >> n;
	vel count(n, 0);
	rep(i, n) {
		int a; cin >> a; a--;
		count[a]++;
	}
	sor(count);
	vel c_bel(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		c_bel[i] = count.end() - lower_bound(count.begin(), count.end(), i);
		c_bel[i] += c_bel[i - 1];
	}
	for (int i = 1; i <= n; i++) {
		int ans = n / i;
		while (true) {
			if (c_bel[ans] >= ans * i) {
				cout << ans << endl; break;
			}
			ans--;
		}
	}
	return 0;
}

Measured memory_bytes: 5504
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
    if nB != 0:
        Bsum += B[nB-1]
    if Bsum > K:
        break
    while Asum + Bsum > K:
        nA -= 1
        Asum -= A[nA]
    ans = max(nA + nB, ans)

print(ans)


Measured memory_bytes: 40684
import sys

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


def main():
    A, B, C, X, Y = map(int, readline().split())

    ans = INF
    for k in range(0, 2 * max(X, Y) + 1, 2):
        i = max(0, X - k // 2)
        j = max(0, Y - k // 2)
        if ans > A * i + B * j + C * k:
            ans = A * i + B * j + C * k

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(){

    int price[3];
    int x, y;

    for(int i = 0; i < 3; i++) cin >> price[i];
    cin >> x;
    cin >> y;

    if(price[0] + price[1] < 2 * price[2]){
        cout << price[0] * x + price[1] * y << endl;
    }
    else{
        if(x < y){
            cout << min( 2 * price[2] * x + price[1] * (y - x), 2 * price[2] * y ) << endl;
            //cout << "tes1" << endl;

        }
        else if(x >= y){
            cout << min( 2 * price[2] * y + price[0] * (x - y), 2 * price[2] * x ) << endl;
            //cout << "tes" << endl;
        }
    }

}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int p = -1, r = 0, t = 0;
	char s[51];
	scanf("%*d %s", s);
	while(s[++p])
		if(s[p] == 'A' + t) {
			if(++t == 3) {
				r++;
				t = 0;
			}
		} else
			t = s[p] == 'A';
	printf("%d", r);
	return 0;
}

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

typedef long long LL;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    LL N = S.length();
    LL counter = 0, result = 0;
    for (LL i = 0; i < N; ++i)
    {
        if (S[i] == 'B')
            counter++;
        else if (S[i] == 'W')
            result += counter;
    }

    cout << result;
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<math.h>

int main(){
	double a, b, c, d;
	scanf("%lf %lf %lf", &a, &b, &c);
	c = M_PI * c / 180;
	d = sqrt(a * a + b * b - 2 * a * b * cos(c));
	printf("%lf\n", a * b * sin(c) / 2);
	printf("%lf\n", a + b + d);
	printf("%lf\n", b * sin(c));
	return 0;
}

Measured memory_bytes: 1124
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(m);
	for (int i = 0; i < n; i++) {
		int p, q;
		cin >> p >> q;
		if (p <= m) {
			a[m - p].emplace_back(q);
		}
	}

	priority_queue<int> q;
	int ans = 0;
	for (int i = m - 1; i >= 0; i--) {
		for (auto & j : a[i]) {
			q.push(j);
		}

		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5504
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 100

using namespace std;

int A[MAX_N];

int main() {
  int N, x;
  cin >> N >> x;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A, A + N);
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] <= x) {
      ++cnt;
      x -= A[i];
    } else {
      printf("%d\n", cnt);
      return 0;
    }
  }
  if (x > 0) {
    printf("%d\n", cnt - 1);
  } else {
    printf("%d\n", cnt);
  }
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int M,K;
  cin>>M>>K;
  ll N=pow(2,M);
  if(M==0&&K==0){
    for(int i=0;i<N;i++)cout<<i<<" "<<i<<" ";
  }
  else if(M==1&&K==0){
    cout<<1<<" "<<1<<" "<<0<<" "<<0;
  }
  else if(M==1&&K==1){
    cout<<-1<<endl;
  }
  else if(N<=K){
    cout<<-1<<endl;
  }
  else{
    for(int i=0;i<N;i++){
      if(i==K)continue;
      cout<<i<<" ";
    }
    cout<<K<<" ";
    for(int i=N-1;i>=0;i--){
      if(i==K)continue;
      cout<<i<<" ";
    }
    cout<<K;
  }

  return 0;
}


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

vector<int> KMP(string s) {
  int n = s.size();
  s += "_"; // sentinel
  vector<int> kmp(n + 1), mp(n + 1);
  kmp[0] = mp[0] = -1;
  int j = -1;
  for(int i = 0; i < n; i++) {
    while(j >= 0 && s[i] != s[j]) j = kmp[j];
    kmp[i + 1] = mp[i + 1] = ++j;
    if(s[i + 1] == s[j]) kmp[i + 1] = kmp[j];
  }
  return mp;
}

vector<int> cycle(string s) {
  auto mp = KMP(s);
  vector<int> len(s.size());
  for(int i = 0; i < (int) s.size(); i++)
    len[i] = i + 1 - mp[i + 1];
  return len;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string s; cin >> s;
  string rev = s; reverse(begin(rev), end(rev));
  int n = s.size();
  auto len = cycle(s);
  auto rlen = cycle(rev);
  if(len.back() == n || n % len.back() != 0) {
    cout << 1 << endl << 1 << endl;
  } else if(len.back() == 1) {
    cout << n << endl << 1 << endl;
  } else {
    int cnt = 0;
    for(int i = 0; i < n - 1; i++)
      if(
          (len[i] == i + 1 || (i + 1) % len[i] != 0) && 
          (rlen[n - 2 - i] == n - 2 - i + 1 ||
           (n - 2 - i + 1) % rlen[n - 2 - i] != 0)) cnt++;
    cout << 2 << endl << cnt << endl;
  }
}



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

#define y1 dmytxdy
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1000000007;
int n;
ll d[300005][4][3],pw[300005],cnt[300005];
char s[300005];

ll mod(ll x){return x>=cys?x-cys:x;}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n==1){
		if(s[1]=='1'||s[1]=='?') printf("1\n");
		else printf("0\n");
		return 0;
	}
	pw[0]=1;
	for(int i=1;i<=n;i++) pw[i]=mod(pw[i-1]*2);
	for(int i=1;i<=n;i++) cnt[i]=cnt[i-1]+(s[i]=='?');
	d[0][2][0]=1;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='0'||s[i]=='?'){
			for(int j=0;j<=3;j++){
				for(int k=0;k<=2;k++){
					if(k==2) d[i][j+1][1]=mod(d[i][j+1][1]+d[i-1][j][k]);
					else if(k==1) d[i][j-1][2]=mod(d[i][j-1][2]+d[i-1][j][k]);
					else d[i][j-1][1]=mod(d[i][j-1][1]+d[i-1][j][k]);
				}
			}
		}
		if(s[i]=='1'||s[i]=='?'){
			for(int j=0;j<=3;j++){
				for(int k=0;k<=2;k++){
					if(j==3) ans=(ans+d[i-1][j][k]*pw[cnt[n]-cnt[i]])%cys;
					else d[i][j+1][max(k-1,0)]=mod(d[i][j+1][max(k-1,0)]+d[i-1][j][k]);
				}
			}
		}
	}
	printf("%lld\n",(ans+d[n][3][0]+d[n][3][1]+d[n][3][2])%cys);
	return 0;
}

Measured memory_bytes: 36800
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y] :
            self.par[x] = y
        
        else:
            self.par[y] = x

            if self.rank[x] == self.rank[y] :
                self.rank[x] += 1

n, q = map(int, input().split())

sets = UnionFind(n)
for _ in range(q):
    l = list(map(int, input().split()))
    if l[0] == 0:
        sets.union(l[1], l[2])
    else:
        if(sets.same(l[1], l[2])):
            print(1)
        else:
            print(0)


Measured memory_bytes: 6044