akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string kaibun;
  cin >>kaibun;
  int n= kaibun.size();
  int count=0;
  
  for(int i=0;i<n/2;i++){
    if(kaibun.at(i)!=kaibun.at(n-1-i)){
      count+=1;
    }
  }
  cout<<count<<endl;
}

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

int W, a, b;

int main() {
  cin >> W >> a >> b;
  if (a+W < b) {
    cout << b - (a+W) << endl;
  } else if (b+W < a) {
    cout << a - (b+W) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,m,x = map(int, input().split())
A = list(map(int, input().split()))

cost = []
costA=0
costB=0
l=0



for i in range(n+1):
    if i==A[l]:
        cost.append(1)
        if l < len(A)-1:
            l+=1
    else:
        cost.append(0)

for j in range(x):
    if cost[j]==1:
        costA+=1

for k in range(x,n):
    if cost[k]==1:
        costB+=1

#print("{0},{1}".format(costA,costB))

print(min(costA,costB))

#if costA>costB:
#    print(costB)
#else:
#    print(costA)        

Measured memory_bytes: 3064
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
q = inn()
h = {}
for x in a:
    if x not in h:
        h[x] = 0
    h[x] += 1
sm = sum(a)
for i in range(q):
    b,c = inm()
    if b not in h:
        print(sm)
    else:
        sm += h[b]*(c-b)
        if c not in h:
            h[c] = 0
        h[c] += h[b]
        h[b] = 0
        print(sm)


Measured memory_bytes: 84616
#include<stdio.h>
int main(void)
{
  int n;     //????????°
  int i,j;   //?????????????????????
  int a;
  int x[20]; //??????????????°????´?
  int sum;
  int k=0;   //?????????????????????????????????
  int max, min;

  for(i=0;i<20;i++){
    scanf("%d", &n);
    if(n==0)break;
    sum=0;
    max=0;
    min=1000;
    for(j=0;j<n;j++){
      scanf("%d", &a);
      sum=sum+a;
      if(max<a)max=a;
      if(min>a)min=a;
    }
    x[i]=(sum-max-min)/(n-2);
    k++;
  }
  for(i=0;i<k;i++)
    printf("%d\n", x[i]);

  return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


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

  int n;
  cin >> n;
  vi a(n), b(n), c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(all(a));
  sort(all(b));
  sort(all(c));
  ll ans = 0;
  rep(i,n) {
    int x = 0, y = 0;
    { // a
      auto it = lower_bound(all(a), b[i]);
      x = it - a.begin();
    }
    { // c
      auto it = upper_bound(all(c), b[i]);
      if(it != c.end()) y = c.end() - it;
    }
    ans += 1LL * x * y;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        UL M[2019] = {}; M[0] = 1;
        string S; cin >> S;
        reverse(S.begin(), S.end());
        UL D = 0;
        UL DD = 1;
        ULL ans = 0;
        for (char c : S) {
            UL d = c - '0';
            DD = DD * 10 % 2019;
            D = (D + d * DD) % 2019;
            ans += M[D];
            M[D]++;
        }
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    //cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}


Measured memory_bytes: 3736
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

N,M = imn()
PS = [input().split() for _ in range(M)]
AC = set()
WA = {}
for i in range(M):
    if PS[i][1] == 'AC':
        AC.add(PS[i][0])
    else:
        if PS[i][0] not in AC:
            if PS[i][0] not in WA:
                WA[PS[i][0]] = 1
            else:
                WA[PS[i][0]] += 1
WA_cnt = 0
for k, v in WA.items():
    if k in AC:
        WA_cnt += v

print(len(AC), WA_cnt, sep=' ')

Measured memory_bytes: 40516
#include <stdio.h>
#include <math.h>

int main(void)
{
	long long int n,m;
	
	long long int sum = 0;
	
	
	
	scanf("%lld",&n);
	
	
	for(m = 1;m* m <= n;m++){
		if(n % m == 0){
			long long int temp = n/m - 1;			//割り切れた数でnを割ると約数が出てくる。
			if(n / m - 1 == n % m - 1){
				sum = sum + m;
			}
			if(temp != 0){
				if(n / temp == n % temp){
				sum = sum + temp;
				}
			}
		}
	}
		
	printf("%lld\n",sum);
	
	return 0;
	
}	

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

vector<vector<P>> G;

vector<int> ans;

void dfs(int v, int p, int c)
{
    ans[v] = c;

    for (auto x : G[v])
    {
        if (x.first == p)
        {
            continue;
        }

        if (x.second % 2 == 0)
        {
            dfs(x.first, v, c);
        }
        else
        {
            dfs(x.first, v, 1 - c);
        }
    }
}

int main(void)
{
    int n;
    int u, v, w;

    cin >> n;

    G.assign(n, vector<P>());

    for (int i = 1; i < n; i++)
    {
        cin >> u >> v >> w;
        u--;
        v--;

        G[u].push_back(P(v, w));
        G[v].push_back(P(u, w));
    }

    ans.assign(n, 0);

    dfs(0, -1, 1);

    for (auto x : ans)
    {
        cout << x << endl;
    }
}

Measured memory_bytes: 10496
package main

import (
	"fmt"
)

func main()  {
	var str string

	_, _ = fmt.Scan(&str)

	if IsSevenExistingIn(str) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func IsSevenExistingIn(str string) bool{
	for i := 0; i < len(str); i++{
		if str[i] == '7'{
			return true
		}
	}
	return false
}


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

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

using namespace std;

bool is_prime(long long a){
	if(a%2==0) return a==2;
	for(long long i=3;i*i<=a;i+=2) if(a%i==0) return false;
	return a!=1;
}

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

	for(;!is_prime(x);x++);
	printf("%d\n",x);

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define N 200050
int n,m,X,Y,dfn[N],enp[N],dis[N],is[N],dep[N],ans,fa[N];
struct Tree {
	int head[N],to[N<<1],nxt[N<<1],cnt;
	inline void add(int u,int v) {
		to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
	}
	void dfs(int x,int y) {
		dfn[x]=++dfn[0];int i; fa[x]=y;
		for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
			dis[to[i]]=dis[x]+1;
			dfs(to[i],x);
		}enp[x]=dfn[0];
	}
	bool jdg(int x,int y) {
		if(dfn[x]>dfn[y]) swap(x,y);
		if(dfn[y]>=dfn[x]&&dfn[y]<=enp[x]) return dis[y]-dis[x]>2;
		return fa[x]!=fa[y];
	}
	void dfs2(int x,int y) {
		int i;
		if(dep[x]>=dis[x]) return ;
		is[x]=1;ans=max(ans,dis[x]<<1);
		for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
			dep[to[i]]=dep[x]+1;
			dfs2(to[i],x);
			if(jdg(x,to[i])) {puts("-1");exit(0);}
		}
	}
}t1,t2;
int main() {
	scanf("%d%d%d",&n,&X,&Y);
	if(X==Y) {puts("0"); return 0;}
	int i,x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),t1.add(x,y),t1.add(y,x);
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),t2.add(x,y),t2.add(y,x);
	t2.dfs(Y,0);
	t1.dfs2(X,0);
	printf("%d\n",ans);
}


Measured memory_bytes: 17024
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
vector<int>to[200002];
vector<int>ans;

void dfs(int x, int y = 0) {
	for (auto p : to[x]) {
		if (p == y) continue;
		ans[p] += ans[x];
		dfs(p, x);
	}
}
int main() {
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	rep(i, q) {
		int p, x;
		cin >> p>>x;
		--p;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 23552
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define MOD         1000000007
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)

void IO() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	//IO();
	fastio;
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll n, k; cin >> n >> k;
	vector <int> ar(200002);
	vector <int> C;
	vector <bool> vis(200002, 0);
	for (int i = 1; i <= n; i++) {
		cin >> ar[i];
	}
	int pos = 1;
	int stp = 0;
	while (k && stp <= 100000000) {
		pos = ar[pos]; ++stp; --k;
	}
	int st = pos;
	while (1) {
		vis[st] = true;
		C.pb(st);
		st = ar[st];
		if (vis[st])
			break;
	}
	cout << C[k % (C.size())] << endl;

	return 0;
}

Measured memory_bytes: 6876
#include <stdio.h>

int a,b;



int main(){

scanf("%d", &a);
scanf("%d", &b);


if ( a - b < 0){

printf("a < b\n");

} else if ( a - b > 0){

printf("a > b\n");

} else if ( a - b == 0){

printf("a == b\n");

}

return 0;
}

Measured memory_bytes: 580
#include<cstdio>
#include<cstring>
#include<algorithm>
using std::swap;
const int mod=1e9+7,inv2=(mod+1)/2;
inline int add(int a,int b)
{
	return (a+=b)>=mod?a-mod:a;
}
inline int sub(int a,int b)
{
	return (a-=b)<0?a+mod:a;
}
inline int mul(int a,int b)
{
	return (long long)a*b%mod;
}
const int N=3005;
int n,q,ans,p2q;
int a[N];
int x[N],y[N];
int dp[N][N];
int tmp[2][2][N];
int t0,t1;
signed main()
{
	register int i,j;
	scanf("%d%d",&n,&q);
	p2q=1;
	for(i=1;i<=q;i++)
		p2q=mul(p2q,2);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=q;i++)
		scanf("%d%d",&x[i],&y[i]);
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			if(a[i]<a[j])
				dp[i][j]=1;
	for(i=1;i<=q;i++)
	{
		t0=dp[x[i]][y[i]];
		t1=dp[y[i]][x[i]];
		for(j=1;j<=n;j++)
			if(j!=x[i]&&j!=y[i])
			{
				tmp[0][0][j]=dp[x[i]][j];
				tmp[0][1][j]=dp[y[i]][j];
				tmp[1][0][j]=dp[j][x[i]];
				tmp[1][1][j]=dp[j][y[i]];
			}
		for(j=1;j<=n;j++)
			if(j!=x[i]&&j!=y[i])
			{
				dp[y[i]][j]=add(dp[y[i]][j],tmp[0][0][j]);
				dp[x[i]][j]=add(dp[x[i]][j],tmp[0][1][j]);
				dp[j][y[i]]=add(dp[j][y[i]],tmp[1][0][j]);
				dp[j][x[i]]=add(dp[j][x[i]],tmp[1][1][j]);
			}
		dp[x[i]][y[i]]=add(dp[x[i]][y[i]],t1);
		dp[y[i]][x[i]]=add(dp[y[i]][x[i]],t0);
		for(j=1;j<=n;j++)
			if(j!=x[i]&&j!=y[i])
			{
				dp[x[i]][j]=mul(dp[x[i]][j],inv2);
				dp[y[i]][j]=mul(dp[y[i]][j],inv2);
				dp[j][x[i]]=mul(dp[j][x[i]],inv2);
				dp[j][y[i]]=mul(dp[j][y[i]],inv2);
			}
		dp[x[i]][y[i]]=mul(dp[x[i]][y[i]],inv2);
		dp[y[i]][x[i]]=mul(dp[y[i]][x[i]],inv2);
	}
	for(i=1;i<=n;i++)
		for(j=1;j<i;j++)
			ans=add(ans,mul(dp[i][j],p2q));
	memset(dp,0,sizeof(dp));
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			if(a[i]>a[j])
				dp[i][j]=1;
	for(i=1;i<=q;i++)
	{
		t0=dp[x[i]][y[i]];
		t1=dp[y[i]][x[i]];
		for(j=1;j<=n;j++)
			if(j!=x[i]&&j!=y[i])
			{
				tmp[0][0][j]=dp[x[i]][j];
				tmp[0][1][j]=dp[y[i]][j];
				tmp[1][0][j]=dp[j][x[i]];
				tmp[1][1][j]=dp[j][y[i]];
			}
		for(j=1;j<=n;j++)
			if(j!=x[i]&&j!=y[i])
			{
				dp[y[i]][j]=add(dp[y[i]][j],tmp[0][0][j]);
				dp[x[i]][j]=add(dp[x[i]][j],tmp[0][1][j]);
				dp[j][y[i]]=add(dp[j][y[i]],tmp[1][0][j]);
				dp[j][x[i]]=add(dp[j][x[i]],tmp[1][1][j]);
			}
		dp[x[i]][y[i]]=add(dp[x[i]][y[i]],t1);
		dp[y[i]][x[i]]=add(dp[y[i]][x[i]],t0);
		for(j=1;j<=n;j++)
			if(j!=x[i]&&j!=y[i])
			{
				dp[x[i]][j]=mul(dp[x[i]][j],inv2);
				dp[y[i]][j]=mul(dp[y[i]][j],inv2);
				dp[j][x[i]]=mul(dp[j][x[i]],inv2);
				dp[j][y[i]]=mul(dp[j][y[i]],inv2);
			}
		dp[x[i]][y[i]]=mul(dp[x[i]][y[i]],inv2);
		dp[y[i]][x[i]]=mul(dp[y[i]][x[i]],inv2);
	}
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			ans=add(ans,mul(dp[i][j],p2q));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define sort(x) sort(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int a[100005], n, m;

int main(){
	int i, j=0;
	string s, t;
	cin >> s >> t;
	for(i=0;i<3;i++)if(s[i]==t[i])j++;
	cout << j;
}


Measured memory_bytes: 256
#include <stdio.h>
int func(int n);
int func(int n) {
	if (n % 2)n = n * 3 + 1;
	else n = n / 2;
	return n;
}
int main(void) {
	int a[1000001] = {},i = 0;
	bool ans = false;
	scanf("%d",&a[0]);
	while (ans == false)
	{
		a[i + 1] = func(a[i]);
		for (int j = i; j > -1; j--)
		{
			if (a[i + 1] == a[j])
			{
				ans = true;
			}
		}
		i++;
	}
	printf("%d",i+1);
	return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};

 
vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 

int main(){
    set_combi();
    int n;cin >> n;
    vector<LL> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    vector<LL> v;
    for (int i = 1; i < n; i++) {
        v.pb(x[i] - x[i-1]);
    }
    LL ans = 0;
    vector<LL> cum(n+1,0);
    for (int i = 0; i < n-1; i++) {
        cum[i+1] = (cum[i] + combi(n-1,i+1) * fact[n-1-(i+1)] %mod * fact[i])%mod;
    }
    for (int i = 0; i < n - 1; i++) {
        ans = (ans + v[i] * cum[i+1])%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6000
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define All(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
int N;
ll K;
vector<ll> P, M, Z;
 
bool judge_m(ll mid) {
    ll sum = 0;
    for (int i = 0; i < (int)P.size(); i++) {
        ll d = (mid - P[i] + 1) / P[i];
        sum += upper_bound(M.begin(), M.end(), d) - M.begin();
    }
    return sum >= K;
}
 
bool judge_p(ll mid) {
    ll sum = 0;
    for (int i = 0; i < (int)P.size(); i++) {  // 正と正の積
        ll d = mid / P[i];
        ll tmp = upper_bound(P.begin(), P.end(), d) - P.begin();
        if (i < tmp) tmp--;  // 自身を除く
        sum += tmp;
    }
    for (int i = 0; i < (int)M.size(); i++) {  // 負と負の積
        ll d = mid / M[i];
        ll tmp = upper_bound(M.begin(), M.end(), d) - M.begin();
        if (i < tmp) tmp--;  // 自身を除く
        sum += tmp;
    }
    sum /= 2;
    return sum >= K;
}
 
int main() {
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A.at(i);
    REP(i, N) {  // Aを正か負か0かで分類
        if (A[i] > 0) {
            P.push_back(A[i]);
        } else if (A[i] < 0) {
            M.push_back(A[i]);
        } else {
            Z.push_back(A[i]);
        }
    }
 
    ll p = P.size();
    ll m = M.size();
    ll z = Z.size();
    ll minus = p * m;
    ll zero = z * (z - 1) / 2 + z * p + z * m;
    ll plus = p * p + m * m;
 
    if (K <= minus) {  // X が負の時
        sort(All(M));
        ll l = -1e18 - 1, u = -1;  // 二分探索: (l,u]に答えがある
        while (u - l > 1) {
            ll mid = (u + l) / 2;
            if (judge_m(mid)) {
                u = mid;
            } else {
                l = mid;
            }
        }
        cout << u << endl;
 
    } else if (K <= minus + zero) {  // X が 0 の時
        cout << 0 << endl;
 
    } else if (K <= minus + zero + plus) {  // X が正の時
        K -= (minus + zero);
        REP(i, m) M[i] = abs(M[i]);  // 中身を正に変更
        sort(All(P));
        sort(All(M));
        ll l = -1, u = 1e18;  //二分探索: (l,u]に答えがある
        while (u - l > 1) {
            ll mid = (u + l) / 2;
            if (judge_p(mid)) {
                u = mid;
            } else {
                l = mid;
            }
        }
        cout << u << endl;
    }
    return 0;
}

Measured memory_bytes: 4084
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
//#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
const int mod=1e9+7;
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;//ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,m;
 cin>>n>>m;
 vector<ll>a(m),b(m);
  
 rep(i,0,m){
  cin>>a.at(i)>>b.at(i);
  a[i]--;b[i]--;
 }
 
 ll ans=0;
 rep(i,0,m){
  UnionFind v(n);
  rep(j,0,m){
   if(j==i)continue;
   v.unite(a[j],b[j]);
  }
  if(v.treeSize(0)!=n)ans++;
 }
 pr(ans);
 return 0;}

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

using namespace std;

const int maxn=200000+5;
const int mod=1000000007;

int h,w,a,b;
int fac[maxn];

void exgcd(int a,int b,int &g,int &x,int &y)
{
	if(b==0)g=a,x=1,y=0;
	else exgcd(b,a%b,g,y,x),y-=a/b*x;
}

int inv(int a)
{
	int g,x,y;
	exgcd(a,mod,g,x,y);
	return(x+mod)%mod;
}

int C(int n,int m)
{
	return (long long)fac[n]*inv(fac[m])%mod*inv(fac[n-m])%mod;
}

int f(int n,int m)
{
	return C(n+m-2,n-1);
}

int main()
{
	fac[0]=1;
	for(int i=1;i<maxn;++i)fac[i]=(long long)fac[i-1]*i%mod;
	cin>>h>>w>>a>>b;
	int ret=0;
	for(int i=1;i<=h-a;++i)
	{
		ret=(ret+(long long)f(i,b)*f(h-i+1,w-b))%mod;
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

ll d;
vector<ll> c(26);
vector<vector<ll>> vec(d, vector<ll>(26));

ll calc(vector<ll> t){
    ll res = 0;
    vector<ll> last(26);
    rep(i, d){
        rep(j, 26){
            if(t[i] == j){
                res += vec[i][j];
                last[j] = 0;
            }else{
                last[j]++;
            }
        }
        rep(j, 26){
            res -= c[j]*last[j];
        }
    }
    return res;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    
    cin >> d;
    clock_t start = clock();
    rep(i, 26){
        cin >> c[i];
    }
    vec.resize(d, vector<ll>(26));
    rep(i, d){
        rep(j, 26){
            cin >> vec[i][j];
        }
    }

    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t;
    rep(i, d){

        ll max_value = -1;
        ll contest_type = -1;

        //それぞれの日を選んだ場合
        ll max_val = -INF;
        ll tmp_day = -1;
        rep(j, 26){
            ll tmp = 0;

            rep(k, 26){
                if(j == k){
                    tmp += vec[i][j];
                }
                else{
                    tmp -= c[k] * (last[k] + 1);
                }
            }
            if(max_val < tmp){
                max_val = tmp;
                tmp_day = j;
            }
        }

        //cout << tmp_day + 1 << endl;
        t.push_back(tmp_day);
        ans += max_val;

        //後処理
        rep(j, 26){
            if(j == tmp_day){
                last[j] = 0;
            }else{
                last[j]++;
            }
        }
    }

    

    //cout << ans << endl;

    while(true){

        srand(time(NULL));
        ll before = rand() % 26 + 1;
        ll after = rand() % 26 + 1;
        if(t[before] != after){
            ll old = t[before];
            t[before] = after;

            ll res = 0;
            res = calc(t);

            if(ans < res){
                ans = res;
            }else{
                t[before] = old;
            }
        }

        clock_t end = clock();
        const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        //printf("time %lf[ms]\n", time);
        if(time > 1950){
            break;
        }
    }

    rep(i, t.size()){
        cout << t[i] + 1 << endl;
    }
    
    
    
    
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */


}

Measured memory_bytes: 3744
//When I wrote this only God and I knew what it is
//Now, only The_Blitz knows...
#pragma GCC optimize ("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 2;
int ans[N];

int main(){
	fastio;
	int n; cin >> n;
	for(int i = 1; i < n + 1; ++ i){
		int x ; cin >> x;
		ans[x] = i;
	}
	for(int i = 1; i < n + 1; ++ i) cout << ans[i] << " \n"[i==n];
	return 0;
}



Measured memory_bytes: 3952
import qualified Control.Monad.State.Lazy as State
import Control.Monad.State.Lazy (State)
import qualified Data.Bits as Bits
import qualified Data.ByteString.Char8 as BS
import qualified Data.Char as Char
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import qualified Data.Vector.Unboxed.Mutable as UMVector
import qualified Data.Vector.Unboxed as UVector
import Data.Vector.Unboxed ((!))
--
-- xorLengths' :: UVector.Vector Int -> Int -> Int -> Int
-- xorLengths' as l xorVal
-- 	| l >= UVector.length as =
-- 	| xorVal' == xorVal + next = xorLength' (l + 1) xorVal'
-- 	where
-- 		next = as ! l
-- 		xorVal' = xorVal `Bits.xor` next

type XorLengthState = State (Int, Int)

xorLengths' :: UVector.Vector Int -> [Int] -> XorLengthState [Int]
xorLengths' as acc
	| UVector.null as = return acc
	| otherwise       = do
		(l, xorVal) <- State.get
		let current = as ! 0
		let next = as ! l
		let xorVal' = xorVal `Bits.xor` next
		let nextXor = xorVal `Bits.xor` current
		if l >= UVector.length as || xorVal' /= xorVal + next then do
			State.put (l - 1, nextXor)
			xorLengths' (UVector.tail as) (l:acc)
		else do
			State.put (l + 1, xorVal')
			xorLengths' as acc

main :: IO ()
main = do
	n <- readLn
	as <- UVector.unfoldrN n (BS.readInt . BS.dropWhile Char.isSpace) <$> BS.getLine
	-- print $ sum $ xorLengths as 0 0 []
	print $ sum $ fst $ State.runState (xorLengths' as []) (0, 0)


Measured memory_bytes: 42364
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int K;
	cin >> K;
	ll a = 7;
	ll c = 1;
	for (int i = 1; i < K*10; ++i)
	{
		ll b = a % K;
		if (b == 0)
		{
			cout << i << endl;
			return 0;
		}
		c *= 10;
		a += 7 * c;
		c %= K;
		a %= K;
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 3628
'''


'''
## import
from collections import deque # キュー、スタックに利用
import itertools
# import math # 数学的計算に利用
# import numpy as np # 行列計算などに利用
import sys

## 初期設定
input = sys.stdin.readline # 標準入力の高速化に利用
sys.setrecursionlimit(10**7) # 再帰関数の呼び出し上限を増やす
inf = float('inf')

is_debug = False


## input
h,w = map(int, input().split())

M = [list(input().rstrip()) for _ in range(h)]

## ステータス管理2次元配列
# 訪問状態をWHITE, GRAY, BLACKのいずれかで表す
M_color = [['WHITE']*w for _ in range(h)]

## 距離
# 初期値は-1（到達不能）を入れ、到達できたら実際の距離を代入する
M_distance = [[-1]*w for _ in range(h)]

route_str = '.'
# start, goal設定
sy=0
sx=0
gy=h-1
gx=w-1

def breadth_first_search():
    """

    """
    # 開始頂点sのステータスを探索中へ変更、距離は0を代入
    M_color[sy][sx] = 'GRAY'
    M_distance[sy][sx] = 0
    # キューを初期化し、開始頂点をキューへ代入
    q = deque()
    q.append([sy,sx])

    # 探索時の移動方向（上右下左） # delta y, delta x
    deltas = [[-1,0], [0,1], [1,0], [0,-1]]

    # qが空になるまでwhileループ処理
    while len(q) > 0:
        # 探索する頂点を取り出し
        y, x = q.popleft()

        # ゴールに辿り着いたら距離をreturn
        if x == gx and y == gy:
            return M_distance[y][x]

        ## uに隣接する全ての頂点について、未探索の場合は探索
        for delta in deltas:
            # 移動後の位置を算出
            after_y = y+delta[0]
            after_x = x+delta[1]
            # r,cの範囲に収まっていなければスキップ
            if after_x < 0 or after_x > w-1 or after_y < 0 or after_y > h-1:
                continue
            
            # 移動先が陸かつ未探索なら
            if M[after_y][after_x] == route_str and M_color[after_y][after_x] == 'WHITE':
                M_color[after_y][after_x] = 'GRAY'
                # 距離は、現在キューにある頂点u + 1となる（隣接しているので）
                M_distance[after_y][after_x] = M_distance[y][x] + 1
                # キューに追加
                q.append([after_y,after_x]) # キューに追加
                            
            M_color[y][x] = 'BLACK'
    
    # goalへたどり着けない場合
    return -1


def main():
    '''メイン処理'''
    g_distance = breadth_first_search()
    # 塗りつぶせる'.'の数 = 全ての'.'の数 - ゴールまでの距離 - 1(スタート地点の.)
    if is_debug:
        print(g_distance)
    
    if g_distance == -1:
        print(-1)
    else:
        # 2次元配列Mの中の、.の数をカウント
        all_dot = len([s for s in list(itertools.chain.from_iterable(M)) if '.' in s])
        ans = all_dot - g_distance -1
        print(ans)
    
    
if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()


Measured memory_bytes: 3444
// Cursor jump numbers
// main @ 39
// global @ 35
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, k;
  cin >> a >> b >> k;
  if(k > a) {
    k -= a;
    a = 0;
    if(k > b) {
      b = 0;
    } else {
      b -= k;
    }
  } else {
    a -= k;
  }
  cout << a << ' ' << b << '\n';
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
string k;
ll d,dp[10005][2][105];
ll f(ll pos,ll flag,ll r)
{
	if(pos==sz(k))
		return r==0;
	if(dp[pos][flag][r]!=-1)
		return dp[pos][flag][r];
	ll ans=0;
	if(flag)
	{
		ll e=(k[pos]-'0');
		rep(i,0,e)
			ans=(ans+f(pos+1,0,(r+i)%d))%M;
		ans=(ans+f(pos+1,1,(r+e)%d))%M;
	}
	else
	{
		rep(i,0,10)
			ans=(ans+f(pos+1,0,(r+i)%d))%M;
	}
	dp[pos][flag][r]=ans;
	return ans;	
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>k>>d;
    cout<<(f(0,1,0)+M-1)%M;
}


Measured memory_bytes: 17408
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

int main()
{
	int cs; scanf("%d",&cs);
	while(cs--)
	{
		int w,h,n; scanf("%d%d%d",&w,&h,&n);
		
		int dp[16][16]={0}; dp[0][0]=1;
		bool tate[16][16]={0},yoko[16][16]={0};
		
		rep(i,n)
		{
			int x,y,X,Y; scanf("%d%d%d%d",&x,&y,&X,&Y);
			if(X<x)swap(X,x); if(Y<y)swap(Y,y);
			if(x==X)tate[y][x]=1;
			else yoko[y][x]=1;
		}
		rep(i,h+1)rep(j,w+1)
		{
			if(i&&!tate[i-1][j])dp[i][j]+=dp[i-1][j];
			if(j&&!yoko[i][j-1])dp[i][j]+=dp[i][j-1];
		}
		if(dp[h][w])printf("%d\n",dp[h][w]);
		else puts("Miserable Hokusai!");
	}
	return 0;
}

Measured memory_bytes: 0
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, d; cin >> n >> d;
    ll v = 2 * d + 1;
    ll res = n / v;
    if (n % v != 0) res++;
    cout << res;
    cout << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int a, b;cin >> a >> b;
  vector<int> hoge;
  hoge.push_back(a + (a - 1));
  hoge.push_back(a + b);
  hoge.push_back(b + b - 1);
  int max = *max_element(hoge.begin(), hoge.end());
  say(max);
}

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

#define mp make_pair
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin>>n;
    int ans=0,res=0,prv=1e10;
    while(n--)
    {
        int cur;
        cin>>cur;
        if(cur<=prv)
            res++;
        else
            res=1;
        prv=cur;
        ans=max(ans,res);
    }
    cout<<ans-1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ri register int
using namespace std;
int read()
{
	int num=0;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		num=(num<<3)+(num<<1)+(c^48);
		c=getchar();
	}
	return num;
}
const int maxn=5e5+5;
int l[maxn<<2],r[maxn<<2];
int a[maxn<<2];
int main()
{
	int n=read();
	for (ri i=1; i<=n; ++i)
	{
		a[i]=read();
	}
	for (ri i=1; i<=n; ++i)
	{
		l[i]=i;
		while(l[i]>1&&a[l[i]-1]>a[i])
		{
			l[i]=l[l[i]-1];
		}
	}
	for (ri i=n;i>=1;i--)
	{
		r[i]=i;
		while(r[i]<=n&&a[r[i]+1]>a[i])
		{
			r[i]=r[r[i]+1];
		}
	}
	ll llx=0;
	for (ri i=1; i<=n; ++i)
	{
		llx+=(ll)a[i]*(i-l[i]+1)*(r[i]-i+1);
	}
	cout<<llx;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  ll ans = numeric_limits<ll>::max();
  in(ll, l, r);
  for (ll i = l; i < r; ++i) {
    for (ll j = i + 1; j <= r; ++j) {
      ll k = i * j % 2019;
      if (k == 0) {
        out(0);
        return 0;
      }
      ans = min(ans, k);
    }
  }
  out(ans);
}


Measured memory_bytes: 3596
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int ans = Math.min(a+b, Math.min(b+c, c+a));
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
def main38():
    num = int(input())
    dataa = input().split()
    datab = input().split()
    numa = []
    numb = []
    for i in range(num):
        numa.append(int(dataa[i]))
        numb.append(int(datab[i]))
    numa.append(int(dataa[num]))
    result = 0
    for i in range(num):
        if numa[i] >= numb[i]:
            result = result + numb[i]
        else:
            result = result + numa[i]
            numb[i] = numb[i] - numa[i]
            if numa[i+1] >= numb[i]:
                result = result + numb[i]
                numa[i+1] = numa[i+1] - numb[i]
            else:
                result = result + numa[i+1]
                numa[i+1] = 0
    print(result)

if __name__ == "__main__":
    main38()

Measured memory_bytes: 26048
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    ll m; cin >> m;
    vl c(m),d(m);
    ll sum = 0;
    ll dig = 0;
    ll ans = 0;
    rep(i,m){
        cin >> c[i] >> d[i];
        sum += d[i] * c[i];
        dig += d[i];
    }
    cout << dig-1 + (sum-1)/9 << endl;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>

using namespace std;

void Solution()
{
    int a, b;
    
    while(cin>>a>>b)
    {
        map<int, int> used;
        
        vector<int> ans;
        
        int n = a * 10;
        
        bool flag = true;
        
        int start;
        int size;
        
        size = 0;
        
        used[a] = size++;
        
        for(;;)
        {
            ans.push_back(n / b);
            
            int m = n % b;
            
            if(m == 0)
            {
                break;
            }
            
            if(used.count(m)) // check if "m" is including array
            {
                flag = false;
                start = used[m];
                break;
            }
            
            used[m] = size++;
            
            n %= b;
            n *= 10;
        }
        
        for(int i = 0; i < ans.size(); i++)
        {
            cout << ans[i];
        }
        
        cout << endl;
        
        if(flag)
        {
            continue;
        }
        
        for(int i = 0; i < ans.size(); i++)
        {
            if(i < start)
            {
                cout << " ";
            }
            else
            {
                cout << "^";
            }
        }
        
        cout << endl;
    }
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


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




ll m = 1000007;
ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll A[100010];
int main() {
	int N;
	cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	A[N] = 1000000001;
	SORT(A, N);
	bool ok = true;
	ll ans = 0;
	REP(i, N) {
		if (A[i + 1] == A[i]) {
			if (ok)ok = false;
			else ok = true;
		}
		if (A[i + 1] != A[i]) {
			if (ok)ans++;
			ok = true;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val X = readLine()!!.toInt()
    println(Sieve.nextPrime(X))
}

object Sieve {
    private val N = 1000000
    private val primes: Array<Int>

    init {
        val que = ArrayDeque<Int>()
        val sieve = BooleanArray(N + 1) { true }
        sieve[0] = false
        sieve[1] = false
        for (i in 2..N) {
            if (!sieve[i]) continue
            que.push(i)
            for (j in (i * 2)..N step i) {
                sieve[j] = false
            }
        }
        primes = que.toTypedArray()
    }

    fun nextPrime(n: Int) = primes.last { it >= n }
}

Measured memory_bytes: 40816
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        
        int sum=0,cnt;
        for(cnt=0; cnt<N; cnt++) {
            sum += sc.nextInt();
            if(sum > X) break;
        }
        
        System.out.println(cnt+1);
    }
}


Measured memory_bytes: 23636
#include<iostream>
using namespace std;
int main(){
  int n,m,x,cost1=0,cost2=0,mi;
  cin >> n >> m >> x;
  int i,a;
  for(i=0;i<m;i++){
    cin >> a;
    if(a<x) cost1 ++;
    else cost2 ++;
  }
  mi = (cost1<cost2) ? cost1 : cost2;
  cout << mi <<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.text.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Stack<Integer> stk = new Stack<Integer>();
		while(in.hasNext()){
			int n = in.nextInt();
			if(n == 0){
				n = stk.pop();
				System.out.println(n);
			}
			else{
				stk.push(n);
			}
		}
	}
}

Measured memory_bytes: 12000