akhauriyash/Code-Regression huggingface dataset:
import re

kwd = "keyence"
S = input()

pattern = [r"^.*keyence$",
r"^k.*eyence$",
r"^ke.*yence$",
r"^key.*ence$",
r"^keye.*nce$",
r"^keyen.*ce$",
r"^keyenc.*e$"]

judge = "NO"

for p in pattern:
    result = re.match(p,S)
    if result:
        judge = "YES"

print(judge)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <string>
#include <cmath>

# define PI 3.14159265358979323846

using namespace std;

int main(void) {
    long long h, w;
    cin >> h >> w;

    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }

    long long ans = h * w;
    if (ans % 2 == 1) {
        ans = ans / 2 + 1;
    } else {
        ans = ans / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
 
int main(){
  int n,m;
  scanf("%d",&n);
  
  if(n<105)
    m=0;
  else if(n<135)
    m=1;
  else if(n<165)
    m=2;
  else if(n<189)
    m=3;
  else if(n<195)
    m=4;
  else m=5;
  
  printf("%d",m);
  
  
  
}

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


using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-10;
const ll MOD = 998244353;
const ld PI = 3.141592653589793;
const int maxn = 300001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

struct pt {
    ld x, y;

    pt operator+(const pt &rhs) {
        return {x + rhs.x, y + rhs.y};
    }

    pt operator-(const pt &rhs) {
        return {x - rhs.x, y - rhs.y};
    }

    ld norm() {
        return hypotl(x, y);
    }

    pt operator*(ld v) {
        return {x * v, y * v};
    }
};

bool close_dbl(ld a, ld b) {
    return abs(a - b) < EPS;
}

bool less_dbl(ld a, ld b) {
    return a < b && !close_dbl(a, b);
}

bool less_equal_dbl(ld a, ld b) {
    return a < b || close_dbl(a, b);
}

int close_lg(int n) { return n > 1 ? 32 - __builtin_clz(n - 1) : 0; }

ll add(ll a, ll b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }
    return a;
}

ll mul(ll a, ll b, ll m) {
    return a * b % m;
}

ll pw(ll a, ll b, ll m) {
    ll res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = mul(res, a, m);
        }
        a = mul(a, a, m);
    }
    return res;
}

int h[maxn];

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(9);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    stack<char> st;
    string x;
    cin >> x;
    for (char c:x) {
        if (c == 'S') {
            st.push(c);
        } else {
            if (!st.empty() && st.top() == 'S') {
                st.pop();
            } else {
                st.push(c);
            }
        }
    }
    string res;
    while (!st.empty()) {
        res += st.top();
        st.pop();
    }
    reverse(res.begin(), res.end());
    cout << res.size();
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}



Measured memory_bytes: 1044
S = str(input())
i = 1
ans = 'Yes'
for x in S:
    if i % 2 == 1:
        if S[i-1] == 'L':
            ans = 'No'
            break
    else:
        if S[i-1] == 'R':
            ans = 'No'
            break
    i += 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    int a,b;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    while(op!='?'){
        if(op=='+'){
            printf("%d\n",a+b);
        }
        if(op=='-'){
            printf("%d\n",a-b);
        }
        if(op=='*'){
            printf("%d\n",a*b);
        }
        if(op=='/'){
            printf("%d\n",a/b);
        }
        scanf("%d %c %d",&a,&op,&b);
    }
    return 0;
}

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

#ifdef _DEBUG
#define debug(x) cout << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#define INFILE freopen("input.txt", "r", stdin)
#else
#define debug(x)
#define INFILE
#endif

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009LL;
static constexpr ll LL7_MOD = 1000000007LL;
static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

double dp[3010][3010];

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

  ll n;
  cin >> n;

  vector<double> probs(n, 0.0);
  scan(probs);
  dp[0][0] = 1.0;

  REP(i, 0, n) {
    REP(j, 0, i + 1) {
      double p = probs[i];
      double rev_p = 1.0 - p;

      dp[i + 1][j] += dp[i][j] * rev_p;
      dp[i + 1][j + 1] += dp[i][j] * p;
    }
  }

  double result = accumulate(begin(dp[n]) + (n / 2 + 1), begin(dp[n]) + n + 1, double(0.0));
  // cout << fixed << setprecision(10) << result << endl;
  cout << setprecision(10) << result << endl;

  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 69120
