akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String c = sc.next();
		
		if (c.equals("a") || c.equals("i") || c.equals("u")
				|| c.equals("e") || c.equals("o"))
			System.out.println("vowel");
		else  System.out.println("consonant");
	}
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool cmp1(T a, T b) {
  return a.mn > b.mn;
}

bool cmp2(T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
 ///return a.top - a.mn > b.top - b.mn;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}


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

int main()
{
	 int  n;
	 int a[105]={0};
	  double sum=0;
	 cin>>n;
	 for(int i=0;i<n;i++)
	 {cin>>a[i];
	 sum+=a[i];
	 }
	sum/=n;
	int ans=0;
	
	for(int i=0;i<n;i++)
	{
		if(fabs(sum-a[i])<fabs(sum-a[ans]))
		{
			ans=i;
		}
	}
	cout<<ans<<endl;
 } 

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

int main() {
  int N;
  cin >> N;
  int m = 1000000000;
  int mc = 0;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x < 0) mc += 1;
    sum += abs(x);
    m = min(m,abs(x));
  }
  cout << (mc % 2 == 0 ? sum : sum - 2*m) << endl;
}

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

#define MAXN 705

using namespace std;





int n, cnt, dsu[MAXN], sz[MAXN], col[MAXN];
int mp[MAXN][MAXN];
int n2, c[MAXN][2], sum[MAXN];
int dp[MAXN][MAXN];

int find_dsu(int u)
{
    if (u ^ dsu[u])
        return dsu[u] = find_dsu(dsu[u]);
    else
        return u;
}

void merge_dsu(int u, int v)
{
    u = find_dsu(u);
    v = find_dsu(v);
    if (u ^ v) {
        dsu[u] = v;
        sz[v] += sz[u];
    }
}

bool dfs(int u, int colo)
{
    col[u] = colo;
    if (colo)
        cnt++;
    for (int i = 1; i <= n; i++) {
        if (!mp[u][i] && i != u) {
            if (col[i] == -1) {
                if (!dfs(i, colo ^ 1))
                    return false;
            } else if (col[i] != colo ^ 1)
                return false;
        }
    }
    return true;
}


int solve()
{
    for (int i = 1; i <= n; i++) {
        sz[i] = 1;
        dsu[i] = i;
        col[i] = -1;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++)
            if (!mp[i][j])
                merge_dsu(i, j);
    for (int i = 1; i <= n; i++)
        find_dsu(i);
    n2 = 0;
    sum[0] = 0;
    for (int i = 1; i <= n; i++)
        dp[0][i] = n * n;
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        if (find_dsu(i) != i)
            continue;
        cnt = 0;
        if (!dfs(i, 0))
            return -1;
        n2++;
        c[n2][0] = cnt;
        c[n2][1] = sz[i] - cnt;
        sum[n2] = sum[n2 - 1] + sz[i];
        for (int j = 0; j <= n; j++) {
            dp[n2][j] = n * n;
            for (int k = 0; k < 2; k++) {
                int last = j - c[n2][k];
                if (last >= 0) {
                    int tmp = dp[n2 - 1][last];
                    tmp += last * c[n2][k];
                    tmp += c[n2][k ^ 1] * (sum[n2 - 1] - last);
                    dp[n2][j] = min(dp[n2][j], tmp);
                }
            }
        }
    }
    int ans = n * n;
    for (int i = 0; i <= n; i++)
        ans = min(ans, dp[n2][i]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++)
            if (mp[i][j] && find_dsu(i) == find_dsu(j) && col[i] == col[j])
                ans += mp[i][j];
    return ans;
}

int main()
{
    int m;
    //freopen("e.txt", "r", stdin);
    while (cin >> n >> m) {
        memset(mp, 0, sizeof(mp));
        int u, v;
        while (m--) {
            scanf("%d%d", &u, &v);
            mp[u][v]++;
            mp[v][u]++;
        }
        cout << solve() << endl;

    }
    return 0;

}


Measured memory_bytes: 4096
import java.util.*;

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

        if (s.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 35480
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        int N = RInt();
        var d = new SortedSet<int>();
        for (int i = 0; i < N; i++)
        {
            d.Add(RInt());
        }
        WriteLine(d.Count);
    }
}

class Scanner
{
    
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[0], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[0], typeof(T4));
        return (r1, r2, r3, r4);
    }

}




