akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
    int M,N,K;
    scanf("%d %d %d",&M,&N,&K);
    char po[1919][1919];
    for(int i=0;i<M;i++){
        scanf("%s",po[i]);
    }
    int buri[3][1919][1919]={};
    //for(int i=0;i<3;i++)for(int j=0;j<1919;j++)for(int k=0;k<1919;k++){buri[i][j][k]=0;}
    for(int i=0;i<M;i++){for(int j=0;j<N;j++){
        if(po[i][j]=='J')buri[0][i+1][j+1]=1;
        if(po[i][j]=='O')buri[1][i+1][j+1]=1;
        if(po[i][j]=='I')buri[2][i+1][j+1]=1;
    }}
    for(int i=0;i<3;i++)for(int j=0;j<1919;j++)for(int k=0;k<1910;k++){buri[i][j][k+1]+=buri[i][j][k];}
    for(int i=0;i<3;i++)for(int j=0;j<1910;j++)for(int k=0;k<1919;k++)buri[i][j+1][k]+=buri[i][j][k];
    for(int i=0;i<K;i++){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        for(int j=0;j<3;j++){
            printf("%d",buri[j][c][d]-buri[j][c][b-1]-buri[j][a-1][d]+buri[j][a-1][b-1]);
            if(j!=2)printf(" ");
            else printf("\n");
        }
    }
    return 0;
}



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

using ll = long long;
// #define int long long
using P = pair<int, int>;
#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int H, W;
  cin >> H >> W;
  int coins[H][W];
  REP(i,H) {
    REP(j,W) {
      cin >> coins[i][j];
    }
  }
  int count = 0;
  vector<P> command;
  REP(y,H) {
    REP(x,W) {
      int cur_y = y;
      int cur_x = x;
      if(cur_y%2) cur_x = W - 1 - x;
      if(coins[cur_y][cur_x]%2 == 0) continue;
      int next_y;
      int next_x;
      if(cur_x == 0) {
        if(W == 1) {
          next_y = cur_y + 1;
          next_x = cur_x;
        } else if(cur_y%2) {
          next_y = cur_y+1;
          next_x = cur_x;
        } else {
          next_y = cur_y;
          next_x = cur_x+1;
        }
      } else if(cur_x == W-1) {
        if(cur_y%2) {
          next_y = cur_y;
          next_x = cur_x - 1;
        } else {
          next_y = cur_y + 1;
          next_x = cur_x;
        }
      } else {
        if(cur_y%2) {
          next_y = cur_y;
          next_x = cur_x - 1;
        } else {
          next_y = cur_y;
          next_x = cur_x + 1;
        }
      }
      if(next_x >= W || next_y >= H) continue;
      ++count;
      --coins[cur_y][cur_x];
      ++coins[next_y][next_x];
      command.PB(P(cur_y+1,cur_x+1));
      command.PB(P(next_y+1,next_x+1));
    }
  }
  cout << count << endl;
  REP(i,count) {
    COUTS(command[i*2].first);
    COUTS(command[i*2].second);
    COUTS(command[i*2+1].first);
    COUTB(command[i*2+1].second);
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 5104
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let s = input_line_str();
    //let table = vec!["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];

    let ans = match &s[..] {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => 0,
    };
    p(ans);
}


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

typedef pair<int, int> Position;

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char> > A(H, vector<char>(W));
    vector<vector<int> > reach(H, vector<int>(W));
    queue<Position> q;

    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){    
            cin >> A[i][j];
            if(A[i][j] == '#'){
                q.push(make_pair(i,j));                
                reach[i][j] = 0;
            }else{
                reach[i][j] = -1;
            }
        }
    }

    while(!q.empty()){
        Position p = q.front();
        q.pop();
        int x = p.first; int y = p.second;
        
        if(x + 1 < H && A[x + 1][y] != '#' && reach[x + 1][y] == -1){
            reach[x + 1][y] = reach[x][y] + 1;
            q.push(make_pair(x + 1, y));
        }   
        if(0 <= x - 1 && A[x - 1][y] != '#' && reach[x - 1][y] == -1){
            reach[x - 1][y] = reach[x][y] + 1;
            q.push(make_pair(x - 1, y));
        }
        if(y + 1 < W && A[x][y + 1] != '#' && reach[x][y + 1] == -1){
            reach[x][y + 1] = reach[x][y] + 1;
            q.push(make_pair(x, y + 1));
        }
        if(0 <= y - 1 && A[x][y - 1] != '#' && reach[x][y - 1] == -1){
            reach[x][y - 1] = reach[x][y] + 1;
            q.push(make_pair(x, y - 1));
        }
    }

    int ans = 0;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            ans = max(ans, reach[i][j]);
            // cout << reach[i][j];
        }
        // cout << endl;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int input() {int a;cin>>a;return a;}