/////////// <----------------------  Quicksilver_ ---------------------> ///////////
#include <bits/stdc++.h>
#include <sstream>
#include <algorithm>
#include <map>
#include <iterator>
#include <queue>
#include <utility>
#include <set>

using namespace std;
#define endl '\n'
#define ll long long int
#define c(x) ll x;cin>>x
#define cc(x,y) ll x,y;cin>>x>>y
#define ccc(x,y,z) ll x,y,z; cin>>x>>y>>z
#define db long double
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (ll)(x).size()
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define print(arr,n) cout<<" :: "<<#arr<<" :: "<<endl; rep(i,n) cout<<arr[i]<<" "; cout<<endl
#define print2(arr,n,m) cout<<" :: "<<#arr<<" :: "<<endl; rep(i,n){ rep(j,m) cout<<arr[i][j]<<" "; cout<<endl; }
#define dyn1(arr,n) ll* arr=new ll[n]; rep(i,n) arr[i]=0;
#define dyn2(arr,n,m) ll** arr=new ll*[(n)]; rep(i,n) arr[i]=new ll[m]; rep(i,n) rep(j,m) arr[i][j]=0
#define carr(arr,n) rep(i,n) cin>>arr[i]
#define carr2(arr,n,m) rep(i,n) rep(j,m) cin>>arr[i][j]
#define debug(a) cout<<" :: "<<#a<<" == "<<a<<endl
#define debug2(a,b) cout<<" :: "<<#a<<" == "<<a<<" :: "<<#b<<" == "<<b<<endl
typedef pair<ll,ll> pii;
typedef vector<pii> vii;

inline ll maxim(ll a,ll b) {if(a>b) return a; else return b;}
inline ll minim(ll a,ll b) {if(a<b) return a; else return b;}
inline bool equals(double a, double b){ return fabs(a - b) < 1e-9; }
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }


bool prime[3001];
void SieveOfEratosthenes()
{
    memset(prime, true, sizeof(prime));
    prime[1]=false;
    for (int p=2; p*p<=3000; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=3000; i += p)
                prime[i] = false;
        }
    }
}

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1) res = (res * a)%998244353;
        a = (a * a)%998244353;
        b >>= 1;
    }
    return res;
}

// ll gcd(ll a,ll b,ll& x,ll& y)
// {
//   if(a==0)
//   {
//     x=0;
//     y=1;
//     return b;
//   }
//   else
//   {
//     ll x1,y1;
//     ll g=gcd(b%a,a,x1,y1);
//     x=y1-(b/a)*x1;
//     y=x1;
//     return g;
//   }
// }

ll arr[1000010];
ll freq[1000010];
ll counter[1000010];
ll mul[1000010];
set<string> temp;
vector<pii> queries;



int main()
{
  fast;
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cout<<setprecision(10)<<fixed;
  c(n);
  while(n--)
  {
    string s;
    cin>>s;
    temp.insert(s);
  }
  cout<<temp.size()<<endl;
  return 0;
}


Measured memory_bytes: 19140
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    private static final int MAX = 100+24;
    private static final int[] price=new int[]{10,5,1};
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        while(in.hasNext()) {
            int n=in.nextInt(),y=in.nextInt(),i,j,k;
            y /= 1000;
            boolean flag=false;
            for(i=0;i<=y/price[0]&&!flag;i++){
                for(j=0;j<=(y-price[0]*i)/price[1]&&!flag;j++) {
                    int need=y-price[0]*i-price[1]*j;
                    if(i+j+need==n){
                        flag=true;
                        out.println(i+" "+j+" "+need);
                    }
                }
            }
            if(!flag){
                out.println("-1 -1 -1");
            }
            out.flush();
        }
        in.close();
        out.close();
    }

}


Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int N = sc.nextInt();
        int D = sc.nextInt();
        double range = 2*D + 1;
        System.out.println((int)(Math.ceil(N/range)));
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