Measured memory_bytes: 27868
#include<stdio.h>
int main()
{
    int a[6],i,x,y,z,min;
    scanf("%d%d%d",&x,&y,&z);
    a[0]=x+y;
    a[1]=x+z;
    a[2]=z+y;
    min=a[0];
    for(i=0; i<3; i++)
    {
        if(min>a[i])
            min=a[i];
    }
    printf("%d\n",min);

    return 0;
}


Measured memory_bytes: 128
using System;

namespace AizuOnline
{
    class Program
    {
        static void Main(string[] args)
        {
            int sec = Int32.Parse(Console.ReadLine());
            int hour = sec / 3600;
            sec -= hour * 3600;
            int minute = sec / 60;
            sec -= minute * 60;
            Console.WriteLine("{0}:{1}:{2}", hour, minute, sec);
        }
    }
}



Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    double pi=3.141592653589793;
    double A,B,H,M;
    cin>>A>>B>>H>>M;
    
    double hor=H*30+M/2;
    double min=M*6;
    
    
    
    double R=abs(hor-min)/180;
    //cout<<hor<<endl;
    //cout<<min<<endl;
    //cout<<abs(hor-min)<<endl;
    double r=R*pi;
    double c=sqrt(A*A+B*B-2*A*B*cos(r));
    if (hor-min==0||hor-min==360) c=abs(A-B);
    //cout<<hor<<endl<<min<<endl;
    //cout<<cos(r)<<endl;
    cout<<fixed << setprecision(15)<<c;
    
}

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

int min(int a,int b){
    return (a<b)? a : b ;
}

ll f(ll x){
    if(x==1) return 1 ;
    return f(x/2)*2+1 ;
}

int main() {
    ll h ;
    cin >> h ;

    cout << f(h) << endl ;
    return 0 ;
}


Measured memory_bytes: 3652
n, k = map(int, input().split())
r, s, p = map(int, input().split())
com = input()

dic_p = {"r": r, "s": s, "p": p}
dic_win = {"r": "p", "s": "r", "p": "s"}
player = [dic_win[c] for c in com]

point = 0
for i in range(n):
    if i - k < 0 or (i - k >= 0 and player[i] != player[i - k]):
        point += dic_p[player[i]]
    else:
        if player[i] == player[i - k]:
            player[i] = ""

print(point)


Measured memory_bytes: 4212
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;
int h, w, k, ans = 1000000;
int dis[800][800];
string s[800];
queue<pair<int, int> > q;
int main() {
  cin >> h >> w >> k;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == 'S') {
        dis[i][j] = 0;
        q.push({i, j});
      } else {
        dis[i][j] = 1000000;
      }
    }
  }
  while (!q.empty()) {
    int x, y;
    x = q.front().first;
    y = q.front().second;
    q.pop();
    if (dis[x][y] == k + 1) {
      break;
    }
    ans = min(ans, (k - 1 + x) / k);
    ans = min(ans, (k - 1 + y) / k);
    ans = min(ans, (k - 1 + h - 1 - x) / k);
    ans = min(ans, (k - 1 + w - 1 - y) / k);
    if (x != 0 && s[x - 1][y] == '.' && dis[x - 1][y] > dis[x][y] + 1) {
      dis[x - 1][y] = dis[x][y] + 1;
      q.push({x - 1, y});
    }
    if (x != h - 1 && s[x + 1][y] == '.' && dis[x + 1][y] > dis[x][y] + 1) {
      dis[x + 1][y] = dis[x][y] + 1;
      q.push({x + 1, y});
    }
    if (y != 0 && s[x][y - 1] == '.' && dis[x][y - 1] > dis[x][y] + 1) {
      dis[x][y - 1] = dis[x][y] + 1;
      q.push({x, y - 1});
    }
    if (y != w - 1 && s[x][y + 1] == '.' && dis[x][y + 1] > dis[x][y] + 1) {
      dis[x][y + 1] = dis[x][y] + 1;
      q.push({x, y + 1});
    }
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INFTY 200000000000
long long dp[310][310];
vector<long long> a(310);
int b;
const double PI=3.1415926535897932;
int main(){
    ll n;cin>>n;
    vector<ll> a(n+1);
    for (int i = 0; i <=n; i++)
    {
        a[i] = 0;
    }
    
    for (int i = 1; i < n; i++)
    {
        int p;cin >>p;
        a[p]+=1;
    }

    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << endl;
    }
    
    


    return 0;
}

