akhauriyash/Code-Regression huggingface dataset:
/* ex3_2
    sak_Citrus*/

#include <stdio.h>
 
int main(void){
    int n;
    scanf("%d",&n);
    //1桁目だけが欲しいので
    n = n % 10;
    switch(n){
        //3だったらbon
        case 3:
            printf("bon");
            break;
        //0,1,6,8だったらpon
        case 0:
        case 1:
        case 6:
        case 8:
            printf("pon");
            break;
        //2,4,5,7,9はhon
        default:
            printf("hon");
            break;
    }
    //改行
    printf("\n");
    return 0;
}

Measured memory_bytes: 1696
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int A = 20190430;
        
        S = S.replace("/","");
        int num = Integer.parseInt(S); 

        System.out.println(num - A <= 0 ? "Heisei" : "TBD");
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll N,K,Q;
  cin >> N >> K >> Q;
  vector<ll> A(Q);
  ll i;
  vector<ll> R(N,K-Q);
  for(i=0;i<Q;i++){
    cin >> A[i];
    R[A[i]-1]++;
  }
  for(i=0;i<N;i++){
    if(R[i]>0) cout << "Yes\n";
      else cout << "No\n";
  }
  
}


Measured memory_bytes: 2176
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);
        //出力
        Console.WriteLine(String.Format("{0} {1} {2}", c, a, b));
    }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main {
	static class Sub {
		List<Integer> vals = new ArrayList<>();

		boolean isEnable() {
			boolean result = true;
			for (int i = 0; i < vals.size(); ++i) {
				if (vals.get(i) > i + 1) {
					result = false;
					break;
				}
			}
			return result;
		}

		List<Integer> getInputs() {
			Collections.sort(vals);
			return vals;
		}
	}

	Deque<Integer> dfs(List<Integer> vals, Deque<Integer> prevs) {
		if (vals.size() == 1) {
			if (vals.get(0) == 1) {
				prevs.addFirst(vals.get(0));
				return prevs;
			} else {
				return null;
			}
		}
		boolean result = false;
		for (int i = vals.size() - 1; i >= 0; --i) {
			if (vals.get(i) == i + 1) {
				// この要素を取り除ける
				List<Integer> remain = new ArrayList<>(N);
				remain.addAll(vals.subList(0, i));
				remain.addAll(vals.subList(i + 1, vals.size()));
				prevs.addFirst(vals.get(i));
				Deque<Integer> remainResult = dfs(remain, prevs);
				if (remainResult != null) {
					result = true;
					break;
				} else {
					prevs.removeFirst();
				}
			}
		}
		if (result) {
			return prevs;
		} else {
			return null;
		}
	}

	int N;
	int[] b;
	boolean isEnable = false;
	Deque<Sub> subs = new ArrayDeque<>();

	Main() {
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		b = new int[N];
		for (int i = 0; i < N; ++i) {
			b[i] = in.nextInt();
		}
		in.close();
	}

	boolean isEnable() {
		for (int i = 0; i < N; ++i) {
			if (b[i] > i + 1) {
				return false;
			}
		}
		return true;
	}

	void calc() {
		List<Integer> vals = new ArrayList<>();
		for (int i = 0; i < N; ++i) {
			vals.add(b[i]);
		}

		Deque<Integer> result = this.dfs(vals, new ArrayDeque<Integer>());
		if (result != null) {
			while (!result.isEmpty()) {
				System.out.println(result.pollFirst());
			}
		} else {
			System.out.println("-1");
		}
	}

	void show() {
		List<Integer> inputs = new ArrayList<>();
		while (!this.subs.isEmpty()) {
			Sub sub = this.subs.pollLast();
			inputs.addAll(sub.getInputs());
		}
		for (int i = 0; i < inputs.size(); ++i) {
			System.out.println(inputs.get(i));
		}
	}

	public static void main(String[] args) {
		Main ins = new Main();
		if (!ins.isEnable()) {
			System.out.println("-1");
		} else {
			ins.calc();
		}
	}
}

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

typedef long long ll;

const ll mod = 1e9 + 7;

string s;

int dp[100002][15];

ll go(int pos, int rem) {
    if(pos == s.size()) {
        return rem == 5;
    }

    if(dp[pos][rem] != -1) return dp[pos][rem];

    ll ans = 0LL;

    if(s[pos] == '?') {
        for(int i = 0; i <= 9; i++) {
            ans += go(pos + 1, (rem * 10 + i) % 13) % mod;
        }
    }
    else ans += go(pos + 1, (rem * 10 + s[pos] - '0') % 13) % mod;

    return dp[pos][rem] = ans % mod;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    memset(dp, -1, sizeof dp);

    cin >> s;

    cout << go(0, 0) << endl;

}

/**
*/