#define N 200005
int main(){fastio;
    ll n;cin>>n;
    vector<ll>v;
    ll last;cin>>last;v.pb(last);
    rep(i,1,n-1){
        ll z;cin>>z;
        if(z!=last){
            v.pb(z);
            last=z;
        }
    }
    n=v.size();
    ll dp[n][2];
    ll c[N];memset(c,0,sizeof(c));
    dp[0][0]=0;dp[0][1]=1;
    c[v[0]]=1;
    rep(i,1,n-1){
        dp[i][1]=mod(dp[i-1][0]+dp[i-1][1]);
        dp[i][0]=c[v[i]];
        Add(c[v[i]],dp[i][1]);
    }
    /*rep(j,0,1){
        rep(i,0,n-1)cout<<dp[i][j]<<" ";cout<<endl;
    }*/
    cout<<mod(dp[n-1][0]+dp[n-1][1])<<endl;
    return 0;
}








Measured memory_bytes: 6640
import random
n = int(input())
a = [int(i) for i in input().split()]

def get_even_idx(a):
    try_idx = random.randint(0,a.len()-1)
    while a[try_idx] % 2 != 0:
        #try again.
        try_idx = random.randint(0,a.len()-1)
    return try_idx

def get_odd_idx(a):
    try_idx = random.randint(0,a.len()-1)
    while a[try_idx] % 2 == 0:
        #try again.
        try_idx = random.randint(0,a.len()-1)
    return try_idx

def select(a):
    even = 0
    odd = 0
    for i in a:
        if i % 2 == 0:
            even += 1
        else:
            odd += 1
#    print("even,odd", even, odd)
    #もし奇数が奇数個存在したらout!!
    if odd % 2 == 1:
        print("NO")
    else:
        print("YES")

select(a)


Measured memory_bytes: 16396
n=int(input())
a=input().split()
for i in range(n):
   if i==0:
       max=int(a[i])
       min=int(a[i])
   if(max<int(a[i])):
       max=int(a[i])
   if (min>int(a[i])):
       min=int(a[i])
print(max-min)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int X;
long long penta[2001];
int main(){
	cin >> X;
  for(int i = 0; i <= 2000; i++){
    penta[i] = pow((i-1000),5);
  }
  bool found = false;
  for(int i = 0; i <= 2000; i++){
    for(int j = 1; j <= 2000; j++){
      if(penta[i] - penta[j] == X){
        cout << i-1000 << " " << j-1000 << endl;
        found = true;
        break;
      }
    }
    if(found == true){
      break;
    }
  }
}

Measured memory_bytes: 4044
#include <stdio.h>

int main(void)
{
    char x[1001];
    int sum;
    int i;
    
    while (1){
        scanf("%s", x);
        if (x[0] == '0'){
            break;
        }
        
        sum = 0;
        i = 0;
        while (x[i] != '\0'){
            sum += x[i] - '0';
            i++;
        }
        printf("%d\n", sum);
    }
    
    return (0);
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli a,b,c,d;
    cin>>a>>b>>c>>d;
    lli x=0;
    while(a>0 && c>0){
    	if(x%2==0){
    		c=c-b;
    		x=1-x;
		}
		else{
			a=a-d;
			x=1-x;
		}
	}
	if(a<=0)
	cout<<"No";
	else 
	cout<<"Yes";
    return 0;
}


Measured memory_bytes: 3640
n = int(input())
a_array = map(int, input().split())
color = [0, 0, 0]
ans = 1
for a in a_array:
    count = 0
    for i in range(3):
        if color[i] == a:
            if not count:
                color[i] += 1
            count += 1
    ans *= count
    ans %= 1000000007
print(ans)

