akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
lol w[111000],v[111000],q[111000];
lol mem[111000][5];
lol dp(int n,int m){
    if(n==a) return 0;
    if(mem[n][m]!=-1) return mem[n][m];
    if(m==0) return mem[n][m]=max(dp(n+1,1),dp(n+1,2))+w[n];
    if(m==1) return mem[n][m]=max(dp(n+1,0),dp(n+1,2))+v[n];
    return mem[n][m]=max(dp(n+1,0),dp(n+1,1))+q[n];
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  string s;
  cin >>a;
  for(int n=0;n<a;n++){
      cin >>w[n]>>v[n]>>q[n];
  }
  memset(mem,-1,sizeof(mem));
  cout <<max(dp(0,0),max(dp(0,1),dp(0,2)))<<'\n';
  return (0);
}


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

int main() {
    string s; cin >> s;
    string t = "ATGC";
    vector<int> num(s.size(), 0);
    int idx = 0;
    for(int i = 0; i < s.size(); i++) {
        if((int)t.find(s[i]) != -1) num[idx]++;
        else idx++;
    }
    int ans = 0;
    for(int i = 0; i < num.size(); i++) ans = max(ans, num[i]);
    cout << ans << endl;
}


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

int main(){
    int n, q;
    cin >> n >> q;
    vector<char> c;
    for (int i = 0; i < n; i++) {
        char x; cin >> x;
        c.push_back(x);
    }
    struct magic { char x,y; } m[q];
    for (int i = 0; i < q; i++) {
        char x, y;
        cin >> x >> y;
        m[i].x = x;
        m[i].y = y;
    }
    int l = 1, r = n;
    for (int i = q - 1; i >= 0; i--) {
        if (m[i].y == 'L') {
            if (c[l-1] == m[i].x) l++;
            if (r != n && c[r] == m[i].x) r++;
        } else {
            if (c[r-1] == m[i].x) r--;
            if (l != 1 && c[l-2] == m[i].x) l--;
        }
    }
    cout << r - l + 1 << endl;
    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  string result ="";
  while(N!=0) {
    if(N%2==0) {
      result = "0"+result;
    } else {
      N -= 1;
      result = "1"+result;
    }
    N = N/(-2);
  }
  if (result=="") {
    result ="0";
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        //N,V,Cを取り込む
        int N = s.nextInt();
        int Vn[] = new int[N];
        int Cn[] = new int[N];

        for(int i=0;i<N;i++){
            Vn[i]=s.nextInt();
        }
        for(int i=0;i<N;i++){
            Cn[i]=s.nextInt();
        }
        int ans=0;
        //V-Nを計算して、1以上ならansに足していく
        for(int i=0;i<N;i++){
            int check=0;
            check=Vn[i]-Cn[i];
            if(check>0){
                ans+=check;
            }
            check=0;
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
bool isSeven(int n){
	while(n){
    	if(n%10 == 7) return true;
      	n=n/10;
    }
  return false;
}

int main(){
int n;
  cin>>n;
  
if(isSeven(n)) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3628
N = int(input())
h = list(map(int, input().split()))


def calc(arr, count):
    m = min(arr)
    count += m
    l = 0
    new_arr = [arr[i] - m for i in range(len(arr))]
    for i, v in enumerate(new_arr):
        if v == 0:
            if l < i:
                count = calc(new_arr[l:i], count)
            l = i + 1
    if l < len(new_arr):
        count = calc(new_arr[l:len(new_arr)], count)

    return count


ans = calc(h, 0)
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<vector>
#include<iostream>
#include<set>
using namespace std;




int main() {
	int n;
	cin >> n;
	bool f = true;
	int tmp;
	for(int i=0;i<n;++i){
		cin >> tmp;
		if(tmp%2==0){
			if(!(tmp%3==0||tmp%5==0)) f = false;
		}
	}
	
	if(f) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	
    return 0;
}


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

int main() {
    using namespace std;

    unsigned long N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    {
        string T(S.begin(), S.end());
        T += string(S.rbegin(), S.rend());
        for(unsigned long i = 0; i < N; ++i)S = min(S, string(T.begin() + i, T.begin() + i + N));
    }

    unsigned long k{static_cast<unsigned long>(find_if_not(S.begin(), S.end(), [&S](auto i){return i == S[0];}) - S.begin())};
    --K;

    if(K > 13 || (k << K) > N){
        cout << string(N, *min_element(S.begin(), S.end())) << endl;
        return 0;
    }

    string A((k << K) - k, S[0]);
    A += string(S.begin(), S.begin() + N - A.size());

    cout << A << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[110];
int s1,s2;
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(i%2)
		{
			s1+=a[i];
		}
		else s2+=a[i];
	}
	cout<<s1-s2;
	return 0;
}

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

int main() {
  int k,s,ans=0; cin>>k>>s;
  for(int a=0;a<=k;a++){
    for(int b=0;b<=k;b++){
        int c=s-a-b;
        if(0<= c && c<=k) {
            ans++;
        }
      }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i,j,h,w;
    char s[52][52];

    for (i = 0; i < 52; i++)
    {
        for (j = 0; j < 52; j++)
        {
            s[i][j] = '.';
        }        
    }

    scanf("%d %d",&h,&w);
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            scanf("\n%c",&s[i + 1][j + 1]);
        }
    }

    for (i = 1; i <= h; i++)
    {
        for (j = 1; j <= w; j++)
        {
            if(s[i][j] == '#')
            {
                if(s[i][j] != s[i + 1][j] && s[i][j] != s[i - 1][j] && s[i][j] != s[i][j + 1] &&s[i][j] != s[i][j - 1])break;
            }
        }
        if(j != w + 1)break;
    }
    printf("%s\n",i == h + 1 ? "Yes" : "No");
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<int> dp0(s.size() + 1), dp1(s.size() + 1);
  dp0[0] = 0;
  dp1[0] = 1;
  rep(i, s.size()) {
    int a = s[i] - '0';
    dp0[i + 1] = min(dp0[i] + a, min(dp1[i] + a + 1, dp1[i] + 10 - a));
    dp1[i + 1] = dp1[i] + 10 - a - 1;
    if (a < 9) {
      dp1[i + 1] = min(dp1[i + 1], min(dp0[i] + a + 1, dp1[i] + a + 2));
    }
  }

  // irep(i, s.size()) { cerr << " " << dp0[i] << " " << dp1[i] << "\n"; }

  cout << dp0[s.size()] << endl;
  return 0;
}

Measured memory_bytes: 12156
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  cin>>N;
  int t[N+1],x[N+1],y[N+1];
  t[0]=0; x[0]=0; y[0]=0;
  rep(i,N){
    int tt,xx,yy;
    cin>>tt>>xx>>yy;
    t[i+1]=tt;x[i+1]=xx;y[i+1]=yy;
  }
  rep(i,N){
    int T=t[i+1]-t[i];
    int X=x[i+1]-x[i];
    int Y=y[i+1]-y[i];
    if(T<X+Y or (T-X-Y)%2==1){
      cout<< "No"<<"\n";
      return;
    }
  }
  cout<< "Yes"<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

typedef bitset<64> bs;

int N;
vector<bs> A;

int main() {
  cin >> N;
  A.resize(N);
  rep(i, N) {
    ll a;
    cin >> a;
    A[i] = bs(a);
  }

  const int D = 60;
  bs allXor;
  rep(i, N) allXor ^= A[i];
  rep(i, N) A[i] &= ~allXor;

  int idx = 0;
  for (int d = D - 1; d >= 0; --d) {
    int j = idx;
    while (j < N && !A[j][d]) ++j;
    if (j < N) {
      swap(A[idx], A[j]);
      rep(k, N) {
        if (k != idx && A[k][d]) {
          A[k] ^= A[idx];
        }
      }
      ++idx;
    }
  }

  unsigned long long ans = 0;
  rep(i, N) ans = max(ans, ans ^ A[i].to_ullong());
  ans <<= 1;
  ans += allXor.to_ullong();

  cout << ans << endl;

  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    string s;
    cin >> s;
    cout << s.size()/2-count(s.begin(),s.end(),'p') << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

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


int main()
{
	FAST;
	string str;
	cin >> str;

	for(int i=1 ; i<=str.size() ; i++)
	{
		if(i&1)
			cout << str[i-1];
	}
	return 0;
}

Measured memory_bytes: 592
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
ruiseki_A = [0]
ruiseki_B = [0]
 
for i in range(len(A)):
    ruiseki_A.append(ruiseki_A[i]+A[i])
for i in range(len(B)):
    ruiseki_B.append(ruiseki_B[i]+B[i])
#print(ruiseki_A)
 
ans = 0
for i in range(len(ruiseki_A)):
    tmp = K - ruiseki_A[i]
    if tmp < 0:
        continue
    r = len(ruiseki_B)
    l = 0
    while r-l > 1:
        mid = (r + l) // 2
        if ruiseki_B[mid] <= tmp:
            l = mid
        else:
            r = mid
    ans = max(ans, i+l)
 
print(ans)

Measured memory_bytes: 132304
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	string S; cin >> S;
	long long K; cin >> K;
	for (long long i = 0; i < K; i++) {
		if(S.at(i) != '1') {
			cout << S.at(i) << endl;
			return 0;
		}
	}
	cout << 1 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f; 
}
const int maxn = 1e5 + 50;
int n;
int a[maxn];
inline int cmp(const int &a, const int &b) {
	return a > b;
}
bool solve() {
	sort(a + 1, a + n + 1, cmp);
	int k = 1;
	while(a[k + 1] >= k + 1) ++k;
	int x = a[k] - k;
	int y = 0;
	while(a[k + y + 1] == k) ++y;
	return (x & 1) || (y & 1);
}
int main() {
	read(n);
	for(int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	puts(solve() ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }


bool isprime(long long int val) {
 if (val <= 1)return false;
 for (long long int i = 2; i*i <= val; i++) {
   if (val%i == 0LL)return false;
 }
 return true;//ç´ æ•°
}

bool f[56000];


int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for(int i=2; i<=55555; i++){
    f[i]=isprime(i);
  }
  int cnt=0;
  for(int i=2; i<=55555; i++){
    if(f[i] && i%5==1 && cnt<n){
      printf("%d ",i );
      cnt++;
    }
    if(cnt==n) break;
  }
  cout << endl;
  return 0;
}


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

int main() {
  int hmk;
  cin >> hmk;
  float zerotemp, wanttemp;
  cin >> zerotemp >> wanttemp;
  vector<float> htati(hmk);
  for (int i = 0; i < hmk; i++) {
    cin >> htati.at(i);
  }
  vector<float> tempati(hmk);
  for (int i = 0; i < hmk; i++) {
    tempati.at(i) = zerotemp - htati.at(i) * 0.006;
  }
  vector<float> dtempati(hmk);
  for (int i = 0; i < hmk; i++) {
    if (wanttemp < tempati.at(i)) {
      dtempati.at(i) = tempati.at(i) - wanttemp;
    } else {
      dtempati.at(i) = wanttemp - tempati.at(i);
    }
  }
  int count = 0;
  for (int i = 0; i < dtempati.size(); i++) {
    if (dtempati.at(count) > dtempati.at(i)) {
      count = i;
    }
  }
  cout << count + 1 << endl;
}

Measured memory_bytes: 256
n = int(input())

lsA = list(map(int,input().split()))
tot = sum(lsA)

an = tot
for i in range(0,n-2,2):
  an -= 2*lsA[i]

ans = [2*lsA[i] for i in range(n)]
ans[n-1] = an
for i in range(n-2,-1,-1):
  ans[i] -= ans[i+1]

print(" ".join(list(map(str,ans))))

Measured memory_bytes: 19144
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)
using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int main() {
    
    ll N = lin();
    
    vector<ll> A;
    
    ll ans = 0;
    for(auto i = 0; i<N; i++){
        A.push_back(in());
        ans += A.back()-1;
    }
    
    cout << ans << endl;
    
    return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#define mod 1000000007
using namespace std;



int main()
{
    int m,n,o=0,i,j,k,sum=0,change=0,small;
    //long long int m,n,o,i,j,k;
    //vector <int> v;
    //float f,g,h;
    //char c,d;
    string a;
    cin>>n>>a;
    int *attention=new int [n];
    for(i=0;i<n;i++) attention[i]=0;
    for(i=1;i<n;i++)
    {
        if(a[i-1]=='W') attention[i]=++change;
        else attention[i]=change;
    }
    change=0;
    for(i=n-2;i>=0;i--)
    {
        if(a[i+1]=='E') attention[i]+=++change;
        else attention[i]+=change;
    }
    for(i=1;i<n;i++)
    {
        if(i==1) small=min(attention[0],attention[1]);
        else small=min(small,attention[i]);
    }
    //cin>>m>>c>>n>>d>>i;
    //cin>>f>>g;
    //cin>>c;
    cout<<small;
    delete [] attention;
    return 0;
}





Measured memory_bytes: 1916
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

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

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

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    int h, a;
    cin >> h >> a;

    cout << (h + a - 1) / a << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
bool is_prime(int n) {
	for (int i = 2; i*i <= n; ++i) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

int main() {
	ll N; cin >> N;
	string ans = "";
	while (N != 0) {
		N--;
		int x = N % 26;
		ans += ('a' + x);
		N /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;




const ll MOD = 998244353;
const ll MAX = 510000;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

//処理法
//int main() {
    // 前処理
//    COMinit();

    // 計算例
//    cout << COM(100000, 50000) << endl;
//}

// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//逆元 mod の計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

// a^n mod の計算
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    ll ans=0;
    COMinit();

    rep(i,k+1){
        ans += ((COM(n-1,i)*m)%MOD)*modpow(m-1,n-i-1,MOD);
        ans %= MOD;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 15596
import sys
def input(): return sys.stdin.readline().strip()


def main():
    C = [list(map(int, input().split())) for _ in range(3)]
    rumor = True
    for i in range(1, 3):
        diff1 = C[i][0] - C[0][0]
        diff2 = C[i][1] - C[0][1]
        diff3 = C[i][2] - C[0][2]
        if diff1 != diff2 or diff2 != diff3 or diff1 != diff3:
            rumor = False
            break
    if rumor: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int k, s;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> k >> s;
	int ans = 0;
	rep (i, k + 1) rep (j, k + 1) {
		int x = i;
		int y = j;
		int z = s - x - y;
		if (range(z, 0, k) && x + y + z == s) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;

class Program
{


    static void Main(string[] args)
	{
        int N = int.Parse(Console.ReadLine());

        int A = 1;

        int count = 0;

        for (int i = 0; i < N; i++)
        {
            int B = 1;

            for(int j = 0;j < N; j++)
            {

                if(A * B < N)
                {
                    count++;
                    B++;
                }
                else
                {
                    break;
                }
            }

            A++;
        }


        Console.WriteLine(count);
    }
}


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

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


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

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

    int ok[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    int dk[k+1];
    for (int i = 0; i < k; i++) {
        scanf("%d", &dk[i]);
        ok[dk[i]] = -1;
    }

    for (int m = n; ; m++) {
        char ns[10] = {'\0'};
        sprintf(ns, "%d", m);

        // WA
        //int n4 = m/1000;
        //int n3 = (m - n4*1000)/100;
        //int n2 = (m - n4*1000 - n3*100)/10;
        //int n1 = (m - n4*1000 - n3*100 - n2*10);
        //printf("%d %d %d %d\n", n4, n3, n2, n1);
        //int n0[] = {n4, n3, n2, n1};

        int allok = 0;
        for (int i = 0; i < strlen(ns); i++) {
            int j = ns[i] - '0';
            if (ok[j] == j) {
                allok += 1;
            } else {
                break;
            }
        }

        if (allok == strlen(ns)) {
            printf("%d\n", m);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 128
<?php
$N = intval(fgets(STDIN));
$L = trim(fgets(STDIN));
$L = array_map("intval", explode(" ", $L));
sort($L);

$ans = 0;
for ($i=0; $i < $N; $i++) {
  for ($j=($i+1); $j < $N; $j++) {
    for ($k=($j+1); $k < $N; $k++) {
      if ($L[$i] != $L[$j] && $L[$j] != $L[$k] &&
          $L[$i] + $L[$j] > $L[$k]) {
        $ans++;
      }
    }
  }
}

echo $ans;

Measured memory_bytes: 16320
import heapq
n, m, s, t = map(int, input().split())
INF = 2**63-1
data = []
for _ in range(m):
    data.append(list(map(int, input().split())))

check = [False for i in range(n+1)]
graph = [[] for i in range(n+1)]

for i in range(m):
    graph[data[i][0]].append([data[i][1], data[i][2], data[i][3]])
    graph[data[i][1]].append([data[i][0], data[i][2], data[i][3]])
city_yen_cost = [INF for i in range(n+1)]
city_yen_cost[s] = 0
queue = []
#[cost, vertex]
heapq.heappush(queue, [0, s])
while len(queue) > 0:
    now = heapq.heappop(queue)
    if check[now[1]]:
        continue
    else:
        check[now[1]] = True
        for path in graph[now[1]]:
            if city_yen_cost[now[1]]+path[1] < city_yen_cost[path[0]]:
                city_yen_cost[path[0]] = min(city_yen_cost[now[1]]+path[1], city_yen_cost[path[0]])
                if not check[path[0]]:
                    heapq.heappush(queue, [city_yen_cost[now[1]]+path[1], path[0]])




check = [False for i in range(n+1)]
city_snuke_cost = [INF for i in range(n+1)]
city_snuke_cost[t] = 0
queue = []
heapq.heappush(queue, [0, t])
while len(queue) > 0:
    now = heapq.heappop(queue)
    if check[now[1]]:
        continue
    else:
        check[now[1]] = True
        for path in graph[now[1]]:
            if city_snuke_cost[now[1]]+path[2] < city_snuke_cost[path[0]]:
                city_snuke_cost[path[0]] = min(city_snuke_cost[now[1]]+path[2], city_snuke_cost[path[0]])
                if not check[path[0]]:
                    heapq.heappush(queue, [city_snuke_cost[now[1]]+path[2], path[0]])


totalcost = [None] * (n+1)
for i in range(n+1):
    totalcost[i] = city_yen_cost[i] + city_snuke_cost[i]
for i in range(n):
    totalcost[-i-2] = min(totalcost[-i-2], totalcost[-i-1])
for i in range(n):
    print(10**15-totalcost[i+1])


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

#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
map<int,int>mp;

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>N;
    int cnt=1;
    while(!mp.count(N)){
        mp[N]=cnt;
        if(N%2)N=N*3+1;
        else N/=2;
        //cout<<N<<endl;
        cnt++;
    }
    cout<<cnt<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans1 = a[n - 1]
ans2 = a[0]
for i in range(n):
    ans2 = max(ans2, min(a[i], ans1 - a[i]))
exist = False
for i in range(n):
    if (ans2 == a[i]):
        exist = True
if (exist):
    print(ans1, ans2)
else:
    print(ans1, ans1 - ans2)


Measured memory_bytes: 14428
#include<iostream>
#include<stdio.h>
using namespace std;
#define maxn 200005
int main ()
{
    int n,r=0,w=0,r1=0,w1=0,r2,w2,sum;
    char c[maxn];
    scanf ("%d",&n);
    for(int i=0;i<=n;i++)
    {
        scanf ("%c",&c[i]);
        if(c[i]=='R')
            r++;
        else if(c[i]=='W')
            w++;
    }
    for(int i=0;i<=r;i++)
    {
        if(c[i]=='W')
        w1++;
    }
        r1=r-w1;
        r2=r-r1;
        sum=min(r,w);
        sum=min(r2,sum);
        printf("%d\n",sum);
    return 0;
}

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

using namespace std;

#define endl '\n'

int main(){

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

  int x,y;
  cin >> x >> y;
 
  for(int i=0;i<=x;i++){
    for(int j=0;j<=x;j++){
      if(2*i + 4*j == y && i+j == x){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3612
mod=10**9+7
s=list(input())
s=['-']+s
l=len(s)
dp=[[0 for j in range(4)] for i in range(l)]
dp[0][0]=1
for i in range(1,l):
    for j in range(4):
        dp[i][j]=dp[i-1][j]
        if s[i]=='?':
            dp[i][j]*=3;
        if j and (s[i]=='?' or 'ABC'[j-1]==s[i]):
            dp[i][j]+=dp[i-1][j-1]
        dp[i][j]%=mod
print(dp[-1][3])

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

char getAns(int m,int e,int j){
	if(m==100||e==100||j==100)return 'A';
	if((m+e)/2>=90)return 'A';
	if((m+e+j)/3>=80)return 'A';
	if((m+e+j)/3>=70)return 'B';
	if((m+e+j)/3>=50&& (m>=80||e>=80))return 'B';
	return 'C';

}
int main(){
	int d;
	while(cin>>d){
		int pm,pe,pj;
		for(;d>0;d--){
			cin>>pm>>pe>>pj;
			cout<<getAns(pm,pe,pj)<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
int N, M; 
cin >> N >> M; 
int A[10][10] = {}; 
for(int i = 0; i < M; i++){
	int a, b; 
	cin >> a >> b; 
	A[a][b] = 1, A[b][a] = 1; 
}
int B[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 
int count = 0; 
do{
	bool possible = 1; 
	for(int i = 0; i < N-1; i++){
		if(A[B[i]][B[i+1]] == 0){
			possible = 0; 
			break; 
		}
    }
	if(possible){count ++;}
} while (next_permutation(B+1, B+N));
cout << count << endl;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if(A + B > C + D){
    cout << "Left" << endl;
  }else if(A + B < C + D){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; }

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;

  for (auto &c : s) {
    if (c == '9') c = '1';
    else c = '9';
  }

  cout << s << endl;

  return (0);
}


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

int main(int argc, char *argv[])
{

  string S, T;

  cin >> S >> T;

  if (S.length() > 10 || S.length() < 1)
  {
    cout << "No" << endl;
    return 0;
  }

  if (S + T[T.length() - 1] != T)
  {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3040
//2017-10-13
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (100000+5)

int a[N];
bool had[N];

int main(){	
	int n;
	LL ans = 0;

	scanf("%d", &n);
	For(i, 1, n){
		scanf("%d", &a[i]);
		
		if(a[i] >= 2) had[i] = true;
		ans += a[i] >> 1; a[i] = a[i] & 1;
	}
	
	int lst = -1;

	For(i, 1, n){
		if(!a[i] && lst == -1) continue;

		if(a[i] && lst == -1){
			lst = i; continue;
		}

		if(lst != -1 && !a[i]){
			if(!had[i]) lst = -1;
			continue;
		}

		++ans; lst = -1;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,rem,i,j,k;
    vector<long long int>s;
    vector<long long int>::iterator it;
    cin>>n;
    if(n==0)
        s.push_back(0);
    while(n!=0)
    {
        rem=n%-2;
        n=n/-2;
        if(rem<0)
        {
            rem=rem+2;
            n=n+1;
        }
        s.push_back(rem);
    }
    reverse(s.begin(),s.end());
    for(it=s.begin();it!=s.end();it++)
        cout<<*it;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,n,b,tot;
int main() {
    cin>>n>>a>>b;
    
    for(int i=1;i<=n;i++)
    {
        int sum=0;
        int k=i;
        while(k>0)
        {
            sum=sum+k%10;
            k=k/10;
        }
        
        if(sum>=a&&sum<=b)
        {
            tot=tot+i;
            sum=0;
        }
    }
        cout<<tot;
    
}
    
    
    
       

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define M_PI   3.14159265358979323846264338327950288
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout<<"("<< #x <<", "<< #y <<") = ("<<x << ", " << y << ")\n"
 
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
struct cmp{
  bool operator() (pair<int,int> const & lhs, pair<int,int> const & rhs) const
  {
    if(lhs.first != rhs.first)
     return lhs.first > rhs.first;
   return lhs.second < rhs.second;
  }
};
 
// int digsum(int pos,int n,int sum ){
 
//   if(pos == n){
//     return sum;
//   }
 
//   int s = 0;
//   for(int i=0;i<10;i++){
//     s += digsum(pos+1,n,sum+i);
//   }
 
//   return s;
// }

bool fx(int odd,int even,int rqdev){
  
  if(odd < 0)return false;
  
  while(even < rqdev){
  	rqdev--;
  	odd-=2;
  	if(odd < 0)return false;
  }

  return true;
}

int fx(int a,int b){
   
   int ans = 0;
   
   if(a/2 <= b){

    ans += a/2;

    b -= a/2;
    a -= 2*(a/2);

   }else if(a/2 >= b){
     
    ans += b;
    a -= 2*b;
    b -= b;
   }
   
  
   ans += min(b/2,a);

   return ans;
}


signed main() {
 
  FIO;

#ifndef ONLINE_JUDGE     
   freopen("input.txt", "r", stdin); 
   // freopen("output.txt", "w", stdout);  
#endif 

 int a;
 string b;

 cin>>a;
 cin>>b;


 int ansx = 0LL;

 for(int i=0;i<b.size();i++){
    if(b[i] == '.')continue;
      ansx = ansx*10 + (b[i] - '0');
   
 }
 
 
 int ans = a * ansx;

 ans = ans /100;
 
 if(ans == 0){
  cout<<"0\n";
 }else{

  string val ="";

   while(ans > 0){
        val += char((ans % 10LL) + '0');
        ans = ans / 10;
   }

   reverse(val.begin(),val.end());
   cout<<val<<"\n";
 }

 

  return 0;
}

Measured memory_bytes: 3600
while True:
  h, w = map(int, input().split())

  if h == 0 and w == 0:
    break

  for i in range(h):
    for j in range(w):
      if i == 0 or i == h-1 or j == 0 or j == w-1:
        print("#", end="")
      else:
        print(".", end="")
    print("")
  
  print("")


Measured memory_bytes: 7012
from itertools import groupby, accumulate, product, permutations, combinations
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = 0
for p in product([0,1],repeat=H+W):
  cnt = 0
  for i in range(H):
    for j in range(W):
      if S[i][j]=='#' and p[i]==0 and p[H+j]==0:
        cnt += 1
  if cnt == K:
    ans += 1
print(ans)


Measured memory_bytes: 9220
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println(scanner.next().matches(String.format("\\d{%d}-\\d{%d}", a, b)) ? "Yes" : "No");
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
 
const int N = 2e5 + 5;
int n;
LL k, a[N], b[N];

bool check(LL score) {
  LL cnt = 0;
  for (int i = 1; i <= n; ++i) {
    LL x = score / b[i];
    cnt += max(0LL, a[i] - x);
    if (cnt > k) return false;
  }
  return true;
}

int main() {
  cin >> n >> k;
  FI(i,1,n) scanf("%lld", &a[i]);
  FI(i,1,n) scanf("%lld", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n, greater<LL>());
  LL l = -1, r = 1e12;
  while (l + 1 < r) {
    LL m = (l + r + 1) >> 1;
    if (check(m)) r = m;
    else l = m;
  }
  cout << r << endl;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

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

  int n;
  cin >> n;
  
  vector<int> ps(n);
  vector<vector<Edge>> graph(n);
  vector<int> out_ds(n);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    p--;
    ps[i] = p;
    graph[p].push_back(Edge(p, i));
    out_ds[p]++;
  }

  auto grundy_fn = [](const vector<vector<Edge>>& graph, const vector<int>& gs, int v) -> int {
    set<int> s;
    for (const auto& e : graph[v]) {
      s.insert(gs[e.to]);
    }
    int c = 0;
    while (true) {
      if (s.find(c) == s.end()) return c;
      c++;
    }
  };

  vector<int> gs(n, -1);
  deque<int> q;
  for (int v = 0; v < n; v++) {
    if (out_ds[v] == 0) {
      q.push_back(v);
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop_front();
    gs[v] = grundy_fn(graph, gs, v);
    out_ds[ps[v]]--;
    if (out_ds[ps[v]] == 0) {
      q.push_back(ps[v]);
    }
  }

  vector<int> cycle;
  for (int v = 0; v < n; v++) {
    if (out_ds[v] > 0) {
      cycle.push_back(v);
      int u = ps[v];
      while (true) {
        cycle.push_back(u);
        u = ps[u];
        if (u == v) break;
      }
      break;
    }
  }
  reverse(cycle.begin(), cycle.end());

  if (cycle.empty()) {
    cerr << "Unexpected: No cycle!" << endl;
    exit(1);
  }

  int v1 = cycle[cycle.size() - 1];
  vector<int> g1s;
  {
    set<int> s;
    for (const auto& e : graph[v1]) {
      s.insert(gs[e.to]);
    }
    int c = 0;
    while (true) {
      if (s.find(c) == s.end()) {
        g1s.push_back(c);
        if (g1s.size() == 2) break;
      }
      c++;
    }
  }

  bool ans = false;
  for (int g1 : g1s) {
    vector<int> hs(gs.begin(), gs.end());
    hs[v1] = g1;
    for (int i = cycle.size() - 2; i >= 0; i--) {
      hs[cycle[i]] = grundy_fn(graph, hs, cycle[i]);
    }
    if (grundy_fn(graph, hs, v1) == hs[v1]) {
      ans = true;
    }
  }

  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 14068
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> AB(N);
  long Bsum = 0;
  rep (i, N) {
    long a, b;
    cin >> a >> b;
    AB[i] = a + b;
    Bsum += b;
  }
  sort(AB.rbegin(), AB.rend());
  long ABsum = 0;
  for (long i = 0; i < N; i+=2) {
    ABsum += AB[i];
  }
  cout << ABsum - Bsum << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1024
from itertools import product,permutations

N,C = map(int,input().split())
D = tuple(tuple(map(int,input().split())) for _ in range(C))
grid = tuple(tuple(map(int,input().split())) for _ in range(N))

cnt = [[0]*C for _ in range(3)]
for x,y in product(range(N),range(N)):
  cnt[(x+y)%3][grid[x][y]-1] += 1

print(min(sum(n*D[i][j] for s,j in zip(range(3),p) for i,n in enumerate(cnt[s])) for p in permutations(range(C), r=3)))

Measured memory_bytes: 5108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_ABC088_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int a = int.Parse(Console.ReadLine());

            Console.WriteLine(n % 500 <= a ? "Yes" : "No");
        }
    }
}


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

int main() {
  std::string s;
  std::cin >> s;
  bool is_easy = true;
  for (size_t i = 0; i < s.size(); i++) {
    if ((i % 2 == 0 && s[i] == 'L') || (i % 2 == 1 && s[i] == 'R')) {
      is_easy = false;
      break;
    }
  }
  if (is_easy) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginner contest 075 B - Minesweeper
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/03/04
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int h, w;
// vector<vector<string>> s;
string s[50];

void solve() {
    vector<vector<int>> map(h, vector<int>(w));
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            map.at(i).at(j) = 0;
        }
    }

    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            if (s[i][j] == '#') {
                if (i != 0 && j != 0)       map[i-1][j-1]++;
                if (i != 0 && j != w-1)     map[i-1][j+1]++;
                if (i != 0)                 map[i-1][j]++;
                if (j != 0)                 map[i][j-1]++;
                if (i != h-1)               map[i+1][j]++;
                if (j != w-1)               map[i][j+1]++;
                if (i != h-1 && j != 0)     map[i+1][j-1]++;
                if (i != h-1 && j != w-1)   map[i+1][j+1]++;
            }
        }
    }

    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            if (s[i][j] == '#') {
                cout << '#';
            } else {
                cout << map[i][j];
            }
            if (j == w-1) {
                cout << endl;
            }
        }
    }
}

int main() {

    cin >> h >> w;

    string s_in;
    for (int i=0;i<h;i++) {
        // for (int j=0;j<w;j++) {
            cin >> s[i];
            // s[i].push_back(s_in);
        // }
    }
    solve();

}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  string s;
  cin >> s;
  int eneG = 0, eneP = 0;
  for (unsigned int i = 0; i < s.size(); i++)
    {
      switch(s[i]) 
	{
	case 'g':
	  eneG++;
	  break;
	case 'p':
	  eneP++;
	  break;
	default:
	  break;
	}
    }
  int myP = (eneG+eneP)/2;
  int myG = eneG+eneP - myP;
  int wins = 0, loses = 0, draws = 0;
  if (myG > eneG)
    {
      loses = myG - eneG;
    }
  else
    {
      wins = eneG - myG;
    }
  cout << wins - loses << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  ll X; cin >> X;
  ll ans;
  for ( ll n = 1; n <=100000; n++ ) {
    if ( (n*(n+1))/2 >= X ) {
      ans = n;
      break;
    }
  }

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


Measured memory_bytes: 256