akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}
static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}

typedef i32  radix_type;

#define RADIX_WIDTH 10
const uint32_t radix_type_max = 30;
const uint32_t radix_type_begin = 0;
const uint32_t radix_width = RADIX_WIDTH;
const uint32_t radix_mask = (1 << RADIX_WIDTH) - 1;
#undef RADIX_WIDTH

static inline uint32_t radix_get_bit (radix_type v, uint32_t shift) {
  return v >> shift & radix_mask;
}

void radix_sort (radix_type *a, uint32_t n) {
  radix_type * const array = (radix_type *) calloc (4 * n, sizeof (radix_type));
  radix_type **bucket = (radix_type **) calloc (1 << radix_width, sizeof (radix_type *));
  uint32_t *len = (uint32_t *) calloc (2 << radix_width, sizeof (uint32_t));
  uint32_t *max_len = len + (1 << radix_width);
  for (uint32_t shift = radix_type_begin; shift < radix_type_max; shift += radix_width) {
    radix_type *p = array;
    memset (len, 0, sizeof (uint32_t) << (radix_width + 1));
    for (uint32_t i = 0; i < n; ++i) {
      uint32_t bit = radix_get_bit (a[i], shift);
      if (len[bit] == max_len[bit]) {
	for (uint32_t j = 0; j < len[bit]; ++j) {
	  p[j] = bucket[bit][j];
	}
	max_len[bit] = 2 * max_len[bit] + 1;
	bucket[bit] = p;
	p += max_len[bit];
      }
      bucket[bit][len[bit]++] = a[i];
    }
    for (uint32_t bit = 0, i = 0; bit < (1 << radix_width); ++bit) {
      for (uint32_t j = 0; j < len[bit]; ++j, ++i) {
	a[i] = bucket[bit][j];
      }
    }
  }
  free (array);
  free (bucket);
  free (len);
}

void run (void) {
  i32 n = read_int();
  i32 *a = (i32 *) calloc (2 * n, sizeof (i32));
  i32 *b = a + n;
  for (i32 i = 0; i < n; ++i) {
    a[i] = b[i] = read_int();
  }
  radix_sort (b, n);
  i32 l = b[n / 2 - 1];
  i32 r = b[n / 2];
  for (i32 i = 0; i < n; ++i) {
    print_int (a[i] <= l ? r : l);
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define rep(i, k) for (i = 0; i < k; i++) 
typedef long long ll;
typedef pair<ll, ll> l_l;
int i, j;

int main() {
	int a,b,k,z=0;
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA";
		return 0;
	}
	int c = 0;
	rep(i,s.length()){
		if (isupper(s[i]))c++;
	}
	if (c!=2) {
		cout <<"WA";
		return 0;
	}
	a = 0;
	for (i = 2; i < s.length() - 1; i++) {
		if (s[i] == 'C')a++;
	}
	if (a==0) {
		cout << "WA";
		return 0;
	}
	cout << "AC";
}



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

int main(void) {
  int n;
  cin >> n;
  ll a[n];
  rep (i, n) cin >> a[i];

  sort(a, a + n);

  vector<ll> s(n, 0);
  s[0] = a[0];
  rep (i, n - 1) s[i + 1] = s[i] + a[i + 1];

  int ans = 1;
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] * 2 >= a[i + 1]) {
      ans++;
      continue;
    }
    break;
  }

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

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

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans;
    rep(i,n) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

long n, d, sum, ans = 0;
long x[10][10];
bool isSquare;