int n,a,f,ans,hoge=INF;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        ans += abs(a);
        if (a < 0) {
            f = (f+1)%2;
        }
        hoge = min(hoge,abs(a));
    }
    if (f) ans -= hoge*2;
    cout << ans << endl;
}




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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int a,b,x;cin>>a>>b>>x;

	double ans = 0.0;

	if(a*a*b > 2*x){
		double t = (double)x*2/a/b;
		double beta = atan((double)t/b);
		printf("%0.8lf\n",  (double)90.0 - (beta* (180.0)/M_PI) );
	}else{
		double V = a*a*b-x;
		double t = (double)V*2/a/a;
		double alpha = atan((double)t/a);
		// cout << V << " " << t << endl;
		printf("%0.8lf\n", (double)alpha * (180.0)/M_PI );
	}


	return 0;
}




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

int main(void)
{
    long long int a,b,c,i,j,k,n;
    string s;
    cin >> s;
    for(i=0;i<2;i++){
        for(j=i;j<3;j++){
            if(s.at(i)>s.at(j)){
                swap(s.at(i),s.at(j));
            }
        }
    }
    if(s=="abc") cout << "Yes";
    else cout << "No";
    return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'i' || c == 'u' || c == 'o' || c == 'e') {
    cout << "vowel";
  } else {
    cout << "consonant";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>

using namespace std;

int V,E;
int map[15][15];
int dp[1<<15][15];

int saiki(int vis,int pos){

    int r = 1<<28;
    if(dp[vis][pos] != -1) return dp[vis][pos];
    if(pos == 0 && vis == (1<<V)-1){
       	return 0;
    }
    for(int i=0;i<V;i++){
	if(map[pos][i] != -1 && !(vis & (1<<i)) ){
	    r = min(r,saiki( vis | (1<<i) ,i) + map[pos][i]);
	
	}
    }

    return dp[vis][pos] = r;
}
int main(){

    int s,t;
    cin >> V >> E;
    fill(&map[0][0],&map[15][0],-1);
    for(int i=0;i<E;i++){
	cin >> s >> t;
	cin >> map[s][t];
    }
    fill(&dp[0][0],&dp[1<<15][0],-1);

    int res = saiki(0,0);

    if(res >= 1<<28) res = -1;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3084
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let mut ans = 0;
    let n = s.len();
    for i in 0..n / 2 {
        if s[i] != s[n - 1 - i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			
			String s = sc.next();
			
			int len = s.length();
			int cnt = 0;
			char[] sChars = s.toCharArray();
			
			for(int i=0;i<len;i++) {
				cnt= cnt+Character.getNumericValue(sChars[i]);		
			}
			
			if(Math.floorMod(cnt,9)==0) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
				
			}
	}	
}

Measured memory_bytes: 40700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,l[100];
  cin >> n >> k;
  for(int i=0; i<n; i++){
    cin >> l[i];
  }
  
  sort(l,l+n,greater<int>());
  
  int total=0;
  
  for(int i=0; i<k; i++){
    total = total+l[i];
  }
  
  cout << total << endl;
}

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

int n,k;
long long ans,p[2010][2010];

long long combi(int a, int b) {
    if((b==0) || (a==b)){return 1;}
    if(p[a][b]!=0){return p[a][b];}
    ans=combi(a-1,b-1)+combi(a-1,b);
    ans%=1000000007;
    p[a][b]=ans;
    return ans;
}

