akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using P = pair<int, int>;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  REP(i, n) {
    REP(j, n - 1) {
      cin >> a[i][j];
      a[i][j]--;
    }
    REVERSE(a[i]);
  }
  vector<P> que;
  auto check = [&](int i) {
    if (a[i].size() == 0) return;
    int j = a[i].back();
    if (a[j].back() == i) {
      if (i > j) que.push_back(P(j, i));
      else
        que.push_back(P(i, j));
    }
  };
  REP(i, n) {
    check(i);
  }
  int day = 0;
  while (que.size() > 0) {
    day++;
    SORT(que);
    que.erase(unique(que.begin(), que.end()), que.end());
    vector<P> prevQ;
    swap(prevQ, que);
    EACH(p, prevQ) {
      int i = p.first;
      int j = p.second;
      a[i].pop_back();
      a[j].pop_back();
    }
    EACH(p, prevQ) {
      int i = p.first;
      int j = p.second;
      check(i);
      check(j);
    }
  }
  REP(i, n) {
    if (a[i].size() != 0) {
      cout << -1 << endl;
      return;
    }
  }
  cout << day << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 7104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int minCount = 100000;
        for (char c: "KUPC".toCharArray()) {
            int count = 0;
            for (int i = s.indexOf(c, 0); i != -1; i = s.indexOf(c, i+1)) count++;
            minCount = Math.min(minCount, count);
        }
        System.out.println(minCount);
    }

}

Measured memory_bytes: 0
n = int(input())
li = list(map(int,input().split()))
li_ans = []
for i in range(n):
  li_1 = li[0:i]
  li_2 = li[i:n]
  d = abs(sum(li_1)-sum(li_2))
  li_ans.append(d)
print(min(li_ans))