Measured memory_bytes: 10620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N; cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    for(int i=0; i<N; i++){
        cin >> S[i] >> P[i];
    }
    
    vector<int> O(N);
    iota(O.begin(), O.end(), 0);
    sort(O.begin(), O.end(), [&](int a, int b){
        if(S[a] == S[b]) return P[a] > P[b];
        return S[a] < S[b];
    });
    
    for(int i=0; i<N; i++){
        cout << O[i] + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;


int main() {
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	int r = C - (A - B);
	printf("%d", r > 0 ? r : 0);
	return 0;
}

Measured memory_bytes: 128
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s.size() != 26) {
		for (char c = 'a'; c <= 'z'; ++c) {
			if (s.find(c) == string::npos) {
				cout << s + c << endl;
				break;
			}
		}
	}
	else {
		string ans;
		for (int i = s.size() - 1; i >= 0 && ans.empty(); --i) {
			int rem = 'z' - s[i];
			for (int j = 0; j < i; ++j) {
				if (s[j] > s[i]) --rem;
			}
			if (rem > 0) {
				for (char j = s[i] + 1; j <= 'z'; ++j) {
					if (s.substr(0, i).find(j) == string::npos) {
						ans = s.substr(0, i) + j;
						break;
					}
				}
			}
		}
		if (ans.empty()) cout << -1 << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=105;
const int M=15;
long long int n,f[N][M],p[N][M],x,ans=-1000000000,c[N];
 
int main(){
    bool b=0;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>f[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>p[i][j];
        }
    }
    for(int i=1;i<(1<<10);i++){
        memset(c,0,sizeof(c));
        x=0;
        for(int j=0;j<=9;j++){
            if((1<<j)&i){
                for(int k=0;k<n;k++){
                    c[k]+=f[k][j];
                }
            }
        }
        for(int j=0;j<n;j++){
//            cout<<j<<' '<<c[j]<<'\n';
            x+=p[j][c[j]];
        }
//        cout<<i<<' '<<x<<'\n';
        ans=max(ans,x);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
N = int(input())
D = sorted(list(map(int, input().split())))

D1 = [0] + [(D[i] if i % 2 == 0 else 24 - D[i]) for i in range(N)]
D2 = [0] + [(D[i] if i % 2 == 0 else 24 - D[i]) for i in range(N)]

ans1 = float('inf')
ans2 = float('inf')

for i in range(N + 1):
    for j in range(i + 1, N + 1):
        ans1 = min(ans1, abs(D1[i] - D1[j]))
        ans2 = min(ans2, abs(D2[i] - D2[j]))

print(max(ans1, ans2))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//-------------------------------------------------------------------------------

#define MAX 10000

ll a[2222][2222];

ll sum2d(ll x2, ll y2, ll x1, ll y1) {
  return a[x2][y2] - a[x2][y1 - 1] - a[x1 - 1][y2] + a[x1 - 1][y1 - 1];
}

int main(void) {
  ll x, y, k;
  char c;
  cin >> n >> k;

  FOR(i, 0, n) {
	cin >> x >> y >> c;
	if (c == 'W') x += k;
	x %= 2 * k;
	y %= 2 * k;
	a[x + 1][y + 1]++;
  }

  FOR(i, 0, 2 * k + 2) {
	FOR(j, 0, 2 * k + 2) {
	  a[i + 1][j + 1] += a[i + 1][j] + a[i][j + 1] - a[i][j];
	}
  }

  FOR(x, 1, k + 1) {
	FOR(y, 1, k + 1) {
	  temp = 0;
	  temp += sum2d(x + k - 1, y + k - 1, x, y);
	  if (x > 1 && y > 1)temp += sum2d(x - 1, y - 1, 1, 1);
	  temp += sum2d(2 * k, 2 * k, x + k, y + k);
	  if (x > 1) temp += sum2d(x - 1, 2 * k, 1, y + k);
	  if (y > 1) temp += sum2d(2 * k, y - 1, x + k, 1);
	  ans = max(ans, max(n - temp, temp));
	}
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 35072
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;


int main() {
	ll a, b,c,d,e;
	cin >> a>>b;
	c = max(a + b, a - b);
	c = max(c, a*b);
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


def eratosthenes(n):
    p = []
    t = [-1] * n

    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i] == -1:
            p.append(i)
            t[i] = i
            for j in range(2*i, n, i):
                if t[j] == -1:
                    t[j] = i

    for j in range(i+1, n):
        if t[j] == -1:
            p.append(j)
            t[j] = j

    return p, t

P, T = eratosthenes(10**6+1)

@mt
def slv(N, A):
    c = Counter()
    for a in A:
        while a != 1:
            p = T[a]
            t = 0
            while a % p == 0:
                t += 1
                a //= p
            if t > 0:
                c[p] = max(c[p], t)
            if a == 1:
                break

    M = Mod(10**9+7)
    L = 1
    for k, v in c.items():
        L = M.mul(L, M.pow(k, v))

    ans = 0
    for a in A:
        ans = M.add(ans, M.div(L, a))

    return ans




def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


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

string s;
int n, ans;

int main() {
  int i, j;
  while(1) {
    cin >> n;
    if(n == 0) break;
    vector<int> v;
    for(i = 0; i < n; ++i) {
      cin >> s;
      v.push_back(s.size());
    }
    ans = 0;
    for(i = 0; i < n; ++i) {
      if(ans != 0) break;
      int now = 0, ch = 0;
      for(j = i; j < n; ++j) {
        now += v[j];
        if(now == 5 || now == 12 || now == 17 || now == 24 || now == 31) ++ch;
        if(now > 31) break;
      }
      if(ch == 5) ans = ++i;
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 101010
using namespace std;

vi g[MAXN];


vector<pii> added;

map<int , int> eee[MAXN];

void brute(int n){
	bool ck = 1;
	while(ck){
		ck = 0;
		rep(u , n){
			for(int to1 : g[u]){
				for(int to2 : g[to1]){
					for(int to3 : g[to2]){
						set<int> s;
						s.insert(u);
						s.insert(to1);
						s.insert(to2);
						s.insert(to3);
						if(sz(s)==4 && eee[u][to1] && eee[to1][to2] && eee[to2][to3])
						if(eee[u].find(to3)==eee[u].end()){
					//	cout << u+1 << " " <<to3+1 << " " << to1+1 << " " << to2 + 1 << nl;
					//	cout << eee[u][to1] << nl;
							eee[u][to3]=1;
							eee[to3][u] = 1;
							added.pb({u , to3});
							g[u].pb(to3);
							g[to3].pb(u);
							ck = 1;
						}
					}
				}
			}	
		}
	}
}

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

	int n , m;
	cin >> n >> m;
	
	rep(i , m){
		int u , v;
		cin >> u >> v;
		--u;
		--v;
		g[u].pb(v);
		g[v].pb(u);
	//	eee[u][v] = eee[v][u] = 1;
	}
	
//	brute(n);
//	cout << added.size() << nl;
//	rep(i , added.size()){
//		cout << 1+added[i].fi << " " << 1+added[i].se << nl;
//	}

	vi used(MAXN , 0);
	queue<int> q({0});
	used[0] = 1;
	while(sz(q)){
		int e = q.front();
		q.pop();
		for(int to : g[e]){
			if(!used[to]){
				q.push(to);
				used[to] = -1 * used[e];
			}else if(used[to] == used[e]){
				dier(1ll * n * (n - 1) / 2 - m);
			}
			
		}
	}

	
	vi cols = {0 , 0};
	
	rep(i , n){
		++cols[used[i] == 1];
	}
	cout << 1ll * cols[0] * cols[1] - m;
	

	return 0;
}

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

#define ll long long int 
ll a[100009];
int main()
{
	
	ll n,i;
	scanf("%lld",&n);
	
	long double s=0;
	for(i = 0 ; i < n ; i++ )
	scanf("%lld",&a[i]);
	for(i=0;i<n;i++)
	{
		if(a[i]==0)
		{
			printf("0\n");
			return 0;
		}
	}
	s=0;
	for(i=0;i<n;i++)
	{
		s+=log10(a[i]);
	}
	if(s>18)
	{
	    printf("-1\n");
		return 0;
	}
	ll ans=1;
	for(i=0;i<n;i++)
	{
		ans*=a[i];
	}
	if(ans>1000000000000000000)
	{
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4708
import sys
sys.setrecursionlimit(10 ** 8)


def lowLink(N: int, Adj: list):
	articulation = []
	bridge = []
	order = [None] * N
	lowest = [1 << 100] * N

	def _dfs(cur, pre, k):
		order[cur] = lowest[cur] = k
		is_articulation = False
		cnt = 0
		for nxt in Adj[cur]:
			if order[nxt] is None:
				cnt += 1
				_dfs(nxt, cur, k + 1)
				if lowest[cur] > lowest[nxt]:
					lowest[cur] = lowest[nxt]
				is_articulation |= pre >= 0 and lowest[nxt] >= order[cur]
				if order[cur] < lowest[nxt]:
					if cur < nxt:
						bridge.append((cur, nxt))
					else:
						bridge.append((nxt, cur))
			elif nxt != pre and lowest[cur] > order[nxt]:
				lowest[cur] = order[nxt]
		is_articulation |= pre < 0 and cnt > 1
		if is_articulation:
			articulation.append(cur)

	"""
	kk = 0
	for i in range(N):
		if order[i] is None:
			kk = _dfs(i, -1, kk)
	"""
	_dfs(0, -1, 0)
	return articulation, bridge

def main():
	n,m,*L=map(int,open(0).read().split())
	con=[[] for _ in range(n)]
	for a,b in zip(*[iter(L)]*2):
		con[a-1].append(b-1)
		con[b-1].append(a-1)
	_,br=lowLink(n,con)
	print(len(br))

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
a = lr()
dic = collections.Counter(a)
dic_list = list(dic.items())
dic_list.sort(key=lambda x:x[1], reverse=True)
ans = 0
if len(dic_list) <= k:
    print(ans)
else:
    for _,num in dic_list[k:]:
        ans+=num
    print(ans)

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

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

    vector<int> a(S.size() + 1);
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '<') a[i + 1] = a[i] + 1;
    }

    reverse(S.begin(), S.end());
    reverse(a.begin(), a.end());

    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '>') a[i + 1] = max(a[i + 1], a[i] + 1);
    }

    long long ans = 0;
    for (int i = 0; i < a.size(); ++i) {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2820
import sys
input = sys.stdin.readline

N=int(input())
B=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0]+x[1])
#W+Sの順にソートすると無駄がない。

DP=[0]*(10**4+2)
#重さの合計がWのときの価値。
#W=10**4+1ならそれ以上更新されないので、W>=10**4+1以上のものはそこに置く

for w,s,v in B:
    
    if 10**4+1-w<=s:
        x=max(DP[10**4+1-w:s+1])+v
        if DP[-1]<x:
            DP[-1]=x
        
    for i in range(min(10**4-w,s),-1,-1):
        if DP[i+w]<DP[i]+v:
            DP[i+w]=DP[i]+v

print(max(DP))


Measured memory_bytes: 42716
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll k, n;
    cin >> k >> n;
    cout << (500 * k >= n ? "Yes" : "No");
    return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
using namespace std;

int main() {
	vector<int>s, a, b;
	int n, ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		ans += tmp;
		if (tmp % 10 == 0) {
			a.push_back(tmp);
		}
		else {
			b.push_back(tmp);
		}
	}
	sort(b.begin(), b.end());
	if (ans % 10 == 0) {
		if (b.size() > 0) {
			ans -= b[0];
		}
		else {
			ans = 0;
		}
	}
	cout << ans << endl;
}

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

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

  vector<string> vec;
  for (int i = 0; i < s.size(); i ++) {
    for (int j = 1; j <= k; j ++) {
      string tmp = s.substr(i, j);
      vec.push_back(tmp);
    }
  }
  sort(vec.begin(), vec.end());
  unique(vec.begin(), vec.end());
  string ans = vec.at(k - 1);

  cout << ans << endl;
}


Measured memory_bytes: 1660
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static char UNDETERMINED = 'D';
    private static char SHEEP = 'S';
    private static char WOLF = 'W';
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String s = scan.next();
        char[] d = s.toCharArray();
        if (solve(N, d, Main.SHEEP, Main.SHEEP)) {
            return;
        }
        if (solve(N, d, Main.SHEEP, Main.WOLF)) {
            return;
        }
        if (solve(N, d, Main.WOLF, Main.SHEEP)) {
            return;
        }
        if (solve(N, d, Main.WOLF, Main.WOLF)) {
            return;
        }
        System.out.println(-1);
    }
    private static boolean solve(int N, char[] d, char x, char y) {
        char[] candidates = new char[N];
        Arrays.fill(candidates, Main.UNDETERMINED);
        candidates[0] = x;
        candidates[1] = y;
        for (int i = 0; i < N; i++) {
            if (candidates[i] == Main.SHEEP && d[i] == 'o' || candidates[i] == Main.WOLF && d[i] == 'x') {
                if (candidates[(i + N - 1) % N] == Main.UNDETERMINED) {
                    candidates[(i + N - 1) % N] = candidates[i + 1];
                    continue;
                }
                if (candidates[(i + 1) % N] == Main.UNDETERMINED) {
                    candidates[(i + 1) % N] = candidates[(i + N - 1) % N];
                    continue;
                }
                if (candidates[(i + 1) % N] == candidates[(i + N - 1) % N]) {
                    continue;
                }
                return false;
            } else {
                if (candidates[(i + N - 1) % N] == Main.UNDETERMINED) {
                    candidates[(i + N - 1) % N] = candidates[i+1] == Main.SHEEP ? Main.WOLF : Main.SHEEP;
                    continue;
                }
                if (candidates[(i + 1) % N] == Main.UNDETERMINED) {
                    candidates[(i + 1) % N] = candidates[(i + N - 1) % N] == Main.SHEEP ? Main.WOLF : Main.SHEEP;
                    continue;
                }
                if (candidates[(i + 1) % N] != candidates[(i + N - 1) % N]) {
                    continue;
                }
                return false;
            }
        }
        System.out.println(candidates);
        return true;
    }
}


