akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int n;
vector<int> g[100];
vector<int> w[100];
int d[100];
char color[100];

bool bellman() {
    for (int i = 0; i < n; ++i) {
        d[i] = INT_MAX;
    }
    d[0] = 0;

    for (int j = 0; j < n ; ++j) {
        for (int i = 0; i < n; ++i) {
            for (int k = 0; k < g[i].size(); ++k) {
                int v = g[i][k];
                if(d[i] != INT_MAX && d[v] > d[i] + w[i][k]) {
                    d[v] = d[i] + w[i][k];
                    if(j == n - 1) return true;
                }
            }
        }
    }
    return false;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        int k;
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; ++j) {
            cin >> v >> c;
            g[u].push_back(v);
            w[u].push_back(c);
        }
    }

    bool neg = bellman();

    for (int j = 0; j < n; ++j) {
        if (d[j] == INT_MAX) cout << "INF" << endl;
        else
            cout << j << " " << d[j] << endl;

    }

    return 0;
}



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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int a, p; cin >> a >> p;

	a = a*3;
	int z = a+p;
	cout << z/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class City {
    public:
    int num, point;
    string name;
    City(int n, int p, string s):
    num(n), point(p), name(s) {}
    bool operator < (const City &c) const {
        if (name == c.name) return point > c.point;
        return name < c.name;
    }
};
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<City> v;
    int a;
    string s;
    for (int i = 0; i < N; i++) {
        cin >> s >> a;
        v.push_back(City(i, a, s));
    }
    sort(v.begin(), v.end());
    for (auto c : v) {
        cout << c.num + 1 << '\n';
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main()
{
long int n,i,sum=0;
scanf("%ld",&n);
i=n;
while(i!=0)
{
    sum+=i%10;
    i/=10;
    
}
if(n%sum==0)
{
    printf("Yes");
}else{
    printf("No");
}
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define int ll
int n,m;
vvi G;
vi used,in,tmp;
int dfs(int a,int b=0){
	tmp.pb(a);
	used[a]=b;
	rep(i,G[a].size()){
		int to=G[a][i];
		if(used[to]==2){
			if(!dfs(to,b^1))return 0;
		}else if(used[to]==b)return 0;
	}
	return 1;
}
signed main(){
	cin>>n>>m;
	G=vvi(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	used=vi(n,2);
	in=vi(n);
	ll sum=0;
	rep(i,n)if(used[i]==2){
		tmp=vi(0);
		if(!dfs(i)){
			cout<<-1<<endl;
			return 0;
		}
		ll co=0;
		rep(j,tmp.size())if(used[tmp[j]]==1)co++;else co--;
		in[abs(co)]++;
		sum+=abs(co);
	}
	vi dp(100010,-1);
	dp[0]=0;
	rep(i,n)if(in[i])rep(j,100010){
		if(dp[j]>=0)dp[j]=in[i];
		else if(j<i||dp[j-i]<=0)dp[j]=-1;
		else dp[j]=dp[j-i]-1;
	}
	ll t=INF;
	rep(i,100010)if(dp[i]>=0)t=min(t,abs(i-(sum-i)));
	cout<<(n*n-t*t)/4-m<<endl;
}

Measured memory_bytes: 10480
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>

using namespace std;

class Point{
public:
    double x, y;
    Point(double x, double y){
        this->x = x;
        this->y = y;
    }
};

int main(){
    int n; cin >> n;
    vector<Point*> vec(n);
    for(int i = 0; i < n; i++){
        double x, y; cin >> x >> y;
        Point* p = new Point(x, y);
        vec[i] = p;
    }
    double ans = 0.0;
    for(auto p: vec){
        for(auto j: vec){
            if(p->x == j->x && p->y == j->y) continue;
            ans += sqrt(pow((p->x - j->x), 2) + pow((p->y - j->y), 2));
        }
    }
    printf("%f", ans/n);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

long long isprime(long long x) {

	if (x == 2) { return true; }
	if (x < 2 || x % 2 == 0) { return false; }

	long long     sqrtx = sqrt(x);//xの平方根を取得

	long long     i = 3;

	while (i <= sqrtx) {

		if (x % i == 0) { return false; }

		i += 2;
	}

	return true;
}


int main() {

	ll n;

	cin >> n;

	ll m = n;

	if (isprime(n)) {
		cout << '1' << endl;
		return 0;
	}

	vector <pair<ll, int>> fs;

	for (ll i = 2; i*i <= m; i++) {
		int x = 0;
		while (n % i == 0) {
			n /= i; x++;
		}
		fs.emplace_back(i, x);
	}
	if (n != 1)fs.emplace_back(n, 1);

	ll ans = 0;

	for (auto p : fs) {
		ll a = p.second;
		ll b = 1;
		while (b <= a) {
			a -= b;
			b++;
			ans++;
		}

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

Measured memory_bytes: 19716
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
na, nb, nm = i2()
a = intl()
b = intl()
mp = min(a)+min(b)
for i in range(nm):
    x , y , c = i2()
    p = a[x-1]+b[y-1]-c
    if (p) < mp:
        mp = p
print(mp)

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

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

void printArray(const int *arr, int n);
void printArray(const vector<int> &arr);

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
char s[102];

int val(const char *s){
    return (s[0] -'0')*10 + s[1] -'0';
}

bool inrange(int val){
    return val >= 1 && val <=12;
}

int main(){
    scanf("%s", s);
    int a = val(s);
    int b = val(s+2);
    if(inrange(a) && inrange(b)){
        puts("AMBIGUOUS");
    }
    else if(inrange(a)){
        puts("MMYY");
    }
    else if(inrange(b)){
        puts("YYMM");
    }
    else{
        puts("NA");
    }
	return 0;
}

/* Template Function */
void printArray(const int * a, int n){
	for(int i=0;i<n;++i){
		printf("%d ", a[i]);
	}
	puts("");
}

void printArray(const vector<int> &arr){
	for(int x : arr){
		printf("%d ", x);
	}
	puts("");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,s[101];
    bool flag=true;
	cin>>a;
	for(int i=0;i<a;i++)
	{
		cin>>s[i];
		if(s[i]%2==0&&s[i]%3!=0&&s[i]%5!=0) flag=false; 
	}
	if(flag) cout<<"APPROVED";
	else cout<<"DENIED"; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
LL n, q, x, w[N], p[N];
stack<LL> s;
vector<LL> v;
void solve(LL pos, LL W) {
    int x = lower_bound(v.begin(), v.end(), pos) - v.begin() - 1;
    if (x<0) {
        p[1] += W;
        p[pos+1] -= W;
        return;
    }
    w[x] += pos / v[x] * W;
    solve(pos % v[x], W);
}
int main() {
    scanf("%lld%lld", &n, &q);
    s.push(n);
    for (int i = 1; i <= q; i++) {
        scanf("%lld", &x);
        while (s.size() && s.top() >= x) s.pop();
        s.push(x);
    }
    while (s.size()) {
        v.push_back(s.top());
        s.pop();
    }
    reverse(v.begin(), v.end());
    w[v.size() - 1] = 1;
    for (int i = v.size() - 1; ~i; i--) solve(v[i], w[i]);
    for (int i = 1; i <= n; i++) p[i] += p[i - 1];
    for (int i = 1; i <= n; i++) printf("%lld\n", p[i]);
    return 0;
}

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

public class P
{
    public long a { get; set; }
    public long b { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var ps2= new P[n];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var w1 = long.Parse(line[0]);
            var w2 = long.Parse(line[1]);
            ps2[i] = new P { a = w1, b = w2 };
        }
        var ps = ps2.OrderBy(x => x.a).ToArray();
        getAns(ps, n, m);
    }
    static void getAns (P[] ps , int n, int m)
    {
        var t = 0L;  var tp = 0L;
        for (int i = 0; i < n; i++)
        {
            var w = tp + ps[i].b;
            if (w < m) { t += ps[i].a * ps[i].b; tp += ps[i].b;   }
            else
            {
                t += ps[i].a * (m - tp);
                Console.WriteLine(t);
                return;
            }
        }
    }
}

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

int main() {
    int m,n;
    cin>>n>>m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i) {
        cin>>a[i];
    }
    int ans=0;
    for (int i = 0; i < m; ++i) {
        if(a[i]>m)++ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3100
// Problem : E - This Message Will Self-Destruct in 5s
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

const int N = 2e5 + 5;
int n, a[N];
std::map<int, int> b, c;

int main() {
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ans += b[i - a[i]] + c[a[i] + i];
    ++b[i + a[i]], ++c[i - a[i]];
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 38472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans = 0;
    ll m=2;
    ans += a[0]-1;
    for(int i=1;i<n;i++){
        if(m!=a[i]){
            ans+=a[i]/m;
            if(a[i]%m==0){
                ans -= 1;
            }
        }else{
            m++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
from sys import stdin
N = int(stdin.readline().rstrip())
nums = [int(stdin.readline().rstrip()) for _ in range(N)]

minimum = nums[0]
ans = (10**9)*-1
for i in range(1, N):
    ans = max(ans, nums[i]-minimum)
    minimum = min(minimum, nums[i])
print(ans)


Measured memory_bytes: 13624
#include<cstdio>
#include<iostream>
using namespace std;
int d,t,s;
int main()
{
	scanf("%d%d%d",&d,&t,&s);
	int tmp=d/s;
	if(d%s)++tmp;
	if(tmp<=t)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {

   int N,K;
   cin >> N >> K;

   int d;
   int test;
   set<int> sss;
   for(int i=0; i<K;i++){
      cin >> d;
      for(int j=0; j<d;j++){
         cin >> test;
         sss.insert(test);
      }
   }
   int A[N];
   for(int i=0;i<N+1;i++ ){
      A[i]=0;
   }
   for(auto itr = sss.begin(); itr != sss.end(); ++itr){
      A[*itr]=1;	
   }
   int sum=0;
   for(int i=1;i<N+1;i++ ){
      if(A[i]==0){
         sum++;
      }
   }
   cout << sum << endl;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int a[200200];
int main(){
    int k, n, maxdis = 0;
	scanf(" %d %d", &k, &n);
	for(int i = 0; i < n; i++){
        scanf(" %d", &a[i]);
	}
	sort(a, a+n);
	maxdis = max(maxdis, a[0]+k-a[n-1]);
	for(int i = 1; i < n; i++){
        maxdis = max(maxdis, a[i]-a[i-1]);
	}
	printf("%d\n", k-maxdis);
}


Measured memory_bytes: 1024
import sys
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse = True)

A += [0]
count = 1
lst = []
for i in range(1, N+1):
    if A[i] == A[i-1]:
        count += 1
    else:
        lst += [[A[i-1], count]]
        count = 1

ans = 1
flag = 0
for i in range(len(lst)):
    if lst[i][1] >= 2:
        ans *= lst[i][0]
        flag += 1
        if flag == 2:
            print (ans)
            sys.exit()
        if lst[i][1] >= 4:
            ans *= lst[i][0]
            print (ans)
            sys.exit()

print (0)


Measured memory_bytes: 17296
#include <iostream>

#include <vector>

#include <algorithm>
#include <functional>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::greater;
using std::sort;

static int
solve(int N, int K, vector<int> &l)
{
  sort(l.begin(), l.end(), greater<int>());
  int ret = 0;
  for (int i = 0; i < K; i++)
  {
    ret += l[i];
  }
  return ret;
}

int
main()
{
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int n = 0; n < N; n++)
  {
    cin >> l[n];
  }
  cout << solve(N, K, l) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

string n;

int main(){

    cin >> n;

    for(int i = 0; i < n.length(); i++){
        if(n[i] == '9'){
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";


}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<long long> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  long long mx=v[0];
  long long ans=0;
  for(int i=1;i<n;i++)
  {
    if(v[i]<mx) ans+=mx-v[i];
    mx=max(mx,v[i]);
  }
  cout<<ans;
  return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    string a, s(w+2,'#');
    cout << s << endl;
    for (int i = 0; i < h; i++) {
        cin >> a;
        cout << '#' + a + '#' << endl;
    }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>

/**------------ SUB ROUTIONE -------------*/
/**------------ SUB ROUTIONE -------------*/

int main()
{
	int i,k;
	int a,b;

	/**--init --**/
	for (a=1,i=1 ; i<10 ; i++,a++) {
		for (b=1,k=1 ; k<10 ; k++,b++) {
			printf("%dx%d=%d\n",a,b,a*b);
		}
	}
	return 0;
}

Measured memory_bytes: 920
#include <iostream>
#include <string>
#include <vector>
// #include <cxx-prettyprint/prettyprint.hpp>

using namespace std;

int main(int argc, char const *argv[])
{
    long long int MOD = 1000000000 + 7;
    string s;
    cin >> s;
    vector<vector<long long int>> dp(s.length(), vector<long long int>(13, 0));
    for (int i = 0; i < s.length(); i++) {
        if (i == 0) {
            if (s[i] == '?') {
                for (int j = 0; j <=9; j++) {
                    dp[i][j] = 1LL;
                }
            } else {
                int j = (int) (s[i] - '0');
                dp[i][j] = 1LL;
            }
        } else {
            for (int j = 0; j < 13; j++) {
                if (s[i] == '?') {
                    for (int k = 0; k <= 9; k++) {
                        int j_now = (j * 10 + k) % 13;
                        dp[i][j_now] += dp[i - 1][j];
                        dp[i][j_now] %= MOD;
                    }
                } else {
                    int k = (int) (s[i] - '0');
                    int j_now = (j * 10 + k) % 13;
                    dp[i][j_now] += dp[i - 1][j];
                    dp[i][j_now] %= MOD;
                }
            }
        }
        // for (auto d: dp) {
        //     for (auto _: d) {
        //         cout << _ << ", ";
        //     }
        //     cout << endl;
        // }
        // cout << endl;
    }
    cout << dp[s.length() - 1][5] << endl;
    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n;
    cin >> n;
    vector<int> a1(n), a2(n);
    rep(i, n) {
        cin >> a1[i];
    }
    rep(i, n) {
        cin >> a2[i];
    }
    vector<int> s1(n+1), s2(n+1);
    rep(i, n+1) {
        if (i == 0) {
            s1[i] = s2[i] = 0;
        } else {
            s1[i] = s1[i-1] + a1[i-1];
            s2[i] = s2[i-1] + a2[i-1];
        }
    }
    int ans = 0;
    rep(i, n+1) {
        if (i == 0) continue;
        int cnt = 0;
        cnt += s1[i] - s2[0];
        cnt += s2[n] - s2[i-1];
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

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

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 


int main() {
    ios_base::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if (a < 1 || a > 9 || b < 1 || b > 9) {
        cout << -1 << '\n';
    }
    else cout << a*b << '\n';
    return 0;

    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  string S;
  int Q;
  cin >> S;
  cin >> Q;

  int operation;

  int F;
  char C;
  
  // ---------------------
  //
  deque<char> deq;

  for (int i = 0; i < S.size(); i++) {
    deq.push_back(S[i]);
  }

  int rev_flag = 1;

  for (int i = 0; i < Q; i++) {

    cin >> operation;
    
    if(operation == 1) {
      rev_flag *= -1;
    }
    
    else if (operation == 2){
      cin >> F >> C;
      
      if (F == 1) {
	if (rev_flag == 1) deq.push_front(C);
	else deq.push_back(C);

      }
      else if (F == 2) {
	if (rev_flag == 1) deq.push_back(C);
	else deq.push_front(C);
      }
    }
    
  }

  if (rev_flag == 1) {
    
    for(int i = 0; i < deq.size(); i++) {
      cout << deq[i];
    }
    cout << endl;
    
  }
  else if (rev_flag == -1) {

    for(int i = deq.size() - 1; i >= 0; i--) {
      cout << deq[i];
    }
    cout << endl;

  }
  
  return 0;
  
}


Measured memory_bytes: 1104
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

int b[110];
int a[110];
int cnt[100010];

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;

    for (int i = 1; i <= N - 1; ++i)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            cnt[i + 1] = cnt[i] + 1;
        }
        else
        {
            cnt[i + 1] = cnt[i];
        }
        //cout << cnt[i] << endl;
    }

    for (int i = 0; i < Q; ++i)
    {
        int l, r;
        cin >> l >> r;

        cout << cnt[r] - cnt[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1488
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int x, a, b;
	cin >> x >> a >> b;

	if (b <= a)
	{
		cout << "delicious";
	}
	else if ((a+x) >= b)
	{
		cout << "safe";
	}
	else
	{
		cout << "dangerous";
	}
	cout << endl;
	
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  vector<int> dp(h + 1);
  for(int i = 1; i <= h; ++i) {
    dp[i] = 1e9;
    for(int j = 0; j < n; ++j) {
      dp[i] = min(dp[i], (i - a[j] <= 0 ? 0 : dp[i - a[j]]) + b[j]); 
    }
  }
  cout << dp[h] << '\n';
}

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

int main()
{
    int e[12];

    for ( int i = 0; i < 12; i++ ) cin >> e[i];

    sort(e, e + 12);

    if ( e[0] == e[1] && e[1] == e[2] && e[2] == e[3] &&
         e[4] == e[5] && e[5] == e[6] && e[6] == e[7] &&
         e[8] == e[9] && e[9] == e[10] && e[10] == e[11] )
    {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }

    return ( 0 );
}



Measured memory_bytes: 3180
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      char[][] grid = new char[h][w];
      for(int i = 0; i < h; i++)
        grid[i] = sc.next().toCharArray();
      int[][] cnt = new int[h][w];
      if(grid[0][0] == '#')
        cnt[0][0] = 1;
      for(int i = 1; i < w; i++) {
        if(grid[0][i] == '.')
          cnt[0][i] = cnt[0][i-1];
        else {
          if(grid[0][i-1] == '#')
            cnt[0][i] = cnt[0][i-1];
          else
            cnt[0][i] = cnt[0][i-1] + 1;
        }
      }

      for(int i = 1; i < h; i++) {
        if(grid[i][0] == '.')
          cnt[i][0] = cnt[i-1][0];
        else {
          if(grid[i-1][0] == '#')
            cnt[i][0] = cnt[i-1][0];
          else
            cnt[i][0] = cnt[i-1][0] + 1;
        }
      }

      for(int i = 1; i < h; i++) {
        for(int j = 1; j < w; j++) {
          if(grid[i][j] == '.') {
            cnt[i][j] = Math.min(cnt[i-1][j], cnt[i][j-1]);
          } else {
            int up = cnt[i-1][j];
            if(grid[i-1][j] == '.')
              up++;
            int left = cnt[i][j-1];
            if(grid[i][j-1] == '.')
              left++;
            cnt[i][j] = Math.min(up, left);
          }
        }
      }

      System.out.println(cnt[h-1][w-1]);
  }
}


Measured memory_bytes: 22996
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long K = Long.parseLong(sc.next());
        int[] A = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(A);

        long ok_key = 2_000_000_000_000_000_000L;
        long ng_key = -2_000_000_000_000_000_000L;
        while (Math.abs(ok_key-ng_key)>1) {

            long key = (ok_key+ng_key)/2;

            long cnt = 0L;
            for (int i=0;i<N-1;i++) {
                if (A[i]>=0) {
                    int ok = i;
                    int ng = N;
                    while (Math.abs(ok-ng)>1) {
                        int mid = (ok+ng)/2;
                        if ((long)A[mid]*A[i]<=key) {
                            ok = mid;
                        } else {
                            ng = mid;
                        }
                    }
                    cnt+=ok-i;
                } else { // A[i]<0
                    int ok = N;
                    int ng = i;
                    while (Math.abs(ok-ng)>1) {
                        int mid = (ok+ng)/2;
                        if ((long)A[mid]*A[i]<=key) {
                            ok = mid;
                        } else {
                            ng = mid;
                        }
                    }
                    cnt+=N-ok;
                }
                // System.out.println("ok: "+ok);
                // System.out.println("ok_cnt: "+(i));
            }

            if (cnt>=K) {
                ok_key = key;
            } else {
                ng_key = key;
            }
            // System.out.println("key, cnt: "+key+" "+cnt);
        }
        System.out.println(ok_key);
    }
}

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

int main() {
  int n, a, b;
  a =0, b=0;
  cin>>n;
  
  vector<int>vect(n);
  for(int i = 0; i<n; i++){
    cin>> vect.at(i);
  }
  
  sort(vect.begin(), vect.end());  
  reverse(vect.begin(), vect.end());
  
  for(int i = 0; i<n; i +=2){
    a += vect.at(i);
  }
    for(int i = 1; i<n; i +=2){
    b += vect.at(i);
  }
  
  cout<< a - b<< endl;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int c[20];
  rep(i, m) cin >> c[i];
  int dp[100010];
  fill(dp, dp + 100010, INF);
  dp[0] = 0;
  for (int i = 1; i <= n; ++i)
  {
    rep(j, m)
    {
      if (i - c[j] >= 0)
        dp[i] = min(dp[i], dp[i - c[j]] + 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}



Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
  int N;
  int c;
  int i, j;
  int count[100001] = {0};
  int value;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    scanf("%d", &c);
    count[c] = 1;
  }

  value = 0;
  for(i = 0; i < 100001; i++) {
    value += count[i];
  }
  if(value%2 == 0) {
    printf("%d\n", value-1);
  } else {
    printf("%d\n", value);
  }
  return 0;
}

Measured memory_bytes: 640
n = int(input())
h = list(map(int, input().split()))
ans = 1
for i in range(1, n):
  f = 0
  for j in range(i): 
    if f == 0:
      if h[j] <= h[i]:
        next
      else:
        f = 1
  if f == 0:
    ans += 1
print(ans)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, X, Y := getInt(), getInt()-1, getInt()-1
	a := make([]int, N)
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			x := j - i
			y := abs(X-i) + abs(Y-j) + 1
			// out(i, j, x, y, "->", min(x, y))
			a[min(x, y)]++
		}
	}

	for i := 1; i < N; i++ {
		out(a[i])
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto &x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

//=========================

void run_test() {
	int L, R, D;
	cin >> L >> R >> D;
	int ans = 0;
	for(int d = L; d <= R; d++) if(d % D == 0) ans++;
	cout << ans << endl;
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 3620
N = int(input())
 
num_list = []
for _ in range(N):
    num_list.append(int(input()))
    
num_sorted = sorted(num_list)
 
def calc_diff(add, add2, diff, diff2, num_sorted):
    total = 0
    
    for _ in range(add2):
        tmp = num_sorted.pop()
        total += tmp * 2
        
    for _ in range(add):
        tmp = num_sorted.pop()
        total += tmp * 1
        
    for _ in range(diff):
        tmp = num_sorted.pop()
        total -= tmp * 1
            
    for _ in range(diff2):
        tmp = num_sorted.pop()
        total -= tmp * 2
        
    return total
  
import copy
 
def calc(N, num_sorted):
    
    diff2 = 0
    add2 = 0
    diff = 0
    add = 0
    
    if N % 2 == 0:
        add = 1
        diff = 1
        add2 = N // 2 - 1
        diff2 = N // 2 - 1
        
        total = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
 
        return total
            
    if N % 2 == 1:        
        add = 0
        diff = 2
        add2 =(N - 1) // 2
        diff2 = (N - 1) // 2 - 1
        
        totalB = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
        
        add = 2
        diff = 0
        add2 =(N - 1) // 2 - 1
        diff2 = (N - 1) // 2
        
        totalC = calc_diff(add, add2, diff, diff2, copy.deepcopy(num_sorted))
        
        return max(totalB, totalC)
      
print(calc(N, num_sorted))

Measured memory_bytes: 9444
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	int N;
	cin >> N;
	int ans, num;
	rep(i, N)
	{
		cin >> num;
		if (i == 0)ans = num;
		else
		{
			ans = gcd(ans, num);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

ans = 'YES'
d = defaultdict(int)
for i in a:
    if d[i] == 1:
        ans = 'NO'
        break
    d[i] = 1

print(ans)

Measured memory_bytes: 58324
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll a, b;
    cin>>a>>b;
    for(ll i=1; i<=1e5+10; i++)
    {
        if((ll)(i*0.08)==a&&(ll)(i*0.1)==b)
        {
            cout<<i;
            return;
        }
    }
    cout<<-1;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
typedef long long lint;
const int N=1e5+5;
int n;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

namespace G{
	int dis[N];
	bool vis[N];
	struct edge{
		int to,wi;
	};
	std::vector <edge> g[N],vg[N];

	inline void add(const int a,const int b,const int v){
		g[a].push_back((edge){b,v});
		vg[b].push_back((edge){a,v});
	}

	bool dfs(const int x){
		vis[x]=1;
		for(std::vector <edge> ::iterator it=g[x].begin(); it!=g[x].end(); ++it){
			const int y=it->to,d=dis[x]+it->wi;
			if(!vis[y]&&!(dis[y]=d,dfs(y))) return 0;
			if(dis[y]!=d) return 0;
		}
		for(std::vector <edge> ::iterator it=vg[x].begin(); it!=vg[x].end(); ++it){
			const int y=it->to,d=dis[x]-it->wi;
			if(!vis[y]&&!(dis[y]=d,dfs(y))) return 0;
			if(dis[y]!=d) return 0;
		}
		return 1;
	}

	bool build(){
		for(int i=1; i<=n; ++i){
			if(!vis[i]&&!dfs(i)) return 0;
		}
		return 1;
	}
}

int main(){
	n=nxi();
	for(int i=nxi(); i; --i){
		const int a=nxi(),b=nxi();
		G::add(a,b,nxi());
	}
	puts(G::build()?"Yes":"No");
	return 0;
}


Measured memory_bytes: 16128
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
  
    int n;
    cin>>n;

    string s = "Christmas";
    string t = "Eve";

    for(int i=25;i>n;i--){
        s += " ";
        s += t;
    }

    cout<<s;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    bool first = false;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a % 2 == 1)
            first = true;
    }

    cout << (first ? "first" : "second") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;

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

	int n; 
	ll k;
	cin >> n >> k;

	ll *a, *f;
	a = new ll[n];
	f = new ll[n];
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> f[i];

	sort(a, a + n);
	sort(f, f + n);

	ll l = -1, r = 1e12+1;
	ll mid;
	while (l + 1 != r) {
		mid = (l + r) / 2;

		ll counter = 0;
		rep(i, n) {
			if (a[i] * f[n - 1 - i] > mid) counter += a[i] - mid / f[n - 1 - i];
			if (counter > k) break;
		}

		if (counter > k)l = mid;
		else r = mid;
	}

	cout << r << "\n";

	delete[] a;
	delete[] f;

	return 0;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int D;
  cin >> D;
  vector<int64_t> C(26);
  rep(i, 26) { cin >> C[i]; }

  vector<vector<int64_t>> S(D, vector<int64_t>(26));
  rep(i, D) {
    rep(j, 26) {
      int s;
      cin >> s;
      S[i][j] = s;
    }
  }

  vector<int> T(D);
  vector<int> Last(26, 0);
  rep(i, D) {
    vector<int64_t> score(26);
    int64_t max_score = 0;
    int max_idx = 0;
    rep(j, 26) {
      score[j] = S[i][j] + C[j] * (i + 1 - Last[j]);
      if (max_score < score[j]) {
        max_score = score[j];
        max_idx = j;
      }
    }
    T[i] = max_idx + 1;
    Last[max_idx] = i + 1;
  }

  rep(i, D) { cout << T[i] << endl; }
  return 0;
}


Measured memory_bytes: 3744
n = int(input())
A = list(map(int, input().split()))
count = 1
direction = 0
for a, b in zip(A, A[1:]):
	dif = b - a
	if direction == 0 and dif != 0:
		direction = dif // abs(dif)
	elif (direction == 1 and dif < 0) or (direction == -1 and dif > 0):
		count += 1
		direction = 0
print(count)

Measured memory_bytes: 62704
import sys

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


input = sys.stdin.readline
N, M = map(int, input().split())

uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

ans = 0
for i in range(N):
    ans = max(ans, uf.size(i))

print(ans)

Measured memory_bytes: 14500
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
      int leng=line.length();
      int ans=999;
      for(int i=0;i<leng-2;i++){
      	String s=line.substring(i,i+3);
        ans=Math.min(ans,Math.max(753-Integer.parseInt(s),Integer.parseInt(s)-753));
      }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
    double a,x;
    while(cin>>a){
        if(a==-1)
            break;
        x=a/2;
        while(1){
            x=x-(x*x*x-a)/(3*x*x);
            if(fabs(x*x*x-a)<0.00001*a)
                break;
        }
        printf("%.6f\n",x);
    }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;
  cin>>N;
  map<int,int> A;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    A[j]++;
  }
  if(N%2==0){
    for(int i=1;i<N;i+=2)
      if(A[i]!=2){
        cout<<0<<endl;
        return 0;
      }
  }else if(A[0]!=1){
    cout<<0<<endl;
    return 0;
  }else
    for(int i=2;i<N;i+=2)
      if(A[i]!=2){
        cout<<0<<endl;
        return 0;
      }
  int j=1;
  for(int i=0;i<N/2;i++)
    j=j*2%1000000007;
  cout<<j<<endl;
}

Measured memory_bytes: 7548
#include<stdio.h>

int main(){
  
  int N,K;
  int sum = 1;
  scanf("%d %d",&N,&K);

  for(int i=0; i<N; i++){
    if(sum <= K) sum = 2*sum;
    else sum += K;
  }

  printf("%d",sum);

  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mo=1e9+7,N=5005;
int n,x,y,i,j,sz[N],f[N][N],ff[N],g[N];
vector<int>e[N];
void dfs(int x,int fa){
	f[x][1]=sz[x]=1;
	for(int y:e[x])if(y!=fa){
		dfs(y,x);
		memset(ff,0,sz[x]+sz[y]+1<<2);
		for(i=0;i<=sz[x];++i)for(j=0;j<=sz[y];++j)ff[i+j]=(ff[i+j]+1ll*f[x][i]*f[y][j])%mo;
		sz[x]+=sz[y];memcpy(f[x],ff,sz[x]+1<<2);
	}
	for(i=1;i<<1<=sz[x];++i)f[x][0]=(f[x][0]+1ll*g[i]*f[x][i<<1])%mo;if(fa)f[x][0]=mo-f[x][0];
}
int main(){
	scanf("%d",&n);
	for(i=1;i<n;++i)scanf("%d%d",&x,&y),e[x].push_back(y),e[y].push_back(x);
	for(i=2,g[1]=1;i<=n>>1;++i)g[i]=1ll*g[i-1]*(i*2-1)%mo;
	dfs(1,0);
	printf("%d\n",f[1][0]);
	return 0;
}

Measured memory_bytes: 97536
fun main(args: Array<String>) {
    val D = readLine()!!.toInt()

    if (D == 25) {
        println("Christmas")
    } else if (D == 24) {
        println("Christmas Eve")
    } else if (D == 23) {
        println("Christmas Eve Eve")
    } else if (D == 22) {
        println("Christmas Eve Eve Eve")
    }
}

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

int main(){
  bool zero = false;
  int mc = 0;
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i]<0){
      mc ++;
      a[i] = abs(a[i]);
    }
    if(a[i]==0) zero = true;
    sum += a[i];
  }
  
  if(zero||mc%2==0){
    cout << sum << endl;
  }
  else{
    sort(a.begin(),a.end());
    cout << sum - 2 * a[0] << endl;
  }
}


Measured memory_bytes: 4024