Measured memory_bytes: 4792
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            double d = ((double)((N+1) / 2)) / (double)N;

            Console.WriteLine(d);
        }
    }
}



Measured memory_bytes: 13140
while True:
    try:
        w = int(raw_input())
        cu = [2**i for i in range(10)]
        all = 1023
        i = 9
        while all != w:
            if all > w:
                all -= cu[i]
                cu[i] = 0
                i -= 1
            if all < w:
                all = all + 2*cu[i] - cu[i]
                cu[i+1] = 2*cu[i]
                cu[i] = 0
                i -= 1
        for j in range(cu.count(0)):
            cu.remove(0)
        print (" ".join(map(str, cu)))
    except:
        break

Measured memory_bytes: 4232
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        final String S = scan.next();
        scan.close();
        int length = S.length();
        String moji;
        String result = "Yes";
        for(int i = 1; i <= length; i++){
            moji = S.substring(i - 1, i);
            if(i % 2 == 1){
                if(moji.equals("R") || moji.equals("U") || moji.equals("D")){
                    // OK
                }else{
                    result = "No";
                    break;
                }
            }else{
                if(moji.equals("L") || moji.equals("U") || moji.equals("D")){
                    // OK
                }else{
                    result = "No";
                    break;
                }
            }
        }
        System.out.println(result);
        

    }
        
    
}


Measured memory_bytes: 23124
N, W = map(int, input().split())
max_value = N*(10**3)
dp = [[10**11]*(max_value+1) for _ in range(N+1)]
dp[0][0]=0
for j in range(1, N+1):
    w, v = map(int, input().split())
    for k in range(0, max_value+1):
        if k < v:
            dp[j][k] = dp[j-1][k]
        else:
            dp[j][k] = min(dp[j-1][k-v]+w, dp[j-1][k])
answer = 0
for index, weight in enumerate(dp[N]):
    if weight <= W:
        answer = index
print(answer)

Measured memory_bytes: 119280
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x = ii()
dp = [0]*201
for i in range(1,201):
    dp[i] = i**5
from bisect import bisect_left as bl
'''index  =  bl(list,num)'''
for i in range(1,200):
    index = bl(dp,dp[i]+x)
    if index == 201:
        continue
    if dp[index] == dp[i] +x:
        print(index,i)
        exit()

for i in range(1,200):
    index = bl(dp,-dp[i]+x)
    if index == 201:
        continue
    if dp[index] == -dp[i] +x:
        print(index,-i)
        exit()



Measured memory_bytes: 9164
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits<int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair<T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map<T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template<typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector <int> a(n+1), b(m+1);
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 1; i <= m; ++i)
		cin >> b[i];
	for (int i = 1; i <= max(n, m);  ++i) {
		if (i <= n)
			a[i]+= a[i-1];
		if (i <= m)
			b[i]+= b[i-1];
	}
	int i = 0, j = m, count = b[m], ans = 0;
	while (i < n) {
		while (j-1 >= 0 && count > k) {
			count-= b[j--];
			count+=b[j];
		}
		if (count <= k)
			ans = max(ans, i + j);
		count-= a[i];
		count+= a[i + 1];
		i++;
	}
	if (count <= k)
		ans = max(ans, i + j);
	cout << ans << '\n';
	return 0;
}


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