int main(){
	cin >> n >> d;
	for(int i = 0; i < n; ++i) for(int j = 0; j < d; ++j) cin >> x[i][j];

	for(int i = 0; i < n - 1; ++i){
		for(int j = i + 1; j < n; ++j){
			isSquare = false;
			sum = 0;
			for(int k = 0; k < d; ++k){
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			for(int k = 0;; ++k){
				if(k * k == sum){
					isSquare = true;
					break;
				}else if(k * k > sum) break;
			}
			ans += isSquare;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const long long MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m;
  cin >> n >> m;
  int s[n], t[m];
  for(int i = 0; i < n; i++) cin >> s[i];
  for(int i = 0; i < m; i++) cin >> t[i];

  ll dp[n + 1][m + 1][2][2];
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++){
      for(int k = 0; k < 2; k++){
        fill(dp[i][j][k], dp[i][j][k] + 2, 0);
      }
    }
  }

  for(int j = 0; j <= m; j++){
    dp[0][j][0][0] = 1;
  }
  for(int i = 0; i <= n; i++){
    dp[i][0][0][0] = 1;
  }

  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      for(int k = 0; k < 2; k++){
        for(int l = 0; l < 2; l++){
          if(k == 1 && l == 1){
            if(s[i - 1] == t[j - 1])
              dp[i][j][k][l] = (
                  (dp[i - 1][j - 1][0][0] +
                   dp[i - 1][j - 1][0][1]) % MOD +
                  (dp[i - 1][j - 1][1][0] +
                   dp[i - 1][j - 1][1][1]) % MOD
                  ) % MOD;
          }
          else if(k != 1 && l == 1){
            dp[i][j][k][l] = dp[i - 1][j][0][1];
            dp[i][j][k][l] = (dp[i][j][k][l] + dp[i - 1][j][1][1]) % MOD;
          }
          else if(k == 1 && l != 1){
            dp[i][j][k][l] = dp[i][j - 1][1][0];
            dp[i][j][k][l] = (dp[i][j][k][l] + dp[i][j - 1][1][1]) % MOD;
          }
          else{
            dp[i][j][k][l] = (
                (dp[i - 1][j - 1][0][0] +
                 dp[i - 1][j - 1][0][1]) % MOD +
                (dp[i - 1][j - 1][1][0] +
                 dp[i - 1][j - 1][1][1]) % MOD
                ) % MOD;
          }
        }
      }
    }
  }

  ll sum = dp[n][m][0][0];
  sum = (sum + dp[n][m][0][1]) % MOD;
  sum = (sum + dp[n][m][1][0]) % MOD;
  sum = (sum + dp[n][m][1][1]) % MOD;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 125440
#include<stdio.h>
#include<stdlib.h>
 
int main(){
  int n,bus,i,muda,ans=0,sum=0,weight=0,mudajougen;
  int *W;
  scanf("%d %d",&n,&bus);
  W=malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&W[i]);
    sum+=W[i];
    if(ans<W[i]) ans=W[i];
  }
  if(ans< sum/bus) ans=sum/bus;
  while(1){
    muda=0;
    weight=0;
    mudajougen=ans*bus-sum;
    for(i=0;i<n;i++){
      if(weight +W[i] <= ans) weight+=W[i];
      else{
        muda+=ans-weight;
        if(muda>mudajougen) break;
        weight=W[i];
      }
    }
    if(i==n) break;
    ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2220
fun main(args: Array<String>) = asakatsu0404c()

fun asakatsu0404c() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val scList = (1..m).map { readLine()!!.split(' ').map { it.toInt() } }
        .map { it[0] to it[1] }

    for (i in 0..999) {
        if (i.toString().length != n) continue
        if (scList.all { Character.getNumericValue(i.toString()[it.first - 1]) == it.second }) {
            return println(i)
        }
    }

    println(-1)
}


Measured memory_bytes: 38472
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I a,b,c;
  cin >> a >> b >> c;
  I t=b/a;
  t = min(t,c);
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
#define INF 9223372036854775807;
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};



int main(){
  intl A,B,AB,X,Y;
  cin >> A>>B>>AB>>X>>Y;
  intl mincost=INF;
  Rep(i, max(X,Y)+1 ){
    intl cost = AB*2*i + A*max(X-i,(intl)(0)) + B*max(Y-i,(intl)(0));
    mincost= min (mincost,cost);
  }
  cout <<mincost;
}

  

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

