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

int a;
char x[60][30];
int y[60];

int isPalin[60][30][30];
int check1[60][30][30][3];
long long int check2[60][30][30][3];
long long int MAX = 1;
long long int func(int s, int L, int R, int type)
{
	if(L>R) return 0;
	if(isPalin[s][L][R]==1) return 0;
	
	if(check1[s][L][R][type]==1) return MAX;
	else if(check1[s][L][R][type]==2) return check2[s][L][R][type];
	
	check1[s][L][R][type] = 1;
	long long int ans = MAX;
	if(type==1)
	{
		for(int i=1;i<=a;i++)
		{
			long long int S = MAX;
			int b = strlen(x[i]+1);
			if(b<=R-L+1)
			{
				for(int j=1;j<=b;j++) if(x[s][L-j+b]!=x[i][j]) goto u;
				S = func(s,L+b,R,type) + y[i];
				ans = ans<S?ans:S;
			}
			else
			{
				for(int j=L;j<=R;j++) if(x[s][j]!=x[i][b-j+L]) goto u;
				S = func(i,1,b-R+L-1,3-type) + y[i];
				ans = ans<S?ans:S;
			}
			u:;
		}
	}
	else
	{
		for(int i=1;i<=a;i++)
		{
			long long int S = MAX;
			int b = strlen(x[i]+1);
			if(b<=R-L+1)
			{
				for(int j=1;j<=b;j++) if(x[s][R-j+1]!=x[i][j]) goto v;
				S = func(s,L,R-b,type) + y[i];
				ans = ans<S?ans:S;
			}
			else
			{
				for(int j=L;j<=R;j++) if(x[s][j]!=x[i][1-j+R]) goto v;
				S = func(i,R-L+2,b,3-type) + y[i];
				ans = ans<S?ans:S;
			}
			v:;
		}
	}
	check1[s][L][R][type] = 2;
	return check2[s][L][R][type] = ans;
}


int main()
{
	for(int i=1;i<=16;i++) MAX*=10;
	scanf("%d",&a);
	for(int i=1;i<=a;i++)
	{
		scanf("%s",x[i]+1);
		scanf("%d",&y[i]);
	}
	for(int i=1;i<=a;i++)
	{
		int b = strlen(x[i]+1);
		for(int L=1;L<=b;L++)
		{
			for(int R=L;R<=b;R++)
			{
				for(int k=L;k<=R;k++) if(x[i][k]!=x[i][L-k+R]) goto u;
				isPalin[i][L][R] = 1;
				u:;
			}
		}
	}
	
	long long int ans = MAX;
	for(int i=1;i<=a;i++)
	{
		int b = strlen(x[i]+1);
		long long int s = func(i,1,b,1) + y[i];
		ans = ans<s?ans:s;
	}
	if(ans>=MAX) printf("-1");
	else printf("%lld",ans);
}

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int h, f;
	scanf("%d%d", &h, &f);
	int ashi = h*2;
    int flag=0;
    for(int kame = 0; ashi <= f && kame <= h; kame++)
    {
      ashi = (h-kame) * 2 + kame * 4;
      if(ashi==f)
        flag =1;
    }
    
   if(flag==1)
     printf("Yes\n");
   else
     printf("No\n");
	return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
int N;
cin>>N;
vector<pair<int,int>> v;
for(int i=0;i<N;i++) {
    int X,L;
    cin>>X>>L;
    v.push_back({X+L,X-L});
}
sort(all(v));
int c = 0, mini = -1000000000;
for(auto x: v) {
    if(mini<=x.second) {
        mini = x.first;
        c++;
    }
}
cout<<c<<endl;
return 0;
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<Edge>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}



bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int dfs(int x,int y,int H,int W,vector<vector<char>> &masu){
  if(masu[x][y] == '#'){

  }
}
int main(){
  int N,M;
  cin >> N >> M;
  int ans = 0;
  ans = N*(N-1)/2 + M*(M-1)/2;
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <utility>
using namespace std;

using pi = pair<int, int>;

int main()
{
  int n;
  vector<pi> a; // a は value, index
  vector<pi> b; // b は b.value, a.value

  cin >> n;
  int v;
  for (int i = 0; i < n; ++i)
  {
    cin >> v;
    a.push_back(pi(v, i)); //
  }
  for (int i = 0; i < n; ++i)
  {
    cin >> v;
    b.push_back(pi(v, a[i].first));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  // N-2 の制限を考えずに自由に並び替えたばあい
  for (int i = 0; i < n; ++i)
  {
    if (a[i].first > b[i].first)
    {
      // No が確定
      cout << "No" << endl;
      return 0;
    }
  }

  for (int i = 0; i < n - 1; ++i)
  {
    if (a[i + 1].first <= b[i].first)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }

  a.clear();
  for (int i = 0; i < n; ++i)
  {
    a.push_back(pi(b[i].second, i));
  }
  sort(a.begin(), a.end());

  // サイクル数が1じゃないかどうか調べる
  const long long size = 1e5 + 10;
  bitset<size> visited(0);
  int crnt = 0;
  while (!visited.test(crnt))
  {
    visited.set(crnt);
    crnt = a[crnt].second;
  }
  if (visited.count() == n)
  {
    cout << "No" << endl;
    return 0;
  }
  else
  {
    cout << "Yes" << endl;
    return 0;
  }
  return 0;
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    int l,r,d;
    cin>>l>>r>>d;

    int ans;
    ans=(r/d)-(l/d);

    if(l%d==0)ans++;

    cout<<ans<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3580
#include <iostream>
#include <bits/stdc++.h>
const int maxn=100000+10;
using namespace std;
typedef long long int ll;
ll st[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",st+i);
    }
    sort(st,st+n);
    ll ans=0;
    int i=n-1;
    ll a=0,b=0;
    for(;i>=1;i--){
        if(st[i]==st[i-1]){
            a=st[i];
            i-=2;
            break;
        }
    }
    for(;i>=1;i--){
        if(st[i]==st[i-1]){
            b=st[i];
            i-=2;
            break;
        }
    }
    ans=a*b;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;
typedef tree<
        pair<int, int>, // change type
        null_type,
        less<pair<int, int> >, // change type
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    int freq[2][50] = {0};
    rep(i,0,n)
    {
        cin >> a[i];
        for (int j = 0; j < 50; ++j)
        {
            if ((1LL<<j) & a[i])
                freq[1][j]++;
            else
                freq[0][j]++;
        }
    }
    ll curK = 0;
    for (int i = 49; i >= 0; --i)
    {
        if (freq[1][i] > freq[0][i])
            continue;
        if ((1LL<<i) + curK > k)
            continue;
        curK += (1LL<<i);
    }
    ll ans = 0;
//    cout << curK << endl;
    rep(i,0,n)
        ans += (curK ^ a[i]);
    cout << ans;

    return  0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, n) for(int i = n-1; i >= 0; i--)
#define rep4(i, x, n) for(int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    int N, T;
    cin >> N >> T;
    ll A[N], B[N];
    rep(i, N) cin >> A[i] >> B[i];
    ll dp[N][T], rem[N][T];
    rep(i, T){
        if(i < A[0]){
            dp[0][i] = 0;
            rem[0][i] = B[0];
        }
        else{
            dp[0][i] = B[0];
            rem[0][i] = 0;
        }
    }
    rep2(i, 1, N){
        rep(j, T){
            if(j < A[i]){
                dp[i][j] = dp[i-1][j];
                rem[i][j] = max(rem[i-1][j], B[i]);
            }
            else{
                ll M = dp[i-1][j] + rem[i-1][j];
                M = max(M, dp[i-1][j-A[i]] + B[i] + rem[i-1][j-A[i]]);
                M = max(M, dp[i-1][j] + B[i]);
                if(M == dp[i-1][j] + rem[i-1][j]){
                    dp[i][j] = dp[i-1][j];
                    rem[i][j] = rem[i-1][j];
                }
                elif(M == dp[i-1][j-A[i]] + B[i] + rem[i-1][j-A[i]]){
                    dp[i][j] = dp[i-1][j-A[i]] + B[i];
                    rem[i][j] = rem[i-1][j-A[i]];
                }
                else{
                    dp[i][j] = dp[i-1][j];
                    rem[i][j] = B[i];
                }
            }
        }
    }
    cout << dp[N-1][T-1] + rem[N-1][T-1] << endl;
}

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

int main() {
  int A, B, n;
  cin >> A >> B;
  for(int i=0; i<99; i++) {
    if((A-1)*i+1 >= B) {
      n = i;
      break;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int a,b,c,d;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	while(!(c<=0 || a<=0)){
		c=c-b;
		if(c <= 0){
			cout << "Yes" << endl;
			goto Exit;
		}
		a=a-d;
		if(a <= 0){
			cout << "No" << endl;
			goto Exit;
		}
	}
	Exit : 
	;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int N, ans=0;
	cin >> N;
	vector<int> h(N+1);
	for(int i=0;i<N;i++){
		cin >> h[i];
	}
	h[N] = 0;
	for(int i=0;i<N;i++){
		if (h[i] > h[i+1]){
			ans += h[i] - h[i+1];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using ll = long long;
int main() {
  ll n, k, z = 0; std::cin >> n >> k;
  for(ll i = k; i <= n + 1; i++) z += ((2 * n - i + 1) * i / 2) - (i * (i - 1) / 2) + 1;
  z %= 1000000007; std::cout << z << std::endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;

ll		func(ll x, ll k){
	return (abs(x - k));
}

int		main(void){
	ll n, k;
	cin >> n >> k;
	n %= k;
	while (1){
	if (n <= func(n, k)){
		cout << n << endl;
		return 0;
	}
	n = func(n, k);
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long mn = 1e9 + 1;
  int cnt_minus = 0;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long ab = abs(A[i]);
    sum += ab;
    mn = min(ab, mn);
    if (A[i] < 0) cnt_minus++;
  }
  if (cnt_minus % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << sum - mn * 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 4056
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int m=scan.nextInt(),n=scan.nextInt();
      if (m==n){
      System.out.println("Yes");
      }
      else{
      System.out.print("No");
      
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int mvx[]={0, 0, -1, 1};
int mvy[]={-1, 1, 0, 0};
string ms[] = {"up", "down", "left", "right"};


int main(){
    int h, w;
    while(cin >> w >> h, h || w){
        //上下左右に動けるか
        bool maize[h][w][4] = {};

        rep(i, 2*h-1){
            int inp;

            if(i&1){
                rep(j, w){
                    cin >> inp;
                    if(inp == 0){
                        maize[i/2][j][1] = true;
                        maize[i/2+1][j][0] = true;
                    }
                }
            }
            else{
                rep(j, w-1){
                    cin >> inp;
                    if(inp == 0){
                        maize[i/2][j][3] = true;
                        maize[i/2][j+1][2] = true;
                    }
                }
            }
        }

        int dist[h][w];
        rep(i, h)rep(j, w)dist[i][j] = INF;
        dist[0][0] = 1;

        bool visited[h][w] = {};
        visited[0][0] = true;
        
        queue<pll> que;
        que.push(make_pair(0, 0));

        while(!que.empty()){
            pll pos = que.front();
            que.pop();

            if(pos.first == h-1 && pos.second == w-1)break;
            
            rep(i, 4){
                if(!maize[pos.first][pos.second][i])continue;

                int dx = pos.second + mvx[i];
                int dy = pos.first + mvy[i];

                if(dy < 0 || dy >= h || dx < 0 || dx >= w)continue;

                if(visited[dy][dx])continue;
                visited[dy][dx] = true;

                

                dist[dy][dx] = dist[pos.first][pos.second] + 1;
                que.push(make_pair(dy, dx));
            }
        }

        if(dist[h-1][w-1] >= INF)cout << 0 << endl;
        else cout << dist[h-1][w-1] << endl;
    }
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> D(N, 0);
  for(int i = 0; i < N; ++i) cin >> D[i];
  sort(D.begin(), D.end());

  int M;
  cin >> M;
  vector<int> T(M, 0);
  for(int i = 0; i < M; ++i) cin >> T[i];
  sort(T.begin(), T.end());

  int result = 0;
  if(M > N) result = 1;
  int i = 0, j = 0;
  
  while(i < M){
    while(j < N){
      if(j == N - 1 && T[i] != D[j]) result = 1;
      if(T[i] == D[j]){
        ++j;
        break;
      }
      ++j;
    }
    ++i;
  }
  if(result == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
 return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/bellman_ford_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
using namespace std;
using namespace boost::math;

int main() {
	int N, Q;

	cin >> N >> Q;
    multimap<int, int> adj;
  
    REP(i, N-1) {
      int a, b;
      
      cin >> a >> b;
      adj.emplace(a, b);
      adj.emplace(b, a);
    }
  
    vector<long long> count(N+1, 0);
  
    REP(i, Q) {
      long long p, x;
      cin >> p >> x;
      
      count[p] += x;
    }
  
  unordered_set<int> visited;
    auto dfs = [&](auto f, int n, int v) -> void{
      if (!visited.count(n)) {
        visited.insert(n);
        auto it = adj.lower_bound(n), eit = adj.upper_bound(n);

        for (; it != eit; ++it) {
          f(f, it->second, v + count[n]);
        }
        count[n] += v;
        visited.erase(n);
      }
    };

    dfs(dfs, 1, 0);
	cout << count[1];
    for (auto i : boost::irange(2, N+1))
      cout << " " << count[i];
  cout << endl;
 
	return 0;
}


Measured memory_bytes: 51272
sx,sy,tx,ty = map(int, input().split())

dx = (tx-sx)
dy = (ty-sy)

first = dx*'R'+dy*'U'+dx*'L'+dy*'D'
second = 'D'+(dx+1)*'R'+(dy+1)*'U'+'L'+'U'+(dx+1)*'L'+(dy+1)*'D'+'R'

print(first+second)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
  ll ans = INT64_MAX;
  for (int i = 0; i <= x || i <= y; i++)
  {
    if (x - i >= 0 && y - i >= 0)
    ans = min(ans, (ll) a * (x - i) + b * (y - i) + (i * 2 * c));
    else if (x - i < 0 && y - i >= 0)
    ans = min(ans, (ll) b * (y - i) + (i * 2 * c));
    else if (x - i >= 0 && y - i < 0)
    ans = min(ans, (ll) a * (x - i) + (i * 2 * c));
    else 
    ans = min(ans, (ll)(i * 2 * c));
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    d = 0
    ans = 0
    k = 0
    for i in s:
        if i == "R":
            if d == 0:
                k = 1
            d += 1
            d %= 4
            if d == 0 and k:ans += 1
        else:
            if d == 0:
                k = 0
            d -= 1
            d %= 4
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()



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

int main() {
  int N;
  cin >> N;
  vector<int> price(N);
  vector<int> cost(N);
  for (int i = 0; i < N; i++) {
    cin >> price[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> cost[i];
  }
  int value = 0;
  for (int i = 0; i < N; i++) {
    if (price[i] > cost[i]) {
      value += price[i] - cost[i];
    }
  }
  cout << value << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

signed main(){
    int a,b,k;
    cin >> a >> b >> k;
    int cnt = 0;
    for(int i = max(a,b);i >= 1;i--){
        if(a%i ==0 && b%i == 0)cnt++;
        if(cnt == k){
            cout << i << endl;
            return 0;
        }
    }
 
    

    
    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc059.contest.atcoder.jp/tasks/arc059_a
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

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

using namespace std;

int main(){
	string str; cin >> str;
	string ans = "YAKI";
	bool flag = true;
	if( str.size() >= 4){
		for(int i = 0; i < 4; i++){
			if(str[i] != ans[i]){
				flag = false;
				break;
			}
		}
		if(flag){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int long long

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); ++i)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    ll N;
    cin >> N;

    ll a = (int)ceil(sqrt(N));
    ll m = INF;
    REP2(i, 1, a) {
        if (N % i == 0) {
            m = min(m, N / i + i);
        }
    }
    cout << m - 2 << endl;

    return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    char C;
    cin >> C;

    cout << (char)(C+1) << endl;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)

double const eps=1e-8;
double const inf = 1e10;
double const pi = acos(-1);

typedef complex<double> P;
inline double cross(const P& a, const P& b){return imag(conj(a)*b);}
inline double dot(const P& a, const P& b){return real(conj(a)*b);}
struct L : public vector<P> {
    L(const P &a, const P &b){push_back(a); push_back(b);}
    L(){}
};
P projection(const L &l, const P &p){double t = dot(p-l[0],l[0]-l[1])/norm(l[0]-l[1]);return l[0]+t*(l[0]-l[1]);}
inline double distanceLP(const L &l, const P &p){return abs(p-projection(l, p));}
P innerCenter(P a, P b, P c){double la=abs(b-c), lb=abs(c-a), lc=abs(a-b);return (la*a+lb*b+lc*c)/(la+lb+lc);}

int n;
P ps[128];
L es[128];

enum { OUT, ON, IN };
int convex_contains(const P &p) {
    P g=(ps[0]+ps[n/3]+ps[2*n/3])/3.0;
    int a=0,b=n;
    while (a+1 < b) {
        int c=(a+b)/2;
        if (cross(ps[a]-g, ps[c]-g) > 0) {
            if (cross(ps[a]-g, p-g) > 0 && cross(ps[c]-g, p-g) < 0) b = c;
            else                                                    a = c;
        } else {
            if (cross(ps[a]-g, p-g) < 0 && cross(ps[c]-g, p-g) > 0) a = c;
            else                                                    b = c;
        }
    }
    b %= n;
    if (cross(ps[a] - p, ps[b] - p) < 0) return 0;
    if (cross(ps[a] - p, ps[b] - p) > 0) return 2;
    return 1;
}

double solve(){
    rotate(ps,ps+rand()%n,ps+n);
    ps[n]=ps[0];
    rep(i,n){
        es[i]={ps[i],ps[i+1]};
    }
    P p=innerCenter(ps[0],ps[n/3],ps[n/3*2]);

    if(n==3)return distanceLP(es[0],p);

    double const r[]={100,10,1,1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7,1e-8};
    double static d[128];
    int near=0;
    rep(t,11){
        rep(u,3000){
            rep(i,n)d[i]=distanceLP(es[i],p);
            near=0;
            rep(i,n)if(d[i]<d[near])near=i;
            P h=projection(es[near],p);
            P np=p-(h-p)/d[near]*r[t];
            if(convex_contains(np)==IN){
                swap(p,np);
            } else {
                break;
            }
        }
    }
    return d[near];
}

int main(){
    srand(time(0));
    while(cin>>n && n){
        rep(i,n){
            double x,y;
            scanf("%lf%lf",&x,&y);
            ps[i]=P(x,y);
        }
        printf("%lf\n",solve());
    }
}

Measured memory_bytes: 1292
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then (
                if flag then cur :: acc else acc
            ) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) 0 false (cur :: acc)
                | false, ' ' -> loop (i + 1) 0 false acc
                | true,  v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
                | false, v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
            )
        in
        List.rev (loop 0 0 false [])
    in
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let arr = Array.init m (fun _ -> List.tl (split (read_line ()))) in
        let p = Array.of_list (split (read_line ())) in
        let sw = Array.make m 0 in
        for i = 0 to m - 1 do
            sw.(i) <- List.fold_left (fun acc v -> acc lor (1 lsl (v - 1))) 0 arr.(i)
        done;
        let count bits =
            let rec loop i acc =
                if i = 0 then acc else loop (i / 2) (acc + i land 1)
            in
            loop bits 0
        in
        let forall bits switch p =
            let rec loop i =
                if i < 0 then true else
                if count (switch.(i) land bits) mod 2 = p.(i) then loop (i - 1) else false
            in
            loop (m - 1)
        in
        let rec loop i acc =
            if i < 0 then acc else
                let acc = if forall i sw p then acc + 1 else acc in
                loop (i - 1) acc
        in
        let ans = loop ((1 lsl n) - 1) 0 in
        Printf.printf "%d\n" ans
    in
    main ()

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	//int t;
	//cin >> t;
	//while(t--)
	//{
		long long a,b,k;
		cin >> a >>b >> k;
		if(a<k)
		{
			long long temp = k-a;
			if(temp < b)
			{
				long long temp2 = b-temp;
				cout << 0 << " " << temp2;
			}
			else
				cout << 0 <<" " << 0 ;
		}
		else
		{
			long long temp = a-k;
			cout << temp << " " << b;
		}

	//}
	return 0;
}

Measured memory_bytes: 256
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};module.exports=I;

function main(input) {
  const o = new I(input);

  const N = o.a();
  const T = o.a();

  let c = [];
  let t = [];
  for (let i=0;i<N;i++) {
    c.push(o.a()); 
    t.push(o.a()); 
  }

  let min = Infinity;
  for (let i=0;i<N;i++) {
    if (t[i] <= T && c[i] < min) {
      min = c[i];
    }
  }

  if (!Number.isFinite(min)) {
    console.log("TLE");
  } else {
    console.log(min);
  }
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7756
#include <cstdio>
#include <vector>
#include <iostream>

using namespace std;

const int size = 1005;
vector<int> gra[size];
int vis[size];

int n, m;
int ans = 0;

void dfs(int a, int num) {
	if(num == n) {
		ans ++;
		return ;
	}

	for ( int i = 0; i < gra[a].size(); i ++ ) {
		if(!vis[gra[a][i]]) {
			vis[gra[a][i]] = 1;
			dfs(gra[a][i], num+1);
			vis[gra[a][i]] = 0;
		}
	}
}

int main() {	
	scanf("%d %d", &n, &m);
	for ( int i = 1; i <= m; i ++ ) {
		int u, v;
		scanf("%d %d", &u, &v);
		gra[u].push_back(v); gra[v].push_back(u);
	}

	vis[1] = 1;
	dfs(1, 1);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))

p_dash = []
for i in range(n):
    p_dash.append((p[i] + 1) / 2)

ans_max = 0
for i in range(k):
    ans_max += p_dash[i]

temp = ans_max
for i in range(k, n):
    temp = temp - p_dash[i - k] + p_dash[i]
    if(temp > ans_max):
        ans_max = temp

print(ans_max)

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

typedef long int				int32;
typedef unsigned long int		uint32;
typedef long long int			int64;
typedef unsigned long long int  uint64;
typedef pair<int, int>			PII;
typedef vector<int>				VI;
typedef vector<long long>		VLL;
typedef vector<string>			VS;
typedef vector<PII>				VII;
typedef vector<VI>				VVI;

#define MEM(a, b)				memset(a, (b), sizeof(a))
#define calctime				std::cout << setprecision(5) << fixed << "Time to completed program: " << (double)(clock() - start)/(CLOCKS_PER_SEC) << "s.\n";
#define FOR(i, j, k, in)		for (int i = (j); i < (k); i += (in))
#define FORW(i, j, k, in)		for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in)		for (int i = (j); i >= (k); i -= (in))
#define RFORW(i, j, k, in)		for (int i = (j); i > (k); i -= (in))
#define aint64(cont)			cont.begin(), cont.end()
#define raint64(cont)			cont.end(), cont.begin()
#define sz(cont)				int((cont).size())
#define PB						push_back
#define MP						make_pair
#define EPS						1e-9
#define MOD						1000000007
#define PI						3.1415926535897932384626433832795
#define Ff						first
#define Ss						second
#define FastIO					ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define fileIO(name)			ifstream iFs(name".inp"); ofstream oFs(name".out");
#define fileio(name)			ifstream cin(name".inp"); ofstream cout(name".out");
#define endl					'\n'

//int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, -1, 0, 1, 1, -1, -1, 1};	

int main() {
	FastIO;
#ifndef ONLINE_JUDGE
	//fileio("input");		//Remember to change this
#endif

	int n; cin >> n;
	int a[3][100000] = {}; FOR(i, 0, n, 1) cin >> a[0][i] >> a[1][i] >> a[2][i];
	int dp[3][100000] = { {a[0][0]}, {a[1][0]}, {a[2][0]} };
	FOR(i, 1, n, 1) {
		dp[0][i] = max(dp[1][i - 1] + a[0][i], dp[2][i - 1] + a[0][i]);
		dp[1][i] = max(dp[0][i - 1] + a[1][i], dp[2][i - 1] + a[1][i]);
		dp[2][i] = max(dp[0][i - 1] + a[2][i], dp[1][i - 1] + a[2][i]);
	}

	cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1]));

	//calctime
	return 0;
}

Measured memory_bytes: 5920
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define all(x) (x).begin(), (x).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll sum = 0;
    vector<ll> a(100010, 0);
    rep(i, 0, n) {
        ll x;
        cin >> x;
        sum += x;
        a[x]++;
    }
    int q;
    cin >> q;
    rep(i, 0, q) {
        ll b, c;
        cin >> b >> c;
        sum += (c - b) * a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3992
N, x = map(int, input().split())
li = list(map(int, input().split()))

result = 0

if x == 0:
  result = sum(li)
  pass
else:
  for i in range(N-1):
    S = li[i] + li[i+1]
    if S <= x:
      pass
    else:
      eat = S - x
      result += eat
      if eat <= li[i+1]:
        li[i+1] = li[i+1] - eat
      else:
        li[i+1] = 0

print(result)

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 105;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

ll a[maxN][maxN];
ll c[maxN];

int main()
{
	
	int n,m;
	ll x;
	scanf("%d%d",&n,&m);
	scanf("%lld",&x);
	ll ans = INF;
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&c[i]);
		for(int j=0;j<m;j++)
		{
			scanf("%lld",&a[i][j]);
		}
	}
	int M = (1<<n);
	
	for(int k=0;k<M;k++)
	{
		ll sum = 0;
		vector<ll> t(m+1);
		for(int i=0;i<n;i++)
		{
			if((k&(1<<i)) != 0)
			{
				for(int j=0;j<m;j++)
				{
					t[j] += a[i][j];
				}
				sum += c[i];
			}
		}
		int flag = 0;
		for(int i=0;i<m;i++)
		{
			if(t[i] < x)
			{
				flag = 1;
				break;
			}
		}
		if(!flag)
		{
			ans = min(ans,sum);
		}
	}
	if(ans == INF)
	{
		puts("-1");
	}
	else
	{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; ++i) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3636
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]

    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] + args[3] + text[b + 1:]

Measured memory_bytes: 6728
#include<iostream>
#include<stdio.h>
using namespace std;
int a[200050], b[200050];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	b[n / 2 + 1] = a[1];
	if (n % 2)
	{
		for (int i = 1; i <= n / 2; i++)
		{
			b[n / 2 + 1 + i] = a[2 * i];
			b[n / 2 + 1 - i] = a[2 * i + 1];
		}
	}
	else
	{
		for (int i = 1; i <= n / 2; i++)
		{
			b[n / 2 + 1 - i] = a[2 * i];
		}
		for (int i = 1; i < (n / 2); i++)
		{
			b[n / 2 + 1 + i] = a[2 * i + 1];
		}
	}
	for (int i = 1; i < n; i++)
		printf("%d ", b[i]);
	printf("%d\n", b[n]);
	return 0;
}

Measured memory_bytes: 3712
N, M =list( map(int, input().split()) )


ab = []
for _ in range(M):
  ab.append(list(map(int, input().split())))
  
           
bridges = [0] * N
            
for c in range(N):
  for i in range(M):
    if c+1==ab[i][0] or c+1==ab[i][1]:
      bridges[c] += 1
            
 
for _ in range(N):
  print(bridges[_] ) 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int(i) = 0; (i) < (n); (i)++)
int main(){
  int64_t A, B, C, K;
  string S, T;
  cin >> A >> B >> C >> K;
  int64_t ans = 0;
  if (K < A + B){
    ans = K;
  }else{
    ans = A - (K-A-B);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
while True:
    n=input()
    if n==0:break
    L=[]
    for	i in range(n):
	m,a,b=map(int,raw_input().split())
	L.append((a,1,m))
	L.append((b,0,m))
    L.sort()
    wgt=0
    for ts,p,w in L:
	if p:
            wgt+=w
        else:
            wgt-=w
    	if wgt>150:
            print "NG"
            break
    else:
	print "OK"

Measured memory_bytes: 4244
//suhan lee,saitama university

//suhan lee,saitama university
#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <complex>
using namespace std;
 
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
 
#define all(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define repn(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
#define pb push_back 
#define pf push_front


int num,p,q,a,n;
void sai(int len,int ue,int sita,int pre){
  if(len>n) {
    //  cout<<ue<<" "<<sita<<" kk"<<len<<endl;
return;}
  if(ue*q==sita*p) {
    // cout<<ue<<" "<<sita<<" "<<len<<endl;
    num++;
    return;
  }
  // else if(ue*q>sita*p) {
  //   return;
  // }
  if(pre*sita+sita<=a)
    sai(len,ue,sita,pre+1);
  ue*=pre;
  ue+=sita;
  sita*=pre;
  if(ue*q>sita*p||sita>a) {
    //  cout<<ue<<" dd"<<sita<<" "<<len<<endl;
    return;
  }
  else sai(len+1,ue,sita,pre);
}
int main(){

  while(true){
    cin>>p>>q>>a>>n;
    num=0;
    if(!(p||q||a||n)) return 0;
    sai(0,0,1,1);
    cout<<num<<endl;
    
  }
  return 0;
}

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

int main() {

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int ans = 0;
	if (A > B) ans += B;
		else ans += A;
	if (C > D) ans += D;
		else ans += C;

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


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

int main2() {
  ll A = nextInt();
  ll B = nextInt();
  ll C = nextInt();
  ll X = nextInt() * 2;
  ll Y = nextInt() * 2;

  ll ans = 1LL << 61;
  for (int c = 0; c <= max(X, Y); c++) {
    ll am = C * c;
    ll AA = max(0LL, X - c);
    ll BB = max(0LL, Y - c);
    am += (AA+1)/2 * A;
    am += (BB+1)/2 * B;
    chmin(ans, am);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5;
long long l,r,N,K,a[maxn],f[maxn];
inline long long read(){
	long long x=0,f=1;
	char c;
	do{c=getchar();if(c=='-'){f*=-1;}}while(!isdigit(c));
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
bool check(long long now){
	long long cur=0,q;
	for(int i=1;i<=N;i++){
		if(a[i]*f[N-i+1]<=now){continue;}
		else{
			q=a[i]*f[N-i+1]-now;
			cur+=(((q-1)/f[N-i+1])+1);
		}
	}
	return cur<=K;
}

int main(){
	N=read();
	K=read();
	for(int i=1;i<=N;i++){a[i]=read();}
	for(int i=1;i<=N;i++){f[i]=read();}
	sort(a+1,a+N+1);
	sort(f+1,f+N+1);
	l=0;r=1e18;
	while(l!=r){
		long long mid=(l+r)/2;
		bool flag=check(mid);
		if(flag){r=mid;}
		else{l=mid+1;}
	}
	printf("%lld\n",(l+r)/2);
	return 0;
}

Measured memory_bytes: 5888
#include<iostream>
using namespace std;
int gcd(int a,int b){
    int r=a%b;
    while(r>0){
        a = b;
        b = r;
        r = a%b;
    }
    return(b);
}

int main(){
    int N;
    cin >> N;
    int cnt=0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            for(int k=1;k<=N;k++){
                cnt += gcd(gcd(i,j),k);
            }
        }
    }

    cout << cnt << endl;

    return(0);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
using namespace std;
const int maxn = 5e5 + 10;
vector<pii> qry[maxn];
int n, q, c[maxn], pre[maxn], lst[maxn], ans[maxn];

struct SegmentTree{
	#define ls (o << 1)
	#define rs (o << 1 | 1)
	int sum[maxn << 2];
	void update(int o, int l, int r, int x) {
		++sum[o];
		if (l == r) return ;
		int mid = (l + r) >> 1;
		if (x <= mid) update(ls, l, mid, x);
		else update(rs, mid + 1, r, x);
	}
	int query(int o, int l, int r, int ql, int qr) {
		if (ql <= l && r <= qr) {
			return sum[o];
		}
		int mid = (l + r) >> 1, ret = 0;
		if (ql <= mid) ret = query(ls, l, mid, ql, qr);
		if (qr > mid) ret += query(rs, mid + 1, r, ql, qr);
		return ret;
	}
}sgt;

int main()
{
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &c[i]);
	for (int i = 1; i <= n; ++i) {
		pre[i] = lst[c[i]];
		lst[c[i]] = i;
	}
	for (int i = 1, l, r; i <= q; ++i) {
		scanf("%d%d", &l, &r);
		qry[l - 1].pb(mp(l - 1, -i));
		qry[r].pb(mp(l - 1, i));
	}
	for (int i = 1; i <= n; ++i) {
		sgt.update(1, 0, n, pre[i]);
		for (auto x : qry[i]) {
			if (x.second > 0)
				ans[x.second] += sgt.query(1, 0, n, 0, x.first);
			else 
				ans[-x.second] -= sgt.query(1, 0, n, 0, x.first);
		}
	}
	for (int i = 1; i <= q; ++i)
		printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 44308
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int n;
const int N = 2e5 + 1;
int pwmd(int n, int m)
{
    int res = 1;
    while (m > 0)
    {
        if (m & 1)
            res = (res % mod * n % mod) % mod;
        m /= 2;
        n = (n % mod * n % mod) % mod;
    }
    return res;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    map<pair<int, int>, int> m;
    int total = 1;
    int zero = 0;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0)
        {
            zero++;
            continue;
        }
        else
        {
            int g = gcd(a, b);
            a /= g;
            b /= g;
            if (a < 0)
                a = -a, b = -b;
        }
        m[{a, b}]++;
    }
    for (auto i : m)
    {
        if (i.second == 0)
            continue;
        int a = i.first.first;
        int b = i.first.second;
        int v = pwmd(2, i.second);
        // deb2(a, b);

        b = -b;
        if (b < 0)
            a = -a, b = -b;

        if (m.find({b, a}) != m.end())
        {
            v = (v + pwmd(2, m[{b, a}]) - 1) % mod;
            m[{b, a}] = 0;
        }
        total = (total * (v)) % mod;
    }
    total = (total - 1 + zero + mod) % mod;
    cout << total;
    return 0;
}


Measured memory_bytes: 16108
fun main(args: Array<String>) {
    abc118b()
}

fun abc118b() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val kaList = (1..n).map { readLine()!!.split(" ").map { it.toInt() }.drop(1) }

    var intersected = kaList[0].toSet()
    (1 until kaList.size).forEach { intersected = intersected.intersect(kaList[it]) }

    println(intersected.count())
}


Measured memory_bytes: 37848
n=int(input())
wl=list(map(int,input().split()))
totalw=sum(wl)
ans=[]
for t in range(1,n):
  s1=0
  for i in range(t):
    s1+=wl[i]
  s2=totalw-s1
  ans.append(abs(s1-s2))
ans.sort()
print(ans[0])


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;


int N, K, D;
bool B[10];

int main() {
	cin >> N >> K;
	for (int i = 0; i != K; ++i) {
		cin >> D;
		B[D] = true;
	}
	for (int i = N;; ++i) {
		int k = i;
		bool f = true;
		while (k) {
			if (B[k % 10]) {
				f = false;
				break;
			}
			k /= 10;
		}
		if (f) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
def getlist():
	return list(map(int, input().split()))

#初期化
N = int(input())
A = getlist()
S = sum(A)
if S % (N * (N + 1) // 2) != 0:
	print("NO")
#計算
else:
	judge = "YES"
	n = S // (N * (N + 1) // 2)
	for i in range(N):
		val = A[(i + 1) % N] - A[i]
		if val < n * (1 - N) or val > n or (val - n) % N != 0:
			judge = "NO"

	print(judge)

Measured memory_bytes: 15060
//b.c B-Christmas Eve Eve
#include<stdio.h>

int main(void){
    int n;
    scanf("%d\n",&n);
    int p[n];
    for(int i=0;i<n;++i){
        scanf("%d",&p[i]);
    }

    int max = p[0];
    int maxnum = 0;
    for(int i=0;i<n;++i){
        if(max<p[i]){
            max = p[i];
            maxnum = i;
        }
    }

    int sum = 0;
    for(int i=0;i<n;++i){
        if(i!=maxnum){
            sum += p[i];
        }else{
            sum += (p[i]/2);
        }
    }

    printf("%d\n",sum);
    return 0;
}

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

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

//vector<vector<ll> > comb(ll n, ll b){
void comb(vector<vector <ll> > &v, ll n){
  cout << v.size();
  rep(i, n){
    v[i][0] = 1;
    v[i][i] = 1;
  }

  rep(j, n) {
    rep(k,j) {
      v[j][k] = (v[j-1][k-1] + v[j-1][k]);
    }
  }
}


int main(){
  ll n;
  cin >> n;
  ll ans;
  vector<ll> v(n);

  if (n==1) {
    cin >> ans;
    cout << ans << endl;
      return 0;
  }

  if (n%2==0){
    rep(i,n) {
      if (i%2==0) cin >> v.at(i/2+n/2);
      else cin >> v.at(-i/2+n/2-1);
    }
  }
  else {
    rep(i,n){
    if (i==0) cin >> v.at(n/2);
    else if (i%2==1) cin >> v.at(i/2+n/2+1);
    else cin >> v.at(-i/2+n/2);
    }
  }
  rep(i,n) cout << v.at(i) << " ";
  cout << endl;


}

Measured memory_bytes: 3712