akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define mx_int_prime 999999937
#define mem(a,b) memset(a, b, sizeof(a) )
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef long double ld;
const int mx=2e5+125;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
ll p[mx],a[mx],b[mx];
int main()
{
    faster();
    vector<int> v1,v2,v3;
    int n,y,z;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        v1.PB(x);
        v3.PB(x);
    }
    sort(all(v3));
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        v2.PB(x);
    }
    int cnt=1,flag=0;
    do
    {
        if(v1==v3)
        {
            y=cnt;
            flag++;
        }
        if(v2==v3)
        {
            z=cnt;
            flag++;
        }
        cnt++;
        if(flag==2)
            break;
    }
    while(next_permutation(all(v3)));
    cout<<abs(y-z)<<'\n';

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];
    if(N == 1) {
        cout << 1 << "\n";
        return 0;
    }
    sort(v.begin(), v.end());
    bool tmp = true;
    ll ans = 0;
    for(int i = 1; i < N; i++) {
        if(v[i - 1] != v[i]) {
            if(tmp)
                ans++;
            else
                tmp = true;
        } else {
            tmp = !tmp;
        }
    }
    if(tmp) ans++;
    cout << ans << "\n";
    return 0;
}

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

#define MAX_LINE 8
#define MAXA_DATA 50

using namespace std;

// プロトタイプ宣言
void searchString(string box);

// main関数
int main() {
    int count = 0;
    int max = MAX_LINE * MAXA_DATA;
    char str[8];
    string box;
    for (int i = 0; i < max; i++) {
        cin >> str;
        box.append(str);
        count++;
        // 8行ごとにチェック
        if(count%MAX_LINE == 0){
            searchString(box);
            box = "";
        }
    }
}

// 文字列チェック
void searchString(string box){
    string A("1100000011");
    string B("1000000010000000100000001");
    string C("1111");
    string D("1000000110000001");
    string E("11000000011");
    string F("100000001100000001");
    string G("110000011");
    
    // find関数は文字列がみつからなかったときにnposを返す
    if (box.find(A) != std::string::npos) {
        cout << "A" << endl;
    }
    else if(box.find(B) != std::string::npos) {
        cout << "B" << endl;
    }
    else if(box.find(C) != std::string::npos) {
        cout << "C" << endl;
    }
    else if(box.find(D) != std::string::npos) {
        cout << "D" << endl;
    }
    else if(box.find(E) != std::string::npos) {
        cout << "E" << endl;
    }
    else if(box.find(F) != std::string::npos) {
        cout << "F" << endl;
    }
    else if(box.find(G) != std::string::npos) {
        cout << "G" << endl;
    }
}


Measured memory_bytes: 3016
require 'pp'
s = gets.chomp.chars
t = gets.chomp.chars
# p s
# p t
# pp s.each_cons(t.size).to_a



arr = []
0.upto(s.size - t.size) do |i|

  before_x = (i-1) < 0 ? [] : s[0..(i-1)]
  x = s[i..(i+(t.size-1))]
  after_x = s[(i+(t.size))..-1]
  if Regexp.new(x.join.gsub('?', '\w')) === t.join
    arr << before_x.join + t.join + after_x.join
  else
    nil
  end
end
if arr.empty?
  puts 'UNRESTORABLE'
  exit
end
puts arr.map{|ss|ss.gsub('?','a')}.sort[0]


Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<(b);++i)
using namespace std;

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

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

	string ans;
	for(char c : S){
		if (c == '0' || c == '1') ans.push_back(c);
		else if (c == 'B' && !ans.empty()) ans.pop_back();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  vector<int> c(n);
  for (int i = 0; i < m; i++){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    c[a] = (c[a] + 1) % 2;
    c[b] = (c[b] + 1) % 2;
  }

  int ok = 1;
  for (int i = 0; i < n; i++){
    if(c[i] == 1)
      ok = 0;
  }
  if(ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>

#define rep(i,p,n) for(int i=p;i<n;i++)
#define lli long long int
#define vi vector<int> 

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}


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

	bool c = true, f = true;

	rep(i, 0, s.length()) {
		if (s[i] == 'C')c = false;
		if (s[i] == 'F' && !c)f = false;
	}

	if (!c && !f) pp("Yes");
	else pp("No");



	return 0;
}

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