int main(){
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        if(n-k<i-1){
            cout<<0<<endl;
            continue;
        }
        ans=combi(k-1,i-1)*combi(n-k+1,i);
        ans%=1000000007;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 29696
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
 
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second
 
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>
 
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>
 
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n
 
const ll HMOD = (ll)1e9 + 7;
const ll LMOD = 998244353;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
const long double EPS = 1e-10;
 
void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}
 
void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}
 
void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main(){
  string s;
  cin >> s;
  ll c;
  cin >> c;
  c =min(c,(ll)s.size());
  REP(i,c){
    if (s[i] != '1'){
      cout << s[i]<<endl;
      return 0;
    }
  }
  cout << 1 <<endl;
  return 0;

}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

int main() {
  int A, B, result = 1;
  cin >> A >> B;
  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }
  while ((A - 1) * result < B - 1) {
    result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	int tmp = n / 2;
	if (n % 2) tmp++;
	double ans = (double)tmp / n;
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int main(){
    int N;
    while(cin >> N && N > 0) {
        vector<double> X(N);
        vector<double> R(N);
        REP(i, N) cin >> X[i] >> R[i];

        double lb = 0, ub = 100000;
        REP(_, 80) {
            double h = (lb + ub) / 2;
            vector<pair<double, int>> ev;
            REP(i, N) if(h <= R[i]) {
                double d = sqrt(R[i] * R[i] - h * h);
                ev.push_back(make_pair(X[i] - d, 0));
                ev.push_back(make_pair(X[i] + d, 1));
            }
            sort(ev.begin(), ev.end());

            double last = 0;
            int cnt = 0;
            double max_len = 0;
            for(auto e : ev) {
                if(e.second == 0) {
                    if(++cnt == 1) {
                        last = e.first;
                    }
                } else {
                    if(--cnt == 0) {
                        max_len = max(max_len, e.first - last);
                    }
                }
            }
            assert(cnt == 0);

            if(max_len >= 2.0 * h) {
                lb = h;
            } else {
                ub = h;
            }
        }

        printf("%.12f\n", 2.0 * lb);
    }

    return 0;
}

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

using namespace std;

const int MOD=1e9+7;

//const int MOD=998244353;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<int> v(n);
    for(int&i:v) cin>>i;
    
    vector<long long> dp(2e5+1);
    
    dp[v[0]]=1;
    for(int i=1; i<n; i++){
        if(v[i]!=v[i-1]){
            dp[v[i]]+=dp[v[i-1]];
            dp[v[i]]%=MOD;
        }
    }
    cout<<dp[v[n-1]];
    
    
}

Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define nmax 100010

int n, k;
int a[nmax][3], dp[nmax][3];

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

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

    for (int i = 1; i <= n; i++) 
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);

    printf("%d\n", max({ dp[n][0], dp[n][1], dp[n][2] }));

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include<math.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 PI 3.14159265358979323846264338327950