Measured memory_bytes: 14160
while True:
    n=int(input())
    if(2<=n<=200000):
        break
a=[]
for i in range(n):
        a.append(int(input()))
ma=a[0]
b=0
for j in range(1,n):
    if(ma==a[j]):
        b=a[j]
    if(ma<a[j]):
        ma=a[j]
        continue
    if(b<a[j]):
        b=a[j]
for l in range(n):
    if(a[l]!=ma):
        print(str(ma))
    else:
        print(str(b))

Measured memory_bytes: 12532
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int safe = a + b;
		if (c <= safe) {
			System.out.println(b + c);
			return;
		}
		System.out.println(safe + 1 + b);
	}
}


Measured memory_bytes: 23892
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);
		W = in.readLine();
		String[] Ws = W.split(" ");

		long[] A = new long[Ws.length];
		for (int i = 0; i < Ws.length; i++) {
			A[i] = Long.parseLong(Ws[i]);
		}

		String ans = "APPROVED";
		for(int i=0;i<N;i++){
			if(A[i]%2 == 0 && !(A[i]%3==0 || A[i]%5==0)){
				ans="DENIED";
				break;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21332
#include<iostream>

using namespace std;
int main(void) {
	int K;
	cin >> K;
	int count = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = i + 1; j <= K; j++) {
			if ((i + j) % 2 != 0) {
				count++;
			}
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	string s; cin >> s;
	int n = s.size();
	vector<vector<ll>> dp(n + 1);
	rep(i, n+1) {
		dp[i].resize(4, 0);
	}
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, 4) {
			rep(k, 3) {
				if (s[i] == 'A' + k||s[i]=='?') {
					dp[i + 1][j] = (dp[i+1][j]+dp[i][j])%mod;
					if (j == k) {
						dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
					}
				}
			}
		}
	}
	cout << dp[n][3] << endl;
	return 0;
}

Measured memory_bytes: 7424
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    vector<int> u(n - 1), v(n - 1);
    rep(i, n - 1) cin >> u[i] >> v[i];

    int ans = 0;
    rep(i, n) ans += (i + 1) * (n - i);

    rep(i, n - 1) {
        if (u[i] > v[i]) swap(u[i], v[i]);
        ans -= u[i] * (n - v[i] + 1);
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 6228
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;

string str;
int n;
char c;
vector<int> v;
vector<ll int> s;
vector<ll int> a;

void dfs(vector<ll int> s, int i){
    if(i == n){
        ll int ans=0;
        REP(i, s.size()){
            ans += s[i];
        }
      	a.push_back(ans);
    } else if(i == 0) {
        s.push_back(v[0]);
        dfs(s, i+1);
    } else {
        s.push_back(v[i]);
        dfs(s, i+1);
        s.pop_back();
        ll int tmp = s.back();
        s.pop_back();
        tmp = tmp * 10 + v[i];
        s.push_back(tmp);
        dfs(s, i+1);
    }
}

int main(){
    cin >> str;
    n=str.size();
    REP(i, n){
        c = str[i];
        int k = c - '0';
        v.push_back(k);
    }

    dfs(s, 0);

    ll int ans=0;
    REP(i, a.size()){
        ans += a[i];
    }

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

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int min = INT_MAX;
  int max = INT_MIN;
  
  for(int i = 0; i < n; i++){
    int a; 
    cin >> a;
    if(a < min) min = a;
    if(max < a) max = a;
  }
  
  cout << max - min << endl;
  return 0;
}

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

const int MXN = 1e5 + 1;
const int MOD = 1e9 + 7;

int add(int x, int y) {return (x+y) % MOD;}
int mul(int x, int y) {return (x*1ll*y) % MOD;};
int bp(int x, int y) {
	int ans = 1;
	while (y) {
		if (y&1) ans = mul(ans, x);
		x = mul(x, x);
		y >>= 1;
	}
	return ans;
}


int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> sv[k+1];
	for (int i=1; i<=k; i++) {
		for (int j=2; i*j<=k; j++) {
			sv[i*j].push_back(i);
		}
	}
	vector<int> sub(k+1);
	int ans = 0;
	for (int i=k; i>0; i--) {
		int num = k/i;
		int cur = add(bp(num, n), MOD-sub[i]);
//		cout << i << ' ' << cur << '\n';
		ans = add(ans, mul(i, cur));
		for (int x : sv[i]) {
			sub[x] = add(sub[x], cur);
		}
	}
	cout << ans;
}

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

int main(){
	char a, b;
	cin >> a >> b;
	if (a == 'H' && b == 'H'){
		cout << "H" ;
	}
	else if (a == 'D' && b == 'D'){
		cout << "H";
	}
	else{
		cout << "D";
	}
}


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

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

	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == t.at(i)) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
S = input()

