akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

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

int main()
{
    ll a, b; cin >> a >> b;
    ll x = gcd(a, b);
    ll y = (ll)sqrt(x) + 2;

    bool table[y] = {false};
    vector<ll> prime;

    for (int i = 2; i <= y; i++) {
        if (!table[i]) prime.push_back(i);
        for (int j = 2 * i; j <= y; j += i) table[j] = true;
    }

    int ans = 1;
    for (auto &i : prime) {
        if (x % i == 0) ans++;
        while (x % i == 0) x /= i;
    }
    if (x > 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2424
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final int c = scanner.nextInt();
        final int x = scanner.nextInt();
        final int y = scanner.nextInt();

        int result;
        if (x < y) {
            result = Math.min((a + b) * x, c * 2 * x);
            result += Math.min(b * (y - x), 2 * c * (y - x));
        } else {
            result = Math.min((a + b) * y, c * 2 * y);
            result += Math.min(a * (x - y), c * 2 * (x - y));
        }

        System.out.println(result);
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int& di : d)
	cin >> di;
  sort(d.begin(), d.end());
  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 H, W, N;
  cin >> H >> W >> N;
  i64 K = max(H, W);
  i64 ans = N / K;
  if(N % K != 0)
    ++ans;
  cout << ans << endl;

  return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    constexpr int MX_V = 1000000;
    int cp[MX_V + 1];
    Vi ps;
    for (ll i = 0; i <= MX_V; i++) {
        cp[i] = -1;
    }
    for (ll i = 2; i <= MX_V; i++) {
        if (cp[i] == -1) {
            ps.emplace_back(i);
            cp[i] = i;
        }
        for (ll j = i + i; j <= MX_V; j += i) {
            if (cp[j] != -1) continue;
            cp[j] = i;
        }
    }

    ll N;
    cin >> N;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    int ns[MX_V + 1];
    for (ll i = 0; i <= MX_V; i++) {
        ns[i] = 0;
    }

    set<int> st;
    for (ll i = 0; i < N; i++) {
        st.clear();
        int t = A[i];
        while (t > 1) {
            ll q = cp[t];
            if (q > 1) {
                st.emplace(q);
            }
            t /= q;
        }
        for (auto x : st) {
            ++ns[x];
        }
    }

    ll mx = 0;
    for (ll i = 0; i < MX_V; i++) {
        chmax(mx, ns[i]);
    }

    if (mx <= 1) {
        prints()("pairwise coprime");
    }
    else if (mx < N) {
        prints()("setwise coprime");
    }
    else {
        prints()("not coprime");
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

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

int main() {
    string S = "yyyy/mm/dd";
    cin >> S;
    if(S.at(5)=='0'){
        if(S.at(6)<'5'){
            cout << "Heisei" << endl;
        }
        else{
            cout << "TBD" << endl;
            }
    }
    else{
        cout << "TBD" << endl;
    }
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    string S;
    cin >> S;
    bool same = false;
    for (ll i = 0; i < S.size() - 1; i++) {
        if (S[i] == S[i + 1]) {
            same = true;
        }
    }
    cout << (same ? "Bad" : "Good") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 1<<30

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int V,vector<vector<edge> >& graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	for (int i = 0;i < V;i++) {
		if (d[i] == INF) {
			cout << "INF"<<endl;
		}
		else cout << d[i] << endl;
	}


}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int main() {
	int V, E, r;
	cin >> V >> E >> r;
	vector<vector<edge> > graph(V);
	for (int i = 0;i < E;i++) {
		int s, t, d;
		cin >> s >> t >> d;
		graph[s].push_back(edge(t,d));
	}
	dijkistra(r, V, graph);
	
}

int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}

Measured memory_bytes: 11212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

template<class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

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

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

struct Union_find {
	int par[200010]; //親
	int siz[200010]; //根ノードiの木に含まれる要素数。iが根ノード出ない場合無意味な値となる。

	//n要素で初期化
	Union_find(int n) {
		for(int i = 0;i < n;i++) {
			par[i] = i;
			siz[i] = 1;
		}
	}

	//木の根を求める
	int find(int x) {
		if(par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//ｘとｙの属する集合を併合
	void unite(int x,int y) {
		x = find(x);
		y = find(y);
		if(x == y) {
			return;
		}
		if(siz[x] < siz[y]) {
			swap(x,y);
		}
		par[y] = x;
		siz[x] += siz[y];
	}

	//ｘとｙが同じ集合に属するか否か
	bool same(int x,int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		return siz[find(x)];
	}
};

int main() {
    int N,M;
    cin >> N >> M;
    Union_find uf(N);
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        uf.unite(A,B);
    }
    set<int> st;
    for(int i = 0;i < N;i++) {
        st.insert(uf.find(i));
    }
    cout << st.size() - 1 << endl;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const ll N=10001;
ll a[N],b[N],abm[N],n,as=0,bs=0,c,ca,k,aa=0,bb=0;



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,1,n+1){
		cin>>a[i];
		as+=a[i];
	}
	FOR(i,1,n+1){
		cin>>b[i];
		bs+=b[i];
	}
	c=bs-as;
	ca=c*2ll;
	if(as>bs){
		cout<<"No"<<endl;
		return 0;
	}

	FOR(i,1,n+1){
		if((a[i]%2ll)!=(b[i]%2ll))k=1ll;
		else k=0ll;
		abm[i]=max(a[i],b[i]+k);
	}

	FOR(i,1,n+1){
		if(abm[i]>a[i]){
			aa+=(abm[i]-a[i]);
		}
		if(abm[i]>b[i]){
			bb=(abm[i]-b[i]);
		}
	}

	if(ca<aa || c<bb){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	IN(int, n, k);
	vector<int> a(n);
	cin >> a;
	sort(ALL(a));
	int ans = 0;
	inc(i, k) { ans += a[i]; }
	OUT(ans);
}


Measured memory_bytes: 3628
import math
import sys

n=int(input())
#  =map(int,input().split())
#  =list(map(int,input().split()))

sum=0

for i in range(1, n + 1):
    if i % 3 == 0 or i % 5 == 0:
        pass
    else:
        sum+=i

print(sum)

Measured memory_bytes: 64576
/*
  ___    ___             ___    __                   _     _   _
 |   \  /   |           |   \  |  |                 | |   (_) | |
 |    \/    |  _ __     |    \ |  |   __ _   _____  | |_   _  | | __
 |  |\  /|  | | '__|    |  |\ \|  |  / _' | |  ___) | __| | | | |/ /
 |  | \/ |  | | |    _  |  | \    | | (_| | |___  | | \_  | | |   /
 |__|    |__| |_|   (_) |__|  \___|  \__,_| (_____|  \__| |_| |_|\_\

 */

 #include<bits/stdc++.h>
 using namespace std;
 #define ll long long
 #define M 1000000007
 #define endl "\n"

 int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int b[n+1];
    memset(b,-1,sizeof b);
    b[0]=0;
    for(int i=0;i<n;i++)
    {
        if(b[a[i]-1]!=-1)
            b[a[i]]=max(b[a[i]],b[a[i]-1]+1);
    }
    int m=-1;
    for(int i=1;i<=n;i++)
        if(m<b[i])
        m=b[i];
    if(m==-1) cout<<-1;
    else
    cout<<n-m;
 }



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

int main(){
  int n,no=0;
  cin>>n;
  for(int i=0; i<n; i++){
    int t;
    cin>>t;
    if(t!=i+1)no++;
  }
  if(no==0 || no==2)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
#define Yes cout<<"Yes"<<endl; 
#define No cout<<"No"<<endl;
#define YES cout<<"YES"<<endl; 
#define NO cout<<"NO"<<endl;
#define yes cout<<"yes"<<endl; 
#define no cout<<"no"<<endl;

// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
ll n;cin>>n;
    ll A=1,B=1,C=1;
    rep(i,n){
        A = A * 10 % 1000000007;
        B = B * 9 % 1000000007;
        C = C * 8 % 1000000007;
    }

    ll ans = (A+C)+INF - (B*2)%INF;
    ans %= INF;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
n, y = map(int, input().split())

for yukiti in range(0, 1 + (y // 10000)):
  for higuti in range(0, 1 + (y - 10000 * yukiti) // 5000):
    noguti = (y - 10000 * yukiti - 5000 * higuti) // 1000
    paper = yukiti + higuti + noguti # 今気がついたんだけど全員tiで終わってるわw
    #count = yukiti * 10000 + higuti * 5000 + noguti * 
    if paper == n:
      print("{0} {1} {2}".format(yukiti, higuti, noguti))
      exit(0)

print("-1 -1 -1")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>

using namespace std;

int main() {

  int a, b, c;
  //cin >> a;
  double ans, ra, rb;
  string weatherReport;
  cin >> weatherReport;
  for(int i = 0;i < weatherReport.size();i++){
    if(weatherReport[i] == '9'){
      cout << 1;
    }else{
      cout << 9;
    }
  }
  return 0;
}


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

int main(){
int N,T,A,X;
  scanf("%d%d%d",&N,&T,&A);
    
    int c= 1000000;
  int res,d;
    for(int i=1;i<=N;i++){
    scanf("%d",&X);
      d=T*1000-6*X-1000*A;
      if(d<0)d=-d;
      if(c>d)c=d,res=i;
    }
  printf("%d\n",res);
}

Measured memory_bytes: 3840
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll x,a; cin>>x>>a;
    vec<ll> m(a), hv(1050);
    for(int q=0; q<a; q++){
        cin>>m[q];
        hv[m[q]] = 1;
    }
    int c = -1, d = 1e9;
    for(int q=0; q<200; q++){
        if(hv[q]) continue;
        if(abs(q-x)<d) d = abs(q-x), c = q;
    }
    cout<<c;
}

Measured memory_bytes: 3668
#include<iostream>
using namespace std;
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bits/stdc++.h>
#include<stdio.h>
 
int main(){
    string S;
    cin >> S;
    if(S=="SUN"){
        cout << 7;
    }
     if(S=="MON"){
        cout << 6;
    }
     if(S=="TUE"){
        cout << 5;
    }
     if(S=="WED"){
        cout << 4;
    }
     if(S=="THU"){
        cout << 3;
    }
     if(S=="FRI"){
        cout << 2;
    }
     if(S=="SAT"){
        cout << 1;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
    int x,a,b;
    while(cin>>x>>a>>b)
    {
        if(fabs(x-a)<fabs(x-b))
            cout<<"A"<<endl;
        else cout<<"B"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<functional>
using namespace std;
int main(int argc, char *argv[])
{
  string exp;
  cin >> exp;
  int ans;
  cin >> ans;
  auto parseLR = [](const string &e) {
    int c = e[0] - '0';
    for(int i = 1; i < e.size(); i++) {
      if(e[i] == '*') {
        c *= e[i+1] - '0';
        i++;
      } else if(e[i] == '+') {
        c += e[i+1] - '0';
        i++;
      } else {
        throw string("something wrong!");
      }
    }
    return c;
  };
  auto num = [](const string &e, int &i) {
    return e[i++] - '0';
  };
  auto mul = [&num](const string &e, int &i) {
    int c = num(e,i);
    while(i < e.size() && e[i] == '*') {
      i++;
      c *= num(e,i);
    }
    return c;
  };
  auto add = [&mul](const string &e, int &i) {
    int c = mul(e,i);
    while(i < e.size() && e[i] == '+') {
      i++;
      c += mul(e,i);
    }
    return c;
  };
  auto parse = [&add](const string &e) {
    int i = 0;
    return add(e, i);
  };
  bool lr = parseLR(exp) == ans;
  bool ty = parse(exp) == ans;
  if(lr && ty) {
    cout << "U" << endl;;
  } else if(lr) {
    cout << "L" << endl;
  } else if(ty) {
    cout << "M" << endl;
  } else {
    cout << "I" << endl;
  }
  return 0;
}



Measured memory_bytes: 3220
from fractions import gcd

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

dic = {}
L = int((N*M) / gcd(N,M))
ans = L

for i in range(N):
  dic[int(i*(L/N)+1)] = i

key = set(dic.keys())
for i in range(M):
  if i*(L/M)+1 in key:
    if S[dic[int(i*(L/M)+1)]] == T[i]:continue
    else: 
      ans = -1
      break

  


print(ans)


Measured memory_bytes: 87780
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var cnt = 0
    for (i in 0..999) {
        val num = i.toString().padStart(3, '0')

        var num1Found = false
        var num2Found = false

        inner@for(i in s.indices) {
            if (num2Found && s[i] == num[2]) {
                cnt++
                break@inner
            } else if (num1Found && s[i] == num[1]) {
                num2Found = true
            } else if (s[i] == num[0]) {
                num1Found = true
            }
        }
    }

    println(cnt)
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	//ios::sync_with_stdio(false); cin.tie(0);
	int a[3][3];
	rep(i, 3) rep(j, 3) cin >> a[i][j];
	int n;
	cin >> n;
	int b[n];
	rep(i, n) cin >> b[i];

	bool check[3][3];
	rep(i, 3) rep(j, 3) check[i][j] = false;

	rep(i, 3) rep(j, 3)
	{
		rep(k, n)
		{
			if(a[i][j] == b[k])
				check[i][j] = true;
		}
	}

	bool ans = false;
	rep(i, 3)
	{
		if(check[i][0] & check[i][1] & check[i][2])
			ans = true;
	}

	rep(i, 3)
	{
		if(check[0][i] & check[1][i] & check[2][i])
			ans = true;
	}

	if(check[0][0] & check[1][1] & check[2][2])
		ans = true;

	if(check[0][2] & check[1][1] & check[2][0])
		ans = true;

	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out ="";
    int sumPrice = 0;
    double sumNum = 0;
    int n = 0;
    while (scanner.hasNext()) {
      String line = scanner.nextLine();
      String[] p = line.split(",");
      sumPrice += Integer.parseInt(p[0]) * Integer.parseInt(p[1]);
      sumNum += Double.parseDouble(p[1]);
      n++;
    }
    BigDecimal avgNumWork = new BigDecimal(sumNum / n);
    BigDecimal avgNum = avgNumWork.setScale(0, BigDecimal.ROUND_HALF_UP);
    System.out.println(sumPrice);
    System.out.println(avgNum.intValue());
  }
}

Measured memory_bytes: 17196
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007

using namespace std;

int main(){
    string N; cin >> N;
    if(N[1] == N[2] && (N[0] == N[1] || N[2] == N[3])) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <stdio.h>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b){return b? gcd(b, a%b):a;}
using namespace std;

int d[2001][2001] = {3000};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, A, B;
	cin >> N >> A >> B;
	char S[N];
	int count_pass = 0;
	int count_oversea = 0;
	for(int i = 0; i < N; i++){
		cin >> S[i];
		if(S[i] == 'a'){
			if(count_pass < A+B){
				cout << "Yes" <<endl;
				count_pass++;
			}else{
				cout << "No" << endl;
			}
		}else if (S[i] == 'b'){
			if(count_pass < A+B && count_oversea < B){
				cout << "Yes" <<endl;
				count_pass++;
				count_oversea++;
			}else{
				cout<<"No" <<endl;
			}
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        boolean primes[] = new boolean [55560];
        for (int n = 2; n < primes.length; n++) {
            if (primes[n]) continue;
            for (int m = 2 * n; m < primes.length; m += n) {
                primes[m] = true;
            }
        }

        int count = 1;
        System.out.print("2 ");
        for (int i = 7; i <= 55560; i+=5) {
            if (count == N) {
                break;
            }
            if (!primes[i]) {
                System.out.print(i + " ");
                count++;
            }
        }
        System.out.println();


    }
}

Measured memory_bytes: 20688
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int L = A+B;
    int R = C+D;
    if(L > R) cout << "Left" << endl;
    else if(L == R) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int n, A[50];

//入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m){
  if(m == 0) return 1;
  if(i >= n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main(){
  int q, M, i;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &M);
    if(solve(0, M))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}


Measured memory_bytes: 2136
hash = Hash.new(0)
min_a, max_v = Float::INFINITY, -Float::INFINITY
 
n, q = gets.chomp.split.map(&:to_i)
 
q.times do
  a, v = gets.chomp.split.map(&:to_i)
  hash[a] += v
  if v > 0
    if hash[a] > max_v
      max_v = hash[a]
      min_a = a
    elsif hash[a] == max_v
      min_a = [a, min_a].min
    end
  else
    if a == min_a
      order = hash.sort do |(k1, v1), (k2, v2)|
        if v1 == v2
          k1 <=> k2
        else
          v2 <=> v1
        end
      end
      min_a, max_v = order.first[0], order.first[1]
    end
  end
 
  puts [min_a, max_v].join(' ')
end


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

using namespace std;

typedef long long ll;

int n;
const int N = 200005;
int a[N][25];
int cnt[25];

void change(int x, int i)
{
    int tot = 0;
    while (x != 0)
        {
        a[i][tot] = x%2;
        tot++;
        x /= 2;
        }
    //for (int j = 20; j >= 0; j--) printf("%d", a[i][j]);
}

bool check()
{
    for (int i = 0; i <= 21; i++) if (cnt[i] > 1) return false;
    return true;
}

void solve()
{
    ll ans = 0;
    int l = 1, r = 1;
    for (int i = 0; i <= 21; i++) cnt[i] = a[1][i];
    while (r <= n)
        {
        if (check())
            {
            ans += (ll)(r-l+1);
            r++;
            for (int i = 0; i <= 21; i++) cnt[i] += a[r][i];
            }
        else
            {
            for (int i = 0; i <= 21; i++) cnt[i] -= a[l][i];
            l++;
            }
        }
    printf("%lld\n", ans);
}

int main()
{
    cin>>n;
    for (int i = 1; i <= n; i++)
        {
        int x;
        scanf("%d", &x);
        change(x, i);
        }
    solve();
}


Measured memory_bytes: 19840
# import sys
# fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# and also we do not have to implement Vertex class.
# Instead, we can use (distance, vertex).
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, parent = initialize(adj, s)
    priority_queue = []
    heappush(priority_queue, (d[s], s))
    while priority_queue:
        distance, source = heappop(priority_queue) 
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
                parent[neighbor] = source
                heappush(priority_queue, (new_distance, neighbor))
    return d


n, m, s, t = map(int, input().split())
adj = defaultdict(list)
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = map(int, input().split())
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in range(n, 0, -1):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
print(*(initial_money - cost for cost in reversed(min_cost_after_each_year_reversed)), sep='\n')



Measured memory_bytes: 135536
#include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,l,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;
 
    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
  
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
    l=0;
      for(j=1;j<=c;j++){
    for(k=p-1+l;k>=1+l;k--){
          nh[k+1]=nh[k];
    }
        l++;
      }
     
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }
 
    printf("%d\n",nh[1]);
  }
    return 0;
}

Measured memory_bytes: 2688
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(map(str,input())))

row=[False]*h
col=[False]*w
for i in range(h):
    for k in range(w):
        if l[i][k]=="#":
            row[i]=True
            col[k]=True
for i in range(h):
    if row[i]:
        for k in range(w):
            if col[k]:
                print(l[i][k], end="")
        print("")


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

using namespace std;
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
	string s;
	cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'L' && i % 2 == 0) {
            puts("No");
            return 0;
        } 
        if (s[i] == 'R' && i % 2 ) {
            puts("No");
            return 0;
        } 
    }
    puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,sum=0; cin >> N >> M;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  for(int i=0; i<N; i++) sum += A.at(i);
  
  if(N<sum) {
    cout << -1 << endl;
    return 0;
  }
  cout << N-sum << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