int main () {
    ll a, b, k;
    cin >> a >> b >> k;
    if (a > k){
        a = a - k;
    }
    else if (a + b > k){
        b = b - (k - a );
        a = 0 ;
    }
    else {
        a = 0;
        b = 0;
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
using namespace std;
int main(){
int a,b;
cin>>a>>b;
printf("%.6f",a*b/3.305785);
}

Measured memory_bytes: 1192
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
void main()
{
    readln;
    immutable
        a = readln.chomp.split.to!(uint[]),
        sumall = a.reduce!((p, q) => p ^ q);
    "%(%d %)".writefln(a.map!(e => e ^ sumall));
}


Measured memory_bytes: 11028
#include<stdio.h>
typedef long long LL;
const int sz=2e5;
int A[sz]={0},here[sz]={0},town[sz]={0};
inline LL IN(void)
{
  LL x=0;int f=1;char c=getchar();
  while((c<'0'||c>'9')&&c!='-')c=getchar();
  if(c=='-')f=-f,c=getchar();
  while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();
  return f*x;
}
int main(void)
{
  int N,i,j,x;LL K;
  N=IN(),K=IN();
  for(i=0;i<N;i++)A[i]=IN(),here[i]=-1;
  for(i=0,j=0;;i=A[i]-1,j++)if(here[i]<0)here[i]=j,town[j]=i;else{x=here[i];break;}
  if(K>=j)K=(K-x)%(x-j)+x;
  return printf("%d\n",town[K]+1),0;
}

Measured memory_bytes: 3844
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <functional>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

template <typename T>
using V = vector<T>;

int main() {
	for (int px, py; px = in, py = in, px || py;) {
		int n {in};
		V<V<V<bool>>> s(n, V<V<bool>>(14, V<bool>(14)));
		for (auto &i: s) {
			int x {(int)in + 1}, y {(int) in + 1};
			for (int j = max(2, x); j < min(12, x + 3); j++)
				for (int k = max(2, y); k < min(12, y + 3); k++)
					i[k][j] = true;
		}
		function<bool(int, int, int)> dfs = [&](int i, int x, int y) {
			if (i == n)
				return true;
			static const int dx[] = {0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1},
							 dy[] = {-2, -2, -1, 0, 1, 2, 2, 2, 1, 0, -1, -2};
			for (int j: range(12))
				if (s[i][y + dy[j]][x + dx[j]] && dfs(i + 1, x + dx[j], y + dy[j]))
					return true;
			return false;
		};
		outl(dfs(0, px + 2, py + 2) ? "OK": "NA");
	}
}


Measured memory_bytes: 2444
n = int(input())
a = [int(input()) for i in range(n)]

even_num = set((a[i] for i in range(0,n) if i % 2 == 0))

a.sort()

odd_num = set((a[i] for i in range(0, n) if i % 2 == 1))

count = len(even_num & odd_num)
print(count)


Measured memory_bytes: 13860
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n, m, a;

vector<int> vo, ve, res;

int main() {
    GI(n); GI(m);

    FORN(i, m) {
        GI(a);
        if (a % 2 == 1) {
            vo.PB(a);
        }
        else {
            ve.PB(a);
        }
    }

    if (vo.size() > 2) {
        printf("Impossible\n");
        return 0;
    }
    else if (vo.size() == 2) {
        printf("%d ", vo[0]); if (vo[0] > 1) res.PB(vo[0] - 1);
        for (auto e : ve) { printf("%d ", e); res.PB(e); }
        res.PB(2);
        printf("%d\n", vo[1]); if (vo[1] > 1) res.PB(vo[1] - 1);

        cout << res.size() << "\n";
        for (auto r : res) cout << r << " "; cout << "\n";
    }
    else if (vo.size() == 1) {
        printf("%d ", vo[0]); if (vo[0] > 1) res.PB(vo[0] - 1);
        for (auto e : ve) { printf("%d ", e); res.PB(e); }
        res.PB(1);
        printf("\n");
        
        cout << res.size() << "\n";
        for (auto r : res) cout << r << " "; cout << "\n";
    }
    else {
        for (auto e : ve) printf("%d ", e);
        printf("\n");
        
        printf("%d\n", ve.size() + 1);
        printf("%d ", ve[0] - 1);
        for (int i = 1; i < ve.size(); i++) printf("%d ", ve[i]);
        printf("%d\n", 1);
    }

    return 0;
}

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const ld inf = 3e18 ;
const int N = 15 + 2 , MASK = (1 << 15) + 20 ;
int n , x[N] , y[N] , a[N] ;
ld sum[MASK] , mst[MASK] , res[MASK] ;

inline ld dist (int i , int j) {
	ld dx = x[i] - x[j] , dy = y[i] - y[j] ;
	return sqrt(dx * dx + dy * dy) ;
}

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

	cin >> n ;

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

	for (int mask = 0 ; mask < (1 << n) ; mask ++) {
		for (int i = 0 ; i < n ; i ++)
			if (mask >> i & 1) sum[mask] += a[i] ;

		if (__builtin_popcount(mask) <= 1) continue ;

		mst[mask] = inf ;

		for (int leaf = 0 ; leaf < n ; leaf ++) {
			if (!(mask >> leaf & 1)) continue ;

			for (int par = 0 ; par < n ; par ++) {
				if (!(mask >> par & 1) || leaf == par) continue ;

				mst[mask] = min(mst[mask] , dist(leaf , par) + mst[mask ^ (1 << leaf)]) ;
			}
		}
	}

	for (int mask = 1 ; mask < (1 << n) ; mask ++) {
		int k = __builtin_popcount(mask) ;

		res[mask] = (sum[mask] - mst[mask]) / k ;

		for (int sub = (mask - 1) & mask ; sub ; sub = (sub - 1) & mask) {
			res[mask] = max(res[mask] , min(res[sub] , res[mask ^ sub])) ;
		}
	}

	cout << fixed << setprecision(10) << res[(1 << n) - 1] << '\n' ;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int cnt = 0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(x==(500*i+100*j+50*k)) cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass

N, M = map(int, input().split())

divisors = divisor(M)

ans = 1
divisors.sort()

for d in divisors:
  if N*d <= M:
    ans = d

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int K = 0;
vector<VI> G(100010);
int N;

map<pii, int>res;
bool F[100010] = { false };

void dfs(int v, int cnt) {
	F[v] = true;

	REP(i,G[v].size()){

		int to = G[v][i];
		int u = v;

		if (to < v)swap(u, to);

		if (F[G[v][i]])continue;

		if (!F[G[v][i]]) {
			res[pii(u, to)] = cnt % K;
		//	cout << v << " " << G[v][i] <<" "<< cnt << endl;
			dfs(G[v][i], (cnt + 1)%K);
		}
		cnt++;

	}
	return;
}




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

	cin >> N;
	vector<pii>out;
	map<int, int>mp;
	REP(i, N-1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		out.push_back(pii(a, b));
		mp[a]++;
		mp[b]++;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int tmp;
	REP(i, N) {
		if (K < mp[i]) {
			K = max(K, mp[i]);
			tmp = i;
		}
	}
	dfs(tmp,0);

	cout << K << endl;
	REP(i, N-1) {
		cout << res[out[i]] +1 << endl;
	}

	return 0;
}



Measured memory_bytes: 20724
#include<bits/stdc++.h>
using namespace std;
vector<bool> mark(1e6+7,true);
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int N;
	cin>>N;
	vector<int> v(N);
	unordered_set<int> s;
	for(int &x: v)
	{
		cin>>x;
		if(s.count(x))mark[x]=false;
		else s.insert(x);
	}
	int ans = 0;
	int max = *max_element(v.begin(),v.end());
	for(int i=0;i<N;i++)
		for(int j = 2*v[i];j<=max;j+=v[i])
			mark[j]=false;
			
	for(int i=0;i<N;i++)
		if(mark[v[i]])ans++;
		
	cout<<ans<<'\n';
}


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

typedef double f64;
typedef long long i64;
typedef int i32;
typedef pair<i32, i32> pi32;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef vector<i32> vi32;
typedef deque<i32> di32;

#define all(c) (c).begin(), (c).end()
#define REP(i, a, b) for (auto i = a; i < b; i++)
#define REPA(i, a, b, acc) for (auto i = a; i < b; i += acc)
#define PB push_back
#define PF push_front
#define PRINT(x) cout << #x ": " << (x) << endl;
#define TR(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); (it)++)
#define MAX_PRECISION cout << setprecision(numeric_limits<double>::max_digits10);

i32 main() {
  ios::sync_with_stdio(false);  // Makes IO faster, remove this line if C style scanf/printf needed.

  i32 n;
  cin >> n;
  vi32 v(n);

  REP(i, 0, n) {
    cin >> v[i];
  }
  i32 ret = 0;
  REP(i, 0, n) {
    i32 c;
    cin >> c;
    v[i] -= c;
    if (v[i] > 0) ret += v[i];
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let v:Vec<&str> = buf.trim().split('/').collect();
	let mut x:Vec<i32> = Vec::new();
	for i in 0..3 {
		x.push(v[i].parse().ok().unwrap());
	}
	if x[0] > 2019 ||  x[1] > 4 || x[2] > 30{
		println!("TBD");
	}else{
		println!("Heisei");
	}
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


ll calc(ll x){
    ll res = 1;
    for(int i = 0; i < 5; i++){
        res *= x;
    }
    return res;
}

int main(){
    ll x;   cin >> x;
    for(ll a = 0; calc(a) <= 2 * x + 10; a++){
        for(ll b = 0; b <= a; b++){
            if(calc(a) + calc(b) == x){
                cout << a << " " << -b << endl;
                return 0;
            }
        }
    }

    ll a = 0;
    while(true){
        for(ll b = 0; b < a; b++){
            if(calc(a) - calc(b) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
        a++;
    }
    

    return 0;
}


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

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

	string sub1 = S.substr(0, ((int)S.size() - 1) / 2);
	string sub2 = S.substr(((int)S.size() + 3) / 2 - 1, ((int)S.size() - 1) / 2);

	bool flag = true;
	for (int i = 0; i < S.size() / 2; i++)
	{
		if (S[i] != S[S.size() - 1 - i])flag = false;
	}
	for (int i = 0; i < sub1.size() / 2; i++)
	{
		if (sub1[i] != sub1[sub1.size() - 1 - i])flag = false;
	}
	for (int i = 0; i < sub2.size() / 2; i++)
	{
		if (sub2[i] != sub2[sub2.size() - 1 - i])flag = false;
	}

	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input().strip())
xl = [list(map(int, input().split())) for i in range(n)]
lst=[[0]*2 for _ in range(n)]

for i in range(n):
    lst[i][0]=xl[i][0]-xl[i][1]
    lst[i][1]=xl[i][0]+xl[i][1]

lst.sort(key=lambda x: x[1])
ans=0
last=-10**10
for i in range(n):
    if last <= lst[i][0]:
        ans+=1
        last=lst[i][1]
print(ans)

Measured memory_bytes: 42620
#include<stdio.h>

int main(){
	long long n, a, b;
	long long ans;

	scanf("%lld %lld %lld", &n, &a, &b);

	if((b-a)%2 == 0){
		ans = (b-a)/2;
	}else{
		ans = ((a-1 < n-b) ? a-1 : n-b) + 1 + (b-a-1)/2;
	}
	printf("%lld", ans);

	return 0;
}


Measured memory_bytes: 128
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(0, N):
    result = input().strip()
    if result == 'AC':
        ac += 1
    elif result == 'WA':
        wa += 1
    elif result == 'TLE':
        tle += 1
    elif result == 'RE':
        re += 1

print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))




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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int h[n];
  rep(i, n) cin >> h[i];

  int dp[n];
  dp[0] = 0;

  for (int i = 1; i < n; ++i) {
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    if (i - 2 >= 0) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }

  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int num;
    cin >> num;
    int ans = 0;
    for(int i = 1; i <= num; ++i){
        for(int j = 1; j <= num; ++j){
            int tmp = 0;
            tmp = gcd(i, j);
            for(int k = 1; k <= num; ++k){
                ans += gcd(tmp, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
def main():
    from bisect import bisect_left
    I=10**9+1
    n,q,*t=map(int,open(0).read().split())
    d=tuple(t[-q:])
    t=t[:-q]
    N0=2**(q-1).bit_length()
    data=[I]*2*N0
    for x,l,r in sorted(((x,bisect_left(d,s-x)+N0,bisect_left(d,t-x)+N0)for s,t,x in zip(t[::3],t[1::3],t[2::3])),reverse=1):
        while l<r:
            if r&1:
                r-=1
                data[r-1]=x
            if l&1:
                data[l-1]=x
                l+=1
            l//=2
            r//=2
    a=[]
    for k in range(N0-1,q+N0-1):
        s=I
        while~k:
            if data[k]<s:s=data[k]
            k=(k-1)//2
        a.append(-(s==I)or s)
    print('\n'.join(map(str,a)))
if __name__=='__main__':
    main()

Measured memory_bytes: 166364
"""
成績をSにできるか？という二分探索をするのがよさそう。
S秒以内に全員が食べ終わった状態でいる必要がある。
S/xをすることで、各メンバーのキャパシティが見えてくる。
あとは「食べ物をどう割り当てるか」だけどこれは貪欲的にキャパシティの小さい順に、食べづらさの小さい食べ物を割り当てればOK。
もし、キャパシティが足りない場合はK回までxを調整して、キャパシティを計算しなおす。
計算量としては、O(log(10**12)N)で間に合う。

"""

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort(reverse=True)
F.sort()
from math import ceil

def is_ok(S):
    tmpK = K
    for i in range(N):
        f = F[i]
        a = A[i]
        if S//a < f:
            x = ceil(a-S/f)
            tmpK -= x
        if tmpK < 0:
            return False
    return True

def bisearch(high,low):
    while high - low > 1:
        mid = (high+low)//2
        if is_ok(mid):
            high = mid
        else:
            low = mid
    return high

print(bisearch(max(A)*max(F),-1))

Measured memory_bytes: 113868
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    List<Number> tails = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      if (tails.isEmpty() || tails.get(tails.size() - 1).num >= a[i]) {
        tails.add(new Number(a[i]));
      } else {
        Number num = lowerBound(tails, a[i]);
        num.num = a[i];
      }
    }
    System.out.println(tails.size());
  }

  private static Number lowerBound(List<Number> a, int k) {
    int left = -1;
    int right = a.size();
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (k > a.get(mid).num) {
        right = mid;
      } else {
        left = mid;
      }
    }
    if (right == a.size()) return null;
    return a.get(right);
  }

  private static class Number {
    private int num;
    public Number(int num) {
      this.num = num;
    }
  }
}


Measured memory_bytes: 51960
#include <bits/stdc++.h>
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
	cin >> N >> K;
	vector<int> g(N);
	vector<int> a(N);
	map<int, vector<int>> mp;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		mp[a[i]].push_back(i);
	}
	for (auto kv : mp) {
		auto v = kv.second;
		for (int i = 0; i < v.size(); i++) {
			if (i == v.size() - 1) {
				if (v[0] == N - 1) {
					g[v[i]] = 0;
				}
				else {
					g[v[i]] = v[0] + 1;
				}
			}
			else {
				if (v[i + 1] == N - 1) {
					g[v[i]] = 0;
				}
				else {
					g[v[i]] = v[i + 1] + 1;
				}
			}
		}
	}
	set<int> st;
	int prev = 0;
	int loop_ind;
	int loop_dist = 0;
	st.insert(0);
	while (1) {
		if (g[prev] - prev == 1||prev - g[prev]==N-1) {
			loop_dist += N + 1;
		}
		else if (g[prev] > prev) {
			loop_dist += g[prev] - prev;
		}
		else {
			loop_dist += (N - prev) + g[prev];
		}
		if (st.count(g[prev]) == 1) {
			loop_ind = g[prev];
			break;
		}
		else {
			st.insert(g[prev]);
			prev = g[prev];
		}
	}
	ans = (N * K - 1) % loop_dist;
	int tmp = 0;
	prev = 0;
	int mem = 0;
	int mem_ans = 0;
	while (ans > tmp) {
		mem_ans = tmp;
		if (g[prev] - prev == 1||prev-g[prev]==N-1) {
			tmp += N + 1;
		}
		else if (g[prev] > prev) {
			tmp += g[prev] - prev;
		}
		else {
			tmp += (N - prev) + g[prev];
		}
		mem = prev;
		prev = g[prev];
	}
	vector<int> res;
	set<int> st1;
	int now  = mem;
	ans -= mem_ans;
	for (int i = 0; i <= ans; i++) {
		if (st1.count(a[now]) == 1) {
			while (st1.count(a[now])==1) {
				int end = res.size() - 1;
				st1.erase(res[end]);
				res.pop_back();
			}
		}
		else {
			st1.insert(a[now]);
			res.push_back(a[now]);
		}
		now++;
		if (now >= N) {
			now = 0;
		}
	}
	for (int i = 0; i < res.size(); i++) {
		cout << res[i];
		if (i == res.size() - 1) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}
}



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