signed main(){
    int n;
    cin >> n;
    int x[n];
    rep(i,n) cin >> x[i];
    sort(x,x+n);
    int ans=10000000000000;
    for(int i=x[i];i<=x[n-1];i++){
        int sum=0;
        rep(j,n){
            sum+=(x[j]-i)*(x[j]-i);
        }
        ans=min(ans,sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n;
  scanf("%d\n",&n );
  if (n<105) {
    puts("0");
  } else if (n < 135) {
    puts("1");
  } else if(n < 165){
    puts("2");
  } else if(n<189){
    puts("3");
  }else if(n < 195){
    puts("4");
  }else{
    puts("5");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

class Factorial {
    public:
    Factorial(int n) {
        fac = new ll[n + 1];
        fac[0] = 0; fac[1] = 1;
        REP(i, 2, n + 1) {
            fac[i] = fac[i - 1] * i % MOD;
        }
    }

    ll factorial(int n) {
        return fac[n];
    }

    private:
    ll *fac;
};

int main() {
    int N, M; cin >> N >> M;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
        return 0;
    }

    Factorial f(max(N, M));
    ll ans = f.factorial(N) * f.factorial(M) % MOD;
    if (N == M) ans = (ans * 2) % MOD;
    cout << ans << endl;
    return 0;
}

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

int main() {
#ifdef _test
    freopen( "in.txt", "r", stdin);
#endif

    int a, b;
    cin >> a >> b;
    int x = max( a + b, max(a-b,a*b));
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
count = 0

for i in range(N):
  A = list(map(int,input().split()))
  z = 0
  for j in range(M):
   z = z + (A[j] * B[j])
  if z + C > 0:
   count = count + 1
  
print(count)

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

typedef long long ll;

int n,r,w;
string in;

int main()
{
    cin>>n;

    cin>>in;

    for(int i=0;i<n;i++)
    {
        if(in[i]=='W') w++;
        else r++;
    }

    int ans = min(r,w);

    w=0;

    for(int i=0;i<r;i++)
    {
        if(in[i]=='W') w++;
    }

    cout<<min(ans,w);


}

Measured memory_bytes: 3728
N = int(input())
As = list(map(int, input().split()))

n_neg = 0
for A in As:
    if A < 0:
        n_neg += 1

Bs = list(map(abs, As))
if n_neg % 2 == 0:
    ans = sum(Bs)

else:
    Bs = sorted(Bs)
    Bs[0] = -Bs[0]
    ans = sum(Bs)
print(ans)

Measured memory_bytes: 14332
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String[] s = new String[3];
		for (int i = 0; i < 3; i++)
			s[i] = sc.next();

		System.out.println(s[0].substring(0, 1) + s[1].substring(1, 2) + s[2].substring(2, 3));

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

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

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

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

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

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

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 20564
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
 
public class Main {
 
	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Map <Integer,Integer> mapP = new HashMap<Integer,Integer> ();
		Map <Integer,Integer> mapS = new TreeMap<Integer,Integer> ();
			// 整数の入力
			int n,p,q,a,b;
			int index,counter,result;
			n = sc.nextInt();
			for(index=0;index<n;index++) {
				p = sc.nextInt();
				mapP.put(index,p);
				mapS.put(p,index);
			}
			sc.close();
			
			result=0;
			counter=0;
			for(Integer s: mapS.keySet()) {
				index=mapS.get(s);
				p=mapP.get(index);
				if(counter!=index) {
					result++;
				}
				counter++;
			}
			if(result==0 || result==2) {
				System.out.print("YES");
			}
			else {
				System.out.print("NO");
			}
			
 
			// 出力
 
	}
}

Measured memory_bytes: 21716
#include"iostream"
#include"string"
#include"algorithm"
using namespace std;

int n,m;
int a[55];

int main()
{
	cin >> n;

	for (int i = 1; i <= 10000; i++)
	{
		int yakusuu = 0;
		for (int j = 1; j <= i; j++)
		{
			if (i%j == 0) yakusuu++;
		}

		if (yakusuu == 2&&i%5==2) {
			a[m] = i;
			m++;
		}
		if (m == n)break;
	}

	for (int i = 0; i < n; i++) cout << a[i]<<" ";
	
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vi a(n-1);rep(i,n-1) cin >> a[i];
    map<int,int> mp;
    rep(i,n) mp[i+1]=0;
    rep(i,a.size()) {
        mp[a[i]]++;
    }
    for(auto x:mp) {
        ct(x.second);
    }
}


Measured memory_bytes: 13428
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<=n;i++)
    {
        dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
    }
    cout<<dp[n-1];
    return 0;
}









Measured memory_bytes: 1408
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
    string N;cin>>N;
    ll N_ll = stoll(N);
    string N1 = N.substr(0, 1);
    int sum = stoi(N1) - 1;
    while (N_ll >= 10) {
        sum += 9;
        N1 += "9";
        N_ll /= 10;
    }
    if (N1 == N) cout << sum + 1 << endl;
    else cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<string, int> mp;
#define ll long long

int main() {
    string s;
    cin >> s;
    if (s == "ani") {
        cout << "square1001" << endl;
    }
    else cout << "e869120" << endl;
    return 0;
}


Measured memory_bytes: 3144
import java.util.LinkedList;
import java.util.Collections;
import java.util.Scanner;

public class Main{
	
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		LinkedList<Integer> nums = new LinkedList<>();
		
		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			nums.add(scan.nextInt());
		}
		
		// sort
		Collections.sort(nums);
		
		// search
		int answer = 0;
		int count = 1;
		int memory = nums.poll();
		while(nums.size() > 0){
			if(memory != nums.peek()){
				if(count > memory){
					answer += count - memory;
				} else if (count < memory){
					answer += count;
				}				
				count = 1;
				memory = nums.poll();
			} else {
				nums.poll();
				count++;
			}
		}
		if(count > memory){
			answer += count - memory;
		} else if (count < memory){
			answer += count;
		}		
		
		// answer
		System.out.println(answer);
		
	}
}

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