ans = 'keyence'
p = 0
for s in S:
    if s == ans[p]:
        p += 1
    else:
        break
for i in range(7 - p):
    if S[::-1][i] != ans[::-1][i]:
        print('NO')
        exit()
    p += 1

print('YES')


Measured memory_bytes: 3060
using System;
using System.Linq;

namespace Make_Purse_Light
{
    class Program
    {
        private static void Main(string[] args)
        {
            int n, k, i = 0, q, j;
            int[] m = new int[4], x = new int[4] , y = new int[4], p = new int[] { 10, 50, 100, 500 };

            while (true)
            {
                n = int.Parse(Console.ReadLine());
                if (n==0) { break; }
                if (i!=0) { Console.WriteLine(); }
                i++;
                k = 0;
                m = Console.ReadLine().Trim().Split(' ').Select(o => int.Parse(o)).ToArray();
                for (j = 3; j >= 0; j--)
                {
                    k += m[j] * p[j];
                }
                q = k - n;

                for (j = 3; j >= 0; j--)
                {
                    x[j] = q / p[j]; q -= x[j] * p[j];
                    y[j] = Math.Max(0, m[j] - x[j]);
                }

                for (j = 0; j < 4; j++)
                {
                    if (y[j]!=0) { Console.WriteLine("{0} {1}", p[j], y[j]); }
                }
            }
        }
    }
}


Measured memory_bytes: 9728
n,m=map(int,input().split())
A=[input() for _ in range(n)]
B=[input() for _ in range(m)]
ok=0
for i in range(n-m+1):
  for k in range(n-m+1):
    if B[0]==A[i][k:k+m]:
      for j in range(i,i+m):
        if B[j-i]!=A[j][k:k+m]:
          break
      else:
        ok=1
print("Yes" if ok==1 else "No")

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define int long long int
#define MOD 1000000007
using namespace std;
bool strictly_inc(vector <int> v) {
        for(int i=0;i<v.size()-1;i++) {
                if(v[i] >= v[i+1])
                        return false;
        }
        return true;
}
bool strictly_dec(vector <int> v) {
        for(int i=0;i<v.size()-1;i++) {
                if(v[i] < v[i+1])
                        return false;
        }
        return true;
}
void solve() {
        int n;
        cin >> n;
        vector <int> v;
        for(int i=0;i<n;i++) {
                int x;
                cin >> x;
                v.push_back(x);
        }
        if(strictly_inc(v))
                cout << '0' << '\n';
        else if(strictly_dec(v))
                cout << v.size()-1 << '\n';
        else {
                int count = 0, max = 0;
                for(int i=0;i<n-1;i++) {
                         if(v[i] >= v[i+1])
                                count++;
                         if(count > max)
                                 max = count;
                         if(v[i] < v[i+1])
                                 count = 0;
                }
                cout << max << endl;
        }
        return ;
}

int32_t main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef vector<string> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<string>> x = vector<vector<string>>(a,vector<string>(b,"."))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

string strcon(string a, string b){
  if(a.size() > b.size()){
    return a;
  }
  else if(a.size() < b.size()){
    return b;
  }
  else{
    vector<string> v;
    v.push_back(a);
    v.push_back(b);
    sortAl(v);
    return v[1];
  }
}

string insert_s (string s, char in){
  ll pos=0;
  FOR(i,0,s.size()){

    char x = s[i];
    if(in - x > 0){
      break;
    }
    pos = i+1;
  }
  string res;
  FOR(i,0,pos){
    res.push_back(s[i]);
  }
  res.push_back(in);
  FOR(i,pos,s.size()){
    res.push_back(s[i]);
  }
  return res;
}

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

    map<ll,ll> number;
    number[1] = 2;
    number[2] = 5;
    number[3] = 5;
    number[4] = 4;
    number[5] = 5;
    number[6] = 6;
    number[7] = 3;
    number[8] = 7;
    number[9] = 6;

    ll n,m;
    cin>>n>>m;
    VEC2(dp,n+1,m+1);
    vector<char> v(m);
    cinv(v,0,m);
    FOR(i,0,m+1){
      dp[0][i] = "";
    }

    FOR(i,1,n+1){
      FOR(j,1,m+1){
        char num = v[j-1];
        ll mat = number[num - '0'];
        string tmp_ans1 = dp[i][j-1];
        string tmp_ans2 = ".";
//        cout<<"i = "<<i<<endl;
        if(i - mat >= 0){
          tmp_ans2 = dp[i - mat][m];
//          cout<<"ans2 = "<<tmp_ans2<<" in = "<<num<<endl;
          if(tmp_ans2 != ".")tmp_ans2 = insert_s(tmp_ans2, num);
//          cout<<"in ans2 = "<<tmp_ans2<<endl;
        }
        string res = ".";
        if(tmp_ans2 == "." && tmp_ans1 == "." );
        else if(tmp_ans1 == "."){
          res = tmp_ans2;
        }
        else if(tmp_ans2 == "."){
          res = tmp_ans1;
        }
        else{
          res = strcon(tmp_ans1, tmp_ans2);
        }

        dp[i][j] = res;
      }
    }
    cout<<dp[n][m]<<endl;


}