const ll MX = 1e18;

int main()
{
    int n;
    cin >> n;
    long long sum = 1,a;
    bool ng = false;
    rep(i, n) {
        cin >> a;

        if (a == 0) {
            cout << 0 << endl;
            return 0;
        }

        if (ng || (MX / a) < sum) {
            ng = true;
        }
        sum *= a;
    }

    if(ng)
        cout << -1 << endl;
    else
        cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3632
from itertools import permutations
from math import sqrt

N = int(input())
lst = [list(map(int, input().split())) for _ in range(N)]
path = list(permutations(list(range(N))))

s = 0 #合計
for p in path:
    before = [lst[p[0]][0], lst[p[0]][1]]
    for i in range(1, N):
        s += sqrt((lst[p[i]][0] - before[0])**2 + (lst[p[i]][1] - before[1])**2)
        before[0] = lst[p[i]][0]
        before[1] = lst[p[i]][1]

#n!の計算
n = 1
for i in range(1, N+1):
    n *= i

print(s/n)

Measured memory_bytes: 13740
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int w, h;
vector< vector<int> > s;
vector< vector<int> > sum;
int dp[1005][1005];

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

template<typename T>
bool chmin(T &_a, T _b){
    if(_a > _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

int solve(int i, int j){
    if(dp[i][j] < IINF){
        return dp[i][j];
    }else if(i == h && j == w){
        return dp[i][j] = 0;
    }

    int res;
    if((i + j) % 2 == 0){
        res = -IINF;
        if(i + 1 <= h) chmax(res, solve(i + 1, j) + (sum[i + 1][w] - sum[i + 1][j] - sum[i][w] + sum[i][j]));
        if(j + 1 <= w) chmax(res, solve(i, j + 1) - (sum[h][j + 1] - sum[h][j] - sum[i][j + 1] + sum[i][j]));
    }else{
        res = IINF;
        if(i + 1 <= h) chmin(res, solve(i + 1, j) + (sum[i + 1][w] - sum[i + 1][j] - sum[i][w] + sum[i][j]));
        if(j + 1 <= w) chmin(res, solve(i, j + 1) - (sum[h][j + 1] - sum[h][j] - sum[i][j + 1] + sum[i][j]));
    }

    return dp[i][j] = res;
}

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

    cin >> w >> h;

    s.resize(h);
    sum.resize(h + 1);
    sum[0].resize(w + 1);
    rep(i, h){
        s[i].resize(w);
        sum[i + 1].resize(w + 1);
        rep(j, w){
            cin >> s[i][j];
            sum[i + 1][j + 1] = s[i][j];
        }
    }

    rep(i, h + 1){
        reps(j, w){
            sum[i][j] += sum[i][j - 1];
        }
    }

    rep(j, w + 1){
        reps(i, h){
            sum[i][j] += sum[i - 1][j];
        }
    }

    fill(dp[0], dp[1005], IINF);

    cout << abs(solve(0, 0)) << endl;

    return 0;
}


Measured memory_bytes: 14720
from collections import Counter

kyougi, iin = list(map(int, input().split(' ')))

kyougi_costs = {}
for i in range(1, kyougi+1):
    kyougi_costs[i] = int(input())

iin_likes = {}
for i in range(1, iin+1):
    iin_likes[i] = int(input())

vote = []
for iin, like in iin_likes.items():
    max_interest = -1
    tmp_kyougi = []
    for kyougi, cost in kyougi_costs.items():
        if like >= cost:
            tmp_kyougi.append(kyougi)
    vote.append(min(tmp_kyougi))

c = Counter(vote)
for key, value in c.items():
    if value == max(c.values()):
        print(key)


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n]={};
    for(int i = 1; i < n; i++) {
        int tmp;
        cin >> tmp;
        a[tmp-1]++;
    }
    for(int i = 0; i < n; i++) {
        cout << a[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 4428