using namespace std;

int main() {
	int n_r, n_c;
	scanf("%d %d", &n_r, &n_c);

	int t[100][100];

	int r, c;
	int v;
	for(r = 0; r < n_r; r++) {
		c = 0;
		while(cin >> v) {
			t[r][c] = v;
			//printf("t[%d][%d] = %d\n", r, c, v);
			c++;
			if(c >= n_c) break;
		}
	}

	int sum;

	for(r = 0; r < n_r; r++) {
		sum = 0;
		for(c = 0; c < n_c; c++) {
			sum += t[r][c];
			printf("%d ", t[r][c]);
		}
		printf("%d\n", sum);
	}

	int total_sum = 0;
	for(c = 0; c < n_c; c++) {
		sum = 0;
		for(r = 0; r < n_r; r++) {
			sum += t[r][c];
		}
		total_sum += sum;
		printf("%d ", sum);
	}
	printf("%d\n", total_sum);
	return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    LL x, y;
    cin >> x >> y;
    LL ans;
    if (x % y == 0) ans = -1;
    else {
        ans = x << 1;
        while (ans % y == 0) ans += x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  vvi a(3,vi(3,0));
  rep(i,3) rep(j,3) cin>>a[i][j];
  int n;
  cin>>n;
  vi b(n,0);
  cin>>b;
  vvi hit(3,vi(3,0));
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(b[i]==a[j][k]) hit[j][k]=1;
      }
    }
  }


  rep(i,3){
    int bingo=0;
    bingo+=hit[i][0];
    bingo+=hit[i][1];
    bingo+=hit[i][2];
    if(bingo==3){
      cout<<"Yes"<<endl;
      return;
    }
  }

  rep(i,3){
    int bingo=0;
    bingo+=hit[0][i];
    bingo+=hit[1][i];
    bingo+=hit[2][i];
    if(bingo==3){
      cout<<"Yes"<<endl;
      return;
    }
  }

    int bingo=0;
    bingo+=hit[0][0];
    bingo+=hit[1][1];
    bingo+=hit[2][2];
    if(bingo==3){
      cout<<"Yes"<<endl;
      return;
    }

    bingo=0;
    bingo+=hit[0][2];
    bingo+=hit[1][1];
    bingo+=hit[2][0];
    if(bingo==3){
      cout<<"Yes"<<endl;
      return;
    }
  
  cout<<"No"<<endl;
  return;

} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N;
	int a[Nmax]={};
	cin >> N;
	int cnt=0;
	REP(i,N){
		cin >> a[i];
		while(a[i]%2==0){
			a[i]/=2;
			cnt++;
		}
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    long long int sum=0;
    for(i=1;i<=n;i++){
        if(!(i%3==0) && !(i%5==0) /*&& !(i%15==0)*/)
        sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;
 

int main(){
    int n,m; cin >> n >> m;
    int ma=INF; int mi=0;
    rep(i,m){
        int l,r; cin >> l >> r;
        ma=min(ma,r);
        mi=max(mi,l);
    }
    cout << max(0,ma-mi+1) << endl;
return 0;
}


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

#define int long long
#define inf 10000000000000
typedef pair<int, int> P;//to,1=cost

vector<P>G[205];
int R[10];
int graf[205][205];
int dp[1 << 10][70];

signed main() {
	int n, m, r;
	cin >> n >> m >> r;
	for (int i = 0; i < 204; i++)
		for (int j = 0; j < 205; j++)graf[i][j] = inf;

	for (int i = 0; i < r; i++) { cin >> R[i]; R[i]--; }
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		G[a - 1].push_back(P(b - 1, c));
		G[b - 1].push_back(P(a - 1, c));
		graf[a - 1][b - 1] = c;
		graf[b - 1][a - 1] = c;
	}
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)graf[j][k] = min(graf[j][k], graf[j][i] + graf[i][k]);

	int ans = inf;
	sort(R, R + r);
	do {
		int res = 0;
		for (int i = 0; i < r - 1; i++)res += graf[R[i]][R[i + 1]];
		ans = min(ans, res);
	} while (next_permutation(R, R + r));
	cout << ans << endl;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(input())
    dist = [[] for _ in range(N)]
    for i in range(N-1):
        u,v,w = map(int,input().split())
        dist[u-1].append((v-1,w%2))
        dist[v-1].append((u-1,w%2))

    go = [True for _ in range(N)]
    length = [0 for _ in range(N)]
    go[0] = False
    q = deque([0])
    while q:
        now = q.pop()
        for fol,d in dist[now]:
            if go[fol]:
                length[fol] = length[now]+d
                go[fol] = False
                q.append(fol)

    for i in length:
        print(i%2)
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 37212
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,W;
  cin>>n>>W;
  vector<ll> w(n);
  vector<ll> v(n);
  rep(i,n)cin>>w[i]>>v[i];
  int MAX_V=100001;
  vector<vector<ll>> dp(n,vector<ll>(MAX_V,-1));
  dp[0][0]=0;
  dp[0][v[0]]=w[0];
  repeat(i,1,n) {
    dp[i][0]=0;
    repeat(vv,1,MAX_V) {
      if(dp[i-1][vv]!=-1)
        dp[i][vv]=dp[i-1][vv];
      if(vv-v[i]>=0&&dp[i-1][vv-v[i]]!=-1) {
        if(dp[i][vv]!=-1)
          dp[i][vv]=min(dp[i][vv],w[i]+dp[i-1][vv-v[i]]);
        else
          dp[i][vv]=w[i]+dp[i-1][vv-v[i]];
      }
    }
  }
  ll ans=0;
  repeat(vv,1,MAX_V) {
    if(dp[n-1][vv]!=-1&&dp[n-1][vv]<=W)
      ans=vv;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 79984
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

int cost[200000];
int ans[200000];
vector<int> g[200000];

void func(int y, int count){
    if (ans[y] != -1) {
        return;
    }
    ans[y] = count;
    // cout << ans[y] << endl;
    rep(i, g[y].size()){
        func(g[y][i], count + cost[g[y][i]]);
    }
    
}

int main(){
    int n, q;
    cin >> n >> q;
    
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i, q){
        int p, x;
        cin >> p >> x;
        p--;
        cost[p] += x;
    }
    fill(ans, ans + n, -1);
    func(0, cost[0]);
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
}

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

using namespace std;
using ll = long long;

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

	if (K == 1) { cout << 0 << endl; }
	else { cout << N - (K - 1) - 1 << endl; }

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int ret=0;
		for(int i=1;i<=x[0];i++)
		{
			int n=0;
			string s=i.ToString();
			for(int j=0;j<s.Length;j++)
			{
			n+=int.Parse(s[j].ToString());	
			}
			if(x[1]<=n&&n<=x[2])ret+=i;
		}
		Console.WriteLine(ret);
	}
}