int main()
{
	int n, cnt, y;
	int c[31];

	c[0] = 1;
	c[1] = 1;
	c[2] = 2;
	for( int i=3; i<=30; i++ )
		c[i] = c[i-1] + c[i-2] + c[i-3];

	while( cin >> n, n != 0 ){
		y = c[n]/(365*10);
		y += !( c[n]%(365*10) == 0 );
		cout << y << endl;
	}

	return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#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;

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

    Int N; cin >> N;
    vector<Int> a(N), b(N), c(N);
    rep(i, 0, N) cin >> a[i] >> b[i] >> c[i];

    vector<Int> dpA(N, 0), dpB(N, 0), dpC(N, 0);
    dpA[0] = a[0];
    dpB[0] = b[0];
    dpC[0] = c[0];

    rep(i, 1, N) {
        dpA[i] = max(dpB[i-1]+a[i], dpC[i-1]+a[i]);
        dpB[i] = max(dpA[i-1]+b[i], dpC[i-1]+b[i]);
        dpC[i] = max(dpA[i-1]+c[i], dpB[i-1]+c[i]);
    }

    Int res = max(max(dpA[N-1], dpB[N-1]), dpC[N-1]);
    cout << res << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n[3];
  cin >> n[0] >> n[1] >> n[2];
  sort(n, n + 3);
  cout << n[0] << ' ' << n[1] << ' ' << n[2] << endl;
  return 0;
}

Measured memory_bytes: 3108
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
using namespace std;
using lint = long long;
using ld = long double;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
#pragma endregion

const lint INF = 1ll << 60;
const int mod = 1000000007;