class mint {
public:
    long long x;

    mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}

    mint operator-() const {
        return mint(-x);
    }

    mint &operator+=(const mint &rhs) {
        if ((x += rhs.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator-=(const mint &rhs) {
        if ((x += MOD - rhs.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator*=(const mint &rhs) {
        (x *= rhs.x) %= MOD;
        return *this;
    }

    mint operator+(const mint &rhs) const {
        mint res(*this);
        return res += rhs;
    }

    mint operator-(const mint &rhs) const {
        mint res(*this);
        return res -= rhs;
    }

    mint operator*(const mint &rhs) const {
        mint res(*this);
        return res *= rhs;
    }

    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator/=(mint rhs) {
        return *this *= rhs.inv();
    }

    mint operator/(const mint rhs) const {
        return mint(*this) /= rhs;
    }

    bool operator==(const mint &rhs) const noexcept {
        return this->x == rhs.x;
    }

    bool operator!=(const mint &rhs) const noexcept {
        return this->x != rhs.x;
    }

    bool operator<(const mint &rhs) const noexcept {
        return this->x < rhs.x;
    }

    bool operator>(const mint &rhs) const noexcept {
        return this->x > rhs.x;
    }

    bool operator<=(const mint &rhs) const noexcept {
        return this->x <= rhs.x;
    }

    bool operator>=(const mint &rhs) const noexcept {
        return this->x >= rhs.x;
    }

    friend istream &operator>>(istream &is, mint &a) {
        long long t;
        is >> t;
        a = mint(t);
        return is;
    }

    friend ostream &operator<<(ostream &os, const mint &a) {
        return os << a.x;
    }
};


void solve() {
    ll N, K;
    cin >> N >> K;
    mint ans = K;
    cout << ans.pow(N) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}



Measured memory_bytes: 3212
N=int(input())
A=[int(a) for a in input().split()]
cnt=[0 for _ in range(N//2 if N%2==0 else N//2+1)]
ans=0
for a in A:
  cnt[a//2]+=1
if N%2==0:
  if all(c==2 for c in cnt):
    ans=pow(2,N//2,10**9+7)
else:
  if cnt[0]==1 and all(c==2 for c in cnt[1:]):
    ans=pow(2,N//2,10**9+7)
print(ans)
  

Measured memory_bytes: 13880
#include<iostream>
#include<cstdint>
#include<algorithm>

int const MAXH = 100000;
int const MAXW = 100000;
int const MAXN = 3000;
uint64_t MOD = 1000000007;

int H, W, N;
struct P { int x, y; };
bool operator< (P const& p1, P const& p2) {
  if(p1.x < p2.x) return true;
  if(p1.x > p2.x) return false;
  return p1.y < p2.y;
}
P b[MAXN];

uint64_t fact[MAXH+MAXW+1];
uint64_t inv_fact[MAXH+MAXW+1];
uint64_t dp[MAXN];

void init_fact(int x) {
  uint64_t inv[MAXH+MAXW+1];
  fact[0] = fact[1] = 1;
  inv_fact[0] = inv_fact[1] = 1;
  inv[0] = inv[1] = 1;
  for(int i = 2; i <= x; ++i) {
    fact[i] = fact[i-1]*(uint64_t)i%MOD;
    inv[i] = MOD - (MOD/i)*inv[MOD%i]%MOD;
    inv_fact[i] = inv_fact[i-1]*inv[i]%MOD;
  }
}

uint64_t mod_ways(int x, int y) {
  uint64_t ret = fact[x+y]*inv_fact[x]%MOD;
  ret = ret*inv_fact[y]%MOD;
  return ret;
}

int main() {
  std::cin >> H >> W >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> b[i].x >> b[i].y;
    --b[i].x; --b[i].y;
  }
  std::sort(b, b+N);

  init_fact(H+W-2);
  uint64_t ans = mod_ways(H-1, W-1);
  for(int i = 0; i < N; ++i) {
    dp[i] = mod_ways(b[i].x, b[i].y);
    for(int j = 0; j < i; ++j) {
      int dx = b[i].x - b[j].x, dy = b[i].y - b[j].y;
      if(dx >= 0 && dy >= 0) {
        uint64_t diff = dp[j]*mod_ways(dx, dy)%MOD;
        dp[i] = (dp[i] + MOD - diff)%MOD;
      }
    }
    uint64_t diff = dp[i]*mod_ways(H-1-b[i].x, W-1-b[i].y)%MOD;
    ans = (ans + MOD - diff)%MOD;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

#define WHITE 0
#define BLACK 1

typedef struct{
    int M[101][101];
    int d[101];
    int color[101];
} Akkarin;

Akkarin akk;
int n = 0;

int prim(){
    int sum = 0;
    int mincost = 0;
    int t = 0;
    int u = 0;
    int i = 0;

    akk.d[0] = 0;
    akk.color[0] = BLACK;
    t++;
    while(t<n){
        for(i=0; i<n; i++){
            if(akk.M[u][i]<akk.d[i]){
                    akk.d[i] = akk.M[u][i];
            }
        }
        mincost = 9999999;
        for(i=0; i<n; i++){
            if(akk.d[i]<mincost && akk.color[i]!=BLACK){
                u=i;
                mincost = akk.d[i];
            }
        }
        sum = sum + mincost;
        akk.color[u] = BLACK;
        t++;
    }
    return sum;
}


int main(){
    int i = 0;
    int j = 0;
    int ppp;
    scanf("%d", &n);

    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            scanf("%d", &ppp);
            akk.M[i][j]=((ppp==-1) ? (9999999):(ppp));
        }
    }
    for(i=0;i<n;i++){
        akk.color[i] = WHITE;
        akk.d[i] = 9999999;
    }

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

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b;

int main() {
	cin >> a >> b;
	if (a+b>=10) cout << "error" << ln;
	else cout << a+b << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(2*1e5)+5
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long

using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;

ll n, k, p[MAXN], f[MAXN];

// qtd de treinos = diferença X-p[i]
// X = minpower to do in Y seconds;
// f/mid


bool check(ll mid) {
	ll need = 0;
	for(int i = 0; i < n; i++) {
		ll aux = p[i]*f[i];
		if(aux <= mid)
			continue;
		need += (aux-mid+f[i]-1)/f[i];
	}
	if(need <= k)
		return 1;
	else return 0;
}

ll bb() {
	ll ini = 0, mid, fim = 1e12+5, ans = LINF;
	while(ini <= fim) {
		mid = (ini+fim)/2;
		if(check(mid)) {
			ans = min(ans, mid);
			fim = mid-1;
		}
		else ini = mid+1;
	}
	return ans;
}


int32_t main() {
	FAST;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> p[i];
	for(int i = 0; i < n; i++)
		cin >> f[i];
	sort(p, p+n, greater<int>());
	sort(f, f+n);
	cout << bb() << endl;
}


Measured memory_bytes: 3328
import java.util.*;
import java.io.*;
public class Main{
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int n = Integer.parseInt(st.nextToken());
      int k = Integer.parseInt(st.nextToken());
      st = new StringTokenizer(br.readLine());
      int[] a = new int[n];
      for(int i = 0; i < n; i++)
    	  a[i] = Integer.parseInt(st.nextToken());
      StringJoiner sj = new StringJoiner(" ");
      if(k > 3*Math.log(n)/Math.log(2)) {
    	  for(int i = 0; i < n; i++)
    		  sj.add(Integer.toString(n));
      }
      else {
    	  for(int i = 0; i < k; i++) {
    		  int[] b = new int[n];
    		  for(int j = 0; j < n; j++) {
    			  b[Math.max(0,j - a[j])]++;
    			  if(j + a[j] < n-1)
    				  b[j + a[j]+1]--;
    		  }
    		  for(int j = 1; j < n; j++) {
    			  b[j] += b[j-1];
    		  }
    		  a = b;
    	  }
    	  for(int i = 0; i < n; i++)
    		  sj.add(Integer.toString(a[i]));
      }
      out.println(sj);
      out.close();
   }
}

Measured memory_bytes: 63672
N = int(input())
A = [int(i) for i in input().split()]
a = 0
for i in range(N):
  a += A[i] * (-1) ** i
b = a
print(a, end = " ")

for i in range(0, N-2):
  b = 2 * A[i] - b
  print(b, end = " ")

print(2 * A[N-2] - b)

Measured memory_bytes: 63984
//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 100005

typedef long long ll;

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

using namespace std;

int N, M, K;

int main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N >> K;
	int R, S, P;
	cin >> R >> S >> P;

	string s1;
	cin >> s1;

	ll ans = 0;
	int t = min(K, N);
	for (int i = 0; i < t; i++) {
		if (s1[i] == 's')
			ans += R;
		else if (s1[i] == 'p')
			ans += S;
		else
			ans += P;
	}

	for (int i = t; i < N; i++) {
		if (s1[i] == s1[i - K]) {
			s1[i] = '.';
			continue;
		}
		if (s1[i] == 's')
			ans += R;
		else if (s1[i] == 'p')
			ans += S;
		else
			ans += P;
	}

	cout << ans << '\n';


	return 0;
}



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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for(int &i:p)cin >> i;
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<K;i++)ans+=p.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3632
let () = Scanf.scanf "%f %f\n%f %f\n%f %f\n" @@ fun x1 y1 x2 y2 x3 y3 ->
  let a = sqrt @@ (x2 -. x1) ** 2. +. (y2 -. y1) ** 2. in
  let b = sqrt @@ (x3 -. x2) ** 2. +. (y3 -. y2) ** 2. in
  let c = sqrt @@ (x1 -. x3) ** 2. +. (y1 -. y3) ** 2. in
  let s = (a +. b +. c) *. 0.5 in
  let s_ = sqrt @@ s *. (s -. a) *. (s -. b) *. (s -. c) in
  let r = s_ /. s in
  let m = max a @@ max b c in
  Printf.printf "%.13f\n" @@ m *. r /. (2. *. r +. m)


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

ll x,y,z,n,m,s,t,a[200009],b[200009],c[200009],d[200009];
vector<ll>X[100009],Y[100009],Z[100009];
bool END[3][100009];

int main(){
    cin>>x>>y>>z>>n>>m>>s>>t;
    t+=n;
    FOR(i,1,n+1){
        cin>>a[i]>>b[i];
        X[a[i]].push_back(i);
        Y[b[i]].push_back(i);
    }
    FOR(i,n+1,n+m+1){
        cin>>b[i]>>c[i];
        Y[b[i]].push_back(i);
        Z[c[i]].push_back(i);
    }

    queue<ll> que;
    FOR(i,0,n+m+2)d[i]=-1;
    d[s]=0;
    que.push(s);

    while(!que.empty()){
        ll now=que.front();
        que.pop();
        ll A=a[now],B=b[now],C=c[now];
        if(!END[0][A]){
            rep(i,X[A].size()){
                if(d[X[A][i]]==-1){
                    d[X[A][i]]=d[now]+1;
                    que.push(X[A][i]);
                }
            }
            END[0][A]=1;
        }
        if(!END[1][B]){
            rep(i,Y[B].size()){
                if(d[Y[B][i]]==-1){
                    d[Y[B][i]]=d[now]+1;
                    que.push(Y[B][i]);
                }
            }
            END[1][B]=1;
        }
        if(!END[2][C]){
            rep(i,Z[C].size()){
                if(d[Z[C][i]]==-1){
                    d[Z[C][i]]=d[now]+1;
                    que.push(Z[C][i]);
                }
            }
            END[2][C]=1;
        }
    }
    cout<<d[t]<<endl;
}


Measured memory_bytes: 24264
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll N, A, B;
ll ans;
signed main(){
	cin >> N >> A >> B;
	ll tmp = N / (A+B);
	ans = A * tmp;
	ans += min(A, N-tmp*(A+B));
	cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define log long long

signed main()
{
   log n, x;
   cin >> n;
   int cnt = 1, ans = 0;

   rep(i, n)
   {
      cin >> x;
      if (x == cnt)
      {
         cnt++;
         ans++;
      }
   }

   if (ans == 0)
      cout << -1 << '\n';
   else
      cout << n - ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>

int main() {
	long long int a, b, n; std::cin >> a >> b >> n;
	if (b == 1) {
		std::cout << 0 << '\n';
		return 0;
	}
	const auto x = std::min(b - 1, n);
	std::cout << (a * x) / b - a * (x / b) << '\n';
}

Measured memory_bytes: 3620
n ,m = map(int, input().split())
a = [0] * n
b = [0] * n
arr = [[0] * 2 for _ in range(n)]

for i in range(n):
    a[i], b[i] = map(int, input().split())
    arr[i][0] = a[i]
    arr[i][1] = b[i]

arr.sort()

count = 0
cost = 0

for i in range(n):
    rem = m - count 
    cost += arr[i][0] * min(arr[i][1], rem)
    count += min(arr[i][1], rem)
    if count >= m:
        break

print(cost)


Measured memory_bytes: 21676
import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int h = in.ni();
        int n = in.ni();
        int sum = 0;
        for(int i = 0; i < n; i++) {
            sum += in.ni();
        }
        out.println(sum>=h?"Yes":"No");
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private ArrayDeque<String> que;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            que = null;
        }
        public String ns(){
            if(que == null || que.isEmpty()){
                try{
                    que = new ArrayDeque<>(Arrays.asList(br.readLine().split(" ")));
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return que.pollFirst();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}


Measured memory_bytes: 33492