Measured memory_bytes: 13268
xx = []
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
xx = sorted(ab, key= lambda x:x[0])

ans = 0
for i in range(n):
  ans += xx[i][1]
  if ans >=  k:
    print(xx[i][0])
    break

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

int main() {
  int N;
  int64_t D;
  cin >> N >> D;
  int ans=0;
  for(int i=0;i<N;i++){
    int64_t x,y;
    cin >> x >> y;
    if(x*x+y*y<=D*D) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, ans;
	string s;
	set<string> ss;

	cin >> n;
	while (n--) {
		cin >> s;
		ss.insert(s);
	}
	cout << ss.size() << "\n";

	return 0;
}


Measured memory_bytes: 19228
n = int(input())
restaurants = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    restaurants.append((i, s, p))

# restaurants.sort(key=lambda x: x[2], reverse=True)
# restaurants.sort(key=lambda x: x[1])
restaurants.sort(key=lambda x: (x[1], -x[2]))
for res in restaurants:
    print(res[0] + 1)

Measured memory_bytes: 3060
from collections import deque
N, Q = map(int, input().split())
counter = [0] * N
graph = [deque([]) for _ in range(N + 1)]
for i in range(N - 1):
  a, b =  map(int, input().split())
  graph[a - 1].append(b - 1)
  graph[b - 1].append(a - 1)
  
for i in range(Q):
  p, x = map(int, input().split())
  counter[p - 1] += x 

#print(graph, counter)
# 深さ優先探索
def dfs(v):
    #global time
    #time += 1
    visited[v] = 1
    stack = [v]
    #print(stack, v)
    #arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if visited[w] == 0:
              visited[w] = 1
              counter[w] += counter[v]
              stack.append(w) 
        else:
            stack.pop()          
    return 0

visited = [0] * N
# 孤立している頂点対策
#for i in range(N):
 #   if visited[i] == 0:
  #     dfs(i)
dfs(0)

#print(counter)

print(*counter)

Measured memory_bytes: 157120
n,x=map(int,input().split())
a=[]
for i in range(n):
    a.append(int(input()))
a.sort()
for j in range(0,n):
    x-=int(a[j])
count = n
while True:
    if(x<int(a[0])):
        print(count)
        break
    else:
        x -= int(a[0])
        count += 1

Measured memory_bytes: 3064
instr = input()
A, B, C = map(int, instr.split(" "))

score = 0
if B < C:
    score += 2 * B
    C -= B
    B = 0

    if A <= C:
        score += A
        C -= A
        A = 0

        if C > 0:
            score += 1
            C -= 1

    else:
        score += C
        C = 0
        A -= C
else:
    score += B + C
    B = C = 0

print(score)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
vector <int> adj[100001];
ll vis[100001];
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int root_find()
{
    ll x;
    for(int i=1;i<100001;i++)
    {
        if(adj[i].size()==1)
        {
            x = i;
            break;
        }
    }
    return x;
}
void dfs(int s,int y)
{
    for(int i=0;i<adj[s].size();i++)
    {
        if(adj[s][i]==y)
        continue;
        dfs(adj[s][i],s);
    }
}
void bfs(int s)
{
    queue <ll> q;
    q.push(s);
    vis[s]=1;
    while(!q.empty())
    {
        ll u = q.front();
        q.pop();
        for(int i=0;i<adj[u].size();i++)
        {
            if(vis[adj[u][i]]==0)
            {
            vis[adj[u][i]]=1;
            q.push(adj[u][i]);
            }
        }

    }
}
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
ll smallestDivisor(ll n) 
{ 
    // if divisible by 2 
    if (n % 2 == 0) 
        return n/2; 
  
    // iterate from 3 to sqrt(n) 
    for (int i = 3; i * i <= n; i += 2) { 
        if (n % i == 0) 
            return n/i; 
    } 
  
    return n; 
}  
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            ans = ans + a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7572
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;
int n,m;
map<string,int > buy;
map<string,pair<int,vector<string> > > make;

int cal(string s){
  int ret1,ret2;
  //cout<<"name:"<<s<<endl;
  ret1 = buy[s];
  if( make.find(s) != make.end() ){
    pair<int,vector<string> > p = make[s];
    int k = p.first;
    ret2 = 0;
    for(int i = 0;i<k;i++){
      ret2 += cal((p.second)[i]);
    }    
  }else{
    ret2 = 1111111111;
  }
  return min(ret1,ret2);
  

}

int main(){
  while(cin>>n){
    if(n==0)
      return 0;
    buy.clear();
    make.clear();
    for(int i = 0;i<n;i++){
      string s;
      int p;
      cin>>s>>p;
      buy[s] = p;
    }
    cin>>m;
    for(int i = 0;i<m;i++){
      string s,tmp;
      int k;
      vector<string> tmp_v;
      cin>>s;
      cin>>k;
      for(int j = 0;j<k;j++){
	cin>>tmp;
	tmp_v.push_back(tmp);
      }
      make[s] = make_pair(k,tmp_v);
    }
    string t;
    cin>>t;
    cout<<cal(t)<<endl;
  }

  return 0;
}

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

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  cout << (m1 != m2 ? 1 : 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin >> t;
	cout << t*t;
	return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int MOD = 1e9 + 7;


#define INPUT(x)                freopen(x,"r",stdin)
#define OUTPUT(x)               freopen (x,"w",stdout)


#define pb                      push_back
#define endl                    '\n'
#define LCM(a,b)                (a/__gcd(a,b))*b
#define GCD(a,b)                __gcd(a,b)
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define PI                      acos(-1.0)
#define distance(x1,y1,x2,y2)   sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define MAX                     1e9 + 9

#define taratari                ios_base::sync_with_stdio(0);cin.tie(NULL);



int main()
{
    taratari

    map <int, int> a;

    map <int,int>::iterator it;

    int n;
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;

        a[x]++;
    }

    int sum=0;

    for(it=a.begin();it!=a.end();it++)
    {
            if(it->second & 1) // % operator
            sum++;

    }

    cout<<sum;

    return 0;

}



Measured memory_bytes: 8280
#include <stdio.h>

int main(void){
   int i, a, n, max, min;
   long int sum;
   fscanf(stdin,"%d",&n);
   fscanf(stdin,"%d",&a);
   min=a; max=a; sum=a;
   for(i=1;i<n;i++){
      fscanf(stdin,"%d",&a);
      if(a>max) max=a;
      if(a<min) min=a;
      sum+=a;
   }
   printf("%d %d %ld\n",min,max,sum);
   return 0;
}

Measured memory_bytes: 604
N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l=-1
r=10**12+10
while l+1<r:
    mid=(l+r)//2
    s=0
    for i in range(N):
        s+=max(0, A[i]-mid//F[i])
    if s<=K:
        r=mid
    else:
        l=mid
print(r)


Measured memory_bytes: 120140
#include <iostream>
#include <algorithm>
using namespace std;
struct A{
    int ai;
    int i;
}a[100005];
bool cmp(A a, A b) {
    return a.ai < b.ai;
}
int main() {
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> a[i].ai;
        a[i].i = i;
    }
    sort(a, a + N, cmp);
    for(int i = 0; i < N; ++i)
        cout << a[i].i + 1 << ' ';
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    REP(i, N) cin >> L[i];
    sort(L.begin(), L.end());

    long long ans = 0;
    REP(i, N) REP(j, i+1, N){
        int a = L[i];
        int b = L[j];
        int id = lower_bound(L.begin(), L.end(), a+b) - L.begin();
        int diff = id - j - 1;
        if(diff > 0) ans += diff;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;


void solve()
{
    ll a,b,c,k,s=0;
    cin >> a >> b >> c >> k;
    
    if(k-a<0)
    {
        s+=k;
        k=0;
    }
    else
    {
        s+=a;
        k-=a;
    }    

    if(k-b<0)
    {
        k=0;
    }    
    else
    {
        k-=b;
    }

    if(k-c<0)
    {
        s-=k;
        k=0;
    }    
    else
    {
        s-=c;
        k-=c;
    }

    cout << s << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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 N;
ll X;
ll l[60];

ll query(int n, ll x) {
  if (n == 0) {
    if (x == 1) {
      return 1LL;
    } else {
      return 0LL;
    }
  } else if (n == 1) {
    if (x >= 4) {
      return 3LL;
    } else if (x == 3) {
      return 2LL;
    } else if (x == 2) {
      return 1LL;
    } else {
      return 0LL;
    }
  } else {
    if (x >= l[n]-1) {
      ll tmp = query(n-1, l[n-1]);
      return tmp * 2 + 1;
    } else if (x >= (l[n-1] + 2)) {
      ll d = x - (l[n-1] + 2);
      ll tmp1 = query(n-1, l[n-1]);
      ll tmp2 = query(n-1, d);
      return tmp1 + tmp2 + 1;
    } else if (x >= (l[n-1] + 1)) {
      ll tmp = query(n-1, l[n-1]);
      return tmp;
    } else if (x >= 1) {
      ll tmp2 = query(n-1, x-1);
      return tmp2;
    } else {
      return 0LL;
    }
  }
}

int main () {
  cin >> N >> X;

  l[0] = 1;
  rep(i, 50) {
    l[i] = l[i-1] * 2 + 3;
  }

  cout << query(N, X) << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC 147B
int main() {
	string s;
	cin >> s;

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

Measured memory_bytes: 256
/*


                 """Bismillahir Rahmanur Rahim"""

*/
#include<bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
#define ll long long int
#define inf 922337203470075000
#define pb push_back
#define pf push_front
const ll sz = 1000001;
#define ek(x) __builtin_popcount(x)
#define ses '\n'
#define in(x) scanf("%lld",&x);
#define out(x) printf("%lld\n",x);
#define stm istringstream
#define all(x) x.begin(),x.end()
#define ghora ios_base::sync_with_stdio(0);cin.tie(0);
#define gcd __gcd
ll lcm(ll x,ll y){return (x*y)/gcd(x,y);}
#define tin ll T;cin>>T; for(ll o=1;o<=T;o++)
#define tout cout<<"Case "<<o<<": ";
#define spc printf(" ");
std::vector<ll> v;
ll n,k;
ll dp[100000];
ll f(ll i)
{
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    ll m=922337203470075,z;
    for(int j=1;j<=k;j++)
   {
      z=i+j;
      if(z>=n)
        continue;
       m=min(m,(abs(v[i]-v[z])+f(z)));
   }
return dp[i]=m;
}
int main()
{
   
     ll p;
     memset(dp,-1,sizeof(dp));
     cin>>n>>k;
     for(ll i=0;i<n;i++)
     {
        cin>>p;
        v.pb(p);
     }
     ll x=f(0);
     cout<<x<<ses;
    return 0;
}
/*   --------------------
    |      ~SOHAN~       |
    |   ~Chandler68~     |
     --------------------
    || VALAR MORGULIS||==|| ALL MEN MUST DIE ||
    \\ Power Is Power//
    || I Can Do This All day ||
    // We are on a Break \\ // How you doin'? \\
    || Say My Name || ~~ || I Am The Who Knocks ||
    // I Am Ted Mosby Architect \\
    || It Is Legen --wait for it -- dary ,Legendary ||
    \\ Penny - Penny - Penny // -- Bazinga

*/

Measured memory_bytes: 8180
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
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<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    int x,a,b;
    cin>>x>>a>>b;
    if(a-b>=0)fin("delicious");
    else if(x>=b-a)fin("safe");
    else fin("dangerous");

}


Measured memory_bytes: 256