lint dp[110][100100];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, w; cin >> n >> w;
	vector<pair<lint, lint>> d(105);
	for (int i = 0; i < n; i++) cin >> d[i].first >> d[i].second;
	for (int i = 0; i < 110; i++) for (int j = 0; j < 100100; j++) dp[i][j] = INF;
	dp[0][0] = 0;
	for (int i = 0; i < 105; i++) {
		for (int j = 0; j < 100010; j++) {
			if (j - d[i].second >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - d[i].second] + d[i].first);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	lint ans = 0;
	for (lint i = 0; i < 100010; i++) if (dp[n][i] <= w) ans = max(ans, i);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 89640
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
LL d;
LL a[5];
int main()
{
	scanf("%lld %lld %lld",&a[1],&a[2],&a[3]);
	if(a[1] % 2 == 0 || a[2] % 2 == 0 || a[3] % 2 == 0)
	{
		printf("0\n");
		return 0;
	}
	else 
	{
		sort(a + 1,a + 1 + 3);
		printf("%lld\n", a[1] * a[2]);
		return 0;
	}
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int root;

vector<int> temp_node[100000];

struct node{
    int parent;
    int height;
    vector<int> child;
};

void construct_tree(node *nd, int p, int s){
    nd[s].parent = p;
    rep(i, temp_node[s].size()){
        int to = temp_node[s][i];
        if(to == p) continue;
        nd[s].child.push_back(to);
        construct_tree(nd, s, to);
    }
}

int calc_height(node *nd, int p, int s){
    int res = -1;
    if(nd[s].child.empty()){
        nd[s].height = 0;
        return 0;
    }
    rep(i, nd[s].child.size()){
        res = max(res, calc_height(nd, s, nd[s].child[i]));
    }
    nd[s].height = res + 1;
    return nd[s].height;
}

int main(void){
    int N; cin >> N;
    int u, v; cin >> u >> v;
    u--; v--;
    root = v;
    node nd[N];

    rep(i, N-1){
        int a, b; cin >> a >> b;
        a--; b--;
        temp_node[a].push_back(b);
        temp_node[b].push_back(a);
    }

    construct_tree(nd, -1, root);

    calc_height(nd, -1, root);

    int pos = u;
    int dist = 0;
    while(pos != root){
        pos = nd[pos].parent;
        dist++;
    }
    int ans = 0;
    int climb = (dist-1) / 2;
    rep(i, climb){
        u = nd[u].parent;
        ans++;
    }
    dist -= ans*2;
    int h = nd[u].height;
    if(dist % 2 == 0){
        cout << ans + h + 1 << endl;
    }
    else{
        cout << ans + h << endl;
    }

    return 0;
}

Measured memory_bytes: 19328
A = int(input())
B = int(input())
C = int(input())
X = int(input())
Z = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if X == (i * 500) + (j * 100) + (k * 50):
                Z += 1
print(Z)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
   
  cin >> a ;
  
  
  if(a=="a"||a=="i"||a=="u"||a=="e"||a=="o"){
    cout <<"vowel"<<endl; 
  }else{
     cout <<"consonant"<<endl;
  }     
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int A, B, C; cin >> A >> B >> C;
    cout << ((C - (A - B)) >= 0?(C - (A - B)):0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

// -------------8<------- start of library -------8<------------------------
struct LowestCommonAncestor {
    const int root, INF, n;
    int size, no;
    std::vector<std::vector<int>> adj;
    std::vector<int> ord, idx;
    std::vector<std::pair<int, int>> dep;

    LowestCommonAncestor(int _n, int _r = 0) :
        root(_r), INF(INT_MAX), n(_n), adj(n), ord(2 * n - 1), idx(n) {}

    void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); }

    void Dfs(int cur, int p, int d) {
        ord[no] = cur;
        idx[cur] = no;
        dep[size - 1 + no++] = std::make_pair(d, cur);
        for (int nxt : adj[cur]) {
            if (nxt == p) continue;
            Dfs(nxt, cur, d + 1);
            ord[no] = cur;
            dep[size - 1 + no++] = std::make_pair(d, cur);
        }
    }

    void Preprocessing() {
        for (size = 1; size < 2 * n - 1; ) size <<= 1;
        dep.assign(2 * size - 1, std::make_pair(INF, INF));

        no = 0;
        Dfs(root, -1, 0);

        for (int i = size - 2; 0 <= i; --i) {
            if (dep[2 * i + 1] < dep[2 * i + 2]) dep[i] = dep[2 * i + 1];
            else dep[i] = dep[2 * i + 2];
        }
    }

    int rmq(int l, int r) {
        std::pair<int, int> res(INF, INF);
        l += size - 1;
        r += size - 1;
        while (l < r) {
            if ((l & 1) == 0) res = std::min(res, dep[l]);
            if ((r & 1) == 0) res = std::min(res, dep[r - 1]);
            l >>= 1;
            r = (r - 1) >> 1;
        }
        return res.second;
    }

    int query(int u, int v) {
        if (idx[v] < idx[u]) std::swap(u, v);
        return rmq(idx[u], idx[v] + 1);
    }
};
// -------------8<------- end of library ---------8-------------------------

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

    // AOJ GRL_5_C: Tree - Lowest Common Ancestor
    int n;
    std::cin >> n;

    LowestCommonAncestor lca(n, 0);
    for (int v = 0, deg, c; v < n; ++v) {
        std::cin >> deg;
        while (deg--) {
            std::cin >> c;
            lca.add_edge(v, c);
        }
    }
    lca.Preprocessing();

    int q, u, v;
    std::cin >> q;
    while (q--) {
        std::cin >> u >> v;
        std::cout << lca.query(u, v) << '\n';
    }

    return 0;
}



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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
#define int long long
const int mod = 1e9 + 7;

const int N = 1e6 + 5;

int n, q, sum[N], total[N], ways;

string s;
bool used[N];
vector<int> vec;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    cin >> s;
    s = "+" + s;
    for(int i = 1; i <= n; i++) {
        if(s[i] == 'M')
            sum[i] = 1;
        sum[i] += sum[i - 1];
        if(s[i] == 'C')
            total[i] = 1;
        total[i] += total[i - 1];
        if(s[i] == 'D')
            vec.pb(i);
    }
    cin >> q;
    while(q--) {
        int k;
        cin >> k;
        if(vec.size() == 0) {
            cout << "0\n";
            continue;
        }
        ways = 0;
        long long sumb = 0, sumc = 0;
        int l = vec[0], r = l;
        for(int i = 0; i < vec.size(); i++) {
            while(l < vec[i]) {
                if(s[l] == 'C')
                    sumc--;
                if(s[l] == 'M')
                    sumb -= sumc;
                l++;
            }
            while(r - l < k && r <= n) {
                if(s[r] == 'C') {
                    sumb += sum[r] - sum[l - 1];
                    sumc++;
                }
                r++;
            }
            ways += sumb;
            //cout << l << " " << r << " " << sumb << "\n";
        }
        cout << ways << "\n";
    }
}