int main(){
  string mp[]={"Rock","Gun","Lightning","Devil","Dragon","Water","Air","Paper","Sponge","Wolf","Tree","Human","Snake","Scissors","Fire"};

  int n;
  while(cin>>n,n){
    string str[1001];
    for(int i=0;i<n;i++) cin>>str[i];
    
    string ans="Draw";
    set<string> S;
    for(int i=0;i<n;i++){
      if(S.count(str[i]))continue;
      S.insert(str[i]);
      int A=0;
      while(str[i]!=mp[A])A++;	
      int j;
      for(j=0;j<n;j++){
	if(str[i]==str[j])continue;
	int B=0;
	while(str[j]!=mp[B])B++;	
	if((15+B-A)%15<=7)break;
      }
      if(j==n) ans=str[i];
    }
    
    for(int i=1;i<n&&str[0]==str[i];i++)if(i==n-1)ans="Draw"; 

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

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

int main() {
  string s;
  cin >> s;
  int a = 0, b = 0;
  rep(i, s.size()) {
    if (s[i] == '+')
      a++;
    else
      b++;
  }
  cout << a - b << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:10240000")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

map <int, bool> p;

int main ()
{
    int n;
    scanf ("%d", &n);
    int num = 0;
    p.clear ();
    for (int i = 1; i <= n; i ++)
    {
        int x;
        scanf ("%d", &x);
        if (p[x])
        {
            p[x] = false;
            num --;
        }
        else
        {
            p[x] = true;
            num ++;
        }
    }
    printf ("%d\n", num);
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string s[26][26];
	int h,w;
	cin>>h>>w;

	int number;
	char c;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin>>s[i][j];
			if(s[i][j]=="snuke"){
				c='A'+j;
				number=i+1;
			}
		}
	}

	cout<<c<<number<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  int n,x;
  cin >> n >> x;
  vi data(n);
  rep(i,n) cin >> data[i];
  vi data2(n+1);
  data2[0] = 0;
  repa(i,1,n+1) data2[i] = data2[i-1] + data[i-1];
  int ans = 0;
  rep(i,n+1) if(data2[i] <= x) ans++;
  cout << ans;
  hinata;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 510
int f[N][N],n,que[N*N][2],c[N][N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j){
		f[i][j]=min(min(i,n+1-i),min(j,n+1-j));
		c[i][j]=1;
	}int ans=0;
	for(int i=1;i<=n*n;++i){
		int x,y,P;scanf("%d",&P);
		x=(P-1)/n+1;y=P-(x-1)*n;
		int R=min(min(f[x+1][y],f[x-1][y]),min(f[x][y+1],f[x][y-1]));
		ans=ans+R;
		c[x][y]=0;f[x][y]=R;
		int t=1;
		que[1][0]=x;que[1][1]=y;
		for(int i=1;i<=t;++i){
			x=que[i][0],y=que[i][1];
			if(y&&f[x][y-1]>f[x][y]+c[x][y-1]){
				f[x][y-1]=f[x][y]+c[x][y-1];++t;
				que[t][0]=x;que[t][1]=y-1;
			}
			if(y&&f[x][y+1]>f[x][y]+c[x][y+1]){
				f[x][y+1]=f[x][y]+c[x][y+1];++t;
				que[t][0]=x;que[t][1]=y+1;
			}
			if(y&&f[x-1][y]>f[x][y]+c[x-1][y]){
				f[x-1][y]=f[x][y]+c[x-1][y];++t;
				que[t][0]=x-1;que[t][1]=y;
			}
			if(y&&f[x+1][y]>f[x][y]+c[x+1][y]){
				f[x+1][y]=f[x][y]+c[x+1][y];++t;
				que[t][0]=x+1;que[t][1]=y;
			}
		}
	}printf("%d",ans);
}

Measured memory_bytes: 7660
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int D; cin>>D;
	vector<int> cs(26);
	vector<vector<int>> s(D,vector<int> (26));
	vector<int> sche(D);
	vector<int> last(26,-1);
	rep(i,26)cin>>cs[i];
	rep(i,D)rep(j,26)cin>>s[i][j];
	rep(i,D)cin>>sche[i];
	ll ans = 0;
	rep(i,D){
		int ch = sche[i]-1;
		ans += s[i][ch];
		last[ch] = i;
		rep(k,26){
			ans -= cs[k] * (i - last[k]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(void)
{
    char cardt[1024];
    char cardh[1024];
    int taro;
    int hanako;
    int cmp;
    int n;

    scanf("%d", &n);
    taro = 0;
    hanako = 0;
    while (n-- > 0){
        scanf("%s %s", cardt, cardh);
        cmp = strcmp(cardt, cardh);

        if (cmp > 0){
            taro += 3;
        }
        else if (cmp < 0){
            hanako += 3;
        }
        else {
            ++taro;
            ++hanako;
        }
    }

    printf("%d %d\n", taro, hanako);

    return (0);
}

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

using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll LNF = __LONG_LONG_MAX__;

int main(){
    int N; cin >> N;
    ll out=0;
    for(int i=1;i<=N;i++){
        //cerr << "\n" << i << "\t";
        for(int j=1;j<=N;j++){
            if(N-i*j>0)out++;
            else break;
            //cerr << j << " ";
        }
    }
    //out *= 2;
    out++;
    cout << out-1 << endl;
    return 0;
}


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


int main(){
    long long ans = 0;
    int n;
    cin >> n;
    int ind=0;
    vector<int> h = {};
    for(int i=0;i<n;i++){
        int hi;
        cin >> hi;
        h.push_back(hi);
    }

    while(1){
        int f1 = -1,f2 = -1;
        for(int i=0;i<n;i++){
            if(i == n-1 && f1 == -1){
                f1 = i;
                f2 = i;
            }else if(h[i] != 0 && f1 == -1){
                f1 = i;
            }else if(f1 != -1 && h[i] == 0){
                f2 = i-1;
            }else if(f1 != -1 && i == n-1){
                f2 = n-1;
            }

            //cerr << h[i] << " ";

            if(f1 != -1 && f2 != -1){
                if(f1 == f2){
                    ans = ans + h[f1];
                    h[f1] = 0;
                    break;
                }

                for(int j = f1;j<=f2;j++){
                    h[j] = h[j]-1;
                    //cerr << h[j] << " ";
                }
                ans++;
                break;
            }

            //cerr << f1 <<" "<< f2 << endl; 
        }
        //cerr << endl;
        //cerr << f1 << f2 << endl;

        bool flag = true;
        for(int i=0;i<n;i++){
            if(h[i] != 0){
                flag = false;
                break;
            }
        }
        if(flag){
            break;
        }
    }

    cout << ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

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

    std::string S;
    std::cin >> S;
    int A = S.find("A");
    int Z = S.rfind("Z");
    std::cout << Z - A + 1 << '\n';
    
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if (a == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = n / (a + b);
    ans *= a;
    n %= (a + b);
    ans += min(n, a);
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    string s;
    cin>>s;
    int n= s.length();
    if(s[n-1]=='s'){
        s += "es";
    }
    else{
        s += "s";
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lb long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >

using namespace std;

const int N = 100005;
const int M = 1000000007;
const lb PI = acos(-1);

ll t , n;
ll a[N] , d[N][3];

void Test()
{
    ll i;

    cin >> n;

    for(i = 1 ; i <= n ; i++)
        cin >> a[i];

    d[2][0] = a[2] + a[1];
    d[2][1] = -a[2] + (-a[1]);

    for(i = 3 ; i <= n ; i++)
    {
        d[i][0] = max(d[i - 1][0] + a[i] , d[i - 1][1] + a[i]);
        d[i][1] = max(d[i - 1][0] - a[i - 1] + (-a[i - 1]) + (-a[i]) , d[i - 1][1] - (-a[i - 1]) + a[i - 1] + (-a[i]));
    }

    cout << max(d[n][1] , d[n][0]);
}

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

    t = 1;
	//cin >> t;

	while(t--)
		Test();

    return 0;
}


Measured memory_bytes: 3328
import math


class point():
    def __init__(self, x,y):
        self.x = x
        self.y = y



n=int(input())
points = list()
for i in range(n):
    x,y = map(int,input().split())
    points.append(point(x,y))


sum = 0
for i in range(n-1):
    for j in range(i+1,n):
        sum += math.sqrt((points[i].x-points[j].x)**2+(points[i].y-points[j].y)**2)
print(sum*2/n)


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

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

  if (S.at(0) == S.at(1) && S.at(1) == S.at(2)) {
    cout << "No" << endl;
  }
  else{
  cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])

if A+B+C+D==7:
  print("{}+{}+{}+{}=7".format(A,B,C,D))
elif A-B+C+D==7:
  print("{}-{}+{}+{}=7".format(A,B,C,D))
elif A+B-C+D==7:
  print("{}+{}-{}+{}=7".format(A,B,C,D))
elif A-B-C+D==7:
  print("{}-{}-{}+{}=7".format(A,B,C,D))
elif A+B+C-D==7:
  print("{}+{}+{}-{}=7".format(A,B,C,D))
elif A-B+C-D==7:
  print("{}-{}+{}-{}=7".format(A,B,C,D))
elif A+B-C-D==7:
  print("{}+{}-{}-{}=7".format(A,B,C,D))  
elif A-B-C-D==7:
  print("{}-{}-{}-{}=7".format(A,B,C,D))

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    string S; cin >> S;
    string ans="Yes";
    for(int i=0; i<S.size(); i++){
        if(i%2==0 && S[i]=='L'){
            ans="No";
        }

        if(i%2==1 && S[i]=='R'){
            ans="No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    // スペース区切りの整数の入力
    int d;
  cin >> d;
  int data[n][d];
  int a;
  for(int i = 0;i<n;i++){
      for(int j = 0;j<d;j++){
    cin >> a;
    data[i][j] = a;
  	}  
  }
  
 int ans = 0;
 for (int i = 0; i < n; ++i) {
 for (int j = i+1; j < n; ++j) {
 int norm = 0;
 for (int k = 0; k < d; ++k) {
 int diff = abs(data[i][k] - data[j][k]);
 norm += diff * diff;
 }
 // check whether norm = k for some k
 bool flag = false;
 for (int k = 0; k <= norm; ++k) {
 if (k * k == norm) {
 flag = true;
 }
 }
 if (flag) ++ans;
 }
 }
 cout << ans << endl;
  
  
    return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll N,M;
    priority_queue<ll> que;
    cin >> N >> M;
    REP(i,0,N){
        ll cur;
        cin >> cur;
        que.push(cur);
    }
    ll now;
    REP(i,0,M){
        now=que.top();
        que.pop();
        que.push(now/2);
    }
    ll ans=0;
    while(!que.empty()){
        ans+=que.top();
        que.pop();
    }
    P(ans);
}


Measured memory_bytes: 1400
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    String s;
    int arare[] = new int[4];
    int ans = 0;
    
    for (int i = 0; i < n; i++) {
        s = sc.next();
        switch (s) {
            case "P": arare[0] = 1; break;
            case "W": arare[1] = 1; break;
            case "G": arare[2] = 1; break;
            case "Y": arare[3] = 1; break;
        }
    }
    
    for (int i = 0; i < 4; i++)
        ans += arare[i];
    
    System.out.println(ans == 3 ? "Three" : "Four");
  }
}

Measured memory_bytes: 23892
import java.util.*;
public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long x = (long)n*(n-1)/2;
      System.out.println(x);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
#define ll long long
string s,t;
ll ok,i;
int main()
{
    cin>>s>>t;
    for (i=0;i<t.size()-1;++i)
    {
        if (t[i]!=s[i])
        {
            ok=1;
            break;
        }
    }
    if (ok) cout<<"No\n";
    else cout<<"Yes\n";
}


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

n = inp()
a = inpl()

ans = 'APPROVED'
for i in range(n):
    if a[i] % 2 == 0 and a[i] % 3 != 0 and a[i] % 5 != 0:
        ans = 'DENIED'

print(ans)

Measured memory_bytes: 31148
#include <string>
#include<iostream>
#include <algorithm>
#include<sstream>
#include<list>
 #include <cstdio>
//#include <stdio.h>
using namespace std;                      



int main ()
{
int n=0;

cin>>n;
int sum=0;
for(int i=1;i<=n; i++ ){
    sum=sum+i;

}

cout<<sum;





return 0;
}

Measured memory_bytes: 256
#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() {
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int k=0;
    int now=1;
    for(int i=0; i<n; i++){
        if(now!=a[i]) k++;
        else now++;
    }
    if(k==n) cout<<-1<<endl;
    else cout<<k<<endl;
}

Measured memory_bytes: 1024
K = int(input())

lun = list(range(0, 10)) + [0] * (K - 9 + 2) # lun[0]はダミー

k = 9
i = 1
while k < K:
    next = lun[i]
    dig = next % 10
    if dig > 0:
        k += 1
        lun[k] = next * 10 + dig - 1
    k += 1
    lun[k] = next * 10 + dig
    if dig < 9:
        k += 1
        lun[k] = next * 10 + dig + 1
    i += 1

print(lun[K])

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

int main(void) {
    int diff;
    vector<int> abc(3);
    cin >> abc[0] >> abc[1] >> abc[2];
    sort(abc.begin(), abc.end());

    diff = abc[2]-abc[1] + abc[2] - abc[0];
    if(diff%2) {
        cout << 1+(diff+1)/2 << endl;
    } else {
        cout << diff/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
} 

int mak[mxn];
pair <char,char> ql[mxn];
char now[mxn];
int n,q;
string s;
long long ans;

bool check (int x, int t){
	now[x]=s[x];
	mak[x]=x;
	for (int i = 0;i<q;i++){
		if (ql[i].F==now[x]){
			if (ql[i].S=='R')
				mak[x]++;
			if (ql[i].S=='L')
				mak[x]--;
			now[x]=s[mak[x]];
			if (mak[x]<0 and t)
				return 0;
			if (mak[x]>n-1 and t)
				return 1;
			if (mak[x]<0 and !t)
				return 1;
			if (mak[x]>n-1 and !t)
				return 0;
		}
	}
	return 0;
}

int main(){
	cin>>n>>q;
	ans=n;
	cin>>s;
	for (int i = 0;i<q;i++){
		char a ,  b;
		cin>>a>>b;
		ql[i]={a,b};
	}
	int l = 0, r = n, mid = 0;
	while (r-l>1){
		mid = (l+r)/2;
		if (check(mid,1))
			r = mid;
		else
			l= mid;
	}
	//cout<<n-r<<" ";
	ans-=(n-r);
	l = 0, r = n, mid = 0;
	while (r-l>1){
		mid = (l+r)/2;
		if (check(mid,0))
			l= mid;
		else
			r= mid;
	}
	ans-=r;
	//cout<<r<<" ";
	cout<<ans;
	
}

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

int h,w;
const int maxh=1e3;

string arr[maxh];
int val[maxh][maxh];

void dfs(int i,int j,int cnt)
{
	if(i>=h || i<0 || j>=w || j<0)
		return;
	
	if(arr[i][j]=='#' || val[i][j]!=-1)
		return;
		
//	cout<<i<<' '<<j<<' '<<cnt<<endl;
	
	val[i][j]=cnt;
	
	dfs(i+1,j,cnt);
	dfs(i-1,j,cnt);
	dfs(i,j+1,cnt);
	dfs(i,j-1,cnt);
}

int main()
{
	cin>>h>>w;
	
	int sx,sy;
	int ex,ey;
	
	cin>>sx>>sy;
	cin>>ex>>ey;
	
	sx--,sy--;
	ex--,ey--;
	
	memset(val,-1,sizeof(val));
	
	for(int i=0;i<h;i++)
	{
		cin>>arr[i];
	}
	
	int cnt=0;
	
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(val[i][j]==-1 && arr[i][j]=='.')
			{
				//cout<<i<<' '<<j<<endl;
				dfs(i,j,cnt++);
			}
		}
	}
	
	set<int> adj[cnt];
	int depth[cnt];
	memset(depth,-1,sizeof(depth));
	
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(arr[i][j]=='.')
			{
				int v1=val[i][j];
				
				for(int x=max(0,i-2);x<=min(h-1,i+2);x++)
				{
					for(int y=max(0,j-2);y<=min(w-1,j+2);y++)
					{
						int v2=val[x][y];
						
						if(v1!=v2)
						{
							adj[v1].insert(v2);
						}
					}
				}
			}
		}
	}
	
	queue<int> q;
	q.push(val[sx][sy]);
	depth[val[sx][sy]]=0;
	
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		
		for(int j:adj[v])
		{
			if(depth[j]==-1)
			{
				depth[j]=depth[v]+1;
				q.push(j);
			}
		}
	}
	
	cout<<depth[val[ex][ey]]<<endl;
	return 0;
}