Measured memory_bytes: 3060
def main():
    W, H, x, y = map(int, input().split())
    area = (H*W)/2
    mid_x, mid_y = W/2, H/2
    if x == mid_x and y == mid_y:
        ans = 1
    else:
        ans = 0
    print(area, ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 100002

int x;
int y;
int z;

struct st {
	int a;
	int b;
	int c;
};
vector<st> v;
bool cmp(st &a, st &b) {
	return a.a - a.b > b.a - b.b;
}


map<pair<int,int>, int> ac;
map<pair<int,int> , int> bc;

template<typename ty>
struct BIT {
	vector<ty> v;
	void resize(int n) {
		v.assign(n + 1, 0);
	}
	void add(int i, int j) {
		i++;
		while (i < v.size()) {
			v[i] += j;
			i += i&-i;
		}

	}
	ty sum(int i) {
		ty r = 0;
		i++;
		while (i) {
			r += v[i];
			i -= i&-i;
		}
		return r;
	}
	int lower_bound(int x) {
		if (x <= 0) return 0;
		int res = 0;
		for (int i = 1 << 24; i > 0; i >>= 1)
			if (res + i < v.size() && v[res + i] < x) {
				res += i; x -= v[res];
			}
		return res;
	}
};
struct BLOCK {
	BIT<int> b1;
	BIT<long long int> b2;
	int lim;
	long long int sumc;
	long long int calc() {
		int id = b1.lower_bound(lim);
		return sumc + b2.sum(id);
	}
	BLOCK() {
		sumc = 0;
		b1.resize(100002);
		b2.resize(100002);
	}
	void add(pair<int,int> sa, int c,map<pair<int,int>,int> &mp) {
		b1.add(mp[sa], 1);
		sumc += c;
		b2.add(mp[sa], sa.first);
	}
	void del(pair<int,int> sa, int c, map<pair<int,int>, int> &mp) {
		b1.add(mp[sa], -1);
		sumc -= c;
		b2.add(mp[sa], -sa.first);
	}
};
BLOCK AC;
BLOCK BC;
int main() {
	cin >> x >> y >> z;
	int n = x + y + z;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		v.push_back({ a,b,c });
	}
	sort(v.begin(), v.end(),cmp);
	for (int i = 0; i < v.size(); i++) {
		ac[make_pair(v[i].a - v[i].c,i)] = 0;
		bc[make_pair(v[i].b - v[i].c,i)] = 0;
	}
	int ii = 0;
	for (auto it = ac.rbegin(); it != ac.rend(); it++) {
		(*it).second = ii;
		ii++;
	}
	ii = 0;
	for (auto it = bc.rbegin(); it != bc.rend(); it++) {
		(*it).second = ii;
		ii++;
	}
	AC.lim = x;
	BC.lim = y;
	for (int i = 0; i < n; i++) {
		if (i < x) {
			AC.add(make_pair(v[i].a - v[i].c, i), v[i].c, ac);
		}
		else {
			BC.add(make_pair(v[i].b - v[i].c, i), v[i].c, bc);
		}
	}
	long long int ans = AC.calc() + BC.calc();
	for (int i = x - 1; i < n - y-1; i++) {
		AC.add(make_pair(v[i + 1].a - v[i + 1].c, i + 1), v[i + 1].c, ac);
		BC.del(make_pair(v[i + 1].b - v[i + 1].c, i+1), v[i + 1].c, bc);
		ans = max(ans, AC.calc() + BC.calc());
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 18292
import java.util.*;
public class Main {
    public static void main(String[] args) {	
	Main main = new Main();
    	main.solveC();
    }
    
    private void solveA() {
	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	System.out.println(A <= B ? A: A-1);
    }

    private void solveB() {
	Scanner sc = new Scanner(System.in);
	int[] n = new int[3];
	for(int i=0; i < 3; i++){
	    n[i] = sc.nextInt();	    
	}
	Arrays.sort(n);

	int k = sc.nextInt();

	for(int i=0; i < k; i++){
	    n[2] = n[2] * 2;	    
	}

	System.out.println(n[0] + n[1] + n[2]);
    }
    private void solveC() {
	Scanner sc = new Scanner(System.in);
	int h = sc.nextInt();
	int w = sc.nextInt();
	String[] n = new String[h+2];
	boolean b = true;

	n[0] = ".........................................................";
	n[h+1] = ".........................................................";

	for(int i=1; i < h+1; i++){
	    String s = sc.next();
	    n[i] = "."+ s + ".";
	}

	for(int i=1; i < h+1; i++){
	    for(int j=1; j < w+1; j++){
		if (n[i].charAt(j) == '#' && n[i-1].charAt(j) == '.'
		                   && n[i+1].charAt(j) == '.'
		                   && n[i].charAt(j-1) == '.'
		                   && n[i].charAt(j+1) == '.'){
		    b = false;
		}
	    }
	    
	}
	
	System.out.println(b ? "Yes" : "No");
    }
}

Measured memory_bytes: 21844
#include <cstdio>

using namespace std;

int main()
{
        int a, b, c;
        int cnt[100] = {0};

        scanf("%d%d%d", &a, &b, &c);
        cnt[a - 1]++; cnt[b - 1]++; cnt[c - 1]++;
        int ans = 0;
        for (int i = 0; i < 100; i++) {
                if (cnt[i] > 0) {
                        ans++;
                }
        }

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

        return 0;
}

Measured memory_bytes: 128
import collections
a,b,c = map(int,input().split())
lists = [str(a%2),str(b%2),str(c%2)]
abc = [a,b,c]
an = []
if len(set(lists)) != 1:

    d = collections.Counter(lists)
    jud = int(d.most_common()[0][0])
    for i in range(3):
        if jud == int(lists[i]):
            an.append(i)
    for i in an:
            abc[i] += 1
    cnt = 1
else:
    cnt = 0

while 1:
    Max = max(abc)
    count = 0
    for i in range(3):
        if Max == abc[i]:
            count += 1
    if count == 1:
        cnt += 1
        for i in range(3):
            if Max != abc[i]:
                abc[i] += 1

    elif count == 2:
        cnt += abs(max(abc) - min(abc)) // 2
        abc.sort()
        abc[0] += abs(max(abc) - min(abc))
    elif count == 3:
        break

print(cnt)


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

vector<int> adj[200000];
int update[200000],ans[200000];

void dfs(int cur,int par,int lst){
    ans[cur]=update[cur]+lst;
    for(int child:adj[cur]){
        if(child==par)continue;
        dfs(child,cur,ans[cur]);
    }
}

int main() {
    int n,q;cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        a--,b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<q;i++){
        int p,x;cin>>p>>x;
        p--;
        update[p]+=x;
    }
    dfs(0,-1,0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<" ";
    }
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

const int dx[] = { -1,0,1,0 }, dy[] = { 0,-1,0,1 };
int N, M, K;
vector<string> F;
int C[1000][1000], PS[1000][1000];

bool valid_coord(int x, int y, bool chk = true)
{
	if(chk) return 0 < x && x <= N && 0 < y && y <= N && C[x][y];
	return 0 < x && x <= N && 0 < y && y <= N;
}

int cnt(int x1, int y1, int x2, int y2)
{
	if (!valid_coord(x1, y1, false) || !valid_coord(x2, y2, false) || x1 > x2 || y1 > y2) return 0;
	return PS[x2][y2] - PS[x1 - 1][y2] - PS[x2][y1 - 1] + PS[x1 - 1][y1 - 1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	long long ans = 0;
	cin >> N >> M;
	F.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> F[i];
		for (int j = 0; j < M; j++) {
			C[M + i - j][i + j + 1] = F[i][j] == '#';
		}
	}
	N += M;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			PS[i][j] = C[i][j] + PS[i][j - 1] + PS[i - 1][j] - PS[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (valid_coord(i, j)) {
				for (int k = max(N - i, N - j); k; k--) {
					if (valid_coord(i + k, j)) {
						ans += cnt(i + 1, j - k, i + k, j - k);
						ans += cnt(i, j + k, i + k, j + k);
					}
					if (valid_coord(i, j + k)) {
						ans += cnt(i - k, j + 1, i - k, j + k - 1);
						ans += cnt(i + k, j, i + k, j + k);
					}
					ans -= valid_coord(i + k, j) && valid_coord(i, j + k);
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 6656
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val n = Integer.parseInt(sc.next())
    val pList = (0 until n).map { sc.nextInt() }
    var count = 0
    pList.forEachIndexed { i, pi ->
        if(i == 0 || i == pList.size -1) return@forEachIndexed
        if(listOf(pList[i - 1], pi, pList[i + 1]).sorted()[1] == pi) count++
    }
    println(count)
}

Measured memory_bytes: 34284
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let 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() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    s: chars,
  }
  let red = s.iter().filter(|&&c| c == '0').count();
  let blue = s.len() - red;
  let rem = if red > blue {
    red - blue
  } else {
    blue - red
  };

  puts!("{}\n", s.len() - rem);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
#define PI 3.14159265358979323846264338327950288419716939937510

int main() {
    int a,b,h,m;
    long double ans,angle;
    cin>>a>>b>>h>>m;
    angle=abs(30*h+3.0/6*m-6*m);
    //cout<<cos(angle*PI/180)<<endl;
    ans=sqrt(a*a+b*b-2*a*b*cos(angle*PI/180));
    cout.precision(20);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4092
import numpy as np

n, _ = map(int, input().split())
x = np.array([[int(i) for i in input().split()] for _ in range(n)])

c = [1 if np.linalg.norm(x[i]-x[j]).is_integer() else 0 for i in range(1, len(x)) for j in range(i)]
print(sum(c))

Measured memory_bytes: 21432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int a, b, c;
  cin >> a >> b >> c;

  string ans = "NO";
  for (int i = 1; i <= b; i++) {
    int mod = i * a % b;

    if (mod == c) ans = "YES";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define all(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int inf = 1 << 28;
const int N = 100010;
const double pi=acos(-1.0);
int n;
int num[N * 3];
ll Ml[N], Mr[N];
int main()
{
    int a, b;
    n = read();
    rep(i, 0, n * 3 - 1) num[i] = read();
    priority_queue<int, vector<int>, greater<int> > Q1;
    priority_queue<int> Q2;
    rep(i, 0, n - 1)
    {
        Ml[0] += num[i];
        Q1.push(num[i]);
        Mr[n + 1] += num[n * 3 - 1 - i];
        Q2.push(num[n * 3 - 1 - i]);
    }
    rep(i, 1, n)
    {
        Q1.push(num[n + i - 1]);
        Ml[i] = Ml[i - 1] + num[n + i - 1] - Q1.top();
        Q1.pop();
 
        Q2.push(num[n * 2 - i]);
        Mr[n + 1 - i] = Mr[n + 1 - i + 1] + num[n * 2 - i] - Q2.top();
        Q2.pop();
    }
    ll ans;
    rep(i, 0, n)
        if(!i) ans = Ml[i] - Mr[i + 1];
        else ans = max(ans, Ml[i] - Mr[i + 1]);
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 3956
#include <cstdio>

using namespace std;

#define N_MAX 100
#define M_MAX 100
#define INF '.'

int N, M;
char Field[N_MAX][M_MAX + 1] = {INF};

bool solve(int x, int y) {
	if(Field[x][y] == INF) return false;
    char tmp = Field[x][y];
    Field[x][y] = INF;

	int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
    int nx, ny;
    for(int i = 0; i < 4; i++) {
        nx = x + dx[i];
        ny = y + dy[i];
        if(nx < 0 || N <= nx || ny < 0 || M <= ny) continue;
    	if(Field[nx][ny] == tmp) solve(nx, ny);
    }
    return true;
}

int main(void) {
	int i, j;
	while(1) {
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
    	for(i = 0; i < N; i++) scanf("%s", Field[i]);
	
    	int count = 0;
    	for(i = 0; i < N; i++) {
        	for(j = 0; j < M; j++) {
            	if( solve(i, j) ) count++;
        	}
    	}
    	printf("%d\n", count);
		count = 0;
	}
    return 0;
}

Measured memory_bytes: 1816
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    ll n , a , b ;
    cin >> n >> a >> b ; 
    if(n*a > b)cout << b ; 
    else cout << a*n ; 
    
    
    



















return 0 ;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
signed main(){
	double a,b,c,d,e,f,g,h;
	while(cin>>a>>b>>c>>d>>e>>f>>g>>h){
		if(kosa(a,b,a+(g-a)*10000,b+(h-b)*10000,c,d,e,f)&&
		kosa(c,d,c+(g-c)*10000,d+(h-d)*10000,a,b,e,f)&&
		kosa(e,f,e+(g-e)*10000,f+(h-f)*10000,a,b,c,d))puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> ans(n,0);
	for(int i=1;i*i<=n;i++)
	for(int j=1;j*j<=n;j++)
	for(int k=1;k*k<=n;k++)
	{
		long long f=i*i+j*j+k*k+i*j+j*k+k*i;
		if(f<=n)
			ans[f-1]++;
	}

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

}

Measured memory_bytes: 3620
import math

A, B = map(int,input().split())

i = 1
c = 1
d = 0
while i > 0:
  if d > B:
    print(-1)
    break
  else:
    a = math.floor(c * 0.08)
    b = math.floor(c * 0.1)
    if a == A and b == B:
      print(c)
      break
    else:
      c += 1
      d = b

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
	lli x;
	cin>>x;
	double c=1.01;
	lli temp=(100*c);
	//cout<<temp;
	lli count=1;
	while(temp<x)
	{
		temp=(temp*c);
			//cout<<temp<<endl;
		count++;
	}
	cout<<count;
}


Measured memory_bytes: 3632
#最初の1文字をインプット
k=int(input())
#文字列を1文字ずつ配列としてインプット
s=list(input())

#確認用
#print(k)
#print(s)

if len(s) <= k: #配列sの文字数がk以下なら
    #print(s)
    print(''.join(s)) #join関数は.以前で指定した文字を結合する関数
else: #配列sの文字数がkを超えているなら
    new_s=s[0:k] #配列の最初からk番目までを切りとる
    new_s.append("...") #末尾に...を加える
    #print(new_s)
    print(''.join(new_s))

Measured memory_bytes: 61736
N = int(input())
S = str(input())

def Main(N, S):
    ans = 0
    mx = ans
    for c in S:
        if c == "I":
            ans += 1
        else:
            ans -= 1
        mx = max(mx, ans)
    return mx
        
res = Main(N, S)
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,mo=998244353,inf=1e9;
typedef long long LL;
struct Node{
	int x,d;
	bool operator < (const Node &b)const{
		return x>b.x;
	}
}a[N];
struct Tree{
	int mi;
	Tree *l,*r;
}*rt;
int f[N],L,R;
int query(Tree *p,int l,int r){
	if(!p)return inf;
	if(L<=l&&R>=r)return p->mi;
	int mid=(1ll*l+r)>>1,ans=inf;
	if(L<=mid)ans=min(ans,query(p->l,l,mid));
	if(R>mid)ans=min(ans,query(p->r,mid+1,r));
	return ans;
}
void change(Tree *&p,int l,int r){
	if(!p)p=new Tree{R,0,0};
	if(l==r)return;
	p->mi=min(p->mi,R);
	int mid=(1ll*l+r)>>1,ans=inf;
	if(L<=mid)change(p->l,l,mid);
	else change(p->r,mid+1,r);
}
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].d);
	sort(a+1,a+n+1);
	f[0]=1;
	for(int i=1;i<=n;i++){
		L=a[i].x+1e9+1,R=min(1ll*a[i].x+1e9+a[i].d,1ll+2e9);
		int w=min(i,query(rt,1,2e9+1));R=w;change(rt,1,2e9+1);
		f[i]=(f[i-1]+f[w-1])%mo;
	}
	printf("%d",f[n]);
	return 0;
} 

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

using namespace std;

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

    int n, m;

    cin >> n >> m;

    int x, y;
    vector<int> indeg(n + 1);
    vector<vector<int>> to(n + 1);

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        ++indeg.at(y);
        to.at(x).emplace_back(y);
    }

    vector<int> dp(n + 1);
    queue<int> q;

    for(int i = 1; i <= n; ++i) {
        if(indeg.at(i) == 0) {
            q.emplace(i);
        }
    }

    int qf, ans = 0;

    while(!q.empty()) {
        qf = q.front();
        q.pop();
        ans = max(ans, dp.at(qf));
        for(int qft: to.at(qf)) {
            dp.at(qft) = max(dp.at(qft), dp.at(qf) + 1);
            if(--indeg.at(qft) == 0) q.emplace(qft);
        }
    }

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

    return 0;
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    cout << string(tx - sx, 'R') << string(ty - sy, 'U');
    cout << string(tx - sx, 'L') << string(ty - sy, 'D');
    cout << 'D' << string(tx - sx + 1, 'R') << string(ty - sy + 1, 'U') << 'L';
    cout << 'U' << string(tx - sx + 1, 'L') << string(ty - sy + 1, 'D') << 'R';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const ll INF=10000000000LL;
const ll r197=1000000007;
typedef pair<ll,int>P;

typedef pair<int,P>Pa;
vector<P> v[100001];
int n,m;
ll dp[3003][3003];
string s,t;
struct edge{ll cost,num; };
ll reg(int a,int b){
	if(dp[a][b]!=-1){
		return dp[a][b];
	}
	if(a==n||b==m)return dp[a][b]=0;
	ll res=0;
	if(s[a]==t[b])res=1+reg(a+1,b+1);
	res=max(res,max(reg(a,b+1),reg(a+1,b)));
	return dp[a][b]=res;
}
int main() {
	memset(dp,-1,sizeof(dp));
	cin>>s>>t;
	n=s.size(),m=t.size();
	int v=reg(0,0);
	string str="";
	int c1=0,c2=0;

	while(v>0){
		if(dp[c1+1][c2+1]+1==v&&s[c1]==t[c2]){
			str+=s[c1];
			v--;
			c1++;
			c2++;
		}else{
			if(dp[c1+1][c2]==v){
				c1++;
			}else{
				c2++;
			}
		}
//		cout<<v<<endl;
	}
	cout<<str<<endl;
	return 0;
}


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

const int M = 2005;
const int N = 30005;
const int o = 15000;

bool ab[N],ac[N],bc[N];

bool match(char x,char y) {
    return x=='?' || y=='?' || x==y;
}

string a,b,c;
int la,lb,lc;

signed main() {
    ios::sync_with_stdio(false);
    cin>>a>>b>>c;
    la=a.length();
    lb=b.length();
    lc=c.length();
    for(int i=0;i<la;i++) for(int j=0;j<lb;j++)
        if(ab[i-j+o]==0&&!match(a[i],b[j])) ab[i-j+o]=1;
    for(int i=0;i<la;i++) for(int j=0;j<lc;j++)
        if(ac[i-j+o]==0&&!match(a[i],c[j])) ac[i-j+o]=1;
    for(int i=0;i<lb;i++) for(int j=0;j<lc;j++)
        if(bc[i-j+o]==0&&!match(b[i],c[j])) bc[i-j+o]=1;
    int ans=N;
    for(int i=-2*M;i<=2*M;i++) for(int j=-2*M;j<=2*M;j++) {
        if(!ab[i+o] && !ac[j+o] && !bc[j-i+o]) {
            ans=min(ans, max(la,max(lb+i,lc+j))-min(0,min(i,j)));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//caddi2018_a.cpp
//Sat Dec 22 20:47:24 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	int ans = 0;
	for (int i=0;i<s.length();i++){
		if (s[i]=='2'){
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter
N = int(readline())
C = Counter()

for _ in range(N):
    S = readline().strip()
    C[S] += 1

ma = max(C.values())
K = [k for k, v in C.items() if v == ma]
K.sort()
print('\n'.join(K))


Measured memory_bytes: 106584
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>	
#define inf INT_MAX
#define INF 9223372036854775807
#define rep(i,n) for(i=0;i<n;i++)

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}

int main(void){
	int a=in(),b=in(),t;
	t=a+b;
	if(t<10){
		print(t);
	}
	else{
		puts("error");
	}
	return 0;
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int H,W;
  cin>>H>>W;
  vector<string>s(H);
  for(int i=0;i<H;i++)cin>>s[i];
  int dx[4]={0,0,1,-1};
  int dy[4]={1,-1,0,0};
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      bool ok=false;
      if(s[i][j]=='#'){
        for(int k=0;k<4;k++){
          int X=j+dx[k];
          int Y=i+dy[k];
          if(0<=X&&X<W&&0<=Y&&Y<H&&s[Y][X]=='#')ok=true;
        }
        if(!ok){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


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

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

    while(input.hasNext()){
      int N = input.nextInt();
      String S = input.next();

      int[] countCharX = new int[26];
      int[] countCharY = new int[26];
      int maxDiff = 0;
      for(int i = 1; i < S.length() - 1; ++i){
        Arrays.fill(countCharX, 0);
        Arrays.fill(countCharY, 0);

        for(int j = 0; j < i; ++j){
          ++countCharX[S.charAt(j) - 'a'];
        }

        for(int j = i; j < S.length(); ++j){
          ++countCharY[S.charAt(j) - 'a'];
        }
        
        int bothContain = 0;
        for(int j = 0; j < countCharX.length; ++j){
          if(countCharX[j] != 0 && countCharY[j] != 0){
            ++bothContain;
          }
        }

        maxDiff = Math.max(maxDiff, bothContain);
     }
     System.out.println(maxDiff);
    } 
  }
}
    

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

int main() {
  string x;
  cin>>x;
  int len = x.length();
  int ans = 0;
  int cnt_s = 0;
  for (int i=0; i<len; i++) {
    if (x[i] == 'S') {
      ++cnt_s;
    } else {
      if (cnt_s > 0) {
        --cnt_s;
      } else {
        ++ans;
      }
    }
  }
  cout<<ans * 2<<endl;
}

Measured memory_bytes: 640
#coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    L = LMIIS()
    L.sort()
    count = 0
    for i in range(N):
        a = L[i]
        k = i+2
        for j in range(i+1,N):
            b = L[j]
            while k < N and a+b > L[k]:
                k += 1
            count += k - 1 - j
    print(count)



if __name__ == '__main__':
    main()

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


int find(int n)
{
  int sum = 0;
  while(n > 0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}


int main() {
  int N,A,B;
  cin >> N >> A >> B;

  int total = 0;
  for(int i = 1; i <= N; i++){//20までの整数
    int sum = find(i);
    if(A <= sum && sum <= B){
      total += i;
    }
  }
  cout << total << endl;


}





Measured memory_bytes: 3576
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> sum(n+1);
    rep(i, n) sum[i+1] = (sum[i] + a[i]) % m;
    map<int, ll> mp;
    ll ans = 0;
    rep(i, n+1) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7948
import java.awt.Polygon;
import java.awt.geom.Line2D;
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			while (n-- > 0) {
				int m = scanner.nextInt();
				Polygon[] polygons = new Polygon[m];
				Line2D[][] lines = new Line2D[m][4];
				for (int i = 0; i < m; i++) {
					int[] xx = new int[4];
					int[] yy = new int[4];
					for (int j = 0; j < 4; j++) {
						xx[j] = scanner.nextInt();
						yy[j] = scanner.nextInt();
					}
					for (int k = 0; k < 4; k++) {
						lines[i][k] = new Line2D.Double(xx[k], yy[k],
								xx[(k + 1) % 4], yy[(k + 1) % 4]);
					}
					polygons[i] = new Polygon(xx, yy, 4);
				}

				Unionfin unionfin = new Unionfin(m);
				for (int j = 0; j < m - 1; j++) {
					for (int j2 = j + 1; j2 < m; j2++) {
						if (unionfin.isSame(j, j2))
							continue;
						boolean flag = false;
						if (polygons[j].contains(polygons[j2].xpoints[0],
								polygons[j2].ypoints[0])
								|| polygons[j2].contains(
										polygons[j].xpoints[0],
										polygons[j].ypoints[0])) {
							flag = true;
						} else {
							for (int k = 0; k < 4; k++) {
								for (int k2 = 0; k2 < 4; k2++) {
									if (lines[j][k]
											.intersectsLine(lines[j2][k2])) {
										flag = true;
										break;
									}
								}
							}
						}
						if (flag)
							unionfin.unite(j, j2);
					}
				}
				System.out.println(unionfin.num);
			}
		}
	}

	class Unionfin {
		int[] rank, par;
		int num;

		Unionfin(int size) {
			rank = new int[size];
			par = new int[size];
			num = size;
			for (int i = 0; i < size; i++) {
				par[i] = i;
			}
		}

		int root(int x) {
			if (par[x] == x)
				return x;
			else
				return par[x] = root(par[x]);
		}

		boolean isSame(int x, int y) {
			return root(x) == root(y);
		}

		void unite(int x, int y) {
			x = root(x);
			y = root(y);
			if (x == y)
				return;
			if (rank[x] < rank[y])
				par[x] = y;
			else {
				par[y] = x;
				if (rank[x] == rank[y])
					rank[x]++;
			}
			num--;
		}

	}
}

Measured memory_bytes: 34376
var n,i:integer;
x:longint;
a:array[1..100]of longint;
procedure qsort(l,r:integer);
var i,j,k,mid:longint;
begin 
	i:=l;j:=r;
    mid:=a[(i+j) div 2];
    repeat
    	while a[i]<mid do inc(i);
        while a[j]>mid do dec(j);
        if i<=j then 
        begin 
        	k:=a[i];a[i]:=a[j];a[j]:=k;
            inc(i);
            dec(j);
        end;
    until i>j;
    if i<r then qsort(i,r);
    if j>l then qsort(l,j);
end;
begin 
	read(n);
    read(x);
    for i:=1 to n do read(a[i]);
    qsort(1,n);
    i:=1;
    while (x>0) and (i<=n) do
    begin 
    	x:=x-a[i];
        inc(i);
    end;
	if x=0 then write (i-1)
	else 
	write(i-2);
end.
    

Measured memory_bytes: 128
fun main(args: Array<String>) {
  var n = readLine()!!.toInt()
  val b = readLine()!!
  b.forEachIndexed { index, c ->
      if (index == b.length-1) {
          return@forEachIndexed
      }
      if (c == b[index + 1]) {
          n -= 1
      }
  }
  println(n)
}

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

#define grt long long

int order(const void* a, const void* b){
    int x = *((int *) a);
    int y = *((int *) b);

    return x-y;
}

int main(void){
    int n;
    scanf("%d", &n);

    grt a[n];
    for (int i = 0; i < n; i++) {
        scanf("%lli", &a[i]);
    }

    qsort(a, n, sizeof(a[0]), order);

    printf("%lli\n", a[n-1] - a[0]);



    return 0;
}


Measured memory_bytes: 128
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
for i in range(1, 10):
  for j in range(i, 10):
    a = str(i)
    b = str(j)
    for h in range(1,N+1):
      x = str(h)
      if x[0]==a and x[-1]==b:
        dic[(a,b)] += 1
      elif x[0]==b and x[-1]==a:
        dic[(b,a)] += 1

ans = 0
for a in range(1,10):
  for b in range(1, 10):
    a = str(a)
    b = str(b)
    ans += dic[(a,b)]*dic[(b,a)]
print(ans)

Measured memory_bytes: 44764
//Author:Nirmit Shah
//201701044
//Daiict,Gandhinagar
 
#include<bits/stdc++.h>
using namespace std;
 
//Macros
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define error std::cerr
#define INF LONG_LONG_MAX
//#define MINF=LONG_LONG_MIN
#define MOD 1000000007
#define pii pair<int,int>
#define forn(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define ull unsigned long long
 
//Debugging
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
 
#define all(c) c.begin(),c.end()
 
ll min(ll x,ll y)
{
    if(x>y)
        return y;
    return x;
}
 
ll max(ll x,ll y)
{
    if(x>y)
        return x;
    return y;
}
 
ll gcd(ll x,ll y)
{
    if(!x)
        return y;
    return gcd(y%x,x);
}
 
ll calcpower(ll x, ll y)
{
    ll ans = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            ans = (ans*x) % MOD;
 
            y = y>>1;
            x = (x*x) % MOD;
    }
    return ans;
}
 
/*bool prime[1000005];
void Sieve(ll n)
{
    for(int i=0; i<1000005; i++)
        prime[i] = true;
    prime[1] = false;
    prime[0] = false;
 
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p])
        {
            for (ll i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
}*/

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 100005;
ll pre[maxn];
ll inv[maxn];
ll prei[maxn];
void build(int n){
    pre[1] = pre[0] = 1, inv[1] = inv[0] = 1, prei[1] = prei[0] = 1;
    for(int i = 2 ; i <= n ; i++){
        pre[i] = pre[i-1] * i % mod;
        inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
        prei[i] = prei[i-1] * inv[i] % mod;
    }
}
ll C(int n, int k){
   return pre[n] * prei[k] % mod * prei[n-k] % mod;
}
ll pm(int n,int p){
    ll ret = 1;
    ll now = n;
    while(p){
        if(p & 1){
            ret *= now;
            ret %= mod;
        }
        now *= now;
        now %= mod;
        p >>= 1;
    }
    return ret;
}
void go() {
    ll n;
    cin >> n;
    cout << ((pm(10,n) - pm(9,n) * 2 + pm(8,n)) % mod + mod) % mod << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cout<<elem;}cerr<<endl;}

//解説参考.
int main(){
	int h,w,k;
	cin>>h>>w>>k;
	
	vvi dp(h+1,vi(w,0));//dp[i][j]:=(深さiのときj番目にいる場合の数).
	dp[0][0]=1;
	for(int i=1;i<=h;++i)REP(l,1<<(w-1))REP(j,w){
		bool jud=true;//正しいあみだくじ.
		REP(m,w-2){
			if(l>>m&1 and l>>(m+1)&1) jud=false;
		}
		
		if(jud){
			if(0<l and l>>(j-1)&1) dp[i][j-1]=(dp[i][j-1]+dp[i-1][j])%MOD;		//左に遷移.
			else if(j<w-1 and l>>j&1) dp[i][j+1]=(dp[i][j+1]+dp[i-1][j])%MOD;	//右に遷移.
			else dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;							//下に遷移.
		}
	}
	
	cout<<dp[h][k-1]<<endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <map>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
map<string,int>ma;
int main()
{
    ios::sync_with_stdio(false);
    int n,ans=0;
    cin>>n;
    For(i,1,n)
    {
        string s;
        cin>>s;
        if(!ma.count(s))
        {
            ma[s]=1;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int n;
ll k;

vector<int> a,f;

bool ok(ll x){
  ll sum = 0;
  for(int i = 0; i < n; ++i){
    sum += max((ll)0,a[i]-(x/f[i]));
  }
  
  return sum <= k;
}



int main(){
  cin >> n >> k;
  a.resize(n);
  f.resize(n);
  cin >> a >> f;
  sort(f.begin(),f.end());
  sort(a.begin(),a.end(),greater<int>());
  ll l = -1, r = 2000000000000;
  while(abs(r-l)>1){
    ll mid = (l+r)/2;
    if(ok(mid))r = mid;
    else  l = mid;
  }
  cout << r << endl;
  return 0;  
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
vector<int> pre,in,post;
int n,x,p=0; //p一定要设置成全局变量 
void reconstruct(int l,int r){
	 int c,m;
	 if (l>=r)
	    return;
	 c=pre[p++];
	 for (int i=0; i<n; i++)
	     if (in[i]==c){
	     	 m=i; break;
		 }
     reconstruct(l,m);
	 reconstruct(m+1,r);
	 post.push_back(c);		
}
int main(){
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>x;
		pre.push_back(x);
	}
	for (int i=0; i<n; i++){
		cin>>x;
		in.push_back(x);
	}   
    reconstruct(0,n);
    cout<<post[0];
    for (int i=1; i<n; i++)
        cout<<" "<<post[i];
    cout<<'\n';
	return 0;
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

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

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	ll MAX = 1e7;
	vector<vector<ll> > C(26);
	string s; getline(cin,s);
	string t; getline(cin,t);
	int l =  s.length();
	int T = t.length();
	REP(i,26){
	    C[i].PB(-1);
	}

	REP(i,l){
		char c = s[i];
		C[c - 'a'].PB(i);
	}

	REP(i,26){
		C[i].PB(MAX);
	}

	ll npos = -1;
	ll round = 0;

	REP(i,T){
		char c = t[i];
		int cnum = c - 'a';
		if (C[cnum].size() == 2){
			cout << -1 << endl;
			return 0;
		}

		auto It = upper_bound(C[cnum].begin(),C[cnum].end(),npos);
		if (*It < MAX){
			npos = *It;

		}else{
			npos = C[cnum][1];
			round++;
		}
	}

	cout << round * l + npos + 1 << endl;

}


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

int main(){
    int n;
    cin >> n;
    deque<int> b;
    rep(i, n) {
        int a;
        cin >> a;
        if (i%2==n%2) {
            b.push_back(a);
        } else {
            b.push_front(a);
        }
    }
    rep(i, n) {
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S, T;
    cin >> S >>T;
    int N = S.size();
    
    string ans = "No";
    string now = S;
    for(int i = 0; i < N; i++) {
        if(now==T) {
            ans = "Yes";
            break;
        }
        now = now.at(N-1) + now;
        now.erase(now.begin()+N);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
    ll n,k,i,ans=0;
    cin>>n>>k;
    ll ara[n+1];
    for(i=1;i<=n;i++)cin>>ara[i];
    sort(ara+1,ara+n+1);
    for(i=1;i<=k;i++)
    {
       ans+=ara[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <cstdio>
using namespace std;
int main() {
    char s[5];
    scanf("%s",s);
    int t=0;
    if(s[0]=='o')
        t++;
    if(s[1]=='o')
        t++;
    if(s[2]=='o')
        t++;
    printf("%d\n",700+100*t);
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


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

int main()
{
    int input;
    cin >> input;

    int first = 1;
    int second = 1;
    
    for (int i = 2; i <= input; ++i) {
        int third = first + second;
        first = second;
        second = third;
    }
    cout << second << "\n";
    
    return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define debug(x) cerr<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
#define debug2(a,x) cerr<<#a<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
using namespace std;
const int maxn=2100;
int n,d;
int x[20][20];
bool check(int x){
	int tmp=sqrt(x);
	for(int i=tmp-1;i<=tmp+1;i++)
		if(i*i==x)return true;
	return false;
}
int main(){
	cin>>n>>d;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			cin>>x[i][j];
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			int tmp=0;
			for(int k=1;k<=d;k++){
				tmp+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			if(check(tmp))ans++;
		}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

struct segtree{
  int n;
  vector<ll> dat;
  segtree(int n_){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.resize(2*n-1);
    for(int i=0;i<2*n-1;i++) dat[i]=0;
  }
  void update(int k,ll a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
  }
  ll get(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0) r=n;
    if(r<=a||b<=l) return 0;
    if(a<=l&&r<=b) return dat[k];
    else{
      ll vl=get(a,b,k*2+1,l,(l+r)/2);
      ll vr=get(a,b,k*2+2,(l+r)/2,r);
      return max(vl,vr);
    }
  }
};


int main(){
  int n; cin >> n;
  vector<ll> h(n),a(n);
  rep(i,n){
    cin >> h[i];
    h[i]--;
  }
  rep(i,n) cin >> a[i];
  segtree dp(n);
  ll ans=0;
  rep(i,n){
    ll A=dp.get(0,h[i]);
    if((dp.get(h[i],h[i]+1)<A+a[i])){
      dp.update(h[i],A+a[i]);
      chmax(ans,A+a[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void  solve(){
    char n;
    cin>>n;
    n = n+1;
    cout<<n;
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = a + b;
            
            int f = 1;
            int e = c / 10;
            while (0 < e) {
                e = e / 10;
                f = f + 1;
            }
            
             System.out.println(f);
        }
      
    }
}



Measured memory_bytes: 26216