Measured memory_bytes: 26688
#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define N                1000005
#define inf              999999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type, less<int >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//________________________________________________________________________________________________________________
bool cmp(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.first>b.first) return true;
    if(a.first<b.first) return false;
    if(a.second<b.second) return true;
    else return false;

}
bool ok=false;
ll vis[N],infact[N];
ll t,n,m,x,p,r,y,z,mod=998244353,ans;
vector<ll>v;
string s,s1;
int main()
{
    cin>>n>>m;
    x=gcd(n,m);
    x=(n*m)/x;
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


void solve(){

    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a) cout << k << endl;
    else if(a<k&&k<=a+b) cout << a << endl;
    else cout << a-(k-a-b) << endl;
    

}

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


Measured memory_bytes: 3648
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,K = map(int,input().split())
S = str(input())

replace = S[K-1]
replace = replace.lower()

print(S[:K-1]+replace+S[K:])


Measured memory_bytes: 7876
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		for(int mask = 0 ; mask < 1<<(n - 1) ; mask++) {
			String temp = s.charAt(0) + "";
			int value = (int)(s.charAt(0) - '0');
			for(int i = 0 ; i < 3 ; i++) {
				if((mask&(1<<i)) >= 1) {
					temp += "+" + s.charAt(i + 1);
					value += (int)(s.charAt(i + 1) - '0');
				} else {
					temp += "-" + s.charAt(i + 1);
					value -= (int)(s.charAt(i + 1) - '0');
				}
			}
			if(value == 7) {
				System.out.println(temp + "=7");
				return;
			}
		}
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <tuple>


#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    string S; cin >> S;
    vector<int>A(26);
    rep(i, S.size()) {
        A[S.at(i) - 97]++;
    }
    if (S.size() != 26) {
        cout << S;
        rep(i, 26) {
            if (A[i] == 0) {
                cout << char(i + 97) << endl; return 0;
            }
        }
    }
    REV(i,26) {
        if (S.at(i) < S.at(i - 1)){A[S.at(i)-97]--;continue;}
        for(int j=i;j>=0;j--){
          A[S.at(j)-97]--;
          for(int k=S.at(j)+1;k<123;k++){
            if(A[k-97]==0){
              for(int l=0;l<j;l++)cout<<S.at(l);
              cout << char(k) << endl;
              return 0;
            }
          }
        }
    }
    cout << -1 << endl;
}


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