Measured memory_bytes: 41400
#include <iostream>
using namespace std;
int main(void){
    int count[5][4][11] = {{{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}}};
    int n,b,f,r,v;
    cin >> n;

    for(int i = 0; i < n; i++){
       cin >> b >> f >> r >> v;
       count[b][f][r] += v;
    }
    for(b = 1; b < 5; b++){
        for(f = 1; f < 4; f++){
            for(r = 1; r < 11; r++){
                cout << " " << count[b][f][r];
            }
            cout << endl;
        }
        if(b < 4) cout << "####################" <<endl;
    }
    
}


Measured memory_bytes: 3052
import java.util.*;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long count=0;
	    long t =0;
	    for(long i= 0 ;i<N;i++) {
	    count += t;
	    t++;
	       
	    	
	    }
	     System.out.println(count);
	}
	
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000000000000ll
ll n,k;
ll a[200009],b[200009];

bool judge(ll m){
  ll r=k;
  for(int i=0;i<n;i++){
    ll d=max(a[i]-m/b[i],0ll);
    //cout<<d<<endl;
    r-=d;
    if(r<0)return false;
  }
  
  return true;
}

int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  reverse(b,b+n);

  ll left=-1,right=INF;
  while(right-left>1){
    ll mid=(left+right)/2;
    //cout<<judge(mid)<<endl;
    if(judge(mid)){
      right=mid;
    }
    else{
      left=mid;
    }
  }

  cout<<right<<endl;
  return(0);
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll a, b;
  cin >> a >> b;

  if(a <= b)
    rep(i, b) cout << a;
  else
    rep(i, a) cout << b;

  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		long m = Long.parseLong(sc.next());
		sc.close();

		//nとm*2は等価である為m/2して扱いやすいように 奇数の場合1を切り捨てても問題ない
		m/=2;
		if(n < m) {
			//極端にnとmの差が大きい場合の高速化する為の処理
			n += m/2;m-=m/2;m+=n/2;n-=n/2;
			while(m-n>=20000000000L) {n+=10000000000L; m-=10000000000L;}
			while(m-n>=200000000L) {n+=100000000L; m-=100000000L;}
			while(n+n<m-n) {m-=n; n+=n;}
			while(n<m){m--; n++;}
		}
		//作れる個数 Math.min(n,m)
		System.out.println(n<m?n:m);
	}

}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n, k, s;
	cin>>n>>k>>s;
	forn(i, 0, k){
		cout<<s<<" ";
	}
	forn(i, k, n){
		if(s == 1e9){
			cout<<1<<" ";
		}
		else if(s==1){
			cout<<100000<<" ";
		}
		else{
			cout<<s-1<<" ";
		}
	}
}