Measured memory_bytes: 119424
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+3;

int a[N];
int n,l,t;

int main(){
	n=get();l=get();t=get();
	int cnt=0;
	fo(i,1,n){
		int x=get(),fx=get();
		int p;
		if (fx==1)p=x+t;else p=x-t;
		if (p>0)cnt=(cnt+p/l)%n;
		if (p<0)cnt=(cnt+n+(p+1)/l-1)%n;
		a[i]=(p%l+l)%l;
	}
	sort(a+1,a+1+n);
	fo(i,cnt+1,n)printf("%d\n",a[i]);
	fo(i,1,cnt)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int k;
    int antenna[5];
    for(int i=0; i<5; ++i){
        cin >> antenna[i];
    }
    cin >> k;

    if(antenna[4] - antenna[0] <= k){
        cout << "Yay!" << endl;
        return 0;
    }

    for(int i=0; i<4; ++i){
        for(int j=i+1; j<5; ++i){
            if(antenna[j] - antenna[i] > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

//#include "seq/bsearch.h"

//find largest x in [s,t) which check(x) is true
template<class T>
T bsearch_largest(T s, T t, int check(T)) {
	s--;
	while (t-s>1) {
		T m = (s+t)/2;
		if (check(m)) s = m;
		else t = m;
	}
	return s;
}

//find smallest x in [s,t) which check(x) is true
template<class T>
T bsearch_smallest(T s, T t, int check(T)) {
	s--;
	while (t-s>1) {
		T m = (s+t)/2;
		if (check(m)) t = m;
		else s = m;
	}
	return t;
}


#define MAXN 100000

long a, b;

int input() {
	if (scanf("%ld %ld", &a, &b) < 0) return 0;
	return 1;
}

void init() {
}

long prod(long sum, long x) {
	return x*(sum-x);
}
long in(long sum, long x, long s, long t) {
	long y = sum - x;
	return x>=s && x<=t && y>=s && y<=t;
}
long maxp(long sum, long s, long t) {
	if (t<s) return LONG_MIN;
	long r = max(prod(sum, s), prod(sum, t));
	long m = sum/2;
	if (in(sum, m, s, t)) r = max(r, prod(sum, m));
	if (in(sum, m+1, s, t)) r = max(r, prod(sum, m+1));
	return r;
}
/*
	max: p=i*(s-i)
	i=[1,p): s=x+1
	i=(p,q]: s=x+2
	i=(q,x]: s=x+1
	p,q = a, x+2-b

	1,2,...a-1,a+1.........x-1,x
	x,x-1..........b+1,b-1...2,1
*/
int check(long x) {
	long r, y = x;
	if (a>x) {
		r = maxp(x+1, 1, x);
	}
	else if(b>x) {
		long r1 = maxp(x+1, 1, a-1);
		long r2 = maxp(x+2, a+1, x+1);
		r = max(r1, r2);
	}
	else {
		x++;
		if (a+b < x+1) {
			//long p = min(a, x+2-b), q = max(a, x+2-b);
			long p = a, q = x+2-b;
			long r1 = maxp(x+1,1,p-1);
			long r2 = maxp(x+2,p+1,q);
			long r3 = maxp(x+1,q+1,x);
			r = max(max(r1,r2),r3);
		}
		else if(a+b > x+1) {
			long p = x-b, q = a;
			long r1 = maxp(x+1,1,p-1);
			long r2 = maxp(x,p,q-1);
			long r3 = maxp(x+1,q+1,x);
			r = max(max(r1,r2),r3);
		}
		else {
			long p = a;
			long r1 = maxp(x+1,1,p-1);
			long r2 = maxp(x+1,p+1,x);
			r = max(r1, r2);
		}
	}
	//printf("=%ld : %d\n", y, r<a*b);
	return  r < a*b;
}

long solve() {
	if (a>b) swap(a,b);
	return bsearch_largest(1L, min(10000000000L,a*b), check);
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	int ca; scanf("%d",&ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int N;
vector<vector<int>> A;
ll ans;
 
void warshall_floyd() {
  vector<vector<int>> B(A);
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        B[i][j] = min(B[i][j], B[i][k] + B[k][j]);
      }
    }
  }
 
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (ans == -1) break;
      if (A[i][j] > B[i][j]) {
        ans = -1;
      } else {
        bool ok = false;
        for (int k = 0; k < N; k++) {
          if (k != i && k != j && B[i][j] == B[i][k] + B[k][j]) ok = true;
        }
        if (!ok) ans += B[i][j];
      }
    }
  }
}
 
main() {
  cin >> N;
  A.resize(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
 
  warshall_floyd();
  cout << ans << endl;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    agc034a()
}

fun agc034a() {
    val (n, a, b, c, d) = readLine()!!.split(" ").map { it.toInt() - 1 }
    val road = readLine()!!.map { it == '.' }.toBooleanArray()

    if ((a until Math.max(c, d)).any { !road[it] && !road[it - 1] }) return println("No")

    if (c < d) return println("Yes")

    return if ((b..d).any { road[it - 1] && road[it] && road[it + 1] }) {
        println("Yes")
    } else println("No")
}


Measured memory_bytes: 39544
N,K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

MOD = 10**9 + 7

plus_pq = []
minus_pq = []

A.each do |a_v|
  if a_v >= 0
    plus_pq << a_v
  end
  if a_v < 0
    minus_pq << a_v
  end
end

ok = false
if plus_pq.size > 0
  if N == K
    ok = minus_pq.size.even?
  else
    ok = true
  end
else
  ok = K.even?
end

ans = 1
unless ok
  plus_pq = nil
  minus_pq = nil
  na = A.sort {|x, y| x.abs <=> y.abs}
  K.times do |i|
    ans *= na[i]
    ans %= MOD
  end
else
  plus_pq.sort!
  minus_pq.sort!.reverse!
  if K.odd?
    ans *= plus_pq.last
    ans %= MOD
    plus_pq.pop
  end
  p = []
  while plus_pq.size >= 2
    x = plus_pq.pop
    x *= plus_pq.pop
    p << x
  end
  while minus_pq.size >= 2
    x = minus_pq.pop
    x *= minus_pq.pop
    p << x
  end
  p.sort!.reverse!
  (K/2).times do |i|
    ans *= p[i]
    ans %= MOD
  end
end

puts ans


Measured memory_bytes: 34972
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 50;
ll mat[N][N];

template <typename T>
struct matrix{
	T a[MAXN][MAXM];
	int n,m;
	matrix(int n,int m){
		this->n = n;
		this->m = m;
		for(int i = 0;i < n;++i)
			for(int j = 0;j < m;++j)
				a[i][j] = 0;
	}
	T* operator[](int ind){
		return a[ind];	
	}
	matrix operator*(const matrix &b){
		assert(m == b.n);
		matrix res = matrix(n, b.m);
		for(int i = 0;i < n;++i){
			for(int k = 0;k < m;++k){
				for(int j = 0;j < b.m;++j){
					res.a[i][j] += a[i][k] * b.a[k][j];
					res.a[i][j] %= MOD;
				}
			}
		}
		return res;
	}
	matrix operator^(long long pow){
		matrix y = matrix(n,n);
		cu(i,0,n)y[i][i] = 1;
		if(pow == 0)return y;

		matrix x = matrix(n,n); 
		cu(i,0,n){
			cu(j,0,m){
				x[i][j] = a[i][j];
			}
		}

		while(pow > 1){
			if(pow&1){
				y = x * y;		
			}
			x = x * x;
			pow>>=1;
		}
		return x * y;
	}
	void print(){
		for(int i = 0;i < n;++i){
			for(int j = 0;j < m;++j){
				printf("%d ",a[i][j]);
			}
			printf("\n");
		}
	}
};

int main(){
	fast_io();
	ll n,k;
	cin >> n >> k;
	matrix<ll> trans = matrix<ll>(n,n);
	matrix<ll> start = matrix<ll>(n,1);
	cu(i,0,n){
		cu(j,0,n){
			cin >> trans[i][j];
		}
		start[i][0] = 1;
	}
	matrix<ll> res = (trans^k) * start;
	ll ans = 0;
	cu(i,0,n){
		ans += res[i][0];	
	}
	ans %= MOD;
	cout << ans << '\n';
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool IsT(vector<int> &L,int i,int j,int k)
{
	if (L[i]+L[j]<=L[k]){
		return false;
	}
	if (L[i]+L[k]<=L[j]){
		return false;
	}
	if (L[j]+L[k]<=L[i]){
		return false;
	}
	return true;
}

int main(int argc, char* argv[])
{
	int N,i,j,k;
	cin>>N;
	vector<int> L(N);
	for (i=0;i<N;i++){
		cin>>L[i];
	}
	sort(L.begin(),L.end());
	int ans=0;
	for (i=0;i<N-2;i++){
		for (j=i+1;j<N-1;j++){
			for (k=j+1;k<N;k++){
				if (IsT(L,i,j,k)){
					ans++;
				}else{
					break;
				}
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt(), w = scan.nextInt();

        boolean[][] bombs = new boolean[h + 2][w + 2];
        for (int i = 0; i < h; i++) {
            String s = scan.next();
            char[] arr = s.toCharArray();
            for (int j = 0; j < arr.length; j++) {
                if (arr[j] == '#') {
                    bombs[i + 1][j + 1] = true;
                }
            }
        }
        char[][] res = new char[h+2][w+2];
        for (int i = 1; i <= h; i++ ) {
            for (int j = 1; j <= w; j++) {
                if (bombs[i][j]) {
                    res[i][j] = '#';
                } else {
                    int count = 0;
                    for (int k = -1; k <= 1; k++) {
                        for (int l = -1; l <= 1; l++) {
                            if (k == 0 && l == 0) {
                                continue;
                            }
                            if (bombs[i + k][j + l]) {
                                count++;
                            }
                        }
                    }
                    res[i][j] = (char)(count + '0');
                }
            }
        }
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                System.out.print(res[i][j]);
            }
            System.out.println();
        }
    }

}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

vector<ll> g[111111];

int used[111111];
int f;

void dfs(int n=0,int pr=0){
  if(used[n]!=-1){
    if(pr!=used[n])f=1;
    return;
  }
  used[n]=pr;
  for(int i=0;i<g[n].size();i++){
    dfs(g[n][i],(pr+1)%2);
  }
}

int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    a--,b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  fill_n(used,111111,-1);
  dfs();
  if(f){
    cout<<(n-1)*n/2-m<<endl;
    return 0;
  }

  ll cnt[2]={};
  for(int i=0;i<n;i++){
    cnt[used[i]]++;
  }
  //  dbg(cnt[0]);  dbg(cnt[1]);
  cout<<cnt[0]*cnt[1]-m<<endl;
  
  return 0;
}


Measured memory_bytes: 7936
using System;

namespace ABChujii14
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            c = int.Parse(ss[2]);
            if (a + b + c >= 22)
                Console.WriteLine("bust");
            else
                Console.WriteLine("win");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out,false);
        int a = scanner.nextInt(), b = scanner.nextInt();
        out.println(Math.max(Math.max(a + b, a - b), a * b));
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[101];
bool nibun(int x){
	int s=0,q=0,t=0;
	r(i,n){
		if(s+a[i]<=x)s+=a[i];
		else s=0,q++,i--,t++;
		if(t>110)return 0;
	}
	return m>=q+1;
}
main(){
	while(cin>>m>>n,m){
	  r(i,n)cin>>a[i];
	  int l=0,r=1500001;
	  while(l<r){
    	int mid=(l+r)/2;
		if(nibun(mid))r=mid;
		else l=mid+1;
	  }
	  cout<<l<<endl;
    }
}

Measured memory_bytes: 3060
import copy
from itertools import combinations
S = input()

result = 0
for n_plus in range(len(S)):
    for plus_indices in combinations(range(1, len(S)), n_plus):
        S_new = copy.deepcopy(S)
        for i, plus_idx in enumerate(plus_indices):
            S_new = S_new[:plus_idx+i] + '+' + S_new[plus_idx+i:]
        result += eval(S_new)
print(result)

Measured memory_bytes: 3444
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()
    H = LIST()
    if N <= K:
        print(0)
        sys.exit()

    H = sorted(H)
    print(sum(H[0:N-K]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 84636
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

s = Counter(S)
s[0] = 0
for t in T:
  if(t in s):
    s[t] -= 1
print(max(s.values()))

Measured memory_bytes: 3316
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
ans=0
b=1
while 1:
    c=a[b-1]
    b=c
    if b==2:
        print(ans+1)
        break
    elif ans>n:
        print(-1)
        break
    ans+=1

Measured memory_bytes: 7084
#include <iostream>
#include <string>
#include <vector>

int main() {
  int H, W;

  while (true) {
    std::cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    std::vector<std::string> a(W, "#");

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        std::cout << a[j] << "";
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;



int main() {
  int n,m,x;
  cin >> n >> m >> x;
  vector<vector<int>> data(n, vector<int>(m));
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++) {
      cin >> data.at(i).at(j);
    }
  }
  int ans=1e7;
  int all=1<<n;
  for(int i=0;i<all;i++){
    vector<int> level(m);
    int cost=0;
    for(int j=0;j<n;j++){
      if((i>>j)&1){
        cost+=c.at(j);
        for(int k=0;k<m;k++){
          level[k]+=data[j][k];
        }
      }
    }
    bool ok=true;
    for(int k=0;k<m;k++){
      if(level[k]<x) ok=false;
    }
    if(ok) ans=min(ans,cost);
  }
  if(ans==1e7) cout << -1 << endl;
  else cout << ans << endl;
}



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

int main() {
    int c;
    P a,b;
    cin >> a.first >> b.first >> c >> a.second >> b.second;

    if (a.first + b.first <= 2*c) {
        cout << a.first * a.second + b.first * b.second << endl;
        return 0;
    }

    P l = a.second <= b.second ? a : b;
    P m = a.second <= b.second ? b : a;
    int ans = 2 * c * l.second;

    if (m.first <= 2*c) {
        ans += m.first * (m.second - l.second);
    }
    else {
        ans += 2 * c * (m.second - l.second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3504
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    ll x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    vector<ll> sc;
    vector<ll> sab;

    rep(i,x){ cin>>a[i]; }
    rep(i,y){ cin>>b[i]; }
    rep(i,z){cin>>c[i]; }

    sort(c.rbegin(),c.rend());

    vector<ll> ab;
    for(int long long i=0;i<y;i++){
        for(int long long j=0;j<x;j++){
            ab.push_back(a[j]+b[i]);
        }
    }

    sort(ab.rbegin(),ab.rend());
    //ll absize=ab.size();
    //cout<<"absize"<<ab.size()<<endl;
    //cout<<"x+y"<<x+y<<endl;
    ll u=min(k,x*y);
    rep(i,u){
        sab.push_back(ab[i]);
    }
    sort(sab.rbegin(),sab.rend());

    vector<ll> ans;

    for(int long long i=0;i<c.size();i++) {
        for (int long long j = 0; j < sab.size(); j++) {
            ans.push_back(sab[j] + c[i]);
        }
    }

    sort(ans.rbegin(),ans.rend());

    rep(i,k){
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 43144
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();
		long a[] = new long[n];
		long l[] = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextLong();
			l[i] = (a[i] - (i + 1));
		}

		Arrays.sort(l);
		long b = l[l.length / 2];

		long sum = 0;
		for (int i = 0; i < n; i++) {
			long abs = Math.abs(a[i] - (b + (i + 1)));
			sum += abs;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 78980
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a, b, c, x, y;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            x = in.nextInt();
            y = in.nextInt();

            if (a + b <= 2 * c) {
                out.println(x * a + y * b);
            } else {
                int res;
                if (x < y) {
                    res = 2 * x * c + (y - x) * Math.min(b, 2 * c);
                } else {
                    res = 2 * y * c + (x - y) * Math.min(a, 2 * c);
                }
                out.println(res);
            }
        }

    }
}



Measured memory_bytes: 21844
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, m = map(int, input().split())
tmp = [None]*(10**5+10)
for i in range(len(tmp)):
    tmp[i] = [None]*2
for i in range(len(tmp)):
    tmp[i][0] = False
    tmp[i][1] = 0
for _ in range(m):
    p, s = input().split()
    #print(p, s)
    if tmp[int(p)][0] == False and s == 'WA':
        tmp[int(p)][1] += 1
    if s == 'AC':
        tmp[int(p)][0] = True
ans = 0
penalty = 0
for i in range(len(tmp)):
    if tmp[i][0]:
        ans += 1
    if tmp[i][0] == True and tmp[i][1] != None:
        penalty += tmp[i][1]
print(ans, penalty)


Measured memory_bytes: 91668
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<pair<long long int, long long int>>v(N);
	for (auto &i : v)cin >> i.first >> i.second;
	long long int ans = LLONG_MAX;
	long long int box = 0;
	for (auto i : v)box += i.first;
	long long int bag = 0;
	for (auto i : v)bag += i.second;
	ans = min(box, bag);
	sort(v.begin(), v.end());
	vector<long long int>rev_max(N);
	vector<long long int>ord_min(N);
	for (int i = 0; i < N; i++) {
		rev_max[i] = v[i].second;
		ord_min[i] = v[i].second;
	}
	for (int i = N - 2; i >= 0; i--)rev_max[i] = max(rev_max[i], rev_max[i + 1]);
	for (int i = 1; i < N; i++)ord_min[i] = min(ord_min[i], ord_min[i - 1]);
	vector<long long int>min_sum(N);
	for (int i = 0; i < N; i++)min_sum[i] = v[i].second;
	sort(min_sum.begin(), min_sum.end());
	for (int i = 1; i < N; i++)min_sum[i] += min_sum[i - 1];
	long long int num = 0;
	for (int i = 0; i < N - 1; i++) {
		num += v[i].first;
		if (ord_min[i] > rev_max[i + 1]) {
			ans = min(ans, num + min_sum[N - i - 2] + ord_min[i] - rev_max[i + 1]);
		}
		else {
			ans = min(ans, num + min_sum[N - i - 2]);
		}
	}
	for (int i = 0; i < N; i++)swap(v[i].first, v[i].second);
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		rev_max[i] = v[i].second;
		ord_min[i] = v[i].second;
	}
	for (int i = N - 2; i >= 0; i--)rev_max[i] = max(rev_max[i], rev_max[i + 1]);
	for (int i = 1; i < N; i++)ord_min[i] = min(ord_min[i], ord_min[i - 1]);
	for (int i = 0; i < N; i++)min_sum[i] = v[i].second;
	sort(min_sum.begin(), min_sum.end());
	for (int i = 1; i < N; i++)min_sum[i] += min_sum[i - 1];
	num = 0;
	for (int i = 0; i < N - 1; i++) {
		num += v[i].first;
		if (ord_min[i] > rev_max[i + 1]) {
			ans = min(ans, num + min_sum[N - i - 2] + ord_min[i] - rev_max[i + 1]);
		}
		else {
			ans = min(ans, num + min_sum[N - i - 2]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;
const char x[] = "abc";
char s[5];


int main()
{
    scanf("%s", s);
    sort(s, s + 3);
    if(strcmp(s, x) == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * Think as we need to stack the number in some piles, in which each
 * pile has to be in increasing ordering. We want to minimize the
 * number of piles needed. When we get a number, we want to put it on
 * the pile that has the largest number smaller than the one we have.
 */
/* greedy */

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    int n;
    while (cin >> n) {
        multiset<int> S; int ans = 0;
        FOR(i,0,n) {
            int a; cin >> a;
            auto itr = S.upper_bound(a-1);
            if (itr == S.begin())
                ans++;          /* no smaller one, start a new pile */
            else
                S.erase(--itr); /* put on the smaller one */
            S.insert(a);        /* a becomes the new top */
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
/*
	atcoder ARC094
	D Worst Case
*/
#include <bits/stdc++.h>
typedef long long ll;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int max(const int x, const int y) { return x > y ? x : y; }
inline int min(const int x, const int y) { return x < y ? x : y; }

inline void swap(ll &x, ll &y) { x ^= y ^= x ^= y; }

inline ll calc(ll A, ll B) {
	if (A > B) swap(A, B);
	if (A == B) return A * 2 - 2;
	ll C = sqrt(A * B);
	if (C * C == A * B) --C;
	if (C * (C + 1) < A * B) return C * 2 - 1;
	else return 2 * C - 2;
}
int t;
ll A, B;
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    for (std::cin >> t; t; --t) std::cin >> A >> B, std::cout << calc(A, B) << '\n';
	return 0;
}


Measured memory_bytes: 3652
M,N,D;P[101][4][21][21];S[21][21];C[4][21][21];J[4][21][21];h1,h2;i,n,v1,v2,k;xs,ys,xg,yg,T;d,x,y,d1,t1,x1,y1;vx[]={1,0,-1,0},vy[]={0,1,0,-1};void set_road(int A[][21][21],int h1,int v1,int h2,int v2,int d){if(v1==v2){A[h1<h2?1:3][v1][h1-96]=d;A[h1<h2?3:1][v2][h2-96]=d;}else{A[v1<v2?0:2][v1][h1-96]=d;A[v1<v2?2:0][v2][h2-96]=d;}}main(){for(;scanf("%d%d%d%d",&M,&N,&D,&n),M;){memset(P,0,sizeof(P));memset(S,0,sizeof(S));memset(C,0,sizeof(C));memset(J,0,sizeof(J));for(i=0;i<n;i++){scanf("\n%c-%d%d",&h1,&v1,&k);S[v1][h1-96]=k;}scanf("%d",&n);for(i=0;i<n;i++){scanf("\n%c-%d %c-%d",&h1,&v1,&h2,&v2);set_road(C,h1,v1,h2,v2,1);}scanf("%d",&n);for(i=0;i<n;i++){scanf("\n%c-%d %c-%d%d",&h1,&v1,&h2,&v2,&k);set_road(J,h1,v1,h2,v2,k);}scanf("\n%c-%d %c-%d",&h1,&v1,&h2,&v2);xs=v1;ys=h1-96;xg=v2;yg=h2-96;P[0][0][xs][ys]=1;for(T=0;;T++)for(d=0;d<4;d++){if(P[T][d][xg][yg]){printf("%d\n",T);goto E;}for(x=1;x<=N;x++)for(y=1;y<=M;y++)if(P[T][d][x][y]&&(!S[x][y]||T/S[x][y]%2!=d%2))for(d1=0;d1<4;d1++){t1=T+D+J[d1][x][y];x1=x+vx[d1];y1=y+vy[d1];if(d1!=(d^2)&&!C[d1][x][y]&&t1<=100&&x1>=1&&x1<=N&&y1>=1&&y1<=M)P[t1][d1][x1][y1]=1;}}E:;}return 0;}

Measured memory_bytes: 0