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

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

using namespace std;

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int n,tar; scanf("%d%d",&n,&tar);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	mint dp[2][3001];
	dp[0][0]=1;
	rep(i,n){
		int curr=i%2,next=(i+1)%2;
		rep(w,tar+1) dp[next][w]=0;

		rep(w,tar+1) dp[next][w]+=2*dp[curr][w];
		for(int w=tar;w>=a[i];w--) dp[next][w]+=dp[curr][w-a[i]];

		rep(w,tar+1) dp[curr][w]=dp[next][w];
	}
	cout<<dp[n%2][tar]<<'\n';

	return 0;
}


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

using ld = long double;
using P = complex<ld>;

const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

vector<P> points;

pair<P, ld> min_circle(int seed = 1333) {
    const int n = points.size();

    mt19937 mt(seed);
    shuffle(points.begin(), points.end(), mt);

    auto ps = points.begin();
    using circle = pair<P, ld>;

    auto make_circle_3 = [](const P &a, const P &b, const P &c) -> circle {
        ld A = norm(b - c), B = norm(c - a), C = norm(a - b),
           S = cross(b - a, c - a);
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
        ld r2 = norm(p - a);
        return {p, r2};
    };

    auto make_circle_2 = [](const P &a, const P &b) -> circle {
        P c = (a + b) / (ld)2;
        ld r2 = norm(a - c);
        return {c, r2};
    };

    auto in_circle = [](const P &a, const circle &c) -> bool {
        return norm(a - c.first) <= c.second + eps;
    };

    circle c = make_circle_2(ps[0], ps[1]);

    // MiniDisc
    for (int i = 2; i < n; ++i) {
        if (!in_circle(ps[i], c)) {
            // MiniDiscWithPoint
            c = make_circle_2(ps[0], ps[i]);
            for (int j = 1; j < i; ++j) {
                if (!in_circle(ps[j], c)) {
                    // MiniDiscWith2Points
                    c = make_circle_2(ps[i], ps[j]);
                    for (int k = 0; k < j; ++k) {
                        if (!in_circle(ps[k], c)) {
                            c = make_circle_3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n;cin>>n;
  for(int i=0;i<n;i++){
    double x,y;cin>>x>>y;
    points.push_back({x,y});
  }

  auto ans = min_circle();
  cout.precision(17);
  cout<<sqrt(ans.second)<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main { 
  public static void main(String[] args)

{
	Scanner sc=new Scanner(System.in); 
	String input=sc.nextLine();
	String[] inputArray =input.split(" ");
	
		int a = Integer.parseInt(inputArray[0]);  
    	int b = Integer.parseInt(inputArray[1]);
    	int c = Integer.parseInt(inputArray[2]);
		
		
		if(a>b)
		{
			int t=a;
			a=b;
			b=t;
		}
		
		if(b>c)
		{
			int t=c;
			c=b;
			b=t;
		}
		
		if(a>b)
		{
			int t=a;
			a=b;
			b=t;
		}
		
		System.out.println(a+" "+b+" "+c);
}

}

Measured memory_bytes: 25852
#include <stdio.h>
#include <string.h>

int main() {
	char a[11], b[11], c[11];

	scanf("%s %s %s", a, b, c);
	int l1 = strlen(a);
	int l2 = strlen(b);
	
	if(a[l1 - 1] == b[0] && b[l2 - 1] == c[0]) {
		puts("YES");
	}	
	else puts("NO");

	return 0;
}

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


int main(){
    int N,M;
    cin >> N>>M;
    int H[N+1];
    int C[N+1];
    int count = N;
    C[0]=9;

    for(int i=1;i<=N;i++){
        cin >> H[i];
        C[i] =i;
    }

    for(int j=1;j<=M;j++){
        int a,b;
        cin >> a >> b;
        if(H[a] > H[b]){
            if(C[b]==b){
                count--;
                C[b]=0;
            }
        }
        else if(H[a] < H[b]){
            if(C[a]==a){
                count--;
                C[a]=0;
            }
        }
        else{
            if(C[b]==b){
                count--;
                C[b]=0;
            }
            if(C[a]==a){
                count--;
                C[a]=0;
            }
        }
    }
    cout << count << endl;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    vector<ll> amemo(n);
    vector<ll> a(n);
    ll iin;
    for(ll i=0;i<n;i++) {
        cin >> iin; iin--;
        a.at(i) = iin;
        amemo.at(iin)++;
    }
    ll sum=0;
    for(ll i=0;i<n;i++) {
        sum += amemo.at(i)*(amemo.at(i)-1)/2;
    }

    for(ll i=0;i<n;i++) {
        cout << sum - (amemo.at(a.at(i))-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a[100005],b[100005],sa,sb,ans,s;
vector<ll>h;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sa+=a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        sb+=b[i];
        ll c=a[i]-b[i];
        if(c<0)s+=(-c),ans++;
        else if(c>0)h.PB(c);
    }
    if(sa<sb){
        cout<<-1<<endl;
        return 0;
    }
    sort(h.begin(),h.end(),greater<ll>());
    for(int i=1;i<h.size();i++)h[i]+=h[i-1];
    if(s>0)ans+=(lower_bound(h.begin(),h.end(),s)-h.begin())+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 2296
#include<stdio.h>
#include<stdlib.h>
#define NMIN 1
#define NMAX 36

struct card{
  char mark;
  char value;
};

void bubble(struct card A[],int n){
  int i,j;
  struct card t;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j].value<A[j-1].value){
	t=A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}
void selection(struct card A[],int n){
  int i,j,miji;
  struct card t;
  for(i=0;i<n;i++){
    miji=i;
    for(j=i;j<n;j++){
      if(A[j].value<A[miji].value)miji=j;
    }
    t=A[i];
    A[i]=A[miji];
    A[miji]=t;
      }
    }
void print(struct card A[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%c%c",A[i].mark,A[i].value);
  }
  printf("\n");
}
int isStable(struct card c1[],struct card c2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(c1[i].mark!=c2[i].mark) return 0;
  }
  return 1;
}

int main(){
  int n,i,j;
  struct card c1[NMAX],c2[NMAX];
  char ch;

  scanf("%d",&n);
  if(n<NMIN || n>NMAX)exit(1);
  for(i=0;i<n;i++){
    scanf(" %c%c",&c1[i].mark,&c1[i].value);
  }
  for(i=0;i<n;i++){
    c2[i]=c1[i];
  }
  bubble(c1,n);
  selection(c2,n);

  print(c1,n);
  printf("Stable\n");
  print(c2,n);
  if(isStable(c1,c2,n)==1){
    printf("Stable\n");
  }
  else {printf("Not stable\n");
  }
  return 0;
}
    



Measured memory_bytes: 2060
#include<stdio.h>

int main(void){
	
	int a,b;
	
	
	scanf("%d %d",&a,&b);
	if((a+b)%2==1){
		printf("%d\n",(a+b+1)/2);
	}else{
		printf("%d\n",(a+b)/2);
	}

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll _pow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; b >> i; i++) {
		if ((b >> i) & 1) ans *= a;
		a *= a;
	}
	return ans;
}
ll di[4] = { -1, 1, 0, 0 };
ll dj[4] = { 0, 0, -1, 1 };
ll inp[405][405];
int chk[405][405];
ll black, white;
int Mi, Mj;
void dfs(int xi, int xj) {
	chk[xi][xj] = true;
	if (inp[xi][xj] == '.') white++;
	else black++;
	for (int k = 0; k < 4; k++) {
		int ni = xi + di[k], nj = xj + dj[k];
		if (0 <= ni && ni < Mi && 0 <= nj && nj < Mj) {
			if (!chk[ni][nj] && (inp[xi][xj] != inp[ni][nj])) {
				dfs(ni, nj);
			}
		}
	}
}

ll ans;
int main(void) {
	scanf("%d %d", &Mi, &Mj);
	for (int i = 0; i < Mi; i++) {
		for (int j = 0; j < Mj; j++) {
			scanf(" %c", &inp[i][j]);
		}
	}

	for (int i = 0; i < Mi; i++) {
		for (int j = 0; j < Mj; j++) {
			if (!chk[i][j]) {
				dfs(i, j);
				ans += black * white;
				black = white = 0;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

	

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin >> n;
    ll c[n],s[n],f[n];
    for (ll i=0;i<n-1;i++)cin >> c[i] >> s[i] >> f[i];
    ll count;
    
    for (ll i=0;i<n-1;i++){
        count=s[i]+c[i];
        for (ll j=i+1;j<n-1;j++){
            ll count2=s[j];
            while(count>count2){
                count2+=f[j];
            }
            count=count2+c[j];
        }
        cout << count << endl;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop, heapify
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
v = LI()

heapify(v)

for i in range(N-1) :
    a = heappop(v)
    b = heappop(v)
    heappush(v, (a + b) / 2)
    
print(*v)

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

using namespace std;

int main(void) {
  int N; cin >> N;
  set<string> S;

  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    S.insert(s);
  }

  cout << S.size() << endl;

  return 0;
}

Measured memory_bytes: 19256
object Main extends App {

	var Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toLong)
	
	var x1 = x
	var y1 = n - x

	var flag = true
	var ans = n
	
	while(flag){
		if(x1 > y1){
			val tp = x1
			x1 = y1
			y1 = tp
		}

		if(y1%x1 == 0){
			ans += x1 * ( 2* (y1 / x1) - 1)
			flag = false
		}else{
			ans += x1 * 2 * (y1 / x1)
			y1 = y1 % x1
		}
	}

	println(ans)

}


Measured memory_bytes: 25544
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

s1 = a+b+c+d+e
st = []
st += [(10-a)%10,(10-b)%10,(10-c)%10,(10-d)%10,(10-e)%10]
s2 = sum(st) - max(st)
print(s1+s2)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 31696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
    if(a.at(i) == 2) {
    }

  }

  //上から順番にやっていく
  int count = 0;
  int x = a.at(0); //0+1 -> x
  while(count < N) {
    if(x != 2) {
      count++;
      x = a.at(x-1);
    } else {
      cout << count + 1 << endl;
      break;
    }
  }
  if(count >= N) {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3680
#include<stdio.h>
#define MAX  1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int min(int a,int b){
  if(a>b) return b;
  else return a;
}

int partition(int A[],int p,int r){
  int i,j;
  int t,x;
  x = A[r];
  i = p - 1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}

void quickSort(int A[],int p,int r){
  int q;
  if(p<r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int solve(){
  int ans=0,i,cur,S,m,an,v;

  int V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B,0,n-1);
  for(i=0;i<n;i++) T[B[i]] = i;
  for(i=0;i<n;i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = VMAX;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      v = A[cur];
      m = min(m,v);
      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    ans += min(S+(an-2)*m,m+S+(an+1)*s);
  }
  return ans;
}

int main(){
  int i;

  scanf("%d", &n);
  
  s = VMAX;
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    s = min(s,A[i]);
  }

  int ans = solve();
  printf("%d\n",ans);

  return 0;
}



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

int main(){

  long long int n, a, b, min, max, ans;

  cin >> n >> a >> b;

  if(a > b || (n == 1 && a != b)){
    cout << "0" << endl;
  }else if(n == 1 && a == b){
    cout << "1" << endl;
  }else{
    min = b + a * (n - 1);
    max = a + b * (n - 1);
    ans = max - min + 1; 
    cout << ans << endl;
  }
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int x = a.back();
	a.pop_back();
	int z1 = x/2, z2 = (x+1)/2;
	int m = 2001001001, y = -1;
	for (int e : a) {
		int d = min(abs(z1-e), abs(z2-e));
		if (d < m) m = d, y = e;
	}
	cout << x << ' ' << y << endl;
	return 0;
}

Measured memory_bytes: 3776
#include <cstdio>
using namespace std;
#define S 1000000
typedef struct{char n[10];int t;}QUE;
QUE que[S];
main(){
int i=0,T=0,h=0,t,n,q;
scanf("%d %d",&n,&q);
for(t=n;i<n;)scanf("%s %d",que[i++].n,&que[i].t);
while(h!=t){
i=que[h].t<=q||t-h==1;
T+=i?que[h].t:q;
if(i)printf("%s %d\n",que[h].n,T);
else{que[h].t-=q;que[t]=que[h];t=S==t+1?0:t+1;}
h=S==h+1?0:h+1;
}
}


Measured memory_bytes: 5296
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
INF = float('inf')

def bellmanford(edges, s, t, se):
    N = len(edges)
    dist = [INF] * N
    dist[s] = 0
    for i in range(N):
        update = False
        for v in range(N):
            if v in se and dist[v] == INF:
                continue
            for u, c in edges[v]:
                if u not in se:
                    continue
                d = dist[v] + c
                if d < dist[u]:
                    dist[u] = d
                    update = True
        if update == False:
            return max(0, -dist[t])
    else:
        return -1

N, M, P = map(int, input().split())
es = [[] for i in range(N)]
es_r = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    es[a-1].append((b-1, P-c))
    es_r[b-1].append(a-1)
reachable1 = [False] * N
def dfs(v):
    if reachable1[v]: return
    reachable1[v] = True
    for u, c in es[v]:
        dfs(u)
reachable2 = [False] * N
def rdfs(v):
    if reachable2[v]: return
    reachable2[v] = True
    for u in es_r[v]:
        rdfs(u)
dfs(0)
rdfs(N-1)
se = set()
for i in range(N):
    if reachable1[i] and reachable2[i]:
        se.add(i)
print(bellmanford(es, 0, N-1, se))


Measured memory_bytes: 63964
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	map<ll, ll> mp;
	vector<ll> a(n);
	ll mi = 1e9, mx = 0;
	rep(i,n){
		cin >> a[i];
		++mp[a[i]];
		chmin(mi, a[i]);
		chmax(mx, a[i]);
	}
	if(mx - mi > 1){
		cout << "No" << endl;
	}
	else if(mx == mi){
		if((n == mi + 1) || (n >= 2*mi)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else{
		if(mp[mi] < mx && 2*(mx - mp[mi]) <= mp[mx]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 10108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

int n,count = 0,sub;
cin >> n;
vector <int> a(n);
rep(i,n) cin >> a[i];
int i = 1;
while(count < n+1){
    i = a[i-1];
    count++;
    if(i == 2){
      cout << count << endl; 
      return 0;  
    } 
}
cout << (-1) << endl;


//////////////////////////////////////////////////////
return 0;}

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

typedef long long int ll;

int N;
vector<int> X1, X2, Y1, Y2;

vector<ll> compress(vector<ll> xs){
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    return xs;
}

int main(){
    cin >> N;
    
    vector<ll> xs, ys;
    for(int i=0; i<N; i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        
        X1.push_back(x1);
        Y1.push_back(y1);
        X2.push_back(x2);
        Y2.push_back(y2);
        
        xs.push_back(x1); xs.push_back(x2);
        ys.push_back(y1); ys.push_back(y2);
    }
    
    xs = compress(xs);
    ys = compress(ys);
    
    int X = xs.size();
    int Y = ys.size();
    
    vector<vector<int>> field(X, vector<int>(Y, 0));
    
    for(int i=0; i<N; i++){
        int x1i = lower_bound(xs.begin(), xs.end(), X1[i]) - xs.begin();
        int x2i = lower_bound(xs.begin(), xs.end(), X2[i]) - xs.begin();
        int y1i = lower_bound(ys.begin(), ys.end(), Y1[i]) - ys.begin();
        int y2i = lower_bound(ys.begin(), ys.end(), Y2[i]) - ys.begin();
        
        field[x1i][y1i]++;
        field[x2i][y1i]--;
        field[x1i][y2i]--;
        field[x2i][y2i]++;
        
//        for(int x=x1i; x<x2i; x++)
//            for(int y=y1i; y<y2i; y++)
//                field[x][y]++;
    }
    
    for(int x=0; x<X; x++)
        for(int y=0; y<Y-1; y++)
            field[x][y+1] += field[x][y];
    
    for(int y=0; y<Y; y++)
        for(int x=0; x<X-1; x++)
            field[x+1][y] += field[x][y];
    
    ll ans = 0;
    for(int x=0; x<X-1; x++){
        for(int y=0; y<Y-1; y++) if(field[x][y]){
            ans += (xs[x+1]-xs[x])*(ys[y+1]-ys[y]);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 65624
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data{105, 135, 165, 189, 195};
  int count = 0;
  for(int a: data){
    if(a <= N)count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  char c;
  cin >> c;
  c++;
  cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=2e5+5;
int n,len[MN],stk[MN],val[MN],top;
inline void insert(int pos,int x){
	while(stk[top]>pos)top--;
	if(stk[top]==pos)val[top]++;
	else stk[++top]=pos,val[top]=1;
	if(top&&val[top]==x)top--,insert(pos-1,x);
}
bool check(int x){
	stk[top=0]=val[0]=0;
	for(reg int i=2;i<=n;i++)
		if(len[i-1]>=len[i])insert(len[i],x);
	return !val[0];
}
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++)scanf("%d",len+i);
	reg int flg=1;
	for(reg int i=2;flg&&i<=n;i++)
		if(len[i]<=len[i-1])flg=0;
	if(flg)return 0*puts("1");
	reg int l=2,r=n,ans=n,mid;
	while(l<=r){
		mid=(l+r>>1);
		if(check(mid))r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
from operator import itemgetter
N = int(input())
a = [tuple(map(int, input().split())) for _ in [0]*N]
ans = float("inf")

a.sort()
for (x1, y1), (x2, y2) in zip(a, a[1:]):
    dist = (x1-x2)**2 + (y1-y2)**2
    if ans > dist:
        ans = dist

a.sort(key=itemgetter(1))
for (x1, y1), (x2, y2) in zip(a, a[1:]):
    dist = (x1-x2)**2 + (y1-y2)**2
    if ans > dist:
        ans = dist

print(ans)


Measured memory_bytes: 79872
import java.util.HashSet;
import java.util.Scanner;

public class Main 
{
	static int n, m;
	static int[] par;
	static int[] rank;
	
	static class Bag
	{
		HashSet<Integer> con = new HashSet<>();
	}
	
	static void union(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		
		if(rank[rx] >= rank[ry])
		{
			par[ry] = rx;
			if(rank[rx] == rank[ry])
				rank[rx]++;
		}
		else par[rx] = ry;
	}
	
	static int root(int x)
	{
		if(par[x] != x)
			par[x] = root(par[x]);
		return par[x];
	}
	
	static int[] ya, xa, a;
	static Bag[] bags;
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		a = new int[n];
		xa = new int[m];
		ya = new int[m];
		bags = new Bag[n];
		
		par = new int[n];
		rank = new int[n];
		
		
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			a[i] = sc.nextInt()-1;
		}
		
		for(int i = 0; i < m; i++)
		{
			xa[i] = sc.nextInt()-1;
			ya[i] = sc.nextInt()-1;
			
			union(xa[i],ya[i]);
		}
		
		for(int i = 0; i < n; i++)
		{
			bags[i] = new Bag();
		}
		for(int i = 0; i < n; i++)
		{
			bags[root(i)].con.add(i);
		}
		
		int scr = 0;
		for(int i = 0; i < n; i++)
		{
			Bag bag = bags[i];
			for(int c : bag.con)
			{
				if(bag.con.contains(a[c]))scr++;
			}
		}
		System.out.println(scr);
	}

}


Measured memory_bytes: 98796
N = int(input())
O = str(N)
if(len(O) == 1):
    print(N)
elif(len(O) == 2):
    print(9)
elif(len(O) == 3):
    print(N-90)
elif(len(O) == 4):
    print(909)
elif(len(O) == 5):
    print(N-9090)
else:
    print(90909)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!
i = list(map(int, input().split()))
X=i[0]
Y=i[1]
flag=0

A=2*X
if(A==Y):
    print("Yes")
    flag=1
else:
    for i in range(X):
        A=A+2
        if(A==Y):
            print("Yes")
            flag=1
            break
if(flag==0):
    print("No")
            

Measured memory_bytes: 9120
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    ll d, t, s;
    cin >> d >> t >> s;
    cout << (s * t >= d ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
const int ma = 200000;
template< typename T > inline istream & operator >> ( istream & i, vector< T > & v )
{for( int j = 0; j < v.size(); j++ ) i >> v[j]; return i;}
int dp[ma];
main()
{
    int n,m;
    cin >> n >> m;
    vector< int > a(n);
    cin >> a;
    for( int i = 1; i <= m; i++ )
    {
        for( int j : a )
        {
            if( i >= j )dp[i] |= !dp[i - j];
        }
    }
    if( dp[m] ) puts("First");
    else puts("Second");
    return 0;
}

Measured memory_bytes: 640
from collections import Counter, deque
H, W = map( int, input().split())
S = [list(input()) for x in range(H)]
white = 0
for i in range(H):
    white += Counter(S[i])['.']
Goal = False
Able = True

path = 1
Sunuke = [[0,0]]
S[0][0] = '#'
while Goal == False and len(Sunuke) != 0:
    Sunuke_temp = Sunuke
    Sunuke = []
    path += 1
    for x in Sunuke_temp:
        i = x[0]
        j = x[1]
        if (min(i+1,H-1) == H-1 and j == W-1) or (min(j+1,W-1) == W-1 and i == H-1):
            Goal = True
            Sunuke.append([1,1])
            break
        if S[max(i-1,0)][j] == '.':
            Sunuke.append([i-1,j])
            S[i-1][j] = '#'
        if S[min(i+1,H-1)][j] == '.':
            Sunuke.append([i+1,j])
            S[i+1][j] = '#'
        if S[i][max(j-1,0)] == '.':
            Sunuke.append([i,j-1])
            S[i][j-1] = '#'
        if S[i][min(j+1,W-1)] == '.':
            Sunuke.append([i,j+1])
            S[i][j+1] = '#'

print(-1 if len(Sunuke) == 0 else white - path)

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

using namespace std;

int n;
int v[3010];
long long dp[3010][3010][2];

long long f(int i, int j, int flag) {
    if(i > j) return 0;
    
    long long &ans = dp[i][j][flag];
    if(ans != -1) return ans;
    ans = flag ? -1e18 : 1e18;

    if(flag) {
        ans = max(ans, f(i + 1, j, !flag) + v[i]);
        ans = max(ans, f(i, j - 1, !flag) + v[j]);
    } else {
        ans = min(ans, f(i + 1, j, !flag) - v[i]);
        ans = min(ans, f(i, j - 1, !flag) - v[j]);
    }
    return ans;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i = 0; i < n; ++i) 
        cin >> v[i];
    
    cout << f(0, n - 1, 1) << "\n";
    
    return 0;
    for (int i = 0; i < n; ++i) {
        for (int j = n - 1; j >= 0; j--) {
            if(j <= i) continue;
            dp[i][j][1] = max(dp[i][j][1], dp[i][j - 1][0] + v[j]);
            dp[i][j][1] = max(dp[i][j][1], dp[i + 1][j][0] + v[i]);
            dp[i][j][0] = min(dp[i][j][0], dp[i + 1][j][1] - v[i]);
            dp[i][j][0] = min(dp[i][j][0], dp[i][j - 1][1] - v[j]);
        }
    }
    
    cout << dp[0][n - 1][1] << "\n";
    return 0;
}


Measured memory_bytes: 141952
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  queue<pair<int, int>> que;
  vector<vector<int>> dist(h, vector<int> (w, -1));
  rep(sh,h) {
    rep(sw, w) {
      if(grid[sh][sw] == '#') {
        dist[sh][sw] = 0;
        que.push({sh, sw});
      }
    }
  }

  while(!que.empty()) {
    int vh = que.front().fi;
    int vw = que.front().se;
    que.pop();

    rep(dir, 4) {
      int nvh = vh + dy[dir];
      int nvw = vw + dx[dir];

      if(nvh < 0) continue;
      if(nvw < 0) continue;
      if(nvh >= h) continue;
      if(nvw >= w) continue;
      if(dist[nvh][nvw] != -1) continue;
      if(grid[nvh][nvw] == '#') continue;

      dist[nvh][nvw] = dist[vh][vw]+1;
      que.push({nvh, nvw});
    }
  }

  int res = -1;
  rep(gh,h) rep(gw,w) res = max(res, dist[gh][gw]);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 13456
#include<iostream>
using namespace std;
int main() {
	int a[13];
	a[1] = 0;
	a[2] = 2;
	a[3] = 0;
	a[4] = 1;
	a[5] = 0;
	a[6] = 1;
	a[7] = 0;
	a[8] = 0;
	a[9] = 1;
	a[10] = 0;
	a[11] = 1;
	a[12] = 0;
	int x, y;
	cin >> x >> y;
	if (a[x] == a[y])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007

string s;
int ans=0;
// int check(int i)
// {
// 	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
// 	{
// 		return 1;
// 	}
// 	return 0;
// }
// int rep(int i)
// {
// 	s[i]='B';
// 	s[i+1]='C';
// 	s[i+2]='A';
// 	return 0;
// }
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>s;
	int n=s.length();
	int val=0;
	f(i,0,n-1)
	{
		if(s[i]=='A')
		{
			val++;
		}
		else if(s[i]=='B'&&s[i+1]=='C')
		{
			ans+=val;
			i++;
		}
		else
		{
			val=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

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

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        998244353
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  200005

ll n,l,r;
vi a(N+5,0),seg(4*(N+5));
void build(ll cur,ll st,ll end)
{
	if(st==end)
	{
		seg[cur]=a[st];
		return;
	}
	ll mid=(st+end)>>1;
	build(2*cur,st,mid);
	build(2*cur+1,mid+1,end);
	seg[cur]=max(seg[2*cur],seg[2*cur+1]);	/*  1-change here  */
}
ll query(ll cur,ll st,ll end,ll l,ll r)
{
	if(l<=st&&r>=end)
	return seg[cur];
	if(r<st||l>end)
	return 0;                           /*  2-change here  */
	ll mid=(st+end)>>1;
	ll ans1=query(2*cur,st,mid,l,r);
	ll ans2=query(2*cur+1,mid+1,end,l,r);
	return max(ans1,ans2);                 /*  3-change here  */
}
void update(ll cur,ll st,ll end,ll pos,ll upd)
{
	if(st==end)
	{
		a[pos]=upd;					/*  4-change here  */
		seg[cur]=upd;					/*  5-change here  */
		return;
	}
	ll mid=(st+end)>>1;
	if(st<=pos&&pos<=mid)
		update(2*cur,st,mid,pos,upd);
	else
		update(2*cur+1,mid+1,end,pos,upd);
	seg[cur]=max(seg[2*cur],seg[2*cur+1]);	/*  6-change here  */
}

int main()
{
    ios;
    ll tt=1;
    // cin>>tt; 
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n;
    	build(1,0,N);
    	vector<pair<ll,ll>> v;
    	vi vv;
    	for(i=0;i<n;i++)
    	{
    		cin>>l>>m;
    		vv.pb(l);
    		v.pb({l,m});
    	}
    	vi ans(n+1,0);
    	sort(all(v));
    	sort(all(vv));
    	ans[n]=1;
    	for(i=n-1;i>=0;i--)
    	{
    		ll x=v[i].F+v[i].S-1;
    		ll ind=upper_bound(all(vv),x)-vv.begin()-1;
    		ll y=query(1,0,N,i,ind);
    		y=max(y,i);
    		update(1,0,N,i,y);
    	}
    	for(i=n-1;i>=0;i--)
    	{
    		ll y=a[i];
    		ans[i]=(ans[i+1]+ans[a[i]+1])%hell;
    	}
    	cout<<ans[0]<<endl;
    }
    return 0;
}

Measured memory_bytes: 17376
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort(key=lambda x: x[1])
cnt = 0
tmp = -10 ** 18

for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)

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

ab.sort(key=lambda x: x[1])
sub = -1
ans = 0
for i in range(m):
    if ab[i][0] <= sub and ab[i][1] > sub:
        continue
    else:
        ans += 1
        sub = ab[i][1] - 1

print(ans)

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


int main(){
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> ai(n,0), bi(m,0);
  vector<ll> ta(n+10,0), tb(m+10,0);

  ll a, b;
  rep(i,n){
    cin >> ai[i];
  }
  rep(i,m) {
    cin >> bi[i];
  }
  //reverse(ai.begin(), ai.end());
  //reverse(bi.begin(), bi.end());
  rep(i,n+1){
    if (i > 0) {
      ta[i] = ta[i-1] + ai[i-1];
    } else {
      ta[i] = 0;
    }
  }
  rep(i,m+1){
    if (i > 0) {
      tb[i] = tb[i-1] + bi[i-1];
    } else {
      tb[i] = 0;
    }
  }

  ll ans = 0;
  ll jbest = m;
  rep(i,n+1) {
    if (ta[i] > k) {
      break;
    }
    while (tb[jbest] > k - ta[i]) {
      --jbest;
    }
    ans = max(ans, i+jbest);
  }

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


Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, k;
	cin>>n>>k;
	vector<int> arr;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
		}	
	
	sort(arr.begin(),arr.end());
	reverse(arr.begin(),arr.end());
	long long sum = 0;
	for(int i =0;i<arr.size();i++)
	{
		if(k > 0)
			k--;
		else
		{
			sum += arr[i];
		}
	}
	cout<<sum<<endl;
	
}

Measured memory_bytes: 1400
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        s: chars,
    };
    // println!("{}", s.iter().step_by(2).collect::<String>());
    let ans: String = s
    .iter()
    .enumerate()
    .filter(|&(i, _)| i % 2 == 0)
    .map(|(_, v)| *v)
    .collect();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int m,f,b,x;
	scanf("%d %d %d",&m,&f,&b);
	if(m>=b)	{
		printf("0\n");
	}
	else if(m+f>=b)	{
		printf("%d\n",b-m);
	}
	else {
		printf("NA\n");
	}
	return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct state {
    int D;
    vector<int> c;
    vector<vector<int>> s;
    vector<int> before;

    state(int D,vector<int> &c,vector<vector<int>> &s): D(D),c(c),s(s),before(26,-1) {}

    vector<int> optimization() {
        vector<ll> ans(D + 1,0);
        vector<int> indexs(D);
        rep(i,D) {
            int idx = next_day(i);
            before[idx] = i;
            indexs[i] = idx + 1;
        }
        return indexs;
    }

    int next_day(int d) {
        int idx = -1,ans = -INF;
        rep(i,26) {
            int ret = s[d][i];
            int x = before[i];
            before[i] = d;
            rep(j,26) {
                ret -= (d - before[j]) * c[j];
            }
            if (ans < ret) {
                ans = ret;
                idx = i;
            }
            before[i] = x;
        }
        return idx;
    }

};

int main() {
    int D; cin >> D;;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(i,D)rep(j,26) cin >> s[i][j];
    
    state st(D,c,s);
    vector<int> ans = st.optimization();
    rep(i,D) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long i = 0; i < (long)(n); i++)
 
int main() {
  long n,c = 0;
  cin >> n;
  
  rep(i, n) {
    if ((i+1) % 3 == 0 || (i+1) % 5 == 0) continue;
    else c += i + 1;
  }
  
  cout << c << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=300010;

signed main(){
    ll d,t,s;cin>>d>>t>>s;
    if(s*t>=d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
   int n, x, i, sum=0, cnt=1;
   cin >> n >> x;
   int a[n];
   for(i=0; i<n; i++)
   {
       cin >> a[i];
   }

   for(i=0; i<n; i++)
   {
       sum=sum+a[i];
       if(sum<=x) cnt++;
   }

   cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as U
import Control.Monad
import Data.List

readIntPair :: B.ByteString -> (Int,Int)
readIntPair s = p
    where
    Just p = do
        (n1, s') <- B.readInt s
        (n2, _ ) <- B.readInt (B.tail s')
        return (n1,n2)

main :: IO ()
main = do
    (h, w) <- fmap readIntPair B.getLine
    as <- replicateM h B.getLine
    let modulo = 1000000007 :: Int
    let v0 = U.generate w (\i -> if i == 0 then 1 else 0) :: U.Vector Int
    let vn = foldl' step v0 as 
        step tbl line = U.constructN w gen
            where
            gen v | B.index line i == '#' = 0 
                  | i == 0 = tbl U.! i
                  | otherwise = (tbl U.! i + v U.! (i - 1)) `mod` modulo
                  where i = U.length v
    print (U.last vn)


Measured memory_bytes: 2684
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll nC3(ll n){
    return n * (n-1) / 2 * (n-2) / 3;
}
ll nC2(ll n){
    return n * (n-1) / 2;
}
ll nC1(ll n){
    return n;
}

int main(){
    int N;cin>>N;
    string str;cin>>str;
    vector<int> S;
    int rs = 0, gs = 0, bs = 0;
    for (int i = 0; i < N; i++)
    {
        int a;
        switch(str[i]){
            case 'R':
            a = 0;
            rs++;
            break;
            case 'G':
            a = 1;
            gs++;
            break;
            case 'B':
            bs++;
            a = 2;
        }
        S.push_back(a);
    }
    ll base = nC3(N);
    ll touka = 0;
    for(int i = 0;i < N;i++){
        for(int j = 1;j < N;j++){
            if(i+j >= N || i+j*2 >= N)break;
            touka++;
            // cout<<i<<i+j<<i+2*j<<endl;
            if(S[i] == S[i+j] || S[i+j] == S[i+2*j] || S[i+2*j] == S[i])touka--;
        }
    }
    // cout<<touka<<endl;
    touka += nC3(rs) + nC3(bs) + nC3(gs) + 
         nC2(rs) * nC1(bs) +nC2(rs) * nC1(gs)+
         nC2(bs) * nC1(rs) +nC2(bs) * nC1(gs)+
         nC2(gs) * nC1(rs) +nC2(gs) * nC1(bs);
    // cout<<nC2(3)<<nC2(2)<<nC2(1)<<nC2(0)<<endl;
    // cout<<touka<<" "<<base<<endl;
    cout<<base - touka << endl;
    
}

Measured memory_bytes: 3640
m = 10**9+7

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

l = [0 for i in range(n)]
ll = [[]for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    l[a]+=1
    l[b]+=1
    ll[a].append(b)
    ll[b].append(a)

if n==1:
    print(k)
    exit()

q = max(l)
if k<q+1:
    print(0)
    exit()

f = [1,1]
for i in range(2,k+1):
    f.append(f[-1]*i%m)

g = [1]
for i in range(k):
    g.append(pow(f[i+1],m-2,m))


ans = k

ans *= f[k-1]*g[k-1-l[0]]
ans %= m

visited = [0]*n
visited[0]==1
for x in ll[0]:
    visited[x]==1

for i in range(1,n):
    if visited[i] ==0:
        ans *= f[k-2]*g[k-1-l[i]]
        ans %= m
        for x in ll[i]:
            visited[x]==1

print(ans)



Measured memory_bytes: 72224