Measured memory_bytes: 3600
def cin; gets.split.map(&:to_i) end
def cout(*x); puts x.join(" ") end

# exit if $0 != __FILE__

n,q = cin
s = gets.chop.chars
a = Array(s.length+1)
a[0] = 0
bf = nil
s.each_with_index do |c, i|
  a[i+1] = a[i] + ((bf=='A' && c=='C') ? 1 : 0)
  bf = c
end

q.times do
  l,r = cin
  p a[r] - a[l]
end


Measured memory_bytes: 14100
s = input()

if len(s) == 1:
    print(s)
else:
    total = 0
    for i in range((2 ** (len(s) - 1))):
        bit = format(i, '0{}b'.format(len(s) - 1))
        e = ''
        for j in range(len(s) - 1):
            e += s[j]
            if bit[j] == '1':
                e += '+'
        e += s[-1]
        total += eval(e)
    print(total)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long dp[1009][1009],n,m;
char s[1009][1009];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>s[i][j];
        }
    }
    dp[1][1]=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(s[i][j]=='.' && i+j!=2){
                    dp[i][j]=dp[i-1][j]+dp[i][j-1];
                    dp[i][j]%=1000000007;
                }
            }
        }
    cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 9088
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ayuame
 */

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef pair<int, int> P;
typedef long long ll;