Measured memory_bytes: 26248
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <string>
using namespace std;
vector<string> s;
string input[200001];
int n;

int main (){
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> input[i];
        s.push_back(input[i]);
    }
    sort(s.begin(), s.end());
    int count = 1;
    for (int i = 0; i < n-1; i++){
        if (s.at(i) != s.at(i+1)){
            count += 1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 17740
import java.util.*;

public class Main{

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			if(s.charAt(0) == 'x' && s.charAt(s.length() - 1) == 'x'){
				System.out.println("x");
			}
			else{
				System.out.println("o");
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 17136
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    Q = int(input())
    queries = [list(map(int, input().split(' '))) for _ in range(Q)]
    ans = [0 for _ in range(Q)]
    s = sum(A)
    for q in range(Q):
        B, C = queries[q]
        if counter[B] != 0:
            cnt = counter[B]
            counter[C] += cnt
            counter[B] = 0
            s += (C - B) * cnt
        ans[q] = s
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Measured memory_bytes: 36952
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>

using namespace std;

class Solver {
};

int main() {	
	while (true) {
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0)break;

		int target = h * h + w * w;
		int minH = 0;
		int minW = 0;
		int val = 1e9;
		for (int i = 1; i <= 150; i++) {
			for (int j = i + 1; j <= 150; j++) {
				if (i == h && j == w)continue;

				int tmp = i * i + j * j;
				if ((i < h && target < tmp && tmp < val)
					|| (i >= h && target <= tmp && tmp < val)) {
					minH = i;
					minW = j;
					val = tmp;
				}
			}
		}

		cout << minH << ' ' << minW << endl;
	}
}


Measured memory_bytes: 3036
import copy
N = int(input())
L = list(map(int,input().split()))
C = copy.deepcopy(L)
C.sort()
P,Q = C[N//2-1],C[N//2]
for i in range(N):
  if L[i] <= P:
    print(Q)
  else:
    print(P)

Measured memory_bytes: 27156
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
               
        String lineN = br.readLine();
        String lineA = br.readLine();

        int N = Integer.parseInt(lineN);
        String[] strA = lineA.split(" ", 0);
        List<Integer> A = new ArrayList<>();
        for (String str : strA) {
            A.add(Integer.parseInt(str));
        }

        int center = A.size() / 2;
        int[] out = new int[A.size()];
        int j = 1;

        if (N % 2 == 0) {
            for (int i = 0; i < center; i++) {
                out[i + center] = A.get(j - 1);
                out[i + center - j] = A.get(j);
                j += 2;
            }
        } else {
            out[center] = A.get(0);
            for (int i = 0; i < center; i++) {
                out[center + (i + 1)] = A.get(j);
                out[center - (i + 1)] = A.get(j + 1);
                j += 2;
            }
        }

        int len = out.length;
        for (int i = 0; i < len; i++) {
            System.out.print(out[i]);
            if (i != len - 1) {
                System.out.print(" ");
            }
        }
    }
}

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

using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  int sw = 1 << 20, s = 0;
  int A, B, C, D;
  for (int i = 0; i * 100 * a <= f; i++) {
    A = i * 100 * a;
    for (int j = 0; j * 100 * b <= f - A; j++) {
      B = j * 100 * b;
      for (int k = 0; k * c <= f - A - B; k++) {
        C = k * c;
        for (int l = 0; l * d <= f - A - B - C; l++) {
          D = l * d;
          int sum = A + B + C + D;
          if (sum > f) continue;
          if ((i * a + j * b) * e < C + D) continue;
          int ns = C + D, nsw = ns + A + B;
          if (nsw * s >= ns * sw) continue;
          sw = nsw, s = ns;
        }
      }
    }
  }
  cout << (sw == 1 << 20 ? 100 * a : sw) << " " << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };
ll csb(ll n){ ll count = 0;while (n){ count += n & 1; n >>= 1; } return count;}


int main()
{

ll test,n,k,i,j,a,b,m,c,d;
cin>>n;
ll sum=(n/500);
sum*=1000;
n=n%500;
n=n/5;
sum+=n*5;
cout<<sum;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvp g;
	public:
	int DIJ(int s,int t){
		priority_queue<P> q;
		vi d(n,inf);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			P p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d[t];
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
		g[t].push_back({s,c});
	}
};

int main(){
	while(1){
		ll n;
		cin>>n;
		if(n==0) break;
		int a,b;
		for(ll i=1;i*(i+1)/2<=n;i++){
			if((n-i*(i+1)/2)%i==0){
				int t=(n-i*(i+1)/2)/i;
				a=t+1,b=i;
			}
		}
		cout<<a<<' '<<b<<endl;
	}
}


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

int main()
{
    ll n,m,h;
    cin>>n>>m>>h;
    ll p[n+5],val[n+5][m+5];
    for(int i=0; i<n; i++){
        cin>>p[i];
        for(int j=0; j<m; j++){
            cin>>val[i][j];
        }
    }
    ll cnt=1;
    for(int i=1; i<=n; i++)
        cnt*=2;
    ll price=0,ans=1e18;
    for(int i=0; i<cnt; i++){
        ll test[m+5];
        for(int y=0; y<m; y++)
            test[y]=0;
        price=0;
        for(int j=0; j<n; j++){
            if((i & (1<<j))!=0){
                price+=p[j];
                for(int k=0; k<m; k++){
                    test[k]+=val[j][k];
                }
            }
        }
        bool flag=true;
        for(int x=0; x<m; x++){
            if(test[x]<h)
            {
                flag=false;
                break;
            }
        }
        if(flag){
            ans=min(ans,price);
        }
    }
    if(ans==1e18)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;

    return 0;

}


Measured memory_bytes: 3540
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

int main()
{
    int h, w;
    cin >> h >> w;
    map<int, int> dist;
    multiset<int> values;
    for (int i = 0; i < w; i++) {
        dist[i] = 0;
        values.insert(0);
    }

    for (int i = 0; i < h; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (auto to = dist.upper_bound(b);
            to != dist.begin() && b + 1 < w && dist.count(b + 1) == 0) {
            auto prev_to = prev(to);
            dist[b + 1] = prev_to->second + (b + 1 - prev_to->first);
            values.insert(dist[b + 1]);
        }

        if (auto to = dist.lower_bound(a);
            to != dist.begin() && dist.count(a - 1) == 0) {
            auto prev_to = prev(to);
            dist[a - 1] = prev_to->second + (a - 1 - prev_to->first);
            values.insert(dist[a - 1]);
        }

        for (auto to = dist.lower_bound(a);
             to != dist.end() && to->first <= b;) {
            int value = to->second;
            auto pos = values.lower_bound(value);
            values.erase(pos);
            dist.erase(to++);
        }

        /*        for (auto p : dist) {
                    cout << p.first << ":" << p.second << " ";
                }
                cout << endl;
                for (auto v : values) {
                    cout << v << " ";
                }
                cout << endl;*/

        if (values.empty())
            cout << -1 << endl;
        else
            cout << *values.begin() + i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 21884