namespace AtTest.ABC_139
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] hs = ReadInts();
            int[] sums = new int[n];
            sums[n - 1] = 0;
            for(int i = n - 2; i >= 0; i--)
            {
                if (hs[i] >= hs[i + 1]) sums[i] = sums[i + 1] + 1;
            }
            int res = 0;
            for (int i = 0; i < n; i++) res = Max(res, sums[i]);
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 25308
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int a, b, h; scanf("%d%d%d", &a, &b, &h);
	
	printf("%d\n", (a + b) * h / 2);
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll n; cin >> n;
    map<char, ll> m;
    REP(i, n){
        string s; cin >> s; map<char, ll> t_m;
        for (int i = 0; i < s.size(); i++) {
            t_m[s[i]]++;
        }
        if(i == 0) m = t_m;
        else{
            for(auto it = m.begin(); it != m.end(); it++){
                auto key = it->first;
                m[key] = min(t_m[key], m[key]);
            }
        }
    }
    string ret = "";
    for (auto it = m.begin(); it != m.end(); it++) {
        auto key = it->first;
        REP(i, it->second){
            ret += key;
        }
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
ans = 0
minnow = A[0]
for i in range(1,N):
    if(minnow > A[i]):
        ans += minnow - A[i]
    else:
        minnow = A[i]
print(ans)
    

Measured memory_bytes: 92908
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <vector>

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

    int64_t N;
    std::cin >> N;

    int64_t i,j;
    int64_t min_step = N - 1;
    for(int64_t k = 2; k * k <= N; k++){
        if(N % k == 0){
            i = k;
            j = N / k;
            min_step = std::min(min_step, i-1 + j-1); 
        }
    }
    std::cout << min_step;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

int lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

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


int main(){
    string S;
    string T;
    cin >> S >> T;
    bool OK = true;
    if(S.size()+1 != T.size()){
        OK = false;
    }
    for (int i = 0; i < S.size();i++)
    {
        if(S[i] != T[i]){
            OK = false;
            break;
        }
    }
    if(OK){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3596
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    NS = input()
    N = list(NS.strip())
    fx = 0
    for i in N:
        fx += int(i)

    n = int(NS)
    print("Yes" if n % fx == 0 else "No")



main()


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 998244353; //1e9+7;
const int MAXN = 1e7+1;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int K,N; cin >> K >> N;
    vector<int> a(N);
    fori(i,N) cin >> a[i];

    //debugv(a);
    int mx = a[0]+K-a[N-1];
    fori(i,N-1) mmax(mx, a[i+1]-a[i]);
    cout << K-mx << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std ; 
const int N = 1e6 + 1e5 ; 
long long pt[N] , dd[N] , mark[N] , x , y , a , b , c , st1 , st2 , st3 , ans = 0 ;
bool cmp(int i , int j){
	return pt[i] > pt[j] ;
}
int main(){
	cin>>x>>y>>a>>b>>c;
	for(int i = 1 ; i <= a + b + c ; i ++){
		cin>>pt[i] ;
		dd[i] = i ;
		if(i <= a) {
			mark[i] = 1 ;
		}else if(i <= a + b ){
			mark[i] = 2 ;
		}else{
			mark[i] = 3 ;
		}
	}
	sort(dd + 1 , dd + a + b + c + 1 , cmp) ;
	long long n = a + b + c ;
	for(int i = 1 ; i <= n ; i ++){
		if(mark[dd[i]] == 1 && st1 < x){
			st1 ++ ;
			ans += pt[dd[i]] ;
		}else if(mark[dd[i]] == 2 && st2 < y){
			st2 ++ ;
			ans += pt[dd[i]] ;
		}else if(mark[dd[i]] == 3 ){
			st3 ++ ;
			ans += pt[dd[i]] ;
		}
		if(st1 + st2 + st3 == x + y) break ;
	}
	cout<<ans<<endl ;
	return 0 ;
} 

Measured memory_bytes: 10668
#include<stdio.h>
int main(void)
{
	int a, b;

	scanf("%d", &a);

	if (a % 2 == 0)
		printf("0.5");
	else
	{
		b = a - a / 2;
		printf("%.10lf\n", (double)b / (double)a);
	}
}

Measured memory_bytes: 128
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        io.r<int>();
        List<int> n = io.r<int>(' ').ToList<int>();
        List<int> sort = new List<int>();
        while (n.Count() != 0)
        {
            int b = n[0];
            n.RemoveAt(0);
            bool f = false;
            for (int i = 0; i < sort.Count(); i++)
            {
                if (b < sort[i]) { sort.Insert(i, b); f = true; break; }
            }
            if (!f) { sort.Add(b); }
            List<string> output = new List<string>();
            output.AddRange(sort.Select(item => item.ToString()));
            output.AddRange(n.Select(item => item.ToString()));
            io.w(string.Join(" ", output.ToArray()));
        }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
}

Measured memory_bytes: 10568
import std.stdio;
import std.string;
import std.range;
import std.conv;

void main()
{
	auto ip = readln.split.to!(int[]), X = ip[0], A = ip[1], B = ip[2];
	if(A >= B) {
		writeln("delicious");
	} else {
		if(B-A > X) {
			writeln("dangerous");
		} else {
			writeln("safe");
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;

int main() {
    cin >> n >> a >> b;
    if (a > b) {
        cout << 0 << endl;
        return 0;
    }
    long long L = a * (n - 1) + b;
    long long R = a + b * (n - 1);
    long long res = max(0LL, R - L + 1);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>

int main()
{
	int n, m, r;
	std::cin >> n >> m >> r;
	
	int rs[100];
	for (int i = 0; i < r; ++i)
	{
		std::cin >> rs[i];
		--rs[i];
	}
	
	long long int dist[310][310] = { 0 };
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i != j)
				dist[i][j] = INT_MAX;
		}
	}
	
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		long long int c;
		std::cin >> a >> b >> c;
		--a;
		--b;
		
		dist[a][b] = std::min(dist[a][b], c);
		dist[b][a] = std::min(dist[b][a], c);
	}
	
	for (int k = 0; k < n; ++k)
	{
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (dist[i][j] > dist[i][k] + dist[k][j])
				{
					dist[i][j] = dist[i][k] + dist[k][j];
					dist[j][i] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
	
	std::sort(rs, rs + r);
	
	long long int ans = LONG_MAX;
	do
	{
		long long int count = 0;
		
		for (int i = 1; i < r; ++i)
			count += std::min(dist[rs[i - 1]][rs[i]], dist[rs[i]][rs[i - 1]]);
		
		ans = std::min(ans, count);
	} while (std::next_permutation(rs, rs + r));
	
	std::cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int H[N];
  for (int i = 0; i < N; i++) cin >> H[i];
  bool good[N];
  fill(good, good + N, true);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (H[a] <= H[b]) good[a] = false;
    if (H[b] <= H[a]) good[b] = false;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) ans += good[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4144
#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n - 1; i++) {
        if((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
        else if((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
    }
    cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

    int highest = 0, ans = 0;
    for ( i = 0; i < n; i++ ) {
        if ( h[i] >= highest ) {
            highest = h[i];
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int n,w,z;
vector<int> v;
int main(){
	while(cin>>n>>w&&n){
	v.clear();
	int h=0;
	while(n--){
		cin>>z;
		while(true){
			if(v.size()>z/w)break;
			v.push_back(0);
		}
		v[z/w]++;
		h=max(v[z/w],h);
	}
	double a=0.01;
	for(int i=0;i<v.size();i++)a+=v[i]/(h+0.0)*(1-i/(v.size()-1.0));
	cout<<fixed<<setprecision(9)<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 3224
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int A, B;
  cin >> A >> B;
  cout << (A - 1) * (B - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e17;
using P = pair<ll, ll>;

template <typename T>
class SegmentTree {
	using func_t = function<T(const T&, const T&)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	ll sub(int l, int r, int node, int lb, int ub, ll val) {
		if (ub <= l || r <= lb) return 0;
		if (l <= lb && ub <= r) return data[node].end() - lower_bound(data[node].begin(), data[node].end(), val);
		return sub(l, r, node * 2, lb, (lb + ub) / 2, val) + sub(l, r, node * 2 + 1, (lb + ub) / 2, ub, val);
	}
public:
	SegmentTree(const vector<T>& data_, T id_, func_t merge_) :
		n(size(data_.size())), id(id_), merge(merge_), data(n * 2, id_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	ll Find(int l, int r, ll val) {
		return sub(l, r + 1, 1, 0, n, val);
	}
};


int main()
{
	cin.sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<vector<P>> G(n);
	for (int i = 0, a, b, c; i < m; i++) {
		cin >> a >> b >> c;
		G[a].push_back(P(b, c));
		G[b].push_back(P(a, c));
	}
	vector<ll> sd(n, INF), td(n, INF);
	priority_queue<P, vector<P>, greater<P>> pq1;
	pq1.push(P(0, 0));
	while (!pq1.empty()) {
		auto p = pq1.top(); pq1.pop();
		if (sd[p.second] != INF) continue;
		sd[p.second] = p.first;
		for (auto to : G[p.second]) {
			if (sd[to.first] == INF) {
				pq1.push(P(p.first + to.second, to.first));
			}
		}
	}
	priority_queue<P, vector<P>, greater<P>> pq2;
	pq2.push(P(0, n - 1));
	while (!pq2.empty()) {
		auto p = pq2.top(); pq2.pop();
		if (td[p.second] != INF) continue;
		td[p.second] = p.first;
		for (auto to : G[p.second]) {
			if (td[to.first] == INF) {
				pq2.push(P(p.first + to.second, to.first));
			}
		}
	}
	vector<P> dd(n);
	for (int i = 0; i < n; i++) {
		dd[i].first = sd[i];
		dd[i].second = td[i];
	}
	sort(dd.begin(), dd.end());
	vector<vector<ll>> ba(n);
	for (int i = 0; i < n; i++) {
		sd[i] = dd[i].first;
		ba[i].push_back(dd[i].second);
	}
	SegmentTree<vector<ll>> st(ba, vector<ll>(), [](const vector<ll>& l, const vector<ll>& r) {
		int nl = l.size(), nr = r.size();
		vector<ll> res; res.reserve(nl + nr);
		for (int i = 0, j = 0; i < nl || j < nr; ) {
			if (j == nr) {
				res.push_back(l[i++]);
				continue;
			}
			if (i == nl) {
				res.push_back(r[j++]);
				continue;
			}
			if (l[i] <= r[j]) {
				res.push_back(l[i++]);
			}
			else {
				res.push_back(r[j++]);
			}
		}
		return res;
	});
	ll q, fs, fg;
	cin >> q;
	while (q--) {
		cin >> fs >> fg;
		int l = 0, r = upper_bound(sd.begin(), sd.end(), fs) - sd.begin() - 1;
		printf("%lld\n", st.Find(l, r, fg));
	}
	return 0;
}

Measured memory_bytes: 44032
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) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        long[] a = new long[n];
        final long mod = 1000000007;

        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            sum += a[i];
        }

        long ans = 0;
        for (int i = 0; i < n-1; i++) {
            sum -= a[i];
            long tmp = a[i] * (sum % mod);
            ans += tmp % mod;
            ans %= mod;
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 56256
import bisect

def logcmb(a,b):
  if a<=b or a == 0 or b == 0:
    return 1
  return a*(a+1)//2 - (a-b)*(a-b+1)//2 - b*(b+1) // 2
n = int(input())
a = list(map(int,input().split()))
a.sort()
jdg = 0
for i in range(n):
  x = a[i]
  y = a[i]/2
  c = bisect.bisect_right(a,y)
  if c >= 1 and a[c]-y >= y-a[c-1]:
    r = a[c-1]
  elif c >= 1 and y-a[c-1] > a[c]-y:
    r = a[c]
  elif c == 0:
    r = a[0]
  if logcmb(x,r) >= jdg:
    jdg = logcmb(x,r)
    ans = x,r

print(*ans,sep=" ")

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int t;
    //cin >> t;
    t =1;
    while (t--)
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int ans = a*c;
        for(int i : {a,b})
        {
            for(int j : {c,d})
            {
                ans = max(ans,i*j);
            }
        }
        cout << ans << endl;
    }
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/

Measured memory_bytes: 3648
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int n, m;
vector<int> fronts, backs;

int dfs(vector<bool> bools, int s){
    bools[s-1] = true;
    bool last = true;
    for(int i = 0; i < n; i++){
        last = last && bools[i];
    }
    if(last){
        return 1;
    }
    set<int> next;
    for(int i = 0; i < fronts.size(); i++){
        if(fronts[i] == s){
            int back = backs[i];
            if(!bools[back-1]){
                next.insert(back);
            }
        }
    }

    int sum = 0;
    for(int item : next){
        sum += dfs(bools, item);
    }

    return sum;

}

int main(){
    cin >> n >> m;
    for(int i = 0; i<m; i++){
        int a, b;
        cin >> a >> b;
        fronts.push_back(a);
        backs.push_back(b);
        fronts.push_back(b);
        backs.push_back(a);
    }
    vector<bool> bools(n, false);
    int result = dfs(bools, 1);
    

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static boolean win(StringBuilder a, StringBuilder b){
		StringBuilder c = new StringBuilder(a);
		StringBuilder d = new StringBuilder(b);
		for(int i=0; i<c.length(); i++){
			if(c.charAt(i) == '?') c.setCharAt(i, 'a');
		}
		for(int i=0; i<d.length(); i++){
			if(d.charAt(i) == '?') d.setCharAt(i, 'z');
		}
		for(int i=0; i<c.length() && i<d.length(); i++){
			if(c.charAt(i) != d.charAt(i)){
				return c.charAt(i) < d.charAt(i);
			}
		}
		return c.length() <= d.length();
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder s[] = new StringBuilder[n];
		StringBuilder t;
		for(int i=0; i<n; i++) s[i] = new StringBuilder(sc.next());
		t = new StringBuilder(sc.next());
		int low = 0, high = 0;
		for(int i=0; i<n; i++){
			boolean p1 = win(t, s[i]);
			boolean p2 = win(s[i], t);
			if(p1 && p2){
				high++;
			}
			else if(p2){
				low++;
				high++;
			}			
		}
		sc.close();
		for(int i=low+1; i<=high+1; i++){
			System.out.print(i);
			if(i <= high) System.out.print(" ");
			else System.out.println("");
		}
	}
}


Measured memory_bytes: 34260
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int L = s.nextInt();//冬休みの期間
		int A = s.nextInt();//国語のドリルのページ数
		int B = s.nextInt();//算数のドリルのページ数
		int C = s.nextInt();//一日に進められる国語のページ数
		int D = s.nextInt();//一日に進められる算数のページ数
		int asum = 0;
		int bsum = 0;
		int acount = 0;
		int bcount = 0;
		do{//国語が何日で終わるか
			asum += C;
			acount++;
		}while(asum<A);
		do{//算数が何日で終わるか
			bsum += D;
			bcount++;
		}while(bsum<B);
		if(bcount<acount){
			System.out.println(L-acount);
		}else{
			System.out.println(L-bcount);
		}
	}
}

Measured memory_bytes: 17164
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

case = 1
for s in sys.stdin:

    # capacity
    C = int(s)
    if C == 0:
        break

    N = int(input())

    V = [0]
    W = [0]

    # max value table of (N+1) x (C+1)
    VT = [[0 for i in range(C+1)] for j in range(N+1)]
    WT = [[0 for i in range(C+1)] for j in range(N+1)]

    for i in range(N):
        v, w = map(int, input().split(','))
        V.append(v)
        W.append(w)

    for i in range(1, N+1):
        for j in range(1, C+1):
            if j >= W[i]:
                # can load
                value_on_load = VT[i-1][j - W[i]] + V[i]
                value_not_load = VT[i-1][j]

                weight_on_load = WT[i-1][j - W[i]] + W[i]
                weight_not_load = WT[i-1][j]

                if value_on_load > value_not_load:
                    VT[i][j] = value_on_load
                    WT[i][j] = weight_on_load
                elif value_on_load == value_not_load:
                    VT[i][j] = value_on_load
                    WT[i][j] = min(weight_on_load, weight_not_load)
                else:
                    VT[i][j] = value_not_load
                    WT[i][j] = weight_not_load
            else:
                VT[i][j] = VT[i - 1][j]
                WT[i][j] = WT[i - 1][j]

    print('Case {}:'.format(case))
    case += 1
    print(VT[N][C])
    print(WT[N][C])

Measured memory_bytes: 31832
a,b,c,d,e,f = map(int,input().split())

# 作れるか判定
def check(goal,ac,bd):
    flag = 0
    for x in range(goal//ac+1):
            if (goal-ac*x)%bd == 0 : flag = 1 ; break
    return flag

# 水W、砂糖Sをまわす
anss = []
for w in range(100,f+1,100):
    for s in range(1,f-w+1):
        if check(w,100*a,100*b) and check(s,c,d) and s<=((w*e)/100):
            conc = 100*s/(w+s) # concentration
            anss.append([conc,w,s])

# 出力
anss.sort(reverse=1)
(w,s) = (anss[0][1],anss[0][2]) if anss else (100*a,0)
print(w+s,s)


Measured memory_bytes: 45532
#!/usr/bin/env ruby

n = gets.chomp.to_i

inning = 0
out = 0
base = [0, 0, 0]
point = 0
loop do
  event = gets.chomp

  case event
  when 'HIT'
    point += base.shift
    base << 1
  when 'HOMERUN'
    point += base.inject(:+) + 1
    base = [0, 0, 0]
  when 'OUT'
    out += 1
    if out == 3
      puts point
      inning += 1
      out = 0
      point = 0
      base = [0, 0, 0]
    end
  end

  break if n == inning
end

Measured memory_bytes: 6856