class ANumberOfMultiples {
public:
	void solve(std::istream& in, std::ostream& out) {
	  int L, R, d, cnt = 0;
	  in >> L >> R >> d;
	  FOR(i, L, R+1) {
	    if (i % d == 0) {
	      cnt++;
	    }
	  }
	  out << cnt << endl;
	}
};

int main() {
	ANumberOfMultiples solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

ll heap[MAX_N];
void heapinit(){
    rep(i,0,MAX_N){
        heap[i]=-1;
    }
}

void pushHeap(ll val, ll len){
    ll i = len;
    heap[i]=val;
    while(i!=0){
        if( heap[i]>heap[(i-1)/2] ){
            swap(&heap[i],&heap[(i-1)/2]);
        }    
        i--;i/=2;
    }
}

void popHeap(ll *val, ll len){
    ll i=0;
    *val=heap[0]; heap[0]=-1;
    swap(&heap[0],&heap[len-1]);
    while(len>=i*2+1){
        if(i*2+2<=len && heap[i]< heap[i*2+2] && heap[i*2+1]<heap[i*2+2] ){
            swap(&heap[i],&heap[i*2+2]);
            i*=2;i+=2;
        }else{
            if(heap[i]<heap[i*2+1]){
                swap(&heap[i],&heap[i*2+1]);
                i*=2;i++;
            }else break;
        }
    }
}

int main(void){
    // char ;
    ll n,m,ans=0;
    scanf("%lld%lld",&n,&m);
    ll a[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
    }
    
    rep(i,0,n){
        pushHeap(a[i],i);
    }
    rep(i,0,m){
        ll val;
        popHeap(&val,n);
        val/=2;
        pushHeap(val,n-1);
    }
    rep(i,0,n){
        // printf("%lld ",heap[i]);
        ans+=heap[i];
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

int max3 (int a, int b, int c)
{
  int max = a;
  
  if (b > max ) max = b;
  if (c > max) max = c;
  return max;
}

int main (void)
{
  int a, b, c;
  scanf("%d",&a);
  scanf("%d",&b);
  printf("%d",max3(a-b,a+b,a*b));
    return 0;
}
  

Measured memory_bytes: 128